/soc/2013/ashmew2/filetransferX: cedbd17832bd: gtalk_xfer_handle...

Ashish Gupta ashmew2 at gmail.com
Sun Aug 18 07:53:45 EDT 2013


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

Description:

gtalk_xfer_handle_candidates() added

diffstat:

 libpurple/protocols/jabber/google/google_session.c |  98 +++++++++++++++++++--
 1 files changed, 85 insertions(+), 13 deletions(-)

diffs (168 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
@@ -544,6 +544,7 @@ jabber_google_session_initiate(JabberStr
 	session->remote_jid = jid;
 	session_data = g_new0(GoogleAVSessionData, 1);
 	((GoogleAVSessionData *)session_data)->share_session = g_new0(GoogleXferSessionData, 1);
+	
 	session->session_data = session_data;
 
 	if (type & PURPLE_MEDIA_VIDEO)
@@ -1081,10 +1082,60 @@ google_session_handle_transport_accept(J
 }
 
 static void
+gtalk_xfer_handle_candidates(JabberStream *js, GoogleSession *session, xmlnode *sess, const char *iq_id)
+{/*<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>*/
+
+	NiceCandidate *candid;
+	GSList *candidate_list = NULL;
+	xmlnode *candidate_node;
+	GoogleAVSession *session_data = (GoogleAVSessionData*)session->session_data;
+	GoogleXferSessionData *share_session = session_data->share_session;
+
+	if(sess)
+		candidate_node = xmlnode_get_child(xmlnode_get_child(sess, "transport"), "candidate");
+
+	if(candidate) {
+		gchar *type = xmlnode_get_attrib(candidate_node, "type");
+		candid->type = (!strcmp(type, "local") ? NICE_CANDIDATE_TYPE_HOST : 
+				!strcmp(type, "stun") ? NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE :
+				!strcmp(type, "relay") ? NICE_CANDIDATE_TYPE_RELAYED :
+				NICE_CANDIDATE_TYPE_HOST);
+		if(!strcmp(xmlnode_get_attrib(candidate_node, "protocol"), "udp"))
+			candid->transport = NICE_CANDIDATE_TRANSPORT_UDP;
+		else {
+			purple_debug_info("google_session", "Remote Candidate is not UDP...Returning..\n");
+			return;
+		}
+		nice_address_init(&candid->addr);
+		nice_address_set_from_string(&candid->addr, xmlnode_get_attrib(candidate_node, "address"));
+		nice_address_set_port(&candid->addr, atoi(xmlnode_get_attrib(candidate_node, "port")));
+		candid->stream_id = share_session->stream_id;
+		candid->username = g_strdup(xmlnode_get_attrib("username"));
+		if(!candid->username)
+			candid->username = g_strdup("");
+		candid->password = g_strdup(xmlnode_get_attrib("password"));
+		if(!candid->password)
+			candid->password = g_strdup("");
+		
+		candidate_list = g_slist_append(candidate_list, candid);
+		nice_agent_set_remote_candidates(share_session->share_agent, 
+						 share_session->stream_id, share_session->share_chanel->component_id, 
+						 candidate_list);
+		g_slist_free(candidate_list);
+	}
+	
+	purple_debug_info("google_session", "Added remote candidate to Nice Agent.\n");	
+	
+}
+
+static void
 google_session_handle_transport_info(JabberStream *js, GoogleSession *session, xmlnode *sess, const char *iq_id)
 {
-  
-	google_session_handle_candidates(js, session, sess, iq_id);
+	GoogleAVSessionData *session_data = (GoogleAVSessionData *)session->session_data;
+	if(session_data->share)
+		gtalk_xfer_handle_candidates(js, session, sess, iq_id);
+	else
+		google_session_handle_candidates(js, session, sess, iq_id);
 }
 
 static void
@@ -1250,9 +1301,11 @@ gtalk_xfer_send_candidates(GoogleSession
 		password = g_strdup(nice_candid->password);
 				
 		xmlnode_set_attrib(candidate, "username", username != NULL ? username : "");
-		xmlnode_set_attrib(candidate, "password",
+		/*	xmlnode_set_attrib(candidate, "password",
 				   password != NULL ? password : "");
-
+		TODO: Setting password blank for now. Let's see what happens. Remove Me.
+		*/
+		xmlnode_set_attrib(candidate, "password", "");
 //		purple_debug_info("google_session", "Setting even more attributes now.. : \n");
 /*TODO: Fix preference*/
 		xmlnode_set_attrib(candidate, "preference", type == NICE_CANDIDATE_TYPE_HOST ? "0.000015":
@@ -1448,7 +1501,11 @@ This will most probably end in successfu
 */
 	nice_agent_attach_recv (agent, stream_id, 1,
 				 g_main_loop_get_context (gloop), cb_nice_recv, NULL);
-
+/*				 TODO: REMOVE ME. Trying g_main_context_default () instead of gloop.*/
+/*
+	nice_agent_attach_recv (agent, stream_id, 1,
+				g_main_context_default(), cb_nice_recv, NULL);
+*/
 	g_signal_connect (G_OBJECT (agent), "candidate-gathering-done",
 			  G_CALLBACK (cb_candidate_gathering_done),  session);
 
@@ -1463,9 +1520,11 @@ This will most probably end in successfu
 		purple_debug_info("google_session", "Gather candidates returned FALSE\n");
 	else
 		purple_debug_info("google_session", "Gather Candidates returned TRUE\n");
+	
 	g_main_loop_run (gloop);
 	g_main_loop_unref(gloop); /*TODO: Check if gloop is causing a CRASH when Destroying pidgin instance*/
 	g_object_unref(agent); /*Something here is causing a CRASH on destroying pidgin..Find out what! TODO*/
+	
 	return;
 }
 
@@ -1682,22 +1741,37 @@ void
 gtalk_xfer_init(PurpleXfer *xfer)
 {
 	GoogleSession *session = (GoogleSession *)(xfer->data);
-	GoogleAVSessionData *session_data = (GoogleAVSessionData *)(session->session_data);
+	GoogleAVSessionData *session_data = (GoogleAVSessionData *)session->session_data;
+	GoogleXferSessionData *share_session = session_data->share_session;
 	GList *iter;
 	PurpleNetworkListenData *portdata = purple_network_listen_range_family
 	  (27015, 64000, AF_INET, SOCK_STREAM, gtalk_port_cb, xfer);
-	JabberStream *js = session->js;
-  
+	JabberStream *js = session->js;  
+
 	purple_debug_info("google_session", "Inside gtalk_xfer_init() \n");
 	purple_debug_info("google_session", "We have a file now. Details of Xfer :\nwho : %s\nfilename:%s\nlocal_filename:%s\nsize:%d\nlocal_port : %d\nremote_port:%d\nremote_ip:%s\nBytes Sent:%d\nBytes Remaining:%d\n",xfer->who,xfer->filename,xfer->local_filename,xfer->size,xfer->local_port,xfer->remote_port,xfer->remote_ip,xfer->bytes_sent,xfer->bytes_remaining);
-  if (js->google_relay_host && js->google_relay_token) {
+
+	if(share_session) {
+		NiceAgent *agent = nice_agent_new_reliable (NULL, NICE_COMPATIBILITY_RFC5245);
+		guint stream_id;
+		stream_id = nice_agent_add_stream (agent, 1);
+		share_session->stream_id = stream_id;
+		share_session->share_agent = agent;
+		purple_debug_info("google_session", "share_session wasn't NULL\n");
+	}
+	else {
+		share_session = g_new0(GoogleXferSessionData, 1);
+		purple_debug_info("google_session", "share_session WAS NULL\n");
+	}
+
+/*  if (js->google_relay_host && js->google_relay_token) {
 	  jabber_google_do_relay_request(js, session,
 					 jabber_google_relay_response_session_initiate_cb);
   } else {
 	  jabber_google_relay_response_session_initiate_cb(session, NULL, 0, 0, 0,
 							   NULL, NULL);
   }
-
+*/
 	gtalk_xfer_send_initiate(xfer);
   
 /**TODO: IP.PORT etc should all be in the GoogleSession thing? I guess so.*/
@@ -1858,10 +1932,8 @@ google_session_parse_iq(JabberStream *js
 		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")) {
-//		gtalk_xfer_prepare_candidates(session);
+		gtalk_xfer_prepare_candidates(session);
 		google_session_handle_transport_info(js, session, sess, iq_id);
-
-
 //		google_xfer_send(js,session); TODO: Clean up a bit.
 //		purple_debug_info("google_session", "Back in parse_iq\n");
 //		if(js->stun_ip)



More information about the Commits mailing list