cpw.darkrain42.msn.ft: f7212b36: A quick and dirty hack to make MSN use t...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Thu Oct 15 21:31:56 EDT 2009


-----------------------------------------------------------------
Revision: f7212b36cc13bdbaf77b2c3a8dbcde9cb395c4f8
Ancestor: 8868b966ec81185b033adaf17af1a06143d2edb1
Author: darkrain42 at pidgin.im
Date: 2009-10-16T01:26:04
Branch: im.pidgin.cpw.darkrain42.msn.ft
URL: http://d.pidgin.im/viewmtn/revision/info/f7212b36cc13bdbaf77b2c3a8dbcde9cb395c4f8

Modified files:
        libpurple/protocols/msn/slp.c libpurple/protocols/msn/slp.h
        libpurple/protocols/msn/slpcall.c
        libpurple/protocols/msn/slpcall.h
        libpurple/protocols/msn/slplink.c
        libpurple/protocols/msn/slplink.h
        libpurple/protocols/msn/slpmsg.h

ChangeLog: 

A quick and dirty hack to make MSN use the in-core code to perform FT.

This has the advantage of not requiring an on-disk file or socket that
the MSN code steals from the core.  That said, this is pretty bad code
which I'm only checking in as-is so that I can go back to using trunk
without it.

-------------- next part --------------
============================================================
--- libpurple/protocols/msn/slp.c	0b5fc641e7da6096b1bd8f18e10ffa02cd65c4bc
+++ libpurple/protocols/msn/slp.c	ba14bffed60ebb96b22c7c1e3ad44a08df2ed32e
@@ -96,6 +96,8 @@ msn_xfer_init(PurpleXfer *xfer)
 
 	g_free(content);
 	msn_slplink_send_queued_slpmsgs(slpcall->slplink);
+
+	purple_xfer_start(xfer, -1, NULL, 0);
 }
 
 void
@@ -131,6 +133,54 @@ msn_xfer_cancel(PurpleXfer *xfer)
 	}
 }
 
