Routino SVN Repository Browser

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

ViewVC logotype

Annotation of /trunk/src/xmlparse.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1784 - (hide annotations) (download) (as text)
Sat Aug 15 13:08:37 2015 UTC (9 years, 7 months ago) by amb
File MIME type: text/x-chdr
File size: 4197 byte(s)
Merge libroutino branch back into the trunk.

1 amb 335 /***************************************
2     A simple XML parser
3    
4     Part of the Routino routing software.
5     ******************/ /******************
6 amb 1719 This file Copyright 2010-2015 Andrew M. Bishop
7 amb 335
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 amb 1235 #include <stdint.h>
27 amb 1519 #include <inttypes.h>
28 amb 335
29 amb 1235
30 amb 335 /*+ 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 amb 344 /*+ 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 amb 335
40 amb 344
41 amb 335 /*+ 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 amb 1719 const char * const name; /*+ The name of the tag - must be in lower case. +*/
49 amb 335
50 amb 1719 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 amb 335
53 amb 1719 int (*callback)(); /*+ The callback function when the tag is seen. +*/
54 amb 335
55 amb 1719 const xmltag * const subtags[XMLPARSE_MAX_SUBTAGS]; /*+ The list of valid tags contained within this one (null terminated). +*/
56 amb 335 };
57    
58    
59 amb 366 /* XML Parser options */
60    
61     #define XMLPARSE_UNKNOWN_ATTRIBUTES 0x0003
62 amb 374 #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 amb 366
67 amb 374 #define XMLPARSE_RETURN_ATTR_ENCODED 0x0004 /* Return the XML attribute strings without decoding them. */
68 amb 366
69 amb 374
70 amb 363 /* XML parser functions */
71 amb 335
72 amb 1719 int ParseXML(int fd,const xmltag * const *tags,int options);
73 amb 335
74 amb 1235 uint64_t ParseXML_LineNumber(void);
75 amb 335
76 amb 1784 void ParseXML_SetError(const char *format, ...);
77     char *ParseXML_GetError(void);
78    
79 amb 377 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 amb 348
83 amb 773 int ParseXML_IsInteger(const char *string);
84     int ParseXML_IsFloating(const char *string);
85 amb 356
86 amb 363 /* Macros to simplify the callback functions */
87    
88     #define XMLPARSE_MESSAGE(tag,message) \
89     do \
90     { \
91 amb 1784 ParseXML_SetError(message " in <%s> tag.",tag); \
92 amb 363 return(1); \
93     } \
94     while(0)
95    
96     #define XMLPARSE_INVALID(tag,attribute) \
97     do \
98     { \
99 amb 1784 ParseXML_SetError("Invalid value for '" #attribute "' attribute in <%s> tag.",tag); \
100 amb 363 return(1); \
101     } \
102     while(0)
103    
104     #define XMLPARSE_ASSERT_STRING(tag,attribute) \
105     do \
106     { \
107 amb 389 if(!attribute) \
108 amb 363 { \
109 amb 1784 ParseXML_SetError("'" #attribute "' attribute must be specified in <%s> tag.",tag); \
110 amb 363 return(1); \
111     } \
112     } \
113     while(0)
114    
115 amb 773 #define XMLPARSE_ASSERT_INTEGER(tag,attribute) \
116 amb 363 do \
117     { \
118 amb 773 if(!attribute || !*attribute || !ParseXML_IsInteger(attribute)) \
119 amb 363 { \
120 amb 1784 ParseXML_SetError("'" #attribute "' attribute must be a integer in <%s> tag.",tag); \
121 amb 363 return(1); \
122     } \
123     } \
124     while(0)
125    
126 amb 773 #define XMLPARSE_ASSERT_FLOATING(tag,attribute) \
127 amb 363 do \
128     { \
129 amb 773 if(!attribute || !*attribute || !ParseXML_IsFloating(attribute)) \
130 amb 363 { \
131 amb 1784 ParseXML_SetError("'" #attribute "' attribute must be a number in <%s> tag.",tag); \
132 amb 363 return(1); \
133     } \
134     } \
135     while(0)
136    
137    
138 amb 335 #endif /* XMLPARSE_H */

Properties

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