diff --git a/docs/reference/libsecret/libsecret-sections.txt b/docs/reference/libsecret/libsecret-sections.txt index 02d6c23..04057fe 100644 --- a/docs/reference/libsecret/libsecret-sections.txt +++ b/docs/reference/libsecret/libsecret-sections.txt @@ -41,6 +41,9 @@ SECRET_TYPE_COLLECTION_FLAGS SecretCollectionPrivate secret_collection_get_type secret_collection_flags_get_type +SecretCollectionCreateFlags +SECRET_TYPE_COLLECTION_CREATE_FLAGS +secret_collection_create_flags_get_type
@@ -49,6 +52,7 @@ secret_collection_flags_get_type SecretItem SecretItemClass SecretItemFlags +SecretItemCreateFlags secret_item_create secret_item_create_finish secret_item_create_sync @@ -90,6 +94,8 @@ SECRET_TYPE_ITEM_FLAGS SecretItemPrivate secret_item_get_type secret_item_flags_get_type +SECRET_TYPE_ITEM_CREATE_FLAGS +secret_item_create_flags_get_type
diff --git a/library/secret-collection.c b/library/secret-collection.c index 0da35ba..58d690b 100644 --- a/library/secret-collection.c +++ b/library/secret-collection.c @@ -64,6 +64,13 @@ * Flags which determine which parts of the #SecretCollection proxy are initialized. */ +/** + * SecretCollectionCreateFlags: + * @SECRET_COLLECTION_CREATE_NONE: no flags + * + * Flags for secret_collection_create(). + */ + /** * SECRET_COLLECTION_DEFAULT: * @@ -943,6 +950,7 @@ typedef struct { SecretCollection *collection; GHashTable *properties; gchar *alias; + SecretCollectionCreateFlags flags; } CreateClosure; static void @@ -1010,7 +1018,8 @@ on_create_service (GObject *source, service = secret_service_get_finish (result, &error); if (error == NULL) { secret_service_create_collection_dbus_path (service, create->properties, - create->alias, create->cancellable, + create->alias, create->flags, + create->cancellable, on_create_path, g_object_ref (async)); g_object_unref (service); @@ -1043,6 +1052,7 @@ collection_properties_new (const gchar *label) * @service: (allow-none): a secret service object * @label: label for the new collection * @alias: (allow-none): alias to assign to the collection + * @flags: currently unused * @cancellable: optional cancellation object * @callback: called when the operation completes * @user_data: data to pass to the callback @@ -1067,6 +1077,7 @@ void secret_collection_create (SecretService *service, const gchar *label, const gchar *alias, + SecretCollectionCreateFlags flags, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) @@ -1084,6 +1095,7 @@ secret_collection_create (SecretService *service, closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL; closure->properties = collection_properties_new (label); closure->alias = g_strdup (alias); + closure->flags = flags; g_simple_async_result_set_op_res_gpointer (res, closure, create_closure_free); if (service == NULL) { @@ -1092,7 +1104,8 @@ secret_collection_create (SecretService *service, } else { secret_service_create_collection_dbus_path (service, closure->properties, - closure->alias, closure->cancellable, + closure->alias, closure->flags, + closure->cancellable, on_create_path, g_object_ref (res)); } @@ -1137,6 +1150,7 @@ secret_collection_create_finish (GAsyncResult *result, * @service: (allow-none): a secret service object * @label: label for the new collection * @alias: (allow-none): alias to assign to the collection + * @flags: currently unused * @cancellable: optional cancellation object * @error: location to place an error on failure * @@ -1162,6 +1176,7 @@ SecretCollection * secret_collection_create_sync (SecretService *service, const gchar *label, const gchar *alias, + SecretCollectionCreateFlags flags, GCancellable *cancellable, GError **error) { @@ -1185,7 +1200,7 @@ secret_collection_create_sync (SecretService *service, properties = collection_properties_new (label); path = secret_service_create_collection_dbus_path_sync (service, properties, alias, - cancellable, error); + flags, cancellable, error); g_hash_table_unref (properties); diff --git a/library/secret-collection.h b/library/secret-collection.h index 3296d09..f367dbe 100644 --- a/library/secret-collection.h +++ b/library/secret-collection.h @@ -31,6 +31,10 @@ typedef enum { SECRET_COLLECTION_LOAD_ITEMS = 1 << 1, } SecretCollectionFlags; +typedef enum { + SECRET_COLLECTION_CREATE_NONE = 0, +} SecretCollectionCreateFlags; + #define SECRET_TYPE_COLLECTION (secret_collection_get_type ()) #define SECRET_COLLECTION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), SECRET_TYPE_COLLECTION, SecretCollection)) #define SECRET_COLLECTION_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), SECRET_TYPE_COLLECTION, SecretCollectionClass)) @@ -89,6 +93,7 @@ void secret_collection_refresh (SecretCollection void secret_collection_create (SecretService *service, const gchar *label, const gchar *alias, + SecretCollectionCreateFlags flags, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); @@ -99,6 +104,7 @@ SecretCollection * secret_collection_create_finish (GAsyncResult *re SecretCollection * secret_collection_create_sync (SecretService *service, const gchar *label, const gchar *alias, + SecretCollectionCreateFlags flags, GCancellable *cancellable, GError **error); diff --git a/library/secret-item.c b/library/secret-item.c index 3180d26..a2a8c1b 100644 --- a/library/secret-item.c +++ b/library/secret-item.c @@ -74,6 +74,14 @@ * Flags which determine which parts of the #SecretItem proxy are initialized. */ +/** + * SecretItemCreateFlags: + * @SECRET_ITEM_CREATE_NONE: no flags + * @SECRET_ITEM_CREATE_REPLACE: replace an item with the same attributes. + * + * Flags for secret_item_create(). + */ + enum { PROP_0, PROP_SERVICE, @@ -745,16 +753,16 @@ item_properties_new (const gchar *label, * @attributes: (element-type utf8 utf8): attributes for the new item * @label: label for the new item * @value: secret value for the new item - * @replace: whether to replace an existing item with the same attributes + * @flags: flags for the creation of the new item * @cancellable: optional cancellation object * @callback: called when the operation completes * @user_data: data to pass to the callback * * Create a new item in the secret service. * - * If the @replace is set to %TRUE, then the secret service will search for - * an item matching the @attributes, and update that item instead of creating - * a new one. + * If the @flags contains %SECRET_ITEM_CREATE_REPLACE, then the secret + * service will search for an item matching the @attributes, and update that item + * instead of creating a new one. * * This method may block indefinitely and should not be used in user interface * threads. The secret service may prompt the user. secret_service_prompt() @@ -766,7 +774,7 @@ secret_item_create (SecretCollection *collection, GHashTable *attributes, const gchar *label, SecretValue *value, - gboolean replace, + SecretItemCreateFlags flags, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) @@ -800,7 +808,7 @@ secret_item_create (SecretCollection *collection, collection_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection)); secret_service_create_item_dbus_path (service, collection_path, properties, - value, replace, cancellable, + value, flags, cancellable, on_create_path, g_object_ref (res)); g_hash_table_unref (properties); @@ -848,15 +856,15 @@ secret_item_create_finish (GAsyncResult *result, * @attributes: (element-type utf8 utf8): attributes for the new item * @label: label for the new item * @value: secret value for the new item - * @replace: whether to replace an existing item with the same attributes + * @flags: flags for the creation of the new item * @cancellable: optional cancellation object * @error: location to place an error on failure * * Create a new item in the secret service. * - * If the @replace is set to %TRUE, then the secret service will search for - * an item matching the @attributes, and update that item instead of creating - * a new one. + * If the @flags contains %SECRET_ITEM_CREATE_REPLACE, then the secret + * service will search for an item matching the @attributes, and update that item + * instead of creating a new one. * * This method may block indefinitely and should not be used in user interface * threads. The secret service may prompt the user. secret_service_prompt() @@ -871,7 +879,7 @@ secret_item_create_sync (SecretCollection *collection, GHashTable *attributes, const gchar *label, SecretValue *value, - gboolean replace, + SecretItemCreateFlags flags, GCancellable *cancellable, GError **error) { @@ -898,7 +906,7 @@ secret_item_create_sync (SecretCollection *collection, collection_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection)); path = secret_service_create_item_dbus_path_sync (service, collection_path, properties, - value, replace, cancellable, error); + value, flags, cancellable, error); if (path != NULL) { item = secret_item_new_for_dbus_path_sync (service, path, SECRET_ITEM_NONE, diff --git a/library/secret-item.h b/library/secret-item.h index 85863cb..05dbb1c 100644 --- a/library/secret-item.h +++ b/library/secret-item.h @@ -32,6 +32,11 @@ typedef enum { SECRET_ITEM_LOAD_SECRET = 1 << 1 } SecretItemFlags; +typedef enum { + SECRET_ITEM_CREATE_NONE = 0, + SECRET_ITEM_CREATE_REPLACE = 1 << 1 +} SecretItemCreateFlags; + #define SECRET_TYPE_ITEM (secret_item_get_type ()) #define SECRET_ITEM(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), SECRET_TYPE_ITEM, SecretItem)) #define SECRET_ITEM_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), SECRET_TYPE_ITEM, SecretItemClass)) @@ -65,7 +70,7 @@ void secret_item_create (SecretCollection *co GHashTable *attributes, const gchar *label, SecretValue *value, - gboolean replace, + SecretItemCreateFlags flags, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); @@ -78,7 +83,7 @@ SecretItem * secret_item_create_sync (SecretCollection *co GHashTable *attributes, const gchar *label, SecretValue *value, - gboolean replace, + SecretItemCreateFlags flags, GCancellable *cancellable, GError **error); diff --git a/library/secret-methods.c b/library/secret-methods.c index a45f04c..55b658f 100644 --- a/library/secret-methods.c +++ b/library/secret-methods.c @@ -1001,7 +1001,7 @@ on_store_service (GObject *source, if (error == NULL) { secret_service_create_item_dbus_path (service, store->collection_path, store->properties, store->value, - TRUE, store->cancellable, + SECRET_ITEM_CREATE_REPLACE, store->cancellable, on_store_create, g_object_ref (async)); g_object_unref (service); @@ -1097,7 +1097,7 @@ secret_service_store (SecretService *service, } else { secret_service_create_item_dbus_path (service, store->collection_path, store->properties, store->value, - TRUE, store->cancellable, + SECRET_ITEM_CREATE_REPLACE, store->cancellable, on_store_create, g_object_ref (async)); } diff --git a/library/secret-paths.c b/library/secret-paths.c index dbea6e4..a4068b8 100644 --- a/library/secret-paths.c +++ b/library/secret-paths.c @@ -1684,6 +1684,7 @@ on_create_collection_called (GObject *source, * the new collection * @alias: (allow-none): an alias to check for before creating the new * collection, or to assign to the new collection + * @flags: not currently used * @cancellable: optional cancellation object * @callback: called when the operation completes * @user_data: data to be passed to the callback @@ -1716,6 +1717,7 @@ void secret_service_create_collection_dbus_path (SecretService *self, GHashTable *properties, const gchar *alias, + SecretCollectionCreateFlags flags, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) @@ -1800,6 +1802,7 @@ secret_service_create_collection_dbus_path_finish (SecretService *self, * for the new collection * @alias: (allow-none): an alias to check for before creating the new * collection, or to assign to the new collection + * @flags: not currently used * @cancellable: optional cancellation object * @error: location to place an error on failure * @@ -1832,6 +1835,7 @@ gchar * secret_service_create_collection_dbus_path_sync (SecretService *self, GHashTable *properties, const gchar *alias, + SecretCollectionCreateFlags flags, GCancellable *cancellable, GError **error) { @@ -1846,7 +1850,7 @@ secret_service_create_collection_dbus_path_sync (SecretService *self, sync = _secret_sync_new (); g_main_context_push_thread_default (sync->context); - secret_service_create_collection_dbus_path (self, properties, alias, cancellable, + secret_service_create_collection_dbus_path (self, properties, alias, flags, cancellable, _secret_sync_on_result, sync); g_main_loop_run (sync->loop); @@ -1989,7 +1993,7 @@ on_create_item_session (GObject *source, * @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 - * @replace: whether to replace an item with the matching attributes + * @flags: flags for the creation of the new item * @cancellable: optional cancellation object * @callback: called when the operation completes * @user_data: data to be passed to the callback @@ -2001,9 +2005,9 @@ on_create_item_session (GObject *source, * rather than using this function. Using this method requires that you setup * a correct hash table of D-Bus @properties for the new collection. * - * If @replace is set to %TRUE, and an item already in the collection matches - * the attributes (specified in @properties) then the item will be updated - * instead of creating a new item. + * If the @flags contains %SECRET_ITEM_CREATE_REPLACE, then the secret + * service will search for an item matching the @attributes, and update that item + * instead of creating a new one. * * @properties is a set of properties for the new collection. The keys in the * hash table should be interface.property strings like @@ -2019,7 +2023,7 @@ secret_service_create_item_dbus_path (SecretService *self, const gchar *collection_path, GHashTable *properties, SecretValue *value, - gboolean replace, + SecretItemCreateFlags flags, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) @@ -2039,7 +2043,7 @@ secret_service_create_item_dbus_path (SecretService *self, closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL; closure->properties = _secret_util_variant_for_properties (properties); g_variant_ref_sink (closure->properties); - closure->replace = replace; + closure->replace = flags & SECRET_ITEM_CREATE_REPLACE; closure->value = secret_value_ref (value); closure->collection_path = g_strdup (collection_path); g_simple_async_result_set_op_res_gpointer (res, closure, item_closure_free); @@ -2094,7 +2098,7 @@ secret_service_create_item_dbus_path_finish (SecretService *self, * @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 - * @replace: whether to replace an item with the matching attributes + * @flags: flags for the creation of the new item * @cancellable: optional cancellation object * @error: location to place an error on failure * @@ -2105,9 +2109,9 @@ secret_service_create_item_dbus_path_finish (SecretService *self, * rather than using this function. Using this method requires that you setup * a correct hash table of D-Bus @properties for the new collection. * - * If @replace is set to %TRUE, and an item already in the collection matches - * the attributes (specified in @properties) then the item will be updated - * instead of creating a new item. + * If the @flags contains %SECRET_ITEM_CREATE_REPLACE, then the secret + * service will search for an item matching the @attributes, and update that item + * instead of creating a new one. * * @properties is a set of properties for the new collection. The keys in the * hash table should be interface.property strings like @@ -2126,7 +2130,7 @@ secret_service_create_item_dbus_path_sync (SecretService *self, const gchar *collection_path, GHashTable *properties, SecretValue *value, - gboolean replace, + SecretItemCreateFlags flags, GCancellable *cancellable, GError **error) { @@ -2142,7 +2146,7 @@ secret_service_create_item_dbus_path_sync (SecretService *self, sync = _secret_sync_new (); g_main_context_push_thread_default (sync->context); - secret_service_create_item_dbus_path (self, collection_path, properties, value, replace, + secret_service_create_item_dbus_path (self, collection_path, properties, value, flags, cancellable, _secret_sync_on_result, sync); g_main_loop_run (sync->loop); diff --git a/library/secret-paths.h b/library/secret-paths.h index 644bf00..19cb501 100644 --- a/library/secret-paths.h +++ b/library/secret-paths.h @@ -203,6 +203,7 @@ gboolean secret_service_delete_item_dbus_path_sync (SecretSe void secret_service_create_collection_dbus_path (SecretService *self, GHashTable *properties, const gchar *alias, + SecretCollectionCreateFlags flags, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); @@ -214,6 +215,7 @@ gchar * secret_service_create_collection_dbus_path_finish (SecretSe gchar * secret_service_create_collection_dbus_path_sync (SecretService *self, GHashTable *properties, const gchar *alias, + SecretCollectionCreateFlags flags, GCancellable *cancellable, GError **error); @@ -221,7 +223,7 @@ void secret_service_create_item_dbus_path (SecretSe const gchar *collection_path, GHashTable *properties, SecretValue *value, - gboolean replace, + SecretItemCreateFlags flags, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); @@ -234,7 +236,7 @@ gchar * secret_service_create_item_dbus_path_sync (SecretSe const gchar *collection_path, GHashTable *properties, SecretValue *value, - gboolean replace, + SecretItemCreateFlags flags, GCancellable *cancellable, GError **error); diff --git a/library/tests/test-collection.c b/library/tests/test-collection.c index 0b205c6..feb87e6 100644 --- a/library/tests/test-collection.c +++ b/library/tests/test-collection.c @@ -233,7 +233,8 @@ test_create_sync (Test *test, GError *error = NULL; SecretCollection *collection; - collection = secret_collection_create_sync (test->service, "Train", NULL, NULL, &error); + collection = secret_collection_create_sync (test->service, "Train", NULL, + SECRET_COLLECTION_CREATE_NONE, NULL, &error); g_assert_no_error (error); g_assert (g_str_has_prefix (g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection)), "/org/freedesktop/secrets/collection")); @@ -252,7 +253,9 @@ test_create_async (Test *test, SecretCollection *collection; GAsyncResult *result = NULL; - secret_collection_create (test->service, "Train", NULL, NULL, on_async_result, &result); + secret_collection_create (test->service, "Train", NULL, + SECRET_COLLECTION_CREATE_NONE, + NULL, on_async_result, &result); g_assert (result == NULL); egg_test_wait (); diff --git a/library/tests/test-item.c b/library/tests/test-item.c index c2ab9b2..a99a9b5 100644 --- a/library/tests/test-item.c +++ b/library/tests/test-item.c @@ -190,7 +190,7 @@ test_create_sync (Test *test, value = secret_value_new ("Hoohah", -1, "text/plain"); item = secret_item_create_sync (collection, &MOCK_SCHEMA, attributes, "Tunnel", - value, FALSE, NULL, &error); + value, SECRET_ITEM_CREATE_NONE, NULL, &error); g_assert_no_error (error); g_hash_table_unref (attributes); @@ -229,7 +229,7 @@ test_create_async (Test *test, value = secret_value_new ("Hoohah", -1, "text/plain"); secret_item_create (collection, &MOCK_SCHEMA, attributes, "Tunnel", - value, FALSE, NULL, on_async_result, &result); + value, SECRET_ITEM_CREATE_NONE, NULL, on_async_result, &result); g_assert_no_error (error); g_hash_table_unref (attributes); diff --git a/library/tests/test-paths.c b/library/tests/test-paths.c index 1c7a586..8ca5568 100644 --- a/library/tests/test-paths.c +++ b/library/tests/test-paths.c @@ -544,7 +544,8 @@ test_collection_sync (Test *test, g_variant_ref_sink (g_variant_new_string ("Wheeee"))); path = secret_service_create_collection_dbus_path_sync (test->service, properties, - NULL, NULL, &error); + NULL, SECRET_COLLECTION_CREATE_NONE, + NULL, &error); g_hash_table_unref (properties); @@ -570,7 +571,8 @@ test_collection_async (Test *test, g_variant_ref_sink (g_variant_new_string ("Wheeee"))); secret_service_create_collection_dbus_path (test->service, properties, - NULL, NULL, on_complete_get_result, &result); + NULL, SECRET_COLLECTION_CREATE_NONE, + NULL, on_complete_get_result, &result); g_hash_table_unref (properties); g_assert (result == NULL); @@ -615,7 +617,7 @@ test_item_sync (Test *test, value = secret_value_new ("andmoreandmore", -1, "text/plain"); path = secret_service_create_item_dbus_path_sync (test->service, collection_path, - properties, value, FALSE, + properties, value, SECRET_ITEM_CREATE_NONE, NULL, &error); secret_value_unref (value); @@ -657,7 +659,7 @@ test_item_async (Test *test, value = secret_value_new ("andmoreandmore", -1, "text/plain"); secret_service_create_item_dbus_path (test->service, collection_path, - properties, value, FALSE, + properties, value, SECRET_ITEM_CREATE_NONE, NULL, on_complete_get_result, &result); g_assert (result == NULL);