/soc/2013/ankitkv/gobjectification: 499ffff1e77c: Refactored mxi...

Ankit Vani a at nevitus.org
Thu Sep 5 16:14:32 EDT 2013


Changeset: 499ffff1e77c0dff2b3d726ed1c8e03ab93bde11
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-09-06 01:08 +0530
Branch:	 soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/499ffff1e77c

Description:

Refactored mxit to use the GObject xfer API

diffstat:

 libpurple/protocols/mxit/filexfer.c |  48 ++++++++++++++++++++++++++----------
 libpurple/xfer.c                    |   4 +-
 2 files changed, 36 insertions(+), 16 deletions(-)

diffs (114 lines):

diff --git a/libpurple/protocols/mxit/filexfer.c b/libpurple/protocols/mxit/filexfer.c
--- a/libpurple/protocols/mxit/filexfer.c
+++ b/libpurple/protocols/mxit/filexfer.c
@@ -167,7 +167,7 @@ static void mxit_xfer_start( PurpleXfer*
 		filesize = purple_xfer_get_bytes_remaining( xfer );
 		buffer = g_malloc( filesize );
 
-		if ( fread( buffer, filesize, 1, xfer->dest_fp ) > 0 ) {
+		if ( purple_xfer_read_file( xfer, buffer, filesize ) > 0 ) {
 			/* send data */
 			wrote = purple_xfer_write( xfer, buffer, filesize );
 			if ( wrote > 0 )
@@ -282,6 +282,21 @@ static void mxit_xfer_cancel_recv( Purpl
  * Callbacks from libPurple
  */
 
+
+static PurpleXferIoOps send_ops =
+{
+	mxit_xfer_init,         /* init */
+	NULL,                   /* request_denied */
+	mxit_xfer_start,        /* start */
+	mxit_xfer_end,          /* end */
+	mxit_xfer_cancel_send,  /* cancel_send */
+	NULL,                   /* cancel_recv */
+	NULL,                   /* read */
+	mxit_xfer_write,        /* write */
+	NULL,                   /* ack */
+};
+
+
 /*------------------------------------------------------------------------
  * Indicate if file transfers are supported to this contact.
  * For MXit file transfers are always supported.
@@ -315,13 +330,7 @@ PurpleXfer* mxit_xfer_new( PurpleConnect
 	mx = g_new0( struct mxitxfer, 1 );
 	mx->session = session;
 	purple_xfer_set_protocol_data( xfer, mx );
-
-	/* configure callbacks (reference: "libpurple/xfer.h") */
-	purple_xfer_set_init_fnc( xfer, mxit_xfer_init );
-	purple_xfer_set_start_fnc( xfer, mxit_xfer_start );
-	purple_xfer_set_end_fnc( xfer, mxit_xfer_end );
-	purple_xfer_set_cancel_send_fnc( xfer, mxit_xfer_cancel_send );
-	purple_xfer_set_write_fnc( xfer, mxit_xfer_write );
+	purple_xfer_set_io_ops( xfer, &send_ops );
 
 	return xfer;
 }
@@ -349,6 +358,21 @@ void mxit_xfer_tx( PurpleConnection* gc,
  * Calls from the MXit Protocol layer
  */
 
+
+static PurpleXferIoOps recieve_ops =
+{
+	mxit_xfer_init,            /* init */
+	mxit_xfer_request_denied,  /* request_denied */
+	NULL,                      /* start */
+	mxit_xfer_end,             /* end */
+	NULL,                      /* cancel_send */
+	mxit_xfer_cancel_recv,     /* cancel_recv */
+	NULL,                      /* read */
+	NULL,                      /* write */
+	NULL,                      /* ack */
+};
+
+
 /*------------------------------------------------------------------------
  * A file transfer offer has been received from the MXit server.
  *
@@ -377,11 +401,7 @@ void mxit_xfer_rx_offer( struct MXitSess
 		if( filesize > 0 )
 			purple_xfer_set_size( xfer, filesize );
 
-		/* register file transfer callback functions */
-		purple_xfer_set_init_fnc( xfer, mxit_xfer_init );
-		purple_xfer_set_request_denied_fnc( xfer, mxit_xfer_request_denied );
-		purple_xfer_set_cancel_recv_fnc( xfer, mxit_xfer_cancel_recv );
-		purple_xfer_set_end_fnc( xfer, mxit_xfer_end );
+		purple_xfer_set_io_ops( xfer, &recieve_ops );
 
 		/* give the request to the user to accept/deny */
 		purple_xfer_request( xfer );
@@ -443,7 +463,7 @@ void mxit_xfer_rx_file( struct MXitSessi
 		g_object_ref( xfer );
 		purple_xfer_start( xfer, -1, NULL, 0 );
 
-		if ( fwrite( data, datalen, 1, xfer->dest_fp ) > 0 ) {
+		if ( purple_xfer_write_file( xfer, (const guchar *)data, datalen ) ) {
 			g_object_unref( xfer );
 			purple_xfer_set_completed( xfer, TRUE );
 			purple_xfer_end( xfer );
diff --git a/libpurple/xfer.c b/libpurple/xfer.c
--- a/libpurple/xfer.c
+++ b/libpurple/xfer.c
@@ -1220,7 +1220,7 @@ purple_xfer_write_file(PurpleXfer *xfer,
 			purple_xfer_cancel_local(xfer);
 			return FALSE;
 		}
-		wc = fwrite(buffer, 1, size, xfer->dest_fp);
+		wc = fwrite(buffer, size, 1, xfer->dest_fp);
 	}
 
 	if (wc != size) {
@@ -1270,7 +1270,7 @@ purple_xfer_read_file(PurpleXfer *xfer, 
 			purple_xfer_cancel_local(xfer);
 			return -1;
 		}
-		got_len = fread(buffer, 1, size, xfer->dest_fp);
+		got_len = fread(buffer, size, 1, xfer->dest_fp);
 		if ((got_len < 0 || (gsize)got_len != size) &&
 			ferror(xfer->dest_fp))
 		{



More information about the Commits mailing list