dbus/dbus dbus-address.c, 1.20, 1.21 dbus-internals.h, 1.58,
1.59 dbus-server-debug-pipe.c, 1.22,
1.23 dbus-server-debug-pipe.h, 1.6,
1.7 dbus-server-protected.h, 1.21, 1.22 dbus-server-socket.c,
1.1, 1.2 dbus-server-unix.c, 1.32, 1.33 dbus-server.c, 1.47,
1.48 dbus-transport-protected.h, 1.19,
1.20 dbus-transport-socket.c, 1.1, 1.2 dbus-transport-socket.h,
1.1, 1.2 dbus-transport-unix.c, 1.53, 1.54 dbus-transport.c,
1.50, 1.51
Havoc Pennington
hp at kemper.freedesktop.org
Sat Sep 16 12:24:10 PDT 2006
Update of /cvs/dbus/dbus/dbus
In directory kemper:/tmp/cvs-serv20606/dbus
Modified Files:
dbus-address.c dbus-internals.h dbus-server-debug-pipe.c
dbus-server-debug-pipe.h dbus-server-protected.h
dbus-server-socket.c dbus-server-unix.c dbus-server.c
dbus-transport-protected.h dbus-transport-socket.c
dbus-transport-socket.h dbus-transport-unix.c dbus-transport.c
Log Message:
2006-09-16 Havoc Pennington <hp at redhat.com>
* dbus/dbus-transport.c (_dbus_transport_open): modify to delegate
to _dbus_transport_open_platform_specific,
_dbus_transport_open_socket,
and _dbus_transport_open_debug_pipe
* dbus/dbus-transport-protected.h: add _dbus_transport_open_platform_specific
Index: dbus-address.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-address.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- dbus-address.c 11 Aug 2006 15:37:11 -0000 1.20
+++ dbus-address.c 16 Sep 2006 19:24:08 -0000 1.21
@@ -48,6 +48,81 @@
DBusList *values; /**< List of values */
};
+
+void
+_dbus_set_bad_address (DBusError *error,
+ const char *address_problem_type,
+ const char *address_problem_field,
+ const char *address_problem_other)
+{
+ if (address_problem_type != NULL)
+ dbus_set_error (error, DBUS_ERROR_BAD_ADDRESS,
+ "Server address of type %s was missing argument %s",
+ address_problem_type, address_problem_field);
+ else
+ dbus_set_error (error, DBUS_ERROR_BAD_ADDRESS,
+ "Could not parse server address: %s",
+ address_problem_other);
+}
+
+#define _DBUS_ADDRESS_OPTIONALLY_ESCAPED_BYTE(b) \
+ (((b) >= 'a' && (b) <= 'z') || \
+ ((b) >= 'A' && (b) <= 'Z') || \
+ ((b) >= '0' && (b) <= '9') || \
+ (b) == '-' || \
+ (b) == '_' || \
+ (b) == '/' || \
+ (b) == '\\' || \
+ (b) == '.')
+
+/**
+ * Appends an escaped version of one string to another string,
+ * using the D-Bus address escaping mechanism
+ *
+ * @param escaped the string to append to
+ * @param unescaped the string to escape
+ * @returns #FALSE if no memory
+ */
+dbus_bool_t
+_dbus_address_append_escaped (DBusString *escaped,
+ const DBusString *unescaped)
+{
+ const char *p;
+ const char *end;
+ dbus_bool_t ret;
+ int orig_len;
+
+ ret = FALSE;
+
+ orig_len = _dbus_string_get_length (escaped);
+ p = _dbus_string_get_const_data (unescaped);
+ end = p + _dbus_string_get_length (unescaped);
+ while (p != end)
+ {
+ if (_DBUS_ADDRESS_OPTIONALLY_ESCAPED_BYTE (*p))
+ {
+ if (!_dbus_string_append_byte (escaped, *p))
+ goto out;
+ }
+ else
+ {
+ if (!_dbus_string_append_byte (escaped, '%'))
+ goto out;
+ if (!_dbus_string_append_byte_as_hex (escaped, *p))
+ goto out;
+ }
+
+ ++p;
+ }
+
+ ret = TRUE;
+
+ out:
+ if (!ret)
+ _dbus_string_set_length (escaped, orig_len);
+ return ret;
+}
+
/** @} */ /* End of internals */
static void
@@ -165,64 +240,6 @@
return NULL;
}
-#define _DBUS_ADDRESS_OPTIONALLY_ESCAPED_BYTE(b) \
- (((b) >= 'a' && (b) <= 'z') || \
- ((b) >= 'A' && (b) <= 'Z') || \
- ((b) >= '0' && (b) <= '9') || \
- (b) == '-' || \
- (b) == '_' || \
- (b) == '/' || \
- (b) == '\\' || \
- (b) == '.')
-
-/**
- * Appends an escaped version of one string to another string,
- * using the D-Bus address escaping mechanism
- *
- * @param escaped the string to append to
- * @param unescaped the string to escape
- * @returns #FALSE if no memory
- */
-dbus_bool_t
-_dbus_address_append_escaped (DBusString *escaped,
- const DBusString *unescaped)
-{
- const char *p;
- const char *end;
- dbus_bool_t ret;
- int orig_len;
-
- ret = FALSE;
-
- orig_len = _dbus_string_get_length (escaped);
- p = _dbus_string_get_const_data (unescaped);
- end = p + _dbus_string_get_length (unescaped);
- while (p != end)
- {
- if (_DBUS_ADDRESS_OPTIONALLY_ESCAPED_BYTE (*p))
- {
- if (!_dbus_string_append_byte (escaped, *p))
- goto out;
- }
- else
- {
- if (!_dbus_string_append_byte (escaped, '%'))
- goto out;
- if (!_dbus_string_append_byte_as_hex (escaped, *p))
- goto out;
- }
-
- ++p;
- }
-
- ret = TRUE;
-
- out:
- if (!ret)
- _dbus_string_set_length (escaped, orig_len);
- return ret;
-}
-
static dbus_bool_t
append_unescaped_value (DBusString *unescaped,
const DBusString *escaped,
Index: dbus-internals.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-internals.h,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -d -r1.58 -r1.59
--- dbus-internals.h 11 Sep 2006 15:05:21 -0000 1.58
+++ dbus-internals.h 16 Sep 2006 19:24:08 -0000 1.59
@@ -293,6 +293,12 @@
dbus_bool_t _dbus_address_append_escaped (DBusString *escaped,
const DBusString *unescaped);
+void _dbus_set_bad_address (DBusError *error,
+ const char *address_problem_type,
+ const char *address_problem_field,
+ const char *address_problem_other);
+
+
DBUS_END_DECLS
#endif /* DBUS_INTERNALS_H */
Index: dbus-server-debug-pipe.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-server-debug-pipe.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- dbus-server-debug-pipe.c 16 Sep 2006 17:38:24 -0000 1.22
+++ dbus-server-debug-pipe.c 16 Sep 2006 19:24:08 -0000 1.23
@@ -350,8 +350,8 @@
if (name == NULL)
{
- _dbus_server_set_bad_address(error, "debug-pipe", "name",
- NULL);
+ _dbus_set_bad_address(error, "debug-pipe", "name",
+ NULL);
return DBUS_SERVER_LISTEN_BAD_ADDRESS;
}
@@ -375,6 +375,48 @@
}
}
+DBusTransportOpenResult
+_dbus_transport_open_debug_pipe (DBusAddressEntry *entry,
+ DBusTransport **transport_p,
+ DBusError *error)
+{
+ const char *method;
+
+ method = dbus_address_entry_get_method (entry);
+ _dbus_assert (method != NULL);
+
+ if (strcmp (method, "debug-pipe") == 0)
+ {
+ const char *name = dbus_address_entry_get_value (entry, "name");
+
+ if (name == NULL)
+ {
+ _dbus_set_bad_address (error, "debug-pipe", "name",
+ NULL);
+ return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
+ }
+
+ *transport_p = _dbus_transport_debug_pipe_new (name, error);
+
+ if (*transport_p == NULL)
+ {
+ _DBUS_ASSERT_ERROR_IS_SET (error);
+ return DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT;
+ }
+ else
+ {
+ _DBUS_ASSERT_ERROR_IS_CLEAR (error);
+ return DBUS_TRANSPORT_OPEN_OK;
+ }
+ }
+ else
+ {
+ _DBUS_ASSERT_ERROR_IS_CLEAR (error);
+ return DBUS_TRANSPORT_OPEN_NOT_HANDLED;
+ }
+}
+
+
/** @} */
#endif /* DBUS_BUILD_TESTS */
Index: dbus-server-debug-pipe.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-server-debug-pipe.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- dbus-server-debug-pipe.h 16 Sep 2006 17:38:24 -0000 1.6
+++ dbus-server-debug-pipe.h 16 Sep 2006 19:24:08 -0000 1.7
@@ -26,17 +26,20 @@
#include <dbus/dbus-internals.h>
#include <dbus/dbus-server-protected.h>
-#include <dbus/dbus-transport.h>
+#include <dbus/dbus-transport-protected.h>
DBUS_BEGIN_DECLS
-DBusServer* _dbus_server_debug_pipe_new (const char *server_name,
- DBusError *error);
-DBusTransport* _dbus_transport_debug_pipe_new (const char *server_name,
- DBusError *error);
-DBusServerListenResult _dbus_server_listen_debug_pipe (DBusAddressEntry *entry,
- DBusServer **server_p,
- DBusError *error);
+DBusServer* _dbus_server_debug_pipe_new (const char *server_name,
+ DBusError *error);
+DBusTransport* _dbus_transport_debug_pipe_new (const char *server_name,
+ DBusError *error);
+DBusServerListenResult _dbus_server_listen_debug_pipe (DBusAddressEntry *entry,
+ DBusServer **server_p,
+ DBusError *error);
+DBusTransportOpenResult _dbus_transport_open_debug_pipe (DBusAddressEntry *entry,
+ DBusTransport **transport_p,
+ DBusError *error);
DBUS_END_DECLS
Index: dbus-server-protected.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-server-protected.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- dbus-server-protected.h 16 Sep 2006 17:38:24 -0000 1.21
+++ dbus-server-protected.h 16 Sep 2006 19:24:08 -0000 1.22
@@ -133,10 +133,6 @@
DBusServerListenResult _dbus_server_listen_platform_specific (DBusAddressEntry *entry,
DBusServer **server_p,
DBusError *error);
-void _dbus_server_set_bad_address (DBusError *error,
- const char *address_problem_type,
- const char *address_problem_field,
- const char *address_problem_other);
#ifdef DBUS_DISABLE_CHECKS
#define TOOK_LOCK_CHECK(server)
Index: dbus-server-socket.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-server-socket.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- dbus-server-socket.c 16 Sep 2006 17:38:24 -0000 1.1
+++ dbus-server-socket.c 16 Sep 2006 19:24:08 -0000 1.2
@@ -400,7 +400,7 @@
if (port == NULL)
{
- _dbus_server_set_bad_address(error, "tcp", "port", NULL);
+ _dbus_set_bad_address(error, "tcp", "port", NULL);
return DBUS_SERVER_LISTEN_BAD_ADDRESS;
}
@@ -410,8 +410,8 @@
if (sresult == FALSE || lport <= 0 || lport > 65535)
{
- _dbus_server_set_bad_address(error, NULL, NULL,
- "Port is not an integer between 0 and 65535");
+ _dbus_set_bad_address(error, NULL, NULL,
+ "Port is not an integer between 0 and 65535");
return DBUS_SERVER_LISTEN_BAD_ADDRESS;
}
Index: dbus-server-unix.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-server-unix.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- dbus-server-unix.c 16 Sep 2006 17:38:24 -0000 1.32
+++ dbus-server-unix.c 16 Sep 2006 19:24:08 -0000 1.33
@@ -67,9 +67,9 @@
if (path == NULL && tmpdir == NULL && abstract == NULL)
{
- _dbus_server_set_bad_address(error, "unix",
- "path or tmpdir or abstract",
- NULL);
+ _dbus_set_bad_address(error, "unix",
+ "path or tmpdir or abstract",
+ NULL);
return DBUS_SERVER_LISTEN_BAD_ADDRESS;
}
@@ -77,8 +77,8 @@
(path && abstract) ||
(tmpdir && abstract))
{
- _dbus_server_set_bad_address(error, NULL, NULL,
- "cannot specify two of \"path\" and \"tmpdir\" and \"abstract\" at the same time");
+ _dbus_set_bad_address(error, NULL, NULL,
+ "cannot specify two of \"path\" and \"tmpdir\" and \"abstract\" at the same time");
return DBUS_SERVER_LISTEN_BAD_ADDRESS;
}
Index: dbus-server.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-server.c,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -d -r1.47 -r1.48
--- dbus-server.c 16 Sep 2006 17:38:24 -0000 1.47
+++ dbus-server.c 16 Sep 2006 19:24:08 -0000 1.48
@@ -442,22 +442,6 @@
enabled);
}
-void
-_dbus_server_set_bad_address (DBusError *error,
- const char *address_problem_type,
- const char *address_problem_field,
- const char *address_problem_other)
-{
- if (address_problem_type != NULL)
- dbus_set_error (error, DBUS_ERROR_BAD_ADDRESS,
- "Server address of type %s was missing argument %s",
- address_problem_type, address_problem_field);
- else
- dbus_set_error (error, DBUS_ERROR_BAD_ADDRESS,
- "Could not parse server address: %s",
- address_problem_other);
-}
-
/** @} */
/**
@@ -493,7 +477,11 @@
/**
* Listens for new connections on the given address.
- * Returns #NULL if listening fails for any reason.
+ * If there are multiple address entries in the address,
+ * tries each one and listens on the first one that
+ * works.
+ *
+ * Returns #NULL and sets error if listening fails for any reason.
* Otherwise returns a new #DBusServer.
* dbus_server_set_new_connection_function() and
* dbus_server_set_watch_functions() should be called
Index: dbus-transport-protected.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-transport-protected.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- dbus-transport-protected.h 16 Sep 2006 17:38:24 -0000 1.19
+++ dbus-transport-protected.h 16 Sep 2006 19:24:08 -0000 1.20
@@ -120,6 +120,17 @@
void _dbus_transport_finalize_base (DBusTransport *transport);
+typedef enum
+{
+ DBUS_TRANSPORT_OPEN_NOT_HANDLED, /**< we aren't in charge of this address type */
+ DBUS_TRANSPORT_OPEN_OK, /**< we set up the listen */
+ DBUS_TRANSPORT_OPEN_BAD_ADDRESS, /**< malformed address */
+ DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT /**< well-formed address but failed to set it up */
+} DBusTransportOpenResult;
+
+DBusTransportOpenResult _dbus_transport_open_platform_specific (DBusAddressEntry *entry,
+ DBusTransport **transport_p,
+ DBusError *error);
DBUS_END_DECLS
Index: dbus-transport-socket.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-transport-socket.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- dbus-transport-socket.c 16 Sep 2006 17:38:24 -0000 1.1
+++ dbus-transport-socket.c 16 Sep 2006 19:24:08 -0000 1.2
@@ -1251,5 +1251,59 @@
return NULL;
}
+DBusTransportOpenResult
+_dbus_transport_open_socket(DBusAddressEntry *entry,
+ DBusTransport **transport_p,
+ DBusError *error)
+{
+ const char *method;
+
+ method = dbus_address_entry_get_method (entry);
+ _dbus_assert (method != NULL);
+
+ if (strcmp (method, "tcp") == 0)
+ {
+ const char *host = dbus_address_entry_get_value (entry, "host");
+ const char *port = dbus_address_entry_get_value (entry, "port");
+ DBusString str;
+ long lport;
+ dbus_bool_t sresult;
+
+ if (port == NULL)
+ {
+ _dbus_set_bad_address (error, "tcp", "port", NULL);
+ return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
+ }
+
+ _dbus_string_init_const (&str, port);
+ sresult = _dbus_string_parse_int (&str, 0, &lport, NULL);
+ _dbus_string_free (&str);
+
+ if (sresult == FALSE || lport <= 0 || lport > 65535)
+ {
+ _dbus_set_bad_address (error, NULL, NULL,
+ "Port is not an integer between 0 and 65535");
+ return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
+ }
+
+ *transport_p = _dbus_transport_new_for_tcp_socket (host, lport, error);
+ if (*transport_p == NULL)
+ {
+ _DBUS_ASSERT_ERROR_IS_SET (error);
+ return DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT;
+ }
+ else
+ {
+ _DBUS_ASSERT_ERROR_IS_CLEAR (error);
+ return DBUS_TRANSPORT_OPEN_OK;
+ }
+ }
+ else
+ {
+ _DBUS_ASSERT_ERROR_IS_CLEAR (error);
+ return DBUS_TRANSPORT_OPEN_NOT_HANDLED;
+ }
+}
+
/** @} */
Index: dbus-transport-socket.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-transport-socket.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- dbus-transport-socket.h 16 Sep 2006 17:38:24 -0000 1.1
+++ dbus-transport-socket.h 16 Sep 2006 19:24:08 -0000 1.2
@@ -23,16 +23,20 @@
#ifndef DBUS_TRANSPORT_SOCKET_H
#define DBUS_TRANSPORT_SOCKET_H
-#include <dbus/dbus-transport.h>
+#include <dbus/dbus-transport-protected.h>
DBUS_BEGIN_DECLS
-DBusTransport* _dbus_transport_new_for_socket (int fd,
- const DBusString *server_guid,
- const DBusString *address);
-DBusTransport* _dbus_transport_new_for_tcp_socket (const char *host,
- dbus_int32_t port,
- DBusError *error);
+DBusTransport* _dbus_transport_new_for_socket (int fd,
+ const DBusString *server_guid,
+ const DBusString *address);
+DBusTransport* _dbus_transport_new_for_tcp_socket (const char *host,
+ dbus_int32_t port,
+ DBusError *error);
+DBusTransportOpenResult _dbus_transport_open_socket (DBusAddressEntry *entry,
+ DBusTransport **transport_p,
+ DBusError *error);
+
DBUS_END_DECLS
Index: dbus-transport-unix.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-transport-unix.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -d -r1.53 -r1.54
--- dbus-transport-unix.c 16 Sep 2006 17:38:24 -0000 1.53
+++ dbus-transport-unix.c 16 Sep 2006 19:24:08 -0000 1.54
@@ -24,6 +24,7 @@
#include "dbus-internals.h"
#include "dbus-connection-internal.h"
#include "dbus-transport-unix.h"
+#include "dbus-transport-socket.h"
#include "dbus-transport-protected.h"
#include "dbus-watch.h"
#include "dbus-sysdeps-unix.h"
@@ -107,4 +108,66 @@
return NULL;
}
+DBusTransportOpenResult
+_dbus_transport_open_platform_specific (DBusAddressEntry *entry,
+ DBusTransport **transport_p,
+ DBusError *error)
+{
+ const char *method;
+
+ method = dbus_address_entry_get_method (entry);
+ _dbus_assert (method != NULL);
+
+ if (strcmp (method, "unix") == 0)
+ {
+ 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",
+ "path or abstract",
+ NULL);
+ return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
+ }
+
+ if (path != NULL && abstract != NULL)
+ {
+ _dbus_set_bad_address (error, NULL, NULL,
+ "can't specify both \"path\" and \"abstract\" options in an address");
+ return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
+ }
+
+ if (path)
+ *transport_p = _dbus_transport_new_for_domain_socket (path, FALSE,
+ error);
+ else
+ *transport_p = _dbus_transport_new_for_domain_socket (abstract, TRUE,
+ error);
+ if (*transport_p == NULL)
+ {
+ _DBUS_ASSERT_ERROR_IS_SET (error);
+ return DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT;
+ }
+ else
+ {
+ _DBUS_ASSERT_ERROR_IS_CLEAR (error);
+ return DBUS_TRANSPORT_OPEN_OK;
+ }
+ }
+ else
+ {
+ _DBUS_ASSERT_ERROR_IS_CLEAR (error);
+ return DBUS_TRANSPORT_OPEN_NOT_HANDLED;
+ }
+}
+
/** @} */
Index: dbus-transport.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-transport.c,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -d -r1.50 -r1.51
--- dbus-transport.c 16 Sep 2006 18:46:48 -0000 1.50
+++ dbus-transport.c 16 Sep 2006 19:24:08 -0000 1.51
@@ -201,6 +201,18 @@
dbus_free (transport->expected_guid);
}
+static const struct {
+ DBusTransportOpenResult (* func) (DBusAddressEntry *entry,
+ DBusTransport **transport_p,
+ DBusError *error);
+} open_funcs[] = {
+ { _dbus_transport_open_socket },
+ { _dbus_transport_open_platform_specific }
+#ifdef DBUS_BUILD_TESTS
+ , { _dbus_transport_open_debug_pipe }
+#endif
+};
+
/**
* Try to open a new transport for the given address entry. (This
* opens a client-side-of-the-connection transport.)
@@ -214,19 +226,14 @@
DBusError *error)
{
DBusTransport *transport;
- const char *address_problem_type;
- const char *address_problem_field;
- const char *address_problem_other;
- const char *method;
const char *expected_guid_orig;
char *expected_guid;
-
+ int i;
+ DBusError tmp_error;
+
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
transport = NULL;
- address_problem_type = NULL;
- address_problem_field = NULL;
- address_problem_other = NULL;
expected_guid_orig = dbus_address_entry_get_value (entry, "guid");
expected_guid = _dbus_strdup (expected_guid_orig);
@@ -235,115 +242,56 @@
_DBUS_SET_OOM (error);
return NULL;
}
-
- method = dbus_address_entry_get_method (entry);
- _dbus_assert (method != NULL);
-
- if (strcmp (method, "unix") == 0)
- {
- 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)
- {
- address_problem_other = "cannot use the \"tmpdir\" option for an address to connect to, only in an address to listen on";
- goto bad_address;
- }
-
- if (path == NULL && abstract == NULL)
- {
- address_problem_type = "unix";
- address_problem_field = "path or abstract";
- goto bad_address;
- }
- if (path != NULL && abstract != NULL)
- {
- address_problem_other = "can't specify both \"path\" and \"abstract\" options in an address";
- goto bad_address;
- }
-
- if (path)
- transport = _dbus_transport_new_for_domain_socket (path, FALSE,
- error);
- else
- transport = _dbus_transport_new_for_domain_socket (abstract, TRUE,
- error);
- }
- else if (strcmp (method, "tcp") == 0)
+ dbus_error_init (&tmp_error);
+ for (i = 0; i < (int) _DBUS_N_ELEMENTS (open_funcs); ++i)
{
- const char *host = dbus_address_entry_get_value (entry, "host");
- const char *port = dbus_address_entry_get_value (entry, "port");
- DBusString str;
- long lport;
- dbus_bool_t sresult;
-
- if (port == NULL)
- {
- address_problem_type = "tcp";
- address_problem_field = "port";
- goto bad_address;
- }
+ DBusTransportOpenResult result;
- _dbus_string_init_const (&str, port);
- sresult = _dbus_string_parse_int (&str, 0, &lport, NULL);
- _dbus_string_free (&str);
-
- if (sresult == FALSE || lport <= 0 || lport > 65535)
- {
- address_problem_other = "Port is not an integer between 0 and 65535";
- goto bad_address;
- }
-
- transport = _dbus_transport_new_for_tcp_socket (host, lport, error);
- }
-#ifdef DBUS_BUILD_TESTS
- else if (strcmp (method, "debug-pipe") == 0)
- {
- const char *name = dbus_address_entry_get_value (entry, "name");
+ _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
+ result = (* open_funcs[i].func) (entry, &transport, &tmp_error);
- if (name == NULL)
+ switch (result)
{
- address_problem_type = "debug-pipe";
- address_problem_field = "name";
- goto bad_address;
+ case DBUS_TRANSPORT_OPEN_OK:
+ _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
+ goto out;
+ break;
+ case DBUS_TRANSPORT_OPEN_NOT_HANDLED:
+ _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
+ /* keep going through the loop of open funcs */
+ break;
+ case DBUS_TRANSPORT_OPEN_BAD_ADDRESS:
+ _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
+ goto out;
+ break;
+ case DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT:
+ _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
+ goto out;
+ break;
}
-
- transport = _dbus_transport_debug_pipe_new (name, error);
- }
-#endif
- else
- {
- address_problem_other = "Unknown address type (examples of valid types are \"unix\" and \"tcp\")";
- goto bad_address;
}
+ out:
+
if (transport == NULL)
{
- _DBUS_ASSERT_ERROR_IS_SET (error);
+ if (!dbus_error_is_set (&tmp_error))
+ _dbus_set_bad_address (&tmp_error,
+ NULL, NULL,
+ "Unknown address type (examples of valid types are \"tcp\" and on UNIX \"unix\")");
+
+ _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
+ dbus_move_error(&tmp_error, error);
dbus_free (expected_guid);
}
else
{
+ _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
transport->expected_guid = expected_guid;
}
-
- return transport;
-
- bad_address:
- dbus_free (expected_guid);
-
- if (address_problem_type != NULL)
- dbus_set_error (error, DBUS_ERROR_BAD_ADDRESS,
- "Address of type %s was missing argument %s",
- address_problem_type, address_problem_field);
- else
- dbus_set_error (error, DBUS_ERROR_BAD_ADDRESS,
- "Could not parse address: %s",
- address_problem_other);
- return NULL;
+ return transport;
}
/**
More information about the dbus-commit
mailing list