D-Bus  1.6.4
dbus-server.c
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* dbus-server.c DBusServer object
3  *
4  * Copyright (C) 2002, 2003, 2004, 2005 Red Hat Inc.
5  *
6  * Licensed under the Academic Free License version 2.1
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  */
23 
24 #include <config.h>
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"
31 #endif
32 #include "dbus-address.h"
33 #include "dbus-protocol.h"
34 
56 #ifndef _dbus_server_trace_ref
57 void
58 _dbus_server_trace_ref (DBusServer *server,
59  int old_refcount,
60  int new_refcount,
61  const char *why)
62 {
63  static int enabled = -1;
64 
65  _dbus_trace_ref ("DBusServer", server, old_refcount, new_refcount, why,
66  "DBUS_SERVER_TRACE", &enabled);
67 }
68 #endif
69 
70 /* this is a little fragile since it assumes the address doesn't
71  * already have a guid, but it shouldn't
72  */
73 static char*
74 copy_address_with_guid_appended (const DBusString *address,
75  const DBusString *guid_hex)
76 {
77  DBusString with_guid;
78  char *retval;
79 
80  if (!_dbus_string_init (&with_guid))
81  return NULL;
82 
83  if (!_dbus_string_copy (address, 0, &with_guid,
84  _dbus_string_get_length (&with_guid)) ||
85  !_dbus_string_append (&with_guid, ",guid=") ||
86  !_dbus_string_copy (guid_hex, 0,
87  &with_guid, _dbus_string_get_length (&with_guid)))
88  {
89  _dbus_string_free (&with_guid);
90  return NULL;
91  }
92 
93  retval = NULL;
94  _dbus_string_steal_data (&with_guid, &retval);
95 
96  _dbus_string_free (&with_guid);
97 
98  return retval; /* may be NULL if steal_data failed */
99 }
100 
112  const DBusServerVTable *vtable,
113  const DBusString *address)
114 {
115  server->vtable = vtable;
116 
117 #ifdef DBUS_DISABLE_ASSERT
118  _dbus_atomic_inc (&server->refcount);
119 #else
120  {
121  dbus_int32_t old_refcount = _dbus_atomic_inc (&server->refcount);
122 
123  _dbus_assert (old_refcount == 0);
124  }
125 #endif
126 
127  server->address = NULL;
128  server->watches = NULL;
129  server->timeouts = NULL;
130  server->published_address = FALSE;
131 
132  if (!_dbus_string_init (&server->guid_hex))
133  return FALSE;
134 
135  _dbus_generate_uuid (&server->guid);
136 
137  if (!_dbus_uuid_encode (&server->guid, &server->guid_hex))
138  goto failed;
139 
140  server->address = copy_address_with_guid_appended (address,
141  &server->guid_hex);
142  if (server->address == NULL)
143  goto failed;
144 
146  if (server->mutex == NULL)
147  goto failed;
148 
149  server->watches = _dbus_watch_list_new ();
150  if (server->watches == NULL)
151  goto failed;
152 
153  server->timeouts = _dbus_timeout_list_new ();
154  if (server->timeouts == NULL)
155  goto failed;
156 
158 
159  _dbus_verbose ("Initialized server on address %s\n", server->address);
160 
161  return TRUE;
162 
163  failed:
165  server->mutex = NULL;
166  if (server->watches)
167  {
168  _dbus_watch_list_free (server->watches);
169  server->watches = NULL;
170  }
171  if (server->timeouts)
172  {
174  server->timeouts = NULL;
175  }
176  if (server->address)
177  {
178  dbus_free (server->address);
179  server->address = NULL;
180  }
181  _dbus_string_free (&server->guid_hex);
182 
183  return FALSE;
184 }
185 
192 void
194 {
195  /* We don't have the lock, but nobody should be accessing
196  * concurrently since they don't have a ref
197  */
198 #ifndef DBUS_DISABLE_CHECKS
199  _dbus_assert (!server->have_server_lock);
200 #endif
201  _dbus_assert (server->disconnected);
202 
203  /* calls out to application code... */
205 
207 
208  _dbus_watch_list_free (server->watches);
210 
212 
213  dbus_free (server->address);
214 
216 
217  _dbus_string_free (&server->guid_hex);
218 }
219 
220 
223  DBusWatch *watch);
225 typedef void (* DBusWatchRemoveFunction) (DBusWatchList *list,
226  DBusWatch *watch);
228 typedef void (* DBusWatchToggleFunction) (DBusWatchList *list,
229  DBusWatch *watch,
230  dbus_bool_t enabled);
231 
232 static dbus_bool_t
233 protected_change_watch (DBusServer *server,
234  DBusWatch *watch,
235  DBusWatchAddFunction add_function,
236  DBusWatchRemoveFunction remove_function,
237  DBusWatchToggleFunction toggle_function,
238  dbus_bool_t enabled)
239 {
240  DBusWatchList *watches;
241  dbus_bool_t retval;
242 
243  HAVE_LOCK_CHECK (server);
244 
245  /* This isn't really safe or reasonable; a better pattern is the "do
246  * everything, then drop lock and call out" one; but it has to be
247  * propagated up through all callers
248  */
249 
250  watches = server->watches;
251  if (watches)
252  {
253  server->watches = NULL;
254  _dbus_server_ref_unlocked (server);
255  SERVER_UNLOCK (server);
256 
257  if (add_function)
258  retval = (* add_function) (watches, watch);
259  else if (remove_function)
260  {
261  retval = TRUE;
262  (* remove_function) (watches, watch);
263  }
264  else
265  {
266  retval = TRUE;
267  (* toggle_function) (watches, watch, enabled);
268  }
269 
270  SERVER_LOCK (server);
271  server->watches = watches;
273 
274  return retval;
275  }
276  else
277  return FALSE;
278 }
279 
289  DBusWatch *watch)
290 {
291  HAVE_LOCK_CHECK (server);
292  return protected_change_watch (server, watch,
294  NULL, NULL, FALSE);
295 }
296 
303 void
305  DBusWatch *watch)
306 {
307  HAVE_LOCK_CHECK (server);
308  protected_change_watch (server, watch,
309  NULL,
311  NULL, FALSE);
312 }
313 
323 void
325  DBusWatch *watch,
326  dbus_bool_t enabled)
327 {
328  _dbus_assert (watch != NULL);
329 
330  HAVE_LOCK_CHECK (server);
331  protected_change_watch (server, watch,
332  NULL, NULL,
334  enabled);
335 }
336 
339  DBusTimeout *timeout);
342  DBusTimeout *timeout);
345  DBusTimeout *timeout,
346  dbus_bool_t enabled);
347 
348 
349 static dbus_bool_t
350 protected_change_timeout (DBusServer *server,
351  DBusTimeout *timeout,
352  DBusTimeoutAddFunction add_function,
353  DBusTimeoutRemoveFunction remove_function,
354  DBusTimeoutToggleFunction toggle_function,
355  dbus_bool_t enabled)
356 {
357  DBusTimeoutList *timeouts;
358  dbus_bool_t retval;
359 
360  HAVE_LOCK_CHECK (server);
361 
362  /* This isn't really safe or reasonable; a better pattern is the "do everything, then
363  * drop lock and call out" one; but it has to be propagated up through all callers
364  */
365 
366  timeouts = server->timeouts;
367  if (timeouts)
368  {
369  server->timeouts = NULL;
370  _dbus_server_ref_unlocked (server);
371  SERVER_UNLOCK (server);
372 
373  if (add_function)
374  retval = (* add_function) (timeouts, timeout);
375  else if (remove_function)
376  {
377  retval = TRUE;
378  (* remove_function) (timeouts, timeout);
379  }
380  else
381  {
382  retval = TRUE;
383  (* toggle_function) (timeouts, timeout, enabled);
384  }
385 
386  SERVER_LOCK (server);
387  server->timeouts = timeouts;
389 
390  return retval;
391  }
392  else
393  return FALSE;
394 }
395 
407  DBusTimeout *timeout)
408 {
409  return protected_change_timeout (server, timeout,
411  NULL, NULL, FALSE);
412 }
413 
420 void
422  DBusTimeout *timeout)
423 {
424  protected_change_timeout (server, timeout,
425  NULL,
427  NULL, FALSE);
428 }
429 
439 void
441  DBusTimeout *timeout,
442  dbus_bool_t enabled)
443 {
444  protected_change_timeout (server, timeout,
445  NULL, NULL,
447  enabled);
448 }
449 
450 
456 void
458 {
459  dbus_int32_t old_refcount;
460 
461  _dbus_assert (server != NULL);
462  HAVE_LOCK_CHECK (server);
463 
464  old_refcount = _dbus_atomic_inc (&server->refcount);
465  _dbus_assert (old_refcount > 0);
466  _dbus_server_trace_ref (server, old_refcount, old_refcount + 1,
467  "ref_unlocked");
468 }
469 
475 void
477 {
478  dbus_int32_t old_refcount;
479 
480  /* Keep this in sync with dbus_server_unref */
481 
482  _dbus_assert (server != NULL);
483 
484  HAVE_LOCK_CHECK (server);
485 
486  old_refcount = _dbus_atomic_dec (&server->refcount);
487  _dbus_assert (old_refcount > 0);
488 
489  _dbus_server_trace_ref (server, old_refcount, old_refcount - 1,
490  "unref_unlocked");
491 
492  if (old_refcount == 1)
493  {
494  _dbus_assert (server->disconnected);
495 
496  SERVER_UNLOCK (server);
497 
498  _dbus_assert (server->vtable->finalize != NULL);
499 
500  (* server->vtable->finalize) (server);
501  }
502 }
503 
525 static const struct {
526  DBusServerListenResult (* func) (DBusAddressEntry *entry,
527  DBusServer **server_p,
528  DBusError *error);
529 } listen_funcs[] = {
532 #ifdef DBUS_BUILD_TESTS
533  , { _dbus_server_listen_debug_pipe }
534 #endif
535 };
536 
557 DBusServer*
558 dbus_server_listen (const char *address,
559  DBusError *error)
560 {
561  DBusServer *server;
562  DBusAddressEntry **entries;
563  int len, i;
564  DBusError first_connect_error = DBUS_ERROR_INIT;
565  dbus_bool_t handled_once;
566 
567  _dbus_return_val_if_fail (address != NULL, NULL);
568  _dbus_return_val_if_error_is_set (error, NULL);
569 
570  if (!dbus_parse_address (address, &entries, &len, error))
571  return NULL;
572 
573  server = NULL;
574  handled_once = FALSE;
575 
576  for (i = 0; i < len; i++)
577  {
578  int j;
579 
580  for (j = 0; j < (int) _DBUS_N_ELEMENTS (listen_funcs); ++j)
581  {
582  DBusServerListenResult result;
583  DBusError tmp_error = DBUS_ERROR_INIT;
584 
585  result = (* listen_funcs[j].func) (entries[i],
586  &server,
587  &tmp_error);
588 
589  if (result == DBUS_SERVER_LISTEN_OK)
590  {
591  _dbus_assert (server != NULL);
592  _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
593  handled_once = TRUE;
594  goto out;
595  }
596  else if (result == DBUS_SERVER_LISTEN_ADDRESS_ALREADY_USED)
597  {
598  _dbus_assert (server == NULL);
599  dbus_set_error (error,
601  "Address '%s' already used",
602  dbus_address_entry_get_method (entries[0]));
603  handled_once = TRUE;
604  goto out;
605  }
606  else if (result == DBUS_SERVER_LISTEN_BAD_ADDRESS)
607  {
608  _dbus_assert (server == NULL);
609  _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
610  dbus_move_error (&tmp_error, error);
611  handled_once = TRUE;
612  goto out;
613  }
614  else if (result == DBUS_SERVER_LISTEN_NOT_HANDLED)
615  {
616  _dbus_assert (server == NULL);
617  _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
618 
619  /* keep trying addresses */
620  }
621  else if (result == DBUS_SERVER_LISTEN_DID_NOT_CONNECT)
622  {
623  _dbus_assert (server == NULL);
624  _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
625  if (!dbus_error_is_set (&first_connect_error))
626  dbus_move_error (&tmp_error, &first_connect_error);
627  else
628  dbus_error_free (&tmp_error);
629 
630  handled_once = TRUE;
631 
632  /* keep trying addresses */
633  }
634  }
635 
636  _dbus_assert (server == NULL);
637  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
638  }
639 
640  out:
641 
642  if (!handled_once)
643  {
644  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
645  if (len > 0)
646  dbus_set_error (error,
648  "Unknown address type '%s'",
649  dbus_address_entry_get_method (entries[0]));
650  else
651  dbus_set_error (error,
653  "Empty address '%s'",
654  address);
655  }
656 
657  dbus_address_entries_free (entries);
658 
659  if (server == NULL)
660  {
661  _dbus_assert (error == NULL || dbus_error_is_set (&first_connect_error) ||
662  dbus_error_is_set (error));
663 
664  if (error && dbus_error_is_set (error))
665  {
666  /* already set the error */
667  }
668  else
669  {
670  /* didn't set the error but either error should be
671  * NULL or first_connect_error should be set.
672  */
673  _dbus_assert (error == NULL || dbus_error_is_set (&first_connect_error));
674  dbus_move_error (&first_connect_error, error);
675  }
676 
677  _DBUS_ASSERT_ERROR_IS_CLEAR (&first_connect_error); /* be sure we freed it */
678  _DBUS_ASSERT_ERROR_IS_SET (error);
679 
680  return NULL;
681  }
682  else
683  {
684  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
685  return server;
686  }
687 }
688 
695 DBusServer *
697 {
698  dbus_int32_t old_refcount;
699 
700  _dbus_return_val_if_fail (server != NULL, NULL);
701 
702  /* can't get the refcount without a side-effect */
703  old_refcount = _dbus_atomic_inc (&server->refcount);
704 
705 #ifndef DBUS_DISABLE_CHECKS
706  if (_DBUS_UNLIKELY (old_refcount <= 0))
707  {
708  /* undo side-effect first */
709  _dbus_atomic_dec (&server->refcount);
711  _DBUS_FUNCTION_NAME, "old_refcount > 0",
712  __FILE__, __LINE__);
713  return NULL;
714  }
715 #endif
716 
717  _dbus_server_trace_ref (server, old_refcount, old_refcount + 1, "ref");
718 
719  return server;
720 }
721 
730 void
732 {
733  dbus_int32_t old_refcount;
734 
735  /* keep this in sync with unref_unlocked */
736 
737  _dbus_return_if_fail (server != NULL);
738 
739  /* can't get the refcount without a side-effect */
740  old_refcount = _dbus_atomic_dec (&server->refcount);
741 
742 #ifndef DBUS_DISABLE_CHECKS
743  if (_DBUS_UNLIKELY (old_refcount <= 0))
744  {
745  /* undo side-effect first */
746  _dbus_atomic_inc (&server->refcount);
748  _DBUS_FUNCTION_NAME, "old_refcount > 0",
749  __FILE__, __LINE__);
750  return;
751  }
752 #endif
753 
754  _dbus_server_trace_ref (server, old_refcount, old_refcount - 1, "unref");
755 
756  if (old_refcount == 1)
757  {
758  /* lock not held! */
759  _dbus_assert (server->disconnected);
760 
761  _dbus_assert (server->vtable->finalize != NULL);
762 
763  (* server->vtable->finalize) (server);
764  }
765 }
766 
775 void
777 {
778  _dbus_return_if_fail (server != NULL);
779 
780 #ifdef DBUS_DISABLE_CHECKS
781  _dbus_atomic_inc (&server->refcount);
782 #else
783  {
784  dbus_int32_t old_refcount = _dbus_atomic_inc (&server->refcount);
785 
786  _dbus_return_if_fail (old_refcount > 0);
787  }
788 #endif
789 
790  SERVER_LOCK (server);
791 
792  _dbus_assert (server->vtable->disconnect != NULL);
793 
794  if (!server->disconnected)
795  {
796  /* this has to be first so recursive calls to disconnect don't happen */
797  server->disconnected = TRUE;
798 
799  (* server->vtable->disconnect) (server);
800  }
801 
802  SERVER_UNLOCK (server);
803  dbus_server_unref (server);
804 }
805 
813 {
814  dbus_bool_t retval;
815 
816  _dbus_return_val_if_fail (server != NULL, FALSE);
817 
818  SERVER_LOCK (server);
819  retval = !server->disconnected;
820  SERVER_UNLOCK (server);
821 
822  return retval;
823 }
824 
832 char*
834 {
835  char *retval;
836 
837  _dbus_return_val_if_fail (server != NULL, NULL);
838 
839  SERVER_LOCK (server);
840  retval = _dbus_strdup (server->address);
841  SERVER_UNLOCK (server);
842 
843  return retval;
844 }
845 
868 char*
870 {
871  char *retval;
872 
873  _dbus_return_val_if_fail (server != NULL, NULL);
874 
875  SERVER_LOCK (server);
876  retval = NULL;
877  _dbus_string_copy_data (&server->guid_hex, &retval);
878  SERVER_UNLOCK (server);
879 
880  return retval;
881 }
882 
903 void
905  DBusNewConnectionFunction function,
906  void *data,
907  DBusFreeFunction free_data_function)
908 {
909  DBusFreeFunction old_free_function;
910  void *old_data;
911 
912  _dbus_return_if_fail (server != NULL);
913 
914  SERVER_LOCK (server);
915  old_free_function = server->new_connection_free_data_function;
916  old_data = server->new_connection_data;
917 
918  server->new_connection_function = function;
919  server->new_connection_data = data;
920  server->new_connection_free_data_function = free_data_function;
921  SERVER_UNLOCK (server);
922 
923  if (old_free_function != NULL)
924  (* old_free_function) (old_data);
925 }
926 
945  DBusAddWatchFunction add_function,
946  DBusRemoveWatchFunction remove_function,
947  DBusWatchToggledFunction toggled_function,
948  void *data,
949  DBusFreeFunction free_data_function)
950 {
951  dbus_bool_t result;
952  DBusWatchList *watches;
953 
954  _dbus_return_val_if_fail (server != NULL, FALSE);
955 
956  SERVER_LOCK (server);
957  watches = server->watches;
958  server->watches = NULL;
959  if (watches)
960  {
961  SERVER_UNLOCK (server);
962  result = _dbus_watch_list_set_functions (watches,
963  add_function,
964  remove_function,
965  toggled_function,
966  data,
967  free_data_function);
968  SERVER_LOCK (server);
969  }
970  else
971  {
972  _dbus_warn_check_failed ("Re-entrant call to %s\n", _DBUS_FUNCTION_NAME);
973  result = FALSE;
974  }
975  server->watches = watches;
976  SERVER_UNLOCK (server);
977 
978  return result;
979 }
980 
998  DBusAddTimeoutFunction add_function,
999  DBusRemoveTimeoutFunction remove_function,
1000  DBusTimeoutToggledFunction toggled_function,
1001  void *data,
1002  DBusFreeFunction free_data_function)
1003 {
1004  dbus_bool_t result;
1005  DBusTimeoutList *timeouts;
1006 
1007  _dbus_return_val_if_fail (server != NULL, FALSE);
1008 
1009  SERVER_LOCK (server);
1010  timeouts = server->timeouts;
1011  server->timeouts = NULL;
1012  if (timeouts)
1013  {
1014  SERVER_UNLOCK (server);
1015  result = _dbus_timeout_list_set_functions (timeouts,
1016  add_function,
1017  remove_function,
1018  toggled_function,
1019  data,
1020  free_data_function);
1021  SERVER_LOCK (server);
1022  }
1023  else
1024  {
1025  _dbus_warn_check_failed ("Re-entrant call to %s\n", _DBUS_FUNCTION_NAME);
1026  result = FALSE;
1027  }
1028  server->timeouts = timeouts;
1029  SERVER_UNLOCK (server);
1030 
1031  return result;
1032 }
1033 
1049  const char **mechanisms)
1050 {
1051  char **copy;
1052 
1053  _dbus_return_val_if_fail (server != NULL, FALSE);
1054 
1055  SERVER_LOCK (server);
1056 
1057  if (mechanisms != NULL)
1058  {
1059  copy = _dbus_dup_string_array (mechanisms);
1060  if (copy == NULL)
1061  return FALSE;
1062  }
1063  else
1064  copy = NULL;
1065 
1067  server->auth_mechanisms = copy;
1068 
1069  SERVER_UNLOCK (server);
1070 
1071  return TRUE;
1072 }
1073 
1074 
1075 static DBusDataSlotAllocator slot_allocator;
1076 _DBUS_DEFINE_GLOBAL_LOCK (server_slots);
1077 
1093 dbus_server_allocate_data_slot (dbus_int32_t *slot_p)
1094 {
1095  return _dbus_data_slot_allocator_alloc (&slot_allocator,
1096  (DBusRMutex **)&_DBUS_LOCK_NAME (server_slots),
1097  slot_p);
1098 }
1099 
1111 void
1112 dbus_server_free_data_slot (dbus_int32_t *slot_p)
1113 {
1114  _dbus_return_if_fail (*slot_p >= 0);
1115 
1116  _dbus_data_slot_allocator_free (&slot_allocator, slot_p);
1117 }
1118 
1134  int slot,
1135  void *data,
1136  DBusFreeFunction free_data_func)
1137 {
1138  DBusFreeFunction old_free_func;
1139  void *old_data;
1140  dbus_bool_t retval;
1141 
1142  _dbus_return_val_if_fail (server != NULL, FALSE);
1143 
1144  SERVER_LOCK (server);
1145 
1146  retval = _dbus_data_slot_list_set (&slot_allocator,
1147  &server->slot_list,
1148  slot, data, free_data_func,
1149  &old_free_func, &old_data);
1150 
1151 
1152  SERVER_UNLOCK (server);
1153 
1154  if (retval)
1155  {
1156  /* Do the actual free outside the server lock */
1157  if (old_free_func)
1158  (* old_free_func) (old_data);
1159  }
1160 
1161  return retval;
1162 }
1163 
1172 void*
1174  int slot)
1175 {
1176  void *res;
1177 
1178  _dbus_return_val_if_fail (server != NULL, NULL);
1179 
1180  SERVER_LOCK (server);
1181 
1182  res = _dbus_data_slot_list_get (&slot_allocator,
1183  &server->slot_list,
1184  slot);
1185 
1186  SERVER_UNLOCK (server);
1187 
1188  return res;
1189 }
1190 
1193 #ifdef DBUS_BUILD_TESTS
1194 #include "dbus-test.h"
1195 #include <string.h>
1196 
1198 _dbus_server_test (void)
1199 {
1200  const char *valid_addresses[] = {
1201  "tcp:port=1234",
1202  "tcp:host=localhost,port=1234",
1203  "tcp:host=localhost,port=1234;tcp:port=5678",
1204 #ifdef DBUS_UNIX
1205  "unix:path=./boogie",
1206  "tcp:port=1234;unix:path=./boogie",
1207 #endif
1208  };
1209 
1210  DBusServer *server;
1211  int i;
1212 
1213  for (i = 0; i < _DBUS_N_ELEMENTS (valid_addresses); i++)
1214  {
1215  DBusError error = DBUS_ERROR_INIT;
1216  char *address;
1217  char *id;
1218 
1219  server = dbus_server_listen (valid_addresses[i], &error);
1220  if (server == NULL)
1221  {
1222  _dbus_warn ("server listen error: %s: %s\n", error.name, error.message);
1223  dbus_error_free (&error);
1224  _dbus_assert_not_reached ("Failed to listen for valid address.");
1225  }
1226 
1227  id = dbus_server_get_id (server);
1228  _dbus_assert (id != NULL);
1229  address = dbus_server_get_address (server);
1230  _dbus_assert (address != NULL);
1231 
1232  if (strstr (address, id) == NULL)
1233  {
1234  _dbus_warn ("server id '%s' is not in the server address '%s'\n",
1235  id, address);
1236  _dbus_assert_not_reached ("bad server id or address");
1237  }
1238 
1239  dbus_free (id);
1240  dbus_free (address);
1241 
1242  dbus_server_disconnect (server);
1243  dbus_server_unref (server);
1244  }
1245 
1246  return TRUE;
1247 }
1248 
1249 #endif /* DBUS_BUILD_TESTS */