如何从 ejabberd 数据包对象中获取数据?
Posted
技术标签:
【中文标题】如何从 ejabberd 数据包对象中获取数据?【英文标题】:How to get data from ejabberd packet object? 【发布时间】:2020-02-20 14:22:30 【问题描述】:我有一个包含数据包数据的打印日志,我使用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">>],[]
],
我想要额外的类型,媒体,额外的。等等
【问题讨论】:
【参考方案1】:我有一些方法,我已经提取了必要的数据和属性值。
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]),
【讨论】:
以上是关于如何从 ejabberd 数据包对象中获取数据?的主要内容,如果未能解决你的问题,请参考以下文章
无法从 ejabberd 服务器 15.09 路由自定义数据包
使用 EJABBERD-BUSINESS 版本在 SMACK 中恢复流后读取“重新绑定”数据包