Mercurial > pidgin
comparison src/protocols/yahoo/yahoo.c @ 7675:66d9440db6ec
[gaim-migrate @ 8319]
marv writes: "This fixes some crashes on unusual long profile fields
for yahoo, and probably msn. One test case is the yahoo
[l]user "kent_nwo4life", which crashes without this patch."
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Sun, 30 Nov 2003 23:49:45 +0000 |
parents | e4264f71fac7 |
children | 29bcd6e3da33 |
comparison
equal
deleted
inserted
replaced
7674:3d49c33db741 | 7675:66d9440db6ec |
---|---|
2597 static void yahoo_got_info(void *data, const char *url_text, size_t len) | 2597 static void yahoo_got_info(void *data, const char *url_text, size_t len) |
2598 { | 2598 { |
2599 YahooGetInfoData *info_data = (YahooGetInfoData *)data; | 2599 YahooGetInfoData *info_data = (YahooGetInfoData *)data; |
2600 char *stripped, *p; | 2600 char *stripped, *p; |
2601 char buf[1024]; | 2601 char buf[1024]; |
2602 gboolean found; | 2602 gboolean found = FALSE; |
2603 gboolean has_info = FALSE; | |
2604 char *url_buffer; | 2603 char *url_buffer; |
2604 GString *s; | |
2605 int stripped_len; | |
2605 | 2606 |
2606 gaim_debug_info("yahoo", "In yahoo_got_info\n"); | 2607 gaim_debug_info("yahoo", "In yahoo_got_info\n"); |
2607 | 2608 |
2608 /* we failed to grab the profile URL */ | 2609 /* we failed to grab the profile URL */ |
2609 if (url_text == NULL || strcmp(url_text, "") == 0) { | 2610 if (url_text == NULL || strcmp(url_text, "") == 0) { |
2638 } | 2639 } |
2639 | 2640 |
2640 /* at the moment we don't support profile pages with languages other than | 2641 /* at the moment we don't support profile pages with languages other than |
2641 * english. the problem is, that every user may choose his/her own profile | 2642 * english. the problem is, that every user may choose his/her own profile |
2642 * language. this language has nothing to do with the preferences of the | 2643 * language. this language has nothing to do with the preferences of the |
2643 * user which looks at the profile | 2644 * user which looks at the profile |
2644 */ | 2645 */ |
2645 p = strstr(url_text, "Last Updated:"); | 2646 p = strstr(url_text, "Last Updated:"); |
2646 if (!p) { | 2647 if (!p) { |
2647 p = strstr(url_text, "Last Updated "); | 2648 p = strstr(url_text, "Last Updated "); |
2648 } | 2649 } |
2681 url_buffer[strlen(url_buffer) - 1] = '\0'; | 2682 url_buffer[strlen(url_buffer) - 1] = '\0'; |
2682 } | 2683 } |
2683 | 2684 |
2684 /* nuke the html, it's easier than trying to parse the horrid stuff */ | 2685 /* nuke the html, it's easier than trying to parse the horrid stuff */ |
2685 stripped = gaim_markup_strip_html(url_buffer); | 2686 stripped = gaim_markup_strip_html(url_buffer); |
2687 stripped_len = strlen(stripped); | |
2686 | 2688 |
2687 gaim_debug_misc("yahoo", "stripped = %p\n", stripped); | 2689 gaim_debug_misc("yahoo", "stripped = %p\n", stripped); |
2688 gaim_debug_misc("yahoo", "url_buffer = %p\n", url_buffer); | 2690 gaim_debug_misc("yahoo", "url_buffer = %p\n", url_buffer); |
2689 | 2691 |
2690 /* gonna re-use the memory we've already got for url_buffer */ | 2692 /* gonna re-use the memory we've already got for url_buffer */ |
2691 strcpy(url_buffer, "<html><body>\n"); | 2693 /* no we're not */ |
2694 s = g_string_sized_new(strlen(url_buffer)); | |
2695 g_string_append(s, "<html><body>\n"); | |
2692 | 2696 |
2693 /* extract their Yahoo! ID and put it in. Don't bother marking has_info as | 2697 /* extract their Yahoo! ID and put it in. Don't bother marking has_info as |
2694 * true, since the Yahoo! ID will always be there */ | 2698 * true, since the Yahoo! ID will always be there */ |
2695 found = gaim_markup_extract_info_field(stripped, url_buffer, "Yahoo! ID:", 2, "\n", 0, | 2699 if (!gaim_markup_extract_info_field(stripped, stripped_len, s, "Yahoo! ID:", 2, "\n", 0, |
2696 NULL, _("Yahoo! ID"), 0, NULL); | 2700 NULL, _("Yahoo! ID"), 0, NULL)) |
2701 g_string_append_printf(s, "<b>%s:</b> %s<br>", _("Yahoo! ID"), info_data->name); | |
2697 | 2702 |
2698 | 2703 |
2699 /* extract their Email address and put it in */ | 2704 /* extract their Email address and put it in */ |
2700 found = gaim_markup_extract_info_field(stripped, url_buffer, "My Email", 5, "\n", 0, | 2705 found |= gaim_markup_extract_info_field(stripped, stripped_len, s, "My Email", 5, "\n", 0, |
2701 "Private", _("Email"), 0, NULL); | 2706 "Private", _("Email"), 0, NULL); |
2702 if(found) | |
2703 has_info = TRUE; | |
2704 | 2707 |
2705 /* extract the Nickname if it exists */ | 2708 /* extract the Nickname if it exists */ |
2706 found = gaim_markup_extract_info_field(stripped, url_buffer, "Nickname:", 1, "\n", '\n', | 2709 found |= gaim_markup_extract_info_field(stripped, stripped_len, s, "Nickname:", 1, "\n", '\n', |
2707 NULL, _("Nickname"), 0, NULL); | 2710 NULL, _("Nickname"), 0, NULL); |
2708 if(found) | |
2709 has_info = TRUE; | |
2710 | 2711 |
2711 /* extract their RealName and put it in */ | 2712 /* extract their RealName and put it in */ |
2712 found = gaim_markup_extract_info_field(stripped, url_buffer, "RealName:", 1, "\n", '\n', | 2713 found |= gaim_markup_extract_info_field(stripped, stripped_len, s, "RealName:", 1, "\n", '\n', |
2713 NULL, _("Realname"), 0, NULL); | 2714 NULL, _("Realname"), 0, NULL); |
2714 if(found) | |
2715 has_info = TRUE; | |
2716 | 2715 |
2717 /* extract their Location and put it in */ | 2716 /* extract their Location and put it in */ |
2718 found = gaim_markup_extract_info_field(stripped, url_buffer, "Location:", 2, "\n", '\n', | 2717 found |= gaim_markup_extract_info_field(stripped, stripped_len, s, "Location:", 2, "\n", '\n', |
2719 NULL, _("Location"), 0, NULL); | 2718 NULL, _("Location"), 0, NULL); |
2720 if(found) | |
2721 has_info = TRUE; | |
2722 | 2719 |
2723 /* extract their Age and put it in */ | 2720 /* extract their Age and put it in */ |
2724 found = gaim_markup_extract_info_field(stripped, url_buffer, "Age:", 3, "\n", '\n', | 2721 found |= gaim_markup_extract_info_field(stripped, stripped_len, s, "Age:", 3, "\n", '\n', |
2725 NULL, _("Age"), 0, NULL); | 2722 NULL, _("Age"), 0, NULL); |
2726 if(found) | |
2727 has_info = TRUE; | |
2728 | 2723 |
2729 /* extract their MaritalStatus and put it in */ | 2724 /* extract their MaritalStatus and put it in */ |
2730 found = gaim_markup_extract_info_field(stripped, url_buffer, "MaritalStatus:", 3, "\n", '\n', | 2725 found |= gaim_markup_extract_info_field(stripped, stripped_len, s, "MaritalStatus:", 3, "\n", '\n', |
2731 "No Answer", _("Marital Status"), 0, NULL); | 2726 "No Answer", _("Marital Status"), 0, NULL); |
2732 if(found) | |
2733 has_info = TRUE; | |
2734 | 2727 |
2735 /* extract their Gender and put it in */ | 2728 /* extract their Gender and put it in */ |
2736 found = gaim_markup_extract_info_field(stripped, url_buffer, "Gender:", 3, "\n", '\n', | 2729 found |= gaim_markup_extract_info_field(stripped, stripped_len, s, "Gender:", 3, "\n", '\n', |
2737 "No Answer", _("Gender"), 0, NULL); | 2730 "No Answer", _("Gender"), 0, NULL); |
2738 if(found) | |
2739 has_info = TRUE; | |
2740 | 2731 |
2741 /* extract their Occupation and put it in */ | 2732 /* extract their Occupation and put it in */ |
2742 found = gaim_markup_extract_info_field(stripped, url_buffer, "Occupation:", 2, "\n", '\n', | 2733 found |= gaim_markup_extract_info_field(stripped, stripped_len, s, "Occupation:", 2, "\n", '\n', |
2743 NULL, _("Occupation"), 0, NULL); | 2734 NULL, _("Occupation"), 0, NULL); |
2744 if(found) | |
2745 has_info = TRUE; | |
2746 | 2735 |
2747 /* Hobbies, Latest News, and Favorite Quote are a bit different, since the | 2736 /* Hobbies, Latest News, and Favorite Quote are a bit different, since the |
2748 * values can contain embedded newlines... but any or all of them can also | 2737 * values can contain embedded newlines... but any or all of them can also |
2749 * not appear. The way we delimit them is to successively look for the next | 2738 * not appear. The way we delimit them is to successively look for the next |
2750 * one that _could_ appear, and if all else fails, we end the section by | 2739 * one that _could_ appear, and if all else fails, we end the section by |
2751 * looking for the 'Links' heading, which is the next thing to follow this | 2740 * looking for the 'Links' heading, which is the next thing to follow this |
2752 * bunch. | 2741 * bunch. |
2753 */ | 2742 */ |
2754 | 2743 |
2755 found = gaim_markup_extract_info_field(stripped, url_buffer, "Hobbies:", 1, "Latest News", | 2744 if (!gaim_markup_extract_info_field(stripped, stripped_len, s, "Hobbies:", 1, "Latest News", |
2756 '\n', NULL, _("Hobbies"), 0, NULL); | 2745 '\n', NULL, _("Hobbies"), 0, NULL)) |
2757 if(!found) | |
2758 { | 2746 { |
2759 found = gaim_markup_extract_info_field(stripped, url_buffer, "Hobbies:", 1, "Favorite Quote", | 2747 if (!gaim_markup_extract_info_field(stripped, stripped_len, s, "Hobbies:", 1, "Favorite Quote", |
2760 '\n', NULL, _("Hobbies"), 0, NULL); | 2748 '\n', NULL, _("Hobbies"), 0, NULL)) |
2761 if(!found) | |
2762 { | 2749 { |
2763 found = gaim_markup_extract_info_field(stripped, url_buffer, "Hobbies:", 1, "Links", | 2750 found |= gaim_markup_extract_info_field(stripped, stripped_len, s, "Hobbies:", 1, "Links", |
2764 '\n', NULL, _("Hobbies"), 0, NULL); | 2751 '\n', NULL, _("Hobbies"), 0, NULL); |
2765 if(found) | |
2766 has_info = TRUE; | |
2767 } | 2752 } |
2768 else | 2753 else |
2769 has_info = TRUE; | 2754 found = TRUE; |
2770 } | 2755 } |
2771 else | 2756 else |
2772 has_info = TRUE; | 2757 found = TRUE; |
2773 | 2758 |
2774 found = gaim_markup_extract_info_field(stripped, url_buffer, "Latest News:", 1, "Favorite Quote", | 2759 if (!gaim_markup_extract_info_field(stripped, stripped_len, s, "Latest News:", 1, "Favorite Quote", |
2775 '\n', NULL, _("Latest News"), 0, NULL); | 2760 '\n', NULL, _("Latest News"), 0, NULL)) |
2776 if(!found) | |
2777 { | 2761 { |
2778 found = gaim_markup_extract_info_field(stripped, url_buffer, "Latest News:", 1, "Links", | 2762 found |= gaim_markup_extract_info_field(stripped, stripped_len, s, "Latest News:", 1, "Links", |
2779 '\n', NULL, _("Latest News"), 0, NULL); | 2763 '\n', NULL, _("Latest News"), 0, NULL); |
2780 if(found) | |
2781 has_info = TRUE; | |
2782 } | 2764 } |
2783 else | 2765 else |
2784 has_info = TRUE; | 2766 found = TRUE; |
2785 | 2767 |
2786 found = gaim_markup_extract_info_field(stripped, url_buffer, "Favorite Quote:", 0, "Links", | 2768 found |= gaim_markup_extract_info_field(stripped, stripped_len, s, "Favorite Quote:", 0, "Links", |
2787 '\n', NULL, _("Favorite Quote"), 0, NULL); | 2769 '\n', NULL, _("Favorite Quote"), 0, NULL); |
2788 if(found) | |
2789 has_info = TRUE; | |
2790 | 2770 |
2791 /* Home Page will either be "No home page specified", | 2771 /* Home Page will either be "No home page specified", |
2792 * or "Home Page: " and a link. */ | 2772 * or "Home Page: " and a link. */ |
2793 p = strstr(stripped, "No home page specified"); | 2773 p = strstr(stripped, "No home page specified"); |
2794 if(!p) | 2774 if(!p) |
2795 { | 2775 { |
2796 found = gaim_markup_extract_info_field(stripped, url_buffer, "Home Page:", 1, " ", 0, NULL, | 2776 found |= gaim_markup_extract_info_field(stripped, stripped_len, s, "Home Page:", 1, " ", 0, NULL, |
2797 _("Home Page"), 1, NULL); | 2777 _("Home Page"), 1, NULL); |
2798 if(found) | |
2799 has_info = TRUE; | |
2800 } | 2778 } |
2801 | 2779 |
2802 /* Cool Link {1,2,3} is also different. If "No cool link specified" exists, | 2780 /* Cool Link {1,2,3} is also different. If "No cool link specified" exists, |
2803 * then we have none. If we have one however, we'll need to check and see if | 2781 * then we have none. If we have one however, we'll need to check and see if |
2804 * we have a second one. If we have a second one, we have to check to see if | 2782 * we have a second one. If we have a second one, we have to check to see if |
2805 * we have a third one. | 2783 * we have a third one. |
2806 */ | 2784 */ |
2807 p = strstr(stripped,"No cool link specified"); | 2785 p = strstr(stripped,"No cool link specified"); |
2808 if (!p) | 2786 if (!p) |
2809 { | 2787 { |
2810 found = gaim_markup_extract_info_field(stripped, url_buffer, "Cool Link 1:", 1, " ", 0, NULL, | 2788 if (gaim_markup_extract_info_field(stripped, stripped_len, s, "Cool Link 1:", 1, " ", 0, NULL, |
2811 _("Cool Link 1"), 1, NULL); | 2789 _("Cool Link 1"), 1, NULL)) |
2812 if(found) | |
2813 { | 2790 { |
2814 has_info = TRUE; | 2791 found = TRUE; |
2815 found = gaim_markup_extract_info_field(stripped, url_buffer, "Cool Link 2:", 1, " ", 0, NULL, | 2792 if (gaim_markup_extract_info_field(stripped, stripped_len, s, "Cool Link 2:", 1, " ", 0, NULL, |
2816 _("Cool Link 2"), 1, NULL); | 2793 _("Cool Link 2"), 1, NULL)) |
2817 if(found) | 2794 gaim_markup_extract_info_field(stripped, stripped_len, s, "Cool Link 3:", 1, " ", 0, NULL, |
2818 gaim_markup_extract_info_field(stripped, url_buffer, "Cool Link 3:", 1, " ", 0, NULL, | |
2819 _("Cool Link 3"), 1, NULL); | 2795 _("Cool Link 3"), 1, NULL); |
2820 } | 2796 } |
2821 } | 2797 } |
2822 | 2798 |
2823 /* see if Member Since is there, and if so, extract it. */ | 2799 /* see if Member Since is there, and if so, extract it. */ |
2824 found = gaim_markup_extract_info_field(stripped, url_buffer, "Member Since:", 1, "Last Updated:", | 2800 found |= gaim_markup_extract_info_field(stripped, stripped_len, s, "Member Since:", 1, "Last Updated:", |
2825 '\n', NULL, _("Member Since"), 0, NULL); | 2801 '\n', NULL, _("Member Since"), 0, NULL); |
2802 | |
2803 /* extract the Last Updated date and put it in */ | |
2804 found |= gaim_markup_extract_info_field(stripped, stripped_len, s, "Last Updated:", 1, "\n", '\n', NULL, | |
2805 _("Last Updated"), 0, NULL); | |
2806 | |
2807 /* finish off the html */ | |
2808 g_string_append(s, "</body></html>\n"); | |
2809 g_free(stripped); | |
2810 | |
2826 if(found) | 2811 if(found) |
2827 has_info = TRUE; | |
2828 | |
2829 /* extract the Last Updated date and put it in */ | |
2830 found = gaim_markup_extract_info_field(stripped, url_buffer, "Last Updated:", 1, "\n", '\n', NULL, | |
2831 _("Last Updated"), 0, NULL); | |
2832 if(found) | |
2833 has_info = TRUE; | |
2834 | |
2835 /* finish off the html */ | |
2836 strcat(url_buffer, "</body></html>\n"); | |
2837 g_free(stripped); | |
2838 | |
2839 if(has_info) | |
2840 { | 2812 { |
2841 /* show it to the user */ | 2813 /* show it to the user */ |
2842 gaim_notify_formatted(info_data->gc, NULL, _("Buddy Information"), NULL, | 2814 gaim_notify_formatted(info_data->gc, NULL, _("Buddy Information"), NULL, |
2843 url_buffer, NULL, NULL); | 2815 s->str, NULL, NULL); |
2844 } | 2816 } |
2845 else | 2817 else |
2846 { | 2818 { |
2847 char primary[256]; | 2819 char *primary; |
2848 g_snprintf(primary, sizeof(primary), | 2820 primary = g_strdup_printf(_("User information for %s unavailable"), info_data->name); |
2849 _("User information for %s unavailable"), info_data->name); | |
2850 gaim_notify_error(info_data->gc, NULL, primary, | 2821 gaim_notify_error(info_data->gc, NULL, primary, |
2851 _("The user's profile is empty.")); | 2822 _("The user's profile is empty.")); |
2823 g_free(primary); | |
2852 } | 2824 } |
2853 | 2825 |
2854 g_free(url_buffer); | 2826 g_free(url_buffer); |
2855 | 2827 g_string_free(s, TRUE); |
2856 g_free(info_data->name); | 2828 g_free(info_data->name); |
2857 g_free(info_data); | 2829 g_free(info_data); |
2858 } | 2830 } |
2859 | 2831 |
2860 static void yahoo_get_info(GaimConnection *gc, const char *name) | 2832 static void yahoo_get_info(GaimConnection *gc, const char *name) |