/soc/2013/ashmew2/filetransferY: 05302f8b73cd: Fixed crashes. Ad...

Ashish Gupta ashmew2 at gmail.com
Sun Sep 15 19:47:03 EDT 2013


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

Description:

Fixed crashes. Added functions. Removed functions.

diffstat:

 libpurple/protocols/jabber/google/google_session.c |  345 +++++++++++++-------
 libpurple/protocols/jabber/google/google_session.h |    4 +-
 libpurple/protocols/jabber/google/relay.c          |    3 +-
 3 files changed, 221 insertions(+), 131 deletions(-)

diffs (truncated from 718 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
@@ -17,7 +17,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
  */
-#include<stdlib.h>
+
 #include "internal.h"
 #include "debug.h"
 #include "google_session.h"
@@ -52,15 +52,13 @@ typedef struct {
 	gchar *preview_url;
 	gchar *source_url;
 	PurpleXfer *xfer;
-	/*Needs to have a manifest Entry for Folder Sharing*/
-	NiceAgent *share_agent; /*TODO : Assess the usefulness of share_agent and stream_id*/
+	NiceAgent *share_agent; /*Needs to have a manifest Entry for Folder Sharing: TODO*/
 	gchar *channel_name;
 	NiceComponentState agent_state;
-	PurpleCircBuffer *buffer; /*Need to add something for HTTP_STATUS too */
+	PurpleCircBuffer *buffer; 
 	GoogleXferChannelState channel_state;
 	gint stream_id;
 	gboolean candidates_gathered;
-	gboolean pair_selected;
 	
 	gboolean file_opened;               /* Stuff for using file buffer for sending Gtalk Files.. */ 
 	FILE *file_to_send;
@@ -70,31 +68,18 @@ typedef struct {
 	GSList *remote_share_candidates; /* lists of NiceCandidates */
 	GSList *local_share_candidates;	
 } GoogleXferSessionData; 
-/*Thanks malu!*/
-
-typedef struct {
-	NiceAgent *agent;
-	guint stream_id;
-} TempStruct;
 
 typedef struct {
 	PurpleMedia *media;
 	gboolean video;
-	gboolean share;
+	gboolean share;                 /*for indicating whether it's a fileXfer session*/
 	GoogleXferSessionData* share_session;
 	GList *remote_audio_candidates; /* list of PurpleMediaCandidate */
 	GList *remote_video_candidates; /* list of PurpleMediaCandidate */
 	gboolean added_streams;		/* this indicates if the streams have been
-	 							   to media (ie. after getting relay credentials */
+					   to media (ie. after getting relay credentials */
 } GoogleAVSessionData;
 
-
-/*TODO: When cleaning up typedef struct {
-
-  } GoogleShareManifest;
-*/
-
-
 void cb_candidate_gathering_done(NiceAgent *agent, guint stream_id, gpointer user_data);
 void cb_nice_component_state_changed(NiceAgent *agent,guint stream_id, guint component_id,
 				     guint state, gpointer user_data);
@@ -110,7 +95,6 @@ gtalk_xfer_handle_info(JabberStream  *js
 NiceCandidate * nice_candidate_from_xml(const xmlnode *candidate, guint stream_id);
 gchar * http_read_line(gchar *buffer, guint len);
 char* gtalk_get_temporary_url(void);
-PurpleXfer *gtalk_xfer_new(PurpleConnection *gc, const char *who);
 GoogleSession *gtalk_xfer_new_session(JabberStream *js, char *who);
 char *nice_component_state_to_str(guint state);
 void gtalk_xfer_get_next_block(GoogleXferSessionData *share_session);
@@ -136,10 +120,74 @@ google_session_destroy(GoogleSession *se
 {
 	GoogleAVSessionData *session_data =
 		(GoogleAVSessionData *) session->session_data;
+	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", "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);
+		
+		if(share_session->file_to_send)
+			fclose(share_session->file_to_send);
+	    
+		share_session->xfer = NULL;
+		g_free(share_session->filename);
+		g_free(share_session->preview_url);
+		g_free(share_session->source_url);
+		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);
+		
+			g_signal_handlers_disconnect_by_func(G_OBJECT(share_session->share_agent),
+							     G_CALLBACK (cb_new_selected_pair), NULL);
+			
+			g_signal_handlers_disconnect_by_func(G_OBJECT(share_session->share_agent),
+							     G_CALLBACK (cb_nice_component_state_changed),
+							     session);
+		
+			g_signal_handlers_disconnect_by_func(G_OBJECT(share_session->share_agent),
+							     G_CALLBACK (cb_nice_component_writable), 
+							     share_session);      
+			g_object_unref(share_session->share_agent);
+		}
+
+		purple_circ_buffer_destroy(share_session->buffer);
+		
+		for (temp = share_session->remote_share_candidates; temp; temp =
+			     g_list_delete_link(temp, temp)) {
+			nice_candidate_free(temp->data);
+		}
+		
+		for (temp = share_session->local_share_candidates; temp; temp =
+			     g_list_delete_link(temp, temp)) {
+			nice_candidate_free(temp->data);
+		}
+
+		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);
+
 	g_free(session->id.id);
 	g_free(session->id.initiator);
 	g_free(session->remote_jid);
-
+		      
 	if (session_data->remote_audio_candidates)
 		purple_media_candidate_list_free(session_data->remote_audio_candidates);
 
@@ -148,9 +196,10 @@ google_session_destroy(GoogleSession *se
 
 	if (session->description)
 		xmlnode_free(session->description);
-/*TODO : Since we have made a new GList in _JabberStream, we should probably delete the GoogleSession from it now*/
+
 	g_free(session->session_data);
 	g_free(session);
+	purple_debug_info("google_session", "Reached end of function..\n");
 }
 
 static xmlnode *
@@ -475,7 +524,7 @@ gint gtalk_xfer_init_agent(GoogleSession
 
 	g_signal_connect (G_OBJECT (share_session->share_agent), "reliable-transport-writable",
 			  G_CALLBACK (cb_nice_component_writable), share_session);
-	
+
 	share_session->share_agent = agent;
 	share_session->stream_id = stream_id;
 	return stream_id;
@@ -497,7 +546,9 @@ jabber_google_relay_response_session_ini
 	NiceCandidate *relay_candidate_ssltcp;
 	gint stream_id = share_session->stream_id;
 	NiceAgent *agent = share_session->share_agent;
-
+	
+	purple_debug_info("google_session", "Inside jabber_google_relay_response_initiate_cb!\n");
+		
 	if(session_data->share) {
 		if(!agent) {
 /*			if(purple_xfer_get_type(share_session->xfer) == PURPLE_XFER_RECEIVE)
@@ -598,8 +649,15 @@ jabber_google_relay_response_session_ini
 		else
 			purple_debug_info("google_session","Setting Relay on Niceagent Succeeded..\n");
 */
-		purple_debug_info("google_session", "Calling xfer_send_canddiates()\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);
 		return;
 	}
@@ -755,7 +813,8 @@ jabber_google_relay_response_session_han
 
 	for (codec_element = xmlnode_get_child(session->description, "payload-type");
 	     codec_element; codec_element = codec_element->next) {
-		const char *id, *encoding_name,  *clock_rate;
+		const char *id, *encoding_name,  *clock_rate,
+				*width, *height, *framerate;
 		gboolean video;
 		if (codec_element->name &&
 				strcmp(codec_element->name, "payload-type"))
@@ -771,10 +830,10 @@ jabber_google_relay_response_session_han
 					codec_element, "clockrate");
 			video = FALSE;
 		} else {
-			/*width = xmlnode_get_attrib(codec_element, "width");
+			width = xmlnode_get_attrib(codec_element, "width");
 			height = xmlnode_get_attrib(codec_element, "height");
 			framerate = xmlnode_get_attrib(
-					codec_element, "framerate");*/
+					codec_element, "framerate");
 			clock_rate = "90000";
 			video = TRUE;
 		}
@@ -951,8 +1010,8 @@ FT XML:
 (23:33:01) jabber: Recv (ssl)(238): <iq to="doondoon1234 at gmail.com/B1D48535" type="set" id="152" from="ashmew2 at gmail.com/Talk.v104536A73D2"><session type="terminate" id="1800989809" initiator="ashmew2 at gmail.com/Talk.v104536A73D2" xmlns="http://www.google.com/session"/></iq>
 		************************************/
 		/*Add the GoogleSession *session to the GList*/
-		js->google_share_sessions = g_list_prepend(js->google_share_sessions, session);
-		purple_debug_info("google_session", "We have received a file request.\n");
+
+		purple_debug_info("google_session", "We have received a file request : XFER_RECEIVE.\n");
 		
 		share_session->xfer = purple_xfer_new(purple_connection_get_account(js->gc), PURPLE_XFER_RECEIVE,
 						     session->remote_jid);
@@ -1002,7 +1061,6 @@ FT XML:
 		  jabber_iq_send(set_iq);
 		  purple_debug_info("google_session", "\nSent set_iq\n");
 		*/
-		/*TODO : Fix name for ResponseIq */
 		
 		result = jabber_iq_new(js,JABBER_IQ_RESULT);
 		xmlnode_set_attrib(result->node, "to", session->remote_jid);
@@ -1022,19 +1080,7 @@ FT XML:
 		/*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);
-		/**//*
-
-		ResponseIq2 = jabber_iq_new(js,JABBER_IQ_SET);
-		xmlnode_set_attrib(ResponseIq2->node, "to", session->remote_jid);
-		jabber_iq_set_id(ResponseIq2, xmlnode_get_attrib(sess, "id"));
-		jabber_iq_send(ResponseIq2);
-		//This should have Jingle session-accept according to XEP 0234
-
-		
-		//		purple_debug_info("google_session",x "Sent Both ResponseIq. Now Trying to send rest of the XML stuff.");
-		//		responsetxt = xmlnode_to_str(sess,&responsetxtlen);
-		//purple_debug_info("google_session", "\nresponsetxt : %s with len : %d\n\n",responsetxt,responsetxtlen);
-		*/				
+
 		return TRUE;
 	}
 	return TRUE;	
@@ -1045,6 +1091,7 @@ gtalk_xfer_handle_info(JabberStream  *js
 {
 	JabberIq *iq;
 	xmlnode *channel = xmlnode_get_child(sess, "channel");
+	xmlnode *complete = xmlnode_get_child(sess, "complete");
 	GoogleAVSessionData *session_data = (GoogleAVSessionData *)session->session_data;
 	GoogleXferSessionData *share_session = session_data->share_session;	
 	gchar *me = g_strdup_printf("%s@%s/%s",
@@ -1053,7 +1100,20 @@ gtalk_xfer_handle_info(JabberStream  *js
 				    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) {
+		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);
+		
+		google_session_destroy(session);
+		return;
+	}
 
 	if(channel) {
 
@@ -1061,7 +1121,7 @@ gtalk_xfer_handle_info(JabberStream  *js
 		/*TODO: Make sure the NiceAgent exists here?*/
 		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);
@@ -1324,10 +1384,9 @@ google_session_handle_transport_info(Jab
 	GoogleXferSessionData *share_session = session_data->share_session;



More information about the Commits mailing list