/soc/2013/ashmew2/filetransferY: d0f92a47edaf: Added functions f...

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


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

Description:

Added functions for cancelling/rejecting. Cleaned up a bit

diffstat:

 libpurple/protocols/jabber/google/google_session.c |  115 +++++++++++---------
 1 files changed, 65 insertions(+), 50 deletions(-)

diffs (228 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
@@ -133,9 +133,18 @@ google_session_destroy(GoogleSession *se
 		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);
-		
+		/*Xfer section needs fixing...TODO*/
+		purple_debug_info("google_session", "Trying to kill xfer..BEFORE?\n");
+		purple_debug_info("gs_", "status of xfer : %d",purple_xfer_get_status(share_session->xfer) == PURPLE_XFER_STATUS_STARTED);
+
+		if (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);
 	    
@@ -485,6 +494,37 @@ jabber_google_session_get_params(JabberS
 	return new_params;
 }
 
+void
+gtalk_xfer_send_terminate(PurpleXfer *xfer)
+{
+	GoogleSession *session = (GoogleSession *) xfer->data;
+	JabberStream *js = session->js;
+	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);        
+	jabber_iq_send(iq);       	
+}
+
+void
+gtalk_xfer_cancel_xfer(PurpleXfer *xfer)
+{
+	GoogleSession *session = (GoogleSession *)xfer->data;
+	purple_debug_info("gs", "Inside gtalk_xfer_cancel_xfer...\n");
+	
+	if(session->state == TERMINATED)
+		return;
+	
+	gtalk_xfer_send_terminate(xfer);	
+	session->state = TERMINATED;
+	google_session_destroy(session);
+}
+
 gint gtalk_xfer_init_agent(GoogleSession *session)
 {
 	gint stream_id;
@@ -963,13 +1003,15 @@ FT XML:
 			purple_xfer_set_filename(share_session->xfer, xmlnode_get_data_unescaped(filename));
 
 		purple_xfer_set_size(share_session->xfer, filesize);
-		
+		/*Setting up stuff for XFER_RECEIVE*/
 		purple_xfer_set_init_fnc(share_session->xfer, gtalk_xfer_init);
 		purple_xfer_set_request_denied_fnc(share_session->xfer,
 						   gtalk_xfer_request_denied);
+		purple_xfer_set_cancel_recv_fnc(share_session->xfer,
+						gtalk_xfer_cancel_xfer);
 		purple_xfer_set_read_fnc(share_session->xfer, gtalk_xfer_read);
 		purple_xfer_set_end_fnc(share_session->xfer, gtalk_xfer_end);
-
+		
 		share_session->xfer->data = session;
 		share_session->buffer = purple_circ_buffer_new(65536);
 		
@@ -1371,12 +1413,16 @@ google_session_handle_accept(JabberStrea
 static void 
 gtalk_xfer_handle_reject(JabberStream *js, GoogleSession *session, const char *iq_id)
 {	
+	GoogleAVSessionData *session_data = (GoogleAVSessionData *)session->session_data;
+	
 	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");       
+	purple_debug_info("google_session", "The remote user Rejected the Xfer request..\n");
+
+	session->state = TERMINATED;
 	google_session_destroy(session);
 }
 
@@ -1405,8 +1451,10 @@ google_session_handle_terminate(JabberSt
 		return;
 	}
 			
-	if(session_data->share) 			
+	if(session_data->share) {	
+		session->state = TERMINATED;
 		google_session_destroy(session);
+	}
 	else
 		purple_media_end(session_data->media, NULL, NULL);
 }
@@ -1630,31 +1678,7 @@ gtalk_xfer_send_reject(PurpleXfer *xfer)
 	session_node = xmlnode_new_child(iq->node, "session");
 	xmlnode_set_attrib(session_node, "type", "reject");
 	xmlnode_set_attrib(session_node, "id", session->id.id);
-	xmlnode_set_attrib(session_node, "initiator", session->remote_jid);
-	xmlnode_set_namespace(session_node, NS_GOOGLE_SESSION);        
-	jabber_iq_send(iq);       	
-}
-
-void
-gtalk_xfer_send_terminate(PurpleXfer *xfer)
-{
-	GoogleSession *session = (GoogleSession *) xfer->data;
-	JabberStream *js = session->js;
-	JabberIq *iq = jabber_iq_new(js, JABBER_IQ_SET);
-	xmlnode *session_node;
-
-	if(purple_xfer_get_type(xfer) != PURPLE_XFER_RECEIVE)
-		return;
-
-	/*TODO: Remove me..
-<iq to="doondoon1234 at gmail.com/853FDFA2" type="set" id="455" from="ashmew2 at gmail.com/Talk.v104D0FD2998"><session type="terminate" id="purpled9582498" initiator="doondoon1234 at gmail.com/853FDFA2" xmlns="http://www.google.com/session"/></iq>
-	*/
-
-	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->remote_jid);
+	xmlnode_set_attrib(session_node, "initiator", session->id.initiator);
 	xmlnode_set_namespace(session_node, NS_GOOGLE_SESSION);        
 	jabber_iq_send(iq);       	
 }
