diff options
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | bus/driver.c | 165 | ||||
-rw-r--r-- | bus/driver.h | 3 | ||||
-rw-r--r-- | bus/main.c | 29 |
4 files changed, 131 insertions, 79 deletions
@@ -1,5 +1,18 @@ 2006-09-06 John (J5) Palmieri <johnp@redhat.com> + * bus/driver.c: + (bus_driver_generate_introspect_string): New method for populating + a DBusString with the introspect data + (bus_driver_handle_introspect): Move introspect generation code to + bus_driver_generate_introspect_string + + * bus/main.c: + (introspect): New function which prints out the intropect data and + exits + (main): Add a --introspect switch + +2006-09-06 John (J5) Palmieri <johnp@redhat.com> + * doc/TODO: Removed dtd publishing item. It seems the dtd has already been added at http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd diff --git a/bus/driver.c b/bus/driver.c index 1a2c050b..69084330 100644 --- a/bus/driver.c +++ b/bus/driver.c @@ -1493,125 +1493,134 @@ write_args_for_direction (DBusString *xml, return FALSE; } -static dbus_bool_t -bus_driver_handle_introspect (DBusConnection *connection, - BusTransaction *transaction, - DBusMessage *message, - DBusError *error) +dbus_bool_t +bus_driver_generate_introspect_string (DBusString *xml) { - DBusString xml; - DBusMessage *reply; - const char *v_STRING; int i; - _dbus_verbose ("Introspect() on bus driver\n"); - - _DBUS_ASSERT_ERROR_IS_CLEAR (error); - - reply = NULL; - - if (! dbus_message_get_args (message, error, - DBUS_TYPE_INVALID)) - { - _DBUS_ASSERT_ERROR_IS_SET (error); - return FALSE; - } - - if (!_dbus_string_init (&xml)) - { - BUS_SET_OOM (error); - return FALSE; - } - - if (!_dbus_string_append (&xml, DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE)) - goto oom; - if (!_dbus_string_append (&xml, "<node>\n")) - goto oom; - if (!_dbus_string_append_printf (&xml, " <interface name=\"%s\">\n", DBUS_INTERFACE_INTROSPECTABLE)) - goto oom; - if (!_dbus_string_append (&xml, " <method name=\"Introspect\">\n")) - goto oom; - if (!_dbus_string_append_printf (&xml, " <arg name=\"data\" direction=\"out\" type=\"%s\"/>\n", DBUS_TYPE_STRING_AS_STRING)) - goto oom; - if (!_dbus_string_append (&xml, " </method>\n")) - goto oom; - if (!_dbus_string_append (&xml, " </interface>\n")) - goto oom; + 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", + if (!_dbus_string_append_printf (xml, " <interface name=\"%s\">\n", DBUS_INTERFACE_DBUS)) - goto oom; + return FALSE; i = 0; while (i < _DBUS_N_ELEMENTS (message_handlers)) { - if (!_dbus_string_append_printf (&xml, " <method name=\"%s\">\n", + if (!_dbus_string_append_printf (xml, " <method name=\"%s\">\n", message_handlers[i].name)) - goto oom; + return FALSE; - if (!write_args_for_direction (&xml, message_handlers[i].in_args, TRUE)) - goto oom; + if (!write_args_for_direction (xml, message_handlers[i].in_args, TRUE)) + return FALSE; - if (!write_args_for_direction (&xml, message_handlers[i].out_args, FALSE)) - goto oom; + if (!write_args_for_direction (xml, message_handlers[i].out_args, FALSE)) + return FALSE; - if (!_dbus_string_append (&xml, " </method>\n")) - goto oom; + if (!_dbus_string_append (xml, " </method>\n")) + return FALSE; ++i; } - if (!_dbus_string_append_printf (&xml, " <signal name=\"NameOwnerChanged\">\n")) - goto oom; + if (!_dbus_string_append_printf (xml, " <signal name=\"NameOwnerChanged\">\n")) + return FALSE; - if (!_dbus_string_append_printf (&xml, " <arg type=\"s\"/>\n")) - goto oom; + if (!_dbus_string_append_printf (xml, " <arg type=\"s\"/>\n")) + return FALSE; - if (!_dbus_string_append_printf (&xml, " <arg type=\"s\"/>\n")) - goto oom; + if (!_dbus_string_append_printf (xml, " <arg type=\"s\"/>\n")) + return FALSE; - if (!_dbus_string_append_printf (&xml, " <arg type=\"s\"/>\n")) - goto oom; + if (!_dbus_string_append_printf (xml, " <arg type=\"s\"/>\n")) + return FALSE; - if (!_dbus_string_append_printf (&xml, " </signal>\n")) - goto oom; + if (!_dbus_string_append_printf (xml, " </signal>\n")) + return FALSE; - if (!_dbus_string_append_printf (&xml, " <signal name=\"NameLost\">\n")) - goto oom; + if (!_dbus_string_append_printf (xml, " <signal name=\"NameLost\">\n")) + return FALSE; - if (!_dbus_string_append_printf (&xml, " <arg type=\"s\"/>\n")) - goto oom; + if (!_dbus_string_append_printf (xml, " <arg type=\"s\"/>\n")) + return FALSE; - if (!_dbus_string_append_printf (&xml, " </signal>\n")) - goto oom; + if (!_dbus_string_append_printf (xml, " </signal>\n")) + return FALSE; - if (!_dbus_string_append_printf (&xml, " <signal name=\"NameAcquired\">\n")) - goto oom; + if (!_dbus_string_append_printf (xml, " <signal name=\"NameAcquired\">\n")) + return FALSE; - if (!_dbus_string_append_printf (&xml, " <arg type=\"s\"/>\n")) - goto oom; + if (!_dbus_string_append_printf (xml, " <arg type=\"s\"/>\n")) + return FALSE; - if (!_dbus_string_append_printf (&xml, " </signal>\n")) - goto oom; - + if (!_dbus_string_append_printf (xml, " </signal>\n")) + return FALSE; + if (!_dbus_string_append (xml, " </interface>\n")) + return FALSE; - if (!_dbus_string_append (&xml, " </interface>\n")) - goto oom; + if (!_dbus_string_append (xml, "</node>\n")) + return FALSE; + + return TRUE; +} + +static dbus_bool_t +bus_driver_handle_introspect (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + DBusString xml; + DBusMessage *reply; + const char *v_STRING; + + _dbus_verbose ("Introspect() on bus driver\n"); - if (!_dbus_string_append (&xml, "</node>\n")) + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + reply = NULL; + + if (! dbus_message_get_args (message, error, + DBUS_TYPE_INVALID)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + return FALSE; + } + + if (!_dbus_string_init (&xml)) + { + BUS_SET_OOM (error); + return FALSE; + } + + if (!bus_driver_generate_introspect_string (&xml)) goto oom; + v_STRING = _dbus_string_get_const_data (&xml); + reply = dbus_message_new_method_return (message); if (reply == NULL) goto oom; - v_STRING = _dbus_string_get_const_data (&xml); if (! dbus_message_append_args (reply, DBUS_TYPE_STRING, &v_STRING, DBUS_TYPE_INVALID)) diff --git a/bus/driver.h b/bus/driver.h index bc430520..39bff672 100644 --- a/bus/driver.h +++ b/bus/driver.h @@ -45,5 +45,8 @@ dbus_bool_t bus_driver_send_service_owner_changed (const char *service_name const char *new_owner, BusTransaction *transaction, DBusError *error); +dbus_bool_t bus_driver_generate_introspect_string (DBusString *xml); + + #endif /* BUS_DRIVER_H */ @@ -21,6 +21,7 @@ * */ #include "bus.h" +#include "driver.h" #include <dbus/dbus-internals.h> #include <dbus/dbus-watch.h> #include <stdio.h> @@ -66,7 +67,7 @@ signal_handler (int sig) static void usage (void) { - fprintf (stderr, DAEMON_NAME " [--version] [--session] [--system] [--config-file=FILE] [--print-address[=DESCRIPTOR]] [--print-pid[=DESCRIPTOR]] [--fork] [--nofork]\n"); + fprintf (stderr, DAEMON_NAME " [--version] [--session] [--system] [--config-file=FILE] [--print-address[=DESCRIPTOR]] [--print-pid[=DESCRIPTOR]] [--fork] [--nofork] [--introspect]\n"); exit (1); } @@ -82,6 +83,30 @@ version (void) } static void +introspect (void) +{ + DBusString xml; + const char *v_STRING; + + if (!_dbus_string_init (&xml)) + goto oom; + + if (!bus_driver_generate_introspect_string (&xml)) + { + _dbus_string_free (&xml); + goto oom; + } + + v_STRING = _dbus_string_get_const_data (&xml); + printf ("%s\n", v_STRING); + + exit (0); + + oom: + _dbus_warn ("Can not introspect - Out of memory\n"); + exit (1); +} +static void check_two_config_files (const DBusString *config_file, const char *extra_arg) { @@ -231,6 +256,8 @@ main (int argc, char **argv) usage (); else if (strcmp (arg, "--version") == 0) version (); + else if (strcmp (arg, "--introspect") == 0) + introspect (); else if (strcmp (arg, "--nofork") == 0) force_fork = FORK_NEVER; else if (strcmp (arg, "--fork") == 0) |