[evolution-couchdb] Enable OAuth for desktopcouch instance when secrets available in the keyring



commit d6b2e5bd84947e740485e9ecccff49d04bcf5375
Author: Rodrigo Moya <rodrigo gnome-db org>
Date:   Wed Sep 9 16:59:34 2009 +0200

    Enable OAuth for desktopcouch instance when secrets available in the keyring

 addressbook/e-book-backend-couchdb.c |   54 ++++++++++++++++++++++++++++++++-
 configure.ac                         |    2 +-
 2 files changed, 53 insertions(+), 3 deletions(-)
---
diff --git a/addressbook/e-book-backend-couchdb.c b/addressbook/e-book-backend-couchdb.c
index fbd5b9d..0c2d56e 100644
--- a/addressbook/e-book-backend-couchdb.c
+++ b/addressbook/e-book-backend-couchdb.c
@@ -24,6 +24,7 @@
 #include <libedata-book/e-data-book.h>
 #include <libedata-book/e-data-book-view.h>
 #include <dbus/dbus-glib.h>
+#include <gnome-keyring.h>
 
 #define COUCHDB_REVISION_PROP                "X-COUCHDB-REVISION"
 #define COUCHDB_UUID_PROP                    "X-COUCHDB-UUID"
@@ -714,6 +715,8 @@ e_book_backend_couchdb_load_source (EBookBackend *backend,
 	const gchar *property;
 	CouchDBDatabaseInfo *db_info;
 	GError *error = NULL;
+	gboolean enable_oauth = FALSE;
+	char *oauth_c_key = NULL, *oauth_c_secret = NULL, *oauth_t_key = NULL, *oauth_t_secret = NULL;
 	EBookBackendCouchDB *couchdb_backend = E_BOOK_BACKEND_COUCHDB (backend);
 
 	g_return_val_if_fail (E_IS_BOOK_BACKEND_COUCHDB (couchdb_backend), GNOME_Evolution_Addressbook_OtherError);
@@ -756,9 +759,43 @@ e_book_backend_couchdb_load_source (EBookBackend *backend,
 		g_object_unref (G_OBJECT (proxy));
 		dbus_g_connection_unref (bus);
 
-		if (success)
+		if (success) {
+			GnomeKeyringAttributeList *attrs;
+			GnomeKeyringResult result;
+			GList *items_found;
+
 			uri = g_strdup_printf ("http://127.0.0.1:%d";, port);
-		else {
+
+			/* Get OAuth tokens from GnomeKeyring */
+			attrs = gnome_keyring_attribute_list_new();
+			gnome_keyring_attribute_list_append_string (attrs, "desktopcouch", "oauth");
+
+			result = gnome_keyring_find_items_sync (GNOME_KEYRING_ITEM_GENERIC_SECRET,
+								attrs, &items_found);
+			if (result == GNOME_KEYRING_RESULT_OK && items_found != NULL) {
+				gchar **items;
+				GnomeKeyringFound *first_item = (GnomeKeyringFound *) items_found->data;
+
+				items = g_strsplit (first_item->secret, ":", 4);
+				if (items) {
+					oauth_c_key = g_strdup (items[0]);
+					oauth_c_secret = g_strdup (items[1]);
+					oauth_t_key = g_strdup (items[2]);
+					oauth_t_secret = g_strdup (items[3]);
+					g_strfreev (items);
+
+					enable_oauth = TRUE;
+				}
+
+				gnome_keyring_found_list_free (items_found);
+			} else {
+				g_warning ("Could not get OAuth tokens from keyring: %s",
+					   gnome_keyring_result_to_message (result));
+			}
+
+			/* Free memory */
+			gnome_keyring_attribute_list_free (attrs);
+		} else {
 			g_warning ("Couldn't get port for desktopcouch: %s", error->message);
 			g_error_free (error);
 
@@ -775,6 +812,19 @@ e_book_backend_couchdb_load_source (EBookBackend *backend,
 		return GNOME_Evolution_Addressbook_OtherError;
 	}
 
+	if (enable_oauth) {
+		couchdb_enable_oauth (couchdb_backend->couchdb,
+				      oauth_c_key,
+				      oauth_c_secret,
+				      oauth_t_key,
+				      oauth_t_secret);
+
+		g_free (oauth_c_key);
+		g_free (oauth_c_secret);
+		g_free (oauth_t_key);
+		g_free (oauth_t_secret);
+	}
+
 	g_free (uri);
 
 	/* check if only_if_exists */
diff --git a/configure.ac b/configure.ac
index 5004f79..94cea97 100644
--- a/configure.ac
+++ b/configure.ac
@@ -34,7 +34,7 @@ localedir='$(prefix)/$(DATADIRNAME)/locale'
 AC_SUBST(localedir)
 
 dnl Check for dependencies
-PKG_CHECK_MODULES(EVOLUTION, glib-2.0 couchdb-glib-1.0 >= 0.4.5 libebook-1.2 libedata-book-1.2 dbus-glib-1)
+PKG_CHECK_MODULES(EVOLUTION, glib-2.0 couchdb-glib-1.0 >= 0.4.5 libebook-1.2 libedata-book-1.2 dbus-glib-1 gnome-keyring-1)
 AC_SUBST(EVOLUTION_CFLAGS)
 AC_SUBST(EVOLUTION_LIBS)
 



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