comparison src/protocols/yahoo/yahoo.c @ 6514:64d952098596

[gaim-migrate @ 7031] Nathan Poznick implemented yahoo info :-) please test and submit patches for bugs committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Wed, 20 Aug 2003 01:35:03 +0000
parents 63c449a1022f
children 7c14b35bc984
comparison
equal deleted inserted replaced
6513:63c449a1022f 6514:64d952098596
46 46
47 #define USEROPT_MAIL 0 47 #define USEROPT_MAIL 0
48 48
49 #define YAHOO_PAGER_HOST "scs.yahoo.com" 49 #define YAHOO_PAGER_HOST "scs.yahoo.com"
50 #define YAHOO_PAGER_PORT 5050 50 #define YAHOO_PAGER_PORT 5050
51 #define YAHOO_PROFILE_URL "http://profiles.yahoo.com/"
51 52
52 #define YAHOO_PROTO_VER 0x0900 53 #define YAHOO_PROTO_VER 0x0900
53 54
54 enum yahoo_service { /* these are easier to see in hex */ 55 enum yahoo_service { /* these are easier to see in hex */
55 YAHOO_SERVICE_LOGON = 1, 56 YAHOO_SERVICE_LOGON = 1,
1387 { 1388 {
1388 yahoo_dest_colorht(); 1389 yahoo_dest_colorht();
1389 return TRUE; 1390 return TRUE;
1390 } 1391 }
1391 1392
1393 static void yahoo_got_info(gpointer data, char *url_text, unsigned long len)
1394 {
1395 char *stripped,*p;
1396 char buf[1024];
1397
1398 /* we failed to grab the profile URL */
1399 if (!url_text) {
1400 g_show_info_text(NULL, NULL, 2,
1401 "<html><body><b>Error retrieving profile</b></body></html>", NULL);
1402 return;
1403 }
1404
1405 /* we don't yet support the multiple link level of the warning page for
1406 * 'adult' profiles, not to mention the fact that yahoo wants you to be
1407 * logged in (on the website) to be able to view an 'adult' profile. for
1408 * now, just tell them that we can't help them, and provide a link to the
1409 * profile if they want to do the web browser thing.
1410 */
1411 p = strstr(url_text, "Adult Profiles Warning Message");
1412 if (p) {
1413 strcpy(buf, "<b>Sorry, profiles marked as containing adult content are ");
1414 strcat(buf, "not supported at this time.</b><br><br>\n");
1415 info_extract_field(url_text, buf, ".idname=", 0, "%26", 0, NULL,
1416 "If you wish to view this profile, you will need to visit this link in your web browser",
1417 1, YAHOO_PROFILE_URL);
1418 strcat(buf, "</body></html>\n");
1419 g_show_info_text(NULL, NULL, 2, buf, NULL);
1420 return;
1421 }
1422
1423 /* strip_html() doesn't strip out character entities like &nbsp; and &#183;
1424 */
1425 while ((p = strstr(url_text, "&nbsp;")) != NULL) {
1426 memmove(p, p + 6, strlen(p + 6));
1427 url_text[strlen(url_text) - 6] = '\0';
1428 }
1429 while ((p = strstr(url_text, "&#183;")) != NULL) {
1430 memmove(p, p + 6, strlen(p + 6));
1431 url_text[strlen(url_text) - 6] = '\0';
1432 }
1433
1434 /* nuke the nasty \r's */
1435 while ((p = strchr(url_text, '\r')) != NULL) {
1436 memmove(p, p + 1, strlen(p + 1));
1437 url_text[strlen(url_text) - 1] = '\0';
1438 }
1439
1440 /* nuke the html, it's easier than trying to parse the horrid stuff */
1441 stripped = strip_html(url_text);
1442
1443 /* gonna re-use the memory we've already got for url_text */
1444 strcpy(url_text, "<html><body>\n");
1445
1446 /* extract their Yahoo! ID and put it in */
1447 info_extract_field(stripped, url_text, "Yahoo! ID:", 2, "\n", 0,
1448 NULL, "Yahoo! ID", 0, NULL);
1449
1450 /* extract their Email address and put it in */
1451 info_extract_field(stripped, url_text, "My Email", 5, "\n", 0,
1452 "Private", "Email", 0, NULL);
1453
1454 /* extract the Nickname if it exists */
1455 info_extract_field(stripped, url_text, "Nickname:", 1, "\n", '\n',
1456 NULL, "Nickname", 0, NULL);
1457
1458 /* extract their RealName and put it in */
1459 info_extract_field(stripped, url_text, "RealName:", 1, "\n", '\n',
1460 NULL, "Real Name", 0, NULL);
1461
1462 /* extract their Location and put it in */
1463 info_extract_field(stripped, url_text, "Location:", 2, "\n", '\n',
1464 NULL, "Location", 0, NULL);
1465
1466 /* extract their Age and put it in */
1467 info_extract_field(stripped, url_text, "Age:", 3, "\n", '\n',
1468 NULL, "Age", 0, NULL);
1469
1470 /* extract their MaritalStatus and put it in */
1471 info_extract_field(stripped, url_text, "MaritalStatus:", 3, "\n", '\n',
1472 "No Answer", "Marital Status", 0, NULL);
1473
1474 /* extract their Gender and put it in */
1475 info_extract_field(stripped, url_text, "Gender:", 3, "\n", '\n',
1476 "No Answer", "Gender", 0, NULL);
1477
1478 /* extract their Occupation and put it in */
1479 info_extract_field(stripped, url_text, "Occupation:", 2, "\n", '\n',
1480 NULL, "Occupation", 0, NULL);
1481
1482 /* Hobbies, Latest News, and Favorite Quote are a bit different, since the
1483 * values can contain embedded newlines... but any or all of them can also
1484 * not appear. The way we delimit them is to successively look for the next
1485 * one that _could_ appear, and if all else fails, we end the section by
1486 * looking for the 'Links' heading, which is the next thing to follow this
1487 * bunch.
1488 */
1489 if (!info_extract_field(stripped, url_text, "Hobbies:", 1, "Latest News",
1490 '\n', NULL, "Hobbies", 0, NULL))
1491 if (!info_extract_field(stripped, url_text, "Hobbies:", 1, "Favorite Quote",
1492 '\n', NULL, "Hobbies", 0, NULL))
1493 info_extract_field(stripped, url_text, "Hobbies:", 1, "Links",
1494 '\n', NULL, "Hobbies", 0, NULL);
1495 if (!info_extract_field(stripped, url_text, "Latest News:", 1, "Favorite Quote",
1496 '\n', NULL, "Latest News", 0, NULL))
1497 info_extract_field(stripped, url_text, "Latest News:", 1, "Links",
1498 '\n', NULL, "Latest News", 0, NULL);
1499 info_extract_field(stripped, url_text, "Favorite Quote:", 0, "Links",
1500 '\n', NULL, "Favorite Quote", 0, NULL);
1501
1502 /* Home Page will either be "No home page specified",
1503 * or "Home Page: " and a link. */
1504 p = strstr(stripped, "No home page specified");
1505 if (!p)
1506 info_extract_field(stripped, url_text, "Home Page:", 1, " ", 0, NULL,
1507 "Home Page", 1, NULL);
1508
1509 /* Cool Link {1,2,3} is also different. If "No cool link specified" exists,
1510 * then we have none. If we have one however, we'll need to check and see if
1511 * we have a second one. If we have a second one, we have to check to see if
1512 * we have a third one.
1513 */
1514 p = strstr(stripped,"No cool link specified");
1515 if (!p)
1516 if (info_extract_field(stripped, url_text, "Cool Link 1:", 1, " ", 0, NULL,
1517 "Cool Link 1", 1, NULL))
1518 if (info_extract_field(stripped, url_text, "Cool Link 2:", 1, " ", 0, NULL,
1519 "Cool Link 2", 1, NULL))
1520 info_extract_field(stripped, url_text, "Cool Link 3:", 1, " ", 0, NULL,
1521 "Cool Link 3", 1, NULL);
1522
1523 /* see if Member Since is there, and if so, extract it. */
1524 info_extract_field(stripped, url_text, "Member Since:", 1, "Last Updated:",
1525 '\n', NULL, "Member Since", 0, NULL);
1526
1527 /* extract the Last Updated date and put it in */
1528 info_extract_field(stripped, url_text, "Last Updated:", 1, "\n", '\n', NULL,
1529 "Last Updated", 0, NULL);
1530
1531 /* finish off the html */
1532 strcat(url_text, "</body></html>\n");
1533 g_free(stripped);
1534
1535 /* show it to the user */
1536 g_show_info_text(NULL, NULL, 2, url_text, NULL);
1537 }
1538
1539 static void yahoo_get_info(GaimConnection *gc, const char *name)
1540 {
1541 /* struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; */
1542 char url[256];
1543 g_snprintf(url, sizeof url, "%s%s", YAHOO_PROFILE_URL, name);
1544 grab_url(url, FALSE, yahoo_got_info, NULL);
1545 }
1546
1392 static GaimPlugin *my_protocol = NULL; 1547 static GaimPlugin *my_protocol = NULL;
1393 1548
1394 static GaimPluginProtocolInfo prpl_info = 1549 static GaimPluginProtocolInfo prpl_info =
1395 { 1550 {
1396 GAIM_PROTO_YAHOO, 1551 GAIM_PROTO_YAHOO,
1408 yahoo_login, 1563 yahoo_login,
1409 yahoo_close, 1564 yahoo_close,
1410 yahoo_send_im, 1565 yahoo_send_im,
1411 NULL, 1566 NULL,
1412 yahoo_send_typing, 1567 yahoo_send_typing,
1413 NULL, 1568 yahoo_get_info,
1414 yahoo_set_away, 1569 yahoo_set_away,
1415 NULL, 1570 NULL,
1416 NULL, 1571 NULL,
1417 NULL, 1572 NULL,
1418 NULL, 1573 NULL,