comparison src/protocols/yahoo/yahoo.c @ 6820:4b3fa146e995

[gaim-migrate @ 7364] Tim Ringenbach (marv_sf) writes: " What this patch tries to do is, if Gaim and Yahoo disagree about which groups a buddy is in, add all the buddies in the groups they should be, and delete all the buddies that are in the wrong groups. This gets confusing because the buddy might be in more than one group on both gaim's list and yahoo's list." committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Fri, 12 Sep 2003 21:22:48 +0000
parents bc8f329c1341
children b67670ac5584
comparison
equal deleted inserted replaced
6819:7403ed48d144 6820:4b3fa146e995
429 429
430 l = l->next; 430 l = l->next;
431 } 431 }
432 } 432 }
433 433
434 static void yahoo_do_group_check(GaimAccount *account, GHashTable *ht, const char *name, const char *group,
435 gboolean *export)
436 {
437 GaimBuddy *b;
438 GaimGroup *g;
439 GSList *list, *i;
440 gboolean onlist = 0;
441 char *oname = NULL;
442
443 if (!g_hash_table_lookup_extended(ht, name, (gpointer *) &oname, (gpointer *) &list))
444 list = gaim_find_buddies(account, name);
445 else
446 g_hash_table_steal(ht, name);
447
448 for (i = list; i; i = i->next) {
449 b = i->data;
450 g = gaim_find_buddys_group(b);
451 if (!gaim_utf8_strcasecmp(group, g->name)) {
452 gaim_debug(GAIM_DEBUG_MISC, "yahoo",
453 "Oh good, %s is in the right group (%s).\n", name, group);
454 list = g_slist_delete_link(list, i);
455 onlist = 1;
456 break;
457 }
458 }
459
460 if (!onlist) {
461 gaim_debug(GAIM_DEBUG_MISC, "yahoo",
462 "Uhoh, %s isn't on the list (or not in this group), adding him to group %s.\n", name, group);
463 if (!(g = gaim_find_group(group))) {
464 g = gaim_group_new(group);
465 gaim_blist_add_group(g, NULL);
466 }
467 b = gaim_buddy_new(account, name, NULL);
468 gaim_blist_add_buddy(b, NULL, g, NULL);
469 *export = TRUE;
470 }
471
472 if (list) {
473 if (!oname)
474 oname = g_strdup(name);
475 g_hash_table_insert(ht, oname, list);
476 } else if (oname)
477 g_free(oname);
478 }
479
480 static void yahoo_do_group_cleanup(gpointer key, gpointer value, gpointer user_data)
481 {
482 char *name = key;
483 GSList *list = value, *i;
484 GaimBuddy *b;
485 GaimGroup *g;
486 gboolean *export = user_data;
487
488 if (list)
489 *export = TRUE;
490
491 for (i = list; i; i = i->next) {
492 b = i->data;
493 g = gaim_find_buddys_group(b);
494 gaim_debug(GAIM_DEBUG_MISC, "yahoo", "Deleting Buddy %s from group %s.\n", name, g->name);
495 gaim_blist_remove_buddy(b);
496 }
497 }
498
434 static void yahoo_process_list(GaimConnection *gc, struct yahoo_packet *pkt) 499 static void yahoo_process_list(GaimConnection *gc, struct yahoo_packet *pkt)
435 { 500 {
436 GSList *l = pkt->hash; 501 GSList *l = pkt->hash;
437 gboolean export = FALSE; 502 gboolean export = FALSE;
438 gboolean got_serv_list = FALSE; 503 gboolean got_serv_list = FALSE;
439 GaimBuddy *b; 504 GaimBuddy *b;
440 GaimGroup *g; 505 GaimGroup *g;
441 struct yahoo_friend *f = NULL; 506 struct yahoo_friend *f = NULL;
507 GaimAccount *account = gaim_connection_get_account(gc);
442 struct yahoo_data *yd = gc->proto_data; 508 struct yahoo_data *yd = gc->proto_data;
509 GHashTable *ht;
443 510
444 char **lines; 511 char **lines;
445 char **split; 512 char **split;
446 char **buddies; 513 char **buddies;
447 char **tmp, **bud; 514 char **tmp, **bud;
468 535
469 if (pkt->status != 0) 536 if (pkt->status != 0)
470 return; 537 return;
471 538
472 if (yd->tmp_serv_blist) { 539 if (yd->tmp_serv_blist) {
540 ht = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_slist_free);
541
473 lines = g_strsplit(yd->tmp_serv_blist->str, "\n", -1); 542 lines = g_strsplit(yd->tmp_serv_blist->str, "\n", -1);
474 for (tmp = lines; *tmp; tmp++) { 543 for (tmp = lines; *tmp; tmp++) {
475 split = g_strsplit(*tmp, ":", 2); 544 split = g_strsplit(*tmp, ":", 2);
476 if (!split) 545 if (!split)
477 continue; 546 continue;
483 for (bud = buddies; bud && *bud; bud++) { 552 for (bud = buddies; bud && *bud; bud++) {
484 if (!(f = g_hash_table_lookup(yd->friends, *bud))) { 553 if (!(f = g_hash_table_lookup(yd->friends, *bud))) {
485 f = yahoo_friend_new(*bud); 554 f = yahoo_friend_new(*bud);
486 g_hash_table_insert(yd->friends, g_strdup(*bud), f); 555 g_hash_table_insert(yd->friends, g_strdup(*bud), f);
487 } 556 }
488 if (!(b = gaim_find_buddy(gc->account, *bud))) { 557 if (!(b = gaim_find_buddy(account, *bud))) {
489 if (!(g = gaim_find_group(split[0]))) { 558 if (!(g = gaim_find_group(split[0]))) {
490 g = gaim_group_new(split[0]); 559 g = gaim_group_new(split[0]);
491 gaim_blist_add_group(g, NULL); 560 gaim_blist_add_group(g, NULL);
492 } 561 }
493 b = gaim_buddy_new(gc->account, *bud, NULL); 562 b = gaim_buddy_new(account, *bud, NULL);
494 gaim_blist_add_buddy(b, NULL, g, NULL); 563 gaim_blist_add_buddy(b, NULL, g, NULL);
495 export = TRUE; 564 export = TRUE;
496 } /*else { do something here is gaim and yahoo don't agree on the buddies group 565 }
497 GaimGroup *tmpgp; 566
498 567 yahoo_do_group_check(account, ht, *bud, split[0], &export);
499 tmpgp = gaim_find_buddys_group(b);
500 if (!tmpgp || !gaim_utf8_strcasecmp(tmpgp->name, split[0])) {
501 GaimGroup *ng;
502 if (!(ng = gaim_find_group(split[0])) {
503 g = gaim_group_new(split[0]);
504 gaim_blist_add_group(g, NULL);
505 } */
506
507 } 568 }
508 g_strfreev(buddies); 569 g_strfreev(buddies);
509 g_strfreev(split); 570 g_strfreev(split);
510 } 571 }
511 g_strfreev(lines); 572 g_strfreev(lines);
512 573
513 g_string_free(yd->tmp_serv_blist, TRUE); 574 g_string_free(yd->tmp_serv_blist, TRUE);
514 yd->tmp_serv_blist = NULL; 575 yd->tmp_serv_blist = NULL;
576 g_hash_table_foreach(ht, yahoo_do_group_cleanup, &export);
577 g_hash_table_destroy(ht);
515 } 578 }
516 579
517 580
518 if (yd->tmp_serv_ilist) { 581 if (yd->tmp_serv_ilist) {
519 buddies = g_strsplit(yd->tmp_serv_ilist->str, ",", -1); 582 buddies = g_strsplit(yd->tmp_serv_ilist->str, ",", -1);
1726 1789
1727 pkt = yahoo_packet_new(YAHOO_SERVICE_ADDBUDDY, YAHOO_STATUS_AVAILABLE, 0); 1790 pkt = yahoo_packet_new(YAHOO_SERVICE_ADDBUDDY, YAHOO_STATUS_AVAILABLE, 0);
1728 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); 1791 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc));
1729 yahoo_packet_hash(pkt, 7, who); 1792 yahoo_packet_hash(pkt, 7, who);
1730 yahoo_packet_hash(pkt, 65, group); 1793 yahoo_packet_hash(pkt, 65, group);
1794 yahoo_packet_hash(pkt, 14, "");
1731 yahoo_send_packet(yd, pkt); 1795 yahoo_send_packet(yd, pkt);
1732 yahoo_packet_free(pkt); 1796 yahoo_packet_free(pkt);
1733 } 1797 }
1734 1798
1735 static void yahoo_remove_buddy(GaimConnection *gc, const char *who, const char *group) 1799 static void yahoo_remove_buddy(GaimConnection *gc, const char *who, const char *group)
1739 struct yahoo_packet *pkt; 1803 struct yahoo_packet *pkt;
1740 1804
1741 if (!(f = g_hash_table_lookup(yd->friends, who))) 1805 if (!(f = g_hash_table_lookup(yd->friends, who)))
1742 return; 1806 return;
1743 1807
1744 g_hash_table_remove(yd->friends, who); 1808 if (!gaim_find_buddy(gaim_connection_get_account(gc), who))
1809 g_hash_table_remove(yd->friends, who);
1745 1810
1746 pkt = yahoo_packet_new(YAHOO_SERVICE_REMBUDDY, YAHOO_STATUS_AVAILABLE, 0); 1811 pkt = yahoo_packet_new(YAHOO_SERVICE_REMBUDDY, YAHOO_STATUS_AVAILABLE, 0);
1747 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); 1812 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc));
1748 yahoo_packet_hash(pkt, 7, who); 1813 yahoo_packet_hash(pkt, 7, who);
1749 yahoo_packet_hash(pkt, 65, group); 1814 yahoo_packet_hash(pkt, 65, group);