changeset 31085:4297feb30ad1

Merged everything related to ICQ server changes. applied changes from b6d7712e90b68610df3bd2d8cbaf46d94c8b3794 through d849dc2a852a4ffdd345a150f0b88ab37de36e36 applied changes from 7aedaac3ed815cab16d758474a829d5ec5a59e4b through d849dc2a852a4ffdd345a150f0b88ab37de36e36
author ivan.komarov@soc.pidgin.im
date Sat, 30 Oct 2010 21:36:34 +0000
parents a61147460879
children 1558900f47e5
files libpurple/protocols/oscar/clientlogin.c libpurple/protocols/oscar/libaim.c libpurple/protocols/oscar/libicq.c libpurple/protocols/oscar/oscar.c libpurple/protocols/oscar/oscarcommon.h libpurple/protocols/oscar/peer.c libpurple/protocols/oscar/peer.h
diffstat 7 files changed, 95 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/oscar/clientlogin.c	Sat Oct 30 21:27:00 2010 +0000
+++ b/libpurple/protocols/oscar/clientlogin.c	Sat Oct 30 21:36:34 2010 +0000
@@ -42,8 +42,36 @@
 #include "cipher.h"
 #include "core.h"
 
-#define URL_CLIENT_LOGIN "https://api.screenname.aol.com/auth/clientLogin"
-#define URL_START_OSCAR_SESSION "https://api.oscar.aol.com/aim/startOSCARSession"
+#define AIM_LOGIN_HOST "api.screenname.aol.com"
+#define ICQ_LOGIN_HOST "api.login.icq.net"
+
+#define AIM_API_HOST "api.oscar.aol.com"
+#define ICQ_API_HOST "api.icq.net"
+
+#define CLIENT_LOGIN_PAGE "/auth/clientLogin"
+#define START_OSCAR_SESSION_PAGE "/aim/startOSCARSession"
+
+#define HTTPS_FORMAT_URL(host, page) "https://" host page
+
+static const gchar *client_login_urls[] = {
+	HTTPS_FORMAT_URL(AIM_LOGIN_HOST, CLIENT_LOGIN_PAGE),
+	HTTPS_FORMAT_URL(ICQ_LOGIN_HOST, CLIENT_LOGIN_PAGE),
+};
+
+static const gchar *start_oscar_session_urls[] = {
+	HTTPS_FORMAT_URL(AIM_API_HOST, START_OSCAR_SESSION_PAGE),
+	HTTPS_FORMAT_URL(ICQ_API_HOST, START_OSCAR_SESSION_PAGE),
+};
+
+static const gchar *get_client_login_url(OscarData *od)
+{
+	return client_login_urls[od->icq];
+}
+
+static const gchar *get_start_oscar_session_url(OscarData *od)
+{
+	return start_oscar_session_urls[od->icq];
+}
 
 /*
  * Using clientLogin requires a developer ID.  This key is for libpurple.
@@ -125,6 +153,7 @@
 
 static gboolean parse_start_oscar_session_response(PurpleConnection *gc, const gchar *response, gsize response_len, char **host, unsigned short *port, char **cookie, char **tls_certname)
 {
+	OscarData *od = purple_connection_get_protocol_data(gc);
 	xmlnode *response_node, *tmp_node, *data_node;
 	xmlnode *host_node = NULL, *port_node = NULL, *cookie_node = NULL, *tls_node = NULL;
 	gboolean use_tls;
@@ -142,7 +171,7 @@
 				"response as XML: %s\n", response);
 		/* Note to translators: %s in this string is a URL */
 		msg = generate_error_message(response_node,
-				URL_START_OSCAR_SESSION);
+				get_start_oscar_session_url(od));
 		purple_connection_error_reason(gc,
 				PURPLE_CONNECTION_ERROR_NETWORK_ERROR, msg);
 		g_free(msg);
@@ -165,7 +194,7 @@
 		purple_debug_error("oscar", "startOSCARSession response was "
 				"missing statusCode: %s\n", response);
 		msg = generate_error_message(response_node,
-				URL_START_OSCAR_SESSION);
+				get_start_oscar_session_url(od));
 		purple_connection_error_reason(gc,
 				PURPLE_CONNECTION_ERROR_NETWORK_ERROR, msg);
 		g_free(msg);
