changeset 28659:1375fd2d9df2

propagate from branch 'im.pidgin.pidgin' (head d330e81020232653571a0d5b1f5c927bc148a6fe) to branch 'im.pidgin.pidgin.mxit' (head f160c344624e9fdd06fd3a5e7eb58bcb772274dd)
author andrew.victor@mxit.com
date Wed, 25 Nov 2009 08:17:02 +0000
parents 0e70cbf43934 (current diff) bbc3eac0ee95 (diff)
children 2b964c74de53
files
diffstat 9 files changed, 90 insertions(+), 72 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/mxit/chunk.c	Tue Nov 24 17:14:59 2009 +0000
+++ b/libpurple/protocols/mxit/chunk.c	Wed Nov 25 08:17:02 2009 +0000
@@ -576,18 +576,17 @@
 
 	/* parse the resource chunks */
 	while ( chunklen > 0 ) {
-		struct raw_chunk* chunkhdr = ( struct raw_chunk * ) &chunkdata[pos];
-		chunkhdr->length = ntohl( chunkhdr->length );		/* host byte-order */
+		gchar* chunk = &chunkdata[pos];
 
 		/* start of chunk data */
-		pos += sizeof( struct raw_chunk );
+		pos += MXIT_CHUNK_HEADER_SIZE;
 
-		switch ( chunkhdr->type ) {
+		switch ( chunk_type( chunk ) ) {
 			case CP_CHUNK_SPLASH :			/* splash image */
 				{
 					struct splash_chunk* splash = g_new0( struct splash_chunk, 1 );
 
-					mxit_chunk_parse_splash( &chunkdata[pos], chunkhdr->length, splash );
+					mxit_chunk_parse_splash( &chunkdata[pos], chunk_length( chunk ), splash );
 
 					cr->resources = g_list_append( cr->resources, splash );
 					break;
@@ -600,12 +599,12 @@
 					break;
 				}
 			default:
-				purple_debug_info( MXIT_PLUGIN_ID, "Unsupported custom resource chunk received (%i)\n", chunkhdr->type );
+				purple_debug_info( MXIT_PLUGIN_ID, "Unsupported custom resource chunk received (%i)\n", chunk_type( chunk) );
 		}
 
 		/* skip over data to next resource chunk */
-		pos += chunkhdr->length;
-		chunklen -= ( sizeof( struct raw_chunk ) + chunkhdr->length );
+		pos += chunk_length( chunk );
+		chunklen -= ( MXIT_CHUNK_HEADER_SIZE + chunk_length( chunk ) );
 	}
 }
 
--- a/libpurple/protocols/mxit/chunk.h	Tue Nov 24 17:14:59 2009 +0000
+++ b/libpurple/protocols/mxit/chunk.h	Wed Nov 25 08:17:02 2009 +0000
@@ -31,6 +31,8 @@
 
 
 #define		MXIT_CHUNK_FILEID_LEN		8			/* bytes */
+#define		MXIT_CHUNK_HEADER_SIZE		5			/* type (1 byte) + length (4 bytes) */
+
 
 /* Multimedia chunk types */
 #define		CP_CHUNK_NONE				0x00		/* (0) no chunk */
@@ -68,13 +70,35 @@
 #define		REJECT_BAD_RECIPIENT		4
 
 /*
- * a Chunk header
+ * Chunk header manipulation functions
  */
