1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
/*******************************************************************************
* libproxy - A library for proxy configuration
* Copyright (C) 2006 Nathaniel McCallum <nathaniel@natemccallum.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/
#include <stdlib.h>
#include <string.h>
#include <misc.h>
#include <proxy_factory.h>
#include <gconf/gconf-client.h>
// From xhasclient.c
bool x_has_client(char *prog, ...);
pxConfig *
gconf_config_cb(pxProxyFactory *self)
{
// Get the GConf client
GConfClient *client = px_proxy_factory_misc_get(self, "gnome");
if (!client)
{
// Create a new instance if not found
client = gconf_client_get_default();
if (!client) return NULL;
px_proxy_factory_misc_set(self, "gnome", client);
}
g_object_ref(client);
// Get the mode
char *mode = gconf_client_get_string(client, "/system/proxy/mode", NULL);
if (!mode) { g_object_unref(client); return NULL; }
char *url = NULL, *ignore = NULL;
// Mode is direct://
if (!strcmp(mode, "none"))
url = px_strdup("direct://");
// Mode is wpad:// or pac+http://...
else if (!strcmp(mode, "auto"))
{
char *tmp = gconf_client_get_string(client, "/system/proxy/autoconfig_url", NULL);
if (px_url_is_valid(tmp))
url = g_strdup_printf("pac+%s", tmp);
else
url = px_strdup("wpad://");
px_free(tmp);
}
// Mode is http://... or socks://...
else if (!strcmp(mode, "manual"))
{
char *type = px_strdup("http");
char *host = gconf_client_get_string(client, "/system/http_proxy/host", NULL);
int port = gconf_client_get_int (client, "/system/http_proxy/port", NULL);
if (port < 0 || port > 65535) port = 0;
// If http proxy is not set, try socks
if (!host || !strcmp(host, "") || !port)
{
if (type) px_free(type);
if (host) px_free(host);
type = px_strdup("socks");
host = gconf_client_get_string(client, "/system/proxy/socks_host", NULL);
port = gconf_client_get_int (client, "/system/proxy/socks_port", NULL);
if (port < 0 || port > 65535) port = 0;
}
// If host and port were found, build config url
if (host && strcmp(host, "") && port)
url = g_strdup_printf("%s://%s:%d", type, host, port);
if (type) px_free(type);
if (host) px_free(host);
}
px_free(mode);
if (url)
{
GSList *ignores = gconf_client_get_list(client, "/system/http_proxy/ignore_hosts",
GCONF_VALUE_STRING, NULL);
if (ignores)
{
GSList *start = ignores;
for ( ; ignores ; ignores = g_slist_next(ignores))
{
if (ignore)
{
char *tmp = g_strdup_printf("%s,%s", ignore, ignores->data);
g_free(ignore);
ignore = tmp;
}
else
ignore = g_strdup(ignores->data);
g_free(ignores->data);
}
g_slist_free(start);
}
}
g_object_unref(client);
return px_config_create(url, ignore);
}
bool
on_proxy_factory_instantiate(pxProxyFactory *self)
{
// If we are running in GNOME, then make sure this plugin is registered.
if (x_has_client("gnome-session", "gnome-panel", NULL))
{
g_type_init();
return px_proxy_factory_config_add(self, "gnome", PX_CONFIG_CATEGORY_SESSION,
(pxProxyFactoryPtrCallback) gconf_config_cb);
}
return false;
}
void
on_proxy_factory_destantiate(pxProxyFactory *self)
{
px_proxy_factory_config_del(self, "gnome");
// Close the GConf connection, if present
if (px_proxy_factory_misc_get(self, "gnome"))
{
g_object_unref(px_proxy_factory_misc_get(self, "gnome"));
px_proxy_factory_misc_set(self, "gnome", NULL);
}
}
|