/pidgin/main: 99e88f0702f1: HTTP: removing extra yahoo HTTP impl...
Tomasz Wasilczyk
tomkiewicz at cpw.pidgin.im
Fri Aug 9 08:55:47 EDT 2013
Changeset: 99e88f0702f1ab65e628c0188de379636b7b65a9
Author: Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date: 2013-08-09 14:55 +0200
Branch: default
URL: https://hg.pidgin.im/pidgin/main/rev/99e88f0702f1
Description:
HTTP: removing extra yahoo HTTP implementations - webmessenger login (however, it still doesn't work well)
diffstat:
libpurple/http.c | 4 -
libpurple/protocols/yahoo/libymsg.c | 275 ++++++++++++-----------------------
libpurple/protocols/yahoo/libymsg.h | 1 -
3 files changed, 99 insertions(+), 181 deletions(-)
diffs (truncated from 404 to 300 lines):
diff --git a/libpurple/http.c b/libpurple/http.c
--- a/libpurple/http.c
+++ b/libpurple/http.c
@@ -1004,10 +1004,6 @@ static gboolean _purple_http_recv_body_c
g_string_erase(hc->response_buffer, 0, got_now);
hc->in_chunk = (hc->chunk_got < hc->chunk_length);
- if (purple_debug_is_verbose())
- purple_debug_misc("http", "Chunk (%d/%d)\n",
- hc->chunk_got, hc->chunk_length);
-
continue;
}
diff --git a/libpurple/protocols/yahoo/libymsg.c b/libpurple/protocols/yahoo/libymsg.c
--- a/libpurple/protocols/yahoo/libymsg.c
+++ b/libpurple/protocols/yahoo/libymsg.c
@@ -54,8 +54,10 @@
/* #define YAHOO_DEBUG */
-/* Not tested with new HTTP API, because it doesn't compile at the moment. */
-/* #define TRY_WEBMESSENGER_LOGIN 0 */
+/* It doesn't looks like working (previously used host is down, another one
+ * doesn't sends us back cookies.
+ */
+#define TRY_WEBMESSENGER_LOGIN 0
/* One hour */
#define PING_TIMEOUT 3600
@@ -63,8 +65,10 @@
/* One minute */
#define KEEPALIVE_TIMEOUT 60
-#ifdef TRY_WEBMESSENGER_LOGIN
-static void yahoo_login_page_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, size_t len, const gchar *error_message);
+#if TRY_WEBMESSENGER_LOGIN
+static void
+yahoo_login_page_cb(PurpleHttpConnection *http_conn,
+ PurpleHttpResponse *response, gpointer _unused);
#endif /* TRY_WEBMESSENGER_LOGIN */
static gboolean yahoo_is_japan(PurpleAccount *account)
@@ -2142,11 +2146,38 @@ static void yahoo_process_ignore(PurpleC
}
}
+#if TRY_WEBMESSENGER_LOGIN
+
+static gboolean
+yahoo_try_webmessenger_login(PurpleConnection *gc)
+{
+ YahooData *yd = purple_connection_get_protocol_data(gc);
+ PurpleHttpRequest *req;
+
+ if (yd->wm)
+ return FALSE;
+
+ yd->wm = TRUE;
+ if (yd->fd >= 0)
+ close(yd->fd);
+ if (yd->inpa) {
+ purple_input_remove(yd->inpa);
+ yd->inpa = 0;
+ }
+
+ req = purple_http_request_new(WEBMESSENGER_URL);
+ purple_http_request_header_set(req, "User-Agent", "Purple/" VERSION);
+ purple_http_connection_set_add(yd->http_reqs, purple_http_request(gc,
+ req, yahoo_login_page_cb, NULL));
+ purple_http_request_unref(req);
+
+ return TRUE;
+}
+
+#endif /* TRY_WEBMESSENGER_LOGIN */
+
static void yahoo_process_authresp(PurpleConnection *gc, struct yahoo_packet *pkt)
{
-#ifdef TRY_WEBMESSENGER_LOGIN
- YahooData *yd = purple_connection_get_protocol_data(gc);
-#endif /* TRY_WEBMESSENGER_LOGIN */
GSList *l = pkt->hash;
int err = 0;
char *msg;
@@ -2176,24 +2207,11 @@ static void yahoo_process_authresp(Purpl
reason = PURPLE_CONNECTION_ERROR_INVALID_USERNAME;
break;
case 13:
-#ifdef TRY_WEBMESSENGER_LOGIN
- if (!yd->wm) {
- PurpleHttpRequest *req;
- PurpleHttpConnection *hc;
- yd->wm = TRUE;
- if (yd->fd >= 0)
- close(yd->fd);
- if (yd->inpa) {
- purple_input_remove(yd->inpa);
- yd->inpa = 0;
- }
- req = purple_http_request_new(WEBMESSENGER_URL);
- purple_http_request_header_set(req, "User-Agent", "Purple/" VERSION);
- hc = purple_http_request(gc, req, yahoo_login_page_cb, NULL);
- purple_http_request_unref(req);
- yd->http_reqs = g_slist_prepend(yd->http_reqs, hc);
+#if TRY_WEBMESSENGER_LOGIN
+ if (yahoo_try_webmessenger_login(gc))
return;
- }
+#else
+ purple_debug_info("yahoo", "Web messenger login is disabled\n");
#endif /* TRY_WEBMESSENGER_LOGIN */
if (!purple_account_get_remember_password(account))
purple_account_set_password(account, NULL, NULL, NULL);
@@ -3194,7 +3212,8 @@ static void yahoo_got_connected(gpointer
yd->inpa = purple_input_add(yd->fd, PURPLE_INPUT_READ, yahoo_pending, gc);
}
-#ifdef TRY_WEBMESSENGER_LOGIN
+#if TRY_WEBMESSENGER_LOGIN
+
static void yahoo_got_web_connected(gpointer data, gint source, const gchar *error_message)
{
PurpleConnection *gc = data;
@@ -3224,141 +3243,51 @@ static void yahoo_got_web_connected(gpoi
yd->inpa = purple_input_add(yd->fd, PURPLE_INPUT_READ, yahoo_pending, gc);
}
-static void yahoo_web_pending(gpointer data, gint source, PurpleInputCondition cond)
+static void
+yahoo_login_page_got(PurpleHttpConnection *hc, PurpleHttpResponse *resp,
+ gpointer _unused)
{
- PurpleConnection *gc = data;
+ PurpleConnection *gc = purple_http_conn_get_purple_connection(hc);
+ YahooData *yd = purple_connection_get_protocol_data(gc);
PurpleAccount *account = purple_connection_get_account(gc);
- YahooData *yd = purple_connection_get_protocol_data(gc);
- char bufread[2048], *i = bufread, *buf = bufread;
- int len;
- GString *s;
-
- len = read(source, bufread, sizeof(bufread) - 1);
-
- if (len < 0) {
- gchar *tmp;
-
- if (errno == EAGAIN)
- /* No worries */
- return;
-
- tmp = g_strdup_printf(_("Lost connection with server: %s"),
- g_strerror(errno));
- purple_connection_error(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp);
- g_free(tmp);
- return;
- } else if (len == 0) {
- purple_connection_error(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
- _("Server closed the connection"));
+ PurpleHttpCookieJar *cjar;
+ GString *auth_s;
+ const gchar *cookie;
+
+ if (purple_http_response_get_code(resp) != 302) {
+ purple_connection_error(gc,
+ PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
+ _("Unable to connect"));
return;
}
- if (yd->rxlen > 0 || !g_strstr_len(buf, len, "\r\n\r\n")) {
- yd->rxqueue = g_realloc(yd->rxqueue, yd->rxlen + len + 1);
- memcpy(yd->rxqueue + yd->rxlen, buf, len);
- yd->rxlen += len;
- i = buf = (char *)yd->rxqueue;
- len = yd->rxlen;
- }
- buf[len] = '\0';
-
- if ((strncmp(buf, "HTTP/1.0 302", strlen("HTTP/1.0 302")) &&
- strncmp(buf, "HTTP/1.1 302", strlen("HTTP/1.1 302")))) {
- purple_connection_error(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
- _("Received unexpected HTTP response from server"));
- purple_debug_misc("yahoo", "Unexpected HTTP response: %s\n", buf);
+ auth_s = g_string_new(NULL);
+ cjar = purple_http_conn_get_cookie_jar(hc);
+ cookie = purple_http_cookie_jar_get(cjar, "B");
+ if (cookie)
+ g_string_append_printf(auth_s, "B=%s; ", cookie);
+ cookie = purple_http_cookie_jar_get(cjar, "T");
+ if (cookie)
+ g_string_append_printf(auth_s, "T=%s; ", cookie);
+ cookie = purple_http_cookie_jar_get(cjar, "Y");
+ if (cookie)
+ g_string_append_printf(auth_s, "Y=%s; ", cookie);
+
+ yd->auth = g_string_free(auth_s, FALSE);
+ /* Now we have our cookies to login with. I'll go get the milk. */
+
+ /* XXX: wcs2.msg.dcn.yahoo.com is down, so I used
+ * YAHOO_PAGER_HOST_FALLBACK. But I'm not sure, if its correct host.
+ */
+ if (purple_proxy_connect(gc, account, YAHOO_PAGER_HOST_FALLBACK,
+ purple_account_get_int(account, "port", YAHOO_PAGER_PORT),
+ yahoo_got_web_connected, gc) == NULL)
+ {
+ purple_connection_error(gc,
+ PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
+ _("Unable to connect"));
return;
}
-
- s = g_string_sized_new(len);
-
- while ((i = strstr(i, "Set-Cookie: "))) {
-
- i += strlen("Set-Cookie: ");
- for (;*i != ';' && *i != '\0'; i++)
- g_string_append_c(s, *i);
-
- g_string_append(s, "; ");
- /* Should these cookies be included too when trying for xfer?
- * It seems to work without these
- */
- }
-
- yd->auth = g_string_free(s, FALSE);
- purple_input_remove(yd->inpa);
- yd->inpa = 0;
- close(source);
- g_free(yd->rxqueue);
- yd->rxqueue = NULL;
- yd->rxlen = 0;
- /* Now we have our cookies to login with. I'll go get the milk. */
- if (purple_proxy_connect(gc, account, "wcs2.msg.dcn.yahoo.com",
- purple_account_get_int(account, "port", YAHOO_PAGER_PORT),
- yahoo_got_web_connected, gc) == NULL) {
- purple_connection_error(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
- _("Unable to connect"));
- return;
- }
-}
-
-static void yahoo_got_cookies_send_cb(gpointer data, gint source, PurpleInputCondition cond)
-{
- PurpleConnection *gc = data;
- YahooData *yd = purple_connection_get_protocol_data(gc);
- int written, remaining;
-
- remaining = strlen(yd->auth) - yd->auth_written;
- written = write(source, yd->auth + yd->auth_written, remaining);
-
- if (written < 0 && errno == EAGAIN)
- written = 0;
- else if (written <= 0) {
- gchar *tmp;
- g_free(yd->auth);
- yd->auth = NULL;
- if (yd->inpa) {
- purple_input_remove(yd->inpa);
- yd->inpa = 0;
- }
- tmp = g_strdup_printf(_("Lost connection with %s: %s"),
- "login.yahoo.com:80", g_strerror(errno));
- purple_connection_error(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp);
- g_free(tmp);
- return;
- }
-
- if (written < remaining) {
- yd->auth_written += written;
- return;
- }
-
- g_free(yd->auth);
- yd->auth = NULL;
- yd->auth_written = 0;
- purple_input_remove(yd->inpa);
- yd->inpa = purple_input_add(source, PURPLE_INPUT_READ, yahoo_web_pending, gc);
-}
-
-static void yahoo_got_cookies(gpointer data, gint source, const gchar *error_message)
-{
- PurpleConnection *gc = data;
- YahooData *yd = purple_connection_get_protocol_data(gc);
-
- if (source < 0) {
- gchar *tmp;
- tmp = g_strdup_printf(_("Unable to establish a connection with %s: %s"),
- "login.yahoo.com:80", error_message);
- purple_connection_error(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp);
- g_free(tmp);
- return;
- }
-
- if (yd->inpa == 0)
- {
- yd->inpa = purple_input_add(source, PURPLE_INPUT_WRITE,
- yahoo_got_cookies_send_cb, gc);
- yahoo_got_cookies_send_cb(gc, source, PURPLE_INPUT_WRITE);
More information about the Commits
mailing list