1 /* libxml2 - Library for parsing XML documents
2  * Copyright (C) 2006-2019 Free Software Foundation, Inc.
3  *
4  * This file is not part of the GNU gettext program, but is used with
5  * GNU gettext.
6  *
7  * The original copyright notice is as follows:
8  */
9 
10 /*
11  * Copyright (C) 1998-2012 Daniel Veillard.  All Rights Reserved.
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining a copy
14  * of this software and associated documentation files (the "Software"), to deal
15  * in the Software without restriction, including without limitation the rights
16  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17  * copies of the Software, and to permit persons to whom the Software is fur-
18  * nished to do so, subject to the following conditions:
19  *
20  * The above copyright notice and this permission notice shall be included in
21  * all copies or substantial portions of the Software.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT-
25  * NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
26  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29  * THE SOFTWARE.
30  *
31  * Author: Daniel Veillard
32  */
33 
34 /*
35  * Summary: implementation of the Relax-NG validation
36  * Description: implementation of the Relax-NG validation
37  */
38 
39 #ifndef __XML_RELAX_NG__
40 #define __XML_RELAX_NG__
41 
42 #include <libxml/xmlversion.h>
43 #include <libxml/hash.h>
44 #include <libxml/xmlstring.h>
45 
46 #ifdef LIBXML_SCHEMAS_ENABLED
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
52 typedef struct _xmlRelaxNG xmlRelaxNG;
53 typedef xmlRelaxNG *xmlRelaxNGPtr;
54 
55 
56 /**
57  * xmlRelaxNGValidityErrorFunc:
58  * @ctx: the validation context
59  * @msg: the message
60  * @...: extra arguments
61  *
62  * Signature of an error callback from a Relax-NG validation
63  */
64 typedef void (XMLCDECL *xmlRelaxNGValidityErrorFunc) (void *ctx,
65 						      const char *msg,
66 						      ...) LIBXML_ATTR_FORMAT(2,3);
67 
68 /**
69  * xmlRelaxNGValidityWarningFunc:
70  * @ctx: the validation context
71  * @msg: the message
72  * @...: extra arguments
73  *
74  * Signature of a warning callback from a Relax-NG validation
75  */
76 typedef void (XMLCDECL *xmlRelaxNGValidityWarningFunc) (void *ctx,
77 							const char *msg,
78 							...) LIBXML_ATTR_FORMAT(2,3);
79 
80 /**
81  * A schemas validation context
82  */
83 typedef struct _xmlRelaxNGParserCtxt xmlRelaxNGParserCtxt;
84 typedef xmlRelaxNGParserCtxt *xmlRelaxNGParserCtxtPtr;
85 
86 typedef struct _xmlRelaxNGValidCtxt xmlRelaxNGValidCtxt;
87 typedef xmlRelaxNGValidCtxt *xmlRelaxNGValidCtxtPtr;
88 
89 /*
90  * xmlRelaxNGValidErr:
91  *
92  * List of possible Relax NG validation errors
93  */
94 typedef enum {
95     XML_RELAXNG_OK = 0,
96     XML_RELAXNG_ERR_MEMORY,
97     XML_RELAXNG_ERR_TYPE,
98     XML_RELAXNG_ERR_TYPEVAL,
99     XML_RELAXNG_ERR_DUPID,
100     XML_RELAXNG_ERR_TYPECMP,
101     XML_RELAXNG_ERR_NOSTATE,
102     XML_RELAXNG_ERR_NODEFINE,
103     XML_RELAXNG_ERR_LISTEXTRA,
104     XML_RELAXNG_ERR_LISTEMPTY,
105     XML_RELAXNG_ERR_INTERNODATA,
106     XML_RELAXNG_ERR_INTERSEQ,
107     XML_RELAXNG_ERR_INTEREXTRA,
108     XML_RELAXNG_ERR_ELEMNAME,
109     XML_RELAXNG_ERR_ATTRNAME,
110     XML_RELAXNG_ERR_ELEMNONS,
111     XML_RELAXNG_ERR_ATTRNONS,
112     XML_RELAXNG_ERR_ELEMWRONGNS,
113     XML_RELAXNG_ERR_ATTRWRONGNS,
114     XML_RELAXNG_ERR_ELEMEXTRANS,
115     XML_RELAXNG_ERR_ATTREXTRANS,
116     XML_RELAXNG_ERR_ELEMNOTEMPTY,
117     XML_RELAXNG_ERR_NOELEM,
118     XML_RELAXNG_ERR_NOTELEM,
119     XML_RELAXNG_ERR_ATTRVALID,
120     XML_RELAXNG_ERR_CONTENTVALID,
121     XML_RELAXNG_ERR_EXTRACONTENT,
122     XML_RELAXNG_ERR_INVALIDATTR,
123     XML_RELAXNG_ERR_DATAELEM,
124     XML_RELAXNG_ERR_VALELEM,
125     XML_RELAXNG_ERR_LISTELEM,
126     XML_RELAXNG_ERR_DATATYPE,
127     XML_RELAXNG_ERR_VALUE,
128     XML_RELAXNG_ERR_LIST,
129     XML_RELAXNG_ERR_NOGRAMMAR,
130     XML_RELAXNG_ERR_EXTRADATA,
131     XML_RELAXNG_ERR_LACKDATA,
132     XML_RELAXNG_ERR_INTERNAL,
133     XML_RELAXNG_ERR_ELEMWRONG,
134     XML_RELAXNG_ERR_TEXTWRONG
135 } xmlRelaxNGValidErr;
136 
137 /*
138  * xmlRelaxNGParserFlags:
139  *
140  * List of possible Relax NG Parser flags
141  */
142 typedef enum {
143     XML_RELAXNGP_NONE = 0,
144     XML_RELAXNGP_FREE_DOC = 1,
145     XML_RELAXNGP_CRNG = 2
146 } xmlRelaxNGParserFlag;
147 
148 XMLPUBFUN int XMLCALL
149 		    xmlRelaxNGInitTypes		(void);
150 XMLPUBFUN void XMLCALL
151 		    xmlRelaxNGCleanupTypes	(void);
152 
153 /*
154  * Interfaces for parsing.
155  */
156 XMLPUBFUN xmlRelaxNGParserCtxtPtr XMLCALL
157 		    xmlRelaxNGNewParserCtxt	(const char *URL);
158 XMLPUBFUN xmlRelaxNGParserCtxtPtr XMLCALL
159 		    xmlRelaxNGNewMemParserCtxt	(const char *buffer,
160 						 int size);
161 XMLPUBFUN xmlRelaxNGParserCtxtPtr XMLCALL
162 		    xmlRelaxNGNewDocParserCtxt	(xmlDocPtr doc);
163 
164 XMLPUBFUN int XMLCALL
165 		    xmlRelaxParserSetFlag	(xmlRelaxNGParserCtxtPtr ctxt,
166 						 int flag);
167 
168 XMLPUBFUN void XMLCALL
169 		    xmlRelaxNGFreeParserCtxt	(xmlRelaxNGParserCtxtPtr ctxt);
170 XMLPUBFUN void XMLCALL
171 		    xmlRelaxNGSetParserErrors(xmlRelaxNGParserCtxtPtr ctxt,
172 					 xmlRelaxNGValidityErrorFunc err,
173 					 xmlRelaxNGValidityWarningFunc warn,
174 					 void *ctx);
175 XMLPUBFUN int XMLCALL
176 		    xmlRelaxNGGetParserErrors(xmlRelaxNGParserCtxtPtr ctxt,
177 					 xmlRelaxNGValidityErrorFunc *err,
178 					 xmlRelaxNGValidityWarningFunc *warn,
179 					 void **ctx);
180 XMLPUBFUN void XMLCALL
181 		    xmlRelaxNGSetParserStructuredErrors(
182 					 xmlRelaxNGParserCtxtPtr ctxt,
183 					 xmlStructuredErrorFunc serror,
184 					 void *ctx);
185 XMLPUBFUN xmlRelaxNGPtr XMLCALL
186 		    xmlRelaxNGParse		(xmlRelaxNGParserCtxtPtr ctxt);
187 XMLPUBFUN void XMLCALL
188 		    xmlRelaxNGFree		(xmlRelaxNGPtr schema);
189 #ifdef LIBXML_OUTPUT_ENABLED
190 XMLPUBFUN void XMLCALL
191 		    xmlRelaxNGDump		(FILE *output,
192 					 xmlRelaxNGPtr schema);
193 XMLPUBFUN void XMLCALL
194 		    xmlRelaxNGDumpTree	(FILE * output,
195 					 xmlRelaxNGPtr schema);
196 #endif /* LIBXML_OUTPUT_ENABLED */
197 /*
198  * Interfaces for validating
199  */
200 XMLPUBFUN void XMLCALL
201 		    xmlRelaxNGSetValidErrors(xmlRelaxNGValidCtxtPtr ctxt,
202 					 xmlRelaxNGValidityErrorFunc err,
203 					 xmlRelaxNGValidityWarningFunc warn,
204 					 void *ctx);
205 XMLPUBFUN int XMLCALL
206 		    xmlRelaxNGGetValidErrors(xmlRelaxNGValidCtxtPtr ctxt,
207 					 xmlRelaxNGValidityErrorFunc *err,
208 					 xmlRelaxNGValidityWarningFunc *warn,
209 					 void **ctx);
210 XMLPUBFUN void XMLCALL
211 			xmlRelaxNGSetValidStructuredErrors(xmlRelaxNGValidCtxtPtr ctxt,
212 					  xmlStructuredErrorFunc serror, void *ctx);
213 XMLPUBFUN xmlRelaxNGValidCtxtPtr XMLCALL
214 		    xmlRelaxNGNewValidCtxt	(xmlRelaxNGPtr schema);
215 XMLPUBFUN void XMLCALL
216 		    xmlRelaxNGFreeValidCtxt	(xmlRelaxNGValidCtxtPtr ctxt);
217 XMLPUBFUN int XMLCALL
218 		    xmlRelaxNGValidateDoc	(xmlRelaxNGValidCtxtPtr ctxt,
219 						 xmlDocPtr doc);
220 /*
221  * Interfaces for progressive validation when possible
222  */
223 XMLPUBFUN int XMLCALL
224 		    xmlRelaxNGValidatePushElement	(xmlRelaxNGValidCtxtPtr ctxt,
225 					 xmlDocPtr doc,
226 					 xmlNodePtr elem);
227 XMLPUBFUN int XMLCALL
228 		    xmlRelaxNGValidatePushCData	(xmlRelaxNGValidCtxtPtr ctxt,
229 					 const xmlChar *data,
230 					 int len);
231 XMLPUBFUN int XMLCALL
232 		    xmlRelaxNGValidatePopElement	(xmlRelaxNGValidCtxtPtr ctxt,
233 					 xmlDocPtr doc,
234 					 xmlNodePtr elem);
235 XMLPUBFUN int XMLCALL
236 		    xmlRelaxNGValidateFullElement	(xmlRelaxNGValidCtxtPtr ctxt,
237 					 xmlDocPtr doc,
238 					 xmlNodePtr elem);
239 
240 #ifdef __cplusplus
241 }
242 #endif
243 
244 #endif /* LIBXML_SCHEMAS_ENABLED */
245 
246 #endif /* __XML_RELAX_NG__ */
247