pidgin: a46b0d6e: Try to hide msn_p2p_info_get_flags as mu...

qulogic at pidgin.im qulogic at pidgin.im
Sat May 7 04:51:37 EDT 2011


----------------------------------------------------------------------
Revision: a46b0d6e1fc0bd5c88f389a00ade812d37e90e34
Parent:   ffb1743e219725a5cd5a51e3f58fbae1ed7a4f1d
Author:   qulogic at pidgin.im
Date:     05/07/11 04:43:31
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/a46b0d6e1fc0bd5c88f389a00ade812d37e90e34

Changelog: 

Try to hide msn_p2p_info_get_flags as much as possible, since it may
not exist in p2pv2.

Changes against parent ffb1743e219725a5cd5a51e3f58fbae1ed7a4f1d

  patched  libpurple/protocols/msn/p2p.c
  patched  libpurple/protocols/msn/p2p.h
  patched  libpurple/protocols/msn/slpcall.c
  patched  libpurple/protocols/msn/slplink.c
  patched  libpurple/protocols/msn/slpmsg_part.c

-------------- next part --------------
============================================================
--- libpurple/protocols/msn/slpcall.c	9e329ef2b0f995417db0fa82b1f5357fc9e57338
+++ libpurple/protocols/msn/slpcall.c	bc8f60feff42d958a59ce40e6dbe3fa1948a9c4e
@@ -1130,7 +1130,7 @@ msn_slp_process_msg(MsnSlpLink *slplink,
 		}
 		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 @@ msn_slp_process_msg(MsnSlpLink *slplink,
 			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. */
 	}
============================================================
--- libpurple/protocols/msn/slplink.c	524347d209fd7268b0e6300821f56e39a9087bfb
+++ libpurple/protocols/msn/slplink.c	075df5ce5366359858dcca4c0eb2077ab01ec407
@@ -292,7 +292,7 @@ msn_slplink_send_msgpart(MsnSlpLink *slp
 	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_msgpart(MsnSlpLink *slp
 	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_slplink_release_slpmsg(MsnSlpLink *s
 	{
 		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 @@ init_first_msg(MsnSlpLink *slplink, MsnP
 {
 	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 @@ msn_slplink_process_msg(MsnSlpLink *slpl
 
 	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;
 
============================================================
--- libpurple/protocols/msn/p2p.h	80870417f017578c8202a9ece08f929c9e6ae2a1
+++ libpurple/protocols/msn/p2p.h	328dca8e62d91266353c6b895669171d24c476e2
@@ -183,7 +183,7 @@ gboolean
 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 @@ msn_p2p_info_require_ack(MsnP2PInfo *inf
 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);
 
============================================================
--- libpurple/protocols/msn/p2p.c	bf132b4b8408627f55967594197855b1dcb1b1d5
+++ libpurple/protocols/msn/p2p.c	b3b5b955c9e79fe0f120c1a5f6ccb627e488d230
@@ -313,11 +313,28 @@ gboolean
 }
 
 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 @@ msn_p2p_info_require_ack(MsnP2PInfo *inf
 			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 @@ msn_p2p_info_require_ack(MsnP2PInfo *inf
 	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 @@ msn_p2p_info_get_flags(MsnP2PInfo *info)
 			break;
 
 		case MSN_P2P_VERSION_TWO:
-			/* Nothing to do! */
+			flags = info->header.v2.data_tf;
 			break;
 
 		default:
@@ -723,7 +780,7 @@ msn_p2p_info_set_flags(MsnP2PInfo *info,
 			break;
 
 		case MSN_P2P_VERSION_TWO:
-			/* Nothing to do! */
+			info->header.v2.data_tf = flags;
 			break;
 
 		default:
============================================================
--- libpurple/protocols/msn/slpmsg_part.c	a222ab61724234e114161fb6f0c28652cecf03b8
+++ libpurple/protocols/msn/slpmsg_part.c	bc2993596520f3f4014f0b89e3f17123f2d73736
@@ -175,7 +175,7 @@ msn_slpmsgpart_ack(MsnSlpMessagePart *pa
 
 	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 @@ msn_slpmsgpart_ack(MsnSlpMessagePart *pa
 	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)
 			{


More information about the Commits mailing list