对于ejabberd而言,Stanze不能通过mod_rest模块工作 [英] Presence Stanze for ejabberd NOT working via mod_rest module

查看:291
本文介绍了对于ejabberd而言,Stanze不能通过mod_rest模块工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



命令用于通过mod_rest调用存在节。
curl --verbose --dataWorld-X POST servername:5280 / rest / -HContent-Type:text / xml-HAccept:application / xml



日志。

  ==> error.log< == 

2014-12-12 03:00:20.055 [error]< ; 0.1199.0> CRASH REPORT Process< 0.1199.0> 0个邻居崩溃,原因如下:no function clause matching xml:get_tag_attr_s(<from>>,{error,{4,<不正确的(无效的令牌)>>}})line 362

  ==> ejabberd.log< == 
2014-12-12 03:00:20.049 [info]< 0.557.0> @ejabberd_listener:accept:313(#Port <0.6318)接受的连接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},{并[d< 验证码 >>],ejabberd_captcha},{并[d< 管理员 >>],ejabberd_web_admin},{并[d<HTTP-绑定>>],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查询:'POST'/ rest /
2014-12-12 03:00:20.050 [debug]< 0.1199.0> @ejabberd_http:process_request:438客户端数据: << 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>]匹配[< >>]
2014-12-12 03:00:20.050 [debug]< 0.1199.0> @ejabberd_http:process:354 [{'Content-Length',<108 >>},{ '接受',<< 应用程序/ xml 的>>},{ '内容类型',<< 文本/ xml 的>>},{主机',<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: may_post_request:70 Stanza:{error,{4,<not well-formed(invalid token)>>}}
2014-12-12 03:00:20.055 [error] 0.1199.0>冲突报告过程< 0.1199.0> 0个邻居崩溃,原因如下: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>主管ejabberd_http_sup有孩子未定义开始于{ejabberd_http,start_link,undefined}在< 0.1199.0>退出原因function_clause在上下文child_terminated

==> ejabberd.log< ==
2014-12-12 03:00:20.055 [error]< 0.311.0>主管ejabberd_http_sup有孩子未定义开始于{ejabberd_http,start_link,undefined}在< 0.1199.0>退出原因function_clause在上下文child_terminated

它以某种方式无法解析该节。不知道为什么会发生这种情况:(任何指向这个方向的指针都很有用
请同时让我知道有其他的做法也是有帮助的。



编辑1:CURL有一些问题,所以我在chrome中切换到POSTMan Client。现在这个节至少被解析了,现在的问题是消息节是为我工作的,但是Presence节没有工作对我来说,我现在可以建立客户端到服务器会话。任何一个请帮助我。



mod_admin_extra.erl中的set_presence方法代码



命令定义

  #ejabberd_commands {name = set_presence,
tags = [session],
desc =设置会话的存在,
module =?MODULE,function = set_presence,
args = [{user,string},{host,string},
{re source,string},{type,string},
{show,string},{status,string},
{priority,string}],
result = {res,rescode}} ,

命令正文到目前为止,我已经评论过大部分的身体。一旦我得到了有效的Pid,我将取消对其余代码的注释。

  set_presence(用户,主机,资源,类型,显示,状态,优先级) - > 
Pid = ejabberd_sm:get_session_pid(用户,主机,资源),
%% USR =用户++@++主机++/++资源,
%% US = User ++@++ Host,
%% Message = {route_xmlstreamelement,
%% {xmlel,<presence>>&$,
%% [ {<,>>,USR},{<至>> b $ b %% [{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!信息。

用法

  su  -  root set_presence 2067343756主机5599628551424712277712378订阅dnd Im_away_25_minutes 127 

输出

 执行命令时出现问题'error undef'。 
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,进程1,
[{file,src / ejabberd_ctl.erl},{line,203}]},
{rpc,' - handle_call_call / 6-fun-0 - ',5,
[{file,rpc.erl},{line,205}]}]


解决方案

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



只发送一个存在节是不够的模拟用户存在。



是的,您以前在套接字上发送不正确的XML数据。


Currently i am using ejabberd 14.05 server and using it`s mod_rest module to update the presence of the user from server based on a certain condition from a 3rd party web service. But i am not able to post the presence stanza to update the presence of user. Below are my finding.

command using to invoke the presence stanza via mod_rest. curl --verbose --data "World" -X POST servername:5280/rest/ -H "Content-Type: text/xml" -H "Accept: application/xml"

logs.

==> error.log <==

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

==> 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

Its somehow not able to parse the stanza. Not sure why this is happening :( Any pointers in this direction are useful. Please also let me know there is any another approach to do this would be also helpful.

EDIT 1: There was some issue with the CURL. So i switched to POSTMan Client in chrome.Now the stanza are atleast getting parsed. Now the issue is that the message stanza is working for me but the Presence stanza is not working for me. I am now able to establish the client to server session.Can any one please help me with it.

Code for set_presence method in mod_admin_extra.erl

Command definition

#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}},

Command Body As of now i have commented most of the body. Once i get the valid Pid, i will uncomment the rest of the code.

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.

Usage

su - root set_presence 2067343756 host 5599628551424712277712378 subscribed dnd Im_away_25_minutes 127

Output

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}]}]

解决方案

I am not sure why you would need to send a presence stanza.

Sending just a presence stanza is not enough to simulate user presence. There will still not be any XMPP sessions associated with that presence stanza.

And yes, you were sending incorrect XML data on the socket previously.

这篇关于对于ejabberd而言,Stanze不能通过mod_rest模块工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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