comparison src/protocols/yahoo/yahoo.c @ 9279:1eaa4d8dcf26

[gaim-migrate @ 10082] Some more cleanups. Add some yahoo_friend_* functions and made yahoo use them. I may eventually make the structure opque. committer: Tailor Script <tailor@pidgin.im>
author Tim Ringenbach <marv@pidgin.im>
date Mon, 14 Jun 2004 05:47:41 +0000
parents 2401a9ef74a0
children 2104c1039626
comparison
equal deleted inserted replaced
9278:2401a9ef74a0 9279:1eaa4d8dcf26
270 } 270 }
271 271
272 static void yahoo_process_status(GaimConnection *gc, struct yahoo_packet *pkt) 272 static void yahoo_process_status(GaimConnection *gc, struct yahoo_packet *pkt)
273 { 273 {
274 struct yahoo_data *yd = gc->proto_data; 274 struct yahoo_data *yd = gc->proto_data;
275 GaimAccount *account = gaim_connection_get_account(gc);
276 GSList *l = pkt->hash; 275 GSList *l = pkt->hash;
277 YahooFriend *f = NULL; 276 YahooFriend *f = NULL;
278 char *name = NULL; 277 char *name = NULL;
279 278
280 if (pkt->service == YAHOO_SERVICE_LOGOFF && pkt->status == -1) { 279 if (pkt->service == YAHOO_SERVICE_LOGOFF && pkt->status == -1) {
311 break; 310 break;
312 case 8: /* how many online buddies we have */ 311 case 8: /* how many online buddies we have */
313 break; 312 break;
314 case 7: /* the current buddy */ 313 case 7: /* the current buddy */
315 name = pair->value; 314 name = pair->value;
316 f = g_hash_table_lookup(yd->friends, gaim_normalize(account, name)); 315 f = yahoo_friend_find_or_new(gc, name);
317 if (!f) {
318 f = yahoo_friend_new();
319 g_hash_table_insert(yd->friends, g_strdup(gaim_normalize(account, name)), f);
320 }
321 break; 316 break;
322 case 10: /* state */ 317 case 10: /* state */
323 if (!f) 318 if (!f)
324 break; 319 break;
325 320
589 } 584 }
590 grp = yahoo_string_decode(gc, split[0], FALSE); 585 grp = yahoo_string_decode(gc, split[0], FALSE);
591 buddies = g_strsplit(split[1], ",", -1); 586 buddies = g_strsplit(split[1], ",", -1);
592 for (bud = buddies; bud && *bud; bud++) { 587 for (bud = buddies; bud && *bud; bud++) {
593 norm_bud = g_strdup(gaim_normalize(account, *bud)); 588 norm_bud = g_strdup(gaim_normalize(account, *bud));
594 if (!(f = g_hash_table_lookup(yd->friends, norm_bud))) { 589 f = yahoo_friend_find_or_new(gc, norm_bud);
595 f = yahoo_friend_new(); 590
596 g_hash_table_insert(yd->friends, g_strdup(norm_bud), f);
597 }
598 if (!(b = gaim_find_buddy(account, norm_bud))) { 591 if (!(b = gaim_find_buddy(account, norm_bud))) {
599 if (!(g = gaim_find_group(grp))) { 592 if (!(g = gaim_find_group(grp))) {
600 g = gaim_group_new(grp); 593 g = gaim_group_new(grp);
601 gaim_blist_add_group(g, NULL); 594 gaim_blist_add_group(g, NULL);
602 } 595 }
648 char *from = NULL; 641 char *from = NULL;
649 char *stat = NULL; 642 char *stat = NULL;
650 char *game = NULL; 643 char *game = NULL;
651 YahooFriend *f = NULL; 644 YahooFriend *f = NULL;
652 GSList *l = pkt->hash; 645 GSList *l = pkt->hash;
653 GaimAccount *account = gaim_connection_get_account(gc);
654 struct yahoo_data *yd = (struct yahoo_data*) gc->proto_data;
655 646
656 while (l) { 647 while (l) {
657 struct yahoo_pair *pair = l->data; 648 struct yahoo_pair *pair = l->data;
658 if (pair->key == 4) 649 if (pair->key == 4)
659 from = pair->value; 650 from = pair->value;
681 gaim_debug(GAIM_DEBUG_WARNING, "yahoo", 672 gaim_debug(GAIM_DEBUG_WARNING, "yahoo",
682 "%s is playing a game, and doesn't want " 673 "%s is playing a game, and doesn't want "
683 "you to know.\n", from); 674 "you to know.\n", from);
684 } 675 }
685 676
686 f = g_hash_table_lookup(yd->friends, gaim_normalize(account, from)); 677 f = yahoo_friend_find(gc, from);
687 if (!f) 678 if (!f)
688 return; /* if they're not on the list, don't bother */ 679 return; /* if they're not on the list, don't bother */
689 680
690 if (f->game) { 681 if (f->game) {
691 g_free(f->game); 682 g_free(f->game);
1753 char *who = NULL; 1744 char *who = NULL;
1754 char *group = NULL; 1745 char *group = NULL;
1755 char *decoded_group; 1746 char *decoded_group;
1756 char *buf; 1747 char *buf;
1757 YahooFriend *f; 1748 YahooFriend *f;
1758 struct yahoo_data *yd = gc->proto_data;
1759 GSList *l = pkt->hash; 1749 GSList *l = pkt->hash;
1760 1750
1761 while (l) { 1751 while (l) {
1762 struct yahoo_pair *pair = l->data; 1752 struct yahoo_pair *pair = l->data;
1763 1753
1780 return; 1770 return;
1781 if (!group) 1771 if (!group)
1782 group = ""; 1772 group = "";
1783 1773
1784 if (!err || (err == 2)) { /* 0 = ok, 2 = already on serv list */ 1774 if (!err || (err == 2)) { /* 0 = ok, 2 = already on serv list */
1785 if (!g_hash_table_lookup(yd->friends, gaim_normalize(gaim_connection_get_account(gc), who))) { 1775 f = yahoo_friend_find_or_new(gc, who);
1786 f = yahoo_friend_new(); 1776 yahoo_update_status(gc, who, f);
1787 g_hash_table_insert(yd->friends, g_strdup(gaim_normalize(gaim_connection_get_account(gc), who)), f);
1788 yahoo_update_status(gc, who, f);
1789 }
1790 return; 1777 return;
1791 } 1778 }
1792 1779
1793 decoded_group = yahoo_string_decode(gc, group, FALSE); 1780 decoded_group = yahoo_string_decode(gc, group, FALSE);
1794 buf = g_strdup_printf(_("Could not add buddy %s to group %s to the server list on account %s."), 1781 buf = g_strdup_printf(_("Could not add buddy %s to group %s to the server list on account %s."),
2327 2314
2328 if (!b || !(account = b->account) || !(gc = gaim_account_get_connection(account)) || 2315 if (!b || !(account = b->account) || !(gc = gaim_account_get_connection(account)) ||
2329 !(yd = gc->proto_data)) 2316 !(yd = gc->proto_data))
2330 return; 2317 return;
2331 2318
2332 f = g_hash_table_lookup(yd->friends, b->name); 2319 f = yahoo_friend_find(gc, b->name);
2333 if (!f) { 2320 if (!f) {
2334 *se = "notauthorized"; 2321 *se = "notauthorized";
2335 return; 2322 return;
2336 } 2323 }
2337 2324
2426 2413
2427 buddy = (GaimBuddy *) node; 2414 buddy = (GaimBuddy *) node;
2428 gc = gaim_account_get_connection(buddy->account); 2415 gc = gaim_account_get_connection(buddy->account);
2429 yd = (struct yahoo_data *) gc->proto_data; 2416 yd = (struct yahoo_data *) gc->proto_data;
2430 2417
2431 f = g_hash_table_lookup(yd->friends, buddy->name); 2418 f = yahoo_friend_find(gc, buddy->name);
2432 if (!f) 2419 if (!f)
2433 return; 2420 return;
2434 2421
2435 game = f->game; 2422 game = f->game;
2436 if (!game) 2423 if (!game)
2445 g_free(game); 2432 g_free(game);
2446 } 2433 }
2447 2434
2448 static char *yahoo_status_text(GaimBuddy *b) 2435 static char *yahoo_status_text(GaimBuddy *b)
2449 { 2436 {
2450 struct yahoo_data *yd = (struct yahoo_data*)b->account->gc->proto_data;
2451 YahooFriend *f = NULL; 2437 YahooFriend *f = NULL;
2452 2438
2453 f = g_hash_table_lookup(yd->friends, b->name); 2439 f = yahoo_friend_find(b->account->gc, b->name);
2454 if (!f) 2440 if (!f)
2455 return g_strdup(_("Not on server list")); 2441 return g_strdup(_("Not on server list"));
2456 2442
2457 switch (f->status) { 2443 switch (f->status) {
2458 case YAHOO_STATUS_AVAILABLE: 2444 case YAHOO_STATUS_AVAILABLE:
2471 } 2457 }
2472 } 2458 }
2473 2459
2474 char *yahoo_tooltip_text(GaimBuddy *b) 2460 char *yahoo_tooltip_text(GaimBuddy *b)
2475 { 2461 {
2476 struct yahoo_data *yd = (struct yahoo_data*)b->account->gc->proto_data;
2477 YahooFriend *f; 2462 YahooFriend *f;
2478 char *escaped, *status, *ret; 2463 char *escaped, *status, *ret;
2479 2464
2480 f = g_hash_table_lookup(yd->friends, b->name); 2465 f = yahoo_friend_find(b->account->gc, b->name);
2481 if (!f) 2466 if (!f)
2482 status = g_strdup_printf("\n%s", _("Not on server list")); 2467 status = g_strdup_printf("\n%s", _("Not on server list"));
2483 else 2468 else
2484 switch (f->status) { 2469 switch (f->status) {
2485 case YAHOO_STATUS_IDLE: 2470 case YAHOO_STATUS_IDLE:
2552 { 2537 {
2553 GList *m = NULL; 2538 GList *m = NULL;
2554 GaimBlistNodeAction *act; 2539 GaimBlistNodeAction *act;
2555 2540
2556 GaimConnection *gc = gaim_account_get_connection(buddy->account); 2541 GaimConnection *gc = gaim_account_get_connection(buddy->account);
2557 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
2558 static char buf2[1024]; 2542 static char buf2[1024];
2559 YahooFriend *f; 2543 YahooFriend *f;
2560 2544
2561 f = g_hash_table_lookup(yd->friends, buddy->name); 2545 f = yahoo_friend_find(gc, buddy->name);
2562 2546
2563 if (!f) { 2547 if (!f) {
2564 act = gaim_blist_node_action_new(_("Add Buddy"), 2548 act = gaim_blist_node_action_new(_("Add Buddy"),
2565 yahoo_addbuddyfrommenu_cb, NULL); 2549 yahoo_addbuddyfrommenu_cb, NULL);
2566 m = g_list_append(m, act); 2550 m = g_list_append(m, act);
2920 GSList *buddies, *l; 2904 GSList *buddies, *l;
2921 GaimGroup *g; 2905 GaimGroup *g;
2922 gboolean remove = TRUE; 2906 gboolean remove = TRUE;
2923 char *cg; 2907 char *cg;
2924 2908
2925 if (!(f = g_hash_table_lookup(yd->friends, who))) 2909 if (!(f = yahoo_friend_find(gc, who)))
2926 return; 2910 return;
2927 2911
2928 buddies = gaim_find_buddies(gaim_connection_get_account(gc), who); 2912 buddies = gaim_find_buddies(gaim_connection_get_account(gc), who);
2929 for (l = buddies; l; l = l->next) { 2913 for (l = buddies; l; l = l->next) {
2930 g = gaim_find_buddys_group(l->data); 2914 g = gaim_find_buddys_group(l->data);
3026 char *gpn, *gpo; 3010 char *gpn, *gpo;
3027 3011
3028 /* Step 0: If they aren't on the server list anyway, 3012 /* Step 0: If they aren't on the server list anyway,
3029 * don't bother letting the server know. 3013 * don't bother letting the server know.
3030 */ 3014 */
3031 if (!g_hash_table_lookup(yd->friends, who)) 3015 if (!yahoo_friend_find(gc, who))
3032 return; 3016 return;
3033 3017
3034 /* If old and new are the same, we would probably 3018 /* If old and new are the same, we would probably
3035 * end up deleting the buddy, which would be bad. 3019 * end up deleting the buddy, which would be bad.
3036 * This might happen because of the charset conversation. 3020 * This might happen because of the charset conversation.