如何使用smack库从客户端搜索ejabberd服务器上的注册用户? [英] How to search registered user on ejabberd server from client side using smack library?

查看:83
本文介绍了如何使用smack库从客户端搜索ejabberd服务器上的注册用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在客户端使用smack.我尝试在客户端上搜索已注册的用户,因为在创建新用户之前,我想知道该ID是否已在服务器上注册(如果未注册),则可以创建该用户或者登录该用户,但是ejabberd服务器因该错误而崩溃.这是ejabberd服务器的崩溃日志.

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());
    }

服务器在 ReportedData数据= search.getSearchResults(answerForm,s ;; 代码行)上崩溃.

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

推荐答案

您在ejabberd中发现了一个错误:

You found a bug in ejabberd:

  1. 该问题已于2018年修复 https://github.com/processone/ejabberd/commit/1be21126342d503205798605725ba5ceef9de42b
  2. >
  3. 但该错误于2019年重新引入 https://github.com/processone/ejabberd78247357171f613241ed580c3e5dad2b4526503f2R12
  4. 并且我现在在中应用了一个临时修复程序 https://github.com/processone/ejabberd/commit/92913389a51ddc564f11e0712b9d>
  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

但是,即使该错误已修复,您想要使用的功能也可能无济于事:用户必须设置其vCard才能在vJud搜索中提供其帐户.换句话说,vJUD在存储的vCard中搜索,而不是在注册帐户中搜索.如果我注册了一个帐户但未设置vCard,则vJUD将找不到它.

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.

在创建新用户之前,我想知道该ID是否已在服务器上注册

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?

另一方面,如果您想预先检查一个帐户是否可以注册(就像某些网站注册网站一样,允许用户修改用户名直到一个可用),那么我认为XMPP出于安全原因没有提供这种可能性:不允许知道帐户是否存在.

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.

一个解决方案是使用check_account ejabberd命令 https://docs.ejabberd.im/developer/ejabberd-api/admin-api/#check-account 用一些前端执行它,例如ejabberdctl,ReST或XMLRPC https://docs.ejabberd.im/admin/guide/managing/#ejabberd命令

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

这篇关于如何使用smack库从客户端搜索ejabberd服务器上的注册用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