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