From 61316dd897846c6ee18daccdddaf8a78650a1406 Mon Sep 17 00:00:00 2001 From: "John (J5) Palmieri" Date: Wed, 6 Sep 2006 21:16:12 +0000 Subject: * 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 --- bus/driver.c | 165 +++++++++++++++++++++++++++++++---------------------------- bus/driver.h | 3 ++ bus/main.c | 29 ++++++++++- 3 files changed, 118 insertions(+), 79 deletions(-) (limited to 'bus') 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, "\n")) - goto oom; - if (!_dbus_string_append_printf (&xml, " \n", DBUS_INTERFACE_INTROSPECTABLE)) - goto oom; - if (!_dbus_string_append (&xml, " \n")) - goto oom; - if (!_dbus_string_append_printf (&xml, " \n", DBUS_TYPE_STRING_AS_STRING)) - goto oom; - if (!_dbus_string_append (&xml, " \n")) - goto oom; - if (!_dbus_string_append (&xml, " \n")) - goto oom; + if (!_dbus_string_append (xml, DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE)) + return FALSE; + if (!_dbus_string_append (xml, "\n")) + return FALSE; + if (!_dbus_string_append_printf (xml, " \n", DBUS_INTERFACE_INTROSPECTABLE)) + return FALSE; + if (!_dbus_string_append (xml, " \n")) + return FALSE; + if (!_dbus_string_append_printf (xml, " \n", DBUS_TYPE_STRING_AS_STRING)) + return FALSE; + if (!_dbus_string_append (xml, " \n")) + return FALSE; + if (!_dbus_string_append (xml, " \n")) + return FALSE; - if (!_dbus_string_append_printf (&xml, " \n", + if (!_dbus_string_append_printf (xml, " \n", DBUS_INTERFACE_DBUS)) - goto oom; + return FALSE; i = 0; while (i < _DBUS_N_ELEMENTS (message_handlers)) { - if (!_dbus_string_append_printf (&xml, " \n", + if (!_dbus_string_append_printf (xml, " \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, " \n")) - goto oom; + if (!_dbus_string_append (xml, " \n")) + return FALSE; ++i; } - if (!_dbus_string_append_printf (&xml, " \n")) - goto oom; + if (!_dbus_string_append_printf (xml, " \n")) + return FALSE; - if (!_dbus_string_append_printf (&xml, " \n")) - goto oom; + if (!_dbus_string_append_printf (xml, " \n")) + return FALSE; - if (!_dbus_string_append_printf (&xml, " \n")) - goto oom; + if (!_dbus_string_append_printf (xml, " \n")) + return FALSE; - if (!_dbus_string_append_printf (&xml, " \n")) - goto oom; + if (!_dbus_string_append_printf (xml, " \n")) + return FALSE; - if (!_dbus_string_append_printf (&xml, " \n")) - goto oom; + if (!_dbus_string_append_printf (xml, " \n")) + return FALSE; - if (!_dbus_string_append_printf (&xml, " \n")) - goto oom; + if (!_dbus_string_append_printf (xml, " \n")) + return FALSE; - if (!_dbus_string_append_printf (&xml, " \n")) - goto oom; + if (!_dbus_string_append_printf (xml, " \n")) + return FALSE; - if (!_dbus_string_append_printf (&xml, " \n")) - goto oom; + if (!_dbus_string_append_printf (xml, " \n")) + return FALSE; - if (!_dbus_string_append_printf (&xml, " \n")) - goto oom; + if (!_dbus_string_append_printf (xml, " \n")) + return FALSE; - if (!_dbus_string_append_printf (&xml, " \n")) - goto oom; + if (!_dbus_string_append_printf (xml, " \n")) + return FALSE; - if (!_dbus_string_append_printf (&xml, " \n")) - goto oom; - + if (!_dbus_string_append_printf (xml, " \n")) + return FALSE; + if (!_dbus_string_append (xml, " \n")) + return FALSE; - if (!_dbus_string_append (&xml, " \n")) - goto oom; + if (!_dbus_string_append (xml, "\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, "\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 */ diff --git a/bus/main.c b/bus/main.c index ba13983f..b4ace1e4 100644 --- a/bus/main.c +++ b/bus/main.c @@ -21,6 +21,7 @@ * */ #include "bus.h" +#include "driver.h" #include #include #include @@ -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); } @@ -81,6 +82,30 @@ version (void) exit (0); } +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) -- cgit