Ejabberd自定义IQ处理程序:获取功能未实现或服务不可用 [英] Ejabberd custom IQ Handler: getting feature-not-implemented or service-unavailable

查看:169
本文介绍了Ejabberd自定义IQ处理程序:获取功能未实现或服务不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我剥离了 mod_last.erl 以测试创建IQHandler(仅粘贴重要部分):

  start(Host,Opts) - > 
IQDisc = gen_mod:get_opt(iqdisc,opts,fun gen_iq_handler:check_type / 1,
one_queue),
gen_iq_handler:add_iq_handler(ejabberd_local,Host,
< >>,... MODULE,process_local_iq,IQDisc)。

stop(主机) - >
gen_iq_handler:remove_iq_handler(ejabberd_local,Host,
<join>>)。

process_local_iq(_From,_To,
#iq {type = Type,sub_el = SubEl} = IQ) - >
case类型
set - >
IQ#iq {type = error,sub_el = [SubEl,?ERR_NOT_ALLOWED]};
get - >
Sec = 60,
IQ#iq {type = result,
sub_el =
[#xmlel {name =<query>> $ b attrs =
[{<xmlns>><<join>>},
{<seconds>> ;
iolist_to_binary(integer_to_list(Sec))}],
children = []}]}
end。

但是当我发送请求时:

 < iq type ='get'id ='123'> 
< query xmlns ='join'/>
< / iq>

我继续收到服务不可用错误:

 < iq from ='alfred @ localhost'to ='alfred @ localhost / Alfreds-MacBook-Pro'type ='error'id =' 123' > 
< query xmlns ='join'/>
< error code ='503'type ='cancel'>
< service-unavailable xmlns ='urn:ietf:params:xml:ns:xmpp-stanzas'/>
< / error>
< / iq>

A 类似的问题没有帮助,因为我没有将添加到。注意:我要创建的IQHandler是要求加入游戏室。

解决方案

如果您发送没有属性的IQ节,服务器将代表发送实体处理节( RFC 6120,第10.3.3节)。实际上,这意味着服务器将会对节进行处理,就好像属性是用户的裸JID,在这种情况下 alfred @当您调用 gen_iq_handler:add_iq_handler 注册新的处理程序时,您将还指定范围, ejabberd_local ejabberd_sm (SM表示会话管理器)。如果它是 ejabberd_local ,处理程序将对服务器本身的IQ节做出反应,在这种情况下 localhost 。如果它是 ejabberd_sm ,则处理程序将对寻址到本地用户的裸JID的IQ节进行响应。 alfred @ localhost



所以这就是为什么你的智商节最终没有得到处理。或者在发送请求时包含 to =localhost,或将 ejabberd_local 更改为 ejabberd_sm 注册处理程序。


I stripped mod_last.erl to test the creation of a IQHandler (pasted only the part that matters):

start(Host, Opts) ->
    IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1,
                             one_queue),
    gen_iq_handler:add_iq_handler(ejabberd_local, Host,
                  <<"join">>, ?MODULE, process_local_iq, IQDisc).

stop(Host) ->
    gen_iq_handler:remove_iq_handler(ejabberd_local, Host,
                     <<"join">>).

process_local_iq(_From, _To,
         #iq{type = Type, sub_el = SubEl} = IQ) ->
    case Type of
      set ->
      IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
      get ->
      Sec = 60,
      IQ#iq{type = result,
        sub_el =
            [#xmlel{name = <<"query">>,
                attrs =
                [{<<"xmlns">>, <<"join">>},
                 {<<"seconds">>,
                  iolist_to_binary(integer_to_list(Sec))}],
                children = []}]}
    end.

But when I send the request:

<iq type='get' id='123'>
    <query xmlns='join'/>
</iq>

I keep getting the service-unavailable error:

<iq from='alfred@localhost' to='alfred@localhost/Alfreds-MacBook-Pro' type='error' id='123'>
<query xmlns='join'/>
<error code='503' type='cancel'>
    <service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
</error>
</iq>

A similar question wasn't helpful, since I'm not adding to.

Note: the IQHandler that I want to create is to request joining game rooms.

解决方案

If you send an IQ stanza without a to attribute, the server will "handle the stanza on behalf of the sending entity" (RFC 6120, section 10.3.3). In practice, that means that the server will treat the stanza as if the to attribute had been the bare JID of the user, in this case alfred@localhost.

When you call gen_iq_handler:add_iq_handler to register a new handler, you also specify the "scope", either ejabberd_local or ejabberd_sm ("SM" stands for "session manager"). If it's ejabberd_local, the handler will react to IQ stanzas addressed to the server itself, in this case localhost. If it's ejabberd_sm, the handler will react to IQ stanzas addressed to the bare JID of a local user, e.g. alfred@localhost.

So that's why your IQ stanza ends up not being handled. Either include to="localhost" when sending the request, or change ejabberd_local to ejabberd_sm when registering the handler.

这篇关于Ejabberd自定义IQ处理程序:获取功能未实现或服务不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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