1 /* libsecret - GLib wrapper for Secret Service
3 * Copyright 2012 Red Hat Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published
7 * by the Free Software Foundation; either version 2.1 of the licence or (at
8 * your option) any later version.
10 * See the included COPYING file for more information.
12 * Author: Stef Walter <stefw@gnome.org>
17 #include "secret-collection.h"
18 #include "secret-dbus-generated.h"
19 #include "secret-enum-types.h"
20 #include "secret-item.h"
21 #include "secret-paths.h"
22 #include "secret-private.h"
23 #include "secret-service.h"
24 #include "secret-types.h"
25 #include "secret-value.h"
27 #include <glib/gi18n-lib.h>
32 * @short_description: A secret item
34 * #SecretItem represents a secret item stored in the Secret Service.
36 * Each item has a value, represented by a #SecretValue, which can be
37 * retrieved by secret_item_get_secret() or set by secret_item_set_secret().
38 * The item is only available when the item is not locked.
40 * Items can be locked or unlocked using the secret_service_lock() or
41 * secret_service_unlock() functions. The Secret Service may not be able to
42 * unlock individual items, and may unlock an entire collection when a single
45 * Each item has a set of attributes, which are used to locate the item later.
46 * These are not stored or transferred in a secure manner. Each attribute has
47 * a string name and a string value. Use secret_service_search() to search for
48 * items based on their attributes, and secret_item_set_attributes() to change
49 * the attributes associated with an item.
51 * Items can be created with secret_item_create() or secret_service_store().
53 * These functions have an unstable API and may change across versions. Use
54 * <literal>libsecret-unstable</literal> package to access them.
62 * A proxy object representing a secret item in the Secret Service.
67 * @parent_class: the parent class
69 * The class for #SecretItem.
74 * @SECRET_ITEM_NONE: no flags
75 * @SECRET_ITEM_LOAD_SECRET: a secret has been (or should be) loaded for #SecretItem
77 * Flags which determine which parts of the #SecretItem proxy are initialized.
81 * SecretItemCreateFlags:
82 * @SECRET_ITEM_CREATE_NONE: no flags
83 * @SECRET_ITEM_CREATE_REPLACE: replace an item with the same attributes.
85 * Flags for secret_item_create().
99 struct _SecretItemPrivate {
100 /* No changes between construct and finalize */
101 SecretService *service;
102 SecretItemFlags init_flags;
103 GCancellable *cancellable;
105 /* Locked by mutex */
110 static GInitableIface *secret_item_initable_parent_iface = NULL;
112 static GAsyncInitableIface *secret_item_async_initable_parent_iface = NULL;
114 static void secret_item_initable_iface (GInitableIface *iface);
116 static void secret_item_async_initable_iface (GAsyncInitableIface *iface);
118 G_DEFINE_TYPE_WITH_CODE (SecretItem, secret_item, G_TYPE_DBUS_PROXY,
119 G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, secret_item_initable_iface);
120 G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, secret_item_async_initable_iface);
124 secret_item_init (SecretItem *self)
126 self->pv = G_TYPE_INSTANCE_GET_PRIVATE (self, SECRET_TYPE_ITEM, SecretItemPrivate);
127 self->pv->cancellable = g_cancellable_new ();
128 g_mutex_init (&self->pv->mutex);
132 on_set_attributes (GObject *source,
133 GAsyncResult *result,
136 SecretItem *self = SECRET_ITEM (user_data);
137 GError *error = NULL;
139 secret_item_set_attributes_finish (self, result, &error);
141 g_warning ("couldn't set SecretItem Attributes: %s", error->message);
142 g_error_free (error);
145 g_object_unref (self);
149 on_set_label (GObject *source,
150 GAsyncResult *result,
153 SecretItem *self = SECRET_ITEM (user_data);
154 GError *error = NULL;
156 secret_item_set_label_finish (self, result, &error);
158 g_warning ("couldn't set SecretItem Label: %s", error->message);
159 g_error_free (error);
162 g_object_unref (self);
167 item_take_service (SecretItem *self,
168 SecretService *service)
173 g_return_if_fail (self->pv->service == NULL);
175 self->pv->service = service;
176 g_object_add_weak_pointer (G_OBJECT (self->pv->service),
177 (gpointer *)&self->pv->service);
179 /* Yes, we expect that the service will stay around */
180 g_object_unref (service);
184 secret_item_set_property (GObject *obj,
189 SecretItem *self = SECRET_ITEM (obj);
193 item_take_service (self, g_value_dup_object (value));
196 self->pv->init_flags = g_value_get_flags (value);
198 case PROP_ATTRIBUTES:
199 secret_item_set_attributes (self, NULL, g_value_get_boxed (value),
200 self->pv->cancellable, on_set_attributes,
201 g_object_ref (self));
204 secret_item_set_label (self, g_value_get_string (value),
205 self->pv->cancellable, on_set_label,
206 g_object_ref (self));
209 G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
215 secret_item_get_property (GObject *obj,
220 SecretItem *self = SECRET_ITEM (obj);
224 g_value_set_object (value, self->pv->service);
227 g_value_set_flags (value, secret_item_get_flags (self));
229 case PROP_ATTRIBUTES:
230 g_value_take_boxed (value, secret_item_get_attributes (self));
233 g_value_take_string (value, secret_item_get_label (self));
236 g_value_set_boolean (value, secret_item_get_locked (self));
239 g_value_set_uint64 (value, secret_item_get_created (self));
242 g_value_set_uint64 (value, secret_item_get_modified (self));
245 G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
251 secret_item_dispose (GObject *obj)
253 SecretItem *self = SECRET_ITEM (obj);
255 g_cancellable_cancel (self->pv->cancellable);
257 G_OBJECT_CLASS (secret_item_parent_class)->dispose (obj);
261 secret_item_finalize (GObject *obj)
263 SecretItem *self = SECRET_ITEM (obj);
265 if (self->pv->service)
266 g_object_remove_weak_pointer (G_OBJECT (self->pv->service),
267 (gpointer *)&self->pv->service);
269 g_object_unref (self->pv->cancellable);
270 g_mutex_clear (&self->pv->mutex);
272 G_OBJECT_CLASS (secret_item_parent_class)->finalize (obj);
276 handle_property_changed (GObject *object,
277 const gchar *property_name)
279 if (g_str_equal (property_name, "Attributes"))
280 g_object_notify (object, "attributes");
282 else if (g_str_equal (property_name, "Label"))
283 g_object_notify (object, "label");
285 else if (g_str_equal (property_name, "Locked"))
286 g_object_notify (object, "locked");
288 else if (g_str_equal (property_name, "Created"))
289 g_object_notify (object, "created");
291 else if (g_str_equal (property_name, "Modified"))
292 g_object_notify (object, "modified");
296 secret_item_properties_changed (GDBusProxy *proxy,
297 GVariant *changed_properties,
298 const gchar* const *invalidated_properties)
300 GObject *obj = G_OBJECT (proxy);
301 gchar *property_name;
305 g_object_freeze_notify (obj);
307 g_variant_iter_init (&iter, changed_properties);
308 while (g_variant_iter_loop (&iter, "{sv}", &property_name, &value))
309 handle_property_changed (obj, property_name);
311 g_object_thaw_notify (obj);
315 secret_item_class_init (SecretItemClass *klass)
317 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
318 GDBusProxyClass *proxy_class = G_DBUS_PROXY_CLASS (klass);
320 gobject_class->get_property = secret_item_get_property;
321 gobject_class->set_property = secret_item_set_property;
322 gobject_class->dispose = secret_item_dispose;
323 gobject_class->finalize = secret_item_finalize;
325 proxy_class->g_properties_changed = secret_item_properties_changed;
328 * SecretItem:service:
330 * The #SecretService object that this item is associated with and
331 * uses to interact with the actual D-Bus Secret Service.
333 g_object_class_install_property (gobject_class, PROP_SERVICE,
334 g_param_spec_object ("service", "Service", "Secret Service",
335 SECRET_TYPE_SERVICE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
340 * A set of flags describing which parts of the secret item have
343 g_object_class_install_property (gobject_class, PROP_FLAGS,
344 g_param_spec_flags ("flags", "Flags", "Item flags",
345 secret_item_flags_get_type (), SECRET_ITEM_NONE,
346 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
349 * SecretItem:attributes:
351 * The attributes set on this item. Attributes are used to locate an
352 * item. They are not guaranteed to be stored or transferred securely.
354 * Type: GLib.HashTable(utf8,utf8)
357 g_object_class_install_property (gobject_class, PROP_ATTRIBUTES,
358 g_param_spec_boxed ("attributes", "Attributes", "Item attributes",
359 G_TYPE_HASH_TABLE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
364 * The human readable label for the item.
366 * Setting this property will result in the label of the item being
367 * set asynchronously. To properly track the changing of the label use the
368 * secret_item_set_label() function.
370 g_object_class_install_property (gobject_class, PROP_LABEL,
371 g_param_spec_string ("label", "Label", "Item label",
372 NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
377 * Whether the item is locked or not. An item may not be independently
378 * lockable separate from other items in its collection.
380 * To lock or unlock a item use the secret_service_lock() or
381 * secret_service_unlock() functions.
383 g_object_class_install_property (gobject_class, PROP_LOCKED,
384 g_param_spec_boolean ("locked", "Locked", "Item locked",
385 TRUE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
388 * SecretItem:created:
390 * The date and time (in seconds since the UNIX epoch) that this
393 g_object_class_install_property (gobject_class, PROP_CREATED,
394 g_param_spec_uint64 ("created", "Created", "Item creation date",
395 0UL, G_MAXUINT64, 0UL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
398 * SecretItem:modified:
400 * The date and time (in seconds since the UNIX epoch) that this
401 * item was last modified.
403 g_object_class_install_property (gobject_class, PROP_MODIFIED,
404 g_param_spec_uint64 ("modified", "Modified", "Item modified date",
405 0UL, G_MAXUINT64, 0UL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
407 g_type_class_add_private (gobject_class, sizeof (SecretItemPrivate));
411 GCancellable *cancellable;
415 init_closure_free (gpointer data)
417 InitClosure *closure = data;
418 g_clear_object (&closure->cancellable);
419 g_slice_free (InitClosure, closure);
423 item_ensure_for_flags_sync (SecretItem *self,
424 SecretItemFlags flags,
425 GCancellable *cancellable,
428 if (flags & SECRET_ITEM_LOAD_SECRET && !secret_item_get_locked (self)) {
429 if (!secret_item_load_secret_sync (self, cancellable, error))
438 on_init_load_secret (GObject *source,
439 GAsyncResult *result,
442 GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data);
443 SecretItem *self = SECRET_ITEM (source);
444 GError *error = NULL;
446 if (!secret_item_load_secret_finish (self, result, &error))
447 g_simple_async_result_take_error (async, error);
449 g_simple_async_result_complete (async);
450 g_object_unref (async);
454 item_ensure_for_flags_async (SecretItem *self,
455 SecretItemFlags flags,
456 GSimpleAsyncResult *async)
458 InitClosure *init = g_simple_async_result_get_op_res_gpointer (async);
460 if (flags & SECRET_ITEM_LOAD_SECRET && !secret_item_get_locked (self))
461 secret_item_load_secret (self, init->cancellable,
462 on_init_load_secret, g_object_ref (async));
465 g_simple_async_result_complete (async);
469 secret_item_initable_init (GInitable *initable,
470 GCancellable *cancellable,
474 SecretService *service;
477 if (!secret_item_initable_parent_iface->init (initable, cancellable, error))
480 proxy = G_DBUS_PROXY (initable);
482 if (!_secret_util_have_cached_properties (proxy)) {
483 g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD,
484 "No such secret item at path: %s",
485 g_dbus_proxy_get_object_path (proxy));
489 self = SECRET_ITEM (initable);
490 if (!self->pv->service) {
491 service = secret_service_get_sync (SECRET_SERVICE_NONE, cancellable, error);
495 item_take_service (self, service);
498 return item_ensure_for_flags_sync (self, self->pv->init_flags, cancellable, error);
502 secret_item_initable_iface (GInitableIface *iface)
504 secret_item_initable_parent_iface = g_type_interface_peek_parent (iface);
506 iface->init = secret_item_initable_init;
510 on_init_service (GObject *source,
511 GAsyncResult *result,
514 GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data);
515 SecretItem *self = SECRET_ITEM (g_async_result_get_source_object (user_data));
516 SecretService *service;
517 GError *error = NULL;
519 service = secret_service_get_finish (result, &error);
521 item_take_service (self, service);
522 item_ensure_for_flags_async (self, self->pv->init_flags, async);
525 g_simple_async_result_take_error (async, error);
526 g_simple_async_result_complete (async);
529 g_object_unref (self);
530 g_object_unref (async);
534 on_init_base (GObject *source,
535 GAsyncResult *result,
538 GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
539 InitClosure *init = g_simple_async_result_get_op_res_gpointer (res);
540 SecretItem *self = SECRET_ITEM (source);
541 GDBusProxy *proxy = G_DBUS_PROXY (self);
542 GError *error = NULL;
544 if (!secret_item_async_initable_parent_iface->init_finish (G_ASYNC_INITABLE (self),
546 g_simple_async_result_take_error (res, error);
547 g_simple_async_result_complete (res);
549 } else if (!_secret_util_have_cached_properties (proxy)) {
550 g_simple_async_result_set_error (res, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD,
551 "No such secret item at path: %s",
552 g_dbus_proxy_get_object_path (proxy));
553 g_simple_async_result_complete (res);
555 } else if (self->pv->service == NULL) {
556 secret_service_get (SECRET_SERVICE_NONE, init->cancellable,
557 on_init_service, g_object_ref (res));
560 item_ensure_for_flags_async (self, self->pv->init_flags, res);
563 g_object_unref (res);
567 secret_item_async_initable_init_async (GAsyncInitable *initable,
569 GCancellable *cancellable,
570 GAsyncReadyCallback callback,
573 GSimpleAsyncResult *res;
576 res = g_simple_async_result_new (G_OBJECT (initable), callback, user_data,
577 secret_item_async_initable_init_async);
578 init = g_slice_new0 (InitClosure);
579 init->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
580 g_simple_async_result_set_op_res_gpointer (res, init, init_closure_free);
582 secret_item_async_initable_parent_iface->init_async (initable, io_priority,
587 g_object_unref (res);
591 secret_item_async_initable_init_finish (GAsyncInitable *initable,
592 GAsyncResult *result,
595 g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (initable),
596 secret_item_async_initable_init_async), FALSE);
598 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
605 secret_item_async_initable_iface (GAsyncInitableIface *iface)
607 secret_item_async_initable_parent_iface = g_type_interface_peek_parent (iface);
609 iface->init_async = secret_item_async_initable_init_async;
610 iface->init_finish = secret_item_async_initable_init_finish;
614 * secret_item_refresh:
615 * @self: the collection
617 * Refresh the properties on this item. This fires off a request to
618 * refresh, and the properties will be updated later.
620 * Calling this method is not normally necessary, as the secret service
621 * will notify the client when properties change.
624 secret_item_refresh (SecretItem *self)
626 g_return_if_fail (SECRET_IS_ITEM (self));
628 _secret_util_get_properties (G_DBUS_PROXY (self),
634 _secret_item_set_cached_secret (SecretItem *self,
637 SecretValue *other = NULL;
638 gboolean updated = FALSE;
640 g_return_if_fail (SECRET_IS_ITEM (self));
643 secret_value_ref (value);
645 g_mutex_lock (&self->pv->mutex);
647 if (value != self->pv->value) {
648 other = self->pv->value;
649 self->pv->value = value;
655 g_mutex_unlock (&self->pv->mutex);
658 secret_value_unref (other);
661 g_object_notify (G_OBJECT (self), "flags");
665 GCancellable *cancellable;
671 create_closure_free (gpointer data)
673 CreateClosure *closure = data;
674 g_clear_object (&closure->cancellable);
675 g_clear_object (&closure->item);
676 secret_value_unref (closure->value);
677 g_slice_free (CreateClosure, closure);
681 on_create_item (GObject *source,
682 GAsyncResult *result,
685 GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
686 CreateClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
687 GError *error = NULL;
689 closure->item = secret_item_new_for_dbus_path_finish (result, &error);
691 g_simple_async_result_take_error (res, error);
693 /* As a convenince mark down the SecretValue on the item */
694 _secret_item_set_cached_secret (closure->item, closure->value);
696 g_simple_async_result_complete (res);
697 g_object_unref (res);
701 on_create_path (GObject *source,
702 GAsyncResult *result,
705 GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
706 CreateClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
707 SecretService *service = SECRET_SERVICE (source);
708 GError *error = NULL;
711 path = secret_service_create_item_dbus_path_finish (service, result, &error);
713 secret_item_new_for_dbus_path (service, path, SECRET_ITEM_NONE,
714 closure->cancellable, on_create_item,
717 g_simple_async_result_take_error (res, error);
718 g_simple_async_result_complete (res);
721 g_object_unref (res);
725 item_properties_new (const gchar *label,
726 const SecretSchema *schema,
727 GHashTable *attributes)
729 const gchar *schema_name = NULL;
730 GHashTable *properties;
734 schema_name = schema->name;
736 properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
737 (GDestroyNotify)g_variant_unref);
739 value = g_variant_new_string (label);
740 g_hash_table_insert (properties,
741 SECRET_ITEM_INTERFACE ".Label",
742 g_variant_ref_sink (value));
744 value = _secret_attributes_to_variant (attributes, schema_name);
745 g_hash_table_insert (properties,
746 SECRET_ITEM_INTERFACE ".Attributes",
747 g_variant_ref_sink (value));
753 * secret_item_create:
754 * @collection: a secret collection to create this item in
755 * @schema: (allow-none): the schema for the attributes
756 * @attributes: (element-type utf8 utf8): attributes for the new item
757 * @label: label for the new item
758 * @value: secret value for the new item
759 * @flags: flags for the creation of the new item
760 * @cancellable: optional cancellation object
761 * @callback: called when the operation completes
762 * @user_data: data to pass to the callback
764 * Create a new item in the secret service.
766 * If the @flags contains %SECRET_ITEM_CREATE_REPLACE, then the secret
767 * service will search for an item matching the @attributes, and update that item
768 * instead of creating a new one.
770 * This method may block indefinitely and should not be used in user interface
771 * threads. The secret service may prompt the user. secret_service_prompt()
772 * will be used to handle any prompts that are required.
775 secret_item_create (SecretCollection *collection,
776 const SecretSchema *schema,
777 GHashTable *attributes,
780 SecretItemCreateFlags flags,
781 GCancellable *cancellable,
782 GAsyncReadyCallback callback,
785 SecretService *service = NULL;
786 const gchar *collection_path;
787 GSimpleAsyncResult *res;
788 CreateClosure *closure;
789 GHashTable *properties;
791 g_return_if_fail (SECRET_IS_COLLECTION (collection));
792 g_return_if_fail (label != NULL);
793 g_return_if_fail (attributes != NULL);
794 g_return_if_fail (value != NULL);
795 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
797 /* Warnings raised already */
798 if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, FALSE))
801 res = g_simple_async_result_new (NULL, callback, user_data,
803 closure = g_slice_new0 (CreateClosure);
804 closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
805 closure->value = secret_value_ref (value);
806 g_simple_async_result_set_op_res_gpointer (res, closure, create_closure_free);
808 properties = item_properties_new (label, schema, attributes);
809 g_object_get (collection, "service", &service, NULL);
811 collection_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection));
813 secret_service_create_item_dbus_path (service, collection_path, properties,
814 value, flags, cancellable,
815 on_create_path, g_object_ref (res));
817 g_hash_table_unref (properties);
818 g_object_unref (service);
819 g_object_unref (res);
823 * secret_item_create_finish:
824 * @result: the asynchronous result passed to the callback
825 * @error: location to place an error on failure
827 * Finish operation to create a new item in the secret service.
829 * Returns: (transfer full): the new item, which should be unreferenced
830 * with g_object_unref()
833 secret_item_create_finish (GAsyncResult *result,
836 GSimpleAsyncResult *res;
837 CreateClosure *closure;
839 g_return_val_if_fail (g_simple_async_result_is_valid (result, NULL,
840 secret_item_create), NULL);
841 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
843 res = G_SIMPLE_ASYNC_RESULT (result);
845 if (g_simple_async_result_propagate_error (res, error))
848 closure = g_simple_async_result_get_op_res_gpointer (res);
849 if (closure->item == NULL)
852 return g_object_ref (closure->item);
856 * secret_item_create_sync:
857 * @collection: a secret collection to create this item in
858 * @schema: (allow-none): the schema for the attributes
859 * @attributes: (element-type utf8 utf8): attributes for the new item
860 * @label: label for the new item
861 * @value: secret value for the new item
862 * @flags: flags for the creation of the new item
863 * @cancellable: optional cancellation object
864 * @error: location to place an error on failure
866 * Create a new item in the secret service.
868 * If the @flags contains %SECRET_ITEM_CREATE_REPLACE, then the secret
869 * service will search for an item matching the @attributes, and update that item
870 * instead of creating a new one.
872 * This method may block indefinitely and should not be used in user interface
873 * threads. The secret service may prompt the user. secret_service_prompt()
874 * will be used to handle any prompts that are required.
876 * Returns: (transfer full): the new item, which should be unreferenced
877 * with g_object_unref()
880 secret_item_create_sync (SecretCollection *collection,
881 const SecretSchema *schema,
882 GHashTable *attributes,
885 SecretItemCreateFlags flags,
886 GCancellable *cancellable,
889 SecretService *service = NULL;
890 const gchar *collection_path;
891 SecretItem *item = NULL;
892 GHashTable *properties;
895 g_return_val_if_fail (SECRET_IS_COLLECTION (collection), NULL);
896 g_return_val_if_fail (label != NULL, NULL);
897 g_return_val_if_fail (attributes != NULL, NULL);
898 g_return_val_if_fail (value != NULL, NULL);
899 g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
900 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
902 /* Warnings raised already */
903 if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, FALSE))
906 properties = item_properties_new (label, schema, attributes);
907 g_object_get (collection, "service", &service, NULL);
909 collection_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection));
911 path = secret_service_create_item_dbus_path_sync (service, collection_path, properties,
912 value, flags, cancellable, error);
915 item = secret_item_new_for_dbus_path_sync (service, path, SECRET_ITEM_NONE,
920 g_hash_table_unref (properties);
921 g_object_unref (service);
927 on_item_deleted (GObject *source,
928 GAsyncResult *result,
931 GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
932 SecretItem *self = SECRET_ITEM (g_async_result_get_source_object (user_data));
933 GError *error = NULL;
935 if (_secret_service_delete_path_finish (SECRET_SERVICE (source), result, &error))
936 g_simple_async_result_set_op_res_gboolean (res, TRUE);
939 g_simple_async_result_take_error (res, error);
941 g_simple_async_result_complete (res);
942 g_object_unref (self);
943 g_object_unref (res);
947 * secret_item_delete:
949 * @cancellable: optional cancellation object
950 * @callback: called when the operation completes
951 * @user_data: data to pass to the callback
955 * This method returns immediately and completes asynchronously. The secret
956 * service may prompt the user. secret_service_prompt() will be used to handle
957 * any prompts that show up.
960 secret_item_delete (SecretItem *self,
961 GCancellable *cancellable,
962 GAsyncReadyCallback callback,
965 GSimpleAsyncResult *res;
966 const gchar *object_path;
968 g_return_if_fail (SECRET_IS_ITEM (self));
969 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
971 object_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (self));
972 res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
975 _secret_service_delete_path (self->pv->service, object_path, TRUE,
976 cancellable, on_item_deleted, g_object_ref (res));
978 g_object_unref (res);
982 * secret_item_delete_finish:
984 * @result: asynchronous result passed to the callback
985 * @error: location to place an error on failure
987 * Complete asynchronous operation to delete the secret item.
989 * Returns: whether the item was successfully deleted or not
992 secret_item_delete_finish (SecretItem *self,
993 GAsyncResult *result,
996 GSimpleAsyncResult *res;
998 g_return_val_if_fail (SECRET_IS_ITEM (self), FALSE);
999 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1000 g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
1001 secret_item_delete), FALSE);
1003 res = G_SIMPLE_ASYNC_RESULT (result);
1005 if (g_simple_async_result_propagate_error (res, error))
1008 return g_simple_async_result_get_op_res_gboolean (res);
1012 * secret_item_delete_sync:
1014 * @cancellable: optional cancellation object
1015 * @error: location to place an error on failure
1017 * Delete this secret item.
1019 * This method may block indefinitely and should not be used in user
1020 * interface threads. The secret service may prompt the user.
1021 * secret_service_prompt() will be used to handle any prompts that show up.
1023 * Returns: whether the item was successfully deleted or not
1026 secret_item_delete_sync (SecretItem *self,
1027 GCancellable *cancellable,
1033 g_return_val_if_fail (SECRET_IS_ITEM (self), FALSE);
1034 g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
1035 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1037 sync = _secret_sync_new ();
1038 g_main_context_push_thread_default (sync->context);
1040 secret_item_delete (self, cancellable, _secret_sync_on_result, sync);
1042 g_main_loop_run (sync->loop);
1044 ret = secret_item_delete_finish (self, sync->result, error);
1046 g_main_context_pop_thread_default (sync->context);
1047 _secret_sync_free (sync);
1053 * secret_item_get_flags:
1054 * @self: the secret item proxy
1056 * Get the flags representing what features of the #SecretItem proxy
1057 * have been initialized.
1059 * Use secret_item_load_secret() to initialize further features
1060 * and change the flags.
1062 * Returns: the flags for features initialized
1065 secret_item_get_flags (SecretItem *self)
1067 SecretServiceFlags flags = 0;
1069 g_return_val_if_fail (SECRET_IS_ITEM (self), SECRET_ITEM_NONE);
1071 g_mutex_lock (&self->pv->mutex);
1073 if (self->pv->value)
1074 flags |= SECRET_ITEM_LOAD_SECRET;
1076 g_mutex_unlock (&self->pv->mutex);
1083 * secret_item_get_service:
1086 * Get the Secret Service object that this item was created with.
1088 * Returns: (transfer none): the Secret Service object
1091 secret_item_get_service (SecretItem *self)
1093 g_return_val_if_fail (SECRET_IS_ITEM (self), NULL);
1094 return self->pv->service;
1099 * secret_item_get_secret:
1102 * Get the secret value of this item. If this item is locked or the secret
1103 * has not yet been loaded then this will return %NULL.
1105 * To load the secret call the secret_item_load_secret() method.
1107 * Returns: (transfer full) (allow-none): the secret value which should be
1108 * released with secret_value_unref(), or %NULL
1111 secret_item_get_secret (SecretItem *self)
1113 SecretValue *value = NULL;
1115 g_return_val_if_fail (SECRET_IS_ITEM (self), NULL);
1117 g_mutex_lock (&self->pv->mutex);
1119 if (self->pv->value)
1120 value = secret_value_ref (self->pv->value);
1122 g_mutex_unlock (&self->pv->mutex);
1129 GCancellable *cancellable;
1133 load_closure_free (gpointer data)
1135 LoadClosure *closure = data;
1136 g_clear_object (&closure->cancellable);
1137 g_slice_free (LoadClosure, closure);
1141 on_item_load_secret (GObject *source,
1142 GAsyncResult *result,
1145 GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
1146 SecretItem *self = SECRET_ITEM (g_async_result_get_source_object (user_data));
1147 SecretSession *session;
1148 GError *error = NULL;
1153 retval = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), result, &error);
1154 if (error == NULL) {
1155 child = g_variant_get_child_value (retval, 0);
1156 g_variant_unref (retval);
1158 session = _secret_service_get_session (self->pv->service);
1159 value = _secret_session_decode_secret (session, child);
1160 g_variant_unref (child);
1162 if (value == NULL) {
1163 g_set_error (&error, SECRET_ERROR, SECRET_ERROR_PROTOCOL,
1164 _("Received invalid secret from the secret storage"));
1166 _secret_item_set_cached_secret (self, value);
1167 secret_value_unref (value);
1171 if (error != NULL) {
1172 _secret_util_strip_remote_error (&error);
1173 g_simple_async_result_take_error (res, error);
1176 g_simple_async_result_complete (res);
1177 g_object_unref (res);
1181 on_load_ensure_session (GObject *source,
1182 GAsyncResult *result,
1185 GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
1186 SecretItem *self = SECRET_ITEM (g_async_result_get_source_object (user_data));
1187 LoadClosure *load = g_simple_async_result_get_op_res_gpointer (res);
1188 const gchar *session_path;
1189 GError *error = NULL;
1191 secret_service_ensure_session_finish (self->pv->service, result, &error);
1192 if (error != NULL) {
1193 g_simple_async_result_take_error (res, error);
1194 g_simple_async_result_complete (res);
1197 session_path = secret_service_get_session_dbus_path (self->pv->service);
1198 g_assert (session_path != NULL && session_path[0] != '\0');
1199 g_dbus_proxy_call (G_DBUS_PROXY (self), "GetSecret",
1200 g_variant_new ("(o)", session_path),
1201 G_DBUS_CALL_FLAGS_NONE, -1, load->cancellable,
1202 on_item_load_secret, g_object_ref (res));
1205 g_object_unref (self);
1206 g_object_unref (res);
1210 * secret_item_load_secret:
1211 * @self: an item proxy
1212 * @cancellable: optional cancellation object
1213 * @callback: called when the operation completes
1214 * @user_data: data to pass to the callback
1216 * Load the secret value of this item.
1218 * Each item has a single secret which might be a password or some
1219 * other secret binary value.
1221 * This function will fail if the secret item is locked.
1223 * This function returns immediately and completes asynchronously.
1226 secret_item_load_secret (SecretItem *self,
1227 GCancellable *cancellable,
1228 GAsyncReadyCallback callback,
1231 GSimpleAsyncResult *res;
1232 LoadClosure *closure;
1234 g_return_if_fail (SECRET_IS_ITEM (self));
1235 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
1237 res = g_simple_async_result_new (G_OBJECT (self), callback,
1238 user_data, secret_item_load_secret);
1239 closure = g_slice_new0 (LoadClosure);
1240 closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
1241 g_simple_async_result_set_op_res_gpointer (res, closure, load_closure_free);
1243 secret_service_ensure_session (self->pv->service, cancellable,
1244 on_load_ensure_session,
1245 g_object_ref (res));
1247 g_object_unref (res);
1251 * secret_item_load_secret_finish:
1252 * @self: an item proxy
1253 * @result: asynchronous result passed to callback
1254 * @error: location to place error on failure
1256 * Complete asynchronous operation to load the secret value of this item.
1258 * The newly loaded secret value can be accessed by calling
1259 * secret_item_get_secret().
1261 * Returns: whether the secret item succesfully loaded or not
1264 secret_item_load_secret_finish (SecretItem *self,
1265 GAsyncResult *result,
1268 GSimpleAsyncResult *res;
1270 g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
1271 secret_item_load_secret), FALSE);
1273 res = G_SIMPLE_ASYNC_RESULT (result);
1274 if (g_simple_async_result_propagate_error (res, error))
1281 * secret_item_load_secret_sync:
1283 * @cancellable: optional cancellation object
1284 * @error: location to place error on failure
1286 * Load the secret value of this item.
1288 * Each item has a single secret which might be a password or some
1289 * other secret binary value.
1291 * This function may block indefinetely. Use the asynchronous version
1292 * in user interface threads.
1294 * Returns: whether the secret item succesfully loaded or not
1297 secret_item_load_secret_sync (SecretItem *self,
1298 GCancellable *cancellable,
1304 g_return_val_if_fail (SECRET_IS_ITEM (self), FALSE);
1305 g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
1306 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1308 sync = _secret_sync_new ();
1309 g_main_context_push_thread_default (sync->context);
1311 secret_item_load_secret (self, cancellable, _secret_sync_on_result, sync);
1313 g_main_loop_run (sync->loop);
1315 result = secret_item_load_secret_finish (self, sync->result, error);
1317 g_main_context_pop_thread_default (sync->context);
1318 _secret_sync_free (sync);
1324 SecretService *service;
1325 GCancellable *cancellable;
1331 loads_closure_free (gpointer data)
1333 LoadsClosure *loads = data;
1335 g_variant_unref (loads->in);
1337 g_object_unref (loads->service);
1338 g_clear_object (&loads->cancellable);
1339 g_slice_free (LoadsClosure, loads);
1343 on_get_secrets_complete (GObject *source,
1344 GAsyncResult *result,
1347 GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data);
1348 LoadsClosure *loads = g_simple_async_result_get_op_res_gpointer (async);
1349 GHashTable *with_paths;
1350 GError *error = NULL;
1351 GHashTableIter iter;
1357 retval = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), result, &error);
1358 if (retval != NULL) {
1359 with_paths = _secret_service_decode_get_secrets_all (loads->service, retval);
1360 g_return_if_fail (with_paths != NULL);
1362 g_hash_table_iter_init (&iter, with_paths);
1363 while (g_hash_table_iter_next (&iter, (gpointer *)&path, (gpointer *)&value)) {
1364 item = g_hash_table_lookup (loads->items, path);
1366 _secret_item_set_cached_secret (item, value);
1369 g_hash_table_unref (with_paths);
1370 g_variant_unref (retval);
1373 if (error != NULL) {
1374 _secret_util_strip_remote_error (&error);
1375 g_simple_async_result_take_error (async, error);
1378 g_simple_async_result_complete (async);
1379 g_object_unref (async);
1383 on_loads_secrets_session (GObject *source,
1384 GAsyncResult *result,
1387 GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data);
1388 LoadsClosure *loads = g_simple_async_result_get_op_res_gpointer (async);
1389 GError *error = NULL;
1390 const gchar *session;
1392 secret_service_ensure_session_finish (SECRET_SERVICE (source), result, &error);
1393 if (error != NULL) {
1394 g_simple_async_result_take_error (async, error);
1395 g_simple_async_result_complete (async);
1398 session = secret_service_get_session_dbus_path (SECRET_SERVICE (source));
1399 g_dbus_proxy_call (G_DBUS_PROXY (source), "GetSecrets",
1400 g_variant_new ("(@aoo)", loads->in, session),
1401 G_DBUS_CALL_FLAGS_NO_AUTO_START, -1,
1402 loads->cancellable, on_get_secrets_complete,
1403 g_object_ref (async));
1406 g_object_unref (async);
1410 * secret_item_load_secrets:
1411 * @items: (element-type SecretUnstable.Item): the items to retrieve secrets for
1412 * @cancellable: optional cancellation object
1413 * @callback: called when the operation completes
1414 * @user_data: data to pass to the callback
1416 * Load the secret values for an secret items stored in the service.
1418 * The @items must all have the same SecretItem::service property.
1420 * This function returns immediately and completes asynchronously.
1423 secret_item_load_secrets (GList *items,
1424 GCancellable *cancellable,
1425 GAsyncReadyCallback callback,
1428 GSimpleAsyncResult *async;
1429 LoadsClosure *loads;
1434 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
1436 for (l = items; l != NULL; l = g_list_next (l))
1437 g_return_if_fail (SECRET_IS_ITEM (l->data));
1439 async = g_simple_async_result_new (NULL, callback, user_data,
1440 secret_item_load_secrets);
1441 loads = g_slice_new0 (LoadsClosure);
1442 loads->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
1443 loads->items = g_hash_table_new_full (g_str_hash, g_str_equal,
1444 g_free, g_object_unref);
1446 paths = g_ptr_array_new ();
1447 for (l = items; l != NULL; l = g_list_next (l)) {
1448 if (secret_item_get_locked (l->data))
1451 if (loads->service == NULL) {
1452 loads->service = secret_item_get_service (l->data);
1454 g_object_ref (loads->service);
1457 path = g_dbus_proxy_get_object_path (l->data);
1458 g_hash_table_insert (loads->items, g_strdup (path), g_object_ref (l->data));
1459 g_ptr_array_add (paths, (gpointer)path);
1462 loads->in = g_variant_new_objv ((const gchar * const *)paths->pdata, paths->len);
1463 g_variant_ref_sink (loads->in);
1465 g_ptr_array_free (paths, TRUE);
1466 g_simple_async_result_set_op_res_gpointer (async, loads, loads_closure_free);
1468 if (loads->service) {
1469 secret_service_ensure_session (loads->service, cancellable,
1470 on_loads_secrets_session,
1471 g_object_ref (async));
1473 g_simple_async_result_complete_in_idle (async);
1476 g_object_unref (async);
1480 * secret_item_load_secrets_finish:
1481 * @result: asynchronous result passed to callback
1482 * @error: location to place an error on failure
1484 * Complete asynchronous operation to load the secret values for
1485 * secret items stored in the service.
1487 * Items that are locked will not have their secrets loaded.
1489 * Returns: whether the operation succeded or not
1492 secret_item_load_secrets_finish (GAsyncResult *result,
1495 GSimpleAsyncResult *async;
1497 g_return_val_if_fail (g_simple_async_result_is_valid (result, NULL,
1498 secret_item_load_secrets), FALSE);
1499 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1501 async = G_SIMPLE_ASYNC_RESULT (result);
1502 if (g_simple_async_result_propagate_error (async, error))
1509 * secret_item_load_secrets_sync:
1510 * @items: (element-type SecretUnstable.Item): the items to retrieve secrets for
1511 * @cancellable: optional cancellation object
1512 * @error: location to place an error on failure
1514 * Load the secret values for an secret items stored in the service.
1516 * The @items must all have the same SecretItem::service property.
1518 * This method may block indefinitely and should not be used in user interface
1521 * Items that are locked will not have their secrets loaded.
1523 * Returns: whether the operation succeded or not
1526 secret_item_load_secrets_sync (GList *items,
1527 GCancellable *cancellable,
1534 for (l = items; l != NULL; l = g_list_next (l))
1535 g_return_val_if_fail (SECRET_IS_ITEM (l->data), FALSE);
1537 g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
1538 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1540 sync = _secret_sync_new ();
1541 g_main_context_push_thread_default (sync->context);
1543 secret_item_load_secrets (items, cancellable,
1544 _secret_sync_on_result, sync);
1546 g_main_loop_run (sync->loop);
1548 ret = secret_item_load_secrets_finish (sync->result, error);
1550 g_main_context_pop_thread_default (sync->context);
1551 _secret_sync_free (sync);
1557 GCancellable *cancellable;
1562 set_closure_free (gpointer data)
1564 SetClosure *set = data;
1565 g_clear_object (&set->cancellable);
1566 secret_value_unref (set->value);
1567 g_slice_free (SetClosure, set);
1571 on_item_set_secret (GObject *source,
1572 GAsyncResult *result,
1575 GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
1576 SecretItem *self = SECRET_ITEM (g_async_result_get_source_object (user_data));
1577 SetClosure *set = g_simple_async_result_get_op_res_gpointer (res);
1578 GError *error = NULL;
1581 retval = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), result, &error);
1583 if (error == NULL) {
1584 _secret_item_set_cached_secret (self, set->value);
1586 _secret_util_strip_remote_error (&error);
1587 g_simple_async_result_take_error (res, error);
1590 g_variant_unref (retval);
1592 g_simple_async_result_complete (res);
1593 g_object_unref (self);
1594 g_object_unref (res);
1598 on_set_ensure_session (GObject *source,
1599 GAsyncResult *result,
1602 GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
1603 SecretItem *self = SECRET_ITEM (g_async_result_get_source_object (user_data));
1604 SetClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
1605 SecretSession *session;
1607 GError *error = NULL;
1609 secret_service_ensure_session_finish (self->pv->service, result, &error);
1610 if (error != NULL) {
1611 g_simple_async_result_take_error (res, error);
1612 g_simple_async_result_complete (res);
1615 session = _secret_service_get_session (self->pv->service);
1616 encoded = _secret_session_encode_secret (session, closure->value);
1617 g_dbus_proxy_call (G_DBUS_PROXY (self), "SetSecret",
1618 g_variant_new ("(@(oayays))", encoded),
1619 G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, closure->cancellable,
1620 on_item_set_secret, g_object_ref (res));
1623 g_object_unref (self);
1624 g_object_unref (res);
1628 * secret_item_set_secret:
1630 * @value: a new secret value
1631 * @cancellable: optional cancellation object
1632 * @callback: called when the operation completes
1633 * @user_data: data to pass to the callback
1635 * Set the secret value of this item.
1637 * Each item has a single secret which might be a password or some
1638 * other secret binary value.
1640 * This function returns immediately and completes asynchronously.
1643 secret_item_set_secret (SecretItem *self,
1645 GCancellable *cancellable,
1646 GAsyncReadyCallback callback,
1649 GSimpleAsyncResult *res;
1650 SetClosure *closure;
1652 g_return_if_fail (SECRET_IS_ITEM (self));
1653 g_return_if_fail (value != NULL);
1654 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
1656 res = g_simple_async_result_new (G_OBJECT (self), callback,
1657 user_data, secret_item_set_secret);
1658 closure = g_slice_new0 (SetClosure);
1659 closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
1660 closure->value = secret_value_ref (value);
1661 g_simple_async_result_set_op_res_gpointer (res, closure, set_closure_free);
1663 secret_service_ensure_session (self->pv->service, cancellable,
1664 on_set_ensure_session,
1665 g_object_ref (res));
1667 g_object_unref (res);
1671 * secret_item_set_secret_finish:
1673 * @result: asynchronous result passed to callback
1674 * @error: location to place error on failure
1676 * Complete asynchronous operation to set the secret value of this item.
1678 * Returns: whether the change was successful or not
1681 secret_item_set_secret_finish (SecretItem *self,
1682 GAsyncResult *result,
1685 GSimpleAsyncResult *res;
1687 g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
1688 secret_item_set_secret), FALSE);
1690 res = G_SIMPLE_ASYNC_RESULT (result);
1691 if (g_simple_async_result_propagate_error (res, error))
1698 * secret_item_set_secret_sync:
1700 * @value: a new secret value
1701 * @cancellable: optional cancellation object
1702 * @error: location to place error on failure
1704 * Set the secret value of this item.
1706 * Each item has a single secret which might be a password or some
1707 * other secret binary value.
1709 * This function may block indefinetely. Use the asynchronous version
1710 * in user interface threads.
1712 * Returns: whether the change was successful or not
1715 secret_item_set_secret_sync (SecretItem *self,
1717 GCancellable *cancellable,
1723 g_return_val_if_fail (SECRET_IS_ITEM (self), FALSE);
1724 g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
1725 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1727 sync = _secret_sync_new ();
1728 g_main_context_push_thread_default (sync->context);
1730 secret_item_set_secret (self, value, cancellable, _secret_sync_on_result, sync);
1732 g_main_loop_run (sync->loop);
1734 ret = secret_item_set_secret_finish (self, sync->result, error);
1736 g_main_context_pop_thread_default (sync->context);
1737 _secret_sync_free (sync);
1743 * secret_item_get_schema_name:
1746 * Gets the name of the schema that this item was stored with. This is also
1747 * available at the <literal>xdg:schema</literal> attribute.
1749 * Returns: (transfer full): the schema name
1752 secret_item_get_schema_name (SecretItem *self)
1757 g_return_val_if_fail (SECRET_IS_ITEM (self), NULL);
1759 variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self), "Attributes");
1760 g_return_val_if_fail (variant != NULL, NULL);
1762 g_variant_lookup (variant, "xdg:schema", "s", &schema_name);
1763 g_variant_unref (variant);
1769 * secret_item_get_attributes:
1772 * Set the attributes of this item.
1774 * The @attributes are a mapping of string keys to string values.
1775 * Attributes are used to search for items. Attributes are not stored
1776 * or transferred securely by the secret service.
1778 * Do not modify the attributes returned by this method. Use
1779 * secret_item_set_attributes() instead.
1781 * Returns: (transfer full) (element-type utf8 utf8): a new reference
1782 * to the attributes, which should not be modified, and
1783 * released with g_hash_table_unref()
1786 secret_item_get_attributes (SecretItem *self)
1788 GHashTable *attributes;
1791 g_return_val_if_fail (SECRET_IS_ITEM (self), NULL);
1793 variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self), "Attributes");
1794 g_return_val_if_fail (variant != NULL, NULL);
1796 attributes = _secret_attributes_for_variant (variant);
1797 g_variant_unref (variant);
1803 * secret_item_set_attributes:
1805 * @schema: (allow-none): the schema for the attributes
1806 * @attributes: (element-type utf8 utf8): a new set of attributes
1807 * @cancellable: optional cancellation object
1808 * @callback: called when the asynchronous operation completes
1809 * @user_data: data to pass to the callback
1811 * Set the attributes of this item.
1813 * The @attributes are a mapping of string keys to string values.
1814 * Attributes are used to search for items. Attributes are not stored
1815 * or transferred securely by the secret service.
1817 * This function returns immediately and completes asynchronously.
1820 secret_item_set_attributes (SecretItem *self,
1821 const SecretSchema *schema,
1822 GHashTable *attributes,
1823 GCancellable *cancellable,
1824 GAsyncReadyCallback callback,
1827 const gchar *schema_name = NULL;
1829 g_return_if_fail (SECRET_IS_ITEM (self));
1830 g_return_if_fail (attributes != NULL);
1832 if (schema != NULL) {
1833 if (!_secret_attributes_validate (schema, attributes, G_STRFUNC, FALSE))
1834 return; /* Warnings raised already */
1835 schema_name = schema->name;
1838 _secret_util_set_property (G_DBUS_PROXY (self), "Attributes",
1839 _secret_attributes_to_variant (attributes, schema_name),
1840 secret_item_set_attributes, cancellable,
1841 callback, user_data);
1845 * secret_item_set_attributes_finish:
1847 * @result: asynchronous result passed to the callback
1848 * @error: location to place error on failure
1850 * Complete operation to set the attributes of this item.
1852 * Returns: whether the change was successful or not
1855 secret_item_set_attributes_finish (SecretItem *self,
1856 GAsyncResult *result,
1859 g_return_val_if_fail (SECRET_IS_ITEM (self), FALSE);
1861 return _secret_util_set_property_finish (G_DBUS_PROXY (self),
1862 secret_item_set_attributes,
1867 * secret_item_set_attributes_sync:
1869 * @schema: (allow-none): the schema for the attributes
1870 * @attributes: (element-type utf8 utf8): a new set of attributes
1871 * @cancellable: optional cancellation object
1872 * @error: location to place error on failure
1874 * Set the attributes of this item.
1876 * The @attributes are a mapping of string keys to string values.
1877 * Attributes are used to search for items. Attributes are not stored
1878 * or transferred securely by the secret service.
1880 * This function may block indefinetely. Use the asynchronous version
1881 * in user interface threads.
1883 * Returns: whether the change was successful or not
1886 secret_item_set_attributes_sync (SecretItem *self,
1887 const SecretSchema *schema,
1888 GHashTable *attributes,
1889 GCancellable *cancellable,
1892 const gchar *schema_name = NULL;
1894 g_return_val_if_fail (SECRET_IS_ITEM (self), FALSE);
1895 g_return_val_if_fail (attributes != NULL, FALSE);
1897 if (schema != NULL) {
1898 if (!_secret_attributes_validate (schema, attributes, G_STRFUNC, FALSE))
1899 return FALSE; /* Warnings raised already */
1900 schema_name = schema->name;
1903 return _secret_util_set_property_sync (G_DBUS_PROXY (self), "Attributes",
1904 _secret_attributes_to_variant (attributes, schema_name),
1905 cancellable, error);
1909 * secret_item_get_label:
1912 * Get the label of this item.
1914 * Returns: (transfer full): the label, which should be freed with g_free()
1917 secret_item_get_label (SecretItem *self)
1922 g_return_val_if_fail (SECRET_IS_ITEM (self), NULL);
1924 variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self), "Label");
1925 g_return_val_if_fail (variant != NULL, NULL);
1927 label = g_variant_dup_string (variant, NULL);
1928 g_variant_unref (variant);
1934 * secret_item_set_label:
1936 * @label: a new label
1937 * @cancellable: optional cancellation object
1938 * @callback: called when the operation completes
1939 * @user_data: data to pass to the callback
1941 * Set the label of this item.
1943 * This function returns immediately and completes asynchronously.
1946 secret_item_set_label (SecretItem *self,
1948 GCancellable *cancellable,
1949 GAsyncReadyCallback callback,
1952 g_return_if_fail (SECRET_IS_ITEM (self));
1953 g_return_if_fail (label != NULL);
1955 _secret_util_set_property (G_DBUS_PROXY (self), "Label",
1956 g_variant_new_string (label),
1957 secret_item_set_label,
1958 cancellable, callback, user_data);
1962 * secret_item_set_label_finish:
1964 * @result: asynchronous result passed to callback
1965 * @error: location to place error on failure
1967 * Complete asynchronous operation to set the label of this collection.
1969 * Returns: whether the change was successful or not
1972 secret_item_set_label_finish (SecretItem *self,
1973 GAsyncResult *result,
1976 g_return_val_if_fail (SECRET_IS_ITEM (self), FALSE);
1978 return _secret_util_set_property_finish (G_DBUS_PROXY (self),
1979 secret_item_set_label,
1984 * secret_item_set_label_sync:
1986 * @label: a new label
1987 * @cancellable: optional cancellation object
1988 * @error: location to place error on failure
1990 * Set the label of this item.
1992 * This function may block indefinetely. Use the asynchronous version
1993 * in user interface threads.
1995 * Returns: whether the change was successful or not
1998 secret_item_set_label_sync (SecretItem *self,
2000 GCancellable *cancellable,
2003 g_return_val_if_fail (SECRET_IS_ITEM (self), FALSE);
2004 g_return_val_if_fail (label != NULL, FALSE);
2006 return _secret_util_set_property_sync (G_DBUS_PROXY (self), "Label",
2007 g_variant_new_string (label),
2008 cancellable, error);
2012 * secret_item_get_locked:
2015 * Get whether the item is locked or not.
2017 * Depending on the secret service an item may not be able to be locked
2018 * independently from the collection that it is in.
2020 * Returns: whether the item is locked or not
2023 secret_item_get_locked (SecretItem *self)
2028 g_return_val_if_fail (SECRET_IS_ITEM (self), TRUE);
2030 variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self), "Locked");
2031 g_return_val_if_fail (variant != NULL, TRUE);
2033 locked = g_variant_get_boolean (variant);
2034 g_variant_unref (variant);
2040 * secret_item_get_created:
2043 * Get the created date and time of the item. The return value is
2044 * the number of seconds since the unix epoch, January 1st 1970.
2046 * Returns: the created date and time
2049 secret_item_get_created (SecretItem *self)
2054 g_return_val_if_fail (SECRET_IS_ITEM (self), TRUE);
2056 variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self), "Created");
2057 g_return_val_if_fail (variant != NULL, 0);
2059 created = g_variant_get_uint64 (variant);
2060 g_variant_unref (variant);
2066 * secret_item_get_modified:
2069 * Get the modified date and time of the item. The return value is
2070 * the number of seconds since the unix epoch, January 1st 1970.
2072 * Returns: the modified date and time
2075 secret_item_get_modified (SecretItem *self)
2080 g_return_val_if_fail (SECRET_IS_ITEM (self), TRUE);
2082 variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self), "Modified");
2083 g_return_val_if_fail (variant != NULL, 0);
2085 modified = g_variant_get_uint64 (variant);
2086 g_variant_unref (variant);