Mercurial > pidgin.yaz
annotate libgaim/protocols/gg/gg.c @ 15141:05c55c2b6c25
[gaim-migrate @ 17926]
Mark these strings for translation.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Huetsch <markhuetsch> |
---|---|
date | Sat, 09 Dec 2006 07:39:29 +0000 |
parents | 9e1d9c9229ce |
children | b81e4e44b509 |
rev | line source |
---|---|
14192 | 1 /** |
2 * @file gg.c Gadu-Gadu protocol plugin | |
3 * | |
4 * gaim | |
5 * | |
6 * Copyright (C) 2005 Bartosz Oler <bartosz@bzimage.us> | |
7 * | |
8 * Some parts of the code are adapted or taken from the previous implementation | |
9 * of this plugin written by Arkadiusz Miskiewicz <misiek@pld.org.pl> | |
10 * | |
11 * Thanks to Google's Summer of Code Program. | |
12 * | |
13 * This program is free software; you can redistribute it and/or modify | |
14 * it under the terms of the GNU General Public License as published by | |
15 * the Free Software Foundation; either version 2 of the License, or | |
16 * (at your option) any later version. | |
17 * | |
18 * This program is distributed in the hope that it will be useful, | |
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 * GNU General Public License for more details. | |
22 * | |
23 * You should have received a copy of the GNU General Public License | |
24 * along with this program; if not, write to the Free Software | |
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
26 */ | |
27 | |
28 #include "internal.h" | |
29 | |
30 #include "plugin.h" | |
31 #include "version.h" | |
32 #include "notify.h" | |
33 #include "status.h" | |
34 #include "blist.h" | |
35 #include "accountopt.h" | |
36 #include "debug.h" | |
37 #include "util.h" | |
38 #include "request.h" | |
39 | |
40 #include <libgadu.h> | |
41 | |
42 #include "gg.h" | |
43 #include "confer.h" | |
44 #include "search.h" | |
45 #include "buddylist.h" | |
46 #include "gg-utils.h" | |
47 | |
48 static GaimPlugin *my_protocol = NULL; | |
49 | |
50 /* ---------------------------------------------------------------------- */ | |
51 /* ----- EXTERNAL CALLBACKS --------------------------------------------- */ | |
52 /* ---------------------------------------------------------------------- */ | |
53 | |
54 | |
55 /* ----- HELPERS -------------------------------------------------------- */ | |
56 | |
57 /** | |
58 * Set up libgadu's proxy. | |
59 * | |
60 * @param account Account for which to set up the proxy. | |
61 * | |
62 * @return Zero if proxy setup is valid, otherwise -1. | |
63 */ | |
64 /* static int ggp_setup_proxy(GaimAccount *account) {{{ */ | |
65 static int ggp_setup_proxy(GaimAccount *account) | |
66 { | |
67 GaimProxyInfo *gpi; | |
68 | |
69 gpi = gaim_proxy_get_setup(account); | |
70 | |
71 if ((gaim_proxy_info_get_type(gpi) != GAIM_PROXY_NONE) && | |
72 (gaim_proxy_info_get_host(gpi) == NULL || | |
73 gaim_proxy_info_get_port(gpi) <= 0)) { | |
74 | |
75 gg_proxy_enabled = 0; | |
76 gaim_notify_error(NULL, NULL, _("Invalid proxy settings"), | |
77 _("Either the host name or port number specified for your given proxy type is invalid.")); | |
78 return -1; | |
79 } else if (gaim_proxy_info_get_type(gpi) != GAIM_PROXY_NONE) { | |
80 gg_proxy_enabled = 1; | |
81 gg_proxy_host = g_strdup(gaim_proxy_info_get_host(gpi)); | |
82 gg_proxy_port = gaim_proxy_info_get_port(gpi); | |
83 gg_proxy_username = g_strdup(gaim_proxy_info_get_username(gpi)); | |
84 gg_proxy_password = g_strdup(gaim_proxy_info_get_password(gpi)); | |
85 } else { | |
86 gg_proxy_enabled = 0; | |
87 } | |
88 | |
89 return 0; | |
90 } | |
91 /* }}} */ | |
92 | |
93 /* | |
94 */ | |
95 /* static void ggp_async_token_handler(gpointer _gc, gint fd, GaimInputCondition cond) {{{ */ | |
96 static void ggp_async_token_handler(gpointer _gc, gint fd, GaimInputCondition cond) | |
97 { | |
98 GaimConnection *gc = _gc; | |
99 GGPInfo *info = gc->proto_data; | |
100 GGPToken *token = info->token; | |
101 GGPTokenCallback cb; | |
102 | |
103 struct gg_token *t = NULL; | |
104 | |
105 gaim_debug_info("gg", "token_handler: token->req: check = %d; state = %d;\n", | |
106 token->req->check, token->req->state); | |
107 | |
108 if (gg_token_watch_fd(token->req) == -1 || token->req->state == GG_STATE_ERROR) { | |
109 gaim_debug_error("gg", "token error (1): %d\n", token->req->error); | |
110 gaim_input_remove(token->inpa); | |
111 gg_token_free(token->req); | |
112 token->req = NULL; | |
113 | |
114 gaim_notify_error(gaim_connection_get_account(gc), | |
115 _("Token Error"), | |
116 _("Unable to fetch the token.\n"), NULL); | |
117 return; | |
118 } | |
119 | |
120 if (token->req->state != GG_STATE_DONE) { | |
121 gaim_input_remove(token->inpa); | |
122 token->inpa = gaim_input_add(token->req->fd, | |
123 (token->req->check == 1) | |
124 ? GAIM_INPUT_WRITE | |
125 : GAIM_INPUT_READ, | |
126 ggp_async_token_handler, gc); | |
127 return; | |
128 } | |
129 | |
130 if (!(t = token->req->data) || !token->req->body) { | |
131 gaim_debug_error("gg", "token error (2): %d\n", token->req->error); | |
132 gaim_input_remove(token->inpa); | |
133 gg_token_free(token->req); | |
134 token->req = NULL; | |
135 | |
136 gaim_notify_error(gaim_connection_get_account(gc), | |
137 _("Token Error"), | |
138 _("Unable to fetch the token.\n"), NULL); | |
139 return; | |
140 } | |
141 | |
142 gaim_input_remove(token->inpa); | |
143 | |
144 token->id = g_strdup(t->tokenid); | |
145 token->size = token->req->body_size; | |
146 token->data = g_new0(char, token->size); | |
147 memcpy(token->data, token->req->body, token->size); | |
148 | |
149 gaim_debug_info("gg", "TOKEN! tokenid = %s; size = %d\n", | |
150 token->id, token->size); | |
151 | |
152 gg_token_free(token->req); | |
153 token->req = NULL; | |
154 token->inpa = 0; | |
155 | |
156 cb = token->cb; | |
157 token->cb = NULL; | |
158 cb(gc); | |
159 } | |
160 /* }}} */ | |
161 | |
162 /* | |
163 */ | |
164 /* static void ggp_token_request(GaimConnection *gc, GGPTokenCallback cb) {{{ */ | |
165 static void ggp_token_request(GaimConnection *gc, GGPTokenCallback cb) | |
166 { | |
167 GaimAccount *account; | |
168 struct gg_http *req; | |
169 GGPInfo *info; | |
170 | |
171 account = gaim_connection_get_account(gc); | |
172 | |
173 if (ggp_setup_proxy(account) == -1) | |
174 return; | |
175 | |
176 info = gc->proto_data; | |
177 | |
178 if ((req = gg_token(1)) == NULL) { | |
179 gaim_notify_error(account, | |
180 _("Token Error"), | |
181 _("Unable to fetch the token.\n"), NULL); | |
182 return; | |
183 } | |
184 | |
185 info->token = g_new(GGPToken, 1); | |
186 info->token->cb = cb; | |
187 | |
188 info->token->req = req; | |
189 info->token->inpa = gaim_input_add(req->fd, GAIM_INPUT_READ, | |
190 ggp_async_token_handler, gc); | |
191 } | |
192 /* }}} */ | |
193 | |
194 /* ---------------------------------------------------------------------- */ | |
195 | |
196 /** | |
197 * Request buddylist from the server. | |
198 * Buddylist is received in the ggp_callback_recv(). | |
199 * | |
200 * @param Current action handler. | |
201 */ | |
202 /* static void ggp_action_buddylist_get(GaimPluginAction *action) {{{ */ | |
203 static void ggp_action_buddylist_get(GaimPluginAction *action) | |
204 { | |
205 GaimConnection *gc = (GaimConnection *)action->context; | |
206 GGPInfo *info = gc->proto_data; | |
207 | |
208 gaim_debug_info("gg", "Downloading...\n"); | |
209 | |
210 gg_userlist_request(info->session, GG_USERLIST_GET, NULL); | |
211 } | |
212 /* }}} */ | |
213 | |
214 /** | |
215 * Upload the buddylist to the server. | |
216 * | |
217 * @param action Current action handler. | |
218 */ | |
219 /* static void ggp_action_buddylist_put(GaimPluginAction *action) {{{ */ | |
220 static void ggp_action_buddylist_put(GaimPluginAction *action) | |
221 { | |
222 GaimConnection *gc = (GaimConnection *)action->context; | |
223 GGPInfo *info = gc->proto_data; | |
224 | |
225 char *buddylist = ggp_buddylist_dump(gaim_connection_get_account(gc)); | |
226 | |
227 gaim_debug_info("gg", "Uploading...\n"); | |
228 | |
229 if (buddylist == NULL) | |
230 return; | |
231 | |
232 gg_userlist_request(info->session, GG_USERLIST_PUT, buddylist); | |
233 g_free(buddylist); | |
234 } | |
235 /* }}} */ | |
236 | |
237 /** | |
238 * Delete buddylist from the server. | |
239 * | |
240 * @param action Current action handler. | |
241 */ | |
242 /* static void ggp_action_buddylist_delete(GaimPluginAction *action) {{{ */ | |
243 static void ggp_action_buddylist_delete(GaimPluginAction *action) | |
244 { | |
245 GaimConnection *gc = (GaimConnection *)action->context; | |
246 GGPInfo *info = gc->proto_data; | |
247 | |
248 gaim_debug_info("gg", "Deleting...\n"); | |
249 | |
250 gg_userlist_request(info->session, GG_USERLIST_PUT, NULL); | |
251 } | |
252 /* }}} */ | |
253 | |
254 /* | |
255 */ | |
256 /* static void ggp_callback_buddylist_save_ok(GaimConnection *gc, gchar *file) {{{ */ | |
257 static void ggp_callback_buddylist_save_ok(GaimConnection *gc, gchar *file) | |
258 { | |
259 GaimAccount *account = gaim_connection_get_account(gc); | |
260 | |
261 FILE *fh; | |
262 char *buddylist = ggp_buddylist_dump(account); | |
263 gchar *msg; | |
264 | |
265 gaim_debug_info("gg", "Saving...\n"); | |
266 gaim_debug_info("gg", "file = %s\n", file); | |
267 | |
268 if (buddylist == NULL) { | |
269 gaim_notify_info(account, _("Save Buddylist..."), | |
270 _("Your buddylist is empty, nothing was written to the file."), | |
271 NULL); | |
272 return; | |
273 } | |
274 | |
275 if ((fh = g_fopen(file, "wb")) == NULL) { | |
276 msg = g_strconcat(_("Couldn't open file"), ": ", file, "\n", NULL); | |
277 gaim_debug_error("gg", "Could not open file: %s\n", file); | |
278 gaim_notify_error(account, _("Couldn't open file"), msg, NULL); | |
279 g_free(msg); | |
280 g_free(file); | |
281 return; | |
282 } | |
283 | |
284 fwrite(buddylist, sizeof(char), g_utf8_strlen(buddylist, -1), fh); | |
285 fclose(fh); | |
286 g_free(buddylist); | |
287 | |
288 gaim_notify_info(account, _("Save Buddylist..."), | |
289 _("Buddylist saved successfully!"), NULL); | |
290 } | |
291 /* }}} */ | |
292 | |
293 /* | |
294 */ | |
295 /* static void ggp_callback_buddylist_load_ok(GaimConnection *gc, gchar *file) {{{ */ | |
296 static void ggp_callback_buddylist_load_ok(GaimConnection *gc, gchar *file) | |
297 { | |
298 GaimAccount *account = gaim_connection_get_account(gc); | |
299 GError *error = NULL; | |
300 char *buddylist = NULL; | |
301 gsize length; | |
302 | |
303 gaim_debug_info("gg", "file_name = %s\n", file); | |
304 | |
305 if (!g_file_get_contents(file, &buddylist, &length, &error)) { | |
306 gaim_notify_error(account, | |
307 _("Couldn't load buddylist"), | |
308 _("Couldn't load buddylist"), | |
309 error->message); | |
310 | |
311 gaim_debug_error("gg", | |
312 "Couldn't load buddylist. file = %s; error = %s\n", | |
313 file, error->message); | |
314 | |
315 g_error_free(error); | |
316 | |
317 return; | |
318 } | |
319 | |
320 ggp_buddylist_load(gc, buddylist); | |
321 g_free(buddylist); | |
322 | |
323 gaim_notify_info(account, | |
324 _("Load Buddylist..."), | |
325 _("Buddylist loaded successfully!"), NULL); | |
326 } | |
327 /* }}} */ | |
328 | |
329 /* | |
330 */ | |
331 /* static void ggp_action_buddylist_save(GaimPluginAction *action) {{{ */ | |
332 static void ggp_action_buddylist_save(GaimPluginAction *action) | |
333 { | |
334 GaimConnection *gc = (GaimConnection *)action->context; | |
335 | |
336 gaim_request_file(action, _("Save buddylist..."), NULL, TRUE, | |
337 G_CALLBACK(ggp_callback_buddylist_save_ok), NULL, gc); | |
338 } | |
339 /* }}} */ | |
340 | |
341 /* | |
342 */ | |
343 /* static void ggp_action_buddylist_load(GaimPluginAction *action) {{{ */ | |
344 static void ggp_action_buddylist_load(GaimPluginAction *action) | |
345 { | |
346 GaimConnection *gc = (GaimConnection *)action->context; | |
347 | |
348 gaim_request_file(action, "Load buddylist from file...", NULL, FALSE, | |
349 G_CALLBACK(ggp_callback_buddylist_load_ok), NULL, gc); | |
350 } | |
351 /* }}} */ | |
352 | |
353 /* | |
354 */ | |
355 /* static void ggp_callback_register_account_ok(GaimConnection *gc, GaimRequestFields *fields) {{{ */ | |
356 static void ggp_callback_register_account_ok(GaimConnection *gc, | |
357 GaimRequestFields *fields) | |
358 { | |
359 GaimAccount *account; | |
360 GGPInfo *info = gc->proto_data; | |
361 struct gg_http *h = NULL; | |
362 struct gg_pubdir *s; | |
363 uin_t uin; | |
364 gchar *email, *p1, *p2, *t; | |
365 GGPToken *token = info->token; | |
366 | |
367 email = charset_convert(gaim_request_fields_get_string(fields, "email"), | |
368 "UTF-8", "CP1250"); | |
369 p1 = charset_convert(gaim_request_fields_get_string(fields, "password1"), | |
370 "UTF-8", "CP1250"); | |
371 p2 = charset_convert(gaim_request_fields_get_string(fields, "password2"), | |
372 "UTF-8", "CP1250"); | |
373 t = charset_convert(gaim_request_fields_get_string(fields, "token"), | |
374 "UTF-8", "CP1250"); | |
375 | |
376 account = gaim_connection_get_account(gc); | |
377 | |
378 if (email == NULL || p1 == NULL || p2 == NULL || t == NULL || | |
379 *email == '\0' || *p1 == '\0' || *p2 == '\0' || *t == '\0') { | |
380 gaim_connection_error(gc, _("Fill in the registration fields.")); | |
381 goto exit_err; | |
382 } | |
383 | |
384 if (g_utf8_collate(p1, p2) != 0) { | |
385 gaim_connection_error(gc, _("Passwords do not match.")); | |
386 goto exit_err; | |
387 } | |
388 | |
389 gaim_debug_info("gg", "register_account_ok: token_id = %d; t = %s\n", | |
390 token->id, t); | |
391 h = gg_register3(email, p1, token->id, t, 0); | |
392 if (h == NULL || !(s = h->data) || !s->success) { | |
393 gaim_connection_error(gc, | |
394 _("Unable to register new account. Error occurred.\n")); | |
395 goto exit_err; | |
396 } | |
397 | |
398 uin = s->uin; | |
399 gaim_debug_info("gg", "registered uin: %d\n", uin); | |
400 | |
401 g_free(t); | |
402 t = g_strdup_printf("%u", uin); | |
403 gaim_account_set_username(account, t); | |
404 /* Save the password if remembering passwords for the account */ | |
405 gaim_account_set_password(account, p1); | |
406 | |
407 gaim_notify_info(NULL, _("New Gadu-Gadu Account Registered"), | |
408 _("Registration completed successfully!"), NULL); | |
409 | |
410 /* TODO: the currently open Accounts Window will not be updated withthe | |
411 * new username and etc, we need to somehow have it refresh at this | |
412 * point | |
413 */ | |
414 | |
415 /* Need to disconnect or actually log in. For now, we disconnect. */ | |
416 gaim_connection_destroy(gc); | |
417 | |
418 exit_err: | |
419 gg_register_free(h); | |
420 g_free(email); | |
421 g_free(p1); | |
422 g_free(p2); | |
423 g_free(t); | |
424 g_free(token->id); | |
425 g_free(token); | |
426 } | |
427 /* }}} */ | |
428 | |
429 /* | |
430 */ | |
431 /* static void ggp_callback_register_account_cancel(GaimConnection *gc, GaimRequestFields *fields) {{{ */ | |
432 static void ggp_callback_register_account_cancel(GaimConnection *gc, | |
433 GaimRequestFields *fields) | |
434 { | |
435 GGPInfo *info = gc->proto_data; | |
436 GGPToken *token = info->token; | |
437 | |
438 gaim_connection_destroy(gc); | |
439 | |
440 g_free(token->id); | |
441 g_free(token->data); | |
442 g_free(token); | |
443 | |
444 } | |
445 /* }}} */ | |
446 | |
447 /* | |
448 */ | |
449 /* static void ggp_register_user_dialog(GaimConnection *gc) {{{ */ | |
450 static void ggp_register_user_dialog(GaimConnection *gc) | |
451 { | |
452 GaimAccount *account; | |
453 GaimRequestFields *fields; | |
454 GaimRequestFieldGroup *group; | |
455 GaimRequestField *field; | |
456 | |
457 GGPInfo *info = gc->proto_data; | |
458 GGPToken *token = info->token; | |
459 | |
460 | |
461 account = gaim_connection_get_account(gc); | |
462 | |
463 fields = gaim_request_fields_new(); | |
464 group = gaim_request_field_group_new(NULL); | |
465 gaim_request_fields_add_group(fields, group); | |
466 | |
467 field = gaim_request_field_string_new("email", | |
468 _("E-mail"), "", FALSE); | |
469 gaim_request_field_string_set_masked(field, FALSE); | |
470 gaim_request_field_group_add_field(group, field); | |
471 | |
472 field = gaim_request_field_string_new("password1", | |
473 _("Password"), "", FALSE); | |
474 gaim_request_field_string_set_masked(field, TRUE); | |
475 gaim_request_field_group_add_field(group, field); | |
476 | |
477 field = gaim_request_field_string_new("password2", | |
478 _("Password (retype)"), "", FALSE); | |
479 gaim_request_field_string_set_masked(field, TRUE); | |
480 gaim_request_field_group_add_field(group, field); | |
481 | |
482 field = gaim_request_field_string_new("token", | |
483 _("Enter current token"), "", FALSE); | |
484 gaim_request_field_string_set_masked(field, FALSE); | |
485 gaim_request_field_group_add_field(group, field); | |
486 | |
487 /* original size: 60x24 */ | |
488 field = gaim_request_field_image_new("token_img", | |
489 _("Current token"), token->data, token->size); | |
490 gaim_request_field_group_add_field(group, field); | |
491 | |
492 gaim_request_fields(account, | |
493 _("Register New Gadu-Gadu Account"), | |
494 _("Register New Gadu-Gadu Account"), | |
495 _("Please, fill in the following fields"), | |
496 fields, | |
497 _("OK"), G_CALLBACK(ggp_callback_register_account_ok), | |
498 _("Cancel"), G_CALLBACK(ggp_callback_register_account_cancel), | |
499 gc); | |
500 } | |
501 /* }}} */ | |
502 | |
503 /* ----- PUBLIC DIRECTORY SEARCH ---------------------------------------- */ | |
504 | |
505 /* | |
506 */ | |
507 /* static void ggp_callback_show_next(GaimConnection *gc, GList *row, gpointer user_data) {{{ */ | |
508 static void ggp_callback_show_next(GaimConnection *gc, GList *row, gpointer user_data) | |
509 { | |
510 GGPInfo *info = gc->proto_data; | |
511 GGPSearchForm *form = user_data; | |
512 guint32 seq; | |
513 | |
514 g_free(form->offset); | |
515 form->offset = g_strdup(form->last_uin); | |
516 | |
517 ggp_search_remove(info->searches, form->seq); | |
518 | |
519 seq = ggp_search_start(gc, form); | |
520 ggp_search_add(info->searches, seq, form); | |
521 } | |
522 /* }}} */ | |
523 | |
524 /* | |
525 */ | |
526 /* static void ggp_callback_add_buddy(GaimConnection *gc, GList *row, gpointer user_data) {{{ */ | |
527 static void ggp_callback_add_buddy(GaimConnection *gc, GList *row, gpointer user_data) | |
528 { | |
529 gaim_blist_request_add_buddy(gaim_connection_get_account(gc), | |
530 g_list_nth_data(row, 0), NULL, NULL); | |
531 } | |
532 /* }}} */ | |
533 | |
534 /* | |
535 */ | |
536 /* static void ggp_callback_im(GaimConnection *gc, GList *row, gpointer user_data) {{{ */ | |
537 static void ggp_callback_im(GaimConnection *gc, GList *row, gpointer user_data) | |
538 { | |
539 GaimAccount *account; | |
540 GaimConversation *conv; | |
541 char *name; | |
542 | |
543 account = gaim_connection_get_account(gc); | |
544 | |
545 name = g_list_nth_data(row, 0); | |
546 conv = gaim_conversation_new(GAIM_CONV_TYPE_IM, account, name); | |
547 gaim_conversation_present(conv); | |
548 } | |
549 /* }}} */ | |
550 | |
551 /* | |
552 */ | |
553 /* static void ggp_callback_find_buddies(GaimConnection *gc, GaimRequestFields *fields) {{{ */ | |
554 static void ggp_callback_find_buddies(GaimConnection *gc, GaimRequestFields *fields) | |
555 { | |
556 GGPInfo *info = gc->proto_data; | |
557 GGPSearchForm *form; | |
558 guint32 seq; | |
559 | |
560 form = ggp_search_form_new(GGP_SEARCH_TYPE_FULL); | |
561 | |
562 form->user_data = info; | |
563 form->lastname = charset_convert( | |
564 gaim_request_fields_get_string(fields, "lastname"), | |
565 "UTF-8", "CP1250"); | |
566 form->firstname = charset_convert( | |
567 gaim_request_fields_get_string(fields, "firstname"), | |
568 "UTF-8", "CP1250"); | |
569 form->nickname = charset_convert( | |
570 gaim_request_fields_get_string(fields, "nickname"), | |
571 "UTF-8", "CP1250"); | |
572 form->city = charset_convert( | |
573 gaim_request_fields_get_string(fields, "city"), | |
574 "UTF-8", "CP1250"); | |
575 form->birthyear = charset_convert( | |
576 gaim_request_fields_get_string(fields, "year"), | |
577 "UTF-8", "CP1250"); | |
578 | |
579 switch (gaim_request_fields_get_choice(fields, "gender")) { | |
580 case 1: | |
581 form->gender = g_strdup(GG_PUBDIR50_GENDER_MALE); | |
582 break; | |
583 case 2: | |
584 form->gender = g_strdup(GG_PUBDIR50_GENDER_FEMALE); | |
585 break; | |
586 default: | |
587 form->gender = NULL; | |
588 break; | |
589 } | |
590 | |
591 form->active = gaim_request_fields_get_bool(fields, "active") | |
592 ? g_strdup(GG_PUBDIR50_ACTIVE_TRUE) : NULL; | |
593 | |
594 form->offset = g_strdup("0"); | |
595 | |
596 seq = ggp_search_start(gc, form); | |
597 ggp_search_add(info->searches, seq, form); | |
598 } | |
599 /* }}} */ | |
600 | |
601 /* | |
602 */ | |
603 /* static void ggp_find_buddies(GaimPluginAction *action) {{{ */ | |
604 static void ggp_find_buddies(GaimPluginAction *action) | |
605 { | |
606 GaimConnection *gc = (GaimConnection *)action->context; | |
607 | |
608 GaimRequestFields *fields; | |
609 GaimRequestFieldGroup *group; | |
610 GaimRequestField *field; | |
611 | |
612 fields = gaim_request_fields_new(); | |
613 group = gaim_request_field_group_new(NULL); | |
614 gaim_request_fields_add_group(fields, group); | |
615 | |
616 field = gaim_request_field_string_new("lastname", | |
617 _("Last name"), NULL, FALSE); | |
618 gaim_request_field_string_set_masked(field, FALSE); | |
619 gaim_request_field_group_add_field(group, field); | |
620 | |
621 field = gaim_request_field_string_new("firstname", | |
622 _("First name"), NULL, FALSE); | |
623 gaim_request_field_string_set_masked(field, FALSE); | |
624 gaim_request_field_group_add_field(group, field); | |
625 | |
626 field = gaim_request_field_string_new("nickname", | |
627 _("Nickname"), NULL, FALSE); | |
628 gaim_request_field_string_set_masked(field, FALSE); | |
629 gaim_request_field_group_add_field(group, field); | |
630 | |
631 field = gaim_request_field_string_new("city", | |
632 _("City"), NULL, FALSE); | |
633 gaim_request_field_string_set_masked(field, FALSE); | |
634 gaim_request_field_group_add_field(group, field); | |
635 | |
636 field = gaim_request_field_string_new("year", | |
637 _("Year of birth"), NULL, FALSE); | |
638 gaim_request_field_group_add_field(group, field); | |
639 | |
640 field = gaim_request_field_choice_new("gender", _("Gender"), 0); | |
641 gaim_request_field_choice_add(field, _("Male or female")); | |
642 gaim_request_field_choice_add(field, _("Male")); | |
643 gaim_request_field_choice_add(field, _("Female")); | |
644 gaim_request_field_group_add_field(group, field); | |
645 | |
646 field = gaim_request_field_bool_new("active", | |
647 _("Only online"), FALSE); | |
648 gaim_request_field_group_add_field(group, field); | |
649 | |
650 gaim_request_fields(gc, | |
651 _("Find buddies"), | |
652 _("Find buddies"), | |
653 _("Please, enter your search criteria below"), | |
654 fields, | |
655 _("OK"), G_CALLBACK(ggp_callback_find_buddies), | |
656 _("Cancel"), NULL, | |
657 gc); | |
658 } | |
659 /* }}} */ | |
660 | |
661 /* ----- CHANGE PASSWORD ------------------------------------------------ */ | |
662 | |
663 /* | |
664 */ | |
665 /* static void ggp_callback_change_passwd_ok(GaimConnection *gc, GaimRequestFields *fields) {{{ */ | |
666 static void ggp_callback_change_passwd_ok(GaimConnection *gc, GaimRequestFields *fields) | |
667 { | |
668 GaimAccount *account; | |
669 GGPInfo *info = gc->proto_data; | |
670 struct gg_http *h; | |
671 gchar *cur, *p1, *p2, *t; | |
672 | |
673 cur = charset_convert( | |
674 gaim_request_fields_get_string(fields, "password_cur"), | |
675 "UTF-8", "CP1250"); | |
676 p1 = charset_convert( | |
677 gaim_request_fields_get_string(fields, "password1"), | |
678 "UTF-8", "CP1250"); | |
679 p2 = charset_convert( | |
680 gaim_request_fields_get_string(fields, "password2"), | |
681 "UTF-8", "CP1250"); | |
682 t = charset_convert( | |
683 gaim_request_fields_get_string(fields, "token"), | |
684 "UTF-8", "CP1250"); | |
685 | |
686 account = gaim_connection_get_account(gc); | |
687 | |
688 if (cur == NULL || p1 == NULL || p2 == NULL || t == NULL || | |
689 *cur == '\0' || *p1 == '\0' || *p2 == '\0' || *t == '\0') { | |
690 gaim_notify_error(account, NULL, _("Fill in the fields."), NULL); | |
691 goto exit_err; | |
692 } | |
693 | |
694 if (g_utf8_collate(p1, p2) != 0) { | |
695 gaim_notify_error(account, NULL, | |
696 _("New passwords do not match."), NULL); | |
697 goto exit_err; | |
698 } | |
699 | |
700 if (g_utf8_collate(cur, gaim_account_get_password(account)) != 0) { | |
701 gaim_notify_error(account, NULL, | |
702 _("Your current password is different from the one that you specified."), | |
703 NULL); | |
704 goto exit_err; | |
705 } | |
706 | |
707 gaim_debug_info("gg", "Changing password\n"); | |
708 | |
709 /* XXX: this e-mail should be a pref... */ | |
710 h = gg_change_passwd4(ggp_get_uin(account), | |
711 "user@example.net", gaim_account_get_password(account), | |
712 p1, info->token->id, t, 0); | |
713 | |
714 if (h == NULL) { | |
715 gaim_notify_error(account, NULL, | |
14692 | 716 _("Unable to change password. Error occurred.\n"), |
14192 | 717 NULL); |
718 goto exit_err; | |
719 } | |
720 | |
721 gaim_account_set_password(account, p1); | |
722 | |
723 gg_change_passwd_free(h); | |
724 | |
725 gaim_notify_info(account, _("Change password for the Gadu-Gadu account"), | |
726 _("Password was changed successfully!"), NULL); | |
727 | |
728 exit_err: | |
729 g_free(cur); | |
730 g_free(p1); | |
731 g_free(p2); | |
732 g_free(t); | |
733 g_free(info->token->id); | |
734 g_free(info->token->data); | |
735 g_free(info->token); | |
736 } | |
737 /* }}} */ | |
738 | |
739 /* | |
740 */ | |
741 /* static void ggp_change_passwd_dialog(GaimConnection *gc) {{{ */ | |
742 static void ggp_change_passwd_dialog(GaimConnection *gc) | |
743 { | |
744 GaimRequestFields *fields; | |
745 GaimRequestFieldGroup *group; | |
746 GaimRequestField *field; | |
747 | |
748 GGPInfo *info = gc->proto_data; | |
749 GGPToken *token = info->token; | |
750 | |
751 char *msg; | |
752 | |
753 | |
754 fields = gaim_request_fields_new(); | |
755 group = gaim_request_field_group_new(NULL); | |
756 gaim_request_fields_add_group(fields, group); | |
757 | |
758 field = gaim_request_field_string_new("password_cur", | |
759 _("Current password"), "", FALSE); | |
760 gaim_request_field_string_set_masked(field, TRUE); | |
761 gaim_request_field_group_add_field(group, field); | |
762 | |
763 field = gaim_request_field_string_new("password1", | |
764 _("Password"), "", FALSE); | |
765 gaim_request_field_string_set_masked(field, TRUE); | |
766 gaim_request_field_group_add_field(group, field); | |
767 | |
768 field = gaim_request_field_string_new("password2", | |
769 _("Password (retype)"), "", FALSE); | |
770 gaim_request_field_string_set_masked(field, TRUE); | |
771 gaim_request_field_group_add_field(group, field); | |
772 | |
773 field = gaim_request_field_string_new("token", | |
774 _("Enter current token"), "", FALSE); | |
775 gaim_request_field_string_set_masked(field, FALSE); | |
776 gaim_request_field_group_add_field(group, field); | |
777 | |
778 /* original size: 60x24 */ | |
779 field = gaim_request_field_image_new("token_img", | |
780 _("Current token"), token->data, token->size); | |
781 gaim_request_field_group_add_field(group, field); | |
782 | |
783 msg = g_strdup_printf("%s %d", | |
784 _("Please, enter your current password and your new password for UIN: "), | |
785 ggp_get_uin(gaim_connection_get_account(gc))); | |
786 | |
787 gaim_request_fields(gc, | |
788 _("Change Gadu-Gadu Password"), | |
789 _("Change Gadu-Gadu Password"), | |
790 msg, | |
791 fields, _("OK"), G_CALLBACK(ggp_callback_change_passwd_ok), | |
792 _("Cancel"), NULL, gc); | |
793 | |
794 g_free(msg); | |
795 } | |
796 /* }}} */ | |
797 | |
798 /* | |
799 */ | |
800 /* static void ggp_change_passwd(GaimPluginAction *action) {{{ */ | |
801 static void ggp_change_passwd(GaimPluginAction *action) | |
802 { | |
803 GaimConnection *gc = (GaimConnection *)action->context; | |
804 | |
805 ggp_token_request(gc, ggp_change_passwd_dialog); | |
806 } | |
807 /* }}} */ | |
808 | |
809 /* ----- CONFERENCES ---------------------------------------------------- */ | |
810 | |
811 /* | |
812 */ | |
813 /* static void ggp_callback_add_to_chat_ok(GaimConnection *gc, GaimRequestFields *fields) {{{ */ | |
814 static void ggp_callback_add_to_chat_ok(GaimConnection *gc, GaimRequestFields *fields) | |
815 { | |
816 GGPInfo *info = gc->proto_data; | |
817 GaimRequestField *field; | |
818 const GList *sel; | |
819 | |
820 field = gaim_request_fields_get_field(fields, "name"); | |
821 sel = gaim_request_field_list_get_selected(field); | |
822 | |
823 ggp_confer_participants_add_uin(gc, sel->data, info->tmp_buddy); | |
824 info->tmp_buddy = 0; | |
825 } | |
826 /* }}} */ | |
827 | |
828 /* | |
829 */ | |
830 /* static void ggp_bmenu_add_to_chat(GaimBlistNode *node, gpointer ignored) {{{ */ | |
831 static void ggp_bmenu_add_to_chat(GaimBlistNode *node, gpointer ignored) | |
832 { | |
833 GaimBuddy *buddy; | |
834 GaimConnection *gc; | |
835 GGPInfo *info; | |
836 | |
837 GaimRequestFields *fields; | |
838 GaimRequestFieldGroup *group; | |
839 GaimRequestField *field; | |
840 | |
841 GList *l; | |
842 gchar *msg; | |
843 | |
844 buddy = (GaimBuddy *)node; | |
845 gc = gaim_account_get_connection(gaim_buddy_get_account(buddy)); | |
846 info = gc->proto_data; | |
847 | |
848 /* TODO: It tmp_buddy != 0 then stop! */ | |
849 info->tmp_buddy = ggp_str_to_uin(gaim_buddy_get_name(buddy)); | |
850 | |
851 fields = gaim_request_fields_new(); | |
852 group = gaim_request_field_group_new(NULL); | |
853 gaim_request_fields_add_group(fields, group); | |
854 | |
855 field = gaim_request_field_list_new("name", "Chat name"); | |
856 for (l = info->chats; l != NULL; l = l->next) { | |
857 GGPChat *chat = l->data; | |
858 gaim_request_field_list_add(field, g_strdup(chat->name), | |
859 g_strdup(chat->name)); | |
860 } | |
861 gaim_request_field_group_add_field(group, field); | |
862 | |
863 msg = g_strdup_printf(_("Select a chat for buddy: %s"), | |
864 gaim_buddy_get_alias(buddy)); | |
865 gaim_request_fields(gc, | |
866 _("Add to chat..."), | |
867 _("Add to chat..."), | |
868 msg, | |
869 fields, | |
870 _("Add"), G_CALLBACK(ggp_callback_add_to_chat_ok), | |
871 _("Cancel"), NULL, gc); | |
872 g_free(msg); | |
873 } | |
874 /* }}} */ | |
875 | |
876 /* ----- BLOCK BUDDIES -------------------------------------------------- */ | |
877 | |
878 /* | |
879 */ | |
880 /* static void ggp_bmenu_block(GaimBlistNode *node, gpointer ignored) {{{ */ | |
881 static void ggp_bmenu_block(GaimBlistNode *node, gpointer ignored) | |
882 { | |
883 GaimConnection *gc; | |
884 GaimBuddy *buddy; | |
885 GGPInfo *info; | |
886 uin_t uin; | |
887 | |
888 buddy = (GaimBuddy *)node; | |
889 gc = gaim_account_get_connection(gaim_buddy_get_account(buddy)); | |
890 info = gc->proto_data; | |
891 | |
892 uin = ggp_str_to_uin(gaim_buddy_get_name(buddy)); | |
893 | |
894 if (gaim_blist_node_get_bool(node, "blocked")) { | |
895 gaim_blist_node_set_bool(node, "blocked", FALSE); | |
896 gg_remove_notify_ex(info->session, uin, GG_USER_BLOCKED); | |
897 gg_add_notify_ex(info->session, uin, GG_USER_NORMAL); | |
898 gaim_debug_info("gg", "send: uin=%d; mode=NORMAL\n", uin); | |
899 } else { | |
900 gaim_blist_node_set_bool(node, "blocked", TRUE); | |
901 gg_remove_notify_ex(info->session, uin, GG_USER_NORMAL); | |
902 gg_add_notify_ex(info->session, uin, GG_USER_BLOCKED); | |
903 gaim_debug_info("gg", "send: uin=%d; mode=BLOCKED\n", uin); | |
904 } | |
905 } | |
906 /* }}} */ | |
907 | |
908 /* ---------------------------------------------------------------------- */ | |
909 /* ----- INTERNAL CALLBACKS --------------------------------------------- */ | |
910 /* ---------------------------------------------------------------------- */ | |
911 | |
912 /* just a prototype */ | |
913 static void ggp_set_status(GaimAccount *account, GaimStatus *status); | |
914 | |
915 /** | |
916 * Handle change of the status of the buddy. | |
917 * | |
918 * @param gc GaimConnection | |
919 * @param uin UIN of the buddy. | |
920 * @param status ID of the status. | |
921 * @param descr Description. | |
922 */ | |
923 /* static void ggp_generic_status_handler(GaimConnection *gc, uin_t uin, int status, const char *descr) {{{ */ | |
924 static void ggp_generic_status_handler(GaimConnection *gc, uin_t uin, | |
925 int status, const char *descr) | |
926 { | |
927 gchar *from; | |
928 const char *st; | |
929 gchar *msg; | |
930 | |
931 from = g_strdup_printf("%ld", (unsigned long int)uin); | |
932 switch (status) { | |
933 case GG_STATUS_NOT_AVAIL: | |
934 case GG_STATUS_NOT_AVAIL_DESCR: | |
935 st = "offline"; | |
936 break; | |
937 case GG_STATUS_AVAIL: | |
938 case GG_STATUS_AVAIL_DESCR: | |
939 st = "available"; | |
940 break; | |
941 case GG_STATUS_BUSY: | |
942 case GG_STATUS_BUSY_DESCR: | |
943 st = "away"; | |
944 break; | |
945 case GG_STATUS_BLOCKED: | |
946 /* user is blocking us.... */ | |
947 st = "blocked"; | |
948 break; | |
949 default: | |
950 st = "available"; | |
951 gaim_debug_info("gg", | |
952 "GG_EVENT_NOTIFY: Unknown status: %d\n", status); | |
953 break; | |
954 } | |
955 | |
956 gaim_debug_info("gg", "st = %s\n", st); | |
957 msg = charset_convert(descr, "CP1250", "UTF-8"); | |
958 gaim_prpl_got_user_status(gaim_connection_get_account(gc), | |
959 from, st, "message", msg, NULL); | |
960 g_free(from); | |
961 g_free(msg); | |
962 } | |
963 /* }}} */ | |
964 | |
965 /* | |
966 */ | |
967 /* static void ggp_sr_close_cb(gpointer user_data) {{{ */ | |
968 static void ggp_sr_close_cb(gpointer user_data) | |
969 { | |
970 GGPSearchForm *form = user_data; | |
971 GGPInfo *info = form->user_data; | |
972 | |
973 ggp_search_remove(info->searches, form->seq); | |
974 ggp_search_form_destroy(form); | |
975 } | |
976 /* }}} */ | |
977 | |
978 /** | |
979 * Translate a status' ID to a more user-friendly name. | |
980 * | |
981 * @param id The ID of the status. | |
982 * | |
983 * @return The user-friendly name of the status. | |
984 */ | |
985 /* static const char *ggp_status_by_id(unsigned int id) {{{ */ | |
986 static const char *ggp_status_by_id(unsigned int id) | |
987 { | |
988 const char *st; | |
989 | |
990 gaim_debug_info("gg", "ggp_status_by_id: %d\n", id); | |
991 switch (id) { | |
992 case GG_STATUS_NOT_AVAIL: | |
993 st = _("Offline"); | |
994 break; | |
995 case GG_STATUS_AVAIL: | |
996 st = _("Available"); | |
997 break; | |
998 case GG_STATUS_BUSY: | |
999 st = _("Away"); | |
1000 break; | |
1001 default: | |
1002 st = _("Unknown"); | |
1003 break; | |
1004 } | |
1005 | |
1006 return st; | |
1007 } | |
1008 /* }}} */ | |
1009 | |
1010 /* | |
1011 */ | |
1012 /* static void ggp_pubdir_handle_info(GaimConnection *gc, gg_pubdir50_t req, GGPSearchForm *form) {{{ */ | |
1013 static void ggp_pubdir_handle_info(GaimConnection *gc, gg_pubdir50_t req, | |
1014 GGPSearchForm *form) | |
1015 { | |
1016 GString *text; | |
1017 char *val, *who; | |
1018 | |
1019 text = g_string_new(""); | |
1020 | |
1021 val = ggp_search_get_result(req, 0, GG_PUBDIR50_STATUS); | |
1022 /* XXX: Use of ggp_str_to_uin() is an ugly hack! */ | |
1023 g_string_append_printf(text, "<b>%s:</b> %s<br/>", | |
1024 _("Status"), ggp_status_by_id(ggp_str_to_uin(val))); | |
1025 g_free(val); | |
1026 | |
1027 who = ggp_search_get_result(req, 0, GG_PUBDIR50_UIN); | |
1028 g_string_append_printf(text, "<b>%s:</b> %s<br/>", | |
1029 _("UIN"), who); | |
1030 | |
1031 val = ggp_search_get_result(req, 0, GG_PUBDIR50_FIRSTNAME); | |
1032 g_string_append_printf(text, "<b>%s:</b> %s<br/>", | |
1033 _("First Name"), val); | |
1034 g_free(val); | |
1035 | |
1036 val = ggp_search_get_result(req, 0, GG_PUBDIR50_NICKNAME); | |
1037 g_string_append_printf(text, "<b>%s:</b> %s<br/>", | |
1038 _("Nickname"), val); | |
1039 g_free(val); | |
1040 | |
1041 val = ggp_search_get_result(req, 0, GG_PUBDIR50_CITY); | |
1042 g_string_append_printf(text, "<b>%s:</b> %s<br/>", | |
1043 _("City"), val); | |
1044 g_free(val); | |
1045 | |
1046 val = ggp_search_get_result(req, 0, GG_PUBDIR50_BIRTHYEAR); | |
1047 if (strncmp(val, "0", 1) == 0) { | |
1048 g_free(val); | |
1049 val = g_strdup(""); | |
1050 } | |
1051 g_string_append_printf(text, "<b>%s:</b> %s<br/>", | |
1052 _("Birth Year"), val); | |
1053 g_free(val); | |
1054 | |
1055 val = ggp_buddy_get_name(gc, ggp_str_to_uin(who)); | |
1056 g_free(who); | |
1057 who = val; | |
1058 | |
1059 val = gaim_strdup_withhtml(text->str); | |
1060 | |
1061 gaim_notify_userinfo(gc, who, val, ggp_sr_close_cb, form); | |
1062 | |
1063 g_string_free(text, TRUE); | |
1064 g_free(val); | |
1065 g_free(who); | |
1066 } | |
1067 /* }}} */ | |
1068 | |
1069 /* | |
1070 */ | |
1071 /* static void ggp_pubdir_handle_full(GaimConnection *gc, gg_pubdir50_t req, GGPSearchForm *form) {{{ */ | |
1072 static void ggp_pubdir_handle_full(GaimConnection *gc, gg_pubdir50_t req, | |
1073 GGPSearchForm *form) | |
1074 { | |
1075 GaimNotifySearchResults *results; | |
1076 GaimNotifySearchColumn *column; | |
1077 int res_count; | |
1078 int start; | |
1079 int i; | |
1080 | |
1081 g_return_if_fail(form != NULL); | |
1082 | |
1083 res_count = gg_pubdir50_count(req); | |
1084 res_count = (res_count > PUBDIR_RESULTS_MAX) ? PUBDIR_RESULTS_MAX : res_count; | |
1085 | |
1086 results = gaim_notify_searchresults_new(); | |
1087 | |
1088 if (results == NULL) { | |
1089 gaim_debug_error("gg", "ggp_pubdir_reply_handler: " | |
1090 "Unable to display the search results.\n"); | |
1091 gaim_notify_error(gc, NULL, | |
1092 _("Unable to display the search results."), | |
1093 NULL); | |
1094 ggp_sr_close_cb(form); | |
1095 return; | |
1096 } | |
1097 | |
1098 column = gaim_notify_searchresults_column_new(_("UIN")); | |
1099 gaim_notify_searchresults_column_add(results, column); | |
1100 | |
1101 column = gaim_notify_searchresults_column_new(_("First Name")); | |
1102 gaim_notify_searchresults_column_add(results, column); | |
1103 | |
1104 column = gaim_notify_searchresults_column_new(_("Nickname")); | |
1105 gaim_notify_searchresults_column_add(results, column); | |
1106 | |
1107 column = gaim_notify_searchresults_column_new(_("City")); | |
1108 gaim_notify_searchresults_column_add(results, column); | |
1109 | |
1110 column = gaim_notify_searchresults_column_new(_("Birth Year")); | |
1111 gaim_notify_searchresults_column_add(results, column); | |
1112 | |
1113 gaim_debug_info("gg", "Going with %d entries\n", res_count); | |
1114 | |
1115 start = (int)ggp_str_to_uin(gg_pubdir50_get(req, 0, GG_PUBDIR50_START)); | |
1116 gaim_debug_info("gg", "start = %d\n", start); | |
1117 | |
1118 for (i = 0; i < res_count; i++) { | |
1119 GList *row = NULL; | |
1120 char *birth = ggp_search_get_result(req, i, GG_PUBDIR50_BIRTHYEAR); | |
1121 | |
1122 /* TODO: Status will be displayed as an icon. */ | |
1123 /* row = g_list_append(row, ggp_search_get_result(req, i, GG_PUBDIR50_STATUS)); */ | |
1124 row = g_list_append(row, ggp_search_get_result(req, i, | |
1125 GG_PUBDIR50_UIN)); | |
1126 row = g_list_append(row, ggp_search_get_result(req, i, | |
1127 GG_PUBDIR50_FIRSTNAME)); | |
1128 row = g_list_append(row, ggp_search_get_result(req, i, | |
1129 GG_PUBDIR50_NICKNAME)); | |
1130 row = g_list_append(row, ggp_search_get_result(req, i, | |
1131 GG_PUBDIR50_CITY)); | |
1132 row = g_list_append(row, | |
1133 (birth && strncmp(birth, "0", 1)) ? birth : g_strdup("-")); | |
1134 | |
1135 gaim_notify_searchresults_row_add(results, row); | |
1136 | |
1137 if (i == res_count - 1) { | |
1138 g_free(form->last_uin); | |
1139 form->last_uin = ggp_search_get_result(req, i, GG_PUBDIR50_UIN); | |
1140 } | |
1141 } | |
1142 | |
1143 gaim_notify_searchresults_button_add(results, GAIM_NOTIFY_BUTTON_CONTINUE, | |
1144 ggp_callback_show_next); | |
1145 gaim_notify_searchresults_button_add(results, GAIM_NOTIFY_BUTTON_ADD, | |
1146 ggp_callback_add_buddy); | |
1147 gaim_notify_searchresults_button_add(results, GAIM_NOTIFY_BUTTON_IM, | |
1148 ggp_callback_im); | |
1149 | |
1150 if (form->window == NULL) { | |
1151 void *h = gaim_notify_searchresults(gc, | |
1152 _("Gadu-Gadu Public Directory"), | |
1153 _("Search results"), NULL, results, | |
1154 (GaimNotifyCloseCallback)ggp_sr_close_cb, | |
1155 form); | |
1156 | |
1157 if (h == NULL) { | |
1158 gaim_debug_error("gg", "ggp_pubdir_reply_handler: " | |
1159 "Unable to display the search results.\n"); | |
1160 gaim_notify_error(gc, NULL, | |
1161 _("Unable to display the search results."), | |
1162 NULL); | |
1163 return; | |
1164 } | |
1165 | |
1166 form->window = h; | |
1167 } else { | |
1168 gaim_notify_searchresults_new_rows(gc, results, form->window); | |
1169 } | |
1170 } | |
1171 /* }}} */ | |
1172 | |
1173 /* | |
1174 */ | |
1175 /* static void ggp_pubdir_reply_handler(GaimConnection *gc, gg_pubdir50_t req) {{{ */ | |
1176 static void ggp_pubdir_reply_handler(GaimConnection *gc, gg_pubdir50_t req) | |
1177 { | |
1178 GGPInfo *info = gc->proto_data; | |
1179 GGPSearchForm *form; | |
1180 int res_count; | |
1181 guint32 seq; | |
1182 | |
1183 seq = gg_pubdir50_seq(req); | |
1184 form = ggp_search_get(info->searches, seq); | |
1185 | |
1186 /* | |
1187 * this can happen when user will request more results | |
1188 * and close the results window before they arrive. | |
1189 */ | |
1190 g_return_if_fail(form != NULL); | |
1191 | |
1192 res_count = gg_pubdir50_count(req); | |
1193 if (res_count < 1) { | |
1194 gaim_debug_info("gg", "GG_EVENT_PUBDIR50_SEARCH_REPLY: Nothing found\n"); | |
1195 gaim_notify_error(gc, NULL, | |
1196 _("No matching users found"), | |
1197 _("There are no users matching your search criteria.")); | |
1198 ggp_sr_close_cb(form); | |
1199 return; | |
1200 } | |
1201 | |
1202 switch (form->search_type) { | |
1203 case GGP_SEARCH_TYPE_INFO: | |
1204 ggp_pubdir_handle_info(gc, req, form); | |
1205 break; | |
1206 case GGP_SEARCH_TYPE_FULL: | |
1207 ggp_pubdir_handle_full(gc, req, form); | |
1208 break; | |
1209 default: | |
1210 gaim_debug_warning("gg", "Unknown search_type!\n"); | |
1211 break; | |
1212 } | |
1213 } | |
1214 /* }}} */ | |
1215 | |
1216 /** | |
1217 * Dispatch a message received from a buddy. | |
1218 * | |
1219 * @param gc GaimConnection. | |
1220 * @param ev Gadu-Gadu event structure. | |
1221 */ | |
1222 /* static void ggp_recv_message_handler(GaimConnection *gc, const struct gg_event *ev) {{{ */ | |
1223 static void ggp_recv_message_handler(GaimConnection *gc, const struct gg_event *ev) | |
1224 { | |
1225 GGPInfo *info = gc->proto_data; | |
1226 GaimConversation *conv; | |
1227 gchar *from; | |
1228 gchar *msg; | |
1229 gchar *tmp; | |
1230 | |
1231 from = g_strdup_printf("%lu", (unsigned long int)ev->event.msg.sender); | |
1232 | |
1233 tmp = charset_convert((const char *)ev->event.msg.message, | |
1234 "CP1250", "UTF-8"); | |
1235 gaim_str_strip_char(tmp, '\r'); | |
1236 msg = g_markup_escape_text(tmp, -1); | |
1237 g_free(tmp); | |
1238 | |
1239 gaim_debug_info("gg", "msg form (%s): %s (class = %d; rcpt_count = %d)\n", | |
1240 from, msg, ev->event.msg.msgclass, | |
1241 ev->event.msg.recipients_count); | |
1242 | |
1243 if (ev->event.msg.recipients_count == 0) { | |
1244 serv_got_im(gc, from, msg, 0, ev->event.msg.time); | |
1245 } else { | |
1246 const char *chat_name; | |
1247 int chat_id; | |
1248 char *buddy_name; | |
1249 | |
1250 chat_name = ggp_confer_find_by_participants(gc, | |
1251 ev->event.msg.recipients, | |
1252 ev->event.msg.recipients_count); | |
1253 | |
1254 if (chat_name == NULL) { | |
1255 chat_name = ggp_confer_add_new(gc, NULL); | |
1256 serv_got_joined_chat(gc, info->chats_count, chat_name); | |
1257 | |
1258 ggp_confer_participants_add_uin(gc, chat_name, | |
1259 ev->event.msg.sender); | |
1260 | |
1261 ggp_confer_participants_add(gc, chat_name, | |
1262 ev->event.msg.recipients, | |
1263 ev->event.msg.recipients_count); | |
1264 } | |
1265 conv = ggp_confer_find_by_name(gc, chat_name); | |
1266 chat_id = gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv)); | |
1267 | |
1268 buddy_name = ggp_buddy_get_name(gc, ev->event.msg.sender); | |
1269 serv_got_chat_in(gc, chat_id, buddy_name, | |
1270 GAIM_MESSAGE_RECV, msg, ev->event.msg.time); | |
1271 g_free(buddy_name); | |
1272 } | |
1273 g_free(msg); | |
1274 g_free(from); | |
1275 } | |
1276 /* }}} */ | |
1277 | |
1278 /* | |
1279 */ | |
1280 /* static void ggp_callback_recv(gpointer _gc, gint fd, GaimInputCondition cond) {{{ */ | |
1281 static void ggp_callback_recv(gpointer _gc, gint fd, GaimInputCondition cond) | |
1282 { | |
1283 GaimConnection *gc = _gc; | |
1284 GGPInfo *info = gc->proto_data; | |
1285 struct gg_event *ev; | |
1286 int i; | |
1287 | |
1288 if (!(ev = gg_watch_fd(info->session))) { | |
1289 gaim_debug_error("gg", | |
1290 "ggp_callback_recv: gg_watch_fd failed -- CRITICAL!\n"); | |
1291 gaim_connection_error(gc, _("Unable to read socket")); | |
1292 return; | |
1293 } | |
1294 | |
1295 switch (ev->type) { | |
1296 case GG_EVENT_NONE: | |
1297 /* Nothing happened. */ | |
1298 break; | |
1299 case GG_EVENT_MSG: | |
1300 ggp_recv_message_handler(gc, ev); | |
1301 break; | |
1302 case GG_EVENT_ACK: | |
1303 gaim_debug_info("gg", | |
1304 "message sent to: %ld, delivery status=%d, seq=%d\n", | |
1305 ev->event.ack.recipient, ev->event.ack.status, | |
1306 ev->event.ack.seq); | |
1307 break; | |
1308 case GG_EVENT_NOTIFY: | |
1309 case GG_EVENT_NOTIFY_DESCR: | |
1310 { | |
1311 struct gg_notify_reply *n; | |
1312 char *descr; | |
1313 | |
1314 gaim_debug_info("gg", "notify_pre: (%d) status: %d\n", | |
1315 ev->event.notify->uin, | |
1316 ev->event.notify->status); | |
1317 | |
1318 n = (ev->type == GG_EVENT_NOTIFY) ? ev->event.notify | |
1319 : ev->event.notify_descr.notify; | |
1320 | |
1321 for (; n->uin; n++) { | |
1322 descr = (ev->type == GG_EVENT_NOTIFY) ? NULL | |
1323 : ev->event.notify_descr.descr; | |
1324 | |
1325 gaim_debug_info("gg", | |
1326 "notify: (%d) status: %d; descr: %s\n", | |
14462
34a5709ff951
[gaim-migrate @ 17176]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14459
diff
changeset
|
1327 n->uin, n->status, descr ? descr : "(null)"); |
14192 | 1328 |
1329 ggp_generic_status_handler(gc, | |
1330 n->uin, n->status, descr); | |
1331 } | |
1332 } | |
1333 break; | |
1334 case GG_EVENT_NOTIFY60: | |
1335 gaim_debug_info("gg", | |
1336 "notify60_pre: (%d) status=%d; version=%d; descr=%s\n", | |
1337 ev->event.notify60->uin, ev->event.notify60->status, | |
14462
34a5709ff951
[gaim-migrate @ 17176]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14459
diff
changeset
|
1338 ev->event.notify60->version, |
34a5709ff951
[gaim-migrate @ 17176]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14459
diff
changeset
|
1339 ev->event.notify60->descr ? ev->event.notify60->descr : "(null)"); |
14192 | 1340 |
1341 for (i = 0; ev->event.notify60[i].uin; i++) { | |
1342 gaim_debug_info("gg", | |
1343 "notify60: (%d) status=%d; version=%d; descr=%s\n", | |
1344 ev->event.notify60[i].uin, | |
1345 ev->event.notify60[i].status, | |
1346 ev->event.notify60[i].version, | |
14462
34a5709ff951
[gaim-migrate @ 17176]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14459
diff
changeset
|
1347 ev->event.notify60[i].descr ? ev->event.notify60[i].descr : "(null)"); |
14192 | 1348 |
1349 ggp_generic_status_handler(gc, ev->event.notify60[i].uin, | |
1350 ev->event.notify60[i].status, | |
1351 ev->event.notify60[i].descr); | |
1352 } | |
1353 break; | |
1354 case GG_EVENT_STATUS: | |
1355 gaim_debug_info("gg", "status: (%d) status=%d; descr=%s\n", | |
1356 ev->event.status.uin, ev->event.status.status, | |
14462
34a5709ff951
[gaim-migrate @ 17176]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14459
diff
changeset
|
1357 ev->event.status.descr ? ev->event.status.descr : "(null)"); |
14192 | 1358 |
1359 ggp_generic_status_handler(gc, ev->event.status.uin, | |
1360 ev->event.status.status, ev->event.status.descr); | |
1361 break; | |
1362 case GG_EVENT_STATUS60: | |
1363 gaim_debug_info("gg", | |
1364 "status60: (%d) status=%d; version=%d; descr=%s\n", | |
1365 ev->event.status60.uin, ev->event.status60.status, | |
14462
34a5709ff951
[gaim-migrate @ 17176]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14459
diff
changeset
|
1366 ev->event.status60.version, |
34a5709ff951
[gaim-migrate @ 17176]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14459
diff
changeset
|
1367 ev->event.status60.descr ? ev->event.status60.descr : "(null)"); |
14192 | 1368 |
1369 ggp_generic_status_handler(gc, ev->event.status60.uin, | |
1370 ev->event.status60.status, ev->event.status60.descr); | |
1371 break; | |
1372 case GG_EVENT_USERLIST: | |
1373 if (ev->event.userlist.type == GG_USERLIST_GET_REPLY) { | |
1374 gaim_debug_info("gg", "GG_USERLIST_GET_REPLY\n"); | |
1375 gaim_notify_info(gc, NULL, | |
1376 _("Buddy list downloaded"), | |
1377 _("Your buddy list was downloaded from the server.")); | |
1378 if (ev->event.userlist.reply != NULL) { | |
1379 ggp_buddylist_load(gc, ev->event.userlist.reply); | |
1380 } | |
1381 } else { | |
1382 gaim_debug_info("gg", "GG_USERLIST_PUT_REPLY\n"); | |
1383 gaim_notify_info(gc, NULL, | |
1384 _("Buddy list uploaded"), | |
1385 _("Your buddy list was stored on the server.")); | |
1386 } | |
1387 break; | |
1388 case GG_EVENT_PUBDIR50_SEARCH_REPLY: | |
1389 ggp_pubdir_reply_handler(gc, ev->event.pubdir50); | |
1390 break; | |
1391 default: | |
1392 gaim_debug_error("gg", | |
1393 "unsupported event type=%d\n", ev->type); | |
1394 break; | |
1395 } | |
1396 | |
1397 gg_free_event(ev); | |
1398 } | |
1399 /* }}} */ | |
1400 | |
1401 /* | |
1402 */ | |
1403 /* static void ggp_async_login_handler(gpointer _gc, gint fd, GaimInputCondition cond) {{{ */ | |
1404 static void ggp_async_login_handler(gpointer _gc, gint fd, GaimInputCondition cond) | |
1405 { | |
1406 GaimConnection *gc = _gc; | |
1407 GGPInfo *info = gc->proto_data; | |
1408 struct gg_event *ev; | |
1409 | |
1410 gaim_debug_info("gg", "login_handler: session: check = %d; state = %d;\n", | |
1411 info->session->check, info->session->state); | |
1412 | |
1413 switch (info->session->state) { | |
1414 case GG_STATE_RESOLVING: | |
1415 gaim_debug_info("gg", "GG_STATE_RESOLVING\n"); | |
1416 break; | |
1417 case GG_STATE_CONNECTING_HUB: | |
1418 gaim_debug_info("gg", "GG_STATE_CONNECTING_HUB\n"); | |
1419 break; | |
1420 case GG_STATE_READING_DATA: | |
1421 gaim_debug_info("gg", "GG_STATE_READING_DATA\n"); | |
1422 break; | |
1423 case GG_STATE_CONNECTING_GG: | |
1424 gaim_debug_info("gg", "GG_STATE_CONNECTING_GG\n"); | |
1425 break; | |
1426 case GG_STATE_READING_KEY: | |
1427 gaim_debug_info("gg", "GG_STATE_READING_KEY\n"); | |
1428 break; | |
1429 case GG_STATE_READING_REPLY: | |
1430 gaim_debug_info("gg", "GG_STATE_READING_REPLY\n"); | |
1431 break; | |
1432 default: | |
1433 gaim_debug_error("gg", "unknown state = %d\n", | |
1434 info->session->state); | |
1435 break; | |
1436 } | |
1437 | |
1438 if (!(ev = gg_watch_fd(info->session))) { | |
1439 gaim_debug_error("gg", "login_handler: gg_watch_fd failed!\n"); | |
1440 gaim_connection_error(gc, _("Unable to read socket")); | |
1441 return; | |
1442 } | |
1443 gaim_debug_info("gg", "login_handler: session->fd = %d\n", info->session->fd); | |
1444 gaim_debug_info("gg", "login_handler: session: check = %d; state = %d;\n", | |
1445 info->session->check, info->session->state); | |
1446 | |
1447 gaim_input_remove(gc->inpa); | |
1448 | |
1449 /** XXX I think that this shouldn't be done if ev->type is GG_EVENT_CONN_FAILED or GG_EVENT_CONN_SUCCESS -datallah */ | |
1450 gc->inpa = gaim_input_add(info->session->fd, | |
1451 (info->session->check == 1) ? GAIM_INPUT_WRITE | |
1452 : GAIM_INPUT_READ, | |
1453 ggp_async_login_handler, gc); | |
1454 | |
1455 switch (ev->type) { | |
1456 case GG_EVENT_NONE: | |
1457 /* Nothing happened. */ | |
1458 gaim_debug_info("gg", "GG_EVENT_NONE\n"); | |
1459 break; | |
1460 case GG_EVENT_CONN_SUCCESS: | |
1461 { | |
1462 GaimAccount *account; | |
1463 GaimPresence *presence; | |
1464 GaimStatus *status; | |
1465 | |
1466 gaim_debug_info("gg", "GG_EVENT_CONN_SUCCESS\n"); | |
1467 gaim_input_remove(gc->inpa); | |
1468 gc->inpa = gaim_input_add(info->session->fd, | |
1469 GAIM_INPUT_READ, | |
1470 ggp_callback_recv, gc); | |
1471 | |
1472 /* gg_change_status(info->session, GG_STATUS_AVAIL); */ | |
1473 | |
1474 account = gaim_connection_get_account(gc); | |
1475 presence = gaim_account_get_presence(account); | |
1476 status = gaim_presence_get_active_status(presence); | |
1477 | |
1478 ggp_set_status(account, status); | |
1479 gaim_connection_set_state(gc, GAIM_CONNECTED); | |
1480 ggp_buddylist_send(gc); | |
1481 } | |
1482 break; | |
1483 case GG_EVENT_CONN_FAILED: | |
1484 gaim_input_remove(gc->inpa); | |
1485 gc->inpa = 0; | |
1486 gaim_connection_error(gc, _("Connection failed.")); | |
1487 break; | |
1488 default: | |
1489 gaim_debug_error("gg", "strange event: %d\n", ev->type); | |
1490 break; | |
1491 } | |
1492 | |
1493 gg_free_event(ev); | |
1494 } | |
1495 /* }}} */ | |
1496 | |
1497 /* ---------------------------------------------------------------------- */ | |
1498 /* ----- GaimPluginProtocolInfo ----------------------------------------- */ | |
1499 /* ---------------------------------------------------------------------- */ | |
1500 | |
1501 /* static const char *ggp_list_icon(GaimAccount *account, GaimBuddy *buddy) {{{ */ | |
1502 static const char *ggp_list_icon(GaimAccount *account, GaimBuddy *buddy) | |
1503 { | |
1504 return "gadu-gadu"; | |
1505 } | |
1506 /* }}} */ | |
1507 | |
1508 /* static void ggp_list_emblems(GaimBuddy *b, const char **se, const char **sw, const char **nw, const char **ne) {{{ */ | |
1509 static void ggp_list_emblems(GaimBuddy *b, const char **se, const char **sw, | |
1510 const char **nw, const char **ne) | |
1511 { | |
1512 GaimPresence *presence = gaim_buddy_get_presence(b); | |
1513 | |
1514 /* | |
1515 * Note to myself: | |
1516 * The only valid status types are those defined | |
1517 * in prpl_info->status_types. | |
1518 * | |
1519 * Usable icons: away, blocked, dnd, extended_away, | |
1520 * freeforchat, ignored, invisible, na, offline. | |
1521 */ | |
1522 | |
1523 if (!GAIM_BUDDY_IS_ONLINE(b)) { | |
1524 *se = "offline"; | |
1525 } else if (gaim_presence_is_status_primitive_active(presence, GAIM_STATUS_AWAY)) { | |
1526 *se = "away"; | |
1527 } else if (gaim_presence_is_status_active(presence, "blocked")) { | |
1528 *se = "blocked"; | |
1529 } | |
1530 } | |
1531 /* }}} */ | |
1532 | |
1533 /* static char *ggp_status_text(GaimBuddy *b) {{{ */ | |
1534 static char *ggp_status_text(GaimBuddy *b) | |
1535 { | |
1536 GaimStatus *status; | |
1537 const char *msg; | |
1538 char *text; | |
1539 char *tmp; | |
1540 | |
1541 status = gaim_presence_get_active_status(gaim_buddy_get_presence(b)); | |
1542 | |
1543 msg = gaim_status_get_attr_string(status, "message"); | |
1544 | |
1545 if (msg != NULL) { | |
1546 tmp = gaim_markup_strip_html(msg); | |
1547 text = g_markup_escape_text(tmp, -1); | |
1548 g_free(tmp); | |
1549 | |
1550 return text; | |
1551 } else { | |
14459
4e004a2994c2
[gaim-migrate @ 17173]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14192
diff
changeset
|
1552 tmp = gaim_utf8_salvage(gaim_status_get_name(status)); |
14192 | 1553 text = g_markup_escape_text(tmp, -1); |
1554 g_free(tmp); | |
1555 | |
1556 return text; | |
1557 } | |
1558 } | |
1559 /* }}} */ | |
1560 | |
1561 /* static void ggp_tooltip_text(GaimBuddy *b, GString *str, gboolean full) {{{ */ | |
1562 static void ggp_tooltip_text(GaimBuddy *b, GString *str, gboolean full) | |
1563 { | |
1564 GaimStatus *status; | |
1565 char *text; | |
1566 const char *msg, *name; | |
1567 | |
14944 | 1568 g_return_if_fail(b != NULL); |
1569 | |
14192 | 1570 status = gaim_presence_get_active_status(gaim_buddy_get_presence(b)); |
1571 msg = gaim_status_get_attr_string(status, "message"); | |
1572 name = gaim_status_get_name(status); | |
1573 | |
1574 if (msg != NULL) { | |
1575 text = g_markup_escape_text(msg, -1); | |
15135 | 1576 if (GAIM_BUDDY_IS_ONLINE(b)) { |
1577 g_string_append_printf(str, "\n<b>%s:</b> %s: %s", | |
1578 _("Status"), name, text); | |
1579 } else { | |
1580 g_string_append_printf(str, "\n<b>%s:</b>: %s", | |
1581 _("Message"), text); | |
1582 } | |
14192 | 1583 g_free(text); |
15135 | 1584 } else if (GAIM_BUDDY_IS_ONLINE(b)) { |
14192 | 1585 g_string_append_printf(str, "\n<b>%s:</b> %s", |
1586 _("Status"), name); | |
1587 } | |
1588 } | |
1589 /* }}} */ | |
1590 | |
1591 /* static GList *ggp_status_types(GaimAccount *account) {{{ */ | |
1592 static GList *ggp_status_types(GaimAccount *account) | |
1593 { | |
1594 GaimStatusType *type; | |
1595 GList *types = NULL; | |
1596 | |
1597 type = gaim_status_type_new_with_attrs( | |
1598 GAIM_STATUS_AVAILABLE, NULL, NULL, TRUE, TRUE, FALSE, | |
1599 "message", _("Message"), gaim_value_new(GAIM_TYPE_STRING), | |
1600 NULL); | |
1601 types = g_list_append(types, type); | |
1602 | |
1603 /* | |
1604 * Without this selecting Invisible as own status doesn't | |
1605 * work. It's not used and not needed to show status of buddies. | |
1606 */ | |
1607 type = gaim_status_type_new_with_attrs( | |
1608 GAIM_STATUS_INVISIBLE, NULL, NULL, TRUE, TRUE, FALSE, | |
1609 "message", _("Message"), gaim_value_new(GAIM_TYPE_STRING), | |
1610 NULL); | |
1611 types = g_list_append(types, type); | |
1612 | |
1613 type = gaim_status_type_new_with_attrs( | |
1614 GAIM_STATUS_AWAY, NULL, NULL, TRUE, TRUE, FALSE, | |
1615 "message", _("Message"), gaim_value_new(GAIM_TYPE_STRING), | |
1616 NULL); | |
1617 types = g_list_append(types, type); | |
1618 | |
1619 /* | |
1620 * This status is necessary to display guys who are blocking *us*. | |
1621 */ | |
1622 type = gaim_status_type_new_with_attrs( | |
1623 GAIM_STATUS_INVISIBLE, "blocked", _("Blocked"), TRUE, FALSE, FALSE, | |
1624 "message", _("Message"), gaim_value_new(GAIM_TYPE_STRING), NULL); | |
1625 types = g_list_append(types, type); | |
1626 | |
1627 type = gaim_status_type_new_with_attrs( | |
1628 GAIM_STATUS_OFFLINE, NULL, NULL, TRUE, TRUE, FALSE, | |
1629 "message", _("Message"), gaim_value_new(GAIM_TYPE_STRING), | |
1630 NULL); | |
1631 types = g_list_append(types, type); | |
1632 | |
1633 return types; | |
1634 } | |
1635 /* }}} */ | |
1636 | |
1637 /* static GList *ggp_blist_node_menu(GaimBlistNode *node) {{{ */ | |
1638 static GList *ggp_blist_node_menu(GaimBlistNode *node) | |
1639 { | |
1640 GaimMenuAction *act; | |
1641 GList *m = NULL; | |
1642 | |
1643 if (!GAIM_BLIST_NODE_IS_BUDDY(node)) | |
1644 return NULL; | |
1645 | |
1646 act = gaim_menu_action_new(_("Add to chat"), | |
1647 GAIM_CALLBACK(ggp_bmenu_add_to_chat), | |
1648 NULL, NULL); | |
1649 m = g_list_append(m, act); | |
1650 | |
1651 /* Using a blist node boolean here is also wrong. | |
1652 * Once the Block and Unblock actions are added to the core, | |
1653 * this will have to go. -- rlaager */ | |
1654 if (gaim_blist_node_get_bool(node, "blocked")) { | |
1655 act = gaim_menu_action_new(_("Unblock"), | |
1656 GAIM_CALLBACK(ggp_bmenu_block), | |
1657 NULL, NULL); | |
1658 } else { | |
1659 act = gaim_menu_action_new(_("Block"), | |
1660 GAIM_CALLBACK(ggp_bmenu_block), | |
1661 NULL, NULL); | |
1662 } | |
1663 m = g_list_append(m, act); | |
1664 | |
1665 return m; | |
1666 } | |
1667 /* }}} */ | |
1668 | |
1669 /* static GList *ggp_chat_info(GaimConnection *gc) {{{ */ | |
1670 static GList *ggp_chat_info(GaimConnection *gc) | |
1671 { | |
1672 GList *m = NULL; | |
1673 struct proto_chat_entry *pce; | |
1674 | |
1675 pce = g_new0(struct proto_chat_entry, 1); | |
1676 pce->label = _("Chat _name:"); | |
1677 pce->identifier = "name"; | |
1678 pce->required = TRUE; | |
1679 m = g_list_append(m, pce); | |
1680 | |
1681 return m; | |
1682 } | |
1683 /* }}} */ | |
1684 | |
1685 /* static void ggp_login(GaimAccount *account) {{{ */ | |
1686 static void ggp_login(GaimAccount *account) | |
1687 { | |
1688 GaimConnection *gc; | |
1689 struct gg_login_params *glp; | |
1690 GGPInfo *info; | |
1691 | |
1692 if (ggp_setup_proxy(account) == -1) | |
1693 return; | |
1694 | |
1695 gc = gaim_account_get_connection(account); | |
1696 glp = g_new0(struct gg_login_params, 1); | |
1697 info = g_new0(GGPInfo, 1); | |
1698 | |
1699 /* Probably this should be moved to *_new() function. */ | |
1700 info->session = NULL; | |
1701 info->chats = NULL; | |
1702 info->chats_count = 0; | |
1703 info->token = NULL; | |
1704 info->searches = ggp_search_new(); | |
1705 | |
1706 gc->proto_data = info; | |
1707 | |
1708 glp->uin = ggp_get_uin(account); | |
1709 glp->password = (char *)gaim_account_get_password(account); | |
1710 | |
1711 glp->async = 1; | |
1712 glp->status = GG_STATUS_AVAIL; | |
1713 glp->tls = 0; | |
1714 | |
1715 info->session = gg_login(glp); | |
1716 if (info->session == NULL) { | |
1717 gaim_connection_error(gc, _("Connection failed.")); | |
1718 g_free(glp); | |
1719 return; | |
1720 } | |
1721 gc->inpa = gaim_input_add(info->session->fd, GAIM_INPUT_READ, | |
1722 ggp_async_login_handler, gc); | |
1723 } | |
1724 /* }}} */ | |
1725 | |
1726 /* static void ggp_close(GaimConnection *gc) {{{ */ | |
1727 static void ggp_close(GaimConnection *gc) | |
1728 { | |
1729 | |
1730 if (gc == NULL) { | |
1731 gaim_debug_info("gg", "gc == NULL\n"); | |
1732 return; | |
1733 } | |
1734 | |
1735 if (gc->proto_data) { | |
1736 GaimAccount *account = gaim_connection_get_account(gc); | |
1737 GaimStatus *status; | |
1738 GGPInfo *info = gc->proto_data; | |
1739 | |
1740 status = gaim_account_get_active_status(account); | |
1741 | |
1742 if (info->session != NULL) { | |
1743 ggp_set_status(account, status); | |
1744 gg_logoff(info->session); | |
1745 gg_free_session(info->session); | |
1746 } | |
1747 | |
1748 /* Immediately close any notifications on this handle since that process depends | |
1749 * upon the contents of info->searches, which we are about to destroy. | |
1750 */ | |
1751 gaim_notify_close_with_handle(gc); | |
1752 | |
1753 ggp_search_destroy(info->searches); | |
1754 g_free(info); | |
1755 gc->proto_data = NULL; | |
1756 } | |
1757 | |
1758 if (gc->inpa > 0) | |
1759 gaim_input_remove(gc->inpa); | |
1760 | |
1761 ggp_buddylist_offline(gc); | |
1762 | |
1763 gaim_debug_info("gg", "Connection closed.\n"); | |
1764 } | |
1765 /* }}} */ | |
1766 | |
1767 /* static int ggp_send_im(GaimConnection *gc, const char *who, const char *msg, GaimMessageFlags flags) {{{ */ | |
1768 static int ggp_send_im(GaimConnection *gc, const char *who, const char *msg, | |
1769 GaimMessageFlags flags) | |
1770 { | |
1771 GGPInfo *info = gc->proto_data; | |
1772 char *tmp, *plain; | |
1773 | |
1774 if (strlen(msg) == 0) | |
1775 return 1; | |
1776 | |
1777 plain = gaim_unescape_html(msg); | |
1778 gaim_debug_info("gg", "ggp_send_im: msg = %s\n", msg); | |
1779 tmp = charset_convert(plain, "UTF-8", "CP1250"); | |
1780 g_free(plain); | |
1781 | |
1782 if (tmp != NULL && strlen(tmp) > 0) { | |
1783 if (gg_send_message(info->session, GG_CLASS_CHAT, | |
1784 ggp_str_to_uin(who), (unsigned char *)tmp) < 0) { | |
1785 return -1; | |
1786 } | |
1787 } | |
1788 g_free(tmp); | |
1789 | |
1790 return 1; | |
1791 } | |
1792 /* }}} */ | |
1793 | |
1794 /* static void ggp_get_info(GaimConnection *gc, const char *name) { {{{ */ | |
1795 static void ggp_get_info(GaimConnection *gc, const char *name) | |
1796 { | |
1797 GGPInfo *info = gc->proto_data; | |
1798 GGPSearchForm *form; | |
1799 guint32 seq; | |
1800 | |
1801 form = ggp_search_form_new(GGP_SEARCH_TYPE_INFO); | |
1802 | |
1803 form->user_data = info; | |
1804 form->uin = g_strdup(name); | |
1805 form->offset = g_strdup("0"); | |
1806 form->last_uin = g_strdup("0"); | |
1807 | |
1808 seq = ggp_search_start(gc, form); | |
1809 ggp_search_add(info->searches, seq, form); | |
1810 } | |
1811 /* }}} */ | |
1812 | |
1813 /* static void ggp_set_status(GaimAccount *account, GaimStatus *status) {{{ */ | |
1814 static void ggp_set_status(GaimAccount *account, GaimStatus *status) | |
1815 { | |
1816 GaimConnection *gc; | |
1817 GGPInfo *info; | |
1818 const char *status_id, *msg; | |
1819 int new_status, new_status_descr; | |
1820 | |
1821 if (!gaim_status_is_active(status)) | |
1822 return; | |
1823 | |
1824 gc = gaim_account_get_connection(account); | |
1825 info = gc->proto_data; | |
1826 | |
1827 status_id = gaim_status_get_id(status); | |
1828 | |
1829 gaim_debug_info("gg", "ggp_set_status: Requested status = %s\n", | |
1830 status_id); | |
1831 | |
1832 if (strcmp(status_id, "available") == 0) { | |
1833 new_status = GG_STATUS_AVAIL; | |
1834 new_status_descr = GG_STATUS_AVAIL_DESCR; | |
1835 } else if (strcmp(status_id, "away") == 0) { | |
1836 new_status = GG_STATUS_BUSY; | |
1837 new_status_descr = GG_STATUS_BUSY_DESCR; | |
1838 } else if (strcmp(status_id, "invisible") == 0) { | |
1839 new_status = GG_STATUS_INVISIBLE; | |
1840 new_status_descr = GG_STATUS_INVISIBLE_DESCR; | |
1841 } else if (strcmp(status_id, "offline") == 0) { | |
1842 new_status = GG_STATUS_NOT_AVAIL; | |
1843 new_status_descr = GG_STATUS_NOT_AVAIL_DESCR; | |
1844 } else { | |
1845 new_status = GG_STATUS_AVAIL; | |
1846 new_status_descr = GG_STATUS_AVAIL_DESCR; | |
1847 gaim_debug_info("gg", | |
1848 "ggp_set_status: uknown status requested (status_id=%s)\n", | |
1849 status_id); | |
1850 } | |
1851 | |
1852 msg = gaim_status_get_attr_string(status, "message"); | |
1853 | |
1854 if (msg == NULL) { | |
1855 gg_change_status(info->session, new_status); | |
1856 } else { | |
1857 gchar *tmp, *new_msg; | |
1858 | |
1859 tmp = charset_convert(msg, "UTF-8", "CP1250"); | |
1860 new_msg = gaim_markup_strip_html(tmp); | |
1861 g_free(tmp); | |
1862 | |
1863 gg_change_status_descr(info->session, new_status_descr, new_msg); | |
1864 g_free(new_msg); | |
1865 } | |
1866 } | |
1867 /* }}} */ | |
1868 | |
1869 /* static void ggp_add_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) {{{ */ | |
1870 static void ggp_add_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) | |
1871 { | |
1872 GGPInfo *info = gc->proto_data; | |
1873 | |
1874 gg_add_notify(info->session, ggp_str_to_uin(buddy->name)); | |
1875 } | |
1876 /* }}} */ | |
1877 | |
1878 /* static void ggp_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) {{{ */ | |
1879 static void ggp_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, | |
1880 GaimGroup *group) | |
1881 { | |
1882 GGPInfo *info = gc->proto_data; | |
1883 | |
1884 gg_remove_notify(info->session, ggp_str_to_uin(buddy->name)); | |
1885 } | |
1886 /* }}} */ | |
1887 | |
1888 /* static void ggp_join_chat(GaimConnection *gc, GHashTable *data) {{{ */ | |
1889 static void ggp_join_chat(GaimConnection *gc, GHashTable *data) | |
1890 { | |
1891 GGPInfo *info = gc->proto_data; | |
1892 GGPChat *chat; | |
1893 char *chat_name; | |
1894 GList *l; | |
1895 GaimConversation *conv; | |
1896 GaimAccount *account = gaim_connection_get_account(gc); | |
1897 | |
1898 chat_name = g_hash_table_lookup(data, "name"); | |
1899 | |
1900 if (chat_name == NULL) | |
1901 return; | |
1902 | |
1903 gaim_debug_info("gg", "joined %s chat\n", chat_name); | |
1904 | |
1905 for (l = info->chats; l != NULL; l = l->next) { | |
1906 chat = l->data; | |
1907 | |
1908 if (chat != NULL && g_utf8_collate(chat->name, chat_name) == 0) { | |
1909 gaim_notify_error(gc, _("Chat error"), | |
1910 _("This chat name is already in use"), NULL); | |
1911 return; | |
1912 } | |
1913 } | |
1914 | |
1915 ggp_confer_add_new(gc, chat_name); | |
1916 conv = serv_got_joined_chat(gc, info->chats_count, chat_name); | |
1917 gaim_conv_chat_add_user(GAIM_CONV_CHAT(conv), | |
1918 gaim_account_get_username(account), NULL, | |
1919 GAIM_CBFLAGS_NONE, TRUE); | |
1920 } | |
1921 /* }}} */ | |
1922 | |
1923 /* static char *ggp_get_chat_name(GHashTable *data) { {{{ */ | |
1924 static char *ggp_get_chat_name(GHashTable *data) { | |
1925 return g_strdup(g_hash_table_lookup(data, "name")); | |
1926 } | |
1927 /* }}} */ | |
1928 | |
1929 /* static int ggp_chat_send(GaimConnection *gc, int id, const char *message, GaimMessageFlags flags) {{{ */ | |
1930 static int ggp_chat_send(GaimConnection *gc, int id, const char *message, GaimMessageFlags flags) | |
1931 { | |
1932 GaimConversation *conv; | |
1933 GGPInfo *info = gc->proto_data; | |
1934 GGPChat *chat = NULL; | |
1935 GList *l; | |
1936 char *msg, *plain; | |
1937 uin_t *uins; | |
1938 int count = 0; | |
1939 | |
1940 if ((conv = gaim_find_chat(gc, id)) == NULL) | |
1941 return -EINVAL; | |
1942 | |
1943 for (l = info->chats; l != NULL; l = l->next) { | |
1944 chat = l->data; | |
1945 | |
1946 if (g_utf8_collate(chat->name, conv->name) == 0) { | |
1947 break; | |
1948 } | |
1949 | |
1950 chat = NULL; | |
1951 } | |
1952 | |
1953 if (chat == NULL) { | |
1954 gaim_debug_error("gg", | |
1955 "ggp_chat_send: Hm... that's strange. No such chat?\n"); | |
1956 return -EINVAL; | |
1957 } | |
1958 | |
1959 uins = g_new0(uin_t, g_list_length(chat->participants)); | |
1960 | |
1961 for (l = chat->participants; l != NULL; l = l->next) { | |
1962 uin_t uin = GPOINTER_TO_INT(l->data); | |
1963 | |
1964 uins[count++] = uin; | |
1965 } | |
1966 | |
1967 plain = gaim_unescape_html(message); | |
1968 msg = charset_convert(plain, "UTF-8", "CP1250"); | |
1969 g_free(plain); | |
1970 gg_send_message_confer(info->session, GG_CLASS_CHAT, count, uins, | |
1971 (unsigned char *)msg); | |
1972 g_free(msg); | |
1973 g_free(uins); | |
1974 | |
1975 serv_got_chat_in(gc, id, | |
1976 gaim_account_get_username(gaim_connection_get_account(gc)), | |
1977 0, message, time(NULL)); | |
1978 | |
1979 return 0; | |
1980 } | |
1981 /* }}} */ | |
1982 | |
1983 /* static void ggp_keepalive(GaimConnection *gc) {{{ */ | |
1984 static void ggp_keepalive(GaimConnection *gc) | |
1985 { | |
1986 GGPInfo *info = gc->proto_data; | |
1987 | |
1988 /* gaim_debug_info("gg", "Keeping connection alive....\n"); */ | |
1989 | |
1990 if (gg_ping(info->session) < 0) { | |
1991 gaim_debug_info("gg", "Not connected to the server " | |
1992 "or gg_session is not correct\n"); | |
1993 gaim_connection_error(gc, _("Not connected to the server.")); | |
1994 } | |
1995 } | |
1996 /* }}} */ | |
1997 | |
1998 /* static void ggp_register_user(GaimAccount *account) {{{ */ | |
1999 static void ggp_register_user(GaimAccount *account) | |
2000 { | |
2001 GaimConnection *gc = gaim_account_get_connection(account); | |
2002 GGPInfo *info; | |
2003 | |
2004 info = gc->proto_data = g_new0(GGPInfo, 1); | |
2005 | |
2006 ggp_token_request(gc, ggp_register_user_dialog); | |
2007 } | |
2008 /* }}} */ | |
2009 | |
2010 /* static GList *ggp_actions(GaimPlugin *plugin, gpointer context) {{{ */ | |
2011 static GList *ggp_actions(GaimPlugin *plugin, gpointer context) | |
2012 { | |
2013 GList *m = NULL; | |
2014 GaimPluginAction *act; | |
2015 | |
2016 act = gaim_plugin_action_new(_("Find buddies..."), | |
2017 ggp_find_buddies); | |
2018 m = g_list_append(m, act); | |
2019 | |
2020 m = g_list_append(m, NULL); | |
2021 | |
2022 act = gaim_plugin_action_new(_("Change password..."), | |
2023 ggp_change_passwd); | |
2024 m = g_list_append(m, act); | |
2025 | |
2026 m = g_list_append(m, NULL); | |
2027 | |
2028 act = gaim_plugin_action_new(_("Upload buddylist to Server"), | |
2029 ggp_action_buddylist_put); | |
2030 m = g_list_append(m, act); | |
2031 | |
2032 act = gaim_plugin_action_new(_("Download buddylist from Server"), | |
2033 ggp_action_buddylist_get); | |
2034 m = g_list_append(m, act); | |
2035 | |
2036 act = gaim_plugin_action_new(_("Delete buddylist from Server"), | |
2037 ggp_action_buddylist_delete); | |
2038 m = g_list_append(m, act); | |
2039 | |
2040 act = gaim_plugin_action_new(_("Save buddylist to file..."), | |
2041 ggp_action_buddylist_save); | |
2042 m = g_list_append(m, act); | |
2043 | |
2044 act = gaim_plugin_action_new(_("Load buddylist from file..."), | |
2045 ggp_action_buddylist_load); | |
2046 m = g_list_append(m, act); | |
2047 | |
2048 return m; | |
2049 } | |
2050 /* }}} */ | |
2051 | |
2052 /* static gboolean ggp_offline_message(const GaimBuddy *buddy) {{{ */ | |
2053 static gboolean ggp_offline_message(const GaimBuddy *buddy) | |
2054 { | |
2055 return TRUE; | |
2056 } | |
2057 /* }}} */ | |
2058 | |
2059 /* prpl_info setup {{{ */ | |
2060 static GaimPluginProtocolInfo prpl_info = | |
2061 { | |
2062 OPT_PROTO_REGISTER_NOSCREENNAME, | |
2063 NULL, /* user_splits */ | |
2064 NULL, /* protocol_options */ | |
2065 NO_BUDDY_ICONS, /* icon_spec */ | |
2066 ggp_list_icon, /* list_icon */ | |
2067 ggp_list_emblems, /* list_emblems */ | |
2068 ggp_status_text, /* status_text */ | |
2069 ggp_tooltip_text, /* tooltip_text */ | |
2070 ggp_status_types, /* status_types */ | |
2071 ggp_blist_node_menu, /* blist_node_menu */ | |
2072 ggp_chat_info, /* chat_info */ | |
2073 NULL, /* chat_info_defaults */ | |
2074 ggp_login, /* login */ | |
2075 ggp_close, /* close */ | |
2076 ggp_send_im, /* send_im */ | |
2077 NULL, /* set_info */ | |
2078 NULL, /* send_typing */ | |
2079 ggp_get_info, /* get_info */ | |
2080 ggp_set_status, /* set_away */ | |
2081 NULL, /* set_idle */ | |
2082 NULL, /* change_passwd */ | |
2083 ggp_add_buddy, /* add_buddy */ | |
2084 NULL, /* add_buddies */ | |
2085 ggp_remove_buddy, /* remove_buddy */ | |
2086 NULL, /* remove_buddies */ | |
2087 NULL, /* add_permit */ | |
2088 NULL, /* add_deny */ | |
2089 NULL, /* rem_permit */ | |
2090 NULL, /* rem_deny */ | |
2091 NULL, /* set_permit_deny */ | |
2092 ggp_join_chat, /* join_chat */ | |
2093 NULL, /* reject_chat */ | |
2094 ggp_get_chat_name, /* get_chat_name */ | |
2095 NULL, /* chat_invite */ | |
2096 NULL, /* chat_leave */ | |
2097 NULL, /* chat_whisper */ | |
2098 ggp_chat_send, /* chat_send */ | |
2099 ggp_keepalive, /* keepalive */ | |
2100 ggp_register_user, /* register_user */ | |
2101 NULL, /* get_cb_info */ | |
2102 NULL, /* get_cb_away */ | |
2103 NULL, /* alias_buddy */ | |
2104 NULL, /* group_buddy */ | |
2105 NULL, /* rename_group */ | |
2106 NULL, /* buddy_free */ | |
2107 NULL, /* convo_closed */ | |
2108 NULL, /* normalize */ | |
2109 NULL, /* set_buddy_icon */ | |
2110 NULL, /* remove_group */ | |
2111 NULL, /* get_cb_real_name */ | |
2112 NULL, /* set_chat_topic */ | |
2113 NULL, /* find_blist_chat */ | |
2114 NULL, /* roomlist_get_list */ | |
2115 NULL, /* roomlist_cancel */ | |
2116 NULL, /* roomlist_expand_category */ | |
2117 NULL, /* can_receive_file */ | |
2118 NULL, /* send_file */ | |
2119 NULL, /* new_xfer */ | |
2120 ggp_offline_message, /* offline_message */ | |
2121 NULL, /* whiteboard_prpl_ops */ | |
14542 | 2122 NULL, /* send_raw */ |
15124 | 2123 NULL, /* roomlist_room_serialize */ |
14192 | 2124 }; |
2125 /* }}} */ | |
2126 | |
2127 /* GaimPluginInfo setup {{{ */ | |
2128 static GaimPluginInfo info = { | |
2129 GAIM_PLUGIN_MAGIC, /* magic */ | |
2130 GAIM_MAJOR_VERSION, /* major_version */ | |
2131 GAIM_MINOR_VERSION, /* minor_version */ | |
2132 GAIM_PLUGIN_PROTOCOL, /* plugin type */ | |
2133 NULL, /* ui_requirement */ | |
2134 0, /* flags */ | |
2135 NULL, /* dependencies */ | |
2136 GAIM_PRIORITY_DEFAULT, /* priority */ | |
2137 | |
2138 "prpl-gg", /* id */ | |
2139 "Gadu-Gadu", /* name */ | |
2140 VERSION, /* version */ | |
2141 | |
2142 N_("Gadu-Gadu Protocol Plugin"), /* summary */ | |
2143 N_("Polish popular IM"), /* description */ | |
2144 "boler@sourceforge.net", /* author */ | |
2145 GAIM_WEBSITE, /* homepage */ | |
2146 | |
2147 NULL, /* load */ | |
2148 NULL, /* unload */ | |
2149 NULL, /* destroy */ | |
2150 | |
2151 NULL, /* ui_info */ | |
2152 &prpl_info, /* extra_info */ | |
2153 NULL, /* prefs_info */ | |
2154 ggp_actions /* actions */ | |
2155 }; | |
2156 /* }}} */ | |
2157 | |
2158 /* static void gaim_gg_debug_handler(int level, const char * format, va_list args) {{{ */ | |
2159 static void gaim_gg_debug_handler(int level, const char * format, va_list args) { | |
2160 GaimDebugLevel gaim_level; | |
2161 char *msg = g_strdup_vprintf(format, args); | |
2162 | |
2163 /* This is pretty pointless since the GG_DEBUG levels don't correspond to | |
2164 * the gaim ones */ | |
2165 switch (level) { | |
2166 case GG_DEBUG_FUNCTION: | |
2167 gaim_level = GAIM_DEBUG_INFO; | |
2168 break; | |
2169 case GG_DEBUG_MISC: | |
2170 case GG_DEBUG_NET: | |
2171 case GG_DEBUG_DUMP: | |
2172 case GG_DEBUG_TRAFFIC: | |
2173 default: | |
2174 gaim_level = GAIM_DEBUG_MISC; | |
2175 break; | |
2176 } | |
2177 | |
2178 gaim_debug(gaim_level, "gg", msg); | |
2179 g_free(msg); | |
2180 } | |
2181 /* }}} */ | |
2182 | |
2183 /* | |
2184 */ | |
2185 /* static void init_plugin(GaimPlugin *plugin) {{{ */ | |
2186 static void init_plugin(GaimPlugin *plugin) | |
2187 { | |
2188 GaimAccountOption *option; | |
2189 | |
2190 option = gaim_account_option_string_new(_("Nickname"), | |
2191 "nick", _("Gadu-Gadu User")); | |
2192 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, | |
2193 option); | |
2194 | |
2195 my_protocol = plugin; | |
2196 | |
2197 gg_debug_handler = gaim_gg_debug_handler; | |
2198 } | |
2199 /* }}} */ | |
2200 | |
2201 GAIM_INIT_PLUGIN(gg, init_plugin, info); | |
2202 | |
2203 /* vim: set ts=8 sts=0 sw=8 noet: */ |