changeset 31200:e03f912141dd

Start moving p2p specific code to its own module.
author masca@cpw.pidgin.im
date Thu, 03 Jun 2010 21:07:08 +0000
parents 712c8ddcf5ed
children 83eb90d18a96
files libpurple/protocols/msn/directconn.c libpurple/protocols/msn/msg.h libpurple/protocols/msn/slp.c libpurple/protocols/msn/slpcall.c libpurple/protocols/msn/slplink.c
diffstat 5 files changed, 49 insertions(+), 78 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/msn/directconn.c	Wed Jun 02 09:33:21 2010 +0000
+++ b/libpurple/protocols/msn/directconn.c	Thu Jun 03 21:07:08 2010 +0000
@@ -31,25 +31,10 @@
 
 #include "slp.h"
 #include "slpmsg.h"
+#include "p2p.h"
 
-#pragma pack(push,1)
-typedef struct {
-	guint32 session_id;
-	guint32 seq_id;
-	guint64 offset;
-	guint64 total_size;
-	guint32 length;
-	guint32 flags;
-	guint32 ack_id;
-	guint32 ack_uid;
-	guint64 ack_size;
-/*	guint8  body[1]; */
-} MsnDcContext;
-#pragma pack(pop)
-
-#define DC_PACKET_HEADER_SIZE sizeof(MsnDcContext)
 #define DC_MAX_BODY_SIZE      8*1024
