我有ejabberd 15.07并在尝试从数据包中获取id时使用mod_ack模块获取此错误?
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).
错误日志:
[错误]&lt; 0.437.0&gt; @ejabberd_hooks:run_fold1:371 {function_clause,[{xml,get_tag_attr_s,[&lt;&lt;“id”&gt;&gt;,{jid,&lt;&lt;“xxxxxx” &gt;&gt;,&lt;&lt;“xxxxxx”&gt;&gt;,&lt;&lt;&gt;&gt;,&lt;&lt;“xxxxxx”&gt;&gt;,&lt;&lt;“xxxxxx”&gt;&gt;, &LT;&LT;&GT;&GT;}],[{文件, “SRC / xml.erl”},{线,210}]},{mod_ack,return_message_reciept_to_sender,3,[{文件, “SRC / mod_ack.erl” },{线,36}]},{mod_ack,on_user_send_packet,4,[{文件, “SRC / mod_ack.erl”},{线,30}]},{ejabberd_hooks,safe_apply,3,[{文件,” SRC / ejabberd_hooks.erl “},{线,385}]},{ejabberd_hooks,run_fold1,4,[{文件,” SRC / ejabberd_hooks.erl“},{线,368}]},{ejabberd_c2s,session_established2,2 ,[{文件, “SRC / ejabberd_c2s.erl”},{线,1296}]},{p1_fsm,HANDLE_MSG,10,[{文件, “SRC / p1_fsm.erl”},{线,582}]}, {proc_lib,init_p_do_apply,3,[{文件, “proc_lib.erl”},{线,237}]}]}
答案 0 :(得分:2)
-spec(get_tag_attr_s/2 ::
(
AttrName :: binary(),
Xmlel :: xmlel())
-> binary()
).
get_tag_attr_s(AttrName, #xmlel{attrs = Attrs}) ->
get_attr_s(AttrName, Attrs).
如果第二个参数是不一个xmlel
记录,则模式匹配将失败,您将得到该function_clause错误。
你传递的是7元组而不是正确的记录。如果要构建自己的记录以进行传递,则必须匹配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{}).
如果your other question中的代码正在调用此函数,则可能需要更改on_user_send_packet
的参数的顺序以匹配ejabberd挂钩。