[evolution-data-server/account-mgmt: 17/37] Adapt calendar backends to the new ESource API.



commit 201329ecf9754c71b9707520690828ea3f3e34d5
Author: Matthew Barnes <mbarnes redhat com>
Date:   Mon Nov 22 23:04:56 2010 -0500

    Adapt calendar backends to the new ESource API.

 calendar/backends/http/e-cal-backend-http.c |  110 ++++++++++++++++++++++-----
 1 files changed, 90 insertions(+), 20 deletions(-)
---
diff --git a/calendar/backends/http/e-cal-backend-http.c b/calendar/backends/http/e-cal-backend-http.c
index e564eb9..1279f17 100644
--- a/calendar/backends/http/e-cal-backend-http.c
+++ b/calendar/backends/http/e-cal-backend-http.c
@@ -28,6 +28,10 @@
 #include <glib/gi18n-lib.h>
 #include "libedataserver/e-xml-hash-utils.h"
 #include "libedataserver/e-proxy.h"
+#include "libedataserver/e-source-authentication.h"
+#include "libedataserver/e-source-refresh.h"
+#include "libedataserver/e-source-security.h"
+#include "libedataserver/e-source-webdav.h"
 #include <libecal/e-cal-recur.h>
 #include <libecal/e-cal-util.h>
 #include <libecal/e-cal-time-util.h>
@@ -554,13 +558,24 @@ soup_authenticate (SoupSession *session,
                    gpointer data)
 {
 	ECalBackendHttpPrivate *priv;
-	ECalBackendHttp        *cbhttp;
+	ECalBackendHttp *cbhttp;
+	ESourceAuthentication *auth_extension;
+	ESource *source;
+	const gchar *extension_name;
+	const gchar *user;
 
 	cbhttp = E_CAL_BACKEND_HTTP (data);
 	priv =  cbhttp->priv;
 
-	if (!retrying && priv->credentials && e_credentials_has_key (priv->credentials, E_CREDENTIALS_KEY_USERNAME)) {
-		soup_auth_authenticate (auth, e_credentials_peek (priv->credentials, E_CREDENTIALS_KEY_USERNAME), e_credentials_peek (priv->credentials, E_CREDENTIALS_KEY_PASSWORD));
+	source = e_backend_get_source (E_BACKEND (data));
+	extension_name = E_SOURCE_EXTENSION_AUTHENTICATION;
+	auth_extension = e_source_get_extension (source, extension_name);
+	user = e_source_authentication_get_user (auth_extension);
+
+	if (!retrying && priv->credentials) {
+		soup_auth_authenticate (
+			auth, user, e_credentials_peek (
+			priv->credentials, E_CREDENTIALS_KEY_PASSWORD));
 		e_credentials_clear_peek (priv->credentials);
 	}
 }
@@ -589,12 +604,34 @@ begin_retrieval_cb (ECalBackendHttp *cbhttp)
 	priv->is_loading = TRUE;
 
 	if (priv->uri == NULL) {
-		ESource *source = e_backend_get_source (E_BACKEND (cbhttp));
-		const gchar *secure_prop = e_source_get_property (source, "use_ssl");
+		ESource *source;
+		ESourceSecurity *security_extension;
+		ESourceWebdav *webdav_extension;
+		SoupURI *soup_uri;
+		gboolean secure_connection;
+		const gchar *extension_name;
+		const gchar *method;
+		gchar *uri_string;
+
+		source = e_backend_get_source (E_BACKEND (cbhttp));
+
+		extension_name = E_SOURCE_EXTENSION_SECURITY;
+		security_extension = e_source_get_extension (source, extension_name);
+
+		extension_name = E_SOURCE_EXTENSION_WEBDAV_BACKEND;
+		webdav_extension = e_source_get_extension (source, extension_name);
+
+		method = e_source_security_get_method (security_extension);
+		secure_connection = (g_strcmp0 (method, "none") != 0);
+
+		soup_uri = e_source_webdav_get_soup_uri (webdav_extension);
+		uri_string = soup_uri_to_string (soup_uri, FALSE);
+		soup_uri_free (soup_uri);
 
 		priv->uri = webcal_to_http_method (
-			e_source_get_uri (source),
-			(secure_prop && g_str_equal(secure_prop, "1")));
+			uri_string, secure_connection);
+
+		g_free (uri_string);
 	}
 
 	/* create the Soup session if not already created */
@@ -674,7 +711,9 @@ maybe_start_reload_timeout (ECalBackendHttp *cbhttp)
 {
 	ECalBackendHttpPrivate *priv;
 	ESource *source;
-	const gchar *refresh_str;
+	ESourceRefresh *refresh_extension;
+	const gchar *extension_name;
+	guint interval_in_minutes;
 
 	priv = cbhttp->priv;
 
@@ -689,10 +728,14 @@ maybe_start_reload_timeout (ECalBackendHttp *cbhttp)
 		return;
 	}
 
-	refresh_str = e_source_get_property (source, "refresh");
+	extension_name = E_SOURCE_EXTENSION_REFRESH;
+	refresh_extension = e_source_get_extension (source, extension_name);
+
+	interval_in_minutes =
+		e_source_refresh_get_interval_minutes (refresh_extension);
 
-	priv->reload_timeout_id = g_timeout_add ((refresh_str ? atoi (refresh_str) : 30) * 60000,
-						 (GSourceFunc) reload_cb, cbhttp);
+	priv->reload_timeout_id = g_timeout_add_seconds (
+		interval_in_minutes * 60, (GSourceFunc) reload_cb, cbhttp);
 }
 
 static void
