changeset 31508:c5bdf87770df

* Handle response to SendFile chunk packet, and display the error message if the file transfer failed. * Enable protocol version 6.3.
author andrew.victor@mxit.com
date Tue, 12 Apr 2011 21:25:51 +0000
parents efed7d3c5574
children 99b03406e433
files libpurple/protocols/mxit/chunk.c libpurple/protocols/mxit/chunk.h libpurple/protocols/mxit/protocol.c libpurple/protocols/mxit/protocol.h
diffstat 4 files changed, 78 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/mxit/chunk.c	Tue Apr 12 19:59:54 2011 +0000
+++ b/libpurple/protocols/mxit/chunk.c	Tue Apr 12 21:25:51 2011 +0000
@@ -224,6 +224,7 @@
  *
  *  @param chunkdata		The chunked-data buffer
  *  @param str				A pointer to extracted string.  Must be g_free()'d.
+ *  @param maxstrlen		Maximum size of destination buffer.
  *  @return					The number of bytes consumed
  */
 static int get_utf8_string( const char* chunkdata, char* str, int maxstrlen )
@@ -465,10 +466,10 @@
 	pos += get_int32( &chunkdata[pos], &(offer->filesize) );
 
 	/* filename [UTF-8] */
-	pos += get_utf8_string( &chunkdata[pos], offer->filename, sizeof( offer->filename) );
+	pos += get_utf8_string( &chunkdata[pos], offer->filename, sizeof( offer->filename ) );
 
 	/* mime type [UTF-8] */
-	/* not used by libPurple */
+	pos += get_utf8_string( &chunkdata[pos], offer->mimetype, sizeof( offer->mimetype ) );
 
 	/* timestamp [8 bytes] */
 	/* not used by libPurple */
@@ -606,6 +607,37 @@
 
 
 /*------------------------------------------------------------------------
+ * Parse a received "send file direct" response chunk.  (Chunk 10)
+ *
+ *  @param chunkdata		Chunked data buffer
+ *  @param datalen			The length of the chunked data
+ *  @param sendfile			Decoded sendfile information
+ */
+void mxit_chunk_parse_sendfile( char* chunkdata, int datalen, struct sendfile_chunk* sendfile )
+{
+	int			pos		= 0;
+	short		entries	= 0;
+
+	purple_debug_info( MXIT_PLUGIN_ID, "mxit_chunk_parse_sendfile (%i bytes)\n", datalen );
+
+	/* number of entries [2 bytes] */
+	pos += get_int16( &chunkdata[pos], &entries );
+
+	if ( entries < 1 )		/* no data */
+		return;
+
+	/* contactAddress [UTF-8 string] */
+	pos += get_utf8_string( &chunkdata[pos], sendfile->username, sizeof( sendfile->username ) );
+
+	/* status [4 bytes] */
+	pos += get_int32( &chunkdata[pos], &(sendfile->status) );
+
+	/* status message [UTF-8 string] */
+	pos += get_utf8_string( &chunkdata[pos], sendfile->statusmsg, sizeof( sendfile->statusmsg ) );
+}
+
+
+/*------------------------------------------------------------------------
  * Parse a received "get avatar" response chunk.  (Chunk 14)
  *
  *  @param chunkdata		Chunked data buffer
--- a/libpurple/protocols/mxit/chunk.h	Tue Apr 12 19:59:54 2011 +0000
+++ b/libpurple/protocols/mxit/chunk.h	Tue Apr 12 21:25:51 2011 +0000
@@ -99,14 +99,20 @@
 	return &chunkheader[MXIT_CHUNK_HEADER_SIZE];
 }
 
-
+/*
+ * Offer File chunk (6).
+ */
 struct offerfile_chunk {
 	char	fileid[MXIT_CHUNK_FILEID_LEN];
 	char	username[MXIT_CP_MAX_JID_LEN + 1];
 	int		filesize;
 	char	filename[FILENAME_MAX];
+	char	mimetype[64];
 };
 
+/*
+ * Get File chunk (8) response.
+ */
 struct getfile_chunk {
 	char	fileid[MXIT_CHUNK_FILEID_LEN];
 	int		offset;
@@ -115,6 +121,9 @@
 	char*	data;
 };
 
+/*
+ * Custom Resource chunk (1).
+ */
 struct cr_chunk {
 	char	id[64];
 	char	handle[64];
@@ -122,6 +131,9 @@
 	GList*	resources;
 };
 
