diff libpurple/protocols/jabber/jabber.c @ 29754:5dec9d90fb51

propagate from branch 'im.pidgin.pidgin' (head d14a1fe9d288c6942c8bfc6d1df3c8297ba7ca54) to branch 'im.pidgin.pidgin.next.minor' (head 8761a76439ad0ebb03090ebdd75ca3aa5422d105)
author Paul Aurich <paul@darkrain42.org>
date Thu, 11 Feb 2010 04:38:48 +0000
parents 422889fb57e0 9e735d7e2f1d
children 2ad2e3490b23
line wrap: on
line diff
--- a/libpurple/protocols/jabber/jabber.c	Wed Feb 10 04:05:50 2010 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Thu Feb 11 04:38:48 2010 +0000
@@ -3142,8 +3142,9 @@
 			purple_account_get_connection(account)->proto_data;
 	JabberBuddy *jb;
 	JabberBuddyResource *jbr;
-	PurpleMediaCaps caps = PURPLE_MEDIA_CAPS_NONE;
+	PurpleMediaCaps total = PURPLE_MEDIA_CAPS_NONE;
 	gchar *resource;
+	GList *specific = NULL, *l;
 
 	if (!js) {
 		purple_debug_info("jabber",
@@ -3151,20 +3152,37 @@
 		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 total;
+
+	} 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);
 
 		if (!jbr) {
 			purple_debug_error("jabber", "jabber_get_media_caps:"
 					" Can't find resource %s\n", who);
-			return caps;
+			return total;
 		}
 
+		l = specific = g_list_prepend(specific, jbr);
+
+	} else {
+		/* we've got multiple resources, combine their caps */
+		l = jb->resources;
+	}
+
+	for (; l; l = l->next) {
+		PurpleMediaCaps caps = PURPLE_MEDIA_CAPS_NONE;
+		jbr = l->data;
+
 		if (jabber_resource_has_capability(jbr,
 				JINGLE_APP_RTP_SUPPORT_AUDIO))
 			caps |= PURPLE_MEDIA_CAPS_AUDIO_SINGLE_DIRECTION |
@@ -3193,38 +3211,15 @@
 			if (jabber_resource_has_capability(jbr, NS_GOOGLE_VIDEO))
 				caps |= PURPLE_MEDIA_CAPS_AUDIO_VIDEO;
 		}
-		return caps;
+
+		total |= 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;
+	return total;
 #else
 	return PURPLE_MEDIA_CAPS_NONE;
 #endif