/soc/2013/ashmew2/filetransferY: e6606478f27e: Fixed Crash : Can...

Ashish Gupta ashmew2 at gmail.com
Sun Dec 22 04:25:22 EST 2013


Changeset: e6606478f27eeabebbfcca7f3de6eeb3116bdca5
Author:	 Ashish Gupta <ashmew2 at gmail.com>
Date:	 2013-12-22 11:42 +0530
Branch:	 filetransferX
URL: https://hg.pidgin.im/soc/2013/ashmew2/filetransferY/rev/e6606478f27e

Description:

Fixed Crash : Cancel while selecting a file

diffstat:

 libpurple/ft.c                                     |    4 +-
 libpurple/protocols/jabber/google/google_session.c |  111 ++++++++++++++-------
 libpurple/protocols/jabber/google/google_session.h |    2 +-
 3 files changed, 77 insertions(+), 40 deletions(-)

diffs (297 lines):

diff --git a/libpurple/ft.c b/libpurple/ft.c
--- a/libpurple/ft.c
+++ b/libpurple/ft.c
@@ -1382,8 +1382,8 @@ purple_xfer_prpl_ready(PurpleXfer *xfer)
 		purple_debug_misc("xfer", "prpl is ready on ft %p, waiting for UI\n", xfer);
 		return;
 	}
