summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Aurich <darkrain42@pidgin.im>2009-05-13 18:40:41 +0000
committerPaul Aurich <darkrain42@pidgin.im>2009-05-13 18:40:41 +0000
commitc07d1dd3be5196056c5ce2601a4437cff8ef7cd0 (patch)
tree65fbf6d45ee388bc7d2eaf85657defb39f2175e8
parentb3f1afef06d7f194619cee66985ee2bfc669e2c2 (diff)
downloadpidgin-c07d1dd3be5196056c5ce2601a4437cff8ef7cd0.tar.gz
Various minor cleanups. The majority of this is the #define for the useragent.
Also notable: Tighter scoping for variables and fewer magic numbers in the parsing of the server response.
-rw-r--r--libpurple/protocols/yahoo/yahoo.c115
-rw-r--r--libpurple/protocols/yahoo/yahoo.h2
-rw-r--r--libpurple/protocols/yahoo/yahoo_aliases.c4
-rw-r--r--libpurple/protocols/yahoo/yahoo_filexfer.c41
-rw-r--r--libpurple/protocols/yahoo/yahoo_picture.c4
5 files changed, 103 insertions, 63 deletions
diff --git a/libpurple/protocols/yahoo/yahoo.c b/libpurple/protocols/yahoo/yahoo.c
index c3df7ce100..0f056060f4 100644
--- a/libpurple/protocols/yahoo/yahoo.c
+++ b/libpurple/protocols/yahoo/yahoo.c
@@ -1564,7 +1564,7 @@ static void to_y64(char *out, const unsigned char *in, gsize inlen)
*out = '\0';
}
-static void yahoo_auth16_stage3(PurpleConnection *gc, char *crypt)
+static void yahoo_auth16_stage3(PurpleConnection *gc, const char *crypt)
{
struct yahoo_data *yd = gc->proto_data;
PurpleAccount *account = purple_connection_get_account(gc);
@@ -1612,25 +1612,24 @@ static void yahoo_auth16_stage3(PurpleConnection *gc, char *crypt)
yahoo_packet_send_and_free(pkt, yd);
purple_cipher_context_destroy(md5_ctx);
- g_free(crypt);
}
-static void yahoo_auth16_stage2(PurpleUtilFetchUrlData *url_data2, gpointer user_data, const gchar *ret_data, size_t len, const gchar *error_message)
+static void yahoo_auth16_stage2(PurpleUtilFetchUrlData *unused, gpointer user_data, const gchar *ret_data, size_t len, const gchar *error_message)
{
struct yahoo_auth_data *auth_data = user_data;
PurpleConnection *gc = auth_data->gc;
- struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
- gchar **split_data = NULL;
- int totalelements;
- int response_no;
- char *crumb = NULL;
- char *error_reason = NULL;
- char *crypt = NULL;
+ struct yahoo_data *yd;
gboolean try_login_on_error = FALSE;
purple_debug_info("yahoo","Authentication: In yahoo_auth16_stage2\n");
- g_return_if_fail(PURPLE_CONNECTION_IS_VALID(gc));
+ if (!PURPLE_CONNECTION_IS_VALID(gc)) {
+ g_free(auth_data->seed);
+ g_free(auth_data);
+ g_return_if_reached();
+ }
+
+ yd = (struct yahoo_data *)gc->proto_data;
if (error_message != NULL) {
purple_debug_error("yahoo", "Login Failed, unable to retrieve stage 2 url: %s\n", error_message);
@@ -1640,26 +1639,30 @@ static void yahoo_auth16_stage2(PurpleUtilFetchUrlData *url_data2, gpointer user
return;
}
else if (len > 0 && ret_data && *ret_data) {
- split_data = g_strsplit(ret_data, "\r\n", -1);
- totalelements = g_strv_length(split_data);
+ gchar **split_data = g_strsplit(ret_data, "\r\n", -1);
+ int totalelements = g_strv_length(split_data);
+ int response_no = -1;
+ char *crumb = NULL;
+ char *crypt = NULL;
+
if (totalelements >= 5) {
response_no = strtol(split_data[1], NULL, 10);
- crumb = g_strdup(split_data[2] + 6);
- yd->cookie_y = g_strdup(split_data[3] + 2);
- yd->cookie_t = g_strdup(split_data[4] + 2);
+ crumb = g_strdup(split_data[2] + strlen("crumb="));
+ yd->cookie_y = g_strdup(split_data[3] + strlen("Y="));
+ yd->cookie_t = g_strdup(split_data[4] + strlen("T="));
}
- else
- response_no = -1;
g_strfreev(split_data);
if(response_no != 0) {
/* Some error in the login process */
PurpleConnectionError error;
+ char *error_reason = NULL;
+
switch(response_no) {
case -1:
/* Some error in the received stream */
- error_reason = g_strdup(_("Error in the received data"));
+ error_reason = g_strdup(_("Received invalid data"));
error = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
break;
case 100:
@@ -1678,35 +1681,37 @@ static void yahoo_auth16_stage2(PurpleUtilFetchUrlData *url_data2, gpointer user
break;
}
if(error_reason) {
- purple_debug_error("yahoo","Authentication error: %s", error_reason);
+ purple_debug_error("yahoo", "Authentication error: %s\n",
+ error_reason);
purple_connection_error_reason(gc, error, error_reason);
g_free(error_reason);
+ g_free(auth_data->seed);
+ g_free(auth_data);
+ return;
}
}
- if((response_no == 0) || try_login_on_error) {
- crypt = g_strconcat(crumb, auth_data->seed, NULL);
- yahoo_auth16_stage3(gc, crypt);
- g_free(crumb);
- }
+
+ crypt = g_strconcat(crumb, auth_data->seed, NULL);
+ yahoo_auth16_stage3(gc, crypt);
+ g_free(crypt);
+ g_free(crumb);
}
g_free(auth_data->seed);
g_free(auth_data);
}
-static void yahoo_auth16_stage1_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *ret_data, size_t len, const gchar *error_message)
+static void yahoo_auth16_stage1_cb(PurpleUtilFetchUrlData *unused, gpointer user_data, const gchar *ret_data, size_t len, const gchar *error_message)
{
struct yahoo_auth_data *auth_data = user_data;
PurpleConnection *gc = auth_data->gc;
- gchar **split_data = NULL;
- int response_no;
- int totalelements;
- char *error_reason = NULL;
- PurpleUtilFetchUrlData *url_data2 = NULL;
- char *token = NULL;
purple_debug_info("yahoo","Authentication: In yahoo_auth16_stage1_cb\n");
- g_return_if_fail(PURPLE_CONNECTION_IS_VALID(gc));
+ if (!PURPLE_CONNECTION_IS_VALID(gc)) {
+ g_free(auth_data->seed);
+ g_free(auth_data);
+ g_return_if_reached();
+ }
if (error_message != NULL) {
purple_debug_error("yahoo", "Login Failed, unable to retrieve login url: %s\n", error_message);
@@ -1716,25 +1721,27 @@ static void yahoo_auth16_stage1_cb(PurpleUtilFetchUrlData *url_data, gpointer us
return;
}
else if (len > 0 && ret_data && *ret_data) {
- split_data = g_strsplit(ret_data, "\r\n", -1);
- totalelements = g_strv_length(split_data);
-
+ gchar **split_data = g_strsplit(ret_data, "\r\n", -1);
+ int totalelements = g_strv_length(split_data);
+ int response_no = -1;
+ char *token = NULL;
+
if(totalelements >= 5) {
response_no = strtol(split_data[1], NULL, 10);
- token = g_strdup(split_data[2] + 6);
+ token = g_strdup(split_data[2] + strlen("ymsgr="));
}
- else
- response_no = -1;
g_strfreev(split_data);
if(response_no != 0) {
/* Some error in the login process */
PurpleConnectionError error;
+ char *error_reason;
+
switch(response_no) {
case -1:
/* Some error in the received stream */
- error_reason = g_strdup(_("Error in the received data"));
+ error_reason = g_strdup(_("Received invalid data"));
error = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
break;
case 1212:
@@ -1744,7 +1751,7 @@ static void yahoo_auth16_stage1_cb(PurpleUtilFetchUrlData *url_data, gpointer us
break;
case 1213:
/* security lock from too many failed login attempts */
- error_reason = g_strdup(_("Login locked: Too many failed login attempts"));
+ error_reason = g_strdup(_("Account locked: Too many failed login attempts"));
error = PURPLE_CONNECTION_ERROR_OTHER_ERROR;
break;
case 1235:
@@ -1754,7 +1761,7 @@ static void yahoo_auth16_stage1_cb(PurpleUtilFetchUrlData *url_data, gpointer us
break;
case 1236:
/* indicates a lock of some description */
- error_reason = g_strdup(_("Login locked: See the debug log"));
+ error_reason = g_strdup(_("Account locked: See the debug log"));
error = PURPLE_CONNECTION_ERROR_OTHER_ERROR;
break;
case 100:
@@ -1764,24 +1771,26 @@ static void yahoo_auth16_stage1_cb(PurpleUtilFetchUrlData *url_data, gpointer us
break;
default:
/* Unknown error! */
- error_reason = g_strdup(_("Unkown error"));
+ error_reason = g_strdup(_("Unknown error"));
error = PURPLE_CONNECTION_ERROR_OTHER_ERROR;
break;
}
- purple_debug_error("yahoo","Authentication error: %s", error_reason);
+ purple_debug_error("yahoo", "Authentication error: %s\n",
+ error_reason);
purple_connection_error_reason(gc, error, error_reason);
g_free(error_reason);
g_free(auth_data->seed);
g_free(auth_data);
}
- else {
+ else {
/* OK to login, correct information provided */
+ PurpleUtilFetchUrlData *url_data = NULL;
char *url = NULL;
gboolean yahoojp = purple_account_get_bool(purple_connection_get_account(gc),
"yahoojp", 0);
url = g_strdup_printf(yahoojp ? YAHOOJP_LOGIN_URL : YAHOO_LOGIN_URL, token);
- url_data2 = purple_util_fetch_url_request(url, TRUE, "Mozilla/4.0 (compatible; MSIE 5.5)", TRUE, NULL, FALSE, yahoo_auth16_stage2, auth_data);
+ url_data = purple_util_fetch_url_request(url, TRUE, YAHOO_CLIENT_USERAGENT, TRUE, NULL, FALSE, yahoo_auth16_stage2, auth_data);
g_free(url);
g_free(token);
}
@@ -1797,10 +1806,10 @@ static void yahoo_auth16_stage1(PurpleConnection *gc, const char *seed)
char *encoded_password;
gboolean yahoojp;
- purple_debug_info("yahoo","Authentication: In yahoo_auth16_stage1\n");
+ purple_debug_info("yahoo", "Authentication: In yahoo_auth16_stage1\n");
if(!purple_ssl_is_supported()) {
- purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT, _("Server requires TLS/SSL for login. No TLS/SSL support found."));
+ purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT, _("SSL support unavailable"));
return;
}
@@ -1817,7 +1826,7 @@ static void yahoo_auth16_stage1(PurpleConnection *gc, const char *seed)
g_free(encoded_password);
g_free(encoded_username);
- 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);
+ url_data = purple_util_fetch_url_request(url, TRUE, YAHOO_CLIENT_USERAGENT, TRUE, NULL, FALSE, yahoo_auth16_stage1_cb, auth_data);
g_free(url);
}
@@ -3933,14 +3942,14 @@ static void yahoo_show_inbox(PurplePluginAction *action)
gchar *request = g_strdup_printf(
"POST %s/config/cookie_token HTTP/1.0\r\n"
"Cookie: T=%s; path=/; domain=.yahoo.com; Y=%s;\r\n"
- "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5)\r\n"
+ "User-Agent: " YAHOO_CLIENT_USERAGENT "\r\n"
"Host: login.yahoo.com\r\n"
"Content-Length: 0\r\n\r\n",
use_whole_url ? base_url : "",
yd->cookie_t, yd->cookie_y);
url_data = purple_util_fetch_url_request(base_url, use_whole_url,
- "Mozilla/4.0 (compatible; MSIE 5.5)", TRUE, request, FALSE,
+ YAHOO_CLIENT_USERAGENT, TRUE, request, FALSE,
yahoo_get_inbox_token_cb, gc);
g_free(request);
@@ -4091,7 +4100,7 @@ static void yahoo_get_sms_carrier(PurpleConnection *gc, gpointer data)
request = g_strdup_printf(
"POST /mobileno?intl=us&version=%s HTTP/1.1\r\n"
"Cookie: T=%s; path=/; domain=.yahoo.com; Y=%s; path=/; domain=.yahoo.com;\r\n"
- "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5)\r\n"
+ "User-Agent: " YAHOO_CLIENT_USERAGENT "\r\n"
"Host: validate.msg.yahoo.com\r\n"
"Content-Length: %" G_GSIZE_FORMAT "\r\n"
"Cache-Control: no-cache\r\n\r\n%s",
@@ -4102,7 +4111,7 @@ static void yahoo_get_sms_carrier(PurpleConnection *gc, gpointer data)
use_whole_url = TRUE;
url_data = purple_util_fetch_url_request(YAHOO_SMS_CARRIER_URL, use_whole_url,
- "Mozilla/4.0 (compatible; MSIE 5.5)", TRUE, request, FALSE,
+ YAHOO_CLIENT_USERAGENT, TRUE, request, FALSE,
yahoo_get_sms_carrier_cb, data);
g_free(request);
diff --git a/libpurple/protocols/yahoo/yahoo.h b/libpurple/protocols/yahoo/yahoo.h
index 52de686617..446819d280 100644
--- a/libpurple/protocols/yahoo/yahoo.h
+++ b/libpurple/protocols/yahoo/yahoo.h
@@ -89,6 +89,8 @@
#define YAHOOJP_CLIENT_VERSION_ID "4194239"
#define YAHOOJP_CLIENT_VERSION "9.0.0.2152"
+#define YAHOO_CLIENT_USERAGENT "Mozilla/4.0 (compatible; MSIE 5.5)"
+
/* Index into attention types list. */
#define YAHOO_BUZZ 0
diff --git a/libpurple/protocols/yahoo/yahoo_aliases.c b/libpurple/protocols/yahoo/yahoo_aliases.c
index 927e69120b..47b2ea78fb 100644
--- a/libpurple/protocols/yahoo/yahoo_aliases.c
+++ b/libpurple/protocols/yahoo/yahoo_aliases.c
@@ -166,7 +166,7 @@ yahoo_fetch_aliases(PurpleConnection *gc)
url = yd->jp ? YAHOOJP_ALIAS_FETCH_URL : YAHOO_ALIAS_FETCH_URL;
purple_url_parse(url, &webaddress, NULL, &webpage, NULL, NULL);
request = g_strdup_printf("GET %s%s/%s HTTP/1.1\r\n"
- "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5)\r\n"
+ "User-Agent: " YAHOO_CLIENT_USERAGENT "\r\n"
"Cookie: T=%s; Y=%s\r\n"
"Host: %s\r\n"
"Cache-Control: no-cache\r\n\r\n",
@@ -334,7 +334,7 @@ yahoo_update_alias(PurpleConnection *gc, const char *who, const char *alias)
}
request = g_strdup_printf("POST %s%s/%s HTTP/1.1\r\n"
- "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5)\r\n"
+ "User-Agent: " YAHOO_CLIENT_USERAGENT "\r\n"
"Cookie: T=%s; Y=%s\r\n"
"Host: %s\r\n"
"Content-Length: %" G_GSIZE_FORMAT "\r\n"
diff --git a/libpurple/protocols/yahoo/yahoo_filexfer.c b/libpurple/protocols/yahoo/yahoo_filexfer.c
index fff238f48a..4db626b80d 100644
--- a/libpurple/protocols/yahoo/yahoo_filexfer.c
+++ b/libpurple/protocols/yahoo/yahoo_filexfer.c
@@ -1249,7 +1249,11 @@ static void yahoo_xfer_connected_15(gpointer data, gint source, const gchar *err
if(xd->info_val_249 == 2)
{
/* sending file via p2p, we are connected as client */
- xd->txbuf = g_strdup_printf("POST /%s HTTP/1.1\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 5.5)\r\nHost: %s\r\nContent-Length: %ld\r\nCache-Control: no-cache\r\n\r\n",
+ xd->txbuf = g_strdup_printf("POST /%s HTTP/1.1\r\n"
+ "User-Agent: " YAHOO_CLIENT_USERAGENT "\r\n"
+ "Host: %s\r\n"
+ "Content-Length: %ld\r\n"
+ "Cache-Control: no-cache\r\n\r\n",
xd->path,
xd->host,
(long int)xfer->size); /* to do, add Referer */
@@ -1257,7 +1261,12 @@ static void yahoo_xfer_connected_15(gpointer data, gint source, const gchar *err
else
{
/* sending file via relaying */
- xd->txbuf = g_strdup_printf("POST /relay?token=%s&sender=%s&recver=%s HTTP/1.1\r\nCookie:%s\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 5.5)\r\nHost: %s\r\nContent-Length: %ld\r\nCache-Control: no-cache\r\n\r\n",
+ xd->txbuf = g_strdup_printf("POST /relay?token=%s&sender=%s&recver=%s HTTP/1.1\r\n"
+ "Cookie:%s\r\n"
+ "User-Agent: " YAHOO_CLIENT_USERAGENT "\r\n"
+ "Host: %s\r\n"
+ "Content-Length: %ld\r\n"
+ "Cache-Control: no-cache\r\n\r\n",
purple_url_encode(xd->xfer_idstring_for_relay),
purple_normalize(account, purple_account_get_username(account)),
xfer->who,
@@ -1271,12 +1280,24 @@ static void yahoo_xfer_connected_15(gpointer data, gint source, const gchar *err
if(xd->info_val_249 == 1)
{
/* receiving file via p2p, connected as client */
- xd->txbuf = g_strdup_printf("HEAD /%s HTTP/1.1\r\nAccept:*/*\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 5.5)\r\nHost: %s\r\nContent-Length: 0\r\nCache-Control: no-cache\r\n\r\n",xd->path,xd->host);
+ xd->txbuf = g_strdup_printf("HEAD /%s HTTP/1.1\r\n"
+ "Accept: */*\r\n"
+ "User-Agent: " YAHOO_CLIENT_USERAGENT "\r\n"
+ "Host: %s\r\n"
+ "Content-Length: 0\r\n"
+ "Cache-Control: no-cache\r\n\r\n",
+ xd->path,xd->host);
}
else
{
/* receiving file via relaying */
- xd->txbuf = g_strdup_printf("HEAD /relay?token=%s&sender=%s&recver=%s HTTP/1.1\r\nAccept:*/*\r\nCookie:%s\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 5.5)\r\nHost:%s\r\nContent-Length: 0\r\nCache-Control: no-cache\r\n\r\n",
+ xd->txbuf = g_strdup_printf("HEAD /relay?token=%s&sender=%s&recver=%s HTTP/1.1\r\n"
+ "Accept: */*\r\n"
+ "Cookie: %s\r\n"
+ "User-Agent: " YAHOO_CLIENT_USERAGENT "\r\n"
+ "Host: %s\r\n"
+ "Content-Length: 0\r\n"
+ "Cache-Control: no-cache\r\n\r\n",
purple_url_encode(xd->xfer_idstring_for_relay),
purple_normalize(account, purple_account_get_username(account)),
xfer->who,
@@ -1289,12 +1310,20 @@ static void yahoo_xfer_connected_15(gpointer data, gint source, const gchar *err
if(xd->info_val_249 == 1)
{
/* receiving file via p2p, connected as client */
- xd->txbuf = g_strdup_printf("GET /%s HTTP/1.1\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 5.5)\r\nHost: %s\r\nConnection: Keep-Alive\r\n\r\n",xd->path,xd->host);
+ xd->txbuf = g_strdup_printf("GET /%s HTTP/1.1\r\n"
+ "User-Agent: " YAHOO_CLIENT_USERAGENT "\r\n"
+ "Host: %s\r\n"
+ "Connection: Keep-Alive\r\n\r\n",
+ xd->path, xd->host);
}
else
{
/* receiving file via relaying */
- xd->txbuf = g_strdup_printf("GET /relay?token=%s&sender=%s&recver=%s HTTP/1.1\r\nCookie:%s\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 5.5)\r\nHost:%s\r\nConnection: Keep-Alive\r\n\r\n",
+ xd->txbuf = g_strdup_printf("GET /relay?token=%s&sender=%s&recver=%s HTTP/1.1\r\n"
+ "Cookie: %s\r\n"
+ "User-Agent: " YAHOO_CLIENT_USERAGENT "\r\n"
+ "Host: %s\r\n"
+ "Connection: Keep-Alive\r\n\r\n",
purple_url_encode(xd->xfer_idstring_for_relay),
purple_normalize(account, purple_account_get_username(account)),
xfer->who,
diff --git a/libpurple/protocols/yahoo/yahoo_picture.c b/libpurple/protocols/yahoo/yahoo_picture.c
index 0f006fa442..cd1d97a5e2 100644
--- a/libpurple/protocols/yahoo/yahoo_picture.c
+++ b/libpurple/protocols/yahoo/yahoo_picture.c
@@ -135,7 +135,7 @@ void yahoo_process_picture(PurpleConnection *gc, struct yahoo_packet *pkt)
data->who = g_strdup(who);
data->checksum = checksum;
url_data = purple_util_fetch_url(url, use_whole_url,
- "Mozilla/4.0 (compatible; MSIE 5.0)", FALSE,
+ YAHOO_CLIENT_USERAGENT, FALSE,
yahoo_fetch_picture_cb, data);
if (url_data != NULL) {
yd = gc->proto_data;
@@ -499,7 +499,7 @@ static void yahoo_buddy_icon_upload_connected(gpointer data, gint source, const
port = purple_account_get_int(account, "xfer_port", YAHOO_XFER_PORT);
tmp = g_strdup_printf("%s:%d", host, port);
header = g_strdup_printf("POST %s%s/notifyft HTTP/1.1\r\n"
- "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5)\r\n"
+ "User-Agent: " YAHOO_CLIENT_USERAGENT "\r\n"
"Cookie: T=%s; Y=%s\r\n"
"Host: %s\r\n"
"Content-Length: %" G_GSIZE_FORMAT "\r\n"