aboutsummaryrefslogtreecommitdiffstats
path: root/mail/em-utils.c
diff options
context:
space:
mode:
authorNot Zed <NotZed@Ximian.com>2005-01-18 13:32:19 +0800
committerMichael Zucci <zucchi@src.gnome.org>2005-01-18 13:32:19 +0800
commitc075b7d96c7c9e4bbfc32f1541c96c6a3ef538e3 (patch)
treee8d21d0b47fa689138ebee5159b33255051cb404 /mail/em-utils.c
parent5d2343810cde0d4dca4e9a18abea26ac32dbb700 (diff)
downloadgsoc2013-evolution-c075b7d96c7c9e4bbfc32f1541c96c6a3ef538e3.tar.gz
gsoc2013-evolution-c075b7d96c7c9e4bbfc32f1541c96c6a3ef538e3.tar.zst
gsoc2013-evolution-c075b7d96c7c9e4bbfc32f1541c96c6a3ef538e3.zip
kill old 'load http 0 now=0' debug.
2005-01-18 Not Zed <NotZed@Ximian.com> * em-format-html.c (emfh_gethttp): kill old 'load http 0 now=0' debug. ** See bug #70563. * em-utils.c (emu_set_proxy, emu_proxy_setup) (em_utils_get_proxy_uri): make sure the init code is called from main thread (gconf usage), and add locking for data consistency. svn path=/trunk/; revision=28424
Diffstat (limited to 'mail/em-utils.c')
-rw-r--r--mail/em-utils.c83
1 files changed, 50 insertions, 33 deletions
diff --git a/mail/em-utils.c b/mail/em-utils.c
index b5041ff8bd..0236f2e329 100644
--- a/mail/em-utils.c
+++ b/mail/em-utils.c
@@ -1319,47 +1319,63 @@ em_utils_adjustment_page(GtkAdjustment *adj, gboolean down)
/* ********************************************************************** */
static char *emu_proxy_uri;
+static int emu_proxy_init = 0;
+static pthread_mutex_t emu_proxy_lock = PTHREAD_MUTEX_INITIALIZER;
static void
-emu_set_proxy(GConfClient *client)
+emu_set_proxy(GConfClient *client, int needlock)
{
- char *server;
+ char *server, *uri = NULL;
int port;
- if (!gconf_client_get_bool(client, "/system/http_proxy/use_http_proxy", NULL)) {
- g_free(emu_proxy_uri);
- emu_proxy_uri = NULL;
+ if (gconf_client_get_bool(client, "/system/http_proxy/use_http_proxy", NULL)) {
+ server = gconf_client_get_string(client, "/system/http_proxy/host", NULL);
+ port = gconf_client_get_int(client, "/system/http_proxy/port", NULL);
- return;
- }
+ if (server && server[0]) {
+ if (gconf_client_get_bool(client, "/system/http_proxy/use_authentication", NULL)) {
+ char *user = gconf_client_get_string(client, "/system/http_proxy/authentication_user", NULL);
+ char *pass = gconf_client_get_string(client, "/system/http_proxy/authentication_password", NULL);
- /* TODO: Should lock ... */
+ uri = g_strdup_printf("http://%s:%s@%s:%d", user, pass, server, port);
+ g_free(user);
+ g_free(pass);
+ } else {
+ uri = g_strdup_printf("http://%s:%d", server, port);
+ }
+ }
- server = gconf_client_get_string(client, "/system/http_proxy/host", NULL);
- port = gconf_client_get_int(client, "/system/http_proxy/port", NULL);
+ g_free(server);
+ }
- if (server && server[0]) {
- g_free(emu_proxy_uri);
+ if (needlock)
+ pthread_mutex_lock(&emu_proxy_lock);
- if (gconf_client_get_bool(client, "/system/http_proxy/use_authentication", NULL)) {
- char *user = gconf_client_get_string(client, "/system/http_proxy/authentication_user", NULL);
- char *pass = gconf_client_get_string(client, "/system/http_proxy/authentication_password", NULL);
+ g_free(emu_proxy_uri);
+ emu_proxy_uri = uri;
- emu_proxy_uri = g_strdup_printf("http://%s:%s@%s:%d", user, pass, server, port);
- g_free(user);
- g_free(pass);
- } else {
- emu_proxy_uri = g_strdup_printf("http://%s:%d", server, port);
- }
- }
+ if (needlock)
+ pthread_mutex_unlock(&emu_proxy_lock);
- g_free(server);
}
static void
emu_proxy_changed(GConfClient *client, guint32 cnxn_id, GConfEntry *entry, gpointer user_data)
{
- emu_set_proxy(client);
+ emu_set_proxy(client, TRUE);
+}
+
+static void *
+emu_proxy_setup(void *data)
+{
+ GConfClient *client = gconf_client_get_default();
+
+ gconf_client_add_dir(client, "/system/http_proxy", GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
+ gconf_client_notify_add(client, "/system/http_proxy", emu_proxy_changed, NULL, NULL, NULL);
+ emu_set_proxy(client, FALSE);
+ g_object_unref(client);
+
+ return NULL;
}
/**
@@ -1372,19 +1388,20 @@ emu_proxy_changed(GConfClient *client, guint32 cnxn_id, GConfEntry *entry, gpoin
char *
em_utils_get_proxy_uri(void)
{
- static int init;
+ char *uri;
- if (!init) {
- GConfClient *client = gconf_client_get_default();
+ pthread_mutex_lock(&emu_proxy_lock);
- gconf_client_add_dir(client, "/system/http_proxy", GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
- gconf_client_notify_add(client, "/system/http_proxy", emu_proxy_changed, NULL, NULL, NULL);
- emu_set_proxy(client);
- g_object_unref(client);
- init = TRUE;
+ if (!emu_proxy_init) {
+ mail_call_main(MAIL_CALL_p_p, emu_proxy_setup, NULL);
+ emu_proxy_init = TRUE;
}
- return g_strdup(emu_proxy_uri);
+ uri = g_strdup(emu_proxy_uri);
+
+ pthread_mutex_unlock(&emu_proxy_lock);
+
+ return uri;
}
/**