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"
32 #include <dbus/dbus-string.h>
33 #include <dbus/dbus-internals.h>
36 static dbus_bool_t bus_driver_send_welcome_message (DBusConnection *connection,
37 DBusMessage *hello_message,
38 BusTransaction *transaction,
42 bus_driver_send_service_owner_changed (const char *service_name,
43 const char *old_owner,
44 const char *new_owner,
45 BusTransaction *transaction,
50 const char *null_service;
52 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
55 _dbus_verbose ("sending name owner changed: %s [%s -> %s]\n",
57 old_owner ? old_owner : null_service,
58 new_owner ? new_owner : null_service);
60 message = dbus_message_new_signal (DBUS_PATH_DBUS,
70 if (!dbus_message_set_sender (message, DBUS_SERVICE_DBUS))
73 if (!dbus_message_append_args (message,
74 DBUS_TYPE_STRING, &service_name,
75 DBUS_TYPE_STRING, old_owner ? &old_owner : &null_service,
76 DBUS_TYPE_STRING, new_owner ? &new_owner : &null_service,
80 _dbus_assert (dbus_message_has_signature (message, "sss"));
82 retval = bus_dispatch_matches (transaction, NULL, NULL, message, error);
83 dbus_message_unref (message);
88 dbus_message_unref (message);
94 bus_driver_send_service_lost (DBusConnection *connection,
95 const char *service_name,
96 BusTransaction *transaction,
101 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
103 message = dbus_message_new_signal (DBUS_PATH_DBUS,
113 if (!dbus_message_set_destination (message, bus_connection_get_name (connection)) ||
114 !dbus_message_append_args (message,
115 DBUS_TYPE_STRING, &service_name,
118 dbus_message_unref (message);
123 if (!bus_transaction_send_from_driver (transaction, connection, message))
125 dbus_message_unref (message);
131 dbus_message_unref (message);
137 bus_driver_send_service_acquired (DBusConnection *connection,
138 const char *service_name,
139 BusTransaction *transaction,
142 DBusMessage *message;
144 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
146 message = dbus_message_new_signal (DBUS_PATH_DBUS,
156 if (!dbus_message_set_destination (message, bus_connection_get_name (connection)) ||
157 !dbus_message_append_args (message,
158 DBUS_TYPE_STRING, &service_name,
161 dbus_message_unref (message);
166 if (!bus_transaction_send_from_driver (transaction, connection, message))
168 dbus_message_unref (message);
174 dbus_message_unref (message);
180 create_unique_client_name (BusRegistry *registry,
183 /* We never want to use the same unique client name twice, because
184 * we want to guarantee that if you send a message to a given unique
185 * name, you always get the same application. So we use two numbers
186 * for INT_MAX * INT_MAX combinations, should be pretty safe against
189 /* FIXME these should be in BusRegistry rather than static vars */
190 static int next_major_number = 0;
191 static int next_minor_number = 0;
194 len = _dbus_string_get_length (str);
198 /* start out with 1-0, go to 1-1, 1-2, 1-3,
199 * up to 1-MAXINT, then 2-0, 2-1, etc.
201 if (next_minor_number <= 0)
203 next_major_number += 1;
204 next_minor_number = 0;
205 if (next_major_number <= 0)
206 _dbus_assert_not_reached ("INT_MAX * INT_MAX clients were added");
209 _dbus_assert (next_major_number > 0);
210 _dbus_assert (next_minor_number >= 0);
212 /* appname:MAJOR-MINOR */
214 if (!_dbus_string_append (str, ":"))
217 if (!_dbus_string_append_int (str, next_major_number))
220 if (!_dbus_string_append (str, "."))
223 if (!_dbus_string_append_int (str, next_minor_number))
226 next_minor_number += 1;
228 /* Check if a client with the name exists */
229 if (bus_registry_lookup (registry, str) == NULL)
232 /* drop the number again, try the next one. */
233 _dbus_string_set_length (str, len);
240 bus_driver_handle_hello (DBusConnection *connection,
241 BusTransaction *transaction,
242 DBusMessage *message,
245 DBusString unique_name;
248 BusRegistry *registry;
249 BusConnections *connections;
251 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
253 if (bus_connection_is_active (connection))
255 /* We already handled an Hello message for this connection. */
256 dbus_set_error (error, DBUS_ERROR_FAILED,
257 "Already handled an Hello message");
261 /* Note that when these limits are exceeded we don't disconnect the
262 * connection; we just sort of leave it hanging there until it times
263 * out or disconnects itself or is dropped due to the max number of
264 * incomplete connections. It's even OK if the connection wants to
265 * retry the hello message, we support that.
267 connections = bus_connection_get_connections (connection);
268 if (!bus_connections_check_limits (connections, connection,
271 _DBUS_ASSERT_ERROR_IS_SET (error);
275 if (!_dbus_string_init (&unique_name))
283 registry = bus_connection_get_registry (connection);
285 if (!create_unique_client_name (registry, &unique_name))
291 if (!bus_connection_complete (connection, &unique_name, error))
293 _DBUS_ASSERT_ERROR_IS_SET (error);
297 if (!dbus_message_set_sender (message,
298 bus_connection_get_name (connection)))
304 if (!bus_driver_send_welcome_message (connection, message, transaction, error))
307 /* Create the service */
308 service = bus_registry_ensure (registry,
309 &unique_name, connection, transaction, error);
313 bus_service_set_prohibit_replacement (service, TRUE);
315 _dbus_assert (bus_connection_is_active (connection));
319 _dbus_string_free (&unique_name);
324 bus_driver_send_welcome_message (DBusConnection *connection,
325 DBusMessage *hello_message,
326 BusTransaction *transaction,
329 DBusMessage *welcome;
332 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
334 name = bus_connection_get_name (connection);
335 _dbus_assert (name != NULL);
337 welcome = dbus_message_new_method_return (hello_message);
344 if (!dbus_message_append_args (welcome,
345 DBUS_TYPE_STRING, &name,
348 dbus_message_unref (welcome);
353 _dbus_assert (dbus_message_has_signature (welcome, DBUS_TYPE_STRING_AS_STRING));
355 if (!bus_transaction_send_from_driver (transaction, connection, welcome))
357 dbus_message_unref (welcome);
363 dbus_message_unref (welcome);
369 bus_driver_handle_list_services (DBusConnection *connection,
370 BusTransaction *transaction,
371 DBusMessage *message,
377 BusRegistry *registry;
379 DBusMessageIter iter;
382 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
384 registry = bus_connection_get_registry (connection);
386 reply = dbus_message_new_method_return (message);
393 if (!bus_registry_list_services (registry, &services, &len))
395 dbus_message_unref (reply);
400 dbus_message_iter_init_append (reply, &iter);
402 if (!dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY,
403 DBUS_TYPE_STRING_AS_STRING,
406 dbus_free_string_array (services);
407 dbus_message_unref (reply);
413 /* Include the bus driver in the list */
414 const char *v_STRING = DBUS_SERVICE_DBUS;
415 if (!dbus_message_iter_append_basic (&sub, DBUS_TYPE_STRING,
418 dbus_free_string_array (services);
419 dbus_message_unref (reply);
428 if (!dbus_message_iter_append_basic (&sub, DBUS_TYPE_STRING,
431 dbus_free_string_array (services);
432 dbus_message_unref (reply);
439 if (!dbus_message_iter_close_container (&iter, &sub))
441 dbus_free_string_array (services);
442 dbus_message_unref (reply);
447 dbus_free_string_array (services);
449 if (!bus_transaction_send_from_driver (transaction, connection, reply))
451 dbus_message_unref (reply);
457 dbus_message_unref (reply);
463 bus_driver_handle_acquire_service (DBusConnection *connection,
464 BusTransaction *transaction,
465 DBusMessage *message,
469 DBusString service_name;
474 BusRegistry *registry;
476 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
478 registry = bus_connection_get_registry (connection);
480 if (!dbus_message_get_args (message, error,
481 DBUS_TYPE_STRING, &name,
482 DBUS_TYPE_UINT32, &flags,
486 _dbus_verbose ("Trying to own name %s with flags 0x%x\n", name, flags);
491 _dbus_string_init_const (&service_name, name);
493 if (!bus_registry_acquire_service (registry, connection,
494 &service_name, flags,
495 &service_reply, transaction,
499 reply = dbus_message_new_method_return (message);
506 if (!dbus_message_append_args (reply, DBUS_TYPE_UINT32, &service_reply, DBUS_TYPE_INVALID))
512 if (!bus_transaction_send_from_driver (transaction, connection, reply))
522 dbus_message_unref (reply);
527 bus_driver_handle_service_exists (DBusConnection *connection,
528 BusTransaction *transaction,
529 DBusMessage *message,
533 DBusString service_name;
535 dbus_bool_t service_exists;
538 BusRegistry *registry;
540 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
542 registry = bus_connection_get_registry (connection);
544 if (!dbus_message_get_args (message, error,
545 DBUS_TYPE_STRING, &name,
551 if (strcmp (name, DBUS_SERVICE_DBUS) == 0)
553 service_exists = TRUE;
557 _dbus_string_init_const (&service_name, name);
558 service = bus_registry_lookup (registry, &service_name);
559 service_exists = service != NULL;
562 reply = dbus_message_new_method_return (message);
569 if (!dbus_message_append_args (reply,
570 DBUS_TYPE_BOOLEAN, &service_exists,
577 if (!bus_transaction_send_from_driver (transaction, connection, reply))
587 dbus_message_unref (reply);
593 bus_driver_handle_activate_service (DBusConnection *connection,
594 BusTransaction *transaction,
595 DBusMessage *message,
601 BusActivation *activation;
603 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
605 activation = bus_connection_get_activation (connection);
607 if (!dbus_message_get_args (message, error,
608 DBUS_TYPE_STRING, &name,
609 DBUS_TYPE_UINT32, &flags,
612 _DBUS_ASSERT_ERROR_IS_SET (error);
613 _dbus_verbose ("No memory to get arguments to StartServiceByName\n");
619 if (!bus_activation_activate_service (activation, connection, transaction, FALSE,
620 message, name, error))
622 _DBUS_ASSERT_ERROR_IS_SET (error);
623 _dbus_verbose ("bus_activation_activate_service() failed\n");
634 send_ack_reply (DBusConnection *connection,
635 BusTransaction *transaction,
636 DBusMessage *message,
641 reply = dbus_message_new_method_return (message);
648 if (!bus_transaction_send_from_driver (transaction, connection, reply))
651 dbus_message_unref (reply);
655 dbus_message_unref (reply);
661 bus_driver_handle_add_match (DBusConnection *connection,
662 BusTransaction *transaction,
663 DBusMessage *message,
669 BusMatchmaker *matchmaker;
671 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
676 if (bus_connection_get_n_match_rules (connection) >=
677 bus_context_get_max_match_rules_per_connection (bus_transaction_get_context (transaction)))
679 dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
680 "Connection \"%s\" is not allowed to add more match rules "
681 "(increase limits in configuration file if required)",
682 bus_connection_is_active (connection) ?
683 bus_connection_get_name (connection) :
688 if (!dbus_message_get_args (message, error,
689 DBUS_TYPE_STRING, &text,
692 _dbus_verbose ("No memory to get arguments to AddMatch\n");
696 _dbus_string_init_const (&str, text);
698 rule = bus_match_rule_parse (connection, &str, error);
702 matchmaker = bus_connection_get_matchmaker (connection);
704 if (!bus_matchmaker_add_rule (matchmaker, rule))
710 if (!send_ack_reply (connection, transaction,
713 bus_matchmaker_remove_rule (matchmaker, rule);
717 bus_match_rule_unref (rule);
722 _DBUS_ASSERT_ERROR_IS_SET (error);
724 bus_match_rule_unref (rule);
729 bus_driver_handle_remove_match (DBusConnection *connection,
730 BusTransaction *transaction,
731 DBusMessage *message,
737 BusMatchmaker *matchmaker;
739 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
744 if (!dbus_message_get_args (message, error,
745 DBUS_TYPE_STRING, &text,
748 _dbus_verbose ("No memory to get arguments to RemoveMatch\n");
752 _dbus_string_init_const (&str, text);
754 rule = bus_match_rule_parse (connection, &str, error);
758 /* Send the ack before we remove the rule, since the ack is undone
759 * on transaction cancel, but rule removal isn't.
761 if (!send_ack_reply (connection, transaction,
765 matchmaker = bus_connection_get_matchmaker (connection);
767 if (!bus_matchmaker_remove_rule_by_value (matchmaker, rule, error))
770 bus_match_rule_unref (rule);
775 _DBUS_ASSERT_ERROR_IS_SET (error);
777 bus_match_rule_unref (rule);
782 bus_driver_handle_get_service_owner (DBusConnection *connection,
783 BusTransaction *transaction,
784 DBusMessage *message,
788 const char *base_name;
790 BusRegistry *registry;
794 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
796 registry = bus_connection_get_registry (connection);
801 if (! dbus_message_get_args (message, error,
802 DBUS_TYPE_STRING, &text,
806 _dbus_string_init_const (&str, text);
807 service = bus_registry_lookup (registry, &str);
808 if (service == NULL &&
809 _dbus_string_equal_c_str (&str, DBUS_SERVICE_DBUS))
811 /* ORG_FREEDESKTOP_DBUS owns itself */
812 base_name = DBUS_SERVICE_DBUS;
814 else if (service == NULL)
816 dbus_set_error (error,
817 DBUS_ERROR_NAME_HAS_NO_OWNER,
818 "Could not get owner of name '%s': no such name", text);
823 base_name = bus_connection_get_name (bus_service_get_primary_owner (service));
824 if (base_name == NULL)
826 /* FIXME - how is this error possible? */
827 dbus_set_error (error,
829 "Could not determine unique name for '%s'", text);
832 _dbus_assert (*base_name == ':');
835 _dbus_assert (base_name != NULL);
837 reply = dbus_message_new_method_return (message);
841 if (! dbus_message_append_args (reply,
842 DBUS_TYPE_STRING, &base_name,
846 if (! bus_transaction_send_from_driver (transaction, connection, reply))
849 dbus_message_unref (reply);
857 _DBUS_ASSERT_ERROR_IS_SET (error);
859 dbus_message_unref (reply);
864 bus_driver_handle_get_connection_unix_user (DBusConnection *connection,
865 BusTransaction *transaction,
866 DBusMessage *message,
871 BusRegistry *registry;
873 DBusConnection *conn;
878 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
880 registry = bus_connection_get_registry (connection);
885 if (! dbus_message_get_args (message, error,
886 DBUS_TYPE_STRING, &service,
890 _dbus_verbose ("asked for UID of connection %s\n", service);
892 _dbus_string_init_const (&str, service);
893 serv = bus_registry_lookup (registry, &str);
896 dbus_set_error (error,
897 DBUS_ERROR_NAME_HAS_NO_OWNER,
898 "Could not get UID of name '%s': no such name", service);
902 conn = bus_service_get_primary_owner (serv);
904 reply = dbus_message_new_method_return (message);
908 if (!dbus_connection_get_unix_user (conn, &uid))
910 dbus_set_error (error,
912 "Could not determine UID for '%s'", service);
917 if (! dbus_message_append_args (reply,
918 DBUS_TYPE_UINT32, &uid32,
922 if (! bus_transaction_send_from_driver (transaction, connection, reply))
925 dbus_message_unref (reply);
933 _DBUS_ASSERT_ERROR_IS_SET (error);
935 dbus_message_unref (reply);
940 bus_driver_handle_get_connection_unix_process_id (DBusConnection *connection,
941 BusTransaction *transaction,
942 DBusMessage *message,
947 BusRegistry *registry;
949 DBusConnection *conn;
954 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
956 registry = bus_connection_get_registry (connection);
961 if (! dbus_message_get_args (message, error,
962 DBUS_TYPE_STRING, &service,
966 _dbus_verbose ("asked for PID of connection %s\n", service);
968 _dbus_string_init_const (&str, service);
969 serv = bus_registry_lookup (registry, &str);
972 dbus_set_error (error,
973 DBUS_ERROR_NAME_HAS_NO_OWNER,
974 "Could not get PID of name '%s': no such name", service);
978 conn = bus_service_get_primary_owner (serv);
980 reply = dbus_message_new_method_return (message);
984 if (!dbus_connection_get_unix_process_id (conn, &pid))
986 dbus_set_error (error,
987 DBUS_ERROR_UNIX_PROCESS_ID_UNKNOWN,
988 "Could not determine PID for '%s'", service);
993 if (! dbus_message_append_args (reply,
994 DBUS_TYPE_UINT32, &pid32,
998 if (! bus_transaction_send_from_driver (transaction, connection, reply))
1001 dbus_message_unref (reply);
1006 BUS_SET_OOM (error);
1009 _DBUS_ASSERT_ERROR_IS_SET (error);
1011 dbus_message_unref (reply);
1016 bus_driver_handle_reload_config (DBusConnection *connection,
1017 BusTransaction *transaction,
1018 DBusMessage *message,
1021 BusContext *context;
1024 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1028 context = bus_connection_get_context (connection);
1029 if (!bus_context_reload_config (context, error))
1031 _DBUS_ASSERT_ERROR_IS_SET (error);
1041 /* For speed it might be useful to sort this in order of
1042 * frequency of use (but doesn't matter with only a few items
1048 const char *in_args;
1049 const char *out_args;
1050 dbus_bool_t (* handler) (DBusConnection *connection,
1051 BusTransaction *transaction,
1052 DBusMessage *message,
1054 } message_handlers[] = {
1056 DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING,
1057 DBUS_TYPE_UINT32_AS_STRING,
1058 bus_driver_handle_acquire_service },
1059 { "StartServiceByName",
1060 DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING,
1061 DBUS_TYPE_UINT32_AS_STRING,
1062 bus_driver_handle_activate_service },
1065 DBUS_TYPE_STRING_AS_STRING,
1066 bus_driver_handle_hello },
1068 DBUS_TYPE_STRING_AS_STRING,
1069 DBUS_TYPE_BOOLEAN_AS_STRING,
1070 bus_driver_handle_service_exists },
1073 DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING,
1074 bus_driver_handle_list_services },
1076 DBUS_TYPE_STRING_AS_STRING,
1078 bus_driver_handle_add_match },
1080 DBUS_TYPE_STRING_AS_STRING,
1082 bus_driver_handle_remove_match },
1084 DBUS_TYPE_STRING_AS_STRING,
1085 DBUS_TYPE_STRING_AS_STRING,
1086 bus_driver_handle_get_service_owner },
1087 { "GetConnectionUnixUser",
1088 DBUS_TYPE_STRING_AS_STRING,
1089 DBUS_TYPE_UINT32_AS_STRING,
1090 bus_driver_handle_get_connection_unix_user },
1091 { "GetConnectionUnixProcessID",
1092 DBUS_TYPE_STRING_AS_STRING,
1093 DBUS_TYPE_UINT32_AS_STRING,
1094 bus_driver_handle_get_connection_unix_process_id },
1098 bus_driver_handle_reload_config }
1102 bus_driver_handle_introspect (DBusConnection *connection,
1103 BusTransaction *transaction,
1104 DBusMessage *message,
1109 const char *v_STRING;
1112 _dbus_verbose ("Introspect() on bus driver\n");
1114 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1118 if (! dbus_message_get_args (message, error,
1121 _DBUS_ASSERT_ERROR_IS_SET (error);
1125 if (!_dbus_string_init (&xml))
1127 BUS_SET_OOM (error);
1131 if (!_dbus_string_append (&xml, DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE))
1133 if (!_dbus_string_append (&xml, "<node>\n"))
1135 if (!_dbus_string_append_printf (&xml, " <interface name=\"%s\">\n", DBUS_INTERFACE_INTROSPECTABLE))
1137 if (!_dbus_string_append (&xml, " <method name=\"Introspect\">\n"))
1139 if (!_dbus_string_append_printf (&xml, " <arg name=\"data\" direction=\"out\" type=\"%s\"/>\n", DBUS_TYPE_STRING_AS_STRING))
1141 if (!_dbus_string_append (&xml, " </method>\n"))
1143 if (!_dbus_string_append (&xml, " </interface>\n"))
1146 if (!_dbus_string_append_printf (&xml, " <interface name=\"%s\">\n",
1147 DBUS_INTERFACE_DBUS))
1151 while (i < _DBUS_N_ELEMENTS (message_handlers))
1153 if (!_dbus_string_append_printf (&xml, " <method name=\"%s\">\n",
1154 message_handlers[i].name))
1157 /* This hacky mess can probably get mopped up eventually when the
1158 * introspection format is related to the signature format
1161 if (strcmp (message_handlers[i].in_args, "") == 0)
1163 else if (strcmp (message_handlers[i].in_args,
1164 DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING) == 0)
1166 if (!_dbus_string_append_printf (&xml, " <arg direction=\"in\" type=\"%s\"/>\n", DBUS_TYPE_STRING_AS_STRING))
1168 if (!_dbus_string_append_printf (&xml, " <arg direction=\"in\" type=\"%s\"/>\n", DBUS_TYPE_UINT32_AS_STRING))
1171 else if (strcmp (message_handlers[i].in_args,
1172 DBUS_TYPE_STRING_AS_STRING) == 0)
1174 if (!_dbus_string_append_printf (&xml, " <arg direction=\"in\" type=\"%s\"/>\n", DBUS_TYPE_STRING_AS_STRING))
1179 _dbus_warn ("Lack introspection code for in sig '%s'\n",
1180 message_handlers[i].in_args);
1181 _dbus_assert_not_reached ("FIXME introspection missing");
1184 if (strcmp (message_handlers[i].out_args, "") == 0)
1186 else if (strcmp (message_handlers[i].out_args,
1187 DBUS_TYPE_STRING_AS_STRING) == 0)
1189 if (!_dbus_string_append_printf (&xml, " <arg direction=\"out\" type=\"%s\"/>\n", DBUS_TYPE_STRING_AS_STRING))
1192 else if (strcmp (message_handlers[i].out_args,
1193 DBUS_TYPE_BOOLEAN_AS_STRING) == 0)
1195 if (!_dbus_string_append_printf (&xml, " <arg direction=\"out\" type=\"%s\"/>\n", DBUS_TYPE_BOOLEAN_AS_STRING))
1198 else if (strcmp (message_handlers[i].out_args,
1199 DBUS_TYPE_UINT32_AS_STRING) == 0)
1201 if (!_dbus_string_append_printf (&xml, " <arg direction=\"out\" type=\"%s\"/>\n", DBUS_TYPE_UINT32_AS_STRING))
1204 else if (strcmp (message_handlers[i].out_args,
1205 DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING) == 0)
1207 /* FIXME introspection format doesn't handle arrays yet */
1208 if (!_dbus_string_append_printf (&xml, " <arg direction=\"out\" type=\"%s\"/>\n", DBUS_TYPE_STRING_AS_STRING))
1213 _dbus_warn ("Lack introspection code for out sig '%s'\n",
1214 message_handlers[i].out_args);
1215 _dbus_assert_not_reached ("FIXME introspection missing");
1218 if (!_dbus_string_append (&xml, " </method>\n"))
1224 if (!_dbus_string_append (&xml, " </interface>\n"))
1227 if (!_dbus_string_append (&xml, "</node>\n"))
1230 reply = dbus_message_new_method_return (message);
1234 v_STRING = _dbus_string_get_const_data (&xml);
1235 if (! dbus_message_append_args (reply,
1236 DBUS_TYPE_STRING, &v_STRING,
1240 if (! bus_transaction_send_from_driver (transaction, connection, reply))
1243 dbus_message_unref (reply);
1244 _dbus_string_free (&xml);
1249 BUS_SET_OOM (error);
1252 dbus_message_unref (reply);
1254 _dbus_string_free (&xml);
1260 bus_driver_handle_message (DBusConnection *connection,
1261 BusTransaction *transaction,
1262 DBusMessage *message,
1265 const char *name, *sender, *interface;
1268 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1270 if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_METHOD_CALL)
1272 _dbus_verbose ("Driver got a non-method-call message, ignoring\n");
1273 return TRUE; /* we just ignore this */
1276 if (dbus_message_is_method_call (message,
1277 DBUS_INTERFACE_INTROSPECTABLE,
1279 return bus_driver_handle_introspect (connection, transaction, message, error);
1281 interface = dbus_message_get_interface (message);
1282 if (interface == NULL)
1283 interface = DBUS_INTERFACE_DBUS;
1285 _dbus_assert (dbus_message_get_member (message) != NULL);
1287 name = dbus_message_get_member (message);
1288 sender = dbus_message_get_sender (message);
1290 if (strcmp (interface,
1291 DBUS_INTERFACE_DBUS) != 0)
1293 _dbus_verbose ("Driver got message to unknown interface \"%s\"\n",
1298 _dbus_verbose ("Driver got a method call: %s\n",
1299 dbus_message_get_member (message));
1301 /* security checks should have kept this from getting here */
1302 _dbus_assert (sender != NULL || strcmp (name, "Hello") == 0);
1305 while (i < _DBUS_N_ELEMENTS (message_handlers))
1307 if (strcmp (message_handlers[i].name, name) == 0)
1309 _dbus_verbose ("Found driver handler for %s\n", name);
1311 if (!dbus_message_has_signature (message, message_handlers[i].in_args))
1313 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1314 _dbus_verbose ("Call to %s has wrong args (%s, expected %s)\n",
1315 name, dbus_message_get_signature (message),
1316 message_handlers[i].in_args);
1318 dbus_set_error (error, DBUS_ERROR_INVALID_ARGS,
1319 "Call to %s has wrong args (%s, expected %s)\n",
1320 name, dbus_message_get_signature (message),
1321 message_handlers[i].in_args);
1322 _DBUS_ASSERT_ERROR_IS_SET (error);
1326 if ((* message_handlers[i].handler) (connection, transaction, message, error))
1328 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1329 _dbus_verbose ("Driver handler succeeded\n");
1334 _DBUS_ASSERT_ERROR_IS_SET (error);
1335 _dbus_verbose ("Driver handler returned failure\n");
1344 _dbus_verbose ("No driver handler for message \"%s\"\n",
1347 dbus_set_error (error, DBUS_ERROR_UNKNOWN_METHOD,
1348 "%s does not understand message %s",
1349 DBUS_SERVICE_DBUS, name);
1355 bus_driver_remove_connection (DBusConnection *connection)
1357 /* FIXME Does nothing for now, should unregister the connection
1358 * with the bus driver.