/soc/2013/ashmew2/filetransferX: f5b29d9aff5c: Modified GoogleXf...

Ashish Gupta ashmew2 at gmail.com
Thu Aug 15 17:45:09 EDT 2013


Changeset: f5b29d9aff5c2c2b5d1f40f8d6cbec6f9575cf27
Author:	 Ashish Gupta <ashmew2 at gmail.com>
Date:	 2013-08-15 12:59 +0530
Branch:	 filetransferX
URL: https://hg.pidgin.im/soc/2013/ashmew2/filetransferX/rev/f5b29d9aff5c

Description:

Modified GoogleXferSessionData

diffstat:

 libpurple/protocols/jabber/google/google_session.c |  97 ++++++++++++++++++++-
 1 files changed, 89 insertions(+), 8 deletions(-)

diffs (145 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
@@ -38,6 +38,7 @@ typedef struct {
 	gchar *source_url;
 	/*Needs to have a manifest Entry for Folder Sharing*/
 	GList *remote_share_candidates; /* list of PurpleMediaCandidate */
+	GList *local_share_candidates;
 } GoogleXferSessionData; 
 
 typedef struct {
@@ -1056,13 +1057,95 @@ cb_candidate_gathering_done(NiceAgent *a
 	
 	if(lcands) {
 		GList *iter = lcands;
+		GoogleSession *session = (GoogleSession *)user_data;
+		GoogleSessionAVData *session_data = (GoogleSessionAVData *)session->session_data;
+		GoogleXferSessionData *share_session = (GoogleXferSessionData *)session_data->share_session;
+
 		purple_debug_info("google_session", "lcands is nOT null..\n");
 		for(; iter; iter = iter->next) {
 			gchar *ip = g_malloc(NICE_ADDRESS_STRING_LEN + 1);
 			NiceCandidate *candid = (NiceCandidate *)iter->data;
+/*Insert it into our GoogleXferSession's local_share_candidates*/
+			share_session->local_share_candidates = g_list_prepend(share_session->local_share_candidates, candid);
+
+			if(1) {
+				JabberIq *iq;
+				gchar *ip, *port, *username, *password;
+				gchar pref[16];
+				NiceCandidateType type;
+				xmlnode *sess;
+				xmlnode *candidate;
+				guint component_id;
+				/*TODO : REMOVE ME : transport needs to be replaced by candid*/
+				/*Is component ID necessary? This is a share session TODO*/
+/*				component_id = purple_media_candidate_get_component_id(
+					transport);
+*/				/*Format we want to use : TODO REMOVE : 
+<iq to="doondoon1234 at gmail.com/F0529E73" type="set" id="249" from="ashmew2 at gmail.com/Talk.v1040217A105"><session type="transport-info" id="1195983148" initiator="ashmew2 at gmail.com/Talk.v1040217A105" xmlns="http://www.google.com/session"><transport xmlns="http://www.google.com/transport/p2p"><candidate name="private-1" address="10.0.2.15" port="58919" preference="1" username="j8xIQAN/LvaC/dxb" protocol="udp" generation="0" password="eEy12J+BFBmZO0jj" type="local" network="0"/></transport></session></iq>
+				*/
+
+				iq = jabber_iq_new(session->js, JABBER_IQ_SET);
+				sess = google_session_create_xmlnode(session, "candidates");
+				xmlnode_insert_child(iq->node, sess);
+				xmlnode_set_attrib(iq->node, "to", session->remote_jid);
+				
+				candidate = xmlnode_new("candidate");
+				
+				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);
+		
+				xmlnode_set_attrib(candidate, "address", ip);
+				xmlnode_set_attrib(candidate, "port", port);
+				xmlnode_set_attrib(candidate, "name",
+						   component_id == PURPLE_MEDIA_COMPONENT_RTP ?
+						   video ? "video_rtp" : "rtp" :
+						   component_id == PURPLE_MEDIA_COMPONENT_RTCP ?
+						   video ? "video_rtcp" : "rtcp" : "none");
+				xmlnode_set_attrib(candidate, "username", username);
+				/*
+				 * As of this writing, Farsight 2 in Google compatibility
+				 * mode doesn't provide a password. The Gmail client
+				 * requires this to be set.
+				 */
+				xmlnode_set_attrib(candidate, "password",
+						   password != NULL ? password : "");
+				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, candidate);
+				purple_debug_info("google_session", "Candidate's IP and PORT : %s:%s",ip,port);
+				g_free(ip);
+				g_free(port);
+				g_free(username);
+				g_free(password);
+		
+				jabber_iq_send(iq);
+				
+			}
 			NiceAddress *address = &(candid->addr);
 			nice_address_to_string (address, ip);
 			purple_debug_info("google_session", "IP is %s\n",ip);
+			
+			/*TODO: Put me at my proper location*/
+			/*Sending each candidate here itself*/
+			
 		}
 	}
 	else
@@ -1099,7 +1182,6 @@ gtalk_xfer_send_candidates(GoogleSession
 		purple_debug_info("google_session", "Agent's stun was not NULL.");
 
 	gloop = g_main_loop_new(NULL, FALSE);
-	  
 	
 	purple_debug_info("google_session", "Inside send candids\n");
 	temp_struct->agent = agent;
@@ -1114,15 +1196,14 @@ gtalk_xfer_send_candidates(GoogleSession
   
 	stream_id = nice_agent_add_stream (agent, 1);
 	temp_struct->stream_id = stream_id;
-
-	  nice_agent_attach_recv(agent, stream_id, 1,
-      g_main_loop_get_context (gloop), cb_nice_recv, NULL);
-
+	
+	nice_agent_attach_recv(agent, stream_id, 1,
+				 g_main_loop_get_context (gloop), cb_nice_recv, NULL);
 /*	  nice_agent_attach_recv (agent, stream_id, 1, NULL,
-				cb_nice_recv, NULL);
+	  cb_nice_recv, NULL);
 */
 	g_signal_connect (G_OBJECT (agent), "candidate-gathering-done",
-			  G_CALLBACK (cb_candidate_gathering_done),  NULL);
+			  G_CALLBACK (cb_candidate_gathering_done),  session);
 	
 
 	if(!nice_agent_gather_candidates (agent, stream_id))
@@ -1137,7 +1218,7 @@ gtalk_xfer_send_candidates(GoogleSession
 	    /*TODO: need to add $(NICE_LIBS) and look it up with configure.ac*/
   
 	// ... Wait until the signal candidate-gathering-done is fired ...
-	lcands = nice_agent_get_local_candidates(agent, stream_id, 1);
+/*REMOVE ME : 	lcands = nice_agent_get_local_candidates(agent, stream_id, 1);*/
 	return;
 
 	for(; lcands ; lcands=lcands->next) {



More information about the Commits mailing list