]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
dbus-connection: Add builtin_filters_enabled flag
authorKai A. Hiller <V02460@gmail.com>
Mon, 19 Sep 2022 12:30:35 +0000 (14:30 +0200)
committerSimon McVittie <smcv@collabora.com>
Tue, 11 Oct 2022 10:50:08 +0000 (10:50 +0000)
dbus/dbus-connection.c
dbus/dbus-connection.h

index 159dbe1b6a6a562e9ee86ee7281ed9b4b7cbc3af..5841d81744e8d7d57a2c1ed0a6bf4a58f9f308ec 100644 (file)
@@ -316,6 +316,8 @@ struct DBusConnection
   
   unsigned int exit_on_disconnect : 1; /**< If #TRUE, exit after handling disconnect signal */
 
+  unsigned int builtin_filters_enabled : 1; /**< If #TRUE, handle org.freedesktop.DBus.Peer messages automatically, whether they have a bus name or not */
+
   unsigned int route_peer_messages : 1; /**< If #TRUE, if org.freedesktop.DBus.Peer messages have a bus name, don't handle them automatically */
 
   unsigned int disconnected_message_arrived : 1;   /**< We popped or are dispatching the disconnected message.
@@ -1343,6 +1345,7 @@ _dbus_connection_new_for_transport (DBusTransport *transport)
   connection->objects = objects;
   connection->exit_on_disconnect = FALSE;
   connection->shareable = FALSE;
+  connection->builtin_filters_enabled = TRUE;
   connection->route_peer_messages = FALSE;
   connection->disconnected_message_arrived = FALSE;
   connection->disconnected_message_processed = FALSE;
@@ -4657,10 +4660,14 @@ dbus_connection_dispatch (DBusConnection *connection)
       goto out;
     }
 
-  result = _dbus_connection_run_builtin_filters_unlocked_no_update (connection, message);
-  if (result != DBUS_HANDLER_RESULT_NOT_YET_HANDLED)
-    goto out;
+  /* If skipping builtin filters, we are probably a monitor. */
+  if (connection->builtin_filters_enabled)
+    {
+      result = _dbus_connection_run_builtin_filters_unlocked_no_update (connection, message);
+      if (result != DBUS_HANDLER_RESULT_NOT_YET_HANDLED)
+        goto out;
+    }
+
   if (!_dbus_list_copy (&connection->filter_list, &filter_list_copy))
     {
       _dbus_connection_release_dispatch (connection);
@@ -5532,6 +5539,38 @@ dbus_connection_set_allow_anonymous (DBusConnection             *connection,
   CONNECTION_UNLOCK (connection);
 }
 
+/**
+ * Enables the builtin filtering of messages.
+ *
+ * Currently the only filtering implemented by libdbus and mandated by the spec
+ * is that of peer messages.
+ *
+ * If #TRUE, #DBusConnection automatically handles all messages to the
+ * org.freedesktop.DBus.Peer interface. For monitors this can break the
+ * specification if the response is sending a message.
+ *
+ * If #FALSE, the result is similar to calling
+ * dbus_connection_set_route_peer_messages() with argument TRUE, but
+ * messages with a NULL destination are also dispatched to the
+ * application instead of being passed to the built-in filters.
+ *
+ * If a normal application disables this flag, it can break things badly. So
+ * only unset this if you are a monitor.
+ *
+ * @param connection the connection
+ * @param value #TRUE to pass through org.freedesktop.DBus.Peer messages
+ */
+void
+dbus_connection_set_builtin_filters_enabled (DBusConnection         *connection,
+                                             dbus_bool_t             value)
+{
+  _dbus_return_if_fail (connection != NULL);
+
+  CONNECTION_LOCK (connection);
+  connection->builtin_filters_enabled = value;
+  CONNECTION_UNLOCK (connection);
+}
+
 /**
  *
  * Normally #DBusConnection automatically handles all messages to the
index 32d79979b6071779d70760c8cd82cccbb9cb7f13..5d9f244dd1b123d26fe2f52b80de96b12063653a 100644 (file)
@@ -286,6 +286,9 @@ DBUS_EXPORT
 void               dbus_connection_set_allow_anonymous          (DBusConnection             *connection,
                                                                  dbus_bool_t                 value);
 DBUS_EXPORT
+void               dbus_connection_set_builtin_filters_enabled  (DBusConnection             *connection,
+                                                                 dbus_bool_t                 value);
+DBUS_EXPORT
 void               dbus_connection_set_route_peer_messages      (DBusConnection             *connection,
                                                                  dbus_bool_t                 value);