CUBRID Engine  latest
xml_parser.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 
20 /*
21  * xml_parser.h : XML Parser for CUBRID
22  *
23  */
24 
25 #ifndef _XML_PARSER_H_
26 #define _XML_PARSER_H_
27 
28 #ident "$Id$"
29 
30 #include "config.h"
31 #include "porting.h"
32 /* static linking for expat */
33 #define XML_STATIC
34 #include "expat.h"
35 
36 #define XML_CUB_NO_ERROR 0
37 #define XML_CUB_ERR_BASE 1
38 #define XML_CUB_SCHEMA_BROKEN (XML_CUB_ERR_BASE)
39 #define XML_CUB_OUT_OF_MEMORY (XML_CUB_ERR_BASE + 1)
40 #define XML_CUB_ERR_HEADER_ENCODING (XML_CUB_ERR_BASE + 2)
41 #define XML_CUB_ERR_FILE_READ (XML_CUB_ERR_BASE + 3)
42 #define XML_CUB_ERR_PARSER (XML_CUB_ERR_BASE + 4)
43 #define XML_CUB_ERR_FILE_MISSING (XML_CUB_ERR_BASE + 5)
44 #define XML_CUB_ERR_INCLUDE_LOOP (XML_CUB_ERR_BASE + 6)
45 #define XML_CUB_ERR_PARSER_INIT_FAIL (XML_CUB_ERR_BASE + 7)
46 
47 /* XML parser schema */
48 #define MAX_ELEMENT_NAME 30
49 
50 #define MAX_ENCODE_LEN 10
51 /*
52  * start_xxxxxxxxx - XML element start function
53  * function be called when an element starts
54  *
55  * return: 0 validation OK enter this element , 1 validation NOK do not enter
56  * -1 error abort parsing
57  * (data): user data
58  * (attr): attribute/value pair array
59  */
60 typedef int (*ELEM_START_FUNC) (void *, const char **);
61 
62 /*
63  * end_xxxxxxxxx - XML element end function
64  * function be called when an element starts
65  *
66  * return: 0 parser OK, non-zero value if parser NOK and stop parsing
67  * (data): user data
68  * (el_name): element name
69  */
70 typedef int (*ELEM_END_FUNC) (void *, const char *);
71 
72 /*
73  * handle_xxxxxxxxx - XML element data content handle function
74  * function be called for element data content
75  *
76  * return: 0 handling OK, non-zero if handling NOK and stop parsing
77  * (data): user data
78  * (s): content buffer
79  * (len): length of buffer
80  */
81 typedef int (*ELEM_DATA_FUNC) (void *, const char *, int);
82 
85 {
86  const char *full_name; /* fullname of element with spaces between parents */
87  const int depth; /* first level has depth 1 */
88  ELEM_START_FUNC start_func; /* element start function */
89  ELEM_END_FUNC end_func; /* element end function */
90  ELEM_DATA_FUNC data_func; /* element content handling function */
91 };
92 
93 typedef struct xml_element XML_ELEMENT;
95 {
97  const char *short_name;
98  XML_ELEMENT *parent; /* parent element */
99  XML_ELEMENT *child; /* first child element */
100  XML_ELEMENT *next; /* next element (same level) */
101  XML_ELEMENT *prev; /* next element (same level) */
102  bool match;
103 };
104 
105 #define START_FUNC(el) (el->def->start_func)
106 #define END_FUNC(el) (el->def->end_func)
107 #define DATA_FUNC(el) (el->def->data_func)
108 
109 #define XML_USER_DATA(xml) (xml->ud)
110 
113 {
114  XML_Parser xml_parser; /* XML parser (expat) */
115  int depth; /* current depth of parser */
116  XML_ELEMENT *sc; /* parse tree schema */
117  XML_ELEMENT *ce; /* current element (in schema) */
118  int xml_error; /* XML error code */
119  int xml_error_line; /* line with error */
120  int xml_error_column; /* column with error */
121  char *buf; /* file read parser buffer */
122  bool verbose; /* to print debug info */
123  void *ud; /* user data */
124  char filepath[PATH_MAX]; /* path to current XML file */
125  char encoding[MAX_ENCODE_LEN]; /* encoding to use by parser and subparsers */
126  XML_PARSER_DATA *prev; /* pointer to the encapsulating parser data */
127  XML_PARSER_DATA *next; /* pointer to the encapsulated parser data */
128 };
129 
130 #ifdef __cplusplus
131 extern "C"
132 {
133 #endif
134 
135  XML_Parser xml_init_parser (void *data, const char *xml_file, const char *encoding, XML_ELEMENT_DEF ** element_array,
136  const int count);
137  void xml_destroy_parser (void *data);
138  void xml_destroy_parser_data (void *data);
139  void xml_parser_exec (XML_PARSER_DATA * pd);
140  int xml_check_att_value (const char **attrs, const char *att_name, const char *att_value);
141  int xml_get_att_value (const char **attrs, const char *att_name, char **p_att_value);
142  XML_PARSER_DATA *xml_create_subparser (XML_PARSER_DATA * data, char *new_file);
143 
144 #ifdef __cplusplus
145 }
146 
147 #endif /* _XML_PARSER_H_ */
148 
149 #endif /* _LANGUAGE_SUPPORT_H_ */
const int depth
Definition: xml_parser.h:87
int xml_get_att_value(const char **attrs, const char *att_name, char **p_att_value)
Definition: xml_parser.c:1180
const char * full_name
Definition: xml_parser.h:86
void xml_parser_exec(XML_PARSER_DATA *pd)
Definition: xml_parser.c:1240
XML_ELEMENT * child
Definition: xml_parser.h:99
#define MAX_ENCODE_LEN
Definition: xml_parser.h:50
int(* ELEM_START_FUNC)(void *, const char **)
Definition: xml_parser.h:60
ELEM_END_FUNC end_func
Definition: xml_parser.h:89
XML_ELEMENT * parent
Definition: xml_parser.h:98
XML_PARSER_DATA * xml_create_subparser(XML_PARSER_DATA *data, char *new_file)
Definition: xml_parser.c:1002
XML_ELEMENT_DEF * def
Definition: xml_parser.h:96
int xml_check_att_value(const char **attrs, const char *att_name, const char *att_value)
Definition: xml_parser.c:1152
XML_Parser xml_parser
Definition: xml_parser.h:114
ELEM_START_FUNC start_func
Definition: xml_parser.h:88
XML_ELEMENT * sc
Definition: xml_parser.h:116
int count(int &result, const cub_regex_object &reg, const std::string &src, const int position, const INTL_CODESET codeset)
XML_ELEMENT * prev
Definition: xml_parser.h:101
void xml_destroy_parser(void *data)
Definition: xml_parser.c:977
int(* ELEM_DATA_FUNC)(void *, const char *, int)
Definition: xml_parser.h:81
int(* ELEM_END_FUNC)(void *, const char *)
Definition: xml_parser.h:70
XML_PARSER_DATA * next
Definition: xml_parser.h:127
void xml_destroy_parser_data(void *data)
Definition: xml_parser.c:1067
ELEM_DATA_FUNC data_func
Definition: xml_parser.h:90
XML_Parser xml_init_parser(void *data, const char *xml_file, const char *encoding, XML_ELEMENT_DEF **element_array, const int count)
Definition: xml_parser.c:939
XML_ELEMENT * next
Definition: xml_parser.h:100
const char * short_name
Definition: xml_parser.h:97
XML_PARSER_DATA * prev
Definition: xml_parser.h:126
XML_ELEMENT * ce
Definition: xml_parser.h:117