/cpw/tomkiewicz/gg11: 2179667660bc: Edisc authentication, file t...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Sun Oct 21 19:26:30 EDT 2012


Changeset: 2179667660bc4d090041191066da77432aa57908
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2012-10-22 01:26 +0200
Branch:	 default
URL: http://hg.pidgin.im/cpw/tomkiewicz/gg11/rev/2179667660bc

Description:

Edisc authentication, file transfer implementation started

diffstat:

 libpurple/protocols/gg/Makefile.am |    4 +-
 libpurple/protocols/gg/ggdrive.c   |  384 +++++++++++++++++++++++++++---------
 libpurple/protocols/gg/ggdrive.h   |   18 +-
 libpurple/protocols/gg/gg.c        |   10 +-
 libpurple/protocols/gg/gg.h        |    2 +
 5 files changed, 307 insertions(+), 111 deletions(-)

diffs (truncated from 534 to 300 lines):

diff --git a/libpurple/protocols/gg/Makefile.am b/libpurple/protocols/gg/Makefile.am
--- a/libpurple/protocols/gg/Makefile.am
+++ b/libpurple/protocols/gg/Makefile.am
@@ -62,10 +62,10 @@ GGSOURCES = \
 	chat.h \
 	deprecated.c \
 	deprecated.h \
+	edisc.c \
+	edisc.h \
 	gg.c \
 	gg.h \
-	ggdrive.c \
-	ggdrive.h \
 	html.c \
 	html.h \
 	image.c \
diff --git a/libpurple/protocols/gg/ggdrive.c b/libpurple/protocols/gg/edisc.c
rename from libpurple/protocols/gg/ggdrive.c
rename to libpurple/protocols/gg/edisc.c
--- a/libpurple/protocols/gg/ggdrive.c
+++ b/libpurple/protocols/gg/edisc.c
@@ -1,133 +1,317 @@
-#include "ggdrive.h"
+#include "edisc.h"
 
 #include <debug.h>
 
 #include "gg.h"
 #include "libgaduw.h"
+#include <http.h>
 
-#define GGP_GGDRIVE_HOSTNAME "MyComputer"
-#define GGP_GGDRIVE_OS "WINNT x86-msvc"
-#define GGP_GGDRIVE_TYPE "desktop"
+#define GGP_EDISC_HOSTNAME "MyComputer"
+#define GGP_EDISC_OS "WINNT x86-msvc"
+#define GGP_EDISC_TYPE "desktop"
 
