pidgin.vv.msn.webcam: 2385cb91: I don't really like this weird pointer a...

qulogic at pidgin.im qulogic at pidgin.im
Sat Feb 6 01:26:55 EST 2010


-----------------------------------------------------------------
Revision: 2385cb917e9b93d500c582293b6c3102cc5d60cf
Ancestor: f58d536d352f197d779da5a6ce4d253f9275c17e
Author: qulogic at pidgin.im
Date: 2010-01-31T00:19:51
Branch: im.pidgin.pidgin.vv.msn.webcam
URL: http://d.pidgin.im/viewmtn/revision/info/2385cb917e9b93d500c582293b6c3102cc5d60cf

Modified files:
        libpurple/protocols/msn/webcam.c

ChangeLog: 

I don't really like this weird pointer arithmetic. Not too sure what each
of the fields mean, but it looks better to use a struct here.

-------------- next part --------------
============================================================
--- libpurple/protocols/msn/webcam.c	a616f0a741c06d3601155b72b3e8304a40279d7d
+++ libpurple/protocols/msn/webcam.c	b464abac71aa16a3be0c95bc6d3880d743554df8
@@ -37,6 +37,16 @@
 #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;
+
 static void
 msn_webcam_session_init_cb(MsnSlpCall *slpcall)
 {
@@ -170,8 +180,7 @@ msn_webcam_send_syn(MsnSlpCall *slpcall,
 msn_webcam_send_syn(MsnSlpCall *slpcall, const gchar *content)
 {
 	MsnSlpMessage *slpmsg;
-	gchar *body;
-	guint16 *r;
+	MsnWebcamData *body;
 
 	/*
 	 * The SlpCall object has a different instance here,
@@ -202,16 +211,20 @@ msn_webcam_send_syn(MsnSlpCall *slpcall,
 	}
 	g_list_free(iter);
 
-	body = g_memdup("\x80\x00\x00\x01\x08\x00\x08\x00\x00\x00"
-			"s\x00y\x00n\x00\x00\x00", 18);
-	r = (guint16*)(body+1);
-	*r = GINT16_TO_LE(rand() % 0xFFFF0000);
+	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);
 
 	slpmsg = msn_slpmsg_new(slpcall->slplink);
 	slpmsg->slpcall = slpcall;
 
 	slpmsg->session_id = slpcall->session_id;
-	msn_slpmsg_set_body(slpmsg, body, 18);
+	msn_slpmsg_set_body(slpmsg, (char *)body, 18);
 	g_free(body);
 	msn_slplink_queue_slpmsg(slpcall->slplink, slpmsg);
 }
@@ -220,12 +233,18 @@ msn_webcam_send_ack(MsnSlpLink *slplink,
 msn_webcam_send_ack(MsnSlpLink *slplink, MsnSlpMessage *slpmsg)
 {
 	MsnSlpMessage *slpmsg2;
-	gchar *body = g_memdup("\x80\xea\00\x00\x08\x00\x08\x00\x00\0"
-			"a\0c\0k\x00\x00\x00", 18);
+	MsnWebcamData *body = g_memdup("\x80"
+	                               "\xea\00"
+	                               "\x00"
+	                               "\x08\x00"
+	                               "\x08\x00\x00\x00"
+	                               "a\0c\x00k\x00\x00\x00",
+	                               18);
+
 	slpmsg2 = msn_slpmsg_new(slplink);
 	slpmsg2->slpcall = slpmsg->slpcall;
 	slpmsg2->session_id = slpmsg->session_id;
-	msn_slpmsg_set_body(slpmsg2, body, 18);
+	msn_slpmsg_set_body(slpmsg2, (char *)body, 18);
 	g_free(body);
 	msn_slplink_queue_slpmsg(slplink, slpmsg2);
 	purple_media_stream_info(slpmsg->slpcall->media,
@@ -246,8 +265,7 @@ msn_webcam_send_xml(MsnSlpLink *slplink,
 	guint count = 1;
 
 	gsize written;
-	gchar *body;
-	guint32 *len;
+	MsnWebcamData *body;
 	gboolean is_producer = FALSE;
 
 	/* Get candidates */
@@ -331,17 +349,19 @@ msn_webcam_send_xml(MsnSlpLink *slplink,
 	g_free(xml);
 	written += 2;
 
-	body = g_malloc(written + 10);
-	memcpy(body, "\x80\x00\x00\x00\x08\x00", 6);
-	len = (guint32*)(body+6);
-	*len = GUINT32_TO_LE(written);
-	memcpy(body + 10, xmlutf, written);
+	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);
 	g_free(xmlutf);
 
 	slpmsg2 = msn_slpmsg_new(slplink);
 	slpmsg2->slpcall = slpmsg->slpcall;
 	slpmsg2->session_id = slpmsg->session_id;
-	msn_slpmsg_set_body(slpmsg2, body, written + 10);
+	msn_slpmsg_set_body(slpmsg2, (char *)body, sizeof(MsnWebcamData) + written);
 	g_free(body);
 	msn_slplink_queue_slpmsg(slplink, slpmsg2);
 }
@@ -350,13 +370,16 @@ 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 = g_convert((const gchar *)body + 5, body_len - 5,
-	                       "UTF-8", "UTF-16LE",
-	                       NULL, &bytes_written, NULL);
-	gchar *body_str;
+	gchar *xml;
+	MsnWebcamData *reply;
 	gboolean is_producer = FALSE;
 
+	xml = g_convert((const gchar *)request->data, body_len - sizeof(MsnWebcamData),
+	                "UTF-8", "UTF-16LE",
+	                NULL, &bytes_written, NULL);
+
 	if (!strncmp(xml, "<producer>", 10))
 		is_producer = TRUE;
 
@@ -441,12 +464,19 @@ msn_webcam_recv_xml(MsnSlpLink *slplink,
 		slpmsg2 = msn_slpmsg_new(slplink);
 		slpmsg2->slpcall = slpmsg->slpcall;
 		slpmsg2->session_id = slpmsg->session_id;
-		body_str = g_memdup(
-				"\x80\xec\x00\x03\x08\x00" /* magic string */
-				"\x16\0\0\0"		/* length of following */
-				"r\0e\0c\0e\0i\0v\0e\0d\0V\0i\0e\0w\0e\0r\0D\0a\0t\0a\0\0\0", 48);
-		msn_slpmsg_set_body(slpmsg2, body_str, 48);
-		g_free(body_str);
+		reply = (MsnWebcamData *)g_memdup(
+				/* 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",
+				48);
+		msn_slpmsg_set_body(slpmsg2, (char *)reply, 48);
+		g_free(reply);
 		msn_slplink_queue_slpmsg(slplink, slpmsg2);
 	}
 	g_free(xml);


More information about the Commits mailing list