/soc/2012/tomkiewicz/gg: bc2f2ea7b5ab: Gadu-Gadu: refactoring of...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Thu Jul 5 13:31:55 EDT 2012


Changeset: bc2f2ea7b5ab03c252ead08a8bfee9bc52fb179f
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2012-07-02 00:58 +0200
Branch:	 soc.2012.gg
URL: http://hg.pidgin.im/soc/2012/tomkiewicz/gg/rev/bc2f2ea7b5ab

Description:

Gadu-Gadu: refactoring of account registration done

diffstat:

 libpurple/protocols/gg/account.c  |  305 ++++++++++++++++++++++++++-----------
 libpurple/protocols/gg/account.h  |    7 +-
 libpurple/protocols/gg/libgaduw.c |    7 +-
 libpurple/protocols/gg/libgaduw.h |    3 +-
 libpurple/protocols/gg/purplew.c  |    5 +
 libpurple/protocols/gg/utils.c    |    9 +
 libpurple/protocols/gg/utils.h    |    2 +
 7 files changed, 240 insertions(+), 98 deletions(-)

diffs (truncated from 550 to 300 lines):

diff --git a/libpurple/protocols/gg/account.c b/libpurple/protocols/gg/account.c
--- a/libpurple/protocols/gg/account.c
+++ b/libpurple/protocols/gg/account.c
@@ -18,27 +18,30 @@
 	ggp_account_token_cb callback;
 	PurpleConnection *gc;
 	void *user_data;
-
-	ggp_libgaduw_http_req *req;
 } ggp_account_token_reqdata;
 
-static void ggp_account_token_response(struct gg_http *h, gboolean success, gboolean cancelled, gpointer _reqdata);
+static void ggp_account_token_response(struct gg_http *h, gboolean success,
+	gboolean cancelled, gpointer _reqdata);
 
 /******************************************************************************/
 
 void ggp_account_token_free(ggp_account_token *token)
 {
+	if (!token)
+		return;
 	g_free(token->id);
 	g_free(token->data);
 	g_free(token);
 }
 
-void ggp_account_token_request(PurpleConnection *gc, ggp_account_token_cb callback, void *user_data)
+void ggp_account_token_request(PurpleConnection *gc,
+	ggp_account_token_cb callback, void *user_data)
 {
 	struct gg_http *h;
 	ggp_account_token_reqdata *reqdata;
 
-	purple_debug_info("gg", "ggp_account_token_request: requesting token...\n");
+	purple_debug_info("gg", "ggp_account_token_request: "
+		"requesting token...\n");
 
 	if (!ggp_deprecated_setup_proxy(gc))
 	{
@@ -58,7 +61,8 @@
 	reqdata->callback = callback;
 	reqdata->gc = gc;
 	reqdata->user_data = user_data;
-	reqdata->req = ggp_libgaduw_http_watch(gc, h, ggp_account_token_response, reqdata, TRUE);
+	ggp_libgaduw_http_watch(gc, h, ggp_account_token_response, reqdata,
+		TRUE);
 }
 
 static void ggp_account_token_response(struct gg_http *h, gboolean success,
@@ -71,10 +75,12 @@
 	g_assert(!(success && cancelled));
 	
 	if (cancelled)
-		purple_debug_info("gg", "ggp_account_token_handler: cancelled\n");
+		purple_debug_info("gg", "ggp_account_token_handler: "
+			"cancelled\n");
 	else if (success)
 	{
-		purple_debug_info("gg", "ggp_account_token_handler: got token\n");
+		purple_debug_info("gg", "ggp_account_token_handler: "
+			"got token\n");
 	
 		token = g_new(ggp_account_token, 1);
 	
@@ -82,6 +88,7 @@
 		token->id = g_strdup(token_info->tokenid);
 		token->size = h->body_size;
 		token->data = g_memdup(h->body, token->size);
+		token->length = token_info->length;
 	}
 	else
 	{
@@ -89,10 +96,9 @@
 		purple_notify_error(
 			purple_connection_get_account(reqdata->gc),
 			_("Token Error"),
-			_("Unable to fetch the token.\n"), NULL);
+			_("Unable to fetch the token."), NULL);
 	}
 	
-	gg_token_free(h);
 	reqdata->callback(reqdata->gc, token, reqdata->user_data);
 	g_free(reqdata);
 }
@@ -105,93 +111,118 @@
 {
 	ggp_account_token *token;
 	PurpleConnection *gc;
+	
+	gchar *email;
+	gchar *password;
+	gchar *token_value;
+	gboolean password_remember;
 } ggp_account_register_data;
 
