changeset 14980:c157efddc62a

[gaim-migrate @ 17758] Don't lose the account proxy settings just because they are hidden and not in use. Also, make the MSN HTTP method use the same proxy setup code as the core - this should improve env. var proxy handling. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Thu, 16 Nov 2006 04:58:40 +0000
parents f719225f988e
children f4705e2c2026
files gtk/gtkaccount.c libgaim/account.c libgaim/protocols/msn/httpconn.c libgaim/proxy.c
diffstat 4 files changed, 120 insertions(+), 116 deletions(-) [+]
line wrap: on
line diff
--- a/gtk/gtkaccount.c	Thu Nov 16 03:17:27 2006 +0000
+++ b/gtk/gtkaccount.c	Thu Nov 16 04:58:40 2006 +0000
@@ -1004,6 +1004,8 @@
 		(proxy_info = gaim_account_get_proxy_info(dialog->account)) != NULL) {
 
 		GaimProxyType type = gaim_proxy_info_get_type(proxy_info);
+		const char *value;
+		int int_val;
 
 		/* Hah! */
 		/* I dunno what you're laughing about, fuzz ball. */
@@ -1012,30 +1014,26 @@
 				type + 1);
 
 		if (type == GAIM_PROXY_USE_GLOBAL || type == GAIM_PROXY_NONE ||
-			type == GAIM_PROXY_USE_ENVVAR) {
+				type == GAIM_PROXY_USE_ENVVAR)
 			gtk_widget_hide_all(vbox2);
+
+
+		if ((value = gaim_proxy_info_get_host(proxy_info)) != NULL)
+			gtk_entry_set_text(GTK_ENTRY(dialog->proxy_host_entry), value);
+
+		if ((int_val = gaim_proxy_info_get_port(proxy_info)) != 0) {
+			char buf[11];
+
+			g_snprintf(buf, sizeof(buf), "%d", int_val);
+
+			gtk_entry_set_text(GTK_ENTRY(dialog->proxy_port_entry), buf);
 		}
-		else {
-			const char *value;
-			int int_val;
-
-			if ((value = gaim_proxy_info_get_host(proxy_info)) != NULL)
-				gtk_entry_set_text(GTK_ENTRY(dialog->proxy_host_entry), value);
-
-			if ((int_val = gaim_proxy_info_get_port(proxy_info)) != 0) {
-				char buf[32];
-
-				g_snprintf(buf, sizeof(buf), "%d", int_val);
-
-				gtk_entry_set_text(GTK_ENTRY(dialog->proxy_port_entry), buf);
-			}
-
-			if ((value = gaim_proxy_info_get_username(proxy_info)) != NULL)
-				gtk_entry_set_text(GTK_ENTRY(dialog->proxy_user_entry), value);
-
-			if ((value = gaim_proxy_info_get_password(proxy_info)) != NULL)
-				gtk_entry_set_text(GTK_ENTRY(dialog->proxy_pass_entry), value);
-		}
+
+		if ((value = gaim_proxy_info_get_username(proxy_info)) != NULL)
+			gtk_entry_set_text(GTK_ENTRY(dialog->proxy_user_entry), value);
+
+		if ((value = gaim_proxy_info_get_password(proxy_info)) != NULL)
+			gtk_entry_set_text(GTK_ENTRY(dialog->proxy_pass_entry), value);
 	}
 	else {
 		dialog->new_proxy_type = GAIM_PROXY_USE_GLOBAL;
@@ -1258,54 +1256,61 @@
 	}
 
 	/* Set the proxy stuff. */
