[ejabberd] process_received_packet hook (ejabberd alpha 3)

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


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



More information about the ejabberd mailing list