mirror of
https://gitlab.gnome.org/GNOME/libsecret.git
synced 2025-01-03 02:28:53 +00:00
secret_service_search() accepts a SecretSchema
* For validation and adding the xdg:schema attribute
This commit is contained in:
parent
889f6d66b7
commit
3f0c69d862
@ -215,6 +215,7 @@ on_search_paths (GObject *source,
|
||||
/**
|
||||
* secret_service_search:
|
||||
* @self: the secret service
|
||||
* @schema: (allow-none): the schema for the attributes
|
||||
* @attributes: (element-type utf8 utf8): search for items matching these attributes
|
||||
* @flags: search option flags
|
||||
* @cancellable: optional cancellation object
|
||||
@ -239,6 +240,7 @@ on_search_paths (GObject *source,
|
||||
*/
|
||||
void
|
||||
secret_service_search (SecretService *self,
|
||||
const SecretSchema *schema,
|
||||
GHashTable *attributes,
|
||||
SecretSearchFlags flags,
|
||||
GCancellable *cancellable,
|
||||
@ -252,6 +254,10 @@ secret_service_search (SecretService *self,
|
||||
g_return_if_fail (attributes != NULL);
|
||||
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
||||
|
||||
/* Warnings raised already */
|
||||
if (schema != NULL && !_secret_attributes_validate (schema, attributes))
|
||||
return;
|
||||
|
||||
res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
|
||||
secret_service_search);
|
||||
closure = g_slice_new0 (SearchClosure);
|
||||
@ -261,7 +267,7 @@ secret_service_search (SecretService *self,
|
||||
closure->flags = flags;
|
||||
g_simple_async_result_set_op_res_gpointer (res, closure, search_closure_free);
|
||||
|
||||
secret_service_search_for_paths (self, attributes, cancellable,
|
||||
secret_service_search_for_paths (self, schema, attributes, cancellable,
|
||||
on_search_paths, g_object_ref (res));
|
||||
|
||||
g_object_unref (res);
|
||||
@ -337,6 +343,7 @@ service_load_items_sync (SecretService *self,
|
||||
/**
|
||||
* secret_service_search_sync:
|
||||
* @self: the secret service
|
||||
* @schema: (allow-none): the schema for the attributes
|
||||
* @attributes: (element-type utf8 utf8): search for items matching these attributes
|
||||
* @flags: search option flags
|
||||
* @cancellable: optional cancellation object
|
||||
@ -366,6 +373,7 @@ service_load_items_sync (SecretService *self,
|
||||
*/
|
||||
GList *
|
||||
secret_service_search_sync (SecretService *self,
|
||||
const SecretSchema *schema,
|
||||
GHashTable *attributes,
|
||||
SecretSearchFlags flags,
|
||||
GCancellable *cancellable,
|
||||
@ -384,7 +392,11 @@ secret_service_search_sync (SecretService *self,
|
||||
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||
|
||||
if (!secret_service_search_for_paths_sync (self, attributes, cancellable,
|
||||
/* Warnings raised already */
|
||||
if (schema != NULL && !_secret_attributes_validate (schema, attributes))
|
||||
return NULL;
|
||||
|
||||
if (!secret_service_search_for_paths_sync (self, schema, attributes, cancellable,
|
||||
&unlocked_paths, &locked_paths, error))
|
||||
return NULL;
|
||||
|
||||
|
@ -62,6 +62,7 @@ on_search_items_complete (GObject *source,
|
||||
/**
|
||||
* secret_service_search_for_paths:
|
||||
* @self: the secret service
|
||||
* @schema: (allow-none): the schema for the attributes
|
||||
* @attributes: (element-type utf8 utf8): search for items matching these attributes
|
||||
* @cancellable: optional cancellation object
|
||||
* @callback: called when the operation completes
|
||||
@ -80,16 +81,26 @@ on_search_items_complete (GObject *source,
|
||||
*/
|
||||
void
|
||||
secret_service_search_for_paths (SecretService *self,
|
||||
const SecretSchema *schema,
|
||||
GHashTable *attributes,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
const gchar *schema_name = NULL;
|
||||
|
||||
g_return_if_fail (SECRET_IS_SERVICE (self));
|
||||
g_return_if_fail (attributes != NULL);
|
||||
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
||||
|
||||
_secret_service_search_for_paths_variant (self, _secret_attributes_to_variant (attributes, NULL),
|
||||
/* Warnings raised already */
|
||||
if (schema != NULL && !_secret_attributes_validate (schema, attributes))
|
||||
return;
|
||||
|
||||
if (schema != NULL && !(schema->flags & SECRET_SCHEMA_DONT_MATCH_NAME))
|
||||
schema_name = schema->name;
|
||||
|
||||
_secret_service_search_for_paths_variant (self, _secret_attributes_to_variant (attributes, schema_name),
|
||||
cancellable, callback, user_data);
|
||||
}
|
||||
|
||||
@ -177,6 +188,7 @@ secret_service_search_for_paths_finish (SecretService *self,
|
||||
/**
|
||||
* secret_service_search_for_paths_sync:
|
||||
* @self: the secret service
|
||||
* @schema: (allow-none): the schema for the attributes
|
||||
* @attributes: (element-type utf8 utf8): search for items matching these attributes
|
||||
* @cancellable: optional cancellation object
|
||||
* @unlocked: (out) (transfer full) (array zero-terminated=1) (allow-none):
|
||||
@ -205,12 +217,14 @@ secret_service_search_for_paths_finish (SecretService *self,
|
||||
*/
|
||||
gboolean
|
||||
secret_service_search_for_paths_sync (SecretService *self,
|
||||
const SecretSchema *schema,
|
||||
GHashTable *attributes,
|
||||
GCancellable *cancellable,
|
||||
gchar ***unlocked,
|
||||
gchar ***locked,
|
||||
GError **error)
|
||||
{
|
||||
const gchar *schema_name = NULL;
|
||||
gchar **dummy = NULL;
|
||||
GVariant *response;
|
||||
|
||||
@ -219,9 +233,16 @@ secret_service_search_for_paths_sync (SecretService *self,
|
||||
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||
|
||||
/* Warnings raised already */
|
||||
if (schema != NULL && !_secret_attributes_validate (schema, attributes))
|
||||
return FALSE;
|
||||
|
||||
if (schema != NULL && !(schema->flags & SECRET_SCHEMA_DONT_MATCH_NAME))
|
||||
schema_name = schema->name;
|
||||
|
||||
response = g_dbus_proxy_call_sync (G_DBUS_PROXY (self), "SearchItems",
|
||||
g_variant_new ("(@a{ss})",
|
||||
_secret_attributes_to_variant (attributes, NULL)),
|
||||
_secret_attributes_to_variant (attributes, schema_name)),
|
||||
G_DBUS_CALL_FLAGS_NONE, -1, cancellable, error);
|
||||
|
||||
if (response != NULL) {
|
||||
|
@ -30,6 +30,7 @@
|
||||
G_BEGIN_DECLS
|
||||
|
||||
void secret_service_search_for_paths (SecretService *self,
|
||||
const SecretSchema *schema,
|
||||
GHashTable *attributes,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
@ -42,6 +43,7 @@ gboolean secret_service_search_for_paths_finish (SecretService
|
||||
GError **error);
|
||||
|
||||
gboolean secret_service_search_for_paths_sync (SecretService *self,
|
||||
const SecretSchema *schema,
|
||||
GHashTable *attributes,
|
||||
GCancellable *cancellable,
|
||||
gchar ***unlocked,
|
||||
|
@ -151,6 +151,7 @@ gboolean secret_service_ensure_collections_sync (SecretService
|
||||
GError **error);
|
||||
|
||||
void secret_service_search (SecretService *self,
|
||||
const SecretSchema *schema,
|
||||
GHashTable *attributes,
|
||||
SecretSearchFlags flags,
|
||||
GCancellable *cancellable,
|
||||
@ -162,6 +163,7 @@ GList * secret_service_search_finish (SecretService
|
||||
GError **error);
|
||||
|
||||
GList * secret_service_search_sync (SecretService *self,
|
||||
const SecretSchema *schema,
|
||||
GHashTable *attributes,
|
||||
SecretSearchFlags flags,
|
||||
GCancellable *cancellable,
|
||||
|
@ -127,8 +127,8 @@ test_search_sync (Test *test,
|
||||
attributes = g_hash_table_new (g_str_hash, g_str_equal);
|
||||
g_hash_table_insert (attributes, "number", "1");
|
||||
|
||||
items = secret_service_search_sync (test->service, attributes, SECRET_SEARCH_NONE,
|
||||
NULL, &error);
|
||||
items = secret_service_search_sync (test->service, &MOCK_SCHEMA, attributes,
|
||||
SECRET_SEARCH_NONE, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_hash_table_unref (attributes);
|
||||
|
||||
@ -151,7 +151,8 @@ test_search_async (Test *test,
|
||||
attributes = g_hash_table_new (g_str_hash, g_str_equal);
|
||||
g_hash_table_insert (attributes, "number", "1");
|
||||
|
||||
secret_service_search (test->service, attributes, SECRET_SEARCH_NONE, NULL,
|
||||
secret_service_search (test->service, &MOCK_SCHEMA, attributes,
|
||||
SECRET_SEARCH_NONE, NULL,
|
||||
on_complete_get_result, &result);
|
||||
g_hash_table_unref (attributes);
|
||||
g_assert (result == NULL);
|
||||
@ -181,8 +182,8 @@ test_search_all_sync (Test *test,
|
||||
attributes = g_hash_table_new (g_str_hash, g_str_equal);
|
||||
g_hash_table_insert (attributes, "number", "1");
|
||||
|
||||
items = secret_service_search_sync (test->service, attributes, SECRET_SEARCH_ALL,
|
||||
NULL, &error);
|
||||
items = secret_service_search_sync (test->service, &MOCK_SCHEMA, attributes,
|
||||
SECRET_SEARCH_ALL, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_hash_table_unref (attributes);
|
||||
|
||||
@ -212,7 +213,8 @@ test_search_all_async (Test *test,
|
||||
attributes = g_hash_table_new (g_str_hash, g_str_equal);
|
||||
g_hash_table_insert (attributes, "number", "1");
|
||||
|
||||
secret_service_search (test->service, attributes, SECRET_SEARCH_ALL, NULL,
|
||||
secret_service_search (test->service, &MOCK_SCHEMA, attributes,
|
||||
SECRET_SEARCH_ALL, NULL,
|
||||
on_complete_get_result, &result);
|
||||
g_hash_table_unref (attributes);
|
||||
g_assert (result == NULL);
|
||||
@ -249,7 +251,7 @@ test_search_unlock_sync (Test *test,
|
||||
attributes = g_hash_table_new (g_str_hash, g_str_equal);
|
||||
g_hash_table_insert (attributes, "number", "1");
|
||||
|
||||
items = secret_service_search_sync (test->service, attributes,
|
||||
items = secret_service_search_sync (test->service, &MOCK_SCHEMA, attributes,
|
||||
SECRET_SEARCH_ALL | SECRET_SEARCH_UNLOCK,
|
||||
NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
@ -281,7 +283,7 @@ test_search_unlock_async (Test *test,
|
||||
attributes = g_hash_table_new (g_str_hash, g_str_equal);
|
||||
g_hash_table_insert (attributes, "number", "1");
|
||||
|
||||
secret_service_search (test->service, attributes,
|
||||
secret_service_search (test->service, &MOCK_SCHEMA, attributes,
|
||||
SECRET_SEARCH_ALL | SECRET_SEARCH_UNLOCK, NULL,
|
||||
on_complete_get_result, &result);
|
||||
g_hash_table_unref (attributes);
|
||||
@ -320,7 +322,7 @@ test_search_secrets_sync (Test *test,
|
||||
attributes = g_hash_table_new (g_str_hash, g_str_equal);
|
||||
g_hash_table_insert (attributes, "number", "1");
|
||||
|
||||
items = secret_service_search_sync (test->service, attributes,
|
||||
items = secret_service_search_sync (test->service, &MOCK_SCHEMA, attributes,
|
||||
SECRET_SEARCH_ALL | SECRET_SEARCH_LOAD_SECRETS,
|
||||
NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
@ -355,7 +357,7 @@ test_search_secrets_async (Test *test,
|
||||
attributes = g_hash_table_new (g_str_hash, g_str_equal);
|
||||
g_hash_table_insert (attributes, "number", "1");
|
||||
|
||||
secret_service_search (test->service, attributes,
|
||||
secret_service_search (test->service, &MOCK_SCHEMA, attributes,
|
||||
SECRET_SEARCH_ALL | SECRET_SEARCH_LOAD_SECRETS, NULL,
|
||||
on_complete_get_result, &result);
|
||||
g_hash_table_unref (attributes);
|
||||
@ -731,8 +733,8 @@ test_store_sync (Test *test,
|
||||
g_hash_table_insert (attributes, "string", "seventeen");
|
||||
g_hash_table_insert (attributes, "number", "17");
|
||||
|
||||
ret = secret_service_search_for_paths_sync (test->service, attributes, NULL,
|
||||
&paths, NULL, &error);
|
||||
ret = secret_service_search_for_paths_sync (test->service, &MOCK_SCHEMA, attributes,
|
||||
NULL, &paths, NULL, &error);
|
||||
g_hash_table_unref (attributes);
|
||||
g_assert (ret == TRUE);
|
||||
|
||||
@ -784,8 +786,8 @@ test_store_replace (Test *test,
|
||||
g_hash_table_insert (attributes, "string", "seventeen");
|
||||
g_hash_table_insert (attributes, "number", "17");
|
||||
|
||||
ret = secret_service_search_for_paths_sync (test->service, attributes, NULL,
|
||||
&paths, NULL, &error);
|
||||
ret = secret_service_search_for_paths_sync (test->service, &MOCK_SCHEMA, attributes,
|
||||
NULL, &paths, NULL, &error);
|
||||
g_hash_table_unref (attributes);
|
||||
g_assert (ret == TRUE);
|
||||
|
||||
@ -832,8 +834,8 @@ test_store_async (Test *test,
|
||||
g_hash_table_insert (attributes, "string", "seventeen");
|
||||
g_hash_table_insert (attributes, "number", "17");
|
||||
|
||||
ret = secret_service_search_for_paths_sync (test->service, attributes, NULL,
|
||||
&paths, NULL, &error);
|
||||
ret = secret_service_search_for_paths_sync (test->service, &MOCK_SCHEMA, attributes,
|
||||
NULL, &paths, NULL, &error);
|
||||
g_hash_table_unref (attributes);
|
||||
g_assert (ret == TRUE);
|
||||
|
||||
|
@ -129,8 +129,8 @@ test_search_paths_sync (Test *test,
|
||||
attributes = g_hash_table_new (g_str_hash, g_str_equal);
|
||||
g_hash_table_insert (attributes, "number", "1");
|
||||
|
||||
ret = secret_service_search_for_paths_sync (test->service, attributes, NULL,
|
||||
&unlocked, &locked, &error);
|
||||
ret = secret_service_search_for_paths_sync (test->service, &MOCK_SCHEMA, attributes, NULL,
|
||||
&unlocked, &locked, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (ret == TRUE);
|
||||
|
||||
@ -160,7 +160,7 @@ test_search_paths_async (Test *test,
|
||||
attributes = g_hash_table_new (g_str_hash, g_str_equal);
|
||||
g_hash_table_insert (attributes, "number", "1");
|
||||
|
||||
secret_service_search_for_paths (test->service, attributes, NULL,
|
||||
secret_service_search_for_paths (test->service, &MOCK_SCHEMA, attributes, NULL,
|
||||
on_complete_get_result, &result);
|
||||
egg_test_wait ();
|
||||
|
||||
@ -197,7 +197,7 @@ test_search_paths_nulls (Test *test,
|
||||
attributes = g_hash_table_new (g_str_hash, g_str_equal);
|
||||
g_hash_table_insert (attributes, "number", "1");
|
||||
|
||||
ret = secret_service_search_for_paths_sync (test->service, attributes, NULL,
|
||||
ret = secret_service_search_for_paths_sync (test->service, &MOCK_SCHEMA, attributes, NULL,
|
||||
&paths, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (ret == TRUE);
|
||||
@ -205,7 +205,7 @@ test_search_paths_nulls (Test *test,
|
||||
g_assert_cmpstr (paths[0], ==, "/org/freedesktop/secrets/collection/english/1");
|
||||
g_strfreev (paths);
|
||||
|
||||
ret = secret_service_search_for_paths_sync (test->service, attributes, NULL,
|
||||
ret = secret_service_search_for_paths_sync (test->service, &MOCK_SCHEMA, attributes, NULL,
|
||||
NULL, &paths, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (ret == TRUE);
|
||||
@ -213,12 +213,12 @@ test_search_paths_nulls (Test *test,
|
||||
g_assert_cmpstr (paths[0], ==, "/org/freedesktop/secrets/collection/spanish/10");
|
||||
g_strfreev (paths);
|
||||
|
||||
ret = secret_service_search_for_paths_sync (test->service, attributes, NULL,
|
||||
ret = secret_service_search_for_paths_sync (test->service, &MOCK_SCHEMA, attributes, NULL,
|
||||
NULL, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (ret == TRUE);
|
||||
|
||||
secret_service_search_for_paths (test->service, attributes, NULL,
|
||||
secret_service_search_for_paths (test->service, &MOCK_SCHEMA, attributes, NULL,
|
||||
on_complete_get_result, &result);
|
||||
egg_test_wait ();
|
||||
g_assert (G_IS_ASYNC_RESULT (result));
|
||||
@ -231,7 +231,7 @@ test_search_paths_nulls (Test *test,
|
||||
g_strfreev (paths);
|
||||
g_clear_object (&result);
|
||||
|
||||
secret_service_search_for_paths (test->service, attributes, NULL,
|
||||
secret_service_search_for_paths (test->service, &MOCK_SCHEMA, attributes, NULL,
|
||||
on_complete_get_result, &result);
|
||||
egg_test_wait ();
|
||||
g_assert (G_IS_ASYNC_RESULT (result));
|
||||
@ -244,7 +244,7 @@ test_search_paths_nulls (Test *test,
|
||||
g_strfreev (paths);
|
||||
g_clear_object (&result);
|
||||
|
||||
secret_service_search_for_paths (test->service, attributes, NULL,
|
||||
secret_service_search_for_paths (test->service, &MOCK_SCHEMA, attributes, NULL,
|
||||
on_complete_get_result, &result);
|
||||
egg_test_wait ();
|
||||
g_assert (G_IS_ASYNC_RESULT (result));
|
||||
|
Loading…
Reference in New Issue
Block a user