Branch data Line data Source code
1 : : /* libsecret - GLib wrapper for Secret Service
2 : : *
3 : : * Copyright 2011 Collabora Ltd.
4 : : * Copyright 2012 Red Hat Inc.
5 : : *
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.
10 : : *
11 : : * See the included COPYING file for more information.
12 : : *
13 : : * Author: Stef Walter <stefw@gnome.org>
14 : : */
15 : :
16 : : #include "config.h"
17 : :
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"
24 : :
25 : :
26 : : /**
27 : : * secret_collection_new_for_dbus_path: (skip)
28 : : * @service: (nullable): a secret service object
29 : : * @collection_path: the D-Bus path of the collection
30 : : * @flags: options for the collection initialization
31 : : * @cancellable: (nullable): optional cancellation object
32 : : * @callback: called when the operation completes
33 : : * @user_data: data to be passed to the callback
34 : : *
35 : : * Get a new collection proxy for a collection in the secret service.
36 : : *
37 : : * If @service is %NULL, then [func@Service.get] will be called to get
38 : : * the default [class@Service] proxy.
39 : : *
40 : : * This method will return immediately and complete asynchronously.
41 : : *
42 : : * Stability: Unstable
43 : : */
44 : : void
45 : 32 : secret_collection_new_for_dbus_path (SecretService *service,
46 : : const gchar *collection_path,
47 : : SecretCollectionFlags flags,
48 : : GCancellable *cancellable,
49 : : GAsyncReadyCallback callback,
50 : : gpointer user_data)
51 : : {
52 : : GDBusProxy *proxy;
53 : :
54 [ + - - + : 32 : g_return_if_fail (service == NULL || SECRET_IS_SERVICE (service));
+ - + - -
+ ]
55 [ - + ]: 32 : g_return_if_fail (collection_path != NULL);
56 [ - + - - : 32 : g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
- - - - -
- ]
57 : :
58 : 32 : proxy = G_DBUS_PROXY (service);
59 : :
60 : 32 : g_async_initable_new_async (secret_service_get_collection_gtype (service),
61 : : G_PRIORITY_DEFAULT, cancellable, callback, user_data,
62 : : "g-flags", G_DBUS_CALL_FLAGS_NONE,
63 : : "g-interface-info", _secret_gen_collection_interface_info (),
64 : : "g-name", g_dbus_proxy_get_name (proxy),
65 : : "g-connection", g_dbus_proxy_get_connection (proxy),
66 : : "g-object-path", collection_path,
67 : : "g-interface-name", SECRET_COLLECTION_INTERFACE,
68 : : "service", service,
69 : : "flags", flags,
70 : : NULL);
71 : : }
72 : :
73 : : /**
74 : : * secret_collection_new_for_dbus_path_finish: (skip)
75 : : * @result: the asynchronous result passed to the callback
76 : : * @error: location to place an error on failure
77 : : *
78 : : * Finish asynchronous operation to get a new collection proxy for a
79 : : * collection in the secret service.
80 : : *
81 : : * Returns: (transfer full): the new collection, which should be unreferenced
82 : : * with [method@GObject.Object.unref]
83 : : */
84 : : SecretCollection *
85 : 32 : secret_collection_new_for_dbus_path_finish (GAsyncResult *result,
86 : : GError **error)
87 : : {
88 : : GObject *source_object;
89 : : GObject *object;
90 : :
91 [ - + + - : 32 : g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
- + - + ]
92 [ + - - + ]: 32 : g_return_val_if_fail (error == NULL || *error == NULL, NULL);
93 : :
94 : 32 : source_object = g_async_result_get_source_object (result);
95 : 32 : object = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object),
96 : : result, error);
97 : 32 : g_object_unref (source_object);
98 : :
99 [ + + ]: 32 : if (object == NULL)
100 : 1 : return NULL;
101 : :
102 : 31 : return SECRET_COLLECTION (object);
103 : : }
104 : :
105 : : /**
106 : : * secret_collection_new_for_dbus_path_sync: (skip)
107 : : * @service: (nullable): a secret service object
108 : : * @collection_path: the D-Bus path of the collection
109 : : * @flags: options for the collection initialization
110 : : * @cancellable: (nullable): optional cancellation object
111 : : * @error: location to place an error on failure
112 : : *
113 : : * Get a new collection proxy for a collection in the secret service.
114 : : *
115 : : * If @service is %NULL, then [func@Service.get_sync] will be called to get
116 : : * the default [class@Service] proxy.
117 : : *
118 : : * This method may block indefinitely and should not be used in user interface
119 : : * threads.
120 : : *
121 : : * Stability: Unstable
122 : : *
123 : : * Returns: (transfer full): the new collection, which should be unreferenced
124 : : * with [method@GObject.Object.unref]
125 : : */
126 : : SecretCollection *
127 : 43 : secret_collection_new_for_dbus_path_sync (SecretService *service,
128 : : const gchar *collection_path,
129 : : SecretCollectionFlags flags,
130 : : GCancellable *cancellable,
131 : : GError **error)
132 : : {
133 : : GDBusProxy *proxy;
134 : :
135 [ + - - + : 43 : g_return_val_if_fail (service == NULL || SECRET_IS_SERVICE (service), NULL);
+ - + - -
+ ]
136 [ - + ]: 43 : g_return_val_if_fail (collection_path != NULL, NULL);
137 [ - + - - : 43 : g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
- - - - -
- ]
138 [ + - - + ]: 43 : g_return_val_if_fail (error == NULL || *error == NULL, NULL);
139 : :
140 : 43 : proxy = G_DBUS_PROXY (service);
141 : :
142 : 43 : return g_initable_new (secret_service_get_collection_gtype (service),
143 : : cancellable, error,
144 : : "g-flags", G_DBUS_CALL_FLAGS_NONE,
145 : : "g-interface-info", _secret_gen_collection_interface_info (),
146 : : "g-name", g_dbus_proxy_get_name (proxy),
147 : : "g-connection", g_dbus_proxy_get_connection (proxy),
148 : : "g-object-path", collection_path,
149 : : "g-interface-name", SECRET_COLLECTION_INTERFACE,
150 : : "service", service,
151 : : "flags", flags,
152 : : NULL);
153 : : }
154 : :
155 : : /**
156 : : * secret_item_new_for_dbus_path: (skip)
157 : : * @service: (nullable): a secret service object
158 : : * @item_path: the D-Bus path of the collection
159 : : * @flags: initialization flags for the new item
160 : : * @cancellable: (nullable): optional cancellation object
161 : : * @callback: called when the operation completes
162 : : * @user_data: data to be passed to the callback
163 : : *
164 : : * Get a new item proxy for a secret item in the secret service.
165 : : *
166 : : * If @service is %NULL, then [func@Service.get] will be called to get
167 : : * the default [class@Service] proxy.
168 : : *
169 : : * This method will return immediately and complete asynchronously.
170 : : *
171 : : * Stability: Unstable
172 : : */
173 : : void
174 : 74 : secret_item_new_for_dbus_path (SecretService *service,
175 : : const gchar *item_path,
176 : : SecretItemFlags flags,
177 : : GCancellable *cancellable,
178 : : GAsyncReadyCallback callback,
179 : : gpointer user_data)
180 : : {
181 : : GDBusProxy *proxy;
182 : :
183 [ + - - + : 74 : g_return_if_fail (service == NULL || SECRET_IS_SERVICE (service));
+ - + - -
+ ]
184 [ - + ]: 74 : g_return_if_fail (item_path != NULL);
185 [ - + - - : 74 : g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
- - - - -
- ]
186 : :
187 : 74 : proxy = G_DBUS_PROXY (service);
188 : :
189 : 74 : g_async_initable_new_async (secret_service_get_item_gtype (service),
190 : : G_PRIORITY_DEFAULT, cancellable, callback, user_data,
191 : : "g-flags", G_DBUS_CALL_FLAGS_NONE,
192 : : "g-interface-info", _secret_gen_item_interface_info (),
193 : : "g-name", g_dbus_proxy_get_name (proxy),
194 : : "g-connection", g_dbus_proxy_get_connection (proxy),
195 : : "g-object-path", item_path,
196 : : "g-interface-name", SECRET_ITEM_INTERFACE,
197 : : "service", service,
198 : : "flags", flags,
199 : : NULL);
200 : : }
201 : :
202 : : /**
203 : : * secret_item_new_for_dbus_path_finish: (skip)
204 : : * @result: the asynchronous result passed to the callback
205 : : * @error: location to place an error on failure
206 : : *
207 : : * Finish asynchronous operation to get a new item proxy for a secret
208 : : * item in the secret service.
209 : : *
210 : : * Stability: Unstable
211 : : *
212 : : * Returns: (transfer full): the new item, which should be unreferenced
213 : : * with [method@GObject.Object.unref]
214 : : */
215 : : SecretItem *
216 : 74 : secret_item_new_for_dbus_path_finish (GAsyncResult *result,
217 : : GError **error)
218 : : {
219 : : GObject *object;
220 : : GObject *source_object;
221 : :
222 : 74 : source_object = g_async_result_get_source_object (result);
223 : 74 : object = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object),
224 : : result, error);
225 : 74 : g_object_unref (source_object);
226 : :
227 [ + + ]: 74 : if (object == NULL)
228 : 1 : return NULL;
229 : :
230 : 73 : return SECRET_ITEM (object);
231 : : }
232 : :
233 : : /**
234 : : * secret_item_new_for_dbus_path_sync: (skip)
235 : : * @service: (nullable): a secret service object
236 : : * @item_path: the D-Bus path of the item
237 : : * @flags: initialization flags for the new item
238 : : * @cancellable: (nullable): optional cancellation object
239 : : * @error: location to place an error on failure
240 : : *
241 : : * Get a new item proxy for a secret item in the secret service.
242 : : *
243 : : * If @service is %NULL, then [func@Service.get_sync] will be called to get
244 : : * the default [class@Service] proxy.
245 : : *
246 : : * This method may block indefinitely and should not be used in user interface
247 : : * threads.
248 : : *
249 : : * Stability: Unstable
250 : : *
251 : : * Returns: (transfer full): the new item, which should be unreferenced
252 : : * with [method@GObject.Object.unref]
253 : : */
254 : : SecretItem *
255 : 70 : secret_item_new_for_dbus_path_sync (SecretService *service,
256 : : const gchar *item_path,
257 : : SecretItemFlags flags,
258 : : GCancellable *cancellable,
259 : : GError **error)
260 : : {
261 : : GDBusProxy *proxy;
262 : :
263 [ + - - + : 70 : g_return_val_if_fail (service == NULL || SECRET_IS_SERVICE (service), NULL);
+ - + - -
+ ]
264 [ - + ]: 70 : g_return_val_if_fail (item_path != NULL, NULL);
265 [ - + - - : 70 : g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
- - - - -
- ]
266 [ + - - + ]: 70 : g_return_val_if_fail (error == NULL || *error == NULL, NULL);
267 : :
268 : 70 : proxy = G_DBUS_PROXY (service);
269 : :
270 : 70 : return g_initable_new (secret_service_get_item_gtype (service),
271 : : cancellable, error,
272 : : "g-flags", G_DBUS_CALL_FLAGS_NONE,
273 : : "g-interface-info", _secret_gen_item_interface_info (),
274 : : "g-name", g_dbus_proxy_get_name (proxy),
275 : : "g-connection", g_dbus_proxy_get_connection (proxy),
276 : : "g-object-path", item_path,
277 : : "g-interface-name", SECRET_ITEM_INTERFACE,
278 : : "service", service,
279 : : "flags", flags,
280 : : NULL);
281 : : }
282 : :
283 : : static void
284 : 59 : on_search_items_complete (GObject *source,
285 : : GAsyncResult *result,
286 : : gpointer user_data)
287 : : {
288 : 59 : GTask *task = G_TASK (user_data);
289 : 59 : GError *error = NULL;
290 : : GVariant *response;
291 : :
292 : 59 : response = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), result, &error);
293 [ - + ]: 59 : if (error != NULL) {
294 : 0 : g_task_return_error (task, g_steal_pointer (&error));
295 : : } else {
296 : 59 : g_task_return_pointer (task,
297 : : g_steal_pointer (&response),
298 : : (GDestroyNotify) g_variant_unref);
299 : : }
300 : :
301 : 59 : g_object_unref (task);
302 : 59 : }
303 : :
304 : : /**
305 : : * secret_collection_search_for_dbus_paths: (skip)
306 : : * @collection: the secret collection
307 : : * @schema: (nullable): the schema for the attributes
308 : : * @attributes: (element-type utf8 utf8): search for items matching these attributes
309 : : * @cancellable: (nullable): optional cancellation object
310 : : * @callback: called when the operation completes
311 : : * @user_data: data to pass to the callback
312 : : *
313 : : * Search for items in @collection matching the @attributes, and return their
314 : : * DBus object paths.
315 : : *
316 : : * Only the specified collection is searched. The @attributes should be a table
317 : : * of string keys and string values.
318 : : *
319 : : * This function returns immediately and completes asynchronously.
320 : : *
321 : : * When your callback is called use [method@Collection.search_for_dbus_paths_finish]
322 : : * to get the results of this function. Only the DBus object paths of the
323 : : * items will be returned. If you would like [class@Item] objects to be returned
324 : : * instead, then use the [method@Collection.search] function.
325 : : *
326 : : * Stability: Unstable
327 : : */
328 : : void
329 : 8 : secret_collection_search_for_dbus_paths (SecretCollection *collection,
330 : : const SecretSchema *schema,
331 : : GHashTable *attributes,
332 : : GCancellable *cancellable,
333 : : GAsyncReadyCallback callback,
334 : : gpointer user_data)
335 : : {
336 : 8 : GTask *task = NULL;
337 : 8 : const gchar *schema_name = NULL;
338 : :
339 [ - + + - : 8 : g_return_if_fail (SECRET_IS_COLLECTION (collection));
+ - - + ]
340 [ - + ]: 8 : g_return_if_fail (attributes != NULL);
341 [ - + - - : 8 : g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
- - - - -
- ]
342 : :
343 : : /* Warnings raised already */
344 [ + - - + ]: 8 : if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
345 : 0 : return;
346 : :
347 [ + - + - ]: 8 : if (schema != NULL && !(schema->flags & SECRET_SCHEMA_DONT_MATCH_NAME))
348 : 8 : schema_name = schema->name;
349 : :
350 : 8 : task = g_task_new (collection, cancellable, callback, user_data);
351 [ + - ]: 8 : g_task_set_source_tag (task, secret_collection_search_for_dbus_paths);
352 : :
353 : 8 : g_dbus_proxy_call (G_DBUS_PROXY (collection), "SearchItems",
354 : : g_variant_new ("(@a{ss})",
355 : : _secret_attributes_to_variant (attributes, schema_name)),
356 : : G_DBUS_CALL_FLAGS_NONE, -1, cancellable,
357 : : on_search_items_complete, g_steal_pointer (&task));
358 : :
359 [ - + ]: 8 : g_clear_object (&task);
360 : : }
361 : :
362 : : /**
363 : : * secret_collection_search_for_dbus_paths_finish: (skip)
364 : : * @collection: the secret collection
365 : : * @result: asynchronous result passed to callback
366 : : * @error: location to place error on failure
367 : : *
368 : : * Complete asynchronous operation to search for items in a collection.
369 : : *
370 : : * DBus object paths of the items will be returned. If you would to have
371 : : * [class@Item] objects to be returned instead, then use the
372 : : * [method@Collection.search] and [method@Collection.search_finish] functions.
373 : : *
374 : : * Stability: Unstable
375 : : *
376 : : * Returns: (transfer full) (array zero-terminated=1): an array of DBus object
377 : : * paths for matching items.
378 : : */
379 : : gchar **
380 : 8 : secret_collection_search_for_dbus_paths_finish (SecretCollection *collection,
381 : : GAsyncResult *result,
382 : : GError **error)
383 : : {
384 : 8 : GVariant *retval = NULL;
385 : 8 : gchar **paths = NULL;
386 : :
387 [ - + ]: 8 : g_return_val_if_fail (g_task_is_valid (result, collection), NULL);
388 [ - + ]: 8 : g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) ==
389 : : secret_collection_search_for_dbus_paths, NULL);
390 [ + - - + ]: 8 : g_return_val_if_fail (error == NULL || *error == NULL, NULL);
391 : :
392 : 8 : retval = g_task_propagate_pointer (G_TASK (result), error);
393 [ - + ]: 8 : if (retval == NULL) {
394 : 0 : _secret_util_strip_remote_error (error);
395 : 0 : return NULL;
396 : : }
397 : :
398 : 8 : g_variant_get (retval, "(^ao)", &paths);
399 [ + - ]: 8 : g_clear_pointer (&retval, g_variant_unref);
400 : 8 : return g_steal_pointer (&paths);
401 : : }
402 : :
403 : : /**
404 : : * secret_collection_search_for_dbus_paths_sync: (skip)
405 : : * @collection: the secret collection
406 : : * @schema: (nullable): the schema for the attributes
407 : : * @attributes: (element-type utf8 utf8): search for items matching these attributes
408 : : * @cancellable: (nullable): optional cancellation object
409 : : * @error: location to place error on failure
410 : : *
411 : : * Search for items matching the @attributes in @collection, and return their
412 : : * DBus object paths.
413 : : *
414 : : * The @attributes should be a table of string keys and string values.
415 : : *
416 : : * This function may block indefinitely. Use the asynchronous version
417 : : * in user interface threads.
418 : : *
419 : : * DBus object paths of the items will be returned. If you would to have
420 : : * [class@Item] objects to be returned instead, then use the
421 : : * [method@Collection.search_sync] function.
422 : : *
423 : : * Stability: Unstable
424 : : *
425 : : * Returns: (transfer full) (array zero-terminated=1): an array of DBus object
426 : : * paths for matching items.
427 : : */
428 : : gchar **
429 : 4 : secret_collection_search_for_dbus_paths_sync (SecretCollection *collection,
430 : : const SecretSchema *schema,
431 : : GHashTable *attributes,
432 : : GCancellable *cancellable,
433 : : GError **error)
434 : : {
435 : : SecretSync *sync;
436 : : gchar **paths;
437 : :
438 [ - + + - : 4 : g_return_val_if_fail (SECRET_IS_COLLECTION (collection), NULL);
+ - - + ]
439 [ - + ]: 4 : g_return_val_if_fail (attributes != NULL, NULL);
440 [ - + - - : 4 : g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
- - - - -
- ]
441 [ + - - + ]: 4 : g_return_val_if_fail (error == NULL || *error == NULL, NULL);
442 : :
443 : 4 : sync = _secret_sync_new ();
444 : 4 : g_main_context_push_thread_default (sync->context);
445 : :
446 : 4 : secret_collection_search_for_dbus_paths (collection, schema, attributes, cancellable,
447 : : _secret_sync_on_result, sync);
448 : :
449 : 4 : g_main_loop_run (sync->loop);
450 : :
451 : 4 : paths = secret_collection_search_for_dbus_paths_finish (collection, sync->result, error);
452 : :
453 : 4 : g_main_context_pop_thread_default (sync->context);
454 : 4 : _secret_sync_free (sync);
455 : :
456 : 4 : return paths;
457 : : }
458 : :
459 : : /**
460 : : * secret_service_search_for_dbus_paths: (skip)
461 : : * @self: the secret service
462 : : * @schema: (nullable): the schema for the attributes
463 : : * @attributes: (element-type utf8 utf8): search for items matching these attributes
464 : : * @cancellable: (nullable): optional cancellation object
465 : : * @callback: called when the operation completes
466 : : * @user_data: data to pass to the callback
467 : : *
468 : : * Search for items matching the @attributes, and return their D-Bus object paths.
469 : : *
470 : : * All collections are searched. The @attributes should be a table of string keys
471 : : * and string values.
472 : : *
473 : : * This function returns immediately and completes asynchronously.
474 : : *
475 : : * When your callback is called use [method@Service.search_for_dbus_paths_finish]
476 : : * to get the results of this function. Only the D-Bus object paths of the
477 : : * items will be returned. If you would like [class@Item] objects to be returned
478 : : * instead, then use the [method@Service.search] function.
479 : : *
480 : : * Stability: Unstable
481 : : */
482 : : void
483 : 4 : secret_service_search_for_dbus_paths (SecretService *self,
484 : : const SecretSchema *schema,
485 : : GHashTable *attributes,
486 : : GCancellable *cancellable,
487 : : GAsyncReadyCallback callback,
488 : : gpointer user_data)
489 : : {
490 : 4 : const gchar *schema_name = NULL;
491 : :
492 [ - + + - : 4 : g_return_if_fail (SECRET_IS_SERVICE (self));
+ - - + ]
493 [ - + ]: 4 : g_return_if_fail (attributes != NULL);
494 [ - + - - : 4 : g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
- - - - -
- ]
495 : :
496 : : /* Warnings raised already */
497 [ + - - + ]: 4 : if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
498 : 0 : return;
499 : :
500 [ + - + - ]: 4 : if (schema != NULL && !(schema->flags & SECRET_SCHEMA_DONT_MATCH_NAME))
501 : 4 : schema_name = schema->name;
502 : :
503 : 4 : _secret_service_search_for_paths_variant (self, _secret_attributes_to_variant (attributes, schema_name),
504 : : cancellable, callback, user_data);
505 : : }
506 : :
507 : : void
508 : 51 : _secret_service_search_for_paths_variant (SecretService *self,
509 : : GVariant *attributes,
510 : : GCancellable *cancellable,
511 : : GAsyncReadyCallback callback,
512 : : gpointer user_data)
513 : : {
514 : 51 : GTask *task = NULL;
515 : :
516 [ - + + - : 51 : g_return_if_fail (SECRET_IS_SERVICE (self));
+ - - + ]
517 [ - + ]: 51 : g_return_if_fail (attributes != NULL);
518 [ - + - - : 51 : g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
- - - - -
- ]
519 : :
520 : 51 : task = g_task_new (self, cancellable, callback, user_data);
521 [ + - ]: 51 : g_task_set_source_tag (task, secret_service_search_for_dbus_paths);
522 : :
523 : 51 : g_dbus_proxy_call (G_DBUS_PROXY (self), "SearchItems",
524 : : g_variant_new ("(@a{ss})", attributes),
525 : : G_DBUS_CALL_FLAGS_NONE, -1, cancellable,
526 : : on_search_items_complete, g_steal_pointer (&task));
527 : :
528 [ - + ]: 51 : g_clear_object (&task);
529 : : }
530 : :
531 : : /**
532 : : * secret_service_search_for_dbus_paths_finish: (skip)
533 : : * @self: the secret service
534 : : * @result: asynchronous result passed to callback
535 : : * @unlocked: (out) (transfer full) (array zero-terminated=1) (optional) (nullable):
536 : : * location to place an array of D-Bus object paths for matching
537 : : * items which were locked.
538 : : * @locked: (out) (transfer full) (array zero-terminated=1) (optional) (nullable):
539 : : * location to place an array of D-Bus object paths for matching
540 : : * items which were locked.
541 : : * @error: location to place error on failure
542 : : *
543 : : * Complete asynchronous operation to search for items, and return their
544 : : * D-Bus object paths.
545 : : *
546 : : * Matching items that are locked or unlocked, have their D-Bus paths placed
547 : : * in the @locked or @unlocked arrays respectively.
548 : : *
549 : : * D-Bus object paths of the items will be returned in the @unlocked or
550 : : * @locked arrays. If you would to have [class@Item] objects to be returned
551 : : * instead, then us the [method@Service.search] and
552 : : * [method@Service.search_finish] functions.
553 : : *
554 : : * Stability: Unstable
555 : : *
556 : : * Returns: whether the search was successful or not
557 : : */
558 : : gboolean
559 : 51 : secret_service_search_for_dbus_paths_finish (SecretService *self,
560 : : GAsyncResult *result,
561 : : gchar ***unlocked,
562 : : gchar ***locked,
563 : : GError **error)
564 : : {
565 : : GVariant *response;
566 : 51 : gchar **unlocked_ret = NULL, **locked_ret = NULL;
567 : :
568 [ - + ]: 51 : g_return_val_if_fail (g_task_is_valid (result, self), FALSE);
569 [ - + ]: 51 : g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) ==
570 : : secret_service_search_for_dbus_paths, FALSE);
571 [ + - - + ]: 51 : g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
572 : :
573 : 51 : response = g_task_propagate_pointer (G_TASK (result), error);
574 [ - + ]: 51 : if (response == NULL) {
575 : 0 : _secret_util_strip_remote_error (error);
576 : 0 : return FALSE;
577 : : }
578 : :
579 : 51 : g_variant_get (response, "(^ao^ao)", &unlocked_ret, &locked_ret);
580 : :
581 [ + + ]: 51 : if (unlocked)
582 : 49 : *unlocked = g_steal_pointer (&unlocked_ret);
583 [ + + ]: 51 : if (locked)
584 : 35 : *locked = g_steal_pointer (&locked_ret);
585 : :
586 : 51 : g_strfreev (unlocked_ret);
587 : 51 : g_strfreev (locked_ret);
588 : 51 : g_variant_unref (response);
589 : :
590 : 51 : return TRUE;
591 : : }
592 : :
593 : : /**
594 : : * secret_service_search_for_dbus_paths_sync: (skip)
595 : : * @self: the secret service
596 : : * @schema: (nullable): the schema for the attributes
597 : : * @attributes: (element-type utf8 utf8): search for items matching these attributes
598 : : * @cancellable: (nullable): optional cancellation object
599 : : * @unlocked: (out) (transfer full) (array zero-terminated=1) (optional) (nullable):
600 : : * location to place an array of D-Bus object paths for matching
601 : : * items which were locked.
602 : : * @locked: (out) (transfer full) (array zero-terminated=1) (optional) (nullable):
603 : : * location to place an array of D-Bus object paths for matching
604 : : * items which were locked.
605 : : * @error: location to place error on failure
606 : : *
607 : : * Search for items matching the @attributes, and return their D-Bus object
608 : : * paths.
609 : : *
610 : : * All collections are searched. The @attributes should be a table of string
611 : : * keys and string values.
612 : : *
613 : : * This function may block indefinitely. Use the asynchronous version
614 : : * in user interface threads.
615 : : *
616 : : * Matching items that are locked or unlocked, have their D-Bus paths placed
617 : : * in the @locked or @unlocked arrays respectively.
618 : : *
619 : : * D-Bus object paths of the items will be returned in the @unlocked or
620 : : * @locked arrays. If you would to have [class@Item] objects to be returned
621 : : * instead, then use the [method@Service.search_sync] function.
622 : : *
623 : : * Stability: Unstable
624 : : *
625 : : * Returns: whether the search was successful or not
626 : : */
627 : : gboolean
628 : 12 : secret_service_search_for_dbus_paths_sync (SecretService *self,
629 : : const SecretSchema *schema,
630 : : GHashTable *attributes,
631 : : GCancellable *cancellable,
632 : : gchar ***unlocked,
633 : : gchar ***locked,
634 : : GError **error)
635 : : {
636 : 12 : const gchar *schema_name = NULL;
637 : : GVariant *response;
638 : 12 : gchar **unlocked_ret = NULL, **locked_ret = NULL;
639 : :
640 [ - + + - : 12 : g_return_val_if_fail (SECRET_IS_SERVICE (self), FALSE);
+ - - + ]
641 [ - + ]: 12 : g_return_val_if_fail (attributes != NULL, FALSE);
642 [ - + - - : 12 : g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
- - - - -
- ]
643 [ + - - + ]: 12 : g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
644 : :
645 : : /* Warnings raised already */
646 [ + - - + ]: 12 : if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
647 : 0 : return FALSE;
648 : :
649 [ + - + - ]: 12 : if (schema != NULL && !(schema->flags & SECRET_SCHEMA_DONT_MATCH_NAME))
650 : 12 : schema_name = schema->name;
651 : :
652 : 12 : response = g_dbus_proxy_call_sync (G_DBUS_PROXY (self), "SearchItems",
653 : : g_variant_new ("(@a{ss})",
654 : : _secret_attributes_to_variant (attributes, schema_name)),
655 : : G_DBUS_CALL_FLAGS_NONE, -1,
656 : : cancellable, error);
657 : :
658 [ - + ]: 12 : if (response == NULL)
659 : 0 : return FALSE;
660 : :
661 : 12 : g_variant_get (response, "(^ao^ao)", &unlocked_ret, &locked_ret);
662 [ + + ]: 12 : if (unlocked)
663 : 10 : *unlocked = g_steal_pointer (&unlocked_ret);
664 [ + + ]: 12 : if (locked)
665 : 6 : *locked = g_steal_pointer (&locked_ret);
666 : 12 : g_variant_unref (response);
667 : :
668 : 12 : g_strfreev (unlocked_ret);
669 : 12 : g_strfreev (locked_ret);
670 : :
671 : 12 : return TRUE;
672 : : }
673 : :
674 : : static void
675 : 25 : on_get_secrets_complete (GObject *source,
676 : : GAsyncResult *result,
677 : : gpointer user_data)
678 : : {
679 : 25 : GTask *task = G_TASK (user_data);
680 : : GVariant *ret;
681 : 25 : GError *error = NULL;
682 : :
683 : 25 : ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), result, &error);
684 [ - + ]: 25 : if (error != NULL) {
685 : 0 : g_task_return_error (task, g_steal_pointer (&error));
686 : : } else {
687 : 25 : g_task_return_pointer (task, ret, (GDestroyNotify) g_variant_unref);
688 : : }
689 : :
690 [ + - ]: 25 : g_clear_object (&task);
691 : 25 : }
692 : :
693 : : static void
694 : 25 : on_get_secrets_session (GObject *source,
695 : : GAsyncResult *result,
696 : : gpointer user_data)
697 : : {
698 : 25 : GTask *task = G_TASK (user_data);
699 : 25 : GVariant *item_paths = g_task_get_task_data (task);
700 : 25 : GCancellable *cancellable = g_task_get_cancellable (task);
701 : 25 : GError *error = NULL;
702 : : const gchar *session;
703 : :
704 : 25 : secret_service_ensure_session_finish (SECRET_SERVICE (source), result, &error);
705 [ - + ]: 25 : if (error != NULL) {
706 : 0 : g_task_return_error (task, g_steal_pointer (&error));
707 : : } else {
708 : 25 : session = secret_service_get_session_dbus_path (SECRET_SERVICE (source));
709 : 25 : g_dbus_proxy_call (G_DBUS_PROXY (source), "GetSecrets",
710 : : g_variant_new ("(@aoo)", item_paths, session),
711 : : G_DBUS_CALL_FLAGS_NO_AUTO_START, -1,
712 : : cancellable, on_get_secrets_complete,
713 : : g_steal_pointer (&task));
714 : : }
715 : :
716 [ - + ]: 25 : g_clear_object (&task);
717 : 25 : }
718 : :
719 : : /**
720 : : * secret_service_get_secret_for_dbus_path: (skip)
721 : : * @self: the secret service
722 : : * @item_path: the D-Bus path to item to retrieve secret for
723 : : * @cancellable: (nullable): optional cancellation object
724 : : * @callback: called when the operation completes
725 : : * @user_data: data to pass to the callback
726 : : *
727 : : * Get the secret value for a secret item stored in the service.
728 : : *
729 : : * The item is represented by its D-Bus object path. If you already have a
730 : : * [class@Item] proxy object, use use [method@Item.get_secret] to more simply
731 : : * get its secret value.
732 : : *
733 : : * This function returns immediately and completes asynchronously.
734 : : *
735 : : * Stability: Unstable
736 : : */
737 : : void
738 : 23 : secret_service_get_secret_for_dbus_path (SecretService *self,
739 : : const gchar *item_path,
740 : : GCancellable *cancellable,
741 : : GAsyncReadyCallback callback,
742 : : gpointer user_data)
743 : : {
744 : : GTask *task;
745 : : GVariant *path_variant;
746 : :
747 [ - + + - : 23 : g_return_if_fail (SECRET_IS_SERVICE (self));
+ - - + ]
748 [ - + ]: 23 : g_return_if_fail (item_path != NULL);
749 [ - + - - : 23 : g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
- - - - -
- ]
750 : :
751 : 23 : path_variant = g_variant_ref_sink (g_variant_new_objv (&item_path, 1));
752 : :
753 : 23 : task = g_task_new (self, cancellable, callback, user_data);
754 [ + - ]: 23 : g_task_set_source_tag (task, secret_service_get_secret_for_dbus_path);
755 : 23 : g_task_set_task_data (task, path_variant, (GDestroyNotify) g_variant_unref);
756 : :
757 : 23 : secret_service_ensure_session (self, cancellable,
758 : : on_get_secrets_session,
759 : : g_steal_pointer (&task));
760 : :
761 [ - + ]: 23 : g_clear_object (&task);
762 : : }
763 : :
764 : : /**
765 : : * secret_service_get_secret_for_dbus_path_finish: (skip)
766 : : * @self: the secret service
767 : : * @result: asynchronous result passed to callback
768 : : * @error: location to place an error on failure
769 : : *
770 : : * Complete asynchronous operation to get the secret value for an
771 : : * secret item stored in the service.
772 : : *
773 : : * Will return %NULL if the item is locked.
774 : : *
775 : : * Stability: Unstable
776 : : *
777 : : * Returns: (transfer full) (nullable): the newly allocated secret value
778 : : * for the item, which should be released with [method@Value.unref]
779 : : */
780 : : SecretValue *
781 : 23 : secret_service_get_secret_for_dbus_path_finish (SecretService *self,
782 : : GAsyncResult *result,
783 : : GError **error)
784 : : {
785 : : GVariant *ret;
786 : : SecretValue *value;
787 : :
788 [ - + + - : 23 : g_return_val_if_fail (SECRET_IS_SERVICE (self), NULL);
+ - - + ]
789 [ - + ]: 23 : g_return_val_if_fail (g_task_is_valid (result, self), NULL);
790 [ - + ]: 23 : g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) ==
791 : : secret_service_get_secret_for_dbus_path, NULL);
792 [ + - - + ]: 23 : g_return_val_if_fail (error == NULL || *error == NULL, NULL);
793 : :
794 : 23 : ret = g_task_propagate_pointer (G_TASK (result), error);
795 [ - + ]: 23 : if (ret == NULL) {
796 : 0 : _secret_util_strip_remote_error (error);
797 : 0 : return NULL;
798 : : }
799 : :
800 : 23 : value = _secret_service_decode_get_secrets_first (self, ret);
801 : 23 : g_variant_unref (ret);
802 : 23 : return value;
803 : : }
804 : :
805 : : /**
806 : : * secret_service_get_secret_for_dbus_path_sync: (skip)
807 : : * @self: the secret service
808 : : * @item_path: the D-Bus path to item to retrieve secret for
809 : : * @cancellable: (nullable): optional cancellation object
810 : : * @error: location to place an error on failure
811 : : *
812 : : * Get the secret value for a secret item stored in the service.
813 : : *
814 : : * The item is represented by its D-Bus object path. If you already have a
815 : : * [class@Item] proxy object, use use [method@Item.load_secret_sync] to more simply
816 : : * get its secret value.
817 : : *
818 : : * This method may block indefinitely and should not be used in user interface
819 : : * threads.
820 : : *
821 : : * Will return %NULL if the item is locked.
822 : : *
823 : : * Stability: Unstable
824 : : *
825 : : * Returns: (transfer full) (nullable): the newly allocated secret value
826 : : * the item, which should be released with [method@Value.unref]
827 : : */
828 : : SecretValue *
829 : 5 : secret_service_get_secret_for_dbus_path_sync (SecretService *self,
830 : : const gchar *item_path,
831 : : GCancellable *cancellable,
832 : : GError **error)
833 : : {
834 : : SecretSync *sync;
835 : : SecretValue *value;
836 : :
837 [ - + + - : 5 : g_return_val_if_fail (SECRET_IS_SERVICE (self), NULL);
+ - - + ]
838 [ - + ]: 5 : g_return_val_if_fail (item_path != NULL, NULL);
839 [ - + - - : 5 : g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
- - - - -
- ]
840 [ + - - + ]: 5 : g_return_val_if_fail (error == NULL || *error == NULL, NULL);
841 : :
842 : 5 : sync = _secret_sync_new ();
843 : 5 : g_main_context_push_thread_default (sync->context);
844 : :
845 : 5 : secret_service_get_secret_for_dbus_path (self, item_path, cancellable,
846 : : _secret_sync_on_result, sync);
847 : :
848 : 5 : g_main_loop_run (sync->loop);
849 : :
850 : 5 : value = secret_service_get_secret_for_dbus_path_finish (self, sync->result, error);
851 : :
852 : 5 : g_main_context_pop_thread_default (sync->context);
853 : 5 : _secret_sync_free (sync);
854 : :
855 : 5 : return value;
856 : : }
857 : :
858 : : /**
859 : : * secret_service_get_secrets_for_dbus_paths: (skip)
860 : : * @self: the secret service
861 : : * @item_paths: the D-Bus paths to items to retrieve secrets for
862 : : * @cancellable: (nullable): optional cancellation object
863 : : * @callback: called when the operation completes
864 : : * @user_data: data to pass to the callback
865 : : *
866 : : * Get the secret values for a secret item stored in the service.
867 : : *
868 : : * The items are represented by their D-Bus object paths. If you already have
869 : : * [class@Item] proxy objects, use use [func@Item.load_secrets] to more simply
870 : : * get their secret values.
871 : : *
872 : : * This function returns immediately and completes asynchronously.
873 : : *
874 : : * Stability: Unstable
875 : : */
876 : : void
877 : 2 : secret_service_get_secrets_for_dbus_paths (SecretService *self,
878 : : const gchar **item_paths,
879 : : GCancellable *cancellable,
880 : : GAsyncReadyCallback callback,
881 : : gpointer user_data)
882 : : {
883 : : GTask *task;
884 : : GVariant *paths_variant;
885 : :
886 [ - + + - : 2 : g_return_if_fail (SECRET_IS_SERVICE (self));
+ - - + ]
887 [ - + ]: 2 : g_return_if_fail (item_paths != NULL);
888 [ - + - - : 2 : g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
- - - - -
- ]
889 : :
890 : 2 : paths_variant = g_variant_ref_sink (g_variant_new_objv (item_paths, -1));
891 : :
892 : 2 : task = g_task_new (self, cancellable, callback, user_data);
893 [ + - ]: 2 : g_task_set_source_tag (task, secret_service_get_secret_for_dbus_path);
894 : 2 : g_task_set_task_data (task, paths_variant, (GDestroyNotify) g_variant_unref);
895 : :
896 : 2 : secret_service_ensure_session (self, cancellable,
897 : : on_get_secrets_session,
898 : : g_steal_pointer (&task));
899 : :
900 [ - + ]: 2 : g_clear_object (&task);
901 : : }
902 : :
903 : : /**
904 : : * secret_service_get_secrets_for_dbus_paths_finish: (skip)
905 : : * @self: the secret service
906 : : * @result: asynchronous result passed to callback
907 : : * @error: location to place an error on failure
908 : : *
909 : : * Complete asynchronous operation to get the secret values for an
910 : : * secret items stored in the service.
911 : : *
912 : : * Items that are locked will not be included the results.
913 : : *
914 : : * Stability: Unstable
915 : : *
916 : : * Returns: (transfer full) (element-type utf8 Secret.Value): a newly
917 : : * allocated hash table of item path keys to [struct@Value]
918 : : * values.
919 : : */
920 : : GHashTable *
921 : 2 : secret_service_get_secrets_for_dbus_paths_finish (SecretService *self,
922 : : GAsyncResult *result,
923 : : GError **error)
924 : : {
925 : : GVariant *ret;
926 : : GHashTable *values;
927 : :
928 [ - + + - : 2 : g_return_val_if_fail (SECRET_IS_SERVICE (self), NULL);
+ - - + ]
929 [ - + ]: 2 : g_return_val_if_fail (g_task_is_valid (result, self), NULL);
930 [ - + ]: 2 : g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) ==
931 : : secret_service_get_secret_for_dbus_path, NULL);
932 [ + - - + ]: 2 : g_return_val_if_fail (error == NULL || *error == NULL, NULL);
933 : :
934 : 2 : ret = g_task_propagate_pointer (G_TASK (result), error);
935 [ - + ]: 2 : if (ret == NULL) {
936 : 0 : _secret_util_strip_remote_error (error);
937 : 0 : return NULL;
938 : : }
939 : :
940 : 2 : values = _secret_service_decode_get_secrets_all (self, ret);
941 : 2 : g_variant_unref (ret);
942 : 2 : return values;
943 : : }
944 : :
945 : : /**
946 : : * secret_service_get_secrets_for_dbus_paths_sync: (skip)
947 : : * @self: the secret service
948 : : * @item_paths: the D-Bus paths to items to retrieve secrets for
949 : : * @cancellable: (nullable): optional cancellation object
950 : : * @error: location to place an error on failure
951 : : *
952 : : * Get the secret values for a secret item stored in the service.
953 : : *
954 : : * The items are represented by their D-Bus object paths. If you already have
955 : : * [class@Item] proxy objects, use use [func@Item.load_secrets_sync] to more
956 : : * simply get their secret values.
957 : : *
958 : : * This method may block indefinitely and should not be used in user interface
959 : : * threads.
960 : : *
961 : : * Items that are locked will not be included the results.
962 : : *
963 : : * Stability: Unstable
964 : : *
965 : : * Returns: (transfer full) (element-type utf8 Secret.Value): a newly
966 : : * allocated hash table of item_path keys to [struct@Value]
967 : : * values.
968 : : */
969 : : GHashTable *
970 : 1 : secret_service_get_secrets_for_dbus_paths_sync (SecretService *self,
971 : : const gchar **item_paths,
972 : : GCancellable *cancellable,
973 : : GError **error)
974 : : {
975 : : SecretSync *sync;
976 : : GHashTable *secrets;
977 : :
978 [ - + + - : 1 : g_return_val_if_fail (SECRET_IS_SERVICE (self), NULL);
+ - - + ]
979 [ - + ]: 1 : g_return_val_if_fail (item_paths != NULL, NULL);
980 [ - + - - : 1 : g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
- - - - -
- ]
981 [ + - - + ]: 1 : g_return_val_if_fail (error == NULL || *error == NULL, NULL);
982 : :
983 : 1 : sync = _secret_sync_new ();
984 : 1 : g_main_context_push_thread_default (sync->context);
985 : :
986 : 1 : secret_service_get_secrets_for_dbus_paths (self, item_paths, cancellable,
987 : : _secret_sync_on_result, sync);
988 : :
989 : 1 : g_main_loop_run (sync->loop);
990 : :
991 : 1 : secrets = secret_service_get_secrets_for_dbus_paths_finish (self, sync->result, error);
992 : :
993 : 1 : g_main_context_pop_thread_default (sync->context);
994 : 1 : _secret_sync_free (sync);
995 : :
996 : 1 : return secrets;
997 : : }
998 : :
999 : :
1000 : : typedef struct {
1001 : : SecretPrompt *prompt;
1002 : : } XlockClosure;
1003 : :
1004 : : static void
1005 : 17 : xlock_closure_free (gpointer data)
1006 : : {
1007 : 17 : XlockClosure *closure = data;
1008 [ + + ]: 17 : g_clear_object (&closure->prompt);
1009 : 17 : g_free (closure);
1010 : 17 : }
1011 : :
1012 : : static void
1013 : 1 : on_xlock_prompted (GObject *source,
1014 : : GAsyncResult *result,
1015 : : gpointer user_data)
1016 : : {
1017 : 1 : GTask *task = G_TASK (user_data);
1018 : 1 : SecretService *self = SECRET_SERVICE (source);
1019 : : GPtrArray *xlocked_array;
1020 : 1 : GError *error = NULL;
1021 : : GVariantIter iter;
1022 : : GVariant *retval;
1023 : : gchar *path;
1024 : :
1025 : 1 : retval = secret_service_prompt_finish (self, result, &error);
1026 [ - + ]: 1 : if (error != NULL) {
1027 : 0 : g_task_return_error (task, g_steal_pointer (&error));
1028 : :
1029 : : } else {
1030 : 1 : xlocked_array = g_ptr_array_new_with_free_func (g_free);
1031 : 1 : g_variant_iter_init (&iter, retval);
1032 [ + + ]: 2 : while (g_variant_iter_loop (&iter, "o", &path))
1033 : 2 : g_ptr_array_add (xlocked_array, g_strdup (path));
1034 : 1 : g_variant_unref (retval);
1035 : :
1036 : 1 : g_task_return_pointer (task,
1037 : : xlocked_array,
1038 : : (GDestroyNotify) g_ptr_array_unref);
1039 : : }
1040 : :
1041 [ + - ]: 1 : g_clear_object (&task);
1042 : 1 : }
1043 : :
1044 : : static void
1045 : 17 : on_xlock_called (GObject *source,
1046 : : GAsyncResult *result,
1047 : : gpointer user_data)
1048 : : {
1049 : 17 : GTask *task = G_TASK (user_data);
1050 : 17 : XlockClosure *closure = g_task_get_task_data (task);
1051 : 17 : GCancellable *cancellable = g_task_get_cancellable (task);
1052 : 17 : SecretService *self = SECRET_SERVICE (g_task_get_source_object (task));
1053 : 17 : const gchar *prompt = NULL;
1054 : 17 : gchar **xlocked = NULL;
1055 : 17 : GError *error = NULL;
1056 : : GVariant *retval;
1057 : : guint i;
1058 : :
1059 : 17 : retval = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), result, &error);
1060 [ - + ]: 17 : if (error != NULL) {
1061 : 0 : g_task_return_error (task, g_steal_pointer (&error));
1062 : :
1063 : : } else {
1064 : 17 : g_variant_get (retval, "(^ao&o)", &xlocked, &prompt);
1065 : :
1066 [ + + ]: 17 : if (_secret_util_empty_path (prompt)) {
1067 : : GPtrArray *xlocked_array;
1068 : :
1069 : 16 : xlocked_array = g_ptr_array_new_with_free_func (g_free);
1070 : :
1071 [ + + ]: 32 : for (i = 0; xlocked[i]; i++)
1072 : 32 : g_ptr_array_add (xlocked_array, g_strdup (xlocked[i]));
1073 : :
1074 : 16 : g_task_return_pointer (task,
1075 : : xlocked_array,
1076 : : (GDestroyNotify) g_ptr_array_unref);
1077 : :
1078 : : } else {
1079 : 1 : closure->prompt = _secret_prompt_instance (self, prompt);
1080 : 1 : secret_service_prompt (self, closure->prompt, G_VARIANT_TYPE ("ao"),
1081 : : cancellable,
1082 : : on_xlock_prompted, g_steal_pointer (&task));
1083 : : }
1084 : :
1085 : 17 : g_strfreev (xlocked);
1086 : 17 : g_variant_unref (retval);
1087 : : }
1088 : :
1089 [ + + ]: 17 : g_clear_object (&task);
1090 : 17 : }
1091 : :
1092 : : void
1093 : 17 : _secret_service_xlock_paths_async (SecretService *self,
1094 : : const gchar *method,
1095 : : const gchar **paths,
1096 : : GCancellable *cancellable,
1097 : : GAsyncReadyCallback callback,
1098 : : gpointer user_data)
1099 : : {
1100 : 17 : GTask *task = NULL;
1101 : : XlockClosure *closure;
1102 : :
1103 : 17 : task = g_task_new (self, cancellable, callback, user_data);
1104 [ + - ]: 17 : g_task_set_source_tag (task, _secret_service_xlock_paths_async);
1105 : 17 : closure = g_new0 (XlockClosure, 1);
1106 : 17 : g_task_set_task_data (task, closure, xlock_closure_free);
1107 : :
1108 : 17 : g_dbus_proxy_call (G_DBUS_PROXY (self), method,
1109 : : g_variant_new ("(@ao)", g_variant_new_objv (paths, -1)),
1110 : : G_DBUS_CALL_FLAGS_NO_AUTO_START, -1,
1111 : : cancellable, on_xlock_called, g_steal_pointer (&task));
1112 : :
1113 [ - + ]: 17 : g_clear_object (&task);
1114 : 17 : }
1115 : :
1116 : : gint
1117 : 17 : _secret_service_xlock_paths_finish (SecretService *self,
1118 : : GAsyncResult *result,
1119 : : gchar ***xlocked,
1120 : : GError **error)
1121 : : {
1122 : 17 : GPtrArray *xlocked_array = NULL;
1123 : 17 : gchar **xlocked_ret = NULL;
1124 : : gint count;
1125 : :
1126 : 17 : xlocked_array = g_task_propagate_pointer (G_TASK (result), error);
1127 [ - + ]: 17 : if (xlocked_array == NULL) {
1128 : 0 : _secret_util_strip_remote_error (error);
1129 : 0 : return -1;
1130 : : }
1131 : :
1132 : 17 : count = xlocked_array->len;
1133 : : /* Add NULL-terminator after storing the count,
1134 : : * but before getting out the raw pointer */
1135 : 17 : g_ptr_array_add (xlocked_array, NULL);
1136 : 17 : xlocked_ret = (gchar **) g_ptr_array_free (xlocked_array, FALSE);
1137 : :
1138 [ + + ]: 17 : if (xlocked != NULL)
1139 : 12 : *xlocked = g_steal_pointer (&xlocked_ret);
1140 : :
1141 : 17 : g_strfreev (xlocked_ret);
1142 : :
1143 : 17 : return count;
1144 : : }
1145 : :
1146 : : /**
1147 : : * secret_service_lock_dbus_paths_sync: (skip)
1148 : : * @self: the secret service
1149 : : * @paths: (array zero-terminated=1): the D-Bus object paths of the items or collections to lock
1150 : : * @cancellable: (nullable): optional cancellation object
1151 : : * @locked: (out) (array zero-terminated=1) (transfer full) (optional) (nullable):
1152 : : * location to place array of D-Bus paths of items or collections
1153 : : * that were locked
1154 : : * @error: location to place an error on failure
1155 : : *
1156 : : * Lock items or collections in the secret service.
1157 : : *
1158 : : * The items or collections are represented by their D-Bus object paths. If you
1159 : : * already have [class@Item] and [class@Collection] proxy objects, use use
1160 : : * [method@Service.lock_sync] instead.
1161 : : *
1162 : : * The secret service may not be able to lock items individually, and may
1163 : : * lock an entire collection instead.
1164 : : *
1165 : : * This method may block indefinitely and should not be used in user
1166 : : * interface threads. The secret service may prompt the user.
1167 : : * [method@Service.prompt] will be used to handle any prompts that show up.
1168 : : *
1169 : : * Stability: Unstable
1170 : : *
1171 : : * Returns: the number of items or collections that were locked
1172 : : */
1173 : : gint
1174 : 2 : secret_service_lock_dbus_paths_sync (SecretService *self,
1175 : : const gchar **paths,
1176 : : GCancellable *cancellable,
1177 : : gchar ***locked,
1178 : : GError **error)
1179 : : {
1180 : : SecretSync *sync;
1181 : : gint count;
1182 : :
1183 [ - + + - : 2 : g_return_val_if_fail (SECRET_IS_SERVICE (self), -1);
+ - - + ]
1184 [ - + ]: 2 : g_return_val_if_fail (paths != NULL, -1);
1185 [ - + - - : 2 : g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), -1);
- - - - -
- ]
1186 [ + - - + ]: 2 : g_return_val_if_fail (error == NULL || *error == NULL, -1);
1187 : :
1188 : 2 : sync = _secret_sync_new ();
1189 : 2 : g_main_context_push_thread_default (sync->context);
1190 : :
1191 : 2 : secret_service_lock_dbus_paths (self, paths, cancellable,
1192 : : _secret_sync_on_result, sync);
1193 : :
1194 : 2 : g_main_loop_run (sync->loop);
1195 : :
1196 : 2 : count = secret_service_lock_dbus_paths_finish (self, sync->result,
1197 : : locked, error);
1198 : :
1199 : 2 : g_main_context_pop_thread_default (sync->context);
1200 : 2 : _secret_sync_free (sync);
1201 : :
1202 : 2 : return count;
1203 : : }
1204 : :
1205 : : /**
1206 : : * secret_service_lock_dbus_paths: (skip)
1207 : : * @self: the secret service
1208 : : * @paths: (array zero-terminated=1): the D-Bus paths for items or collections to lock
1209 : : * @cancellable: (nullable): optional cancellation object
1210 : : * @callback: called when the operation completes
1211 : : * @user_data: data to pass to the callback
1212 : : *
1213 : : * Lock items or collections in the secret service.
1214 : : *
1215 : : * The items or collections are represented by their D-Bus object paths. If you
1216 : : * already have [class@Item] and [class@Collection] proxy objects, use use
1217 : : * [method@Service.lock] instead.
1218 : : *
1219 : : * The secret service may not be able to lock items individually, and may
1220 : : * lock an entire collection instead.
1221 : : *
1222 : : * This method returns immediately and completes asynchronously. The secret
1223 : : * service may prompt the user. [method@Service.prompt] will be used to handle
1224 : : * any prompts that show up.
1225 : : *
1226 : : * Stability: Unstable
1227 : : */
1228 : : void
1229 : 2 : secret_service_lock_dbus_paths (SecretService *self,
1230 : : const gchar **paths,
1231 : : GCancellable *cancellable,
1232 : : GAsyncReadyCallback callback,
1233 : : gpointer user_data)
1234 : : {
1235 [ - + + - : 2 : g_return_if_fail (SECRET_IS_SERVICE (self));
+ - - + ]
1236 [ - + ]: 2 : g_return_if_fail (paths != NULL);
1237 [ - + - - : 2 : g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
- - - - -
- ]
1238 : :
1239 : 2 : _secret_service_xlock_paths_async (self, "Lock", paths, cancellable,
1240 : : callback, user_data);
1241 : : }
1242 : :
1243 : : /**
1244 : : * secret_service_lock_dbus_paths_finish: (skip)
1245 : : * @self: the secret service
1246 : : * @result: asynchronous result passed to the callback
1247 : : * @locked: (out) (array zero-terminated=1) (transfer full) (optional) (nullable):
1248 : : * location to place array of D-Bus paths of items or collections
1249 : : * that were locked
1250 : : * @error: location to place an error on failure
1251 : : *
1252 : : * Complete asynchronous operation to lock items or collections in the secret
1253 : : * service.
1254 : : *
1255 : : * The secret service may not be able to lock items individually, and may
1256 : : * lock an entire collection instead.
1257 : : *
1258 : : * Stability: Unstable
1259 : : *
1260 : : * Returns: the number of items or collections that were locked
1261 : : */
1262 : : gint
1263 : 2 : secret_service_lock_dbus_paths_finish (SecretService *self,
1264 : : GAsyncResult *result,
1265 : : gchar ***locked,
1266 : : GError **error)
1267 : : {
1268 [ - + + - : 2 : g_return_val_if_fail (SECRET_IS_SERVICE (self), -1);
+ - - + ]
1269 [ - + ]: 2 : g_return_val_if_fail (locked != NULL, -1);
1270 [ + - - + ]: 2 : g_return_val_if_fail (error == NULL || *error == NULL, -1);
1271 : :
1272 : 2 : return _secret_service_xlock_paths_finish (self, result, locked, error);
1273 : : }
1274 : :
1275 : : /**
1276 : : * secret_service_unlock_dbus_paths_sync: (skip)
1277 : : * @self: the secret service
1278 : : * @paths: (array zero-terminated=1): the D-Bus object paths of the items or
1279 : : * collections to unlock
1280 : : * @cancellable: (nullable): optional cancellation object
1281 : : * @unlocked: (out) (array zero-terminated=1) (transfer full) (optional) (nullable):
1282 : : * location to place array of D-Bus paths of items or collections
1283 : : * that were unlocked
1284 : : * @error: location to place an error on failure
1285 : : *
1286 : : * Unlock items or collections in the secret service.
1287 : : *
1288 : : * The items or collections are represented by their D-Bus object paths. If you
1289 : : * already have [class@Item] and [class@Collection] proxy objects, use use
1290 : : * [method@Service.unlock_sync] instead.
1291 : : *
1292 : : * The secret service may not be able to unlock items individually, and may
1293 : : * unlock an entire collection instead.
1294 : : *
1295 : : * This method may block indefinitely and should not be used in user
1296 : : * interface threads. The secret service may prompt the user.
1297 : : * [method@Service.prompt] will be used to handle any prompts that show up.
1298 : : *
1299 : : * Stability: Unstable
1300 : : *
1301 : : * Returns: the number of items or collections that were unlocked
1302 : : */
1303 : : gint
1304 : 5 : secret_service_unlock_dbus_paths_sync (SecretService *self,
1305 : : const gchar **paths,
1306 : : GCancellable *cancellable,
1307 : : gchar ***unlocked,
1308 : : GError **error)
1309 : : {
1310 : : SecretSync *sync;
1311 : : gint count;
1312 : :
1313 [ - + + - : 5 : g_return_val_if_fail (SECRET_IS_SERVICE (self), -1);
+ - - + ]
1314 [ - + ]: 5 : g_return_val_if_fail (paths != NULL, -1);
1315 [ - + - - : 5 : g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), -1);
- - - - -
- ]
1316 [ + + - + ]: 5 : g_return_val_if_fail (error == NULL || *error == NULL, -1);
1317 : :
1318 : 5 : sync = _secret_sync_new ();
1319 : 5 : g_main_context_push_thread_default (sync->context);
1320 : :
1321 : 5 : secret_service_unlock_dbus_paths (self, paths, cancellable,
1322 : : _secret_sync_on_result, sync);
1323 : :
1324 : 5 : g_main_loop_run (sync->loop);
1325 : :
1326 : 5 : count = secret_service_unlock_dbus_paths_finish (self, sync->result,
1327 : : unlocked, error);
1328 : :
1329 : 5 : g_main_context_pop_thread_default (sync->context);
1330 : 5 : _secret_sync_free (sync);
1331 : :
1332 : 5 : return count;
1333 : : }
1334 : :
1335 : : /**
1336 : : * secret_service_unlock_dbus_paths: (skip)
1337 : : * @self: the secret service
1338 : : * @paths: (array zero-terminated=1): the D-Bus paths for items or
1339 : : * collections to unlock
1340 : : * @cancellable: (nullable): optional cancellation object
1341 : : * @callback: called when the operation completes
1342 : : * @user_data: data to pass to the callback
1343 : : *
1344 : : * Unlock items or collections in the secret service.
1345 : : *
1346 : : * The items or collections are represented by their D-Bus object paths. If you
1347 : : * already have [class@Item] and [class@Collection] proxy objects, use use
1348 : : * [method@Service.unlock] instead.
1349 : : *
1350 : : * The secret service may not be able to unlock items individually, and may
1351 : : * unlock an entire collection instead.
1352 : : *
1353 : : * This method returns immediately and completes asynchronously. The secret
1354 : : * service may prompt the user. [method@Service.prompt] will be used to handle
1355 : : * any prompts that show up.
1356 : : *
1357 : : * Stability: Unstable
1358 : : */
1359 : : void
1360 : 10 : secret_service_unlock_dbus_paths (SecretService *self,
1361 : : const gchar **paths,
1362 : : GCancellable *cancellable,
1363 : : GAsyncReadyCallback callback,
1364 : : gpointer user_data)
1365 : : {
1366 [ - + + - : 10 : g_return_if_fail (SECRET_IS_SERVICE (self));
+ - - + ]
1367 [ - + ]: 10 : g_return_if_fail (paths != NULL);
1368 [ - + - - : 10 : g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
- - - - -
- ]
1369 : :
1370 : 10 : _secret_service_xlock_paths_async (self, "Unlock",
1371 : : paths, cancellable,
1372 : : callback, user_data);
1373 : : }
1374 : :
1375 : : /**
1376 : : * secret_service_unlock_dbus_paths_finish: (skip)
1377 : : * @self: the secret service
1378 : : * @result: asynchronous result passed to the callback
1379 : : * @unlocked: (out) (array zero-terminated=1) (transfer full) (optional) (nullable):
1380 : : * location to place array of D-Bus paths of items or collections
1381 : : * that were unlocked
1382 : : * @error: location to place an error on failure
1383 : : *
1384 : : * Complete asynchronous operation to unlock items or collections in the secret
1385 : : * service.
1386 : : *
1387 : : * The secret service may not be able to unlock items individually, and may
1388 : : * unlock an entire collection instead.
1389 : : *
1390 : : * Stability: Unstable
1391 : : *
1392 : : * Returns: the number of items or collections that were unlocked
1393 : : */
1394 : : gint
1395 : 10 : secret_service_unlock_dbus_paths_finish (SecretService *self,
1396 : : GAsyncResult *result,
1397 : : gchar ***unlocked,
1398 : : GError **error)
1399 : : {
1400 [ - + + - : 10 : g_return_val_if_fail (SECRET_IS_SERVICE (self), -1);
+ - - + ]
1401 [ + + - + ]: 10 : g_return_val_if_fail (error == NULL || *error == NULL, -1);
1402 : :
1403 : 10 : return _secret_service_xlock_paths_finish (self, result,
1404 : : unlocked, error);
1405 : : }
1406 : :
1407 : : typedef struct {
1408 : : SecretPrompt *prompt;
1409 : : } DeleteClosure;
1410 : :
1411 : : static void
1412 : 14 : delete_closure_free (gpointer data)
1413 : : {
1414 : 14 : DeleteClosure *closure = data;
1415 [ + + ]: 14 : g_clear_object (&closure->prompt);
1416 : 14 : g_free (closure);
1417 : 14 : }
1418 : :
1419 : : static void
1420 : 1 : on_delete_prompted (GObject *source,
1421 : : GAsyncResult *result,
1422 : : gpointer user_data)
1423 : : {
1424 : 1 : GTask *task = G_TASK (user_data);
1425 : 1 : GError *error = NULL;
1426 : : GVariant *retval;
1427 : :
1428 : 1 : retval = secret_service_prompt_finish (SECRET_SERVICE (source), result,
1429 : : &error);
1430 [ + - ]: 1 : if (retval != NULL)
1431 : 1 : g_variant_unref (retval);
1432 : :
1433 [ + - ]: 1 : if (error == NULL)
1434 : 1 : g_task_return_boolean (task, TRUE);
1435 : : else
1436 : 0 : g_task_return_error (task, g_steal_pointer (&error));
1437 : :
1438 : 1 : g_object_unref (task);
1439 : 1 : }
1440 : :
1441 : : static void
1442 : 14 : on_delete_complete (GObject *source,
1443 : : GAsyncResult *result,
1444 : : gpointer user_data)
1445 : : {
1446 : 14 : GTask *task = G_TASK (user_data);
1447 : 14 : DeleteClosure *closure = g_task_get_task_data (task);
1448 : 14 : SecretService *self = SECRET_SERVICE (g_task_get_source_object (task));
1449 : 14 : GCancellable *cancellable = g_task_get_cancellable (task);
1450 : : const gchar *prompt_path;
1451 : 14 : GError *error = NULL;
1452 : : GVariant *retval;
1453 : :
1454 : 14 : retval = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), result, &error);
1455 [ + - ]: 14 : if (error == NULL) {
1456 : 14 : g_variant_get (retval, "(&o)", &prompt_path);
1457 : :
1458 [ + + ]: 14 : if (_secret_util_empty_path (prompt_path)) {
1459 : 13 : g_task_return_boolean (task, TRUE);
1460 : :
1461 : : } else {
1462 : 1 : closure->prompt = _secret_prompt_instance (self, prompt_path);
1463 : :
1464 : 1 : secret_service_prompt (self, closure->prompt, NULL,
1465 : : cancellable,
1466 : : on_delete_prompted,
1467 : : g_steal_pointer (&task));
1468 : : }
1469 : :
1470 : 14 : g_variant_unref (retval);
1471 : :
1472 : : } else {
1473 : 0 : g_task_return_error (task, g_steal_pointer (&error));
1474 : : }
1475 : :
1476 [ + + ]: 14 : g_clear_object (&task);
1477 : 14 : }
1478 : :
1479 : : void
1480 : 14 : _secret_service_delete_path (SecretService *self,
1481 : : const gchar *object_path,
1482 : : gboolean is_an_item,
1483 : : GCancellable *cancellable,
1484 : : GAsyncReadyCallback callback,
1485 : : gpointer user_data)
1486 : : {
1487 : 14 : GTask *task = NULL;
1488 : : DeleteClosure *closure;
1489 : :
1490 [ - + + - : 14 : g_return_if_fail (SECRET_IS_SERVICE (self));
+ - - + ]
1491 [ - + ]: 14 : g_return_if_fail (object_path != NULL);
1492 [ - + - - : 14 : g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
- - - - -
- ]
1493 : :
1494 : 14 : task = g_task_new (self, cancellable, callback, user_data);
1495 [ + - ]: 14 : g_task_set_source_tag (task, _secret_service_delete_path);
1496 : 14 : closure = g_new0 (DeleteClosure, 1);
1497 : 14 : g_task_set_task_data (task, closure, delete_closure_free);
1498 : :
1499 [ + + ]: 28 : g_dbus_connection_call (g_dbus_proxy_get_connection (G_DBUS_PROXY (self)),
1500 : 14 : g_dbus_proxy_get_name (G_DBUS_PROXY (self)),
1501 : : object_path,
1502 : : is_an_item ? SECRET_ITEM_INTERFACE : SECRET_COLLECTION_INTERFACE,
1503 : : "Delete", g_variant_new ("()"), G_VARIANT_TYPE ("(o)"),
1504 : : G_DBUS_CALL_FLAGS_NO_AUTO_START, -1,
1505 : : cancellable,
1506 : : on_delete_complete, g_steal_pointer (&task));
1507 : :
1508 [ - + ]: 14 : g_clear_object (&task);
1509 : : }
1510 : :
1511 : : gboolean
1512 : 14 : _secret_service_delete_path_finish (SecretService *self,
1513 : : GAsyncResult *result,
1514 : : GError **error)
1515 : : {
1516 [ - + + - : 14 : g_return_val_if_fail (SECRET_IS_SERVICE (self), FALSE);
+ - - + ]
1517 [ + - - + ]: 14 : g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1518 [ - + ]: 14 : g_return_val_if_fail (g_task_is_valid (result, self), FALSE);
1519 [ - + ]: 14 : g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) ==
1520 : : _secret_service_delete_path, FALSE);
1521 : :
1522 [ - + ]: 14 : if (!g_task_propagate_boolean (G_TASK (result), error)) {
1523 : 0 : _secret_util_strip_remote_error (error);
1524 : 0 : return FALSE;
1525 : : }
1526 : :
1527 : 14 : return TRUE;
1528 : : }
1529 : :
1530 : : /**
1531 : : * secret_service_delete_item_dbus_path: (skip)
1532 : : * @self: the secret service
1533 : : * @item_path: the D-Bus path of item to delete
1534 : : * @cancellable: (nullable): optional cancellation object
1535 : : * @callback: called when the operation completes
1536 : : * @user_data: data to be passed to the callback
1537 : : *
1538 : : * Delete a secret item from the secret service.
1539 : : *
1540 : : * The item is represented by its D-Bus object path. If you already have a
1541 : : * [class@Item] proxy objects, use use [method@Item.delete] instead.
1542 : : *
1543 : : * This method will return immediately and complete asynchronously.
1544 : : *
1545 : : * Stability: Unstable
1546 : : */
1547 : : void
1548 : 2 : secret_service_delete_item_dbus_path (SecretService *self,
1549 : : const gchar *item_path,
1550 : : GCancellable *cancellable,
1551 : : GAsyncReadyCallback callback,
1552 : : gpointer user_data)
1553 : : {
1554 [ - + + - : 2 : g_return_if_fail (SECRET_IS_SERVICE (self));
+ - - + ]
1555 [ - + ]: 2 : g_return_if_fail (item_path != NULL);
1556 [ - + - - : 2 : g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
- - - - -
- ]
1557 : :
1558 : 2 : _secret_service_delete_path (self, item_path, TRUE, cancellable, callback, user_data);
1559 : : }
1560 : :
1561 : : /**
1562 : : * secret_service_delete_item_dbus_path_finish: (skip)
1563 : : * @self: the secret service
1564 : : * @result: the asynchronous result passed to the callback
1565 : : * @error: location to place an error on failure
1566 : : *
1567 : : * Complete an asynchronous operation to delete a secret item from the secret
1568 : : * service.
1569 : : *
1570 : : * Stability: Unstable
1571 : : *
1572 : : * Returns: whether the deletion was successful or not
1573 : : */
1574 : : gboolean
1575 : 2 : secret_service_delete_item_dbus_path_finish (SecretService *self,
1576 : : GAsyncResult *result,
1577 : : GError **error)
1578 : : {
1579 : 2 : return _secret_service_delete_path_finish (self, result, error);
1580 : : }
1581 : :
1582 : : /**
1583 : : * secret_service_delete_item_dbus_path_sync: (skip)
1584 : : * @self: the secret service
1585 : : * @item_path: the D-Bus path of item to delete
1586 : : * @cancellable: (nullable): optional cancellation object
1587 : : * @error: location to place an error on failure
1588 : : *
1589 : : * Delete a secret item from the secret service.
1590 : : *
1591 : : * The item is represented by its D-Bus object path. If you already have a
1592 : : * [class@Item] proxy objects, use use [method@Item.delete_sync] instead.
1593 : : *
1594 : : * This method may block indefinitely and should not be used in user interface
1595 : : * threads.
1596 : : *
1597 : : * Stability: Unstable
1598 : : *
1599 : : * Returns: whether the deletion was successful or not
1600 : : */
1601 : : gboolean
1602 : 2 : secret_service_delete_item_dbus_path_sync (SecretService *self,
1603 : : const gchar *item_path,
1604 : : GCancellable *cancellable,
1605 : : GError **error)
1606 : : {
1607 : : SecretSync *sync;
1608 : : gboolean result;
1609 : :
1610 [ - + + - : 2 : g_return_val_if_fail (SECRET_IS_SERVICE (self), FALSE);
+ - - + ]
1611 [ - + ]: 2 : g_return_val_if_fail (item_path != NULL, FALSE);
1612 [ - + - - : 2 : g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
- - - - -
- ]
1613 [ + - - + ]: 2 : g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1614 : :
1615 : 2 : sync = _secret_sync_new ();
1616 : 2 : g_main_context_push_thread_default (sync->context);
1617 : :
1618 : 2 : secret_service_delete_item_dbus_path (self, item_path, cancellable,
1619 : : _secret_sync_on_result, sync);
1620 : :
1621 : 2 : g_main_loop_run (sync->loop);
1622 : :
1623 : 2 : result = secret_service_delete_item_dbus_path_finish (self, sync->result, error);
1624 : :
1625 : 2 : g_main_context_pop_thread_default (sync->context);
1626 : 2 : _secret_sync_free (sync);
1627 : :
1628 : 2 : return result;
1629 : : }
1630 : :
1631 : : typedef struct {
1632 : : SecretPrompt *prompt;
1633 : : } CollectionClosure;
1634 : :
1635 : : static void
1636 : 5 : collection_closure_free (gpointer data)
1637 : : {
1638 : 5 : CollectionClosure *closure = data;
1639 [ + - ]: 5 : g_clear_object (&closure->prompt);
1640 : 5 : g_free (closure);
1641 : 5 : }
1642 : :
1643 : : static void
1644 : 5 : on_create_collection_prompt (GObject *source,
1645 : : GAsyncResult *result,
1646 : : gpointer user_data)
1647 : : {
1648 : 5 : GTask *task = G_TASK (user_data);
1649 : 5 : GError *error = NULL;
1650 : : GVariant *value;
1651 : : gchar *collection_path;
1652 : :
1653 : 5 : value = secret_service_prompt_finish (SECRET_SERVICE (source), result, &error);
1654 [ - + ]: 5 : if (error != NULL) {
1655 : 0 : g_task_return_error (task, g_steal_pointer (&error));
1656 : : } else {
1657 : 5 : collection_path = g_variant_dup_string (value, NULL);
1658 : 5 : g_task_return_pointer (task, collection_path, g_free);
1659 : 5 : g_variant_unref (value);
1660 : : }
1661 : :
1662 [ + - ]: 5 : g_clear_object (&task);
1663 : 5 : }
1664 : :
1665 : : static void
1666 : 5 : on_create_collection_called (GObject *source,
1667 : : GAsyncResult *result,
1668 : : gpointer user_data)
1669 : : {
1670 : 5 : GTask *task = G_TASK (user_data);
1671 : 5 : CollectionClosure *closure = g_task_get_task_data (task);
1672 : 5 : GCancellable *cancellable = g_task_get_cancellable (task);
1673 : 5 : SecretService *self = SECRET_SERVICE (g_task_get_source_object (task));
1674 : 5 : const gchar *prompt_path = NULL;
1675 : 5 : const gchar *collection_path = NULL;
1676 : 5 : GError *error = NULL;
1677 : : GVariant *retval;
1678 : :
1679 : 5 : retval = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), result, &error);
1680 [ + - ]: 5 : if (error == NULL) {
1681 : 5 : g_variant_get (retval, "(&o&o)", &collection_path, &prompt_path);
1682 [ + - ]: 5 : if (!_secret_util_empty_path (prompt_path)) {
1683 : 5 : closure->prompt = _secret_prompt_instance (self, prompt_path);
1684 : 5 : secret_service_prompt (self, closure->prompt, G_VARIANT_TYPE ("o"),
1685 : : cancellable, on_create_collection_prompt,
1686 : : g_steal_pointer (&task));
1687 : :
1688 : : } else {
1689 : 0 : g_task_return_pointer (task, g_strdup (collection_path), g_free);
1690 : : }
1691 : :
1692 : 5 : g_variant_unref (retval);
1693 : :
1694 : : } else {
1695 : 0 : g_task_return_error (task, g_steal_pointer (&error));
1696 : : }
1697 : :
1698 [ - + ]: 5 : g_clear_object (&task);
1699 : 5 : }
1700 : :
1701 : : /**
1702 : : * secret_service_create_collection_dbus_path: (skip)
1703 : : * @self: a secret service object
1704 : : * @properties: (element-type utf8 GLib.Variant): hash table of properties for
1705 : : * the new collection
1706 : : * @alias: (nullable): an alias to check for before creating the new
1707 : : * collection, or to assign to the new collection
1708 : : * @flags: not currently used
1709 : : * @cancellable: (nullable): optional cancellation object
1710 : : * @callback: called when the operation completes
1711 : : * @user_data: data to be passed to the callback
1712 : : *
1713 : : * Create a new collection in the secret service, and return its path.
1714 : : *
1715 : : * Using this method requires that you setup a correct hash table of D-Bus
1716 : : * properties for the new collection. You may prefer to use
1717 : : * [func@Collection.create] which does handles this for you.
1718 : : *
1719 : : * An @alias is a well-known tag for a collection, such as 'default' (ie: the
1720 : : * default collection to store items in). This allows other applications to
1721 : : * easily identify and share a collection. If a collection with the @alias
1722 : : * already exists, then instead of creating a new collection, the existing
1723 : : * collection will be returned. If no collection with this alias exists, then a
1724 : : * new collection will be created and this alias will be assigned to it.
1725 : : *
1726 : : * @properties is a set of properties for the new collection. The keys in the
1727 : : * hash table should be interface.property strings like
1728 : : * `org.freedesktop.Secret.Collection.Label`. The values
1729 : : * in the hash table should be [struct@GLib.Variant] values of the properties.
1730 : : *
1731 : : * If you wish to have a
1732 : : *
1733 : : * This method will return immediately and complete asynchronously. The secret
1734 : : * service may prompt the user. [method@Service.prompt] will be used to handle
1735 : : * any prompts that are required.
1736 : : *
1737 : : * Stability: Unstable
1738 : : */
1739 : : void
1740 : 5 : secret_service_create_collection_dbus_path (SecretService *self,
1741 : : GHashTable *properties,
1742 : : const gchar *alias,
1743 : : SecretCollectionCreateFlags flags,
1744 : : GCancellable *cancellable,
1745 : : GAsyncReadyCallback callback,
1746 : : gpointer user_data)
1747 : : {
1748 : 5 : GTask *task = NULL;
1749 : : CollectionClosure *closure;
1750 : : GVariant *params;
1751 : : GVariant *props;
1752 : : GDBusProxy *proxy;
1753 : :
1754 [ - + + - : 5 : g_return_if_fail (SECRET_IS_SERVICE (self));
+ - - + ]
1755 [ - + ]: 5 : g_return_if_fail (properties != NULL);
1756 [ - + - - : 5 : g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
- - - - -
- ]
1757 : :
1758 [ + + ]: 5 : if (alias == NULL)
1759 : 4 : alias = "";
1760 : :
1761 : 5 : task = g_task_new (self, cancellable, callback, user_data);
1762 [ + - ]: 5 : g_task_set_source_tag (task, secret_service_create_collection_dbus_path);
1763 : 5 : closure = g_new0 (CollectionClosure, 1);
1764 : 5 : g_task_set_task_data (task, closure, collection_closure_free);
1765 : :
1766 : 5 : props = _secret_util_variant_for_properties (properties);
1767 : 5 : params = g_variant_new ("(@a{sv}s)", props, alias);
1768 : 5 : proxy = G_DBUS_PROXY (self);
1769 : :
1770 : 5 : g_dbus_connection_call (g_dbus_proxy_get_connection (proxy),
1771 : : g_dbus_proxy_get_name (proxy),
1772 : : g_dbus_proxy_get_object_path (proxy),
1773 : : SECRET_SERVICE_INTERFACE,
1774 : : "CreateCollection", params, G_VARIANT_TYPE ("(oo)"),
1775 : : G_DBUS_CALL_FLAGS_NONE, -1,
1776 : : cancellable,
1777 : : on_create_collection_called,
1778 : : g_steal_pointer (&task));
1779 : :
1780 [ - + ]: 5 : g_clear_object (&task);
1781 : : }
1782 : :
1783 : : /**
1784 : : * secret_service_create_collection_dbus_path_finish: (skip)
1785 : : * @self: a secret service object
1786 : : * @result: the asynchronous result passed to the callback
1787 : : * @error: location to place an error on failure
1788 : : *
1789 : : * Finish asynchronous operation to create a new collection in the secret
1790 : : * service.
1791 : : *
1792 : : * Stability: Unstable
1793 : : *
1794 : : * Returns: (transfer full): a new string containing the D-Bus object path
1795 : : * of the collection
1796 : : */
1797 : : gchar *
1798 : 5 : secret_service_create_collection_dbus_path_finish (SecretService *self,
1799 : : GAsyncResult *result,
1800 : : GError **error)
1801 : : {
1802 : : gchar *path;
1803 : :
1804 [ - + ]: 5 : g_return_val_if_fail (g_task_is_valid (result, self), NULL);
1805 [ - + ]: 5 : g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) ==
1806 : : secret_service_create_collection_dbus_path, NULL);
1807 [ + - - + ]: 5 : g_return_val_if_fail (error == NULL || *error == NULL, NULL);
1808 : :
1809 : 5 : path = g_task_propagate_pointer (G_TASK (result), error);
1810 [ - + ]: 5 : if (path == NULL) {
1811 : 0 : _secret_util_strip_remote_error (error);
1812 : 0 : return NULL;
1813 : : }
1814 : :
1815 : 5 : return g_steal_pointer (&path);
1816 : : }
1817 : :
1818 : : /**
1819 : : * secret_service_create_collection_dbus_path_sync: (skip)
1820 : : * @self: a secret service object
1821 : : * @properties: (element-type utf8 GLib.Variant): hash table of D-Bus properties
1822 : : * for the new collection
1823 : : * @alias: (nullable): an alias to check for before creating the new
1824 : : * collection, or to assign to the new collection
1825 : : * @flags: not currently used
1826 : : * @cancellable: (nullable): optional cancellation object
1827 : : * @error: location to place an error on failure
1828 : : *
1829 : : * Create a new collection in the secret service and return its path.
1830 : : *
1831 : : * Using this method requires that you setup a correct hash table of D-Bus
1832 : : * properties for the new collection. You may prefer to use
1833 : : * [func@Collection.create] which does handles this for you.
1834 : : *
1835 : : * An @alias is a well-known tag for a collection, such as 'default' (ie: the
1836 : : * default collection to store items in). This allows other applications to
1837 : : * easily identify and share a collection. If a collection with the @alias
1838 : : * already exists, then instead of creating a new collection, the existing
1839 : : * collection will be returned. If no collection with this alias exists, then
1840 : : * a new collection will be created and this alias will be assigned to it.
1841 : : *
1842 : : * @properties is a set of properties for the new collection. The keys in the
1843 : : * hash table should be interface.property strings like
1844 : : * `org.freedesktop.Secret.Collection.Label`. The values
1845 : : * in the hash table should be [struct@GLib.Variant] values of the properties.
1846 : : *
1847 : : * This method may block indefinitely and should not be used in user interface
1848 : : * threads. The secret service may prompt the user. [method@Service.prompt]
1849 : : * will be used to handle any prompts that are required.
1850 : : *
1851 : : * Stability: Unstable
1852 : : *
1853 : : * Returns: (transfer full): a new string containing the D-Bus object path
1854 : : * of the collection
1855 : : */
1856 : : gchar *
1857 : 2 : secret_service_create_collection_dbus_path_sync (SecretService *self,
1858 : : GHashTable *properties,
1859 : : const gchar *alias,
1860 : : SecretCollectionCreateFlags flags,
1861 : : GCancellable *cancellable,
1862 : : GError **error)
1863 : : {
1864 : : SecretSync *sync;
1865 : : gchar *path;
1866 : :
1867 [ - + + - : 2 : g_return_val_if_fail (SECRET_IS_SERVICE (self), NULL);
+ - - + ]
1868 [ - + ]: 2 : g_return_val_if_fail (properties != NULL, NULL);
1869 [ - + - - : 2 : g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
- - - - -
- ]
1870 [ + - - + ]: 2 : g_return_val_if_fail (error == NULL || *error == NULL, NULL);
1871 : :
1872 : 2 : sync = _secret_sync_new ();
1873 : 2 : g_main_context_push_thread_default (sync->context);
1874 : :
1875 : 2 : secret_service_create_collection_dbus_path (self, properties, alias, flags, cancellable,
1876 : : _secret_sync_on_result, sync);
1877 : :
1878 : 2 : g_main_loop_run (sync->loop);
1879 : :
1880 : 2 : path = secret_service_create_collection_dbus_path_finish (self, sync->result, error);
1881 : :
1882 : 2 : g_main_context_pop_thread_default (sync->context);
1883 : 2 : _secret_sync_free (sync);
1884 : :
1885 : 2 : return path;
1886 : : }
1887 : :
1888 : : typedef struct {
1889 : : GVariant *properties;
1890 : : SecretValue *value;
1891 : : gboolean replace;
1892 : : gchar *collection_path;
1893 : : SecretPrompt *prompt;
1894 : : } ItemClosure;
1895 : :
1896 : : static void
1897 : 18 : item_closure_free (gpointer data)
1898 : : {
1899 : 18 : ItemClosure *closure = data;
1900 : 18 : g_variant_unref (closure->properties);
1901 : 18 : secret_value_unref (closure->value);
1902 : 18 : g_free (closure->collection_path);
1903 [ - + ]: 18 : g_clear_object (&closure->prompt);
1904 : 18 : g_free (closure);
1905 : 18 : }
1906 : :
1907 : : static void
1908 : 0 : on_create_item_prompt (GObject *source,
1909 : : GAsyncResult *result,
1910 : : gpointer user_data)
1911 : : {
1912 : 0 : GTask *task = G_TASK (user_data);
1913 : 0 : GError *error = NULL;
1914 : : GVariant *value;
1915 : : gchar *item_path;
1916 : :
1917 : 0 : value = secret_service_prompt_finish (SECRET_SERVICE (source), result, &error);
1918 [ # # ]: 0 : if (error != NULL) {
1919 : 0 : g_task_return_error (task, g_steal_pointer (&error));
1920 : : } else {
1921 : 0 : item_path = g_variant_dup_string (value, NULL);
1922 : 0 : g_variant_unref (value);
1923 : 0 : g_task_return_pointer (task, item_path, g_free);
1924 : : }
1925 : :
1926 [ # # ]: 0 : g_clear_object (&task);
1927 : 0 : }
1928 : :
1929 : : static void
1930 : 18 : on_create_item_called (GObject *source,
1931 : : GAsyncResult *result,
1932 : : gpointer user_data)
1933 : : {
1934 : 18 : GTask *task = G_TASK (user_data);
1935 : 18 : ItemClosure *closure = g_task_get_task_data (task);
1936 : 18 : SecretService *self = SECRET_SERVICE (g_task_get_source_object (task));
1937 : 18 : GCancellable *cancellable = g_task_get_cancellable (task);
1938 : 18 : const gchar *prompt_path = NULL;
1939 : 18 : const gchar *item_path = NULL;
1940 : 18 : GError *error = NULL;
1941 : : GVariant *retval;
1942 : :
1943 : 18 : retval = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), result, &error);
1944 [ + + ]: 18 : if (error == NULL) {
1945 : 16 : g_variant_get (retval, "(&o&o)", &item_path, &prompt_path);
1946 [ - + ]: 16 : if (!_secret_util_empty_path (prompt_path)) {
1947 : 0 : closure->prompt = _secret_prompt_instance (self, prompt_path);
1948 : 0 : secret_service_prompt (self, closure->prompt, G_VARIANT_TYPE ("o"),
1949 : : cancellable, on_create_item_prompt,
1950 : : g_steal_pointer (&task));
1951 : :
1952 : : } else {
1953 : 32 : g_task_return_pointer (task, g_strdup (item_path), g_free);
1954 : : }
1955 : :
1956 : 16 : g_variant_unref (retval);
1957 : :
1958 : : } else {
1959 : 2 : g_task_return_error (task, g_steal_pointer (&error));
1960 : : }
1961 : :
1962 [ + - ]: 18 : g_clear_object (&task);
1963 : 18 : }
1964 : :
1965 : : static void
1966 : 18 : on_create_item_session (GObject *source,
1967 : : GAsyncResult *result,
1968 : : gpointer user_data)
1969 : : {
1970 : 18 : GTask *task = G_TASK (user_data);
1971 : 18 : ItemClosure *closure = g_task_get_task_data (task);
1972 : 18 : SecretService *self = SECRET_SERVICE (source);
1973 : 18 : GCancellable *cancellable = g_task_get_cancellable (task);
1974 : : SecretSession *session;
1975 : : GVariant *params;
1976 : 18 : GError *error = NULL;
1977 : : GDBusProxy *proxy;
1978 : :
1979 : 18 : secret_service_ensure_session_finish (self, result, &error);
1980 [ + - ]: 18 : if (error == NULL) {
1981 : 18 : session = _secret_service_get_session (self);
1982 : 18 : params = g_variant_new ("(@a{sv}@(oayays)b)",
1983 : : closure->properties,
1984 : : _secret_session_encode_secret (session, closure->value),
1985 : : closure->replace);
1986 : :
1987 : 18 : proxy = G_DBUS_PROXY (self);
1988 : 36 : g_dbus_connection_call (g_dbus_proxy_get_connection (proxy),
1989 : : g_dbus_proxy_get_name (proxy),
1990 : 18 : closure->collection_path,
1991 : : SECRET_COLLECTION_INTERFACE,
1992 : : "CreateItem", params, G_VARIANT_TYPE ("(oo)"),
1993 : : G_DBUS_CALL_FLAGS_NONE, -1,
1994 : : cancellable,
1995 : : on_create_item_called,
1996 : : g_steal_pointer (&task));
1997 : : } else {
1998 : 0 : g_task_return_error (task, g_steal_pointer (&error));
1999 : : }
2000 : :
2001 [ - + ]: 18 : g_clear_object (&task);
2002 : 18 : }
2003 : :
2004 : : /**
2005 : : * secret_service_create_item_dbus_path: (skip)
2006 : : * @self: a secret service object
2007 : : * @collection_path: the D-Bus object path of the collection in which to create item
2008 : : * @properties: (element-type utf8 GLib.Variant): hash table of D-Bus properties
2009 : : * for the new collection
2010 : : * @value: the secret value to store in the item
2011 : : * @flags: flags for the creation of the new item
2012 : : * @cancellable: (nullable): optional cancellation object
2013 : : * @callback: called when the operation completes
2014 : : * @user_data: data to be passed to the callback
2015 : : *
2016 : : * Create a new item in a secret service collection and return its D-Bus
2017 : : * object path.
2018 : : *
2019 : : * It is often easier to use [func@password_store] or [func@Item.create]
2020 : : * rather than using this function. Using this method requires that you setup
2021 : : * a correct hash table of D-Bus @properties for the new collection.
2022 : : *
2023 : : * If the @flags contains %SECRET_ITEM_CREATE_REPLACE, then the secret
2024 : : * service will search for an item matching the @attributes, and update that item
2025 : : * instead of creating a new one.
2026 : : *
2027 : : * @properties is a set of properties for the new collection. The keys in the
2028 : : * hash table should be interface.property strings like
2029 : : * `org.freedesktop.Secret.Item.Label`. The values
2030 : : * in the hash table should be [struct@GLib.Variant] values of the properties.
2031 : : *
2032 : : * This method will return immediately and complete asynchronously. The secret
2033 : : * service may prompt the user. [method@Service.prompt] will be used to handle
2034 : : * any prompts that are required.
2035 : : *
2036 : : * Stability: Unstable
2037 : : */
2038 : : void
2039 : 18 : secret_service_create_item_dbus_path (SecretService *self,
2040 : : const gchar *collection_path,
2041 : : GHashTable *properties,
2042 : : SecretValue *value,
2043 : : SecretItemCreateFlags flags,
2044 : : GCancellable *cancellable,
2045 : : GAsyncReadyCallback callback,
2046 : : gpointer user_data)
2047 : : {
2048 : 18 : GTask *task = NULL;
2049 : : ItemClosure *closure;
2050 : :
2051 [ - + + - : 18 : g_return_if_fail (SECRET_IS_SERVICE (self));
+ - - + ]
2052 [ + - + - ]: 18 : g_return_if_fail (collection_path != NULL && g_variant_is_object_path (collection_path));
2053 [ - + ]: 18 : g_return_if_fail (properties != NULL);
2054 [ - + ]: 18 : g_return_if_fail (value != NULL);
2055 [ - + - - : 18 : g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
- - - - -
- ]
2056 : :
2057 : 18 : task = g_task_new (self, cancellable, callback, user_data);
2058 [ + - ]: 18 : g_task_set_source_tag (task, secret_service_create_item_dbus_path);
2059 : 18 : closure = g_new0 (ItemClosure, 1);
2060 : 18 : closure->properties = _secret_util_variant_for_properties (properties);
2061 : 18 : g_variant_ref_sink (closure->properties);
2062 : 18 : closure->replace = flags & SECRET_ITEM_CREATE_REPLACE;
2063 : 18 : closure->value = secret_value_ref (value);
2064 : 18 : closure->collection_path = g_strdup (collection_path);
2065 : 18 : g_task_set_task_data (task, closure, item_closure_free);
2066 : :
2067 : 18 : secret_service_ensure_session (self, cancellable,
2068 : : on_create_item_session,
2069 : : g_steal_pointer (&task));
2070 : :
2071 [ - + ]: 18 : g_clear_object (&task);
2072 : : }
2073 : :
2074 : : /**
2075 : : * secret_service_create_item_dbus_path_finish: (skip)
2076 : : * @self: a secret service object
2077 : : * @result: the asynchronous result passed to the callback
2078 : : * @error: location to place an error on failure
2079 : : *
2080 : : * Finish asynchronous operation to create a new item in the secret
2081 : : * service.
2082 : : *
2083 : : * Stability: Unstable
2084 : : *
2085 : : * Returns: (transfer full): a new string containing the D-Bus object path
2086 : : * of the item
2087 : : */
2088 : : gchar *
2089 : 4 : secret_service_create_item_dbus_path_finish (SecretService *self,
2090 : : GAsyncResult *result,
2091 : : GError **error)
2092 : : {
2093 : : gchar *path;
2094 : :
2095 [ - + ]: 4 : g_return_val_if_fail (g_task_is_valid (result, self), NULL);
2096 [ - + ]: 4 : g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) ==
2097 : : secret_service_create_item_dbus_path, NULL);
2098 [ + - - + ]: 4 : g_return_val_if_fail (error == NULL || *error == NULL, NULL);
2099 : :
2100 : 4 : path = g_task_propagate_pointer (G_TASK (result), error);
2101 [ - + ]: 4 : if (path == NULL) {
2102 : 0 : _secret_util_strip_remote_error (error);
2103 : 0 : return NULL;
2104 : : }
2105 : :
2106 : 4 : return g_steal_pointer (&path);
2107 : : }
2108 : :
2109 : : /* Same as the function above, but doesn't strip the remote error and throws
2110 : : * away the result */
2111 : : void
2112 : 14 : _secret_service_create_item_dbus_path_finish_raw (GAsyncResult *result,
2113 : : GError **error)
2114 : : {
2115 : : gchar *path;
2116 : :
2117 [ - + ]: 14 : g_return_if_fail (g_task_get_source_tag (G_TASK (result)) ==
2118 : : secret_service_create_item_dbus_path);
2119 [ + - - + ]: 14 : g_return_if_fail (error == NULL || *error == NULL);
2120 : :
2121 : 14 : path = g_task_propagate_pointer (G_TASK (result), error);
2122 : :
2123 : 14 : g_free (path);
2124 : : }
2125 : :
2126 : : /**
2127 : : * secret_service_create_item_dbus_path_sync:
2128 : : * @self: a secret service object
2129 : : * @collection_path: the D-Bus path of the collection in which to create item
2130 : : * @properties: (element-type utf8 GLib.Variant): hash table of D-Bus properties
2131 : : * for the new collection
2132 : : * @value: the secret value to store in the item
2133 : : * @flags: flags for the creation of the new item
2134 : : * @cancellable: (nullable): optional cancellation object
2135 : : * @error: location to place an error on failure
2136 : : *
2137 : : * Create a new item in a secret service collection and return its D-Bus
2138 : : * object path.
2139 : : *
2140 : : * It is often easier to use [func@password_store_sync] or [func@Item.create_sync]
2141 : : * rather than using this function. Using this method requires that you setup
2142 : : * a correct hash table of D-Bus @properties for the new collection.
2143 : : *
2144 : : * If the @flags contains %SECRET_ITEM_CREATE_REPLACE, then the secret
2145 : : * service will search for an item matching the @attributes, and update that item
2146 : : * instead of creating a new one.
2147 : : *
2148 : : * @properties is a set of properties for the new collection. The keys in the
2149 : : * hash table should be interface.property strings like
2150 : : * `org.freedesktop.Secret.Item.Label`. The values
2151 : : * in the hash table should be [struct@GLib.Variant] values of the properties.
2152 : : *
2153 : : * This method may block indefinitely and should not be used in user interface
2154 : : * threads. The secret service may prompt the user. [method@Service.prompt]
2155 : : * will be used to handle any prompts that are required.
2156 : : *
2157 : : * Stability: Unstable
2158 : : *
2159 : : * Returns: (transfer full): a new string containing the D-Bus object path
2160 : : * of the item
2161 : : */
2162 : : gchar *
2163 : 2 : secret_service_create_item_dbus_path_sync (SecretService *self,
2164 : : const gchar *collection_path,
2165 : : GHashTable *properties,
2166 : : SecretValue *value,
2167 : : SecretItemCreateFlags flags,
2168 : : GCancellable *cancellable,
2169 : : GError **error)
2170 : : {
2171 : : SecretSync *sync;
2172 : : gchar *path;
2173 : :
2174 [ - + + - : 2 : g_return_val_if_fail (SECRET_IS_SERVICE (self), NULL);
+ - - + ]
2175 [ + - + - ]: 2 : g_return_val_if_fail (collection_path != NULL && g_variant_is_object_path (collection_path), NULL);
2176 [ - + ]: 2 : g_return_val_if_fail (properties != NULL, NULL);
2177 [ - + - - : 2 : g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
- - - - -
- ]
2178 [ + - - + ]: 2 : g_return_val_if_fail (error == NULL || *error == NULL, NULL);
2179 : :
2180 : 2 : sync = _secret_sync_new ();
2181 : 2 : g_main_context_push_thread_default (sync->context);
2182 : :
2183 : 2 : secret_service_create_item_dbus_path (self, collection_path, properties, value, flags,
2184 : : cancellable, _secret_sync_on_result, sync);
2185 : :
2186 : 2 : g_main_loop_run (sync->loop);
2187 : :
2188 : 2 : path = secret_service_create_item_dbus_path_finish (self, sync->result, error);
2189 : :
2190 : 2 : g_main_context_pop_thread_default (sync->context);
2191 : 2 : _secret_sync_free (sync);
2192 : :
2193 : 2 : return path;
2194 : : }
2195 : :
2196 : : /**
2197 : : * secret_service_read_alias_dbus_path: (skip)
2198 : : * @self: a secret service object
2199 : : * @alias: the alias to lookup
2200 : : * @cancellable: (nullable): optional cancellation object
2201 : : * @callback: called when the operation completes
2202 : : * @user_data: data to pass to the callback
2203 : : *
2204 : : * Lookup which collection is assigned to this alias.
2205 : : *
2206 : : * Aliases help determine well known collections, such as 'default'. This method
2207 : : * looks up the dbus object path of the well known collection.
2208 : : *
2209 : : * This method will return immediately and complete asynchronously.
2210 : : *
2211 : : * Stability: Unstable
2212 : : */
2213 : : void
2214 : 12 : secret_service_read_alias_dbus_path (SecretService *self,
2215 : : const gchar *alias,
2216 : : GCancellable *cancellable,
2217 : : GAsyncReadyCallback callback,
2218 : : gpointer user_data)
2219 : : {
2220 [ - + + - : 12 : g_return_if_fail (SECRET_IS_SERVICE (self));
+ - - + ]
2221 [ - + ]: 12 : g_return_if_fail (alias != NULL);
2222 [ - + - - : 12 : g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
- - - - -
- ]
2223 : :
2224 : 12 : g_dbus_proxy_call (G_DBUS_PROXY (self), "ReadAlias",
2225 : : g_variant_new ("(s)", alias),
2226 : : G_DBUS_CALL_FLAGS_NONE, -1,
2227 : : cancellable, callback, user_data);
2228 : : }
2229 : :
2230 : : /**
2231 : : * secret_service_read_alias_dbus_path_finish: (skip)
2232 : : * @self: a secret service object
2233 : : * @result: asynchronous result passed to callback
2234 : : * @error: location to place error on failure
2235 : : *
2236 : : * Finish an asynchronous operation to lookup which collection is assigned
2237 : : * to an alias.
2238 : : *
2239 : : * This method returns the DBus object path of the collection
2240 : : *
2241 : : * Stability: Unstable
2242 : : *
2243 : : * Returns: (transfer full) (nullable): the collection dbus object path,
2244 : : * or %NULL if none assigned to the alias
2245 : : */
2246 : : gchar *
2247 : 12 : secret_service_read_alias_dbus_path_finish (SecretService *self,
2248 : : GAsyncResult *result,
2249 : : GError **error)
2250 : : {
2251 : : gchar *collection_path;
2252 : : GVariant *retval;
2253 : :
2254 : 12 : retval = g_dbus_proxy_call_finish (G_DBUS_PROXY (self), result, error);
2255 : :
2256 : 12 : _secret_util_strip_remote_error (error);
2257 [ - + ]: 12 : if (retval == NULL)
2258 : 0 : return NULL;
2259 : :
2260 : 12 : g_variant_get (retval, "(o)", &collection_path);
2261 : 12 : g_variant_unref (retval);
2262 : :
2263 [ + + ]: 12 : if (g_str_equal (collection_path, "/")) {
2264 : 6 : g_free (collection_path);
2265 : 6 : collection_path = NULL;
2266 : : }
2267 : :
2268 : 12 : return collection_path;
2269 : : }
2270 : :
2271 : : /**
2272 : : * secret_service_read_alias_dbus_path_sync: (skip)
2273 : : * @self: a secret service object
2274 : : * @alias: the alias to lookup
2275 : : * @cancellable: (nullable): optional cancellation object
2276 : : * @error: location to place error on failure
2277 : : *
2278 : : * Lookup which collection is assigned to this alias.
2279 : : *
2280 : : * Aliases help determine well known collections, such as 'default'. This method
2281 : : * returns the dbus object path of the collection.
2282 : : *
2283 : : * This method may block and should not be used in user interface threads.
2284 : : *
2285 : : * Stability: Unstable
2286 : : *
2287 : : * Returns: (transfer full) (nullable): the collection dbus object path,
2288 : : * or %NULL if none assigned to the alias
2289 : : */
2290 : : gchar *
2291 : 9 : secret_service_read_alias_dbus_path_sync (SecretService *self,
2292 : : const gchar *alias,
2293 : : GCancellable *cancellable,
2294 : : GError **error)
2295 : : {
2296 : : SecretSync *sync;
2297 : : gchar *collection_path;
2298 : :
2299 [ - + + - : 9 : g_return_val_if_fail (SECRET_IS_SERVICE (self), NULL);
+ - - + ]
2300 [ - + ]: 9 : g_return_val_if_fail (alias != NULL, NULL);
2301 [ - + - - : 9 : g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
- - - - -
- ]
2302 [ + - - + ]: 9 : g_return_val_if_fail (error == NULL || *error == NULL, NULL);
2303 : :
2304 : 9 : sync = _secret_sync_new ();
2305 : 9 : g_main_context_push_thread_default (sync->context);
2306 : :
2307 : 9 : secret_service_read_alias_dbus_path (self, alias, cancellable, _secret_sync_on_result, sync);
2308 : :
2309 : 9 : g_main_loop_run (sync->loop);
2310 : :
2311 : 9 : collection_path = secret_service_read_alias_dbus_path_finish (self, sync->result, error);
2312 : :
2313 : 9 : g_main_context_pop_thread_default (sync->context);
2314 : 9 : _secret_sync_free (sync);
2315 : :
2316 : 9 : return collection_path;
2317 : : }
2318 : :
2319 : : /**
2320 : : * secret_service_set_alias_to_dbus_path: (skip)
2321 : : * @self: a secret service object
2322 : : * @alias: the alias to assign the collection to
2323 : : * @collection_path: (nullable): the dbus object path of the collection to assign to the alias
2324 : : * @cancellable: (nullable): optional cancellation object
2325 : : * @callback: called when the operation completes
2326 : : * @user_data: data to pass to the callback
2327 : : *
2328 : : * Assign a collection to this alias. Aliases help determine
2329 : : * well known collections, such as 'default'. This method takes the dbus object
2330 : : * path of the collection to assign to the alias.
2331 : : *
2332 : : * This method will return immediately and complete asynchronously.
2333 : : *
2334 : : * Stability: Unstable
2335 : : */
2336 : : void
2337 : 4 : secret_service_set_alias_to_dbus_path (SecretService *self,
2338 : : const gchar *alias,
2339 : : const gchar *collection_path,
2340 : : GCancellable *cancellable,
2341 : : GAsyncReadyCallback callback,
2342 : : gpointer user_data)
2343 : : {
2344 [ - + + - : 4 : g_return_if_fail (SECRET_IS_SERVICE (self));
+ - - + ]
2345 [ - + ]: 4 : g_return_if_fail (alias != NULL);
2346 [ - + - - : 4 : g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
- - - - -
- ]
2347 : :
2348 [ + + ]: 4 : if (collection_path == NULL)
2349 : 1 : collection_path = "/";
2350 : : else
2351 [ - + ]: 3 : g_return_if_fail (g_variant_is_object_path (collection_path));
2352 : :
2353 : 4 : g_dbus_proxy_call (G_DBUS_PROXY (self), "SetAlias",
2354 : : g_variant_new ("(so)", alias, collection_path),
2355 : : G_DBUS_CALL_FLAGS_NONE, -1, cancellable,
2356 : : callback, user_data);
2357 : : }
2358 : :
2359 : : /**
2360 : : * secret_service_set_alias_to_dbus_path_finish: (skip)
2361 : : * @self: a secret service object
2362 : : * @result: asynchronous result passed to callback
2363 : : * @error: location to place error on failure
2364 : : *
2365 : : * Finish an asynchronous operation to assign a collection to an alias.
2366 : : *
2367 : : * Stability: Unstable
2368 : : *
2369 : : * Returns: %TRUE if successful
2370 : : */
2371 : : gboolean
2372 : 4 : secret_service_set_alias_to_dbus_path_finish (SecretService *self,
2373 : : GAsyncResult *result,
2374 : : GError **error)
2375 : : {
2376 : : GVariant *retval;
2377 : :
2378 [ - + + - : 4 : g_return_val_if_fail (SECRET_IS_SERVICE (self), FALSE);
+ - - + ]
2379 [ + - - + ]: 4 : g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
2380 : :
2381 : 4 : retval = g_dbus_proxy_call_finish (G_DBUS_PROXY (self), result, error);
2382 : :
2383 : 4 : _secret_util_strip_remote_error (error);
2384 [ - + ]: 4 : if (retval == NULL)
2385 : 0 : return FALSE;
2386 : :
2387 : 4 : g_variant_unref (retval);
2388 : 4 : return TRUE;
2389 : : }
2390 : :
2391 : : /**
2392 : : * secret_service_set_alias_to_dbus_path_sync: (skip)
2393 : : * @self: a secret service object
2394 : : * @alias: the alias to assign the collection to
2395 : : * @collection_path: (nullable): the D-Bus object path of the collection to
2396 : : * assign to the alias
2397 : : * @cancellable: (nullable): optional cancellation object
2398 : : * @error: location to place error on failure
2399 : : *
2400 : : * Assign a collection to this alias.
2401 : : *
2402 : : * Aliases help determine well known collections, such as 'default'. This method
2403 : : * takes the dbus object path of the collection to assign to the alias.
2404 : : *
2405 : : * This method may block and should not be used in user interface threads.
2406 : : *
2407 : : * Stability: Unstable
2408 : : *
2409 : : * Returns: %TRUE if successful
2410 : : */
2411 : : gboolean
2412 : 2 : secret_service_set_alias_to_dbus_path_sync (SecretService *self,
2413 : : const gchar *alias,
2414 : : const gchar *collection_path,
2415 : : GCancellable *cancellable,
2416 : : GError **error)
2417 : : {
2418 : : SecretSync *sync;
2419 : : gboolean ret;
2420 : :
2421 [ - + + - : 2 : g_return_val_if_fail (SECRET_IS_SERVICE (self), FALSE);
+ - - + ]
2422 [ - + ]: 2 : g_return_val_if_fail (alias != NULL, FALSE);
2423 [ - + - - : 2 : g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
- - - - -
- ]
2424 [ + - - + ]: 2 : g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
2425 : :
2426 [ + + ]: 2 : if (collection_path == NULL)
2427 : 1 : collection_path = "/";
2428 : : else
2429 [ - + ]: 1 : g_return_val_if_fail (g_variant_is_object_path (collection_path), FALSE);
2430 : :
2431 : 2 : sync = _secret_sync_new ();
2432 : 2 : g_main_context_push_thread_default (sync->context);
2433 : :
2434 : 2 : secret_service_set_alias_to_dbus_path (self, alias, collection_path,
2435 : : cancellable, _secret_sync_on_result, sync);
2436 : :
2437 : 2 : g_main_loop_run (sync->loop);
2438 : :
2439 : 2 : ret = secret_service_set_alias_to_dbus_path_finish (self, sync->result, error);
2440 : :
2441 : 2 : g_main_context_pop_thread_default (sync->context);
2442 : 2 : _secret_sync_free (sync);
2443 : :
2444 : 2 : return ret;
2445 : : }
2446 : :
2447 : : /**
2448 : : * secret_service_prompt_at_dbus_path_sync: (skip)
2449 : : * @self: the secret service
2450 : : * @prompt_path: the D-Bus object path of the prompt
2451 : : * @cancellable: (nullable): optional cancellation object
2452 : : * @return_type: (nullable): the variant type of the prompt result
2453 : : * @error: location to place error on failure
2454 : : *
2455 : : * Perform prompting for a [class@Prompt].
2456 : : *
2457 : : * Override the #SecretServiceClass [vfunc@Service.prompt_async] virtual method
2458 : : * to change the behavior of the propmting. The default behavior is to simply
2459 : : * run [method@Prompt.perform] on the prompt.
2460 : : *
2461 : : * Returns a variant result if the prompt was completed and not dismissed. The
2462 : : * type of result depends on the action the prompt is completing, and is defined
2463 : : * in the Secret Service DBus API specification.
2464 : : *
2465 : : * This method may block and should not be used in user interface threads.
2466 : : *
2467 : : * Stability: Unstable
2468 : : *
2469 : : * Returns: (transfer full) (nullable): %NULL if the prompt was dismissed or an
2470 : : * error occurred, a variant result if the prompt was successful
2471 : : */
2472 : : GVariant *
2473 : 0 : secret_service_prompt_at_dbus_path_sync (SecretService *self,
2474 : : const gchar *prompt_path,
2475 : : GCancellable *cancellable,
2476 : : const GVariantType *return_type,
2477 : : GError **error)
2478 : : {
2479 : : SecretPrompt *prompt;
2480 : : GVariant *retval;
2481 : :
2482 [ # # # # : 0 : g_return_val_if_fail (SECRET_IS_SERVICE (self), NULL);
# # # # ]
2483 [ # # ]: 0 : g_return_val_if_fail (prompt_path != NULL, NULL);
2484 [ # # # # : 0 : g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
# # # # #
# ]
2485 [ # # # # ]: 0 : g_return_val_if_fail (error == NULL || *error == NULL, NULL);
2486 : :
2487 : 0 : prompt = _secret_prompt_instance (self, prompt_path);
2488 : 0 : retval = secret_service_prompt_sync (self, prompt, cancellable, return_type, error);
2489 : 0 : g_object_unref (prompt);
2490 : :
2491 : 0 : return retval;
2492 : : }
2493 : :
2494 : : /**
2495 : : * secret_service_prompt_at_dbus_path: (skip)
2496 : : * @self: the secret service
2497 : : * @prompt_path: the D-Bus object path of the prompt
2498 : : * @return_type: (nullable): the variant type of the prompt result
2499 : : * @cancellable: (nullable): optional cancellation object
2500 : : * @callback: called when the operation completes
2501 : : * @user_data: data to be passed to the callback
2502 : : *
2503 : : * Perform prompting for a [class@Prompt].
2504 : : *
2505 : : * This function is called by other parts of this library to handle prompts
2506 : : * for the various actions that can require prompting.
2507 : : *
2508 : : * Override the #SecretServiceClass [vfunc@Service.prompt_async] virtual method
2509 : : * to change the behavior of the propmting. The default behavior is to simply
2510 : : * run [method@Prompt.perform] on the prompt.
2511 : : *
2512 : : * Stability: Unstable
2513 : : */
2514 : : void
2515 : 0 : secret_service_prompt_at_dbus_path (SecretService *self,
2516 : : const gchar *prompt_path,
2517 : : const GVariantType *return_type,
2518 : : GCancellable *cancellable,
2519 : : GAsyncReadyCallback callback,
2520 : : gpointer user_data)
2521 : : {
2522 : : SecretPrompt *prompt;
2523 : :
2524 [ # # # # : 0 : g_return_if_fail (SECRET_IS_SERVICE (self));
# # # # ]
2525 [ # # ]: 0 : g_return_if_fail (prompt_path != NULL);
2526 [ # # # # : 0 : g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
# # # # #
# ]
2527 : :
2528 : 0 : prompt = _secret_prompt_instance (self, prompt_path);
2529 : 0 : secret_service_prompt (self, prompt, return_type, cancellable, callback, user_data);
2530 : 0 : g_object_unref (prompt);
2531 : : }
2532 : :
2533 : : /**
2534 : : * secret_service_prompt_at_dbus_path_finish: (skip)
2535 : : * @self: the secret service
2536 : : * @result: the asynchronous result passed to the callback
2537 : : * @error: location to place an error on failure
2538 : : *
2539 : : * Complete asynchronous operation to perform prompting for a [class@Prompt].
2540 : : *
2541 : : * Returns a variant result if the prompt was completed and not dismissed. The
2542 : : * type of result depends on the action the prompt is completing, and is defined
2543 : : * in the Secret Service DBus API specification.
2544 : : *
2545 : : * Stability: Unstable
2546 : : *
2547 : : * Returns: (transfer full) (nullable): %NULL if the prompt was dismissed or an
2548 : : * error occurred, a variant result if the prompt was successful
2549 : : */
2550 : : GVariant *
2551 : 0 : secret_service_prompt_at_dbus_path_finish (SecretService *self,
2552 : : GAsyncResult *result,
2553 : : GError **error)
2554 : : {
2555 [ # # # # : 0 : g_return_val_if_fail (SECRET_IS_SERVICE (self), NULL);
# # # # ]
2556 [ # # # # : 0 : g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
# # # # ]
2557 [ # # # # ]: 0 : g_return_val_if_fail (error == NULL || *error == NULL, NULL);
2558 : :
2559 : 0 : return secret_service_prompt_finish (self, result, error);
2560 : : }
2561 : :
2562 : : /**
2563 : : * secret_service_encode_dbus_secret:
2564 : : * @service: the service
2565 : : * @value: the secret value
2566 : : *
2567 : : * Encodes a [struct@Value] into [struct@GLib.Variant] for use with the Secret
2568 : : * Service DBus API.
2569 : : *
2570 : : * The resulting [struct@GLib.Variant] will have a `(oayays)` signature.
2571 : : *
2572 : : * A session must have already been established by the [class@Service].
2573 : : *
2574 : : * Returns: (transfer floating): the encoded secret
2575 : : */
2576 : : GVariant *
2577 : 1 : secret_service_encode_dbus_secret (SecretService *service,
2578 : : SecretValue *value)
2579 : : {
2580 : : SecretSession *session;
2581 : :
2582 [ - + ]: 1 : g_return_val_if_fail (service != NULL, NULL);
2583 [ - + ]: 1 : g_return_val_if_fail (value != NULL, NULL);
2584 : :
2585 : 1 : session = _secret_service_get_session (service);
2586 [ - + ]: 1 : g_return_val_if_fail (session != NULL, NULL);
2587 : :
2588 : 1 : return _secret_session_encode_secret (session, value);
2589 : : }
2590 : :
2591 : : /**
2592 : : * secret_service_decode_dbus_secret:
2593 : : * @service: the service
2594 : : * @value: the encoded secret
2595 : : *
2596 : : * Decode a [struct@Value] into [struct@GLib.Variant] received with the Secret Service
2597 : : * DBus API.
2598 : : *
2599 : : * The [struct@GLib.Variant] should have a `(oayays)` signature.
2600 : : *
2601 : : * A session must have already been established by the [class@Service], and
2602 : : * the encoded secret must be valid for that session.
2603 : : *
2604 : : * Returns: (transfer full): the decoded secret value
2605 : : */
2606 : : SecretValue *
2607 : 1 : secret_service_decode_dbus_secret (SecretService *service,
2608 : : GVariant *value)
2609 : : {
2610 : : SecretSession *session;
2611 : :
2612 [ - + ]: 1 : g_return_val_if_fail (service != NULL, NULL);
2613 [ - + ]: 1 : g_return_val_if_fail (value != NULL, NULL);
2614 : :
2615 : 1 : session = _secret_service_get_session (service);
2616 [ - + ]: 1 : g_return_val_if_fail (session != NULL, NULL);
2617 : :
2618 : 1 : return _secret_session_decode_secret (session, value);
2619 : : }
|