[tracker/miner-web: 74/77] libtracker-miner: Add TrackerMinerWeb class
- From: Adrien Bustany <abustany src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/miner-web: 74/77] libtracker-miner: Add TrackerMinerWeb class
- Date: Wed, 3 Mar 2010 12:54:55 +0000 (UTC)
commit adae8ab0ab12c9d133e44d64065f798a76597689
Author: Adrien Bustany <abustany gnome org>
Date: Fri Nov 6 15:25:19 2009 +0100
libtracker-miner: Add TrackerMinerWeb class
The TrackerMinerWeb class is a thin layer above TrackerMiner which adds
functions commonly used by miners fetching data from remote services.
configure.ac | 44 +++
data/dbus/tracker-miner-web.xml | 21 +
examples/libtracker-miner/Makefile.am | 16 +-
examples/libtracker-miner/password-provider-test.c | 56 +++
src/libtracker-miner/Makefile.am | 48 +++-
src/libtracker-miner/gnome-password-provider.c | 304 +++++++++++++++
src/libtracker-miner/keyfile-password-provider.c | 393 ++++++++++++++++++++
src/libtracker-miner/tracker-miner-0.7.vapi | 82 ++++
src/libtracker-miner/tracker-miner-web-0.7.vapi | 40 ++
src/libtracker-miner/tracker-miner-web-dbus.h | 47 +++
src/libtracker-miner/tracker-miner-web.c | 249 +++++++++++++
src/libtracker-miner/tracker-miner-web.deps.in | 1 +
src/libtracker-miner/tracker-miner-web.h | 138 +++++++
src/libtracker-miner/tracker-miner.c | 4 +-
src/libtracker-miner/tracker-password-provider.c | 131 +++++++
src/libtracker-miner/tracker-password-provider.h | 84 +++++
.../tracker-password-provider.vala | 32 ++
src/libtracker-miner/vapi/rebuild_vapi.sh | 6 +
.../vapi/tracker-miner-0.7-custom.vala | 46 +++
src/libtracker-miner/vapi/tracker-miner-0.7.deps | 1 +
src/libtracker-miner/vapi/tracker-miner-0.7.files | 1 +
.../vapi/tracker-miner-0.7.metadata | 37 ++
.../vapi/tracker-miner-0.7.namespace | 1 +
23 files changed, 1775 insertions(+), 7 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 963f3ef..fbd985d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -157,6 +157,7 @@ EDS_REQUIRED=2.25.5
LIBSTREAMANALYZER_REQUIRED=0.7.0
GEE_REQUIRED=0.3
ID3LIB_REQUIRED=3.8.3
+GNOME_KEYRING_REQUIRED=2.26
# Library Checks
PKG_CHECK_MODULES(GLIB2, [glib-2.0 >= $GLIB_REQUIRED])
@@ -761,6 +762,36 @@ fi
AM_CONDITIONAL(HAVE_UNAC, test "x$have_unac" = "xyes")
+##################################################################
+# Enable Gnome Keyring support?
+##################################################################
+
+AC_ARG_ENABLE(gnome_keyring,
+ AS_HELP_STRING([--enable-gnome-keyring],
+ [enable Gnome Keyring support to store credentials [[default=auto]]]),,
+ [enable_gnome_keyring=auto])
+
+if test "x$enable_gnome_keyring" != "xno"; then
+ PKG_CHECK_MODULES(GNOME_KEYRING,
+ [ gnome-keyring-1 >= $GNOME_KEYRING_REQUIRED ],
+ [have_gnome_keyring=yes],
+ [have_gnome_keyring=no])
+ AC_SUBST(GNOME_KEYRING_LIBS)
+ AC_SUBST(GNOME_KEYRING_CFLAGS)
+
+ if test "x$have_gnome_keyring" = "xyes"; then
+ AC_DEFINE(HAVE_GNOME_KEYRING, [], [Define if we have Gnome Keyring for password storage])
+ fi
+fi
+
+if test "x$enable_gnome_keyring" = "xyes"; then
+ if test "x$have_gnome_keyring" != "xyes"; then
+ AC_MSG_ERROR([Couldn't find Gnome Keyring >= $GNOME_KEYRING_REQUIRED.])
+ fi
+fi
+
+AM_CONDITIONAL(HAVE_GNOME_KEYRING, test "x$have_gnome_keyring" = "xyes")
+
####################################################################
# Mail miners
####################################################################
@@ -876,6 +907,19 @@ PKG_CHECK_MODULES(TRACKER_VALA,
AC_SUBST(TRACKER_VALA_CFLAGS)
AC_SUBST(TRACKER_VALA_LIBS)
+PKG_CHECK_MODULES(GNOMEKEYRING,
+ [ gnome-keyring-1 >= $GNOMEKEYRING_REQUIRED ],
+ [have_gnomekeyring=yes],
+ [have_gnomekeyring=no])
+AC_SUBST(GNOMEKEYRING_LIBS)
+AC_SUBST(GNOMEKEYRING_CFLAGS)
+
+if test "x$have_gnomekeyring" = "xyes"; then
+ AC_DEFINE(HAVE_GNOMEKEYRING, [], [Define if we have Gnome Keyring for password storage])
+fi
+
+AM_CONDITIONAL(HAVE_GNOMEKEYRING, test "x$have_gnomekeyring" = "xyes")
+
##################################################################
# Enable building tracker-status-icon?
##################################################################
diff --git a/data/dbus/tracker-miner-web.xml b/data/dbus/tracker-miner-web.xml
new file mode 100644
index 0000000..5c17a6a
--- /dev/null
+++ b/data/dbus/tracker-miner-web.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<node name="/">
+ <interface name="org.freedesktop.Tracker1.Miner.Web">
+ <method name="Authenticate">
+ <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
+ </method>
+ <method name="GetAssociationData">
+ <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
+ <arg name="result" type="a{ss}" direction="out"/>
+ </method>
+ <method name="Associate">
+ <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
+ <arg name="data" type="a{ss}" direction="in"/>
+ </method>
+ <method name="Dissociate">
+ <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
+ </method>
+ <property name="AssociationStatus" type="u" access="read"/>
+ </interface>
+</node>
diff --git a/examples/libtracker-miner/Makefile.am b/examples/libtracker-miner/Makefile.am
index 5f753ce..6e1da78 100644
--- a/examples/libtracker-miner/Makefile.am
+++ b/examples/libtracker-miner/Makefile.am
@@ -17,7 +17,7 @@ INCLUDES = \
$(DBUS_CFLAGS) \
$(UNAC_CFLAGS)
-noinst_PROGRAMS = tracker-miner-test
+noinst_PROGRAMS = tracker-miner-test password-provider-test
tracker_miner_test_SOURCES = \
tracker-miner-test.c \
@@ -36,3 +36,17 @@ tracker_miner_test_LDADD = \
$(GLIB2_LIBS) \
-lz \
-lm
+
+password_provider_test_SOURCES = \
+ password-provider-test.c
+
+password_provider_test_LDADD = \
+ $(top_builddir)/src/libtracker-miner/libtracker-miner- TRACKER_API_VERSION@.la \
+ $(DBUS_LIBS) \
+ $(GMODULE_LIBS) \
+ $(GTHREAD_LIBS) \
+ $(GIO_LIBS) \
+ $(GCOV_LIBS) \
+ $(GLIB2_LIBS) \
+ -lz \
+ -lm
diff --git a/examples/libtracker-miner/password-provider-test.c b/examples/libtracker-miner/password-provider-test.c
new file mode 100644
index 0000000..12a8097
--- /dev/null
+++ b/examples/libtracker-miner/password-provider-test.c
@@ -0,0 +1,56 @@
+#include "config.h"
+#include <libtracker-miner/tracker-password-provider.h>
+
+#define SERVICE_NAME "TestService"
+
+int main (int argc, char **argv)
+{
+ g_type_init ();
+ g_set_application_name ("PasswordBackendTest");
+
+ TrackerPasswordProvider *p = tracker_get_password_provider ();
+
+ GError *error = NULL;
+ tracker_password_provider_store_password (p, SERVICE_NAME, "This is the test service", "testUser", "testPass", &error);
+
+ if (error) {
+ g_critical ("tracker_password_provider_store: %s", error->message);
+ g_error_free (error);
+
+ return 1;
+ }
+
+ gchar *username = NULL;
+
+ gchar *password = tracker_password_provider_get_password (p, SERVICE_NAME, &username, &error);
+
+ if (error) {
+ g_critical ("tracker_password_provider_get: %s", error->message);
+ g_error_free (error);
+
+ return 1;
+ } else {
+ g_message ("Username: %s , Password:%s", username, password);
+ }
+
+ g_free (username);
+ username = NULL;
+ g_free (password);
+
+ // Also test without getting the username
+ password = tracker_password_provider_get_password (p, SERVICE_NAME, NULL, &error);
+
+ if (error) {
+ g_critical ("tracker_password_provider_get: %s", error->message);
+ g_error_free (error);
+
+ return 1;
+ } else {
+ g_message ("Username: %s , Password:%s", username, password);
+ }
+
+ g_free (username);
+ g_free (password);
+ g_free (p);
+ return 0;
+}
diff --git a/src/libtracker-miner/Makefile.am b/src/libtracker-miner/Makefile.am
index 72451ca..8e4c6c7 100644
--- a/src/libtracker-miner/Makefile.am
+++ b/src/libtracker-miner/Makefile.am
@@ -17,7 +17,8 @@ INCLUDES = \
$(HAL_CFLAGS) \
$(DEVKIT_POWER_CFLAGS) \
$(DBUS_CFLAGS) \
- $(UNAC_CFLAGS)
+ $(UNAC_CFLAGS) \
+ --include $(top_srcdir)/config.h
lib_LTLIBRARIES = libtracker-miner- TRACKER_API_VERSION@.la
@@ -36,6 +37,8 @@ libtracker_miner_ TRACKER_API_VERSION@_la_SOURCES = \
tracker-miner-dbus.h \
tracker-miner-fs.c \
tracker-miner-fs.h \
+ tracker-miner-web.c \
+ tracker-miner-web.h \
tracker-miner-manager.c \
tracker-miner-manager.h \
tracker-monitor.c \
@@ -43,8 +46,9 @@ libtracker_miner_ TRACKER_API_VERSION@_la_SOURCES = \
tracker-storage.c \
tracker-storage.h \
tracker-utils.c \
- tracker-utils.h \
- tracker-thumbnailer.c
+ tracker-thumbnailer.c \
+ tracker-utils.h \
+ tracker-password-provider.c
libtracker_minerinclude_HEADERS = \
tracker-crawler.h \
@@ -54,6 +58,8 @@ libtracker_minerinclude_HEADERS = \
tracker-miner-manager.h \
tracker-storage.h \
tracker-thumbnailer.h
+ tracker-miner-web.h \
+ tracker-password-provider.h
libtracker_miner_ TRACKER_API_VERSION@_la_LDFLAGS = \
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
@@ -74,6 +80,28 @@ libtracker_miner_ TRACKER_API_VERSION@_la_LIBADD = \
$(GLIB2_LIBS) \
$(GDKPIXBUF_LIBS)
+if HAVE_GNOME_KEYRING
+libtracker_miner_ TRACKER_API_VERSION@_la_SOURCES += \
+ gnome-password-provider.c
+
+libtracker_miner_ TRACKER_API_VERSION@_la_LIBADD += \
+ $(GNOME_KEYRING_LIBS)
+
+INCLUDES += \
+ $(GNOME_KEYRING_CFLAGS)
+else
+libtracker_miner_ TRACKER_API_VERSION@_la_SOURCES += \
+ keyfile-password-provider.c
+endif
+
+vapidir=$(datadir)/vala/vapi
+vapi_DATA = \
+ tracker-miner-$(TRACKER_API_VERSION).vapi
+
+tracker-miner-web-$(TRACKER_API_VERSION).deps: tracker-miner-web.deps.in
+ @sed -e "s|@VERSION[ ]|${TRACKER_API_VERSION}|" $< > $@
+
+
tracker-marshal.h: tracker-marshal.list
$(AM_V_GEN)$(GLIB_GENMARSHAL) $< --prefix=tracker_marshal --header > $@
@@ -87,15 +115,27 @@ marshal_sources = \
dbus_sources = \
tracker-miner-glue.h \
+ tracker-miner-web-glue.h \
tracker-miner-client.h
+# Custom rule to avoid API duplication. There is also a workaround for bug
+# in dbus-binding-tool where it generates bad code when two files are passed
+# on the command line (though the man page says it supports it)
+# This bug is reported at https://bugs.freedesktop.org/show_bug.cgi?id=25056
+tracker-miner-web-glue.h: $(top_srcdir)/data/dbus/tracker-miner-web.xml $(top_srcdir)/data/dbus/tracker-miner.xml
+ echo '<?xml version="1.0" encoding="UTF-8"?>' > $(top_srcdir)/src/libtracker-miner/tracker-miner-web-full.xml
+ echo '<node name="/">' >> $(top_srcdir)/src/libtracker-miner/tracker-miner-web-full.xml
+ cat $^ | grep -v -e '<node' -e '<?xml' -e '</node>' >> $(top_srcdir)/src/libtracker-miner/tracker-miner-web-full.xml
+ echo '</node>' >> $(top_srcdir)/src/libtracker-miner/tracker-miner-web-full.xml
+ $(AM_V_GEN)$(DBUSBINDINGTOOL) --mode=glib-server --output=$@ --prefix=tracker_miner_web_dbus $(top_srcdir)/src/libtracker-miner/tracker-miner-web-full.xml
+
%-glue.h: $(top_srcdir)/data/dbus/%.xml
$(AM_V_GEN)$(DBUSBINDINGTOOL) --mode=glib-server --output=$@ --prefix=$(subst -,_,$*) $^
%-client.h: $(top_srcdir)/data/dbus/%.xml
$(AM_V_GEN)$(DBUSBINDINGTOOL) --mode=glib-client --output=$@ --prefix=$(subst -,_,$*) $^
-BUILT_SOURCES = $(dbus_sources) $(marshal_sources)
+BUILT_SOURCES = $(dbus_sources) $(marshal_sources) tracker-miner-web-full.xml
CLEANFILES = $(BUILT_SOURCES)
diff --git a/src/libtracker-miner/gnome-password-provider.c b/src/libtracker-miner/gnome-password-provider.c
new file mode 100644
index 0000000..96dbb89
--- /dev/null
+++ b/src/libtracker-miner/gnome-password-provider.c
@@ -0,0 +1,304 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2009, Adrien Bustany (abustany gnome org)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <glib-object.h>
+#include <gnome-keyring.h>
+
+#include "tracker-password-provider.h"
+
+#define TRACKER_TYPE_PASSWORD_PROVIDER_GNOME (tracker_password_provider_gnome_get_type())
+#define TRACKER_PASSWORD_PROVIDER_GNOME(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_PASSWORD_PROVIDER_GNOME, TrackerPasswordProviderGnome))
+#define TRACKER_PASSWORD_PROVIDER_GNOME_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), TRACKER_TYPE_PASSWORD_PROVIDER_GNOME, TrackerPasswordProviderGnomeClass))
+#define TRACKER_IS_PASSWORD_PROVIDER_GNOME(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_PASSWORD_PROVIDER_GNOME))
+#define TRACKER_IS_PASSWORD_PROVIDER_GNOME_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), TRACKER_TYPE_PASSWORD_PROVIDER_GNOME))
+#define TRACKER_PASSWORD_PROVIDER_GNOME_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_PASSWORD_PROVIDER_GNOME, TrackerPasswordProviderGnomeClass))
+
+#define TRACKER_PASSWORD_PROVIDER_GNOME_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRACKER_TYPE_PASSWORD_PROVIDER_GNOME, TrackerPasswordProviderGnomePrivate))
+
+#define PASSWORD_PROVIDER_GNOME_NAME "Gnome keyring"
+
+typedef struct TrackerPasswordProviderGnome TrackerPasswordProviderGnome;
+typedef struct TrackerPasswordProviderGnomeClass TrackerPasswordProviderGnomeClass;
+typedef struct TrackerPasswordProviderGnomePrivate TrackerPasswordProviderGnomePrivate;
+
+struct TrackerPasswordProviderGnome {
+ GObject parent_instance;
+ TrackerPasswordProviderGnomePrivate *private;
+};
+
+struct TrackerPasswordProviderGnomeClass {
+ GObjectClass parent_class;
+};
+
+struct TrackerPasswordProviderGnomePrivate {
+ gchar *name;
+};
+
+const GnomeKeyringPasswordSchema password_schema = {
+ GNOME_KEYRING_ITEM_GENERIC_SECRET,
+ {
+ { "service", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
+ { "username", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
+ { NULL, 0 }
+ }
+};
+
+enum {
+ PROP_0,
+ PROP_NAME
+};
+
+GType tracker_password_provider_gnome_get_type (void) G_GNUC_CONST;
+
+static void tracker_password_provider_iface_init (TrackerPasswordProviderIface *iface);
+static void password_provider_gnome_constructed (GObject *object);
+static void password_provider_gnome_finalize (GObject *object);
+static void password_provider_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void password_provider_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+
+void password_provider_gnome_store (TrackerPasswordProvider *provider,
+ const gchar *service,
+ const gchar *description,
+ const gchar *username,
+ const gchar *password,
+ GError **error);
+gchar* password_provider_gnome_get (TrackerPasswordProvider *provider,
+ const gchar *service,
+ gchar **username,
+ GError **error);
+void password_provider_gnome_forget (TrackerPasswordProvider *provider,
+ const gchar *service,
+ GError **error);
+
+G_DEFINE_TYPE_WITH_CODE (TrackerPasswordProviderGnome,
+ tracker_password_provider_gnome,
+ G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (TRACKER_TYPE_PASSWORD_PROVIDER,
+ tracker_password_provider_iface_init))
+
+static void
+tracker_password_provider_gnome_class_init (TrackerPasswordProviderGnomeClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = password_provider_gnome_finalize;
+ object_class->constructed = password_provider_gnome_constructed;
+ object_class->set_property = password_provider_set_property;
+ object_class->get_property = password_provider_get_property;
+
+ g_object_class_override_property (object_class,
+ PROP_NAME,
+ "name");
+ g_type_class_add_private (object_class,
+ sizeof (TrackerPasswordProviderGnomePrivate));
+}
+
+static void
+tracker_password_provider_gnome_init (TrackerPasswordProviderGnome *provider)
+{
+ TrackerPasswordProviderGnomePrivate *priv;
+
+ priv = TRACKER_PASSWORD_PROVIDER_GNOME_GET_PRIVATE (provider);
+}
+
+static void
+tracker_password_provider_iface_init (TrackerPasswordProviderIface *iface)
+{
+ iface->store_password = password_provider_gnome_store;
+ iface->get_password = password_provider_gnome_get;
+ iface->forget_password = password_provider_gnome_forget;
+}
+
+static void
+password_provider_gnome_constructed (GObject *object)
+{
+}
+
+static void
+password_provider_gnome_finalize (GObject *object)
+{
+ G_OBJECT_CLASS (tracker_password_provider_gnome_parent_class)->finalize (object);
+}
+
+static void
+password_provider_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ TrackerPasswordProviderGnome *gnome_provider = TRACKER_PASSWORD_PROVIDER_GNOME (object);
+ TrackerPasswordProviderGnomePrivate *priv = TRACKER_PASSWORD_PROVIDER_GNOME_GET_PRIVATE (gnome_provider);
+
+ switch (prop_id) {
+ case PROP_NAME:
+ g_free (priv->name);
+ priv->name = g_value_dup_string (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ };
+}
+
+static void
+password_provider_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ TrackerPasswordProviderGnome *gnome_provider = TRACKER_PASSWORD_PROVIDER_GNOME (object);
+ TrackerPasswordProviderGnomePrivate *priv = TRACKER_PASSWORD_PROVIDER_GNOME_GET_PRIVATE (gnome_provider);
+
+ switch (prop_id) {
+ case PROP_NAME:
+ g_value_set_string (value, priv->name);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ };
+}
+
+void
+password_provider_gnome_store (TrackerPasswordProvider *provider,
+ const gchar *service,
+ const gchar *description,
+ const gchar *username,
+ const gchar *password,
+ GError **error)
+{
+ GnomeKeyringResult r = gnome_keyring_store_password_sync (&password_schema,
+ NULL,
+ description,
+ password,
+ "service", service,
+ "username", username,
+ NULL);
+ if (r != GNOME_KEYRING_RESULT_OK) {
+ g_set_error_literal (error,
+ TRACKER_PASSWORD_PROVIDER_ERROR,
+ TRACKER_PASSWORD_PROVIDER_ERROR_SERVICE,
+ "Cannot store password in Gnome keyring");
+ }
+}
+
+gchar*
+password_provider_gnome_get (TrackerPasswordProvider *provider,
+ const gchar *service,
+ gchar **username,
+ GError **error)
+{
+ gchar *password;
+ GnomeKeyringAttributeList *search_attributes;
+ GList *found_items = NULL;
+
+ GnomeKeyringAttribute service_attr = {
+ "service",
+ GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
+ { service }
+ };
+
+ search_attributes = g_array_sized_new (FALSE,
+ FALSE,
+ sizeof (GnomeKeyringAttribute),
+ 1);
+
+ g_array_append_val (search_attributes, service_attr);
+
+ GnomeKeyringResult r = gnome_keyring_find_items_sync (GNOME_KEYRING_ITEM_GENERIC_SECRET,
+ search_attributes,
+ &found_items);
+
+ if (r != GNOME_KEYRING_RESULT_OK) {
+ if (r == GNOME_KEYRING_RESULT_NO_MATCH) {
+ g_set_error_literal (error,
+ TRACKER_PASSWORD_PROVIDER_ERROR,
+ TRACKER_PASSWORD_PROVIDER_ERROR_NOTFOUND,
+ "Password not found");
+ } else {
+ g_set_error (error,
+ TRACKER_PASSWORD_PROVIDER_ERROR,
+ TRACKER_PASSWORD_PROVIDER_ERROR_SERVICE,
+ "Keyring error: %s",
+ gnome_keyring_result_to_message (r));
+ }
+
+ gnome_keyring_found_list_free (found_items);
+ return NULL;
+ }
+
+ GnomeKeyringFound *found = (GnomeKeyringFound *)(g_list_first (found_items));
+
+ /* Walk through all attributes and select the ones we're interested in */
+ gint i;
+ for (i = 0 ; i < found->attributes->len ; ++i) {
+ GnomeKeyringAttribute *attr = &g_array_index (found->attributes, GnomeKeyringAttribute, i);
+ if (g_strcmp0 (attr->name, "username") && username) {
+ *username = g_strdup (attr->value.string);
+ }
+ }
+
+ password = g_strdup (found->secret);
+
+ gnome_keyring_found_list_free (found_items);
+
+ return password;
+}
+
+void
+password_provider_gnome_forget (TrackerPasswordProvider *provider,
+ const gchar *service,
+ GError **error)
+{
+ GnomeKeyringResult r = gnome_keyring_delete_password_sync (&password_schema,
+ "service", service,
+ NULL);
+
+ if (r != GNOME_KEYRING_RESULT_OK) {
+ g_set_error (error,
+ TRACKER_PASSWORD_PROVIDER_ERROR,
+ TRACKER_PASSWORD_PROVIDER_ERROR_SERVICE,
+ "Cannot delete password: %s",
+ gnome_keyring_result_to_message (r));
+ }
+}
+
+const TrackerPasswordProvider*
+tracker_get_password_provider (void)
+{
+ static TrackerPasswordProvider *instance = NULL;
+
+ if (instance == NULL) {
+ instance = g_object_new (TRACKER_TYPE_PASSWORD_PROVIDER_GNOME,
+ "name", PASSWORD_PROVIDER_GNOME_NAME,
+ NULL);
+ }
+
+ g_assert (instance != NULL);
+
+ return instance;
+}
+
diff --git a/src/libtracker-miner/keyfile-password-provider.c b/src/libtracker-miner/keyfile-password-provider.c
new file mode 100644
index 0000000..d52c9e2
--- /dev/null
+++ b/src/libtracker-miner/keyfile-password-provider.c
@@ -0,0 +1,393 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2009, Adrien Bustany (abustany gnome org)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <glib-object.h>
+
+#include "tracker-password-provider.h"
+
+#define TRACKER_TYPE_PASSWORD_PROVIDER_KEYFILE (tracker_password_provider_keyfile_get_type())
+#define TRACKER_PASSWORD_PROVIDER_KEYFILE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_PASSWORD_PROVIDER_KEYFILE, TrackerPasswordProviderKeyfile))
+#define TRACKER_PASSWORD_PROVIDER_KEYFILE_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), TRACKER_TYPE_PASSWORD_PROVIDER_KEYFILE, TrackerPasswordProviderKeyfileClass))
+#define TRACKER_IS_PASSWORD_PROVIDER_KEYFILE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_PASSWORD_PROVIDER_KEYFILE))
+#define TRACKER_IS_PASSWORD_PROVIDER_KEYFILE_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), TRACKER_TYPE_PASSWORD_PROVIDER_KEYFILE))
+#define TRACKER_PASSWORD_PROVIDER_KEYFILE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_PASSWORD_PROVIDER_KEYFILE, TrackerPasswordProviderKeyfileClass))
+
+#define TRACKER_PASSWORD_PROVIDER_KEYFILE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRACKER_TYPE_PASSWORD_PROVIDER_KEYFILE, TrackerPasswordProviderKeyfilePrivate))
+
+#define PASSWORD_PROVIDER_KEYFILE_NAME "KeyFile"
+
+/* GKeyFile settings */
+#define KEYFILE_FILENAME "passwords.cfg"
+#define GROUP_GENERAL "General"
+
+typedef struct TrackerPasswordProviderKeyfile TrackerPasswordProviderKeyfile;
+typedef struct TrackerPasswordProviderKeyfileClass TrackerPasswordProviderKeyfileClass;
+typedef struct TrackerPasswordProviderKeyfilePrivate TrackerPasswordProviderKeyfilePrivate;
+
+struct TrackerPasswordProviderKeyfile {
+ GObject parent_instance;
+ TrackerPasswordProviderKeyfilePrivate *private;
+};
+
+struct TrackerPasswordProviderKeyfileClass {
+ GObjectClass parent_class;
+};
+
+struct TrackerPasswordProviderKeyfilePrivate {
+ gchar *name;
+ GKeyFile *password_file;
+};
+
+enum {
+ PROP_0,
+ PROP_NAME
+};
+
+GType tracker_password_provider_keyfile_get_type (void) G_GNUC_CONST;
+
+static void tracker_password_provider_iface_init (TrackerPasswordProviderIface *iface);
+static void password_provider_keyfile_constructed (GObject *object);
+static void password_provider_keyfile_finalize (GObject *object);
+static void password_provider_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void password_provider_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+
+void password_provider_keyfile_store (TrackerPasswordProvider *provider,
+ const gchar *service,
+ const gchar *description,
+ const gchar *username,
+ const gchar *password,
+ GError **error);
+gchar* password_provider_keyfile_get (TrackerPasswordProvider *provider,
+ const gchar *service,
+ gchar **username,
+ GError **error);
+void password_provider_keyfile_forget (TrackerPasswordProvider *provider,
+ const gchar *service,
+ GError **error);
+
+static void load_password_file (TrackerPasswordProviderKeyfile *kf);
+static gboolean save_password_file (TrackerPasswordProviderKeyfile *kf);
+
+G_DEFINE_TYPE_WITH_CODE (TrackerPasswordProviderKeyfile,
+ tracker_password_provider_keyfile,
+ G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (TRACKER_TYPE_PASSWORD_PROVIDER,
+ tracker_password_provider_iface_init))
+
+static void
+tracker_password_provider_keyfile_class_init (TrackerPasswordProviderKeyfileClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = password_provider_keyfile_finalize;
+ object_class->constructed = password_provider_keyfile_constructed;
+ object_class->set_property = password_provider_set_property;
+ object_class->get_property = password_provider_get_property;
+
+ g_object_class_override_property (object_class,
+ PROP_NAME,
+ "name");
+ g_type_class_add_private (object_class,
+ sizeof (TrackerPasswordProviderKeyfilePrivate));
+}
+
+static void
+tracker_password_provider_keyfile_init (TrackerPasswordProviderKeyfile *provider)
+{
+ TrackerPasswordProviderKeyfilePrivate *priv;
+
+ priv = TRACKER_PASSWORD_PROVIDER_KEYFILE_GET_PRIVATE (provider);
+}
+
+static void
+tracker_password_provider_iface_init (TrackerPasswordProviderIface *iface)
+{
+ iface->store_password = password_provider_keyfile_store;
+ iface->get_password = password_provider_keyfile_get;
+ iface->forget_password = password_provider_keyfile_forget;
+}
+
+static void
+password_provider_keyfile_constructed (GObject *object)
+{
+ TrackerPasswordProviderKeyfile *kf = TRACKER_PASSWORD_PROVIDER_KEYFILE (object);
+ TrackerPasswordProviderKeyfilePrivate *priv = TRACKER_PASSWORD_PROVIDER_KEYFILE_GET_PRIVATE (kf);
+
+ priv->password_file = g_key_file_new ();
+
+ load_password_file (kf);
+}
+
+static void
+password_provider_keyfile_finalize (GObject *object)
+{
+ TrackerPasswordProviderKeyfile *kf = TRACKER_PASSWORD_PROVIDER_KEYFILE (object);
+ TrackerPasswordProviderKeyfilePrivate *priv = TRACKER_PASSWORD_PROVIDER_KEYFILE_GET_PRIVATE (kf);
+
+ g_key_file_free (priv->password_file);
+
+ G_OBJECT_CLASS (tracker_password_provider_keyfile_parent_class)->finalize (object);
+}
+
+static void
+password_provider_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ TrackerPasswordProviderKeyfile *kf = TRACKER_PASSWORD_PROVIDER_KEYFILE (object);
+ TrackerPasswordProviderKeyfilePrivate *priv = TRACKER_PASSWORD_PROVIDER_KEYFILE_GET_PRIVATE (kf);
+
+ switch (prop_id) {
+ case PROP_NAME:
+ g_free (priv->name);
+ priv->name = g_value_dup_string (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ };
+}
+
+static void
+password_provider_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ TrackerPasswordProviderKeyfile *kf = TRACKER_PASSWORD_PROVIDER_KEYFILE (object);
+ TrackerPasswordProviderKeyfilePrivate *priv = TRACKER_PASSWORD_PROVIDER_KEYFILE_GET_PRIVATE (kf);
+
+ switch (prop_id) {
+ case PROP_NAME:
+ g_value_set_string (value, priv->name);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ };
+}
+
+void
+password_provider_keyfile_store (TrackerPasswordProvider *provider,
+ const gchar *service,
+ const gchar *description,
+ const gchar *username,
+ const gchar *password,
+ GError **error)
+{
+ TrackerPasswordProviderKeyfile *kf = TRACKER_PASSWORD_PROVIDER_KEYFILE (provider);
+ TrackerPasswordProviderKeyfilePrivate *priv = TRACKER_PASSWORD_PROVIDER_KEYFILE_GET_PRIVATE (kf);
+
+ g_key_file_set_string (priv->password_file,
+ service,
+ "description",
+ description);
+ g_key_file_set_string (priv->password_file,
+ service,
+ "username",
+ username);
+ g_key_file_set_string (priv->password_file,
+ service,
+ "password",
+ password);
+
+ if (!save_password_file (kf)) {
+ g_set_error_literal (error,
+ TRACKER_PASSWORD_PROVIDER_ERROR,
+ TRACKER_PASSWORD_PROVIDER_ERROR_SERVICE,
+ "Cannot write password file");
+ }
+}
+
+gchar*
+password_provider_keyfile_get (TrackerPasswordProvider *provider,
+ const gchar *service,
+ gchar **username,
+ GError **error)
+{
+ TrackerPasswordProviderKeyfile *kf = TRACKER_PASSWORD_PROVIDER_KEYFILE (provider);
+ TrackerPasswordProviderKeyfilePrivate *priv = TRACKER_PASSWORD_PROVIDER_KEYFILE_GET_PRIVATE (kf);
+
+ gchar *password;
+
+ GError *e1 = NULL;
+ GError *e2 = NULL;
+
+ password = g_key_file_get_string (priv->password_file,
+ service,
+ "password",
+ &e1);
+
+ if (username) {
+ *username = g_key_file_get_string (priv->password_file,
+ service,
+ "username",
+ &e2);
+ }
+
+ if (e1 || e2) {
+ g_set_error_literal (error,
+ TRACKER_PASSWORD_PROVIDER_ERROR,
+ TRACKER_PASSWORD_PROVIDER_ERROR_NOTFOUND,
+ "Password not found");
+ }
+
+ if (e1)
+ g_error_free (e1);
+ if (e2)
+ g_error_free (e2);
+
+ return password;
+}
+
+void
+password_provider_keyfile_forget (TrackerPasswordProvider *provider,
+ const gchar *service,
+ GError **error)
+{
+ TrackerPasswordProviderKeyfile *kf = TRACKER_PASSWORD_PROVIDER_KEYFILE (provider);
+ TrackerPasswordProviderKeyfilePrivate *priv = TRACKER_PASSWORD_PROVIDER_KEYFILE_GET_PRIVATE (kf);
+
+ GError *e = NULL;
+
+ if (!g_key_file_remove_group (priv->password_file, service, &e)) {
+ g_warning ("Cannot remove group '%s' from password file: %s",
+ service,
+ e->message);
+ g_error_free (e);
+
+ g_set_error_literal (error,
+ TRACKER_PASSWORD_PROVIDER_ERROR,
+ TRACKER_PASSWORD_PROVIDER_ERROR_NOTFOUND,
+ "Service not found");
+ }
+}
+
+const TrackerPasswordProvider*
+tracker_get_password_provider (void)
+{
+ static TrackerPasswordProvider *instance = NULL;
+
+ if (instance == NULL) {
+ instance = g_object_new (TRACKER_TYPE_PASSWORD_PROVIDER_KEYFILE,
+ "name", PASSWORD_PROVIDER_KEYFILE_NAME,
+ NULL);
+ }
+
+ g_assert (instance != NULL);
+
+ return instance;
+}
+
+/* Copied from tracker-config-file.c */
+static gchar *
+config_dir_ensure_exists_and_return (void)
+{
+ gchar *directory;
+
+ directory = g_build_filename (g_get_user_config_dir (),
+ "tracker",
+ NULL);
+
+ if (!g_file_test (directory, G_FILE_TEST_EXISTS)) {
+ g_print ("Creating config directory:'%s'\n", directory);
+
+ if (g_mkdir_with_parents (directory, 0700) == -1) {
+ g_critical ("Could not create configuration directory");
+ g_free (directory);
+ return NULL;
+ }
+ }
+
+ return directory;
+}
+
+static void
+load_password_file (TrackerPasswordProviderKeyfile *kf)
+{
+ TrackerPasswordProviderKeyfilePrivate *priv = TRACKER_PASSWORD_PROVIDER_KEYFILE_GET_PRIVATE (kf);
+ gchar *filename;
+ gchar *directory;
+
+ GError *error = NULL;
+
+ directory = config_dir_ensure_exists_and_return ();
+ if (!directory) {
+ return;
+ }
+
+ filename = g_build_filename (directory, KEYFILE_FILENAME, NULL);
+ g_free (directory);
+
+ if (!g_file_test (filename, G_FILE_TEST_EXISTS)) {
+ return;
+ }
+
+ g_key_file_load_from_file (priv->password_file,
+ filename,
+ G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
+ &error);
+
+ if (error) {
+ g_critical ("Cannot load password file: %s", error->message);
+ g_error_free (error);
+ }
+}
+
+static gboolean
+save_password_file (TrackerPasswordProviderKeyfile *kf)
+{
+ TrackerPasswordProviderKeyfilePrivate *priv = TRACKER_PASSWORD_PROVIDER_KEYFILE_GET_PRIVATE (kf);
+ gchar *filename;
+ gchar *directory;
+ gchar *data;
+ gsize size;
+
+ GError *error = NULL;
+
+ directory = config_dir_ensure_exists_and_return ();
+ if (!directory) {
+ return FALSE;
+ }
+
+ filename = g_build_filename (directory, KEYFILE_FILENAME, NULL);
+ g_free (directory);
+
+ data = g_key_file_to_data (priv->password_file, &size, NULL);
+
+ g_file_set_contents (filename, data, size, &error);
+ g_free (data);
+ g_free (filename);
+
+ if (error) {
+ g_warning ("Couldn't write password file : %s", error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+
+ return TRUE;
+}
diff --git a/src/libtracker-miner/tracker-miner-0.7.vapi b/src/libtracker-miner/tracker-miner-0.7.vapi
new file mode 100644
index 0000000..eae382d
--- /dev/null
+++ b/src/libtracker-miner/tracker-miner-0.7.vapi
@@ -0,0 +1,82 @@
+/* tracker-miner-0.7.vapi generated by vapigen, do not modify. */
+
+[CCode (cprefix = "Tracker", lower_case_cprefix = "tracker_")]
+namespace Tracker {
+ [CCode (cheader_filename = "libtracker-miner/tracker-miner.h")]
+ public class Miner : GLib.Object {
+ public async void commit (GLib.Cancellable? cancellable = null) throws GLib.Error;
+ public static GLib.Quark error_quark ();
+ public async void execute_batch_update (string sparql, GLib.Cancellable? cancellable = null) throws GLib.Error;
+ public async unowned GLib.PtrArray execute_sparql (string sparql, GLib.Cancellable? cancellable = null) throws GLib.Error;
+ public async void execute_update (string sparql, GLib.Cancellable? cancellable = null) throws GLib.Error;
+ public bool is_started ();
+ public int pause (string reason) throws GLib.Error;
+ public virtual void paused ();
+ public bool resume (int cookie) throws GLib.Error;
+ public virtual void resumed ();
+ public void start ();
+ public virtual void started ();
+ public void stop ();
+ public virtual void stopped ();
+ public virtual void writeback ([CCode (array_length = false)] string[] subjects);
+ public signal void error (GLib.Error e);
+ }
+ [CCode (ref_function = "tracker_miner_fs_ref", unref_function = "tracker_miner_fs_unref", cheader_filename = "libtracker-miner/tracker-miner-fs.h")]
+ public class MinerFS {
+ public void add_directory (GLib.File file, bool recurse);
+ public void add_file (GLib.File file);
+ public virtual bool check_directory (GLib.File directory);
+ public virtual bool check_directory_contents (GLib.File directory, GLib.List<GLib.File> children);
+ public virtual bool check_file (GLib.File file);
+ public double get_throttle ();
+ public virtual bool monitor_directory (GLib.File directory);
+ public void notify_file (GLib.File file, GLib.Error error);
+ public bool remove_directory (GLib.File file);
+ public void set_throttle (double throttle);
+ public signal void finished (double elapsed, uint directories_found, uint directories_ignored, uint files_found, uint files_ignored);
+ }
+ [CCode (cheader_filename = "libtracker-miner/tracker-miner-web.h")]
+ public class MinerWeb : Tracker.Miner {
+ public virtual void associate (GLib.HashTable association_data) throws Tracker.MinerWebError;
+ public virtual Tracker.MinerWebAssociationStatus authenticate () throws Tracker.MinerWebError;
+ public virtual void dissociate () throws Tracker.MinerWebError;
+ public static GLib.Quark error_quark ();
+ public virtual GLib.HashTable get_association_data () throws Tracker.MinerWebError;
+ }
+ [CCode (cheader_filename = "libtracker-miner/tracker-password-provider.h")]
+ public interface PasswordProvider : GLib.Object {
+ public void forget_password (string service) throws GLib.Error;
+ public unowned string get_name ();
+ public string get_password (string service, out string username) throws GLib.Error;
+ public void store_password (string service, string description, string username, string password) throws GLib.Error;
+ }
+ [CCode (cprefix = "TRACKER_MINER_WEB_", has_type_id = "0", cheader_filename = "libtracker-miner/tracker-miner-web.h")]
+ public enum MinerWebAssociationStatus {
+ UNASSOCIATED,
+ ASSOCIATED
+ }
+ [CCode (cprefix = "TRACKER_MINER_WEB_ERROR_", cheader_filename = "libtracker-miner/tracker-miner-web.h")]
+ public errordomain MinerWebError {
+ WRONG_CREDENTIALS,
+ TOKEN_EXPIRED,
+ NO_CREDENTIALS,
+ KEYRING,
+ SERVICE,
+ TRACKER,
+ }
+ [CCode (cprefix = "TRACKER_PASSWORD_PROVIDER_ERROR_", cheader_filename = "libtracker-miner/tracker-password-provider.h")]
+ public errordomain PasswordProviderError {
+ SERVICE,
+ NOTFOUND,
+ }
+ [CCode (cheader_filename = "libtracker-miner/tracker-miner.h")]
+ public const string MINER_DBUS_INTERFACE;
+ [CCode (cheader_filename = "libtracker-miner/tracker-miner.h")]
+ public const string MINER_DBUS_NAME_PREFIX;
+ [CCode (cheader_filename = "libtracker-miner/tracker-miner.h")]
+ public const string MINER_DBUS_PATH_PREFIX;
+ [CCode (cheader_filename = "libtracker-miner/tracker-miner.h")]
+ public const string MINER_WEB_DBUS_INTERFACE;
+ [CCode (cheader_filename = "libtracker-miner/tracker-password-provider.h")]
+ public static unowned Tracker.PasswordProvider get_password_provider ();
+}
diff --git a/src/libtracker-miner/tracker-miner-web-0.7.vapi b/src/libtracker-miner/tracker-miner-web-0.7.vapi
new file mode 100644
index 0000000..55b550a
--- /dev/null
+++ b/src/libtracker-miner/tracker-miner-web-0.7.vapi
@@ -0,0 +1,40 @@
+[CCode (cprefix = "Tracker", lower_case_cprefix = "tracker_")]
+namespace Tracker {
+
+ public errordomain MinerWebError {
+ WRONG_CREDENTIALS,
+ TOKEN_EXPIRED,
+ NO_CREDENTIALS,
+ KEYRING,
+ SERVICE,
+ TRACKER
+ }
+
+ [Compact]
+ [CCode (cheader_filename = "libtracker-miner/tracker-miner-web.h")]
+ public abstract class MinerWeb : Miner {
+ public abstract void authenticate () throws GLib.Error;
+ public abstract GLib.HashTable<string, string> get_association_data () throws GLib.Error;
+ public abstract void associate (GLib.HashTable<string, string> association_data) throws GLib.Error;
+ public abstract void dissociate () throws GLib.Error;
+
+ [CCode (cprefix = "TRACKER_MINER_WEB_")]
+ public enum AssociationStatus {
+ UNASSOCIATED,
+ ASSOCIATED
+ }
+ public AssociationStatus association_status {
+ get {
+ AssociationStatus s;
+ this.get ("association-status", out s);
+ return s;
+ }
+ set {
+ this.set ("association-status", association_status);
+ }
+ }
+ }
+
+ public const string MINER_WEB_DBUS_INTERFACE;
+ public const string MINER_WEB_ERROR_DOMAIN;
+}
diff --git a/src/libtracker-miner/tracker-miner-web-dbus.h b/src/libtracker-miner/tracker-miner-web-dbus.h
new file mode 100644
index 0000000..cefce86
--- /dev/null
+++ b/src/libtracker-miner/tracker-miner-web-dbus.h
@@ -0,0 +1,47 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2009, Nokia (urho konttori nokia com)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __LIBTRACKERMINER_WEB_DBUS_H__
+#define __LIBTRACKERMINER_WEB_DBUS_H__
+
+#include <glib-object.h>
+
+#include "tracker-miner-dbus.h"
+#include "tracker-miner-web.h"
+
+G_BEGIN_DECLS
+
+void tracker_miner_web_dbus_authenticate (TrackerMinerWeb *miner,
+ DBusGMethodInvocation *context,
+ GError **error);
+void tracker_miner_web_dbus_get_association_data (TrackerMinerWeb *miner,
+ DBusGMethodInvocation *context,
+ GError **error);
+void tracker_miner_web_dbus_associate (TrackerMinerWeb *miner,
+ const GHashTable *association_data,
+ DBusGMethodInvocation *context,
+ GError **error);
+void tracker_miner_web_dbus_dissociate (TrackerMinerWeb *miner,
+ DBusGMethodInvocation *context,
+ GError **error);
+
+G_END_DECLS
+
+#endif /* __LIBTRACKERMINER_DBUS_H__ */
diff --git a/src/libtracker-miner/tracker-miner-web.c b/src/libtracker-miner/tracker-miner-web.c
new file mode 100644
index 0000000..a0abcc8
--- /dev/null
+++ b/src/libtracker-miner/tracker-miner-web.c
@@ -0,0 +1,249 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2009, Adrien Bustany (abustany gnome org)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "tracker-miner-web.h"
+#include "tracker-dbus.h"
+#include "tracker-miner-web-dbus.h"
+#include "tracker-miner-web-glue.h"
+
+/**
+ * SECTION:tracker-miner-web
+ * @short_description: Abstract base class for miners using web services
+ * @include: libtracker-miner/tracker-miner-web.h
+ *
+ * #TrackerMinerWeb is an abstract base class for miners retrieving data
+ * from web services. It's a very thin layer above #TrackerMiner, only
+ * adding virtual methods needed to handle association with the remote
+ * service.
+ **/
+
+#define TRACKER_MINER_WEB_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRACKER_TYPE_MINER_WEB, TrackerMinerWebPrivate))
+
+struct TrackerMinerWebPrivate {
+ TrackerMinerWebAssociationStatus association_status;
+};
+
+enum {
+ PROP_0,
+ PROP_ASSOCIATION_STATUS
+};
+
+static void miner_web_set_property (GObject * object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void miner_web_get_property (GObject * object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void miner_web_constructed (GObject *object);
+static void miner_web_finalize (GObject *object);
+
+G_DEFINE_ABSTRACT_TYPE (TrackerMinerWeb, tracker_miner_web, TRACKER_TYPE_MINER)
+
+static void
+tracker_miner_web_class_init (TrackerMinerWebClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->set_property = miner_web_set_property;
+ object_class->get_property = miner_web_get_property;
+ object_class->constructed = miner_web_constructed;
+ object_class->finalize = miner_web_finalize;
+
+ g_object_class_install_property (object_class,
+ PROP_ASSOCIATION_STATUS,
+ g_param_spec_uint ("association-status",
+ "Association status",
+ "Tells if the miner is associated with the remote service",
+ TRACKER_MINER_WEB_UNASSOCIATED, /* min value */
+ TRACKER_MINER_WEB_ASSOCIATED, /* max value */
+ TRACKER_MINER_WEB_UNASSOCIATED, /* default value */
+ G_PARAM_READWRITE));
+
+ g_type_class_add_private (object_class, sizeof (TrackerMinerWebPrivate));
+}
+
+static void
+tracker_miner_web_init (TrackerMinerWeb *miner)
+{
+ TrackerMinerWebPrivate *priv;
+ miner->private = priv = TRACKER_MINER_WEB_GET_PRIVATE (miner);
+ priv->association_status = TRACKER_MINER_WEB_UNASSOCIATED;
+}
+
+static void
+miner_web_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ TrackerMinerWeb *miner = TRACKER_MINER_WEB (object);
+ switch (param_id) {
+ case PROP_ASSOCIATION_STATUS:
+ miner->private->association_status = g_value_get_uint (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ }
+}
+
+static void
+miner_web_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ TrackerMinerWeb *miner = TRACKER_MINER_WEB (object);
+ switch (param_id) {
+ case PROP_ASSOCIATION_STATUS:
+ g_value_set_uint (value, miner->private->association_status);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ }
+}
+
+static void
+miner_web_constructed (GObject *object)
+{
+ tracker_miner_dbus_init (TRACKER_MINER (object),
+ &dbus_glib_tracker_miner_web_dbus_object_info);
+
+ G_OBJECT_CLASS (tracker_miner_web_parent_class)->constructed (object);
+}
+
+static void
+miner_web_finalize (GObject *object)
+{
+ /* TrackerMinerWeb *miner = TRACKER_MINER_WEB (object); */
+
+ G_OBJECT_CLASS (tracker_miner_web_parent_class)->finalize (object);
+}
+
+GQuark
+tracker_miner_web_error_quark (void)
+{
+ return g_quark_from_static_string (TRACKER_MINER_WEB_ERROR_DOMAIN);
+}
+
+void
+tracker_miner_web_dbus_authenticate (TrackerMinerWeb *miner,
+ DBusGMethodInvocation *context,
+ GError **error)
+{
+ g_assert (TRACKER_IS_MINER_WEB (miner));
+
+ GError *local_error = NULL;
+ TRACKER_MINER_WEB_GET_CLASS (miner)->authenticate (miner, &local_error);
+
+ if (local_error != NULL) {
+ dbus_g_method_return_error (context, local_error);
+ } else {
+ dbus_g_method_return (context);
+ }
+}
+
+void
+tracker_miner_web_dbus_get_association_data (TrackerMinerWeb *miner,
+ DBusGMethodInvocation *context,
+ GError **error)
+{
+ g_assert (TRACKER_IS_MINER_WEB (miner));
+
+ GError *local_error = NULL;
+ GHashTable *association_data = TRACKER_MINER_WEB_GET_CLASS (miner)->get_association_data (miner, &local_error);
+
+ if (local_error != NULL) {
+ dbus_g_method_return_error (context, local_error);
+ } else {
+ dbus_g_method_return (context, association_data);
+ }
+}
+
+void
+tracker_miner_web_dbus_associate (TrackerMinerWeb *miner,
+ const GHashTable *association_data,
+ DBusGMethodInvocation *context,
+ GError **error)
+{
+ g_assert (TRACKER_IS_MINER_WEB (miner));
+
+ GError *local_error = NULL;
+ TRACKER_MINER_WEB_GET_CLASS (miner)->associate (miner, association_data, &local_error);
+
+ if (local_error != NULL) {
+ dbus_g_method_return_error (context, local_error);
+ } else {
+ dbus_g_method_return (context);
+ }
+}
+
+void
+tracker_miner_web_dbus_dissociate (TrackerMinerWeb *miner,
+ DBusGMethodInvocation *context,
+ GError **error)
+{
+ g_assert (TRACKER_IS_MINER_WEB (miner));
+
+ GError *local_error = NULL;
+ TRACKER_MINER_WEB_GET_CLASS (miner)->dissociate (miner, &local_error);
+
+ if (local_error != NULL) {
+ dbus_g_method_return_error (context, local_error);
+ } else {
+ dbus_g_method_return (context);
+ }
+}
+
+TrackerMinerWebAssociationStatus
+tracker_miner_web_authenticate (TrackerMinerWeb *miner,
+ GError **error)
+{
+ g_assert (TRACKER_IS_MINER_WEB (miner));
+ return TRACKER_MINER_WEB_GET_CLASS (miner)->authenticate (miner, error);
+}
+
+GHashTable*
+tracker_miner_web_get_association_data (TrackerMinerWeb *miner,
+ GError **error)
+{
+ g_assert (TRACKER_IS_MINER_WEB (miner));
+ return TRACKER_MINER_WEB_GET_CLASS (miner)->get_association_data (miner, error);
+}
+
+void
+tracker_miner_web_associate (TrackerMinerWeb *miner,
+ const GHashTable *association_data,
+ GError **error)
+{
+ g_assert (TRACKER_IS_MINER_WEB (miner));
+ TRACKER_MINER_WEB_GET_CLASS (miner)->associate (miner, association_data, error);
+}
+
+void
+tracker_miner_web_dissociate (TrackerMinerWeb *miner,
+ GError **error)
+{
+ g_assert (TRACKER_IS_MINER_WEB (miner));
+ TRACKER_MINER_WEB_GET_CLASS (miner)->dissociate (miner, error);
+}
diff --git a/src/libtracker-miner/tracker-miner-web.deps.in b/src/libtracker-miner/tracker-miner-web.deps.in
new file mode 100644
index 0000000..0f1fc53
--- /dev/null
+++ b/src/libtracker-miner/tracker-miner-web.deps.in
@@ -0,0 +1 @@
+tracker-miner- VERSION@
diff --git a/src/libtracker-miner/tracker-miner-web.h b/src/libtracker-miner/tracker-miner-web.h
new file mode 100644
index 0000000..50bfaa6
--- /dev/null
+++ b/src/libtracker-miner/tracker-miner-web.h
@@ -0,0 +1,138 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2009, Adrien Bustany (abustany gnome org)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __TRACKER_MINER_WEB_H__
+#define __TRACKER_MINER_WEB_H__
+
+#include <libtracker-miner/tracker-miner.h>
+
+G_BEGIN_DECLS
+
+#define TRACKER_TYPE_MINER_WEB (tracker_miner_web_get_type())
+#define TRACKER_MINER_WEB(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_MINER_WEB, TrackerMinerWeb))
+#define TRACKER_MINER_WEB_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), TRACKER_TYPE_MINER_WEB, TrackerMinerWebClass))
+#define TRACKER_IS_MINER_WEB(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_MINER_WEB))
+#define TRACKER_IS_MINER_WEB_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), TRACKER_TYPE_MINER_WEB))
+#define TRACKER_MINER_WEB_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_MINER_WEB, TrackerMinerWebClass))
+
+typedef struct TrackerMinerWeb TrackerMinerWeb;
+typedef struct TrackerMinerWebPrivate TrackerMinerWebPrivate;
+
+/**
+ * The name of the DBus interface exposed by the web miners
+ **/
+#define TRACKER_MINER_WEB_DBUS_INTERFACE "org.freedesktop.Tracker1.MinerWeb"
+
+/**
+ * TrackerMinerWebError:
+ * @TRACKER_MINER_WEB_ERROR_WRONG_CREDENTIALS: The stored credentials are refused by the remote service
+ * @TRACKER_MINER_WEB_ERROR_TOKEN_EXPIRED : The service says the stored token has expired
+ * @TRACKER_MINER_WEB_ERROR_NO_CREDENTIALS : There are currenty no credentials stored for this service
+ * @TRACKER_MINER_WEB_ERROR_KEYRING : Error while contacting the credentials storage
+ * @TRACKER_MINER_WEB_ERROR_SERVICE : Error while contacting the remote service
+ * @TRACKER_MINER_WEB_ERROR_TRACKER : Error while contacting Tracker
+ *
+ * Describes the different errors that can occur while operating with the remote service.
+ **/
+typedef enum {
+ TRACKER_MINER_WEB_ERROR_WRONG_CREDENTIALS,
+ TRACKER_MINER_WEB_ERROR_TOKEN_EXPIRED,
+ TRACKER_MINER_WEB_ERROR_NO_CREDENTIALS,
+ TRACKER_MINER_WEB_ERROR_KEYRING,
+ TRACKER_MINER_WEB_ERROR_SERVICE,
+ TRACKER_MINER_WEB_ERROR_TRACKER
+} TrackerMinerWebError;
+#define TRACKER_MINER_WEB_ERROR tracker_miner_web_error_quark ()
+#define TRACKER_MINER_WEB_ERROR_DOMAIN "TrackerMinerWeb"
+
+/**
+ * TrackerMinerWebAssociationStatus:
+ * @TRACKER_MINER_WEB_UNASSOCIATED : The miner is currently unassociated with the remote service
+ * @TRACKER_MINER_WEB_ASSOCIATED : The miner is currently associated with the remote service
+ *
+ * Describes if the miner can currently communicate (import data) with the web service.
+ **/
+typedef enum {
+ TRACKER_MINER_WEB_UNASSOCIATED,
+ TRACKER_MINER_WEB_ASSOCIATED
+} TrackerMinerWebAssociationStatus;
+
+struct TrackerMinerWeb {
+ TrackerMiner parent_instance;
+ /*< private >*/
+ TrackerMinerWebPrivate *private;
+};
+
+/**
+ * TrackerMinerWebClass
+ * @parent_class : parent object class
+ * @authenticate : called when the miner is told to authenticate against the remote service
+ * @get_association_data: called when one requests the miner's association data.
+ * In the case of a user/pass based authentication, this should return
+ * an empty hash table.
+ * In the case of a token based authentication, the following keys must
+ * be defined in the returned hash table:
+ * - url: the url to point the user too
+ * Additionally, the miner can define the following keys :
+ * - post_message: a message to display after the user completes the
+ * association process
+ * - post_url: a url to point the user after he completes the association
+ *
+ * If both post_message and post_url are defined, the message will be
+ * displayed before the url is opened.
+ * @associate : called when the miner is told to associate with the web service.
+ * In the case of a user/pass based authentication, the following keys must be defined
+ * - username: the provided username
+ * - password: the provided password
+ * In the case of a token based authentication, the hash table can be ignored
+ * since it will be empty.
+ * @dissociate : called when the miner is told to forget any user credentials it has stored
+ **/
+typedef struct {
+ TrackerMinerClass parent_class;
+
+ /* vmethods */
+ TrackerMinerWebAssociationStatus (* authenticate) (TrackerMinerWeb *miner,
+ GError **error);
+ GHashTable* (* get_association_data) (TrackerMinerWeb *miner,
+ GError **error);
+ void (* associate) (TrackerMinerWeb *miner,
+ const GHashTable *association_data,
+ GError **error);
+ void (* dissociate) (TrackerMinerWeb *miner,
+ GError **error);
+} TrackerMinerWebClass;
+
+GType tracker_miner_web_get_type (void) G_GNUC_CONST;
+GQuark tracker_miner_web_error_quark (void);
+
+TrackerMinerWebAssociationStatus tracker_miner_web_authenticate (TrackerMinerWeb *miner,
+ GError **error);
+GHashTable* tracker_miner_web_get_association_data (TrackerMinerWeb *miner,
+ GError **error);
+void tracker_miner_web_associate (TrackerMinerWeb *miner,
+ const GHashTable *association_data,
+ GError **error);
+void tracker_miner_web_dissociate (TrackerMinerWeb *miner,
+ GError **error);
+
+G_END_DECLS
+
+#endif /* __TRACKER_MINER_WEB_H__ */
diff --git a/src/libtracker-miner/tracker-miner.c b/src/libtracker-miner/tracker-miner.c
index 2739527..f1f392b 100644
--- a/src/libtracker-miner/tracker-miner.c
+++ b/src/libtracker-miner/tracker-miner.c
@@ -435,8 +435,8 @@ miner_constructed (GObject *object)
static void
store_name_monitor_cb (TrackerMiner *miner,
- const gchar *name,
- gboolean available)
+ const gchar *name,
+ gboolean available)
{
GError *error = NULL;
diff --git a/src/libtracker-miner/tracker-password-provider.c b/src/libtracker-miner/tracker-password-provider.c
new file mode 100644
index 0000000..1172911
--- /dev/null
+++ b/src/libtracker-miner/tracker-password-provider.c
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 2009, Adrien Bustany (abustany gnome org)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "tracker-password-provider.h"
+
+#include "config.h"
+
+/* for mlock */
+#include <sys/mman.h>
+
+static void
+tracker_password_provider_init (gpointer object_class)
+{
+ static gboolean is_initialized = FALSE;
+
+ if (!is_initialized) {
+ g_object_interface_install_property (object_class,
+ g_param_spec_string ("name",
+ "Password provider name",
+ "Password provider name",
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ is_initialized = TRUE;
+ }
+}
+
+GType
+tracker_password_provider_get_type (void)
+{
+ static GType iface_type = 0;
+
+ if (iface_type == 0) {
+ static const GTypeInfo info = {
+ sizeof (TrackerPasswordProviderIface),
+ tracker_password_provider_init,
+ NULL
+ };
+
+ iface_type = g_type_register_static (G_TYPE_INTERFACE,
+ "TrackerPasswordProvider",
+ &info,
+ 0);
+ }
+
+ return iface_type;
+}
+
+GQuark
+tracker_password_provider_error_quark (void)
+{
+ return g_quark_from_static_string (TRACKER_PASSWORD_PROVIDER_ERROR_DOMAIN);
+}
+
+gchar*
+tracker_password_provider_get_name (TrackerPasswordProvider *provider)
+{
+ g_assert (TRACKER_IS_PASSWORD_PROVIDER (provider));
+
+ gchar *name;
+ g_object_get (provider,
+ "name", &name,
+ NULL);
+
+ return name;
+}
+
+void
+tracker_password_provider_store_password (TrackerPasswordProvider *provider,
+ const gchar *service,
+ const gchar *description,
+ const gchar *username,
+ const gchar *password,
+ GError **error)
+{
+ g_assert (TRACKER_IS_PASSWORD_PROVIDER (provider));
+
+ TRACKER_PASSWORD_PROVIDER_GET_INTERFACE (provider)->store_password (provider,
+ service,
+ description,
+ username,
+ password,
+ error);
+}
+
+gchar*
+tracker_password_provider_get_password (TrackerPasswordProvider *provider,
+ const gchar *service,
+ gchar **username,
+ GError **error)
+{
+ g_assert (TRACKER_IS_PASSWORD_PROVIDER (provider));
+
+ gchar *password = TRACKER_PASSWORD_PROVIDER_GET_INTERFACE (provider)->get_password (provider,
+ service,
+ username,
+ error);
+ /* This locking is not perfect since the process can be swapped before the mlock call...
+ * gnome-keyring has a better implementation using a pool of locked memory to allocate the
+ * password, but it's much more complex :-/
+ */
+ mlock (password, sizeof (password));
+ return password;
+}
+
+void
+tracker_password_provider_forget_password (TrackerPasswordProvider *provider,
+ const gchar *service,
+ GError **error)
+{
+ g_assert (TRACKER_IS_PASSWORD_PROVIDER (provider));
+
+ TRACKER_PASSWORD_PROVIDER_GET_INTERFACE (provider)->forget_password (provider,
+ service,
+ error);
+}
diff --git a/src/libtracker-miner/tracker-password-provider.h b/src/libtracker-miner/tracker-password-provider.h
new file mode 100644
index 0000000..ff6ae66
--- /dev/null
+++ b/src/libtracker-miner/tracker-password-provider.h
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2009, Adrien Bustany (abustany gnome org)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __TRACKER_PASSWORD_PROVIDER_H__
+#define __TRACKER_PASSWORD_PROVIDER_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define TRACKER_TYPE_PASSWORD_PROVIDER (tracker_password_provider_get_type())
+#define TRACKER_PASSWORD_PROVIDER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_PASSWORD_PROVIDER, TrackerPasswordProvider))
+#define TRACKER_IS_PASSWORD_PROVIDER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_PASSWORD_PROVIDER))
+#define TRACKER_PASSWORD_PROVIDER_GET_INTERFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), TRACKER_TYPE_PASSWORD_PROVIDER, TrackerPasswordProviderIface))
+
+#define TRACKER_PASSWORD_PROVIDER_ERROR_DOMAIN "TrackerPasswordProvider"
+#define TRACKER_PASSWORD_PROVIDER_ERROR tracker_password_provider_error_quark()
+
+typedef struct TrackerPasswordProvider TrackerPasswordProvider;
+typedef struct TrackerPasswordProviderIface TrackerPasswordProviderIface;
+
+typedef enum {
+ TRACKER_PASSWORD_PROVIDER_ERROR_SERVICE,
+ TRACKER_PASSWORD_PROVIDER_ERROR_NOTFOUND
+} TrackerPasswordProviderError;
+
+struct TrackerPasswordProviderIface
+{
+ GTypeInterface parent_iface;
+
+ void (* store_password) (TrackerPasswordProvider *provider,
+ const gchar *service,
+ const gchar *description,
+ const gchar *username,
+ const gchar *password,
+ GError **error);
+ gchar* (* get_password) (TrackerPasswordProvider *provider,
+ const gchar *service,
+ gchar **username,
+ GError **error);
+ void (* forget_password) (TrackerPasswordProvider *provider,
+ const gchar *service,
+ GError **error);
+};
+
+GType tracker_password_provider_get_type (void) G_GNUC_CONST;
+GQuark tracker_password_provider_error_quark (void);
+
+gchar* tracker_password_provider_get_name (TrackerPasswordProvider *provider);
+/* Must be defined by the selected implementation */
+const TrackerPasswordProvider* tracker_get_password_provider (void);
+void tracker_password_provider_store_password (TrackerPasswordProvider *provider,
+ const gchar *service,
+ const gchar *description,
+ const gchar *username,
+ const gchar *password,
+ GError **error);
+
+gchar* tracker_password_provider_get_password (TrackerPasswordProvider *provider,
+ const gchar *service,
+ gchar **username,
+ GError **error);
+void tracker_password_provider_forget_password (TrackerPasswordProvider *provider,
+ const gchar *service,
+ GError **error);
+G_END_DECLS
+
+#endif
diff --git a/src/libtracker-miner/tracker-password-provider.vala b/src/libtracker-miner/tracker-password-provider.vala
new file mode 100644
index 0000000..97acca0
--- /dev/null
+++ b/src/libtracker-miner/tracker-password-provider.vala
@@ -0,0 +1,32 @@
+namespace Tracker {
+ [CCode (cheader_filename = "libtracker-miner/tracker-password-provider.h")]
+ public errordomain PasswordProviderError {
+ SERVICE, // The service couldn't be contacted
+ NOTFOUND, // No results were found during a call to get
+ }
+
+ private static PasswordProvider _password_provider_instance = null;
+
+ [CCode (cheader_filename = "libtracker-miner/tracker-password-provider.h")]
+ public interface PasswordProvider : GLib.Object {
+ public abstract string name { get; }
+ public abstract void store_password (string service, string description, string username, string password) throws PasswordProviderError;
+ public abstract string @get_password (string service, out string? username) throws PasswordProviderError;
+ public abstract void forget_password (string service) throws PasswordProviderError;
+
+ public static PasswordProvider password_provider {
+ get {
+ if (_password_provider_instance == null) {
+#if HAVE_GNOME_KEYRING
+ _password_provider_instance = new GnomePasswordProvider ();
+#else
+ _password_provider_instance = new KeyFilePasswordProvider ();
+#endif
+ }
+
+ assert (_password_provider_instance != null);
+ return _password_provider_instance;
+ }
+ }
+ }
+}
diff --git a/src/libtracker-miner/vapi/rebuild_vapi.sh b/src/libtracker-miner/vapi/rebuild_vapi.sh
new file mode 100755
index 0000000..5da0280
--- /dev/null
+++ b/src/libtracker-miner/vapi/rebuild_vapi.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+cd $(dirname $0)/..
+echo vala-gen-introspect
+vala-gen-introspect tracker-miner-0.7 vapi
+echo vapigen
+vapigen --library tracker-miner-0.7 --metadata vapi/tracker-miner-0.7.metadata vapi/tracker-miner-0.7.gi vapi/tracker-miner-0.7-custom.vala
diff --git a/src/libtracker-miner/vapi/tracker-miner-0.7-custom.vala b/src/libtracker-miner/vapi/tracker-miner-0.7-custom.vala
new file mode 100644
index 0000000..baa973f
--- /dev/null
+++ b/src/libtracker-miner/vapi/tracker-miner-0.7-custom.vala
@@ -0,0 +1,46 @@
+namespace Tracker {
+ [CCode (cheader_filename="libtracker-miner/tracker-miner.h")]
+ public class Miner : GLib.Object {
+ public async void commit (GLib.Cancellable? cancellable = null) throws GLib.Error;
+ public async void execute_batch_update (string sparql, GLib.Cancellable? cancellable = null) throws GLib.Error;
+ public async unowned GLib.PtrArray execute_sparql (string sparql, GLib.Cancellable? cancellable = null) throws GLib.Error;
+ public async void execute_update (string sparql, GLib.Cancellable? cancellable = null) throws GLib.Error;
+
+ public virtual void started ();
+ public virtual void stopped ();
+ public virtual void paused ();
+ public virtual void resumed ();
+ public virtual void writeback ([CCode (array_length = false, array_null_terminated = true)] string[] subjects);
+
+ public signal void error (GLib.Error e);
+ }
+
+ [CCode (cheader_filename = "libtracker-miner/tracker-miner-fs.h")]
+ public class MinerFS {
+ public virtual bool check_file (GLib.File file);
+ public virtual bool check_directory (GLib.File directory);
+ public virtual bool check_directory_contents (GLib.File directory, GLib.List<GLib.File> children);
+ public virtual bool monitor_directory (GLib.File directory);
+ // Commented out since we don't have a Tracker.SparqlBuilder binding yet
+ //public virtual bool process_file (GLib.File file, Tracker.SparqlBuilder builder, GLib.Cancellable cancellable);
+ //public virtual bool writeback_file (GLib.File file, Tracker.SparqlBuilder builder, GLib.Cancellable cancellable);
+
+ public signal void finished (double elapsed, uint directories_found, uint directories_ignored, uint files_found, uint files_ignored);
+ }
+
+ [CCode (cheader_filename="libtracker-miner/tracker-miner-web.h")]
+ public class MinerWeb : Miner {
+ public virtual void associate (GLib.HashTable association_data) throws MinerWebError;
+ public virtual Tracker.MinerWebAssociationStatus authenticate () throws MinerWebError;
+ public virtual void dissociate () throws MinerWebError;
+ public virtual GLib.HashTable get_association_data () throws MinerWebError;
+ }
+
+ [CCode (cheader_filename = "libtracker-miner/tracker-password-provider.h")]
+ public interface PasswordProvider : GLib.Object {
+ public void store_password (string service, string description, string username, string password) throws GLib.Error;
+ public string get_password (string service, out string username) throws GLib.Error;
+ public void forget_password (string service) throws GLib.Error;
+ public unowned string get_name ();
+ }
+}
diff --git a/src/libtracker-miner/vapi/tracker-miner-0.7.deps b/src/libtracker-miner/vapi/tracker-miner-0.7.deps
new file mode 100644
index 0000000..cd10dfd
--- /dev/null
+++ b/src/libtracker-miner/vapi/tracker-miner-0.7.deps
@@ -0,0 +1 @@
+gio-2.0
diff --git a/src/libtracker-miner/vapi/tracker-miner-0.7.files b/src/libtracker-miner/vapi/tracker-miner-0.7.files
new file mode 100644
index 0000000..0dc1d20
--- /dev/null
+++ b/src/libtracker-miner/vapi/tracker-miner-0.7.files
@@ -0,0 +1 @@
+include/tracker-0.7/libtracker-miner/
diff --git a/src/libtracker-miner/vapi/tracker-miner-0.7.metadata b/src/libtracker-miner/vapi/tracker-miner-0.7.metadata
new file mode 100644
index 0000000..f1ec439
--- /dev/null
+++ b/src/libtracker-miner/vapi/tracker-miner-0.7.metadata
@@ -0,0 +1,37 @@
+TrackerMiner cheader_filename="libtracker-miner/tracker-miner.h"
+TrackerMinerWeb cheader_filename="libtracker-miner/tracker-miner-web.h"
+TrackerMinerWebAssociationStatus cheader_filename="libtracker-miner/tracker-miner-web.h"
+TRACKER_MINER_* cheader_filename="libtracker-miner/tracker-miner.h"
+TrackerMinerFS cheader_filename="libtracker-miner/tracker-miner-fs.h"
+TrackerMiner.parent_instance hidden="1"
+TrackerMinerFS.parent hidden="1"
+TrackerMinerClass hidden="1"
+tracker_miner_commit hidden="1"
+tracker_miner_commit_finish hidden="1"
+tracker_miner_execute_batch_update hidden="1"
+tracker_miner_execute_batch_update_finish hidden="1"
+tracker_miner_execute_sparql hidden="1"
+tracker_miner_execute_sparql_finish hidden="1"
+tracker_miner_execute_update hidden="1"
+tracker_miner_execute_update_finish hidden="1"
+tracker_miner_writeback hidden="1"
+TrackerMinerFS.private hidden="1"
+TrackerMinerFSClass hidden="1"
+TrackerMinerFSDoneCb hidden="1"
+tracker_miner_dbus_* hidden="1"
+TrackerMiner.private hidden="1"
+TrackerMinerWeb.private hidden="1"
+TrackerMinerWeb.parent_instance hidden="1"
+TrackerMinerWebClass hidden="1"
+TrackerMinerWebError errordomain="1" cheader_filename="libtracker-miner/tracker-miner-web.h"
+tracker_miner_web_associate hidden="1"
+tracker_miner_web_dissociate hidden="1"
+tracker_miner_web_authenticate hidden="1"
+tracker_miner_web_get_association_data hidden="1"
+TrackerPasswordProviderIface hidden="1"
+TrackerPasswordProviderError errordomain="1" cheader_filename="libtracker-miner/tracker-password-provider.h"
+TrackerPasswordProvider hidden="1"
+TRACKER_MINER_ERROR_DOMAIN hidden="1"
+TRACKER_MINER_WEB_ERROR_DOMAIN hidden="1"
+TRACKER_PASSWORD_PROVIDER_ERROR_DOMAIN hidden="1"
+tracker_get_password_provider cheader_filename="libtracker-miner/tracker-password-provider.h"
diff --git a/src/libtracker-miner/vapi/tracker-miner-0.7.namespace b/src/libtracker-miner/vapi/tracker-miner-0.7.namespace
new file mode 100644
index 0000000..7bd7aa0
--- /dev/null
+++ b/src/libtracker-miner/vapi/tracker-miner-0.7.namespace
@@ -0,0 +1 @@
+Tracker
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]