aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/eina/src/include/eina_simple_xml_parser.h
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/eina/src/include/eina_simple_xml_parser.h')
-rw-r--r--libraries/eina/src/include/eina_simple_xml_parser.h390
1 files changed, 0 insertions, 390 deletions
diff --git a/libraries/eina/src/include/eina_simple_xml_parser.h b/libraries/eina/src/include/eina_simple_xml_parser.h
deleted file mode 100644
index 78660ef..0000000
--- a/libraries/eina/src/include/eina_simple_xml_parser.h
+++ /dev/null
@@ -1,390 +0,0 @@
1/* EINA - EFL data type library
2 * Copyright (C) 2011 Gustavo Sverzut Barbieri
3 * Cedric Bail
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library;
17 * if not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef EINA_SIMPLE_XML_H_
21#define EINA_SIMPLE_XML_H_
22
23#include "eina_config.h"
24
25#include "eina_types.h"
26#include "eina_magic.h"
27#include "eina_inlist.h"
28
29/**
30 * @defgroup Eina_Simple_XML_Group Simple_XML
31 *
32 * Simplistic relaxed SAX-like XML parser.
33 *
34 * This parser is far from being compliant with XML standard, but will
35 * do for most XMLs out there. If you know that your format is simple
36 * and will not vary in future with strange corner cases, then you can
37 * use it safely.
38 *
39 * The parser is SAX like, that is, it will tokenize contents and call
40 * you back so you can take some action. No contents are allocated
41 * during this parser work and it's not recursive, so you can use it
42 * with a very large document without worries.
43 *
44 * It will not validate the document anyhow, neither it will create a
45 * tree hierarchy. That's up to you.
46 *
47 * Accordingly to XML, open tags may contain attributes. This parser
48 * will not tokenize this. If you want you can use
49 * eina_simple_xml_tag_attributes_find() and then
50 * eina_simple_xml_attributes_parse().
51 */
52
53/**
54 * @addtogroup Eina_Tools_Group Tools
55 *
56 * @{
57 */
58
59/**
60 * @defgroup Eina_Simple_XML_Group Simple_XML
61 *
62 * @{
63 */
64
65typedef struct _Eina_Simple_XML_Node Eina_Simple_XML_Node;
66typedef struct _Eina_Simple_XML_Node_Tag Eina_Simple_XML_Node_Root;
67typedef struct _Eina_Simple_XML_Node_Tag Eina_Simple_XML_Node_Tag;
68typedef struct _Eina_Simple_XML_Node_Data Eina_Simple_XML_Node_Data;
69typedef struct _Eina_Simple_XML_Node_Data Eina_Simple_XML_Node_CData;
70typedef struct _Eina_Simple_XML_Node_Data Eina_Simple_XML_Node_Processing;
71typedef struct _Eina_Simple_XML_Node_Data Eina_Simple_XML_Node_Doctype;
72typedef struct _Eina_Simple_XML_Node_Data Eina_Simple_XML_Node_Comment;
73typedef struct _Eina_Simple_XML_Attribute Eina_Simple_XML_Attribute;
74
75struct _Eina_Simple_XML_Attribute
76{
77 EINA_INLIST;
78 EINA_MAGIC;
79
80 Eina_Simple_XML_Node_Tag *parent;
81 const char *key;
82 const char *value;
83};
84
85typedef enum _Eina_Simple_XML_Node_Type
86{
87 EINA_SIMPLE_XML_NODE_ROOT = 0,
88 EINA_SIMPLE_XML_NODE_TAG,
89 EINA_SIMPLE_XML_NODE_DATA,
90 EINA_SIMPLE_XML_NODE_CDATA,
91 EINA_SIMPLE_XML_NODE_PROCESSING,
92 EINA_SIMPLE_XML_NODE_DOCTYPE,
93 EINA_SIMPLE_XML_NODE_COMMENT
94} Eina_Simple_XML_Node_Type;
95
96struct _Eina_Simple_XML_Node
97{
98 EINA_INLIST;
99 EINA_MAGIC;
100
101 Eina_Simple_XML_Node_Tag *parent;
102 Eina_Simple_XML_Node_Type type;
103};
104
105struct _Eina_Simple_XML_Node_Tag
106{
107 Eina_Simple_XML_Node base;
108 Eina_Inlist *children;
109 Eina_Inlist *attributes;
110 const char *name;
111};
112
113struct _Eina_Simple_XML_Node_Data
114{
115 Eina_Simple_XML_Node base;
116 size_t length;
117 char data[];
118};
119
120typedef enum _Eina_Simple_XML_Type
121{
122 EINA_SIMPLE_XML_OPEN = 0, /*!< <tag attribute="value"> */
123 EINA_SIMPLE_XML_OPEN_EMPTY, /*!< <tag attribute="value" /> */
124 EINA_SIMPLE_XML_CLOSE, /*!< </tag> */
125 EINA_SIMPLE_XML_DATA, /*!< tag text data */
126 EINA_SIMPLE_XML_CDATA, /*!< <![CDATA[something]]> */
127 EINA_SIMPLE_XML_ERROR, /*!< error contents */
128 EINA_SIMPLE_XML_PROCESSING, /*!< <?xml ... ?> <?php .. ?> */
129 EINA_SIMPLE_XML_DOCTYPE, /*!< <!DOCTYPE html */
130 EINA_SIMPLE_XML_COMMENT, /*!< <!-- something --> */
131 EINA_SIMPLE_XML_IGNORED /*!< whatever is ignored by parser, like whitespace */
132} Eina_Simple_XML_Type;
133
134typedef Eina_Bool (*Eina_Simple_XML_Cb)(void *data, Eina_Simple_XML_Type type, const char *content, unsigned offset, unsigned length);
135typedef Eina_Bool (*Eina_Simple_XML_Attribute_Cb)(void *data, const char *key, const char *value);
136
137
138/**
139 * Parse a section of XML string text
140 *
141 * @param buf the input string. May not contain \0 terminator.
142 * @param buflen the input string size.
143 * @param strip whenever this parser should strip leading and trailing
144 * whitespace. These whitespace will still be issued, but as type
145 * #EINA_SIMPLE_XML_IGNORED.
146 * @param func what to call back while parse to do some action. The
147 * first parameter is the given user @a data, the second is the
148 * token type, the third is the pointer to content start (it's
149 * not a NULL terminated string!), the forth is where this
150 * content is located inside @a buf (does not include tag
151 * start, for instance "<!DOCTYPE value>" the offset points at
152 * "value"), the fifth is the size of the content. Whenever this
153 * function return EINA_FALSE the parser will abort. @param
154 * data what to give as context to @a func.
155 *
156 * @return EINA_TRUE on success or EINA_FALSE if it was aborted by user or
157 * parsing error.
158 */
159EAPI Eina_Bool eina_simple_xml_parse(const char *buf, unsigned buflen,
160 Eina_Bool strip,
161 Eina_Simple_XML_Cb func, const void *data);
162
163
164/**
165 * Given the contents of a tag, find where the attributes start.
166 *
167 * @param buf the input string. May not contain \0 terminator.
168 * @param buflen the input string size.
169 * @return pointer to the start of attributes, it can be used
170 * to feed eina_simple_xml_attributes_parse(). NULL is returned
171 * if no attributes were found.
172 *
173 * The tag contents is returned by eina_simple_xml_parse() when
174 * type is #EINA_SIMPLE_XML_OPEN or #EINA_SIMPLE_XML_OPEN_EMPTY.
175 *
176 */
177EAPI const char * eina_simple_xml_tag_attributes_find(const char *buf, unsigned buflen);
178
179/**
180 * Given a buffer with xml attributes, parse them to key=value pairs.
181 *
182 * @param buf the input string. May not contain \0 terminator.
183 * @param buflen the input string size.
184 * @param func what to call back while parse to do some action. The
185 * first parameter is the given user @a data, the second is the
186 * key (null-terminated) and the last is the value (null
187 * terminated). These strings should not be modified and
188 * reference is just valid until the function return.
189 * @param data data to pass to the callback function.
190 *
191 * @return EINA_TRUE on success or EINA_FALSE if it was aborted by user or
192 * parsing error.
193 */
194EAPI Eina_Bool eina_simple_xml_attributes_parse(const char *buf, unsigned buflen,
195 Eina_Simple_XML_Attribute_Cb func, const void *data);
196
197/**
198 * Create (and append) new attribute to tag.
199 *
200 * @param parent if provided, will be set in the resulting structure
201 * as well as the attribute will be appended to attributes list.
202 * @param key null-terminated string. Must not be NULL.
203 * @param value null-terminated string. If NULL, the empty string will be used.
204 *
205 * @return newly allocated memory or NULL on error. This memory should be
206 * released with eina_simple_xml_attribute_free() or indirectly
207 * with eina_simple_xml_node_tag_free().
208 */
209EAPI Eina_Simple_XML_Attribute * eina_simple_xml_attribute_new(Eina_Simple_XML_Node_Tag *parent, const char *key, const char *value);
210
211/**
212 * Remove attribute from parent and delete it.
213 *
214 * @param attr attribute to release memory.
215 */
216EAPI void eina_simple_xml_attribute_free(Eina_Simple_XML_Attribute *attr);
217
218
219/**
220 * Create new tag. If parent is provided, it is automatically appended.
221 *
222 * @param parent if provided, will be set in the resulting structure
223 * as well as the tag will be appended to children list.
224 * @param name null-terminated string. Must not be NULL.
225 *
226 * @return newly allocated memory or NULL on error. This memory should be
227 * released with eina_simple_xml_node_tag_free() or indirectly
228 * with eina_simple_xml_node_tag_free() of the parent.
229 */
230EAPI Eina_Simple_XML_Node_Tag * eina_simple_xml_node_tag_new(Eina_Simple_XML_Node_Tag *parent, const char *name);
231
232/**
233 * Remove tag from parent and delete it.
234 *
235 * @param tag to release memory.
236 */
237EAPI void eina_simple_xml_node_tag_free(Eina_Simple_XML_Node_Tag *tag);
238
239
240/**
241 * Create new data. If parent is provided, it is automatically appended.
242 *
243 * @param parent if provided, will be set in the resulting structure
244 * as well as the data will be appended to children list.
245 * @param contents string to be used. Must not be NULL.
246 * @param length size in bytes of @a contents.
247 *
248 * @return newly allocated memory or NULL on error. This memory should be
249 * released with eina_simple_xml_node_data_free() or indirectly
250 * with eina_simple_xml_node_tag_free() of the parent.
251 */
252EAPI Eina_Simple_XML_Node_Data * eina_simple_xml_node_data_new(Eina_Simple_XML_Node_Tag *parent, const char *contents, size_t length);
253
254/**
255 * Remove data from parent and delete it.
256 *
257 * @param node to release memory.
258 */
259EAPI void eina_simple_xml_node_data_free(Eina_Simple_XML_Node_Data *node);
260
261
262/**
263 * Create new cdata. If parent is provided, it is automatically appended.
264 *
265 * @param parent if provided, will be set in the resulting structure
266 * as well as the cdata will be appended to children list.
267 * @param contents string to be used. Must not be NULL.
268 * @param length size in bytes of @a content.
269 *
270 * @return newly allocated memory or NULL on error. This memory should be
271 * released with eina_simple_xml_node_cdata_free() or indirectly
272 * with eina_simple_xml_node_tag_free() of the parent.
273 */
274EAPI Eina_Simple_XML_Node_CData * eina_simple_xml_node_cdata_new(Eina_Simple_XML_Node_Tag *parent, const char *contents, size_t length);
275
276/**
277 * Remove cdata from parent and delete it.
278 *
279 * @param node to release memory.
280 */
281EAPI void eina_simple_xml_node_cdata_free(Eina_Simple_XML_Node_Data *node);
282
283
284/**
285 * Create new processing. If parent is provided, it is automatically appended.
286 *
287 * @param parent if provided, will be set in the resulting structure
288 * as well as the processing will be appended to children list.
289 * @param contents string to be used. Must not be NULL.
290 * @param length size in bytes of @a contents.
291 *
292 * @return newly allocated memory or NULL on error. This memory should be
293 * released with eina_simple_xml_node_processing_free() or indirectly
294 * with eina_simple_xml_node_tag_free() of the parent.
295 */
296EAPI Eina_Simple_XML_Node_Processing * eina_simple_xml_node_processing_new(Eina_Simple_XML_Node_Tag *parent, const char *contents, size_t length);
297
298/**
299 * Remove processing from parent and delete it.
300 *
301 * @param node processing to release memory.
302 */
303EAPI void eina_simple_xml_node_processing_free(Eina_Simple_XML_Node_Data *node);
304
305
306/**
307 * Create new doctype. If parent is provided, it is automatically appended.
308 *
309 * @param parent if provided, will be set in the resulting structure
310 * as well as the doctype will be appended to children list.
311 * @param contents string to be used. Must not be NULL.
312 * @param length size in bytes of @a contents.
313 *
314 * @return newly allocated memory or NULL on error. This memory should be
315 * released with eina_simple_xml_node_doctype_free() or indirectly
316 * with eina_simple_xml_node_tag_free() of the parent.
317 */
318EAPI Eina_Simple_XML_Node_Doctype * eina_simple_xml_node_doctype_new(Eina_Simple_XML_Node_Tag *parent, const char *contents, size_t length);
319
320/**
321 * Remove doctype from parent and delete it.
322 *
323 * @param node doctype to release memory.
324 */
325EAPI void eina_simple_xml_node_doctype_free(Eina_Simple_XML_Node_Data *node);
326
327
328/**
329 * Create new comment. If parent is provided, it is automatically appended.
330 *
331 * @param parent if provided, will be set in the resulting structure
332 * as well as the comment will be appended to children list.
333 * @param contents string to be used. Must not be NULL.
334 * @param length size in bytes of @a contents.
335 *
336 * @return newly allocated memory or NULL on error. This memory should be
337 * released with eina_simple_xml_node_comment_free() or indirectly
338 * with eina_simple_xml_node_tag_free() of the parent.
339 */
340EAPI Eina_Simple_XML_Node_Comment * eina_simple_xml_node_comment_new(Eina_Simple_XML_Node_Tag *parent, const char *contents, size_t length);
341
342/**
343 * Remove comment from parent and delete it.
344 *
345 * @param node comment to release memory.
346 */
347EAPI void eina_simple_xml_node_comment_free(Eina_Simple_XML_Node_Data *node);
348
349
350/**
351 * Load a XML node tree based on the given string.
352 *
353 * @param buf the input string. May not contain \0 terminator.
354 * @param buflen the input string size.
355 * @param strip whenever this parser should strip leading and trailing
356 * whitespace.
357 *
358 * @return document root with children tags, or NULL on errors.
359 * Document with errors may return partial tree instead of NULL,
360 * we'll do our best to avoid returning nothing.
361 */
362EAPI Eina_Simple_XML_Node_Root * eina_simple_xml_node_load(const char *buf, unsigned buflen, Eina_Bool strip);
363
364/**
365 * Free node tree build with eina_simple_xml_node_load()
366 *
367 * @param root memory returned by eina_simple_xml_node_load()
368 */
369EAPI void eina_simple_xml_node_root_free(Eina_Simple_XML_Node_Root *root);
370
371/**
372 * Converts the node tree under the given element to a XML string.
373 *
374 * @param node the base node to convert.
375 * @param indent indentation string, or NULL to disable it.
376 *
377 * @return NULL on errors or a newly allocated string on success.
378 */
379EAPI char * eina_simple_xml_node_dump(Eina_Simple_XML_Node *node, const char *indent);
380
381
382/**
383 * @}
384 */
385
386/**
387 * @}
388 */
389
390#endif /* EINA_SIMPLE_XML_H_ */