/soc/2013/ashmew2/filetransferY: de2fd0892c1a: Added support for...

Ashish Gupta ashmew2 at gmail.com
Mon Sep 16 13:39:22 EDT 2013


Changeset: de2fd0892c1a8a387b19da369123d30960be3465
Author:	 Ashish Gupta <ashmew2 at gmail.com>
Date:	 2013-09-16 19:09 +0530
Branch:	 filetransferX
URL: https://hg.pidgin.im/soc/2013/ashmew2/filetransferY/rev/de2fd0892c1a

Description:

Added support for sending/handling reject messages. Also Cleaned up code.

diffstat:

 libpurple/protocols/jabber/google/google_session.c |  765 ++------------------
 1 files changed, 107 insertions(+), 658 deletions(-)

diffs (truncated from 1174 to 300 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
@@ -123,15 +123,16 @@ google_session_destroy(GoogleSession *se
 	JabberStream *js = session->js;
 	
 	if(session_data->share) {
-		/*TODO: Add destroy_session_stuff. Make sure to remove all the callbacks as well.*/
 		GoogleXferSessionData *share_session = session_data->share_session;
 		GSList *temp = NULL;
 
-		if(!share_session->share_agent)
+		purple_debug_info("google_session", "Destroying the current Google Session..\n");
+
+/*TODO REMOVE:		if(!share_session->share_agent)
 			purple_debug_info("google_session", "Agent is NULL!\n");
 		else
 			purple_debug_info("google_session", "Agent is not NULL!\n");
-		
+*/	
 		if(!purple_xfer_is_completed(share_session->xfer))
 			purple_xfer_end(share_session->xfer);
 		
@@ -145,9 +146,6 @@ google_session_destroy(GoogleSession *se
 		g_free(share_session->file_buf);
 		g_free(share_session->channel_name);
 
-/*(00:52:13) jabber: Recv (ssl)(739): <iq type="error" id="purple795256ca" to="doondoon1234 at gmail.com/2697BDC0" from="ashmew2 at gmail.com/Talk.v104D0FD2998"><session type="initiate" id="purple795256c9" initiator="doondoon1234 at gmail.com/2697BDC0" xmlns="http://www.google.com/session"><description xmlns="http://www.google.com/session/share"><manifest><file size="6425"><name>conversion.js</name></file></manifest><protocol><http><url name="source-path">/temporary/c75z072y65r8l3s8svm3k8zm94ukyut6/</url><url name="preview-path">/temporary/y38r081c30n8j2r5jtd1f1dr16tbmkv1/</url></http></protocol></description><transport xmlns="http://www.google.com/transport/p2p"/></session><error code="405" type="cancel"><not-allowed xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>
-TODO: Remove 
-*/
 		if(share_session->share_agent) {
 			g_signal_handlers_disconnect_by_func(G_OBJECT(share_session->share_agent),
 							     G_CALLBACK (cb_candidate_gathering_done), session);
@@ -179,7 +177,6 @@ TODO: Remove
 
 		g_free(share_session);		
 		g_free(temp);		
-		purple_debug_info("google_session", "Destroyed gtalk_xfer session.\n");	    
 	}
 
 	js->google_share_sessions = g_list_remove(js->google_share_sessions,session);
@@ -199,7 +196,6 @@ TODO: Remove
 
 	g_free(session->session_data);
 	g_free(session);
-	purple_debug_info("google_session", "Reached end of function..\n");
 }
 
 static xmlnode *
@@ -561,13 +557,12 @@ jabber_google_relay_response_session_ini
 			purple_debug_info("google_session", "share_agent created with stream id : %d!\n", stream_id);
 
 			if(js->stun_ip) {
-				purple_debug_info("google_session", "Setting Agent's STUN..");
 				g_object_set(G_OBJECT (agent), "stun-server", js->stun_ip, NULL);
 				g_object_set(G_OBJECT (agent), "stun-server-port", js->stun_port, NULL);
 			}
-
+/*TODO: REMOVE ME???
 			if (relay_ip) {
-				purple_debug_info("google_session", "Setting relay stuff on the agent\n");
+				purple_debug_info("google_session", "Setting relay info on the agent..\n");
 				if (relay_udp)
 					nice_agent_set_relay_info(agent, share_session->stream_id, 1, relay_ip, relay_udp,
 								  relay_username, relay_password, NICE_RELAY_TYPE_TURN_UDP);
@@ -579,58 +574,12 @@ jabber_google_relay_response_session_ini
 								  relay_username, relay_password, NICE_RELAY_TYPE_TURN_TLS);
 			}
 
-/*			nice_agent_attach_recv(agent, stream_id, 1, g_main_context_default(),
-					       cb_nice_recv, share_session);
+			return;
+*/
+		}
+		else 
+			purple_debug_info("google_session", "share_agent is already initialized!..\n");		
 
-			g_signal_connect(G_OBJECT(agent), "candidate-gathering-done",
-					 G_CALLBACK(cb_candidate_gathering_done), session);
-			g_signal_connect(G_OBJECT(agent), "reliable-transport-writable",
-					 G_CALLBACK(cb_nice_component_writable), session);
-			g_signal_connect(G_OBJECT(agent), "component-state-changed",
-					 G_CALLBACK(cb_nice_component_state_changed), session);
-			Add relay candidates to our candidate list?
-		            * candidate address='49.248.181.68' port='46448' username='HKmLfAkZB81f7r8x' password='' preference='0.000000' protocol='udp' type='stun' component='1' network='0' generation='0' name='private-1'
- */
-			purple_debug_info("google_session", "share_agent is NULL in relab_cb! Not adding manually the candidates. ..\n");
-/*Set up other stuff for NiceAgent TODO*/
-/*TODO : Return for now, trying to receive a file from GTalk, otherwise we went on with the relay_candidate_* set up..*/
-/*TODO: The point here is that the share_agent will ALWAYS BE NULL when receiving a file because we are not changing it in
-  handle_initiate() */
-/*
-			relay_candidate_udp = nice_candidate_new(NICE_CANDIDATE_TYPE_RELAYED);
-			relay_candidate_udp->transport = NICE_CANDIDATE_TRANSPORT_UDP;
-			relay_candidate_udp->priority = 0;
-			relay_candidate_udp->stream_id = stream_id;
-			relay_candidate_udp->username = g_strdup_printf("%s",relay_username);
-			relay_candidate_udp->password = g_strdup_printf("%s",relay_password);
-			nice_address_set_from_string(&relay_candidate_udp->addr, relay_ip);
-			nice_address_set_port(&relay_candidate_udp->addr, relay_udp);
-			relay_candidate_udp->turn = g_new0(TurnServer, 1);
-			nice_address_set_from_string(&relay_candidate_udp->turn->server, relay_ip);
-			relay_candidate_udp->turn->type = NICE_RELAY_TYPE_TURN_UDP;
-			relay_candidate_udp->turn->username = g_strdup_printf("%s",relay_username);
-			relay_candidate_udp->turn->password = g_strdup_printf("%s",relay_password);
-			
-			relay_candidate_tcp = nice_candidate_copy(relay_candidate_udp);
-			nice_address_set_port(&relay_candidate_tcp->addr, relay_tcp);
-			
-			relay_candidate_ssltcp = nice_candidate_copy(relay_candidate_udp);
-			nice_address_set_port(&relay_candidate_ssltcp->addr, relay_ssltcp);
-			
-			share_session->local_share_candidates = g_list_append(share_session->local_share_candidates, relay_candidate_udp);
-//			share_session->local_share_candidates = g_list_append(share_session->local_share_candidates, relay_candidate_tcp);
-//			share_session->local_share_candidates = g_list_append(share_session->local_share_candidates, relay_candidate_ssltcp);
-*/			
-			purple_debug_info("google_session", "Did not add candidates manually.\n");
-			return;
-		}
-		else {
-			purple_debug_info("google_session", "share_agent is NOT NULL\n");
-		}
-/*TODO: Add candidates here to the local_candidates GList in GoogleXferSessionData;*/
-		
-
-/*		purple_debug_info("google_session", "Trying to Set Relay IP : %s\n", relay_ip);*/
 		if (relay_ip) {
 			if (relay_udp)
 				nice_agent_set_relay_info(agent, share_session->stream_id, 1, relay_ip, relay_udp,
@@ -643,25 +592,20 @@ jabber_google_relay_response_session_ini
 							  relay_username, relay_password, NICE_RELAY_TYPE_TURN_TLS);
 		}
 
-/*		nice_agent_set_relay_info (agent, share_session->stream_id, 1, relay_ip, relay_udp, relay_username,
-					      relay_password, NICE_RELAY_TYPE_TURN_UDP)) 
-			purple_debug_info("google_session","Setting Relay on Niceagent Failed..\n");
-		else
-			purple_debug_info("google_session","Setting Relay on Niceagent Succeeded..\n");
-*/
 		purple_debug_info("google_session", "Calling xfer_send_candiates()\n");
-/*TODO: Uncomment send_candidates below*/
 		
 		session->relay_processing = FALSE;
+
 		if(session->session_should_die) {
 			google_session_destroy(session);
 			return;
 		}
 		
-		gtalk_xfer_send_candidates(session);
+/*		gtalk_xfer_send_candidates(session);  TODO: Possible Removal*/
 		return;
 	}
