changeset 22411:7ba68075beea

merge of 'e4cc3b79eb04e4937c5fa764f6839a8e07397651' and 'f6f182a65daf42e9f1e50f409e9d965119d3932f'
author Mark Doliner <mark@kingant.net>
date Wed, 05 Mar 2008 18:13:11 +0000
parents 316c8565f562 (diff) 6eb0749ad46c (current diff)
children 04b807c8b98d
files libpurple/proxy.c
diffstat 1 files changed, 65 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/proxy.c	Wed Mar 05 18:11:02 2008 +0000
+++ b/libpurple/proxy.c	Wed Mar 05 18:13:11 2008 +0000
@@ -211,67 +211,78 @@
 purple_gnome_proxy_get_info(void)
 {
 	static PurpleProxyInfo info = {0, NULL, 0, NULL, NULL};
-	gchar *path;
-	if ((path = g_find_program_in_path("gconftool-2"))) {
-		gchar *tmp;
-
-		g_free(path);
+	gchar *tmp;
 
-		/* See whether to use a proxy. */
-		if (!g_spawn_command_line_sync("gconftool-2 -g /system/proxy/mode", &tmp,
-					       NULL, NULL, NULL))
-			return purple_global_proxy_get_info();
-		if (!strcmp(tmp, "none\n")) {
-			info.type = PURPLE_PROXY_NONE;
-			g_free(tmp);
-			return &info;
-		} else if (strcmp(tmp, "manual\n")) {
-			g_free(tmp);
-			return purple_global_proxy_get_info();
-		}
+	tmp = g_find_program_in_path("gconftool-2");
+	if (tmp == NULL)
+		return purple_global_proxy_get_info();
 
-		g_free(tmp);
-		info.type = PURPLE_PROXY_HTTP;
+	g_free(tmp);
 
-		/* Free the old fields */
-		if (info.host) {
-			g_free(info.host);
-			info.host = NULL;
-		}
-		if (info.username) {
-			g_free(info.username);
-			info.username = NULL;
-		}
-		if (info.password) {
-			g_free(info.password);
-			info.password = NULL;
-		}
+	/* Check whether to use a proxy. */
+	if (!g_spawn_command_line_sync("gconftool-2 -g /system/proxy/mode",
+			&tmp, NULL, NULL, NULL))
+		return purple_global_proxy_get_info();
 
-		/* Get the new ones */
-		if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/host", &info.host,
-					       NULL, NULL, NULL))
-			return purple_global_proxy_get_info();
-		g_strchomp(info.host);
-
-		if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_user", &info.username,
-					       NULL, NULL, NULL))
-			return purple_global_proxy_get_info();
-		g_strchomp(info.username);
-
-		if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_password", &info.password,
-					       NULL, NULL, NULL))
-			return purple_global_proxy_get_info();
-		g_strchomp(info.password);
-
-		if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/port", &tmp,
-					       NULL, NULL, NULL))
-			return purple_global_proxy_get_info();
-		info.port = atoi(tmp);
+	if (!strcmp(tmp, "none\n")) {
+		info.type = PURPLE_PROXY_NONE;
 		g_free(tmp);
-
 		return &info;
 	}
-	return purple_global_proxy_get_info();
+
+	if (strcmp(tmp, "manual\n")) {
+		/* Unknown setting.  Fallback to using our global proxy settings. */
+		g_free(tmp);
+		return purple_global_proxy_get_info();
+	}
+
+	g_free(tmp);
+
+	/* If we get this far then we know we're using an HTTP proxy */
+	info.type = PURPLE_PROXY_HTTP;
+
+	if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/host",
+			&info.host, NULL, NULL, NULL))
+		return purple_global_proxy_get_info();
+	g_strchomp(info.host);
+	if (*info.host == '\0')
+	{
+		purple_debug_info("proxy", "Gnome proxy settings are set to "
+				"'manual' but no proxy server is specified.  Using "
+				"Pidgin's proxy settings instead.\n");
+		g_free(info.host);
+		return purple_global_proxy_get_info();
+	}
+
+	if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_user",
+			&info.username, NULL, NULL, NULL))
+	{
+		g_free(info.host);
+		return purple_global_proxy_get_info();
+	}
+	g_strchomp(info.username);
+
+	if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_password",
+			&info.password, NULL, NULL, NULL))
+	{
+		g_free(info.host);
+		g_free(info.username);
+		return purple_global_proxy_get_info();
+	}
+	g_strchomp(info.password);
+
+	if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/port",
+			&tmp, NULL, NULL, NULL))
+	{
+		g_free(info.host);
+		g_free(info.username);
+		g_free(info.password);
+		return purple_global_proxy_get_info();
+	}
+	info.port = atoi(tmp);
+	g_free(tmp);
+
+	return &info;
 }
 /**************************************************************************
  * Proxy API