cpw.malu.xmpp.jingle_ft: 3b1bc046: Broke out the functionallity to connect ...

malu at pidgin.im malu at pidgin.im
Sun Apr 19 04:01:31 EDT 2009


-----------------------------------------------------------------
Revision: 3b1bc046a34aae0543a73a4663bc36ee3359db96
Ancestor: 16ed51cdfe4abd968be5d6f79b39696b356ac80d
Author: malu at pidgin.im
Date: 2009-04-19T07:58:42
Branch: im.pidgin.cpw.malu.xmpp.jingle_ft
URL: http://d.pidgin.im/viewmtn/revision/info/3b1bc046a34aae0543a73a4663bc36ee3359db96

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

ChangeLog: 

Broke out the functionallity to connect to a streamhost to its own function.
This way it can be reused for when the client offering the a streamhost
connects (in the case when it's a proxy), which is a little different.

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/jingle/s5b.c	a2847d19718a6cec04479b2ba1a972561a4c35bc
+++ libpurple/protocols/jabber/jingle/s5b.c	c545b311478872e05d47337b165abd4fb7889cc4
@@ -1041,7 +1041,64 @@ jingle_s5b_connect_cb(gpointer data, gin
 	jabber_iq_send(result);
 }
 	
+static void
+jingle_s5b_connect_to_streamhost(JingleS5BConnectData *data, 
+	JabberBytestreamsStreamhost *sh, 
+	void (*connect_cb)(gpointer, gint, const gchar *),
+	GSourceFunc timeout_cb)
+{
+	JingleSession *session = data->session;
+	JingleS5B *s5b = data->s5b;
+	JabberStream *js = jingle_session_get_js(session);
+	const gchar *who = jingle_session_get_remote_jid(session);
+	JabberID *dstjid = jabber_id_new(who);
 
+	gchar *dstaddr = NULL;
+	gchar *hash = NULL;
+	
+	purple_debug_info("jingle-s5b", 
+		"attempting to connect to streamhost: %s, port: %d\n",
+		sh->host, sh->port);
+
+	if (s5b->priv->ppi)
+		purple_proxy_info_destroy(s5b->priv->ppi);
+	s5b->priv->ppi = purple_proxy_info_new();
+	purple_proxy_info_set_type(s5b->priv->ppi, PURPLE_PROXY_SOCKS5);
+	purple_proxy_info_set_host(s5b->priv->ppi, sh->host);
+	purple_proxy_info_set_port(s5b->priv->ppi, sh->port);
+	
+	if(jingle_session_is_initiator(session))
+		dstaddr = g_strdup_printf("%s%s@%s/%s%s@%s/%s", s5b->priv->sid, 
+			js->user->node, js->user->domain, js->user->resource, 
+			dstjid->node, dstjid->domain, dstjid->resource);
+	else
+		dstaddr = g_strdup_printf("%s%s@%s/%s%s@%s/%s", s5b->priv->sid, 
+			dstjid->node, dstjid->domain, dstjid->resource,
+			js->user->node, js->user->domain, js->user->resource);
+
+	/* Per XEP-0065, the 'host' must be SHA1(SID + from JID + to JID) */
+	purple_debug_info("jingle-s5b", "dstaddr: %s\n", dstaddr);
+	hash = jabber_calculate_data_sha1sum(dstaddr, strlen(dstaddr));
+	purple_debug_info("jingle-s5b", "connecting with hash: %s\n", hash);
+
+	s5b->priv->connect_data = 
+		purple_proxy_connect_socks5(NULL, s5b->priv->ppi, hash, 0, 
+			connect_cb, data);
+	g_free(hash);
+	g_free(dstaddr);
+	
+	/* add timeout */
+	/* we should add a longer timeout if the next streamhost candidate
+	is a proxy and we have local candidates ourselves, to allow the other
+	end a chance to connect to use before reverting to a proxy */
+	/* the timeout should perhaps be longer when connecting to a proxy */
+	s5b->priv->connect_timeout =
+		purple_timeout_add(STREAMHOST_CONNECT_TIMEOUT_MILLIS,
+			timeout_cb, data);
+
+	g_free(dstjid);
+}
+
 static void
 jingle_s5b_attempt_connect_internal(gpointer data)
 {
@@ -1049,54 +1106,12 @@ jingle_s5b_attempt_connect_internal(gpoi
 	JingleS5B *s5b = ((JingleS5BConnectData *) data)->s5b;
 	
 	if (s5b->priv->remaining_streamhosts) {
-		JabberStream *js = jingle_session_get_js(session);
-		const gchar *who = jingle_session_get_remote_jid(session);
-		JabberID *dstjid = jabber_id_new(who);
+		
 		JabberBytestreamsStreamhost *sh =
 			(JabberBytestreamsStreamhost *) s5b->priv->remaining_streamhosts->data;
-		gchar *dstaddr = NULL;
-		gchar *hash = NULL;
-		
-		purple_debug_info("jingle-s5b", 
-			"attempting to connect to streamhost: %s, port: %d\n",
-			sh->host, sh->port);
-		
-		if (s5b->priv->ppi)
-			purple_proxy_info_destroy(s5b->priv->ppi);
-		s5b->priv->ppi = purple_proxy_info_new();
-		purple_proxy_info_set_type(s5b->priv->ppi, PURPLE_PROXY_SOCKS5);
-		purple_proxy_info_set_host(s5b->priv->ppi, sh->host);
-		purple_proxy_info_set_port(s5b->priv->ppi, sh->port);
-		
-		if(jingle_session_is_initiator(session))
-			dstaddr = g_strdup_printf("%s%s@%s/%s%s@%s/%s", s5b->priv->sid, 
-				js->user->node, js->user->domain, js->user->resource, 
-				dstjid->node, dstjid->domain, dstjid->resource);
-		else
-			dstaddr = g_strdup_printf("%s%s@%s/%s%s@%s/%s", s5b->priv->sid, 
-				dstjid->node, dstjid->domain, dstjid->resource,
-				js->user->node, js->user->domain, js->user->resource);
 
-		/* Per XEP-0065, the 'host' must be SHA1(SID + from JID + to JID) */
-		purple_debug_info("jingle-s5b", "dstaddr: %s\n", dstaddr);
-		hash = jabber_calculate_data_sha1sum(dstaddr, strlen(dstaddr));
-		purple_debug_info("jingle-s5b", "connecting with hash: %s\n", hash);
-		
-		s5b->priv->connect_data = 
-			purple_proxy_connect_socks5(NULL, s5b->priv->ppi, hash, 0, 
-				jingle_s5b_connect_cb, data);
-		g_free(hash);
-		g_free(dstaddr);
-		
-		/* add timeout */
-		/* we should add a longer timeout if the next streamhost candidate
-		 is a proxy and we have local candidates ourselves, to allow the other
-		 end a chance to connect to use before reverting to a proxy */
-		s5b->priv->connect_timeout =
-			purple_timeout_add(STREAMHOST_CONNECT_TIMEOUT_MILLIS,
-				jingle_s5b_connect_timeout_cb, data);
-		
-		g_free(dstjid);
+		jingle_s5b_connect_to_streamhost((JingleS5BConnectData *) data, sh,
+			jingle_s5b_connect_cb, jingle_s5b_connect_timeout_cb);
 	} else {
 		/* send streamhost error */
 		
@@ -1139,6 +1154,13 @@ jingle_s5b_streamhost_is_local(JabberStr
 	return equal;
 }
 
+static void
+jingle_s5b_connect_to_proxy(JingleSession *session, JingleS5B *s5b, 
+	const gchar *jid)
+{
+	purple_debug_info("jingle-s5b", "in jingle_s5b_connect_to_proxy\n");
+}
+
 void
 jingle_s5b_handle_transport_accept(JingleS5B *s5b, JingleSession *session, 
 	xmlnode *transport)
@@ -1169,6 +1191,7 @@ jingle_s5b_handle_transport_accept(Jingl
 				purple_debug_info("jingle-ft",
 					"got transport-accept on a proxy, "
 					"need to connect to the proxy\n");
+				jingle_s5b_connect_to_proxy(session, s5b, jid);
 			} else {
 				/* start transfer */
 				if (s5b->priv->connect_cb && s5b->priv->connect_content) {


More information about the Commits mailing list