changeset 32021:eb1bbaae3427

Try to hide msn_p2p_info_get_flags as much as possible, since it may not exist in p2pv2.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sat, 07 May 2011 08:43:31 +0000
parents 50ca9e64186b
children 15efeffa8a85
files libpurple/protocols/msn/p2p.c libpurple/protocols/msn/p2p.h libpurple/protocols/msn/slpcall.c libpurple/protocols/msn/slplink.c libpurple/protocols/msn/slpmsg_part.c
diffstat 5 files changed, 81 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/msn/p2p.c	Sat May 07 07:49:25 2011 +0000
+++ b/libpurple/protocols/msn/p2p.c	Sat May 07 08:43:31 2011 +0000
@@ -313,11 +313,28 @@
 }
 
 gboolean
-msn_p2p_msg_is_data(const MsnP2PHeaderFlag flags)
+msn_p2p_msg_is_data(const MsnP2PInfo *info)
 {
-	return (flags == P2P_MSN_OBJ_DATA ||
-	        flags == (P2P_WLM2009_COMP | P2P_MSN_OBJ_DATA) ||
-	        flags == P2P_FILE_DATA);
+	gboolean data = FALSE;
+
+	switch (info->version) {
+		case MSN_P2P_VERSION_ONE: {
+			guint32 flags = info->header.v1.flags;
+			data = (flags == P2P_MSN_OBJ_DATA ||
+			        flags == (P2P_WLM2009_COMP | P2P_MSN_OBJ_DATA) ||
+			        flags == P2P_FILE_DATA);
+			break;
+		}
+
+		case MSN_P2P_VERSION_TWO:
+			data = info->header.v2.message_len > 0;
+			break;
+
+		default:
+			purple_debug_error("msn", "Invalid P2P Info version: %d\n", info->version);
+	}
+
+	return data;
 }
 
 gboolean
@@ -417,7 +434,7 @@
 			guint32 flags = msn_p2p_info_get_flags(info);
 
 			ret = flags == P2P_NO_FLAG || flags == P2P_WLM2009_COMP ||
-			      msn_p2p_msg_is_data(flags);
+			      msn_p2p_msg_is_data(info);
 			break;
 		}
 
@@ -432,6 +449,46 @@
 	return ret;
 }
 
+gboolean
+msn_p2p_info_is_ack(MsnP2PInfo *info)
+{
+	gboolean ret = FALSE;
+
+	switch (info->version) {
+		case MSN_P2P_VERSION_ONE: {
+			ret = msn_p2p_info_get_flags(info) == P2P_ACK;
+			break;
+		}
+
+		case MSN_P2P_VERSION_TWO:
+			ret = msn_tlv_gettlv(info->header.v2.header_tlv, P2P_TLV_TYPE_ACK, 1) != NULL;
+			break;
+
+		default:
+			purple_debug_error("msn", "Invalid P2P Info version: %d\n", info->version);
+	}
+
+	return ret;
+}
+
+void
+msn_p2p_info_init_first(MsnP2PInfo *info, MsnP2PInfo *old_info)
+{
+	switch (info->version) {
+		case MSN_P2P_VERSION_ONE:
+			info->header.v1.session_id = old_info->header.v1.session_id;
+			info->header.v1.flags = old_info->header.v1.flags;
+			break;
+
+		case MSN_P2P_VERSION_TWO:
+			info->header.v2.data_tf = TF_FIRST;
+			break;
+
+		default:
+			purple_debug_error("msn", "Invalid P2P Info version: %d\n", info->version);
+	}
+}
+
 guint32
 msn_p2p_info_get_session_id(MsnP2PInfo *info)
 {
@@ -548,7 +605,7 @@
 			break;
 
 		case MSN_P2P_VERSION_TWO:
-			/* Nothing to do! */
+			flags = info->header.v2.data_tf;
 			break;
 
 		default:
@@ -723,7 +780,7 @@
 			break;
 
 		case MSN_P2P_VERSION_TWO:
-			/* Nothing to do! */
+			info->header.v2.data_tf = flags;
 			break;
 
 		default:
--- a/libpurple/protocols/msn/p2p.h	Sat May 07 07:49:25 2011 +0000
+++ b/libpurple/protocols/msn/p2p.h	Sat May 07 08:43:31 2011 +0000
@@ -183,7 +183,7 @@
 msn_p2p_info_to_string(MsnP2PInfo *info, GString *str);
 
 gboolean
-msn_p2p_msg_is_data(const MsnP2PHeaderFlag flags);
+msn_p2p_msg_is_data(const MsnP2PInfo *info);
 
 gboolean
 msn_p2p_info_is_valid(MsnP2PInfo *info);
@@ -197,6 +197,12 @@
 gboolean
 msn_p2p_info_require_ack(MsnP2PInfo *info);
 
+gboolean
+msn_p2p_info_is_ack(MsnP2PInfo *info);
+
+void
+msn_p2p_info_init_first(MsnP2PInfo *new_info, MsnP2PInfo *old_info);
+
 guint32
 msn_p2p_info_get_session_id(MsnP2PInfo *info);
 
--- a/libpurple/protocols/msn/slpcall.c	Sat May 07 07:49:25 2011 +0000
+++ b/libpurple/protocols/msn/slpcall.c	Sat May 07 08:43:31 2011 +0000
@@ -1130,7 +1130,7 @@
 		}
 		g_free(body_str);
 	}