@@ -1680,7 +1704,7 @@ gtalk_xfer_end(PurpleXfer *xfer)
 		session_node = xmlnode_new_child(iq->node, "session");
 		xmlnode_set_attrib(session_node, "type", "info");
 		xmlnode_set_attrib(session_node, "id", session->id.id);
-		xmlnode_set_attrib(session_node, "initiator", session->remote_jid);
+		xmlnode_set_attrib(session_node, "initiator", session->id.initiator);
 		xmlnode_set_namespace(session_node, NS_GOOGLE_SESSION);
 	
 		complete_node = xmlnode_new_child(session_node, "complete");
@@ -1814,9 +1838,9 @@ cb_nice_recv(NiceAgent *agent, guint str
 			/* write data to transfer */
 			curlen+=len;
 			
-			purple_debug_info("google-session",
+/*			purple_debug_info("google-session",
 					  "got %d bytes to write to transfer, CURLEN: %d\n", len, curlen);
-			
+*/			
 			if (len <= purple_xfer_get_bytes_remaining(xfer)) {
 				purple_circ_buffer_append(share_session->buffer, curr, len);
 				purple_xfer_prpl_ready(xfer);
@@ -2162,14 +2186,16 @@ gtalk_xfer_send(PurpleConnection *gc, co
 
 	  xfer = purple_xfer_new(purple_connection_get_account(gc), PURPLE_XFER_SEND, 
 				 session->remote_jid);
-
+	  /*Setting up Stuff for XFER_SEND*/
 	  purple_xfer_set_init_fnc(xfer, gtalk_xfer_init);
 	  purple_xfer_set_request_denied_fnc(xfer,
 					     gtalk_xfer_request_denied);
+	  purple_xfer_set_cancel_send_fnc(xfer, gtalk_xfer_cancel_xfer);
 	  purple_xfer_set_write_fnc(xfer, gtalk_xfer_write);
 
 	  xfer->data = session;
 	  share_session->xfer = xfer;
+	  purple_debug_info("gs....","xfer status?????->>> %d",purple_xfer_get_status(xfer));
 	  purple_xfer_request(xfer);
   }
 
@@ -2359,7 +2385,7 @@ void gtalk_xfer_send_info(JabberStream *
 	session_node = xmlnode_new_child(iq->node, "session");
 	xmlnode_set_attrib(session_node, "type", "info");
 	xmlnode_set_attrib(session_node, "id", xmlnode_get_attrib(sess, "id"));
-	xmlnode_set_attrib(session_node, "initiator", session->remote_jid);
+	xmlnode_set_attrib(session_node, "initiator", session->id.initiator);
 	xmlnode_set_namespace(session_node, NS_GOOGLE_SESSION);
 	
 	channel_node = xmlnode_new_child(session_node, "channel");
@@ -2441,7 +2467,7 @@ void gtalk_xfer_send_accept(JabberStream
 	
 	xmlnode_set_attrib(session_node, "type", "accept");
 	xmlnode_set_attrib(session_node, "id", session->id.id);
-	xmlnode_set_attrib(session_node, "initiator", session->remote_jid);
+	xmlnode_set_attrib(session_node, "initiator", session->id.initiator);
 	xmlnode_set_namespace(session_node, NS_GOOGLE_SESSION);
 	
 	xmlnode_new_child(description_node, "manifest");
@@ -2475,7 +2501,7 @@ gtalk_xfer_send_transport_accept(JabberS
 	
 	xmlnode_set_attrib(session_node, "type", "transport-accept");
 	xmlnode_set_attrib(session_node, "id", session->id.id);
-	xmlnode_set_attrib(session_node, "initiator", session->remote_jid);
+	xmlnode_set_attrib(session_node, "initiator", session->id.initiator);
 	xmlnode_set_namespace(session_node, NS_GOOGLE_SESSION);
 
 	xmlnode_set_namespace(transport_node, NS_GOOGLE_TRANSPORT_P2P);
@@ -2484,17 +2510,6 @@ gtalk_xfer_send_transport_accept(JabberS
 }
 
 static void
-google_xfer_send(JabberStream *js, GoogleSession *session)
-{
-	PurpleXfer *xfer = purple_xfer_new(purple_connection_get_account(js->gc), PURPLE_XFER_SEND, session->remote_jid);
-	xfer->data = session;
-	purple_debug_info("google_session", "inside google_xfer_send\n");
-
-	purple_xfer_set_init_fnc( xfer, gtalk_xfer_init );
-	purple_xfer_set_start_fnc(xfer, gtalk_xfer_start);
-}
-
-static void
 google_session_parse_iq(JabberStream *js, GoogleSession *session, xmlnode *sess, const char *iq_id)
 {
 	const char *type = xmlnode_get_attrib(sess, "type");



More information about the Commits mailing list