comparison src/protocols/oscar/oscar.c @ 13873:77a50840d9e2

[gaim-migrate @ 16344] Fix some bugs that Relan (resver) tracked down. Basically we were attempting to convert various strings from some encoding to UTF8 twice. The strings were mostly in ICQ buddy info. He submitted sf patch #1503955, but I like my approach better. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Mon, 26 Jun 2006 03:55:24 +0000
parents 84f2675cf87f
children eb20e674ccf2
comparison
equal deleted inserted replaced
13872:d1da27a099d2 13873:77a50840d9e2
724 else 724 else
725 return g_strdup_printf(_("Online")); 725 return g_strdup_printf(_("Online"));
726 } 726 }
727 727
728 static void 728 static void
729 oscar_string_append(GaimAccount *account, GString *str, const char *newline, 729 oscar_string_append(GString *str, const char *newline,
730 const char *name, const char *value)
731 {
732 if (value && value[0]) {
733 g_string_append_printf(str, "%s<b>%s:</b> %s", newline, name, value);
734 }
735 }
736
737 static void
738 oscar_string_convert_and_append(GaimAccount *account, GString *str, const char *newline,
730 const char *name, const char *value) 739 const char *name, const char *value)
731 { 740 {
732 gchar *utf8; 741 gchar *utf8;
733 742
734 if (value && value[0] && (utf8 = oscar_utf8_try_convert(account, value))) { 743 if (value && value[0] && (utf8 = oscar_utf8_try_convert(account, value))) {
770 779
771 if (b != NULL) { 780 if (b != NULL) {
772 if (gaim_presence_is_online(presence)) { 781 if (gaim_presence_is_online(presence)) {
773 if (aim_sn_is_icq(b->name)) { 782 if (aim_sn_is_icq(b->name)) {
774 GaimStatus *status = gaim_presence_get_active_status(presence); 783 GaimStatus *status = gaim_presence_get_active_status(presence);
775 oscar_string_append(gc->account, str, newline, _("Status"), 784 oscar_string_append(str, newline, _("Status"),
776 gaim_status_get_name(status)); 785 gaim_status_get_name(status));
777 } 786 }
778 } else { 787 } else {
779 tmp = aim_ssi_itemlist_findparentname(od->ssi.local, b->name); 788 tmp = aim_ssi_itemlist_findparentname(od->ssi.local, b->name);
780 if (aim_ssi_waitingforauth(od->ssi.local, tmp, b->name)) 789 if (aim_ssi_waitingforauth(od->ssi.local, tmp, b->name))
781 oscar_string_append(gc->account, str, newline, _("Status"), 790 oscar_string_append(str, newline, _("Status"),
782 _("Not Authorized")); 791 _("Not Authorized"));
783 else 792 else
784 oscar_string_append(gc->account, str, newline, _("Status"), 793 oscar_string_append(str, newline, _("Status"),
785 _("Offline")); 794 _("Offline"));
786 } 795 }
787 } 796 }
788 797
789 if ((bi != NULL) && (bi->ipaddr != 0)) { 798 if ((bi != NULL) && (bi->ipaddr != 0)) {
790 tmp = g_strdup_printf("%hhu.%hhu.%hhu.%hhu", 799 tmp = g_strdup_printf("%hhu.%hhu.%hhu.%hhu",
791 (bi->ipaddr & 0xff000000) >> 24, 800 (bi->ipaddr & 0xff000000) >> 24,
792 (bi->ipaddr & 0x00ff0000) >> 16, 801 (bi->ipaddr & 0x00ff0000) >> 16,
793 (bi->ipaddr & 0x0000ff00) >> 8, 802 (bi->ipaddr & 0x0000ff00) >> 8,
794 (bi->ipaddr & 0x000000ff)); 803 (bi->ipaddr & 0x000000ff));
795 oscar_string_append(gc->account, str, newline, _("IP Address"), tmp); 804 oscar_string_append(str, newline, _("IP Address"), tmp);
796 g_free(tmp); 805 g_free(tmp);
797 } 806 }
798 807
799 808
800 if ((userinfo != NULL) && (userinfo->warnlevel != 0)) { 809 if ((userinfo != NULL) && (userinfo->warnlevel != 0)) {
801 tmp = g_strdup_printf("%d", (int)(userinfo->warnlevel/10.0 + .5)); 810 tmp = g_strdup_printf("%d", (int)(userinfo->warnlevel/10.0 + .5));
802 oscar_string_append(gc->account, str, newline, _("Warning Level"), tmp); 811 oscar_string_append(str, newline, _("Warning Level"), tmp);
803 g_free(tmp); 812 g_free(tmp);
804 } 813 }
805 814
806 if ((b != NULL) && (b->name != NULL) && (g != NULL) && (g->name != NULL)) { 815 if ((b != NULL) && (b->name != NULL) && (g != NULL) && (g->name != NULL)) {
807 tmp = aim_ssi_getcomment(od->ssi.local, g->name, b->name); 816 tmp = aim_ssi_getcomment(od->ssi.local, g->name, b->name);
808 if (tmp != NULL) { 817 if (tmp != NULL) {
809 char *tmp2 = g_markup_escape_text(tmp, strlen(tmp)); 818 char *tmp2 = g_markup_escape_text(tmp, strlen(tmp));
810 g_free(tmp); 819 g_free(tmp);
811 oscar_string_append(gc->account, str, newline, _("Buddy Comment"), tmp2); 820 oscar_string_convert_and_append(account, str, newline, _("Buddy Comment"), tmp2);
812 g_free(tmp2); 821 g_free(tmp2);
813 } 822 }
814 } 823 }
815 } 824 }
816 825
2822 g_string_append_printf(str, "<b>%s:</b> %s", _("Screen Name"), userinfo->sn); 2831 g_string_append_printf(str, "<b>%s:</b> %s", _("Screen Name"), userinfo->sn);
2823 g_string_append_printf(str, "\n<br><b>%s</b>: %d%%", _("Warning Level"), (int)((userinfo->warnlevel/10.0) + 0.5)); 2832 g_string_append_printf(str, "\n<br><b>%s</b>: %d%%", _("Warning Level"), (int)((userinfo->warnlevel/10.0) + 0.5));
2824 2833
2825 if (userinfo->present & AIM_USERINFO_PRESENT_ONLINESINCE) { 2834 if (userinfo->present & AIM_USERINFO_PRESENT_ONLINESINCE) {
2826 time_t t = userinfo->onlinesince - od->timeoffset; 2835 time_t t = userinfo->onlinesince - od->timeoffset;
2827 oscar_string_append(gc->account, str, "\n<br>", _("Online Since"), gaim_date_format_full(localtime(&t))); 2836 oscar_string_append(str, "\n<br>", _("Online Since"), gaim_date_format_full(localtime(&t)));
2828 } 2837 }
2829 2838
2830 if (userinfo->present & AIM_USERINFO_PRESENT_MEMBERSINCE) { 2839 if (userinfo->present & AIM_USERINFO_PRESENT_MEMBERSINCE) {
2831 time_t t = userinfo->membersince - od->timeoffset; 2840 time_t t = userinfo->membersince - od->timeoffset;
2832 oscar_string_append(gc->account, str, "\n<br>", _("Member Since"), gaim_date_format_full(localtime(&t))); 2841 oscar_string_append(str, "\n<br>", _("Member Since"), gaim_date_format_full(localtime(&t)));
2833 } 2842 }
2834 2843
2835 if (userinfo->capabilities != 0) { 2844 if (userinfo->capabilities != 0) {
2836 tmp = oscar_caps_to_string(userinfo->capabilities); 2845 tmp = oscar_caps_to_string(userinfo->capabilities);
2837 oscar_string_append(gc->account, str, "\n<br>", _("Capabilities"), tmp); 2846 oscar_string_append(str, "\n<br>", _("Capabilities"), tmp);
2838 g_free(tmp); 2847 g_free(tmp);
2839 } 2848 }
2840 2849
2841 if (userinfo->present & AIM_USERINFO_PRESENT_IDLE) { 2850 if (userinfo->present & AIM_USERINFO_PRESENT_IDLE) {
2842 tmp = gaim_str_seconds_to_string(userinfo->idletime*60); 2851 tmp = gaim_str_seconds_to_string(userinfo->idletime*60);
2843 oscar_string_append(gc->account, str, "\n<br>", _("Idle"), tmp); 2852 oscar_string_append(str, "\n<br>", _("Idle"), tmp);
2844 g_free(tmp); 2853 g_free(tmp);
2845 } 2854 }
2846 2855
2847 oscar_string_append_info(gc, str, "\n<br>", NULL, userinfo); 2856 oscar_string_append_info(gc, str, "\n<br>", NULL, userinfo);
2848 2857
2850 if ((userinfo->status != NULL) && !(userinfo->flags & AIM_FLAG_AWAY)) 2859 if ((userinfo->status != NULL) && !(userinfo->flags & AIM_FLAG_AWAY))
2851 { 2860 {
2852 if (userinfo->status[0] != '\0') 2861 if (userinfo->status[0] != '\0')
2853 tmp = oscar_encoding_to_utf8(userinfo->status_encoding, 2862 tmp = oscar_encoding_to_utf8(userinfo->status_encoding,
2854 userinfo->status, userinfo->status_len); 2863 userinfo->status, userinfo->status_len);
2855 oscar_string_append(gc->account, str, "\n<br>", _("Available Message"), tmp); 2864 oscar_string_convert_and_append(account, str, "\n<br>", _("Available Message"), tmp);
2856 g_free(tmp); 2865 g_free(tmp);
2857 } 2866 }
2858 2867
2859 /* Away message */ 2868 /* Away message */
2860 if ((userinfo->flags & AIM_FLAG_AWAY) && (userinfo->away_len > 0) && (userinfo->away != NULL) && (userinfo->away_encoding != NULL)) { 2869 if ((userinfo->flags & AIM_FLAG_AWAY) && (userinfo->away_len > 0) && (userinfo->away != NULL) && (userinfo->away_encoding != NULL)) {
3596 return 1; 3605 return 1;
3597 } 3606 }
3598 3607
3599 static int gaim_icqinfo(OscarData *od, FlapConnection *conn, FlapFrame *fr, ...) 3608 static int gaim_icqinfo(OscarData *od, FlapConnection *conn, FlapFrame *fr, ...)
3600 { 3609 {
3601 GaimConnection *gc = od->gc; 3610 GaimConnection *gc;
3611 GaimAccount *account;
3602 GaimBuddy *buddy; 3612 GaimBuddy *buddy;
3603 struct buddyinfo *bi = NULL; 3613 struct buddyinfo *bi;
3604 gchar who[16]; 3614 gchar who[16];
3605 GString *str; 3615 GString *str;
3606 gchar *utf8; 3616 gchar *utf8;
3607 const gchar *alias; 3617 const gchar *alias;
3608 va_list ap; 3618 va_list ap;
3609 struct aim_icq_info *info; 3619 struct aim_icq_info *info;
3610 3620
3621 gc = od->gc;
3622 account = gaim_connection_get_account(gc);
3623
3611 va_start(ap, fr); 3624 va_start(ap, fr);
3612 info = va_arg(ap, struct aim_icq_info *); 3625 info = va_arg(ap, struct aim_icq_info *);
3613 va_end(ap); 3626 va_end(ap);
3614 3627
3615 if (!info->uin) 3628 if (!info->uin)
3618 str = g_string_sized_new(100); 3631 str = g_string_sized_new(100);
3619 g_snprintf(who, sizeof(who), "%u", info->uin); 3632 g_snprintf(who, sizeof(who), "%u", info->uin);
3620 buddy = gaim_find_buddy(gaim_connection_get_account(gc), who); 3633 buddy = gaim_find_buddy(gaim_connection_get_account(gc), who);
3621 if (buddy != NULL) 3634 if (buddy != NULL)
3622 bi = g_hash_table_lookup(od->buddyinfo, gaim_normalize(buddy->account, buddy->name)); 3635 bi = g_hash_table_lookup(od->buddyinfo, gaim_normalize(buddy->account, buddy->name));
3636 else
3637 bi = NULL;
3623 3638
3624 g_string_append_printf(str, "<b>%s:</b> %s", _("UIN"), who); 3639 g_string_append_printf(str, "<b>%s:</b> %s", _("UIN"), who);
3625 oscar_string_append(gc->account, str, "\n<br>", _("Nick"), info->nick); 3640 oscar_string_convert_and_append(account, str, "\n<br>", _("Nick"), info->nick);
3626 if ((bi != NULL) && (bi->ipaddr != 0)) { 3641 if ((bi != NULL) && (bi->ipaddr != 0)) {
3627 char *tstr = g_strdup_printf("%hhu.%hhu.%hhu.%hhu", 3642 char *tstr = g_strdup_printf("%hhu.%hhu.%hhu.%hhu",
3628 (bi->ipaddr & 0xff000000) >> 24, 3643 (bi->ipaddr & 0xff000000) >> 24,
3629 (bi->ipaddr & 0x00ff0000) >> 16, 3644 (bi->ipaddr & 0x00ff0000) >> 16,
3630 (bi->ipaddr & 0x0000ff00) >> 8, 3645 (bi->ipaddr & 0x0000ff00) >> 8,
3631 (bi->ipaddr & 0x000000ff)); 3646 (bi->ipaddr & 0x000000ff));
3632 oscar_string_append(gc->account, str, "\n<br>", _("IP Address"), tstr); 3647 oscar_string_append(str, "\n<br>", _("IP Address"), tstr);
3633 g_free(tstr); 3648 g_free(tstr);
3634 } 3649 }
3635 oscar_string_append(gc->account, str, "\n<br>", _("First Name"), info->first); 3650 oscar_string_convert_and_append(account, str, "\n<br>", _("First Name"), info->first);
3636 oscar_string_append(gc->account, str, "\n<br>", _("Last Name"), info->last); 3651 oscar_string_convert_and_append(account, str, "\n<br>", _("Last Name"), info->last);
3637 if (info->email && info->email[0] && (utf8 = oscar_utf8_try_convert(gc->account, info->email))) { 3652 if (info->email && info->email[0] && (utf8 = oscar_utf8_try_convert(gc->account, info->email))) {
3638 g_string_append_printf(str, "\n<br><b>%s:</b> <a href=\"mailto:%s\">%s</a>", _("E-Mail Address"), utf8, utf8); 3653 g_string_append_printf(str, "\n<br><b>%s:</b> <a href=\"mailto:%s\">%s</a>", _("E-Mail Address"), utf8, utf8);
3639 g_free(utf8); 3654 g_free(utf8);
3640 } 3655 }
3641 if (info->numaddresses && info->email2) { 3656 if (info->numaddresses && info->email2) {
3645 g_string_append_printf(str, "\n<br><b>%s:</b> <a href=\"mailto:%s\">%s</a>", _("E-Mail Address"), utf8, utf8); 3660 g_string_append_printf(str, "\n<br><b>%s:</b> <a href=\"mailto:%s\">%s</a>", _("E-Mail Address"), utf8, utf8);
3646 g_free(utf8); 3661 g_free(utf8);
3647 } 3662 }
3648 } 3663 }
3649 } 3664 }
3650 oscar_string_append(gc->account, str, "\n<br>", _("Mobile Phone"), info->mobile); 3665 oscar_string_convert_and_append(account, str, "\n<br>", _("Mobile Phone"), info->mobile);
3651 if (info->gender != 0) 3666 if (info->gender != 0)
3652 oscar_string_append(gc->account, str, "\n<br>", _("Gender"), info->gender == 1 ? _("Female") : _("Male")); 3667 oscar_string_append(str, "\n<br>", _("Gender"), info->gender == 1 ? _("Female") : _("Male"));
3653 if ((info->birthyear > 1900) && (info->birthmonth > 0) && (info->birthday > 0)) { 3668 if ((info->birthyear > 1900) && (info->birthmonth > 0) && (info->birthday > 0)) {
3654 /* Initialize the struct properly or strftime() will crash 3669 /* Initialize the struct properly or strftime() will crash
3655 * under some conditions (e.g. Debian sarge w/ LANG=en_HK). */ 3670 * under some conditions (e.g. Debian sarge w/ LANG=en_HK). */
3656 time_t t = time(NULL); 3671 time_t t = time(NULL);
3657 struct tm *tm = localtime(&t); 3672 struct tm *tm = localtime(&t);
3663 /* To be 100% sure that the fields are re-normalized. 3678 /* To be 100% sure that the fields are re-normalized.
3664 * If you're sure strftime() ALWAYS does this EVERYWHERE, 3679 * If you're sure strftime() ALWAYS does this EVERYWHERE,
3665 * feel free to remove it. --rlaager */ 3680 * feel free to remove it. --rlaager */
3666 mktime(tm); 3681 mktime(tm);
3667 3682
3668 oscar_string_append(gc->account, str, "\n<br>", _("Birthday"), 3683 oscar_string_append(str, "\n<br>", _("Birthday"),
3669 gaim_date_format_short(tm)); 3684 gaim_date_format_short(tm));
3670 } 3685 }
3671 if ((info->age > 0) && (info->age < 255)) { 3686 if ((info->age > 0) && (info->age < 255)) {
3672 char age[5]; 3687 char age[5];
3673 snprintf(age, sizeof(age), "%hhd", info->age); 3688 snprintf(age, sizeof(age), "%hhd", info->age);
3674 oscar_string_append(gc->account, str, "\n<br>", _("Age"), age); 3689 oscar_string_append(str, "\n<br>", _("Age"), age);
3675 } 3690 }
3676 if (info->personalwebpage && info->personalwebpage[0] && (utf8 = oscar_utf8_try_convert(gc->account, info->personalwebpage))) { 3691 if (info->personalwebpage && info->personalwebpage[0] && (utf8 = oscar_utf8_try_convert(gc->account, info->personalwebpage))) {
3677 g_string_append_printf(str, "\n<br><b>%s:</b> <a href=\"%s\">%s</a>", _("Personal Web Page"), utf8, utf8); 3692 g_string_append_printf(str, "\n<br><b>%s:</b> <a href=\"%s\">%s</a>", _("Personal Web Page"), utf8, utf8);
3678 g_free(utf8); 3693 g_free(utf8);
3679 } 3694 }
3682 g_free(utf8); 3697 g_free(utf8);
3683 } 3698 }
3684 g_string_append_printf(str, "<hr>"); 3699 g_string_append_printf(str, "<hr>");
3685 if ((info->homeaddr && (info->homeaddr[0])) || (info->homecity && info->homecity[0]) || (info->homestate && info->homestate[0]) || (info->homezip && info->homezip[0])) { 3700 if ((info->homeaddr && (info->homeaddr[0])) || (info->homecity && info->homecity[0]) || (info->homestate && info->homestate[0]) || (info->homezip && info->homezip[0])) {
3686 g_string_append_printf(str, "<b>%s:</b>", _("Home Address")); 3701 g_string_append_printf(str, "<b>%s:</b>", _("Home Address"));
3687 oscar_string_append(gc->account, str, "\n<br>", _("Address"), info->homeaddr); 3702 oscar_string_convert_and_append(account, str, "\n<br>", _("Address"), info->homeaddr);
3688 oscar_string_append(gc->account, str, "\n<br>", _("City"), info->homecity); 3703 oscar_string_convert_and_append(account, str, "\n<br>", _("City"), info->homecity);
3689 oscar_string_append(gc->account, str, "\n<br>", _("State"), info->homestate); 3704 oscar_string_convert_and_append(account, str, "\n<br>", _("State"), info->homestate);
3690 oscar_string_append(gc->account, str, "\n<br>", _("Zip Code"), info->homezip); 3705 oscar_string_convert_and_append(account, str, "\n<br>", _("Zip Code"), info->homezip);
3691 g_string_append_printf(str, "\n<hr>"); 3706 g_string_append_printf(str, "\n<hr>");
3692 } 3707 }
3693 if ((info->workaddr && info->workaddr[0]) || (info->workcity && info->workcity[0]) || (info->workstate && info->workstate[0]) || (info->workzip && info->workzip[0])) { 3708 if ((info->workaddr && info->workaddr[0]) || (info->workcity && info->workcity[0]) || (info->workstate && info->workstate[0]) || (info->workzip && info->workzip[0])) {
3694 g_string_append_printf(str, "<b>%s:</b>", _("Work Address")); 3709 g_string_append_printf(str, "<b>%s:</b>", _("Work Address"));
3695 oscar_string_append(gc->account, str, "\n<br>", _("Address"), info->workaddr); 3710 oscar_string_convert_and_append(account, str, "\n<br>", _("Address"), info->workaddr);
3696 oscar_string_append(gc->account, str, "\n<br>", _("City"), info->workcity); 3711 oscar_string_convert_and_append(account, str, "\n<br>", _("City"), info->workcity);
3697 oscar_string_append(gc->account, str, "\n<br>", _("State"), info->workstate); 3712 oscar_string_convert_and_append(account, str, "\n<br>", _("State"), info->workstate);
3698 oscar_string_append(gc->account, str, "\n<br>", _("Zip Code"), info->workzip); 3713 oscar_string_convert_and_append(account, str, "\n<br>", _("Zip Code"), info->workzip);
3699 g_string_append_printf(str, "\n<hr>"); 3714 g_string_append_printf(str, "\n<hr>");
3700 } 3715 }
3701 if ((info->workcompany && info->workcompany[0]) || (info->workdivision && info->workdivision[0]) || (info->workposition && info->workposition[0]) || (info->workwebpage && info->workwebpage[0])) { 3716 if ((info->workcompany && info->workcompany[0]) || (info->workdivision && info->workdivision[0]) || (info->workposition && info->workposition[0]) || (info->workwebpage && info->workwebpage[0])) {
3702 g_string_append_printf(str, "<b>%s:</b>", _("Work Information")); 3717 g_string_append_printf(str, "<b>%s:</b>", _("Work Information"));
3703 oscar_string_append(gc->account, str, "\n<br>", _("Company"), info->workcompany); 3718 oscar_string_convert_and_append(account, str, "\n<br>", _("Company"), info->workcompany);
3704 oscar_string_append(gc->account, str, "\n<br>", _("Division"), info->workdivision); 3719 oscar_string_convert_and_append(account, str, "\n<br>", _("Division"), info->workdivision);
3705 oscar_string_append(gc->account, str, "\n<br>", _("Position"), info->workposition); 3720 oscar_string_convert_and_append(account, str, "\n<br>", _("Position"), info->workposition);
3706 if (info->workwebpage && info->workwebpage[0] && (utf8 = oscar_utf8_try_convert(gc->account, info->workwebpage))) { 3721 if (info->workwebpage && info->workwebpage[0] && (utf8 = oscar_utf8_try_convert(gc->account, info->workwebpage))) {
3707 g_string_append_printf(str, "\n<br><b>%s:</b> <a href=\"%s\">%s</a>", _("Web Page"), utf8, utf8); 3722 g_string_append_printf(str, "\n<br><b>%s:</b> <a href=\"%s\">%s</a>", _("Web Page"), utf8, utf8);
3708 g_free(utf8); 3723 g_free(utf8);
3709 } 3724 }
3710 g_string_append_printf(str, "\n<hr>"); 3725 g_string_append_printf(str, "\n<hr>");