-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy pathxml_parser.h
More file actions
149 lines (129 loc) · 4.67 KB
/
xml_parser.h
File metadata and controls
149 lines (129 loc) · 4.67 KB
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
/*
* Copyright 2008 Search Solution Corporation
* Copyright 2016 CUBRID Corporation
*
* Licensed 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.
*
*/
/*
* xml_parser.h : XML Parser for CUBRID
*
*/
#ifndef _XML_PARSER_H_
#define _XML_PARSER_H_
#ident "$Id$"
#include "config.h"
#include "porting.h"
/* static linking for expat */
#define XML_STATIC
#include "expat.h"
#define XML_CUB_NO_ERROR 0
#define XML_CUB_ERR_BASE 1
#define XML_CUB_SCHEMA_BROKEN (XML_CUB_ERR_BASE)
#define XML_CUB_OUT_OF_MEMORY (XML_CUB_ERR_BASE + 1)
#define XML_CUB_ERR_HEADER_ENCODING (XML_CUB_ERR_BASE + 2)
#define XML_CUB_ERR_FILE_READ (XML_CUB_ERR_BASE + 3)
#define XML_CUB_ERR_PARSER (XML_CUB_ERR_BASE + 4)
#define XML_CUB_ERR_FILE_MISSING (XML_CUB_ERR_BASE + 5)
#define XML_CUB_ERR_INCLUDE_LOOP (XML_CUB_ERR_BASE + 6)
#define XML_CUB_ERR_PARSER_INIT_FAIL (XML_CUB_ERR_BASE + 7)
/* XML parser schema */
#define MAX_ELEMENT_NAME 30
#define MAX_ENCODE_LEN 10
/*
* start_xxxxxxxxx - XML element start function
* function be called when an element starts
*
* return: 0 validation OK enter this element , 1 validation NOK do not enter
* -1 error abort parsing
* (data): user data
* (attr): attribute/value pair array
*/
typedef int (*ELEM_START_FUNC) (void *, const char **);
/*
* end_xxxxxxxxx - XML element end function
* function be called when an element starts
*
* return: 0 parser OK, non-zero value if parser NOK and stop parsing
* (data): user data
* (el_name): element name
*/
typedef int (*ELEM_END_FUNC) (void *, const char *);
/*
* handle_xxxxxxxxx - XML element data content handle function
* function be called for element data content
*
* return: 0 handling OK, non-zero if handling NOK and stop parsing
* (data): user data
* (s): content buffer
* (len): length of buffer
*/
typedef int (*ELEM_DATA_FUNC) (void *, const char *, int);
typedef struct xml_element_def XML_ELEMENT_DEF;
struct xml_element_def
{
const char *full_name; /* fullname of element with spaces between parents */
const int depth; /* first level has depth 1 */
ELEM_START_FUNC start_func; /* element start function */
ELEM_END_FUNC end_func; /* element end function */
ELEM_DATA_FUNC data_func; /* element content handling function */
};
typedef struct xml_element XML_ELEMENT;
struct xml_element
{
XML_ELEMENT_DEF *def;
const char *short_name;
XML_ELEMENT *parent; /* parent element */
XML_ELEMENT *child; /* first child element */
XML_ELEMENT *next; /* next element (same level) */
XML_ELEMENT *prev; /* next element (same level) */
bool match;
};
#define START_FUNC(el) (el->def->start_func)
#define END_FUNC(el) (el->def->end_func)
#define DATA_FUNC(el) (el->def->data_func)
#define XML_USER_DATA(xml) (xml->ud)
typedef struct xml_parser_data XML_PARSER_DATA;
struct xml_parser_data
{
XML_Parser xml_parser; /* XML parser (expat) */
int depth; /* current depth of parser */
XML_ELEMENT *sc; /* parse tree schema */
XML_ELEMENT *ce; /* current element (in schema) */
int xml_error; /* XML error code */
int xml_error_line; /* line with error */
int xml_error_column; /* column with error */
char *buf; /* file read parser buffer */
bool verbose; /* to print debug info */
void *ud; /* user data */
char filepath[PATH_MAX]; /* path to current XML file */
char encoding[MAX_ENCODE_LEN]; /* encoding to use by parser and subparsers */
XML_PARSER_DATA *prev; /* pointer to the encapsulating parser data */
XML_PARSER_DATA *next; /* pointer to the encapsulated parser data */
};
#ifdef __cplusplus
extern "C"
{
#endif
XML_Parser xml_init_parser (void *data, const char *xml_file, const char *encoding, XML_ELEMENT_DEF ** element_array,
const int count);
void xml_destroy_parser (void *data);
void xml_destroy_parser_data (void *data);
void xml_parser_exec (XML_PARSER_DATA * pd);
int xml_check_att_value (const char **attrs, const char *att_name, const char *att_value);
int xml_get_att_value (const char **attrs, const char *att_name, char **p_att_value);
XML_PARSER_DATA *xml_create_subparser (XML_PARSER_DATA * data, char *new_file);
#ifdef __cplusplus
}
#endif /* _XML_PARSER_H_ */
#endif /* _LANGUAGE_SUPPORT_H_ */