# HG changeset patch # User Elliott Sales de Andrade # Date 1265860796 0 # Node ID 7cab6dc6b79c85045e24cb51bcdfa24b3201449b # Parent 64bee7ae306f58fcd232edcd38337e2c30e07c67 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. diff -r 64bee7ae306f -r 7cab6dc6b79c libpurple/protocols/jabber/jabber.c --- a/libpurple/protocols/jabber/jabber.c Wed Feb 10 16:46:08 2010 +0000 +++ b/libpurple/protocols/jabber/jabber.c Thu Feb 11 03:59:56 2010 +0000 @@ -3148,6 +3148,7 @@ JabberBuddyResource *jbr; PurpleMediaCaps caps = PURPLE_MEDIA_CAPS_NONE; gchar *resource; + GList *specific = NULL, *l; if (!js) { purple_debug_info("jabber", @@ -3155,11 +3156,17 @@ 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 @@ 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 @@ 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;