Mercurial > pidgin
comparison src/protocols/yahoo/yahoo.c @ 7112:cc1d09631513
[gaim-migrate @ 7679]
"ChipX86 recently fixed up the MSN user info code so that if no actual
information is found, it will display an error message instead of simply
giving a blank screen. Here is a patch for Yahoo which does the same
thing." --Nathan Poznick
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Wed, 01 Oct 2003 22:14:54 +0000 |
parents | 6faeeecab0dc |
children | bf630f7dfdcd |
comparison
equal
deleted
inserted
replaced
7111:b9664e6257b5 | 7112:cc1d09631513 |
---|---|
38 #include "yahoo.h" | 38 #include "yahoo.h" |
39 #include "yahoochat.h" | 39 #include "yahoochat.h" |
40 #include "md5.h" | 40 #include "md5.h" |
41 | 41 |
42 extern char *yahoo_crypt(const char *, const char *); | 42 extern char *yahoo_crypt(const char *, const char *); |
43 | |
44 typedef struct | |
45 { | |
46 GaimConnection *gc; | |
47 char *name; | |
48 } YahooGetInfoData; | |
49 | |
43 | 50 |
44 /* #define YAHOO_DEBUG */ | 51 /* #define YAHOO_DEBUG */ |
45 | 52 |
46 #define USEROPT_MAIL 0 | 53 #define USEROPT_MAIL 0 |
47 | 54 |
2386 return TRUE; | 2393 return TRUE; |
2387 } | 2394 } |
2388 | 2395 |
2389 static void yahoo_got_info(void *data, const char *url_text, size_t len) | 2396 static void yahoo_got_info(void *data, const char *url_text, size_t len) |
2390 { | 2397 { |
2398 YahooGetInfoData *info_data = (YahooGetInfoData *)data; | |
2391 char *stripped, *p; | 2399 char *stripped, *p; |
2392 char buf[1024]; | 2400 char buf[1024]; |
2401 gboolean found; | |
2402 gboolean has_info = FALSE; | |
2393 char *url_buffer; | 2403 char *url_buffer; |
2394 | 2404 |
2405 gaim_debug_info("yahoo", "In yahoo_got_info\n"); | |
2406 | |
2395 /* we failed to grab the profile URL */ | 2407 /* we failed to grab the profile URL */ |
2396 if (!url_text) { | 2408 if (url_text == NULL || strcmp(url_text, "") == 0) { |
2397 gaim_notify_formatted(data, NULL, _("Buddy Information"), NULL, | 2409 gaim_notify_formatted(info_data->gc, NULL, _("Buddy Information"), NULL, |
2398 _("<html><body><b>Error retrieving profile</b></body></html>"), | 2410 _("<html><body><b>Error retrieving profile</b></body></html>"), |
2399 NULL, NULL); | 2411 NULL, NULL); |
2400 | 2412 |
2401 return; | 2413 return; |
2402 } | 2414 } |
2407 * now, just tell them that we can't help them, and provide a link to the | 2419 * now, just tell them that we can't help them, and provide a link to the |
2408 * profile if they want to do the web browser thing. | 2420 * profile if they want to do the web browser thing. |
2409 */ | 2421 */ |
2410 p = strstr(url_text, "Adult Profiles Warning Message"); | 2422 p = strstr(url_text, "Adult Profiles Warning Message"); |
2411 if (p) { | 2423 if (p) { |
2412 strcpy(buf, _("<b>Sorry, profiles marked as containing adult content are not supported at this time.</b><br><br>\n")); | 2424 g_snprintf(buf, 1024, "<html><body>%s%s<a href=\"%s%s\">%s%s</a></body></html>", |
2413 gaim_markup_extract_info_field(url_text, buf, ".idname=", 0, "%26", 0, NULL, | 2425 _("<b>Sorry, profiles marked as containing adult content are not supported at this time.</b><br><br>\n"), |
2414 _("If you wish to view this profile, you will need to visit this link in your web browser"), | 2426 _("If you wish to view this profile, you will need to visit this link in your web browser<br>"), |
2415 1, YAHOO_PROFILE_URL); | 2427 YAHOO_PROFILE_URL, info_data->name, YAHOO_PROFILE_URL, info_data->name); |
2416 strcat(buf, "</body></html>\n"); | 2428 |
2417 gaim_notify_formatted(data, NULL, _("Buddy Information"), NULL, | 2429 gaim_notify_formatted(info_data->gc, NULL, _("Buddy Information"), NULL, |
2418 buf, NULL, NULL); | 2430 buf, NULL, NULL); |
2419 return; | 2431 return; |
2420 } | 2432 } |
2421 | 2433 |
2422 /* at the moment we don't support profile pages with languages other than | 2434 /* at the moment we don't support profile pages with languages other than |
2423 * english. the problem is, that every user may choose his/her own profile | 2435 * english. the problem is, that every user may choose his/her own profile |
2424 * language. this language has nothing to do with the preferences of the | 2436 * language. this language has nothing to do with the preferences of the |
2425 * user which looks at the profile | 2437 * user which looks at the profile |
2426 */ | 2438 */ |
2427 p = strstr(url_text, "Last Updated:"); | 2439 p = strstr(url_text, "Last Updated:"); |
2428 if (!p) { | 2440 if (!p) { |
2429 strcpy(buf, _("<b>Sorry, non-English profiles are not supported at this time.</b><br><br>\n")); | 2441 g_snprintf(buf, 1024, "<html><body>%s%s<a href=\"%s%s\">%s%s</a></body></html>", |
2430 gaim_markup_extract_info_field(url_text, buf, "<title>", 0, "'s Yahoo! Profile", 0, NULL, | 2442 _("<b>Sorry, non-English profiles are not supported at this time.</b><br><br>\n"), |
2431 _("If you wish to view this profile, you will need to visit this link in your web browser"), | 2443 _("If you wish to view this profile, you will need to visit this link in your web browser<br>"), |
2432 1, YAHOO_PROFILE_URL); | 2444 YAHOO_PROFILE_URL, info_data->name, YAHOO_PROFILE_URL, info_data->name); |
2433 strcat(buf, "</body></html>\n"); | 2445 |
2434 gaim_notify_formatted(data, NULL, _("Buddy Information"), NULL, | 2446 gaim_notify_formatted(info_data->gc, NULL, _("Buddy Information"), NULL, |
2435 buf, NULL, NULL); | 2447 buf, NULL, NULL); |
2436 return; | 2448 return; |
2437 } | 2449 } |
2438 | 2450 |
2439 url_buffer = g_strdup(url_text); | 2451 url_buffer = g_strdup(url_text); |
2440 | 2452 |
2441 /* gaim_markup_strip_html() doesn't strip out character entities like and · | 2453 /* |
2454 * gaim_markup_strip_html() doesn't strip out character entities like | |
2455 * and · | |
2442 */ | 2456 */ |
2443 while ((p = strstr(url_buffer, " ")) != NULL) { | 2457 while ((p = strstr(url_buffer, " ")) != NULL) { |
2444 memmove(p, p + 6, strlen(p + 6)); | 2458 memmove(p, p + 6, strlen(p + 6)); |
2445 url_buffer[strlen(url_buffer) - 6] = '\0'; | 2459 url_buffer[strlen(url_buffer) - 6] = '\0'; |
2446 } | 2460 } |
2456 } | 2470 } |
2457 | 2471 |
2458 /* nuke the html, it's easier than trying to parse the horrid stuff */ | 2472 /* nuke the html, it's easier than trying to parse the horrid stuff */ |
2459 stripped = gaim_markup_strip_html(url_buffer); | 2473 stripped = gaim_markup_strip_html(url_buffer); |
2460 | 2474 |
2475 gaim_debug_misc("yahoo", "stripped = %p\n", stripped); | |
2476 gaim_debug_misc("yahoo", "url_buffer = %p\n", url_buffer); | |
2477 | |
2461 /* gonna re-use the memory we've already got for url_buffer */ | 2478 /* gonna re-use the memory we've already got for url_buffer */ |
2462 strcpy(url_buffer, "<html><body>\n"); | 2479 strcpy(url_buffer, "<html><body>\n"); |
2463 | 2480 |
2464 /* extract their Yahoo! ID and put it in */ | 2481 /* extract their Yahoo! ID and put it in. Don't bother marking has_info as |
2465 gaim_markup_extract_info_field(stripped, url_buffer, "Yahoo! ID:", 2, "\n", 0, | 2482 * true, since the Yahoo! ID will always be there */ |
2483 found = gaim_markup_extract_info_field(stripped, url_buffer, "Yahoo! ID:", 2, "\n", 0, | |
2466 NULL, _("Yahoo! ID"), 0, NULL); | 2484 NULL, _("Yahoo! ID"), 0, NULL); |
2467 | 2485 |
2486 | |
2468 /* extract their Email address and put it in */ | 2487 /* extract their Email address and put it in */ |
2469 gaim_markup_extract_info_field(stripped, url_buffer, "My Email", 5, "\n", 0, | 2488 found = gaim_markup_extract_info_field(stripped, url_buffer, "My Email", 5, "\n", 0, |
2470 "Private", _("Email"), 0, NULL); | 2489 "Private", _("Email"), 0, NULL); |
2490 if(found) | |
2491 has_info = TRUE; | |
2471 | 2492 |
2472 /* extract the Nickname if it exists */ | 2493 /* extract the Nickname if it exists */ |
2473 gaim_markup_extract_info_field(stripped, url_buffer, "Nickname:", 1, "\n", '\n', | 2494 found = gaim_markup_extract_info_field(stripped, url_buffer, "Nickname:", 1, "\n", '\n', |
2474 NULL, _("Nickname"), 0, NULL); | 2495 NULL, _("Nickname"), 0, NULL); |
2496 if(found) | |
2497 has_info = TRUE; | |
2475 | 2498 |
2476 /* extract their RealName and put it in */ | 2499 /* extract their RealName and put it in */ |
2477 gaim_markup_extract_info_field(stripped, url_buffer, "RealName:", 1, "\n", '\n', | 2500 found = gaim_markup_extract_info_field(stripped, url_buffer, "RealName:", 1, "\n", '\n', |
2478 NULL, _("Realname"), 0, NULL); | 2501 NULL, _("Realname"), 0, NULL); |
2502 if(found) | |
2503 has_info = TRUE; | |
2479 | 2504 |
2480 /* extract their Location and put it in */ | 2505 /* extract their Location and put it in */ |
2481 gaim_markup_extract_info_field(stripped, url_buffer, "Location:", 2, "\n", '\n', | 2506 found = gaim_markup_extract_info_field(stripped, url_buffer, "Location:", 2, "\n", '\n', |
2482 NULL, _("Location"), 0, NULL); | 2507 NULL, _("Location"), 0, NULL); |
2508 if(found) | |
2509 has_info = TRUE; | |
2483 | 2510 |
2484 /* extract their Age and put it in */ | 2511 /* extract their Age and put it in */ |
2485 gaim_markup_extract_info_field(stripped, url_buffer, "Age:", 3, "\n", '\n', | 2512 found = gaim_markup_extract_info_field(stripped, url_buffer, "Age:", 3, "\n", '\n', |
2486 NULL, _("Age"), 0, NULL); | 2513 NULL, _("Age"), 0, NULL); |
2514 if(found) | |
2515 has_info = TRUE; | |
2487 | 2516 |
2488 /* extract their MaritalStatus and put it in */ | 2517 /* extract their MaritalStatus and put it in */ |
2489 gaim_markup_extract_info_field(stripped, url_buffer, "MaritalStatus:", 3, "\n", '\n', | 2518 found = gaim_markup_extract_info_field(stripped, url_buffer, "MaritalStatus:", 3, "\n", '\n', |
2490 "No Answer", _("Marital Status"), 0, NULL); | 2519 "No Answer", _("Marital Status"), 0, NULL); |
2520 if(found) | |
2521 has_info = TRUE; | |
2491 | 2522 |
2492 /* extract their Gender and put it in */ | 2523 /* extract their Gender and put it in */ |
2493 gaim_markup_extract_info_field(stripped, url_buffer, "Gender:", 3, "\n", '\n', | 2524 found = gaim_markup_extract_info_field(stripped, url_buffer, "Gender:", 3, "\n", '\n', |
2494 "No Answer", _("Gender"), 0, NULL); | 2525 "No Answer", _("Gender"), 0, NULL); |
2526 if(found) | |
2527 has_info = TRUE; | |
2495 | 2528 |
2496 /* extract their Occupation and put it in */ | 2529 /* extract their Occupation and put it in */ |
2497 gaim_markup_extract_info_field(stripped, url_buffer, "Occupation:", 2, "\n", '\n', | 2530 found = gaim_markup_extract_info_field(stripped, url_buffer, "Occupation:", 2, "\n", '\n', |
2498 NULL, _("Occupation"), 0, NULL); | 2531 NULL, _("Occupation"), 0, NULL); |
2532 if(found) | |
2533 has_info = TRUE; | |
2499 | 2534 |
2500 /* Hobbies, Latest News, and Favorite Quote are a bit different, since the | 2535 /* Hobbies, Latest News, and Favorite Quote are a bit different, since the |
2501 * values can contain embedded newlines... but any or all of them can also | 2536 * values can contain embedded newlines... but any or all of them can also |
2502 * not appear. The way we delimit them is to successively look for the next | 2537 * not appear. The way we delimit them is to successively look for the next |
2503 * one that _could_ appear, and if all else fails, we end the section by | 2538 * one that _could_ appear, and if all else fails, we end the section by |
2504 * looking for the 'Links' heading, which is the next thing to follow this | 2539 * looking for the 'Links' heading, which is the next thing to follow this |
2505 * bunch. | 2540 * bunch. |
2506 */ | 2541 */ |
2507 if (!gaim_markup_extract_info_field(stripped, url_buffer, "Hobbies:", 1, "Latest News", | 2542 |
2508 '\n', NULL, _("Hobbies"), 0, NULL)) | 2543 found = gaim_markup_extract_info_field(stripped, url_buffer, "Hobbies:", 1, "Latest News", |
2509 if (!gaim_markup_extract_info_field(stripped, url_buffer, "Hobbies:", 1, "Favorite Quote", | 2544 '\n', NULL, _("Hobbies"), 0, NULL); |
2510 '\n', NULL, _("Hobbies"), 0, NULL)) | 2545 if(!found) |
2511 gaim_markup_extract_info_field(stripped, url_buffer, "Hobbies:", 1, "Links", | 2546 { |
2547 found = gaim_markup_extract_info_field(stripped, url_buffer, "Hobbies:", 1, "Favorite Quote", | |
2548 '\n', NULL, _("Hobbies"), 0, NULL); | |
2549 if(!found) | |
2550 { | |
2551 found = gaim_markup_extract_info_field(stripped, url_buffer, "Hobbies:", 1, "Links", | |
2512 '\n', NULL, _("Hobbies"), 0, NULL); | 2552 '\n', NULL, _("Hobbies"), 0, NULL); |
2513 if (!gaim_markup_extract_info_field(stripped, url_buffer, "Latest News:", 1, "Favorite Quote", | 2553 if(found) |
2514 '\n', NULL, _("Latest News"), 0, NULL)) | 2554 has_info = TRUE; |
2515 gaim_markup_extract_info_field(stripped, url_buffer, "Latest News:", 1, "Links", | 2555 } |
2556 else | |
2557 has_info = TRUE; | |
2558 } | |
2559 else | |
2560 has_info = TRUE; | |
2561 | |
2562 found = gaim_markup_extract_info_field(stripped, url_buffer, "Latest News:", 1, "Favorite Quote", | |
2563 '\n', NULL, _("Latest News"), 0, NULL); | |
2564 if(!found) | |
2565 { | |
2566 found = gaim_markup_extract_info_field(stripped, url_buffer, "Latest News:", 1, "Links", | |
2516 '\n', NULL, _("Latest News"), 0, NULL); | 2567 '\n', NULL, _("Latest News"), 0, NULL); |
2517 gaim_markup_extract_info_field(stripped, url_buffer, "Favorite Quote:", 0, "Links", | 2568 if(found) |
2569 has_info = TRUE; | |
2570 } | |
2571 else | |
2572 has_info = TRUE; | |
2573 | |
2574 found = gaim_markup_extract_info_field(stripped, url_buffer, "Favorite Quote:", 0, "Links", | |
2518 '\n', NULL, _("Favorite Quote"), 0, NULL); | 2575 '\n', NULL, _("Favorite Quote"), 0, NULL); |
2576 if(found) | |
2577 has_info = TRUE; | |
2519 | 2578 |
2520 /* Home Page will either be "No home page specified", | 2579 /* Home Page will either be "No home page specified", |
2521 * or "Home Page: " and a link. */ | 2580 * or "Home Page: " and a link. */ |
2522 p = strstr(stripped, "No home page specified"); | 2581 p = strstr(stripped, "No home page specified"); |
2523 if (!p) | 2582 if(!p) |
2524 gaim_markup_extract_info_field(stripped, url_buffer, "Home Page:", 1, " ", 0, NULL, | 2583 { |
2584 found = gaim_markup_extract_info_field(stripped, url_buffer, "Home Page:", 1, " ", 0, NULL, | |
2525 _("Home Page"), 1, NULL); | 2585 _("Home Page"), 1, NULL); |
2586 if(found) | |
2587 has_info = TRUE; | |
2588 } | |
2526 | 2589 |
2527 /* Cool Link {1,2,3} is also different. If "No cool link specified" exists, | 2590 /* Cool Link {1,2,3} is also different. If "No cool link specified" exists, |
2528 * then we have none. If we have one however, we'll need to check and see if | 2591 * then we have none. If we have one however, we'll need to check and see if |
2529 * we have a second one. If we have a second one, we have to check to see if | 2592 * we have a second one. If we have a second one, we have to check to see if |
2530 * we have a third one. | 2593 * we have a third one. |
2531 */ | 2594 */ |
2532 p = strstr(stripped,"No cool link specified"); | 2595 p = strstr(stripped,"No cool link specified"); |
2533 if (!p) | 2596 if (!p) |
2534 if (gaim_markup_extract_info_field(stripped, url_buffer, "Cool Link 1:", 1, " ", 0, NULL, | 2597 { |
2535 _("Cool Link 1"), 1, NULL)) | 2598 found = gaim_markup_extract_info_field(stripped, url_buffer, "Cool Link 1:", 1, " ", 0, NULL, |
2536 if (gaim_markup_extract_info_field(stripped, url_buffer, "Cool Link 2:", 1, " ", 0, NULL, | 2599 _("Cool Link 1"), 1, NULL); |
2537 _("Cool Link 2"), 1, NULL)) | 2600 if(found) |
2601 { | |
2602 has_info = TRUE; | |
2603 found = gaim_markup_extract_info_field(stripped, url_buffer, "Cool Link 2:", 1, " ", 0, NULL, | |
2604 _("Cool Link 2"), 1, NULL); | |
2605 if(found) | |
2538 gaim_markup_extract_info_field(stripped, url_buffer, "Cool Link 3:", 1, " ", 0, NULL, | 2606 gaim_markup_extract_info_field(stripped, url_buffer, "Cool Link 3:", 1, " ", 0, NULL, |
2539 _("Cool Link 3"), 1, NULL); | 2607 _("Cool Link 3"), 1, NULL); |
2608 } | |
2609 } | |
2540 | 2610 |
2541 /* see if Member Since is there, and if so, extract it. */ | 2611 /* see if Member Since is there, and if so, extract it. */ |
2542 gaim_markup_extract_info_field(stripped, url_buffer, "Member Since:", 1, "Last Updated:", | 2612 found = gaim_markup_extract_info_field(stripped, url_buffer, "Member Since:", 1, "Last Updated:", |
2543 '\n', NULL, _("Member Since"), 0, NULL); | 2613 '\n', NULL, _("Member Since"), 0, NULL); |
2614 if(found) | |
2615 has_info = TRUE; | |
2544 | 2616 |
2545 /* extract the Last Updated date and put it in */ | 2617 /* extract the Last Updated date and put it in */ |
2546 gaim_markup_extract_info_field(stripped, url_buffer, "Last Updated:", 1, "\n", '\n', NULL, | 2618 found = gaim_markup_extract_info_field(stripped, url_buffer, "Last Updated:", 1, "\n", '\n', NULL, |
2547 _("Last Updated"), 0, NULL); | 2619 _("Last Updated"), 0, NULL); |
2620 if(found) | |
2621 has_info = TRUE; | |
2548 | 2622 |
2549 /* finish off the html */ | 2623 /* finish off the html */ |
2550 strcat(url_buffer, "</body></html>\n"); | 2624 strcat(url_buffer, "</body></html>\n"); |
2551 g_free(stripped); | 2625 g_free(stripped); |
2552 | 2626 |
2553 /* show it to the user */ | 2627 if(has_info) |
2554 gaim_notify_formatted(data, NULL, _("Buddy Information"), NULL, | 2628 { |
2555 url_buffer, NULL, NULL); | 2629 /* show it to the user */ |
2630 gaim_notify_formatted(info_data->gc, NULL, _("Buddy Information"), NULL, | |
2631 url_buffer, NULL, NULL); | |
2632 } | |
2633 else | |
2634 { | |
2635 char primary[256]; | |
2636 g_snprintf(primary, sizeof(primary), | |
2637 _("User information for %s unavailable"), info_data->name); | |
2638 gaim_notify_error(info_data->gc, NULL, primary, | |
2639 _("The user's profile is empty.")); | |
2640 } | |
2556 | 2641 |
2557 g_free(url_buffer); | 2642 g_free(url_buffer); |
2558 } | 2643 } |
2559 | 2644 |
2560 static void yahoo_get_info(GaimConnection *gc, const char *name) | 2645 static void yahoo_get_info(GaimConnection *gc, const char *name) |
2561 { | 2646 { |
2562 /* struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; */ | 2647 YahooGetInfoData *data; |
2563 char url[256]; | 2648 char *url; |
2564 g_snprintf(url, sizeof url, "%s%s", YAHOO_PROFILE_URL, name); | 2649 |
2565 gaim_url_fetch(url, FALSE, NULL, FALSE, yahoo_got_info, gc); | 2650 data = g_new0(YahooGetInfoData, 1); |
2651 data->gc = gc; | |
2652 data->name = g_strdup(name); | |
2653 | |
2654 url = g_strdup_printf("%s%s", YAHOO_PROFILE_URL, name); | |
2655 | |
2656 gaim_url_fetch(url, FALSE, NULL, FALSE, yahoo_got_info, data); | |
2657 | |
2658 g_free(url); | |
2566 } | 2659 } |
2567 | 2660 |
2568 static void yahoo_change_buddys_group(GaimConnection *gc, const char *who, | 2661 static void yahoo_change_buddys_group(GaimConnection *gc, const char *who, |
2569 const char *old_group, const char *new_group) | 2662 const char *old_group, const char *new_group) |
2570 { | 2663 { |