/soc/2013/ashmew2/filetransferX: 9f369cb9bda5: Able to send larg...

Ashish Gupta ashmew2 at gmail.com
Sun Sep 8 06:41:38 EDT 2013


Changeset: 9f369cb9bda5d1836e505b56468618e764a2f9b1
Author:	 Ashish Gupta <ashmew2 at gmail.com>
Date:	 2013-09-08 16:11 +0530
Branch:	 filetransferX
URL: https://hg.pidgin.im/soc/2013/ashmew2/filetransferX/rev/9f369cb9bda5

Description:

Able to send large files. Checking md5 passes on both sides now to verify integrity of the files transferred.

diffstat:

 libpurple/protocols/jabber/google/google_session.c |  74 ++++++++++++++++-----
 1 files changed, 55 insertions(+), 19 deletions(-)

diffs (183 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
@@ -451,7 +451,7 @@ gint gtalk_xfer_init_agent(GoogleSession
 	
 	g_signal_connect  (G_OBJECT (share_session->share_agent), "component-state-changed",
 			   G_CALLBACK (cb_nice_component_state_changed), session);
-	
+
 	g_signal_connect (G_OBJECT (share_session->share_agent), "reliable-transport-writable",
 			  G_CALLBACK (cb_nice_component_writable), share_session);
 	
@@ -1837,7 +1837,13 @@ cb_nice_recv(NiceAgent *agent, guint str
 		share_session->channel_state = GTALK_XFER_CHANNEL_HTTP_SENDING;
 		purple_debug_info("google_session", "\nChanged to _SENDING, Bytes remaining: %llu",
 				  purple_xfer_get_bytes_remaining(xfer));
+		share_session->file_to_send = fopen(share_session->xfer->local_filename, "rb");
+		/*TODO: The file_to_send pointer remains open as long as the file hasn't been sent..there seems to be some issue with
+		  fseeking the file from the SEEK_SET always, Trying to acheive desired results with SEEK_CUR"
+		*/
+
 		purple_debug_info("google_session", "Calling component_writable..\n");
+/*TODO: Remove the call to writable..*/
 		cb_nice_component_writable(share_session->share_agent, share_session->stream_id,
 					   1, share_session);
 
@@ -2003,13 +2009,17 @@ void cb_nice_component_state_changed(Nic
 	GoogleXferSessionData *share_session = session_data->share_session;
 
 	share_session->agent_state = state;
-
+	
 	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) {
+		purple_debug_info("google_session", "Not READY_, returning from state_changed..\n");
+		return;
+	}
 
 	if(state == NICE_COMPONENT_STATE_READY) {
 		GSList *remote_candids = nice_agent_get_remote_candidates(agent, stream_id, component_id);
 		GSList *local_candids = nice_agent_get_local_candidates(agent, stream_id, component_id);
-
+		
 		purple_debug_info("google_session", "List of remote candidates : \n********\n");
 
 		while(remote_candids) {
@@ -2032,6 +2042,14 @@ void cb_nice_component_state_changed(Nic
 			local_candids = local_candids->next;
 		}
 		purple_debug_info("google_session", "***********\n");
+		g_signal_stop_emission_by_name(G_OBJECT(share_session->share_agent),"component-state-changed");
+
+/*TODO: Check if another way can be worked out without disconnecting the component-state-changed signal..*/
+
+		purple_debug_info("google_session", "Disconnected the component-state-changed signal..");
+		cb_nice_component_writable(share_session->share_agent, share_session->stream_id,
+					   1, share_session);
+
 	}
 	
 	if(state == NICE_COMPONENT_STATE_READY && 
@@ -2056,7 +2074,8 @@ void cb_nice_component_state_changed(Nic
 
 	if( purple_xfer_get_type(share_session->xfer) == PURPLE_XFER_SEND && state == NICE_COMPONENT_STATE_READY) {
 		char *file_buf = NULL;
-		FILE *file_ptr = fopen(share_session->xfer->local_filename, "rb");
+		/*FILE *file_ptr = fopen(share_session->xfer->local_filename, "rb");*/
+		FILE *file_ptr = share_session->file_to_send;
 
 		purple_debug_info("google_session", "STATE_READY for XFER_SEND! in cb_component_state_changed.");
 		purple_debug_info("google_session", "xfer->local_filename = %s\n",share_session->xfer->local_filename);
@@ -2176,17 +2195,22 @@ void cb_nice_component_writable(NiceAgen
 
 	purple_debug_info("google_session", "__WRITABLE NOW ! (Inside cb_nice_component_writable\n");
 
+	if(share_session->agent_state!=NICE_COMPONENT_STATE_READY) {
+		purple_debug_info("google_session", "returning from _writable as state!=READY..\n");
+		return;
+	}
+
 	if(share_session->channel_state == GTALK_XFER_CHANNEL_HTTP_SENDING) {
-		FILE *file_ptr = fopen(xfer->local_filename, "rb");
+		FILE *file_ptr = share_session->file_to_send;
 		int send_ret, fread_ret;
 		purple_debug_info("google_session", "Entering the FOREVER loop..\n");
-		while(1) {
+		while (1) {
 		  char *file_buf = g_malloc(65536);
 
 		  purple_debug_info("google_session", "Inside writable(), SENDING_STATE!\n");
-		  fseek(file_ptr, purple_xfer_get_bytes_sent(xfer),SEEK_SET);
-		  purple_debug_info("google_session", "fseek completed..\n");
 		  purple_debug_info("google_session", "ftell gives : %ld\n", ftell(file_ptr));
+		  purple_debug_info("google_session", "\nBytes remaining: %llu",
+				    purple_xfer_get_bytes_remaining(xfer));
 		
 		  if(purple_xfer_get_bytes_remaining(xfer) == 0) {
 			  purple_debug_info("google_session", "\nZero bytes remaining!!");
@@ -2195,27 +2219,38 @@ void cb_nice_component_writable(NiceAgen
 					  strlen("\r\n\r\n"), "\r\n\r\n");
 			  return;
 		  }
-		  /*Change the magic number 65530 to something sensible*/
-		  fread_ret = fread(file_buf, 1, 65530, file_ptr);
+		  /*Change the magic number 65530 to something sensible. Max trans now : 32570245*/
+		  fread_ret = fread(file_buf, 1, 65536, file_ptr);
 		  send_ret = nice_agent_send(share_session->share_agent, share_session->stream_id, 1,
-					   fread_ret, file_buf);
+					     strlen(file_buf), file_buf);
 		  
 /*send_ret = nice_agent_send(share_session->share_agent, share_session->stream_id, 1,
   purple_xfer_get_bytes_remaining(xfer), file_ptr);*/
 		  purple_debug_info("google_session", "\n_SENDING state..send_ret is : %d",send_ret);
+		  purple_debug_info("google_session", "\nSize of file_buf : %d\n",strlen(file_buf));
 		  free(file_buf);
 
-		  purple_debug_info("google_session", "\nBytes remaining: %llu",
-				    purple_xfer_get_bytes_remaining(xfer));
-
 		  if(send_ret<0) {
-			  purple_debug_info("google_session", "send_ret is negative..\n");
+			  purple_debug_info("google_session", "send_ret is negative or zero...\n");
 			  break;
 		  }
 		  else if (send_ret>0) {
+			  fseek(file_ptr, send_ret,SEEK_CUR);
+			  purple_debug_info("google_session", "fseek completed..\n");
+			  purple_xfer_update_progress(xfer);
 			  xfer->bytes_sent += send_ret;
 			  xfer->bytes_remaining -= send_ret;
 		  }
+		  else if(send_ret == 0) {
+			  long old_ftell = ftell(file_ptr);
+			  purple_debug_info("google_session", "send_ret is zero..\nClosing and Reopening file..\n");
+			  fclose(file_ptr);
+			  
+			  share_session->file_to_send = fopen(xfer->local_filename, "rb");
+			  file_ptr = share_session->file_to_send;
+			  fseek(file_ptr, old_ftell,SEEK_SET); 
+		  }
+			  
 
 		  
 //TODO??		if (purple_xfer_get_bytes_remaining(xfer) == 0)
@@ -2306,7 +2341,7 @@ void cb_initial_binding(NiceAgent *agent
   purple_debug_info("google_session", "__Initial binding request..\n");
 }
 
-void
+/*void
 gtalk_xfer_prepare_candidates(GoogleSession *session)
 {	
 /*
@@ -2339,7 +2374,7 @@ OUR Response :
 
 This will most probably end in successful candidate exchange.
 	    */
-
+/*
 	GSList *lcands = NULL;
 //	GMainLoop *gloop;
 	GoogleAVSessionData *session_data = (GoogleAVSessionData *)session->session_data;
@@ -2372,7 +2407,7 @@ This will most probably end in successfu
 /*
 	nice_agent_attach_recv (agent, stream_id, 1,
 				g_main_context_default(), cb_nice_recv, NULL);
-*/
+*//*
 	g_signal_connect (G_OBJECT (agent), "initial-binding-request-received",
 			  G_CALLBACK (cb_initial_binding),  session);
 
@@ -2402,9 +2437,10 @@ This will most probably end in successfu
 //	g_object_unref(agent); /*Something here is causing a CRASH on destroying pidgin..Find out what! TODO*/
 
 	/*relay information gathering : */
-	purple_debug_info("google_session", "Returning from prepare_candidates()\n");
+/*	purple_debug_info("google_session", "Returning from prepare_candidates()\n");
 	return;
 }
+*/
 
 void
 gtalk_xfer_start(PurpleXfer *xfer)



More information about the Commits mailing list