+gssize
+msn_xfer_write(const guchar *data, gsize len, PurpleXfer *xfer)
+{
+	MsnSlpCall *slpcall;
+
+	g_return_val_if_fail(xfer != NULL, -1);
+	g_return_val_if_fail(data != NULL, -1);
+	g_return_val_if_fail(len > 0, -1);
+
+	g_return_val_if_fail(purple_xfer_get_type(xfer) == PURPLE_XFER_SEND, -1);
+
+	slpcall = xfer->data;
+	/* Not sure I trust it'll be there */
+	g_return_val_if_fail(slpcall != NULL, -1);
+
+	g_return_val_if_fail(slpcall->xfer_msg != NULL, -1);
+
+	slpcall->u.outgoing.len = len;
+	slpcall->u.outgoing.data = data;
+	msn_slplink_send_msgpart(slpcall->slplink, slpcall->xfer_msg);
+	return MIN(1202, len);
+}
+
+gssize
+msn_xfer_read(guchar **data, PurpleXfer *xfer)
+{
+	MsnSlpCall *slpcall;
+	gsize len;
+
+	g_return_val_if_fail(xfer != NULL, -1);
+	g_return_val_if_fail(data != NULL, -1);
+
+	g_return_val_if_fail(purple_xfer_get_type(xfer) == PURPLE_XFER_RECEIVE, -1);
+
+	slpcall = xfer->data;
+	/* Not sure I trust it'll be there */
+	g_return_val_if_fail(slpcall != NULL, -1);
+
+	/* Just pass up the whole GByteArray. We'll make another. */
+	*data = slpcall->u.incoming_data->data;
+	len = slpcall->u.incoming_data->len;
+
+	g_byte_array_free(slpcall->u.incoming_data, FALSE);
+	slpcall->u.incoming_data = g_byte_array_new();
+
+	return len;
+}
+
 void
 msn_xfer_progress_cb(MsnSlpCall *slpcall, gsize total_length, gsize len, gsize offset)
 {
@@ -332,9 +382,7 @@ got_sessionreq(MsnSlpCall *slpcall, cons
 
 		account = slpcall->slplink->session->account;
 
-		slpcall->cb = msn_xfer_completed_cb;
 		slpcall->end_cb = msn_xfer_end_cb;
-		slpcall->progress_cb = msn_xfer_progress_cb;
 		slpcall->branch = g_strdup(branch);
 
 		slpcall->pending = TRUE;
@@ -357,7 +405,11 @@ got_sessionreq(MsnSlpCall *slpcall, cons
 			purple_xfer_set_init_fnc(xfer, msn_xfer_init);
 			purple_xfer_set_request_denied_fnc(xfer, msn_xfer_cancel);
 			purple_xfer_set_cancel_recv_fnc(xfer, msn_xfer_cancel);
+			purple_xfer_set_read_fnc(xfer, msn_xfer_read);
+			purple_xfer_set_write_fnc(xfer, msn_xfer_write);
 
+			slpcall->u.incoming_data = g_byte_array_new();
+
 			slpcall->xfer = xfer;
 			purple_xfer_ref(slpcall->xfer);
 
============================================================
--- libpurple/protocols/msn/slp.h	dc0dde5fc9f6fe677e799f5b3f179deca9440155
+++ libpurple/protocols/msn/slp.h	1555fcaf0304a6dd010a6cd891df48662dd986da
@@ -41,6 +41,9 @@ void msn_xfer_cancel(PurpleXfer *xfer);
 						   const guchar *body, gsize size);
 
 void msn_xfer_cancel(PurpleXfer *xfer);
+gssize msn_xfer_write(const guchar *data, gsize len, PurpleXfer *xfer);
+gssize msn_xfer_read(guchar **data, PurpleXfer *xfer);
+
 void msn_xfer_end_cb(MsnSlpCall *slpcall, MsnSession *session);
 
 void msn_queue_buddy_icon_request(MsnUser *user);
============================================================
--- libpurple/protocols/msn/slpcall.c	c5cffd20e8282ade7b1d83051ffa9deb5756e5b6
+++ libpurple/protocols/msn/slpcall.c	8e026624bfadbce92df43572f26207612b8db3b1
@@ -105,10 +105,13 @@ msn_slpcall_destroy(MsnSlpCall *slpcall)
 		slpcall->end_cb(slpcall, slpcall->slplink->session);
 
 	if (slpcall->xfer != NULL) {
+		if (purple_xfer_get_type(slpcall->xfer) == PURPLE_XFER_RECEIVE)
+			g_byte_array_free(slpcall->u.incoming_data, TRUE);
 		slpcall->xfer->data = NULL;
 		purple_xfer_unref(slpcall->xfer);
 	}
 
+
 	msn_slplink_remove_slpcall(slpcall->slplink, slpcall);
 
 	g_free(slpcall->id);
@@ -272,7 +275,8 @@ msn_slp_process_msg(MsnSlpLink *slplink,
 				slpcall->timer = 0;
 			}
 
-			slpcall->cb(slpcall, body, body_len);
+			if (slpcall->cb)
+				slpcall->cb(slpcall, body, body_len);
 
 			slpcall->wasted = TRUE;
 		}
============================================================
--- libpurple/protocols/msn/slpcall.h	13863cc3a700579662279fdb70c9fb520d5c2adf
+++ libpurple/protocols/msn/slpcall.h	704615e339ead6c0591938878f41c540024b06e0
@@ -72,6 +72,14 @@ struct _MsnSlpCall
 	char *data_info;
 
 	PurpleXfer *xfer;
+	union {
+		GByteArray *incoming_data;
+		struct {
+			gsize len;
+			const guchar *data;
+		} outgoing;
+	} u;
+	MsnSlpMessage *xfer_msg; /* A dirty hack */
 
 	MsnSlpCb cb;
 	void (*end_cb)(MsnSlpCall *slpcall, MsnSession *session);
============================================================
--- libpurple/protocols/msn/slplink.c	a1d28636ade1b68f9bbbee806ca0ff5904635a55
+++ libpurple/protocols/msn/slplink.c	a4bff4ae250b81bc6bd0b0b3b3b52fa97cdb9cfd
@@ -232,7 +232,7 @@ msn_slplink_send_msg(MsnSlpLink *slplink
 	}
 }
 
