/soc/2013/ashmew2/filetransferX: 5cb680486dce: faking candidates...

Ashish Gupta ashmew2 at gmail.com
Wed Aug 7 08:51:14 EDT 2013


Changeset: 5cb680486dce4de9e370a8b699f207ed6ba22a38
Author:	 Ashish Gupta <ashmew2 at gmail.com>
Date:	 2013-08-07 05:42 +0530
Branch:	 filetransferX
URL: https://hg.pidgin.im/soc/2013/ashmew2/filetransferX/rev/5cb680486dce

Description:

faking candidates, getting relay

diffstat:

 libpurple/protocols/jabber/google/google_session.c |  75 +++++++++++++++++----
 1 files changed, 59 insertions(+), 16 deletions(-)

diffs (153 lines):

diff --git a/libpurple/protocols/jabber/google/google_session.c b/libpurple/protocols/jabber/google/google_session.c
--- a/libpurple/protocols/jabber/google/google_session.c
+++ b/libpurple/protocols/jabber/google/google_session.c
@@ -24,6 +24,8 @@
 #include "relay.h"
 #include "jingle/jingle.h"
 #include "network.h"
+#include "stun.h"
+
 #ifdef USE_VV
 
 typedef struct {
@@ -726,15 +728,6 @@ FT XML:
 
 		purple_debug_info("google_session", "Sending a file request in return\n");
 		jabber_send_raw(js,temp,strlen(temp));
-		if(1) {
-/*			GList *iplist = purple_network_get_all_local_system_ips();
-			GList *iter;
-			for(iter = iplist; iter; iter=iter->next) {
-				purple_debug_info("google_session", "\nIP : %s\n",iter->data);
-			}
-			g_list_free(iplist);
-*/		
-		}
 		/*
 		result_iq = jabber_iq_new(js,JABBER_IQ_RESULT);
 		xmlnode_set_attrib(result_iq->node, "to", session->remote_jid);
@@ -1042,16 +1035,32 @@ PurpleXfer *gtalk_xfer_new(PurpleConnect
 }
 
 void
+stun_discovery_cb(PurpleStunNatDiscovery *stun_discovery)
+{
+	purple_debug_info("google_session", "Inside stun_discovery_cb with publicip as %s\n",stun_discovery->publicip);
+}
+
+void
 gtalk_xfer_send(PurpleConnection *gc, const char *who, const char *file)
 {
   PurpleXfer *xfer;
+  PurpleStunNatDiscovery *stun_discovery;
+
   xfer = gtalk_xfer_new(gc, who);
   
   if(!xfer) {
 	  purple_debug_info("google_session", "Failed to Create an Xfer for Sending a File..");
 	  return;
   }
-  
+  /*TODO: Start a STUN discovery here to get our external IP for sending out as a candidate to GTalk*/
+  stun_discovery = purple_stun_discover(stun_discovery_cb);
+  /*TODO: if stun_discovery is NULL, that means stun_discovery_cb will be called when discovery is done.*/
+
+  if(stun_discovery)
+	  purple_debug_info("google_session", "stun_discovery is NOT NULL. Public IP : %s\n",stun_discovery->publicip);
+  else
+	  purple_debug_info("google_session", "stun_discovery is NULL for now..\n");
+
   if (file) {
 /*TODO: This should probably be something else*/
 	  purple_xfer_request_accepted(xfer, file);
@@ -1078,20 +1087,22 @@ char*
 gtalk_get_temporary_url(void)
 {
 /*According to GTalk data, the length of temporary URL must be 44.*/
+	static int z = - 1;
 	char *temporary_url = g_malloc(45);
 	int i = 11;
 	char *alpha = "abcdefghijklmnopqrstuvwxyz";
 	char *num = "0123456789";
 	srandom(time(NULL));
+	z++;
 
 	strcpy(temporary_url, "/temporary/");
 	for(;i<43;i++) {
 		int j=random()%2;
 
 		if(j==0)
-			temporary_url[i] = alpha[random()%26];
+			temporary_url[i] = alpha[random()%(26-z)];
 		else
-			temporary_url[i] = num[random()%10];
+			temporary_url[i] = num[random()%(10-z)];
 		}
 	temporary_url[i]='/';
 	++i;
@@ -1238,16 +1249,47 @@ google_session_parse_iq(JabberStream *js
 	} else if (!strcmp(type, "terminate")) {
 		google_session_handle_terminate(js, session, sess);
 	} else if (!strcmp(type, "candidates")) {
+		static int num_candid=0;
+		num_candid++;
 		google_session_handle_candidates(js, session, sess, iq_id);
+		if(js->stun_ip)
+			purple_debug_info("google_session", "We might be able to get a stun public address now.\n");
+		if(num_candid == 2) {
+		gchar *me = g_strdup_printf("%s@%s/%s",
+				session->js->user->node,
+				session->js->user->domain,
+				session->js->user->resource);
+
+		char *buf1 = g_strdup_printf("<iq to=\"%s\" type=\"set\" id=\"299\" from=\"%s\"><session type=\"candidates\" id=\"%s\" initiator=\"%s\" xmlns=\"http://www.google.com/session\"><candidate name=\"private-1\" address=\"192.168.19.103\" port=\"61227\" preference=\"1\" username=\"FZR9vsoNFS6J0YyG\" protocol=\"udp\" generation=\"0\" password=\"QRjZne/7ctLxzAPs\" type=\"local\" network=\"0\"/></session></iq>",session->remote_jid, me, session->id.id, me);
+
+		char *buf2 = g_strdup_printf("<iq to=\"%s\" type=\"set\" id=\"151\" from=\"%s\"><session type=\"candidates\" id=\"%s\" initiator=\"%s\" xmlns=\"http://www.google.com/session\"><candidate name=\"private-1\" address=\"49.248.185.190\" port=\"27777\" preference=\"0.9\" username=\"rTjIPIdOe2BZchUn\" protocol=\"udp\" generation=\"0\" password=\"dbuAaKuZErs5YXva\" type=\"stun\" network=\"0\"/></session></iq>",session->remote_jid, me, session->id.id, me);
+
+			jabber_send_raw(js,buf1,strlen(buf1));
+			jabber_send_raw(js,buf2,strlen(buf2));
+
 	} else if (!strcmp(type, "transport-accept")) {
 		google_session_handle_transport_accept(js, session, sess, iq_id);
 	} else if (!strcmp(type, "transport-info")) {
 		google_session_handle_transport_info(js, session, sess, iq_id);
-		google_session_initiate_file_transfer(js,session);
+//		google_session_initiate_file_transfer(js,session);
+		purple_debug_info("google_session", "Back in parse_iq\n");
+		if(js->stun_ip)
+			purple_debug_info("google_session", "We might be able to get a stun public address now.\n");
+		if(1) {
+			GList *iplist = purple_network_get_all_local_system_ips();
+			GList *iter;
+			for(iter = iplist; iter; iter=iter->next) {
+				purple_debug_info("google_session", "\nIP : %s\n",iter->data);
+			}
+			g_list_free(iplist);
+			purple_debug_info("google_session", "get_pub_ip : %s",purple_network_get_public_ip());
+
+		}
 	}
-
+	
+	}
 }
-
+	
 void
 jabber_google_session_parse(JabberStream *js, const char *from,
                             JabberIqType type, const char *iq_id,
@@ -1338,7 +1380,7 @@ jabber_google_session_parse(JabberStream
 		else
 			purple_debug_info("google_session", "Check for session!=initiate and peer==gtalk FAILED.\n");	  
 	
-*/	}
+		   */	}
 	/* If the session doesn't exist, this has to be an initiate message */
 
 	if (strcmp(xmlnode_get_attrib(session_node, "type"), "initiate")) {
@@ -1362,4 +1404,5 @@ jabber_google_session_parse(JabberStream
 	session_data->share_session = g_new0(GoogleXferSessionData, 1);
 	google_session_handle_initiate(js, session, session_node, iq_id);
 }
+
 #endif /* USE_VV */



More information about the Commits mailing list