changeset 22410:316c8565f562

Improve our error handling of Gnome proxy settings. * If the proxy hostname is null then fallback to using Pidgin's proxy settings (and print a debug message). * If a subsequent call to gconftool-2 fails then make sure we free the stuff we've already read.
author Mark Doliner <mark@kingant.net>
date Wed, 05 Mar 2008 10:00:45 +0000
parents 31fb78b1184c
children 7ba68075beea b0b8c94118c8 fdda2b8a4146 b31b72cd273d
files libpurple/proxy.c
diffstat 1 files changed, 38 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/proxy.c	Wed Mar 05 09:43:31 2008 +0000
+++ b/libpurple/proxy.c	Wed Mar 05 10:00:45 2008 +0000
@@ -219,41 +219,66 @@
 
 	g_free(tmp);
 
-	/* See whether to use a proxy. */
-	if (!g_spawn_command_line_sync("gconftool-2 -g /system/proxy/mode", &tmp,
-				       NULL, NULL, 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();
+
 	if (!strcmp(tmp, "none\n")) {
 		info.type = PURPLE_PROXY_NONE;
 		g_free(tmp);
 		return &info;
-	} else if (strcmp(tmp, "manual\n")) {
+	}
+
+	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;
 
-	/* Get the new ones */
-	if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/host", &info.host,
-				       NULL, NULL, NULL))
+	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))
+	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))
+	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))
+	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);