]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
dbus: handle unix transport in a new common function
authorMarc-André Lureau <marcandre.lureau@redhat.com>
Tue, 8 Feb 2022 09:04:33 +0000 (13:04 +0400)
committerSimon McVittie <smcv@collabora.com>
Fri, 15 Jul 2022 15:26:18 +0000 (16:26 +0100)
Split out the Unix socket handling from open_platform_specific(),
enabling "unix:" connectable addresses on Windows in next patch.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
dbus/dbus-transport-unix.c
dbus/dbus-transport-unix.h
dbus/dbus-transport.c

index 574fd16340aa32d24639e626b6c59e2bcac6aa17..9931da5141d23611d5c08e993572588c7bc48fef 100644 (file)
@@ -210,20 +210,20 @@ _dbus_transport_new_for_exec (const char     *path,
 }
 
 /**
- * Opens platform specific transport types.
- * 
- * @param entry the address entry to try opening
+ * Opens a UNIX socket transport.
+ *
+ * @param entry the address entry to try opening as a unix transport.
  * @param transport_p return location for the opened transport
  * @param error error to be set
  * @returns result of the attempt
  */
 DBusTransportOpenResult
-_dbus_transport_open_platform_specific (DBusAddressEntry  *entry,
-                                        DBusTransport    **transport_p,
-                                        DBusError         *error)
+_dbus_transport_open_unix_socket (DBusAddressEntry  *entry,
+                                  DBusTransport    **transport_p,
+                                  DBusError         *error)
 {
   const char *method;
-  
+
   method = dbus_address_entry_get_method (entry);
   _dbus_assert (method != NULL);
 
@@ -232,14 +232,14 @@ _dbus_transport_open_platform_specific (DBusAddressEntry  *entry,
       const char *path = dbus_address_entry_get_value (entry, "path");
       const char *tmpdir = dbus_address_entry_get_value (entry, "tmpdir");
       const char *abstract = dbus_address_entry_get_value (entry, "abstract");
-          
+
       if (tmpdir != NULL)
         {
           _dbus_set_bad_address (error, NULL, NULL,
                                  "cannot use the \"tmpdir\" option for an address to connect to, only in an address to listen on");
           return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
         }
-          
+
       if (path == NULL && abstract == NULL)
         {
           _dbus_set_bad_address (error, "unix",
@@ -346,8 +346,33 @@ _dbus_transport_open_platform_specific (DBusAddressEntry  *entry,
           return DBUS_TRANSPORT_OPEN_OK;
         }
     }
+  else
+    {
+      _DBUS_ASSERT_ERROR_IS_CLEAR (error);
+      return DBUS_TRANSPORT_OPEN_NOT_HANDLED;
+    }
+}
+
+/**
+ * Opens platform specific transport types.
+ *
+ * @param entry the address entry to try opening
+ * @param transport_p return location for the opened transport
+ * @param error error to be set
+ * @returns result of the attempt
+ */
+DBusTransportOpenResult
+_dbus_transport_open_platform_specific (DBusAddressEntry  *entry,
+                                        DBusTransport    **transport_p,
+                                        DBusError         *error)
+{
 #ifdef DBUS_ENABLE_LAUNCHD
-  else if (strcmp (method, "launchd") == 0)
+  const char *method;
+
+  method = dbus_address_entry_get_method (entry);
+  _dbus_assert (method != NULL);
+
+  if (strcmp (method, "launchd") == 0)
     {
       DBusError tmp_error = DBUS_ERROR_INIT;
       const char *launchd_env_var = dbus_address_entry_get_value (entry, "env");
@@ -398,8 +423,8 @@ _dbus_transport_open_platform_specific (DBusAddressEntry  *entry,
           return DBUS_TRANSPORT_OPEN_OK;
         }
     }
-#endif
   else
+#endif /* DBUS_ENABLE_LAUNCHD */
     {
       _DBUS_ASSERT_ERROR_IS_CLEAR (error);
       return DBUS_TRANSPORT_OPEN_NOT_HANDLED;
index 5124e0b6d4015fb2fb4bfafeb186007f5781f7e3..952fa0a45626e2e5e7880459c7e75ddc8517ef58 100644 (file)
@@ -23,7 +23,7 @@
 #ifndef DBUS_TRANSPORT_UNIX_H
 #define DBUS_TRANSPORT_UNIX_H
 
-#include <dbus/dbus-transport.h>
+#include <dbus/dbus-transport-protected.h>
 
 DBUS_BEGIN_DECLS
 
@@ -31,6 +31,9 @@ DBusTransport* _dbus_transport_new_for_domain_socket (const char       *path,
                                                       dbus_bool_t       abstract,
                                                       DBusError        *error);
 
+DBusTransportOpenResult _dbus_transport_open_unix_socket (DBusAddressEntry  *entry,
+                                                          DBusTransport    **transport_p,
+                                                          DBusError         *error);
 
 DBUS_END_DECLS
 
index 592abf9f8170c5017a8e357e7adedd19a3a0d511..9e189f84074d33463d09d0f06fe6a5f334b7b5f3 100644 (file)
@@ -348,6 +348,9 @@ static const struct {
                                     DBusError        *error);
 } open_funcs[] = {
   { _dbus_transport_open_socket },
+#ifndef _WIN32 /* FIXME: removed in next patch */
+  { _dbus_transport_open_unix_socket },
+#endif
   { _dbus_transport_open_platform_specific },
   { _dbus_transport_open_autolaunch }
 #ifdef DBUS_ENABLE_EMBEDDED_TESTS