-	 else if (msn_p2p_msg_is_data(flags))
+	 else if (msn_p2p_msg_is_data(slpmsg->p2p_info))
 	{
 		slpcall = msn_slplink_find_slp_call_with_session_id(slplink, session_id);
 
@@ -1147,7 +1147,7 @@
 			slpcall->wasted = TRUE;
 		}
 	}
-	else if (flags == P2P_ACK)
+	else if (msn_p2p_info_is_ack(slpmsg->p2p_info))
 	{
 		/* Acknowledgement of previous message. Don't do anything currently. */
 	}
--- a/libpurple/protocols/msn/slplink.c	Sat May 07 07:49:25 2011 +0000
+++ b/libpurple/protocols/msn/slplink.c	Sat May 07 08:43:31 2011 +0000
@@ -292,7 +292,7 @@
 	part = msn_slpmsgpart_new(msn_p2p_info_dup(info));
 	part->ack_data = slpmsg;
 
-	real_size = (msn_p2p_info_get_flags(info) == P2P_ACK) ? 0 : slpmsg->size;
+	real_size = msn_p2p_info_is_ack(info) ? 0 : slpmsg->size;
 
 	offset = msn_p2p_info_get_offset(info);
 	if (offset < real_size)
@@ -330,8 +330,7 @@
 	msn_slplink_send_part(slplink, part);
 
 
-	if (msn_p2p_msg_is_data(msn_p2p_info_get_flags(info)) &&
-		(slpmsg->slpcall != NULL))
+	if (msn_p2p_msg_is_data(info) && slpmsg->slpcall != NULL)
 	{
 		slpmsg->slpcall->progress = TRUE;
 
@@ -358,7 +357,7 @@
 	{
 		msn_p2p_info_set_ack_id(info, rand() % 0xFFFFFF00);
 	}
-	else if (msn_p2p_msg_is_data(flags))
+	else if (msn_p2p_msg_is_data(info))
 	{
 		MsnSlpCall *slpcall;
 		slpcall = slpmsg->slpcall;
@@ -447,22 +446,19 @@
 {
 	MsnSlpMessage *slpmsg;
 	guint32 session_id;
-	guint32 flags;
 
 	slpmsg = msn_slpmsg_new(slplink);
 	slpmsg->id = msn_p2p_info_get_id(info);
 	session_id = msn_p2p_info_get_session_id(info);
-	msn_p2p_info_set_session_id(slpmsg->p2p_info, session_id);
 	slpmsg->size = msn_p2p_info_get_total_size(info);
-	flags = msn_p2p_info_get_flags(info);
-	msn_p2p_info_set_flags(slpmsg->p2p_info, flags);
+	msn_p2p_info_init_first(slpmsg->p2p_info, info);
 
 	if (session_id)
 	{
 		slpmsg->slpcall = msn_slplink_find_slp_call_with_session_id(slplink, session_id);
 		if (slpmsg->slpcall != NULL)
 		{
-			if (msn_p2p_msg_is_data(flags))
+			if (msn_p2p_msg_is_data(info))
 			{
 				PurpleXfer *xfer = slpmsg->slpcall->xfer;
 				if (xfer != NULL)
@@ -601,8 +597,7 @@
 
 	slpmsg_add_part(slpmsg, part);
 
-	if (msn_p2p_msg_is_data(msn_p2p_info_get_flags(slpmsg->p2p_info)) &&
-		(slpmsg->slpcall != NULL))
+	if (msn_p2p_msg_is_data(slpmsg->p2p_info) && slpmsg->slpcall != NULL)
 	{
 		slpmsg->slpcall->progress = TRUE;
 
--- a/libpurple/protocols/msn/slpmsg_part.c	Sat May 07 07:49:25 2011 +0000
+++ b/libpurple/protocols/msn/slpmsg_part.c	Sat May 07 08:43:31 2011 +0000
@@ -175,7 +175,7 @@
 
 	slpmsg = data;
 
-	real_size = (msn_p2p_info_get_flags(slpmsg->p2p_info) == P2P_ACK) ? 0 : slpmsg->size;
+	real_size = msn_p2p_info_is_ack(slpmsg->p2p_info) ? 0 : slpmsg->size;
 
 	offset = msn_p2p_info_get_offset(slpmsg->p2p_info);
 	offset += msn_p2p_info_get_length(part->info);
@@ -197,7 +197,7 @@
 	else
 	{
 		/* The whole message has been sent */
-		if (msn_p2p_msg_is_data(msn_p2p_info_get_flags(slpmsg->p2p_info)))
+		if (msn_p2p_msg_is_data(slpmsg->p2p_info))
 		{
 			if (slpmsg->slpcall != NULL)
 			{