changeset 31120:e9b9d6ba2cff

merge of 'b37e581d0bfe6efa24595ece99a284dd51c08d78' and 'ddda3b9ca9b6cf8b06736f8b59b92683511117df'
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sun, 09 Jan 2011 04:54:17 +0000
parents 4b66ef54f6a3 (current diff) d143f52ae28e (diff)
children 98b37f61379c
files
diffstat 5 files changed, 69 insertions(+), 76 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/msn/directconn.c	Sat Jan 08 17:14:54 2011 +0000
+++ b/libpurple/protocols/msn/directconn.c	Sun Jan 09 04:54:17 2011 +0000
@@ -539,13 +539,11 @@
 msn_dc_enqueue_part(MsnDirectConn *dc, MsnSlpMessagePart *part)
 {
 	MsnDirectConnPacket *p;
-	guint32 length;
+	size_t length;
 
-	length = part->size + P2P_PACKET_HEADER_SIZE;
-	p = msn_dc_new_packet(length);
-
-	memcpy(p->data, part->header, P2P_PACKET_HEADER_SIZE);
-	memcpy(p->data + P2P_PACKET_HEADER_SIZE, part->buffer, part->size);
+	p = msn_dc_new_packet(0);
+	p->data = (guchar *)msn_slpmsgpart_serialize(part, &length);
+	p->length = length - P2P_PACKET_FOOTER_SIZE; /* DC doesn't need footer? */
 
 	p->sent_cb = msn_dc_send_packet_cb;
 	p->part = msn_slpmsgpart_ref(part);
--- a/libpurple/protocols/msn/slp.c	Sat Jan 08 17:14:54 2011 +0000
+++ b/libpurple/protocols/msn/slp.c	Sun Jan 09 04:54:17 2011 +0000
@@ -293,7 +293,7 @@
 gen_context(PurpleXfer *xfer, const char *file_name, const char *file_path)
 {
 	gsize size = 0;
-	MsnFileContext header;
+	MsnFileContext context;
 	gchar *u8 = NULL;
 	gchar *ret;
 	gunichar2 *uni = NULL;
@@ -323,28 +323,28 @@
 
 	preview = purple_xfer_get_thumbnail(xfer, &preview_len);
 
-	header.length = MSN_FILE_CONTEXT_SIZE;
-	header.version = 2; /* V.3 contains additional unnecessary data */
-	header.file_size = size;
+	context.length = MSN_FILE_CONTEXT_SIZE;
+	context.version = 2; /* V.3 contains additional unnecessary data */
+	context.file_size = size;
 	if (preview)
-		header.type = 0;
+		context.type = 0;
 	else
-		header.type = 1;
+		context.type = 1;
 
 	len = MIN(len, MAX_FILE_NAME_LEN);
 	for (currentChar = 0; currentChar < len; currentChar++) {
-		header.file_name[currentChar] = GUINT16_TO_LE(uni[currentChar]);
+		context.file_name[currentChar] = GUINT16_TO_LE(uni[currentChar]);
 	}
-	memset(&header.file_name[currentChar], 0x00, (MAX_FILE_NAME_LEN - currentChar) * 2);
+	memset(&context.file_name[currentChar], 0x00, (MAX_FILE_NAME_LEN - currentChar) * 2);
 
-	memset(&header.unknown1, 0, sizeof(header.unknown1));
-	header.unknown2 = 0xffffffff;
+	memset(&context.unknown1, 0, sizeof(context.unknown1));
+	context.unknown2 = 0xffffffff;
 
 	/* Mind the cast, as in, don't free it after! */
-	header.preview = (char *)preview;
-	header.preview_len = preview_len;
+	context.preview = (char *)preview;
+	context.preview_len = preview_len;
 
-	u8 = msn_file_context_to_wire(&header);
+	u8 = msn_file_context_to_wire(&context);
 	ret = purple_base64_encode((const guchar *)u8, MSN_FILE_CONTEXT_SIZE + preview_len);
 
 	g_free(uni);
--- a/libpurple/protocols/msn/slpcall.c	Sat Jan 08 17:14:54 2011 +0000
+++ b/libpurple/protocols/msn/slpcall.c	Sun Jan 09 04:54:17 2011 +0000
@@ -511,7 +511,7 @@
 		/* File Transfer */
 		PurpleAccount *account;
 		PurpleXfer *xfer;
-		MsnFileContext *header;
+		MsnFileContext *file_context;
 		char *buf;
 		gsize bin_len;
 		guint32 file_size;
@@ -528,12 +528,12 @@
 							 slpcall->slplink->remote_user);
 
 		buf = (char *)purple_base64_decode(context, &bin_len);
-		header = msn_file_context_from_wire(buf, bin_len);
+		file_context = msn_file_context_from_wire(buf, bin_len);
 
-		if (header != NULL) {
-			file_size = header->file_size;
+		if (file_context != NULL) {
+			file_size = file_context->file_size;
 
-			file_name = g_convert((const gchar *)&header->file_name,
+			file_name = g_convert((const gchar *)&file_context->file_name,
 			                      MAX_FILE_NAME_LEN * 2,
 			                      "UTF-8", "UTF-16LE",
 			                      NULL, NULL, NULL);
@@ -554,16 +554,16 @@
 
 			xfer->data = slpcall;
 
-			if (header->preview) {
-				purple_xfer_set_thumbnail(xfer, header->preview,
-				                          header->preview_len,
+			if (file_context->preview) {
+				purple_xfer_set_thumbnail(xfer, file_context->preview,
+				                          file_context->preview_len,
 				    					  "image/png");
-				g_free(header->preview);
+				g_free(file_context->preview);
 			}
 
 			purple_xfer_request(xfer);
 		}
-		g_free(header);
+		g_free(file_context);
 		g_free(buf);
 
 		accepted = TRUE;
@@ -1142,15 +1142,6 @@
 			slpcall->wasted = TRUE;
 		}
 	}
-#if 0
-	else if (slpmsg->header->flags == 0x100)
-	{
-		slpcall = slplink->directconn->initial_call;
-
-		if (slpcall != NULL)
-			msn_slpcall_session_init(slpcall);
-	}
-#endif
 	else if (slpmsg->header->flags == P2P_ACK)
 	{
 		/* Acknowledgement of previous message. Don't do anything currently. */
--- a/libpurple/protocols/msn/xfer.c	Sat Jan 08 17:14:54 2011 +0000
+++ b/libpurple/protocols/msn/xfer.c	Sun Jan 09 04:54:17 2011 +0000
@@ -162,25 +162,25 @@
 }
 
 gchar *
-msn_file_context_to_wire(MsnFileContext *header)
+msn_file_context_to_wire(MsnFileContext *context)
 {
 	gchar *ret, *tmp;
 
-	tmp = ret = g_new(gchar, MSN_FILE_CONTEXT_SIZE + header->preview_len + 1);
+	tmp = ret = g_new(gchar, MSN_FILE_CONTEXT_SIZE + context->preview_len + 1);
 
-	msn_push32le(tmp, header->length);
-	msn_push32le(tmp, header->version);
-	msn_push64le(tmp, header->file_size);
-	msn_push32le(tmp, header->type);
-	memcpy(tmp, header->file_name, MAX_FILE_NAME_LEN * 2);
+	msn_push32le(tmp, context->length);
+	msn_push32le(tmp, context->version);
+	msn_push64le(tmp, context->file_size);
+	msn_push32le(tmp, context->type);
+	memcpy(tmp, context->file_name, MAX_FILE_NAME_LEN * 2);
 	tmp += MAX_FILE_NAME_LEN * 2;
-	memcpy(tmp, header->unknown1, sizeof(header->unknown1));
-	tmp += sizeof(header->unknown1);
-	msn_push32le(tmp, header->unknown2);
-	if (header->preview) {
-		memcpy(tmp, header->preview, header->preview_len);
+	memcpy(tmp, context->unknown1, sizeof(context->unknown1));
+	tmp += sizeof(context->unknown1);
+	msn_push32le(tmp, context->unknown2);
+	if (context->preview) {
+		memcpy(tmp, context->preview, context->preview_len);
 	}
-	tmp[header->preview_len] = '\0';
+	tmp[context->preview_len] = '\0';
 
 	return ret;
 }
@@ -188,48 +188,48 @@
 MsnFileContext *
 msn_file_context_from_wire(const char *buf, gsize len)
 {
-	MsnFileContext *header;
+	MsnFileContext *context;
 
 	if (!buf || len < MSN_FILE_CONTEXT_SIZE)
 		return NULL;
 
-	header = g_new(MsnFileContext, 1);
+	context = g_new(MsnFileContext, 1);
 
-	header->length = msn_pop32le(buf);
-	header->version = msn_pop32le(buf);
-	if (header->version == 2) {
+	context->length = msn_pop32le(buf);
+	context->version = msn_pop32le(buf);
+	if (context->version == 2) {
 		/* The length field is broken for this version. No check. */
-		header->length = MSN_FILE_CONTEXT_SIZE;
-	} else if (header->version == 3) {
-		if (header->length != MSN_FILE_CONTEXT_SIZE + 63) {
-			g_free(header);
+		context->length = MSN_FILE_CONTEXT_SIZE;
+	} else if (context->version == 3) {
+		if (context->length != MSN_FILE_CONTEXT_SIZE + 63) {
+			g_free(context);
 			return NULL;
 		} else if (len < MSN_FILE_CONTEXT_SIZE + 63) {
-			g_free(header);
+			g_free(context);
 			return NULL;
 		}
 	} else {
-		purple_debug_warning("msn", "Received MsnFileContext with unknown version: %d\n", header->version);
-		g_free(header);
+		purple_debug_warning("msn", "Received MsnFileContext with unknown version: %d\n", context->version);
+		g_free(context);
 		return NULL;
 	}
 
-	header->file_size = msn_pop64le(buf);
-	header->type = msn_pop32le(buf);
-	memcpy(header->file_name, buf, MAX_FILE_NAME_LEN * 2);
+	context->file_size = msn_pop64le(buf);
+	context->type = msn_pop32le(buf);
+	memcpy(context->file_name, buf, MAX_FILE_NAME_LEN * 2);
 	buf += MAX_FILE_NAME_LEN * 2;
-	memcpy(header->unknown1, buf, sizeof(header->unknown1));
-	buf += sizeof(header->unknown1);
-	header->unknown2 = msn_pop32le(buf);
+	memcpy(context->unknown1, buf, sizeof(context->unknown1));
+	buf += sizeof(context->unknown1);
+	context->unknown2 = msn_pop32le(buf);
 
-	if (header->type == 0 && len > header->length) {
-		header->preview_len = len - header->length;
-		header->preview = g_memdup(buf, header->preview_len);
+	if (context->type == 0 && len > context->length) {
+		context->preview_len = len - context->length;
+		context->preview = g_memdup(buf, context->preview_len);
 	} else {
-		header->preview_len = 0;
-		header->preview = NULL;
+		context->preview_len = 0;
+		context->preview = NULL;
 	}
 
-	return header;
+	return context;
 }
 
--- a/libpurple/protocols/msn/xfer.h	Sat Jan 08 17:14:54 2011 +0000
+++ b/libpurple/protocols/msn/xfer.h	Sun Jan 09 04:54:17 2011 +0000
@@ -22,6 +22,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
  */
 
+#ifndef MSN_XFER_H
+#define MSN_XFER_H
 
 #include "slpcall.h"
 
@@ -56,8 +58,10 @@
 void msn_xfer_end_cb(MsnSlpCall *slpcall, MsnSession *session);
 
 gchar *
-msn_file_context_to_wire(MsnFileContext *header);
+msn_file_context_to_wire(MsnFileContext *context);
 
 MsnFileContext *
 msn_file_context_from_wire(const char *buf, gsize len);
 
+#endif /* MSN_XFER_H */
+