-struct raw_chunk {
-	guint8		type;
-	guint32		length;
-	gchar		data[0];
-} __attribute__ ((packed));
+static inline guint chunk_type( gchar* chunkheader )
+{
+	return *chunkheader;
+}
+
+static inline void set_chunk_type( gchar* chunkheader, guint type )
+{
+	*chunkheader = type;
+}
+
+static inline guint32 chunk_length( gchar* chunkheader )
+{
+	guint32 length = *( (const guint32*) &chunkheader[1] );
+	return htonl( length );
+}
+
+static inline void set_chunk_length( gchar* chunkheader, guint32 size )
+{
+	size = htonl( size );
+	memcpy( &chunkheader[1], &size, sizeof( guint32 ) );
+}
+
+static inline gchar* chunk_data( gchar* chunkheader )
+{
+	return &chunkheader[MXIT_CHUNK_HEADER_SIZE];
+}
+
 
 struct offerfile_chunk {
 	char	fileid[MXIT_CHUNK_FILEID_LEN];
--- a/libpurple/protocols/mxit/formcmds.c	Tue Nov 24 17:14:59 2009 +0000
+++ b/libpurple/protocols/mxit/formcmds.c	Wed Nov 25 08:17:02 2009 +0000
@@ -345,7 +345,6 @@
  *  @param message			The message text
  *  @return					The length of the command
  */
-//void mxit_command_received(struct MXitSession* session, const char* from, char* message, time_t timestamp)
 int mxit_parse_command(struct RXMsgData* mx, char* message)
 {
 	GHashTable* hash	= NULL;
--- a/libpurple/protocols/mxit/markup.c	Tue Nov 24 17:14:59 2009 +0000
+++ b/libpurple/protocols/mxit/markup.c	Wed Nov 25 08:17:02 2009 +0000
@@ -416,7 +416,6 @@
 	}
 	else if ( mx->chatid < 0 ) {
 		/* normal chat message */
-		//serv_got_im( mx->session->con, mx->from, mx->msg->str, mx->flags, mx->timestamp );
 		mxit_show_split_message( mx );
 	}
 	else {
--- a/libpurple/protocols/mxit/mxit.c	Tue Nov 24 17:14:59 2009 +0000
+++ b/libpurple/protocols/mxit/mxit.c	Wed Nov 25 08:17:02 2009 +0000
@@ -689,9 +689,6 @@
 
 	option = purple_account_option_bool_new( _( "Enable splash-screen popup" ), MXIT_CONFIG_SPLASHPOPUP, FALSE );
 	proto_info.protocol_options = g_list_append( proto_info.protocol_options, option );
-
-	if ( sizeof( struct raw_chunk ) != 5 )
-		g_log(G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "sizeof(struct raw_chunk) != 5!  MXit probably won't work!\n");
 }
 
 PURPLE_INIT_PLUGIN( mxit, init_plugin, plugin_info );
--- a/libpurple/protocols/mxit/mxit.h	Tue Nov 24 17:14:59 2009 +0000
+++ b/libpurple/protocols/mxit/mxit.h	Wed Nov 25 08:17:02 2009 +0000
@@ -61,7 +61,7 @@
 /* Plugin details */
 #define		MXIT_PLUGIN_ID				"prpl-loubserp-mxit"
 #define		MXIT_PLUGIN_NAME			"MXit"
-#define		MXIT_PLUGIN_VERSION			"2.2.0"
+#define		MXIT_PLUGIN_VERSION			"2.3.0"
 #define		MXIT_PLUGIN_EMAIL			"Pieter Loubser <libpurple@mxit.com>"
 #define		MXIT_PLUGIN_WWW				"http://www.mxit.com"
 #define		MXIT_PLUGIN_SUMMARY			"MXit Protocol Plugin"
--- a/libpurple/protocols/mxit/protocol.c	Tue Nov 24 17:14:59 2009 +0000
+++ b/libpurple/protocols/mxit/protocol.c	Wed Nov 25 08:17:02 2009 +0000
@@ -1035,7 +1035,7 @@
 {
 	char				data[CP_MAX_PACKET];
 	int					datalen		= 0;
-	struct raw_chunk*	chunk;
+	gchar*				chunk;
 	int					size;
 
 	purple_debug_info( MXIT_PLUGIN_ID, "SENDING FILE '%s' of %i bytes to user '%s'\n", filename, buflen, username );
@@ -1044,17 +1044,17 @@
 	datalen = sprintf( data, "ms=" );
 
 	/* map chunk header over data buffer */
-	chunk = (struct raw_chunk *) &data[datalen];
-
-	size = mxit_chunk_create_senddirect( chunk->data, username, filename, buf, buflen );
+	chunk = &data[datalen];
+
+	size = mxit_chunk_create_senddirect( chunk_data( chunk ), username, filename, buf, buflen );
 	if ( size < 0 ) {
 		purple_debug_error( MXIT_PLUGIN_ID, "Error creating senddirect chunk (%i)\n", size );
 		return;
 	}
 
-	chunk->type = CP_CHUNK_DIRECT_SND;
-	chunk->length = htonl( size );
-	datalen += sizeof( struct raw_chunk ) + size;
+	set_chunk_type( chunk, CP_CHUNK_DIRECT_SND );
+	set_chunk_length( chunk, size );
+	datalen += MXIT_CHUNK_HEADER_SIZE + size;
 
 	/* send the byte stream to the mxit server */
 	mxit_queue_packet( session, data, datalen, CP_CMD_MEDIA );
@@ -1071,7 +1071,7 @@
 {
 	char				data[CP_MAX_PACKET];
 	int					datalen		= 0;
-	struct raw_chunk*	chunk;
+	gchar*				chunk;
 	int					size;
 
 	purple_debug_info( MXIT_PLUGIN_ID, "mxit_send_file_reject\n" );
@@ -1080,17 +1080,17 @@
 	datalen = sprintf( data, "ms=" );
 
 	/* map chunk header over data buffer */
-	chunk = (struct raw_chunk *) &data[datalen];
-
-	size = mxit_chunk_create_reject( chunk->data, fileid );
+	chunk = &data[datalen];
+
+	size = mxit_chunk_create_reject( chunk_data( chunk ), fileid );
 	if ( size < 0 ) {
 		purple_debug_error( MXIT_PLUGIN_ID, "Error creating reject chunk (%i)\n", size );
 		return;
 	}
 
-	chunk->type = CP_CHUNK_REJECT;
-	chunk->length = htonl( size );
-	datalen += sizeof( struct raw_chunk ) + size;
+	set_chunk_type( chunk, CP_CHUNK_REJECT );
+	set_chunk_length( chunk, size );
+	datalen += MXIT_CHUNK_HEADER_SIZE + size;
 
 	/* send the byte stream to the mxit server */
 	mxit_queue_packet( session, data, datalen, CP_CMD_MEDIA );
@@ -1109,7 +1109,7 @@
 {
 	char				data[CP_MAX_PACKET];
 	int					datalen		= 0;
-	struct raw_chunk*	chunk;
+	gchar*				chunk;
 	int					size;
 
 	purple_debug_info( MXIT_PLUGIN_ID, "mxit_send_file_accept\n" );
@@ -1118,17 +1118,17 @@
 	datalen = sprintf( data, "ms=" );
 
 	/* map chunk header over data buffer */
-	chunk = (struct raw_chunk *) &data[datalen];
-
-	size = mxit_chunk_create_get( chunk->data, fileid, filesize, offset );
+	chunk = &data[datalen];
+
+	size = mxit_chunk_create_get( chunk_data(chunk), fileid, filesize, offset );
 	if ( size < 0 ) {
 		purple_debug_error( MXIT_PLUGIN_ID, "Error creating getfile chunk (%i)\n", size );
 		return;
 	}
 
-	chunk->type = CP_CHUNK_GET;
-	chunk->length = htonl( size );
-	datalen += sizeof( struct raw_chunk ) + size;
+	set_chunk_type( chunk, CP_CHUNK_GET );
+	set_chunk_length( chunk, size );
+	datalen += MXIT_CHUNK_HEADER_SIZE + size;
 
 	/* send the byte stream to the mxit server */
 	mxit_queue_packet( session, data, datalen, CP_CMD_MEDIA );
@@ -1145,7 +1145,7 @@
 {
 	char				data[CP_MAX_PACKET];
 	int					datalen		= 0;
-	struct raw_chunk*	chunk;
+	gchar*				chunk;
 	int					size;
 
 	purple_debug_info( MXIT_PLUGIN_ID, "mxit_send_file_received\n" );
@@ -1154,17 +1154,17 @@
 	datalen = sprintf( data, "ms=" );
 
 	/* map chunk header over data buffer */
-	chunk = (struct raw_chunk *) &data[datalen];
-
-	size = mxit_chunk_create_received( chunk->data, fileid, status );
+	chunk = &data[datalen];
+
+	size = mxit_chunk_create_received( chunk_data(chunk), fileid, status );
 	if ( size < 0 ) {
 		purple_debug_error( MXIT_PLUGIN_ID, "Error creating received chunk (%i)\n", size );
 		return;
 	}
 
-	chunk->type = CP_CHUNK_RECIEVED;
-	chunk->length = htonl( size );
-	datalen += sizeof( struct raw_chunk ) + size;
+	set_chunk_type( chunk, CP_CHUNK_RECIEVED );
+	set_chunk_length( chunk, size );
+	datalen += MXIT_CHUNK_HEADER_SIZE + size;
 
 	/* send the byte stream to the mxit server */
 	mxit_queue_packet( session, data, datalen, CP_CMD_MEDIA );
@@ -1182,7 +1182,7 @@
 {
 	char				data[CP_MAX_PACKET];
 	int					datalen		= 0;
-	struct raw_chunk*	chunk;
+	gchar*				chunk;
 	int					size;
 
 	purple_debug_info( MXIT_PLUGIN_ID, "mxit_set_avatar: %i bytes\n", avatarlen );
@@ -1191,17 +1191,17 @@
 	datalen = sprintf( data, "ms=" );
 
 	/* map chunk header over data buffer */
-	chunk = (struct raw_chunk *) &data[datalen];
-
-	size = mxit_chunk_create_set_avatar( chunk->data, avatar, avatarlen );
+	chunk = &data[datalen];
+
+	size = mxit_chunk_create_set_avatar( chunk_data(chunk), avatar, avatarlen );
 	if ( size < 0 ) {
 		purple_debug_error( MXIT_PLUGIN_ID, "Error creating set avatar chunk (%i)\n", size );
 		return;
 	}
 
-	chunk->type = CP_CHUNK_SET_AVATAR;
-	chunk->length = htonl( size );
-	datalen += sizeof( struct raw_chunk ) + size;
+	set_chunk_type( chunk, CP_CHUNK_SET_AVATAR );
+	set_chunk_length( chunk, size );
+	datalen += MXIT_CHUNK_HEADER_SIZE + size;
 
 	/* send the byte stream to the mxit server */
 	mxit_queue_packet( session, data, datalen, CP_CMD_MEDIA );
@@ -1221,7 +1221,7 @@
 {
 	char				data[CP_MAX_PACKET];
 	int					datalen		= 0;
-	struct raw_chunk*	chunk;
+	gchar*				chunk;
 	int					size;
 
 	purple_debug_info( MXIT_PLUGIN_ID, "mxit_get_avatar: %s\n", mxitId );
@@ -1230,17 +1230,17 @@
 	datalen = sprintf( data, "ms=" );
 
 	/* map chunk header over data buffer */
-	chunk = (struct raw_chunk *) &data[datalen];
-
-	size = mxit_chunk_create_get_avatar( chunk->data, mxitId, avatarId, MXIT_AVATAR_SIZE );
+	chunk = &data[datalen];
+
+	size = mxit_chunk_create_get_avatar( chunk_data(chunk), mxitId, avatarId, MXIT_AVATAR_SIZE );
 	if ( size < 0 ) {
 		purple_debug_error( MXIT_PLUGIN_ID, "Error creating get avatar chunk (%i)\n", size );
 		return;
 	}
 
-	chunk->type = CP_CHUNK_GET_AVATAR;
-	chunk->length = htonl( size );
-	datalen += sizeof( struct raw_chunk ) + size;
+	set_chunk_type( chunk, CP_CHUNK_GET_AVATAR );
+	set_chunk_length( chunk, size );
+	datalen += MXIT_CHUNK_HEADER_SIZE + size;
 
 	/* send the byte stream to the mxit server */
 	mxit_queue_packet( session, data, datalen, CP_CMD_MEDIA );
--- a/libpurple/protocols/mxit/roster.c	Tue Nov 24 17:14:59 2009 +0000
+++ b/libpurple/protocols/mxit/roster.c	Wed Nov 25 08:17:02 2009 +0000
@@ -53,11 +53,11 @@
 	const char*				name;
 } const mxit_statuses[] = {
 		/*	primative,						no,							id,			name					*/
-		{	PURPLE_STATUS_OFFLINE,			MXIT_PRESENCE_OFFLINE,		"offline",	NULL				},	/* 0 */
-		{	PURPLE_STATUS_AVAILABLE,		MXIT_PRESENCE_ONLINE,		"online",	NULL				},	/* 1 */
-		{	PURPLE_STATUS_AWAY,				MXIT_PRESENCE_AWAY,			"away",		NULL				},	/* 2 */
-		{	PURPLE_STATUS_AVAILABLE,		MXIT_PRESENCE_AVAILABLE,	"chat",		N_( "Chatty" )		},	/* 3 */
-		{	PURPLE_STATUS_UNAVAILABLE,		MXIT_PRESENCE_DND,			"dnd",		NULL				}	/* 4 */
+		{	PURPLE_STATUS_OFFLINE,			MXIT_PRESENCE_OFFLINE,		"offline",	N_( "Offline" )			},	/* 0 */
+		{	PURPLE_STATUS_AVAILABLE,		MXIT_PRESENCE_ONLINE,		"online",	N_( "Available" )		},	/* 1 */
+		{	PURPLE_STATUS_AWAY,				MXIT_PRESENCE_AWAY,			"away",		N_( "Away" )			},	/* 2 */
+		{	PURPLE_STATUS_AVAILABLE,		MXIT_PRESENCE_AVAILABLE,	"chat",		N_( "Chatty" )			},	/* 3 */
+		{	PURPLE_STATUS_UNAVAILABLE,		MXIT_PRESENCE_DND,			"dnd",		N_( "Do Not Disturb" )	}	/* 4 */
 };
 
 
@@ -398,7 +398,7 @@
 		contact->statusMsg = NULL;
 	}
 	if ( statusMsg[0] != '\0' )
-		contact->statusMsg = g_strdup( statusMsg );	
+		contact->statusMsg = g_markup_escape_text( statusMsg, -1 );
 
 	/* update avatarId */
 	if ( ( contact->avatarId ) && ( g_ascii_strcasecmp( contact->avatarId, avatarId ) == 0 ) ) {
--- a/libpurple/protocols/mxit/splashscreen.c	Tue Nov 24 17:14:59 2009 +0000
+++ b/libpurple/protocols/mxit/splashscreen.c	Wed Nov 25 08:17:02 2009 +0000
@@ -43,10 +43,10 @@
 {
 	const char* splashId = purple_account_get_string(session->acc, MXIT_CONFIG_SPLASHID, NULL);
 
-	purple_debug_info(MXIT_PLUGIN_ID, "Current splashId: '%s'\n", splashId);
-
-	if ((splashId != NULL) && (*splashId != '\0'))
+	if ((splashId != NULL) && (*splashId != '\0')) {
+		purple_debug_info(MXIT_PLUGIN_ID, "Current splashId: '%s'\n", splashId);
 		return splashId;
+	}
 	else
 		return NULL;
 }
@@ -149,7 +149,7 @@
 
 	/* Get current splash ID */
 	splashId = splash_current(session);
-	if (!splashId)
+	if (splashId == NULL)		/* no splash-screen */
 		return;
 
 	/* if is clickable, then send click event */