How to search registered user on ejabberd server from client side using smack library?

 ̄綄美尐妖づ 提交于 2021-02-17 05:18:57

问题


I am using smack on the client-side. I tried to search registered users on the client-side because before creating a new user I want to know that the id is registered on server or not if not then create the user either log in the user but ejabberd server crashed with the error. Here are the crash logs of ejabberd server.

Failed to process iq:
#iq{
 id = <<"Hh6AJ-28">>,type = set,lang = <<"en">>,
 from =
  #jid{
   user = <<"admin">>,server = <<"faiqkhan-virtualbox">>,
   resource = <<"92526029764259513741138">>,luser = <<"admin">>,
   lserver = <<"faiqkhan-virtualbox">>,
   lresource = <<"92526029764259513741138">>},
 to =
  #jid{
   user = <<>>,server = <<"vjud.faiqkhan-virtualbox">>,resource = <<>>,
   luser = <<>>,lserver = <<"vjud.faiqkhan-virtualbox">>,lresource = <<>>},
 sub_els =
  [#xmlel{
    name = <<"query">>,
    attrs = [{<<"xmlns">>,<<"jabber:iq:search">>}],
    children =
     [#xmlel{
       name = <<"x">>,
       attrs = [{<<"xmlns">>,<<"jabber:x:data">>},{<<"type">>,<<"submit">>}],
       children =
        [#xmlel{
          name = <<"field">>,
          attrs = [{<<"var">>,<<"user">>},{<<"type">>,<<"text-single">>}],
          children =
           [#xmlel{
             name = <<"value">>,attrs = [],
             children = [{xmlcdata,<<"wasiq@faiqkhan-virtualbox">>}]}]}]}]}],
 meta = #{ip => {0,0,0,0,0,65535,49320,11092}}}
exception error: {module_not_loaded,mod_vcard_mnesia,
                                     <<"faiqkhan-virtualbox">>}
   in function  gen_mod:get_module_opts/2 (src/gen_mod.erl, line 338)
   in call from gen_mod:get_module_opt/3 (src/gen_mod.erl, line 318)
   in call from mod_vcard_mnesia:filter_fields/3 (src/mod_vcard_mnesia.erl, line 200)
   in call from mod_vcard_mnesia:search/4 (src/mod_vcard_mnesia.erl, line 78)
   in call from mod_vcard:search_result/4 (src/mod_vcard.erl, line 479)
   in call from mod_vcard:process_search/1 (src/mod_vcard.erl, line 264)
   in call from gen_iq_handler:process_iq/3 (src/gen_iq_handler.erl, line 131)
   in call from gen_iq_handler:process_iq/4 (src/gen_iq_handler.erl, line 109)

I used the following code to get a registered user from the client-side:

InetAddress address = InetAddress.getByName(HOST);
DomainBareJid serviceName = JidCreate.domainBareFrom("faiqkhan-VirtualBox");        XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder();
builder.setPort(PORT);
builder.setSendPresence(true);
builder.setHostAddress(address);
builder.setServiceName(serviceName);
builder.setUsernameAndPassword("admin", "123456");
builder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
XMPPTCPConnection connection = new XMPPTCPConnection(builder.build());
try {
    connection.connect();
    connection.login("admin", "123456");
    Logger.showError("21560-connection created to: " + connection.getHost());
    Roster roster = Roster.getInstanceFor(connection);
    Set<RosterEntry> entities = roster.getEntries();
    UserSearchManager search = new UserSearchManager(connection);
    DomainBareJid s = JidCreate.domainBareFrom("vjud.".concat("faiqkhan-VirtualBox"));
    Form searchForm = search.getSearchForm(s);
    Form answerForm = searchForm.createAnswerForm();
    answerForm.setAnswer("user", "wasiq@faiqkhan-virtualbox");
    ReportedData data = search.getSearchResults(answerForm, s);
    if (data.getRows() != null) {
        for (ReportedData.Row row : data.getRows()) {
            for (CharSequence value : row.getValues("jid")) {
                Log.i("Iteartor values......", " " + value);
            }
        }
    }

    } catch (SmackException | IOException | XMPPException | InterruptedException e) {
        Logger.showError("21560-error on account creation: " + e.getMessage());
    }

Server crashed on ReportedData data = search.getSearchResults(answerForm, s); line of code.


回答1:


You found a bug in ejabberd:

  1. It was already fixed in 2018 in https://github.com/processone/ejabberd/commit/1be21126342d503205798605725ba5ceef9de42b
  2. but the bug got reintroduced in 2019 in https://github.com/processone/ejabberd/commit/a02cff0e780bb735531594c4ece81e8628f79782#diff-71f613241ed580c3e5dad2b4526503f2R12
  3. and I've now applied a temporary fix in https://github.com/processone/ejabberd/commit/92913389a51ddc564f11e0712b0d82fca8c9aecb

But even if that bug is fixed, the feature you want to use probably doesn't help: a user must set his vCard in order for his account to be provided in vJud search. In other words, vJUD searches in stored vCards, not in registered accounts. If I register an account but don't set a vCard, then vJUD will not find it.

before creating a new user I want to know that the id is registered on server or not

And why don't you simply attempt to register the account first?

On the other hand, if you would like to check in advance if an account is available for registration or not (like some web registration sites do, to allow the user modify the username until one is available), then I think XMPP doesn't provide that possibility for security reasons: it is not allowed to know if an account exists or not.

A solution for that would be to use the check_account ejabberd command https://docs.ejabberd.im/developer/ejabberd-api/admin-api/#check-account executing it with some frontend, like ejabberdctl, ReST or XMLRPC https://docs.ejabberd.im/admin/guide/managing/#ejabberd-commands

$ ejabberdctl check_account user1 localhost
$ ejabberdctl check_account user6666 localhost
Error: false
~ 1


来源:https://stackoverflow.com/questions/63499864/how-to-search-registered-user-on-ejabberd-server-from-client-side-using-smack-li

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!