[tracker] libtracker-miner: General code clean ups
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker] libtracker-miner: General code clean ups
- Date: Thu, 18 Mar 2010 13:57:38 +0000 (UTC)
commit 1aadd9205938fcd8190b3ab355c671aa68740c42
Author: Martyn Russell <martyn lanedo com>
Date: Wed Mar 17 18:30:15 2010 +0000
libtracker-miner: General code clean ups
src/libtracker-miner/tracker-miner-web-dbus.h | 2 +-
src/libtracker-miner/tracker-miner-web.c | 74 ++++----
src/libtracker-miner/tracker-miner-web.h | 47 +++---
.../tracker-password-provider-gnome.c | 198 +++++++++++---------
.../tracker-password-provider-keyfile.c | 194 ++++++++++----------
src/libtracker-miner/tracker-password-provider.c | 84 ++++++---
src/libtracker-miner/tracker-password-provider.h | 66 +++----
7 files changed, 348 insertions(+), 317 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-web-dbus.h b/src/libtracker-miner/tracker-miner-web-dbus.h
index 547340d..ec8f680 100644
--- a/src/libtracker-miner/tracker-miner-web-dbus.h
+++ b/src/libtracker-miner/tracker-miner-web-dbus.h
@@ -34,7 +34,7 @@ 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,
+ GHashTable *association_data,
DBusGMethodInvocation *context,
GError **error);
void tracker_miner_web_dbus_dissociate (TrackerMinerWeb *miner,
diff --git a/src/libtracker-miner/tracker-miner-web.c b/src/libtracker-miner/tracker-miner-web.c
index 73d5253..fe55268 100644
--- a/src/libtracker-miner/tracker-miner-web.c
+++ b/src/libtracker-miner/tracker-miner-web.c
@@ -46,16 +46,15 @@ enum {
PROP_ASSOCIATION_STATUS
};
-static void miner_web_set_property (GObject * object,
+static void miner_web_set_property (GObject *object,
guint param_id,
const GValue *value,
GParamSpec *pspec);
-static void miner_web_get_property (GObject * object,
+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);
+static void miner_web_constructed (GObject *object);
G_DEFINE_ABSTRACT_TYPE (TrackerMinerWeb, tracker_miner_web, TRACKER_TYPE_MINER)
@@ -67,7 +66,6 @@ tracker_miner_web_class_init (TrackerMinerWebClass *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,
@@ -86,7 +84,9 @@ static void
tracker_miner_web_init (TrackerMinerWeb *miner)
{
TrackerMinerWebPrivate *priv;
+
priv = TRACKER_MINER_WEB_GET_PRIVATE (miner);
+
priv->association_status = TRACKER_MINER_WEB_UNASSOCIATED;
}
@@ -96,8 +96,8 @@ miner_web_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
- TrackerMinerWeb *miner = TRACKER_MINER_WEB (object);
TrackerMinerWebPrivate *priv;
+
priv = TRACKER_MINER_WEB_GET_PRIVATE (object);
switch (param_id) {
@@ -111,13 +111,13 @@ miner_web_set_property (GObject *object,
}
static void
-miner_web_get_property (GObject *object,
- guint param_id,
- GValue *value,
- GParamSpec *pspec)
+miner_web_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- TrackerMinerWeb *miner = TRACKER_MINER_WEB (object);
TrackerMinerWebPrivate *priv;
+
priv = TRACKER_MINER_WEB_GET_PRIVATE (object);
switch (param_id) {
@@ -139,14 +139,6 @@ miner_web_constructed (GObject *object)
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)
{
@@ -160,7 +152,7 @@ tracker_miner_web_dbus_authenticate (TrackerMinerWeb *miner,
{
GError *local_error = NULL;
- g_assert (TRACKER_IS_MINER_WEB (miner));
+ g_return_if_fail (TRACKER_IS_MINER_WEB (miner));
TRACKER_MINER_WEB_GET_CLASS (miner)->authenticate (miner, &local_error);
@@ -177,29 +169,32 @@ tracker_miner_web_dbus_get_association_data (TrackerMinerWeb *miner,
DBusGMethodInvocation *context,
GError **error)
{
+ GHashTable *association_data;
GError *local_error = NULL;
- g_assert (TRACKER_IS_MINER_WEB (miner));
+ g_return_if_fail (TRACKER_IS_MINER_WEB (miner));
- GHashTable *association_data = TRACKER_MINER_WEB_GET_CLASS (miner)->get_association_data (miner, &local_error);
+ 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);
g_error_free (local_error);
} else {
dbus_g_method_return (context, association_data);
+ /* g_hash_table_unref (association_data); */
}
}
void
tracker_miner_web_dbus_associate (TrackerMinerWeb *miner,
- const GHashTable *association_data,
+ GHashTable *association_data,
DBusGMethodInvocation *context,
GError **error)
{
GError *local_error = NULL;
- g_assert (TRACKER_IS_MINER_WEB (miner));
+ g_return_if_fail (TRACKER_IS_MINER_WEB (miner));
+ g_return_if_fail (association_data != NULL);
TRACKER_MINER_WEB_GET_CLASS (miner)->associate (miner, association_data, &local_error);
@@ -218,7 +213,7 @@ tracker_miner_web_dbus_dissociate (TrackerMinerWeb *miner,
{
GError *local_error = NULL;
- g_assert (TRACKER_IS_MINER_WEB (miner));
+ g_return_if_fail (TRACKER_IS_MINER_WEB (miner));
TRACKER_MINER_WEB_GET_CLASS (miner)->dissociate (miner, &local_error);
@@ -231,27 +226,31 @@ tracker_miner_web_dbus_dissociate (TrackerMinerWeb *miner,
}
void
-tracker_miner_web_authenticate (TrackerMinerWeb *miner,
- GError **error)
+tracker_miner_web_authenticate (TrackerMinerWeb *miner,
+ GError **error)
{
- g_assert (TRACKER_IS_MINER_WEB (miner));
+ g_return_if_fail (TRACKER_IS_MINER_WEB (miner));
+
TRACKER_MINER_WEB_GET_CLASS (miner)->authenticate (miner, error);
}
-GHashTable*
-tracker_miner_web_get_association_data (TrackerMinerWeb *miner,
- GError **error)
+GHashTable *
+tracker_miner_web_get_association_data (TrackerMinerWeb *miner,
+ GError **error)
{
- g_assert (TRACKER_IS_MINER_WEB (miner));
+ g_return_val_if_fail (TRACKER_IS_MINER_WEB (miner), NULL);
+
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)
+tracker_miner_web_associate (TrackerMinerWeb *miner,
+ GHashTable *association_data,
+ GError **error)
{
- g_assert (TRACKER_IS_MINER_WEB (miner));
+ g_return_if_fail (TRACKER_IS_MINER_WEB (miner));
+ g_return_if_fail (association_data != NULL);
+
TRACKER_MINER_WEB_GET_CLASS (miner)->associate (miner, association_data, error);
}
@@ -259,6 +258,7 @@ void
tracker_miner_web_dissociate (TrackerMinerWeb *miner,
GError **error)
{
- g_assert (TRACKER_IS_MINER_WEB (miner));
+ g_return_if_fail (TRACKER_IS_MINER_WEB (miner));
+
TRACKER_MINER_WEB_GET_CLASS (miner)->dissociate (miner, error);
}
diff --git a/src/libtracker-miner/tracker-miner-web.h b/src/libtracker-miner/tracker-miner-web.h
index d7f6e42..09a5f5b 100644
--- a/src/libtracker-miner/tracker-miner-web.h
+++ b/src/libtracker-miner/tracker-miner-web.h
@@ -104,32 +104,31 @@ struct TrackerMinerWeb {
* @dissociate : called when the miner is told to forget any user credentials it has stored
**/
typedef struct {
- TrackerMinerClass parent_class;
-
- /* vmethods */
- void (* 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);
+ TrackerMinerClass parent_class;
+
+ /* vmethods */
+ void (* 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);
-
-void 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);
+GType tracker_miner_web_get_type (void) G_GNUC_CONST;
+GQuark tracker_miner_web_error_quark (void);
+void 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,
+ GHashTable *association_data,
+ GError **error);
+void tracker_miner_web_dissociate (TrackerMinerWeb *miner,
+ GError **error);
G_END_DECLS
diff --git a/src/libtracker-miner/tracker-password-provider-gnome.c b/src/libtracker-miner/tracker-password-provider-gnome.c
index 056a9f1..c1894cb 100644
--- a/src/libtracker-miner/tracker-password-provider-gnome.c
+++ b/src/libtracker-miner/tracker-password-provider-gnome.c
@@ -34,9 +34,7 @@
#define TRACKER_PASSWORD_PROVIDER_GNOME_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRACKER_TYPE_PASSWORD_PROVIDER_GNOME, TrackerPasswordProviderGnomePrivate))
-#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_PASSWORD_PROVIDER_GNOME, TrackerPasswordProviderGnomePrivate))
-
-#define PASSWORD_PROVIDER_GNOME_NAME "Gnome keyring"
+#define PASSWORD_PROVIDER_GNOME_NAME "GNOME Keyring"
typedef struct TrackerPasswordProviderGnome TrackerPasswordProviderGnome;
typedef struct TrackerPasswordProviderGnomeClass TrackerPasswordProviderGnomeClass;
@@ -51,14 +49,38 @@ struct TrackerPasswordProviderGnomeClass {
};
struct TrackerPasswordProviderGnomePrivate {
- gchar *name;
+ gchar *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_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);
+static gboolean password_provider_gnome_store (TrackerPasswordProvider *provider,
+ const gchar *service,
+ const gchar *description,
+ const gchar *username,
+ const gchar *password,
+ GError **error);
+static gchar* password_provider_gnome_get (TrackerPasswordProvider *provider,
+ const gchar *service,
+ gchar **username,
+ GError **error);
+static gboolean password_provider_gnome_forget (TrackerPasswordProvider *provider,
+ const gchar *service,
+ GError **error);
+
const GnomeKeyringPasswordSchema password_schema = {
- GNOME_KEYRING_ITEM_GENERIC_SECRET, {
- { "service", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
- { "username", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
- { NULL, 0 }
+ GNOME_KEYRING_ITEM_GENERIC_SECRET,
+ { { "service", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
+ { "username", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
+ { NULL, 0 }
}
};
@@ -67,33 +89,6 @@ enum {
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_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);
-
-static gboolean password_provider_gnome_store (TrackerPasswordProvider *provider,
- const gchar *service,
- const gchar *description,
- const gchar *username,
- const gchar *password,
- GError **error);
-static gchar* password_provider_gnome_get (TrackerPasswordProvider *provider,
- const gchar *service,
- gchar **username,
- GError **error);
-static 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,
@@ -105,15 +100,12 @@ tracker_password_provider_gnome_class_init (TrackerPasswordProviderGnomeClass *k
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = password_provider_gnome_finalize;
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));
+ g_object_class_override_property (object_class, PROP_NAME, "name");
+
+ g_type_class_add_private (object_class, sizeof (TrackerPasswordProviderGnomePrivate));
}
static void
@@ -124,30 +116,28 @@ tracker_password_provider_gnome_init (TrackerPasswordProviderGnome *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->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_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)
{
- TrackerPasswordProviderGnomePrivate *priv = GET_PRIV (object);
+ TrackerPasswordProviderGnomePrivate *priv;
+
+ priv = TRACKER_PASSWORD_PROVIDER_GNOME_GET_PRIVATE (object);
switch (prop_id) {
case PROP_NAME:
g_free (priv->name);
priv->name = g_value_dup_string (value);
+ g_object_notify (object, "name");
break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -155,17 +145,20 @@ password_provider_set_property (GObject *object,
}
static void
-password_provider_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+password_provider_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- TrackerPasswordProviderGnomePrivate *priv = GET_PRIV (object);
+ TrackerPasswordProviderGnomePrivate *priv;
+
+ priv = TRACKER_PASSWORD_PROVIDER_GNOME_GET_PRIVATE (object);
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;
@@ -180,73 +173,87 @@ password_provider_gnome_store (TrackerPasswordProvider *provider,
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) {
+ GnomeKeyringResult result;
+
+ result = gnome_keyring_store_password_sync (&password_schema,
+ NULL,
+ description,
+ password,
+ "service", service,
+ "username", username,
+ NULL);
+
+ if (result != GNOME_KEYRING_RESULT_OK) {
g_set_error (error,
TRACKER_PASSWORD_PROVIDER_ERROR,
TRACKER_PASSWORD_PROVIDER_ERROR_SERVICE,
- "Cannot store password: %s",
- gnome_keyring_result_to_message (r));
+ "Could not store GNOME keyring password, %s",
+ gnome_keyring_result_to_message (result));
+
return FALSE;
}
return TRUE;
}
-static gchar*
+static gchar *
password_provider_gnome_get (TrackerPasswordProvider *provider,
const gchar *service,
gchar **username,
GError **error)
{
- gchar *password;
GnomeKeyringAttributeList *search_attributes;
- GList *found_items = NULL;
GnomeKeyringFound *found;
- GnomeKeyringResult r;
+ GnomeKeyringResult result;
+ GList *found_items = NULL;
+ gchar *password;
gint i;
search_attributes = gnome_keyring_attribute_list_new ();
gnome_keyring_attribute_list_append_string (search_attributes,
- "service", service);
+ "service",
+ service);
- r = gnome_keyring_find_items_sync (GNOME_KEYRING_ITEM_GENERIC_SECRET,
- search_attributes,
- &found_items);
+ result = gnome_keyring_find_items_sync (GNOME_KEYRING_ITEM_GENERIC_SECRET,
+ search_attributes,
+ &found_items);
gnome_keyring_attribute_list_free (search_attributes);
- if (r != GNOME_KEYRING_RESULT_OK) {
- if (r == GNOME_KEYRING_RESULT_NO_MATCH) {
+ if (result != GNOME_KEYRING_RESULT_OK) {
+ if (result == GNOME_KEYRING_RESULT_NO_MATCH) {
g_set_error_literal (error,
TRACKER_PASSWORD_PROVIDER_ERROR,
TRACKER_PASSWORD_PROVIDER_ERROR_NOTFOUND,
- "Password not found");
+ "Could not find GNOME keyring password");
} else {
g_set_error (error,
TRACKER_PASSWORD_PROVIDER_ERROR,
TRACKER_PASSWORD_PROVIDER_ERROR_SERVICE,
- "Keyring error: %s",
- gnome_keyring_result_to_message (r));
+ "Could not fetch GNOME keyring password, %s",
+ gnome_keyring_result_to_message (result));
}
gnome_keyring_found_list_free (found_items);
+
return NULL;
}
found = found_items->data;
- /* Walk through all attributes and select the ones we're interested in */
- for (i = 0 ; i < found->attributes->len ; ++i) {
- GnomeKeyringAttribute *attr = &gnome_keyring_attribute_list_index (found->attributes, i);
- if (username && !g_strcmp0 (attr->name, "username")) {
- *username = g_strdup (attr->value.string);
+ /* Find username if we asked for it */
+ if (username) {
+ /* Make sure it is always set */
+ *username = NULL;
+
+ for (i = 0; i < found->attributes->len; ++i) {
+ GnomeKeyringAttribute *attr;
+
+ attr = &gnome_keyring_attribute_list_index (found->attributes, i);
+
+ if (g_ascii_strcasecmp (attr->name, "username") == 0) {
+ *username = g_strdup (attr->value.string);
+ }
}
}
@@ -257,22 +264,27 @@ password_provider_gnome_get (TrackerPasswordProvider *provider,
return password;
}
-static void
+static gboolean
password_provider_gnome_forget (TrackerPasswordProvider *provider,
const gchar *service,
GError **error)
{
- GnomeKeyringResult r = gnome_keyring_delete_password_sync (&password_schema,
- "service", service,
- NULL);
+ GnomeKeyringResult result;
+
+ result = gnome_keyring_delete_password_sync (&password_schema,
+ "service", service,
+ NULL);
- if (r != GNOME_KEYRING_RESULT_OK) {
+ if (result != 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));
+ "Coult not delete GNOME keyring password, %s",
+ gnome_keyring_result_to_message (result));
+ return FALSE;
}
+
+ return TRUE;
}
TrackerPasswordProvider *
@@ -282,14 +294,14 @@ tracker_password_provider_get (void)
static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
g_static_mutex_lock (&mutex);
- if (instance == NULL) {
+
+ if (!instance) {
instance = g_object_new (TRACKER_TYPE_PASSWORD_PROVIDER_GNOME,
"name", PASSWORD_PROVIDER_GNOME_NAME,
NULL);
}
- g_static_mutex_unlock (&mutex);
- g_assert (instance != NULL);
+ g_static_mutex_unlock (&mutex);
return instance;
}
diff --git a/src/libtracker-miner/tracker-password-provider-keyfile.c b/src/libtracker-miner/tracker-password-provider-keyfile.c
index fae3540..300070c 100644
--- a/src/libtracker-miner/tracker-password-provider-keyfile.c
+++ b/src/libtracker-miner/tracker-password-provider-keyfile.c
@@ -32,7 +32,7 @@
#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 GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_PASSWORD_PROVIDER_KEYFILE, TrackerPasswordProviderKeyfilePrivate))
+#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"
@@ -57,16 +57,10 @@ struct TrackerPasswordProviderKeyfilePrivate {
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,
@@ -76,25 +70,29 @@ static void password_provider_get_property (GObject
GValue *value,
GParamSpec *pspec);
-void password_provider_keyfile_store (TrackerPasswordProvider *provider,
+static gboolean 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,
+static gchar * password_provider_keyfile_get (TrackerPasswordProvider *provider,
const gchar *service,
gchar **username,
GError **error);
-void password_provider_keyfile_forget (TrackerPasswordProvider *provider,
+static gboolean password_provider_keyfile_forget (TrackerPasswordProvider *provider,
const gchar *service,
GError **error);
-
static void load_password_file (TrackerPasswordProviderKeyfile *kf,
GError **error);
static gboolean save_password_file (TrackerPasswordProviderKeyfile *kf,
GError **error);
+enum {
+ PROP_0,
+ PROP_NAME
+};
+
G_DEFINE_TYPE_WITH_CODE (TrackerPasswordProviderKeyfile,
tracker_password_provider_keyfile,
G_TYPE_OBJECT,
@@ -106,14 +104,11 @@ tracker_password_provider_keyfile_class_init (TrackerPasswordProviderKeyfileClas
{
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_object_class_override_property (object_class, PROP_NAME, "name");
g_type_class_add_private (object_class, sizeof (TrackerPasswordProviderKeyfilePrivate));
}
@@ -126,47 +121,49 @@ tracker_password_provider_keyfile_init (TrackerPasswordProviderKeyfile *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->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 = GET_PRIV (object);
+ TrackerPasswordProviderKeyfile *kf;
+ TrackerPasswordProviderKeyfilePrivate *priv;
GError *error = NULL;
+ kf = TRACKER_PASSWORD_PROVIDER_KEYFILE (object);
+ priv = TRACKER_PASSWORD_PROVIDER_KEYFILE_GET_PRIVATE (kf);
+
priv->password_file = g_key_file_new ();
load_password_file (kf, &error);
if (error) {
- g_critical ("Cannot load password file: %s", error->message);
+ g_critical ("Could not load GKeyFile password file, %s",
+ error->message);
g_error_free (error);
}
}
static void
-password_provider_keyfile_finalize (GObject *object)
-{
- 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)
{
- TrackerPasswordProviderKeyfilePrivate *priv = GET_PRIV (object);
+ TrackerPasswordProviderKeyfilePrivate *priv;
+
+ priv = TRACKER_PASSWORD_PROVIDER_KEYFILE_GET_PRIVATE (object);
switch (prop_id) {
case PROP_NAME:
g_free (priv->name);
priv->name = g_value_dup_string (value);
+ g_object_notify (object, "name");
break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -174,24 +171,27 @@ password_provider_set_property (GObject *object,
}
static void
-password_provider_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+password_provider_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- TrackerPasswordProviderKeyfilePrivate *priv = GET_PRIV (object);
+ TrackerPasswordProviderKeyfilePrivate *priv;
+
+ priv = TRACKER_PASSWORD_PROVIDER_KEYFILE_GET_PRIVATE (object);
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
+static gboolean
password_provider_keyfile_store (TrackerPasswordProvider *provider,
const gchar *service,
const gchar *description,
@@ -199,9 +199,11 @@ password_provider_keyfile_store (TrackerPasswordProvider *provider,
const gchar *password,
GError **error)
{
- TrackerPasswordProviderKeyfile *kf = TRACKER_PASSWORD_PROVIDER_KEYFILE (provider);
- TrackerPasswordProviderKeyfilePrivate *priv = GET_PRIV (provider);
- GError *local_error = NULL;
+ TrackerPasswordProviderKeyfile *kf;
+ TrackerPasswordProviderKeyfilePrivate *priv;
+
+ kf = TRACKER_PASSWORD_PROVIDER_KEYFILE (provider);
+ priv = TRACKER_PASSWORD_PROVIDER_KEYFILE_GET_PRIVATE (kf);
g_key_file_set_string (priv->password_file,
service,
@@ -216,71 +218,84 @@ password_provider_keyfile_store (TrackerPasswordProvider *provider,
"password",
password);
- if (!save_password_file (kf, &local_error)) {
- g_propagate_error (error, local_error);
- }
+ return save_password_file (kf, error);
}
-gchar*
+static gchar *
password_provider_keyfile_get (TrackerPasswordProvider *provider,
const gchar *service,
gchar **username,
GError **error)
{
- TrackerPasswordProviderKeyfilePrivate *priv = GET_PRIV (provider);
- gchar *password = NULL;
- GError *error_password = NULL;
- GError *error_username = NULL;
+ TrackerPasswordProviderKeyfilePrivate *priv;
+ gchar *password;
+ GError *local_error = NULL;
+
+ priv = TRACKER_PASSWORD_PROVIDER_KEYFILE_GET_PRIVATE (provider);
password = g_key_file_get_string (priv->password_file,
service,
"password",
- &error_password);
+ &local_error);
- mlock (password, sizeof (password));
+ if (local_error) {
+ g_set_error_literal (error,
+ TRACKER_PASSWORD_PROVIDER_ERROR,
+ TRACKER_PASSWORD_PROVIDER_ERROR_NOTFOUND,
+ "Could not get GKeyFile password, it was not found");
+ g_error_free (local_error);
+ g_free (password);
+
+ return NULL;
+ }
if (username) {
*username = g_key_file_get_string (priv->password_file,
service,
"username",
- &error_username);
- }
-
- if (error_password || error_username) {
- g_set_error_literal (error,
- TRACKER_PASSWORD_PROVIDER_ERROR,
- TRACKER_PASSWORD_PROVIDER_ERROR_NOTFOUND,
- "Password not found");
+ &local_error);
+
+ if (local_error) {
+ g_set_error_literal (error,
+ TRACKER_PASSWORD_PROVIDER_ERROR,
+ TRACKER_PASSWORD_PROVIDER_ERROR_NOTFOUND,
+ "Could not get GKeyFile password, it was not found");
+ g_error_free (local_error);
+ g_free (password);
+ return NULL;
+ }
}
- if (error_password)
- g_error_free (error_password);
- if (error_username)
- g_error_free (error_username);
+ mlock (password, sizeof (password));
return password;
}
-void
+static gboolean
password_provider_keyfile_forget (TrackerPasswordProvider *provider,
const gchar *service,
GError **error)
{
- TrackerPasswordProviderKeyfilePrivate *priv = GET_PRIV (provider);
+ TrackerPasswordProviderKeyfilePrivate *priv;
+ GError *local_error = NULL;
- GError *e = NULL;
+ priv = TRACKER_PASSWORD_PROVIDER_KEYFILE_GET_PRIVATE (provider);
- if (!g_key_file_remove_group (priv->password_file, service, &e)) {
- g_warning ("Cannot remove group '%s' from password file: %s",
+ if (!g_key_file_remove_group (priv->password_file, service, &local_error)) {
+ g_warning ("Could not remove GKeyFile group '%s' from password file, %s",
service,
- e->message);
- g_error_free (e);
+ local_error->message);
+ g_error_free (local_error);
g_set_error_literal (error,
TRACKER_PASSWORD_PROVIDER_ERROR,
TRACKER_PASSWORD_PROVIDER_ERROR_NOTFOUND,
- "Service not found");
+ "Could not find service for GKeyFile password");
+
+ return FALSE;
}
+
+ return TRUE;
}
TrackerPasswordProvider *
@@ -290,14 +305,14 @@ tracker_password_provider_get (void)
static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
g_static_mutex_lock (&mutex);
+
if (instance == NULL) {
instance = g_object_new (TRACKER_TYPE_PASSWORD_PROVIDER_KEYFILE,
"name", PASSWORD_PROVIDER_KEYFILE_NAME,
NULL);
}
- g_static_mutex_unlock (&mutex);
- g_assert (instance != NULL);
+ g_static_mutex_unlock (&mutex);
return instance;
}
@@ -308,21 +323,19 @@ config_dir_ensure_exists_and_return (GError **error)
{
gchar *directory;
- directory = g_build_filename (g_get_user_config_dir (),
- "tracker",
- NULL);
+ 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) {
if (error) {
*error = g_error_new (TRACKER_PASSWORD_PROVIDER_ERROR,
TRACKER_PASSWORD_PROVIDER_ERROR_SERVICE,
- "Impossible to create directory: '%s'",
+ "Could not create directory '%s'",
directory);
}
+
g_free (directory);
+
return NULL;
}
}
@@ -334,64 +347,51 @@ static void
load_password_file (TrackerPasswordProviderKeyfile *kf,
GError **error)
{
- TrackerPasswordProviderKeyfilePrivate *priv = GET_PRIV (kf);
+ TrackerPasswordProviderKeyfilePrivate *priv;
gchar *filename;
gchar *directory;
- GError *local_error = NULL;
- directory = config_dir_ensure_exists_and_return (&local_error);
+ directory = config_dir_ensure_exists_and_return (error);
if (!directory) {
- g_propagate_error (error, local_error);
return;
}
filename = g_build_filename (directory, KEYFILE_FILENAME, NULL);
g_free (directory);
- if (!g_file_test (filename, G_FILE_TEST_EXISTS)) {
- return;
- }
+ priv = TRACKER_PASSWORD_PROVIDER_KEYFILE_GET_PRIVATE (kf);
g_key_file_load_from_file (priv->password_file,
filename,
G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
- &local_error);
-
- if (local_error) {
- g_propagate_error (error, local_error);
- }
+ error);
}
static gboolean
save_password_file (TrackerPasswordProviderKeyfile *kf,
GError **error)
{
- TrackerPasswordProviderKeyfilePrivate *priv = GET_PRIV (kf);
+ TrackerPasswordProviderKeyfilePrivate *priv;
gchar *filename;
gchar *directory;
gchar *data;
gsize size;
- GError *local_error = NULL;
- directory = config_dir_ensure_exists_and_return (&local_error);
+ directory = config_dir_ensure_exists_and_return (error);
if (!directory) {
- g_propagate_error (error, local_error);
return FALSE;
}
filename = g_build_filename (directory, KEYFILE_FILENAME, NULL);
g_free (directory);
+ priv = TRACKER_PASSWORD_PROVIDER_KEYFILE_GET_PRIVATE (kf);
+
data = g_key_file_to_data (priv->password_file, &size, NULL);
- g_file_set_contents (filename, data, size, &local_error);
+ g_file_set_contents (filename, data, size, error);
g_free (data);
g_free (filename);
- if (local_error) {
- g_propagate_error (error, local_error);
- return FALSE;
- }
-
- return TRUE;
+ return *error == NULL ? TRUE : FALSE;
}
diff --git a/src/libtracker-miner/tracker-password-provider.c b/src/libtracker-miner/tracker-password-provider.c
index 8517e60..17ffd02 100644
--- a/src/libtracker-miner/tracker-password-provider.c
+++ b/src/libtracker-miner/tracker-password-provider.c
@@ -40,7 +40,7 @@ tracker_password_provider_init (gpointer object_class)
}
}
-/* That would be better done with G_DECLARE_INTERFACE, but it's GLib 2.24 */
+/* That would be better done with G_DECLARE_INTERFACE, but it's GLib 2.24. */
GType
tracker_password_provider_get_type (void)
{
@@ -68,12 +68,13 @@ tracker_password_provider_error_quark (void)
return g_quark_from_static_string (TRACKER_PASSWORD_PROVIDER_ERROR_DOMAIN);
}
-gchar*
+gchar *
tracker_password_provider_get_name (TrackerPasswordProvider *provider)
{
- g_assert (TRACKER_IS_PASSWORD_PROVIDER (provider));
-
gchar *name;
+
+ g_return_val_if_fail (TRACKER_IS_PASSWORD_PROVIDER (provider), NULL);
+
g_object_get (provider, "name", &name, NULL);
return name;
@@ -87,47 +88,68 @@ tracker_password_provider_store_password (TrackerPasswordProvider *provider,
const gchar *password,
GError **error)
{
- g_assert (TRACKER_IS_PASSWORD_PROVIDER (provider));
-
- return TRACKER_PASSWORD_PROVIDER_GET_INTERFACE (provider)->store_password (provider,
- service,
- description,
- username,
- password,
- error);
+ TrackerPasswordProviderIface *iface;
+
+ g_return_val_if_fail (TRACKER_IS_PASSWORD_PROVIDER (provider), FALSE);
+ g_return_val_if_fail (service != NULL, FALSE);
+ g_return_val_if_fail (description != NULL, FALSE);
+ g_return_val_if_fail (password != NULL, FALSE);
+
+ iface = TRACKER_PASSWORD_PROVIDER_GET_INTERFACE (provider);
+
+ if (!iface || !iface->store_password) {
+ return FALSE;
+ }
+
+ return iface->store_password (provider, service, description, username, password, error);
}
-gchar*
-tracker_password_provider_get_password (TrackerPasswordProvider *provider,
- const gchar *service,
- gchar **username,
- GError **error)
+gchar *
+tracker_password_provider_get_password (TrackerPasswordProvider *provider,
+ const gchar *service,
+ gchar **username,
+ GError **error)
{
- g_assert (TRACKER_IS_PASSWORD_PROVIDER (provider));
+ TrackerPasswordProviderIface *iface;
+
+ g_return_val_if_fail (TRACKER_IS_PASSWORD_PROVIDER (provider), NULL);
+ g_return_val_if_fail (service != NULL, NULL);
- gchar *password = TRACKER_PASSWORD_PROVIDER_GET_INTERFACE (provider)->get_password (provider,
- service,
- username,
- error);
- return password;
+ iface = TRACKER_PASSWORD_PROVIDER_GET_INTERFACE (provider);
+
+ if (!iface || !iface->get_password) {
+ return NULL;
+ }
+
+ return iface->get_password (provider, service, username, error);
}
void
-tracker_password_provider_forget_password (TrackerPasswordProvider *provider,
- const gchar *service,
- GError **error)
+tracker_password_provider_forget_password (TrackerPasswordProvider *provider,
+ const gchar *service,
+ GError **error)
{
- g_assert (TRACKER_IS_PASSWORD_PROVIDER (provider));
+ TrackerPasswordProviderIface *iface;
+
+ g_return_if_fail (TRACKER_IS_PASSWORD_PROVIDER (provider));
+ g_return_if_fail (service != NULL);
+
+ iface = TRACKER_PASSWORD_PROVIDER_GET_INTERFACE (provider);
- TRACKER_PASSWORD_PROVIDER_GET_INTERFACE (provider)->forget_password (provider,
- service,
- error);
+ if (!iface || !iface->forget_password) {
+ return;
+ }
+
+ iface->forget_password (provider, service, error);
}
-gchar*
+gchar *
tracker_password_provider_strdup_mlock (const gchar *source)
{
gchar *dest;
+
+ g_return_val_if_fail (source != NULL, NULL);
+
dest = malloc (1 + strlen (source));
dest = memset (dest, 0, 1 + strlen (source));
mlock (dest, sizeof (dest));
diff --git a/src/libtracker-miner/tracker-password-provider.h b/src/libtracker-miner/tracker-password-provider.h
index 1a702a5..6b12fe6 100644
--- a/src/libtracker-miner/tracker-password-provider.h
+++ b/src/libtracker-miner/tracker-password-provider.h
@@ -40,49 +40,47 @@ typedef enum {
TRACKER_PASSWORD_PROVIDER_ERROR_NOTFOUND
} TrackerPasswordProviderError;
-struct TrackerPasswordProviderIface
-{
+struct TrackerPasswordProviderIface {
GTypeInterface parent_iface;
- gboolean (* 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);
+ gboolean (* 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);
+ gboolean (* 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);
+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);
+gchar* tracker_password_provider_get_name (TrackerPasswordProvider *provider);
/* Must be defined by the selected implementation */
TrackerPasswordProvider*
- tracker_password_provider_get (void);
-gboolean tracker_password_provider_store_password (TrackerPasswordProvider *provider,
- const gchar *service,
- const gchar *description,
- const gchar *username,
- const gchar *password,
- GError **error);
+ tracker_password_provider_get (void);
+gboolean 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);
+gchar* tracker_password_provider_strdup_mlock (const gchar *source);
-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);
-
-gchar* tracker_password_provider_strdup_mlock (const gchar *source);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]