* 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
* 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.
*
* Items can be created with secret_item_create() or secret_service_store().
self->pv->init_flags = g_value_get_flags (value);
break;
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,
g_object_ref (self));
break;
static GHashTable *
item_properties_new (const gchar *label,
+ const SecretSchema *schema,
GHashTable *attributes)
{
+ const gchar *schema_name = NULL;
GHashTable *properties;
GVariant *value;
+ if (schema != NULL)
+ schema_name = schema->name;
+
properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
(GDestroyNotify)g_variant_unref);
SECRET_ITEM_INTERFACE ".Label",
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,
SECRET_ITEM_INTERFACE ".Attributes",
g_variant_ref_sink (value));
/**
* secret_item_create:
* @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
+ * @label: label for the new item
* @value: secret value for the new item
* @replace: whether to replace an existing item with the same attributes
* @cancellable: optional cancellation object
*/
void
secret_item_create (SecretCollection *collection,
- const gchar *label,
+ const SecretSchema *schema,
GHashTable *attributes,
+ const gchar *label,
SecretValue *value,
gboolean replace,
GCancellable *cancellable,
g_return_if_fail (value != NULL);
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,
secret_item_create);
closure = g_slice_new0 (CreateClosure);
closure->value = secret_value_ref (value);
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);
collection_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection));
/**
* secret_item_create_sync:
* @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
+ * @label: label for the new item
* @value: secret value for the new item
* @replace: whether to replace an existing item with the same attributes
* @cancellable: optional cancellation object
*/
SecretItem *
secret_item_create_sync (SecretCollection *collection,
- const gchar *label,
+ const SecretSchema *schema,
GHashTable *attributes,
+ const gchar *label,
SecretValue *value,
gboolean replace,
GCancellable *cancellable,
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), 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);
collection_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection));
/**
* secret_item_set_attributes:
* @self: an item
+ * @schema: (allow-none): the schema for the attributes
* @attributes: (element-type utf8 utf8): a new set of attributes
* @cancellable: optional cancellation object
* @callback: called when the asynchronous operation completes
*/
void
secret_item_set_attributes (SecretItem *self,
+ const SecretSchema *schema,
GHashTable *attributes,
GCancellable *cancellable,
GAsyncReadyCallback callback,
g_return_if_fail (SECRET_IS_ITEM (self));
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_attributes_to_variant (attributes, NULL),
secret_item_set_attributes, cancellable,
/**
* secret_item_set_attributes_sync:
* @self: an item
+ * @schema: (allow-none): the schema for the attributes
* @attributes: (element-type utf8 utf8): a new set of attributes
* @cancellable: optional cancellation object
* @error: location to place error on failure
*/
gboolean
secret_item_set_attributes_sync (SecretItem *self,
+ const SecretSchema *schema,
GHashTable *attributes,
GCancellable *cancellable,
GError **error)
g_return_val_if_fail (SECRET_IS_ITEM (self), 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",
_secret_attributes_to_variant (attributes, NULL),
cancellable, error);
value = secret_value_new ("Hoohah", -1, "text/plain");
- item = secret_item_create_sync (collection, "Tunnel",
- attributes, value, FALSE, NULL, &error);
+ item = secret_item_create_sync (collection, NULL, attributes, "Tunnel",
+ value, FALSE, NULL, &error);
g_assert_no_error (error);
g_hash_table_unref (attributes);
value = secret_value_new ("Hoohah", -1, "text/plain");
- secret_item_create (collection, "Tunnel",
- attributes, value, FALSE, NULL, on_async_result, &result);
+ secret_item_create (collection, NULL, attributes, "Tunnel",
+ value, FALSE, NULL, on_async_result, &result);
g_assert_no_error (error);
g_hash_table_unref (attributes);
attributes = g_hash_table_new (g_str_hash, g_str_equal);
g_hash_table_insert (attributes, "string", "five");
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_assert_no_error (error);
g_assert (ret == TRUE);
attributes = g_hash_table_new (g_str_hash, g_str_equal);
g_hash_table_insert (attributes, "string", "five");
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);
egg_test_wait ();