Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function clause error when using exmpp function

Previously I was using xml:get_tag_attr_s("type", Packet) for that debug line in ejabberd 2.1.10, but that is not working anymore in ejabberd 13.03. Probably because it is deprecated according to the docs (http://www.process-one.net/docs/exmpp/devdoc/trunk/xml.html#get_attr_s-2), so I tried using a function from exmpp library.

I am getting an error on the second DEBUG line (First debug line works fine). And ideas how to get the value from the attribute?

Code excerpt:

 on_user_send_packet(From, To, Packet) ->
  ?DEBUG("Sent packet (1): ~p", [Packet]),
  Type = exmpp_xml:get_attribute(Packet, <<"type">>, <<"unknown">>),
  ?DEBUG("Sent packet from (2): ~p", [From]),

Log:

  =INFO REPORT==== 2013-05-25 09:58:50 ===
  D(<0.1625.0>:mod_stanza_ack:59) : Sent packet (1): {xmlel,<<"message">>,
                                                [{<<"to">>,
                                                  <<"31600000002@whatsupp_dev">>},
                                                 {<<"from">>,
                                                  <<"31600000001@whatsupp_dev/webapp">>},
                                                 {<<"type">>,<<"chat">>},
                                                 {<<"id">>,<<"4834">>}],
                                                [{xmlel,<<"body">>,[],
                                                  [{xmlcdata,
                                                    <<"SHOOOOOT">>}]},
                                                 {xmlel,<<"request">>,
                                                  [{<<"xmlns">>,
                                                    <<"urn:xmpp:receipts">>}],
                                                  []}]}

 =ERROR REPORT==== 2013-05-25 09:58:50 ===
 E(<0.1625.0>:ejabberd_hooks:315) : {function_clause,
                                [{exmpp_xml,get_attribute,
                                  [{xmlel,<<"message">>,
                                    [{<<"to">>,
                                      <<"31600000002@whatsupp_dev">>},
                                     {<<"from">>,
                                      <<"31600000001@whatsupp_dev/webapp">>},
                                     {<<"type">>,<<"chat">>},
                                     {<<"id">>,<<"4834">>}],
                                    [{xmlel,<<"body">>,[],
                                      [{xmlcdata,<<"SHOOOOOT">>}]},
                                     {xmlel,<<"request">>,
                                      [{<<"xmlns">>,
                                        <<"urn:xmpp:receipts">>}],
                                      []}]},
                                   <<"from">>,<<"unknown">>],
                                  [{file,"./core/exmpp_xml.erl"},
                                   {line,1173}]},
                                 {mod_stanza_ack,on_user_send_packet,3,
                                  [{file,"mod_stanza_ack.erl"},{line,60}]},
                                 {ejabberd_hooks,run1,3,
                                  [{file,"ejabberd_hooks.erl"},
                                   {line,311}]},
                                 {ejabberd_c2s,session_established2,2,
                                  [{file,"ejabberd_c2s.erl"},{line,1136}]},
                                 {p1_fsm,handle_msg,10,
                                  [{file,"p1_fsm.erl"},{line,578}]},
                                 {proc_lib,init_p_do_apply,3,
                                  [{file,"proc_lib.erl"},{line,239}]}]}
like image 945
Kay Tsar Avatar asked May 25 '13 08:05

Kay Tsar


2 Answers

The Packet that you're passing to exmpp_xml:get_attribute is an xmlel record with three fields: element name, attributes and child elements. However, exmpp defines the xmlel record with five elements (definition from here):

% Elements.
-record(xmlel, {
  ns = undefined :: xmlname() | undefined,
  declared_ns = [] :: [{xmlname(), string() | none}],
  name :: xmlname(),
  attrs = [] :: [xmlattr()],
  children = [] :: [#xmlel{} | xmlcdata()] | undefined
}).

I had a quick look at the ejabberd 13.03 source code, and it looks like xml:get_tag_attr_s should work fine, so I suspect that ejabberd 13.03 is not compatible with exmpp. (Though I haven't followed ejabberd development closely lately, so more insight about that would be appreciated.) I think you'd be better off trying to figure out why get_tag_attr_s breaks for you.

like image 196
legoscia Avatar answered Oct 01 '22 14:10

legoscia


Pre ejabberd 13.XX

xml:get_tag_attr_s("type", Packet)

Post ejabberd 13.XX

xml:get_tag_attr_s(<<"type">>, Packet) 
like image 35
Kay Tsar Avatar answered Oct 01 '22 14:10

Kay Tsar