comparison libgaim/protocols/yahoo/yahoo_profile.c @ 14354:01daacf7b771

[gaim-migrate @ 17060] Make gaim_url_fetch() cancelable and change Yahoo! to take advantage of the changes. Other stuff can be changed later, the important thing is that the API is there. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 27 Aug 2006 21:13:30 +0000
parents 60b1bc8dbf37
children b7754ba03aa8
comparison
equal deleted inserted replaced
14353:33dc9f22b528 14354:01daacf7b771
740 740
741 g_string_free(s, TRUE); 741 g_string_free(s, TRUE);
742 return it; 742 return it;
743 } 743 }
744 744
745 static void yahoo_got_photo(void *data, const char *url_text, size_t len); 745 static void
746 yahoo_got_photo(GaimUtilFetchUrlData *url_data, gpointer data,
747 const gchar *url_text, size_t len, const gchar *error_message);
746 748
747 #endif /* PHOTO_SUPPORT */ 749 #endif /* PHOTO_SUPPORT */
748 750
749 static void yahoo_got_info(void *data, const char *url_text, size_t len) 751 static void yahoo_got_info(GaimUtilFetchUrlData *url_data, gpointer user_data,
752 const gchar *url_text, size_t len, const gchar *error_message)
750 { 753 {
751 YahooGetInfoData *info_data = (YahooGetInfoData *)data; 754 YahooGetInfoData *info_data = (YahooGetInfoData *)user_data;
752 char *p; 755 char *p;
753 char buf[1024]; 756 char buf[1024];
754 #if PHOTO_SUPPORT 757 #if PHOTO_SUPPORT
755 YahooGetInfoStepTwoData *info2_data; 758 YahooGetInfoStepTwoData *info2_data;
756 char *photo_url_text = NULL; 759 char *photo_url_text = NULL;
769 struct yahoo_data *yd; 772 struct yahoo_data *yd;
770 const profile_strings_node_t *strings = NULL; 773 const profile_strings_node_t *strings = NULL;
771 const char *title; 774 const char *title;
772 profile_state_t profile_state = PROFILE_STATE_DEFAULT; 775 profile_state_t profile_state = PROFILE_STATE_DEFAULT;
773 776
774 if (!GAIM_CONNECTION_IS_VALID(info_data->gc)) {
775 g_free(info_data->name);
776 g_free(info_data);
777 return;
778 }
779
780 gaim_debug_info("yahoo", "In yahoo_got_info\n"); 777 gaim_debug_info("yahoo", "In yahoo_got_info\n");
781 778
782 yd = info_data->gc->proto_data; 779 yd = info_data->gc->proto_data;
783 title = (yd->jp? _("Yahoo! Japan Profile") : 780 yd->url_datas = g_slist_remove(yd->url_datas, url_data);
784 _("Yahoo! Profile")); 781
782 title = yd->jp ? _("Yahoo! Japan Profile") :
783 _("Yahoo! Profile");
785 784
786 /* Get the tooltip info string */ 785 /* Get the tooltip info string */
787 tooltip_text = yahoo_tooltip_info_text(info_data); 786 tooltip_text = yahoo_tooltip_info_text(info_data);
788 787
789 /* We failed to grab the profile URL. This is not expected to actually 788 /* We failed to grab the profile URL. This is not expected to actually
790 * happen except under unusual error conditions, as Yahoo is observed 789 * happen except under unusual error conditions, as Yahoo is observed
791 * to send back HTML, with a 200 status code. 790 * to send back HTML, with a 200 status code.
792 */ 791 */
793 if (url_text == NULL || strcmp(url_text, "") == 0) { 792 if (error_message != NULL || url_text == NULL || strcmp(url_text, "") == 0) {
794 g_snprintf(buf, 1024, "<html><body>%s<b>%s</b></body></html>", 793 g_snprintf(buf, 1024, "<html><body>%s<b>%s</b></body></html>",
795 tooltip_text, _("Error retrieving profile")); 794 tooltip_text, _("Error retrieving profile"));
796 795
797 gaim_notify_userinfo(info_data->gc, info_data->name, 796 gaim_notify_userinfo(info_data->gc, info_data->name,
798 buf, NULL, NULL); 797 buf, NULL, NULL);
918 info2_data->title = title; 917 info2_data->title = title;
919 info2_data->profile_state = profile_state; 918 info2_data->profile_state = profile_state;
920 919
921 /* Try to put the photo in there too, if there's one */ 920 /* Try to put the photo in there too, if there's one */
922 if (photo_url_text) { 921 if (photo_url_text) {
922 GaimUtilFetchUrlData *url_data;
923 /* User-uploaded photos use a different server that requires the Host 923 /* User-uploaded photos use a different server that requires the Host
924 * header, but Yahoo Japan will use the "chunked" content encoding if 924 * header, but Yahoo Japan will use the "chunked" content encoding if
925 * we specify HTTP 1.1. So we have to specify 1.0 & fix gaim_url_fetch 925 * we specify HTTP 1.1. So we have to specify 1.0 & fix gaim_util_fetch_url
926 */ 926 */
927 gaim_url_fetch(photo_url_text, FALSE, NULL, FALSE, yahoo_got_photo, 927 url_data = gaim_util_fetch_url(photo_url_text, FALSE, NULL,
928 info2_data); 928 FALSE, yahoo_got_photo, info2_data);
929 if (url_data != NULL)
930 yd->url_datas = g_slist_prepend(yd->url_datas, url_data);
931 else {
932 g_free(info2_data->info_data->name);
933 g_free(info2_data->info_data);
934 g_free(info2_data);
935 }
929 } else { 936 } else {
930 /* Emulate a callback */ 937 /* Emulate a callback */
931 yahoo_got_photo(info2_data, NULL, 0); 938 yahoo_got_photo(NULL, info2_data, NULL, 0, NULL);
932 } 939 }
933 } 940 }
934 941
935 static void yahoo_got_photo(void *data, const char *url_text, size_t len) 942 static void
943 yahoo_got_photo(GaimUtilFetchUrlData *url_data, gpointer data,
944 const gchar *url_text, size_t len, const gchar *error_message)
936 { 945 {
937 YahooGetInfoStepTwoData *info2_data = (YahooGetInfoStepTwoData *)data; 946 YahooGetInfoStepTwoData *info2_data = (YahooGetInfoStepTwoData *)data;
947 struct yahoo_data *yd;
938 gboolean found = FALSE; 948 gboolean found = FALSE;
939 int id = -1; 949 int id = -1;
940 950
941 /* Temporary variables */ 951 /* Temporary variables */
942 char *p = NULL; 952 char *p = NULL;
960 970
961 /* Jun 29 05 Bleeter: Y! changed their profile pages. Terminators now seem to be */ 971 /* Jun 29 05 Bleeter: Y! changed their profile pages. Terminators now seem to be */
962 /* </dd> and not \n. The prpl's need to be audited before it can be moved */ 972 /* </dd> and not \n. The prpl's need to be audited before it can be moved */
963 /* in to gaim_markup_strip_html*/ 973 /* in to gaim_markup_strip_html*/
964 char *fudged_buffer; 974 char *fudged_buffer;
975
976 yd = info_data->gc->proto_data;
977 yd->url_datas = g_slist_remove(yd->url_datas, url_data);
978
965 fudged_buffer = gaim_strcasereplace(url_buffer, "</dd>", "</dd><br>"); 979 fudged_buffer = gaim_strcasereplace(url_buffer, "</dd>", "</dd><br>");
966 /* nuke the html, it's easier than trying to parse the horrid stuff */ 980 /* nuke the html, it's easier than trying to parse the horrid stuff */
967 stripped = gaim_markup_strip_html(fudged_buffer); 981 stripped = gaim_markup_strip_html(fudged_buffer);
968 stripped_len = strlen(stripped); 982 stripped_len = strlen(stripped);
969 983
1195 _("Could not retrieve the user's profile. " 1209 _("Could not retrieve the user's profile. "
1196 "This most likely means that the user does not exist; " 1210 "This most likely means that the user does not exist; "
1197 "however, Yahoo! sometimes does fail to find a user's " 1211 "however, Yahoo! sometimes does fail to find a user's "
1198 "profile. If you know that the user exists, " 1212 "profile. If you know that the user exists, "
1199 "please try again later.")); 1213 "please try again later."));
1200
1201 } else { 1214 } else {
1202 g_string_append_printf(s, "%s<br><br>", 1215 g_string_append_printf(s, "%s<br><br>",
1203 _("The user's profile is empty.")); 1216 _("The user's profile is empty."));
1204 } 1217 }
1205 } 1218 }
1243 void yahoo_get_info(GaimConnection *gc, const char *name) 1256 void yahoo_get_info(GaimConnection *gc, const char *name)
1244 { 1257 {
1245 struct yahoo_data *yd = gc->proto_data; 1258 struct yahoo_data *yd = gc->proto_data;
1246 YahooGetInfoData *data; 1259 YahooGetInfoData *data;
1247 char *url; 1260 char *url;
1261 GaimUtilFetchUrlData *url_data;
1248 1262
1249 data = g_new0(YahooGetInfoData, 1); 1263 data = g_new0(YahooGetInfoData, 1);
1250 data->gc = gc; 1264 data->gc = gc;
1251 data->name = g_strdup(name); 1265 data->name = g_strdup(name);
1252 1266
1253 url = g_strdup_printf("%s%s", 1267 url = g_strdup_printf("%s%s",
1254 (yd->jp? YAHOOJP_PROFILE_URL: YAHOO_PROFILE_URL), name); 1268 (yd->jp ? YAHOOJP_PROFILE_URL : YAHOO_PROFILE_URL), name);
1255 1269
1256 gaim_url_fetch(url, TRUE, NULL, FALSE, yahoo_got_info, data); 1270 url_data = gaim_util_fetch_url(url, TRUE, NULL, FALSE, yahoo_got_info, data);
1271 if (url_data != NULL)
1272 yd->url_datas = g_slist_prepend(yd->url_datas, url_data);
1273 else {
1274 g_free(data->name);
1275 g_free(data);
1276 }
1257 1277
1258 g_free(url); 1278 g_free(url);
1259 } 1279 }