-#define DC_MAX_PACKET_SIZE    (DC_PACKET_HEADER_SIZE + DC_MAX_BODY_SIZE)
+#define DC_MAX_PACKET_SIZE    (P2P_PACKET_HEADER_SIZE + DC_MAX_BODY_SIZE)
 
 static void
 msn_dc_calculate_nonce_hash(MsnDirectConnNonceType type,
@@ -356,13 +341,13 @@
 msn_dc_parse_binary_header(MsnDirectConn *dc)
 {
 	MsnSlpHeader *h;
-	MsnDcContext *context;
+	MsnP2PBinaryHeader *context;
 
 	g_return_if_fail(dc != NULL);
 
 	h = &dc->header;
 	/* Skip packet size */
-	context = (MsnDcContext *)(dc->in_buffer + 4);
+	context = (MsnP2PBinaryHeader *)(dc->in_buffer + 4);
 
 	h->session_id = GUINT32_FROM_LE(context->session_id);
 	h->id = GUINT32_FROM_LE(context->seq_id);
@@ -378,7 +363,7 @@
 static const gchar *
 msn_dc_serialize_binary_header(MsnDirectConn *dc) {
 	MsnSlpHeader *h;
-	static MsnDcContext bin_header;
+	static MsnP2PBinaryHeader bin_header;
 
 	g_return_val_if_fail(dc != NULL, NULL);
 
@@ -493,9 +478,9 @@
 	const gchar *h;
 
 	h = msn_dc_serialize_binary_header(dc);
-	memcpy(p->data, h, DC_PACKET_HEADER_SIZE);
+	memcpy(p->data, h, P2P_PACKET_HEADER_SIZE);
 
-	memcpy(p->data + offsetof(MsnDcContext, ack_id), dc->nonce, 16);
+	memcpy(p->data + offsetof(MsnP2PBinaryHeader, ack_id), dc->nonce, 16);
 
 	msn_dc_enqueue_packet(dc, p);
 }
@@ -505,7 +490,7 @@
 {
 	MsnDirectConnPacket *p;
 
-	p = msn_dc_new_packet(DC_PACKET_HEADER_SIZE);
+	p = msn_dc_new_packet(P2P_PACKET_HEADER_SIZE);
 
 	dc->header.session_id = 0;
 	dc->header.id = dc->slpcall->slplink->slp_seq_id++;
@@ -522,7 +507,7 @@
 {
 	MsnDirectConnPacket *p;
 
-	p = msn_dc_new_packet(DC_PACKET_HEADER_SIZE);
+	p = msn_dc_new_packet(P2P_PACKET_HEADER_SIZE);
 
 	dc->header.id = dc->slpcall->slplink->slp_seq_id++;
 	dc->header.length = 0;
@@ -536,10 +521,10 @@
 	guchar nonce[16];
 	gchar  nonce_hash[37];
 
-	if (packet_length != DC_PACKET_HEADER_SIZE)
+	if (packet_length != P2P_PACKET_HEADER_SIZE)
 		return FALSE;
 
-	memcpy(nonce, dc->in_buffer + 4 + offsetof(MsnDcContext, ack_id), 16);
+	memcpy(nonce, dc->in_buffer + 4 + offsetof(MsnP2PBinaryHeader, ack_id), 16);
 
 	if (dc->nonce_type == DC_NONCE_PLAIN) {
 		if (memcmp(dc->nonce, nonce, 16) == 0) {
@@ -589,11 +574,11 @@
 	MsnDirectConnPacket *p;
 	guint32 length;
 
-	length = msg->body_len + DC_PACKET_HEADER_SIZE;
+	length = msg->body_len + P2P_PACKET_HEADER_SIZE;
 	p = msn_dc_new_packet(length);
 
-	memcpy(p->data, &msg->msnslp_header, DC_PACKET_HEADER_SIZE);
-	memcpy(p->data + DC_PACKET_HEADER_SIZE, msg->body, msg->body_len);
+	memcpy(p->data, &msg->msnslp_header, P2P_PACKET_HEADER_SIZE);
+	memcpy(p->data + P2P_PACKET_HEADER_SIZE, msg->body, msg->body_len);
 
 	p->sent_cb = msn_dc_send_packet_cb;
 	p->msg = msn_message_ref(msg);
@@ -643,7 +628,7 @@
 		msn_slplink_process_msg(
 			dc->slplink,
 			&dc->header,
-			dc->in_buffer + 4 + DC_PACKET_HEADER_SIZE,
+			dc->in_buffer + 4 + P2P_PACKET_HEADER_SIZE,
 			dc->header.length
 		);
 
--- a/libpurple/protocols/msn/msg.h	Wed Jun 02 09:33:21 2010 +0000
+++ b/libpurple/protocols/msn/msg.h	Thu Jun 03 21:07:08 2010 +0000
@@ -67,23 +67,6 @@
 #define MSG_OIM_BODY_DEM	"\n\n"
 #define MSG_OIM_LINE_DEM	"\n"
 
-typedef enum
-{
-	SLP_HF_NO_FLAG         = 0x0,        /**< No flags specified */
-	SLP_HF_OUT_OF_ORDER    = 0x1,        /**< Chunk out-of-order */
-	SLP_HF_ACK             = 0x2,        /**< Acknowledgement */
-	SLP_HF_PENDING_INVITE  = 0x4,        /**< There is a pending invite */
-	SLP_HF_BINARY_ERROR    = 0x8,        /**< Error on the binary level */
-	SLP_HF_MSN_OBJ_DATA    = 0x20,       /**< MsnObject data */
-	SLP_HF_WML2009_COMP    = 0x1000000,  /**< Compatibility with WLM 2009 */
-	SLP_HF_FILE_DATA       = 0x1000030   /**< File transfer data */
-} SlpHeaderFlag;
-/* Info From:
- * http://msnpiki.msnfanatic.com/index.php/MSNC:P2Pv1_Headers#Flags
- * http://trac.kmess.org/changeset/ba04d0c825769d23370511031c47f6be75fe9b86
- * #7180
- */
-
 typedef struct
 {
 	guint32 session_id;
--- a/libpurple/protocols/msn/slp.c	Wed Jun 02 09:33:21 2010 +0000
+++ b/libpurple/protocols/msn/slp.c	Thu Jun 03 21:07:08 2010 +0000
@@ -34,6 +34,7 @@
 #include "user.h"
 #include "switchboard.h"
 #include "directconn.h"
+#include "p2p.h"
 
 #include "smiley.h"
 
@@ -518,7 +519,7 @@
 			/* DATA */
 			slpmsg = msn_slpmsg_new(slplink);
 			slpmsg->slpcall = slpcall;
-			slpmsg->flags = SLP_HF_MSN_OBJ_DATA;
+			slpmsg->flags = P2P_MSN_OBJ_DATA;
 			slpmsg->info = "SLP DATA";
 			msn_slpmsg_set_image(slpmsg, img);
 			msn_slplink_queue_slpmsg(slplink, slpmsg);
--- a/libpurple/protocols/msn/slpcall.c	Wed Jun 02 09:33:21 2010 +0000
+++ b/libpurple/protocols/msn/slpcall.c	Thu Jun 03 21:07:08 2010 +0000
@@ -29,6 +29,7 @@
 #include "slpcall.h"
 
 #include "slp.h"
+#include "p2p.h"
 
 /**************************************************************************
  * Main
@@ -204,7 +205,7 @@
 	body = slpmsg->buffer;
 	body_len = slpmsg->offset;
 
-	if (slpmsg->flags == SLP_HF_NO_FLAG || slpmsg->flags == SLP_HF_WML2009_COMP)
+	if (slpmsg->flags == P2P_NO_FLAG || slpmsg->flags == P2P_WML2009_COMP)
 	{
 		char *body_str;
 
@@ -265,9 +266,9 @@
 		}
 		g_free(body_str);
 	}
-	else if (slpmsg->flags == SLP_HF_MSN_OBJ_DATA ||
-	         slpmsg->flags == SLP_HF_WML2009_COMP & SLP_HF_MSN_OBJ_DATA ||
-	         slpmsg->flags == SLP_HF_FILE_DATA)
+	else if (slpmsg->flags == P2P_MSN_OBJ_DATA ||
+	         slpmsg->flags == P2P_WML2009_COMP & P2P_MSN_OBJ_DATA ||
+	         slpmsg->flags == P2P_FILE_DATA)
 	{
 		slpcall = msn_slplink_find_slp_call_with_session_id(slplink, slpmsg->session_id);
 
@@ -293,7 +294,7 @@
 			msn_slpcall_session_init(slpcall);
 	}
 #endif
-	else if (slpmsg->flags == SLP_HF_ACK)
+	else if (slpmsg->flags == P2P_ACK)
 	{
 		/* Acknowledgement of previous message. Don't do anything currently. */
 	}
--- a/libpurple/protocols/msn/slplink.c	Wed Jun 02 09:33:21 2010 +0000
+++ b/libpurple/protocols/msn/slplink.c	Thu Jun 03 21:07:08 2010 +0000
@@ -30,6 +30,7 @@
 
 #include "switchboard.h"
 #include "slp.h"
+#include "p2p.h"
 
 #ifdef MSN_DEBUG_SLP_FILES
 static int m_sc = 0;
@@ -294,7 +295,7 @@
 	 * reusing the same one all the time. */
 	msg = slpmsg->msg;
 
-	real_size = (slpmsg->flags == SLP_HF_ACK) ? 0 : slpmsg->size;
+	real_size = (slpmsg->flags == P2P_ACK) ? 0 : slpmsg->size;
 
 	if (slpmsg->offset < real_size)
 	{
@@ -329,9 +330,9 @@
 		g_list_append(slpmsg->msgs, msn_message_ref(msg));
 	msn_slplink_send_msg(slplink, msg);
 
-	if ((slpmsg->flags == SLP_HF_MSN_OBJ_DATA || 
-	     slpmsg->flags == (SLP_HF_WML2009_COMP & SLP_HF_MSN_OBJ_DATA) ||
-	     slpmsg->flags == SLP_HF_FILE_DATA) &&
+	if ((slpmsg->flags == P2P_MSN_OBJ_DATA || 
+	     slpmsg->flags == (P2P_WML2009_COMP & P2P_MSN_OBJ_DATA) ||
+	     slpmsg->flags == P2P_FILE_DATA) &&
 		(slpmsg->slpcall != NULL))
 	{
 		slpmsg->slpcall->progress = TRUE;
@@ -355,7 +356,7 @@
 
 	slpmsg = data;
 
-	real_size = (slpmsg->flags == SLP_HF_ACK) ? 0 : slpmsg->size;
+	real_size = (slpmsg->flags == P2P_ACK) ? 0 : slpmsg->size;
 
 	slpmsg->offset += msg->msnslp_header.length;
 
@@ -375,9 +376,9 @@
 	else
 	{
 		/* The whole message has been sent */
-		if (slpmsg->flags == SLP_HF_MSN_OBJ_DATA ||
-	        slpmsg->flags == (SLP_HF_WML2009_COMP & SLP_HF_MSN_OBJ_DATA) ||
-	        slpmsg->flags == SLP_HF_FILE_DATA) 
+		if (slpmsg->flags == P2P_MSN_OBJ_DATA ||
+	        slpmsg->flags == (P2P_WML2009_COMP & P2P_MSN_OBJ_DATA) ||
+	        slpmsg->flags == P2P_FILE_DATA) 
 		{
 			if (slpmsg->slpcall != NULL)
 			{
@@ -413,21 +414,21 @@
 
 	slpmsg->msg = msg = msn_message_new_msnslp();
 
-	if (slpmsg->flags == SLP_HF_NO_FLAG)
+	if (slpmsg->flags == P2P_NO_FLAG)
 	{
 		msg->msnslp_header.session_id = slpmsg->session_id;
 		msg->msnslp_header.ack_id = rand() % 0xFFFFFF00;
 	}
-	else if (slpmsg->flags == SLP_HF_ACK)
+	else if (slpmsg->flags == P2P_ACK)
 	{
 		msg->msnslp_header.session_id = slpmsg->session_id;
 		msg->msnslp_header.ack_id = slpmsg->ack_id;
 		msg->msnslp_header.ack_size = slpmsg->ack_size;
 		msg->msnslp_header.ack_sub_id = slpmsg->ack_sub_id;
 	}
-	else if (slpmsg->flags == SLP_HF_MSN_OBJ_DATA ||
-	         slpmsg->flags == (SLP_HF_WML2009_COMP & SLP_HF_MSN_OBJ_DATA) ||
-	         slpmsg->flags == SLP_HF_FILE_DATA)
+	else if (slpmsg->flags == P2P_MSN_OBJ_DATA ||
+	         slpmsg->flags == (P2P_WML2009_COMP & P2P_MSN_OBJ_DATA) ||
+	         slpmsg->flags == P2P_FILE_DATA)
 	{
 		MsnSlpCall *slpcall;
 		slpcall = slpmsg->slpcall;
@@ -500,7 +501,7 @@
 
 	slpmsg->session_id = header->session_id;
 	slpmsg->size       = header->total_size;
-	slpmsg->flags      = SLP_HF_ACK;
+	slpmsg->flags      = P2P_ACK;
 	slpmsg->ack_id     = header->id;
 	slpmsg->ack_sub_id = header->ack_id;
 	slpmsg->ack_size   = header->total_size;
@@ -538,7 +539,7 @@
 
 	slpmsg = msn_slpmsg_new(slpcall->slplink);
 	slpmsg->slpcall = slpcall;
-	slpmsg->flags = SLP_HF_FILE_DATA;
+	slpmsg->flags = P2P_FILE_DATA;
 	slpmsg->info = "SLP FILE";
 	slpmsg->size = purple_xfer_get_size(xfer);
 
@@ -591,9 +592,9 @@
 			slpmsg->slpcall = msn_slplink_find_slp_call_with_session_id(slplink, slpmsg->session_id);
 			if (slpmsg->slpcall != NULL)
 			{
-				if (slpmsg->flags == SLP_HF_MSN_OBJ_DATA ||
-					slpmsg->flags == (SLP_HF_WML2009_COMP & SLP_HF_MSN_OBJ_DATA) ||
-					slpmsg->flags == SLP_HF_FILE_DATA)
+				if (slpmsg->flags == P2P_MSN_OBJ_DATA ||
+					slpmsg->flags == (P2P_WML2009_COMP & P2P_MSN_OBJ_DATA) ||
+					slpmsg->flags == P2P_FILE_DATA)
 				{
 					PurpleXfer *xfer = slpmsg->slpcall->xfer;
 					if (xfer != NULL)
@@ -657,9 +658,9 @@
 		}
 	}
 
-	if ((slpmsg->flags == SLP_HF_MSN_OBJ_DATA ||
-		slpmsg->flags == (SLP_HF_WML2009_COMP & SLP_HF_MSN_OBJ_DATA) ||
-		slpmsg->flags == SLP_HF_FILE_DATA) &&
+	if ((slpmsg->flags == P2P_MSN_OBJ_DATA ||
+		slpmsg->flags == (P2P_WML2009_COMP & P2P_MSN_OBJ_DATA) ||
+		slpmsg->flags == P2P_FILE_DATA) &&
 		(slpmsg->slpcall != NULL))
 	{
 		slpmsg->slpcall->progress = TRUE;
@@ -700,10 +701,10 @@
 				msn_directconn_send_handshake(directconn);
 #endif
 		}
-		else if (slpmsg->flags == SLP_HF_NO_FLAG || slpmsg->flags == SLP_HF_WML2009_COMP ||
-			slpmsg->flags == SLP_HF_MSN_OBJ_DATA ||
-			slpmsg->flags == (SLP_HF_WML2009_COMP & SLP_HF_MSN_OBJ_DATA) ||
-			slpmsg->flags == SLP_HF_FILE_DATA)
+		else if (slpmsg->flags == P2P_NO_FLAG || slpmsg->flags == P2P_WML2009_COMP ||
+			slpmsg->flags == P2P_MSN_OBJ_DATA ||
+			slpmsg->flags == (P2P_WML2009_COMP & P2P_MSN_OBJ_DATA) ||
+			slpmsg->flags == P2P_FILE_DATA)
 		{
 			/* Release all the messages and send the ACK */