1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dispatch.c Message dispatcher
4 * Copyright (C) 2003 CodeFactory AB
5 * Copyright (C) 2003 Red Hat, Inc.
7 * Licensed under the Academic Free License version 1.2
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "connection.h"
33 #include <dbus/dbus-internals.h>
36 static int message_handler_slot = -1;
37 static int message_handler_slot_refcount;
42 BusTransaction *transaction;
47 send_one_message (DBusConnection *connection, void *data)
49 SendMessageData *d = data;
51 if (!bus_connection_is_active (connection))
54 if (!bus_transaction_send_message (d->transaction,
58 BUS_SET_OOM (d->error);
66 bus_dispatch_broadcast_message (BusTransaction *transaction,
72 BusConnections *connections;
74 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
76 _dbus_assert (dbus_message_get_sender (message) != NULL);
78 connections = bus_transaction_get_connections (transaction);
80 dbus_error_init (&tmp_error);
82 d.transaction = transaction;
85 bus_connections_foreach (connections, send_one_message, &d);
87 if (dbus_error_is_set (&tmp_error))
89 dbus_move_error (&tmp_error, error);
97 send_service_nonexistent_error (BusTransaction *transaction,
98 DBusConnection *connection,
99 const char *service_name,
100 DBusMessage *in_reply_to,
103 DBusMessage *error_reply;
104 DBusString error_message;
105 const char *error_str;
107 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
109 /* Trying to send a message to a non-existant service,
110 * bounce back an error message.
113 if (!_dbus_string_init (&error_message))
119 if (!_dbus_string_append (&error_message, "Service \"") ||
120 !_dbus_string_append (&error_message, service_name) ||
121 !_dbus_string_append (&error_message, "\" does not exist"))
123 _dbus_string_free (&error_message);
128 error_str = _dbus_string_get_const_data (&error_message);
129 error_reply = dbus_message_new_error_reply (in_reply_to,
130 DBUS_ERROR_SERVICE_DOES_NOT_EXIST,
133 _dbus_string_free (&error_message);
135 if (error_reply == NULL)
141 if (!bus_transaction_send_message (transaction, connection, error_reply))
143 dbus_message_unref (error_reply);
148 dbus_message_unref (error_reply);
154 bus_dispatch (DBusConnection *connection,
155 DBusMessage *message)
157 const char *sender, *service_name, *message_name;
159 BusTransaction *transaction;
163 dbus_error_init (&error);
165 context = bus_connection_get_context (connection);
166 _dbus_assert (context != NULL);
168 /* If we can't even allocate an OOM error, we just go to sleep
171 while (!bus_connection_preallocate_oom_error (connection))
172 bus_wait_for_memory ();
174 /* Ref connection in case we disconnect it at some point in here */
175 dbus_connection_ref (connection);
177 service_name = dbus_message_get_service (message);
178 message_name = dbus_message_get_name (message);
180 _dbus_assert (message_name != NULL); /* DBusMessageLoader is supposed to check this */
182 _dbus_verbose ("DISPATCH: %s to %s\n",
183 message_name, service_name ? service_name : "peer");
185 /* If service_name is NULL, this is a message to the bus daemon, not intended
186 * to actually go "on the bus"; e.g. a peer-to-peer ping. Handle these
187 * immediately, especially disconnection messages.
189 if (service_name == NULL)
191 if (strcmp (message_name, DBUS_MESSAGE_LOCAL_DISCONNECT) == 0)
192 bus_connection_disconnected (connection);
194 /* DBusConnection also handles some of these automatically, we leave
200 _dbus_assert (service_name != NULL); /* this message is intended for bus routing */
202 /* Create our transaction */
203 transaction = bus_transaction_new (context);
204 if (transaction == NULL)
206 BUS_SET_OOM (&error);
210 /* Assign a sender to the message */
211 if (bus_connection_is_active (connection))
213 sender = bus_connection_get_name (connection);
214 _dbus_assert (sender != NULL);
216 if (!dbus_message_set_sender (message, sender))
218 BUS_SET_OOM (&error);
222 /* We need to refetch the service name here, because
223 * dbus_message_set_sender can cause the header to be
224 * reallocated, and thus the service_name pointer will become
227 service_name = dbus_message_get_service (message);
230 if (strcmp (service_name, DBUS_SERVICE_DBUS) == 0) /* to bus driver */
232 if (!bus_driver_handle_message (connection, transaction, message, &error))
235 else if (!bus_connection_is_active (connection)) /* clients must talk to bus driver first */
237 _dbus_verbose ("Received message from non-registered client. Disconnecting.\n");
238 dbus_connection_disconnect (connection);
240 /* FIXME what if we un-special-case this service and just have a flag
241 * on services that all service owners will get messages to it, not just
244 else if (strcmp (service_name, DBUS_SERVICE_BROADCAST) == 0) /* spam! */
246 if (!bus_dispatch_broadcast_message (transaction, message, &error))
249 else /* route to named service */
251 DBusString service_string;
253 BusRegistry *registry;
255 registry = bus_connection_get_registry (connection);
257 _dbus_string_init_const (&service_string, service_name);
258 service = bus_registry_lookup (registry, &service_string);
262 if (!send_service_nonexistent_error (transaction, connection,
269 _dbus_assert (bus_service_get_primary_owner (service) != NULL);
271 /* Dispatch the message */
272 if (!bus_transaction_send_message (transaction,
273 bus_service_get_primary_owner (service),
276 BUS_SET_OOM (&error);
283 if (dbus_error_is_set (&error))
285 if (!dbus_connection_get_is_connected (connection))
287 /* If we disconnected it, we won't bother to send it any error
291 else if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
293 bus_connection_send_oom_error (connection, message);
295 /* cancel transaction due to OOM */
296 if (transaction != NULL)
298 bus_transaction_cancel_and_free (transaction);
304 /* Try to send the real error, if no mem to do that, send
307 _dbus_assert (transaction != NULL);
309 if (!bus_transaction_send_error_reply (transaction, connection,
312 bus_connection_send_oom_error (connection, message);
314 /* cancel transaction due to OOM */
315 if (transaction != NULL)
317 bus_transaction_cancel_and_free (transaction);
323 dbus_error_free (&error);
326 if (transaction != NULL)
328 bus_transaction_execute_and_free (transaction);
331 dbus_connection_unref (connection);
334 static DBusHandlerResult
335 bus_dispatch_message_handler (DBusMessageHandler *handler,
336 DBusConnection *connection,
337 DBusMessage *message,
340 bus_dispatch (connection, message);
342 return DBUS_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
346 message_handler_slot_ref (void)
348 if (message_handler_slot < 0)
350 message_handler_slot = dbus_connection_allocate_data_slot ();
352 if (message_handler_slot < 0)
355 _dbus_assert (message_handler_slot_refcount == 0);
358 message_handler_slot_refcount += 1;
364 message_handler_slot_unref (void)
366 _dbus_assert (message_handler_slot_refcount > 0);
368 message_handler_slot_refcount -= 1;
370 if (message_handler_slot_refcount == 0)
372 dbus_connection_free_data_slot (message_handler_slot);
373 message_handler_slot = -1;
378 free_message_handler (void *data)
380 DBusMessageHandler *handler = data;
382 _dbus_assert (message_handler_slot >= 0);
383 _dbus_assert (message_handler_slot_refcount > 0);
385 dbus_message_handler_unref (handler);
386 message_handler_slot_unref ();
390 bus_dispatch_add_connection (DBusConnection *connection)
392 DBusMessageHandler *handler;
394 if (!message_handler_slot_ref ())
397 handler = dbus_message_handler_new (bus_dispatch_message_handler, NULL, NULL);
400 message_handler_slot_unref ();
404 if (!dbus_connection_add_filter (connection, handler))
406 dbus_message_handler_unref (handler);
407 message_handler_slot_unref ();
412 _dbus_assert (message_handler_slot >= 0);
413 _dbus_assert (message_handler_slot_refcount > 0);
415 if (!dbus_connection_set_data (connection,
416 message_handler_slot,
418 free_message_handler))
420 dbus_message_handler_unref (handler);
421 message_handler_slot_unref ();
430 bus_dispatch_remove_connection (DBusConnection *connection)
432 /* Here we tell the bus driver that we want to get off. */
433 bus_driver_remove_connection (connection);
435 dbus_connection_set_data (connection,
436 message_handler_slot,
440 #ifdef DBUS_BUILD_TESTS
442 typedef dbus_bool_t (* Check1Func) (BusContext *context);
443 typedef dbus_bool_t (* Check2Func) (BusContext *context,
444 DBusConnection *connection);
446 static dbus_bool_t check_no_leftovers (BusContext *context);
450 const char *expected_service_name;
452 } CheckServiceDeletedData;
455 check_service_deleted_foreach (DBusConnection *connection,
458 CheckServiceDeletedData *d = data;
459 DBusMessage *message;
463 dbus_error_init (&error);
467 message = dbus_connection_pop_message (connection);
470 _dbus_warn ("Did not receive a message on %p, expecting %s\n",
471 connection, DBUS_MESSAGE_SERVICE_DELETED);
474 else if (!dbus_message_name_is (message, DBUS_MESSAGE_SERVICE_DELETED))
476 _dbus_warn ("Received message %s on %p, expecting %s\n",
477 dbus_message_get_name (message),
478 connection, DBUS_MESSAGE_SERVICE_DELETED);
483 if (!dbus_message_get_args (message, &error,
484 DBUS_TYPE_STRING, &service_name,
487 if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
489 _dbus_verbose ("no memory to get service name arg\n");
493 _dbus_assert (dbus_error_is_set (&error));
494 _dbus_warn ("Did not get the expected single string argument\n");
498 else if (strcmp (service_name, d->expected_service_name) != 0)
500 _dbus_warn ("expected deletion of service %s, got deletion of %s\n",
501 d->expected_service_name,
510 dbus_free (service_name);
511 dbus_error_free (&error);
514 dbus_message_unref (message);
520 kill_client_connection (BusContext *context,
521 DBusConnection *connection)
525 CheckServiceDeletedData csdd;
527 _dbus_verbose ("killing connection %p\n", connection);
529 s = dbus_bus_get_base_service (connection);
530 _dbus_assert (s != NULL);
532 while ((base_service = _dbus_strdup (s)) == NULL)
533 bus_wait_for_memory ();
535 dbus_connection_ref (connection);
537 /* kick in the disconnect handler that unrefs the connection */
538 dbus_connection_disconnect (connection);
540 bus_test_run_everything (context);
542 _dbus_assert (bus_test_client_listed (connection));
544 /* Run disconnect handler in test.c */
545 if (bus_connection_dispatch_one_message (connection))
546 _dbus_assert_not_reached ("something received on connection being killed other than the disconnect");
548 _dbus_assert (!dbus_connection_get_is_connected (connection));
549 dbus_connection_unref (connection);
551 _dbus_assert (!bus_test_client_listed (connection));
553 csdd.expected_service_name = base_service;
556 bus_test_clients_foreach (check_service_deleted_foreach,
559 dbus_free (base_service);
562 _dbus_assert_not_reached ("didn't get the expected ServiceDeleted messages");
564 if (!check_no_leftovers (context))
565 _dbus_assert_not_reached ("stuff left in message queues after disconnecting a client");
569 kill_client_connection_unchecked (DBusConnection *connection)
571 /* This kills the connection without expecting it to affect
572 * the rest of the bus.
574 _dbus_verbose ("Unchecked kill of connection %p\n", connection);
576 dbus_connection_ref (connection);
577 dbus_connection_disconnect (connection);
578 /* dispatching disconnect handler will unref once */
579 if (bus_connection_dispatch_one_message (connection))
580 _dbus_assert_not_reached ("message other than disconnect dispatched after failure to register");
581 dbus_connection_unref (connection);
582 _dbus_assert (!bus_test_client_listed (connection));
588 } CheckNoMessagesData;
591 check_no_messages_foreach (DBusConnection *connection,
594 CheckNoMessagesData *d = data;
595 DBusMessage *message;
597 message = dbus_connection_pop_message (connection);
600 _dbus_warn ("Received message %s on %p, expecting no messages\n",
601 dbus_message_get_name (message), connection);
606 dbus_message_unref (message);
612 DBusConnection *skip_connection;
613 const char *expected_service_name;
615 } CheckServiceCreatedData;
618 check_service_created_foreach (DBusConnection *connection,
621 CheckServiceCreatedData *d = data;
622 DBusMessage *message;
626 if (connection == d->skip_connection)
629 dbus_error_init (&error);
633 message = dbus_connection_pop_message (connection);
636 _dbus_warn ("Did not receive a message on %p, expecting %s\n",
637 connection, DBUS_MESSAGE_SERVICE_CREATED);
640 else if (!dbus_message_name_is (message, DBUS_MESSAGE_SERVICE_CREATED))
642 _dbus_warn ("Received message %s on %p, expecting %s\n",
643 dbus_message_get_name (message),
644 connection, DBUS_MESSAGE_SERVICE_CREATED);
649 if (!dbus_message_get_args (message, &error,
650 DBUS_TYPE_STRING, &service_name,
653 if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
655 _dbus_verbose ("no memory to get service name arg\n");
659 _dbus_assert (dbus_error_is_set (&error));
660 _dbus_warn ("Did not get the expected single string argument\n");
664 else if (strcmp (service_name, d->expected_service_name) != 0)
666 _dbus_warn ("expected creation of service %s, got creation of %s\n",
667 d->expected_service_name,
676 dbus_free (service_name);
677 dbus_error_free (&error);
680 dbus_message_unref (message);
686 check_no_leftovers (BusContext *context)
688 CheckNoMessagesData nmd;
691 bus_test_clients_foreach (check_no_messages_foreach,
700 /* returns TRUE if the correct thing happens,
701 * but the correct thing may include OOM errors.
704 check_hello_message (BusContext *context,
705 DBusConnection *connection)
707 DBusMessage *message;
714 dbus_error_init (&error);
718 message = dbus_message_new (DBUS_SERVICE_DBUS,
724 if (!dbus_connection_send (connection, message, &serial))
726 dbus_message_unref (message);
730 dbus_message_unref (message);
733 bus_test_run_everything (context);
735 if (!dbus_connection_get_is_connected (connection))
737 _dbus_verbose ("connection was disconnected\n");
743 message = dbus_connection_pop_message (connection);
746 _dbus_warn ("Did not receive a reply to %s %d on %p\n",
747 DBUS_MESSAGE_HELLO, serial, connection);
751 _dbus_verbose ("Received %s on %p\n",
752 dbus_message_get_name (message), connection);
754 if (!dbus_message_sender_is (message, DBUS_SERVICE_DBUS))
756 _dbus_warn ("Message has wrong sender %s\n",
757 dbus_message_get_sender (message) ?
758 dbus_message_get_sender (message) : "(none)");
762 if (dbus_message_get_is_error (message))
764 if (dbus_message_name_is (message,
765 DBUS_ERROR_NO_MEMORY))
767 ; /* good, this is a valid response */
771 _dbus_warn ("Did not expect error %s\n",
772 dbus_message_get_name (message));
778 CheckServiceCreatedData scd;
780 if (dbus_message_name_is (message,
783 ; /* good, expected */
787 _dbus_warn ("Did not expect reply %s\n",
788 dbus_message_get_name (message));
792 retry_get_hello_name:
793 if (!dbus_message_get_args (message, &error,
794 DBUS_TYPE_STRING, &name,
797 if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
799 _dbus_verbose ("no memory to get service name arg from hello\n");
800 dbus_error_free (&error);
801 bus_wait_for_memory ();
802 goto retry_get_hello_name;
806 _dbus_assert (dbus_error_is_set (&error));
807 _dbus_warn ("Did not get the expected single string argument to hello\n");
812 _dbus_verbose ("Got hello name: %s\n", name);
814 while (!dbus_bus_set_base_service (connection, name))
815 bus_wait_for_memory ();
817 scd.skip_connection = NULL;
819 scd.expected_service_name = name;
820 bus_test_clients_foreach (check_service_created_foreach,
826 /* Client should also have gotten ServiceAcquired */
827 dbus_message_unref (message);
828 message = dbus_connection_pop_message (connection);
831 _dbus_warn ("Expecting %s, got nothing\n",
832 DBUS_MESSAGE_SERVICE_ACQUIRED);
836 retry_get_acquired_name:
837 if (!dbus_message_get_args (message, &error,
838 DBUS_TYPE_STRING, &acquired,
841 if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
843 _dbus_verbose ("no memory to get service name arg from acquired\n");
844 dbus_error_free (&error);
845 bus_wait_for_memory ();
846 goto retry_get_acquired_name;
850 _dbus_assert (dbus_error_is_set (&error));
851 _dbus_warn ("Did not get the expected single string argument to ServiceAcquired\n");
856 _dbus_verbose ("Got acquired name: %s\n", acquired);
858 if (strcmp (acquired, name) != 0)
860 _dbus_warn ("Acquired name is %s but expected %s\n",
866 if (!check_no_leftovers (context))
872 dbus_error_free (&error);
875 dbus_free (acquired);
878 dbus_message_unref (message);
883 /* returns TRUE if the correct thing happens,
884 * but the correct thing may include OOM errors.
887 check_hello_connection (BusContext *context)
889 DBusConnection *connection;
892 dbus_error_init (&error);
894 connection = dbus_connection_open ("debug-pipe:name=test-server", &error);
895 if (connection == NULL)
897 _DBUS_ASSERT_ERROR_IS_SET (&error);
898 dbus_error_free (&error);
902 if (!bus_setup_debug_client (connection))
904 dbus_connection_disconnect (connection);
905 dbus_connection_unref (connection);
909 if (!check_hello_message (context, connection))
912 if (dbus_bus_get_base_service (connection) == NULL)
914 /* We didn't successfully register, so we can't
915 * do the usual kill_client_connection() checks
917 kill_client_connection_unchecked (connection);
921 kill_client_connection (context, connection);
927 #define NONEXISTENT_SERVICE_NAME "test.this.service.does.not.exist.ewuoiurjdfxcvn"
929 /* returns TRUE if the correct thing happens,
930 * but the correct thing may include OOM errors.
933 check_nonexistent_service_activation (BusContext *context,
934 DBusConnection *connection)
936 DBusMessage *message;
941 dbus_error_init (&error);
943 message = dbus_message_new (DBUS_SERVICE_DBUS,
944 DBUS_MESSAGE_ACTIVATE_SERVICE);
949 if (!dbus_message_append_args (message,
950 DBUS_TYPE_STRING, NONEXISTENT_SERVICE_NAME,
954 dbus_message_unref (message);
958 if (!dbus_connection_send (connection, message, &serial))
960 dbus_message_unref (message);
964 dbus_message_unref (message);
967 bus_test_run_everything (context);
969 if (!dbus_connection_get_is_connected (connection))
971 _dbus_verbose ("connection was disconnected\n");
977 message = dbus_connection_pop_message (connection);
980 _dbus_warn ("Did not receive a reply to %s %d on %p\n",
981 DBUS_MESSAGE_ACTIVATE_SERVICE, serial, connection);
985 _dbus_verbose ("Received %s on %p\n",
986 dbus_message_get_name (message), connection);
988 if (dbus_message_get_is_error (message))
990 if (!dbus_message_sender_is (message, DBUS_SERVICE_DBUS))
992 _dbus_warn ("Message has wrong sender %s\n",
993 dbus_message_get_sender (message) ?
994 dbus_message_get_sender (message) : "(none)");
998 if (dbus_message_name_is (message,
999 DBUS_ERROR_NO_MEMORY))
1001 ; /* good, this is a valid response */
1003 else if (dbus_message_name_is (message,
1004 DBUS_ERROR_ACTIVATE_SERVICE_NOT_FOUND))
1006 ; /* good, this is expected also */
1010 _dbus_warn ("Did not expect error %s\n",
1011 dbus_message_get_name (message));
1017 _dbus_warn ("Did not expect to successfully activate %s\n",
1018 NONEXISTENT_SERVICE_NAME);
1026 dbus_message_unref (message);
1031 #define EXISTENT_SERVICE_NAME "org.freedesktop.DBus.TestSuiteEchoService"
1033 /* returns TRUE if the correct thing happens,
1034 * but the correct thing may include OOM errors.
1037 check_existent_service_activation (BusContext *context,
1038 DBusConnection *connection)
1040 DBusMessage *message;
1041 dbus_int32_t serial;
1045 dbus_error_init (&error);
1047 message = dbus_message_new (DBUS_SERVICE_DBUS,
1048 DBUS_MESSAGE_ACTIVATE_SERVICE);
1050 if (message == NULL)
1053 if (!dbus_message_append_args (message,
1054 DBUS_TYPE_STRING, EXISTENT_SERVICE_NAME,
1055 DBUS_TYPE_UINT32, 0,
1058 dbus_message_unref (message);
1062 if (!dbus_connection_send (connection, message, &serial))
1064 dbus_message_unref (message);
1068 dbus_message_unref (message);
1071 bus_test_run_everything (context);
1073 if (dbus_connection_get_dispatch_status (connection) ==
1074 DBUS_DISPATCH_COMPLETE)
1075 /* now wait for the message bus to hear back from the activated service */
1076 bus_test_run_bus_loop (context);
1078 /* and process everything again */
1079 bus_test_run_everything (context);
1081 if (!dbus_connection_get_is_connected (connection))
1083 _dbus_verbose ("connection was disconnected\n");
1089 message = dbus_connection_pop_message (connection);
1090 if (message == NULL)
1092 _dbus_warn ("Did not receive a reply to %s %d on %p\n",
1093 DBUS_MESSAGE_ACTIVATE_SERVICE, serial, connection);
1097 _dbus_verbose ("Received %s on %p\n",
1098 dbus_message_get_name (message), connection);
1100 if (dbus_message_get_is_error (message))
1102 if (!dbus_message_sender_is (message, DBUS_SERVICE_DBUS))
1104 _dbus_warn ("Message has wrong sender %s\n",
1105 dbus_message_get_sender (message) ?
1106 dbus_message_get_sender (message) : "(none)");
1110 if (dbus_message_name_is (message,
1111 DBUS_ERROR_NO_MEMORY))
1113 ; /* good, this is a valid response */
1115 else if (dbus_message_name_is (message,
1116 DBUS_ERROR_ACTIVATE_SERVICE_NOT_FOUND))
1118 ; /* good, this is expected also */
1122 _dbus_warn ("Did not expect error %s\n",
1123 dbus_message_get_name (message));
1129 _dbus_warn ("Did not expect to successfully activate %s\n",
1130 EXISTENT_SERVICE_NAME);
1138 dbus_message_unref (message);
1146 BusContext *context;
1150 check_oom_check1_func (void *data)
1152 Check1Data *d = data;
1154 if (! (* d->func) (d->context))
1157 if (!check_no_leftovers (d->context))
1159 _dbus_warn ("Messages were left over, should be covered by test suite");
1167 check1_try_iterations (BusContext *context,
1168 const char *description,
1174 d.context = context;
1176 if (!_dbus_test_oom_handling (description, check_oom_check1_func,
1178 _dbus_assert_not_reached ("test failed");
1184 BusContext *context;
1185 DBusConnection *connection;
1189 check_oom_check2_func (void *data)
1191 Check2Data *d = data;
1193 if (! (* d->func) (d->context, d->connection))
1196 if (!check_no_leftovers (d->context))
1198 _dbus_warn ("Messages were left over, should be covered by test suite");
1206 check2_try_iterations (BusContext *context,
1207 DBusConnection *connection,
1208 const char *description,
1214 d.context = context;
1215 d.connection = connection;
1217 if (!_dbus_test_oom_handling (description, check_oom_check2_func,
1219 _dbus_assert_not_reached ("test failed");
1223 bus_dispatch_test (const DBusString *test_data_dir)
1225 BusContext *context;
1226 DBusConnection *foo;
1227 DBusConnection *bar;
1228 DBusConnection *baz;
1231 context = bus_context_new_test (test_data_dir,
1232 "valid-config-files/debug-allow-all.conf");
1233 if (context == NULL)
1236 dbus_error_init (&error);
1238 foo = dbus_connection_open ("debug-pipe:name=test-server", &error);
1240 _dbus_assert_not_reached ("could not alloc connection");
1242 if (!bus_setup_debug_client (foo))
1243 _dbus_assert_not_reached ("could not set up connection");
1245 if (!check_hello_message (context, foo))
1246 _dbus_assert_not_reached ("hello message failed");
1248 bar = dbus_connection_open ("debug-pipe:name=test-server", &error);
1250 _dbus_assert_not_reached ("could not alloc connection");
1252 if (!bus_setup_debug_client (bar))
1253 _dbus_assert_not_reached ("could not set up connection");
1255 if (!check_hello_message (context, bar))
1256 _dbus_assert_not_reached ("hello message failed");
1258 baz = dbus_connection_open ("debug-pipe:name=test-server", &error);
1260 _dbus_assert_not_reached ("could not alloc connection");
1262 if (!bus_setup_debug_client (baz))
1263 _dbus_assert_not_reached ("could not set up connection");
1265 if (!check_hello_message (context, baz))
1266 _dbus_assert_not_reached ("hello message failed");
1269 check2_try_iterations (context, foo, "existent_service_activation",
1270 check_existent_service_activation);
1273 check2_try_iterations (context, foo, "nonexistent_service_activation",
1274 check_nonexistent_service_activation);
1276 check1_try_iterations (context, "create_and_hello",
1277 check_hello_connection);
1279 _dbus_verbose ("Disconnecting foo, bar, and baz\n");
1281 kill_client_connection_unchecked (foo);
1282 kill_client_connection_unchecked (bar);
1283 kill_client_connection_unchecked (baz);
1285 bus_context_unref (context);
1289 #endif /* DBUS_BUILD_TESTS */