From: Marc-André Lureau Date: Tue, 8 Feb 2022 09:04:33 +0000 (+0400) Subject: dbus: handle unix transport in a new common function X-Git-Tag: dbus-1.15.0~26^2~21 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ed838d41693dc49ec6ea7875fb07139f3074c788;p=thirdparty%2Fdbus.git dbus: handle unix transport in a new common function 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 --- diff --git a/dbus/dbus-transport-unix.c b/dbus/dbus-transport-unix.c index 574fd1634..9931da514 100644 --- a/dbus/dbus-transport-unix.c +++ b/dbus/dbus-transport-unix.c @@ -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; diff --git a/dbus/dbus-transport-unix.h b/dbus/dbus-transport-unix.h index 5124e0b6d..952fa0a45 100644 --- a/dbus/dbus-transport-unix.h +++ b/dbus/dbus-transport-unix.h @@ -23,7 +23,7 @@ #ifndef DBUS_TRANSPORT_UNIX_H #define DBUS_TRANSPORT_UNIX_H -#include +#include 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 diff --git a/dbus/dbus-transport.c b/dbus/dbus-transport.c index 592abf9f8..9e189f840 100644 --- a/dbus/dbus-transport.c +++ b/dbus/dbus-transport.c @@ -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