From d2e6554dfd702c91b353aaff5442726e43a6d011 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 2 Jun 2017 11:59:08 +0100 Subject: [PATCH 06/10] driver: Implement the Peer interface, for completeness Signed-off-by: Simon McVittie --- bus/driver.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++- dbus/dbus-internals.h | 1 + 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/bus/driver.c b/bus/driver.c index 373e53eb..ed897411 100644 --- a/bus/driver.c +++ b/bus/driver.c @@ -2289,6 +2289,69 @@ out: return ret; } +static dbus_bool_t +bus_driver_handle_get_machine_id (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + DBusMessage *reply = NULL; + DBusString uuid; + const char *str; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + if (!_dbus_string_init (&uuid)) + { + BUS_SET_OOM (error); + return FALSE; + } + + if (!_dbus_get_local_machine_uuid_encoded (&uuid, error)) + return FALSE; + + reply = dbus_message_new_method_return (message); + + if (reply == NULL) + goto oom; + + str = _dbus_string_get_const_data (&uuid); + + if (!dbus_message_append_args (reply, + DBUS_TYPE_STRING, &str, + DBUS_TYPE_INVALID)) + goto oom; + + _dbus_assert (dbus_message_has_signature (reply, "s")); + + if (!bus_transaction_send_from_driver (transaction, connection, reply)) + goto oom; + + _dbus_string_free (&uuid); + dbus_message_unref (reply); + return TRUE; + +oom: + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + BUS_SET_OOM (error); + + if (reply != NULL) + dbus_message_unref (reply); + + _dbus_string_free (&uuid); + return FALSE; +} + +static dbus_bool_t +bus_driver_handle_ping (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + return send_ack_reply (connection, transaction, message, error); +} + static dbus_bool_t bus_driver_handle_get (DBusConnection *connection, BusTransaction *transaction, DBusMessage *message, @@ -2314,6 +2377,7 @@ typedef enum /* Various older methods were available at every object path. We have to * preserve that behaviour for backwards compatibility, but we can at least * stop doing that for newly added methods. + * The special Peer interface should also work at any object path. * */ METHOD_FLAG_ANY_PATH = (1 << 0), @@ -2491,13 +2555,20 @@ static const MessageHandler stats_message_handlers[] = { }; #endif +static const MessageHandler peer_message_handlers[] = { + { "GetMachineId", "", "s", bus_driver_handle_get_machine_id, + METHOD_FLAG_ANY_PATH }, + { "Ping", "", "", bus_driver_handle_ping, METHOD_FLAG_ANY_PATH }, + { NULL, NULL, NULL, NULL } +}; + typedef enum { /* Various older interfaces were available at every object path. We have to * preserve that behaviour for backwards compatibility, but we can at least * stop doing that for newly added interfaces: * - * Introspectable is also useful at all object paths. */ + * Introspectable and Peer are also useful at all object paths. */ INTERFACE_FLAG_ANY_PATH = (1 << 0), /* Set this flag for interfaces that should not show up in the @@ -2560,6 +2631,11 @@ static InterfaceHandler interface_handlers[] = { { BUS_INTERFACE_STATS, stats_message_handlers, NULL, INTERFACE_FLAG_NONE }, #endif + { DBUS_INTERFACE_PEER, peer_message_handlers, NULL, + /* Not in the Interfaces property because it's a pseudo-interface + * on all object paths of all connections, rather than a feature of the + * bus driver object. */ + INTERFACE_FLAG_ANY_PATH | INTERFACE_FLAG_UNINTERESTING }, { NULL, NULL, NULL } }; diff --git a/dbus/dbus-internals.h b/dbus/dbus-internals.h index beff1e23..4af106ef 100644 --- a/dbus/dbus-internals.h +++ b/dbus/dbus-internals.h @@ -409,6 +409,7 @@ dbus_bool_t _dbus_write_uuid_file (const DBusString *filename, const DBusGUID *uuid, DBusError *error); +DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_get_local_machine_uuid_encoded (DBusString *uuid_str, DBusError *error); -- 2.11.0