Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Contents of /branches/destination-access/src/xmlparse.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1807 - (show annotations) (download) (as text)
Wed Sep 23 18:20:13 2015 UTC (9 years, 6 months ago) by amb
File MIME type: text/x-chdr
File size: 4197 byte(s)
Merge the trunk changes back into the destination-access branch.

1 /***************************************
2 A simple XML parser
3
4 Part of the Routino routing software.
5 ******************/ /******************
6 This file Copyright 2010-2015 Andrew M. Bishop
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Affero General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Affero General Public License for more details.
17
18 You should have received a copy of the GNU Affero General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ***************************************/
21
22
23 #ifndef XMLPARSE_H
24 #define XMLPARSE_H /*+ To stop multiple inclusions. +*/
25
26 #include <stdint.h>
27 #include <inttypes.h>
28
29
30 /*+ The maximum number of attributes per tag. +*/
31 #define XMLPARSE_MAX_ATTRS 16
32
33 /*+ The maximum number of subtags per tag. +*/
34 #define XMLPARSE_MAX_SUBTAGS 16
35
36 /*+ A flag to indicate the start and/or end of a tag. +*/
37 #define XMLPARSE_TAG_START 1
38 #define XMLPARSE_TAG_END 2
39
40
41 /*+ A forward definition of the xmltag +*/
42 typedef struct _xmltag xmltag;
43
44
45 /*+ A structure to hold the definition of a tag. +*/
46 struct _xmltag
47 {
48 const char * const name; /*+ The name of the tag - must be in lower case. +*/
49
50 const int nattributes; /*+ The number of valid attributes for the tag. +*/
51 const char * const attributes[XMLPARSE_MAX_ATTRS]; /*+ The valid attributes for the tag. +*/
52
53 int (*callback)(); /*+ The callback function when the tag is seen. +*/
54
55 const xmltag * const subtags[XMLPARSE_MAX_SUBTAGS]; /*+ The list of valid tags contained within this one (null terminated). +*/
56 };
57
58
59 /* XML Parser options */
60
61 #define XMLPARSE_UNKNOWN_ATTRIBUTES 0x0003
62 #define XMLPARSE_UNKNOWN_ATTR_ERROR 0x0000 /* Flag an error and exit. */
63 #define XMLPARSE_UNKNOWN_ATTR_ERRNONAME 0x0001 /* Flag an error and exit unless a namespace is specified. */
64 #define XMLPARSE_UNKNOWN_ATTR_WARN 0x0002 /* Warn about the problem and continue. */
65 #define XMLPARSE_UNKNOWN_ATTR_IGNORE 0x0003 /* Ignore the potential problem. */
66
67 #define XMLPARSE_RETURN_ATTR_ENCODED 0x0004 /* Return the XML attribute strings without decoding them. */
68
69
70 /* XML parser functions */
71
72 int ParseXML(int fd,const xmltag * const *tags,int options);
73
74 uint64_t ParseXML_LineNumber(void);
75
76 void ParseXML_SetError(const char *format, ...);
77 char *ParseXML_GetError(void);
78
79 char *ParseXML_Decode_Entity_Ref(const char *string);
80 char *ParseXML_Decode_Char_Ref(const char *string);
81 char *ParseXML_Encode_Safe_XML(const char *string);
82
83 int ParseXML_IsInteger(const char *string);
84 int ParseXML_IsFloating(const char *string);
85
86 /* Macros to simplify the callback functions */
87
88 #define XMLPARSE_MESSAGE(tag,message) \
89 do \
90 { \
91 ParseXML_SetError(message " in <%s> tag.",tag); \
92 return(1); \
93 } \
94 while(0)
95
96 #define XMLPARSE_INVALID(tag,attribute) \
97 do \
98 { \
99 ParseXML_SetError("Invalid value for '" #attribute "' attribute in <%s> tag.",tag); \
100 return(1); \
101 } \
102 while(0)
103
104 #define XMLPARSE_ASSERT_STRING(tag,attribute) \
105 do \
106 { \
107 if(!attribute) \
108 { \
109 ParseXML_SetError("'" #attribute "' attribute must be specified in <%s> tag.",tag); \
110 return(1); \
111 } \
112 } \
113 while(0)
114
115 #define XMLPARSE_ASSERT_INTEGER(tag,attribute) \
116 do \
117 { \
118 if(!attribute || !*attribute || !ParseXML_IsInteger(attribute)) \
119 { \
120 ParseXML_SetError("'" #attribute "' attribute must be a integer in <%s> tag.",tag); \
121 return(1); \
122 } \
123 } \
124 while(0)
125
126 #define XMLPARSE_ASSERT_FLOATING(tag,attribute) \
127 do \
128 { \
129 if(!attribute || !*attribute || !ParseXML_IsFloating(attribute)) \
130 { \
131 ParseXML_SetError("'" #attribute "' attribute must be a number in <%s> tag.",tag); \
132 return(1); \
133 } \
134 } \
135 while(0)
136
137
138 #endif /* XMLPARSE_H */

Properties

Name Value
cvs:description A simple generic XML parser (header file).