-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Felipe Contreras <felipe.contreras@nokia.com>
- Loading branch information
Felipe Contreras
committed
Dec 30, 2010
1 parent
e9011ec
commit 9ac2fad
Showing
2 changed files
with
45 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,65 @@ | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <stdio.h> | ||
|
||
#include "proxy.h" | ||
|
||
#include <gconf/gconf-client.h> | ||
|
||
struct px_factory { | ||
GConfClient *client; | ||
}; | ||
|
||
struct px_factory *px_proxy_factory_new(void) | ||
{ | ||
struct px_factory *factory; | ||
|
||
factory = calloc(1, sizeof(*factory)); | ||
|
||
g_type_init(); | ||
|
||
factory->client = gconf_client_get_default(); | ||
|
||
return factory; | ||
} | ||
|
||
static char *get_gnome_conf(struct px_factory *factory) | ||
{ | ||
char *proxy = NULL; | ||
char *mode, *host; | ||
int port; | ||
|
||
proxy = host = NULL; | ||
|
||
mode = gconf_client_get_string(factory->client, "/system/proxy/mode", NULL); | ||
if (strcasecmp(mode, "manual") != 0) | ||
goto disabled; | ||
|
||
host = gconf_client_get_string(factory->client, "/system/http_proxy/host", NULL); | ||
port = gconf_client_get_int(factory->client, "/system/http_proxy/port", NULL); | ||
|
||
if (host && port) | ||
asprintf(&proxy, "http://%s:%u/", host, port); | ||
|
||
g_free(host); | ||
disabled: | ||
g_free(mode); | ||
return proxy; | ||
} | ||
|
||
char **px_proxy_factory_get_proxies(struct px_factory *factory, const char *url) | ||
{ | ||
char **proxies; | ||
char **proxies, *proxy; | ||
proxies = calloc(1, sizeof(*proxies)); | ||
proxies[0] = strdup("direct://"); | ||
proxy = get_gnome_conf(factory); | ||
if (!proxy) | ||
proxy = strdup("direct://"); | ||
proxies[0] = proxy; | ||
return proxies; | ||
} | ||
|
||
void px_proxy_factory_free(struct px_factory *factory) | ||
{ | ||
g_object_unref(factory->client); | ||
free(factory); | ||
} |