@@ -203,7 +232,7 @@
 		else {
 			char *msg;
 			msg = generate_error_message(response_node,
-					URL_START_OSCAR_SESSION);
+					get_start_oscar_session_url(od));
 			purple_connection_error_reason(gc,
 					PURPLE_CONNECTION_ERROR_OTHER_ERROR, msg);
 			g_free(msg);
@@ -216,15 +245,13 @@
 	g_free(tmp);
 
 	/* Make sure we have everything else */
-	if (data_node == NULL || host_node == NULL ||
-		port_node == NULL || cookie_node == NULL ||
-		(use_tls && tls_node == NULL))
+	if (data_node == NULL || host_node == NULL || port_node == NULL || cookie_node == NULL)
 	{
 		char *msg;
 		purple_debug_error("oscar", "startOSCARSession response was missing "
 				"something: %s\n", response);
 		msg = generate_error_message(response_node,
-				URL_START_OSCAR_SESSION);
+				get_start_oscar_session_url(od));
 		purple_connection_error_reason(gc,
 				PURPLE_CONNECTION_ERROR_NETWORK_ERROR, msg);
 		g_free(msg);
@@ -237,17 +264,21 @@
 	tmp = xmlnode_get_data_unescaped(port_node);
 	*cookie = xmlnode_get_data_unescaped(cookie_node);
 
-	if (use_tls)
-		*tls_certname = xmlnode_get_data_unescaped(tls_node);
+	if (use_tls) {
+		if (tls_node != NULL) {
+			*tls_certname = xmlnode_get_data_unescaped(tls_node);
+		} else {
+			purple_debug_warning("oscar", "useTls was 1, but we haven't received a tlsCertName to use. We will not do SSL to BOS.\n");
+		}
+	}
 
-	if (*host == NULL || **host == '\0' || tmp == NULL || *tmp == '\0' || *cookie == NULL || **cookie == '\0' ||
-			(use_tls && (*tls_certname == NULL || **tls_certname == '\0')))
+	if (*host == NULL || **host == '\0' || tmp == NULL || *tmp == '\0' || *cookie == NULL || **cookie == '\0')
 	{
 		char *msg;
 		purple_debug_error("oscar", "startOSCARSession response was missing "
 				"something: %s\n", response);
 		msg = generate_error_message(response_node,
-				URL_START_OSCAR_SESSION);
+				get_start_oscar_session_url(od));
 		purple_connection_error_reason(gc,
 				PURPLE_CONNECTION_ERROR_NETWORK_ERROR, msg);
 		g_free(msg);
@@ -284,7 +315,7 @@
 		/* Note to translators: The first %s is a URL, the second is an
 		   error message. */
 		tmp = g_strdup_printf(_("Error requesting %s: %s"),
-				URL_START_OSCAR_SESSION, error_message);
+				get_start_oscar_session_url(od), error_message);
 		purple_connection_error_reason(gc,
 				PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp);
 		g_free(tmp);
@@ -326,9 +357,9 @@
 			oscar_get_ui_info_int(od->icq ? "prpl-icq-distid"
 					: "prpl-aim-distid", 0x00000611),
 			get_client_key(od), hosttime, use_tls);
