0
votes

i have ejabberd 15.07 and using mod_ack module while trying to get id from packet getting this error ?

return_message_reciept_to_sender(From, _To, Packet) ->
    ReturnRecieptType = "serverreceipt",
    MessageId = xml:get_tag_attr_s(<<"id">>, Packet),
    ?INFO_MSG("mod_echo_receipt - MsgID: ~p To: ~p From: ~p", [MessageId, _To, From]),
    send_message(From, _To, ReturnRecieptType, MessageId).

Error log :

[error] <0.437.0>@ejabberd_hooks:run_fold1:371 {function_clause,[{xml,get_tag_attr_s,[<<"id">>,{jid,<<"xxxxxx">>,<<" xxxxxx">>,<<>>,<<"xxxxxx">>,<<" xxxxxx">>,<<>>}],[{file,"src/xml.erl"},{line,210}]},{mod_ack,return_message_reciept_to_sender,3,[{file,"src/mod_ack.erl"},{line,36}]},{mod_ack,on_user_send_packet,4,[{file,"src/mod_ack.erl"},{line,30}]},{ejabberd_hooks,safe_apply,3,[{file,"src/ejabberd_hooks.erl"},{line,385}]},{ejabberd_hooks,run_fold1,4,[{file,"src/ejabberd_hooks.erl"},{line,368}]},{ejabberd_c2s,session_established2,2,[{file,"src/ejabberd_c2s.erl"},{line,1296}]},{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}]}]}

1

1 Answers

2
votes

The source on github shows:

-spec(get_tag_attr_s/2 ::
(
  AttrName :: binary(),
  Xmlel    :: xmlel())
    -> binary()
).

get_tag_attr_s(AttrName, #xmlel{attrs = Attrs}) ->
    get_attr_s(AttrName, Attrs).

If the second argument is not an xmlel record, the pattern match will fail and you will get that function_clause error.

You are passing a 7-tuple instead of the proper record. If you want to build your own record to pass, you will have to match the definition of the record in xml.hrl:

-record(xmlel,
{
    name = <<"">> :: binary(),
    attrs    = [] :: [attr()],
    children = [] :: [xmlel() | cdata()]
}).

-type(cdata() :: {xmlcdata, CData::binary()}).

-type(attr() :: {Name::binary(), Value::binary()}).

-type(xmlel() :: #xmlel{}).

If this function is being called by the code in your other question you probably need to change the order of the arguments of on_user_send_packet to match the ejabberd hook.