summaryrefslogtreecommitdiff
path: root/bus
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2011-03-14 11:53:09 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2011-03-14 11:53:09 +0000
commit2adf484fb39853bfc4bc9a43fb73d0fc935e92c9 (patch)
tree326b92827be4104196d956d41e8263d8e58c5661 /bus
parent2c34514620c4b79ea4ec71d1db583379138d01ac (diff)
Revert merge of master (dbus-1.5) into dbus-1.4
This reverts commits d1d395774435..09c9d6406b75f, keeping Lennart's addition of UnknownInterface etc.
Diffstat (limited to 'bus')
-rw-r--r--bus/driver.c179
1 files changed, 98 insertions, 81 deletions
diff --git a/bus/driver.c b/bus/driver.c
index 1e9573ee..cc8d1f26 100644
--- a/bus/driver.c
+++ b/bus/driver.c
@@ -1644,7 +1644,11 @@ bus_driver_handle_get_id (DBusConnection *connection,
return FALSE;
}
-typedef struct
+/* For speed it might be useful to sort this in order of
+ * frequency of use (but doesn't matter with only a few items
+ * anyhow)
+ */
+static struct
{
const char *name;
const char *in_args;
@@ -1653,13 +1657,7 @@ typedef struct
BusTransaction *transaction,
DBusMessage *message,
DBusError *error);
-} MessageHandler;
-
-/* For speed it might be useful to sort this in order of
- * frequency of use (but doesn't matter with only a few items
- * anyhow)
- */
-static const MessageHandler dbus_message_handlers[] = {
+} message_handlers[] = {
{ "Hello",
"",
DBUS_TYPE_STRING_AS_STRING,
@@ -1731,41 +1729,7 @@ static const MessageHandler dbus_message_handlers[] = {
{ "GetId",
"",
DBUS_TYPE_STRING_AS_STRING,
- bus_driver_handle_get_id },
- { NULL, NULL, NULL, NULL }
-};
-
-static dbus_bool_t bus_driver_handle_introspect (DBusConnection *,
- BusTransaction *, DBusMessage *, DBusError *);
-
-static const MessageHandler introspectable_message_handlers[] = {
- { "Introspect", "", DBUS_TYPE_STRING_AS_STRING, bus_driver_handle_introspect },
- { NULL, NULL, NULL, NULL }
-};
-
-typedef struct {
- const char *name;
- const MessageHandler *message_handlers;
- const char *extra_introspection;
-} InterfaceHandler;
-
-/* These should ideally be sorted by frequency of use, although it
- * probably doesn't matter with this few items */
-static InterfaceHandler interface_handlers[] = {
- { DBUS_INTERFACE_DBUS, dbus_message_handlers,
- " <signal name=\"NameOwnerChanged\">\n"
- " <arg type=\"s\"/>\n"
- " <arg type=\"s\"/>\n"
- " <arg type=\"s\"/>\n"
- " </signal>\n"
- " <signal name=\"NameLost\">\n"
- " <arg type=\"s\"/>\n"
- " </signal>\n"
- " <signal name=\"NameAcquired\">\n"
- " <arg type=\"s\"/>\n"
- " </signal>\n" },
- { DBUS_INTERFACE_INTROSPECTABLE, introspectable_message_handlers, NULL },
- { NULL, NULL, NULL }
+ bus_driver_handle_get_id }
};
static dbus_bool_t
@@ -1806,43 +1770,86 @@ write_args_for_direction (DBusString *xml,
dbus_bool_t
bus_driver_generate_introspect_string (DBusString *xml)
{
- const InterfaceHandler *ih;
- const MessageHandler *mh;
+ int i;
if (!_dbus_string_append (xml, DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE))
return FALSE;
if (!_dbus_string_append (xml, "<node>\n"))
return FALSE;
+ if (!_dbus_string_append_printf (xml, " <interface name=\"%s\">\n", DBUS_INTERFACE_INTROSPECTABLE))
+ return FALSE;
+ if (!_dbus_string_append (xml, " <method name=\"Introspect\">\n"))
+ return FALSE;
+ if (!_dbus_string_append_printf (xml, " <arg name=\"data\" direction=\"out\" type=\"%s\"/>\n", DBUS_TYPE_STRING_AS_STRING))
+ return FALSE;
+ if (!_dbus_string_append (xml, " </method>\n"))
+ return FALSE;
+ if (!_dbus_string_append (xml, " </interface>\n"))
+ return FALSE;
+
+ if (!_dbus_string_append_printf (xml, " <interface name=\"%s\">\n",
+ DBUS_INTERFACE_DBUS))
+ return FALSE;
- for (ih = interface_handlers; ih->name != NULL; ih++)
+ i = 0;
+ while (i < _DBUS_N_ELEMENTS (message_handlers))
{
- if (!_dbus_string_append_printf (xml, " <interface name=\"%s\">\n",
- ih->name))
+
+ if (!_dbus_string_append_printf (xml, " <method name=\"%s\">\n",
+ message_handlers[i].name))
return FALSE;
- for (mh = ih->message_handlers; mh->name != NULL; mh++)
- {
- if (!_dbus_string_append_printf (xml, " <method name=\"%s\">\n",
- mh->name))
- return FALSE;
+ if (!write_args_for_direction (xml, message_handlers[i].in_args, TRUE))
+ return FALSE;
- if (!write_args_for_direction (xml, mh->in_args, TRUE))
- return FALSE;
+ if (!write_args_for_direction (xml, message_handlers[i].out_args, FALSE))
+ return FALSE;
- if (!write_args_for_direction (xml, mh->out_args, FALSE))
- return FALSE;
+ if (!_dbus_string_append (xml, " </method>\n"))
+ return FALSE;
- if (!_dbus_string_append (xml, " </method>\n"))
- return FALSE;
- }
+ ++i;
+ }
+
+ if (!_dbus_string_append_printf (xml, " <signal name=\"NameOwnerChanged\">\n"))
+ return FALSE;
+
+ if (!_dbus_string_append_printf (xml, " <arg type=\"s\"/>\n"))
+ return FALSE;
+
+ if (!_dbus_string_append_printf (xml, " <arg type=\"s\"/>\n"))
+ return FALSE;
+
+ if (!_dbus_string_append_printf (xml, " <arg type=\"s\"/>\n"))
+ return FALSE;
+
+ if (!_dbus_string_append_printf (xml, " </signal>\n"))
+ return FALSE;
- if (ih->extra_introspection != NULL &&
- !_dbus_string_append (xml, ih->extra_introspection))
- return FALSE;
- if (!_dbus_string_append (xml, " </interface>\n"))
- return FALSE;
- }
+
+ if (!_dbus_string_append_printf (xml, " <signal name=\"NameLost\">\n"))
+ return FALSE;
+
+ if (!_dbus_string_append_printf (xml, " <arg type=\"s\"/>\n"))
+ return FALSE;
+
+ if (!_dbus_string_append_printf (xml, " </signal>\n"))
+ return FALSE;
+
+
+
+ if (!_dbus_string_append_printf (xml, " <signal name=\"NameAcquired\">\n"))
+ return FALSE;
+
+ if (!_dbus_string_append_printf (xml, " <arg type=\"s\"/>\n"))
+ return FALSE;
+
+ if (!_dbus_string_append_printf (xml, " </signal>\n"))
+ return FALSE;
+
+ if (!_dbus_string_append (xml, " </interface>\n"))
+ return FALSE;
if (!_dbus_string_append (xml, "</node>\n"))
return FALSE;
@@ -1919,8 +1926,7 @@ bus_driver_handle_message (DBusConnection *connection,
DBusError *error)
{
const char *name, *sender, *interface;
- const InterfaceHandler *ih;
- const MessageHandler *mh;
+ int i;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
@@ -1938,48 +1944,57 @@ bus_driver_handle_message (DBusConnection *connection,
return TRUE; /* we just ignore this */
}
- /* may be NULL, which means "any interface will do" */
+ if (dbus_message_is_method_call (message,
+ DBUS_INTERFACE_INTROSPECTABLE,
+ "Introspect"))
+ return bus_driver_handle_introspect (connection, transaction, message, error);
+
interface = dbus_message_get_interface (message);
+ if (interface == NULL)
+ interface = DBUS_INTERFACE_DBUS;
_dbus_assert (dbus_message_get_member (message) != NULL);
name = dbus_message_get_member (message);
sender = dbus_message_get_sender (message);
+ if (strcmp (interface,
+ DBUS_INTERFACE_DBUS) != 0)
+ {
+ _dbus_verbose ("Driver got message to unknown interface \"%s\"\n",
+ interface);
+ goto unknown;
+ }
+
_dbus_verbose ("Driver got a method call: %s\n",
dbus_message_get_member (message));
/* security checks should have kept this from getting here */
_dbus_assert (sender != NULL || strcmp (name, "Hello") == 0);
- for (ih = interface_handlers; ih->name != NULL; ih++)
+ i = 0;
+ while (i < _DBUS_N_ELEMENTS (message_handlers))
{
- if (interface != NULL && strcmp (interface, ih->name) != 0)
- continue;
-
- for (mh = ih->message_handlers; mh->name != NULL; mh++)
+ if (strcmp (message_handlers[i].name, name) == 0)
{
- if (strcmp (mh->name, name) != 0)
- continue;
-
_dbus_verbose ("Found driver handler for %s\n", name);
- if (!dbus_message_has_signature (message, mh->in_args))
+ 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),
- mh->in_args);
+ 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),
- mh->in_args);
+ message_handlers[i].in_args);
_DBUS_ASSERT_ERROR_IS_SET (error);
return FALSE;
}
- if ((* mh->handler) (connection, transaction, message, error))
+ if ((* message_handlers[i].handler) (connection, transaction, message, error))
{
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
_dbus_verbose ("Driver handler succeeded\n");
@@ -1992,6 +2007,8 @@ bus_driver_handle_message (DBusConnection *connection,
return FALSE;
}
}
+
+ ++i;
}
unknown: