hi, a proxy (usign gconf) patch for eds http calendar backend -- Jens Reimann <ctron dentrassi de> http://dentrassi.de ICQ: 119027938
--- calendar/backends/http/e-cal-backend-http.c.orig 2004-05-16 16:43:42.166997064 +0200 +++ calendar/backends/http/e-cal-backend-http.c 2004-05-16 17:34:13.822115432 +0200 @@ -35,6 +35,7 @@ #include <libedata-cal/e-cal-backend-sexp.h> #include <libsoup/soup-session-async.h> #include <libsoup/soup-uri.h> +#include <gconf/gconf-client.h> #include "e-cal-backend-http.h" @@ -275,6 +276,101 @@ static gboolean reload_cb (ECalBackendHttp *cbhttp); static void maybe_start_reload_timeout (ECalBackendHttp *cbhttp); +static SoupUri * +get_proxy_uri () +{ + GConfClient * conf_client = NULL; + SoupUri * uri = NULL; + gchar * uri_string = NULL; + + conf_client = gconf_client_get_default (); + + if ( !gconf_client_get_bool ( conf_client, "/system/http_proxy/use_http_proxy", NULL ) ) { + if ( conf_client ) + g_object_unref ( conf_client ); + return NULL; + } + + /* create a dummy object */ + uri = soup_uri_new ( "http://localhost" ); + + if ( uri->host ) + g_free ( uri->host ); + + uri->host = gconf_client_get_string ( conf_client, "/system/http_proxy/host", NULL ); + uri->port = gconf_client_get_int ( conf_client, "/system/http_proxy/port", NULL ); + + if ( gconf_client_get_bool ( conf_client, "/system/http_proxy/use_authentication", NULL ) ) { + uri->user = gconf_client_get_string ( conf_client, "/system/http_proxy/authentication_user", NULL ); + uri->passwd = gconf_client_get_string ( conf_client, "/system/http_proxy/authentication_password", NULL ); + } + + if ( uri ) + uri_string = soup_uri_to_string ( uri, FALSE ); + + if ( uri_string ) { + g_message ( "Proxy URI: %s\n", uri_string ); + g_free ( uri_string ); + uri_string = NULL; + } + + if ( conf_client ) + g_object_unref ( conf_client ); + + return uri; +} + +static void +assign_new_proxy ( SoupSession * session, SoupUri * proxy ) +{ + GValue * value = NULL; + + value = g_value_init ( value, G_TYPE_POINTER ); + g_value_set_pointer ( value, (gpointer)proxy ); + + g_object_set_property ( G_OBJECT(session), SOUP_SESSION_PROXY_URI, value ); + + g_value_unset ( value ); +} + +static void +update_proxy ( ECalBackendHttp *cbhttp ) +{ + if ( !cbhttp ) return; + if ( !cbhttp->priv ) return; + if ( !cbhttp->priv->soup_session ) return; + + SoupUri * uri = NULL; + + uri = get_proxy_uri (); + + /* Note: also a NULL proxy uri is ok. It simply means: "no proxy" */ + assign_new_proxy ( cbhttp->priv->soup_session, uri ); + + if ( uri ) + soup_uri_free ( uri ); +} + +static SoupSession * +create_soup_session () +{ + SoupUri * proxy_uri = NULL; + SoupSession * soup_session = NULL; + + proxy_uri = get_proxy_uri (); + + if ( proxy_uri ) { + soup_session = soup_session_async_new_with_options ( SOUP_SESSION_PROXY_URI, proxy_uri, NULL ); + } else { + soup_session = soup_session_async_new (); + } + + if ( proxy_uri ) + soup_uri_free ( proxy_uri ); + + return soup_session; +} + static gboolean begin_retrieval_cb (ECalBackendHttp *cbhttp) { @@ -297,7 +393,12 @@ /* create the Soup session if not already created */ if (!priv->soup_session) { - priv->soup_session = soup_session_async_new (); + priv->soup_session = create_soup_session (); + } else { + /* this is a little bit quick and dirty. notification using gconf would + * be a lot nicer. Anyway, it works! + */ + update_proxy ( cbhttp ); } if (priv->uri == NULL)
Attachment:
signature.asc
Description: This is a digitally signed message part