diff libpurple/protocols/mxit/protocol.c @ 29036:06fabb28bc69

The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension. (ie, no alignment padding between members of the structure) To build with compilers which don't support this packed attribute, we've now use methods to access/modify the fields in the packed MXit chunk header.
author andrew.victor@mxit.com
date Tue, 24 Nov 2009 13:23:27 +0000
parents 66c4fbe088d0
children 259bbfb423d4
line wrap: on
line diff
--- a/libpurple/protocols/mxit/protocol.c	Tue Nov 24 11:50:55 2009 +0000
+++ b/libpurple/protocols/mxit/protocol.c	Tue Nov 24 13:23:27 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 );