-#define GGP_GGDRIVE_RESPONSE_MAX 1024
+#define GGP_EDISC_RESPONSE_MAX 10240
+
+typedef struct _ggp_edisc_auth_data ggp_edisc_auth_data;
+
+typedef struct _ggp_edisc_xfer ggp_edisc_xfer;
+
+struct _ggp_edisc_session_data
+{
+	PurpleHttpCookieJar *cookies;
+	gchar *security_token;
+
+	PurpleHttpConnection *auth_request;
+	gboolean auth_done;
+	GList *auth_pending;
+};
+
+struct _ggp_edisc_xfer
+{
+	PurpleConnection *gc;
+};
+
+typedef void (*ggp_ggdrive_auth_cb)(PurpleConnection *gc, gboolean success,
+	gpointer user_data);
+
+static void ggp_ggdrive_auth(PurpleConnection *gc, ggp_ggdrive_auth_cb cb,
+	gpointer user_data);
+
+static void ggp_edisc_xfer_free(PurpleXfer *xfer);
+
+/*******************************************************************************
+ * Setting up.
+ ******************************************************************************/
+
+static inline ggp_edisc_session_data *
+ggp_edisc_get_sdata(PurpleConnection *gc)
+{
+	GGPInfo *accdata = purple_connection_get_protocol_data(gc);
+	return accdata->edisc_data;
+}
+
+void ggp_edisc_setup(PurpleConnection *gc)
+{
+	GGPInfo *accdata = purple_connection_get_protocol_data(gc);
+	ggp_edisc_session_data *sdata = g_new0(ggp_edisc_session_data, 1);
+
+	accdata->edisc_data = sdata;
+
+	sdata->cookies = purple_http_cookie_jar_new();
+}
+
+void ggp_edisc_cleanup(PurpleConnection *gc)
+{
+	ggp_edisc_session_data *sdata = ggp_edisc_get_sdata(gc);
+
+	purple_http_conn_cancel(sdata->auth_request);
+	g_list_free_full(sdata->auth_pending, g_free);
+	g_free(sdata->security_token);
+
+	purple_http_cookie_jar_unref(sdata->cookies);
+
+	g_free(sdata);
+}
+
+/*******************************************************************************
+ * Sending a file.
+ ******************************************************************************/
+
+static void ggp_edisc_xfer_init(PurpleXfer *xfer);
+static void ggp_edisc_xfer_init_authenticated(PurpleConnection *gc,
+	gboolean success, gpointer _xfer);
+
+static void ggp_edisc_xfer_error(PurpleXfer *xfer, const gchar *msg);
+
+static void ggp_edisc_xfer_free(PurpleXfer *xfer)
+{
+	ggp_edisc_xfer *edisc_xfer = purple_xfer_get_protocol_data(xfer);
+
+	if (edisc_xfer == NULL)
+		return;
+
+	g_free(edisc_xfer);
+	purple_xfer_set_protocol_data(xfer, NULL);
+}
+
+static void ggp_edisc_xfer_error(PurpleXfer *xfer, const gchar *msg)
+{
+	purple_xfer_error(
+		purple_xfer_get_type(xfer),
+		purple_xfer_get_account(xfer),
+		purple_xfer_get_remote_user(xfer),
+		msg);
+	ggp_edisc_xfer_free(xfer);
+}
+
+gboolean ggp_edisc_xfer_can_receive_file(PurpleConnection *gc, const char *who)
+{
+	return TRUE; /* TODO: only online, buddies (?) */
+}
+
+static void ggp_edisc_xfer_init(PurpleXfer *xfer)
+{
+	ggp_edisc_xfer *edisc_xfer = purple_xfer_get_protocol_data(xfer);
+
+	if (purple_xfer_get_type(xfer) != PURPLE_XFER_SEND) {
+		purple_debug_error("gg", "ggp_edisc_xfer_init: "
+			"Not yet implemented\n");
+		return;
+	}
+
+	ggp_ggdrive_auth(edisc_xfer->gc, ggp_edisc_xfer_init_authenticated, xfer);
+}
+
+static void ggp_edisc_xfer_init_authenticated(PurpleConnection *gc,
+	gboolean success, gpointer _xfer)
+{
+	PurpleXfer *xfer = _xfer;
+
+	if (!success) {
+		ggp_edisc_xfer_error(xfer, _("Authentication failed"));
+		return;
+	}
+
+	/* TODO: requesting a ticket */
+
+	purple_xfer_start(xfer, -1, NULL, 0);
+}
+
+static void ggp_edisc_xfer_start(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", "Starting a file transfer...\n");
+}
+
+PurpleXfer * ggp_edisc_xfer_new(PurpleConnection *gc, const char *who)
+{
+	PurpleXfer *xfer;
+	ggp_edisc_xfer *edisc_xfer;
+
+	g_return_val_if_fail(gc != NULL, NULL);
+	g_return_val_if_fail(who != NULL, NULL);
+
+	xfer = purple_xfer_new(purple_connection_get_account(gc),
+		PURPLE_XFER_SEND, who);
+	edisc_xfer = g_new0(ggp_edisc_xfer, 1);
+	purple_xfer_set_protocol_data(xfer, edisc_xfer);
+
+	edisc_xfer->gc = gc;
+
+	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, bonjour_xfer_cancel_send);
+	//purple_xfer_set_end_fnc(xfer, bonjour_xfer_end);
+
+	return xfer;
+}
+
+void ggp_edisc_xfer_send_file(PurpleConnection *gc, const char *who,
+	const char *filename)
+{
+	PurpleXfer *xfer;
+
+	g_return_if_fail(gc != NULL);
+	g_return_if_fail(who != NULL);
+
+	/* Nothing interesting here, this code is common among prpls.
+	 * See ggp_edisc_new_xfer. */
+
+	xfer = ggp_edisc_xfer_new(gc, who);
+	if (filename)
+		purple_xfer_request_accepted(xfer, filename);
+	else
+		purple_xfer_request(xfer);
+}
 
 /*******************************************************************************
  * Authentication
  ******************************************************************************/
 
