From 056d76d809dc341b0dce160d3f79062604565c77 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Thu, 20 Mar 2003 07:57:39 +0000 Subject: 2003-03-20 Havoc Pennington * bus/connection.c (bus_connection_send_oom_error): assert that message has a sender (connection_execute_transaction): ditto (bus_connection_preallocate_oom_error): fix to set the sender, and set recipient to the destination service, not the bus driver * bus/policy.c: hacking * dbus/dbus-message.c (dbus_message_service_is): new function (dbus_message_sender_is): new --- dbus/dbus-message.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++ dbus/dbus-message.h | 4 ++++ 2 files changed, 65 insertions(+) (limited to 'dbus') diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c index defa0585..6366c54e 100644 --- a/dbus/dbus-message.c +++ b/dbus/dbus-message.c @@ -1018,6 +1018,11 @@ dbus_message_get_name (DBusMessage *message) /** * Gets the destination service of a message. * + * @todo I think if we have set_sender/get_sender, + * this function might be better named set_destination/ + * get_destination for clarity, as the sender + * is also a service name. + * * @param message the message * @returns the message destination service (should not be freed) */ @@ -2326,6 +2331,62 @@ dbus_message_name_is (DBusMessage *message, return FALSE; } +/** + * Checks whether the message was sent to the given service. If the + * message has no service specified or has a different name, returns + * #FALSE. + * + * @param message the message + * @param service the service to check (must not be #NULL) + * + * @returns #TRUE if the message has the given destination service + */ +dbus_bool_t +dbus_message_service_is (DBusMessage *message, + const char *service) +{ + const char *s; + + _dbus_assert (service != NULL); + + s = dbus_message_get_service (message); + + if (s && strcmp (s, service) == 0) + return TRUE; + else + return FALSE; +} + +/** + * Checks whether the message has the given service as its sender. If + * the message has no sender specified or has a different sender, + * returns #FALSE. Note that if a peer application owns multiple + * services, its messages will have only one of those services as the + * sender (usually the base service). So you can't use this + * function to prove the sender didn't own service Foo, you can + * only use it to prove that it did. + * + * @param message the message + * @param service the service to check (must not be #NULL) + * + * @returns #TRUE if the message has the given origin service + */ +dbus_bool_t +dbus_message_sender_is (DBusMessage *message, + const char *service) +{ + const char *s; + + _dbus_assert (service != NULL); + + s = dbus_message_get_sender (message); + + if (s && strcmp (s, service) == 0) + return TRUE; + else + return FALSE; +} + /** @} */ /** diff --git a/dbus/dbus-message.h b/dbus/dbus-message.h index 1d5bbeb8..be752c94 100644 --- a/dbus/dbus-message.h +++ b/dbus/dbus-message.h @@ -58,6 +58,10 @@ void dbus_message_set_is_error (DBusMessage *message, dbus_bool_t dbus_message_get_is_error (DBusMessage *message); dbus_bool_t dbus_message_name_is (DBusMessage *message, const char *name); +dbus_bool_t dbus_message_service_is (DBusMessage *message, + const char *service); +dbus_bool_t dbus_message_sender_is (DBusMessage *message, + const char *service); dbus_int32_t dbus_message_get_serial (DBusMessage *message); dbus_bool_t dbus_message_set_reply_serial (DBusMessage *message, dbus_int32_t reply_serial); -- cgit