-	
+	/*The procedure for Share Session ends here. What follows is the process needed for Media sessions*/
+
 	session_data->media = purple_media_manager_create_media(
 			purple_media_manager_get(),
 			purple_connection_get_account(js->gc),
@@ -1077,10 +1021,6 @@ FT XML:
 		/*Ask the user to accept the file transfer*/
 		purple_xfer_request(share_session->xfer);
 
-		/*TODO: Uncomment the send_transport_accept and sent it __ONLY__ when we have accepted the file request
-		 Moving to gtalk_xfer_init*/
-//		gtalk_xfer_send_transport_accept(js, session);
-
 		return TRUE;
 	}
 	return TRUE;	
@@ -1099,10 +1039,6 @@ gtalk_xfer_handle_info(JabberStream  *js
 				    js->user->domain,
 				    js->user->resource);
 
-	/*Since a channel was specified in the message, we should mostly be creating a ShareChannel right here TODO*/	
-	/*Added the complete xmlnode above, need to fit it here for this XML : (At end of Share Session) : 
-  <iq to="doondoon1234 at gmail.com/24E670D3" type="set" id="102" from="ashmew2 at gmail.com/Talk.v1048DA41A6C"><session type="info" id="purple4bbd2553" initiator="doondoon1234 at gmail.com/24E670D3" xmlns="http://www.google.com/session"><complete xmlns="http://www.google.com/session/share"/></session></iq>
-	*/
 	purple_debug_info("google_session", "Inside gtalk_xfer_handle_info\n");
 	
 	if(complete) {
@@ -1115,24 +1051,17 @@ gtalk_xfer_handle_info(JabberStream  *js
 		return;
 	}
 
-	if(channel) {
-
-/*		gboolean is_initiator = !strcmp(session->id.initiator, me); TODO*/
-		/*TODO: Make sure the NiceAgent exists here?*/
+	if(channel)
 		share_session->channel_name = g_strdup(xmlnode_get_attrib(channel, "name"));
-	}
 	
 	iq = jabber_iq_new(js, JABBER_IQ_RESULT);
 	jabber_iq_set_id(iq, iq_id);
 	xmlnode_set_attrib(iq->node, "to", session->remote_jid);
 	jabber_iq_send(iq);
-	/*TODO: Finding a good place for calling prepare candidates*/
-	/*TODO: Uncomment prepare_candidates*/
-	/*TODO: Judge the utility of gtalk_xfer_prepare_candidates(session)*/
-	purple_debug_info("google_session", "Calling gather candidates..\n");
+
+	purple_debug_info("google_session", "Starting candidate cathering with nice agent..\n");
+
 	nice_agent_gather_candidates(share_session->share_agent, share_session->stream_id);
-
-	/*	gtalk_xfer_prepare_candidates(session);*/
 }
 
 static void
