libpurple/protocols/jabber/jabber.c

branch
soc.2008.masterpassword
changeset 34111
85b5efb9a873
parent 34108
7a07b6857540
parent 33796
4854740e5277
child 34227
6d016a081401
child 34529
68cf25486001
--- a/libpurple/protocols/jabber/jabber.c	Mon Mar 18 11:53:11 2013 +0100
+++ b/libpurple/protocols/jabber/jabber.c	Mon Mar 18 12:50:51 2013 +0100
@@ -667,7 +667,7 @@
 	else {
 		gchar *tmp;
 		if (len == 0)
-			tmp = g_strdup_printf(_("Server closed the connection"));
+			tmp = g_strdup(_("Server closed the connection"));
 		else
 			tmp = g_strdup_printf(_("Lost connection with server: %s"),
 					g_strerror(errno));
@@ -725,7 +725,7 @@
 	} else {
 		gchar *tmp;
 		if (len == 0)
-			tmp = g_strdup_printf(_("Server closed the connection"));
+			tmp = g_strdup(_("Server closed the connection"));
 		else
 			tmp = g_strdup_printf(_("Lost connection with server: %s"),
 					g_strerror(errno));
@@ -3295,7 +3295,7 @@
 	JabberStream *js = purple_connection_get_protocol_data(gc);
 	JabberBuddy *jb;
 	JabberBuddyResource *jbr = NULL;
-	char *resource;
+	char *resource = NULL;
 
 	if (!js) {
 		purple_debug_error("jabber",
@@ -3303,26 +3303,11 @@
 		return FALSE;
 	}
 
-	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 (type & PURPLE_MEDIA_AUDIO &&
-			!jabber_resource_has_capability(jbr,
-			JINGLE_APP_RTP_SUPPORT_AUDIO) &&
-			jabber_resource_has_capability(jbr, NS_GOOGLE_VOICE))
-			return jabber_google_session_initiate(js, who, type);
-		else
-			return jingle_rtp_initiate_media(js, who, type);
-	}
-
 	jb = jabber_buddy_find(js, who, FALSE);
 
-	if(!jb || !jb->resources) {
+	if(!jb || !jb->resources ||
+			(((resource = jabber_get_resource(who)) != NULL)
+			 && (jbr = jabber_buddy_find_resource(jb, resource)) == NULL)) {
 		/* no resources online, we're trying to initiate with someone
 		 * whose presence we're not subscribed to, or
 		 * someone who is offline.  Let's inform the user */
@@ -3330,8 +3315,10 @@
 
 		if(!jb) {
 			msg = g_strdup_printf(_("Unable to initiate media with %s: invalid JID"), who);
-		} else if(jb->subscription & JABBER_SUB_TO) {
+		} else if(jb->subscription & JABBER_SUB_TO && !jb->resources) {
 			msg = g_strdup_printf(_("Unable to initiate media with %s: user is not online"), who);
+		} else if(resource) {
+			msg = g_strdup_printf(_("Unable to initiate media with %s: resource is not online"), who);
 		} else {
 			msg = g_strdup_printf(_("Unable to initiate media with %s: not subscribed to user presence"), who);
 		}
@@ -3339,7 +3326,21 @@
 		purple_notify_error(account, _("Media Initiation Failed"),
 				_("Media Initiation Failed"), msg);
 		g_free(msg);
+		g_free(resource);
 		return FALSE;
+	} else if(jbr != NULL) {
+		/* they've specified a resource, no need to ask or
+		 * default or anything, just do it */
+
+		g_free(resource);
+
+		if (type & PURPLE_MEDIA_AUDIO &&
+			!jabber_resource_has_capability(jbr,
+				JINGLE_APP_RTP_SUPPORT_AUDIO) &&
+			jabber_resource_has_capability(jbr, NS_GOOGLE_VOICE))
+			return jabber_google_session_initiate(js, who, type);
+		else
+			return jingle_rtp_initiate_media(js, who, type);
 	} else if(!jb->resources->next) {
 		/* only 1 resource online (probably our most common case)
 		 * so no need to ask who to initiate with */

mercurial