changeset 30858:2d00d29a45fd

Process SlpMessageParts, a sequence of parts will generate a SlpMessage.
author masca@cpw.pidgin.im
date Thu, 29 Jul 2010 00:12:54 +0000
parents 1ded0bc5c911
children 2c2ca0aed68e
files libpurple/protocols/msn/directconn.c libpurple/protocols/msn/msg.c libpurple/protocols/msn/slplink.c libpurple/protocols/msn/slplink.h
diffstat 4 files changed, 19 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/msn/directconn.c	Wed Jul 28 20:35:28 2010 +0000
+++ b/libpurple/protocols/msn/directconn.c	Thu Jul 29 00:12:54 2010 +0000
@@ -591,6 +591,8 @@
 static int
 msn_dc_process_packet(MsnDirectConn *dc, guint32 packet_length)
 {
+	MsnSlpMessagePart *part;
+
 	g_return_val_if_fail(dc != NULL, DC_PROCESS_ERROR);
 
 	switch (dc->state) {
@@ -627,12 +629,9 @@
 		break;
 
 	case DC_STATE_ESTABLISHED:
-		msn_slplink_process_msg(
-			dc->slplink,
-			&dc->header,
-			dc->in_buffer + 4 + P2P_PACKET_HEADER_SIZE,
-			dc->header.length
-		);
+
+		part = msn_slpmsgpart_new_from_data(dc->in_buffer, dc->header.length);
+		msn_slplink_process_msg(dc->slplink, part);
 
 		/*
 		if (dc->num_calls == 0) {
--- a/libpurple/protocols/msn/msg.c	Wed Jul 28 20:35:28 2010 +0000
+++ b/libpurple/protocols/msn/msg.c	Thu Jul 29 00:12:54 2010 +0000
@@ -943,10 +943,7 @@
 	data = msn_message_get_bin_data(msg, &len);
 
 	if (msg->part) {
-		len -= P2P_PACKET_HEADER_SIZE;
-		len -= P2P_PACKET_FOOTER_SIZE;
-
-		msn_slplink_process_msg(slplink, msg->part->header, data+P2P_PACKET_HEADER_SIZE, len);
+		msn_slplink_process_msg(slplink, msg->part);
 	}
 	else /* This should never happen. */
 		purple_debug_fatal("msn", "P2P message without a Part.\n");
--- a/libpurple/protocols/msn/slplink.c	Wed Jul 28 20:35:28 2010 +0000
+++ b/libpurple/protocols/msn/slplink.c	Thu Jul 29 00:12:54 2010 +0000
@@ -569,11 +569,14 @@
 }
 
 void
-msn_slplink_process_msg(MsnSlpLink *slplink, MsnP2PHeader *header, const char *data, gsize len)
+msn_slplink_process_msg(MsnSlpLink *slplink, MsnSlpMessagePart *part)
 {
 	MsnSlpMessage *slpmsg;
+	MsnP2PHeader *header;
 	guint64 offset;
 
+	header = part->header;
+
 	if (header->total_size < header->length)
 	{
 		/* We seem to have received a bad header */
@@ -600,20 +603,22 @@
 	if (slpmsg->ft)
 	{
 		slpmsg->slpcall->u.incoming_data =
-				g_byte_array_append(slpmsg->slpcall->u.incoming_data, (const guchar *)data, len);
+				g_byte_array_append(slpmsg->slpcall->u.incoming_data, (const guchar *)part->buffer, part->size);
 		purple_xfer_prpl_ready(slpmsg->slpcall->xfer);
 	}
 	else if (slpmsg->size && slpmsg->buffer)
 	{
-		if (G_MAXSIZE - len < offset || (offset + len) > slpmsg->size || slpmsg->offset != offset)
+		if (G_MAXSIZE - part->size < offset
+				|| (offset + part->size) > slpmsg->size
+				|| slpmsg->offset != offset)
 		{
 			purple_debug_error("msn",
 				"Oversized slpmsg - msgsize=%lld offset=%" G_GUINT64_FORMAT " len=%" G_GSIZE_FORMAT "\n",
-				slpmsg->size, offset, len);
+				slpmsg->size, offset, part->size);
 			g_return_if_reached();
 		} else {
-			memcpy(slpmsg->buffer + offset, data, len);
-			slpmsg->offset += len;
+			memcpy(slpmsg->buffer + offset, part->buffer, part->size);
+			slpmsg->offset += part->size;
 		}
 	}
 
@@ -627,7 +632,7 @@
 		if (slpmsg->slpcall->progress_cb != NULL)
 		{
 			slpmsg->slpcall->progress_cb(slpmsg->slpcall, slpmsg->size,
-										 len, offset);
+										 part->size, offset);
 		}
 	}
 
--- a/libpurple/protocols/msn/slplink.h	Wed Jul 28 20:35:28 2010 +0000
+++ b/libpurple/protocols/msn/slplink.h	Thu Jul 29 00:12:54 2010 +0000
@@ -79,7 +79,7 @@
 void msn_slplink_send_slpmsg(MsnSlpLink *slplink,
 							 MsnSlpMessage *slpmsg);
 void msn_slplink_send_queued_slpmsgs(MsnSlpLink *slplink);
-void msn_slplink_process_msg(MsnSlpLink *slplink, MsnP2PHeader *header, const char *data, gsize len);
+void msn_slplink_process_msg(MsnSlpLink *slplink, MsnSlpMessagePart *part);
 
 /* Only exported for msn_xfer_write */
 void msn_slplink_send_msgpart(MsnSlpLink *slplink, MsnSlpMessage *slpmsg);