changeset 31567:968103d932d6

Add P2Pv2 ack'ing.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sat, 07 May 2011 07:29:47 +0000
parents c714ccbcdf00
children 50ca9e64186b
files libpurple/protocols/msn/p2p.c libpurple/protocols/msn/p2p.h libpurple/protocols/msn/slpmsg.c
diffstat 3 files changed, 49 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/msn/p2p.c	Sat May 07 07:28:05 2011 +0000
+++ b/libpurple/protocols/msn/p2p.c	Sat May 07 07:29:47 2011 +0000
@@ -362,6 +362,51 @@
 	return final;
 }
 
+void
+msn_p2p_info_create_ack(MsnP2PInfo *old_info, MsnP2PInfo *new_info)
+{
+	switch (old_info->version) {
+		case MSN_P2P_VERSION_ONE: {
+			MsnP2PHeader *old = &old_info->header.v1;
+			MsnP2PHeader *new = &new_info->header.v1;
+
+			new->session_id = old->session_id;
+			new->flags = P2P_ACK;
+			new->ack_id = old->id;
+			new->ack_sub_id = old->ack_id;
+			new->ack_size = old->total_size;
+			break;
+		}
+
+		case MSN_P2P_VERSION_TWO: {
+			MsnP2Pv2Header *old = &old_info->header.v2;
+			MsnP2Pv2Header *new = &new_info->header.v2;
+
+			msn_tlvlist_add_32(&new->header_tlv, P2P_TLV_TYPE_ACK, old->base_id + old->message_len);
+			new->opcode = P2P_OPCODE_NONE;
+
+			if (old->message_len > 0) {
+				if (!msn_tlv_gettlv(old->header_tlv, P2P_TLV_TYPE_ACK, 1)) {
+					if (old->opcode & P2P_OPCODE_SYN) {
+						msn_tlv_t *ack_tlv;
+						new->opcode |= P2P_OPCODE_RAK;
+						
+						ack_tlv = msn_tlv_gettlv(old->header_tlv, P2P_TLV_TYPE_PEER_INFO, 1);
+						if (ack_tlv) {
+							msn_tlvlist_add_tlv(&new->header_tlv, ack_tlv);
+							new->opcode |= P2P_OPCODE_SYN;
+						}
+					}
+				}
+			}
+			break;
+		}
+
+		default:
+			purple_debug_error("msn", "Invalid P2P Info version: %d\n", old_info->version);
+	}
+}
+
 guint32
 msn_p2p_info_get_session_id(MsnP2PInfo *info)
 {
--- a/libpurple/protocols/msn/p2p.h	Sat May 07 07:28:05 2011 +0000
+++ b/libpurple/protocols/msn/p2p.h	Sat May 07 07:29:47 2011 +0000
@@ -191,6 +191,9 @@
 gboolean
 msn_p2p_info_is_final(MsnP2PInfo *info);
 
+void
+msn_p2p_info_create_ack(MsnP2PInfo *old_info, MsnP2PInfo *new_info);
+
 guint32
 msn_p2p_info_get_session_id(MsnP2PInfo *info);
 
--- a/libpurple/protocols/msn/slpmsg.c	Sat May 07 07:28:05 2011 +0000
+++ b/libpurple/protocols/msn/slpmsg.c	Sat May 07 07:29:47 2011 +0000
@@ -206,12 +206,8 @@
 	slpmsg = msn_slpmsg_new(NULL);
 
 	new_info = slpmsg->p2p_info;
-	msn_p2p_info_set_session_id(new_info, msn_p2p_info_get_session_id(ack_info));
+	msn_p2p_info_create_ack(ack_info, new_info);
 	slpmsg->size = msn_p2p_info_get_total_size(ack_info);
-	msn_p2p_info_set_flags(new_info, P2P_ACK);
-	msn_p2p_info_set_ack_id(new_info, msn_p2p_info_get_id(ack_info));
-	msn_p2p_info_set_ack_sub_id(new_info, msn_p2p_info_get_ack_id(ack_info));
-	msn_p2p_info_set_ack_size(new_info, msn_p2p_info_get_total_size(ack_info));
 	slpmsg->info = "SLP ACK";
 
 	return slpmsg;