/soc/2013/ashmew2/filetransferX: fcc0d27fb4b4: Trying to break 6...

Ashish Gupta ashmew2 at gmail.com
Sun Sep 8 04:46:53 EDT 2013


Changeset: fcc0d27fb4b4cc4f481761810213afb868ebd37b
Author:	 Ashish Gupta <ashmew2 at gmail.com>
Date:	 2013-09-08 14:15 +0530
Branch:	 filetransferX
URL: https://hg.pidgin.im/soc/2013/ashmew2/filetransferX/rev/fcc0d27fb4b4

Description:

Trying to break 64K limit

diffstat:

 libpurple/protocols/jabber/google/google_session.c |  109 +++++++++++++-------
 libpurple/protocols/jabber/google/google_session.h |    2 +-
 2 files changed, 72 insertions(+), 39 deletions(-)

diffs (196 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
@@ -41,7 +41,9 @@ typedef enum {
 	GTALK_XFER_CHANNEL_HTTP_SENDING,
 	GTALK_XFER_CHANNEL_HTTP_RECEIVING,
 	GTALK_XFER_CHANNEL_HTTP_TRANSFERRING,
-	GTALK_XFER_CHANNEL_PARSED_HTTP_RESPONSE_HEADER	
+	GTALK_XFER_CHANNEL_HTTP_SENDING_COMPLETE,
+	GTALK_XFER_CHANNEL_HTTP_RECEIVING_COMPLETE,
+	GTALK_XFER_CHANNEL_PARSED_HTTP_RESPONSE_HEADER
 } GoogleXferChannelState;
 
 typedef struct {
@@ -1939,6 +1941,7 @@ cb_nice_recv(NiceAgent *agent, guint str
 				
 				share_session->channel_state =
 					GTALK_XFER_CHANNEL_PARSED_HTTP_RESPONSE_HEADER;
+				purple_debug_info("google_session", "Calling purple_xfer_start\n");
 				purple_xfer_start(xfer, -1, NULL, 0);
 			}
 			/* otherwise the remaining headers would come in the next package
@@ -2053,10 +2056,10 @@ void cb_nice_component_state_changed(Nic
 
 		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);
-		if(share_session->channel_state == GTALK_XFER_CHANNEL_HTTP_OK_SENT) {
+		/*		if(share_session->channel_state == GTALK_XFER_CHANNEL_HTTP_OK_SENT) {
 			cb_nice_component_writable(share_session->share_agent, share_session->stream_id, 1,
 				share_session);  
-
+		*/
 /*TODO: Should this code go to the cb_nice_component_writable?*/
 /*
 			if(file_ptr)
@@ -2156,9 +2159,9 @@ void cb_nice_component_state_changed(Nic
 		}
 		purple_debug_info("google_session", "***********\n");
 */
-	}
 }
 
