5

以前我在 ejabberd 2.1.10 中使用 xml:get_tag_attr_s("type", Packet) 作为调试行,但在 ejabberd 13.03 中不再起作用。可能是因为根据文档(http://www.process-one.net/docs/exmpp/devdoc/trunk/xml.html#get_attr_s-2)已弃用它,所以我尝试使用 exmpp 库中的函数。

我在第二个 DEBUG 行上遇到错误(第一个调试行工作正常)。以及如何从属性中获取值的想法?

代码摘录:

 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]),

日志:

  =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}]}]}
4

3 回答 3

6

Packet您传递给的exmpp_xml:get_attribute是一个xmlel包含三个字段的记录:元素名称、属性和子元素。但是, exmppxmlel用五个元素定义记录(定义来自这里):

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

我快速浏览了 ejabberd 13.03 源代码,看起来xml:get_tag_attr_s应该可以正常工作,所以我怀疑 ejabberd 13.03 与 exmpp 不兼容。(尽管我最近没有密切关注 ejabberd 的发展,所以对此有更多的了解将不胜感激。)我认为你最好尝试找出为什么get_tag_attr_s会中断。

于 2013-05-25T10:44:40.967 回答
1

前 ejabberd 13.XX

xml:get_tag_attr_s("type", Packet)

发布 ejabberd 13.XX

xml:get_tag_attr_s(<<"type">>, Packet) 
于 2016-04-04T09:57:12.450 回答
0

在 ejabberd 16.04 上应该是

fxml:get_tag_attr_s(<<"type">>, 数据包)

于 2016-05-25T18:48:30.547 回答