-	signature = generate_signature("GET", URL_START_OSCAR_SESSION,
+	signature = generate_signature("GET", get_start_oscar_session_url(od),
 			query_string, session_key);
-	url = g_strdup_printf(URL_START_OSCAR_SESSION "?%s&sig_sha256=%s",
+	url = g_strdup_printf("%s?%s&sig_sha256=%s", get_start_oscar_session_url(od),
 			query_string, signature);
 	g_free(query_string);
 	g_free(signature);
@@ -367,6 +398,7 @@
  */
 static gboolean parse_client_login_response(PurpleConnection *gc, const gchar *response, gsize response_len, char **token, char **secret, time_t *hosttime)
 {
+	OscarData *od = purple_connection_get_protocol_data(gc);
 	xmlnode *response_node, *tmp_node, *data_node;
 	xmlnode *secret_node = NULL, *hosttime_node = NULL, *token_node = NULL, *tokena_node = NULL;
 	char *tmp;
@@ -379,7 +411,7 @@
 		purple_debug_error("oscar", "clientLogin could not parse "
 				"response as XML: %s\n", response);
 		msg = generate_error_message(response_node,
-				URL_CLIENT_LOGIN);
+				get_client_login_url(od));
 		purple_connection_error_reason(gc,
 				PURPLE_CONNECTION_ERROR_NETWORK_ERROR, msg);
 		g_free(msg);
@@ -403,7 +435,7 @@
 		purple_debug_error("oscar", "clientLogin response was "
 				"missing statusCode: %s\n", response);
 		msg = generate_error_message(response_node,
-				URL_CLIENT_LOGIN);
+				get_client_login_url(od));
 		purple_connection_error_reason(gc,
 				PURPLE_CONNECTION_ERROR_NETWORK_ERROR, msg);
 		g_free(msg);
@@ -446,7 +478,7 @@
 		} else {
 			char *msg;
 			msg = generate_error_message(response_node,
-					URL_CLIENT_LOGIN);
+					get_client_login_url(od));
 			purple_connection_error_reason(gc,
 					PURPLE_CONNECTION_ERROR_OTHER_ERROR, msg);
 			g_free(msg);
@@ -465,7 +497,7 @@
 		purple_debug_error("oscar", "clientLogin response was missing "
 				"something: %s\n", response);
 		msg = generate_error_message(response_node,
-				URL_CLIENT_LOGIN);
+				get_client_login_url(od));
 		purple_connection_error_reason(gc,
 				PURPLE_CONNECTION_ERROR_NETWORK_ERROR, msg);
 		g_free(msg);
@@ -483,7 +515,7 @@
 		purple_debug_error("oscar", "clientLogin response was missing "
 				"something: %s\n", response);
 		msg = generate_error_message(response_node,
-				URL_CLIENT_LOGIN);
+				get_client_login_url(od));
 		purple_connection_error_reason(gc,
 				PURPLE_CONNECTION_ERROR_NETWORK_ERROR, msg);
 		g_free(msg);
@@ -520,10 +552,10 @@
 		gchar *tmp;
 		if (error_message != NULL)
 			tmp = g_strdup_printf(_("Error requesting %s: %s"),
-					URL_CLIENT_LOGIN, error_message);
+					get_client_login_url(od), error_message);
 		else
 			tmp = g_strdup_printf(_("Error requesting %s"),
-					URL_CLIENT_LOGIN);
+					get_client_login_url(od));
 		purple_connection_error_reason(gc,
 				PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp);
 		g_free(tmp);
@@ -599,7 +631,7 @@
 
 	/* Send the POST request  */
 	od->url_data = purple_util_fetch_url_request_len_with_account(
-			purple_connection_get_account(gc), URL_CLIENT_LOGIN,
+			purple_connection_get_account(gc), get_client_login_url(od),
 			TRUE, NULL, FALSE, request->str, FALSE, -1,
 			client_login_cb, od);
 	g_string_free(request, TRUE);
--- a/libpurple/protocols/oscar/libaim.c	Sat Oct 30 21:27:00 2010 +0000
+++ b/libpurple/protocols/oscar/libaim.c	Sat Oct 30 21:36:34 2010 +0000
@@ -143,7 +143,7 @@
 static void
 init_plugin(PurplePlugin *plugin)
 {
-	oscar_init(plugin);
+	oscar_init(plugin, FALSE);
 }
 
 PURPLE_INIT_PLUGIN(aim, init_plugin, info);