-	if (dialog->new_proxy_type == GAIM_PROXY_USE_GLOBAL) {
-		gaim_account_set_proxy_info(account, NULL);
+	proxy_info = gaim_account_get_proxy_info(account);
+
+	/* Create the proxy info if it doesn't exist. */
+	if (proxy_info == NULL) {
+		proxy_info = gaim_proxy_info_new();
+		gaim_account_set_proxy_info(account, proxy_info);
 	}
-	else {
-		proxy_info = gaim_account_get_proxy_info(account);
-
-		/* Create the proxy info if it doesn't exist. */
-		if (proxy_info == NULL) {
-			proxy_info = gaim_proxy_info_new();
-			gaim_account_set_proxy_info(account, proxy_info);
-		}
-
-		/* Set the proxy info type. */
-		gaim_proxy_info_set_type(proxy_info, dialog->new_proxy_type);
-
-		/* Host */
-		value = gtk_entry_get_text(GTK_ENTRY(dialog->proxy_host_entry));
-
-		if (*value != '\0')
-			gaim_proxy_info_set_host(proxy_info, value);
-		else
-			gaim_proxy_info_set_host(proxy_info, NULL);
-
-		/* Port */
-		value = gtk_entry_get_text(GTK_ENTRY(dialog->proxy_port_entry));
-
-		if (*value != '\0')
-			gaim_proxy_info_set_port(proxy_info, atoi(value));
-		else
-			gaim_proxy_info_set_port(proxy_info, 0);
-
-		/* Username */
-		value = gtk_entry_get_text(GTK_ENTRY(dialog->proxy_user_entry));
-
-		if (*value != '\0')
-			gaim_proxy_info_set_username(proxy_info, value);
-		else
-			gaim_proxy_info_set_username(proxy_info, NULL);
-
-		/* Password */
-		value = gtk_entry_get_text(GTK_ENTRY(dialog->proxy_pass_entry));
-
-		if (*value != '\0')
-			gaim_proxy_info_set_password(proxy_info, value);
-		else
-			gaim_proxy_info_set_password(proxy_info, NULL);
+
+	/* Set the proxy info type. */
+	gaim_proxy_info_set_type(proxy_info, dialog->new_proxy_type);
+
+	/* Host */
+	value = gtk_entry_get_text(GTK_ENTRY(dialog->proxy_host_entry));
+
+	if (*value != '\0')
+		gaim_proxy_info_set_host(proxy_info, value);
+	else
+		gaim_proxy_info_set_host(proxy_info, NULL);
+
+	/* Port */
+	value = gtk_entry_get_text(GTK_ENTRY(dialog->proxy_port_entry));
+
+	if (*value != '\0')
+		gaim_proxy_info_set_port(proxy_info, atoi(value));
+	else
+		gaim_proxy_info_set_port(proxy_info, 0);
+
+	/* Username */
+	value = gtk_entry_get_text(GTK_ENTRY(dialog->proxy_user_entry));
+
+	if (*value != '\0')
+		gaim_proxy_info_set_username(proxy_info, value);
+	else
+		gaim_proxy_info_set_username(proxy_info, NULL);
+
+	/* Password */
+	value = gtk_entry_get_text(GTK_ENTRY(dialog->proxy_pass_entry));
+
+	if (*value != '\0')
+		gaim_proxy_info_set_password(proxy_info, value);
+	else
+		gaim_proxy_info_set_password(proxy_info, NULL);
+
+	/* If there are no values set then proxy_info NULL */
+	if ((gaim_proxy_info_get_type(proxy_info) == GAIM_PROXY_USE_GLOBAL) &&
+		(gaim_proxy_info_get_host(proxy_info) == NULL) &&
+		(gaim_proxy_info_get_port(proxy_info) == 0) &&
+		(gaim_proxy_info_get_username(proxy_info) == NULL) &&
+		(gaim_proxy_info_get_password(proxy_info) == NULL))
+	{
+		gaim_account_set_proxy_info(account, NULL);
+		proxy_info = NULL;
 	}
 
+
 	/* We no longer need the data from the dialog window */
 	account_win_destroy_cb(NULL, NULL, dialog);
 
--- a/libgaim/account.c	Thu Nov 16 03:17:27 2006 +0000
+++ b/libgaim/account.c	Thu Nov 16 04:58:40 2006 +0000
@@ -269,34 +269,29 @@
 			 proxy_type == GAIM_PROXY_SOCKS5     ? "socks5" :
 			 proxy_type == GAIM_PROXY_USE_ENVVAR ? "envvar" : "unknown"), -1);
 
-	if (proxy_type != GAIM_PROXY_USE_GLOBAL &&
-		proxy_type != GAIM_PROXY_NONE &&
-		proxy_type != GAIM_PROXY_USE_ENVVAR)
+	if ((value = gaim_proxy_info_get_host(proxy_info)) != NULL)
+	{
+		child = xmlnode_new_child(node, "host");
+		xmlnode_insert_data(child, value, -1);
+	}
+
+	if ((int_value = gaim_proxy_info_get_port(proxy_info)) != 0)
 	{
-		if ((value = gaim_proxy_info_get_host(proxy_info)) != NULL)
-		{
-			child = xmlnode_new_child(node, "host");
-			xmlnode_insert_data(child, value, -1);
-		}
-
-		if ((int_value = gaim_proxy_info_get_port(proxy_info)) != 0)
-		{
-			snprintf(buf, sizeof(buf), "%d", int_value);
-			child = xmlnode_new_child(node, "port");
-			xmlnode_insert_data(child, buf, -1);
-		}
-
-		if ((value = gaim_proxy_info_get_username(proxy_info)) != NULL)
-		{
-			child = xmlnode_new_child(node, "username");
-			xmlnode_insert_data(child, value, -1);
-		}
-
-		if ((value = gaim_proxy_info_get_password(proxy_info)) != NULL)
-		{
-			child = xmlnode_new_child(node, "password");
-			xmlnode_insert_data(child, value, -1);
-		}
+		snprintf(buf, sizeof(buf), "%d", int_value);
+		child = xmlnode_new_child(node, "port");
+		xmlnode_insert_data(child, buf, -1);
+	}
+
+	if ((value = gaim_proxy_info_get_username(proxy_info)) != NULL)
+	{
+		child = xmlnode_new_child(node, "username");
+		xmlnode_insert_data(child, value, -1);
+	}
+
+	if ((value = gaim_proxy_info_get_password(proxy_info)) != NULL)
+	{
+		child = xmlnode_new_child(node, "password");
+		xmlnode_insert_data(child, value, -1);
 	}
 
 	return node;
