1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dispatch.c Message dispatcher
4 * Copyright (C) 2003 CodeFactory AB
5 * Copyright (C) 2003, 2004, 2005 Red Hat, Inc.
6 * Copyright (C) 2004 Imendio HB
8 * Licensed under the Academic Free License version 2.1
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "connection.h"
30 #include "activation.h"
35 #include <dbus/dbus-internals.h>
39 send_one_message (DBusConnection *connection,
41 DBusConnection *sender,
42 DBusConnection *addressed_recipient,
44 BusTransaction *transaction,
47 if (!bus_context_check_security_policy (context, transaction,
53 return TRUE; /* silently don't send it */
55 if (!bus_transaction_send (transaction,
67 bus_dispatch_matches (BusTransaction *transaction,
68 DBusConnection *sender,
69 DBusConnection *addressed_recipient,
74 BusConnections *connections;
76 BusMatchmaker *matchmaker;
80 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
82 /* sender and recipient can both be NULL for the bus driver,
83 * or for signals with no particular recipient
86 _dbus_assert (sender == NULL || bus_connection_is_active (sender));
87 _dbus_assert (dbus_message_get_sender (message) != NULL);
89 connections = bus_transaction_get_connections (transaction);
91 dbus_error_init (&tmp_error);
92 context = bus_transaction_get_context (transaction);
93 matchmaker = bus_context_get_matchmaker (context);
96 if (!bus_matchmaker_get_recipients (matchmaker, connections,
97 sender, addressed_recipient, message,
104 link = _dbus_list_get_first_link (&recipients);
107 DBusConnection *dest;
111 if (!send_one_message (dest, context, sender, addressed_recipient,
112 message, transaction, &tmp_error))
115 link = _dbus_list_get_next_link (&recipients, link);
118 _dbus_list_clear (&recipients);
120 if (dbus_error_is_set (&tmp_error))
122 dbus_move_error (&tmp_error, error);
129 static DBusHandlerResult
130 bus_dispatch (DBusConnection *connection,
131 DBusMessage *message)
133 const char *sender, *service_name;
135 BusTransaction *transaction;
137 DBusHandlerResult result;
138 DBusConnection *addressed_recipient;
140 result = DBUS_HANDLER_RESULT_HANDLED;
143 addressed_recipient = NULL;
144 dbus_error_init (&error);
146 context = bus_connection_get_context (connection);
147 _dbus_assert (context != NULL);
149 /* If we can't even allocate an OOM error, we just go to sleep
152 while (!bus_connection_preallocate_oom_error (connection))
153 _dbus_wait_for_memory ();
155 /* Ref connection in case we disconnect it at some point in here */
156 dbus_connection_ref (connection);
158 service_name = dbus_message_get_destination (message);
160 #ifdef DBUS_ENABLE_VERBOSE_MODE
162 const char *interface_name, *member_name, *error_name;
164 interface_name = dbus_message_get_interface (message);
165 member_name = dbus_message_get_member (message);
166 error_name = dbus_message_get_error_name (message);
168 _dbus_verbose ("DISPATCH: %s %s %s to %s\n",
169 interface_name ? interface_name : "(no interface)",
170 member_name ? member_name : "(no member)",
171 error_name ? error_name : "(no error name)",
172 service_name ? service_name : "peer");
174 #endif /* DBUS_ENABLE_VERBOSE_MODE */
176 /* If service_name is NULL, if it's a signal we send it to all
177 * connections with a match rule. If it's not a signal, there
178 * are some special cases here but mostly we just bail out.
180 if (service_name == NULL)
182 if (dbus_message_is_signal (message,
183 DBUS_INTERFACE_ORG_FREEDESKTOP_LOCAL,
186 bus_connection_disconnected (connection);
190 if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_SIGNAL)
192 /* DBusConnection also handles some of these automatically, we leave
195 result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
200 /* Create our transaction */
201 transaction = bus_transaction_new (context);
202 if (transaction == NULL)
204 BUS_SET_OOM (&error);
208 /* Assign a sender to the message */
209 if (bus_connection_is_active (connection))
211 sender = bus_connection_get_name (connection);
212 _dbus_assert (sender != NULL);
214 if (!dbus_message_set_sender (message, sender))
216 BUS_SET_OOM (&error);
220 /* We need to refetch the service name here, because
221 * dbus_message_set_sender can cause the header to be
222 * reallocated, and thus the service_name pointer will become
225 service_name = dbus_message_get_destination (message);
229 strcmp (service_name, DBUS_SERVICE_ORG_FREEDESKTOP_DBUS) == 0) /* to bus driver */
231 if (!bus_context_check_security_policy (context, transaction,
232 connection, NULL, NULL, message, &error))
234 _dbus_verbose ("Security policy rejected message\n");
238 _dbus_verbose ("Giving message to %s\n", DBUS_SERVICE_ORG_FREEDESKTOP_DBUS);
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);
248 else if (service_name != NULL) /* route to named service */
250 DBusString service_string;
252 BusRegistry *registry;
254 _dbus_assert (service_name != NULL);
256 registry = bus_connection_get_registry (connection);
258 _dbus_string_init_const (&service_string, service_name);
259 service = bus_registry_lookup (registry, &service_string);
261 if (service == NULL && dbus_message_get_auto_activation (message))
263 BusActivation *activation;
265 /* We can't do the security policy check here, since the addressed
266 * recipient service doesn't exist yet. We do it before sending the
267 * message after the service has been created.
269 activation = bus_connection_get_activation (connection);
271 if (!bus_activation_activate_service (activation, connection, transaction, TRUE,
272 message, service_name, &error))
274 _DBUS_ASSERT_ERROR_IS_SET (&error);
275 _dbus_verbose ("bus_activation_activate_service() failed\n");
281 else if (service == NULL)
283 dbus_set_error (&error,
284 DBUS_ERROR_SERVICE_DOES_NOT_EXIST,
285 "Service \"%s\" does not exist",
291 addressed_recipient = bus_service_get_primary_owner (service);
292 _dbus_assert (addressed_recipient != NULL);
294 if (!bus_context_check_security_policy (context, transaction,
295 connection, addressed_recipient,
300 /* Dispatch the message */
301 if (!bus_transaction_send (transaction, addressed_recipient, message))
303 BUS_SET_OOM (&error);
309 /* Now match the messages against any match rules, which will send
310 * out signals and such. addressed_recipient may == NULL.
312 if (!bus_dispatch_matches (transaction, connection, addressed_recipient, message, &error))
316 if (dbus_error_is_set (&error))
318 if (!dbus_connection_get_is_connected (connection))
320 /* If we disconnected it, we won't bother to send it any error
323 _dbus_verbose ("Not sending error to connection we disconnected\n");
325 else if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
327 bus_connection_send_oom_error (connection, message);
329 /* cancel transaction due to OOM */
330 if (transaction != NULL)
332 bus_transaction_cancel_and_free (transaction);
338 /* Try to send the real error, if no mem to do that, send
341 _dbus_assert (transaction != NULL);
343 if (!bus_transaction_send_error_reply (transaction, connection,
346 bus_connection_send_oom_error (connection, message);
348 /* cancel transaction due to OOM */
349 if (transaction != NULL)
351 bus_transaction_cancel_and_free (transaction);
357 dbus_error_free (&error);
360 if (transaction != NULL)
362 bus_transaction_execute_and_free (transaction);
365 dbus_connection_unref (connection);
370 static DBusHandlerResult
371 bus_dispatch_message_filter (DBusConnection *connection,
372 DBusMessage *message,
375 return bus_dispatch (connection, message);
379 bus_dispatch_add_connection (DBusConnection *connection)
381 if (!dbus_connection_add_filter (connection,
382 bus_dispatch_message_filter,
390 bus_dispatch_remove_connection (DBusConnection *connection)
392 /* Here we tell the bus driver that we want to get off. */
393 bus_driver_remove_connection (connection);
395 dbus_connection_remove_filter (connection,
396 bus_dispatch_message_filter,
400 #ifdef DBUS_BUILD_TESTS
404 /* This is used to know whether we need to block in order to finish
405 * sending a message, or whether the initial dbus_connection_send()
406 * already flushed the queue.
408 #define SEND_PENDING(connection) (dbus_connection_has_messages_to_send (connection))
410 typedef dbus_bool_t (* Check1Func) (BusContext *context);
411 typedef dbus_bool_t (* Check2Func) (BusContext *context,
412 DBusConnection *connection);
414 static dbus_bool_t check_no_leftovers (BusContext *context);
417 block_connection_until_message_from_bus (BusContext *context,
418 DBusConnection *connection,
419 const char *what_is_expected)
421 _dbus_verbose ("expecting: %s\n", what_is_expected);
423 while (dbus_connection_get_dispatch_status (connection) ==
424 DBUS_DISPATCH_COMPLETE &&
425 dbus_connection_get_is_connected (connection))
427 bus_test_run_bus_loop (context, TRUE);
428 bus_test_run_clients_loop (FALSE);
433 spin_connection_until_authenticated (BusContext *context,
434 DBusConnection *connection)
436 _dbus_verbose ("Spinning to auth connection %p\n", connection);
437 while (!dbus_connection_get_is_authenticated (connection) &&
438 dbus_connection_get_is_connected (connection))
440 bus_test_run_bus_loop (context, FALSE);
441 bus_test_run_clients_loop (FALSE);
443 _dbus_verbose (" ... done spinning to auth connection %p\n", connection);
446 /* compensate for fact that pop_message() can return #NULL due to OOM */
448 pop_message_waiting_for_memory (DBusConnection *connection)
450 while (dbus_connection_get_dispatch_status (connection) ==
451 DBUS_DISPATCH_NEED_MEMORY)
452 _dbus_wait_for_memory ();
454 return dbus_connection_pop_message (connection);
458 borrow_message_waiting_for_memory (DBusConnection *connection)
460 while (dbus_connection_get_dispatch_status (connection) ==
461 DBUS_DISPATCH_NEED_MEMORY)
462 _dbus_wait_for_memory ();
464 return dbus_connection_borrow_message (connection);
468 warn_unexpected_real (DBusConnection *connection,
469 DBusMessage *message,
470 const char *expected,
471 const char *function,
475 _dbus_warn ("%s:%d received message interface \"%s\" member \"%s\" error name \"%s\" on %p, expecting %s\n",
477 dbus_message_get_interface (message) ?
478 dbus_message_get_interface (message) : "(unset)",
479 dbus_message_get_member (message) ?
480 dbus_message_get_member (message) : "(unset)",
481 dbus_message_get_error_name (message) ?
482 dbus_message_get_error_name (message) : "(unset)",
486 _dbus_warn ("%s:%d received no message on %p, expecting %s\n",
487 function, line, connection, expected);
490 #define warn_unexpected(connection, message, expected) \
491 warn_unexpected_real (connection, message, expected, _DBUS_FUNCTION_NAME, __LINE__)
494 verbose_message_received (DBusConnection *connection,
495 DBusMessage *message)
497 _dbus_verbose ("Received message interface \"%s\" member \"%s\" error name \"%s\" on %p\n",
498 dbus_message_get_interface (message) ?
499 dbus_message_get_interface (message) : "(unset)",
500 dbus_message_get_member (message) ?
501 dbus_message_get_member (message) : "(unset)",
502 dbus_message_get_error_name (message) ?
503 dbus_message_get_error_name (message) : "(unset)",
516 ServiceInfoKind expected_kind;
517 const char *expected_service_name;
519 DBusConnection *skip_connection;
520 } CheckServiceOwnerChangedData;
523 check_service_owner_changed_foreach (DBusConnection *connection,
526 CheckServiceOwnerChangedData *d = data;
527 DBusMessage *message;
529 const char *service_name, *old_owner, *new_owner;
531 if (d->expected_kind == SERVICE_CREATED
532 && connection == d->skip_connection)
535 dbus_error_init (&error);
538 message = pop_message_waiting_for_memory (connection);
541 _dbus_warn ("Did not receive a message on %p, expecting %s\n",
542 connection, "ServiceOwnerChanged");
545 else if (!dbus_message_is_signal (message,
546 DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
547 "ServiceOwnerChanged"))
549 warn_unexpected (connection, message, "ServiceOwnerChanged");
555 reget_service_info_data:
560 dbus_message_get_args (message, &error,
561 DBUS_TYPE_STRING, &service_name,
562 DBUS_TYPE_STRING, &old_owner,
563 DBUS_TYPE_STRING, &new_owner,
566 if (dbus_error_is_set (&error))
568 if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
570 dbus_error_free (&error);
571 _dbus_wait_for_memory ();
572 goto reget_service_info_data;
576 _dbus_warn ("Did not get the expected arguments\n");
581 if ((d->expected_kind == SERVICE_CREATED && ( old_owner[0] || !new_owner[0]))
582 || (d->expected_kind == OWNER_CHANGED && (!old_owner[0] || !new_owner[0]))
583 || (d->expected_kind == SERVICE_DELETED && (!old_owner[0] || new_owner[0])))
585 _dbus_warn ("inconsistent ServiceOwnerChanged arguments");
589 if (strcmp (service_name, d->expected_service_name) != 0)
591 _dbus_warn ("expected info on service %s, got info on %s\n",
592 d->expected_service_name,
597 if (*service_name == ':' && new_owner[0]
598 && strcmp (service_name, new_owner) != 0)
600 _dbus_warn ("inconsistent ServiceOwnedChanged message (\"%s\" [ %s -> %s ])\n",
601 service_name, old_owner, new_owner);
609 dbus_error_free (&error);
612 dbus_message_unref (message);
619 kill_client_connection (BusContext *context,
620 DBusConnection *connection)
624 CheckServiceOwnerChangedData socd;
626 _dbus_verbose ("killing connection %p\n", connection);
628 s = dbus_bus_get_base_service (connection);
629 _dbus_assert (s != NULL);
631 while ((base_service = _dbus_strdup (s)) == NULL)
632 _dbus_wait_for_memory ();
634 dbus_connection_ref (connection);
636 /* kick in the disconnect handler that unrefs the connection */
637 dbus_connection_disconnect (connection);
639 bus_test_run_everything (context);
641 _dbus_assert (bus_test_client_listed (connection));
643 /* Run disconnect handler in test.c */
644 if (bus_connection_dispatch_one_message (connection))
645 _dbus_assert_not_reached ("something received on connection being killed other than the disconnect");
647 _dbus_assert (!dbus_connection_get_is_connected (connection));
648 dbus_connection_unref (connection);
650 _dbus_assert (!bus_test_client_listed (connection));
652 socd.expected_kind = SERVICE_DELETED;
653 socd.expected_service_name = base_service;
655 socd.skip_connection = NULL;
657 bus_test_clients_foreach (check_service_owner_changed_foreach,
660 dbus_free (base_service);
663 _dbus_assert_not_reached ("didn't get the expected ServiceOwnerChanged (deletion) messages");
665 if (!check_no_leftovers (context))
666 _dbus_assert_not_reached ("stuff left in message queues after disconnecting a client");
670 kill_client_connection_unchecked (DBusConnection *connection)
672 /* This kills the connection without expecting it to affect
673 * the rest of the bus.
675 _dbus_verbose ("Unchecked kill of connection %p\n", connection);
677 dbus_connection_ref (connection);
678 dbus_connection_disconnect (connection);
679 /* dispatching disconnect handler will unref once */
680 if (bus_connection_dispatch_one_message (connection))
681 _dbus_assert_not_reached ("message other than disconnect dispatched after failure to register");
683 _dbus_assert (!bus_test_client_listed (connection));
684 dbus_connection_unref (connection);
690 } CheckNoMessagesData;
693 check_no_messages_foreach (DBusConnection *connection,
696 CheckNoMessagesData *d = data;
697 DBusMessage *message;
699 message = pop_message_waiting_for_memory (connection);
702 warn_unexpected (connection, message, "no messages");
708 dbus_message_unref (message);
713 check_no_leftovers (BusContext *context)
715 CheckNoMessagesData nmd;
718 bus_test_clients_foreach (check_no_messages_foreach,
723 _dbus_verbose ("%s: leftover message found\n",
724 _DBUS_FUNCTION_NAME);
731 /* returns TRUE if the correct thing happens,
732 * but the correct thing may include OOM errors.
735 check_hello_message (BusContext *context,
736 DBusConnection *connection)
738 DBusMessage *message;
739 DBusMessage *name_message;
740 dbus_uint32_t serial;
744 const char *acquired;
747 dbus_error_init (&error);
753 _dbus_verbose ("check_hello_message for %p\n", connection);
755 message = dbus_message_new_method_call (DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
756 DBUS_PATH_ORG_FREEDESKTOP_DBUS,
757 DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
763 dbus_connection_ref (connection); /* because we may get disconnected */
765 if (!dbus_connection_send (connection, message, &serial))
767 dbus_message_unref (message);
768 dbus_connection_unref (connection);
772 _dbus_assert (dbus_message_has_signature (message, ""));
774 dbus_message_unref (message);
777 if (!dbus_connection_get_is_connected (connection))
779 _dbus_verbose ("connection was disconnected (presumably auth failed)\n");
781 dbus_connection_unref (connection);
786 /* send our message */
787 bus_test_run_clients_loop (SEND_PENDING (connection));
789 if (!dbus_connection_get_is_connected (connection))
791 _dbus_verbose ("connection was disconnected (presumably auth failed)\n");
793 dbus_connection_unref (connection);
798 block_connection_until_message_from_bus (context, connection, "reply to Hello");
800 if (!dbus_connection_get_is_connected (connection))
802 _dbus_verbose ("connection was disconnected (presumably auth failed)\n");
804 dbus_connection_unref (connection);
809 dbus_connection_unref (connection);
811 message = pop_message_waiting_for_memory (connection);
814 _dbus_warn ("Did not receive a reply to %s %d on %p\n",
815 "Hello", serial, connection);
819 verbose_message_received (connection, message);
821 if (!dbus_message_has_sender (message, DBUS_SERVICE_ORG_FREEDESKTOP_DBUS))
823 _dbus_warn ("Message has wrong sender %s\n",
824 dbus_message_get_sender (message) ?
825 dbus_message_get_sender (message) : "(none)");
829 if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR)
831 if (dbus_message_is_error (message,
832 DBUS_ERROR_NO_MEMORY))
834 ; /* good, this is a valid response */
838 warn_unexpected (connection, message, "not this error");
845 CheckServiceOwnerChangedData socd;
847 if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_METHOD_RETURN)
849 ; /* good, expected */
853 warn_unexpected (connection, message, "method return for Hello");
858 retry_get_hello_name:
859 if (!dbus_message_get_args (message, &error,
860 DBUS_TYPE_STRING, &name,
863 if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
865 _dbus_verbose ("no memory to get service name arg from hello\n");
866 dbus_error_free (&error);
867 _dbus_wait_for_memory ();
868 goto retry_get_hello_name;
872 _dbus_assert (dbus_error_is_set (&error));
873 _dbus_warn ("Did not get the expected single string argument to hello\n");
878 _dbus_verbose ("Got hello name: %s\n", name);
880 while (!dbus_bus_set_base_service (connection, name))
881 _dbus_wait_for_memory ();
883 socd.expected_kind = SERVICE_CREATED;
884 socd.expected_service_name = name;
886 socd.skip_connection = connection; /* we haven't done AddMatch so won't get it ourselves */
887 bus_test_clients_foreach (check_service_owner_changed_foreach,
893 name_message = message;
894 /* Client should also have gotten ServiceAcquired */
896 message = pop_message_waiting_for_memory (connection);
899 _dbus_warn ("Expecting %s, got nothing\n",
903 if (! dbus_message_is_signal (message, DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
906 _dbus_warn ("Expecting %s, got smthg else\n",
911 retry_get_acquired_name:
912 if (!dbus_message_get_args (message, &error,
913 DBUS_TYPE_STRING, &acquired,
916 if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
918 _dbus_verbose ("no memory to get service name arg from acquired\n");
919 dbus_error_free (&error);
920 _dbus_wait_for_memory ();
921 goto retry_get_acquired_name;
925 _dbus_assert (dbus_error_is_set (&error));
926 _dbus_warn ("Did not get the expected single string argument to ServiceAcquired\n");
931 _dbus_verbose ("Got acquired name: %s\n", acquired);
933 if (strcmp (acquired, name) != 0)
935 _dbus_warn ("Acquired name is %s but expected %s\n",
942 if (!check_no_leftovers (context))
948 _dbus_verbose ("ending %s retval = %d\n", _DBUS_FUNCTION_NAME, retval);
950 dbus_error_free (&error);
953 dbus_message_unref (message);
956 dbus_message_unref (name_message);
961 /* returns TRUE if the correct thing happens,
962 * but the correct thing may include OOM errors.
965 check_double_hello_message (BusContext *context,
966 DBusConnection *connection)
968 DBusMessage *message;
969 dbus_uint32_t serial;
974 dbus_error_init (&error);
977 _dbus_verbose ("check_double_hello_message for %p\n", connection);
979 message = dbus_message_new_method_call (DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
980 DBUS_PATH_ORG_FREEDESKTOP_DBUS,
981 DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
987 if (!dbus_connection_send (connection, message, &serial))
989 dbus_message_unref (message);
993 dbus_message_unref (message);
996 /* send our message */
997 bus_test_run_clients_loop (SEND_PENDING (connection));
999 dbus_connection_ref (connection); /* because we may get disconnected */
1000 block_connection_until_message_from_bus (context, connection, "reply to Hello");
1002 if (!dbus_connection_get_is_connected (connection))
1004 _dbus_verbose ("connection was disconnected: %s %d\n", _DBUS_FUNCTION_NAME, __LINE__);
1006 dbus_connection_unref (connection);
1011 dbus_connection_unref (connection);
1013 message = pop_message_waiting_for_memory (connection);
1014 if (message == NULL)
1016 _dbus_warn ("Did not receive a reply to %s %d on %p\n",
1017 "Hello", serial, connection);
1021 verbose_message_received (connection, message);
1023 if (!dbus_message_has_sender (message, DBUS_SERVICE_ORG_FREEDESKTOP_DBUS))
1025 _dbus_warn ("Message has wrong sender %s\n",
1026 dbus_message_get_sender (message) ?
1027 dbus_message_get_sender (message) : "(none)");
1031 if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_ERROR)
1033 warn_unexpected (connection, message, "method return for Hello");
1037 if (!check_no_leftovers (context))
1043 dbus_error_free (&error);
1046 dbus_message_unref (message);
1051 /* returns TRUE if the correct thing happens,
1052 * but the correct thing may include OOM errors.
1055 check_get_connection_unix_user (BusContext *context,
1056 DBusConnection *connection)
1058 DBusMessage *message;
1059 dbus_uint32_t serial;
1062 const char *base_service_name;
1066 dbus_error_init (&error);
1069 _dbus_verbose ("check_get_connection_unix_user for %p\n", connection);
1071 message = dbus_message_new_method_call (DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
1072 DBUS_PATH_ORG_FREEDESKTOP_DBUS,
1073 DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
1074 "GetConnectionUnixUser");
1076 if (message == NULL)
1079 base_service_name = dbus_bus_get_base_service (connection);
1081 if (!dbus_message_append_args (message,
1082 DBUS_TYPE_STRING, &base_service_name,
1085 dbus_message_unref (message);
1089 if (!dbus_connection_send (connection, message, &serial))
1091 dbus_message_unref (message);
1095 /* send our message */
1096 bus_test_run_clients_loop (SEND_PENDING (connection));
1098 dbus_message_unref (message);
1101 dbus_connection_ref (connection); /* because we may get disconnected */
1102 block_connection_until_message_from_bus (context, connection, "reply to GetConnectionUnixUser");
1104 if (!dbus_connection_get_is_connected (connection))
1106 _dbus_verbose ("connection was disconnected: %s %d\n", _DBUS_FUNCTION_NAME, __LINE__);
1108 dbus_connection_unref (connection);
1113 dbus_connection_unref (connection);
1115 message = pop_message_waiting_for_memory (connection);
1116 if (message == NULL)
1118 _dbus_warn ("Did not receive a reply to %s %d on %p\n",
1119 "GetConnectionUnixUser", serial, connection);
1123 verbose_message_received (connection, message);
1125 if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR)
1127 if (dbus_message_is_error (message, DBUS_ERROR_NO_MEMORY))
1129 ; /* good, this is a valid response */
1133 warn_unexpected (connection, message, "not this error");
1140 if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_METHOD_RETURN)
1142 ; /* good, expected */
1146 warn_unexpected (connection, message,
1147 "method_return for GetConnectionUnixUser");
1154 if (!dbus_message_get_args (message, &error,
1155 DBUS_TYPE_UINT32, &uid,
1158 if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
1160 _dbus_verbose ("no memory to get uid by GetConnectionUnixUser\n");
1161 dbus_error_free (&error);
1162 _dbus_wait_for_memory ();
1163 goto retry_get_property;
1167 _dbus_assert (dbus_error_is_set (&error));
1168 _dbus_warn ("Did not get the expected DBUS_TYPE_UINT32 from GetConnectionUnixUser\n");
1174 if (!check_no_leftovers (context))
1180 dbus_error_free (&error);
1183 dbus_message_unref (message);
1188 /* returns TRUE if the correct thing happens,
1189 * but the correct thing may include OOM errors.
1192 check_get_connection_unix_process_id (BusContext *context,
1193 DBusConnection *connection)
1195 DBusMessage *message;
1196 dbus_uint32_t serial;
1199 const char *base_service_name;
1203 dbus_error_init (&error);
1206 _dbus_verbose ("check_get_connection_unix_process_id for %p\n", connection);
1208 message = dbus_message_new_method_call (DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
1209 DBUS_PATH_ORG_FREEDESKTOP_DBUS,
1210 DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
1211 "GetConnectionUnixProcessID");
1213 if (message == NULL)
1216 base_service_name = dbus_bus_get_base_service (connection);
1218 if (!dbus_message_append_args (message,
1219 DBUS_TYPE_STRING, &base_service_name,
1222 dbus_message_unref (message);
1226 if (!dbus_connection_send (connection, message, &serial))
1228 dbus_message_unref (message);
1232 /* send our message */
1233 bus_test_run_clients_loop (SEND_PENDING (connection));
1235 dbus_message_unref (message);
1238 dbus_connection_ref (connection); /* because we may get disconnected */
1239 block_connection_until_message_from_bus (context, connection, "reply to GetConnectionUnixProcessID");
1241 if (!dbus_connection_get_is_connected (connection))
1243 _dbus_verbose ("connection was disconnected: %s %d\n", _DBUS_FUNCTION_NAME, __LINE__);
1245 dbus_connection_unref (connection);
1250 dbus_connection_unref (connection);
1252 message = pop_message_waiting_for_memory (connection);
1253 if (message == NULL)
1255 _dbus_warn ("Did not receive a reply to %s %d on %p\n",
1256 "GetConnectionUnixProcessID", serial, connection);
1260 verbose_message_received (connection, message);
1262 if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR)
1264 if (dbus_message_is_error (message, DBUS_ERROR_NO_MEMORY))
1266 ; /* good, this is a valid response */
1270 warn_unexpected (connection, message, "not this error");
1277 if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_METHOD_RETURN)
1279 ; /* good, expected */
1283 warn_unexpected (connection, message,
1284 "method_return for GetConnectionUnixProcessID");
1291 if (!dbus_message_get_args (message, &error,
1292 DBUS_TYPE_UINT32, &pid,
1295 if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
1297 _dbus_verbose ("no memory to get pid by GetConnectionUnixProcessID\n");
1298 dbus_error_free (&error);
1299 _dbus_wait_for_memory ();
1300 goto retry_get_property;
1304 _dbus_assert (dbus_error_is_set (&error));
1305 _dbus_warn ("Did not get the expected DBUS_TYPE_UINT32 from GetConnectionUnixProcessID\n");
1310 /* test if returned pid is the same as our own pid
1312 * @todo It would probably be good to restructure the tests
1313 * in a way so our parent is the bus that we're testing
1314 * cause then we can test that the pid returned matches
1317 if (pid != (dbus_uint32_t) _dbus_getpid ())
1319 _dbus_assert (dbus_error_is_set (&error));
1320 _dbus_warn ("Result from GetConnectionUnixProcessID is not our own pid\n");
1326 if (!check_no_leftovers (context))
1332 dbus_error_free (&error);
1335 dbus_message_unref (message);
1340 /* returns TRUE if the correct thing happens,
1341 * but the correct thing may include OOM errors.
1344 check_add_match_all (BusContext *context,
1345 DBusConnection *connection)
1347 DBusMessage *message;
1349 dbus_uint32_t serial;
1351 const char *empty = "";
1354 dbus_error_init (&error);
1357 _dbus_verbose ("check_add_match_all for %p\n", connection);
1359 message = dbus_message_new_method_call (DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
1360 DBUS_PATH_ORG_FREEDESKTOP_DBUS,
1361 DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
1364 if (message == NULL)
1367 /* empty string match rule matches everything */
1368 if (!dbus_message_append_args (message, DBUS_TYPE_STRING, &empty,
1371 dbus_message_unref (message);
1375 if (!dbus_connection_send (connection, message, &serial))
1377 dbus_message_unref (message);
1381 dbus_message_unref (message);
1384 dbus_connection_ref (connection); /* because we may get disconnected */
1386 /* send our message */
1387 bus_test_run_clients_loop (SEND_PENDING (connection));
1389 if (!dbus_connection_get_is_connected (connection))
1391 _dbus_verbose ("connection was disconnected: %s %d\n", _DBUS_FUNCTION_NAME, __LINE__);
1393 dbus_connection_unref (connection);
1398 block_connection_until_message_from_bus (context, connection, "reply to AddMatch");
1400 if (!dbus_connection_get_is_connected (connection))
1402 _dbus_verbose ("connection was disconnected: %s %d\n", _DBUS_FUNCTION_NAME, __LINE__);
1404 dbus_connection_unref (connection);
1409 dbus_connection_unref (connection);
1411 message = pop_message_waiting_for_memory (connection);
1412 if (message == NULL)
1414 _dbus_warn ("Did not receive a reply to %s %d on %p\n",
1415 "AddMatch", serial, connection);
1419 verbose_message_received (connection, message);
1421 if (!dbus_message_has_sender (message, DBUS_SERVICE_ORG_FREEDESKTOP_DBUS))
1423 _dbus_warn ("Message has wrong sender %s\n",
1424 dbus_message_get_sender (message) ?
1425 dbus_message_get_sender (message) : "(none)");
1429 if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR)
1431 if (dbus_message_is_error (message,
1432 DBUS_ERROR_NO_MEMORY))
1434 ; /* good, this is a valid response */
1438 warn_unexpected (connection, message, "not this error");
1445 if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_METHOD_RETURN)
1447 ; /* good, expected */
1448 _dbus_assert (dbus_message_get_reply_serial (message) == serial);
1452 warn_unexpected (connection, message, "method return for AddMatch");
1458 if (!check_no_leftovers (context))
1464 dbus_error_free (&error);
1467 dbus_message_unref (message);
1472 /* returns TRUE if the correct thing happens,
1473 * but the correct thing may include OOM errors.
1476 check_hello_connection (BusContext *context)
1478 DBusConnection *connection;
1481 dbus_error_init (&error);
1483 connection = dbus_connection_open ("debug-pipe:name=test-server", &error);
1484 if (connection == NULL)
1486 _DBUS_ASSERT_ERROR_IS_SET (&error);
1487 dbus_error_free (&error);
1491 if (!bus_setup_debug_client (connection))
1493 dbus_connection_disconnect (connection);
1494 dbus_connection_unref (connection);
1498 spin_connection_until_authenticated (context, connection);
1500 if (!check_hello_message (context, connection))
1503 if (dbus_bus_get_base_service (connection) == NULL)
1505 /* We didn't successfully register, so we can't
1506 * do the usual kill_client_connection() checks
1508 kill_client_connection_unchecked (connection);
1512 if (!check_add_match_all (context, connection))
1515 kill_client_connection (context, connection);
1521 #define NONEXISTENT_SERVICE_NAME "test.this.service.does.not.exist.ewuoiurjdfxcvn"
1523 /* returns TRUE if the correct thing happens,
1524 * but the correct thing may include OOM errors.
1527 check_nonexistent_service_activation (BusContext *context,
1528 DBusConnection *connection)
1530 DBusMessage *message;
1531 dbus_uint32_t serial;
1533 const char *nonexistent = NONEXISTENT_SERVICE_NAME;
1534 dbus_uint32_t flags;
1536 message = dbus_message_new_method_call (DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
1537 DBUS_PATH_ORG_FREEDESKTOP_DBUS,
1538 DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
1541 if (message == NULL)
1545 if (!dbus_message_append_args (message,
1546 DBUS_TYPE_STRING, &nonexistent,
1547 DBUS_TYPE_UINT32, &flags,
1550 dbus_message_unref (message);
1554 if (!dbus_connection_send (connection, message, &serial))
1556 dbus_message_unref (message);
1560 dbus_message_unref (message);
1563 bus_test_run_everything (context);
1564 block_connection_until_message_from_bus (context, connection, "reply to ActivateService on nonexistent");
1565 bus_test_run_everything (context);
1567 if (!dbus_connection_get_is_connected (connection))
1569 _dbus_verbose ("connection was disconnected: %s %d\n", _DBUS_FUNCTION_NAME, __LINE__);
1575 message = pop_message_waiting_for_memory (connection);
1576 if (message == NULL)
1578 _dbus_warn ("Did not receive a reply to %s %d on %p\n",
1579 "ActivateService", serial, connection);
1583 verbose_message_received (connection, message);
1585 if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR)
1587 if (!dbus_message_has_sender (message, DBUS_SERVICE_ORG_FREEDESKTOP_DBUS))
1589 _dbus_warn ("Message has wrong sender %s\n",
1590 dbus_message_get_sender (message) ?
1591 dbus_message_get_sender (message) : "(none)");
1595 if (dbus_message_is_error (message,
1596 DBUS_ERROR_NO_MEMORY))
1598 ; /* good, this is a valid response */
1600 else if (dbus_message_is_error (message,
1601 DBUS_ERROR_ACTIVATE_SERVICE_NOT_FOUND))
1603 ; /* good, this is expected also */
1607 warn_unexpected (connection, message, "not this error");
1613 _dbus_warn ("Did not expect to successfully activate %s\n",
1614 NONEXISTENT_SERVICE_NAME);
1622 dbus_message_unref (message);
1627 /* returns TRUE if the correct thing happens,
1628 * but the correct thing may include OOM errors.
1631 check_nonexistent_service_auto_activation (BusContext *context,
1632 DBusConnection *connection)
1634 DBusMessage *message;
1635 dbus_uint32_t serial;
1638 message = dbus_message_new_method_call (NONEXISTENT_SERVICE_NAME,
1639 "/org/freedesktop/TestSuite",
1640 "org.freedesktop.TestSuite",
1643 if (message == NULL)
1646 dbus_message_set_auto_activation (message, TRUE);
1648 if (!dbus_connection_send (connection, message, &serial))
1650 dbus_message_unref (message);
1654 dbus_message_unref (message);
1657 bus_test_run_everything (context);
1658 block_connection_until_message_from_bus (context, connection, "reply to Echo");
1659 bus_test_run_everything (context);
1661 if (!dbus_connection_get_is_connected (connection))
1663 _dbus_verbose ("connection was disconnected: %s %d\n", _DBUS_FUNCTION_NAME, __LINE__);
1669 message = pop_message_waiting_for_memory (connection);
1671 if (message == NULL)
1673 _dbus_warn ("Did not receive a reply to %s %d on %p\n",
1674 "Echo message (auto activation)", serial, connection);
1678 verbose_message_received (connection, message);
1680 if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR)
1682 if (!dbus_message_has_sender (message, DBUS_SERVICE_ORG_FREEDESKTOP_DBUS))
1684 _dbus_warn ("Message has wrong sender %s\n",
1685 dbus_message_get_sender (message) ?
1686 dbus_message_get_sender (message) : "(none)");
1690 if (dbus_message_is_error (message,
1691 DBUS_ERROR_NO_MEMORY))
1693 ; /* good, this is a valid response */
1695 else if (dbus_message_is_error (message,
1696 DBUS_ERROR_ACTIVATE_SERVICE_NOT_FOUND))
1698 ; /* good, this is expected also */
1702 warn_unexpected (connection, message, "not this error");
1708 _dbus_warn ("Did not expect to successfully activate %s\n",
1709 NONEXISTENT_SERVICE_NAME);
1717 dbus_message_unref (message);
1723 check_base_service_activated (BusContext *context,
1724 DBusConnection *connection,
1725 DBusMessage *initial_message,
1726 const char **base_service_p)
1728 DBusMessage *message;
1731 const char *base_service, *base_service_from_bus, *old_owner;
1735 dbus_error_init (&error);
1736 base_service = NULL;
1738 base_service_from_bus = NULL;
1740 message = initial_message;
1741 dbus_message_ref (message);
1743 if (dbus_message_is_signal (message,
1744 DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
1745 "ServiceOwnerChanged"))
1747 CheckServiceOwnerChangedData socd;
1749 reget_service_name_arg:
1750 base_service = NULL;
1752 base_service_from_bus = NULL;
1754 if (!dbus_message_get_args (message, &error,
1755 DBUS_TYPE_STRING, &base_service,
1756 DBUS_TYPE_STRING, &old_owner,
1757 DBUS_TYPE_STRING, &base_service_from_bus,
1760 if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
1762 dbus_error_free (&error);
1763 _dbus_wait_for_memory ();
1764 goto reget_service_name_arg;
1768 _dbus_warn ("Message %s doesn't have a service name: %s\n",
1769 "ServiceOwnerChanged (creation)",
1775 if (*base_service != ':')
1777 _dbus_warn ("Expected base service activation, got \"%s\" instead\n",
1782 if (strcmp (base_service, base_service_from_bus) != 0)
1784 _dbus_warn ("Expected base service activation, got \"%s\" instead with owner \"%s\"\n",
1785 base_service, base_service_from_bus);
1791 _dbus_warn ("Received an old_owner argument during base service activation, \"%s\"\n",
1796 socd.expected_kind = SERVICE_CREATED;
1797 socd.expected_service_name = base_service;
1798 socd.failed = FALSE;
1799 socd.skip_connection = connection;
1800 bus_test_clients_foreach (check_service_owner_changed_foreach,
1808 warn_unexpected (connection, message, "ServiceOwnerChanged (creation) for base service");
1814 *base_service_p = base_service;
1820 dbus_message_unref (message);
1821 dbus_error_free (&error);
1827 check_service_activated (BusContext *context,
1828 DBusConnection *connection,
1829 const char *activated_name,
1830 const char *base_service_name,
1831 DBusMessage *initial_message)
1833 DBusMessage *message;
1836 dbus_uint32_t activation_result;
1840 dbus_error_init (&error);
1842 message = initial_message;
1843 dbus_message_ref (message);
1845 if (dbus_message_is_signal (message,
1846 DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
1847 "ServiceOwnerChanged"))
1849 CheckServiceOwnerChangedData socd;
1850 const char *service_name, *base_service_from_bus, *old_owner;
1852 reget_service_name_arg:
1853 service_name = NULL;
1855 base_service_from_bus = NULL;
1857 if (!dbus_message_get_args (message, &error,
1858 DBUS_TYPE_STRING, &service_name,
1859 DBUS_TYPE_STRING, &old_owner,
1860 DBUS_TYPE_STRING, &base_service_from_bus,
1863 if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
1865 dbus_error_free (&error);
1866 _dbus_wait_for_memory ();
1867 goto reget_service_name_arg;
1871 _dbus_warn ("Message %s doesn't have a service name: %s\n",
1872 "ServiceOwnerChanged (creation)",
1878 if (strcmp (service_name, activated_name) != 0)
1880 _dbus_warn ("Expected to see service %s created, saw %s instead\n",
1881 activated_name, service_name);
1885 if (strcmp (base_service_name, base_service_from_bus) != 0)
1887 _dbus_warn ("ServiceOwnerChanged reports wrong base service: %s owner, expected %s instead\n",
1888 base_service_from_bus, base_service_name);
1894 _dbus_warn ("expected a %s, got a %s\n",
1895 "ServiceOwnerChanged (creation)",
1896 "ServiceOwnerChanged (change)");
1900 socd.expected_kind = SERVICE_CREATED;
1901 socd.skip_connection = connection;
1902 socd.failed = FALSE;
1903 socd.expected_service_name = service_name;
1904 bus_test_clients_foreach (check_service_owner_changed_foreach,
1910 dbus_message_unref (message);
1911 service_name = NULL;
1913 base_service_from_bus = NULL;
1915 message = pop_message_waiting_for_memory (connection);
1916 if (message == NULL)
1918 _dbus_warn ("Expected a reply to %s, got nothing\n",
1925 warn_unexpected (connection, message, "ServiceOwnerChanged for the activated name");
1930 if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_METHOD_RETURN)
1932 warn_unexpected (connection, message, "reply to ActivateService");
1937 activation_result = 0;
1938 if (!dbus_message_get_args (message, &error,
1939 DBUS_TYPE_UINT32, &activation_result,
1942 if (!dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
1944 _dbus_warn ("Did not have activation result first argument to %s: %s\n",
1945 "ActivateService", error.message);
1949 dbus_error_free (&error);
1953 if (activation_result == DBUS_ACTIVATION_REPLY_ACTIVATED)
1955 else if (activation_result == DBUS_ACTIVATION_REPLY_ALREADY_ACTIVE)
1959 _dbus_warn ("Activation result was 0x%x, no good.\n",
1965 dbus_message_unref (message);
1968 if (!check_no_leftovers (context))
1970 _dbus_warn ("Messages were left over after verifying existent activation results\n");
1978 dbus_message_unref (message);
1979 dbus_error_free (&error);
1985 check_service_auto_activated (BusContext *context,
1986 DBusConnection *connection,
1987 const char *activated_name,
1988 const char *base_service_name,
1989 DBusMessage *initial_message)
1991 DBusMessage *message;
1997 dbus_error_init (&error);
1999 message = initial_message;
2000 dbus_message_ref (message);
2002 if (dbus_message_is_signal (message,
2003 DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
2004 "ServiceOwnerChanged"))
2006 const char *service_name;
2007 CheckServiceOwnerChangedData socd;
2009 reget_service_name_arg:
2010 if (!dbus_message_get_args (message, &error,
2011 DBUS_TYPE_STRING, &service_name,
2014 if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
2016 dbus_error_free (&error);
2017 _dbus_wait_for_memory ();
2018 goto reget_service_name_arg;
2022 _dbus_warn ("Message %s doesn't have a service name: %s\n",
2023 "ServiceOwnerChanged",
2025 dbus_error_free (&error);
2030 if (strcmp (service_name, activated_name) != 0)
2032 _dbus_warn ("Expected to see service %s created, saw %s instead\n",
2033 activated_name, service_name);
2037 socd.expected_kind = SERVICE_CREATED;
2038 socd.expected_service_name = service_name;
2039 socd.failed = FALSE;
2040 socd.skip_connection = connection;
2041 bus_test_clients_foreach (check_service_owner_changed_foreach,
2047 /* Note that this differs from regular activation in that we don't get a
2048 * reply to ActivateService here.
2051 dbus_message_unref (message);
2053 service_name = NULL;
2057 warn_unexpected (connection, message, "ServiceOwnerChanged for the activated name");
2066 dbus_message_unref (message);
2072 check_service_deactivated (BusContext *context,
2073 DBusConnection *connection,
2074 const char *activated_name,
2075 const char *base_service)
2078 CheckServiceOwnerChangedData socd;
2082 /* Now we are expecting ServiceOwnerChanged (deletion) messages for the base
2083 * service and the activated_name. The base service
2084 * notification is required to come last.
2086 socd.expected_kind = SERVICE_DELETED;
2087 socd.expected_service_name = activated_name;
2088 socd.failed = FALSE;
2089 socd.skip_connection = NULL;
2090 bus_test_clients_foreach (check_service_owner_changed_foreach,
2096 socd.expected_kind = SERVICE_DELETED;
2097 socd.expected_service_name = base_service;
2098 socd.failed = FALSE;
2099 socd.skip_connection = NULL;
2100 bus_test_clients_foreach (check_service_owner_changed_foreach,
2113 check_send_exit_to_service (BusContext *context,
2114 DBusConnection *connection,
2115 const char *service_name,
2116 const char *base_service)
2118 dbus_bool_t got_error;
2119 DBusMessage *message;
2120 dbus_uint32_t serial;
2123 _dbus_verbose ("Sending exit message to the test service\n");
2127 /* Kill off the test service by sending it a quit message */
2128 message = dbus_message_new_method_call (service_name,
2129 "/org/freedesktop/TestSuite",
2130 "org.freedesktop.TestSuite",
2133 if (message == NULL)
2135 /* Do this again; we still need the service to exit... */
2136 if (!check_send_exit_to_service (context, connection,
2137 service_name, base_service))
2143 if (!dbus_connection_send (connection, message, &serial))
2145 dbus_message_unref (message);
2147 /* Do this again; we still need the service to exit... */
2148 if (!check_send_exit_to_service (context, connection,
2149 service_name, base_service))
2155 dbus_message_unref (message);
2159 bus_test_run_clients_loop (SEND_PENDING (connection));
2161 /* read it in and write it out to test service */
2162 bus_test_run_bus_loop (context, FALSE);
2164 /* see if we got an error during message bus dispatching */
2165 bus_test_run_clients_loop (FALSE);
2166 message = borrow_message_waiting_for_memory (connection);
2167 got_error = message != NULL && dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR;
2170 dbus_connection_return_message (connection, message);
2176 /* If no error, wait for the test service to exit */
2177 block_connection_until_message_from_bus (context, connection, "test service to exit");
2179 bus_test_run_everything (context);
2184 message = pop_message_waiting_for_memory (connection);
2185 _dbus_assert (message != NULL);
2187 if (dbus_message_get_reply_serial (message) != serial)
2189 warn_unexpected (connection, message,
2190 "error with the correct reply serial");
2194 if (!dbus_message_is_error (message,
2195 DBUS_ERROR_NO_MEMORY))
2197 warn_unexpected (connection, message,
2198 "a no memory error from asking test service to exit");
2202 _dbus_verbose ("Got error %s when asking test service to exit\n",
2203 dbus_message_get_error_name (message));
2205 /* Do this again; we still need the service to exit... */
2206 if (!check_send_exit_to_service (context, connection,
2207 service_name, base_service))
2212 if (!check_service_deactivated (context, connection,
2213 service_name, base_service))
2216 /* Should now have a NoReply error from the Exit() method
2217 * call; it should have come after all the deactivation
2220 message = pop_message_waiting_for_memory (connection);
2222 if (message == NULL)
2224 warn_unexpected (connection, NULL,
2225 "reply to Exit() method call");
2228 if (!dbus_message_is_error (message,
2229 DBUS_ERROR_NO_REPLY))
2231 warn_unexpected (connection, message,
2232 "NoReply error from Exit() method call");
2236 if (dbus_message_get_reply_serial (message) != serial)
2238 warn_unexpected (connection, message,
2239 "error with the correct reply serial");
2243 _dbus_verbose ("Got error %s after test service exited\n",
2244 dbus_message_get_error_name (message));
2246 if (!check_no_leftovers (context))
2248 _dbus_warn ("Messages were left over after %s\n",
2249 _DBUS_FUNCTION_NAME);
2258 dbus_message_unref (message);
2264 check_got_error (BusContext *context,
2265 DBusConnection *connection,
2266 const char *first_error_name,
2269 DBusMessage *message;
2272 dbus_bool_t error_found;
2273 const char *error_name;
2277 message = pop_message_waiting_for_memory (connection);
2278 if (message == NULL)
2280 _dbus_warn ("Did not get an expected error\n");
2284 if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_ERROR)
2286 warn_unexpected (connection, message, "an error");
2291 error_found = FALSE;
2293 va_start (ap, first_error_name);
2294 error_name = first_error_name;
2295 while (error_name != NULL)
2297 if (dbus_message_is_error (message, error_name))
2302 error_name = va_arg (ap, char*);
2308 _dbus_warn ("Expected error %s or other, got %s instead\n",
2310 dbus_message_get_error_name (message));
2318 dbus_message_unref (message);
2325 GOT_SERVICE_CREATED,
2326 GOT_SERVICE_DELETED,
2331 static GotServiceInfo
2332 check_got_service_info (DBusMessage *message)
2334 GotServiceInfo message_kind;
2336 if (dbus_message_is_signal (message,
2337 DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
2338 "ServiceOwnerChanged"))
2341 const char *service_name, *old_owner, *new_owner;
2342 dbus_error_init (&error);
2344 reget_service_info_data:
2345 service_name = NULL;
2349 dbus_message_get_args (message, &error,
2350 DBUS_TYPE_STRING, &service_name,
2351 DBUS_TYPE_STRING, &old_owner,
2352 DBUS_TYPE_STRING, &new_owner,
2354 if (dbus_error_is_set (&error))
2356 if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
2358 dbus_error_free (&error);
2359 goto reget_service_info_data;
2363 _dbus_warn ("unexpected arguments for ServiceOwnerChanged message");
2364 message_kind = GOT_SOMETHING_ELSE;
2367 else if (!old_owner[0])
2368 message_kind = GOT_SERVICE_CREATED;
2369 else if (!new_owner[0])
2370 message_kind = GOT_SERVICE_DELETED;
2372 message_kind = GOT_SOMETHING_ELSE;
2374 dbus_error_free (&error);
2376 else if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR)
2377 message_kind = GOT_ERROR;
2379 message_kind = GOT_SOMETHING_ELSE;
2381 return message_kind;
2384 #define EXISTENT_SERVICE_NAME "org.freedesktop.DBus.TestSuiteEchoService"
2386 /* returns TRUE if the correct thing happens,
2387 * but the correct thing may include OOM errors.
2390 check_existent_service_activation (BusContext *context,
2391 DBusConnection *connection)
2393 DBusMessage *message;
2394 DBusMessage *base_service_message;
2395 const char *base_service;
2396 dbus_uint32_t serial;
2398 const char *existent = EXISTENT_SERVICE_NAME;
2399 dbus_uint32_t flags;
2401 base_service_message = NULL;
2403 message = dbus_message_new_method_call (DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
2404 DBUS_PATH_ORG_FREEDESKTOP_DBUS,
2405 DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
2408 if (message == NULL)
2412 if (!dbus_message_append_args (message,
2413 DBUS_TYPE_STRING, &existent,
2414 DBUS_TYPE_UINT32, &flags,
2417 dbus_message_unref (message);
2421 if (!dbus_connection_send (connection, message, &serial))
2423 dbus_message_unref (message);
2427 dbus_message_unref (message);
2430 bus_test_run_everything (context);
2432 /* now wait for the message bus to hear back from the activated
2435 block_connection_until_message_from_bus (context, connection, "activated service to connect");
2437 bus_test_run_everything (context);
2439 if (!dbus_connection_get_is_connected (connection))
2441 _dbus_verbose ("connection was disconnected: %s %d\n", _DBUS_FUNCTION_NAME, __LINE__);
2447 message = pop_message_waiting_for_memory (connection);
2448 if (message == NULL)
2450 _dbus_warn ("Did not receive any messages after %s %d on %p\n",
2451 "ActivateService", serial, connection);
2455 verbose_message_received (connection, message);
2456 _dbus_verbose (" (after sending %s)\n", "ActivateService");
2458 if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR)
2460 if (!dbus_message_has_sender (message, DBUS_SERVICE_ORG_FREEDESKTOP_DBUS))
2462 _dbus_warn ("Message has wrong sender %s\n",
2463 dbus_message_get_sender (message) ?
2464 dbus_message_get_sender (message) : "(none)");
2468 if (dbus_message_is_error (message,
2469 DBUS_ERROR_NO_MEMORY))
2471 ; /* good, this is a valid response */
2473 else if (dbus_message_is_error (message,
2474 DBUS_ERROR_SPAWN_CHILD_EXITED) ||
2475 dbus_message_is_error (message,
2476 DBUS_ERROR_SPAWN_EXEC_FAILED))
2478 ; /* good, this is expected also */
2482 _dbus_warn ("Did not expect error %s\n",
2483 dbus_message_get_error_name (message));
2489 GotServiceInfo message_kind;
2491 if (!check_base_service_activated (context, connection,
2492 message, &base_service))
2495 base_service_message = message;
2498 /* We may need to block here for the test service to exit or finish up */
2499 block_connection_until_message_from_bus (context, connection, "test service to exit or finish up");
2501 message = dbus_connection_borrow_message (connection);
2502 if (message == NULL)
2504 _dbus_warn ("Did not receive any messages after base service creation notification\n");
2508 message_kind = check_got_service_info (message);
2510 dbus_connection_return_message (connection, message);
2513 switch (message_kind)
2515 case GOT_SOMETHING_ELSE:
2516 _dbus_warn ("Unexpected message after ActivateService "
2517 "(should be an error or a service announcement");
2521 if (!check_got_error (context, connection,
2522 DBUS_ERROR_SPAWN_CHILD_EXITED,
2523 DBUS_ERROR_NO_MEMORY,
2526 /* A service deleted should be coming along now after this error.
2527 * We can also get the error *after* the service deleted.
2532 case GOT_SERVICE_DELETED:
2534 /* The service started up and got a base address, but then
2535 * failed to register under EXISTENT_SERVICE_NAME
2537 CheckServiceOwnerChangedData socd;
2539 socd.expected_kind = SERVICE_DELETED;
2540 socd.expected_service_name = base_service;
2541 socd.failed = FALSE;
2542 socd.skip_connection = NULL;
2544 bus_test_clients_foreach (check_service_owner_changed_foreach,
2550 /* Now we should get an error about the service exiting
2551 * if we didn't get it before.
2553 if (message_kind != GOT_ERROR)
2555 block_connection_until_message_from_bus (context, connection, "error about service exiting");
2557 /* and process everything again */
2558 bus_test_run_everything (context);
2560 if (!check_got_error (context, connection,
2561 DBUS_ERROR_SPAWN_CHILD_EXITED,
2568 case GOT_SERVICE_CREATED:
2569 message = pop_message_waiting_for_memory (connection);
2570 if (message == NULL)
2572 _dbus_warn ("Failed to pop message we just put back! "
2573 "should have been a ServiceOwnerChanged (creation)\n");
2577 if (!check_service_activated (context, connection, EXISTENT_SERVICE_NAME,
2578 base_service, message))
2581 dbus_message_unref (message);
2584 if (!check_no_leftovers (context))
2586 _dbus_warn ("Messages were left over after successful activation\n");
2590 if (!check_send_exit_to_service (context, connection,
2591 EXISTENT_SERVICE_NAME, base_service))
2602 dbus_message_unref (message);
2604 if (base_service_message)
2605 dbus_message_unref (base_service_message);
2610 /* returns TRUE if the correct thing happens,
2611 * but the correct thing may include OOM errors.
2614 check_segfault_service_activation (BusContext *context,
2615 DBusConnection *connection)
2617 DBusMessage *message;
2618 dbus_uint32_t serial;
2620 const char *segv_service;
2621 dbus_uint32_t flags;
2623 message = dbus_message_new_method_call (DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
2624 DBUS_PATH_ORG_FREEDESKTOP_DBUS,
2625 DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
2628 if (message == NULL)
2631 segv_service = "org.freedesktop.DBus.TestSuiteSegfaultService";
2633 if (!dbus_message_append_args (message,
2634 DBUS_TYPE_STRING, &segv_service,
2635 DBUS_TYPE_UINT32, &flags,
2638 dbus_message_unref (message);
2642 if (!dbus_connection_send (connection, message, &serial))
2644 dbus_message_unref (message);
2648 dbus_message_unref (message);
2651 bus_test_run_everything (context);
2652 block_connection_until_message_from_bus (context, connection, "reply to activating segfault service");
2653 bus_test_run_everything (context);
2655 if (!dbus_connection_get_is_connected (connection))
2657 _dbus_verbose ("connection was disconnected: %s %d\n", _DBUS_FUNCTION_NAME, __LINE__);
2663 message = pop_message_waiting_for_memory (connection);
2664 if (message == NULL)
2666 _dbus_warn ("Did not receive a reply to %s %d on %p\n",
2667 "ActivateService", serial, connection);
2671 verbose_message_received (connection, message);
2673 if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR)
2675 if (!dbus_message_has_sender (message, DBUS_SERVICE_ORG_FREEDESKTOP_DBUS))
2677 _dbus_warn ("Message has wrong sender %s\n",
2678 dbus_message_get_sender (message) ?
2679 dbus_message_get_sender (message) : "(none)");
2683 if (dbus_message_is_error (message,
2684 DBUS_ERROR_NO_MEMORY))
2686 ; /* good, this is a valid response */
2688 else if (dbus_message_is_error (message,
2689 DBUS_ERROR_SPAWN_CHILD_SIGNALED))
2691 ; /* good, this is expected also */
2695 warn_unexpected (connection, message, "not this error");
2702 _dbus_warn ("Did not expect to successfully activate segfault service\n");
2710 dbus_message_unref (message);
2716 /* returns TRUE if the correct thing happens,
2717 * but the correct thing may include OOM errors.
2720 check_segfault_service_auto_activation (BusContext *context,
2721 DBusConnection *connection)
2723 DBusMessage *message;
2724 dbus_uint32_t serial;
2727 message = dbus_message_new_method_call ("org.freedesktop.DBus.TestSuiteSegfaultService",
2728 "/org/freedesktop/TestSuite",
2729 "org.freedesktop.TestSuite",
2732 if (message == NULL)
2735 dbus_message_set_auto_activation (message, TRUE);
2737 if (!dbus_connection_send (connection, message, &serial))
2739 dbus_message_unref (message);
2743 dbus_message_unref (message);
2746 bus_test_run_everything (context);
2747 block_connection_until_message_from_bus (context, connection, "reply to Echo on segfault service");
2748 bus_test_run_everything (context);
2750 if (!dbus_connection_get_is_connected (connection))
2752 _dbus_verbose ("connection was disconnected: %s %d\n", _DBUS_FUNCTION_NAME, __LINE__);
2758 message = pop_message_waiting_for_memory (connection);
2759 if (message == NULL)
2761 _dbus_warn ("Did not receive a reply to %s %d on %p\n",
2762 "Echo message (auto activation)", serial, connection);
2766 verbose_message_received (connection, message);
2768 if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR)
2770 if (!dbus_message_has_sender (message, DBUS_SERVICE_ORG_FREEDESKTOP_DBUS))
2772 _dbus_warn ("Message has wrong sender %s\n",
2773 dbus_message_get_sender (message) ?
2774 dbus_message_get_sender (message) : "(none)");
2778 if (dbus_message_is_error (message,
2779 DBUS_ERROR_NO_MEMORY))
2781 ; /* good, this is a valid response */
2783 else if (dbus_message_is_error (message,
2784 DBUS_ERROR_SPAWN_CHILD_SIGNALED))
2786 ; /* good, this is expected also */
2790 warn_unexpected (connection, message, "not this error");
2797 _dbus_warn ("Did not expect to successfully activate segfault service\n");
2805 dbus_message_unref (message);
2810 #define TEST_ECHO_MESSAGE "Test echo message"
2812 /* returns TRUE if the correct thing happens,
2813 * but the correct thing may include OOM errors.
2816 check_existent_service_auto_activation (BusContext *context,
2817 DBusConnection *connection)
2819 DBusMessage *message;
2820 DBusMessage *base_service_message;
2821 dbus_uint32_t serial;
2823 const char *base_service;
2826 base_service_message = NULL;
2828 message = dbus_message_new_method_call (EXISTENT_SERVICE_NAME,
2829 "/org/freedesktop/TestSuite",
2830 "org.freedesktop.TestSuite",
2833 if (message == NULL)
2836 dbus_message_set_auto_activation (message, TRUE);
2838 text = TEST_ECHO_MESSAGE;
2839 if (!dbus_message_append_args (message,
2840 DBUS_TYPE_STRING, &text,
2843 dbus_message_unref (message);
2847 if (!dbus_connection_send (connection, message, &serial))
2849 dbus_message_unref (message);
2853 dbus_message_unref (message);
2856 bus_test_run_everything (context);
2858 /* now wait for the message bus to hear back from the activated
2861 block_connection_until_message_from_bus (context, connection, "reply to Echo on existent service");
2862 bus_test_run_everything (context);
2864 if (!dbus_connection_get_is_connected (connection))
2866 _dbus_verbose ("connection was disconnected: %s %d\n", _DBUS_FUNCTION_NAME, __LINE__);
2872 message = pop_message_waiting_for_memory (connection);
2873 if (message == NULL)
2875 _dbus_warn ("Did not receive any messages after auto activation %d on %p\n",
2876 serial, connection);
2880 verbose_message_received (connection, message);
2881 _dbus_verbose (" (after sending %s)\n", "auto activation");
2883 /* we should get zero or two ServiceOwnerChanged signals */
2884 if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_SIGNAL)
2886 GotServiceInfo message_kind;
2888 if (!check_base_service_activated (context, connection,
2889 message, &base_service))
2892 base_service_message = message;
2895 /* We may need to block here for the test service to exit or finish up */
2896 block_connection_until_message_from_bus (context, connection, "service to exit");
2898 /* Should get a service creation notification for the activated
2899 * service name, or a service deletion on the base service name
2901 message = dbus_connection_borrow_message (connection);
2902 if (message == NULL)
2904 _dbus_warn ("No message after auto activation "
2905 "(should be a service announcement)");
2906 dbus_connection_return_message (connection, message);
2911 message_kind = check_got_service_info (message);
2913 dbus_connection_return_message (connection, message);
2916 switch (message_kind)
2918 case GOT_SERVICE_CREATED:
2919 message = pop_message_waiting_for_memory (connection);
2920 if (message == NULL)
2922 _dbus_warn ("Failed to pop message we just put back! "
2923 "should have been a ServiceOwnerChanged (creation)\n");
2927 /* Check that ServiceOwnerChanged (creation) was correctly received */
2928 if (!check_service_auto_activated (context, connection, EXISTENT_SERVICE_NAME,
2929 base_service, message))
2932 dbus_message_unref (message);
2937 case GOT_SERVICE_DELETED:
2939 /* The service started up and got a base address, but then
2940 * failed to register under EXISTENT_SERVICE_NAME
2942 CheckServiceOwnerChangedData socd;
2944 socd.expected_kind = SERVICE_DELETED;
2945 socd.expected_service_name = base_service;
2946 socd.failed = FALSE;
2947 socd.skip_connection = NULL;
2948 bus_test_clients_foreach (check_service_owner_changed_foreach,
2958 case GOT_SOMETHING_ELSE:
2959 _dbus_warn ("Unexpected message after auto activation\n");
2964 /* OK, now we've dealt with ServiceOwnerChanged signals, now should
2965 * come the method reply (or error) from the initial method call
2968 /* Note: if this test is run in OOM mode, it will block when the bus
2969 * doesn't send a reply due to OOM.
2971 block_connection_until_message_from_bus (context, connection, "reply from echo message after auto-activation");
2973 message = pop_message_waiting_for_memory (connection);
2974 if (message == NULL)
2976 _dbus_warn ("Failed to pop message! Should have been reply from echo message\n");
2980 if (dbus_message_get_reply_serial (message) != serial)
2982 _dbus_warn ("Wrong reply serial\n");
2986 dbus_message_unref (message);
2989 if (!check_send_exit_to_service (context, connection,
2990 EXISTENT_SERVICE_NAME,
2998 dbus_message_unref (message);
3000 if (base_service_message)
3001 dbus_message_unref (base_service_message);
3009 BusContext *context;
3013 check_oom_check1_func (void *data)
3015 Check1Data *d = data;
3017 if (! (* d->func) (d->context))
3020 if (!check_no_leftovers (d->context))
3022 _dbus_warn ("Messages were left over, should be covered by test suite\n");
3030 check1_try_iterations (BusContext *context,
3031 const char *description,
3037 d.context = context;
3039 if (!_dbus_test_oom_handling (description, check_oom_check1_func,
3041 _dbus_assert_not_reached ("test failed");
3047 BusContext *context;
3048 DBusConnection *connection;
3052 check_oom_check2_func (void *data)
3054 Check2Data *d = data;
3056 if (! (* d->func) (d->context, d->connection))
3059 if (!check_no_leftovers (d->context))
3061 _dbus_warn ("Messages were left over, should be covered by test suite");
3069 check2_try_iterations (BusContext *context,
3070 DBusConnection *connection,
3071 const char *description,
3077 d.context = context;
3078 d.connection = connection;
3080 if (!_dbus_test_oom_handling (description, check_oom_check2_func,
3083 _dbus_warn ("%s failed during oom\n", description);
3084 _dbus_assert_not_reached ("test failed");
3089 bus_dispatch_test (const DBusString *test_data_dir)
3091 BusContext *context;
3092 DBusConnection *foo;
3093 DBusConnection *bar;
3094 DBusConnection *baz;
3097 dbus_error_init (&error);
3099 context = bus_context_new_test (test_data_dir,
3100 "valid-config-files/debug-allow-all.conf");
3101 if (context == NULL)
3104 foo = dbus_connection_open ("debug-pipe:name=test-server", &error);
3106 _dbus_assert_not_reached ("could not alloc connection");
3108 if (!bus_setup_debug_client (foo))
3109 _dbus_assert_not_reached ("could not set up connection");
3111 spin_connection_until_authenticated (context, foo);
3113 if (!check_hello_message (context, foo))
3114 _dbus_assert_not_reached ("hello message failed");
3116 if (!check_double_hello_message (context, foo))
3117 _dbus_assert_not_reached ("double hello message failed");
3119 if (!check_add_match_all (context, foo))
3120 _dbus_assert_not_reached ("AddMatch message failed");
3122 bar = dbus_connection_open ("debug-pipe:name=test-server", &error);
3124 _dbus_assert_not_reached ("could not alloc connection");
3126 if (!bus_setup_debug_client (bar))
3127 _dbus_assert_not_reached ("could not set up connection");
3129 spin_connection_until_authenticated (context, bar);
3131 if (!check_hello_message (context, bar))
3132 _dbus_assert_not_reached ("hello message failed");
3134 if (!check_add_match_all (context, bar))
3135 _dbus_assert_not_reached ("AddMatch message failed");
3137 baz = dbus_connection_open ("debug-pipe:name=test-server", &error);
3139 _dbus_assert_not_reached ("could not alloc connection");
3141 if (!bus_setup_debug_client (baz))
3142 _dbus_assert_not_reached ("could not set up connection");
3144 spin_connection_until_authenticated (context, baz);
3146 if (!check_hello_message (context, baz))
3147 _dbus_assert_not_reached ("hello message failed");
3149 if (!check_add_match_all (context, baz))
3150 _dbus_assert_not_reached ("AddMatch message failed");
3152 if (!check_get_connection_unix_user (context, baz))
3153 _dbus_assert_not_reached ("GetConnectionUnixUser message failed");
3155 if (!check_get_connection_unix_process_id (context, baz))
3156 _dbus_assert_not_reached ("GetConnectionUnixProcessID message failed");
3158 if (!check_no_leftovers (context))
3160 _dbus_warn ("Messages were left over after setting up initial connections");
3161 _dbus_assert_not_reached ("initial connection setup failed");
3164 check1_try_iterations (context, "create_and_hello",
3165 check_hello_connection);
3167 check2_try_iterations (context, foo, "nonexistent_service_activation",
3168 check_nonexistent_service_activation);
3170 check2_try_iterations (context, foo, "segfault_service_activation",
3171 check_segfault_service_activation);
3173 check2_try_iterations (context, foo, "existent_service_activation",
3174 check_existent_service_activation);
3176 check2_try_iterations (context, foo, "nonexistent_service_auto_activation",
3177 check_nonexistent_service_auto_activation);
3179 check2_try_iterations (context, foo, "segfault_service_auto_activation",
3180 check_segfault_service_auto_activation);
3183 /* Note: need to resolve some issues with the testing code in order to run
3184 * this in oom (handle that we sometimes don't get replies back from the bus
3185 * when oom happens, without blocking the test).
3187 check2_try_iterations (context, foo, "existent_service_auto_activation",
3188 check_existent_service_auto_activation);
3191 if (!check_existent_service_auto_activation (context, foo))
3192 _dbus_assert_not_reached ("existent service auto activation failed");
3194 _dbus_verbose ("Disconnecting foo, bar, and baz\n");
3196 kill_client_connection_unchecked (foo);
3197 kill_client_connection_unchecked (bar);
3198 kill_client_connection_unchecked (baz);
3200 bus_context_unref (context);
3206 bus_dispatch_sha1_test (const DBusString *test_data_dir)
3208 BusContext *context;
3209 DBusConnection *foo;
3212 dbus_error_init (&error);
3214 /* Test SHA1 authentication */
3215 _dbus_verbose ("Testing SHA1 context\n");
3217 context = bus_context_new_test (test_data_dir,
3218 "valid-config-files/debug-allow-all-sha1.conf");
3219 if (context == NULL)
3222 foo = dbus_connection_open ("debug-pipe:name=test-server", &error);
3224 _dbus_assert_not_reached ("could not alloc connection");
3226 if (!bus_setup_debug_client (foo))
3227 _dbus_assert_not_reached ("could not set up connection");
3229 spin_connection_until_authenticated (context, foo);
3231 if (!check_hello_message (context, foo))
3232 _dbus_assert_not_reached ("hello message failed");
3234 if (!check_add_match_all (context, foo))
3235 _dbus_assert_not_reached ("addmatch message failed");
3237 if (!check_no_leftovers (context))
3239 _dbus_warn ("Messages were left over after setting up initial SHA-1 connection\n");
3240 _dbus_assert_not_reached ("initial connection setup failed");
3243 check1_try_iterations (context, "create_and_hello_sha1",
3244 check_hello_connection);
3246 kill_client_connection_unchecked (foo);
3248 bus_context_unref (context);
3253 #endif /* DBUS_BUILD_TESTS */