comparison libpurple/protocols/yahoo/yahoo.c @ 26907:53d4b3a1c80f

Whitespace, syntatic sugar, move the URLs to yahoo.h, and escape the token-fetching URL parameters. I'm appalled their server works if I pass https://login.yahoo.com/config/pwtoken_get?src=ymsgr&ts=&login=me&passwd=hunter2&chal=e^r-t*w%4+h&p^y-o|i|(p&l^z/a-j-l&x/r+h&q^u)/s/a&s|8&j/j^e*1+4|f
author Paul Aurich <paul@darkrain42.org>
date Wed, 13 May 2009 06:50:47 +0000
parents 644606f508e6
children fac90dbe196d
comparison
equal deleted inserted replaced
26906:644606f508e6 26907:53d4b3a1c80f
277 if (strtol(pair->value, NULL, 10) == 0) { 277 if (strtol(pair->value, NULL, 10) == 0) {
278 if (f) 278 if (f)
279 f->status = YAHOO_STATUS_OFFLINE; 279 f->status = YAHOO_STATUS_OFFLINE;
280 if (name) { 280 if (name) {
281 purple_prpl_got_user_status(account, name, "offline", NULL); 281 purple_prpl_got_user_status(account, name, "offline", NULL);
282 purple_prpl_got_user_status_deactive(account, name, YAHOO_STATUS_TYPE_MOBILE); 282 purple_prpl_got_user_status_deactive(account, name, YAHOO_STATUS_TYPE_MOBILE);
283 } 283 }
284 break; 284 break;
285 } 285 }
286 break; 286 break;
287 case 60: /* SMS */ 287 case 60: /* SMS */
352 case 244: /* client version number. Yahoo Client Detection */ 352 case 244: /* client version number. Yahoo Client Detection */
353 if(f && strtol(pair->value, NULL, 10)) 353 if(f && strtol(pair->value, NULL, 10))
354 f->version_id = strtol(pair->value, NULL, 10); 354 f->version_id = strtol(pair->value, NULL, 10);
355 break; 355 break;
356 case 241: /* protocol buddy belongs to */ 356 case 241: /* protocol buddy belongs to */
357 if(strtol(pair->value, NULL, 10) == 2) { 357 if(strtol(pair->value, NULL, 10) == 2) {
358 msn_name = g_strconcat("msn/", name, NULL); 358 msn_name = g_strconcat("msn/", name, NULL);
359 name = msn_name; 359 name = msn_name;
360 } 360 }
361 break; 361 break;
362 default: 362 default:
508 yd->current_list15_grp = NULL; 508 yd->current_list15_grp = NULL;
509 } 509 }
510 510
511 break; 511 break;
512 case 301: /* This is 319 before all s/n's in a group after the first. It is followed by an identical 300. */ 512 case 301: /* This is 319 before all s/n's in a group after the first. It is followed by an identical 300. */
513 if(temp != NULL) { 513 if(temp != NULL) {
514 if(protocol == 2) 514 if(protocol == 2)
515 norm_bud = g_strconcat("msn/", temp, NULL); 515 norm_bud = g_strconcat("msn/", temp, NULL);
516 else 516 else
517 norm_bud = g_strdup(temp); 517 norm_bud = g_strdup(temp);
518 518
526 } 526 }
527 b = purple_buddy_new(account, norm_bud, NULL); 527 b = purple_buddy_new(account, norm_bud, NULL);
528 purple_blist_add_buddy(b, NULL, g, NULL); 528 purple_blist_add_buddy(b, NULL, g, NULL);
529 } 529 }
530 yahoo_do_group_check(account, ht, norm_bud, yd->current_list15_grp); 530 yahoo_do_group_check(account, ht, norm_bud, yd->current_list15_grp);
531 if(protocol != 0) { 531 if(protocol != 0) {
532 f->protocol = protocol; 532 f->protocol = protocol;
533 purple_debug_info("yahoo", "Setting protocol to %d\n", f->protocol); 533 purple_debug_info("yahoo", "Setting protocol to %d\n", f->protocol);
534 } 534 }
535 if(stealth == 2) 535 if(stealth == 2)
536 f->presence = YAHOO_PRESENCE_PERM_OFFLINE; 536 f->presence = YAHOO_PRESENCE_PERM_OFFLINE;
537 537
538 /* set p2p status not connected and no p2p packet sent */ 538 /* set p2p status not connected and no p2p packet sent */
539 if(protocol == 0) { 539 if(protocol == 0) {
540 yahoo_friend_set_p2p_status(f, YAHOO_P2PSTATUS_NOT_CONNECTED); 540 yahoo_friend_set_p2p_status(f, YAHOO_P2PSTATUS_NOT_CONNECTED);
541 f->p2p_packet_sent = 0; 541 f->p2p_packet_sent = 0;
542 } else 542 } else
543 yahoo_friend_set_p2p_status(f, YAHOO_P2PSTATUS_DO_NOT_CONNECT); 543 yahoo_friend_set_p2p_status(f, YAHOO_P2PSTATUS_DO_NOT_CONNECT);
544 } else { 544 } else {
774 msn_from = g_strconcat("msn/", from, NULL); 774 msn_from = g_strconcat("msn/", from, NULL);
775 775
776 if (!g_ascii_strncasecmp(msg, "TYPING", strlen("TYPING")) 776 if (!g_ascii_strncasecmp(msg, "TYPING", strlen("TYPING"))
777 && (purple_privacy_check(account, from))) 777 && (purple_privacy_check(account, from)))
778 { 778 {
779 if(msn) { 779 if(msn) {
780 if (*stat == '1') 780 if (*stat == '1')
781 serv_got_typing(gc, msn_from, 0, PURPLE_TYPING); 781 serv_got_typing(gc, msn_from, 0, PURPLE_TYPING);
782 else 782 else
783 serv_got_typing_stopped(gc, msn_from); 783 serv_got_typing_stopped(gc, msn_from);
784 } 784 }
839 yd = gc->proto_data; 839 yd = gc->proto_data;
840 account = purple_connection_get_account(gc); 840 account = purple_connection_get_account(gc);
841 841
842 while (l != NULL) { 842 while (l != NULL) {
843 struct yahoo_pair *pair = l->data; 843 struct yahoo_pair *pair = l->data;
844 if (pair->key == 4) { 844 if (pair->key == 4) {
845 sms = g_new0(struct _yahoo_im, 1); 845 sms = g_new0(struct _yahoo_im, 1);
846 sms->from = g_strdup_printf("+%s", pair->value); 846 sms->from = g_strdup_printf("+%s", pair->value);
847 sms->time = time(NULL); 847 sms->time = time(NULL);
848 sms->utf8 = TRUE; 848 sms->utf8 = TRUE;
849 } 849 }
857 if (pair->key == 16) 857 if (pair->key == 16)
858 server_msg = pair->value; 858 server_msg = pair->value;
859 l = l->next; 859 l = l->next;
860 } 860 }
861 861
862 if( (pkt->status == -1) || (pkt->status == YAHOO_STATUS_DISCONNECTED) ) { 862 if( (pkt->status == -1) || (pkt->status == YAHOO_STATUS_DISCONNECTED) ) {
863 if (server_msg) { 863 if (server_msg) {
864 PurpleConversation *c; 864 PurpleConversation *c;
865 c = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, sms->from, account); 865 c = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, sms->from, account);
866 if (c == NULL) 866 if (c == NULL)
867 c = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, sms->from); 867 c = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, sms->from);
868 purple_conversation_write(c, NULL, server_msg, PURPLE_MESSAGE_SYSTEM, time(NULL)); 868 purple_conversation_write(c, NULL, server_msg, PURPLE_MESSAGE_SYSTEM, time(NULL));
925 im->buddy_icon = strtol(pair->value, NULL, 10); 925 im->buddy_icon = strtol(pair->value, NULL, 10);
926 if (pair->key == 14) { 926 if (pair->key == 14) {
927 if (im) 927 if (im)
928 im->msg = pair->value; 928 im->msg = pair->value;
929 } 929 }
930 if (pair->key == 241) { 930 if (pair->key == 241) {
931 if(strtol(pair->value, NULL, 10) == 2) 931 if(strtol(pair->value, NULL, 10) == 2)
932 msn = TRUE; 932 msn = TRUE;
933 } 933 }
934 /* peer session id */ 934 /* peer session id */
935 if (pair->key == 11) { 935 if (pair->key == 11) {
1023 c=purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, msn_from, account); 1023 c=purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, msn_from, account);
1024 1024
1025 if (!strcmp(m, "<ding>")) { 1025 if (!strcmp(m, "<ding>")) {
1026 char *username; 1026 char *username;
1027 1027
1028 if(c == NULL) { 1028 if(c == NULL) {
1029 if(msn) 1029 if(msn)
1030 c = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, msn_from); 1030 c = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, msn_from);
1031 else 1031 else
1032 c = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, im->from); 1032 c = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, im->from);
1033 } 1033 }
1053 serv_got_im(gc, im->from, m2, 0, im->time); 1053 serv_got_im(gc, im->from, m2, 0, im->time);
1054 1054
1055 g_free(m2); 1055 g_free(m2);
1056 1056
1057 /* laters : implement buddy icon for msn friends */ 1057 /* laters : implement buddy icon for msn friends */
1058 if(!msn) { 1058 if(!msn) {
1059 if ((f = yahoo_friend_find(gc, im->from)) && im->buddy_icon == 2) { 1059 if ((f = yahoo_friend_find(gc, im->from)) && im->buddy_icon == 2) {
1060 if (yahoo_friend_get_buddy_icon_need_request(f)) { 1060 if (yahoo_friend_get_buddy_icon_need_request(f)) {
1061 yahoo_send_picture_request(gc, im->from); 1061 yahoo_send_picture_request(gc, im->from);
1062 yahoo_friend_set_buddy_icon_need_request(f, FALSE); 1062 yahoo_friend_set_buddy_icon_need_request(f, FALSE);
1063 } 1063 }
1577 1577
1578 purple_debug_info("yahoo","Authentication: In yahoo_auth16_stage3\n"); 1578 purple_debug_info("yahoo","Authentication: In yahoo_auth16_stage3\n");
1579 1579
1580 md5_cipher = purple_ciphers_find_cipher("md5"); 1580 md5_cipher = purple_ciphers_find_cipher("md5");
1581 md5_ctx = purple_cipher_context_new(md5_cipher, NULL); 1581 md5_ctx = purple_cipher_context_new(md5_cipher, NULL);
1582 purple_cipher_context_append(md5_ctx,(guchar *)crypt, strlen(crypt)); 1582 purple_cipher_context_append(md5_ctx, (guchar *)crypt, strlen(crypt));
1583 purple_cipher_context_digest(md5_ctx, sizeof(md5_digest),md5_digest, NULL); 1583 purple_cipher_context_digest(md5_ctx, sizeof(md5_digest), md5_digest, NULL);
1584 1584
1585 to_y64(base64_string, md5_digest, 16); 1585 to_y64(base64_string, md5_digest, 16);
1586 1586
1587 pkt = yahoo_packet_new(YAHOO_SERVICE_AUTHRESP, YAHOO_STATUS_WEBLOGIN, yd->session_id); 1587 pkt = yahoo_packet_new(YAHOO_SERVICE_AUTHRESP, YAHOO_STATUS_WEBLOGIN, yd->session_id);
1588 if(yd->jp) { 1588 if(yd->jp) {
1630 1630
1631 purple_debug_info("yahoo","Authentication: In yahoo_auth16_stage2\n"); 1631 purple_debug_info("yahoo","Authentication: In yahoo_auth16_stage2\n");
1632 1632
1633 g_return_if_fail(PURPLE_CONNECTION_IS_VALID(gc)); 1633 g_return_if_fail(PURPLE_CONNECTION_IS_VALID(gc));
1634 1634
1635 if (error_message != NULL) { 1635 if (error_message != NULL) {
1636 purple_debug_error("yahoo", "Login Failed, unable to retrieve stage 2 url: %s\n", error_message); 1636 purple_debug_error("yahoo", "Login Failed, unable to retrieve stage 2 url: %s\n", error_message);
1637 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, error_message); 1637 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, error_message);
1638 g_free(auth_data->seed); 1638 g_free(auth_data->seed);
1639 g_free(auth_data); 1639 g_free(auth_data);
1640 return; 1640 return;
1641 } 1641 }
1642 else if (len > 0 && ret_data && *ret_data) { 1642 else if (len > 0 && ret_data && *ret_data) {
1643 split_data = g_strsplit(ret_data, "\r\n", -1); 1643 split_data = g_strsplit(ret_data, "\r\n", -1);
1644 totalelements = g_strv_length(split_data); 1644 totalelements = g_strv_length(split_data);
1645 if(totalelements >= 5) { 1645 if (totalelements >= 5) {
1646 response_no = strtol(*(split_data+1), NULL, 10); 1646 response_no = strtol(split_data[1], NULL, 10);
1647 crumb = g_strdup(*(split_data+2)+6); 1647 crumb = g_strdup(split_data[2] + 6);
1648 yd->cookie_y = g_strdup(*(split_data+3)+2); 1648 yd->cookie_y = g_strdup(split_data[3] + 2);
1649 yd->cookie_t = g_strdup(*(split_data+4)+2); 1649 yd->cookie_t = g_strdup(split_data[4] + 2);
1650 } 1650 }
1651 else 1651 else
1652 response_no = -1; 1652 response_no = -1;
1653 1653
1654 g_strfreev(split_data); 1654 g_strfreev(split_data);
1655 1655
1656 if(response_no != 0) { 1656 if(response_no != 0) {
1657 /* Some error in the login process */ 1657 /* Some error in the login process */
1658 PurpleConnectionError error; 1658 PurpleConnectionError error;
1659 switch(response_no) { 1659 switch(response_no) {
1660 case -1: 1660 case -1:
1661 /* Some error in the received stream */ 1661 /* Some error in the received stream */
1662 error_reason = g_strdup(_("Error in the received data")); 1662 error_reason = g_strdup(_("Error in the received data"));
1663 error = PURPLE_CONNECTION_ERROR_NETWORK_ERROR; 1663 error = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
1664 break; 1664 break;
1667 error_reason = g_strdup(_("Unknown error")); 1667 error_reason = g_strdup(_("Unknown error"));
1668 error = PURPLE_CONNECTION_ERROR_OTHER_ERROR; 1668 error = PURPLE_CONNECTION_ERROR_OTHER_ERROR;
1669 break; 1669 break;
1670 default: 1670 default:
1671 /* if we have everything we need, why not try to login irrespective of response */ 1671 /* if we have everything we need, why not try to login irrespective of response */
1672 if((crumb != NULL) && (yd->cookie_y != NULL) && (yd->cookie_t != NULL)) { 1672 if((crumb != NULL) && (yd->cookie_y != NULL) && (yd->cookie_t != NULL)) {
1673 try_login_on_error = TRUE; 1673 try_login_on_error = TRUE;
1674 break; 1674 break;
1675 } 1675 }
1676 error_reason = g_strdup(_("Unknown error")); 1676 error_reason = g_strdup(_("Unknown error"));
1677 error = PURPLE_CONNECTION_ERROR_OTHER_ERROR; 1677 error = PURPLE_CONNECTION_ERROR_OTHER_ERROR;
1678 break; 1678 break;
1679 } 1679 }
1680 if(error_reason) { 1680 if(error_reason) {
1681 purple_debug_error("yahoo","Authentication error: %s", error_reason); 1681 purple_debug_error("yahoo","Authentication error: %s", error_reason);
1682 purple_connection_error_reason(gc, error, error_reason); 1682 purple_connection_error_reason(gc, error, error_reason);
1683 g_free(error_reason); 1683 g_free(error_reason);
1684 } 1684 }
1685 } 1685 }
1686 if((response_no == 0) || try_login_on_error) { 1686 if((response_no == 0) || try_login_on_error) {
1687 crypt = g_strconcat(crumb, auth_data->seed, NULL); 1687 crypt = g_strconcat(crumb, auth_data->seed, NULL);
1688 yahoo_auth16_stage3(gc, crypt); 1688 yahoo_auth16_stage3(gc, crypt);
1689 g_free(crumb); 1689 g_free(crumb);
1690 } 1690 }
1691 } 1691 }
1706 1706
1707 purple_debug_info("yahoo","Authentication: In yahoo_auth16_stage1_cb\n"); 1707 purple_debug_info("yahoo","Authentication: In yahoo_auth16_stage1_cb\n");
1708 1708
1709 g_return_if_fail(PURPLE_CONNECTION_IS_VALID(gc)); 1709 g_return_if_fail(PURPLE_CONNECTION_IS_VALID(gc));
1710 1710
1711 if (error_message != NULL) { 1711 if (error_message != NULL) {
1712 purple_debug_error("yahoo", "Login Failed, unable to retrieve login url: %s\n", error_message); 1712 purple_debug_error("yahoo", "Login Failed, unable to retrieve login url: %s\n", error_message);
1713 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, error_message); 1713 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, error_message);
1714 g_free(auth_data->seed); 1714 g_free(auth_data->seed);
1715 g_free(auth_data); 1715 g_free(auth_data);
1716 return; 1716 return;
1717 } 1717 }
1718 else if (len > 0 && ret_data && *ret_data) { 1718 else if (len > 0 && ret_data && *ret_data) {
1719 split_data = g_strsplit(ret_data, "\r\n", -1); 1719 split_data = g_strsplit(ret_data, "\r\n", -1);
1720 totalelements = g_strv_length(split_data); 1720 totalelements = g_strv_length(split_data);
1721 1721
1722 if(totalelements >= 5) { 1722 if(totalelements >= 5) {
1723 response_no = strtol(*(split_data+1), NULL, 10); 1723 response_no = strtol(split_data[1], NULL, 10);
1724 token = g_strdup(*(split_data+2)+6); 1724 token = g_strdup(split_data[2] + 6);
1725 } 1725 }
1726 else 1726 else
1727 response_no = -1; 1727 response_no = -1;
1728 1728
1729 g_strfreev(split_data); 1729 g_strfreev(split_data);
1730 1730
1731 if(response_no != 0) { 1731 if(response_no != 0) {
1732 /* Some error in the login process */ 1732 /* Some error in the login process */
1733 PurpleConnectionError error; 1733 PurpleConnectionError error;
1734 switch(response_no) { 1734 switch(response_no) {
1735 case -1: 1735 case -1:
1736 /* Some error in the received stream */ 1736 /* Some error in the received stream */
1737 error_reason = g_strdup(_("Error in the received data")); 1737 error_reason = g_strdup(_("Error in the received data"));
1738 error = PURPLE_CONNECTION_ERROR_NETWORK_ERROR; 1738 error = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
1739 break; 1739 break;
1778 /* OK to login, correct information provided */ 1778 /* OK to login, correct information provided */
1779 char *url = NULL; 1779 char *url = NULL;
1780 gboolean yahoojp = purple_account_get_bool(purple_connection_get_account(gc), 1780 gboolean yahoojp = purple_account_get_bool(purple_connection_get_account(gc),
1781 "yahoojp", 0); 1781 "yahoojp", 0);
1782 1782
1783 url = g_strdup_printf(yahoojp ? 1783 url = g_strdup_printf(yahoojp ? YAHOOJP_LOGIN_URL : YAHOO_LOGIN_URL, token);
1784 "https://login.yahoo.co.jp/config/pwtoken_login?src=ymsgr&ts=&token=%s" :
1785 "https://login.yahoo.com/config/pwtoken_login?src=ymsgr&ts=&token=%s",
1786 token);
1787 url_data2 = purple_util_fetch_url_request(url, TRUE, "Mozilla/4.0 (compatible; MSIE 5.5)", TRUE, NULL, FALSE, yahoo_auth16_stage2, auth_data); 1784 url_data2 = purple_util_fetch_url_request(url, TRUE, "Mozilla/4.0 (compatible; MSIE 5.5)", TRUE, NULL, FALSE, yahoo_auth16_stage2, auth_data);
1788 g_free(url); 1785 g_free(url);
1789 g_free(token); 1786 g_free(token);
1790 } 1787 }
1791 } 1788 }
1794 static void yahoo_auth16_stage1(PurpleConnection *gc, const char *seed) 1791 static void yahoo_auth16_stage1(PurpleConnection *gc, const char *seed)
1795 { 1792 {
1796 PurpleUtilFetchUrlData *url_data = NULL; 1793 PurpleUtilFetchUrlData *url_data = NULL;
1797 struct yahoo_auth_data *auth_data = NULL; 1794 struct yahoo_auth_data *auth_data = NULL;
1798 char *url = NULL; 1795 char *url = NULL;
1796 char *encoded_username;
1797 char *encoded_password;
1799 gboolean yahoojp; 1798 gboolean yahoojp;
1800 1799
1801 purple_debug_info("yahoo","Authentication: In yahoo_auth16_stage1\n"); 1800 purple_debug_info("yahoo","Authentication: In yahoo_auth16_stage1\n");
1802 1801
1803 if(!purple_ssl_is_supported()) { 1802 if(!purple_ssl_is_supported()) {
1809 "yahoojp", 0); 1808 "yahoojp", 0);
1810 auth_data = g_new0(struct yahoo_auth_data, 1); 1809 auth_data = g_new0(struct yahoo_auth_data, 1);
1811 auth_data->gc = gc; 1810 auth_data->gc = gc;
1812 auth_data->seed = g_strdup(seed); 1811 auth_data->seed = g_strdup(seed);
1813 1812
1814 url = g_strdup_printf(yahoojp ? 1813 encoded_username = g_strdup(purple_url_encode(purple_account_get_username(purple_connection_get_account(gc))));
1815 "https://login.yahoo.co.jp/config/pwtoken_get?src=ymsgr&ts=&login=%s&passwd=%s&chal=%s" : 1814 encoded_password = g_strdup(purple_url_encode(purple_connection_get_password(gc)));
1816 "https://login.yahoo.com/config/pwtoken_get?src=ymsgr&ts=&login=%s&passwd=%s&chal=%s", 1815 url = g_strdup_printf(yahoojp ? YAHOOJP_TOKEN_URL : YAHOO_TOKEN_URL,
1817 purple_account_get_username(purple_connection_get_account(gc)), 1816 encoded_username, encoded_password, purple_url_encode(seed));
1818 purple_connection_get_password(gc), seed); 1817 g_free(encoded_password);
1818 g_free(encoded_username);
1819 1819
1820 url_data = purple_util_fetch_url_request(url, TRUE, "Mozilla/4.0 (compatible; MSIE 5.5)", TRUE, NULL, FALSE, yahoo_auth16_stage1_cb, auth_data); 1820 url_data = purple_util_fetch_url_request(url, TRUE, "Mozilla/4.0 (compatible; MSIE 5.5)", TRUE, NULL, FALSE, yahoo_auth16_stage1_cb, auth_data);
1821 g_free(url); 1821 g_free(url);
1822 } 1822 }
1823 1823
2085 f = yahoo_friend_find_or_new(gc, who); 2085 f = yahoo_friend_find_or_new(gc, who);
2086 yahoo_update_status(gc, who, f); 2086 yahoo_update_status(gc, who, f);
2087 if(protocol) 2087 if(protocol)
2088 f->protocol = protocol; 2088 f->protocol = protocol;
2089 2089
2090 if( !g_hash_table_lookup(yd->peers, who) ) { 2090 if( !g_hash_table_lookup(yd->peers, who) ) {
2091 /* we are not connected as client, so set friend to not connected */ 2091 /* we are not connected as client, so set friend to not connected */
2092 if(msn) 2092 if(msn)
2093 yahoo_friend_set_p2p_status(f,YAHOO_P2PSTATUS_DO_NOT_CONNECT); 2093 yahoo_friend_set_p2p_status(f, YAHOO_P2PSTATUS_DO_NOT_CONNECT);
2094 else { 2094 else {
2095 yahoo_friend_set_p2p_status(f, YAHOO_P2PSTATUS_NOT_CONNECTED); 2095 yahoo_friend_set_p2p_status(f, YAHOO_P2PSTATUS_NOT_CONNECTED);
2096 f->p2p_packet_sent = 0; 2096 f->p2p_packet_sent = 0;
2097 } 2097 }
2098 } 2098 }
2224 * WHEN WE ARE CLIENT: yahoo server sends val_13 = 0, we send to peer val_13 = 1, receive back val_13 = 5, 2224 * WHEN WE ARE CLIENT: yahoo server sends val_13 = 0, we send to peer val_13 = 1, receive back val_13 = 5,
2225 * we send val_13=6, receive val_13=7, we send val_13=7, HALT. Keep sending val_13 = 7 as keep alive. 2225 * we send val_13=6, receive val_13=7, we send val_13=7, HALT. Keep sending val_13 = 7 as keep alive.
2226 * WHEN WE ARE SERVER: we send val_13 = 0 to yahoo server, peer sends us val_13 = 1, we send val_13 = 5, 2226 * WHEN WE ARE SERVER: we send val_13 = 0 to yahoo server, peer sends us val_13 = 1, we send val_13 = 5,
2227 * receive val_13 = 6, send val_13 = 7, receive val_13 = 7. HALT. Keep sending val_13 = 7 as keep alive. */ 2227 * receive val_13 = 6, send val_13 = 7, receive val_13 = 7. HALT. Keep sending val_13 = 7 as keep alive. */
2228 2228
2229 switch(p2p_data->val_13) { 2229 switch(p2p_data->val_13) {
2230 case 1 : val_13_to_send = 5; break; 2230 case 1 : val_13_to_send = 5; break;
2231 case 5 : val_13_to_send = 6; break; 2231 case 5 : val_13_to_send = 6; break;
2232 case 6 : val_13_to_send = 7; break; 2232 case 6 : val_13_to_send = 7; break;
2233 case 7 : if( g_hash_table_lookup(yd->peers, p2p_data->host_username) ) 2233 case 7 : if( g_hash_table_lookup(yd->peers, p2p_data->host_username) )
2234 return; 2234 return;
2249 /* build the raw packet and send it to the host */ 2249 /* build the raw packet and send it to the host */
2250 yahoo_p2p_write_pkt(source, pkt_to_send); 2250 yahoo_p2p_write_pkt(source, pkt_to_send);
2251 yahoo_packet_free(pkt_to_send); 2251 yahoo_packet_free(pkt_to_send);
2252 2252
2253 if( val_13_to_send == 7 ) 2253 if( val_13_to_send == 7 )
2254 if( !g_hash_table_lookup(yd->peers, p2p_data->host_username) ) { 2254 if( !g_hash_table_lookup(yd->peers, p2p_data->host_username) ) {
2255 g_hash_table_insert(yd->peers, g_strdup(p2p_data->host_username), p2p_data); 2255 g_hash_table_insert(yd->peers, g_strdup(p2p_data->host_username), p2p_data);
2256 /* If the peer is a friend, set him connected */ 2256 /* If the peer is a friend, set him connected */
2257 f = yahoo_friend_find(p2p_data->gc, p2p_data->host_username); 2257 f = yahoo_friend_find(p2p_data->gc, p2p_data->host_username);
2258 if (f) { 2258 if (f) {
2259 if(p2p_data->connection_type == YAHOO_P2P_WE_ARE_SERVER) { 2259 if(p2p_data->connection_type == YAHOO_P2P_WE_ARE_SERVER) {
2260 p2p_data->session_id = f->session_id; 2260 p2p_data->session_id = f->session_id;
2261 yahoo_friend_set_p2p_status(f, YAHOO_P2PSTATUS_WE_ARE_SERVER); 2261 yahoo_friend_set_p2p_status(f, YAHOO_P2PSTATUS_WE_ARE_SERVER);
2262 } 2262 }
2263 else 2263 else
2264 yahoo_friend_set_p2p_status(f, YAHOO_P2PSTATUS_WE_ARE_CLIENT); 2264 yahoo_friend_set_p2p_status(f, YAHOO_P2PSTATUS_WE_ARE_CLIENT);
2327 2327
2328 purple_debug(PURPLE_DEBUG_MISC, "yahoo", "p2p: Yahoo Service: 0x%02x Status: %d\n",pkt->service, pkt->status); 2328 purple_debug(PURPLE_DEBUG_MISC, "yahoo", "p2p: Yahoo Service: 0x%02x Status: %d\n",pkt->service, pkt->status);
2329 yahoo_packet_read(pkt, buf + pos, pktlen); 2329 yahoo_packet_read(pkt, buf + pos, pktlen);
2330 2330
2331 /* packet processing */ 2331 /* packet processing */
2332 switch(pkt->service) { 2332 switch(pkt->service) {
2333 case YAHOO_SERVICE_P2PFILEXFER: 2333 case YAHOO_SERVICE_P2PFILEXFER:
2334 yahoo_p2p_process_p2pfilexfer(data, source, pkt); 2334 yahoo_p2p_process_p2pfilexfer(data, source, pkt);
2335 break; 2335 break;
2336 case YAHOO_SERVICE_MESSAGE: 2336 case YAHOO_SERVICE_MESSAGE:
2337 yahoo_process_message(p2p_data->gc, pkt, YAHOO_PKT_TYPE_P2P); 2337 yahoo_process_message(p2p_data->gc, pkt, YAHOO_PKT_TYPE_P2P);
2413 struct yahoo_data *yd; 2413 struct yahoo_data *yd;
2414 2414
2415 if(!(p2p_data = data)) 2415 if(!(p2p_data = data))
2416 return ; 2416 return ;
2417 2417
2418 if(listenfd == -1) { 2418 if(listenfd == -1) {
2419 purple_debug_warning("yahoo","p2p: error starting p2p server\n"); 2419 purple_debug_warning("yahoo","p2p: error starting p2p server\n");
2420 yahoo_p2p_disconnect_destroy_data(data); 2420 yahoo_p2p_disconnect_destroy_data(data);
2421 return; 2421 return;
2422 } 2422 }
2423 2423
2514 2514
2515 if(!(p2p_data = data)) 2515 if(!(p2p_data = data))
2516 return ; 2516 return ;
2517 yd = p2p_data->gc->proto_data; 2517 yd = p2p_data->gc->proto_data;
2518 2518
2519 if(error_message != NULL) { 2519 if(error_message != NULL) {
2520 purple_debug_warning("yahoo","p2p: %s\n",error_message); 2520 purple_debug_warning("yahoo","p2p: %s\n",error_message);
2521 yahoo_send_p2p_pkt(p2p_data->gc, p2p_data->host_username, 2);/* send p2p init packet with val_13=2 */ 2521 yahoo_send_p2p_pkt(p2p_data->gc, p2p_data->host_username, 2);/* send p2p init packet with val_13=2 */
2522 2522
2523 yahoo_p2p_disconnect_destroy_data(p2p_data); 2523 yahoo_p2p_disconnect_destroy_data(p2p_data);
2524 return; 2524 return;
2621 yahoo_friend_set_ip(f, host_ip); 2621 yahoo_friend_set_ip(f, host_ip);
2622 purple_debug_info("yahoo", "IP : %s\n", host_ip); 2622 purple_debug_info("yahoo", "IP : %s\n", host_ip);
2623 2623
2624 account = purple_connection_get_account(gc); 2624 account = purple_connection_get_account(gc);
2625 2625
2626 if(val_11==0) { 2626 if(val_11==0) {
2627 if(!f) 2627 if(!f)
2628 return; 2628 return;
2629 else 2629 else
2630 val_11 = f->session_id; 2630 val_11 = f->session_id;
2631 } 2631 }
2638 p2p_data->gc = gc; 2638 p2p_data->gc = gc;
2639 p2p_data->connection_type = YAHOO_P2P_WE_ARE_CLIENT; 2639 p2p_data->connection_type = YAHOO_P2P_WE_ARE_CLIENT;
2640 p2p_data->source = -1; 2640 p2p_data->source = -1;
2641 2641
2642 /* connect to host */ 2642 /* connect to host */
2643 if((purple_proxy_connect(NULL, account, host_ip, YAHOO_PAGER_PORT_P2P, yahoo_p2p_init_cb, p2p_data))==NULL) { 2643 if((purple_proxy_connect(NULL, account, host_ip, YAHOO_PAGER_PORT_P2P, yahoo_p2p_init_cb, p2p_data))==NULL) {
2644 purple_debug_info("yahoo","p2p: Connection to %s failed\n", host_ip); 2644 purple_debug_info("yahoo","p2p: Connection to %s failed\n", host_ip);
2645 g_free(p2p_data->host_ip); 2645 g_free(p2p_data->host_ip);
2646 g_free(p2p_data->host_username); 2646 g_free(p2p_data->host_username);
2647 g_free(p2p_data); 2647 g_free(p2p_data);
2648 } 2648 }
3070 while ((i = strstr(i, "Set-Cookie: "))) { 3070 while ((i = strstr(i, "Set-Cookie: "))) {
3071 3071
3072 i += strlen("Set-Cookie: "); 3072 i += strlen("Set-Cookie: ");
3073 for (;*i != ';' && *i != '\0'; i++) 3073 for (;*i != ';' && *i != '\0'; i++)
3074 g_string_append_c(s, *i); 3074 g_string_append_c(s, *i);
3075 3075
3076 g_string_append(s, "; "); 3076 g_string_append(s, "; ");
3077 /* Should these cookies be included too when trying for xfer? 3077 /* Should these cookies be included too when trying for xfer?
3078 * It seems to work without these 3078 * It seems to work without these
3079 */ 3079 */
3080 } 3080 }
4017 char *status = NULL; 4017 char *status = NULL;
4018 char *carrier = NULL; 4018 char *carrier = NULL;
4019 PurpleAccount *account = purple_connection_get_account(gc); 4019 PurpleAccount *account = purple_connection_get_account(gc);
4020 PurpleConversation *conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, sms_cb_data->who, account); 4020 PurpleConversation *conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, sms_cb_data->who, account);
4021 4021
4022 if (error_message != NULL) { 4022 if (error_message != NULL) {
4023 purple_conversation_write(conv, NULL, "Cant send SMS, Unable to obtain mobile carrier", PURPLE_MESSAGE_SYSTEM, time(NULL)); 4023 purple_conversation_write(conv, NULL, "Cant send SMS, Unable to obtain mobile carrier", PURPLE_MESSAGE_SYSTEM, time(NULL));
4024 4024
4025 g_free(sms_cb_data->who); 4025 g_free(sms_cb_data->who);
4026 g_free(sms_cb_data->what); 4026 g_free(sms_cb_data->what);
4027 g_free(sms_cb_data); 4027 g_free(sms_cb_data);
4039 validate_data_child = xmlnode_get_child(validate_data_root, "carrier"); 4039 validate_data_child = xmlnode_get_child(validate_data_root, "carrier");
4040 carrier = xmlnode_get_data(validate_data_child); 4040 carrier = xmlnode_get_data(validate_data_child);
4041 4041
4042 purple_debug_info("yahoo","SMS validate data: Mobile:%s, Status:%s, Carrier:%s\n", mobile_no, status, carrier); 4042 purple_debug_info("yahoo","SMS validate data: Mobile:%s, Status:%s, Carrier:%s\n", mobile_no, status, carrier);
4043 4043
4044 if( strcmp(status, "Valid") == 0) { 4044 if( strcmp(status, "Valid") == 0) {
4045 g_hash_table_insert(yd->sms_carrier, g_strdup_printf("+%s", mobile_no), g_strdup(carrier)); 4045 g_hash_table_insert(yd->sms_carrier, g_strdup_printf("+%s", mobile_no), g_strdup(carrier));
4046 yahoo_send_im(sms_cb_data->gc, sms_cb_data->who, sms_cb_data->what, PURPLE_MESSAGE_SEND); 4046 yahoo_send_im(sms_cb_data->gc, sms_cb_data->who, sms_cb_data->what, PURPLE_MESSAGE_SEND);
4047 } 4047 }
4048 else { 4048 else {
4049 g_hash_table_insert(yd->sms_carrier, g_strdup_printf("+%s", mobile_no), g_strdup("Unknown")); 4049 g_hash_table_insert(yd->sms_carrier, g_strdup_printf("+%s", mobile_no), g_strdup("Unknown"));
4106 yahoo_get_sms_carrier_cb, data); 4106 yahoo_get_sms_carrier_cb, data);
4107 4107
4108 g_free(request); 4108 g_free(request);
4109 g_free(validate_request_str); 4109 g_free(validate_request_str);
4110 4110
4111 if (!url_data) { 4111 if (!url_data) {
4112 PurpleAccount *account = purple_connection_get_account(gc); 4112 PurpleAccount *account = purple_connection_get_account(gc);
4113 PurpleConversation *conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, sms_cb_data->who, account); 4113 PurpleConversation *conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, sms_cb_data->who, account);
4114 purple_conversation_write(conv, NULL, "Cant send SMS, Unable to obtain mobile carrier", PURPLE_MESSAGE_SYSTEM, time(NULL)); 4114 purple_conversation_write(conv, NULL, "Cant send SMS, Unable to obtain mobile carrier", PURPLE_MESSAGE_SYSTEM, time(NULL));
4115 g_free(sms_cb_data->who); 4115 g_free(sms_cb_data->who);
4116 g_free(sms_cb_data->what); 4116 g_free(sms_cb_data->what);
4149 } 4149 }
4150 } 4150 }
4151 4151
4152 msn = g_str_has_prefix(who, "msn/") || g_str_has_prefix(who, "MSN/"); 4152 msn = g_str_has_prefix(who, "msn/") || g_str_has_prefix(who, "MSN/");
4153 4153
4154 if( strncmp(who, "+", 1) == 0 ) { 4154 if( strncmp(who, "+", 1) == 0 ) {
4155 /* we have an sms to be sent */ 4155 /* we have an sms to be sent */
4156 gchar *carrier = NULL; 4156 gchar *carrier = NULL;
4157 const char *alias = NULL; 4157 const char *alias = NULL;
4158 PurpleAccount *account = purple_connection_get_account(gc); 4158 PurpleAccount *account = purple_connection_get_account(gc);
4159 PurpleConversation *conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, who, account); 4159 PurpleConversation *conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, who, account);
4160 4160
4161 carrier = g_hash_table_lookup(yd->sms_carrier, who); 4161 carrier = g_hash_table_lookup(yd->sms_carrier, who);
4162 if (!carrier) { 4162 if (!carrier) {
4163 struct yahoo_sms_carrier_cb_data *sms_cb_data; 4163 struct yahoo_sms_carrier_cb_data *sms_cb_data;
4164 sms_cb_data = g_malloc(sizeof(struct yahoo_sms_carrier_cb_data)); 4164 sms_cb_data = g_malloc(sizeof(struct yahoo_sms_carrier_cb_data));
4165 sms_cb_data->gc = gc; 4165 sms_cb_data->gc = gc;
4166 sms_cb_data->who = g_malloc(strlen(who)); 4166 sms_cb_data->who = g_malloc(strlen(who));
4167 sms_cb_data->what = g_malloc(strlen(what)); 4167 sms_cb_data->what = g_malloc(strlen(what));
4199 4199
4200 return ret; 4200 return ret;
4201 } 4201 }
4202 4202
4203 pkt = yahoo_packet_new(YAHOO_SERVICE_MESSAGE, YAHOO_STATUS_OFFLINE, 0); 4203 pkt = yahoo_packet_new(YAHOO_SERVICE_MESSAGE, YAHOO_STATUS_OFFLINE, 0);
4204 if(msn) { 4204 if(msn) {
4205 yahoo_packet_hash(pkt, "ss", 1, purple_connection_get_display_name(gc), 5, who+4); 4205 yahoo_packet_hash(pkt, "ss", 1, purple_connection_get_display_name(gc), 5, who+4);
4206 yahoo_packet_hash_int(pkt, 241, 2); 4206 yahoo_packet_hash_int(pkt, 241, 2);
4207 } 4207 }
4208 else { 4208 else {
4209 yahoo_packet_hash(pkt, "ss", 1, purple_connection_get_display_name(gc), 5, who); 4209 yahoo_packet_hash(pkt, "ss", 1, purple_connection_get_display_name(gc), 5, who);
4246 yahoo_packet_hash_str(pkt, 206, "0"); /* 0 = no picture, 2 = picture, maybe 1 = avatar? */ 4246 yahoo_packet_hash_str(pkt, 206, "0"); /* 0 = no picture, 2 = picture, maybe 1 = avatar? */
4247 else 4247 else
4248 yahoo_packet_hash_str(pkt, 206, "2"); 4248 yahoo_packet_hash_str(pkt, 206, "2");
4249 4249
4250 /* We may need to not send any packets over 2000 bytes, but I'm not sure yet. */ 4250 /* We may need to not send any packets over 2000 bytes, but I'm not sure yet. */
4251 if ((YAHOO_PACKET_HDRLEN + yahoo_packet_length(pkt)) <= 2000) { 4251 if ((YAHOO_PACKET_HDRLEN + yahoo_packet_length(pkt)) <= 2000) {
4252 /* if p2p link exists, send through it. To-do: key 15, time value to be sent in case of p2p */ 4252 /* if p2p link exists, send through it. To-do: key 15, time value to be sent in case of p2p */
4253 if( (p2p_data = g_hash_table_lookup(yd->peers, who)) && !msn ) { 4253 if( (p2p_data = g_hash_table_lookup(yd->peers, who)) && !msn ) {
4254 yahoo_packet_hash_int(pkt, 11, p2p_data->session_id); 4254 yahoo_packet_hash_int(pkt, 11, p2p_data->session_id);
4255 yahoo_p2p_write_pkt(p2p_data->source, pkt); 4255 yahoo_p2p_write_pkt(p2p_data->source, pkt);
4256 } 4256 }
4257 else { 4257 else {
4258 yahoo_packet_send(pkt, yd); 4258 yahoo_packet_send(pkt, yd);
4283 return 0; 4283 return 0;
4284 4284
4285 pkt = yahoo_packet_new(YAHOO_SERVICE_NOTIFY, YAHOO_STATUS_TYPING, 0); 4285 pkt = yahoo_packet_new(YAHOO_SERVICE_NOTIFY, YAHOO_STATUS_TYPING, 0);
4286 4286
4287 /* check to see if p2p link exists, send through it */ 4287 /* check to see if p2p link exists, send through it */
4288 if( (p2p_data = g_hash_table_lookup(yd->peers, who)) && !msn ) { 4288 if( (p2p_data = g_hash_table_lookup(yd->peers, who)) && !msn ) {
4289 yahoo_packet_hash(pkt, "sssssis", 49, "TYPING", 1, purple_connection_get_display_name(gc), 4289 yahoo_packet_hash(pkt, "sssssis", 49, "TYPING", 1, purple_connection_get_display_name(gc),
4290 14, " ", 13, state == PURPLE_TYPING ? "1" : "0", 4290 14, " ", 13, state == PURPLE_TYPING ? "1" : "0",
4291 5, who, 11, p2p_data->session_id, 1002, "1"); /* To-do: key 15 to be sent in case of p2p */ 4291 5, who, 11, p2p_data->session_id, 1002, "1"); /* To-do: key 15 to be sent in case of p2p */
4292 yahoo_p2p_write_pkt(p2p_data->source, pkt); 4292 yahoo_p2p_write_pkt(p2p_data->source, pkt);
4293 yahoo_packet_free(pkt); 4293 yahoo_packet_free(pkt);
4554 else 4554 else
4555 group = "Buddies"; 4555 group = "Buddies";
4556 4556
4557 group2 = yahoo_string_encode(gc, group, NULL); 4557 group2 = yahoo_string_encode(gc, group, NULL);
4558 pkt = yahoo_packet_new(YAHOO_SERVICE_ADDBUDDY, YAHOO_STATUS_AVAILABLE, 0); 4558 pkt = yahoo_packet_new(YAHOO_SERVICE_ADDBUDDY, YAHOO_STATUS_AVAILABLE, 0);
4559 if(msn) { 4559 if(msn) {
4560 yahoo_packet_hash(pkt, "sssssssssss", 4560 yahoo_packet_hash(pkt, "sssssssssss",
4561 14, "", 4561 14, "",
4562 65, group2, 4562 65, group2,
4563 97, "1", 4563 97, "1",
4564 1, purple_connection_get_display_name(gc), 4564 1, purple_connection_get_display_name(gc),
4717 * don't bother letting the server know. 4717 * don't bother letting the server know.
4718 */ 4718 */
4719 if (!f) 4719 if (!f)
4720 return; 4720 return;
4721 4721
4722 if(f->protocol == 2) { 4722 if(f->protocol == 2) {
4723 msn = TRUE; 4723 msn = TRUE;
4724 temp = who+4; 4724 temp = who+4;
4725 } else 4725 } else
4726 temp = who; 4726 temp = who;
4727 4727