| 73 #if TRY_WEBMESSENGER_LOGIN |
73 #if TRY_WEBMESSENGER_LOGIN |
| 74 static void |
74 static void |
| 75 yahoo_login_page_cb(PurpleHttpConnection *http_conn, |
75 yahoo_login_page_cb(PurpleHttpConnection *http_conn, |
| 76 PurpleHttpResponse *response, gpointer _unused); |
76 PurpleHttpResponse *response, gpointer _unused); |
| 77 #endif /* TRY_WEBMESSENGER_LOGIN */ |
77 #endif /* TRY_WEBMESSENGER_LOGIN */ |
| 78 |
|
| 79 static gboolean yahoo_is_japan(PurpleAccount *account) |
|
| 80 { |
|
| 81 return purple_strequal(purple_account_get_protocol_id(account), "prpl-yahoojp"); |
|
| 82 } |
|
| 83 |
78 |
| 84 static void yahoo_update_status(PurpleConnection *gc, const char *name, YahooFriend *f) |
79 static void yahoo_update_status(PurpleConnection *gc, const char *name, YahooFriend *f) |
| 85 { |
80 { |
| 86 char *status = NULL; |
81 char *status = NULL; |
| 87 |
82 |
| 1723 *n = *p; |
1718 *n = *p; |
| 1724 } |
1719 } |
| 1725 |
1720 |
| 1726 *n = '\0'; |
1721 *n = '\0'; |
| 1727 |
1722 |
| |
1723 /* XXX: Is this related to Yahoo! Japan? If so, it should be removed. -mmcco */ |
| 1728 if (strstr(text, "\033$B")) |
1724 if (strstr(text, "\033$B")) |
| 1729 converted = g_convert(new, n - new, OUT_CHARSET, "iso-2022-jp", NULL, NULL, NULL); |
1725 converted = g_convert(new, n - new, OUT_CHARSET, "iso-2022-jp", NULL, NULL, NULL); |
| 1730 if (!converted) |
1726 if (!converted) |
| 1731 converted = g_convert(new, n - new, OUT_CHARSET, "iso-8859-1", NULL, NULL, NULL); |
1727 converted = g_convert(new, n - new, OUT_CHARSET, "iso-8859-1", NULL, NULL, NULL); |
| 1732 g_free(new); |
1728 g_free(new); |
| 1735 } |
1731 } |
| 1736 |
1732 |
| 1737 static void yahoo_process_mail(PurpleConnection *gc, struct yahoo_packet *pkt) |
1733 static void yahoo_process_mail(PurpleConnection *gc, struct yahoo_packet *pkt) |
| 1738 { |
1734 { |
| 1739 PurpleAccount *account = purple_connection_get_account(gc); |
1735 PurpleAccount *account = purple_connection_get_account(gc); |
| 1740 YahooData *yd = purple_connection_get_protocol_data(gc); |
|
| 1741 const char *who = NULL; |
1736 const char *who = NULL; |
| 1742 const char *email = NULL; |
1737 const char *email = NULL; |
| 1743 const char *subj = NULL; |
1738 const char *subj = NULL; |
| 1744 const char *yahoo_mail_url = (yd->jp? YAHOOJP_MAIL_URL: YAHOO_MAIL_URL); |
1739 const char *yahoo_mail_url = YAHOO_MAIL_URL; |
| 1745 int count = 0; |
1740 int count = 0; |
| 1746 GSList *l = pkt->hash; |
1741 GSList *l = pkt->hash; |
| 1747 |
1742 |
| 1748 if (!purple_account_get_check_mail(account)) |
1743 if (!purple_account_get_check_mail(account)) |
| 1749 return; |
1744 return; |
| 1863 1, name, |
1858 1, name, |
| 1864 0, name, |
1859 0, name, |
| 1865 277, yd->cookie_y, |
1860 277, yd->cookie_y, |
| 1866 278, yd->cookie_t, |
1861 278, yd->cookie_t, |
| 1867 307, base64_string, |
1862 307, base64_string, |
| 1868 244, yd->jp ? YAHOOJP_CLIENT_VERSION_ID : YAHOO_CLIENT_VERSION_ID, |
1863 244, YAHOO_CLIENT_VERSION_ID, |
| 1869 2, name, |
1864 2, name, |
| 1870 2, "1", |
1865 2, "1", |
| 1871 59, yd->cookie_b, |
1866 59, yd->cookie_b, |
| 1872 98, purple_account_get_string(account, "room_list_locale", yd->jp ? "jp" : "us"), |
1867 98, purple_account_get_string(account, "room_list_locale", "us"), |
| 1873 135, yd->jp ? YAHOOJP_CLIENT_VERSION : YAHOO_CLIENT_VERSION); |
1868 135, YAHOO_CLIENT_VERSION); |
| 1874 } else { /* don't try to send an empty B cookie - the server will be mad */ |
1869 } else { /* don't try to send an empty B cookie - the server will be mad */ |
| 1875 yahoo_packet_hash(pkt, "sssssssss", |
1870 yahoo_packet_hash(pkt, "sssssssss", |
| 1876 1, name, |
1871 1, name, |
| 1877 0, name, |
1872 0, name, |
| 1878 277, yd->cookie_y, |
1873 277, yd->cookie_y, |
| 1879 278, yd->cookie_t, |
1874 278, yd->cookie_t, |
| 1880 307, base64_string, |
1875 307, base64_string, |
| 1881 244, yd->jp ? YAHOOJP_CLIENT_VERSION_ID : YAHOO_CLIENT_VERSION_ID, |
1876 244, YAHOO_CLIENT_VERSION_ID, |
| 1882 2, name, |
1877 2, name, |
| 1883 2, "1", |
1878 2, "1", |
| 1884 98, purple_account_get_string(account, "room_list_locale", yd->jp ? "jp" : "us"), |
1879 98, purple_account_get_string(account, "room_list_locale", "us"), |
| 1885 135, yd->jp ? YAHOOJP_CLIENT_VERSION : YAHOO_CLIENT_VERSION); |
1880 135, YAHOO_CLIENT_VERSION); |
| 1886 } |
1881 } |
| 1887 |
1882 |
| 1888 if (yd->picture_checksum) |
1883 if (yd->picture_checksum) |
| 1889 yahoo_packet_hash_int(pkt, 192, yd->picture_checksum); |
1884 yahoo_packet_hash_int(pkt, 192, yd->picture_checksum); |
| 1890 yahoo_packet_send_and_free(pkt, yd); |
1885 yahoo_packet_send_and_free(pkt, yd); |
| 2094 g_free(auth_data->seed); |
2089 g_free(auth_data->seed); |
| 2095 g_free(auth_data); |
2090 g_free(auth_data); |
| 2096 g_free(token); |
2091 g_free(token); |
| 2097 } |
2092 } |
| 2098 else { |
2093 else { |
| 2099 /* OK to login, correct information provided */ |
|
| 2100 gboolean yahoojp = yahoo_is_japan(account); |
|
| 2101 PurpleHttpRequest *req; |
2094 PurpleHttpRequest *req; |
| 2102 |
2095 |
| 2103 req = purple_http_request_new(NULL); |
2096 req = purple_http_request_new(NULL); |
| 2104 purple_http_request_set_url_printf(req, |
2097 purple_http_request_set_url_printf(req, YAHOO_LOGIN_URL, token); |
| 2105 yahoojp ? YAHOOJP_LOGIN_URL : YAHOO_LOGIN_URL, |
|
| 2106 token); |
|
| 2107 purple_http_request_header_set(req, "User-Agent", |
2098 purple_http_request_header_set(req, "User-Agent", |
| 2108 YAHOO_CLIENT_USERAGENT); |
2099 YAHOO_CLIENT_USERAGENT); |
| 2109 purple_http_connection_set_add(yd->http_reqs, |
2100 purple_http_connection_set_add(yd->http_reqs, |
| 2110 purple_http_request(gc, req, |
2101 purple_http_request(gc, req, |
| 2111 yahoo_auth16_stage2, auth_data)); |
2102 yahoo_auth16_stage2, auth_data)); |
| 2117 } |
2108 } |
| 2118 |
2109 |
| 2119 static void yahoo_auth16_stage1(PurpleConnection *gc, const char *seed) |
2110 static void yahoo_auth16_stage1(PurpleConnection *gc, const char *seed) |
| 2120 { |
2111 { |
| 2121 YahooData *yd = purple_connection_get_protocol_data(gc); |
2112 YahooData *yd = purple_connection_get_protocol_data(gc); |
| 2122 PurpleAccount *account = purple_connection_get_account(gc); |
|
| 2123 PurpleHttpRequest *req; |
2113 PurpleHttpRequest *req; |
| 2124 struct yahoo_auth_data *auth_data = NULL; |
2114 struct yahoo_auth_data *auth_data = NULL; |
| 2125 char *encoded_username; |
2115 char *encoded_username; |
| 2126 char *encoded_password; |
2116 char *encoded_password; |
| 2127 gboolean yahoojp = yahoo_is_japan(account); |
|
| 2128 |
2117 |
| 2129 purple_debug_info("yahoo", "Authentication: In yahoo_auth16_stage1\n"); |
2118 purple_debug_info("yahoo", "Authentication: In yahoo_auth16_stage1\n"); |
| 2130 |
2119 |
| 2131 if(!purple_ssl_is_supported()) { |
2120 if(!purple_ssl_is_supported()) { |
| 2132 purple_connection_error(gc, PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT, _("SSL support unavailable")); |
2121 purple_connection_error(gc, PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT, _("SSL support unavailable")); |
| 2139 |
2128 |
| 2140 encoded_username = g_strdup(purple_url_encode(purple_account_get_username(purple_connection_get_account(gc)))); |
2129 encoded_username = g_strdup(purple_url_encode(purple_account_get_username(purple_connection_get_account(gc)))); |
| 2141 encoded_password = g_strdup(purple_url_encode(purple_connection_get_password(gc))); |
2130 encoded_password = g_strdup(purple_url_encode(purple_connection_get_password(gc))); |
| 2142 |
2131 |
| 2143 req = purple_http_request_new(NULL); |
2132 req = purple_http_request_new(NULL); |
| 2144 purple_http_request_set_url_printf(req, |
2133 purple_http_request_set_url_printf(req, YAHOO_TOKEN_URL, |
| 2145 yahoojp ? YAHOOJP_TOKEN_URL : YAHOO_TOKEN_URL, |
|
| 2146 encoded_username, encoded_password, purple_url_encode(seed)); |
2134 encoded_username, encoded_password, purple_url_encode(seed)); |
| 2147 purple_http_request_header_set(req, "User-Agent", YAHOO_CLIENT_USERAGENT); |
2135 purple_http_request_header_set(req, "User-Agent", YAHOO_CLIENT_USERAGENT); |
| 2148 purple_http_connection_set_add(yd->http_reqs, purple_http_request(gc, |
2136 purple_http_connection_set_add(yd->http_reqs, purple_http_request(gc, |
| 2149 req, yahoo_auth16_stage1_cb, auth_data)); |
2137 req, yahoo_auth16_stage1_cb, auth_data)); |
| 2150 purple_http_request_unref(req); |
2138 purple_http_request_unref(req); |
| 2506 size_t pkt_len; |
2494 size_t pkt_len; |
| 2507 gssize written; |
2495 gssize written; |
| 2508 guchar *raw_packet; |
2496 guchar *raw_packet; |
| 2509 |
2497 |
| 2510 /*build the raw packet and send it to the host*/ |
2498 /*build the raw packet and send it to the host*/ |
| 2511 pkt_len = yahoo_packet_build(pkt, 0, 0, 0, &raw_packet); |
2499 pkt_len = yahoo_packet_build(pkt, 0, 0, &raw_packet); |
| 2512 written = write(source, raw_packet, pkt_len); |
2500 written = write(source, raw_packet, pkt_len); |
| 2513 if (written < 0 || (gsize)written != pkt_len) |
2501 if (written < 0 || (gsize)written != pkt_len) |
| 2514 purple_debug_warning("yahoo","p2p: couldn't write to the source\n"); |
2502 purple_debug_warning("yahoo","p2p: couldn't write to the source\n"); |
| 2515 g_free(raw_packet); |
2503 g_free(raw_packet); |
| 2516 } |
2504 } |
| 3704 |
3692 |
| 3705 if (!purple_http_response_is_successful(response)) { |
3693 if (!purple_http_response_is_successful(response)) { |
| 3706 purple_debug_error("yahoo", "Unable to retrieve server info: %s\n", |
3694 purple_debug_error("yahoo", "Unable to retrieve server info: %s\n", |
| 3707 purple_http_response_get_error(response)); |
3695 purple_http_response_get_error(response)); |
| 3708 |
3696 |
| 3709 if(yahoo_is_japan(a)) { /* We don't know fallback hosts for Yahoo Japan :( */ |
3697 if(purple_proxy_connect(gc, a, YAHOO_PAGER_HOST_FALLBACK, port, |
| |
3698 yahoo_got_connected, gc) == NULL) { |
| 3710 purple_connection_error(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
3699 purple_connection_error(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
| 3711 _("Unable to connect: The server returned an empty response.")); |
3700 _("Unable to connect")); |
| 3712 } else { |
|
| 3713 if(purple_proxy_connect(gc, a, YAHOO_PAGER_HOST_FALLBACK, port, |
|
| 3714 yahoo_got_connected, gc) == NULL) { |
|
| 3715 purple_connection_error(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
|
| 3716 _("Unable to connect")); |
|
| 3717 } |
|
| 3718 } |
3701 } |
| 3719 } else { |
3702 } else { |
| 3720 got_data = purple_http_response_get_data(response, NULL); |
3703 got_data = purple_http_response_get_data(response, NULL); |
| 3721 strings = g_strsplit(got_data, "\r\n", -1); |
3704 strings = g_strsplit(got_data, "\r\n", -1); |
| 3722 |
3705 |
| 3739 _("Unable to connect")); |
3722 _("Unable to connect")); |
| 3740 } else { |
3723 } else { |
| 3741 purple_debug_error("yahoo", "No CS address retrieved! Server " |
3724 purple_debug_error("yahoo", "No CS address retrieved! Server " |
| 3742 "response:\n%s\n", got_data); |
3725 "response:\n%s\n", got_data); |
| 3743 |
3726 |
| 3744 if(yahoo_is_japan(a)) { /* We don't know fallback hosts for Yahoo Japan :( */ |
3727 if(purple_proxy_connect(gc, a, YAHOO_PAGER_HOST_FALLBACK, port, |
| |
3728 yahoo_got_connected, gc) == NULL) { |
| 3745 purple_connection_error(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
3729 purple_connection_error(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
| 3746 _("Unable to connect: The server's response did not contain " |
3730 _("Unable to connect")); |
| 3747 "the necessary information")); |
3731 } |
| 3748 } else |
|
| 3749 if(purple_proxy_connect(gc, a, YAHOO_PAGER_HOST_FALLBACK, port, |
|
| 3750 yahoo_got_connected, gc) == NULL) { |
|
| 3751 purple_connection_error(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
|
| 3752 _("Unable to connect")); |
|
| 3753 } |
|
| 3754 } |
3732 } |
| 3755 } |
3733 } |
| 3756 |
3734 |
| 3757 g_strfreev(strings); |
3735 g_strfreev(strings); |
| 3758 g_free(cs_server); |
3736 g_free(cs_server); |
| 3773 purple_connection_update_progress(gc, _("Connecting"), 1, 2); |
3751 purple_connection_update_progress(gc, _("Connecting"), 1, 2); |
| 3774 |
3752 |
| 3775 purple_connection_set_display_name(gc, purple_account_get_username(account)); |
3753 purple_connection_set_display_name(gc, purple_account_get_username(account)); |
| 3776 |
3754 |
| 3777 yd->gc = gc; |
3755 yd->gc = gc; |
| 3778 yd->jp = yahoo_is_japan(account); |
|
| 3779 yd->yahoo_local_p2p_server_fd = -1; |
3756 yd->yahoo_local_p2p_server_fd = -1; |
| 3780 yd->fd = -1; |
3757 yd->fd = -1; |
| 3781 yd->txhandler = 0; |
3758 yd->txhandler = 0; |
| 3782 /* TODO: Is there a good grow size for the buffer? */ |
3759 /* TODO: Is there a good grow size for the buffer? */ |
| 3783 yd->txbuf = purple_circular_buffer_new(0); |
3760 yd->txbuf = purple_circular_buffer_new(0); |
| 3798 |
3775 |
| 3799 yahoo_picture_check(account); |
3776 yahoo_picture_check(account); |
| 3800 |
3777 |
| 3801 /* Get the pager server. Actually start connecting in the callback since we |
3778 /* Get the pager server. Actually start connecting in the callback since we |
| 3802 * must have the contents of the HTTP response to proceed. */ |
3779 * must have the contents of the HTTP response to proceed. */ |
| 3803 req = purple_http_request_new(yd->jp ? YAHOOJP_PAGER_HOST_REQ_URL : |
3780 req = purple_http_request_new(YAHOO_PAGER_HOST_REQ_URL); |
| 3804 YAHOO_PAGER_HOST_REQ_URL); |
|
| 3805 purple_http_request_header_set(req, "User-Agent", YAHOO_CLIENT_USERAGENT); |
3781 purple_http_request_header_set(req, "User-Agent", YAHOO_CLIENT_USERAGENT); |
| 3806 purple_http_connection_set_add(yd->http_reqs, purple_http_request(gc, |
3782 purple_http_connection_set_add(yd->http_reqs, purple_http_request(gc, |
| 3807 req, yahoo_got_pager_server, yd)); |
3783 req, yahoo_got_pager_server, yd)); |
| 3808 purple_http_request_unref(req); |
3784 purple_http_request_unref(req); |
| 3809 |
3785 |
| 4327 PurpleHttpResponse *response, gpointer _unused) |
4303 PurpleHttpResponse *response, gpointer _unused) |
| 4328 { |
4304 { |
| 4329 PurpleConnection *gc = |
4305 PurpleConnection *gc = |
| 4330 purple_http_conn_get_purple_connection(http_conn); |
4306 purple_http_conn_get_purple_connection(http_conn); |
| 4331 gchar *url; |
4307 gchar *url; |
| 4332 YahooData *yd = purple_connection_get_protocol_data(gc); |
|
| 4333 |
4308 |
| 4334 PURPLE_ASSERT_CONNECTION_IS_VALID(gc); |
4309 PURPLE_ASSERT_CONNECTION_IS_VALID(gc); |
| 4335 |
4310 |
| 4336 if (!purple_http_response_is_successful(response)) { |
4311 if (!purple_http_response_is_successful(response)) { |
| 4337 purple_debug_error("yahoo", |
4312 purple_debug_error("yahoo", |
| 4338 "Requesting mail login token failed: %s\n", |
4313 "Requesting mail login token failed: %s\n", |
| 4339 purple_http_response_get_error(response)); |
4314 purple_http_response_get_error(response)); |
| 4340 url = g_strdup(yd->jp ? YAHOOJP_MAIL_URL : YAHOO_MAIL_URL); |
4315 url = g_strdup(YAHOO_MAIL_URL); |
| 4341 } else { |
4316 } else { |
| 4342 /* Should we not be hardcoding the rd url? */ |
4317 /* Should we not be hardcoding the rd url? */ |
| 4343 gchar *token; |
4318 gchar *token; |
| 4344 token = g_strdup(purple_http_response_get_data(response, NULL)); |
4319 token = g_strdup(purple_http_response_get_data(response, NULL)); |
| 4345 g_strstrip(token); |
4320 g_strstrip(token); |
| 4359 |
4334 |
| 4360 |
4335 |
| 4361 static void yahoo_show_inbox(PurpleProtocolAction *action) |
4336 static void yahoo_show_inbox(PurpleProtocolAction *action) |
| 4362 { |
4337 { |
| 4363 /* Setup a cookie that can be used by the browser */ |
4338 /* Setup a cookie that can be used by the browser */ |
| 4364 /* XXX I have no idea how this will work with Yahoo! Japan. */ |
|
| 4365 |
4339 |
| 4366 PurpleConnection *gc = action->connection; |
4340 PurpleConnection *gc = action->connection; |
| 4367 YahooData *yd = purple_connection_get_protocol_data(gc); |
4341 YahooData *yd = purple_connection_get_protocol_data(gc); |
| 4368 PurpleHttpRequest *req; |
4342 PurpleHttpRequest *req; |
| 4369 PurpleHttpCookieJar *cookiejar; |
4343 PurpleHttpCookieJar *cookiejar; |