Posted this issue on ejabberd's forum and got no response so I am posting it here (https://www.ejabberd.im/forum/25371/tracking-roster-and-presence-cause-error). I created a simple ejabberd module to log all the events for roster and presence. I am trying to understand the order of event and the parameters at each event. Everything seem to work except that I am seeing 2 errors in the ejabberd log file and I am not sure how to fix them since all I am doing is just writing to the log file.
Module Code (mod_monitor_roster):
start(Host, Opt) ->
?INFO_MSG("Monitor Roster Started for Host (~p) and Opt(~p)...~n", [Host, Opt]),
%%Add the roster hooks here...
ejabberd_hooks:add(roster_process_item, Host, ?MODULE, process_item, 10),
ejabberd_hooks:add(roster_get, Host, ?MODULE, rosterget, 10),
ejabberd_hooks:add(roster_get_jid_info, Host, ?MODULE, rostergetjidinfo, 10),
ejabberd_hooks:add(roster_get_subscription_lists, Host, ?MODULE, rostergetsubscriptionlists, 10),
ejabberd_hooks:add(roster_get_versioning_feature, Host, ?MODULE, rostergetversioningfeature, 10),
ejabberd_hooks:add(roster_groups, Host, ?MODULE, rostergroup, 10),
ejabberd_hooks:add(roster_in_subscription, Host, ?MODULE, rosterinsubscription, 10),
ejabberd_hooks:add(roster_out_subscription, Host, ?MODULE, rosteroutsubscription, 10),
ejabberd_hooks:add(set_presence_hook, Host, ?MODULE, setpresencehook, 1),
%%ejabberd_hooks:add(resend_subscription_requests_hook, Host, ?MODULE, resendsubscriptionrequestshook, 50),
ok.
process_item(Acc, Server) ->
?INFO_MSG("Roster process Item... Acc= ~p~n Server= ~p~n", [Acc, Server]).
rosterget(Acc, {User,Server}) ->
?INFO_MSG("Roster Get.... Acc= ~p~n User/Server= ~p~n", [Acc, {User,Server}]).
rostergetjidinfo(Acc, User, Server, From) ->
?INFO_MSG("Roster Get Jid Info.... Acc= ~p~n User= ~p.~n Server= ~p~n From= ~p~n", [Acc, User,Server, From]).
rostergetsubscriptionlists(Acc, User, Server) ->
?INFO_MSG("Roster Get Subscription List.... Acc= ~p~n User= ~p~n Server= ~p~n", [Acc, User,Server]).
rostergetversioningfeature(Acc, User, Server) ->
?INFO_MSG("Roster Get Versioning Feature.... Acc= ~p~n User= ~p~n Server= ~p~n", [Acc, User,Server]),
[].
rostergroup(Acc, ServerHost) ->
?INFO_MSG("Roster Group.... Acc= ~p~n ServerHost= ~p~n", [Acc, ServerHost]).
rosterinsubscription(Acc, User, Server, From, SubscriptionInType, Reason) ->
?INFO_MSG("Roster In Subscription.... Acc= ~p~n User= ~p.~n Server= ~p~n From= ~p~n SubscriptionType= ~p~n Reason= ~p~n", [Acc, User,Server, From, SubscriptionInType, Reason]).
rosteroutsubscription(Acc, Server, To, SubscriptionOutType) ->
?INFO_MSG("Roster Out Subscription.... Acc= ~p~n Server= ~p~n To= ~p~n SubscriptionType= ~p~n", [Acc, Server, To, SubscriptionOutType]).
setpresencehook(User, Server, Resource, Presence) ->
?INFO_MSG("Set Presence Hook.... User= ~p~n Server= ~p~n Resource= ~p~n Presence= ~p~n", [User, Server, Resource, Presence]),
ok.
resendsubscriptionrequestshook(Acc, User, Server) ->
?INFO_MSG("Resend Subscription Request Hook.... Acc= ~p~n User= ~p~n Server= ~p~n", [Acc, User,Server]).
The ejabberd log entries (showing the errors):
2016-02-10 22:10:07.975 [error] <0.5735.0>@ejabberd_hooks:run_fold1:368 {undef,[{mod_monitor_roster,rostergetversioningfeature,[[],<<"adminpc">>],[]},{ejabberd_hooks,safe_apply,3,[{file,"src/ejabberd_hooks.erl"},{line,382}]},{ejabberd_hooks,run_fold1,4,[{file,"src/ejabberd_hooks.erl"},{line,365}]},{ejabberd_c2s,wait_for_stream,2,[{file,"src/ejabberd_c2s.erl"},{line,463}]},{p1_fsm,handle_msg,10,[{file,"src/p1_fsm.erl"},{line,582}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,237}]}]} running hook: {roster_get_versioning_feature,[<<"adminpc">>]}
2016-02-10 22:10:08.178 [info] <0.5735.0>@ejabberd_c2s:wait_for_session:1117 ({socket_state,p1_tls,{tlssock,#Port<0.6781>,#Port<0.6784>},<0.5734.0>}) Opened session for karen@adminpc/adminPC
2016-02-10 22:10:08.178 [info] <0.5735.0>@mod_monitor_roster:rostergetsubscriptionlists:93 Roster Get Subscription List.... Acc= {[],[]} User= <<"karen">> Server= <<"adminpc">>
2016-02-10 22:10:08.255 [info] <0.451.0>@mod_monitor_roster:rosterget:87 Roster Get.... Acc= [] User/Server= {<<"karen">>,<<"adminpc">>}
2016-02-10 22:10:08.256 [error] <0.451.0>@ejabberd_hooks:run_fold1:368 {function_clause,[{lists,mapfoldl,[#Fun<mod_shared_roster.1.107782361>,{dict,0,16,16,8,80,48,{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},{{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]}}},ok],[{file,"lists.erl"},{line,1351}]},{lists,mapfoldl,3,[{file,"lists.erl"},{line,1353}]},{lists,mapfoldl,3,[{file,"lists.erl"},{line,1353}]},{mod_shared_roster,get_user_roster,2,[{file,"src/mod_shared_roster.erl"},{line,148}]},{ejabberd_hooks,safe_apply,3,[{file,"src/ejabberd_hooks.erl"},{line,382}]},{ejabberd_hooks,run_fold1,4,[{file,"src/ejabberd_hooks.erl"},{line,365}]},{mod_roster,process_iq_get,3,[{file,"src/mod_roster.erl"},{line,316}]},{gen_iq_handler,process_iq,6,[{file,"src/gen_iq_handler.erl"},{line,127}]}]} running hook: {roster_get,[{<<"karen">>,<<"adminpc">>}]}
2016-02-10 22:10:08.272 [info] <0.5735.0>@mod_monitor_roster:setpresencehook:109 Set Presence Hook.... User=<<"karen">> Server= <<"adminpc">> Resource= <<"adminPC">> Presence= {xmlel,<<"presence">>,[{<<"xml:lang">>,<<"en">>}],[{xmlcdata,<<"\n">>},{xmlel,<<"priority">>,[],[{xmlcdata,<<"5">>}]},{xmlcdata,<<"\n">>},{xmlel,<<"c">>,[{<<"xmlns">>,<<"http://jabber.org/protocol/caps">>},{<<"node">>,<<"http://psi-im.org/caps">>},{<<"ver">>,<<"caps-b75d8d2b25">>},{<<"ext">>,<<"ca cs ep-notify-2 html">>}],[]},{xmlcdata,<<"\n">>}]}
2016-02-10 22:12:41.994 [info] <0.475.0>@ejabberd_listener:accept:299 (#Port<0.6792>) Accepted connection 127.0.0.1:23595 -> 127.0.0.1:5280
Hope I have provided all the information
Regards,
Will
For the mapfoldl
function_clause
error, the problem is your function for the roster_get
hook. The functions that are added to this hook get a list of users, and are supposed to add their own entries to this list and pass it on. This is done through ejabberd_hook:run_fold
. However, since your rosterget
function just prints a debug message, it returns ok
instead of the list to pass on, and this later on leads to an error in the bowels of mod_shared_roster
, since it passes what it thinks is a list to lists:mapfoldl
, but it's actually the atom ok
.
To fix this, return the Acc
value from the rosterget
function, like this:
rosterget(Acc, {User,Server}) ->
?INFO_MSG("Roster Get.... Acc= ~p~n User/Server= ~p~n", [Acc, {User,Server}]),
Acc.
I suspect you need to do the same for all those functions that get an Acc
argument.