0
votes

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 [email protected] 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}]}]
1

1 Answers

2
votes

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.