[evolution-data-server/account-mgmt: 18/28] Add an ESource extension for the webcal backend.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/account-mgmt: 18/28] Add an ESource extension for the webcal backend.
- Date: Wed, 2 Mar 2011 03:46:32 +0000 (UTC)
commit 85d08f56f5e01157e29ee9b83b1d5831518164f5
Author: Matthew Barnes <mbarnes redhat com>
Date: Mon Nov 22 23:04:56 2010 -0500
Add an ESource extension for the webcal backend.
.../backends/http/e-cal-backend-http-factory.c | 218 +++++++++-----------
calendar/backends/http/e-cal-backend-http.c | 106 ++++++++--
2 files changed, 182 insertions(+), 142 deletions(-)
---
diff --git a/calendar/backends/http/e-cal-backend-http-factory.c b/calendar/backends/http/e-cal-backend-http-factory.c
index 840762f..33a4f35 100644
--- a/calendar/backends/http/e-cal-backend-http-factory.c
+++ b/calendar/backends/http/e-cal-backend-http-factory.c
@@ -16,18 +16,34 @@
#include "e-cal-backend-http-factory.h"
#include "e-cal-backend-http.h"
-typedef struct {
- ECalBackendFactory parent_object;
-} ECalBackendHttpFactory;
+typedef ECalBackendFactory ECalBackendHttpEventsFactory;
+typedef ECalBackendFactoryClass ECalBackendHttpEventsFactoryClass;
-typedef struct {
- ECalBackendFactoryClass parent_class;
-} ECalBackendHttpFactoryClass;
+typedef ECalBackendFactory ECalBackendHttpJournalFactory;
+typedef ECalBackendFactoryClass ECalBackendHttpJournalFactoryClass;
-static void
-e_cal_backend_http_factory_instance_init (ECalBackendHttpFactory *factory)
-{
-}
+typedef ECalBackendFactory ECalBackendHttpTodosFactory;
+typedef ECalBackendFactoryClass ECalBackendHttpTodosFactoryClass;
+
+/* Forward Declarations */
+GType e_cal_backend_http_events_factory_get_type (void);
+GType e_cal_backend_http_journal_factory_get_type (void);
+GType e_cal_backend_http_todos_factory_get_type (void);
+
+G_DEFINE_DYNAMIC_TYPE (
+ ECalBackendHttpEventsFactory,
+ e_cal_backend_http_events_factory,
+ E_TYPE_CAL_BACKEND_FACTORY)
+
+G_DEFINE_DYNAMIC_TYPE (
+ ECalBackendHttpJournalFactory,
+ e_cal_backend_http_journal_factory,
+ E_TYPE_CAL_BACKEND_FACTORY)
+
+G_DEFINE_DYNAMIC_TYPE (
+ ECalBackendHttpTodosFactory,
+ e_cal_backend_http_todos_factory,
+ E_TYPE_CAL_BACKEND_FACTORY)
static const gchar *
_get_protocol (ECalBackendFactory *factory)
@@ -35,170 +51,130 @@ _get_protocol (ECalBackendFactory *factory)
return "webcal";
}
-static ECalBackend*
-_todos_new_backend (ECalBackendFactory *factory, ESource *source)
+static icalcomponent_kind
+_events_get_kind (ECalBackendFactory *factory)
+{
+ return ICAL_VEVENT_COMPONENT;
+}
+
+static ECalBackend *
+_events_new_backend (ECalBackendFactory *factory,
+ ESource *source)
{
- return g_object_new (e_cal_backend_http_get_type (),
- "source", source,
- "kind", ICAL_VTODO_COMPONENT,
- NULL);
+ return g_object_new (
+ e_cal_backend_http_get_type (),
+ "kind", ICAL_VEVENT_COMPONENT,
+ "source", source, NULL);
}
static icalcomponent_kind
-_todos_get_kind (ECalBackendFactory *factory)
+_journal_get_kind (ECalBackendFactory *factory)
{
- return ICAL_VTODO_COMPONENT;
+ return ICAL_VJOURNAL_COMPONENT;
}
-static ECalBackend*
-_events_new_backend (ECalBackendFactory *factory, ESource *source)
+static ECalBackend *
+_journal_new_backend (ECalBackendFactory *factory,
+ ESource *source)
{
- return g_object_new (e_cal_backend_http_get_type (),
- "source", source,
- "kind", ICAL_VEVENT_COMPONENT,
- NULL);
+ return g_object_new (
+ e_cal_backend_http_get_type (),
+ "kind", ICAL_VJOURNAL_COMPONENT,
+ "source", source, NULL);
}
static icalcomponent_kind
-_events_get_kind (ECalBackendFactory *factory)
+_todos_get_kind (ECalBackendFactory *factory)
{
- return ICAL_VEVENT_COMPONENT;
+ return ICAL_VTODO_COMPONENT;
}
-static ECalBackend*
-_memos_new_backend (ECalBackendFactory *factory, ESource *source)
+static ECalBackend *
+_todos_new_backend (ECalBackendFactory *factory,
+ ESource *source)
{
- return g_object_new (e_cal_backend_http_get_type (),
- "source", source,
- "kind", ICAL_VJOURNAL_COMPONENT,
- NULL);
+ return g_object_new (
+ e_cal_backend_http_get_type (),
+ "kind", ICAL_VTODO_COMPONENT,
+ "source", source, NULL);
}
-static icalcomponent_kind
-_memos_get_kind (ECalBackendFactory *factory)
+static void
+e_cal_backend_http_events_factory_class_init (ECalBackendFactoryClass *class)
{
- return ICAL_VJOURNAL_COMPONENT;
+ class->get_protocol = _get_protocol;
+ class->get_kind = _events_get_kind;
+ class->new_backend = _events_new_backend;
}
static void
-todos_backend_factory_class_init (ECalBackendHttpFactoryClass *klass)
+e_cal_backend_http_events_factory_class_finalize (ECalBackendFactoryClass *class)
{
- E_CAL_BACKEND_FACTORY_CLASS (klass)->get_protocol = _get_protocol;
- E_CAL_BACKEND_FACTORY_CLASS (klass)->get_kind = _todos_get_kind;
- E_CAL_BACKEND_FACTORY_CLASS (klass)->new_backend = _todos_new_backend;
}
static void
-events_backend_factory_class_init (ECalBackendHttpFactoryClass *klass)
+e_cal_backend_http_events_factory_init (ECalBackendFactory *factory)
{
- E_CAL_BACKEND_FACTORY_CLASS (klass)->get_protocol = _get_protocol;
- E_CAL_BACKEND_FACTORY_CLASS (klass)->get_kind = _events_get_kind;
- E_CAL_BACKEND_FACTORY_CLASS (klass)->new_backend = _events_new_backend;
}
static void
-memos_backend_factory_class_init (ECalBackendHttpFactoryClass *klass)
+e_cal_backend_http_journal_factory_class_init (ECalBackendFactoryClass *class)
{
- E_CAL_BACKEND_FACTORY_CLASS (klass)->get_protocol = _get_protocol;
- E_CAL_BACKEND_FACTORY_CLASS (klass)->get_kind = _memos_get_kind;
- E_CAL_BACKEND_FACTORY_CLASS (klass)->new_backend = _memos_new_backend;
+ class->get_protocol = _get_protocol;
+ class->get_kind = _journal_get_kind;
+ class->new_backend = _journal_new_backend;
}
-static GType
-events_backend_factory_get_type (GTypeModule *module)
+static void
+e_cal_backend_http_journal_factory_class_finalize (ECalBackendFactoryClass *class)
{
- GType type;
-
- GTypeInfo info = {
- sizeof (ECalBackendHttpFactoryClass),
- NULL, /* base_class_init */
- NULL, /* base_class_finalize */
- (GClassInitFunc) events_backend_factory_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (ECalBackend),
- 0, /* n_preallocs */
- (GInstanceInitFunc) e_cal_backend_http_factory_instance_init
- };
-
- type = g_type_module_register_type (module,
- E_TYPE_CAL_BACKEND_FACTORY,
- "ECalBackendHttpEventsFactory",
- &info, 0);
-
- return type;
}
-static GType
-todos_backend_factory_get_type (GTypeModule *module)
+static void
+e_cal_backend_http_journal_factory_init (ECalBackendFactory *factory)
{
- GType type;
-
- GTypeInfo info = {
- sizeof (ECalBackendHttpFactoryClass),
- NULL, /* base_class_init */
- NULL, /* base_class_finalize */
- (GClassInitFunc) todos_backend_factory_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (ECalBackend),
- 0, /* n_preallocs */
- (GInstanceInitFunc) e_cal_backend_http_factory_instance_init
- };
-
- type = g_type_module_register_type (module,
- E_TYPE_CAL_BACKEND_FACTORY,
- "ECalBackendHttpTodosFactory",
- &info, 0);
-
- return type;
}
-static GType
-memos_backend_factory_get_type (GTypeModule *module)
+static void
+e_cal_backend_http_todos_factory_class_init (ECalBackendFactoryClass *class)
{
- GType type;
-
- GTypeInfo info = {
- sizeof (ECalBackendHttpFactoryClass),
- NULL, /* base_class_init */
- NULL, /* base_class_finalize */
- (GClassInitFunc) memos_backend_factory_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (ECalBackend),
- 0, /* n_preallocs */
- (GInstanceInitFunc) e_cal_backend_http_factory_instance_init
- };
-
- type = g_type_module_register_type (module,
- E_TYPE_CAL_BACKEND_FACTORY,
- "ECalBackendHttpMemosFactory",
- &info, 0);
-
- return type;
+ class->get_protocol = _get_protocol;
+ class->get_kind = _todos_get_kind;
+ class->new_backend = _todos_new_backend;
}
-
+static void
+e_cal_backend_http_todos_factory_class_finalize (ECalBackendFactoryClass *class)
+{
+}
-static GType http_types[3];
+static void
+e_cal_backend_http_todos_factory_init (ECalBackendFactory *factory)
+{
+}
void
-eds_module_initialize (GTypeModule *module)
+eds_module_initialize (GTypeModule *type_module)
{
- http_types[0] = todos_backend_factory_get_type (module);
- http_types[1] = events_backend_factory_get_type (module);
- http_types[2] = memos_backend_factory_get_type (module);
+ e_cal_backend_http_events_factory_register_type (type_module);
+ e_cal_backend_http_journal_factory_register_type (type_module);
+ e_cal_backend_http_todos_factory_register_type (type_module);
}
void
-eds_module_shutdown (void)
+eds_module_shutdown (void)
{
}
void
eds_module_list_types (const GType **types, gint *num_types)
{
+ static GType http_types[3];
+
+ http_types[0] = e_cal_backend_http_events_factory_get_type ();
+ http_types[1] = e_cal_backend_http_journal_factory_get_type ();
+ http_types[2] = e_cal_backend_http_todos_factory_get_type ();
+
*types = http_types;
- *num_types = 3;
+ *num_types = G_N_ELEMENTS (http_types);
}
diff --git a/calendar/backends/http/e-cal-backend-http.c b/calendar/backends/http/e-cal-backend-http.c
index dfcc56a..403a9eb 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>
@@ -595,11 +599,34 @@ begin_retrieval_cb (ECalBackendHttp *cbhttp)
priv->is_loading = TRUE;
if (priv->uri == NULL) {
- ESource *source = e_cal_backend_get_source (E_CAL_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;
- priv->uri = webcal_to_http_method (e_cal_backend_get_uri (E_CAL_BACKEND (cbhttp)),
- (secure_prop && g_str_equal(secure_prop, "1")));
+ source = e_cal_backend_get_source (E_CAL_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 (
+ uri_string, secure_connection);
+
+ g_free (uri_string);
}
/* create the Soup session if not already created */
@@ -679,7 +706,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;
@@ -694,10 +723,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
@@ -711,12 +744,35 @@ source_changed_cb (ESource *source, ECalBackendHttp *cbhttp)
priv = cbhttp->priv;
if (priv->uri) {
- ESource *source = e_cal_backend_get_source (E_CAL_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;
gchar *new_uri;
- new_uri = webcal_to_http_method (e_cal_backend_get_uri (E_CAL_BACKEND (cbhttp)),
- (secure_prop && g_str_equal(secure_prop, "1")));
+ source = e_cal_backend_get_source (E_CAL_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);
+
+ new_uri = webcal_to_http_method (
+ 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 */
@@ -739,6 +795,8 @@ e_cal_backend_http_open (ECalBackendSync *backend, EDataCal *cal, gboolean only_
ECalBackendHttp *cbhttp;
ECalBackendHttpPrivate *priv;
ESource *source;
+ ESourceAuthentication *auth_extension;
+ const gchar *extension_name;
gchar *tmp;
cbhttp = E_CAL_BACKEND_HTTP (backend);
@@ -750,6 +808,9 @@ e_cal_backend_http_open (ECalBackendSync *backend, EDataCal *cal, gboolean only_
source = e_cal_backend_get_source (E_CAL_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);
}
@@ -759,7 +820,7 @@ e_cal_backend_http_open (ECalBackendSync *backend, EDataCal *cal, gboolean only_
priv->uri = NULL;
g_free (tmp);
- if (e_source_get_property (source, "auth") != NULL) {
+ if (e_source_authentication_required (auth_extension)) {
if ((username == NULL || password == NULL)) {
g_propagate_error (perror, EDC_ERROR (AuthenticationRequired));
return;
@@ -814,8 +875,9 @@ e_cal_backend_http_refresh (ECalBackendSync *backend, EDataCal *cal, GError **pe
priv->reload_timeout_id = g_timeout_add (1000, (GSourceFunc) reload_cb, cbhttp);
}
-static void
-e_cal_backend_http_remove (ECalBackendSync *backend, EDataCal *cal, GError **perror)
+/* is_loaded handler for the file backend */
+static gboolean
+e_cal_backend_http_is_loaded (ECalBackend *backend)
{
ECalBackendHttp *cbhttp;
ECalBackendHttpPrivate *priv;
@@ -824,14 +886,14 @@ e_cal_backend_http_remove (ECalBackendSync *backend, EDataCal *cal, GError **per
priv = cbhttp->priv;
if (!priv->store)
- return;
+ return FALSE;
- e_cal_backend_store_remove (priv->store);
+ return TRUE;
}
-/* is_loaded handler for the file backend */
static gboolean
-e_cal_backend_http_is_loaded (ECalBackend *backend)
+e_cal_backend_http_remove (ECalBackend *backend,
+ GError **error)
{
ECalBackendHttp *cbhttp;
ECalBackendHttpPrivate *priv;
@@ -840,7 +902,9 @@ e_cal_backend_http_is_loaded (ECalBackend *backend)
priv = cbhttp->priv;
if (!priv->store)
- return FALSE;
+ return TRUE;
+
+ e_cal_backend_store_remove (priv->store);
return TRUE;
}
@@ -1426,7 +1490,6 @@ e_cal_backend_http_class_init (ECalBackendHttpClass *class)
sync_class->get_static_capabilities_sync = e_cal_backend_http_get_static_capabilities;
sync_class->open_sync = e_cal_backend_http_open;
sync_class->refresh_sync = e_cal_backend_http_refresh;
- sync_class->remove_sync = e_cal_backend_http_remove;
sync_class->create_object_sync = e_cal_backend_http_create_object;
sync_class->modify_object_sync = e_cal_backend_http_modify_object;
sync_class->remove_object_sync = e_cal_backend_http_remove_object;
@@ -1442,6 +1505,7 @@ e_cal_backend_http_class_init (ECalBackendHttpClass *class)
sync_class->get_changes_sync = e_cal_backend_http_get_changes;
backend_class->is_loaded = e_cal_backend_http_is_loaded;
+ backend_class->remove = e_cal_backend_http_remove;
backend_class->start_query = e_cal_backend_http_start_query;
backend_class->get_mode = e_cal_backend_http_get_mode;
backend_class->set_mode = e_cal_backend_http_set_mode;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]