[evolution-data-server/account-mgmt: 10/33] Adapt address book backends to the new ESource API.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/account-mgmt: 10/33] Adapt address book backends to the new ESource API.
- Date: Wed, 7 Sep 2011 16:07:56 +0000 (UTC)
commit 9a2f223ac23ca312d37333968c0897828033c379
Author: Matthew Barnes <mbarnes redhat com>
Date: Fri Nov 12 17:46:14 2010 -0500
Adapt address book backends to the new ESource API.
addressbook/backends/file/e-book-backend-file.c | 46 ++--------
.../backends/google/e-book-backend-google.c | 60 +++++++-----
.../webdav/e-book-backend-webdav-factory.c | 11 ++-
.../backends/webdav/e-book-backend-webdav.c | 104 +++++++-------------
4 files changed, 86 insertions(+), 135 deletions(-)
---
diff --git a/addressbook/backends/file/e-book-backend-file.c b/addressbook/backends/file/e-book-backend-file.c
index 596a902..ffaeeb5 100644
--- a/addressbook/backends/file/e-book-backend-file.c
+++ b/addressbook/backends/file/e-book-backend-file.c
@@ -959,45 +959,13 @@ e_book_backend_file_stop_book_view (EBookBackend *backend,
static gchar *
e_book_backend_file_extract_path_from_source (ESource *source)
{
- gchar *filename = NULL;
- const gchar *absolute_uri;
+ const gchar *user_data_dir;
+ const gchar *uid;
- absolute_uri = e_source_peek_absolute_uri (source);
+ uid = e_source_get_uid (source);
+ user_data_dir = e_get_user_data_dir ();
- if (absolute_uri && g_str_has_prefix (absolute_uri, "local://")) {
- gchar *uri;
-
- uri = g_strconcat ("file://", absolute_uri + 8, NULL);
- filename = g_filename_from_uri (uri, NULL, NULL);
- g_free (uri);
-
- if (!g_file_test (filename, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
- g_free (filename);
- filename = NULL;
- }
- }
-
- if (!filename) {
- const gchar *user_data_dir;
- const gchar *source_dir;
- gchar *mangled_source_dir;
-
- user_data_dir = e_get_user_data_dir ();
- source_dir = e_source_peek_relative_uri (source);
-
- if (!source_dir || !g_str_equal (source_dir, "system"))
- source_dir = e_source_peek_uid (source);
-
- /* Mangle the URI to not contain invalid characters. */
- mangled_source_dir = g_strdelimit (g_strdup (source_dir), ":/", '_');
-
- filename = g_build_filename (
- user_data_dir, "addressbook", mangled_source_dir, NULL);
-
- g_free (mangled_source_dir);
- }
-
- return filename;
+ return g_build_filename (user_data_dir, "addressbook", uid, NULL);
}
static void
@@ -1441,7 +1409,7 @@ e_book_backend_file_remove (EBookBackendSync *backend,
while ((name = g_dir_read_name (dir))) {
if (select_changes (name)) {
gchar *full_path = g_build_filename (bf->priv->dirname, name, NULL);
- if (-1 == g_unlink (full_path)) {
+ if (g_unlink (full_path) == -1) {
g_warning ("failed to remove change db `%s': %s", full_path, g_strerror (errno));
}
g_free (full_path);
@@ -1451,7 +1419,7 @@ e_book_backend_file_remove (EBookBackendSync *backend,
g_dir_close (dir);
}
- if (-1 == g_rmdir (bf->priv->dirname))
+ if (g_rmdir (bf->priv->dirname) == -1)
g_warning ("failed to remove directory `%s`: %s", bf->priv->dirname, g_strerror (errno));
/* we may not have actually succeeded in removing the
diff --git a/addressbook/backends/google/e-book-backend-google.c b/addressbook/backends/google/e-book-backend-google.c
index b84d1df..25fdb26 100644
--- a/addressbook/backends/google/e-book-backend-google.c
+++ b/addressbook/backends/google/e-book-backend-google.c
@@ -27,7 +27,10 @@
#include <glib/gi18n-lib.h>
#include <libedataserver/e-proxy.h>
-#include <libebook/e-vcard.h>
+#include <libedataserver/e-source-authentication.h>
+#include <libedataserver/e-source-offline.h>
+#include <libedataserver/e-source-refresh.h>
+#include <libedataserver/e-source-security.h>
#include <libebook/e-contact.h>
#include <libedata-book/e-data-book.h>
#include <libedata-book/e-data-book-view.h>
@@ -2089,7 +2092,11 @@ e_book_backend_google_authenticate_user (EBookBackend *backend,
ECredentials *credentials)
{
EBookBackendGooglePrivate *priv = E_BOOK_BACKEND_GOOGLE (backend)->priv;
+ ESourceAuthentication *auth_extension;
+ ESource *source;
AuthenticateUserData *data;
+ const gchar *extension_name;
+ const gchar *user;
guint32 opid;
__debug__ (G_STRFUNC);
@@ -2108,11 +2115,16 @@ e_book_backend_google_authenticate_user (EBookBackend *backend,
return;
}
- if (!credentials || !e_credentials_has_key (credentials, E_CREDENTIALS_KEY_USERNAME) || !e_credentials_has_key (credentials, E_CREDENTIALS_KEY_PASSWORD)) {
+ if (!credentials || !e_credentials_has_key (credentials, E_CREDENTIALS_KEY_PASSWORD)) {
e_book_backend_notify_opened (backend, EDB_ERROR (AUTHENTICATION_REQUIRED));
return;
}
+ source = e_book_backend_get_source (backend);
+ extension_name = E_SOURCE_EXTENSION_AUTHENTICATION;
+ auth_extension = e_source_get_extension (source, extension_name);
+ user = e_source_authentication_get_user (auth_extension);
+
opid = -1;
while (g_hash_table_lookup (priv->cancellables, GUINT_TO_POINTER (opid)))
opid--;
@@ -2129,7 +2141,7 @@ e_book_backend_google_authenticate_user (EBookBackend *backend,
#ifdef HAVE_LIBGDATA_0_9
gdata_client_login_authorizer_authenticate_async (
GDATA_CLIENT_LOGIN_AUTHORIZER (priv->authorizer),
- e_credentials_peek (credentials, E_CREDENTIALS_KEY_USERNAME),
+ user,
e_credentials_peek (credentials, E_CREDENTIALS_KEY_PASSWORD),
cancellable,
(GAsyncReadyCallback) authenticate_client_login_cb,
@@ -2137,7 +2149,7 @@ e_book_backend_google_authenticate_user (EBookBackend *backend,
#else
gdata_service_authenticate_async (
priv->service,
- e_credentials_peek (credentials, E_CREDENTIALS_KEY_USERNAME),
+ user,
e_credentials_peek (credentials, E_CREDENTIALS_KEY_PASSWORD),
cancellable,
(GAsyncReadyCallback) authenticate_client_login_cb,
@@ -2165,10 +2177,13 @@ e_book_backend_google_open (EBookBackend *backend,
gboolean only_if_exists)
{
EBookBackendGooglePrivate *priv = E_BOOK_BACKEND_GOOGLE (backend)->priv;
- const gchar *refresh_interval_str, *use_ssl_str, *use_cache_str;
- guint refresh_interval;
+ ESourceOffline *offline_extension;
+ ESourceRefresh *refresh_extension;
+ ESourceSecurity *security_extension;
+ ESource *source;
+ guint interval_in_minutes;
gboolean use_ssl, use_cache;
- ESource *source = e_book_backend_get_source (backend);
+ const gchar *extension_name;
__debug__ (G_STRFUNC);
@@ -2177,24 +2192,23 @@ e_book_backend_google_open (EBookBackend *backend,
return;
}
- /* Parse various other properties */
- refresh_interval_str = e_source_get_property (source, "refresh-interval");
- use_ssl_str = e_source_get_property (source, "ssl");
- use_cache_str = e_source_get_property (source, "offline_sync");
+ source = e_data_book_get_source (book);
- refresh_interval = 3600;
- if (refresh_interval_str && sscanf (refresh_interval_str, "%u", &refresh_interval) != 1) {
- g_warning ("Could not parse refresh-interval!");
- refresh_interval = 3600;
- }
+ extension_name = E_SOURCE_EXTENSION_OFFLINE;
+ offline_extension = e_source_get_extension (source, extension_name);
+
+ extension_name = E_SOURCE_EXTENSION_REFRESH;
+ refresh_extension = e_source_get_extension (source, extension_name);
+
+ extension_name = E_SOURCE_EXTENSION_SECURITY;
+ security_extension = e_source_get_extension (source, extension_name);
+
+ interval_in_minutes =
+ e_source_refresh_get_interval_minutes (refresh_extension);
- use_ssl = TRUE;
- if (use_ssl_str && (g_ascii_strcasecmp (use_ssl_str, "false") == 0 || strcmp (use_ssl_str, "0") == 0))
- use_ssl = FALSE;
+ use_ssl = e_source_security_get_secure (security_extension);
- use_cache = TRUE;
- if (use_cache_str && (g_ascii_strcasecmp (use_cache_str, "false") == 0 || strcmp (use_cache_str, "0") == 0))
- use_cache = FALSE;
+ use_cache = e_source_offline_get_stay_synchronized (offline_extension);
/* Set up our object */
priv->groups_by_id = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
@@ -2202,7 +2216,7 @@ e_book_backend_google_open (EBookBackend *backend,
priv->cancellables = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_object_unref);
cache_init (backend, use_cache);
priv->use_ssl = use_ssl;
- priv->refresh_interval = refresh_interval;
+ priv->refresh_interval = interval_in_minutes * 60;
/* Remove and re-add the timeout */
if (priv->refresh_id != 0) {
diff --git a/addressbook/backends/webdav/e-book-backend-webdav-factory.c b/addressbook/backends/webdav/e-book-backend-webdav-factory.c
index 794a59d..9666a6c 100644
--- a/addressbook/backends/webdav/e-book-backend-webdav-factory.c
+++ b/addressbook/backends/webdav/e-book-backend-webdav-factory.c
@@ -28,16 +28,19 @@ E_BOOK_BACKEND_FACTORY_SIMPLE (webdav, Webdav, e_book_backend_webdav_new)
static GType webdav_type;
-void eds_module_initialize (GTypeModule *module)
+void
+eds_module_initialize (GTypeModule *type_module)
{
- webdav_type = _webdav_factory_get_type (module);
+ webdav_type = _webdav_factory_get_type (type_module);
}
-void eds_module_shutdown (void)
+void
+eds_module_shutdown (void)
{
}
-void eds_module_list_types (const GType **types, gint *num_types)
+void
+eds_module_list_types (const GType **types, gint *num_types)
{
*types = &webdav_type;
*num_types = 1;
diff --git a/addressbook/backends/webdav/e-book-backend-webdav.c b/addressbook/backends/webdav/e-book-backend-webdav.c
index 3f2e24f..95c69f6 100644
--- a/addressbook/backends/webdav/e-book-backend-webdav.c
+++ b/addressbook/backends/webdav/e-book-backend-webdav.c
@@ -35,6 +35,9 @@
#include <libedataserver/e-url.h>
#include <libedataserver/e-flag.h>
#include <libedataserver/e-proxy.h>
+#include <libedataserver/e-source-authentication.h>
+#include <libedataserver/e-source-offline.h>
+#include <libedataserver/e-source-webdav.h>
#include <libebook/e-contact.h>
#include <libebook/e-address-western.h>
@@ -193,14 +196,20 @@ upload_contact (EBookBackendWebdav *webdav,
gchar **reason)
{
ESource *source;
+ ESourceWebdav *webdav_extension;
SoupMessage *message;
gchar *uri;
gchar *etag;
const gchar *new_etag, *redir_uri;
gchar *request;
guint status;
- const gchar *property;
gboolean avoid_ifmatch;
+ const gchar *extension_name;
+
+ source = e_book_backend_get_source (E_BOOK_BACKEND (webdav));
+
+ extension_name = E_SOURCE_EXTENSION_WEBDAV_BACKEND;
+ webdav_extension = e_source_get_extension (source, extension_name);
source = e_book_backend_get_source (E_BOOK_BACKEND (webdav));
@@ -214,12 +223,7 @@ upload_contact (EBookBackendWebdav *webdav,
soup_message_headers_append (message->request_headers, "User-Agent", USERAGENT);
soup_message_headers_append (message->request_headers, "Connection", "close");
- property = e_source_get_property(source, "avoid_ifmatch");
- if (property != NULL && strcmp(property, "1") == 0) {
- avoid_ifmatch = TRUE;
- } else {
- avoid_ifmatch = FALSE;
- }
+ avoid_ifmatch = e_source_webdav_get_avoid_ifmatch (webdav_extension);
/* some servers (like apache < 2.2.8) don't handle If-Match, correctly so
* we can leave it out */
@@ -1172,10 +1176,19 @@ e_book_backend_webdav_authenticate_user (EBookBackend *backend,
{
EBookBackendWebdav *webdav = E_BOOK_BACKEND_WEBDAV (backend);
EBookBackendWebdavPrivate *priv = webdav->priv;
+ ESourceAuthentication *auth_extension;
+ ESource *source;
SoupMessage *message;
+ const gchar *extension_name;
+ const gchar *user;
guint status;
- priv->username = e_credentials_get (credentials, E_CREDENTIALS_KEY_USERNAME);
+ source = e_book_backend_get_source (backend);
+ extension_name = E_SOURCE_EXTENSION_AUTHENTICATION;
+ auth_extension = e_source_get_extension (source, extension_name);
+ user = e_source_authentication_get_user (auth_extension);
+
+ priv->username = g_strdup (user);
priv->password = e_credentials_get (credentials, E_CREDENTIALS_KEY_PASSWORD);
/* Evolution API requires a direct feedback on the authentication,
@@ -1238,15 +1251,14 @@ e_book_backend_webdav_open (EBookBackend *backend,
{
EBookBackendWebdav *webdav = E_BOOK_BACKEND_WEBDAV (backend);
EBookBackendWebdavPrivate *priv = webdav->priv;
- ESource *source;
- gchar *uri;
+ ESourceOffline *offline_extension;
+ ESourceWebdav *webdav_extension;
+ ESource *source;
+ const gchar *extension_name;
const gchar *cache_dir;
- const gchar *offline;
- const gchar *use_ssl;
gchar *filename;
SoupSession *session;
SoupURI *suri;
- gint port;
/* will try fetch ctag for the first time, if it fails then sets this to FALSE */
priv->supports_getctag = TRUE;
@@ -1254,70 +1266,21 @@ e_book_backend_webdav_open (EBookBackend *backend,
source = e_book_backend_get_source (backend);
cache_dir = e_book_backend_get_cache_dir (backend);
- uri = e_source_get_uri (source);
- if (uri == NULL) {
- e_book_backend_respond_opened (backend, book, opid, EDB_ERROR_EX (OTHER_ERROR, "No uri given for addressbook"));
- return;
- }
-
- suri = soup_uri_new (uri);
- g_free (uri);
+ extension_name = E_SOURCE_EXTENSION_OFFLINE;
+ offline_extension = e_source_get_extension (source, extension_name);
- if (!suri) {
- e_book_backend_respond_opened (backend, book, opid, EDB_ERROR_EX (OTHER_ERROR, "Invalid uri given for addressbook"));
- return;
- }
+ extension_name = E_SOURCE_EXTENSION_WEBDAV_BACKEND;
+ webdav_extension = e_source_get_extension (source, extension_name);
- offline = e_source_get_property(source, "offline_sync");
- if (offline && g_str_equal(offline, "1"))
- priv->marked_for_offline = TRUE;
+ priv->marked_for_offline =
+ e_source_offline_get_stay_synchronized (offline_extension);
if (!priv->is_online && !priv->marked_for_offline ) {
- soup_uri_free (suri);
e_book_backend_respond_opened (backend, book, opid, EDB_ERROR (OFFLINE_UNAVAILABLE));
return;
}
- if (!suri->scheme || !g_str_equal (suri->scheme, "webdav")) {
- /* the book is not for us */
- soup_uri_free (suri);
- e_book_backend_respond_opened (backend, book, opid, EDB_ERROR_EX (OTHER_ERROR, "Not a webdav uri"));
- return;
- }
-
- port = soup_uri_get_port (suri);
- use_ssl = e_source_get_property (source, "use_ssl");
- if (use_ssl != NULL && strcmp (use_ssl, "1") == 0) {
- soup_uri_set_scheme (suri, "https");
- } else {
- soup_uri_set_scheme (suri, "http");
- }
-
- if (port > 0 && port != soup_uri_get_port (suri))
- soup_uri_set_port (suri, port);
-
- /* append slash if missing */
- if (!suri->path || !*suri->path || suri->path[strlen (suri->path) - 1] != '/') {
- gchar *new_path = g_strconcat (suri->path ? suri->path : "", "/", NULL);
- soup_uri_set_path (suri, new_path);
- g_free (new_path);
- }
-
- if (suri->host && strchr (suri->host, '@')) {
- gchar *at = strchr (suri->host, '@');
- gchar *new_user;
-
- *at = '\0';
-
- new_user = g_strconcat (suri->user ? suri->user : "", "@", suri->host, NULL);
-
- *at = '@';
-
- soup_uri_set_host (suri, at + 1);
- soup_uri_set_user (suri, new_user);
-
- g_free (new_user);
- }
+ suri = e_source_webdav_get_soup_uri (webdav_extension);
priv->uri = soup_uri_to_string (suri, FALSE);
if (!priv->uri) {
@@ -1473,6 +1436,9 @@ e_book_backend_webdav_class_init (EBookBackendWebdavClass *klass)
object_class->dispose = e_book_backend_webdav_dispose;
g_type_class_add_private (object_class, sizeof (EBookBackendWebdavPrivate));
+
+ /* Register our ESource extension. */
+ E_TYPE_SOURCE_WEBDAV;
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]