~ubuntu-branches/ubuntu/quantal/gnome-terminal/quantal-proposed

« back to all changes in this revision

Viewing changes to src/terminal-util.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Ancell
  • Date: 2010-04-01 11:18:48 UTC
  • mfrom: (1.3.39 upstream) (2.1.9 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100401111848-225g3npz0f923ebx
Tags: 2.30.1-1ubuntu1
* Merge with Debian unstable, remaining Ubuntu changes:
* debian/control.in:
  - Build depend on liblaunchpad-integration-dev
  - Build depend on gnome-common to run autoreconf
  - Add Bzr link
* debian/rules:
  - Run autoreconf on build
* debian/patches/01_lpi.patch:
  - LP integration
* debian/patches/02_add_transparency_properties.patch:
  - This patch allows the background transparency to be controlled from
    the GTK theme (using "TerminalScreen::background-darkness"). In
    addition to this, the background colour and text colour are already
    themable from the GTK theme (by setting the "text[NORMAL]" and
    "base[NORMAL]" colours for the TerminalScreen class)
* debian/patches/20_add_alt_screen_toggle_ui.patch:
  - Hook new vte alternate screen scrolling toggle via UI
* debian/watch:
  - Watch for unstable versions

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include <gio/gio.h>
33
33
#include <gtk/gtk.h>
34
34
 
 
35
#include <gconf/gconf.h>
 
36
 
35
37
#ifdef GDK_WINDOWING_X11
36
38
#include <gdk/gdkx.h>
37
39
#include <X11/Xatom.h>
649
651
  return (char **) g_ptr_array_free (argv, FALSE);
650
652
}
651
653
 
 
654
/* Proxy stuff */
 
655
 
 
656
static char *
 
657
conf_get_string (GConfClient *conf,
 
658
                 const char *key)
 
659
{
 
660
  char *value;
 
661
  value = gconf_client_get_string (conf, key, NULL);
 
662
  if (G_UNLIKELY (value && *value == '\0'))
 
663
    {
 
664
      g_free (value);
 
665
      value = NULL;
 
666
    }
 
667
  return value;
 
668
}
 
669
 
 
670
/*
 
671
 * set_proxy_env:
 
672
 * @env_table: a #GHashTable
 
673
 * @key: the env var name
 
674
 * @value: the env var value
 
675
 *
 
676
 * Adds @value for @key to @env_table, taking care to never overwrite an
 
677
 * existing value for @key. @value is consumed.
 
678
 */
 
679
static void
 
680
set_proxy_env (GHashTable *env_table,
 
681
               const char *key,
 
682
               char *value)
 
683
{
 
684
  char *key1 = NULL, *key2 = NULL;
 
685
  char *value1 = NULL, *value2 = NULL;
 
686
 
 
687
  if (!value)
 
688
    return;
 
689
 
 
690
  if (g_hash_table_lookup (env_table, key) == NULL)
 
691
    key1 = g_strdup (key);
 
692
 
 
693
  key2 = g_ascii_strup (key, -1);
 
694
  if (g_hash_table_lookup (env_table, key) != NULL)
 
695
    {
 
696
      g_free (key2);
 
697
      key2 = NULL;
 
698
    }
 
699
 
 
700
  if (key1 && key2)
 
701
    {
 
702
      value1 = value;
 
703
      value2 = g_strdup (value);
 
704
    }
 
705
  else if (key1)
 
706
    value1 = value;
 
707
  else if (key2)
 
708
    value2 = value;
 
709
  else
 
710
    g_free (value);
 
711
 
 
712
  if (key1)
 
713
    g_hash_table_replace (env_table, key1, value1);
 
714
  if (key2)
 
715
    g_hash_table_replace (env_table, key2, value2);
 
716
}
 
717
 
 
718
static void
 
719
setup_http_proxy_env (GHashTable *env_table,
 
720
                      GConfClient *conf)
 
721
{
 
722
  gchar *host, *auth = NULL;
 
723
  gint port;
 
724
  GSList *ignore;
 
725
 
 
726
  if (!gconf_client_get_bool (conf, CONF_HTTP_PROXY_PREFIX "/use_http_proxy", NULL))
 
727
    return;
 
728
 
 
729
  if (gconf_client_get_bool (conf, CONF_HTTP_PROXY_PREFIX "/use_authentication", NULL))
 
730
    {
 
731
      char *user, *password;
 
732
      user = conf_get_string (conf, CONF_HTTP_PROXY_PREFIX "/authentication_user");
 
733
      password = conf_get_string (conf, CONF_HTTP_PROXY_PREFIX "/authentication_password");
 
734
      if (user)
 
735
        {
 
736
          if (password)
 
737
            {
 
738
              auth = g_strdup_printf ("%s:%s", user, password);
 
739
              g_free (user);
 
740
            }
 
741
          else
 
742
            auth = user;
 
743
        }
 
744
      g_free (password);
 
745
    }
 
746
 
 
747
  host = conf_get_string (conf, CONF_HTTP_PROXY_PREFIX "/host");
 
748
  port = gconf_client_get_int (conf, CONF_HTTP_PROXY_PREFIX "/port", NULL);
 
749
  if (host && port)
 
750
    {
 
751
      char *proxy;
 
752
      if (auth)
 
753
        proxy = g_strdup_printf ("http://%s@%s:%d/", auth, host, port);
 
754
      else
 
755
        proxy = g_strdup_printf ("http://%s:%d/", host, port);
 
756
      set_proxy_env (env_table, "http_proxy", proxy);
 
757
    }
 
758
  g_free (host);
 
759
 
 
760
  g_free (auth);
 
761
 
 
762
 
 
763
  ignore = gconf_client_get_list (conf, CONF_HTTP_PROXY_PREFIX "/ignore_hosts", GCONF_VALUE_STRING, NULL);
 
764
  if (ignore)
 
765
    {
 
766
      GString *buf = g_string_sized_new (64);
 
767
      while (ignore != NULL)
 
768
        {
 
769
          GSList *old;
 
770
 
 
771
          if (buf->len)
 
772
            g_string_append_c (buf, ',');
 
773
          g_string_append (buf, ignore->data);
 
774
 
 
775
          old = ignore;
 
776
          ignore = g_slist_next (ignore);
 
777
          g_free (old->data);
 
778
          g_slist_free_1 (old);
 
779
        }
 
780
      set_proxy_env (env_table, "no_proxy", g_string_free (buf, FALSE));
 
781
    }
 
782
}
 
