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,
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,
351 HAVE_LOCK_CHECK (server);
362 SERVER_UNLOCK (server);
365 retval = (* add_function) (timeouts, timeout);
366 else if (remove_function)
369 (* remove_function) (timeouts, timeout);
374 (* toggle_function) (timeouts, timeout, enabled);
377 SERVER_LOCK (server);
400 return protected_change_timeout (server, timeout,
415 protected_change_timeout (server, timeout,
435 protected_change_timeout (server, timeout,
453 HAVE_LOCK_CHECK (server);
457 _dbus_server_trace_ref (server, old_refcount, old_refcount + 1,
475 HAVE_LOCK_CHECK (server);
480 _dbus_server_trace_ref (server, old_refcount, old_refcount - 1,
483 if (old_refcount == 1)
487 SERVER_UNLOCK (server);
516 static const struct {
523 #ifdef DBUS_BUILD_TESTS
524 , { _dbus_server_listen_debug_pipe }
558 _dbus_return_val_if_fail (address !=
NULL,
NULL);
559 _dbus_return_val_if_error_is_set (error,
NULL);
565 handled_once =
FALSE;
567 for (i = 0; i < len; i++)
573 DBusServerListenResult result;
576 result = (* listen_funcs[j].func) (entries[i],
580 if (result == DBUS_SERVER_LISTEN_OK)
583 _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
587 else if (result == DBUS_SERVER_LISTEN_ADDRESS_ALREADY_USED)
592 "Address '%s' already used",
597 else if (result == DBUS_SERVER_LISTEN_BAD_ADDRESS)
600 _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
605 else if (result == DBUS_SERVER_LISTEN_NOT_HANDLED)
608 _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
612 else if (result == DBUS_SERVER_LISTEN_DID_NOT_CONNECT)
615 _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
628 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
635 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
639 "Unknown address type '%s'",
644 "Empty address '%s'",
668 _DBUS_ASSERT_ERROR_IS_CLEAR (&first_connect_error);
669 _DBUS_ASSERT_ERROR_IS_SET (error);
675 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
691 _dbus_return_val_if_fail (server !=
NULL,
NULL);
696 #ifndef DBUS_DISABLE_CHECKS
697 if (_DBUS_UNLIKELY (old_refcount <= 0))
702 _DBUS_FUNCTION_NAME,
"old_refcount > 0",
708 _dbus_server_trace_ref (server, old_refcount, old_refcount + 1,
"ref");
728 _dbus_return_if_fail (server !=
NULL);
733 #ifndef DBUS_DISABLE_CHECKS
734 if (_DBUS_UNLIKELY (old_refcount <= 0))
739 _DBUS_FUNCTION_NAME,
"old_refcount > 0",
745 _dbus_server_trace_ref (server, old_refcount, old_refcount - 1,
"unref");
747 if (old_refcount == 1)
769 _dbus_return_if_fail (server !=
NULL);
771 #ifdef DBUS_DISABLE_CHECKS
777 _dbus_return_if_fail (old_refcount > 0);
781 SERVER_LOCK (server);
793 SERVER_UNLOCK (server);
807 _dbus_return_val_if_fail (server !=
NULL,
FALSE);
809 SERVER_LOCK (server);
811 SERVER_UNLOCK (server);
828 _dbus_return_val_if_fail (server !=
NULL,
NULL);
830 SERVER_LOCK (server);
832 SERVER_UNLOCK (server);
864 _dbus_return_val_if_fail (server !=
NULL,
NULL);
866 SERVER_LOCK (server);
869 SERVER_UNLOCK (server);
903 _dbus_return_if_fail (server !=
NULL);
905 SERVER_LOCK (server);
912 SERVER_UNLOCK (server);
914 if (old_free_function !=
NULL)
915 (* old_free_function) (old_data);
945 _dbus_return_val_if_fail (server !=
NULL,
FALSE);
947 SERVER_LOCK (server);
952 SERVER_UNLOCK (server);
959 SERVER_LOCK (server);
967 SERVER_UNLOCK (server);
998 _dbus_return_val_if_fail (server !=
NULL,
FALSE);
1000 SERVER_LOCK (server);
1005 SERVER_UNLOCK (server);
1011 free_data_function);
1012 SERVER_LOCK (server);
1020 SERVER_UNLOCK (server);
1040 const char **mechanisms)
1044 _dbus_return_val_if_fail (server !=
NULL,
FALSE);
1046 SERVER_LOCK (server);
1048 if (mechanisms !=
NULL)
1060 SERVER_UNLOCK (server);
1105 _dbus_return_if_fail (*slot_p >= 0);
1133 _dbus_return_val_if_fail (server !=
NULL,
FALSE);
1135 SERVER_LOCK (server);
1139 slot, data, free_data_func,
1140 &old_free_func, &old_data);
1143 SERVER_UNLOCK (server);
1149 (* old_free_func) (old_data);
1169 _dbus_return_val_if_fail (server !=
NULL,
NULL);
1171 SERVER_LOCK (server);
1177 SERVER_UNLOCK (server);
1184 #ifdef DBUS_BUILD_TESTS
1185 #include "dbus-test.h"
1189 _dbus_server_test (
void)
1191 const char *valid_addresses[] = {
1193 "tcp:host=localhost,port=1234",
1194 "tcp:host=localhost,port=1234;tcp:port=5678",
1196 "unix:path=./boogie",
1197 "tcp:port=1234;unix:path=./boogie",
1223 if (strstr (address,
id) ==
NULL)
1225 _dbus_warn (
"server id '%s' is not in the server address '%s'\n",