changeset 29815:3175b89c5156

Add support for recieving and sending MSN file transfer previews.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sun, 28 Feb 2010 04:14:15 +0000
parents 6d3a90b49dba
children d1d03fff1f62
files libpurple/protocols/msn/slp.c libpurple/protocols/msn/slplink.c
diffstat 2 files changed, 34 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/msn/slp.c	Sun Feb 28 04:07:39 2010 +0000
+++ b/libpurple/protocols/msn/slp.c	Sun Feb 28 04:14:15 2010 +0000
@@ -422,6 +422,11 @@
 
 			xfer->data = slpcall;
 
+			if (header->type == 0 && bin_len >= sizeof(MsnFileContext)) {
+				purple_xfer_set_thumbnail(xfer, &header->preview,
+				                          bin_len - sizeof(MsnFileContext));
+			}
+
 			purple_xfer_request(xfer);
 		}
 		g_free(header);
--- a/libpurple/protocols/msn/slplink.c	Sun Feb 28 04:07:39 2010 +0000
+++ b/libpurple/protocols/msn/slplink.c	Sun Feb 28 04:14:15 2010 +0000
@@ -662,15 +662,19 @@
 gen_context(PurpleXfer *xfer, const char *file_name, const char *file_path)
 {
 	gsize size = 0;
-	MsnFileContext header;
+	MsnFileContext *header;
 	gchar *u8 = NULL;
 	gchar *ret;
 	gunichar2 *uni = NULL;
 	glong currentChar = 0;
 	glong len = 0;
+	const char *preview;
+	gsize preview_len;
 
 	size = purple_xfer_get_size(xfer);
 
+	purple_xfer_prepare_thumbnail(xfer);
+
 	if (!file_name) {
 		gchar *basename = g_path_get_basename(file_path);
 		u8 = purple_utf8_try_convert(basename);
@@ -686,23 +690,37 @@
 		u8 = NULL;
 	}
 
-	header.length = GUINT32_TO_LE(sizeof(MsnFileContext) - 1);
-	header.version = GUINT32_TO_LE(2); /* V.3 contains additional unnecessary data */
-	header.file_size = GUINT64_TO_LE(size);
-	header.type = GUINT32_TO_LE(1);    /* No file preview */
+	preview = purple_xfer_get_thumbnail_data(xfer);
+	if (preview)
+		preview_len = purple_xfer_get_thumbnail_size(xfer);
+	else
+		preview_len = 0;
+	header = g_malloc(sizeof(MsnFileContext) + preview_len);
+
+	header->length = GUINT32_TO_LE(sizeof(MsnFileContext) - 1);
+	header->version = GUINT32_TO_LE(2); /* V.3 contains additional unnecessary data */
+	header->file_size = GUINT64_TO_LE(size);
+	if (preview)
+		header->type = GUINT32_TO_LE(0);
+	else
+		header->type = GUINT32_TO_LE(1);
 
 	len = MIN(len, MAX_FILE_NAME_LEN);
 	for (currentChar = 0; currentChar < len; currentChar++) {
-		header.file_name[currentChar] = GUINT16_TO_LE(uni[currentChar]);
+		header->file_name[currentChar] = GUINT16_TO_LE(uni[currentChar]);
 	}
-	memset(&header.file_name[currentChar], 0x00, (MAX_FILE_NAME_LEN - currentChar) * 2);
+	memset(&header->file_name[currentChar], 0x00, (MAX_FILE_NAME_LEN - currentChar) * 2);
 
-	memset(&header.unknown1, 0, sizeof(header.unknown1));
-	header.unknown2 = GUINT32_TO_LE(0xffffffff);
-	header.preview[0] = '\0';
+	memset(&header->unknown1, 0, sizeof(header->unknown1));
+	header->unknown2 = GUINT32_TO_LE(0xffffffff);
+	if (preview) {
+		memcpy(&header->preview, preview, preview_len);
+	}
+	header->preview[preview_len] = '\0';
 
 	g_free(uni);
-	ret = purple_base64_encode((const guchar *)&header, sizeof(MsnFileContext));
+	ret = purple_base64_encode((const guchar *)header, sizeof(MsnFileContext) + preview_len);
+	g_free(header);
 	return ret;
 }