25 #include "dbus-server.h"
26 #include "dbus-server-unix.h"
27 #include "dbus-server-socket.h"
28 #include "dbus-string.h"
29 #ifdef DBUS_BUILD_TESTS
30 #include "dbus-server-debug-pipe.h"
32 #include "dbus-address.h"
33 #include "dbus-protocol.h"
56 #ifndef _dbus_server_trace_ref
63 static int enabled = -1;
65 _dbus_trace_ref (
"DBusServer", server, old_refcount, new_refcount, why,
66 "DBUS_SERVER_TRACE", &enabled);
74 copy_address_with_guid_appended (
const DBusString *address,
84 _dbus_string_get_length (&with_guid)) ||
87 &with_guid, _dbus_string_get_length (&with_guid)))
117 #ifdef DBUS_DISABLE_ASSERT
140 server->
address = copy_address_with_guid_appended (address,
159 _dbus_verbose (
"Initialized server on address %s\n", server->
address);
198 #ifndef DBUS_DISABLE_CHECKS
243 HAVE_LOCK_CHECK (server);
255 SERVER_UNLOCK (server);
258 retval = (* add_function) (watches, watch);
259 else if (remove_function)
262 (* remove_function) (watches, watch);
267 (* toggle_function) (watches, watch, enabled);
270 SERVER_LOCK (server);
291 HAVE_LOCK_CHECK (server);
292 return protected_change_watch (server, watch,
307 HAVE_LOCK_CHECK (server);
308 protected_change_watch (server, watch,
330 HAVE_LOCK_CHECK (server);
331 protected_change_watch (server, watch,
360 HAVE_LOCK_CHECK (server);
371 SERVER_UNLOCK (server);
374 retval = (* add_function) (timeouts, timeout);
375 else if (remove_function)
378 (* remove_function) (timeouts, timeout);
383 (* toggle_function) (timeouts, timeout, enabled);
386 SERVER_LOCK (server);
409 return protected_change_timeout (server, timeout,
424 protected_change_timeout (server, timeout,
444 protected_change_timeout (server, timeout,
459 dbus_int32_t old_refcount;
462 HAVE_LOCK_CHECK (server);
466 _dbus_server_trace_ref (server, old_refcount, old_refcount + 1,
478 dbus_int32_t old_refcount;
484 HAVE_LOCK_CHECK (server);
489 _dbus_server_trace_ref (server, old_refcount, old_refcount - 1,
492 if (old_refcount == 1)
496 SERVER_UNLOCK (server);
525 static const struct {
532 #ifdef DBUS_BUILD_TESTS
533 , { _dbus_server_listen_debug_pipe }
567 _dbus_return_val_if_fail (address !=
NULL,
NULL);
568 _dbus_return_val_if_error_is_set (error,
NULL);
574 handled_once =
FALSE;
576 for (i = 0; i < len; i++)
582 DBusServerListenResult result;
585 result = (* listen_funcs[j].func) (entries[i],
589 if (result == DBUS_SERVER_LISTEN_OK)
592 _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
596 else if (result == DBUS_SERVER_LISTEN_ADDRESS_ALREADY_USED)
601 "Address '%s' already used",
606 else if (result == DBUS_SERVER_LISTEN_BAD_ADDRESS)
609 _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
614 else if (result == DBUS_SERVER_LISTEN_NOT_HANDLED)
617 _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
621 else if (result == DBUS_SERVER_LISTEN_DID_NOT_CONNECT)
624 _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
637 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
644 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
648 "Unknown address type '%s'",
653 "Empty address '%s'",
677 _DBUS_ASSERT_ERROR_IS_CLEAR (&first_connect_error);
678 _DBUS_ASSERT_ERROR_IS_SET (error);
684 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
698 dbus_int32_t old_refcount;
700 _dbus_return_val_if_fail (server !=
NULL,
NULL);
705 #ifndef DBUS_DISABLE_CHECKS
706 if (_DBUS_UNLIKELY (old_refcount <= 0))
711 _DBUS_FUNCTION_NAME,
"old_refcount > 0",
717 _dbus_server_trace_ref (server, old_refcount, old_refcount + 1,
"ref");
733 dbus_int32_t old_refcount;
737 _dbus_return_if_fail (server !=
NULL);
742 #ifndef DBUS_DISABLE_CHECKS
743 if (_DBUS_UNLIKELY (old_refcount <= 0))
748 _DBUS_FUNCTION_NAME,
"old_refcount > 0",
754 _dbus_server_trace_ref (server, old_refcount, old_refcount - 1,
"unref");
756 if (old_refcount == 1)
778 _dbus_return_if_fail (server !=
NULL);
780 #ifdef DBUS_DISABLE_CHECKS
786 _dbus_return_if_fail (old_refcount > 0);
790 SERVER_LOCK (server);
802 SERVER_UNLOCK (server);
816 _dbus_return_val_if_fail (server !=
NULL,
FALSE);
818 SERVER_LOCK (server);
820 SERVER_UNLOCK (server);
837 _dbus_return_val_if_fail (server !=
NULL,
NULL);
839 SERVER_LOCK (server);
841 SERVER_UNLOCK (server);
873 _dbus_return_val_if_fail (server !=
NULL,
NULL);
875 SERVER_LOCK (server);
878 SERVER_UNLOCK (server);
912 _dbus_return_if_fail (server !=
NULL);
914 SERVER_LOCK (server);
921 SERVER_UNLOCK (server);
923 if (old_free_function !=
NULL)
924 (* old_free_function) (old_data);
954 _dbus_return_val_if_fail (server !=
NULL,
FALSE);
956 SERVER_LOCK (server);
961 SERVER_UNLOCK (server);
968 SERVER_LOCK (server);
976 SERVER_UNLOCK (server);
1007 _dbus_return_val_if_fail (server !=
NULL,
FALSE);
1009 SERVER_LOCK (server);
1014 SERVER_UNLOCK (server);
1020 free_data_function);
1021 SERVER_LOCK (server);
1029 SERVER_UNLOCK (server);
1049 const char **mechanisms)
1053 _dbus_return_val_if_fail (server !=
NULL,
FALSE);
1055 SERVER_LOCK (server);
1057 if (mechanisms !=
NULL)
1069 SERVER_UNLOCK (server);
1114 _dbus_return_if_fail (*slot_p >= 0);
1142 _dbus_return_val_if_fail (server !=
NULL,
FALSE);
1144 SERVER_LOCK (server);
1148 slot, data, free_data_func,
1149 &old_free_func, &old_data);
1152 SERVER_UNLOCK (server);
1158 (* old_free_func) (old_data);
1178 _dbus_return_val_if_fail (server !=
NULL,
NULL);
1180 SERVER_LOCK (server);
1186 SERVER_UNLOCK (server);
1193 #ifdef DBUS_BUILD_TESTS
1194 #include "dbus-test.h"
1198 _dbus_server_test (
void)
1200 const char *valid_addresses[] = {
1202 "tcp:host=localhost,port=1234",
1203 "tcp:host=localhost,port=1234;tcp:port=5678",
1205 "unix:path=./boogie",
1206 "tcp:port=1234;unix:path=./boogie",
1232 if (strstr (address,
id) ==
NULL)
1234 _dbus_warn (
"server id '%s' is not in the server address '%s'\n",