Commit 05d6df8f authored by Christian Kellner's avatar Christian Kellner
Browse files

dbus: move Forget method from device to manager

So the both methods that insert (EnrollDevice) and remove the
devices (ForgetDevice) are located at the Manager object.
parent b61bdfd4
......@@ -126,7 +126,7 @@ handle_authorize_method (GDBusInterfaceSkeleton *iface,
action = "org.freedesktop.bolt.enroll";
else if (bolt_streq (method_name, "Authorize"))
action = "org.freedesktop.bolt.authorize";
else if (bolt_streq (method_name, "Forget"))
else if (bolt_streq (method_name, "ForgetDevice"))
action = "org.freedesktop.bolt.manage";
else if (bolt_streq (method_name, "ListDevices"))
authorized = TRUE;
......
......@@ -38,10 +38,6 @@ static gboolean handle_authorize (BoltDBusDevice *object,
gpointer user_data);
static gboolean handle_forget (BoltDBusDevice *object,
GDBusMethodInvocation *invocation,
gpointer user_data);
struct _BoltDevice
{
BoltDBusDeviceSkeleton object;
......@@ -136,8 +132,6 @@ bolt_device_init (BoltDevice *dev)
{
g_signal_connect (dev, "handle-authorize",
G_CALLBACK (handle_authorize), NULL);
g_signal_connect (dev, "handle-forget",
G_CALLBACK (handle_forget), NULL);
}
static void
......@@ -722,36 +716,6 @@ handle_authorize (BoltDBusDevice *object,
return TRUE;
}
static gboolean
handle_forget (BoltDBusDevice *object,
GDBusMethodInvocation *inv,
gpointer user_data)
{
g_autoptr(GError) key_err = NULL;
g_autoptr(GError) dev_err = NULL;
BoltDevice *dev;
gboolean key_ok, dev_ok;
dev = BOLT_DEVICE (object);
key_ok = bolt_store_del_key (dev->store, dev->uid, &key_err);
if (!key_ok && bolt_err_notfound (key_err))
key_ok = TRUE;
dev_ok = bolt_store_del_device (dev->store, dev->uid, &dev_err);
g_debug ("[%s] forgetting: key: %d, dev: %d", dev->uid, key_ok, dev_ok);
if (!dev_ok)
g_dbus_method_invocation_take_error (inv, g_steal_pointer (&dev_err));
else if (!key_ok)
g_dbus_method_invocation_take_error (inv, g_steal_pointer (&key_err));
else
bolt_dbus_device_complete_forget (BOLT_DBUS_DEVICE (dev), inv);
return TRUE;
}
/* public methods */
BoltDevice *
......
......@@ -102,6 +102,10 @@ static gboolean handle_enroll_device (BoltDBusManager *object,
GDBusMethodInvocation *invocation,
gpointer user_data);
static gboolean handle_forget_device (BoltDBusManager *object,
GDBusMethodInvocation *invocation,
gpointer user_data);
/* */
struct _BoltManager
{
......@@ -216,6 +220,7 @@ bolt_manager_init (BoltManager *mgr)
g_signal_connect (mgr, "handle-list-devices", G_CALLBACK (handle_list_devices), NULL);
g_signal_connect (mgr, "handle-device-by-uid", G_CALLBACK (handle_device_by_uid), NULL);
g_signal_connect (mgr, "handle-enroll-device", G_CALLBACK (handle_enroll_device), NULL);
g_signal_connect (mgr, "handle-forget-device", G_CALLBACK (handle_forget_device), NULL);
g_signal_connect (mgr->store, "device-removed", G_CALLBACK (handle_store_device_removed), mgr);
}
......@@ -1053,6 +1058,51 @@ handle_enroll_device (BoltDBusManager *obj,
}
static gboolean
handle_forget_device (BoltDBusManager *obj,
GDBusMethodInvocation *inv,
gpointer user_data)
{
g_autoptr(BoltDevice) dev = NULL;
g_autoptr(GError) key_err = NULL;
g_autoptr(GError) dev_err = NULL;
BoltManager *mgr;
gboolean key_ok, dev_ok;
GVariant *params;
const char *uid;
mgr = BOLT_MANAGER (obj);
params = g_dbus_method_invocation_get_parameters (inv);
g_variant_get (params, "(&s)", &uid);
dev = bolt_manager_get_device_by_uid (mgr, uid);
if (!dev)
{
g_dbus_method_invocation_return_error (inv,
G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
"device with id '%s' could not be found.",
uid);
return TRUE;
}
key_ok = bolt_store_del_key (mgr->store, uid, &key_err);
if (!key_ok && bolt_err_notfound (key_err))
key_ok = TRUE;
dev_ok = bolt_store_del_device (mgr->store, uid, &dev_err);
g_debug ("[%s] forgetting: key: %d, dev: %d", uid, key_ok, dev_ok);
if (!dev_ok)
g_dbus_method_invocation_take_error (inv, g_steal_pointer (&dev_err));
else if (!key_ok)
g_dbus_method_invocation_take_error (inv, g_steal_pointer (&key_err));
else
bolt_dbus_manager_complete_forget_device (BOLT_DBUS_MANAGER (mgr), inv);
return TRUE;
}
/* public methods */
......
......@@ -359,3 +359,35 @@ bolt_client_enroll_device (BoltClient *client,
dev = bolt_device_new_for_object_path (bus, opath, error);
return dev;
}
gboolean
bolt_client_forget_device (BoltClient *client,
const char *uid,
GError **error)
{
g_autoptr(GError) err = NULL;
GDBusProxy *proxy;
g_return_val_if_fail (BOLT_IS_CLIENT (client), FALSE);
proxy = bolt_proxy_get_proxy (BOLT_PROXY (client));
g_dbus_proxy_call_sync (proxy,
"ForgetDevice",
g_variant_new ("(s)", uid),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&err);
if (err != NULL)
{
if (g_dbus_error_is_remote_error (err))
g_dbus_error_strip_remote_error (err);
g_propagate_error (error, g_steal_pointer (&err));
return FALSE;
}
return TRUE;
}
......@@ -39,4 +39,7 @@ BoltDevice * bolt_client_enroll_device (BoltClient *client,
const char *uid,
BoltPolicy policy,
GError **error);
gboolean bolt_client_forget_device (BoltClient *client,
const char *uid,
GError **error);
G_END_DECLS
......@@ -231,34 +231,3 @@ bolt_device_authorize (BoltDevice *dev,
return TRUE;
}
gboolean
bolt_device_forget (BoltDevice *dev,
GError **error)
{
g_autoptr(GError) err = NULL;
GDBusProxy *proxy;
g_return_val_if_fail (BOLT_IS_DEVICE (dev), FALSE);
proxy = bolt_proxy_get_proxy (BOLT_PROXY (dev));
g_dbus_proxy_call_sync (proxy,
"Forget",
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&err);
if (err != NULL)
{
if (g_dbus_error_is_remote_error (err))
g_dbus_error_strip_remote_error (err);
g_propagate_error (error, g_steal_pointer (&err));
return FALSE;
}
return TRUE;
}
......@@ -34,7 +34,5 @@ BoltDevice * bolt_device_new_for_object_path (GDBusConnection *bus,
gboolean bolt_device_authorize (BoltDevice *dev,
GError **error);
gboolean bolt_device_forget (BoltDevice *dev,
GError **error);
G_END_DECLS
......@@ -253,7 +253,6 @@ static int
forget (BoltClient *client, int argc, char **argv)
{
g_autoptr(GOptionContext) optctx = NULL;
g_autoptr(BoltDevice) dev = NULL;
g_autoptr(GError) error = NULL;
const char *uid;
gboolean ok;
......@@ -268,14 +267,7 @@ forget (BoltClient *client, int argc, char **argv)
uid = argv[1];
dev = bolt_client_get_device (client, uid, &error);
if (dev == NULL)
{
g_printerr ("%s\n", error->message);
return EXIT_FAILURE;
}
ok = bolt_device_forget (dev, &error);
ok = bolt_client_forget_device (client, uid, &error);
if (!ok)
g_printerr ("Failed to forget device: %s\n", error->message);
......
......@@ -77,6 +77,23 @@
</doc:doc>
</method>
<method name="ForgetDevice">
<arg type='s' name='uid' direction='in'>
<doc:doc><doc:summary>The unique id of the device.</doc:summary>
</doc:doc>
</arg>
<doc:doc>
<doc:description>
<doc:para>
Remove the device and any associated inforamtion,
such as the policy and its key, from the store.
</doc:para>
</doc:description>
</doc:doc>
</method>
<!-- signals -->
<signal name="DeviceAdded">
......@@ -188,18 +205,6 @@
</doc:doc>
</method>
<method name="Forget">
<doc:doc>
<doc:description>
<doc:para>
Remove the device and any associated inforamtion,
such as the policy and its key, from the store.
</doc:para>
</doc:description>
</doc:doc>
</method>
</interface>
</node>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment