Mercurial > pidgin
comparison libpurple/protocols/jabber/presence.c @ 25189:05693f6885a4
Support old (XEP v1.3) Entity Capabilities alongside the new ones.
The ext structures from v1.3 are stored in a ref-counted structure that
is shared among all instances of the ClientInfo that share the same 'node'
(unique per client). exts are only used for v1.3-entity capabilities
clients and are not shared with caps that specify the 'hash' attribute
(required in v1.5).
The jabber_caps_cbplususerdata is also ref-counted and will never leak,
even if some disco#info responses from a client return errors.
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Fri, 19 Dec 2008 04:11:07 +0000 |
parents | 6bdcdb77ce77 |
children | 5ad14a53e266 |
comparison
equal
deleted
inserted
replaced
25188:d5b1fede10a0 | 25189:05693f6885a4 |
---|---|
380 JabberStream *js; | 380 JabberStream *js; |
381 JabberBuddy *jb; | 381 JabberBuddy *jb; |
382 char *from; | 382 char *from; |
383 } JabberPresenceCapabilities; | 383 } JabberPresenceCapabilities; |
384 | 384 |
385 static void jabber_presence_set_capabilities(JabberCapsClientInfo *info, JabberPresenceCapabilities *userdata) | 385 static void |
386 jabber_presence_set_capabilities(JabberCapsClientInfo *info, GList *exts, | |
387 JabberPresenceCapabilities *userdata) | |
386 { | 388 { |
387 JabberBuddyResource *jbr; | 389 JabberBuddyResource *jbr; |
388 char *resource = g_utf8_strrchr(userdata->from, -1, '/'); | 390 char *resource = g_utf8_strrchr(userdata->from, -1, '/'); |
389 resource += 1; | 391 resource += 1; |
390 | 392 |
391 jbr = jabber_buddy_find_resource(userdata->jb, resource); | 393 jbr = jabber_buddy_find_resource(userdata->jb, resource); |
392 if (!jbr) { | 394 if (!jbr) { |
393 g_free(userdata->from); | 395 g_free(userdata->from); |
394 g_free(userdata); | 396 g_free(userdata); |
395 return; | 397 jabber_caps_client_info_unref(info); |
396 } | 398 if (exts) { |
397 | 399 g_list_foreach(exts, (GFunc)g_free, NULL); |
398 jabber_caps_client_info_unref(jbr->caps); | 400 g_list_free(exts); |
399 jbr->caps = info; | 401 } |
402 return; | |
403 } | |
404 | |
405 jabber_caps_client_info_unref(jbr->caps.info); | |
406 if (jbr->caps.exts) { | |
407 g_list_foreach(jbr->caps.exts, (GFunc)g_free, NULL); | |
408 g_list_free(jbr->caps.exts); | |
409 } | |
410 | |
411 jbr->caps.info = info; | |
412 jbr->caps.exts = exts; | |
400 | 413 |
401 if (jabber_resource_has_capability(jbr, "http://jabber.org/protocol/commands")) { | 414 if (jabber_resource_has_capability(jbr, "http://jabber.org/protocol/commands")) { |
402 JabberIq *iq = jabber_iq_new_query(userdata->js, JABBER_IQ_GET, "http://jabber.org/protocol/disco#items"); | 415 JabberIq *iq = jabber_iq_new_query(userdata->js, JABBER_IQ_GET, "http://jabber.org/protocol/disco#items"); |
403 xmlnode *query = xmlnode_get_child_with_namespace(iq->node, "query", "http://jabber.org/protocol/disco#items"); | 416 xmlnode *query = xmlnode_get_child_with_namespace(iq->node, "query", "http://jabber.org/protocol/disco#items"); |
404 xmlnode_set_attrib(iq->node, "to", userdata->from); | 417 xmlnode_set_attrib(iq->node, "to", userdata->from); |
749 if(caps) { | 762 if(caps) { |
750 /* handle XEP-0115 */ | 763 /* handle XEP-0115 */ |
751 const char *node = xmlnode_get_attrib(caps,"node"); | 764 const char *node = xmlnode_get_attrib(caps,"node"); |
752 const char *ver = xmlnode_get_attrib(caps,"ver"); | 765 const char *ver = xmlnode_get_attrib(caps,"ver"); |
753 const char *hash = xmlnode_get_attrib(caps,"hash"); | 766 const char *hash = xmlnode_get_attrib(caps,"hash"); |
754 | 767 const char *ext = xmlnode_get_attrib(caps,"ext"); |
755 if(node && ver && hash) { | 768 |
769 /* v1.3 uses: node, ver, and optionally ext. | |
770 * v1.5 uses: node, ver, and hash. */ | |
771 if (node && ver) { | |
756 JabberPresenceCapabilities *userdata = g_new0(JabberPresenceCapabilities, 1); | 772 JabberPresenceCapabilities *userdata = g_new0(JabberPresenceCapabilities, 1); |
757 userdata->js = js; | 773 userdata->js = js; |
758 userdata->jb = jb; | 774 userdata->jb = jb; |
759 userdata->from = g_strdup(from); | 775 userdata->from = g_strdup(from); |
760 jabber_caps_get_info(js, from, node, ver, hash, | 776 jabber_caps_get_info(js, from, node, ver, hash, ext, |
761 (jabber_caps_get_info_cb)jabber_presence_set_capabilities, | 777 (jabber_caps_get_info_cb)jabber_presence_set_capabilities, |
762 userdata); | 778 userdata); |
763 } | 779 } |
764 } | 780 } |
765 } | 781 } |