-static void ggp_account_register_dialog(PurpleConnection *gc, ggp_account_token *token, gpointer user_data);
-static void ggp_account_register_dialog_ok(ggp_account_register_data *register_data, PurpleRequestFields *fields);
-static void ggp_account_register_dialog_cancel(ggp_account_register_data *register_data, PurpleRequestFields *fields);
-static void ggp_account_register_completed(ggp_account_register_data *register_data, gboolean success);
+static void ggp_account_register_dialog(PurpleConnection *gc,
+	ggp_account_token *token, gpointer user_data);
+static void ggp_account_register_dialog_ok(
+	ggp_account_register_data *register_data, PurpleRequestFields *fields);
+static void ggp_account_register_dialog_invalid(
+	ggp_account_register_data *register_data, const gchar *message);
+static void ggp_account_register_dialog_cancel(
+	ggp_account_register_data *register_data, PurpleRequestFields *fields);
+static void ggp_account_register_response(struct gg_http *h, gboolean success,
+	gboolean cancelled, gpointer _reqdata);
+static void ggp_account_register_completed(
+	ggp_account_register_data *register_data, gboolean success);
+
+#define GGP_ACCOUNT_REGISTER_TITLE _("Register New Gadu-Gadu Account")
 
 /******************************************************************************/
 
-static void ggp_account_register_completed(ggp_account_register_data *register_data, gboolean success)
-{
-	PurpleAccount *account = purple_connection_get_account(register_data->gc);
-	
-	ggp_account_token_free(register_data->token);
-	g_free(register_data);
-	
-	purple_account_disconnect(account);
-	purple_account_register_completed(account, TRUE);
-}
-
 void ggp_account_register(PurpleAccount *account)
 {
 	PurpleConnection *gc = purple_account_get_connection(account);
+	ggp_account_register_data *register_data;
 	
 	purple_debug_info("gg", "ggp_account_register\n");
 	
-	ggp_account_token_request(gc, ggp_account_register_dialog, NULL);
+	register_data = g_new0(ggp_account_register_data, 1);
+	register_data->gc = gc;
+	register_data->password_remember = TRUE;
+	
+	ggp_account_token_request(gc, ggp_account_register_dialog,
+		register_data);
 }
 
-static void ggp_account_register_dialog(PurpleConnection *gc, ggp_account_token *token, gpointer user_data)
+static void ggp_account_register_dialog(PurpleConnection *gc,
+	ggp_account_token *token, gpointer _register_data)
 {
 	PurpleAccount *account = purple_connection_get_account(gc);
 	PurpleRequestFields *fields;
-	PurpleRequestFieldGroup *group;
+	PurpleRequestFieldGroup *main_group, *password_group, *token_group;
 	PurpleRequestField *field;
-	ggp_account_register_data *register_data;
+	ggp_account_register_data *register_data = _register_data;
 	
 	purple_debug_info("gg", "ggp_account_register_dialog(%x, %x, %x)\n",
-		(unsigned int)gc, (unsigned int)token, (unsigned int)user_data);
+		(unsigned int)gc, (unsigned int)token,
+		(unsigned int)_register_data);
 	if (!token)
 	{
-		purple_account_disconnect(account);
-		purple_account_register_completed(account, FALSE);
+		ggp_account_register_completed(register_data, FALSE);
 		return;
 	}
 	
-	// TODO: required fields
 	fields = purple_request_fields_new();
-	group = purple_request_field_group_new(NULL);
-	purple_request_fields_add_group(fields, group);
+	main_group = purple_request_field_group_new(NULL);
+	purple_request_fields_add_group(fields, main_group);
 	
-	field = purple_request_field_string_new("email", _("Email"), "", FALSE);
-	purple_request_field_group_add_field(group, field);
+	field = purple_request_field_string_new("email", _("Email"),
+		register_data->email, FALSE);
+	purple_request_field_set_required(field, TRUE);
+	purple_request_field_group_add_field(main_group, field);
+
+	password_group = purple_request_field_group_new(_("Password"));
+	purple_request_fields_add_group(fields, password_group);
+
+	field = purple_request_field_string_new("password1", _("Password"),
+		register_data->password, FALSE);
+	purple_request_field_set_required(field, TRUE);
+	purple_request_field_string_set_masked(field, TRUE);
+	purple_request_field_group_add_field(password_group, field);
 	
