cpw.darkrain42.xmpp.bosh: 8c7ebef6: Sprinkle jabber_resource_has_capability ...

paul at darkrain42.org paul at darkrain42.org
Sat Jan 17 23:56:24 EST 2009


-----------------------------------------------------------------
Revision: 8c7ebef63cff9084aa9cb6c67abf84ede85e9308
Ancestor: 1e9fc45ee3625ce6ef4401b3d7d30cfe971ceeb8
Author: paul at darkrain42.org
Date: 2008-11-26T22:06:46
Branch: im.pidgin.cpw.darkrain42.xmpp.bosh
URL: http://d.pidgin.im/viewmtn/revision/info/8c7ebef63cff9084aa9cb6c67abf84ede85e9308

Modified files:
        libpurple/protocols/jabber/buddy.c
        libpurple/protocols/jabber/jabber.c
        libpurple/protocols/jabber/presence.c

ChangeLog: 

Sprinkle jabber_resource_has_capability in places
Plug a small leak

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/buddy.c	2141e6fec6fc6c22556f193d35935a297531098b
+++ libpurple/protocols/jabber/buddy.c	39e5c3fe80b6a41c655009852b04d82d62d26c82
@@ -2495,7 +2495,7 @@ jabber_resource_has_capability(const Jab
 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 @@ jabber_resource_has_capability(const Jab
 		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
============================================================
--- libpurple/protocols/jabber/jabber.c	98a99e88f3c1a150875db8a37d609516db37c066
+++ libpurple/protocols/jabber/jabber.c	728c7a50d12d7ba801772ecbed8e1531af26747a
@@ -2390,7 +2390,6 @@ static gboolean _jabber_send_buzz(Jabber
 
 	JabberBuddy *jb;
 	JabberBuddyResource *jbr;
-	GList *iter;
 
 	if(!username)
 		return FALSE;
@@ -2407,31 +2406,30 @@ static gboolean _jabber_send_buzz(Jabber
 		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;
+	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);
+		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");
+		/* 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");
+		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);
+		jabber_send(js, msg);
+		xmlnode_free(msg);
 
-			return TRUE;
-		}
+		return TRUE;
 	}
 
 	*error = g_strdup_printf(_("Unable to buzz, because the user %s does not support it."), username);
@@ -2590,7 +2588,6 @@ jabber_ipc_contact_has_feature(PurpleAcc
 		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 @@ jabber_ipc_contact_has_feature(PurpleAcc
 
 	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
============================================================
--- libpurple/protocols/jabber/presence.c	2f8903db374c7f87aa7a9f72025d26e3e2818a3d
+++ libpurple/protocols/jabber/presence.c	57bd9903c42617ad2de79b2e51f8439c97a303e4
@@ -398,16 +398,13 @@ static void jabber_presence_set_capabili
 	/* 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);


More information about the Commits mailing list