summaryrefslogtreecommitdiffstats
path: root/dbus
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2003-03-20 07:57:39 +0000
committerHavoc Pennington <hp@redhat.com>2003-03-20 07:57:39 +0000
commit056d76d809dc341b0dce160d3f79062604565c77 (patch)
tree1c0518c56526b71f8c4e77b97bb1b6e504339b55 /dbus
parenta284a148e40551a2e6e5d0e54c2e04d2b679aaad (diff)
2003-03-20 Havoc Pennington <hp@pobox.com>
* 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
Diffstat (limited to 'dbus')
-rw-r--r--dbus/dbus-message.c61
-rw-r--r--dbus/dbus-message.h4
2 files changed, 65 insertions, 0 deletions
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);