pidgin: 7213a475: Add P2Pv2 header information to the P2P ...

qulogic at pidgin.im qulogic at pidgin.im
Tue Mar 1 01:40:57 EST 2011


----------------------------------------------------------------------
Revision: 7213a4754e9be9412facf1630d7b811256673f4b
Parent:   76222186bea3c01000d2d0b46040f87ebd07afe3
Author:   qulogic at pidgin.im
Date:     02/27/11 19:19:29
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/7213a4754e9be9412facf1630d7b811256673f4b

Changelog: 

Add P2Pv2 header information to the P2P info struct. Of course, all
the v2 stuff does nothing right now.

Changes against parent 76222186bea3c01000d2d0b46040f87ebd07afe3

  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/slpmsg.c	47abad6139c6f623eeeeb45fe488380a6406a581
+++ libpurple/protocols/msn/slpmsg.c	7b2c36165ce8cfe928c5427216b8e8b37c06a51a
@@ -48,7 +48,7 @@ msn_slpmsg_new(MsnSlpLink *slplink)
 	else
 		slpmsg->slplink = NULL;
 
-	slpmsg->p2p_info = msn_p2p_info_new();
+	slpmsg->p2p_info = msn_p2p_info_new(MSN_P2P_VERSION_ONE);
 
 	return slpmsg;
 }
============================================================
--- libpurple/protocols/msn/p2p.h	3a63cea280159224855c3de1050510ef8e979d10
+++ libpurple/protocols/msn/p2p.h	f4f11b3492534222d3f5d49cef8c6ec557651261
@@ -58,8 +58,18 @@ typedef struct
 } MsnP2PFooter;
 #define P2P_PACKET_FOOTER_SIZE (1 * 4)
 
+typedef enum
+{
+	MSN_P2P_VERSION_ONE = 0,
+	MSN_P2P_VERSION_TWO = 1,
+} MsnP2PVersion;
+
 typedef struct {
-	MsnP2PHeader header;
+	MsnP2PVersion version;
+	union {
+		MsnP2PHeader v1;
+		MsnP2Pv2Header v2;
+	} header;
 	MsnP2PFooter footer;
 } MsnP2PInfo;
 
@@ -94,7 +104,7 @@ MsnP2PInfo *
 } MsnP2PAppId;
 
 MsnP2PInfo *
-msn_p2p_info_new(void);
+msn_p2p_info_new(MsnP2PVersion version);
 
 MsnP2PInfo *
 msn_p2p_info_dup(MsnP2PInfo *info);
============================================================
--- libpurple/protocols/msn/p2p.c	e4a3485dfc20ced9206df7d9dc033b1b0681363a
+++ libpurple/protocols/msn/p2p.c	5df8d7afd6207ea006afa5f2f2440795a68d1326
@@ -23,73 +23,140 @@
  */
 
 #include "internal.h"
+#include "debug.h"
 
 #include "p2p.h"
 #include "msnutils.h"
 
 MsnP2PInfo *