@@ -1243,34 +1172,6 @@ google_session_handle_candidates(JabberS
 	jabber_iq_set_id(result, iq_id);
 	xmlnode_set_attrib(result->node, "to", session->remote_jid);
 	jabber_iq_send(result);
-
-/*  TODO: Relocate me to proper place */
-/* TODO: Please use the below somewhere..looks right?*/
-/*
-
-	if(1) {
-	PurpleUtilFetchUrlData *url_data = NULL;
-	gchar *url = g_strdup_printf("http://%s", temp_ip);
-	gchar *request =
-		g_strdup_printf("GET %s HTTP/1.1"
-				,share_session->source_url);
-
-	JabberGoogleRelayCallbackData *data = g_new0(JabberGoogleRelayCallbackData, 1);
-
-	data->session = session;
-	data->cb = NULL;
-
-	purple_debug_info("google_session","Sending GET Request For File..\n");
-	url_data =
-		purple_util_fetch_url_request(url, FALSE, NULL, FALSE, request, FALSE,
-			gtalk_get_request_cb, data);
-	if (url_data) 
-		purple_debug_info("google_session", "Got some finite data..\n");
-	else
-		purple_debug_info("google_session", "Got no data....\n");
-	
-		}
-*/
 }
 
 static void
@@ -1466,6 +1367,19 @@ google_session_handle_accept(JabberStrea
 	jabber_iq_send(result);
 }
 