--- a/libpurple/protocols/oscar/libicq.c	Sat Oct 30 21:27:00 2010 +0000
+++ b/libpurple/protocols/oscar/libicq.c	Sat Oct 30 21:36:34 2010 +0000
@@ -155,7 +155,7 @@
 {
 	PurpleAccountOption *option;
 
-	oscar_init(plugin);
+	oscar_init(plugin, TRUE);
 
 	option = purple_account_option_string_new(_("Encoding"), "encoding", OSCAR_DEFAULT_CUSTOM_ENCODING);
 	prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
--- a/libpurple/protocols/oscar/oscar.c	Sat Oct 30 21:27:00 2010 +0000
+++ b/libpurple/protocols/oscar/oscar.c	Sat Oct 30 21:36:34 2010 +0000
@@ -612,6 +612,18 @@
 		aim_ssi_setpresence(od, presence | AIM_SSI_PRESENCE_FLAG_NORECENTBUDDIES);
 }
 
+static const gchar *login_servers[] = {
+	AIM_DEFAULT_LOGIN_SERVER,
+	AIM_DEFAULT_SSL_LOGIN_SERVER,
+	ICQ_DEFAULT_LOGIN_SERVER,
+	ICQ_DEFAULT_SSL_LOGIN_SERVER,
+};
+
+static const gchar *get_login_server(gboolean is_icq, gboolean use_ssl)
+{
+	return login_servers[is_icq*2 + use_ssl];
+}
+
 void
 oscar_login(PurpleAccount *account)
 {
@@ -725,7 +737,7 @@
 				return;
 			}
 
-			server = purple_account_get_string(account, "server", OSCAR_DEFAULT_SSL_LOGIN_SERVER);
+			server = purple_account_get_string(account, "server", get_login_server(od->icq, TRUE));
 
 			/*
 			 * If the account's server is what the oscar prpl has offered as
@@ -734,27 +746,27 @@
 			 * do what we know is best for them and change the setting out
 			 * from under them to the SSL login server.
 			 */
