1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* driver.c Bus client (driver)
4 * Copyright (C) 2003 CodeFactory AB
5 * Copyright (C) 2003, 2004, 2005 Red Hat, Inc.
7 * Licensed under the Academic Free License version 2.1
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
25 #include "activation.h"
26 #include "connection.h"
33 #include <dbus/dbus-string.h>
34 #include <dbus/dbus-internals.h>
35 #include <dbus/dbus-marshal-recursive.h>
38 static dbus_bool_t bus_driver_send_welcome_message (DBusConnection *connection,
39 DBusMessage *hello_message,
40 BusTransaction *transaction,
44 bus_driver_send_service_owner_changed (const char *service_name,
45 const char *old_owner,
46 const char *new_owner,
47 BusTransaction *transaction,
52 const char *null_service;
54 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
57 _dbus_verbose ("sending name owner changed: %s [%s -> %s]\n",
59 old_owner ? old_owner : null_service,
60 new_owner ? new_owner : null_service);
62 message = dbus_message_new_signal (DBUS_PATH_DBUS,
72 if (!dbus_message_set_sender (message, DBUS_SERVICE_DBUS))
75 if (!dbus_message_append_args (message,
76 DBUS_TYPE_STRING, &service_name,
77 DBUS_TYPE_STRING, old_owner ? &old_owner : &null_service,
78 DBUS_TYPE_STRING, new_owner ? &new_owner : &null_service,
82 _dbus_assert (dbus_message_has_signature (message, "sss"));
84 retval = bus_dispatch_matches (transaction, NULL, NULL, message, error);
85 dbus_message_unref (message);
90 dbus_message_unref (message);
96 bus_driver_send_service_lost (DBusConnection *connection,
97 const char *service_name,
98 BusTransaction *transaction,
101 DBusMessage *message;
103 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
105 message = dbus_message_new_signal (DBUS_PATH_DBUS,
115 if (!dbus_message_set_destination (message, bus_connection_get_name (connection)) ||
116 !dbus_message_append_args (message,
117 DBUS_TYPE_STRING, &service_name,
120 dbus_message_unref (message);
125 if (!bus_transaction_send_from_driver (transaction, connection, message))
127 dbus_message_unref (message);
133 dbus_message_unref (message);
139 bus_driver_send_service_acquired (DBusConnection *connection,
140 const char *service_name,
141 BusTransaction *transaction,
144 DBusMessage *message;
146 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
148 message = dbus_message_new_signal (DBUS_PATH_DBUS,
158 if (!dbus_message_set_destination (message, bus_connection_get_name (connection)) ||
159 !dbus_message_append_args (message,
160 DBUS_TYPE_STRING, &service_name,
163 dbus_message_unref (message);
168 if (!bus_transaction_send_from_driver (transaction, connection, message))
170 dbus_message_unref (message);
176 dbus_message_unref (message);
182 create_unique_client_name (BusRegistry *registry,
185 /* We never want to use the same unique client name twice, because
186 * we want to guarantee that if you send a message to a given unique
187 * name, you always get the same application. So we use two numbers
188 * for INT_MAX * INT_MAX combinations, should be pretty safe against
191 /* FIXME these should be in BusRegistry rather than static vars */
192 static int next_major_number = 0;
193 static int next_minor_number = 0;
196 len = _dbus_string_get_length (str);
200 /* start out with 1-0, go to 1-1, 1-2, 1-3,
201 * up to 1-MAXINT, then 2-0, 2-1, etc.
203 if (next_minor_number <= 0)
205 next_major_number += 1;
206 next_minor_number = 0;
207 if (next_major_number <= 0)
208 _dbus_assert_not_reached ("INT_MAX * INT_MAX clients were added");
211 _dbus_assert (next_major_number > 0);
212 _dbus_assert (next_minor_number >= 0);
214 /* appname:MAJOR-MINOR */
216 if (!_dbus_string_append (str, ":"))
219 if (!_dbus_string_append_int (str, next_major_number))
222 if (!_dbus_string_append (str, "."))
225 if (!_dbus_string_append_int (str, next_minor_number))
228 next_minor_number += 1;
230 /* Check if a client with the name exists */
231 if (bus_registry_lookup (registry, str) == NULL)
234 /* drop the number again, try the next one. */
235 _dbus_string_set_length (str, len);
242 bus_driver_handle_hello (DBusConnection *connection,
243 BusTransaction *transaction,
244 DBusMessage *message,
247 DBusString unique_name;
250 BusRegistry *registry;
251 BusConnections *connections;
253 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
255 if (bus_connection_is_active (connection))
257 /* We already handled an Hello message for this connection. */
258 dbus_set_error (error, DBUS_ERROR_FAILED,
259 "Already handled an Hello message");
263 /* Note that when these limits are exceeded we don't disconnect the
264 * connection; we just sort of leave it hanging there until it times
265 * out or disconnects itself or is dropped due to the max number of
266 * incomplete connections. It's even OK if the connection wants to
267 * retry the hello message, we support that.
269 connections = bus_connection_get_connections (connection);
270 if (!bus_connections_check_limits (connections, connection,
273 _DBUS_ASSERT_ERROR_IS_SET (error);
277 if (!_dbus_string_init (&unique_name))
285 registry = bus_connection_get_registry (connection);
287 if (!create_unique_client_name (registry, &unique_name))
293 if (!bus_connection_complete (connection, &unique_name, error))
295 _DBUS_ASSERT_ERROR_IS_SET (error);
299 if (!dbus_message_set_sender (message,
300 bus_connection_get_name (connection)))
306 if (!bus_driver_send_welcome_message (connection, message, transaction, error))
309 /* Create the service */
310 service = bus_registry_ensure (registry,
311 &unique_name, connection, transaction, error);
315 bus_service_set_prohibit_replacement (service, TRUE);
317 _dbus_assert (bus_connection_is_active (connection));
321 _dbus_string_free (&unique_name);
326 bus_driver_send_welcome_message (DBusConnection *connection,
327 DBusMessage *hello_message,
328 BusTransaction *transaction,
331 DBusMessage *welcome;
334 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
336 name = bus_connection_get_name (connection);
337 _dbus_assert (name != NULL);
339 welcome = dbus_message_new_method_return (hello_message);
346 if (!dbus_message_append_args (welcome,
347 DBUS_TYPE_STRING, &name,
350 dbus_message_unref (welcome);
355 _dbus_assert (dbus_message_has_signature (welcome, DBUS_TYPE_STRING_AS_STRING));
357 if (!bus_transaction_send_from_driver (transaction, connection, welcome))
359 dbus_message_unref (welcome);
365 dbus_message_unref (welcome);
371 bus_driver_handle_list_services (DBusConnection *connection,
372 BusTransaction *transaction,
373 DBusMessage *message,
379 BusRegistry *registry;
381 DBusMessageIter iter;
384 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
386 registry = bus_connection_get_registry (connection);
388 reply = dbus_message_new_method_return (message);
395 if (!bus_registry_list_services (registry, &services, &len))
397 dbus_message_unref (reply);
402 dbus_message_iter_init_append (reply, &iter);
404 if (!dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY,
405 DBUS_TYPE_STRING_AS_STRING,
408 dbus_free_string_array (services);
409 dbus_message_unref (reply);
415 /* Include the bus driver in the list */
416 const char *v_STRING = DBUS_SERVICE_DBUS;
417 if (!dbus_message_iter_append_basic (&sub, DBUS_TYPE_STRING,
420 dbus_free_string_array (services);
421 dbus_message_unref (reply);
430 if (!dbus_message_iter_append_basic (&sub, DBUS_TYPE_STRING,
433 dbus_free_string_array (services);
434 dbus_message_unref (reply);
441 if (!dbus_message_iter_close_container (&iter, &sub))
443 dbus_free_string_array (services);
444 dbus_message_unref (reply);
449 dbus_free_string_array (services);
451 if (!bus_transaction_send_from_driver (transaction, connection, reply))
453 dbus_message_unref (reply);
459 dbus_message_unref (reply);
465 bus_driver_handle_acquire_service (DBusConnection *connection,
466 BusTransaction *transaction,
467 DBusMessage *message,
471 DBusString service_name;
476 BusRegistry *registry;
478 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
480 registry = bus_connection_get_registry (connection);
482 if (!dbus_message_get_args (message, error,
483 DBUS_TYPE_STRING, &name,
484 DBUS_TYPE_UINT32, &flags,
488 _dbus_verbose ("Trying to own name %s with flags 0x%x\n", name, flags);
493 _dbus_string_init_const (&service_name, name);
495 if (!bus_registry_acquire_service (registry, connection,
496 &service_name, flags,
497 &service_reply, transaction,
501 reply = dbus_message_new_method_return (message);
508 if (!dbus_message_append_args (reply, DBUS_TYPE_UINT32, &service_reply, DBUS_TYPE_INVALID))
514 if (!bus_transaction_send_from_driver (transaction, connection, reply))
524 dbus_message_unref (reply);
529 bus_driver_handle_service_exists (DBusConnection *connection,
530 BusTransaction *transaction,
531 DBusMessage *message,
535 DBusString service_name;
537 dbus_bool_t service_exists;
540 BusRegistry *registry;
542 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
544 registry = bus_connection_get_registry (connection);
546 if (!dbus_message_get_args (message, error,
547 DBUS_TYPE_STRING, &name,
553 if (strcmp (name, DBUS_SERVICE_DBUS) == 0)
555 service_exists = TRUE;
559 _dbus_string_init_const (&service_name, name);
560 service = bus_registry_lookup (registry, &service_name);
561 service_exists = service != NULL;
564 reply = dbus_message_new_method_return (message);
571 if (!dbus_message_append_args (reply,
572 DBUS_TYPE_BOOLEAN, &service_exists,
579 if (!bus_transaction_send_from_driver (transaction, connection, reply))
589 dbus_message_unref (reply);
595 bus_driver_handle_activate_service (DBusConnection *connection,
596 BusTransaction *transaction,
597 DBusMessage *message,
603 BusActivation *activation;
605 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
607 activation = bus_connection_get_activation (connection);
609 if (!dbus_message_get_args (message, error,
610 DBUS_TYPE_STRING, &name,
611 DBUS_TYPE_UINT32, &flags,
614 _DBUS_ASSERT_ERROR_IS_SET (error);
615 _dbus_verbose ("No memory to get arguments to StartServiceByName\n");
621 if (!bus_activation_activate_service (activation, connection, transaction, FALSE,
622 message, name, error))
624 _DBUS_ASSERT_ERROR_IS_SET (error);
625 _dbus_verbose ("bus_activation_activate_service() failed\n");
636 send_ack_reply (DBusConnection *connection,
637 BusTransaction *transaction,
638 DBusMessage *message,
643 reply = dbus_message_new_method_return (message);
650 if (!bus_transaction_send_from_driver (transaction, connection, reply))
653 dbus_message_unref (reply);
657 dbus_message_unref (reply);
663 bus_driver_handle_add_match (DBusConnection *connection,
664 BusTransaction *transaction,
665 DBusMessage *message,
671 BusMatchmaker *matchmaker;
673 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
678 if (bus_connection_get_n_match_rules (connection) >=
679 bus_context_get_max_match_rules_per_connection (bus_transaction_get_context (transaction)))
681 dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
682 "Connection \"%s\" is not allowed to add more match rules "
683 "(increase limits in configuration file if required)",
684 bus_connection_is_active (connection) ?
685 bus_connection_get_name (connection) :
690 if (!dbus_message_get_args (message, error,
691 DBUS_TYPE_STRING, &text,
694 _dbus_verbose ("No memory to get arguments to AddMatch\n");
698 _dbus_string_init_const (&str, text);
700 rule = bus_match_rule_parse (connection, &str, error);
704 matchmaker = bus_connection_get_matchmaker (connection);
706 if (!bus_matchmaker_add_rule (matchmaker, rule))
712 if (!send_ack_reply (connection, transaction,
715 bus_matchmaker_remove_rule (matchmaker, rule);
719 bus_match_rule_unref (rule);
724 _DBUS_ASSERT_ERROR_IS_SET (error);
726 bus_match_rule_unref (rule);
731 bus_driver_handle_remove_match (DBusConnection *connection,
732 BusTransaction *transaction,
733 DBusMessage *message,
739 BusMatchmaker *matchmaker;
741 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
746 if (!dbus_message_get_args (message, error,
747 DBUS_TYPE_STRING, &text,
750 _dbus_verbose ("No memory to get arguments to RemoveMatch\n");
754 _dbus_string_init_const (&str, text);
756 rule = bus_match_rule_parse (connection, &str, error);
760 /* Send the ack before we remove the rule, since the ack is undone
761 * on transaction cancel, but rule removal isn't.
763 if (!send_ack_reply (connection, transaction,
767 matchmaker = bus_connection_get_matchmaker (connection);
769 if (!bus_matchmaker_remove_rule_by_value (matchmaker, rule, error))
772 bus_match_rule_unref (rule);
777 _DBUS_ASSERT_ERROR_IS_SET (error);
779 bus_match_rule_unref (rule);
784 bus_driver_handle_get_service_owner (DBusConnection *connection,
785 BusTransaction *transaction,
786 DBusMessage *message,
790 const char *base_name;
792 BusRegistry *registry;
796 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
798 registry = bus_connection_get_registry (connection);
803 if (! dbus_message_get_args (message, error,
804 DBUS_TYPE_STRING, &text,
808 _dbus_string_init_const (&str, text);
809 service = bus_registry_lookup (registry, &str);
810 if (service == NULL &&
811 _dbus_string_equal_c_str (&str, DBUS_SERVICE_DBUS))
813 /* ORG_FREEDESKTOP_DBUS owns itself */
814 base_name = DBUS_SERVICE_DBUS;
816 else if (service == NULL)
818 dbus_set_error (error,
819 DBUS_ERROR_NAME_HAS_NO_OWNER,
820 "Could not get owner of name '%s': no such name", text);
825 base_name = bus_connection_get_name (bus_service_get_primary_owner (service));
826 if (base_name == NULL)
828 /* FIXME - how is this error possible? */
829 dbus_set_error (error,
831 "Could not determine unique name for '%s'", text);
834 _dbus_assert (*base_name == ':');
837 _dbus_assert (base_name != NULL);
839 reply = dbus_message_new_method_return (message);
843 if (! dbus_message_append_args (reply,
844 DBUS_TYPE_STRING, &base_name,
848 if (! bus_transaction_send_from_driver (transaction, connection, reply))
851 dbus_message_unref (reply);
859 _DBUS_ASSERT_ERROR_IS_SET (error);
861 dbus_message_unref (reply);
866 bus_driver_handle_get_connection_unix_user (DBusConnection *connection,
867 BusTransaction *transaction,
868 DBusMessage *message,
873 BusRegistry *registry;
875 DBusConnection *conn;
880 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
882 registry = bus_connection_get_registry (connection);
887 if (! dbus_message_get_args (message, error,
888 DBUS_TYPE_STRING, &service,
892 _dbus_verbose ("asked for UID of connection %s\n", service);
894 _dbus_string_init_const (&str, service);
895 serv = bus_registry_lookup (registry, &str);
898 dbus_set_error (error,
899 DBUS_ERROR_NAME_HAS_NO_OWNER,
900 "Could not get UID of name '%s': no such name", service);
904 conn = bus_service_get_primary_owner (serv);
906 reply = dbus_message_new_method_return (message);
910 if (!dbus_connection_get_unix_user (conn, &uid))
912 dbus_set_error (error,
914 "Could not determine UID for '%s'", service);
919 if (! dbus_message_append_args (reply,
920 DBUS_TYPE_UINT32, &uid32,
924 if (! bus_transaction_send_from_driver (transaction, connection, reply))
927 dbus_message_unref (reply);
935 _DBUS_ASSERT_ERROR_IS_SET (error);
937 dbus_message_unref (reply);
942 bus_driver_handle_get_connection_unix_process_id (DBusConnection *connection,
943 BusTransaction *transaction,
944 DBusMessage *message,
949 BusRegistry *registry;
951 DBusConnection *conn;
956 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
958 registry = bus_connection_get_registry (connection);
963 if (! dbus_message_get_args (message, error,
964 DBUS_TYPE_STRING, &service,
968 _dbus_verbose ("asked for PID of connection %s\n", service);
970 _dbus_string_init_const (&str, service);
971 serv = bus_registry_lookup (registry, &str);
974 dbus_set_error (error,
975 DBUS_ERROR_NAME_HAS_NO_OWNER,
976 "Could not get PID of name '%s': no such name", service);
980 conn = bus_service_get_primary_owner (serv);
982 reply = dbus_message_new_method_return (message);
986 if (!dbus_connection_get_unix_process_id (conn, &pid))
988 dbus_set_error (error,
989 DBUS_ERROR_UNIX_PROCESS_ID_UNKNOWN,
990 "Could not determine PID for '%s'", service);
995 if (! dbus_message_append_args (reply,
996 DBUS_TYPE_UINT32, &pid32,
1000 if (! bus_transaction_send_from_driver (transaction, connection, reply))
1003 dbus_message_unref (reply);
1008 BUS_SET_OOM (error);
1011 _DBUS_ASSERT_ERROR_IS_SET (error);
1013 dbus_message_unref (reply);
1018 bus_driver_handle_get_connection_selinux_security_context (DBusConnection *connection,
1019 BusTransaction *transaction,
1020 DBusMessage *message,
1023 const char *service;
1025 BusRegistry *registry;
1027 DBusConnection *conn;
1029 BusSELinuxID *context;
1031 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1033 registry = bus_connection_get_registry (connection);
1038 if (! dbus_message_get_args (message, error,
1039 DBUS_TYPE_STRING, &service,
1043 _dbus_verbose ("asked for security context of connection %s\n", service);
1045 _dbus_string_init_const (&str, service);
1046 serv = bus_registry_lookup (registry, &str);
1049 dbus_set_error (error,
1050 DBUS_ERROR_NAME_HAS_NO_OWNER,
1051 "Could not get security context of name '%s': no such name", service);
1055 conn = bus_service_get_primary_owner (serv);
1057 reply = dbus_message_new_method_return (message);
1061 context = bus_connection_get_selinux_id (conn);
1064 dbus_set_error (error,
1065 DBUS_ERROR_SELINUX_SECURITY_CONTEXT_UNKNOWN,
1066 "Could not determine security context for '%s'", service);
1070 if (! bus_selinux_append_context (reply, context, error))
1073 if (! bus_transaction_send_from_driver (transaction, connection, reply))
1076 dbus_message_unref (reply);
1081 BUS_SET_OOM (error);
1084 _DBUS_ASSERT_ERROR_IS_SET (error);
1086 dbus_message_unref (reply);
1091 bus_driver_handle_reload_config (DBusConnection *connection,
1092 BusTransaction *transaction,
1093 DBusMessage *message,
1096 BusContext *context;
1099 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1103 context = bus_connection_get_context (connection);
1104 if (!bus_context_reload_config (context, error))
1106 _DBUS_ASSERT_ERROR_IS_SET (error);
1116 /* For speed it might be useful to sort this in order of
1117 * frequency of use (but doesn't matter with only a few items
1123 const char *in_args;
1124 const char *out_args;
1125 dbus_bool_t (* handler) (DBusConnection *connection,
1126 BusTransaction *transaction,
1127 DBusMessage *message,
1129 } message_handlers[] = {
1131 DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING,
1132 DBUS_TYPE_UINT32_AS_STRING,
1133 bus_driver_handle_acquire_service },
1134 { "StartServiceByName",
1135 DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING,
1136 DBUS_TYPE_UINT32_AS_STRING,
1137 bus_driver_handle_activate_service },
1140 DBUS_TYPE_STRING_AS_STRING,
1141 bus_driver_handle_hello },
1143 DBUS_TYPE_STRING_AS_STRING,
1144 DBUS_TYPE_BOOLEAN_AS_STRING,
1145 bus_driver_handle_service_exists },
1148 DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING,
1149 bus_driver_handle_list_services },
1151 DBUS_TYPE_STRING_AS_STRING,
1153 bus_driver_handle_add_match },
1155 DBUS_TYPE_STRING_AS_STRING,
1157 bus_driver_handle_remove_match },
1159 DBUS_TYPE_STRING_AS_STRING,
1160 DBUS_TYPE_STRING_AS_STRING,
1161 bus_driver_handle_get_service_owner },
1162 { "GetConnectionUnixUser",
1163 DBUS_TYPE_STRING_AS_STRING,
1164 DBUS_TYPE_UINT32_AS_STRING,
1165 bus_driver_handle_get_connection_unix_user },
1166 { "GetConnectionUnixProcessID",
1167 DBUS_TYPE_STRING_AS_STRING,
1168 DBUS_TYPE_UINT32_AS_STRING,
1169 bus_driver_handle_get_connection_unix_process_id },
1170 { "GetConnectionSELinuxSecurityContext",
1171 DBUS_TYPE_STRING_AS_STRING,
1172 DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_BYTE_AS_STRING,
1173 bus_driver_handle_get_connection_selinux_security_context },
1177 bus_driver_handle_reload_config }
1181 write_args_for_direction (DBusString *xml,
1182 const char *signature,
1185 DBusTypeReader typereader;
1189 _dbus_string_init_const (&sigstr, signature);
1190 _dbus_type_reader_init_types_only (&typereader, &sigstr, 0);
1192 while ((current_type = _dbus_type_reader_get_current_type (&typereader)) != DBUS_TYPE_INVALID)
1194 const DBusString *subsig;
1197 _dbus_type_reader_get_signature (&typereader, &subsig, &start, &len);
1198 if (!_dbus_string_append_printf (xml, " <arg direction=\"%s\" type=\"",
1201 if (!_dbus_string_append_len (xml,
1202 _dbus_string_get_const_data (subsig) + start,
1205 if (!_dbus_string_append (xml, "\"/>\n"))
1208 _dbus_type_reader_next (&typereader);
1216 bus_driver_handle_introspect (DBusConnection *connection,
1217 BusTransaction *transaction,
1218 DBusMessage *message,
1223 const char *v_STRING;
1226 _dbus_verbose ("Introspect() on bus driver\n");
1228 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1232 if (! dbus_message_get_args (message, error,
1235 _DBUS_ASSERT_ERROR_IS_SET (error);
1239 if (!_dbus_string_init (&xml))
1241 BUS_SET_OOM (error);
1245 if (!_dbus_string_append (&xml, DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE))
1247 if (!_dbus_string_append (&xml, "<node>\n"))
1249 if (!_dbus_string_append_printf (&xml, " <interface name=\"%s\">\n", DBUS_INTERFACE_INTROSPECTABLE))
1251 if (!_dbus_string_append (&xml, " <method name=\"Introspect\">\n"))
1253 if (!_dbus_string_append_printf (&xml, " <arg name=\"data\" direction=\"out\" type=\"%s\"/>\n", DBUS_TYPE_STRING_AS_STRING))
1255 if (!_dbus_string_append (&xml, " </method>\n"))
1257 if (!_dbus_string_append (&xml, " </interface>\n"))
1260 if (!_dbus_string_append_printf (&xml, " <interface name=\"%s\">\n",
1261 DBUS_INTERFACE_DBUS))
1265 while (i < _DBUS_N_ELEMENTS (message_handlers))
1268 if (!_dbus_string_append_printf (&xml, " <method name=\"%s\">\n",
1269 message_handlers[i].name))
1272 if (!write_args_for_direction (&xml, message_handlers[i].in_args, TRUE))
1275 if (!write_args_for_direction (&xml, message_handlers[i].out_args, FALSE))
1278 if (!_dbus_string_append (&xml, " </method>\n"))
1284 if (!_dbus_string_append (&xml, " </interface>\n"))
1287 if (!_dbus_string_append (&xml, "</node>\n"))
1290 reply = dbus_message_new_method_return (message);
1294 v_STRING = _dbus_string_get_const_data (&xml);
1295 if (! dbus_message_append_args (reply,
1296 DBUS_TYPE_STRING, &v_STRING,
1300 if (! bus_transaction_send_from_driver (transaction, connection, reply))
1303 dbus_message_unref (reply);
1304 _dbus_string_free (&xml);
1309 BUS_SET_OOM (error);
1312 dbus_message_unref (reply);
1314 _dbus_string_free (&xml);
1320 bus_driver_handle_message (DBusConnection *connection,
1321 BusTransaction *transaction,
1322 DBusMessage *message,
1325 const char *name, *sender, *interface;
1328 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1330 if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_METHOD_CALL)
1332 _dbus_verbose ("Driver got a non-method-call message, ignoring\n");
1333 return TRUE; /* we just ignore this */
1336 if (dbus_message_is_method_call (message,
1337 DBUS_INTERFACE_INTROSPECTABLE,
1339 return bus_driver_handle_introspect (connection, transaction, message, error);
1341 interface = dbus_message_get_interface (message);
1342 if (interface == NULL)
1343 interface = DBUS_INTERFACE_DBUS;
1345 _dbus_assert (dbus_message_get_member (message) != NULL);
1347 name = dbus_message_get_member (message);
1348 sender = dbus_message_get_sender (message);
1350 if (strcmp (interface,
1351 DBUS_INTERFACE_DBUS) != 0)
1353 _dbus_verbose ("Driver got message to unknown interface \"%s\"\n",
1358 _dbus_verbose ("Driver got a method call: %s\n",
1359 dbus_message_get_member (message));
1361 /* security checks should have kept this from getting here */
1362 _dbus_assert (sender != NULL || strcmp (name, "Hello") == 0);
1365 while (i < _DBUS_N_ELEMENTS (message_handlers))
1367 if (strcmp (message_handlers[i].name, name) == 0)
1369 _dbus_verbose ("Found driver handler for %s\n", name);
1371 if (!dbus_message_has_signature (message, message_handlers[i].in_args))
1373 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1374 _dbus_verbose ("Call to %s has wrong args (%s, expected %s)\n",
1375 name, dbus_message_get_signature (message),
1376 message_handlers[i].in_args);
1378 dbus_set_error (error, DBUS_ERROR_INVALID_ARGS,
1379 "Call to %s has wrong args (%s, expected %s)\n",
1380 name, dbus_message_get_signature (message),
1381 message_handlers[i].in_args);
1382 _DBUS_ASSERT_ERROR_IS_SET (error);
1386 if ((* message_handlers[i].handler) (connection, transaction, message, error))
1388 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1389 _dbus_verbose ("Driver handler succeeded\n");
1394 _DBUS_ASSERT_ERROR_IS_SET (error);
1395 _dbus_verbose ("Driver handler returned failure\n");
1404 _dbus_verbose ("No driver handler for message \"%s\"\n",
1407 dbus_set_error (error, DBUS_ERROR_UNKNOWN_METHOD,
1408 "%s does not understand message %s",
1409 DBUS_SERVICE_DBUS, name);
1415 bus_driver_remove_connection (DBusConnection *connection)
1417 /* FIXME Does nothing for now, should unregister the connection
1418 * with the bus driver.