1 /* Copyright (c) 2000, 2002, 2003, 2005, 2007 MySQL AB
2    Use is subject to license terms
3 
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; version 2 of the License.
7 
8    This program is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11    GNU General Public License for more details.
12 
13    You should have received a copy of the GNU General Public License
14    along with this program; if not, write to the Free Software
15    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1335  USA  */
16 
17 
18 #ifndef _my_xml_h
19 #define _my_xml_h
20 
21 #ifdef	__cplusplus
22 extern "C" {
23 #endif
24 
25 
26 #define MY_XML_OK	0
27 #define MY_XML_ERROR	1
28 
29 /*
30   A flag whether to use absolute tag names in call-back functions,
31   like "a", "a.b" and "a.b.c" (used in character set file parser),
32   or relative names like "a", "b" and "c".
33 */
34 #define MY_XML_FLAG_RELATIVE_NAMES 1
35 
36 /*
37   A flag whether to skip normilization of text values before calling
38   call-back functions: i.e. skip leading/trailing spaces,
39   \r, \n, \t characters.
40 */
41 #define MY_XML_FLAG_SKIP_TEXT_NORMALIZATION 2
42 
43 enum my_xml_node_type
44 {
45   MY_XML_NODE_TAG,   /* can have TAG, ATTR and TEXT children */
46   MY_XML_NODE_ATTR,  /* can have TEXT children               */
47   MY_XML_NODE_TEXT   /* cannot have children                 */
48 };
49 
50 typedef struct xml_stack_st
51 {
52   int flags;
53   enum my_xml_node_type current_node_type;
54   char errstr[128];
55 
56   struct {
57     char static_buffer[128];
58     char *buffer;
59     size_t buffer_size;
60     char *start;
61     char *end;
62   } attr;
63 
64   const char *beg;
65   const char *cur;
66   const char *end;
67   void *user_data;
68   int  (*enter)(struct xml_stack_st *st,const char *val, size_t len);
69   int  (*value)(struct xml_stack_st *st,const char *val, size_t len);
70   int  (*leave_xml)(struct xml_stack_st *st,const char *val, size_t len);
71 } MY_XML_PARSER;
72 
73 void my_xml_parser_create(MY_XML_PARSER *st);
74 void my_xml_parser_free(MY_XML_PARSER *st);
75 int  my_xml_parse(MY_XML_PARSER *st,const char *str, size_t len);
76 
77 void my_xml_set_value_handler(MY_XML_PARSER *st, int (*)(MY_XML_PARSER *,
78 							 const char *,
79 							 size_t len));
80 void my_xml_set_enter_handler(MY_XML_PARSER *st, int (*)(MY_XML_PARSER *,
81 							 const char *,
82 							 size_t len));
83 void my_xml_set_leave_handler(MY_XML_PARSER *st, int (*)(MY_XML_PARSER *,
84 							 const char *,
85 							 size_t len));
86 void my_xml_set_user_data(MY_XML_PARSER *st, void *);
87 
88 size_t my_xml_error_pos(MY_XML_PARSER *st);
89 uint my_xml_error_lineno(MY_XML_PARSER *st);
90 
91 const char *my_xml_error_string(MY_XML_PARSER *st);
92 
93 #ifdef	__cplusplus
94 }
95 #endif
96 
97 #endif /* _my_xml_h */
98