pidgin: 32b85baa: Fix jabber_get_media_caps for buddies wi...

qulogic at pidgin.im qulogic at pidgin.im
Wed Feb 10 23:07:14 EST 2010


-----------------------------------------------------------------
Revision: 32b85baaacb01e5073c7589441a33c7f29c66f29
Ancestor: 087c5864fefbb9ea8e8985e0ecc1783ee18502cb
Author: qulogic at pidgin.im
Date: 2010-02-11T03:59:56
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/32b85baaacb01e5073c7589441a33c7f29c66f29

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

ChangeLog: 

Fix jabber_get_media_caps for buddies with a single resource that has no
name. I don't believe the resource is required, and Facebook doesn't have
them, causing a NULL-printf crash on Windows.


-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/jabber.c	31afbaa2ab15dd1d49dbb57d59505fad496d9d5e
+++ libpurple/protocols/jabber/jabber.c	abdf49add02277cf2131471b76b0c787a2c55fb8
@@ -3148,6 +3148,7 @@ PurpleMediaCaps jabber_get_media_caps(Pu
 	JabberBuddyResource *jbr;
 	PurpleMediaCaps caps = PURPLE_MEDIA_CAPS_NONE;
 	gchar *resource;
+	GList *specific = NULL, *l;
 
 	if (!js) {
 		purple_debug_info("jabber",
@@ -3155,11 +3156,17 @@ PurpleMediaCaps jabber_get_media_caps(Pu
 		return FALSE;
 	}
 
-	if ((resource = jabber_get_resource(who)) != NULL) {
+	jb = jabber_buddy_find(js, who, FALSE);
+
+	if (!jb || !jb->resources) {
+		/* no resources online, we're trying to get caps for someone
+		 * whose presence we're not subscribed to, or
+		 * someone who is offline. */
+		return caps;
+
+	} else if ((resource = jabber_get_resource(who)) != NULL) {
 		/* they've specified a resource, no need to ask or
 		 * default or anything, just do it */
-
-		jb = jabber_buddy_find(js, who, FALSE);
 		jbr = jabber_buddy_find_resource(jb, resource);
 		g_free(resource);
 
@@ -3169,6 +3176,16 @@ PurpleMediaCaps jabber_get_media_caps(Pu
 			return caps;
 		}
 
+		l = specific = g_list_prepend(specific, jbr);
+
+	} else {
+		/* we've got multiple resources, combine their caps */
+		l = jb->resources;
+	}
+
+	for (; l; l = l->next) {
+		jbr = l->data;
+
 		if (jabber_resource_has_capability(jbr,
 				JINGLE_APP_RTP_SUPPORT_AUDIO))
 			caps |= PURPLE_MEDIA_CAPS_AUDIO_SINGLE_DIRECTION |
@@ -3197,35 +3214,10 @@ PurpleMediaCaps jabber_get_media_caps(Pu
 			if (jabber_resource_has_capability(jbr, NS_GOOGLE_VIDEO))
 				caps |= PURPLE_MEDIA_CAPS_AUDIO_VIDEO;
 		}
-		return caps;
 	}
 
-	jb = jabber_buddy_find(js, who, FALSE);
-
-	if(!jb || !jb->resources) {
-		/* no resources online, we're trying to get caps for someone
-		 * whose presence we're not subscribed to, or
-		 * someone who is offline. */
-		return caps;
-	} else if(!jb->resources->next) {
-		/* only 1 resource online (probably our most common case) */
-		gchar *name;
-		jbr = jb->resources->data;
-		name = g_strdup_printf("%s/%s", who, jbr->name);
-		caps = jabber_get_media_caps(account, name);
-		g_free(name);
-	} else {
-		/* we've got multiple resources, combine their caps */
-		GList *l;
-
-		for(l = jb->resources; l; l = l->next)
-		{
-			gchar *name;
-			jbr = l->data;
-			name = g_strdup_printf("%s/%s", who, jbr->name);
-			caps |= jabber_get_media_caps(account, name);
-			g_free(name);
-		}
+	if (specific) {
+		g_list_free(specific);
 	}
 
 	return caps;


More information about the Commits mailing list