Mercurial > ~mikael > mcabber > hg
diff mcabber/src/jab_iq.c @ 1016:4d3c48844746
Add /roster note
Implement XEP-0145 (Annotations)
Usage: /roster note [-|note_text]
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Wed, 15 Nov 2006 00:04:57 +0100 |
parents | 579299b1c9b2 |
children | f7ef8003fc35 |
line wrap: on
line diff
--- a/mcabber/src/jab_iq.c Mon Nov 13 21:58:18 2006 +0100 +++ b/mcabber/src/jab_iq.c Wed Nov 15 00:04:57 2006 +0100 @@ -36,6 +36,8 @@ // Bookmarks for IQ:private storage xmlnode bookmarks; +// Roster notes for IQ:private storage +xmlnode rosternotes; static GSList *iqs_list; @@ -684,6 +686,7 @@ if (p && !strcmp(p, "conference")) storage_bookmarks_parse_conference(x); } + // Copy the bookmarks node xmlnode_free(bookmarks); bookmarks = xmlnode_dup(ansqry); } @@ -702,6 +705,40 @@ jab_send(jc, iqn->xmldata); } +static void iqscallback_storage_rosternotes(eviqs *iqp, xmlnode xml_result, + guint iqcontext) +{ + xmlnode ansqry; + + // Leave now if we cannot process xml_result + if (!xml_result || iqcontext) return; + + ansqry = xmlnode_get_tag(xml_result, "query"); + ansqry = xmlnode_get_tag(ansqry, "storage"); + if (!ansqry) { + scr_LogPrint(LPRINT_LOG, "Invalid IQ:private result! " + "(storage:rosternotes)"); + return; + } + // Copy the rosternotes node + xmlnode_free(rosternotes); + rosternotes = xmlnode_dup(ansqry); +} + +static void request_storage_rosternotes(void) +{ + eviqs *iqn; + xmlnode x; + + iqn = iqs_new(JPACKET__GET, NS_PRIVATE, "storage", IQS_DEFAULT_TIMEOUT); + + x = xmlnode_insert_tag(xmlnode_get_tag(iqn->xmldata, "query"), "storage"); + xmlnode_put_attrib(x, "xmlns", "storage:rosternotes"); + + iqn->callback = &iqscallback_storage_rosternotes; + jab_send(jc, iqn->xmldata); +} + void iqscallback_auth(eviqs *iqp, xmlnode xml_result) { if (jstate == STATE_GETAUTH) { @@ -721,6 +758,7 @@ } else if (jstate == STATE_SENDAUTH) { request_roster(); request_storage_bookmarks(); + request_storage_rosternotes(); jstate = STATE_LOGGED; } } @@ -989,4 +1027,20 @@ iqs_del(iqn->id); // XXX } +// send_storage_rosternotes() +// Send the current rosternotes node to update the server. +// Note: the sender should check we're online. +void send_storage_rosternotes(void) +{ + eviqs *iqn; + + if (!rosternotes) return; + + iqn = iqs_new(JPACKET__SET, NS_PRIVATE, "storage", IQS_DEFAULT_TIMEOUT); + xmlnode_insert_node(xmlnode_get_tag(iqn->xmldata, "query"), rosternotes); + + jab_send(jc, iqn->xmldata); + iqs_del(iqn->id); // XXX +} + /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */