libpurple/protocols/gg/account.c

Sat, 30 Jun 2012 19:56:46 +0200

author
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
date
Sat, 30 Jun 2012 19:56:46 +0200
branch
soc.2012.gg
changeset 33308
140aa3ad4cae
parent 33307
45147502ceab
child 33309
bc2f2ea7b5ab
permissions
-rw-r--r--

Gadu-Gadu: cancellable gg_http watcher

33303
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
1 #include "account.h"
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
2
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
3 #include <libgadu.h>
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
4 #include <debug.h>
33305
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
5 #include <request.h>
33303
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
6
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
7 #include "deprecated.h"
33306
b1bef9a92b4c Gadu-Gadu: rename purple.(c|h) to purplew.(c|h) - purple wrappers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33305
diff changeset
8 #include "purplew.h"
33305
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
9 #include "utils.h"
33307
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33306
diff changeset
10 #include "libgaduw.h"
33305
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
11
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
12 /*******************************************************************************
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
13 * Token requesting.
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
14 ******************************************************************************/
33303
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
15
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
16 typedef struct
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
17 {
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
18 ggp_account_token_cb callback;
33305
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
19 PurpleConnection *gc;
33303
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
20 void *user_data;
33307
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33306
diff changeset
21
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33306
diff changeset
22 ggp_libgaduw_http_req *req;
33303
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
23 } ggp_account_token_reqdata;
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
24
33308
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
25 static void ggp_account_token_response(struct gg_http *h, gboolean success, gboolean cancelled, gpointer _reqdata);
33305
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
26
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
27 /******************************************************************************/
33303
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
28
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
29 void ggp_account_token_free(ggp_account_token *token)
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
30 {
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
31 g_free(token->id);
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
32 g_free(token->data);
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
33 g_free(token);
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
34 }
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
35
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
36 void ggp_account_token_request(PurpleConnection *gc, ggp_account_token_cb callback, void *user_data)
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
37 {
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
38 struct gg_http *h;
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
39 ggp_account_token_reqdata *reqdata;
33308
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
40
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
41 purple_debug_info("gg", "ggp_account_token_request: requesting token...\n");
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
42
33303
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
43 if (!ggp_deprecated_setup_proxy(gc))
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
44 {
33305
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
45 callback(gc, NULL, user_data);
33303
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
46 return;
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
47 }
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
48
33308
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
49 h = gg_token(TRUE);
33303
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
50
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
51 if (!h)
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
52 {
33305
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
53 callback(gc, NULL, user_data);
33303
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
54 return;
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
55 }
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
56
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
57 reqdata = g_new(ggp_account_token_reqdata, 1);
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
58 reqdata->callback = callback;
33305
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
59 reqdata->gc = gc;
33303
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
60 reqdata->user_data = user_data;
33308
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
61 reqdata->req = ggp_libgaduw_http_watch(gc, h, ggp_account_token_response, reqdata, TRUE);
33303
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
62 }
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
63
33308
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
64 static void ggp_account_token_response(struct gg_http *h, gboolean success,
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
65 gboolean cancelled, gpointer _reqdata)
33303
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
66 {
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
67 ggp_account_token_reqdata *reqdata = _reqdata;
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
68 struct gg_token *token_info;
33308
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
69 ggp_account_token *token = NULL;
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
70
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
71 g_assert(!(success && cancelled));
33303
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
72
33308
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
73 if (cancelled)
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
74 purple_debug_info("gg", "ggp_account_token_handler: cancelled\n");
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
75 else if (success)
33303
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
76 {
33308
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
77 purple_debug_info("gg", "ggp_account_token_handler: got token\n");
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
78
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
79 token = g_new(ggp_account_token, 1);
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
80
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
81 token_info = h->data;
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
82 token->id = g_strdup(token_info->tokenid);
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
83 token->size = h->body_size;
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
84 token->data = g_memdup(h->body, token->size);
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
85 }
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
86 else
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
87 {
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
88 purple_debug_error("gg", "ggp_account_token_handler: error\n");
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
89 purple_notify_error(
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
90 purple_connection_get_account(reqdata->gc),
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
91 _("Token Error"),
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
92 _("Unable to fetch the token.\n"), NULL);
33303
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
93 }
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
94
33307
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33306
diff changeset
95 gg_token_free(h);
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33306
diff changeset
96 reqdata->callback(reqdata->gc, token, reqdata->user_data);
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33306
diff changeset
97 g_free(reqdata);
33305
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
98 }
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
99
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
100 /*******************************************************************************
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
101 * New account registration.
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
102 ******************************************************************************/
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
103
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
104 typedef struct
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
105 {
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
106 ggp_account_token *token;
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
107 PurpleConnection *gc;
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
108 } ggp_account_register_data;
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
109
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
110 static void ggp_account_register_dialog(PurpleConnection *gc, ggp_account_token *token, gpointer user_data);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
111 static void ggp_account_register_dialog_ok(ggp_account_register_data *register_data, PurpleRequestFields *fields);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
112 static void ggp_account_register_dialog_cancel(ggp_account_register_data *register_data, PurpleRequestFields *fields);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
113 static void ggp_account_register_completed(ggp_account_register_data *register_data, gboolean success);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
114
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
115 /******************************************************************************/
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
116
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
117 static void ggp_account_register_completed(ggp_account_register_data *register_data, gboolean success)
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
118 {
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
119 PurpleAccount *account = purple_connection_get_account(register_data->gc);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
120
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
121 ggp_account_token_free(register_data->token);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
122 g_free(register_data);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
123
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
124 purple_account_disconnect(account);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
125 purple_account_register_completed(account, TRUE);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
126 }
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
127
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
128 void ggp_account_register(PurpleAccount *account)
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
129 {
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
130 PurpleConnection *gc = purple_account_get_connection(account);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
131
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
132 purple_debug_info("gg", "ggp_account_register\n");
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
133
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
134 ggp_account_token_request(gc, ggp_account_register_dialog, NULL);
33303
50f7a92eeb90 Gadu-Gadu: code refactoring - token request, proxy setup (deprecated)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
135 }
33305
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
136
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
137 static void ggp_account_register_dialog(PurpleConnection *gc, ggp_account_token *token, gpointer user_data)
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
138 {
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
139 PurpleAccount *account = purple_connection_get_account(gc);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
140 PurpleRequestFields *fields;
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
141 PurpleRequestFieldGroup *group;
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
142 PurpleRequestField *field;
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
143 ggp_account_register_data *register_data;
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
144
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
145 purple_debug_info("gg", "ggp_account_register_dialog(%x, %x, %x)\n",
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
146 (unsigned int)gc, (unsigned int)token, (unsigned int)user_data);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
147 if (!token)
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
148 {
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
149 purple_account_disconnect(account);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
150 purple_account_register_completed(account, FALSE);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
151 return;
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
152 }
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
153
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
154 // TODO: required fields
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
155 fields = purple_request_fields_new();
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
156 group = purple_request_field_group_new(NULL);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
157 purple_request_fields_add_group(fields, group);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
158
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
159 field = purple_request_field_string_new("email", _("Email"), "", FALSE);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
160 purple_request_field_group_add_field(group, field);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
161
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
162 field = purple_request_field_string_new("password1", _("Password"), "",
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
163 FALSE);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
164 purple_request_field_string_set_masked(field, TRUE);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
165 purple_request_field_group_add_field(group, field);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
166
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
167 field = purple_request_field_string_new("password2", _("Password (again)"), "",
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
168 FALSE);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
169 purple_request_field_string_set_masked(field, TRUE);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
170 purple_request_field_group_add_field(group, field);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
171
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
172 //TODO: move it into a new group?
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
173 field = purple_request_field_string_new("token_value",
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
174 _("Enter captcha text"), "", FALSE);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
175 purple_request_field_group_add_field(group, field);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
176
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
177 field = purple_request_field_image_new("token_image", _("Captcha"),
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
178 token->data, token->size);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
179 purple_request_field_group_add_field(group, field);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
180
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
181 register_data = g_new(ggp_account_register_data, 1);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
182 register_data->gc = gc;
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
183 register_data->token = token;
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
184
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
185 purple_request_fields(gc,
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
186 _("Register New Gadu-Gadu Account"),
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
187 _("Register New Gadu-Gadu Account"),
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
188 _("Please, fill in the following fields"), fields,
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
189 _("OK"), G_CALLBACK(ggp_account_register_dialog_ok),
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
190 _("Cancel"), G_CALLBACK(ggp_account_register_dialog_cancel),
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
191 account, NULL, NULL, register_data);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
192 }
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
193
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
194 static void ggp_account_register_dialog_cancel(ggp_account_register_data *register_data, PurpleRequestFields *fields)
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
195 {
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
196 purple_debug_info("gg", "ggp_account_register_dialog_cancel(%x, %x)\n",
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
197 (unsigned int)register_data, (unsigned int)fields);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
198
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
199 ggp_account_register_completed(register_data, FALSE);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
200 }
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
201
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
202 static void ggp_account_register_dialog_ok(ggp_account_register_data *register_data, PurpleRequestFields *fields)
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
203 {
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
204 PurpleAccount *account = purple_connection_get_account(register_data->gc);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
205 const gchar *email, *password1, *password2, *token_value;
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
206 struct gg_http *h;
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
207 struct gg_pubdir *register_result;
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
208 uin_t uin;
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
209
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
210 purple_debug_info("gg", "ggp_account_register_dialog_ok(%x, %x)\n",
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
211 (unsigned int)register_data, (unsigned int)fields);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
212
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
213 email = purple_request_fields_get_string(fields, "email");
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
214 password1 = purple_request_fields_get_string(fields, "password1");
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
215 password2 = purple_request_fields_get_string(fields, "password2");
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
216 token_value = purple_request_fields_get_string(fields, "token_value");
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
217
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
218 g_assert(email != NULL);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
219 g_assert(password1 != NULL);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
220 g_assert(password2 != NULL);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
221 g_assert(token_value != NULL);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
222
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
223 if (g_utf8_collate(password1, password2) != 0)
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
224 {
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
225 purple_debug_warning("gg", "ggp_account_register_dialog_ok: validation failed - passwords does not match\n");
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
226 purple_notify_error(purple_connection_get_account(register_data->gc),
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
227 _("TODO: title"),
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
228 _("Passwords do not match"), NULL);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
229 ggp_account_register_completed(register_data, FALSE);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
230 return;
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
231 }
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
232
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
233 purple_debug_info("gg", "ggp_account_register_dialog_ok: validation ok [token id=%s, value=%s]\n",
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
234 register_data->token->id, token_value);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
235 h = gg_register3(email, password1, register_data->token->id, token_value, 0); // TODO: async (use code from ggp_account_token_handler)
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
236 if (h == NULL || !(register_result = h->data) || !register_result->success)
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
237 {
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
238 purple_debug_warning("gg", "ggp_account_register_dialog_ok: registration failed\n");
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
239 purple_notify_error(purple_connection_get_account(register_data->gc),
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
240 _("TODO: title"),
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
241 _("Unable to register new account. An unknown error occurred."), NULL);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
242 ggp_account_register_completed(register_data, FALSE);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
243 return;
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
244 }
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
245 uin = register_result->uin;
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
246
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
247 purple_debug_info("gg", "ggp_account_register_dialog_ok: registered uin %u\n", uin);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
248 gg_register_free(h);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
249
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
250 purple_account_set_username(account, ggp_uin_to_str(uin));
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
251 purple_account_set_remember_password(account, TRUE); //TODO: option
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
252 purple_account_set_password(account, password1);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
253
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
254 purple_notify_info(NULL, _("New Gadu-Gadu Account Registered"),
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
255 _("Registration completed successfully!"), NULL); //TODO: show new UIN
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
256
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
257 ggp_account_register_completed(register_data, TRUE);
41e5ff454167 Gadu-Gadu: ggp_purple_request_processing implementation; refactoring of account registration (first stage); cancellable token request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33303
diff changeset
258 }

mercurial