-			if (!strcmp(server, OSCAR_DEFAULT_LOGIN_SERVER) || !strcmp(server, OSCAR_OLD_LOGIN_SERVER)) {
+			if (!strcmp(server, get_login_server(od->icq, FALSE))) {
 				purple_debug_info("oscar", "Account uses SSL, so changing server to default SSL server\n");
-				purple_account_set_string(account, "server", OSCAR_DEFAULT_SSL_LOGIN_SERVER);
-				server = OSCAR_DEFAULT_SSL_LOGIN_SERVER;
+				purple_account_set_string(account, "server", get_login_server(od->icq, TRUE));
+				server = get_login_server(od->icq, TRUE);
 			}
 
 			newconn->gsc = purple_ssl_connect(account, server,
 					purple_account_get_int(account, "port", OSCAR_DEFAULT_LOGIN_PORT),
 					ssl_connection_established_cb, ssl_connection_error_cb, newconn);
 		} else {
-			server = purple_account_get_string(account, "server", OSCAR_DEFAULT_LOGIN_SERVER);
+			server = purple_account_get_string(account, "server", get_login_server(od->icq, FALSE));
 
 			/*
 			 * See the comment above. We do the reverse here. If they don't want
 			 * SSL but their server is set to OSCAR_DEFAULT_SSL_LOGIN_SERVER,
 			 * set it back to the default.
 			 */
-			if (!strcmp(server, OSCAR_DEFAULT_SSL_LOGIN_SERVER)) {
+			if (!strcmp(server, get_login_server(od->icq, TRUE))) {
 				purple_debug_info("oscar", "Account does not use SSL, so changing server back to non-SSL\n");
-				purple_account_set_string(account, "server", OSCAR_DEFAULT_LOGIN_SERVER);
-				server = OSCAR_DEFAULT_LOGIN_SERVER;
+				purple_account_set_string(account, "server", get_login_server(od->icq, FALSE));
+				server = get_login_server(od->icq, FALSE);
 			}
 
 			newconn->connect_data = purple_proxy_connect(NULL, account, server,
@@ -969,8 +981,8 @@
 	conn->cookie = g_memdup(cookie, cookielen);
 
 	/*
-	 * tls_certname is only set (and must be set if we get this far) if
-	 * SSL is enabled.
+	 * Use SSL only if the server provided us with a tls_certname. The server might not specify a tls_certname even if we requested to use TLS, 
+	 * and that is something we should be prepared to.
 	 */
 	if (tls_certname)
 	{
@@ -5666,13 +5678,13 @@
 	return FALSE;
 }
 
-void oscar_init(PurplePlugin *plugin)
+void oscar_init(PurplePlugin *plugin, gboolean is_icq)
 {
 	PurplePluginProtocolInfo *prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin);
 	PurpleAccountOption *option;
 	static gboolean init = FALSE;
 
-	option = purple_account_option_string_new(_("Server"), "server", OSCAR_DEFAULT_LOGIN_SERVER);
+	option = purple_account_option_string_new(_("Server"), "server", get_login_server(is_icq, FALSE));
 	prpl_info->protocol_options = g_list_append(prpl_info->protocol_options, option);
 
 	option = purple_account_option_int_new(_("Port"), "port", OSCAR_DEFAULT_LOGIN_PORT);
--- a/libpurple/protocols/oscar/oscarcommon.h	Sat Oct 30 21:27:00 2010 +0000
+++ b/libpurple/protocols/oscar/oscarcommon.h	Sat Oct 30 21:36:34 2010 +0000
@@ -32,10 +32,13 @@
 #include "notify.h"
 #include "status.h"
 
-#define OSCAR_DEFAULT_LOGIN_SERVER "login.messaging.aol.com"
+#define AIM_DEFAULT_LOGIN_SERVER "login.oscar.aol.com"
+#define AIM_DEFAULT_SSL_LOGIN_SERVER "slogin.oscar.aol.com"
+#define ICQ_DEFAULT_LOGIN_SERVER "login.icq.com"
+#define ICQ_DEFAULT_SSL_LOGIN_SERVER "slogin.icq.com"
+
 #define OSCAR_DEFAULT_LOGIN_PORT 5190
-#define OSCAR_DEFAULT_SSL_LOGIN_SERVER "slogin.oscar.aol.com"
-#define OSCAR_OLD_LOGIN_SERVER "login.oscar.aol.com"
+
 #ifndef _WIN32
 #define OSCAR_DEFAULT_CUSTOM_ENCODING "ISO-8859-1"
 #else
@@ -96,4 +99,4 @@
 gboolean oscar_offline_message(const PurpleBuddy *buddy);
 void oscar_format_username(PurpleConnection *gc, const char *nick);
 GList *oscar_actions(PurplePlugin *plugin, gpointer context);
-void oscar_init(PurplePlugin *plugin);
+void oscar_init(PurplePlugin *plugin, gboolean is_icq);
--- a/libpurple/protocols/oscar/peer.c	Sat Oct 30 21:27:00 2010 +0000
+++ b/libpurple/protocols/oscar/peer.c	Sat Oct 30 21:36:34 2010 +0000
@@ -879,7 +879,9 @@
 		}
 
 		conn->verified_connect_data = purple_proxy_connect(NULL, account,
-				(conn->proxyip != NULL) ? conn->proxyip : PEER_PROXY_SERVER,
+				(conn->proxyip != NULL)
+					? conn->proxyip
+					: (conn->od->icq ? ICQ_PEER_PROXY_SERVER : AIM_PEER_PROXY_SERVER),
 				PEER_PROXY_PORT,
 				peer_proxy_connection_established_cb, conn);
 		if (conn->verified_connect_data != NULL)
--- a/libpurple/protocols/oscar/peer.h	Sat Oct 30 21:27:00 2010 +0000
+++ b/libpurple/protocols/oscar/peer.h	Sat Oct 30 21:36:34 2010 +0000
@@ -58,7 +58,8 @@
 /*
  * For peer proxying
  */
-#define PEER_PROXY_SERVER         "ars.oscar.aol.com"
+#define AIM_PEER_PROXY_SERVER         "ars.oscar.aol.com"
+#define ICQ_PEER_PROXY_SERVER         "ars.icq.com"
 #define PEER_PROXY_PORT           5190   /* The port we should always connect to */
 #define PEER_PROXY_PACKET_VERSION 0x044a