summaryrefslogtreecommitdiffstats
path: root/bus/config-loader-libxml.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2003-03-26 03:58:11 +0000
committerHavoc Pennington <hp@redhat.com>2003-03-26 03:58:11 +0000
commit90ed1d84588a84697051e643175452c50d682ece (patch)
treea8ee3ecb05c584194d5c74e98038c24e5fdabe9b /bus/config-loader-libxml.c
parent17e82f5728d3fc8abd41c816b1c34c506339c7a7 (diff)
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
Diffstat (limited to 'bus/config-loader-libxml.c')
-rw-r--r--bus/config-loader-libxml.c105
1 files changed, 105 insertions, 0 deletions
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;
+}