diff options
author | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2011-03-11 10:38:33 +0000 |
---|---|---|
committer | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2011-03-23 09:37:05 +0000 |
commit | 59ac2219bd44399949c6732dafa402786b317404 (patch) | |
tree | 1464067d7e92cd91b5dfb8b578ad548dabc4b059 | |
parent | 506ffdf83b335175e037385b6cf323c6c94f0728 (diff) |
pubsub-helpers: add make_event_stanza helper function
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
-rw-r--r-- | wocky/wocky-pubsub-helpers.c | 50 | ||||
-rw-r--r-- | wocky/wocky-pubsub-helpers.h | 5 |
2 files changed, 55 insertions, 0 deletions
diff --git a/wocky/wocky-pubsub-helpers.c b/wocky/wocky-pubsub-helpers.c index 0312c3d..f6b299c 100644 --- a/wocky/wocky-pubsub-helpers.c +++ b/wocky/wocky-pubsub-helpers.c @@ -23,6 +23,56 @@ #include "wocky-namespaces.h" #include "wocky-pubsub-service.h" + +/** + * wocky_pubsub_make_event_stanza: + * @node: the the name of the pubsub node; may not be %NULL + * @from: a JID to use as the 'from' attribute, or %NULL + * @item_out: a location to store the <code>item</code> #WockyNode, or %NULL + * + * Generates a new message stanza to send to other contacts about an + * updated PEP node. + * + * Note that this should only be used in link-local + * connections. Regular pubsub consists of making a publish stanza + * with wocky_pubsub_make_publish_stanza() and sending it to your own + * server. The server will then send the event stanza on to your + * contacts who have the appropriate capability. + * + * Returns: a new #WockyStanza pubsub event stanza; free with g_object_unref() + */ +WockyStanza * +wocky_pubsub_make_event_stanza (const gchar *node, + const gchar *from, + WockyNode **item_out) +{ + WockyStanza *stanza; + WockyNode *message, *event, *items, *item; + + g_return_val_if_fail (node != NULL, NULL); + + stanza = wocky_stanza_build (WOCKY_STANZA_TYPE_MESSAGE, + WOCKY_STANZA_SUB_TYPE_HEADLINE, from, NULL, + '(', "event", + ':', WOCKY_XMPP_NS_PUBSUB_EVENT, + '(', "items", + ':', node, + '(', "item", + ')', + ')', + ')', NULL); + + message = wocky_stanza_get_top_node (stanza); + event = wocky_node_get_first_child (message); + items = wocky_node_get_first_child (event); + item = wocky_node_get_first_child (items); + + if (item_out != NULL) + *item_out = item; + + return stanza; +} + /** * wocky_pubsub_make_publish_stanza: * @service: the JID of a PubSub service, or %NULL diff --git a/wocky/wocky-pubsub-helpers.h b/wocky/wocky-pubsub-helpers.h index c756b41..bc83298 100644 --- a/wocky/wocky-pubsub-helpers.h +++ b/wocky/wocky-pubsub-helpers.h @@ -25,6 +25,11 @@ #include "wocky-stanza.h" +WockyStanza * wocky_pubsub_make_event_stanza ( + const gchar *node, + const gchar *from, + WockyNode **item_out); + WockyStanza *wocky_pubsub_make_stanza ( const gchar *service, WockyStanzaSubType sub_type, |