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_ORG_FREEDESKTOP_DBUS,
61 DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
70 if (!dbus_message_set_sender (message, DBUS_SERVICE_ORG_FREEDESKTOP_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_ORG_FREEDESKTOP_DBUS,
104 DBUS_INTERFACE_ORG_FREEDESKTOP_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_ORG_FREEDESKTOP_DBUS,
147 DBUS_INTERFACE_ORG_FREEDESKTOP_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);
415 if (!dbus_message_iter_append_basic (&sub, DBUS_TYPE_STRING,
418 dbus_free_string_array (services);
419 dbus_message_unref (reply);
426 if (!dbus_message_iter_close_container (&iter, &sub))
428 dbus_free_string_array (services);
429 dbus_message_unref (reply);
434 dbus_free_string_array (services);
436 if (!bus_transaction_send_from_driver (transaction, connection, reply))
438 dbus_message_unref (reply);
444 dbus_message_unref (reply);
450 bus_driver_handle_acquire_service (DBusConnection *connection,
451 BusTransaction *transaction,
452 DBusMessage *message,
456 DBusString service_name;
461 BusRegistry *registry;
463 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
465 registry = bus_connection_get_registry (connection);
467 if (!dbus_message_get_args (message, error,
468 DBUS_TYPE_STRING, &name,
469 DBUS_TYPE_UINT32, &flags,
473 _dbus_verbose ("Trying to own name %s with flags 0x%x\n", name, flags);
478 _dbus_string_init_const (&service_name, name);
480 if (!bus_registry_acquire_service (registry, connection,
481 &service_name, flags,
482 &service_reply, transaction,
486 reply = dbus_message_new_method_return (message);
493 if (!dbus_message_append_args (reply, DBUS_TYPE_UINT32, &service_reply, DBUS_TYPE_INVALID))
499 if (!bus_transaction_send_from_driver (transaction, connection, reply))
509 dbus_message_unref (reply);
514 bus_driver_handle_service_exists (DBusConnection *connection,
515 BusTransaction *transaction,
516 DBusMessage *message,
520 DBusString service_name;
522 dbus_bool_t service_exists;
525 BusRegistry *registry;
527 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
529 registry = bus_connection_get_registry (connection);
531 if (!dbus_message_get_args (message, error,
532 DBUS_TYPE_STRING, &name,
538 if (strcmp (name, DBUS_SERVICE_ORG_FREEDESKTOP_DBUS) == 0)
540 service_exists = TRUE;
544 _dbus_string_init_const (&service_name, name);
545 service = bus_registry_lookup (registry, &service_name);
546 service_exists = service != NULL;
549 reply = dbus_message_new_method_return (message);
556 if (!dbus_message_append_args (reply,
557 DBUS_TYPE_BOOLEAN, &service_exists,
564 if (!bus_transaction_send_from_driver (transaction, connection, reply))
574 dbus_message_unref (reply);
580 bus_driver_handle_activate_service (DBusConnection *connection,
581 BusTransaction *transaction,
582 DBusMessage *message,
588 BusActivation *activation;
590 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
592 activation = bus_connection_get_activation (connection);
594 if (!dbus_message_get_args (message, error,
595 DBUS_TYPE_STRING, &name,
596 DBUS_TYPE_UINT32, &flags,
599 _DBUS_ASSERT_ERROR_IS_SET (error);
600 _dbus_verbose ("No memory to get arguments to StartServiceByName\n");
606 if (!bus_activation_activate_service (activation, connection, transaction, FALSE,
607 message, name, error))
609 _DBUS_ASSERT_ERROR_IS_SET (error);
610 _dbus_verbose ("bus_activation_activate_service() failed\n");
621 send_ack_reply (DBusConnection *connection,
622 BusTransaction *transaction,
623 DBusMessage *message,
628 reply = dbus_message_new_method_return (message);
635 if (!bus_transaction_send_from_driver (transaction, connection, reply))
638 dbus_message_unref (reply);
642 dbus_message_unref (reply);
648 bus_driver_handle_add_match (DBusConnection *connection,
649 BusTransaction *transaction,
650 DBusMessage *message,
656 BusMatchmaker *matchmaker;
658 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
663 if (bus_connection_get_n_match_rules (connection) >=
664 bus_context_get_max_match_rules_per_connection (bus_transaction_get_context (transaction)))
666 dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
667 "Connection \"%s\" is not allowed to add more match rules "
668 "(increase limits in configuration file if required)",
669 bus_connection_is_active (connection) ?
670 bus_connection_get_name (connection) :
675 if (!dbus_message_get_args (message, error,
676 DBUS_TYPE_STRING, &text,
679 _dbus_verbose ("No memory to get arguments to AddMatch\n");
683 _dbus_string_init_const (&str, text);
685 rule = bus_match_rule_parse (connection, &str, error);
689 matchmaker = bus_connection_get_matchmaker (connection);
691 if (!bus_matchmaker_add_rule (matchmaker, rule))
697 if (!send_ack_reply (connection, transaction,
700 bus_matchmaker_remove_rule (matchmaker, rule);
704 bus_match_rule_unref (rule);
709 _DBUS_ASSERT_ERROR_IS_SET (error);
711 bus_match_rule_unref (rule);
716 bus_driver_handle_remove_match (DBusConnection *connection,
717 BusTransaction *transaction,
718 DBusMessage *message,
724 BusMatchmaker *matchmaker;
726 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
731 if (!dbus_message_get_args (message, error,
732 DBUS_TYPE_STRING, &text,
735 _dbus_verbose ("No memory to get arguments to RemoveMatch\n");
739 _dbus_string_init_const (&str, text);
741 rule = bus_match_rule_parse (connection, &str, error);
745 /* Send the ack before we remove the rule, since the ack is undone
746 * on transaction cancel, but rule removal isn't.
748 if (!send_ack_reply (connection, transaction,
752 matchmaker = bus_connection_get_matchmaker (connection);
754 if (!bus_matchmaker_remove_rule_by_value (matchmaker, rule, error))
757 bus_match_rule_unref (rule);
762 _DBUS_ASSERT_ERROR_IS_SET (error);
764 bus_match_rule_unref (rule);
769 bus_driver_handle_get_service_owner (DBusConnection *connection,
770 BusTransaction *transaction,
771 DBusMessage *message,
775 const char *base_name;
777 BusRegistry *registry;
781 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
783 registry = bus_connection_get_registry (connection);
788 if (! dbus_message_get_args (message, error,
789 DBUS_TYPE_STRING, &text,
793 _dbus_string_init_const (&str, text);
794 service = bus_registry_lookup (registry, &str);
795 if (service == NULL &&
796 _dbus_string_equal_c_str (&str, DBUS_SERVICE_ORG_FREEDESKTOP_DBUS))
798 /* ORG_FREEDESKTOP_DBUS owns itself */
799 base_name = DBUS_SERVICE_ORG_FREEDESKTOP_DBUS;
801 else if (service == NULL)
803 dbus_set_error (error,
804 DBUS_ERROR_NAME_HAS_NO_OWNER,
805 "Could not get owner of name '%s': no such name", text);
810 base_name = bus_connection_get_name (bus_service_get_primary_owner (service));
811 if (base_name == NULL)
813 /* FIXME - how is this error possible? */
814 dbus_set_error (error,
816 "Could not determine unique name for '%s'", text);
819 _dbus_assert (*base_name == ':');
822 _dbus_assert (base_name != NULL);
824 reply = dbus_message_new_method_return (message);
828 if (! dbus_message_append_args (reply,
829 DBUS_TYPE_STRING, &base_name,
833 if (! bus_transaction_send_from_driver (transaction, connection, reply))
836 dbus_message_unref (reply);
844 _DBUS_ASSERT_ERROR_IS_SET (error);
846 dbus_message_unref (reply);
851 bus_driver_handle_get_connection_unix_user (DBusConnection *connection,
852 BusTransaction *transaction,
853 DBusMessage *message,
858 BusRegistry *registry;
860 DBusConnection *conn;
865 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
867 registry = bus_connection_get_registry (connection);
872 if (! dbus_message_get_args (message, error,
873 DBUS_TYPE_STRING, &service,
877 _dbus_verbose ("asked for UID of connection %s\n", service);
879 _dbus_string_init_const (&str, service);
880 serv = bus_registry_lookup (registry, &str);
883 dbus_set_error (error,
884 DBUS_ERROR_NAME_HAS_NO_OWNER,
885 "Could not get UID of name '%s': no such name", service);
889 conn = bus_service_get_primary_owner (serv);
891 reply = dbus_message_new_method_return (message);
895 if (!dbus_connection_get_unix_user (conn, &uid))
897 dbus_set_error (error,
899 "Could not determine UID for '%s'", service);
904 if (! dbus_message_append_args (reply,
905 DBUS_TYPE_UINT32, &uid32,
909 if (! bus_transaction_send_from_driver (transaction, connection, reply))
912 dbus_message_unref (reply);
920 _DBUS_ASSERT_ERROR_IS_SET (error);
922 dbus_message_unref (reply);
927 bus_driver_handle_get_connection_unix_process_id (DBusConnection *connection,
928 BusTransaction *transaction,
929 DBusMessage *message,
934 BusRegistry *registry;
936 DBusConnection *conn;
941 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
943 registry = bus_connection_get_registry (connection);
948 if (! dbus_message_get_args (message, error,
949 DBUS_TYPE_STRING, &service,
953 _dbus_verbose ("asked for PID of connection %s\n", service);
955 _dbus_string_init_const (&str, service);
956 serv = bus_registry_lookup (registry, &str);
959 dbus_set_error (error,
960 DBUS_ERROR_NAME_HAS_NO_OWNER,
961 "Could not get PID of name '%s': no such name", service);
965 conn = bus_service_get_primary_owner (serv);
967 reply = dbus_message_new_method_return (message);
971 if (!dbus_connection_get_unix_process_id (conn, &pid))
973 dbus_set_error (error,
974 DBUS_ERROR_UNIX_PROCESS_ID_UNKNOWN,
975 "Could not determine PID for '%s'", service);
980 if (! dbus_message_append_args (reply,
981 DBUS_TYPE_UINT32, &pid32,
985 if (! bus_transaction_send_from_driver (transaction, connection, reply))
988 dbus_message_unref (reply);
996 _DBUS_ASSERT_ERROR_IS_SET (error);
998 dbus_message_unref (reply);
1003 bus_driver_handle_reload_config (DBusConnection *connection,
1004 BusTransaction *transaction,
1005 DBusMessage *message,
1008 BusContext *context;
1011 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1015 context = bus_connection_get_context (connection);
1016 if (!bus_context_reload_config (context, error))
1018 _DBUS_ASSERT_ERROR_IS_SET (error);
1028 /* For speed it might be useful to sort this in order of
1029 * frequency of use (but doesn't matter with only a few items
1035 const char *in_args;
1036 const char *out_args;
1037 dbus_bool_t (* handler) (DBusConnection *connection,
1038 BusTransaction *transaction,
1039 DBusMessage *message,
1041 } message_handlers[] = {
1043 DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING,
1044 DBUS_TYPE_UINT32_AS_STRING,
1045 bus_driver_handle_acquire_service },
1046 { "StartServiceByName",
1047 DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING,
1048 DBUS_TYPE_UINT32_AS_STRING,
1049 bus_driver_handle_activate_service },
1052 DBUS_TYPE_STRING_AS_STRING,
1053 bus_driver_handle_hello },
1055 DBUS_TYPE_STRING_AS_STRING,
1056 DBUS_TYPE_BOOLEAN_AS_STRING,
1057 bus_driver_handle_service_exists },
1060 DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING,
1061 bus_driver_handle_list_services },
1063 DBUS_TYPE_STRING_AS_STRING,
1065 bus_driver_handle_add_match },
1067 DBUS_TYPE_STRING_AS_STRING,
1069 bus_driver_handle_remove_match },
1071 DBUS_TYPE_STRING_AS_STRING,
1072 DBUS_TYPE_STRING_AS_STRING,
1073 bus_driver_handle_get_service_owner },
1074 { "GetConnectionUnixUser",
1075 DBUS_TYPE_STRING_AS_STRING,
1076 DBUS_TYPE_UINT32_AS_STRING,
1077 bus_driver_handle_get_connection_unix_user },
1078 { "GetConnectionUnixProcessID",
1079 DBUS_TYPE_STRING_AS_STRING,
1080 DBUS_TYPE_UINT32_AS_STRING,
1081 bus_driver_handle_get_connection_unix_process_id },
1085 bus_driver_handle_reload_config }
1089 bus_driver_handle_introspect (DBusConnection *connection,
1090 BusTransaction *transaction,
1091 DBusMessage *message,
1096 const char *v_STRING;
1099 _dbus_verbose ("Introspect() on bus driver\n");
1101 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1105 if (! dbus_message_get_args (message, error,
1108 _DBUS_ASSERT_ERROR_IS_SET (error);
1112 if (!_dbus_string_init (&xml))
1114 BUS_SET_OOM (error);
1118 if (!_dbus_string_append (&xml, DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE))
1120 if (!_dbus_string_append (&xml, "<node>\n"))
1122 if (!_dbus_string_append (&xml, " <interface name=\"org.freedesktop.Introspectable\">\n"))
1124 if (!_dbus_string_append (&xml, " <method name=\"Introspect\">\n"))
1126 if (!_dbus_string_append (&xml, " <arg name=\"data\" direction=\"out\" type=\"string\"/>\n"))
1128 if (!_dbus_string_append (&xml, " </method>\n"))
1130 if (!_dbus_string_append (&xml, " </interface>\n"))
1133 if (!_dbus_string_append_printf (&xml, " <interface name=\"%s\">\n",
1134 DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS))
1138 while (i < _DBUS_N_ELEMENTS (message_handlers))
1140 if (!_dbus_string_append_printf (&xml, " <method name=\"%s\">\n",
1141 message_handlers[i].name))
1144 /* This hacky mess can probably get mopped up eventually when the
1145 * introspection format is related to the signature format
1148 if (strcmp (message_handlers[i].in_args, "") == 0)
1150 else if (strcmp (message_handlers[i].in_args,
1151 DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING) == 0)
1153 if (!_dbus_string_append (&xml, " <arg direction=\"in\" type=\"string\"/>\n"))
1155 if (!_dbus_string_append (&xml, " <arg direction=\"in\" type=\"uint32\"/>\n"))
1158 else if (strcmp (message_handlers[i].in_args,
1159 DBUS_TYPE_STRING_AS_STRING) == 0)
1161 if (!_dbus_string_append (&xml, " <arg direction=\"in\" type=\"string\"/>\n"))
1166 _dbus_warn ("Lack introspection code for in sig '%s'\n",
1167 message_handlers[i].in_args);
1168 _dbus_assert_not_reached ("FIXME introspection missing");
1171 if (strcmp (message_handlers[i].out_args, "") == 0)
1173 else if (strcmp (message_handlers[i].out_args,
1174 DBUS_TYPE_STRING_AS_STRING) == 0)
1176 if (!_dbus_string_append (&xml, " <arg direction=\"out\" type=\"string\"/>\n"))
1179 else if (strcmp (message_handlers[i].out_args,
1180 DBUS_TYPE_BOOLEAN_AS_STRING) == 0)
1182 if (!_dbus_string_append (&xml, " <arg direction=\"out\" type=\"boolean\"/>\n"))
1185 else if (strcmp (message_handlers[i].out_args,
1186 DBUS_TYPE_UINT32_AS_STRING) == 0)
1188 if (!_dbus_string_append (&xml, " <arg direction=\"out\" type=\"uint32\"/>\n"))
1191 else if (strcmp (message_handlers[i].out_args,
1192 DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING) == 0)
1194 /* FIXME introspection format doesn't handle arrays yet */
1195 if (!_dbus_string_append (&xml, " <arg direction=\"out\" type=\"string\"/>\n"))
1200 _dbus_warn ("Lack introspection code for out sig '%s'\n",
1201 message_handlers[i].out_args);
1202 _dbus_assert_not_reached ("FIXME introspection missing");
1205 if (!_dbus_string_append (&xml, " </method>\n"))
1211 if (!_dbus_string_append (&xml, " </interface>\n"))
1214 if (!_dbus_string_append (&xml, "</node>\n"))
1217 reply = dbus_message_new_method_return (message);
1221 v_STRING = _dbus_string_get_const_data (&xml);
1222 if (! dbus_message_append_args (reply,
1223 DBUS_TYPE_STRING, &v_STRING,
1227 if (! bus_transaction_send_from_driver (transaction, connection, reply))
1230 dbus_message_unref (reply);
1231 _dbus_string_free (&xml);
1236 BUS_SET_OOM (error);
1239 dbus_message_unref (reply);
1241 _dbus_string_free (&xml);
1247 bus_driver_handle_message (DBusConnection *connection,
1248 BusTransaction *transaction,
1249 DBusMessage *message,
1252 const char *name, *sender, *interface;
1255 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1257 if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_METHOD_CALL)
1259 _dbus_verbose ("Driver got a non-method-call message, ignoring\n");
1260 return TRUE; /* we just ignore this */
1263 if (dbus_message_is_method_call (message,
1264 DBUS_INTERFACE_ORG_FREEDESKTOP_INTROSPECTABLE,
1266 return bus_driver_handle_introspect (connection, transaction, message, error);
1268 interface = dbus_message_get_interface (message);
1269 if (interface == NULL)
1270 interface = DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS;
1272 _dbus_assert (dbus_message_get_member (message) != NULL);
1274 name = dbus_message_get_member (message);
1275 sender = dbus_message_get_sender (message);
1277 if (strcmp (interface,
1278 DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS) != 0)
1280 _dbus_verbose ("Driver got message to unknown interface \"%s\"\n",
1285 _dbus_verbose ("Driver got a method call: %s\n",
1286 dbus_message_get_member (message));
1288 /* security checks should have kept this from getting here */
1289 _dbus_assert (sender != NULL || strcmp (name, "Hello") == 0);
1292 while (i < _DBUS_N_ELEMENTS (message_handlers))
1294 if (strcmp (message_handlers[i].name, name) == 0)
1296 _dbus_verbose ("Found driver handler for %s\n", name);
1298 if (!dbus_message_has_signature (message, message_handlers[i].in_args))
1300 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1301 _dbus_verbose ("Call to %s has wrong args (%s, expected %s)\n",
1302 name, dbus_message_get_signature (message),
1303 message_handlers[i].in_args);
1305 dbus_set_error (error, DBUS_ERROR_INVALID_ARGS,
1306 "Call to %s has wrong args (%s, expected %s)\n",
1307 name, dbus_message_get_signature (message),
1308 message_handlers[i].in_args);
1309 _DBUS_ASSERT_ERROR_IS_SET (error);
1313 if ((* message_handlers[i].handler) (connection, transaction, message, error))
1315 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1316 _dbus_verbose ("Driver handler succeeded\n");
1321 _DBUS_ASSERT_ERROR_IS_SET (error);
1322 _dbus_verbose ("Driver handler returned failure\n");
1331 _dbus_verbose ("No driver handler for message \"%s\"\n",
1334 dbus_set_error (error, DBUS_ERROR_UNKNOWN_METHOD,
1335 "%s does not understand message %s",
1336 DBUS_SERVICE_ORG_FREEDESKTOP_DBUS, name);
1342 bus_driver_remove_connection (DBusConnection *connection)
1344 /* FIXME Does nothing for now, should unregister the connection
1345 * with the bus driver.