0

我正在尝试从 android 应用程序向 ejabberd 服务器发送自定义 IQ,并且我有以下课程

public class IQCustom extends IQ {


    public final static String childElementName = "query";
    public final static String childElementNamespace = "jabber:iq:conversations";





    public IQCustom(String userFrom, String server)
    {

        super( childElementName, childElementNamespace );
        this.setType(Type.get);


        setTo( server );
        setFrom( userFrom );
    }


    @Override
    protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {




        xml.rightAngleBracket();

        xml.halfOpenElement("abc");
        xml.attribute("op","sum");
        xml.rightAngleBracket();
        xml.closeElement("abc");



        return xml;
    }
}

这些是我得到的 IQ 日志:

    D/SMACK: SENT (1): <iq to=‘example.com' id='BQ8wt-16' type='get'><query xmlns='jabber:iq:conversations'><abc op='sum'></abc></query></iq>
 D/SMACK: RECV (1): <iq to='testing7@example.com/Smack' from='example.com' type='get' id='BQ8wt-16'><query xmlns='jabber:iq:conversations'><abc op='sum'/></query></iq>
 D/SMACK: RECV (1): <r xmlns='urn:xmpp:sm:3'/>
 D/SMACK: SENT (1): <iq to='example.com' id='BQ8wt-16' type='error'><error type='cancel'><feature-not-implemented xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></iq>
 D/SMACK: SENT (1): <r xmlns='urn:xmpp:sm:3'/>
 D/SMACK: SENT (1): <a xmlns='urn:xmpp:sm:3' h='4'/>
 D/SMACK: RECV (1): <a h='5' xmlns='urn:xmpp:sm:3'/>

我理解我得到的第一次收到 iq 的原因,但我不明白 iq 的原因:

D/SMACK: SENT (1): <iq to='example.com' id='BQ8wt-16' type='error'><error type='cancel'><feature-not-implemented xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></iq>

编辑

这是我发送上述查询时应该执行的模块:

-module(mod_conversations).
-behaviour(gen_mod).
%% ====================================================================
%% API functions
%% ====================================================================
-export([start/2, stop/1, process_local_iq/3]).
-include("ejabberd.hrl").
-include("logger.hrl").
-include("xmpp.hrl").
-define(NS_IQ_CUSTOM, <<"jabber:iq:conversations">>).
start(Host, _) ->
    gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_IQ_CUSTOM, ?MODULE, process_local_iq, one_queue),
    ?INFO_MSG("Inside mod_conversation",[]),
ok.
stop(Host) ->
    gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_IQ_CUSTOM),
ok.
process_local_iq(From,_ ,IQ) ->
    From,
    ?INFO_MSG("Inside mod_conversation, IQ is ~p~n ",[IQ]),
    Sum = 2+2,
    IQ.

在 gen_iq_handler() 内部,我看到处理程序已经注册,所以我现在很困惑,实现该功能意味着什么。

我只想将响应 iq 中的 Sum 值发送给客户端,为此我应该如何准确注册此功能以及如何从该模块向客户端/用户发送 iq 响应而不会出现任何错误 iq?

4

1 回答 1

0

您是否使用 ns xmpp-stanzas 实现了该功能?

于 2018-05-07T06:58:59.547 回答