-
-	purple_debug_misc("xfer", "Prpl (and UI) ready on ft %p, so proceeding\n", xfer);
+	/*TODO: Commented out as this gives many messages while transferring a file from Gtalk to pidgin*/
+	//purple_debug_misc("xfer", "Prpl (and UI) ready on ft %p, so proceeding\n", xfer);
 
 	priv->ready = PURPLE_XFER_READY_NONE;
 
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
@@ -122,6 +122,11 @@ google_session_destroy(GoogleSession *se
 		(GoogleAVSessionData *) session->session_data;
 	JabberStream *js = session->js;
 	
+	purple_debug_info("google_session", "Inside google_session_destroy..\n\n");
+
+	if(!session_data)
+		purple_debug_info("google_session","Session_data is NULL..\n");
+
 	if(session_data->share) {
 		GoogleXferSessionData *share_session = session_data->share_session;
 		GSList *temp = NULL;
@@ -133,21 +138,24 @@ google_session_destroy(GoogleSession *se
 		purple_debug_info("gs_", "status of xfer : %d",purple_xfer_get_status(share_session->xfer) == PURPLE_XFER_STATUS_STARTED);
 		TODO: Add various status changes when cancelling Xfers so that the following section can make use of it.
 		*/
+
 		if(share_session->xfer)	{
-
 			if(purple_xfer_get_status(share_session->xfer) == PURPLE_XFER_STATUS_CANCEL_REMOTE)
 				purple_xfer_cancel_remote(share_session->xfer);
-			else if (purple_xfer_get_status(share_session->xfer) != PURPLE_XFER_STATUS_CANCEL_LOCAL &&				 
+			else if (purple_xfer_get_status(share_session->xfer) != PURPLE_XFER_STATUS_CANCEL_LOCAL &&
 				 purple_xfer_get_status(share_session->xfer) != PURPLE_XFER_STATUS_DONE) {				
 				purple_debug_info("google_session", "Calling xfer_cancel_local\n");
 				purple_xfer_cancel_local(share_session->xfer);
-			}
+			}			
 		}
+
 		purple_debug_info("google_session", "Trying to kill xfer..AFTERWARDS?\n");
 
 		if(share_session->file_to_send)
 			fclose(share_session->file_to_send);
-	    
+
+		purple_debug_info("google_session", "Phase -3\n");	    
+
 		share_session->xfer = NULL;
 		g_free(share_session->filename);
 		g_free(share_session->preview_url);
@@ -155,6 +163,7 @@ google_session_destroy(GoogleSession *se
 		g_free(share_session->file_buf);
 		g_free(share_session->channel_name);
 
+		purple_debug_info("google_session", "Phase -2\n");
 		if(share_session->share_agent) {
 			g_signal_handlers_disconnect_by_func(G_OBJECT(share_session->share_agent),
 							     G_CALLBACK (cb_candidate_gathering_done), session);
@@ -187,6 +196,7 @@ google_session_destroy(GoogleSession *se
 		g_free(share_session);		
 		g_free(temp);		
 	}
+	purple_debug_info("google_session", "Phase -1\n");
 
 	js->google_share_sessions = g_list_remove(js->google_share_sessions,session);
 
@@ -205,6 +215,7 @@ google_session_destroy(GoogleSession *se
 
 	g_free(session->session_data);
 	g_free(session);
+	purple_debug_info("google_session", "Phase END of function\n");
 }
 
 static xmlnode *
@@ -502,29 +513,43 @@ gtalk_xfer_send_terminate(PurpleXfer *xf
 	JabberIq *iq = jabber_iq_new(js, JABBER_IQ_SET);
 	xmlnode *session_node;
 
-	xmlnode_set_attrib(iq->node, "to", session->remote_jid);	
-	session_node = xmlnode_new_child(iq->node, "session");
-	xmlnode_set_attrib(session_node, "type", "terminate");
-	xmlnode_set_attrib(session_node, "id", session->id.id);
-	xmlnode_set_attrib(session_node, "initiator", session->id.initiator);
-	xmlnode_set_namespace(session_node, NS_GOOGLE_SESSION);        
+	purple_debug_info("google_session", "Inside gtalk_xfer_send_terminate, xfer_status : %d\n",
+			  purple_xfer_get_status(xfer));
 
-	jabber_iq_set_callback(iq, google_session_destroy, session);
-	jabber_iq_send(iq);       	
+	if(session->state < IN_PROGRESS)		
+		google_session_destroy(session);
+	else {
+		xmlnode_set_attrib(iq->node, "to", session->remote_jid);	
+		session_node = xmlnode_new_child(iq->node, "session");
+		xmlnode_set_attrib(session_node, "type", "terminate");
+		xmlnode_set_attrib(session_node, "id", session->id.id);
+		xmlnode_set_attrib(session_node, "initiator", session->id.initiator);
+		xmlnode_set_namespace(session_node, NS_GOOGLE_SESSION);        
+		purple_debug_info("google_session", "Sending google_s_dest as callback..Sending IQ\n");
+		jabber_iq_set_callback(iq, google_session_destroy, session);
+		jabber_iq_send(iq);       	
+	}
 }
 
 void
 gtalk_xfer_cancel_xfer(PurpleXfer *xfer)
 {
 	GoogleSession *session = (GoogleSession *)xfer->data;
+	GoogleAVSessionData *session_data = session->session_data;
+	GoogleXferSessionData *share_session = session_data->share_session;
+
 	purple_debug_info("gs", "Inside gtalk_xfer_cancel_xfer...\n");
 	
 	if(session->state == TERMINATED)
 		return;
-	
-	gtalk_xfer_send_terminate(xfer);	
-	session->state = TERMINATED;
-	purple_debug_info("google_session", "Calling the google_session_destroy from gtalk_xfer_cancel_xfer() \n");
+//TODO: Possible shift the = TERMINATED to google_session_destroy exclusively and remove from everywhere else.
+//High cohesion is good.
+
+//	session->state = TERMINATED;
+
+	gtalk_xfer_send_terminate(xfer);
+
+//	purple_debug_info("google_session", "Calling the google_session_destroy from gtalk_xfer_cancel_xfer() \n");
 //	google_session_destroy(session);
 }
 
@@ -618,8 +643,6 @@ jabber_google_relay_response_session_ini
 				nice_agent_set_relay_info(agent, share_session->stream_id, 1, relay_ip, relay_ssltcp,
 							  relay_username, relay_password, NICE_RELAY_TYPE_TURN_TLS);
 		}
-
-		purple_debug_info("google_session", "Calling xfer_send_candidates()\n");
 		
 		session->relay_processing = FALSE;
 
@@ -627,7 +650,7 @@ jabber_google_relay_response_session_ini
 		  purple_debug_info("google_session","Detected session_should_die as 1.\n");
 		  google_session_destroy(session);
 		  return;
-		}		
+		}
 		return;
 	}
 	/*The procedure for Share Session ends here. What follows is the process needed for Media sessions*/
@@ -1383,15 +1406,16 @@ google_session_handle_terminate(JabberSt
 	xmlnode_set_attrib(result->node, "to", session->remote_jid);
 	jabber_iq_send(result);
 	purple_debug_info("google_session","Setting session_should_die to 1 \n");
-	session->session_should_die = 1; /*TODO: what to do?*/
-	
+	session->session_should_die = 1; /*TODO: what to do?*/	       
+	session_data->share_session->xfer->status = PURPLE_XFER_STATUS_CANCEL_REMOTE;
+
 	if(session->relay_processing) {
 		purple_debug_info("google_session","Relay is processing..\n");
 		return;
 	}
 			
 	if(session_data->share) {	/*TODO: Right now, we are only using local_cancel(xfer), need to use
-					  remote_cancel(xfer) as well*/
+					  remote_cancel(xfer) as well, Possibly fixed, but not everywhere.*/
 		purple_debug_info("google_session","Setting session_state to TERMINATED..\n");
 		session->state = TERMINATED;
 		google_session_destroy(session);
@@ -1673,7 +1697,7 @@ gtalk_xfer_read(guchar **out_buffer, Pur
 
 void
 cb_nice_recv(NiceAgent *agent, guint stream_id, guint component_id,
-    guint len, gchar *buf, gpointer data)
+	     guint len, gchar *buf, gpointer data)
 {
 	GoogleXferSessionData *share_session = (GoogleXferSessionData *)data;
 	PurpleXfer *xfer = share_session->xfer;
@@ -1774,14 +1798,21 @@ cb_nice_recv(NiceAgent *agent, guint str
 			} else {
 				purple_debug_error("google-share",
 						   "trying to write past end of file\n");
-				purple_xfer_cancel_remote(xfer);				
+
+				if(purple_xfer_get_status(xfer) != PURPLE_XFER_STATUS_CANCEL_REMOTE && 
+				   purple_xfer_get_status(xfer) != PURPLE_XFER_STATUS_CANCEL_LOCAL) {
+					purple_debug_info("google_session", "Calling purple_xfer_cancel_remote from cb_nice_recv()\n");
+					purple_xfer_cancel_remote(xfer);									
+				}
 			}
 		}
 	}
+	/*TODO: Possibly uncomment the else below, but that results in spammy behaviour if xfer cancelled*/
+	/*
 	else {
-		purple_debug_info("google_session", "XFER_TYPE NOT KNOWN!");
-		
-	}
+		purple_debug_info("google_session", "XFER_TYPE NOT KNOWN!");		
+		}
+	*/
 }
 
 char *nice_component_state_to_str(guint state)
@@ -1829,7 +1860,7 @@ void cb_nice_component_state_changed(Nic
 	}
 	
 	selected_pair = nice_agent_get_selected_pair(share_session->share_agent, share_session->stream_id, 1,
-				     &lcand, &rcand);
+						     &lcand, &rcand);
 	if(selected_pair) {
 		purple_debug_info("google_session", "Selected Candidates : \n**********\n");
 		nice_address_to_string(&lcand->addr, temp);
@@ -2072,17 +2103,18 @@ gtalk_xfer_send(PurpleConnection *gc, co
   JabberStream *js = purple_connection_get_protocol_data(gc);
 
   purple_debug_info("google_session", "INSIDE GTALK_XFER_SEND\n");
-
+  
   if (file) {
-	  purple_debug_info("google_session", "file is non NULL.File : %s\n", file);
+	  purple_debug_info("google_session", "file is not NULL, %s\n", file);	  
 	  purple_xfer_request_accepted(xfer, file);
   }
   else {
-	  purple_debug_info("google_session", "File is NULL!\n");
 	  GoogleSession *session = gtalk_xfer_new_session(js, who);
 	  GoogleAVSessionData *session_data = session->session_data;
 	  GoogleXferSessionData *share_session = session_data->share_session;
-	  
+	  session->state = SENT_INITIATE; /*TODO: Or UNINIT ?*/
+
+	  purple_debug_info("google_session", "File is NULL!\n");  
 	  session_data->share = TRUE;
 
 	  xfer = purple_xfer_new(purple_connection_get_account(gc), PURPLE_XFER_SEND, 
@@ -2098,7 +2130,9 @@ gtalk_xfer_send(PurpleConnection *gc, co
 
 	  xfer->data = session;
 	  share_session->xfer = xfer;
-	  purple_debug_info("gs....","xfer status?????->>> %d",purple_xfer_get_status(xfer));
+	  purple_debug_info("google_session","xfer status :  %d\n",purple_xfer_get_status(xfer));
+	  
+	  xfer->status = PURPLE_XFER_STATUS_NOT_STARTED;
 	  purple_xfer_request(xfer);
   }
 
@@ -2115,7 +2149,7 @@ gtalk_get_temporary_url(void)
 	char *num = "0123456789";
 	srandom(time(NULL));
 	z++;
-
+	/*TODO: Check whether after many increments, will z force 26-z or 10-z to be negative?*/
 	strcpy(temporary_url, "/temporary/");
 	for(;i<43;i++) {
 		int j=random()%2;
@@ -2323,15 +2357,18 @@ void
 gtalk_xfer_accept_cb(JabberStream *js, const gchar *from, JabberIqType type, 
 		     const gchar *id, xmlnode *sess, gpointer data)
 {
+	GoogleSession *session = (GoogleSession *) data;
+	GoogleAVSessionData *session_data = (GoogleAVSessionData *)session->session_data;
+	GoogleXferSessionData *share_session = session_data->share_session;
+		
 	if (type != JABBER_IQ_RESULT) {
 		purple_debug_info("google_session", "Our Accept Request was REJECTED by Gtalk?. Should Abort.\n");
+		share_session->xfer->status = PURPLE_XFER_STATUS_CANCEL_REMOTE;
+		google_session_destroy(share_session->xfer);
 		/*TODO: Make the session terminate gracefully here*/
 	}
 	else {
 		/*Send a channel*/
-		GoogleSession *session = (GoogleSession *) data;
-		GoogleAVSessionData *session_data = (GoogleAVSessionData *)session->session_data;
-		GoogleXferSessionData *share_session = session_data->share_session;
 		
 		gchar *me = g_strdup_printf("%s@%s/%s",
 					    session->js->user->node,
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
@@ -32,7 +32,7 @@ typedef enum {
 	UNINIT,
 	SENT_INITIATE,
 	RECEIVED_INITIATE,
-	IN_PRORESS,
+	IN_PROGRESS,
 	TERMINATED
 } GoogleSessionState;
 



More information about the Commits mailing list