Mercurial > pidgin
comparison src/protocols/yahoo/yahoo.c @ 7094:2343c3aa1dec
[gaim-migrate @ 7659]
grab_url() and parse_url() are gone, replaced with gaim_url_fetch() and
gaim_url_parse(). They were also moved to util.[ch].
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Wed, 01 Oct 2003 03:01:25 +0000 |
parents | 0909ebf6fb28 |
children | c8bf2da398e3 |
comparison
equal
deleted
inserted
replaced
7093:3650612c7daa | 7094:2343c3aa1dec |
---|---|
2385 { | 2385 { |
2386 yahoo_dest_colorht(); | 2386 yahoo_dest_colorht(); |
2387 return TRUE; | 2387 return TRUE; |
2388 } | 2388 } |
2389 | 2389 |
2390 static void yahoo_got_info(gpointer data, char *url_text, unsigned long len) | 2390 static void yahoo_got_info(void *data, const char *url_text, size_t len) |
2391 { | 2391 { |
2392 char *stripped,*p; | 2392 char *stripped, *p; |
2393 char buf[1024]; | 2393 char buf[1024]; |
2394 char *url_buffer; | |
2394 | 2395 |
2395 /* we failed to grab the profile URL */ | 2396 /* we failed to grab the profile URL */ |
2396 if (!url_text) { | 2397 if (!url_text) { |
2397 gaim_notify_formatted(data, NULL, _("Buddy Information"), NULL, | 2398 gaim_notify_formatted(data, NULL, _("Buddy Information"), NULL, |
2398 _("<html><body><b>Error retrieving profile</b></body></html>"), | 2399 _("<html><body><b>Error retrieving profile</b></body></html>"), |
2434 gaim_notify_formatted(data, NULL, _("Buddy Information"), NULL, | 2435 gaim_notify_formatted(data, NULL, _("Buddy Information"), NULL, |
2435 buf, NULL, NULL); | 2436 buf, NULL, NULL); |
2436 return; | 2437 return; |
2437 } | 2438 } |
2438 | 2439 |
2440 url_buffer = g_strdup(url_text); | |
2441 | |
2439 /* strip_html() doesn't strip out character entities like and · | 2442 /* strip_html() doesn't strip out character entities like and · |
2440 */ | 2443 */ |
2441 while ((p = strstr(url_text, " ")) != NULL) { | 2444 while ((p = strstr(url_buffer, " ")) != NULL) { |
2442 memmove(p, p + 6, strlen(p + 6)); | 2445 memmove(p, p + 6, strlen(p + 6)); |
2443 url_text[strlen(url_text) - 6] = '\0'; | 2446 url_buffer[strlen(url_buffer) - 6] = '\0'; |
2444 } | 2447 } |
2445 while ((p = strstr(url_text, "·")) != NULL) { | 2448 while ((p = strstr(url_buffer, "·")) != NULL) { |
2446 memmove(p, p + 6, strlen(p + 6)); | 2449 memmove(p, p + 6, strlen(p + 6)); |
2447 url_text[strlen(url_text) - 6] = '\0'; | 2450 url_buffer[strlen(url_buffer) - 6] = '\0'; |
2448 } | 2451 } |
2449 | 2452 |
2450 /* nuke the nasty \r's */ | 2453 /* nuke the nasty \r's */ |
2451 while ((p = strchr(url_text, '\r')) != NULL) { | 2454 while ((p = strchr(url_buffer, '\r')) != NULL) { |
2452 memmove(p, p + 1, strlen(p + 1)); | 2455 memmove(p, p + 1, strlen(p + 1)); |
2453 url_text[strlen(url_text) - 1] = '\0'; | 2456 url_buffer[strlen(url_buffer) - 1] = '\0'; |
2454 } | 2457 } |
2455 | 2458 |
2456 /* nuke the html, it's easier than trying to parse the horrid stuff */ | 2459 /* nuke the html, it's easier than trying to parse the horrid stuff */ |
2457 stripped = strip_html(url_text); | 2460 stripped = strip_html(url_buffer); |
2458 | 2461 |
2459 /* gonna re-use the memory we've already got for url_text */ | 2462 /* gonna re-use the memory we've already got for url_buffer */ |
2460 strcpy(url_text, "<html><body>\n"); | 2463 strcpy(url_buffer, "<html><body>\n"); |
2461 | 2464 |
2462 /* extract their Yahoo! ID and put it in */ | 2465 /* extract their Yahoo! ID and put it in */ |
2463 info_extract_field(stripped, url_text, "Yahoo! ID:", 2, "\n", 0, | 2466 info_extract_field(stripped, url_buffer, "Yahoo! ID:", 2, "\n", 0, |
2464 NULL, _("Yahoo! ID"), 0, NULL); | 2467 NULL, _("Yahoo! ID"), 0, NULL); |
2465 | 2468 |
2466 /* extract their Email address and put it in */ | 2469 /* extract their Email address and put it in */ |
2467 info_extract_field(stripped, url_text, "My Email", 5, "\n", 0, | 2470 info_extract_field(stripped, url_buffer, "My Email", 5, "\n", 0, |
2468 "Private", _("Email"), 0, NULL); | 2471 "Private", _("Email"), 0, NULL); |
2469 | 2472 |
2470 /* extract the Nickname if it exists */ | 2473 /* extract the Nickname if it exists */ |
2471 info_extract_field(stripped, url_text, "Nickname:", 1, "\n", '\n', | 2474 info_extract_field(stripped, url_buffer, "Nickname:", 1, "\n", '\n', |
2472 NULL, _("Nickname"), 0, NULL); | 2475 NULL, _("Nickname"), 0, NULL); |
2473 | 2476 |
2474 /* extract their RealName and put it in */ | 2477 /* extract their RealName and put it in */ |
2475 info_extract_field(stripped, url_text, "RealName:", 1, "\n", '\n', | 2478 info_extract_field(stripped, url_buffer, "RealName:", 1, "\n", '\n', |
2476 NULL, _("Realname"), 0, NULL); | 2479 NULL, _("Realname"), 0, NULL); |
2477 | 2480 |
2478 /* extract their Location and put it in */ | 2481 /* extract their Location and put it in */ |
2479 info_extract_field(stripped, url_text, "Location:", 2, "\n", '\n', | 2482 info_extract_field(stripped, url_buffer, "Location:", 2, "\n", '\n', |
2480 NULL, _("Location"), 0, NULL); | 2483 NULL, _("Location"), 0, NULL); |
2481 | 2484 |
2482 /* extract their Age and put it in */ | 2485 /* extract their Age and put it in */ |
2483 info_extract_field(stripped, url_text, "Age:", 3, "\n", '\n', | 2486 info_extract_field(stripped, url_buffer, "Age:", 3, "\n", '\n', |
2484 NULL, _("Age"), 0, NULL); | 2487 NULL, _("Age"), 0, NULL); |
2485 | 2488 |
2486 /* extract their MaritalStatus and put it in */ | 2489 /* extract their MaritalStatus and put it in */ |
2487 info_extract_field(stripped, url_text, "MaritalStatus:", 3, "\n", '\n', | 2490 info_extract_field(stripped, url_buffer, "MaritalStatus:", 3, "\n", '\n', |
2488 "No Answer", _("Marital Status"), 0, NULL); | 2491 "No Answer", _("Marital Status"), 0, NULL); |
2489 | 2492 |
2490 /* extract their Gender and put it in */ | 2493 /* extract their Gender and put it in */ |
2491 info_extract_field(stripped, url_text, "Gender:", 3, "\n", '\n', | 2494 info_extract_field(stripped, url_buffer, "Gender:", 3, "\n", '\n', |
2492 "No Answer", _("Gender"), 0, NULL); | 2495 "No Answer", _("Gender"), 0, NULL); |
2493 | 2496 |
2494 /* extract their Occupation and put it in */ | 2497 /* extract their Occupation and put it in */ |
2495 info_extract_field(stripped, url_text, "Occupation:", 2, "\n", '\n', | 2498 info_extract_field(stripped, url_buffer, "Occupation:", 2, "\n", '\n', |
2496 NULL, _("Occupation"), 0, NULL); | 2499 NULL, _("Occupation"), 0, NULL); |
2497 | 2500 |
2498 /* Hobbies, Latest News, and Favorite Quote are a bit different, since the | 2501 /* Hobbies, Latest News, and Favorite Quote are a bit different, since the |
2499 * values can contain embedded newlines... but any or all of them can also | 2502 * values can contain embedded newlines... but any or all of them can also |
2500 * not appear. The way we delimit them is to successively look for the next | 2503 * not appear. The way we delimit them is to successively look for the next |
2501 * one that _could_ appear, and if all else fails, we end the section by | 2504 * one that _could_ appear, and if all else fails, we end the section by |
2502 * looking for the 'Links' heading, which is the next thing to follow this | 2505 * looking for the 'Links' heading, which is the next thing to follow this |
2503 * bunch. | 2506 * bunch. |
2504 */ | 2507 */ |
2505 if (!info_extract_field(stripped, url_text, "Hobbies:", 1, "Latest News", | 2508 if (!info_extract_field(stripped, url_buffer, "Hobbies:", 1, "Latest News", |
2506 '\n', NULL, _("Hobbies"), 0, NULL)) | 2509 '\n', NULL, _("Hobbies"), 0, NULL)) |
2507 if (!info_extract_field(stripped, url_text, "Hobbies:", 1, "Favorite Quote", | 2510 if (!info_extract_field(stripped, url_buffer, "Hobbies:", 1, "Favorite Quote", |
2508 '\n', NULL, _("Hobbies"), 0, NULL)) | 2511 '\n', NULL, _("Hobbies"), 0, NULL)) |
2509 info_extract_field(stripped, url_text, "Hobbies:", 1, "Links", | 2512 info_extract_field(stripped, url_buffer, "Hobbies:", 1, "Links", |
2510 '\n', NULL, _("Hobbies"), 0, NULL); | 2513 '\n', NULL, _("Hobbies"), 0, NULL); |
2511 if (!info_extract_field(stripped, url_text, "Latest News:", 1, "Favorite Quote", | 2514 if (!info_extract_field(stripped, url_buffer, "Latest News:", 1, "Favorite Quote", |
2512 '\n', NULL, _("Latest News"), 0, NULL)) | 2515 '\n', NULL, _("Latest News"), 0, NULL)) |
2513 info_extract_field(stripped, url_text, "Latest News:", 1, "Links", | 2516 info_extract_field(stripped, url_buffer, "Latest News:", 1, "Links", |
2514 '\n', NULL, _("Latest News"), 0, NULL); | 2517 '\n', NULL, _("Latest News"), 0, NULL); |
2515 info_extract_field(stripped, url_text, "Favorite Quote:", 0, "Links", | 2518 info_extract_field(stripped, url_buffer, "Favorite Quote:", 0, "Links", |
2516 '\n', NULL, _("Favorite Quote"), 0, NULL); | 2519 '\n', NULL, _("Favorite Quote"), 0, NULL); |
2517 | 2520 |
2518 /* Home Page will either be "No home page specified", | 2521 /* Home Page will either be "No home page specified", |
2519 * or "Home Page: " and a link. */ | 2522 * or "Home Page: " and a link. */ |
2520 p = strstr(stripped, "No home page specified"); | 2523 p = strstr(stripped, "No home page specified"); |
2521 if (!p) | 2524 if (!p) |
2522 info_extract_field(stripped, url_text, "Home Page:", 1, " ", 0, NULL, | 2525 info_extract_field(stripped, url_buffer, "Home Page:", 1, " ", 0, NULL, |
2523 _("Home Page"), 1, NULL); | 2526 _("Home Page"), 1, NULL); |
2524 | 2527 |
2525 /* Cool Link {1,2,3} is also different. If "No cool link specified" exists, | 2528 /* Cool Link {1,2,3} is also different. If "No cool link specified" exists, |
2526 * then we have none. If we have one however, we'll need to check and see if | 2529 * then we have none. If we have one however, we'll need to check and see if |
2527 * we have a second one. If we have a second one, we have to check to see if | 2530 * we have a second one. If we have a second one, we have to check to see if |
2528 * we have a third one. | 2531 * we have a third one. |
2529 */ | 2532 */ |
2530 p = strstr(stripped,"No cool link specified"); | 2533 p = strstr(stripped,"No cool link specified"); |
2531 if (!p) | 2534 if (!p) |
2532 if (info_extract_field(stripped, url_text, "Cool Link 1:", 1, " ", 0, NULL, | 2535 if (info_extract_field(stripped, url_buffer, "Cool Link 1:", 1, " ", 0, NULL, |
2533 _("Cool Link 1"), 1, NULL)) | 2536 _("Cool Link 1"), 1, NULL)) |
2534 if (info_extract_field(stripped, url_text, "Cool Link 2:", 1, " ", 0, NULL, | 2537 if (info_extract_field(stripped, url_buffer, "Cool Link 2:", 1, " ", 0, NULL, |
2535 _("Cool Link 2"), 1, NULL)) | 2538 _("Cool Link 2"), 1, NULL)) |
2536 info_extract_field(stripped, url_text, "Cool Link 3:", 1, " ", 0, NULL, | 2539 info_extract_field(stripped, url_buffer, "Cool Link 3:", 1, " ", 0, NULL, |
2537 _("Cool Link 3"), 1, NULL); | 2540 _("Cool Link 3"), 1, NULL); |
2538 | 2541 |
2539 /* see if Member Since is there, and if so, extract it. */ | 2542 /* see if Member Since is there, and if so, extract it. */ |
2540 info_extract_field(stripped, url_text, "Member Since:", 1, "Last Updated:", | 2543 info_extract_field(stripped, url_buffer, "Member Since:", 1, "Last Updated:", |
2541 '\n', NULL, _("Member Since"), 0, NULL); | 2544 '\n', NULL, _("Member Since"), 0, NULL); |
2542 | 2545 |
2543 /* extract the Last Updated date and put it in */ | 2546 /* extract the Last Updated date and put it in */ |
2544 info_extract_field(stripped, url_text, "Last Updated:", 1, "\n", '\n', NULL, | 2547 info_extract_field(stripped, url_buffer, "Last Updated:", 1, "\n", '\n', NULL, |
2545 _("Last Updated"), 0, NULL); | 2548 _("Last Updated"), 0, NULL); |
2546 | 2549 |
2547 /* finish off the html */ | 2550 /* finish off the html */ |
2548 strcat(url_text, "</body></html>\n"); | 2551 strcat(url_buffer, "</body></html>\n"); |
2549 g_free(stripped); | 2552 g_free(stripped); |
2550 | 2553 |
2551 /* show it to the user */ | 2554 /* show it to the user */ |
2552 gaim_notify_formatted(data, NULL, _("Buddy Information"), NULL, | 2555 gaim_notify_formatted(data, NULL, _("Buddy Information"), NULL, |
2553 url_text, NULL, NULL); | 2556 url_buffer, NULL, NULL); |
2557 | |
2558 g_free(url_buffer); | |
2554 } | 2559 } |
2555 | 2560 |
2556 static void yahoo_get_info(GaimConnection *gc, const char *name) | 2561 static void yahoo_get_info(GaimConnection *gc, const char *name) |
2557 { | 2562 { |
2558 /* struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; */ | 2563 /* struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; */ |
2559 char url[256]; | 2564 char url[256]; |
2560 g_snprintf(url, sizeof url, "%s%s", YAHOO_PROFILE_URL, name); | 2565 g_snprintf(url, sizeof url, "%s%s", YAHOO_PROFILE_URL, name); |
2561 grab_url(url, FALSE, yahoo_got_info, gc, NULL, 0); | 2566 gaim_url_fetch(url, FALSE, NULL, FALSE, yahoo_got_info, gc); |
2562 } | 2567 } |
2563 | 2568 |
2564 static void yahoo_change_buddys_group(GaimConnection *gc, const char *who, | 2569 static void yahoo_change_buddys_group(GaimConnection *gc, const char *who, |
2565 const char *old_group, const char *new_group) | 2570 const char *old_group, const char *new_group) |
2566 { | 2571 { |