783
 
 
784
static void
 
785
setup_https_proxy_env (GHashTable *env_table,
 
786
                       GConfClient *conf)
 
787
{
 
788
  gchar *host;
 
789
  gint port;
 
790
 
 
791
  host = conf_get_string (conf, CONF_PROXY_PREFIX "/secure_host");
 
792
  port = gconf_client_get_int (conf, CONF_PROXY_PREFIX "/secure_port", NULL);
 
793
  if (host && port)
 
794
    {
 
795
      char *proxy;
 
796
      proxy = g_strdup_printf ("https://%s:%d/", host, port);
 
797
      set_proxy_env (env_table, "https_proxy", proxy);
 
798
    }
 
799
  g_free (host);
 
800
}
 
801
 
 
802
static void
 
803
setup_ftp_proxy_env (GHashTable *env_table,
 
804
                     GConfClient *conf)
 
805
{
 
806
  gchar *host;
 
807
  gint port;
 
808
 
 
809
  host = conf_get_string (conf, CONF_PROXY_PREFIX "/ftp_host");
 
810
  port = gconf_client_get_int (conf, CONF_PROXY_PREFIX "/ftp_port", NULL);
 
811
  if (host && port)
 
812
    {
 
813
      char *proxy;
 
814
      proxy = g_strdup_printf ("ftp://%s:%d/", host, port);
 
815
      set_proxy_env (env_table, "ftp_proxy", proxy);
 
816
    }
 
817
  g_free (host);
 
818
}
 
819
 
 
820
static void
 
821
setup_socks_proxy_env (GHashTable *env_table,
 
822
                       GConfClient *conf)
 
823
{
 
824
  gchar *host;
 
825
  gint port;
 
826
 
 
827
  host = conf_get_string (conf, CONF_PROXY_PREFIX "/socks_host");
 
828
  port = gconf_client_get_int (conf, CONF_PROXY_PREFIX "/socks_port", NULL);
 
829
  if (host && port)
 
830
    {
 
831
      char *proxy;
 
832
      proxy = g_strdup_printf ("socks://%s:%d/", host, port);
 
833
      set_proxy_env (env_table, "all_proxy", proxy);
 
834
    }
 
835
  g_free (host);
 
836
}
 
837
 
 
838
static void
 
839
setup_autoconfig_proxy_env (GHashTable *env_table,
 
840
                            GConfClient *conf)
 
841
{
 
842
  gchar *url;
 
843
 
 
844
  url = conf_get_string (conf, CONF_PROXY_PREFIX "/autoconfig_url");
 
845
  if (url)
 
846
    {
 
847
      /* XXX  Not sure what to do with it.  See bug 596688
 
848
      char *proxy;
 
849
      proxy = g_strdup_printf ("pac+%s", url);
 
850
      set_proxy_env (env_table, "http_proxy", proxy);
 
851
      */
 
852
    }
 
853
  g_free (url);
 
854
}
 
855
 
 
856
/**
 
857
 * terminal_util_add_proxy_env:
 
858
 * @env_table: a #GHashTable
 
859
 *
 
860
 * Adds the proxy env variables to @env_table.
 
861
 */
 
862
void
 
863
terminal_util_add_proxy_env (GHashTable *env_table)
 
864
{
 
865
  char *proxymode;
 
866
 
 
867
  GConfClient *conf;
 
868
  conf = gconf_client_get_default ();
 
869
 
 
870
  /* If mode is not manual, nothing to set */
 
871
  proxymode = conf_get_string (conf, CONF_PROXY_PREFIX "/mode");
 
872
  if (proxymode && 0 == strcmp (proxymode, "manual"))
 
873
    {
 
874
      setup_http_proxy_env (env_table, conf);
 
875
      setup_https_proxy_env (env_table, conf);
 
876
      setup_ftp_proxy_env (env_table, conf);
 
877
      setup_socks_proxy_env (env_table, conf);
 
878
    }
 
879
  else if (proxymode && 0 == strcmp (proxymode, "auto"))
 
880
    {
 
881
      setup_autoconfig_proxy_env (env_table, conf);
 
882
    }
 
883
 
 
884
  g_free (proxymode);
 
885
  g_object_unref (conf);
 
886
}
 
887
 
652
888
/* Bidirectional object/widget binding */
653
889
 
654
890
typedef struct {