[ejabberd] Modifying packet in offline_message_hook

Saúl Ibarra Corretgé saul at ag-projects.com
Fri Feb 17 12:19:37 MSK 2012


Hi all,

I'm trying to achieve something I believe it's quite simple, but my lack of knowledge of Erlang (just started) could be playing me here.

I basically want to add a custom element to a message stanza when I get it in an offline_message hook. This is the simplest possible code that is failing for me:

...
XmlTo = {xmlelement,"agp:foo", [{"value", "bar"}, {"xmlns:agp","ag-projects:xmpp"}], []},
NewPacket = xml:append_subtags(Packet, XmlTo),
...
ejabberd_router:route(_From, Destination, NewPacket),

This gives me a badxml error:

** {{badxml,
     {xmlelement,"message",
      [{"from","saghul at gmail.com/Psi+4A1A4569"},
       {"to","saghul at a.b.c.d"},
       {"type","chat"},
       {"id","a2298a"}],
      [{xmlcdata,<<"\n">>},
       {xmlelement,"body",[],[{xmlcdata,<<"t">>}]},
       {xmlcdata,<<"\n">>},
       {xmlelement,"active",
        [{"xmlns","http://jabber.org/protocol/chatstates"}],
        []},
       {xmlcdata,<<"\n">>},
       {xmlelement,"request",[{"xmlns","urn:xmpp:receipts"}],[]},
       {xmlcdata,<<"\n">>},
       {xmlelement,"nos:x",
        [{"value","disabled"},{"xmlns:nos","google:nosave"}],
        []},
       {xmlelement,"arc:record",
        [{"otr","false"},{"xmlns:arc","http://jabber.org/protocol/archive"}],
        []}|
       {xmlelement,"agp:foo",
        [{"value","bar"},{"xmlns:agp","ag-projects:xmpp"}],
        []}]},
     {function_clause,
      [{xml,'-element_to_string_nocatch/1-lc$^0/1-0-',
        [{xmlelement,"agp:foo",
          [{"value","bar"},{"xmlns:agp","ag-projects:xmpp"}],
          []}]},
       {xml,'-element_to_string_nocatch/1-lc$^0/1-0-',1},
       {xml,element_to_string_nocatch,1},
       {xml,element_to_string,1},
       {xml,element_to_binary,1},
       {ejabberd_service,handle_info,3},
       {p1_fsm,handle_msg,10},
       {proc_lib,init_p_do_apply,3}]}},
    [{xml,element_to_string,1},
     {xml,element_to_binary,1},
     {ejabberd_service,handle_info,3},
     {p1_fsm,handle_msg,10},
     {proc_lib,init_p_do_apply,3}]}

I guess it's a simple mistake, but I can't seem to find it :-S any help would be appreciated.

In case it matters this is ejabberd 2.1.10.


Thanks and regards,

--
Saúl Ibarra Corretgé
AG Projects





More information about the ejabberd mailing list