2012-02-01 12:34:08 +00:00
|
|
|
/* libsecret - GLib wrapper for Secret Service
|
2011-09-25 06:22:36 +00:00
|
|
|
*
|
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
|
|
|
|
* by the Free Software Foundation; either version 2 of the licence or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* See the included COPYING file for more information.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
#include "secret-collection.h"
|
|
|
|
#include "secret-dbus-generated.h"
|
|
|
|
#include "secret-item.h"
|
|
|
|
#include "secret-private.h"
|
|
|
|
#include "secret-service.h"
|
|
|
|
#include "secret-types.h"
|
|
|
|
#include "secret-value.h"
|
2011-09-25 06:22:36 +00:00
|
|
|
|
|
|
|
#include <glib/gi18n-lib.h>
|
|
|
|
|
2012-02-02 13:59:59 +00:00
|
|
|
/**
|
|
|
|
* SECTION:secret-item
|
|
|
|
* @title: SecretItem
|
|
|
|
* @short_description: A secret item
|
|
|
|
*
|
|
|
|
* #SecretItem represents a secret item stored in the Secret Service.
|
|
|
|
*
|
|
|
|
* Each item has a value, represented by a #SecretValue, which can be
|
2012-03-17 13:25:50 +00:00
|
|
|
* retrieved by secret_item_get_secret() or set by secret_item_set_secret().
|
2012-02-02 13:59:59 +00:00
|
|
|
* The item is only available when the item is not locked.
|
|
|
|
*
|
|
|
|
* Items can be locked or unlocked using the secret_service_lock() or
|
|
|
|
* secret_service_unlock() functions. The Secret Service may not be able to
|
|
|
|
* unlock individual items, and may unlock an entire collection when a single
|
|
|
|
* item is unlocked.
|
|
|
|
*
|
|
|
|
* Each item has a set of attributes, which are used to locate the item later.
|
|
|
|
* These are not stored or transferred in a secure manner. Each attribute has
|
|
|
|
* a string name and a string value. Use secret_service_search() to search for
|
|
|
|
* items based on their attributes, and secret_item_set_attributes to change
|
|
|
|
* the attributes associated with an item.
|
|
|
|
*
|
|
|
|
* Items can be created with secret_item_create() or secret_service_store().
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SecretItem:
|
|
|
|
*
|
|
|
|
* A proxy object representing a secret item in the Secret Service.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SecretItemClass:
|
|
|
|
* @parent_class: the parent class
|
|
|
|
*
|
|
|
|
* The class for #SecretItem.
|
|
|
|
*/
|
|
|
|
|
2012-01-20 14:10:35 +00:00
|
|
|
enum {
|
|
|
|
PROP_0,
|
2012-01-23 16:20:18 +00:00
|
|
|
PROP_SERVICE,
|
2012-01-20 14:10:35 +00:00
|
|
|
PROP_ATTRIBUTES,
|
|
|
|
PROP_LABEL,
|
2012-01-26 17:23:12 +00:00
|
|
|
PROP_SCHEMA,
|
2012-01-20 14:10:35 +00:00
|
|
|
PROP_LOCKED,
|
|
|
|
PROP_CREATED,
|
|
|
|
PROP_MODIFIED
|
2011-09-25 06:22:36 +00:00
|
|
|
};
|
|
|
|
|
2012-01-20 14:10:35 +00:00
|
|
|
/* Thread safe: no changes between construct and finalize */
|
2012-02-01 12:34:08 +00:00
|
|
|
typedef struct _SecretItemPrivate {
|
|
|
|
SecretService *service;
|
2012-01-20 14:10:35 +00:00
|
|
|
GCancellable *cancellable;
|
2012-02-01 12:34:08 +00:00
|
|
|
} SecretItemPrivate;
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
static GInitableIface *secret_item_initable_parent_iface = NULL;
|
2012-01-25 13:26:52 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
static GAsyncInitableIface *secret_item_async_initable_parent_iface = NULL;
|
2012-01-25 13:26:52 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
static void secret_item_initable_iface (GInitableIface *iface);
|
2012-01-25 13:26:52 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
static void secret_item_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 (SecretItem, secret_item, G_TYPE_DBUS_PROXY,
|
|
|
|
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, secret_item_initable_iface);
|
|
|
|
G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, secret_item_async_initable_iface);
|
2012-01-25 13:26:52 +00:00
|
|
|
);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_init (SecretItem *self)
|
2011-09-25 06:22:36 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
self->pv = G_TYPE_INSTANCE_GET_PRIVATE (self, SECRET_TYPE_ITEM, SecretItemPrivate);
|
2012-01-23 16:20:18 +00:00
|
|
|
self->pv->cancellable = g_cancellable_new ();
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_set_attributes (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *self = SECRET_ITEM (user_data);
|
2012-01-20 14:10:35 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_set_attributes_finish (self, result, &error);
|
2012-01-20 14:10:35 +00:00
|
|
|
if (error != NULL) {
|
2012-02-01 12:34:08 +00:00
|
|
|
g_warning ("couldn't set SecretItem Attributes: %s", error->message);
|
2012-01-20 14:10:35 +00:00
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (self);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_set_label (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *self = SECRET_ITEM (user_data);
|
2012-01-20 14:10:35 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_set_label_finish (self, result, &error);
|
2012-01-20 14:10:35 +00:00
|
|
|
if (error != NULL) {
|
2012-02-01 12:34:08 +00:00
|
|
|
g_warning ("couldn't set SecretItem Label: %s", error->message);
|
2012-01-20 14:10:35 +00:00
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (self);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_set_property (GObject *obj,
|
2012-02-02 12:40:47 +00:00
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *self = SECRET_ITEM (obj);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2012-01-23 16:20:18 +00:00
|
|
|
case PROP_SERVICE:
|
|
|
|
g_return_if_fail (self->pv->service == NULL);
|
|
|
|
self->pv->service = g_value_get_object (value);
|
|
|
|
if (self->pv->service)
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (self->pv->service),
|
|
|
|
(gpointer *)&self->pv->service);
|
|
|
|
break;
|
2012-01-20 14:10:35 +00:00
|
|
|
case PROP_ATTRIBUTES:
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_set_attributes (self, g_value_get_boxed (value),
|
2012-02-02 12:40:47 +00:00
|
|
|
self->pv->cancellable, on_set_attributes,
|
|
|
|
g_object_ref (self));
|
2012-01-20 14:10:35 +00:00
|
|
|
break;
|
|
|
|
case PROP_LABEL:
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_set_label (self, g_value_get_string (value),
|
2012-02-02 12:40:47 +00:00
|
|
|
self->pv->cancellable, on_set_label,
|
|
|
|
g_object_ref (self));
|
2012-01-20 14:10:35 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_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
|
|
|
SecretItem *self = SECRET_ITEM (obj);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2012-01-23 16:20:18 +00:00
|
|
|
case PROP_SERVICE:
|
|
|
|
g_value_set_object (value, self->pv->service);
|
|
|
|
break;
|
2012-01-20 14:10:35 +00:00
|
|
|
case PROP_ATTRIBUTES:
|
2012-02-01 12:34:08 +00:00
|
|
|
g_value_take_boxed (value, secret_item_get_attributes (self));
|
2012-01-20 14:10:35 +00:00
|
|
|
break;
|
|
|
|
case PROP_LABEL:
|
2012-02-01 12:34:08 +00:00
|
|
|
g_value_take_string (value, secret_item_get_label (self));
|
2012-01-20 14:10:35 +00:00
|
|
|
break;
|
2012-01-26 17:23:12 +00:00
|
|
|
case PROP_SCHEMA:
|
2012-02-01 12:34:08 +00:00
|
|
|
g_value_take_string (value, secret_item_get_schema (self));
|
2012-01-26 17:23:12 +00:00
|
|
|
break;
|
2012-01-20 14:10:35 +00:00
|
|
|
case PROP_LOCKED:
|
2012-02-01 12:34:08 +00:00
|
|
|
g_value_set_boolean (value, secret_item_get_locked (self));
|
2012-01-20 14:10:35 +00:00
|
|
|
break;
|
|
|
|
case PROP_CREATED:
|
2012-02-01 12:34:08 +00:00
|
|
|
g_value_set_uint64 (value, secret_item_get_created (self));
|
2012-01-20 14:10:35 +00:00
|
|
|
break;
|
|
|
|
case PROP_MODIFIED:
|
2012-02-01 12:34:08 +00:00
|
|
|
g_value_set_uint64 (value, secret_item_get_modified (self));
|
2012-01-20 14:10:35 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_dispose (GObject *obj)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *self = SECRET_ITEM (obj);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-01-23 16:20:18 +00:00
|
|
|
g_cancellable_cancel (self->pv->cancellable);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
G_OBJECT_CLASS (secret_item_parent_class)->dispose (obj);
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_finalize (GObject *obj)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *self = SECRET_ITEM (obj);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-01-23 16:20:18 +00:00
|
|
|
if (self->pv->service)
|
|
|
|
g_object_remove_weak_pointer (G_OBJECT (self->pv->service),
|
|
|
|
(gpointer *)&self->pv->service);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-01-23 16:20:18 +00:00
|
|
|
g_object_unref (self->pv->cancellable);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
G_OBJECT_CLASS (secret_item_parent_class)->finalize (obj);
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_property_changed (GObject *object,
|
|
|
|
const gchar *property_name)
|
|
|
|
{
|
|
|
|
if (g_str_equal (property_name, "Attributes"))
|
|
|
|
g_object_notify (object, "attributes");
|
|
|
|
|
|
|
|
else if (g_str_equal (property_name, "Label"))
|
|
|
|
g_object_notify (object, "label");
|
|
|
|
|
2012-01-31 19:20:31 +00:00
|
|
|
else if (g_str_equal (property_name, "Type"))
|
2012-01-26 17:23:12 +00:00
|
|
|
g_object_notify (object, "schema");
|
|
|
|
|
2012-01-20 14:10:35 +00:00
|
|
|
else if (g_str_equal (property_name, "Locked"))
|
|
|
|
g_object_notify (object, "locked");
|
|
|
|
|
|
|
|
else if (g_str_equal (property_name, "Created"))
|
|
|
|
g_object_notify (object, "created");
|
|
|
|
|
|
|
|
else if (g_str_equal (property_name, "Modified"))
|
|
|
|
g_object_notify (object, "modified");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_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
|
|
|
{
|
|
|
|
GObject *obj = G_OBJECT (proxy);
|
|
|
|
gchar *property_name;
|
|
|
|
GVariantIter iter;
|
|
|
|
GVariant *value;
|
|
|
|
|
|
|
|
g_object_freeze_notify (obj);
|
|
|
|
|
|
|
|
g_variant_iter_init (&iter, changed_properties);
|
|
|
|
while (g_variant_iter_loop (&iter, "{sv}", &property_name, &value))
|
|
|
|
handle_property_changed (obj, property_name);
|
|
|
|
|
|
|
|
g_object_thaw_notify (obj);
|
2011-09-25 06:22:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_class_init (SecretItemClass *klass)
|
2011-09-25 06:22:36 +00:00
|
|
|
{
|
2012-01-20 14:10:35 +00:00
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
GDBusProxyClass *proxy_class = G_DBUS_PROXY_CLASS (klass);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
gobject_class->get_property = secret_item_get_property;
|
|
|
|
gobject_class->set_property = secret_item_set_property;
|
|
|
|
gobject_class->dispose = secret_item_dispose;
|
|
|
|
gobject_class->finalize = secret_item_finalize;
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
proxy_class->g_properties_changed = secret_item_properties_changed;
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-02 13:59:59 +00:00
|
|
|
/**
|
|
|
|
* SecretItem:service:
|
|
|
|
*
|
|
|
|
* The #SecretService object that this item is associated with and
|
|
|
|
* uses to interact with the actual DBus Secret Service.
|
|
|
|
*/
|
2012-01-23 16:20:18 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_SERVICE,
|
|
|
|
g_param_spec_object ("service", "Service", "Secret Service",
|
2012-02-01 12:34:08 +00:00
|
|
|
SECRET_TYPE_SERVICE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
2012-01-23 16:20:18 +00:00
|
|
|
|
2012-02-02 13:59:59 +00:00
|
|
|
/**
|
|
|
|
* SecretItem:attributes:
|
|
|
|
*
|
|
|
|
* The attributes set on this item. Attributes are used to locate an
|
|
|
|
* item. They are not guaranteed to be stored or transferred securely.
|
|
|
|
*
|
|
|
|
* The schema describes which attributes should be present and their types.
|
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_ATTRIBUTES,
|
|
|
|
g_param_spec_boxed ("attributes", "Attributes", "Item attributes",
|
2012-01-23 16:20:18 +00:00
|
|
|
G_TYPE_HASH_TABLE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-02 13:59:59 +00:00
|
|
|
/**
|
|
|
|
* SecretItem:label:
|
|
|
|
*
|
|
|
|
* The human readable label for the item.
|
|
|
|
*
|
|
|
|
* Setting this property will result in the label of the item being
|
|
|
|
* set asynchronously. To properly track the changing of the label use the
|
|
|
|
* secret_item_set_label() function.
|
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_LABEL,
|
|
|
|
g_param_spec_string ("label", "Label", "Item label",
|
2012-01-23 16:20:18 +00:00
|
|
|
NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-02 13:59:59 +00:00
|
|
|
/**
|
|
|
|
* SecretItem:schema:
|
|
|
|
*
|
|
|
|
* The schema for this item. This is a dotted string that describes
|
|
|
|
* which attributes should be present and the types of values on
|
|
|
|
* those attributes.
|
|
|
|
*/
|
2012-01-26 17:23:12 +00:00
|
|
|
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));
|
|
|
|
|
2012-02-02 13:59:59 +00:00
|
|
|
/**
|
|
|
|
* SecretItem:locked:
|
|
|
|
*
|
|
|
|
* Whether the item is locked or not. An item may not be independently
|
|
|
|
* lockable separate from other items in its collection.
|
|
|
|
*
|
|
|
|
* To lock or unlock a item use the secret_service_lock() or
|
|
|
|
* secret_service_unlock() functions.
|
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_LOCKED,
|
|
|
|
g_param_spec_boolean ("locked", "Locked", "Item locked",
|
2012-01-23 16:20:18 +00:00
|
|
|
TRUE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-02 13:59:59 +00:00
|
|
|
/**
|
|
|
|
* SecretItem:created:
|
|
|
|
*
|
|
|
|
* The date and time (in seconds since the UNIX epoch) that this
|
|
|
|
* item was created.
|
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_CREATED,
|
|
|
|
g_param_spec_uint64 ("created", "Created", "Item creation date",
|
2012-01-23 16:20:18 +00:00
|
|
|
0UL, G_MAXUINT64, 0UL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-02 13:59:59 +00:00
|
|
|
/**
|
|
|
|
* SecretItem:modified:
|
|
|
|
*
|
|
|
|
* The date and time (in seconds since the UNIX epoch) that this
|
|
|
|
* item was last modified.
|
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_MODIFIED,
|
|
|
|
g_param_spec_uint64 ("modified", "Modified", "Item modified date",
|
2012-01-23 16:20:18 +00:00
|
|
|
0UL, G_MAXUINT64, 0UL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_type_class_add_private (gobject_class, sizeof (SecretItemPrivate));
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
static gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_initable_init (GInitable *initable,
|
2012-02-02 12:40:47 +00:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2012-01-25 13:26:52 +00:00
|
|
|
{
|
|
|
|
GDBusProxy *proxy;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
if (!secret_item_initable_parent_iface->init (initable, cancellable, error))
|
2012-01-25 13:26:52 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
proxy = G_DBUS_PROXY (initable);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
if (!_secret_util_have_cached_properties (proxy)) {
|
2012-01-25 13:26:52 +00:00
|
|
|
g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD,
|
|
|
|
"No such secret item at path: %s",
|
|
|
|
g_dbus_proxy_get_object_path (proxy));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_initable_iface (GInitableIface *iface)
|
2012-01-25 13:26:52 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_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 = secret_item_initable_init;
|
2012-01-25 13:26:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_init_base (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *self = SECRET_ITEM (source);
|
2012-01-25 13:26:52 +00:00
|
|
|
GDBusProxy *proxy = G_DBUS_PROXY (self);
|
|
|
|
GError *error = NULL;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
if (!secret_item_async_initable_parent_iface->init_finish (G_ASYNC_INITABLE (self),
|
2012-02-02 12:40:47 +00:00
|
|
|
result, &error)) {
|
2012-01-25 13:26:52 +00:00
|
|
|
g_simple_async_result_take_error (res, error);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
} else if (!_secret_util_have_cached_properties (proxy)) {
|
2012-01-25 13:26:52 +00:00
|
|
|
g_simple_async_result_set_error (res, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD,
|
|
|
|
"No such secret item at path: %s",
|
|
|
|
g_dbus_proxy_get_object_path (proxy));
|
|
|
|
}
|
|
|
|
|
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_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-25 13:26:52 +00:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
|
|
|
|
res = g_simple_async_result_new (G_OBJECT (initable), callback, user_data,
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_async_initable_init_async);
|
2012-01-25 13:26:52 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_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-25 13:26:52 +00:00
|
|
|
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_async_initable_init_finish (GAsyncInitable *initable,
|
2012-02-02 12:40:47 +00:00
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
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_item_async_initable_init_async), FALSE);
|
2012-01-25 13:26:52 +00:00
|
|
|
|
|
|
|
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-01-23 16:20:18 +00:00
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_async_initable_iface (GAsyncInitableIface *iface)
|
2012-01-23 16:20:18 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_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_item_async_initable_init_async;
|
|
|
|
iface->init_finish = secret_item_async_initable_init_finish;
|
2012-01-23 16:20:18 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_new:
|
|
|
|
* @service: a secret service object
|
|
|
|
* @item_path: the dbus path of the collection
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @callback: called when the operation completes
|
|
|
|
* @user_data: data to be passed to the callback
|
|
|
|
*
|
|
|
|
* Get a new item proxy for a secret item in the secret service.
|
|
|
|
*
|
|
|
|
* 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_item_new (SecretService *service,
|
2012-02-02 12:40:47 +00:00
|
|
|
const gchar *item_path,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
|
|
|
GDBusProxy *proxy;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_if_fail (SECRET_IS_SERVICE (service));
|
2012-01-20 14:10:35 +00:00
|
|
|
g_return_if_fail (item_path != NULL);
|
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
|
|
|
|
proxy = G_DBUS_PROXY (service);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_async_initable_new_async (SECRET_SERVICE_GET_CLASS (service)->item_gtype,
|
2012-01-25 13:26:52 +00:00
|
|
|
G_PRIORITY_DEFAULT, cancellable, callback, user_data,
|
2012-01-20 14:10:35 +00:00
|
|
|
"g-flags", G_DBUS_CALL_FLAGS_NONE,
|
2012-02-01 12:34:08 +00:00
|
|
|
"g-interface-info", _secret_gen_item_interface_info (),
|
2012-01-20 14:10:35 +00:00
|
|
|
"g-name", g_dbus_proxy_get_name (proxy),
|
|
|
|
"g-connection", g_dbus_proxy_get_connection (proxy),
|
|
|
|
"g-object-path", item_path,
|
2012-02-01 12:34:08 +00:00
|
|
|
"g-interface-name", SECRET_ITEM_INTERFACE,
|
2012-01-23 16:20:18 +00:00
|
|
|
"service", service,
|
2012-01-20 14:10:35 +00:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_new_finish:
|
|
|
|
* @result: the asynchronous result passed to the callback
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Finish asynchronous operation to get a new item proxy for an secret
|
|
|
|
* item in the secret service.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the new item, which should be unreferenced
|
|
|
|
* with g_object_unref()
|
|
|
|
*/
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *
|
|
|
|
secret_item_new_finish (GAsyncResult *result,
|
2012-02-02 12:40:47 +00:00
|
|
|
GError **error)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
|
|
|
GObject *object;
|
|
|
|
GObject *source_object;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2012-01-23 16:20:18 +00:00
|
|
|
if (object == NULL)
|
2012-01-20 14:10:35 +00:00
|
|
|
return NULL;
|
2012-01-23 16:20:18 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
return SECRET_ITEM (object);
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_new_sync:
|
|
|
|
* @service: a secret service object
|
|
|
|
* @item_path: the dbus path of the item
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Get a new item proxy for a secret item in the secret service.
|
|
|
|
*
|
|
|
|
* This method may block indefinitely and should not be used in user interface
|
|
|
|
* threads.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the new item, which should be unreferenced
|
|
|
|
* with g_object_unref()
|
|
|
|
*/
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *
|
|
|
|
secret_item_new_sync (SecretService *service,
|
2012-02-02 12:40:47 +00:00
|
|
|
const gchar *item_path,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-01-25 13:26:52 +00:00
|
|
|
GDBusProxy *proxy;
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_SERVICE (service), NULL);
|
2012-01-20 14:10:35 +00:00
|
|
|
g_return_val_if_fail (item_path != NULL, NULL);
|
2012-01-23 16:20:18 +00:00
|
|
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
|
2012-01-20 14:10:35 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
proxy = G_DBUS_PROXY (service);
|
2012-01-23 16:20:18 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
return g_initable_new (SECRET_SERVICE_GET_CLASS (service)->item_gtype,
|
2012-01-25 13:26:52 +00:00
|
|
|
cancellable, error,
|
|
|
|
"g-flags", G_DBUS_CALL_FLAGS_NONE,
|
2012-02-01 12:34:08 +00:00
|
|
|
"g-interface-info", _secret_gen_item_interface_info (),
|
2012-01-25 13:26:52 +00:00
|
|
|
"g-name", g_dbus_proxy_get_name (proxy),
|
|
|
|
"g-connection", g_dbus_proxy_get_connection (proxy),
|
|
|
|
"g-object-path", item_path,
|
2012-02-01 12:34:08 +00:00
|
|
|
"g-interface-name", SECRET_ITEM_INTERFACE,
|
2012-01-25 13:26:52 +00:00
|
|
|
"service", service,
|
|
|
|
NULL);
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_refresh:
|
|
|
|
* @self: the collection
|
|
|
|
*
|
|
|
|
* Refresh the properties on this item. This fires off a request to
|
|
|
|
* refresh, and the properties will be updated later.
|
|
|
|
*
|
|
|
|
* Calling this method is not normally necessary, as the secret service
|
|
|
|
* will notify the client when properties change.
|
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_refresh (SecretItem *self)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_if_fail (SECRET_IS_ITEM (self));
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
_secret_util_get_properties (G_DBUS_PROXY (self),
|
2012-02-02 12:40:47 +00:00
|
|
|
secret_item_refresh,
|
|
|
|
NULL, NULL, NULL);
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 17:23:12 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
GCancellable *cancellable;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *item;
|
2012-01-26 17:23:12 +00:00
|
|
|
} 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;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
closure->item = secret_item_new_finish (result, &error);
|
2012-01-26 17:23:12 +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
|
|
|
|
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);
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *service = SECRET_SERVICE (source);
|
2012-01-26 17:23:12 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
gchar *path;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
path = secret_service_create_item_path_finish (service, result, &error);
|
2012-01-26 17:23:12 +00:00
|
|
|
if (error == NULL) {
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_new (service, path, closure->cancellable,
|
2012-02-02 12:40:47 +00:00
|
|
|
on_create_item, g_object_ref (res));
|
2012-01-26 17:23:12 +00:00
|
|
|
} 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,
|
2012-02-01 12:34:08 +00:00
|
|
|
SECRET_ITEM_INTERFACE ".Label",
|
2012-01-26 17:23:12 +00:00
|
|
|
g_variant_ref_sink (value));
|
|
|
|
|
|
|
|
value = g_variant_new_string (schema_name);
|
|
|
|
g_hash_table_insert (properties,
|
2012-02-01 12:34:08 +00:00
|
|
|
SECRET_ITEM_INTERFACE ".Schema",
|
2012-01-26 17:23:12 +00:00
|
|
|
g_variant_ref_sink (value));
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
value = _secret_util_variant_for_attributes (attributes);
|
2012-01-26 17:23:12 +00:00
|
|
|
g_hash_table_insert (properties,
|
2012-02-01 12:34:08 +00:00
|
|
|
SECRET_ITEM_INTERFACE ".Attributes",
|
2012-01-26 17:23:12 +00:00
|
|
|
g_variant_ref_sink (value));
|
|
|
|
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_create:
|
|
|
|
* @collection: a secret collection to create this item in
|
|
|
|
* @schema_name: schema name for the new item
|
|
|
|
* @label: label for the new item
|
2012-03-11 08:06:40 +00:00
|
|
|
* @attributes: (element-type utf8 utf8): attributes for the new item
|
2012-02-02 12:40:47 +00:00
|
|
|
* @value: secret value for the new item
|
|
|
|
* @replace: whether to replace an existing item with the same attributes
|
2012-02-02 13:59:59 +00:00
|
|
|
* @cancellable: optional cancellation object
|
2012-02-02 12:40:47 +00:00
|
|
|
* @callback: called when the operation completes
|
|
|
|
* @user_data: data to pass to the callback
|
|
|
|
*
|
|
|
|
* Create a new item in the secret service.
|
|
|
|
*
|
|
|
|
* If the @replace is set to %TRUE, then the secret service will search for
|
|
|
|
* an item matching the @attributes, and update that item instead of creating
|
|
|
|
* a new one.
|
|
|
|
*
|
|
|
|
* This method may block indefinitely and should not be used in user interface
|
|
|
|
* threads. The secret service may prompt the user. secret_service_prompt()
|
|
|
|
* will be used to handle any prompts that are required.
|
|
|
|
*/
|
2012-01-26 17:23:12 +00:00
|
|
|
void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_create (SecretCollection *collection,
|
2012-02-02 12:40:47 +00:00
|
|
|
const gchar *schema_name,
|
|
|
|
const gchar *label,
|
|
|
|
GHashTable *attributes,
|
|
|
|
SecretValue *value,
|
|
|
|
gboolean replace,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2012-01-26 17:23:12 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *service = NULL;
|
2012-01-26 17:23:12 +00:00
|
|
|
const gchar *collection_path;
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
CreateClosure *closure;
|
|
|
|
GHashTable *properties;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_if_fail (SECRET_IS_COLLECTION (collection));
|
2012-01-26 17:23:12 +00:00
|
|
|
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,
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_create);
|
2012-01-26 17:23:12 +00:00
|
|
|
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));
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_create_item_path (service, collection_path, properties,
|
2012-02-02 12:40:47 +00:00
|
|
|
value, replace, cancellable,
|
|
|
|
on_create_path, g_object_ref (res));
|
2012-01-26 17:23:12 +00:00
|
|
|
|
|
|
|
g_hash_table_unref (properties);
|
|
|
|
g_object_unref (service);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_create_finish:
|
|
|
|
* @result: the asynchronous result passed to the callback
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Finish operation to create a new item in the secret service.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the new item, which should be unreferenced
|
|
|
|
* with g_object_unref()
|
|
|
|
*/
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *
|
|
|
|
secret_item_create_finish (GAsyncResult *result,
|
2012-02-02 12:40:47 +00:00
|
|
|
GError **error)
|
2012-01-26 17:23:12 +00:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
CreateClosure *closure;
|
|
|
|
|
|
|
|
g_return_val_if_fail (g_simple_async_result_is_valid (result, NULL,
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_create), NULL);
|
2012-01-26 17:23:12 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_create_sync:
|
|
|
|
* @collection: a secret collection to create this item in
|
|
|
|
* @schema_name: schema name for the new item
|
|
|
|
* @label: label for the new item
|
2012-03-11 08:06:40 +00:00
|
|
|
* @attributes: (element-type utf8 utf8): attributes for the new item
|
2012-02-02 12:40:47 +00:00
|
|
|
* @value: secret value for the new item
|
|
|
|
* @replace: whether to replace an existing item with the same attributes
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Create a new item in the secret service.
|
|
|
|
*
|
|
|
|
* If the @replace is set to %TRUE, then the secret service will search for
|
|
|
|
* an item matching the @attributes, and update that item instead of creating
|
|
|
|
* a new one.
|
|
|
|
*
|
|
|
|
* This method may block indefinitely and should not be used in user interface
|
|
|
|
* threads. The secret service may prompt the user. secret_service_prompt()
|
|
|
|
* will be used to handle any prompts that are required.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the new item, which should be unreferenced
|
|
|
|
* with g_object_unref()
|
|
|
|
*/
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *
|
|
|
|
secret_item_create_sync (SecretCollection *collection,
|
2012-02-02 12:40:47 +00:00
|
|
|
const gchar *schema_name,
|
|
|
|
const gchar *label,
|
|
|
|
GHashTable *attributes,
|
|
|
|
SecretValue *value,
|
|
|
|
gboolean replace,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2012-01-26 17:23:12 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *service = NULL;
|
2012-01-26 17:23:12 +00:00
|
|
|
const gchar *collection_path;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *item = NULL;
|
2012-01-26 17:23:12 +00:00
|
|
|
GHashTable *properties;
|
|
|
|
gchar *path;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_COLLECTION (collection), NULL);
|
2012-01-26 17:23:12 +00:00
|
|
|
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));
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
path = secret_service_create_item_path_sync (service, collection_path, properties,
|
2012-02-02 12:40:47 +00:00
|
|
|
value, replace, cancellable, error);
|
2012-01-26 17:23:12 +00:00
|
|
|
|
|
|
|
if (path != NULL) {
|
2012-02-01 12:34:08 +00:00
|
|
|
item = secret_item_new_sync (service, path, cancellable, error);
|
2012-01-26 17:23:12 +00:00
|
|
|
g_free (path);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_hash_table_unref (properties);
|
|
|
|
g_object_unref (service);
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2012-01-20 14:10:35 +00:00
|
|
|
static void
|
|
|
|
on_item_deleted (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *self = SECRET_ITEM (g_async_result_get_source_object (user_data));
|
2012-01-20 14:10:35 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
if (secret_service_delete_path_finish (SECRET_SERVICE (source), result, &error)) {
|
2012-01-23 16:20:18 +00:00
|
|
|
g_simple_async_result_set_op_res_gboolean (res, TRUE);
|
2012-01-20 14:10:35 +00:00
|
|
|
g_object_run_dispose (G_OBJECT (self));
|
2012-01-23 16:20:18 +00:00
|
|
|
}
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
if (error != NULL)
|
|
|
|
g_simple_async_result_take_error (res, error);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-01-20 14:10:35 +00:00
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
g_object_unref (self);
|
|
|
|
g_object_unref (res);
|
2011-09-25 06:22:36 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_collection_delete:
|
|
|
|
* @self: a collection
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @callback: called when the operation completes
|
|
|
|
* @user_data: data to pass to the callback
|
|
|
|
*
|
|
|
|
* Delete this collection.
|
|
|
|
*
|
|
|
|
* This method returns immediately and completes asynchronously. The secret
|
|
|
|
* service may prompt the user. secret_service_prompt() will be used to handle
|
|
|
|
* any prompts that show up.
|
|
|
|
*/
|
2011-09-25 06:22:36 +00:00
|
|
|
void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_delete (SecretItem *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2011-09-25 06:22:36 +00:00
|
|
|
{
|
2012-01-20 14:10:35 +00:00
|
|
|
GSimpleAsyncResult *res;
|
2011-09-25 06:22:36 +00:00
|
|
|
const gchar *object_path;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_if_fail (SECRET_IS_ITEM (self));
|
2011-09-25 06:22:36 +00:00
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
|
|
|
|
object_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (self));
|
2012-01-20 14:10:35 +00:00
|
|
|
res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_delete);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
_secret_service_delete_path (self->pv->service, object_path, TRUE,
|
2012-02-02 12:40:47 +00:00
|
|
|
cancellable, on_item_deleted, g_object_ref (res));
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
g_object_unref (res);
|
2011-09-25 06:22:36 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_delete_finish:
|
|
|
|
* @self: an item
|
|
|
|
* @result: asynchronous result passed to the callback
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Complete asynchronous operation to delete the secret item.
|
|
|
|
*
|
|
|
|
* Returns: whether the item was successfully deleted or not
|
|
|
|
*/
|
2011-09-25 06:22:36 +00:00
|
|
|
gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_delete_finish (SecretItem *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
2011-09-25 06:22:36 +00:00
|
|
|
{
|
2012-01-23 16:20:18 +00:00
|
|
|
GSimpleAsyncResult *res;
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_ITEM (self), FALSE);
|
2011-09-25 06:22:36 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
2012-01-23 16:20:18 +00:00
|
|
|
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_delete), FALSE);
|
2012-01-23 16:20:18 +00:00
|
|
|
|
|
|
|
res = G_SIMPLE_ASYNC_RESULT (result);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-01-23 16:20:18 +00:00
|
|
|
if (g_simple_async_result_propagate_error (res, error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_simple_async_result_get_op_res_gboolean (res);
|
2011-09-25 06:22:36 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_delete_sync:
|
|
|
|
* @self: an item
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Delete this secret item.
|
|
|
|
*
|
|
|
|
* This method may block indefinitely and should not be used in user
|
|
|
|
* interface threads. The secret service may prompt the user.
|
|
|
|
* secret_service_prompt() will be used to handle any prompts that show up.
|
|
|
|
*
|
|
|
|
* Returns: whether the item was successfully deleted or not
|
|
|
|
*/
|
2011-09-25 06:22:36 +00:00
|
|
|
gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_delete_sync (SecretItem *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-01-20 14:10:35 +00:00
|
|
|
gboolean ret;
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_ITEM (self), FALSE);
|
2011-09-25 06:22:36 +00:00
|
|
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
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);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_delete (self, cancellable, _secret_sync_on_result, sync);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
g_main_loop_run (sync->loop);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_item_delete_finish (self, sync->result, error);
|
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);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
return ret;
|
2011-09-25 06:22:36 +00:00
|
|
|
}
|
|
|
|
|
2012-01-23 16:20:18 +00:00
|
|
|
typedef struct {
|
|
|
|
GCancellable *cancellable;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretValue *value;
|
2012-01-23 16:20:18 +00:00
|
|
|
} GetClosure;
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_closure_free (gpointer data)
|
|
|
|
{
|
|
|
|
GetClosure *closure = data;
|
|
|
|
g_clear_object (&closure->cancellable);
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_value_unref (closure->value);
|
2012-01-23 16:20:18 +00:00
|
|
|
g_slice_free (GetClosure, closure);
|
|
|
|
}
|
|
|
|
|
2011-09-25 06:22:36 +00:00
|
|
|
static void
|
2012-01-26 17:23:12 +00:00
|
|
|
on_item_get_secret (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
2011-09-25 06:22:36 +00:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *self = SECRET_ITEM (g_async_result_get_source_object (user_data));
|
2012-01-23 16:20:18 +00:00
|
|
|
GetClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretSession *session;
|
2011-09-25 06:22:36 +00:00
|
|
|
GError *error = NULL;
|
2012-01-23 16:20:18 +00:00
|
|
|
GVariant *retval;
|
|
|
|
GVariant *child;
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-01-23 16:20:18 +00:00
|
|
|
retval = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), result, &error);
|
2011-09-25 06:22:36 +00:00
|
|
|
if (error == NULL) {
|
2012-01-23 16:20:18 +00:00
|
|
|
child = g_variant_get_child_value (retval, 0);
|
|
|
|
g_variant_unref (retval);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
session = _secret_service_get_session (self->pv->service);
|
|
|
|
closure->value = _secret_session_decode_secret (session, child);
|
2012-01-23 16:20:18 +00:00
|
|
|
g_variant_unref (child);
|
|
|
|
|
|
|
|
if (closure->value == NULL)
|
2012-02-01 12:34:08 +00:00
|
|
|
g_set_error (&error, SECRET_ERROR, SECRET_ERROR_PROTOCOL,
|
2011-09-25 06:22:36 +00:00
|
|
|
_("Received invalid secret from the secret storage"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error != NULL)
|
|
|
|
g_simple_async_result_take_error (res, error);
|
|
|
|
|
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-01-26 17:23:12 +00:00
|
|
|
on_get_ensure_session (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
2011-09-25 06:22:36 +00:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *self = SECRET_ITEM (g_async_result_get_source_object (user_data));
|
2012-01-23 16:20:18 +00:00
|
|
|
GetClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
2011-09-25 06:22:36 +00:00
|
|
|
const gchar *session_path;
|
2012-01-23 16:20:18 +00:00
|
|
|
GError *error = NULL;
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
session_path = secret_service_ensure_session_finish (self->pv->service, result, &error);
|
2011-09-25 06:22:36 +00:00
|
|
|
if (error != NULL) {
|
|
|
|
g_simple_async_result_take_error (res, error);
|
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
g_assert (session_path != NULL && session_path[0] != '\0');
|
|
|
|
g_dbus_proxy_call (G_DBUS_PROXY (self), "GetSecret",
|
2012-01-23 16:20:18 +00:00
|
|
|
g_variant_new ("(o)", session_path),
|
|
|
|
G_DBUS_CALL_FLAGS_NONE, -1, closure->cancellable,
|
2012-01-26 17:23:12 +00:00
|
|
|
on_item_get_secret, g_object_ref (res));
|
2011-09-25 06:22:36 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 17:23:12 +00:00
|
|
|
g_object_unref (self);
|
2011-09-25 06:22:36 +00:00
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_get_secret:
|
|
|
|
* @self: an item
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @callback: called when the operation completes
|
|
|
|
* @user_data: data to pass to the callback
|
|
|
|
*
|
|
|
|
* Get the secret value of this item.
|
|
|
|
*
|
|
|
|
* Each item has a single secret which might be a password or some
|
|
|
|
* other secret binary value.
|
|
|
|
*
|
|
|
|
* This function returns immediately and completes asynchronously.
|
|
|
|
*/
|
2011-09-25 06:22:36 +00:00
|
|
|
void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_get_secret (SecretItem *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-01-23 16:20:18 +00:00
|
|
|
GetClosure *closure;
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_if_fail (SECRET_IS_ITEM (self));
|
2011-09-25 06:22:36 +00:00
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
|
|
|
|
res = g_simple_async_result_new (G_OBJECT (self), callback,
|
2012-02-01 12:34:08 +00:00
|
|
|
user_data, secret_item_get_secret);
|
2012-01-23 16:20:18 +00:00
|
|
|
closure = g_slice_new0 (GetClosure);
|
|
|
|
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
|
|
|
g_simple_async_result_set_op_res_gpointer (res, closure, get_closure_free);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_ensure_session (self->pv->service, cancellable,
|
2012-02-02 12:40:47 +00:00
|
|
|
on_get_ensure_session,
|
|
|
|
g_object_ref (res));
|
2011-09-25 06:22:36 +00:00
|
|
|
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_get_secret_finish:
|
|
|
|
* @self: an item
|
|
|
|
* @result: asynchronous result passed to callback
|
|
|
|
* @error: location to place error on failure
|
|
|
|
*
|
|
|
|
* Get the secret value of this item.
|
|
|
|
*
|
|
|
|
* Complete asynchronous operation to get the secret value of this item.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the newly allocated secret value in this
|
|
|
|
* item, which should be released with secret_value_unref()
|
|
|
|
*/
|
|
|
|
SecretValue *
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_get_secret_finish (SecretItem *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
2011-09-25 06:22:36 +00:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
2012-01-23 16:20:18 +00:00
|
|
|
GetClosure *closure;
|
2011-09-25 06:22:36 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_get_secret), NULL);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
|
|
|
res = G_SIMPLE_ASYNC_RESULT (result);
|
|
|
|
if (g_simple_async_result_propagate_error (res, error))
|
|
|
|
return NULL;
|
|
|
|
|
2012-01-23 16:20:18 +00:00
|
|
|
closure = g_simple_async_result_get_op_res_gpointer (res);
|
2012-02-01 12:34:08 +00:00
|
|
|
return closure->value ? secret_value_ref (closure->value) : NULL;
|
2011-09-25 06:22:36 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_get_secret_sync:
|
|
|
|
* @self: an item
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @error: location to place error on failure
|
|
|
|
*
|
|
|
|
* Get the secret value of this item.
|
|
|
|
*
|
|
|
|
* Each item has a single secret which might be a password or some
|
|
|
|
* other secret binary value.
|
|
|
|
*
|
|
|
|
* This function may block indefinetely. Use the asynchronous version
|
|
|
|
* in user interface threads.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the newly allocated secret value in this
|
|
|
|
* item, which should be released with secret_value_unref()
|
|
|
|
*/
|
|
|
|
SecretValue *
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_get_secret_sync (SecretItem *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;
|
|
|
|
SecretValue *value;
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_ITEM (self), FALSE);
|
2012-01-20 14:10:35 +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-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_item_get_secret (self, cancellable, _secret_sync_on_result, sync);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
g_main_loop_run (sync->loop);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
value = secret_item_get_secret_finish (self, sync->result, error);
|
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
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2012-01-26 17:23:12 +00:00
|
|
|
typedef struct {
|
|
|
|
GCancellable *cancellable;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretValue *value;
|
2012-01-26 17:23:12 +00:00
|
|
|
} SetClosure;
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_closure_free (gpointer data)
|
|
|
|
{
|
|
|
|
GetClosure *closure = data;
|
|
|
|
g_clear_object (&closure->cancellable);
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_value_unref (closure->value);
|
2012-01-26 17:23:12 +00:00
|
|
|
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);
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *self = SECRET_ITEM (g_async_result_get_source_object (user_data));
|
2012-01-26 17:23:12 +00:00
|
|
|
SetClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretSession *session;
|
2012-01-26 17:23:12 +00:00
|
|
|
GVariant *encoded;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_ensure_session_finish (self->pv->service, result, &error);
|
2012-01-26 17:23:12 +00:00
|
|
|
if (error != NULL) {
|
|
|
|
g_simple_async_result_take_error (res, error);
|
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
|
|
|
|
} else {
|
2012-02-01 12:34:08 +00:00
|
|
|
session = _secret_service_get_session (self->pv->service);
|
|
|
|
encoded = _secret_session_encode_secret (session, closure->value);
|
2012-01-26 17:23:12 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_set_secret:
|
|
|
|
* @self: an item
|
|
|
|
* @value: a new secret value
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @callback: called when the operation completes
|
|
|
|
* @user_data: data to pass to the callback
|
|
|
|
*
|
|
|
|
* Set the secret value of this item.
|
|
|
|
*
|
|
|
|
* Each item has a single secret which might be a password or some
|
|
|
|
* other secret binary value.
|
|
|
|
*
|
|
|
|
* This function returns immediately and completes asynchronously.
|
|
|
|
*/
|
2012-01-26 17:23:12 +00:00
|
|
|
void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_set_secret (SecretItem *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
SecretValue *value,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2012-01-26 17:23:12 +00:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
SetClosure *closure;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_if_fail (SECRET_IS_ITEM (self));
|
2012-01-26 17:23:12 +00:00
|
|
|
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,
|
2012-02-01 12:34:08 +00:00
|
|
|
user_data, secret_item_set_secret);
|
2012-01-26 17:23:12 +00:00
|
|
|
closure = g_slice_new0 (SetClosure);
|
|
|
|
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
2012-02-01 12:34:08 +00:00
|
|
|
closure->value = secret_value_ref (value);
|
2012-01-26 17:23:12 +00:00
|
|
|
g_simple_async_result_set_op_res_gpointer (res, closure, set_closure_free);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_ensure_session (self->pv->service, cancellable,
|
2012-02-02 12:40:47 +00:00
|
|
|
on_set_ensure_session,
|
|
|
|
g_object_ref (res));
|
2012-01-26 17:23:12 +00:00
|
|
|
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_set_secret_finish:
|
|
|
|
* @self: an item
|
|
|
|
* @result: asynchronous result passed to callback
|
|
|
|
* @error: location to place error on failure
|
|
|
|
*
|
|
|
|
* Complete asynchronous operation to set the secret value of this item.
|
|
|
|
*
|
|
|
|
* Returns: whether the change was successful or not
|
|
|
|
*/
|
2012-01-26 17:23:12 +00:00
|
|
|
gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_set_secret_finish (SecretItem *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
2012-01-26 17:23:12 +00:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
|
|
|
|
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_set_secret), FALSE);
|
2012-01-26 17:23:12 +00:00
|
|
|
|
|
|
|
res = G_SIMPLE_ASYNC_RESULT (result);
|
|
|
|
if (g_simple_async_result_propagate_error (res, error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_set_secret_sync:
|
|
|
|
* @self: an item
|
|
|
|
* @value: a new secret value
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @error: location to place error on failure
|
|
|
|
*
|
|
|
|
* Set the secret value of this item.
|
|
|
|
*
|
|
|
|
* Each item has a single secret which might be a password or some
|
|
|
|
* other secret binary value.
|
|
|
|
*
|
|
|
|
* This function may block indefinetely. Use the asynchronous version
|
|
|
|
* in user interface threads.
|
|
|
|
*
|
|
|
|
* Returns: whether the change was successful or not
|
|
|
|
*/
|
2012-01-26 17:23:12 +00:00
|
|
|
gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_set_secret_sync (SecretItem *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
SecretValue *value,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2012-01-26 17:23:12 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretSync *sync;
|
2012-01-26 17:23:12 +00:00
|
|
|
gboolean ret;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_ITEM (self), FALSE);
|
2012-01-26 17:23:12 +00:00
|
|
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
sync = _secret_sync_new ();
|
2012-01-26 17:23:12 +00:00
|
|
|
g_main_context_push_thread_default (sync->context);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_set_secret (self, value, cancellable, _secret_sync_on_result, sync);
|
2012-01-26 17:23:12 +00:00
|
|
|
|
|
|
|
g_main_loop_run (sync->loop);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_item_set_secret_finish (self, sync->result, error);
|
2012-01-26 17:23:12 +00:00
|
|
|
|
|
|
|
g_main_context_pop_thread_default (sync->context);
|
2012-02-01 12:34:08 +00:00
|
|
|
_secret_sync_free (sync);
|
2012-01-26 17:23:12 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_get_attributes:
|
|
|
|
* @self: an item
|
|
|
|
*
|
|
|
|
* Set the attributes of this item.
|
|
|
|
*
|
|
|
|
* The @attributes are a mapping of string keys to string values.
|
|
|
|
* Attributes are used to search for items. Attributes are not stored
|
|
|
|
* or transferred securely by the secret service.
|
|
|
|
*
|
|
|
|
* Do not modify the attributes returned by this method. Use
|
|
|
|
* secret_item_set_attributes() instead.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): a new reference to the attributes, which should
|
|
|
|
* not be modified, and released with g_hash_table_unref()
|
|
|
|
*/
|
2012-01-16 14:08:46 +00:00
|
|
|
GHashTable *
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_get_attributes (SecretItem *self)
|
2012-01-16 14:08:46 +00:00
|
|
|
{
|
|
|
|
GHashTable *attributes;
|
|
|
|
GVariant *variant;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_ITEM (self), NULL);
|
2012-01-16 14:08:46 +00:00
|
|
|
|
|
|
|
variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self), "Attributes");
|
|
|
|
g_return_val_if_fail (variant != NULL, NULL);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
attributes = _secret_util_attributes_for_variant (variant);
|
2012-01-16 14:08:46 +00:00
|
|
|
g_variant_unref (variant);
|
|
|
|
|
|
|
|
return attributes;
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_set_attributes:
|
|
|
|
* @self: an item
|
2012-03-11 08:06:40 +00:00
|
|
|
* @attributes: (element-type utf8 utf8): a new set of attributes
|
2012-02-02 12:40:47 +00:00
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @callback: called when the asynchronous operation completes
|
|
|
|
* @user_data: data to pass to the callback
|
|
|
|
*
|
|
|
|
* Set the attributes of this item.
|
|
|
|
*
|
|
|
|
* The @attributes are a mapping of string keys to string values.
|
|
|
|
* Attributes are used to search for items. Attributes are not stored
|
|
|
|
* or transferred securely by the secret service.
|
|
|
|
*
|
|
|
|
* This function returns immediately and completes asynchronously.
|
|
|
|
*/
|
2012-01-16 14:08:46 +00:00
|
|
|
void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_set_attributes (SecretItem *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
GHashTable *attributes,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2012-01-16 14:08:46 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_if_fail (SECRET_IS_ITEM (self));
|
2012-01-16 14:08:46 +00:00
|
|
|
g_return_if_fail (attributes != NULL);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
_secret_util_set_property (G_DBUS_PROXY (self), "Attributes",
|
2012-02-02 12:40:47 +00:00
|
|
|
_secret_util_variant_for_attributes (attributes),
|
|
|
|
secret_item_set_attributes, cancellable,
|
|
|
|
callback, user_data);
|
2012-01-16 14:08:46 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_set_attributes_finish:
|
|
|
|
* @self: an item
|
|
|
|
* @result: asynchronous result passed to the callback
|
|
|
|
* @error: location to place error on failure
|
|
|
|
*
|
|
|
|
* Complete operation to set the attributes of this item.
|
|
|
|
*
|
|
|
|
* Returns: whether the change was successful or not
|
|
|
|
*/
|
2012-01-16 14:08:46 +00:00
|
|
|
gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_set_attributes_finish (SecretItem *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
2012-01-16 14:08:46 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_ITEM (self), FALSE);
|
2012-01-16 14:08:46 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
return _secret_util_set_property_finish (G_DBUS_PROXY (self),
|
2012-02-02 12:40:47 +00:00
|
|
|
secret_item_set_attributes,
|
|
|
|
result, error);
|
2012-01-16 14:08:46 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_set_attributes_sync:
|
|
|
|
* @self: an item
|
2012-03-11 08:06:40 +00:00
|
|
|
* @attributes: (element-type utf8 utf8): a new set of attributes
|
2012-02-02 12:40:47 +00:00
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @error: location to place error on failure
|
|
|
|
*
|
|
|
|
* Set the attributes of this item.
|
|
|
|
*
|
|
|
|
* The @attributes are a mapping of string keys to string values.
|
|
|
|
* Attributes are used to search for items. Attributes are not stored
|
|
|
|
* or transferred securely by the secret service.
|
|
|
|
*
|
|
|
|
* This function may block indefinetely. Use the asynchronous version
|
|
|
|
* in user interface threads.
|
|
|
|
*
|
|
|
|
* Returns: whether the change was successful or not
|
|
|
|
*/
|
2012-01-16 14:08:46 +00:00
|
|
|
gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_set_attributes_sync (SecretItem *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
GHashTable *attributes,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2012-01-16 14:08:46 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_ITEM (self), FALSE);
|
2012-01-16 14:08:46 +00:00
|
|
|
g_return_val_if_fail (attributes != NULL, FALSE);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
return _secret_util_set_property_sync (G_DBUS_PROXY (self), "Attributes",
|
2012-02-02 12:40:47 +00:00
|
|
|
_secret_util_variant_for_attributes (attributes),
|
|
|
|
cancellable, error);
|
2012-01-16 14:08:46 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_get_schema:
|
|
|
|
* @self: an item
|
|
|
|
*
|
|
|
|
* Get the schema of this item.
|
|
|
|
*
|
|
|
|
* The schema is a dotted string like <literal>org.freedesktop.Secret.Generic</literal>.
|
|
|
|
* A schema describes the set of attributes that should be set on this item.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the schema, which should be freed with g_free()
|
|
|
|
*/
|
2012-01-26 17:23:12 +00:00
|
|
|
gchar *
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_get_schema (SecretItem *self)
|
2012-01-26 17:23:12 +00:00
|
|
|
{
|
|
|
|
GVariant *variant;
|
|
|
|
gchar *label;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_ITEM (self), NULL);
|
2012-01-26 17:23:12 +00:00
|
|
|
|
2012-01-31 19:20:31 +00:00
|
|
|
variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self), "Type");
|
|
|
|
if (variant == NULL)
|
|
|
|
return NULL;
|
2012-01-26 17:23:12 +00:00
|
|
|
|
|
|
|
label = g_variant_dup_string (variant, NULL);
|
|
|
|
g_variant_unref (variant);
|
|
|
|
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_get_label:
|
|
|
|
* @self: an item
|
|
|
|
*
|
|
|
|
* Get the label of this item.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the label, which should be freed with g_free()
|
|
|
|
*/
|
2012-01-16 14:08:46 +00:00
|
|
|
gchar *
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_get_label (SecretItem *self)
|
2012-01-16 14:08:46 +00:00
|
|
|
{
|
|
|
|
GVariant *variant;
|
|
|
|
gchar *label;
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_ITEM (self), NULL);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-01-16 14:08:46 +00:00
|
|
|
variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self), "Label");
|
|
|
|
g_return_val_if_fail (variant != NULL, NULL);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-01-16 14:08:46 +00:00
|
|
|
label = g_variant_dup_string (variant, NULL);
|
|
|
|
g_variant_unref (variant);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-01-16 14:08:46 +00:00
|
|
|
return label;
|
|
|
|
}
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_set_label:
|
|
|
|
* @self: an item
|
|
|
|
* @label: a new label
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @callback: called when the operation completes
|
|
|
|
* @user_data: data to pass to the callback
|
|
|
|
*
|
|
|
|
* Set the label of this item.
|
|
|
|
*
|
|
|
|
* This function returns immediately and completes asynchronously.
|
|
|
|
*/
|
2012-01-16 14:08:46 +00:00
|
|
|
void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_set_label (SecretItem *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
const gchar *label,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2012-01-16 14:08:46 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_if_fail (SECRET_IS_ITEM (self));
|
2012-01-16 14:08:46 +00:00
|
|
|
g_return_if_fail (label != NULL);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
_secret_util_set_property (G_DBUS_PROXY (self), "Label",
|
2012-02-02 12:40:47 +00:00
|
|
|
g_variant_new_string (label),
|
|
|
|
secret_item_set_label,
|
|
|
|
cancellable, callback, user_data);
|
2012-01-16 14:08:46 +00:00
|
|
|
}
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_set_label_finish:
|
|
|
|
* @self: an item
|
|
|
|
* @result: asynchronous result passed to callback
|
|
|
|
* @error: location to place error on failure
|
|
|
|
*
|
|
|
|
* Complete asynchronous operation to set the label of this collection.
|
|
|
|
*
|
|
|
|
* Returns: whether the change was successful or not
|
|
|
|
*/
|
2012-01-16 14:08:46 +00:00
|
|
|
gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_set_label_finish (SecretItem *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
2012-01-16 14:08:46 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_ITEM (self), FALSE);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
return _secret_util_set_property_finish (G_DBUS_PROXY (self),
|
2012-02-02 12:40:47 +00:00
|
|
|
secret_item_set_label,
|
|
|
|
result, error);
|
2012-01-16 14:08:46 +00:00
|
|
|
}
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_set_label_sync:
|
|
|
|
* @self: an item
|
|
|
|
* @label: a new label
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @error: location to place error on failure
|
|
|
|
*
|
|
|
|
* Set the label of this item.
|
|
|
|
*
|
|
|
|
* This function may block indefinetely. Use the asynchronous version
|
|
|
|
* in user interface threads.
|
|
|
|
*
|
|
|
|
* Returns: whether the change was successful or not
|
|
|
|
*/
|
2012-01-16 14:08:46 +00:00
|
|
|
gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_set_label_sync (SecretItem *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
const gchar *label,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2012-01-16 14:08:46 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_ITEM (self), FALSE);
|
2012-01-16 14:08:46 +00:00
|
|
|
g_return_val_if_fail (label != NULL, FALSE);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
return _secret_util_set_property_sync (G_DBUS_PROXY (self), "Label",
|
2012-01-16 14:08:46 +00:00
|
|
|
g_variant_new_string (label),
|
|
|
|
cancellable, error);
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_get_locked:
|
|
|
|
* @self: an item
|
|
|
|
*
|
|
|
|
* Get whether the item is locked or not.
|
|
|
|
*
|
|
|
|
* Depending on the secret service an item may not be able to be locked
|
|
|
|
* independently from the collection that it is in.
|
|
|
|
*
|
|
|
|
* Returns: whether the item is locked or not
|
|
|
|
*/
|
2012-01-16 14:08:46 +00:00
|
|
|
gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_get_locked (SecretItem *self)
|
2012-01-16 14:08:46 +00:00
|
|
|
{
|
|
|
|
GVariant *variant;
|
|
|
|
gboolean locked;
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_ITEM (self), TRUE);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-01-16 14:08:46 +00:00
|
|
|
variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self), "Locked");
|
|
|
|
g_return_val_if_fail (variant != NULL, TRUE);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-01-16 14:08:46 +00:00
|
|
|
locked = g_variant_get_boolean (variant);
|
|
|
|
g_variant_unref (variant);
|
|
|
|
|
|
|
|
return locked;
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_get_created:
|
|
|
|
* @self: an item
|
|
|
|
*
|
|
|
|
* Get the created date and time of the item. The return value is
|
|
|
|
* the number of seconds since the unix epoch, January 1st 1970.
|
|
|
|
*
|
|
|
|
* Returns: the created date and time
|
|
|
|
*/
|
2012-01-16 14:08:46 +00:00
|
|
|
guint64
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_get_created (SecretItem *self)
|
2012-01-16 14:08:46 +00:00
|
|
|
{
|
|
|
|
GVariant *variant;
|
|
|
|
guint64 created;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_ITEM (self), TRUE);
|
2012-01-16 14:08:46 +00:00
|
|
|
|
|
|
|
variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self), "Created");
|
|
|
|
g_return_val_if_fail (variant != NULL, 0);
|
|
|
|
|
|
|
|
created = g_variant_get_uint64 (variant);
|
|
|
|
g_variant_unref (variant);
|
|
|
|
|
|
|
|
return created;
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_get_modified:
|
|
|
|
* @self: an item
|
|
|
|
*
|
|
|
|
* Get the modified date and time of the item. The return value is
|
|
|
|
* the number of seconds since the unix epoch, January 1st 1970.
|
|
|
|
*
|
|
|
|
* Returns: the modified date and time
|
|
|
|
*/
|
2012-01-16 14:08:46 +00:00
|
|
|
guint64
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_get_modified (SecretItem *self)
|
2012-01-16 14:08:46 +00:00
|
|
|
{
|
|
|
|
GVariant *variant;
|
|
|
|
guint64 modified;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_ITEM (self), TRUE);
|
2012-01-16 14:08:46 +00:00
|
|
|
|
|
|
|
variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self), "Modified");
|
|
|
|
g_return_val_if_fail (variant != NULL, 0);
|
|
|
|
|
|
|
|
modified = g_variant_get_uint64 (variant);
|
|
|
|
g_variant_unref (variant);
|
|
|
|
|
|
|
|
return modified;
|
|
|
|
}
|