/soc/2013/ashmew2/filetransferX: f511b8288712: (Crash) gtalk_xfe...

Ashish Gupta ashmew2 at gmail.com
Wed Aug 7 18:17:37 EDT 2013


Changeset: f511b8288712309e2d73fd11619611d7b66201f4
Author:	 Ashish Gupta <ashmew2 at gmail.com>
Date:	 2013-08-08 03:47 +0530
Branch:	 filetransferX
URL: https://hg.pidgin.im/soc/2013/ashmew2/filetransferX/rev/f511b8288712

Description:

(Crash) gtalk_xfer_send_candidates()

diffstat:

 libpurple/protocols/jabber/google/google_session.c |  168 ++++++++++++++++----
 libpurple/protocols/jabber/google/jingleinfo.c     |    1 -
 2 files changed, 131 insertions(+), 38 deletions(-)

diffs (278 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
@@ -48,7 +48,7 @@ typedef struct {
 	 							   to media (ie. after getting relay credentials */
 } GoogleAVSessionData;
 
-/*typedef struct {
+/*TODO: When cleaning uptypedef struct {
 
   } GoogleShareManifest;
 */
@@ -653,10 +653,8 @@ google_session_handle_initiate(JabberStr
 				session->js->user->node,
 				session->js->user->domain,
 				session->js->user->resource);
-		
-		char *temp=g_strdup_printf("<iq to=\"%s\" type=\"set\" id=\"%s\" from=\"%s\"><session type=\"initiate\" id=\"%s\" initiator=\"%s\" xmlns=\"http://www.google.com/session\"><description xmlns=\"http://www.google.com/session/share\"><manifest><file size=\"1611\"><name>XPLUS5.rar</name></file></manifest><protocol><http><url name=\"source-path\">/temporary/667e854066cbd01f8cd111c35752275e/</url><url name=\"preview-path\">/temporary/bca878ad01c248741978a105ed28d9a4/</url></http></protocol></description><transport xmlns=\"http://www.google.com/transport/p2p\"/></session></iq>",session->remote_jid, iq_id, me, xmlnode_get_attrib(sess, "id"), me);
 
-		
+		purple_debug_info("google_session", "Indeed a SHARE Session\n");
 		if( description ) {
 			purple_debug_info("google_session", "description is not NULL");
 			manifest = xmlnode_get_child(description, "manifest");
@@ -779,8 +777,7 @@ FT XML:
 		//		purple_debug_info("google_session",x "Sent Both ResponseIq. Now Trying to send rest of the XML stuff.");
 		//		responsetxt = xmlnode_to_str(sess,&responsetxtlen);
 		//purple_debug_info("google_session", "\nresponsetxt : %s with len : %d\n\n",responsetxt,responsetxtlen);
-		*/
-				
+		*/				
 		return TRUE;
 	}
 	return TRUE;	
@@ -801,14 +798,21 @@ google_session_handle_candidates(JabberS
 {
 	JabberIq *result;
 	GList *list = NULL, *video_list = NULL;
-	xmlnode *cand;
+	xmlnode *cand, *transport, *cand_parent;
 	static int name = 0;
 	char n[4];
 	GoogleAVSessionData *session_data =
 		(GoogleAVSessionData *) session->session_data;
-	purple_debug_info("google_session", "Inside google_session_handle_candidiates()\n");
-	for (cand = xmlnode_get_child(sess, "candidate"); cand;
-			cand = xmlnode_get_next_twin(cand)) {
+	
+	cand_parent = sess;
+	if(session_data->share) {
+		transport = xmlnode_get_child(sess, "transport");
+		cand_parent = transport;
+	}
+	purple_debug_info("google_session", "Inside google_session_handle_candidiates(), share is %d\n",session_data->share);
+
+	for (cand = xmlnode_get_child(cand_parent, "candidate"); cand;
+	     cand = xmlnode_get_next_twin(cand)) {
 		PurpleMediaCandidate *info;
 		const gchar *cname = xmlnode_get_attrib(cand, "name");
 		const gchar *type = xmlnode_get_attrib(cand, "type");
@@ -818,10 +822,12 @@ google_session_handle_candidates(JabberS
 		const gchar *preference = xmlnode_get_attrib(cand, "preference");
 		guint component_id;
 		
+		purple_debug_info("google_session", "Inside the for cand = loop\n");
 		if (cname && type && address && port) {
 			PurpleMediaCandidateType candidate_type;
 			guint prio = preference ? g_ascii_strtod(preference, NULL) * 1000 : 0;
-
+			
+			purple_debug_info("purple_debug_info", "inside the if block..\n");
 			g_snprintf(n, sizeof(n), "S%d", name++);
 
 			if (g_str_equal(type, "local"))
@@ -869,10 +875,15 @@ google_session_handle_candidates(JabberS
 					}
 				}
 			}
-			else /*If it's a share session*/
+			else {/*If it's a share session*/
 				session_data->share_session->remote_share_candidates = 
 					g_list_append(session_data->share_session->remote_share_candidates,
 						      info);
+				purple_debug_info("google_session", "Added remote_candid to sharelist\n");
+			}
+		}
+		else {
+			purple_debug_info("google_session", "cname && port && address && type FAILED!\n");
 		}
 	}
 	/*if session was share, list and video_list are NULL*/
@@ -1014,6 +1025,99 @@ gtalk_port_cb(int listenfd, gpointer dat
 }
 
 void
+gtalk_xfer_send_candidates(GoogleSession *session)
+{	
+	GoogleAVSessionData *session_data =  session->session_data;
+	GoogleXferSessionData *share_session = session_data->share_session;
+
+	GList *candidates = share_session->remote_share_candidates;
+	/*TODO: Candidates should be only local according to the existing media implementation..Why? Let's keep it that way for now in the loop*/
+	GList *iter;
+	if(!candidates)
+		purple_debug_info("google_session", "Candidate LIST is EMPTY!\n");
+	
+	purple_debug_info("google_session", "Inside gtalk_xfer_send_candidates()\n");
+
+	PurpleMediaCandidate *transport;
+	gboolean video = FALSE;
+
+	for (iter = candidates; iter; iter = iter->next) {
+		JabberIq *iq;
+		gchar *ip, *port, *username, *password;
+		gchar pref[16];
+		PurpleMediaCandidateType type;
+		xmlnode *sess;
+		xmlnode *candidate;
+		xmlnode *transport_node;
+
+		purple_debug_info("google_session", "inside iter loop..\n");
+
+/*		guint component_id;*/
+
+		transport = PURPLE_MEDIA_CANDIDATE(iter->data);
+
+		iq = jabber_iq_new(session->js, JABBER_IQ_SET);
+		sess = google_session_create_xmlnode(session, "transport-info");
+		xmlnode_insert_child(iq->node, sess);
+		
+		xmlnode_set_attrib(iq->node, "to", session->remote_jid);
+		
+		candidate = xmlnode_new("candidate");
+		transport_node = xmlnode_new("transport");
+
+		ip = purple_media_candidate_get_ip(transport);
+		port = g_strdup_printf("%d",
+				purple_media_candidate_get_port(transport));
+		g_ascii_dtostr(pref, 16,
+			purple_media_candidate_get_priority(transport) / 1000.0);
+		username = purple_media_candidate_get_username(transport);
+		password = purple_media_candidate_get_password(transport);
+		type = purple_media_candidate_get_candidate_type(transport);
+		if(ip)
+			xmlnode_set_attrib(candidate, "address", ip);
+		if(port)
+			xmlnode_set_attrib(candidate, "port", port);
+		if(username)
+			xmlnode_set_attrib(candidate, "username", username);
+		
+		xmlnode_set_attrib(candidate, "password",
+				password != NULL ? password : "");
+		if(pref)
+			xmlnode_set_attrib(candidate, "preference", pref);
+
+		xmlnode_set_attrib(candidate, "protocol",
+				purple_media_candidate_get_protocol(transport)
+				== PURPLE_MEDIA_NETWORK_PROTOCOL_UDP ?
+				"udp" : "tcp");
+/*
+		xmlnode_set_attrib(candidate, "type", type ==
+				PURPLE_MEDIA_CANDIDATE_TYPE_HOST ? "local" :
+						      type ==
+				PURPLE_MEDIA_CANDIDATE_TYPE_SRFLX ? "stun" :
+					       	      type ==
+				PURPLE_MEDIA_CANDIDATE_TYPE_RELAY ? "relay" :
+				NULL);
+*/
+		xmlnode_set_attrib(candidate, "generation", "0");
+		xmlnode_set_attrib(candidate, "network", "0");
+
+		xmlnode_insert_child(sess, transport_node);
+		xmlnode_insert_child(transport_node, candidate);
+		xmlnode_set_namespace(transport_node, NS_GOOGLE_TRANSPORT_P2P);
+
+		g_free(ip);
+		g_free(port);
+		g_free(username);
+		g_free(password);
+		
+		jabber_iq_send(iq);
+	}
+	purple_debug_info("google_session", "outside iter loop..\n");
+	purple_media_candidate_list_free(candidates);
+}
+
+
+void
 gtalk_xfer_start(PurpleXfer *xfer)
 {
 	purple_debug_info("google_session", "Inside gtalk_xfer_start()\n");
@@ -1037,7 +1141,7 @@ gtalk_xfer_start(PurpleXfer *xfer)
 PurpleXfer *gtalk_xfer_new(PurpleConnection *gc, const char *who)
 {
 	PurpleXfer *xfer;
-	
+	purple_network_set_stun_server("stun.l.google.com");
 	xfer = purple_xfer_new(gc->account, PURPLE_XFER_SEND, who);
 
 	if (xfer) {
@@ -1359,7 +1463,7 @@ google_session_parse_iq(JabberStream *js
 {
 	/*TODO: Add an action for type="info"*/
 	const char *type = xmlnode_get_attrib(sess, "type");
-	purple_debug_info("google_session", "\nType of IQ being parsed : %s\n",type);
+	purple_debug_info("google_session", "\nType of IQ being parsed : %s\n, STUN IP : %s\n",type,purple_network_get_stun_ip());
 	GoogleAVSessionData *session_data = (GoogleAVSessionData *)(session->session_data);
 
 	if (!strcmp(type, "initiate")) {
@@ -1372,36 +1476,26 @@ google_session_parse_iq(JabberStream *js
 		google_session_handle_reject(js, session, sess);
 	} 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")) {
 		purple_debug_info("google_session", "Inside transport-accept handle block..Calling it now..\n");
 		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_xfer_send(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) {
+//		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");
+		static int num_candid=0;
+		num_candid++;
+		if(num_candid==2) {
+			purple_debug_info("google_session", "Calling send_candids()\n");
+			gtalk_xfer_send_candidates(session);
+		}
+
+/*		if(1) {
 			GList *iplist = purple_network_get_all_local_system_ips();
 			GList *iter;
 			for(iter = iplist; iter; iter=iter->next) {
@@ -1410,7 +1504,7 @@ google_session_parse_iq(JabberStream *js
 			g_list_free(iplist);
 			purple_debug_info("google_session", "get_pub_ip : %s",purple_network_get_public_ip());
 			
-		}
+			}*/
 	}
 	else {
 		purple_debug_info("google_session", "No suitable IQ Parse Handler Found..\n");
diff --git a/libpurple/protocols/jabber/google/jingleinfo.c b/libpurple/protocols/jabber/google/jingleinfo.c
--- a/libpurple/protocols/jabber/google/jingleinfo.c
+++ b/libpurple/protocols/jabber/google/jingleinfo.c
@@ -58,7 +58,6 @@ jabber_google_stun_lookup_cb(GSList *hos
 
 		purple_debug_info("jabber", "set Google STUN IP/port address: "
 		                  "%s:%d\n", dst, port);
-
 		/* unmark ongoing query */
 		js->stun_query = NULL;
 	}



More information about the Commits mailing list