mirror of
https://gitlab.gnome.org/GNOME/libsecret.git
synced 2024-12-22 12:48:51 +00:00
Implement CreateCollection and CreateItem and related
This commit is contained in:
parent
97dca30728
commit
45705b781b
@ -665,6 +665,162 @@ gsecret_collection_refresh (GSecretCollection *self)
|
|||||||
self->pv->cancellable, NULL, NULL);
|
self->pv->cancellable, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
GCancellable *cancellable;
|
||||||
|
GSecretCollection *collection;
|
||||||
|
} CreateClosure;
|
||||||
|
|
||||||
|
static void
|
||||||
|
create_closure_free (gpointer data)
|
||||||
|
{
|
||||||
|
CreateClosure *closure = data;
|
||||||
|
g_clear_object (&closure->cancellable);
|
||||||
|
g_clear_object (&closure->collection);
|
||||||
|
g_slice_free (CreateClosure, closure);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
on_create_collection (GObject *source,
|
||||||
|
GAsyncResult *result,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
||||||
|
CreateClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
|
closure->collection = gsecret_collection_new_finish (result, &error);
|
||||||
|
if (error != NULL)
|
||||||
|
g_simple_async_result_take_error (res, error);
|
||||||
|
|
||||||
|
g_simple_async_result_complete (res);
|
||||||
|
g_object_unref (res);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
on_create_path (GObject *source,
|
||||||
|
GAsyncResult *result,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
||||||
|
CreateClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
||||||
|
GSecretService *service = GSECRET_SERVICE (source);
|
||||||
|
GError *error = NULL;
|
||||||
|
gchar *path;
|
||||||
|
|
||||||
|
path = gsecret_service_create_collection_path_finish (service, result, &error);
|
||||||
|
if (error == NULL) {
|
||||||
|
gsecret_collection_new (service, path, closure->cancellable,
|
||||||
|
on_create_collection, g_object_ref (res));
|
||||||
|
} else {
|
||||||
|
g_simple_async_result_take_error (res, error);
|
||||||
|
g_simple_async_result_complete (res);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_object_unref (res);
|
||||||
|
}
|
||||||
|
|
||||||
|
static GHashTable *
|
||||||
|
collection_properties_new (const gchar *label)
|
||||||
|
{
|
||||||
|
GHashTable *properties;
|
||||||
|
GVariant *value;
|
||||||
|
|
||||||
|
properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
|
||||||
|
(GDestroyNotify)g_variant_unref);
|
||||||
|
value = g_variant_new_string (label);
|
||||||
|
g_hash_table_insert (properties,
|
||||||
|
GSECRET_COLLECTION_INTERFACE "Label",
|
||||||
|
g_variant_ref_sink (value));
|
||||||
|
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gsecret_collection_create (GSecretService *service,
|
||||||
|
const gchar *label,
|
||||||
|
const gchar *alias,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GSimpleAsyncResult *res;
|
||||||
|
CreateClosure *closure;
|
||||||
|
GHashTable *properties;
|
||||||
|
|
||||||
|
g_return_if_fail (GSECRET_IS_SERVICE (service));
|
||||||
|
g_return_if_fail (label != NULL);
|
||||||
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
||||||
|
|
||||||
|
res = g_simple_async_result_new (NULL, callback, user_data,
|
||||||
|
gsecret_collection_create);
|
||||||
|
closure = g_slice_new0 (CreateClosure);
|
||||||
|
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
||||||
|
g_simple_async_result_set_op_res_gpointer (res, closure, create_closure_free);
|
||||||
|
|
||||||
|
properties = collection_properties_new (label);
|
||||||
|
|
||||||
|
gsecret_service_create_collection_path (service, properties, alias, cancellable,
|
||||||
|
on_create_path, g_object_ref (res));
|
||||||
|
|
||||||
|
g_hash_table_unref (properties);
|
||||||
|
g_object_unref (res);
|
||||||
|
}
|
||||||
|
|
||||||
|
GSecretCollection *
|
||||||
|
gsecret_collection_create_finish (GAsyncResult *result,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
GSimpleAsyncResult *res;
|
||||||
|
CreateClosure *closure;
|
||||||
|
|
||||||
|
g_return_val_if_fail (g_simple_async_result_is_valid (result, NULL,
|
||||||
|
gsecret_collection_create), NULL);
|
||||||
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||||
|
|
||||||
|
res = G_SIMPLE_ASYNC_RESULT (result);
|
||||||
|
|
||||||
|
if (g_simple_async_result_propagate_error (res, error))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
closure = g_simple_async_result_get_op_res_gpointer (res);
|
||||||
|
if (closure->collection == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return g_object_ref (closure->collection);
|
||||||
|
}
|
||||||
|
|
||||||
|
GSecretCollection *
|
||||||
|
gsecret_collection_create_sync (GSecretService *service,
|
||||||
|
const gchar *label,
|
||||||
|
const gchar *alias,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
GSecretCollection *collection;
|
||||||
|
GHashTable *properties;
|
||||||
|
gchar *path;
|
||||||
|
|
||||||
|
g_return_val_if_fail (GSECRET_IS_SERVICE (service), NULL);
|
||||||
|
g_return_val_if_fail (label != NULL, NULL);
|
||||||
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
|
||||||
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||||
|
|
||||||
|
properties = collection_properties_new (label);
|
||||||
|
|
||||||
|
path = gsecret_service_create_collection_path_sync (service, properties, alias,
|
||||||
|
cancellable, error);
|
||||||
|
|
||||||
|
g_hash_table_unref (properties);
|
||||||
|
|
||||||
|
if (path == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
collection = gsecret_collection_new_sync (service, path, cancellable, error);
|
||||||
|
g_free (path);
|
||||||
|
|
||||||
|
return collection;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gsecret_collection_delete (GSecretCollection *self,
|
gsecret_collection_delete (GSecretCollection *self,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
|
@ -57,6 +57,22 @@ GSecretCollection * gsecret_collection_new_sync (GSecretService
|
|||||||
|
|
||||||
void gsecret_collection_refresh (GSecretCollection *self);
|
void gsecret_collection_refresh (GSecretCollection *self);
|
||||||
|
|
||||||
|
void gsecret_collection_create (GSecretService *service,
|
||||||
|
const gchar *label,
|
||||||
|
const gchar *alias,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer user_data);
|
||||||
|
|
||||||
|
GSecretCollection * gsecret_collection_create_finish (GAsyncResult *result,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
|
GSecretCollection * gsecret_collection_create_sync (GSecretService *service,
|
||||||
|
const gchar *label,
|
||||||
|
const gchar *alias,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
void gsecret_collection_delete (GSecretCollection *self,
|
void gsecret_collection_delete (GSecretCollection *self,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "gsecret-collection.h"
|
||||||
#include "gsecret-dbus-generated.h"
|
#include "gsecret-dbus-generated.h"
|
||||||
#include "gsecret-item.h"
|
#include "gsecret-item.h"
|
||||||
#include "gsecret-private.h"
|
#include "gsecret-private.h"
|
||||||
@ -26,6 +27,7 @@ enum {
|
|||||||
PROP_SERVICE,
|
PROP_SERVICE,
|
||||||
PROP_ATTRIBUTES,
|
PROP_ATTRIBUTES,
|
||||||
PROP_LABEL,
|
PROP_LABEL,
|
||||||
|
PROP_SCHEMA,
|
||||||
PROP_LOCKED,
|
PROP_LOCKED,
|
||||||
PROP_CREATED,
|
PROP_CREATED,
|
||||||
PROP_MODIFIED
|
PROP_MODIFIED
|
||||||
@ -141,6 +143,9 @@ gsecret_item_get_property (GObject *obj,
|
|||||||
case PROP_LABEL:
|
case PROP_LABEL:
|
||||||
g_value_take_string (value, gsecret_item_get_label (self));
|
g_value_take_string (value, gsecret_item_get_label (self));
|
||||||
break;
|
break;
|
||||||
|
case PROP_SCHEMA:
|
||||||
|
g_value_take_string (value, gsecret_item_get_schema (self));
|
||||||
|
break;
|
||||||
case PROP_LOCKED:
|
case PROP_LOCKED:
|
||||||
g_value_set_boolean (value, gsecret_item_get_locked (self));
|
g_value_set_boolean (value, gsecret_item_get_locked (self));
|
||||||
break;
|
break;
|
||||||
@ -190,6 +195,9 @@ handle_property_changed (GObject *object,
|
|||||||
else if (g_str_equal (property_name, "Label"))
|
else if (g_str_equal (property_name, "Label"))
|
||||||
g_object_notify (object, "label");
|
g_object_notify (object, "label");
|
||||||
|
|
||||||
|
else if (g_str_equal (property_name, "Schema"))
|
||||||
|
g_object_notify (object, "schema");
|
||||||
|
|
||||||
else if (g_str_equal (property_name, "Locked"))
|
else if (g_str_equal (property_name, "Locked"))
|
||||||
g_object_notify (object, "locked");
|
g_object_notify (object, "locked");
|
||||||
|
|
||||||
@ -244,6 +252,10 @@ gsecret_item_class_init (GSecretItemClass *klass)
|
|||||||
g_param_spec_string ("label", "Label", "Item label",
|
g_param_spec_string ("label", "Label", "Item label",
|
||||||
NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
|
g_object_class_install_property (gobject_class, PROP_SCHEMA,
|
||||||
|
g_param_spec_string ("schema", "Schema", "Item schema",
|
||||||
|
NULL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
g_object_class_install_property (gobject_class, PROP_LOCKED,
|
g_object_class_install_property (gobject_class, PROP_LOCKED,
|
||||||
g_param_spec_boolean ("locked", "Locked", "Item locked",
|
g_param_spec_boolean ("locked", "Locked", "Item locked",
|
||||||
TRUE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
TRUE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||||
@ -438,6 +450,198 @@ gsecret_item_refresh (GSecretItem *self)
|
|||||||
NULL, NULL, NULL);
|
NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
GCancellable *cancellable;
|
||||||
|
GSecretItem *item;
|
||||||
|
} CreateClosure;
|
||||||
|
|
||||||
|
static void
|
||||||
|
create_closure_free (gpointer data)
|
||||||
|
{
|
||||||
|
CreateClosure *closure = data;
|
||||||
|
g_clear_object (&closure->cancellable);
|
||||||
|
g_clear_object (&closure->item);
|
||||||
|
g_slice_free (CreateClosure, closure);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
on_create_item (GObject *source,
|
||||||
|
GAsyncResult *result,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
||||||
|
CreateClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
|
closure->item = gsecret_item_new_finish (result, &error);
|
||||||
|
if (error != NULL)
|
||||||
|
g_simple_async_result_take_error (res, error);
|
||||||
|
|
||||||
|
g_simple_async_result_complete (res);
|
||||||
|
g_object_unref (res);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
on_create_path (GObject *source,
|
||||||
|
GAsyncResult *result,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
||||||
|
CreateClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
||||||
|
GSecretService *service = GSECRET_SERVICE (source);
|
||||||
|
GError *error = NULL;
|
||||||
|
gchar *path;
|
||||||
|
|
||||||
|
path = gsecret_service_create_item_path_finish (service, result, &error);
|
||||||
|
if (error == NULL) {
|
||||||
|
gsecret_item_new (service, path, closure->cancellable,
|
||||||
|
on_create_item, g_object_ref (res));
|
||||||
|
} else {
|
||||||
|
g_simple_async_result_take_error (res, error);
|
||||||
|
g_simple_async_result_complete (res);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_object_unref (res);
|
||||||
|
}
|
||||||
|
|
||||||
|
static GHashTable *
|
||||||
|
item_properties_new (const gchar *schema_name,
|
||||||
|
const gchar *label,
|
||||||
|
GHashTable *attributes)
|
||||||
|
{
|
||||||
|
GHashTable *properties;
|
||||||
|
GVariant *value;
|
||||||
|
|
||||||
|
properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
|
||||||
|
(GDestroyNotify)g_variant_unref);
|
||||||
|
|
||||||
|
value = g_variant_new_string (label);
|
||||||
|
g_hash_table_insert (properties,
|
||||||
|
GSECRET_COLLECTION_INTERFACE "Label",
|
||||||
|
g_variant_ref_sink (value));
|
||||||
|
|
||||||
|
value = g_variant_new_string (schema_name);
|
||||||
|
g_hash_table_insert (properties,
|
||||||
|
GSECRET_COLLECTION_INTERFACE "Schema",
|
||||||
|
g_variant_ref_sink (value));
|
||||||
|
|
||||||
|
value = _gsecret_util_variant_for_attributes (attributes);
|
||||||
|
g_hash_table_insert (properties,
|
||||||
|
GSECRET_COLLECTION_INTERFACE "Attributes",
|
||||||
|
g_variant_ref_sink (value));
|
||||||
|
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gsecret_item_create (GSecretCollection *collection,
|
||||||
|
const gchar *schema_name,
|
||||||
|
const gchar *label,
|
||||||
|
GHashTable *attributes,
|
||||||
|
GSecretValue *value,
|
||||||
|
gboolean replace,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GSecretService *service = NULL;
|
||||||
|
const gchar *collection_path;
|
||||||
|
GSimpleAsyncResult *res;
|
||||||
|
CreateClosure *closure;
|
||||||
|
GHashTable *properties;
|
||||||
|
|
||||||
|
g_return_if_fail (GSECRET_IS_COLLECTION (collection));
|
||||||
|
g_return_if_fail (label != NULL);
|
||||||
|
g_return_if_fail (attributes != NULL);
|
||||||
|
g_return_if_fail (value != NULL);
|
||||||
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
||||||
|
|
||||||
|
res = g_simple_async_result_new (NULL, callback, user_data,
|
||||||
|
gsecret_item_create);
|
||||||
|
closure = g_slice_new0 (CreateClosure);
|
||||||
|
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
||||||
|
g_simple_async_result_set_op_res_gpointer (res, closure, create_closure_free);
|
||||||
|
|
||||||
|
properties = item_properties_new (schema_name, label, attributes);
|
||||||
|
g_object_get (collection, "service", &service, NULL);
|
||||||
|
|
||||||
|
collection_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection));
|
||||||
|
|
||||||
|
gsecret_service_create_item_path (service, collection_path, properties,
|
||||||
|
value, replace, cancellable,
|
||||||
|
on_create_path, g_object_ref (res));
|
||||||
|
|
||||||
|
g_hash_table_unref (properties);
|
||||||
|
g_object_unref (service);
|
||||||
|
g_object_unref (res);
|
||||||
|
}
|
||||||
|
|
||||||
|
GSecretItem *
|
||||||
|
gsecret_item_create_finish (GAsyncResult *result,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
GSimpleAsyncResult *res;
|
||||||
|
CreateClosure *closure;
|
||||||
|
|
||||||
|
g_return_val_if_fail (g_simple_async_result_is_valid (result, NULL,
|
||||||
|
gsecret_item_create), NULL);
|
||||||
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||||
|
|
||||||
|
res = G_SIMPLE_ASYNC_RESULT (result);
|
||||||
|
|
||||||
|
if (g_simple_async_result_propagate_error (res, error))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
closure = g_simple_async_result_get_op_res_gpointer (res);
|
||||||
|
if (closure->item == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return g_object_ref (closure->item);
|
||||||
|
}
|
||||||
|
|
||||||
|
GSecretItem *
|
||||||
|
gsecret_item_create_sync (GSecretCollection *collection,
|
||||||
|
const gchar *schema_name,
|
||||||
|
const gchar *label,
|
||||||
|
GHashTable *attributes,
|
||||||
|
GSecretValue *value,
|
||||||
|
gboolean replace,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
GSecretService *service = NULL;
|
||||||
|
const gchar *collection_path;
|
||||||
|
GSecretItem *item = NULL;
|
||||||
|
GHashTable *properties;
|
||||||
|
gchar *path;
|
||||||
|
|
||||||
|
g_return_val_if_fail (GSECRET_IS_COLLECTION (collection), NULL);
|
||||||
|
g_return_val_if_fail (label != NULL, NULL);
|
||||||
|
g_return_val_if_fail (attributes != NULL, NULL);
|
||||||
|
g_return_val_if_fail (value != NULL, NULL);
|
||||||
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
|
||||||
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||||
|
|
||||||
|
properties = item_properties_new (schema_name, label, attributes);
|
||||||
|
g_object_get (collection, "service", &service, NULL);
|
||||||
|
|
||||||
|
collection_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection));
|
||||||
|
|
||||||
|
path = gsecret_service_create_item_path_sync (service, collection_path, properties,
|
||||||
|
value, replace, cancellable, error);
|
||||||
|
|
||||||
|
if (path != NULL) {
|
||||||
|
item = gsecret_item_new_sync (service, path, cancellable, error);
|
||||||
|
g_free (path);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_hash_table_unref (properties);
|
||||||
|
g_object_unref (service);
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
on_item_deleted (GObject *source,
|
on_item_deleted (GObject *source,
|
||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
@ -544,7 +748,9 @@ get_closure_free (gpointer data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
on_item_get_secret_ready (GObject *source, GAsyncResult *result, gpointer user_data)
|
on_item_get_secret (GObject *source,
|
||||||
|
GAsyncResult *result,
|
||||||
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
||||||
GSecretItem *self = GSECRET_ITEM (g_async_result_get_source_object (user_data));
|
GSecretItem *self = GSECRET_ITEM (g_async_result_get_source_object (user_data));
|
||||||
@ -576,7 +782,9 @@ on_item_get_secret_ready (GObject *source, GAsyncResult *result, gpointer user_d
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
on_service_ensure_session (GObject *source, GAsyncResult *result, gpointer user_data)
|
on_get_ensure_session (GObject *source,
|
||||||
|
GAsyncResult *result,
|
||||||
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
||||||
GSecretItem *self = GSECRET_ITEM (g_async_result_get_source_object (user_data));
|
GSecretItem *self = GSECRET_ITEM (g_async_result_get_source_object (user_data));
|
||||||
@ -594,9 +802,10 @@ on_service_ensure_session (GObject *source, GAsyncResult *result, gpointer user_
|
|||||||
g_dbus_proxy_call (G_DBUS_PROXY (self), "GetSecret",
|
g_dbus_proxy_call (G_DBUS_PROXY (self), "GetSecret",
|
||||||
g_variant_new ("(o)", session_path),
|
g_variant_new ("(o)", session_path),
|
||||||
G_DBUS_CALL_FLAGS_NONE, -1, closure->cancellable,
|
G_DBUS_CALL_FLAGS_NONE, -1, closure->cancellable,
|
||||||
on_item_get_secret_ready, g_object_ref (res));
|
on_item_get_secret, g_object_ref (res));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_object_unref (self);
|
||||||
g_object_unref (res);
|
g_object_unref (res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -619,7 +828,7 @@ gsecret_item_get_secret (GSecretItem *self,
|
|||||||
g_simple_async_result_set_op_res_gpointer (res, closure, get_closure_free);
|
g_simple_async_result_set_op_res_gpointer (res, closure, get_closure_free);
|
||||||
|
|
||||||
gsecret_service_ensure_session (self->pv->service, cancellable,
|
gsecret_service_ensure_session (self->pv->service, cancellable,
|
||||||
on_service_ensure_session,
|
on_get_ensure_session,
|
||||||
g_object_ref (res));
|
g_object_ref (res));
|
||||||
|
|
||||||
g_object_unref (res);
|
g_object_unref (res);
|
||||||
@ -671,6 +880,142 @@ gsecret_item_get_secret_sync (GSecretItem *self,
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
GCancellable *cancellable;
|
||||||
|
GSecretValue *value;
|
||||||
|
} SetClosure;
|
||||||
|
|
||||||
|
static void
|
||||||
|
set_closure_free (gpointer data)
|
||||||
|
{
|
||||||
|
GetClosure *closure = data;
|
||||||
|
g_clear_object (&closure->cancellable);
|
||||||
|
gsecret_value_unref (closure->value);
|
||||||
|
g_slice_free (GetClosure, closure);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
on_item_set_secret (GObject *source,
|
||||||
|
GAsyncResult *result,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
||||||
|
GError *error = NULL;
|
||||||
|
GVariant *retval;
|
||||||
|
|
||||||
|
retval = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), result, &error);
|
||||||
|
|
||||||
|
if (error != NULL)
|
||||||
|
g_simple_async_result_take_error (res, error);
|
||||||
|
if (retval != NULL)
|
||||||
|
g_variant_unref (retval);
|
||||||
|
|
||||||
|
g_simple_async_result_complete (res);
|
||||||
|
g_object_unref (res);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
on_set_ensure_session (GObject *source,
|
||||||
|
GAsyncResult *result,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
||||||
|
GSecretItem *self = GSECRET_ITEM (g_async_result_get_source_object (user_data));
|
||||||
|
SetClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
||||||
|
GSecretSession *session;
|
||||||
|
GVariant *encoded;
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
|
gsecret_service_ensure_session_finish (self->pv->service, result, &error);
|
||||||
|
if (error != NULL) {
|
||||||
|
g_simple_async_result_take_error (res, error);
|
||||||
|
g_simple_async_result_complete (res);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
session = _gsecret_service_get_session (self->pv->service);
|
||||||
|
encoded = _gsecret_session_encode_secret (session, closure->value);
|
||||||
|
g_dbus_proxy_call (G_DBUS_PROXY (self), "SetSecret",
|
||||||
|
g_variant_new ("(@(oayays))", encoded),
|
||||||
|
G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, closure->cancellable,
|
||||||
|
on_item_set_secret, g_object_ref (res));
|
||||||
|
}
|
||||||
|
|
||||||
|
g_object_unref (self);
|
||||||
|
g_object_unref (res);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gsecret_item_set_secret (GSecretItem *self,
|
||||||
|
GSecretValue *value,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GSimpleAsyncResult *res;
|
||||||
|
SetClosure *closure;
|
||||||
|
|
||||||
|
g_return_if_fail (GSECRET_IS_ITEM (self));
|
||||||
|
g_return_if_fail (value != NULL);
|
||||||
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
||||||
|
|
||||||
|
res = g_simple_async_result_new (G_OBJECT (self), callback,
|
||||||
|
user_data, gsecret_item_set_secret);
|
||||||
|
closure = g_slice_new0 (SetClosure);
|
||||||
|
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
||||||
|
g_simple_async_result_set_op_res_gpointer (res, closure, set_closure_free);
|
||||||
|
|
||||||
|
gsecret_service_ensure_session (self->pv->service, cancellable,
|
||||||
|
on_set_ensure_session,
|
||||||
|
g_object_ref (res));
|
||||||
|
|
||||||
|
g_object_unref (res);
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
gsecret_item_set_secret_finish (GSecretItem *self,
|
||||||
|
GAsyncResult *result,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
GSimpleAsyncResult *res;
|
||||||
|
|
||||||
|
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
|
||||||
|
gsecret_item_set_secret), FALSE);
|
||||||
|
|
||||||
|
res = G_SIMPLE_ASYNC_RESULT (result);
|
||||||
|
if (g_simple_async_result_propagate_error (res, error))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
gsecret_item_set_secret_sync (GSecretItem *self,
|
||||||
|
GSecretValue *value,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
GSecretSync *sync;
|
||||||
|
gboolean ret;
|
||||||
|
|
||||||
|
g_return_val_if_fail (GSECRET_IS_ITEM (self), FALSE);
|
||||||
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
|
||||||
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||||
|
|
||||||
|
sync = _gsecret_sync_new ();
|
||||||
|
g_main_context_push_thread_default (sync->context);
|
||||||
|
|
||||||
|
gsecret_item_set_secret (self, value, cancellable, _gsecret_sync_on_result, sync);
|
||||||
|
|
||||||
|
g_main_loop_run (sync->loop);
|
||||||
|
|
||||||
|
ret = gsecret_item_set_secret_finish (self, sync->result, error);
|
||||||
|
|
||||||
|
g_main_context_pop_thread_default (sync->context);
|
||||||
|
_gsecret_sync_free (sync);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
GHashTable *
|
GHashTable *
|
||||||
gsecret_item_get_attributes (GSecretItem *self)
|
gsecret_item_get_attributes (GSecretItem *self)
|
||||||
{
|
{
|
||||||
@ -730,6 +1075,23 @@ gsecret_item_set_attributes_sync (GSecretItem *self,
|
|||||||
cancellable, error);
|
cancellable, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gchar *
|
||||||
|
gsecret_item_get_schema (GSecretItem *self)
|
||||||
|
{
|
||||||
|
GVariant *variant;
|
||||||
|
gchar *label;
|
||||||
|
|
||||||
|
g_return_val_if_fail (GSECRET_IS_ITEM (self), NULL);
|
||||||
|
|
||||||
|
variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self), "Schema");
|
||||||
|
g_return_val_if_fail (variant != NULL, NULL);
|
||||||
|
|
||||||
|
label = g_variant_dup_string (variant, NULL);
|
||||||
|
g_variant_unref (variant);
|
||||||
|
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
gchar *
|
gchar *
|
||||||
gsecret_item_get_label (GSecretItem *self)
|
gsecret_item_get_label (GSecretItem *self)
|
||||||
{
|
{
|
||||||
|
@ -59,6 +59,28 @@ GSecretItem * gsecret_item_new_sync (GSecretService *ser
|
|||||||
|
|
||||||
void gsecret_item_refresh (GSecretItem *self);
|
void gsecret_item_refresh (GSecretItem *self);
|
||||||
|
|
||||||
|
void gsecret_item_create (GSecretCollection *collection,
|
||||||
|
const gchar *schema_name,
|
||||||
|
const gchar *label,
|
||||||
|
GHashTable *attributes,
|
||||||
|
GSecretValue *value,
|
||||||
|
gboolean replace,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer user_data);
|
||||||
|
|
||||||
|
GSecretItem * gsecret_item_create_finish (GAsyncResult *result,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
|
GSecretItem * gsecret_item_create_sync (GSecretCollection *collection,
|
||||||
|
const gchar *schema_name,
|
||||||
|
const gchar *label,
|
||||||
|
GHashTable *attributes,
|
||||||
|
GSecretValue *value,
|
||||||
|
gboolean replace,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
void gsecret_item_delete (GSecretItem *self,
|
void gsecret_item_delete (GSecretItem *self,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
@ -85,6 +107,21 @@ GSecretValue * gsecret_item_get_secret_sync (GSecretItem *self,
|
|||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
void gsecret_item_set_secret (GSecretItem *self,
|
||||||
|
GSecretValue *value,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer user_data);
|
||||||
|
|
||||||
|
gboolean gsecret_item_set_secret_finish (GSecretItem *self,
|
||||||
|
GAsyncResult *result,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
|
gboolean gsecret_item_set_secret_sync (GSecretItem *self,
|
||||||
|
GSecretValue *value,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
GHashTable* gsecret_item_get_attributes (GSecretItem *self);
|
GHashTable* gsecret_item_get_attributes (GSecretItem *self);
|
||||||
|
|
||||||
void gsecret_item_set_attributes (GSecretItem *self,
|
void gsecret_item_set_attributes (GSecretItem *self,
|
||||||
@ -119,6 +156,8 @@ gboolean gsecret_item_set_label_sync (GSecretItem *self,
|
|||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
gchar * gsecret_item_get_schema (GSecretItem *self);
|
||||||
|
|
||||||
gboolean gsecret_item_get_locked (GSecretItem *self);
|
gboolean gsecret_item_get_locked (GSecretItem *self);
|
||||||
|
|
||||||
guint64 gsecret_item_get_created (GSecretItem *self);
|
guint64 gsecret_item_get_created (GSecretItem *self);
|
||||||
|
@ -2053,3 +2053,399 @@ gsecret_service_removev_sync (GSecretService *self,
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
GCancellable *cancellable;
|
||||||
|
GSecretPrompt *prompt;
|
||||||
|
gchar *collection_path;
|
||||||
|
} CollectionClosure;
|
||||||
|
|
||||||
|
static void
|
||||||
|
collection_closure_free (gpointer data)
|
||||||
|
{
|
||||||
|
CollectionClosure *closure = data;
|
||||||
|
g_clear_object (&closure->cancellable);
|
||||||
|
g_clear_object (&closure->prompt);
|
||||||
|
|
||||||
|
g_slice_free (CollectionClosure, closure);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
on_create_collection_prompt (GObject *source,
|
||||||
|
GAsyncResult *result,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
||||||
|
CollectionClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
||||||
|
GError *error = NULL;
|
||||||
|
gboolean created;
|
||||||
|
GVariant *value;
|
||||||
|
|
||||||
|
created = gsecret_service_prompt_finish (GSECRET_SERVICE (source), result, &error);
|
||||||
|
if (error != NULL)
|
||||||
|
g_simple_async_result_take_error (res, error);
|
||||||
|
|
||||||
|
if (created) {
|
||||||
|
value = gsecret_prompt_get_result_value (closure->prompt, G_VARIANT_TYPE ("o"));
|
||||||
|
closure->collection_path = g_variant_dup_string (value, NULL);
|
||||||
|
g_variant_unref (value);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_simple_async_result_complete (res);
|
||||||
|
g_object_unref (res);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
on_create_collection_called (GObject *source,
|
||||||
|
GAsyncResult *result,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
||||||
|
CollectionClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
||||||
|
GSecretService *self = GSECRET_SERVICE (g_async_result_get_source_object (user_data));
|
||||||
|
const gchar *prompt_path = NULL;
|
||||||
|
const gchar *collection_path = NULL;
|
||||||
|
GError *error = NULL;
|
||||||
|
GVariant *retval;
|
||||||
|
|
||||||
|
retval = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), result, &error);
|
||||||
|
if (error == NULL) {
|
||||||
|
g_variant_get (retval, "(&o&o)", &collection_path, &prompt_path);
|
||||||
|
if (!_gsecret_util_empty_path (prompt_path)) {
|
||||||
|
closure->prompt = gsecret_prompt_instance (self, prompt_path);
|
||||||
|
gsecret_service_prompt (self, closure->prompt,
|
||||||
|
closure->cancellable, on_create_collection_prompt,
|
||||||
|
g_object_ref (res));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
closure->collection_path = g_strdup (collection_path);
|
||||||
|
g_simple_async_result_complete (res);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_variant_unref (retval);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
g_simple_async_result_take_error (res, error);
|
||||||
|
g_simple_async_result_complete (res);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_object_unref (self);
|
||||||
|
g_object_unref (res);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gsecret_service_create_collection_path (GSecretService *self,
|
||||||
|
GHashTable *properties,
|
||||||
|
const gchar *alias,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GSimpleAsyncResult *res;
|
||||||
|
CollectionClosure *closure;
|
||||||
|
GVariant *params;
|
||||||
|
GVariant *props;
|
||||||
|
GDBusProxy *proxy;
|
||||||
|
|
||||||
|
g_return_if_fail (GSECRET_IS_SERVICE (self));
|
||||||
|
g_return_if_fail (properties != NULL);
|
||||||
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
||||||
|
|
||||||
|
if (alias == NULL)
|
||||||
|
alias = "";
|
||||||
|
|
||||||
|
res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
|
||||||
|
gsecret_service_create_collection_path);
|
||||||
|
closure = g_new0 (CollectionClosure, 1);
|
||||||
|
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
||||||
|
g_simple_async_result_set_op_res_gpointer (res, closure, collection_closure_free);
|
||||||
|
|
||||||
|
props = _gsecret_util_variant_for_properties (properties);
|
||||||
|
params = g_variant_new ("(@a{sv}a)", props, alias);
|
||||||
|
proxy = G_DBUS_PROXY (self);
|
||||||
|
|
||||||
|
g_dbus_connection_call (g_dbus_proxy_get_connection (proxy),
|
||||||
|
g_dbus_proxy_get_name (proxy),
|
||||||
|
g_dbus_proxy_get_object_path (proxy),
|
||||||
|
GSECRET_SERVICE_INTERFACE,
|
||||||
|
"CreateCollection", params, G_VARIANT_TYPE ("(oo)"),
|
||||||
|
G_DBUS_CALL_FLAGS_NONE, -1,
|
||||||
|
closure->cancellable,
|
||||||
|
on_create_collection_called,
|
||||||
|
g_object_ref (res));
|
||||||
|
|
||||||
|
g_object_unref (res);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
gchar *
|
||||||
|
gsecret_service_create_collection_path_finish (GSecretService *self,
|
||||||
|
GAsyncResult *result,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
GSimpleAsyncResult *res;
|
||||||
|
CollectionClosure *closure;
|
||||||
|
gchar *path;
|
||||||
|
|
||||||
|
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
|
||||||
|
gsecret_collection_create), NULL);
|
||||||
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||||
|
|
||||||
|
res = G_SIMPLE_ASYNC_RESULT (result);
|
||||||
|
|
||||||
|
if (g_simple_async_result_propagate_error (res, error))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
closure = g_simple_async_result_get_op_res_gpointer (res);
|
||||||
|
path = closure->collection_path;
|
||||||
|
closure->collection_path = NULL;
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
gchar *
|
||||||
|
gsecret_service_create_collection_path_sync (GSecretService *self,
|
||||||
|
GHashTable *properties,
|
||||||
|
const gchar *alias,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
GSecretSync *sync;
|
||||||
|
gchar *path;
|
||||||
|
|
||||||
|
g_return_val_if_fail (GSECRET_IS_SERVICE (self), NULL);
|
||||||
|
g_return_val_if_fail (properties != NULL, NULL);
|
||||||
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
|
||||||
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||||
|
|
||||||
|
sync = _gsecret_sync_new ();
|
||||||
|
g_main_context_push_thread_default (sync->context);
|
||||||
|
|
||||||
|
gsecret_service_create_collection_path (self, properties, alias, cancellable,
|
||||||
|
_gsecret_sync_on_result, sync);
|
||||||
|
|
||||||
|
g_main_loop_run (sync->loop);
|
||||||
|
|
||||||
|
path = gsecret_service_create_collection_path_finish (self, sync->result, error);
|
||||||
|
|
||||||
|
g_main_context_pop_thread_default (sync->context);
|
||||||
|
_gsecret_sync_free (sync);
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
GCancellable *cancellable;
|
||||||
|
GVariant *properties;
|
||||||
|
GSecretValue *value;
|
||||||
|
gboolean replace;
|
||||||
|
gchar *collection_path;
|
||||||
|
GSecretPrompt *prompt;
|
||||||
|
gchar *item_path;
|
||||||
|
} ItemClosure;
|
||||||
|
|
||||||
|
static void
|
||||||
|
item_closure_free (gpointer data)
|
||||||
|
{
|
||||||
|
ItemClosure *closure = data;
|
||||||
|
g_variant_unref (closure->properties);
|
||||||
|
gsecret_value_unref (closure->value);
|
||||||
|
g_clear_object (&closure->cancellable);
|
||||||
|
g_free (closure->collection_path);
|
||||||
|
g_clear_object (&closure->prompt);
|
||||||
|
g_slice_free (ItemClosure, closure);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
on_create_item_prompt (GObject *source,
|
||||||
|
GAsyncResult *result,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
||||||
|
ItemClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
||||||
|
GError *error = NULL;
|
||||||
|
gboolean created;
|
||||||
|
GVariant *value;
|
||||||
|
|
||||||
|
created = gsecret_service_prompt_finish (GSECRET_SERVICE (source), result, &error);
|
||||||
|
if (error != NULL)
|
||||||
|
g_simple_async_result_take_error (res, error);
|
||||||
|
|
||||||
|
if (created) {
|
||||||
|
value = gsecret_prompt_get_result_value (closure->prompt, G_VARIANT_TYPE ("o"));
|
||||||
|
closure->item_path = g_variant_dup_string (value, NULL);
|
||||||
|
g_variant_unref (value);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_simple_async_result_complete (res);
|
||||||
|
g_object_unref (res);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
on_create_item_called (GObject *source,
|
||||||
|
GAsyncResult *result,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
||||||
|
ItemClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
||||||
|
GSecretService *self = GSECRET_SERVICE (g_async_result_get_source_object (user_data));
|
||||||
|
const gchar *prompt_path = NULL;
|
||||||
|
const gchar *item_path = NULL;
|
||||||
|
GError *error = NULL;
|
||||||
|
GVariant *retval;
|
||||||
|
|
||||||
|
retval = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), result, &error);
|
||||||
|
if (error == NULL) {
|
||||||
|
g_variant_get (retval, "(&o&o)", &item_path, &prompt_path);
|
||||||
|
if (!_gsecret_util_empty_path (prompt_path)) {
|
||||||
|
closure->prompt = gsecret_prompt_instance (self, prompt_path);
|
||||||
|
gsecret_service_prompt (self, closure->prompt,
|
||||||
|
closure->cancellable, on_create_item_prompt,
|
||||||
|
g_object_ref (res));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
closure->item_path = g_strdup (item_path);
|
||||||
|
g_simple_async_result_complete (res);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_variant_unref (retval);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
g_simple_async_result_take_error (res, error);
|
||||||
|
g_simple_async_result_complete (res);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_object_unref (self);
|
||||||
|
g_object_unref (res);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
on_create_item_session (GObject *source,
|
||||||
|
GAsyncResult *result,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
||||||
|
ItemClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
||||||
|
GSecretService *self = GSECRET_SERVICE (source);
|
||||||
|
GSecretSession *session;
|
||||||
|
GVariant *params;
|
||||||
|
GError *error = NULL;
|
||||||
|
GDBusProxy *proxy;
|
||||||
|
|
||||||
|
gsecret_service_ensure_session_finish (self, result, &error);
|
||||||
|
if (error == NULL) {
|
||||||
|
session = _gsecret_service_get_session (self);
|
||||||
|
params = g_variant_new ("@a{sv}@(oayays)b",
|
||||||
|
closure->properties,
|
||||||
|
_gsecret_session_encode_secret (session, closure->value),
|
||||||
|
closure->replace);
|
||||||
|
|
||||||
|
proxy = G_DBUS_PROXY (self);
|
||||||
|
g_dbus_connection_call (g_dbus_proxy_get_connection (proxy),
|
||||||
|
g_dbus_proxy_get_name (proxy),
|
||||||
|
closure->collection_path,
|
||||||
|
GSECRET_COLLECTION_INTERFACE,
|
||||||
|
"CreateItem", params, G_VARIANT_TYPE ("(oo)"),
|
||||||
|
G_DBUS_CALL_FLAGS_NONE, -1,
|
||||||
|
closure->cancellable,
|
||||||
|
on_create_item_called,
|
||||||
|
g_object_ref (res));
|
||||||
|
} else {
|
||||||
|
g_simple_async_result_take_error (res, error);
|
||||||
|
g_simple_async_result_complete (res);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_object_unref (res);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gsecret_service_create_item_path (GSecretService *self,
|
||||||
|
const gchar *collection_path,
|
||||||
|
GHashTable *properties,
|
||||||
|
GSecretValue *value,
|
||||||
|
gboolean replace,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GSimpleAsyncResult *res;
|
||||||
|
ItemClosure *closure;
|
||||||
|
|
||||||
|
g_return_if_fail (GSECRET_IS_SERVICE (self));
|
||||||
|
g_return_if_fail (properties != NULL);
|
||||||
|
g_return_if_fail (value != NULL);
|
||||||
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
||||||
|
|
||||||
|
res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
|
||||||
|
gsecret_service_create_item_path);
|
||||||
|
closure = g_new0 (ItemClosure, 1);
|
||||||
|
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
||||||
|
closure->properties = _gsecret_util_variant_for_properties (properties);
|
||||||
|
g_variant_ref_sink (closure->properties);
|
||||||
|
closure->replace = replace;
|
||||||
|
closure->value = gsecret_value_ref (value);
|
||||||
|
closure->collection_path = g_strdup (collection_path);
|
||||||
|
g_simple_async_result_set_op_res_gpointer (res, closure, item_closure_free);
|
||||||
|
|
||||||
|
gsecret_service_ensure_session (self, cancellable,
|
||||||
|
on_create_item_session,
|
||||||
|
g_object_ref (res));
|
||||||
|
|
||||||
|
g_object_unref (res);
|
||||||
|
}
|
||||||
|
|
||||||
|
gchar *
|
||||||
|
gsecret_service_create_item_path_finish (GSecretService *self,
|
||||||
|
GAsyncResult *result,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
GSimpleAsyncResult *res;
|
||||||
|
CollectionClosure *closure;
|
||||||
|
gchar *path;
|
||||||
|
|
||||||
|
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
|
||||||
|
gsecret_service_create_item_path), NULL);
|
||||||
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||||
|
|
||||||
|
res = G_SIMPLE_ASYNC_RESULT (result);
|
||||||
|
|
||||||
|
if (g_simple_async_result_propagate_error (res, error))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
closure = g_simple_async_result_get_op_res_gpointer (res);
|
||||||
|
path = closure->collection_path;
|
||||||
|
closure->collection_path = NULL;
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
gchar *
|
||||||
|
gsecret_service_create_item_path_sync (GSecretService *self,
|
||||||
|
const gchar *collection_path,
|
||||||
|
GHashTable *properties,
|
||||||
|
GSecretValue *value,
|
||||||
|
gboolean replace,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
GSecretSync *sync;
|
||||||
|
gchar *path;
|
||||||
|
|
||||||
|
g_return_val_if_fail (GSECRET_IS_SERVICE (self), NULL);
|
||||||
|
g_return_val_if_fail (properties != NULL, NULL);
|
||||||
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
|
||||||
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||||
|
|
||||||
|
sync = _gsecret_sync_new ();
|
||||||
|
g_main_context_push_thread_default (sync->context);
|
||||||
|
|
||||||
|
gsecret_service_create_item_path (self, collection_path, properties, value, replace,
|
||||||
|
cancellable, _gsecret_sync_on_result, sync);
|
||||||
|
|
||||||
|
g_main_loop_run (sync->loop);
|
||||||
|
|
||||||
|
path = gsecret_service_create_collection_path_finish (self, sync->result, error);
|
||||||
|
|
||||||
|
g_main_context_pop_thread_default (sync->context);
|
||||||
|
_gsecret_sync_free (sync);
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
@ -52,7 +52,7 @@ void _gsecret_sync_on_result (GObject *source,
|
|||||||
GSecretPrompt * _gsecret_prompt_instance (GDBusConnection *connection,
|
GSecretPrompt * _gsecret_prompt_instance (GDBusConnection *connection,
|
||||||
const gchar *object_path);
|
const gchar *object_path);
|
||||||
|
|
||||||
gchar * _gsecret_util_parent_path (const gchar *path);
|
gchar * _gsecret_util_parent_path (const gchar *path);
|
||||||
|
|
||||||
gboolean _gsecret_util_empty_path (const gchar *path);
|
gboolean _gsecret_util_empty_path (const gchar *path);
|
||||||
|
|
||||||
@ -65,6 +65,8 @@ GHashTable * _gsecret_util_attributes_for_variant (GVariant *varian
|
|||||||
GHashTable * _gsecret_util_attributes_for_varargs (const GSecretSchema *schema,
|
GHashTable * _gsecret_util_attributes_for_varargs (const GSecretSchema *schema,
|
||||||
va_list va);
|
va_list va);
|
||||||
|
|
||||||
|
GVariant * _gsecret_util_variant_for_properties (GHashTable *properties);
|
||||||
|
|
||||||
void _gsecret_util_get_properties (GDBusProxy *proxy,
|
void _gsecret_util_get_properties (GDBusProxy *proxy,
|
||||||
gpointer result_tag,
|
gpointer result_tag,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
|
@ -408,6 +408,44 @@ gboolean gsecret_service_removev_sync (GSecretServi
|
|||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
void gsecret_service_create_collection_path (GSecretService *self,
|
||||||
|
GHashTable *properties,
|
||||||
|
const gchar *alias,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer user_data);
|
||||||
|
|
||||||
|
gchar * gsecret_service_create_collection_path_finish (GSecretService *self,
|
||||||
|
GAsyncResult *result,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
|
gchar * gsecret_service_create_collection_path_sync (GSecretService *self,
|
||||||
|
GHashTable *properties,
|
||||||
|
const gchar *alias,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
|
void gsecret_service_create_item_path (GSecretService *self,
|
||||||
|
const gchar *collection_path,
|
||||||
|
GHashTable *properties,
|
||||||
|
GSecretValue *value,
|
||||||
|
gboolean replace,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer user_data);
|
||||||
|
|
||||||
|
gchar * gsecret_service_create_item_path_finish (GSecretService *self,
|
||||||
|
GAsyncResult *result,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
|
gchar * gsecret_service_create_item_path_sync (GSecretService *self,
|
||||||
|
const gchar *collection_path,
|
||||||
|
GHashTable *properties,
|
||||||
|
GSecretValue *value,
|
||||||
|
gboolean replace,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __GSECRET_SERVICE_H___ */
|
#endif /* __GSECRET_SERVICE_H___ */
|
||||||
|
@ -86,6 +86,25 @@ _gsecret_util_empty_path (const gchar *path)
|
|||||||
return (g_str_equal (path, "") || g_str_equal (path, "/"));
|
return (g_str_equal (path, "") || g_str_equal (path, "/"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GVariant *
|
||||||
|
_gsecret_util_variant_for_properties (GHashTable *properties)
|
||||||
|
{
|
||||||
|
GHashTableIter iter;
|
||||||
|
GVariantBuilder builder;
|
||||||
|
const gchar *name;
|
||||||
|
GVariant *value;
|
||||||
|
|
||||||
|
g_return_val_if_fail (properties != NULL, NULL);
|
||||||
|
|
||||||
|
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
|
||||||
|
|
||||||
|
g_hash_table_iter_init (&iter, properties);
|
||||||
|
while (g_hash_table_iter_next (&iter, (gpointer *)&name, (gpointer *)&value))
|
||||||
|
g_variant_builder_add (&builder, "{sv}", name, value);
|
||||||
|
|
||||||
|
return g_variant_builder_end (&builder);
|
||||||
|
}
|
||||||
|
|
||||||
GVariant *
|
GVariant *
|
||||||
_gsecret_util_variant_for_attributes (GHashTable *attributes)
|
_gsecret_util_variant_for_attributes (GHashTable *attributes)
|
||||||
{
|
{
|
||||||
@ -103,7 +122,6 @@ _gsecret_util_variant_for_attributes (GHashTable *attributes)
|
|||||||
g_variant_builder_add (&builder, "{ss}", name, value);
|
g_variant_builder_add (&builder, "{ss}", name, value);
|
||||||
|
|
||||||
return g_variant_builder_end (&builder);
|
return g_variant_builder_end (&builder);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GHashTable *
|
GHashTable *
|
||||||
|
Loading…
Reference in New Issue
Block a user