dbus/bus driver.c,1.63,1.64

Havoc Pennington hp at freedesktop.org
Sat Feb 12 09:13:15 PST 2005


Update of /cvs/dbus/dbus/bus
In directory gabe:/tmp/cvs-serv24066/bus

Modified Files:
	driver.c 
Log Message:
2005-02-12  Havoc Pennington  <hp at redhat.com>

	* bus/driver.c: put the signature of each bus driver method in the
	table of handlers and check it on incoming calls; this isn't
	really useful, but going to add introspect support in a minute.



Index: driver.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/driver.c,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -d -r1.63 -r1.64
--- driver.c	30 Jan 2005 07:44:08 -0000	1.63
+++ driver.c	12 Feb 2005 17:13:13 -0000	1.64
@@ -2,7 +2,7 @@
 /* driver.c  Bus client (driver)
  *
  * Copyright (C) 2003 CodeFactory AB
- * Copyright (C) 2003, 2004 Red Hat, Inc.
+ * Copyright (C) 2003, 2004, 2005 Red Hat, Inc.
  *
  * Licensed under the Academic Free License version 2.1
  * 
@@ -350,7 +350,7 @@
       return FALSE;
     }
 
-  _dbus_assert (dbus_message_has_signature (welcome, "s"));
+  _dbus_assert (dbus_message_has_signature (welcome, DBUS_TYPE_STRING_AS_STRING));
   
   if (!bus_transaction_send_from_driver (transaction, connection, welcome))
     {
@@ -1032,22 +1032,57 @@
 struct
 {
   const char *name;
+  const char *in_args;
+  const char *out_args;
   dbus_bool_t (* handler) (DBusConnection *connection,
                            BusTransaction *transaction,
                            DBusMessage    *message,
                            DBusError      *error);
 } message_handlers[] = {
-  { "RequestName", bus_driver_handle_acquire_service },
-  { "StartServiceByName", bus_driver_handle_activate_service },
-  { "Hello", bus_driver_handle_hello },
-  { "NameHasOwner", bus_driver_handle_service_exists },
-  { "ListNames", bus_driver_handle_list_services },
-  { "AddMatch", bus_driver_handle_add_match },
-  { "RemoveMatch", bus_driver_handle_remove_match },
-  { "GetNameOwner", bus_driver_handle_get_service_owner },
-  { "GetConnectionUnixUser", bus_driver_handle_get_connection_unix_user },
-  { "GetConnectionUnixProcessID", bus_driver_handle_get_connection_unix_process_id },
-  { "ReloadConfig", bus_driver_handle_reload_config }
+  { "RequestName",
+    DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING,
+    DBUS_TYPE_UINT32_AS_STRING,
+    bus_driver_handle_acquire_service },
+  { "StartServiceByName",
+    DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING,
+    DBUS_TYPE_UINT32_AS_STRING,
+    bus_driver_handle_activate_service },
+  { "Hello",
+    "",
+    DBUS_TYPE_STRING_AS_STRING,
+    bus_driver_handle_hello },
+  { "NameHasOwner",
+    DBUS_TYPE_STRING_AS_STRING,
+    DBUS_TYPE_BOOLEAN_AS_STRING,
+    bus_driver_handle_service_exists },
+  { "ListNames",
+    "",
+    DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING,
+    bus_driver_handle_list_services },
+  { "AddMatch",
+    DBUS_TYPE_STRING_AS_STRING,
+    "",
+    bus_driver_handle_add_match },
+  { "RemoveMatch",
+    DBUS_TYPE_STRING_AS_STRING,
+    "",
+    bus_driver_handle_remove_match },
+  { "GetNameOwner",
+    DBUS_TYPE_STRING_AS_STRING,
+    DBUS_TYPE_STRING_AS_STRING,
+    bus_driver_handle_get_service_owner },
+  { "GetConnectionUnixUser",
+    DBUS_TYPE_STRING_AS_STRING,
+    DBUS_TYPE_UINT32_AS_STRING,
+    bus_driver_handle_get_connection_unix_user },
+  { "GetConnectionUnixProcessID",
+    DBUS_TYPE_STRING_AS_STRING,
+    DBUS_TYPE_UINT32_AS_STRING,
+    bus_driver_handle_get_connection_unix_process_id },
+  { "ReloadConfig",
+    "",
+    "",
+    bus_driver_handle_reload_config }
 };
 
 static dbus_bool_t
@@ -1176,7 +1211,23 @@
     {
       if (strcmp (message_handlers[i].name, name) == 0)
         {
-          _dbus_verbose ("Running driver handler for %s\n", name);
+          _dbus_verbose ("Found driver handler for %s\n", name);
+
+          if (!dbus_message_has_signature (message, message_handlers[i].in_args))
+            {
+              _DBUS_ASSERT_ERROR_IS_CLEAR (error);
+              _dbus_verbose ("Call to %s has wrong args (%s, expected %s)\n",
+                             name, dbus_message_get_signature (message),
+                             message_handlers[i].in_args);
+              
+              dbus_set_error (error, DBUS_ERROR_INVALID_ARGS,
+                              "Call to %s has wrong args (%s, expected %s)\n",
+                              name, dbus_message_get_signature (message),
+                              message_handlers[i].in_args);
+              _DBUS_ASSERT_ERROR_IS_SET (error);
+              return FALSE;
+            }
+          
           if ((* message_handlers[i].handler) (connection, transaction, message, error))
             {
               _DBUS_ASSERT_ERROR_IS_CLEAR (error);



More information about the dbus-commit mailing list