-msn_p2p_info_new(void)
+msn_p2p_info_new(MsnP2PVersion version)
 {
-	return g_new0(MsnP2PInfo, 1);
+	MsnP2PInfo *info = g_new0(MsnP2PInfo, 1);
+	info->version = version;
+
+	switch (version) {
+		case MSN_P2P_VERSION_ONE:
+		case MSN_P2P_VERSION_TWO:
+			/* Nothing to do */
+			break;
+
+		default:
+			purple_debug_error("msn", "Invalid P2P Info version: %d\n", version);
+			g_free(info);
+			info = NULL;
+	}
+
+	return info;
 }
 
 MsnP2PInfo *
 msn_p2p_info_dup(MsnP2PInfo *info)
 {
 	MsnP2PInfo *new_info = g_new0(MsnP2PInfo, 1);
-	*new_info = *info;
+
+	new_info->version = info->version;
+
+	switch (info->version) {
+		case MSN_P2P_VERSION_ONE:
+		case MSN_P2P_VERSION_TWO:
+			*new_info = *info;
+			break;
+
+		default:
+			purple_debug_error("msn", "Invalid P2P Info version: %d\n", info->version);
+			g_free(new_info);
+			new_info = NULL;
+	}
+
 	return new_info;
 }
 
 void
 msn_p2p_info_free(MsnP2PInfo *info)
 {
+	switch (info->version) {
+		case MSN_P2P_VERSION_ONE:
+		case MSN_P2P_VERSION_TWO:
+			/* Nothing to do! */
+			break;
+
+		default:
+			purple_debug_error("msn", "Invalid P2P Info version: %d\n", info->version);
+	}
+
 	g_free(info);
 }
 
 size_t
 msn_p2p_header_from_wire(MsnP2PInfo *info, const char *wire)
 {
-	MsnP2PHeader *header;
+	size_t len;
 
-	header = &info->header;
+	switch (info->version) {
+		case MSN_P2P_VERSION_ONE: {
+			MsnP2PHeader *header = &info->header.v1;
 
-	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);
+			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 P2P_PACKET_HEADER_SIZE;
+			len = P2P_PACKET_HEADER_SIZE;
+			break;
+		}
+
+		case MSN_P2P_VERSION_TWO:
+			break;
+
+		default:
+			purple_debug_error("msn", "Invalid P2P Info version: %d\n", info->version);
+	}
+
+	return len;
 }
 
 char *
 msn_p2p_header_to_wire(MsnP2PInfo *info, size_t *len)
 {
-	MsnP2PHeader *header;
-	char *wire;
+	char *wire = NULL;
 	char *tmp;
 
-	header = &info->header;
-	tmp = wire = g_new(char, P2P_PACKET_HEADER_SIZE);
+	switch (info->version) {
+		case MSN_P2P_VERSION_ONE: {
+			MsnP2PHeader *header = &info->header.v1;
+			tmp = wire = g_new(char, P2P_PACKET_HEADER_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);
+			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);
 
-	if (len)
-		*len = P2P_PACKET_HEADER_SIZE;
+			if (len)
+				*len = P2P_PACKET_HEADER_SIZE;
 
+			break;
+		}
+
+		case MSN_P2P_VERSION_TWO:
+			if (len)
+				*len = 0;
+
+			break;
+
+		default:
+			purple_debug_error("msn", "Invalid P2P Info version: %d\n", info->version);
+	}
+
 	return wire;
 
 }
