Mercurial > pidgin.yaz
comparison src/protocols/gg/gg.c @ 2846:4b3f17ca66bf
[gaim-migrate @ 2859]
so here it comes - some bugs fixed, new ones introduced:
- password changing (was in part 1)
- update to latest libgg (fixes password change on alpha)
- auto away on idle (remembers GG_STATE_FRIENDS_MASK)
- handle_errcode() can now use hide_login_progress()
- remove encode_postdata() and use gg_urlencode() from libgg
+ encode only fields (not whole url)
- fixed status related ugly bug in GG_EVENT_NOTIFY (!!!)
- remove linefeed from messages
Thanks, Arkadiusz Miskiewicz
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Wed, 05 Dec 2001 09:48:56 +0000 |
parents | d8e67ff8022f |
children | b1e300a85678 |
comparison
equal
deleted
inserted
replaced
2845:0c10058610a0 | 2846:4b3f17ca66bf |
---|---|
1 /* | 1 /* |
2 * gaim - Gadu-Gadu Protocol Plugin | 2 * gaim - Gadu-Gadu Protocol Plugin |
3 * $Id: gg.c 2848 2001-12-02 20:42:30Z warmenhoven $ | 3 * $Id: gg.c 2859 2001-12-05 09:48:56Z warmenhoven $ |
4 * | 4 * |
5 * Copyright (C) 2001 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL> | 5 * Copyright (C) 2001 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL> |
6 * | 6 * |
7 * This program is free software; you can redistribute it and/or modify | 7 * This program is free software; you can redistribute it and/or modify |
8 * it under the terms of the GNU General Public License as published by | 8 * it under the terms of the GNU General Public License as published by |
63 #define AGG_GENDER_NONE -1 | 63 #define AGG_GENDER_NONE -1 |
64 | 64 |
65 #define AGG_PUBDIR_USERLIST_EXPORT_FORM "/appsvc/fmcontactsput.asp" | 65 #define AGG_PUBDIR_USERLIST_EXPORT_FORM "/appsvc/fmcontactsput.asp" |
66 #define AGG_PUBDIR_USERLIST_IMPORT_FORM "/appsvc/fmcontactsget.asp" | 66 #define AGG_PUBDIR_USERLIST_IMPORT_FORM "/appsvc/fmcontactsget.asp" |
67 #define AGG_PUBDIR_SEARCH_FORM "/appsvc/fmpubquery2.asp" | 67 #define AGG_PUBDIR_SEARCH_FORM "/appsvc/fmpubquery2.asp" |
68 #define AGG_REGISTER_DATA_FORM "/appsvc/fmregister.asp" | |
68 #define AGG_PUBDIR_MAX_ENTRIES 200 | 69 #define AGG_PUBDIR_MAX_ENTRIES 200 |
69 | 70 |
70 #define AGG_STATUS_AVAIL _("Available") | 71 #define AGG_STATUS_AVAIL _("Available") |
71 #define AGG_STATUS_AVAIL_FRIENDS _("Available for friends only") | 72 #define AGG_STATUS_AVAIL_FRIENDS _("Available for friends only") |
72 #define AGG_STATUS_BUSY _("Away") | 73 #define AGG_STATUS_BUSY _("Away") |
78 #define AGG_HTTP_NONE 0 | 79 #define AGG_HTTP_NONE 0 |
79 #define AGG_HTTP_SEARCH 1 | 80 #define AGG_HTTP_SEARCH 1 |
80 #define AGG_HTTP_USERLIST_IMPORT 2 | 81 #define AGG_HTTP_USERLIST_IMPORT 2 |
81 #define AGG_HTTP_USERLIST_EXPORT 3 | 82 #define AGG_HTTP_USERLIST_EXPORT 3 |
82 #define AGG_HTTP_USERLIST_DELETE 4 | 83 #define AGG_HTTP_USERLIST_DELETE 4 |
84 #define AGG_HTTP_PASSWORD_CHANGE 5 | |
83 | 85 |
84 #define UC_NORMAL 2 | 86 #define UC_NORMAL 2 |
85 | 87 |
86 struct agg_data { | 88 struct agg_data { |
87 struct gg_session *sess; | 89 struct gg_session *sess; |
90 int own_status; | |
88 }; | 91 }; |
89 | 92 |
90 struct agg_http { | 93 struct agg_http { |
91 struct gaim_connection *gc; | 94 struct gaim_connection *gc; |
92 gchar *request; | 95 gchar *request; |
168 #endif | 171 #endif |
169 } | 172 } |
170 return gg_localenc; | 173 return gg_localenc; |
171 } | 174 } |
172 | 175 |
173 static char *handle_errcode(int errcode, gboolean show) | 176 static char *handle_errcode(struct gaim_connection *gc, int errcode) |
174 { | 177 { |
175 static char msg[AGG_BUF_LEN]; | 178 static char msg[AGG_BUF_LEN]; |
176 | 179 |
177 switch (errcode) { | 180 switch (errcode) { |
178 case GG_FAILURE_RESOLVING: | 181 case GG_FAILURE_RESOLVING: |
196 default: | 199 default: |
197 g_snprintf(msg, sizeof(msg), _("Unknown Error Code.")); | 200 g_snprintf(msg, sizeof(msg), _("Unknown Error Code.")); |
198 break; | 201 break; |
199 } | 202 } |
200 | 203 |
201 if (show) | 204 hide_login_progress(gc, msg); |
202 do_error_dialog(msg, _("Gadu-Gadu Error")); | |
203 | 205 |
204 return msg; | 206 return msg; |
205 } | 207 } |
206 | 208 |
207 static gchar *encode_postdata(const gchar *data) | |
208 { | |
209 gchar *p = NULL; | |
210 int i, j = 0; | |
211 for (i = 0; i < strlen(data); i++) { | |
212 /* locale insensitive, doesn't reflect RFC (1738 section 2.2, 1866 section 8.2.1) */ | |
213 if ((data[i] >= 'a' && data[i] <= 'z') | |
214 || (data[i] >= 'A' && data[i] <= 'Z') | |
215 || (data[i] >= '0' && data[i] <= '9') | |
216 || data[i] == '=' || data[i] == '&') { | |
217 p = g_realloc(p, j + 1); | |
218 p[j] = data[i]; | |
219 j++; | |
220 } else { | |
221 p = g_realloc(p, j + 4); /* remember, sprintf appends a '\0' */ | |
222 sprintf(p + j, "%%%02x", (unsigned char)data[i]); | |
223 j += 3; | |
224 } | |
225 } | |
226 p = g_realloc(p, j + 1); | |
227 p[j] = '\0'; | |
228 | |
229 if (p && strlen(p)) | |
230 return p; | |
231 else | |
232 return g_strdup(data); | |
233 } | |
234 | |
235 static void agg_set_away(struct gaim_connection *gc, char *state, char *msg) | 209 static void agg_set_away(struct gaim_connection *gc, char *state, char *msg) |
236 { | 210 { |
237 struct agg_data *gd = (struct agg_data *)gc->proto_data; | 211 struct agg_data *gd = (struct agg_data *)gc->proto_data; |
212 int status = gd->own_status; | |
238 | 213 |
239 if (gc->away) | 214 if (gc->away) |
240 gc->away = NULL; | 215 gc->away = NULL; |
241 | 216 |
242 if (!g_strcasecmp(state, AGG_STATUS_AVAIL)) | 217 if (!g_strcasecmp(state, AGG_STATUS_AVAIL)) |
243 gg_change_status(gd->sess, GG_STATUS_AVAIL); | 218 status = GG_STATUS_AVAIL; |
244 else if (!g_strcasecmp(state, AGG_STATUS_AVAIL_FRIENDS)) | 219 else if (!g_strcasecmp(state, AGG_STATUS_AVAIL_FRIENDS)) |
245 gg_change_status(gd->sess, GG_STATUS_AVAIL | GG_STATUS_FRIENDS_MASK); | 220 status = GG_STATUS_AVAIL | GG_STATUS_FRIENDS_MASK; |
246 else if (!g_strcasecmp(state, AGG_STATUS_BUSY)) { | 221 else if (!g_strcasecmp(state, AGG_STATUS_BUSY)) { |
247 gg_change_status(gd->sess, GG_STATUS_BUSY); | 222 status = GG_STATUS_BUSY; |
248 gc->away = ""; | 223 gc->away = ""; |
249 } else if (!g_strcasecmp(state, AGG_STATUS_BUSY_FRIENDS)) { | 224 } else if (!g_strcasecmp(state, AGG_STATUS_BUSY_FRIENDS)) { |
250 gg_change_status(gd->sess, GG_STATUS_BUSY | GG_STATUS_FRIENDS_MASK); | 225 status = GG_STATUS_BUSY | GG_STATUS_FRIENDS_MASK; |
251 gc->away = ""; | 226 gc->away = ""; |
252 } else if (!g_strcasecmp(state, AGG_STATUS_INVISIBLE)) { | 227 } else if (!g_strcasecmp(state, AGG_STATUS_INVISIBLE)) { |
253 gg_change_status(gd->sess, GG_STATUS_INVISIBLE); | 228 status = GG_STATUS_INVISIBLE; |
254 gc->away = ""; | 229 gc->away = ""; |
255 } else if (!g_strcasecmp(state, AGG_STATUS_INVISIBLE_FRIENDS)) { | 230 } else if (!g_strcasecmp(state, AGG_STATUS_INVISIBLE_FRIENDS)) { |
256 gg_change_status(gd->sess, GG_STATUS_INVISIBLE | GG_STATUS_FRIENDS_MASK); | 231 status = GG_STATUS_INVISIBLE | GG_STATUS_FRIENDS_MASK; |
257 gc->away = ""; | 232 gc->away = ""; |
258 } else if (!g_strcasecmp(state, AGG_STATUS_NOT_AVAIL)) { | 233 } else if (!g_strcasecmp(state, AGG_STATUS_NOT_AVAIL)) { |
259 gg_change_status(gd->sess, GG_STATUS_NOT_AVAIL); | 234 status = GG_STATUS_NOT_AVAIL; |
260 gc->away = ""; | 235 gc->away = ""; |
261 } else if (!g_strcasecmp(state, GAIM_AWAY_CUSTOM)) { | 236 } else if (!g_strcasecmp(state, GAIM_AWAY_CUSTOM)) { |
262 if (msg) { | 237 if (msg) { |
263 gg_change_status(gd->sess, GG_STATUS_BUSY); | 238 status = GG_STATUS_BUSY; |
264 gc->away = ""; | 239 gc->away = ""; |
265 } else | 240 } else |
266 gg_change_status(gd->sess, GG_STATUS_AVAIL); | 241 status = GG_STATUS_AVAIL; |
267 } | 242 |
243 if (gd->own_status & GG_STATUS_FRIENDS_MASK) | |
244 status |= GG_STATUS_FRIENDS_MASK; | |
245 } | |
246 | |
247 gd->own_status = status; | |
248 gg_change_status(gd->sess, status); | |
268 } | 249 } |
269 | 250 |
270 static gchar *get_away_text(int uc) | 251 static gchar *get_away_text(int uc) |
271 { | 252 { |
272 if (uc == UC_UNAVAILABLE) | 253 if (uc == UC_UNAVAILABLE) |
357 return; | 338 return; |
358 } | 339 } |
359 | 340 |
360 if (!(e = gg_watch_fd(gd->sess))) { | 341 if (!(e = gg_watch_fd(gd->sess))) { |
361 debug_printf("main_callback: gg_watch_fd failed - CRITICAL!\n"); | 342 debug_printf("main_callback: gg_watch_fd failed - CRITICAL!\n"); |
343 hide_login_progress(gc, _("Unable to read socket")); | |
362 signoff(gc); | 344 signoff(gc); |
363 return; | 345 return; |
364 } | 346 } |
365 | 347 |
366 switch (e->type) { | 348 switch (e->type) { |
371 debug_printf("main_callback: CONNECTED AGAIN!?\n"); | 353 debug_printf("main_callback: CONNECTED AGAIN!?\n"); |
372 break; | 354 break; |
373 case GG_EVENT_CONN_FAILED: | 355 case GG_EVENT_CONN_FAILED: |
374 if (gc->inpa) | 356 if (gc->inpa) |
375 gaim_input_remove(gc->inpa); | 357 gaim_input_remove(gc->inpa); |
376 handle_errcode(e->event.failure, TRUE); | 358 handle_errcode(gc, e->event.failure); |
377 signoff(gc); | 359 signoff(gc); |
378 break; | 360 break; |
379 case GG_EVENT_MSG: | 361 case GG_EVENT_MSG: |
380 { | 362 { |
381 gchar *imsg; | 363 gchar *imsg; |
383 | 365 |
384 g_snprintf(user, sizeof(user), "%lu", e->event.msg.sender); | 366 g_snprintf(user, sizeof(user), "%lu", e->event.msg.sender); |
385 if (!allowed_uin(gc, user)) | 367 if (!allowed_uin(gc, user)) |
386 break; | 368 break; |
387 imsg = charset_convert(e->event.msg.message, "CP1250", find_local_charset()); | 369 imsg = charset_convert(e->event.msg.message, "CP1250", find_local_charset()); |
370 strip_linefeed(imsg); | |
388 /* e->event.msg.time - we don't know what this time is for */ | 371 /* e->event.msg.time - we don't know what this time is for */ |
389 serv_got_im(gc, user, imsg, 0, time((time_t) NULL)); | 372 serv_got_im(gc, user, imsg, 0, time((time_t) NULL)); |
390 g_free(imsg); | 373 g_free(imsg); |
391 } | 374 } |
392 break; | 375 break; |
402 status = UC_UNAVAILABLE; | 385 status = UC_UNAVAILABLE; |
403 break; | 386 break; |
404 case GG_STATUS_AVAIL: | 387 case GG_STATUS_AVAIL: |
405 case GG_STATUS_BUSY: | 388 case GG_STATUS_BUSY: |
406 case GG_STATUS_INVISIBLE: | 389 case GG_STATUS_INVISIBLE: |
407 case GG_STATUS_FRIENDS_MASK: | 390 status = UC_NORMAL | (n->status << 5); |
408 status = UC_NORMAL | (e->event.status.status << 5); | |
409 break; | 391 break; |
410 default: | 392 default: |
411 status = UC_NORMAL; | 393 status = UC_NORMAL; |
412 break; | 394 break; |
413 } | 395 } |
429 status = UC_UNAVAILABLE; | 411 status = UC_UNAVAILABLE; |
430 break; | 412 break; |
431 case GG_STATUS_AVAIL: | 413 case GG_STATUS_AVAIL: |
432 case GG_STATUS_BUSY: | 414 case GG_STATUS_BUSY: |
433 case GG_STATUS_INVISIBLE: | 415 case GG_STATUS_INVISIBLE: |
434 case GG_STATUS_FRIENDS_MASK: | |
435 status = UC_NORMAL | (e->event.status.status << 5); | 416 status = UC_NORMAL | (e->event.status.status << 5); |
436 break; | 417 break; |
437 default: | 418 default: |
438 status = UC_NORMAL; | 419 status = UC_NORMAL; |
439 break; | 420 break; |
440 } | 421 } |
441 | 422 |
442 g_snprintf(user, sizeof(user), "%lu", e->event.status.uin); | 423 g_snprintf(user, sizeof(user), "%lu", e->event.status.uin); |
443 serv_got_update(gc, user, (status == UC_UNAVAILABLE) ? 0 : 1, 0, 0, 0, status, | 424 serv_got_update(gc, user, (status == UC_UNAVAILABLE) ? 0 : 1, 0, 0, 0, |
444 0); | 425 status, 0); |
445 } | 426 } |
446 break; | 427 break; |
447 case GG_EVENT_ACK: | 428 case GG_EVENT_ACK: |
448 debug_printf("main_callback: message %d to %u sent with status %d\n", | 429 debug_printf("main_callback: message %d to %u sent with status %d\n", |
449 e->event.ack.seq, e->event.ack.recipient, e->event.ack.status); | 430 e->event.ack.seq, e->event.ack.recipient, e->event.ack.status); |
477 | 458 |
478 if (gc->inpa == 0) | 459 if (gc->inpa == 0) |
479 gc->inpa = gaim_input_add(gd->sess->fd, GAIM_INPUT_READ, login_callback, gc); | 460 gc->inpa = gaim_input_add(gd->sess->fd, GAIM_INPUT_READ, login_callback, gc); |
480 | 461 |
481 switch (gd->sess->state) { | 462 switch (gd->sess->state) { |
482 case GG_STATE_CONNECTING_HTTP: | 463 case GG_STATE_READING_DATA: |
483 case GG_STATE_WRITING_HTTP: | 464 set_login_progress(gc, 2, _("Reading data")); |
484 set_login_progress(gc, 2, _("Handshake")); | |
485 break; | 465 break; |
486 case GG_STATE_CONNECTING_GG: | 466 case GG_STATE_CONNECTING_GG: |
487 set_login_progress(gc, 3, _("Connecting to GG server")); | 467 set_login_progress(gc, 3, _("Balancer handshake")); |
488 break; | 468 break; |
489 case GG_STATE_WAITING_FOR_KEY: | 469 case GG_STATE_READING_KEY: |
490 set_login_progress(gc, 4, _("Waiting for server key")); | 470 set_login_progress(gc, 4, _("Reading server key")); |
491 break; | 471 break; |
492 case GG_STATE_SENDING_KEY: | 472 case GG_STATE_READING_REPLY: |
493 set_login_progress(gc, 5, _("Sending key")); | 473 set_login_progress(gc, 5, _("Exchanging key hash")); |
494 break; | 474 break; |
495 default: | 475 default: |
496 break; | 476 break; |
497 } | 477 } |
498 | 478 |
499 if (!(e = gg_watch_fd(gd->sess))) { | 479 if (!(e = gg_watch_fd(gd->sess))) { |
500 debug_printf("login_callback: gg_watch_fd failed - CRITICAL!\n"); | 480 debug_printf("login_callback: gg_watch_fd failed - CRITICAL!\n"); |
481 hide_login_progress(gc, _("Critical error in GG library\n")); | |
501 signoff(gc); | 482 signoff(gc); |
502 return; | 483 return; |
503 } | 484 } |
504 | 485 |
505 switch (e->type) { | 486 switch (e->type) { |
520 do_import(gc, NULL); | 501 do_import(gc, NULL); |
521 break; | 502 break; |
522 case GG_EVENT_CONN_FAILED: | 503 case GG_EVENT_CONN_FAILED: |
523 gaim_input_remove(gc->inpa); | 504 gaim_input_remove(gc->inpa); |
524 gc->inpa = 0; | 505 gc->inpa = 0; |
525 handle_errcode(e->event.failure, TRUE); | 506 handle_errcode(gc, e->event.failure); |
526 signoff(gc); | 507 signoff(gc); |
527 break; | 508 break; |
528 default: | 509 default: |
529 break; | 510 break; |
530 } | 511 } |
534 | 515 |
535 static void agg_keepalive(struct gaim_connection *gc) | 516 static void agg_keepalive(struct gaim_connection *gc) |
536 { | 517 { |
537 struct agg_data *gd = (struct agg_data *)gc->proto_data; | 518 struct agg_data *gd = (struct agg_data *)gc->proto_data; |
538 if (gg_ping(gd->sess) < 0) { | 519 if (gg_ping(gd->sess) < 0) { |
520 hide_login_progress(gc, _("Unable to ping server")); | |
539 signoff(gc); | 521 signoff(gc); |
540 return; | 522 return; |
541 } | 523 } |
542 } | 524 } |
543 | 525 |
576 gg_login() sucks for me, so I'm using proxy_connect() | 558 gg_login() sucks for me, so I'm using proxy_connect() |
577 */ | 559 */ |
578 | 560 |
579 gd->sess->uin = (uin_t) strtol(user->username, (char **)NULL, 10); | 561 gd->sess->uin = (uin_t) strtol(user->username, (char **)NULL, 10); |
580 gd->sess->password = g_strdup(user->password); | 562 gd->sess->password = g_strdup(user->password); |
581 gd->sess->state = GG_STATE_CONNECTING_HTTP; | 563 gd->sess->state = GG_STATE_CONNECTING; |
582 gd->sess->check = GG_CHECK_WRITE; | 564 gd->sess->check = GG_CHECK_WRITE; |
583 gd->sess->async = 1; | 565 gd->sess->async = 1; |
584 gd->sess->fd = proxy_connect(GG_APPMSG_HOST, GG_APPMSG_PORT, login_callback, gc); | 566 gd->sess->fd = proxy_connect(GG_APPMSG_HOST, GG_APPMSG_PORT, login_callback, gc); |
585 | 567 |
586 if (gd->sess->fd < 0) { | 568 if (gd->sess->fd < 0) { |
597 if (gc->inpa) | 579 if (gc->inpa) |
598 gaim_input_remove(gc->inpa); | 580 gaim_input_remove(gc->inpa); |
599 gg_logoff(gd->sess); | 581 gg_logoff(gd->sess); |
600 gg_free_session(gd->sess); | 582 gg_free_session(gd->sess); |
601 g_free(gc->proto_data); | 583 g_free(gc->proto_data); |
584 gd->own_status = GG_STATUS_NOT_AVAIL; | |
602 } | 585 } |
603 | 586 |
604 static int agg_send_im(struct gaim_connection *gc, char *who, char *msg, int flags) | 587 static int agg_send_im(struct gaim_connection *gc, char *who, char *msg, int flags) |
605 { | 588 { |
606 struct agg_data *gd = (struct agg_data *)gc->proto_data; | 589 struct agg_data *gd = (struct agg_data *)gc->proto_data; |
612 return -1; | 595 return -1; |
613 } | 596 } |
614 | 597 |
615 if (strlen(msg) > 0) { | 598 if (strlen(msg) > 0) { |
616 imsg = charset_convert(msg, find_local_charset(), "CP1250"); | 599 imsg = charset_convert(msg, find_local_charset(), "CP1250"); |
617 if (gg_send_message(gd->sess, (flags & IM_FLAG_CHECKBOX) ? GG_CLASS_MSG : GG_CLASS_CHAT, | 600 if (gg_send_message(gd->sess, (flags & IM_FLAG_CHECKBOX) |
601 ? GG_CLASS_MSG : GG_CLASS_CHAT, | |
618 strtol(who, (char **)NULL, 10), imsg) < 0) | 602 strtol(who, (char **)NULL, 10), imsg) < 0) |
619 return -1; | 603 return -1; |
620 g_free(imsg); | 604 g_free(imsg); |
621 } | 605 } |
622 return 1; | 606 return 1; |
846 | 830 |
847 debug_printf("delete_buddies_server_results: webdata [%s]\n", webdata); | 831 debug_printf("delete_buddies_server_results: webdata [%s]\n", webdata); |
848 do_error_dialog(_("Couldn't delete Buddies List from Server"), _("Gadu-Gadu Error")); | 832 do_error_dialog(_("Couldn't delete Buddies List from Server"), _("Gadu-Gadu Error")); |
849 } | 833 } |
850 | 834 |
835 static void password_change_server_results(struct gaim_connection *gc, gchar *webdata) | |
836 { | |
837 if (strstr(webdata, "reg_success:")) { | |
838 do_error_dialog(_("Password changed sucessfully"), | |
839 _("Gadu-Gadu Information")); | |
840 return; | |
841 } | |
842 | |
843 debug_printf("delete_buddies_server_results: webdata [%s]\n", webdata); | |
844 do_error_dialog(_("Password couldn't be changed"), _("Gadu-Gadu Error")); | |
845 } | |
846 | |
851 static void http_results(gpointer data, gint source, GaimInputCondition cond) | 847 static void http_results(gpointer data, gint source, GaimInputCondition cond) |
852 { | 848 { |
853 struct agg_http *hdata = data; | 849 struct agg_http *hdata = data; |
854 struct gaim_connection *gc = hdata->gc; | 850 struct gaim_connection *gc = hdata->gc; |
855 char *webdata; | 851 char *webdata; |
902 export_buddies_server_results(gc, webdata); | 898 export_buddies_server_results(gc, webdata); |
903 break; | 899 break; |
904 case AGG_HTTP_USERLIST_DELETE: | 900 case AGG_HTTP_USERLIST_DELETE: |
905 delete_buddies_server_results(gc, webdata); | 901 delete_buddies_server_results(gc, webdata); |
906 break; | 902 break; |
903 case AGG_HTTP_PASSWORD_CHANGE: | |
904 password_change_server_results(gc, webdata); | |
905 break; | |
907 case AGG_HTTP_NONE: | 906 case AGG_HTTP_NONE: |
908 default: | 907 default: |
909 debug_printf("http_results: unsupported type %d\n", hdata->type); | 908 debug_printf("http_results: unsupported type %d\n", hdata->type); |
910 break; | 909 break; |
911 } | 910 } |
918 { | 917 { |
919 struct agg_http *hdata = data; | 918 struct agg_http *hdata = data; |
920 struct gaim_connection *gc = hdata->gc; | 919 struct gaim_connection *gc = hdata->gc; |
921 gchar *request = hdata->request; | 920 gchar *request = hdata->request; |
922 gchar *buf; | 921 gchar *buf; |
923 char *ptr; | |
924 | 922 |
925 debug_printf("http_req_callback: begin\n"); | 923 debug_printf("http_req_callback: begin\n"); |
926 | 924 |
927 if (!g_slist_find(connections, gc)) { | 925 if (!g_slist_find(connections, gc)) { |
928 debug_printf("http_req_callback: g_slist_find error\n"); | 926 debug_printf("http_req_callback: g_slist_find error\n"); |
936 g_free(request); | 934 g_free(request); |
937 g_free(hdata); | 935 g_free(hdata); |
938 return; | 936 return; |
939 } | 937 } |
940 | 938 |
941 ptr = encode_postdata(request); | 939 debug_printf("http_req_callback: http request [%s]\n", request); |
942 g_free(request); | |
943 | |
944 debug_printf("http_req_callback: http request [%s]\n", ptr); | |
945 | 940 |
946 buf = g_strdup_printf("POST %s HTTP/1.0\r\n" | 941 buf = g_strdup_printf("POST %s HTTP/1.0\r\n" |
947 "Host: %s\r\n" | 942 "Host: %s\r\n" |
948 "Content-Type: application/x-www-form-urlencoded\r\n" | 943 "Content-Type: application/x-www-form-urlencoded\r\n" |
949 "User-Agent: " GG_HTTP_USERAGENT "\r\n" | 944 "User-Agent: " GG_HTTP_USERAGENT "\r\n" |
950 "Content-Length: %d\r\n" | 945 "Content-Length: %d\r\n" |
951 "Pragma: no-cache\r\n" "\r\n" "%s\r\n", | 946 "Pragma: no-cache\r\n" "\r\n" "%s\r\n", |
952 hdata->form, hdata->host, strlen(ptr), ptr); | 947 hdata->form, hdata->host, strlen(request), request); |
953 | 948 |
954 g_free(ptr); | 949 g_free(request); |
955 | 950 |
956 if (write(source, buf, strlen(buf)) < strlen(buf)) { | 951 if (write(source, buf, strlen(buf)) < strlen(buf)) { |
957 g_free(buf); | 952 g_free(buf); |
958 g_free(hdata); | 953 g_free(hdata); |
959 close(source); | 954 close(source); |
968 | 963 |
969 static void import_buddies_server(struct gaim_connection *gc) | 964 static void import_buddies_server(struct gaim_connection *gc) |
970 { | 965 { |
971 struct agg_http *hi = g_new0(struct agg_http, 1); | 966 struct agg_http *hi = g_new0(struct agg_http, 1); |
972 static char msg[AGG_BUF_LEN]; | 967 static char msg[AGG_BUF_LEN]; |
968 gchar *u = gg_urlencode(gc->username); | |
969 gchar *p = gg_urlencode(gc->password); | |
973 | 970 |
974 hi->gc = gc; | 971 hi->gc = gc; |
975 hi->type = AGG_HTTP_USERLIST_IMPORT; | 972 hi->type = AGG_HTTP_USERLIST_IMPORT; |
976 hi->form = AGG_PUBDIR_USERLIST_IMPORT_FORM; | 973 hi->form = AGG_PUBDIR_USERLIST_IMPORT_FORM; |
977 hi->host = GG_PUBDIR_HOST; | 974 hi->host = GG_PUBDIR_HOST; |
978 hi->request = g_strdup_printf("FmNum=%s&Pass=%s", gc->username, gc->password); | 975 hi->request = g_strdup_printf("FmNum=%s&Pass=%s", u, p); |
976 | |
977 g_free(u); | |
978 g_free(p); | |
979 | 979 |
980 if (proxy_connect(GG_PUBDIR_HOST, GG_PUBDIR_PORT, http_req_callback, hi) < 0) { | 980 if (proxy_connect(GG_PUBDIR_HOST, GG_PUBDIR_PORT, http_req_callback, hi) < 0) { |
981 g_snprintf(msg, sizeof(msg), _("Buddies List import from Server failed (%s)"), | 981 g_snprintf(msg, sizeof(msg), _("Buddies List import from Server failed (%s)"), |
982 GG_PUBDIR_HOST); | 982 GG_PUBDIR_HOST); |
983 do_error_dialog(msg, _("Gadu-Gadu Error")); | 983 do_error_dialog(msg, _("Gadu-Gadu Error")); |
990 static void export_buddies_server(struct gaim_connection *gc) | 990 static void export_buddies_server(struct gaim_connection *gc) |
991 { | 991 { |
992 struct agg_http *he = g_new0(struct agg_http, 1); | 992 struct agg_http *he = g_new0(struct agg_http, 1); |
993 static char msg[AGG_BUF_LEN]; | 993 static char msg[AGG_BUF_LEN]; |
994 gchar *ptr; | 994 gchar *ptr; |
995 gchar *u = gg_urlencode(gc->username); | |
996 gchar *p = gg_urlencode(gc->password); | |
997 | |
995 GSList *gr = gc->groups; | 998 GSList *gr = gc->groups; |
996 | 999 |
997 he->gc = gc; | 1000 he->gc = gc; |
998 he->type = AGG_HTTP_USERLIST_EXPORT; | 1001 he->type = AGG_HTTP_USERLIST_EXPORT; |
999 he->form = AGG_PUBDIR_USERLIST_EXPORT_FORM; | 1002 he->form = AGG_PUBDIR_USERLIST_EXPORT_FORM; |
1000 he->host = GG_PUBDIR_HOST; | 1003 he->host = GG_PUBDIR_HOST; |
1001 he->request = g_strdup_printf("FmNum=%s&Pass=%s&Contacts=", gc->username, gc->password); | 1004 he->request = g_strdup_printf("FmNum=%s&Pass=%s&Contacts=", u, p); |
1005 | |
1006 g_free(u); | |
1007 g_free(p); | |
1002 | 1008 |
1003 while (gr) { | 1009 while (gr) { |
1004 struct group *g = gr->data; | 1010 struct group *g = gr->data; |
1005 GSList *m = g->members; | 1011 GSList *m = g->members; |
1006 while (m) { | 1012 while (m) { |
1007 struct buddy *b = m->data; | 1013 struct buddy *b = m->data; |
1008 gchar *newdata; | 1014 gchar *newdata; |
1009 /* GG Number */ | 1015 /* GG Number */ |
1010 gchar *name = b->name; | 1016 gchar *name = gg_urlencode(b->name); |
1011 /* GG Pseudo */ | 1017 /* GG Pseudo */ |
1012 gchar *show = strlen(b->show) ? b->show : b->name; | 1018 gchar *show = gg_urlencode(strlen(b->show) ? b->show : b->name); |
1019 /* Group Name */ | |
1020 gchar *gname = gg_urlencode(g->name); | |
1013 | 1021 |
1014 ptr = he->request; | 1022 ptr = he->request; |
1015 newdata = g_strdup_printf("%s;%s;%s;%s;%s;%s;%s\r\n", | 1023 newdata = g_strdup_printf("%s;%s;%s;%s;%s;%s;%s\r\n", |
1016 show, show, show, show, "", g->name, name); | 1024 show, show, show, show, "", gname, name); |
1017 he->request = g_strconcat(ptr, newdata, NULL); | 1025 he->request = g_strconcat(ptr, newdata, NULL); |
1026 | |
1018 g_free(newdata); | 1027 g_free(newdata); |
1019 g_free(ptr); | 1028 g_free(ptr); |
1029 | |
1030 g_free(gname); | |
1031 g_free(show); | |
1032 g_free(name); | |
1020 | 1033 |
1021 m = g_slist_next(m); | 1034 m = g_slist_next(m); |
1022 } | 1035 } |
1023 gr = g_slist_next(gr); | 1036 gr = g_slist_next(gr); |
1024 } | 1037 } |
1035 | 1048 |
1036 static void delete_buddies_server(struct gaim_connection *gc) | 1049 static void delete_buddies_server(struct gaim_connection *gc) |
1037 { | 1050 { |
1038 struct agg_http *he = g_new0(struct agg_http, 1); | 1051 struct agg_http *he = g_new0(struct agg_http, 1); |
1039 static char msg[AGG_BUF_LEN]; | 1052 static char msg[AGG_BUF_LEN]; |
1053 gchar *u = gg_urlencode(gc->username); | |
1054 gchar *p = gg_urlencode(gc->password); | |
1040 | 1055 |
1041 he->gc = gc; | 1056 he->gc = gc; |
1042 he->type = AGG_HTTP_USERLIST_DELETE; | 1057 he->type = AGG_HTTP_USERLIST_DELETE; |
1043 he->form = AGG_PUBDIR_USERLIST_EXPORT_FORM; | 1058 he->form = AGG_PUBDIR_USERLIST_EXPORT_FORM; |
1044 he->host = GG_PUBDIR_HOST; | 1059 he->host = GG_PUBDIR_HOST; |
1045 he->request = g_strdup_printf("FmNum=%s&Pass=%s&Delete=1", gc->username, gc->password); | 1060 he->request = g_strdup_printf("FmNum=%s&Pass=%s&Delete=1", u, p); |
1046 | 1061 |
1047 if (proxy_connect(GG_PUBDIR_HOST, GG_PUBDIR_PORT, http_req_callback, he) < 0) { | 1062 if (proxy_connect(GG_PUBDIR_HOST, GG_PUBDIR_PORT, http_req_callback, he) < 0) { |
1048 g_snprintf(msg, sizeof(msg), _("Deletion of Buddies List from Server failed (%s)"), | 1063 g_snprintf(msg, sizeof(msg), _("Deletion of Buddies List from Server failed (%s)"), |
1049 GG_PUBDIR_HOST); | 1064 GG_PUBDIR_HOST); |
1050 do_error_dialog(msg, _("Gadu-Gadu Error")); | 1065 do_error_dialog(msg, _("Gadu-Gadu Error")); |
1053 return; | 1068 return; |
1054 } | 1069 } |
1055 } | 1070 } |
1056 | 1071 |
1057 static void agg_dir_search(struct gaim_connection *gc, char *first, char *middle, | 1072 static void agg_dir_search(struct gaim_connection *gc, char *first, char *middle, |
1058 char *last, char *maiden, char *city, char *state, char *country, char *email) | 1073 char *last, char *maiden, char *city, char *state, |
1074 char *country, char *email) | |
1059 { | 1075 { |
1060 struct agg_http *srch = g_new0(struct agg_http, 1); | 1076 struct agg_http *srch = g_new0(struct agg_http, 1); |
1061 static char msg[AGG_BUF_LEN]; | 1077 static char msg[AGG_BUF_LEN]; |
1062 | 1078 |
1063 srch->gc = gc; | 1079 srch->gc = gc; |
1064 srch->type = AGG_HTTP_SEARCH; | 1080 srch->type = AGG_HTTP_SEARCH; |
1065 srch->form = AGG_PUBDIR_SEARCH_FORM; | 1081 srch->form = AGG_PUBDIR_SEARCH_FORM; |
1066 srch->host = GG_PUBDIR_HOST; | 1082 srch->host = GG_PUBDIR_HOST; |
1067 | 1083 |
1068 if (email && strlen(email)) { | 1084 if (email && strlen(email)) { |
1069 srch->request = g_strdup_printf("Mode=1&Email=%s", email); | 1085 gchar *eemail = gg_urlencode(email); |
1086 srch->request = g_strdup_printf("Mode=1&Email=%s", eemail); | |
1087 g_free(eemail); | |
1070 } else { | 1088 } else { |
1071 gchar *new_first = charset_convert(first, find_local_charset(), "CP1250"); | 1089 gchar *new_first = charset_convert(first, find_local_charset(), "CP1250"); |
1072 gchar *new_last = charset_convert(last, find_local_charset(), "CP1250"); | 1090 gchar *new_last = charset_convert(last, find_local_charset(), "CP1250"); |
1073 gchar *new_city = charset_convert(city, find_local_charset(), "CP1250"); | 1091 gchar *new_city = charset_convert(city, find_local_charset(), "CP1250"); |
1074 | 1092 |
1093 gchar *enew_first = gg_urlencode(new_first); | |
1094 gchar *enew_last = gg_urlencode(new_last); | |
1095 gchar *enew_city = gg_urlencode(new_city); | |
1096 | |
1097 g_free(new_first); | |
1098 g_free(new_last); | |
1099 g_free(new_city); | |
1100 | |
1075 /* For active only add &ActiveOnly= */ | 1101 /* For active only add &ActiveOnly= */ |
1076 srch->request = g_strdup_printf("Mode=0&FirstName=%s&LastName=%s&Gender=%d" | 1102 srch->request = g_strdup_printf("Mode=0&FirstName=%s&LastName=%s&Gender=%d" |
1077 "&NickName=%s&City=%s&MinBirth=%d&MaxBirth=%d", | 1103 "&NickName=%s&City=%s&MinBirth=%d&MaxBirth=%d", |
1078 new_first, new_last, AGG_GENDER_NONE, | 1104 enew_first, enew_last, AGG_GENDER_NONE, |
1079 "", new_city, 0, 0); | 1105 "", enew_city, 0, 0); |
1080 | 1106 |
1081 g_free(new_first); | 1107 g_free(enew_first); |
1082 g_free(new_last); | 1108 g_free(enew_last); |
1083 g_free(new_city); | 1109 g_free(enew_city); |
1084 } | 1110 } |
1085 | 1111 |
1086 if (proxy_connect(GG_PUBDIR_HOST, GG_PUBDIR_PORT, http_req_callback, srch) < 0) { | 1112 if (proxy_connect(GG_PUBDIR_HOST, GG_PUBDIR_PORT, http_req_callback, srch) < 0) { |
1087 g_snprintf(msg, sizeof(msg), _("Connect to search service failed (%s)"), GG_PUBDIR_HOST); | 1113 g_snprintf(msg, sizeof(msg), _("Connect to search service failed (%s)"), |
1114 GG_PUBDIR_HOST); | |
1088 do_error_dialog(msg, _("Gadu-Gadu Error")); | 1115 do_error_dialog(msg, _("Gadu-Gadu Error")); |
1089 g_free(srch->request); | 1116 g_free(srch->request); |
1090 g_free(srch); | 1117 g_free(srch); |
1091 return; | 1118 return; |
1092 } | 1119 } |
1093 } | 1120 } |
1094 | 1121 |
1122 static void agg_change_passwd(struct gaim_connection *gc, char *old, char *new) | |
1123 { | |
1124 struct agg_http *hpass = g_new0(struct agg_http, 1); | |
1125 static char msg[AGG_BUF_LEN]; | |
1126 gchar *u = gg_urlencode(gc->username); | |
1127 gchar *p = gg_urlencode(gc->password); | |
1128 gchar *enew = gg_urlencode(new); | |
1129 gchar *eold = gg_urlencode(old); | |
1130 | |
1131 hpass->gc = gc; | |
1132 hpass->type = AGG_HTTP_PASSWORD_CHANGE; | |
1133 hpass->form = AGG_REGISTER_DATA_FORM; | |
1134 hpass->host = GG_REGISTER_HOST; | |
1135 | |
1136 /* We are using old password as place for email - it's ugly */ | |
1137 hpass->request = g_strdup_printf("fmnumber=%s&fmpwd=%s&pwd=%s&email=%s&code=%u", | |
1138 u, p, enew, eold, gg_http_hash(old, new)); | |
1139 | |
1140 g_free(u); | |
1141 g_free(p); | |
1142 g_free(enew); | |
1143 g_free(eold); | |
1144 | |
1145 if (proxy_connect(GG_REGISTER_HOST, GG_REGISTER_PORT, http_req_callback, hpass) < 0) { | |
1146 g_snprintf(msg, sizeof(msg), _("Changing Password failed (%s)"), | |
1147 GG_REGISTER_HOST); | |
1148 do_error_dialog(msg, _("Gadu-Gadu Error")); | |
1149 g_free(hpass->request); | |
1150 g_free(hpass); | |
1151 return; | |
1152 } | |
1153 } | |
1154 | |
1095 static void agg_do_action(struct gaim_connection *gc, char *action) | 1155 static void agg_do_action(struct gaim_connection *gc, char *action) |
1096 { | 1156 { |
1097 if (!strcmp(action, _("Directory Search"))) { | 1157 if (!strcmp(action, _("Directory Search"))) { |
1098 show_find_info(gc); | 1158 show_find_info(gc); |
1159 } else if (!strcmp(action, _("Change Password"))) { | |
1160 show_change_passwd(gc); | |
1099 } else if (!strcmp(action, _("Import Buddies List from Server"))) { | 1161 } else if (!strcmp(action, _("Import Buddies List from Server"))) { |
1100 import_buddies_server(gc); | 1162 import_buddies_server(gc); |
1101 } else if (!strcmp(action, _("Export Buddies List to Server"))) { | 1163 } else if (!strcmp(action, _("Export Buddies List to Server"))) { |
1102 export_buddies_server(gc); | 1164 export_buddies_server(gc); |
1103 } else if (!strcmp(action, _("Delete Buddies List from Server"))) { | 1165 } else if (!strcmp(action, _("Delete Buddies List from Server"))) { |
1108 static GList *agg_actions() | 1170 static GList *agg_actions() |
1109 { | 1171 { |
1110 GList *m = NULL; | 1172 GList *m = NULL; |
1111 | 1173 |
1112 m = g_list_append(m, _("Directory Search")); | 1174 m = g_list_append(m, _("Directory Search")); |
1175 m = g_list_append(m, NULL); | |
1176 m = g_list_append(m, _("Change Password")); | |
1177 m = g_list_append(m, NULL); | |
1113 m = g_list_append(m, _("Import Buddies List from Server")); | 1178 m = g_list_append(m, _("Import Buddies List from Server")); |
1114 m = g_list_append(m, _("Export Buddies List to Server")); | 1179 m = g_list_append(m, _("Export Buddies List to Server")); |
1115 m = g_list_append(m, _("Delete Buddies List from Server")); | 1180 m = g_list_append(m, _("Delete Buddies List from Server")); |
1116 | 1181 |
1117 return m; | 1182 return m; |
1128 srch->host = GG_PUBDIR_HOST; | 1193 srch->host = GG_PUBDIR_HOST; |
1129 | 1194 |
1130 /* If it's invalid uin then maybe it's nickname? */ | 1195 /* If it's invalid uin then maybe it's nickname? */ |
1131 if (invalid_uin(who)) { | 1196 if (invalid_uin(who)) { |
1132 gchar *new_who = charset_convert(who, find_local_charset(), "CP1250"); | 1197 gchar *new_who = charset_convert(who, find_local_charset(), "CP1250"); |
1198 gchar *enew_who = gg_urlencode(new_who); | |
1199 | |
1200 g_free(new_who); | |
1133 | 1201 |
1134 srch->request = g_strdup_printf("Mode=0&FirstName=%s&LastName=%s&Gender=%d" | 1202 srch->request = g_strdup_printf("Mode=0&FirstName=%s&LastName=%s&Gender=%d" |
1135 "&NickName=%s&City=%s&MinBirth=%d&MaxBirth=%d", | 1203 "&NickName=%s&City=%s&MinBirth=%d&MaxBirth=%d", |
1136 "", "", AGG_GENDER_NONE, new_who, "", 0, 0); | 1204 "", "", AGG_GENDER_NONE, enew_who, "", 0, 0); |
1137 | 1205 |
1138 g_free(new_who); | 1206 g_free(enew_who); |
1139 } else | 1207 } else |
1140 srch->request = g_strdup_printf("Mode=3&UserId=%s", who); | 1208 srch->request = g_strdup_printf("Mode=3&UserId=%s", who); |
1141 | 1209 |
1142 if (proxy_connect(GG_PUBDIR_HOST, GG_PUBDIR_PORT, http_req_callback, srch) < 0) { | 1210 if (proxy_connect(GG_PUBDIR_HOST, GG_PUBDIR_PORT, http_req_callback, srch) < 0) { |
1143 g_snprintf(msg, sizeof(msg), _("Connect to search service failed (%s)"), GG_PUBDIR_HOST); | 1211 g_snprintf(msg, sizeof(msg), _("Connect to search service failed (%s)"), |
1212 GG_PUBDIR_HOST); | |
1144 do_error_dialog(msg, _("Gadu-Gadu Error")); | 1213 do_error_dialog(msg, _("Gadu-Gadu Error")); |
1145 g_free(srch->request); | 1214 g_free(srch->request); |
1146 g_free(srch); | 1215 g_free(srch); |
1147 return; | 1216 return; |
1148 } | 1217 } |
1197 ret->set_away = agg_set_away; | 1266 ret->set_away = agg_set_away; |
1198 ret->set_dir = NULL; | 1267 ret->set_dir = NULL; |
1199 ret->get_dir = agg_get_info; | 1268 ret->get_dir = agg_get_info; |
1200 ret->dir_search = agg_dir_search; | 1269 ret->dir_search = agg_dir_search; |
1201 ret->set_idle = NULL; | 1270 ret->set_idle = NULL; |
1202 ret->change_passwd = NULL; | 1271 ret->change_passwd = agg_change_passwd; |
1203 ret->add_buddy = agg_add_buddy; | 1272 ret->add_buddy = agg_add_buddy; |
1204 ret->add_buddies = agg_add_buddies; | 1273 ret->add_buddies = agg_add_buddies; |
1205 ret->remove_buddy = agg_rem_buddy; | 1274 ret->remove_buddy = agg_rem_buddy; |
1206 ret->add_permit = agg_permit_deny_dummy; | 1275 ret->add_permit = agg_permit_deny_dummy; |
1207 ret->add_deny = agg_permit_deny_dummy; | 1276 ret->add_deny = agg_permit_deny_dummy; |
1243 { | 1312 { |
1244 return PRPL_DESC("Gadu-Gadu"); | 1313 return PRPL_DESC("Gadu-Gadu"); |
1245 } | 1314 } |
1246 | 1315 |
1247 #endif | 1316 #endif |
1317 | |
1318 /* | |
1319 * Local variables: | |
1320 * c-indentation-style: k&r | |
1321 * c-basic-offset: 8 | |
1322 * indent-tabs-mode: notnil | |
1323 * End: | |
1324 * | |
1325 * vim: shiftwidth=8: | |
1326 */ |