+/*
+ * Splash Image chunk (2)
+ */
 struct splash_chunk {
 	char	anchor;
 	char	showtime;
@@ -130,10 +142,16 @@
 	int		datalen;
 };
 
+/*
+ * Splash Click Through chunk (3)
+ */
 struct splash_click_chunk {
 	char	reserved[1];
 };
 
+/*
+ * Get Avatar chunk (14) response.
+ */
 struct getavatar_chunk {
 	char	mxitid[50];
 	char	avatarid[64];
@@ -146,6 +164,15 @@
 	char*	data;
 };
 
+/*
+ * Send File Direct chunk (10) response.
+ */
+struct sendfile_chunk {
+	char	username[MXIT_CP_MAX_JID_LEN + 1];
+	int		status;
+	char	statusmsg[1024];
+};
+
 /* Encode chunk */
 int mxit_chunk_create_senddirect( char* chunkdata, const char* username, const char* filename, const unsigned char* data, int datalen );
 int mxit_chunk_create_reject( char* chunkdata, const char* fileid );
@@ -158,6 +185,7 @@
 void mxit_chunk_parse_offer( char* chunkdata, int datalen, struct offerfile_chunk* offer );
 void mxit_chunk_parse_get( char* chunkdata, int datalen, struct getfile_chunk* getfile );
 void mxit_chunk_parse_cr( char* chunkdata, int datalen, struct cr_chunk* cr );
+void mxit_chunk_parse_sendfile( char* chunkdata, int datalen, struct sendfile_chunk* sendfile );
 void mxit_chunk_parse_get_avatar( char* chunkdata, int datalen, struct getavatar_chunk* avatar );
 
 #endif		/* _MXIT_CHUNK_H_ */
--- a/libpurple/protocols/mxit/protocol.c	Tue Apr 12 19:59:54 2011 +0000
+++ b/libpurple/protocols/mxit/protocol.c	Tue Apr 12 21:25:51 2011 +0000
@@ -2088,7 +2088,7 @@
 				struct contact* contact = NULL;
 
 				/* decode the chunked data */
-				memset( &chunk, 0, sizeof ( struct getavatar_chunk ) );
+				memset( &chunk, 0, sizeof( struct getavatar_chunk ) );
 				mxit_chunk_parse_get_avatar( &records[0]->fields[0]->data[sizeof( char ) + sizeof( int )], records[0]->fields[0]->len, &chunk );
 
 				/* update avatar image */
@@ -2114,7 +2114,18 @@
 			break;
 
 		case CP_CHUNK_DIRECT_SND :
-			/* this is a ack for a file send. no action is required */
+			/* this is a ack for a file send. */
+			{
+				struct sendfile_chunk chunk;
+
+				memset( &chunk, 0, sizeof( struct sendfile_chunk ) );
+				mxit_chunk_parse_sendfile( &records[0]->fields[0]->data[sizeof( char ) + sizeof( int )], records[0]->fields[0]->len, &chunk );
+
+				purple_debug_info( MXIT_PLUGIN_ID, "file-send send to '%s' [status=%i message='%s']\n", chunk.username, chunk.status, chunk.statusmsg );
+
+				if ( chunk.status != 0 )	/* not success */
+					mxit_popup( PURPLE_NOTIFY_MSG_ERROR, _( "File Send Failed" ), chunk.statusmsg );
+			}
 			break;
 
 		case CP_CHUNK_RECEIVED :
@@ -2285,6 +2296,7 @@
 				/* HTTP poll reply */
 		case CP_CMD_EXTPROFILE_SET :
 				/* profile update */
+				// TODO: Protocol 6.2 indicates status for each attribute, and current value.
 		case CP_CMD_SPLASHCLICK :
 				/* splash-screen clickthrough */
 		case CP_CMD_MSGEVENT :
--- a/libpurple/protocols/mxit/protocol.h	Tue Apr 12 19:59:54 2011 +0000
+++ b/libpurple/protocols/mxit/protocol.h	Tue Apr 12 21:25:51 2011 +0000
@@ -91,7 +91,7 @@
 #define		MXIT_CP_ARCH			"Y"						/* client architecture series (Y not for Yoda but for PC-client) */
 #define		MXIT_CLIENT_ID			"LP"					/* client ID as specified by MXit */
 #define		MXIT_CP_PLATFORM		"PURPLE"				/* client platform */
-#define		MXIT_CP_PROTO_VESION	60						/* client protocol version */
+#define		MXIT_CP_PROTO_VESION	63						/* client protocol version */
 
 /* set operating system name */
 #if defined( __APPLE__ )