soc.2010.msn-tlc: 17457a26: Start moving p2p specific code to its ow...
masca at cpw.pidgin.im
masca at cpw.pidgin.im
Fri Jun 4 21:35:37 EDT 2010
-----------------------------------------------------------------
Revision: 17457a26c2a06781fae929e78e8b7d3bf59f3831
Ancestor: b14a4e8fae0513bf8f5883c852a30bb8c3bcfc55
Author: masca at cpw.pidgin.im
Date: 2010-06-03T21:07:08
Branch: im.pidgin.soc.2010.msn-tlc
URL: http://d.pidgin.im/viewmtn/revision/info/17457a26c2a06781fae929e78e8b7d3bf59f3831
Modified 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
ChangeLog:
Start moving p2p specific code to its own module.
-------------- next part --------------
============================================================
--- libpurple/protocols/msn/directconn.c 8035a6be246891bc7c876564d583615ae655dd0a
+++ libpurple/protocols/msn/directconn.c 5ab855487f6413d8c511e123b3d61acc3c41ceee
@@ -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
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 @@ msn_dc_serialize_binary_header(MsnDirect
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 @@ msn_dc_send_handshake_with_nonce(MsnDire
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 @@ msn_dc_send_handshake(MsnDirectConn *dc)
{
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 @@ msn_dc_send_handshake_reply(MsnDirectCon
{
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 @@ msn_dc_verify_handshake(MsnDirectConn *d
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 @@ msn_dc_enqueue_msg(MsnDirectConn *dc, Ms
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_dc_process_packet(MsnDirectConn *dc,
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
);
============================================================
--- libpurple/protocols/msn/msg.h b551c58fefa3a0196d0927c76741434976a16b30
+++ libpurple/protocols/msn/msg.h 3de3f539b888ce0bb26b84a7a8e1f0070bde3f84
@@ -67,23 +67,6 @@ typedef void (*MsnMsgCb)(MsnMessage *, v
#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;
============================================================
--- libpurple/protocols/msn/slp.c e5f88f0e646d8bb4cf031761501f3b8c5441b605
+++ libpurple/protocols/msn/slp.c fe547b7c58ac03c3c3ce51bcb1ca0617d8e50aae
@@ -34,6 +34,7 @@
#include "user.h"
#include "switchboard.h"
#include "directconn.h"
+#include "p2p.h"
#include "smiley.h"
@@ -518,7 +519,7 @@ got_sessionreq(MsnSlpCall *slpcall, cons
/* 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);
============================================================
--- libpurple/protocols/msn/slpcall.c f2813c13816dc5d8ca5a40a961b963c9c39fdcaf
+++ libpurple/protocols/msn/slpcall.c 9e5768e62f1e2c96a849f15b87431be710ce94e5
@@ -29,6 +29,7 @@
#include "slpcall.h"
#include "slp.h"
+#include "p2p.h"
/**************************************************************************
* Main
@@ -204,7 +205,7 @@ msn_slp_process_msg(MsnSlpLink *slplink,
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 @@ msn_slp_process_msg(MsnSlpLink *slplink,
}
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_slp_process_msg(MsnSlpLink *slplink,
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. */
}
============================================================
--- libpurple/protocols/msn/slplink.c c51a106510d44c95be05c0e8e9094008f73913d2
+++ libpurple/protocols/msn/slplink.c 18ec3f7b96fcc64b85bba3dc1119b4fd57930655
@@ -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 @@ msn_slplink_send_msgpart(MsnSlpLink *slp
* 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 @@ msn_slplink_send_msgpart(MsnSlpLink *slp
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 @@ msg_ack(MsnMessage *msg, void *data)
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 @@ msg_ack(MsnMessage *msg, void *data)
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 @@ msn_slplink_release_slpmsg(MsnSlpLink *s
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 @@ msn_slplink_create_ack(MsnSlpLink *slpli
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 @@ send_file_cb(MsnSlpCall *slpcall)
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 @@ msn_slplink_process_msg(MsnSlpLink *slpl
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 @@ msn_slplink_process_msg(MsnSlpLink *slpl
}
}
- 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_slplink_process_msg(MsnSlpLink *slpl
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 */
More information about the Commits
mailing list