[libsecret] Use collection aliases with secret_password_store() and friends
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsecret] Use collection aliases with secret_password_store() and friends
- Date: Fri, 6 Jul 2012 09:50:26 +0000 (UTC)
commit b535ed1bbfa1f8e78db1f4a27f42e06adcb1b04b
Author: Stef Walter <stefw gnome org>
Date: Fri Jul 6 09:42:08 2012 +0200
Use collection aliases with secret_password_store() and friends
* Make SECRET_COLLECTION_DEFAULT and SECRET_COLLECTION_SESSION
be the simple aliases for those collections.
* Accept either an alias or a path in secret_password_store()
and secret_service_store() and friends.
library/secret-collection.c | 15 +++++++++++++++
library/secret-methods.c | 16 ++++++++--------
library/secret-password.c | 32 ++++++++++++++++----------------
library/secret-password.h | 8 ++++----
library/secret-paths.c | 13 ++++---------
library/secret-private.h | 2 ++
library/secret-service.h | 4 ++--
library/secret-types.h | 4 ++--
library/secret-util.c | 10 ++++++++++
9 files changed, 63 insertions(+), 41 deletions(-)
---
diff --git a/library/secret-collection.c b/library/secret-collection.c
index 9c51662..df86730 100644
--- a/library/secret-collection.c
+++ b/library/secret-collection.c
@@ -66,6 +66,21 @@
* during a secret_collection_new() or secret_collection_new_sync() operation.
*/
+/**
+ * SECRET_COLLECTION_DEFAULT:
+ *
+ * An alias to the default collection. This can be passed to secret_password_store()
+ * secret_service_read_alias().
+ */
+
+/**
+ * SECRET_COLLECTION_SESSION:
+ *
+ * An alias to the session collection, which will be cleared when the user ends
+ * the session. This can be passed to secret_password_store(),
+ * secret_service_read_alias() or similar functions.
+ */
+
enum {
PROP_0,
PROP_SERVICE,
diff --git a/library/secret-methods.c b/library/secret-methods.c
index 97901d9..e9841ae 100644
--- a/library/secret-methods.c
+++ b/library/secret-methods.c
@@ -1000,7 +1000,7 @@ on_store_service (GObject *source,
* @service: (allow-none): the secret service
* @schema: (allow-none): the schema to use to check attributes
* @attributes: (element-type utf8 utf8): the attribute keys and values
- * @collection_path: (allow-none): the D-Bus path to the collection where to store the secret
+ * @collection: (allow-none): a collection alias, or D-Bus object path of the collection where to store the secret
* @label: label for the secret
* @value: the secret value
* @cancellable: optional cancellation object
@@ -1017,7 +1017,7 @@ on_store_service (GObject *source,
* If @service is NULL, then secret_service_get() will be called to get
* the default #SecretService proxy.
*
- * If @collection_path is not specified, then the default collection will be
+ * If @collection is not specified, then the default collection will be
* used. Use #SECRET_COLLECTION_SESSION to store the password in the session
* collection, which doesn't get stored across login sessions.
*
@@ -1027,7 +1027,7 @@ void
secret_service_store (SecretService *service,
const SecretSchema *schema,
GHashTable *attributes,
- const gchar *collection_path,
+ const gchar *collection,
const gchar *label,
SecretValue *value,
GCancellable *cancellable,
@@ -1052,7 +1052,7 @@ secret_service_store (SecretService *service,
async = g_simple_async_result_new (G_OBJECT (service), callback, user_data,
secret_service_store);
store = g_slice_new0 (StoreClosure);
- store->collection_path = g_strdup (collection_path);
+ store->collection_path = _secret_util_collection_to_path (collection);
store->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
store->value = secret_value_ref (value);
store->properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
@@ -1117,7 +1117,7 @@ secret_service_store_finish (SecretService *service,
* @service: (allow-none): the secret service
* @schema: (allow-none): the schema for the attributes
* @attributes: (element-type utf8 utf8): the attribute keys and values
- * @collection_path: (allow-none): the D-Bus path to the collection where to store the secret
+ * @collection: (allow-none): a collection alias, or D-Bus object path of the collection where to store the secret
* @label: label for the secret
* @value: the secret value
* @cancellable: optional cancellation object
@@ -1130,7 +1130,7 @@ secret_service_store_finish (SecretService *service,
* If the attributes match a secret item already stored in the collection, then
* the item will be updated with these new values.
*
- * If @collection_path is %NULL, then the default collection will be
+ * If @collection is %NULL, then the default collection will be
* used. Use #SECRET_COLLECTION_SESSION to store the password in the session
* collection, which doesn't get stored across login sessions.
*
@@ -1146,7 +1146,7 @@ gboolean
secret_service_store_sync (SecretService *service,
const SecretSchema *schema,
GHashTable *attributes,
- const gchar *collection_path,
+ const gchar *collection,
const gchar *label,
SecretValue *value,
GCancellable *cancellable,
@@ -1169,7 +1169,7 @@ secret_service_store_sync (SecretService *service,
sync = _secret_sync_new ();
g_main_context_push_thread_default (sync->context);
- secret_service_store (service, schema, attributes, collection_path,
+ secret_service_store (service, schema, attributes, collection,
label, value, cancellable, _secret_sync_on_result, sync);
g_main_loop_run (sync->loop);
diff --git a/library/secret-password.c b/library/secret-password.c
index b27c44e..92d640e 100644
--- a/library/secret-password.c
+++ b/library/secret-password.c
@@ -45,7 +45,7 @@
/**
* secret_password_store: (skip)
* @schema: the schema for attributes
- * @collection_path: (allow-none): the D-Bus object path of the collection where to store the secret
+ * @collection: (allow-none): a collection alias, or D-Bus object path of the collection where to store the secret
* @label: label for the secret
* @password: the null-terminated password to store
* @cancellable: optional cancellation object
@@ -63,7 +63,7 @@
* If the attributes match a secret item already stored in the collection, then
* the item will be updated with these new values.
*
- * If @collection_path is %NULL, then the default collection will be
+ * If @collection is %NULL, then the default collection will be
* used. Use #SECRET_COLLECTION_SESSION to store the password in the session
* collection, which doesn't get stored across login sessions.
*
@@ -71,7 +71,7 @@
*/
void
secret_password_store (const SecretSchema *schema,
- const gchar *collection_path,
+ const gchar *collection,
const gchar *label,
const gchar *password,
GCancellable *cancellable,
@@ -91,7 +91,7 @@ secret_password_store (const SecretSchema *schema,
attributes = secret_attributes_buildv (schema, va);
va_end (va);
- secret_password_storev (schema, attributes, collection_path, label, password,
+ secret_password_storev (schema, attributes, collection, label, password,
cancellable, callback, user_data);
g_hash_table_unref (attributes);
@@ -101,7 +101,7 @@ secret_password_store (const SecretSchema *schema,
* secret_password_storev:
* @schema: the schema for attributes
* @attributes: (element-type utf8 utf8): the attribute keys and values
- * @collection_path: (allow-none): the D-Bus object path of the collection where to store the secret
+ * @collection: (allow-none): a collection alias, or D-Bus object path of the collection where to store the secret
* @label: label for the secret
* @password: the null-terminated password to store
* @cancellable: optional cancellation object
@@ -115,7 +115,7 @@ secret_password_store (const SecretSchema *schema,
* If the attributes match a secret item already stored in the collection, then
* the item will be updated with these new values.
*
- * If @collection_path is %NULL, then the default collection will be
+ * If @collection is %NULL, then the default collection will be
* used. Use #SECRET_COLLECTION_SESSION to store the password in the session
* collection, which doesn't get stored across login sessions.
*
@@ -126,7 +126,7 @@ secret_password_store (const SecretSchema *schema,
void
secret_password_storev (const SecretSchema *schema,
GHashTable *attributes,
- const gchar *collection_path,
+ const gchar *collection,
const gchar *label,
const gchar *password,
GCancellable *cancellable,
@@ -147,7 +147,7 @@ secret_password_storev (const SecretSchema *schema,
value = secret_value_new (password, -1, "text/plain");
- secret_service_store (NULL, schema, attributes, collection_path,
+ secret_service_store (NULL, schema, attributes, collection,
label, value, cancellable, callback, user_data);
secret_value_unref (value);
@@ -173,7 +173,7 @@ secret_password_store_finish (GAsyncResult *result,
/**
* secret_password_store_sync:
* @schema: the schema for attributes
- * @collection_path: (allow-none): the D-Bus object path of the collection where to store the secret
+ * @collection: (allow-none): a collection alias, or D-Bus object path of the collection where to store the secret
* @label: label for the secret
* @password: the null-terminated password to store
* @cancellable: optional cancellation object
@@ -190,7 +190,7 @@ secret_password_store_finish (GAsyncResult *result,
* If the attributes match a secret item already stored in the collection, then
* the item will be updated with these new values.
*
- * If @collection_path is %NULL, then the default collection will be
+ * If @collection is %NULL, then the default collection will be
* used. Use #SECRET_COLLECTION_SESSION to store the password in the session
* collection, which doesn't get stored across login sessions.
*
@@ -201,7 +201,7 @@ secret_password_store_finish (GAsyncResult *result,
*/
gboolean
secret_password_store_sync (const SecretSchema *schema,
- const gchar *collection_path,
+ const gchar *collection,
const gchar *label,
const gchar *password,
GCancellable *cancellable,
@@ -222,7 +222,7 @@ secret_password_store_sync (const SecretSchema *schema,
attributes = secret_attributes_buildv (schema, va);
va_end (va);
- ret = secret_password_storev_sync (schema, attributes, collection_path,
+ ret = secret_password_storev_sync (schema, attributes, collection,
label, password, cancellable, error);
g_hash_table_unref (attributes);
@@ -233,7 +233,7 @@ secret_password_store_sync (const SecretSchema *schema,
* secret_password_storev_sync:
* @schema: the schema for attributes
* @attributes: (element-type utf8 utf8): the attribute keys and values
- * @collection_path: (allow-none): the D-Bus object path of the collection where to store the secret
+ * @collection: (allow-none): a collection alias, or D-Bus object path of the collection where to store the secret
* @label: label for the secret
* @password: the null-terminated password to store
* @cancellable: optional cancellation object
@@ -246,7 +246,7 @@ secret_password_store_sync (const SecretSchema *schema,
* If the attributes match a secret item already stored in the collection, then
* the item will be updated with these new values.
*
- * If @collection_path is %NULL, then the default collection will be
+ * If @collection is %NULL, then the default collection will be
* used. Use #SECRET_COLLECTION_SESSION to store the password in the session
* collection, which doesn't get stored across login sessions.
*
@@ -260,7 +260,7 @@ secret_password_store_sync (const SecretSchema *schema,
gboolean
secret_password_storev_sync (const SecretSchema *schema,
GHashTable *attributes,
- const gchar *collection_path,
+ const gchar *collection,
const gchar *label,
const gchar *password,
GCancellable *cancellable,
@@ -283,7 +283,7 @@ secret_password_storev_sync (const SecretSchema *schema,
sync = _secret_sync_new ();
g_main_context_push_thread_default (sync->context);
- secret_password_storev (schema, attributes, collection_path, label, password,
+ secret_password_storev (schema, attributes, collection, label, password,
cancellable, _secret_sync_on_result, sync);
g_main_loop_run (sync->loop);
diff --git a/library/secret-password.h b/library/secret-password.h
index b8d3746..58a42d6 100644
--- a/library/secret-password.h
+++ b/library/secret-password.h
@@ -27,7 +27,7 @@ G_BEGIN_DECLS
#include "secret-types.h"
void secret_password_store (const SecretSchema *schema,
- const gchar *collection_path,
+ const gchar *collection,
const gchar *label,
const gchar *password,
GCancellable *cancellable,
@@ -37,7 +37,7 @@ void secret_password_store (const SecretSchema *sche
void secret_password_storev (const SecretSchema *schema,
GHashTable *attributes,
- const gchar *collection_path,
+ const gchar *collection,
const gchar *label,
const gchar *password,
GCancellable *cancellable,
@@ -48,7 +48,7 @@ gboolean secret_password_store_finish (GAsyncResult *result,
GError **error);
gboolean secret_password_store_sync (const SecretSchema *schema,
- const gchar *collection_path,
+ const gchar *collection,
const gchar *label,
const gchar *password,
GCancellable *cancellable,
@@ -57,7 +57,7 @@ gboolean secret_password_store_sync (const SecretSchema *sche
gboolean secret_password_storev_sync (const SecretSchema *schema,
GHashTable *attributes,
- const gchar *collection_path,
+ const gchar *collection,
const gchar *label,
const gchar *password,
GCancellable *cancellable,
diff --git a/library/secret-paths.c b/library/secret-paths.c
index d1bde90..63bb603 100644
--- a/library/secret-paths.c
+++ b/library/secret-paths.c
@@ -1834,7 +1834,7 @@ on_create_item_session (GObject *source,
/**
* secret_service_create_item_dbus_path:
* @self: a secret service object
- * @collection_path: (allow-none): the D-Bus object path of the collection in which to create item
+ * @collection_path: the D-Bus object path of the collection in which to create item
* @properties: (element-type utf8 GLib.Variant): hash table of D-Bus properties
* for the new collection
* @value: the secret value to store in the item
@@ -1859,10 +1859,6 @@ on_create_item_session (GObject *source,
* <literal>org.freedesktop.Secret.Item.Label</literal>. The values
* in the hash table should be #GVariant values of the properties.
*
- * If @collection_path is %NULL, then the default collection will be
- * used. Use #SECRET_COLLECTION_SESSION to store the password in the session
- * collection, which doesn't get stored across login sessions.
- *
* This method will return immediately and complete asynchronously. The secret
* service may prompt the user. secret_service_prompt() will be used to handle
* any prompts that are required.
@@ -1881,13 +1877,11 @@ secret_service_create_item_dbus_path (SecretService *self,
ItemClosure *closure;
g_return_if_fail (SECRET_IS_SERVICE (self));
+ g_return_if_fail (collection_path != NULL && g_variant_is_object_path (collection_path));
g_return_if_fail (properties != NULL);
g_return_if_fail (value != NULL);
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
- if (collection_path == NULL)
- collection_path = SECRET_COLLECTION_DEFAULT;
-
res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
secret_service_create_item_dbus_path);
closure = g_slice_new0 (ItemClosure);
@@ -1945,7 +1939,7 @@ secret_service_create_item_dbus_path_finish (SecretService *self,
/**
* secret_service_create_item_dbus_path_sync:
* @self: a secret service object
- * @collection_path: (allow-none): the D-Bus path of the collection in which to create item
+ * @collection_path: the D-Bus path of the collection in which to create item
* @properties: (element-type utf8 GLib.Variant): hash table of D-Bus properties
* for the new collection
* @value: the secret value to store in the item
@@ -1989,6 +1983,7 @@ secret_service_create_item_dbus_path_sync (SecretService *self,
gchar *path;
g_return_val_if_fail (SECRET_IS_SERVICE (self), NULL);
+ g_return_val_if_fail (collection_path != NULL && g_variant_is_object_path (collection_path), NULL);
g_return_val_if_fail (properties != NULL, NULL);
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
diff --git a/library/secret-private.h b/library/secret-private.h
index ae021ca..66bb5d4 100644
--- a/library/secret-private.h
+++ b/library/secret-private.h
@@ -64,6 +64,8 @@ gchar * _secret_util_parent_path (const gchar *path
gboolean _secret_util_empty_path (const gchar *path);
+gchar * _secret_util_collection_to_path (const gchar *collection);
+
gint _secret_util_array_index_of (GVariant *array,
GVariant *value);
diff --git a/library/secret-service.h b/library/secret-service.h
index b2e9e5d..6c8d7ca 100644
--- a/library/secret-service.h
+++ b/library/secret-service.h
@@ -223,7 +223,7 @@ gint secret_service_unlock_sync (SecretService
void secret_service_store (SecretService *service,
const SecretSchema *schema,
GHashTable *attributes,
- const gchar *collection_path,
+ const gchar *collection,
const gchar *label,
SecretValue *value,
GCancellable *cancellable,
@@ -237,7 +237,7 @@ gboolean secret_service_store_finish (SecretService
gboolean secret_service_store_sync (SecretService *service,
const SecretSchema *schema,
GHashTable *attributes,
- const gchar *collection_path,
+ const gchar *collection,
const gchar *label,
SecretValue *value,
GCancellable *cancellable,
diff --git a/library/secret-types.h b/library/secret-types.h
index 356d8d7..70d1cf8 100644
--- a/library/secret-types.h
+++ b/library/secret-types.h
@@ -37,9 +37,9 @@ typedef struct _SecretPrompt SecretPrompt;
typedef struct _SecretService SecretService;
typedef struct _SecretValue SecretValue;
-#define SECRET_COLLECTION_DEFAULT "/org/freedesktop/secrets/aliases/default"
+#define SECRET_COLLECTION_DEFAULT "default"
-#define SECRET_COLLECTION_SESSION "/org/freedesktop/secrets/aliases/session"
+#define SECRET_COLLECTION_SESSION "session"
G_END_DECLS
diff --git a/library/secret-util.c b/library/secret-util.c
index bbb27c4..ad4baeb 100644
--- a/library/secret-util.c
+++ b/library/secret-util.c
@@ -109,6 +109,16 @@ _secret_util_empty_path (const gchar *path)
return (g_str_equal (path, "") || g_str_equal (path, "/"));
}
+gchar *
+_secret_util_collection_to_path (const gchar *collection)
+{
+ if (collection == NULL)
+ collection = SECRET_COLLECTION_DEFAULT;
+ if (strchr (collection, '/') == NULL)
+ return g_strdup_printf ("/org/freedesktop/secrets/aliases/%s", collection);
+ return g_strdup (collection);
+}
+
GVariant *
_secret_util_variant_for_properties (GHashTable *properties)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]