@@ -127,15 +194,30 @@ msn_p2p_info_to_string(MsnP2PInfo *info,
 void
 msn_p2p_info_to_string(MsnP2PInfo *info, GString *str)
 {
-	g_string_append_printf(str, "Session ID: %u\r\n", info->header.session_id);
-	g_string_append_printf(str, "ID:         %u\r\n", info->header.id);
-	g_string_append_printf(str, "Offset:     %" G_GUINT64_FORMAT "\r\n", info->header.offset);
-	g_string_append_printf(str, "Total size: %" G_GUINT64_FORMAT "\r\n", info->header.total_size);
-	g_string_append_printf(str, "Length:     %u\r\n", info->header.length);
-	g_string_append_printf(str, "Flags:      0x%x\r\n", info->header.flags);
-	g_string_append_printf(str, "ACK ID:     %u\r\n", info->header.ack_id);
-	g_string_append_printf(str, "SUB ID:     %u\r\n", info->header.ack_sub_id);
-	g_string_append_printf(str, "ACK Size:   %" G_GUINT64_FORMAT "\r\n", info->header.ack_size);
+	switch (info->version) {
+		case MSN_P2P_VERSION_ONE: {
+			MsnP2PHeader *header = &info->header.v1;
+			g_string_append_printf(str, "Session ID: %u\r\n", header->session_id);
+			g_string_append_printf(str, "ID:         %u\r\n", header->id);
+			g_string_append_printf(str, "Offset:     %" G_GUINT64_FORMAT "\r\n", header->offset);
+			g_string_append_printf(str, "Total size: %" G_GUINT64_FORMAT "\r\n", header->total_size);
+			g_string_append_printf(str, "Length:     %u\r\n", header->length);
+			g_string_append_printf(str, "Flags:      0x%x\r\n", header->flags);
+			g_string_append_printf(str, "ACK ID:     %u\r\n", header->ack_id);
+			g_string_append_printf(str, "SUB ID:     %u\r\n", header->ack_sub_id);
+			g_string_append_printf(str, "ACK Size:   %" G_GUINT64_FORMAT "\r\n", header->ack_size);
+
+			break;
+		}
+
+		case MSN_P2P_VERSION_TWO:
+			/* Nothing to do! */
+			break;
+
+		default:
+			purple_debug_error("msn", "Invalid P2P Info version: %d\n", info->version);
+	}
+
 	g_string_append_printf(str, "Footer:     0x%08X\r\n", info->footer.value);
 }
 
@@ -150,67 +232,232 @@ msn_p2p_info_is_valid(MsnP2PInfo *info)
 gboolean
 msn_p2p_info_is_valid(MsnP2PInfo *info)
 {
-	return info->header.total_size >= info->header.length;
+	gboolean valid = FALSE;
+
+	switch (info->version) {
+		case MSN_P2P_VERSION_ONE:
+			valid = info->header.v1.total_size >= info->header.v1.length;
+			break;
+
+		case MSN_P2P_VERSION_TWO:
+			/* Nothing to do! */
+			break;
+
+		default:
+			purple_debug_error("msn", "Invalid P2P Info version: %d\n", info->version);
+	}
+
+	return valid;
 }
 
 gboolean
 msn_p2p_info_is_final(MsnP2PInfo *info)
 {
-	return info->header.offset + info->header.length >= info->header.total_size;
+	gboolean final = FALSE;
+
+	switch (info->version) {
+		case MSN_P2P_VERSION_ONE:
+			final = info->header.v1.offset + info->header.v1.length >= info->header.v1.total_size;
+			break;
+
+		case MSN_P2P_VERSION_TWO:
+			/* Nothing to do! */
+			break;
+
+		default:
+			purple_debug_error("msn", "Invalid P2P Info version: %d\n", info->version);
+	}
+
+	return final;
 }
 
 guint32
 msn_p2p_info_get_session_id(MsnP2PInfo *info)
 {
-	return info->header.session_id;
+	guint32 session_id = 0;
+
+	switch (info->version) {
+		case MSN_P2P_VERSION_ONE:
+			session_id = info->header.v1.session_id;
+			break;
+
+		case MSN_P2P_VERSION_TWO:
+			/* Nothing to do! */
+			break;
+
+		default:
+			purple_debug_error("msn", "Invalid P2P Info version: %d\n", info->version);
+	}
+
+	return session_id;
 }
 
 guint32
 msn_p2p_info_get_id(MsnP2PInfo *info)
 {
-	return info->header.id;
+	guint32 id = 0;
+
+	switch (info->version) {
+		case MSN_P2P_VERSION_ONE:
+			id = info->header.v1.id;
+			break;
+
+		case MSN_P2P_VERSION_TWO:
+			/* Nothing to do! */
+			break;
+
+		default:
+			purple_debug_error("msn", "Invalid P2P Info version: %d\n", info->version);
+	}
+
+	return id;
 }
 
 guint64
 msn_p2p_info_get_offset(MsnP2PInfo *info)
 {
-	return info->header.offset;
+	guint64 offset = 0;
+
+	switch (info->version) {
+		case MSN_P2P_VERSION_ONE:
+			offset = info->header.v1.offset;
+			break;
+
+		case MSN_P2P_VERSION_TWO:
+			/* Nothing to do! */
+			break;
+
+		default:
+			purple_debug_error("msn", "Invalid P2P Info version: %d\n", info->version);
+	}
+
+	return offset;
 }
 
 guint64
 msn_p2p_info_get_total_size(MsnP2PInfo *info)
 {
-	return info->header.total_size;
+	guint64 total_size = 0;
+
+	switch (info->version) {
+		case MSN_P2P_VERSION_ONE:
+			total_size = info->header.v1.total_size;
+			break;
+
+		case MSN_P2P_VERSION_TWO:
+			/* Nothing to do! */
+			break;
+
+		default:
+			purple_debug_error("msn", "Invalid P2P Info version: %d\n", info->version);
+	}
+
+	return total_size;
 }
 
 guint32
 msn_p2p_info_get_length(MsnP2PInfo *info)
 {
-	return info->header.length;
+	guint32 length = 0;
+
+	switch (info->version) {
+		case MSN_P2P_VERSION_ONE:
+			length = info->header.v1.length;
+			break;
+
+		case MSN_P2P_VERSION_TWO:
+			/* Nothing to do! */
+			break;
+
+		default:
+			purple_debug_error("msn", "Invalid P2P Info version: %d\n", info->version);
+	}
+
+	return length;
 }
 
 guint32
 msn_p2p_info_get_flags(MsnP2PInfo *info)
 {
-	return info->header.flags;
+	guint32 flags = 0;
+
+	switch (info->version) {
+		case MSN_P2P_VERSION_ONE:
+			flags = info->header.v1.flags;
+			break;
+
+		case MSN_P2P_VERSION_TWO:
+			/* Nothing to do! */
+			break;
+
+		default:
+			purple_debug_error("msn", "Invalid P2P Info version: %d\n", info->version);
+	}
+
+	return flags;
 }
 
 guint32
 msn_p2p_info_get_ack_id(MsnP2PInfo *info)
 {
-	return info->header.ack_id;
+	guint32 ack_id = 0;
+
+	switch (info->version) {
+		case MSN_P2P_VERSION_ONE:
+			ack_id = info->header.v1.ack_id;
+			break;
+
+		case MSN_P2P_VERSION_TWO:
+			/* Nothing to do! */
+			break;
+
+		default:
+			purple_debug_error("msn", "Invalid P2P Info version: %d\n", info->version);
+	}
+
+	return ack_id;
 }
 
 guint32
 msn_p2p_info_get_ack_sub_id(MsnP2PInfo *info)
 {
-	return info->header.ack_sub_id;
+	guint32 ack_sub_id = 0;
+
+	switch (info->version) {
+		case MSN_P2P_VERSION_ONE:
+			ack_sub_id = info->header.v1.ack_sub_id;
+			break;
+
+		case MSN_P2P_VERSION_TWO:
+			/* Nothing to do! */
+			break;
+
+		default:
+			purple_debug_error("msn", "Invalid P2P Info version: %d\n", info->version);
+	}
+
+	return ack_sub_id;
 }
 
 guint64
 msn_p2p_info_get_ack_size(MsnP2PInfo *info)
 {
-	return info->header.ack_size;
+	guint64 ack_size = 0;
+
+	switch (info->version) {
+		case MSN_P2P_VERSION_ONE:
+			ack_size = info->header.v1.ack_size;
+			break;
+
+		case MSN_P2P_VERSION_TWO:
+			/* Nothing to do! */
+			break;
+
+		default:
+			purple_debug_error("msn", "Invalid P2P Info version: %d\n", info->version);
+	}
+
+	return ack_size;
 }
 
 guint32
@@ -222,55 +469,156 @@ msn_p2p_info_set_session_id(MsnP2PInfo *
 void
 msn_p2p_info_set_session_id(MsnP2PInfo *info, guint32 session_id)
 {
-	info->header.session_id = session_id;
+	switch (info->version) {
+		case MSN_P2P_VERSION_ONE:
+			info->header.v1.session_id = session_id;
+			break;
+
+		case MSN_P2P_VERSION_TWO:
+			/* Nothing to do! */
+			break;
+
+		default:
+			purple_debug_error("msn", "Invalid P2P Info version: %d\n", info->version);
+	}
+
 }
 
 void
 msn_p2p_info_set_id(MsnP2PInfo *info, guint32 id)
 {
-	info->header.id = id;
+	switch (info->version) {
+		case MSN_P2P_VERSION_ONE:
+			info->header.v1.id = id;
+			break;
+
+		case MSN_P2P_VERSION_TWO:
+			/* Nothing to do! */
+			break;
+
+		default:
+			purple_debug_error("msn", "Invalid P2P Info version: %d\n", info->version);
+	}
+
 }
 
 void
 msn_p2p_info_set_offset(MsnP2PInfo *info, guint64 offset)
 {
-	info->header.offset = offset;
+	switch (info->version) {
+		case MSN_P2P_VERSION_ONE:
+			info->header.v1.offset = offset;
+			break;
+
+		case MSN_P2P_VERSION_TWO:
+			/* Nothing to do! */
+			break;
+
+		default:
+			purple_debug_error("msn", "Invalid P2P Info version: %d\n", info->version);
+	}
 }
 
 void
 msn_p2p_info_set_total_size(MsnP2PInfo *info, guint64 total_size)
 {
-	info->header.total_size = total_size;
+	switch (info->version) {
+		case MSN_P2P_VERSION_ONE:
+			info->header.v1.total_size = total_size;
+			break;
+
+		case MSN_P2P_VERSION_TWO:
+			/* Nothing to do! */
+			break;
+
+		default:
+			purple_debug_error("msn", "Invalid P2P Info version: %d\n", info->version);
+	}
 }
 
 void
 msn_p2p_info_set_length(MsnP2PInfo *info, guint32 length)
 {
-	info->header.length = length;
+	switch (info->version) {
+		case MSN_P2P_VERSION_ONE:
+			info->header.v1.length = length;
+			break;
+
+		case MSN_P2P_VERSION_TWO:
+			/* Nothing to do! */
+			break;
+
+		default:
+			purple_debug_error("msn", "Invalid P2P Info version: %d\n", info->version);
+	}
 }
 
 void
 msn_p2p_info_set_flags(MsnP2PInfo *info, guint32 flags)
 {
-	info->header.flags = flags;
+	switch (info->version) {
+		case MSN_P2P_VERSION_ONE:
+			info->header.v1.flags = flags;
+			break;
+
+		case MSN_P2P_VERSION_TWO:
+			/* Nothing to do! */
+			break;
+
+		default:
+			purple_debug_error("msn", "Invalid P2P Info version: %d\n", info->version);
+	}
 }
 
 void
 msn_p2p_info_set_ack_id(MsnP2PInfo *info, guint32 ack_id)
 {
-	info->header.ack_id = ack_id;
+	switch (info->version) {
+		case MSN_P2P_VERSION_ONE:
+			info->header.v1.ack_id = ack_id;
+			break;
+
+		case MSN_P2P_VERSION_TWO:
+			/* Nothing to do! */
+			break;
+
+		default:
+			purple_debug_error("msn", "Invalid P2P Info version: %d\n", info->version);
+	}
 }
 
 void
 msn_p2p_info_set_ack_sub_id(MsnP2PInfo *info, guint32 ack_sub_id)
 {
-	info->header.ack_sub_id = ack_sub_id;
+	switch (info->version) {
+		case MSN_P2P_VERSION_ONE:
+			info->header.v1.ack_sub_id = ack_sub_id;
+			break;
+
+		case MSN_P2P_VERSION_TWO:
+			/* Nothing to do! */
+			break;
+
+		default:
+			purple_debug_error("msn", "Invalid P2P Info version: %d\n", info->version);
+	}
 }
 
 void
 msn_p2p_info_set_ack_size(MsnP2PInfo *info, guint64 ack_size)
 {
-	info->header.ack_size = ack_size;
+	switch (info->version) {
+		case MSN_P2P_VERSION_ONE:
+			info->header.v1.ack_size = ack_size;
+			break;
+
+		case MSN_P2P_VERSION_TWO:
+			/* Nothing to do! */
+			break;
+
+		default:
+			purple_debug_error("msn", "Invalid P2P Info version: %d\n", info->version);
+	}
 }
 
 void
============================================================
--- libpurple/protocols/msn/slpmsg_part.c	1f86fd1004f78b19e1dbe7138b0dc71038780eb3
+++ libpurple/protocols/msn/slpmsg_part.c	04872e920f062e46677804811987ebbd719b369d
@@ -54,7 +54,7 @@ MsnSlpMessagePart *msn_slpmsgpart_new_fr
 	}
 
 	part = msn_slpmsgpart_new(NULL);
-	part->info = msn_p2p_info_new();
+	part->info = msn_p2p_info_new(MSN_P2P_VERSION_ONE);
 
 	/* Extract the binary SLP header */
 	len = msn_p2p_header_from_wire(part->info, data);


More information about the Commits mailing list