2012-02-01 12:34:08 +00:00
|
|
|
/* libsecret - GLib wrapper for Secret Service
|
2011-09-25 06:22:36 +00:00
|
|
|
*
|
|
|
|
* Copyright 2011 Collabora Ltd.
|
2012-01-23 16:20:18 +00:00
|
|
|
* Copyright 2012 Red Hat Inc.
|
2011-09-25 06:22:36 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published
|
2012-03-31 13:32:43 +00:00
|
|
|
* by the Free Software Foundation; either version 2.1 of the licence or (at
|
2011-09-25 06:22:36 +00:00
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* See the included COPYING file for more information.
|
2012-03-31 13:32:43 +00:00
|
|
|
*
|
|
|
|
* Author: Stef Walter <stefw@gnome.org>
|
2011-09-25 06:22:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
#include "secret-collection.h"
|
|
|
|
#include "secret-dbus-generated.h"
|
|
|
|
#include "secret-enum-types.h"
|
|
|
|
#include "secret-item.h"
|
2012-07-05 14:41:28 +00:00
|
|
|
#include "secret-paths.h"
|
2012-02-01 12:34:08 +00:00
|
|
|
#include "secret-private.h"
|
|
|
|
#include "secret-service.h"
|
|
|
|
#include "secret-types.h"
|
|
|
|
#include "secret-value.h"
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2011-09-25 08:03:48 +00:00
|
|
|
#include "egg/egg-secure-memory.h"
|
|
|
|
|
2012-02-02 13:59:59 +00:00
|
|
|
/**
|
|
|
|
* SECTION:secret-service
|
|
|
|
* @title: SecretService
|
|
|
|
* @short_description: the Secret Service
|
|
|
|
*
|
|
|
|
* A #SecretService object represents the Secret Service implementation which
|
2012-03-24 12:31:14 +00:00
|
|
|
* runs as a D-Bus service.
|
2012-02-02 13:59:59 +00:00
|
|
|
*
|
|
|
|
* Normally a single #SecretService object can be shared between multiple
|
|
|
|
* callers. The secret_service_get() method is used to access this #SecretService
|
|
|
|
* object. If a new independent #SecretService object is required, use
|
|
|
|
* secret_service_new().
|
|
|
|
*
|
|
|
|
* In order to securely transfer secrets to the Sercret Service, an session
|
|
|
|
* is established. This session can be established while initializing a
|
|
|
|
* #SecretService object by passing the %SECRET_SERVICE_OPEN_SESSION flag
|
|
|
|
* to the secret_service_get() or secret_service_new() functions. In order to
|
|
|
|
* establish a session on an already existing #SecretService, use the
|
|
|
|
* secret_service_ensure_session() function.
|
|
|
|
*
|
|
|
|
* To search for items, use the secret_service_search() method.
|
|
|
|
*
|
|
|
|
* Multiple collections can exist in the Secret Service, each of which contains
|
|
|
|
* secret items. In order to instantiate #SecretCollection objects which
|
|
|
|
* represent those collections while initializing a #SecretService then pass
|
|
|
|
* the %SECRET_SERVICE_LOAD_COLLECTIONS flag to the secret_service_get() or
|
|
|
|
* secret_service_new() functions. In order to establish a session on an already
|
2012-07-05 19:26:20 +00:00
|
|
|
* existing #SecretService, use the secret_service_load_collections() function.
|
2012-02-02 13:59:59 +00:00
|
|
|
* To access the list of collections use secret_service_get_collections().
|
|
|
|
*
|
|
|
|
* Certain actions on the Secret Service require user prompting to complete,
|
|
|
|
* such as creating a collection, or unlocking a collection. When such a prompt
|
|
|
|
* is necessary, then a #SecretPrompt object is created by this library, and
|
2012-03-17 13:25:50 +00:00
|
|
|
* passed to the secret_service_prompt() method. In this way it is handled
|
2012-02-02 13:59:59 +00:00
|
|
|
* automatically.
|
|
|
|
*
|
2012-03-17 13:25:50 +00:00
|
|
|
* In order to customize prompt handling, override the <literal>prompt_async</literal>
|
|
|
|
* and <literal>prompt_finish</literal> virtual methods of the #SecretService class.
|
2012-03-24 06:52:12 +00:00
|
|
|
*
|
2012-04-27 14:57:36 +00:00
|
|
|
* Stability: Unstable
|
2012-02-02 13:59:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SecretService:
|
|
|
|
*
|
|
|
|
* A proxy object representing the Secret Service.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SecretServiceClass:
|
|
|
|
* @parent_class: the parent class
|
|
|
|
* @collection_gtype: the #GType of the #SecretCollection objects instantiated
|
|
|
|
* by the #SecretService proxy
|
|
|
|
* @item_gtype: the #GType of the #SecretItem objects instantiated by the
|
|
|
|
* #SecretService proxy
|
|
|
|
* @prompt_async: called to perform asynchronous prompting when necessary
|
|
|
|
* @prompt_finish: called to complete an asynchronous prompt operation
|
|
|
|
* @prompt_sync: called to perform synchronous prompting when necessary
|
|
|
|
*
|
|
|
|
* The class for #SecretService.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SecretServiceFlags:
|
|
|
|
* @SECRET_SERVICE_NONE: no flags for initializing the #SecretService
|
|
|
|
* @SECRET_SERVICE_OPEN_SESSION: establish a session for transfer of secrets
|
|
|
|
* while initializing the #SecretService
|
|
|
|
* @SECRET_SERVICE_LOAD_COLLECTIONS: load collections while initializing the
|
|
|
|
* #SecretService
|
|
|
|
*
|
|
|
|
* Flags which determine which parts of the #SecretService proxy are initialized
|
|
|
|
* during a secret_service_get() or secret_service_new() operation.
|
|
|
|
*/
|
|
|
|
|
2011-09-25 06:22:36 +00:00
|
|
|
EGG_SECURE_GLIB_DEFINITIONS ();
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
static const gchar *default_bus_name = SECRET_SERVICE_BUS_NAME;
|
2012-01-11 06:44:32 +00:00
|
|
|
|
2012-01-20 14:10:35 +00:00
|
|
|
enum {
|
|
|
|
PROP_0,
|
2012-01-25 13:26:52 +00:00
|
|
|
PROP_FLAGS,
|
2012-01-20 14:10:35 +00:00
|
|
|
PROP_COLLECTIONS
|
2011-09-25 06:22:36 +00:00
|
|
|
};
|
|
|
|
|
2012-03-30 12:59:04 +00:00
|
|
|
struct _SecretServicePrivate {
|
2012-01-20 14:10:35 +00:00
|
|
|
/* No change between construct and finalize */
|
|
|
|
GCancellable *cancellable;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretServiceFlags init_flags;
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
/* Locked by mutex */
|
|
|
|
GMutex mutex;
|
|
|
|
gpointer session;
|
|
|
|
GHashTable *collections;
|
2012-03-30 12:59:04 +00:00
|
|
|
};
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2011-09-25 16:39:03 +00:00
|
|
|
G_LOCK_DEFINE (service_instance);
|
|
|
|
static gpointer service_instance = NULL;
|
2012-07-06 08:08:27 +00:00
|
|
|
static guint service_watch = 0;
|
2011-09-25 16:39:03 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
static GInitableIface *secret_service_initable_parent_iface = NULL;
|
2011-09-25 16:39:03 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
static GAsyncInitableIface *secret_service_async_initable_parent_iface = NULL;
|
2012-01-25 13:26:52 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
static void secret_service_initable_iface (GInitableIface *iface);
|
2012-01-25 13:26:52 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
static void secret_service_async_initable_iface (GAsyncInitableIface *iface);
|
2012-01-25 13:26:52 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (SecretService, secret_service, G_TYPE_DBUS_PROXY,
|
|
|
|
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, secret_service_initable_iface);
|
|
|
|
G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, secret_service_async_initable_iface);
|
2012-01-25 13:26:52 +00:00
|
|
|
);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-07-06 08:08:27 +00:00
|
|
|
static SecretService *
|
|
|
|
service_get_instance (void)
|
|
|
|
{
|
|
|
|
SecretService *instance = NULL;
|
|
|
|
|
|
|
|
G_LOCK (service_instance);
|
|
|
|
if (service_instance != NULL)
|
|
|
|
instance = g_object_ref (service_instance);
|
|
|
|
G_UNLOCK (service_instance);
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
service_uncache_instance (SecretService *which)
|
|
|
|
{
|
|
|
|
SecretService *instance = NULL;
|
|
|
|
guint watch = 0;
|
|
|
|
gboolean matched = FALSE;
|
|
|
|
|
|
|
|
G_LOCK (service_instance);
|
|
|
|
if (which == NULL || service_instance == which) {
|
|
|
|
instance = service_instance;
|
|
|
|
service_instance = NULL;
|
|
|
|
watch = service_watch;
|
|
|
|
service_watch = 0;
|
|
|
|
matched = TRUE;
|
|
|
|
}
|
|
|
|
G_UNLOCK (service_instance);
|
|
|
|
|
|
|
|
if (instance != NULL)
|
|
|
|
g_object_unref (instance);
|
|
|
|
if (watch != 0)
|
|
|
|
g_bus_unwatch_name (watch);
|
|
|
|
|
|
|
|
return matched;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_service_instance_vanished (GDBusConnection *connection,
|
|
|
|
const gchar *name,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
if (!service_uncache_instance (user_data)) {
|
|
|
|
g_warning ("Global default SecretService instance out of sync "
|
|
|
|
"with the watch for its DBus name");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
service_cache_instance (SecretService *instance)
|
|
|
|
{
|
|
|
|
GDBusProxy *proxy;
|
|
|
|
guint watch;
|
|
|
|
|
|
|
|
g_object_ref (instance);
|
|
|
|
proxy = G_DBUS_PROXY (instance);
|
|
|
|
watch = g_bus_watch_name_on_connection (g_dbus_proxy_get_connection (proxy),
|
|
|
|
g_dbus_proxy_get_name (proxy),
|
|
|
|
G_BUS_NAME_WATCHER_FLAGS_AUTO_START,
|
|
|
|
NULL, on_service_instance_vanished,
|
|
|
|
instance, NULL);
|
|
|
|
|
|
|
|
G_LOCK (service_instance);
|
|
|
|
if (service_instance == NULL) {
|
|
|
|
service_instance = instance;
|
|
|
|
instance = NULL;
|
|
|
|
service_watch = watch;
|
|
|
|
watch = 0;
|
|
|
|
}
|
|
|
|
G_UNLOCK (service_instance);
|
|
|
|
|
|
|
|
if (instance != NULL)
|
|
|
|
g_object_unref (instance);
|
|
|
|
if (watch != 0)
|
|
|
|
g_bus_unwatch_name (watch);
|
|
|
|
}
|
|
|
|
|
2011-09-25 16:39:03 +00:00
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_init (SecretService *self)
|
2011-09-25 16:39:03 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
self->pv = G_TYPE_INSTANCE_GET_PRIVATE (self, SECRET_TYPE_SERVICE,
|
|
|
|
SecretServicePrivate);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
g_mutex_init (&self->pv->mutex);
|
|
|
|
self->pv->cancellable = g_cancellable_new ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_get_property (GObject *obj,
|
2012-02-02 12:40:47 +00:00
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *self = SECRET_SERVICE (obj);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2012-01-25 13:26:52 +00:00
|
|
|
case PROP_FLAGS:
|
2012-02-01 12:34:08 +00:00
|
|
|
g_value_set_flags (value, secret_service_get_flags (self));
|
2012-01-25 13:26:52 +00:00
|
|
|
break;
|
2012-01-20 14:10:35 +00:00
|
|
|
case PROP_COLLECTIONS:
|
2012-02-01 12:34:08 +00:00
|
|
|
g_value_take_boxed (value, secret_service_get_collections (self));
|
2012-01-20 14:10:35 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_set_property (GObject *obj,
|
2012-02-02 12:40:47 +00:00
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2012-01-25 13:26:52 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *self = SECRET_SERVICE (obj);
|
2012-01-25 13:26:52 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_FLAGS:
|
|
|
|
self->pv->init_flags = g_value_get_flags (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-20 14:10:35 +00:00
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_dispose (GObject *obj)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *self = SECRET_SERVICE (obj);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
g_cancellable_cancel (self->pv->cancellable);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
G_OBJECT_CLASS (secret_service_parent_class)->dispose (obj);
|
2011-09-25 16:39:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_finalize (GObject *obj)
|
2011-09-25 16:39:03 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *self = SECRET_SERVICE (obj);
|
2011-09-25 16:39:03 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
_secret_session_free (self->pv->session);
|
2012-01-25 13:26:52 +00:00
|
|
|
if (self->pv->collections)
|
|
|
|
g_hash_table_destroy (self->pv->collections);
|
2012-01-20 14:10:35 +00:00
|
|
|
g_clear_object (&self->pv->cancellable);
|
2012-07-05 13:40:23 +00:00
|
|
|
g_mutex_clear (&self->pv->mutex);
|
2011-09-25 16:39:03 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
G_OBJECT_CLASS (secret_service_parent_class)->finalize (obj);
|
2011-09-25 16:39:03 +00:00
|
|
|
}
|
|
|
|
|
2012-04-29 19:34:40 +00:00
|
|
|
static GVariant *
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_real_prompt_sync (SecretService *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
SecretPrompt *prompt,
|
|
|
|
GCancellable *cancellable,
|
2012-04-29 19:34:40 +00:00
|
|
|
const GVariantType *return_type,
|
2012-02-02 12:40:47 +00:00
|
|
|
GError **error)
|
2012-01-11 06:44:32 +00:00
|
|
|
{
|
2012-04-29 19:34:40 +00:00
|
|
|
return secret_prompt_perform_sync (prompt, 0, cancellable, return_type, error);
|
2012-01-11 06:44:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_real_prompt_completed (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
GError *error = NULL;
|
2012-04-29 19:34:40 +00:00
|
|
|
GVariant *retval;
|
2012-01-11 06:44:32 +00:00
|
|
|
|
2012-04-29 19:34:40 +00:00
|
|
|
retval = secret_prompt_perform_finish (SECRET_PROMPT (source), result, NULL, &error);
|
|
|
|
if (retval != NULL)
|
|
|
|
g_simple_async_result_set_op_res_gpointer (res, retval, (GDestroyNotify)g_variant_unref);
|
2012-01-11 06:44:32 +00:00
|
|
|
if (error != NULL)
|
|
|
|
g_simple_async_result_take_error (res, error);
|
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_real_prompt_async (SecretService *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
SecretPrompt *prompt,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2012-01-11 06:44:32 +00:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
|
|
|
|
res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_real_prompt_async);
|
2012-01-11 06:44:32 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_prompt_perform (prompt, 0, cancellable,
|
2012-02-02 12:40:47 +00:00
|
|
|
on_real_prompt_completed,
|
|
|
|
g_object_ref (res));
|
2012-01-11 06:44:32 +00:00
|
|
|
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
2012-04-29 19:34:40 +00:00
|
|
|
static GVariant *
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_real_prompt_finish (SecretService *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
GAsyncResult *result,
|
2012-04-29 19:34:40 +00:00
|
|
|
const GVariantType *return_type,
|
2012-02-02 12:40:47 +00:00
|
|
|
GError **error)
|
2012-01-11 06:44:32 +00:00
|
|
|
{
|
2012-04-29 19:34:40 +00:00
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
GVariant *retval;
|
|
|
|
gchar *string;
|
|
|
|
|
|
|
|
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
|
|
|
|
secret_service_real_prompt_async), NULL);
|
2012-01-11 06:44:32 +00:00
|
|
|
|
2012-04-29 19:34:40 +00:00
|
|
|
res = G_SIMPLE_ASYNC_RESULT (result);
|
2012-01-11 06:44:32 +00:00
|
|
|
if (g_simple_async_result_propagate_error (res, error))
|
2012-04-29 19:34:40 +00:00
|
|
|
return NULL;
|
2012-01-11 06:44:32 +00:00
|
|
|
|
2012-04-29 19:34:40 +00:00
|
|
|
retval = g_simple_async_result_get_op_res_gpointer (res);
|
|
|
|
if (retval == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (return_type != NULL && !g_variant_is_of_type (retval, return_type)) {
|
|
|
|
string = g_variant_type_dup_string (return_type);
|
|
|
|
g_warning ("received unexpected result type %s from prompt's Completed signal instead of expected %s",
|
|
|
|
g_variant_get_type_string (retval), string);
|
|
|
|
g_free (string);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_variant_ref (retval);
|
2012-01-11 06:44:32 +00:00
|
|
|
}
|
|
|
|
|
2012-01-20 14:10:35 +00:00
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
handle_property_changed (SecretService *self,
|
2012-01-20 14:10:35 +00:00
|
|
|
const gchar *property_name,
|
|
|
|
GVariant *value)
|
|
|
|
{
|
2012-01-25 13:26:52 +00:00
|
|
|
gboolean perform;
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-19 12:09:07 +00:00
|
|
|
g_variant_ref_sink (value);
|
|
|
|
|
2012-01-20 14:10:35 +00:00
|
|
|
if (g_str_equal (property_name, "Collections")) {
|
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
g_mutex_lock (&self->pv->mutex);
|
|
|
|
perform = self->pv->collections != NULL;
|
|
|
|
g_mutex_unlock (&self->pv->mutex);
|
|
|
|
|
|
|
|
if (perform)
|
2012-07-05 19:26:20 +00:00
|
|
|
secret_service_load_collections (self, self->pv->cancellable, NULL, NULL);
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
2012-02-19 12:09:07 +00:00
|
|
|
|
|
|
|
g_variant_unref (value);
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_properties_changed (GDBusProxy *proxy,
|
2012-02-02 12:40:47 +00:00
|
|
|
GVariant *changed_properties,
|
|
|
|
const gchar* const *invalidated_properties)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *self = SECRET_SERVICE (proxy);
|
2012-01-20 14:10:35 +00:00
|
|
|
gchar *property_name;
|
|
|
|
GVariantIter iter;
|
|
|
|
GVariant *value;
|
|
|
|
|
|
|
|
g_object_freeze_notify (G_OBJECT (self));
|
|
|
|
|
|
|
|
g_variant_iter_init (&iter, changed_properties);
|
|
|
|
while (g_variant_iter_loop (&iter, "{sv}", &property_name, &value))
|
|
|
|
handle_property_changed (self, property_name, value);
|
|
|
|
|
|
|
|
g_object_thaw_notify (G_OBJECT (self));
|
|
|
|
}
|
|
|
|
|
2012-02-19 12:09:07 +00:00
|
|
|
static void
|
|
|
|
secret_service_signal (GDBusProxy *proxy,
|
|
|
|
const gchar *sender_name,
|
|
|
|
const gchar *signal_name,
|
|
|
|
GVariant *parameters)
|
|
|
|
{
|
|
|
|
SecretService *self = SECRET_SERVICE (proxy);
|
|
|
|
SecretCollection *collection;
|
|
|
|
const gchar *collection_path;
|
|
|
|
GVariantBuilder builder;
|
|
|
|
gboolean found = FALSE;
|
|
|
|
GVariantIter iter;
|
|
|
|
GVariant *value;
|
|
|
|
GVariant *paths;
|
|
|
|
GVariant *path;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remember that these signals come from a time before PropertiesChanged.
|
|
|
|
* We support them because they're in the spec, and ksecretservice uses them.
|
|
|
|
*/
|
|
|
|
|
|
|
|
paths = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self), "Collections");
|
|
|
|
|
|
|
|
/* A new collection was added, add it to the Collections property */
|
|
|
|
if (g_str_equal (signal_name, SECRET_SIGNAL_COLLECTION_CREATED)) {
|
2012-06-27 14:36:45 +00:00
|
|
|
g_variant_get (parameters, "(@o)", &value);
|
2012-02-19 12:09:07 +00:00
|
|
|
g_variant_builder_init (&builder, G_VARIANT_TYPE ("ao"));
|
|
|
|
g_variant_iter_init (&iter, paths);
|
|
|
|
while ((path = g_variant_iter_next_value (&iter)) != NULL) {
|
|
|
|
if (g_variant_equal (path, value)) {
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
g_variant_builder_add_value (&builder, path);
|
|
|
|
g_variant_unref (path);
|
|
|
|
}
|
|
|
|
if (!found) {
|
|
|
|
g_variant_builder_add_value (&builder, value);
|
|
|
|
handle_property_changed (self, "Collections", g_variant_builder_end (&builder));
|
|
|
|
}
|
|
|
|
g_variant_builder_clear (&builder);
|
|
|
|
g_variant_unref (value);
|
|
|
|
|
|
|
|
/* A collection was deleted, remove it from the Collections property */
|
|
|
|
} else if (g_str_equal (signal_name, SECRET_SIGNAL_COLLECTION_DELETED)) {
|
2012-06-27 14:36:45 +00:00
|
|
|
g_variant_get (parameters, "(@o)", &value);
|
2012-02-19 12:09:07 +00:00
|
|
|
g_variant_builder_init (&builder, G_VARIANT_TYPE ("ao"));
|
|
|
|
g_variant_iter_init (&iter, paths);
|
|
|
|
while ((path = g_variant_iter_next_value (&iter)) != NULL) {
|
|
|
|
if (g_variant_equal (path, value))
|
|
|
|
found = TRUE;
|
|
|
|
else
|
|
|
|
g_variant_builder_add_value (&builder, path);
|
|
|
|
g_variant_unref (path);
|
|
|
|
}
|
|
|
|
if (found)
|
|
|
|
handle_property_changed (self, "Collections", g_variant_builder_end (&builder));
|
|
|
|
g_variant_unref (value);
|
|
|
|
|
|
|
|
/* The collection changed, update it */
|
|
|
|
} else if (g_str_equal (signal_name, SECRET_SIGNAL_COLLECTION_CHANGED)) {
|
2012-06-27 14:36:45 +00:00
|
|
|
g_variant_get (parameters, "(&o)", &collection_path);
|
2012-02-19 12:09:07 +00:00
|
|
|
|
|
|
|
g_mutex_lock (&self->pv->mutex);
|
|
|
|
|
|
|
|
if (self->pv->collections)
|
|
|
|
collection = g_hash_table_lookup (self->pv->collections, collection_path);
|
|
|
|
else
|
|
|
|
collection = NULL;
|
|
|
|
if (collection)
|
|
|
|
g_object_ref (collection);
|
|
|
|
|
|
|
|
g_mutex_unlock (&self->pv->mutex);
|
|
|
|
|
2012-06-27 14:38:35 +00:00
|
|
|
if (collection) {
|
|
|
|
secret_collection_refresh (collection);
|
|
|
|
g_object_unref (collection);
|
|
|
|
}
|
2012-02-19 12:09:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_variant_unref (paths);
|
|
|
|
}
|
|
|
|
|
2011-09-25 16:39:03 +00:00
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_class_init (SecretServiceClass *klass)
|
2011-09-25 16:39:03 +00:00
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2012-01-20 14:10:35 +00:00
|
|
|
GDBusProxyClass *proxy_class = G_DBUS_PROXY_CLASS (klass);
|
2011-09-25 16:39:03 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
object_class->get_property = secret_service_get_property;
|
|
|
|
object_class->set_property = secret_service_set_property;
|
|
|
|
object_class->dispose = secret_service_dispose;
|
|
|
|
object_class->finalize = secret_service_finalize;
|
2011-09-25 16:39:03 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
proxy_class->g_properties_changed = secret_service_properties_changed;
|
2012-02-19 12:09:07 +00:00
|
|
|
proxy_class->g_signal = secret_service_signal;
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
klass->prompt_sync = secret_service_real_prompt_sync;
|
|
|
|
klass->prompt_async = secret_service_real_prompt_async;
|
|
|
|
klass->prompt_finish = secret_service_real_prompt_finish;
|
2012-01-11 06:44:32 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
klass->item_gtype = SECRET_TYPE_ITEM;
|
|
|
|
klass->collection_gtype = SECRET_TYPE_COLLECTION;
|
2012-01-23 16:20:18 +00:00
|
|
|
|
2012-02-02 13:59:59 +00:00
|
|
|
/**
|
|
|
|
* SecretService:flags:
|
|
|
|
*
|
|
|
|
* A set of flags describing which parts of the secret service have
|
|
|
|
* been initialized.
|
|
|
|
*/
|
2012-01-25 13:26:52 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_FLAGS,
|
|
|
|
g_param_spec_flags ("flags", "Flags", "Service flags",
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_flags_get_type (), SECRET_SERVICE_NONE,
|
2012-01-25 13:26:52 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2012-02-02 13:59:59 +00:00
|
|
|
/**
|
|
|
|
* SecretService:collections:
|
|
|
|
*
|
|
|
|
* A list of #SecretCollection objects representing the collections in
|
|
|
|
* the Secret Service. This list may be %NULL if the collections have
|
|
|
|
* not been loaded.
|
|
|
|
*
|
|
|
|
* To load the collections, specify the %SECRET_SERVICE_LOAD_COLLECTIONS
|
|
|
|
* initialization flag when calling the secret_service_get() or
|
2012-07-05 19:26:20 +00:00
|
|
|
* secret_service_new() functions. Or call the secret_service_load_collections()
|
2012-02-02 13:59:59 +00:00
|
|
|
* method.
|
|
|
|
*/
|
2012-01-25 13:26:52 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_COLLECTIONS,
|
|
|
|
g_param_spec_boxed ("collections", "Collections", "Secret Service Collections",
|
2012-02-01 12:34:08 +00:00
|
|
|
_secret_list_get_type (), G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
2012-01-25 13:26:52 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (SecretServicePrivate));
|
2011-09-25 16:39:03 +00:00
|
|
|
}
|
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
typedef struct {
|
|
|
|
GCancellable *cancellable;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretServiceFlags flags;
|
2012-01-25 13:26:52 +00:00
|
|
|
} InitClosure;
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_closure_free (gpointer data)
|
2012-01-11 06:44:32 +00:00
|
|
|
{
|
2012-01-25 13:26:52 +00:00
|
|
|
InitClosure *closure = data;
|
|
|
|
g_clear_object (&closure->cancellable);
|
|
|
|
g_slice_free (InitClosure, closure);
|
2012-01-11 06:44:32 +00:00
|
|
|
}
|
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
static gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
service_ensure_for_flags_sync (SecretService *self,
|
|
|
|
SecretServiceFlags flags,
|
2012-01-25 13:26:52 +00:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2011-09-25 16:39:03 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
if (flags & SECRET_SERVICE_OPEN_SESSION)
|
|
|
|
if (!secret_service_ensure_session_sync (self, cancellable, error))
|
2012-01-25 13:26:52 +00:00
|
|
|
return FALSE;
|
2011-09-25 16:39:03 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
if (flags & SECRET_SERVICE_LOAD_COLLECTIONS)
|
2012-07-05 19:26:20 +00:00
|
|
|
if (!secret_service_load_collections_sync (self, cancellable, error))
|
2012-01-25 13:26:52 +00:00
|
|
|
return FALSE;
|
2011-09-25 16:39:03 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
return TRUE;
|
2011-09-25 16:39:03 +00:00
|
|
|
}
|
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
static void
|
2012-07-05 19:26:20 +00:00
|
|
|
on_load_collections (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
2011-09-25 16:39:03 +00:00
|
|
|
{
|
2012-01-25 13:26:52 +00:00
|
|
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *self = SECRET_SERVICE (source);
|
2011-09-25 16:39:03 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
|
2012-07-05 19:26:20 +00:00
|
|
|
if (!secret_service_load_collections_finish (self, result, &error))
|
2012-01-25 13:26:52 +00:00
|
|
|
g_simple_async_result_take_error (res, error);
|
2011-09-25 16:39:03 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_ensure_session (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
InitClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *self = SECRET_SERVICE (source);
|
2012-01-25 13:26:52 +00:00
|
|
|
GError *error = NULL;
|
2011-11-06 07:59:20 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
if (!secret_service_ensure_session_finish (self, result, &error)) {
|
2012-01-25 13:26:52 +00:00
|
|
|
g_simple_async_result_take_error (res, error);
|
|
|
|
g_simple_async_result_complete (res);
|
2011-11-06 07:59:20 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
} else if (closure->flags & SECRET_SERVICE_LOAD_COLLECTIONS) {
|
2012-07-05 19:26:20 +00:00
|
|
|
secret_service_load_collections (self, closure->cancellable,
|
|
|
|
on_load_collections, g_object_ref (res));
|
2011-11-06 07:59:20 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
} else {
|
|
|
|
g_simple_async_result_complete_in_idle (res);
|
2011-09-25 16:39:03 +00:00
|
|
|
}
|
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
g_object_unref (res);
|
|
|
|
}
|
2011-09-25 16:39:03 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
service_ensure_for_flags_async (SecretService *self,
|
|
|
|
SecretServiceFlags flags,
|
2012-01-25 13:26:52 +00:00
|
|
|
GSimpleAsyncResult *res)
|
|
|
|
{
|
|
|
|
InitClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
2011-09-25 16:39:03 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
closure->flags = flags;
|
2011-09-25 16:39:03 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
if (closure->flags & SECRET_SERVICE_OPEN_SESSION)
|
|
|
|
secret_service_ensure_session (self, closure->cancellable,
|
2012-02-02 12:40:47 +00:00
|
|
|
on_ensure_session, g_object_ref (res));
|
2011-09-25 16:39:03 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
else if (closure->flags & SECRET_SERVICE_LOAD_COLLECTIONS)
|
2012-07-05 19:26:20 +00:00
|
|
|
secret_service_load_collections (self, closure->cancellable,
|
|
|
|
on_load_collections, g_object_ref (res));
|
2011-09-25 16:39:03 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
else
|
|
|
|
g_simple_async_result_complete_in_idle (res);
|
|
|
|
}
|
2012-01-11 06:44:32 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
static gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_initable_init (GInitable *initable,
|
2012-02-02 12:40:47 +00:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2012-01-11 06:44:32 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *self;
|
2012-01-25 13:26:52 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
if (!secret_service_initable_parent_iface->init (initable, cancellable, error))
|
2012-01-25 13:26:52 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
self = SECRET_SERVICE (initable);
|
2012-01-25 13:26:52 +00:00
|
|
|
return service_ensure_for_flags_sync (self, self->pv->init_flags, cancellable, error);
|
2012-01-11 06:44:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_initable_iface (GInitableIface *iface)
|
2012-01-11 06:44:32 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_initable_parent_iface = g_type_interface_peek_parent (iface);
|
2012-01-11 06:44:32 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
iface->init = secret_service_initable_init;
|
2012-01-11 06:44:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-01-25 13:26:52 +00:00
|
|
|
on_init_base (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
2012-01-11 06:44:32 +00:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *self = SECRET_SERVICE (source);
|
2012-01-11 06:44:32 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
if (!secret_service_async_initable_parent_iface->init_finish (G_ASYNC_INITABLE (self),
|
2012-02-02 12:40:47 +00:00
|
|
|
result, &error)) {
|
2012-01-11 06:44:32 +00:00
|
|
|
g_simple_async_result_take_error (res, error);
|
|
|
|
g_simple_async_result_complete (res);
|
2012-01-26 13:34:37 +00:00
|
|
|
} else {
|
2012-07-05 13:40:57 +00:00
|
|
|
service_ensure_for_flags_async (self, self->pv->init_flags, res);
|
2012-01-11 06:44:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_async_initable_init_async (GAsyncInitable *initable,
|
2012-02-02 12:40:47 +00:00
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2012-01-11 06:44:32 +00:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
2012-01-25 13:26:52 +00:00
|
|
|
InitClosure *closure;
|
2012-01-11 06:44:32 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
res = g_simple_async_result_new (G_OBJECT (initable), callback, user_data,
|
2012-02-02 12:40:47 +00:00
|
|
|
secret_service_async_initable_init_async);
|
2012-01-25 13:26:52 +00:00
|
|
|
closure = g_slice_new0 (InitClosure);
|
2012-01-11 06:44:32 +00:00
|
|
|
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
2012-01-25 13:26:52 +00:00
|
|
|
g_simple_async_result_set_op_res_gpointer (res, closure, init_closure_free);
|
2012-01-11 06:44:32 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_async_initable_parent_iface->init_async (initable, io_priority,
|
2012-02-02 12:40:47 +00:00
|
|
|
cancellable,
|
|
|
|
on_init_base,
|
|
|
|
g_object_ref (res));
|
2012-01-11 06:44:32 +00:00
|
|
|
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
static gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_async_initable_init_finish (GAsyncInitable *initable,
|
2012-02-02 12:40:47 +00:00
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
2012-01-11 06:44:32 +00:00
|
|
|
{
|
2012-01-25 13:26:52 +00:00
|
|
|
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (initable),
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_async_initable_init_async), FALSE);
|
2012-01-11 06:44:32 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
|
|
|
|
return FALSE;
|
2012-01-11 06:44:32 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
return TRUE;
|
2012-01-11 06:44:32 +00:00
|
|
|
}
|
|
|
|
|
2012-01-20 14:10:35 +00:00
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_async_initable_iface (GAsyncInitableIface *iface)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_async_initable_parent_iface = g_type_interface_peek_parent (iface);
|
2012-01-25 13:26:52 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
iface->init_async = secret_service_async_initable_init_async;
|
|
|
|
iface->init_finish = secret_service_async_initable_init_finish;
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
void
|
2012-02-01 12:34:08 +00:00
|
|
|
_secret_service_set_default_bus_name (const gchar *bus_name)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-01-25 13:26:52 +00:00
|
|
|
g_return_if_fail (bus_name != NULL);
|
|
|
|
default_bus_name = bus_name;
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_service_get:
|
|
|
|
* @flags: flags for which service functionality to ensure is initialized
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @callback: called when the operation completes
|
|
|
|
* @user_data: data to be passed to the callback
|
|
|
|
*
|
|
|
|
* Get a #SecretService proxy for the Secret Service. If such a proxy object
|
|
|
|
* already exists, then the same proxy is returned.
|
|
|
|
*
|
|
|
|
* If @flags contains any flags of which parts of the secret service to
|
|
|
|
* ensure are initialized, then those will be initialized before completing.
|
|
|
|
*
|
|
|
|
* This method will return immediately and complete asynchronously.
|
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_get (SecretServiceFlags flags,
|
2012-02-02 12:40:47 +00:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *service = NULL;
|
2012-01-20 14:10:35 +00:00
|
|
|
GSimpleAsyncResult *res;
|
2012-01-25 13:26:52 +00:00
|
|
|
InitClosure *closure;
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-07-06 08:08:27 +00:00
|
|
|
service = service_get_instance ();
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
/* Create a whole new service */
|
|
|
|
if (service == NULL) {
|
2012-02-01 12:34:08 +00:00
|
|
|
g_async_initable_new_async (SECRET_TYPE_SERVICE, G_PRIORITY_DEFAULT,
|
2012-01-25 13:26:52 +00:00
|
|
|
cancellable, callback, user_data,
|
|
|
|
"g-flags", G_DBUS_PROXY_FLAGS_NONE,
|
2012-02-01 12:34:08 +00:00
|
|
|
"g-interface-info", _secret_gen_service_interface_info (),
|
2012-01-25 13:26:52 +00:00
|
|
|
"g-name", default_bus_name,
|
|
|
|
"g-bus-type", G_BUS_TYPE_SESSION,
|
2012-02-01 12:34:08 +00:00
|
|
|
"g-object-path", SECRET_SERVICE_PATH,
|
|
|
|
"g-interface-name", SECRET_SERVICE_INTERFACE,
|
2012-01-25 13:26:52 +00:00
|
|
|
"flags", flags,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
/* Just have to ensure that the service matches flags */
|
|
|
|
} else {
|
|
|
|
res = g_simple_async_result_new (G_OBJECT (service), callback,
|
2012-02-01 12:34:08 +00:00
|
|
|
user_data, secret_service_get);
|
2012-01-25 13:26:52 +00:00
|
|
|
closure = g_slice_new0 (InitClosure);
|
|
|
|
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
|
|
|
closure->flags = flags;
|
|
|
|
g_simple_async_result_set_op_res_gpointer (res, closure, init_closure_free);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
service_ensure_for_flags_async (service, flags, res);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-01-26 13:34:37 +00:00
|
|
|
g_object_unref (service);
|
2012-01-25 13:26:52 +00:00
|
|
|
g_object_unref (res);
|
|
|
|
}
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_service_get_finish:
|
|
|
|
* @result: the asynchronous result passed to the callback
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Complete an asynchronous operation to get a #SecretService proxy for the
|
|
|
|
* Secret Service.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): a new reference to a #SecretService proxy, which
|
|
|
|
* should be released with g_object_unref().
|
|
|
|
*/
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *
|
|
|
|
secret_service_get_finish (GAsyncResult *result,
|
2012-02-02 12:40:47 +00:00
|
|
|
GError **error)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-01-25 13:26:52 +00:00
|
|
|
GObject *service = NULL;
|
|
|
|
GObject *source_object;
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
source_object = g_async_result_get_source_object (result);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
/* Just ensuring that the service matches flags */
|
2012-02-01 12:34:08 +00:00
|
|
|
if (g_simple_async_result_is_valid (result, source_object, secret_service_get)) {
|
2012-01-25 13:26:52 +00:00
|
|
|
if (!g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
|
|
|
|
service = g_object_ref (source_object);
|
|
|
|
|
|
|
|
/* Creating a whole new service */
|
|
|
|
} else {
|
|
|
|
service = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), result, error);
|
2012-07-06 08:08:27 +00:00
|
|
|
if (service)
|
|
|
|
service_cache_instance (SECRET_SERVICE (service));
|
2012-01-25 13:26:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (source_object)
|
|
|
|
g_object_unref (source_object);
|
|
|
|
|
|
|
|
if (service == NULL)
|
2012-01-20 14:10:35 +00:00
|
|
|
return NULL;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
return SECRET_SERVICE (service);
|
2012-01-25 13:26:52 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_service_get_sync:
|
|
|
|
* @flags: flags for which service functionality to ensure is initialized
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Get a #SecretService proxy for the Secret Service. If such a proxy object
|
|
|
|
* already exists, then the same proxy is returned.
|
|
|
|
*
|
|
|
|
* If @flags contains any flags of which parts of the secret service to
|
|
|
|
* ensure are initialized, then those will be initialized before returning.
|
|
|
|
*
|
|
|
|
* This method may block indefinitely and should not be used in user interface
|
|
|
|
* threads.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): a new reference to a #SecretService proxy, which
|
|
|
|
* should be released with g_object_unref().
|
|
|
|
*/
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *
|
|
|
|
secret_service_get_sync (SecretServiceFlags flags,
|
2012-02-02 12:40:47 +00:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2012-01-25 13:26:52 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *service = NULL;
|
2012-01-25 13:26:52 +00:00
|
|
|
|
2012-07-06 08:08:27 +00:00
|
|
|
service = service_get_instance ();
|
2012-01-25 13:26:52 +00:00
|
|
|
|
|
|
|
if (service == NULL) {
|
2012-02-01 12:34:08 +00:00
|
|
|
service = g_initable_new (SECRET_TYPE_SERVICE, cancellable, error,
|
2012-01-25 13:26:52 +00:00
|
|
|
"g-flags", G_DBUS_PROXY_FLAGS_NONE,
|
2012-02-01 12:34:08 +00:00
|
|
|
"g-interface-info", _secret_gen_service_interface_info (),
|
2012-01-25 13:26:52 +00:00
|
|
|
"g-name", default_bus_name,
|
|
|
|
"g-bus-type", G_BUS_TYPE_SESSION,
|
2012-02-01 12:34:08 +00:00
|
|
|
"g-object-path", SECRET_SERVICE_PATH,
|
|
|
|
"g-interface-name", SECRET_SERVICE_INTERFACE,
|
2012-01-25 13:26:52 +00:00
|
|
|
"flags", flags,
|
|
|
|
NULL);
|
|
|
|
|
2012-07-06 08:08:27 +00:00
|
|
|
if (service != NULL)
|
|
|
|
service_cache_instance (service);
|
2012-01-25 13:26:52 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
if (!service_ensure_for_flags_sync (service, flags, cancellable, error)) {
|
|
|
|
g_object_unref (service);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-20 14:10:35 +00:00
|
|
|
return service;
|
|
|
|
}
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
/**
|
|
|
|
* secret_service_disconnect:
|
|
|
|
*
|
|
|
|
* Disconnect the default #SecretService proxy returned by secret_service_get()
|
|
|
|
* and secret_service_get_sync().
|
|
|
|
*
|
|
|
|
* It is not necessary to call this function, but you may choose to do so at
|
|
|
|
* program exit. It is useful for testing that memory is not leaked.
|
|
|
|
*
|
|
|
|
* This function is safe to call at any time. But if other objects in this
|
|
|
|
* library are still referenced, then this will not result in all memory
|
|
|
|
* being freed.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
secret_service_disconnect (void)
|
|
|
|
{
|
2012-07-06 08:08:27 +00:00
|
|
|
service_uncache_instance (NULL);
|
2012-07-05 21:14:50 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_service_new:
|
2012-06-27 09:45:09 +00:00
|
|
|
* @service_gtype: the GType of the new secret service
|
2012-03-24 12:31:14 +00:00
|
|
|
* @service_bus_name: (allow-none): the D-Bus service name of the secret service
|
2012-02-02 12:40:47 +00:00
|
|
|
* @flags: flags for which service functionality to ensure is initialized
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @callback: called when the operation completes
|
|
|
|
* @user_data: data to be passed to the callback
|
|
|
|
*
|
|
|
|
* Create a new #SecretService proxy for the Secret Service.
|
|
|
|
*
|
|
|
|
* This function is rarely used, see secret_service_get() instead.
|
|
|
|
*
|
2012-06-27 09:45:09 +00:00
|
|
|
* The @service_gtype argument should be set to %SECRET_TYPE_SERVICE or a the type
|
|
|
|
* of a derived class.
|
|
|
|
*
|
2012-02-02 12:40:47 +00:00
|
|
|
* If @flags contains any flags of which parts of the secret service to
|
|
|
|
* ensure are initialized, then those will be initialized before returning.
|
|
|
|
*
|
|
|
|
* If @service_bus_name is %NULL then the default is used.
|
|
|
|
*
|
|
|
|
* This method will return immediately and complete asynchronously.
|
|
|
|
*/
|
2012-01-25 13:26:52 +00:00
|
|
|
void
|
2012-06-27 09:45:09 +00:00
|
|
|
secret_service_new (GType service_gtype,
|
|
|
|
const gchar *service_bus_name,
|
2012-02-02 12:40:47 +00:00
|
|
|
SecretServiceFlags flags,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2012-01-25 13:26:52 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
2012-06-27 09:45:09 +00:00
|
|
|
g_return_if_fail (g_type_is_a (service_gtype, SECRET_TYPE_SERVICE));
|
2012-01-25 13:26:52 +00:00
|
|
|
|
|
|
|
if (service_bus_name == NULL)
|
|
|
|
service_bus_name = default_bus_name;
|
|
|
|
|
2012-06-27 09:45:09 +00:00
|
|
|
g_async_initable_new_async (service_gtype, G_PRIORITY_DEFAULT,
|
2012-01-25 13:26:52 +00:00
|
|
|
cancellable, callback, user_data,
|
|
|
|
"g-flags", G_DBUS_PROXY_FLAGS_NONE,
|
2012-02-01 12:34:08 +00:00
|
|
|
"g-interface-info", _secret_gen_service_interface_info (),
|
2012-01-25 13:26:52 +00:00
|
|
|
"g-name", service_bus_name,
|
|
|
|
"g-bus-type", G_BUS_TYPE_SESSION,
|
2012-02-01 12:34:08 +00:00
|
|
|
"g-object-path", SECRET_SERVICE_PATH,
|
|
|
|
"g-interface-name", SECRET_SERVICE_INTERFACE,
|
2012-01-25 13:26:52 +00:00
|
|
|
"flags", flags,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_service_new_finish:
|
|
|
|
* @result: the asynchronous result passed to the callback
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Complete an asynchronous operation to create a new #SecretService proxy for
|
|
|
|
* the Secret Service.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): a new reference to a #SecretService proxy, which
|
|
|
|
* should be released with g_object_unref().
|
|
|
|
*/
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *
|
|
|
|
secret_service_new_finish (GAsyncResult *result,
|
2012-02-02 12:40:47 +00:00
|
|
|
GError **error)
|
2012-01-25 13:26:52 +00:00
|
|
|
{
|
|
|
|
GObject *source_object;
|
|
|
|
GObject *object;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
|
|
|
|
|
|
source_object = g_async_result_get_source_object (result);
|
|
|
|
object = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object),
|
|
|
|
result, error);
|
|
|
|
g_object_unref (source_object);
|
|
|
|
|
|
|
|
if (object == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
return SECRET_SERVICE (object);
|
2012-01-25 13:26:52 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_service_new_sync:
|
2012-06-27 09:45:09 +00:00
|
|
|
* @service_gtype: the GType of the new secret service
|
2012-03-24 12:31:14 +00:00
|
|
|
* @service_bus_name: (allow-none): the D-Bus service name of the secret service
|
2012-02-02 12:40:47 +00:00
|
|
|
* @flags: flags for which service functionality to ensure is initialized
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Create a new #SecretService proxy for the Secret Service.
|
|
|
|
*
|
|
|
|
* This function is rarely used, see secret_service_get_sync() instead.
|
|
|
|
*
|
2012-06-27 09:45:09 +00:00
|
|
|
* The @service_gtype argument should be set to %SECRET_TYPE_SERVICE or a the
|
|
|
|
* type of a derived class.
|
|
|
|
*
|
2012-02-02 12:40:47 +00:00
|
|
|
* If @flags contains any flags of which parts of the secret service to
|
|
|
|
* ensure are initialized, then those will be initialized before returning.
|
|
|
|
*
|
|
|
|
* If @service_bus_name is %NULL then the default is used.
|
|
|
|
*
|
|
|
|
* This method may block indefinitely and should not be used in user interface
|
|
|
|
* threads.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): a new reference to a #SecretService proxy, which
|
|
|
|
* should be released with g_object_unref().
|
|
|
|
*/
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *
|
2012-06-27 09:45:09 +00:00
|
|
|
secret_service_new_sync (GType service_gtype,
|
|
|
|
const gchar *service_bus_name,
|
2012-02-02 12:40:47 +00:00
|
|
|
SecretServiceFlags flags,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-01-25 13:26:52 +00:00
|
|
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
|
2012-06-27 09:45:09 +00:00
|
|
|
g_return_val_if_fail (g_type_is_a (service_gtype, SECRET_TYPE_SERVICE), NULL);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
if (service_bus_name == NULL)
|
|
|
|
service_bus_name = default_bus_name;
|
|
|
|
|
2012-06-27 09:45:09 +00:00
|
|
|
return g_initable_new (service_gtype, cancellable, error,
|
2012-01-25 13:26:52 +00:00
|
|
|
"g-flags", G_DBUS_PROXY_FLAGS_NONE,
|
2012-02-01 12:34:08 +00:00
|
|
|
"g-interface-info", _secret_gen_service_interface_info (),
|
2012-01-25 13:26:52 +00:00
|
|
|
"g-name", service_bus_name,
|
|
|
|
"g-bus-type", G_BUS_TYPE_SESSION,
|
2012-02-01 12:34:08 +00:00
|
|
|
"g-object-path", SECRET_SERVICE_PATH,
|
|
|
|
"g-interface-name", SECRET_SERVICE_INTERFACE,
|
2012-01-25 13:26:52 +00:00
|
|
|
"flags", flags,
|
|
|
|
NULL);
|
|
|
|
}
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_service_get_flags:
|
|
|
|
* @self: the secret service proxy
|
|
|
|
*
|
|
|
|
* Get the flags representing what features of the #SecretService proxy
|
|
|
|
* have been initialized.
|
|
|
|
*
|
2012-07-05 19:26:20 +00:00
|
|
|
* Use secret_service_ensure_session() or secret_service_load_collections()
|
2012-02-02 12:40:47 +00:00
|
|
|
* to initialize further features and change the flags.
|
|
|
|
*
|
|
|
|
* Returns: the flags for features initialized
|
|
|
|
*/
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretServiceFlags
|
|
|
|
secret_service_get_flags (SecretService *self)
|
2012-01-25 13:26:52 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretServiceFlags flags = 0;
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_SERVICE (self), SECRET_SERVICE_NONE);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
g_mutex_lock (&self->pv->mutex);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
if (self->pv->session)
|
2012-02-01 12:34:08 +00:00
|
|
|
flags |= SECRET_SERVICE_OPEN_SESSION;
|
2012-01-25 13:26:52 +00:00
|
|
|
if (self->pv->collections)
|
2012-02-01 12:34:08 +00:00
|
|
|
flags |= SECRET_SERVICE_LOAD_COLLECTIONS;
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
g_mutex_unlock (&self->pv->mutex);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
return flags;
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_service_get_collections:
|
|
|
|
* @self: the secret service proxy
|
|
|
|
*
|
|
|
|
* Get a list of #SecretCollection objects representing all the collections
|
|
|
|
* in the secret service.
|
|
|
|
*
|
|
|
|
* If the %SECRET_SERVICE_LOAD_COLLECTIONS flag was not specified when
|
|
|
|
* initializing #SecretService proxy object, then this method will return
|
2012-07-05 19:26:20 +00:00
|
|
|
* %NULL. Use secret_service_load_collections() to load the collections.
|
2012-02-02 12:40:47 +00:00
|
|
|
*
|
|
|
|
* Returns: (transfer full) (element-type Secret.Collection) (allow-none): a
|
|
|
|
* list of the collections in the secret service
|
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
GList *
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_get_collections (SecretService *self)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
|
|
|
GList *l, *collections;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_SERVICE (self), NULL);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
g_mutex_lock (&self->pv->mutex);
|
2012-01-25 13:26:52 +00:00
|
|
|
|
|
|
|
if (self->pv->collections == NULL) {
|
|
|
|
collections = NULL;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
collections = g_hash_table_get_values (self->pv->collections);
|
|
|
|
for (l = collections; l != NULL; l = g_list_next (l))
|
|
|
|
g_object_ref (l->data);
|
|
|
|
}
|
|
|
|
|
2012-01-20 14:10:35 +00:00
|
|
|
g_mutex_unlock (&self->pv->mutex);
|
|
|
|
|
|
|
|
return collections;
|
|
|
|
}
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *
|
|
|
|
_secret_service_find_item_instance (SecretService *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
const gchar *item_path)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretCollection *collection = NULL;
|
2012-01-20 14:10:35 +00:00
|
|
|
gchar *collection_path;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *item;
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
collection_path = _secret_util_parent_path (item_path);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-06-23 12:09:50 +00:00
|
|
|
collection = _secret_service_find_collection_instance (self, collection_path);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
g_free (collection_path);
|
|
|
|
|
|
|
|
if (collection == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
item = _secret_collection_find_item_instance (collection, item_path);
|
2012-01-20 14:10:35 +00:00
|
|
|
g_object_unref (collection);
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2012-06-23 12:09:50 +00:00
|
|
|
SecretCollection *
|
|
|
|
_secret_service_find_collection_instance (SecretService *self,
|
|
|
|
const gchar *collection_path)
|
|
|
|
{
|
|
|
|
SecretCollection *collection = NULL;
|
|
|
|
|
|
|
|
g_mutex_lock (&self->pv->mutex);
|
|
|
|
if (self->pv->collections) {
|
|
|
|
collection = g_hash_table_lookup (self->pv->collections, collection_path);
|
|
|
|
if (collection != NULL)
|
|
|
|
g_object_ref (collection);
|
|
|
|
}
|
|
|
|
g_mutex_unlock (&self->pv->mutex);
|
|
|
|
|
|
|
|
return collection;
|
|
|
|
}
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretSession *
|
|
|
|
_secret_service_get_session (SecretService *self)
|
2012-01-23 16:20:18 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretSession *session;
|
2012-01-23 16:20:18 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_SERVICE (self), NULL);
|
2012-01-23 16:20:18 +00:00
|
|
|
|
|
|
|
g_mutex_lock (&self->pv->mutex);
|
|
|
|
session = self->pv->session;
|
2012-01-25 13:26:52 +00:00
|
|
|
g_mutex_unlock (&self->pv->mutex);
|
2012-01-23 16:20:18 +00:00
|
|
|
|
|
|
|
return session;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-01 12:34:08 +00:00
|
|
|
_secret_service_take_session (SecretService *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
SecretSession *session)
|
2012-01-23 16:20:18 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_if_fail (SECRET_IS_SERVICE (self));
|
2012-01-23 16:20:18 +00:00
|
|
|
g_return_if_fail (session != NULL);
|
|
|
|
|
|
|
|
g_mutex_lock (&self->pv->mutex);
|
|
|
|
if (self->pv->session == NULL)
|
|
|
|
self->pv->session = session;
|
|
|
|
else
|
2012-02-01 12:34:08 +00:00
|
|
|
_secret_session_free (session);
|
2012-01-23 16:20:18 +00:00
|
|
|
g_mutex_unlock (&self->pv->mutex);
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_service_get_session_algorithms:
|
|
|
|
* @self: the secret service proxy
|
|
|
|
*
|
|
|
|
* Get the set of algorithms being used to transfer secrets between this
|
|
|
|
* secret service proxy and the Secret Service itself.
|
|
|
|
*
|
|
|
|
* This will be %NULL if no session has been established. Use
|
|
|
|
* secret_service_ensure_session() to establish a session.
|
|
|
|
*
|
|
|
|
* Returns: (allow-none): a string representing the algorithms for transferring
|
|
|
|
* secrets
|
|
|
|
*/
|
2011-09-25 20:59:43 +00:00
|
|
|
const gchar *
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_get_session_algorithms (SecretService *self)
|
2011-09-25 20:59:43 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretSession *session;
|
2012-01-20 14:10:35 +00:00
|
|
|
const gchar *algorithms;
|
2011-09-25 20:59:43 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_SERVICE (self), NULL);
|
2011-09-25 20:59:43 +00:00
|
|
|
|
2012-01-20 14:10:35 +00:00
|
|
|
g_mutex_lock (&self->pv->mutex);
|
|
|
|
session = self->pv->session;
|
2012-02-01 12:34:08 +00:00
|
|
|
algorithms = session ? _secret_session_get_algorithms (session) : NULL;
|
2012-01-20 14:10:35 +00:00
|
|
|
g_mutex_unlock (&self->pv->mutex);
|
|
|
|
|
|
|
|
/* Session never changes once established, so can return const */
|
|
|
|
return algorithms;
|
2011-09-25 20:59:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
2012-07-06 07:01:20 +00:00
|
|
|
* secret_service_get_session_dbus_path:
|
2012-02-02 12:40:47 +00:00
|
|
|
* @self: the secret service proxy
|
|
|
|
*
|
2012-03-24 12:31:14 +00:00
|
|
|
* Get the D-Bus object path of the session object being used to transfer
|
2012-02-02 12:40:47 +00:00
|
|
|
* secrets between this secret service proxy and the Secret Service itself.
|
|
|
|
*
|
|
|
|
* This will be %NULL if no session has been established. Use
|
|
|
|
* secret_service_ensure_session() to establish a session.
|
|
|
|
*
|
2012-03-24 12:31:14 +00:00
|
|
|
* Returns: (allow-none): a string representing the D-Bus object path of the
|
2012-02-02 12:40:47 +00:00
|
|
|
* session
|
|
|
|
*/
|
2011-09-25 20:59:43 +00:00
|
|
|
const gchar *
|
2012-07-06 07:01:20 +00:00
|
|
|
secret_service_get_session_dbus_path (SecretService *self)
|
2011-09-25 20:59:43 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretSession *session;
|
2012-01-20 14:10:35 +00:00
|
|
|
const gchar *path;
|
2011-09-25 20:59:43 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_SERVICE (self), NULL);
|
2011-09-25 20:59:43 +00:00
|
|
|
|
2012-01-20 14:10:35 +00:00
|
|
|
g_mutex_lock (&self->pv->mutex);
|
|
|
|
session = self->pv->session;
|
2012-02-01 12:34:08 +00:00
|
|
|
path = session ? _secret_session_get_path (session) : NULL;
|
2012-01-20 14:10:35 +00:00
|
|
|
g_mutex_unlock (&self->pv->mutex);
|
|
|
|
|
|
|
|
/* Session never changes once established, so can return const */
|
|
|
|
return path;
|
2011-09-25 20:59:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_service_ensure_session:
|
|
|
|
* @self: the secret service
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @callback: called when the operation completes
|
|
|
|
* @user_data: data to be passed to the callback
|
|
|
|
*
|
|
|
|
* Ensure that the #SecretService proxy has established a session with the
|
|
|
|
* Secret Service. This session is used to transfer secrets.
|
|
|
|
*
|
|
|
|
* It is not normally necessary to call this method, as the session is
|
|
|
|
* established as necessary. You can also pass the %SECRET_SERVICE_OPEN_SESSION
|
|
|
|
* to secret_service_get() in order to ensure that a session has been established
|
|
|
|
* by the time you get the #SecretService proxy.
|
|
|
|
*
|
|
|
|
* This method will return immediately and complete asynchronously.
|
|
|
|
*/
|
2011-09-25 06:22:36 +00:00
|
|
|
void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_ensure_session (SecretService *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2011-09-25 06:22:36 +00:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretSession *session;
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_if_fail (SECRET_IS_SERVICE (self));
|
2011-09-25 06:22:36 +00:00
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
|
2012-01-20 14:10:35 +00:00
|
|
|
g_mutex_lock (&self->pv->mutex);
|
|
|
|
session = self->pv->session;
|
|
|
|
g_mutex_unlock (&self->pv->mutex);
|
|
|
|
|
|
|
|
if (session == NULL) {
|
2012-02-01 12:34:08 +00:00
|
|
|
_secret_session_open (self, cancellable, callback, user_data);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
|
|
|
} else {
|
2012-01-23 16:20:18 +00:00
|
|
|
res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_ensure_session);
|
2011-09-25 06:22:36 +00:00
|
|
|
g_simple_async_result_complete_in_idle (res);
|
2012-01-23 16:20:18 +00:00
|
|
|
g_object_unref (res);
|
2011-09-25 06:22:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_service_ensure_session_finish:
|
|
|
|
* @self: the secret service
|
|
|
|
* @result: the asynchronous result passed to the callback
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Finish an asynchronous operation to ensure that the #SecretService proxy
|
|
|
|
* has established a session with the Secret Service.
|
|
|
|
*
|
2012-07-06 07:01:20 +00:00
|
|
|
* Returns: whether a session is established or not
|
2012-02-02 12:40:47 +00:00
|
|
|
*/
|
2012-07-06 07:01:20 +00:00
|
|
|
gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_ensure_session_finish (SecretService *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
2011-09-25 06:22:36 +00:00
|
|
|
{
|
2012-07-06 07:01:20 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_SERVICE (self), FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-01-23 16:20:18 +00:00
|
|
|
if (!g_simple_async_result_is_valid (result, G_OBJECT (self),
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_ensure_session)) {
|
|
|
|
if (!_secret_session_open_finish (result, error))
|
2012-07-06 07:01:20 +00:00
|
|
|
return FALSE;
|
2011-09-25 16:39:03 +00:00
|
|
|
}
|
|
|
|
|
2012-07-06 07:01:20 +00:00
|
|
|
g_return_val_if_fail (self->pv->session != NULL, FALSE);
|
|
|
|
return TRUE;
|
2011-09-25 16:39:03 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_service_ensure_session_sync:
|
|
|
|
* @self: the secret service
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Ensure that the #SecretService proxy has established a session with the
|
|
|
|
* Secret Service. This session is used to transfer secrets.
|
|
|
|
*
|
|
|
|
* It is not normally necessary to call this method, as the session is
|
|
|
|
* established as necessary. You can also pass the %SECRET_SERVICE_OPEN_SESSION
|
|
|
|
* to secret_service_get_sync() in order to ensure that a session has been
|
|
|
|
* established by the time you get the #SecretService proxy.
|
|
|
|
*
|
|
|
|
* This method may block indefinitely and should not be used in user interface
|
|
|
|
* threads.
|
|
|
|
*
|
2012-07-06 07:01:20 +00:00
|
|
|
* Returns: whether a session is established or not
|
2012-02-02 12:40:47 +00:00
|
|
|
*/
|
2012-07-06 07:01:20 +00:00
|
|
|
gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_ensure_session_sync (SecretService *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2011-09-25 06:22:36 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretSync *sync;
|
2012-07-06 07:01:20 +00:00
|
|
|
gboolean ret;
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-07-06 07:01:20 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_SERVICE (self), FALSE);
|
|
|
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
sync = _secret_sync_new ();
|
2012-01-20 14:10:35 +00:00
|
|
|
g_main_context_push_thread_default (sync->context);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_ensure_session (self, cancellable,
|
2012-02-02 12:40:47 +00:00
|
|
|
_secret_sync_on_result, sync);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-01-20 14:10:35 +00:00
|
|
|
g_main_loop_run (sync->loop);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-07-06 07:01:20 +00:00
|
|
|
ret = secret_service_ensure_session_finish (self, sync->result, error);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-01-20 14:10:35 +00:00
|
|
|
g_main_context_pop_thread_default (sync->context);
|
2012-02-01 12:34:08 +00:00
|
|
|
_secret_sync_free (sync);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-07-06 07:01:20 +00:00
|
|
|
return ret;
|
2011-09-25 06:22:36 +00:00
|
|
|
}
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
static SecretCollection *
|
|
|
|
service_lookup_collection (SecretService *self,
|
2012-01-25 13:26:52 +00:00
|
|
|
const gchar *path)
|
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretCollection *collection = NULL;
|
2012-01-25 13:26:52 +00:00
|
|
|
|
|
|
|
g_mutex_lock (&self->pv->mutex);
|
|
|
|
|
|
|
|
if (self->pv->collections) {
|
|
|
|
collection = g_hash_table_lookup (self->pv->collections, path);
|
|
|
|
if (collection != NULL)
|
|
|
|
g_object_ref (collection);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_mutex_unlock (&self->pv->mutex);
|
|
|
|
|
|
|
|
return collection;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
service_update_collections (SecretService *self,
|
2012-01-25 13:26:52 +00:00
|
|
|
GHashTable *collections)
|
|
|
|
{
|
|
|
|
GHashTable *previous;
|
|
|
|
|
|
|
|
g_hash_table_ref (collections);
|
|
|
|
|
|
|
|
g_mutex_lock (&self->pv->mutex);
|
|
|
|
|
|
|
|
previous = self->pv->collections;
|
|
|
|
self->pv->collections = collections;
|
|
|
|
|
|
|
|
g_mutex_unlock (&self->pv->mutex);
|
|
|
|
|
|
|
|
if (previous != NULL)
|
|
|
|
g_hash_table_unref (previous);
|
2012-06-27 14:33:22 +00:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (self), "collections");
|
2012-01-25 13:26:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
GCancellable *cancellable;
|
|
|
|
GHashTable *collections;
|
|
|
|
gint collections_loading;
|
|
|
|
} EnsureClosure;
|
|
|
|
|
|
|
|
static GHashTable *
|
|
|
|
collections_table_new (void)
|
|
|
|
{
|
|
|
|
return g_hash_table_new_full (g_str_hash, g_str_equal,
|
|
|
|
g_free, g_object_unref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ensure_closure_free (gpointer data)
|
|
|
|
{
|
|
|
|
EnsureClosure *closure = data;
|
|
|
|
g_clear_object (&closure->cancellable);
|
|
|
|
g_hash_table_unref (closure->collections);
|
|
|
|
g_slice_free (EnsureClosure, closure);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_ensure_collection (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *self = SECRET_SERVICE (g_async_result_get_source_object (user_data));
|
2012-01-25 13:26:52 +00:00
|
|
|
EnsureClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretCollection *collection;
|
2012-01-25 13:26:52 +00:00
|
|
|
const gchar *path;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
closure->collections_loading--;
|
|
|
|
|
2012-07-06 07:01:20 +00:00
|
|
|
collection = secret_collection_new_for_dbus_path_finish (result, &error);
|
2012-01-25 13:26:52 +00:00
|
|
|
|
|
|
|
if (error != NULL)
|
|
|
|
g_simple_async_result_take_error (res, error);
|
|
|
|
|
|
|
|
if (collection != NULL) {
|
2012-06-27 14:43:14 +00:00
|
|
|
path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection));
|
2012-01-25 13:26:52 +00:00
|
|
|
g_hash_table_insert (closure->collections, g_strdup (path), collection);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (closure->collections_loading == 0) {
|
|
|
|
service_update_collections (self, closure->collections);
|
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (self);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
2012-07-05 19:26:20 +00:00
|
|
|
* secret_service_load_collections:
|
2012-02-02 12:40:47 +00:00
|
|
|
* @self: the secret service
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @callback: called when the operation completes
|
|
|
|
* @user_data: data to be passed to the callback
|
|
|
|
*
|
|
|
|
* Ensure that the #SecretService proxy has loaded all the collections present
|
|
|
|
* in the Secret Service. This affects the result of
|
|
|
|
* secret_service_get_collections().
|
|
|
|
*
|
|
|
|
* You can also pass the %SECRET_SERVICE_LOAD_COLLECTIONS to
|
|
|
|
* secret_service_get_sync() in order to ensure that the collections have been
|
|
|
|
* loaded by the time you get the #SecretService proxy.
|
|
|
|
*
|
|
|
|
* This method will return immediately and complete asynchronously.
|
|
|
|
*/
|
2012-01-23 16:20:18 +00:00
|
|
|
void
|
2012-07-05 19:26:20 +00:00
|
|
|
secret_service_load_collections (SecretService *self,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2011-09-25 06:22:36 +00:00
|
|
|
{
|
2012-01-25 13:26:52 +00:00
|
|
|
EnsureClosure *closure;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretCollection *collection;
|
2012-01-23 16:20:18 +00:00
|
|
|
GSimpleAsyncResult *res;
|
2012-01-25 13:26:52 +00:00
|
|
|
const gchar *path;
|
|
|
|
GVariant *paths;
|
|
|
|
GVariantIter iter;
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_if_fail (SECRET_IS_SERVICE (self));
|
2012-01-23 16:20:18 +00:00
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
paths = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self), "Collections");
|
2012-01-26 13:34:37 +00:00
|
|
|
g_return_if_fail (paths != NULL);
|
2012-01-25 13:26:52 +00:00
|
|
|
|
|
|
|
res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
|
2012-07-05 19:26:20 +00:00
|
|
|
secret_service_load_collections);
|
2012-01-25 13:26:52 +00:00
|
|
|
closure = g_slice_new0 (EnsureClosure);
|
|
|
|
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
|
|
|
closure->collections = collections_table_new ();
|
|
|
|
g_simple_async_result_set_op_res_gpointer (res, closure, ensure_closure_free);
|
|
|
|
|
|
|
|
g_variant_iter_init (&iter, paths);
|
|
|
|
while (g_variant_iter_loop (&iter, "&o", &path)) {
|
|
|
|
collection = service_lookup_collection (self, path);
|
|
|
|
|
|
|
|
/* No such collection yet create a new one */
|
|
|
|
if (collection == NULL) {
|
2012-07-06 07:01:20 +00:00
|
|
|
secret_collection_new_for_dbus_path (self, path, SECRET_COLLECTION_LOAD_ITEMS,
|
|
|
|
cancellable, on_ensure_collection, g_object_ref (res));
|
2012-01-25 13:26:52 +00:00
|
|
|
closure->collections_loading++;
|
|
|
|
} else {
|
|
|
|
g_hash_table_insert (closure->collections, g_strdup (path), collection);
|
|
|
|
}
|
|
|
|
}
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
if (closure->collections_loading == 0) {
|
|
|
|
service_update_collections (self, closure->collections);
|
|
|
|
g_simple_async_result_complete_in_idle (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_variant_unref (paths);
|
|
|
|
g_object_unref (res);
|
2011-09-25 06:22:36 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
2012-07-05 19:26:20 +00:00
|
|
|
* secret_service_load_collections_finish:
|
2012-02-02 12:40:47 +00:00
|
|
|
* @self: the secret service
|
|
|
|
* @result: the asynchronous result passed to the callback
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Complete an asynchronous operation to ensure that the #SecretService proxy
|
|
|
|
* has loaded all the collections present in the Secret Service.
|
|
|
|
*
|
|
|
|
* Returns: whether the load was successful or not
|
|
|
|
*/
|
2012-01-23 16:20:18 +00:00
|
|
|
gboolean
|
2012-07-05 19:26:20 +00:00
|
|
|
secret_service_load_collections_finish (SecretService *self,
|
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
2011-09-25 06:22:36 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_SERVICE (self), FALSE);
|
2012-01-23 16:20:18 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
|
2012-07-05 19:26:20 +00:00
|
|
|
secret_service_load_collections), FALSE);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
|
|
|
|
return FALSE;
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
return TRUE;
|
2011-09-25 06:22:36 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
2012-07-05 19:26:20 +00:00
|
|
|
* secret_service_load_collections_sync:
|
2012-02-02 12:40:47 +00:00
|
|
|
* @self: the secret service
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Ensure that the #SecretService proxy has loaded all the collections present
|
|
|
|
* in the Secret Service. This affects the result of
|
|
|
|
* secret_service_get_collections().
|
|
|
|
*
|
|
|
|
* You can also pass the %SECRET_SERVICE_LOAD_COLLECTIONS to
|
|
|
|
* secret_service_get_sync() in order to ensure that the collections have been
|
|
|
|
* loaded by the time you get the #SecretService proxy.
|
|
|
|
*
|
|
|
|
* This method may block indefinitely and should not be used in user interface
|
|
|
|
* threads.
|
|
|
|
*
|
|
|
|
* Returns: whether the load was successful or not
|
|
|
|
*/
|
2012-01-23 16:20:18 +00:00
|
|
|
gboolean
|
2012-07-05 19:26:20 +00:00
|
|
|
secret_service_load_collections_sync (SecretService *self,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2011-09-25 06:22:36 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretCollection *collection;
|
2012-01-25 13:26:52 +00:00
|
|
|
GHashTable *collections;
|
|
|
|
GVariant *paths;
|
|
|
|
GVariantIter iter;
|
|
|
|
const gchar *path;
|
|
|
|
gboolean ret = TRUE;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_SERVICE (self), FALSE);
|
2012-01-23 16:20:18 +00:00
|
|
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
paths = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self), "Collections");
|
2012-01-26 13:34:37 +00:00
|
|
|
g_return_val_if_fail (paths != NULL, FALSE);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
collections = collections_table_new ();
|
|
|
|
|
|
|
|
g_variant_iter_init (&iter, paths);
|
|
|
|
while (g_variant_iter_next (&iter, "&o", &path)) {
|
|
|
|
collection = service_lookup_collection (self, path);
|
|
|
|
|
|
|
|
/* No such collection yet create a new one */
|
|
|
|
if (collection == NULL) {
|
2012-07-06 07:01:20 +00:00
|
|
|
collection = secret_collection_new_for_dbus_path_sync (self, path,
|
|
|
|
SECRET_COLLECTION_LOAD_ITEMS,
|
|
|
|
cancellable, error);
|
2012-01-25 13:26:52 +00:00
|
|
|
if (collection == NULL) {
|
|
|
|
ret = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_hash_table_insert (collections, g_strdup (path), collection);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
service_update_collections (self, collections);
|
|
|
|
|
|
|
|
g_hash_table_unref (collections);
|
|
|
|
g_variant_unref (paths);
|
|
|
|
return ret;
|
2011-09-25 06:22:36 +00:00
|
|
|
}
|
2011-11-05 19:59:00 +00:00
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_service_prompt_sync:
|
|
|
|
* @self: the secret service
|
|
|
|
* @prompt: the prompt
|
|
|
|
* @cancellable: optional cancellation object
|
2012-04-29 19:34:40 +00:00
|
|
|
* @return_type: the variant type of the prompt result
|
2012-02-02 12:40:47 +00:00
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Perform prompting for a #SecretPrompt.
|
|
|
|
*
|
2012-04-29 19:34:40 +00:00
|
|
|
* Runs a prompt and performs the prompting. Returns a variant result if the
|
|
|
|
* prompt was completed and not dismissed. The type of result depends on the
|
|
|
|
* action the prompt is completing, and is defined in the Secret Service DBus
|
|
|
|
* API specification.
|
|
|
|
*
|
2012-02-02 12:40:47 +00:00
|
|
|
* This function is called by other parts of this library to handle prompts
|
|
|
|
* for the various actions that can require prompting.
|
|
|
|
*
|
2012-03-17 13:25:50 +00:00
|
|
|
* Override the #SecretServiceClass <literal>prompt_sync</literal> virtual method
|
2012-02-02 12:40:47 +00:00
|
|
|
* to change the behavior of the propmting. The default behavior is to simply
|
|
|
|
* run secret_prompt_perform_sync() on the prompt.
|
|
|
|
*
|
2012-04-29 19:34:40 +00:00
|
|
|
* Returns: (transfer full): %NULL if the prompt was dismissed or an error occurred,
|
|
|
|
* a variant result if the prompt was successful
|
2012-02-02 12:40:47 +00:00
|
|
|
*/
|
2012-04-29 19:34:40 +00:00
|
|
|
GVariant *
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_prompt_sync (SecretService *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
SecretPrompt *prompt,
|
|
|
|
GCancellable *cancellable,
|
2012-04-29 19:34:40 +00:00
|
|
|
const GVariantType *return_type,
|
2012-02-02 12:40:47 +00:00
|
|
|
GError **error)
|
2011-11-05 19:59:00 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretServiceClass *klass;
|
2011-11-05 19:59:00 +00:00
|
|
|
|
2012-04-29 19:34:40 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_SERVICE (self), NULL);
|
|
|
|
g_return_val_if_fail (SECRET_IS_PROMPT (prompt), NULL);
|
|
|
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
2011-11-05 19:59:00 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
klass = SECRET_SERVICE_GET_CLASS (self);
|
2012-04-29 19:34:40 +00:00
|
|
|
g_return_val_if_fail (klass->prompt_sync != NULL, NULL);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-04-29 19:34:40 +00:00
|
|
|
return (klass->prompt_sync) (self, prompt, cancellable, return_type, error);
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_service_prompt:
|
|
|
|
* @self: the secret service
|
|
|
|
* @prompt: the prompt
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @callback: called when the operation completes
|
|
|
|
* @user_data: data to be passed to the callback
|
|
|
|
*
|
|
|
|
* Perform prompting for a #SecretPrompt.
|
|
|
|
*
|
|
|
|
* This function is called by other parts of this library to handle prompts
|
|
|
|
* for the various actions that can require prompting.
|
|
|
|
*
|
2012-03-17 13:25:50 +00:00
|
|
|
* Override the #SecretServiceClass <literal>prompt_async</literal> virtual method
|
2012-02-02 12:40:47 +00:00
|
|
|
* to change the behavior of the propmting. The default behavior is to simply
|
|
|
|
* run secret_prompt_perform() on the prompt.
|
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_prompt (SecretService *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
SecretPrompt *prompt,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretServiceClass *klass;
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_if_fail (SECRET_IS_SERVICE (self));
|
|
|
|
g_return_if_fail (SECRET_IS_PROMPT (prompt));
|
2012-01-20 14:10:35 +00:00
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
klass = SECRET_SERVICE_GET_CLASS (self);
|
2012-01-26 14:34:26 +00:00
|
|
|
g_return_if_fail (klass->prompt_async != NULL);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-01-26 14:34:26 +00:00
|
|
|
(klass->prompt_async) (self, prompt, cancellable, callback, user_data);
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_service_prompt_finish:
|
|
|
|
* @self: the secret service
|
|
|
|
* @result: the asynchronous result passed to the callback
|
2012-04-29 19:34:40 +00:00
|
|
|
* @return_type: the variant type of the prompt result
|
2012-02-02 12:40:47 +00:00
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Complete asynchronous operation to perform prompting for a #SecretPrompt.
|
|
|
|
*
|
2012-04-29 19:34:40 +00:00
|
|
|
* Returns a variant result if the prompt was completed and not dismissed. The
|
|
|
|
* type of result depends on the action the prompt is completing, and is defined
|
|
|
|
* in the Secret Service DBus API specification.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): %NULL if the prompt was dismissed or an error occurred,
|
|
|
|
* a variant result if the prompt was successful
|
2012-02-02 12:40:47 +00:00
|
|
|
*/
|
2012-04-29 19:34:40 +00:00
|
|
|
GVariant *
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_prompt_finish (SecretService *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
GAsyncResult *result,
|
2012-04-29 19:34:40 +00:00
|
|
|
const GVariantType *return_type,
|
2012-02-02 12:40:47 +00:00
|
|
|
GError **error)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretServiceClass *klass;
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-04-29 19:34:40 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_SERVICE (self), NULL);
|
|
|
|
g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
klass = SECRET_SERVICE_GET_CLASS (self);
|
2012-04-29 19:34:40 +00:00
|
|
|
g_return_val_if_fail (klass->prompt_finish != NULL, NULL);
|
|
|
|
|
|
|
|
return (klass->prompt_finish) (self, result, return_type, error);
|
|
|
|
}
|