1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* config-parser.c XML-library-agnostic configuration file parser
4 * Copyright (C) 2003 Red Hat, Inc.
6 * Licensed under the Academic Free License version 1.2
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "config-parser.h"
25 #include <dbus/dbus-list.h>
26 #include <dbus/dbus-internals.h>
48 BusConfigParser *parser;
83 struct BusConfigParser
87 DBusList *stack; /**< stack of Element */
89 char *user; /**< user to run as */
94 push_element (BusConfigParser *parser,
99 e = dbus_new0 (Element, 1);
109 pop_element (BusConfigParser *parser)
113 e = _dbus_list_pop_last (&parser->stack);
119 bus_config_parser_new (void)
121 BusConfigParser *parser;
123 parser = dbus_new0 (BusConfigParser, 1);
127 parser->refcount = 1;
133 bus_config_parser_ref (BusConfigParser *parser)
135 _dbus_assert (parser->refcount > 0);
137 parser->refcount += 1;
141 bus_config_parser_unref (BusConfigParser *parser)
143 _dbus_assert (parser->refcount > 0);
145 parser->refcount -= 1;
147 if (parser->refcount == 0)
149 while (parser->stack != NULL)
150 pop_element (parser);
152 dbus_free (parser->user);
159 bus_config_parser_check_doctype (BusConfigParser *parser,
163 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
165 if (strcmp (doctype, "busconfig") != 0)
167 dbus_set_error (error,
169 "Document has the wrong type %s",
178 bus_config_parser_start_element (BusConfigParser *parser,
179 const char *element_name,
180 const char **attribute_names,
181 const char **attribute_values,
184 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
189 bus_config_parser_end_element (BusConfigParser *parser,
190 const char *element_name,
193 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
198 bus_config_parser_content (BusConfigParser *parser,
199 const DBusString *content,
202 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
207 bus_config_parser_finished (BusConfigParser *parser,
210 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
215 bus_config_parser_get_user (BusConfigParser *parser)
221 #ifdef DBUS_BUILD_TESTS
224 bus_config_parser_test (const DBusString *test_data_dir)
230 #endif /* DBUS_BUILD_TESTS */