cpw.malu.xmpp.jingle_ft: 24df7cc1: Don't create the content and transport u...

malu at pidgin.im malu at pidgin.im
Tue Mar 24 19:10:29 EDT 2009


-----------------------------------------------------------------
Revision: 24df7cc1a18815849528b16e8ea3a564471383b2
Ancestor: 5e2b1bdb7fa7ca202aa2ac6356af02daf5fd01ec
Author: malu at pidgin.im
Date: 2009-03-24T23:06:31
Branch: im.pidgin.cpw.malu.xmpp.jingle_ft
URL: http://d.pidgin.im/viewmtn/revision/info/24df7cc1a18815849528b16e8ea3a564471383b2

Modified files:
        libpurple/protocols/jabber/jingle/file-transfer.c

ChangeLog: 

Don't create the content and transport until we are about to start the transfer
when we are the iniator.
This will allow selecting transport based on the file selected (such as size)

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/jingle/file-transfer.c	1e0b699540819463e44053ed58e8e8d011c36737
+++ libpurple/protocols/jabber/jingle/file-transfer.c	7150c5f566ca62f6e1c2c931a00736039ac9abd6
@@ -339,16 +339,104 @@ static void
 }
 
 static void
+jingle_file_transfer_add_ibb_session_to_transport(JabberStream *js,
+	JingleTransport *transport, JingleContent *content, const gchar *jid)
+{
+	gchar *sid = jabber_get_next_id(js);
+
+	if (JINGLE_IS_IBB(transport)) {
+		jingle_ibb_create_session(JINGLE_IBB(transport), content, sid, jid);
+		jingle_ibb_set_data_sent_callback(JINGLE_IBB(transport),
+			jingle_file_transfer_ibb_data_sent_callback);
+		jingle_ibb_set_error_callback(JINGLE_IBB(transport),
+			jingle_file_transfer_ibb_error_callback);
+	} else {
+		purple_debug_error("jingle-ft",
+			"trying to setup an IBB session of a non-IBB transport\n");
+	}
+		
+	g_free(sid);
+}
+
+static void
 jingle_file_transfer_xfer_init(PurpleXfer *xfer)
 {
-	JingleContent *content = (JingleContent *) xfer->data;
-	JingleSession *session = jingle_content_get_session(content);
-	JingleTransport *transport = jingle_content_get_transport(content);
+	if (purple_xfer_get_type(xfer) == PURPLE_XFER_SEND) {
+		PurpleAccount *account = purple_xfer_get_account(xfer);
+		PurpleConnection *gc = purple_account_get_connection(account);
+		JabberStream *js = 
+			(JabberStream *) purple_connection_get_protocol_data(gc);
+				JingleSession *session;
+		const gchar *who = purple_xfer_get_remote_user(xfer);
+		JingleContent *content;
+		JingleTransport *transport;
+		gchar *jid = NULL, *me = NULL, *sid = NULL;
+		const gchar *transport_type = NULL;
+			
+		/* construct JID to send to */
+		JabberBuddy *jb = jabber_buddy_find(js, who, FALSE);
+		JabberBuddyResource *jbr;
 		
-	if (jingle_session_is_initiator(session)) {
+		if (!jb) {
+			purple_debug_error("jingle-rtp", "Could not find Jabber buddy\n");
+			return;
+		}
+		jbr = jabber_buddy_find_resource(jb, NULL);
+		if (!jbr) {
+			purple_debug_error("jingle-rtp", "Could not find buddy's resource\n");
+		}
+		
+		if (jabber_resource_has_capability(jbr, JINGLE_TRANSPORT_S5B)) {
+			purple_debug_info("jingle-ft", 
+				"receiver supports S5B, let's try that first\n");
+			transport_type = JINGLE_TRANSPORT_S5B;
+		} else if (jabber_resource_has_capability(jbr, JINGLE_TRANSPORT_IBB)) {
+			purple_debug_info("jingle-ft",
+				"receiver didn't support S5B but IBB, so let's try that\n");
+			transport_type = JINGLE_TRANSPORT_IBB;
+		} else {
+			purple_debug_error("jingle-ft",
+				"receiver doesn't support S5B or IBB, bailing out "
+				"(this shouldn't happen).");
+			return;
+		}
+		
+		if ((strchr(who, '/') == NULL) && jbr && (jbr->name != NULL)) {
+			jid = g_strdup_printf("%s/%s", who, jbr->name);
+		} else {
+			jid = g_strdup(who);
+		}
+
+		/* set ourselves as initiator */
+		me = g_strdup_printf("%s@%s/%s", js->user->node, js->user->domain, js->user->resource);
+
+		sid = jabber_get_next_id(js);
+		session = jingle_session_create(js, sid, me, jid, TRUE);
+		g_free(sid);
+		g_free(jid);
+		g_free(me);
+		
+		/* add the content */
+		transport = jingle_transport_create(transport_type);
+		content = jingle_content_create(JINGLE_APP_FT, "initiator", "session",
+			"ft-session", "sender", transport);
+		jingle_session_add_content(session, content);
+		JINGLE_FT_GET_PRIVATE(JINGLE_FT(content))->xfer = xfer;
+
+		if (JINGLE_IS_IBB(transport)) {
+			jingle_file_transfer_add_ibb_session_to_transport(js, transport, 
+				content, jid);
+		}	
+
+		xfer->data = content;
+		
 		jabber_iq_send(jingle_session_to_packet(session, 
 			JINGLE_SESSION_INITIATE));
 	} else {
+		JingleContent *content = (JingleContent *) xfer->data;
+		JingleSession *session = jingle_content_get_session(content);
+		JingleTransport *transport = jingle_content_get_transport(content);
+
 		jabber_iq_send(jingle_session_to_packet(session,
 			JINGLE_SESSION_ACCEPT));
 		/* ready to receive */
@@ -381,9 +469,9 @@ jingle_file_transfer_xfer_init(PurpleXfe
 			/* start the transfer */
 			purple_xfer_start(xfer, 0, NULL, 0);
 		}
+		g_object_unref(session);
+		g_object_unref(transport);
 	}
-	g_object_unref(session);
-	g_object_unref(transport);
 }
 
 static void
@@ -576,26 +664,6 @@ jingle_file_transfer_handle_action_inter
 	}
 }
 
