Skip to content

Commit

Permalink
Add support for GConf
Browse files Browse the repository at this point in the history
Signed-off-by: Felipe Contreras <felipe.contreras@nokia.com>
  • Loading branch information
Felipe Contreras committed Dec 30, 2010
1 parent e9011ec commit 9ac2fad
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
CC := $(CROSS_COMPILE)gcc

GCONF_CFLAGS := $(shell pkg-config --cflags gconf-2.0 gobject-2.0)
GCONF_LIBS := $(shell pkg-config --libs gconf-2.0 gobject-2.0)

CFLAGS := -O2 -ggdb -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes -ansi -std=c99

override CFLAGS += -D_GNU_SOURCE
Expand All @@ -12,7 +15,8 @@ version := $(shell ./get-version)
all:

libproxy.so: proxy.o
libproxy.so: override CFLAGS += -fPIC
libproxy.so: override CFLAGS += $(GCONF_CFLAGS) -fPIC
libproxy.so: override LIBS += $(GCONF_LIBS)
libproxy.so: override LDFLAGS += -Wl,-soname,libproxy.so.0

all: libproxy.so
Expand Down
42 changes: 40 additions & 2 deletions proxy.c
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);
}

0 comments on commit 9ac2fad

Please sign in to comment.