pidgin.2.5.7: 2ce13aec: Backport the parts of b859960a4a19f57f20...

rekkanoryo at pidgin.im rekkanoryo at pidgin.im
Fri Jun 19 17:40:32 EDT 2009


-----------------------------------------------------------------
Revision: 2ce13aec38e3a91664d53ff050dc56c76ec6ff20
Ancestor: dae8e0225a1317c83d9be0e34f9ef97f65833e3b
Author: rekkanoryo at pidgin.im
Date: 2009-06-19T01:18:18
Branch: im.pidgin.pidgin.2.5.7
URL: http://d.pidgin.im/viewmtn/revision/info/2ce13aec38e3a91664d53ff050dc56c76ec6ff20

Modified files:
        libpurple/protocols/yahoo/yahoo.c
        libpurple/protocols/yahoo/yahoo.h
        libpurple/protocols/yahoo/yahoo_aliases.c
        libpurple/protocols/yahoo/yahoo_picture.c

ChangeLog: 

Backport the parts of b859960a4a19f57f20db0536c1815a6d79e08e36 that apply to
this branch, and also apply 162a734100aafd62b7338baa81b04510c6b66921.

-------------- next part --------------
============================================================
--- libpurple/protocols/yahoo/yahoo.c	4a1d22ed350b8052bef019689c96af77897b286a
+++ libpurple/protocols/yahoo/yahoo.c	af2b2e96c13f48c4e3f0242ea07e83156cce9325
@@ -1377,7 +1377,7 @@ static void to_y64(char *out, const unsi
 	*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);
@@ -1425,26 +1425,25 @@ static void yahoo_auth16_stage3(PurpleCo
 	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);
 		purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, error_message);
@@ -1453,26 +1452,30 @@ static void yahoo_auth16_stage2(PurpleUt
 		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:
@@ -1491,35 +1494,37 @@ static void yahoo_auth16_stage2(PurpleUt
 					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);
@@ -1529,25 +1534,27 @@ static void yahoo_auth16_stage1_cb(Purpl
 		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:
@@ -1557,7 +1564,7 @@ static void yahoo_auth16_stage1_cb(Purpl
 					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:
@@ -1567,7 +1574,7 @@ static void yahoo_auth16_stage1_cb(Purpl
 					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:
@@ -1577,24 +1584,26 @@ static void yahoo_auth16_stage1_cb(Purpl
 					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);
 		}
@@ -1610,10 +1619,10 @@ static void yahoo_auth16_stage1(PurpleCo
 	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;
 	}
 
@@ -1630,7 +1639,7 @@ static void yahoo_auth16_stage1(PurpleCo
 	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);
 }
 
@@ -3211,14 +3220,14 @@ static void yahoo_show_inbox(PurplePlugi
 	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);
============================================================
--- libpurple/protocols/yahoo/yahoo.h	f111e71b76816040a711839f084ca3ad19824fd5
+++ libpurple/protocols/yahoo/yahoo.h	32a28e5232bc07f5e4dbd3771e8f15dc56527c02
@@ -85,6 +85,8 @@
 #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
 
============================================================
--- libpurple/protocols/yahoo/yahoo_aliases.c	3998f5dd68caf66551db891e5f92b97f8946bbf9
+++ libpurple/protocols/yahoo/yahoo_aliases.c	8b6d4bbfa69c647fd56b71cc4fb3b0b4cdd60404
@@ -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,
 	}
 
 	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"
============================================================
--- libpurple/protocols/yahoo/yahoo_picture.c	0755d6f680f82bc049cc9d2fa6ad513304c497a6
+++ libpurple/protocols/yahoo/yahoo_picture.c	10e0b0fe51850bc90774dcbb4af730d95bf00d70
@@ -134,6 +134,7 @@ void yahoo_process_picture(PurpleConnect
 		data->gc = gc;
 		data->who = g_strdup(who);
 		data->checksum = checksum;
+		/* TODO: Does this need to be MSIE 5.0? */
 		url_data = purple_util_fetch_url(url, use_whole_url,
 				"Mozilla/4.0 (compatible; MSIE 5.0)", FALSE,
 				yahoo_fetch_picture_cb, data);
@@ -499,7 +500,7 @@ static void yahoo_buddy_icon_upload_conn
 	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"


More information about the Commits mailing list