soc.2010.msn-tlc: 9950ccdc: Use convenient p2p functions to avoid co...

masca at cpw.pidgin.im masca at cpw.pidgin.im
Fri Jun 4 21:35:49 EDT 2010


-----------------------------------------------------------------
Revision: 9950ccdc3ca0e19a4e7fa3081eedcf77a77182e6
Ancestor: 229545fc9eb3612a643b83a54e3b92a41a4474ca
Author: masca at cpw.pidgin.im
Date: 2010-06-04T00:21:00
Branch: im.pidgin.soc.2010.msn-tlc
URL: http://d.pidgin.im/viewmtn/revision/info/9950ccdc3ca0e19a4e7fa3081eedcf77a77182e6

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

ChangeLog: 

Use convenient p2p functions to avoid code here. There is a lot more code duplication to fix here.

-------------- next part --------------
============================================================
--- libpurple/protocols/msn/msg.c	d27d28b3d407f3900ab8c517b135a9e5a5e5dc08
+++ libpurple/protocols/msn/msg.c	e3fa0c8943473f05f85aa2e334670e0a2fd0a3b2
@@ -28,6 +28,7 @@
 #include "msn.h"
 #include "msg.h"
 #include "msnutils.h"
+#include "p2p.h"
 
 MsnMessage *
 msn_message_new(MsnMsgType type)