-typedef void (*ggp_ggdrive_authentication_cb)(const gchar *security_token,
-	gpointer user_data);
+struct _ggp_edisc_auth_data
+{
+	ggp_ggdrive_auth_cb cb;
+	gpointer user_data;
+};
 
-static void ggp_ggdrive_authenticate(PurpleConnection *gc,
-	ggp_ggdrive_authentication_cb cb, gpointer user_data);
+static void ggp_ggdrive_auth_done(PurpleHttpConnection *hc,
+	PurpleHttpResponse *response, gpointer user_data);
 
-#if 0
-static void ggp_ggdrive_authenticate_done(PurpleUtilFetchUrlData *url_data,
-	gpointer _user_data, const gchar *url_text, gsize len,
-	const gchar *error_message);
-#endif
-
-typedef struct
+static void ggp_ggdrive_auth(PurpleConnection *gc, ggp_ggdrive_auth_cb cb,
+	gpointer user_data)
 {
-	PurpleConnection *gc;
-	ggp_ggdrive_authentication_cb cb;
-	gpointer user_data;
-} ggp_ggdrive_authenticate_data;
-
-/******************************************************************************/
-
-static void ggp_ggdrive_authenticate(PurpleConnection *gc,
-	ggp_ggdrive_authentication_cb cb, gpointer user_data)
-{
-#if 0
-	PurpleAccount *account = purple_connection_get_account(gc);
+	GGPInfo *accdata = purple_connection_get_protocol_data(gc);
+	ggp_edisc_session_data *sdata = ggp_edisc_get_sdata(gc);
+	ggp_edisc_auth_data *auth;
 	const gchar *imtoken;
-	gchar *request, *metadata;
-	ggp_ggdrive_authenticate_data *req_data;
+	gchar *metadata;
+	PurpleHttpRequest *req;
 
 	imtoken = ggp_get_imtoken(gc);
 	if (!imtoken)
 	{
-		cb(NULL, user_data);
-		return;
-	}
-	
-	metadata = g_strdup_printf("{"
-		"\"id\": \"%032x\", "
-		"\"name\": \"" GGP_GGDRIVE_HOSTNAME "\", "
-		"\"os_version\": \"" GGP_GGDRIVE_OS "\", "
-		"\"client_version\": \"%s\", "
-		"\"type\": \"" GGP_GGDRIVE_TYPE "\"}",
-		g_random_int_range(1, 1 << 16),
-		ggp_libgaduw_version(gc));
-	
-	request = g_strdup_printf(
-		"PUT /signin HTTP/1.1\r\n"
-		"Host: drive.mpa.gg.pl\r\n"
-		"Authorization: IMToken %s\r\n"
-		"X-gged-user: gg/pl:%u\r\n"
-		"X-gged-client-metadata: %s\r\n"
-		"X-gged-api-version: 6\r\n"
-		"Content-Type: application/x-www-form-urlencoded\r\n"
-		"Content-Length: 0\r\n"
-		"\r\n",
-		imtoken, ggp_own_uin(gc), metadata);
-
-	req_data = g_new0(ggp_ggdrive_authenticate_data, 1);
-	req_data->gc = gc;
-	req_data->cb = cb;



More information about the Commits mailing list