[ejabberd] process_received_packet hook (ejabberd alpha 3) [SOLVED]

Samuel Wejéus samuelw at opera.com
Fri Aug 5 18:47:05 MSD 2011


Hmm after some digging i found the problem. It had to to with the module 
for offline messages (mod_offline_json) which is a custom module i 
written myself... shame on me...

The reason is that when you route messages from offline module (done in 
the same way in original mod_offline) the route modules use the contents 
of the record #offline_msg with whatever you supply to it like (in my case)

{route,R#offline_msg.from,R#offline_msg.to,exmpp_xml:append_children(Packet,[TimeXml, 
TimeXml91])}

Here #offline_msg.from only contains a list and that is what gets passed 
on to other functions that use this hook.

A potential patch to include in ejabberd is to let the route module 
check the type of the fields, like IS_JID(from) if not raise an error.

Kind regards,

Samuel

On 08/05/2011 04:32 PM, Samuel Wejéus wrote:
> UPDATE:
>
> Yes it can! (sometimes..) For instance on a roster update you can get 
> messages from yourself.. But the problem is still there, with code 
> like this:
>
> process_message(Direction, From, To, MessagePacket) ->
>     Type = exmpp_message:get_type(MessagePacket),
>     if (Type /= <<"error">>) and (Type /= <<"groupchat">>) and (Type 
> /= <<"headline">>) ->
>         LFrom = exmpp_jid:bare_to_list(From),
>         LTo = exmpp_jid:bare_to_list(To),
>         MessageBody = exmpp_message:get_body(MessagePacket),
>         ?INFO_MSG("****** Intercepted ~p message FROM: ~p TO: ~p BODY: 
> ~p",[Direction, LFrom, LTo, MessageBody]);
>     true -> ok
>     end,
>     ok.
>
> To handle just message type stanzas From and To is still the same jid..
>
>
> On 08/05/2011 04:24 PM, Samuel Wejéus wrote:
>> Hello list!
>>
>> I'm writing a module where i need to intercept stanzas of type 
>> 'message' sent between users and came across an odd behaviour:
>>
>> I set up two hooks:
>>
>> ejabberd_hooks:add(user_send_packet, HostB, ?MODULE, 
>> process_sent_packet, 50),
>> ejabberd_hooks:add(user_receive_packet, HostB, ?MODULE, 
>> process_receive_packet, 50).
>>
>> And the handler look like this (for now..)
>>
>> process_receive_packet(JID, From, To, Packet) ->
>> ?INFO_MSG("####### ~p~n~p~n~p~n",[JID,From,To]),
>>     case exmpp_message:is_message(Packet) of
>>         true -> process_message(received, From, To, Packet);
>>         _ -> ok
>>     end.
>>
>> The problem is the output from ?INFO_MSG gives:
>>
>> =INFO REPORT==== 5-Aug-2011::16:18:04 ===
>> I(<0.510.0>:mod_chatlog:41) : ####### {jid,
>> <<"megatron at decepticons.com/undefined">>,
>> <<"megatron">>,<<"decepticons.com">>,
>> <<"undefined">>}
>> {jid,<<"megatron at decepticons.com/undefined">>,<<"megatron">>,
>> <<"decepticons.com">>,<<"undefined">>}
>> {jid,<<"megatron at decepticons.com/undefined">>,<<"megatron">>,
>> <<"decepticons.com">>,<<"undefined">>}
>>
>> This cant be right, can it?
>>
>> JID, From and To contains the same user?
>>
>> Kind regards,
>>
>> Samuel
>>
>> _______________________________________________
>> ejabberd mailing list
>> ejabberd at jabber.ru
>> http://lists.jabber.ru/mailman/listinfo/ejabberd
>
> _______________________________________________
> ejabberd mailing list
> ejabberd at jabber.ru
> http://lists.jabber.ru/mailman/listinfo/ejabberd



More information about the ejabberd mailing list