2003-03-25 Havoc Pennington <hp@redhat.com>
[platform/upstream/dbus.git] / bus / config-parser.c
1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* config-parser.c  XML-library-agnostic configuration file parser
3  *
4  * Copyright (C) 2003 Red Hat, Inc.
5  *
6  * Licensed under the Academic Free License version 1.2
7  * 
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.
12  *
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.
17  * 
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
21  *
22  */
23 #include "config-parser.h"
24 #include "test.h"
25 #include <dbus/dbus-list.h>
26 #include <dbus/dbus-internals.h>
27 #include <string.h>
28
29 typedef enum
30 {
31   ELEMENT_BUSCONFIG,
32   ELEMENT_INCLUDE,
33   ELEMENT_USER,
34   ELEMENT_LISTEN,
35   ELEMENT_AUTH,
36   ELEMENT_POLICY,
37   ELEMENT_LIMIT
38 } ElementType;
39
40 typedef struct
41 {
42   ElementType type;
43
44   union
45   {
46     struct
47     {
48       BusConfigParser *parser;
49     } include;
50
51     struct
52     {
53       char *username;
54     } user;
55
56     struct
57     {
58       char *address;
59     } listen;
60
61     struct
62     {
63       char *mechanism;
64     } auth;
65
66     struct
67     {
68       char *context;
69       char *user;
70       char *group;
71       DBusList *rules;
72     } policy;
73
74     struct
75     {
76       int foo;
77     } limit;
78     
79   } d;
80   
81 } Element;
82
83 struct BusConfigParser
84 {
85   int refcount;
86
87   DBusList *stack; /**< stack of Element */
88
89   char *user;      /**< user to run as */
90 };
91
92
93 static Element*
94 push_element (BusConfigParser *parser,
95               ElementType      type)
96 {
97   Element *e;
98
99   e = dbus_new0 (Element, 1);
100   if (e == NULL)
101     return NULL;
102   
103   e->type = type;
104
105   return e;
106 }
107
108 static void
109 pop_element (BusConfigParser *parser)
110 {
111   Element *e;
112
113   e = _dbus_list_pop_last (&parser->stack);
114
115   dbus_free (e);
116 }
117
118 BusConfigParser*
119 bus_config_parser_new (void)
120 {
121   BusConfigParser *parser;
122
123   parser = dbus_new0 (BusConfigParser, 1);
124   if (parser == NULL)
125     return NULL;
126
127   parser->refcount = 1;
128
129   return parser;
130 }
131
132 void
133 bus_config_parser_ref (BusConfigParser *parser)
134 {
135   _dbus_assert (parser->refcount > 0);
136
137   parser->refcount += 1;
138 }
139
140 void
141 bus_config_parser_unref (BusConfigParser *parser)
142 {
143   _dbus_assert (parser->refcount > 0);
144
145   parser->refcount -= 1;
146
147   if (parser->refcount == 0)
148     {
149       while (parser->stack != NULL)
150         pop_element (parser);
151       
152       dbus_free (parser->user);
153
154       dbus_free (parser);
155     }
156 }
157
158 dbus_bool_t
159 bus_config_parser_check_doctype (BusConfigParser   *parser,
160                                  const char        *doctype,
161                                  DBusError         *error)
162 {
163   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
164   
165   if (strcmp (doctype, "busconfig") != 0)
166     {
167       dbus_set_error (error,
168                       DBUS_ERROR_FAILED,
169                       "Document has the wrong type %s",
170                       doctype);
171       return FALSE;
172     }
173   else
174     return TRUE;
175 }
176
177 dbus_bool_t
178 bus_config_parser_start_element (BusConfigParser   *parser,
179                                  const char        *element_name,
180                                  const char       **attribute_names,
181                                  const char       **attribute_values,
182                                  DBusError         *error)
183 {
184   _DBUS_ASSERT_ERROR_IS_CLEAR (error);  
185
186 }
187
188 dbus_bool_t
189 bus_config_parser_end_element (BusConfigParser   *parser,
190                                const char        *element_name,
191                                DBusError         *error)
192 {
193   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
194
195 }
196
197 dbus_bool_t
198 bus_config_parser_content (BusConfigParser   *parser,
199                            const DBusString  *content,
200                            DBusError         *error)
201 {
202   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
203
204 }
205
206 dbus_bool_t
207 bus_config_parser_finished (BusConfigParser   *parser,
208                             DBusError         *error)
209 {
210   _DBUS_ASSERT_ERROR_IS_CLEAR (error);  
211
212 }
213
214 const char*
215 bus_config_parser_get_user (BusConfigParser *parser)
216 {
217
218
219 }
220
221 #ifdef DBUS_BUILD_TESTS
222
223 dbus_bool_t
224 bus_config_parser_test (const DBusString *test_data_dir)
225 {
226   
227   return TRUE;
228 }
229
230 #endif /* DBUS_BUILD_TESTS */
231