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_ENABLE_EMBEDDED_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,
119 #ifdef DBUS_DISABLE_ASSERT
136 _DBUS_SET_OOM (error);
146 server->
address = copy_address_with_guid_appended (address,
165 _dbus_verbose (
"Initialized server on address %s\n", server->
address);
170 _DBUS_SET_OOM (error);
206 #ifndef DBUS_DISABLE_CHECKS
251 HAVE_LOCK_CHECK (server);
263 SERVER_UNLOCK (server);
266 retval = (* add_function) (watches, watch);
267 else if (remove_function)
270 (* remove_function) (watches, watch);
275 (* toggle_function) (watches, watch, enabled);
278 SERVER_LOCK (server);
299 HAVE_LOCK_CHECK (server);
300 return protected_change_watch (server, watch,
315 HAVE_LOCK_CHECK (server);
316 protected_change_watch (server, watch,
359 HAVE_LOCK_CHECK (server);
370 SERVER_UNLOCK (server);
373 retval = (* add_function) (timeouts, timeout);
374 else if (remove_function)
377 (* remove_function) (timeouts, timeout);
382 (* toggle_function) (timeouts, timeout, enabled);
385 SERVER_LOCK (server);
408 return protected_change_timeout (server, timeout,
423 protected_change_timeout (server, timeout,
443 protected_change_timeout (server, timeout,
461 HAVE_LOCK_CHECK (server);
465 _dbus_server_trace_ref (server, old_refcount, old_refcount + 1,
483 HAVE_LOCK_CHECK (server);
488 _dbus_server_trace_ref (server, old_refcount, old_refcount - 1,
491 if (old_refcount == 1)
495 SERVER_UNLOCK (server);
524 static const struct {
531 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
532 , { _dbus_server_listen_debug_pipe }
566 _dbus_return_val_if_fail (address !=
NULL,
NULL);
567 _dbus_return_val_if_error_is_set (error,
NULL);
573 handled_once =
FALSE;
575 for (i = 0; i < len; i++)
581 DBusServerListenResult result;
584 result = (* listen_funcs[j].func) (entries[i],
588 if (result == DBUS_SERVER_LISTEN_OK)
591 _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
595 else if (result == DBUS_SERVER_LISTEN_ADDRESS_ALREADY_USED)
600 "Address '%s' already used",
605 else if (result == DBUS_SERVER_LISTEN_BAD_ADDRESS)
608 _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
613 else if (result == DBUS_SERVER_LISTEN_NOT_HANDLED)
616 _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
620 else if (result == DBUS_SERVER_LISTEN_DID_NOT_CONNECT)
623 _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
636 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
643 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
647 "Unknown address type '%s'",
652 "Empty address '%s'",
676 _DBUS_ASSERT_ERROR_IS_CLEAR (&first_connect_error);
677 _DBUS_ASSERT_ERROR_IS_SET (error);
684 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
700 _dbus_return_val_if_fail (server !=
NULL,
NULL);
704 #ifndef DBUS_DISABLE_CHECKS
705 if (_DBUS_UNLIKELY (old_refcount <= 0))
708 _dbus_warn_return_if_fail (_DBUS_FUNCTION_NAME,
"old_refcount > 0",
714 _dbus_server_trace_ref (server, old_refcount, old_refcount + 1,
"ref");
734 _dbus_return_if_fail (server !=
NULL);
738 #ifndef DBUS_DISABLE_CHECKS
739 if (_DBUS_UNLIKELY (old_refcount <= 0))
749 _dbus_warn_return_if_fail (_DBUS_FUNCTION_NAME,
"old_refcount > 0",
755 _dbus_server_trace_ref (server, old_refcount, old_refcount - 1,
"unref");
757 if (old_refcount == 1)
769 _dbus_server_disconnect_unlocked (
DBusServer *server)
793 _dbus_return_if_fail (server !=
NULL);
796 SERVER_LOCK (server);
798 _dbus_server_disconnect_unlocked (server);
800 SERVER_UNLOCK (server);
814 _dbus_return_val_if_fail (server !=
NULL,
FALSE);
816 SERVER_LOCK (server);
818 SERVER_UNLOCK (server);
835 _dbus_return_val_if_fail (server !=
NULL,
NULL);
837 SERVER_LOCK (server);
839 SERVER_UNLOCK (server);
871 _dbus_return_val_if_fail (server !=
NULL,
NULL);
873 SERVER_LOCK (server);
876 SERVER_UNLOCK (server);
910 _dbus_return_if_fail (server !=
NULL);
912 SERVER_LOCK (server);
919 SERVER_UNLOCK (server);
921 if (old_free_function !=
NULL)
922 (* old_free_function) (old_data);
952 _dbus_return_val_if_fail (server !=
NULL,
FALSE);
954 SERVER_LOCK (server);
959 SERVER_UNLOCK (server);
966 SERVER_LOCK (server);
974 SERVER_UNLOCK (server);
1005 _dbus_return_val_if_fail (server !=
NULL,
FALSE);
1007 SERVER_LOCK (server);
1012 SERVER_UNLOCK (server);
1018 free_data_function);
1019 SERVER_LOCK (server);
1027 SERVER_UNLOCK (server);
1047 const char **mechanisms)
1051 _dbus_return_val_if_fail (server !=
NULL,
FALSE);
1053 SERVER_LOCK (server);
1055 if (mechanisms !=
NULL)
1060 SERVER_UNLOCK (server);
1070 SERVER_UNLOCK (server);
1113 _dbus_return_if_fail (*slot_p >= 0);
1141 _dbus_return_val_if_fail (server !=
NULL,
FALSE);
1143 SERVER_LOCK (server);
1147 slot, data, free_data_func,
1148 &old_free_func, &old_data);
1151 SERVER_UNLOCK (server);
1157 (* old_free_func) (old_data);
1177 _dbus_return_val_if_fail (server !=
NULL,
NULL);
1179 SERVER_LOCK (server);
1185 SERVER_UNLOCK (server);
1192 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
1193 #include "dbus-test.h"
1197 _dbus_server_test (
void)
1199 const char *valid_addresses[] = {
1201 "tcp:host=localhost,port=1234",
1202 "tcp:host=localhost,port=1234;tcp:port=5678",
1204 "unix:path=./boogie",
1205 "tcp:port=1234;unix:path=./boogie",
1231 if (strstr (address,
id) ==
NULL)
1233 _dbus_warn (
"server id '%s' is not in the server address '%s'",