From 702234cb6410bda279b3322612ab3c2e67427bf5 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 9 Jun 2017 15:59:16 +0100 Subject: [PATCH 40/49] bus/driver: Add GetConnectionContainerInstance(), GetContainerInstanceInfo() Signed-off-by: Simon McVittie --- bus/containers.c | 146 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ bus/containers.h | 10 ++++ bus/driver.c | 6 +++ 3 files changed, 162 insertions(+) diff --git a/bus/containers.c b/bus/containers.c index 8e53c2b1..0aeda633 100644 --- a/bus/containers.c +++ b/bus/containers.c @@ -917,6 +917,152 @@ failed: return FALSE; } +dbus_bool_t +bus_containers_handle_get_connection_container_instance (DBusConnection *caller, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + BusContainerInstance *instance; + BusDriverFound found; + DBusConnection *subject; + DBusMessage *reply = NULL; + DBusMessageIter writer; + const char *bus_name; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + found = bus_driver_get_conn_helper (caller, message, "container instance", + &bus_name, &subject, error); + + switch (found) + { + case BUS_DRIVER_FOUND_SELF: + dbus_set_error (error, DBUS_ERROR_NOT_CONTAINER, + "The message bus is not in a container"); + goto failed; + + case BUS_DRIVER_FOUND_PEER: + break; + + case BUS_DRIVER_FOUND_ERROR: + /* fall through */ + default: + goto failed; + } + + instance = dbus_connection_get_data (subject, contained_data_slot); + + if (instance == NULL) + { + dbus_set_error (error, DBUS_ERROR_NOT_CONTAINER, + "Connection '%s' is not in a container", bus_name); + goto failed; + } + + reply = dbus_message_new_method_return (message); + + if (reply == NULL) + goto oom; + + if (!dbus_message_append_args (reply, + DBUS_TYPE_OBJECT_PATH, &instance->path, + DBUS_TYPE_STRING, &instance->type, + DBUS_TYPE_STRING, &instance->name, + DBUS_TYPE_INVALID)) + goto oom; + + dbus_message_iter_init_append (reply, &writer); + + if (!_dbus_variant_write (instance->metadata, &writer)) + goto oom; + + if (!bus_transaction_send_from_driver (transaction, caller, reply)) + goto oom; + + dbus_message_unref (reply); + return TRUE; + +oom: + BUS_SET_OOM (error); + /* fall through */ +failed: + _DBUS_ASSERT_ERROR_IS_SET (error); + + if (reply != NULL) + dbus_message_unref (reply); + + return FALSE; +} + +dbus_bool_t +bus_containers_handle_get_container_instance_info (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + BusContext *context; + BusContainers *containers; + BusContainerInstance *instance = NULL; + DBusMessage *reply = NULL; + DBusMessageIter writer; + const char *path; + + if (!dbus_message_get_args (message, error, + DBUS_TYPE_OBJECT_PATH, &path, + DBUS_TYPE_INVALID)) + goto failed; + + context = bus_transaction_get_context (transaction); + containers = bus_context_get_containers (context); + + if (containers->instances_by_path != NULL) + { + instance = _dbus_hash_table_lookup_string (containers->instances_by_path, + path); + } + + if (instance == NULL) + { + dbus_set_error (error, DBUS_ERROR_NOT_CONTAINER, + "There is no container with path '%s'", path); + goto failed; + } + + reply = dbus_message_new_method_return (message); + + if (reply == NULL) + goto oom; + + if (!dbus_message_append_args (reply, + DBUS_TYPE_STRING, &instance->type, + DBUS_TYPE_STRING, &instance->name, + DBUS_TYPE_INVALID)) + goto oom; + + dbus_message_iter_init_append (reply, &writer); + + if (!_dbus_variant_write (instance->metadata, &writer)) + goto oom; + + if (!bus_transaction_send_from_driver (transaction, connection, reply)) + goto oom; + + dbus_message_unref (reply); + return TRUE; + +oom: + BUS_SET_OOM (error); + /* fall through */ +failed: + _DBUS_ASSERT_ERROR_IS_SET (error); + + if (reply != NULL) + dbus_message_unref (reply); + + return FALSE; +} + #else BusContainers * diff --git a/bus/containers.h b/bus/containers.h index 4fff8ae3..731d8e43 100644 --- a/bus/containers.h +++ b/bus/containers.h @@ -44,6 +44,16 @@ dbus_bool_t bus_containers_handle_stop_container_listening (DBusConnection *conn DBusMessage *message, DBusError *error); +dbus_bool_t bus_containers_handle_get_container_instance_info (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error); + +dbus_bool_t bus_containers_handle_get_connection_container_instance (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error); + dbus_bool_t bus_containers_supported_arguments_getter (BusContext *context, DBusMessageIter *var_iter); diff --git a/bus/driver.c b/bus/driver.c index a261a199..41e96c1e 100644 --- a/bus/driver.c +++ b/bus/driver.c @@ -2580,6 +2580,12 @@ static const MessageHandler containers_message_handlers[] = { { "StopContainerListening", "o", "", bus_containers_handle_stop_container_listening, METHOD_FLAG_PRIVILEGED }, + { "GetConnectionContainerInstance", "s", "ossa{sv}", + bus_containers_handle_get_connection_container_instance, + METHOD_FLAG_NONE }, + { "GetContainerInstanceInfo", "o", "ssa{sv}", + bus_containers_handle_get_container_instance_info, + METHOD_FLAG_NONE }, { NULL, NULL, NULL, NULL } }; static const PropertyHandler containers_property_handlers[] = { -- 2.11.0