+
 /*TODO: Add more stuff related to state changes here*/
 
 void cb_nice_component_writable(NiceAgent *agent, guint stream_id, guint component_id,
@@ -2169,44 +2172,50 @@ void cb_nice_component_writable(NiceAgen
 
 	purple_debug_info("google_session", "__WRITABLE NOW ! (Inside cb_nice_component_writable\n");
 
-	if(share_session)
-		purple_debug_info("gogo", "NON NULL SESSION!\n");
-	else
-		purple_debug_info("goog", "NULL SESSION\n");
-
 	if(share_session->channel_state == GTALK_XFER_CHANNEL_HTTP_SENDING) {
 		FILE *file_ptr = fopen(xfer->local_filename, "rb");
 		int send_ret, fread_ret;
-		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", "ftell gives : %ld\n", ftell(file_ptr));
+		purple_debug_info("google_session", "Entering the FOREVER loop..\n");
+		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", "ftell gives : %ld\n", ftell(file_ptr));
 		
-		if(purple_xfer_get_bytes_remaining(xfer) == 0) {
-			purple_debug_info("google_session", "\nZero bytes remaining!!");
-			nice_agent_send(share_session->share_agent, share_session->stream_id, 1,
-					strlen("\r\n\r\n"), "\r\n\r\n");
-			return;
-		}
-
-		fread_ret = fread(file_buf, 1, 65530, file_ptr);
-		send_ret = nice_agent_send(share_session->share_agent, share_session->stream_id, 1,
+		  if(purple_xfer_get_bytes_remaining(xfer) == 0) {
+			  purple_debug_info("google_session", "\nZero bytes remaining!!");
+/*Set up something here to check if CRLF CRLF is properly sent or not, otherwise wait for writable signal again and resend:TODO*/
+			  nice_agent_send(share_session->share_agent, share_session->stream_id, 1,
+					  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);
+		  send_ret = nice_agent_send(share_session->share_agent, share_session->stream_id, 1,
 					   fread_ret, 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);
-		if(send_ret>0) {
-			xfer->bytes_sent += send_ret;
-			xfer->bytes_remaining -= send_ret;
-		}
-		purple_debug_info("google_session", "\nBytes remaining: %llu",
-				  purple_xfer_get_bytes_remaining(xfer));
-		free(file_buf);
+		  purple_debug_info("google_session", "\n_SENDING state..send_ret is : %d",send_ret);
+		  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");
+			  break;
+		  }
+		  else if (send_ret>0) {
+			  xfer->bytes_sent += send_ret;
+			  xfer->bytes_remaining -= send_ret;
+		  }
+
+		  
 //TODO??		if (purple_xfer_get_bytes_remaining(xfer) == 0)
 //			exit(0);
-
+		}
                 //TODO: Remove redundant part
 		/*if(share_session->file_to_send)
 			{
@@ -2231,10 +2240,11 @@ void cb_nice_component_writable(NiceAgen
 				}*/
 	}
 
-	if(share_session->channel_state == GTALK_XFER_CHANNEL_HTTP_OK_SENT)
+	/*	if(share_session->channel_state == GTALK_XFER_CHANNEL_HTTP_OK_SENT)
 		share_session->channel_state = GTALK_XFER_CHANNEL_HTTP_TRANSFERRING;
-
-	purple_debug_info("google_session", "GTALK_XFER_CHHANEL_TREANSFERRING\n");
+	*/
+	/*
+	purple_debug_info("google_session", "GTALK_XFER_CHHANEL_TRANSFERRING\n");
 
 	if(share_session->channel_state == GTALK_XFER_CHANNEL_HTTP_TRANSFERRING)
 		{
@@ -2265,7 +2275,7 @@ void cb_nice_component_writable(NiceAgen
 			}		        			 
 		}
 	
-
+	*/
 	/*TODO: Whenever nice_agent_send returns -1, that means that either something is VERY WRONG,
 	  or the output buffer is full. If the output buffer is full, that means we need to wait for the
 	  reliable-transport-writable signal in order to resume writing to the xfer. Should probbaly set up a loop 
@@ -2612,9 +2622,32 @@ gtalk_xfer_request_denied(PurpleXfer *xf
 	/*TODO: Session should end here but Not prematurely!*/
 }
 
-void
+gssize
 gtalk_xfer_write(const guchar *buffer, size_t size, PurpleXfer *xfer)
 {
+  /*	gssize len;
+	GoogleSession *session = xfer->data;
+
+	if (!session)
+		return -1;
+
+	if (purple_xfer_get_type(xfer) != PURPLE_XFER_SEND) {
+		return -1;
+	}
+
+	len = nice_agent_send(xfer->fd, buffer, size);
+
+	if (len == -1) {
+		if (purple_xfer_get_bytes_sent(xfer) >= purple_xfer_get_size(xfer))
+			purple_xfer_set_completed(xfer, TRUE);
+		if ((errno != EAGAIN) && (errno != EINTR))
+			return -1;
+		return 0;
+	}
+
+	return len;
+}
+  */
   purple_debug_info("google_session", "Inside gtalk_xfer_write..\n");
 }
 
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
@@ -57,7 +57,7 @@ void gtalk_xfer_send(PurpleConnection *g
 void gtalk_xfer_init(PurpleXfer *xfer);
 void gtalk_xfer_request_denied(PurpleXfer *xfer);
 gssize gtalk_xfer_read(guchar **out_buffer, PurpleXfer *xfer);
-void gtalk_xfer_write(const guchar *buffer, size_t size, PurpleXfer *xfer);
+gssize gtalk_xfer_write(const guchar *buffer, size_t size, PurpleXfer *xfer);
 void gtalk_xfer_start(PurpleXfer *xfer);
 void gtalk_xfer_end(PurpleXfer *xfer);
 void gtalk_xfer_send_transport_accept(JabberStream *js, GoogleSession *session);



More information about the Commits mailing list