[gnome-terminal] Move http_proxy code into a function



commit 524edd0634a988fe7af3bf0e270fbd00982fff9d
Author: Behdad Esfahbod <behdad behdad org>
Date:   Fri Dec 11 08:02:31 2009 -0500

    Move http_proxy code into a function

 src/terminal-screen.c |  245 +++++++++++++++++++++++++------------------------
 1 files changed, 127 insertions(+), 118 deletions(-)
---
diff --git a/src/terminal-screen.c b/src/terminal-screen.c
index 3736983..562de50 100644
--- a/src/terminal-screen.c
+++ b/src/terminal-screen.c
@@ -1288,6 +1288,132 @@ show_command_error_dialog (TerminalScreen *screen,
                                    "%s", _("There was a problem with the command for this terminal"));
 }
 
+
+void
+setup_proxy_env (GHashTable *env_table)
+{
+  char *proxymode, *proxyhost;
+  gboolean use_proxy;
+
+  GConfClient *conf;
+  conf = gconf_client_get_default ();
+
+  /* Series of conditions under which we don't set http_proxy */
+  use_proxy = gconf_client_get_bool (conf, HTTP_PROXY_DIR "/use_http_proxy", NULL);
+
+  /* Is the mode unset or not equal to "manual"? */
+  proxymode = gconf_client_get_string (conf, "/system/proxy/mode", NULL);
+  if (!proxymode || strcmp (proxymode, "manual") != 0)
+    use_proxy = FALSE;
+  g_free (proxymode);
+
+  /* Do we already have a proxy setting? */
+  if (g_hash_table_lookup (env_table, "http_proxy") != NULL)
+    use_proxy = FALSE;
+
+  /* Do we have no proxy host or an empty string? */
+  proxyhost = gconf_client_get_string (conf, HTTP_PROXY_DIR "/host", NULL);
+  if (!proxyhost || proxyhost[0] == '\0')
+    use_proxy = FALSE;
+  g_free (proxyhost);
+
+  /* Set up proxy environment variables if we passed all of the above */
+  if (use_proxy)
+    {
+      gint port;
+      GSList *ignore;
+      gchar *host, *auth = NULL;
+
+      host = gconf_client_get_string (conf, HTTP_PROXY_DIR "/host", NULL);
+      port = gconf_client_get_int (conf, HTTP_PROXY_DIR "/port", NULL);
+      ignore = gconf_client_get_list (conf, HTTP_PROXY_DIR "/ignore_hosts",
+				      GCONF_VALUE_STRING, NULL);
+
+      if (gconf_client_get_bool (conf, HTTP_PROXY_DIR "/use_authentication", NULL))
+	{
+	  char *user, *password;
+
+	  user = gconf_client_get_string (conf,
+					  HTTP_PROXY_DIR "/authentication_user",
+					  NULL);
+
+	  password = gconf_client_get_string (conf,
+					      HTTP_PROXY_DIR
+					      "/authentication_password",
+					      NULL);
+
+	  if (user && *user != '\0')
+            {
+              if (password)
+                auth = g_strdup_printf ("%s:%s", user, password);
+              else
+                auth = g_strdup (user);
+            }
+
+	  g_free (user);
+	  g_free (password);
+	}
+
+      g_object_unref (conf);
+
+      if (port && host && *host != '\0')
+	{
+	  if (auth)
+            g_hash_table_replace (env_table, g_strdup ("http_proxy"),
+                                  g_strdup_printf ("http://%s %s:%d/", auth, host, port));
+	  else
+            g_hash_table_replace (env_table, g_strdup ("http_proxy"),
+	                          g_strdup_printf ("http://%s:%d/";, host, port));
+	}
+
+      if (auth)
+	g_free (auth);
+
+      if (host)
+	g_free (host);
+
+      if (ignore)
+	{
+	  /* code distantly based on gconf's */
+	  gchar *buf = NULL;
+	  guint bufsize = 64;
+	  guint cur = 0;
+
+	  buf = g_malloc (bufsize + 3);
+
+	  while (ignore != NULL)
+	    {
+	      guint len = strlen (ignore->data);
+
+	      if ((cur + len + 2) >= bufsize) /* +2 for '\0' and comma */
+		{
+		  bufsize = MAX(bufsize * 2, bufsize + len + 4); 
+		  buf = g_realloc (buf, bufsize + 3);
+		}
+
+	      g_assert (cur < bufsize);
+
+	      strcpy (&buf[cur], ignore->data);
+	      cur += len;
+
+	      g_assert(cur < bufsize);
+
+	      buf[cur] = ',';
+	      ++cur;
+
+	      g_assert(cur < bufsize);
+
+	      ignore = g_slist_next (ignore);
+	    }
+
+	  buf[cur-1] = '\0'; /* overwrites last comma */
+
+          g_hash_table_replace (env_table, g_strdup ("no_proxy"), buf);
+	}
+    }
+}
+
+
 static gboolean
 get_child_command (TerminalScreen *screen,
                    const char     *shell_env,
@@ -1373,9 +1499,6 @@ get_child_environment (TerminalScreen *screen,
   GtkWidget *window;
   char **env;
   char *e, *v;
-  char *proxymode, *proxyhost;
-  gboolean use_proxy;
-  GConfClient *conf;
   GHashTable *env_table;
   GHashTableIter iter;
   GPtrArray *retval;
@@ -1419,121 +1542,7 @@ get_child_environment (TerminalScreen *screen,
   g_hash_table_replace (env_table, g_strdup ("DISPLAY"), g_strdup (gdk_display_get_name (gtk_widget_get_display (window))));
 #endif
 
-  conf = gconf_client_get_default ();
-
-  /* Series of conditions under which we don't set http_proxy */
-  use_proxy = gconf_client_get_bool (conf, HTTP_PROXY_DIR "/use_http_proxy", NULL);
-
-  /* Is the mode unset or not equal to "manual"? */
-  proxymode = gconf_client_get_string (conf, "/system/proxy/mode", NULL);
-  if (!proxymode || strcmp (proxymode, "manual") != 0)
-    use_proxy = FALSE;
-  g_free (proxymode);
-
-  /* Do we already have a proxy setting? */
-  if (g_hash_table_lookup (env_table, "http_proxy") != NULL)
-    use_proxy = FALSE;
-
-  /* Do we have no proxy host or an empty string? */
-  proxyhost = gconf_client_get_string (conf, HTTP_PROXY_DIR "/host", NULL);
-  if (!proxyhost || proxyhost[0] == '\0')
-    use_proxy = FALSE;
-  g_free (proxyhost);
-
-  /* Set up proxy environment variables if we passed all of the above */
-  if (use_proxy)
-    {
-      gint port;
-      GSList *ignore;
-      gchar *host, *auth = NULL;
-
-      host = gconf_client_get_string (conf, HTTP_PROXY_DIR "/host", NULL);
-      port = gconf_client_get_int (conf, HTTP_PROXY_DIR "/port", NULL);
-      ignore = gconf_client_get_list (conf, HTTP_PROXY_DIR "/ignore_hosts",
-				      GCONF_VALUE_STRING, NULL);
-
-      if (gconf_client_get_bool (conf, HTTP_PROXY_DIR "/use_authentication", NULL))
-	{
-	  char *user, *password;
-
-	  user = gconf_client_get_string (conf,
-					  HTTP_PROXY_DIR "/authentication_user",
-					  NULL);
-
-	  password = gconf_client_get_string (conf,
-					      HTTP_PROXY_DIR
-					      "/authentication_password",
-					      NULL);
-
-	  if (user && *user != '\0')
-            {
-              if (password)
-                auth = g_strdup_printf ("%s:%s", user, password);
-              else
-                auth = g_strdup (user);
-            }
-
-	  g_free (user);
-	  g_free (password);
-	}
-
-      g_object_unref (conf);
-
-      if (port && host && *host != '\0')
-	{
-	  if (auth)
-            g_hash_table_replace (env_table, g_strdup ("http_proxy"),
-                                  g_strdup_printf ("http://%s %s:%d/", auth, host, port));
-	  else
-            g_hash_table_replace (env_table, g_strdup ("http_proxy"),
-	                          g_strdup_printf ("http://%s:%d/";, host, port));
-	}
-
-      if (auth)
-	g_free (auth);
-
-      if (host)
-	g_free (host);
-
-      if (ignore)
-	{
-	  /* code distantly based on gconf's */
-	  gchar *buf = NULL;
-	  guint bufsize = 64;
-	  guint cur = 0;
-
-	  buf = g_malloc (bufsize + 3);
-
-	  while (ignore != NULL)
-	    {
-	      guint len = strlen (ignore->data);
-
-	      if ((cur + len + 2) >= bufsize) /* +2 for '\0' and comma */
-		{
-		  bufsize = MAX(bufsize * 2, bufsize + len + 4); 
-		  buf = g_realloc (buf, bufsize + 3);
-		}
-
-	      g_assert (cur < bufsize);
-
-	      strcpy (&buf[cur], ignore->data);
-	      cur += len;
-
-	      g_assert(cur < bufsize);
-
-	      buf[cur] = ',';
-	      ++cur;
-
-	      g_assert(cur < bufsize);
-
-	      ignore = g_slist_next (ignore);
-	    }
-
-	  buf[cur-1] = '\0'; /* overwrites last comma */
-
-          g_hash_table_replace (env_table, g_strdup ("no_proxy"), buf);
-	}
-    }
+  setup_proxy_env (env_table);
 
   retval = g_ptr_array_sized_new (g_hash_table_size (env_table));
   g_hash_table_iter_init (&iter, env_table);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]