libpurple/protocols/mxit/markup.c

changeset 34243
5019efec9d8f
parent 34236
65f7a964bab1
parent 34217
c144c2019308
child 34253
e5f98ea3b169
--- a/libpurple/protocols/mxit/markup.c	Fri Jul 05 15:24:47 2013 +0200
+++ b/libpurple/protocols/mxit/markup.c	Wed Jul 10 19:50:12 2013 -0400
@@ -87,7 +87,7 @@
  *  @param buf				The data to dump
  *  @param len				The length of the data
  */
-static void hex_dump( const char* buf, int len )
+static void hex_dump( const gchar* buf, int len )
 {
 	char		msg[256];
 	int			pos;
@@ -103,11 +103,11 @@
 		if ( pos == 0 )
 			pos += sprintf( &msg[pos], "%04i:  ", i );
 
-		pos += sprintf( &msg[pos], "0x%02X ", (unsigned char) buf[i] );
+		pos += sprintf( &msg[pos], "0x%02X ", buf[i] );
 
 		if ( i % 16 == 15 ) {
 			pos += sprintf( &msg[pos], "\n" );
-			purple_debug_info( MXIT_PLUGIN_ID, msg );
+			purple_debug_info( MXIT_PLUGIN_ID, "%s", msg );
 			pos = 0;
 		}
 		else if ( i % 16 == 7 )
@@ -116,7 +116,7 @@
 
 	if ( pos > 0 ) {
 		pos += sprintf( &msg[pos], "\n" );
-		purple_debug_info( MXIT_PLUGIN_ID, msg );
+		purple_debug_info( MXIT_PLUGIN_ID, "%s", msg );
 		pos = 0;
 	}
 }
@@ -167,7 +167,7 @@
  *  @param size				The extracted length
  *  @return					The number of bytes extracted
  */
-static unsigned int asn_getlength( const char* data, int* size )
+static unsigned int asn_getlength( const gchar* data, int* size )
 {
 	unsigned int	len		= 0;
 	unsigned char	bytes;
@@ -202,14 +202,14 @@
  *  @param utf8				The extracted string.  Must be deallocated by caller.
  *  @return					The number of bytes extracted
  */
-static int asn_getUtf8( const char* data, unsigned char type, char** utf8 )
+static int asn_getUtf8( const gchar* data, gchar type, char** utf8 )
 {
 	int		len;
 
 	/* validate the field type [1 byte] */
 	if ( data[0] != type ) {
 		/* this is not a utf-8 string! */
-		purple_debug_error( MXIT_PLUGIN_ID, "Invalid UTF-8 encoded string in ASN data (0x%02X)\n", (unsigned char) data[0] );
+		purple_debug_error( MXIT_PLUGIN_ID, "Invalid UTF-8 encoded string in ASN data (got 0x%02X, expected 0x%02X)\n", data[0], type );
 		return -1;
 	}
 
@@ -472,7 +472,6 @@
 	const gchar*			data;
 	size_t				len;
 	unsigned int		pos			= 0;
-	char				emo[16];
 	int					id;
 	char*				str;
 	int					em_size		= 0;
@@ -481,9 +480,7 @@
 	int*				intptr		= NULL;
 	int					res;
 
-#ifdef	MXIT_DEBUG_EMO
 	purple_debug_info( MXIT_PLUGIN_ID, "emoticon_returned\n" );
-#endif
 
 	/* remove request from the async outstanding calls list */
 	mx->session->async_http_reqs = g_slist_remove(mx->session->async_http_reqs, http_conn);
@@ -500,12 +497,8 @@
 	hex_dump( data, len );
 #endif
 
-	/* parse out the emoticon */
-	pos = 0;
-
-	/* validate the binary data received from the wapsite */
+	/* validate that the returned data starts with the magic constant that indicates it is a custom emoticon */
 	if ( memcmp( MXIT_FRAME_MAGIC, &data[pos], strlen( MXIT_FRAME_MAGIC ) ) != 0 ) {
-		/* bad data, magic constant is wrong */
 		purple_debug_error( MXIT_PLUGIN_ID, "Invalid emoticon received from wapsite (bad magic)\n" );
 		goto done;
 	}
@@ -513,16 +506,14 @@
 
 	/* validate the image frame desc byte */
 	if ( data[pos] != '\x6F' ) {
-		/* bad frame desc */
 		purple_debug_error( MXIT_PLUGIN_ID, "Invalid emoticon received from wapsite (bad frame desc)\n" );
 		goto done;
 	}
 	pos++;
 
-	/* get the data length */
+	/* get the frame image data length */
 	res = asn_getlength( &data[pos], &em_size );
 	if ( res <= 0 ) {
-		/* bad frame length */
 		purple_debug_error( MXIT_PLUGIN_ID, "Invalid emoticon received from wapsite (bad frame length)\n" );
 		goto done;
 	}
@@ -534,7 +525,6 @@
 	/* utf-8 (emoticon name) */
 	res = asn_getUtf8( &data[pos], 0x0C, &str );
 	if ( res <= 0 ) {
-		/* bad utf-8 string */
 		purple_debug_error( MXIT_PLUGIN_ID, "Invalid emoticon received from wapsite (bad name string)\n" );
 		goto done;
 	}
@@ -548,7 +538,6 @@
 	/* utf-8 (emoticon shortcut) */
 	res = asn_getUtf8( &data[pos], 0x81, &str );
 	if ( res <= 0 ) {
-		/* bad utf-8 string */
 		purple_debug_error( MXIT_PLUGIN_ID, "Invalid emoticon received from wapsite (bad shortcut string)\n" );
 		goto done;
 	}
@@ -560,7 +549,6 @@
 
 	/* validate the image data type */
 	if ( data[pos] != '\x82' ) {
-		/* bad frame desc */
 		purple_debug_error( MXIT_PLUGIN_ID, "Invalid emoticon received from wapsite (bad data type)\n" );
 		g_free( em_id );
 		goto done;
@@ -580,8 +568,17 @@
 	purple_debug_info( MXIT_PLUGIN_ID, "read the length '%i'\n", em_size );
 #endif
 
+	/* strip the mxit markup tags from the emoticon id (eg, .{XY} -> XY) */
+	if ( ( em_id[0] == '.' ) && ( em_id[1] == '{' ) ) {
+		char	emo[MXIT_MAX_EMO_ID + 1];
+
+		parse_emoticon_str( &em_id[2], emo );
+		strcpy( em_id, emo );
+	}
+
 	if ( g_hash_table_lookup( mx->session->iimages, em_id ) ) {
 		/* emoticon found in the table, so ignore this one */
+		g_free( em_id );
 		goto done;
 	}
 
@@ -589,12 +586,6 @@
 	em_data = g_malloc( em_size );
 	memcpy( em_data, &data[pos], em_size );
 
-	/* strip the mxit markup tags from the emoticon id */
-	if ( ( em_id[0] == '.' ) && ( em_id[1] == '{' ) ) {
-		parse_emoticon_str( &em_id[2], emo );
-		strcpy( em_id, emo );
-	}
-
 	/* we now have the emoticon, store it in the imagestore */
 	id = purple_imgstore_new_with_id( em_data, em_size, NULL );
 

mercurial