-	field = purple_request_field_string_new("password1", _("Password"), "",
+	field = purple_request_field_string_new("password2",
+		_("Password (again)"), register_data->password, FALSE);
+	purple_request_field_set_required(field, TRUE);
+	purple_request_field_string_set_masked(field, TRUE);
+	purple_request_field_group_add_field(password_group, field);
+	
+	field = purple_request_field_bool_new("password_remember",
+		_("Remember password"), register_data->password_remember);
+	purple_request_field_group_add_field(password_group, field);
+	
+	token_group = purple_request_field_group_new(_("Captcha"));
+	purple_request_fields_add_group(fields, token_group);
+	
+	field = purple_request_field_string_new("token_value",
+		_("Enter text from image below"), register_data->token_value,
 		FALSE);
-	purple_request_field_string_set_masked(field, TRUE);
-	purple_request_field_group_add_field(group, field);
-	
-	field = purple_request_field_string_new("password2", _("Password (again)"), "",
-		FALSE);
-	purple_request_field_string_set_masked(field, TRUE);
-	purple_request_field_group_add_field(group, field);
-	
-	//TODO: move it into a new group?
-	field = purple_request_field_string_new("token_value",
-		_("Enter captcha text"), "", FALSE);
-	purple_request_field_group_add_field(group, field);
+	purple_request_field_set_required(field, TRUE);
+	purple_request_field_group_add_field(token_group, field);
 	
 	field = purple_request_field_image_new("token_image", _("Captcha"),
 		token->data, token->size);
-	purple_request_field_group_add_field(group, field);
+	purple_request_field_group_add_field(token_group, field);
 	
-	register_data = g_new(ggp_account_register_data, 1);
-	register_data->gc = gc;
 	register_data->token = token;
+	register_data->password = NULL;
 	
 	purple_request_fields(gc,
-		_("Register New Gadu-Gadu Account"),
-		_("Register New Gadu-Gadu Account"),
+		GGP_ACCOUNT_REGISTER_TITLE,
+		GGP_ACCOUNT_REGISTER_TITLE,
 		_("Please, fill in the following fields"), fields,
 		_("OK"), G_CALLBACK(ggp_account_register_dialog_ok),
 		_("Cancel"), G_CALLBACK(ggp_account_register_dialog_cancel),
 		account, NULL, NULL, register_data);
 }
 
-static void ggp_account_register_dialog_cancel(ggp_account_register_data *register_data, PurpleRequestFields *fields)
+static void ggp_account_register_dialog_cancel(
+	ggp_account_register_data *register_data, PurpleRequestFields *fields)
 {
 	purple_debug_info("gg", "ggp_account_register_dialog_cancel(%x, %x)\n",
 		(unsigned int)register_data, (unsigned int)fields);
@@ -199,60 +230,150 @@
 	ggp_account_register_completed(register_data, FALSE);
 }
 
-static void ggp_account_register_dialog_ok(ggp_account_register_data *register_data, PurpleRequestFields *fields)
+static void ggp_account_register_dialog_ok(
+	ggp_account_register_data *register_data, PurpleRequestFields *fields)
 {
-	PurpleAccount *account = purple_connection_get_account(register_data->gc);
-	const gchar *email, *password1, *password2, *token_value;
+	const gchar *password2;
 	struct gg_http *h;
-	struct gg_pubdir *register_result;
-	uin_t uin;
 
-	purple_debug_info("gg", "ggp_account_register_dialog_ok(%x, %x)\n",
+	purple_debug_misc("gg", "ggp_account_register_dialog_ok(%x, %x)\n",
 		(unsigned int)register_data, (unsigned int)fields);
 
-	email = purple_request_fields_get_string(fields, "email");
-	password1 = purple_request_fields_get_string(fields, "password1");
+	g_free(register_data->email);
+	g_free(register_data->password);
+	g_free(register_data->token_value);
+	
+	register_data->email = g_strdup(
+		purple_request_fields_get_string(fields, "email"));
+	register_data->password = g_strdup(
+		purple_request_fields_get_string(fields, "password1"));
 	password2 = purple_request_fields_get_string(fields, "password2");
-	token_value = purple_request_fields_get_string(fields, "token_value");
+	register_data->password_remember =
+		purple_request_fields_get_bool(fields, "password_remember");
+	register_data->token_value = g_strdup(
+		purple_request_fields_get_string(fields, "token_value"));
 
-	g_assert(email != NULL);
-	g_assert(password1 != NULL);
+	g_assert(register_data->email != NULL);
+	g_assert(register_data->password != NULL);
 	g_assert(password2 != NULL);
-	g_assert(token_value != NULL);
+	g_assert(register_data->token_value != NULL);
 
-	if (g_utf8_collate(password1, password2) != 0)
+	if (g_utf8_collate(register_data->password, password2) != 0)
 	{
-		purple_debug_warning("gg", "ggp_account_register_dialog_ok: validation failed - passwords does not match\n");
-		purple_notify_error(purple_connection_get_account(register_data->gc),
-			_("TODO: title"),
-			_("Passwords do not match"), NULL);



More information about the Commits mailing list