@@ -708,15 +751,34 @@ source_changed_cb (ESource *source,
 
 	if (priv->uri) {
 		ESource *source;
-		const gchar *secure_prop;
+		ESourceSecurity *security_extension;
+		ESourceWebdav *webdav_extension;
+		SoupURI *soup_uri;
+		gboolean secure_connection;
+		const gchar *extension_name;
+		const gchar *method;
+		gchar *uri_string;
 		gchar *new_uri;
 
 		source = e_backend_get_source (E_BACKEND (cbhttp));
-		secure_prop = e_source_get_property (source, "use_ssl");
+
+		extension_name = E_SOURCE_EXTENSION_SECURITY;
+		security_extension = e_source_get_extension (source, extension_name);
+
+		extension_name = E_SOURCE_EXTENSION_WEBDAV_BACKEND;
+		webdav_extension = e_source_get_extension (source, extension_name);
+
+		method = e_source_security_get_method (security_extension);
+		secure_connection = (g_strcmp0 (method, "none") != 0);
+
+		soup_uri = e_source_webdav_get_soup_uri (webdav_extension);
+		uri_string = soup_uri_to_string (soup_uri, FALSE);
+		soup_uri_free (soup_uri);
 
 		new_uri = webcal_to_http_method (
-			e_source_get_uri (source),
-			(secure_prop && g_str_equal(secure_prop, "1")));
+			uri_string, secure_connection);
+
+		g_free (uri_string);
 
 		if (new_uri && !g_str_equal (priv->uri, new_uri)) {
 			/* uri changed, do reload some time soon */
@@ -742,6 +804,8 @@ e_cal_backend_http_open (ECalBackendSync *backend,
 	ECalBackendHttp *cbhttp;
 	ECalBackendHttpPrivate *priv;
 	ESource *source;
+	ESourceAuthentication *auth_extension;
+	const gchar *extension_name;
 	gboolean online;
 	gchar *tmp;
 
@@ -756,6 +820,9 @@ e_cal_backend_http_open (ECalBackendSync *backend,
 
 	source = e_backend_get_source (E_BACKEND (backend));
 
+	extension_name = E_SOURCE_EXTENSION_AUTHENTICATION;
+	auth_extension = e_source_get_extension (source, extension_name);
+
 	if (priv->source_changed_id == 0) {
 		priv->source_changed_id = g_signal_connect (source, "changed", G_CALLBACK (source_changed_cb), cbhttp);
 	}
@@ -788,7 +855,7 @@ e_cal_backend_http_open (ECalBackendSync *backend,
 	e_cal_backend_notify_online (E_CAL_BACKEND (backend), online);
 
 	if (online) {
-		if (e_source_get_property (source, "auth")) {
+		if (e_source_authentication_required (auth_extension)) {
 			e_cal_backend_notify_auth_required (E_CAL_BACKEND (cbhttp), TRUE, priv->credentials);
 		} else if (priv->requires_auth && perror && !*perror) {
 			g_propagate_error (perror, EDC_ERROR (AuthenticationRequired));
@@ -814,7 +881,7 @@ e_cal_backend_http_authenticate_user (ECalBackendSync *backend,
 	cbhttp = E_CAL_BACKEND_HTTP (backend);
 	priv  = cbhttp->priv;
 
-	if (priv->credentials && credentials && e_credentials_equal_keys (priv->credentials, credentials, E_CREDENTIALS_KEY_USERNAME, E_CREDENTIALS_KEY_PASSWORD, NULL)) {
+	if (priv->credentials && credentials && e_credentials_equal_keys (priv->credentials, credentials, E_CREDENTIALS_KEY_PASSWORD, NULL)) {
 		g_propagate_error (error, EDC_ERROR (AuthenticationRequired));
 		return;
 	}
@@ -822,7 +889,7 @@ e_cal_backend_http_authenticate_user (ECalBackendSync *backend,
 	e_credentials_free (priv->credentials);
 	priv->credentials = NULL;
 
-	if (!credentials || !e_credentials_has_key (credentials, E_CREDENTIALS_KEY_USERNAME)) {
+	if (!credentials) {
 		g_propagate_error (error, EDC_ERROR (AuthenticationRequired));
 		return;
 	}
@@ -1220,6 +1287,7 @@ e_cal_backend_http_get_free_busy (ECalBackendSync *backend,
                                   GSList **freebusy,
                                   GError **error)
 {
+	ESourceRegistry *registry;
 	ECalBackendHttp *cbhttp;
 	ECalBackendHttpPrivate *priv;
 	gchar *address, *name;
@@ -1237,8 +1305,10 @@ e_cal_backend_http_get_free_busy (ECalBackendSync *backend,
 		return;
 	}
 
+	registry = e_backend_get_registry (E_BACKEND (backend));
+
 	if (users == NULL) {
-		if (e_cal_backend_mail_account_get_default (&address, &name)) {
+		if (e_cal_backend_mail_account_get_default (registry, &address, &name)) {
 			vfb = create_user_free_busy (cbhttp, address, name, start, end);
 			calobj = icalcomponent_as_ical_string_r (vfb);
                         *freebusy = g_slist_append (*freebusy, calobj);
@@ -1250,7 +1320,7 @@ e_cal_backend_http_get_free_busy (ECalBackendSync *backend,
 		const GSList *l;
 		for (l = users; l != NULL; l = l->next ) {
 			address = l->data;
-			if (e_cal_backend_mail_account_is_valid (address, &name)) {
+			if (e_cal_backend_mail_account_is_valid (registry, address, &name)) {
 				vfb = create_user_free_busy (cbhttp, address, name, start, end);
 				calobj = icalcomponent_as_ical_string_r (vfb);
                                 *freebusy = g_slist_append (*freebusy, calobj);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]