- 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;
-
- server = _dbus_server_new_for_domain_socket (path, result);
-
- if (server)
- break;
- }
- else if (strcmp (method, "tcp") == 0)
- {
- const char *host = dbus_address_entry_get_value (entries[i], "host");
- const char *port = dbus_address_entry_get_value (entries[i], "port");
- DBusString str;
- long lport;
- dbus_bool_t sresult;
-
- if (port == NULL)
- goto 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)
- goto bad_address;
-
- server = _dbus_server_new_for_tcp_socket (host, lport, result);
-
- if (server)
- break;
- }
-#ifdef DBUS_BUILD_TESTS
- else if (strcmp (method, "debug") == 0)
- {
- const char *name = dbus_address_entry_get_value (entries[i], "name");
-
- if (name == NULL)
- goto bad_address;
-
- server = _dbus_server_debug_new (name, result);
-
- if (server)
- break;
- }
- else if (strcmp (method, "debug-pipe") == 0)
- {
- const char *name = dbus_address_entry_get_value (entries[i], "name");
-
- if (name == NULL)
- goto bad_address;
-
- server = _dbus_server_debug_pipe_new (name, result);
-
- if (server)
- break;
- }
-#endif
+ int j;
+
+ for (j = 0; j < (int) _DBUS_N_ELEMENTS (listen_funcs); ++j)
+ {
+ DBusServerListenResult result;
+ DBusError tmp_error = DBUS_ERROR_INIT;
+
+ result = (* listen_funcs[j].func) (entries[i],
+ &server,
+ &tmp_error);
+
+ if (result == DBUS_SERVER_LISTEN_OK)
+ {
+ _dbus_assert (server != NULL);
+ _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
+ handled_once = TRUE;
+ goto out;
+ }
+ else if (result == DBUS_SERVER_LISTEN_ADDRESS_ALREADY_USED)
+ {
+ _dbus_assert (server == NULL);
+ dbus_set_error (error,
+ DBUS_ERROR_ADDRESS_IN_USE,
+ "Address '%s' already used",
+ dbus_address_entry_get_method (entries[0]));
+ handled_once = TRUE;
+ goto out;
+ }
+ else if (result == DBUS_SERVER_LISTEN_BAD_ADDRESS)
+ {
+ _dbus_assert (server == NULL);
+ _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
+ dbus_move_error (&tmp_error, error);
+ handled_once = TRUE;
+ goto out;
+ }
+ else if (result == DBUS_SERVER_LISTEN_NOT_HANDLED)
+ {
+ _dbus_assert (server == NULL);
+ _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
+
+ /* keep trying addresses */
+ }
+ else if (result == DBUS_SERVER_LISTEN_DID_NOT_CONNECT)
+ {
+ _dbus_assert (server == NULL);
+ _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
+ if (!dbus_error_is_set (&first_connect_error))
+ dbus_move_error (&tmp_error, &first_connect_error);
+ else
+ dbus_error_free (&tmp_error);
+
+ handled_once = TRUE;
+
+ /* keep trying addresses */
+ }
+ }
+
+ _dbus_assert (server == NULL);
+ _DBUS_ASSERT_ERROR_IS_CLEAR (error);
+ }
+
+ out:
+
+ if (!handled_once)
+ {
+ _DBUS_ASSERT_ERROR_IS_CLEAR (error);
+ if (len > 0)
+ dbus_set_error (error,
+ DBUS_ERROR_BAD_ADDRESS,
+ "Unknown address type '%s'",
+ dbus_address_entry_get_method (entries[0]));