pidgin: 753113a1: Change SLP P2P functions to use the new ...

qulogic at pidgin.im qulogic at pidgin.im
Fri Dec 17 04:11:22 EST 2010


----------------------------------------------------------------------
Revision: 753113a148c133b26f36171d552fcbde0a35c27f
Parent:   4a92dc84a2b6298d5faac46328cd78b951e804a5
Author:   qulogic at pidgin.im
Date:     12/17/10 02:49:47
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/753113a148c133b26f36171d552fcbde0a35c27f

Changelog: 

Change SLP P2P functions to use the new buffer access functions
instead of mapping to a struct. I don't mind this since it's limited
to just one pair of functions. This means that we don't need to use
any packing there.

Refs #12856.

Changes against parent 4a92dc84a2b6298d5faac46328cd78b951e804a5

  patched  libpurple/protocols/msn/directconn.c
  patched  libpurple/protocols/msn/p2p.c
  patched  libpurple/protocols/msn/p2p.h
  patched  libpurple/protocols/msn/slpmsg.c
  patched  libpurple/protocols/msn/slpmsg_part.c

-------------- next part --------------
============================================================
--- libpurple/protocols/msn/directconn.c	87ef3cddffb1ad7fc0f5f0498a1e263d026aaab7
+++ libpurple/protocols/msn/directconn.c	7a76dbe79a1ed015eaa07b804c0095bb34fdd34d
@@ -447,11 +447,11 @@ msn_dc_send_handshake_with_nonce(MsnDire
 {
 	const gchar *h;
 
-	h = (gchar*)  msn_p2p_header_to_wire(&dc->header);
+	h = msn_p2p_header_to_wire(&dc->header);
 
 	memcpy(p->data, h, P2P_PACKET_HEADER_SIZE);
 
-	memcpy(p->data + offsetof(MsnP2PHeader, ack_id), dc->nonce, 16);
+	memcpy(p->data + P2P_HEADER_ACK_ID_OFFSET, dc->nonce, 16);
 
 	msn_dc_enqueue_packet(dc, p);
 }
@@ -495,7 +495,7 @@ msn_dc_verify_handshake(MsnDirectConn *d
 	if (packet_length != P2P_PACKET_HEADER_SIZE)
 		return FALSE;
 
-	memcpy(nonce, dc->in_buffer + 4 + offsetof(MsnP2PHeader, ack_id), 16);
+	memcpy(nonce, dc->in_buffer + 4 + P2P_HEADER_ACK_ID_OFFSET, 16);
 
 	if (dc->nonce_type == DC_NONCE_PLAIN) {
 		if (memcmp(dc->nonce, nonce, 16) == 0) {
@@ -676,14 +676,11 @@ msn_dc_recv_cb(gpointer data, gint fd, P
 
 		if (dc->state != DC_STATE_FOO) {
 			MsnP2PHeader *context;
-			MsnP2PHeader *h;
 			
 			/* Skip packet size */
-			context = (MsnP2PHeader *)(dc->in_buffer + 4);
-
-			h = msn_p2p_header_from_wire(context);
-			memcpy(&dc->header, h, P2P_PACKET_HEADER_SIZE);
-			g_free(h);
+			context = msn_p2p_header_from_wire(dc->in_buffer + 4);
+			memcpy(&dc->header, context, P2P_PACKET_HEADER_SIZE);
+			g_free(context);
 		}
 
 		switch (msn_dc_process_packet(dc, packet_length)) {
============================================================
--- libpurple/protocols/msn/slpmsg.c	49bb900b84c8619414ada554c7b2df7f77e27267
+++ libpurple/protocols/msn/slpmsg.c	4460cae842dfca65bbd6a9d801e570e4641e40c0
@@ -263,21 +263,21 @@ char *msn_slpmsg_serialize(MsnSlpMessage
 
 char *msn_slpmsg_serialize(MsnSlpMessage *slpmsg, size_t *ret_size)
 {
-	MsnP2PHeader *header;
-	MsnP2PFooter *footer;
+	char *header;
+	char *footer;
 	char *base;
 	char *tmp;
 	size_t siz;
 
-	base = g_malloc(P2P_PACKET_HEADER_SIZE + slpmsg->size + sizeof(MsnP2PFooter));
+	base = g_malloc(P2P_PACKET_HEADER_SIZE + slpmsg->size + P2P_PACKET_FOOTER_SIZE);
 	tmp = base;
 
 	header = msn_p2p_header_to_wire(slpmsg->header);
 	footer = msn_p2p_footer_to_wire(slpmsg->footer);
 
-	siz = sizeof(MsnP2PHeader);
+	siz = P2P_PACKET_HEADER_SIZE;
 	/* Copy header */
-	memcpy(tmp, (char*)header, siz);
+	memcpy(tmp, header, siz);
 	tmp += siz;
 
 	/* Copy body */
@@ -285,8 +285,8 @@ char *msn_slpmsg_serialize(MsnSlpMessage
 	tmp += slpmsg->size;
 
 	/* Copy footer */
-	siz = sizeof(MsnP2PFooter);
-	memcpy(tmp, (char*)footer, siz);
+	siz = P2P_PACKET_FOOTER_SIZE;
+	memcpy(tmp, footer, siz);
 	tmp += siz;
 
 	*ret_size = tmp - base;
============================================================
--- libpurple/protocols/msn/p2p.h	dde9e26e6a6aafd26d22446e7c952d0745c0be59
+++ libpurple/protocols/msn/p2p.h	0c62eb6798172049d9e43bc0ee4471fee08ab378
@@ -25,8 +25,6 @@
 #ifndef MSN_P2P_H
 #define MSN_P2P_H
 
-
-#pragma pack(push,1)
 typedef struct {
 	guint32 session_id;
 	guint32 id;
@@ -45,21 +43,23 @@ typedef struct {
 	guint64 ack_size;
 /*	guint8  body[1]; */
 } MsnP2PHeader;
-#pragma pack(pop)
+#define P2P_PACKET_HEADER_SIZE (6 * 4 + 3 * 8)
 
-#pragma pack(push,1)
+/* Used for DCs to store nonces */
+#define P2P_HEADER_ACK_ID_OFFSET (2*4 + 2*8 + 2*4)
+
 typedef struct {
 	guint8  header_len;
 	guint8  opcode;
 	guint16 message_len;
 	guint32 base_id;
 } MsnP2Pv2Header;
-#pragma pack(pop)
 
 typedef struct
 {
 	guint32 value;
 } MsnP2PFooter;
+#define P2P_PACKET_FOOTER_SIZE (1 * 4)
 
 typedef enum
 {
@@ -91,19 +91,16 @@ typedef enum
 	P2P_APPID_DISPLAY   = 0xC         /**< Display Image */
 } MsnP2PAppId;
 
-#define P2P_PACKET_HEADER_SIZE sizeof(MsnP2PHeader)
-#define P2P_PACKET_FOOTER_SIZE sizeof(MsnP2PFooter)
-
 MsnP2PHeader *
-msn_p2p_header_from_wire(MsnP2PHeader *wire);
+msn_p2p_header_from_wire(const char *wire);
 
-MsnP2PHeader *
+char *
 msn_p2p_header_to_wire(MsnP2PHeader *header);
 
 MsnP2PFooter *
-msn_p2p_footer_from_wire(MsnP2PFooter *wire);
+msn_p2p_footer_from_wire(const char *wire);
 
-MsnP2PFooter *
+char *
 msn_p2p_footer_to_wire(MsnP2PFooter *footer);
 
 gboolean
============================================================
--- libpurple/protocols/msn/p2p.c	c4b5571a0103df63796951b1850ba67c7a8f0027
+++ libpurple/protocols/msn/p2p.c	11673bae5e569ec2cdf8311695f88786451a773a
@@ -25,68 +25,71 @@
 #include "internal.h"
 
 #include "p2p.h"
+#include "msnutils.h"
 
 MsnP2PHeader *
-msn_p2p_header_from_wire(MsnP2PHeader *wire)
+msn_p2p_header_from_wire(const char *wire)
 {
 	MsnP2PHeader *header;
 
 	header = g_new(MsnP2PHeader, 1);
 
-	header->session_id = GUINT32_FROM_LE(wire->session_id);
-	header->id         = GUINT32_FROM_LE(wire->id);
-	header->offset     = GUINT64_FROM_LE(wire->offset);
-	header->total_size = GUINT64_FROM_LE(wire->total_size);
-	header->length     = GUINT32_FROM_LE(wire->length);
-	header->flags      = GUINT32_FROM_LE(wire->flags);
-	header->ack_id     = GUINT32_FROM_LE(wire->ack_id);
-	header->ack_sub_id = GUINT32_FROM_LE(wire->ack_sub_id);
-	header->ack_size   = GUINT64_FROM_LE(wire->ack_size);
+	header->session_id = msn_pop32le(wire);
+	header->id         = msn_pop32le(wire);
+	header->offset     = msn_pop64le(wire);
+	header->total_size = msn_pop64le(wire);
+	header->length     = msn_pop32le(wire);
+	header->flags      = msn_pop32le(wire);
+	header->ack_id     = msn_pop32le(wire);
+	header->ack_sub_id = msn_pop32le(wire);
+	header->ack_size   = msn_pop64le(wire);
 
 	return header;
 }
 
-MsnP2PHeader *
+char *
 msn_p2p_header_to_wire(MsnP2PHeader *header)
 {
-	MsnP2PHeader *wire;
+	char *wire;
+	char *tmp;
 	
-	wire = g_new(MsnP2PHeader, 1);
+	tmp = wire = g_new(char, P2P_PACKET_HEADER_SIZE);
 
-	wire->session_id = GUINT32_TO_LE(header->session_id);
-	wire->id         = GUINT32_TO_LE(header->id);
-	wire->offset     = GUINT64_TO_LE(header->offset);
-	wire->total_size = GUINT64_TO_LE(header->total_size);
-	wire->length     = GUINT32_TO_LE(header->length);
-	wire->flags      = GUINT32_TO_LE(header->flags);
-	wire->ack_id     = GUINT32_TO_LE(header->ack_id);
-	wire->ack_sub_id = GUINT32_TO_LE(header->ack_sub_id);
-	wire->ack_size   = GUINT64_TO_LE(header->ack_size);
+	msn_push32le(tmp, header->session_id);
+	msn_push32le(tmp, header->id);
+	msn_push64le(tmp, header->offset);
+	msn_push64le(tmp, header->total_size);
+	msn_push32le(tmp, header->length);
+	msn_push32le(tmp, header->flags);
+	msn_push32le(tmp, header->ack_id);
+	msn_push32le(tmp, header->ack_sub_id);
+	msn_push64le(tmp, header->ack_size);
 
 	return wire;
 
 }
 
 MsnP2PFooter *
-msn_p2p_footer_from_wire(MsnP2PFooter *wire)
+msn_p2p_footer_from_wire(const char *wire)
 {
 	MsnP2PFooter *footer;
 
 	footer = g_new(MsnP2PFooter, 1);
 
-	footer->value = GUINT32_FROM_BE(wire->value);
+	footer->value = msn_pop32be(wire);
 
 	return footer;
 }
 
-MsnP2PFooter *
+char *
 msn_p2p_footer_to_wire(MsnP2PFooter *footer)
 {
-	MsnP2PFooter *wire;
+	char *wire;
+	char *tmp;
 
-	wire = g_new(MsnP2PFooter, 1);
+	tmp = wire = g_new(char, P2P_PACKET_FOOTER_SIZE);
 
-	wire->value = GUINT32_TO_BE(footer->value);
+	msn_push32be(tmp, footer->value);
 
 	return wire;
 }
@@ -98,3 +101,4 @@ msn_p2p_msg_is_data(const MsnP2PHeaderFl
 	        flags == (P2P_WLM2009_COMP | P2P_MSN_OBJ_DATA) ||
 	        flags == P2P_FILE_DATA);
 }
+
============================================================
--- libpurple/protocols/msn/slpmsg_part.c	2101e8a6f5d9d4680eafaed0960eb95d60b43df8
+++ libpurple/protocols/msn/slpmsg_part.c	d4232974551e15dbfed62e577ba7d9f9fb4f9349
@@ -60,7 +60,7 @@ MsnSlpMessagePart *msn_slpmsgpart_new_fr
 	tmp = data;
 
 	/* Extract the binary SLP header */
-	part->header = msn_p2p_header_from_wire((MsnP2PHeader*)tmp);
+	part->header = msn_p2p_header_from_wire(tmp);
 	tmp += P2P_PACKET_HEADER_SIZE;
 
 	/* Extract the body */
@@ -76,7 +76,7 @@ MsnSlpMessagePart *msn_slpmsgpart_new_fr
 
 	/* Extract the footer */
 	if (body_len >= 0) 
-		part->footer = msn_p2p_footer_from_wire((MsnP2PFooter*)tmp);
+		part->footer = msn_p2p_footer_from_wire(tmp);
 
 	return part;
 }
@@ -136,21 +136,21 @@ char *msn_slpmsgpart_serialize(MsnSlpMes
 
 char *msn_slpmsgpart_serialize(MsnSlpMessagePart *part, size_t *ret_size)
 {
-	MsnP2PHeader *header;
-	MsnP2PFooter *footer;
+	char *header;
+	char *footer;
 	char *base;
 	char *tmp;
 	size_t siz;
 
-	base = g_malloc(P2P_PACKET_HEADER_SIZE + part->size + sizeof(MsnP2PFooter));
+	base = g_malloc(P2P_PACKET_HEADER_SIZE + part->size + P2P_PACKET_FOOTER_SIZE);
 	tmp = base;
 
 	header = msn_p2p_header_to_wire(part->header);
 	footer = msn_p2p_footer_to_wire(part->footer);
 
-	siz = sizeof(MsnP2PHeader);
+	siz = P2P_PACKET_HEADER_SIZE;
 	/* Copy header */
-	memcpy(tmp, (char*)header, siz);
+	memcpy(tmp, header, siz);
 	tmp += siz;
 
 	/* Copy body */
@@ -158,8 +158,8 @@ char *msn_slpmsgpart_serialize(MsnSlpMes
 	tmp += part->size;
 
 	/* Copy footer */
-	siz = sizeof(MsnP2PFooter);
-	memcpy(tmp, (char*)footer, siz);
+	siz = P2P_PACKET_FOOTER_SIZE;
+	memcpy(tmp, footer, siz);
 	tmp += siz;
 
 	*ret_size = tmp - base;


More information about the Commits mailing list