/soc/2013/ashmew2/filetransferX: db20f6decd05: Sending candidates

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


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

Description:

Sending candidates

diffstat:

 libpurple/protocols/jabber/google/google_session.c |  104 +++++++++++---------
 1 files changed, 57 insertions(+), 47 deletions(-)

diffs (158 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
@@ -1058,23 +1058,22 @@ cb_candidate_gathering_done(NiceAgent *a
 	if(lcands) {
 		GList *iter = lcands;
 		GoogleSession *session = (GoogleSession *)user_data;
-		GoogleSessionAVData *session_data = (GoogleSessionAVData *)session->session_data;
+		GoogleAVSessionData *session_data = (GoogleAVSessionData *)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];
+				gchar *username, *password, *port;
+				gchar *ip = g_malloc(NICE_ADDRESS_STRING_LEN + 1);
+				gchar *pref;
 				NiceCandidateType type;
 				xmlnode *sess;
-				xmlnode *candidate;
+				xmlnode *candidate, *transport;
 				guint component_id;
 				/*TODO : REMOVE ME : transport needs to be replaced by candid*/
 				/*Is component ID necessary? This is a share session TODO*/
@@ -1084,65 +1083,74 @@ cb_candidate_gathering_done(NiceAgent *a
 <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>
 				*/
 
+				if(!nice_agent_get_local_credentials(agent, stream_id,
+								     &username, &password))
+					purple_debug_info("google_session","Getting local credentials FAILED..\n");
+				else
+					purple_debug_info("google_session","Getting local credentials SUCCESSFUL..\n");
+
 				iq = jabber_iq_new(session->js, JABBER_IQ_SET);
-				sess = google_session_create_xmlnode(session, "candidates");
+				sess = google_session_create_xmlnode(session, "transport-info");
 				xmlnode_insert_child(iq->node, sess);
 				xmlnode_set_attrib(iq->node, "to", session->remote_jid);
-				
+
+				purple_debug_info("google_session", "IQ Created. Now Transport Node : \n");
+				transport = xmlnode_new("transport");
+				xmlnode_set_namespace(transport, NS_GOOGLE_TRANSPORT_P2P);
+				xmlnode_insert_child(sess, transport);
+
 				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);
-		
+				/*We already have an IP, use that*/
+				/*ip = purple_media_candidate_get_ip(transport); >= REMOVE ME : TODO*/
+				purple_debug_info("google_session", "Using nice_address_to_string : \n");
+				nice_address_to_string(&candid->addr, ip);
+				port = g_strdup_printf("%u",nice_address_get_port(&candid->addr));
+
+				purple_debug_info("google_session", "IP and port : %s:%s\n",ip,port);
+				pref = g_strdup_printf("%u",candid->priority);
+
+				username = candid->username;
+				password = candid->password;
+				type = candid->type;
+				purple_debug_info("google_session", "Setting attributes now.. : \n");
+				
 				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, "name", "private-1");
+				
+				
+				purple_debug_info("google_session", "Setting some more attributes now.. : \n");
+				xmlnode_set_attrib(candidate, "username", username != NULL ? username : "");
 				xmlnode_set_attrib(candidate, "password",
 						   password != NULL ? password : "");
+
+				purple_debug_info("google_session", "Setting even more attributes now.. : \n");
+
 				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, "protocol", "udp");
+
+				/*CHECK THIS : TODO Type*/
+				purple_debug_info("google_session", "Setting type attrib : \n");
+				xmlnode_set_attrib(candidate, "type", 
+						   type == NICE_CANDIDATE_TYPE_HOST ? "local":
+						   type == NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE ? "stun":
+						   type == NICE_CANDIDATE_TYPE_PEER_REFLEXIVE ? "prflx":
+						   type == NICE_CANDIDATE_TYPE_RELAYED ? "relay"
+						   : "local");
+
 				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);
+				xmlnode_insert_child(transport, candidate);
+
+				purple_debug_info("google_session", "We Send : 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);
-				
+				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*/
 			
@@ -1211,7 +1219,9 @@ gtalk_xfer_send_candidates(GoogleSession
 	else
 		purple_debug_info("google_session", "Gather Candidates returned TRUE\n");
 	g_main_loop_run (gloop);
+	g_main_loop_unref(gloop);
 	g_object_unref(agent);
+
 	return;
 	// Attach to the component to receive the data
 	



More information about the Commits mailing list