diff options
author | Simon McVittie <smcv@collabora.com> | 2017-07-21 18:08:40 +0100 |
---|---|---|
committer | Simon McVittie <smcv@collabora.com> | 2017-12-11 16:04:57 +0000 |
commit | 5dee4d49ad01aa0bd7dd1c2d0b2e6e80be093d9c (patch) | |
tree | 08489882c66704efcf2edfa7e3390372c143595e | |
parent | f65b9792439ab39581758e627ca1b42199bf0f87 (diff) |
bus/driver: Add GetConnectionInstance(), GetInstanceInfo()
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101354
-rw-r--r-- | bus/containers.c | 142 | ||||
-rw-r--r-- | bus/containers.h | 8 | ||||
-rw-r--r-- | bus/driver.c | 5 |
3 files changed, 155 insertions, 0 deletions
diff --git a/bus/containers.c b/bus/containers.c index 8f1f71ff..2818a3be 100644 --- a/bus/containers.c +++ b/bus/containers.c @@ -991,6 +991,148 @@ failed: return FALSE; } +dbus_bool_t +bus_containers_handle_get_connection_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); + + dbus_clear_message (&reply); + return FALSE; +} + +dbus_bool_t +bus_containers_handle_get_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); + + dbus_clear_message (&reply); + return FALSE; +} + void bus_containers_stop_listening (BusContainers *self) { diff --git a/bus/containers.h b/bus/containers.h index 2fb4b3aa..05ed0e75 100644 --- a/bus/containers.h +++ b/bus/containers.h @@ -44,6 +44,14 @@ dbus_bool_t bus_containers_handle_stop_listening (DBusConnection *connecti BusTransaction *transaction, DBusMessage *message, DBusError *error); +dbus_bool_t bus_containers_handle_get_instance_info (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error); +dbus_bool_t bus_containers_handle_get_connection_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 ff14ccab..3e42fabc 100644 --- a/bus/driver.c +++ b/bus/driver.c @@ -2576,6 +2576,11 @@ static const MessageHandler containers_message_handlers[] = { METHOD_FLAG_PRIVILEGED }, { "StopListening", "o", "", bus_containers_handle_stop_listening, METHOD_FLAG_PRIVILEGED }, + { "GetConnectionInstance", "s", "ossa{sv}", + bus_containers_handle_get_connection_instance, + METHOD_FLAG_NONE }, + { "GetInstanceInfo", "o", "ssa{sv}", bus_containers_handle_get_instance_info, + METHOD_FLAG_NONE }, { NULL, NULL, NULL, NULL } }; static const PropertyHandler containers_property_handlers[] = { |