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 (!dbus_message_set_sender (error_reply, DBUS_SERVICE_DBUS))
143 dbus_message_unref (error_reply);
148 if (!bus_transaction_send_message (transaction, connection, error_reply))
150 dbus_message_unref (error_reply);
155 dbus_message_unref (error_reply);
161 bus_dispatch (DBusConnection *connection,
162 DBusMessage *message)
164 const char *sender, *service_name, *message_name;
166 BusTransaction *transaction;
170 dbus_error_init (&error);
172 context = bus_connection_get_context (connection);
173 _dbus_assert (context != NULL);
175 /* If we can't even allocate an OOM error, we just go to sleep
178 while (!bus_connection_preallocate_oom_error (connection))
179 bus_wait_for_memory ();
181 /* Ref connection in case we disconnect it at some point in here */
182 dbus_connection_ref (connection);
184 service_name = dbus_message_get_service (message);
185 message_name = dbus_message_get_name (message);
187 _dbus_assert (message_name != NULL); /* DBusMessageLoader is supposed to check this */
189 _dbus_verbose ("DISPATCH: %s to %s\n",
190 message_name, service_name ? service_name : "peer");
192 /* If service_name is NULL, this is a message to the bus daemon, not intended
193 * to actually go "on the bus"; e.g. a peer-to-peer ping. Handle these
194 * immediately, especially disconnection messages.
196 if (service_name == NULL)
198 if (strcmp (message_name, DBUS_MESSAGE_LOCAL_DISCONNECT) == 0)
199 bus_connection_disconnected (connection);
201 /* DBusConnection also handles some of these automatically, we leave
207 _dbus_assert (service_name != NULL); /* this message is intended for bus routing */
209 /* Create our transaction */
210 transaction = bus_transaction_new (context);
211 if (transaction == NULL)
213 BUS_SET_OOM (&error);
217 /* Assign a sender to the message */
218 if (bus_connection_is_active (connection))
220 sender = bus_connection_get_name (connection);
221 _dbus_assert (sender != NULL);
223 if (!dbus_message_set_sender (message, sender))
225 BUS_SET_OOM (&error);
229 /* We need to refetch the service name here, because
230 * dbus_message_set_sender can cause the header to be
231 * reallocated, and thus the service_name pointer will become
234 service_name = dbus_message_get_service (message);
237 if (strcmp (service_name, DBUS_SERVICE_DBUS) == 0) /* to bus driver */
239 if (!bus_driver_handle_message (connection, transaction, message, &error))
242 else if (!bus_connection_is_active (connection)) /* clients must talk to bus driver first */
244 _dbus_verbose ("Received message from non-registered client. Disconnecting.\n");
245 dbus_connection_disconnect (connection);
247 /* FIXME what if we un-special-case this service and just have a flag
248 * on services that all service owners will get messages to it, not just
251 else if (strcmp (service_name, DBUS_SERVICE_BROADCAST) == 0) /* spam! */
253 if (!bus_dispatch_broadcast_message (transaction, message, &error))
256 else /* route to named service */
258 DBusString service_string;
260 BusRegistry *registry;
262 registry = bus_connection_get_registry (connection);
264 _dbus_string_init_const (&service_string, service_name);
265 service = bus_registry_lookup (registry, &service_string);
269 if (!send_service_nonexistent_error (transaction, connection,
276 _dbus_assert (bus_service_get_primary_owner (service) != NULL);
278 /* Dispatch the message */
279 if (!bus_transaction_send_message (transaction,
280 bus_service_get_primary_owner (service),
283 BUS_SET_OOM (&error);
290 if (dbus_error_is_set (&error))
292 if (!dbus_connection_get_is_connected (connection))
294 /* If we disconnected it, we won't bother to send it any error
298 else if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
300 bus_connection_send_oom_error (connection, message);
302 /* cancel transaction due to OOM */
303 if (transaction != NULL)
305 bus_transaction_cancel_and_free (transaction);
311 /* Try to send the real error, if no mem to do that, send
314 _dbus_assert (transaction != NULL);
316 if (!bus_transaction_send_error_reply (transaction, connection,
319 bus_connection_send_oom_error (connection, message);
321 /* cancel transaction due to OOM */
322 if (transaction != NULL)
324 bus_transaction_cancel_and_free (transaction);
330 dbus_error_free (&error);
333 if (transaction != NULL)
335 bus_transaction_execute_and_free (transaction);
338 dbus_connection_unref (connection);
341 static DBusHandlerResult
342 bus_dispatch_message_handler (DBusMessageHandler *handler,
343 DBusConnection *connection,
344 DBusMessage *message,
347 bus_dispatch (connection, message);
349 return DBUS_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
353 message_handler_slot_ref (void)
355 if (message_handler_slot < 0)
357 message_handler_slot = dbus_connection_allocate_data_slot ();
359 if (message_handler_slot < 0)
362 _dbus_assert (message_handler_slot_refcount == 0);
365 message_handler_slot_refcount += 1;
371 message_handler_slot_unref (void)
373 _dbus_assert (message_handler_slot_refcount > 0);
375 message_handler_slot_refcount -= 1;
377 if (message_handler_slot_refcount == 0)
379 dbus_connection_free_data_slot (message_handler_slot);
380 message_handler_slot = -1;
385 free_message_handler (void *data)
387 DBusMessageHandler *handler = data;
389 _dbus_assert (message_handler_slot >= 0);
390 _dbus_assert (message_handler_slot_refcount > 0);
392 dbus_message_handler_unref (handler);
393 message_handler_slot_unref ();
397 bus_dispatch_add_connection (DBusConnection *connection)
399 DBusMessageHandler *handler;
401 if (!message_handler_slot_ref ())
404 handler = dbus_message_handler_new (bus_dispatch_message_handler, NULL, NULL);
407 message_handler_slot_unref ();
411 if (!dbus_connection_add_filter (connection, handler))
413 dbus_message_handler_unref (handler);
414 message_handler_slot_unref ();
419 _dbus_assert (message_handler_slot >= 0);
420 _dbus_assert (message_handler_slot_refcount > 0);
422 if (!dbus_connection_set_data (connection,
423 message_handler_slot,
425 free_message_handler))
427 dbus_message_handler_unref (handler);
428 message_handler_slot_unref ();
437 bus_dispatch_remove_connection (DBusConnection *connection)
439 /* Here we tell the bus driver that we want to get off. */
440 bus_driver_remove_connection (connection);
442 dbus_connection_set_data (connection,
443 message_handler_slot,
447 #ifdef DBUS_BUILD_TESTS
449 typedef dbus_bool_t (* Check1Func) (BusContext *context);
450 typedef dbus_bool_t (* Check2Func) (BusContext *context,
451 DBusConnection *connection);
453 static dbus_bool_t check_no_leftovers (BusContext *context);
457 const char *expected_service_name;
459 } CheckServiceDeletedData;
462 check_service_deleted_foreach (DBusConnection *connection,
465 CheckServiceDeletedData *d = data;
466 DBusMessage *message;
470 dbus_error_init (&error);
474 message = dbus_connection_pop_message (connection);
477 _dbus_warn ("Did not receive a message on %p, expecting %s\n",
478 connection, DBUS_MESSAGE_SERVICE_DELETED);
481 else if (!dbus_message_name_is (message, DBUS_MESSAGE_SERVICE_DELETED))
483 _dbus_warn ("Received message %s on %p, expecting %s\n",
484 dbus_message_get_name (message),
485 connection, DBUS_MESSAGE_SERVICE_DELETED);
490 if (!dbus_message_get_args (message, &error,
491 DBUS_TYPE_STRING, &service_name,
494 if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
496 _dbus_verbose ("no memory to get service name arg\n");
500 _dbus_assert (dbus_error_is_set (&error));
501 _dbus_warn ("Did not get the expected single string argument\n");
505 else if (strcmp (service_name, d->expected_service_name) != 0)
507 _dbus_warn ("expected deletion of service %s, got deletion of %s\n",
508 d->expected_service_name,
517 dbus_free (service_name);
518 dbus_error_free (&error);
521 dbus_message_unref (message);
527 kill_client_connection (BusContext *context,
528 DBusConnection *connection)
532 CheckServiceDeletedData csdd;
534 _dbus_verbose ("killing connection %p\n", connection);
536 s = dbus_bus_get_base_service (connection);
537 _dbus_assert (s != NULL);
539 while ((base_service = _dbus_strdup (s)) == NULL)
540 bus_wait_for_memory ();
542 dbus_connection_ref (connection);
544 /* kick in the disconnect handler that unrefs the connection */
545 dbus_connection_disconnect (connection);
547 bus_test_run_everything (context);
549 _dbus_assert (bus_test_client_listed (connection));
551 /* Run disconnect handler in test.c */
552 if (bus_connection_dispatch_one_message (connection))
553 _dbus_assert_not_reached ("something received on connection being killed other than the disconnect");
555 _dbus_assert (!dbus_connection_get_is_connected (connection));
556 dbus_connection_unref (connection);
558 _dbus_assert (!bus_test_client_listed (connection));
560 csdd.expected_service_name = base_service;
563 bus_test_clients_foreach (check_service_deleted_foreach,
566 dbus_free (base_service);
569 _dbus_assert_not_reached ("didn't get the expected ServiceDeleted messages");
571 if (!check_no_leftovers (context))
572 _dbus_assert_not_reached ("stuff left in message queues after disconnecting a client");
576 kill_client_connection_unchecked (DBusConnection *connection)
578 /* This kills the connection without expecting it to affect
579 * the rest of the bus.
581 _dbus_verbose ("Unchecked kill of connection %p\n", connection);
583 dbus_connection_ref (connection);
584 dbus_connection_disconnect (connection);
585 /* dispatching disconnect handler will unref once */
586 if (bus_connection_dispatch_one_message (connection))
587 _dbus_assert_not_reached ("message other than disconnect dispatched after failure to register");
588 dbus_connection_unref (connection);
589 _dbus_assert (!bus_test_client_listed (connection));
595 } CheckNoMessagesData;
598 check_no_messages_foreach (DBusConnection *connection,
601 CheckNoMessagesData *d = data;
602 DBusMessage *message;
604 message = dbus_connection_pop_message (connection);
607 _dbus_warn ("Received message %s on %p, expecting no messages\n",
608 dbus_message_get_name (message), connection);
613 dbus_message_unref (message);
619 DBusConnection *skip_connection;
620 const char *expected_service_name;
622 } CheckServiceCreatedData;
625 check_service_created_foreach (DBusConnection *connection,
628 CheckServiceCreatedData *d = data;
629 DBusMessage *message;
633 if (connection == d->skip_connection)
636 dbus_error_init (&error);
640 message = dbus_connection_pop_message (connection);
643 _dbus_warn ("Did not receive a message on %p, expecting %s\n",
644 connection, DBUS_MESSAGE_SERVICE_CREATED);
647 else if (!dbus_message_name_is (message, DBUS_MESSAGE_SERVICE_CREATED))
649 _dbus_warn ("Received message %s on %p, expecting %s\n",
650 dbus_message_get_name (message),
651 connection, DBUS_MESSAGE_SERVICE_CREATED);
656 if (!dbus_message_get_args (message, &error,
657 DBUS_TYPE_STRING, &service_name,
660 if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
662 _dbus_verbose ("no memory to get service name arg\n");
666 _dbus_assert (dbus_error_is_set (&error));
667 _dbus_warn ("Did not get the expected single string argument\n");
671 else if (strcmp (service_name, d->expected_service_name) != 0)
673 _dbus_warn ("expected creation of service %s, got creation of %s\n",
674 d->expected_service_name,
683 dbus_free (service_name);
684 dbus_error_free (&error);
687 dbus_message_unref (message);
693 check_no_leftovers (BusContext *context)
695 CheckNoMessagesData nmd;
698 bus_test_clients_foreach (check_no_messages_foreach,
707 /* returns TRUE if the correct thing happens,
708 * but the correct thing may include OOM errors.
711 check_hello_message (BusContext *context,
712 DBusConnection *connection)
714 DBusMessage *message;
721 dbus_error_init (&error);
725 message = dbus_message_new (DBUS_SERVICE_DBUS,
731 if (!dbus_connection_send (connection, message, &serial))
733 dbus_message_unref (message);
737 dbus_message_unref (message);
740 bus_test_run_everything (context);
742 if (!dbus_connection_get_is_connected (connection))
744 _dbus_verbose ("connection was disconnected\n");
750 message = dbus_connection_pop_message (connection);
753 _dbus_warn ("Did not receive a reply to %s %d on %p\n",
754 DBUS_MESSAGE_HELLO, serial, connection);
758 _dbus_verbose ("Received %s on %p\n",
759 dbus_message_get_name (message), connection);
761 if (!dbus_message_sender_is (message, DBUS_SERVICE_DBUS))
763 _dbus_warn ("Message has wrong sender %s\n",
764 dbus_message_get_sender (message) ?
765 dbus_message_get_sender (message) : "(none)");
769 if (dbus_message_get_is_error (message))
771 if (dbus_message_name_is (message,
772 DBUS_ERROR_NO_MEMORY))
774 ; /* good, this is a valid response */
778 _dbus_warn ("Did not expect error %s\n",
779 dbus_message_get_name (message));
785 CheckServiceCreatedData scd;
787 if (dbus_message_name_is (message,
790 ; /* good, expected */
794 _dbus_warn ("Did not expect reply %s\n",
795 dbus_message_get_name (message));
799 retry_get_hello_name:
800 if (!dbus_message_get_args (message, &error,
801 DBUS_TYPE_STRING, &name,
804 if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
806 _dbus_verbose ("no memory to get service name arg from hello\n");
807 dbus_error_free (&error);
808 bus_wait_for_memory ();
809 goto retry_get_hello_name;
813 _dbus_assert (dbus_error_is_set (&error));
814 _dbus_warn ("Did not get the expected single string argument to hello\n");
819 _dbus_verbose ("Got hello name: %s\n", name);
821 while (!dbus_bus_set_base_service (connection, name))
822 bus_wait_for_memory ();
824 scd.skip_connection = NULL;
826 scd.expected_service_name = name;
827 bus_test_clients_foreach (check_service_created_foreach,
833 /* Client should also have gotten ServiceAcquired */
834 dbus_message_unref (message);
835 message = dbus_connection_pop_message (connection);
838 _dbus_warn ("Expecting %s, got nothing\n",
839 DBUS_MESSAGE_SERVICE_ACQUIRED);
843 retry_get_acquired_name:
844 if (!dbus_message_get_args (message, &error,
845 DBUS_TYPE_STRING, &acquired,
848 if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
850 _dbus_verbose ("no memory to get service name arg from acquired\n");
851 dbus_error_free (&error);
852 bus_wait_for_memory ();
853 goto retry_get_acquired_name;
857 _dbus_assert (dbus_error_is_set (&error));
858 _dbus_warn ("Did not get the expected single string argument to ServiceAcquired\n");
863 _dbus_verbose ("Got acquired name: %s\n", acquired);
865 if (strcmp (acquired, name) != 0)
867 _dbus_warn ("Acquired name is %s but expected %s\n",
873 if (!check_no_leftovers (context))
879 dbus_error_free (&error);
882 dbus_free (acquired);
885 dbus_message_unref (message);
890 /* returns TRUE if the correct thing happens,
891 * but the correct thing may include OOM errors.
894 check_hello_connection (BusContext *context)
896 DBusConnection *connection;
899 dbus_error_init (&error);
901 connection = dbus_connection_open ("debug-pipe:name=test-server", &error);
902 if (connection == NULL)
904 _DBUS_ASSERT_ERROR_IS_SET (&error);
905 dbus_error_free (&error);
909 if (!bus_setup_debug_client (connection))
911 dbus_connection_disconnect (connection);
912 dbus_connection_unref (connection);
916 if (!check_hello_message (context, connection))
919 if (dbus_bus_get_base_service (connection) == NULL)
921 /* We didn't successfully register, so we can't
922 * do the usual kill_client_connection() checks
924 kill_client_connection_unchecked (connection);
928 kill_client_connection (context, connection);
934 #define NONEXISTENT_SERVICE_NAME "test.this.service.does.not.exist.ewuoiurjdfxcvn"
936 /* returns TRUE if the correct thing happens,
937 * but the correct thing may include OOM errors.
940 check_nonexistent_service_activation (BusContext *context,
941 DBusConnection *connection)
943 DBusMessage *message;
948 dbus_error_init (&error);
950 message = dbus_message_new (DBUS_SERVICE_DBUS,
951 DBUS_MESSAGE_ACTIVATE_SERVICE);
956 if (!dbus_message_append_args (message,
957 DBUS_TYPE_STRING, NONEXISTENT_SERVICE_NAME,
961 dbus_message_unref (message);
965 if (!dbus_connection_send (connection, message, &serial))
967 dbus_message_unref (message);
971 dbus_message_unref (message);
974 bus_test_run_everything (context);
976 if (!dbus_connection_get_is_connected (connection))
978 _dbus_verbose ("connection was disconnected\n");
984 message = dbus_connection_pop_message (connection);
987 _dbus_warn ("Did not receive a reply to %s %d on %p\n",
988 DBUS_MESSAGE_ACTIVATE_SERVICE, serial, connection);
992 _dbus_verbose ("Received %s on %p\n",
993 dbus_message_get_name (message), connection);
995 if (dbus_message_get_is_error (message))
997 if (!dbus_message_sender_is (message, DBUS_SERVICE_DBUS))
999 _dbus_warn ("Message has wrong sender %s\n",
1000 dbus_message_get_sender (message) ?
1001 dbus_message_get_sender (message) : "(none)");
1005 if (dbus_message_name_is (message,
1006 DBUS_ERROR_NO_MEMORY))
1008 ; /* good, this is a valid response */
1010 else if (dbus_message_name_is (message,
1011 DBUS_ERROR_ACTIVATE_SERVICE_NOT_FOUND))
1013 ; /* good, this is expected also */
1017 _dbus_warn ("Did not expect error %s\n",
1018 dbus_message_get_name (message));
1024 _dbus_warn ("Did not expect to successfully activate %s\n",
1025 NONEXISTENT_SERVICE_NAME);
1033 dbus_message_unref (message);
1038 #define EXISTENT_SERVICE_NAME "org.freedesktop.DBus.TestSuiteEchoService"
1040 /* returns TRUE if the correct thing happens,
1041 * but the correct thing may include OOM errors.
1044 check_existent_service_activation (BusContext *context,
1045 DBusConnection *connection)
1047 DBusMessage *message;
1048 dbus_int32_t serial;
1052 dbus_error_init (&error);
1054 message = dbus_message_new (DBUS_SERVICE_DBUS,
1055 DBUS_MESSAGE_ACTIVATE_SERVICE);
1057 if (message == NULL)
1060 if (!dbus_message_append_args (message,
1061 DBUS_TYPE_STRING, EXISTENT_SERVICE_NAME,
1062 DBUS_TYPE_UINT32, 0,
1065 dbus_message_unref (message);
1069 if (!dbus_connection_send (connection, message, &serial))
1071 dbus_message_unref (message);
1075 dbus_message_unref (message);
1078 bus_test_run_everything (context);
1080 if (dbus_connection_get_dispatch_status (connection) ==
1081 DBUS_DISPATCH_COMPLETE)
1082 /* now wait for the message bus to hear back from the activated service */
1083 bus_test_run_bus_loop (context);
1085 /* and process everything again */
1086 bus_test_run_everything (context);
1088 if (!dbus_connection_get_is_connected (connection))
1090 _dbus_verbose ("connection was disconnected\n");
1096 message = dbus_connection_pop_message (connection);
1097 if (message == NULL)
1099 _dbus_warn ("Did not receive a reply to %s %d on %p\n",
1100 DBUS_MESSAGE_ACTIVATE_SERVICE, serial, connection);
1104 _dbus_verbose ("Received %s on %p\n",
1105 dbus_message_get_name (message), connection);
1107 if (dbus_message_get_is_error (message))
1109 if (!dbus_message_sender_is (message, DBUS_SERVICE_DBUS))
1111 _dbus_warn ("Message has wrong sender %s\n",
1112 dbus_message_get_sender (message) ?
1113 dbus_message_get_sender (message) : "(none)");
1117 if (dbus_message_name_is (message,
1118 DBUS_ERROR_NO_MEMORY))
1120 ; /* good, this is a valid response */
1122 else if (dbus_message_name_is (message,
1123 DBUS_ERROR_ACTIVATE_SERVICE_NOT_FOUND))
1125 ; /* good, this is expected also */
1129 _dbus_warn ("Did not expect error %s\n",
1130 dbus_message_get_name (message));
1136 _dbus_warn ("Did not expect to successfully activate %s\n",
1137 EXISTENT_SERVICE_NAME);
1145 dbus_message_unref (message);
1153 BusContext *context;
1157 check_oom_check1_func (void *data)
1159 Check1Data *d = data;
1161 if (! (* d->func) (d->context))
1164 if (!check_no_leftovers (d->context))
1166 _dbus_warn ("Messages were left over, should be covered by test suite");
1174 check1_try_iterations (BusContext *context,
1175 const char *description,
1181 d.context = context;
1183 if (!_dbus_test_oom_handling (description, check_oom_check1_func,
1185 _dbus_assert_not_reached ("test failed");
1191 BusContext *context;
1192 DBusConnection *connection;
1196 check_oom_check2_func (void *data)
1198 Check2Data *d = data;
1200 if (! (* d->func) (d->context, d->connection))
1203 if (!check_no_leftovers (d->context))
1205 _dbus_warn ("Messages were left over, should be covered by test suite");
1213 check2_try_iterations (BusContext *context,
1214 DBusConnection *connection,
1215 const char *description,
1221 d.context = context;
1222 d.connection = connection;
1224 if (!_dbus_test_oom_handling (description, check_oom_check2_func,
1226 _dbus_assert_not_reached ("test failed");
1230 bus_dispatch_test (const DBusString *test_data_dir)
1232 BusContext *context;
1233 DBusConnection *foo;
1234 DBusConnection *bar;
1235 DBusConnection *baz;
1238 context = bus_context_new_test (test_data_dir,
1239 "valid-config-files/debug-allow-all.conf");
1240 if (context == NULL)
1243 dbus_error_init (&error);
1245 foo = dbus_connection_open ("debug-pipe:name=test-server", &error);
1247 _dbus_assert_not_reached ("could not alloc connection");
1249 if (!bus_setup_debug_client (foo))
1250 _dbus_assert_not_reached ("could not set up connection");
1252 if (!check_hello_message (context, foo))
1253 _dbus_assert_not_reached ("hello message failed");
1255 bar = dbus_connection_open ("debug-pipe:name=test-server", &error);
1257 _dbus_assert_not_reached ("could not alloc connection");
1259 if (!bus_setup_debug_client (bar))
1260 _dbus_assert_not_reached ("could not set up connection");
1262 if (!check_hello_message (context, bar))
1263 _dbus_assert_not_reached ("hello message failed");
1265 baz = dbus_connection_open ("debug-pipe:name=test-server", &error);
1267 _dbus_assert_not_reached ("could not alloc connection");
1269 if (!bus_setup_debug_client (baz))
1270 _dbus_assert_not_reached ("could not set up connection");
1272 if (!check_hello_message (context, baz))
1273 _dbus_assert_not_reached ("hello message failed");
1276 check2_try_iterations (context, foo, "existent_service_activation",
1277 check_existent_service_activation);
1280 check2_try_iterations (context, foo, "nonexistent_service_activation",
1281 check_nonexistent_service_activation);
1283 check1_try_iterations (context, "create_and_hello",
1284 check_hello_connection);
1286 _dbus_verbose ("Disconnecting foo, bar, and baz\n");
1288 kill_client_connection_unchecked (foo);
1289 kill_client_connection_unchecked (bar);
1290 kill_client_connection_unchecked (baz);
1292 bus_context_unref (context);
1296 #endif /* DBUS_BUILD_TESTS */