📄 yahoo_profile.c
字号:
if (p && profile_langs[lang].det && !strstr(url_text, profile_langs[lang].det)) { p = NULL; } if (p) break; } if (p) { for (strid = 0; profile_strings[strid].lang != XX; strid += 1) { if (profile_strings[strid].lang == profile_langs[lang].lang) break; } strings = profile_strings + strid; gaim_debug_info("yahoo", "detected profile lang = %s (%d)\n", profile_strings[strid].lang_string, lang); } /* Every user may choose his/her own profile language, and this language * has nothing to do with the preferences of the user which looks at the * profile. We try to support all languages, but nothing is guaranteed. * If we cannot determine the language, it means either (1) the profile * is written in an unsupported language, (2) our language support is * out of date, or (3) the user is not found. */ if (!p || strings->lang == XX) { if (!strstr(url_text, "Yahoo! Member Directory - User not found") && !strstr(url_text, "was not found on this server.") && !strstr(url_text, "\xb8\xf8\xb3\xab\xa5\xd7\xa5\xed\xa5\xd5\xa5\xa3\xa1\xbc\xa5\xeb\xa4\xac\xb8\xab\xa4\xc4\xa4\xab\xa4\xea\xa4\xde\xa4\xbb\xa4\xf3")) { profile_state = PROFILE_STATE_UNKNOWN_LANGUAGE; } else { profile_state = PROFILE_STATE_NOT_FOUND; } }#if PHOTO_SUPPORT photo_url_text = yahoo_get_photo_url(url_text, info_data->name);#endif url_buffer = g_strdup(url_text); /* * gaim_markup_strip_html() doesn't strip out character entities like * and · */ yahoo_remove_nonbreaking_spaces(url_buffer);#if 1 while ((p = strstr(url_buffer, "·")) != NULL) { memmove(p, p + 6, strlen(p + 6)); url_buffer[strlen(url_buffer) - 6] = '\0'; }#endif /* nuke the nasty \r's */ gaim_str_strip_cr(url_buffer);#if PHOTO_SUPPORT /* Marshall the existing state */ info2_data = g_malloc(sizeof(YahooGetInfoStepTwoData)); info2_data->info_data = info_data; info2_data->url_buffer = url_buffer; info2_data->s = s; info2_data->photo_url_text = photo_url_text; info2_data->profile_url_text = profile_url_text; info2_data->tooltip_text = tooltip_text; info2_data->strings = strings; info2_data->last_updated_string = last_updated_string; info2_data->title = title; info2_data->profile_state = profile_state; /* Try to put the photo in there too, if there's one */ if (photo_url_text) { /* User-uploaded photos use a different server that requires the Host * header, but Yahoo Japan will use the "chunked" content encoding if * we specify HTTP 1.1. So we have to specify 1.0 & fix gaim_url_fetch */ gaim_url_fetch(photo_url_text, FALSE, NULL, FALSE, yahoo_got_photo, info2_data); } else { /* Emulate a callback */ yahoo_got_photo(info2_data, NULL, 0); }}static void yahoo_got_photo(void *data, const char *url_text, size_t len){ YahooGetInfoStepTwoData *info2_data = (YahooGetInfoStepTwoData *)data; gboolean found = FALSE; int id = -1; /* Temporary variables */ char *p = NULL; char *stripped; int stripped_len; char *last_updated_utf8_string = NULL; /* Unmarshall the saved state */ YahooGetInfoData *info_data = info2_data->info_data; char *url_buffer = info2_data->url_buffer; GString *s = info2_data->s; char *photo_url_text = info2_data->photo_url_text; char *profile_url_text = info2_data->profile_url_text; char *tooltip_text = info2_data->tooltip_text; const profile_strings_node_t *strings = info2_data->strings; const char *last_updated_string = info2_data->last_updated_string; const char *title = info2_data->title; profile_state_t profile_state = info2_data->profile_state; /* We continue here from yahoo_got_info, as if nothing has happened */#endif /* PHOTO_SUPPORT */ /* nuke the html, it's easier than trying to parse the horrid stuff */ stripped = gaim_markup_strip_html(url_buffer); stripped_len = strlen(stripped); gaim_debug_misc("yahoo", "stripped = %p\n", stripped); gaim_debug_misc("yahoo", "url_buffer = %p\n", url_buffer); /* convert to utf8 */ if (strings && strings->charset != XX) { p = g_convert(stripped, -1, "utf-8", strings->charset, NULL, NULL, NULL); if (!p) { p = g_locale_to_utf8(stripped, -1, NULL, NULL, NULL); if (!p) { p = g_convert(stripped, -1, "utf-8", "windows-1252", NULL, NULL, NULL); } } if (p) { g_free(stripped); stripped = gaim_utf8_ncr_decode(p); stripped_len = strlen(stripped); g_free(p); } } p = NULL; /* "Last updated" should also be converted to utf8 and with killed */ if (strings && strings->charset != XX) { last_updated_utf8_string = g_convert(last_updated_string, -1, "utf-8", strings->charset, NULL, NULL, NULL); yahoo_remove_nonbreaking_spaces(last_updated_utf8_string); gaim_debug_misc("yahoo", "after utf8 conversion: stripped = (%s)\n", stripped); } /* gonna re-use the memory we've already got for url_buffer */ /* no we're not */ s = g_string_sized_new(strlen(url_buffer)); if (profile_state == PROFILE_STATE_DEFAULT) {#if 0 /* extract their Yahoo! ID and put it in. Don't bother marking has_info as * true, since the Yahoo! ID will always be there */ if (!gaim_markup_extract_info_field(stripped, stripped_len, s, strings->yahoo_id_string, 2, "\n", 0, NULL, _("Yahoo! ID"), 0, NULL)) ;#endif#if PHOTO_SUPPORT /* Try to put the photo in there too, if there's one and is readable */ if (data && url_text && len != 0) { if (strstr(url_text, "400 Bad Request") || strstr(url_text, "403 Forbidden") || strstr(url_text, "404 Not Found")) { gaim_debug_info("yahoo", "Error getting %s: %s\n", photo_url_text, url_text); } else { gaim_debug_info("yahoo", "%s is %d bytes\n", photo_url_text, len); id = gaim_imgstore_add(url_text, len, NULL); g_string_append_printf(s, "<img id=\"%d\"><br>", id); } }#endif /* PHOTO_SUPPORT */ /* extract their Email address and put it in */ found |= gaim_markup_extract_info_field(stripped, stripped_len, s, strings->my_email_string, 5, "\n", 0, strings->private_string, _("Email"), 0, NULL); /* extract the Nickname if it exists */ found |= gaim_markup_extract_info_field(stripped, stripped_len, s, "Nickname:", 1, "\n", '\n', NULL, _("Nickname"), 0, NULL); /* extract their RealName and put it in */ found |= gaim_markup_extract_info_field(stripped, stripped_len, s, strings->realname_string, 1, "\n", '\n', NULL, _("Realname"), 0, NULL); /* extract their Location and put it in */ found |= gaim_markup_extract_info_field(stripped, stripped_len, s, strings->location_string, 2, "\n", '\n', NULL, _("Location"), 0, NULL); /* extract their Age and put it in */ found |= gaim_markup_extract_info_field(stripped, stripped_len, s, strings->age_string, 3, "\n", '\n', NULL, _("Age"), 0, NULL); /* extract their MaritalStatus and put it in */ found |= gaim_markup_extract_info_field(stripped, stripped_len, s, strings->maritalstatus_string, 3, "\n", '\n', strings->no_answer_string, _("Marital Status"), 0, NULL); /* extract their Gender and put it in */ found |= gaim_markup_extract_info_field(stripped, stripped_len, s, strings->gender_string, 3, "\n", '\n', strings->no_answer_string, _("Gender"), 0, NULL); /* extract their Occupation and put it in */ found |= gaim_markup_extract_info_field(stripped, stripped_len, s, strings->occupation_string, 2, "\n", '\n', NULL, _("Occupation"), 0, NULL); /* Hobbies, Latest News, and Favorite Quote are a bit different, since * the values can contain embedded newlines... but any or all of them * can also not appear. The way we delimit them is to successively * look for the next one that _could_ appear, and if all else fails, * we end the section by looking for the 'Links' heading, which is the * next thing to follow this bunch. (For Yahoo Japan, we check for * the "Description" ("Self PR") heading instead of "Links".) */ if (!gaim_markup_extract_info_field(stripped, stripped_len, s, strings->hobbies_string, 1, strings->latest_news_string, '\n', NULL, _("Hobbies"), 0, NULL)) { if (!gaim_markup_extract_info_field(stripped, stripped_len, s, strings->hobbies_string, 1, strings->favorite_quote_string, '\n', NULL, _("Hobbies"), 0, NULL)) { found |= gaim_markup_extract_info_field(stripped, stripped_len, s, strings->hobbies_string, 1, strings->links_string, '\n', NULL, _("Hobbies"), 0, NULL); } else found = TRUE; } else found = TRUE; if (!gaim_markup_extract_info_field(stripped, stripped_len, s, strings->latest_news_string, 1, strings->favorite_quote_string, '\n', NULL, _("Latest News"), 0, NULL)) { found |= gaim_markup_extract_info_field(stripped, stripped_len, s, strings->latest_news_string, 1, strings->links_string, '\n', NULL, _("Latest News"), 0, NULL); } else found = TRUE; found |= gaim_markup_extract_info_field(stripped, stripped_len, s, strings->favorite_quote_string, 1, strings->links_string, '\n', NULL, _("Favorite Quote"), 0, NULL); /* Home Page will either be "No home page specified", * or "Home Page: " and a link. * For Yahoo! Japan, if there is no home page specified, * neither "No home page specified" nor "Home Page:" is shown. */ if (strings->home_page_string) { p = !strings->no_home_page_specified_string? NULL: strstr(stripped, strings->no_home_page_specified_string); if(!p) { found |= gaim_markup_extract_info_field(stripped, stripped_len, s, strings->home_page_string, 1, "\n", 0, NULL, _("Home Page"), 1, NULL); } } /* Cool Link {1,2,3} is also different. If "No cool link specified" * exists, then we have none. If we have one however, we'll need to * check and see if we have a second one. If we have a second one, * we have to check to see if we have a third one. */ p = !strings->no_cool_link_specified_string? NULL: strstr(stripped,strings->no_cool_link_specified_string); if (!p) { if (gaim_markup_extract_info_field(stripped, stripped_len, s, strings->cool_link_1_string, 1, "\n", 0, NULL, _("Cool Link 1"), 1, NULL)) { found = TRUE; if (gaim_markup_extract_info_field(stripped, stripped_len, s, strings->cool_link_2_string, 1, "\n", 0, NULL, _("Cool Link 2"), 1, NULL)) { gaim_markup_extract_info_field(stripped, stripped_len, s, strings->cool_link_3_string, 1, "\n", 0, NULL, _("Cool Link 3"), 1, NULL); } } } /* see if Member Since is there, and if so, extract it. */ found |= gaim_markup_extract_info_field(stripped, stripped_len, s, "Member Since:", 1, last_updated_utf8_string, '\n', NULL, _("Member Since"), 0, NULL); /* extract the Last Updated date and put it in */ found |= gaim_markup_extract_info_field(stripped, stripped_len, s, last_updated_utf8_string, 0, "\n", '\n', NULL, _("Last Updated"), 0, NULL); } /* if (profile_state == PROFILE_STATE_DEFAULT) */ if(!found) { g_string_append_printf(s, "<br><b>"); g_string_append_printf(s, _("User information for %s unavailable"), info_data->name); g_string_append_printf(s, "</b><br>"); if (profile_state == PROFILE_STATE_UNKNOWN_LANGUAGE) { g_string_append_printf(s, "%s<br><br>", _("Sorry, this profile seems to be in a language " "that is not supported at this time.")); } else if (profile_state == PROFILE_STATE_NOT_FOUND) { GaimBuddy *b = gaim_find_buddy (gaim_connection_get_account(info_data->gc), info_data->name); YahooFriend *f = NULL; if (b) { /* Someone on the buddy list can be "not on server list", * in which case the user may or may not actually exist. * Hence this extra step. */ f = yahoo_friend_find(b->account->gc, b->name); } g_string_append_printf(s, "%s<br><br>", f? _("Could not retrieve the user's profile. " "This most likely is a temporary server-side problem. " "Please try again later."): _("Could not retrieve the user's profile. " "This most likely means that the user does not exist; " "however, Yahoo! sometimes does fail to find a user's " "profile. If you know that the user exists, " "please try again later.")); } else { g_string_append_printf(s, "%s<br><br>", _("The user's profile is empty.")); } } /* put a link to the actual profile URL */ g_string_append_printf(s, _("<b>%s:</b> "), _("Profile URL")); g_string_append_printf(s, "<br><a href=\"%s\">%s</a><br>", profile_url_text, profile_url_text); /* finish off the html at the end */ g_string_append(s, "</body></html>\n"); g_free(stripped); /* Put the Yahoo! ID, nickname, idle time, and status message in */ g_string_prepend(s, tooltip_text); /* finish off the html at the beginning */ g_string_prepend(s, "<html><body>\n"); /* show it to the user */ gaim_notify_userinfo(info_data->gc, info_data->name, NULL, title, NULL, s->str, NULL, NULL); g_free(last_updated_utf8_string); g_free(url_buffer); g_string_free(s, TRUE); g_free(profile_url_text); g_free(tooltip_text); g_free(info_data->name); g_free(info_data);#if PHOTO_SUPPORT g_free(photo_url_text); g_free(info2_data); if (id != -1) gaim_imgstore_unref(id);#endif}void yahoo_get_info(GaimConnection *gc, const char *name){ struct yahoo_data *yd = gc->proto_data; YahooGetInfoData *data; char *url; data = g_new0(YahooGetInfoData, 1); data->gc = gc; data->name = g_strdup(name); url = g_strdup_printf("%s%s", (yd->jp? YAHOOJP_PROFILE_URL: YAHOO_PROFILE_URL), name); gaim_url_fetch(url, FALSE, NULL, FALSE, yahoo_got_info, data); g_free(url);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -