[couchdb-glib] Added code to retrieve DC port and oauth credentials
- From: Rodrigo Moya <rodrigo src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [couchdb-glib] Added code to retrieve DC port and oauth credentials
- Date: Fri, 8 Jan 2010 15:48:08 +0000 (UTC)
commit 44e6d039a519791c97202e2698e064649e004064
Author: Rodrigo Moya <rodrigo gnome-db org>
Date: Fri Jan 8 14:25:00 2010 +0100
Added code to retrieve DC port and oauth credentials
.gitignore | 2 +
configure.ac | 8 ++--
desktopcouch-glib/desktopcouch.c | 92 ++++++++++++++++++++++++++++++++++++++
desktopcouch-glib/desktopcouch.h | 2 +-
4 files changed, 99 insertions(+), 5 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 1e9fcd9..330190b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,6 +26,8 @@ couchdb-glib/Couchdb-1.0.gir
couchdb-glib/Couchdb-1.0.typelib
couchdb-glib/couchdb-marshal.c
couchdb-glib/couchdb-marshal.h
+desktopcouch-glib/Desktopcouch-1.0.gir
+desktopcouch-glib/Desktopcouch-1.0.typelib
gtk-doc.make
m4/gtk-doc.m4
m4/libtool.m4
diff --git a/configure.ac b/configure.ac
index d5f2b4f..6fda41d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -38,10 +38,10 @@ PKG_CHECK_MODULES(COUCHDB_GLIB, glib-2.0 gobject-2.0 json-glib-1.0 >= 0.7.4 libs
AC_SUBST(COUCHDB_GLIB_CFLAGS)
AC_SUBST(COUCHDB_GLIB_LIBS)
-dnl Needed modules for DesktopCouchDB
-PKG_CHECK_MODULES(DESKTOPCOUHDB_GLIB, gnome-keyring-1 dbus-glib-1)
-AC_SUBST(DESKTOPCOUHDB_GLIB_CFLAGS)
-AC_SUBST(DESKTOPCOUHDB_GLIB_LIBS)
+dnl Needed modules for Desktopcouch
+PKG_CHECK_MODULES(DESKTOPCOUCH_GLIB, gnome-keyring-1 dbus-glib-1)
+AC_SUBST(DESKTOPCOUCH_GLIB_CFLAGS)
+AC_SUBST(DESKTOPCOUCH_GLIB_LIBS)
LIBCOUCHDBGLIB_CURRENT=1
LIBCOUCHDBGLIB_REVISION=1
diff --git a/desktopcouch-glib/desktopcouch.c b/desktopcouch-glib/desktopcouch.c
index 710107c..c9efc90 100644
--- a/desktopcouch-glib/desktopcouch.c
+++ b/desktopcouch-glib/desktopcouch.c
@@ -19,6 +19,8 @@
* Boston, MA 02110-1301, USA.
*/
+#include <dbus/dbus-glib.h>
+#include <gnome-keyring.h>
#include "desktopcouch.h"
G_DEFINE_TYPE(Desktopcouch, desktopcouch, COUCHDB_TYPE)
@@ -52,4 +54,94 @@ desktopcouch_init (Desktopcouch *dc)
Desktopcouch *
desktopcouch_new (void)
{
+ char *uri = NULL;
+ DBusGConnection *bus;
+ DBusGProxy *proxy;
+ gint port;
+ GError *error;
+ gboolean success;
+
+ /* Get the desktopcouch port via the org.desktopcouch.CouchDB interface */
+ error = NULL;
+ bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+ if (error) {
+ g_warning ("Couldn't get session bus: %s", error->message);
+ g_error_free (error);
+
+ return NULL;
+ }
+
+ proxy = dbus_g_proxy_new_for_name (bus,
+ "org.desktopcouch.CouchDB",
+ "/",
+ "org.desktopcouch.CouchDB");
+
+ error = NULL;
+ success = dbus_g_proxy_call (proxy, "getPort", &error, G_TYPE_INVALID,
+ G_TYPE_INT, &port, G_TYPE_INVALID);
+
+ /* Free memory */
+ g_object_unref (G_OBJECT (proxy));
+ dbus_g_connection_unref (bus);
+
+ if (success) {
+ GnomeKeyringAttributeList *attrs;
+ GnomeKeyringResult result;
+ GList *items_found;
+
+ uri = g_strdup_printf ("http://127.0.0.1:%d", port);
+
+ /* 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;
+ char *oauth_c_key = NULL, *oauth_c_secret = NULL, *oauth_t_key = NULL, *oauth_t_secret = NULL;
+ Desktopcouch *dc;
+ 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);
+ }
+
+ gnome_keyring_found_list_free (items_found);
+
+ /* Enable OAuth on this connection */
+ couchdb_enable_oauth (COUCHDB (dc),
+ 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);
+
+ dc = DESKTOPCOUCH (g_object_new (DESKTOPCOUCH_TYPE, "uri", uri, NULL));
+
+ g_free (uri);
+
+ return dc;
+ } 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);
+ }
+
+ return NULL;
}
diff --git a/desktopcouch-glib/desktopcouch.h b/desktopcouch-glib/desktopcouch.h
index 365e31f..e697ee4 100644
--- a/desktopcouch-glib/desktopcouch.h
+++ b/desktopcouch-glib/desktopcouch.h
@@ -26,7 +26,7 @@
G_BEGIN_DECLS
-#define DESKTOPCOUCH_TYPE (desktopcouchdb_get_type ())
+#define DESKTOPCOUCH_TYPE (desktopcouch_get_type ())
#define DESKTOPCOUCH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DESKTOPCOUCH_TYPE, Desktopcouch))
#define DESKTOPCOUCH_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DESKTOPCOUCH_TYPE))
#define DESKTOPCOUCH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DESKTOPCOUCH_TYPE, DesktopcouchClass))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]