comparison libgaim/protocols/msn/msn.c @ 20390:d634f88e25d8

msn.tgz from SF Patch #1621854 from Ka-Hing Cheung "This tarball brings soc-2006-msnp13 up to head. In addition to that it also fixes a crash with sending offline messages. I wasn't able to generate a diff against that branch, svn seems to insist on diff'ing against HEAD after I run the merge command. After running `svn merge -r 16309:HEAD https://gaim.svn.sourceforge.net/svnroot/gaim/trunk` on the soc-2006-msnp13 you can replace the msn directory with the attached tarball. The fix for offline messaging is on msn.c:901: if (!session->oim) session->oim = msn_oim_new(session)" committer: Richard Laager <rlaager@wiktel.com>
author Ka-Hing Cheung <khc@hxbc.us>
date Sun, 15 Apr 2007 02:18:17 +0000
parents e354528c4163
children 0b0ecee55091 9755b2f7bb0f
comparison
equal deleted inserted replaced
20389:e354528c4163 20390:d634f88e25d8
65 typedef struct 65 typedef struct
66 { 66 {
67 MsnGetInfoData *info_data; 67 MsnGetInfoData *info_data;
68 char *stripped; 68 char *stripped;
69 char *url_buffer; 69 char *url_buffer;
70 GString *s; 70 GaimNotifyUserInfo *user_info;
71 char *photo_url_text; 71 char *photo_url_text;
72 char *tooltip_text;
73 const char *title;
74 72
75 } MsnGetInfoStepTwoData; 73 } MsnGetInfoStepTwoData;
76 74
77 static const char * 75 static const char *
78 msn_normalize(const GaimAccount *account, const char *str) 76 msn_normalize(const GaimAccount *account, const char *str)
560 558
561 return NULL; 559 return NULL;
562 } 560 }
563 561
564 static void 562 static void
565 msn_tooltip_text(GaimBuddy *buddy, GString *str, gboolean full) 563 msn_tooltip_text(GaimBuddy *buddy, GaimNotifyUserInfo *user_info, gboolean full)
566 { 564 {
567 MsnUser *user; 565 MsnUser *user;
568 GaimPresence *presence = gaim_buddy_get_presence(buddy); 566 GaimPresence *presence = gaim_buddy_get_presence(buddy);
569 GaimStatus *status = gaim_presence_get_active_status(presence); 567 GaimStatus *status = gaim_presence_get_active_status(presence);
570 568
571 user = buddy->proto_data; 569 user = buddy->proto_data;
572 570
571
573 if (gaim_presence_is_online(presence)) 572 if (gaim_presence_is_online(presence))
574 { 573 {
575 char *psm; 574 char *psm;
576 psm = msn_status_text(buddy); 575 psm = msn_status_text(buddy);
577 if (psm) 576
578 g_string_append_printf(str, _("\n<b>%s:</b> %s"), _("Psm"),psm); 577 gaim_notify_user_info_add_pair(user_info, _("Status"),
579 g_free(psm); 578 (gaim_presence_is_idle(presence) ? _("Idle") : gaim_status_get_name(status)));
580 579 if (psm) {
581 g_string_append_printf(str, _("\n<b>%s:</b> %s"), _("Status"), 580 gaim_notify_user_info_add_pair(user_info, _("PSM"), psm);
582 gaim_presence_is_idle(presence) ? 581 g_free(psm);
583 _("Idle") : gaim_status_get_name(status)); 582 }
584 } 583 }
585 584
586 if (full && user) 585 if (full && user)
587 { 586 {
588 g_string_append_printf(str, _("\n<b>%s:</b> %s"), _("Has you"), 587 gaim_notify_user_info_add_pair(user_info, _("Has you"),
589 (user->list_op & (1 << MSN_LIST_RL)) ? 588 ((user->list_op & (1 << MSN_LIST_RL)) ? _("Yes") : _("No")));
590 _("Yes") : _("No")); 589 }
591 590
592 /* XXX: This is being shown in non-full tooltips because the 591 /* XXX: This is being shown in non-full tooltips because the
593 * XXX: blocked icon overlay isn't always accurate for MSN. 592 * XXX: blocked icon overlay isn't always accurate for MSN.
594 * XXX: This can die as soon as gaim_privacy_check() knows that 593 * XXX: This can die as soon as gaim_privacy_check() knows that
595 * XXX: this prpl always honors both the allow and deny lists. */ 594 * XXX: this prpl always honors both the allow and deny lists. */
596 if (user) 595 if (user)
597 g_string_append_printf(str, _("\n<b>%s:</b> %s"), _("Blocked"), 596 {
598 (user->list_op & (1 << MSN_LIST_BL)) ? 597 gaim_notify_user_info_add_pair(user_info, _("Blocked"),
599 _("Yes") : _("No")); 598 ((user->list_op & (1 << MSN_LIST_BL)) ? _("Yes") : _("No")));
600 } 599 }
601 } 600 }
602 601
603 static GList * 602 static GList *
604 msn_status_types(GaimAccount *account) 603 msn_status_types(GaimAccount *account)
605 { 604 {
606 GaimStatusType *status; 605 GaimStatusType *status;
607 GList *types = NULL; 606 GList *types = NULL;
608
609 #if 0 607 #if 0
610 status = gaim_status_type_new_full(GAIM_STATUS_AVAILABLE, 608 status = gaim_status_type_new_full(GAIM_STATUS_AVAILABLE,
611 NULL, NULL, FALSE, TRUE, FALSE); 609 NULL, NULL, FALSE, TRUE, FALSE);
612 #endif 610 #endif
613 status = gaim_status_type_new_with_attrs( 611 status = gaim_status_type_new_with_attrs(
631 status = gaim_status_type_new_with_attrs( 629 status = gaim_status_type_new_with_attrs(
632 GAIM_STATUS_AWAY, "busy", _("Busy"), TRUE, TRUE, FALSE, 630 GAIM_STATUS_AWAY, "busy", _("Busy"), TRUE, TRUE, FALSE,
633 "message", _("Message"), gaim_value_new(GAIM_TYPE_STRING), 631 "message", _("Message"), gaim_value_new(GAIM_TYPE_STRING),
634 NULL); 632 NULL);
635 types = g_list_append(types, status); 633 types = g_list_append(types, status);
636
637 status = gaim_status_type_new_with_attrs( 634 status = gaim_status_type_new_with_attrs(
638 GAIM_STATUS_AWAY, "phone", _("On the Phone"), TRUE, TRUE, FALSE, 635 GAIM_STATUS_AWAY, "phone", _("On the Phone"), TRUE, TRUE, FALSE,
639 "message", _("Message"), gaim_value_new(GAIM_TYPE_STRING), 636 "message", _("Message"), gaim_value_new(GAIM_TYPE_STRING),
640 NULL); 637 NULL);
641 types = g_list_append(types, status); 638 types = g_list_append(types, status);
642
643 status = gaim_status_type_new_with_attrs( 639 status = gaim_status_type_new_with_attrs(
644 GAIM_STATUS_AWAY, "lunch", _("Out to Lunch"), TRUE, TRUE, FALSE, 640 GAIM_STATUS_AWAY, "lunch", _("Out to Lunch"), TRUE, TRUE, FALSE,
645 "message", _("Message"), gaim_value_new(GAIM_TYPE_STRING), 641 "message", _("Message"), gaim_value_new(GAIM_TYPE_STRING),
646 NULL); 642 NULL);
647 types = g_list_append(types, status); 643 types = g_list_append(types, status);
899 MsnOim *oim; 895 MsnOim *oim;
900 char *friendname; 896 char *friendname;
901 897
902 gaim_debug_info("MaYuan","prepare to send offline Message\n"); 898 gaim_debug_info("MaYuan","prepare to send offline Message\n");
903 session = gc->proto_data; 899 session = gc->proto_data;
900 /* XXX/khc: hack */
901 if (!session->oim)
902 session->oim = msn_oim_new(session);
903
904 oim = session->oim; 904 oim = session->oim;
905 friendname = msn_encode_mime(account->username); 905 friendname = msn_encode_mime(account->username);
906 msn_oim_prep_send_msg_info(oim, 906 msn_oim_prep_send_msg_info(oim,
907 gaim_account_get_username(account),friendname,who, 907 gaim_account_get_username(account),friendname,who,
908 message); 908 message);
909 msn_oim_send_msg(oim); 909 msn_oim_send_msg(oim);
910 } 910 }
911 else
912 {
913 char *body_str, *body_enc, *pre, *post;
914 const char *format;
915 /*
916 * In MSN, you can't send messages to yourself, so
917 * we'll fake like we received it ;)
918 */
919 body_str = msn_message_to_string(msg);
920 body_enc = g_markup_escape_text(body_str, -1);
921 g_free(body_str);
922
923 format = msn_message_get_attr(msg, "X-MMS-IM-Format");
924 msn_parse_format(format, &pre, &post);
925 body_str = g_strdup_printf("%s%s%s", pre ? pre : "",
926 body_enc ? body_enc : "", post ? post : "");
927 g_free(body_enc);
928 g_free(pre);
929 g_free(post);
930
931 serv_got_typing_stopped(gc, who);
932 serv_got_im(gc, who, body_str, flags, time(NULL));
933 g_free(body_str);
934 }
935
936 msn_message_destroy(msg);
937
938 return 1; 911 return 1;
939 } 912 }
940 913
941 static unsigned int 914 static unsigned int
942 msn_send_typing(GaimConnection *gc, const char *who, GaimTypingState state) 915 msn_send_typing(GaimConnection *gc, const char *who, GaimTypingState state)
992 GaimConnection *gc; 965 GaimConnection *gc;
993 MsnSession *session; 966 MsnSession *session;
994 967
995 gc = gaim_account_get_connection(account); 968 gc = gaim_account_get_connection(account);
996 969
997 if (gc != NULL) 970 if (gc != NULL){
998 {
999 session = gc->proto_data; 971 session = gc->proto_data;
1000 msn_change_status(session); 972 msn_change_status(session);
1001 } 973 }
1002 } 974 }
1003 975
1070 1042
1071 session = gc->proto_data; 1043 session = gc->proto_data;
1072 userlist = session->userlist; 1044 userlist = session->userlist;
1073 who = msn_normalize(gc->account, buddy->name); 1045 who = msn_normalize(gc->account, buddy->name);
1074 1046
1047 gaim_debug_info("MaYuan","add user:{%s} to group:{%s}\n",who,group->name);
1075 if (!session->logged_in) 1048 if (!session->logged_in)
1076 { 1049 {
1077 #if 0 1050 #if 0
1078 fake_userlist_add_buddy(session->sync_userlist, who, MSN_LIST_FL, 1051 fake_userlist_add_buddy(session->sync_userlist, who, MSN_LIST_FL,
1079 group ? group->name : NULL); 1052 group ? group->name : NULL);
1446 if (group_id != NULL){ 1419 if (group_id != NULL){
1447 msn_del_group(session,group_id); 1420 msn_del_group(session,group_id);
1448 } 1421 }
1449 } 1422 }
1450 1423
1451 static char * 1424 /**
1452 msn_tooltip_info_text(MsnGetInfoData *info_data) 1425 * Extract info text from info_data and add it to user_info
1453 { 1426 */
1454 GString *s; 1427 static gboolean
1428 msn_tooltip_extract_info_text(GaimNotifyUserInfo *user_info, MsnGetInfoData *info_data)
1429 {
1455 GaimBuddy *b; 1430 GaimBuddy *b;
1456
1457 s = g_string_sized_new(80); /* wild guess */
1458 1431
1459 b = gaim_find_buddy(gaim_connection_get_account(info_data->gc), 1432 b = gaim_find_buddy(gaim_connection_get_account(info_data->gc),
1460 info_data->name); 1433 info_data->name);
1461 1434
1462 if (b){ 1435 if (b){
1463 GString *str = g_string_new("");
1464 char *tmp; 1436 char *tmp;
1465 1437
1466 if (b->alias && b->alias[0]){ 1438 if (b->alias && b->alias[0]){
1467 char *aliastext = g_markup_escape_text(b->alias, -1); 1439 char *aliastext = g_markup_escape_text(b->alias, -1);
1468 g_string_append_printf(s, _("<b>Alias:</b> %s<br>"), aliastext); 1440 gaim_notify_user_info_add_pair(user_info, _("Alias"), aliastext);
1469 g_free(aliastext); 1441 g_free(aliastext);
1470 } 1442 }
1471 1443
1472 if (b->server_alias){ 1444 if (b->server_alias){
1473 char *nicktext = g_markup_escape_text(b->server_alias, -1); 1445 char *nicktext = g_markup_escape_text(b->server_alias, -1);
1474 g_string_append_printf(s, _("<b>%s:</b> "), _("Nickname")); 1446 tmp = g_strdup_printf("<font sml=\"msn\">%s</font><br>", nicktext);
1475 g_string_append_printf(s, "<font sml=\"msn\">%s</font><br>", 1447 gaim_notify_user_info_add_pair(user_info, _("Nickname"), tmp);
1476 nicktext); 1448 g_free(tmp);
1477 g_free(nicktext); 1449 g_free(nicktext);
1478 } 1450 }
1479 1451
1480 msn_tooltip_text(b, str, TRUE); 1452 /* Add the tooltip information */
1481 tmp = gaim_strreplace((*str->str == '\n' ? str->str + 1 : str->str), 1453 msn_tooltip_text(b, user_info, TRUE);
1482 "\n", "<br>"); 1454
1483 g_string_free(str, TRUE); 1455 return TRUE;
1484 g_string_append_printf(s, "%s<br>", tmp); 1456 }
1485 // gaim_debug_info("MaYuan","tooltip info string:{%s}\n",s); 1457
1486 g_free(tmp); 1458 return FALSE;
1487 }
1488
1489 return g_string_free(s, FALSE);
1490 } 1459 }
1491 1460
1492 #if PHOTO_SUPPORT 1461 #if PHOTO_SUPPORT
1493 1462
1494 static char * 1463 static char *
1497 char *p, *q; 1466 char *p, *q;
1498 1467
1499 if ((p = strstr(url_text, PHOTO_URL)) != NULL){ 1468 if ((p = strstr(url_text, PHOTO_URL)) != NULL){
1500 p += strlen(PHOTO_URL); 1469 p += strlen(PHOTO_URL);
1501 } 1470 }
1502
1503 if (p && (strncmp(p, "http://",strlen("http://")) == 0) && ((q = strchr(p, '"')) != NULL)) 1471 if (p && (strncmp(p, "http://",strlen("http://")) == 0) && ((q = strchr(p, '"')) != NULL))
1504 return g_strndup(p, q - p); 1472 return g_strndup(p, q - p);
1505 1473
1506 return NULL; 1474 return NULL;
1507 } 1475 }
1508 1476
1509 static void msn_got_photo(void *data, const char *url_text, size_t len); 1477 static void msn_got_photo(GaimUtilFetchUrlData *url_data, gpointer data,
1478 const gchar *url_text, size_t len, const gchar *error_message);
1510 1479
1511 #endif 1480 #endif
1512 1481
1513 #if 0 1482 #if 0
1514 static char *msn_info_date_reformat(const char *field, size_t len) 1483 static char *msn_info_date_reformat(const char *field, size_t len)
1520 return g_strdup(gaim_date_format_short(localtime(&t))); 1489 return g_strdup(gaim_date_format_short(localtime(&t)));
1521 } 1490 }
1522 #endif 1491 #endif
1523 1492
1524 #define MSN_GOT_INFO_GET_FIELD(a, b) \ 1493 #define MSN_GOT_INFO_GET_FIELD(a, b) \
1525 found = gaim_markup_extract_info_field(stripped, stripped_len, s, \ 1494 found = gaim_markup_extract_info_field(stripped, stripped_len, user_info, \
1526 "\n" a ":\t", 0, "\n", 0, "Undisclosed", b, 0, NULL, NULL); \ 1495 "\n" a ":", 0, "\n", 0, "Undisclosed", b, 0, NULL, NULL); \
1527 if (found) \ 1496 if (found) \
1528 sect_info = TRUE; 1497 sect_info = TRUE;
1529 1498
1530 static void 1499 static void
1531 msn_got_info(void *data, const char *url_text, size_t len) 1500 msn_got_info(GaimUtilFetchUrlData *url_data, gpointer data,
1501 const gchar *url_text, size_t len, const gchar *error_message)
1532 { 1502 {
1533 MsnGetInfoData *info_data = (MsnGetInfoData *)data; 1503 MsnGetInfoData *info_data = (MsnGetInfoData *)data;
1534 char *stripped, *p, *q; 1504 GaimNotifyUserInfo *user_info;
1535 char buf[1024]; 1505 char *stripped, *p, *q, *tmp;
1536 char *tooltip_text;
1537 char *user_url = NULL; 1506 char *user_url = NULL;
1538 gboolean found; 1507 gboolean found;
1508 gboolean has_tooltip_text = FALSE;
1539 gboolean has_info = FALSE; 1509 gboolean has_info = FALSE;
1540 gboolean sect_info = FALSE; 1510 gboolean sect_info = FALSE;
1541 const char* title = NULL; 1511 gboolean has_contact_info = FALSE;
1542 char *url_buffer; 1512 char *url_buffer;
1543 char *personal = NULL;
1544 char *business = NULL;
1545 GString *s, *s2; 1513 GString *s, *s2;
1546 int stripped_len; 1514 int stripped_len;
1547 #if PHOTO_SUPPORT 1515 #if PHOTO_SUPPORT
1548 char *photo_url_text = NULL; 1516 char *photo_url_text = NULL;
1549 MsnGetInfoStepTwoData *info2_data = NULL; 1517 MsnGetInfoStepTwoData *info2_data = NULL;
1558 g_free(info_data->name); 1526 g_free(info_data->name);
1559 g_free(info_data); 1527 g_free(info_data);
1560 return; 1528 return;
1561 } 1529 }
1562 1530
1563 tooltip_text = msn_tooltip_info_text(info_data); 1531 user_info = gaim_notify_user_info_new();
1564 title = _("MSN Profile"); 1532 has_tooltip_text = msn_tooltip_extract_info_text(user_info, info_data);
1565 1533
1566 if (url_text == NULL || strcmp(url_text, "") == 0) 1534 if (error_message != NULL || url_text == NULL || strcmp(url_text, "") == 0)
1567 { 1535 {
1568 g_snprintf(buf, 1024, "<html><body>%s<b>%s</b></body></html>", 1536 tmp = g_strdup_printf("<b>%s</b>", _("Error retrieving profile"));
1569 tooltip_text, _("Error retrieving profile")); 1537 gaim_notify_user_info_add_pair(user_info, NULL, tmp);
1570 1538 g_free(tmp);
1571 gaim_notify_userinfo(info_data->gc, info_data->name, buf, NULL, NULL); 1539
1572 1540 gaim_notify_userinfo(info_data->gc, info_data->name, user_info, NULL, NULL);
1573 g_free(tooltip_text); 1541 gaim_notify_user_info_destroy(user_info);
1542
1543 g_free(info_data->name);
1544 g_free(info_data);
1574 return; 1545 return;
1575 } 1546 }
1576 1547
1577 url_buffer = g_strdup(url_text); 1548 url_buffer = g_strdup(url_text);
1578 1549
1626 1597
1627 /* Gonna re-use the memory we've already got for url_buffer */ 1598 /* Gonna re-use the memory we've already got for url_buffer */
1628 /* No we're not. */ 1599 /* No we're not. */
1629 s = g_string_sized_new(strlen(url_buffer)); 1600 s = g_string_sized_new(strlen(url_buffer));
1630 s2 = g_string_sized_new(strlen(url_buffer)); 1601 s2 = g_string_sized_new(strlen(url_buffer));
1631 1602
1603 /* General section header */
1604 if (has_tooltip_text)
1605 gaim_notify_user_info_add_section_break(user_info);
1606
1607 gaim_notify_user_info_add_section_header(user_info, _("General"));
1608
1632 /* Extract their Name and put it in */ 1609 /* Extract their Name and put it in */
1633 MSN_GOT_INFO_GET_FIELD("Name", _("Name")) 1610 MSN_GOT_INFO_GET_FIELD("Name", _("Name"));
1634 1611
1635 /* General */ 1612 /* General */
1636 MSN_GOT_INFO_GET_FIELD("Nickname", _("Nickname")); 1613 MSN_GOT_INFO_GET_FIELD("Nickname", _("Nickname"));
1637 MSN_GOT_INFO_GET_FIELD("Age", _("Age")); 1614 MSN_GOT_INFO_GET_FIELD("Age", _("Age"));
1638 MSN_GOT_INFO_GET_FIELD("Gender", _("Gender")); 1615 MSN_GOT_INFO_GET_FIELD("Gender", _("Gender"));
1639 MSN_GOT_INFO_GET_FIELD("Occupation", _("Occupation")); 1616 MSN_GOT_INFO_GET_FIELD("Occupation", _("Occupation"));
1640 MSN_GOT_INFO_GET_FIELD("Location", _("Location")); 1617 MSN_GOT_INFO_GET_FIELD("Location", _("Location"));
1641 1618
1642 /* Extract their Interests and put it in */ 1619 /* Extract their Interests and put it in */
1643 found = gaim_markup_extract_info_field(stripped, stripped_len, s, 1620 found = gaim_markup_extract_info_field(stripped, stripped_len, user_info,
1644 "\nInterests\t", 0, " (/default.aspx?page=searchresults", 0, 1621 "\nInterests\t", 0, " (/default.aspx?page=searchresults", 0,
1645 "Undisclosed", _("Hobbies and Interests") /* _("Interests") */, 1622 "Undisclosed", _("Hobbies and Interests") /* _("Interests") */,
1646 0, NULL, NULL); 1623 0, NULL, NULL);
1647 1624
1648 if (found) 1625 if (found)
1649 sect_info = TRUE; 1626 sect_info = TRUE;
1650 1627
1651 MSN_GOT_INFO_GET_FIELD("More about me", _("A Little About Me")); 1628 MSN_GOT_INFO_GET_FIELD("More about me", _("A Little About Me"));
1652 1629
1653 if (sect_info) 1630 if (sect_info)
1654 { 1631 {
1655 /* trim off the trailing "<br>\n" */
1656 g_string_truncate(s, strlen(s->str) - 5);
1657 g_string_append_printf(s2, _("%s<b>General</b><br>%s"),
1658 (*tooltip_text) ? "<hr>" : "", s->str);
1659 s = g_string_truncate(s, 0);
1660 has_info = TRUE; 1632 has_info = TRUE;
1661 sect_info = FALSE; 1633 sect_info = FALSE;
1662 } 1634 }
1663 1635 else
1664 1636 {
1637 /* Remove the section header */
1638 gaim_notify_user_info_remove_last_item(user_info);
1639 if (has_tooltip_text)
1640 gaim_notify_user_info_remove_last_item(user_info);
1641 }
1642
1665 /* Social */ 1643 /* Social */
1644 gaim_notify_user_info_add_section_break(user_info);
1645 gaim_notify_user_info_add_section_header(user_info, _("Social"));
1646
1666 MSN_GOT_INFO_GET_FIELD("Marital status", _("Marital Status")); 1647 MSN_GOT_INFO_GET_FIELD("Marital status", _("Marital Status"));
1667 MSN_GOT_INFO_GET_FIELD("Interested in", _("Interests")); 1648 MSN_GOT_INFO_GET_FIELD("Interested in", _("Interests"));
1668 MSN_GOT_INFO_GET_FIELD("Pets", _("Pets")); 1649 MSN_GOT_INFO_GET_FIELD("Pets", _("Pets"));
1669 MSN_GOT_INFO_GET_FIELD("Hometown", _("Hometown")); 1650 MSN_GOT_INFO_GET_FIELD("Hometown", _("Hometown"));
1670 MSN_GOT_INFO_GET_FIELD("Places lived", _("Places Lived")); 1651 MSN_GOT_INFO_GET_FIELD("Places lived", _("Places Lived"));
1673 MSN_GOT_INFO_GET_FIELD("Music", _("Music")); 1654 MSN_GOT_INFO_GET_FIELD("Music", _("Music"));
1674 MSN_GOT_INFO_GET_FIELD("Favorite quote", _("Favorite Quote")); 1655 MSN_GOT_INFO_GET_FIELD("Favorite quote", _("Favorite Quote"));
1675 1656
1676 if (sect_info) 1657 if (sect_info)
1677 { 1658 {
1678 g_string_append_printf(s2, _("%s<b>Social</b><br>%s"), has_info ? "<br><hr>" : "", s->str);
1679 s = g_string_truncate(s, 0);
1680 has_info = TRUE; 1659 has_info = TRUE;
1681 sect_info = FALSE; 1660 sect_info = FALSE;
1682 } 1661 }
1662 else
1663 {
1664 /* Remove the section header */
1665 gaim_notify_user_info_remove_last_item(user_info);
1666 gaim_notify_user_info_remove_last_item(user_info);
1667 }
1683 1668
1684 /* Contact Info */ 1669 /* Contact Info */
1685 /* Personal */ 1670 /* Personal */
1671 gaim_notify_user_info_add_section_break(user_info);
1672 gaim_notify_user_info_add_section_header(user_info, _("Contact Info"));
1673 gaim_notify_user_info_add_section_header(user_info, _("Personal"));
1674
1686 MSN_GOT_INFO_GET_FIELD("Name", _("Name")); 1675 MSN_GOT_INFO_GET_FIELD("Name", _("Name"));
1687 MSN_GOT_INFO_GET_FIELD("Significant other", _("Significant Other")); 1676 MSN_GOT_INFO_GET_FIELD("Significant other", _("Significant Other"));
1688 MSN_GOT_INFO_GET_FIELD("Home phone", _("Home Phone")); 1677 MSN_GOT_INFO_GET_FIELD("Home phone", _("Home Phone"));
1689 MSN_GOT_INFO_GET_FIELD("Home phone 2", _("Home Phone 2")); 1678 MSN_GOT_INFO_GET_FIELD("Home phone 2", _("Home Phone 2"));
1690 MSN_GOT_INFO_GET_FIELD("Home address", _("Home Address")); 1679 MSN_GOT_INFO_GET_FIELD("Home address", _("Home Address"));
1696 MSN_GOT_INFO_GET_FIELD("Anniversary", _("Anniversary")); 1685 MSN_GOT_INFO_GET_FIELD("Anniversary", _("Anniversary"));
1697 MSN_GOT_INFO_GET_FIELD("Notes", _("Notes")); 1686 MSN_GOT_INFO_GET_FIELD("Notes", _("Notes"));
1698 1687
1699 if (sect_info) 1688 if (sect_info)
1700 { 1689 {
1701 personal = g_strdup_printf(_("<br><b>Personal</b><br>%s"), s->str); 1690 has_info = TRUE;
1702 s = g_string_truncate(s, 0);
1703 sect_info = FALSE; 1691 sect_info = FALSE;
1692 has_contact_info = TRUE;
1693 }
1694 else
1695 {
1696 /* Remove the section header */
1697 gaim_notify_user_info_remove_last_item(user_info);
1704 } 1698 }
1705 1699
1706 /* Business */ 1700 /* Business */
1701 gaim_notify_user_info_add_section_header(user_info, _("Work"));
1707 MSN_GOT_INFO_GET_FIELD("Name", _("Name")); 1702 MSN_GOT_INFO_GET_FIELD("Name", _("Name"));
1708 MSN_GOT_INFO_GET_FIELD("Job title", _("Job Title")); 1703 MSN_GOT_INFO_GET_FIELD("Job title", _("Job Title"));
1709 MSN_GOT_INFO_GET_FIELD("Company", _("Company")); 1704 MSN_GOT_INFO_GET_FIELD("Company", _("Company"));
1710 MSN_GOT_INFO_GET_FIELD("Department", _("Department")); 1705 MSN_GOT_INFO_GET_FIELD("Department", _("Department"));
1711 MSN_GOT_INFO_GET_FIELD("Profession", _("Profession")); 1706 MSN_GOT_INFO_GET_FIELD("Profession", _("Profession"));
1720 MSN_GOT_INFO_GET_FIELD("Start date", _("Start Date")); 1715 MSN_GOT_INFO_GET_FIELD("Start date", _("Start Date"));
1721 MSN_GOT_INFO_GET_FIELD("Notes", _("Notes")); 1716 MSN_GOT_INFO_GET_FIELD("Notes", _("Notes"));
1722 1717
1723 if (sect_info) 1718 if (sect_info)
1724 { 1719 {
1725 business = g_strdup_printf(_("<br><b>Business</b><br>%s"), s->str); 1720 has_info = TRUE;
1726 s = g_string_truncate(s, 0);
1727 sect_info = FALSE; 1721 sect_info = FALSE;
1728 } 1722 has_contact_info = TRUE;
1729 1723 }
1730 if ((personal != NULL) || (business != NULL)) 1724 else
1731 { 1725 {
1732 /* trim off the trailing "<br>\n" */ 1726 /* Remove the section header */
1733 g_string_truncate(s, strlen(s->str) - 5); 1727 gaim_notify_user_info_remove_last_item(user_info);
1734 1728 }
1735 has_info = TRUE; 1729
1736 g_string_append_printf(s2, _("<hr><b>Contact Info</b>%s%s"), 1730 if (!has_contact_info)
1737 personal ? personal : "", 1731 {
1738 business ? business : ""); 1732 /* Remove the Contact Info section header */
1739 } 1733 gaim_notify_user_info_remove_last_item(user_info);
1740 1734 }
1741 g_free(personal);
1742 g_free(business);
1743 g_string_free(s, TRUE);
1744 s = s2;
1745 1735
1746 #if 0 /* these probably don't show up any more */ 1736 #if 0 /* these probably don't show up any more */
1747 /* 1737 /*
1748 * The fields, 'A Little About Me', 'Favorite Things', 'Hobbies 1738 * The fields, 'A Little About Me', 'Favorite Things', 'Hobbies
1749 * and Interests', 'Favorite Quote', and 'My Homepage' may or may 1739 * and Interests', 'Favorite Quote', and 'My Homepage' may or may
1865 #endif 1855 #endif
1866 1856
1867 /* If we were able to fetch a homepage url earlier, stick it in there */ 1857 /* If we were able to fetch a homepage url earlier, stick it in there */
1868 if (user_url != NULL) 1858 if (user_url != NULL)
1869 { 1859 {
1870 g_snprintf(buf, sizeof(buf), 1860 tmp = g_strdup_printf("<a href=\"%s\">%s</a>", user_url, user_url);
1871 "<b>%s:</b><br><a href=\"%s\">%s</a><br>\n", 1861 gaim_notify_user_info_add_pair(user_info, _("Homepage"), tmp);
1872 _("Homepage"), user_url, user_url); 1862 g_free(tmp);
1873
1874 g_string_append(s, buf);
1875
1876 g_free(user_url); 1863 g_free(user_url);
1877 1864
1878 has_info = TRUE; 1865 has_info = TRUE;
1879 } 1866 }
1880 1867
1889 char *p = strstr(url_buffer, "Unknown Member </TITLE>"); 1876 char *p = strstr(url_buffer, "Unknown Member </TITLE>");
1890 * This might not work for long either ... */ 1877 * This might not work for long either ... */
1891 char *p = strstr(url_buffer, "form id=\"SpacesSearch\" name=\"SpacesSearch\""); 1878 char *p = strstr(url_buffer, "form id=\"SpacesSearch\" name=\"SpacesSearch\"");
1892 GaimBuddy *b = gaim_find_buddy 1879 GaimBuddy *b = gaim_find_buddy
1893 (gaim_connection_get_account(info_data->gc), info_data->name); 1880 (gaim_connection_get_account(info_data->gc), info_data->name);
1894 g_string_append_printf(s, "<br><b>%s</b><br>%s<br><br>", 1881 gaim_notify_user_info_add_pair(user_info, _("Error retrieving profile"),
1895 _("Error retrieving profile"), 1882 ((p && b) ? _("The user has not created a public profile.") :
1896 ((p && b)? 1883 (p ? _("MSN reported not being able to find the user's profile. "
1897 _("The user has not created a public profile."): 1884 "This either means that the user does not exist, "
1898 p? _("MSN reported not being able to find the user's profile. " 1885 "or that the user exists "
1899 "This either means that the user does not exist, " 1886 "but has not created a public profile.") :
1900 "or that the user exists " 1887 _("Gaim could not find " /* This should never happen */
1901 "but has not created a public profile."): 1888 "any information in the user's profile. "
1902 _("Gaim could not find " /* This should never happen */ 1889 "The user most likely does not exist."))));
1903 "any information in the user's profile. " 1890 }
1904 "The user most likely does not exist."))); 1891
1905 }
1906 /* put a link to the actual profile URL */ 1892 /* put a link to the actual profile URL */
1907 g_string_append_printf(s, _("<hr><b>%s:</b> "), _("Profile URL")); 1893 tmp = g_strdup_printf("<a href=\"%s%s\">%s%s</a>",
1908 g_string_append_printf(s, "<br><a href=\"%s%s\">%s%s</a><br>", 1894 PROFILE_URL, info_data->name, PROFILE_URL, info_data->name);
1909 PROFILE_URL, info_data->name, PROFILE_URL, info_data->name); 1895 gaim_notify_user_info_add_pair(user_info, _("Profile URL"), tmp);
1910 1896 g_free(tmp);
1911 /* Finish it off, and show it to them */
1912 g_string_append(s, "</body></html>\n");
1913 1897
1914 #if PHOTO_SUPPORT 1898 #if PHOTO_SUPPORT
1915 /* Find the URL to the photo; must be before the marshalling [Bug 994207] */ 1899 /* Find the URL to the photo; must be before the marshalling [Bug 994207] */
1916 photo_url_text = msn_get_photo_url(url_text); 1900 photo_url_text = msn_get_photo_url(url_text);
1917 gaim_debug_info("Ma Yuan","photo url:{%s}\n",photo_url_text); 1901 gaim_debug_info("Ma Yuan","photo url:{%s}\n",photo_url_text);
1919 /* Marshall the existing state */ 1903 /* Marshall the existing state */
1920 info2_data = g_malloc0(sizeof(MsnGetInfoStepTwoData)); 1904 info2_data = g_malloc0(sizeof(MsnGetInfoStepTwoData));
1921 info2_data->info_data = info_data; 1905 info2_data->info_data = info_data;
1922 info2_data->stripped = stripped; 1906 info2_data->stripped = stripped;
1923 info2_data->url_buffer = url_buffer; 1907 info2_data->url_buffer = url_buffer;
1924 info2_data->s = s; 1908 info2_data->user_info = user_info;
1925 info2_data->photo_url_text = photo_url_text; 1909 info2_data->photo_url_text = photo_url_text;
1926 info2_data->tooltip_text = tooltip_text;
1927 info2_data->title = title;
1928 1910
1929 /* Try to put the photo in there too, if there's one */ 1911 /* Try to put the photo in there too, if there's one */
1930 if (photo_url_text) 1912 if (photo_url_text)
1931 { 1913 {
1932 gaim_url_fetch(photo_url_text, FALSE, NULL, FALSE, msn_got_photo, 1914 gaim_util_fetch_url(photo_url_text, FALSE, NULL, FALSE, msn_got_photo,
1933 info2_data); 1915 info2_data);
1934 } 1916 }
1935 else 1917 else
1936 { 1918 {
1937 /* Emulate a callback */ 1919 /* Emulate a callback */
1938 msn_got_photo(info2_data, NULL, 0); 1920 /* TODO: Huh? */
1939 } 1921 msn_got_photo(NULL, info2_data, NULL, 0, NULL);
1940 } 1922 }
1941 1923 }
1942 static void 1924
1943 msn_got_photo(void *data, const char *url_text, size_t len) 1925 static void
1944 { 1926 msn_got_photo(GaimUtilFetchUrlData *url_data, gpointer user_data,
1945 MsnGetInfoStepTwoData *info2_data = (MsnGetInfoStepTwoData *)data; 1927 const gchar *url_text, size_t len, const gchar *error_message)
1928 {
1929 MsnGetInfoStepTwoData *info2_data = (MsnGetInfoStepTwoData *)user_data;
1946 int id = -1; 1930 int id = -1;
1947 1931
1948 /* Unmarshall the saved state */ 1932 /* Unmarshall the saved state */
1949 MsnGetInfoData *info_data = info2_data->info_data; 1933 MsnGetInfoData *info_data = info2_data->info_data;
1950 char *stripped = info2_data->stripped; 1934 char *stripped = info2_data->stripped;
1951 char *url_buffer = info2_data->url_buffer; 1935 char *url_buffer = info2_data->url_buffer;
1952 GString *s = info2_data->s; 1936 GaimNotifyUserInfo *user_info = info2_data->user_info;
1953 char *photo_url_text = info2_data->photo_url_text; 1937 char *photo_url_text = info2_data->photo_url_text;
1954 char *tooltip_text = info2_data->tooltip_text;
1955 1938
1956 /* Make sure the connection is still valid if we got here by fetching a photo url */ 1939 /* Make sure the connection is still valid if we got here by fetching a photo url */
1957 if (url_text && 1940 if (url_text && (error_message != NULL ||
1958 g_list_find(gaim_connections_get_all(), info_data->gc) == NULL) 1941 g_list_find(gaim_connections_get_all(), info_data->gc) == NULL))
1959 { 1942 {
1960 gaim_debug_warning("msn", "invalid connection. ignoring buddy photo info.\n"); 1943 gaim_debug_warning("msn", "invalid connection. ignoring buddy photo info.\n");
1961 g_free(stripped); 1944 g_free(stripped);
1962 g_free(url_buffer); 1945 g_free(url_buffer);
1963 g_string_free(s, TRUE); 1946 g_free(user_info);
1964 g_free(tooltip_text);
1965 g_free(info_data->name); 1947 g_free(info_data->name);
1966 g_free(info_data); 1948 g_free(info_data);
1967 g_free(photo_url_text); 1949 g_free(photo_url_text);
1968 g_free(info2_data); 1950 g_free(info2_data);
1969 1951
1970 return; 1952 return;
1971 } 1953 }
1972 1954
1973 /* Try to put the photo in there too, if there's one and is readable */ 1955 /* Try to put the photo in there too, if there's one and is readable */
1974 if (data && url_text && len != 0) 1956 if (user_data && url_text && len != 0)
1975 { 1957 {
1976 if (strstr(url_text, "400 Bad Request") 1958 if (strstr(url_text, "400 Bad Request")
1977 || strstr(url_text, "403 Forbidden") 1959 || strstr(url_text, "403 Forbidden")
1978 || strstr(url_text, "404 Not Found")) 1960 || strstr(url_text, "404 Not Found"))
1979 { 1961 {
1985 { 1967 {
1986 char buf[1024]; 1968 char buf[1024];
1987 gaim_debug_info("msn", "%s is %d bytes\n", photo_url_text, len); 1969 gaim_debug_info("msn", "%s is %d bytes\n", photo_url_text, len);
1988 id = gaim_imgstore_add(url_text, len, NULL); 1970 id = gaim_imgstore_add(url_text, len, NULL);
1989 g_snprintf(buf, sizeof(buf), "<img id=\"%d\"><br>", id); 1971 g_snprintf(buf, sizeof(buf), "<img id=\"%d\"><br>", id);
1990 g_string_prepend(s, buf); 1972 gaim_notify_user_info_prepend_pair(user_info, NULL, buf);
1991 } 1973 }
1992 } 1974 }
1993 1975
1994 /* We continue here from msn_got_info, as if nothing has happened */ 1976 /* We continue here from msn_got_info, as if nothing has happened */
1995 #endif 1977 #endif
1996 1978 gaim_notify_userinfo(info_data->gc, info_data->name, user_info, NULL, NULL);
1997 g_string_prepend(s, tooltip_text);
1998 gaim_notify_userinfo(info_data->gc, info_data->name, s->str, NULL, NULL);
1999 1979
2000 g_free(stripped); 1980 g_free(stripped);
2001 g_free(url_buffer); 1981 g_free(url_buffer);
2002 g_string_free(s, TRUE); 1982 gaim_notify_user_info_destroy(user_info);
2003 g_free(tooltip_text);
2004 g_free(info_data->name); 1983 g_free(info_data->name);
2005 g_free(info_data); 1984 g_free(info_data);
2006 #if PHOTO_SUPPORT 1985 #if PHOTO_SUPPORT
2007 g_free(photo_url_text); 1986 g_free(photo_url_text);
2008 g_free(info2_data); 1987 g_free(info2_data);
2021 data->gc = gc; 2000 data->gc = gc;
2022 data->name = g_strdup(name); 2001 data->name = g_strdup(name);
2023 2002
2024 url = g_strdup_printf("%s%s", PROFILE_URL, name); 2003 url = g_strdup_printf("%s%s", PROFILE_URL, name);
2025 2004
2026 gaim_url_fetch(url, FALSE, 2005 gaim_util_fetch_url(url, FALSE,
2027 "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)", 2006 "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)",
2028 TRUE, msn_got_info, data); 2007 TRUE, msn_got_info, data);
2029 2008
2030 g_free(url); 2009 g_free(url);
2031 } 2010 }
2051 static GaimPluginProtocolInfo prpl_info = 2030 static GaimPluginProtocolInfo prpl_info =
2052 { 2031 {
2053 OPT_PROTO_MAIL_CHECK, 2032 OPT_PROTO_MAIL_CHECK,
2054 NULL, /* user_splits */ 2033 NULL, /* user_splits */
2055 NULL, /* protocol_options */ 2034 NULL, /* protocol_options */
2056 {"png", 0, 0, 96, 96, GAIM_ICON_SCALE_SEND}, /* icon_spec */ 2035 {"png", 0, 0, 96, 96, 0, GAIM_ICON_SCALE_SEND}, /* icon_spec */
2057 msn_list_icon, /* list_icon */ 2036 msn_list_icon, /* list_icon */
2058 msn_list_emblems, /* list_emblems */ 2037 msn_list_emblems, /* list_emblems */
2059 msn_status_text, /* status_text */ 2038 msn_status_text, /* status_text */
2060 msn_tooltip_text, /* tooltip_text */ 2039 msn_tooltip_text, /* tooltip_text */
2061 msn_status_types, /* away_states */ 2040 msn_status_types, /* away_states */
2108 msn_can_receive_file, /* can_receive_file */ 2087 msn_can_receive_file, /* can_receive_file */
2109 msn_send_file, /* send_file */ 2088 msn_send_file, /* send_file */
2110 msn_new_xfer, /* new_xfer */ 2089 msn_new_xfer, /* new_xfer */
2111 NULL, /* offline_message */ 2090 NULL, /* offline_message */
2112 NULL, /* whiteboard_prpl_ops */ 2091 NULL, /* whiteboard_prpl_ops */
2092 NULL, /* send_raw */
2093 NULL, /* roomlist_room_serialize */
2113 }; 2094 };
2114 2095
2115 static GaimPluginInfo info = 2096 static GaimPluginInfo info =
2116 { 2097 {
2117 GAIM_PLUGIN_MAGIC, 2098 GAIM_PLUGIN_MAGIC,
2125 2106
2126 "prpl-msn", /**< id */ 2107 "prpl-msn", /**< id */
2127 "MSN", /**< name */ 2108 "MSN", /**< name */
2128 VERSION, /**< version */ 2109 VERSION, /**< version */
2129 /** summary */ 2110 /** summary */
2130 N_("MSN Protocol Plugin"), 2111 N_("Windows Live Messenger Protocol Plugin"),
2131 /** description */ 2112 /** description */
2132 N_("MSN Protocol Plugin"), 2113 N_("Windows Live Messenger Protocol Plugin"),
2133 "Christian Hammond <chipx86@gnupdate.org>", /**< author */ 2114 "MaYuan <mayuan2006@gmail.com>", /**< author */
2134 GAIM_WEBSITE, /**< homepage */ 2115 GAIM_WEBSITE, /**< homepage */
2135 2116
2136 msn_load, /**< load */ 2117 msn_load, /**< load */
2137 msn_unload, /**< unload */ 2118 msn_unload, /**< unload */
2138 NULL, /**< destroy */ 2119 NULL, /**< destroy */