+/*TODO: Make me complete..*/
+static void 
+gtalk_xfer_handle_reject(JabberStream *js, GoogleSession *session, const char *iq_id)
+{	
+	JabberIq *result = jabber_iq_new(js, JABBER_IQ_RESULT);
+	jabber_iq_set_id(result, iq_id);
+	xmlnode_set_attrib(result->node, "to", session->remote_jid);
+	jabber_iq_send(result);
+
+	purple_debug_info("google_session", "The remote user Rejected the Xfer request..\n");       
+	google_session_destroy(session);
+}
+
 static void
 google_session_handle_reject(JabberStream *js, GoogleSession *session, xmlnode *sess)
 {
@@ -1504,6 +1418,7 @@ gtalk_xfer_send_candidates(GoogleSession
 	GoogleXferSessionData *share_session = session_data->share_session;
 	GSList *candidates = share_session->local_share_candidates;
 	GSList *iter;
+	purple_debug_info("google_session", "inside gtalk_xfer_send_candidates()\n");
 
 	for(iter = candidates; iter; iter = iter->next) {
 		JabberIq *iq;
@@ -1631,10 +1546,6 @@ nice_candidate_to_xml(const NiceCandidat
 void
 cb_candidate_gathering_done(NiceAgent *agent, guint stream_id, gpointer user_data)
 {
-/*
-  guint  stream_id = temp->stream_id;
-  NiceAgent *agent = temp->agent;
-*/
 	char *local_ufrag, *local_password;
 	GoogleSession *session = (GoogleSession *)user_data;
 	GoogleAVSessionData *session_data = session->session_data;
@@ -1647,7 +1558,7 @@ cb_candidate_gathering_done(NiceAgent *a
 	/* add remote candidates received while gathering local candidates */
 	nice_agent_set_remote_candidates(agent, share_session->stream_id, 1,
 					 share_session->remote_share_candidates);
-/*TODO: Free the remote_candidates list of the share_session : DONE?*/
+
 
 	while (share_session->remote_share_candidates) {
 		NiceCandidate *c = (NiceCandidate *) share_session->remote_share_candidates->data;
@@ -1664,7 +1575,8 @@ cb_candidate_gathering_done(NiceAgent *a
 				session->js->user->node,
 				session->js->user->domain,
 				session->js->user->resource);
-		/*Preparing the xmlnode for sending out candidates to gtalk*/
+		
+		/*Preparing the xml nodes for sending out candidates to gtalk*/



More information about the Commits mailing list