From 269d74f214f87bed0f6fd58f1c848240d31e0b9f Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Wed, 26 Mar 2003 07:16:03 +0000 Subject: 2003-03-26 Havoc Pennington * bus/test-main.c, dbus/dbus-test.c (main): check memleaks after every test so it's quick and easy to see which leaked, and so we test multiple dbus_shutdown() calls * configure.in: change configure.in XML stuff to also support expat * config-loader-libxml.c: some hacking * config-loader-expat.c: some hacking * config-parser.c: some hacking, plus tests --- bus/config-loader-libxml.c | 74 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 68 insertions(+), 6 deletions(-) (limited to 'bus/config-loader-libxml.c') diff --git a/bus/config-loader-libxml.c b/bus/config-loader-libxml.c index 3bfc97ff..74cfd7dc 100644 --- a/bus/config-loader-libxml.c +++ b/bus/config-loader-libxml.c @@ -26,9 +26,34 @@ #include #include #include +#include #include #include +static void* +libxml_malloc (size_t size) +{ + return dbus_malloc (size); +} + +static void* +libxml_realloc (void *ptr, size_t size) +{ + return dbus_realloc (ptr, size); +} + +static void +libxml_free (void *ptr) +{ + dbus_free (ptr); +} + +static char* +libxml_strdup (const char *str) +{ + return _dbus_strdup (str); +} + static void xml_text_reader_error (void *arg, const char *msg, @@ -57,6 +82,30 @@ bus_config_load (const DBusString *file, _DBUS_ASSERT_ERROR_IS_CLEAR (error); _dbus_string_get_const_data (file, &filename); + parser = NULL; + reader = NULL; + dbus_error_init (&tmp_error); + + if (xmlMemSetup (libxml_free, + libxml_malloc, + libxml_realloc, + libxml_strdup) != 0) + { + /* Current libxml can't possibly fail here, but just being + * paranoid; don't really know why xmlMemSetup() returns an + * error code, assuming some version of libxml had a reason. + */ + dbus_set_error (error, DBUS_ERROR_FAILED, + "xmlMemSetup() didn't work for some reason\n"); + return NULL; + } + + parser = bus_config_parser_new (); + if (parser == NULL) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + return NULL; + } errno = 0; reader = xmlNewTextReaderFilename (filename); @@ -68,24 +117,35 @@ bus_config_load (const DBusString *file, filename, errno != 0 ? strerror (errno) : "Unknown error"); - return NULL; + goto failed; } - dbus_error_init (&tmp_error); xmlTextReaderSetErrorHandler (reader, xml_text_reader_error, &tmp_error); - while (xmlTextReaderRead(reader) == 1) + while (xmlTextReaderRead (reader) == 1) { + int type; + if (dbus_error_is_set (&tmp_error)) goto reader_out; - + /* "enum" anyone? http://dotgnu.org/pnetlib-doc/System/Xml/XmlNodeType.html for + * the magic numbers + */ + type = xmlTextReaderNodeType (reader); + if (dbus_error_is_set (&tmp_error)) + goto reader_out; - + /* FIXME I don't really know exactly what I need to do to + * resolve all entities and so on to get the full content of a + * node or attribute value. I'm worried about whether I need to + * manually handle stuff like < + */ } reader_out: xmlFreeTextReader (reader); + reader = NULL; if (dbus_error_is_set (&tmp_error)) { dbus_move_error (&tmp_error, error); @@ -100,6 +160,8 @@ bus_config_load (const DBusString *file, failed: _DBUS_ASSERT_ERROR_IS_SET (error); - bus_config_parser_unref (parser); + if (parser) + bus_config_parser_unref (parser); + _dbus_assert (reader == NULL); /* must go to reader_out first */ return NULL; } -- cgit