mirror of
https://gitlab.gnome.org/GNOME/libsecret.git
synced 2024-12-22 12:48:51 +00:00
Allow passing SecretSchema to secret_item_create() and set_attributes()
This commit is contained in:
parent
c22bc528df
commit
3c3e05eb11
@ -45,7 +45,7 @@
|
|||||||
* Each item has a set of attributes, which are used to locate the item later.
|
* Each item has a set of attributes, which are used to locate the item later.
|
||||||
* These are not stored or transferred in a secure manner. Each attribute has
|
* These are not stored or transferred in a secure manner. Each attribute has
|
||||||
* a string name and a string value. Use secret_service_search() to search for
|
* a string name and a string value. Use secret_service_search() to search for
|
||||||
* items based on their attributes, and secret_item_set_attributes to change
|
* items based on their attributes, and secret_item_set_attributes() to change
|
||||||
* the attributes associated with an item.
|
* the attributes associated with an item.
|
||||||
*
|
*
|
||||||
* Items can be created with secret_item_create() or secret_service_store().
|
* Items can be created with secret_item_create() or secret_service_store().
|
||||||
@ -185,7 +185,7 @@ secret_item_set_property (GObject *obj,
|
|||||||
self->pv->init_flags = g_value_get_flags (value);
|
self->pv->init_flags = g_value_get_flags (value);
|
||||||
break;
|
break;
|
||||||
case PROP_ATTRIBUTES:
|
case PROP_ATTRIBUTES:
|
||||||
secret_item_set_attributes (self, g_value_get_boxed (value),
|
secret_item_set_attributes (self, NULL, g_value_get_boxed (value),
|
||||||
self->pv->cancellable, on_set_attributes,
|
self->pv->cancellable, on_set_attributes,
|
||||||
g_object_ref (self));
|
g_object_ref (self));
|
||||||
break;
|
break;
|
||||||
@ -712,11 +712,16 @@ on_create_path (GObject *source,
|
|||||||
|
|
||||||
static GHashTable *
|
static GHashTable *
|
||||||
item_properties_new (const gchar *label,
|
item_properties_new (const gchar *label,
|
||||||
|
const SecretSchema *schema,
|
||||||
GHashTable *attributes)
|
GHashTable *attributes)
|
||||||
{
|
{
|
||||||
|
const gchar *schema_name = NULL;
|
||||||
GHashTable *properties;
|
GHashTable *properties;
|
||||||
GVariant *value;
|
GVariant *value;
|
||||||
|
|
||||||
|
if (schema != NULL)
|
||||||
|
schema_name = schema->name;
|
||||||
|
|
||||||
properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
|
properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
|
||||||
(GDestroyNotify)g_variant_unref);
|
(GDestroyNotify)g_variant_unref);
|
||||||
|
|
||||||
@ -725,7 +730,7 @@ item_properties_new (const gchar *label,
|
|||||||
SECRET_ITEM_INTERFACE ".Label",
|
SECRET_ITEM_INTERFACE ".Label",
|
||||||
g_variant_ref_sink (value));
|
g_variant_ref_sink (value));
|
||||||
|
|
||||||
value = _secret_attributes_to_variant (attributes, NULL);
|
value = _secret_attributes_to_variant (attributes, schema_name);
|
||||||
g_hash_table_insert (properties,
|
g_hash_table_insert (properties,
|
||||||
SECRET_ITEM_INTERFACE ".Attributes",
|
SECRET_ITEM_INTERFACE ".Attributes",
|
||||||
g_variant_ref_sink (value));
|
g_variant_ref_sink (value));
|
||||||
@ -736,8 +741,9 @@ item_properties_new (const gchar *label,
|
|||||||
/**
|
/**
|
||||||
* secret_item_create:
|
* secret_item_create:
|
||||||
* @collection: a secret collection to create this item in
|
* @collection: a secret collection to create this item in
|
||||||
* @label: label for the new item
|
* @schema: (allow-none): the schema for the attributes
|
||||||
* @attributes: (element-type utf8 utf8): attributes for the new item
|
* @attributes: (element-type utf8 utf8): attributes for the new item
|
||||||
|
* @label: label for the new item
|
||||||
* @value: secret value for the new item
|
* @value: secret value for the new item
|
||||||
* @replace: whether to replace an existing item with the same attributes
|
* @replace: whether to replace an existing item with the same attributes
|
||||||
* @cancellable: optional cancellation object
|
* @cancellable: optional cancellation object
|
||||||
@ -756,8 +762,9 @@ item_properties_new (const gchar *label,
|
|||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
secret_item_create (SecretCollection *collection,
|
secret_item_create (SecretCollection *collection,
|
||||||
const gchar *label,
|
const SecretSchema *schema,
|
||||||
GHashTable *attributes,
|
GHashTable *attributes,
|
||||||
|
const gchar *label,
|
||||||
SecretValue *value,
|
SecretValue *value,
|
||||||
gboolean replace,
|
gboolean replace,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
@ -776,6 +783,10 @@ secret_item_create (SecretCollection *collection,
|
|||||||
g_return_if_fail (value != NULL);
|
g_return_if_fail (value != NULL);
|
||||||
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
||||||
|
|
||||||
|
/* Warnings raised already */
|
||||||
|
if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, FALSE))
|
||||||
|
return;
|
||||||
|
|
||||||
res = g_simple_async_result_new (NULL, callback, user_data,
|
res = g_simple_async_result_new (NULL, callback, user_data,
|
||||||
secret_item_create);
|
secret_item_create);
|
||||||
closure = g_slice_new0 (CreateClosure);
|
closure = g_slice_new0 (CreateClosure);
|
||||||
@ -783,7 +794,7 @@ secret_item_create (SecretCollection *collection,
|
|||||||
closure->value = secret_value_ref (value);
|
closure->value = secret_value_ref (value);
|
||||||
g_simple_async_result_set_op_res_gpointer (res, closure, create_closure_free);
|
g_simple_async_result_set_op_res_gpointer (res, closure, create_closure_free);
|
||||||
|
|
||||||
properties = item_properties_new (label, attributes);
|
properties = item_properties_new (label, schema, attributes);
|
||||||
g_object_get (collection, "service", &service, NULL);
|
g_object_get (collection, "service", &service, NULL);
|
||||||
|
|
||||||
collection_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection));
|
collection_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection));
|
||||||
@ -833,8 +844,9 @@ secret_item_create_finish (GAsyncResult *result,
|
|||||||
/**
|
/**
|
||||||
* secret_item_create_sync:
|
* secret_item_create_sync:
|
||||||
* @collection: a secret collection to create this item in
|
* @collection: a secret collection to create this item in
|
||||||
* @label: label for the new item
|
* @schema: (allow-none): the schema for the attributes
|
||||||
* @attributes: (element-type utf8 utf8): attributes for the new item
|
* @attributes: (element-type utf8 utf8): attributes for the new item
|
||||||
|
* @label: label for the new item
|
||||||
* @value: secret value for the new item
|
* @value: secret value for the new item
|
||||||
* @replace: whether to replace an existing item with the same attributes
|
* @replace: whether to replace an existing item with the same attributes
|
||||||
* @cancellable: optional cancellation object
|
* @cancellable: optional cancellation object
|
||||||
@ -855,8 +867,9 @@ secret_item_create_finish (GAsyncResult *result,
|
|||||||
*/
|
*/
|
||||||
SecretItem *
|
SecretItem *
|
||||||
secret_item_create_sync (SecretCollection *collection,
|
secret_item_create_sync (SecretCollection *collection,
|
||||||
const gchar *label,
|
const SecretSchema *schema,
|
||||||
GHashTable *attributes,
|
GHashTable *attributes,
|
||||||
|
const gchar *label,
|
||||||
SecretValue *value,
|
SecretValue *value,
|
||||||
gboolean replace,
|
gboolean replace,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
@ -875,7 +888,11 @@ secret_item_create_sync (SecretCollection *collection,
|
|||||||
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
|
||||||
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||||
|
|
||||||
properties = item_properties_new (label, attributes);
|
/* Warnings raised already */
|
||||||
|
if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, FALSE))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
properties = item_properties_new (label, schema, attributes);
|
||||||
g_object_get (collection, "service", &service, NULL);
|
g_object_get (collection, "service", &service, NULL);
|
||||||
|
|
||||||
collection_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection));
|
collection_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection));
|
||||||
@ -1748,6 +1765,7 @@ secret_item_get_attributes (SecretItem *self)
|
|||||||
/**
|
/**
|
||||||
* secret_item_set_attributes:
|
* secret_item_set_attributes:
|
||||||
* @self: an item
|
* @self: an item
|
||||||
|
* @schema: (allow-none): the schema for the attributes
|
||||||
* @attributes: (element-type utf8 utf8): a new set of attributes
|
* @attributes: (element-type utf8 utf8): a new set of attributes
|
||||||
* @cancellable: optional cancellation object
|
* @cancellable: optional cancellation object
|
||||||
* @callback: called when the asynchronous operation completes
|
* @callback: called when the asynchronous operation completes
|
||||||
@ -1763,6 +1781,7 @@ secret_item_get_attributes (SecretItem *self)
|
|||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
secret_item_set_attributes (SecretItem *self,
|
secret_item_set_attributes (SecretItem *self,
|
||||||
|
const SecretSchema *schema,
|
||||||
GHashTable *attributes,
|
GHashTable *attributes,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
@ -1771,6 +1790,10 @@ secret_item_set_attributes (SecretItem *self,
|
|||||||
g_return_if_fail (SECRET_IS_ITEM (self));
|
g_return_if_fail (SECRET_IS_ITEM (self));
|
||||||
g_return_if_fail (attributes != NULL);
|
g_return_if_fail (attributes != NULL);
|
||||||
|
|
||||||
|
/* Warnings raised already */
|
||||||
|
if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, FALSE))
|
||||||
|
return;
|
||||||
|
|
||||||
_secret_util_set_property (G_DBUS_PROXY (self), "Attributes",
|
_secret_util_set_property (G_DBUS_PROXY (self), "Attributes",
|
||||||
_secret_attributes_to_variant (attributes, NULL),
|
_secret_attributes_to_variant (attributes, NULL),
|
||||||
secret_item_set_attributes, cancellable,
|
secret_item_set_attributes, cancellable,
|
||||||
@ -1802,6 +1825,7 @@ secret_item_set_attributes_finish (SecretItem *self,
|
|||||||
/**
|
/**
|
||||||
* secret_item_set_attributes_sync:
|
* secret_item_set_attributes_sync:
|
||||||
* @self: an item
|
* @self: an item
|
||||||
|
* @schema: (allow-none): the schema for the attributes
|
||||||
* @attributes: (element-type utf8 utf8): a new set of attributes
|
* @attributes: (element-type utf8 utf8): a new set of attributes
|
||||||
* @cancellable: optional cancellation object
|
* @cancellable: optional cancellation object
|
||||||
* @error: location to place error on failure
|
* @error: location to place error on failure
|
||||||
@ -1819,6 +1843,7 @@ secret_item_set_attributes_finish (SecretItem *self,
|
|||||||
*/
|
*/
|
||||||
gboolean
|
gboolean
|
||||||
secret_item_set_attributes_sync (SecretItem *self,
|
secret_item_set_attributes_sync (SecretItem *self,
|
||||||
|
const SecretSchema *schema,
|
||||||
GHashTable *attributes,
|
GHashTable *attributes,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
@ -1826,6 +1851,10 @@ secret_item_set_attributes_sync (SecretItem *self,
|
|||||||
g_return_val_if_fail (SECRET_IS_ITEM (self), FALSE);
|
g_return_val_if_fail (SECRET_IS_ITEM (self), FALSE);
|
||||||
g_return_val_if_fail (attributes != NULL, FALSE);
|
g_return_val_if_fail (attributes != NULL, FALSE);
|
||||||
|
|
||||||
|
/* Warnings raised already */
|
||||||
|
if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, FALSE))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
return _secret_util_set_property_sync (G_DBUS_PROXY (self), "Attributes",
|
return _secret_util_set_property_sync (G_DBUS_PROXY (self), "Attributes",
|
||||||
_secret_attributes_to_variant (attributes, NULL),
|
_secret_attributes_to_variant (attributes, NULL),
|
||||||
cancellable, error);
|
cancellable, error);
|
||||||
|
@ -61,8 +61,9 @@ GType secret_item_get_type (void) G_GNUC_CONST;
|
|||||||
void secret_item_refresh (SecretItem *self);
|
void secret_item_refresh (SecretItem *self);
|
||||||
|
|
||||||
void secret_item_create (SecretCollection *collection,
|
void secret_item_create (SecretCollection *collection,
|
||||||
const gchar *label,
|
const SecretSchema *schema,
|
||||||
GHashTable *attributes,
|
GHashTable *attributes,
|
||||||
|
const gchar *label,
|
||||||
SecretValue *value,
|
SecretValue *value,
|
||||||
gboolean replace,
|
gboolean replace,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
@ -73,8 +74,9 @@ SecretItem * secret_item_create_finish (GAsyncResult *result
|
|||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
SecretItem * secret_item_create_sync (SecretCollection *collection,
|
SecretItem * secret_item_create_sync (SecretCollection *collection,
|
||||||
const gchar *label,
|
const SecretSchema *schema,
|
||||||
GHashTable *attributes,
|
GHashTable *attributes,
|
||||||
|
const gchar *label,
|
||||||
SecretValue *value,
|
SecretValue *value,
|
||||||
gboolean replace,
|
gboolean replace,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
@ -142,6 +144,7 @@ gboolean secret_item_set_secret_sync (SecretItem *self,
|
|||||||
GHashTable* secret_item_get_attributes (SecretItem *self);
|
GHashTable* secret_item_get_attributes (SecretItem *self);
|
||||||
|
|
||||||
void secret_item_set_attributes (SecretItem *self,
|
void secret_item_set_attributes (SecretItem *self,
|
||||||
|
const SecretSchema *schema,
|
||||||
GHashTable *attributes,
|
GHashTable *attributes,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
@ -152,6 +155,7 @@ gboolean secret_item_set_attributes_finish (SecretItem *self,
|
|||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
gboolean secret_item_set_attributes_sync (SecretItem *self,
|
gboolean secret_item_set_attributes_sync (SecretItem *self,
|
||||||
|
const SecretSchema *schema,
|
||||||
GHashTable *attributes,
|
GHashTable *attributes,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
@ -179,8 +179,8 @@ test_create_sync (Test *test,
|
|||||||
|
|
||||||
value = secret_value_new ("Hoohah", -1, "text/plain");
|
value = secret_value_new ("Hoohah", -1, "text/plain");
|
||||||
|
|
||||||
item = secret_item_create_sync (collection, "Tunnel",
|
item = secret_item_create_sync (collection, NULL, attributes, "Tunnel",
|
||||||
attributes, value, FALSE, NULL, &error);
|
value, FALSE, NULL, &error);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
|
|
||||||
g_hash_table_unref (attributes);
|
g_hash_table_unref (attributes);
|
||||||
@ -218,8 +218,8 @@ test_create_async (Test *test,
|
|||||||
|
|
||||||
value = secret_value_new ("Hoohah", -1, "text/plain");
|
value = secret_value_new ("Hoohah", -1, "text/plain");
|
||||||
|
|
||||||
secret_item_create (collection, "Tunnel",
|
secret_item_create (collection, NULL, attributes, "Tunnel",
|
||||||
attributes, value, FALSE, NULL, on_async_result, &result);
|
value, FALSE, NULL, on_async_result, &result);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
|
|
||||||
g_hash_table_unref (attributes);
|
g_hash_table_unref (attributes);
|
||||||
@ -421,7 +421,7 @@ test_set_attributes_sync (Test *test,
|
|||||||
attributes = g_hash_table_new (g_str_hash, g_str_equal);
|
attributes = g_hash_table_new (g_str_hash, g_str_equal);
|
||||||
g_hash_table_insert (attributes, "string", "five");
|
g_hash_table_insert (attributes, "string", "five");
|
||||||
g_hash_table_insert (attributes, "number", "5");
|
g_hash_table_insert (attributes, "number", "5");
|
||||||
ret = secret_item_set_attributes_sync (item, attributes, NULL, &error);
|
ret = secret_item_set_attributes_sync (item, NULL, attributes, NULL, &error);
|
||||||
g_hash_table_unref (attributes);
|
g_hash_table_unref (attributes);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
g_assert (ret == TRUE);
|
g_assert (ret == TRUE);
|
||||||
@ -459,7 +459,7 @@ test_set_attributes_async (Test *test,
|
|||||||
attributes = g_hash_table_new (g_str_hash, g_str_equal);
|
attributes = g_hash_table_new (g_str_hash, g_str_equal);
|
||||||
g_hash_table_insert (attributes, "string", "five");
|
g_hash_table_insert (attributes, "string", "five");
|
||||||
g_hash_table_insert (attributes, "number", "5");
|
g_hash_table_insert (attributes, "number", "5");
|
||||||
secret_item_set_attributes (item, attributes, NULL, on_async_result, &result);
|
secret_item_set_attributes (item, NULL, attributes, NULL, on_async_result, &result);
|
||||||
g_assert (result == NULL);
|
g_assert (result == NULL);
|
||||||
|
|
||||||
egg_test_wait ();
|
egg_test_wait ();
|
||||||
|
Loading…
Reference in New Issue
Block a user