如何从 ejabberd 数据包对象获取数据?
How to get data from ejabberd packet object?
我有一个包含数据包数据的打印日志,我使用 Packet#message.sub_els
提取子元素,它给我这样的数组:
[
{xmlel,<<"delay">>,[{<<"xmlns">>,<<"urn:xmpp:delay">>},{<<"stamp">>,<<"2019-10-24T08:08:15.126+00:00">>}],[]},
{xmlel,<<"type">>,[{<<"xmlns">>,<<"urn:xmpp:media">>}],[{xmlcdata,<<"1">>}]},
{xmlel,<<"media">>,[{<<"xmlns">>,<<"urn:xmpp:data">>}],[{xmlcdata,<<"null">>}]},
{xmlel,<<"extra">>,[{<<"xmlns">>,<<"urn:xmpp:extra">>}],[{xmlcdata,<<"{\"type\":\"chat\",\"id\":\"5d666434ae920b04875c0a57\",\"name\":\"X003\",\"username\":\"x003\",\"status\":\"\",\"profile_picture\":\"\"}">>}]},
{xmlel,<<"request">>,[{<<"xmlns">>,<<"urn:xmpp:receipts">>}],[]},
{xmlel,<<"request">>,[{<<"xmlns">>,<<"urn:xmpp:read">>}],[]}
],
我想要额外的类型,媒体,额外的。等等
我得到了一些方法,使用它们我提取了必要的数据和属性值。
AllElm = Packet#message.sub_els,
?INFO_MSG("BinaryData ~p",[fxml:element_to_binary(AllElm)]),
?INFO_MSG("PacketsData ~p",[AllElm]),
%Test = fxml:get_path_s(Packet, [{elem, <<"type">>}]),
Delay = fxml:get_path_s(xmpp:encode(Packet), [{elem,list_to_binary("delay")}, {attr, list_to_binary("stamp")}]),
?INFO_MSG("PacketsDataDelay ~p",[Delay]),
Type = fxml:get_path_s(xmpp:encode(Packet), [{elem,list_to_binary("type")}, cdata]),
?INFO_MSG("PacketsDataType ~p",[Type]),
Media = fxml:get_path_s(xmpp:encode(Packet), [{elem,list_to_binary("media")}, cdata]),
?INFO_MSG("PacketsDataMedia ~p",[Media]),
Extra = fxml:get_path_s(xmpp:encode(Packet), [{elem,list_to_binary("extra")}, cdata]),
?INFO_MSG("PacketsDataExtra ~p",[Extra]),
我有一个包含数据包数据的打印日志,我使用 Packet#message.sub_els
提取子元素,它给我这样的数组:
[
{xmlel,<<"delay">>,[{<<"xmlns">>,<<"urn:xmpp:delay">>},{<<"stamp">>,<<"2019-10-24T08:08:15.126+00:00">>}],[]},
{xmlel,<<"type">>,[{<<"xmlns">>,<<"urn:xmpp:media">>}],[{xmlcdata,<<"1">>}]},
{xmlel,<<"media">>,[{<<"xmlns">>,<<"urn:xmpp:data">>}],[{xmlcdata,<<"null">>}]},
{xmlel,<<"extra">>,[{<<"xmlns">>,<<"urn:xmpp:extra">>}],[{xmlcdata,<<"{\"type\":\"chat\",\"id\":\"5d666434ae920b04875c0a57\",\"name\":\"X003\",\"username\":\"x003\",\"status\":\"\",\"profile_picture\":\"\"}">>}]},
{xmlel,<<"request">>,[{<<"xmlns">>,<<"urn:xmpp:receipts">>}],[]},
{xmlel,<<"request">>,[{<<"xmlns">>,<<"urn:xmpp:read">>}],[]}
],
我想要额外的类型,媒体,额外的。等等
我得到了一些方法,使用它们我提取了必要的数据和属性值。
AllElm = Packet#message.sub_els,
?INFO_MSG("BinaryData ~p",[fxml:element_to_binary(AllElm)]),
?INFO_MSG("PacketsData ~p",[AllElm]),
%Test = fxml:get_path_s(Packet, [{elem, <<"type">>}]),
Delay = fxml:get_path_s(xmpp:encode(Packet), [{elem,list_to_binary("delay")}, {attr, list_to_binary("stamp")}]),
?INFO_MSG("PacketsDataDelay ~p",[Delay]),
Type = fxml:get_path_s(xmpp:encode(Packet), [{elem,list_to_binary("type")}, cdata]),
?INFO_MSG("PacketsDataType ~p",[Type]),
Media = fxml:get_path_s(xmpp:encode(Packet), [{elem,list_to_binary("media")}, cdata]),
?INFO_MSG("PacketsDataMedia ~p",[Media]),
Extra = fxml:get_path_s(xmpp:encode(Packet), [{elem,list_to_binary("extra")}, cdata]),
?INFO_MSG("PacketsDataExtra ~p",[Extra]),