From c5bccebd1e3b16935cb45d1416990b20cd10973f Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 2 Jun 2017 11:59:08 +0100 Subject: [PATCH 4/9] driver: Implement the Peer interface, for completeness Signed-off-by: Simon McVittie --- bus/driver.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++- dbus/dbus-internals.h | 1 + 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/bus/driver.c b/bus/driver.c index 0c7e3307..ab24118a 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 Interfaces. */ @@ -2550,6 +2621,8 @@ static InterfaceHandler interface_handlers[] = { { BUS_INTERFACE_STATS, stats_message_handlers, NULL, INTERFACE_FLAG_NONE }, #endif + { DBUS_INTERFACE_PEER, peer_message_handlers, NULL, + 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