diff options
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | bus/Makefile.am | 11 | ||||
-rw-r--r-- | bus/activation.c | 10 | ||||
-rw-r--r-- | bus/bus.c | 2 | ||||
-rw-r--r-- | bus/config-loader-libxml.c | 105 | ||||
-rw-r--r-- | bus/config-parser.c | 73 | ||||
-rw-r--r-- | bus/config-parser.h | 12 | ||||
-rw-r--r-- | bus/connection.c | 2 | ||||
-rw-r--r-- | bus/desktop-file.c | 12 | ||||
-rw-r--r-- | bus/dispatch.c | 6 | ||||
-rw-r--r-- | bus/driver.c | 22 | ||||
-rw-r--r-- | bus/services.c | 6 | ||||
-rw-r--r-- | bus/test-main.c | 10 | ||||
-rw-r--r-- | bus/test.h | 1 | ||||
-rw-r--r-- | configure.in | 24 |
15 files changed, 292 insertions, 14 deletions
@@ -1,3 +1,13 @@ +2003-03-25 Havoc Pennington <hp@redhat.com> + + * throughout - add more _DBUS_ASSERT_ERROR_IS_CLEAR + + * configure.in: add --with-xml option to specify XML library, + right now only libxml is supported. + + * bus/config-loader-libxml.c, config-parser.c: sync some minor + nonworking code between home and work, still just stubs + 2003-03-24 Havoc Pennington <hp@redhat.com> * dbus/dbus-sysdeps.c (_dbus_set_fd_nonblocking): move to this diff --git a/bus/Makefile.am b/bus/Makefile.am index bc64032c..37d3de06 100644 --- a/bus/Makefile.am +++ b/bus/Makefile.am @@ -6,11 +6,17 @@ EFENCE= bin_PROGRAMS=dbus-daemon-1 +if DBUS_USE_LIBXML +XML_SOURCES=config-loader-libxml.c +endif + BUS_SOURCES= \ activation.c \ activation.h \ bus.c \ bus.h \ + config-parser.c \ + config-parser.h \ connection.c \ connection.h \ desktop-file.c \ @@ -28,7 +34,8 @@ BUS_SOURCES= \ test.c \ test.h \ utils.c \ - utils.h + utils.h \ + $(XML_SOURCES) dbus_daemon_1_SOURCES= \ $(BUS_SOURCES) \ @@ -57,7 +64,7 @@ bus_test_SOURCES= \ $(BUS_SOURCES) \ test-main.c -bus_test_LDADD=$(top_builddir)/dbus/libdbus-convenience.la +bus_test_LDADD=$(top_builddir)/dbus/libdbus-convenience.la $(DBUS_BUS_LIBS) ## mop up the gcov files clean-local: diff --git a/bus/activation.c b/bus/activation.c index fed12781..03a01937 100644 --- a/bus/activation.c +++ b/bus/activation.c @@ -119,6 +119,8 @@ add_desktop_file_entry (BusActivation *activation, char *name, *exec; BusActivationEntry *entry; + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + name = NULL; exec = NULL; entry = NULL; @@ -194,6 +196,8 @@ load_directory (BusActivation *activation, DBusString full_path; BusDesktopFile *desktop_file; DBusError tmp_error; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); _dbus_string_init_const (&dir, directory); @@ -327,6 +331,8 @@ bus_activation_new (BusContext *context, int i; BusActivation *activation; + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + activation = dbus_new0 (BusActivation, 1); if (activation == NULL) { @@ -424,6 +430,8 @@ bus_activation_service_created (BusActivation *activation, BusPendingActivation *pending_activation; DBusMessage *message; DBusList *link; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); /* Check if it's a pending activation */ pending_activation = _dbus_hash_table_lookup_string (activation->pending_activations, service_name); @@ -492,6 +500,8 @@ bus_activation_activate_service (BusActivation *activation, DBusString service_str; char *argv[2]; dbus_bool_t retval; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); entry = _dbus_hash_table_lookup_string (activation->entries, service_name); @@ -143,6 +143,8 @@ bus_context_new (const char *address, DBusError *error) { BusContext *context; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); context = dbus_new0 (BusContext, 1); if (context == NULL) diff --git a/bus/config-loader-libxml.c b/bus/config-loader-libxml.c new file mode 100644 index 00000000..3bfc97ff --- /dev/null +++ b/bus/config-loader-libxml.c @@ -0,0 +1,105 @@ +/* -*- mode: C; c-file-style: "gnu" -*- */ +/* config-loader-libxml.c libxml2 XML loader + * + * Copyright (C) 2003 Red Hat, Inc. + * + * Licensed under the Academic Free License version 1.2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "config-parser.h" +#include <dbus/dbus-internals.h> +#include <libxml/xmlreader.h> +#include <libxml/parser.h> +#include <libxml/globals.h> +#include <errno.h> +#include <string.h> + +static void +xml_text_reader_error (void *arg, + const char *msg, + xmlParserSeverities severity, + xmlTextReaderLocatorPtr locator) +{ + DBusError *error = arg; + + if (!dbus_error_is_set (error)) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Error loading config file: %s", + msg); + } +} + +BusConfigParser* +bus_config_load (const DBusString *file, + DBusError *error) +{ + xmlTextReader *reader; + const char *filename; + BusConfigParser *parser; + DBusError tmp_error; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + _dbus_string_get_const_data (file, &filename); + + errno = 0; + reader = xmlNewTextReaderFilename (filename); + + if (reader == NULL) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Failed to load configuration file %s: %s\n", + filename, + errno != 0 ? strerror (errno) : "Unknown error"); + + return NULL; + } + + dbus_error_init (&tmp_error); + xmlTextReaderSetErrorHandler (reader, xml_text_reader_error, &tmp_error); + + while (xmlTextReaderRead(reader) == 1) + { + if (dbus_error_is_set (&tmp_error)) + goto reader_out; + + + + + } + + reader_out: + xmlFreeTextReader (reader); + if (dbus_error_is_set (&tmp_error)) + { + dbus_move_error (&tmp_error, error); + goto failed; + } + + if (!bus_config_parser_finished (parser, error)) + goto failed; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + return parser; + + failed: + _DBUS_ASSERT_ERROR_IS_SET (error); + bus_config_parser_unref (parser); + return NULL; +} diff --git a/bus/config-parser.c b/bus/config-parser.c index 26e52a8b..0d33d2b9 100644 --- a/bus/config-parser.c +++ b/bus/config-parser.c @@ -20,8 +20,10 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ - #include "config-parser.h" +#include "test.h" +#include <dbus/dbus-list.h> +#include <dbus/dbus-internals.h> #include <string.h> typedef enum @@ -82,9 +84,37 @@ struct BusConfigParser { int refcount; - DBusList *stack; + DBusList *stack; /**< stack of Element */ + + char *user; /**< user to run as */ }; + +static Element* +push_element (BusConfigParser *parser, + ElementType type) +{ + Element *e; + + e = dbus_new0 (Element, 1); + if (e == NULL) + return NULL; + + e->type = type; + + return e; +} + +static void +pop_element (BusConfigParser *parser) +{ + Element *e; + + e = _dbus_list_pop_last (&parser->stack); + + dbus_free (e); +} + BusConfigParser* bus_config_parser_new (void) { @@ -116,7 +146,10 @@ bus_config_parser_unref (BusConfigParser *parser) if (parser->refcount == 0) { - + while (parser->stack != NULL) + pop_element (parser); + + dbus_free (parser->user); dbus_free (parser); } @@ -127,6 +160,8 @@ bus_config_parser_check_doctype (BusConfigParser *parser, const char *doctype, DBusError *error) { + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + if (strcmp (doctype, "busconfig") != 0) { dbus_set_error (error, @@ -146,7 +181,7 @@ bus_config_parser_start_element (BusConfigParser *parser, const char **attribute_values, DBusError *error) { - + _DBUS_ASSERT_ERROR_IS_CLEAR (error); } @@ -155,7 +190,7 @@ bus_config_parser_end_element (BusConfigParser *parser, const char *element_name, DBusError *error) { - + _DBUS_ASSERT_ERROR_IS_CLEAR (error); } @@ -164,7 +199,33 @@ bus_config_parser_content (BusConfigParser *parser, const DBusString *content, DBusError *error) { - + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + +} + +dbus_bool_t +bus_config_parser_finished (BusConfigParser *parser, + DBusError *error) +{ + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + +} + +const char* +bus_config_parser_get_user (BusConfigParser *parser) +{ + } +#ifdef DBUS_BUILD_TESTS + +dbus_bool_t +bus_config_parser_test (const DBusString *test_data_dir) +{ + + return TRUE; +} + +#endif /* DBUS_BUILD_TESTS */ + diff --git a/bus/config-parser.h b/bus/config-parser.h index 371a658c..2fa651a3 100644 --- a/bus/config-parser.h +++ b/bus/config-parser.h @@ -50,6 +50,18 @@ dbus_bool_t bus_config_parser_end_element (BusConfigParser *parser, dbus_bool_t bus_config_parser_content (BusConfigParser *parser, const DBusString *content, DBusError *error); +dbus_bool_t bus_config_parser_finished (BusConfigParser *parser, + DBusError *error); + +/* Functions for extracting the parse results */ +const char* bus_config_parser_get_user (BusConfigParser *parser); + + +/* Loader functions (backended off one of the XML parsers). Returns a + * finished ConfigParser. + */ +BusConfigParser* bus_config_load (const DBusString *file, + DBusError *error); #endif /* BUS_CONFIG_PARSER_H */ diff --git a/bus/connection.c b/bus/connection.c index 4cb98f65..ee7d183c 100644 --- a/bus/connection.c +++ b/bus/connection.c @@ -1023,7 +1023,7 @@ bus_transaction_send_error_reply (BusTransaction *transaction, DBusMessage *in_reply_to) { DBusMessage *reply; - + _dbus_assert (error != NULL); _DBUS_ASSERT_ERROR_IS_SET (error); diff --git a/bus/desktop-file.c b/bus/desktop-file.c index f45a997e..13b709d2 100644 --- a/bus/desktop-file.c +++ b/bus/desktop-file.c @@ -180,6 +180,8 @@ unescape_string (BusDesktopFileParser *parser, DBusError *error) { char *retval, *q; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); /* len + 1 is enough, because unescaping never makes the * string longer @@ -389,6 +391,8 @@ parse_section_start (BusDesktopFileParser *parser, DBusError *error) { int line_end; char *section_name; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); if (!_dbus_string_find (&parser->data, parser->pos, "\n", &line_end)) line_end = parser->len; @@ -447,6 +451,8 @@ parse_key_value (BusDesktopFileParser *parser, DBusError *error) char *value, *tmp; DBusString key; BusDesktopFileLine *line; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); if (!_dbus_string_find (&parser->data, parser->pos, "\n", &line_end)) line_end = parser->len; @@ -549,7 +555,9 @@ report_error (BusDesktopFileParser *parser, DBusError *error) { const char *section_name = NULL; - + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + if (parser->current_section != -1) section_name = parser->desktop_file->sections[parser->current_section].section_name; @@ -589,6 +597,8 @@ bus_desktop_file_load (DBusString *filename, DBusString str; BusDesktopFileParser parser; DBusStat sb; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); /* Clearly there's a race here, but it's just to make it unlikely * that we do something silly, we still handle doing it below. diff --git a/bus/dispatch.c b/bus/dispatch.c index 490ecf24..7db4ac29 100644 --- a/bus/dispatch.c +++ b/bus/dispatch.c @@ -70,6 +70,8 @@ bus_dispatch_broadcast_message (BusTransaction *transaction, DBusError tmp_error; SendMessageData d; BusConnections *connections; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); _dbus_assert (dbus_message_get_sender (message) != NULL); @@ -101,7 +103,9 @@ send_service_nonexistent_error (BusTransaction *transaction, DBusMessage *error_reply; DBusString error_message; const char *error_str; - + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + /* Trying to send a message to a non-existant service, * bounce back an error message. */ diff --git a/bus/driver.c b/bus/driver.c index 98085fc7..4946fd6a 100644 --- a/bus/driver.c +++ b/bus/driver.c @@ -43,6 +43,8 @@ bus_driver_send_service_deleted (const char *service_name, { DBusMessage *message; dbus_bool_t retval; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); _dbus_verbose ("sending service deleted: %s\n", service_name); @@ -77,6 +79,8 @@ bus_driver_send_service_created (const char *service_name, { DBusMessage *message; dbus_bool_t retval; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); message = dbus_message_new (DBUS_SERVICE_BROADCAST, DBUS_MESSAGE_SERVICE_CREATED); @@ -116,6 +120,8 @@ bus_driver_send_service_lost (DBusConnection *connection, { DBusMessage *message; + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + message = dbus_message_new (bus_connection_get_name (connection), DBUS_MESSAGE_SERVICE_LOST); if (message == NULL) @@ -161,6 +167,8 @@ bus_driver_send_service_acquired (DBusConnection *connection, { DBusMessage *message; + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + message = dbus_message_new (bus_connection_get_name (connection), DBUS_MESSAGE_SERVICE_ACQUIRED); if (message == NULL) @@ -267,6 +275,8 @@ bus_driver_handle_hello (DBusConnection *connection, BusService *service; dbus_bool_t retval; BusRegistry *registry; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); if (!_dbus_string_init (&unique_name, _DBUS_INT_MAX)) { @@ -323,6 +333,8 @@ bus_driver_send_welcome_message (DBusConnection *connection, { DBusMessage *welcome; const char *name; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); name = bus_connection_get_name (connection); _dbus_assert (name != NULL); @@ -373,6 +385,8 @@ bus_driver_handle_list_services (DBusConnection *connection, int len; char **services; BusRegistry *registry; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); registry = bus_connection_get_registry (connection); @@ -431,6 +445,8 @@ bus_driver_handle_acquire_service (DBusConnection *connection, DBusConnection *old_owner; DBusConnection *current_owner; BusRegistry *registry; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); registry = bus_connection_get_registry (connection); @@ -554,6 +570,8 @@ bus_driver_handle_service_exists (DBusConnection *connection, char *name; dbus_bool_t retval; BusRegistry *registry; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); registry = bus_connection_get_registry (connection); @@ -615,6 +633,8 @@ bus_driver_handle_activate_service (DBusConnection *connection, dbus_bool_t retval; BusActivation *activation; + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + activation = bus_connection_get_activation (connection); if (!dbus_message_get_args (message, error, @@ -662,6 +682,8 @@ bus_driver_handle_message (DBusConnection *connection, { const char *name, *sender; int i; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); _dbus_verbose ("Driver got a message: %s\n", dbus_message_get_name (message)); diff --git a/bus/services.c b/bus/services.c index 821cb4af..d3ab1e59 100644 --- a/bus/services.c +++ b/bus/services.c @@ -128,6 +128,8 @@ bus_registry_ensure (BusRegistry *registry, const char *c_name; BusService *service; + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + _dbus_assert (owner_if_created != NULL); _dbus_assert (transaction != NULL); @@ -260,6 +262,8 @@ bus_service_add_owner (BusService *service, BusTransaction *transaction, DBusError *error) { + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + /* Send service acquired message first, OOM will result * in cancelling the transaction */ @@ -292,6 +296,8 @@ bus_service_remove_owner (BusService *service, BusTransaction *transaction, DBusError *error) { + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + /* We send out notifications before we do any work we * might have to undo if the notification-sending failed */ diff --git a/bus/test-main.c b/bus/test-main.c index 2e0b952e..c7f9f7b7 100644 --- a/bus/test-main.c +++ b/bus/test-main.c @@ -51,11 +51,19 @@ main (int argc, char **argv) dir = ""; _dbus_string_init_const (&test_data_dir, dir); + + printf ("%s: Running config file parser test\n", argv[0]); + if (!bus_config_parser_test (&test_data_dir)) + die ("parser"); + printf ("%s: Running policy test\n", argv[0]); + if (!bus_policy_test (&test_data_dir)) + die ("policy"); + printf ("%s: Running message dispatch test\n", argv[0]); if (!bus_dispatch_test (&test_data_dir)) die ("dispatch"); - + dbus_shutdown (); printf ("%s: checking for memleaks\n", argv[0]); @@ -34,6 +34,7 @@ dbus_bool_t bus_dispatch_test (const DBusString *test_data_dir); dbus_bool_t bus_policy_test (const DBusString *test_data_dir); +dbus_bool_t bus_config_parser_test (const DBusString *test_data_dir); dbus_bool_t bus_setup_debug_client (DBusConnection *connection); void bus_test_clients_foreach (BusConnectionForeachFunction function, void *data); diff --git a/configure.in b/configure.in index 40557732..552a7cfa 100644 --- a/configure.in +++ b/configure.in @@ -31,6 +31,8 @@ AC_ARG_ENABLE(verbose-mode, [ --enable-verbose-mode support verbose debug mode] AC_ARG_ENABLE(asserts, [ --enable-asserts include assertion checks],enable_asserts=$enableval,enable_asserts=yes) AC_ARG_ENABLE(gcov, [ --enable-gcov compile with coverage profiling instrumentation (gcc only)],enable_gcov=$enableval,enable_gcov=no) +AC_ARG_WITH(xml, [ --with-xml=[libxml] XML library to use]) + dnl DBUS_BUILD_TESTS controls unit tests built in to .c files dnl and also some stuff in the test/ subdir AM_CONDITIONAL(DBUS_BUILD_TESTS, test x$enable_tests = xyes) @@ -45,6 +47,23 @@ if test x$enable_asserts = xno; then AC_DEFINE(DBUS_DISABLE_ASSERT,1,[Disable assertion checking]) fi +dbus_use_libxml=false +dbus_use_fooxml=false +if test x$with_xml = xfooxml; then + dbus_use_fooxml=true +elif test x$with_xml = xlibxml; then + dbus_use_libxml=true +else + with_xml=libxml + dbus_use_libxml=true +fi + +AM_CONDITIONAL(DBUS_USE_LIBXML, $dbus_use_libxml) +if $dbus_use_libxml; then + PKG_CHECK_MODULES(LIBXML, libxml-2.0) +fi +AM_CONDITIONAL(DBUS_USE_FOOXML, $dbus_use_fooxml) + if test "x$GCC" = "xyes"; then changequote(,)dnl case " $CFLAGS " in @@ -224,8 +243,8 @@ DBUS_CLIENT_LIBS= AC_SUBST(DBUS_CLIENT_CFLAGS) AC_SUBST(DBUS_CLIENT_LIBS) -DBUS_BUS_CFLAGS= -DBUS_BUS_LIBS= +DBUS_BUS_CFLAGS=$LIBXML_CFLAGS +DBUS_BUS_LIBS=$LIBXML_LIBS AC_SUBST(DBUS_BUS_CFLAGS) AC_SUBST(DBUS_BUS_LIBS) @@ -329,6 +348,7 @@ echo " Building assertions: ${enable_asserts} Building Qt bindings: ${have_qt} Building GLib bindings: ${have_glib} + Using XML parser: ${with_xml} " if test x$enable_tests = xyes; then |