0

我有示例模块,

-module(mod_iq_test).
-behaviour(gen_mod).
-export([start/2,
         init/2,
         stop/1,
         process_sm_iq/3
    ]).

-define(PROCNAME, ?MODULE).

-include("ejabberd.hrl").
-include("jlib.hrl").
-include("logger.hrl").

-define(NS_TEST, <<"http://jabber.org/protocol/test">>).

start(Host, Opts) ->
    ?INFO_MSG("Loading module 'mod_iqtest' v.01", []),
    ok.

init(Host, _Opts) ->
    IQDisc = gen_mod:get_opt(iqdisc, _Opts, fun(A) -> A end, one_queue),
    gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_TEST, ?MODULE, process_sm_iq, IQDisc),
    ?INFO_MSG("added iq handlers 'mod_iqtest' v.01", []),
    ok.

stop(Host) ->
    gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_TEST),
    ?INFO_MSG("Stoping module 'mod_iqtest' ", []),
    ok.

process_sm_iq(_From, _To, IQ) ->
    ?INFO_MSG("Processing IQ Get query:~n ~p", [IQ]),
    IQ#iq{type = result, sub_el = [{xmlel, <<"value">>, [], [{xmlcdata, <<"Hello World of Testing.">>}]}]}.

在发送智商的同时,

<iq type='get'>
  <query xmlns='http://jabber.org/protocol/test'/>
</iq>
<r xmlns="urn:xmpp:sm:3"/>

它抛出一个错误,

<iq type="error">
  <query xmlns="http://jabber.org/protocol/test"/>
<error code="400" type="modify">
<bad-request xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
<text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" xml:lang="en">Missing attribute 'id' in tag &lt;iq/&gt; qualified by namespace 'jabber:client'</text>
</error>
</iq>
4

1 回答 1

0

尝试提供一个 id 属性,如错误响应中所述:

<iq type='get' id='aaa8821'>
  <query xmlns='http://jabber.org/protocol/test'/>
</iq>
于 2018-05-30T16:14:04.577 回答