Mercurial > pidgin.yaz
diff libpurple/protocols/gg/gg.c @ 32737:03a55a2997d1
Gadu-Gadu: Fixed password change dialog and problems with connecting to accounts with non-ASCII passwords. Fixes #14652
author | tomkiewicz@cpw.pidgin.im |
---|---|
date | Mon, 10 Oct 2011 23:39:33 +0000 |
parents | 1aebe64a412b |
children | f877a2315d7e |
line wrap: on
line diff
--- a/libpurple/protocols/gg/gg.c Sat Oct 08 23:07:45 2011 +0000 +++ b/libpurple/protocols/gg/gg.c Mon Oct 10 23:39:33 2011 +0000 @@ -616,75 +616,137 @@ gc); } -/* ----- CHANGE PASSWORD ------------------------------------------------ */ - -static void ggp_callback_change_passwd_ok(PurpleConnection *gc, PurpleRequestFields *fields) +/* ----- CHANGE PASSWORD ---------------------------------------------------- */ + +typedef struct +{ + guint inpa; + struct gg_http *http_req; + gchar *new_password; + PurpleAccount *account; +} ggp_change_passwd_request; + +static void ggp_callback_change_passwd_handler(gpointer _req, gint fd, + PurpleInputCondition cond) +{ + ggp_change_passwd_request *req = _req; + const char *messagesTitle = + _("Change password for the Gadu-Gadu account"); + + purple_input_remove(req->inpa); + + if (gg_pubdir_watch_fd(req->http_req) == -1 || + req->http_req->state == GG_STATE_ERROR) + goto exit_error; + + if (req->http_req->state != GG_STATE_DONE) + { + req->inpa = ggp_http_input_add(req->http_req, + ggp_callback_change_passwd_handler, req); + return; + } + + if (req->http_req->data != NULL && + ((struct gg_pubdir*)req->http_req->data)->success == 1) + { + purple_account_set_password(req->account, req->new_password); + purple_notify_info(req->account, messagesTitle, + _("Password was changed successfully!"), NULL); + goto exit_cleanup; + } + +exit_error: + purple_notify_error(req->account, messagesTitle, + _("Unable to change password. Error occurred.\n"), NULL); + +exit_cleanup: + gg_pubdir_free(req->http_req); + g_free(req->new_password); + g_free(req); +} + +static void ggp_callback_change_passwd_ok(PurpleConnection *gc, + PurpleRequestFields *fields) { PurpleAccount *account; GGPInfo *info = purple_connection_get_protocol_data(gc); struct gg_http *h; - gchar *cur, *p1, *p2, *t; - - cur = charset_convert( - purple_request_fields_get_string(fields, "password_cur"), - "UTF-8", "CP1250"); - p1 = charset_convert( - purple_request_fields_get_string(fields, "password1"), - "UTF-8", "CP1250"); - p2 = charset_convert( - purple_request_fields_get_string(fields, "password2"), - "UTF-8", "CP1250"); - t = charset_convert( - purple_request_fields_get_string(fields, "token"), - "UTF-8", "CP1250"); + gchar *cur, *p1, *p2, *t, *mail; + const char *messagesTitle = + _("Change password for the Gadu-Gadu account"); + + cur = g_strdup(purple_request_fields_get_string(fields, + "password_cur")); + p1 = g_strdup(purple_request_fields_get_string(fields, "password1")); + p2 = g_strdup(purple_request_fields_get_string(fields, "password2")); + t = g_strdup(purple_request_fields_get_string(fields, "token")); + mail = g_strdup(purple_request_fields_get_string(fields, "email")); account = purple_connection_get_account(gc); if (cur == NULL || p1 == NULL || p2 == NULL || t == NULL || - *cur == '\0' || *p1 == '\0' || *p2 == '\0' || *t == '\0') { - purple_notify_error(account, NULL, _("Fill in the fields."), NULL); + mail == NULL || *cur == '\0' || *p1 == '\0' || *p2 == '\0' || + *t == '\0' || *mail == '\0') { + purple_notify_error(account, messagesTitle, + _("Fill in the fields."), NULL); goto exit_err; } if (g_utf8_collate(p1, p2) != 0) { - purple_notify_error(account, NULL, - _("New passwords do not match."), NULL); + purple_notify_error(account, messagesTitle, + _("New passwords do not match."), NULL); + goto exit_err; + } + + if (strlen(p1) > 15) { + purple_notify_error(account, messagesTitle, + _("New password should be at most 15 characters long."), + NULL); goto exit_err; } if (g_utf8_collate(cur, purple_account_get_password(account)) != 0) { - purple_notify_error(account, NULL, - _("Your current password is different from the one that you specified."), - NULL); + purple_notify_error(account, messagesTitle, + _("Your current password is different from the one that" + " you specified."), NULL); + goto exit_err; + } + + if (!purple_email_is_valid(mail)) { + purple_notify_error(account, messagesTitle, + _("Invalid email address"), NULL); goto exit_err; } - purple_debug_info("gg", "Changing password\n"); - - /* XXX: this email should be a pref... */ - h = gg_change_passwd4(ggp_get_uin(account), - "user@example.net", purple_account_get_password(account), - p1, info->token->id, t, 0); - - if (h == NULL) { - purple_notify_error(account, NULL, + purple_debug_info("gg", "Changing password with email \"%s\"...\n", + mail); + + h = gg_change_passwd4(ggp_get_uin(account), mail, + purple_account_get_password(account), p1, info->token->id, t, + 1); + + if (h == NULL) + purple_notify_error(account, messagesTitle, _("Unable to change password. Error occurred.\n"), NULL); - goto exit_err; + else + { + ggp_change_passwd_request *req = + g_new(ggp_change_passwd_request, 1); + req->http_req = h; + req->new_password = g_strdup(p1); + req->account = account; + + req->inpa = ggp_http_input_add(h, + ggp_callback_change_passwd_handler, req); } - - purple_account_set_password(account, p1); - - gg_change_passwd_free(h); - - purple_notify_info(account, _("Change password for the Gadu-Gadu account"), - _("Password was changed successfully!"), NULL); - + exit_err: g_free(cur); g_free(p1); g_free(p2); g_free(t); + g_free(mail); g_free(info->token->id); g_free(info->token->data); g_free(info->token); @@ -701,7 +763,6 @@ char *msg; - fields = purple_request_fields_new(); group = purple_request_field_group_new(NULL); purple_request_fields_add_group(fields, group); @@ -721,6 +782,11 @@ purple_request_field_string_set_masked(field, TRUE); purple_request_field_group_add_field(group, field); + field = purple_request_field_string_new("email", + _("Email Address"), "", FALSE); + purple_request_field_string_set_masked(field, FALSE); + purple_request_field_group_add_field(group, field); + field = purple_request_field_string_new("token", _("Enter current token"), "", FALSE); purple_request_field_string_set_masked(field, FALSE); @@ -732,8 +798,8 @@ purple_request_field_group_add_field(group, field); msg = g_strdup_printf("%s %d", - _("Please, enter your current password and your new password for UIN: "), - ggp_get_uin(purple_connection_get_account(gc))); + _("Please, enter your current password and your new password " + "for UIN: "), ggp_get_uin(purple_connection_get_account(gc))); purple_request_fields(gc, _("Change Gadu-Gadu Password"), @@ -2188,7 +2254,8 @@ purple_connection_set_protocol_data(gc, info); glp->uin = ggp_get_uin(account); - glp->password = (char *)purple_account_get_password(account); + glp->password = charset_convert(purple_account_get_password(account), + "UTF-8", "CP1250"); if (glp->uin == 0) { purple_connection_error(gc,