-static void
+void
 msn_slplink_send_msgpart(MsnSlpLink *slplink, MsnSlpMessage *slpmsg)
 {
 	MsnMessage *msg;
@@ -247,8 +247,14 @@ msn_slplink_send_msgpart(MsnSlpLink *slp
 
 	if (slpmsg->offset < real_size)
 	{
-		if (slpmsg->fp)
+		if (slpmsg->slpcall && slpmsg->slpcall->xfer && purple_xfer_get_type(slpmsg->slpcall->xfer) == PURPLE_XFER_SEND &&
+				purple_xfer_get_status(slpmsg->slpcall->xfer) == PURPLE_XFER_STATUS_STARTED)
 		{
+			len = MIN(1202, slpmsg->slpcall->u.outgoing.len);
+			msn_message_set_bin_data(msg, slpmsg->slpcall->u.outgoing.data, len);
+		}
+		else if (slpmsg->fp)
+		{
 			char data[1202];
 			len = fread(data, 1, sizeof(data), slpmsg->fp);
 			msn_message_set_bin_data(msg, data, len);
@@ -309,7 +315,13 @@ msg_ack(MsnMessage *msg, void *data)
 
 	if (slpmsg->offset < real_size)
 	{
-		msn_slplink_send_msgpart(slpmsg->slplink, slpmsg);
+		if (slpmsg->slpcall->xfer)
+		{
+			slpmsg->slpcall->xfer_msg = slpmsg;
+			purple_xfer_prpl_ready(slpmsg->slpcall->xfer);
+		}
+		else
+			msn_slplink_send_msgpart(slpmsg->slplink, slpmsg);
 	}
 	else
 	{
@@ -458,10 +470,10 @@ send_file_cb(MsnSlpCall *slpcall)
 
 	xfer = (PurpleXfer *)slpcall->xfer;
 	purple_xfer_start(slpcall->xfer, -1, NULL, 0);
-	slpmsg->fp = xfer->dest_fp;
 	if (g_stat(purple_xfer_get_local_filename(xfer), &st) == 0)
 		slpmsg->size = st.st_size;
-	xfer->dest_fp = NULL; /* Disable double fclose() */
+	else if (purple_xfer_get_size(xfer))
+		slpmsg->size = purple_xfer_get_size(xfer);
 
 	msn_slplink_send_slpmsg(slpcall->slplink, slpmsg);
 }
@@ -489,6 +501,7 @@ msn_slplink_process_msg(MsnSlpLink *slpl
 	const char *data;
 	guint64 offset;
 	gsize len;
+	PurpleXfer *xfer = NULL;
 
 	if (purple_debug_is_verbose())
 		msn_slpmsg_show(msg);
@@ -525,12 +538,12 @@ msn_slplink_process_msg(MsnSlpLink *slpl
 				if (slpmsg->flags == 0x20 ||
 				    slpmsg->flags == 0x1000020 || slpmsg->flags == 0x1000030)
 				{
-					PurpleXfer *xfer;
-
 					xfer = slpmsg->slpcall->xfer;
-
 					if (xfer != NULL)
 					{
+						slpmsg->ft = TRUE;
+						slpmsg->slpcall->xfer_msg = slpmsg;
+
 						purple_xfer_ref(xfer);
 						purple_xfer_start(xfer,	-1, NULL, 0);
 
@@ -540,14 +553,12 @@ msn_slplink_process_msg(MsnSlpLink *slpl
 							g_return_if_reached();
 						} else {
 							purple_xfer_unref(xfer);
-							slpmsg->fp = xfer->dest_fp;
-							xfer->dest_fp = NULL; /* Disable double fclose() */
 						}
 					}
 				}
 			}
 		}
-		if (!slpmsg->fp && slpmsg->size)
+		if (!slpmsg->fp && !slpmsg->ft && slpmsg->size)
 		{
 			slpmsg->buffer = g_try_malloc(slpmsg->size);
 			if (slpmsg->buffer == NULL)
@@ -574,6 +585,13 @@ msn_slplink_process_msg(MsnSlpLink *slpl
 		/* fseek(slpmsg->fp, offset, SEEK_SET); */
 		len = fwrite(data, 1, len, slpmsg->fp);
 	}
+	else if (slpmsg->ft)
+	{
+		xfer = slpmsg->slpcall->xfer;
+		slpmsg->slpcall->u.incoming_data =
+				g_byte_array_append(slpmsg->slpcall->u.incoming_data, (const guchar *)data, len);
+		purple_xfer_prpl_ready(xfer);
+	}
 	else if (slpmsg->size && slpmsg->buffer)
 	{
 		if (G_MAXSIZE - len < offset || (offset + len) > slpmsg->size)
@@ -732,7 +750,6 @@ msn_slplink_request_ft(MsnSlpLink *slpli
 
 	slpcall->session_init_cb = send_file_cb;
 	slpcall->end_cb = msn_xfer_end_cb;
-	slpcall->progress_cb = msn_xfer_progress_cb;
 	slpcall->cb = msn_xfer_completed_cb;
 	slpcall->xfer = xfer;
 	purple_xfer_ref(slpcall->xfer);
@@ -740,6 +757,8 @@ msn_slplink_request_ft(MsnSlpLink *slpli
 	slpcall->pending = TRUE;
 
 	purple_xfer_set_cancel_send_fnc(xfer, msn_xfer_cancel);
+	purple_xfer_set_read_fnc(xfer, msn_xfer_read);
+	purple_xfer_set_write_fnc(xfer, msn_xfer_write);
 
 	xfer->data = slpcall;
 
============================================================
--- libpurple/protocols/msn/slplink.h	76db17e4880fb0a3d73d5877e4c9397e33e2c4d5
+++ libpurple/protocols/msn/slplink.h	1074709379db252e5f89425dd305aca194878d29
@@ -84,6 +84,9 @@ void msn_slplink_request_ft(MsnSlpLink *
 void msn_slplink_process_msg(MsnSlpLink *slplink, MsnMessage *msg);
 void msn_slplink_request_ft(MsnSlpLink *slplink, PurpleXfer *xfer);
 
+/* Only exported for msn_xfer_write */
+void msn_slplink_send_msgpart(MsnSlpLink *slplink, MsnSlpMessage *slpmsg);
+
 void msn_slplink_request_object(MsnSlpLink *slplink,
 								const char *info,
 								MsnSlpCb cb,
============================================================
--- libpurple/protocols/msn/slpmsg.h	4c4b339777e3278a6ae18e1797a379496af0a315
+++ libpurple/protocols/msn/slpmsg.h	4295ba6ce1871d80c49f6cfcd3b56bf39779c933
@@ -55,6 +55,7 @@ struct _MsnSlpMessage
 	long flags;
 
 	FILE *fp;
+	gboolean ft;
 	PurpleStoredImage *img;
 	guchar *buffer;
 	long long offset;


More information about the Commits mailing list