Mercurial > pidgin
comparison src/protocols/gg/gg.c @ 8775:ce90b119b103
[gaim-migrate @ 9537]
" Updates gadu-gadu to use the new version 6.0 protocol.
This patch was compiled with the use of much code from ekg (http:
//dev.null.pl/ekg/). It hasn't been extensively tested (I only speak
English, so how it behaves for polish speakers would be good to
know!), so more testing would be great." --Andrew Wellington
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Fri, 23 Apr 2004 17:24:19 +0000 |
parents | d7b8eb1f0a18 |
children | 7c7c7f5ce09d |
comparison
equal
deleted
inserted
replaced
8774:5205743477bb | 8775:ce90b119b103 |
---|---|
1 /* | 1 /* |
2 * gaim - Gadu-Gadu Protocol Plugin | 2 * gaim - Gadu-Gadu Protocol Plugin |
3 * $Id: gg.c 9504 2004-04-22 01:53:18Z chipx86 $ | 3 * $Id: gg.c 9537 2004-04-23 17:24:19Z lschiere $ |
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 |
263 m = g_list_append(m, pbm); | 263 m = g_list_append(m, pbm); |
264 | 264 |
265 return m; | 265 return m; |
266 } | 266 } |
267 | 267 |
268 static void agg_load_buddy_list(GaimConnection *gc, char *buddylist) | |
269 { | |
270 struct agg_data *gd = (struct agg_data *)gc->proto_data; | |
271 gchar *ptr = buddylist; | |
272 gchar **users_tbl; | |
273 int i; | |
274 uin_t *userlist = NULL; | |
275 int userlist_size = 0; | |
276 | |
277 users_tbl = g_strsplit(ptr, "\r\n", AGG_PUBDIR_MAX_ENTRIES); | |
278 | |
279 /* Parse array of Buddies List */ | |
280 for (i = 0; users_tbl[i] != NULL; i++) { | |
281 gchar **data_tbl; | |
282 gchar *name, *show; | |
283 | |
284 if (strlen(users_tbl[i])==0) { | |
285 gaim_debug(GAIM_DEBUG_MISC, "gg", | |
286 "import_buddies_server_results: users_tbl[i] is empty\n"); | |
287 continue; | |
288 } | |
289 | |
290 data_tbl = g_strsplit(users_tbl[i], ";", 8); | |
291 | |
292 show = charset_convert(data_tbl[3], "CP1250", "UTF-8"); | |
293 name = data_tbl[6]; | |
294 | |
295 if (invalid_uin(name)) { | |
296 continue; | |
297 } | |
298 | |
299 gaim_debug(GAIM_DEBUG_MISC, "gg", | |
300 "import_buddies_server_results: uin: %s\n", name); | |
301 if (!gaim_find_buddy(gc->account, name)) { | |
302 GaimBuddy *b; | |
303 GaimGroup *g; | |
304 /* Default group if none specified on server */ | |
305 gchar *group = g_strdup("Gadu-Gadu"); | |
306 if (strlen(data_tbl[5])) { | |
307 gchar **group_tbl = g_strsplit(data_tbl[5], ",", 2); | |
308 if (strlen(group_tbl[0])) { | |
309 g_free(group); | |
310 group = g_strdup(group_tbl[0]); | |
311 } | |
312 g_strfreev(group_tbl); | |
313 } | |
314 /* Add Buddy to our userlist */ | |
315 if (!(g = gaim_find_group(group))) { | |
316 g = gaim_group_new(group); | |
317 gaim_blist_add_group(g, NULL); | |
318 } | |
319 b = gaim_buddy_new(gc->account, name, strlen(show) ? show : NULL); | |
320 gaim_blist_add_buddy(b,NULL,g,NULL); | |
321 gaim_blist_save(); | |
322 | |
323 userlist_size++; | |
324 userlist = g_renew(uin_t, userlist, userlist_size); | |
325 userlist[userlist_size - 1] = | |
326 (uin_t) strtol((char *)name, (char **)NULL, 10); | |
327 | |
328 g_free(group); | |
329 } | |
330 g_free(show); | |
331 g_strfreev(data_tbl); | |
332 } | |
333 g_strfreev(users_tbl); | |
334 | |
335 if (userlist) { | |
336 gg_notify(gd->sess, userlist, userlist_size); | |
337 g_free(userlist); | |
338 } | |
339 } | |
340 | |
341 static void agg_save_buddy_list (GaimConnection *gc, char *existlist) | |
342 { | |
343 GaimBlistNode *gnode, *cnode, *bnode; | |
344 char *buddylist = g_strdup(existlist ? existlist : ""); | |
345 char *ptr; | |
346 struct agg_data *gd = (struct agg_data *)gc->proto_data; | |
347 | |
348 for(gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) { | |
349 GaimGroup *g = (GaimGroup *)gnode; | |
350 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
351 continue; | |
352 for(cnode = gnode->child; cnode; cnode = cnode->next) { | |
353 if(!GAIM_BLIST_NODE_IS_CONTACT(cnode)) | |
354 continue; | |
355 for(bnode = cnode->child; bnode; bnode = bnode->next) { | |
356 GaimBuddy *b = (GaimBuddy *)bnode; | |
357 | |
358 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
359 continue; | |
360 | |
361 if(b->account == gc->account) { | |
362 gchar *newdata; | |
363 /* GG Number */ | |
364 gchar *name = b->name; | |
365 /* GG Pseudo */ | |
366 gchar *show = b->alias ? b->alias : b->name; | |
367 /* Group Name */ | |
368 gchar *gname = g->name; | |
369 | |
370 newdata = g_strdup_printf("%s;%s;%s;%s;%s;%s;%s;%s%s\r\n", | |
371 show, show, show, show, "", gname, name, "", ""); | |
372 | |
373 ptr = buddylist; | |
374 buddylist = g_strconcat(ptr, newdata, NULL); | |
375 | |
376 g_free(newdata); | |
377 g_free(ptr); | |
378 } | |
379 } | |
380 } | |
381 } | |
382 | |
383 /* save the list to the gadu gadu server */ | |
384 gg_userlist_request(gd->sess, GG_USERLIST_PUT, buddylist); | |
385 } | |
386 | |
268 static void main_callback(gpointer data, gint source, GaimInputCondition cond) | 387 static void main_callback(gpointer data, gint source, GaimInputCondition cond) |
269 { | 388 { |
270 GaimConnection *gc = data; | 389 GaimConnection *gc = data; |
271 struct agg_data *gd = gc->proto_data; | 390 struct agg_data *gd = gc->proto_data; |
272 struct gg_event *e; | 391 struct gg_event *e; |
345 status); | 464 status); |
346 n++; | 465 n++; |
347 } | 466 } |
348 } | 467 } |
349 break; | 468 break; |
469 case GG_EVENT_NOTIFY60: | |
470 { | |
471 gchar user[20]; | |
472 struct gg_notify_reply60 *n = (void *)e->event.notify60; | |
473 guint status; | |
474 | |
475 while (n->uin) { | |
476 switch (n->status) { | |
477 case GG_STATUS_NOT_AVAIL: | |
478 status = UC_UNAVAILABLE; | |
479 break; | |
480 case GG_STATUS_AVAIL: | |
481 case GG_STATUS_BUSY: | |
482 case GG_STATUS_INVISIBLE: | |
483 status = UC_NORMAL | (n->status << 5); | |
484 break; | |
485 default: | |
486 status = UC_NORMAL; | |
487 break; | |
488 } | |
489 | |
490 g_snprintf(user, sizeof(user), "%lu", (long unsigned int)n->uin); | |
491 serv_got_update(gc, user, (status == UC_UNAVAILABLE) ? 0 : 1, 0, 0, 0, | |
492 status); | |
493 n++; | |
494 } | |
495 } | |
496 break; | |
350 case GG_EVENT_STATUS: | 497 case GG_EVENT_STATUS: |
351 { | 498 { |
352 gchar user[20]; | 499 gchar user[20]; |
353 guint status; | 500 guint status; |
354 | 501 |
369 g_snprintf(user, sizeof(user), "%lu", e->event.status.uin); | 516 g_snprintf(user, sizeof(user), "%lu", e->event.status.uin); |
370 serv_got_update(gc, user, (status == UC_UNAVAILABLE) ? 0 : 1, 0, 0, 0, | 517 serv_got_update(gc, user, (status == UC_UNAVAILABLE) ? 0 : 1, 0, 0, 0, |
371 status); | 518 status); |
372 } | 519 } |
373 break; | 520 break; |
521 case GG_EVENT_STATUS60: | |
522 { | |
523 gchar user[20]; | |
524 guint status; | |
525 | |
526 switch (e->event.status60.status) { | |
527 case GG_STATUS_NOT_AVAIL: | |
528 status = UC_UNAVAILABLE; | |
529 break; | |
530 case GG_STATUS_AVAIL: | |
531 case GG_STATUS_BUSY: | |
532 case GG_STATUS_INVISIBLE: | |
533 status = UC_NORMAL | (e->event.status60.status << 5); | |
534 break; | |
535 default: | |
536 status = UC_NORMAL; | |
537 break; | |
538 } | |
539 | |
540 g_snprintf(user, sizeof(user), "%lu", e->event.status60.uin); | |
541 serv_got_update(gc, user, (status == UC_UNAVAILABLE) ? 0 : 1, 0, 0, 0, | |
542 status); | |
543 } | |
544 break; | |
374 case GG_EVENT_ACK: | 545 case GG_EVENT_ACK: |
375 gaim_debug(GAIM_DEBUG_MISC, "gg", | 546 gaim_debug(GAIM_DEBUG_MISC, "gg", |
376 "main_callback: message %d to %lu sent with status %d\n", | 547 "main_callback: message %d to %lu sent with status %d\n", |
377 e->event.ack.seq, e->event.ack.recipient, e->event.ack.status); | 548 e->event.ack.seq, e->event.ack.recipient, e->event.ack.status); |
378 break; | 549 break; |
550 case GG_EVENT_USERLIST: | |
551 { | |
552 gaim_debug(GAIM_DEBUG_MISC, "gg", "main_callback: received userlist reply\n"); | |
553 switch (e->event.userlist.type) { | |
554 case GG_USERLIST_GET_REPLY: | |
555 { | |
556 | |
557 if (e->event.userlist.reply) { | |
558 agg_load_buddy_list(gc, e->event.userlist.reply); | |
559 } | |
560 break; | |
561 } | |
562 | |
563 case GG_USERLIST_PUT_REPLY: | |
564 { | |
565 /* ignored */ | |
566 } | |
567 } | |
568 } | |
569 | |
379 default: | 570 default: |
380 gaim_debug(GAIM_DEBUG_ERROR, "gg", | 571 gaim_debug(GAIM_DEBUG_ERROR, "gg", |
381 "main_callback: unsupported event %d\n", e->type); | 572 "main_callback: unsupported event %d\n", e->type); |
382 break; | 573 break; |
383 } | 574 } |
586 { | 777 { |
587 struct agg_data *gd = (struct agg_data *)gc->proto_data; | 778 struct agg_data *gd = (struct agg_data *)gc->proto_data; |
588 if (invalid_uin(who)) | 779 if (invalid_uin(who)) |
589 return; | 780 return; |
590 gg_add_notify(gd->sess, strtol(who, (char **)NULL, 10)); | 781 gg_add_notify(gd->sess, strtol(who, (char **)NULL, 10)); |
782 agg_save_buddy_list(gc, NULL); | |
591 } | 783 } |
592 | 784 |
593 static void agg_rem_buddy(GaimConnection *gc, const char *who, const char *group) | 785 static void agg_rem_buddy(GaimConnection *gc, const char *who, const char *group) |
594 { | 786 { |
595 struct agg_data *gd = (struct agg_data *)gc->proto_data; | 787 struct agg_data *gd = (struct agg_data *)gc->proto_data; |
596 if (invalid_uin(who)) | 788 if (invalid_uin(who)) |
597 return; | 789 return; |
598 gg_remove_notify(gd->sess, strtol(who, (char **)NULL, 10)); | 790 gg_remove_notify(gd->sess, strtol(who, (char **)NULL, 10)); |
791 agg_save_buddy_list(gc, NULL); | |
599 } | 792 } |
600 | 793 |
601 static void agg_add_buddies(GaimConnection *gc, GList *whos) | 794 static void agg_add_buddies(GaimConnection *gc, GList *whos) |
602 { | 795 { |
603 struct agg_data *gd = (struct agg_data *)gc->proto_data; | 796 struct agg_data *gd = (struct agg_data *)gc->proto_data; |
616 | 809 |
617 if (userlist) { | 810 if (userlist) { |
618 gg_notify(gd->sess, userlist, userlist_size); | 811 gg_notify(gd->sess, userlist, userlist_size); |
619 g_free(userlist); | 812 g_free(userlist); |
620 } | 813 } |
814 | |
815 agg_save_buddy_list(gc, NULL); | |
621 } | 816 } |
622 | 817 |
623 static void search_results(GaimConnection *gc, gchar *webdata) | 818 static void search_results(GaimConnection *gc, gchar *webdata) |
624 { | 819 { |
625 gchar **webdata_tbl; | 820 gchar **webdata_tbl; |
732 change_pass(GaimConnection *gc) | 927 change_pass(GaimConnection *gc) |
733 { | 928 { |
734 gaim_account_request_change_password(gaim_connection_get_account(gc)); | 929 gaim_account_request_change_password(gaim_connection_get_account(gc)); |
735 } | 930 } |
736 | 931 |
932 #if 0 | |
737 static void import_buddies_server_results(GaimConnection *gc, gchar *webdata) | 933 static void import_buddies_server_results(GaimConnection *gc, gchar *webdata) |
738 { | 934 { |
739 gchar *ptr; | 935 gchar *ptr; |
740 gchar **users_tbl; | 936 gchar **users_tbl; |
741 int i; | 937 int i; |
837 "delete_buddies_server_results: webdata [%s]\n", webdata); | 1033 "delete_buddies_server_results: webdata [%s]\n", webdata); |
838 gaim_notify_error(gc, NULL, | 1034 gaim_notify_error(gc, NULL, |
839 _("Couldn't delete Buddy List from Gadu-Gadu server"), | 1035 _("Couldn't delete Buddy List from Gadu-Gadu server"), |
840 NULL); | 1036 NULL); |
841 } | 1037 } |
1038 #endif | |
842 | 1039 |
843 static void password_change_server_results(GaimConnection *gc, gchar *webdata) | 1040 static void password_change_server_results(GaimConnection *gc, gchar *webdata) |
844 { | 1041 { |
845 if (strstr(webdata, "reg_success:")) { | 1042 if (strstr(webdata, "reg_success:")) { |
846 gaim_notify_info(gc, NULL, | 1043 gaim_notify_info(gc, NULL, |
901 | 1098 |
902 switch (hdata->type) { | 1099 switch (hdata->type) { |
903 case AGG_HTTP_SEARCH: | 1100 case AGG_HTTP_SEARCH: |
904 search_results(gc, webdata); | 1101 search_results(gc, webdata); |
905 break; | 1102 break; |
1103 #if 0 | |
906 case AGG_HTTP_USERLIST_IMPORT: | 1104 case AGG_HTTP_USERLIST_IMPORT: |
907 import_buddies_server_results(gc, webdata); | 1105 import_buddies_server_results(gc, webdata); |
908 break; | 1106 break; |
909 case AGG_HTTP_USERLIST_EXPORT: | 1107 case AGG_HTTP_USERLIST_EXPORT: |
910 export_buddies_server_results(gc, webdata); | 1108 export_buddies_server_results(gc, webdata); |
911 break; | 1109 break; |
912 case AGG_HTTP_USERLIST_DELETE: | 1110 case AGG_HTTP_USERLIST_DELETE: |
913 delete_buddies_server_results(gc, webdata); | 1111 delete_buddies_server_results(gc, webdata); |
914 break; | 1112 break; |
1113 #endif | |
915 case AGG_HTTP_PASSWORD_CHANGE: | 1114 case AGG_HTTP_PASSWORD_CHANGE: |
916 password_change_server_results(gc, webdata); | 1115 password_change_server_results(gc, webdata); |
917 break; | 1116 break; |
918 case AGG_HTTP_NONE: | 1117 case AGG_HTTP_NONE: |
919 default: | 1118 default: |
978 g_free(buf); | 1177 g_free(buf); |
979 | 1178 |
980 hdata->inpa = gaim_input_add(source, GAIM_INPUT_READ, http_results, hdata); | 1179 hdata->inpa = gaim_input_add(source, GAIM_INPUT_READ, http_results, hdata); |
981 } | 1180 } |
982 | 1181 |
1182 #if 0 | |
983 static void import_buddies_server(GaimConnection *gc) | 1183 static void import_buddies_server(GaimConnection *gc) |
984 { | 1184 { |
985 struct agg_http *hi = g_new0(struct agg_http, 1); | 1185 struct agg_http *hi = g_new0(struct agg_http, 1); |
986 gchar *u = gg_urlencode(gaim_account_get_username(gc->account)); | 1186 gchar *u = gg_urlencode(gaim_account_get_username(gc->account)); |
987 gchar *p = gg_urlencode(gaim_account_get_password(gc->account)); | 1187 gchar *p = gg_urlencode(gaim_account_get_password(gc->account)); |
1100 g_free(he->request); | 1300 g_free(he->request); |
1101 g_free(he); | 1301 g_free(he); |
1102 return; | 1302 return; |
1103 } | 1303 } |
1104 } | 1304 } |
1305 #endif | |
1105 | 1306 |
1106 static void agg_dir_search(GaimConnection *gc, const char *first, const char *middle, | 1307 static void agg_dir_search(GaimConnection *gc, const char *first, const char *middle, |
1107 const char *last, const char *maiden, const char *city, const char *state, | 1308 const char *last, const char *maiden, const char *city, const char *state, |
1108 const char *country, const char *email) | 1309 const char *country, const char *email) |
1109 { | 1310 { |
1207 pam->label = _("Change Password"); | 1408 pam->label = _("Change Password"); |
1208 pam->callback = change_pass; | 1409 pam->callback = change_pass; |
1209 pam->gc = gc; | 1410 pam->gc = gc; |
1210 m = g_list_append(m, pam); | 1411 m = g_list_append(m, pam); |
1211 | 1412 |
1413 #if 0 | |
1212 m = g_list_append(m, NULL); | 1414 m = g_list_append(m, NULL); |
1213 | |
1214 pam = g_new0(struct proto_actions_menu, 1); | 1415 pam = g_new0(struct proto_actions_menu, 1); |
1215 pam->label = _("Import Buddy List from Server"); | 1416 pam->label = _("Import Buddy List from Server"); |
1216 pam->callback = import_buddies_server; | 1417 pam->callback = import_buddies_server; |
1217 pam->gc = gc; | 1418 pam->gc = gc; |
1218 m = g_list_append(m, pam); | 1419 m = g_list_append(m, pam); |
1226 pam = g_new0(struct proto_actions_menu, 1); | 1427 pam = g_new0(struct proto_actions_menu, 1); |
1227 pam->label = _("Delete Buddy List from Server"); | 1428 pam->label = _("Delete Buddy List from Server"); |
1228 pam->callback = delete_buddies_server; | 1429 pam->callback = delete_buddies_server; |
1229 pam->gc = gc; | 1430 pam->gc = gc; |
1230 m = g_list_append(m, pam); | 1431 m = g_list_append(m, pam); |
1432 #endif | |
1231 | 1433 |
1232 return m; | 1434 return m; |
1233 } | 1435 } |
1234 | 1436 |
1235 static void agg_get_info(GaimConnection *gc, const char *who) | 1437 static void agg_get_info(GaimConnection *gc, const char *who) |
1299 static void agg_permit_deny_dummy(GaimConnection *gc, const char *who) | 1501 static void agg_permit_deny_dummy(GaimConnection *gc, const char *who) |
1300 { | 1502 { |
1301 /* It's implemented on client side because GG server doesn't support this */ | 1503 /* It's implemented on client side because GG server doesn't support this */ |
1302 } | 1504 } |
1303 | 1505 |
1506 static void agg_group_buddy (GaimConnection * gc, const char *who, | |
1507 const char *old_group, const char *new_group) | |
1508 { | |
1509 GaimBuddy *buddy = gaim_find_buddy(gaim_connection_get_account(gc), who); | |
1510 gchar *newdata; | |
1511 /* GG Number */ | |
1512 gchar *name = buddy->name; | |
1513 /* GG Pseudo */ | |
1514 gchar *show = buddy->alias ? buddy->alias : buddy->name; | |
1515 /* Group Name */ | |
1516 const gchar *gname = new_group; | |
1517 | |
1518 newdata = g_strdup_printf("%s;%s;%s;%s;%s;%s;%s;%s%s\r\n", | |
1519 show, show, show, show, "", gname, name, "", ""); | |
1520 agg_save_buddy_list(gc, newdata); | |
1521 g_free(newdata); | |
1522 } | |
1523 | |
1524 static void agg_rename_group (GaimConnection *gc, const char *old_group, | |
1525 const char *new_group, GList *members) | |
1526 { | |
1527 agg_save_buddy_list(gc, NULL); | |
1528 } | |
1529 | |
1304 static GaimPlugin *my_protocol = NULL; | 1530 static GaimPlugin *my_protocol = NULL; |
1305 | 1531 |
1306 static GaimPluginProtocolInfo prpl_info = | 1532 static GaimPluginProtocolInfo prpl_info = |
1307 { | 1533 { |
1308 GAIM_PRPL_API_VERSION, | 1534 GAIM_PRPL_API_VERSION, |
1349 NULL, | 1575 NULL, |
1350 NULL, | 1576 NULL, |
1351 NULL, | 1577 NULL, |
1352 NULL, | 1578 NULL, |
1353 NULL, | 1579 NULL, |
1354 NULL, | 1580 agg_group_buddy, |
1355 NULL, | 1581 agg_rename_group, |
1356 NULL, | 1582 NULL, |
1357 NULL, | 1583 NULL, |
1358 NULL | 1584 NULL |
1359 }; | 1585 }; |
1360 | 1586 |