Mercurial > pidgin
changeset 25175:b1b1b75a922e
Sprinkle jabber_resource_has_capability in places
Plug a small leak
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Wed, 26 Nov 2008 22:06:46 +0000 |
parents | 68bfc99884ea |
children | e1f363f8fd6b |
files | libpurple/protocols/jabber/buddy.c libpurple/protocols/jabber/jabber.c libpurple/protocols/jabber/presence.c |
diffstat | 3 files changed, 35 insertions(+), 47 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/jabber/buddy.c Wed Nov 26 18:45:57 2008 +0000 +++ b/libpurple/protocols/jabber/buddy.c Wed Nov 26 22:06:46 2008 +0000 @@ -2495,7 +2495,7 @@ gboolean jabber_resource_has_capability(const JabberBuddyResource *jbr, const gchar *cap) { - const GList *iter = NULL; + const GList *node = NULL; if (!jbr->caps) { purple_debug_error("jabber", @@ -2503,15 +2503,14 @@ return FALSE; } - for (iter = jbr->caps->features ; iter ; iter = g_list_next(iter)) { - if (strcmp(iter->data, cap) == 0) { - purple_debug_info("jabber", "Found cap: %s\n", (char *)iter->data); - return TRUE; - } - } + node = g_list_find_custom(jbr->caps->features, cap, (GCompareFunc)strcmp); + /* TODO: Are these messages actually useful? */ + if (node) + purple_debug_info("jabber", "Found cap: %s\n", cap); + else + purple_debug_info("jabber", "Cap %s not found\n", cap); - purple_debug_info("jabber", "Cap %s not found\n", cap); - return FALSE; + return (node != NULL); } gboolean
--- a/libpurple/protocols/jabber/jabber.c Wed Nov 26 18:45:57 2008 +0000 +++ b/libpurple/protocols/jabber/jabber.c Wed Nov 26 22:06:46 2008 +0000 @@ -2390,7 +2390,6 @@ JabberBuddy *jb; JabberBuddyResource *jbr; - GList *iter; if(!username) return FALSE; @@ -2407,31 +2406,30 @@ return FALSE; } + /* Is this message sufficiently useful to not just fold it in with the tail error condition below? */ if(!jbr->caps) { *error = g_strdup_printf(_("Unable to buzz, because there is nothing known about user %s."), username); return FALSE; } - for(iter = jbr->caps->features; iter; iter = g_list_next(iter)) { - if(!strcmp(iter->data, "http://www.xmpp.org/extensions/xep-0224.html#ns")) { - xmlnode *buzz, *msg = xmlnode_new("message"); - gchar *to; - - to = g_strdup_printf("%s/%s", username, jbr->name); - xmlnode_set_attrib(msg, "to", to); - g_free(to); - - /* avoid offline storage */ - xmlnode_set_attrib(msg, "type", "headline"); - - buzz = xmlnode_new_child(msg, "attention"); - xmlnode_set_namespace(buzz, "http://www.xmpp.org/extensions/xep-0224.html#ns"); - - jabber_send(js, msg); - xmlnode_free(msg); - - return TRUE; - } + if (jabber_resource_has_capability(jbr, "http://www.xmpp.org/extensions/xep-0224.html#ns")) { + xmlnode *buzz, *msg = xmlnode_new("message"); + gchar *to; + + to = g_strdup_printf("%s/%s", username, jbr->name); + xmlnode_set_attrib(msg, "to", to); + g_free(to); + + /* avoid offline storage */ + xmlnode_set_attrib(msg, "type", "headline"); + + buzz = xmlnode_new_child(msg, "attention"); + xmlnode_set_namespace(buzz, "http://www.xmpp.org/extensions/xep-0224.html#ns"); + + jabber_send(js, msg); + xmlnode_free(msg); + + return TRUE; } *error = g_strdup_printf(_("Unable to buzz, because the user %s does not support it."), username); @@ -2590,7 +2588,6 @@ return FALSE; js = gc->proto_data; - resource = jabber_get_resource(jid); if (!(resource = jabber_get_resource(jid)) || !(jb = jabber_buddy_find(js, jid, FALSE)) || !(jbr = jabber_buddy_find_resource(jb, resource))) { @@ -2600,12 +2597,7 @@ g_free(resource); - if (!jbr->caps) { - /* TODO: fetch them? */ - return FALSE; - } - - return NULL != g_list_find_custom(jbr->caps->features, feature, (GCompareFunc)strcmp); + return jabber_resource_has_capability(jbr, feature); } static void
--- a/libpurple/protocols/jabber/presence.c Wed Nov 26 18:45:57 2008 +0000 +++ b/libpurple/protocols/jabber/presence.c Wed Nov 26 22:06:46 2008 +0000 @@ -398,16 +398,13 @@ /* old value in jbr->caps is owned by caps code */ jbr->caps = info; - if (info) { - GList *node = g_list_find_custom(info->features, "http://jabber.org/protocol/commands", (GCompareFunc)strcmp); - if (node) { - JabberIq *iq = jabber_iq_new_query(userdata->js, JABBER_IQ_GET, "http://jabber.org/protocol/disco#items"); - xmlnode *query = xmlnode_get_child_with_namespace(iq->node, "query", "http://jabber.org/protocol/disco#items"); - xmlnode_set_attrib(iq->node, "to", userdata->from); - xmlnode_set_attrib(query, "node", "http://jabber.org/protocol/commands"); - jabber_iq_set_callback(iq, jabber_adhoc_disco_result_cb, NULL); - jabber_iq_send(iq); - } + if (jabber_resource_has_capability(jbr, "http://jabber.org/protocol/commands")) { + JabberIq *iq = jabber_iq_new_query(userdata->js, JABBER_IQ_GET, "http://jabber.org/protocol/disco#items"); + xmlnode *query = xmlnode_get_child_with_namespace(iq->node, "query", "http://jabber.org/protocol/disco#items"); + xmlnode_set_attrib(iq->node, "to", userdata->from); + xmlnode_set_attrib(query, "node", "http://jabber.org/protocol/commands"); + jabber_iq_set_callback(iq, jabber_adhoc_disco_result_cb, NULL); + jabber_iq_send(iq); } g_free(userdata->from);