1 /* libsecret - GLib wrapper for Secret Service
3 * Copyright 2011 Collabora Ltd.
4 * Copyright 2012 Red Hat Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation; either version 2.1 of the licence or (at
9 * your option) any later version.
11 * See the included COPYING file for more information.
13 * Author: Stef Walter <stefw@gnome.org>
18 #include "secret-dbus-generated.h"
19 #include "secret-paths.h"
20 #include "secret-private.h"
21 #include "secret-service.h"
22 #include "secret-types.h"
23 #include "secret-value.h"
27 * SECTION:secret-paths
28 * @title: DBus Path Related Functions
29 * @short_description: Secret Service functions which operate on DBus object paths
31 * These are low level functions which operate on DBus object paths of
32 * collections or items, instead of the #SecretCollection or #SecretItem
35 * You can use these functions if you wish to manage access to the secret
36 * service using the DBus API directly, and only wish to use a few calls
39 * These functions have an unstable API and may change across versions. Use
40 * <literal>libsecret-unstable</literal> package to access them.
46 * secret_collection_new_for_dbus_path:
47 * @service: (allow-none): a secret service object
48 * @collection_path: the D-Bus path of the collection
49 * @flags: options for the collection initialization
50 * @cancellable: optional cancellation object
51 * @callback: called when the operation completes
52 * @user_data: data to be passed to the callback
54 * Get a new collection proxy for a collection in the secret service.
56 * If @service is NULL, then secret_service_get() will be called to get
57 * the default #SecretService proxy.
59 * This method will return immediately and complete asynchronously.
62 secret_collection_new_for_dbus_path (SecretService *service,
63 const gchar *collection_path,
64 SecretCollectionFlags flags,
65 GCancellable *cancellable,
66 GAsyncReadyCallback callback,
71 g_return_if_fail (service == NULL || SECRET_IS_SERVICE (service));
72 g_return_if_fail (collection_path != NULL);
73 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
75 proxy = G_DBUS_PROXY (service);
77 g_async_initable_new_async (SECRET_SERVICE_GET_CLASS (service)->collection_gtype,
78 G_PRIORITY_DEFAULT, cancellable, callback, user_data,
79 "g-flags", G_DBUS_CALL_FLAGS_NONE,
80 "g-interface-info", _secret_gen_collection_interface_info (),
81 "g-name", g_dbus_proxy_get_name (proxy),
82 "g-connection", g_dbus_proxy_get_connection (proxy),
83 "g-object-path", collection_path,
84 "g-interface-name", SECRET_COLLECTION_INTERFACE,
91 * secret_collection_new_for_dbus_path_finish:
92 * @result: the asynchronous result passed to the callback
93 * @error: location to place an error on failure
95 * Finish asynchronous operation to get a new collection proxy for a
96 * collection in the secret service.
98 * Returns: (transfer full): the new collection, which should be unreferenced
99 * with g_object_unref()
102 secret_collection_new_for_dbus_path_finish (GAsyncResult *result,
105 GObject *source_object;
108 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
109 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
111 source_object = g_async_result_get_source_object (result);
112 object = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object),
114 g_object_unref (source_object);
119 return SECRET_COLLECTION (object);
123 * secret_collection_new_for_dbus_path_sync:
124 * @service: (allow-none): a secret service object
125 * @collection_path: the D-Bus path of the collection
126 * @flags: options for the collection initialization
127 * @cancellable: optional cancellation object
128 * @error: location to place an error on failure
130 * Get a new collection proxy for a collection in the secret service.
132 * If @service is NULL, then secret_service_get_sync() will be called to get
133 * the default #SecretService proxy.
135 * This method may block indefinitely and should not be used in user interface
138 * Returns: (transfer full): the new collection, which should be unreferenced
139 * with g_object_unref()
142 secret_collection_new_for_dbus_path_sync (SecretService *service,
143 const gchar *collection_path,
144 SecretCollectionFlags flags,
145 GCancellable *cancellable,
150 g_return_val_if_fail (service == NULL || SECRET_IS_SERVICE (service), NULL);
151 g_return_val_if_fail (collection_path != NULL, NULL);
152 g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
153 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
155 proxy = G_DBUS_PROXY (service);
157 return g_initable_new (SECRET_SERVICE_GET_CLASS (service)->collection_gtype,
159 "g-flags", G_DBUS_CALL_FLAGS_NONE,
160 "g-interface-info", _secret_gen_collection_interface_info (),
161 "g-name", g_dbus_proxy_get_name (proxy),
162 "g-connection", g_dbus_proxy_get_connection (proxy),
163 "g-object-path", collection_path,
164 "g-interface-name", SECRET_COLLECTION_INTERFACE,
171 * secret_item_new_for_dbus_path:
172 * @service: (allow-none): a secret service object
173 * @item_path: the D-Bus path of the collection
174 * @flags: initialization flags for the new item
175 * @cancellable: optional cancellation object
176 * @callback: called when the operation completes
177 * @user_data: data to be passed to the callback
179 * Get a new item proxy for a secret item in the secret service.
181 * If @service is NULL, then secret_service_get() will be called to get
182 * the default #SecretService proxy.
184 * This method will return immediately and complete asynchronously.
187 secret_item_new_for_dbus_path (SecretService *service,
188 const gchar *item_path,
189 SecretItemFlags flags,
190 GCancellable *cancellable,
191 GAsyncReadyCallback callback,
196 g_return_if_fail (service == NULL || SECRET_IS_SERVICE (service));
197 g_return_if_fail (item_path != NULL);
198 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
200 proxy = G_DBUS_PROXY (service);
202 g_async_initable_new_async (SECRET_SERVICE_GET_CLASS (service)->item_gtype,
203 G_PRIORITY_DEFAULT, cancellable, callback, user_data,
204 "g-flags", G_DBUS_CALL_FLAGS_NONE,
205 "g-interface-info", _secret_gen_item_interface_info (),
206 "g-name", g_dbus_proxy_get_name (proxy),
207 "g-connection", g_dbus_proxy_get_connection (proxy),
208 "g-object-path", item_path,
209 "g-interface-name", SECRET_ITEM_INTERFACE,
216 * secret_item_new_for_dbus_path_finish:
217 * @result: the asynchronous result passed to the callback
218 * @error: location to place an error on failure
220 * Finish asynchronous operation to get a new item proxy for an secret
221 * item in the secret service.
223 * Returns: (transfer full): the new item, which should be unreferenced
224 * with g_object_unref()
227 secret_item_new_for_dbus_path_finish (GAsyncResult *result,
231 GObject *source_object;
233 source_object = g_async_result_get_source_object (result);
234 object = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object),
236 g_object_unref (source_object);
241 return SECRET_ITEM (object);
245 * secret_item_new_dbus_path_sync:
246 * @service: (allow-none): a secret service object
247 * @item_path: the D-Bus path of the item
248 * @flags: initialization flags for the new item
249 * @cancellable: optional cancellation object
250 * @error: location to place an error on failure
252 * Get a new item proxy for a secret item in the secret service.
254 * If @service is NULL, then secret_service_get_sync() will be called to get
255 * the default #SecretService proxy.
257 * This method may block indefinitely and should not be used in user interface
260 * Returns: (transfer full): the new item, which should be unreferenced
261 * with g_object_unref()
264 secret_item_new_for_dbus_path_sync (SecretService *service,
265 const gchar *item_path,
266 SecretItemFlags flags,
267 GCancellable *cancellable,
272 g_return_val_if_fail (service == NULL || SECRET_IS_SERVICE (service), NULL);
273 g_return_val_if_fail (item_path != NULL, NULL);
274 g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
275 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
277 proxy = G_DBUS_PROXY (service);
279 return g_initable_new (SECRET_SERVICE_GET_CLASS (service)->item_gtype,
281 "g-flags", G_DBUS_CALL_FLAGS_NONE,
282 "g-interface-info", _secret_gen_item_interface_info (),
283 "g-name", g_dbus_proxy_get_name (proxy),
284 "g-connection", g_dbus_proxy_get_connection (proxy),
285 "g-object-path", item_path,
286 "g-interface-name", SECRET_ITEM_INTERFACE,
293 on_search_items_complete (GObject *source,
294 GAsyncResult *result,
297 GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
298 GError *error = NULL;
301 response = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), result, &error);
303 g_simple_async_result_take_error (res, error);
305 g_simple_async_result_set_op_res_gpointer (res, response,
306 (GDestroyNotify)g_variant_unref);
309 g_simple_async_result_complete (res);
310 g_object_unref (res);
314 * secret_collection_search_for_dbus_paths:
315 * @collection: the secret collection
316 * @schema: (allow-none): the schema for the attributes
317 * @attributes: (element-type utf8 utf8): search for items matching these attributes
318 * @cancellable: optional cancellation object
319 * @callback: called when the operation completes
320 * @user_data: data to pass to the callback
322 * Search for items in @collection matching the @attributes, and return their
323 * DBus object paths. Only the specified collection is searched. The @attributes
324 * should be a table of string keys and string values.
326 * This function returns immediately and completes asynchronously.
328 * When your callback is called use secret_collection_search_for_dbus_paths_finish()
329 * to get the results of this function. Only the DBus object paths of the
330 * items will be returned. If you would like #SecretItem objects to be returned
331 * instead, then use the secret_collection_search() function.
334 secret_collection_search_for_dbus_paths (SecretCollection *collection,
335 const SecretSchema *schema,
336 GHashTable *attributes,
337 GCancellable *cancellable,
338 GAsyncReadyCallback callback,
341 GSimpleAsyncResult *async;
342 const gchar *schema_name = NULL;
344 g_return_if_fail (SECRET_IS_COLLECTION (collection));
345 g_return_if_fail (attributes != NULL);
346 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
348 /* Warnings raised already */
349 if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
352 if (schema != NULL && !(schema->flags & SECRET_SCHEMA_DONT_MATCH_NAME))
353 schema_name = schema->name;
355 async = g_simple_async_result_new (G_OBJECT (collection), callback, user_data,
356 secret_collection_search_for_dbus_paths);
358 g_dbus_proxy_call (G_DBUS_PROXY (collection), "SearchItems",
359 g_variant_new ("(@a{ss})", _secret_attributes_to_variant (attributes, schema_name)),
360 G_DBUS_CALL_FLAGS_NONE, -1, cancellable,
361 on_search_items_complete, g_object_ref (async));
363 g_object_unref (async);
367 * secret_collection_search_for_dbus_paths_finish:
368 * @collection: the secret collection
369 * @result: asynchronous result passed to callback
370 * @error: location to place error on failure
372 * Complete asynchronous operation to search for items in a collection.
374 * DBus object paths of the items will be returned. If you would to have
375 * #SecretItem objects to be returned instead, then use the
376 * secret_collection_search() and secret_collection_search_finish() functions.
378 * Returns: (transfer full) (array zero-terminated=1): an array of DBus object
379 * paths for matching items.
382 secret_collection_search_for_dbus_paths_finish (SecretCollection *collection,
383 GAsyncResult *result,
387 GSimpleAsyncResult *async;
388 gchar **paths = NULL;
390 g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (collection),
391 secret_collection_search_for_dbus_paths), FALSE);
392 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
394 async = G_SIMPLE_ASYNC_RESULT (result);
395 if (_secret_util_propagate_error (async, error))
398 retval= g_simple_async_result_get_op_res_gpointer (async);
399 g_variant_get (retval, "(^ao)", &paths);
404 * secret_collection_search_for_dbus_paths_sync:
405 * @collection: the secret collection
406 * @schema: (allow-none): the schema for the attributes
407 * @attributes: (element-type utf8 utf8): search for items matching these attributes
408 * @cancellable: optional cancellation object
409 * @error: location to place error on failure
411 * Search for items matching the @attributes in @collection, and return their
412 * DBus object paths. The @attributes should be a table of string keys and
415 * This function may block indefinetely. Use the asynchronous version
416 * in user interface threads.
418 * DBus object paths of the items will be returned. If you would to have
419 * #SecretItem objects to be returned instead, then use the
420 * secret_collection_search_sync() function.
422 * Returns: (transfer full) (array zero-terminated=1): an array of DBus object
423 * paths for matching items.
426 secret_collection_search_for_dbus_paths_sync (SecretCollection *collection,
427 const SecretSchema *schema,
428 GHashTable *attributes,
429 GCancellable *cancellable,
435 g_return_val_if_fail (SECRET_IS_COLLECTION (collection), NULL);
436 g_return_val_if_fail (attributes != NULL, NULL);
437 g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
438 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
440 sync = _secret_sync_new ();
441 g_main_context_push_thread_default (sync->context);
443 secret_collection_search_for_dbus_paths (collection, schema, attributes, cancellable,
444 _secret_sync_on_result, sync);
446 g_main_loop_run (sync->loop);
448 paths = secret_collection_search_for_dbus_paths_finish (collection, sync->result, error);
450 g_main_context_pop_thread_default (sync->context);
451 _secret_sync_free (sync);
457 * secret_service_search_for_dbus_paths:
458 * @self: the secret service
459 * @schema: (allow-none): the schema for the attributes
460 * @attributes: (element-type utf8 utf8): search for items matching these attributes
461 * @cancellable: optional cancellation object
462 * @callback: called when the operation completes
463 * @user_data: data to pass to the callback
465 * Search for items matching the @attributes, and return their D-Bus object paths.
466 * All collections are searched. The @attributes should be a table of string keys
469 * This function returns immediately and completes asynchronously.
471 * When your callback is called use secret_service_search_for_dbus_paths_finish()
472 * to get the results of this function. Only the D-Bus object paths of the
473 * items will be returned. If you would like #SecretItem objects to be returned
474 * instead, then use the secret_service_search() function.
477 secret_service_search_for_dbus_paths (SecretService *self,
478 const SecretSchema *schema,
479 GHashTable *attributes,
480 GCancellable *cancellable,
481 GAsyncReadyCallback callback,
484 const gchar *schema_name = NULL;
486 g_return_if_fail (SECRET_IS_SERVICE (self));
487 g_return_if_fail (attributes != NULL);
488 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
490 /* Warnings raised already */
491 if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
494 if (schema != NULL && !(schema->flags & SECRET_SCHEMA_DONT_MATCH_NAME))
495 schema_name = schema->name;
497 _secret_service_search_for_paths_variant (self, _secret_attributes_to_variant (attributes, schema_name),
498 cancellable, callback, user_data);
502 _secret_service_search_for_paths_variant (SecretService *self,
503 GVariant *attributes,
504 GCancellable *cancellable,
505 GAsyncReadyCallback callback,
508 GSimpleAsyncResult *res;
510 g_return_if_fail (SECRET_IS_SERVICE (self));
511 g_return_if_fail (attributes != NULL);
512 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
514 res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
515 secret_service_search_for_dbus_paths);
517 g_dbus_proxy_call (G_DBUS_PROXY (self), "SearchItems",
518 g_variant_new ("(@a{ss})", attributes),
519 G_DBUS_CALL_FLAGS_NONE, -1, cancellable,
520 on_search_items_complete, g_object_ref (res));
522 g_object_unref (res);
526 * secret_service_search_for_dbus_paths_finish:
527 * @self: the secret service
528 * @result: asynchronous result passed to callback
529 * @unlocked: (out) (transfer full) (array zero-terminated=1) (allow-none):
530 * location to place an array of D-Bus object paths for matching
531 * items which were locked.
532 * @locked: (out) (transfer full) (array zero-terminated=1) (allow-none):
533 * location to place an array of D-Bus object paths for matching
534 * items which were locked.
535 * @error: location to place error on failure
537 * Complete asynchronous operation to search for items, and return their
538 * D-Bus object paths.
540 * Matching items that are locked or unlocked, have their D-Bus paths placed
541 * in the @locked or @unlocked arrays respectively.
543 * D-Bus object paths of the items will be returned in the @unlocked or
544 * @locked arrays. If you would to have #SecretItem objects to be returned
545 * instead, then us the secret_service_search() and
546 * secret_service_search_finish() functions.
548 * Returns: whether the search was successful or not
551 secret_service_search_for_dbus_paths_finish (SecretService *self,
552 GAsyncResult *result,
558 GSimpleAsyncResult *res;
559 gchar **dummy = NULL;
561 g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
562 secret_service_search_for_dbus_paths), FALSE);
563 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
565 res = G_SIMPLE_ASYNC_RESULT (result);
566 if (_secret_util_propagate_error (res, error))
569 if (unlocked || locked) {
574 response = g_simple_async_result_get_op_res_gpointer (res);
575 g_variant_get (response, "(^ao^ao)", unlocked, locked);
583 * secret_service_search_for_dbus_paths_sync:
584 * @self: the secret service
585 * @schema: (allow-none): the schema for the attributes
586 * @attributes: (element-type utf8 utf8): search for items matching these attributes
587 * @cancellable: optional cancellation object
588 * @unlocked: (out) (transfer full) (array zero-terminated=1) (allow-none):
589 * location to place an array of D-Bus object paths for matching
590 * items which were locked.
591 * @locked: (out) (transfer full) (array zero-terminated=1) (allow-none):
592 * location to place an array of D-Bus object paths for matching
593 * items which were locked.
594 * @error: location to place error on failure
596 * Search for items matching the @attributes, and return their D-Bus object
597 * paths. All collections are searched. The @attributes should be a table of
598 * string keys and string values.
600 * This function may block indefinetely. Use the asynchronous version
601 * in user interface threads.
603 * Matching items that are locked or unlocked, have their D-Bus paths placed
604 * in the @locked or @unlocked arrays respectively.
606 * D-Bus object paths of the items will be returned in the @unlocked or
607 * @locked arrays. If you would to have #SecretItem objects to be returned
608 * instead, then use the secret_service_search_sync() function.
610 * Returns: whether the search was successful or not
613 secret_service_search_for_dbus_paths_sync (SecretService *self,
614 const SecretSchema *schema,
615 GHashTable *attributes,
616 GCancellable *cancellable,
621 const gchar *schema_name = NULL;
622 gchar **dummy = NULL;
625 g_return_val_if_fail (SECRET_IS_SERVICE (self), FALSE);
626 g_return_val_if_fail (attributes != NULL, FALSE);
627 g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
628 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
630 /* Warnings raised already */
631 if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
634 if (schema != NULL && !(schema->flags & SECRET_SCHEMA_DONT_MATCH_NAME))
635 schema_name = schema->name;
637 response = g_dbus_proxy_call_sync (G_DBUS_PROXY (self), "SearchItems",
638 g_variant_new ("(@a{ss})",
639 _secret_attributes_to_variant (attributes, schema_name)),
640 G_DBUS_CALL_FLAGS_NONE, -1, cancellable, error);
642 if (response != NULL) {
643 if (unlocked || locked) {
648 g_variant_get (response, "(^ao^ao)", unlocked, locked);
651 g_variant_unref (response);
656 return response != NULL;
660 GCancellable *cancellable;
667 get_closure_free (gpointer data)
669 GetClosure *closure = data;
671 g_variant_unref (closure->in);
673 g_variant_unref (closure->out);
674 g_clear_object (&closure->cancellable);
675 g_slice_free (GetClosure, closure);
679 on_get_secrets_complete (GObject *source,
680 GAsyncResult *result,
683 GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
684 GetClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
685 GError *error = NULL;
687 closure->out = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), result, &error);
689 g_simple_async_result_take_error (res, error);
691 g_simple_async_result_complete (res);
693 g_object_unref (res);
697 on_get_secrets_session (GObject *source,
698 GAsyncResult *result,
701 GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
702 GetClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
703 GError *error = NULL;
704 const gchar *session;
706 secret_service_ensure_session_finish (SECRET_SERVICE (source), result, &error);
708 g_simple_async_result_take_error (res, error);
709 g_simple_async_result_complete (res);
711 session = secret_service_get_session_dbus_path (SECRET_SERVICE (source));
712 g_dbus_proxy_call (G_DBUS_PROXY (source), "GetSecrets",
713 g_variant_new ("(@aoo)", closure->in, session),
714 G_DBUS_CALL_FLAGS_NO_AUTO_START, -1,
715 closure->cancellable, on_get_secrets_complete,
719 g_object_unref (res);
723 * secret_service_get_secret_for_dbus_path:
724 * @self: the secret service
725 * @item_path: the D-Bus path to item to retrieve secret for
726 * @cancellable: optional cancellation object
727 * @callback: called when the operation completes
728 * @user_data: data to pass to the callback
730 * Get the secret value for an secret item stored in the service.
732 * The item is represented by its D-Bus object path. If you already have a
733 * #SecretItem proxy object, use use secret_item_get_secret() to more simply
734 * get its secret value.
736 * This function returns immediately and completes asynchronously.
739 secret_service_get_secret_for_dbus_path (SecretService *self,
740 const gchar *item_path,
741 GCancellable *cancellable,
742 GAsyncReadyCallback callback,
745 GSimpleAsyncResult *res;
748 g_return_if_fail (SECRET_IS_SERVICE (self));
749 g_return_if_fail (item_path != NULL);
750 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
752 res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
753 secret_service_get_secret_for_dbus_path);
755 closure = g_slice_new0 (GetClosure);
756 closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
757 closure->in = g_variant_ref_sink (g_variant_new_objv (&item_path, 1));
758 g_simple_async_result_set_op_res_gpointer (res, closure, get_closure_free);
760 secret_service_ensure_session (self, cancellable,
761 on_get_secrets_session,
764 g_object_unref (res);
768 * secret_service_get_secret_for_dbus_path_finish:
769 * @self: the secret service
770 * @result: asynchronous result passed to callback
771 * @error: location to place an error on failure
773 * Complete asynchronous operation to get the secret value for an
774 * secret item stored in the service.
776 * Will return %NULL if the item is locked.
778 * Returns: (transfer full) (allow-none): the newly allocated secret value
779 * for the item, which should be released with secret_value_unref()
782 secret_service_get_secret_for_dbus_path_finish (SecretService *self,
783 GAsyncResult *result,
786 GSimpleAsyncResult *res;
789 g_return_val_if_fail (SECRET_IS_SERVICE (self), NULL);
790 g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
791 secret_service_get_secret_for_dbus_path), NULL);
792 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
794 res = G_SIMPLE_ASYNC_RESULT (result);
795 if (_secret_util_propagate_error (res, error))
798 closure = g_simple_async_result_get_op_res_gpointer (res);
799 return _secret_service_decode_get_secrets_first (self, closure->out);
803 * secret_service_get_secret_for_dbus_path_sync:
804 * @self: the secret service
805 * @item_path: the D-Bus path to item to retrieve secret for
806 * @cancellable: optional cancellation object
807 * @error: location to place an error on failure
809 * Get the secret value for an secret item stored in the service.
811 * The item is represented by its D-Bus object path. If you already have a
812 * #SecretItem proxy object, use use secret_item_load_secret_sync() to more simply
813 * get its secret value.
815 * This method may block indefinitely and should not be used in user interface
818 * Will return %NULL if the item is locked.
820 * Returns: (transfer full) (allow-none): the newly allocated secret value
821 * for the item, which should be released with secret_value_unref()
824 secret_service_get_secret_for_dbus_path_sync (SecretService *self,
825 const gchar *item_path,
826 GCancellable *cancellable,
832 g_return_val_if_fail (SECRET_IS_SERVICE (self), NULL);
833 g_return_val_if_fail (item_path != NULL, NULL);
834 g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
835 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
837 sync = _secret_sync_new ();
838 g_main_context_push_thread_default (sync->context);
840 secret_service_get_secret_for_dbus_path (self, item_path, cancellable,
841 _secret_sync_on_result, sync);
843 g_main_loop_run (sync->loop);
845 value = secret_service_get_secret_for_dbus_path_finish (self, sync->result, error);
847 g_main_context_pop_thread_default (sync->context);
848 _secret_sync_free (sync);
854 * secret_service_get_secrets_for_dbus_paths:
855 * @self: the secret service
856 * @item_paths: the D-Bus paths to items to retrieve secrets for
857 * @cancellable: optional cancellation object
858 * @callback: called when the operation completes
859 * @user_data: data to pass to the callback
861 * Get the secret values for an secret items stored in the service.
863 * The items are represented by their D-Bus object paths. If you already have
864 * #SecretItem proxy objects, use use secret_item_load_secrets() to more simply
865 * get their secret values.
867 * This function returns immediately and completes asynchronously.
870 secret_service_get_secrets_for_dbus_paths (SecretService *self,
871 const gchar **item_paths,
872 GCancellable *cancellable,
873 GAsyncReadyCallback callback,
876 GSimpleAsyncResult *res;
879 g_return_if_fail (SECRET_IS_SERVICE (self));
880 g_return_if_fail (item_paths != NULL);
881 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
883 res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
884 secret_service_get_secret_for_dbus_path);
886 closure = g_slice_new0 (GetClosure);
887 closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
888 closure->in = g_variant_ref_sink (g_variant_new_objv (item_paths, -1));
889 g_simple_async_result_set_op_res_gpointer (res, closure, get_closure_free);
891 secret_service_ensure_session (self, cancellable,
892 on_get_secrets_session,
895 g_object_unref (res);
899 * secret_service_get_secrets_for_dbus_paths_finish:
900 * @self: the secret service
901 * @result: asynchronous result passed to callback
902 * @error: location to place an error on failure
904 * Complete asynchronous operation to get the secret values for an
905 * secret items stored in the service.
907 * Items that are locked will not be included the results.
909 * Returns: (transfer full) (element-type utf8 SecretUnstable.Value): a newly
910 * allocated hash table of item_path keys to #SecretValue
914 secret_service_get_secrets_for_dbus_paths_finish (SecretService *self,
915 GAsyncResult *result,
918 GSimpleAsyncResult *res;
921 g_return_val_if_fail (SECRET_IS_SERVICE (self), NULL);
922 g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
923 secret_service_get_secret_for_dbus_path), NULL);
924 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
926 res = G_SIMPLE_ASYNC_RESULT (result);
927 if (_secret_util_propagate_error (res, error))
930 closure = g_simple_async_result_get_op_res_gpointer (res);
931 return _secret_service_decode_get_secrets_all (self, closure->out);
935 * secret_service_get_secrets_for_dbus_paths_sync:
936 * @self: the secret service
937 * @item_paths: the D-Bus paths to items to retrieve secrets for
938 * @cancellable: optional cancellation object
939 * @error: location to place an error on failure
941 * Get the secret values for an secret items stored in the service.
943 * The items are represented by their D-Bus object paths. If you already have
944 * #SecretItem proxy objects, use use secret_item_load_secrets_sync() to more
945 * simply get their secret values.
947 * This method may block indefinitely and should not be used in user interface
950 * Items that are locked will not be included the results.
952 * Returns: (transfer full) (element-type utf8 SecretUnstable.Value): a newly
953 * allocated hash table of item_path keys to #SecretValue
957 secret_service_get_secrets_for_dbus_paths_sync (SecretService *self,
958 const gchar **item_paths,
959 GCancellable *cancellable,
965 g_return_val_if_fail (SECRET_IS_SERVICE (self), NULL);
966 g_return_val_if_fail (item_paths != NULL, NULL);
967 g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
968 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
970 sync = _secret_sync_new ();
971 g_main_context_push_thread_default (sync->context);
973 secret_service_get_secrets_for_dbus_paths (self, item_paths, cancellable,
974 _secret_sync_on_result, sync);
976 g_main_loop_run (sync->loop);
978 secrets = secret_service_get_secrets_for_dbus_paths_finish (self, sync->result, error);
980 g_main_context_pop_thread_default (sync->context);
981 _secret_sync_free (sync);
988 GCancellable *cancellable;
989 SecretPrompt *prompt;
994 xlock_closure_free (gpointer data)
996 XlockClosure *closure = data;
997 g_clear_object (&closure->cancellable);
998 g_clear_object (&closure->prompt);
999 if (closure->xlocked)
1000 g_ptr_array_unref (closure->xlocked);
1001 g_slice_free (XlockClosure, closure);
1005 on_xlock_prompted (GObject *source,
1006 GAsyncResult *result,
1009 GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
1010 XlockClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
1011 SecretService *self = SECRET_SERVICE (source);
1012 GError *error = NULL;
1017 retval = secret_service_prompt_finish (self, result, G_VARIANT_TYPE ("ao"), &error);
1019 g_simple_async_result_take_error (res, error);
1021 if (retval != NULL) {
1022 g_variant_iter_init (&iter, retval);
1023 while (g_variant_iter_loop (&iter, "o", &path))
1024 g_ptr_array_add (closure->xlocked, g_strdup (path));
1025 g_variant_unref (retval);
1028 g_simple_async_result_complete (res);
1029 g_object_unref (res);
1033 on_xlock_called (GObject *source,
1034 GAsyncResult *result,
1037 GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
1038 XlockClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
1039 SecretService *self = SECRET_SERVICE (g_async_result_get_source_object (user_data));
1040 const gchar *prompt = NULL;
1041 gchar **xlocked = NULL;
1042 GError *error = NULL;
1046 retval = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), result, &error);
1047 if (error != NULL) {
1048 g_simple_async_result_take_error (res, error);
1049 g_simple_async_result_complete (res);
1052 g_variant_get (retval, "(^ao&o)", &xlocked, &prompt);
1054 if (_secret_util_empty_path (prompt)) {
1055 for (i = 0; xlocked[i]; i++)
1056 g_ptr_array_add (closure->xlocked, g_strdup (xlocked[i]));
1057 g_simple_async_result_complete (res);
1060 closure->prompt = _secret_prompt_instance (self, prompt);
1061 secret_service_prompt (self, closure->prompt, closure->cancellable,
1062 on_xlock_prompted, g_object_ref (res));
1065 g_strfreev (xlocked);
1066 g_variant_unref (retval);
1069 g_object_unref (self);
1070 g_object_unref (res);
1074 _secret_service_xlock_paths_async (SecretService *self,
1075 const gchar *method,
1076 const gchar **paths,
1077 GCancellable *cancellable,
1078 GAsyncReadyCallback callback,
1081 GSimpleAsyncResult *res;
1082 XlockClosure *closure;
1084 res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
1085 _secret_service_xlock_paths_async);
1086 closure = g_slice_new0 (XlockClosure);
1087 closure->cancellable = cancellable ? g_object_ref (cancellable) : cancellable;
1088 closure->xlocked = g_ptr_array_new_with_free_func (g_free);
1089 g_simple_async_result_set_op_res_gpointer (res, closure, xlock_closure_free);
1091 g_dbus_proxy_call (G_DBUS_PROXY (self), method,
1092 g_variant_new ("(@ao)", g_variant_new_objv (paths, -1)),
1093 G_DBUS_CALL_FLAGS_NO_AUTO_START, -1,
1094 cancellable, on_xlock_called, g_object_ref (res));
1096 g_object_unref (res);
1100 _secret_service_xlock_paths_finish (SecretService *self,
1101 GAsyncResult *result,
1105 GSimpleAsyncResult *res;
1106 XlockClosure *closure;
1109 res = G_SIMPLE_ASYNC_RESULT (result);
1110 if (_secret_util_propagate_error (res, error))
1113 closure = g_simple_async_result_get_op_res_gpointer (res);
1114 count = closure->xlocked->len;
1116 if (xlocked != NULL) {
1117 g_ptr_array_add (closure->xlocked, NULL);
1118 *xlocked = (gchar **)g_ptr_array_free (closure->xlocked, FALSE);
1119 closure->xlocked = NULL;
1126 * secret_service_lock_dbus_paths_sync:
1127 * @self: the secret service
1128 * @paths: the D-Bus object paths of the items or collections to lock
1129 * @cancellable: optional cancellation object
1130 * @locked: (out) (array zero-terminated=1) (transfer full) (allow-none):
1131 * location to place array of D-Bus paths of items or collections
1133 * @error: location to place an error on failure
1135 * Lock items or collections in the secret service.
1137 * The items or collections are represented by their D-Bus object paths. If you
1138 * already have #SecretItem and #SecretCollection proxy objects, use use
1139 * secret_service_lock_sync() instead.
1141 * The secret service may not be able to lock items individually, and may
1142 * lock an entire collection instead.
1144 * This method may block indefinitely and should not be used in user
1145 * interface threads. The secret service may prompt the user.
1146 * secret_service_prompt() will be used to handle any prompts that show up.
1148 * Returns: the number of items or collections that were locked
1151 secret_service_lock_dbus_paths_sync (SecretService *self,
1152 const gchar **paths,
1153 GCancellable *cancellable,
1160 g_return_val_if_fail (SECRET_IS_SERVICE (self), -1);
1161 g_return_val_if_fail (paths != NULL, -1);
1162 g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), -1);
1163 g_return_val_if_fail (error == NULL || *error == NULL, -1);
1165 sync = _secret_sync_new ();
1166 g_main_context_push_thread_default (sync->context);
1168 secret_service_lock_dbus_paths (self, paths, cancellable,
1169 _secret_sync_on_result, sync);
1171 g_main_loop_run (sync->loop);
1173 count = secret_service_lock_dbus_paths_finish (self, sync->result,
1176 g_main_context_pop_thread_default (sync->context);
1177 _secret_sync_free (sync);
1183 * secret_service_lock_dbus_paths:
1184 * @self: the secret service
1185 * @paths: the D-Bus paths for items or collections to lock
1186 * @cancellable: optional cancellation object
1187 * @callback: called when the operation completes
1188 * @user_data: data to pass to the callback
1190 * Lock items or collections in the secret service.
1192 * The items or collections are represented by their D-Bus object paths. If you
1193 * already have #SecretItem and #SecretCollection proxy objects, use use
1194 * secret_service_lock() instead.
1196 * The secret service may not be able to lock items individually, and may
1197 * lock an entire collection instead.
1199 * This method returns immediately and completes asynchronously. The secret
1200 * service may prompt the user. secret_service_prompt() will be used to handle
1201 * any prompts that show up.
1204 secret_service_lock_dbus_paths (SecretService *self,
1205 const gchar **paths,
1206 GCancellable *cancellable,
1207 GAsyncReadyCallback callback,
1210 g_return_if_fail (SECRET_IS_SERVICE (self));
1211 g_return_if_fail (paths != NULL);
1212 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
1214 _secret_service_xlock_paths_async (self, "Lock", paths, cancellable,
1215 callback, user_data);
1219 * secret_service_lock_dbus_paths_finish:
1220 * @self: the secret service
1221 * @result: asynchronous result passed to the callback
1222 * @locked: (out) (array zero-terminated=1) (transfer full) (allow-none):
1223 * location to place array of D-Bus paths of items or collections
1225 * @error: location to place an error on failure
1227 * Complete asynchronous operation to lock items or collections in the secret
1230 * The secret service may not be able to lock items individually, and may
1231 * lock an entire collection instead.
1233 * Returns: the number of items or collections that were locked
1236 secret_service_lock_dbus_paths_finish (SecretService *self,
1237 GAsyncResult *result,
1241 g_return_val_if_fail (SECRET_IS_SERVICE (self), -1);
1242 g_return_val_if_fail (locked != NULL, -1);
1243 g_return_val_if_fail (error == NULL || *error == NULL, -1);
1245 return _secret_service_xlock_paths_finish (self, result, locked, error);
1249 * secret_service_unlock_dbus_paths_sync:
1250 * @self: the secret service
1251 * @paths: the D-Bus object paths of the items or collections to unlock
1252 * @cancellable: optional cancellation object
1253 * @unlocked: (out) (array zero-terminated=1) (transfer full) (allow-none):
1254 * location to place array of D-Bus paths of items or collections
1255 * that were unlocked
1256 * @error: location to place an error on failure
1258 * Unlock items or collections in the secret service.
1260 * The items or collections are represented by their D-Bus object paths. If you
1261 * already have #SecretItem and #SecretCollection proxy objects, use use
1262 * secret_service_unlock_sync() instead.
1264 * The secret service may not be able to unlock items individually, and may
1265 * unlock an entire collection instead.
1267 * This method may block indefinitely and should not be used in user
1268 * interface threads. The secret service may prompt the user.
1269 * secret_service_prompt() will be used to handle any prompts that show up.
1271 * Returns: the number of items or collections that were unlocked
1274 secret_service_unlock_dbus_paths_sync (SecretService *self,
1275 const gchar **paths,
1276 GCancellable *cancellable,
1283 g_return_val_if_fail (SECRET_IS_SERVICE (self), -1);
1284 g_return_val_if_fail (paths != NULL, -1);
1285 g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), -1);
1286 g_return_val_if_fail (error == NULL || *error == NULL, -1);
1288 sync = _secret_sync_new ();
1289 g_main_context_push_thread_default (sync->context);
1291 secret_service_unlock_dbus_paths (self, paths, cancellable,
1292 _secret_sync_on_result, sync);
1294 g_main_loop_run (sync->loop);
1296 count = secret_service_unlock_dbus_paths_finish (self, sync->result,
1299 g_main_context_pop_thread_default (sync->context);
1300 _secret_sync_free (sync);
1306 * secret_service_unlock_dbus_paths:
1307 * @self: the secret service
1308 * @paths: the D-Bus paths for items or collections to unlock
1309 * @cancellable: optional cancellation object
1310 * @callback: called when the operation completes
1311 * @user_data: data to pass to the callback
1313 * Unlock items or collections in the secret service.
1315 * The items or collections are represented by their D-Bus object paths. If you
1316 * already have #SecretItem and #SecretCollection proxy objects, use use
1317 * secret_service_unlock() instead.
1319 * The secret service may not be able to unlock items individually, and may
1320 * unlock an entire collection instead.
1322 * This method returns immediately and completes asynchronously. The secret
1323 * service may prompt the user. secret_service_prompt() will be used to handle
1324 * any prompts that show up.
1327 secret_service_unlock_dbus_paths (SecretService *self,
1328 const gchar **paths,
1329 GCancellable *cancellable,
1330 GAsyncReadyCallback callback,
1333 g_return_if_fail (SECRET_IS_SERVICE (self));
1334 g_return_if_fail (paths != NULL);
1335 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
1337 _secret_service_xlock_paths_async (self, "Unlock",
1339 callback, user_data);
1343 * secret_service_unlock_dbus_paths_finish:
1344 * @self: the secret service
1345 * @result: asynchronous result passed to the callback
1346 * @unlocked: (out) (array zero-terminated=1) (transfer full) (allow-none):
1347 * location to place array of D-Bus paths of items or collections
1348 * that were unlocked
1349 * @error: location to place an error on failure
1351 * Complete asynchronous operation to unlock items or collections in the secret
1354 * The secret service may not be able to unlock items individually, and may
1355 * unlock an entire collection instead.
1357 * Returns: the number of items or collections that were unlocked
1360 secret_service_unlock_dbus_paths_finish (SecretService *self,
1361 GAsyncResult *result,
1365 g_return_val_if_fail (SECRET_IS_SERVICE (self), -1);
1366 g_return_val_if_fail (error == NULL || *error == NULL, -1);
1368 return _secret_service_xlock_paths_finish (self, result,
1373 GCancellable *cancellable;
1374 SecretPrompt *prompt;
1379 delete_closure_free (gpointer data)
1381 DeleteClosure *closure = data;
1382 g_clear_object (&closure->prompt);
1383 g_clear_object (&closure->cancellable);
1384 g_slice_free (DeleteClosure, closure);
1388 on_delete_prompted (GObject *source,
1389 GAsyncResult *result,
1392 GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
1393 DeleteClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
1394 GError *error = NULL;
1397 retval = secret_service_prompt_finish (SECRET_SERVICE (source), result,
1401 closure->deleted = TRUE;
1403 g_simple_async_result_take_error (res, error);
1405 g_variant_unref (retval);
1406 g_simple_async_result_complete (res);
1407 g_object_unref (res);
1411 on_delete_complete (GObject *source,
1412 GAsyncResult *result,
1415 GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
1416 DeleteClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
1417 SecretService *self = SECRET_SERVICE (g_async_result_get_source_object (user_data));
1418 const gchar *prompt_path;
1419 GError *error = NULL;
1422 retval = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), result, &error);
1423 if (error == NULL) {
1424 g_variant_get (retval, "(&o)", &prompt_path);
1426 if (_secret_util_empty_path (prompt_path)) {
1427 closure->deleted = TRUE;
1428 g_simple_async_result_complete (res);
1431 closure->prompt = _secret_prompt_instance (self, prompt_path);
1433 secret_service_prompt (self, closure->prompt,
1434 closure->cancellable,
1436 g_object_ref (res));
1439 g_variant_unref (retval);
1442 g_simple_async_result_take_error (res, error);
1443 g_simple_async_result_complete (res);
1446 g_object_unref (self);
1447 g_object_unref (res);
1451 _secret_service_delete_path (SecretService *self,
1452 const gchar *object_path,
1453 gboolean is_an_item,
1454 GCancellable *cancellable,
1455 GAsyncReadyCallback callback,
1458 GSimpleAsyncResult *res;
1459 DeleteClosure *closure;
1461 g_return_if_fail (SECRET_IS_SERVICE (self));
1462 g_return_if_fail (object_path != NULL);
1463 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
1465 res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
1466 _secret_service_delete_path);
1467 closure = g_slice_new0 (DeleteClosure);
1468 closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
1469 g_simple_async_result_set_op_res_gpointer (res, closure, delete_closure_free);
1471 g_dbus_connection_call (g_dbus_proxy_get_connection (G_DBUS_PROXY (self)),
1472 g_dbus_proxy_get_name (G_DBUS_PROXY (self)), object_path,
1473 is_an_item ? SECRET_ITEM_INTERFACE : SECRET_COLLECTION_INTERFACE,
1474 "Delete", g_variant_new ("()"), G_VARIANT_TYPE ("(o)"),
1475 G_DBUS_CALL_FLAGS_NO_AUTO_START, -1,
1476 cancellable, on_delete_complete, g_object_ref (res));
1478 g_object_unref (res);
1482 _secret_service_delete_path_finish (SecretService *self,
1483 GAsyncResult *result,
1486 GSimpleAsyncResult *res;
1487 DeleteClosure *closure;
1489 g_return_val_if_fail (SECRET_IS_SERVICE (self), FALSE);
1490 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1491 g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
1492 _secret_service_delete_path), FALSE);
1494 res = G_SIMPLE_ASYNC_RESULT (result);
1495 if (_secret_util_propagate_error (res, error))
1498 closure = g_simple_async_result_get_op_res_gpointer (res);
1499 return closure->deleted;
1503 * secret_service_delete_item_dbus_path:
1504 * @self: the secret service
1505 * @item_path: the D-Bus path of item to delete
1506 * @cancellable: optional cancellation object
1507 * @callback: called when the operation completes
1508 * @user_data: data to be passed to the callback
1510 * Delete a secret item from the secret service.
1512 * The item is represented by its D-Bus object path. If you already have a
1513 * #SecretItem proxy objects, use use secret_item_delete() instead.
1515 * This method will return immediately and complete asynchronously.
1518 secret_service_delete_item_dbus_path (SecretService *self,
1519 const gchar *item_path,
1520 GCancellable *cancellable,
1521 GAsyncReadyCallback callback,
1524 g_return_if_fail (SECRET_IS_SERVICE (self));
1525 g_return_if_fail (item_path != NULL);
1526 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
1528 _secret_service_delete_path (self, item_path, TRUE, cancellable, callback, user_data);
1532 * secret_service_delete_item_dbus_path_finish:
1533 * @self: the secret service
1534 * @result: the asynchronous result passed to the callback
1535 * @error: location to place an error on failure
1537 * Complete an asynchronous operation to delete a secret item from the secret
1540 * Returns: whether the deletion was successful or not
1543 secret_service_delete_item_dbus_path_finish (SecretService *self,
1544 GAsyncResult *result,
1547 g_return_val_if_fail (SECRET_IS_SERVICE (self), FALSE);
1548 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1549 g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
1550 _secret_service_delete_path), FALSE);
1552 return _secret_service_delete_path_finish (self, result, error);
1556 * secret_service_delete_item_dbus_path_sync:
1557 * @self: the secret service
1558 * @item_path: the D-Bus path of item to delete
1559 * @cancellable: optional cancellation object
1560 * @error: location to place an error on failure
1562 * Delete a secret item from the secret service.
1564 * The item is represented by its D-Bus object path. If you already have a
1565 * #SecretItem proxy objects, use use secret_item_delete_sync() instead.
1567 * This method may block indefinitely and should not be used in user interface
1570 * Returns: whether the deletion was successful or not
1573 secret_service_delete_item_dbus_path_sync (SecretService *self,
1574 const gchar *item_path,
1575 GCancellable *cancellable,
1581 g_return_val_if_fail (SECRET_IS_SERVICE (self), FALSE);
1582 g_return_val_if_fail (item_path != NULL, FALSE);
1583 g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
1584 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1586 sync = _secret_sync_new ();
1587 g_main_context_push_thread_default (sync->context);
1589 secret_service_delete_item_dbus_path (self, item_path, cancellable,
1590 _secret_sync_on_result, sync);
1592 g_main_loop_run (sync->loop);
1594 result = secret_service_delete_item_dbus_path_finish (self, sync->result, error);
1596 g_main_context_pop_thread_default (sync->context);
1597 _secret_sync_free (sync);
1603 GCancellable *cancellable;
1604 SecretPrompt *prompt;
1605 gchar *collection_path;
1606 } CollectionClosure;
1609 collection_closure_free (gpointer data)
1611 CollectionClosure *closure = data;
1612 g_clear_object (&closure->cancellable);
1613 g_clear_object (&closure->prompt);
1614 g_slice_free (CollectionClosure, closure);
1618 on_create_collection_prompt (GObject *source,
1619 GAsyncResult *result,
1622 GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
1623 CollectionClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
1624 GError *error = NULL;
1627 value = secret_service_prompt_finish (SECRET_SERVICE (source), result,
1628 G_VARIANT_TYPE ("o"), &error);
1630 g_simple_async_result_take_error (res, error);
1631 if (value != NULL) {
1632 closure->collection_path = g_variant_dup_string (value, NULL);
1633 g_variant_unref (value);
1636 g_simple_async_result_complete (res);
1637 g_object_unref (res);
1641 on_create_collection_called (GObject *source,
1642 GAsyncResult *result,
1645 GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
1646 CollectionClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
1647 SecretService *self = SECRET_SERVICE (g_async_result_get_source_object (user_data));
1648 const gchar *prompt_path = NULL;
1649 const gchar *collection_path = NULL;
1650 GError *error = NULL;
1653 retval = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), result, &error);
1654 if (error == NULL) {
1655 g_variant_get (retval, "(&o&o)", &collection_path, &prompt_path);
1656 if (!_secret_util_empty_path (prompt_path)) {
1657 closure->prompt = _secret_prompt_instance (self, prompt_path);
1658 secret_service_prompt (self, closure->prompt,
1659 closure->cancellable, on_create_collection_prompt,
1660 g_object_ref (res));
1663 closure->collection_path = g_strdup (collection_path);
1664 g_simple_async_result_complete (res);
1667 g_variant_unref (retval);
1670 g_simple_async_result_take_error (res, error);
1671 g_simple_async_result_complete (res);
1674 g_object_unref (self);
1675 g_object_unref (res);
1679 * secret_service_create_collection_dbus_path:
1680 * @self: a secret service object
1681 * @properties: (element-type utf8 GLib.Variant): hash table of properties for
1682 * the new collection
1683 * @alias: (allow-none): an alias to check for before creating the new
1684 * collection, or to assign to the new collection
1685 * @flags: not currently used
1686 * @cancellable: optional cancellation object
1687 * @callback: called when the operation completes
1688 * @user_data: data to be passed to the callback
1690 * Create a new collection in the secret service, and return its path.
1692 * Using this method requires that you setup a correct hash table of D-Bus
1693 * properties for the new collection. You may prefer to use
1694 * secret_collection_create() which does handles this for you.
1696 * An @alias is a well-known tag for a collection, such as 'default' (ie: the
1697 * default collection to store items in). This allows other applications to
1698 * easily identify and share a collection. If a collection with the @alias
1699 * already exists, then instead of creating a new collection, the existing
1700 * collection will be returned. If no collection with this alias exists, then a
1701 * new collection will be created and this alias will be assigned to it.
1703 * @properties is a set of properties for the new collection. The keys in the
1704 * hash table should be interface.property strings like
1705 * <literal>org.freedesktop.Secret.Collection.Label</literal>. The values
1706 * in the hash table should be #GVariant values of the properties.
1708 * If you wish to have a
1710 * This method will return immediately and complete asynchronously. The secret
1711 * service may prompt the user. secret_service_prompt() will be used to handle
1712 * any prompts that are required.
1715 secret_service_create_collection_dbus_path (SecretService *self,
1716 GHashTable *properties,
1718 SecretCollectionCreateFlags flags,
1719 GCancellable *cancellable,
1720 GAsyncReadyCallback callback,
1723 GSimpleAsyncResult *res;
1724 CollectionClosure *closure;
1729 g_return_if_fail (SECRET_IS_SERVICE (self));
1730 g_return_if_fail (properties != NULL);
1731 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
1736 res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
1737 secret_service_create_collection_dbus_path);
1738 closure = g_slice_new0 (CollectionClosure);
1739 closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
1740 g_simple_async_result_set_op_res_gpointer (res, closure, collection_closure_free);
1742 props = _secret_util_variant_for_properties (properties);
1743 params = g_variant_new ("(@a{sv}s)", props, alias);
1744 proxy = G_DBUS_PROXY (self);
1746 g_dbus_connection_call (g_dbus_proxy_get_connection (proxy),
1747 g_dbus_proxy_get_name (proxy),
1748 g_dbus_proxy_get_object_path (proxy),
1749 SECRET_SERVICE_INTERFACE,
1750 "CreateCollection", params, G_VARIANT_TYPE ("(oo)"),
1751 G_DBUS_CALL_FLAGS_NONE, -1,
1752 closure->cancellable,
1753 on_create_collection_called,
1754 g_object_ref (res));
1756 g_object_unref (res);
1761 * secret_service_create_collection_dbus_path_finish:
1762 * @self: a secret service object
1763 * @result: the asynchronous result passed to the callback
1764 * @error: location to place an error on failure
1766 * Finish asynchronous operation to create a new collection in the secret
1769 * Returns: (transfer full): a new string containing the D-Bus object path
1773 secret_service_create_collection_dbus_path_finish (SecretService *self,
1774 GAsyncResult *result,
1777 GSimpleAsyncResult *res;
1778 CollectionClosure *closure;
1781 g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
1782 secret_service_create_collection_dbus_path), NULL);
1783 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
1785 res = G_SIMPLE_ASYNC_RESULT (result);
1787 if (_secret_util_propagate_error (res, error))
1790 closure = g_simple_async_result_get_op_res_gpointer (res);
1791 path = closure->collection_path;
1792 closure->collection_path = NULL;
1797 * secret_service_create_collection_dbus_path_sync:
1798 * @self: a secret service object
1799 * @properties: (element-type utf8 GLib.Variant): hash table of D-Bus properties
1800 * for the new collection
1801 * @alias: (allow-none): an alias to check for before creating the new
1802 * collection, or to assign to the new collection
1803 * @flags: not currently used
1804 * @cancellable: optional cancellation object
1805 * @error: location to place an error on failure
1807 * Create a new collection in the secret service and return its path.
1809 * Using this method requires that you setup a correct hash table of D-Bus
1810 * properties for the new collection. You may prefer to use
1811 * secret_collection_create() which does handles this for you.
1813 * An @alias is a well-known tag for a collection, such as 'default' (ie: the
1814 * default collection to store items in). This allows other applications to
1815 * easily identify and share a collection. If a collection with the @alias
1816 * already exists, then instead of creating a new collection, the existing
1817 * collection will be returned. If no collection with this alias exists, then
1818 * a new collection will be created and this alias will be assigned to it.
1820 * @properties is a set of properties for the new collection. The keys in the
1821 * hash table should be interface.property strings like
1822 * <literal>org.freedesktop.Secret.Collection.Label</literal>. The values
1823 * in the hash table should be #GVariant values of the properties.
1825 * This method may block indefinitely and should not be used in user interface
1826 * threads. The secret service may prompt the user. secret_service_prompt()
1827 * will be used to handle any prompts that are required.
1829 * Returns: (transfer full): a new string containing the D-Bus object path
1833 secret_service_create_collection_dbus_path_sync (SecretService *self,
1834 GHashTable *properties,
1836 SecretCollectionCreateFlags flags,
1837 GCancellable *cancellable,
1843 g_return_val_if_fail (SECRET_IS_SERVICE (self), NULL);
1844 g_return_val_if_fail (properties != NULL, NULL);
1845 g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
1846 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
1848 sync = _secret_sync_new ();
1849 g_main_context_push_thread_default (sync->context);
1851 secret_service_create_collection_dbus_path (self, properties, alias, flags, cancellable,
1852 _secret_sync_on_result, sync);
1854 g_main_loop_run (sync->loop);
1856 path = secret_service_create_collection_dbus_path_finish (self, sync->result, error);
1858 g_main_context_pop_thread_default (sync->context);
1859 _secret_sync_free (sync);
1865 GCancellable *cancellable;
1866 GVariant *properties;
1869 gchar *collection_path;
1870 SecretPrompt *prompt;
1875 item_closure_free (gpointer data)
1877 ItemClosure *closure = data;
1878 g_variant_unref (closure->properties);
1879 secret_value_unref (closure->value);
1880 g_clear_object (&closure->cancellable);
1881 g_free (closure->collection_path);
1882 g_clear_object (&closure->prompt);
1883 g_slice_free (ItemClosure, closure);
1887 on_create_item_prompt (GObject *source,
1888 GAsyncResult *result,
1891 GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
1892 ItemClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
1893 GError *error = NULL;
1896 value = secret_service_prompt_finish (SECRET_SERVICE (source), result,
1897 G_VARIANT_TYPE ("o"), &error);
1899 g_simple_async_result_take_error (res, error);
1900 if (value != NULL) {
1901 closure->item_path = g_variant_dup_string (value, NULL);
1902 g_variant_unref (value);
1905 g_simple_async_result_complete (res);
1906 g_object_unref (res);
1910 on_create_item_called (GObject *source,
1911 GAsyncResult *result,
1914 GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
1915 ItemClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
1916 SecretService *self = SECRET_SERVICE (g_async_result_get_source_object (user_data));
1917 const gchar *prompt_path = NULL;
1918 const gchar *item_path = NULL;
1919 GError *error = NULL;
1922 retval = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), result, &error);
1923 if (error == NULL) {
1924 g_variant_get (retval, "(&o&o)", &item_path, &prompt_path);
1925 if (!_secret_util_empty_path (prompt_path)) {
1926 closure->prompt = _secret_prompt_instance (self, prompt_path);
1927 secret_service_prompt (self, closure->prompt,
1928 closure->cancellable, on_create_item_prompt,
1929 g_object_ref (res));
1932 closure->item_path = g_strdup (item_path);
1933 g_simple_async_result_complete (res);
1936 g_variant_unref (retval);
1939 g_simple_async_result_take_error (res, error);
1940 g_simple_async_result_complete (res);
1943 g_object_unref (self);
1944 g_object_unref (res);
1948 on_create_item_session (GObject *source,
1949 GAsyncResult *result,
1952 GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
1953 ItemClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
1954 SecretService *self = SECRET_SERVICE (source);
1955 SecretSession *session;
1957 GError *error = NULL;
1960 secret_service_ensure_session_finish (self, result, &error);
1961 if (error == NULL) {
1962 session = _secret_service_get_session (self);
1963 params = g_variant_new ("(@a{sv}@(oayays)b)",
1964 closure->properties,
1965 _secret_session_encode_secret (session, closure->value),
1968 proxy = G_DBUS_PROXY (self);
1969 g_dbus_connection_call (g_dbus_proxy_get_connection (proxy),
1970 g_dbus_proxy_get_name (proxy),
1971 closure->collection_path,
1972 SECRET_COLLECTION_INTERFACE,
1973 "CreateItem", params, G_VARIANT_TYPE ("(oo)"),
1974 G_DBUS_CALL_FLAGS_NONE, -1,
1975 closure->cancellable,
1976 on_create_item_called,
1977 g_object_ref (res));
1979 g_simple_async_result_take_error (res, error);
1980 g_simple_async_result_complete (res);
1983 g_object_unref (res);
1987 * secret_service_create_item_dbus_path:
1988 * @self: a secret service object
1989 * @collection_path: the D-Bus object path of the collection in which to create item
1990 * @properties: (element-type utf8 GLib.Variant): hash table of D-Bus properties
1991 * for the new collection
1992 * @value: the secret value to store in the item
1993 * @flags: flags for the creation of the new item
1994 * @cancellable: optional cancellation object
1995 * @callback: called when the operation completes
1996 * @user_data: data to be passed to the callback
1998 * Create a new item in a secret service collection and return its D-Bus
2001 * It is often easier to use secret_password_store() or secret_item_create()
2002 * rather than using this function. Using this method requires that you setup
2003 * a correct hash table of D-Bus @properties for the new collection.
2005 * If the @flags contains %SECRET_ITEM_CREATE_REPLACE, then the secret
2006 * service will search for an item matching the @attributes, and update that item
2007 * instead of creating a new one.
2009 * @properties is a set of properties for the new collection. The keys in the
2010 * hash table should be interface.property strings like
2011 * <literal>org.freedesktop.Secret.Item.Label</literal>. The values
2012 * in the hash table should be #GVariant values of the properties.
2014 * This method will return immediately and complete asynchronously. The secret
2015 * service may prompt the user. secret_service_prompt() will be used to handle
2016 * any prompts that are required.
2019 secret_service_create_item_dbus_path (SecretService *self,
2020 const gchar *collection_path,
2021 GHashTable *properties,
2023 SecretItemCreateFlags flags,
2024 GCancellable *cancellable,
2025 GAsyncReadyCallback callback,
2028 GSimpleAsyncResult *res;
2029 ItemClosure *closure;
2031 g_return_if_fail (SECRET_IS_SERVICE (self));
2032 g_return_if_fail (collection_path != NULL && g_variant_is_object_path (collection_path));
2033 g_return_if_fail (properties != NULL);
2034 g_return_if_fail (value != NULL);
2035 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
2037 res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
2038 secret_service_create_item_dbus_path);
2039 closure = g_slice_new0 (ItemClosure);
2040 closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
2041 closure->properties = _secret_util_variant_for_properties (properties);
2042 g_variant_ref_sink (closure->properties);
2043 closure->replace = flags & SECRET_ITEM_CREATE_REPLACE;
2044 closure->value = secret_value_ref (value);
2045 closure->collection_path = g_strdup (collection_path);
2046 g_simple_async_result_set_op_res_gpointer (res, closure, item_closure_free);
2048 secret_service_ensure_session (self, cancellable,
2049 on_create_item_session,
2050 g_object_ref (res));
2052 g_object_unref (res);
2056 * secret_service_create_item_dbus_path_finish:
2057 * @self: a secret service object
2058 * @result: the asynchronous result passed to the callback
2059 * @error: location to place an error on failure
2061 * Finish asynchronous operation to create a new item in the secret
2064 * Returns: (transfer full): a new string containing the D-Bus object path
2068 secret_service_create_item_dbus_path_finish (SecretService *self,
2069 GAsyncResult *result,
2072 GSimpleAsyncResult *res;
2073 ItemClosure *closure;
2076 g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
2077 secret_service_create_item_dbus_path), NULL);
2078 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
2080 res = G_SIMPLE_ASYNC_RESULT (result);
2082 if (_secret_util_propagate_error (res, error))
2085 closure = g_simple_async_result_get_op_res_gpointer (res);
2086 path = closure->item_path;
2087 closure->item_path = NULL;
2092 * secret_service_create_item_dbus_path_sync:
2093 * @self: a secret service object
2094 * @collection_path: the D-Bus path of the collection in which to create item
2095 * @properties: (element-type utf8 GLib.Variant): hash table of D-Bus properties
2096 * for the new collection
2097 * @value: the secret value to store in the item
2098 * @flags: flags for the creation of the new item
2099 * @cancellable: optional cancellation object
2100 * @error: location to place an error on failure
2102 * Create a new item in a secret service collection and return its D-Bus
2105 * It is often easier to use secret_password_store_sync() or secret_item_create_sync()
2106 * rather than using this function. Using this method requires that you setup
2107 * a correct hash table of D-Bus @properties for the new collection.
2109 * If the @flags contains %SECRET_ITEM_CREATE_REPLACE, then the secret
2110 * service will search for an item matching the @attributes, and update that item
2111 * instead of creating a new one.
2113 * @properties is a set of properties for the new collection. The keys in the
2114 * hash table should be interface.property strings like
2115 * <literal>org.freedesktop.Secret.Item.Label</literal>. The values
2116 * in the hash table should be #GVariant values of the properties.
2118 * This method may block indefinitely and should not be used in user interface
2119 * threads. The secret service may prompt the user. secret_service_prompt()
2120 * will be used to handle any prompts that are required.
2122 * Returns: (transfer full): a new string containing the D-Bus object path
2126 secret_service_create_item_dbus_path_sync (SecretService *self,
2127 const gchar *collection_path,
2128 GHashTable *properties,
2130 SecretItemCreateFlags flags,
2131 GCancellable *cancellable,
2137 g_return_val_if_fail (SECRET_IS_SERVICE (self), NULL);
2138 g_return_val_if_fail (collection_path != NULL && g_variant_is_object_path (collection_path), NULL);
2139 g_return_val_if_fail (properties != NULL, NULL);
2140 g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
2141 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
2143 sync = _secret_sync_new ();
2144 g_main_context_push_thread_default (sync->context);
2146 secret_service_create_item_dbus_path (self, collection_path, properties, value, flags,
2147 cancellable, _secret_sync_on_result, sync);
2149 g_main_loop_run (sync->loop);
2151 path = secret_service_create_item_dbus_path_finish (self, sync->result, error);
2153 g_main_context_pop_thread_default (sync->context);
2154 _secret_sync_free (sync);
2160 * secret_service_read_alias_dbus_path:
2161 * @self: a secret service object
2162 * @alias: the alias to lookup
2163 * @cancellable: (allow-none): optional cancellation object
2164 * @callback: called when the operation completes
2165 * @user_data: data to pass to the callback
2167 * Lookup which collection is assigned to this alias. Aliases help determine
2168 * well known collections, such as 'default'. This method looks up the
2169 * dbus object path of the well known collection.
2171 * This method will return immediately and complete asynchronously.
2174 secret_service_read_alias_dbus_path (SecretService *self,
2176 GCancellable *cancellable,
2177 GAsyncReadyCallback callback,
2180 g_return_if_fail (SECRET_IS_SERVICE (self));
2181 g_return_if_fail (alias != NULL);
2182 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
2184 g_dbus_proxy_call (G_DBUS_PROXY (self), "ReadAlias",
2185 g_variant_new ("(s)", alias),
2186 G_DBUS_CALL_FLAGS_NONE, -1,
2187 cancellable, callback, user_data);
2191 * secret_service_read_alias_dbus_path_finish:
2192 * @self: a secret service object
2193 * @result: asynchronous result passed to callback
2194 * @error: location to place error on failure
2196 * Finish an asynchronous operation to lookup which collection is assigned
2197 * to an alias. This method returns the DBus object path of the collection
2199 * Returns: (transfer full): the collection dbus object path, or %NULL if
2200 * none assigned to the alias
2203 secret_service_read_alias_dbus_path_finish (SecretService *self,
2204 GAsyncResult *result,
2207 gchar *collection_path;
2210 retval = g_dbus_proxy_call_finish (G_DBUS_PROXY (self), result, error);
2212 _secret_util_strip_remote_error (error);
2216 g_variant_get (retval, "(o)", &collection_path);
2217 g_variant_unref (retval);
2219 if (g_str_equal (collection_path, "/")) {
2220 g_free (collection_path);
2221 collection_path = NULL;
2224 return collection_path;
2228 * secret_service_read_alias_dbus_path_sync:
2229 * @self: a secret service object
2230 * @alias: the alias to lookup
2231 * @cancellable: (allow-none): optional cancellation object
2232 * @error: location to place error on failure
2234 * Lookup which collection is assigned to this alias. Aliases help determine
2235 * well known collections, such as 'default'. This method returns the dbus
2236 * object path of the collection.
2238 * This method may block and should not be used in user interface threads.
2240 * Returns: (transfer full): the collection dbus object path, or %NULL if
2241 * none assigned to the alias
2244 secret_service_read_alias_dbus_path_sync (SecretService *self,
2246 GCancellable *cancellable,
2250 gchar *collection_path;
2252 g_return_val_if_fail (SECRET_IS_SERVICE (self), NULL);
2253 g_return_val_if_fail (alias != NULL, NULL);
2254 g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
2255 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
2257 sync = _secret_sync_new ();
2258 g_main_context_push_thread_default (sync->context);
2260 secret_service_read_alias_dbus_path (self, alias, cancellable, _secret_sync_on_result, sync);
2262 g_main_loop_run (sync->loop);
2264 collection_path = secret_service_read_alias_dbus_path_finish (self, sync->result, error);
2266 g_main_context_pop_thread_default (sync->context);
2267 _secret_sync_free (sync);
2269 return collection_path;
2273 * secret_service_set_alias_to_dbus_path:
2274 * @self: a secret service object
2275 * @alias: the alias to assign the collection to
2276 * @collection_path: (allow-none): the dbus object path of the collection to assign to the alias
2277 * @cancellable: (allow-none): optional cancellation object
2278 * @callback: called when the operation completes
2279 * @user_data: data to pass to the callback
2281 * Assign a collection to this alias. Aliases help determine
2282 * well known collections, such as 'default'. This method takes the dbus object
2283 * path of the collection to assign to the alias.
2285 * This method will return immediately and complete asynchronously.
2288 secret_service_set_alias_to_dbus_path (SecretService *self,
2290 const gchar *collection_path,
2291 GCancellable *cancellable,
2292 GAsyncReadyCallback callback,
2295 g_return_if_fail (SECRET_IS_SERVICE (self));
2296 g_return_if_fail (alias != NULL);
2297 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
2299 if (collection_path == NULL)
2300 collection_path = "/";
2302 g_return_if_fail (g_variant_is_object_path (collection_path));
2304 g_dbus_proxy_call (G_DBUS_PROXY (self), "SetAlias",
2305 g_variant_new ("(so)", alias, collection_path),
2306 G_DBUS_CALL_FLAGS_NONE, -1, cancellable,
2307 callback, user_data);
2311 * secret_service_set_alias_to_dbus_path_finish:
2312 * @self: a secret service object
2313 * @result: asynchronous result passed to callback
2314 * @error: location to place error on failure
2316 * Finish an asynchronous operation to assign a collection to an alias.
2318 * Returns: %TRUE if successful
2321 secret_service_set_alias_to_dbus_path_finish (SecretService *self,
2322 GAsyncResult *result,
2327 g_return_val_if_fail (SECRET_IS_SERVICE (self), FALSE);
2328 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
2330 retval = g_dbus_proxy_call_finish (G_DBUS_PROXY (self), result, error);
2332 _secret_util_strip_remote_error (error);
2336 g_variant_unref (retval);
2341 * secret_service_set_alias_to_dbus_path_sync:
2342 * @self: a secret service object
2343 * @alias: the alias to assign the collection to
2344 * @collection_path: (allow-none): the dbus object path of the collection to assign to the alias
2345 * @cancellable: (allow-none): optional cancellation object
2346 * @error: location to place error on failure
2348 * Assign a collection to this alias. Aliases help determine
2349 * well known collections, such as 'default'. This method takes the dbus object
2350 * path of the collection to assign to the alias.
2352 * This method may block and should not be used in user interface threads.
2354 * Returns: %TRUE if successful
2357 secret_service_set_alias_to_dbus_path_sync (SecretService *self,
2359 const gchar *collection_path,
2360 GCancellable *cancellable,
2366 g_return_val_if_fail (SECRET_IS_SERVICE (self), FALSE);
2367 g_return_val_if_fail (alias != NULL, FALSE);
2368 g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
2369 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
2371 if (collection_path == NULL)
2372 collection_path = "/";
2374 g_return_val_if_fail (g_variant_is_object_path (collection_path), FALSE);
2376 sync = _secret_sync_new ();
2377 g_main_context_push_thread_default (sync->context);
2379 secret_service_set_alias_to_dbus_path (self, alias, collection_path,
2380 cancellable, _secret_sync_on_result, sync);
2382 g_main_loop_run (sync->loop);
2384 ret = secret_service_set_alias_to_dbus_path_finish (self, sync->result, error);
2386 g_main_context_pop_thread_default (sync->context);
2387 _secret_sync_free (sync);
2393 secret_service_prompt_at_dbus_path_sync (SecretService *self,
2394 const gchar *prompt_path,
2395 GCancellable *cancellable,
2396 const GVariantType *return_type,
2399 SecretPrompt *prompt;
2402 g_return_val_if_fail (SECRET_IS_SERVICE (self), NULL);
2403 g_return_val_if_fail (prompt_path != NULL, NULL);
2404 g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
2405 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
2407 prompt = _secret_prompt_instance (self, prompt_path);
2408 retval = secret_service_prompt_sync (self, prompt, cancellable, return_type, error);
2409 g_object_unref (prompt);
2415 * secret_service_prompt_at_dbus_path:
2416 * @self: the secret service
2417 * @prompt_path: the D-Bus object path of the prompt
2418 * @cancellable: optional cancellation object
2419 * @callback: called when the operation completes
2420 * @user_data: data to be passed to the callback
2422 * Perform prompting for a #SecretPrompt.
2424 * This function is called by other parts of this library to handle prompts
2425 * for the various actions that can require prompting.
2427 * Override the #SecretServiceClass <literal>prompt_async</literal> virtual method
2428 * to change the behavior of the propmting. The default behavior is to simply
2429 * run secret_prompt_perform() on the prompt.
2432 secret_service_prompt_at_dbus_path (SecretService *self,
2433 const gchar *prompt_path,
2434 GCancellable *cancellable,
2435 GAsyncReadyCallback callback,
2438 SecretPrompt *prompt;
2440 g_return_if_fail (SECRET_IS_SERVICE (self));
2441 g_return_if_fail (prompt_path != NULL);
2442 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
2444 prompt = _secret_prompt_instance (self, prompt_path);
2445 secret_service_prompt (self, prompt, cancellable, callback, user_data);
2446 g_object_unref (prompt);
2450 * secret_service_prompt_at_dbus_path_finish:
2451 * @self: the secret service
2452 * @result: the asynchronous result passed to the callback
2453 * @return_type: the variant type of the prompt result
2454 * @error: location to place an error on failure
2456 * Complete asynchronous operation to perform prompting for a #SecretPrompt.
2458 * Returns a variant result if the prompt was completed and not dismissed. The
2459 * type of result depends on the action the prompt is completing, and is defined
2460 * in the Secret Service DBus API specification.
2462 * Returns: (transfer full): %NULL if the prompt was dismissed or an error occurred,
2463 * a variant result if the prompt was successful
2466 secret_service_prompt_at_dbus_path_finish (SecretService *self,
2467 GAsyncResult *result,
2468 const GVariantType *return_type,
2471 g_return_val_if_fail (SECRET_IS_SERVICE (self), NULL);
2472 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
2473 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
2475 return secret_service_prompt_finish (self, result, return_type, error);