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: incomplete XML Schemas structure implementation
36  * Description: interface to the XML Schemas handling and schema validity
37  *              checking, it is incomplete right now.
38  */
39 
40 #ifndef __XML_SCHEMA_H__
41 #define __XML_SCHEMA_H__
42 
43 #include <libxml/xmlversion.h>
44 
45 #ifdef LIBXML_SCHEMAS_ENABLED
46 
47 #include <libxml/tree.h>
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
53 /**
54  * This error codes are obsolete; not used any more.
55  */
56 typedef enum {
57     XML_SCHEMAS_ERR_OK		= 0,
58     XML_SCHEMAS_ERR_NOROOT	= 1,
59     XML_SCHEMAS_ERR_UNDECLAREDELEM,
60     XML_SCHEMAS_ERR_NOTTOPLEVEL,
61     XML_SCHEMAS_ERR_MISSING,
62     XML_SCHEMAS_ERR_WRONGELEM,
63     XML_SCHEMAS_ERR_NOTYPE,
64     XML_SCHEMAS_ERR_NOROLLBACK,
65     XML_SCHEMAS_ERR_ISABSTRACT,
66     XML_SCHEMAS_ERR_NOTEMPTY,
67     XML_SCHEMAS_ERR_ELEMCONT,
68     XML_SCHEMAS_ERR_HAVEDEFAULT,
69     XML_SCHEMAS_ERR_NOTNILLABLE,
70     XML_SCHEMAS_ERR_EXTRACONTENT,
71     XML_SCHEMAS_ERR_INVALIDATTR,
72     XML_SCHEMAS_ERR_INVALIDELEM,
73     XML_SCHEMAS_ERR_NOTDETERMINIST,
74     XML_SCHEMAS_ERR_CONSTRUCT,
75     XML_SCHEMAS_ERR_INTERNAL,
76     XML_SCHEMAS_ERR_NOTSIMPLE,
77     XML_SCHEMAS_ERR_ATTRUNKNOWN,
78     XML_SCHEMAS_ERR_ATTRINVALID,
79     XML_SCHEMAS_ERR_VALUE,
80     XML_SCHEMAS_ERR_FACET,
81     XML_SCHEMAS_ERR_,
82     XML_SCHEMAS_ERR_XXX
83 } xmlSchemaValidError;
84 
85 /*
86 * ATTENTION: Change xmlSchemaSetValidOptions's check
87 * for invalid values, if adding to the validation
88 * options below.
89 */
90 /**
91  * xmlSchemaValidOption:
92  *
93  * This is the set of XML Schema validation options.
94  */
95 typedef enum {
96     XML_SCHEMA_VAL_VC_I_CREATE			= 1<<0
97 	/* Default/fixed: create an attribute node
98 	* or an element's text node on the instance.
99 	*/
100 } xmlSchemaValidOption;
101 
102 /*
103     XML_SCHEMA_VAL_XSI_ASSEMBLE			= 1<<1,
104 	* assemble schemata using
105 	* xsi:schemaLocation and
106 	* xsi:noNamespaceSchemaLocation
107 */
108 
109 /**
110  * The schemas related types are kept internal
111  */
112 typedef struct _xmlSchema xmlSchema;
113 typedef xmlSchema *xmlSchemaPtr;
114 
115 /**
116  * xmlSchemaValidityErrorFunc:
117  * @ctx: the validation context
118  * @msg: the message
119  * @...: extra arguments
120  *
121  * Signature of an error callback from an XSD validation
122  */
123 typedef void (XMLCDECL *xmlSchemaValidityErrorFunc)
124                  (void *ctx, const char *msg, ...) LIBXML_ATTR_FORMAT(2,3);
125 
126 /**
127  * xmlSchemaValidityWarningFunc:
128  * @ctx: the validation context
129  * @msg: the message
130  * @...: extra arguments
131  *
132  * Signature of a warning callback from an XSD validation
133  */
134 typedef void (XMLCDECL *xmlSchemaValidityWarningFunc)
135                  (void *ctx, const char *msg, ...) LIBXML_ATTR_FORMAT(2,3);
136 
137 /**
138  * A schemas validation context
139  */
140 typedef struct _xmlSchemaParserCtxt xmlSchemaParserCtxt;
141 typedef xmlSchemaParserCtxt *xmlSchemaParserCtxtPtr;
142 
143 typedef struct _xmlSchemaValidCtxt xmlSchemaValidCtxt;
144 typedef xmlSchemaValidCtxt *xmlSchemaValidCtxtPtr;
145 
146 /**
147  * xmlSchemaValidityLocatorFunc:
148  * @ctx: user provided context
149  * @file: returned file information
150  * @line: returned line information
151  *
152  * A schemas validation locator, a callback called by the validator.
153  * This is used when file or node informations are not available
154  * to find out what file and line number are affected
155  *
156  * Returns: 0 in case of success and -1 in case of error
157  */
158 
159 typedef int (XMLCDECL *xmlSchemaValidityLocatorFunc) (void *ctx,
160                            const char **file, unsigned long *line);
161 
162 /*
163  * Interfaces for parsing.
164  */
165 XMLPUBFUN xmlSchemaParserCtxtPtr XMLCALL
166 	    xmlSchemaNewParserCtxt	(const char *URL);
167 XMLPUBFUN xmlSchemaParserCtxtPtr XMLCALL
168 	    xmlSchemaNewMemParserCtxt	(const char *buffer,
169 					 int size);
170 XMLPUBFUN xmlSchemaParserCtxtPtr XMLCALL
171 	    xmlSchemaNewDocParserCtxt	(xmlDocPtr doc);
172 XMLPUBFUN void XMLCALL
173 	    xmlSchemaFreeParserCtxt	(xmlSchemaParserCtxtPtr ctxt);
174 XMLPUBFUN void XMLCALL
175 	    xmlSchemaSetParserErrors	(xmlSchemaParserCtxtPtr ctxt,
176 					 xmlSchemaValidityErrorFunc err,
177 					 xmlSchemaValidityWarningFunc warn,
178 					 void *ctx);
179 XMLPUBFUN void XMLCALL
180 	    xmlSchemaSetParserStructuredErrors(xmlSchemaParserCtxtPtr ctxt,
181 					 xmlStructuredErrorFunc serror,
182 					 void *ctx);
183 XMLPUBFUN int XMLCALL
184 		xmlSchemaGetParserErrors(xmlSchemaParserCtxtPtr ctxt,
185 					xmlSchemaValidityErrorFunc * err,
186 					xmlSchemaValidityWarningFunc * warn,
187 					void **ctx);
188 XMLPUBFUN int XMLCALL
189 		xmlSchemaIsValid	(xmlSchemaValidCtxtPtr ctxt);
190 
191 XMLPUBFUN xmlSchemaPtr XMLCALL
192 	    xmlSchemaParse		(xmlSchemaParserCtxtPtr ctxt);
193 XMLPUBFUN void XMLCALL
194 	    xmlSchemaFree		(xmlSchemaPtr schema);
195 #ifdef LIBXML_OUTPUT_ENABLED
196 XMLPUBFUN void XMLCALL
197 	    xmlSchemaDump		(FILE *output,
198 					 xmlSchemaPtr schema);
199 #endif /* LIBXML_OUTPUT_ENABLED */
200 /*
201  * Interfaces for validating
202  */
203 XMLPUBFUN void XMLCALL
204 	    xmlSchemaSetValidErrors	(xmlSchemaValidCtxtPtr ctxt,
205 					 xmlSchemaValidityErrorFunc err,
206 					 xmlSchemaValidityWarningFunc warn,
207 					 void *ctx);
208 XMLPUBFUN void XMLCALL
209 	    xmlSchemaSetValidStructuredErrors(xmlSchemaValidCtxtPtr ctxt,
210 					 xmlStructuredErrorFunc serror,
211 					 void *ctx);
212 XMLPUBFUN int XMLCALL
213 	    xmlSchemaGetValidErrors	(xmlSchemaValidCtxtPtr ctxt,
214 					 xmlSchemaValidityErrorFunc *err,
215 					 xmlSchemaValidityWarningFunc *warn,
216 					 void **ctx);
217 XMLPUBFUN int XMLCALL
218 	    xmlSchemaSetValidOptions	(xmlSchemaValidCtxtPtr ctxt,
219 					 int options);
220 XMLPUBFUN void XMLCALL
221             xmlSchemaValidateSetFilename(xmlSchemaValidCtxtPtr vctxt,
222 	                                 const char *filename);
223 XMLPUBFUN int XMLCALL
224 	    xmlSchemaValidCtxtGetOptions(xmlSchemaValidCtxtPtr ctxt);
225 
226 XMLPUBFUN xmlSchemaValidCtxtPtr XMLCALL
227 	    xmlSchemaNewValidCtxt	(xmlSchemaPtr schema);
228 XMLPUBFUN void XMLCALL
229 	    xmlSchemaFreeValidCtxt	(xmlSchemaValidCtxtPtr ctxt);
230 XMLPUBFUN int XMLCALL
231 	    xmlSchemaValidateDoc	(xmlSchemaValidCtxtPtr ctxt,
232 					 xmlDocPtr instance);
233 XMLPUBFUN int XMLCALL
234             xmlSchemaValidateOneElement (xmlSchemaValidCtxtPtr ctxt,
235 			                 xmlNodePtr elem);
236 XMLPUBFUN int XMLCALL
237 	    xmlSchemaValidateStream	(xmlSchemaValidCtxtPtr ctxt,
238 					 xmlParserInputBufferPtr input,
239 					 xmlCharEncoding enc,
240 					 xmlSAXHandlerPtr sax,
241 					 void *user_data);
242 XMLPUBFUN int XMLCALL
243 	    xmlSchemaValidateFile	(xmlSchemaValidCtxtPtr ctxt,
244 					 const char * filename,
245 					 int options);
246 
247 XMLPUBFUN xmlParserCtxtPtr XMLCALL
248 	    xmlSchemaValidCtxtGetParserCtxt(xmlSchemaValidCtxtPtr ctxt);
249 
250 /*
251  * Interface to insert Schemas SAX validation in a SAX stream
252  */
253 typedef struct _xmlSchemaSAXPlug xmlSchemaSAXPlugStruct;
254 typedef xmlSchemaSAXPlugStruct *xmlSchemaSAXPlugPtr;
255 
256 XMLPUBFUN xmlSchemaSAXPlugPtr XMLCALL
257             xmlSchemaSAXPlug		(xmlSchemaValidCtxtPtr ctxt,
258 					 xmlSAXHandlerPtr *sax,
259 					 void **user_data);
260 XMLPUBFUN int XMLCALL
261             xmlSchemaSAXUnplug		(xmlSchemaSAXPlugPtr plug);
262 
263 
264 XMLPUBFUN void XMLCALL
265             xmlSchemaValidateSetLocator	(xmlSchemaValidCtxtPtr vctxt,
266 					 xmlSchemaValidityLocatorFunc f,
267 					 void *ctxt);
268 
269 #ifdef __cplusplus
270 }
271 #endif
272 
273 #endif /* LIBXML_SCHEMAS_ENABLED */
274 #endif /* __XML_SCHEMA_H__ */
275