comparison src/protocols/yahoo/yahoo.c @ 7827:ee32e030c9be

[gaim-migrate @ 8479] marv asserts that these character set conversions are more correct than the previous yahoo conversions, which assumed that pretty much everything was UTF-8. I believe him. committer: Tailor Script <tailor@pidgin.im>
author Ethan Blanton <elb@pidgin.im>
date Wed, 10 Dec 2003 16:48:23 +0000
parents 35cd3ef34fb0
children 4bc847ab3bb4
comparison
equal deleted inserted replaced
7826:5ba07997ade3 7827:ee32e030c9be
49 } YahooGetInfoData; 49 } YahooGetInfoData;
50 50
51 51
52 /* #define YAHOO_DEBUG */ 52 /* #define YAHOO_DEBUG */
53 53
54 #define USEROPT_MAIL 0
55
56 #define YAHOO_PAGER_HOST "scs.yahoo.com"
57 #define YAHOO_PAGER_PORT 5050
58 #define YAHOO_PROFILE_URL "http://profiles.yahoo.com/"
59
60
61 static void yahoo_add_buddy(GaimConnection *gc, const char *who, GaimGroup *); 54 static void yahoo_add_buddy(GaimConnection *gc, const char *who, GaimGroup *);
62 55
63 static struct yahoo_friend *yahoo_friend_new(void) 56 static struct yahoo_friend *yahoo_friend_new(void)
64 { 57 {
65 struct yahoo_friend *ret; 58 struct yahoo_friend *ret;
359 break; 352 break;
360 case 19: /* custom message */ 353 case 19: /* custom message */
361 if (f) { 354 if (f) {
362 if (f->msg) 355 if (f->msg)
363 g_free(f->msg); 356 g_free(f->msg);
364 f->msg = g_strdup(pair->value); 357 f->msg = yahoo_string_decode(gc, pair->value, FALSE);
365 } 358 }
366 break; 359 break;
367 case 11: /* this is the buddy's session id */ 360 case 11: /* this is the buddy's session id */
368 break; 361 break;
369 case 17: /* in chat? */ 362 case 17: /* in chat? */
405 f->sms = strtol(pair->value, NULL, 10); 398 f->sms = strtol(pair->value, NULL, 10);
406 yahoo_update_status(gc, name, f); 399 yahoo_update_status(gc, name, f);
407 } 400 }
408 break; 401 break;
409 case 16: /* Custom error message */ 402 case 16: /* Custom error message */
410 gaim_notify_error(gc, NULL, pair->value, NULL); 403 {
404 char *tmp = yahoo_string_decode(gc, pair->value, TRUE);
405 gaim_notify_error(gc, NULL, tmp, NULL);
406 g_free(tmp);
407 }
411 break; 408 break;
412 default: 409 default:
413 gaim_debug(GAIM_DEBUG_ERROR, "yahoo", 410 gaim_debug(GAIM_DEBUG_ERROR, "yahoo",
414 "Unknown status key %d\n", pair->key); 411 "Unknown status key %d\n", pair->key);
415 break; 412 break;
531 528
532 char **lines; 529 char **lines;
533 char **split; 530 char **split;
534 char **buddies; 531 char **buddies;
535 char **tmp, **bud, *norm_bud; 532 char **tmp, **bud, *norm_bud;
533 char *grp = NULL;
536 534
537 if (pkt->id) 535 if (pkt->id)
538 yd->session_id = pkt->id; 536 yd->session_id = pkt->id;
539 537
540 while (l) { 538 while (l) {
573 continue; 571 continue;
574 if (!split[0] || !split[1]) { 572 if (!split[0] || !split[1]) {
575 g_strfreev(split); 573 g_strfreev(split);
576 continue; 574 continue;
577 } 575 }
576 grp = yahoo_string_decode(gc, split[0], FALSE);
578 buddies = g_strsplit(split[1], ",", -1); 577 buddies = g_strsplit(split[1], ",", -1);
579 for (bud = buddies; bud && *bud; bud++) { 578 for (bud = buddies; bud && *bud; bud++) {
580 norm_bud = g_strdup(gaim_normalize(account, *bud)); 579 norm_bud = g_strdup(gaim_normalize(account, *bud));
581 if (!(f = g_hash_table_lookup(yd->friends, norm_bud))) { 580 if (!(f = g_hash_table_lookup(yd->friends, norm_bud))) {
582 f = yahoo_friend_new(); 581 f = yahoo_friend_new();
583 g_hash_table_insert(yd->friends, g_strdup(norm_bud), f); 582 g_hash_table_insert(yd->friends, g_strdup(norm_bud), f);
584 } 583 }
585 if (!(b = gaim_find_buddy(account, norm_bud))) { 584 if (!(b = gaim_find_buddy(account, norm_bud))) {
586 if (!(g = gaim_find_group(split[0]))) { 585 if (!(g = gaim_find_group(grp))) {
587 g = gaim_group_new(split[0]); 586 g = gaim_group_new(grp);
588 gaim_blist_add_group(g, NULL); 587 gaim_blist_add_group(g, NULL);
589 } 588 }
590 b = gaim_buddy_new(account, norm_bud, NULL); 589 b = gaim_buddy_new(account, norm_bud, NULL);
591 gaim_blist_add_buddy(b, NULL, g, NULL); 590 gaim_blist_add_buddy(b, NULL, g, NULL);
592 export = TRUE; 591 export = TRUE;
593 } 592 }
594 593
595 yahoo_do_group_check(account, ht, norm_bud, split[0], &export); 594 yahoo_do_group_check(account, ht, norm_bud, grp, &export);
596 g_free(norm_bud); 595 g_free(norm_bud);
597 } 596 }
598 g_strfreev(buddies); 597 g_strfreev(buddies);
599 g_strfreev(split); 598 g_strfreev(split);
599 g_free(grp);
600 } 600 }
601 g_strfreev(lines); 601 g_strfreev(lines);
602 602
603 g_string_free(yd->tmp_serv_blist, TRUE); 603 g_string_free(yd->tmp_serv_blist, TRUE);
604 yd->tmp_serv_blist = NULL; 604 yd->tmp_serv_blist = NULL;
684 yahoo_update_status(gc, from, f); 684 yahoo_update_status(gc, from, f);
685 } 685 }
686 } 686 }
687 } 687 }
688 688
689
690 struct _yahoo_im {
691 char *from;
692 int time;
693 int utf8;
694 char *msg;
695 };
696
689 static void yahoo_process_message(GaimConnection *gc, struct yahoo_packet *pkt) 697 static void yahoo_process_message(GaimConnection *gc, struct yahoo_packet *pkt)
690 { 698 {
691 char *msg = NULL;
692 char *from = NULL;
693 time_t tm = time(NULL);
694 GSList *l = pkt->hash; 699 GSList *l = pkt->hash;
700 GSList *list = NULL;
701 struct _yahoo_im *im = NULL;
695 702
696 if (pkt->status <= 1 || pkt->status == 5) { 703 if (pkt->status <= 1 || pkt->status == 5) {
697 while (l) { 704 while (l) {
698 struct yahoo_pair *pair = l->data; 705 struct yahoo_pair *pair = l->data;
699 if (pair->key == 4) 706 if (pair->key == 4) {
700 from = pair->value; 707 im = g_new0(struct _yahoo_im, 1);
708 list = g_slist_append(list, im);
709 im->from = pair->value;
710 im->time = time(NULL);
711 }
712 if (pair->key == 97)
713 if (im)
714 im->utf8 = strtol(pair->value, NULL, 10);
701 if (pair->key == 15) 715 if (pair->key == 15)
702 tm = strtol(pair->value, NULL, 10); 716 if (im)
717 im->time = strtol(pair->value, NULL, 10);
703 if (pair->key == 14) { 718 if (pair->key == 14) {
704 char *m; 719 if (im)
705 720 im->msg = pair->value;
706 msg = pair->value;
707
708 gaim_str_strip_cr(msg);
709 m = yahoo_codes_to_html(msg);
710 serv_got_im(gc, from, m, 0, tm);
711 g_free(m);
712
713 tm = time(NULL);
714 } 721 }
715 l = l->next; 722 l = l->next;
716 } 723 }
717 } else if (pkt->status == 2) { 724 } else if (pkt->status == 2) {
718 gaim_notify_error(gc, NULL, 725 gaim_notify_error(gc, NULL,
719 _("Your Yahoo! message did not get sent."), NULL); 726 _("Your Yahoo! message did not get sent."), NULL);
720 } 727 }
728
729 for (l = list; l; l = l->next) {
730 char *m, *m2;
731 im = l->data;
732
733 if (!im->from || !im->msg) {
734 g_free(im);
735 continue;
736 }
737
738 m = yahoo_string_decode(gc, im->msg, im->utf8);
739 gaim_str_strip_cr(m);
740 m2 = yahoo_codes_to_html(m);
741 g_free(m);
742 serv_got_im(gc, im->from, m2, 0, im->time);
743 g_free(m2);
744 g_free(im);
745 }
746 g_slist_free(list);
721 } 747 }
722 748
723 static void yahoo_buddy_added_us(GaimConnection *gc, struct yahoo_packet *pkt) { 749 static void yahoo_buddy_added_us(GaimConnection *gc, struct yahoo_packet *pkt) {
724 char *id = NULL; 750 char *id = NULL;
725 char *who = NULL; 751 char *who = NULL;
726 char *msg = NULL; 752 char *msg = NULL, *tmpmsg = NULL;
727 GSList *l = pkt->hash; 753 GSList *l = pkt->hash;
728 754
729 while (l) { 755 while (l) {
730 struct yahoo_pair *pair = l->data; 756 struct yahoo_pair *pair = l->data;
731 757
743 break; 769 break;
744 } 770 }
745 l = l->next; 771 l = l->next;
746 } 772 }
747 773
748 if (id) 774 if (id) {
749 gaim_account_notify_added(gc->account, id, who, NULL, msg); 775 if (msg)
776 tmpmsg = yahoo_string_decode(gc, msg, FALSE);
777 gaim_account_notify_added(gc->account, id, who, NULL, tmpmsg);
778 if (tmpmsg)
779 g_free(tmpmsg);
780 }
750 } 781 }
751 782
752 static void yahoo_buddy_denied_our_add(GaimConnection *gc, struct yahoo_packet *pkt) 783 static void yahoo_buddy_denied_our_add(GaimConnection *gc, struct yahoo_packet *pkt)
753 { 784 {
754 char *who = NULL; 785 char *who = NULL;
770 } 801 }
771 l = l->next; 802 l = l->next;
772 } 803 }
773 804
774 if (who) { 805 if (who) {
806 char *msg2;
775 buf = g_string_sized_new(0); 807 buf = g_string_sized_new(0);
776 if (!msg) 808 if (!msg) {
777 g_string_printf(buf, _("%s has (retroactively) denied your request to add them to your list."), who); 809 g_string_printf(buf, _("%s has (retroactively) denied your request to add them to your list."), who);
778 else 810 } else {
779 g_string_printf(buf, _("%s has (retroactively) denied your request to add them to your list for the following reason: %s."), who, msg); 811 msg2 = yahoo_string_decode(gc, msg, FALSE);
812 g_string_printf(buf, _("%s has (retroactively) denied your request to add them to your list for the following reason: %s."), who, msg2);
813 g_free(msg2);
814 }
780 gaim_notify_info(gc, NULL, _("Add buddy rejected"), buf->str); 815 gaim_notify_info(gc, NULL, _("Add buddy rejected"), buf->str);
781 g_string_free(buf, TRUE); 816 g_string_free(buf, TRUE);
782 g_hash_table_remove(yd->friends, who); 817 g_hash_table_remove(yd->friends, who);
783 serv_got_update(gc, who, 0, 0, 0, 0, 0); 818 serv_got_update(gc, who, 0, 0, 0, 0, 0);
784 } 819 }
1549 static void yahoo_process_addbuddy(GaimConnection *gc, struct yahoo_packet *pkt) 1584 static void yahoo_process_addbuddy(GaimConnection *gc, struct yahoo_packet *pkt)
1550 { 1585 {
1551 int err = 0; 1586 int err = 0;
1552 char *who = NULL; 1587 char *who = NULL;
1553 char *group = NULL; 1588 char *group = NULL;
1589 char *decoded_group;
1554 char *buf; 1590 char *buf;
1555 struct yahoo_friend *f; 1591 struct yahoo_friend *f;
1556 struct yahoo_data *yd = gc->proto_data; 1592 struct yahoo_data *yd = gc->proto_data;
1557 GSList *l = pkt->hash; 1593 GSList *l = pkt->hash;
1558 1594
1586 yahoo_update_status(gc, who, f); 1622 yahoo_update_status(gc, who, f);
1587 } 1623 }
1588 return; 1624 return;
1589 } 1625 }
1590 1626
1627 decoded_group = yahoo_string_decode(gc, group, FALSE);
1591 buf = g_strdup_printf(_("Could not add buddy %s to group %s to the server list on account %s."), 1628 buf = g_strdup_printf(_("Could not add buddy %s to group %s to the server list on account %s."),
1592 who, group, gaim_connection_get_display_name(gc)); 1629 who, decoded_group, gaim_connection_get_display_name(gc));
1593 gaim_notify_error(gc, NULL, _("Could not add buddy to server list"), buf); 1630 gaim_notify_error(gc, NULL, _("Could not add buddy to server list"), buf);
1594 g_free(buf); 1631 g_free(buf);
1632 g_free(decoded_group);
1595 } 1633 }
1596 1634
1597 static void yahoo_packet_process(GaimConnection *gc, struct yahoo_packet *pkt) 1635 static void yahoo_packet_process(GaimConnection *gc, struct yahoo_packet *pkt)
1598 { 1636 {
1599 switch (pkt->service) { 1637 switch (pkt->service) {
1979 yd->friends = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, yahoo_friend_free); 2017 yd->friends = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, yahoo_friend_free);
1980 yd->confs = NULL; 2018 yd->confs = NULL;
1981 yd->conf_id = 2; 2019 yd->conf_id = 2;
1982 2020
1983 #ifndef YAHOO_WEBMESSENGER 2021 #ifndef YAHOO_WEBMESSENGER
1984 if (gaim_proxy_connect(account, gaim_account_get_string(account, "server", YAHOO_PAGER_HOST), 2022
1985 gaim_account_get_int(account, "port", YAHOO_PAGER_PORT), 2023 if (gaim_proxy_connect(account,
1986 yahoo_got_connected, gc) != 0) { 2024 gaim_account_get_string(account, "server", YAHOO_PAGER_HOST),
2025 gaim_account_get_int(account, "port", YAHOO_PAGER_PORT),
2026 yahoo_got_connected, gc) != 0)
2027 {
1987 gaim_connection_error(gc, _("Connection problem")); 2028 gaim_connection_error(gc, _("Connection problem"));
1988 return; 2029 return;
1989 } 2030 }
2031
1990 #else 2032 #else
1991 gaim_url_fetch(WEBMESSENGER_URL, TRUE, "Gaim/" VERSION, FALSE, 2033 gaim_url_fetch(WEBMESSENGER_URL, TRUE, "Gaim/" VERSION, FALSE,
1992 yahoo_login_page_cb, gc); 2034 yahoo_login_page_cb, gc);
1993 #endif 2035 #endif
1994 2036
2312 static int yahoo_send_im(GaimConnection *gc, const char *who, const char *what, GaimConvImFlags flags) 2354 static int yahoo_send_im(GaimConnection *gc, const char *who, const char *what, GaimConvImFlags flags)
2313 { 2355 {
2314 struct yahoo_data *yd = gc->proto_data; 2356 struct yahoo_data *yd = gc->proto_data;
2315 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_MESSAGE, YAHOO_STATUS_OFFLINE, 0); 2357 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_MESSAGE, YAHOO_STATUS_OFFLINE, 0);
2316 char *msg = yahoo_html_to_codes(what); 2358 char *msg = yahoo_html_to_codes(what);
2359 char *msg2;
2360 gboolean utf8 = TRUE;
2361
2362 msg2 = yahoo_string_encode(gc, msg, &utf8);
2317 2363
2318 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); 2364 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc));
2319 yahoo_packet_hash(pkt, 5, who); 2365 yahoo_packet_hash(pkt, 5, who);
2320 yahoo_packet_hash(pkt, 14, msg); 2366 if (utf8)
2321 yahoo_packet_hash(pkt, 97, "1"); 2367 yahoo_packet_hash(pkt, 97, "1");
2368 yahoo_packet_hash(pkt, 14, msg2);
2369
2322 2370
2323 yahoo_send_packet(yd, pkt); 2371 yahoo_send_packet(yd, pkt);
2324 2372
2325 yahoo_packet_free(pkt); 2373 yahoo_packet_free(pkt);
2326 2374
2327 g_free(msg); 2375 g_free(msg);
2376 g_free(msg2);
2328 2377
2329 return 1; 2378 return 1;
2330 } 2379 }
2331 2380
2332 int yahoo_send_typing(GaimConnection *gc, const char *who, int typ) 2381 int yahoo_send_typing(GaimConnection *gc, const char *who, int typ)
2351 { 2400 {
2352 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; 2401 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
2353 struct yahoo_packet *pkt; 2402 struct yahoo_packet *pkt;
2354 int service; 2403 int service;
2355 char s[4]; 2404 char s[4];
2405 char *conv_msg = NULL;
2356 2406
2357 if (gc->away) { 2407 if (gc->away) {
2358 g_free(gc->away); 2408 g_free(gc->away);
2359 gc->away = NULL; 2409 gc->away = NULL;
2360 } 2410 }
2406 2456
2407 pkt = yahoo_packet_new(service, YAHOO_STATUS_AVAILABLE, 0); 2457 pkt = yahoo_packet_new(service, YAHOO_STATUS_AVAILABLE, 0);
2408 g_snprintf(s, sizeof(s), "%d", yd->current_status); 2458 g_snprintf(s, sizeof(s), "%d", yd->current_status);
2409 yahoo_packet_hash(pkt, 10, s); 2459 yahoo_packet_hash(pkt, 10, s);
2410 2460
2411 if ((yd->current_status == YAHOO_STATUS_CUSTOM) && gc->away) 2461 if ((yd->current_status == YAHOO_STATUS_CUSTOM) && gc->away) {
2412 yahoo_packet_hash(pkt, 19, gc->away); 2462 conv_msg = yahoo_string_encode(gc, gc->away, NULL);
2463 yahoo_packet_hash(pkt, 19, conv_msg);
2464 }
2413 2465
2414 if ((yd->current_status != YAHOO_STATUS_AVAILABLE) && 2466 if ((yd->current_status != YAHOO_STATUS_AVAILABLE) &&
2415 (yd->current_status != YAHOO_STATUS_IDLE)) { 2467 (yd->current_status != YAHOO_STATUS_IDLE)) {
2416 if (gc->is_idle) 2468 if (gc->is_idle)
2417 yahoo_packet_hash(pkt, 47, "2"); 2469 yahoo_packet_hash(pkt, 47, "2");
2419 yahoo_packet_hash(pkt, 47, "1"); 2471 yahoo_packet_hash(pkt, 47, "1");
2420 } 2472 }
2421 2473
2422 yahoo_send_packet(yd, pkt); 2474 yahoo_send_packet(yd, pkt);
2423 yahoo_packet_free(pkt); 2475 yahoo_packet_free(pkt);
2476 if (conv_msg)
2477 g_free(conv_msg);
2424 } 2478 }
2425 2479
2426 static void yahoo_set_idle(GaimConnection *gc, int idle) 2480 static void yahoo_set_idle(GaimConnection *gc, int idle)
2427 { 2481 {
2428 struct yahoo_data *yd = gc->proto_data; 2482 struct yahoo_data *yd = gc->proto_data;
2429 struct yahoo_packet *pkt = NULL; 2483 struct yahoo_packet *pkt = NULL;
2484 char *msg = NULL;
2430 2485
2431 if (idle && yd->current_status == YAHOO_STATUS_AVAILABLE) { 2486 if (idle && yd->current_status == YAHOO_STATUS_AVAILABLE) {
2432 pkt = yahoo_packet_new(YAHOO_SERVICE_ISAWAY, YAHOO_STATUS_AVAILABLE, 0); 2487 pkt = yahoo_packet_new(YAHOO_SERVICE_ISAWAY, YAHOO_STATUS_AVAILABLE, 0);
2433 yd->current_status = YAHOO_STATUS_IDLE; 2488 yd->current_status = YAHOO_STATUS_IDLE;
2434 } else if (!idle && yd->current_status == YAHOO_STATUS_IDLE) { 2489 } else if (!idle && yd->current_status == YAHOO_STATUS_IDLE) {
2441 if (pkt) { 2496 if (pkt) {
2442 char buf[4]; 2497 char buf[4];
2443 g_snprintf(buf, sizeof(buf), "%d", yd->current_status); 2498 g_snprintf(buf, sizeof(buf), "%d", yd->current_status);
2444 yahoo_packet_hash(pkt, 10, buf); 2499 yahoo_packet_hash(pkt, 10, buf);
2445 if (gc->away && yd->current_status == YAHOO_STATUS_CUSTOM) { 2500 if (gc->away && yd->current_status == YAHOO_STATUS_CUSTOM) {
2446 yahoo_packet_hash(pkt, 19, gc->away); 2501 msg = yahoo_string_encode(gc, gc->away, NULL);
2502 yahoo_packet_hash(pkt, 19, msg);
2447 if (idle) 2503 if (idle)
2448 yahoo_packet_hash(pkt, 47, "2"); 2504 yahoo_packet_hash(pkt, 47, "2");
2449 else 2505 else
2450 yahoo_packet_hash(pkt, 47, "1"); /* fixme when available messages are possible */ 2506 yahoo_packet_hash(pkt, 47, "1"); /* fixme when available messages are possible */
2451 } else if (idle && (yd->current_status != YAHOO_STATUS_AVAILABLE) && 2507 } else if (idle && (yd->current_status != YAHOO_STATUS_AVAILABLE) &&
2457 } 2513 }
2458 2514
2459 yahoo_send_packet(yd, pkt); 2515 yahoo_send_packet(yd, pkt);
2460 yahoo_packet_free(pkt); 2516 yahoo_packet_free(pkt);
2461 } 2517 }
2518 if (msg)
2519 g_free(msg);
2462 } 2520 }
2463 2521
2464 static GList *yahoo_away_states(GaimConnection *gc) 2522 static GList *yahoo_away_states(GaimConnection *gc)
2465 { 2523 {
2466 GList *m = NULL; 2524 GList *m = NULL;
2501 { 2559 {
2502 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; 2560 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
2503 struct yahoo_packet *pkt; 2561 struct yahoo_packet *pkt;
2504 GaimGroup *g; 2562 GaimGroup *g;
2505 char *group = NULL; 2563 char *group = NULL;
2564 char *grp2 = NULL;
2506 2565
2507 if (!yd->logged_in) 2566 if (!yd->logged_in)
2508 return; 2567 return;
2509 2568
2510 if (foo) 2569 if (foo)
2515 group = g->name; 2574 group = g->name;
2516 else 2575 else
2517 group = "Buddies"; 2576 group = "Buddies";
2518 } 2577 }
2519 2578
2579 grp2 = yahoo_string_encode(gc, group, NULL);
2520 pkt = yahoo_packet_new(YAHOO_SERVICE_ADDBUDDY, YAHOO_STATUS_AVAILABLE, 0); 2580 pkt = yahoo_packet_new(YAHOO_SERVICE_ADDBUDDY, YAHOO_STATUS_AVAILABLE, 0);
2521 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); 2581 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc));
2522 yahoo_packet_hash(pkt, 7, who); 2582 yahoo_packet_hash(pkt, 7, who);
2523 yahoo_packet_hash(pkt, 65, group); 2583 yahoo_packet_hash(pkt, 65, grp2);
2524 yahoo_packet_hash(pkt, 14, ""); 2584 yahoo_packet_hash(pkt, 14, "");
2525 yahoo_send_packet(yd, pkt); 2585 yahoo_send_packet(yd, pkt);
2526 yahoo_packet_free(pkt); 2586 yahoo_packet_free(pkt);
2587 g_free(grp2);
2527 } 2588 }
2528 2589
2529 static void yahoo_remove_buddy(GaimConnection *gc, const char *who, const char *group) 2590 static void yahoo_remove_buddy(GaimConnection *gc, const char *who, const char *group)
2530 { 2591 {
2531 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; 2592 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
2532 struct yahoo_friend *f; 2593 struct yahoo_friend *f;
2533 struct yahoo_packet *pkt; 2594 struct yahoo_packet *pkt;
2534 GSList *buddies, *l; 2595 GSList *buddies, *l;
2535 GaimGroup *g; 2596 GaimGroup *g;
2536 gboolean remove = TRUE; 2597 gboolean remove = TRUE;
2598 char *cg;
2537 2599
2538 if (!(f = g_hash_table_lookup(yd->friends, who))) 2600 if (!(f = g_hash_table_lookup(yd->friends, who)))
2539 return; 2601 return;
2540 2602
2541 buddies = gaim_find_buddies(gaim_connection_get_account(gc), who); 2603 buddies = gaim_find_buddies(gaim_connection_get_account(gc), who);
2550 g_slist_free(buddies); 2612 g_slist_free(buddies);
2551 2613
2552 if (remove) 2614 if (remove)
2553 g_hash_table_remove(yd->friends, who); 2615 g_hash_table_remove(yd->friends, who);
2554 2616
2617 cg = yahoo_string_encode(gc, group, NULL);
2555 pkt = yahoo_packet_new(YAHOO_SERVICE_REMBUDDY, YAHOO_STATUS_AVAILABLE, 0); 2618 pkt = yahoo_packet_new(YAHOO_SERVICE_REMBUDDY, YAHOO_STATUS_AVAILABLE, 0);
2556 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); 2619 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc));
2557 yahoo_packet_hash(pkt, 7, who); 2620 yahoo_packet_hash(pkt, 7, who);
2558 yahoo_packet_hash(pkt, 65, group); 2621 yahoo_packet_hash(pkt, 65, cg);
2559 yahoo_send_packet(yd, pkt); 2622 yahoo_send_packet(yd, pkt);
2560 yahoo_packet_free(pkt); 2623 yahoo_packet_free(pkt);
2624 g_free(cg);
2561 } 2625 }
2562 2626
2563 static void yahoo_add_deny(GaimConnection *gc, const char *who) { 2627 static void yahoo_add_deny(GaimConnection *gc, const char *who) {
2564 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; 2628 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
2565 struct yahoo_packet *pkt; 2629 struct yahoo_packet *pkt;
2882 static void yahoo_change_buddys_group(GaimConnection *gc, const char *who, 2946 static void yahoo_change_buddys_group(GaimConnection *gc, const char *who,
2883 const char *old_group, const char *new_group) 2947 const char *old_group, const char *new_group)
2884 { 2948 {
2885 struct yahoo_data *yd = gc->proto_data; 2949 struct yahoo_data *yd = gc->proto_data;
2886 struct yahoo_packet *pkt; 2950 struct yahoo_packet *pkt;
2951 char *gpn, *gpo;
2887 2952
2888 /* Step 0: If they aren't on the server list anyway, 2953 /* Step 0: If they aren't on the server list anyway,
2889 * don't bother letting the server know. 2954 * don't bother letting the server know.
2890 */ 2955 */
2891 if (!g_hash_table_lookup(yd->friends, who)) 2956 if (!g_hash_table_lookup(yd->friends, who))
2892 return; 2957 return;
2893 2958
2959 /* If old and new are the same, we would probably
2960 * end up deleting the buddy, which would be bad.
2961 * This might happen because of the charset conversation.
2962 */
2963 gpn = yahoo_string_encode(gc, new_group, NULL);
2964 gpo = yahoo_string_encode(gc, old_group, NULL);
2965 if (!strcmp(gpn, gpo)) {
2966 g_free(gpn);
2967 g_free(gpo);
2968 return;
2969 }
2970
2894 /* Step 1: Add buddy to new group. */ 2971 /* Step 1: Add buddy to new group. */
2895 pkt = yahoo_packet_new(YAHOO_SERVICE_ADDBUDDY, YAHOO_STATUS_AVAILABLE, 0); 2972 pkt = yahoo_packet_new(YAHOO_SERVICE_ADDBUDDY, YAHOO_STATUS_AVAILABLE, 0);
2896 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); 2973 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc));
2897 yahoo_packet_hash(pkt, 7, who); 2974 yahoo_packet_hash(pkt, 7, who);
2898 yahoo_packet_hash(pkt, 65, new_group); 2975 yahoo_packet_hash(pkt, 65, gpn);
2899 yahoo_packet_hash(pkt, 14, ""); 2976 yahoo_packet_hash(pkt, 14, "");
2900 yahoo_send_packet(yd, pkt); 2977 yahoo_send_packet(yd, pkt);
2901 yahoo_packet_free(pkt); 2978 yahoo_packet_free(pkt);
2902 2979
2903 /* Step 2: Remove buddy from old group */ 2980 /* Step 2: Remove buddy from old group */
2904 pkt = yahoo_packet_new(YAHOO_SERVICE_REMBUDDY, YAHOO_STATUS_AVAILABLE, 0); 2981 pkt = yahoo_packet_new(YAHOO_SERVICE_REMBUDDY, YAHOO_STATUS_AVAILABLE, 0);
2905 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); 2982 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc));
2906 yahoo_packet_hash(pkt, 7, who); 2983 yahoo_packet_hash(pkt, 7, who);
2907 yahoo_packet_hash(pkt, 65, old_group); 2984 yahoo_packet_hash(pkt, 65, gpo);
2908 yahoo_send_packet(yd, pkt); 2985 yahoo_send_packet(yd, pkt);
2909 yahoo_packet_free(pkt); 2986 yahoo_packet_free(pkt);
2987 g_free(gpn);
2988 g_free(gpo);
2910 } 2989 }
2911 2990
2912 static void yahoo_rename_group(GaimConnection *gc, const char *old_group, 2991 static void yahoo_rename_group(GaimConnection *gc, const char *old_group,
2913 const char *new_group, GList *whocares) 2992 const char *new_group, GList *whocares)
2914 { 2993 {
2915 struct yahoo_data *yd = gc->proto_data; 2994 struct yahoo_data *yd = gc->proto_data;
2916 struct yahoo_packet *pkt; 2995 struct yahoo_packet *pkt;
2996 char *gpn, *gpo;
2997
2998 gpn = yahoo_string_encode(gc, new_group, NULL);
2999 gpo = yahoo_string_encode(gc, old_group, NULL);
3000 if (!strcmp(gpn, gpo)) {
3001 g_free(gpn);
3002 g_free(gpo);
3003 return;
3004 }
2917 3005
2918 pkt = yahoo_packet_new(YAHOO_SERVICE_GROUPRENAME, YAHOO_STATUS_AVAILABLE, 0); 3006 pkt = yahoo_packet_new(YAHOO_SERVICE_GROUPRENAME, YAHOO_STATUS_AVAILABLE, 0);
2919 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); 3007 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc));
2920 yahoo_packet_hash(pkt, 65, old_group); 3008 yahoo_packet_hash(pkt, 65, gpo);
2921 yahoo_packet_hash(pkt, 67, new_group); 3009 yahoo_packet_hash(pkt, 67, gpn);
2922 yahoo_send_packet(yd, pkt); 3010 yahoo_send_packet(yd, pkt);
2923 yahoo_packet_free(pkt); 3011 yahoo_packet_free(pkt);
3012 g_free(gpn);
3013 g_free(gpo);
2924 } 3014 }
2925 3015
2926 #if 0 3016 #if 0
2927 static gboolean yahoo_has_send_file(GaimConnection *gc, const char *who) 3017 static gboolean yahoo_has_send_file(GaimConnection *gc, const char *who)
2928 { 3018 {
3024 static void 3114 static void
3025 init_plugin(GaimPlugin *plugin) 3115 init_plugin(GaimPlugin *plugin)
3026 { 3116 {
3027 GaimAccountOption *option; 3117 GaimAccountOption *option;
3028 3118
3029 option = gaim_account_option_string_new(_("Pager host"), "server", 3119 option = gaim_account_option_string_new(_("Pager host"), "server", YAHOO_PAGER_HOST);
3030 YAHOO_PAGER_HOST); 3120 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
3031 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, 3121
3032 option); 3122 option = gaim_account_option_int_new(_("Pager port"), "port", YAHOO_PAGER_PORT);
3033 3123 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
3034 option = gaim_account_option_int_new(_("Pager port"), "port",
3035 YAHOO_PAGER_PORT);
3036 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
3037 option);
3038 3124
3039 option = gaim_account_option_string_new(_("File transfer host"), "xfer_host", YAHOO_XFER_HOST); 3125 option = gaim_account_option_string_new(_("File transfer host"), "xfer_host", YAHOO_XFER_HOST);
3040 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 3126 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
3041 3127
3042 option = gaim_account_option_int_new(_("File transfer port"), "xfer_port", YAHOO_XFER_PORT); 3128 option = gaim_account_option_int_new(_("File transfer port"), "xfer_port", YAHOO_XFER_PORT);