pidgin.vv.msn.webcam: ec068535: Ah, so this stuff won't pack nicely. I g...

qulogic at pidgin.im qulogic at pidgin.im
Fri Sep 3 03:37:01 EDT 2010


----------------------------------------------------------------------
Revision: ec068535120b4a36b841de5176756aac881afaf1
Parent:   fd0ebaab4feb089b101768df831688c995530e44
Author:   qulogic at pidgin.im
Date:     09/03/10 03:28:37
Branch:   im.pidgin.pidgin.vv.msn.webcam
URL: http://d.pidgin.im/viewmtn/revision/info/ec068535120b4a36b841de5176756aac881afaf1

Changelog: 

Ah, so this stuff won't pack nicely. I guess it's back to the weird
math. But only in one function this time.

Changes against parent fd0ebaab4feb089b101768df831688c995530e44

  patched  libpurple/protocols/msn/webcam.c

-------------- next part --------------
============================================================
--- libpurple/protocols/msn/webcam.c	040baefca0f3a70084f08ad14288fb1ff8766520
+++ libpurple/protocols/msn/webcam.c	15581976b531d8dbcb6263ed04e63c23f87c1765
@@ -37,16 +37,60 @@
 #include "slpcall.h"
 #include "slpmsg.h"
 
-/* Don't really know what this should be called. */
-typedef struct MsnWebcamData {
-	guint8  unknown1;
-	guint16 id;
-	guint8  flags;
-	guint16 unknown2;
-	guint32 data_len;
-	guint8  data[];
-} MsnWebcamData;
+/* This is horrible for packing. So I'd rather have one function with all the
+ * weird pointer arithmetic.
+ *
+ * header is (as far as we know):
+ *  guint8  unknown1;
+ *  guint16 id;
+ *  guint8  flags;
+ *  guint16 unknown2;
+ */
+#define WEBCAM_HEADER_LEN (sizeof(guint8) + sizeof(guint16) + sizeof(guint8) + sizeof(guint16))
+static char *
+create_webcam_data(guint16 id, guint8 flags, guint32 data_len, char data[], size_t *out_len)
+{
+	guint32 temp;
+	char *ret = g_malloc(WEBCAM_HEADER_LEN + sizeof(guint32) + data_len);
 
+	/* unknown1 == 0x80 always for now */
+	temp = GUINT32_TO_LE((flags << 24) + (id << 8) + 0x80);
+	memcpy(ret, &temp, sizeof(temp));
+	/* unknown2 == 0x0080 always for now */
+	ret[4] = 0x80;
+	ret[5] = 0x00;
+
+	temp = GUINT32_TO_LE(data_len);
+	memcpy(ret + WEBCAM_HEADER_LEN, &temp, sizeof(temp));
+	memcpy(ret + WEBCAM_HEADER_LEN + sizeof(guint32), data, data_len);
+
+	if (out_len)
+		*out_len = WEBCAM_HEADER_LEN + sizeof(guint32) + data_len;
+
+	return ret;
+}
+
+/* Shortcuts */
+#define WEBCAM_ACK \
+	"\x80" \
+	"\xea\00" \
+	"\x00" \
+	"\x08\x00" \
+	/* length of following */ \
+	"\x08\x00\x00\x00" \
+	/* actual data */ \
+	"a\0c\x00k\x00\x00\x00"
+
+#define WEBCAM_RECEIVER_REPLY \
+	"\x80" \
+	"\xec\x00" \
+	"\x03" \
+	"\x08\x00" \
+	/* length of following */ \
+	"\x16\x00\x00\x00" \
+	/* actual data */ \
+	"r\0e\0c\0e\0i\0v\0e\0d\0V\0i\0e\0w\0e\0r\0D\0a\0t\0a\0\0\0"
+
 static void
 msn_webcam_session_init_cb(MsnSlpCall *slpcall)
 {
@@ -180,7 +224,8 @@ msn_webcam_send_syn(MsnSlpCall *slpcall,
 msn_webcam_send_syn(MsnSlpCall *slpcall, const gchar *content)
 {
 	MsnSlpMessage *slpmsg;
-	MsnWebcamData *body;
+	char *body;
+	size_t body_len;
 
 	/*
 	 * The SlpCall object has a different instance here,
@@ -211,32 +256,19 @@ msn_webcam_send_syn(MsnSlpCall *slpcall,
 	}
 	g_list_free(iter);
 
-	body = (MsnWebcamData *)g_memdup("\x80"
-	                                 "\x00\x00"
-	                                 "\x01"
-	                                 "\x08\x00"
-	                                 "\x08\x00\x00\x00"
-	                                 "s\x00y\x00n\x00\x00\x00",
-	                                 18);
-	body->id = GINT16_TO_LE(rand() % 0xFFFF0000);
+	body = create_webcam_data(rand() % 0xFFFF0000, 0x01,
+	                          8, "s\x00y\x00n\x00\x00\x00",
+	                          &body_len);
 
 	slpmsg = msn_slpmsg_new(slpcall->slplink);
 	slpmsg->slpcall = slpcall;
 
 	slpmsg->session_id = slpcall->session_id;
-	msn_slpmsg_set_body(slpmsg, (char *)body, 18);
+	msn_slpmsg_set_body(slpmsg, body, body_len);
 	g_free(body);
 	msn_slplink_queue_slpmsg(slpcall->slplink, slpmsg);
 }
 
-#define WEBCAM_ACK \
-	"\x80" \
-	"\xea\00" \
-	"\x00" \
-	"\x08\x00" \
-	"\x08\x00\x00\x00" \
-	"a\0c\x00k\x00\x00\x00"
-
 void
 msn_webcam_send_ack(MsnSlpLink *slplink, MsnSlpMessage *slpmsg)
 {
@@ -265,7 +297,8 @@ msn_webcam_send_xml(MsnSlpLink *slplink,
 	guint count = 1;
 
 	gsize written;
-	MsnWebcamData *body;
+	char *body;
+	size_t body_len;
 	gboolean is_producer = FALSE;
 
 	/* Get candidates */
@@ -349,19 +382,15 @@ msn_webcam_send_xml(MsnSlpLink *slplink,
 	g_free(xml);
 	written += 2;
 
-	body = g_malloc(sizeof(MsnWebcamData) + written);
-	body->unknown1 = 0x80;
-	body->id = GUINT16_TO_LE(0x0000);
-	body->flags = 0x0000;
-	body->unknown2 = GUINT16_TO_LE(0x0080);
-	body->data_len = GUINT32_TO_LE(written);
-	memcpy(&body->data, xmlutf, written);
+	body = create_webcam_data(0x0000, 0x00,
+	                          written, xmlutf,
+	                          &body_len);
 	g_free(xmlutf);
 
 	slpmsg2 = msn_slpmsg_new(slplink);
 	slpmsg2->slpcall = slpmsg->slpcall;
 	slpmsg2->session_id = slpmsg->session_id;
-	msn_slpmsg_set_body(slpmsg2, (char *)body, sizeof(MsnWebcamData) + written);
+	msn_slpmsg_set_body(slpmsg2, body, body_len);
 	g_free(body);
 	msn_slplink_queue_slpmsg(slplink, slpmsg2);
 }
@@ -370,12 +399,11 @@ msn_webcam_recv_xml(MsnSlpLink *slplink,
 msn_webcam_recv_xml(MsnSlpLink *slplink, MsnSlpMessage *slpmsg, const guchar *body, gsize body_len)
 {
 	MsnSlpMessage *slpmsg2;
-	MsnWebcamData *request = (MsnWebcamData *)body;
 	gsize bytes_written;
 	gchar *xml;
 	gboolean is_producer = FALSE;
 
-	xml = g_convert((const gchar *)request->data, body_len - sizeof(MsnWebcamData),
+	xml = g_convert((const gchar *)body + WEBCAM_HEADER_LEN + sizeof(guint32), body_len - (WEBCAM_HEADER_LEN + sizeof(guint32)),
 	                "UTF-8", "UTF-16LE",
 	                NULL, &bytes_written, NULL);
 
@@ -460,17 +488,6 @@ msn_webcam_recv_xml(MsnSlpLink *slplink,
 		purple_media_add_remote_candidates(slpmsg->slpcall->media,
 				"msncam-recv", slplink->remote_user, candidates);
 	} else {
-#define WEBCAM_RECEIVER_REPLY \
-		/* magic string */ \
-		"\x80" \
-		"\xec\x00" \
-		"\x03" \
-		"\x08\x00" \
-		/* length of following */ \
-		"\x16\x00\x00\x00" \
-		/* actual data */ \
-		"r\0e\0c\0e\0i\0v\0e\0d\0V\0i\0e\0w\0e\0r\0D\0a\0t\0a\0\0\0"
-
 		slpmsg2 = msn_slpmsg_new(slplink);
 		slpmsg2->slpcall = slpmsg->slpcall;
 		slpmsg2->session_id = slpmsg->session_id;


More information about the Commits mailing list