]> 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 13:29:52 +0000 (14:29 +0100)
dbus/dbus-connection-internal.h
dbus/dbus-connection.c

index de4e55b1c162789ca4d48deb26201f418cf63bc2..d6947d181dbedeb72bd49c97ea087a8b93a714ca 100644 (file)
@@ -120,6 +120,9 @@ dbus_bool_t       _dbus_connection_get_linux_security_label       (DBusConnectio
                                                                    char           **label_p);
 DBUS_PRIVATE_EXPORT
 DBusCredentials  *_dbus_connection_get_credentials                (DBusConnection  *connection);
+DBUS_PRIVATE_EXPORT
+void              _dbus_connection_set_builtin_filters_enabled    (DBusConnection  *connection,
+                                                                   dbus_bool_t      value);
 
 /* if DBUS_ENABLE_STATS */
 DBUS_PRIVATE_EXPORT
index 159dbe1b6a6a562e9ee86ee7281ed9b4b7cbc3af..a61e56a6d291826049f12f430ee9da682d3d5bb8 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_assert (connection != NULL);
+
+  CONNECTION_LOCK (connection);
+  connection->builtin_filters_enabled = value;
+  CONNECTION_UNLOCK (connection);
+}
+
 /**
  *
  * Normally #DBusConnection automatically handles all messages to the