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