/cpw/tomkiewicz/gg11: c6d3ad1669c9: Gadu-Gadu: support file tran...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Wed Nov 7 12:37:04 EST 2012


Changeset: c6d3ad1669c978f2be2204379d0d3ad7cbb4d774
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2012-11-07 18:36 +0100
Branch:	 default
URL: http://hg.pidgin.im/cpw/tomkiewicz/gg11/rev/c6d3ad1669c9

Description:

Gadu-Gadu: support file transfers to legacy clients

diffstat:

 libpurple/protocols/gg/edisc.c |  62 +++++++++++++++++++++++++++++------------
 1 files changed, 43 insertions(+), 19 deletions(-)

diffs (132 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
@@ -48,6 +48,13 @@ struct _ggp_edisc_xfer
 	int already_read;
 };
 
+typedef enum
+{
+	GGP_EDISC_XFER_ACK_STATUS_UNKNOWN,
+	GGP_EDISC_XFER_ACK_STATUS_ALLOWED,
+	GGP_EDISC_XFER_ACK_STATUS_REJECTED
+} ggp_edisc_xfer_ack_status;
+
 typedef void (*ggp_ggdrive_auth_cb)(PurpleConnection *gc, gboolean success,
 	gpointer user_data);
 
@@ -66,6 +73,9 @@ static void ggp_edisc_xfer_cancel(Purple
 static const gchar * ggp_edisc_xfer_ticket_url(const gchar *ticket_id);
 static void ggp_edisc_xfer_progress_watcher(PurpleHttpConnection *hc,
 	gboolean reading_state, int processed, int total, gpointer _xfer);
+static ggp_edisc_xfer_ack_status
+ggp_edisc_xfer_parse_ack_status(const gchar *str);
+
 
 /* Sending a file. */
 static void ggp_edisc_xfer_send_ticket_changed(PurpleConnection *gc,
@@ -216,13 +226,15 @@ void ggp_edisc_xfer_ticket_changed(Purpl
 	PurpleXfer *xfer;
 	JsonParser *parser;
 	JsonObject *ticket;
-	const gchar *ticket_id, *ack_status, *send_status;
-	gboolean is_allowed, is_rejected, is_completed;
+	const gchar *ticket_id, *send_status;
+	ggp_edisc_xfer_ack_status ack_status;
+	gboolean is_completed;
 
 	parser = ggp_json_parse(data);
 	ticket = json_node_get_object(json_parser_get_root(parser));
 	ticket_id = json_object_get_string_member(ticket, "id");
-	ack_status = json_object_get_string_member(ticket, "ack_status");
+	ack_status = ggp_edisc_xfer_parse_ack_status(
+		json_object_get_string_member(ticket, "ack_status"));
 	send_status = json_object_get_string_member(ticket, "send_status");
 
 	xfer = g_hash_table_lookup(sdata->xfers_initialized, ticket_id);
@@ -235,20 +247,6 @@ void ggp_edisc_xfer_ticket_changed(Purpl
 		return;
 	}
 
-	is_allowed = is_rejected = FALSE;
-	if (g_strcmp0("unknown", ack_status) == 0) {
-		/* do nothing */
-	} else if (g_strcmp0("rejected", ack_status) == 0)
-		is_rejected = TRUE;
-	else if (g_strcmp0("allowed", ack_status) == 0)
-		is_allowed = TRUE;
-	else {
-		purple_debug_warning("gg", "ggp_edisc_event_ticket_changed: "
-			"unknown ack_status=%s\n", ack_status);
-		g_object_unref(parser);
-		return;
-	}
-
 	is_completed = FALSE;
 	if (g_strcmp0("in_progress", send_status) == 0) {
 		/* do nothing */
@@ -269,8 +267,9 @@ void ggp_edisc_xfer_ticket_changed(Purpl
 		if (is_completed)
 			ggp_edisc_xfer_recv_ticket_completed(xfer);
 	} else {
-		if (is_allowed || is_rejected)
-			ggp_edisc_xfer_send_ticket_changed(gc, xfer, is_allowed);
+		if (ack_status != GGP_EDISC_XFER_ACK_STATUS_UNKNOWN)
+			ggp_edisc_xfer_send_ticket_changed(gc, xfer, ack_status
+				== GGP_EDISC_XFER_ACK_STATUS_ALLOWED);
 	}
 
 }
@@ -316,6 +315,23 @@ static void ggp_edisc_xfer_progress_watc
 	purple_xfer_update_progress(xfer);
 }
 
+static ggp_edisc_xfer_ack_status
+ggp_edisc_xfer_parse_ack_status(const gchar *str)
+{
+	g_return_val_if_fail(str != NULL, GGP_EDISC_XFER_ACK_STATUS_UNKNOWN);
+
+	if (g_strcmp0("unknown", str) == 0)
+		return GGP_EDISC_XFER_ACK_STATUS_UNKNOWN;
+	if (g_strcmp0("allowed", str) == 0)
+		return GGP_EDISC_XFER_ACK_STATUS_ALLOWED;
+	if (g_strcmp0("rejected", str) == 0)
+		return GGP_EDISC_XFER_ACK_STATUS_REJECTED;
+
+	purple_debug_warning("gg", "ggp_edisc_xfer_parse_ack_status: "
+		"unknown status (%s)\n", str);
+	return GGP_EDISC_XFER_ACK_STATUS_UNKNOWN;
+}
+
 /*******************************************************************************
  * Sending a file.
  ******************************************************************************/
@@ -401,6 +417,7 @@ static void ggp_edisc_xfer_send_init_tic
 	PurpleXfer *xfer = _xfer;
 	ggp_edisc_xfer *edisc_xfer = purple_xfer_get_protocol_data(xfer);
 	const gchar *data = purple_http_response_get_data(response);
+	ggp_edisc_xfer_ack_status ack_status;
 	JsonParser *parser;
 	JsonObject *ticket;
 
@@ -429,6 +446,9 @@ static void ggp_edisc_xfer_send_init_tic
 	ticket = json_object_get_object_member(ticket, "send_ticket");
 	edisc_xfer->ticket_id = g_strdup(json_object_get_string_member(
 		ticket, "id"));
+	ack_status = ggp_edisc_xfer_parse_ack_status(
+		json_object_get_string_member(ticket, "ack_status"));
+	/* send_mode: "normal", "publink" (for legacy clients) */
 
 	g_object_unref(parser);
 
@@ -446,6 +466,10 @@ static void ggp_edisc_xfer_send_init_tic
 		edisc_xfer->ticket_id, xfer);
 	g_hash_table_insert(sdata->xfers_history,
 		g_strdup(edisc_xfer->ticket_id), GINT_TO_POINTER(1));
+
+	if (ack_status != GGP_EDISC_XFER_ACK_STATUS_UNKNOWN)
+		ggp_edisc_xfer_send_ticket_changed(edisc_xfer->gc, xfer,
+			ack_status == GGP_EDISC_XFER_ACK_STATUS_ALLOWED);
 }
 
 void ggp_edisc_xfer_send_ticket_changed(PurpleConnection *gc, PurpleXfer *xfer,



More information about the Commits mailing list