changeset 32288:f0b5a6f8fded

Add support for file context v0, which is used by older official MSN clients on Macs.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sun, 16 Oct 2011 00:15:40 +0000
parents b2b704d658da
children 8b7c7c6bf985
files ChangeLog libpurple/protocols/msn/slp.c libpurple/protocols/msn/xfer.c libpurple/protocols/msn/xfer.h
diffstat 4 files changed, 31 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Oct 16 00:03:52 2011 +0000
+++ b/ChangeLog	Sun Oct 16 00:15:40 2011 +0000
@@ -16,6 +16,9 @@
 	* Better handling of "invisible" and "chatty" statuses. (Tomasz
 	  Wasilczyk) (#13836)
 
+	MSN:
+	* Fix file transfer with older Mac MSN clients.
+
 	MXit:
 	* Remove all reference to Hidden Number.
 	* Fix decoding of font-size changes in the markup of received messages.
--- a/libpurple/protocols/msn/slp.c	Sun Oct 16 00:03:52 2011 +0000
+++ b/libpurple/protocols/msn/slp.c	Sun Oct 16 00:15:40 2011 +0000
@@ -322,7 +322,7 @@
 
 	preview = purple_xfer_get_thumbnail(xfer, &preview_len);
 
-	context.length = MSN_FILE_CONTEXT_SIZE;
+	context.length = MSN_FILE_CONTEXT_SIZE_V2;
 	context.version = 2; /* V.3 contains additional unnecessary data */
 	context.file_size = size;
 	if (preview)
@@ -346,7 +346,7 @@
 	context.preview_len = preview_len;
 
 	u8 = msn_file_context_to_wire(&context);
-	ret = purple_base64_encode((const guchar *)u8, MSN_FILE_CONTEXT_SIZE + preview_len);
+	ret = purple_base64_encode((const guchar *)u8, MSN_FILE_CONTEXT_SIZE_V2 + preview_len);
 
 	g_free(uni);
 	g_free(u8);
--- a/libpurple/protocols/msn/xfer.c	Sun Oct 16 00:03:52 2011 +0000
+++ b/libpurple/protocols/msn/xfer.c	Sun Oct 16 00:15:40 2011 +0000
@@ -166,7 +166,7 @@
 {
 	gchar *ret, *tmp;
 
-	tmp = ret = g_new(gchar, MSN_FILE_CONTEXT_SIZE + context->preview_len + 1);
+	tmp = ret = g_new(gchar, MSN_FILE_CONTEXT_SIZE_V2 + context->preview_len + 1);
 
 	msn_push32le(tmp, context->length);
 	msn_push32le(tmp, context->version);
@@ -196,21 +196,30 @@
 {
 	MsnFileContext *context;
 
-	if (!buf || len < MSN_FILE_CONTEXT_SIZE)
+	if (!buf || len < MSN_FILE_CONTEXT_SIZE_V0)
 		return NULL;
 
 	context = g_new(MsnFileContext, 1);
 
 	context->length = msn_pop32le(buf);
 	context->version = msn_pop32le(buf);
-	if (context->version == 2) {
-		/* The length field is broken for this version. No check. */
-		context->length = MSN_FILE_CONTEXT_SIZE;
-	} else if (context->version == 3) {
-		if (context->length != MSN_FILE_CONTEXT_SIZE + 63) {
+	if (context->version == 0) {
+		if (context->length != MSN_FILE_CONTEXT_SIZE_V0) {
 			g_free(context);
 			return NULL;
-		} else if (len < MSN_FILE_CONTEXT_SIZE + 63) {
+		}
+	} else if (context->version == 2) {
+		/* The length field is broken for this version. No check. */
+		context->length = MSN_FILE_CONTEXT_SIZE_V2;
+		if (len < MSN_FILE_CONTEXT_SIZE_V2) {
+			g_free(context);
+			return NULL;
+		}
+	} else if (context->version == 3) {
+		if (context->length != MSN_FILE_CONTEXT_SIZE_V3) {
+			g_free(context);
+			return NULL;
+		} else if (len < MSN_FILE_CONTEXT_SIZE_V3) {
 			g_free(context);
 			return NULL;
 		}
@@ -224,13 +233,15 @@
 	context->type = msn_pop32le(buf);
 	memcpy(context->file_name, buf, MAX_FILE_NAME_LEN * 2);
 	buf += MAX_FILE_NAME_LEN * 2;
+	if (context->version > 0) {
 #if 0
-	memcpy(context->unknown1, buf, sizeof(context->unknown1));
-	buf += sizeof(context->unknown1);
-	context->unknown2 = msn_pop32le(buf);
+		memcpy(context->unknown1, buf, sizeof(context->unknown1));
+		buf += sizeof(context->unknown1);
+		context->unknown2 = msn_pop32le(buf);
 #else
-	buf += sizeof(gchar[30]) + sizeof(guint32);
+		buf += sizeof(gchar[30]) + sizeof(guint32);
 #endif
+	}
 
 	if (context->type == 0 && len > context->length) {
 		context->preview_len = len - context->length;
--- a/libpurple/protocols/msn/xfer.h	Sun Oct 16 00:03:52 2011 +0000
+++ b/libpurple/protocols/msn/xfer.h	Sun Oct 16 00:15:40 2011 +0000
@@ -47,7 +47,9 @@
 	gsize     preview_len;
 } MsnFileContext;
 
-#define MSN_FILE_CONTEXT_SIZE (4*4 + 1*8 + 2*MAX_FILE_NAME_LEN + 30)
+#define MSN_FILE_CONTEXT_SIZE_V0 (4*3 + 1*8 + 2*MAX_FILE_NAME_LEN)
+#define MSN_FILE_CONTEXT_SIZE_V2 (MSN_FILE_CONTEXT_SIZE_V0 + 4*1 + 30)
+#define MSN_FILE_CONTEXT_SIZE_V3 (MSN_FILE_CONTEXT_SIZE_V2 + 63)
 
 void msn_xfer_init(PurpleXfer *xfer);
 void msn_xfer_cancel(PurpleXfer *xfer);