-static void
-jingle_file_transfer_add_ibb_session_to_transport(JabberStream *js,
-	JingleTransport *transport, JingleContent *content, const gchar *jid)
-{
-	gchar *sid = jabber_get_next_id(js);
-
-	if (JINGLE_IS_IBB(transport)) {
-		jingle_ibb_create_session(JINGLE_IBB(transport), content, sid, jid);
-		jingle_ibb_set_data_sent_callback(JINGLE_IBB(transport),
-			jingle_file_transfer_ibb_data_sent_callback);
-		jingle_ibb_set_error_callback(JINGLE_IBB(transport),
-			jingle_file_transfer_ibb_error_callback);
-	} else {
-		purple_debug_error("jingle-ft",
-			"trying to setup an IBB session of a non-IBB transport\n");
-	}
-		
-	g_free(sid);
-}
-
 PurpleXfer *
 jingle_file_transfer_new_xfer(PurpleConnection *gc, const gchar *who)
 {
@@ -606,72 +674,9 @@ jingle_file_transfer_new_xfer(PurpleConn
 
 	if (xfer)
 	{
-	JingleSession *session;
-		JingleContent *content;
-		JingleTransport *transport;
-		gchar *jid = NULL, *me = NULL, *sid = NULL;
-		const gchar *transport_type = NULL;
-			
-		/* construct JID to send to */
-		JabberBuddy *jb = jabber_buddy_find(js, who, FALSE);
-		JabberBuddyResource *jbr;
-		
-		if (!jb) {
-			purple_debug_error("jingle-rtp", "Could not find Jabber buddy\n");
-			return NULL;
-		}
-		jbr = jabber_buddy_find_resource(jb, NULL);
-		if (!jbr) {
-			purple_debug_error("jingle-rtp", "Could not find buddy's resource\n");
-		}
-		
-		if (jabber_resource_has_capability(jbr, JINGLE_TRANSPORT_S5B)) {
-			purple_debug_info("jingle-ft", 
-				"receiver supports S5B, let's try that first\n");
-			transport_type = JINGLE_TRANSPORT_S5B;
-		} else if (jabber_resource_has_capability(jbr, JINGLE_TRANSPORT_IBB)) {
-			purple_debug_info("jingle-ft",
-				"receiver didn't support S5B but IBB, so let's try that\n");
-			transport_type = JINGLE_TRANSPORT_IBB;
-		} else {
-			purple_debug_error("jingle-ft",
-				"receiver doesn't support S5B or IBB, bailing out "
-				"(this shouldn't happen).");
-			return NULL;
-		}
-		
-		if ((strchr(who, '/') == NULL) && jbr && (jbr->name != NULL)) {
-			jid = g_strdup_printf("%s/%s", who, jbr->name);
-		} else {
-			jid = g_strdup(who);
-		}
-
-		/* set ourselves as initiator */
-		me = g_strdup_printf("%s@%s/%s", js->user->node, js->user->domain, js->user->resource);
-
-		sid = jabber_get_next_id(js);
-		session = jingle_session_create(js, sid, me, jid, TRUE);
-		g_free(sid);
-		
-		/* add the content */
-		transport = jingle_transport_create(transport_type);
-		content = jingle_content_create(JINGLE_APP_FT, "initiator", "session",
-			"ft-session", "sender", transport);
-		jingle_session_add_content(session, content);
-		JINGLE_FT_GET_PRIVATE(JINGLE_FT(content))->xfer = xfer;
-
-		if (JINGLE_IS_IBB(transport)) {
-			jingle_file_transfer_add_ibb_session_to_transport(js, transport, 
-				content, jid);
-		}	
-
-		xfer->data = content;
 		purple_xfer_set_init_fnc(xfer, jingle_file_transfer_xfer_init);
 		purple_xfer_set_cancel_send_fnc(xfer, jingle_file_transfer_cancel_send);
 		purple_xfer_set_end_fnc(xfer, jingle_file_transfer_xfer_end);
-
-		g_free(jid);
-		g_free(me);
 	}
 
 	return xfer;


More information about the Commits mailing list