/soc/2013/ashmew2/filetransferX: 53f3bafa85f9: Removed struct Sh...

Ashish Gupta ashmew2 at gmail.com
Fri Aug 23 03:21:22 EDT 2013


Changeset: 53f3bafa85f93400551ae9c93cd0d954807ec429
Author:	 Ashish Gupta <ashmew2 at gmail.com>
Date:	 2013-08-21 21:31 +0530
Branch:	 filetransferX
URL: https://hg.pidgin.im/soc/2013/ashmew2/filetransferX/rev/53f3bafa85f9

Description:

Removed struct ShareChannel and instances

diffstat:

 libpurple/protocols/jabber/google/google_session.c |  122 +++++++++-----------
 libpurple/protocols/jabber/google/google_session.h |    1 -
 2 files changed, 57 insertions(+), 66 deletions(-)

diffs (262 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
@@ -33,23 +33,6 @@
 
 #ifdef USE_VV
 
-typedef struct {
-	NiceAgent *agent;
-	guint stream_id;
-	guint component_id;
-	gchar *name;
-	gboolean agent_attached;
-	guint share_channel_id;
-/*	HttpStatus http_status; */ /*TODO: Add enum later for current status*/
-	gchar *status_line;
-	gboolean is_chunked;
-	guint64 content_length;
-	gchar *write_buffer;
-	guint write_len;
-	gchar *read_buffer;
-	guint read_len;
-} ShareChannel;
-
 typedef enum {
 	GTALK_XFER_CHANNEL_INITIALIZED = 0,
 	GTALK_XFER_CHANNEL_SENT_HTTP_GET,
@@ -64,7 +47,6 @@ typedef struct {
 	PurpleXfer *xfer;
 	/*Needs to have a manifest Entry for Folder Sharing*/
 	NiceAgent *share_agent; /*TODO : Assess the usefulness of share_agent and stream_id*/
-	ShareChannel *share_channel;
 	gchar *channel_name;
 	NiceComponentState agent_state;
 	PurpleCircBuffer *buffer; /*Need to add something for HTTP_STATUS too */
@@ -107,7 +89,9 @@ void cb_nice_recv(NiceAgent *agent, guin
 	     guint len, gchar *buf, gpointer data);
 void cb_nice_component_writable(NiceAgent *agent, guint stream_id, guint component_id,
 				gpointer user_data);
-
+void cb_new_selected_pair(NiceAgent *agent, guint stream_id, guint component_id,
+			  gchar *lfoundation, gchar *rfoundation, gpointer user_data);
+ 
 static gboolean
 google_session_id_equal(gconstpointer a, gconstpointer b)
 {
@@ -426,17 +410,41 @@ jabber_google_session_get_params(JabberS
 	return new_params;
 }
 
-gint gtalk_xfer_init_agent(GoogleXferSessionData *share_session)
+gint gtalk_xfer_init_agent(GoogleSession *session)
 {
 	gint stream_id;
+	NiceAgent *agent;
+	GoogleAVSessionData *session_data = 
+		(GoogleAVSessionData *)session->session_data;
+	GoogleXferSessionData *share_session = session_data->share_session;
+		
 	if(!share_session)
 		return -1;
 
 	if(share_session->share_agent)
 		return share_session->stream_id;
 
-	share_session->share_agent = nice_agent_new_reliable (g_main_context_default(), NICE_COMPATIBILITY_GOOGLE);
-	stream_id = nice_agent_add_stream(share_session->share_agent, 1);
+	agent = share_session->share_agent;
+	
+	agent = nice_agent_new_reliable (g_main_context_default(), NICE_COMPATIBILITY_GOOGLE);
+	stream_id = nice_agent_add_stream(agent, 1);
+
+	nice_agent_attach_recv (agent, stream_id, 1, g_main_context_default(),
+				cb_nice_recv, share_session);
+	
+	g_signal_connect (G_OBJECT (agent), "candidate-gathering-done",
+			  G_CALLBACK (cb_candidate_gathering_done),  session);
+	
+	g_signal_connect (G_OBJECT (agent), "new-selected-pair",
+			  G_CALLBACK (cb_new_selected_pair), NULL);
+	
+	g_signal_connect  (G_OBJECT (agent), "component-state-changed",
+			   G_CALLBACK (cb_nice_component_state_changed), session);
+	
+	g_signal_connect (G_OBJECT (agent), "reliable-transport-writable",
+			  G_CALLBACK (cb_nice_component_writable), NULL);
+	
+	share_session->share_agent = agent;
 	share_session->stream_id = stream_id;
 	return stream_id;
 }
@@ -464,7 +472,7 @@ jabber_google_relay_response_session_ini
 				purple_xfer_request(share_session->xfer);
 			/*if xfer is of type PURPLE_XFER_SEND, We've already requested it*/
 
-			stream_id = gtalk_xfer_init_agent(share_session);
+			stream_id = gtalk_xfer_init_agent(session);
 			agent = share_session->share_agent;
 
 			purple_debug_info("google_session", "share_agent created with stream id : %d!\n", stream_id);
@@ -994,32 +1002,25 @@ FT XML:
 }
 
 void
-google_session_handle_info(JabberStream  *js, GoogleSession *session, xmlnode *sess, const char *iq_id)
+gtalk_xfer_handle_info(JabberStream  *js, GoogleSession *session, xmlnode *sess, const char *iq_id)
 {
 	JabberIq *iq;
 	xmlnode *channel = xmlnode_get_child(sess, "channel");
+	GoogleAVSessionData *session_data = (GoogleAVSessionData *)session->session_data;
+	GoogleXferSessionData *share_session = session_data->share_session;	
 	gchar *me = g_strdup_printf("%s@%s/%s",
 				    js->user->node,
 				    js->user->domain,
 				    js->user->resource);
-	
+
 	/*Since a channel was specified in the message, we should mostly be creating a ShareChannel right here TODO*/	
+	purple_debug_info("google_session", "Inside gtalk_xfer_handle_info\n");
 
 	if(channel) {
-		GoogleAVSessionData *session_data = (GoogleAVSessionData *)session->session_data;
-		GoogleXferSessionData *share_session = session_data->share_session;
+
 /*		gboolean is_initiator = !strcmp(session->id.initiator, me); TODO*/
-		share_session->share_channel = g_new0(ShareChannel, 1);
 		/*TODO: Make sure the NiceAgent exists here?*/
-		share_session->share_channel->stream_id = share_session->stream_id;
-		share_session->share_channel->agent = share_session->share_agent;
-		share_session->share_channel->name = g_strdup(xmlnode_get_attrib(channel, "name"));
-		share_session->share_channel->component_id = 1; /*TODO: Check if this will be 1 or NOT or something else*/
-		
-		if(share_session->share_agent)
-			purple_debug_info("google_session", "Added a channel !\n");
-		else
-			purple_debug_info("google_session", "Something messed up..Channel NOT Added.\n");
+		share_session->channel_name = g_strdup(xmlnode_get_attrib(channel, "name"));
 	}
 
 	iq = jabber_iq_new(js, JABBER_IQ_RESULT);
@@ -1028,16 +1029,17 @@ google_session_handle_info(JabberStream 
 	jabber_iq_send(iq);
 	/*TODO: Finding a good place for calling prepare candidates*/
 	/*TODO: Uncomment prepare_candidates*/
-	gtalk_xfer_prepare_candidates(session);
-	purple_debug_info("google_session", "CANDIDATES PREPARED!!!!!!!!!\nprepare_candidates()?\n");
+	/*TODO: Judge the utility of gtalk_xfer_prepare_candidates(session)*/
+	nice_agent_gather_candidates(share_session->share_agent, share_session->stream_id);
+
+	/*	gtalk_xfer_prepare_candidates(session);*/
 }
 
 static void
 gtalk_get_request_cb(PurpleUtilFetchUrlData *url_data,
 	gpointer user_data, const gchar *url_text, gsize len,
 		     const gchar *error_message)
-{
-	
+{	
 	purple_debug_info("google_session", "inside gtalk_get_request_cb, url_text : %s", url_text);
 }
 
@@ -1828,7 +1830,8 @@ cb_nice_recv(NiceAgent *agent, guint str
 				purple_xfer_cancel_remote(xfer);
 			}
 		}
-	} else {
+	} else if(purple_xfer_get_type(xfer) == PURPLE_XFER_SEND) {
+		purple_debug_info("google_session", "Inside cb_nice_recv for XFER_SEND..\n");
 		/*TODO: Something to do*/
 	}
 }
@@ -1865,7 +1868,7 @@ void cb_nice_component_state_changed(Nic
 
 	share_session->agent_state = state;
 
-	purple_debug_info("google_session", "__State of NiceAgent Changed...Current State : [%d]%s.Stream ID: %d\n", state, nice_component_state_to_str(state), stream_id);
+	purple_debug_info("google_session", "State of NiceAgent Changed : [%d]%s.Stream ID: %d\n", state, nice_component_state_to_str(state), stream_id);
 
 	if(state == NICE_COMPONENT_STATE_READY) {
 		GSList *remote_candids = nice_agent_get_remote_candidates(agent, stream_id, component_id);
@@ -1895,7 +1898,9 @@ void cb_nice_component_state_changed(Nic
 		purple_debug_info("google_session", "***********\n");
 	}
 	
-	if(state == NICE_COMPONENT_STATE_READY) {
+	if(state == NICE_COMPONENT_STATE_READY && 
+	   purple_xfer_get_type(share_session->xfer) == PURPLE_XFER_RECEIVE) {
+
 	  purple_debug_info("google_session", "READY!\n");
 	  gint send_ret;
 	  JabberStream *js = session->js;
@@ -1912,6 +1917,10 @@ void cb_nice_component_state_changed(Nic
 	  share_session->channel_state = GTALK_XFER_CHANNEL_SENT_HTTP_GET;
 	  purple_debug_info("google_session", "send_ret is %d, Request is : \n%s\n",send_ret, request);	    
 	}
+
+	if( purple_xfer_get_type(share_session->xfer) == PURPLE_XFER_SEND && state == NICE_COMPONENT_STATE_READY) {
+		purple_debug_info("google_session", "STATE_READY for XFER_SEND!");
+	}
 /*	else if(state == NICE_COMPONENT_STATE_CONNECTED && !share_session->pair_selected) {/*
 		GSList *remote_candids = nice_agent_get_remote_candidates(agent, stream_id, component_id);
 		GSList *local_candids = share_session->local_share_candidates; /*TODO: Done for grabbing the relay candidate*/
@@ -2041,27 +2050,9 @@ This will most probably end in successfu
 	NiceAgent *agent = share_session->share_agent;
 	JabberStream *js = session->js;
 
-
-	if(!g_object_get_data(G_OBJECT (agent), "stun->server")) {
-		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);
-	}
-	else
-		purple_debug_info("google_session", "Agent's stun was not NULL.");
-
 //	gloop = g_main_loop_new(NULL, FALSE);
 
 /*Sending relay request to Google's Relay Server..*/
-	if (js->google_relay_host && js->google_relay_token) {
-		purple_debug_info("google_session", "Calling do_relay_request()..\n");
-		jabber_google_do_relay_request(js, session,
-					       jabber_google_relay_response_session_initiate_cb);
-	} else {
-		purple_debug_info("google_session", "FAILED TO Call do_relay_request()..Just the cb\n");
-		jabber_google_relay_response_session_initiate_cb(session, NULL, 0, 0, 0,
-								 NULL, NULL);
-	}	
 
 	// Connect the signals	
 
@@ -2077,9 +2068,9 @@ This will most probably end in successfu
    stream_id = nice_agent_add_stream (agent, 1);
 */
 	
-	nice_agent_attach_recv (share_session->share_agent, share_session->stream_id, 1,
+/*	nice_agent_attach_recv (share_session->share_agent, share_session->stream_id, 1,
 				g_main_context_default(), cb_nice_recv, share_session);
-
+*/
 /*				 TODO: REMOVE ME. Trying g_main_context_default () instead of gloop.*/
 /*
 	nice_agent_attach_recv (agent, stream_id, 1,
@@ -2554,7 +2545,8 @@ google_session_parse_iq(JabberStream *js
 		else
 			google_session_handle_accept(js, session, sess, iq_id);	
 	} else if (!strcmp(type, "info")) {
-		google_session_handle_info(js, session, sess, iq_id);
+		/*"info" type messages are received only for Share Sessions*/
+		gtalk_xfer_handle_info(js, session, sess, iq_id);
 	} else if (!strcmp(type, "reject")) {
 		google_session_handle_reject(js, session, sess);
 	} else if (!strcmp(type, "terminate")) {
diff --git a/libpurple/protocols/jabber/google/google_session.h b/libpurple/protocols/jabber/google/google_session.h
--- a/libpurple/protocols/jabber/google/google_session.h
+++ b/libpurple/protocols/jabber/google/google_session.h
@@ -63,5 +63,4 @@ void gtalk_xfer_send_accept(JabberStream
 void gtalk_xfer_prepare_candidates(GoogleSession *session);
 void gtalk_xfer_send_candidates(GoogleSession *session);
 void gtalk_xfer_send_session_initiate(PurpleXfer *xfer);
-
 #endif /* PURPLE_JABBER_GOOGLE_SESSION_H_ */



More information about the Commits mailing list