/cpw/tomkiewicz/gg11: 31dc448fa178: Allow cancelling a file tran...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Tue Oct 23 08:03:08 EDT 2012


Changeset: 31dc448fa178cc60f70e9056fc6874312e3b78b7
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2012-10-23 14:03 +0200
Branch:	 default
URL: http://hg.pidgin.im/cpw/tomkiewicz/gg11/rev/31dc448fa178

Description:

Allow cancelling a file transfer

diffstat:

 libpurple/protocols/gg/edisc.c |  41 ++++++++++++++++++-----------------------
 1 files changed, 18 insertions(+), 23 deletions(-)

diffs (101 lines):

diff --git a/libpurple/protocols/gg/edisc.c b/libpurple/protocols/gg/edisc.c
--- a/libpurple/protocols/gg/edisc.c
+++ b/libpurple/protocols/gg/edisc.c
@@ -140,6 +140,7 @@ static void ggp_edisc_xfer_free(PurpleXf
 		return;
 
 	g_free(edisc_xfer->filename);
+	purple_http_conn_cancel(edisc_xfer->hc);
 
 	sdata = ggp_edisc_get_sdata(edisc_xfer->gc);
 	if (edisc_xfer->ticket_id != NULL)
@@ -153,6 +154,8 @@ static void ggp_edisc_xfer_free(PurpleXf
 
 static void ggp_edisc_xfer_error(PurpleXfer *xfer, const gchar *msg)
 {
+	if (purple_xfer_is_cancelled(xfer))
+		g_return_if_reached();
 	purple_xfer_set_status(xfer, PURPLE_XFER_STATUS_CANCEL_REMOTE);
 	purple_xfer_conversation_write(xfer, msg, TRUE);
 	purple_xfer_error(
@@ -214,6 +217,9 @@ static void ggp_edisc_xfer_init_authenti
 	ggp_edisc_xfer *edisc_xfer = purple_xfer_get_protocol_data(xfer);
 	gchar *data;
 
+	if (purple_xfer_is_cancelled(xfer))
+		return;
+
 	if (!success) {
 		ggp_edisc_xfer_error(xfer, _("Authentication failed"));
 		return;
@@ -255,6 +261,9 @@ static void ggp_edisc_xfer_init_ticket_s
 	JsonParser *parser;
 	JsonObject *ticket;
 
+	if (purple_xfer_is_cancelled(xfer))
+		return;
+
 	edisc_xfer->hc = NULL;
 
 	if (!purple_http_response_is_successfull(response)) {
@@ -374,7 +383,11 @@ static void ggp_edisc_xfer_reader(Purple
 		return;
 	}
 
-	stored = fread(buffer, 1, length, xfer->dest_fp);
+	if (xfer->dest_fp == NULL)
+		stored = -1;
+	else
+		stored = fread(buffer, 1, length, xfer->dest_fp);
+
 	if (stored < 0)
 		success = FALSE;
 	else {
@@ -468,6 +481,9 @@ static void ggp_edisc_xfer_sent(PurpleHt
 	JsonObject *result;
 	int result_status;
 
+	if (purple_xfer_is_cancelled(xfer))
+		return;
+
 	g_return_if_fail(edisc_xfer != NULL);
 
 	edisc_xfer->hc = NULL;
@@ -498,26 +514,7 @@ static void ggp_edisc_xfer_cancel(Purple
 {
 	g_return_if_fail(xfer != NULL);
 
-	if (purple_xfer_get_type(xfer) != PURPLE_XFER_SEND) {
-		purple_debug_error("gg", "ggp_edisc_xfer_start: "
-			"Not yet implemented\n");
-		return;
-	}
-
-	purple_debug_info("gg", "ggp_edisc_xfer_cancel(%p)\n", xfer);
-}
-
-static void ggp_edisc_xfer_end(PurpleXfer *xfer)
-{
-	g_return_if_fail(xfer != NULL);
-
-	if (purple_xfer_get_type(xfer) != PURPLE_XFER_SEND) {
-		purple_debug_error("gg", "ggp_edisc_xfer_start: "
-			"Not yet implemented\n");
-		return;
-	}
-
-	purple_debug_info("gg", "ggp_edisc_xfer_end(%p)\n", xfer);
+	ggp_edisc_xfer_free(xfer);
 }
 
 PurpleXfer * ggp_edisc_xfer_new(PurpleConnection *gc, const char *who)
@@ -537,9 +534,7 @@ PurpleXfer * ggp_edisc_xfer_new(PurpleCo
 
 	purple_xfer_set_init_fnc(xfer, ggp_edisc_xfer_init);
 	purple_xfer_set_start_fnc(xfer, ggp_edisc_xfer_start);
-
 	purple_xfer_set_cancel_send_fnc(xfer, ggp_edisc_xfer_cancel);
-	purple_xfer_set_end_fnc(xfer, ggp_edisc_xfer_end);
 
 	return xfer;
 }



More information about the Commits mailing list