source: trunk/third/evolution/e-util/e-proxy.c @ 19195

Revision 19195, 3.9 KB checked in by ghudson, 21 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r19194, which included commits to RCS files with non-trunk default branches.
Line 
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2/*
3 *  Authors: Jeffrey Stedfast <fejj@ximian.com>
4 *
5 *  Copyright 2002 Ximian, Inc. (www.ximian.com)
6 *
7 *  This program is free software; you can redistribute it and/or modify
8 *  it under the terms of the GNU General Public License as published by
9 *  the Free Software Foundation; either version 2 of the License, or
10 *  (at your option) any later version.
11 *
12 *  This program is distributed in the hope that it will be useful,
13 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *  GNU General Public License for more details.
16 *
17 *  You should have received a copy of the GNU General Public License
18 *  along with this program; if not, write to the Free Software
19 *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
20 *
21 */
22
23
24#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27
28#include <glib.h>
29
30#include <gconf/gconf.h>
31#include <gconf/gconf-client.h>
32
33#include <libsoup/soup.h>
34
35#include "e-proxy.h"
36
37static void
38set_proxy (GConfClient *client)
39{
40        SoupContext *context;
41        char *proxy_server, *proxy_user, *proxy_pw, *uri;
42        gboolean use_auth, use_proxy;
43        int proxy_port;
44        gboolean new_proxy_exists;
45
46        new_proxy_exists = gconf_client_dir_exists (client, "/system/http_proxy", NULL);
47
48        if (new_proxy_exists) {
49                use_proxy = gconf_client_get_bool (client, "/system/http_proxy/use_http_proxy", NULL);
50        } else {
51                use_proxy = gconf_client_get_bool (client, "/system/gnome-vfs/use-http-proxy", NULL);
52        }
53
54        if (use_proxy == FALSE) {
55                return;
56        }
57
58        if (new_proxy_exists) {
59                proxy_server = gconf_client_get_string (client, "/system/http_proxy/host", NULL);
60                proxy_port = gconf_client_get_int (client, "/system/http_proxy/port", NULL);
61
62                use_auth = gconf_client_get_bool (client, "/system/http_proxy/use_authentication", NULL);
63        } else {
64                proxy_server = gconf_client_get_string (client, "/system/gnome-vfs/http-proxy-host", NULL);
65                proxy_port = gconf_client_get_int (client, "/system/gnome-vfs/http-proxy-port", NULL);
66       
67                use_auth = gconf_client_get_bool (client, "/system/gnome-vfs/use-http-proxy-authorization", NULL);
68        }
69
70        if (use_auth == TRUE) {
71                if (new_proxy_exists) {
72                        proxy_user = gconf_client_get_string (client, "/system/http_proxy/authentication_user", NULL);
73                        proxy_pw = gconf_client_get_string (client, "/system/http_proxy/authentication_password", NULL);
74                } else {
75                        proxy_user = gconf_client_get_string (client, "/system/gnome-vfs/http-proxy-authorization-user", NULL);
76                        proxy_pw = gconf_client_get_string (client, "/system/gnome-vfs/http-proxy-authorization-password", NULL);
77                }
78                uri = g_strdup_printf ("http://%s:%s@%s:%d", proxy_user, proxy_pw, proxy_server, proxy_port);
79        } else {
80                uri = g_strdup_printf ("http://%s:%d", proxy_server, proxy_port);
81        }
82       
83        context = soup_context_get (uri);
84        soup_set_proxy (context);
85        soup_context_unref (context);
86        g_free (uri);
87}
88
89static void
90proxy_setting_changed (GConfClient *client, guint32 cnxn_id,
91                       GConfEntry *entry, gpointer user_data)
92{
93        set_proxy (client);
94}
95
96void
97e_proxy_init ()
98{
99        GConfClient *client;
100        gboolean new_proxy_exists;
101
102        /* We get the gnome-vfs proxy keys here
103           set soup up to use the proxy,
104           and listen to any changes */
105       
106        if (!(client = gconf_client_get_default ()))
107                return;
108       
109        new_proxy_exists = gconf_client_dir_exists (client, "/system/http_proxy", NULL);
110
111        /* Listen to the changes in the gnome-vfs path */
112        if (new_proxy_exists) {
113                gconf_client_add_dir (client, "/system/http_proxy",
114                                      GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
115                gconf_client_notify_add (client, "/system/http_proxy/",
116                                         proxy_setting_changed, NULL,
117                                         NULL, NULL);
118        } else {
119                gconf_client_add_dir (client, "/system/gnome-vfs",
120                                      GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
121                gconf_client_notify_add (client, "/system/gnome-vfs/",
122                                         proxy_setting_changed, NULL,
123                                         NULL, NULL);
124        }
125       
126        set_proxy (client);
127}
Note: See TracBrowser for help on using the repository browser.