diff libpurple/protocols/mxit/chunk.h @ 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 69aa4660401a
children 815bd8b41638
line wrap: on
line diff
--- a/libpurple/protocols/mxit/chunk.h	Tue Nov 24 11:50:55 2009 +0000
+++ b/libpurple/protocols/mxit/chunk.h	Tue Nov 24 13:23:27 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];