存在Stanze for ejabberd不能通过mod_rest模块工作

时间:2014-12-12 11:07:23

标签: rest erlang xmpp ejabberd

目前我正在使用ejabberd 14.05服务器并使用它的mod_rest模块根据来自第三方Web服务的特定条件更新用户在服务器中的存在。但我无法发布存在节来更新用户的存在。以下是我的发现。

命令用于通过mod_rest调用presence节。     curl --verbose --data" World" -X POST servername:5280 / rest / -H" Content-Type:text / xml" -H"接受:application / xml"

日志。

==> error.log <==

2014-12-12 03:00:20.055 [错误]&lt; 0.1199.0&gt;崩溃报告过程&lt; 0.1199.0&gt;与0个邻居崩溃的原因:没有匹配xml的函数子句:get_tag_attr_s(&lt;&lt;&#34;来自&#34;&gt;&gt;,{error,{4,&lt;&lt;&#34;格式不正确(无效令牌)&#34;&gt;&gt;}})第362行

==> ejabberd.log <==
2014-12-12 03:00:20.049 [info] <0.557.0>@ejabberd_listener:accept:313 (#Port<0.6318>) Accepted connection 127.0.0.1:51838 -> 127.0.0.1:5280
2014-12-12 03:00:20.049 [debug] <0.1199.0>@ejabberd_http:init:145 S: [{[<<"rest">>],mod_rest},{[<<"captcha">>],ejabberd_captcha},{[<<"admin">>],ejabberd_web_admin},{[<<"http-bind">>],mod_http_bind},{[<<"http-poll">>],ejabberd_http_poll}]
2014-12-12 03:00:20.049 [info] <0.1199.0>@ejabberd_http:init:149 started: {gen_tcp,#Port<0.6318>}
2014-12-12 03:00:20.050 [debug] <0.1199.0>@ejabberd_http:process_header:277 (#Port<0.6318>) http query: 'POST' /rest/
2014-12-12 03:00:20.050 [debug] <0.1199.0>@ejabberd_http:process_request:438 client data: <<"<message to=user@test.com from=localhost/rest><body>World</body></message>">>
2014-12-12 03:00:20.050 [debug] <0.1199.0>@ejabberd_http:process:350 [<<"rest">>] matches [<<"rest">>]
2014-12-12 03:00:20.050 [debug] <0.1199.0>@ejabberd_http:process:354 [{'Content-Length',<<"108">>},{'Accept',<<"application/xml">>},{'Content-Type',<<"text/xml">>},{'Host',<<"servername:5280">>},{'User-Agent',<<"curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.15.3 zlib/1.2.3 libidn/1.18 libssh2/1.4.2">>}]
2014-12-12 03:00:20.050 [info] <0.1199.0>@mod_rest:maybe_post_request:70 Stanza: {error,{4,<<"not well-formed (invalid token)">>}}
2014-12-12 03:00:20.055 [error] <0.1199.0> CRASH REPORT Process <0.1199.0> with 0 neighbours crashed with reason: no function clause matching xml:get_tag_attr_s(<<"from">>, {error,{4,<<"not well-formed (invalid token)">>}}) line 362

==> error.log <==
2014-12-12 03:00:20.055 [error] <0.311.0> Supervisor ejabberd_http_sup had child undefined started with {ejabberd_http,start_link,undefined} at <0.1199.0> exit with reason function_clause in context child_terminated

==> ejabberd.log <==
2014-12-12 03:00:20.055 [error] <0.311.0> Supervisor ejabberd_http_sup had child undefined started with {ejabberd_http,start_link,undefined} at <0.1199.0> exit with reason function_clause in context child_terminated

它以某种方式无法解析该节。不知道为什么会发生这种情况:(这方面的任何指针都很有用。 另请告诉我,有任何其他方法可以提供帮助。

编辑1:CURL存在一些问题。所以我在chrome中切换到POSTMan客户端。现在这个节至少被解析了。现在的问题是消息节对我有用,但Presence节对我不起作用。我现在能够建立客户端到服务器会话。任何人都可以帮助我。

mod_admin_extra.erl中set_presence方法的代码

命令定义

#ejabberd_commands{name = set_presence,
                    tags = [session],
                    desc = "Set presence of a session",
                    module = ?MODULE, function = set_presence,
                    args = [{user, string}, {host, string},
                            {resource, string}, {type, string},
                            {show, string}, {status, string},
                            {priority, string}],
                    result = {res, rescode}},

指挥机构截至目前,我评论了大部分身体。一旦我得到有效的Pid,我将取消注释剩下的代码。

set_presence(User, Host, Resource, Type, Show, Status, Priority) ->
    Pid = ejabberd_sm:get_session_pid(User, Host, Resource),
%%    USR = User ++ "@" ++ Host ++ "/" ++ Resource,
%%    US = User ++ "@" ++ Host,
%%    Message = {route_xmlstreamelement,
%%             {xmlel, <<"presence">>,
%%              [{<<"from">>, USR}, {<<"to">>, US}, {<<"type">>, Type}],
%%              [{xmlel, <<"show">>, [], [{xmlcdata, Show}]},
%%               {xmlel, <<"status">>, [], [{xmlcdata, Status}]},
%%               {xmlel, <<"priority">>, [], [{xmlcdata, Priority}]}]}},

%%    ?INFO_MSG("Message : ~p~n",[Message]),
    ?INFO_MSG("Pid : ~s~n",[Pid]).
%%    Pid ! Message.

用法

su - root set_presence 2067343756 host 5599628551424712277712378 subscribed dnd Im_away_25_minutes 127

输出

Problem 'error undef' occurred executing the command.
Stacktrace: [{p1_logger,info_msg,[mod_admin_extra,926,"Pid : ~s~n",[none]],[]},
             {ejabberd_ctl,call_command,3,
                           [{file,"src/ejabberd_ctl.erl"},{line,293}]},
             {ejabberd_ctl,try_call_command,3,
                           [{file,"src/ejabberd_ctl.erl"},{line,269}]},
             {ejabberd_ctl,process2,3,
                           [{file,"src/ejabberd_ctl.erl"},{line,218}]},
             {ejabberd_ctl,process,1,
                           [{file,"src/ejabberd_ctl.erl"},{line,203}]},
             {rpc,'-handle_call_call/6-fun-0-',5,
                  [{file,"rpc.erl"},{line,205}]}]

1 个答案:

答案 0 :(得分:2)

我不确定为什么你需要发送一个存在节。

仅发送存在节不足以模拟用户存在。仍然没有任何与该存在节相关联的XMPP会话。

是的,您之前在套接字上发送了错误的XML数据。