@@ -657,7 +652,7 @@
 		g_free(data);
 	}
 
-	/* If there are no values set then proxy_infourn NULL */
+	/* If there are no values set then proxy_info NULL */
 	if ((gaim_proxy_info_get_type(proxy_info) == GAIM_PROXY_USE_GLOBAL) &&
 		(gaim_proxy_info_get_host(proxy_info) == NULL) &&
 		(gaim_proxy_info_get_port(proxy_info) == 0) &&
@@ -1031,7 +1026,7 @@
 	gc = gaim_account_get_connection(account);
 	gaim_connection_destroy(gc);
 	if (!gaim_account_get_remember_password(account))
-	  gaim_account_set_password(account, NULL);
+		gaim_account_set_password(account, NULL);
 	gaim_account_set_connection(account, NULL);
 
 	account->disconnecting = FALSE;
--- a/libgaim/protocols/msn/httpconn.c	Thu Nov 16 03:17:27 2006 +0000
+++ b/libgaim/protocols/msn/httpconn.c	Thu Nov 16 04:58:40 2006 +0000
@@ -475,10 +475,7 @@
 
 	account = httpconn->session->account;
 
-	if (gaim_account_get_proxy_info(account) == NULL)
-		gpi = gaim_global_proxy_get_info();
-	else
-		gpi = gaim_account_get_proxy_info(account);
+	gpi = gaim_proxy_get_setup(account);
 
 	if (gpi == NULL || !(gaim_proxy_info_get_type(gpi) == GAIM_PROXY_HTTP ||
 						 gaim_proxy_info_get_type(gpi) == GAIM_PROXY_USE_ENVVAR))
--- a/libgaim/proxy.c	Thu Nov 16 03:17:27 2006 +0000
+++ b/libgaim/proxy.c	Thu Nov 16 04:58:40 2006 +0000
@@ -1685,7 +1685,7 @@
 GaimProxyInfo *
 gaim_proxy_get_setup(GaimAccount *account)
 {
-	GaimProxyInfo *gpi;
+	GaimProxyInfo *gpi = NULL;
 	const gchar *tmp;
 
 	/* This is used as a fallback so we don't overwrite the selected proxy type */
@@ -1695,12 +1695,17 @@
 		gaim_proxy_info_set_type(tmp_none_proxy_info, GAIM_PROXY_NONE);
 	}
 
-	if (account && gaim_account_get_proxy_info(account) != NULL)
+	if (account && gaim_account_get_proxy_info(account) != NULL) {
 		gpi = gaim_account_get_proxy_info(account);
-	else if (gaim_running_gnome())
-		gpi = gaim_gnome_proxy_get_info();
-	else
-		gpi = gaim_global_proxy_get_info();
+		if (gaim_proxy_info_get_type(gpi) == GAIM_PROXY_USE_GLOBAL)
+			gpi = NULL;
+	}
+	if (gpi == NULL) {
+		if (gaim_running_gnome())
+			gpi = gaim_gnome_proxy_get_info();
+		else
+			gpi = gaim_global_proxy_get_info();
+	}
 
 	if (gaim_proxy_info_get_type(gpi) == GAIM_PROXY_USE_ENVVAR) {
 #ifdef _WIN32
@@ -1733,6 +1738,18 @@
 					proxyport = atoi(tmp);
 
 				gaim_proxy_info_set_port(gpi, proxyport);
+
+				/* XXX: Do we want to skip this step if user/password were part of url? */
+				if ((tmp = g_getenv("HTTP_PROXY_USER")) != NULL ||
+					(tmp = g_getenv("http_proxy_user")) != NULL ||
+					(tmp = g_getenv("HTTPPROXYUSER")) != NULL)
+					gaim_proxy_info_set_username(gpi, tmp);
+
+				if ((tmp = g_getenv("HTTP_PROXY_PASS")) != NULL ||
+					(tmp = g_getenv("http_proxy_pass")) != NULL ||
+					(tmp = g_getenv("HTTPPROXYPASS")) != NULL)
+					gaim_proxy_info_set_password(gpi, tmp);
+
 			}
 		} else {
 			/* no proxy environment variable found, don't use a proxy */
@@ -1740,16 +1757,6 @@
 			gpi = tmp_none_proxy_info;
 		}
 
-		/* XXX: Do we want to skip this step if user/password were part of url? */
-		if ((tmp = g_getenv("HTTP_PROXY_USER")) != NULL ||
-			(tmp = g_getenv("http_proxy_user")) != NULL ||
-			(tmp = g_getenv("HTTPPROXYUSER")) != NULL)
-			gaim_proxy_info_set_username(gpi, tmp);
-
-		if ((tmp = g_getenv("HTTP_PROXY_PASS")) != NULL ||
-			(tmp = g_getenv("http_proxy_pass")) != NULL ||
-			(tmp = g_getenv("HTTPPROXYPASS")) != NULL)
-			gaim_proxy_info_set_password(gpi, tmp);
 	}
 
 	return gpi;