@@ -163,30 +164,27 @@ msn_message_parse_slp_body(MsnMessage *m
 void
 msn_message_parse_slp_body(MsnMessage *msg, const char *body, size_t len)
 {
-	MsnP2PHeader header;
+	MsnP2PHeader *header;
+	MsnP2PHeader wire;
 	const char *tmp;
 	int body_len;
 
 	tmp = body;
 
-	if (len < sizeof(header)) {
+	if (len < sizeof(wire)) {
 		g_return_if_reached();
 	}
 
 	/* Extract the binary SLP header */
-	memcpy(&header, tmp, sizeof(header));
-	tmp += sizeof(header);
+	memcpy(&wire, tmp, sizeof(wire));
+	tmp += sizeof(wire);
 
-	msg->msnslp_header.session_id = GUINT32_FROM_LE(header.session_id);
-	msg->msnslp_header.id         = GUINT32_FROM_LE(header.id);
-	msg->msnslp_header.offset     = GUINT64_FROM_LE(header.offset);
-	msg->msnslp_header.total_size = GUINT64_FROM_LE(header.total_size);
-	msg->msnslp_header.length     = GUINT32_FROM_LE(header.length);
-	msg->msnslp_header.flags      = GUINT32_FROM_LE(header.flags);
-	msg->msnslp_header.ack_id     = GUINT32_FROM_LE(header.ack_id);
-	msg->msnslp_header.ack_sub_id = GUINT32_FROM_LE(header.ack_sub_id);
-	msg->msnslp_header.ack_size   = GUINT64_FROM_LE(header.ack_size);
+	header = msn_p2p_header_from_wire(&wire);
 
+	memcpy(&msg->msnslp_header, (char*)header, sizeof(*header));
+
+	g_free(header);
+
 	/* Extract the body */
 	body_len = len - (tmp - body);
 	/* msg->body_len = msg->msnslp_header.length; */
@@ -298,7 +296,8 @@ msn_message_parse_payload(MsnMessage *ms
 	if (content_type != NULL &&
 		!strcmp(content_type, "application/x-msnmsgrp2p"))
 	{
-		MsnP2PHeader header;
+		MsnP2PHeader *header;
+		MsnP2PHeader wire;
 		MsnP2PFooter footer;
 		int body_len;
 
@@ -310,19 +309,15 @@ msn_message_parse_payload(MsnMessage *ms
 		msg->msnslp_message = TRUE;
 
 		/* Extract the binary SLP header */
-		memcpy(&header, tmp, sizeof(header));
-		tmp += sizeof(header);
+		memcpy(&wire, tmp, sizeof(wire));
+		tmp += sizeof(wire);
 
-		msg->msnslp_header.session_id = GUINT32_FROM_LE(header.session_id);
-		msg->msnslp_header.id         = GUINT32_FROM_LE(header.id);
-		msg->msnslp_header.offset     = GUINT64_FROM_LE(header.offset);
-		msg->msnslp_header.total_size = GUINT64_FROM_LE(header.total_size);
-		msg->msnslp_header.length     = GUINT32_FROM_LE(header.length);
-		msg->msnslp_header.flags      = GUINT32_FROM_LE(header.flags);
-		msg->msnslp_header.ack_id     = GUINT32_FROM_LE(header.ack_id);
-		msg->msnslp_header.ack_sub_id = GUINT32_FROM_LE(header.ack_sub_id);
-		msg->msnslp_header.ack_size   = GUINT64_FROM_LE(header.ack_size);
+		header = msn_p2p_header_from_wire(&wire);
 
+		memcpy(&msg->msnslp_header, (char*)header, sizeof(*header));
+
+		g_free(header);
+
 		body_len = payload_len - (tmp - tmp_base) - sizeof(footer);
 
 		/* Extract the body */
@@ -384,7 +379,7 @@ msn_message_gen_slp_body(MsnMessage *msg
 char *
 msn_message_gen_slp_body(MsnMessage *msg, size_t *ret_size)
 {
-	MsnP2PHeader header;
+	MsnP2PHeader *header;
 
 	char *tmp, *base;
 	const void *body;
@@ -398,19 +393,13 @@ msn_message_gen_slp_body(MsnMessage *msg
 
 	body = msn_message_get_bin_data(msg, &body_len);
 
-	header.session_id = GUINT32_TO_LE(msg->msnslp_header.session_id);
-	header.id         = GUINT32_TO_LE(msg->msnslp_header.id);
-	header.offset     = GUINT64_TO_LE(msg->msnslp_header.offset);
-	header.total_size = GUINT64_TO_LE(msg->msnslp_header.total_size);
-	header.length     = GUINT32_TO_LE(msg->msnslp_header.length);
-	header.flags      = GUINT32_TO_LE(msg->msnslp_header.flags);
-	header.ack_id     = GUINT32_TO_LE(msg->msnslp_header.ack_id);
-	header.ack_sub_id = GUINT32_TO_LE(msg->msnslp_header.ack_sub_id);
-	header.ack_size   = GUINT64_TO_LE(msg->msnslp_header.ack_size);
+	header = msn_p2p_header_to_wire(&(msg->msnslp_header));
 
-	memcpy(tmp, &header, 48);
+	memcpy(tmp, header, 48);
 	tmp += 48;
 
+	g_free(header);
+
 	if (body != NULL)
 	{
 		memcpy(tmp, body, body_len);
@@ -475,22 +464,16 @@ msn_message_gen_payload(MsnMessage *msg,
 
 	if (msg->msnslp_message)
 	{
-		MsnP2PHeader header;
+		MsnP2PHeader *header;
 		MsnP2PFooter footer;
 
-		header.session_id = GUINT32_TO_LE(msg->msnslp_header.session_id);
-		header.id         = GUINT32_TO_LE(msg->msnslp_header.id);
-		header.offset     = GUINT64_TO_LE(msg->msnslp_header.offset);
-		header.total_size = GUINT64_TO_LE(msg->msnslp_header.total_size);
-		header.length     = GUINT32_TO_LE(msg->msnslp_header.length);
-		header.flags      = GUINT32_TO_LE(msg->msnslp_header.flags);
-		header.ack_id     = GUINT32_TO_LE(msg->msnslp_header.ack_id);
-		header.ack_sub_id = GUINT32_TO_LE(msg->msnslp_header.ack_sub_id);
-		header.ack_size   = GUINT64_TO_LE(msg->msnslp_header.ack_size);
+		header = msn_p2p_header_to_wire(&(msg->msnslp_header));
 
-		memcpy(n, &header, 48);
+		memcpy(n, header, 48);
 		n += 48;
 
+		g_free(header);
+
 		if (body != NULL)
 		{
 			memcpy(n, body, body_len);


More information about the Commits mailing list