diff libpurple/protocols/jabber/jabber.c @ 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 860ebaf275ae
children e1f363f8fd6b
line wrap: on
line diff
--- 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