1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
|
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef GUTHTHILA_H
#define GUTHTHILA_H
#include <guththila_defines.h>
#include <guththila_token.h>
#include <guththila_reader.h>
#include <guththila_xml_writer.h>
#include <guththila_attribute.h>
#include <guththila_namespace.h>
#include <guththila_buffer.h>
#include <guththila_stack.h>
#include <guththila_error.h>
#include <axutil_utils.h>
/*
All the functions in this library does not check weather the given arguments are NULL.
It is the responsblity of the user to check weather the arguments contain NULL values.
*/
EXTERN_C_START()
enum guththila_status
{
S_0 = 0,
S_1,
S_2,
S_3
};
enum guththila_UTF16_endianess
{
None = 1,
LE,
BE
};
typedef enum guththila_type
{
type_file_name = 0,
type_memory_buffer,
type_reader,
type_io
} guththila_type_t;
enum guththila_event_types
{
GUTHTHILA_START_DOCUMENT =0,
GUTHTHILA_END_ELEMENT,
GUTHTHILA_CHARACTER,
GUTHTHILA_ENTITY_REFERANCE,
GUTHTHILA_COMMENT,
GUTHTHILA_SPACE,
GUTHTHILA_START_ELEMENT,
GUTHTHILA_EMPTY_ELEMENT
};
typedef struct guththila_s
{
guththila_tok_list_t tokens; /* Token cache */
guththila_buffer_t buffer; /* Holding incoming xml string */
guththila_reader_t *reader; /* Reading the data */
guththila_token_t *prefix; /* Prefix of the xml element */
guththila_token_t *name; /* xml element local name */
guththila_token_t *value; /* text of a xml element */
guththila_stack_t elem; /* elements are put in a stack */
guththila_stack_t attrib; /* Attributes are put in a stack */
guththila_stack_t namesp; /* namespaces are put in a stack */
int status;
int guththila_event; /* Current event */
size_t next; /* Keep track of the position in the xml string */
int last_start; /* Keep track of the starting position of the last token */
guththila_token_t *temp_prefix; /* Temporery location for prefixes */
guththila_token_t *temp_name; /* Temporery location for names */
guththila_token_t *temp_tok; /* We don't know this until we close it */
} guththila_t;
/*
* An element will contain one of these things if it has namespaces
* */
typedef struct guththila_elem_namesp_s
{
guththila_namespace_t *namesp; /* Array of namespaces */
int no; /*Number of namespace in the element */
int size; /* Allocated size */
} guththila_elem_namesp_t;
/*
* Element.
*/
typedef struct guththila_element_s
{
guththila_token_t *name; /* local name */
guththila_token_t *prefix; /* prefix */
int is_namesp; /* Positive if a namespace is present */
} guththila_element_t;
/* Initialize the parser */
GUTHTHILA_EXPORT int GUTHTHILA_CALL
guththila_init(guththila_t * m, void *reader,
const axutil_env_t * env);
/* Uninitialize the parser */
GUTHTHILA_EXPORT int GUTHTHILA_CALL
guththila_un_init(guththila_t * m, const axutil_env_t * env);
/* Still not used */
typedef void(GUTHTHILA_CALL * guththila_error_func)(void *arg,
const guththila_char_t *msg,
guththila_error_level level,
void *locator);
/*
* Parse the xml and return an event. If something went wrong it will return -1.
* The events are of the type guththila_event_types. According to the event
* user can get the required information using the appriate functions.
* @param g pointer to a guththila_t structure
* @param env the environment
*/
GUTHTHILA_EXPORT int GUTHTHILA_CALL
guththila_next(guththila_t * g, const axutil_env_t * env);
/*
* Return the number of attributes in the current element.
* @param g pointer to a guththila_t structure
* @param env the environment
*/
GUTHTHILA_EXPORT int GUTHTHILA_CALL
guththila_get_attribute_count(guththila_t * g, const axutil_env_t * env);
/*
* Return the attribute name.
* @param g pointer to a guththila_t structure
* @param att pointer to a attribute
* @param env the environment
*/
GUTHTHILA_EXPORT guththila_char_t * GUTHTHILA_CALL
guththila_get_attribute_name(guththila_t * g, guththila_attr_t * att,
const axutil_env_t * env);
/*
* Return the attribute value.
* @param g pointer to a guththila_t structure
* @param att pointer to a attribute
* @param env the environment
*/
GUTHTHILA_EXPORT guththila_char_t * GUTHTHILA_CALL
guththila_get_attribute_value(guththila_t * g,
guththila_attr_t * att,
const axutil_env_t * env);
/*
* Return the attribute prefix.
* @param g pointer to a guththila_t structure
* @param att pointer to a attribute
* @param env the environment
*/
GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL
guththila_get_attribute_prefix(guththila_t * g,
guththila_attr_t * att,
const axutil_env_t * env);
/*
* Return the attribute
* @param g pointer to a guththila_t structure
* @param env the environment
*/
GUTHTHILA_EXPORT guththila_attr_t *GUTHTHILA_CALL
guththila_get_attribute(guththila_t * g, const axutil_env_t * env);
/*
* Return the name of the attribute by the attribute bumber.
* First attribute will be 1.
* @param g pointer to a guththila_t structure
* @param index position of the attribute
* @param env the environment
*/
GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL
guththila_get_attribute_name_by_number(guththila_t * g, int index,
const axutil_env_t *env);
/*
* Return the attribute value by number.
* First attribute will be 1.
* @param g pointer to a guththila_t structure
* @param index position of the attribute
* @param env the environment
*/
GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL
guththila_get_attribute_value_by_number(guththila_t * g, int index,
const axutil_env_t *env);
/*
* Return the prefix of the attribute.
* First attribute will be 1.
* @param g pointer to a guththila_t structure
* @param index position of the attribute
* @param env the environment
*/
GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL
guththila_get_attribute_prefix_by_number(guththila_t * g, int index,
const axutil_env_t *env);
/*
* Return the name of the element.
* @param g pointer to a guththila_t structure
* @param env the environment
*/
GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL
guththila_get_name(guththila_t * g, const axutil_env_t * env);
/*
* Return the prefix of the element.
* @param g pointer to a guththila_t structure
* @param env the environment
*/
GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL
guththila_get_prefix(guththila_t * g, const axutil_env_t * env);
/*
* Return the text of the element.
* @param g pointer to a guththila_t structure
* @param env the environment
*/
GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL
guththila_get_value(guththila_t * g, const axutil_env_t * env);
/*
* Return the namespace of the element.
* @param g pointer to a guththila_t structure
* @param env the environment
*/
GUTHTHILA_EXPORT guththila_namespace_t *GUTHTHILA_CALL
guththila_get_namespace(guththila_t * g, const axutil_env_t * env);
/*
* Return the number of namespaces in the element.
* @param g pointer to a guththila_t structure
* @param env the environment
*/
GUTHTHILA_EXPORT int GUTHTHILA_CALL
guththila_get_namespace_count(guththila_t * g, const axutil_env_t * env);
/*
* Return the namespace uri of the given namespace.
* @param g pointer to a guththila_t structure
* @param ns pointer to a namespace
* @param env the environment
*/
GUTHTHILA_EXPORT guththila_char_t * GUTHTHILA_CALL
guththila_get_namespace_uri(guththila_t * g, guththila_namespace_t * ns,
const axutil_env_t * env);
/*
* Return the prefix of the namespace.
* @param g pointer to a guththila_t structure
* @param ns pointer to a namespace
* @param env the environment
*/
GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL
guththila_get_namespace_prefix(guththila_t * p, guththila_namespace_t * ns,
const axutil_env_t * env);
/*
* Return the prefix of the namespace at the given position.
* First namespace will have the value 1.
* @param g pointer to a guththila_t structure
* @param index position of the namespace
* @param env the environment
*/
GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL
guththila_get_namespace_prefix_by_number(guththila_t * g, int index,
const axutil_env_t *env);
/*
* Get the uri of the namespace at the given position.
* First namespace will have the value 1.
* @param g pointer to a guththila_t structure
* @param index position of the namespace
* @param env the environment
*/
GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL
guththila_get_namespace_uri_by_number(guththila_t * g, int index,
const axutil_env_t *env);
/*
* Get the attribute namespace of the attribute at the given position.
* @param g pointer to a guththila_t structure
* @param index position of the namespace
* @param env the environment
*/
GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL
guththila_get_attribute_namespace_by_number(guththila_t *g, int index,
const axutil_env_t *env);
/*
* Get the encoding. at the moment we don't support UNICODE
* @param g pointer to a guththila_t structure
* @param env the environment
*/
GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL
guththila_get_encoding(guththila_t * p, const axutil_env_t * env);
/*
* To do. Implement a proper error handling mechanism.
* @param g pointer to a guththila_t structure
* @param env the environment
*/
GUTHTHILA_EXPORT void GUTHTHILA_CALL
guththila_set_error_handler(guththila_t * m, guththila_error_func,
const axutil_env_t * env);
GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL
guththila_get_current_buffer(
guththila_t * m,
const axutil_env_t * env);
EXTERN_C_END()
#endif
|