Libstrophe 库理解

前端之家收集整理的这篇文章主要介绍了Libstrophe 库理解前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

libstrophe库链接http://strophe.im/libstrophe/

libstrophe库在github上的链接https://github.com/Metajack/libstrophe

LIBSTROPHE


libstrophe是一个XMPP客户端和组件通信的C库。其目标是建立一个可移植的,可用快捷的,可靠的,文档齐全的,并能完全实现XMPP规范的开发工具库。

主要有两个部分组成:

1. 对基于XMPP信息体的解析与组装

2. 实现基于XMPP协议与XMPP SERVER或者其他XMPP实体间的通讯


eg:数据流

<iq from= "google.com" type="set" id="1">\

<pubsub xmlns="http://jabber.org/protocol/pubsub">\

<publish node="http://xmppgoogle.org/google_event">\

<item>\

<status xmlns="http://xmppgoogle.org/google/commands/objects/status\" object_type=\"dev\" event=\"added\" from="google.com">\

<object object_type=\"dev\" object_id=\"devid\" owner_id=\"owner_id\">\

</status>\

</item>\

</publish>\

</pubsub>\

</iq>


eg:C语言

void send_iq(xmpp_conn_t *const conn,)

{

xmpp_stanza_t *iq,*pubsub,*publish,*item,*status,*object;

iq = xmpp_stanza_new(ctx);

xmpp_stanza_set_name(iq,"iq");

xmpp_stanza_set_attribute(iq,"from","google.com");

xmpp_stanza_set_type(iq,"set");

xmpp_stanza_set_id(iq,"1");

pubsub = xmpp_stanza_new(ctx);

xmpp_stanza_set_name(pubsub,"pubsub");

xmpp_stanza_set_ns(pubsub,"http://jabber.org/protocol/pubsub");

xmpp_stanza_add_child(iq,pubsub);

item= xmpp_stanza_new(ctx);

xmpp_stanza_set_name(item,"item");

xmpp_stanza_add_child(publish,item);


status = xmpp_stanza_new(ctx);

xmpp_stanza_set_name(status,"status");

xmpp_stanza_set_ns(status,"http://xmppgoogle.org/google/commands/objects/status");

xmpp_stanza_set_attribute(status,"object_type","dev");

xmpp_stanza_set_attribute(status,"event","added");

xmpp_stanza_set_attribute(status,"google.com");

xmpp_stanza_add_child(item,status);

object= xmpp_stanza_new(ctx);

xmpp_stanza_set_name(object,"object");

xmpp_stanza_set_attribute(object,"dev");

xmpp_stanza_set_attribute(object,"object_id","devid");

xmpp_stanza_set_attribute(object,"owner_id","owner_id");

xmpp_stanza_add_child(status,object);

xmpp_stanza_release(object);

xmpp_stanza_release(status);

xmpp_stanza_release(item);

xmpp_stanza_release(publish);

xmpp_stanza_release(pubsub);

xmpp_stanza_send(conn,iq);

xmpp_stanza_release(iq);

}

原文链接:https://www.f2er.com/xml/297810.html

猜你在找的XML相关文章