From 5ebb5748c2a7587c734eeed9c66f2a1fc0635d09 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Thu, 30 Jan 2003 20:49:11 +0000 Subject: 2003-01-30 Anders Carlsson * dbus/Makefile.am: Add dbus-address.[ch] * dbus/dbus-address.c: (dbus_address_entry_free), (dbus_address_entries_free), (create_entry), (dbus_address_entry_get_method), (dbus_address_entry_get_value), (dbus_parse_address), (_dbus_address_test): * dbus/dbus-address.h: New files for dealing with address parsing. * dbus/dbus-connection.c: Document timeout functions. * dbus/dbus-message.c: Document dbus_message_new_from_message. * dbus/dbus-server-debug.c: Document. * dbus/dbus-server.c: (dbus_server_listen): Parse address and use correct server implementation. * dbus/dbus-string.c: (_dbus_string_find_to), (_dbus_string_test): * dbus/dbus-string.h: New function with test. * dbus/dbus-test.c: (dbus_internal_symbol_do_not_use_run_tests): * dbus/dbus-test.h: Add address tests. * dbus/dbus-transport-debug.c: Document. * dbus/dbus-transport.c: (_dbus_transport_open): Parse address and use correct transport implementation. --- dbus/dbus-transport.c | 56 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 13 deletions(-) (limited to 'dbus/dbus-transport.c') diff --git a/dbus/dbus-transport.c b/dbus/dbus-transport.c index d1f31702..8c923982 100644 --- a/dbus/dbus-transport.c +++ b/dbus/dbus-transport.c @@ -26,6 +26,7 @@ #include "dbus-connection-internal.h" #include "dbus-watch.h" #include "dbus-auth.h" +#include "dbus-address.h" #ifdef DBUS_BUILD_TESTS #include "dbus-transport-debug.h" #endif @@ -194,22 +195,51 @@ _dbus_transport_open (const char *address, DBusResultCode *result) { DBusTransport *transport; + DBusAddressEntry **entries; + int len, i; - /* FIXME parse the address - whatever format - * we decide addresses are in - and find the - * appropriate transport. - */ + if (!dbus_parse_address (address, &entries, &len, result)) + return NULL; -#if 1 - /* Pretend it's just a unix domain socket name for now */ - transport = _dbus_transport_new_for_domain_socket (address, - FALSE, - result); -#else - transport = _dbus_transport_debug_client_new (address, - result); -#endif + transport = NULL; + + for (i = 0; i < len; i++) + { + const char *method = dbus_address_entry_get_method (entries[i]); + + if (strcmp (method, "unix") == 0) + { + const char *path = dbus_address_entry_get_value (entries[i], "path"); + + if (path == NULL) + goto bad_address; + + transport = _dbus_transport_new_for_domain_socket (path, FALSE, result); + } + else if (strcmp (method, "debug") == 0) + { + const char *name = dbus_address_entry_get_value (entries[i], "name"); + + if (name == NULL) + goto bad_address; + + transport = _dbus_transport_debug_client_new (name, result); + } + else + goto bad_address; + + if (transport) + break; + } + + dbus_address_entries_free (entries); return transport; + + bad_address: + dbus_address_entries_free (entries); + dbus_set_result (result, DBUS_RESULT_BAD_ADDRESS); + + return NULL; } /** -- cgit