/src/libxml2/xmlschemas.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * schemas.c : implementation of the XML Schema handling and |
3 | | * schema validity checking |
4 | | * |
5 | | * See Copyright for the status of this software. |
6 | | * |
7 | | * Author: Daniel Veillard |
8 | | */ |
9 | | |
10 | | /* |
11 | | * TODO: |
12 | | * - when types are redefined in includes, check that all |
13 | | * types in the redef list are equal |
14 | | * -> need a type equality operation. |
15 | | * - if we don't intend to use the schema for schemas, we |
16 | | * need to validate all schema attributes (ref, type, name) |
17 | | * against their types. |
18 | | * - Eliminate item creation for: ?? |
19 | | * |
20 | | * URGENT TODO: |
21 | | * - For xsi-driven schema acquisition, augment the IDCs after every |
22 | | * acquisition episode (xmlSchemaAugmentIDC). |
23 | | * |
24 | | * NOTES: |
25 | | * - Eliminated item creation for: <restriction>, <extension>, |
26 | | * <simpleContent>, <complexContent>, <list>, <union> |
27 | | * |
28 | | * PROBLEMS: |
29 | | * - http://lists.w3.org/Archives/Public/www-xml-schema-comments/2005JulSep/0337.html |
30 | | * IDC XPath expression and chameleon includes: the targetNamespace is changed, so |
31 | | * XPath will have trouble to resolve to this namespace, since not known. |
32 | | * |
33 | | * |
34 | | * CONSTRAINTS: |
35 | | * |
36 | | * Schema Component Constraint: |
37 | | * All Group Limited (cos-all-limited) |
38 | | * Status: complete |
39 | | * (1.2) |
40 | | * In #xmlSchemaGroupDefReferenceTermFixup and |
41 | | * (2) |
42 | | * In #xmlSchemaParseModelGroup |
43 | | * TODO: Actually this should go to component-level checks, |
44 | | * but is done here due to performance. Move it to an other layer |
45 | | * is schema construction via an API is implemented. |
46 | | */ |
47 | | |
48 | | /* To avoid EBCDIC trouble when parsing on zOS */ |
49 | | #if defined(__MVS__) |
50 | | #pragma convert("ISO8859-1") |
51 | | #endif |
52 | | |
53 | | #define IN_LIBXML |
54 | | #include "libxml.h" |
55 | | |
56 | | #ifdef LIBXML_SCHEMAS_ENABLED |
57 | | |
58 | | #include <string.h> |
59 | | #include <libxml/xmlmemory.h> |
60 | | #include <libxml/parser.h> |
61 | | #include <libxml/parserInternals.h> |
62 | | #include <libxml/hash.h> |
63 | | #include <libxml/uri.h> |
64 | | #include <libxml/xmlschemas.h> |
65 | | #include <libxml/schemasInternals.h> |
66 | | #include <libxml/xmlschemastypes.h> |
67 | | #include <libxml/xmlautomata.h> |
68 | | #include <libxml/xmlregexp.h> |
69 | | #include <libxml/dict.h> |
70 | | #include <libxml/encoding.h> |
71 | | #include <libxml/xmlIO.h> |
72 | | #ifdef LIBXML_PATTERN_ENABLED |
73 | | #include <libxml/pattern.h> |
74 | | #endif |
75 | | #ifdef LIBXML_READER_ENABLED |
76 | | #include <libxml/xmlreader.h> |
77 | | #endif |
78 | | |
79 | | #include "private/error.h" |
80 | | #include "private/memory.h" |
81 | | #include "private/string.h" |
82 | | |
83 | | /* #define WXS_ELEM_DECL_CONS_ENABLED */ |
84 | | |
85 | | /* #define ENABLE_PARTICLE_RESTRICTION 1 */ |
86 | | |
87 | | #define ENABLE_REDEFINE |
88 | | |
89 | | /* #define ENABLE_NAMED_LOCALS */ |
90 | | |
91 | | /* #define ENABLE_IDC_NODE_TABLES_TEST */ |
92 | | |
93 | | #define DUMP_CONTENT_MODEL |
94 | | |
95 | | #ifdef LIBXML_READER_ENABLED |
96 | | /* #define XML_SCHEMA_READER_ENABLED */ |
97 | | #endif |
98 | | |
99 | 0 | #define UNBOUNDED (1 << 30) |
100 | | |
101 | 0 | #define XML_SCHEMAS_NO_NAMESPACE (const xmlChar *) "##" |
102 | | |
103 | | /* |
104 | | * The XML Schemas namespaces |
105 | | */ |
106 | | static const xmlChar *xmlSchemaNs = (const xmlChar *) |
107 | | "http://www.w3.org/2001/XMLSchema"; |
108 | | |
109 | | static const xmlChar *xmlSchemaInstanceNs = (const xmlChar *) |
110 | | "http://www.w3.org/2001/XMLSchema-instance"; |
111 | | |
112 | | static const xmlChar *xmlNamespaceNs = (const xmlChar *) |
113 | | "http://www.w3.org/2000/xmlns/"; |
114 | | |
115 | | /* |
116 | | * Come casting macros. |
117 | | */ |
118 | 0 | #define ACTXT_CAST (xmlSchemaAbstractCtxtPtr) |
119 | 0 | #define PCTXT_CAST (xmlSchemaParserCtxtPtr) |
120 | | #define VCTXT_CAST (xmlSchemaValidCtxtPtr) |
121 | 0 | #define WXS_BASIC_CAST (xmlSchemaBasicItemPtr) |
122 | 0 | #define WXS_TREE_CAST (xmlSchemaTreeItemPtr) |
123 | 0 | #define WXS_PTC_CAST (xmlSchemaParticlePtr) |
124 | 0 | #define WXS_TYPE_CAST (xmlSchemaTypePtr) |
125 | 0 | #define WXS_ELEM_CAST (xmlSchemaElementPtr) |
126 | 0 | #define WXS_ATTR_GROUP_CAST (xmlSchemaAttributeGroupPtr) |
127 | 0 | #define WXS_ATTR_CAST (xmlSchemaAttributePtr) |
128 | 0 | #define WXS_ATTR_USE_CAST (xmlSchemaAttributeUsePtr) |
129 | 0 | #define WXS_ATTR_PROHIB_CAST (xmlSchemaAttributeUseProhibPtr) |
130 | 0 | #define WXS_MODEL_GROUPDEF_CAST (xmlSchemaModelGroupDefPtr) |
131 | 0 | #define WXS_MODEL_GROUP_CAST (xmlSchemaModelGroupPtr) |
132 | 0 | #define WXS_IDC_CAST (xmlSchemaIDCPtr) |
133 | 0 | #define WXS_QNAME_CAST (xmlSchemaQNameRefPtr) |
134 | 0 | #define WXS_LIST_CAST (xmlSchemaItemListPtr) |
135 | | |
136 | | /* |
137 | | * Macros to query common properties of components. |
138 | | */ |
139 | 0 | #define WXS_ITEM_NODE(i) xmlSchemaGetComponentNode(WXS_BASIC_CAST (i)) |
140 | | |
141 | 0 | #define WXS_ITEM_TYPE_NAME(i) xmlSchemaGetComponentTypeStr(WXS_BASIC_CAST (i)) |
142 | | /* |
143 | | * Macros for element declarations. |
144 | | */ |
145 | 0 | #define WXS_ELEM_TYPEDEF(e) (e)->subtypes |
146 | | |
147 | 0 | #define WXS_SUBST_HEAD(item) (item)->refDecl |
148 | | /* |
149 | | * Macros for attribute declarations. |
150 | | */ |
151 | 0 | #define WXS_ATTR_TYPEDEF(a) (a)->subtypes |
152 | | /* |
153 | | * Macros for attribute uses. |
154 | | */ |
155 | 0 | #define WXS_ATTRUSE_DECL(au) (WXS_ATTR_USE_CAST (au))->attrDecl |
156 | | |
157 | 0 | #define WXS_ATTRUSE_TYPEDEF(au) WXS_ATTR_TYPEDEF(WXS_ATTRUSE_DECL( WXS_ATTR_USE_CAST au)) |
158 | | |
159 | 0 | #define WXS_ATTRUSE_DECL_NAME(au) (WXS_ATTRUSE_DECL(au))->name |
160 | | |
161 | 0 | #define WXS_ATTRUSE_DECL_TNS(au) (WXS_ATTRUSE_DECL(au))->targetNamespace |
162 | | /* |
163 | | * Macros for attribute groups. |
164 | | */ |
165 | 0 | #define WXS_ATTR_GROUP_HAS_REFS(ag) ((WXS_ATTR_GROUP_CAST (ag))->flags & XML_SCHEMAS_ATTRGROUP_HAS_REFS) |
166 | 0 | #define WXS_ATTR_GROUP_EXPANDED(ag) ((WXS_ATTR_GROUP_CAST (ag))->flags & XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED) |
167 | | /* |
168 | | * Macros for particles. |
169 | | */ |
170 | 0 | #define WXS_PARTICLE(p) WXS_PTC_CAST (p) |
171 | | |
172 | 0 | #define WXS_PARTICLE_TERM(p) (WXS_PARTICLE(p))->children |
173 | | |
174 | | #define WXS_PARTICLE_TERM_AS_ELEM(p) (WXS_ELEM_CAST WXS_PARTICLE_TERM(p)) |
175 | | |
176 | | #define WXS_PARTICLE_MODEL(p) WXS_MODEL_GROUP_CAST WXS_PARTICLE(p)->children |
177 | | /* |
178 | | * Macros for model groups definitions. |
179 | | */ |
180 | 0 | #define WXS_MODELGROUPDEF_MODEL(mgd) (WXS_MODEL_GROUP_CAST (mgd))->children |
181 | | /* |
182 | | * Macros for model groups. |
183 | | */ |
184 | | #define WXS_IS_MODEL_GROUP(i) \ |
185 | 0 | (((i)->type == XML_SCHEMA_TYPE_SEQUENCE) || \ |
186 | 0 | ((i)->type == XML_SCHEMA_TYPE_CHOICE) || \ |
187 | 0 | ((i)->type == XML_SCHEMA_TYPE_ALL)) |
188 | | |
189 | 0 | #define WXS_MODELGROUP_PARTICLE(mg) WXS_PTC_CAST (mg)->children |
190 | | /* |
191 | | * Macros for schema buckets. |
192 | | */ |
193 | 0 | #define WXS_IS_BUCKET_INCREDEF(t) (((t) == XML_SCHEMA_SCHEMA_INCLUDE) || \ |
194 | 0 | ((t) == XML_SCHEMA_SCHEMA_REDEFINE)) |
195 | | |
196 | 0 | #define WXS_IS_BUCKET_IMPMAIN(t) (((t) == XML_SCHEMA_SCHEMA_MAIN) || \ |
197 | 0 | ((t) == XML_SCHEMA_SCHEMA_IMPORT)) |
198 | | |
199 | 0 | #define WXS_IMPBUCKET(b) ((xmlSchemaImportPtr) (b)) |
200 | | |
201 | 0 | #define WXS_INCBUCKET(b) ((xmlSchemaIncludePtr) (b)) |
202 | | /* |
203 | | * Macros for complex/simple types. |
204 | | */ |
205 | | #define WXS_IS_ANYTYPE(i) \ |
206 | 0 | (( (i)->type == XML_SCHEMA_TYPE_BASIC) && \ |
207 | 0 | ( (WXS_TYPE_CAST (i))->builtInType == XML_SCHEMAS_ANYTYPE)) |
208 | | |
209 | | #define WXS_IS_COMPLEX(i) \ |
210 | 0 | (((i)->type == XML_SCHEMA_TYPE_COMPLEX) || \ |
211 | 0 | ((i)->builtInType == XML_SCHEMAS_ANYTYPE)) |
212 | | |
213 | | #define WXS_IS_SIMPLE(item) \ |
214 | 0 | ((item->type == XML_SCHEMA_TYPE_SIMPLE) || \ |
215 | 0 | ((item->type == XML_SCHEMA_TYPE_BASIC) && \ |
216 | 0 | (item->builtInType != XML_SCHEMAS_ANYTYPE))) |
217 | | |
218 | | #define WXS_IS_ANY_SIMPLE_TYPE(i) \ |
219 | 0 | (((i)->type == XML_SCHEMA_TYPE_BASIC) && \ |
220 | 0 | ((i)->builtInType == XML_SCHEMAS_ANYSIMPLETYPE)) |
221 | | |
222 | | #define WXS_IS_RESTRICTION(t) \ |
223 | 0 | ((t)->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION) |
224 | | |
225 | | #define WXS_IS_EXTENSION(t) \ |
226 | 0 | ((t)->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION) |
227 | | |
228 | | #define WXS_IS_TYPE_NOT_FIXED(i) \ |
229 | 0 | (((i)->type != XML_SCHEMA_TYPE_BASIC) && \ |
230 | 0 | (((i)->flags & XML_SCHEMAS_TYPE_INTERNAL_RESOLVED) == 0)) |
231 | | |
232 | | #define WXS_IS_TYPE_NOT_FIXED_1(item) \ |
233 | 0 | (((item)->type != XML_SCHEMA_TYPE_BASIC) && \ |
234 | 0 | (((item)->flags & XML_SCHEMAS_TYPE_FIXUP_1) == 0)) |
235 | | |
236 | | #define WXS_TYPE_IS_GLOBAL(t) ((t)->flags & XML_SCHEMAS_TYPE_GLOBAL) |
237 | | |
238 | | #define WXS_TYPE_IS_LOCAL(t) (((t)->flags & XML_SCHEMAS_TYPE_GLOBAL) == 0) |
239 | | /* |
240 | | * Macros for exclusively for complex types. |
241 | | */ |
242 | | #define WXS_HAS_COMPLEX_CONTENT(item) \ |
243 | | ((item->contentType == XML_SCHEMA_CONTENT_MIXED) || \ |
244 | | (item->contentType == XML_SCHEMA_CONTENT_EMPTY) || \ |
245 | | (item->contentType == XML_SCHEMA_CONTENT_ELEMENTS)) |
246 | | |
247 | | #define WXS_HAS_SIMPLE_CONTENT(item) \ |
248 | 0 | ((item->contentType == XML_SCHEMA_CONTENT_SIMPLE) || \ |
249 | 0 | (item->contentType == XML_SCHEMA_CONTENT_BASIC)) |
250 | | |
251 | | #define WXS_HAS_MIXED_CONTENT(item) \ |
252 | 0 | (item->contentType == XML_SCHEMA_CONTENT_MIXED) |
253 | | |
254 | | #define WXS_EMPTIABLE(t) \ |
255 | 0 | (xmlSchemaIsParticleEmptiable(WXS_PTC_CAST (t)->subtypes)) |
256 | | |
257 | 0 | #define WXS_TYPE_CONTENTTYPE(t) (t)->subtypes |
258 | | |
259 | 0 | #define WXS_TYPE_PARTICLE(t) WXS_PTC_CAST (t)->subtypes |
260 | | |
261 | 0 | #define WXS_TYPE_PARTICLE_TERM(t) WXS_PARTICLE_TERM(WXS_TYPE_PARTICLE(t)) |
262 | | /* |
263 | | * Macros for exclusively for simple types. |
264 | | */ |
265 | 0 | #define WXS_LIST_ITEMTYPE(t) (t)->subtypes |
266 | | |
267 | 0 | #define WXS_IS_ATOMIC(t) (t->flags & XML_SCHEMAS_TYPE_VARIETY_ATOMIC) |
268 | | |
269 | 0 | #define WXS_IS_LIST(t) (t->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) |
270 | | |
271 | 0 | #define WXS_IS_UNION(t) (t->flags & XML_SCHEMAS_TYPE_VARIETY_UNION) |
272 | | /* |
273 | | * Misc parser context macros. |
274 | | */ |
275 | 0 | #define WXS_CONSTRUCTOR(ctx) (ctx)->constructor |
276 | | |
277 | 0 | #define WXS_HAS_BUCKETS(ctx) \ |
278 | 0 | ( (WXS_CONSTRUCTOR((ctx))->buckets != NULL) && \ |
279 | 0 | (WXS_CONSTRUCTOR((ctx))->buckets->nbItems > 0) ) |
280 | | |
281 | 0 | #define WXS_SUBST_GROUPS(ctx) WXS_CONSTRUCTOR((ctx))->substGroups |
282 | | |
283 | 0 | #define WXS_BUCKET(ctx) WXS_CONSTRUCTOR((ctx))->bucket |
284 | | |
285 | | #define WXS_SCHEMA(ctx) (ctx)->schema |
286 | | |
287 | | #define WXS_ADD_LOCAL(ctx, item) \ |
288 | 0 | do { \ |
289 | 0 | if ((item != NULL) && \ |
290 | 0 | (xmlSchemaAddItemSize(&(WXS_BUCKET(ctx)->locals), 10, \ |
291 | 0 | item) < 0)) { \ |
292 | 0 | xmlSchemaPErrMemory(ctx); \ |
293 | 0 | xmlFree(item); \ |
294 | 0 | item = NULL; \ |
295 | 0 | } \ |
296 | 0 | } while (0) |
297 | | |
298 | | #define WXS_ADD_GLOBAL(ctx, item) \ |
299 | 0 | do { \ |
300 | 0 | if ((item != NULL) && \ |
301 | 0 | (xmlSchemaAddItemSize(&(WXS_BUCKET(ctx)->globals), 5, \ |
302 | 0 | item) < 0)) { \ |
303 | 0 | xmlSchemaPErrMemory(ctx); \ |
304 | 0 | xmlFree(item); \ |
305 | 0 | item = NULL; \ |
306 | 0 | } \ |
307 | 0 | } while (0) |
308 | | |
309 | | #define WXS_ADD_PENDING(ctx, item) \ |
310 | 0 | do { \ |
311 | 0 | if ((item != NULL) && \ |
312 | 0 | (xmlSchemaAddItemSize(&((ctx)->constructor->pending), 10, \ |
313 | 0 | item) < 0)) { \ |
314 | 0 | xmlSchemaPErrMemory(ctx); \ |
315 | 0 | } \ |
316 | 0 | } while (0) |
317 | | /* |
318 | | * xmlSchemaItemList macros. |
319 | | */ |
320 | 0 | #define WXS_ILIST_IS_EMPTY(l) ((l == NULL) || ((l)->nbItems == 0)) |
321 | | /* |
322 | | * Misc macros. |
323 | | */ |
324 | | #define IS_SCHEMA(node, type) \ |
325 | 0 | ((node != NULL) && (node->ns != NULL) && \ |
326 | 0 | (xmlStrEqual(node->name, (const xmlChar *) type)) && \ |
327 | 0 | (xmlStrEqual(node->ns->href, xmlSchemaNs))) |
328 | | |
329 | 0 | #define FREE_AND_NULL(str) if ((str) != NULL) { xmlFree((xmlChar *) (str)); str = NULL; } |
330 | | |
331 | | /* |
332 | | * Since we put the default/fixed values into the dict, we can |
333 | | * use pointer comparison for those values. |
334 | | * REMOVED: (xmlStrEqual((v1), (v2))) |
335 | | */ |
336 | 0 | #define WXS_ARE_DEFAULT_STR_EQUAL(v1, v2) ((v1) == (v2)) |
337 | | |
338 | 0 | #define INODE_NILLED(item) (item->flags & XML_SCHEMA_ELEM_INFO_NILLED) |
339 | | |
340 | 0 | #define CAN_PARSE_SCHEMA(b) (((b)->doc != NULL) && ((b)->parsed == 0)) |
341 | | |
342 | 0 | #define HFAILURE if (res == -1) goto exit_failure; |
343 | | |
344 | 0 | #define HERROR if (res != 0) goto exit_error; |
345 | | |
346 | 0 | #define HSTOP(ctx) if ((ctx)->stop) goto exit; |
347 | | /* |
348 | | * Some flags used for various schema constraints. |
349 | | */ |
350 | 0 | #define SUBSET_RESTRICTION 1<<0 |
351 | 0 | #define SUBSET_EXTENSION 1<<1 |
352 | | #define SUBSET_SUBSTITUTION 1<<2 |
353 | | #define SUBSET_LIST 1<<3 |
354 | | #define SUBSET_UNION 1<<4 |
355 | | |
356 | | typedef struct _xmlSchemaNodeInfo xmlSchemaNodeInfo; |
357 | | typedef xmlSchemaNodeInfo *xmlSchemaNodeInfoPtr; |
358 | | |
359 | | typedef struct _xmlSchemaItemList xmlSchemaItemList; |
360 | | typedef xmlSchemaItemList *xmlSchemaItemListPtr; |
361 | | struct _xmlSchemaItemList { |
362 | | void **items; /* used for dynamic addition of schemata */ |
363 | | int nbItems; /* used for dynamic addition of schemata */ |
364 | | int sizeItems; /* used for dynamic addition of schemata */ |
365 | | }; |
366 | | |
367 | 0 | #define XML_SCHEMA_CTXT_PARSER 1 |
368 | 0 | #define XML_SCHEMA_CTXT_VALIDATOR 2 |
369 | | |
370 | | typedef struct _xmlSchemaAbstractCtxt xmlSchemaAbstractCtxt; |
371 | | typedef xmlSchemaAbstractCtxt *xmlSchemaAbstractCtxtPtr; |
372 | | struct _xmlSchemaAbstractCtxt { |
373 | | int type; /* E.g. XML_SCHEMA_CTXT_VALIDATOR */ |
374 | | void *dummy; /* Fix alignment issues */ |
375 | | }; |
376 | | |
377 | | typedef struct _xmlSchemaBucket xmlSchemaBucket; |
378 | | typedef xmlSchemaBucket *xmlSchemaBucketPtr; |
379 | | |
380 | 0 | #define XML_SCHEMA_SCHEMA_MAIN 0 |
381 | 0 | #define XML_SCHEMA_SCHEMA_IMPORT 1 |
382 | 0 | #define XML_SCHEMA_SCHEMA_INCLUDE 2 |
383 | 0 | #define XML_SCHEMA_SCHEMA_REDEFINE 3 |
384 | | |
385 | | /** |
386 | | * Used to create a graph of schema relationships. |
387 | | */ |
388 | | typedef struct _xmlSchemaSchemaRelation xmlSchemaSchemaRelation; |
389 | | typedef xmlSchemaSchemaRelation *xmlSchemaSchemaRelationPtr; |
390 | | struct _xmlSchemaSchemaRelation { |
391 | | xmlSchemaSchemaRelationPtr next; |
392 | | int type; /* E.g. XML_SCHEMA_SCHEMA_IMPORT */ |
393 | | const xmlChar *importNamespace; |
394 | | xmlSchemaBucketPtr bucket; |
395 | | }; |
396 | | |
397 | 0 | #define XML_SCHEMA_BUCKET_MARKED 1<<0 |
398 | 0 | #define XML_SCHEMA_BUCKET_COMPS_ADDED 1<<1 |
399 | | |
400 | | struct _xmlSchemaBucket { |
401 | | int type; |
402 | | int flags; |
403 | | const xmlChar *schemaLocation; |
404 | | const xmlChar *origTargetNamespace; |
405 | | const xmlChar *targetNamespace; |
406 | | xmlDocPtr doc; |
407 | | xmlSchemaSchemaRelationPtr relations; |
408 | | int located; |
409 | | int parsed; |
410 | | int imported; |
411 | | int preserveDoc; |
412 | | xmlSchemaItemListPtr globals; /* Global components. */ |
413 | | xmlSchemaItemListPtr locals; /* Local components. */ |
414 | | }; |
415 | | |
416 | | /** |
417 | | * (extends xmlSchemaBucket) |
418 | | * |
419 | | * Reflects a schema. Holds some information |
420 | | * about the schema and its toplevel components. Duplicate |
421 | | * toplevel components are not checked at this level. |
422 | | */ |
423 | | typedef struct _xmlSchemaImport xmlSchemaImport; |
424 | | typedef xmlSchemaImport *xmlSchemaImportPtr; |
425 | | struct _xmlSchemaImport { |
426 | | int type; /* Main OR import OR include. */ |
427 | | int flags; |
428 | | const xmlChar *schemaLocation; /* The URI of the schema document. */ |
429 | | /* For chameleon includes, @origTargetNamespace will be NULL */ |
430 | | const xmlChar *origTargetNamespace; |
431 | | /* |
432 | | * For chameleon includes, @targetNamespace will be the |
433 | | * targetNamespace of the including schema. |
434 | | */ |
435 | | const xmlChar *targetNamespace; |
436 | | xmlDocPtr doc; /* The schema node-tree. */ |
437 | | /* @relations will hold any included/imported/redefined schemas. */ |
438 | | xmlSchemaSchemaRelationPtr relations; |
439 | | int located; |
440 | | int parsed; |
441 | | int imported; |
442 | | int preserveDoc; |
443 | | xmlSchemaItemListPtr globals; |
444 | | xmlSchemaItemListPtr locals; |
445 | | /* The imported schema. */ |
446 | | xmlSchemaPtr schema; |
447 | | }; |
448 | | |
449 | | /* |
450 | | * (extends xmlSchemaBucket) |
451 | | */ |
452 | | typedef struct _xmlSchemaInclude xmlSchemaInclude; |
453 | | typedef xmlSchemaInclude *xmlSchemaIncludePtr; |
454 | | struct _xmlSchemaInclude { |
455 | | int type; |
456 | | int flags; |
457 | | const xmlChar *schemaLocation; |
458 | | const xmlChar *origTargetNamespace; |
459 | | const xmlChar *targetNamespace; |
460 | | xmlDocPtr doc; |
461 | | xmlSchemaSchemaRelationPtr relations; |
462 | | int located; |
463 | | int parsed; |
464 | | int imported; |
465 | | int preserveDoc; |
466 | | xmlSchemaItemListPtr globals; /* Global components. */ |
467 | | xmlSchemaItemListPtr locals; /* Local components. */ |
468 | | |
469 | | /* The owning main or import schema bucket. */ |
470 | | xmlSchemaImportPtr ownerImport; |
471 | | }; |
472 | | |
473 | | /** |
474 | | * The abstract base type for schema components. |
475 | | */ |
476 | | typedef struct _xmlSchemaBasicItem xmlSchemaBasicItem; |
477 | | typedef xmlSchemaBasicItem *xmlSchemaBasicItemPtr; |
478 | | struct _xmlSchemaBasicItem { |
479 | | xmlSchemaTypeType type; |
480 | | void *dummy; /* Fix alignment issues */ |
481 | | }; |
482 | | |
483 | | /** |
484 | | * The abstract base type for annotated schema components. |
485 | | * (Extends xmlSchemaBasicItem) |
486 | | */ |
487 | | typedef struct _xmlSchemaAnnotItem xmlSchemaAnnotItem; |
488 | | typedef xmlSchemaAnnotItem *xmlSchemaAnnotItemPtr; |
489 | | struct _xmlSchemaAnnotItem { |
490 | | xmlSchemaTypeType type; |
491 | | xmlSchemaAnnotPtr annot; |
492 | | }; |
493 | | |
494 | | /** |
495 | | * The abstract base type for tree-like structured schema components. |
496 | | * (Extends xmlSchemaAnnotItem) |
497 | | */ |
498 | | typedef struct _xmlSchemaTreeItem xmlSchemaTreeItem; |
499 | | typedef xmlSchemaTreeItem *xmlSchemaTreeItemPtr; |
500 | | struct _xmlSchemaTreeItem { |
501 | | xmlSchemaTypeType type; |
502 | | xmlSchemaAnnotPtr annot; |
503 | | xmlSchemaTreeItemPtr next; |
504 | | xmlSchemaTreeItemPtr children; |
505 | | }; |
506 | | |
507 | | |
508 | 0 | #define XML_SCHEMA_ATTR_USE_FIXED 1<<0 |
509 | | /** |
510 | | * The abstract base type for tree-like structured schema components. |
511 | | * (Extends xmlSchemaTreeItem) |
512 | | */ |
513 | | typedef struct _xmlSchemaAttributeUse xmlSchemaAttributeUse; |
514 | | typedef xmlSchemaAttributeUse *xmlSchemaAttributeUsePtr; |
515 | | struct _xmlSchemaAttributeUse { |
516 | | xmlSchemaTypeType type; |
517 | | xmlSchemaAnnotPtr annot; |
518 | | xmlSchemaAttributeUsePtr next; /* The next attr. use. */ |
519 | | /* |
520 | | * The attr. decl. OR a QName-ref. to an attr. decl. OR |
521 | | * a QName-ref. to an attribute group definition. |
522 | | */ |
523 | | xmlSchemaAttributePtr attrDecl; |
524 | | |
525 | | int flags; |
526 | | xmlNodePtr node; |
527 | | int occurs; /* required, optional */ |
528 | | const xmlChar * defValue; |
529 | | xmlSchemaValPtr defVal; |
530 | | }; |
531 | | |
532 | | /** |
533 | | * A helper component to reflect attribute prohibitions. |
534 | | * (Extends xmlSchemaBasicItem) |
535 | | */ |
536 | | typedef struct _xmlSchemaAttributeUseProhib xmlSchemaAttributeUseProhib; |
537 | | typedef xmlSchemaAttributeUseProhib *xmlSchemaAttributeUseProhibPtr; |
538 | | struct _xmlSchemaAttributeUseProhib { |
539 | | xmlSchemaTypeType type; /* == XML_SCHEMA_EXTRA_ATTR_USE_PROHIB */ |
540 | | xmlNodePtr node; |
541 | | const xmlChar *name; |
542 | | const xmlChar *targetNamespace; |
543 | | int isRef; |
544 | | }; |
545 | | |
546 | | /** |
547 | | */ |
548 | | typedef struct _xmlSchemaRedef xmlSchemaRedef; |
549 | | typedef xmlSchemaRedef *xmlSchemaRedefPtr; |
550 | | struct _xmlSchemaRedef { |
551 | | xmlSchemaRedefPtr next; |
552 | | xmlSchemaBasicItemPtr item; /* The redefining component. */ |
553 | | xmlSchemaBasicItemPtr reference; /* The referencing component. */ |
554 | | xmlSchemaBasicItemPtr target; /* The to-be-redefined component. */ |
555 | | const xmlChar *refName; /* The name of the to-be-redefined component. */ |
556 | | const xmlChar *refTargetNs; /* The target namespace of the |
557 | | to-be-redefined comp. */ |
558 | | xmlSchemaBucketPtr targetBucket; /* The redefined schema. */ |
559 | | }; |
560 | | |
561 | | /** |
562 | | */ |
563 | | typedef struct _xmlSchemaConstructionCtxt xmlSchemaConstructionCtxt; |
564 | | typedef xmlSchemaConstructionCtxt *xmlSchemaConstructionCtxtPtr; |
565 | | struct _xmlSchemaConstructionCtxt { |
566 | | xmlSchemaPtr mainSchema; /* The main schema. */ |
567 | | xmlSchemaBucketPtr mainBucket; /* The main schema bucket */ |
568 | | xmlDictPtr dict; |
569 | | xmlSchemaItemListPtr buckets; /* List of schema buckets. */ |
570 | | /* xmlSchemaItemListPtr relations; */ /* List of schema relations. */ |
571 | | xmlSchemaBucketPtr bucket; /* The current schema bucket */ |
572 | | xmlSchemaItemListPtr pending; /* All Components of all schemas that |
573 | | need to be fixed. */ |
574 | | xmlHashTablePtr substGroups; |
575 | | xmlSchemaRedefPtr redefs; |
576 | | xmlSchemaRedefPtr lastRedef; |
577 | | }; |
578 | | |
579 | | #define XML_SCHEMAS_PARSE_ERROR 1 |
580 | 0 | #define SCHEMAS_PARSE_OPTIONS XML_PARSE_NOENT |
581 | | |
582 | | struct _xmlSchemaParserCtxt { |
583 | | int type; |
584 | | void *errCtxt; /* user specific error context */ |
585 | | xmlSchemaValidityErrorFunc error; /* the callback in case of errors */ |
586 | | xmlSchemaValidityWarningFunc warning; /* the callback in case of warning */ |
587 | | int err; |
588 | | int nberrors; |
589 | | xmlStructuredErrorFunc serror; |
590 | | |
591 | | xmlSchemaConstructionCtxtPtr constructor; |
592 | | int ownsConstructor; /* TODO: Move this to parser *flags*. */ |
593 | | |
594 | | /* xmlSchemaPtr topschema; */ |
595 | | /* xmlHashTablePtr namespaces; */ |
596 | | |
597 | | xmlSchemaPtr schema; /* The main schema in use */ |
598 | | int counter; |
599 | | |
600 | | const xmlChar *URL; |
601 | | xmlDocPtr doc; |
602 | | int preserve; /* Whether the doc should be freed */ |
603 | | |
604 | | const char *buffer; |
605 | | int size; |
606 | | |
607 | | /* |
608 | | * Used to build complex element content models |
609 | | */ |
610 | | xmlAutomataPtr am; |
611 | | xmlAutomataStatePtr start; |
612 | | xmlAutomataStatePtr end; |
613 | | xmlAutomataStatePtr state; |
614 | | |
615 | | xmlDictPtr dict; /* dictionary for interned string names */ |
616 | | xmlSchemaTypePtr ctxtType; /* The current context simple/complex type */ |
617 | | int options; |
618 | | xmlSchemaValidCtxtPtr vctxt; |
619 | | int isS4S; |
620 | | int isRedefine; |
621 | | int xsiAssemble; |
622 | | int stop; /* If the parser should stop; i.e. a critical error. */ |
623 | | const xmlChar *targetNamespace; |
624 | | xmlSchemaBucketPtr redefined; /* The schema to be redefined. */ |
625 | | |
626 | | xmlSchemaRedefPtr redef; /* Used for redefinitions. */ |
627 | | int redefCounter; /* Used for redefinitions. */ |
628 | | xmlSchemaItemListPtr attrProhibs; |
629 | | |
630 | | xmlResourceLoader resourceLoader; |
631 | | void *resourceCtxt; |
632 | | }; |
633 | | |
634 | | /** |
635 | | * A component reference item (not a schema component) |
636 | | * (Extends xmlSchemaBasicItem) |
637 | | */ |
638 | | typedef struct _xmlSchemaQNameRef xmlSchemaQNameRef; |
639 | | typedef xmlSchemaQNameRef *xmlSchemaQNameRefPtr; |
640 | | struct _xmlSchemaQNameRef { |
641 | | xmlSchemaTypeType type; |
642 | | xmlSchemaBasicItemPtr item; /* The resolved referenced item. */ |
643 | | xmlSchemaTypeType itemType; |
644 | | const xmlChar *name; |
645 | | const xmlChar *targetNamespace; |
646 | | xmlNodePtr node; |
647 | | }; |
648 | | |
649 | | /** |
650 | | * A particle component. |
651 | | * (Extends xmlSchemaTreeItem) |
652 | | */ |
653 | | typedef struct _xmlSchemaParticle xmlSchemaParticle; |
654 | | typedef xmlSchemaParticle *xmlSchemaParticlePtr; |
655 | | struct _xmlSchemaParticle { |
656 | | xmlSchemaTypeType type; |
657 | | xmlSchemaAnnotPtr annot; |
658 | | xmlSchemaTreeItemPtr next; /* next particle */ |
659 | | xmlSchemaTreeItemPtr children; /* the "term" (e.g. a model group, |
660 | | a group definition, a XML_SCHEMA_EXTRA_QNAMEREF (if a reference), |
661 | | etc.) */ |
662 | | int minOccurs; |
663 | | int maxOccurs; |
664 | | xmlNodePtr node; |
665 | | }; |
666 | | |
667 | | /** |
668 | | * A model group component. |
669 | | * (Extends xmlSchemaTreeItem) |
670 | | */ |
671 | | typedef struct _xmlSchemaModelGroup xmlSchemaModelGroup; |
672 | | typedef xmlSchemaModelGroup *xmlSchemaModelGroupPtr; |
673 | | struct _xmlSchemaModelGroup { |
674 | | xmlSchemaTypeType type; /* XML_SCHEMA_TYPE_SEQUENCE, XML_SCHEMA_TYPE_CHOICE, XML_SCHEMA_TYPE_ALL */ |
675 | | xmlSchemaAnnotPtr annot; |
676 | | xmlSchemaTreeItemPtr next; /* not used */ |
677 | | xmlSchemaTreeItemPtr children; /* first particle (OR "element decl" OR "wildcard") */ |
678 | | xmlNodePtr node; |
679 | | }; |
680 | | |
681 | 0 | #define XML_SCHEMA_MODEL_GROUP_DEF_MARKED 1<<0 |
682 | 0 | #define XML_SCHEMA_MODEL_GROUP_DEF_REDEFINED 1<<1 |
683 | | /** |
684 | | * A model group definition component. |
685 | | * (Extends xmlSchemaTreeItem) |
686 | | */ |
687 | | typedef struct _xmlSchemaModelGroupDef xmlSchemaModelGroupDef; |
688 | | typedef xmlSchemaModelGroupDef *xmlSchemaModelGroupDefPtr; |
689 | | struct _xmlSchemaModelGroupDef { |
690 | | xmlSchemaTypeType type; /* XML_SCHEMA_TYPE_GROUP */ |
691 | | xmlSchemaAnnotPtr annot; |
692 | | xmlSchemaTreeItemPtr next; /* not used */ |
693 | | xmlSchemaTreeItemPtr children; /* the "model group" */ |
694 | | const xmlChar *name; |
695 | | const xmlChar *targetNamespace; |
696 | | xmlNodePtr node; |
697 | | int flags; |
698 | | }; |
699 | | |
700 | | typedef struct _xmlSchemaIDC xmlSchemaIDC; |
701 | | typedef xmlSchemaIDC *xmlSchemaIDCPtr; |
702 | | |
703 | | /** |
704 | | * The identity-constraint "field" and "selector" item, holding the |
705 | | * XPath expression. |
706 | | */ |
707 | | typedef struct _xmlSchemaIDCSelect xmlSchemaIDCSelect; |
708 | | typedef xmlSchemaIDCSelect *xmlSchemaIDCSelectPtr; |
709 | | struct _xmlSchemaIDCSelect { |
710 | | xmlSchemaIDCSelectPtr next; |
711 | | xmlSchemaIDCPtr idc; |
712 | | int index; /* an index position if significant for IDC key-sequences */ |
713 | | const xmlChar *xpath; /* the XPath expression */ |
714 | | void *xpathComp; /* the compiled XPath expression */ |
715 | | }; |
716 | | |
717 | | /** |
718 | | * The identity-constraint definition component. |
719 | | * (Extends xmlSchemaAnnotItem) |
720 | | */ |
721 | | |
722 | | struct _xmlSchemaIDC { |
723 | | xmlSchemaTypeType type; |
724 | | xmlSchemaAnnotPtr annot; |
725 | | xmlSchemaIDCPtr next; |
726 | | xmlNodePtr node; |
727 | | const xmlChar *name; |
728 | | const xmlChar *targetNamespace; |
729 | | xmlSchemaIDCSelectPtr selector; |
730 | | xmlSchemaIDCSelectPtr fields; |
731 | | int nbFields; |
732 | | xmlSchemaQNameRefPtr ref; |
733 | | }; |
734 | | |
735 | | /** |
736 | | * The augmented IDC information used for validation. |
737 | | */ |
738 | | typedef struct _xmlSchemaIDCAug xmlSchemaIDCAug; |
739 | | typedef xmlSchemaIDCAug *xmlSchemaIDCAugPtr; |
740 | | struct _xmlSchemaIDCAug { |
741 | | xmlSchemaIDCAugPtr next; /* next in a list */ |
742 | | xmlSchemaIDCPtr def; /* the IDC definition */ |
743 | | int keyrefDepth; /* the lowest tree level to which IDC |
744 | | tables need to be bubbled upwards */ |
745 | | }; |
746 | | |
747 | | /** |
748 | | * The key sequence of a node table item. |
749 | | */ |
750 | | typedef struct _xmlSchemaPSVIIDCKey xmlSchemaPSVIIDCKey; |
751 | | typedef xmlSchemaPSVIIDCKey *xmlSchemaPSVIIDCKeyPtr; |
752 | | struct _xmlSchemaPSVIIDCKey { |
753 | | xmlSchemaTypePtr type; |
754 | | xmlSchemaValPtr val; |
755 | | }; |
756 | | |
757 | | /** |
758 | | * The node table item of a node table. |
759 | | */ |
760 | | typedef struct _xmlSchemaPSVIIDCNode xmlSchemaPSVIIDCNode; |
761 | | typedef xmlSchemaPSVIIDCNode *xmlSchemaPSVIIDCNodePtr; |
762 | | struct _xmlSchemaPSVIIDCNode { |
763 | | xmlNodePtr node; |
764 | | xmlSchemaPSVIIDCKeyPtr *keys; |
765 | | int nodeLine; |
766 | | int nodeQNameID; |
767 | | |
768 | | }; |
769 | | |
770 | | /** |
771 | | * The identity-constraint binding item of the [identity-constraint table]. |
772 | | */ |
773 | | typedef struct _xmlSchemaPSVIIDCBinding xmlSchemaPSVIIDCBinding; |
774 | | typedef xmlSchemaPSVIIDCBinding *xmlSchemaPSVIIDCBindingPtr; |
775 | | struct _xmlSchemaPSVIIDCBinding { |
776 | | xmlSchemaPSVIIDCBindingPtr next; /* next binding of a specific node */ |
777 | | xmlSchemaIDCPtr definition; /* the IDC definition */ |
778 | | xmlSchemaPSVIIDCNodePtr *nodeTable; /* array of key-sequences */ |
779 | | int nbNodes; /* number of entries in the node table */ |
780 | | int sizeNodes; /* size of the node table */ |
781 | | xmlSchemaItemListPtr dupls; |
782 | | }; |
783 | | |
784 | | |
785 | 0 | #define XPATH_STATE_OBJ_TYPE_IDC_SELECTOR 1 |
786 | 0 | #define XPATH_STATE_OBJ_TYPE_IDC_FIELD 2 |
787 | | |
788 | | #define XPATH_STATE_OBJ_MATCHES -2 |
789 | | #define XPATH_STATE_OBJ_BLOCKED -3 |
790 | | |
791 | | typedef struct _xmlSchemaIDCMatcher xmlSchemaIDCMatcher; |
792 | | typedef xmlSchemaIDCMatcher *xmlSchemaIDCMatcherPtr; |
793 | | |
794 | | /** |
795 | | * The state object used to evaluate XPath expressions. |
796 | | */ |
797 | | typedef struct _xmlSchemaIDCStateObj xmlSchemaIDCStateObj; |
798 | | typedef xmlSchemaIDCStateObj *xmlSchemaIDCStateObjPtr; |
799 | | struct _xmlSchemaIDCStateObj { |
800 | | int type; |
801 | | xmlSchemaIDCStateObjPtr next; /* next if in a list */ |
802 | | int depth; /* depth of creation */ |
803 | | int *history; /* list of (depth, state-id) tuples */ |
804 | | int nbHistory; |
805 | | int sizeHistory; |
806 | | xmlSchemaIDCMatcherPtr matcher; /* the correspondent field/selector |
807 | | matcher */ |
808 | | xmlSchemaIDCSelectPtr sel; |
809 | | void *xpathCtxt; |
810 | | }; |
811 | | |
812 | 0 | #define IDC_MATCHER 0 |
813 | | |
814 | | /** |
815 | | * Used to evaluate IDC selectors (and fields). |
816 | | */ |
817 | | struct _xmlSchemaIDCMatcher { |
818 | | int type; |
819 | | int depth; /* the tree depth at creation time */ |
820 | | xmlSchemaIDCMatcherPtr next; /* next in the list */ |
821 | | xmlSchemaIDCMatcherPtr nextCached; /* next in the cache list */ |
822 | | xmlSchemaIDCAugPtr aidc; /* the augmented IDC item */ |
823 | | int idcType; |
824 | | xmlSchemaPSVIIDCKeyPtr **keySeqs; /* the key-sequences of the target |
825 | | elements */ |
826 | | int sizeKeySeqs; |
827 | | xmlSchemaItemListPtr targets; /* list of target-node |
828 | | (xmlSchemaPSVIIDCNodePtr) entries */ |
829 | | xmlHashTablePtr htab; |
830 | | }; |
831 | | |
832 | | /* |
833 | | * Element info flags. |
834 | | */ |
835 | 0 | #define XML_SCHEMA_NODE_INFO_FLAG_OWNED_NAMES (1<<0) |
836 | 0 | #define XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES (1<<1) |
837 | 0 | #define XML_SCHEMA_ELEM_INFO_NILLED (1<<2) |
838 | 0 | #define XML_SCHEMA_ELEM_INFO_LOCAL_TYPE (1<<3) |
839 | | |
840 | 0 | #define XML_SCHEMA_NODE_INFO_VALUE_NEEDED (1<<4) |
841 | 0 | #define XML_SCHEMA_ELEM_INFO_EMPTY (1<<5) |
842 | | #define XML_SCHEMA_ELEM_INFO_HAS_CONTENT (1<<6) |
843 | | |
844 | 0 | #define XML_SCHEMA_ELEM_INFO_HAS_ELEM_CONTENT (1<<7) |
845 | 0 | #define XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT (1<<8) |
846 | 0 | #define XML_SCHEMA_NODE_INFO_ERR_NOT_EXPECTED (1<<9) |
847 | 0 | #define XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE (1<<10) |
848 | | |
849 | | /** |
850 | | * Holds information of an element node. |
851 | | */ |
852 | | struct _xmlSchemaNodeInfo { |
853 | | int nodeType; |
854 | | xmlNodePtr node; |
855 | | int nodeLine; |
856 | | const xmlChar *localName; |
857 | | const xmlChar *nsName; |
858 | | const xmlChar *value; |
859 | | xmlSchemaValPtr val; /* the pre-computed value if any */ |
860 | | xmlSchemaTypePtr typeDef; /* the complex/simple type definition if any */ |
861 | | |
862 | | int flags; /* combination of node info flags */ |
863 | | |
864 | | int valNeeded; |
865 | | int normVal; |
866 | | |
867 | | xmlSchemaElementPtr decl; /* the element/attribute declaration */ |
868 | | int depth; |
869 | | xmlSchemaPSVIIDCBindingPtr idcTable; /* the table of PSVI IDC bindings |
870 | | for the scope element*/ |
871 | | xmlSchemaIDCMatcherPtr idcMatchers; /* the IDC matchers for the scope |
872 | | element */ |
873 | | xmlRegExecCtxtPtr regexCtxt; |
874 | | |
875 | | const xmlChar **nsBindings; /* Namespace bindings on this element */ |
876 | | int nbNsBindings; |
877 | | int sizeNsBindings; |
878 | | |
879 | | int hasKeyrefs; |
880 | | int appliedXPath; /* Indicates that an XPath has been applied. */ |
881 | | }; |
882 | | |
883 | 0 | #define XML_SCHEMAS_ATTR_UNKNOWN 1 |
884 | 0 | #define XML_SCHEMAS_ATTR_ASSESSED 2 |
885 | | #define XML_SCHEMAS_ATTR_PROHIBITED 3 |
886 | 0 | #define XML_SCHEMAS_ATTR_ERR_MISSING 4 |
887 | 0 | #define XML_SCHEMAS_ATTR_INVALID_VALUE 5 |
888 | 0 | #define XML_SCHEMAS_ATTR_ERR_NO_TYPE 6 |
889 | 0 | #define XML_SCHEMAS_ATTR_ERR_FIXED_VALUE 7 |
890 | 0 | #define XML_SCHEMAS_ATTR_DEFAULT 8 |
891 | | #define XML_SCHEMAS_ATTR_VALIDATE_VALUE 9 |
892 | 0 | #define XML_SCHEMAS_ATTR_ERR_WILD_STRICT_NO_DECL 10 |
893 | | #define XML_SCHEMAS_ATTR_HAS_ATTR_USE 11 |
894 | | #define XML_SCHEMAS_ATTR_HAS_ATTR_DECL 12 |
895 | 0 | #define XML_SCHEMAS_ATTR_WILD_SKIP 13 |
896 | 0 | #define XML_SCHEMAS_ATTR_WILD_LAX_NO_DECL 14 |
897 | 0 | #define XML_SCHEMAS_ATTR_ERR_WILD_DUPLICATE_ID 15 |
898 | 0 | #define XML_SCHEMAS_ATTR_ERR_WILD_AND_USE_ID 16 |
899 | 0 | #define XML_SCHEMAS_ATTR_META 17 |
900 | | /* |
901 | | * @metaType values of xmlSchemaAttrInfo. |
902 | | */ |
903 | 0 | #define XML_SCHEMA_ATTR_INFO_META_XSI_TYPE 1 |
904 | 0 | #define XML_SCHEMA_ATTR_INFO_META_XSI_NIL 2 |
905 | 0 | #define XML_SCHEMA_ATTR_INFO_META_XSI_SCHEMA_LOC 3 |
906 | 0 | #define XML_SCHEMA_ATTR_INFO_META_XSI_NO_NS_SCHEMA_LOC 4 |
907 | 0 | #define XML_SCHEMA_ATTR_INFO_META_XMLNS 5 |
908 | | |
909 | | typedef struct _xmlSchemaAttrInfo xmlSchemaAttrInfo; |
910 | | typedef xmlSchemaAttrInfo *xmlSchemaAttrInfoPtr; |
911 | | struct _xmlSchemaAttrInfo { |
912 | | int nodeType; |
913 | | xmlNodePtr node; |
914 | | int nodeLine; |
915 | | const xmlChar *localName; |
916 | | const xmlChar *nsName; |
917 | | const xmlChar *value; |
918 | | xmlSchemaValPtr val; /* the pre-computed value if any */ |
919 | | xmlSchemaTypePtr typeDef; /* the complex/simple type definition if any */ |
920 | | int flags; /* combination of node info flags */ |
921 | | |
922 | | xmlSchemaAttributePtr decl; /* the attribute declaration */ |
923 | | xmlSchemaAttributeUsePtr use; /* the attribute use */ |
924 | | int state; |
925 | | int metaType; |
926 | | const xmlChar *vcValue; /* the value constraint value */ |
927 | | xmlSchemaNodeInfoPtr parent; |
928 | | }; |
929 | | |
930 | | |
931 | 0 | #define XML_SCHEMA_VALID_CTXT_FLAG_STREAM 1 |
932 | | /** |
933 | | * A Schemas validation context |
934 | | */ |
935 | | struct _xmlSchemaValidCtxt { |
936 | | int type; |
937 | | void *errCtxt; /* user specific data block */ |
938 | | xmlSchemaValidityErrorFunc error; /* the callback in case of errors */ |
939 | | xmlSchemaValidityWarningFunc warning; /* the callback in case of warning */ |
940 | | xmlStructuredErrorFunc serror; |
941 | | |
942 | | xmlSchemaPtr schema; /* The schema in use */ |
943 | | xmlDocPtr doc; |
944 | | xmlParserInputBufferPtr input; |
945 | | xmlCharEncoding enc; |
946 | | xmlSAXHandlerPtr sax; |
947 | | xmlParserCtxtPtr parserCtxt; |
948 | | void *user_data; /* TODO: What is this for? */ |
949 | | char *filename; |
950 | | |
951 | | int err; |
952 | | int nberrors; |
953 | | |
954 | | xmlNodePtr node; |
955 | | xmlNodePtr cur; |
956 | | /* xmlSchemaTypePtr type; */ |
957 | | |
958 | | xmlRegExecCtxtPtr regexp; |
959 | | xmlSchemaValPtr value; |
960 | | |
961 | | int valueWS; |
962 | | int options; |
963 | | xmlNodePtr validationRoot; |
964 | | xmlSchemaParserCtxtPtr pctxt; |
965 | | int xsiAssemble; |
966 | | |
967 | | int depth; |
968 | | xmlSchemaNodeInfoPtr *elemInfos; /* array of element information */ |
969 | | int sizeElemInfos; |
970 | | xmlSchemaNodeInfoPtr inode; /* the current element information */ |
971 | | |
972 | | xmlSchemaIDCAugPtr aidcs; /* a list of augmented IDC information */ |
973 | | |
974 | | xmlSchemaIDCStateObjPtr xpathStates; /* first active state object. */ |
975 | | xmlSchemaIDCStateObjPtr xpathStatePool; /* first stored state object. */ |
976 | | xmlSchemaIDCMatcherPtr idcMatcherCache; /* Cache for IDC matcher objects. */ |
977 | | |
978 | | xmlSchemaPSVIIDCNodePtr *idcNodes; /* list of all IDC node-table entries*/ |
979 | | int nbIdcNodes; |
980 | | int sizeIdcNodes; |
981 | | |
982 | | xmlSchemaPSVIIDCKeyPtr *idcKeys; /* list of all IDC node-table entries */ |
983 | | int nbIdcKeys; |
984 | | int sizeIdcKeys; |
985 | | |
986 | | int flags; |
987 | | |
988 | | xmlDictPtr dict; |
989 | | |
990 | | #ifdef LIBXML_READER_ENABLED |
991 | | xmlTextReaderPtr reader; |
992 | | #endif |
993 | | |
994 | | xmlSchemaAttrInfoPtr *attrInfos; |
995 | | int nbAttrInfos; |
996 | | int sizeAttrInfos; |
997 | | |
998 | | int skipDepth; |
999 | | xmlSchemaItemListPtr nodeQNames; |
1000 | | int hasKeyrefs; |
1001 | | int createIDCNodeTables; |
1002 | | int psviExposeIDCNodeTables; |
1003 | | |
1004 | | /* Locator for error reporting in streaming mode */ |
1005 | | xmlSchemaValidityLocatorFunc locFunc; |
1006 | | void *locCtxt; |
1007 | | }; |
1008 | | |
1009 | | typedef struct _xmlSchemaSubstGroup xmlSchemaSubstGroup; |
1010 | | typedef xmlSchemaSubstGroup *xmlSchemaSubstGroupPtr; |
1011 | | struct _xmlSchemaSubstGroup { |
1012 | | xmlSchemaElementPtr head; |
1013 | | xmlSchemaItemListPtr members; |
1014 | | }; |
1015 | | |
1016 | | /** |
1017 | | * an entry in hash tables to quickly look up keys/uniques |
1018 | | */ |
1019 | | typedef struct _xmlIDCHashEntry xmlIDCHashEntry; |
1020 | | typedef xmlIDCHashEntry *xmlIDCHashEntryPtr; |
1021 | | struct _xmlIDCHashEntry { |
1022 | | xmlIDCHashEntryPtr next; /* next item with same hash */ |
1023 | | int index; /* index into associated item list */ |
1024 | | }; |
1025 | | |
1026 | | /************************************************************************ |
1027 | | * * |
1028 | | * Some predeclarations * |
1029 | | * * |
1030 | | ************************************************************************/ |
1031 | | |
1032 | | static int xmlSchemaParseInclude(xmlSchemaParserCtxtPtr ctxt, |
1033 | | xmlSchemaPtr schema, |
1034 | | xmlNodePtr node); |
1035 | | static int xmlSchemaParseRedefine(xmlSchemaParserCtxtPtr ctxt, |
1036 | | xmlSchemaPtr schema, |
1037 | | xmlNodePtr node); |
1038 | | static int |
1039 | | xmlSchemaTypeFixup(xmlSchemaTypePtr type, |
1040 | | xmlSchemaAbstractCtxtPtr ctxt); |
1041 | | static const xmlChar * |
1042 | | xmlSchemaFacetTypeToString(xmlSchemaTypeType type); |
1043 | | static int |
1044 | | xmlSchemaParseImport(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
1045 | | xmlNodePtr node); |
1046 | | static int |
1047 | | xmlSchemaCheckFacetValues(xmlSchemaTypePtr typeDecl, |
1048 | | xmlSchemaParserCtxtPtr ctxt); |
1049 | | static void |
1050 | | xmlSchemaClearValidCtxt(xmlSchemaValidCtxtPtr vctxt); |
1051 | | static xmlSchemaWhitespaceValueType |
1052 | | xmlSchemaGetWhiteSpaceFacetValue(xmlSchemaTypePtr type); |
1053 | | static xmlSchemaTreeItemPtr |
1054 | | xmlSchemaParseModelGroup(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
1055 | | xmlNodePtr node, xmlSchemaTypeType type, |
1056 | | int withParticle); |
1057 | | static const xmlChar * |
1058 | | xmlSchemaGetComponentTypeStr(xmlSchemaBasicItemPtr item); |
1059 | | static xmlSchemaTypeLinkPtr |
1060 | | xmlSchemaGetUnionSimpleTypeMemberTypes(xmlSchemaTypePtr type); |
1061 | | static void |
1062 | | xmlSchemaInternalErr(xmlSchemaAbstractCtxtPtr actxt, |
1063 | | const char *funcName, |
1064 | | const char *message) LIBXML_ATTR_FORMAT(3,0); |
1065 | | static int |
1066 | | xmlSchemaCheckCOSSTDerivedOK(xmlSchemaAbstractCtxtPtr ctxt, |
1067 | | xmlSchemaTypePtr type, |
1068 | | xmlSchemaTypePtr baseType, |
1069 | | int subset); |
1070 | | static void |
1071 | | xmlSchemaCheckElementDeclComponent(xmlSchemaElementPtr elemDecl, |
1072 | | xmlSchemaParserCtxtPtr ctxt); |
1073 | | static void |
1074 | | xmlSchemaComponentListFree(xmlSchemaItemListPtr list); |
1075 | | static xmlSchemaQNameRefPtr |
1076 | | xmlSchemaParseAttributeGroupRef(xmlSchemaParserCtxtPtr pctxt, |
1077 | | xmlSchemaPtr schema, |
1078 | | xmlNodePtr node); |
1079 | | |
1080 | | /************************************************************************ |
1081 | | * * |
1082 | | * Helper functions * |
1083 | | * * |
1084 | | ************************************************************************/ |
1085 | | |
1086 | | /** |
1087 | | * @param type the type of the schema item |
1088 | | * @returns the component name of a schema item. |
1089 | | */ |
1090 | | static const xmlChar * |
1091 | | xmlSchemaItemTypeToStr(xmlSchemaTypeType type) |
1092 | 0 | { |
1093 | 0 | switch (type) { |
1094 | 0 | case XML_SCHEMA_TYPE_BASIC: |
1095 | 0 | return(BAD_CAST "simple type definition"); |
1096 | 0 | case XML_SCHEMA_TYPE_SIMPLE: |
1097 | 0 | return(BAD_CAST "simple type definition"); |
1098 | 0 | case XML_SCHEMA_TYPE_COMPLEX: |
1099 | 0 | return(BAD_CAST "complex type definition"); |
1100 | 0 | case XML_SCHEMA_TYPE_ELEMENT: |
1101 | 0 | return(BAD_CAST "element declaration"); |
1102 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTE_USE: |
1103 | 0 | return(BAD_CAST "attribute use"); |
1104 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTE: |
1105 | 0 | return(BAD_CAST "attribute declaration"); |
1106 | 0 | case XML_SCHEMA_TYPE_GROUP: |
1107 | 0 | return(BAD_CAST "model group definition"); |
1108 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
1109 | 0 | return(BAD_CAST "attribute group definition"); |
1110 | 0 | case XML_SCHEMA_TYPE_NOTATION: |
1111 | 0 | return(BAD_CAST "notation declaration"); |
1112 | 0 | case XML_SCHEMA_TYPE_SEQUENCE: |
1113 | 0 | return(BAD_CAST "model group (sequence)"); |
1114 | 0 | case XML_SCHEMA_TYPE_CHOICE: |
1115 | 0 | return(BAD_CAST "model group (choice)"); |
1116 | 0 | case XML_SCHEMA_TYPE_ALL: |
1117 | 0 | return(BAD_CAST "model group (all)"); |
1118 | 0 | case XML_SCHEMA_TYPE_PARTICLE: |
1119 | 0 | return(BAD_CAST "particle"); |
1120 | 0 | case XML_SCHEMA_TYPE_IDC_UNIQUE: |
1121 | 0 | return(BAD_CAST "unique identity-constraint"); |
1122 | | /* return(BAD_CAST "IDC (unique)"); */ |
1123 | 0 | case XML_SCHEMA_TYPE_IDC_KEY: |
1124 | 0 | return(BAD_CAST "key identity-constraint"); |
1125 | | /* return(BAD_CAST "IDC (key)"); */ |
1126 | 0 | case XML_SCHEMA_TYPE_IDC_KEYREF: |
1127 | 0 | return(BAD_CAST "keyref identity-constraint"); |
1128 | | /* return(BAD_CAST "IDC (keyref)"); */ |
1129 | 0 | case XML_SCHEMA_TYPE_ANY: |
1130 | 0 | return(BAD_CAST "wildcard (any)"); |
1131 | 0 | case XML_SCHEMA_EXTRA_QNAMEREF: |
1132 | 0 | return(BAD_CAST "[helper component] QName reference"); |
1133 | 0 | case XML_SCHEMA_EXTRA_ATTR_USE_PROHIB: |
1134 | 0 | return(BAD_CAST "[helper component] attribute use prohibition"); |
1135 | 0 | default: |
1136 | 0 | return(BAD_CAST "Not a schema component"); |
1137 | 0 | } |
1138 | 0 | } |
1139 | | |
1140 | | /** |
1141 | | * @param item the type of the schema item |
1142 | | * @returns the component name of a schema item. |
1143 | | */ |
1144 | | static const xmlChar * |
1145 | | xmlSchemaGetComponentTypeStr(xmlSchemaBasicItemPtr item) |
1146 | 0 | { |
1147 | 0 | switch (item->type) { |
1148 | 0 | case XML_SCHEMA_TYPE_BASIC: |
1149 | 0 | if (WXS_IS_COMPLEX(WXS_TYPE_CAST item)) |
1150 | 0 | return(BAD_CAST "complex type definition"); |
1151 | 0 | else |
1152 | 0 | return(BAD_CAST "simple type definition"); |
1153 | 0 | default: |
1154 | 0 | return(xmlSchemaItemTypeToStr(item->type)); |
1155 | 0 | } |
1156 | 0 | } |
1157 | | |
1158 | | /** |
1159 | | * @param item a schema component |
1160 | | * @returns node associated with the schema component. |
1161 | | * NOTE that such a node need not be available; plus, a component's |
1162 | | * node need not to reflect the component directly, since there is no |
1163 | | * one-to-one relationship between the XML Schema representation and |
1164 | | * the component representation. |
1165 | | */ |
1166 | | static xmlNodePtr |
1167 | | xmlSchemaGetComponentNode(xmlSchemaBasicItemPtr item) |
1168 | 0 | { |
1169 | 0 | switch (item->type) { |
1170 | 0 | case XML_SCHEMA_TYPE_ELEMENT: |
1171 | 0 | return (((xmlSchemaElementPtr) item)->node); |
1172 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTE: |
1173 | 0 | return (((xmlSchemaAttributePtr) item)->node); |
1174 | 0 | case XML_SCHEMA_TYPE_COMPLEX: |
1175 | 0 | case XML_SCHEMA_TYPE_SIMPLE: |
1176 | 0 | return (((xmlSchemaTypePtr) item)->node); |
1177 | 0 | case XML_SCHEMA_TYPE_ANY: |
1178 | 0 | case XML_SCHEMA_TYPE_ANY_ATTRIBUTE: |
1179 | 0 | return (((xmlSchemaWildcardPtr) item)->node); |
1180 | 0 | case XML_SCHEMA_TYPE_PARTICLE: |
1181 | 0 | return (((xmlSchemaParticlePtr) item)->node); |
1182 | 0 | case XML_SCHEMA_TYPE_SEQUENCE: |
1183 | 0 | case XML_SCHEMA_TYPE_CHOICE: |
1184 | 0 | case XML_SCHEMA_TYPE_ALL: |
1185 | 0 | return (((xmlSchemaModelGroupPtr) item)->node); |
1186 | 0 | case XML_SCHEMA_TYPE_GROUP: |
1187 | 0 | return (((xmlSchemaModelGroupDefPtr) item)->node); |
1188 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
1189 | 0 | return (((xmlSchemaAttributeGroupPtr) item)->node); |
1190 | 0 | case XML_SCHEMA_TYPE_IDC_UNIQUE: |
1191 | 0 | case XML_SCHEMA_TYPE_IDC_KEY: |
1192 | 0 | case XML_SCHEMA_TYPE_IDC_KEYREF: |
1193 | 0 | return (((xmlSchemaIDCPtr) item)->node); |
1194 | 0 | case XML_SCHEMA_EXTRA_QNAMEREF: |
1195 | 0 | return(((xmlSchemaQNameRefPtr) item)->node); |
1196 | | /* TODO: What to do with NOTATIONs? |
1197 | | case XML_SCHEMA_TYPE_NOTATION: |
1198 | | return (((xmlSchemaNotationPtr) item)->node); |
1199 | | */ |
1200 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTE_USE: |
1201 | 0 | return (((xmlSchemaAttributeUsePtr) item)->node); |
1202 | 0 | default: |
1203 | 0 | return (NULL); |
1204 | 0 | } |
1205 | 0 | } |
1206 | | |
1207 | | #if 0 |
1208 | | /** |
1209 | | * @param item a schema component |
1210 | | * @returns the next sibling of the schema component. |
1211 | | */ |
1212 | | static xmlSchemaBasicItemPtr |
1213 | | xmlSchemaGetNextComponent(xmlSchemaBasicItemPtr item) |
1214 | | { |
1215 | | switch (item->type) { |
1216 | | case XML_SCHEMA_TYPE_ELEMENT: |
1217 | | return ((xmlSchemaBasicItemPtr) ((xmlSchemaElementPtr) item)->next); |
1218 | | case XML_SCHEMA_TYPE_ATTRIBUTE: |
1219 | | return ((xmlSchemaBasicItemPtr) ((xmlSchemaAttributePtr) item)->next); |
1220 | | case XML_SCHEMA_TYPE_COMPLEX: |
1221 | | case XML_SCHEMA_TYPE_SIMPLE: |
1222 | | return ((xmlSchemaBasicItemPtr) ((xmlSchemaTypePtr) item)->next); |
1223 | | case XML_SCHEMA_TYPE_ANY: |
1224 | | case XML_SCHEMA_TYPE_ANY_ATTRIBUTE: |
1225 | | return (NULL); |
1226 | | case XML_SCHEMA_TYPE_PARTICLE: |
1227 | | return ((xmlSchemaBasicItemPtr) ((xmlSchemaParticlePtr) item)->next); |
1228 | | case XML_SCHEMA_TYPE_SEQUENCE: |
1229 | | case XML_SCHEMA_TYPE_CHOICE: |
1230 | | case XML_SCHEMA_TYPE_ALL: |
1231 | | return (NULL); |
1232 | | case XML_SCHEMA_TYPE_GROUP: |
1233 | | return (NULL); |
1234 | | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
1235 | | return ((xmlSchemaBasicItemPtr) ((xmlSchemaAttributeGroupPtr) item)->next); |
1236 | | case XML_SCHEMA_TYPE_IDC_UNIQUE: |
1237 | | case XML_SCHEMA_TYPE_IDC_KEY: |
1238 | | case XML_SCHEMA_TYPE_IDC_KEYREF: |
1239 | | return ((xmlSchemaBasicItemPtr) ((xmlSchemaIDCPtr) item)->next); |
1240 | | default: |
1241 | | return (NULL); |
1242 | | } |
1243 | | } |
1244 | | #endif |
1245 | | |
1246 | | |
1247 | | /** |
1248 | | * Returns the given QName in the format "{namespaceName}localName" or |
1249 | | * just "localName" if `namespaceName` is NULL. |
1250 | | * |
1251 | | * @param buf the string buffer |
1252 | | * @param namespaceName the namespace name |
1253 | | * @param localName the local name |
1254 | | * @returns the localName if `namespaceName` is NULL, a formatted |
1255 | | * string otherwise. |
1256 | | */ |
1257 | | static const xmlChar* |
1258 | | xmlSchemaFormatQName(xmlChar **buf, |
1259 | | const xmlChar *namespaceName, |
1260 | | const xmlChar *localName) |
1261 | 0 | { |
1262 | 0 | FREE_AND_NULL(*buf) |
1263 | 0 | if (namespaceName != NULL) { |
1264 | 0 | *buf = xmlStrdup(BAD_CAST "{"); |
1265 | 0 | *buf = xmlStrcat(*buf, namespaceName); |
1266 | 0 | *buf = xmlStrcat(*buf, BAD_CAST "}"); |
1267 | 0 | } |
1268 | 0 | if (localName != NULL) { |
1269 | 0 | if (namespaceName == NULL) |
1270 | 0 | return(localName); |
1271 | 0 | *buf = xmlStrcat(*buf, localName); |
1272 | 0 | } else { |
1273 | 0 | *buf = xmlStrcat(*buf, BAD_CAST "(NULL)"); |
1274 | 0 | } |
1275 | 0 | return ((const xmlChar *) *buf); |
1276 | 0 | } |
1277 | | |
1278 | | static const xmlChar* |
1279 | | xmlSchemaFormatQNameNs(xmlChar **buf, xmlNsPtr ns, const xmlChar *localName) |
1280 | 0 | { |
1281 | 0 | if (ns != NULL) |
1282 | 0 | return (xmlSchemaFormatQName(buf, ns->href, localName)); |
1283 | 0 | else |
1284 | 0 | return (xmlSchemaFormatQName(buf, NULL, localName)); |
1285 | 0 | } |
1286 | | |
1287 | | static const xmlChar * |
1288 | | xmlSchemaGetComponentName(xmlSchemaBasicItemPtr item) |
1289 | 0 | { |
1290 | 0 | if (item == NULL) { |
1291 | 0 | return (NULL); |
1292 | 0 | } |
1293 | 0 | switch (item->type) { |
1294 | 0 | case XML_SCHEMA_TYPE_ELEMENT: |
1295 | 0 | return (((xmlSchemaElementPtr) item)->name); |
1296 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTE: |
1297 | 0 | return (((xmlSchemaAttributePtr) item)->name); |
1298 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
1299 | 0 | return (((xmlSchemaAttributeGroupPtr) item)->name); |
1300 | 0 | case XML_SCHEMA_TYPE_BASIC: |
1301 | 0 | case XML_SCHEMA_TYPE_SIMPLE: |
1302 | 0 | case XML_SCHEMA_TYPE_COMPLEX: |
1303 | 0 | return (((xmlSchemaTypePtr) item)->name); |
1304 | 0 | case XML_SCHEMA_TYPE_GROUP: |
1305 | 0 | return (((xmlSchemaModelGroupDefPtr) item)->name); |
1306 | 0 | case XML_SCHEMA_TYPE_IDC_KEY: |
1307 | 0 | case XML_SCHEMA_TYPE_IDC_UNIQUE: |
1308 | 0 | case XML_SCHEMA_TYPE_IDC_KEYREF: |
1309 | 0 | return (((xmlSchemaIDCPtr) item)->name); |
1310 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTE_USE: |
1311 | 0 | if (WXS_ATTRUSE_DECL(item) != NULL) { |
1312 | 0 | return(xmlSchemaGetComponentName( |
1313 | 0 | WXS_BASIC_CAST WXS_ATTRUSE_DECL(item))); |
1314 | 0 | } else |
1315 | 0 | return(NULL); |
1316 | 0 | case XML_SCHEMA_EXTRA_QNAMEREF: |
1317 | 0 | return (((xmlSchemaQNameRefPtr) item)->name); |
1318 | 0 | case XML_SCHEMA_TYPE_NOTATION: |
1319 | 0 | return (((xmlSchemaNotationPtr) item)->name); |
1320 | 0 | default: |
1321 | | /* |
1322 | | * Other components cannot have names. |
1323 | | */ |
1324 | 0 | break; |
1325 | 0 | } |
1326 | 0 | return (NULL); |
1327 | 0 | } |
1328 | | |
1329 | 0 | #define xmlSchemaGetQNameRefName(r) (WXS_QNAME_CAST (r))->name |
1330 | 0 | #define xmlSchemaGetQNameRefTargetNs(r) (WXS_QNAME_CAST (r))->targetNamespace |
1331 | | /* |
1332 | | static const xmlChar * |
1333 | | xmlSchemaGetQNameRefName(void *ref) |
1334 | | { |
1335 | | return(((xmlSchemaQNameRefPtr) ref)->name); |
1336 | | } |
1337 | | |
1338 | | static const xmlChar * |
1339 | | xmlSchemaGetQNameRefTargetNs(void *ref) |
1340 | | { |
1341 | | return(((xmlSchemaQNameRefPtr) ref)->targetNamespace); |
1342 | | } |
1343 | | */ |
1344 | | |
1345 | | static const xmlChar * |
1346 | | xmlSchemaGetComponentTargetNs(xmlSchemaBasicItemPtr item) |
1347 | 0 | { |
1348 | 0 | if (item == NULL) { |
1349 | 0 | return (NULL); |
1350 | 0 | } |
1351 | 0 | switch (item->type) { |
1352 | 0 | case XML_SCHEMA_TYPE_ELEMENT: |
1353 | 0 | return (((xmlSchemaElementPtr) item)->targetNamespace); |
1354 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTE: |
1355 | 0 | return (((xmlSchemaAttributePtr) item)->targetNamespace); |
1356 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
1357 | 0 | return (((xmlSchemaAttributeGroupPtr) item)->targetNamespace); |
1358 | 0 | case XML_SCHEMA_TYPE_BASIC: |
1359 | 0 | return (BAD_CAST "http://www.w3.org/2001/XMLSchema"); |
1360 | 0 | case XML_SCHEMA_TYPE_SIMPLE: |
1361 | 0 | case XML_SCHEMA_TYPE_COMPLEX: |
1362 | 0 | return (((xmlSchemaTypePtr) item)->targetNamespace); |
1363 | 0 | case XML_SCHEMA_TYPE_GROUP: |
1364 | 0 | return (((xmlSchemaModelGroupDefPtr) item)->targetNamespace); |
1365 | 0 | case XML_SCHEMA_TYPE_IDC_KEY: |
1366 | 0 | case XML_SCHEMA_TYPE_IDC_UNIQUE: |
1367 | 0 | case XML_SCHEMA_TYPE_IDC_KEYREF: |
1368 | 0 | return (((xmlSchemaIDCPtr) item)->targetNamespace); |
1369 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTE_USE: |
1370 | 0 | if (WXS_ATTRUSE_DECL(item) != NULL) { |
1371 | 0 | return(xmlSchemaGetComponentTargetNs( |
1372 | 0 | WXS_BASIC_CAST WXS_ATTRUSE_DECL(item))); |
1373 | 0 | } |
1374 | | /* TODO: Will returning NULL break something? */ |
1375 | 0 | break; |
1376 | 0 | case XML_SCHEMA_EXTRA_QNAMEREF: |
1377 | 0 | return (((xmlSchemaQNameRefPtr) item)->targetNamespace); |
1378 | 0 | case XML_SCHEMA_TYPE_NOTATION: |
1379 | 0 | return (((xmlSchemaNotationPtr) item)->targetNamespace); |
1380 | 0 | default: |
1381 | | /* |
1382 | | * Other components cannot have names. |
1383 | | */ |
1384 | 0 | break; |
1385 | 0 | } |
1386 | 0 | return (NULL); |
1387 | 0 | } |
1388 | | |
1389 | | static const xmlChar* |
1390 | | xmlSchemaGetComponentQName(xmlChar **buf, |
1391 | | void *item) |
1392 | 0 | { |
1393 | 0 | return (xmlSchemaFormatQName(buf, |
1394 | 0 | xmlSchemaGetComponentTargetNs((xmlSchemaBasicItemPtr) item), |
1395 | 0 | xmlSchemaGetComponentName((xmlSchemaBasicItemPtr) item))); |
1396 | 0 | } |
1397 | | |
1398 | | static const xmlChar* |
1399 | | xmlSchemaGetComponentDesignation(xmlChar **buf, void *item) |
1400 | 0 | { |
1401 | 0 | xmlChar *str = NULL; |
1402 | |
|
1403 | 0 | *buf = xmlStrcat(*buf, WXS_ITEM_TYPE_NAME(item)); |
1404 | 0 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
1405 | 0 | *buf = xmlStrcat(*buf, xmlSchemaGetComponentQName(&str, |
1406 | 0 | (xmlSchemaBasicItemPtr) item)); |
1407 | 0 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
1408 | 0 | FREE_AND_NULL(str); |
1409 | 0 | return(*buf); |
1410 | 0 | } |
1411 | | |
1412 | | static const xmlChar* |
1413 | | xmlSchemaGetIDCDesignation(xmlChar **buf, xmlSchemaIDCPtr idc) |
1414 | 0 | { |
1415 | 0 | return(xmlSchemaGetComponentDesignation(buf, idc)); |
1416 | 0 | } |
1417 | | |
1418 | | /** |
1419 | | * @param pc the type of processContents |
1420 | | * @returns a string representation of the type of |
1421 | | * processContents. |
1422 | | */ |
1423 | | static const xmlChar * |
1424 | | xmlSchemaWildcardPCToString(int pc) |
1425 | 0 | { |
1426 | 0 | switch (pc) { |
1427 | 0 | case XML_SCHEMAS_ANY_SKIP: |
1428 | 0 | return (BAD_CAST "skip"); |
1429 | 0 | case XML_SCHEMAS_ANY_LAX: |
1430 | 0 | return (BAD_CAST "lax"); |
1431 | 0 | case XML_SCHEMAS_ANY_STRICT: |
1432 | 0 | return (BAD_CAST "strict"); |
1433 | 0 | default: |
1434 | 0 | return (BAD_CAST "invalid process contents"); |
1435 | 0 | } |
1436 | 0 | } |
1437 | | |
1438 | | /** |
1439 | | * Get a the canonical representation of the value. |
1440 | | * The caller has to free the returned retValue. |
1441 | | * |
1442 | | * @param val the precomputed value |
1443 | | * @param retValue the returned value |
1444 | | * @param ws the whitespace type of the value |
1445 | | * @param for_hash non-zero if this is supposed to generate a string for hashing |
1446 | | * @returns 0 if the value could be built and -1 in case of |
1447 | | * API errors or if the value type is not supported yet. |
1448 | | */ |
1449 | | static int |
1450 | | xmlSchemaGetCanonValueWhtspExt_1(xmlSchemaValPtr val, |
1451 | | xmlSchemaWhitespaceValueType ws, |
1452 | | xmlChar **retValue, |
1453 | | int for_hash) |
1454 | 0 | { |
1455 | 0 | int list; |
1456 | 0 | xmlSchemaValType valType; |
1457 | 0 | const xmlChar *value, *value2 = NULL; |
1458 | | |
1459 | |
|
1460 | 0 | if ((retValue == NULL) || (val == NULL)) |
1461 | 0 | return (-1); |
1462 | 0 | list = xmlSchemaValueGetNext(val) ? 1 : 0; |
1463 | 0 | *retValue = NULL; |
1464 | 0 | do { |
1465 | 0 | value = NULL; |
1466 | 0 | valType = xmlSchemaGetValType(val); |
1467 | 0 | switch (valType) { |
1468 | 0 | case XML_SCHEMAS_STRING: |
1469 | 0 | case XML_SCHEMAS_NORMSTRING: |
1470 | 0 | case XML_SCHEMAS_ANYSIMPLETYPE: |
1471 | 0 | value = xmlSchemaValueGetAsString(val); |
1472 | 0 | if (value != NULL) { |
1473 | 0 | if (ws == XML_SCHEMA_WHITESPACE_COLLAPSE) |
1474 | 0 | value2 = xmlSchemaCollapseString(value); |
1475 | 0 | else if (ws == XML_SCHEMA_WHITESPACE_REPLACE) |
1476 | 0 | value2 = xmlSchemaWhiteSpaceReplace(value); |
1477 | 0 | if (value2 != NULL) |
1478 | 0 | value = value2; |
1479 | 0 | } |
1480 | 0 | break; |
1481 | 0 | default: |
1482 | 0 | if (xmlSchemaGetCanonValue(val, &value2) == -1) { |
1483 | 0 | if (value2 != NULL) |
1484 | 0 | xmlFree((xmlChar *) value2); |
1485 | 0 | goto internal_error; |
1486 | 0 | } |
1487 | 0 | if (for_hash && valType == XML_SCHEMAS_DECIMAL) { |
1488 | | /* We can mostly use the canonical value for hashing, |
1489 | | except in the case of decimal. There the canonical |
1490 | | representation requires a trailing '.0' even for |
1491 | | non-fractional numbers, but for the derived integer |
1492 | | types it forbids any decimal point. Nevertheless they |
1493 | | compare equal if the value is equal. We need to generate |
1494 | | the same hash value for this to work, and it's easiest |
1495 | | to just cut off the useless '.0' suffix for the |
1496 | | decimal type. */ |
1497 | 0 | int len = xmlStrlen(value2); |
1498 | 0 | if (len > 2 && value2[len-1] == '0' && value2[len-2] == '.') |
1499 | 0 | ((xmlChar*)value2)[len-2] = 0; |
1500 | 0 | } |
1501 | 0 | value = value2; |
1502 | 0 | } |
1503 | 0 | if (*retValue == NULL) |
1504 | 0 | if (value == NULL) { |
1505 | 0 | if (! list) |
1506 | 0 | *retValue = xmlStrdup(BAD_CAST ""); |
1507 | 0 | } else |
1508 | 0 | *retValue = xmlStrdup(value); |
1509 | 0 | else if (value != NULL) { |
1510 | | /* List. */ |
1511 | 0 | *retValue = xmlStrcat((xmlChar *) *retValue, BAD_CAST " "); |
1512 | 0 | *retValue = xmlStrcat((xmlChar *) *retValue, value); |
1513 | 0 | } |
1514 | 0 | FREE_AND_NULL(value2) |
1515 | 0 | val = xmlSchemaValueGetNext(val); |
1516 | 0 | } while (val != NULL); |
1517 | | |
1518 | 0 | return (0); |
1519 | 0 | internal_error: |
1520 | 0 | if (*retValue != NULL) |
1521 | 0 | xmlFree((xmlChar *) (*retValue)); |
1522 | 0 | if (value2 != NULL) |
1523 | 0 | xmlFree((xmlChar *) value2); |
1524 | 0 | return (-1); |
1525 | 0 | } |
1526 | | |
1527 | | static int |
1528 | | xmlSchemaGetCanonValueWhtspExt(xmlSchemaValPtr val, |
1529 | | xmlSchemaWhitespaceValueType ws, |
1530 | | xmlChar **retValue) |
1531 | 0 | { |
1532 | 0 | return xmlSchemaGetCanonValueWhtspExt_1(val, ws, retValue, 0); |
1533 | 0 | } |
1534 | | |
1535 | | static int |
1536 | | xmlSchemaGetCanonValueHash(xmlSchemaValPtr val, |
1537 | | xmlChar **retValue) |
1538 | 0 | { |
1539 | 0 | return xmlSchemaGetCanonValueWhtspExt_1(val, XML_SCHEMA_WHITESPACE_COLLAPSE, |
1540 | 0 | retValue, 1); |
1541 | 0 | } |
1542 | | |
1543 | | /** |
1544 | | * The following order is used to build the resulting |
1545 | | * designation if the arguments are not NULL: |
1546 | | * 1a. If itemDes not NULL -> itemDes |
1547 | | * 1b. If (itemDes not NULL) and (itemName not NULL) |
1548 | | * -> itemDes + itemName |
1549 | | * 2. If the preceding was NULL and (item not NULL) -> item |
1550 | | * 3. If the preceding was NULL and (itemNode not NULL) -> itemNode |
1551 | | * |
1552 | | * If the itemNode is an attribute node, the name of the attribute |
1553 | | * will be appended to the result. |
1554 | | * |
1555 | | * Returns a representation of the given item used |
1556 | | * for error reports. |
1557 | | * |
1558 | | * @param buf the string buffer |
1559 | | * @param itemDes the designation of the item |
1560 | | * @param item the item as an object |
1561 | | * @param itemNode the node of the item |
1562 | | * @returns the formatted string and sets `buf` to the resulting value. |
1563 | | */ |
1564 | | static xmlChar* |
1565 | | xmlSchemaFormatItemForReport(xmlChar **buf, |
1566 | | const xmlChar *itemDes, |
1567 | | xmlSchemaBasicItemPtr item, |
1568 | | xmlNodePtr itemNode) |
1569 | 0 | { |
1570 | 0 | xmlChar *str = NULL; |
1571 | 0 | int named = 1; |
1572 | |
|
1573 | 0 | if (*buf != NULL) { |
1574 | 0 | xmlFree(*buf); |
1575 | 0 | *buf = NULL; |
1576 | 0 | } |
1577 | |
|
1578 | 0 | if (itemDes != NULL) { |
1579 | 0 | *buf = xmlStrdup(itemDes); |
1580 | 0 | } else if (item != NULL) { |
1581 | 0 | switch (item->type) { |
1582 | 0 | case XML_SCHEMA_TYPE_BASIC: { |
1583 | 0 | xmlSchemaTypePtr type = WXS_TYPE_CAST item; |
1584 | |
|
1585 | 0 | if (WXS_IS_ATOMIC(type)) |
1586 | 0 | *buf = xmlStrdup(BAD_CAST "atomic type 'xs:"); |
1587 | 0 | else if (WXS_IS_LIST(type)) |
1588 | 0 | *buf = xmlStrdup(BAD_CAST "list type 'xs:"); |
1589 | 0 | else if (WXS_IS_UNION(type)) |
1590 | 0 | *buf = xmlStrdup(BAD_CAST "union type 'xs:"); |
1591 | 0 | else |
1592 | 0 | *buf = xmlStrdup(BAD_CAST "simple type 'xs:"); |
1593 | 0 | *buf = xmlStrcat(*buf, type->name); |
1594 | 0 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
1595 | 0 | } |
1596 | 0 | break; |
1597 | 0 | case XML_SCHEMA_TYPE_SIMPLE: { |
1598 | 0 | xmlSchemaTypePtr type = WXS_TYPE_CAST item; |
1599 | |
|
1600 | 0 | if (type->flags & XML_SCHEMAS_TYPE_GLOBAL) { |
1601 | 0 | *buf = xmlStrdup(BAD_CAST""); |
1602 | 0 | } else { |
1603 | 0 | *buf = xmlStrdup(BAD_CAST "local "); |
1604 | 0 | } |
1605 | 0 | if (WXS_IS_ATOMIC(type)) |
1606 | 0 | *buf = xmlStrcat(*buf, BAD_CAST "atomic type"); |
1607 | 0 | else if (WXS_IS_LIST(type)) |
1608 | 0 | *buf = xmlStrcat(*buf, BAD_CAST "list type"); |
1609 | 0 | else if (WXS_IS_UNION(type)) |
1610 | 0 | *buf = xmlStrcat(*buf, BAD_CAST "union type"); |
1611 | 0 | else |
1612 | 0 | *buf = xmlStrcat(*buf, BAD_CAST "simple type"); |
1613 | 0 | if (type->flags & XML_SCHEMAS_TYPE_GLOBAL) { |
1614 | 0 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
1615 | 0 | *buf = xmlStrcat(*buf, type->name); |
1616 | 0 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
1617 | 0 | } |
1618 | 0 | } |
1619 | 0 | break; |
1620 | 0 | case XML_SCHEMA_TYPE_COMPLEX: { |
1621 | 0 | xmlSchemaTypePtr type = WXS_TYPE_CAST item; |
1622 | |
|
1623 | 0 | if (type->flags & XML_SCHEMAS_TYPE_GLOBAL) |
1624 | 0 | *buf = xmlStrdup(BAD_CAST ""); |
1625 | 0 | else |
1626 | 0 | *buf = xmlStrdup(BAD_CAST "local "); |
1627 | 0 | *buf = xmlStrcat(*buf, BAD_CAST "complex type"); |
1628 | 0 | if (type->flags & XML_SCHEMAS_TYPE_GLOBAL) { |
1629 | 0 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
1630 | 0 | *buf = xmlStrcat(*buf, type->name); |
1631 | 0 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
1632 | 0 | } |
1633 | 0 | } |
1634 | 0 | break; |
1635 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTE_USE: { |
1636 | 0 | xmlSchemaAttributeUsePtr ause; |
1637 | |
|
1638 | 0 | ause = WXS_ATTR_USE_CAST item; |
1639 | 0 | *buf = xmlStrdup(BAD_CAST "attribute use "); |
1640 | 0 | if (WXS_ATTRUSE_DECL(ause) != NULL) { |
1641 | 0 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
1642 | 0 | *buf = xmlStrcat(*buf, |
1643 | 0 | xmlSchemaGetComponentQName(&str, WXS_ATTRUSE_DECL(ause))); |
1644 | 0 | FREE_AND_NULL(str) |
1645 | 0 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
1646 | 0 | } else { |
1647 | 0 | *buf = xmlStrcat(*buf, BAD_CAST "(unknown)"); |
1648 | 0 | } |
1649 | 0 | } |
1650 | 0 | break; |
1651 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTE: { |
1652 | 0 | xmlSchemaAttributePtr attr; |
1653 | |
|
1654 | 0 | attr = (xmlSchemaAttributePtr) item; |
1655 | 0 | *buf = xmlStrdup(BAD_CAST "attribute decl."); |
1656 | 0 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
1657 | 0 | *buf = xmlStrcat(*buf, xmlSchemaFormatQName(&str, |
1658 | 0 | attr->targetNamespace, attr->name)); |
1659 | 0 | FREE_AND_NULL(str) |
1660 | 0 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
1661 | 0 | } |
1662 | 0 | break; |
1663 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
1664 | 0 | xmlSchemaGetComponentDesignation(buf, item); |
1665 | 0 | break; |
1666 | 0 | case XML_SCHEMA_TYPE_ELEMENT: { |
1667 | 0 | xmlSchemaElementPtr elem; |
1668 | |
|
1669 | 0 | elem = (xmlSchemaElementPtr) item; |
1670 | 0 | *buf = xmlStrdup(BAD_CAST "element decl."); |
1671 | 0 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
1672 | 0 | *buf = xmlStrcat(*buf, xmlSchemaFormatQName(&str, |
1673 | 0 | elem->targetNamespace, elem->name)); |
1674 | 0 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
1675 | 0 | } |
1676 | 0 | break; |
1677 | 0 | case XML_SCHEMA_TYPE_IDC_UNIQUE: |
1678 | 0 | case XML_SCHEMA_TYPE_IDC_KEY: |
1679 | 0 | case XML_SCHEMA_TYPE_IDC_KEYREF: |
1680 | 0 | if (item->type == XML_SCHEMA_TYPE_IDC_UNIQUE) |
1681 | 0 | *buf = xmlStrdup(BAD_CAST "unique '"); |
1682 | 0 | else if (item->type == XML_SCHEMA_TYPE_IDC_KEY) |
1683 | 0 | *buf = xmlStrdup(BAD_CAST "key '"); |
1684 | 0 | else |
1685 | 0 | *buf = xmlStrdup(BAD_CAST "keyRef '"); |
1686 | 0 | *buf = xmlStrcat(*buf, ((xmlSchemaIDCPtr) item)->name); |
1687 | 0 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
1688 | 0 | break; |
1689 | 0 | case XML_SCHEMA_TYPE_ANY: |
1690 | 0 | case XML_SCHEMA_TYPE_ANY_ATTRIBUTE: |
1691 | 0 | *buf = xmlStrdup(xmlSchemaWildcardPCToString( |
1692 | 0 | ((xmlSchemaWildcardPtr) item)->processContents)); |
1693 | 0 | *buf = xmlStrcat(*buf, BAD_CAST " wildcard"); |
1694 | 0 | break; |
1695 | 0 | case XML_SCHEMA_FACET_MININCLUSIVE: |
1696 | 0 | case XML_SCHEMA_FACET_MINEXCLUSIVE: |
1697 | 0 | case XML_SCHEMA_FACET_MAXINCLUSIVE: |
1698 | 0 | case XML_SCHEMA_FACET_MAXEXCLUSIVE: |
1699 | 0 | case XML_SCHEMA_FACET_TOTALDIGITS: |
1700 | 0 | case XML_SCHEMA_FACET_FRACTIONDIGITS: |
1701 | 0 | case XML_SCHEMA_FACET_PATTERN: |
1702 | 0 | case XML_SCHEMA_FACET_ENUMERATION: |
1703 | 0 | case XML_SCHEMA_FACET_WHITESPACE: |
1704 | 0 | case XML_SCHEMA_FACET_LENGTH: |
1705 | 0 | case XML_SCHEMA_FACET_MAXLENGTH: |
1706 | 0 | case XML_SCHEMA_FACET_MINLENGTH: |
1707 | 0 | *buf = xmlStrdup(BAD_CAST "facet '"); |
1708 | 0 | *buf = xmlStrcat(*buf, xmlSchemaFacetTypeToString(item->type)); |
1709 | 0 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
1710 | 0 | break; |
1711 | 0 | case XML_SCHEMA_TYPE_GROUP: { |
1712 | 0 | *buf = xmlStrdup(BAD_CAST "model group def."); |
1713 | 0 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
1714 | 0 | *buf = xmlStrcat(*buf, xmlSchemaGetComponentQName(&str, item)); |
1715 | 0 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
1716 | 0 | FREE_AND_NULL(str) |
1717 | 0 | } |
1718 | 0 | break; |
1719 | 0 | case XML_SCHEMA_TYPE_SEQUENCE: |
1720 | 0 | case XML_SCHEMA_TYPE_CHOICE: |
1721 | 0 | case XML_SCHEMA_TYPE_ALL: |
1722 | 0 | case XML_SCHEMA_TYPE_PARTICLE: |
1723 | 0 | *buf = xmlStrdup(WXS_ITEM_TYPE_NAME(item)); |
1724 | 0 | break; |
1725 | 0 | case XML_SCHEMA_TYPE_NOTATION: { |
1726 | 0 | *buf = xmlStrdup(WXS_ITEM_TYPE_NAME(item)); |
1727 | 0 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
1728 | 0 | *buf = xmlStrcat(*buf, xmlSchemaGetComponentQName(&str, item)); |
1729 | 0 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
1730 | 0 | FREE_AND_NULL(str); |
1731 | 0 | } |
1732 | | /* Falls through. */ |
1733 | 0 | default: |
1734 | 0 | named = 0; |
1735 | 0 | } |
1736 | 0 | } else |
1737 | 0 | named = 0; |
1738 | | |
1739 | 0 | if ((named == 0) && (itemNode != NULL)) { |
1740 | 0 | xmlNodePtr elem; |
1741 | |
|
1742 | 0 | if (itemNode->type == XML_ATTRIBUTE_NODE) |
1743 | 0 | elem = itemNode->parent; |
1744 | 0 | else |
1745 | 0 | elem = itemNode; |
1746 | 0 | *buf = xmlStrdup(BAD_CAST "Element '"); |
1747 | 0 | if (elem->ns != NULL) { |
1748 | 0 | *buf = xmlStrcat(*buf, |
1749 | 0 | xmlSchemaFormatQName(&str, elem->ns->href, elem->name)); |
1750 | 0 | FREE_AND_NULL(str) |
1751 | 0 | } else |
1752 | 0 | *buf = xmlStrcat(*buf, elem->name); |
1753 | 0 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
1754 | |
|
1755 | 0 | } |
1756 | 0 | if ((itemNode != NULL) && (itemNode->type == XML_ATTRIBUTE_NODE)) { |
1757 | 0 | *buf = xmlStrcat(*buf, BAD_CAST ", attribute '"); |
1758 | 0 | if (itemNode->ns != NULL) { |
1759 | 0 | *buf = xmlStrcat(*buf, xmlSchemaFormatQName(&str, |
1760 | 0 | itemNode->ns->href, itemNode->name)); |
1761 | 0 | FREE_AND_NULL(str) |
1762 | 0 | } else |
1763 | 0 | *buf = xmlStrcat(*buf, itemNode->name); |
1764 | 0 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
1765 | 0 | } |
1766 | 0 | FREE_AND_NULL(str) |
1767 | |
|
1768 | 0 | return (xmlEscapeFormatString(buf)); |
1769 | 0 | } |
1770 | | |
1771 | | /** |
1772 | | * Builds a string consisting of all enumeration elements. |
1773 | | * |
1774 | | * @param actxt schema context |
1775 | | * @param buf the string buffer |
1776 | | * @param type the type holding the enumeration facets |
1777 | | * @returns a string of all enumeration elements. |
1778 | | */ |
1779 | | static const xmlChar * |
1780 | | xmlSchemaFormatFacetEnumSet(xmlSchemaAbstractCtxtPtr actxt, |
1781 | | xmlChar **buf, xmlSchemaTypePtr type) |
1782 | 0 | { |
1783 | 0 | xmlSchemaFacetPtr facet; |
1784 | 0 | xmlSchemaWhitespaceValueType ws; |
1785 | 0 | xmlChar *value = NULL; |
1786 | 0 | int res, found = 0; |
1787 | |
|
1788 | 0 | if (*buf != NULL) |
1789 | 0 | xmlFree(*buf); |
1790 | 0 | *buf = NULL; |
1791 | |
|
1792 | 0 | do { |
1793 | | /* |
1794 | | * Use the whitespace type of the base type. |
1795 | | */ |
1796 | 0 | ws = xmlSchemaGetWhiteSpaceFacetValue(type->baseType); |
1797 | 0 | for (facet = type->facets; facet != NULL; facet = facet->next) { |
1798 | 0 | if (facet->type != XML_SCHEMA_FACET_ENUMERATION) |
1799 | 0 | continue; |
1800 | 0 | found = 1; |
1801 | 0 | res = xmlSchemaGetCanonValueWhtspExt(facet->val, |
1802 | 0 | ws, &value); |
1803 | 0 | if (res == -1) { |
1804 | 0 | xmlSchemaInternalErr(actxt, |
1805 | 0 | "xmlSchemaFormatFacetEnumSet", |
1806 | 0 | "compute the canonical lexical representation"); |
1807 | 0 | if (*buf != NULL) |
1808 | 0 | xmlFree(*buf); |
1809 | 0 | *buf = NULL; |
1810 | 0 | return (NULL); |
1811 | 0 | } |
1812 | 0 | if (*buf == NULL) |
1813 | 0 | *buf = xmlStrdup(BAD_CAST "'"); |
1814 | 0 | else |
1815 | 0 | *buf = xmlStrcat(*buf, BAD_CAST ", '"); |
1816 | 0 | *buf = xmlStrcat(*buf, BAD_CAST value); |
1817 | 0 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
1818 | 0 | if (value != NULL) { |
1819 | 0 | xmlFree((xmlChar *)value); |
1820 | 0 | value = NULL; |
1821 | 0 | } |
1822 | 0 | } |
1823 | | /* |
1824 | | * The enumeration facet of a type restricts the enumeration |
1825 | | * facet of the ancestor type; i.e., such restricted enumerations |
1826 | | * do not belong to the set of the given type. Thus we break |
1827 | | * on the first found enumeration. |
1828 | | */ |
1829 | 0 | if (found) |
1830 | 0 | break; |
1831 | 0 | type = type->baseType; |
1832 | 0 | } while ((type != NULL) && (type->type != XML_SCHEMA_TYPE_BASIC)); |
1833 | | |
1834 | 0 | return ((const xmlChar *) *buf); |
1835 | 0 | } |
1836 | | |
1837 | | /************************************************************************ |
1838 | | * * |
1839 | | * Error functions * |
1840 | | * * |
1841 | | ************************************************************************/ |
1842 | | |
1843 | | /** |
1844 | | * Handle an out of memory condition |
1845 | | * |
1846 | | * @param ctxt schema parser context |
1847 | | */ |
1848 | | static void |
1849 | | xmlSchemaPErrMemory(xmlSchemaParserCtxtPtr ctxt) |
1850 | 0 | { |
1851 | 0 | xmlGenericErrorFunc channel = NULL; |
1852 | 0 | xmlStructuredErrorFunc schannel = NULL; |
1853 | 0 | void *data = NULL; |
1854 | |
|
1855 | 0 | if (ctxt != NULL) { |
1856 | 0 | ctxt->nberrors++; |
1857 | 0 | ctxt->err = XML_ERR_NO_MEMORY; |
1858 | 0 | channel = ctxt->error; |
1859 | 0 | schannel = ctxt->serror; |
1860 | 0 | data = ctxt->errCtxt; |
1861 | 0 | } |
1862 | |
|
1863 | 0 | xmlRaiseMemoryError(schannel, channel, data, XML_FROM_SCHEMASP, NULL); |
1864 | 0 | } |
1865 | | |
1866 | | static void LIBXML_ATTR_FORMAT(11,12) |
1867 | | xmlSchemaPErrFull(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int code, |
1868 | | xmlErrorLevel level, const char *file, int line, |
1869 | | const xmlChar *str1, const xmlChar *str2, const xmlChar *str3, |
1870 | 0 | int col, const char *msg, ...) { |
1871 | 0 | xmlGenericErrorFunc channel = NULL; |
1872 | 0 | xmlStructuredErrorFunc schannel = NULL; |
1873 | 0 | void *data = NULL; |
1874 | 0 | int res; |
1875 | 0 | va_list ap; |
1876 | |
|
1877 | 0 | if (ctxt != NULL) { |
1878 | | /* Don't overwrite memory errors */ |
1879 | 0 | if (ctxt->err == XML_ERR_NO_MEMORY) |
1880 | 0 | return; |
1881 | | |
1882 | 0 | if (level == XML_ERR_WARNING) { |
1883 | 0 | channel = ctxt->warning; |
1884 | 0 | } else { |
1885 | 0 | ctxt->nberrors++; |
1886 | 0 | ctxt->err = code; |
1887 | 0 | channel = ctxt->error; |
1888 | 0 | } |
1889 | 0 | data = ctxt->errCtxt; |
1890 | 0 | schannel = ctxt->serror; |
1891 | 0 | } |
1892 | | |
1893 | 0 | if ((channel == NULL) && (schannel == NULL)) { |
1894 | 0 | channel = xmlGenericError; |
1895 | 0 | data = xmlGenericErrorContext; |
1896 | 0 | } |
1897 | |
|
1898 | 0 | va_start(ap, msg); |
1899 | 0 | res = xmlVRaiseError(schannel, channel, data, ctxt, node, |
1900 | 0 | XML_FROM_SCHEMASP, code, level, file, line, |
1901 | 0 | (const char *) str1, |
1902 | 0 | (const char *) str2, |
1903 | 0 | (const char *) str3, |
1904 | 0 | 0, col, msg, ap); |
1905 | 0 | va_end(ap); |
1906 | |
|
1907 | 0 | if (res < 0) |
1908 | 0 | xmlSchemaPErrMemory(ctxt); |
1909 | 0 | } |
1910 | | |
1911 | | /** |
1912 | | * Handle a parser error |
1913 | | * |
1914 | | * @param ctxt the parsing context |
1915 | | * @param node the context node |
1916 | | * @param code the error code |
1917 | | * @param msg the error message |
1918 | | * @param str1 extra data |
1919 | | * @param str2 extra data |
1920 | | */ |
1921 | | static void LIBXML_ATTR_FORMAT(4,0) |
1922 | | xmlSchemaPErr(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int code, |
1923 | | const char *msg, const xmlChar * str1, const xmlChar * str2) |
1924 | 0 | { |
1925 | 0 | xmlSchemaPErrFull(ctxt, node, code, XML_ERR_ERROR, NULL, 0, |
1926 | 0 | str1, str2, NULL, 0, msg, str1, str2); |
1927 | 0 | } |
1928 | | |
1929 | | /** |
1930 | | * Handle a parser error |
1931 | | * |
1932 | | * @param ctxt the parsing context |
1933 | | * @param node the context node |
1934 | | * @param child the current child |
1935 | | * @param error the error code |
1936 | | * @param msg the error message |
1937 | | * @param str1 extra data |
1938 | | * @param str2 extra data |
1939 | | */ |
1940 | | static void LIBXML_ATTR_FORMAT(5,0) |
1941 | | xmlSchemaPErr2(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, |
1942 | | xmlNodePtr child, int error, |
1943 | | const char *msg, const xmlChar * str1, const xmlChar * str2) |
1944 | 0 | { |
1945 | 0 | if (child != NULL) |
1946 | 0 | xmlSchemaPErr(ctxt, child, error, msg, str1, str2); |
1947 | 0 | else |
1948 | 0 | xmlSchemaPErr(ctxt, node, error, msg, str1, str2); |
1949 | 0 | } |
1950 | | |
1951 | | |
1952 | | /** |
1953 | | * Handle a parser error |
1954 | | * |
1955 | | * @param ctxt the parsing context |
1956 | | * @param node the context node |
1957 | | * @param code the error code |
1958 | | * @param strData1 extra data |
1959 | | * @param strData2 extra data |
1960 | | * @param strData3 extra data |
1961 | | * @param msg the message |
1962 | | * @param str1 extra parameter for the message display |
1963 | | * @param str2 extra parameter for the message display |
1964 | | * @param str3 extra parameter for the message display |
1965 | | * @param str4 extra parameter for the message display |
1966 | | * @param str5 extra parameter for the message display |
1967 | | */ |
1968 | | static void LIBXML_ATTR_FORMAT(7,0) |
1969 | | xmlSchemaPErrExt(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int code, |
1970 | | const xmlChar * strData1, const xmlChar * strData2, |
1971 | | const xmlChar * strData3, const char *msg, const xmlChar * str1, |
1972 | | const xmlChar * str2, const xmlChar * str3, const xmlChar * str4, |
1973 | | const xmlChar * str5) |
1974 | 0 | { |
1975 | 0 | xmlSchemaPErrFull(ctxt, node, code, XML_ERR_ERROR, NULL, 0, |
1976 | 0 | strData1, strData2, strData3, 0, |
1977 | 0 | msg, str1, str2, str3, str4, str5); |
1978 | 0 | } |
1979 | | |
1980 | | /************************************************************************ |
1981 | | * * |
1982 | | * Allround error functions * |
1983 | | * * |
1984 | | ************************************************************************/ |
1985 | | |
1986 | | /** |
1987 | | * Handle an out of memory condition |
1988 | | * |
1989 | | * @param ctxt schema validation context |
1990 | | */ |
1991 | | static void |
1992 | | xmlSchemaVErrMemory(xmlSchemaValidCtxtPtr ctxt) |
1993 | 0 | { |
1994 | 0 | xmlGenericErrorFunc channel = NULL; |
1995 | 0 | xmlStructuredErrorFunc schannel = NULL; |
1996 | 0 | void *data = NULL; |
1997 | |
|
1998 | 0 | if (ctxt != NULL) { |
1999 | 0 | ctxt->nberrors++; |
2000 | 0 | ctxt->err = XML_ERR_NO_MEMORY; |
2001 | 0 | channel = ctxt->error; |
2002 | 0 | schannel = ctxt->serror; |
2003 | 0 | data = ctxt->errCtxt; |
2004 | 0 | } |
2005 | |
|
2006 | 0 | xmlRaiseMemoryError(schannel, channel, data, XML_FROM_SCHEMASV, NULL); |
2007 | 0 | } |
2008 | | |
2009 | | static void LIBXML_ATTR_FORMAT(11,12) |
2010 | | xmlSchemaVErrFull(xmlSchemaValidCtxtPtr ctxt, xmlNodePtr node, int code, |
2011 | | xmlErrorLevel level, const char *file, int line, |
2012 | | const xmlChar *str1, const xmlChar *str2, const xmlChar *str3, |
2013 | 0 | int col, const char *msg, ...) { |
2014 | 0 | xmlGenericErrorFunc channel = NULL; |
2015 | 0 | xmlStructuredErrorFunc schannel = NULL; |
2016 | 0 | void *data = NULL; |
2017 | 0 | int res; |
2018 | 0 | va_list ap; |
2019 | |
|
2020 | 0 | if (ctxt != NULL) { |
2021 | | /* Don't overwrite memory errors */ |
2022 | 0 | if (ctxt->err == XML_ERR_NO_MEMORY) |
2023 | 0 | return; |
2024 | | |
2025 | 0 | if (level == XML_ERR_WARNING) { |
2026 | 0 | channel = ctxt->warning; |
2027 | 0 | } else { |
2028 | 0 | ctxt->nberrors++; |
2029 | 0 | ctxt->err = code; |
2030 | 0 | channel = ctxt->error; |
2031 | 0 | } |
2032 | 0 | data = ctxt->errCtxt; |
2033 | 0 | schannel = ctxt->serror; |
2034 | 0 | } |
2035 | | |
2036 | 0 | if ((channel == NULL) && (schannel == NULL)) { |
2037 | 0 | channel = xmlGenericError; |
2038 | 0 | data = xmlGenericErrorContext; |
2039 | 0 | } |
2040 | |
|
2041 | 0 | va_start(ap, msg); |
2042 | 0 | res = xmlVRaiseError(schannel, channel, data, ctxt, node, |
2043 | 0 | XML_FROM_SCHEMASV, code, level, file, line, |
2044 | 0 | (const char *) str1, |
2045 | 0 | (const char *) str2, |
2046 | 0 | (const char *) str3, |
2047 | 0 | 0, col, msg, ap); |
2048 | 0 | va_end(ap); |
2049 | |
|
2050 | 0 | if (res < 0) |
2051 | 0 | xmlSchemaVErrMemory(ctxt); |
2052 | 0 | } |
2053 | | |
2054 | | #define WXS_ERROR_TYPE_ERROR 1 |
2055 | | #define WXS_ERROR_TYPE_WARNING 2 |
2056 | | /** |
2057 | | * Handle a validation error |
2058 | | * |
2059 | | * @param ctxt the validation context |
2060 | | * @param errorLevel the error level |
2061 | | * @param code the error code |
2062 | | * @param node the context node |
2063 | | * @param line the line number |
2064 | | * @param msg the error message |
2065 | | * @param str1 extra data |
2066 | | * @param str2 extra data |
2067 | | * @param str3 extra data |
2068 | | * @param str4 extra data |
2069 | | */ |
2070 | | static void LIBXML_ATTR_FORMAT(6,0) |
2071 | | xmlSchemaErr4Line(xmlSchemaAbstractCtxtPtr ctxt, |
2072 | | xmlErrorLevel errorLevel, |
2073 | | int code, xmlNodePtr node, int line, const char *msg, |
2074 | | const xmlChar *str1, const xmlChar *str2, |
2075 | | const xmlChar *str3, const xmlChar *str4) |
2076 | 0 | { |
2077 | 0 | if (ctxt != NULL) { |
2078 | 0 | if (ctxt->type == XML_SCHEMA_CTXT_VALIDATOR) { |
2079 | 0 | xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctxt; |
2080 | 0 | const char *file = NULL; |
2081 | 0 | int col = 0; |
2082 | | |
2083 | | /* |
2084 | | * Error node. If we specify a line number, then |
2085 | | * do not channel any node to the error function. |
2086 | | */ |
2087 | 0 | if (line == 0) { |
2088 | 0 | if ((node == NULL) && |
2089 | 0 | (vctxt->depth >= 0) && |
2090 | 0 | (vctxt->inode != NULL)) { |
2091 | 0 | node = vctxt->inode->node; |
2092 | 0 | } |
2093 | | /* |
2094 | | * Get filename and line if no node-tree. |
2095 | | */ |
2096 | 0 | if ((node == NULL) && |
2097 | 0 | (vctxt->parserCtxt != NULL) && |
2098 | 0 | (vctxt->parserCtxt->input != NULL)) { |
2099 | 0 | file = vctxt->parserCtxt->input->filename; |
2100 | 0 | if (vctxt->inode != NULL) { |
2101 | 0 | line = vctxt->inode->nodeLine; |
2102 | 0 | col = 0; |
2103 | 0 | } else { |
2104 | | /* This is inaccurate. */ |
2105 | 0 | line = vctxt->parserCtxt->input->line; |
2106 | 0 | col = vctxt->parserCtxt->input->col; |
2107 | 0 | } |
2108 | 0 | } |
2109 | 0 | } else { |
2110 | | /* |
2111 | | * Override the given node's (if any) position |
2112 | | * and channel only the given line number. |
2113 | | */ |
2114 | 0 | node = NULL; |
2115 | | /* |
2116 | | * Get filename. |
2117 | | */ |
2118 | 0 | if (vctxt->doc != NULL) |
2119 | 0 | file = (const char *) vctxt->doc->URL; |
2120 | 0 | else if ((vctxt->parserCtxt != NULL) && |
2121 | 0 | (vctxt->parserCtxt->input != NULL)) |
2122 | 0 | file = vctxt->parserCtxt->input->filename; |
2123 | 0 | } |
2124 | 0 | if (vctxt->locFunc != NULL) { |
2125 | 0 | if ((file == NULL) || (line == 0)) { |
2126 | 0 | unsigned long l; |
2127 | 0 | const char *f; |
2128 | 0 | vctxt->locFunc(vctxt->locCtxt, &f, &l); |
2129 | 0 | if (file == NULL) |
2130 | 0 | file = f; |
2131 | 0 | if (line == 0) |
2132 | 0 | line = (int) l; |
2133 | 0 | } |
2134 | 0 | } |
2135 | 0 | if ((file == NULL) && (vctxt->filename != NULL)) |
2136 | 0 | file = vctxt->filename; |
2137 | |
|
2138 | 0 | xmlSchemaVErrFull(vctxt, node, code, errorLevel, |
2139 | 0 | file, line, str1, str2, str3, col, |
2140 | 0 | msg, str1, str2, str3, str4); |
2141 | 0 | } else if (ctxt->type == XML_SCHEMA_CTXT_PARSER) { |
2142 | 0 | xmlSchemaParserCtxtPtr pctxt = (xmlSchemaParserCtxtPtr) ctxt; |
2143 | |
|
2144 | 0 | xmlSchemaPErrFull(pctxt, node, code, errorLevel, |
2145 | 0 | NULL, 0, str1, str2, str3, 0, |
2146 | 0 | msg, str1, str2, str3, str4); |
2147 | 0 | } |
2148 | 0 | } |
2149 | 0 | } |
2150 | | |
2151 | | /** |
2152 | | * Handle a validation error |
2153 | | * |
2154 | | * @param actxt the validation context |
2155 | | * @param error the error code |
2156 | | * @param node the context node |
2157 | | * @param msg the error message |
2158 | | * @param str1 extra data |
2159 | | * @param str2 extra data |
2160 | | * @param str3 extra data |
2161 | | */ |
2162 | | static void LIBXML_ATTR_FORMAT(4,0) |
2163 | | xmlSchemaErr3(xmlSchemaAbstractCtxtPtr actxt, |
2164 | | int error, xmlNodePtr node, const char *msg, |
2165 | | const xmlChar *str1, const xmlChar *str2, const xmlChar *str3) |
2166 | 0 | { |
2167 | 0 | xmlSchemaErr4Line(actxt, XML_ERR_ERROR, error, node, 0, |
2168 | 0 | msg, str1, str2, str3, NULL); |
2169 | 0 | } |
2170 | | |
2171 | | static void LIBXML_ATTR_FORMAT(4,0) |
2172 | | xmlSchemaErr4(xmlSchemaAbstractCtxtPtr actxt, |
2173 | | int error, xmlNodePtr node, const char *msg, |
2174 | | const xmlChar *str1, const xmlChar *str2, |
2175 | | const xmlChar *str3, const xmlChar *str4) |
2176 | 0 | { |
2177 | 0 | xmlSchemaErr4Line(actxt, XML_ERR_ERROR, error, node, 0, |
2178 | 0 | msg, str1, str2, str3, str4); |
2179 | 0 | } |
2180 | | |
2181 | | static void LIBXML_ATTR_FORMAT(4,0) |
2182 | | xmlSchemaErr(xmlSchemaAbstractCtxtPtr actxt, |
2183 | | int error, xmlNodePtr node, const char *msg, |
2184 | | const xmlChar *str1, const xmlChar *str2) |
2185 | 0 | { |
2186 | 0 | xmlSchemaErr4(actxt, error, node, msg, str1, str2, NULL, NULL); |
2187 | 0 | } |
2188 | | |
2189 | | static xmlChar * |
2190 | | xmlSchemaFormatNodeForError(xmlChar ** msg, |
2191 | | xmlSchemaAbstractCtxtPtr actxt, |
2192 | | xmlNodePtr node) |
2193 | 0 | { |
2194 | 0 | xmlChar *str = NULL; |
2195 | |
|
2196 | 0 | *msg = NULL; |
2197 | 0 | if ((node != NULL) && |
2198 | 0 | (node->type != XML_ELEMENT_NODE) && |
2199 | 0 | (node->type != XML_ATTRIBUTE_NODE)) |
2200 | 0 | { |
2201 | | /* |
2202 | | * Don't try to format other nodes than element and |
2203 | | * attribute nodes. |
2204 | | * Play safe and return an empty string. |
2205 | | */ |
2206 | 0 | *msg = xmlStrdup(BAD_CAST ""); |
2207 | 0 | return(*msg); |
2208 | 0 | } |
2209 | 0 | if (node != NULL) { |
2210 | | /* |
2211 | | * Work on tree nodes. |
2212 | | */ |
2213 | 0 | if (node->type == XML_ATTRIBUTE_NODE) { |
2214 | 0 | xmlNodePtr elem = node->parent; |
2215 | |
|
2216 | 0 | *msg = xmlStrdup(BAD_CAST "Element '"); |
2217 | 0 | if (elem->ns != NULL) |
2218 | 0 | *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str, |
2219 | 0 | elem->ns->href, elem->name)); |
2220 | 0 | else |
2221 | 0 | *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str, |
2222 | 0 | NULL, elem->name)); |
2223 | 0 | FREE_AND_NULL(str); |
2224 | 0 | *msg = xmlStrcat(*msg, BAD_CAST "', "); |
2225 | 0 | *msg = xmlStrcat(*msg, BAD_CAST "attribute '"); |
2226 | 0 | } else { |
2227 | 0 | *msg = xmlStrdup(BAD_CAST "Element '"); |
2228 | 0 | } |
2229 | 0 | if (node->ns != NULL) |
2230 | 0 | *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str, |
2231 | 0 | node->ns->href, node->name)); |
2232 | 0 | else |
2233 | 0 | *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str, |
2234 | 0 | NULL, node->name)); |
2235 | 0 | FREE_AND_NULL(str); |
2236 | 0 | *msg = xmlStrcat(*msg, BAD_CAST "': "); |
2237 | 0 | } else if (actxt->type == XML_SCHEMA_CTXT_VALIDATOR) { |
2238 | 0 | xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) actxt; |
2239 | | /* |
2240 | | * Work on node infos. |
2241 | | */ |
2242 | 0 | if (vctxt->inode->nodeType == XML_ATTRIBUTE_NODE) { |
2243 | 0 | xmlSchemaNodeInfoPtr ielem = |
2244 | 0 | vctxt->elemInfos[vctxt->depth]; |
2245 | |
|
2246 | 0 | *msg = xmlStrdup(BAD_CAST "Element '"); |
2247 | 0 | *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str, |
2248 | 0 | ielem->nsName, ielem->localName)); |
2249 | 0 | FREE_AND_NULL(str); |
2250 | 0 | *msg = xmlStrcat(*msg, BAD_CAST "', "); |
2251 | 0 | *msg = xmlStrcat(*msg, BAD_CAST "attribute '"); |
2252 | 0 | } else { |
2253 | 0 | *msg = xmlStrdup(BAD_CAST "Element '"); |
2254 | 0 | } |
2255 | 0 | *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str, |
2256 | 0 | vctxt->inode->nsName, vctxt->inode->localName)); |
2257 | 0 | FREE_AND_NULL(str); |
2258 | 0 | *msg = xmlStrcat(*msg, BAD_CAST "': "); |
2259 | 0 | } else if (actxt->type == XML_SCHEMA_CTXT_PARSER) { |
2260 | | /* |
2261 | | * Hmm, no node while parsing? |
2262 | | * Return an empty string, in case NULL will break something. |
2263 | | */ |
2264 | 0 | *msg = xmlStrdup(BAD_CAST ""); |
2265 | 0 | } else { |
2266 | | /* TODO */ |
2267 | 0 | return (NULL); |
2268 | 0 | } |
2269 | | |
2270 | | /* |
2271 | | * xmlSchemaFormatItemForReport() also returns an escaped format |
2272 | | * string, so do this before calling it below (in the future). |
2273 | | */ |
2274 | 0 | xmlEscapeFormatString(msg); |
2275 | | |
2276 | | /* |
2277 | | * VAL TODO: The output of the given schema component is currently |
2278 | | * disabled. |
2279 | | */ |
2280 | | #if 0 |
2281 | | if ((type != NULL) && (xmlSchemaIsGlobalItem(type))) { |
2282 | | *msg = xmlStrcat(*msg, BAD_CAST " ["); |
2283 | | *msg = xmlStrcat(*msg, xmlSchemaFormatItemForReport(&str, |
2284 | | NULL, type, NULL, 0)); |
2285 | | FREE_AND_NULL(str) |
2286 | | *msg = xmlStrcat(*msg, BAD_CAST "]"); |
2287 | | } |
2288 | | #endif |
2289 | 0 | return (*msg); |
2290 | 0 | } |
2291 | | |
2292 | | static void LIBXML_ATTR_FORMAT(3,0) |
2293 | | xmlSchemaInternalErr2(xmlSchemaAbstractCtxtPtr actxt, |
2294 | | const char *funcName, |
2295 | | const char *message, |
2296 | | const xmlChar *str1, |
2297 | | const xmlChar *str2) |
2298 | 0 | { |
2299 | 0 | xmlChar *msg = NULL; |
2300 | |
|
2301 | 0 | if (actxt == NULL) |
2302 | 0 | return; |
2303 | 0 | msg = xmlStrdup(BAD_CAST "Internal error: %s, "); |
2304 | 0 | msg = xmlStrcat(msg, BAD_CAST message); |
2305 | 0 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
2306 | |
|
2307 | 0 | if (actxt->type == XML_SCHEMA_CTXT_VALIDATOR) |
2308 | 0 | xmlSchemaErr3(actxt, XML_SCHEMAV_INTERNAL, NULL, |
2309 | 0 | (const char *) msg, (const xmlChar *) funcName, str1, str2); |
2310 | 0 | else if (actxt->type == XML_SCHEMA_CTXT_PARSER) |
2311 | 0 | xmlSchemaErr3(actxt, XML_SCHEMAP_INTERNAL, NULL, |
2312 | 0 | (const char *) msg, (const xmlChar *) funcName, str1, str2); |
2313 | |
|
2314 | 0 | FREE_AND_NULL(msg) |
2315 | 0 | } |
2316 | | |
2317 | | static void LIBXML_ATTR_FORMAT(3,0) |
2318 | | xmlSchemaInternalErr(xmlSchemaAbstractCtxtPtr actxt, |
2319 | | const char *funcName, |
2320 | | const char *message) |
2321 | 0 | { |
2322 | 0 | xmlSchemaInternalErr2(actxt, funcName, message, NULL, NULL); |
2323 | 0 | } |
2324 | | |
2325 | | #if 0 |
2326 | | static void LIBXML_ATTR_FORMAT(3,0) |
2327 | | xmlSchemaPInternalErr(xmlSchemaParserCtxtPtr pctxt, |
2328 | | const char *funcName, |
2329 | | const char *message, |
2330 | | const xmlChar *str1, |
2331 | | const xmlChar *str2) |
2332 | | { |
2333 | | xmlSchemaInternalErr2(ACTXT_CAST pctxt, funcName, message, |
2334 | | str1, str2); |
2335 | | } |
2336 | | #endif |
2337 | | |
2338 | | static void LIBXML_ATTR_FORMAT(5,0) |
2339 | | xmlSchemaCustomErr4(xmlSchemaAbstractCtxtPtr actxt, |
2340 | | xmlParserErrors error, |
2341 | | xmlNodePtr node, |
2342 | | xmlSchemaBasicItemPtr item, |
2343 | | const char *message, |
2344 | | const xmlChar *str1, const xmlChar *str2, |
2345 | | const xmlChar *str3, const xmlChar *str4) |
2346 | 0 | { |
2347 | 0 | xmlChar *msg = NULL; |
2348 | |
|
2349 | 0 | if ((node == NULL) && (item != NULL) && |
2350 | 0 | (actxt->type == XML_SCHEMA_CTXT_PARSER)) { |
2351 | 0 | node = WXS_ITEM_NODE(item); |
2352 | 0 | xmlSchemaFormatItemForReport(&msg, NULL, item, NULL); |
2353 | 0 | msg = xmlStrcat(msg, BAD_CAST ": "); |
2354 | 0 | } else |
2355 | 0 | xmlSchemaFormatNodeForError(&msg, actxt, node); |
2356 | 0 | msg = xmlStrcat(msg, (const xmlChar *) message); |
2357 | 0 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
2358 | 0 | xmlSchemaErr4(actxt, error, node, |
2359 | 0 | (const char *) msg, str1, str2, str3, str4); |
2360 | 0 | FREE_AND_NULL(msg) |
2361 | 0 | } |
2362 | | |
2363 | | static void LIBXML_ATTR_FORMAT(5,0) |
2364 | | xmlSchemaCustomErr(xmlSchemaAbstractCtxtPtr actxt, |
2365 | | xmlParserErrors error, |
2366 | | xmlNodePtr node, |
2367 | | xmlSchemaBasicItemPtr item, |
2368 | | const char *message, |
2369 | | const xmlChar *str1, |
2370 | | const xmlChar *str2) |
2371 | 0 | { |
2372 | 0 | xmlSchemaCustomErr4(actxt, error, node, item, |
2373 | 0 | message, str1, str2, NULL, NULL); |
2374 | 0 | } |
2375 | | |
2376 | | |
2377 | | |
2378 | | static void LIBXML_ATTR_FORMAT(5,0) |
2379 | | xmlSchemaCustomWarning(xmlSchemaAbstractCtxtPtr actxt, |
2380 | | xmlParserErrors error, |
2381 | | xmlNodePtr node, |
2382 | | xmlSchemaTypePtr type ATTRIBUTE_UNUSED, |
2383 | | const char *message, |
2384 | | const xmlChar *str1, |
2385 | | const xmlChar *str2, |
2386 | | const xmlChar *str3) |
2387 | 0 | { |
2388 | 0 | xmlChar *msg = NULL; |
2389 | |
|
2390 | 0 | xmlSchemaFormatNodeForError(&msg, actxt, node); |
2391 | 0 | msg = xmlStrcat(msg, (const xmlChar *) message); |
2392 | 0 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
2393 | | |
2394 | | /* URGENT TODO: Set the error code to something sane. */ |
2395 | 0 | xmlSchemaErr4Line(actxt, XML_ERR_WARNING, error, node, 0, |
2396 | 0 | (const char *) msg, str1, str2, str3, NULL); |
2397 | |
|
2398 | 0 | FREE_AND_NULL(msg) |
2399 | 0 | } |
2400 | | |
2401 | | |
2402 | | |
2403 | | static void LIBXML_ATTR_FORMAT(5,0) |
2404 | | xmlSchemaKeyrefErr(xmlSchemaValidCtxtPtr vctxt, |
2405 | | xmlParserErrors error, |
2406 | | xmlSchemaPSVIIDCNodePtr idcNode, |
2407 | | xmlSchemaTypePtr type ATTRIBUTE_UNUSED, |
2408 | | const char *message, |
2409 | | const xmlChar *str1, |
2410 | | const xmlChar *str2) |
2411 | 0 | { |
2412 | 0 | xmlChar *msg = NULL, *qname = NULL; |
2413 | |
|
2414 | 0 | msg = xmlStrdup(BAD_CAST "Element '%s': "); |
2415 | 0 | msg = xmlStrcat(msg, (const xmlChar *) message); |
2416 | 0 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
2417 | 0 | xmlSchemaErr4Line(ACTXT_CAST vctxt, XML_ERR_ERROR, |
2418 | 0 | error, NULL, idcNode->nodeLine, (const char *) msg, |
2419 | 0 | xmlSchemaFormatQName(&qname, |
2420 | 0 | vctxt->nodeQNames->items[idcNode->nodeQNameID +1], |
2421 | 0 | vctxt->nodeQNames->items[idcNode->nodeQNameID]), |
2422 | 0 | str1, str2, NULL); |
2423 | 0 | FREE_AND_NULL(qname); |
2424 | 0 | FREE_AND_NULL(msg); |
2425 | 0 | } |
2426 | | |
2427 | | static int |
2428 | | xmlSchemaEvalErrorNodeType(xmlSchemaAbstractCtxtPtr actxt, |
2429 | | xmlNodePtr node) |
2430 | 0 | { |
2431 | 0 | if (node != NULL) |
2432 | 0 | return (node->type); |
2433 | 0 | if ((actxt->type == XML_SCHEMA_CTXT_VALIDATOR) && |
2434 | 0 | (((xmlSchemaValidCtxtPtr) actxt)->inode != NULL)) |
2435 | 0 | return ( ((xmlSchemaValidCtxtPtr) actxt)->inode->nodeType); |
2436 | 0 | return (-1); |
2437 | 0 | } |
2438 | | |
2439 | | static int |
2440 | | xmlSchemaIsGlobalItem(xmlSchemaTypePtr item) |
2441 | 0 | { |
2442 | 0 | switch (item->type) { |
2443 | 0 | case XML_SCHEMA_TYPE_COMPLEX: |
2444 | 0 | case XML_SCHEMA_TYPE_SIMPLE: |
2445 | 0 | if (item->flags & XML_SCHEMAS_TYPE_GLOBAL) |
2446 | 0 | return(1); |
2447 | 0 | break; |
2448 | 0 | case XML_SCHEMA_TYPE_GROUP: |
2449 | 0 | return (1); |
2450 | 0 | case XML_SCHEMA_TYPE_ELEMENT: |
2451 | 0 | if ( ((xmlSchemaElementPtr) item)->flags & |
2452 | 0 | XML_SCHEMAS_ELEM_GLOBAL) |
2453 | 0 | return(1); |
2454 | 0 | break; |
2455 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTE: |
2456 | 0 | if ( ((xmlSchemaAttributePtr) item)->flags & |
2457 | 0 | XML_SCHEMAS_ATTR_GLOBAL) |
2458 | 0 | return(1); |
2459 | 0 | break; |
2460 | | /* Note that attribute groups are always global. */ |
2461 | 0 | default: |
2462 | 0 | return(1); |
2463 | 0 | } |
2464 | 0 | return (0); |
2465 | 0 | } |
2466 | | |
2467 | | static void |
2468 | | xmlSchemaSimpleTypeErr(xmlSchemaAbstractCtxtPtr actxt, |
2469 | | xmlParserErrors error, |
2470 | | xmlNodePtr node, |
2471 | | const xmlChar *value, |
2472 | | xmlSchemaTypePtr type, |
2473 | | int displayValue) |
2474 | 0 | { |
2475 | 0 | xmlChar *msg = NULL; |
2476 | |
|
2477 | 0 | xmlSchemaFormatNodeForError(&msg, actxt, node); |
2478 | |
|
2479 | 0 | if (displayValue || (xmlSchemaEvalErrorNodeType(actxt, node) == |
2480 | 0 | XML_ATTRIBUTE_NODE)) |
2481 | 0 | msg = xmlStrcat(msg, BAD_CAST "'%s' is not a valid value of "); |
2482 | 0 | else |
2483 | 0 | msg = xmlStrcat(msg, BAD_CAST "The character content is not a valid " |
2484 | 0 | "value of "); |
2485 | |
|
2486 | 0 | if (! xmlSchemaIsGlobalItem(type)) |
2487 | 0 | msg = xmlStrcat(msg, BAD_CAST "the local "); |
2488 | 0 | else |
2489 | 0 | msg = xmlStrcat(msg, BAD_CAST "the "); |
2490 | |
|
2491 | 0 | if (WXS_IS_ATOMIC(type)) |
2492 | 0 | msg = xmlStrcat(msg, BAD_CAST "atomic type"); |
2493 | 0 | else if (WXS_IS_LIST(type)) |
2494 | 0 | msg = xmlStrcat(msg, BAD_CAST "list type"); |
2495 | 0 | else if (WXS_IS_UNION(type)) |
2496 | 0 | msg = xmlStrcat(msg, BAD_CAST "union type"); |
2497 | |
|
2498 | 0 | if (xmlSchemaIsGlobalItem(type)) { |
2499 | 0 | xmlChar *str = NULL; |
2500 | 0 | msg = xmlStrcat(msg, BAD_CAST " '"); |
2501 | 0 | if (type->builtInType != 0) { |
2502 | 0 | msg = xmlStrcat(msg, BAD_CAST "xs:"); |
2503 | 0 | str = xmlStrdup(type->name); |
2504 | 0 | } else { |
2505 | 0 | const xmlChar *qName = xmlSchemaFormatQName(&str, type->targetNamespace, type->name); |
2506 | 0 | if (!str) |
2507 | 0 | str = xmlStrdup(qName); |
2508 | 0 | } |
2509 | 0 | msg = xmlStrcat(msg, xmlEscapeFormatString(&str)); |
2510 | 0 | msg = xmlStrcat(msg, BAD_CAST "'"); |
2511 | 0 | FREE_AND_NULL(str); |
2512 | 0 | } |
2513 | 0 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
2514 | 0 | if (displayValue || (xmlSchemaEvalErrorNodeType(actxt, node) == |
2515 | 0 | XML_ATTRIBUTE_NODE)) |
2516 | 0 | xmlSchemaErr(actxt, error, node, (const char *) msg, value, NULL); |
2517 | 0 | else |
2518 | 0 | xmlSchemaErr(actxt, error, node, (const char *) msg, NULL, NULL); |
2519 | 0 | FREE_AND_NULL(msg) |
2520 | 0 | } |
2521 | | |
2522 | | static const xmlChar * |
2523 | | xmlSchemaFormatErrorNodeQName(xmlChar ** str, |
2524 | | xmlSchemaNodeInfoPtr ni, |
2525 | | xmlNodePtr node) |
2526 | 0 | { |
2527 | 0 | if (node != NULL) { |
2528 | 0 | if (node->ns != NULL) |
2529 | 0 | return (xmlSchemaFormatQName(str, node->ns->href, node->name)); |
2530 | 0 | else |
2531 | 0 | return (xmlSchemaFormatQName(str, NULL, node->name)); |
2532 | 0 | } else if (ni != NULL) |
2533 | 0 | return (xmlSchemaFormatQName(str, ni->nsName, ni->localName)); |
2534 | 0 | return (NULL); |
2535 | 0 | } |
2536 | | |
2537 | | static void |
2538 | | xmlSchemaIllegalAttrErr(xmlSchemaAbstractCtxtPtr actxt, |
2539 | | xmlParserErrors error, |
2540 | | xmlSchemaAttrInfoPtr ni, |
2541 | | xmlNodePtr node) |
2542 | 0 | { |
2543 | 0 | xmlChar *msg = NULL, *str = NULL; |
2544 | |
|
2545 | 0 | xmlSchemaFormatNodeForError(&msg, actxt, node); |
2546 | 0 | msg = xmlStrcat(msg, BAD_CAST "The attribute '%s' is not allowed.\n"); |
2547 | 0 | xmlSchemaErr(actxt, error, node, (const char *) msg, |
2548 | 0 | xmlSchemaFormatErrorNodeQName(&str, (xmlSchemaNodeInfoPtr) ni, node), |
2549 | 0 | NULL); |
2550 | 0 | FREE_AND_NULL(str) |
2551 | 0 | FREE_AND_NULL(msg) |
2552 | 0 | } |
2553 | | |
2554 | | static void LIBXML_ATTR_FORMAT(5,0) |
2555 | | xmlSchemaComplexTypeErr(xmlSchemaAbstractCtxtPtr actxt, |
2556 | | xmlParserErrors error, |
2557 | | xmlNodePtr node, |
2558 | | xmlSchemaTypePtr type ATTRIBUTE_UNUSED, |
2559 | | const char *message, |
2560 | | int nbval, |
2561 | | int nbneg, |
2562 | | xmlChar **values) |
2563 | 0 | { |
2564 | 0 | xmlChar *str = NULL, *msg = NULL; |
2565 | 0 | xmlChar *localName, *nsName; |
2566 | 0 | const xmlChar *cur, *end; |
2567 | 0 | int i; |
2568 | |
|
2569 | 0 | xmlSchemaFormatNodeForError(&msg, actxt, node); |
2570 | 0 | msg = xmlStrcat(msg, (const xmlChar *) message); |
2571 | 0 | msg = xmlStrcat(msg, BAD_CAST "."); |
2572 | | /* |
2573 | | * Note that is does not make sense to report that we have a |
2574 | | * wildcard here, since the wildcard might be unfolded into |
2575 | | * multiple transitions. |
2576 | | */ |
2577 | 0 | if (nbval + nbneg > 0) { |
2578 | 0 | if (nbval + nbneg > 1) { |
2579 | 0 | str = xmlStrdup(BAD_CAST " Expected is one of ( "); |
2580 | 0 | } else |
2581 | 0 | str = xmlStrdup(BAD_CAST " Expected is ( "); |
2582 | 0 | nsName = NULL; |
2583 | |
|
2584 | 0 | for (i = 0; i < nbval + nbneg; i++) { |
2585 | 0 | cur = values[i]; |
2586 | 0 | if (cur == NULL) |
2587 | 0 | continue; |
2588 | 0 | if ((cur[0] == 'n') && (cur[1] == 'o') && (cur[2] == 't') && |
2589 | 0 | (cur[3] == ' ')) { |
2590 | 0 | cur += 4; |
2591 | 0 | str = xmlStrcat(str, BAD_CAST "##other"); |
2592 | 0 | } |
2593 | | /* |
2594 | | * Get the local name. |
2595 | | */ |
2596 | 0 | localName = NULL; |
2597 | |
|
2598 | 0 | end = cur; |
2599 | 0 | if (*end == '*') { |
2600 | 0 | localName = xmlStrdup(BAD_CAST "*"); |
2601 | 0 | end++; |
2602 | 0 | } else { |
2603 | 0 | while ((*end != 0) && (*end != '|')) |
2604 | 0 | end++; |
2605 | 0 | localName = xmlStrncat(localName, BAD_CAST cur, end - cur); |
2606 | 0 | } |
2607 | 0 | if (*end != 0) { |
2608 | 0 | end++; |
2609 | | /* |
2610 | | * Skip "*|*" if they come with negated expressions, since |
2611 | | * they represent the same negated wildcard. |
2612 | | */ |
2613 | 0 | if ((nbneg == 0) || (*end != '*') || (*localName != '*')) { |
2614 | | /* |
2615 | | * Get the namespace name. |
2616 | | */ |
2617 | 0 | cur = end; |
2618 | 0 | if (*end == '*') { |
2619 | 0 | nsName = xmlStrdup(BAD_CAST "{*}"); |
2620 | 0 | } else { |
2621 | 0 | while (*end != 0) |
2622 | 0 | end++; |
2623 | |
|
2624 | 0 | if (i >= nbval) |
2625 | 0 | nsName = xmlStrdup(BAD_CAST "{##other:"); |
2626 | 0 | else |
2627 | 0 | nsName = xmlStrdup(BAD_CAST "{"); |
2628 | |
|
2629 | 0 | nsName = xmlStrncat(nsName, BAD_CAST cur, end - cur); |
2630 | 0 | nsName = xmlStrcat(nsName, BAD_CAST "}"); |
2631 | 0 | } |
2632 | 0 | str = xmlStrcat(str, BAD_CAST nsName); |
2633 | 0 | FREE_AND_NULL(nsName) |
2634 | 0 | } else { |
2635 | 0 | FREE_AND_NULL(localName); |
2636 | 0 | continue; |
2637 | 0 | } |
2638 | 0 | } |
2639 | 0 | str = xmlStrcat(str, BAD_CAST localName); |
2640 | 0 | FREE_AND_NULL(localName); |
2641 | |
|
2642 | 0 | if (i < nbval + nbneg -1) |
2643 | 0 | str = xmlStrcat(str, BAD_CAST ", "); |
2644 | 0 | } |
2645 | 0 | str = xmlStrcat(str, BAD_CAST " ).\n"); |
2646 | 0 | msg = xmlStrcat(msg, xmlEscapeFormatString(&str)); |
2647 | 0 | FREE_AND_NULL(str) |
2648 | 0 | } else |
2649 | 0 | msg = xmlStrcat(msg, BAD_CAST "\n"); |
2650 | 0 | xmlSchemaErr(actxt, error, node, (const char *) msg, NULL, NULL); |
2651 | 0 | xmlFree(msg); |
2652 | 0 | } |
2653 | | |
2654 | | static void LIBXML_ATTR_FORMAT(8,0) |
2655 | | xmlSchemaFacetErr(xmlSchemaAbstractCtxtPtr actxt, |
2656 | | xmlParserErrors error, |
2657 | | xmlNodePtr node, |
2658 | | const xmlChar *value, |
2659 | | unsigned long length, |
2660 | | xmlSchemaTypePtr type, |
2661 | | xmlSchemaFacetPtr facet, |
2662 | | const char *message, |
2663 | | const xmlChar *str1, |
2664 | | const xmlChar *str2) |
2665 | 0 | { |
2666 | 0 | xmlChar *str = NULL, *msg = NULL; |
2667 | 0 | xmlSchemaTypeType facetType; |
2668 | 0 | int nodeType = xmlSchemaEvalErrorNodeType(actxt, node); |
2669 | |
|
2670 | 0 | xmlSchemaFormatNodeForError(&msg, actxt, node); |
2671 | 0 | if (error == XML_SCHEMAV_CVC_ENUMERATION_VALID) { |
2672 | 0 | facetType = XML_SCHEMA_FACET_ENUMERATION; |
2673 | | /* |
2674 | | * If enumerations are validated, one must not expect the |
2675 | | * facet to be given. |
2676 | | */ |
2677 | 0 | } else |
2678 | 0 | facetType = facet->type; |
2679 | 0 | msg = xmlStrcat(msg, BAD_CAST "["); |
2680 | 0 | msg = xmlStrcat(msg, BAD_CAST "facet '"); |
2681 | 0 | msg = xmlStrcat(msg, xmlSchemaFacetTypeToString(facetType)); |
2682 | 0 | msg = xmlStrcat(msg, BAD_CAST "'] "); |
2683 | 0 | if (message == NULL) { |
2684 | | /* |
2685 | | * Use a default message. |
2686 | | */ |
2687 | 0 | if ((facetType == XML_SCHEMA_FACET_LENGTH) || |
2688 | 0 | (facetType == XML_SCHEMA_FACET_MINLENGTH) || |
2689 | 0 | (facetType == XML_SCHEMA_FACET_MAXLENGTH)) { |
2690 | |
|
2691 | 0 | char len[25], actLen[25]; |
2692 | | |
2693 | | /* FIXME, TODO: What is the max expected string length of the |
2694 | | * this value? |
2695 | | */ |
2696 | 0 | if (nodeType == XML_ATTRIBUTE_NODE) |
2697 | 0 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' has a length of '%s'; "); |
2698 | 0 | else |
2699 | 0 | msg = xmlStrcat(msg, BAD_CAST "The value has a length of '%s'; "); |
2700 | |
|
2701 | 0 | snprintf(len, 24, "%lu", xmlSchemaGetFacetValueAsULong(facet)); |
2702 | 0 | snprintf(actLen, 24, "%lu", length); |
2703 | |
|
2704 | 0 | if (facetType == XML_SCHEMA_FACET_LENGTH) |
2705 | 0 | msg = xmlStrcat(msg, |
2706 | 0 | BAD_CAST "this differs from the allowed length of '%s'.\n"); |
2707 | 0 | else if (facetType == XML_SCHEMA_FACET_MAXLENGTH) |
2708 | 0 | msg = xmlStrcat(msg, |
2709 | 0 | BAD_CAST "this exceeds the allowed maximum length of '%s'.\n"); |
2710 | 0 | else if (facetType == XML_SCHEMA_FACET_MINLENGTH) |
2711 | 0 | msg = xmlStrcat(msg, |
2712 | 0 | BAD_CAST "this underruns the allowed minimum length of '%s'.\n"); |
2713 | |
|
2714 | 0 | if (nodeType == XML_ATTRIBUTE_NODE) |
2715 | 0 | xmlSchemaErr3(actxt, error, node, (const char *) msg, |
2716 | 0 | value, (const xmlChar *) actLen, (const xmlChar *) len); |
2717 | 0 | else |
2718 | 0 | xmlSchemaErr(actxt, error, node, (const char *) msg, |
2719 | 0 | (const xmlChar *) actLen, (const xmlChar *) len); |
2720 | |
|
2721 | 0 | } else if (facetType == XML_SCHEMA_FACET_ENUMERATION) { |
2722 | 0 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not an element " |
2723 | 0 | "of the set {%s}.\n"); |
2724 | 0 | xmlSchemaErr(actxt, error, node, (const char *) msg, value, |
2725 | 0 | xmlSchemaFormatFacetEnumSet(actxt, &str, type)); |
2726 | 0 | } else if (facetType == XML_SCHEMA_FACET_PATTERN) { |
2727 | 0 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not accepted " |
2728 | 0 | "by the pattern '%s'.\n"); |
2729 | 0 | xmlSchemaErr(actxt, error, node, (const char *) msg, value, |
2730 | 0 | facet->value); |
2731 | 0 | } else if (facetType == XML_SCHEMA_FACET_MININCLUSIVE) { |
2732 | 0 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' is less than the " |
2733 | 0 | "minimum value allowed ('%s').\n"); |
2734 | 0 | xmlSchemaErr(actxt, error, node, (const char *) msg, value, |
2735 | 0 | facet->value); |
2736 | 0 | } else if (facetType == XML_SCHEMA_FACET_MAXINCLUSIVE) { |
2737 | 0 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' is greater than the " |
2738 | 0 | "maximum value allowed ('%s').\n"); |
2739 | 0 | xmlSchemaErr(actxt, error, node, (const char *) msg, value, |
2740 | 0 | facet->value); |
2741 | 0 | } else if (facetType == XML_SCHEMA_FACET_MINEXCLUSIVE) { |
2742 | 0 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' must be greater than " |
2743 | 0 | "'%s'.\n"); |
2744 | 0 | xmlSchemaErr(actxt, error, node, (const char *) msg, value, |
2745 | 0 | facet->value); |
2746 | 0 | } else if (facetType == XML_SCHEMA_FACET_MAXEXCLUSIVE) { |
2747 | 0 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' must be less than " |
2748 | 0 | "'%s'.\n"); |
2749 | 0 | xmlSchemaErr(actxt, error, node, (const char *) msg, value, |
2750 | 0 | facet->value); |
2751 | 0 | } else if (facetType == XML_SCHEMA_FACET_TOTALDIGITS) { |
2752 | 0 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' has more " |
2753 | 0 | "digits than are allowed ('%s').\n"); |
2754 | 0 | xmlSchemaErr(actxt, error, node, (const char*) msg, value, |
2755 | 0 | facet->value); |
2756 | 0 | } else if (facetType == XML_SCHEMA_FACET_FRACTIONDIGITS) { |
2757 | 0 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' has more fractional " |
2758 | 0 | "digits than are allowed ('%s').\n"); |
2759 | 0 | xmlSchemaErr(actxt, error, node, (const char*) msg, value, |
2760 | 0 | facet->value); |
2761 | 0 | } else if (nodeType == XML_ATTRIBUTE_NODE) { |
2762 | 0 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not facet-valid.\n"); |
2763 | 0 | xmlSchemaErr(actxt, error, node, (const char *) msg, value, NULL); |
2764 | 0 | } else { |
2765 | 0 | msg = xmlStrcat(msg, BAD_CAST "The value is not facet-valid.\n"); |
2766 | 0 | xmlSchemaErr(actxt, error, node, (const char *) msg, NULL, NULL); |
2767 | 0 | } |
2768 | 0 | } else { |
2769 | 0 | msg = xmlStrcat(msg, (const xmlChar *) message); |
2770 | 0 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
2771 | 0 | xmlSchemaErr(actxt, error, node, (const char *) msg, str1, str2); |
2772 | 0 | } |
2773 | 0 | FREE_AND_NULL(str) |
2774 | 0 | xmlFree(msg); |
2775 | 0 | } |
2776 | | |
2777 | | #define VERROR(err, type, msg) \ |
2778 | 0 | xmlSchemaCustomErr(ACTXT_CAST vctxt, err, NULL, type, msg, NULL, NULL); |
2779 | | |
2780 | 0 | #define VERROR_INT(func, msg) xmlSchemaInternalErr(ACTXT_CAST vctxt, func, msg); |
2781 | | |
2782 | 0 | #define PERROR_INT(func, msg) xmlSchemaInternalErr(ACTXT_CAST pctxt, func, msg); |
2783 | 0 | #define PERROR_INT2(func, msg) xmlSchemaInternalErr(ACTXT_CAST ctxt, func, msg); |
2784 | | |
2785 | 0 | #define AERROR_INT(func, msg) xmlSchemaInternalErr(actxt, func, msg); |
2786 | | |
2787 | | |
2788 | | /** |
2789 | | * Reports an illegal attribute. |
2790 | | * |
2791 | | * @param ctxt the schema validation context |
2792 | | * @param error the error code |
2793 | | * @param ownerItem the owner as a schema object |
2794 | | * @param ownerElem the owner as an element node |
2795 | | * @param name name of the attribute |
2796 | | * @param message the error message |
2797 | | */ |
2798 | | static void |
2799 | | xmlSchemaPMissingAttrErr(xmlSchemaParserCtxtPtr ctxt, |
2800 | | xmlParserErrors error, |
2801 | | xmlSchemaBasicItemPtr ownerItem, |
2802 | | xmlNodePtr ownerElem, |
2803 | | const char *name, |
2804 | | const char *message) |
2805 | 0 | { |
2806 | 0 | xmlChar *des = NULL; |
2807 | |
|
2808 | 0 | xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem); |
2809 | |
|
2810 | 0 | if (message != NULL) |
2811 | 0 | xmlSchemaPErr(ctxt, ownerElem, error, "%s: %s.\n", BAD_CAST des, BAD_CAST message); |
2812 | 0 | else |
2813 | 0 | xmlSchemaPErr(ctxt, ownerElem, error, |
2814 | 0 | "%s: The attribute '%s' is required but missing.\n", |
2815 | 0 | BAD_CAST des, BAD_CAST name); |
2816 | 0 | FREE_AND_NULL(des); |
2817 | 0 | } |
2818 | | |
2819 | | |
2820 | | /** |
2821 | | * Used to report QName attribute values that failed to resolve |
2822 | | * to schema components. |
2823 | | * |
2824 | | * @param ctxt the schema validation context |
2825 | | * @param error the error code |
2826 | | * @param ownerItem the owner as a schema object |
2827 | | * @param ownerElem the owner as an element node |
2828 | | * @param name the name of the attribute holding the QName |
2829 | | * @param refName the referenced local name |
2830 | | * @param refURI the referenced namespace URI |
2831 | | * @param refType the referenced type |
2832 | | * @param refTypeStr the referenced type string |
2833 | | */ |
2834 | | static void |
2835 | | xmlSchemaPResCompAttrErr(xmlSchemaParserCtxtPtr ctxt, |
2836 | | xmlParserErrors error, |
2837 | | xmlSchemaBasicItemPtr ownerItem, |
2838 | | xmlNodePtr ownerElem, |
2839 | | const char *name, |
2840 | | const xmlChar *refName, |
2841 | | const xmlChar *refURI, |
2842 | | xmlSchemaTypeType refType, |
2843 | | const char *refTypeStr) |
2844 | 0 | { |
2845 | 0 | xmlChar *des = NULL, *strA = NULL; |
2846 | |
|
2847 | 0 | xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem); |
2848 | 0 | if (refTypeStr == NULL) |
2849 | 0 | refTypeStr = (const char *) xmlSchemaItemTypeToStr(refType); |
2850 | 0 | xmlSchemaPErrExt(ctxt, ownerElem, error, |
2851 | 0 | NULL, NULL, NULL, |
2852 | 0 | "%s, attribute '%s': The QName value '%s' does not resolve to a(n) " |
2853 | 0 | "%s.\n", BAD_CAST des, BAD_CAST name, |
2854 | 0 | xmlSchemaFormatQName(&strA, refURI, refName), |
2855 | 0 | BAD_CAST refTypeStr, NULL); |
2856 | 0 | FREE_AND_NULL(des) |
2857 | 0 | FREE_AND_NULL(strA) |
2858 | 0 | } |
2859 | | |
2860 | | /** |
2861 | | * Reports an illegal attribute during the parse. |
2862 | | * |
2863 | | * @param ctxt the schema parser context |
2864 | | * @param error the error code |
2865 | | * @param ownerDes the designation of the owner |
2866 | | * @param ownerItem the owner as a schema object |
2867 | | * @param attr the illegal attribute node |
2868 | | * @param msg the error message |
2869 | | */ |
2870 | | static void |
2871 | | xmlSchemaPCustomAttrErr(xmlSchemaParserCtxtPtr ctxt, |
2872 | | xmlParserErrors error, |
2873 | | xmlChar **ownerDes, |
2874 | | xmlSchemaBasicItemPtr ownerItem, |
2875 | | xmlAttrPtr attr, |
2876 | | const char *msg) |
2877 | 0 | { |
2878 | 0 | xmlChar *des = NULL; |
2879 | |
|
2880 | 0 | if (ownerDes == NULL) |
2881 | 0 | xmlSchemaFormatItemForReport(&des, NULL, ownerItem, attr->parent); |
2882 | 0 | else if (*ownerDes == NULL) { |
2883 | 0 | xmlSchemaFormatItemForReport(ownerDes, NULL, ownerItem, attr->parent); |
2884 | 0 | des = *ownerDes; |
2885 | 0 | } else |
2886 | 0 | des = *ownerDes; |
2887 | 0 | if (attr == NULL) { |
2888 | 0 | xmlSchemaPErrExt(ctxt, NULL, error, NULL, NULL, NULL, |
2889 | 0 | "%s, attribute '%s': %s.\n", |
2890 | 0 | BAD_CAST des, (const xmlChar *) "Unknown", |
2891 | 0 | (const xmlChar *) msg, NULL, NULL); |
2892 | 0 | } else { |
2893 | 0 | xmlSchemaPErrExt(ctxt, (xmlNodePtr) attr, error, NULL, NULL, NULL, |
2894 | 0 | "%s, attribute '%s': %s.\n", |
2895 | 0 | BAD_CAST des, attr->name, (const xmlChar *) msg, NULL, NULL); |
2896 | 0 | } |
2897 | 0 | if (ownerDes == NULL) |
2898 | 0 | FREE_AND_NULL(des); |
2899 | 0 | } |
2900 | | |
2901 | | /** |
2902 | | * Reports an illegal attribute during the parse. |
2903 | | * |
2904 | | * @param ctxt the schema parser context |
2905 | | * @param error the error code |
2906 | | * @param ownerComp the attribute's owner item (unused) |
2907 | | * @param attr the illegal attribute node |
2908 | | */ |
2909 | | static void |
2910 | | xmlSchemaPIllegalAttrErr(xmlSchemaParserCtxtPtr ctxt, |
2911 | | xmlParserErrors error, |
2912 | | xmlSchemaBasicItemPtr ownerComp ATTRIBUTE_UNUSED, |
2913 | | xmlAttrPtr attr) |
2914 | 0 | { |
2915 | 0 | xmlChar *strA = NULL, *strB = NULL; |
2916 | |
|
2917 | 0 | xmlSchemaFormatNodeForError(&strA, ACTXT_CAST ctxt, attr->parent); |
2918 | 0 | xmlSchemaErr4(ACTXT_CAST ctxt, error, (xmlNodePtr) attr, |
2919 | 0 | "%sThe attribute '%s' is not allowed.\n", BAD_CAST strA, |
2920 | 0 | xmlSchemaFormatQNameNs(&strB, attr->ns, attr->name), |
2921 | 0 | NULL, NULL); |
2922 | 0 | FREE_AND_NULL(strA); |
2923 | 0 | FREE_AND_NULL(strB); |
2924 | 0 | } |
2925 | | |
2926 | | /** |
2927 | | * Reports an error during parsing. |
2928 | | * |
2929 | | * @param ctxt the schema parser context |
2930 | | * @param error the error code |
2931 | | * @param item the schema item |
2932 | | * @param itemElem the node of the schema item |
2933 | | * @param message the error message |
2934 | | * @param str1 an optional param for the error message |
2935 | | * @param str2 an optional param for the error message |
2936 | | * @param str3 an optional param for the error message |
2937 | | */ |
2938 | | static void LIBXML_ATTR_FORMAT(5,0) |
2939 | | xmlSchemaPCustomErrExt(xmlSchemaParserCtxtPtr ctxt, |
2940 | | xmlParserErrors error, |
2941 | | xmlSchemaBasicItemPtr item, |
2942 | | xmlNodePtr itemElem, |
2943 | | const char *message, |
2944 | | const xmlChar *str1, |
2945 | | const xmlChar *str2, |
2946 | | const xmlChar *str3) |
2947 | 0 | { |
2948 | 0 | xmlChar *des = NULL, *msg = NULL; |
2949 | |
|
2950 | 0 | xmlSchemaFormatItemForReport(&des, NULL, item, itemElem); |
2951 | 0 | msg = xmlStrdup(BAD_CAST "%s: "); |
2952 | 0 | msg = xmlStrcat(msg, (const xmlChar *) message); |
2953 | 0 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
2954 | 0 | if ((itemElem == NULL) && (item != NULL)) |
2955 | 0 | itemElem = WXS_ITEM_NODE(item); |
2956 | 0 | xmlSchemaPErrExt(ctxt, itemElem, error, NULL, NULL, NULL, |
2957 | 0 | (const char *) msg, BAD_CAST des, str1, str2, str3, NULL); |
2958 | 0 | FREE_AND_NULL(des); |
2959 | 0 | FREE_AND_NULL(msg); |
2960 | 0 | } |
2961 | | |
2962 | | /** |
2963 | | * Reports an error during parsing. |
2964 | | * |
2965 | | * @param ctxt the schema parser context |
2966 | | * @param error the error code |
2967 | | * @param item the schema item |
2968 | | * @param itemElem the node of the schema item |
2969 | | * @param message the error message |
2970 | | * @param str1 the optional param for the error message |
2971 | | */ |
2972 | | static void LIBXML_ATTR_FORMAT(5,0) |
2973 | | xmlSchemaPCustomErr(xmlSchemaParserCtxtPtr ctxt, |
2974 | | xmlParserErrors error, |
2975 | | xmlSchemaBasicItemPtr item, |
2976 | | xmlNodePtr itemElem, |
2977 | | const char *message, |
2978 | | const xmlChar *str1) |
2979 | 0 | { |
2980 | 0 | xmlSchemaPCustomErrExt(ctxt, error, item, itemElem, message, |
2981 | 0 | str1, NULL, NULL); |
2982 | 0 | } |
2983 | | |
2984 | | /** |
2985 | | * Reports an attribute use error during parsing. |
2986 | | * |
2987 | | * @param ctxt the schema parser context |
2988 | | * @param error the error code |
2989 | | * @param node the context node |
2990 | | * @param ownerItem the owner as a schema object |
2991 | | * @param attruse the invalid schema attribute |
2992 | | * @param message the error message |
2993 | | * @param str1 the optional param for the error message |
2994 | | * @param str2 the optional param for the error message |
2995 | | * @param str3 the optional param for the error message |
2996 | | * @param str4 the optional param for the error message |
2997 | | */ |
2998 | | static void LIBXML_ATTR_FORMAT(6,0) |
2999 | | xmlSchemaPAttrUseErr4(xmlSchemaParserCtxtPtr ctxt, |
3000 | | xmlParserErrors error, |
3001 | | xmlNodePtr node, |
3002 | | xmlSchemaBasicItemPtr ownerItem, |
3003 | | const xmlSchemaAttributeUsePtr attruse, |
3004 | | const char *message, |
3005 | | const xmlChar *str1, const xmlChar *str2, |
3006 | | const xmlChar *str3,const xmlChar *str4) |
3007 | 0 | { |
3008 | 0 | xmlChar *str = NULL, *msg = NULL; |
3009 | |
|
3010 | 0 | xmlSchemaFormatItemForReport(&msg, NULL, ownerItem, NULL); |
3011 | 0 | msg = xmlStrcat(msg, BAD_CAST ", "); |
3012 | 0 | msg = xmlStrcat(msg, |
3013 | 0 | BAD_CAST xmlSchemaFormatItemForReport(&str, NULL, |
3014 | 0 | WXS_BASIC_CAST attruse, NULL)); |
3015 | 0 | FREE_AND_NULL(str); |
3016 | 0 | msg = xmlStrcat(msg, BAD_CAST ": "); |
3017 | 0 | msg = xmlStrcat(msg, (const xmlChar *) message); |
3018 | 0 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
3019 | 0 | xmlSchemaErr4(ACTXT_CAST ctxt, error, node, |
3020 | 0 | (const char *) msg, str1, str2, str3, str4); |
3021 | 0 | xmlFree(msg); |
3022 | 0 | } |
3023 | | |
3024 | | /** |
3025 | | * Reports an illegal facet for atomic simple types. |
3026 | | * |
3027 | | * @param ctxt the schema parser context |
3028 | | * @param error the error code |
3029 | | * @param type the schema type |
3030 | | * @param baseType the base type of type |
3031 | | * @param facet the illegal facet |
3032 | | */ |
3033 | | static void |
3034 | | xmlSchemaPIllegalFacetAtomicErr(xmlSchemaParserCtxtPtr ctxt, |
3035 | | xmlParserErrors error, |
3036 | | xmlSchemaTypePtr type, |
3037 | | xmlSchemaTypePtr baseType, |
3038 | | xmlSchemaFacetPtr facet) |
3039 | 0 | { |
3040 | 0 | xmlChar *des = NULL, *strT = NULL; |
3041 | |
|
3042 | 0 | xmlSchemaFormatItemForReport(&des, NULL, WXS_BASIC_CAST type, type->node); |
3043 | 0 | xmlSchemaPErrExt(ctxt, type->node, error, NULL, NULL, NULL, |
3044 | 0 | "%s: The facet '%s' is not allowed on types derived from the " |
3045 | 0 | "type %s.\n", |
3046 | 0 | BAD_CAST des, xmlSchemaFacetTypeToString(facet->type), |
3047 | 0 | xmlSchemaFormatItemForReport(&strT, NULL, WXS_BASIC_CAST baseType, NULL), |
3048 | 0 | NULL, NULL); |
3049 | 0 | FREE_AND_NULL(des); |
3050 | 0 | FREE_AND_NULL(strT); |
3051 | 0 | } |
3052 | | |
3053 | | /** |
3054 | | * Reports an illegal facet for `<list>` and `<union>`. |
3055 | | * |
3056 | | * @param ctxt the schema parser context |
3057 | | * @param error the error code |
3058 | | * @param type the schema type |
3059 | | * @param facet the illegal facet |
3060 | | */ |
3061 | | static void |
3062 | | xmlSchemaPIllegalFacetListUnionErr(xmlSchemaParserCtxtPtr ctxt, |
3063 | | xmlParserErrors error, |
3064 | | xmlSchemaTypePtr type, |
3065 | | xmlSchemaFacetPtr facet) |
3066 | 0 | { |
3067 | 0 | xmlChar *des = NULL; |
3068 | |
|
3069 | 0 | xmlSchemaFormatItemForReport(&des, NULL, WXS_BASIC_CAST type, |
3070 | 0 | type->node); |
3071 | 0 | xmlSchemaPErr(ctxt, type->node, error, |
3072 | 0 | "%s: The facet '%s' is not allowed.\n", |
3073 | 0 | BAD_CAST des, xmlSchemaFacetTypeToString(facet->type)); |
3074 | 0 | FREE_AND_NULL(des); |
3075 | 0 | } |
3076 | | |
3077 | | /** |
3078 | | * Reports an illegal attribute. |
3079 | | * |
3080 | | * @param ctxt the schema validation context |
3081 | | * @param error the error code |
3082 | | * @param ownerItem the owner as a schema object |
3083 | | * @param attr the bad attribute node |
3084 | | * @param name1 first mutually exclusive name |
3085 | | * @param name2 second mutually exclusive name |
3086 | | */ |
3087 | | static void |
3088 | | xmlSchemaPMutualExclAttrErr(xmlSchemaParserCtxtPtr ctxt, |
3089 | | xmlParserErrors error, |
3090 | | xmlSchemaBasicItemPtr ownerItem, |
3091 | | xmlAttrPtr attr, |
3092 | | const char *name1, |
3093 | | const char *name2) |
3094 | 0 | { |
3095 | 0 | xmlChar *des = NULL; |
3096 | |
|
3097 | 0 | xmlSchemaFormatItemForReport(&des, NULL, WXS_BASIC_CAST ownerItem, attr->parent); |
3098 | 0 | xmlSchemaPErrExt(ctxt, (xmlNodePtr) attr, error, NULL, NULL, NULL, |
3099 | 0 | "%s: The attributes '%s' and '%s' are mutually exclusive.\n", |
3100 | 0 | BAD_CAST des, BAD_CAST name1, BAD_CAST name2, NULL, NULL); |
3101 | 0 | FREE_AND_NULL(des); |
3102 | 0 | } |
3103 | | |
3104 | | /** |
3105 | | * Reports a simple type validation error. |
3106 | | * TODO: Should this report the value of an element as well? |
3107 | | * |
3108 | | * @param ctxt the schema validation context |
3109 | | * @param error the error code |
3110 | | * @param ownerItem the schema object if existent |
3111 | | * @param node the validated node |
3112 | | * @param type the type specifier |
3113 | | * @param expected the expected value |
3114 | | * @param value the validated value |
3115 | | * @param message error message |
3116 | | * @param str1 extra data |
3117 | | * @param str2 extra data |
3118 | | */ |
3119 | | static void LIBXML_ATTR_FORMAT(8,0) |
3120 | | xmlSchemaPSimpleTypeErr(xmlSchemaParserCtxtPtr ctxt, |
3121 | | xmlParserErrors error, |
3122 | | xmlSchemaBasicItemPtr ownerItem ATTRIBUTE_UNUSED, |
3123 | | xmlNodePtr node, |
3124 | | xmlSchemaTypePtr type, |
3125 | | const char *expected, |
3126 | | const xmlChar *value, |
3127 | | const char *message, |
3128 | | const xmlChar *str1, |
3129 | | const xmlChar *str2) |
3130 | 0 | { |
3131 | 0 | xmlChar *msg = NULL; |
3132 | |
|
3133 | 0 | xmlSchemaFormatNodeForError(&msg, ACTXT_CAST ctxt, node); |
3134 | 0 | if (message == NULL) { |
3135 | | /* |
3136 | | * Use default messages. |
3137 | | */ |
3138 | 0 | if (type != NULL) { |
3139 | 0 | if (node->type == XML_ATTRIBUTE_NODE) |
3140 | 0 | msg = xmlStrcat(msg, BAD_CAST "'%s' is not a valid value of "); |
3141 | 0 | else |
3142 | 0 | msg = xmlStrcat(msg, BAD_CAST "The character content is not a " |
3143 | 0 | "valid value of "); |
3144 | 0 | if (! xmlSchemaIsGlobalItem(type)) |
3145 | 0 | msg = xmlStrcat(msg, BAD_CAST "the local "); |
3146 | 0 | else |
3147 | 0 | msg = xmlStrcat(msg, BAD_CAST "the "); |
3148 | |
|
3149 | 0 | if (WXS_IS_ATOMIC(type)) |
3150 | 0 | msg = xmlStrcat(msg, BAD_CAST "atomic type"); |
3151 | 0 | else if (WXS_IS_LIST(type)) |
3152 | 0 | msg = xmlStrcat(msg, BAD_CAST "list type"); |
3153 | 0 | else if (WXS_IS_UNION(type)) |
3154 | 0 | msg = xmlStrcat(msg, BAD_CAST "union type"); |
3155 | |
|
3156 | 0 | if (xmlSchemaIsGlobalItem(type)) { |
3157 | 0 | xmlChar *str = NULL; |
3158 | 0 | msg = xmlStrcat(msg, BAD_CAST " '"); |
3159 | 0 | if (type->builtInType != 0) { |
3160 | 0 | msg = xmlStrcat(msg, BAD_CAST "xs:"); |
3161 | 0 | str = xmlStrdup(type->name); |
3162 | 0 | } else { |
3163 | 0 | const xmlChar *qName = xmlSchemaFormatQName(&str, type->targetNamespace, type->name); |
3164 | 0 | if (!str) |
3165 | 0 | str = xmlStrdup(qName); |
3166 | 0 | } |
3167 | 0 | msg = xmlStrcat(msg, xmlEscapeFormatString(&str)); |
3168 | 0 | msg = xmlStrcat(msg, BAD_CAST "'."); |
3169 | 0 | FREE_AND_NULL(str); |
3170 | 0 | } |
3171 | 0 | } else { |
3172 | 0 | if (node->type == XML_ATTRIBUTE_NODE) |
3173 | 0 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not valid."); |
3174 | 0 | else |
3175 | 0 | msg = xmlStrcat(msg, BAD_CAST "The character content is not " |
3176 | 0 | "valid."); |
3177 | 0 | } |
3178 | 0 | if (expected) { |
3179 | 0 | xmlChar *expectedEscaped = xmlCharStrdup(expected); |
3180 | 0 | msg = xmlStrcat(msg, BAD_CAST " Expected is '"); |
3181 | 0 | msg = xmlStrcat(msg, xmlEscapeFormatString(&expectedEscaped)); |
3182 | 0 | FREE_AND_NULL(expectedEscaped); |
3183 | 0 | msg = xmlStrcat(msg, BAD_CAST "'.\n"); |
3184 | 0 | } else |
3185 | 0 | msg = xmlStrcat(msg, BAD_CAST "\n"); |
3186 | 0 | if (node->type == XML_ATTRIBUTE_NODE) |
3187 | 0 | xmlSchemaPErr(ctxt, node, error, (const char *) msg, value, NULL); |
3188 | 0 | else |
3189 | 0 | xmlSchemaPErr(ctxt, node, error, (const char *) msg, NULL, NULL); |
3190 | 0 | } else { |
3191 | 0 | msg = xmlStrcat(msg, BAD_CAST message); |
3192 | 0 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
3193 | 0 | xmlSchemaPErrExt(ctxt, node, error, NULL, NULL, NULL, |
3194 | 0 | (const char*) msg, str1, str2, NULL, NULL, NULL); |
3195 | 0 | } |
3196 | | /* Cleanup. */ |
3197 | 0 | FREE_AND_NULL(msg) |
3198 | 0 | } |
3199 | | |
3200 | | /** |
3201 | | * Reports an error concerning the content of a schema element. |
3202 | | * |
3203 | | * @param ctxt the schema parser context |
3204 | | * @param error the error code |
3205 | | * @param ownerItem the owner item of the holder of the content |
3206 | | * @param ownerElem the node of the holder of the content |
3207 | | * @param child the invalid child node |
3208 | | * @param message the optional error message |
3209 | | * @param content the optional string describing the correct content |
3210 | | */ |
3211 | | static void |
3212 | | xmlSchemaPContentErr(xmlSchemaParserCtxtPtr ctxt, |
3213 | | xmlParserErrors error, |
3214 | | xmlSchemaBasicItemPtr ownerItem, |
3215 | | xmlNodePtr ownerElem, |
3216 | | xmlNodePtr child, |
3217 | | const char *message, |
3218 | | const char *content) |
3219 | 0 | { |
3220 | 0 | xmlChar *des = NULL; |
3221 | |
|
3222 | 0 | xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem); |
3223 | 0 | if (message != NULL) |
3224 | 0 | xmlSchemaPErr2(ctxt, ownerElem, child, error, |
3225 | 0 | "%s: %s.\n", |
3226 | 0 | BAD_CAST des, BAD_CAST message); |
3227 | 0 | else { |
3228 | 0 | if (content != NULL) { |
3229 | 0 | xmlSchemaPErr2(ctxt, ownerElem, child, error, |
3230 | 0 | "%s: The content is not valid. Expected is %s.\n", |
3231 | 0 | BAD_CAST des, BAD_CAST content); |
3232 | 0 | } else { |
3233 | 0 | xmlSchemaPErr2(ctxt, ownerElem, child, error, |
3234 | 0 | "%s: The content is not valid.\n", |
3235 | 0 | BAD_CAST des, NULL); |
3236 | 0 | } |
3237 | 0 | } |
3238 | 0 | FREE_AND_NULL(des) |
3239 | 0 | } |
3240 | | |
3241 | | /************************************************************************ |
3242 | | * * |
3243 | | * Streamable error functions * |
3244 | | * * |
3245 | | ************************************************************************/ |
3246 | | |
3247 | | |
3248 | | |
3249 | | |
3250 | | /************************************************************************ |
3251 | | * * |
3252 | | * Validation helper functions * |
3253 | | * * |
3254 | | ************************************************************************/ |
3255 | | |
3256 | | |
3257 | | /************************************************************************ |
3258 | | * * |
3259 | | * Allocation functions * |
3260 | | * * |
3261 | | ************************************************************************/ |
3262 | | |
3263 | | /** |
3264 | | * Allocate a new Schema structure. |
3265 | | * |
3266 | | * @param ctxt a schema validation context |
3267 | | * @returns the newly allocated structure or NULL in case or error |
3268 | | */ |
3269 | | static xmlSchemaPtr |
3270 | | xmlSchemaNewSchema(xmlSchemaParserCtxtPtr ctxt) |
3271 | 0 | { |
3272 | 0 | xmlSchemaPtr ret; |
3273 | |
|
3274 | 0 | ret = (xmlSchemaPtr) xmlMalloc(sizeof(xmlSchema)); |
3275 | 0 | if (ret == NULL) { |
3276 | 0 | xmlSchemaPErrMemory(ctxt); |
3277 | 0 | return (NULL); |
3278 | 0 | } |
3279 | 0 | memset(ret, 0, sizeof(xmlSchema)); |
3280 | 0 | ret->dict = ctxt->dict; |
3281 | 0 | xmlDictReference(ret->dict); |
3282 | |
|
3283 | 0 | return (ret); |
3284 | 0 | } |
3285 | | |
3286 | | /** |
3287 | | * Allocate a new Facet structure. |
3288 | | * |
3289 | | * @returns the newly allocated structure or NULL in case or error |
3290 | | */ |
3291 | | xmlSchemaFacet * |
3292 | | xmlSchemaNewFacet(void) |
3293 | 0 | { |
3294 | 0 | xmlSchemaFacetPtr ret; |
3295 | |
|
3296 | 0 | ret = (xmlSchemaFacetPtr) xmlMalloc(sizeof(xmlSchemaFacet)); |
3297 | 0 | if (ret == NULL) { |
3298 | 0 | return (NULL); |
3299 | 0 | } |
3300 | 0 | memset(ret, 0, sizeof(xmlSchemaFacet)); |
3301 | |
|
3302 | 0 | return (ret); |
3303 | 0 | } |
3304 | | |
3305 | | /** |
3306 | | * Allocate a new annotation structure. |
3307 | | * |
3308 | | * @param ctxt a schema validation context |
3309 | | * @param node a node |
3310 | | * @returns the newly allocated structure or NULL in case or error |
3311 | | */ |
3312 | | static xmlSchemaAnnotPtr |
3313 | | xmlSchemaNewAnnot(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node) |
3314 | 0 | { |
3315 | 0 | xmlSchemaAnnotPtr ret; |
3316 | |
|
3317 | 0 | ret = (xmlSchemaAnnotPtr) xmlMalloc(sizeof(xmlSchemaAnnot)); |
3318 | 0 | if (ret == NULL) { |
3319 | 0 | xmlSchemaPErrMemory(ctxt); |
3320 | 0 | return (NULL); |
3321 | 0 | } |
3322 | 0 | memset(ret, 0, sizeof(xmlSchemaAnnot)); |
3323 | 0 | ret->content = node; |
3324 | 0 | return (ret); |
3325 | 0 | } |
3326 | | |
3327 | | static xmlSchemaItemListPtr |
3328 | | xmlSchemaItemListCreate(void) |
3329 | 0 | { |
3330 | 0 | xmlSchemaItemListPtr ret; |
3331 | |
|
3332 | 0 | ret = xmlMalloc(sizeof(xmlSchemaItemList)); |
3333 | 0 | if (ret == NULL) { |
3334 | 0 | xmlSchemaPErrMemory(NULL); |
3335 | 0 | return (NULL); |
3336 | 0 | } |
3337 | 0 | memset(ret, 0, sizeof(xmlSchemaItemList)); |
3338 | 0 | return (ret); |
3339 | 0 | } |
3340 | | |
3341 | | static void |
3342 | | xmlSchemaItemListClear(xmlSchemaItemListPtr list) |
3343 | 0 | { |
3344 | 0 | if (list->items != NULL) { |
3345 | 0 | xmlFree(list->items); |
3346 | 0 | list->items = NULL; |
3347 | 0 | } |
3348 | 0 | list->nbItems = 0; |
3349 | 0 | list->sizeItems = 0; |
3350 | 0 | } |
3351 | | |
3352 | | static int |
3353 | | xmlSchemaItemListGrow(xmlSchemaItemListPtr list, int initialSize) |
3354 | 0 | { |
3355 | 0 | void **tmp; |
3356 | 0 | int newSize; |
3357 | |
|
3358 | 0 | if (initialSize <= 0) |
3359 | 0 | initialSize = 1; |
3360 | 0 | newSize = xmlGrowCapacity(list->sizeItems, sizeof(tmp[0]), |
3361 | 0 | initialSize, XML_MAX_ITEMS); |
3362 | 0 | if (newSize < 0) |
3363 | 0 | return(-1); |
3364 | 0 | tmp = xmlRealloc(list->items, newSize * sizeof(tmp[0])); |
3365 | 0 | if (tmp == NULL) |
3366 | 0 | return(-1); |
3367 | | |
3368 | 0 | list->items = tmp; |
3369 | 0 | list->sizeItems = newSize; |
3370 | 0 | return(0); |
3371 | 0 | } |
3372 | | |
3373 | | static int |
3374 | | xmlSchemaItemListAddSize(xmlSchemaItemListPtr list, |
3375 | | int initialSize, |
3376 | | void *item) |
3377 | 0 | { |
3378 | 0 | if (list->sizeItems <= list->nbItems) { |
3379 | 0 | if (xmlSchemaItemListGrow(list, initialSize) < 0) { |
3380 | 0 | xmlSchemaPErrMemory(NULL); |
3381 | 0 | return(-1); |
3382 | 0 | } |
3383 | 0 | } |
3384 | | |
3385 | 0 | list->items[list->nbItems++] = item; |
3386 | 0 | return(0); |
3387 | 0 | } |
3388 | | |
3389 | | static int |
3390 | | xmlSchemaItemListAdd(xmlSchemaItemListPtr list, void *item) |
3391 | 0 | { |
3392 | 0 | return(xmlSchemaItemListAddSize(list, 20, item)); |
3393 | 0 | } |
3394 | | |
3395 | | static int |
3396 | | xmlSchemaItemListInsert(xmlSchemaItemListPtr list, void *item, int idx) |
3397 | 0 | { |
3398 | 0 | if (list->sizeItems <= list->nbItems) { |
3399 | 0 | if (xmlSchemaItemListGrow(list, 20) < 0) { |
3400 | 0 | xmlSchemaPErrMemory(NULL); |
3401 | 0 | return(-1); |
3402 | 0 | } |
3403 | 0 | } |
3404 | | |
3405 | | /* |
3406 | | * Just append if the index is greater/equal than the item count. |
3407 | | */ |
3408 | 0 | if (idx >= list->nbItems) { |
3409 | 0 | list->items[list->nbItems++] = item; |
3410 | 0 | } else { |
3411 | 0 | int i; |
3412 | 0 | for (i = list->nbItems; i > idx; i--) |
3413 | 0 | list->items[i] = list->items[i-1]; |
3414 | 0 | list->items[idx] = item; |
3415 | 0 | list->nbItems++; |
3416 | 0 | } |
3417 | 0 | return(0); |
3418 | 0 | } |
3419 | | |
3420 | | static int |
3421 | | xmlSchemaItemListRemove(xmlSchemaItemListPtr list, int idx) |
3422 | 0 | { |
3423 | 0 | int i; |
3424 | 0 | if ((list->items == NULL) || (idx >= list->nbItems)) |
3425 | 0 | return(-1); |
3426 | | |
3427 | 0 | if (list->nbItems == 1) { |
3428 | | /* TODO: Really free the list? */ |
3429 | 0 | xmlFree(list->items); |
3430 | 0 | list->items = NULL; |
3431 | 0 | list->nbItems = 0; |
3432 | 0 | list->sizeItems = 0; |
3433 | 0 | } else if (list->nbItems -1 == idx) { |
3434 | 0 | list->nbItems--; |
3435 | 0 | } else { |
3436 | 0 | for (i = idx; i < list->nbItems -1; i++) |
3437 | 0 | list->items[i] = list->items[i+1]; |
3438 | 0 | list->nbItems--; |
3439 | 0 | } |
3440 | 0 | return(0); |
3441 | 0 | } |
3442 | | |
3443 | | /** |
3444 | | * Deallocate a annotation structure |
3445 | | * |
3446 | | * @param list a schema type structure |
3447 | | */ |
3448 | | static void |
3449 | | xmlSchemaItemListFree(xmlSchemaItemListPtr list) |
3450 | 0 | { |
3451 | 0 | if (list == NULL) |
3452 | 0 | return; |
3453 | 0 | if (list->items != NULL) |
3454 | 0 | xmlFree(list->items); |
3455 | 0 | xmlFree(list); |
3456 | 0 | } |
3457 | | |
3458 | | static void |
3459 | | xmlSchemaBucketFree(xmlSchemaBucketPtr bucket) |
3460 | 0 | { |
3461 | 0 | if (bucket == NULL) |
3462 | 0 | return; |
3463 | 0 | if (bucket->globals != NULL) { |
3464 | 0 | xmlSchemaComponentListFree(bucket->globals); |
3465 | 0 | xmlSchemaItemListFree(bucket->globals); |
3466 | 0 | } |
3467 | 0 | if (bucket->locals != NULL) { |
3468 | 0 | xmlSchemaComponentListFree(bucket->locals); |
3469 | 0 | xmlSchemaItemListFree(bucket->locals); |
3470 | 0 | } |
3471 | 0 | if (bucket->relations != NULL) { |
3472 | 0 | xmlSchemaSchemaRelationPtr prev, cur = bucket->relations; |
3473 | 0 | do { |
3474 | 0 | prev = cur; |
3475 | 0 | cur = cur->next; |
3476 | 0 | xmlFree(prev); |
3477 | 0 | } while (cur != NULL); |
3478 | 0 | } |
3479 | 0 | if ((! bucket->preserveDoc) && (bucket->doc != NULL)) { |
3480 | 0 | xmlFreeDoc(bucket->doc); |
3481 | 0 | } |
3482 | 0 | if (bucket->type == XML_SCHEMA_SCHEMA_IMPORT) { |
3483 | 0 | if (WXS_IMPBUCKET(bucket)->schema != NULL) |
3484 | 0 | xmlSchemaFree(WXS_IMPBUCKET(bucket)->schema); |
3485 | 0 | } |
3486 | 0 | xmlFree(bucket); |
3487 | 0 | } |
3488 | | |
3489 | | static void |
3490 | | xmlSchemaBucketFreeEntry(void *bucket, const xmlChar *name ATTRIBUTE_UNUSED) |
3491 | 0 | { |
3492 | 0 | xmlSchemaBucketFree((xmlSchemaBucketPtr) bucket); |
3493 | 0 | } |
3494 | | |
3495 | | static xmlSchemaBucketPtr |
3496 | | xmlSchemaBucketCreate(xmlSchemaParserCtxtPtr pctxt, |
3497 | | int type, const xmlChar *targetNamespace) |
3498 | 0 | { |
3499 | 0 | xmlSchemaBucketPtr ret; |
3500 | 0 | int size; |
3501 | 0 | xmlSchemaPtr mainSchema; |
3502 | |
|
3503 | 0 | if (WXS_CONSTRUCTOR(pctxt)->mainSchema == NULL) { |
3504 | 0 | PERROR_INT("xmlSchemaBucketCreate", |
3505 | 0 | "no main schema on constructor"); |
3506 | 0 | return(NULL); |
3507 | 0 | } |
3508 | 0 | mainSchema = WXS_CONSTRUCTOR(pctxt)->mainSchema; |
3509 | | /* Create the schema bucket. */ |
3510 | 0 | if (WXS_IS_BUCKET_INCREDEF(type)) |
3511 | 0 | size = sizeof(xmlSchemaInclude); |
3512 | 0 | else |
3513 | 0 | size = sizeof(xmlSchemaImport); |
3514 | 0 | ret = (xmlSchemaBucketPtr) xmlMalloc(size); |
3515 | 0 | if (ret == NULL) { |
3516 | 0 | xmlSchemaPErrMemory(NULL); |
3517 | 0 | return(NULL); |
3518 | 0 | } |
3519 | 0 | memset(ret, 0, size); |
3520 | 0 | ret->targetNamespace = targetNamespace; |
3521 | 0 | ret->type = type; |
3522 | 0 | ret->globals = xmlSchemaItemListCreate(); |
3523 | 0 | if (ret->globals == NULL) { |
3524 | 0 | xmlSchemaBucketFree(ret); |
3525 | 0 | return(NULL); |
3526 | 0 | } |
3527 | 0 | ret->locals = xmlSchemaItemListCreate(); |
3528 | 0 | if (ret->locals == NULL) { |
3529 | 0 | xmlSchemaBucketFree(ret); |
3530 | 0 | return(NULL); |
3531 | 0 | } |
3532 | | /* |
3533 | | * The following will assure that only the first bucket is marked as |
3534 | | * XML_SCHEMA_SCHEMA_MAIN and it points to the *main* schema. |
3535 | | * For each following import buckets an xmlSchema will be created. |
3536 | | * An xmlSchema will be created for every distinct targetNamespace. |
3537 | | * We assign the targetNamespace to the schemata here. |
3538 | | */ |
3539 | 0 | if (! WXS_HAS_BUCKETS(pctxt)) { |
3540 | 0 | if (WXS_IS_BUCKET_INCREDEF(type)) { |
3541 | 0 | PERROR_INT("xmlSchemaBucketCreate", |
3542 | 0 | "first bucket but it's an include or redefine"); |
3543 | 0 | xmlSchemaBucketFree(ret); |
3544 | 0 | return(NULL); |
3545 | 0 | } |
3546 | | /* Force the type to be XML_SCHEMA_SCHEMA_MAIN. */ |
3547 | 0 | ret->type = XML_SCHEMA_SCHEMA_MAIN; |
3548 | | /* Point to the *main* schema. */ |
3549 | 0 | WXS_CONSTRUCTOR(pctxt)->mainBucket = ret; |
3550 | 0 | WXS_IMPBUCKET(ret)->schema = mainSchema; |
3551 | | /* |
3552 | | * Ensure that the main schema gets a targetNamespace. |
3553 | | */ |
3554 | 0 | mainSchema->targetNamespace = targetNamespace; |
3555 | 0 | } else { |
3556 | 0 | if (type == XML_SCHEMA_SCHEMA_MAIN) { |
3557 | 0 | PERROR_INT("xmlSchemaBucketCreate", |
3558 | 0 | "main bucket but it's not the first one"); |
3559 | 0 | xmlSchemaBucketFree(ret); |
3560 | 0 | return(NULL); |
3561 | 0 | } else if (type == XML_SCHEMA_SCHEMA_IMPORT) { |
3562 | | /* |
3563 | | * Create a schema for imports and assign the |
3564 | | * targetNamespace. |
3565 | | */ |
3566 | 0 | WXS_IMPBUCKET(ret)->schema = xmlSchemaNewSchema(pctxt); |
3567 | 0 | if (WXS_IMPBUCKET(ret)->schema == NULL) { |
3568 | 0 | xmlSchemaBucketFree(ret); |
3569 | 0 | return(NULL); |
3570 | 0 | } |
3571 | 0 | WXS_IMPBUCKET(ret)->schema->targetNamespace = targetNamespace; |
3572 | 0 | } |
3573 | 0 | } |
3574 | 0 | if (WXS_IS_BUCKET_IMPMAIN(type)) { |
3575 | 0 | int res; |
3576 | | /* |
3577 | | * Imports go into the "schemasImports" slot of the main *schema*. |
3578 | | * Note that we create an import entry for the main schema as well; i.e., |
3579 | | * even if there's only one schema, we'll get an import. |
3580 | | */ |
3581 | 0 | if (mainSchema->schemasImports == NULL) { |
3582 | 0 | mainSchema->schemasImports = xmlHashCreateDict(5, |
3583 | 0 | WXS_CONSTRUCTOR(pctxt)->dict); |
3584 | 0 | if (mainSchema->schemasImports == NULL) { |
3585 | 0 | xmlSchemaBucketFree(ret); |
3586 | 0 | return(NULL); |
3587 | 0 | } |
3588 | 0 | } |
3589 | 0 | if (targetNamespace == NULL) |
3590 | 0 | res = xmlHashAddEntry(mainSchema->schemasImports, |
3591 | 0 | XML_SCHEMAS_NO_NAMESPACE, ret); |
3592 | 0 | else |
3593 | 0 | res = xmlHashAddEntry(mainSchema->schemasImports, |
3594 | 0 | targetNamespace, ret); |
3595 | 0 | if (res != 0) { |
3596 | 0 | PERROR_INT("xmlSchemaBucketCreate", |
3597 | 0 | "failed to add the schema bucket to the hash"); |
3598 | 0 | xmlSchemaBucketFree(ret); |
3599 | 0 | return(NULL); |
3600 | 0 | } |
3601 | 0 | } else { |
3602 | | /* Set the @ownerImport of an include bucket. */ |
3603 | 0 | if (WXS_IS_BUCKET_IMPMAIN(WXS_CONSTRUCTOR(pctxt)->bucket->type)) |
3604 | 0 | WXS_INCBUCKET(ret)->ownerImport = |
3605 | 0 | WXS_IMPBUCKET(WXS_CONSTRUCTOR(pctxt)->bucket); |
3606 | 0 | else |
3607 | 0 | WXS_INCBUCKET(ret)->ownerImport = |
3608 | 0 | WXS_INCBUCKET(WXS_CONSTRUCTOR(pctxt)->bucket)->ownerImport; |
3609 | | |
3610 | | /* Includes got into the "includes" slot of the *main* schema. */ |
3611 | 0 | if (mainSchema->includes == NULL) { |
3612 | 0 | mainSchema->includes = xmlSchemaItemListCreate(); |
3613 | 0 | if (mainSchema->includes == NULL) { |
3614 | 0 | xmlSchemaBucketFree(ret); |
3615 | 0 | return(NULL); |
3616 | 0 | } |
3617 | 0 | } |
3618 | 0 | if (xmlSchemaItemListAdd(mainSchema->includes, ret) < 0) { |
3619 | 0 | xmlSchemaBucketFree(ret); |
3620 | 0 | return(NULL); |
3621 | 0 | } |
3622 | 0 | } |
3623 | | /* |
3624 | | * Add to list of all buckets; this is used for lookup |
3625 | | * during schema construction time only. |
3626 | | */ |
3627 | 0 | if (xmlSchemaItemListAdd(WXS_CONSTRUCTOR(pctxt)->buckets, ret) == -1) |
3628 | 0 | return(NULL); |
3629 | 0 | return(ret); |
3630 | 0 | } |
3631 | | |
3632 | | static int |
3633 | | xmlSchemaAddItemSize(xmlSchemaItemListPtr *list, int initialSize, void *item) |
3634 | 0 | { |
3635 | 0 | if (*list == NULL) { |
3636 | 0 | *list = xmlSchemaItemListCreate(); |
3637 | 0 | if (*list == NULL) |
3638 | 0 | return(-1); |
3639 | 0 | } |
3640 | 0 | return(xmlSchemaItemListAddSize(*list, initialSize, item)); |
3641 | 0 | } |
3642 | | |
3643 | | /** |
3644 | | * Deallocate a annotation structure |
3645 | | * |
3646 | | * @param annot a schema type structure |
3647 | | */ |
3648 | | static void |
3649 | | xmlSchemaFreeAnnot(xmlSchemaAnnotPtr annot) |
3650 | 0 | { |
3651 | 0 | if (annot == NULL) |
3652 | 0 | return; |
3653 | 0 | if (annot->next == NULL) { |
3654 | 0 | xmlFree(annot); |
3655 | 0 | } else { |
3656 | 0 | xmlSchemaAnnotPtr prev; |
3657 | |
|
3658 | 0 | do { |
3659 | 0 | prev = annot; |
3660 | 0 | annot = annot->next; |
3661 | 0 | xmlFree(prev); |
3662 | 0 | } while (annot != NULL); |
3663 | 0 | } |
3664 | 0 | } |
3665 | | |
3666 | | /** |
3667 | | * Deallocate a Schema Notation structure. |
3668 | | * |
3669 | | * @param nota a schema notation structure |
3670 | | */ |
3671 | | static void |
3672 | | xmlSchemaFreeNotation(xmlSchemaNotationPtr nota) |
3673 | 0 | { |
3674 | 0 | if (nota == NULL) |
3675 | 0 | return; |
3676 | 0 | if (nota->annot != NULL) |
3677 | 0 | xmlSchemaFreeAnnot(nota->annot); |
3678 | 0 | xmlFree(nota); |
3679 | 0 | } |
3680 | | |
3681 | | /** |
3682 | | * Deallocates an attribute declaration structure. |
3683 | | * |
3684 | | * @param attr an attribute declaration |
3685 | | */ |
3686 | | static void |
3687 | | xmlSchemaFreeAttribute(xmlSchemaAttributePtr attr) |
3688 | 0 | { |
3689 | 0 | if (attr == NULL) |
3690 | 0 | return; |
3691 | 0 | if (attr->annot != NULL) |
3692 | 0 | xmlSchemaFreeAnnot(attr->annot); |
3693 | 0 | if (attr->defVal != NULL) |
3694 | 0 | xmlSchemaFreeValue(attr->defVal); |
3695 | 0 | xmlFree(attr); |
3696 | 0 | } |
3697 | | |
3698 | | /** |
3699 | | * Deallocates an attribute use structure. |
3700 | | * |
3701 | | * @param use an attribute use |
3702 | | */ |
3703 | | static void |
3704 | | xmlSchemaFreeAttributeUse(xmlSchemaAttributeUsePtr use) |
3705 | 0 | { |
3706 | 0 | if (use == NULL) |
3707 | 0 | return; |
3708 | 0 | if (use->annot != NULL) |
3709 | 0 | xmlSchemaFreeAnnot(use->annot); |
3710 | 0 | if (use->defVal != NULL) |
3711 | 0 | xmlSchemaFreeValue(use->defVal); |
3712 | 0 | xmlFree(use); |
3713 | 0 | } |
3714 | | |
3715 | | /** |
3716 | | * Deallocates an attribute use structure. |
3717 | | * |
3718 | | * @param prohib an attribute use prohibition |
3719 | | */ |
3720 | | static void |
3721 | | xmlSchemaFreeAttributeUseProhib(xmlSchemaAttributeUseProhibPtr prohib) |
3722 | 0 | { |
3723 | 0 | if (prohib == NULL) |
3724 | 0 | return; |
3725 | 0 | xmlFree(prohib); |
3726 | 0 | } |
3727 | | |
3728 | | /** |
3729 | | * set: a schema wildcard namespace |
3730 | | * |
3731 | | * Deallocates a list of wildcard constraint structures. |
3732 | | */ |
3733 | | static void |
3734 | | xmlSchemaFreeWildcardNsSet(xmlSchemaWildcardNsPtr set) |
3735 | 0 | { |
3736 | 0 | xmlSchemaWildcardNsPtr next; |
3737 | |
|
3738 | 0 | while (set != NULL) { |
3739 | 0 | next = set->next; |
3740 | 0 | xmlFree(set); |
3741 | 0 | set = next; |
3742 | 0 | } |
3743 | 0 | } |
3744 | | |
3745 | | /** |
3746 | | * Deallocates a wildcard structure. |
3747 | | * |
3748 | | * @param wildcard a wildcard structure |
3749 | | */ |
3750 | | void |
3751 | | xmlSchemaFreeWildcard(xmlSchemaWildcard *wildcard) |
3752 | 0 | { |
3753 | 0 | if (wildcard == NULL) |
3754 | 0 | return; |
3755 | 0 | if (wildcard->annot != NULL) |
3756 | 0 | xmlSchemaFreeAnnot(wildcard->annot); |
3757 | 0 | if (wildcard->nsSet != NULL) |
3758 | 0 | xmlSchemaFreeWildcardNsSet(wildcard->nsSet); |
3759 | 0 | if (wildcard->negNsSet != NULL) |
3760 | 0 | xmlFree(wildcard->negNsSet); |
3761 | 0 | xmlFree(wildcard); |
3762 | 0 | } |
3763 | | |
3764 | | /** |
3765 | | * Deallocate a Schema Attribute Group structure. |
3766 | | * |
3767 | | * @param attrGr a schema attribute group structure |
3768 | | */ |
3769 | | static void |
3770 | | xmlSchemaFreeAttributeGroup(xmlSchemaAttributeGroupPtr attrGr) |
3771 | 0 | { |
3772 | 0 | if (attrGr == NULL) |
3773 | 0 | return; |
3774 | 0 | if (attrGr->annot != NULL) |
3775 | 0 | xmlSchemaFreeAnnot(attrGr->annot); |
3776 | 0 | if (attrGr->attrUses != NULL) |
3777 | 0 | xmlSchemaItemListFree(WXS_LIST_CAST attrGr->attrUses); |
3778 | 0 | xmlFree(attrGr); |
3779 | 0 | } |
3780 | | |
3781 | | /** |
3782 | | * Deallocatea a QName reference structure. |
3783 | | * |
3784 | | * @param item a QName reference structure |
3785 | | */ |
3786 | | static void |
3787 | | xmlSchemaFreeQNameRef(xmlSchemaQNameRefPtr item) |
3788 | 0 | { |
3789 | 0 | xmlFree(item); |
3790 | 0 | } |
3791 | | |
3792 | | /** |
3793 | | * Deallocate a list of types. |
3794 | | * |
3795 | | * @param link a type link |
3796 | | */ |
3797 | | static void |
3798 | | xmlSchemaFreeTypeLinkList(xmlSchemaTypeLinkPtr link) |
3799 | 0 | { |
3800 | 0 | xmlSchemaTypeLinkPtr next; |
3801 | |
|
3802 | 0 | while (link != NULL) { |
3803 | 0 | next = link->next; |
3804 | 0 | xmlFree(link); |
3805 | 0 | link = next; |
3806 | 0 | } |
3807 | 0 | } |
3808 | | |
3809 | | static void |
3810 | | xmlSchemaFreeIDCStateObjList(xmlSchemaIDCStateObjPtr sto) |
3811 | 0 | { |
3812 | 0 | xmlSchemaIDCStateObjPtr next; |
3813 | 0 | while (sto != NULL) { |
3814 | 0 | next = sto->next; |
3815 | 0 | if (sto->history != NULL) |
3816 | 0 | xmlFree(sto->history); |
3817 | 0 | if (sto->xpathCtxt != NULL) |
3818 | 0 | xmlFreeStreamCtxt((xmlStreamCtxtPtr) sto->xpathCtxt); |
3819 | 0 | xmlFree(sto); |
3820 | 0 | sto = next; |
3821 | 0 | } |
3822 | 0 | } |
3823 | | |
3824 | | /** |
3825 | | * Deallocates an identity-constraint definition. |
3826 | | * |
3827 | | * @param idcDef a identity-constraint definition |
3828 | | */ |
3829 | | static void |
3830 | | xmlSchemaFreeIDC(xmlSchemaIDCPtr idcDef) |
3831 | 0 | { |
3832 | 0 | xmlSchemaIDCSelectPtr cur, prev; |
3833 | |
|
3834 | 0 | if (idcDef == NULL) |
3835 | 0 | return; |
3836 | 0 | if (idcDef->annot != NULL) |
3837 | 0 | xmlSchemaFreeAnnot(idcDef->annot); |
3838 | | /* Selector */ |
3839 | 0 | if (idcDef->selector != NULL) { |
3840 | 0 | if (idcDef->selector->xpathComp != NULL) |
3841 | 0 | xmlFreePattern((xmlPatternPtr) idcDef->selector->xpathComp); |
3842 | 0 | xmlFree(idcDef->selector); |
3843 | 0 | } |
3844 | | /* Fields */ |
3845 | 0 | if (idcDef->fields != NULL) { |
3846 | 0 | cur = idcDef->fields; |
3847 | 0 | do { |
3848 | 0 | prev = cur; |
3849 | 0 | cur = cur->next; |
3850 | 0 | if (prev->xpathComp != NULL) |
3851 | 0 | xmlFreePattern((xmlPatternPtr) prev->xpathComp); |
3852 | 0 | xmlFree(prev); |
3853 | 0 | } while (cur != NULL); |
3854 | 0 | } |
3855 | 0 | xmlFree(idcDef); |
3856 | 0 | } |
3857 | | |
3858 | | /** |
3859 | | * Deallocate a Schema Element structure. |
3860 | | * |
3861 | | * @param elem a schema element structure |
3862 | | */ |
3863 | | static void |
3864 | | xmlSchemaFreeElement(xmlSchemaElementPtr elem) |
3865 | 0 | { |
3866 | 0 | if (elem == NULL) |
3867 | 0 | return; |
3868 | 0 | if (elem->annot != NULL) |
3869 | 0 | xmlSchemaFreeAnnot(elem->annot); |
3870 | 0 | if (elem->contModel != NULL) |
3871 | 0 | xmlRegFreeRegexp(elem->contModel); |
3872 | 0 | if (elem->defVal != NULL) |
3873 | 0 | xmlSchemaFreeValue(elem->defVal); |
3874 | 0 | xmlFree(elem); |
3875 | 0 | } |
3876 | | |
3877 | | /** |
3878 | | * Deallocate a Schema Facet structure. |
3879 | | * |
3880 | | * @param facet a schema facet structure |
3881 | | */ |
3882 | | void |
3883 | | xmlSchemaFreeFacet(xmlSchemaFacet *facet) |
3884 | 0 | { |
3885 | 0 | if (facet == NULL) |
3886 | 0 | return; |
3887 | 0 | if (facet->val != NULL) |
3888 | 0 | xmlSchemaFreeValue(facet->val); |
3889 | 0 | if (facet->regexp != NULL) |
3890 | 0 | xmlRegFreeRegexp(facet->regexp); |
3891 | 0 | if (facet->annot != NULL) |
3892 | 0 | xmlSchemaFreeAnnot(facet->annot); |
3893 | 0 | xmlFree(facet); |
3894 | 0 | } |
3895 | | |
3896 | | /** |
3897 | | * Deallocate a Schema Type structure. |
3898 | | * |
3899 | | * @param type a schema type structure |
3900 | | */ |
3901 | | void |
3902 | | xmlSchemaFreeType(xmlSchemaType *type) |
3903 | 0 | { |
3904 | 0 | if (type == NULL) |
3905 | 0 | return; |
3906 | 0 | if (type->annot != NULL) |
3907 | 0 | xmlSchemaFreeAnnot(type->annot); |
3908 | 0 | if (type->facets != NULL) { |
3909 | 0 | xmlSchemaFacetPtr facet, next; |
3910 | |
|
3911 | 0 | facet = type->facets; |
3912 | 0 | while (facet != NULL) { |
3913 | 0 | next = facet->next; |
3914 | 0 | xmlSchemaFreeFacet(facet); |
3915 | 0 | facet = next; |
3916 | 0 | } |
3917 | 0 | } |
3918 | 0 | if (type->attrUses != NULL) |
3919 | 0 | xmlSchemaItemListFree((xmlSchemaItemListPtr) type->attrUses); |
3920 | 0 | if (type->memberTypes != NULL) |
3921 | 0 | xmlSchemaFreeTypeLinkList(type->memberTypes); |
3922 | 0 | if (type->facetSet != NULL) { |
3923 | 0 | xmlSchemaFacetLinkPtr next, link; |
3924 | |
|
3925 | 0 | link = type->facetSet; |
3926 | 0 | do { |
3927 | 0 | next = link->next; |
3928 | 0 | xmlFree(link); |
3929 | 0 | link = next; |
3930 | 0 | } while (link != NULL); |
3931 | 0 | } |
3932 | 0 | if (type->contModel != NULL) |
3933 | 0 | xmlRegFreeRegexp(type->contModel); |
3934 | 0 | xmlFree(type); |
3935 | 0 | } |
3936 | | |
3937 | | /** |
3938 | | * Deallocates a schema model group definition. |
3939 | | * |
3940 | | * @param item a schema model group definition |
3941 | | */ |
3942 | | static void |
3943 | | xmlSchemaFreeModelGroupDef(xmlSchemaModelGroupDefPtr item) |
3944 | 0 | { |
3945 | 0 | if (item->annot != NULL) |
3946 | 0 | xmlSchemaFreeAnnot(item->annot); |
3947 | 0 | xmlFree(item); |
3948 | 0 | } |
3949 | | |
3950 | | /** |
3951 | | * Deallocates a schema model group structure. |
3952 | | * |
3953 | | * @param item a schema model group |
3954 | | */ |
3955 | | static void |
3956 | | xmlSchemaFreeModelGroup(xmlSchemaModelGroupPtr item) |
3957 | 0 | { |
3958 | 0 | if (item->annot != NULL) |
3959 | 0 | xmlSchemaFreeAnnot(item->annot); |
3960 | 0 | xmlFree(item); |
3961 | 0 | } |
3962 | | |
3963 | | static void |
3964 | | xmlSchemaComponentListFree(xmlSchemaItemListPtr list) |
3965 | 0 | { |
3966 | 0 | if ((list == NULL) || (list->nbItems == 0)) |
3967 | 0 | return; |
3968 | 0 | { |
3969 | 0 | xmlSchemaTreeItemPtr item; |
3970 | 0 | xmlSchemaTreeItemPtr *items = (xmlSchemaTreeItemPtr *) list->items; |
3971 | 0 | int i; |
3972 | |
|
3973 | 0 | for (i = 0; i < list->nbItems; i++) { |
3974 | 0 | item = items[i]; |
3975 | 0 | if (item == NULL) |
3976 | 0 | continue; |
3977 | 0 | switch (item->type) { |
3978 | 0 | case XML_SCHEMA_TYPE_SIMPLE: |
3979 | 0 | case XML_SCHEMA_TYPE_COMPLEX: |
3980 | 0 | xmlSchemaFreeType((xmlSchemaTypePtr) item); |
3981 | 0 | break; |
3982 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTE: |
3983 | 0 | xmlSchemaFreeAttribute((xmlSchemaAttributePtr) item); |
3984 | 0 | break; |
3985 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTE_USE: |
3986 | 0 | xmlSchemaFreeAttributeUse((xmlSchemaAttributeUsePtr) item); |
3987 | 0 | break; |
3988 | 0 | case XML_SCHEMA_EXTRA_ATTR_USE_PROHIB: |
3989 | 0 | xmlSchemaFreeAttributeUseProhib( |
3990 | 0 | (xmlSchemaAttributeUseProhibPtr) item); |
3991 | 0 | break; |
3992 | 0 | case XML_SCHEMA_TYPE_ELEMENT: |
3993 | 0 | xmlSchemaFreeElement((xmlSchemaElementPtr) item); |
3994 | 0 | break; |
3995 | 0 | case XML_SCHEMA_TYPE_PARTICLE: |
3996 | 0 | if (item->annot != NULL) |
3997 | 0 | xmlSchemaFreeAnnot(item->annot); |
3998 | 0 | xmlFree(item); |
3999 | 0 | break; |
4000 | 0 | case XML_SCHEMA_TYPE_SEQUENCE: |
4001 | 0 | case XML_SCHEMA_TYPE_CHOICE: |
4002 | 0 | case XML_SCHEMA_TYPE_ALL: |
4003 | 0 | xmlSchemaFreeModelGroup((xmlSchemaModelGroupPtr) item); |
4004 | 0 | break; |
4005 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
4006 | 0 | xmlSchemaFreeAttributeGroup( |
4007 | 0 | (xmlSchemaAttributeGroupPtr) item); |
4008 | 0 | break; |
4009 | 0 | case XML_SCHEMA_TYPE_GROUP: |
4010 | 0 | xmlSchemaFreeModelGroupDef( |
4011 | 0 | (xmlSchemaModelGroupDefPtr) item); |
4012 | 0 | break; |
4013 | 0 | case XML_SCHEMA_TYPE_ANY: |
4014 | 0 | case XML_SCHEMA_TYPE_ANY_ATTRIBUTE: |
4015 | 0 | xmlSchemaFreeWildcard((xmlSchemaWildcardPtr) item); |
4016 | 0 | break; |
4017 | 0 | case XML_SCHEMA_TYPE_IDC_KEY: |
4018 | 0 | case XML_SCHEMA_TYPE_IDC_UNIQUE: |
4019 | 0 | case XML_SCHEMA_TYPE_IDC_KEYREF: |
4020 | 0 | xmlSchemaFreeIDC((xmlSchemaIDCPtr) item); |
4021 | 0 | break; |
4022 | 0 | case XML_SCHEMA_TYPE_NOTATION: |
4023 | 0 | xmlSchemaFreeNotation((xmlSchemaNotationPtr) item); |
4024 | 0 | break; |
4025 | 0 | case XML_SCHEMA_EXTRA_QNAMEREF: |
4026 | 0 | xmlSchemaFreeQNameRef((xmlSchemaQNameRefPtr) item); |
4027 | 0 | break; |
4028 | 0 | default: |
4029 | | /* TODO: This should never be hit. */ |
4030 | 0 | break; |
4031 | 0 | } |
4032 | 0 | } |
4033 | 0 | list->nbItems = 0; |
4034 | 0 | } |
4035 | 0 | } |
4036 | | |
4037 | | /** |
4038 | | * Deallocate a Schema structure. |
4039 | | * |
4040 | | * @param schema a schema structure |
4041 | | */ |
4042 | | void |
4043 | | xmlSchemaFree(xmlSchema *schema) |
4044 | 0 | { |
4045 | 0 | if (schema == NULL) |
4046 | 0 | return; |
4047 | | /* |
4048 | | * Note that those slots are not responsible for freeing |
4049 | | * schema components anymore; this will now be done by |
4050 | | * the schema buckets. |
4051 | | */ |
4052 | 0 | if (schema->notaDecl != NULL) |
4053 | 0 | xmlHashFree(schema->notaDecl, NULL); |
4054 | 0 | if (schema->attrDecl != NULL) |
4055 | 0 | xmlHashFree(schema->attrDecl, NULL); |
4056 | 0 | if (schema->attrgrpDecl != NULL) |
4057 | 0 | xmlHashFree(schema->attrgrpDecl, NULL); |
4058 | 0 | if (schema->elemDecl != NULL) |
4059 | 0 | xmlHashFree(schema->elemDecl, NULL); |
4060 | 0 | if (schema->typeDecl != NULL) |
4061 | 0 | xmlHashFree(schema->typeDecl, NULL); |
4062 | 0 | if (schema->groupDecl != NULL) |
4063 | 0 | xmlHashFree(schema->groupDecl, NULL); |
4064 | 0 | if (schema->idcDef != NULL) |
4065 | 0 | xmlHashFree(schema->idcDef, NULL); |
4066 | |
|
4067 | 0 | if (schema->schemasImports != NULL) |
4068 | 0 | xmlHashFree(schema->schemasImports, xmlSchemaBucketFreeEntry); |
4069 | 0 | if (schema->includes != NULL) { |
4070 | 0 | xmlSchemaItemListPtr list = (xmlSchemaItemListPtr) schema->includes; |
4071 | 0 | int i; |
4072 | 0 | for (i = 0; i < list->nbItems; i++) { |
4073 | 0 | xmlSchemaBucketFree((xmlSchemaBucketPtr) list->items[i]); |
4074 | 0 | } |
4075 | 0 | xmlSchemaItemListFree(list); |
4076 | 0 | } |
4077 | 0 | if (schema->annot != NULL) |
4078 | 0 | xmlSchemaFreeAnnot(schema->annot); |
4079 | | /* Never free the doc here, since this will be done by the buckets. */ |
4080 | |
|
4081 | 0 | xmlDictFree(schema->dict); |
4082 | 0 | xmlFree(schema); |
4083 | 0 | } |
4084 | | |
4085 | | /************************************************************************ |
4086 | | * * |
4087 | | * Debug functions * |
4088 | | * * |
4089 | | ************************************************************************/ |
4090 | | |
4091 | | #ifdef LIBXML_DEBUG_ENABLED |
4092 | | |
4093 | | static void |
4094 | | xmlSchemaTypeDump(xmlSchemaTypePtr type, FILE * output); /* forward */ |
4095 | | |
4096 | | /** |
4097 | | * Dump the element |
4098 | | * |
4099 | | * @param payload an element |
4100 | | * @param data the file output |
4101 | | * @param name unused |
4102 | | * @param namespace unused |
4103 | | * @param context unused |
4104 | | */ |
4105 | | static void |
4106 | | xmlSchemaElementDump(void *payload, void *data, |
4107 | | const xmlChar * name ATTRIBUTE_UNUSED, |
4108 | | const xmlChar * namespace ATTRIBUTE_UNUSED, |
4109 | | const xmlChar * context ATTRIBUTE_UNUSED) |
4110 | 0 | { |
4111 | 0 | xmlSchemaElementPtr elem = (xmlSchemaElementPtr) payload; |
4112 | 0 | FILE *output = (FILE *) data; |
4113 | 0 | if (elem == NULL) |
4114 | 0 | return; |
4115 | | |
4116 | | |
4117 | 0 | fprintf(output, "Element"); |
4118 | 0 | if (elem->flags & XML_SCHEMAS_ELEM_GLOBAL) |
4119 | 0 | fprintf(output, " (global)"); |
4120 | 0 | fprintf(output, ": '%s' ", elem->name); |
4121 | 0 | if (namespace != NULL) |
4122 | 0 | fprintf(output, "ns '%s'", namespace); |
4123 | 0 | fprintf(output, "\n"); |
4124 | | #if 0 |
4125 | | if ((elem->minOccurs != 1) || (elem->maxOccurs != 1)) { |
4126 | | fprintf(output, " min %d ", elem->minOccurs); |
4127 | | if (elem->maxOccurs >= UNBOUNDED) |
4128 | | fprintf(output, "max: unbounded\n"); |
4129 | | else if (elem->maxOccurs != 1) |
4130 | | fprintf(output, "max: %d\n", elem->maxOccurs); |
4131 | | else |
4132 | | fprintf(output, "\n"); |
4133 | | } |
4134 | | #endif |
4135 | | /* |
4136 | | * Misc other properties. |
4137 | | */ |
4138 | 0 | if ((elem->flags & XML_SCHEMAS_ELEM_NILLABLE) || |
4139 | 0 | (elem->flags & XML_SCHEMAS_ELEM_ABSTRACT) || |
4140 | 0 | (elem->flags & XML_SCHEMAS_ELEM_FIXED) || |
4141 | 0 | (elem->flags & XML_SCHEMAS_ELEM_DEFAULT)) { |
4142 | 0 | fprintf(output, " props: "); |
4143 | 0 | if (elem->flags & XML_SCHEMAS_ELEM_FIXED) |
4144 | 0 | fprintf(output, "[fixed] "); |
4145 | 0 | if (elem->flags & XML_SCHEMAS_ELEM_DEFAULT) |
4146 | 0 | fprintf(output, "[default] "); |
4147 | 0 | if (elem->flags & XML_SCHEMAS_ELEM_ABSTRACT) |
4148 | 0 | fprintf(output, "[abstract] "); |
4149 | 0 | if (elem->flags & XML_SCHEMAS_ELEM_NILLABLE) |
4150 | 0 | fprintf(output, "[nillable] "); |
4151 | 0 | fprintf(output, "\n"); |
4152 | 0 | } |
4153 | | /* |
4154 | | * Default/fixed value. |
4155 | | */ |
4156 | 0 | if (elem->value != NULL) |
4157 | 0 | fprintf(output, " value: '%s'\n", elem->value); |
4158 | | /* |
4159 | | * Type. |
4160 | | */ |
4161 | 0 | if (elem->namedType != NULL) { |
4162 | 0 | fprintf(output, " type: '%s' ", elem->namedType); |
4163 | 0 | if (elem->namedTypeNs != NULL) |
4164 | 0 | fprintf(output, "ns '%s'\n", elem->namedTypeNs); |
4165 | 0 | else |
4166 | 0 | fprintf(output, "\n"); |
4167 | 0 | } else if (elem->subtypes != NULL) { |
4168 | | /* |
4169 | | * Dump local types. |
4170 | | */ |
4171 | 0 | xmlSchemaTypeDump(elem->subtypes, output); |
4172 | 0 | } |
4173 | | /* |
4174 | | * Substitution group. |
4175 | | */ |
4176 | 0 | if (elem->substGroup != NULL) { |
4177 | 0 | fprintf(output, " substitutionGroup: '%s' ", elem->substGroup); |
4178 | 0 | if (elem->substGroupNs != NULL) |
4179 | 0 | fprintf(output, "ns '%s'\n", elem->substGroupNs); |
4180 | 0 | else |
4181 | 0 | fprintf(output, "\n"); |
4182 | 0 | } |
4183 | 0 | } |
4184 | | |
4185 | | /** |
4186 | | * Dump the annotation |
4187 | | * |
4188 | | * @param output the file output |
4189 | | * @param annot a annotation |
4190 | | */ |
4191 | | static void |
4192 | | xmlSchemaAnnotDump(FILE * output, xmlSchemaAnnotPtr annot) |
4193 | 0 | { |
4194 | 0 | xmlChar *content; |
4195 | |
|
4196 | 0 | if (annot == NULL) |
4197 | 0 | return; |
4198 | | |
4199 | 0 | content = xmlNodeGetContent(annot->content); |
4200 | 0 | if (content != NULL) { |
4201 | 0 | fprintf(output, " Annot: %s\n", content); |
4202 | 0 | xmlFree(content); |
4203 | 0 | } else |
4204 | 0 | fprintf(output, " Annot: empty\n"); |
4205 | 0 | } |
4206 | | |
4207 | | /** |
4208 | | * Dump a SchemaType structure |
4209 | | * |
4210 | | * @param particle the schema particle |
4211 | | * @param output the file output |
4212 | | * @param depth the depth used for indentation |
4213 | | */ |
4214 | | static void |
4215 | | xmlSchemaContentModelDump(xmlSchemaParticlePtr particle, FILE * output, int depth) |
4216 | 0 | { |
4217 | 0 | xmlChar *str = NULL; |
4218 | 0 | xmlSchemaTreeItemPtr term; |
4219 | 0 | char shift[100]; |
4220 | 0 | int i; |
4221 | |
|
4222 | 0 | if (particle == NULL) |
4223 | 0 | return; |
4224 | 0 | for (i = 0;((i < depth) && (i < 25));i++) |
4225 | 0 | shift[2 * i] = shift[2 * i + 1] = ' '; |
4226 | 0 | shift[2 * i] = shift[2 * i + 1] = 0; |
4227 | 0 | fprintf(output, "%s", shift); |
4228 | 0 | if (particle->children == NULL) { |
4229 | 0 | fprintf(output, "MISSING particle term\n"); |
4230 | 0 | return; |
4231 | 0 | } |
4232 | 0 | term = particle->children; |
4233 | 0 | if (term == NULL) { |
4234 | 0 | fprintf(output, "(NULL)"); |
4235 | 0 | } else { |
4236 | 0 | switch (term->type) { |
4237 | 0 | case XML_SCHEMA_TYPE_ELEMENT: |
4238 | 0 | fprintf(output, "ELEM '%s'", xmlSchemaFormatQName(&str, |
4239 | 0 | ((xmlSchemaElementPtr)term)->targetNamespace, |
4240 | 0 | ((xmlSchemaElementPtr)term)->name)); |
4241 | 0 | FREE_AND_NULL(str); |
4242 | 0 | break; |
4243 | 0 | case XML_SCHEMA_TYPE_SEQUENCE: |
4244 | 0 | fprintf(output, "SEQUENCE"); |
4245 | 0 | break; |
4246 | 0 | case XML_SCHEMA_TYPE_CHOICE: |
4247 | 0 | fprintf(output, "CHOICE"); |
4248 | 0 | break; |
4249 | 0 | case XML_SCHEMA_TYPE_ALL: |
4250 | 0 | fprintf(output, "ALL"); |
4251 | 0 | break; |
4252 | 0 | case XML_SCHEMA_TYPE_ANY: |
4253 | 0 | fprintf(output, "ANY"); |
4254 | 0 | break; |
4255 | 0 | default: |
4256 | 0 | fprintf(output, "UNKNOWN\n"); |
4257 | 0 | return; |
4258 | 0 | } |
4259 | 0 | } |
4260 | 0 | if (particle->minOccurs != 1) |
4261 | 0 | fprintf(output, " min: %d", particle->minOccurs); |
4262 | 0 | if (particle->maxOccurs >= UNBOUNDED) |
4263 | 0 | fprintf(output, " max: unbounded"); |
4264 | 0 | else if (particle->maxOccurs != 1) |
4265 | 0 | fprintf(output, " max: %d", particle->maxOccurs); |
4266 | 0 | fprintf(output, "\n"); |
4267 | 0 | if (term && |
4268 | 0 | ((term->type == XML_SCHEMA_TYPE_SEQUENCE) || |
4269 | 0 | (term->type == XML_SCHEMA_TYPE_CHOICE) || |
4270 | 0 | (term->type == XML_SCHEMA_TYPE_ALL)) && |
4271 | 0 | (term->children != NULL)) { |
4272 | 0 | xmlSchemaContentModelDump((xmlSchemaParticlePtr) term->children, |
4273 | 0 | output, depth +1); |
4274 | 0 | } |
4275 | 0 | if (particle->next != NULL) |
4276 | 0 | xmlSchemaContentModelDump((xmlSchemaParticlePtr) particle->next, |
4277 | 0 | output, depth); |
4278 | 0 | } |
4279 | | |
4280 | | /** |
4281 | | * Dumps a list of attribute use components. |
4282 | | * |
4283 | | * @param uses attribute uses list |
4284 | | * @param output the file output |
4285 | | */ |
4286 | | static void |
4287 | | xmlSchemaAttrUsesDump(xmlSchemaItemListPtr uses, FILE * output) |
4288 | 0 | { |
4289 | 0 | xmlSchemaAttributeUsePtr use; |
4290 | 0 | xmlSchemaAttributeUseProhibPtr prohib; |
4291 | 0 | xmlSchemaQNameRefPtr ref; |
4292 | 0 | const xmlChar *name, *tns; |
4293 | 0 | xmlChar *str = NULL; |
4294 | 0 | int i; |
4295 | |
|
4296 | 0 | if ((uses == NULL) || (uses->nbItems == 0)) |
4297 | 0 | return; |
4298 | | |
4299 | 0 | fprintf(output, " attributes:\n"); |
4300 | 0 | for (i = 0; i < uses->nbItems; i++) { |
4301 | 0 | use = uses->items[i]; |
4302 | 0 | if (use->type == XML_SCHEMA_EXTRA_ATTR_USE_PROHIB) { |
4303 | 0 | fprintf(output, " [prohibition] "); |
4304 | 0 | prohib = (xmlSchemaAttributeUseProhibPtr) use; |
4305 | 0 | name = prohib->name; |
4306 | 0 | tns = prohib->targetNamespace; |
4307 | 0 | } else if (use->type == XML_SCHEMA_EXTRA_QNAMEREF) { |
4308 | 0 | fprintf(output, " [reference] "); |
4309 | 0 | ref = (xmlSchemaQNameRefPtr) use; |
4310 | 0 | name = ref->name; |
4311 | 0 | tns = ref->targetNamespace; |
4312 | 0 | } else { |
4313 | 0 | fprintf(output, " [use] "); |
4314 | 0 | name = WXS_ATTRUSE_DECL_NAME(use); |
4315 | 0 | tns = WXS_ATTRUSE_DECL_TNS(use); |
4316 | 0 | } |
4317 | 0 | fprintf(output, "'%s'\n", |
4318 | 0 | (const char *) xmlSchemaFormatQName(&str, tns, name)); |
4319 | 0 | FREE_AND_NULL(str); |
4320 | 0 | } |
4321 | 0 | } |
4322 | | |
4323 | | /** |
4324 | | * Dump a SchemaType structure |
4325 | | * |
4326 | | * @param output the file output |
4327 | | * @param type a type structure |
4328 | | */ |
4329 | | static void |
4330 | | xmlSchemaTypeDump(xmlSchemaTypePtr type, FILE * output) |
4331 | 0 | { |
4332 | 0 | if (type == NULL) { |
4333 | 0 | fprintf(output, "Type: NULL\n"); |
4334 | 0 | return; |
4335 | 0 | } |
4336 | 0 | fprintf(output, "Type: "); |
4337 | 0 | if (type->name != NULL) |
4338 | 0 | fprintf(output, "'%s' ", type->name); |
4339 | 0 | else |
4340 | 0 | fprintf(output, "(no name) "); |
4341 | 0 | if (type->targetNamespace != NULL) |
4342 | 0 | fprintf(output, "ns '%s' ", type->targetNamespace); |
4343 | 0 | switch (type->type) { |
4344 | 0 | case XML_SCHEMA_TYPE_BASIC: |
4345 | 0 | fprintf(output, "[basic] "); |
4346 | 0 | break; |
4347 | 0 | case XML_SCHEMA_TYPE_SIMPLE: |
4348 | 0 | fprintf(output, "[simple] "); |
4349 | 0 | break; |
4350 | 0 | case XML_SCHEMA_TYPE_COMPLEX: |
4351 | 0 | fprintf(output, "[complex] "); |
4352 | 0 | break; |
4353 | 0 | case XML_SCHEMA_TYPE_SEQUENCE: |
4354 | 0 | fprintf(output, "[sequence] "); |
4355 | 0 | break; |
4356 | 0 | case XML_SCHEMA_TYPE_CHOICE: |
4357 | 0 | fprintf(output, "[choice] "); |
4358 | 0 | break; |
4359 | 0 | case XML_SCHEMA_TYPE_ALL: |
4360 | 0 | fprintf(output, "[all] "); |
4361 | 0 | break; |
4362 | 0 | case XML_SCHEMA_TYPE_UR: |
4363 | 0 | fprintf(output, "[ur] "); |
4364 | 0 | break; |
4365 | 0 | case XML_SCHEMA_TYPE_RESTRICTION: |
4366 | 0 | fprintf(output, "[restriction] "); |
4367 | 0 | break; |
4368 | 0 | case XML_SCHEMA_TYPE_EXTENSION: |
4369 | 0 | fprintf(output, "[extension] "); |
4370 | 0 | break; |
4371 | 0 | default: |
4372 | 0 | fprintf(output, "[unknown type %d] ", type->type); |
4373 | 0 | break; |
4374 | 0 | } |
4375 | 0 | fprintf(output, "content: "); |
4376 | 0 | switch (type->contentType) { |
4377 | 0 | case XML_SCHEMA_CONTENT_UNKNOWN: |
4378 | 0 | fprintf(output, "[unknown] "); |
4379 | 0 | break; |
4380 | 0 | case XML_SCHEMA_CONTENT_EMPTY: |
4381 | 0 | fprintf(output, "[empty] "); |
4382 | 0 | break; |
4383 | 0 | case XML_SCHEMA_CONTENT_ELEMENTS: |
4384 | 0 | fprintf(output, "[element] "); |
4385 | 0 | break; |
4386 | 0 | case XML_SCHEMA_CONTENT_MIXED: |
4387 | 0 | fprintf(output, "[mixed] "); |
4388 | 0 | break; |
4389 | 0 | case XML_SCHEMA_CONTENT_MIXED_OR_ELEMENTS: |
4390 | | /* not used. */ |
4391 | 0 | break; |
4392 | 0 | case XML_SCHEMA_CONTENT_BASIC: |
4393 | 0 | fprintf(output, "[basic] "); |
4394 | 0 | break; |
4395 | 0 | case XML_SCHEMA_CONTENT_SIMPLE: |
4396 | 0 | fprintf(output, "[simple] "); |
4397 | 0 | break; |
4398 | 0 | case XML_SCHEMA_CONTENT_ANY: |
4399 | 0 | fprintf(output, "[any] "); |
4400 | 0 | break; |
4401 | 0 | } |
4402 | 0 | fprintf(output, "\n"); |
4403 | 0 | if (type->base != NULL) { |
4404 | 0 | fprintf(output, " base type: '%s'", type->base); |
4405 | 0 | if (type->baseNs != NULL) |
4406 | 0 | fprintf(output, " ns '%s'\n", type->baseNs); |
4407 | 0 | else |
4408 | 0 | fprintf(output, "\n"); |
4409 | 0 | } |
4410 | 0 | if (type->attrUses != NULL) |
4411 | 0 | xmlSchemaAttrUsesDump(type->attrUses, output); |
4412 | 0 | if (type->annot != NULL) |
4413 | 0 | xmlSchemaAnnotDump(output, type->annot); |
4414 | 0 | #ifdef DUMP_CONTENT_MODEL |
4415 | 0 | if ((type->type == XML_SCHEMA_TYPE_COMPLEX) && |
4416 | 0 | (type->subtypes != NULL)) { |
4417 | 0 | xmlSchemaContentModelDump((xmlSchemaParticlePtr) type->subtypes, |
4418 | 0 | output, 1); |
4419 | 0 | } |
4420 | 0 | #endif |
4421 | 0 | } |
4422 | | |
4423 | | static void |
4424 | | xmlSchemaTypeDumpEntry(void *type, void *output, |
4425 | | const xmlChar *name ATTRIBUTE_UNUSED) |
4426 | 0 | { |
4427 | 0 | xmlSchemaTypeDump((xmlSchemaTypePtr) type, (FILE *) output); |
4428 | 0 | } |
4429 | | |
4430 | | /** |
4431 | | * Dump a Schema structure. |
4432 | | * |
4433 | | * @param output the file output |
4434 | | * @param schema a schema structure |
4435 | | */ |
4436 | | void |
4437 | | xmlSchemaDump(FILE * output, xmlSchema *schema) |
4438 | 0 | { |
4439 | 0 | if (output == NULL) |
4440 | 0 | return; |
4441 | 0 | if (schema == NULL) { |
4442 | 0 | fprintf(output, "Schemas: NULL\n"); |
4443 | 0 | return; |
4444 | 0 | } |
4445 | 0 | fprintf(output, "Schemas: "); |
4446 | 0 | if (schema->name != NULL) |
4447 | 0 | fprintf(output, "%s, ", schema->name); |
4448 | 0 | else |
4449 | 0 | fprintf(output, "no name, "); |
4450 | 0 | if (schema->targetNamespace != NULL) |
4451 | 0 | fprintf(output, "%s", (const char *) schema->targetNamespace); |
4452 | 0 | else |
4453 | 0 | fprintf(output, "no target namespace"); |
4454 | 0 | fprintf(output, "\n"); |
4455 | 0 | if (schema->annot != NULL) |
4456 | 0 | xmlSchemaAnnotDump(output, schema->annot); |
4457 | 0 | xmlHashScan(schema->typeDecl, xmlSchemaTypeDumpEntry, output); |
4458 | 0 | xmlHashScanFull(schema->elemDecl, xmlSchemaElementDump, output); |
4459 | 0 | } |
4460 | | |
4461 | | #endif /* LIBXML_DEBUG_ENABLED */ |
4462 | | |
4463 | | /************************************************************************ |
4464 | | * * |
4465 | | * Utilities * |
4466 | | * * |
4467 | | ************************************************************************/ |
4468 | | |
4469 | | /** |
4470 | | * Seeks an attribute with a name of `name` in |
4471 | | * no namespace. |
4472 | | * |
4473 | | * @param node the element node |
4474 | | * @param name the name of the attribute |
4475 | | * @returns the attribute or NULL if not present. |
4476 | | */ |
4477 | | static xmlAttrPtr |
4478 | | xmlSchemaGetPropNode(xmlNodePtr node, const char *name) |
4479 | 0 | { |
4480 | 0 | xmlAttrPtr prop; |
4481 | |
|
4482 | 0 | if ((node == NULL) || (name == NULL)) |
4483 | 0 | return(NULL); |
4484 | 0 | prop = node->properties; |
4485 | 0 | while (prop != NULL) { |
4486 | 0 | if ((prop->ns == NULL) && xmlStrEqual(prop->name, BAD_CAST name)) |
4487 | 0 | return(prop); |
4488 | 0 | prop = prop->next; |
4489 | 0 | } |
4490 | 0 | return (NULL); |
4491 | 0 | } |
4492 | | |
4493 | | /** |
4494 | | * Seeks an attribute with a local name of `name` and |
4495 | | * a namespace URI of `uri`. |
4496 | | * |
4497 | | * @param node the element node |
4498 | | * @param uri the uri |
4499 | | * @param name the name of the attribute |
4500 | | * @returns the attribute or NULL if not present. |
4501 | | */ |
4502 | | static xmlAttrPtr |
4503 | | xmlSchemaGetPropNodeNs(xmlNodePtr node, const char *uri, const char *name) |
4504 | 0 | { |
4505 | 0 | xmlAttrPtr prop; |
4506 | |
|
4507 | 0 | if ((node == NULL) || (name == NULL)) |
4508 | 0 | return(NULL); |
4509 | 0 | prop = node->properties; |
4510 | 0 | while (prop != NULL) { |
4511 | 0 | if ((prop->ns != NULL) && |
4512 | 0 | xmlStrEqual(prop->name, BAD_CAST name) && |
4513 | 0 | xmlStrEqual(prop->ns->href, BAD_CAST uri)) |
4514 | 0 | return(prop); |
4515 | 0 | prop = prop->next; |
4516 | 0 | } |
4517 | 0 | return (NULL); |
4518 | 0 | } |
4519 | | |
4520 | | static const xmlChar * |
4521 | | xmlSchemaGetNodeContent(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node) |
4522 | 0 | { |
4523 | 0 | xmlChar *val; |
4524 | 0 | const xmlChar *ret; |
4525 | |
|
4526 | 0 | val = xmlNodeGetContent(node); |
4527 | 0 | if (val == NULL) |
4528 | 0 | val = xmlStrdup((xmlChar *)""); |
4529 | 0 | ret = xmlDictLookup(ctxt->dict, val, -1); |
4530 | 0 | xmlFree(val); |
4531 | 0 | if (ret == NULL) |
4532 | 0 | xmlSchemaPErrMemory(ctxt); |
4533 | 0 | return(ret); |
4534 | 0 | } |
4535 | | |
4536 | | static const xmlChar * |
4537 | | xmlSchemaGetNodeContentNoDict(xmlNodePtr node) |
4538 | 0 | { |
4539 | 0 | return((const xmlChar*) xmlNodeGetContent(node)); |
4540 | 0 | } |
4541 | | |
4542 | | /** |
4543 | | * Read a attribute value and internalize the string |
4544 | | * |
4545 | | * @param ctxt the parser context |
4546 | | * @param node the node |
4547 | | * @param name the property name |
4548 | | * @returns the string or NULL if not present. |
4549 | | */ |
4550 | | static const xmlChar * |
4551 | | xmlSchemaGetProp(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, |
4552 | | const char *name) |
4553 | 0 | { |
4554 | 0 | xmlChar *val; |
4555 | 0 | const xmlChar *ret; |
4556 | |
|
4557 | 0 | val = xmlGetNoNsProp(node, BAD_CAST name); |
4558 | 0 | if (val == NULL) |
4559 | 0 | return(NULL); |
4560 | 0 | ret = xmlDictLookup(ctxt->dict, val, -1); |
4561 | 0 | xmlFree(val); |
4562 | 0 | return(ret); |
4563 | 0 | } |
4564 | | |
4565 | | /************************************************************************ |
4566 | | * * |
4567 | | * Parsing functions * |
4568 | | * * |
4569 | | ************************************************************************/ |
4570 | | |
4571 | | #define WXS_FIND_GLOBAL_ITEM(slot) \ |
4572 | 0 | if (xmlStrEqual(nsName, schema->targetNamespace)) { \ |
4573 | 0 | ret = xmlHashLookup(schema->slot, name); \ |
4574 | 0 | if (ret != NULL) goto exit; \ |
4575 | 0 | } \ |
4576 | 0 | if (xmlHashSize(schema->schemasImports) > 1) { \ |
4577 | 0 | xmlSchemaImportPtr import; \ |
4578 | 0 | if (nsName == NULL) \ |
4579 | 0 | import = xmlHashLookup(schema->schemasImports, \ |
4580 | 0 | XML_SCHEMAS_NO_NAMESPACE); \ |
4581 | 0 | else \ |
4582 | 0 | import = xmlHashLookup(schema->schemasImports, nsName); \ |
4583 | 0 | if (import == NULL) \ |
4584 | 0 | goto exit; \ |
4585 | 0 | ret = xmlHashLookup(import->schema->slot, name); \ |
4586 | 0 | } |
4587 | | |
4588 | | /** |
4589 | | * Lookup a global element declaration in the schema. |
4590 | | * |
4591 | | * @param schema the schema context |
4592 | | * @param name the element name |
4593 | | * @param nsName the element namespace |
4594 | | * @returns the element declaration or NULL if not found. |
4595 | | */ |
4596 | | static xmlSchemaElementPtr |
4597 | | xmlSchemaGetElem(xmlSchemaPtr schema, const xmlChar * name, |
4598 | | const xmlChar * nsName) |
4599 | 0 | { |
4600 | 0 | xmlSchemaElementPtr ret = NULL; |
4601 | |
|
4602 | 0 | if ((name == NULL) || (schema == NULL)) |
4603 | 0 | return(NULL); |
4604 | 0 | if (schema != NULL) { |
4605 | 0 | WXS_FIND_GLOBAL_ITEM(elemDecl) |
4606 | 0 | } |
4607 | 0 | exit: |
4608 | 0 | return (ret); |
4609 | 0 | } |
4610 | | |
4611 | | /** |
4612 | | * Lookup a type in the schemas or the predefined types |
4613 | | * |
4614 | | * @param schema the main schema |
4615 | | * @param name the type's name |
4616 | | * @param nsName the type's namespace |
4617 | | * @returns the group definition or NULL if not found. |
4618 | | */ |
4619 | | static xmlSchemaTypePtr |
4620 | | xmlSchemaGetType(xmlSchemaPtr schema, const xmlChar * name, |
4621 | | const xmlChar * nsName) |
4622 | 0 | { |
4623 | 0 | xmlSchemaTypePtr ret = NULL; |
4624 | |
|
4625 | 0 | if (name == NULL) |
4626 | 0 | return (NULL); |
4627 | | /* First try the built-in types. */ |
4628 | 0 | if ((nsName != NULL) && xmlStrEqual(nsName, xmlSchemaNs)) { |
4629 | 0 | ret = xmlSchemaGetPredefinedType(name, nsName); |
4630 | 0 | if (ret != NULL) |
4631 | 0 | goto exit; |
4632 | | /* |
4633 | | * Note that we try the parsed schemas as well here |
4634 | | * since one might have parsed the S4S, which contain more |
4635 | | * than the built-in types. |
4636 | | * TODO: Can we optimize this? |
4637 | | */ |
4638 | 0 | } |
4639 | 0 | if (schema != NULL) { |
4640 | 0 | WXS_FIND_GLOBAL_ITEM(typeDecl) |
4641 | 0 | } |
4642 | 0 | exit: |
4643 | |
|
4644 | 0 | return (ret); |
4645 | 0 | } |
4646 | | |
4647 | | /** |
4648 | | * Lookup a an attribute in the schema or imported schemas |
4649 | | * |
4650 | | * @param schema the context of the schema |
4651 | | * @param name the name of the attribute |
4652 | | * @param nsName the target namespace of the attribute |
4653 | | * @returns the attribute declaration or NULL if not found. |
4654 | | */ |
4655 | | static xmlSchemaAttributePtr |
4656 | | xmlSchemaGetAttributeDecl(xmlSchemaPtr schema, const xmlChar * name, |
4657 | | const xmlChar * nsName) |
4658 | 0 | { |
4659 | 0 | xmlSchemaAttributePtr ret = NULL; |
4660 | |
|
4661 | 0 | if ((name == NULL) || (schema == NULL)) |
4662 | 0 | return (NULL); |
4663 | 0 | if (schema != NULL) { |
4664 | 0 | WXS_FIND_GLOBAL_ITEM(attrDecl) |
4665 | 0 | } |
4666 | 0 | exit: |
4667 | 0 | return (ret); |
4668 | 0 | } |
4669 | | |
4670 | | /** |
4671 | | * Lookup a an attribute group in the schema or imported schemas |
4672 | | * |
4673 | | * @param schema the context of the schema |
4674 | | * @param name the name of the attribute group |
4675 | | * @param nsName the target namespace of the attribute group |
4676 | | * @returns the attribute group definition or NULL if not found. |
4677 | | */ |
4678 | | static xmlSchemaAttributeGroupPtr |
4679 | | xmlSchemaGetAttributeGroup(xmlSchemaPtr schema, const xmlChar * name, |
4680 | | const xmlChar * nsName) |
4681 | 0 | { |
4682 | 0 | xmlSchemaAttributeGroupPtr ret = NULL; |
4683 | |
|
4684 | 0 | if ((name == NULL) || (schema == NULL)) |
4685 | 0 | return (NULL); |
4686 | 0 | if (schema != NULL) { |
4687 | 0 | WXS_FIND_GLOBAL_ITEM(attrgrpDecl) |
4688 | 0 | } |
4689 | 0 | exit: |
4690 | | /* TODO: |
4691 | | if ((ret != NULL) && (ret->redef != NULL)) { |
4692 | | * Return the last redefinition. * |
4693 | | ret = ret->redef; |
4694 | | } |
4695 | | */ |
4696 | 0 | return (ret); |
4697 | 0 | } |
4698 | | |
4699 | | /** |
4700 | | * Lookup a group in the schema or imported schemas |
4701 | | * |
4702 | | * @param schema the context of the schema |
4703 | | * @param name the name of the group |
4704 | | * @param nsName the target namespace of the group |
4705 | | * @returns the group definition or NULL if not found. |
4706 | | */ |
4707 | | static xmlSchemaModelGroupDefPtr |
4708 | | xmlSchemaGetGroup(xmlSchemaPtr schema, const xmlChar * name, |
4709 | | const xmlChar * nsName) |
4710 | 0 | { |
4711 | 0 | xmlSchemaModelGroupDefPtr ret = NULL; |
4712 | |
|
4713 | 0 | if ((name == NULL) || (schema == NULL)) |
4714 | 0 | return (NULL); |
4715 | 0 | if (schema != NULL) { |
4716 | 0 | WXS_FIND_GLOBAL_ITEM(groupDecl) |
4717 | 0 | } |
4718 | 0 | exit: |
4719 | |
|
4720 | 0 | return (ret); |
4721 | 0 | } |
4722 | | |
4723 | | static xmlSchemaNotationPtr |
4724 | | xmlSchemaGetNotation(xmlSchemaPtr schema, |
4725 | | const xmlChar *name, |
4726 | | const xmlChar *nsName) |
4727 | 0 | { |
4728 | 0 | xmlSchemaNotationPtr ret = NULL; |
4729 | |
|
4730 | 0 | if ((name == NULL) || (schema == NULL)) |
4731 | 0 | return (NULL); |
4732 | 0 | if (schema != NULL) { |
4733 | 0 | WXS_FIND_GLOBAL_ITEM(notaDecl) |
4734 | 0 | } |
4735 | 0 | exit: |
4736 | 0 | return (ret); |
4737 | 0 | } |
4738 | | |
4739 | | static xmlSchemaIDCPtr |
4740 | | xmlSchemaGetIDC(xmlSchemaPtr schema, |
4741 | | const xmlChar *name, |
4742 | | const xmlChar *nsName) |
4743 | 0 | { |
4744 | 0 | xmlSchemaIDCPtr ret = NULL; |
4745 | |
|
4746 | 0 | if ((name == NULL) || (schema == NULL)) |
4747 | 0 | return (NULL); |
4748 | 0 | if (schema != NULL) { |
4749 | 0 | WXS_FIND_GLOBAL_ITEM(idcDef) |
4750 | 0 | } |
4751 | 0 | exit: |
4752 | 0 | return (ret); |
4753 | 0 | } |
4754 | | |
4755 | | /** |
4756 | | * Lookup a group in the schema or imported schemas |
4757 | | * |
4758 | | * @param schema the schema |
4759 | | * @param itemType the item type |
4760 | | * @param name the name of the group |
4761 | | * @param targetNs the target namespace of the group |
4762 | | * @returns the group definition or NULL if not found. |
4763 | | */ |
4764 | | static xmlSchemaBasicItemPtr |
4765 | | xmlSchemaGetNamedComponent(xmlSchemaPtr schema, |
4766 | | xmlSchemaTypeType itemType, |
4767 | | const xmlChar *name, |
4768 | | const xmlChar *targetNs) |
4769 | 0 | { |
4770 | 0 | switch (itemType) { |
4771 | 0 | case XML_SCHEMA_TYPE_GROUP: |
4772 | 0 | return ((xmlSchemaBasicItemPtr) xmlSchemaGetGroup(schema, |
4773 | 0 | name, targetNs)); |
4774 | 0 | case XML_SCHEMA_TYPE_ELEMENT: |
4775 | 0 | return ((xmlSchemaBasicItemPtr) xmlSchemaGetElem(schema, |
4776 | 0 | name, targetNs)); |
4777 | 0 | default: |
4778 | | /* TODO */ |
4779 | 0 | return (NULL); |
4780 | 0 | } |
4781 | 0 | } |
4782 | | |
4783 | | /************************************************************************ |
4784 | | * * |
4785 | | * Parsing functions * |
4786 | | * * |
4787 | | ************************************************************************/ |
4788 | | |
4789 | | #define IS_BLANK_NODE(n) \ |
4790 | 0 | (((n)->type == XML_TEXT_NODE) && (xmlSchemaIsBlank((n)->content, -1))) |
4791 | | |
4792 | | /** |
4793 | | * Check if a string is ignorable |
4794 | | * |
4795 | | * @param str a string |
4796 | | * @param len the length of the string or -1 |
4797 | | * @returns 1 if the string is NULL or made of blanks chars, 0 otherwise |
4798 | | */ |
4799 | | static int |
4800 | | xmlSchemaIsBlank(xmlChar * str, int len) |
4801 | 0 | { |
4802 | 0 | if (str == NULL) |
4803 | 0 | return (1); |
4804 | 0 | if (len < 0) { |
4805 | 0 | while (*str != 0) { |
4806 | 0 | if (!(IS_BLANK_CH(*str))) |
4807 | 0 | return (0); |
4808 | 0 | str++; |
4809 | 0 | } |
4810 | 0 | } else while ((*str != 0) && (len != 0)) { |
4811 | 0 | if (!(IS_BLANK_CH(*str))) |
4812 | 0 | return (0); |
4813 | 0 | str++; |
4814 | 0 | len--; |
4815 | 0 | } |
4816 | | |
4817 | 0 | return (1); |
4818 | 0 | } |
4819 | | |
4820 | 0 | #define WXS_COMP_NAME(c, t) ((t) (c))->name |
4821 | 0 | #define WXS_COMP_TNS(c, t) ((t) (c))->targetNamespace |
4822 | | /* |
4823 | | * xmlSchemaFindRedefCompInGraph: |
4824 | | * ATTENTION TODO: This uses pointer comp. for strings. |
4825 | | */ |
4826 | | static xmlSchemaBasicItemPtr |
4827 | | xmlSchemaFindRedefCompInGraph(xmlSchemaBucketPtr bucket, |
4828 | | xmlSchemaTypeType type, |
4829 | | const xmlChar *name, |
4830 | | const xmlChar *nsName) |
4831 | 0 | { |
4832 | 0 | xmlSchemaBasicItemPtr ret; |
4833 | 0 | int i; |
4834 | |
|
4835 | 0 | if ((bucket == NULL) || (name == NULL)) |
4836 | 0 | return(NULL); |
4837 | 0 | if ((bucket->globals == NULL) || |
4838 | 0 | (bucket->globals->nbItems == 0)) |
4839 | 0 | goto subschemas; |
4840 | | /* |
4841 | | * Search in global components. |
4842 | | */ |
4843 | 0 | for (i = 0; i < bucket->globals->nbItems; i++) { |
4844 | 0 | ret = bucket->globals->items[i]; |
4845 | 0 | if (ret->type == type) { |
4846 | 0 | switch (type) { |
4847 | 0 | case XML_SCHEMA_TYPE_COMPLEX: |
4848 | 0 | case XML_SCHEMA_TYPE_SIMPLE: |
4849 | 0 | if ((WXS_COMP_NAME(ret, xmlSchemaTypePtr) == name) && |
4850 | 0 | (WXS_COMP_TNS(ret, xmlSchemaTypePtr) == |
4851 | 0 | nsName)) |
4852 | 0 | { |
4853 | 0 | return(ret); |
4854 | 0 | } |
4855 | 0 | break; |
4856 | 0 | case XML_SCHEMA_TYPE_GROUP: |
4857 | 0 | if ((WXS_COMP_NAME(ret, |
4858 | 0 | xmlSchemaModelGroupDefPtr) == name) && |
4859 | 0 | (WXS_COMP_TNS(ret, |
4860 | 0 | xmlSchemaModelGroupDefPtr) == nsName)) |
4861 | 0 | { |
4862 | 0 | return(ret); |
4863 | 0 | } |
4864 | 0 | break; |
4865 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
4866 | 0 | if ((WXS_COMP_NAME(ret, |
4867 | 0 | xmlSchemaAttributeGroupPtr) == name) && |
4868 | 0 | (WXS_COMP_TNS(ret, |
4869 | 0 | xmlSchemaAttributeGroupPtr) == nsName)) |
4870 | 0 | { |
4871 | 0 | return(ret); |
4872 | 0 | } |
4873 | 0 | break; |
4874 | 0 | default: |
4875 | | /* Should not be hit. */ |
4876 | 0 | return(NULL); |
4877 | 0 | } |
4878 | 0 | } |
4879 | 0 | } |
4880 | 0 | subschemas: |
4881 | | /* |
4882 | | * Process imported/included schemas. |
4883 | | */ |
4884 | 0 | if (bucket->relations != NULL) { |
4885 | 0 | xmlSchemaSchemaRelationPtr rel = bucket->relations; |
4886 | | |
4887 | | /* |
4888 | | * TODO: Marking the bucket will not avoid multiple searches |
4889 | | * in the same schema, but avoids at least circularity. |
4890 | | */ |
4891 | 0 | bucket->flags |= XML_SCHEMA_BUCKET_MARKED; |
4892 | 0 | do { |
4893 | 0 | if ((rel->bucket != NULL) && |
4894 | 0 | ((rel->bucket->flags & XML_SCHEMA_BUCKET_MARKED) == 0)) { |
4895 | 0 | ret = xmlSchemaFindRedefCompInGraph(rel->bucket, |
4896 | 0 | type, name, nsName); |
4897 | 0 | if (ret != NULL) |
4898 | 0 | return(ret); |
4899 | 0 | } |
4900 | 0 | rel = rel->next; |
4901 | 0 | } while (rel != NULL); |
4902 | 0 | bucket->flags ^= XML_SCHEMA_BUCKET_MARKED; |
4903 | 0 | } |
4904 | 0 | return(NULL); |
4905 | 0 | } |
4906 | | |
4907 | | /** |
4908 | | * Add an XML schema annotation declaration |
4909 | | * *WARNING* this interface is highly subject to change |
4910 | | * |
4911 | | * @param ctxt a schema parser context |
4912 | | * @param schema the schema being built |
4913 | | * @param name the item name |
4914 | | * @param nsName the element namespace |
4915 | | * @param node unused |
4916 | | * @returns the new structure or NULL in case of error |
4917 | | */ |
4918 | | static xmlSchemaNotationPtr |
4919 | | xmlSchemaAddNotation(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
4920 | | const xmlChar *name, const xmlChar *nsName, |
4921 | | xmlNodePtr node ATTRIBUTE_UNUSED) |
4922 | 0 | { |
4923 | 0 | xmlSchemaNotationPtr ret = NULL; |
4924 | |
|
4925 | 0 | if ((ctxt == NULL) || (schema == NULL) || (name == NULL)) |
4926 | 0 | return (NULL); |
4927 | | |
4928 | 0 | ret = (xmlSchemaNotationPtr) xmlMalloc(sizeof(xmlSchemaNotation)); |
4929 | 0 | if (ret == NULL) { |
4930 | 0 | xmlSchemaPErrMemory(ctxt); |
4931 | 0 | return (NULL); |
4932 | 0 | } |
4933 | 0 | memset(ret, 0, sizeof(xmlSchemaNotation)); |
4934 | 0 | ret->type = XML_SCHEMA_TYPE_NOTATION; |
4935 | 0 | ret->name = name; |
4936 | 0 | ret->targetNamespace = nsName; |
4937 | | /* TODO: do we need the node to be set? |
4938 | | * ret->node = node;*/ |
4939 | 0 | WXS_ADD_GLOBAL(ctxt, ret); |
4940 | 0 | return (ret); |
4941 | 0 | } |
4942 | | |
4943 | | /** |
4944 | | * Add an XML schema Attribute declaration |
4945 | | * *WARNING* this interface is highly subject to change |
4946 | | * |
4947 | | * @param ctxt a schema parser context |
4948 | | * @param schema the schema being built |
4949 | | * @param name the item name |
4950 | | * @param nsName the item namespace |
4951 | | * @param node the context node |
4952 | | * @param topLevel whether this is a top-level element |
4953 | | * @returns the new structure or NULL in case of error |
4954 | | */ |
4955 | | static xmlSchemaAttributePtr |
4956 | | xmlSchemaAddAttribute(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
4957 | | const xmlChar * name, const xmlChar * nsName, |
4958 | | xmlNodePtr node, int topLevel) |
4959 | 0 | { |
4960 | 0 | xmlSchemaAttributePtr ret = NULL; |
4961 | |
|
4962 | 0 | if ((ctxt == NULL) || (schema == NULL)) |
4963 | 0 | return (NULL); |
4964 | | |
4965 | 0 | ret = (xmlSchemaAttributePtr) xmlMalloc(sizeof(xmlSchemaAttribute)); |
4966 | 0 | if (ret == NULL) { |
4967 | 0 | xmlSchemaPErrMemory(ctxt); |
4968 | 0 | return (NULL); |
4969 | 0 | } |
4970 | 0 | memset(ret, 0, sizeof(xmlSchemaAttribute)); |
4971 | 0 | ret->type = XML_SCHEMA_TYPE_ATTRIBUTE; |
4972 | 0 | ret->node = node; |
4973 | 0 | ret->name = name; |
4974 | 0 | ret->targetNamespace = nsName; |
4975 | |
|
4976 | 0 | if (topLevel) |
4977 | 0 | WXS_ADD_GLOBAL(ctxt, ret); |
4978 | 0 | else |
4979 | 0 | WXS_ADD_LOCAL(ctxt, ret); |
4980 | 0 | WXS_ADD_PENDING(ctxt, ret); |
4981 | 0 | return (ret); |
4982 | 0 | } |
4983 | | |
4984 | | /** |
4985 | | * Add an XML schema Attribute declaration |
4986 | | * *WARNING* this interface is highly subject to change |
4987 | | * |
4988 | | * @param pctxt a schema parser context |
4989 | | * @param node the context node |
4990 | | * @returns the new structure or NULL in case of error |
4991 | | */ |
4992 | | static xmlSchemaAttributeUsePtr |
4993 | | xmlSchemaAddAttributeUse(xmlSchemaParserCtxtPtr pctxt, |
4994 | | xmlNodePtr node) |
4995 | 0 | { |
4996 | 0 | xmlSchemaAttributeUsePtr ret = NULL; |
4997 | |
|
4998 | 0 | if (pctxt == NULL) |
4999 | 0 | return (NULL); |
5000 | | |
5001 | 0 | ret = (xmlSchemaAttributeUsePtr) xmlMalloc(sizeof(xmlSchemaAttributeUse)); |
5002 | 0 | if (ret == NULL) { |
5003 | 0 | xmlSchemaPErrMemory(pctxt); |
5004 | 0 | return (NULL); |
5005 | 0 | } |
5006 | 0 | memset(ret, 0, sizeof(xmlSchemaAttributeUse)); |
5007 | 0 | ret->type = XML_SCHEMA_TYPE_ATTRIBUTE_USE; |
5008 | 0 | ret->node = node; |
5009 | |
|
5010 | 0 | WXS_ADD_LOCAL(pctxt, ret); |
5011 | 0 | return (ret); |
5012 | 0 | } |
5013 | | |
5014 | | /* |
5015 | | * xmlSchemaAddRedef: |
5016 | | * |
5017 | | * Adds a redefinition information. This is used at a later stage to: |
5018 | | * resolve references to the redefined components and to check constraints. |
5019 | | */ |
5020 | | static xmlSchemaRedefPtr |
5021 | | xmlSchemaAddRedef(xmlSchemaParserCtxtPtr pctxt, |
5022 | | xmlSchemaBucketPtr targetBucket, |
5023 | | void *item, |
5024 | | const xmlChar *refName, |
5025 | | const xmlChar *refTargetNs) |
5026 | 0 | { |
5027 | 0 | xmlSchemaRedefPtr ret; |
5028 | |
|
5029 | 0 | ret = (xmlSchemaRedefPtr) |
5030 | 0 | xmlMalloc(sizeof(xmlSchemaRedef)); |
5031 | 0 | if (ret == NULL) { |
5032 | 0 | xmlSchemaPErrMemory(pctxt); |
5033 | 0 | return (NULL); |
5034 | 0 | } |
5035 | 0 | memset(ret, 0, sizeof(xmlSchemaRedef)); |
5036 | 0 | ret->item = item; |
5037 | 0 | ret->targetBucket = targetBucket; |
5038 | 0 | ret->refName = refName; |
5039 | 0 | ret->refTargetNs = refTargetNs; |
5040 | 0 | if (WXS_CONSTRUCTOR(pctxt)->redefs == NULL) |
5041 | 0 | WXS_CONSTRUCTOR(pctxt)->redefs = ret; |
5042 | 0 | else |
5043 | 0 | WXS_CONSTRUCTOR(pctxt)->lastRedef->next = ret; |
5044 | 0 | WXS_CONSTRUCTOR(pctxt)->lastRedef = ret; |
5045 | |
|
5046 | 0 | return (ret); |
5047 | 0 | } |
5048 | | |
5049 | | /** |
5050 | | * Add an XML schema Attribute Group definition. |
5051 | | * |
5052 | | * @param pctxt a schema parser context |
5053 | | * @param schema the schema being built |
5054 | | * @param name the item name |
5055 | | * @param nsName the target namespace |
5056 | | * @param node the corresponding node |
5057 | | * @returns the new structure or NULL in case of error |
5058 | | */ |
5059 | | static xmlSchemaAttributeGroupPtr |
5060 | | xmlSchemaAddAttributeGroupDefinition(xmlSchemaParserCtxtPtr pctxt, |
5061 | | xmlSchemaPtr schema ATTRIBUTE_UNUSED, |
5062 | | const xmlChar *name, |
5063 | | const xmlChar *nsName, |
5064 | | xmlNodePtr node) |
5065 | 0 | { |
5066 | 0 | xmlSchemaAttributeGroupPtr ret = NULL; |
5067 | |
|
5068 | 0 | if ((pctxt == NULL) || (name == NULL)) |
5069 | 0 | return (NULL); |
5070 | | |
5071 | 0 | ret = (xmlSchemaAttributeGroupPtr) |
5072 | 0 | xmlMalloc(sizeof(xmlSchemaAttributeGroup)); |
5073 | 0 | if (ret == NULL) { |
5074 | 0 | xmlSchemaPErrMemory(pctxt); |
5075 | 0 | return (NULL); |
5076 | 0 | } |
5077 | 0 | memset(ret, 0, sizeof(xmlSchemaAttributeGroup)); |
5078 | 0 | ret->type = XML_SCHEMA_TYPE_ATTRIBUTEGROUP; |
5079 | 0 | ret->name = name; |
5080 | 0 | ret->targetNamespace = nsName; |
5081 | 0 | ret->node = node; |
5082 | | |
5083 | | /* TODO: Remove the flag. */ |
5084 | 0 | ret->flags |= XML_SCHEMAS_ATTRGROUP_GLOBAL; |
5085 | 0 | if (pctxt->isRedefine) { |
5086 | 0 | pctxt->redef = xmlSchemaAddRedef(pctxt, pctxt->redefined, |
5087 | 0 | ret, name, nsName); |
5088 | 0 | if (pctxt->redef == NULL) { |
5089 | 0 | xmlFree(ret); |
5090 | 0 | return(NULL); |
5091 | 0 | } |
5092 | 0 | pctxt->redefCounter = 0; |
5093 | 0 | } |
5094 | 0 | WXS_ADD_GLOBAL(pctxt, ret); |
5095 | 0 | WXS_ADD_PENDING(pctxt, ret); |
5096 | 0 | return (ret); |
5097 | 0 | } |
5098 | | |
5099 | | /** |
5100 | | * Add an XML schema Element declaration |
5101 | | * *WARNING* this interface is highly subject to change |
5102 | | * |
5103 | | * @param ctxt a schema parser context |
5104 | | * @param name the type name |
5105 | | * @param nsName the type namespace |
5106 | | * @param node the context node |
5107 | | * @param topLevel whether this is a top-level element |
5108 | | * @returns the new structure or NULL in case of error |
5109 | | */ |
5110 | | static xmlSchemaElementPtr |
5111 | | xmlSchemaAddElement(xmlSchemaParserCtxtPtr ctxt, |
5112 | | const xmlChar * name, const xmlChar * nsName, |
5113 | | xmlNodePtr node, int topLevel) |
5114 | 0 | { |
5115 | 0 | xmlSchemaElementPtr ret = NULL; |
5116 | |
|
5117 | 0 | if ((ctxt == NULL) || (name == NULL)) |
5118 | 0 | return (NULL); |
5119 | | |
5120 | 0 | ret = (xmlSchemaElementPtr) xmlMalloc(sizeof(xmlSchemaElement)); |
5121 | 0 | if (ret == NULL) { |
5122 | 0 | xmlSchemaPErrMemory(ctxt); |
5123 | 0 | return (NULL); |
5124 | 0 | } |
5125 | 0 | memset(ret, 0, sizeof(xmlSchemaElement)); |
5126 | 0 | ret->type = XML_SCHEMA_TYPE_ELEMENT; |
5127 | 0 | ret->name = name; |
5128 | 0 | ret->targetNamespace = nsName; |
5129 | 0 | ret->node = node; |
5130 | |
|
5131 | 0 | if (topLevel) |
5132 | 0 | WXS_ADD_GLOBAL(ctxt, ret); |
5133 | 0 | else |
5134 | 0 | WXS_ADD_LOCAL(ctxt, ret); |
5135 | 0 | WXS_ADD_PENDING(ctxt, ret); |
5136 | 0 | return (ret); |
5137 | 0 | } |
5138 | | |
5139 | | /** |
5140 | | * Add an XML schema item |
5141 | | * *WARNING* this interface is highly subject to change |
5142 | | * |
5143 | | * @param ctxt a schema parser context |
5144 | | * @param schema the schema being built |
5145 | | * @param type the type |
5146 | | * @param name the item name |
5147 | | * @param nsName the namespace |
5148 | | * @param node the context node |
5149 | | * @param topLevel whether this is a top-level element |
5150 | | * @returns the new structure or NULL in case of error |
5151 | | */ |
5152 | | static xmlSchemaTypePtr |
5153 | | xmlSchemaAddType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
5154 | | xmlSchemaTypeType type, |
5155 | | const xmlChar * name, const xmlChar * nsName, |
5156 | | xmlNodePtr node, int topLevel) |
5157 | 0 | { |
5158 | 0 | xmlSchemaTypePtr ret = NULL; |
5159 | |
|
5160 | 0 | if ((ctxt == NULL) || (schema == NULL)) |
5161 | 0 | return (NULL); |
5162 | | |
5163 | 0 | ret = (xmlSchemaTypePtr) xmlMalloc(sizeof(xmlSchemaType)); |
5164 | 0 | if (ret == NULL) { |
5165 | 0 | xmlSchemaPErrMemory(ctxt); |
5166 | 0 | return (NULL); |
5167 | 0 | } |
5168 | 0 | memset(ret, 0, sizeof(xmlSchemaType)); |
5169 | 0 | ret->type = type; |
5170 | 0 | ret->name = name; |
5171 | 0 | ret->targetNamespace = nsName; |
5172 | 0 | ret->node = node; |
5173 | 0 | if (topLevel) { |
5174 | 0 | if (ctxt->isRedefine) { |
5175 | 0 | ctxt->redef = xmlSchemaAddRedef(ctxt, ctxt->redefined, |
5176 | 0 | ret, name, nsName); |
5177 | 0 | if (ctxt->redef == NULL) { |
5178 | 0 | xmlFree(ret); |
5179 | 0 | return(NULL); |
5180 | 0 | } |
5181 | 0 | ctxt->redefCounter = 0; |
5182 | 0 | } |
5183 | 0 | WXS_ADD_GLOBAL(ctxt, ret); |
5184 | 0 | } else |
5185 | 0 | WXS_ADD_LOCAL(ctxt, ret); |
5186 | 0 | WXS_ADD_PENDING(ctxt, ret); |
5187 | 0 | return (ret); |
5188 | 0 | } |
5189 | | |
5190 | | static xmlSchemaQNameRefPtr |
5191 | | xmlSchemaNewQNameRef(xmlSchemaParserCtxtPtr pctxt, |
5192 | | xmlSchemaTypeType refType, |
5193 | | const xmlChar *refName, |
5194 | | const xmlChar *refNs) |
5195 | 0 | { |
5196 | 0 | xmlSchemaQNameRefPtr ret; |
5197 | |
|
5198 | 0 | ret = (xmlSchemaQNameRefPtr) |
5199 | 0 | xmlMalloc(sizeof(xmlSchemaQNameRef)); |
5200 | 0 | if (ret == NULL) { |
5201 | 0 | xmlSchemaPErrMemory(pctxt); |
5202 | 0 | return (NULL); |
5203 | 0 | } |
5204 | 0 | ret->node = NULL; |
5205 | 0 | ret->type = XML_SCHEMA_EXTRA_QNAMEREF; |
5206 | 0 | ret->name = refName; |
5207 | 0 | ret->targetNamespace = refNs; |
5208 | 0 | ret->item = NULL; |
5209 | 0 | ret->itemType = refType; |
5210 | | /* |
5211 | | * Store the reference item in the schema. |
5212 | | */ |
5213 | 0 | WXS_ADD_LOCAL(pctxt, ret); |
5214 | 0 | return (ret); |
5215 | 0 | } |
5216 | | |
5217 | | static xmlSchemaAttributeUseProhibPtr |
5218 | | xmlSchemaAddAttributeUseProhib(xmlSchemaParserCtxtPtr pctxt) |
5219 | 0 | { |
5220 | 0 | xmlSchemaAttributeUseProhibPtr ret; |
5221 | |
|
5222 | 0 | ret = (xmlSchemaAttributeUseProhibPtr) |
5223 | 0 | xmlMalloc(sizeof(xmlSchemaAttributeUseProhib)); |
5224 | 0 | if (ret == NULL) { |
5225 | 0 | xmlSchemaPErrMemory(pctxt); |
5226 | 0 | return (NULL); |
5227 | 0 | } |
5228 | 0 | memset(ret, 0, sizeof(xmlSchemaAttributeUseProhib)); |
5229 | 0 | ret->type = XML_SCHEMA_EXTRA_ATTR_USE_PROHIB; |
5230 | 0 | WXS_ADD_LOCAL(pctxt, ret); |
5231 | 0 | return (ret); |
5232 | 0 | } |
5233 | | |
5234 | | |
5235 | | /** |
5236 | | * Adds a schema model group |
5237 | | * *WARNING* this interface is highly subject to change |
5238 | | * |
5239 | | * @param ctxt a schema parser context |
5240 | | * @param schema the schema being built |
5241 | | * @param type the "compositor" type of the model group |
5242 | | * @param node the node in the schema doc |
5243 | | * @returns the new structure or NULL in case of error |
5244 | | */ |
5245 | | static xmlSchemaModelGroupPtr |
5246 | | xmlSchemaAddModelGroup(xmlSchemaParserCtxtPtr ctxt, |
5247 | | xmlSchemaPtr schema, |
5248 | | xmlSchemaTypeType type, |
5249 | | xmlNodePtr node) |
5250 | 0 | { |
5251 | 0 | xmlSchemaModelGroupPtr ret = NULL; |
5252 | |
|
5253 | 0 | if ((ctxt == NULL) || (schema == NULL)) |
5254 | 0 | return (NULL); |
5255 | | |
5256 | 0 | ret = (xmlSchemaModelGroupPtr) |
5257 | 0 | xmlMalloc(sizeof(xmlSchemaModelGroup)); |
5258 | 0 | if (ret == NULL) { |
5259 | 0 | xmlSchemaPErrMemory(ctxt); |
5260 | 0 | return (NULL); |
5261 | 0 | } |
5262 | 0 | memset(ret, 0, sizeof(xmlSchemaModelGroup)); |
5263 | 0 | ret->type = type; |
5264 | 0 | ret->node = node; |
5265 | 0 | WXS_ADD_LOCAL(ctxt, ret); |
5266 | 0 | if ((type == XML_SCHEMA_TYPE_SEQUENCE) || |
5267 | 0 | (type == XML_SCHEMA_TYPE_CHOICE)) |
5268 | 0 | WXS_ADD_PENDING(ctxt, ret); |
5269 | 0 | return (ret); |
5270 | 0 | } |
5271 | | |
5272 | | |
5273 | | /** |
5274 | | * Adds an XML schema particle component. |
5275 | | * *WARNING* this interface is highly subject to change |
5276 | | * |
5277 | | * @param ctxt a schema parser context |
5278 | | * @param node the corresponding node in the schema doc |
5279 | | * @param min the minOccurs |
5280 | | * @param max the maxOccurs |
5281 | | * @returns the new structure or NULL in case of error |
5282 | | */ |
5283 | | static xmlSchemaParticlePtr |
5284 | | xmlSchemaAddParticle(xmlSchemaParserCtxtPtr ctxt, |
5285 | | xmlNodePtr node, int min, int max) |
5286 | 0 | { |
5287 | 0 | xmlSchemaParticlePtr ret = NULL; |
5288 | 0 | if (ctxt == NULL) |
5289 | 0 | return (NULL); |
5290 | | |
5291 | 0 | ret = (xmlSchemaParticlePtr) |
5292 | 0 | xmlMalloc(sizeof(xmlSchemaParticle)); |
5293 | 0 | if (ret == NULL) { |
5294 | 0 | xmlSchemaPErrMemory(ctxt); |
5295 | 0 | return (NULL); |
5296 | 0 | } |
5297 | 0 | ret->type = XML_SCHEMA_TYPE_PARTICLE; |
5298 | 0 | ret->annot = NULL; |
5299 | 0 | ret->node = node; |
5300 | 0 | ret->minOccurs = min; |
5301 | 0 | ret->maxOccurs = max; |
5302 | 0 | ret->next = NULL; |
5303 | 0 | ret->children = NULL; |
5304 | |
|
5305 | 0 | WXS_ADD_LOCAL(ctxt, ret); |
5306 | | /* |
5307 | | * Note that addition to pending components will be done locally |
5308 | | * to the specific parsing function, since the most particles |
5309 | | * need not to be fixed up (i.e. the reference to be resolved). |
5310 | | * REMOVED: WXS_ADD_PENDING(ctxt, ret); |
5311 | | */ |
5312 | 0 | return (ret); |
5313 | 0 | } |
5314 | | |
5315 | | /** |
5316 | | * Add an XML schema Group definition |
5317 | | * |
5318 | | * @param ctxt a schema validation context |
5319 | | * @param schema the schema being built |
5320 | | * @param name the group name |
5321 | | * @param nsName the group namespace |
5322 | | * @param node the context node |
5323 | | * @returns the new structure or NULL in case of error |
5324 | | */ |
5325 | | static xmlSchemaModelGroupDefPtr |
5326 | | xmlSchemaAddModelGroupDefinition(xmlSchemaParserCtxtPtr ctxt, |
5327 | | xmlSchemaPtr schema, |
5328 | | const xmlChar *name, |
5329 | | const xmlChar *nsName, |
5330 | | xmlNodePtr node) |
5331 | 0 | { |
5332 | 0 | xmlSchemaModelGroupDefPtr ret = NULL; |
5333 | |
|
5334 | 0 | if ((ctxt == NULL) || (schema == NULL) || (name == NULL)) |
5335 | 0 | return (NULL); |
5336 | | |
5337 | 0 | ret = (xmlSchemaModelGroupDefPtr) |
5338 | 0 | xmlMalloc(sizeof(xmlSchemaModelGroupDef)); |
5339 | 0 | if (ret == NULL) { |
5340 | 0 | xmlSchemaPErrMemory(ctxt); |
5341 | 0 | return (NULL); |
5342 | 0 | } |
5343 | 0 | memset(ret, 0, sizeof(xmlSchemaModelGroupDef)); |
5344 | 0 | ret->name = name; |
5345 | 0 | ret->type = XML_SCHEMA_TYPE_GROUP; |
5346 | 0 | ret->node = node; |
5347 | 0 | ret->targetNamespace = nsName; |
5348 | |
|
5349 | 0 | if (ctxt->isRedefine) { |
5350 | 0 | ctxt->redef = xmlSchemaAddRedef(ctxt, ctxt->redefined, |
5351 | 0 | ret, name, nsName); |
5352 | 0 | if (ctxt->redef == NULL) { |
5353 | 0 | xmlFree(ret); |
5354 | 0 | return(NULL); |
5355 | 0 | } |
5356 | 0 | ctxt->redefCounter = 0; |
5357 | 0 | } |
5358 | 0 | WXS_ADD_GLOBAL(ctxt, ret); |
5359 | 0 | WXS_ADD_PENDING(ctxt, ret); |
5360 | 0 | return (ret); |
5361 | 0 | } |
5362 | | |
5363 | | /** |
5364 | | * Creates a new wildcard namespace constraint. |
5365 | | * |
5366 | | * @param ctxt a schema validation context |
5367 | | * @returns the new structure or NULL in case of error |
5368 | | */ |
5369 | | static xmlSchemaWildcardNsPtr |
5370 | | xmlSchemaNewWildcardNsConstraint(xmlSchemaParserCtxtPtr ctxt) |
5371 | 0 | { |
5372 | 0 | xmlSchemaWildcardNsPtr ret; |
5373 | |
|
5374 | 0 | ret = (xmlSchemaWildcardNsPtr) |
5375 | 0 | xmlMalloc(sizeof(xmlSchemaWildcardNs)); |
5376 | 0 | if (ret == NULL) { |
5377 | 0 | xmlSchemaPErrMemory(ctxt); |
5378 | 0 | return (NULL); |
5379 | 0 | } |
5380 | 0 | ret->value = NULL; |
5381 | 0 | ret->next = NULL; |
5382 | 0 | return (ret); |
5383 | 0 | } |
5384 | | |
5385 | | static xmlSchemaIDCPtr |
5386 | | xmlSchemaAddIDC(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
5387 | | const xmlChar *name, const xmlChar *nsName, |
5388 | | int category, xmlNodePtr node) |
5389 | 0 | { |
5390 | 0 | xmlSchemaIDCPtr ret = NULL; |
5391 | |
|
5392 | 0 | if ((ctxt == NULL) || (schema == NULL) || (name == NULL)) |
5393 | 0 | return (NULL); |
5394 | | |
5395 | 0 | ret = (xmlSchemaIDCPtr) xmlMalloc(sizeof(xmlSchemaIDC)); |
5396 | 0 | if (ret == NULL) { |
5397 | 0 | xmlSchemaPErrMemory(ctxt); |
5398 | 0 | return (NULL); |
5399 | 0 | } |
5400 | 0 | memset(ret, 0, sizeof(xmlSchemaIDC)); |
5401 | | /* The target namespace of the parent element declaration. */ |
5402 | 0 | ret->targetNamespace = nsName; |
5403 | 0 | ret->name = name; |
5404 | 0 | ret->type = category; |
5405 | 0 | ret->node = node; |
5406 | |
|
5407 | 0 | WXS_ADD_GLOBAL(ctxt, ret); |
5408 | | /* |
5409 | | * Only keyrefs need to be fixup up. |
5410 | | */ |
5411 | 0 | if (category == XML_SCHEMA_TYPE_IDC_KEYREF) |
5412 | 0 | WXS_ADD_PENDING(ctxt, ret); |
5413 | 0 | return (ret); |
5414 | 0 | } |
5415 | | |
5416 | | /** |
5417 | | * Adds a wildcard. |
5418 | | * It corresponds to a xsd:anyAttribute and xsd:any. |
5419 | | * |
5420 | | * @param ctxt a schema validation context |
5421 | | * @param schema a schema |
5422 | | * @param type the type |
5423 | | * @param node the context node |
5424 | | * @returns the new structure or NULL in case of error |
5425 | | */ |
5426 | | static xmlSchemaWildcardPtr |
5427 | | xmlSchemaAddWildcard(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
5428 | | xmlSchemaTypeType type, xmlNodePtr node) |
5429 | 0 | { |
5430 | 0 | xmlSchemaWildcardPtr ret = NULL; |
5431 | |
|
5432 | 0 | if ((ctxt == NULL) || (schema == NULL)) |
5433 | 0 | return (NULL); |
5434 | | |
5435 | 0 | ret = (xmlSchemaWildcardPtr) xmlMalloc(sizeof(xmlSchemaWildcard)); |
5436 | 0 | if (ret == NULL) { |
5437 | 0 | xmlSchemaPErrMemory(ctxt); |
5438 | 0 | return (NULL); |
5439 | 0 | } |
5440 | 0 | memset(ret, 0, sizeof(xmlSchemaWildcard)); |
5441 | 0 | ret->type = type; |
5442 | 0 | ret->node = node; |
5443 | 0 | WXS_ADD_LOCAL(ctxt, ret); |
5444 | 0 | return (ret); |
5445 | 0 | } |
5446 | | |
5447 | | static void |
5448 | | xmlSchemaSubstGroupFree(xmlSchemaSubstGroupPtr group) |
5449 | 0 | { |
5450 | 0 | if (group == NULL) |
5451 | 0 | return; |
5452 | 0 | if (group->members != NULL) |
5453 | 0 | xmlSchemaItemListFree(group->members); |
5454 | 0 | xmlFree(group); |
5455 | 0 | } |
5456 | | |
5457 | | static void |
5458 | | xmlSchemaSubstGroupFreeEntry(void *group, const xmlChar *name ATTRIBUTE_UNUSED) |
5459 | 0 | { |
5460 | 0 | xmlSchemaSubstGroupFree((xmlSchemaSubstGroupPtr) group); |
5461 | 0 | } |
5462 | | |
5463 | | static xmlSchemaSubstGroupPtr |
5464 | | xmlSchemaSubstGroupAdd(xmlSchemaParserCtxtPtr pctxt, |
5465 | | xmlSchemaElementPtr head) |
5466 | 0 | { |
5467 | 0 | xmlSchemaSubstGroupPtr ret; |
5468 | | |
5469 | | /* Init subst group hash. */ |
5470 | 0 | if (WXS_SUBST_GROUPS(pctxt) == NULL) { |
5471 | 0 | WXS_SUBST_GROUPS(pctxt) = xmlHashCreateDict(10, pctxt->dict); |
5472 | 0 | if (WXS_SUBST_GROUPS(pctxt) == NULL) |
5473 | 0 | return(NULL); |
5474 | 0 | } |
5475 | | /* Create a new substitution group. */ |
5476 | 0 | ret = (xmlSchemaSubstGroupPtr) xmlMalloc(sizeof(xmlSchemaSubstGroup)); |
5477 | 0 | if (ret == NULL) { |
5478 | 0 | xmlSchemaPErrMemory(NULL); |
5479 | 0 | return(NULL); |
5480 | 0 | } |
5481 | 0 | memset(ret, 0, sizeof(xmlSchemaSubstGroup)); |
5482 | 0 | ret->head = head; |
5483 | | /* Create list of members. */ |
5484 | 0 | ret->members = xmlSchemaItemListCreate(); |
5485 | 0 | if (ret->members == NULL) { |
5486 | 0 | xmlSchemaSubstGroupFree(ret); |
5487 | 0 | return(NULL); |
5488 | 0 | } |
5489 | | /* Add subst group to hash. */ |
5490 | 0 | if (xmlHashAddEntry2(WXS_SUBST_GROUPS(pctxt), |
5491 | 0 | head->name, head->targetNamespace, ret) != 0) { |
5492 | 0 | PERROR_INT("xmlSchemaSubstGroupAdd", |
5493 | 0 | "failed to add a new substitution container"); |
5494 | 0 | xmlSchemaSubstGroupFree(ret); |
5495 | 0 | return(NULL); |
5496 | 0 | } |
5497 | 0 | return(ret); |
5498 | 0 | } |
5499 | | |
5500 | | static xmlSchemaSubstGroupPtr |
5501 | | xmlSchemaSubstGroupGet(xmlSchemaParserCtxtPtr pctxt, |
5502 | | xmlSchemaElementPtr head) |
5503 | 0 | { |
5504 | 0 | if (WXS_SUBST_GROUPS(pctxt) == NULL) |
5505 | 0 | return(NULL); |
5506 | 0 | return(xmlHashLookup2(WXS_SUBST_GROUPS(pctxt), |
5507 | 0 | head->name, head->targetNamespace)); |
5508 | |
|
5509 | 0 | } |
5510 | | |
5511 | | /** |
5512 | | * Allocate a new annotation structure. |
5513 | | * |
5514 | | * @param pctxt a schema parser context |
5515 | | * @param head the head of the substitution group |
5516 | | * @param member the new member of the substitution group |
5517 | | * @returns the newly allocated structure or NULL in case or error |
5518 | | */ |
5519 | | static int |
5520 | | xmlSchemaAddElementSubstitutionMember(xmlSchemaParserCtxtPtr pctxt, |
5521 | | xmlSchemaElementPtr head, |
5522 | | xmlSchemaElementPtr member) |
5523 | 0 | { |
5524 | 0 | xmlSchemaSubstGroupPtr substGroup = NULL; |
5525 | |
|
5526 | 0 | if ((pctxt == NULL) || (head == NULL) || (member == NULL)) |
5527 | 0 | return (-1); |
5528 | | |
5529 | 0 | substGroup = xmlSchemaSubstGroupGet(pctxt, head); |
5530 | 0 | if (substGroup == NULL) |
5531 | 0 | substGroup = xmlSchemaSubstGroupAdd(pctxt, head); |
5532 | 0 | if (substGroup == NULL) |
5533 | 0 | return(-1); |
5534 | 0 | if (xmlSchemaItemListAdd(substGroup->members, member) == -1) |
5535 | 0 | return(-1); |
5536 | 0 | return(0); |
5537 | 0 | } |
5538 | | |
5539 | | /************************************************************************ |
5540 | | * * |
5541 | | * Utilities for parsing * |
5542 | | * * |
5543 | | ************************************************************************/ |
5544 | | |
5545 | | /** |
5546 | | * Extracts the local name and the URI of a QName value and validates it. |
5547 | | * This one is intended to be used on attribute values that |
5548 | | * should resolve to schema components. |
5549 | | * |
5550 | | * @param ctxt a schema parser context |
5551 | | * @param schema the schema context |
5552 | | * @param attr the attribute node |
5553 | | * @param ownerItem the parent as a schema object |
5554 | | * @param value the QName value |
5555 | | * @param uri the resulting namespace URI if found |
5556 | | * @param local the resulting local part if found, the attribute value otherwise |
5557 | | * @returns 0, in case the QName is valid, a positive error code |
5558 | | * if not valid and -1 if an internal error occurs. |
5559 | | */ |
5560 | | static int |
5561 | | xmlSchemaPValAttrNodeQNameValue(xmlSchemaParserCtxtPtr ctxt, |
5562 | | xmlSchemaPtr schema, |
5563 | | xmlSchemaBasicItemPtr ownerItem, |
5564 | | xmlAttrPtr attr, |
5565 | | const xmlChar *value, |
5566 | | const xmlChar **uri, |
5567 | | const xmlChar **local) |
5568 | 0 | { |
5569 | 0 | const xmlChar *pref; |
5570 | 0 | xmlNsPtr ns; |
5571 | 0 | int len, ret; |
5572 | |
|
5573 | 0 | *uri = NULL; |
5574 | 0 | *local = NULL; |
5575 | 0 | ret = xmlValidateQName(value, 1); |
5576 | 0 | if (ret > 0) { |
5577 | 0 | xmlSchemaPSimpleTypeErr(ctxt, |
5578 | 0 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
5579 | 0 | ownerItem, (xmlNodePtr) attr, |
5580 | 0 | xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), |
5581 | 0 | NULL, value, NULL, NULL, NULL); |
5582 | 0 | *local = value; |
5583 | 0 | return (ctxt->err); |
5584 | 0 | } else if (ret < 0) |
5585 | 0 | return (-1); |
5586 | | |
5587 | 0 | if (!strchr((char *) value, ':')) { |
5588 | 0 | ns = xmlSearchNs(attr->doc, attr->parent, NULL); |
5589 | 0 | if (ns && ns->href && ns->href[0]) |
5590 | 0 | *uri = xmlDictLookup(ctxt->dict, ns->href, -1); |
5591 | 0 | else if (schema->flags & XML_SCHEMAS_INCLUDING_CONVERT_NS) { |
5592 | | /* TODO: move XML_SCHEMAS_INCLUDING_CONVERT_NS to the |
5593 | | * parser context. */ |
5594 | | /* |
5595 | | * This one takes care of included schemas with no |
5596 | | * target namespace. |
5597 | | */ |
5598 | 0 | *uri = ctxt->targetNamespace; |
5599 | 0 | } |
5600 | 0 | *local = xmlDictLookup(ctxt->dict, value, -1); |
5601 | 0 | return (0); |
5602 | 0 | } |
5603 | | /* |
5604 | | * At this point xmlSplitQName3 has to return a local name. |
5605 | | */ |
5606 | 0 | *local = xmlSplitQName3(value, &len); |
5607 | 0 | *local = xmlDictLookup(ctxt->dict, *local, -1); |
5608 | 0 | pref = xmlDictLookup(ctxt->dict, value, len); |
5609 | 0 | ns = xmlSearchNs(attr->doc, attr->parent, pref); |
5610 | 0 | if (ns == NULL) { |
5611 | 0 | xmlSchemaPSimpleTypeErr(ctxt, |
5612 | 0 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
5613 | 0 | ownerItem, (xmlNodePtr) attr, |
5614 | 0 | xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), NULL, value, |
5615 | 0 | "The value '%s' of simple type 'xs:QName' has no " |
5616 | 0 | "corresponding namespace declaration in scope", value, NULL); |
5617 | 0 | return (ctxt->err); |
5618 | 0 | } else { |
5619 | 0 | *uri = xmlDictLookup(ctxt->dict, ns->href, -1); |
5620 | 0 | } |
5621 | 0 | return (0); |
5622 | 0 | } |
5623 | | |
5624 | | /** |
5625 | | * Extracts and validates the QName of an attribute value. |
5626 | | * This one is intended to be used on attribute values that |
5627 | | * should resolve to schema components. |
5628 | | * |
5629 | | * @param ctxt a schema parser context |
5630 | | * @param schema the schema context |
5631 | | * @param ownerItem the owner as a schema object |
5632 | | * @param attr the attribute node |
5633 | | * @param uri the resulting namespace URI if found |
5634 | | * @param local the resulting local part if found, the attribute value otherwise |
5635 | | * @returns 0, in case the QName is valid, a positive error code |
5636 | | * if not valid and -1 if an internal error occurs. |
5637 | | */ |
5638 | | static int |
5639 | | xmlSchemaPValAttrNodeQName(xmlSchemaParserCtxtPtr ctxt, |
5640 | | xmlSchemaPtr schema, |
5641 | | xmlSchemaBasicItemPtr ownerItem, |
5642 | | xmlAttrPtr attr, |
5643 | | const xmlChar **uri, |
5644 | | const xmlChar **local) |
5645 | 0 | { |
5646 | 0 | const xmlChar *value; |
5647 | |
|
5648 | 0 | value = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
5649 | 0 | return (xmlSchemaPValAttrNodeQNameValue(ctxt, schema, |
5650 | 0 | ownerItem, attr, value, uri, local)); |
5651 | 0 | } |
5652 | | |
5653 | | /** |
5654 | | * Extracts and validates the QName of an attribute value. |
5655 | | * |
5656 | | * @param ctxt a schema parser context |
5657 | | * @param schema the schema context |
5658 | | * @param ownerItem the owner as a schema object |
5659 | | * @param ownerElem the parent node of the attribute |
5660 | | * @param name the name of the attribute |
5661 | | * @param uri the resulting namespace URI if found |
5662 | | * @param local the resulting local part if found, the attribute value otherwise |
5663 | | * @returns 0, in case the QName is valid, a positive error code |
5664 | | * if not valid and -1 if an internal error occurs. |
5665 | | */ |
5666 | | static int |
5667 | | xmlSchemaPValAttrQName(xmlSchemaParserCtxtPtr ctxt, |
5668 | | xmlSchemaPtr schema, |
5669 | | xmlSchemaBasicItemPtr ownerItem, |
5670 | | xmlNodePtr ownerElem, |
5671 | | const char *name, |
5672 | | const xmlChar **uri, |
5673 | | const xmlChar **local) |
5674 | 0 | { |
5675 | 0 | xmlAttrPtr attr; |
5676 | |
|
5677 | 0 | attr = xmlSchemaGetPropNode(ownerElem, name); |
5678 | 0 | if (attr == NULL) { |
5679 | 0 | *local = NULL; |
5680 | 0 | *uri = NULL; |
5681 | 0 | return (0); |
5682 | 0 | } |
5683 | 0 | return (xmlSchemaPValAttrNodeQName(ctxt, schema, |
5684 | 0 | ownerItem, attr, uri, local)); |
5685 | 0 | } |
5686 | | |
5687 | | /** |
5688 | | * Extracts and validates the ID of an attribute value. |
5689 | | * |
5690 | | * @param ctxt a schema parser context |
5691 | | * @param attr attribute node |
5692 | | * @returns 0, in case the ID is valid, a positive error code |
5693 | | * if not valid and -1 if an internal error occurs. |
5694 | | */ |
5695 | | static int |
5696 | | xmlSchemaPValAttrNodeID(xmlSchemaParserCtxtPtr ctxt, xmlAttrPtr attr) |
5697 | 0 | { |
5698 | 0 | int ret; |
5699 | 0 | const xmlChar *value; |
5700 | |
|
5701 | 0 | if (attr == NULL) |
5702 | 0 | return(0); |
5703 | 0 | value = xmlSchemaGetNodeContentNoDict((xmlNodePtr) attr); |
5704 | 0 | ret = xmlValidateNCName(value, 1); |
5705 | 0 | if (ret == 0) { |
5706 | | /* |
5707 | | * NOTE: the IDness might have already be declared in the DTD |
5708 | | */ |
5709 | 0 | if (attr->atype != XML_ATTRIBUTE_ID) { |
5710 | 0 | xmlChar *strip; |
5711 | 0 | int res; |
5712 | | |
5713 | | /* |
5714 | | * TODO: Use xmlSchemaStrip here; it's not exported at this |
5715 | | * moment. |
5716 | | */ |
5717 | 0 | strip = xmlSchemaCollapseString(value); |
5718 | 0 | if (strip != NULL) { |
5719 | 0 | xmlFree((xmlChar *) value); |
5720 | 0 | value = strip; |
5721 | 0 | } |
5722 | 0 | res = xmlAddIDSafe(attr, value); |
5723 | 0 | if (res < 0) { |
5724 | 0 | xmlSchemaPErrMemory(ctxt); |
5725 | 0 | } else if (res == 0) { |
5726 | 0 | ret = XML_SCHEMAP_S4S_ATTR_INVALID_VALUE; |
5727 | 0 | xmlSchemaPSimpleTypeErr(ctxt, |
5728 | 0 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
5729 | 0 | NULL, (xmlNodePtr) attr, |
5730 | 0 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ID), |
5731 | 0 | NULL, NULL, "Duplicate value '%s' of simple " |
5732 | 0 | "type 'xs:ID'", value, NULL); |
5733 | 0 | } |
5734 | 0 | } |
5735 | 0 | } else if (ret > 0) { |
5736 | 0 | ret = XML_SCHEMAP_S4S_ATTR_INVALID_VALUE; |
5737 | 0 | xmlSchemaPSimpleTypeErr(ctxt, |
5738 | 0 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
5739 | 0 | NULL, (xmlNodePtr) attr, |
5740 | 0 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ID), |
5741 | 0 | NULL, NULL, "The value '%s' of simple type 'xs:ID' is " |
5742 | 0 | "not a valid 'xs:NCName'", |
5743 | 0 | value, NULL); |
5744 | 0 | } |
5745 | 0 | if (value != NULL) |
5746 | 0 | xmlFree((xmlChar *)value); |
5747 | |
|
5748 | 0 | return (ret); |
5749 | 0 | } |
5750 | | |
5751 | | static int |
5752 | | xmlSchemaPValAttrID(xmlSchemaParserCtxtPtr ctxt, |
5753 | | xmlNodePtr ownerElem, |
5754 | | const xmlChar *name) |
5755 | 0 | { |
5756 | 0 | xmlAttrPtr attr; |
5757 | |
|
5758 | 0 | attr = xmlSchemaGetPropNode(ownerElem, (const char *) name); |
5759 | 0 | if (attr == NULL) |
5760 | 0 | return(0); |
5761 | 0 | return(xmlSchemaPValAttrNodeID(ctxt, attr)); |
5762 | |
|
5763 | 0 | } |
5764 | | |
5765 | | /** |
5766 | | * Get the maxOccurs property |
5767 | | * |
5768 | | * @param ctxt a schema validation context |
5769 | | * @param node a subtree containing XML Schema information |
5770 | | * @param min minimum |
5771 | | * @param max maximum |
5772 | | * @param def default |
5773 | | * @param expected expected |
5774 | | * @returns the default if not found, or the value |
5775 | | */ |
5776 | | static int |
5777 | | xmlGetMaxOccurs(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, |
5778 | | int min, int max, int def, const char *expected) |
5779 | 0 | { |
5780 | 0 | const xmlChar *val, *cur; |
5781 | 0 | int ret = 0; |
5782 | 0 | xmlAttrPtr attr; |
5783 | |
|
5784 | 0 | attr = xmlSchemaGetPropNode(node, "maxOccurs"); |
5785 | 0 | if (attr == NULL) |
5786 | 0 | return (def); |
5787 | 0 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
5788 | 0 | if (val == NULL) |
5789 | 0 | return (def); |
5790 | | |
5791 | 0 | if (xmlStrEqual(val, (const xmlChar *) "unbounded")) { |
5792 | 0 | if (max != UNBOUNDED) { |
5793 | 0 | xmlSchemaPSimpleTypeErr(ctxt, |
5794 | 0 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
5795 | | /* XML_SCHEMAP_INVALID_MINOCCURS, */ |
5796 | 0 | NULL, (xmlNodePtr) attr, NULL, expected, |
5797 | 0 | val, NULL, NULL, NULL); |
5798 | 0 | return (def); |
5799 | 0 | } else |
5800 | 0 | return (UNBOUNDED); /* encoding it with -1 might be another option */ |
5801 | 0 | } |
5802 | | |
5803 | 0 | cur = val; |
5804 | 0 | while (IS_BLANK_CH(*cur)) |
5805 | 0 | cur++; |
5806 | 0 | if (*cur == 0) { |
5807 | 0 | xmlSchemaPSimpleTypeErr(ctxt, |
5808 | 0 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
5809 | | /* XML_SCHEMAP_INVALID_MINOCCURS, */ |
5810 | 0 | NULL, (xmlNodePtr) attr, NULL, expected, |
5811 | 0 | val, NULL, NULL, NULL); |
5812 | 0 | return (def); |
5813 | 0 | } |
5814 | 0 | while ((*cur >= '0') && (*cur <= '9')) { |
5815 | 0 | if (ret > INT_MAX / 10) { |
5816 | 0 | ret = INT_MAX; |
5817 | 0 | } else { |
5818 | 0 | int digit = *cur - '0'; |
5819 | 0 | ret *= 10; |
5820 | 0 | if (ret > INT_MAX - digit) |
5821 | 0 | ret = INT_MAX; |
5822 | 0 | else |
5823 | 0 | ret += digit; |
5824 | 0 | } |
5825 | 0 | cur++; |
5826 | 0 | } |
5827 | 0 | while (IS_BLANK_CH(*cur)) |
5828 | 0 | cur++; |
5829 | | /* |
5830 | | * TODO: Restrict the maximal value to Integer. |
5831 | | */ |
5832 | 0 | if ((*cur != 0) || (ret < min) || ((max != -1) && (ret > max))) { |
5833 | 0 | xmlSchemaPSimpleTypeErr(ctxt, |
5834 | 0 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
5835 | | /* XML_SCHEMAP_INVALID_MINOCCURS, */ |
5836 | 0 | NULL, (xmlNodePtr) attr, NULL, expected, |
5837 | 0 | val, NULL, NULL, NULL); |
5838 | 0 | return (def); |
5839 | 0 | } |
5840 | 0 | return (ret); |
5841 | 0 | } |
5842 | | |
5843 | | /** |
5844 | | * Get the minOccurs property |
5845 | | * |
5846 | | * @param ctxt a schema validation context |
5847 | | * @param node a subtree containing XML Schema information |
5848 | | * @param min minimum |
5849 | | * @param max maximum |
5850 | | * @param def default |
5851 | | * @param expected expected |
5852 | | * @returns the default if not found, or the value |
5853 | | */ |
5854 | | static int |
5855 | | xmlGetMinOccurs(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, |
5856 | | int min, int max, int def, const char *expected) |
5857 | 0 | { |
5858 | 0 | const xmlChar *val, *cur; |
5859 | 0 | int ret = 0; |
5860 | 0 | xmlAttrPtr attr; |
5861 | |
|
5862 | 0 | attr = xmlSchemaGetPropNode(node, "minOccurs"); |
5863 | 0 | if (attr == NULL) |
5864 | 0 | return (def); |
5865 | 0 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
5866 | 0 | if (val == NULL) |
5867 | 0 | return (def); |
5868 | 0 | cur = val; |
5869 | 0 | while (IS_BLANK_CH(*cur)) |
5870 | 0 | cur++; |
5871 | 0 | if (*cur == 0) { |
5872 | 0 | xmlSchemaPSimpleTypeErr(ctxt, |
5873 | 0 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
5874 | | /* XML_SCHEMAP_INVALID_MINOCCURS, */ |
5875 | 0 | NULL, (xmlNodePtr) attr, NULL, expected, |
5876 | 0 | val, NULL, NULL, NULL); |
5877 | 0 | return (def); |
5878 | 0 | } |
5879 | 0 | while ((*cur >= '0') && (*cur <= '9')) { |
5880 | 0 | if (ret > INT_MAX / 10) { |
5881 | 0 | ret = INT_MAX; |
5882 | 0 | } else { |
5883 | 0 | int digit = *cur - '0'; |
5884 | 0 | ret *= 10; |
5885 | 0 | if (ret > INT_MAX - digit) |
5886 | 0 | ret = INT_MAX; |
5887 | 0 | else |
5888 | 0 | ret += digit; |
5889 | 0 | } |
5890 | 0 | cur++; |
5891 | 0 | } |
5892 | 0 | while (IS_BLANK_CH(*cur)) |
5893 | 0 | cur++; |
5894 | | /* |
5895 | | * TODO: Restrict the maximal value to Integer. |
5896 | | */ |
5897 | 0 | if ((*cur != 0) || (ret < min) || ((max != -1) && (ret > max))) { |
5898 | 0 | xmlSchemaPSimpleTypeErr(ctxt, |
5899 | 0 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
5900 | | /* XML_SCHEMAP_INVALID_MINOCCURS, */ |
5901 | 0 | NULL, (xmlNodePtr) attr, NULL, expected, |
5902 | 0 | val, NULL, NULL, NULL); |
5903 | 0 | return (def); |
5904 | 0 | } |
5905 | 0 | return (ret); |
5906 | 0 | } |
5907 | | |
5908 | | /** |
5909 | | * Converts a boolean string value into 1 or 0. |
5910 | | * |
5911 | | * @param ctxt a schema validation context |
5912 | | * @param ownerItem the owner as a schema item |
5913 | | * @param node the node holding the value |
5914 | | * @returns 0 or 1. |
5915 | | */ |
5916 | | static int |
5917 | | xmlSchemaPGetBoolNodeValue(xmlSchemaParserCtxtPtr ctxt, |
5918 | | xmlSchemaBasicItemPtr ownerItem, |
5919 | | xmlNodePtr node) |
5920 | 0 | { |
5921 | 0 | xmlChar *value = NULL; |
5922 | 0 | int res = 0; |
5923 | |
|
5924 | 0 | value = xmlNodeGetContent(node); |
5925 | | /* |
5926 | | * 3.2.2.1 Lexical representation |
5927 | | * An instance of a datatype that is defined as `boolean` |
5928 | | * can have the following legal literals {true, false, 1, 0}. |
5929 | | */ |
5930 | 0 | if (xmlStrEqual(BAD_CAST value, BAD_CAST "true")) |
5931 | 0 | res = 1; |
5932 | 0 | else if (xmlStrEqual(BAD_CAST value, BAD_CAST "false")) |
5933 | 0 | res = 0; |
5934 | 0 | else if (xmlStrEqual(BAD_CAST value, BAD_CAST "1")) |
5935 | 0 | res = 1; |
5936 | 0 | else if (xmlStrEqual(BAD_CAST value, BAD_CAST "0")) |
5937 | 0 | res = 0; |
5938 | 0 | else { |
5939 | 0 | xmlSchemaPSimpleTypeErr(ctxt, |
5940 | 0 | XML_SCHEMAP_INVALID_BOOLEAN, |
5941 | 0 | ownerItem, node, |
5942 | 0 | xmlSchemaGetBuiltInType(XML_SCHEMAS_BOOLEAN), |
5943 | 0 | NULL, BAD_CAST value, |
5944 | 0 | NULL, NULL, NULL); |
5945 | 0 | } |
5946 | 0 | if (value != NULL) |
5947 | 0 | xmlFree(value); |
5948 | 0 | return (res); |
5949 | 0 | } |
5950 | | |
5951 | | /** |
5952 | | * Evaluate if a boolean property is set |
5953 | | * |
5954 | | * @param ctxt a schema validation context |
5955 | | * @param node a subtree containing XML Schema information |
5956 | | * @param name the attribute name |
5957 | | * @param def the default value |
5958 | | * @returns the default if not found, 0 if found to be false, |
5959 | | * 1 if found to be true |
5960 | | */ |
5961 | | static int |
5962 | | xmlGetBooleanProp(xmlSchemaParserCtxtPtr ctxt, |
5963 | | xmlNodePtr node, |
5964 | | const char *name, int def) |
5965 | 0 | { |
5966 | 0 | const xmlChar *val; |
5967 | |
|
5968 | 0 | val = xmlSchemaGetProp(ctxt, node, name); |
5969 | 0 | if (val == NULL) |
5970 | 0 | return (def); |
5971 | | /* |
5972 | | * 3.2.2.1 Lexical representation |
5973 | | * An instance of a datatype that is defined as `boolean` |
5974 | | * can have the following legal literals {true, false, 1, 0}. |
5975 | | */ |
5976 | 0 | if (xmlStrEqual(val, BAD_CAST "true")) |
5977 | 0 | def = 1; |
5978 | 0 | else if (xmlStrEqual(val, BAD_CAST "false")) |
5979 | 0 | def = 0; |
5980 | 0 | else if (xmlStrEqual(val, BAD_CAST "1")) |
5981 | 0 | def = 1; |
5982 | 0 | else if (xmlStrEqual(val, BAD_CAST "0")) |
5983 | 0 | def = 0; |
5984 | 0 | else { |
5985 | 0 | xmlSchemaPSimpleTypeErr(ctxt, |
5986 | 0 | XML_SCHEMAP_INVALID_BOOLEAN, |
5987 | 0 | NULL, |
5988 | 0 | (xmlNodePtr) xmlSchemaGetPropNode(node, name), |
5989 | 0 | xmlSchemaGetBuiltInType(XML_SCHEMAS_BOOLEAN), |
5990 | 0 | NULL, val, NULL, NULL, NULL); |
5991 | 0 | } |
5992 | 0 | return (def); |
5993 | 0 | } |
5994 | | |
5995 | | /************************************************************************ |
5996 | | * * |
5997 | | * Schema extraction from an Infoset * |
5998 | | * * |
5999 | | ************************************************************************/ |
6000 | | static xmlSchemaTypePtr xmlSchemaParseSimpleType(xmlSchemaParserCtxtPtr |
6001 | | ctxt, xmlSchemaPtr schema, |
6002 | | xmlNodePtr node, |
6003 | | int topLevel); |
6004 | | static xmlSchemaTypePtr xmlSchemaParseComplexType(xmlSchemaParserCtxtPtr |
6005 | | ctxt, |
6006 | | xmlSchemaPtr schema, |
6007 | | xmlNodePtr node, |
6008 | | int topLevel); |
6009 | | static xmlSchemaTypePtr xmlSchemaParseRestriction(xmlSchemaParserCtxtPtr |
6010 | | ctxt, |
6011 | | xmlSchemaPtr schema, |
6012 | | xmlNodePtr node, |
6013 | | xmlSchemaTypeType parentType); |
6014 | | static xmlSchemaBasicItemPtr |
6015 | | xmlSchemaParseLocalAttribute(xmlSchemaParserCtxtPtr pctxt, |
6016 | | xmlSchemaPtr schema, |
6017 | | xmlNodePtr node, |
6018 | | xmlSchemaItemListPtr uses, |
6019 | | int parentType); |
6020 | | static xmlSchemaTypePtr xmlSchemaParseList(xmlSchemaParserCtxtPtr ctxt, |
6021 | | xmlSchemaPtr schema, |
6022 | | xmlNodePtr node); |
6023 | | static xmlSchemaWildcardPtr |
6024 | | xmlSchemaParseAnyAttribute(xmlSchemaParserCtxtPtr ctxt, |
6025 | | xmlSchemaPtr schema, xmlNodePtr node); |
6026 | | |
6027 | | /** |
6028 | | * Validates a value against the given built-in type. |
6029 | | * This one is intended to be used internally for validation |
6030 | | * of schema attribute values during parsing of the schema. |
6031 | | * |
6032 | | * @param pctxt a schema parser context |
6033 | | * @param ownerItem the schema object owner if existent |
6034 | | * @param attr the schema attribute node being validated |
6035 | | * @param value the value |
6036 | | * @param type the built-in type to be validated against |
6037 | | * @returns 0 if the value is valid, a positive error code |
6038 | | * number otherwise and -1 in case of an internal or API error. |
6039 | | */ |
6040 | | static int |
6041 | | xmlSchemaPValAttrNodeValue(xmlSchemaParserCtxtPtr pctxt, |
6042 | | xmlSchemaBasicItemPtr ownerItem, |
6043 | | xmlAttrPtr attr, |
6044 | | const xmlChar *value, |
6045 | | xmlSchemaTypePtr type) |
6046 | 0 | { |
6047 | |
|
6048 | 0 | int ret = 0; |
6049 | | |
6050 | | /* |
6051 | | * NOTE: Should we move this to xmlschematypes.c? Hmm, but this |
6052 | | * one is really meant to be used internally, so better not. |
6053 | | */ |
6054 | 0 | if ((pctxt == NULL) || (type == NULL) || (attr == NULL)) |
6055 | 0 | return (-1); |
6056 | 0 | if (type->type != XML_SCHEMA_TYPE_BASIC) { |
6057 | 0 | PERROR_INT("xmlSchemaPValAttrNodeValue", |
6058 | 0 | "the given type is not a built-in type"); |
6059 | 0 | return (-1); |
6060 | 0 | } |
6061 | 0 | switch (type->builtInType) { |
6062 | 0 | case XML_SCHEMAS_NCNAME: |
6063 | 0 | case XML_SCHEMAS_QNAME: |
6064 | 0 | case XML_SCHEMAS_ANYURI: |
6065 | 0 | case XML_SCHEMAS_TOKEN: |
6066 | 0 | case XML_SCHEMAS_LANGUAGE: |
6067 | 0 | ret = xmlSchemaValPredefTypeNode(type, value, NULL, |
6068 | 0 | (xmlNodePtr) attr); |
6069 | 0 | break; |
6070 | 0 | default: { |
6071 | 0 | PERROR_INT("xmlSchemaPValAttrNodeValue", |
6072 | 0 | "validation using the given type is not supported while " |
6073 | 0 | "parsing a schema"); |
6074 | 0 | return (-1); |
6075 | 0 | } |
6076 | 0 | } |
6077 | | /* |
6078 | | * TODO: Should we use the S4S error codes instead? |
6079 | | */ |
6080 | 0 | if (ret < 0) { |
6081 | 0 | PERROR_INT("xmlSchemaPValAttrNodeValue", |
6082 | 0 | "failed to validate a schema attribute value"); |
6083 | 0 | return (-1); |
6084 | 0 | } else if (ret > 0) { |
6085 | 0 | if (WXS_IS_LIST(type)) |
6086 | 0 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2; |
6087 | 0 | else |
6088 | 0 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1; |
6089 | 0 | xmlSchemaPSimpleTypeErr(pctxt, |
6090 | 0 | ret, ownerItem, (xmlNodePtr) attr, |
6091 | 0 | type, NULL, value, NULL, NULL, NULL); |
6092 | 0 | } |
6093 | 0 | return (ret); |
6094 | 0 | } |
6095 | | |
6096 | | /** |
6097 | | * Extracts and validates a value against the given built-in type. |
6098 | | * This one is intended to be used internally for validation |
6099 | | * of schema attribute values during parsing of the schema. |
6100 | | * |
6101 | | * @param ctxt a schema parser context |
6102 | | * @param ownerItem the schema object owner if existent |
6103 | | * @param attr the schema attribute node being validated |
6104 | | * @param type the built-in type to be validated against |
6105 | | * @param value the resulting value if any |
6106 | | * @returns 0 if the value is valid, a positive error code |
6107 | | * number otherwise and -1 in case of an internal or API error. |
6108 | | */ |
6109 | | static int |
6110 | | xmlSchemaPValAttrNode(xmlSchemaParserCtxtPtr ctxt, |
6111 | | xmlSchemaBasicItemPtr ownerItem, |
6112 | | xmlAttrPtr attr, |
6113 | | xmlSchemaTypePtr type, |
6114 | | const xmlChar **value) |
6115 | 0 | { |
6116 | 0 | const xmlChar *val; |
6117 | |
|
6118 | 0 | if ((ctxt == NULL) || (type == NULL) || (attr == NULL)) |
6119 | 0 | return (-1); |
6120 | | |
6121 | 0 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
6122 | 0 | if (value != NULL) |
6123 | 0 | *value = val; |
6124 | |
|
6125 | 0 | return (xmlSchemaPValAttrNodeValue(ctxt, ownerItem, attr, |
6126 | 0 | val, type)); |
6127 | 0 | } |
6128 | | |
6129 | | /** |
6130 | | * Extracts and validates a value against the given built-in type. |
6131 | | * This one is intended to be used internally for validation |
6132 | | * of schema attribute values during parsing of the schema. |
6133 | | * |
6134 | | * @param ctxt a schema parser context |
6135 | | * @param ownerItem the schema object owner if existent |
6136 | | * @param ownerElem the owner element node |
6137 | | * @param name the name of the schema attribute node |
6138 | | * @param type the built-in type to be validated against |
6139 | | * @param value the resulting value if any |
6140 | | * @returns 0 if the value is valid, a positive error code |
6141 | | * number otherwise and -1 in case of an internal or API error. |
6142 | | */ |
6143 | | static int |
6144 | | xmlSchemaPValAttr(xmlSchemaParserCtxtPtr ctxt, |
6145 | | xmlSchemaBasicItemPtr ownerItem, |
6146 | | xmlNodePtr ownerElem, |
6147 | | const char *name, |
6148 | | xmlSchemaTypePtr type, |
6149 | | const xmlChar **value) |
6150 | 0 | { |
6151 | 0 | xmlAttrPtr attr; |
6152 | |
|
6153 | 0 | if ((ctxt == NULL) || (type == NULL)) { |
6154 | 0 | if (value != NULL) |
6155 | 0 | *value = NULL; |
6156 | 0 | return (-1); |
6157 | 0 | } |
6158 | 0 | if (type->type != XML_SCHEMA_TYPE_BASIC) { |
6159 | 0 | if (value != NULL) |
6160 | 0 | *value = NULL; |
6161 | 0 | xmlSchemaPErr(ctxt, ownerElem, |
6162 | 0 | XML_SCHEMAP_INTERNAL, |
6163 | 0 | "Internal error: xmlSchemaPValAttr, the given " |
6164 | 0 | "type '%s' is not a built-in type.\n", |
6165 | 0 | type->name, NULL); |
6166 | 0 | return (-1); |
6167 | 0 | } |
6168 | 0 | attr = xmlSchemaGetPropNode(ownerElem, name); |
6169 | 0 | if (attr == NULL) { |
6170 | 0 | if (value != NULL) |
6171 | 0 | *value = NULL; |
6172 | 0 | return (0); |
6173 | 0 | } |
6174 | 0 | return (xmlSchemaPValAttrNode(ctxt, ownerItem, attr, |
6175 | 0 | type, value)); |
6176 | 0 | } |
6177 | | |
6178 | | static int |
6179 | | xmlSchemaCheckReference(xmlSchemaParserCtxtPtr pctxt, |
6180 | | xmlSchemaPtr schema ATTRIBUTE_UNUSED, |
6181 | | xmlNodePtr node, |
6182 | | xmlAttrPtr attr, |
6183 | | const xmlChar *namespaceName) |
6184 | 0 | { |
6185 | | /* TODO: Pointer comparison instead? */ |
6186 | 0 | if (xmlStrEqual(pctxt->targetNamespace, namespaceName)) |
6187 | 0 | return (0); |
6188 | 0 | if (xmlStrEqual(xmlSchemaNs, namespaceName)) |
6189 | 0 | return (0); |
6190 | | /* |
6191 | | * Check if the referenced namespace was <import>ed. |
6192 | | */ |
6193 | 0 | if (WXS_BUCKET(pctxt)->relations != NULL) { |
6194 | 0 | xmlSchemaSchemaRelationPtr rel; |
6195 | |
|
6196 | 0 | rel = WXS_BUCKET(pctxt)->relations; |
6197 | 0 | do { |
6198 | 0 | if (WXS_IS_BUCKET_IMPMAIN(rel->type) && |
6199 | 0 | xmlStrEqual(namespaceName, rel->importNamespace)) |
6200 | 0 | return (0); |
6201 | 0 | rel = rel->next; |
6202 | 0 | } while (rel != NULL); |
6203 | 0 | } |
6204 | | /* |
6205 | | * No matching <import>ed namespace found. |
6206 | | */ |
6207 | 0 | { |
6208 | 0 | xmlNodePtr n = (attr != NULL) ? (xmlNodePtr) attr : node; |
6209 | |
|
6210 | 0 | if (namespaceName == NULL) |
6211 | 0 | xmlSchemaCustomErr(ACTXT_CAST pctxt, |
6212 | 0 | XML_SCHEMAP_SRC_RESOLVE, n, NULL, |
6213 | 0 | "References from this schema to components in no " |
6214 | 0 | "namespace are not allowed, since not indicated by an " |
6215 | 0 | "import statement", NULL, NULL); |
6216 | 0 | else |
6217 | 0 | xmlSchemaCustomErr(ACTXT_CAST pctxt, |
6218 | 0 | XML_SCHEMAP_SRC_RESOLVE, n, NULL, |
6219 | 0 | "References from this schema to components in the " |
6220 | 0 | "namespace '%s' are not allowed, since not indicated by an " |
6221 | 0 | "import statement", namespaceName, NULL); |
6222 | 0 | } |
6223 | 0 | return (XML_SCHEMAP_SRC_RESOLVE); |
6224 | 0 | } |
6225 | | |
6226 | | /** |
6227 | | * Parses attribute uses and attribute declarations and |
6228 | | * attribute group references. |
6229 | | * |
6230 | | * @param ctxt a schema validation context |
6231 | | * @param schema the schema being built |
6232 | | * @param child a subtree containing XML Schema information |
6233 | | * @param list an item list |
6234 | | * @param parentType the hosting type where the attributes will be anchored |
6235 | | * @param hasRefs set if references were found |
6236 | | */ |
6237 | | static int |
6238 | | xmlSchemaParseLocalAttributes(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
6239 | | xmlNodePtr *child, xmlSchemaItemListPtr *list, |
6240 | | int parentType, int *hasRefs) |
6241 | 0 | { |
6242 | 0 | void *item; |
6243 | |
|
6244 | 0 | while ((IS_SCHEMA((*child), "attribute")) || |
6245 | 0 | (IS_SCHEMA((*child), "attributeGroup"))) { |
6246 | 0 | if (IS_SCHEMA((*child), "attribute")) { |
6247 | 0 | item = xmlSchemaParseLocalAttribute(ctxt, schema, *child, |
6248 | 0 | *list, parentType); |
6249 | 0 | } else { |
6250 | 0 | item = xmlSchemaParseAttributeGroupRef(ctxt, schema, *child); |
6251 | 0 | if ((item != NULL) && (hasRefs != NULL)) |
6252 | 0 | *hasRefs = 1; |
6253 | 0 | } |
6254 | 0 | if (item != NULL) { |
6255 | 0 | if (*list == NULL) { |
6256 | | /* TODO: Customize grow factor. */ |
6257 | 0 | *list = xmlSchemaItemListCreate(); |
6258 | 0 | if (*list == NULL) |
6259 | 0 | return(-1); |
6260 | 0 | } |
6261 | 0 | if (xmlSchemaItemListAddSize(*list, 2, item) == -1) |
6262 | 0 | return(-1); |
6263 | 0 | } |
6264 | 0 | *child = (*child)->next; |
6265 | 0 | } |
6266 | 0 | return (0); |
6267 | 0 | } |
6268 | | |
6269 | | /** |
6270 | | * parse a XML schema Attribute declaration |
6271 | | * *WARNING* this interface is highly subject to change |
6272 | | * |
6273 | | * @param ctxt a schema validation context |
6274 | | * @param node a subtree containing XML Schema information |
6275 | | * @param needed needed |
6276 | | * @returns -1 in case of error, 0 if the declaration is improper and |
6277 | | * 1 in case of success. |
6278 | | */ |
6279 | | static xmlSchemaAnnotPtr |
6280 | | xmlSchemaParseAnnotation(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int needed) |
6281 | 0 | { |
6282 | 0 | xmlSchemaAnnotPtr ret; |
6283 | 0 | xmlNodePtr child = NULL; |
6284 | 0 | xmlAttrPtr attr; |
6285 | 0 | int barked = 0; |
6286 | | |
6287 | | /* |
6288 | | * INFO: S4S completed. |
6289 | | */ |
6290 | | /* |
6291 | | * id = ID |
6292 | | * {any attributes with non-schema namespace . . .}> |
6293 | | * Content: (appinfo | documentation)* |
6294 | | */ |
6295 | 0 | if ((ctxt == NULL) || (node == NULL)) |
6296 | 0 | return (NULL); |
6297 | 0 | if (needed) |
6298 | 0 | ret = xmlSchemaNewAnnot(ctxt, node); |
6299 | 0 | else |
6300 | 0 | ret = NULL; |
6301 | 0 | attr = node->properties; |
6302 | 0 | while (attr != NULL) { |
6303 | 0 | if (((attr->ns == NULL) && |
6304 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "id"))) || |
6305 | 0 | ((attr->ns != NULL) && |
6306 | 0 | xmlStrEqual(attr->ns->href, xmlSchemaNs))) { |
6307 | |
|
6308 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
6309 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
6310 | 0 | } |
6311 | 0 | attr = attr->next; |
6312 | 0 | } |
6313 | 0 | xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id"); |
6314 | | /* |
6315 | | * And now for the children... |
6316 | | */ |
6317 | 0 | child = node->children; |
6318 | 0 | while (child != NULL) { |
6319 | 0 | if (IS_SCHEMA(child, "appinfo")) { |
6320 | | /* TODO: make available the content of "appinfo". */ |
6321 | | /* |
6322 | | * source = anyURI |
6323 | | * {any attributes with non-schema namespace . . .}> |
6324 | | * Content: ({any})* |
6325 | | */ |
6326 | 0 | attr = child->properties; |
6327 | 0 | while (attr != NULL) { |
6328 | 0 | if (((attr->ns == NULL) && |
6329 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "source"))) || |
6330 | 0 | ((attr->ns != NULL) && |
6331 | 0 | xmlStrEqual(attr->ns->href, xmlSchemaNs))) { |
6332 | |
|
6333 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
6334 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
6335 | 0 | } |
6336 | 0 | attr = attr->next; |
6337 | 0 | } |
6338 | 0 | xmlSchemaPValAttr(ctxt, NULL, child, "source", |
6339 | 0 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), NULL); |
6340 | 0 | child = child->next; |
6341 | 0 | } else if (IS_SCHEMA(child, "documentation")) { |
6342 | | /* TODO: make available the content of "documentation". */ |
6343 | | /* |
6344 | | * source = anyURI |
6345 | | * {any attributes with non-schema namespace . . .}> |
6346 | | * Content: ({any})* |
6347 | | */ |
6348 | 0 | attr = child->properties; |
6349 | 0 | while (attr != NULL) { |
6350 | 0 | if (attr->ns == NULL) { |
6351 | 0 | if (!xmlStrEqual(attr->name, BAD_CAST "source")) { |
6352 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
6353 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
6354 | 0 | } |
6355 | 0 | } else { |
6356 | 0 | if (xmlStrEqual(attr->ns->href, xmlSchemaNs) || |
6357 | 0 | (xmlStrEqual(attr->name, BAD_CAST "lang") && |
6358 | 0 | (!xmlStrEqual(attr->ns->href, XML_XML_NAMESPACE)))) { |
6359 | |
|
6360 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
6361 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
6362 | 0 | } |
6363 | 0 | } |
6364 | 0 | attr = attr->next; |
6365 | 0 | } |
6366 | | /* |
6367 | | * Attribute "xml:lang". |
6368 | | */ |
6369 | 0 | attr = xmlSchemaGetPropNodeNs(child, (const char *) XML_XML_NAMESPACE, "lang"); |
6370 | 0 | if (attr != NULL) |
6371 | 0 | xmlSchemaPValAttrNode(ctxt, NULL, attr, |
6372 | 0 | xmlSchemaGetBuiltInType(XML_SCHEMAS_LANGUAGE), NULL); |
6373 | 0 | child = child->next; |
6374 | 0 | } else { |
6375 | 0 | if (!barked) |
6376 | 0 | xmlSchemaPContentErr(ctxt, |
6377 | 0 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
6378 | 0 | NULL, node, child, NULL, "(appinfo | documentation)*"); |
6379 | 0 | barked = 1; |
6380 | 0 | child = child->next; |
6381 | 0 | } |
6382 | 0 | } |
6383 | |
|
6384 | 0 | return (ret); |
6385 | 0 | } |
6386 | | |
6387 | | /** |
6388 | | * parse a XML schema Facet declaration |
6389 | | * *WARNING* this interface is highly subject to change |
6390 | | * |
6391 | | * @param ctxt a schema validation context |
6392 | | * @param schema the schema being built |
6393 | | * @param node a subtree containing XML Schema information |
6394 | | * @returns the new type structure or NULL in case of error |
6395 | | */ |
6396 | | static xmlSchemaFacetPtr |
6397 | | xmlSchemaParseFacet(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
6398 | | xmlNodePtr node) |
6399 | 0 | { |
6400 | 0 | xmlSchemaFacetPtr facet; |
6401 | 0 | xmlNodePtr child = NULL; |
6402 | 0 | const xmlChar *value; |
6403 | |
|
6404 | 0 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
6405 | 0 | return (NULL); |
6406 | | |
6407 | 0 | facet = xmlSchemaNewFacet(); |
6408 | 0 | if (facet == NULL) { |
6409 | 0 | xmlSchemaPErrMemory(ctxt); |
6410 | 0 | return (NULL); |
6411 | 0 | } |
6412 | 0 | facet->node = node; |
6413 | 0 | value = xmlSchemaGetProp(ctxt, node, "value"); |
6414 | 0 | if (value == NULL) { |
6415 | 0 | xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_FACET_NO_VALUE, |
6416 | 0 | "Facet %s has no value\n", node->name, NULL); |
6417 | 0 | xmlSchemaFreeFacet(facet); |
6418 | 0 | return (NULL); |
6419 | 0 | } |
6420 | 0 | if (IS_SCHEMA(node, "minInclusive")) { |
6421 | 0 | facet->type = XML_SCHEMA_FACET_MININCLUSIVE; |
6422 | 0 | } else if (IS_SCHEMA(node, "minExclusive")) { |
6423 | 0 | facet->type = XML_SCHEMA_FACET_MINEXCLUSIVE; |
6424 | 0 | } else if (IS_SCHEMA(node, "maxInclusive")) { |
6425 | 0 | facet->type = XML_SCHEMA_FACET_MAXINCLUSIVE; |
6426 | 0 | } else if (IS_SCHEMA(node, "maxExclusive")) { |
6427 | 0 | facet->type = XML_SCHEMA_FACET_MAXEXCLUSIVE; |
6428 | 0 | } else if (IS_SCHEMA(node, "totalDigits")) { |
6429 | 0 | facet->type = XML_SCHEMA_FACET_TOTALDIGITS; |
6430 | 0 | } else if (IS_SCHEMA(node, "fractionDigits")) { |
6431 | 0 | facet->type = XML_SCHEMA_FACET_FRACTIONDIGITS; |
6432 | 0 | } else if (IS_SCHEMA(node, "pattern")) { |
6433 | 0 | facet->type = XML_SCHEMA_FACET_PATTERN; |
6434 | 0 | } else if (IS_SCHEMA(node, "enumeration")) { |
6435 | 0 | facet->type = XML_SCHEMA_FACET_ENUMERATION; |
6436 | 0 | } else if (IS_SCHEMA(node, "whiteSpace")) { |
6437 | 0 | facet->type = XML_SCHEMA_FACET_WHITESPACE; |
6438 | 0 | } else if (IS_SCHEMA(node, "length")) { |
6439 | 0 | facet->type = XML_SCHEMA_FACET_LENGTH; |
6440 | 0 | } else if (IS_SCHEMA(node, "maxLength")) { |
6441 | 0 | facet->type = XML_SCHEMA_FACET_MAXLENGTH; |
6442 | 0 | } else if (IS_SCHEMA(node, "minLength")) { |
6443 | 0 | facet->type = XML_SCHEMA_FACET_MINLENGTH; |
6444 | 0 | } else { |
6445 | 0 | xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_UNKNOWN_FACET_TYPE, |
6446 | 0 | "Unknown facet type %s\n", node->name, NULL); |
6447 | 0 | xmlSchemaFreeFacet(facet); |
6448 | 0 | return (NULL); |
6449 | 0 | } |
6450 | 0 | xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id"); |
6451 | 0 | facet->value = value; |
6452 | 0 | if ((facet->type != XML_SCHEMA_FACET_PATTERN) && |
6453 | 0 | (facet->type != XML_SCHEMA_FACET_ENUMERATION)) { |
6454 | 0 | const xmlChar *fixed; |
6455 | |
|
6456 | 0 | fixed = xmlSchemaGetProp(ctxt, node, "fixed"); |
6457 | 0 | if (fixed != NULL) { |
6458 | 0 | if (xmlStrEqual(fixed, BAD_CAST "true")) |
6459 | 0 | facet->fixed = 1; |
6460 | 0 | } |
6461 | 0 | } |
6462 | 0 | child = node->children; |
6463 | |
|
6464 | 0 | if (IS_SCHEMA(child, "annotation")) { |
6465 | 0 | facet->annot = xmlSchemaParseAnnotation(ctxt, child, 1); |
6466 | 0 | child = child->next; |
6467 | 0 | } |
6468 | 0 | if (child != NULL) { |
6469 | 0 | xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_UNKNOWN_FACET_CHILD, |
6470 | 0 | "Facet %s has unexpected child content\n", |
6471 | 0 | node->name, NULL); |
6472 | 0 | } |
6473 | 0 | return (facet); |
6474 | 0 | } |
6475 | | |
6476 | | /** |
6477 | | * Parses the attribute "processContents" and "namespace" |
6478 | | * of a xsd:anyAttribute and xsd:any. |
6479 | | * *WARNING* this interface is highly subject to change |
6480 | | * |
6481 | | * @param ctxt a schema parser context |
6482 | | * @param schema unused |
6483 | | * @param wildc the wildcard, already created |
6484 | | * @param node a subtree containing XML Schema information |
6485 | | * @returns 0 if everything goes fine, a positive error code |
6486 | | * if something is not valid and -1 if an internal error occurs. |
6487 | | */ |
6488 | | static int |
6489 | | xmlSchemaParseWildcardNs(xmlSchemaParserCtxtPtr ctxt, |
6490 | | xmlSchemaPtr schema ATTRIBUTE_UNUSED, |
6491 | | xmlSchemaWildcardPtr wildc, |
6492 | | xmlNodePtr node) |
6493 | 0 | { |
6494 | 0 | const xmlChar *pc, *ns, *dictnsItem; |
6495 | 0 | int ret = 0; |
6496 | 0 | xmlChar *nsItem; |
6497 | 0 | xmlSchemaWildcardNsPtr tmp, lastNs = NULL; |
6498 | 0 | xmlAttrPtr attr; |
6499 | |
|
6500 | 0 | pc = xmlSchemaGetProp(ctxt, node, "processContents"); |
6501 | 0 | if ((pc == NULL) |
6502 | 0 | || (xmlStrEqual(pc, (const xmlChar *) "strict"))) { |
6503 | 0 | wildc->processContents = XML_SCHEMAS_ANY_STRICT; |
6504 | 0 | } else if (xmlStrEqual(pc, (const xmlChar *) "skip")) { |
6505 | 0 | wildc->processContents = XML_SCHEMAS_ANY_SKIP; |
6506 | 0 | } else if (xmlStrEqual(pc, (const xmlChar *) "lax")) { |
6507 | 0 | wildc->processContents = XML_SCHEMAS_ANY_LAX; |
6508 | 0 | } else { |
6509 | 0 | xmlSchemaPSimpleTypeErr(ctxt, |
6510 | 0 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
6511 | 0 | NULL, node, |
6512 | 0 | NULL, "(strict | skip | lax)", pc, |
6513 | 0 | NULL, NULL, NULL); |
6514 | 0 | wildc->processContents = XML_SCHEMAS_ANY_STRICT; |
6515 | 0 | ret = XML_SCHEMAP_S4S_ATTR_INVALID_VALUE; |
6516 | 0 | } |
6517 | | /* |
6518 | | * Build the namespace constraints. |
6519 | | */ |
6520 | 0 | attr = xmlSchemaGetPropNode(node, "namespace"); |
6521 | 0 | ns = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
6522 | 0 | if (ns == NULL) |
6523 | 0 | return (-1); |
6524 | 0 | if ((attr == NULL) || (xmlStrEqual(ns, BAD_CAST "##any"))) |
6525 | 0 | wildc->any = 1; |
6526 | 0 | else if (xmlStrEqual(ns, BAD_CAST "##other")) { |
6527 | 0 | wildc->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt); |
6528 | 0 | if (wildc->negNsSet == NULL) { |
6529 | 0 | return (-1); |
6530 | 0 | } |
6531 | 0 | wildc->negNsSet->value = ctxt->targetNamespace; |
6532 | 0 | } else { |
6533 | 0 | const xmlChar *end, *cur; |
6534 | |
|
6535 | 0 | cur = ns; |
6536 | 0 | do { |
6537 | 0 | while (IS_BLANK_CH(*cur)) |
6538 | 0 | cur++; |
6539 | 0 | end = cur; |
6540 | 0 | while ((*end != 0) && (!(IS_BLANK_CH(*end)))) |
6541 | 0 | end++; |
6542 | 0 | if (end == cur) |
6543 | 0 | break; |
6544 | 0 | nsItem = xmlStrndup(cur, end - cur); |
6545 | 0 | if ((xmlStrEqual(nsItem, BAD_CAST "##other")) || |
6546 | 0 | (xmlStrEqual(nsItem, BAD_CAST "##any"))) { |
6547 | 0 | xmlSchemaPSimpleTypeErr(ctxt, |
6548 | 0 | XML_SCHEMAP_WILDCARD_INVALID_NS_MEMBER, |
6549 | 0 | NULL, (xmlNodePtr) attr, |
6550 | 0 | NULL, |
6551 | 0 | "((##any | ##other) | List of (xs:anyURI | " |
6552 | 0 | "(##targetNamespace | ##local)))", |
6553 | 0 | nsItem, NULL, NULL, NULL); |
6554 | 0 | ret = XML_SCHEMAP_WILDCARD_INVALID_NS_MEMBER; |
6555 | 0 | } else { |
6556 | 0 | if (xmlStrEqual(nsItem, BAD_CAST "##targetNamespace")) { |
6557 | 0 | dictnsItem = ctxt->targetNamespace; |
6558 | 0 | } else if (xmlStrEqual(nsItem, BAD_CAST "##local")) { |
6559 | 0 | dictnsItem = NULL; |
6560 | 0 | } else { |
6561 | | /* |
6562 | | * Validate the item (anyURI). |
6563 | | */ |
6564 | 0 | xmlSchemaPValAttrNodeValue(ctxt, NULL, attr, |
6565 | 0 | nsItem, xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI)); |
6566 | 0 | dictnsItem = xmlDictLookup(ctxt->dict, nsItem, -1); |
6567 | 0 | } |
6568 | | /* |
6569 | | * Avoid duplicate namespaces. |
6570 | | */ |
6571 | 0 | tmp = wildc->nsSet; |
6572 | 0 | while (tmp != NULL) { |
6573 | 0 | if (dictnsItem == tmp->value) |
6574 | 0 | break; |
6575 | 0 | tmp = tmp->next; |
6576 | 0 | } |
6577 | 0 | if (tmp == NULL) { |
6578 | 0 | tmp = xmlSchemaNewWildcardNsConstraint(ctxt); |
6579 | 0 | if (tmp == NULL) { |
6580 | 0 | xmlFree(nsItem); |
6581 | 0 | return (-1); |
6582 | 0 | } |
6583 | 0 | tmp->value = dictnsItem; |
6584 | 0 | tmp->next = NULL; |
6585 | 0 | if (wildc->nsSet == NULL) |
6586 | 0 | wildc->nsSet = tmp; |
6587 | 0 | else if (lastNs != NULL) |
6588 | 0 | lastNs->next = tmp; |
6589 | 0 | lastNs = tmp; |
6590 | 0 | } |
6591 | |
|
6592 | 0 | } |
6593 | 0 | xmlFree(nsItem); |
6594 | 0 | cur = end; |
6595 | 0 | } while (*cur != 0); |
6596 | 0 | } |
6597 | 0 | return (ret); |
6598 | 0 | } |
6599 | | |
6600 | | static int |
6601 | | xmlSchemaPCheckParticleCorrect_2(xmlSchemaParserCtxtPtr ctxt, |
6602 | | xmlSchemaParticlePtr item ATTRIBUTE_UNUSED, |
6603 | | xmlNodePtr node, |
6604 | | int minOccurs, |
6605 | 0 | int maxOccurs) { |
6606 | |
|
6607 | 0 | if ((maxOccurs == 0) && ( minOccurs == 0)) |
6608 | 0 | return (0); |
6609 | 0 | if (maxOccurs != UNBOUNDED) { |
6610 | | /* |
6611 | | * TODO: Maybe we should better not create the particle, |
6612 | | * if min/max is invalid, since it could confuse the build of the |
6613 | | * content model. |
6614 | | */ |
6615 | | /* |
6616 | | * 3.9.6 Schema Component Constraint: Particle Correct |
6617 | | * |
6618 | | */ |
6619 | 0 | if (maxOccurs < 1) { |
6620 | | /* |
6621 | | * 2.2 {max occurs} must be greater than or equal to 1. |
6622 | | */ |
6623 | 0 | xmlSchemaPCustomAttrErr(ctxt, |
6624 | 0 | XML_SCHEMAP_P_PROPS_CORRECT_2_2, |
6625 | 0 | NULL, NULL, |
6626 | 0 | xmlSchemaGetPropNode(node, "maxOccurs"), |
6627 | 0 | "The value must be greater than or equal to 1"); |
6628 | 0 | return (XML_SCHEMAP_P_PROPS_CORRECT_2_2); |
6629 | 0 | } else if (minOccurs > maxOccurs) { |
6630 | | /* |
6631 | | * 2.1 {min occurs} must not be greater than {max occurs}. |
6632 | | */ |
6633 | 0 | xmlSchemaPCustomAttrErr(ctxt, |
6634 | 0 | XML_SCHEMAP_P_PROPS_CORRECT_2_1, |
6635 | 0 | NULL, NULL, |
6636 | 0 | xmlSchemaGetPropNode(node, "minOccurs"), |
6637 | 0 | "The value must not be greater than the value of 'maxOccurs'"); |
6638 | 0 | return (XML_SCHEMAP_P_PROPS_CORRECT_2_1); |
6639 | 0 | } |
6640 | 0 | } |
6641 | 0 | return (0); |
6642 | 0 | } |
6643 | | |
6644 | | /** |
6645 | | * Parsea a XML schema `<any>` element. A particle and wildcard |
6646 | | * will be created (except if minOccurs==maxOccurs==0, in this case |
6647 | | * nothing will be created). |
6648 | | * *WARNING* this interface is highly subject to change |
6649 | | * |
6650 | | * @param ctxt a schema validation context |
6651 | | * @param schema the schema being built |
6652 | | * @param node a subtree containing XML Schema information |
6653 | | * @returns the particle or NULL in case of error or if minOccurs==maxOccurs==0 |
6654 | | */ |
6655 | | static xmlSchemaParticlePtr |
6656 | | xmlSchemaParseAny(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
6657 | | xmlNodePtr node) |
6658 | 0 | { |
6659 | 0 | xmlSchemaParticlePtr particle; |
6660 | 0 | xmlNodePtr child = NULL; |
6661 | 0 | xmlSchemaWildcardPtr wild; |
6662 | 0 | int min, max; |
6663 | 0 | xmlAttrPtr attr; |
6664 | 0 | xmlSchemaAnnotPtr annot = NULL; |
6665 | |
|
6666 | 0 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
6667 | 0 | return (NULL); |
6668 | | /* |
6669 | | * Check for illegal attributes. |
6670 | | */ |
6671 | 0 | attr = node->properties; |
6672 | 0 | while (attr != NULL) { |
6673 | 0 | if (attr->ns == NULL) { |
6674 | 0 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
6675 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "minOccurs")) && |
6676 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "maxOccurs")) && |
6677 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "namespace")) && |
6678 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "processContents"))) { |
6679 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
6680 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
6681 | 0 | } |
6682 | 0 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
6683 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
6684 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
6685 | 0 | } |
6686 | 0 | attr = attr->next; |
6687 | 0 | } |
6688 | 0 | xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id"); |
6689 | | /* |
6690 | | * minOccurs/maxOccurs. |
6691 | | */ |
6692 | 0 | max = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1, |
6693 | 0 | "(xs:nonNegativeInteger | unbounded)"); |
6694 | 0 | min = xmlGetMinOccurs(ctxt, node, 0, -1, 1, |
6695 | 0 | "xs:nonNegativeInteger"); |
6696 | 0 | xmlSchemaPCheckParticleCorrect_2(ctxt, NULL, node, min, max); |
6697 | | /* |
6698 | | * Create & parse the wildcard. |
6699 | | */ |
6700 | 0 | wild = xmlSchemaAddWildcard(ctxt, schema, XML_SCHEMA_TYPE_ANY, node); |
6701 | 0 | if (wild == NULL) |
6702 | 0 | return (NULL); |
6703 | 0 | xmlSchemaParseWildcardNs(ctxt, schema, wild, node); |
6704 | | /* |
6705 | | * And now for the children... |
6706 | | */ |
6707 | 0 | child = node->children; |
6708 | 0 | if (IS_SCHEMA(child, "annotation")) { |
6709 | 0 | annot = xmlSchemaParseAnnotation(ctxt, child, 1); |
6710 | 0 | child = child->next; |
6711 | 0 | } |
6712 | 0 | if (child != NULL) { |
6713 | 0 | xmlSchemaPContentErr(ctxt, |
6714 | 0 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
6715 | 0 | NULL, node, child, |
6716 | 0 | NULL, "(annotation?)"); |
6717 | 0 | } |
6718 | | /* |
6719 | | * No component if minOccurs==maxOccurs==0. |
6720 | | */ |
6721 | 0 | if ((min == 0) && (max == 0)) { |
6722 | | /* Don't free the wildcard, since it's already on the list. */ |
6723 | 0 | return (NULL); |
6724 | 0 | } |
6725 | | /* |
6726 | | * Create the particle. |
6727 | | */ |
6728 | 0 | particle = xmlSchemaAddParticle(ctxt, node, min, max); |
6729 | 0 | if (particle == NULL) |
6730 | 0 | return (NULL); |
6731 | 0 | particle->annot = annot; |
6732 | 0 | particle->children = (xmlSchemaTreeItemPtr) wild; |
6733 | |
|
6734 | 0 | return (particle); |
6735 | 0 | } |
6736 | | |
6737 | | /** |
6738 | | * parse a XML schema Notation declaration |
6739 | | * |
6740 | | * @param ctxt a schema validation context |
6741 | | * @param schema the schema being built |
6742 | | * @param node a subtree containing XML Schema information |
6743 | | * @returns the new structure or NULL in case of error |
6744 | | */ |
6745 | | static xmlSchemaNotationPtr |
6746 | | xmlSchemaParseNotation(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
6747 | | xmlNodePtr node) |
6748 | 0 | { |
6749 | 0 | const xmlChar *name; |
6750 | 0 | xmlSchemaNotationPtr ret; |
6751 | 0 | xmlNodePtr child = NULL; |
6752 | |
|
6753 | 0 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
6754 | 0 | return (NULL); |
6755 | 0 | name = xmlSchemaGetProp(ctxt, node, "name"); |
6756 | 0 | if (name == NULL) { |
6757 | 0 | xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_NOTATION_NO_NAME, |
6758 | 0 | "Notation has no name\n", NULL, NULL); |
6759 | 0 | return (NULL); |
6760 | 0 | } |
6761 | 0 | ret = xmlSchemaAddNotation(ctxt, schema, name, |
6762 | 0 | ctxt->targetNamespace, node); |
6763 | 0 | if (ret == NULL) |
6764 | 0 | return (NULL); |
6765 | 0 | xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id"); |
6766 | |
|
6767 | 0 | child = node->children; |
6768 | 0 | if (IS_SCHEMA(child, "annotation")) { |
6769 | 0 | ret->annot = xmlSchemaParseAnnotation(ctxt, child, 1); |
6770 | 0 | child = child->next; |
6771 | 0 | } |
6772 | 0 | if (child != NULL) { |
6773 | 0 | xmlSchemaPContentErr(ctxt, |
6774 | 0 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
6775 | 0 | NULL, node, child, |
6776 | 0 | NULL, "(annotation?)"); |
6777 | 0 | } |
6778 | |
|
6779 | 0 | return (ret); |
6780 | 0 | } |
6781 | | |
6782 | | /** |
6783 | | * parse a XML schema AnyAttribute declaration |
6784 | | * *WARNING* this interface is highly subject to change |
6785 | | * |
6786 | | * @param ctxt a schema validation context |
6787 | | * @param schema the schema being built |
6788 | | * @param node a subtree containing XML Schema information |
6789 | | * @returns a wildcard or NULL. |
6790 | | */ |
6791 | | static xmlSchemaWildcardPtr |
6792 | | xmlSchemaParseAnyAttribute(xmlSchemaParserCtxtPtr ctxt, |
6793 | | xmlSchemaPtr schema, xmlNodePtr node) |
6794 | 0 | { |
6795 | 0 | xmlSchemaWildcardPtr ret; |
6796 | 0 | xmlNodePtr child = NULL; |
6797 | 0 | xmlAttrPtr attr; |
6798 | |
|
6799 | 0 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
6800 | 0 | return (NULL); |
6801 | | |
6802 | 0 | ret = xmlSchemaAddWildcard(ctxt, schema, XML_SCHEMA_TYPE_ANY_ATTRIBUTE, |
6803 | 0 | node); |
6804 | 0 | if (ret == NULL) { |
6805 | 0 | return (NULL); |
6806 | 0 | } |
6807 | | /* |
6808 | | * Check for illegal attributes. |
6809 | | */ |
6810 | 0 | attr = node->properties; |
6811 | 0 | while (attr != NULL) { |
6812 | 0 | if (attr->ns == NULL) { |
6813 | 0 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
6814 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "namespace")) && |
6815 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "processContents"))) { |
6816 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
6817 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
6818 | 0 | } |
6819 | 0 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
6820 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
6821 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
6822 | 0 | } |
6823 | 0 | attr = attr->next; |
6824 | 0 | } |
6825 | 0 | xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id"); |
6826 | | /* |
6827 | | * Parse the namespace list. |
6828 | | */ |
6829 | 0 | if (xmlSchemaParseWildcardNs(ctxt, schema, ret, node) != 0) |
6830 | 0 | return (NULL); |
6831 | | /* |
6832 | | * And now for the children... |
6833 | | */ |
6834 | 0 | child = node->children; |
6835 | 0 | if (IS_SCHEMA(child, "annotation")) { |
6836 | 0 | ret->annot = xmlSchemaParseAnnotation(ctxt, child, 1); |
6837 | 0 | child = child->next; |
6838 | 0 | } |
6839 | 0 | if (child != NULL) { |
6840 | 0 | xmlSchemaPContentErr(ctxt, |
6841 | 0 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
6842 | 0 | NULL, node, child, |
6843 | 0 | NULL, "(annotation?)"); |
6844 | 0 | } |
6845 | |
|
6846 | 0 | return (ret); |
6847 | 0 | } |
6848 | | |
6849 | | |
6850 | | /** |
6851 | | * parse a XML schema Attribute declaration |
6852 | | * *WARNING* this interface is highly subject to change |
6853 | | * |
6854 | | * @param pctxt a schema validation context |
6855 | | * @param schema the schema being built |
6856 | | * @param node a subtree containing XML Schema information |
6857 | | * @param uses attribute uses list |
6858 | | * @param parentType parent type |
6859 | | * @returns the attribute declaration. |
6860 | | */ |
6861 | | static xmlSchemaBasicItemPtr |
6862 | | xmlSchemaParseLocalAttribute(xmlSchemaParserCtxtPtr pctxt, |
6863 | | xmlSchemaPtr schema, |
6864 | | xmlNodePtr node, |
6865 | | xmlSchemaItemListPtr uses, |
6866 | | int parentType) |
6867 | 0 | { |
6868 | 0 | const xmlChar *attrValue, *name = NULL, *ns = NULL; |
6869 | 0 | xmlSchemaAttributeUsePtr use = NULL; |
6870 | 0 | xmlNodePtr child = NULL; |
6871 | 0 | xmlAttrPtr attr; |
6872 | 0 | const xmlChar *tmpNs = NULL, *tmpName = NULL, *defValue = NULL; |
6873 | 0 | int isRef = 0, occurs = XML_SCHEMAS_ATTR_USE_OPTIONAL; |
6874 | 0 | int nberrors, hasForm = 0, defValueType = 0; |
6875 | |
|
6876 | 0 | #define WXS_ATTR_DEF_VAL_DEFAULT 1 |
6877 | 0 | #define WXS_ATTR_DEF_VAL_FIXED 2 |
6878 | | |
6879 | | /* |
6880 | | * 3.2.3 Constraints on XML Representations of Attribute Declarations |
6881 | | */ |
6882 | |
|
6883 | 0 | if ((pctxt == NULL) || (schema == NULL) || (node == NULL)) |
6884 | 0 | return (NULL); |
6885 | 0 | attr = xmlSchemaGetPropNode(node, "ref"); |
6886 | 0 | if (attr != NULL) { |
6887 | 0 | if (xmlSchemaPValAttrNodeQName(pctxt, schema, |
6888 | 0 | NULL, attr, &tmpNs, &tmpName) != 0) { |
6889 | 0 | return (NULL); |
6890 | 0 | } |
6891 | 0 | if (xmlSchemaCheckReference(pctxt, schema, node, attr, tmpNs) != 0) |
6892 | 0 | return(NULL); |
6893 | 0 | isRef = 1; |
6894 | 0 | } |
6895 | 0 | nberrors = pctxt->nberrors; |
6896 | | /* |
6897 | | * Check for illegal attributes. |
6898 | | */ |
6899 | 0 | attr = node->properties; |
6900 | 0 | while (attr != NULL) { |
6901 | 0 | if (attr->ns == NULL) { |
6902 | 0 | if (isRef) { |
6903 | 0 | if (xmlStrEqual(attr->name, BAD_CAST "id")) { |
6904 | 0 | xmlSchemaPValAttrNodeID(pctxt, attr); |
6905 | 0 | goto attr_next; |
6906 | 0 | } else if (xmlStrEqual(attr->name, BAD_CAST "ref")) { |
6907 | 0 | goto attr_next; |
6908 | 0 | } |
6909 | 0 | } else { |
6910 | 0 | if (xmlStrEqual(attr->name, BAD_CAST "name")) { |
6911 | 0 | goto attr_next; |
6912 | 0 | } else if (xmlStrEqual(attr->name, BAD_CAST "id")) { |
6913 | 0 | xmlSchemaPValAttrNodeID(pctxt, attr); |
6914 | 0 | goto attr_next; |
6915 | 0 | } else if (xmlStrEqual(attr->name, BAD_CAST "type")) { |
6916 | 0 | xmlSchemaPValAttrNodeQName(pctxt, schema, NULL, |
6917 | 0 | attr, &tmpNs, &tmpName); |
6918 | 0 | goto attr_next; |
6919 | 0 | } else if (xmlStrEqual(attr->name, BAD_CAST "form")) { |
6920 | | /* |
6921 | | * Evaluate the target namespace |
6922 | | */ |
6923 | 0 | hasForm = 1; |
6924 | 0 | attrValue = xmlSchemaGetNodeContent(pctxt, |
6925 | 0 | (xmlNodePtr) attr); |
6926 | 0 | if (xmlStrEqual(attrValue, BAD_CAST "qualified")) { |
6927 | 0 | ns = pctxt->targetNamespace; |
6928 | 0 | } else if (!xmlStrEqual(attrValue, BAD_CAST "unqualified")) |
6929 | 0 | { |
6930 | 0 | xmlSchemaPSimpleTypeErr(pctxt, |
6931 | 0 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
6932 | 0 | NULL, (xmlNodePtr) attr, |
6933 | 0 | NULL, "(qualified | unqualified)", |
6934 | 0 | attrValue, NULL, NULL, NULL); |
6935 | 0 | } |
6936 | 0 | goto attr_next; |
6937 | 0 | } |
6938 | 0 | } |
6939 | 0 | if (xmlStrEqual(attr->name, BAD_CAST "use")) { |
6940 | |
|
6941 | 0 | attrValue = xmlSchemaGetNodeContent(pctxt, (xmlNodePtr) attr); |
6942 | | /* TODO: Maybe we need to normalize the value beforehand. */ |
6943 | 0 | if (xmlStrEqual(attrValue, BAD_CAST "optional")) |
6944 | 0 | occurs = XML_SCHEMAS_ATTR_USE_OPTIONAL; |
6945 | 0 | else if (xmlStrEqual(attrValue, BAD_CAST "prohibited")) |
6946 | 0 | occurs = XML_SCHEMAS_ATTR_USE_PROHIBITED; |
6947 | 0 | else if (xmlStrEqual(attrValue, BAD_CAST "required")) |
6948 | 0 | occurs = XML_SCHEMAS_ATTR_USE_REQUIRED; |
6949 | 0 | else { |
6950 | 0 | xmlSchemaPSimpleTypeErr(pctxt, |
6951 | 0 | XML_SCHEMAP_INVALID_ATTR_USE, |
6952 | 0 | NULL, (xmlNodePtr) attr, |
6953 | 0 | NULL, "(optional | prohibited | required)", |
6954 | 0 | attrValue, NULL, NULL, NULL); |
6955 | 0 | } |
6956 | 0 | goto attr_next; |
6957 | 0 | } else if (xmlStrEqual(attr->name, BAD_CAST "default")) { |
6958 | | /* |
6959 | | * 3.2.3 : 1 |
6960 | | * default and fixed must not both be present. |
6961 | | */ |
6962 | 0 | if (defValue) { |
6963 | 0 | xmlSchemaPMutualExclAttrErr(pctxt, |
6964 | 0 | XML_SCHEMAP_SRC_ATTRIBUTE_1, |
6965 | 0 | NULL, attr, "default", "fixed"); |
6966 | 0 | } else { |
6967 | 0 | defValue = xmlSchemaGetNodeContent(pctxt, (xmlNodePtr) attr); |
6968 | 0 | defValueType = WXS_ATTR_DEF_VAL_DEFAULT; |
6969 | 0 | } |
6970 | 0 | goto attr_next; |
6971 | 0 | } else if (xmlStrEqual(attr->name, BAD_CAST "fixed")) { |
6972 | | /* |
6973 | | * 3.2.3 : 1 |
6974 | | * default and fixed must not both be present. |
6975 | | */ |
6976 | 0 | if (defValue) { |
6977 | 0 | xmlSchemaPMutualExclAttrErr(pctxt, |
6978 | 0 | XML_SCHEMAP_SRC_ATTRIBUTE_1, |
6979 | 0 | NULL, attr, "default", "fixed"); |
6980 | 0 | } else { |
6981 | 0 | defValue = xmlSchemaGetNodeContent(pctxt, (xmlNodePtr) attr); |
6982 | 0 | defValueType = WXS_ATTR_DEF_VAL_FIXED; |
6983 | 0 | } |
6984 | 0 | goto attr_next; |
6985 | 0 | } |
6986 | 0 | } else if (! xmlStrEqual(attr->ns->href, xmlSchemaNs)) |
6987 | 0 | goto attr_next; |
6988 | | |
6989 | 0 | xmlSchemaPIllegalAttrErr(pctxt, |
6990 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
6991 | |
|
6992 | 0 | attr_next: |
6993 | 0 | attr = attr->next; |
6994 | 0 | } |
6995 | | /* |
6996 | | * 3.2.3 : 2 |
6997 | | * If default and use are both present, use must have |
6998 | | * the actual value optional. |
6999 | | */ |
7000 | 0 | if ((defValueType == WXS_ATTR_DEF_VAL_DEFAULT) && |
7001 | 0 | (occurs != XML_SCHEMAS_ATTR_USE_OPTIONAL)) { |
7002 | 0 | xmlSchemaPSimpleTypeErr(pctxt, |
7003 | 0 | XML_SCHEMAP_SRC_ATTRIBUTE_2, |
7004 | 0 | NULL, node, NULL, |
7005 | 0 | "(optional | prohibited | required)", NULL, |
7006 | 0 | "The value of the attribute 'use' must be 'optional' " |
7007 | 0 | "if the attribute 'default' is present", |
7008 | 0 | NULL, NULL); |
7009 | 0 | } |
7010 | | /* |
7011 | | * We want correct attributes. |
7012 | | */ |
7013 | 0 | if (nberrors != pctxt->nberrors) |
7014 | 0 | return(NULL); |
7015 | 0 | if (! isRef) { |
7016 | 0 | xmlSchemaAttributePtr attrDecl; |
7017 | | |
7018 | | /* TODO: move XML_SCHEMAS_QUALIF_ATTR to the parser. */ |
7019 | 0 | if ((! hasForm) && (schema->flags & XML_SCHEMAS_QUALIF_ATTR)) |
7020 | 0 | ns = pctxt->targetNamespace; |
7021 | | /* |
7022 | | * 3.2.6 Schema Component Constraint: xsi: Not Allowed |
7023 | | * TODO: Move this to the component layer. |
7024 | | */ |
7025 | 0 | if (xmlStrEqual(ns, xmlSchemaInstanceNs)) { |
7026 | 0 | xmlSchemaCustomErr(ACTXT_CAST pctxt, |
7027 | 0 | XML_SCHEMAP_NO_XSI, |
7028 | 0 | node, NULL, |
7029 | 0 | "The target namespace must not match '%s'", |
7030 | 0 | xmlSchemaInstanceNs, NULL); |
7031 | 0 | } |
7032 | 0 | attr = xmlSchemaGetPropNode(node, "name"); |
7033 | 0 | if (attr == NULL) { |
7034 | 0 | xmlSchemaPMissingAttrErr(pctxt, XML_SCHEMAP_S4S_ATTR_MISSING, |
7035 | 0 | NULL, node, "name", NULL); |
7036 | 0 | return (NULL); |
7037 | 0 | } |
7038 | 0 | if (xmlSchemaPValAttrNode(pctxt, NULL, attr, |
7039 | 0 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) { |
7040 | 0 | return (NULL); |
7041 | 0 | } |
7042 | | /* |
7043 | | * 3.2.6 Schema Component Constraint: xmlns Not Allowed |
7044 | | * TODO: Move this to the component layer. |
7045 | | */ |
7046 | 0 | if (xmlStrEqual(name, BAD_CAST "xmlns")) { |
7047 | 0 | xmlSchemaPSimpleTypeErr(pctxt, |
7048 | 0 | XML_SCHEMAP_NO_XMLNS, |
7049 | 0 | NULL, (xmlNodePtr) attr, |
7050 | 0 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), NULL, NULL, |
7051 | 0 | "The value of the attribute must not match 'xmlns'", |
7052 | 0 | NULL, NULL); |
7053 | 0 | return (NULL); |
7054 | 0 | } |
7055 | 0 | if (occurs == XML_SCHEMAS_ATTR_USE_PROHIBITED) |
7056 | 0 | goto check_children; |
7057 | | /* |
7058 | | * Create the attribute use component. |
7059 | | */ |
7060 | 0 | use = xmlSchemaAddAttributeUse(pctxt, node); |
7061 | 0 | if (use == NULL) |
7062 | 0 | return(NULL); |
7063 | 0 | use->occurs = occurs; |
7064 | | /* |
7065 | | * Create the attribute declaration. |
7066 | | */ |
7067 | 0 | attrDecl = xmlSchemaAddAttribute(pctxt, schema, name, ns, node, 0); |
7068 | 0 | if (attrDecl == NULL) |
7069 | 0 | return (NULL); |
7070 | 0 | if (tmpName != NULL) { |
7071 | 0 | attrDecl->typeName = tmpName; |
7072 | 0 | attrDecl->typeNs = tmpNs; |
7073 | 0 | } |
7074 | 0 | use->attrDecl = attrDecl; |
7075 | | /* |
7076 | | * Value constraint. |
7077 | | */ |
7078 | 0 | if (defValue != NULL) { |
7079 | 0 | attrDecl->defValue = defValue; |
7080 | 0 | if (defValueType == WXS_ATTR_DEF_VAL_FIXED) |
7081 | 0 | attrDecl->flags |= XML_SCHEMAS_ATTR_FIXED; |
7082 | 0 | } |
7083 | 0 | } else if (occurs != XML_SCHEMAS_ATTR_USE_PROHIBITED) { |
7084 | 0 | xmlSchemaQNameRefPtr ref; |
7085 | | |
7086 | | /* |
7087 | | * Create the attribute use component. |
7088 | | */ |
7089 | 0 | use = xmlSchemaAddAttributeUse(pctxt, node); |
7090 | 0 | if (use == NULL) |
7091 | 0 | return(NULL); |
7092 | | /* |
7093 | | * We need to resolve the reference at later stage. |
7094 | | */ |
7095 | 0 | WXS_ADD_PENDING(pctxt, use); |
7096 | 0 | use->occurs = occurs; |
7097 | | /* |
7098 | | * Create a QName reference to the attribute declaration. |
7099 | | */ |
7100 | 0 | ref = xmlSchemaNewQNameRef(pctxt, XML_SCHEMA_TYPE_ATTRIBUTE, |
7101 | 0 | tmpName, tmpNs); |
7102 | 0 | if (ref == NULL) |
7103 | 0 | return(NULL); |
7104 | | /* |
7105 | | * Assign the reference. This will be substituted for the |
7106 | | * referenced attribute declaration when the QName is resolved. |
7107 | | */ |
7108 | 0 | use->attrDecl = WXS_ATTR_CAST ref; |
7109 | | /* |
7110 | | * Value constraint. |
7111 | | */ |
7112 | 0 | if (defValue != NULL) |
7113 | 0 | use->defValue = defValue; |
7114 | 0 | if (defValueType == WXS_ATTR_DEF_VAL_FIXED) |
7115 | 0 | use->flags |= XML_SCHEMA_ATTR_USE_FIXED; |
7116 | 0 | } |
7117 | | |
7118 | 0 | check_children: |
7119 | | /* |
7120 | | * And now for the children... |
7121 | | */ |
7122 | 0 | child = node->children; |
7123 | 0 | if (occurs == XML_SCHEMAS_ATTR_USE_PROHIBITED) { |
7124 | 0 | xmlSchemaAttributeUseProhibPtr prohib; |
7125 | |
|
7126 | 0 | if (IS_SCHEMA(child, "annotation")) { |
7127 | 0 | xmlSchemaParseAnnotation(pctxt, child, 0); |
7128 | 0 | child = child->next; |
7129 | 0 | } |
7130 | 0 | if (child != NULL) { |
7131 | 0 | xmlSchemaPContentErr(pctxt, |
7132 | 0 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
7133 | 0 | NULL, node, child, NULL, |
7134 | 0 | "(annotation?)"); |
7135 | 0 | } |
7136 | | /* |
7137 | | * Check for pointlessness of attribute prohibitions. |
7138 | | */ |
7139 | 0 | if (parentType == XML_SCHEMA_TYPE_ATTRIBUTEGROUP) { |
7140 | 0 | xmlSchemaCustomWarning(ACTXT_CAST pctxt, |
7141 | 0 | XML_SCHEMAP_WARN_ATTR_POINTLESS_PROH, |
7142 | 0 | node, NULL, |
7143 | 0 | "Skipping attribute use prohibition, since it is " |
7144 | 0 | "pointless inside an <attributeGroup>", |
7145 | 0 | NULL, NULL, NULL); |
7146 | 0 | return(NULL); |
7147 | 0 | } else if (parentType == XML_SCHEMA_TYPE_EXTENSION) { |
7148 | 0 | xmlSchemaCustomWarning(ACTXT_CAST pctxt, |
7149 | 0 | XML_SCHEMAP_WARN_ATTR_POINTLESS_PROH, |
7150 | 0 | node, NULL, |
7151 | 0 | "Skipping attribute use prohibition, since it is " |
7152 | 0 | "pointless when extending a type", |
7153 | 0 | NULL, NULL, NULL); |
7154 | 0 | return(NULL); |
7155 | 0 | } |
7156 | 0 | if (! isRef) { |
7157 | 0 | tmpName = name; |
7158 | 0 | tmpNs = ns; |
7159 | 0 | } |
7160 | | /* |
7161 | | * Check for duplicate attribute prohibitions. |
7162 | | */ |
7163 | 0 | if (uses) { |
7164 | 0 | int i; |
7165 | |
|
7166 | 0 | for (i = 0; i < uses->nbItems; i++) { |
7167 | 0 | use = uses->items[i]; |
7168 | 0 | if ((use->type == XML_SCHEMA_EXTRA_ATTR_USE_PROHIB) && |
7169 | 0 | (tmpName == (WXS_ATTR_PROHIB_CAST use)->name) && |
7170 | 0 | (tmpNs == (WXS_ATTR_PROHIB_CAST use)->targetNamespace)) |
7171 | 0 | { |
7172 | 0 | xmlChar *str = NULL; |
7173 | |
|
7174 | 0 | xmlSchemaCustomWarning(ACTXT_CAST pctxt, |
7175 | 0 | XML_SCHEMAP_WARN_ATTR_POINTLESS_PROH, |
7176 | 0 | node, NULL, |
7177 | 0 | "Skipping duplicate attribute use prohibition '%s'", |
7178 | 0 | xmlSchemaFormatQName(&str, tmpNs, tmpName), |
7179 | 0 | NULL, NULL); |
7180 | 0 | FREE_AND_NULL(str) |
7181 | 0 | return(NULL); |
7182 | 0 | } |
7183 | 0 | } |
7184 | 0 | } |
7185 | | /* |
7186 | | * Create the attribute prohibition helper component. |
7187 | | */ |
7188 | 0 | prohib = xmlSchemaAddAttributeUseProhib(pctxt); |
7189 | 0 | if (prohib == NULL) |
7190 | 0 | return(NULL); |
7191 | 0 | prohib->node = node; |
7192 | 0 | prohib->name = tmpName; |
7193 | 0 | prohib->targetNamespace = tmpNs; |
7194 | 0 | if (isRef) { |
7195 | | /* |
7196 | | * We need at least to resolve to the attribute declaration. |
7197 | | */ |
7198 | 0 | WXS_ADD_PENDING(pctxt, prohib); |
7199 | 0 | } |
7200 | 0 | return(WXS_BASIC_CAST prohib); |
7201 | 0 | } else { |
7202 | 0 | if (IS_SCHEMA(child, "annotation")) { |
7203 | | /* |
7204 | | * TODO: Should this go into the attr decl? |
7205 | | */ |
7206 | 0 | use->annot = xmlSchemaParseAnnotation(pctxt, child, 1); |
7207 | 0 | child = child->next; |
7208 | 0 | } |
7209 | 0 | if (isRef) { |
7210 | 0 | if (child != NULL) { |
7211 | 0 | if (IS_SCHEMA(child, "simpleType")) |
7212 | | /* |
7213 | | * 3.2.3 : 3.2 |
7214 | | * If ref is present, then all of <simpleType>, |
7215 | | * form and type must be absent. |
7216 | | */ |
7217 | 0 | xmlSchemaPContentErr(pctxt, |
7218 | 0 | XML_SCHEMAP_SRC_ATTRIBUTE_3_2, |
7219 | 0 | NULL, node, child, NULL, |
7220 | 0 | "(annotation?)"); |
7221 | 0 | else |
7222 | 0 | xmlSchemaPContentErr(pctxt, |
7223 | 0 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
7224 | 0 | NULL, node, child, NULL, |
7225 | 0 | "(annotation?)"); |
7226 | 0 | } |
7227 | 0 | } else { |
7228 | 0 | if (IS_SCHEMA(child, "simpleType")) { |
7229 | 0 | if (WXS_ATTRUSE_DECL(use)->typeName != NULL) { |
7230 | | /* |
7231 | | * 3.2.3 : 4 |
7232 | | * type and <simpleType> must not both be present. |
7233 | | */ |
7234 | 0 | xmlSchemaPContentErr(pctxt, XML_SCHEMAP_SRC_ATTRIBUTE_4, |
7235 | 0 | NULL, node, child, |
7236 | 0 | "The attribute 'type' and the <simpleType> child " |
7237 | 0 | "are mutually exclusive", NULL); |
7238 | 0 | } else |
7239 | 0 | WXS_ATTRUSE_TYPEDEF(use) = |
7240 | 0 | xmlSchemaParseSimpleType(pctxt, schema, child, 0); |
7241 | 0 | child = child->next; |
7242 | 0 | } |
7243 | 0 | if (child != NULL) |
7244 | 0 | xmlSchemaPContentErr(pctxt, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
7245 | 0 | NULL, node, child, NULL, |
7246 | 0 | "(annotation?, simpleType?)"); |
7247 | 0 | } |
7248 | 0 | } |
7249 | 0 | return (WXS_BASIC_CAST use); |
7250 | 0 | } |
7251 | | |
7252 | | |
7253 | | static xmlSchemaAttributePtr |
7254 | | xmlSchemaParseGlobalAttribute(xmlSchemaParserCtxtPtr pctxt, |
7255 | | xmlSchemaPtr schema, |
7256 | | xmlNodePtr node) |
7257 | 0 | { |
7258 | 0 | const xmlChar *attrValue; |
7259 | 0 | xmlSchemaAttributePtr ret; |
7260 | 0 | xmlNodePtr child = NULL; |
7261 | 0 | xmlAttrPtr attr; |
7262 | | |
7263 | | /* |
7264 | | * Note that the w3c spec assumes the schema to be validated with schema |
7265 | | * for schemas beforehand. |
7266 | | * |
7267 | | * 3.2.3 Constraints on XML Representations of Attribute Declarations |
7268 | | */ |
7269 | 0 | if ((pctxt == NULL) || (schema == NULL) || (node == NULL)) |
7270 | 0 | return (NULL); |
7271 | | /* |
7272 | | * 3.2.3 : 3.1 |
7273 | | * One of ref or name must be present, but not both |
7274 | | */ |
7275 | 0 | attr = xmlSchemaGetPropNode(node, "name"); |
7276 | 0 | if (attr == NULL) { |
7277 | 0 | xmlSchemaPMissingAttrErr(pctxt, XML_SCHEMAP_S4S_ATTR_MISSING, |
7278 | 0 | NULL, node, "name", NULL); |
7279 | 0 | return (NULL); |
7280 | 0 | } |
7281 | 0 | if (xmlSchemaPValAttrNode(pctxt, NULL, attr, |
7282 | 0 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &attrValue) != 0) { |
7283 | 0 | return (NULL); |
7284 | 0 | } |
7285 | | /* |
7286 | | * 3.2.6 Schema Component Constraint: xmlns Not Allowed |
7287 | | * TODO: Move this to the component layer. |
7288 | | */ |
7289 | 0 | if (xmlStrEqual(attrValue, BAD_CAST "xmlns")) { |
7290 | 0 | xmlSchemaPSimpleTypeErr(pctxt, |
7291 | 0 | XML_SCHEMAP_NO_XMLNS, |
7292 | 0 | NULL, (xmlNodePtr) attr, |
7293 | 0 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), NULL, NULL, |
7294 | 0 | "The value of the attribute must not match 'xmlns'", |
7295 | 0 | NULL, NULL); |
7296 | 0 | return (NULL); |
7297 | 0 | } |
7298 | | /* |
7299 | | * 3.2.6 Schema Component Constraint: xsi: Not Allowed |
7300 | | * TODO: Move this to the component layer. |
7301 | | * Or better leave it here and add it to the component layer |
7302 | | * if we have a schema construction API. |
7303 | | */ |
7304 | 0 | if (xmlStrEqual(pctxt->targetNamespace, xmlSchemaInstanceNs)) { |
7305 | 0 | xmlSchemaCustomErr(ACTXT_CAST pctxt, |
7306 | 0 | XML_SCHEMAP_NO_XSI, node, NULL, |
7307 | 0 | "The target namespace must not match '%s'", |
7308 | 0 | xmlSchemaInstanceNs, NULL); |
7309 | 0 | } |
7310 | |
|
7311 | 0 | ret = xmlSchemaAddAttribute(pctxt, schema, attrValue, |
7312 | 0 | pctxt->targetNamespace, node, 1); |
7313 | 0 | if (ret == NULL) |
7314 | 0 | return (NULL); |
7315 | 0 | ret->flags |= XML_SCHEMAS_ATTR_GLOBAL; |
7316 | | |
7317 | | /* |
7318 | | * Check for illegal attributes. |
7319 | | */ |
7320 | 0 | attr = node->properties; |
7321 | 0 | while (attr != NULL) { |
7322 | 0 | if (attr->ns == NULL) { |
7323 | 0 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
7324 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "default")) && |
7325 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "fixed")) && |
7326 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "name")) && |
7327 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "type"))) |
7328 | 0 | { |
7329 | 0 | xmlSchemaPIllegalAttrErr(pctxt, |
7330 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
7331 | 0 | } |
7332 | 0 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
7333 | 0 | xmlSchemaPIllegalAttrErr(pctxt, |
7334 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
7335 | 0 | } |
7336 | 0 | attr = attr->next; |
7337 | 0 | } |
7338 | 0 | xmlSchemaPValAttrQName(pctxt, schema, NULL, |
7339 | 0 | node, "type", &ret->typeNs, &ret->typeName); |
7340 | |
|
7341 | 0 | xmlSchemaPValAttrID(pctxt, node, BAD_CAST "id"); |
7342 | | /* |
7343 | | * Attribute "fixed". |
7344 | | */ |
7345 | 0 | ret->defValue = xmlSchemaGetProp(pctxt, node, "fixed"); |
7346 | 0 | if (ret->defValue != NULL) |
7347 | 0 | ret->flags |= XML_SCHEMAS_ATTR_FIXED; |
7348 | | /* |
7349 | | * Attribute "default". |
7350 | | */ |
7351 | 0 | attr = xmlSchemaGetPropNode(node, "default"); |
7352 | 0 | if (attr != NULL) { |
7353 | | /* |
7354 | | * 3.2.3 : 1 |
7355 | | * default and fixed must not both be present. |
7356 | | */ |
7357 | 0 | if (ret->flags & XML_SCHEMAS_ATTR_FIXED) { |
7358 | 0 | xmlSchemaPMutualExclAttrErr(pctxt, XML_SCHEMAP_SRC_ATTRIBUTE_1, |
7359 | 0 | WXS_BASIC_CAST ret, attr, "default", "fixed"); |
7360 | 0 | } else |
7361 | 0 | ret->defValue = xmlSchemaGetNodeContent(pctxt, (xmlNodePtr) attr); |
7362 | 0 | } |
7363 | | /* |
7364 | | * And now for the children... |
7365 | | */ |
7366 | 0 | child = node->children; |
7367 | 0 | if (IS_SCHEMA(child, "annotation")) { |
7368 | 0 | ret->annot = xmlSchemaParseAnnotation(pctxt, child, 1); |
7369 | 0 | child = child->next; |
7370 | 0 | } |
7371 | 0 | if (IS_SCHEMA(child, "simpleType")) { |
7372 | 0 | if (ret->typeName != NULL) { |
7373 | | /* |
7374 | | * 3.2.3 : 4 |
7375 | | * type and <simpleType> must not both be present. |
7376 | | */ |
7377 | 0 | xmlSchemaPContentErr(pctxt, XML_SCHEMAP_SRC_ATTRIBUTE_4, |
7378 | 0 | NULL, node, child, |
7379 | 0 | "The attribute 'type' and the <simpleType> child " |
7380 | 0 | "are mutually exclusive", NULL); |
7381 | 0 | } else |
7382 | 0 | ret->subtypes = xmlSchemaParseSimpleType(pctxt, schema, child, 0); |
7383 | 0 | child = child->next; |
7384 | 0 | } |
7385 | 0 | if (child != NULL) |
7386 | 0 | xmlSchemaPContentErr(pctxt, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
7387 | 0 | NULL, node, child, NULL, |
7388 | 0 | "(annotation?, simpleType?)"); |
7389 | |
|
7390 | 0 | return (ret); |
7391 | 0 | } |
7392 | | |
7393 | | /** |
7394 | | * Parse an attribute group definition reference. |
7395 | | * Note that a reference to an attribute group does not |
7396 | | * correspond to any component at all. |
7397 | | * *WARNING* this interface is highly subject to change |
7398 | | * |
7399 | | * @param pctxt a schema validation context |
7400 | | * @param schema the schema being built |
7401 | | * @param node a subtree containing XML Schema information |
7402 | | * @returns the attribute group or NULL in case of error. |
7403 | | */ |
7404 | | static xmlSchemaQNameRefPtr |
7405 | | xmlSchemaParseAttributeGroupRef(xmlSchemaParserCtxtPtr pctxt, |
7406 | | xmlSchemaPtr schema, |
7407 | | xmlNodePtr node) |
7408 | 0 | { |
7409 | 0 | xmlSchemaQNameRefPtr ret; |
7410 | 0 | xmlNodePtr child = NULL; |
7411 | 0 | xmlAttrPtr attr; |
7412 | 0 | const xmlChar *refNs = NULL, *ref = NULL; |
7413 | |
|
7414 | 0 | if ((pctxt == NULL) || (schema == NULL) || (node == NULL)) |
7415 | 0 | return (NULL); |
7416 | | |
7417 | 0 | attr = xmlSchemaGetPropNode(node, "ref"); |
7418 | 0 | if (attr == NULL) { |
7419 | 0 | xmlSchemaPMissingAttrErr(pctxt, |
7420 | 0 | XML_SCHEMAP_S4S_ATTR_MISSING, |
7421 | 0 | NULL, node, "ref", NULL); |
7422 | 0 | return (NULL); |
7423 | 0 | } |
7424 | 0 | xmlSchemaPValAttrNodeQName(pctxt, schema, |
7425 | 0 | NULL, attr, &refNs, &ref); |
7426 | 0 | if (xmlSchemaCheckReference(pctxt, schema, node, attr, refNs) != 0) |
7427 | 0 | return(NULL); |
7428 | | |
7429 | | /* |
7430 | | * Check for illegal attributes. |
7431 | | */ |
7432 | 0 | attr = node->properties; |
7433 | 0 | while (attr != NULL) { |
7434 | 0 | if (attr->ns == NULL) { |
7435 | 0 | if ((!xmlStrEqual(attr->name, BAD_CAST "ref")) && |
7436 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "id"))) |
7437 | 0 | { |
7438 | 0 | xmlSchemaPIllegalAttrErr(pctxt, |
7439 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
7440 | 0 | } |
7441 | 0 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
7442 | 0 | xmlSchemaPIllegalAttrErr(pctxt, |
7443 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
7444 | 0 | } |
7445 | 0 | attr = attr->next; |
7446 | 0 | } |
7447 | | /* Attribute ID */ |
7448 | 0 | xmlSchemaPValAttrID(pctxt, node, BAD_CAST "id"); |
7449 | | |
7450 | | /* |
7451 | | * And now for the children... |
7452 | | */ |
7453 | 0 | child = node->children; |
7454 | 0 | if (IS_SCHEMA(child, "annotation")) { |
7455 | | /* |
7456 | | * TODO: We do not have a place to store the annotation, do we? |
7457 | | */ |
7458 | 0 | xmlSchemaParseAnnotation(pctxt, child, 0); |
7459 | 0 | child = child->next; |
7460 | 0 | } |
7461 | 0 | if (child != NULL) { |
7462 | 0 | xmlSchemaPContentErr(pctxt, |
7463 | 0 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
7464 | 0 | NULL, node, child, NULL, |
7465 | 0 | "(annotation?)"); |
7466 | 0 | } |
7467 | | |
7468 | | /* |
7469 | | * Handle attribute group redefinitions. |
7470 | | */ |
7471 | 0 | if (pctxt->isRedefine && pctxt->redef && |
7472 | 0 | (pctxt->redef->item->type == |
7473 | 0 | XML_SCHEMA_TYPE_ATTRIBUTEGROUP) && |
7474 | 0 | (ref == pctxt->redef->refName) && |
7475 | 0 | (refNs == pctxt->redef->refTargetNs)) |
7476 | 0 | { |
7477 | | /* |
7478 | | * SPEC src-redefine: |
7479 | | * (7.1) "If it has an <attributeGroup> among its contents |
7480 | | * the `actual value` of whose ref [attribute] is the same |
7481 | | * as the `actual value` of its own name attribute plus |
7482 | | * target namespace, then it must have exactly one such group." |
7483 | | */ |
7484 | 0 | if (pctxt->redefCounter != 0) { |
7485 | 0 | xmlChar *str = NULL; |
7486 | |
|
7487 | 0 | xmlSchemaCustomErr(ACTXT_CAST pctxt, |
7488 | 0 | XML_SCHEMAP_SRC_REDEFINE, node, NULL, |
7489 | 0 | "The redefining attribute group definition " |
7490 | 0 | "'%s' must not contain more than one " |
7491 | 0 | "reference to the redefined definition", |
7492 | 0 | xmlSchemaFormatQName(&str, refNs, ref), NULL); |
7493 | 0 | FREE_AND_NULL(str); |
7494 | 0 | return(NULL); |
7495 | 0 | } |
7496 | 0 | pctxt->redefCounter++; |
7497 | | /* |
7498 | | * URGENT TODO: How to ensure that the reference will not be |
7499 | | * handled by the normal component resolution mechanism? |
7500 | | */ |
7501 | 0 | ret = xmlSchemaNewQNameRef(pctxt, |
7502 | 0 | XML_SCHEMA_TYPE_ATTRIBUTEGROUP, ref, refNs); |
7503 | 0 | if (ret == NULL) |
7504 | 0 | return(NULL); |
7505 | 0 | ret->node = node; |
7506 | 0 | pctxt->redef->reference = WXS_BASIC_CAST ret; |
7507 | 0 | } else { |
7508 | | /* |
7509 | | * Create a QName-reference helper component. We will substitute this |
7510 | | * component for the attribute uses of the referenced attribute group |
7511 | | * definition. |
7512 | | */ |
7513 | 0 | ret = xmlSchemaNewQNameRef(pctxt, |
7514 | 0 | XML_SCHEMA_TYPE_ATTRIBUTEGROUP, ref, refNs); |
7515 | 0 | if (ret == NULL) |
7516 | 0 | return(NULL); |
7517 | 0 | ret->node = node; |
7518 | | /* Add to pending items, to be able to resolve the reference. */ |
7519 | 0 | WXS_ADD_PENDING(pctxt, ret); |
7520 | 0 | } |
7521 | 0 | return (ret); |
7522 | 0 | } |
7523 | | |
7524 | | /** |
7525 | | * parse a XML schema Attribute Group declaration |
7526 | | * *WARNING* this interface is highly subject to change |
7527 | | * |
7528 | | * @param pctxt a schema validation context |
7529 | | * @param schema the schema being built |
7530 | | * @param node a subtree containing XML Schema information |
7531 | | * @returns the attribute group definition or NULL in case of error. |
7532 | | */ |
7533 | | static xmlSchemaAttributeGroupPtr |
7534 | | xmlSchemaParseAttributeGroupDefinition(xmlSchemaParserCtxtPtr pctxt, |
7535 | | xmlSchemaPtr schema, |
7536 | | xmlNodePtr node) |
7537 | 0 | { |
7538 | 0 | const xmlChar *name; |
7539 | 0 | xmlSchemaAttributeGroupPtr ret; |
7540 | 0 | xmlNodePtr child = NULL; |
7541 | 0 | xmlAttrPtr attr; |
7542 | 0 | int hasRefs = 0; |
7543 | 0 | int res; |
7544 | |
|
7545 | 0 | if ((pctxt == NULL) || (schema == NULL) || (node == NULL)) |
7546 | 0 | return (NULL); |
7547 | | |
7548 | 0 | attr = xmlSchemaGetPropNode(node, "name"); |
7549 | 0 | if (attr == NULL) { |
7550 | 0 | xmlSchemaPMissingAttrErr(pctxt, |
7551 | 0 | XML_SCHEMAP_S4S_ATTR_MISSING, |
7552 | 0 | NULL, node, "name", NULL); |
7553 | 0 | return (NULL); |
7554 | 0 | } |
7555 | | /* |
7556 | | * The name is crucial, exit if invalid. |
7557 | | */ |
7558 | 0 | if (xmlSchemaPValAttrNode(pctxt, |
7559 | 0 | NULL, attr, |
7560 | 0 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) { |
7561 | 0 | return (NULL); |
7562 | 0 | } |
7563 | 0 | ret = xmlSchemaAddAttributeGroupDefinition(pctxt, schema, |
7564 | 0 | name, pctxt->targetNamespace, node); |
7565 | 0 | if (ret == NULL) |
7566 | 0 | return (NULL); |
7567 | | /* |
7568 | | * Check for illegal attributes. |
7569 | | */ |
7570 | 0 | attr = node->properties; |
7571 | 0 | while (attr != NULL) { |
7572 | 0 | if (attr->ns == NULL) { |
7573 | 0 | if ((!xmlStrEqual(attr->name, BAD_CAST "name")) && |
7574 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "id"))) |
7575 | 0 | { |
7576 | 0 | xmlSchemaPIllegalAttrErr(pctxt, |
7577 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
7578 | 0 | } |
7579 | 0 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
7580 | 0 | xmlSchemaPIllegalAttrErr(pctxt, |
7581 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
7582 | 0 | } |
7583 | 0 | attr = attr->next; |
7584 | 0 | } |
7585 | | /* Attribute ID */ |
7586 | 0 | xmlSchemaPValAttrID(pctxt, node, BAD_CAST "id"); |
7587 | | /* |
7588 | | * And now for the children... |
7589 | | */ |
7590 | 0 | child = node->children; |
7591 | 0 | if (IS_SCHEMA(child, "annotation")) { |
7592 | 0 | ret->annot = xmlSchemaParseAnnotation(pctxt, child, 1); |
7593 | 0 | child = child->next; |
7594 | 0 | } |
7595 | | /* |
7596 | | * Parse contained attribute decls/refs. |
7597 | | */ |
7598 | 0 | res = xmlSchemaParseLocalAttributes(pctxt, schema, &child, |
7599 | 0 | (xmlSchemaItemListPtr *) &(ret->attrUses), |
7600 | 0 | XML_SCHEMA_TYPE_ATTRIBUTEGROUP, &hasRefs); |
7601 | 0 | if (hasRefs) |
7602 | 0 | ret->flags |= XML_SCHEMAS_ATTRGROUP_HAS_REFS; |
7603 | 0 | if (res == -1) |
7604 | 0 | return(NULL); |
7605 | | /* |
7606 | | * Parse the attribute wildcard. |
7607 | | */ |
7608 | 0 | if (IS_SCHEMA(child, "anyAttribute")) { |
7609 | 0 | ret->attributeWildcard = xmlSchemaParseAnyAttribute(pctxt, |
7610 | 0 | schema, child); |
7611 | 0 | child = child->next; |
7612 | 0 | } |
7613 | 0 | if (child != NULL) { |
7614 | 0 | xmlSchemaPContentErr(pctxt, |
7615 | 0 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
7616 | 0 | NULL, node, child, NULL, |
7617 | 0 | "(annotation?, ((attribute | attributeGroup)*, anyAttribute?))"); |
7618 | 0 | } |
7619 | 0 | return (ret); |
7620 | 0 | } |
7621 | | |
7622 | | /** |
7623 | | * @param value the value |
7624 | | * @param flags the flags to be modified |
7625 | | * @param flagQualified the specific flag for "qualified" |
7626 | | * @returns 0 if the value is valid, 1 otherwise. |
7627 | | */ |
7628 | | static int |
7629 | | xmlSchemaPValAttrFormDefault(const xmlChar *value, |
7630 | | int *flags, |
7631 | | int flagQualified) |
7632 | 0 | { |
7633 | 0 | if (xmlStrEqual(value, BAD_CAST "qualified")) { |
7634 | 0 | if ((*flags & flagQualified) == 0) |
7635 | 0 | *flags |= flagQualified; |
7636 | 0 | } else if (!xmlStrEqual(value, BAD_CAST "unqualified")) |
7637 | 0 | return (1); |
7638 | | |
7639 | 0 | return (0); |
7640 | 0 | } |
7641 | | |
7642 | | /** |
7643 | | * Validates the value of the attribute "final" and "block". The value |
7644 | | * is converted into the specified flag values and returned in `flags`. |
7645 | | * |
7646 | | * @param value the value |
7647 | | * @param flags the flags to be modified |
7648 | | * @param flagAll the specific flag for "\#all" |
7649 | | * @param flagExtension the specific flag for "extension" |
7650 | | * @param flagRestriction the specific flag for "restriction" |
7651 | | * @param flagSubstitution the specific flag for "substitution" |
7652 | | * @param flagList the specific flag for "list" |
7653 | | * @param flagUnion the specific flag for "union" |
7654 | | * @returns 0 if the value is valid, 1 otherwise. |
7655 | | */ |
7656 | | |
7657 | | static int |
7658 | | xmlSchemaPValAttrBlockFinal(const xmlChar *value, |
7659 | | int *flags, |
7660 | | int flagAll, |
7661 | | int flagExtension, |
7662 | | int flagRestriction, |
7663 | | int flagSubstitution, |
7664 | | int flagList, |
7665 | | int flagUnion) |
7666 | 0 | { |
7667 | 0 | int ret = 0; |
7668 | | |
7669 | | /* |
7670 | | * TODO: This does not check for duplicate entries. |
7671 | | */ |
7672 | 0 | if ((flags == NULL) || (value == NULL)) |
7673 | 0 | return (-1); |
7674 | 0 | if (value[0] == 0) |
7675 | 0 | return (0); |
7676 | 0 | if (xmlStrEqual(value, BAD_CAST "#all")) { |
7677 | 0 | if (flagAll != -1) |
7678 | 0 | *flags |= flagAll; |
7679 | 0 | else { |
7680 | 0 | if (flagExtension != -1) |
7681 | 0 | *flags |= flagExtension; |
7682 | 0 | if (flagRestriction != -1) |
7683 | 0 | *flags |= flagRestriction; |
7684 | 0 | if (flagSubstitution != -1) |
7685 | 0 | *flags |= flagSubstitution; |
7686 | 0 | if (flagList != -1) |
7687 | 0 | *flags |= flagList; |
7688 | 0 | if (flagUnion != -1) |
7689 | 0 | *flags |= flagUnion; |
7690 | 0 | } |
7691 | 0 | } else { |
7692 | 0 | const xmlChar *end, *cur = value; |
7693 | 0 | xmlChar *item; |
7694 | |
|
7695 | 0 | do { |
7696 | 0 | while (IS_BLANK_CH(*cur)) |
7697 | 0 | cur++; |
7698 | 0 | end = cur; |
7699 | 0 | while ((*end != 0) && (!(IS_BLANK_CH(*end)))) |
7700 | 0 | end++; |
7701 | 0 | if (end == cur) |
7702 | 0 | break; |
7703 | 0 | item = xmlStrndup(cur, end - cur); |
7704 | 0 | if (xmlStrEqual(item, BAD_CAST "extension")) { |
7705 | 0 | if (flagExtension != -1) { |
7706 | 0 | if ((*flags & flagExtension) == 0) |
7707 | 0 | *flags |= flagExtension; |
7708 | 0 | } else |
7709 | 0 | ret = 1; |
7710 | 0 | } else if (xmlStrEqual(item, BAD_CAST "restriction")) { |
7711 | 0 | if (flagRestriction != -1) { |
7712 | 0 | if ((*flags & flagRestriction) == 0) |
7713 | 0 | *flags |= flagRestriction; |
7714 | 0 | } else |
7715 | 0 | ret = 1; |
7716 | 0 | } else if (xmlStrEqual(item, BAD_CAST "substitution")) { |
7717 | 0 | if (flagSubstitution != -1) { |
7718 | 0 | if ((*flags & flagSubstitution) == 0) |
7719 | 0 | *flags |= flagSubstitution; |
7720 | 0 | } else |
7721 | 0 | ret = 1; |
7722 | 0 | } else if (xmlStrEqual(item, BAD_CAST "list")) { |
7723 | 0 | if (flagList != -1) { |
7724 | 0 | if ((*flags & flagList) == 0) |
7725 | 0 | *flags |= flagList; |
7726 | 0 | } else |
7727 | 0 | ret = 1; |
7728 | 0 | } else if (xmlStrEqual(item, BAD_CAST "union")) { |
7729 | 0 | if (flagUnion != -1) { |
7730 | 0 | if ((*flags & flagUnion) == 0) |
7731 | 0 | *flags |= flagUnion; |
7732 | 0 | } else |
7733 | 0 | ret = 1; |
7734 | 0 | } else |
7735 | 0 | ret = 1; |
7736 | 0 | if (item != NULL) |
7737 | 0 | xmlFree(item); |
7738 | 0 | cur = end; |
7739 | 0 | } while ((ret == 0) && (*cur != 0)); |
7740 | 0 | } |
7741 | | |
7742 | 0 | return (ret); |
7743 | 0 | } |
7744 | | |
7745 | | static int |
7746 | | xmlSchemaCheckCSelectorXPath(xmlSchemaParserCtxtPtr ctxt, |
7747 | | xmlSchemaIDCPtr idc, |
7748 | | xmlSchemaIDCSelectPtr selector, |
7749 | | xmlAttrPtr attr, |
7750 | | int isField) |
7751 | 0 | { |
7752 | 0 | xmlNodePtr node; |
7753 | | |
7754 | | /* |
7755 | | * c-selector-xpath: |
7756 | | * Schema Component Constraint: Selector Value OK |
7757 | | * |
7758 | | * TODO: 1 The {selector} must be a valid XPath expression, as defined |
7759 | | * in [XPath]. |
7760 | | */ |
7761 | 0 | if (selector == NULL) { |
7762 | 0 | xmlSchemaPErr(ctxt, idc->node, |
7763 | 0 | XML_SCHEMAP_INTERNAL, |
7764 | 0 | "Internal error: xmlSchemaCheckCSelectorXPath, " |
7765 | 0 | "the selector is not specified.\n", NULL, NULL); |
7766 | 0 | return (-1); |
7767 | 0 | } |
7768 | 0 | if (attr == NULL) |
7769 | 0 | node = idc->node; |
7770 | 0 | else |
7771 | 0 | node = (xmlNodePtr) attr; |
7772 | 0 | if (selector->xpath == NULL) { |
7773 | 0 | xmlSchemaPCustomErr(ctxt, |
7774 | | /* TODO: Adjust error code. */ |
7775 | 0 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
7776 | 0 | NULL, node, |
7777 | 0 | "The XPath expression of the selector is not valid", NULL); |
7778 | 0 | return (XML_SCHEMAP_S4S_ATTR_INVALID_VALUE); |
7779 | 0 | } else { |
7780 | 0 | const xmlChar **nsArray = NULL; |
7781 | 0 | xmlNsPtr *nsList = NULL; |
7782 | | /* |
7783 | | * Compile the XPath expression. |
7784 | | */ |
7785 | | /* |
7786 | | * TODO: We need the array of in-scope namespaces for compilation. |
7787 | | * TODO: Call xmlPatterncompile with different options for selector/ |
7788 | | * field. |
7789 | | */ |
7790 | 0 | if (attr == NULL) |
7791 | 0 | nsList = NULL; |
7792 | 0 | else |
7793 | 0 | nsList = xmlGetNsList(attr->doc, attr->parent); |
7794 | | /* |
7795 | | * Build an array of prefixes and namespaces. |
7796 | | */ |
7797 | 0 | if (nsList != NULL) { |
7798 | 0 | int i, count = 0; |
7799 | |
|
7800 | 0 | for (i = 0; nsList[i] != NULL; i++) |
7801 | 0 | count++; |
7802 | |
|
7803 | 0 | nsArray = (const xmlChar **) xmlMalloc( |
7804 | 0 | (count * 2 + 1) * sizeof(const xmlChar *)); |
7805 | 0 | if (nsArray == NULL) { |
7806 | 0 | xmlSchemaPErrMemory(ctxt); |
7807 | 0 | xmlFree(nsList); |
7808 | 0 | return (-1); |
7809 | 0 | } |
7810 | 0 | for (i = 0; i < count; i++) { |
7811 | 0 | nsArray[2 * i] = nsList[i]->href; |
7812 | 0 | nsArray[2 * i + 1] = nsList[i]->prefix; |
7813 | 0 | } |
7814 | 0 | nsArray[count * 2] = NULL; |
7815 | 0 | xmlFree(nsList); |
7816 | 0 | } |
7817 | | /* |
7818 | | * TODO: Differentiate between "selector" and "field". |
7819 | | */ |
7820 | 0 | if (isField) |
7821 | 0 | selector->xpathComp = (void *) xmlPatterncompile(selector->xpath, |
7822 | 0 | NULL, XML_PATTERN_XSFIELD, nsArray); |
7823 | 0 | else |
7824 | 0 | selector->xpathComp = (void *) xmlPatterncompile(selector->xpath, |
7825 | 0 | NULL, XML_PATTERN_XSSEL, nsArray); |
7826 | 0 | if (nsArray != NULL) |
7827 | 0 | xmlFree((xmlChar **) nsArray); |
7828 | |
|
7829 | 0 | if (selector->xpathComp == NULL) { |
7830 | 0 | xmlSchemaPCustomErr(ctxt, |
7831 | | /* TODO: Adjust error code? */ |
7832 | 0 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
7833 | 0 | NULL, node, |
7834 | 0 | "The XPath expression '%s' could not be " |
7835 | 0 | "compiled", selector->xpath); |
7836 | 0 | return (XML_SCHEMAP_S4S_ATTR_INVALID_VALUE); |
7837 | 0 | } |
7838 | 0 | } |
7839 | 0 | return (0); |
7840 | 0 | } |
7841 | | |
7842 | | #define ADD_ANNOTATION(annot) \ |
7843 | 0 | xmlSchemaAnnotPtr cur = item->annot; \ |
7844 | 0 | if (item->annot == NULL) { \ |
7845 | 0 | item->annot = annot; \ |
7846 | 0 | return (annot); \ |
7847 | 0 | } \ |
7848 | 0 | cur = item->annot; \ |
7849 | 0 | while (cur->next != NULL) { \ |
7850 | 0 | cur = cur->next; \ |
7851 | 0 | } \ |
7852 | 0 | cur->next = annot; |
7853 | | |
7854 | | /** |
7855 | | * Adds the annotation to the given schema component. |
7856 | | * |
7857 | | * @param annItem the schema component |
7858 | | * @param annot the annotation |
7859 | | * @returns the given annotation. |
7860 | | */ |
7861 | | static xmlSchemaAnnotPtr |
7862 | | xmlSchemaAddAnnotation(xmlSchemaAnnotItemPtr annItem, |
7863 | | xmlSchemaAnnotPtr annot) |
7864 | 0 | { |
7865 | 0 | if ((annItem == NULL) || (annot == NULL)) |
7866 | 0 | return (NULL); |
7867 | 0 | switch (annItem->type) { |
7868 | 0 | case XML_SCHEMA_TYPE_ELEMENT: { |
7869 | 0 | xmlSchemaElementPtr item = (xmlSchemaElementPtr) annItem; |
7870 | 0 | ADD_ANNOTATION(annot) |
7871 | 0 | } |
7872 | 0 | break; |
7873 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTE: { |
7874 | 0 | xmlSchemaAttributePtr item = (xmlSchemaAttributePtr) annItem; |
7875 | 0 | ADD_ANNOTATION(annot) |
7876 | 0 | } |
7877 | 0 | break; |
7878 | 0 | case XML_SCHEMA_TYPE_ANY_ATTRIBUTE: |
7879 | 0 | case XML_SCHEMA_TYPE_ANY: { |
7880 | 0 | xmlSchemaWildcardPtr item = (xmlSchemaWildcardPtr) annItem; |
7881 | 0 | ADD_ANNOTATION(annot) |
7882 | 0 | } |
7883 | 0 | break; |
7884 | 0 | case XML_SCHEMA_TYPE_PARTICLE: |
7885 | 0 | case XML_SCHEMA_TYPE_IDC_KEY: |
7886 | 0 | case XML_SCHEMA_TYPE_IDC_KEYREF: |
7887 | 0 | case XML_SCHEMA_TYPE_IDC_UNIQUE: { |
7888 | 0 | xmlSchemaAnnotItemPtr item = (xmlSchemaAnnotItemPtr) annItem; |
7889 | 0 | ADD_ANNOTATION(annot) |
7890 | 0 | } |
7891 | 0 | break; |
7892 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: { |
7893 | 0 | xmlSchemaAttributeGroupPtr item = |
7894 | 0 | (xmlSchemaAttributeGroupPtr) annItem; |
7895 | 0 | ADD_ANNOTATION(annot) |
7896 | 0 | } |
7897 | 0 | break; |
7898 | 0 | case XML_SCHEMA_TYPE_NOTATION: { |
7899 | 0 | xmlSchemaNotationPtr item = (xmlSchemaNotationPtr) annItem; |
7900 | 0 | ADD_ANNOTATION(annot) |
7901 | 0 | } |
7902 | 0 | break; |
7903 | 0 | case XML_SCHEMA_FACET_MININCLUSIVE: |
7904 | 0 | case XML_SCHEMA_FACET_MINEXCLUSIVE: |
7905 | 0 | case XML_SCHEMA_FACET_MAXINCLUSIVE: |
7906 | 0 | case XML_SCHEMA_FACET_MAXEXCLUSIVE: |
7907 | 0 | case XML_SCHEMA_FACET_TOTALDIGITS: |
7908 | 0 | case XML_SCHEMA_FACET_FRACTIONDIGITS: |
7909 | 0 | case XML_SCHEMA_FACET_PATTERN: |
7910 | 0 | case XML_SCHEMA_FACET_ENUMERATION: |
7911 | 0 | case XML_SCHEMA_FACET_WHITESPACE: |
7912 | 0 | case XML_SCHEMA_FACET_LENGTH: |
7913 | 0 | case XML_SCHEMA_FACET_MAXLENGTH: |
7914 | 0 | case XML_SCHEMA_FACET_MINLENGTH: { |
7915 | 0 | xmlSchemaFacetPtr item = (xmlSchemaFacetPtr) annItem; |
7916 | 0 | ADD_ANNOTATION(annot) |
7917 | 0 | } |
7918 | 0 | break; |
7919 | 0 | case XML_SCHEMA_TYPE_SIMPLE: |
7920 | 0 | case XML_SCHEMA_TYPE_COMPLEX: { |
7921 | 0 | xmlSchemaTypePtr item = (xmlSchemaTypePtr) annItem; |
7922 | 0 | ADD_ANNOTATION(annot) |
7923 | 0 | } |
7924 | 0 | break; |
7925 | 0 | case XML_SCHEMA_TYPE_GROUP: { |
7926 | 0 | xmlSchemaModelGroupDefPtr item = (xmlSchemaModelGroupDefPtr) annItem; |
7927 | 0 | ADD_ANNOTATION(annot) |
7928 | 0 | } |
7929 | 0 | break; |
7930 | 0 | case XML_SCHEMA_TYPE_SEQUENCE: |
7931 | 0 | case XML_SCHEMA_TYPE_CHOICE: |
7932 | 0 | case XML_SCHEMA_TYPE_ALL: { |
7933 | 0 | xmlSchemaModelGroupPtr item = (xmlSchemaModelGroupPtr) annItem; |
7934 | 0 | ADD_ANNOTATION(annot) |
7935 | 0 | } |
7936 | 0 | break; |
7937 | 0 | default: |
7938 | 0 | xmlSchemaPCustomErr(NULL, |
7939 | 0 | XML_SCHEMAP_INTERNAL, |
7940 | 0 | NULL, NULL, |
7941 | 0 | "Internal error: xmlSchemaAddAnnotation, " |
7942 | 0 | "The item is not a annotated schema component", NULL); |
7943 | 0 | break; |
7944 | 0 | } |
7945 | 0 | return (annot); |
7946 | 0 | } |
7947 | | |
7948 | | /** |
7949 | | * Parses a XML Schema identity-constraint definition's |
7950 | | * `<selector>` and `<field>` elements. |
7951 | | * |
7952 | | * @param ctxt a schema validation context |
7953 | | * @param idc the identity-constraint definition |
7954 | | * @param node a subtree containing XML Schema information |
7955 | | * @param isField field indicator |
7956 | | * @returns the parsed identity-constraint definition. |
7957 | | */ |
7958 | | static xmlSchemaIDCSelectPtr |
7959 | | xmlSchemaParseIDCSelectorAndField(xmlSchemaParserCtxtPtr ctxt, |
7960 | | xmlSchemaIDCPtr idc, |
7961 | | xmlNodePtr node, |
7962 | | int isField) |
7963 | 0 | { |
7964 | 0 | xmlSchemaIDCSelectPtr item; |
7965 | 0 | xmlNodePtr child = NULL; |
7966 | 0 | xmlAttrPtr attr; |
7967 | | |
7968 | | /* |
7969 | | * Check for illegal attributes. |
7970 | | */ |
7971 | 0 | attr = node->properties; |
7972 | 0 | while (attr != NULL) { |
7973 | 0 | if (attr->ns == NULL) { |
7974 | 0 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
7975 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "xpath"))) { |
7976 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
7977 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
7978 | 0 | } |
7979 | 0 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
7980 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
7981 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
7982 | 0 | } |
7983 | 0 | attr = attr->next; |
7984 | 0 | } |
7985 | | /* |
7986 | | * Create the item. |
7987 | | */ |
7988 | 0 | item = (xmlSchemaIDCSelectPtr) xmlMalloc(sizeof(xmlSchemaIDCSelect)); |
7989 | 0 | if (item == NULL) { |
7990 | 0 | xmlSchemaPErrMemory(ctxt); |
7991 | 0 | return (NULL); |
7992 | 0 | } |
7993 | 0 | memset(item, 0, sizeof(xmlSchemaIDCSelect)); |
7994 | | /* |
7995 | | * Attribute "xpath" (mandatory). |
7996 | | */ |
7997 | 0 | attr = xmlSchemaGetPropNode(node, "xpath"); |
7998 | 0 | if (attr == NULL) { |
7999 | 0 | xmlSchemaPMissingAttrErr(ctxt, |
8000 | 0 | XML_SCHEMAP_S4S_ATTR_MISSING, |
8001 | 0 | NULL, node, |
8002 | 0 | "name", NULL); |
8003 | 0 | } else { |
8004 | 0 | item->xpath = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
8005 | | /* |
8006 | | * URGENT TODO: "field"s have an other syntax than "selector"s. |
8007 | | */ |
8008 | |
|
8009 | 0 | if (xmlSchemaCheckCSelectorXPath(ctxt, idc, item, attr, |
8010 | 0 | isField) == -1) { |
8011 | 0 | xmlSchemaPErr(ctxt, |
8012 | 0 | (xmlNodePtr) attr, |
8013 | 0 | XML_SCHEMAP_INTERNAL, |
8014 | 0 | "Internal error: xmlSchemaParseIDCSelectorAndField, " |
8015 | 0 | "validating the XPath expression of a IDC selector.\n", |
8016 | 0 | NULL, NULL); |
8017 | 0 | } |
8018 | |
|
8019 | 0 | } |
8020 | 0 | xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id"); |
8021 | | /* |
8022 | | * And now for the children... |
8023 | | */ |
8024 | 0 | child = node->children; |
8025 | 0 | if (IS_SCHEMA(child, "annotation")) { |
8026 | | /* |
8027 | | * Add the annotation to the parent IDC. |
8028 | | */ |
8029 | 0 | xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) idc, |
8030 | 0 | xmlSchemaParseAnnotation(ctxt, child, 1)); |
8031 | 0 | child = child->next; |
8032 | 0 | } |
8033 | 0 | if (child != NULL) { |
8034 | 0 | xmlSchemaPContentErr(ctxt, |
8035 | 0 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
8036 | 0 | NULL, node, child, |
8037 | 0 | NULL, "(annotation?)"); |
8038 | 0 | } |
8039 | |
|
8040 | 0 | return (item); |
8041 | 0 | } |
8042 | | |
8043 | | /** |
8044 | | * Parses a XML Schema identity-constraint definition. |
8045 | | * |
8046 | | * @param ctxt a schema validation context |
8047 | | * @param schema the schema being built |
8048 | | * @param node a subtree containing XML Schema information |
8049 | | * @param idcCategory the IDC category |
8050 | | * @param targetNamespace the target namespace |
8051 | | * @returns the parsed identity-constraint definition. |
8052 | | */ |
8053 | | static xmlSchemaIDCPtr |
8054 | | xmlSchemaParseIDC(xmlSchemaParserCtxtPtr ctxt, |
8055 | | xmlSchemaPtr schema, |
8056 | | xmlNodePtr node, |
8057 | | xmlSchemaTypeType idcCategory, |
8058 | | const xmlChar *targetNamespace) |
8059 | 0 | { |
8060 | 0 | xmlSchemaIDCPtr item = NULL; |
8061 | 0 | xmlNodePtr child = NULL; |
8062 | 0 | xmlAttrPtr attr; |
8063 | 0 | const xmlChar *name = NULL; |
8064 | 0 | xmlSchemaIDCSelectPtr field = NULL, lastField = NULL; |
8065 | | |
8066 | | /* |
8067 | | * Check for illegal attributes. |
8068 | | */ |
8069 | 0 | attr = node->properties; |
8070 | 0 | while (attr != NULL) { |
8071 | 0 | if (attr->ns == NULL) { |
8072 | 0 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
8073 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "name")) && |
8074 | 0 | ((idcCategory != XML_SCHEMA_TYPE_IDC_KEYREF) || |
8075 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "refer")))) { |
8076 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
8077 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
8078 | 0 | } |
8079 | 0 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
8080 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
8081 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
8082 | 0 | } |
8083 | 0 | attr = attr->next; |
8084 | 0 | } |
8085 | | /* |
8086 | | * Attribute "name" (mandatory). |
8087 | | */ |
8088 | 0 | attr = xmlSchemaGetPropNode(node, "name"); |
8089 | 0 | if (attr == NULL) { |
8090 | 0 | xmlSchemaPMissingAttrErr(ctxt, |
8091 | 0 | XML_SCHEMAP_S4S_ATTR_MISSING, |
8092 | 0 | NULL, node, |
8093 | 0 | "name", NULL); |
8094 | 0 | return (NULL); |
8095 | 0 | } else if (xmlSchemaPValAttrNode(ctxt, |
8096 | 0 | NULL, attr, |
8097 | 0 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) { |
8098 | 0 | return (NULL); |
8099 | 0 | } |
8100 | | /* Create the component. */ |
8101 | 0 | item = xmlSchemaAddIDC(ctxt, schema, name, targetNamespace, |
8102 | 0 | idcCategory, node); |
8103 | 0 | if (item == NULL) |
8104 | 0 | return(NULL); |
8105 | | |
8106 | 0 | xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id"); |
8107 | 0 | if (idcCategory == XML_SCHEMA_TYPE_IDC_KEYREF) { |
8108 | | /* |
8109 | | * Attribute "refer" (mandatory). |
8110 | | */ |
8111 | 0 | attr = xmlSchemaGetPropNode(node, "refer"); |
8112 | 0 | if (attr == NULL) { |
8113 | 0 | xmlSchemaPMissingAttrErr(ctxt, |
8114 | 0 | XML_SCHEMAP_S4S_ATTR_MISSING, |
8115 | 0 | NULL, node, |
8116 | 0 | "refer", NULL); |
8117 | 0 | } else { |
8118 | | /* |
8119 | | * Create a reference item. |
8120 | | */ |
8121 | 0 | item->ref = xmlSchemaNewQNameRef(ctxt, XML_SCHEMA_TYPE_IDC_KEY, |
8122 | 0 | NULL, NULL); |
8123 | 0 | if (item->ref == NULL) |
8124 | 0 | return (NULL); |
8125 | 0 | xmlSchemaPValAttrNodeQName(ctxt, schema, |
8126 | 0 | NULL, attr, |
8127 | 0 | &(item->ref->targetNamespace), |
8128 | 0 | &(item->ref->name)); |
8129 | 0 | xmlSchemaCheckReference(ctxt, schema, node, attr, |
8130 | 0 | item->ref->targetNamespace); |
8131 | 0 | } |
8132 | 0 | } |
8133 | | /* |
8134 | | * And now for the children... |
8135 | | */ |
8136 | 0 | child = node->children; |
8137 | 0 | if (IS_SCHEMA(child, "annotation")) { |
8138 | 0 | item->annot = xmlSchemaParseAnnotation(ctxt, child, 1); |
8139 | 0 | child = child->next; |
8140 | 0 | } |
8141 | 0 | if (child == NULL) { |
8142 | 0 | xmlSchemaPContentErr(ctxt, |
8143 | 0 | XML_SCHEMAP_S4S_ELEM_MISSING, |
8144 | 0 | NULL, node, child, |
8145 | 0 | "A child element is missing", |
8146 | 0 | "(annotation?, (selector, field+))"); |
8147 | 0 | } |
8148 | | /* |
8149 | | * Child element <selector>. |
8150 | | */ |
8151 | 0 | if (IS_SCHEMA(child, "selector")) { |
8152 | 0 | item->selector = xmlSchemaParseIDCSelectorAndField(ctxt, |
8153 | 0 | item, child, 0); |
8154 | 0 | child = child->next; |
8155 | | /* |
8156 | | * Child elements <field>. |
8157 | | */ |
8158 | 0 | if (IS_SCHEMA(child, "field")) { |
8159 | 0 | do { |
8160 | 0 | field = xmlSchemaParseIDCSelectorAndField(ctxt, |
8161 | 0 | item, child, 1); |
8162 | 0 | if (field != NULL) { |
8163 | 0 | field->index = item->nbFields; |
8164 | 0 | item->nbFields++; |
8165 | 0 | if (lastField != NULL) |
8166 | 0 | lastField->next = field; |
8167 | 0 | else |
8168 | 0 | item->fields = field; |
8169 | 0 | lastField = field; |
8170 | 0 | } |
8171 | 0 | child = child->next; |
8172 | 0 | } while (IS_SCHEMA(child, "field")); |
8173 | 0 | } else { |
8174 | 0 | xmlSchemaPContentErr(ctxt, |
8175 | 0 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
8176 | 0 | NULL, node, child, |
8177 | 0 | NULL, "(annotation?, (selector, field+))"); |
8178 | 0 | } |
8179 | 0 | } |
8180 | 0 | if (child != NULL) { |
8181 | 0 | xmlSchemaPContentErr(ctxt, |
8182 | 0 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
8183 | 0 | NULL, node, child, |
8184 | 0 | NULL, "(annotation?, (selector, field+))"); |
8185 | 0 | } |
8186 | |
|
8187 | 0 | return (item); |
8188 | 0 | } |
8189 | | |
8190 | | /** |
8191 | | * Parses a XML schema element declaration. |
8192 | | * *WARNING* this interface is highly subject to change |
8193 | | * |
8194 | | * @param ctxt a schema validation context |
8195 | | * @param schema the schema being built |
8196 | | * @param node a subtree containing XML Schema information |
8197 | | * @param isElemRef set if the element is a reference |
8198 | | * @param topLevel indicates if this is global declaration |
8199 | | * @returns the element declaration or a particle; NULL in case |
8200 | | * of an error or if the particle has minOccurs==maxOccurs==0. |
8201 | | */ |
8202 | | static xmlSchemaBasicItemPtr |
8203 | | xmlSchemaParseElement(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
8204 | | xmlNodePtr node, int *isElemRef, int topLevel) |
8205 | 0 | { |
8206 | 0 | xmlSchemaElementPtr decl = NULL; |
8207 | 0 | xmlSchemaParticlePtr particle = NULL; |
8208 | 0 | xmlSchemaAnnotPtr annot = NULL; |
8209 | 0 | xmlNodePtr child = NULL; |
8210 | 0 | xmlAttrPtr attr, nameAttr; |
8211 | 0 | int min, max, isRef = 0; |
8212 | 0 | xmlChar *des = NULL; |
8213 | | |
8214 | | /* 3.3.3 Constraints on XML Representations of Element Declarations */ |
8215 | | /* TODO: Complete implementation of 3.3.6 */ |
8216 | |
|
8217 | 0 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
8218 | 0 | return (NULL); |
8219 | | |
8220 | 0 | if (isElemRef != NULL) |
8221 | 0 | *isElemRef = 0; |
8222 | | /* |
8223 | | * If we get a "ref" attribute on a local <element> we will assume it's |
8224 | | * a reference - even if there's a "name" attribute; this seems to be more |
8225 | | * robust. |
8226 | | */ |
8227 | 0 | nameAttr = xmlSchemaGetPropNode(node, "name"); |
8228 | 0 | attr = xmlSchemaGetPropNode(node, "ref"); |
8229 | 0 | if ((topLevel) || (attr == NULL)) { |
8230 | 0 | if (nameAttr == NULL) { |
8231 | 0 | xmlSchemaPMissingAttrErr(ctxt, |
8232 | 0 | XML_SCHEMAP_S4S_ATTR_MISSING, |
8233 | 0 | NULL, node, "name", NULL); |
8234 | 0 | return (NULL); |
8235 | 0 | } |
8236 | 0 | } else |
8237 | 0 | isRef = 1; |
8238 | | |
8239 | 0 | xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id"); |
8240 | 0 | child = node->children; |
8241 | 0 | if (IS_SCHEMA(child, "annotation")) { |
8242 | 0 | annot = xmlSchemaParseAnnotation(ctxt, child, 1); |
8243 | 0 | child = child->next; |
8244 | 0 | } |
8245 | | /* |
8246 | | * Skip particle part if a global declaration. |
8247 | | */ |
8248 | 0 | if (topLevel) |
8249 | 0 | goto declaration_part; |
8250 | | /* |
8251 | | * The particle part ================================================== |
8252 | | */ |
8253 | 0 | min = xmlGetMinOccurs(ctxt, node, 0, -1, 1, "xs:nonNegativeInteger"); |
8254 | 0 | max = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1, "(xs:nonNegativeInteger | unbounded)"); |
8255 | 0 | xmlSchemaPCheckParticleCorrect_2(ctxt, NULL, node, min, max); |
8256 | 0 | particle = xmlSchemaAddParticle(ctxt, node, min, max); |
8257 | 0 | if (particle == NULL) |
8258 | 0 | goto return_null; |
8259 | | |
8260 | | /* ret->flags |= XML_SCHEMAS_ELEM_REF; */ |
8261 | | |
8262 | 0 | if (isRef) { |
8263 | 0 | const xmlChar *refNs = NULL, *ref = NULL; |
8264 | 0 | xmlSchemaQNameRefPtr refer = NULL; |
8265 | | /* |
8266 | | * The reference part ============================================= |
8267 | | */ |
8268 | 0 | if (isElemRef != NULL) |
8269 | 0 | *isElemRef = 1; |
8270 | |
|
8271 | 0 | xmlSchemaPValAttrNodeQName(ctxt, schema, |
8272 | 0 | NULL, attr, &refNs, &ref); |
8273 | 0 | xmlSchemaCheckReference(ctxt, schema, node, attr, refNs); |
8274 | | /* |
8275 | | * SPEC (3.3.3 : 2.1) "One of ref or name must be present, but not both" |
8276 | | */ |
8277 | 0 | if (nameAttr != NULL) { |
8278 | 0 | xmlSchemaPMutualExclAttrErr(ctxt, |
8279 | 0 | XML_SCHEMAP_SRC_ELEMENT_2_1, NULL, nameAttr, "ref", "name"); |
8280 | 0 | } |
8281 | | /* |
8282 | | * Check for illegal attributes. |
8283 | | */ |
8284 | 0 | attr = node->properties; |
8285 | 0 | while (attr != NULL) { |
8286 | 0 | if (attr->ns == NULL) { |
8287 | 0 | if (xmlStrEqual(attr->name, BAD_CAST "ref") || |
8288 | 0 | xmlStrEqual(attr->name, BAD_CAST "name") || |
8289 | 0 | xmlStrEqual(attr->name, BAD_CAST "id") || |
8290 | 0 | xmlStrEqual(attr->name, BAD_CAST "maxOccurs") || |
8291 | 0 | xmlStrEqual(attr->name, BAD_CAST "minOccurs")) |
8292 | 0 | { |
8293 | 0 | attr = attr->next; |
8294 | 0 | continue; |
8295 | 0 | } else { |
8296 | | /* SPEC (3.3.3 : 2.2) */ |
8297 | 0 | xmlSchemaPCustomAttrErr(ctxt, |
8298 | 0 | XML_SCHEMAP_SRC_ELEMENT_2_2, |
8299 | 0 | NULL, NULL, attr, |
8300 | 0 | "Only the attributes 'minOccurs', 'maxOccurs' and " |
8301 | 0 | "'id' are allowed in addition to 'ref'"); |
8302 | 0 | break; |
8303 | 0 | } |
8304 | 0 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
8305 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
8306 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
8307 | 0 | } |
8308 | 0 | attr = attr->next; |
8309 | 0 | } |
8310 | | /* |
8311 | | * No children except <annotation> expected. |
8312 | | */ |
8313 | 0 | if (child != NULL) { |
8314 | 0 | xmlSchemaPContentErr(ctxt, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
8315 | 0 | NULL, node, child, NULL, "(annotation?)"); |
8316 | 0 | } |
8317 | 0 | if ((min == 0) && (max == 0)) |
8318 | 0 | goto return_null; |
8319 | | /* |
8320 | | * Create the reference item and attach it to the particle. |
8321 | | */ |
8322 | 0 | refer = xmlSchemaNewQNameRef(ctxt, XML_SCHEMA_TYPE_ELEMENT, |
8323 | 0 | ref, refNs); |
8324 | 0 | if (refer == NULL) |
8325 | 0 | goto return_null; |
8326 | 0 | particle->children = (xmlSchemaTreeItemPtr) refer; |
8327 | 0 | particle->annot = annot; |
8328 | | /* |
8329 | | * Add the particle to pending components, since the reference |
8330 | | * need to be resolved. |
8331 | | */ |
8332 | 0 | WXS_ADD_PENDING(ctxt, particle); |
8333 | 0 | return ((xmlSchemaBasicItemPtr) particle); |
8334 | 0 | } |
8335 | | /* |
8336 | | * The declaration part =============================================== |
8337 | | */ |
8338 | 0 | declaration_part: |
8339 | 0 | { |
8340 | 0 | const xmlChar *ns = NULL, *fixed, *name, *attrValue; |
8341 | 0 | xmlSchemaIDCPtr curIDC = NULL, lastIDC = NULL; |
8342 | |
|
8343 | 0 | if (xmlSchemaPValAttrNode(ctxt, NULL, nameAttr, |
8344 | 0 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) |
8345 | 0 | goto return_null; |
8346 | | /* |
8347 | | * Evaluate the target namespace. |
8348 | | */ |
8349 | 0 | if (topLevel) { |
8350 | 0 | ns = ctxt->targetNamespace; |
8351 | 0 | } else { |
8352 | 0 | attr = xmlSchemaGetPropNode(node, "form"); |
8353 | 0 | if (attr != NULL) { |
8354 | 0 | attrValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
8355 | 0 | if (xmlStrEqual(attrValue, BAD_CAST "qualified")) { |
8356 | 0 | ns = ctxt->targetNamespace; |
8357 | 0 | } else if (!xmlStrEqual(attrValue, BAD_CAST "unqualified")) { |
8358 | 0 | xmlSchemaPSimpleTypeErr(ctxt, |
8359 | 0 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
8360 | 0 | NULL, (xmlNodePtr) attr, |
8361 | 0 | NULL, "(qualified | unqualified)", |
8362 | 0 | attrValue, NULL, NULL, NULL); |
8363 | 0 | } |
8364 | 0 | } else if (schema->flags & XML_SCHEMAS_QUALIF_ELEM) |
8365 | 0 | ns = ctxt->targetNamespace; |
8366 | 0 | } |
8367 | 0 | decl = xmlSchemaAddElement(ctxt, name, ns, node, topLevel); |
8368 | 0 | if (decl == NULL) { |
8369 | 0 | goto return_null; |
8370 | 0 | } |
8371 | | /* |
8372 | | * Check for illegal attributes. |
8373 | | */ |
8374 | 0 | attr = node->properties; |
8375 | 0 | while (attr != NULL) { |
8376 | 0 | if (attr->ns == NULL) { |
8377 | 0 | if ((!xmlStrEqual(attr->name, BAD_CAST "name")) && |
8378 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "type")) && |
8379 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "id")) && |
8380 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "default")) && |
8381 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "fixed")) && |
8382 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "block")) && |
8383 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "nillable"))) |
8384 | 0 | { |
8385 | 0 | if (topLevel == 0) { |
8386 | 0 | if ((!xmlStrEqual(attr->name, BAD_CAST "maxOccurs")) && |
8387 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "minOccurs")) && |
8388 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "form"))) |
8389 | 0 | { |
8390 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
8391 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
8392 | 0 | } |
8393 | 0 | } else if ((!xmlStrEqual(attr->name, BAD_CAST "final")) && |
8394 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "abstract")) && |
8395 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "substitutionGroup"))) { |
8396 | |
|
8397 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
8398 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
8399 | 0 | } |
8400 | 0 | } |
8401 | 0 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
8402 | |
|
8403 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
8404 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
8405 | 0 | } |
8406 | 0 | attr = attr->next; |
8407 | 0 | } |
8408 | | /* |
8409 | | * Extract/validate attributes. |
8410 | | */ |
8411 | 0 | if (topLevel) { |
8412 | | /* |
8413 | | * Process top attributes of global element declarations here. |
8414 | | */ |
8415 | 0 | decl->flags |= XML_SCHEMAS_ELEM_GLOBAL; |
8416 | 0 | decl->flags |= XML_SCHEMAS_ELEM_TOPLEVEL; |
8417 | 0 | xmlSchemaPValAttrQName(ctxt, schema, |
8418 | 0 | NULL, node, "substitutionGroup", |
8419 | 0 | &(decl->substGroupNs), &(decl->substGroup)); |
8420 | 0 | if (xmlGetBooleanProp(ctxt, node, "abstract", 0)) |
8421 | 0 | decl->flags |= XML_SCHEMAS_ELEM_ABSTRACT; |
8422 | | /* |
8423 | | * Attribute "final". |
8424 | | */ |
8425 | 0 | attr = xmlSchemaGetPropNode(node, "final"); |
8426 | 0 | if (attr == NULL) { |
8427 | 0 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_EXTENSION) |
8428 | 0 | decl->flags |= XML_SCHEMAS_ELEM_FINAL_EXTENSION; |
8429 | 0 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION) |
8430 | 0 | decl->flags |= XML_SCHEMAS_ELEM_FINAL_RESTRICTION; |
8431 | 0 | } else { |
8432 | 0 | attrValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
8433 | 0 | if (xmlSchemaPValAttrBlockFinal(attrValue, &(decl->flags), |
8434 | 0 | -1, |
8435 | 0 | XML_SCHEMAS_ELEM_FINAL_EXTENSION, |
8436 | 0 | XML_SCHEMAS_ELEM_FINAL_RESTRICTION, -1, -1, -1) != 0) { |
8437 | 0 | xmlSchemaPSimpleTypeErr(ctxt, |
8438 | 0 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
8439 | 0 | NULL, (xmlNodePtr) attr, |
8440 | 0 | NULL, "(#all | List of (extension | restriction))", |
8441 | 0 | attrValue, NULL, NULL, NULL); |
8442 | 0 | } |
8443 | 0 | } |
8444 | 0 | } |
8445 | | /* |
8446 | | * Attribute "block". |
8447 | | */ |
8448 | 0 | attr = xmlSchemaGetPropNode(node, "block"); |
8449 | 0 | if (attr == NULL) { |
8450 | | /* |
8451 | | * Apply default "block" values. |
8452 | | */ |
8453 | 0 | if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION) |
8454 | 0 | decl->flags |= XML_SCHEMAS_ELEM_BLOCK_RESTRICTION; |
8455 | 0 | if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION) |
8456 | 0 | decl->flags |= XML_SCHEMAS_ELEM_BLOCK_EXTENSION; |
8457 | 0 | if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION) |
8458 | 0 | decl->flags |= XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION; |
8459 | 0 | } else { |
8460 | 0 | attrValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
8461 | 0 | if (xmlSchemaPValAttrBlockFinal(attrValue, &(decl->flags), |
8462 | 0 | -1, |
8463 | 0 | XML_SCHEMAS_ELEM_BLOCK_EXTENSION, |
8464 | 0 | XML_SCHEMAS_ELEM_BLOCK_RESTRICTION, |
8465 | 0 | XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION, -1, -1) != 0) { |
8466 | 0 | xmlSchemaPSimpleTypeErr(ctxt, |
8467 | 0 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
8468 | 0 | NULL, (xmlNodePtr) attr, |
8469 | 0 | NULL, "(#all | List of (extension | " |
8470 | 0 | "restriction | substitution))", attrValue, |
8471 | 0 | NULL, NULL, NULL); |
8472 | 0 | } |
8473 | 0 | } |
8474 | 0 | if (xmlGetBooleanProp(ctxt, node, "nillable", 0)) |
8475 | 0 | decl->flags |= XML_SCHEMAS_ELEM_NILLABLE; |
8476 | |
|
8477 | 0 | attr = xmlSchemaGetPropNode(node, "type"); |
8478 | 0 | if (attr != NULL) { |
8479 | 0 | xmlSchemaPValAttrNodeQName(ctxt, schema, |
8480 | 0 | NULL, attr, |
8481 | 0 | &(decl->namedTypeNs), &(decl->namedType)); |
8482 | 0 | xmlSchemaCheckReference(ctxt, schema, node, |
8483 | 0 | attr, decl->namedTypeNs); |
8484 | 0 | } |
8485 | 0 | decl->value = xmlSchemaGetProp(ctxt, node, "default"); |
8486 | 0 | attr = xmlSchemaGetPropNode(node, "fixed"); |
8487 | 0 | if (attr != NULL) { |
8488 | 0 | fixed = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
8489 | 0 | if (decl->value != NULL) { |
8490 | | /* |
8491 | | * 3.3.3 : 1 |
8492 | | * default and fixed must not both be present. |
8493 | | */ |
8494 | 0 | xmlSchemaPMutualExclAttrErr(ctxt, |
8495 | 0 | XML_SCHEMAP_SRC_ELEMENT_1, |
8496 | 0 | NULL, attr, "default", "fixed"); |
8497 | 0 | } else { |
8498 | 0 | decl->flags |= XML_SCHEMAS_ELEM_FIXED; |
8499 | 0 | decl->value = fixed; |
8500 | 0 | } |
8501 | 0 | } |
8502 | | /* |
8503 | | * And now for the children... |
8504 | | */ |
8505 | 0 | if (IS_SCHEMA(child, "complexType")) { |
8506 | | /* |
8507 | | * 3.3.3 : 3 |
8508 | | * "type" and either <simpleType> or <complexType> are mutually |
8509 | | * exclusive |
8510 | | */ |
8511 | 0 | if (decl->namedType != NULL) { |
8512 | 0 | xmlSchemaPContentErr(ctxt, |
8513 | 0 | XML_SCHEMAP_SRC_ELEMENT_3, |
8514 | 0 | NULL, node, child, |
8515 | 0 | "The attribute 'type' and the <complexType> child are " |
8516 | 0 | "mutually exclusive", NULL); |
8517 | 0 | } else |
8518 | 0 | WXS_ELEM_TYPEDEF(decl) = xmlSchemaParseComplexType(ctxt, schema, child, 0); |
8519 | 0 | child = child->next; |
8520 | 0 | } else if (IS_SCHEMA(child, "simpleType")) { |
8521 | | /* |
8522 | | * 3.3.3 : 3 |
8523 | | * "type" and either <simpleType> or <complexType> are |
8524 | | * mutually exclusive |
8525 | | */ |
8526 | 0 | if (decl->namedType != NULL) { |
8527 | 0 | xmlSchemaPContentErr(ctxt, |
8528 | 0 | XML_SCHEMAP_SRC_ELEMENT_3, |
8529 | 0 | NULL, node, child, |
8530 | 0 | "The attribute 'type' and the <simpleType> child are " |
8531 | 0 | "mutually exclusive", NULL); |
8532 | 0 | } else |
8533 | 0 | WXS_ELEM_TYPEDEF(decl) = xmlSchemaParseSimpleType(ctxt, schema, child, 0); |
8534 | 0 | child = child->next; |
8535 | 0 | } |
8536 | 0 | while ((IS_SCHEMA(child, "unique")) || |
8537 | 0 | (IS_SCHEMA(child, "key")) || (IS_SCHEMA(child, "keyref"))) { |
8538 | 0 | if (IS_SCHEMA(child, "unique")) { |
8539 | 0 | curIDC = xmlSchemaParseIDC(ctxt, schema, child, |
8540 | 0 | XML_SCHEMA_TYPE_IDC_UNIQUE, decl->targetNamespace); |
8541 | 0 | } else if (IS_SCHEMA(child, "key")) { |
8542 | 0 | curIDC = xmlSchemaParseIDC(ctxt, schema, child, |
8543 | 0 | XML_SCHEMA_TYPE_IDC_KEY, decl->targetNamespace); |
8544 | 0 | } else if (IS_SCHEMA(child, "keyref")) { |
8545 | 0 | curIDC = xmlSchemaParseIDC(ctxt, schema, child, |
8546 | 0 | XML_SCHEMA_TYPE_IDC_KEYREF, decl->targetNamespace); |
8547 | 0 | } |
8548 | 0 | if (lastIDC != NULL) |
8549 | 0 | lastIDC->next = curIDC; |
8550 | 0 | else |
8551 | 0 | decl->idcs = (void *) curIDC; |
8552 | 0 | lastIDC = curIDC; |
8553 | 0 | child = child->next; |
8554 | 0 | } |
8555 | 0 | if (child != NULL) { |
8556 | 0 | xmlSchemaPContentErr(ctxt, |
8557 | 0 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
8558 | 0 | NULL, node, child, |
8559 | 0 | NULL, "(annotation?, ((simpleType | complexType)?, " |
8560 | 0 | "(unique | key | keyref)*))"); |
8561 | 0 | } |
8562 | 0 | decl->annot = annot; |
8563 | 0 | } |
8564 | | /* |
8565 | | * NOTE: Element Declaration Representation OK 4. will be checked at a |
8566 | | * different layer. |
8567 | | */ |
8568 | 0 | FREE_AND_NULL(des) |
8569 | 0 | if (topLevel) |
8570 | 0 | return ((xmlSchemaBasicItemPtr) decl); |
8571 | 0 | else { |
8572 | 0 | particle->children = (xmlSchemaTreeItemPtr) decl; |
8573 | 0 | return ((xmlSchemaBasicItemPtr) particle); |
8574 | 0 | } |
8575 | | |
8576 | 0 | return_null: |
8577 | 0 | FREE_AND_NULL(des); |
8578 | 0 | if (annot != NULL) { |
8579 | 0 | if (particle != NULL) |
8580 | 0 | particle->annot = NULL; |
8581 | 0 | if (decl != NULL) |
8582 | 0 | decl->annot = NULL; |
8583 | 0 | xmlSchemaFreeAnnot(annot); |
8584 | 0 | } |
8585 | 0 | return (NULL); |
8586 | 0 | } |
8587 | | |
8588 | | /** |
8589 | | * parse a XML schema Union definition |
8590 | | * *WARNING* this interface is highly subject to change |
8591 | | * |
8592 | | * @param ctxt a schema validation context |
8593 | | * @param schema the schema being built |
8594 | | * @param node a subtree containing XML Schema information |
8595 | | * @returns -1 in case of internal error, 0 in case of success and a positive |
8596 | | * error code otherwise. |
8597 | | */ |
8598 | | static int |
8599 | | xmlSchemaParseUnion(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
8600 | | xmlNodePtr node) |
8601 | 0 | { |
8602 | 0 | xmlSchemaTypePtr type; |
8603 | 0 | xmlNodePtr child = NULL; |
8604 | 0 | xmlAttrPtr attr; |
8605 | 0 | const xmlChar *cur = NULL; |
8606 | |
|
8607 | 0 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
8608 | 0 | return (-1); |
8609 | | /* Not a component, don't create it. */ |
8610 | 0 | type = ctxt->ctxtType; |
8611 | | /* |
8612 | | * Mark the simple type as being of variety "union". |
8613 | | */ |
8614 | 0 | type->flags |= XML_SCHEMAS_TYPE_VARIETY_UNION; |
8615 | | /* |
8616 | | * SPEC (Base type) (2) "If the <list> or <union> alternative is chosen, |
8617 | | * then the `simple ur-type definition`." |
8618 | | */ |
8619 | 0 | type->baseType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE); |
8620 | | /* |
8621 | | * Check for illegal attributes. |
8622 | | */ |
8623 | 0 | attr = node->properties; |
8624 | 0 | while (attr != NULL) { |
8625 | 0 | if (attr->ns == NULL) { |
8626 | 0 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
8627 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "memberTypes"))) { |
8628 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
8629 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
8630 | 0 | } |
8631 | 0 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
8632 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
8633 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
8634 | 0 | } |
8635 | 0 | attr = attr->next; |
8636 | 0 | } |
8637 | 0 | xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id"); |
8638 | | /* |
8639 | | * Attribute "memberTypes". This is a list of QNames. |
8640 | | * TODO: Check the value to contain anything. |
8641 | | */ |
8642 | 0 | attr = xmlSchemaGetPropNode(node, "memberTypes"); |
8643 | 0 | if (attr != NULL) { |
8644 | 0 | const xmlChar *end; |
8645 | 0 | xmlChar *tmp; |
8646 | 0 | const xmlChar *localName, *nsName; |
8647 | 0 | xmlSchemaTypeLinkPtr link, lastLink = NULL; |
8648 | 0 | xmlSchemaQNameRefPtr ref; |
8649 | |
|
8650 | 0 | cur = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
8651 | 0 | if (cur == NULL) |
8652 | 0 | return (-1); |
8653 | 0 | type->base = cur; |
8654 | 0 | do { |
8655 | 0 | while (IS_BLANK_CH(*cur)) |
8656 | 0 | cur++; |
8657 | 0 | end = cur; |
8658 | 0 | while ((*end != 0) && (!(IS_BLANK_CH(*end)))) |
8659 | 0 | end++; |
8660 | 0 | if (end == cur) |
8661 | 0 | break; |
8662 | 0 | tmp = xmlStrndup(cur, end - cur); |
8663 | 0 | if (tmp == NULL) { |
8664 | 0 | xmlSchemaPErrMemory(ctxt); |
8665 | 0 | return (-1); |
8666 | 0 | } |
8667 | 0 | if (xmlSchemaPValAttrNodeQNameValue(ctxt, schema, |
8668 | 0 | NULL, attr, BAD_CAST tmp, &nsName, &localName) == 0) { |
8669 | | /* |
8670 | | * Create the member type link. |
8671 | | */ |
8672 | 0 | link = (xmlSchemaTypeLinkPtr) |
8673 | 0 | xmlMalloc(sizeof(xmlSchemaTypeLink)); |
8674 | 0 | if (link == NULL) { |
8675 | 0 | xmlSchemaPErrMemory(ctxt); |
8676 | 0 | FREE_AND_NULL(tmp) |
8677 | 0 | return (-1); |
8678 | 0 | } |
8679 | 0 | link->type = NULL; |
8680 | 0 | link->next = NULL; |
8681 | | /* |
8682 | | * Create a reference item. |
8683 | | */ |
8684 | 0 | ref = xmlSchemaNewQNameRef(ctxt, XML_SCHEMA_TYPE_SIMPLE, |
8685 | 0 | localName, nsName); |
8686 | 0 | if (ref == NULL) { |
8687 | 0 | xmlSchemaPErrMemory(ctxt); |
8688 | 0 | xmlFree(link); |
8689 | 0 | FREE_AND_NULL(tmp) |
8690 | 0 | return (-1); |
8691 | 0 | } |
8692 | | /* |
8693 | | * Assign the reference to the link, it will be resolved |
8694 | | * later during fixup of the union simple type. |
8695 | | */ |
8696 | 0 | link->type = (xmlSchemaTypePtr) ref; |
8697 | |
|
8698 | 0 | if (lastLink == NULL) |
8699 | 0 | type->memberTypes = link; |
8700 | 0 | else |
8701 | 0 | lastLink->next = link; |
8702 | 0 | lastLink = link; |
8703 | 0 | } |
8704 | 0 | FREE_AND_NULL(tmp) |
8705 | 0 | cur = end; |
8706 | 0 | } while (*cur != 0); |
8707 | |
|
8708 | 0 | } |
8709 | | /* |
8710 | | * And now for the children... |
8711 | | */ |
8712 | 0 | child = node->children; |
8713 | 0 | if (IS_SCHEMA(child, "annotation")) { |
8714 | | /* |
8715 | | * Add the annotation to the simple type ancestor. |
8716 | | */ |
8717 | 0 | xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) type, |
8718 | 0 | xmlSchemaParseAnnotation(ctxt, child, 1)); |
8719 | 0 | child = child->next; |
8720 | 0 | } |
8721 | 0 | if (IS_SCHEMA(child, "simpleType")) { |
8722 | 0 | xmlSchemaTypePtr subtype, last = NULL; |
8723 | | |
8724 | | /* |
8725 | | * Anchor the member types in the "subtypes" field of the |
8726 | | * simple type. |
8727 | | */ |
8728 | 0 | while (IS_SCHEMA(child, "simpleType")) { |
8729 | 0 | subtype = (xmlSchemaTypePtr) |
8730 | 0 | xmlSchemaParseSimpleType(ctxt, schema, child, 0); |
8731 | 0 | if (subtype != NULL) { |
8732 | 0 | if (last == NULL) { |
8733 | 0 | type->subtypes = subtype; |
8734 | 0 | last = subtype; |
8735 | 0 | } else { |
8736 | 0 | last->next = subtype; |
8737 | 0 | last = subtype; |
8738 | 0 | } |
8739 | 0 | last->next = NULL; |
8740 | 0 | } |
8741 | 0 | child = child->next; |
8742 | 0 | } |
8743 | 0 | } |
8744 | 0 | if (child != NULL) { |
8745 | 0 | xmlSchemaPContentErr(ctxt, |
8746 | 0 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
8747 | 0 | NULL, node, child, NULL, "(annotation?, simpleType*)"); |
8748 | 0 | } |
8749 | 0 | if ((attr == NULL) && (type->subtypes == NULL)) { |
8750 | | /* |
8751 | | * src-union-memberTypes-or-simpleTypes |
8752 | | * Either the memberTypes [attribute] of the <union> element must |
8753 | | * be non-empty or there must be at least one simpleType [child]. |
8754 | | */ |
8755 | 0 | xmlSchemaPCustomErr(ctxt, |
8756 | 0 | XML_SCHEMAP_SRC_UNION_MEMBERTYPES_OR_SIMPLETYPES, |
8757 | 0 | NULL, node, |
8758 | 0 | "Either the attribute 'memberTypes' or " |
8759 | 0 | "at least one <simpleType> child must be present", NULL); |
8760 | 0 | } |
8761 | 0 | return (0); |
8762 | 0 | } |
8763 | | |
8764 | | /** |
8765 | | * parse a XML schema List definition |
8766 | | * *WARNING* this interface is highly subject to change |
8767 | | * |
8768 | | * @param ctxt a schema validation context |
8769 | | * @param schema the schema being built |
8770 | | * @param node a subtree containing XML Schema information |
8771 | | * @returns -1 in case of error, 0 if the declaration is improper and |
8772 | | * 1 in case of success. |
8773 | | */ |
8774 | | static xmlSchemaTypePtr |
8775 | | xmlSchemaParseList(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
8776 | | xmlNodePtr node) |
8777 | 0 | { |
8778 | 0 | xmlSchemaTypePtr type; |
8779 | 0 | xmlNodePtr child = NULL; |
8780 | 0 | xmlAttrPtr attr; |
8781 | |
|
8782 | 0 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
8783 | 0 | return (NULL); |
8784 | | /* Not a component, don't create it. */ |
8785 | 0 | type = ctxt->ctxtType; |
8786 | | /* |
8787 | | * Mark the type as being of variety "list". |
8788 | | */ |
8789 | 0 | type->flags |= XML_SCHEMAS_TYPE_VARIETY_LIST; |
8790 | | /* |
8791 | | * SPEC (Base type) (2) "If the <list> or <union> alternative is chosen, |
8792 | | * then the `simple ur-type definition`." |
8793 | | */ |
8794 | 0 | type->baseType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE); |
8795 | | /* |
8796 | | * Check for illegal attributes. |
8797 | | */ |
8798 | 0 | attr = node->properties; |
8799 | 0 | while (attr != NULL) { |
8800 | 0 | if (attr->ns == NULL) { |
8801 | 0 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
8802 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "itemType"))) { |
8803 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
8804 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
8805 | 0 | } |
8806 | 0 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
8807 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
8808 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
8809 | 0 | } |
8810 | 0 | attr = attr->next; |
8811 | 0 | } |
8812 | |
|
8813 | 0 | xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id"); |
8814 | | |
8815 | | /* |
8816 | | * Attribute "itemType". NOTE that we will use the "ref" and "refNs" |
8817 | | * fields for holding the reference to the itemType. |
8818 | | * |
8819 | | * REVAMP TODO: Use the "base" and "baseNs" fields, since we will remove |
8820 | | * the "ref" fields. |
8821 | | */ |
8822 | 0 | xmlSchemaPValAttrQName(ctxt, schema, NULL, |
8823 | 0 | node, "itemType", &(type->baseNs), &(type->base)); |
8824 | | /* |
8825 | | * And now for the children... |
8826 | | */ |
8827 | 0 | child = node->children; |
8828 | 0 | if (IS_SCHEMA(child, "annotation")) { |
8829 | 0 | xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) type, |
8830 | 0 | xmlSchemaParseAnnotation(ctxt, child, 1)); |
8831 | 0 | child = child->next; |
8832 | 0 | } |
8833 | 0 | if (IS_SCHEMA(child, "simpleType")) { |
8834 | | /* |
8835 | | * src-list-itemType-or-simpleType |
8836 | | * Either the itemType [attribute] or the <simpleType> [child] of |
8837 | | * the <list> element must be present, but not both. |
8838 | | */ |
8839 | 0 | if (type->base != NULL) { |
8840 | 0 | xmlSchemaPCustomErr(ctxt, |
8841 | 0 | XML_SCHEMAP_SRC_SIMPLE_TYPE_1, |
8842 | 0 | NULL, node, |
8843 | 0 | "The attribute 'itemType' and the <simpleType> child " |
8844 | 0 | "are mutually exclusive", NULL); |
8845 | 0 | } else { |
8846 | 0 | type->subtypes = xmlSchemaParseSimpleType(ctxt, schema, child, 0); |
8847 | 0 | } |
8848 | 0 | child = child->next; |
8849 | 0 | } else if (type->base == NULL) { |
8850 | 0 | xmlSchemaPCustomErr(ctxt, |
8851 | 0 | XML_SCHEMAP_SRC_SIMPLE_TYPE_1, |
8852 | 0 | NULL, node, |
8853 | 0 | "Either the attribute 'itemType' or the <simpleType> child " |
8854 | 0 | "must be present", NULL); |
8855 | 0 | } |
8856 | 0 | if (child != NULL) { |
8857 | 0 | xmlSchemaPContentErr(ctxt, |
8858 | 0 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
8859 | 0 | NULL, node, child, NULL, "(annotation?, simpleType?)"); |
8860 | 0 | } |
8861 | 0 | if ((type->base == NULL) && |
8862 | 0 | (type->subtypes == NULL) && |
8863 | 0 | (xmlSchemaGetPropNode(node, "itemType") == NULL)) { |
8864 | 0 | xmlSchemaPCustomErr(ctxt, |
8865 | 0 | XML_SCHEMAP_SRC_SIMPLE_TYPE_1, |
8866 | 0 | NULL, node, |
8867 | 0 | "Either the attribute 'itemType' or the <simpleType> child " |
8868 | 0 | "must be present", NULL); |
8869 | 0 | } |
8870 | 0 | return (NULL); |
8871 | 0 | } |
8872 | | |
8873 | | /** |
8874 | | * parse a XML schema Simple Type definition |
8875 | | * *WARNING* this interface is highly subject to change |
8876 | | * |
8877 | | * @param ctxt a schema validation context |
8878 | | * @param schema the schema being built |
8879 | | * @param node a subtree containing XML Schema information |
8880 | | * @param topLevel whether this is a top-level element |
8881 | | * @returns -1 in case of error, 0 if the declaration is improper and |
8882 | | * 1 in case of success. |
8883 | | */ |
8884 | | static xmlSchemaTypePtr |
8885 | | xmlSchemaParseSimpleType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
8886 | | xmlNodePtr node, int topLevel) |
8887 | 0 | { |
8888 | 0 | xmlSchemaTypePtr type, oldCtxtType; |
8889 | 0 | xmlNodePtr child = NULL; |
8890 | 0 | const xmlChar *attrValue = NULL; |
8891 | 0 | xmlAttrPtr attr; |
8892 | 0 | int hasRestriction = 0; |
8893 | |
|
8894 | 0 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
8895 | 0 | return (NULL); |
8896 | | |
8897 | 0 | if (topLevel) { |
8898 | 0 | attr = xmlSchemaGetPropNode(node, "name"); |
8899 | 0 | if (attr == NULL) { |
8900 | 0 | xmlSchemaPMissingAttrErr(ctxt, |
8901 | 0 | XML_SCHEMAP_S4S_ATTR_MISSING, |
8902 | 0 | NULL, node, |
8903 | 0 | "name", NULL); |
8904 | 0 | return (NULL); |
8905 | 0 | } else { |
8906 | 0 | if (xmlSchemaPValAttrNode(ctxt, |
8907 | 0 | NULL, attr, |
8908 | 0 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &attrValue) != 0) |
8909 | 0 | return (NULL); |
8910 | | /* |
8911 | | * Skip built-in types. |
8912 | | */ |
8913 | 0 | if (ctxt->isS4S) { |
8914 | 0 | xmlSchemaTypePtr biType; |
8915 | |
|
8916 | 0 | if (ctxt->isRedefine) { |
8917 | | /* |
8918 | | * REDEFINE: Disallow redefinition of built-in-types. |
8919 | | * TODO: It seems that the spec does not say anything |
8920 | | * about this case. |
8921 | | */ |
8922 | 0 | xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_SRC_REDEFINE, |
8923 | 0 | NULL, node, |
8924 | 0 | "Redefinition of built-in simple types is not " |
8925 | 0 | "supported", NULL); |
8926 | 0 | return(NULL); |
8927 | 0 | } |
8928 | 0 | biType = xmlSchemaGetPredefinedType(attrValue, xmlSchemaNs); |
8929 | 0 | if (biType != NULL) |
8930 | 0 | return (biType); |
8931 | 0 | } |
8932 | 0 | } |
8933 | 0 | } |
8934 | | /* |
8935 | | * TargetNamespace: |
8936 | | * SPEC "The `actual value` of the targetNamespace [attribute] |
8937 | | * of the <schema> ancestor element information item if present, |
8938 | | * otherwise `absent`. |
8939 | | */ |
8940 | 0 | if (topLevel == 0) { |
8941 | | #ifdef ENABLE_NAMED_LOCALS |
8942 | | char buf[40]; |
8943 | | #endif |
8944 | | /* |
8945 | | * Parse as local simple type definition. |
8946 | | */ |
8947 | | #ifdef ENABLE_NAMED_LOCALS |
8948 | | snprintf(buf, 39, "#ST%d", ctxt->counter++ + 1); |
8949 | | type = xmlSchemaAddType(ctxt, schema, |
8950 | | XML_SCHEMA_TYPE_SIMPLE, |
8951 | | xmlDictLookup(ctxt->dict, (const xmlChar *)buf, -1), |
8952 | | ctxt->targetNamespace, node, 0); |
8953 | | #else |
8954 | 0 | type = xmlSchemaAddType(ctxt, schema, |
8955 | 0 | XML_SCHEMA_TYPE_SIMPLE, |
8956 | 0 | NULL, ctxt->targetNamespace, node, 0); |
8957 | 0 | #endif |
8958 | 0 | if (type == NULL) |
8959 | 0 | return (NULL); |
8960 | 0 | type->type = XML_SCHEMA_TYPE_SIMPLE; |
8961 | 0 | type->contentType = XML_SCHEMA_CONTENT_SIMPLE; |
8962 | | /* |
8963 | | * Check for illegal attributes. |
8964 | | */ |
8965 | 0 | attr = node->properties; |
8966 | 0 | while (attr != NULL) { |
8967 | 0 | if (attr->ns == NULL) { |
8968 | 0 | if (!xmlStrEqual(attr->name, BAD_CAST "id")) { |
8969 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
8970 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
8971 | 0 | } |
8972 | 0 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
8973 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
8974 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
8975 | 0 | } |
8976 | 0 | attr = attr->next; |
8977 | 0 | } |
8978 | 0 | } else { |
8979 | | /* |
8980 | | * Parse as global simple type definition. |
8981 | | * |
8982 | | * Note that attrValue is the value of the attribute "name" here. |
8983 | | */ |
8984 | 0 | type = xmlSchemaAddType(ctxt, schema, XML_SCHEMA_TYPE_SIMPLE, |
8985 | 0 | attrValue, ctxt->targetNamespace, node, 1); |
8986 | 0 | if (type == NULL) |
8987 | 0 | return (NULL); |
8988 | 0 | type->type = XML_SCHEMA_TYPE_SIMPLE; |
8989 | 0 | type->contentType = XML_SCHEMA_CONTENT_SIMPLE; |
8990 | 0 | type->flags |= XML_SCHEMAS_TYPE_GLOBAL; |
8991 | | /* |
8992 | | * Check for illegal attributes. |
8993 | | */ |
8994 | 0 | attr = node->properties; |
8995 | 0 | while (attr != NULL) { |
8996 | 0 | if (attr->ns == NULL) { |
8997 | 0 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
8998 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "name")) && |
8999 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "final"))) { |
9000 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
9001 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
9002 | 0 | } |
9003 | 0 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
9004 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
9005 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
9006 | 0 | } |
9007 | 0 | attr = attr->next; |
9008 | 0 | } |
9009 | | /* |
9010 | | * Attribute "final". |
9011 | | */ |
9012 | 0 | attr = xmlSchemaGetPropNode(node, "final"); |
9013 | 0 | if (attr == NULL) { |
9014 | 0 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION) |
9015 | 0 | type->flags |= XML_SCHEMAS_TYPE_FINAL_RESTRICTION; |
9016 | 0 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_LIST) |
9017 | 0 | type->flags |= XML_SCHEMAS_TYPE_FINAL_LIST; |
9018 | 0 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_UNION) |
9019 | 0 | type->flags |= XML_SCHEMAS_TYPE_FINAL_UNION; |
9020 | 0 | } else { |
9021 | 0 | attrValue = xmlSchemaGetProp(ctxt, node, "final"); |
9022 | 0 | if (xmlSchemaPValAttrBlockFinal(attrValue, &(type->flags), |
9023 | 0 | -1, -1, XML_SCHEMAS_TYPE_FINAL_RESTRICTION, -1, |
9024 | 0 | XML_SCHEMAS_TYPE_FINAL_LIST, |
9025 | 0 | XML_SCHEMAS_TYPE_FINAL_UNION) != 0) { |
9026 | |
|
9027 | 0 | xmlSchemaPSimpleTypeErr(ctxt, |
9028 | 0 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
9029 | 0 | WXS_BASIC_CAST type, (xmlNodePtr) attr, |
9030 | 0 | NULL, "(#all | List of (list | union | restriction)", |
9031 | 0 | attrValue, NULL, NULL, NULL); |
9032 | 0 | } |
9033 | 0 | } |
9034 | 0 | } |
9035 | 0 | type->targetNamespace = ctxt->targetNamespace; |
9036 | 0 | xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id"); |
9037 | | /* |
9038 | | * And now for the children... |
9039 | | */ |
9040 | 0 | oldCtxtType = ctxt->ctxtType; |
9041 | |
|
9042 | 0 | ctxt->ctxtType = type; |
9043 | |
|
9044 | 0 | child = node->children; |
9045 | 0 | if (IS_SCHEMA(child, "annotation")) { |
9046 | 0 | type->annot = xmlSchemaParseAnnotation(ctxt, child, 1); |
9047 | 0 | child = child->next; |
9048 | 0 | } |
9049 | 0 | if (child == NULL) { |
9050 | 0 | xmlSchemaPContentErr(ctxt, XML_SCHEMAP_S4S_ELEM_MISSING, |
9051 | 0 | NULL, node, child, NULL, |
9052 | 0 | "(annotation?, (restriction | list | union))"); |
9053 | 0 | } else if (IS_SCHEMA(child, "restriction")) { |
9054 | 0 | xmlSchemaParseRestriction(ctxt, schema, child, |
9055 | 0 | XML_SCHEMA_TYPE_SIMPLE); |
9056 | 0 | hasRestriction = 1; |
9057 | 0 | child = child->next; |
9058 | 0 | } else if (IS_SCHEMA(child, "list")) { |
9059 | 0 | xmlSchemaParseList(ctxt, schema, child); |
9060 | 0 | child = child->next; |
9061 | 0 | } else if (IS_SCHEMA(child, "union")) { |
9062 | 0 | xmlSchemaParseUnion(ctxt, schema, child); |
9063 | 0 | child = child->next; |
9064 | 0 | } |
9065 | 0 | if (child != NULL) { |
9066 | 0 | xmlSchemaPContentErr(ctxt, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
9067 | 0 | NULL, node, child, NULL, |
9068 | 0 | "(annotation?, (restriction | list | union))"); |
9069 | 0 | } |
9070 | | /* |
9071 | | * REDEFINE: SPEC src-redefine (5) |
9072 | | * "Within the [children], each <simpleType> must have a |
9073 | | * <restriction> among its [children] ... the `actual value` of whose |
9074 | | * base [attribute] must be the same as the `actual value` of its own |
9075 | | * name attribute plus target namespace;" |
9076 | | */ |
9077 | 0 | if (topLevel && ctxt->isRedefine && (! hasRestriction)) { |
9078 | 0 | xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_SRC_REDEFINE, |
9079 | 0 | NULL, node, "This is a redefinition, thus the " |
9080 | 0 | "<simpleType> must have a <restriction> child", NULL); |
9081 | 0 | } |
9082 | |
|
9083 | 0 | ctxt->ctxtType = oldCtxtType; |
9084 | 0 | return (type); |
9085 | 0 | } |
9086 | | |
9087 | | /** |
9088 | | * Parses a reference to a model group definition. |
9089 | | * |
9090 | | * We will return a particle component with a qname-component or |
9091 | | * NULL in case of an error. |
9092 | | * |
9093 | | * @param ctxt the parser context |
9094 | | * @param schema the schema being built |
9095 | | * @param node the node |
9096 | | */ |
9097 | | static xmlSchemaTreeItemPtr |
9098 | | xmlSchemaParseModelGroupDefRef(xmlSchemaParserCtxtPtr ctxt, |
9099 | | xmlSchemaPtr schema, |
9100 | | xmlNodePtr node) |
9101 | 0 | { |
9102 | 0 | xmlSchemaParticlePtr item; |
9103 | 0 | xmlNodePtr child = NULL; |
9104 | 0 | xmlAttrPtr attr; |
9105 | 0 | const xmlChar *ref = NULL, *refNs = NULL; |
9106 | 0 | int min, max; |
9107 | |
|
9108 | 0 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
9109 | 0 | return (NULL); |
9110 | | |
9111 | 0 | attr = xmlSchemaGetPropNode(node, "ref"); |
9112 | 0 | if (attr == NULL) { |
9113 | 0 | xmlSchemaPMissingAttrErr(ctxt, |
9114 | 0 | XML_SCHEMAP_S4S_ATTR_MISSING, |
9115 | 0 | NULL, node, "ref", NULL); |
9116 | 0 | return (NULL); |
9117 | 0 | } else if (xmlSchemaPValAttrNodeQName(ctxt, schema, NULL, |
9118 | 0 | attr, &refNs, &ref) != 0) { |
9119 | 0 | return (NULL); |
9120 | 0 | } |
9121 | 0 | xmlSchemaCheckReference(ctxt, schema, node, attr, refNs); |
9122 | 0 | min = xmlGetMinOccurs(ctxt, node, 0, -1, 1, "xs:nonNegativeInteger"); |
9123 | 0 | max = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1, |
9124 | 0 | "(xs:nonNegativeInteger | unbounded)"); |
9125 | | /* |
9126 | | * Check for illegal attributes. |
9127 | | */ |
9128 | 0 | attr = node->properties; |
9129 | 0 | while (attr != NULL) { |
9130 | 0 | if (attr->ns == NULL) { |
9131 | 0 | if ((!xmlStrEqual(attr->name, BAD_CAST "ref")) && |
9132 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "id")) && |
9133 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "minOccurs")) && |
9134 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "maxOccurs"))) { |
9135 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
9136 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
9137 | 0 | } |
9138 | 0 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
9139 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
9140 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
9141 | 0 | } |
9142 | 0 | attr = attr->next; |
9143 | 0 | } |
9144 | 0 | xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id"); |
9145 | 0 | item = xmlSchemaAddParticle(ctxt, node, min, max); |
9146 | 0 | if (item == NULL) |
9147 | 0 | return (NULL); |
9148 | | /* |
9149 | | * Create a qname-reference and set as the term; it will be substituted |
9150 | | * for the model group after the reference has been resolved. |
9151 | | */ |
9152 | 0 | item->children = (xmlSchemaTreeItemPtr) |
9153 | 0 | xmlSchemaNewQNameRef(ctxt, XML_SCHEMA_TYPE_GROUP, ref, refNs); |
9154 | 0 | xmlSchemaPCheckParticleCorrect_2(ctxt, item, node, min, max); |
9155 | | /* |
9156 | | * And now for the children... |
9157 | | */ |
9158 | 0 | child = node->children; |
9159 | | /* TODO: Is annotation even allowed for a model group reference? */ |
9160 | 0 | if (IS_SCHEMA(child, "annotation")) { |
9161 | | /* |
9162 | | * TODO: What to do exactly with the annotation? |
9163 | | */ |
9164 | 0 | item->annot = xmlSchemaParseAnnotation(ctxt, child, 1); |
9165 | 0 | child = child->next; |
9166 | 0 | } |
9167 | 0 | if (child != NULL) { |
9168 | 0 | xmlSchemaPContentErr(ctxt, |
9169 | 0 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
9170 | 0 | NULL, node, child, NULL, |
9171 | 0 | "(annotation?)"); |
9172 | 0 | } |
9173 | | /* |
9174 | | * Corresponds to no component at all if minOccurs==maxOccurs==0. |
9175 | | */ |
9176 | 0 | if ((min == 0) && (max == 0)) |
9177 | 0 | return (NULL); |
9178 | | |
9179 | 0 | return ((xmlSchemaTreeItemPtr) item); |
9180 | 0 | } |
9181 | | |
9182 | | /** |
9183 | | * Parses a XML schema model group definition. |
9184 | | * |
9185 | | * Note that the constraint src-redefine (6.2) can't be applied until |
9186 | | * references have been resolved. So we will do this at the |
9187 | | * component fixup level. |
9188 | | * |
9189 | | * *WARNING* this interface is highly subject to change |
9190 | | * |
9191 | | * @param ctxt a schema validation context |
9192 | | * @param schema the schema being built |
9193 | | * @param node a subtree containing XML Schema information |
9194 | | * @returns -1 in case of error, 0 if the declaration is improper and |
9195 | | * 1 in case of success. |
9196 | | */ |
9197 | | static xmlSchemaModelGroupDefPtr |
9198 | | xmlSchemaParseModelGroupDefinition(xmlSchemaParserCtxtPtr ctxt, |
9199 | | xmlSchemaPtr schema, |
9200 | | xmlNodePtr node) |
9201 | 0 | { |
9202 | 0 | xmlSchemaModelGroupDefPtr item; |
9203 | 0 | xmlNodePtr child = NULL; |
9204 | 0 | xmlAttrPtr attr; |
9205 | 0 | const xmlChar *name; |
9206 | |
|
9207 | 0 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
9208 | 0 | return (NULL); |
9209 | | |
9210 | 0 | attr = xmlSchemaGetPropNode(node, "name"); |
9211 | 0 | if (attr == NULL) { |
9212 | 0 | xmlSchemaPMissingAttrErr(ctxt, |
9213 | 0 | XML_SCHEMAP_S4S_ATTR_MISSING, |
9214 | 0 | NULL, node, |
9215 | 0 | "name", NULL); |
9216 | 0 | return (NULL); |
9217 | 0 | } else if (xmlSchemaPValAttrNode(ctxt, NULL, attr, |
9218 | 0 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) { |
9219 | 0 | return (NULL); |
9220 | 0 | } |
9221 | 0 | item = xmlSchemaAddModelGroupDefinition(ctxt, schema, name, |
9222 | 0 | ctxt->targetNamespace, node); |
9223 | 0 | if (item == NULL) |
9224 | 0 | return (NULL); |
9225 | | /* |
9226 | | * Check for illegal attributes. |
9227 | | */ |
9228 | 0 | attr = node->properties; |
9229 | 0 | while (attr != NULL) { |
9230 | 0 | if (attr->ns == NULL) { |
9231 | 0 | if ((!xmlStrEqual(attr->name, BAD_CAST "name")) && |
9232 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "id"))) { |
9233 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
9234 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
9235 | 0 | } |
9236 | 0 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
9237 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
9238 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
9239 | 0 | } |
9240 | 0 | attr = attr->next; |
9241 | 0 | } |
9242 | 0 | xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id"); |
9243 | | /* |
9244 | | * And now for the children... |
9245 | | */ |
9246 | 0 | child = node->children; |
9247 | 0 | if (IS_SCHEMA(child, "annotation")) { |
9248 | 0 | item->annot = xmlSchemaParseAnnotation(ctxt, child, 1); |
9249 | 0 | child = child->next; |
9250 | 0 | } |
9251 | 0 | if (IS_SCHEMA(child, "all")) { |
9252 | 0 | item->children = xmlSchemaParseModelGroup(ctxt, schema, child, |
9253 | 0 | XML_SCHEMA_TYPE_ALL, 0); |
9254 | 0 | child = child->next; |
9255 | 0 | } else if (IS_SCHEMA(child, "choice")) { |
9256 | 0 | item->children = xmlSchemaParseModelGroup(ctxt, schema, child, |
9257 | 0 | XML_SCHEMA_TYPE_CHOICE, 0); |
9258 | 0 | child = child->next; |
9259 | 0 | } else if (IS_SCHEMA(child, "sequence")) { |
9260 | 0 | item->children = xmlSchemaParseModelGroup(ctxt, schema, child, |
9261 | 0 | XML_SCHEMA_TYPE_SEQUENCE, 0); |
9262 | 0 | child = child->next; |
9263 | 0 | } |
9264 | | |
9265 | | |
9266 | |
|
9267 | 0 | if (child != NULL) { |
9268 | 0 | xmlSchemaPContentErr(ctxt, |
9269 | 0 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
9270 | 0 | NULL, node, child, NULL, |
9271 | 0 | "(annotation?, (all | choice | sequence)?)"); |
9272 | 0 | } |
9273 | 0 | return (item); |
9274 | 0 | } |
9275 | | |
9276 | | /** |
9277 | | * removes unwanted nodes in a schemas document tree |
9278 | | * |
9279 | | * @param ctxt a schema validation context |
9280 | | * @param root the root of the document. |
9281 | | */ |
9282 | | static void |
9283 | | xmlSchemaCleanupDoc(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr root) |
9284 | 0 | { |
9285 | 0 | xmlNodePtr delete, cur; |
9286 | |
|
9287 | 0 | if ((ctxt == NULL) || (root == NULL)) return; |
9288 | | |
9289 | | /* |
9290 | | * Remove all the blank text nodes |
9291 | | */ |
9292 | 0 | delete = NULL; |
9293 | 0 | cur = root; |
9294 | 0 | while (cur != NULL) { |
9295 | 0 | if (delete != NULL) { |
9296 | 0 | xmlUnlinkNode(delete); |
9297 | 0 | xmlFreeNode(delete); |
9298 | 0 | delete = NULL; |
9299 | 0 | } |
9300 | 0 | if (cur->type == XML_TEXT_NODE) { |
9301 | 0 | if (IS_BLANK_NODE(cur)) { |
9302 | 0 | if (xmlNodeGetSpacePreserve(cur) != 1) { |
9303 | 0 | delete = cur; |
9304 | 0 | } |
9305 | 0 | } |
9306 | 0 | } else if ((cur->type != XML_ELEMENT_NODE) && |
9307 | 0 | (cur->type != XML_CDATA_SECTION_NODE)) { |
9308 | 0 | delete = cur; |
9309 | 0 | goto skip_children; |
9310 | 0 | } |
9311 | | |
9312 | | /* |
9313 | | * Skip to next node |
9314 | | */ |
9315 | 0 | if (cur->children != NULL) { |
9316 | 0 | if ((cur->children->type != XML_ENTITY_DECL) && |
9317 | 0 | (cur->children->type != XML_ENTITY_REF_NODE) && |
9318 | 0 | (cur->children->type != XML_ENTITY_NODE)) { |
9319 | 0 | cur = cur->children; |
9320 | 0 | continue; |
9321 | 0 | } |
9322 | 0 | } |
9323 | 0 | skip_children: |
9324 | 0 | if (cur->next != NULL) { |
9325 | 0 | cur = cur->next; |
9326 | 0 | continue; |
9327 | 0 | } |
9328 | | |
9329 | 0 | do { |
9330 | 0 | cur = cur->parent; |
9331 | 0 | if (cur == NULL) |
9332 | 0 | break; |
9333 | 0 | if (cur == root) { |
9334 | 0 | cur = NULL; |
9335 | 0 | break; |
9336 | 0 | } |
9337 | 0 | if (cur->next != NULL) { |
9338 | 0 | cur = cur->next; |
9339 | 0 | break; |
9340 | 0 | } |
9341 | 0 | } while (cur != NULL); |
9342 | 0 | } |
9343 | 0 | if (delete != NULL) { |
9344 | 0 | xmlUnlinkNode(delete); |
9345 | 0 | xmlFreeNode(delete); |
9346 | 0 | delete = NULL; |
9347 | 0 | } |
9348 | 0 | } |
9349 | | |
9350 | | |
9351 | | static void |
9352 | | xmlSchemaClearSchemaDefaults(xmlSchemaPtr schema) |
9353 | 0 | { |
9354 | 0 | if (schema->flags & XML_SCHEMAS_QUALIF_ELEM) |
9355 | 0 | schema->flags ^= XML_SCHEMAS_QUALIF_ELEM; |
9356 | |
|
9357 | 0 | if (schema->flags & XML_SCHEMAS_QUALIF_ATTR) |
9358 | 0 | schema->flags ^= XML_SCHEMAS_QUALIF_ATTR; |
9359 | |
|
9360 | 0 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_EXTENSION) |
9361 | 0 | schema->flags ^= XML_SCHEMAS_FINAL_DEFAULT_EXTENSION; |
9362 | 0 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION) |
9363 | 0 | schema->flags ^= XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION; |
9364 | 0 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_LIST) |
9365 | 0 | schema->flags ^= XML_SCHEMAS_FINAL_DEFAULT_LIST; |
9366 | 0 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_UNION) |
9367 | 0 | schema->flags ^= XML_SCHEMAS_FINAL_DEFAULT_UNION; |
9368 | |
|
9369 | 0 | if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION) |
9370 | 0 | schema->flags ^= XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION; |
9371 | 0 | if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION) |
9372 | 0 | schema->flags ^= XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION; |
9373 | 0 | if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION) |
9374 | 0 | schema->flags ^= XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION; |
9375 | 0 | } |
9376 | | |
9377 | | static int |
9378 | | xmlSchemaParseSchemaElement(xmlSchemaParserCtxtPtr ctxt, |
9379 | | xmlSchemaPtr schema, |
9380 | | xmlNodePtr node) |
9381 | 0 | { |
9382 | 0 | xmlAttrPtr attr; |
9383 | 0 | const xmlChar *val; |
9384 | 0 | int res = 0, oldErrs = ctxt->nberrors; |
9385 | | |
9386 | | /* |
9387 | | * Those flags should be moved to the parser context flags, |
9388 | | * since they are not visible at the component level. I.e. |
9389 | | * they are used if processing schema *documents* only. |
9390 | | */ |
9391 | 0 | res = xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id"); |
9392 | 0 | HFAILURE; |
9393 | | |
9394 | | /* |
9395 | | * Since the version is of type xs:token, we won't bother to |
9396 | | * check it. |
9397 | | */ |
9398 | | /* REMOVED: |
9399 | | attr = xmlSchemaGetPropNode(node, "version"); |
9400 | | if (attr != NULL) { |
9401 | | res = xmlSchemaPValAttrNode(ctxt, NULL, NULL, attr, |
9402 | | xmlSchemaGetBuiltInType(XML_SCHEMAS_TOKEN), &val); |
9403 | | HFAILURE; |
9404 | | } |
9405 | | */ |
9406 | 0 | attr = xmlSchemaGetPropNode(node, "targetNamespace"); |
9407 | 0 | if (attr != NULL) { |
9408 | 0 | res = xmlSchemaPValAttrNode(ctxt, NULL, attr, |
9409 | 0 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), NULL); |
9410 | 0 | HFAILURE; |
9411 | 0 | if (res != 0) { |
9412 | 0 | ctxt->stop = XML_SCHEMAP_S4S_ATTR_INVALID_VALUE; |
9413 | 0 | goto exit; |
9414 | 0 | } |
9415 | 0 | } |
9416 | 0 | attr = xmlSchemaGetPropNode(node, "elementFormDefault"); |
9417 | 0 | if (attr != NULL) { |
9418 | 0 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
9419 | 0 | res = xmlSchemaPValAttrFormDefault(val, &schema->flags, |
9420 | 0 | XML_SCHEMAS_QUALIF_ELEM); |
9421 | 0 | HFAILURE; |
9422 | 0 | if (res != 0) { |
9423 | 0 | xmlSchemaPSimpleTypeErr(ctxt, |
9424 | 0 | XML_SCHEMAP_ELEMFORMDEFAULT_VALUE, |
9425 | 0 | NULL, (xmlNodePtr) attr, NULL, |
9426 | 0 | "(qualified | unqualified)", val, NULL, NULL, NULL); |
9427 | 0 | } |
9428 | 0 | } |
9429 | 0 | attr = xmlSchemaGetPropNode(node, "attributeFormDefault"); |
9430 | 0 | if (attr != NULL) { |
9431 | 0 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
9432 | 0 | res = xmlSchemaPValAttrFormDefault(val, &schema->flags, |
9433 | 0 | XML_SCHEMAS_QUALIF_ATTR); |
9434 | 0 | HFAILURE; |
9435 | 0 | if (res != 0) { |
9436 | 0 | xmlSchemaPSimpleTypeErr(ctxt, |
9437 | 0 | XML_SCHEMAP_ATTRFORMDEFAULT_VALUE, |
9438 | 0 | NULL, (xmlNodePtr) attr, NULL, |
9439 | 0 | "(qualified | unqualified)", val, NULL, NULL, NULL); |
9440 | 0 | } |
9441 | 0 | } |
9442 | 0 | attr = xmlSchemaGetPropNode(node, "finalDefault"); |
9443 | 0 | if (attr != NULL) { |
9444 | 0 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
9445 | 0 | res = xmlSchemaPValAttrBlockFinal(val, &(schema->flags), -1, |
9446 | 0 | XML_SCHEMAS_FINAL_DEFAULT_EXTENSION, |
9447 | 0 | XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION, |
9448 | 0 | -1, |
9449 | 0 | XML_SCHEMAS_FINAL_DEFAULT_LIST, |
9450 | 0 | XML_SCHEMAS_FINAL_DEFAULT_UNION); |
9451 | 0 | HFAILURE; |
9452 | 0 | if (res != 0) { |
9453 | 0 | xmlSchemaPSimpleTypeErr(ctxt, |
9454 | 0 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
9455 | 0 | NULL, (xmlNodePtr) attr, NULL, |
9456 | 0 | "(#all | List of (extension | restriction | list | union))", |
9457 | 0 | val, NULL, NULL, NULL); |
9458 | 0 | } |
9459 | 0 | } |
9460 | 0 | attr = xmlSchemaGetPropNode(node, "blockDefault"); |
9461 | 0 | if (attr != NULL) { |
9462 | 0 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
9463 | 0 | res = xmlSchemaPValAttrBlockFinal(val, &(schema->flags), -1, |
9464 | 0 | XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION, |
9465 | 0 | XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION, |
9466 | 0 | XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION, -1, -1); |
9467 | 0 | HFAILURE; |
9468 | 0 | if (res != 0) { |
9469 | 0 | xmlSchemaPSimpleTypeErr(ctxt, |
9470 | 0 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
9471 | 0 | NULL, (xmlNodePtr) attr, NULL, |
9472 | 0 | "(#all | List of (extension | restriction | substitution))", |
9473 | 0 | val, NULL, NULL, NULL); |
9474 | 0 | } |
9475 | 0 | } |
9476 | | |
9477 | 0 | exit: |
9478 | 0 | if (oldErrs != ctxt->nberrors) |
9479 | 0 | res = ctxt->err; |
9480 | 0 | return(res); |
9481 | 0 | exit_failure: |
9482 | 0 | return(-1); |
9483 | 0 | } |
9484 | | |
9485 | | /** |
9486 | | * @param ctxt a schema validation context |
9487 | | * @param schema the schemas |
9488 | | * @param nodes the list of top level nodes |
9489 | | * @returns the internal XML Schema structure built from the resource or |
9490 | | * NULL in case of error |
9491 | | */ |
9492 | | static int |
9493 | | xmlSchemaParseSchemaTopLevel(xmlSchemaParserCtxtPtr ctxt, |
9494 | | xmlSchemaPtr schema, xmlNodePtr nodes) |
9495 | 0 | { |
9496 | 0 | xmlNodePtr child; |
9497 | 0 | xmlSchemaAnnotPtr annot; |
9498 | 0 | int res = 0, oldErrs, tmpOldErrs; |
9499 | |
|
9500 | 0 | if ((ctxt == NULL) || (schema == NULL) || (nodes == NULL)) |
9501 | 0 | return(-1); |
9502 | | |
9503 | 0 | oldErrs = ctxt->nberrors; |
9504 | 0 | child = nodes; |
9505 | 0 | while ((IS_SCHEMA(child, "include")) || |
9506 | 0 | (IS_SCHEMA(child, "import")) || |
9507 | 0 | (IS_SCHEMA(child, "redefine")) || |
9508 | 0 | (IS_SCHEMA(child, "annotation"))) { |
9509 | 0 | if (IS_SCHEMA(child, "annotation")) { |
9510 | 0 | annot = xmlSchemaParseAnnotation(ctxt, child, 1); |
9511 | 0 | if (schema->annot == NULL) |
9512 | 0 | schema->annot = annot; |
9513 | 0 | else |
9514 | 0 | xmlSchemaFreeAnnot(annot); |
9515 | 0 | } else if (IS_SCHEMA(child, "import")) { |
9516 | 0 | tmpOldErrs = ctxt->nberrors; |
9517 | 0 | res = xmlSchemaParseImport(ctxt, schema, child); |
9518 | 0 | HFAILURE; |
9519 | 0 | HSTOP(ctxt); |
9520 | 0 | if (tmpOldErrs != ctxt->nberrors) |
9521 | 0 | goto exit; |
9522 | 0 | } else if (IS_SCHEMA(child, "include")) { |
9523 | 0 | tmpOldErrs = ctxt->nberrors; |
9524 | 0 | res = xmlSchemaParseInclude(ctxt, schema, child); |
9525 | 0 | HFAILURE; |
9526 | 0 | HSTOP(ctxt); |
9527 | 0 | if (tmpOldErrs != ctxt->nberrors) |
9528 | 0 | goto exit; |
9529 | 0 | } else if (IS_SCHEMA(child, "redefine")) { |
9530 | 0 | tmpOldErrs = ctxt->nberrors; |
9531 | 0 | res = xmlSchemaParseRedefine(ctxt, schema, child); |
9532 | 0 | HFAILURE; |
9533 | 0 | HSTOP(ctxt); |
9534 | 0 | if (tmpOldErrs != ctxt->nberrors) |
9535 | 0 | goto exit; |
9536 | 0 | } |
9537 | 0 | child = child->next; |
9538 | 0 | } |
9539 | | /* |
9540 | | * URGENT TODO: Change the functions to return int results. |
9541 | | * We need especially to catch internal errors. |
9542 | | */ |
9543 | 0 | while (child != NULL) { |
9544 | 0 | if (IS_SCHEMA(child, "complexType")) { |
9545 | 0 | xmlSchemaParseComplexType(ctxt, schema, child, 1); |
9546 | 0 | child = child->next; |
9547 | 0 | } else if (IS_SCHEMA(child, "simpleType")) { |
9548 | 0 | xmlSchemaParseSimpleType(ctxt, schema, child, 1); |
9549 | 0 | child = child->next; |
9550 | 0 | } else if (IS_SCHEMA(child, "element")) { |
9551 | 0 | xmlSchemaParseElement(ctxt, schema, child, NULL, 1); |
9552 | 0 | child = child->next; |
9553 | 0 | } else if (IS_SCHEMA(child, "attribute")) { |
9554 | 0 | xmlSchemaParseGlobalAttribute(ctxt, schema, child); |
9555 | 0 | child = child->next; |
9556 | 0 | } else if (IS_SCHEMA(child, "attributeGroup")) { |
9557 | 0 | xmlSchemaParseAttributeGroupDefinition(ctxt, schema, child); |
9558 | 0 | child = child->next; |
9559 | 0 | } else if (IS_SCHEMA(child, "group")) { |
9560 | 0 | xmlSchemaParseModelGroupDefinition(ctxt, schema, child); |
9561 | 0 | child = child->next; |
9562 | 0 | } else if (IS_SCHEMA(child, "notation")) { |
9563 | 0 | xmlSchemaParseNotation(ctxt, schema, child); |
9564 | 0 | child = child->next; |
9565 | 0 | } else { |
9566 | 0 | xmlSchemaPContentErr(ctxt, |
9567 | 0 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
9568 | 0 | NULL, child->parent, child, |
9569 | 0 | NULL, "((include | import | redefine | annotation)*, " |
9570 | 0 | "(((simpleType | complexType | group | attributeGroup) " |
9571 | 0 | "| element | attribute | notation), annotation*)*)"); |
9572 | 0 | child = child->next; |
9573 | 0 | } |
9574 | 0 | while (IS_SCHEMA(child, "annotation")) { |
9575 | | /* |
9576 | | * TODO: We should add all annotations. |
9577 | | */ |
9578 | 0 | annot = xmlSchemaParseAnnotation(ctxt, child, 1); |
9579 | 0 | if (schema->annot == NULL) |
9580 | 0 | schema->annot = annot; |
9581 | 0 | else |
9582 | 0 | xmlSchemaFreeAnnot(annot); |
9583 | 0 | child = child->next; |
9584 | 0 | } |
9585 | 0 | } |
9586 | 0 | exit: |
9587 | 0 | ctxt->ctxtType = NULL; |
9588 | 0 | if (oldErrs != ctxt->nberrors) |
9589 | 0 | res = ctxt->err; |
9590 | 0 | return(res); |
9591 | 0 | exit_failure: |
9592 | 0 | return(-1); |
9593 | 0 | } |
9594 | | |
9595 | | static xmlSchemaSchemaRelationPtr |
9596 | | xmlSchemaSchemaRelationCreate(void) |
9597 | 0 | { |
9598 | 0 | xmlSchemaSchemaRelationPtr ret; |
9599 | |
|
9600 | 0 | ret = (xmlSchemaSchemaRelationPtr) |
9601 | 0 | xmlMalloc(sizeof(xmlSchemaSchemaRelation)); |
9602 | 0 | if (ret == NULL) { |
9603 | 0 | xmlSchemaPErrMemory(NULL); |
9604 | 0 | return(NULL); |
9605 | 0 | } |
9606 | 0 | memset(ret, 0, sizeof(xmlSchemaSchemaRelation)); |
9607 | 0 | return(ret); |
9608 | 0 | } |
9609 | | |
9610 | | #if 0 |
9611 | | static void |
9612 | | xmlSchemaSchemaRelationFree(xmlSchemaSchemaRelationPtr rel) |
9613 | | { |
9614 | | xmlFree(rel); |
9615 | | } |
9616 | | #endif |
9617 | | |
9618 | | static void |
9619 | | xmlSchemaRedefListFree(xmlSchemaRedefPtr redef) |
9620 | 0 | { |
9621 | 0 | xmlSchemaRedefPtr prev; |
9622 | |
|
9623 | 0 | while (redef != NULL) { |
9624 | 0 | prev = redef; |
9625 | 0 | redef = redef->next; |
9626 | 0 | xmlFree(prev); |
9627 | 0 | } |
9628 | 0 | } |
9629 | | |
9630 | | static void |
9631 | | xmlSchemaConstructionCtxtFree(xmlSchemaConstructionCtxtPtr con) |
9632 | 0 | { |
9633 | | /* |
9634 | | * After the construction context has been freed, there will be |
9635 | | * no schema graph available any more. Only the schema buckets |
9636 | | * will stay alive, which are put into the "schemasImports" and |
9637 | | * "includes" slots of the xmlSchema. |
9638 | | */ |
9639 | 0 | if (con->buckets != NULL) |
9640 | 0 | xmlSchemaItemListFree(con->buckets); |
9641 | 0 | if (con->pending != NULL) |
9642 | 0 | xmlSchemaItemListFree(con->pending); |
9643 | 0 | if (con->substGroups != NULL) |
9644 | 0 | xmlHashFree(con->substGroups, xmlSchemaSubstGroupFreeEntry); |
9645 | 0 | if (con->redefs != NULL) |
9646 | 0 | xmlSchemaRedefListFree(con->redefs); |
9647 | 0 | if (con->dict != NULL) |
9648 | 0 | xmlDictFree(con->dict); |
9649 | 0 | xmlFree(con); |
9650 | 0 | } |
9651 | | |
9652 | | static xmlSchemaConstructionCtxtPtr |
9653 | | xmlSchemaConstructionCtxtCreate(xmlDictPtr dict) |
9654 | 0 | { |
9655 | 0 | xmlSchemaConstructionCtxtPtr ret; |
9656 | |
|
9657 | 0 | ret = (xmlSchemaConstructionCtxtPtr) |
9658 | 0 | xmlMalloc(sizeof(xmlSchemaConstructionCtxt)); |
9659 | 0 | if (ret == NULL) { |
9660 | 0 | xmlSchemaPErrMemory(NULL); |
9661 | 0 | return (NULL); |
9662 | 0 | } |
9663 | 0 | memset(ret, 0, sizeof(xmlSchemaConstructionCtxt)); |
9664 | |
|
9665 | 0 | ret->buckets = xmlSchemaItemListCreate(); |
9666 | 0 | if (ret->buckets == NULL) { |
9667 | 0 | xmlSchemaPErrMemory(NULL); |
9668 | 0 | xmlFree(ret); |
9669 | 0 | return (NULL); |
9670 | 0 | } |
9671 | 0 | ret->pending = xmlSchemaItemListCreate(); |
9672 | 0 | if (ret->pending == NULL) { |
9673 | 0 | xmlSchemaPErrMemory(NULL); |
9674 | 0 | xmlSchemaConstructionCtxtFree(ret); |
9675 | 0 | return (NULL); |
9676 | 0 | } |
9677 | 0 | ret->dict = dict; |
9678 | 0 | xmlDictReference(dict); |
9679 | 0 | return(ret); |
9680 | 0 | } |
9681 | | |
9682 | | static xmlSchemaParserCtxtPtr |
9683 | | xmlSchemaParserCtxtCreate(void) |
9684 | 0 | { |
9685 | 0 | xmlSchemaParserCtxtPtr ret; |
9686 | |
|
9687 | 0 | ret = (xmlSchemaParserCtxtPtr) xmlMalloc(sizeof(xmlSchemaParserCtxt)); |
9688 | 0 | if (ret == NULL) { |
9689 | 0 | xmlSchemaPErrMemory(NULL); |
9690 | 0 | return (NULL); |
9691 | 0 | } |
9692 | 0 | memset(ret, 0, sizeof(xmlSchemaParserCtxt)); |
9693 | 0 | ret->type = XML_SCHEMA_CTXT_PARSER; |
9694 | 0 | ret->attrProhibs = xmlSchemaItemListCreate(); |
9695 | 0 | if (ret->attrProhibs == NULL) { |
9696 | 0 | xmlFree(ret); |
9697 | 0 | return(NULL); |
9698 | 0 | } |
9699 | 0 | return(ret); |
9700 | 0 | } |
9701 | | |
9702 | | /** |
9703 | | * Create an XML Schemas parse context for that file/resource expected |
9704 | | * to contain an XML Schemas file. |
9705 | | * |
9706 | | * @param URL the location of the schema |
9707 | | * @param dict the dictionary to be used |
9708 | | * @returns the parser context or NULL in case of error |
9709 | | */ |
9710 | | static xmlSchemaParserCtxtPtr |
9711 | | xmlSchemaNewParserCtxtUseDict(const char *URL, xmlDictPtr dict) |
9712 | 0 | { |
9713 | 0 | xmlSchemaParserCtxtPtr ret; |
9714 | |
|
9715 | 0 | ret = xmlSchemaParserCtxtCreate(); |
9716 | 0 | if (ret == NULL) |
9717 | 0 | return (NULL); |
9718 | 0 | ret->dict = dict; |
9719 | 0 | xmlDictReference(dict); |
9720 | 0 | if (URL != NULL) |
9721 | 0 | ret->URL = xmlDictLookup(dict, (const xmlChar *) URL, -1); |
9722 | 0 | return (ret); |
9723 | 0 | } |
9724 | | |
9725 | | static int |
9726 | | xmlSchemaCreatePCtxtOnVCtxt(xmlSchemaValidCtxtPtr vctxt) |
9727 | 0 | { |
9728 | 0 | if (vctxt->pctxt == NULL) { |
9729 | 0 | if (vctxt->schema != NULL) |
9730 | 0 | vctxt->pctxt = |
9731 | 0 | xmlSchemaNewParserCtxtUseDict("*", vctxt->schema->dict); |
9732 | 0 | else |
9733 | 0 | vctxt->pctxt = xmlSchemaNewParserCtxt("*"); |
9734 | 0 | if (vctxt->pctxt == NULL) { |
9735 | 0 | VERROR_INT("xmlSchemaCreatePCtxtOnVCtxt", |
9736 | 0 | "failed to create a temp. parser context"); |
9737 | 0 | return (-1); |
9738 | 0 | } |
9739 | | /* TODO: Pass user data. */ |
9740 | 0 | xmlSchemaSetParserErrors(vctxt->pctxt, vctxt->error, |
9741 | 0 | vctxt->warning, vctxt->errCtxt); |
9742 | 0 | xmlSchemaSetParserStructuredErrors(vctxt->pctxt, vctxt->serror, |
9743 | 0 | vctxt->errCtxt); |
9744 | 0 | } |
9745 | 0 | return (0); |
9746 | 0 | } |
9747 | | |
9748 | | /** |
9749 | | * @param pctxt the schema parser context |
9750 | | * @param schemaLocation the URI of the schema document |
9751 | | * @returns a schema bucket if it was already parsed from |
9752 | | * `schemaLocation`, NULL otherwise. |
9753 | | */ |
9754 | | static xmlSchemaBucketPtr |
9755 | | xmlSchemaGetSchemaBucket(xmlSchemaParserCtxtPtr pctxt, |
9756 | | const xmlChar *schemaLocation) |
9757 | 0 | { |
9758 | 0 | xmlSchemaBucketPtr cur; |
9759 | 0 | xmlSchemaItemListPtr list; |
9760 | |
|
9761 | 0 | list = pctxt->constructor->buckets; |
9762 | 0 | if (list->nbItems == 0) |
9763 | 0 | return(NULL); |
9764 | 0 | else { |
9765 | 0 | int i; |
9766 | 0 | for (i = 0; i < list->nbItems; i++) { |
9767 | 0 | cur = (xmlSchemaBucketPtr) list->items[i]; |
9768 | | /* Pointer comparison! */ |
9769 | 0 | if (cur->schemaLocation == schemaLocation) |
9770 | 0 | return(cur); |
9771 | 0 | } |
9772 | 0 | } |
9773 | 0 | return(NULL); |
9774 | 0 | } |
9775 | | |
9776 | | static xmlSchemaBucketPtr |
9777 | | xmlSchemaGetChameleonSchemaBucket(xmlSchemaParserCtxtPtr pctxt, |
9778 | | const xmlChar *schemaLocation, |
9779 | | const xmlChar *targetNamespace) |
9780 | 0 | { |
9781 | 0 | xmlSchemaBucketPtr cur; |
9782 | 0 | xmlSchemaItemListPtr list; |
9783 | |
|
9784 | 0 | list = pctxt->constructor->buckets; |
9785 | 0 | if (list->nbItems == 0) |
9786 | 0 | return(NULL); |
9787 | 0 | else { |
9788 | 0 | int i; |
9789 | 0 | for (i = 0; i < list->nbItems; i++) { |
9790 | 0 | cur = (xmlSchemaBucketPtr) list->items[i]; |
9791 | | /* Pointer comparison! */ |
9792 | 0 | if ((cur->origTargetNamespace == NULL) && |
9793 | 0 | (cur->schemaLocation == schemaLocation) && |
9794 | 0 | (cur->targetNamespace == targetNamespace)) |
9795 | 0 | return(cur); |
9796 | 0 | } |
9797 | 0 | } |
9798 | 0 | return(NULL); |
9799 | 0 | } |
9800 | | |
9801 | | |
9802 | | #define IS_BAD_SCHEMA_DOC(b) \ |
9803 | 0 | (((b)->doc == NULL) && ((b)->schemaLocation != NULL)) |
9804 | | |
9805 | | static xmlSchemaBucketPtr |
9806 | | xmlSchemaGetSchemaBucketByTNS(xmlSchemaParserCtxtPtr pctxt, |
9807 | | const xmlChar *targetNamespace, |
9808 | | int imported) |
9809 | 0 | { |
9810 | 0 | xmlSchemaBucketPtr cur; |
9811 | 0 | xmlSchemaItemListPtr list; |
9812 | |
|
9813 | 0 | list = pctxt->constructor->buckets; |
9814 | 0 | if (list->nbItems == 0) |
9815 | 0 | return(NULL); |
9816 | 0 | else { |
9817 | 0 | int i; |
9818 | 0 | for (i = 0; i < list->nbItems; i++) { |
9819 | 0 | cur = (xmlSchemaBucketPtr) list->items[i]; |
9820 | 0 | if ((! IS_BAD_SCHEMA_DOC(cur)) && |
9821 | 0 | (cur->origTargetNamespace == targetNamespace) && |
9822 | 0 | ((imported && cur->imported) || |
9823 | 0 | ((!imported) && (!cur->imported)))) |
9824 | 0 | return(cur); |
9825 | 0 | } |
9826 | 0 | } |
9827 | 0 | return(NULL); |
9828 | 0 | } |
9829 | | |
9830 | | static int |
9831 | | xmlSchemaParseNewDocWithContext(xmlSchemaParserCtxtPtr pctxt, |
9832 | | xmlSchemaPtr schema, |
9833 | | xmlSchemaBucketPtr bucket) |
9834 | 0 | { |
9835 | 0 | int oldFlags; |
9836 | 0 | xmlDocPtr oldDoc; |
9837 | 0 | xmlNodePtr node; |
9838 | 0 | int ret, oldErrs; |
9839 | 0 | xmlSchemaBucketPtr oldbucket = pctxt->constructor->bucket; |
9840 | | |
9841 | | /* |
9842 | | * Save old values; reset the *main* schema. |
9843 | | * URGENT TODO: This is not good; move the per-document information |
9844 | | * to the parser. Get rid of passing the main schema to the |
9845 | | * parsing functions. |
9846 | | */ |
9847 | 0 | oldFlags = schema->flags; |
9848 | 0 | oldDoc = schema->doc; |
9849 | 0 | if (schema->flags != 0) |
9850 | 0 | xmlSchemaClearSchemaDefaults(schema); |
9851 | 0 | schema->doc = bucket->doc; |
9852 | 0 | pctxt->schema = schema; |
9853 | | /* |
9854 | | * Keep the current target namespace on the parser *not* on the |
9855 | | * main schema. |
9856 | | */ |
9857 | 0 | pctxt->targetNamespace = bucket->targetNamespace; |
9858 | 0 | WXS_CONSTRUCTOR(pctxt)->bucket = bucket; |
9859 | |
|
9860 | 0 | if ((bucket->targetNamespace != NULL) && |
9861 | 0 | xmlStrEqual(bucket->targetNamespace, xmlSchemaNs)) { |
9862 | | /* |
9863 | | * We are parsing the schema for schemas! |
9864 | | */ |
9865 | 0 | pctxt->isS4S = 1; |
9866 | 0 | } |
9867 | | /* Mark it as parsed, even if parsing fails. */ |
9868 | 0 | bucket->parsed++; |
9869 | | /* Compile the schema doc. */ |
9870 | 0 | node = xmlDocGetRootElement(bucket->doc); |
9871 | 0 | ret = xmlSchemaParseSchemaElement(pctxt, schema, node); |
9872 | 0 | if (ret != 0) |
9873 | 0 | goto exit; |
9874 | | /* An empty schema; just get out. */ |
9875 | 0 | if (node->children == NULL) |
9876 | 0 | goto exit; |
9877 | 0 | oldErrs = pctxt->nberrors; |
9878 | 0 | ret = xmlSchemaParseSchemaTopLevel(pctxt, schema, node->children); |
9879 | 0 | if (ret != 0) |
9880 | 0 | goto exit; |
9881 | | /* |
9882 | | * TODO: Not nice, but I'm not 100% sure we will get always an error |
9883 | | * as a result of the above functions; so better rely on pctxt->err |
9884 | | * as well. |
9885 | | */ |
9886 | 0 | if ((ret == 0) && (oldErrs != pctxt->nberrors)) { |
9887 | 0 | ret = pctxt->err; |
9888 | 0 | goto exit; |
9889 | 0 | } |
9890 | | |
9891 | 0 | exit: |
9892 | 0 | WXS_CONSTRUCTOR(pctxt)->bucket = oldbucket; |
9893 | | /* Restore schema values. */ |
9894 | 0 | schema->doc = oldDoc; |
9895 | 0 | schema->flags = oldFlags; |
9896 | 0 | return(ret); |
9897 | 0 | } |
9898 | | |
9899 | | static int |
9900 | | xmlSchemaParseNewDoc(xmlSchemaParserCtxtPtr pctxt, |
9901 | | xmlSchemaPtr schema, |
9902 | | xmlSchemaBucketPtr bucket) |
9903 | 0 | { |
9904 | 0 | xmlSchemaParserCtxtPtr newpctxt; |
9905 | 0 | int res = 0; |
9906 | |
|
9907 | 0 | if (bucket == NULL) |
9908 | 0 | return(0); |
9909 | 0 | if (bucket->parsed) { |
9910 | 0 | PERROR_INT("xmlSchemaParseNewDoc", |
9911 | 0 | "reparsing a schema doc"); |
9912 | 0 | return(-1); |
9913 | 0 | } |
9914 | 0 | if (bucket->doc == NULL) { |
9915 | 0 | PERROR_INT("xmlSchemaParseNewDoc", |
9916 | 0 | "parsing a schema doc, but there's no doc"); |
9917 | 0 | return(-1); |
9918 | 0 | } |
9919 | 0 | if (pctxt->constructor == NULL) { |
9920 | 0 | PERROR_INT("xmlSchemaParseNewDoc", |
9921 | 0 | "no constructor"); |
9922 | 0 | return(-1); |
9923 | 0 | } |
9924 | | /* Create and init the temporary parser context. */ |
9925 | 0 | newpctxt = xmlSchemaNewParserCtxtUseDict( |
9926 | 0 | (const char *) bucket->schemaLocation, pctxt->dict); |
9927 | 0 | if (newpctxt == NULL) |
9928 | 0 | return(-1); |
9929 | 0 | newpctxt->constructor = pctxt->constructor; |
9930 | | /* |
9931 | | * TODO: Can we avoid that the parser knows about the main schema? |
9932 | | * It would be better if he knows about the current schema bucket |
9933 | | * only. |
9934 | | */ |
9935 | 0 | newpctxt->schema = schema; |
9936 | 0 | xmlSchemaSetParserErrors(newpctxt, pctxt->error, pctxt->warning, |
9937 | 0 | pctxt->errCtxt); |
9938 | 0 | xmlSchemaSetParserStructuredErrors(newpctxt, pctxt->serror, |
9939 | 0 | pctxt->errCtxt); |
9940 | 0 | newpctxt->counter = pctxt->counter; |
9941 | | |
9942 | |
|
9943 | 0 | res = xmlSchemaParseNewDocWithContext(newpctxt, schema, bucket); |
9944 | | |
9945 | | /* Channel back errors and cleanup the temporary parser context. */ |
9946 | 0 | if (res != 0) |
9947 | 0 | pctxt->err = res; |
9948 | 0 | pctxt->nberrors += newpctxt->nberrors; |
9949 | 0 | pctxt->counter = newpctxt->counter; |
9950 | 0 | newpctxt->constructor = NULL; |
9951 | | /* Free the parser context. */ |
9952 | 0 | xmlSchemaFreeParserCtxt(newpctxt); |
9953 | 0 | return(res); |
9954 | 0 | } |
9955 | | |
9956 | | static void |
9957 | | xmlSchemaSchemaRelationAddChild(xmlSchemaBucketPtr bucket, |
9958 | | xmlSchemaSchemaRelationPtr rel) |
9959 | 0 | { |
9960 | 0 | xmlSchemaSchemaRelationPtr cur = bucket->relations; |
9961 | |
|
9962 | 0 | if (cur == NULL) { |
9963 | 0 | bucket->relations = rel; |
9964 | 0 | return; |
9965 | 0 | } |
9966 | 0 | while (cur->next != NULL) |
9967 | 0 | cur = cur->next; |
9968 | 0 | cur->next = rel; |
9969 | 0 | } |
9970 | | |
9971 | | |
9972 | | static const xmlChar * |
9973 | | xmlSchemaBuildAbsoluteURI(xmlDictPtr dict, const xmlChar* location, |
9974 | | xmlNodePtr ctxtNode) |
9975 | 0 | { |
9976 | | /* |
9977 | | * Build an absolute location URI. |
9978 | | */ |
9979 | 0 | if (location != NULL) { |
9980 | 0 | if (ctxtNode == NULL) |
9981 | 0 | return(location); |
9982 | 0 | else { |
9983 | 0 | xmlChar *base, *URI; |
9984 | 0 | const xmlChar *ret = NULL; |
9985 | |
|
9986 | 0 | base = xmlNodeGetBase(ctxtNode->doc, ctxtNode); |
9987 | 0 | if (base == NULL) { |
9988 | 0 | URI = xmlBuildURI(location, ctxtNode->doc->URL); |
9989 | 0 | } else { |
9990 | 0 | URI = xmlBuildURI(location, base); |
9991 | 0 | xmlFree(base); |
9992 | 0 | } |
9993 | 0 | if (URI != NULL) { |
9994 | 0 | ret = xmlDictLookup(dict, URI, -1); |
9995 | 0 | xmlFree(URI); |
9996 | 0 | return(ret); |
9997 | 0 | } |
9998 | 0 | } |
9999 | 0 | } |
10000 | 0 | return(NULL); |
10001 | 0 | } |
10002 | | |
10003 | | |
10004 | | |
10005 | | /** |
10006 | | * Parse an included (and to-be-redefined) XML schema document. |
10007 | | * |
10008 | | * @param pctxt a schema validation context |
10009 | | * @param type import or include or redefine |
10010 | | * @param schemaLocation schema location |
10011 | | * @param schemaDoc schema document |
10012 | | * @param schemaBuffer document buffer |
10013 | | * @param schemaBufferLen buffer size |
10014 | | * @param invokingNode invoking node |
10015 | | * @param sourceTargetNamespace source target namespace |
10016 | | * @param importNamespace import namespace |
10017 | | * @param bucket bucket |
10018 | | * @returns 0 on success, a positive error code on errors and |
10019 | | * -1 in case of an internal or API error. |
10020 | | */ |
10021 | | |
10022 | | static int |
10023 | | xmlSchemaAddSchemaDoc(xmlSchemaParserCtxtPtr pctxt, |
10024 | | int type, |
10025 | | const xmlChar *schemaLocation, |
10026 | | xmlDocPtr schemaDoc, |
10027 | | const char *schemaBuffer, |
10028 | | int schemaBufferLen, |
10029 | | xmlNodePtr invokingNode, |
10030 | | const xmlChar *sourceTargetNamespace, |
10031 | | const xmlChar *importNamespace, |
10032 | | xmlSchemaBucketPtr *bucket) |
10033 | 0 | { |
10034 | 0 | const xmlChar *targetNamespace = NULL; |
10035 | 0 | xmlSchemaSchemaRelationPtr relation = NULL; |
10036 | 0 | xmlDocPtr doc = NULL; |
10037 | 0 | int res = 0, err = 0, located = 0, preserveDoc = 0; |
10038 | 0 | xmlSchemaBucketPtr bkt = NULL; |
10039 | |
|
10040 | 0 | if (bucket != NULL) |
10041 | 0 | *bucket = NULL; |
10042 | |
|
10043 | 0 | switch (type) { |
10044 | 0 | case XML_SCHEMA_SCHEMA_IMPORT: |
10045 | 0 | case XML_SCHEMA_SCHEMA_MAIN: |
10046 | 0 | err = XML_SCHEMAP_SRC_IMPORT; |
10047 | 0 | break; |
10048 | 0 | case XML_SCHEMA_SCHEMA_INCLUDE: |
10049 | 0 | err = XML_SCHEMAP_SRC_INCLUDE; |
10050 | 0 | break; |
10051 | 0 | case XML_SCHEMA_SCHEMA_REDEFINE: |
10052 | 0 | err = XML_SCHEMAP_SRC_REDEFINE; |
10053 | 0 | break; |
10054 | 0 | } |
10055 | | |
10056 | | |
10057 | | /* Special handling for the main schema: |
10058 | | * skip the location and relation logic and just parse the doc. |
10059 | | * We need just a bucket to be returned in this case. |
10060 | | */ |
10061 | 0 | if ((type == XML_SCHEMA_SCHEMA_MAIN) || (! WXS_HAS_BUCKETS(pctxt))) |
10062 | 0 | goto doc_load; |
10063 | | |
10064 | | /* Note that we expect the location to be an absolute URI. */ |
10065 | 0 | if (schemaLocation != NULL) { |
10066 | 0 | bkt = xmlSchemaGetSchemaBucket(pctxt, schemaLocation); |
10067 | 0 | if ((bkt != NULL) && |
10068 | 0 | (pctxt->constructor->bucket == bkt)) { |
10069 | | /* Report self-imports/inclusions/redefinitions. */ |
10070 | |
|
10071 | 0 | xmlSchemaCustomErr(ACTXT_CAST pctxt, err, |
10072 | 0 | invokingNode, NULL, |
10073 | 0 | "The schema must not import/include/redefine itself", |
10074 | 0 | NULL, NULL); |
10075 | 0 | goto exit; |
10076 | 0 | } |
10077 | 0 | } |
10078 | | /* |
10079 | | * Create a relation for the graph of schemas. |
10080 | | */ |
10081 | 0 | relation = xmlSchemaSchemaRelationCreate(); |
10082 | 0 | if (relation == NULL) |
10083 | 0 | return(-1); |
10084 | 0 | xmlSchemaSchemaRelationAddChild(pctxt->constructor->bucket, |
10085 | 0 | relation); |
10086 | 0 | relation->type = type; |
10087 | | |
10088 | | /* |
10089 | | * Save the namespace import information. |
10090 | | */ |
10091 | 0 | if (WXS_IS_BUCKET_IMPMAIN(type)) { |
10092 | 0 | relation->importNamespace = importNamespace; |
10093 | 0 | if (schemaLocation == NULL) { |
10094 | | /* |
10095 | | * No location; this is just an import of the namespace. |
10096 | | * Note that we don't assign a bucket to the relation |
10097 | | * in this case. |
10098 | | */ |
10099 | 0 | goto exit; |
10100 | 0 | } |
10101 | 0 | targetNamespace = importNamespace; |
10102 | 0 | } |
10103 | | |
10104 | | /* Did we already fetch the doc? */ |
10105 | 0 | if (bkt != NULL) { |
10106 | 0 | if ((WXS_IS_BUCKET_IMPMAIN(type)) && (! bkt->imported)) { |
10107 | | /* |
10108 | | * We included/redefined and then try to import a schema, |
10109 | | * but the new location provided for import was different. |
10110 | | */ |
10111 | 0 | if (schemaLocation == NULL) |
10112 | 0 | schemaLocation = BAD_CAST "in_memory_buffer"; |
10113 | 0 | if (!xmlStrEqual(schemaLocation, |
10114 | 0 | bkt->schemaLocation)) { |
10115 | 0 | xmlSchemaCustomErr(ACTXT_CAST pctxt, err, |
10116 | 0 | invokingNode, NULL, |
10117 | 0 | "The schema document '%s' cannot be imported, since " |
10118 | 0 | "it was already included or redefined", |
10119 | 0 | schemaLocation, NULL); |
10120 | 0 | goto exit; |
10121 | 0 | } |
10122 | 0 | } else if ((! WXS_IS_BUCKET_IMPMAIN(type)) && (bkt->imported)) { |
10123 | | /* |
10124 | | * We imported and then try to include/redefine a schema, |
10125 | | * but the new location provided for the include/redefine |
10126 | | * was different. |
10127 | | */ |
10128 | 0 | if (schemaLocation == NULL) |
10129 | 0 | schemaLocation = BAD_CAST "in_memory_buffer"; |
10130 | 0 | if (!xmlStrEqual(schemaLocation, |
10131 | 0 | bkt->schemaLocation)) { |
10132 | 0 | xmlSchemaCustomErr(ACTXT_CAST pctxt, err, |
10133 | 0 | invokingNode, NULL, |
10134 | 0 | "The schema document '%s' cannot be included or " |
10135 | 0 | "redefined, since it was already imported", |
10136 | 0 | schemaLocation, NULL); |
10137 | 0 | goto exit; |
10138 | 0 | } |
10139 | 0 | } |
10140 | 0 | } |
10141 | | |
10142 | 0 | if (WXS_IS_BUCKET_IMPMAIN(type)) { |
10143 | | /* |
10144 | | * Given that the schemaLocation [attribute] is only a hint, it is open |
10145 | | * to applications to ignore all but the first <import> for a given |
10146 | | * namespace, regardless of the `actual value` of schemaLocation, but |
10147 | | * such a strategy risks missing useful information when new |
10148 | | * schemaLocations are offered. |
10149 | | * |
10150 | | * We will use the first <import> that comes with a location. |
10151 | | * Further <import>s *with* a location, will result in an error. |
10152 | | * TODO: Better would be to just report a warning here, but |
10153 | | * we'll try it this way until someone complains. |
10154 | | * |
10155 | | * Schema Document Location Strategy: |
10156 | | * 3 Based on the namespace name, identify an existing schema document, |
10157 | | * either as a resource which is an XML document or a <schema> element |
10158 | | * information item, in some local schema repository; |
10159 | | * 5 Attempt to resolve the namespace name to locate such a resource. |
10160 | | * |
10161 | | * NOTE: (3) and (5) are not supported. |
10162 | | */ |
10163 | 0 | if (bkt != NULL) { |
10164 | 0 | relation->bucket = bkt; |
10165 | 0 | goto exit; |
10166 | 0 | } |
10167 | 0 | bkt = xmlSchemaGetSchemaBucketByTNS(pctxt, |
10168 | 0 | importNamespace, 1); |
10169 | |
|
10170 | 0 | if (bkt != NULL) { |
10171 | 0 | relation->bucket = bkt; |
10172 | 0 | if (bkt->schemaLocation == NULL) { |
10173 | | /* First given location of the schema; load the doc. */ |
10174 | 0 | bkt->schemaLocation = schemaLocation; |
10175 | 0 | } else { |
10176 | 0 | if (!xmlStrEqual(schemaLocation, |
10177 | 0 | bkt->schemaLocation)) { |
10178 | | /* |
10179 | | * Additional location given; just skip it. |
10180 | | * URGENT TODO: We should report a warning here. |
10181 | | * res = XML_SCHEMAP_SRC_IMPORT; |
10182 | | */ |
10183 | 0 | if (schemaLocation == NULL) |
10184 | 0 | schemaLocation = BAD_CAST "in_memory_buffer"; |
10185 | |
|
10186 | 0 | xmlSchemaCustomWarning(ACTXT_CAST pctxt, |
10187 | 0 | XML_SCHEMAP_WARN_SKIP_SCHEMA, |
10188 | 0 | invokingNode, NULL, |
10189 | 0 | "Skipping import of schema located at '%s' for the " |
10190 | 0 | "namespace '%s', since this namespace was already " |
10191 | 0 | "imported with the schema located at '%s'", |
10192 | 0 | schemaLocation, importNamespace, bkt->schemaLocation); |
10193 | 0 | } |
10194 | 0 | goto exit; |
10195 | 0 | } |
10196 | 0 | } |
10197 | | /* |
10198 | | * No bucket + first location: load the doc and create a |
10199 | | * bucket. |
10200 | | */ |
10201 | 0 | } else { |
10202 | | /* <include> and <redefine> */ |
10203 | 0 | if (bkt != NULL) { |
10204 | |
|
10205 | 0 | if ((bkt->origTargetNamespace == NULL) && |
10206 | 0 | (bkt->targetNamespace != sourceTargetNamespace)) { |
10207 | 0 | xmlSchemaBucketPtr chamel; |
10208 | | |
10209 | | /* |
10210 | | * Chameleon include/redefine: skip loading only if it was |
10211 | | * already build for the targetNamespace of the including |
10212 | | * schema. |
10213 | | */ |
10214 | | /* |
10215 | | * URGENT TODO: If the schema is a chameleon-include then copy |
10216 | | * the components into the including schema and modify the |
10217 | | * targetNamespace of those components, do nothing otherwise. |
10218 | | * NOTE: This is currently worked-around by compiling the |
10219 | | * chameleon for every distinct including targetNamespace; thus |
10220 | | * not performant at the moment. |
10221 | | * TODO: Check when the namespace in wildcards for chameleons |
10222 | | * needs to be converted: before we built wildcard intersections |
10223 | | * or after. |
10224 | | * Answer: after! |
10225 | | */ |
10226 | 0 | chamel = xmlSchemaGetChameleonSchemaBucket(pctxt, |
10227 | 0 | schemaLocation, sourceTargetNamespace); |
10228 | 0 | if (chamel != NULL) { |
10229 | | /* A fitting chameleon was already parsed; NOP. */ |
10230 | 0 | relation->bucket = chamel; |
10231 | 0 | goto exit; |
10232 | 0 | } |
10233 | | /* |
10234 | | * We need to parse the chameleon again for a different |
10235 | | * targetNamespace. |
10236 | | * CHAMELEON TODO: Optimize this by only parsing the |
10237 | | * chameleon once, and then copying the components to |
10238 | | * the new targetNamespace. |
10239 | | */ |
10240 | 0 | bkt = NULL; |
10241 | 0 | } else { |
10242 | 0 | relation->bucket = bkt; |
10243 | 0 | goto exit; |
10244 | 0 | } |
10245 | 0 | } |
10246 | 0 | } |
10247 | 0 | if ((bkt != NULL) && (bkt->doc != NULL)) { |
10248 | 0 | PERROR_INT("xmlSchemaAddSchemaDoc", |
10249 | 0 | "trying to load a schema doc, but a doc is already " |
10250 | 0 | "assigned to the schema bucket"); |
10251 | 0 | goto exit_failure; |
10252 | 0 | } |
10253 | | |
10254 | 0 | doc_load: |
10255 | | /* |
10256 | | * Load the document. |
10257 | | */ |
10258 | 0 | if (schemaDoc != NULL) { |
10259 | 0 | doc = schemaDoc; |
10260 | | /* Don' free this one, since it was provided by the caller. */ |
10261 | 0 | preserveDoc = 1; |
10262 | | /* TODO: Does the context or the doc hold the location? */ |
10263 | 0 | if (schemaDoc->URL != NULL) |
10264 | 0 | schemaLocation = xmlDictLookup(pctxt->dict, |
10265 | 0 | schemaDoc->URL, -1); |
10266 | 0 | else |
10267 | 0 | schemaLocation = BAD_CAST "in_memory_buffer"; |
10268 | 0 | } else if ((schemaLocation != NULL) || (schemaBuffer != NULL)) { |
10269 | 0 | xmlParserCtxtPtr parserCtxt; |
10270 | |
|
10271 | 0 | parserCtxt = xmlNewParserCtxt(); |
10272 | 0 | if (parserCtxt == NULL) { |
10273 | 0 | xmlSchemaPErrMemory(NULL); |
10274 | 0 | goto exit_failure; |
10275 | 0 | } |
10276 | | |
10277 | 0 | if (pctxt->serror != NULL) |
10278 | 0 | xmlCtxtSetErrorHandler(parserCtxt, pctxt->serror, pctxt->errCtxt); |
10279 | 0 | if (pctxt->resourceLoader != NULL) |
10280 | 0 | xmlCtxtSetResourceLoader(parserCtxt, pctxt->resourceLoader, |
10281 | 0 | pctxt->resourceCtxt); |
10282 | |
|
10283 | 0 | if ((pctxt->dict != NULL) && (parserCtxt->dict != NULL)) { |
10284 | | /* |
10285 | | * TODO: Do we have to burden the schema parser dict with all |
10286 | | * the content of the schema doc? |
10287 | | */ |
10288 | 0 | xmlDictFree(parserCtxt->dict); |
10289 | 0 | parserCtxt->dict = pctxt->dict; |
10290 | 0 | xmlDictReference(parserCtxt->dict); |
10291 | 0 | } |
10292 | 0 | if (schemaLocation != NULL) { |
10293 | | /* Parse from file. */ |
10294 | 0 | doc = xmlCtxtReadFile(parserCtxt, (const char *) schemaLocation, |
10295 | 0 | NULL, SCHEMAS_PARSE_OPTIONS); |
10296 | 0 | } else if (schemaBuffer != NULL) { |
10297 | | /* Parse from memory buffer. */ |
10298 | 0 | doc = xmlCtxtReadMemory(parserCtxt, schemaBuffer, schemaBufferLen, |
10299 | 0 | NULL, NULL, SCHEMAS_PARSE_OPTIONS); |
10300 | 0 | schemaLocation = BAD_CAST "in_memory_buffer"; |
10301 | 0 | if (doc != NULL) |
10302 | 0 | doc->URL = xmlStrdup(schemaLocation); |
10303 | 0 | } |
10304 | | /* |
10305 | | * For <import>: |
10306 | | * 2.1 The referent is (a fragment of) a resource which is an |
10307 | | * XML document (see clause 1.1), which in turn corresponds to |
10308 | | * a <schema> element information item in a well-formed information |
10309 | | * set, which in turn corresponds to a valid schema. |
10310 | | * TODO: (2.1) fragments of XML documents are not supported. |
10311 | | * |
10312 | | * 2.2 The referent is a <schema> element information item in |
10313 | | * a well-formed information set, which in turn corresponds |
10314 | | * to a valid schema. |
10315 | | * TODO: (2.2) is not supported. |
10316 | | */ |
10317 | 0 | if (doc == NULL) { |
10318 | 0 | const xmlError *lerr; |
10319 | 0 | lerr = xmlGetLastError(); |
10320 | | /* |
10321 | | * Check if this a parser error, or if the document could |
10322 | | * just not be located. |
10323 | | * TODO: Try to find specific error codes to react only on |
10324 | | * localisation failures. |
10325 | | */ |
10326 | 0 | if ((lerr == NULL) || (lerr->domain != XML_FROM_IO)) { |
10327 | | /* |
10328 | | * We assume a parser error here. |
10329 | | */ |
10330 | 0 | located = 1; |
10331 | | /* TODO: Error code ?? */ |
10332 | 0 | res = XML_SCHEMAP_SRC_IMPORT_2_1; |
10333 | 0 | xmlSchemaCustomErr(ACTXT_CAST pctxt, res, |
10334 | 0 | invokingNode, NULL, |
10335 | 0 | "Failed to parse the XML resource '%s'", |
10336 | 0 | schemaLocation, NULL); |
10337 | 0 | } |
10338 | 0 | } |
10339 | 0 | xmlFreeParserCtxt(parserCtxt); |
10340 | 0 | if ((doc == NULL) && located) |
10341 | 0 | goto exit_error; |
10342 | 0 | } else { |
10343 | 0 | xmlSchemaPErr(pctxt, NULL, |
10344 | 0 | XML_SCHEMAP_NOTHING_TO_PARSE, |
10345 | 0 | "No information for parsing was provided with the " |
10346 | 0 | "given schema parser context.\n", |
10347 | 0 | NULL, NULL); |
10348 | 0 | goto exit_failure; |
10349 | 0 | } |
10350 | | /* |
10351 | | * Preprocess the document. |
10352 | | */ |
10353 | 0 | if (doc != NULL) { |
10354 | 0 | xmlNodePtr docElem = NULL; |
10355 | |
|
10356 | 0 | located = 1; |
10357 | 0 | docElem = xmlDocGetRootElement(doc); |
10358 | 0 | if (docElem == NULL) { |
10359 | 0 | xmlSchemaCustomErr(ACTXT_CAST pctxt, XML_SCHEMAP_NOROOT, |
10360 | 0 | invokingNode, NULL, |
10361 | 0 | "The document '%s' has no document element", |
10362 | 0 | schemaLocation, NULL); |
10363 | 0 | goto exit_error; |
10364 | 0 | } |
10365 | | /* |
10366 | | * Remove all the blank text nodes. |
10367 | | */ |
10368 | 0 | xmlSchemaCleanupDoc(pctxt, docElem); |
10369 | | /* |
10370 | | * Check the schema's top level element. |
10371 | | */ |
10372 | 0 | if (!IS_SCHEMA(docElem, "schema")) { |
10373 | 0 | xmlSchemaCustomErr(ACTXT_CAST pctxt, XML_SCHEMAP_NOT_SCHEMA, |
10374 | 0 | invokingNode, NULL, |
10375 | 0 | "The XML document '%s' is not a schema document", |
10376 | 0 | schemaLocation, NULL); |
10377 | 0 | goto exit_error; |
10378 | 0 | } |
10379 | | /* |
10380 | | * Note that we don't apply a type check for the |
10381 | | * targetNamespace value here. |
10382 | | */ |
10383 | 0 | targetNamespace = xmlSchemaGetProp(pctxt, docElem, |
10384 | 0 | "targetNamespace"); |
10385 | 0 | } |
10386 | | |
10387 | | /* after_doc_loading: */ |
10388 | 0 | if ((bkt == NULL) && located) { |
10389 | | /* Only create a bucket if the schema was located. */ |
10390 | 0 | bkt = xmlSchemaBucketCreate(pctxt, type, |
10391 | 0 | targetNamespace); |
10392 | 0 | if (bkt == NULL) |
10393 | 0 | goto exit_failure; |
10394 | 0 | } |
10395 | 0 | if (bkt != NULL) { |
10396 | 0 | bkt->schemaLocation = schemaLocation; |
10397 | 0 | bkt->located = located; |
10398 | 0 | if (doc != NULL) { |
10399 | 0 | bkt->doc = doc; |
10400 | 0 | bkt->targetNamespace = targetNamespace; |
10401 | 0 | bkt->origTargetNamespace = targetNamespace; |
10402 | 0 | if (preserveDoc) |
10403 | 0 | bkt->preserveDoc = 1; |
10404 | 0 | } |
10405 | 0 | if (WXS_IS_BUCKET_IMPMAIN(type)) |
10406 | 0 | bkt->imported++; |
10407 | | /* |
10408 | | * Add it to the graph of schemas. |
10409 | | */ |
10410 | 0 | if (relation != NULL) |
10411 | 0 | relation->bucket = bkt; |
10412 | 0 | } |
10413 | |
|
10414 | 0 | exit: |
10415 | | /* |
10416 | | * Return the bucket explicitly; this is needed for the |
10417 | | * main schema. |
10418 | | */ |
10419 | 0 | if (bucket != NULL) |
10420 | 0 | *bucket = bkt; |
10421 | 0 | return (0); |
10422 | | |
10423 | 0 | exit_error: |
10424 | 0 | if ((doc != NULL) && (! preserveDoc)) { |
10425 | 0 | xmlFreeDoc(doc); |
10426 | 0 | if (bkt != NULL) |
10427 | 0 | bkt->doc = NULL; |
10428 | 0 | } |
10429 | 0 | return(pctxt->err); |
10430 | | |
10431 | 0 | exit_failure: |
10432 | 0 | if ((doc != NULL) && (! preserveDoc)) { |
10433 | 0 | xmlFreeDoc(doc); |
10434 | 0 | if (bkt != NULL) |
10435 | 0 | bkt->doc = NULL; |
10436 | 0 | } |
10437 | 0 | return (-1); |
10438 | 0 | } |
10439 | | |
10440 | | /** |
10441 | | * parse a XML schema Import definition |
10442 | | * *WARNING* this interface is highly subject to change |
10443 | | * |
10444 | | * @param pctxt a schema validation context |
10445 | | * @param schema the schema being built |
10446 | | * @param node a subtree containing XML Schema information |
10447 | | * @returns 0 in case of success, a positive error code if |
10448 | | * not valid and -1 in case of an internal error. |
10449 | | */ |
10450 | | static int |
10451 | | xmlSchemaParseImport(xmlSchemaParserCtxtPtr pctxt, xmlSchemaPtr schema, |
10452 | | xmlNodePtr node) |
10453 | 0 | { |
10454 | 0 | xmlNodePtr child; |
10455 | 0 | const xmlChar *namespaceName = NULL, *schemaLocation = NULL; |
10456 | 0 | const xmlChar *thisTargetNamespace; |
10457 | 0 | xmlAttrPtr attr; |
10458 | 0 | int ret = 0; |
10459 | 0 | xmlSchemaBucketPtr bucket = NULL; |
10460 | |
|
10461 | 0 | if ((pctxt == NULL) || (schema == NULL) || (node == NULL)) |
10462 | 0 | return (-1); |
10463 | | |
10464 | | /* |
10465 | | * Check for illegal attributes. |
10466 | | */ |
10467 | 0 | attr = node->properties; |
10468 | 0 | while (attr != NULL) { |
10469 | 0 | if (attr->ns == NULL) { |
10470 | 0 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
10471 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "namespace")) && |
10472 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "schemaLocation"))) { |
10473 | 0 | xmlSchemaPIllegalAttrErr(pctxt, |
10474 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
10475 | 0 | } |
10476 | 0 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
10477 | 0 | xmlSchemaPIllegalAttrErr(pctxt, |
10478 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
10479 | 0 | } |
10480 | 0 | attr = attr->next; |
10481 | 0 | } |
10482 | | /* |
10483 | | * Extract and validate attributes. |
10484 | | */ |
10485 | 0 | if (xmlSchemaPValAttr(pctxt, NULL, node, |
10486 | 0 | "namespace", xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), |
10487 | 0 | &namespaceName) != 0) { |
10488 | 0 | xmlSchemaPSimpleTypeErr(pctxt, |
10489 | 0 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
10490 | 0 | NULL, node, |
10491 | 0 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), |
10492 | 0 | NULL, namespaceName, NULL, NULL, NULL); |
10493 | 0 | return (pctxt->err); |
10494 | 0 | } |
10495 | | |
10496 | 0 | if (xmlSchemaPValAttr(pctxt, NULL, node, |
10497 | 0 | "schemaLocation", xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), |
10498 | 0 | &schemaLocation) != 0) { |
10499 | 0 | xmlSchemaPSimpleTypeErr(pctxt, |
10500 | 0 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
10501 | 0 | NULL, node, |
10502 | 0 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), |
10503 | 0 | NULL, schemaLocation, NULL, NULL, NULL); |
10504 | 0 | return (pctxt->err); |
10505 | 0 | } |
10506 | | /* |
10507 | | * And now for the children... |
10508 | | */ |
10509 | 0 | child = node->children; |
10510 | 0 | if (IS_SCHEMA(child, "annotation")) { |
10511 | | /* |
10512 | | * the annotation here is simply discarded ... |
10513 | | * TODO: really? |
10514 | | */ |
10515 | 0 | child = child->next; |
10516 | 0 | } |
10517 | 0 | if (child != NULL) { |
10518 | 0 | xmlSchemaPContentErr(pctxt, |
10519 | 0 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
10520 | 0 | NULL, node, child, NULL, |
10521 | 0 | "(annotation?)"); |
10522 | 0 | } |
10523 | | /* |
10524 | | * Apply additional constraints. |
10525 | | * |
10526 | | * Note that it is important to use the original @targetNamespace |
10527 | | * (or none at all), to rule out imports of schemas _with_ a |
10528 | | * @targetNamespace if the importing schema is a chameleon schema |
10529 | | * (with no @targetNamespace). |
10530 | | */ |
10531 | 0 | thisTargetNamespace = WXS_BUCKET(pctxt)->origTargetNamespace; |
10532 | 0 | if (namespaceName != NULL) { |
10533 | | /* |
10534 | | * 1.1 If the namespace [attribute] is present, then its `actual value` |
10535 | | * must not match the `actual value` of the enclosing <schema>'s |
10536 | | * targetNamespace [attribute]. |
10537 | | */ |
10538 | 0 | if (xmlStrEqual(thisTargetNamespace, namespaceName)) { |
10539 | 0 | xmlSchemaPCustomErr(pctxt, |
10540 | 0 | XML_SCHEMAP_SRC_IMPORT_1_1, |
10541 | 0 | NULL, node, |
10542 | 0 | "The value of the attribute 'namespace' must not match " |
10543 | 0 | "the target namespace '%s' of the importing schema", |
10544 | 0 | thisTargetNamespace); |
10545 | 0 | return (pctxt->err); |
10546 | 0 | } |
10547 | 0 | } else { |
10548 | | /* |
10549 | | * 1.2 If the namespace [attribute] is not present, then the enclosing |
10550 | | * <schema> must have a targetNamespace [attribute]. |
10551 | | */ |
10552 | 0 | if (thisTargetNamespace == NULL) { |
10553 | 0 | xmlSchemaPCustomErr(pctxt, |
10554 | 0 | XML_SCHEMAP_SRC_IMPORT_1_2, |
10555 | 0 | NULL, node, |
10556 | 0 | "The attribute 'namespace' must be existent if " |
10557 | 0 | "the importing schema has no target namespace", |
10558 | 0 | NULL); |
10559 | 0 | return (pctxt->err); |
10560 | 0 | } |
10561 | 0 | } |
10562 | | /* |
10563 | | * Locate and acquire the schema document. |
10564 | | */ |
10565 | 0 | if (schemaLocation != NULL) |
10566 | 0 | schemaLocation = xmlSchemaBuildAbsoluteURI(pctxt->dict, |
10567 | 0 | schemaLocation, node); |
10568 | 0 | ret = xmlSchemaAddSchemaDoc(pctxt, XML_SCHEMA_SCHEMA_IMPORT, |
10569 | 0 | schemaLocation, NULL, NULL, 0, node, thisTargetNamespace, |
10570 | 0 | namespaceName, &bucket); |
10571 | |
|
10572 | 0 | if (ret != 0) |
10573 | 0 | return(ret); |
10574 | | |
10575 | | /* |
10576 | | * For <import>: "It is *not* an error for the application |
10577 | | * schema reference strategy to fail." |
10578 | | * So just don't parse if no schema document was found. |
10579 | | * Note that we will get no bucket if the schema could not be |
10580 | | * located or if there was no schemaLocation. |
10581 | | */ |
10582 | 0 | if ((bucket == NULL) && (schemaLocation != NULL)) { |
10583 | 0 | xmlSchemaCustomWarning(ACTXT_CAST pctxt, |
10584 | 0 | XML_SCHEMAP_WARN_UNLOCATED_SCHEMA, |
10585 | 0 | node, NULL, |
10586 | 0 | "Failed to locate a schema at location '%s'. " |
10587 | 0 | "Skipping the import", schemaLocation, NULL, NULL); |
10588 | 0 | } |
10589 | |
|
10590 | 0 | if ((bucket != NULL) && CAN_PARSE_SCHEMA(bucket)) { |
10591 | 0 | ret = xmlSchemaParseNewDoc(pctxt, schema, bucket); |
10592 | 0 | } |
10593 | |
|
10594 | 0 | return (ret); |
10595 | 0 | } |
10596 | | |
10597 | | static int |
10598 | | xmlSchemaParseIncludeOrRedefineAttrs(xmlSchemaParserCtxtPtr pctxt, |
10599 | | xmlSchemaPtr schema, |
10600 | | xmlNodePtr node, |
10601 | | xmlChar **schemaLocation, |
10602 | | int type) |
10603 | 0 | { |
10604 | 0 | xmlAttrPtr attr; |
10605 | |
|
10606 | 0 | if ((pctxt == NULL) || (schema == NULL) || (node == NULL) || |
10607 | 0 | (schemaLocation == NULL)) |
10608 | 0 | return (-1); |
10609 | | |
10610 | 0 | *schemaLocation = NULL; |
10611 | | /* |
10612 | | * Check for illegal attributes. |
10613 | | * Applies for both <include> and <redefine>. |
10614 | | */ |
10615 | 0 | attr = node->properties; |
10616 | 0 | while (attr != NULL) { |
10617 | 0 | if (attr->ns == NULL) { |
10618 | 0 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
10619 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "schemaLocation"))) { |
10620 | 0 | xmlSchemaPIllegalAttrErr(pctxt, |
10621 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
10622 | 0 | } |
10623 | 0 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
10624 | 0 | xmlSchemaPIllegalAttrErr(pctxt, |
10625 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
10626 | 0 | } |
10627 | 0 | attr = attr->next; |
10628 | 0 | } |
10629 | 0 | xmlSchemaPValAttrID(pctxt, node, BAD_CAST "id"); |
10630 | | /* |
10631 | | * Preliminary step, extract the URI-Reference and make an URI |
10632 | | * from the base. |
10633 | | */ |
10634 | | /* |
10635 | | * Attribute "schemaLocation" is mandatory. |
10636 | | */ |
10637 | 0 | attr = xmlSchemaGetPropNode(node, "schemaLocation"); |
10638 | 0 | if (attr != NULL) { |
10639 | 0 | xmlChar *base = NULL; |
10640 | 0 | xmlChar *uri = NULL; |
10641 | |
|
10642 | 0 | if (xmlSchemaPValAttrNode(pctxt, NULL, attr, |
10643 | 0 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), |
10644 | 0 | (const xmlChar **) schemaLocation) != 0) |
10645 | 0 | goto exit_error; |
10646 | 0 | base = xmlNodeGetBase(node->doc, node); |
10647 | 0 | if (base == NULL) { |
10648 | 0 | uri = xmlBuildURI(*schemaLocation, node->doc->URL); |
10649 | 0 | } else { |
10650 | 0 | uri = xmlBuildURI(*schemaLocation, base); |
10651 | 0 | xmlFree(base); |
10652 | 0 | } |
10653 | 0 | if (uri == NULL) { |
10654 | 0 | PERROR_INT("xmlSchemaParseIncludeOrRedefine", |
10655 | 0 | "could not build an URI from the schemaLocation") |
10656 | 0 | goto exit_failure; |
10657 | 0 | } |
10658 | 0 | (*schemaLocation) = (xmlChar *) xmlDictLookup(pctxt->dict, uri, -1); |
10659 | 0 | xmlFree(uri); |
10660 | 0 | } else { |
10661 | 0 | xmlSchemaPMissingAttrErr(pctxt, |
10662 | 0 | XML_SCHEMAP_S4S_ATTR_MISSING, |
10663 | 0 | NULL, node, "schemaLocation", NULL); |
10664 | 0 | goto exit_error; |
10665 | 0 | } |
10666 | | /* |
10667 | | * Report self-inclusion and self-redefinition. |
10668 | | */ |
10669 | 0 | if (xmlStrEqual(*schemaLocation, pctxt->URL)) { |
10670 | 0 | if (type == XML_SCHEMA_SCHEMA_REDEFINE) { |
10671 | 0 | xmlSchemaPCustomErr(pctxt, |
10672 | 0 | XML_SCHEMAP_SRC_REDEFINE, |
10673 | 0 | NULL, node, |
10674 | 0 | "The schema document '%s' cannot redefine itself.", |
10675 | 0 | *schemaLocation); |
10676 | 0 | } else { |
10677 | 0 | xmlSchemaPCustomErr(pctxt, |
10678 | 0 | XML_SCHEMAP_SRC_INCLUDE, |
10679 | 0 | NULL, node, |
10680 | 0 | "The schema document '%s' cannot include itself.", |
10681 | 0 | *schemaLocation); |
10682 | 0 | } |
10683 | 0 | goto exit_error; |
10684 | 0 | } |
10685 | | |
10686 | 0 | return(0); |
10687 | 0 | exit_error: |
10688 | 0 | return(pctxt->err); |
10689 | 0 | exit_failure: |
10690 | 0 | return(-1); |
10691 | 0 | } |
10692 | | |
10693 | | static int |
10694 | | xmlSchemaParseIncludeOrRedefine(xmlSchemaParserCtxtPtr pctxt, |
10695 | | xmlSchemaPtr schema, |
10696 | | xmlNodePtr node, |
10697 | | int type) |
10698 | 0 | { |
10699 | 0 | xmlNodePtr child = NULL; |
10700 | 0 | const xmlChar *schemaLocation = NULL; |
10701 | 0 | int res = 0; /* hasRedefinitions = 0 */ |
10702 | 0 | int isChameleon = 0, wasChameleon = 0; |
10703 | 0 | xmlSchemaBucketPtr bucket = NULL; |
10704 | |
|
10705 | 0 | if ((pctxt == NULL) || (schema == NULL) || (node == NULL)) |
10706 | 0 | return (-1); |
10707 | | |
10708 | | /* |
10709 | | * Parse attributes. Note that the returned schemaLocation will |
10710 | | * be already converted to an absolute URI. |
10711 | | */ |
10712 | 0 | res = xmlSchemaParseIncludeOrRedefineAttrs(pctxt, schema, |
10713 | 0 | node, (xmlChar **) (&schemaLocation), type); |
10714 | 0 | if (res != 0) |
10715 | 0 | return(res); |
10716 | | /* |
10717 | | * Load and add the schema document. |
10718 | | */ |
10719 | 0 | res = xmlSchemaAddSchemaDoc(pctxt, type, schemaLocation, NULL, |
10720 | 0 | NULL, 0, node, pctxt->targetNamespace, NULL, &bucket); |
10721 | 0 | if (res != 0) |
10722 | 0 | return(res); |
10723 | | /* |
10724 | | * If we get no schema bucket back, then this means that the schema |
10725 | | * document could not be located or was broken XML or was not |
10726 | | * a schema document. |
10727 | | */ |
10728 | 0 | if ((bucket == NULL) || (bucket->doc == NULL)) { |
10729 | 0 | if (type == XML_SCHEMA_SCHEMA_INCLUDE) { |
10730 | | /* |
10731 | | * WARNING for <include>: |
10732 | | * We will raise an error if the schema cannot be located |
10733 | | * for inclusions, since the that was the feedback from the |
10734 | | * schema people. I.e. the following spec piece will *not* be |
10735 | | * satisfied: |
10736 | | * SPEC src-include: "It is not an error for the `actual value` of the |
10737 | | * schemaLocation [attribute] to fail to resolve it all, in which |
10738 | | * case no corresponding inclusion is performed. |
10739 | | * So do we need a warning report here?" |
10740 | | */ |
10741 | 0 | res = XML_SCHEMAP_SRC_INCLUDE; |
10742 | 0 | xmlSchemaCustomErr(ACTXT_CAST pctxt, res, |
10743 | 0 | node, NULL, |
10744 | 0 | "Failed to load the document '%s' for inclusion", |
10745 | 0 | schemaLocation, NULL); |
10746 | 0 | } else { |
10747 | | /* |
10748 | | * NOTE: This was changed to raise an error even if no redefinitions |
10749 | | * are specified. |
10750 | | * |
10751 | | * SPEC src-redefine (1) |
10752 | | * "If there are any element information items among the [children] |
10753 | | * other than <annotation> then the `actual value` of the |
10754 | | * schemaLocation [attribute] must successfully resolve." |
10755 | | * TODO: Ask the WG if a the location has always to resolve |
10756 | | * here as well! |
10757 | | */ |
10758 | 0 | res = XML_SCHEMAP_SRC_REDEFINE; |
10759 | 0 | xmlSchemaCustomErr(ACTXT_CAST pctxt, res, |
10760 | 0 | node, NULL, |
10761 | 0 | "Failed to load the document '%s' for redefinition", |
10762 | 0 | schemaLocation, NULL); |
10763 | 0 | } |
10764 | 0 | } else { |
10765 | | /* |
10766 | | * Check targetNamespace sanity before parsing the new schema. |
10767 | | * TODO: Note that we won't check further content if the |
10768 | | * targetNamespace was bad. |
10769 | | */ |
10770 | 0 | if (bucket->origTargetNamespace != NULL) { |
10771 | | /* |
10772 | | * SPEC src-include (2.1) |
10773 | | * "SII has a targetNamespace [attribute], and its `actual |
10774 | | * value` is identical to the `actual value` of the targetNamespace |
10775 | | * [attribute] of SII' (which must have such an [attribute])." |
10776 | | */ |
10777 | 0 | if (pctxt->targetNamespace == NULL) { |
10778 | 0 | xmlSchemaCustomErr(ACTXT_CAST pctxt, |
10779 | 0 | XML_SCHEMAP_SRC_INCLUDE, |
10780 | 0 | node, NULL, |
10781 | 0 | "The target namespace of the included/redefined schema " |
10782 | 0 | "'%s' has to be absent, since the including/redefining " |
10783 | 0 | "schema has no target namespace", |
10784 | 0 | schemaLocation, NULL); |
10785 | 0 | goto exit_error; |
10786 | 0 | } else if (!xmlStrEqual(bucket->origTargetNamespace, |
10787 | 0 | pctxt->targetNamespace)) { |
10788 | | /* TODO: Change error function. */ |
10789 | 0 | xmlSchemaPCustomErrExt(pctxt, |
10790 | 0 | XML_SCHEMAP_SRC_INCLUDE, |
10791 | 0 | NULL, node, |
10792 | 0 | "The target namespace '%s' of the included/redefined " |
10793 | 0 | "schema '%s' differs from '%s' of the " |
10794 | 0 | "including/redefining schema", |
10795 | 0 | bucket->origTargetNamespace, schemaLocation, |
10796 | 0 | pctxt->targetNamespace); |
10797 | 0 | goto exit_error; |
10798 | 0 | } |
10799 | 0 | } else if (pctxt->targetNamespace != NULL) { |
10800 | | /* |
10801 | | * Chameleons: the original target namespace will |
10802 | | * differ from the resulting namespace. |
10803 | | */ |
10804 | 0 | isChameleon = 1; |
10805 | 0 | bucket->targetNamespace = pctxt->targetNamespace; |
10806 | 0 | } |
10807 | 0 | } |
10808 | | /* |
10809 | | * Parse the schema. |
10810 | | */ |
10811 | 0 | if (bucket && (!bucket->parsed) && (bucket->doc != NULL)) { |
10812 | 0 | if (isChameleon) { |
10813 | | /* TODO: Get rid of this flag on the schema itself. */ |
10814 | 0 | if ((schema->flags & XML_SCHEMAS_INCLUDING_CONVERT_NS) == 0) { |
10815 | 0 | schema->flags |= XML_SCHEMAS_INCLUDING_CONVERT_NS; |
10816 | 0 | } else |
10817 | 0 | wasChameleon = 1; |
10818 | 0 | } |
10819 | 0 | xmlSchemaParseNewDoc(pctxt, schema, bucket); |
10820 | | /* Restore chameleon flag. */ |
10821 | 0 | if (isChameleon && (!wasChameleon)) |
10822 | 0 | schema->flags ^= XML_SCHEMAS_INCLUDING_CONVERT_NS; |
10823 | 0 | } |
10824 | | /* |
10825 | | * And now for the children... |
10826 | | */ |
10827 | 0 | child = node->children; |
10828 | 0 | if (type == XML_SCHEMA_SCHEMA_REDEFINE) { |
10829 | | /* |
10830 | | * Parse (simpleType | complexType | group | attributeGroup))* |
10831 | | */ |
10832 | 0 | pctxt->redefined = bucket; |
10833 | | /* |
10834 | | * How to proceed if the redefined schema was not located? |
10835 | | */ |
10836 | 0 | pctxt->isRedefine = 1; |
10837 | 0 | while (IS_SCHEMA(child, "annotation") || |
10838 | 0 | IS_SCHEMA(child, "simpleType") || |
10839 | 0 | IS_SCHEMA(child, "complexType") || |
10840 | 0 | IS_SCHEMA(child, "group") || |
10841 | 0 | IS_SCHEMA(child, "attributeGroup")) { |
10842 | 0 | if (IS_SCHEMA(child, "annotation")) { |
10843 | | /* |
10844 | | * TODO: discard or not? |
10845 | | */ |
10846 | 0 | } else if (IS_SCHEMA(child, "simpleType")) { |
10847 | 0 | xmlSchemaParseSimpleType(pctxt, schema, child, 1); |
10848 | 0 | } else if (IS_SCHEMA(child, "complexType")) { |
10849 | 0 | xmlSchemaParseComplexType(pctxt, schema, child, 1); |
10850 | | /* hasRedefinitions = 1; */ |
10851 | 0 | } else if (IS_SCHEMA(child, "group")) { |
10852 | | /* hasRedefinitions = 1; */ |
10853 | 0 | xmlSchemaParseModelGroupDefinition(pctxt, |
10854 | 0 | schema, child); |
10855 | 0 | } else if (IS_SCHEMA(child, "attributeGroup")) { |
10856 | | /* hasRedefinitions = 1; */ |
10857 | 0 | xmlSchemaParseAttributeGroupDefinition(pctxt, schema, |
10858 | 0 | child); |
10859 | 0 | } |
10860 | 0 | child = child->next; |
10861 | 0 | } |
10862 | 0 | pctxt->redefined = NULL; |
10863 | 0 | pctxt->isRedefine = 0; |
10864 | 0 | } else { |
10865 | 0 | if (IS_SCHEMA(child, "annotation")) { |
10866 | | /* |
10867 | | * TODO: discard or not? |
10868 | | */ |
10869 | 0 | child = child->next; |
10870 | 0 | } |
10871 | 0 | } |
10872 | 0 | if (child != NULL) { |
10873 | 0 | res = XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED; |
10874 | 0 | if (type == XML_SCHEMA_SCHEMA_REDEFINE) { |
10875 | 0 | xmlSchemaPContentErr(pctxt, res, |
10876 | 0 | NULL, node, child, NULL, |
10877 | 0 | "(annotation | (simpleType | complexType | group | attributeGroup))*"); |
10878 | 0 | } else { |
10879 | 0 | xmlSchemaPContentErr(pctxt, res, |
10880 | 0 | NULL, node, child, NULL, |
10881 | 0 | "(annotation?)"); |
10882 | 0 | } |
10883 | 0 | } |
10884 | 0 | return(res); |
10885 | | |
10886 | 0 | exit_error: |
10887 | 0 | return(pctxt->err); |
10888 | 0 | } |
10889 | | |
10890 | | static int |
10891 | | xmlSchemaParseRedefine(xmlSchemaParserCtxtPtr pctxt, xmlSchemaPtr schema, |
10892 | | xmlNodePtr node) |
10893 | 0 | { |
10894 | 0 | int res; |
10895 | | #ifndef ENABLE_REDEFINE |
10896 | | TODO |
10897 | | return(0); |
10898 | | #endif |
10899 | 0 | res = xmlSchemaParseIncludeOrRedefine(pctxt, schema, node, |
10900 | 0 | XML_SCHEMA_SCHEMA_REDEFINE); |
10901 | 0 | if (res != 0) |
10902 | 0 | return(res); |
10903 | 0 | return(0); |
10904 | 0 | } |
10905 | | |
10906 | | static int |
10907 | | xmlSchemaParseInclude(xmlSchemaParserCtxtPtr pctxt, xmlSchemaPtr schema, |
10908 | | xmlNodePtr node) |
10909 | 0 | { |
10910 | 0 | int res; |
10911 | |
|
10912 | 0 | res = xmlSchemaParseIncludeOrRedefine(pctxt, schema, node, |
10913 | 0 | XML_SCHEMA_SCHEMA_INCLUDE); |
10914 | 0 | if (res != 0) |
10915 | 0 | return(res); |
10916 | 0 | return(0); |
10917 | 0 | } |
10918 | | |
10919 | | /** |
10920 | | * parse a XML schema Sequence definition. |
10921 | | * Applies parts of: |
10922 | | * Schema Representation Constraint: |
10923 | | * Redefinition Constraints and Semantics (src-redefine) |
10924 | | * (6.1), (6.1.1), (6.1.2) |
10925 | | * |
10926 | | * Schema Component Constraint: |
10927 | | * All Group Limited (cos-all-limited) (2) |
10928 | | * TODO: Actually this should go to component-level checks, |
10929 | | * but is done here due to performance. Move it to an other layer |
10930 | | * is schema construction via an API is implemented. |
10931 | | * |
10932 | | * *WARNING* this interface is highly subject to change |
10933 | | * |
10934 | | * @param ctxt a schema validation context |
10935 | | * @param schema the schema being built |
10936 | | * @param node a subtree containing XML Schema information |
10937 | | * @param type the "compositor" type |
10938 | | * @param withParticle if a a model group with a particle |
10939 | | * @returns -1 in case of error, 0 if the declaration is improper and |
10940 | | * 1 in case of success. |
10941 | | */ |
10942 | | static xmlSchemaTreeItemPtr |
10943 | | xmlSchemaParseModelGroup(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
10944 | | xmlNodePtr node, xmlSchemaTypeType type, |
10945 | | int withParticle) |
10946 | 0 | { |
10947 | 0 | xmlSchemaModelGroupPtr item; |
10948 | 0 | xmlSchemaParticlePtr particle = NULL; |
10949 | 0 | xmlNodePtr child = NULL; |
10950 | 0 | xmlAttrPtr attr; |
10951 | 0 | int min = 1, max = 1, isElemRef, hasRefs = 0; |
10952 | |
|
10953 | 0 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
10954 | 0 | return (NULL); |
10955 | | /* |
10956 | | * Create a model group with the given compositor. |
10957 | | */ |
10958 | 0 | item = xmlSchemaAddModelGroup(ctxt, schema, type, node); |
10959 | 0 | if (item == NULL) |
10960 | 0 | return (NULL); |
10961 | | |
10962 | 0 | if (withParticle) { |
10963 | 0 | if (type == XML_SCHEMA_TYPE_ALL) { |
10964 | 0 | min = xmlGetMinOccurs(ctxt, node, 0, 1, 1, "(0 | 1)"); |
10965 | 0 | max = xmlGetMaxOccurs(ctxt, node, 1, 1, 1, "1"); |
10966 | 0 | } else { |
10967 | | /* choice + sequence */ |
10968 | 0 | min = xmlGetMinOccurs(ctxt, node, 0, -1, 1, "xs:nonNegativeInteger"); |
10969 | 0 | max = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1, |
10970 | 0 | "(xs:nonNegativeInteger | unbounded)"); |
10971 | 0 | } |
10972 | 0 | xmlSchemaPCheckParticleCorrect_2(ctxt, NULL, node, min, max); |
10973 | | /* |
10974 | | * Create a particle |
10975 | | */ |
10976 | 0 | particle = xmlSchemaAddParticle(ctxt, node, min, max); |
10977 | 0 | if (particle == NULL) |
10978 | 0 | return (NULL); |
10979 | 0 | particle->children = (xmlSchemaTreeItemPtr) item; |
10980 | | /* |
10981 | | * Check for illegal attributes. |
10982 | | */ |
10983 | 0 | attr = node->properties; |
10984 | 0 | while (attr != NULL) { |
10985 | 0 | if (attr->ns == NULL) { |
10986 | 0 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
10987 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "maxOccurs")) && |
10988 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "minOccurs"))) { |
10989 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
10990 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
10991 | 0 | } |
10992 | 0 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
10993 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
10994 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
10995 | 0 | } |
10996 | 0 | attr = attr->next; |
10997 | 0 | } |
10998 | 0 | } else { |
10999 | | /* |
11000 | | * Check for illegal attributes. |
11001 | | */ |
11002 | 0 | attr = node->properties; |
11003 | 0 | while (attr != NULL) { |
11004 | 0 | if (attr->ns == NULL) { |
11005 | 0 | if (!xmlStrEqual(attr->name, BAD_CAST "id")) { |
11006 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
11007 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
11008 | 0 | } |
11009 | 0 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
11010 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
11011 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
11012 | 0 | } |
11013 | 0 | attr = attr->next; |
11014 | 0 | } |
11015 | 0 | } |
11016 | | |
11017 | | /* |
11018 | | * Extract and validate attributes. |
11019 | | */ |
11020 | 0 | xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id"); |
11021 | | /* |
11022 | | * And now for the children... |
11023 | | */ |
11024 | 0 | child = node->children; |
11025 | 0 | if (IS_SCHEMA(child, "annotation")) { |
11026 | 0 | item->annot = xmlSchemaParseAnnotation(ctxt, child, 1); |
11027 | 0 | child = child->next; |
11028 | 0 | } |
11029 | 0 | if (type == XML_SCHEMA_TYPE_ALL) { |
11030 | 0 | xmlSchemaParticlePtr part, last = NULL; |
11031 | |
|
11032 | 0 | while (IS_SCHEMA(child, "element")) { |
11033 | 0 | part = (xmlSchemaParticlePtr) xmlSchemaParseElement(ctxt, |
11034 | 0 | schema, child, &isElemRef, 0); |
11035 | | /* |
11036 | | * SPEC cos-all-limited (2) |
11037 | | * "The {max occurs} of all the particles in the {particles} |
11038 | | * of the ('all') group must be 0 or 1. |
11039 | | */ |
11040 | 0 | if (part != NULL) { |
11041 | 0 | if (isElemRef) |
11042 | 0 | hasRefs++; |
11043 | 0 | if (part->minOccurs > 1) { |
11044 | 0 | xmlSchemaPCustomErr(ctxt, |
11045 | 0 | XML_SCHEMAP_COS_ALL_LIMITED, |
11046 | 0 | NULL, child, |
11047 | 0 | "Invalid value for minOccurs (must be 0 or 1)", |
11048 | 0 | NULL); |
11049 | | /* Reset to 1. */ |
11050 | 0 | part->minOccurs = 1; |
11051 | 0 | } |
11052 | 0 | if (part->maxOccurs > 1) { |
11053 | 0 | xmlSchemaPCustomErr(ctxt, |
11054 | 0 | XML_SCHEMAP_COS_ALL_LIMITED, |
11055 | 0 | NULL, child, |
11056 | 0 | "Invalid value for maxOccurs (must be 0 or 1)", |
11057 | 0 | NULL); |
11058 | | /* Reset to 1. */ |
11059 | 0 | part->maxOccurs = 1; |
11060 | 0 | } |
11061 | 0 | if (last == NULL) |
11062 | 0 | item->children = (xmlSchemaTreeItemPtr) part; |
11063 | 0 | else |
11064 | 0 | last->next = (xmlSchemaTreeItemPtr) part; |
11065 | 0 | last = part; |
11066 | 0 | } |
11067 | 0 | child = child->next; |
11068 | 0 | } |
11069 | 0 | if (child != NULL) { |
11070 | 0 | xmlSchemaPContentErr(ctxt, |
11071 | 0 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
11072 | 0 | NULL, node, child, NULL, |
11073 | 0 | "(annotation?, (annotation?, element*)"); |
11074 | 0 | } |
11075 | 0 | } else { |
11076 | | /* choice + sequence */ |
11077 | 0 | xmlSchemaTreeItemPtr part = NULL, last = NULL; |
11078 | |
|
11079 | 0 | while ((IS_SCHEMA(child, "element")) || |
11080 | 0 | (IS_SCHEMA(child, "group")) || |
11081 | 0 | (IS_SCHEMA(child, "any")) || |
11082 | 0 | (IS_SCHEMA(child, "choice")) || |
11083 | 0 | (IS_SCHEMA(child, "sequence"))) { |
11084 | |
|
11085 | 0 | if (IS_SCHEMA(child, "element")) { |
11086 | 0 | part = (xmlSchemaTreeItemPtr) |
11087 | 0 | xmlSchemaParseElement(ctxt, schema, child, &isElemRef, 0); |
11088 | 0 | if (part && isElemRef) |
11089 | 0 | hasRefs++; |
11090 | 0 | } else if (IS_SCHEMA(child, "group")) { |
11091 | 0 | part = |
11092 | 0 | xmlSchemaParseModelGroupDefRef(ctxt, schema, child); |
11093 | 0 | if (part != NULL) |
11094 | 0 | hasRefs++; |
11095 | | /* |
11096 | | * Handle redefinitions. |
11097 | | */ |
11098 | 0 | if (ctxt->isRedefine && ctxt->redef && |
11099 | 0 | (ctxt->redef->item->type == XML_SCHEMA_TYPE_GROUP) && |
11100 | 0 | part && part->children) |
11101 | 0 | { |
11102 | 0 | if ((xmlSchemaGetQNameRefName(part->children) == |
11103 | 0 | ctxt->redef->refName) && |
11104 | 0 | (xmlSchemaGetQNameRefTargetNs(part->children) == |
11105 | 0 | ctxt->redef->refTargetNs)) |
11106 | 0 | { |
11107 | | /* |
11108 | | * SPEC src-redefine: |
11109 | | * (6.1) "If it has a <group> among its contents at |
11110 | | * some level the `actual value` of whose ref |
11111 | | * [attribute] is the same as the `actual value` of |
11112 | | * its own name attribute plus target namespace, then |
11113 | | * all of the following must be true:" |
11114 | | * (6.1.1) "It must have exactly one such group." |
11115 | | */ |
11116 | 0 | if (ctxt->redefCounter != 0) { |
11117 | 0 | xmlChar *str = NULL; |
11118 | |
|
11119 | 0 | xmlSchemaCustomErr(ACTXT_CAST ctxt, |
11120 | 0 | XML_SCHEMAP_SRC_REDEFINE, child, NULL, |
11121 | 0 | "The redefining model group definition " |
11122 | 0 | "'%s' must not contain more than one " |
11123 | 0 | "reference to the redefined definition", |
11124 | 0 | xmlSchemaFormatQName(&str, |
11125 | 0 | ctxt->redef->refTargetNs, |
11126 | 0 | ctxt->redef->refName), |
11127 | 0 | NULL); |
11128 | 0 | FREE_AND_NULL(str) |
11129 | 0 | part = NULL; |
11130 | 0 | } else if (((WXS_PARTICLE(part))->minOccurs != 1) || |
11131 | 0 | ((WXS_PARTICLE(part))->maxOccurs != 1)) |
11132 | 0 | { |
11133 | 0 | xmlChar *str = NULL; |
11134 | | /* |
11135 | | * SPEC src-redefine: |
11136 | | * (6.1.2) "The `actual value` of both that |
11137 | | * group's minOccurs and maxOccurs [attribute] |
11138 | | * must be 1 (or `absent`). |
11139 | | */ |
11140 | 0 | xmlSchemaCustomErr(ACTXT_CAST ctxt, |
11141 | 0 | XML_SCHEMAP_SRC_REDEFINE, child, NULL, |
11142 | 0 | "The redefining model group definition " |
11143 | 0 | "'%s' must not contain a reference to the " |
11144 | 0 | "redefined definition with a " |
11145 | 0 | "maxOccurs/minOccurs other than 1", |
11146 | 0 | xmlSchemaFormatQName(&str, |
11147 | 0 | ctxt->redef->refTargetNs, |
11148 | 0 | ctxt->redef->refName), |
11149 | 0 | NULL); |
11150 | 0 | FREE_AND_NULL(str) |
11151 | 0 | part = NULL; |
11152 | 0 | } |
11153 | 0 | ctxt->redef->reference = WXS_BASIC_CAST part; |
11154 | 0 | ctxt->redefCounter++; |
11155 | 0 | } |
11156 | 0 | } |
11157 | 0 | } else if (IS_SCHEMA(child, "any")) { |
11158 | 0 | part = (xmlSchemaTreeItemPtr) |
11159 | 0 | xmlSchemaParseAny(ctxt, schema, child); |
11160 | 0 | } else if (IS_SCHEMA(child, "choice")) { |
11161 | 0 | part = xmlSchemaParseModelGroup(ctxt, schema, child, |
11162 | 0 | XML_SCHEMA_TYPE_CHOICE, 1); |
11163 | 0 | } else if (IS_SCHEMA(child, "sequence")) { |
11164 | 0 | part = xmlSchemaParseModelGroup(ctxt, schema, child, |
11165 | 0 | XML_SCHEMA_TYPE_SEQUENCE, 1); |
11166 | 0 | } |
11167 | 0 | if (part != NULL) { |
11168 | 0 | if (last == NULL) |
11169 | 0 | item->children = part; |
11170 | 0 | else |
11171 | 0 | last->next = part; |
11172 | 0 | last = part; |
11173 | 0 | } |
11174 | 0 | child = child->next; |
11175 | 0 | } |
11176 | 0 | if (child != NULL) { |
11177 | 0 | xmlSchemaPContentErr(ctxt, |
11178 | 0 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
11179 | 0 | NULL, node, child, NULL, |
11180 | 0 | "(annotation?, (element | group | choice | sequence | any)*)"); |
11181 | 0 | } |
11182 | 0 | } |
11183 | 0 | if ((max == 0) && (min == 0)) |
11184 | 0 | return (NULL); |
11185 | 0 | if (hasRefs) { |
11186 | | /* |
11187 | | * We need to resolve references. |
11188 | | */ |
11189 | 0 | WXS_ADD_PENDING(ctxt, item); |
11190 | 0 | } |
11191 | 0 | if (withParticle) |
11192 | 0 | return ((xmlSchemaTreeItemPtr) particle); |
11193 | 0 | else |
11194 | 0 | return ((xmlSchemaTreeItemPtr) item); |
11195 | 0 | } |
11196 | | |
11197 | | /** |
11198 | | * parse a XML schema Restriction definition |
11199 | | * *WARNING* this interface is highly subject to change |
11200 | | * |
11201 | | * @param ctxt a schema validation context |
11202 | | * @param schema the schema being built |
11203 | | * @param node a subtree containing XML Schema information |
11204 | | * @param parentType the parent type |
11205 | | * @returns the type definition or NULL in case of error |
11206 | | */ |
11207 | | static xmlSchemaTypePtr |
11208 | | xmlSchemaParseRestriction(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
11209 | | xmlNodePtr node, xmlSchemaTypeType parentType) |
11210 | 0 | { |
11211 | 0 | xmlSchemaTypePtr type; |
11212 | 0 | xmlNodePtr child = NULL; |
11213 | 0 | xmlAttrPtr attr; |
11214 | |
|
11215 | 0 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
11216 | 0 | return (NULL); |
11217 | | /* Not a component, don't create it. */ |
11218 | 0 | type = ctxt->ctxtType; |
11219 | 0 | type->flags |= XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION; |
11220 | | |
11221 | | /* |
11222 | | * Check for illegal attributes. |
11223 | | */ |
11224 | 0 | attr = node->properties; |
11225 | 0 | while (attr != NULL) { |
11226 | 0 | if (attr->ns == NULL) { |
11227 | 0 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
11228 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "base"))) { |
11229 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
11230 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
11231 | 0 | } |
11232 | 0 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
11233 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
11234 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
11235 | 0 | } |
11236 | 0 | attr = attr->next; |
11237 | 0 | } |
11238 | | /* |
11239 | | * Extract and validate attributes. |
11240 | | */ |
11241 | 0 | xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id"); |
11242 | | /* |
11243 | | * Attribute |
11244 | | */ |
11245 | | /* |
11246 | | * Extract the base type. The "base" attribute is mandatory if inside |
11247 | | * a complex type or if redefining. |
11248 | | * |
11249 | | * SPEC (1.2) "...otherwise (<restriction> has no <simpleType> " |
11250 | | * among its [children]), the simple type definition which is |
11251 | | * the {content type} of the type definition `resolved` to by |
11252 | | * the `actual value` of the base [attribute]" |
11253 | | */ |
11254 | 0 | if (xmlSchemaPValAttrQName(ctxt, schema, NULL, node, "base", |
11255 | 0 | &(type->baseNs), &(type->base)) == 0) |
11256 | 0 | { |
11257 | 0 | if ((type->base == NULL) && (type->type == XML_SCHEMA_TYPE_COMPLEX)) { |
11258 | 0 | xmlSchemaPMissingAttrErr(ctxt, |
11259 | 0 | XML_SCHEMAP_S4S_ATTR_MISSING, |
11260 | 0 | NULL, node, "base", NULL); |
11261 | 0 | } else if ((ctxt->isRedefine) && |
11262 | 0 | (type->flags & XML_SCHEMAS_TYPE_GLOBAL)) |
11263 | 0 | { |
11264 | 0 | if (type->base == NULL) { |
11265 | 0 | xmlSchemaPMissingAttrErr(ctxt, |
11266 | 0 | XML_SCHEMAP_S4S_ATTR_MISSING, |
11267 | 0 | NULL, node, "base", NULL); |
11268 | 0 | } else if ((! xmlStrEqual(type->base, type->name)) || |
11269 | 0 | (! xmlStrEqual(type->baseNs, type->targetNamespace))) |
11270 | 0 | { |
11271 | 0 | xmlChar *str1 = NULL, *str2 = NULL; |
11272 | | /* |
11273 | | * REDEFINE: SPEC src-redefine (5) |
11274 | | * "Within the [children], each <simpleType> must have a |
11275 | | * <restriction> among its [children] ... the `actual value` of |
11276 | | * whose base [attribute] must be the same as the `actual value` |
11277 | | * of its own name attribute plus target namespace;" |
11278 | | */ |
11279 | 0 | xmlSchemaPCustomErrExt(ctxt, XML_SCHEMAP_SRC_REDEFINE, |
11280 | 0 | NULL, node, "This is a redefinition, but the QName " |
11281 | 0 | "value '%s' of the 'base' attribute does not match the " |
11282 | 0 | "type's designation '%s'", |
11283 | 0 | xmlSchemaFormatQName(&str1, type->baseNs, type->base), |
11284 | 0 | xmlSchemaFormatQName(&str2, type->targetNamespace, |
11285 | 0 | type->name), NULL); |
11286 | 0 | FREE_AND_NULL(str1); |
11287 | 0 | FREE_AND_NULL(str2); |
11288 | | /* Avoid confusion and erase the values. */ |
11289 | 0 | type->base = NULL; |
11290 | 0 | type->baseNs = NULL; |
11291 | 0 | } |
11292 | 0 | } |
11293 | 0 | } |
11294 | | /* |
11295 | | * And now for the children... |
11296 | | */ |
11297 | 0 | child = node->children; |
11298 | 0 | if (IS_SCHEMA(child, "annotation")) { |
11299 | | /* |
11300 | | * Add the annotation to the simple type ancestor. |
11301 | | */ |
11302 | 0 | xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) type, |
11303 | 0 | xmlSchemaParseAnnotation(ctxt, child, 1)); |
11304 | 0 | child = child->next; |
11305 | 0 | } |
11306 | 0 | if (parentType == XML_SCHEMA_TYPE_SIMPLE) { |
11307 | | /* |
11308 | | * Corresponds to <simpleType><restriction><simpleType>. |
11309 | | */ |
11310 | 0 | if (IS_SCHEMA(child, "simpleType")) { |
11311 | 0 | if (type->base != NULL) { |
11312 | | /* |
11313 | | * src-restriction-base-or-simpleType |
11314 | | * Either the base [attribute] or the simpleType [child] of the |
11315 | | * <restriction> element must be present, but not both. |
11316 | | */ |
11317 | 0 | xmlSchemaPContentErr(ctxt, |
11318 | 0 | XML_SCHEMAP_SRC_RESTRICTION_BASE_OR_SIMPLETYPE, |
11319 | 0 | NULL, node, child, |
11320 | 0 | "The attribute 'base' and the <simpleType> child are " |
11321 | 0 | "mutually exclusive", NULL); |
11322 | 0 | } else { |
11323 | 0 | type->baseType = (xmlSchemaTypePtr) |
11324 | 0 | xmlSchemaParseSimpleType(ctxt, schema, child, 0); |
11325 | 0 | } |
11326 | 0 | child = child->next; |
11327 | 0 | } else if (type->base == NULL) { |
11328 | 0 | xmlSchemaPContentErr(ctxt, |
11329 | 0 | XML_SCHEMAP_SRC_RESTRICTION_BASE_OR_SIMPLETYPE, |
11330 | 0 | NULL, node, child, |
11331 | 0 | "Either the attribute 'base' or a <simpleType> child " |
11332 | 0 | "must be present", NULL); |
11333 | 0 | } |
11334 | 0 | } else if (parentType == XML_SCHEMA_TYPE_COMPLEX_CONTENT) { |
11335 | | /* |
11336 | | * Corresponds to <complexType><complexContent><restriction>... |
11337 | | * followed by: |
11338 | | * |
11339 | | * Model groups <all>, <choice> and <sequence>. |
11340 | | */ |
11341 | 0 | if (IS_SCHEMA(child, "all")) { |
11342 | 0 | type->subtypes = (xmlSchemaTypePtr) |
11343 | 0 | xmlSchemaParseModelGroup(ctxt, schema, child, |
11344 | 0 | XML_SCHEMA_TYPE_ALL, 1); |
11345 | 0 | child = child->next; |
11346 | 0 | } else if (IS_SCHEMA(child, "choice")) { |
11347 | 0 | type->subtypes = (xmlSchemaTypePtr) |
11348 | 0 | xmlSchemaParseModelGroup(ctxt, |
11349 | 0 | schema, child, XML_SCHEMA_TYPE_CHOICE, 1); |
11350 | 0 | child = child->next; |
11351 | 0 | } else if (IS_SCHEMA(child, "sequence")) { |
11352 | 0 | type->subtypes = (xmlSchemaTypePtr) |
11353 | 0 | xmlSchemaParseModelGroup(ctxt, schema, child, |
11354 | 0 | XML_SCHEMA_TYPE_SEQUENCE, 1); |
11355 | 0 | child = child->next; |
11356 | | /* |
11357 | | * Model group reference <group>. |
11358 | | */ |
11359 | 0 | } else if (IS_SCHEMA(child, "group")) { |
11360 | 0 | type->subtypes = (xmlSchemaTypePtr) |
11361 | 0 | xmlSchemaParseModelGroupDefRef(ctxt, schema, child); |
11362 | | /* |
11363 | | * Note that the reference will be resolved in |
11364 | | * xmlSchemaResolveTypeReferences(); |
11365 | | */ |
11366 | 0 | child = child->next; |
11367 | 0 | } |
11368 | 0 | } else if (parentType == XML_SCHEMA_TYPE_SIMPLE_CONTENT) { |
11369 | | /* |
11370 | | * Corresponds to <complexType><simpleContent><restriction>... |
11371 | | * |
11372 | | * "1.1 the simple type definition corresponding to the <simpleType> |
11373 | | * among the [children] of <restriction> if there is one;" |
11374 | | */ |
11375 | 0 | if (IS_SCHEMA(child, "simpleType")) { |
11376 | | /* |
11377 | | * We will store the to-be-restricted simple type in |
11378 | | * type->contentTypeDef *temporarily*. |
11379 | | */ |
11380 | 0 | type->contentTypeDef = (xmlSchemaTypePtr) |
11381 | 0 | xmlSchemaParseSimpleType(ctxt, schema, child, 0); |
11382 | 0 | if ( type->contentTypeDef == NULL) |
11383 | 0 | return (NULL); |
11384 | 0 | child = child->next; |
11385 | 0 | } |
11386 | 0 | } |
11387 | | |
11388 | 0 | if ((parentType == XML_SCHEMA_TYPE_SIMPLE) || |
11389 | 0 | (parentType == XML_SCHEMA_TYPE_SIMPLE_CONTENT)) { |
11390 | 0 | xmlSchemaFacetPtr facet, lastfacet = NULL; |
11391 | | /* |
11392 | | * Corresponds to <complexType><simpleContent><restriction>... |
11393 | | * <simpleType><restriction>... |
11394 | | */ |
11395 | | |
11396 | | /* |
11397 | | * Add the facets to the simple type ancestor. |
11398 | | */ |
11399 | | /* |
11400 | | * TODO: Datatypes: 4.1.3 Constraints on XML Representation of |
11401 | | * Simple Type Definition Schema Representation Constraint: |
11402 | | * *Single Facet Value* |
11403 | | */ |
11404 | 0 | while ((IS_SCHEMA(child, "minInclusive")) || |
11405 | 0 | (IS_SCHEMA(child, "minExclusive")) || |
11406 | 0 | (IS_SCHEMA(child, "maxInclusive")) || |
11407 | 0 | (IS_SCHEMA(child, "maxExclusive")) || |
11408 | 0 | (IS_SCHEMA(child, "totalDigits")) || |
11409 | 0 | (IS_SCHEMA(child, "fractionDigits")) || |
11410 | 0 | (IS_SCHEMA(child, "pattern")) || |
11411 | 0 | (IS_SCHEMA(child, "enumeration")) || |
11412 | 0 | (IS_SCHEMA(child, "whiteSpace")) || |
11413 | 0 | (IS_SCHEMA(child, "length")) || |
11414 | 0 | (IS_SCHEMA(child, "maxLength")) || |
11415 | 0 | (IS_SCHEMA(child, "minLength"))) { |
11416 | 0 | facet = xmlSchemaParseFacet(ctxt, schema, child); |
11417 | 0 | if (facet != NULL) { |
11418 | 0 | if (lastfacet == NULL) |
11419 | 0 | type->facets = facet; |
11420 | 0 | else |
11421 | 0 | lastfacet->next = facet; |
11422 | 0 | lastfacet = facet; |
11423 | 0 | lastfacet->next = NULL; |
11424 | 0 | } |
11425 | 0 | child = child->next; |
11426 | 0 | } |
11427 | | /* |
11428 | | * Create links for derivation and validation. |
11429 | | */ |
11430 | 0 | if (type->facets != NULL) { |
11431 | 0 | xmlSchemaFacetLinkPtr facetLink, lastFacetLink = NULL; |
11432 | |
|
11433 | 0 | facet = type->facets; |
11434 | 0 | do { |
11435 | 0 | facetLink = (xmlSchemaFacetLinkPtr) |
11436 | 0 | xmlMalloc(sizeof(xmlSchemaFacetLink)); |
11437 | 0 | if (facetLink == NULL) { |
11438 | 0 | xmlSchemaPErrMemory(ctxt); |
11439 | 0 | xmlFree(facetLink); |
11440 | 0 | return (NULL); |
11441 | 0 | } |
11442 | 0 | facetLink->facet = facet; |
11443 | 0 | facetLink->next = NULL; |
11444 | 0 | if (lastFacetLink == NULL) |
11445 | 0 | type->facetSet = facetLink; |
11446 | 0 | else |
11447 | 0 | lastFacetLink->next = facetLink; |
11448 | 0 | lastFacetLink = facetLink; |
11449 | 0 | facet = facet->next; |
11450 | 0 | } while (facet != NULL); |
11451 | 0 | } |
11452 | 0 | } |
11453 | 0 | if (type->type == XML_SCHEMA_TYPE_COMPLEX) { |
11454 | | /* |
11455 | | * Attribute uses/declarations. |
11456 | | */ |
11457 | 0 | if (xmlSchemaParseLocalAttributes(ctxt, schema, &child, |
11458 | 0 | (xmlSchemaItemListPtr *) &(type->attrUses), |
11459 | 0 | XML_SCHEMA_TYPE_RESTRICTION, NULL) == -1) |
11460 | 0 | return(NULL); |
11461 | | /* |
11462 | | * Attribute wildcard. |
11463 | | */ |
11464 | 0 | if (IS_SCHEMA(child, "anyAttribute")) { |
11465 | 0 | type->attributeWildcard = |
11466 | 0 | xmlSchemaParseAnyAttribute(ctxt, schema, child); |
11467 | 0 | child = child->next; |
11468 | 0 | } |
11469 | 0 | } |
11470 | 0 | if (child != NULL) { |
11471 | 0 | if (parentType == XML_SCHEMA_TYPE_COMPLEX_CONTENT) { |
11472 | 0 | xmlSchemaPContentErr(ctxt, |
11473 | 0 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
11474 | 0 | NULL, node, child, NULL, |
11475 | 0 | "annotation?, (group | all | choice | sequence)?, " |
11476 | 0 | "((attribute | attributeGroup)*, anyAttribute?))"); |
11477 | 0 | } else if (parentType == XML_SCHEMA_TYPE_SIMPLE_CONTENT) { |
11478 | 0 | xmlSchemaPContentErr(ctxt, |
11479 | 0 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
11480 | 0 | NULL, node, child, NULL, |
11481 | 0 | "(annotation?, (simpleType?, (minExclusive | minInclusive | " |
11482 | 0 | "maxExclusive | maxInclusive | totalDigits | fractionDigits | " |
11483 | 0 | "length | minLength | maxLength | enumeration | whiteSpace | " |
11484 | 0 | "pattern)*)?, ((attribute | attributeGroup)*, anyAttribute?))"); |
11485 | 0 | } else { |
11486 | | /* Simple type */ |
11487 | 0 | xmlSchemaPContentErr(ctxt, |
11488 | 0 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
11489 | 0 | NULL, node, child, NULL, |
11490 | 0 | "(annotation?, (simpleType?, (minExclusive | minInclusive | " |
11491 | 0 | "maxExclusive | maxInclusive | totalDigits | fractionDigits | " |
11492 | 0 | "length | minLength | maxLength | enumeration | whiteSpace | " |
11493 | 0 | "pattern)*))"); |
11494 | 0 | } |
11495 | 0 | } |
11496 | 0 | return (NULL); |
11497 | 0 | } |
11498 | | |
11499 | | /** |
11500 | | * Parses an `<extension>`, which is found inside a |
11501 | | * `<simpleContent>` or `<complexContent>`. |
11502 | | * *WARNING* this interface is highly subject to change. |
11503 | | * |
11504 | | * @param ctxt a schema validation context |
11505 | | * @param schema the schema being built |
11506 | | * @param node a subtree containing XML Schema information |
11507 | | * @param parentType parent type |
11508 | | * @returns the type definition or NULL in case of error |
11509 | | */ |
11510 | | static xmlSchemaTypePtr |
11511 | | xmlSchemaParseExtension(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
11512 | | xmlNodePtr node, xmlSchemaTypeType parentType) |
11513 | 0 | { |
11514 | 0 | xmlSchemaTypePtr type; |
11515 | 0 | xmlNodePtr child = NULL; |
11516 | 0 | xmlAttrPtr attr; |
11517 | |
|
11518 | 0 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
11519 | 0 | return (NULL); |
11520 | | /* Not a component, don't create it. */ |
11521 | 0 | type = ctxt->ctxtType; |
11522 | 0 | type->flags |= XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION; |
11523 | | |
11524 | | /* |
11525 | | * Check for illegal attributes. |
11526 | | */ |
11527 | 0 | attr = node->properties; |
11528 | 0 | while (attr != NULL) { |
11529 | 0 | if (attr->ns == NULL) { |
11530 | 0 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
11531 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "base"))) { |
11532 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
11533 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
11534 | 0 | } |
11535 | 0 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
11536 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
11537 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
11538 | 0 | } |
11539 | 0 | attr = attr->next; |
11540 | 0 | } |
11541 | |
|
11542 | 0 | xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id"); |
11543 | | |
11544 | | /* |
11545 | | * Attribute "base" - mandatory. |
11546 | | */ |
11547 | 0 | if ((xmlSchemaPValAttrQName(ctxt, schema, NULL, node, |
11548 | 0 | "base", &(type->baseNs), &(type->base)) == 0) && |
11549 | 0 | (type->base == NULL)) { |
11550 | 0 | xmlSchemaPMissingAttrErr(ctxt, |
11551 | 0 | XML_SCHEMAP_S4S_ATTR_MISSING, |
11552 | 0 | NULL, node, "base", NULL); |
11553 | 0 | } |
11554 | | /* |
11555 | | * And now for the children... |
11556 | | */ |
11557 | 0 | child = node->children; |
11558 | 0 | if (IS_SCHEMA(child, "annotation")) { |
11559 | | /* |
11560 | | * Add the annotation to the type ancestor. |
11561 | | */ |
11562 | 0 | xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) type, |
11563 | 0 | xmlSchemaParseAnnotation(ctxt, child, 1)); |
11564 | 0 | child = child->next; |
11565 | 0 | } |
11566 | 0 | if (parentType == XML_SCHEMA_TYPE_COMPLEX_CONTENT) { |
11567 | | /* |
11568 | | * Corresponds to <complexType><complexContent><extension>... and: |
11569 | | * |
11570 | | * Model groups <all>, <choice>, <sequence> and <group>. |
11571 | | */ |
11572 | 0 | if (IS_SCHEMA(child, "all")) { |
11573 | 0 | type->subtypes = (xmlSchemaTypePtr) |
11574 | 0 | xmlSchemaParseModelGroup(ctxt, schema, |
11575 | 0 | child, XML_SCHEMA_TYPE_ALL, 1); |
11576 | 0 | child = child->next; |
11577 | 0 | } else if (IS_SCHEMA(child, "choice")) { |
11578 | 0 | type->subtypes = (xmlSchemaTypePtr) |
11579 | 0 | xmlSchemaParseModelGroup(ctxt, schema, |
11580 | 0 | child, XML_SCHEMA_TYPE_CHOICE, 1); |
11581 | 0 | child = child->next; |
11582 | 0 | } else if (IS_SCHEMA(child, "sequence")) { |
11583 | 0 | type->subtypes = (xmlSchemaTypePtr) |
11584 | 0 | xmlSchemaParseModelGroup(ctxt, schema, |
11585 | 0 | child, XML_SCHEMA_TYPE_SEQUENCE, 1); |
11586 | 0 | child = child->next; |
11587 | 0 | } else if (IS_SCHEMA(child, "group")) { |
11588 | 0 | type->subtypes = (xmlSchemaTypePtr) |
11589 | 0 | xmlSchemaParseModelGroupDefRef(ctxt, schema, child); |
11590 | | /* |
11591 | | * Note that the reference will be resolved in |
11592 | | * xmlSchemaResolveTypeReferences(); |
11593 | | */ |
11594 | 0 | child = child->next; |
11595 | 0 | } |
11596 | 0 | } |
11597 | 0 | if (child != NULL) { |
11598 | | /* |
11599 | | * Attribute uses/declarations. |
11600 | | */ |
11601 | 0 | if (xmlSchemaParseLocalAttributes(ctxt, schema, &child, |
11602 | 0 | (xmlSchemaItemListPtr *) &(type->attrUses), |
11603 | 0 | XML_SCHEMA_TYPE_EXTENSION, NULL) == -1) |
11604 | 0 | return(NULL); |
11605 | | /* |
11606 | | * Attribute wildcard. |
11607 | | */ |
11608 | 0 | if (IS_SCHEMA(child, "anyAttribute")) { |
11609 | 0 | ctxt->ctxtType->attributeWildcard = |
11610 | 0 | xmlSchemaParseAnyAttribute(ctxt, schema, child); |
11611 | 0 | child = child->next; |
11612 | 0 | } |
11613 | 0 | } |
11614 | 0 | if (child != NULL) { |
11615 | 0 | if (parentType == XML_SCHEMA_TYPE_COMPLEX_CONTENT) { |
11616 | | /* Complex content extension. */ |
11617 | 0 | xmlSchemaPContentErr(ctxt, |
11618 | 0 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
11619 | 0 | NULL, node, child, NULL, |
11620 | 0 | "(annotation?, ((group | all | choice | sequence)?, " |
11621 | 0 | "((attribute | attributeGroup)*, anyAttribute?)))"); |
11622 | 0 | } else { |
11623 | | /* Simple content extension. */ |
11624 | 0 | xmlSchemaPContentErr(ctxt, |
11625 | 0 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
11626 | 0 | NULL, node, child, NULL, |
11627 | 0 | "(annotation?, ((attribute | attributeGroup)*, " |
11628 | 0 | "anyAttribute?))"); |
11629 | 0 | } |
11630 | 0 | } |
11631 | 0 | return (NULL); |
11632 | 0 | } |
11633 | | |
11634 | | /** |
11635 | | * parse a XML schema SimpleContent definition |
11636 | | * *WARNING* this interface is highly subject to change |
11637 | | * |
11638 | | * @param ctxt a schema validation context |
11639 | | * @param schema the schema being built |
11640 | | * @param node a subtree containing XML Schema information |
11641 | | * @param hasRestrictionOrExtension set if restriction or extension was found |
11642 | | * @returns the type definition or NULL in case of error |
11643 | | */ |
11644 | | static int |
11645 | | xmlSchemaParseSimpleContent(xmlSchemaParserCtxtPtr ctxt, |
11646 | | xmlSchemaPtr schema, xmlNodePtr node, |
11647 | | int *hasRestrictionOrExtension) |
11648 | 0 | { |
11649 | 0 | xmlSchemaTypePtr type; |
11650 | 0 | xmlNodePtr child = NULL; |
11651 | 0 | xmlAttrPtr attr; |
11652 | |
|
11653 | 0 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL) || |
11654 | 0 | (hasRestrictionOrExtension == NULL)) |
11655 | 0 | return (-1); |
11656 | 0 | *hasRestrictionOrExtension = 0; |
11657 | | /* Not a component, don't create it. */ |
11658 | 0 | type = ctxt->ctxtType; |
11659 | 0 | type->contentType = XML_SCHEMA_CONTENT_SIMPLE; |
11660 | | /* |
11661 | | * Check for illegal attributes. |
11662 | | */ |
11663 | 0 | attr = node->properties; |
11664 | 0 | while (attr != NULL) { |
11665 | 0 | if (attr->ns == NULL) { |
11666 | 0 | if ((!xmlStrEqual(attr->name, BAD_CAST "id"))) { |
11667 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
11668 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
11669 | 0 | } |
11670 | 0 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
11671 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
11672 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
11673 | 0 | } |
11674 | 0 | attr = attr->next; |
11675 | 0 | } |
11676 | |
|
11677 | 0 | xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id"); |
11678 | | |
11679 | | /* |
11680 | | * And now for the children... |
11681 | | */ |
11682 | 0 | child = node->children; |
11683 | 0 | if (IS_SCHEMA(child, "annotation")) { |
11684 | | /* |
11685 | | * Add the annotation to the complex type ancestor. |
11686 | | */ |
11687 | 0 | xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) type, |
11688 | 0 | xmlSchemaParseAnnotation(ctxt, child, 1)); |
11689 | 0 | child = child->next; |
11690 | 0 | } |
11691 | 0 | if (child == NULL) { |
11692 | 0 | xmlSchemaPContentErr(ctxt, |
11693 | 0 | XML_SCHEMAP_S4S_ELEM_MISSING, |
11694 | 0 | NULL, node, NULL, NULL, |
11695 | 0 | "(annotation?, (restriction | extension))"); |
11696 | 0 | } |
11697 | 0 | if (child == NULL) { |
11698 | 0 | xmlSchemaPContentErr(ctxt, |
11699 | 0 | XML_SCHEMAP_S4S_ELEM_MISSING, |
11700 | 0 | NULL, node, NULL, NULL, |
11701 | 0 | "(annotation?, (restriction | extension))"); |
11702 | 0 | } |
11703 | 0 | if (IS_SCHEMA(child, "restriction")) { |
11704 | 0 | xmlSchemaParseRestriction(ctxt, schema, child, |
11705 | 0 | XML_SCHEMA_TYPE_SIMPLE_CONTENT); |
11706 | 0 | (*hasRestrictionOrExtension) = 1; |
11707 | 0 | child = child->next; |
11708 | 0 | } else if (IS_SCHEMA(child, "extension")) { |
11709 | 0 | xmlSchemaParseExtension(ctxt, schema, child, |
11710 | 0 | XML_SCHEMA_TYPE_SIMPLE_CONTENT); |
11711 | 0 | (*hasRestrictionOrExtension) = 1; |
11712 | 0 | child = child->next; |
11713 | 0 | } |
11714 | 0 | if (child != NULL) { |
11715 | 0 | xmlSchemaPContentErr(ctxt, |
11716 | 0 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
11717 | 0 | NULL, node, child, NULL, |
11718 | 0 | "(annotation?, (restriction | extension))"); |
11719 | 0 | } |
11720 | 0 | return (0); |
11721 | 0 | } |
11722 | | |
11723 | | /** |
11724 | | * parse a XML schema ComplexContent definition |
11725 | | * *WARNING* this interface is highly subject to change |
11726 | | * |
11727 | | * @param ctxt a schema validation context |
11728 | | * @param schema the schema being built |
11729 | | * @param node a subtree containing XML Schema information |
11730 | | * @param hasRestrictionOrExtension set if restriction or extension was found |
11731 | | * @returns the type definition or NULL in case of error |
11732 | | */ |
11733 | | static int |
11734 | | xmlSchemaParseComplexContent(xmlSchemaParserCtxtPtr ctxt, |
11735 | | xmlSchemaPtr schema, xmlNodePtr node, |
11736 | | int *hasRestrictionOrExtension) |
11737 | 0 | { |
11738 | 0 | xmlSchemaTypePtr type; |
11739 | 0 | xmlNodePtr child = NULL; |
11740 | 0 | xmlAttrPtr attr; |
11741 | |
|
11742 | 0 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL) || |
11743 | 0 | (hasRestrictionOrExtension == NULL)) |
11744 | 0 | return (-1); |
11745 | 0 | *hasRestrictionOrExtension = 0; |
11746 | | /* Not a component, don't create it. */ |
11747 | 0 | type = ctxt->ctxtType; |
11748 | | /* |
11749 | | * Check for illegal attributes. |
11750 | | */ |
11751 | 0 | attr = node->properties; |
11752 | 0 | while (attr != NULL) { |
11753 | 0 | if (attr->ns == NULL) { |
11754 | 0 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
11755 | 0 | (!xmlStrEqual(attr->name, BAD_CAST "mixed"))) |
11756 | 0 | { |
11757 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
11758 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
11759 | 0 | } |
11760 | 0 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
11761 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
11762 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
11763 | 0 | } |
11764 | 0 | attr = attr->next; |
11765 | 0 | } |
11766 | |
|
11767 | 0 | xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id"); |
11768 | | |
11769 | | /* |
11770 | | * Set the 'mixed' on the complex type ancestor. |
11771 | | */ |
11772 | 0 | if (xmlGetBooleanProp(ctxt, node, "mixed", 0)) { |
11773 | 0 | if ((type->flags & XML_SCHEMAS_TYPE_MIXED) == 0) |
11774 | 0 | type->flags |= XML_SCHEMAS_TYPE_MIXED; |
11775 | 0 | } |
11776 | 0 | child = node->children; |
11777 | 0 | if (IS_SCHEMA(child, "annotation")) { |
11778 | | /* |
11779 | | * Add the annotation to the complex type ancestor. |
11780 | | */ |
11781 | 0 | xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) type, |
11782 | 0 | xmlSchemaParseAnnotation(ctxt, child, 1)); |
11783 | 0 | child = child->next; |
11784 | 0 | } |
11785 | 0 | if (child == NULL) { |
11786 | 0 | xmlSchemaPContentErr(ctxt, |
11787 | 0 | XML_SCHEMAP_S4S_ELEM_MISSING, |
11788 | 0 | NULL, node, NULL, |
11789 | 0 | NULL, "(annotation?, (restriction | extension))"); |
11790 | 0 | } |
11791 | 0 | if (child == NULL) { |
11792 | 0 | xmlSchemaPContentErr(ctxt, |
11793 | 0 | XML_SCHEMAP_S4S_ELEM_MISSING, |
11794 | 0 | NULL, node, NULL, |
11795 | 0 | NULL, "(annotation?, (restriction | extension))"); |
11796 | 0 | } |
11797 | 0 | if (IS_SCHEMA(child, "restriction")) { |
11798 | 0 | xmlSchemaParseRestriction(ctxt, schema, child, |
11799 | 0 | XML_SCHEMA_TYPE_COMPLEX_CONTENT); |
11800 | 0 | (*hasRestrictionOrExtension) = 1; |
11801 | 0 | child = child->next; |
11802 | 0 | } else if (IS_SCHEMA(child, "extension")) { |
11803 | 0 | xmlSchemaParseExtension(ctxt, schema, child, |
11804 | 0 | XML_SCHEMA_TYPE_COMPLEX_CONTENT); |
11805 | 0 | (*hasRestrictionOrExtension) = 1; |
11806 | 0 | child = child->next; |
11807 | 0 | } |
11808 | 0 | if (child != NULL) { |
11809 | 0 | xmlSchemaPContentErr(ctxt, |
11810 | 0 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
11811 | 0 | NULL, node, child, |
11812 | 0 | NULL, "(annotation?, (restriction | extension))"); |
11813 | 0 | } |
11814 | 0 | return (0); |
11815 | 0 | } |
11816 | | |
11817 | | /** |
11818 | | * parse a XML schema Complex Type definition |
11819 | | * *WARNING* this interface is highly subject to change |
11820 | | * |
11821 | | * @param ctxt a schema validation context |
11822 | | * @param schema the schema being built |
11823 | | * @param node a subtree containing XML Schema information |
11824 | | * @param topLevel whether this is a top-level element |
11825 | | * @returns the type definition or NULL in case of error |
11826 | | */ |
11827 | | static xmlSchemaTypePtr |
11828 | | xmlSchemaParseComplexType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
11829 | | xmlNodePtr node, int topLevel) |
11830 | 0 | { |
11831 | 0 | xmlSchemaTypePtr type, ctxtType; |
11832 | 0 | xmlNodePtr child = NULL; |
11833 | 0 | const xmlChar *name = NULL; |
11834 | 0 | xmlAttrPtr attr; |
11835 | 0 | const xmlChar *attrValue; |
11836 | | #ifdef ENABLE_NAMED_LOCALS |
11837 | | char buf[40]; |
11838 | | #endif |
11839 | 0 | int final = 0, block = 0, hasRestrictionOrExtension = 0; |
11840 | | |
11841 | |
|
11842 | 0 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
11843 | 0 | return (NULL); |
11844 | | |
11845 | 0 | ctxtType = ctxt->ctxtType; |
11846 | |
|
11847 | 0 | if (topLevel) { |
11848 | 0 | attr = xmlSchemaGetPropNode(node, "name"); |
11849 | 0 | if (attr == NULL) { |
11850 | 0 | xmlSchemaPMissingAttrErr(ctxt, |
11851 | 0 | XML_SCHEMAP_S4S_ATTR_MISSING, NULL, node, "name", NULL); |
11852 | 0 | return (NULL); |
11853 | 0 | } else if (xmlSchemaPValAttrNode(ctxt, NULL, attr, |
11854 | 0 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) { |
11855 | 0 | return (NULL); |
11856 | 0 | } |
11857 | 0 | } |
11858 | | |
11859 | 0 | if (topLevel == 0) { |
11860 | | /* |
11861 | | * Parse as local complex type definition. |
11862 | | */ |
11863 | | #ifdef ENABLE_NAMED_LOCALS |
11864 | | snprintf(buf, 39, "#CT%d", ctxt->counter++ + 1); |
11865 | | type = xmlSchemaAddType(ctxt, schema, |
11866 | | XML_SCHEMA_TYPE_COMPLEX, |
11867 | | xmlDictLookup(ctxt->dict, (const xmlChar *)buf, -1), |
11868 | | ctxt->targetNamespace, node, 0); |
11869 | | #else |
11870 | 0 | type = xmlSchemaAddType(ctxt, schema, |
11871 | 0 | XML_SCHEMA_TYPE_COMPLEX, |
11872 | 0 | NULL, ctxt->targetNamespace, node, 0); |
11873 | 0 | #endif |
11874 | 0 | if (type == NULL) |
11875 | 0 | return (NULL); |
11876 | 0 | name = type->name; |
11877 | 0 | type->node = node; |
11878 | 0 | type->type = XML_SCHEMA_TYPE_COMPLEX; |
11879 | | /* |
11880 | | * TODO: We need the target namespace. |
11881 | | */ |
11882 | 0 | } else { |
11883 | | /* |
11884 | | * Parse as global complex type definition. |
11885 | | */ |
11886 | 0 | type = xmlSchemaAddType(ctxt, schema, |
11887 | 0 | XML_SCHEMA_TYPE_COMPLEX, |
11888 | 0 | name, ctxt->targetNamespace, node, 1); |
11889 | 0 | if (type == NULL) |
11890 | 0 | return (NULL); |
11891 | 0 | type->node = node; |
11892 | 0 | type->type = XML_SCHEMA_TYPE_COMPLEX; |
11893 | 0 | type->flags |= XML_SCHEMAS_TYPE_GLOBAL; |
11894 | 0 | } |
11895 | 0 | type->targetNamespace = ctxt->targetNamespace; |
11896 | | /* |
11897 | | * Handle attributes. |
11898 | | */ |
11899 | 0 | attr = node->properties; |
11900 | 0 | while (attr != NULL) { |
11901 | 0 | if (attr->ns == NULL) { |
11902 | 0 | if (xmlStrEqual(attr->name, BAD_CAST "id")) { |
11903 | | /* |
11904 | | * Attribute "id". |
11905 | | */ |
11906 | 0 | xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id"); |
11907 | 0 | } else if (xmlStrEqual(attr->name, BAD_CAST "mixed")) { |
11908 | | /* |
11909 | | * Attribute "mixed". |
11910 | | */ |
11911 | 0 | if (xmlSchemaPGetBoolNodeValue(ctxt, |
11912 | 0 | NULL, (xmlNodePtr) attr)) |
11913 | 0 | type->flags |= XML_SCHEMAS_TYPE_MIXED; |
11914 | 0 | } else if (topLevel) { |
11915 | | /* |
11916 | | * Attributes of global complex type definitions. |
11917 | | */ |
11918 | 0 | if (xmlStrEqual(attr->name, BAD_CAST "name")) { |
11919 | | /* Pass. */ |
11920 | 0 | } else if (xmlStrEqual(attr->name, BAD_CAST "abstract")) { |
11921 | | /* |
11922 | | * Attribute "abstract". |
11923 | | */ |
11924 | 0 | if (xmlSchemaPGetBoolNodeValue(ctxt, |
11925 | 0 | NULL, (xmlNodePtr) attr)) |
11926 | 0 | type->flags |= XML_SCHEMAS_TYPE_ABSTRACT; |
11927 | 0 | } else if (xmlStrEqual(attr->name, BAD_CAST "final")) { |
11928 | | /* |
11929 | | * Attribute "final". |
11930 | | */ |
11931 | 0 | attrValue = xmlSchemaGetNodeContent(ctxt, |
11932 | 0 | (xmlNodePtr) attr); |
11933 | 0 | if (xmlSchemaPValAttrBlockFinal(attrValue, |
11934 | 0 | &(type->flags), |
11935 | 0 | -1, |
11936 | 0 | XML_SCHEMAS_TYPE_FINAL_EXTENSION, |
11937 | 0 | XML_SCHEMAS_TYPE_FINAL_RESTRICTION, |
11938 | 0 | -1, -1, -1) != 0) |
11939 | 0 | { |
11940 | 0 | xmlSchemaPSimpleTypeErr(ctxt, |
11941 | 0 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
11942 | 0 | NULL, (xmlNodePtr) attr, NULL, |
11943 | 0 | "(#all | List of (extension | restriction))", |
11944 | 0 | attrValue, NULL, NULL, NULL); |
11945 | 0 | } else |
11946 | 0 | final = 1; |
11947 | 0 | } else if (xmlStrEqual(attr->name, BAD_CAST "block")) { |
11948 | | /* |
11949 | | * Attribute "block". |
11950 | | */ |
11951 | 0 | attrValue = xmlSchemaGetNodeContent(ctxt, |
11952 | 0 | (xmlNodePtr) attr); |
11953 | 0 | if (xmlSchemaPValAttrBlockFinal(attrValue, &(type->flags), |
11954 | 0 | -1, |
11955 | 0 | XML_SCHEMAS_TYPE_BLOCK_EXTENSION, |
11956 | 0 | XML_SCHEMAS_TYPE_BLOCK_RESTRICTION, |
11957 | 0 | -1, -1, -1) != 0) { |
11958 | 0 | xmlSchemaPSimpleTypeErr(ctxt, |
11959 | 0 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
11960 | 0 | NULL, (xmlNodePtr) attr, NULL, |
11961 | 0 | "(#all | List of (extension | restriction)) ", |
11962 | 0 | attrValue, NULL, NULL, NULL); |
11963 | 0 | } else |
11964 | 0 | block = 1; |
11965 | 0 | } else { |
11966 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
11967 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
11968 | 0 | } |
11969 | 0 | } else { |
11970 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
11971 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
11972 | 0 | } |
11973 | 0 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
11974 | 0 | xmlSchemaPIllegalAttrErr(ctxt, |
11975 | 0 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr); |
11976 | 0 | } |
11977 | 0 | attr = attr->next; |
11978 | 0 | } |
11979 | 0 | if (! block) { |
11980 | | /* |
11981 | | * Apply default "block" values. |
11982 | | */ |
11983 | 0 | if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION) |
11984 | 0 | type->flags |= XML_SCHEMAS_TYPE_BLOCK_RESTRICTION; |
11985 | 0 | if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION) |
11986 | 0 | type->flags |= XML_SCHEMAS_TYPE_BLOCK_EXTENSION; |
11987 | 0 | } |
11988 | 0 | if (! final) { |
11989 | | /* |
11990 | | * Apply default "block" values. |
11991 | | */ |
11992 | 0 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION) |
11993 | 0 | type->flags |= XML_SCHEMAS_TYPE_FINAL_RESTRICTION; |
11994 | 0 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_EXTENSION) |
11995 | 0 | type->flags |= XML_SCHEMAS_TYPE_FINAL_EXTENSION; |
11996 | 0 | } |
11997 | | /* |
11998 | | * And now for the children... |
11999 | | */ |
12000 | 0 | child = node->children; |
12001 | 0 | if (IS_SCHEMA(child, "annotation")) { |
12002 | 0 | type->annot = xmlSchemaParseAnnotation(ctxt, child, 1); |
12003 | 0 | child = child->next; |
12004 | 0 | } |
12005 | 0 | ctxt->ctxtType = type; |
12006 | 0 | if (IS_SCHEMA(child, "simpleContent")) { |
12007 | | /* |
12008 | | * <complexType><simpleContent>... |
12009 | | * 3.4.3 : 2.2 |
12010 | | * Specifying mixed='true' when the <simpleContent> |
12011 | | * alternative is chosen has no effect |
12012 | | */ |
12013 | 0 | if (type->flags & XML_SCHEMAS_TYPE_MIXED) |
12014 | 0 | type->flags ^= XML_SCHEMAS_TYPE_MIXED; |
12015 | 0 | xmlSchemaParseSimpleContent(ctxt, schema, child, |
12016 | 0 | &hasRestrictionOrExtension); |
12017 | 0 | child = child->next; |
12018 | 0 | } else if (IS_SCHEMA(child, "complexContent")) { |
12019 | | /* |
12020 | | * <complexType><complexContent>... |
12021 | | */ |
12022 | 0 | type->contentType = XML_SCHEMA_CONTENT_EMPTY; |
12023 | 0 | xmlSchemaParseComplexContent(ctxt, schema, child, |
12024 | 0 | &hasRestrictionOrExtension); |
12025 | 0 | child = child->next; |
12026 | 0 | } else { |
12027 | | /* |
12028 | | * E.g <complexType><sequence>... or <complexType><attribute>... etc. |
12029 | | * |
12030 | | * SPEC |
12031 | | * "...the third alternative (neither <simpleContent> nor |
12032 | | * <complexContent>) is chosen. This case is understood as shorthand |
12033 | | * for complex content restricting the `ur-type definition`, and the |
12034 | | * details of the mappings should be modified as necessary. |
12035 | | */ |
12036 | 0 | type->baseType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE); |
12037 | 0 | type->flags |= XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION; |
12038 | | /* |
12039 | | * Parse model groups. |
12040 | | */ |
12041 | 0 | if (IS_SCHEMA(child, "all")) { |
12042 | 0 | type->subtypes = (xmlSchemaTypePtr) |
12043 | 0 | xmlSchemaParseModelGroup(ctxt, schema, child, |
12044 | 0 | XML_SCHEMA_TYPE_ALL, 1); |
12045 | 0 | child = child->next; |
12046 | 0 | } else if (IS_SCHEMA(child, "choice")) { |
12047 | 0 | type->subtypes = (xmlSchemaTypePtr) |
12048 | 0 | xmlSchemaParseModelGroup(ctxt, schema, child, |
12049 | 0 | XML_SCHEMA_TYPE_CHOICE, 1); |
12050 | 0 | child = child->next; |
12051 | 0 | } else if (IS_SCHEMA(child, "sequence")) { |
12052 | 0 | type->subtypes = (xmlSchemaTypePtr) |
12053 | 0 | xmlSchemaParseModelGroup(ctxt, schema, child, |
12054 | 0 | XML_SCHEMA_TYPE_SEQUENCE, 1); |
12055 | 0 | child = child->next; |
12056 | 0 | } else if (IS_SCHEMA(child, "group")) { |
12057 | 0 | type->subtypes = (xmlSchemaTypePtr) |
12058 | 0 | xmlSchemaParseModelGroupDefRef(ctxt, schema, child); |
12059 | | /* |
12060 | | * Note that the reference will be resolved in |
12061 | | * xmlSchemaResolveTypeReferences(); |
12062 | | */ |
12063 | 0 | child = child->next; |
12064 | 0 | } |
12065 | | /* |
12066 | | * Parse attribute decls/refs. |
12067 | | */ |
12068 | 0 | if (xmlSchemaParseLocalAttributes(ctxt, schema, &child, |
12069 | 0 | (xmlSchemaItemListPtr *) &(type->attrUses), |
12070 | 0 | XML_SCHEMA_TYPE_RESTRICTION, NULL) == -1) |
12071 | 0 | return(NULL); |
12072 | | /* |
12073 | | * Parse attribute wildcard. |
12074 | | */ |
12075 | 0 | if (IS_SCHEMA(child, "anyAttribute")) { |
12076 | 0 | type->attributeWildcard = xmlSchemaParseAnyAttribute(ctxt, schema, child); |
12077 | 0 | child = child->next; |
12078 | 0 | } |
12079 | 0 | } |
12080 | 0 | if (child != NULL) { |
12081 | 0 | xmlSchemaPContentErr(ctxt, |
12082 | 0 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
12083 | 0 | NULL, node, child, |
12084 | 0 | NULL, "(annotation?, (simpleContent | complexContent | " |
12085 | 0 | "((group | all | choice | sequence)?, ((attribute | " |
12086 | 0 | "attributeGroup)*, anyAttribute?))))"); |
12087 | 0 | } |
12088 | | /* |
12089 | | * REDEFINE: SPEC src-redefine (5) |
12090 | | */ |
12091 | 0 | if (topLevel && ctxt->isRedefine && (! hasRestrictionOrExtension)) { |
12092 | 0 | xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_SRC_REDEFINE, |
12093 | 0 | NULL, node, "This is a redefinition, thus the " |
12094 | 0 | "<complexType> must have a <restriction> or <extension> " |
12095 | 0 | "grand-child", NULL); |
12096 | 0 | } |
12097 | 0 | ctxt->ctxtType = ctxtType; |
12098 | 0 | return (type); |
12099 | 0 | } |
12100 | | |
12101 | | /************************************************************************ |
12102 | | * * |
12103 | | * Validating using Schemas * |
12104 | | * * |
12105 | | ************************************************************************/ |
12106 | | |
12107 | | /************************************************************************ |
12108 | | * * |
12109 | | * Reading/Writing Schemas * |
12110 | | * * |
12111 | | ************************************************************************/ |
12112 | | |
12113 | | #if 0 /* Will be enabled if it is clear what options are needed. */ |
12114 | | /** |
12115 | | * Sets the options to be used during the parse. |
12116 | | * |
12117 | | * @param ctxt a schema parser context |
12118 | | * @param options a combination of xmlSchemaParserOption |
12119 | | * @returns 0 in case of success, -1 in case of an |
12120 | | * API error. |
12121 | | */ |
12122 | | static int |
12123 | | xmlSchemaParserCtxtSetOptions(xmlSchemaParserCtxtPtr ctxt, |
12124 | | int options) |
12125 | | |
12126 | | { |
12127 | | int i; |
12128 | | |
12129 | | if (ctxt == NULL) |
12130 | | return (-1); |
12131 | | /* |
12132 | | * WARNING: Change the start value if adding to the |
12133 | | * xmlSchemaParseOption. |
12134 | | */ |
12135 | | for (i = 1; i < (int) sizeof(int) * 8; i++) { |
12136 | | if (options & 1<<i) { |
12137 | | return (-1); |
12138 | | } |
12139 | | } |
12140 | | ctxt->options = options; |
12141 | | return (0); |
12142 | | } |
12143 | | |
12144 | | /** |
12145 | | * @param ctxt a schema parser context |
12146 | | * @returns the option combination of the parser context. |
12147 | | */ |
12148 | | static int |
12149 | | xmlSchemaParserCtxtGetOptions(xmlSchemaParserCtxtPtr ctxt) |
12150 | | |
12151 | | { |
12152 | | if (ctxt == NULL) |
12153 | | return (-1); |
12154 | | else |
12155 | | return (ctxt->options); |
12156 | | } |
12157 | | #endif |
12158 | | |
12159 | | /** |
12160 | | * Create an XML Schemas parse context for that file/resource expected |
12161 | | * to contain an XML Schemas file. |
12162 | | * |
12163 | | * @param URL the location of the schema |
12164 | | * @returns the parser context or NULL in case of error |
12165 | | */ |
12166 | | xmlSchemaParserCtxt * |
12167 | | xmlSchemaNewParserCtxt(const char *URL) |
12168 | 0 | { |
12169 | 0 | xmlSchemaParserCtxtPtr ret; |
12170 | |
|
12171 | 0 | if (URL == NULL) |
12172 | 0 | return (NULL); |
12173 | | |
12174 | 0 | ret = xmlSchemaParserCtxtCreate(); |
12175 | 0 | if (ret == NULL) |
12176 | 0 | return(NULL); |
12177 | 0 | ret->dict = xmlDictCreate(); |
12178 | 0 | ret->URL = xmlDictLookup(ret->dict, (const xmlChar *) URL, -1); |
12179 | 0 | return (ret); |
12180 | 0 | } |
12181 | | |
12182 | | /** |
12183 | | * Create an XML Schemas parse context for that memory buffer expected |
12184 | | * to contain an XML Schemas file. |
12185 | | * |
12186 | | * @param buffer a pointer to a char array containing the schemas |
12187 | | * @param size the size of the array |
12188 | | * @returns the parser context or NULL in case of error |
12189 | | */ |
12190 | | xmlSchemaParserCtxt * |
12191 | | xmlSchemaNewMemParserCtxt(const char *buffer, int size) |
12192 | 0 | { |
12193 | 0 | xmlSchemaParserCtxtPtr ret; |
12194 | |
|
12195 | 0 | if ((buffer == NULL) || (size <= 0)) |
12196 | 0 | return (NULL); |
12197 | 0 | ret = xmlSchemaParserCtxtCreate(); |
12198 | 0 | if (ret == NULL) |
12199 | 0 | return(NULL); |
12200 | 0 | ret->buffer = buffer; |
12201 | 0 | ret->size = size; |
12202 | 0 | ret->dict = xmlDictCreate(); |
12203 | 0 | return (ret); |
12204 | 0 | } |
12205 | | |
12206 | | /** |
12207 | | * Create an XML Schemas parse context for that document. |
12208 | | * NB. The document may be modified during the parsing process. |
12209 | | * |
12210 | | * @param doc a preparsed document tree |
12211 | | * @returns the parser context or NULL in case of error |
12212 | | */ |
12213 | | xmlSchemaParserCtxt * |
12214 | | xmlSchemaNewDocParserCtxt(xmlDoc *doc) |
12215 | 0 | { |
12216 | 0 | xmlSchemaParserCtxtPtr ret; |
12217 | |
|
12218 | 0 | if (doc == NULL) |
12219 | 0 | return (NULL); |
12220 | 0 | ret = xmlSchemaParserCtxtCreate(); |
12221 | 0 | if (ret == NULL) |
12222 | 0 | return(NULL); |
12223 | 0 | ret->doc = doc; |
12224 | 0 | ret->dict = xmlDictCreate(); |
12225 | | /* The application has responsibility for the document */ |
12226 | 0 | ret->preserve = 1; |
12227 | |
|
12228 | 0 | return (ret); |
12229 | 0 | } |
12230 | | |
12231 | | /** |
12232 | | * Free the resources associated to the schema parser context |
12233 | | * |
12234 | | * @param ctxt the schema parser context |
12235 | | */ |
12236 | | void |
12237 | | xmlSchemaFreeParserCtxt(xmlSchemaParserCtxt *ctxt) |
12238 | 0 | { |
12239 | 0 | if (ctxt == NULL) |
12240 | 0 | return; |
12241 | 0 | if (ctxt->doc != NULL && !ctxt->preserve) |
12242 | 0 | xmlFreeDoc(ctxt->doc); |
12243 | 0 | if (ctxt->vctxt != NULL) { |
12244 | 0 | xmlSchemaFreeValidCtxt(ctxt->vctxt); |
12245 | 0 | } |
12246 | 0 | if (ctxt->ownsConstructor && (ctxt->constructor != NULL)) { |
12247 | 0 | xmlSchemaConstructionCtxtFree(ctxt->constructor); |
12248 | 0 | ctxt->constructor = NULL; |
12249 | 0 | ctxt->ownsConstructor = 0; |
12250 | 0 | } |
12251 | 0 | if (ctxt->attrProhibs != NULL) |
12252 | 0 | xmlSchemaItemListFree(ctxt->attrProhibs); |
12253 | 0 | xmlDictFree(ctxt->dict); |
12254 | 0 | xmlFree(ctxt); |
12255 | 0 | } |
12256 | | |
12257 | | /************************************************************************ |
12258 | | * * |
12259 | | * Building the content models * |
12260 | | * * |
12261 | | ************************************************************************/ |
12262 | | |
12263 | | /** |
12264 | | * @returns 1 if nillable, 0 otherwise |
12265 | | */ |
12266 | | static int |
12267 | | xmlSchemaBuildContentModelForSubstGroup(xmlSchemaParserCtxtPtr pctxt, |
12268 | | xmlSchemaParticlePtr particle, int counter, xmlAutomataStatePtr end) |
12269 | 0 | { |
12270 | 0 | xmlAutomataStatePtr start, tmp; |
12271 | 0 | xmlSchemaElementPtr elemDecl, member; |
12272 | 0 | xmlSchemaSubstGroupPtr substGroup; |
12273 | 0 | int i; |
12274 | 0 | int ret = 0; |
12275 | |
|
12276 | 0 | elemDecl = (xmlSchemaElementPtr) particle->children; |
12277 | | /* |
12278 | | * Wrap the substitution group with a CHOICE. |
12279 | | */ |
12280 | 0 | start = pctxt->state; |
12281 | 0 | if (end == NULL) |
12282 | 0 | end = xmlAutomataNewState(pctxt->am); |
12283 | 0 | substGroup = xmlSchemaSubstGroupGet(pctxt, elemDecl); |
12284 | 0 | if (substGroup == NULL) { |
12285 | 0 | xmlSchemaPErr(pctxt, WXS_ITEM_NODE(particle), |
12286 | 0 | XML_SCHEMAP_INTERNAL, |
12287 | 0 | "Internal error: xmlSchemaBuildContentModelForSubstGroup, " |
12288 | 0 | "declaration is marked having a subst. group but none " |
12289 | 0 | "available.\n", elemDecl->name, NULL); |
12290 | 0 | return(0); |
12291 | 0 | } |
12292 | 0 | if (counter >= 0) { |
12293 | | /* |
12294 | | * NOTE that we put the declaration in, even if it's abstract. |
12295 | | * However, an error will be raised during *validation* if an element |
12296 | | * information item shall be validated against an abstract element |
12297 | | * declaration. |
12298 | | */ |
12299 | 0 | tmp = xmlAutomataNewCountedTrans(pctxt->am, start, NULL, counter); |
12300 | 0 | xmlAutomataNewTransition2(pctxt->am, tmp, end, |
12301 | 0 | elemDecl->name, elemDecl->targetNamespace, elemDecl); |
12302 | | /* |
12303 | | * Add subst. group members. |
12304 | | */ |
12305 | 0 | for (i = 0; i < substGroup->members->nbItems; i++) { |
12306 | 0 | member = (xmlSchemaElementPtr) substGroup->members->items[i]; |
12307 | 0 | xmlAutomataNewTransition2(pctxt->am, tmp, end, |
12308 | 0 | member->name, member->targetNamespace, member); |
12309 | 0 | } |
12310 | 0 | } else if (particle->maxOccurs == 1) { |
12311 | | /* |
12312 | | * NOTE that we put the declaration in, even if it's abstract, |
12313 | | */ |
12314 | 0 | xmlAutomataNewEpsilon(pctxt->am, |
12315 | 0 | xmlAutomataNewTransition2(pctxt->am, |
12316 | 0 | start, NULL, |
12317 | 0 | elemDecl->name, elemDecl->targetNamespace, elemDecl), end); |
12318 | | /* |
12319 | | * Add subst. group members. |
12320 | | */ |
12321 | 0 | for (i = 0; i < substGroup->members->nbItems; i++) { |
12322 | 0 | member = (xmlSchemaElementPtr) substGroup->members->items[i]; |
12323 | | /* |
12324 | | * NOTE: This fixes bug #341150. xmlAutomataNewOnceTrans2() |
12325 | | * was incorrectly used instead of xmlAutomataNewTransition2() |
12326 | | * (seems like a copy&paste bug from the XML_SCHEMA_TYPE_ALL |
12327 | | * section in xmlSchemaBuildAContentModel() ). |
12328 | | * TODO: Check if xmlAutomataNewOnceTrans2() was instead |
12329 | | * intended for the above "counter" section originally. I.e., |
12330 | | * check xs:all with subst-groups. |
12331 | | * |
12332 | | * tmp = xmlAutomataNewOnceTrans2(pctxt->am, start, NULL, |
12333 | | * member->name, member->targetNamespace, |
12334 | | * 1, 1, member); |
12335 | | */ |
12336 | 0 | tmp = xmlAutomataNewTransition2(pctxt->am, start, NULL, |
12337 | 0 | member->name, member->targetNamespace, member); |
12338 | 0 | xmlAutomataNewEpsilon(pctxt->am, tmp, end); |
12339 | 0 | } |
12340 | 0 | } else { |
12341 | 0 | xmlAutomataStatePtr hop; |
12342 | 0 | int maxOccurs = particle->maxOccurs == UNBOUNDED ? |
12343 | 0 | UNBOUNDED : particle->maxOccurs - 1; |
12344 | 0 | int minOccurs = particle->minOccurs < 1 ? 0 : particle->minOccurs - 1; |
12345 | |
|
12346 | 0 | counter = |
12347 | 0 | xmlAutomataNewCounter(pctxt->am, minOccurs, |
12348 | 0 | maxOccurs); |
12349 | 0 | hop = xmlAutomataNewState(pctxt->am); |
12350 | |
|
12351 | 0 | xmlAutomataNewEpsilon(pctxt->am, |
12352 | 0 | xmlAutomataNewTransition2(pctxt->am, |
12353 | 0 | start, NULL, |
12354 | 0 | elemDecl->name, elemDecl->targetNamespace, elemDecl), |
12355 | 0 | hop); |
12356 | | /* |
12357 | | * Add subst. group members. |
12358 | | */ |
12359 | 0 | for (i = 0; i < substGroup->members->nbItems; i++) { |
12360 | 0 | member = (xmlSchemaElementPtr) substGroup->members->items[i]; |
12361 | 0 | xmlAutomataNewEpsilon(pctxt->am, |
12362 | 0 | xmlAutomataNewTransition2(pctxt->am, |
12363 | 0 | start, NULL, |
12364 | 0 | member->name, member->targetNamespace, member), |
12365 | 0 | hop); |
12366 | 0 | } |
12367 | 0 | xmlAutomataNewCountedTrans(pctxt->am, hop, start, counter); |
12368 | 0 | xmlAutomataNewCounterTrans(pctxt->am, hop, end, counter); |
12369 | 0 | } |
12370 | 0 | if (particle->minOccurs == 0) { |
12371 | 0 | xmlAutomataNewEpsilon(pctxt->am, start, end); |
12372 | 0 | ret = 1; |
12373 | 0 | } |
12374 | 0 | pctxt->state = end; |
12375 | 0 | return(ret); |
12376 | 0 | } |
12377 | | |
12378 | | /** |
12379 | | * @returns 1 if nillable, 0 otherwise |
12380 | | */ |
12381 | | static int |
12382 | | xmlSchemaBuildContentModelForElement(xmlSchemaParserCtxtPtr ctxt, |
12383 | | xmlSchemaParticlePtr particle) |
12384 | 0 | { |
12385 | 0 | int ret = 0; |
12386 | |
|
12387 | 0 | if (((xmlSchemaElementPtr) particle->children)->flags & |
12388 | 0 | XML_SCHEMAS_ELEM_SUBST_GROUP_HEAD) { |
12389 | | /* |
12390 | | * Substitution groups. |
12391 | | */ |
12392 | 0 | ret = xmlSchemaBuildContentModelForSubstGroup(ctxt, particle, -1, NULL); |
12393 | 0 | } else { |
12394 | 0 | xmlSchemaElementPtr elemDecl; |
12395 | 0 | xmlAutomataStatePtr start; |
12396 | |
|
12397 | 0 | elemDecl = (xmlSchemaElementPtr) particle->children; |
12398 | |
|
12399 | 0 | if (elemDecl->flags & XML_SCHEMAS_ELEM_ABSTRACT) |
12400 | 0 | return(0); |
12401 | 0 | if (particle->maxOccurs == 1) { |
12402 | 0 | start = ctxt->state; |
12403 | 0 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, start, NULL, |
12404 | 0 | elemDecl->name, elemDecl->targetNamespace, elemDecl); |
12405 | 0 | } else if ((particle->maxOccurs >= UNBOUNDED) && |
12406 | 0 | (particle->minOccurs < 2)) { |
12407 | | /* Special case. */ |
12408 | 0 | start = ctxt->state; |
12409 | 0 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, start, NULL, |
12410 | 0 | elemDecl->name, elemDecl->targetNamespace, elemDecl); |
12411 | 0 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, ctxt->state, ctxt->state, |
12412 | 0 | elemDecl->name, elemDecl->targetNamespace, elemDecl); |
12413 | 0 | } else { |
12414 | 0 | int counter; |
12415 | 0 | int maxOccurs = particle->maxOccurs == UNBOUNDED ? |
12416 | 0 | UNBOUNDED : particle->maxOccurs - 1; |
12417 | 0 | int minOccurs = particle->minOccurs < 1 ? |
12418 | 0 | 0 : particle->minOccurs - 1; |
12419 | |
|
12420 | 0 | start = xmlAutomataNewEpsilon(ctxt->am, ctxt->state, NULL); |
12421 | 0 | counter = xmlAutomataNewCounter(ctxt->am, minOccurs, maxOccurs); |
12422 | 0 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, start, NULL, |
12423 | 0 | elemDecl->name, elemDecl->targetNamespace, elemDecl); |
12424 | 0 | xmlAutomataNewCountedTrans(ctxt->am, ctxt->state, start, counter); |
12425 | 0 | ctxt->state = xmlAutomataNewCounterTrans(ctxt->am, ctxt->state, |
12426 | 0 | NULL, counter); |
12427 | 0 | } |
12428 | 0 | if (particle->minOccurs == 0) { |
12429 | 0 | xmlAutomataNewEpsilon(ctxt->am, start, ctxt->state); |
12430 | 0 | ret = 1; |
12431 | 0 | } |
12432 | 0 | } |
12433 | 0 | return(ret); |
12434 | 0 | } |
12435 | | |
12436 | | /** |
12437 | | * Create the automaton for the {content type} of a complex type. |
12438 | | * |
12439 | | * @param pctxt the schema parser context |
12440 | | * @param particle the particle component |
12441 | | * @returns 1 if the content is nillable, 0 otherwise |
12442 | | */ |
12443 | | static int |
12444 | | xmlSchemaBuildAContentModel(xmlSchemaParserCtxtPtr pctxt, |
12445 | | xmlSchemaParticlePtr particle) |
12446 | 0 | { |
12447 | 0 | int ret = 0, tmp2; |
12448 | |
|
12449 | 0 | if (particle == NULL) { |
12450 | 0 | PERROR_INT("xmlSchemaBuildAContentModel", "particle is NULL"); |
12451 | 0 | return(1); |
12452 | 0 | } |
12453 | 0 | if (particle->children == NULL) { |
12454 | | /* |
12455 | | * Just return in this case. A missing "term" of the particle |
12456 | | * might arise due to an invalid "term" component. |
12457 | | */ |
12458 | 0 | return(1); |
12459 | 0 | } |
12460 | | |
12461 | 0 | switch (particle->children->type) { |
12462 | 0 | case XML_SCHEMA_TYPE_ANY: { |
12463 | 0 | xmlAutomataStatePtr start, end; |
12464 | 0 | xmlSchemaWildcardPtr wild; |
12465 | 0 | xmlSchemaWildcardNsPtr ns; |
12466 | |
|
12467 | 0 | wild = (xmlSchemaWildcardPtr) particle->children; |
12468 | |
|
12469 | 0 | start = pctxt->state; |
12470 | 0 | end = xmlAutomataNewState(pctxt->am); |
12471 | |
|
12472 | 0 | if (particle->maxOccurs == 1) { |
12473 | 0 | if (wild->any == 1) { |
12474 | | /* |
12475 | | * We need to add both transitions: |
12476 | | * |
12477 | | * 1. the {"*", "*"} for elements in a namespace. |
12478 | | */ |
12479 | 0 | pctxt->state = |
12480 | 0 | xmlAutomataNewTransition2(pctxt->am, |
12481 | 0 | start, NULL, BAD_CAST "*", BAD_CAST "*", wild); |
12482 | 0 | xmlAutomataNewEpsilon(pctxt->am, pctxt->state, end); |
12483 | | /* |
12484 | | * 2. the {"*"} for elements in no namespace. |
12485 | | */ |
12486 | 0 | pctxt->state = |
12487 | 0 | xmlAutomataNewTransition2(pctxt->am, |
12488 | 0 | start, NULL, BAD_CAST "*", NULL, wild); |
12489 | 0 | xmlAutomataNewEpsilon(pctxt->am, pctxt->state, end); |
12490 | |
|
12491 | 0 | } else if (wild->nsSet != NULL) { |
12492 | 0 | ns = wild->nsSet; |
12493 | 0 | do { |
12494 | 0 | pctxt->state = start; |
12495 | 0 | pctxt->state = xmlAutomataNewTransition2(pctxt->am, |
12496 | 0 | pctxt->state, NULL, BAD_CAST "*", ns->value, wild); |
12497 | 0 | xmlAutomataNewEpsilon(pctxt->am, pctxt->state, end); |
12498 | 0 | ns = ns->next; |
12499 | 0 | } while (ns != NULL); |
12500 | |
|
12501 | 0 | } else if (wild->negNsSet != NULL) { |
12502 | 0 | pctxt->state = xmlAutomataNewNegTrans(pctxt->am, |
12503 | 0 | start, end, BAD_CAST "*", wild->negNsSet->value, |
12504 | 0 | wild); |
12505 | 0 | } |
12506 | 0 | } else { |
12507 | 0 | int counter; |
12508 | 0 | xmlAutomataStatePtr hop; |
12509 | 0 | int maxOccurs = |
12510 | 0 | particle->maxOccurs == UNBOUNDED ? UNBOUNDED : |
12511 | 0 | particle->maxOccurs - 1; |
12512 | 0 | int minOccurs = |
12513 | 0 | particle->minOccurs < 1 ? 0 : particle->minOccurs - 1; |
12514 | |
|
12515 | 0 | counter = xmlAutomataNewCounter(pctxt->am, minOccurs, maxOccurs); |
12516 | 0 | hop = xmlAutomataNewState(pctxt->am); |
12517 | 0 | if (wild->any == 1) { |
12518 | 0 | pctxt->state = |
12519 | 0 | xmlAutomataNewTransition2(pctxt->am, |
12520 | 0 | start, NULL, BAD_CAST "*", BAD_CAST "*", wild); |
12521 | 0 | xmlAutomataNewEpsilon(pctxt->am, pctxt->state, hop); |
12522 | 0 | pctxt->state = |
12523 | 0 | xmlAutomataNewTransition2(pctxt->am, |
12524 | 0 | start, NULL, BAD_CAST "*", NULL, wild); |
12525 | 0 | xmlAutomataNewEpsilon(pctxt->am, pctxt->state, hop); |
12526 | 0 | } else if (wild->nsSet != NULL) { |
12527 | 0 | ns = wild->nsSet; |
12528 | 0 | do { |
12529 | 0 | pctxt->state = |
12530 | 0 | xmlAutomataNewTransition2(pctxt->am, |
12531 | 0 | start, NULL, BAD_CAST "*", ns->value, wild); |
12532 | 0 | xmlAutomataNewEpsilon(pctxt->am, pctxt->state, hop); |
12533 | 0 | ns = ns->next; |
12534 | 0 | } while (ns != NULL); |
12535 | |
|
12536 | 0 | } else if (wild->negNsSet != NULL) { |
12537 | 0 | pctxt->state = xmlAutomataNewNegTrans(pctxt->am, |
12538 | 0 | start, hop, BAD_CAST "*", wild->negNsSet->value, |
12539 | 0 | wild); |
12540 | 0 | } |
12541 | 0 | xmlAutomataNewCountedTrans(pctxt->am, hop, start, counter); |
12542 | 0 | xmlAutomataNewCounterTrans(pctxt->am, hop, end, counter); |
12543 | 0 | } |
12544 | 0 | if (particle->minOccurs == 0) { |
12545 | 0 | xmlAutomataNewEpsilon(pctxt->am, start, end); |
12546 | 0 | ret = 1; |
12547 | 0 | } |
12548 | 0 | pctxt->state = end; |
12549 | 0 | break; |
12550 | 0 | } |
12551 | 0 | case XML_SCHEMA_TYPE_ELEMENT: |
12552 | 0 | ret = xmlSchemaBuildContentModelForElement(pctxt, particle); |
12553 | 0 | break; |
12554 | 0 | case XML_SCHEMA_TYPE_SEQUENCE:{ |
12555 | 0 | xmlSchemaTreeItemPtr sub; |
12556 | |
|
12557 | 0 | ret = 1; |
12558 | | /* |
12559 | | * If max and min occurrences are default (1) then |
12560 | | * simply iterate over the particles of the <sequence>. |
12561 | | */ |
12562 | 0 | if ((particle->minOccurs == 1) && (particle->maxOccurs == 1)) { |
12563 | 0 | sub = particle->children->children; |
12564 | |
|
12565 | 0 | while (sub != NULL) { |
12566 | 0 | tmp2 = xmlSchemaBuildAContentModel(pctxt, |
12567 | 0 | (xmlSchemaParticlePtr) sub); |
12568 | 0 | if (tmp2 != 1) ret = 0; |
12569 | 0 | sub = sub->next; |
12570 | 0 | } |
12571 | 0 | } else { |
12572 | 0 | xmlAutomataStatePtr oldstate = pctxt->state; |
12573 | |
|
12574 | 0 | if (particle->maxOccurs >= UNBOUNDED) { |
12575 | 0 | if (particle->minOccurs > 1) { |
12576 | 0 | xmlAutomataStatePtr tmp; |
12577 | 0 | int counter; |
12578 | |
|
12579 | 0 | pctxt->state = xmlAutomataNewEpsilon(pctxt->am, |
12580 | 0 | oldstate, NULL); |
12581 | 0 | oldstate = pctxt->state; |
12582 | |
|
12583 | 0 | counter = xmlAutomataNewCounter(pctxt->am, |
12584 | 0 | particle->minOccurs - 1, UNBOUNDED); |
12585 | |
|
12586 | 0 | sub = particle->children->children; |
12587 | 0 | while (sub != NULL) { |
12588 | 0 | tmp2 = xmlSchemaBuildAContentModel(pctxt, |
12589 | 0 | (xmlSchemaParticlePtr) sub); |
12590 | 0 | if (tmp2 != 1) ret = 0; |
12591 | 0 | sub = sub->next; |
12592 | 0 | } |
12593 | 0 | tmp = pctxt->state; |
12594 | 0 | xmlAutomataNewCountedTrans(pctxt->am, tmp, |
12595 | 0 | oldstate, counter); |
12596 | 0 | pctxt->state = |
12597 | 0 | xmlAutomataNewCounterTrans(pctxt->am, tmp, |
12598 | 0 | NULL, counter); |
12599 | 0 | if (ret == 1) |
12600 | 0 | xmlAutomataNewEpsilon(pctxt->am, |
12601 | 0 | oldstate, pctxt->state); |
12602 | |
|
12603 | 0 | } else { |
12604 | 0 | pctxt->state = xmlAutomataNewEpsilon(pctxt->am, |
12605 | 0 | oldstate, NULL); |
12606 | 0 | oldstate = pctxt->state; |
12607 | |
|
12608 | 0 | sub = particle->children->children; |
12609 | 0 | while (sub != NULL) { |
12610 | 0 | tmp2 = xmlSchemaBuildAContentModel(pctxt, |
12611 | 0 | (xmlSchemaParticlePtr) sub); |
12612 | 0 | if (tmp2 != 1) ret = 0; |
12613 | 0 | sub = sub->next; |
12614 | 0 | } |
12615 | 0 | xmlAutomataNewEpsilon(pctxt->am, pctxt->state, |
12616 | 0 | oldstate); |
12617 | | /* |
12618 | | * epsilon needed to block previous trans from |
12619 | | * being allowed to enter back from another |
12620 | | * construct |
12621 | | */ |
12622 | 0 | pctxt->state = xmlAutomataNewEpsilon(pctxt->am, |
12623 | 0 | pctxt->state, NULL); |
12624 | 0 | if (particle->minOccurs == 0) { |
12625 | 0 | xmlAutomataNewEpsilon(pctxt->am, |
12626 | 0 | oldstate, pctxt->state); |
12627 | 0 | ret = 1; |
12628 | 0 | } |
12629 | 0 | } |
12630 | 0 | } else if ((particle->maxOccurs > 1) |
12631 | 0 | || (particle->minOccurs > 1)) { |
12632 | 0 | xmlAutomataStatePtr tmp; |
12633 | 0 | int counter; |
12634 | |
|
12635 | 0 | pctxt->state = xmlAutomataNewEpsilon(pctxt->am, |
12636 | 0 | oldstate, NULL); |
12637 | 0 | oldstate = pctxt->state; |
12638 | |
|
12639 | 0 | counter = xmlAutomataNewCounter(pctxt->am, |
12640 | 0 | particle->minOccurs - 1, |
12641 | 0 | particle->maxOccurs - 1); |
12642 | |
|
12643 | 0 | sub = particle->children->children; |
12644 | 0 | while (sub != NULL) { |
12645 | 0 | tmp2 = xmlSchemaBuildAContentModel(pctxt, |
12646 | 0 | (xmlSchemaParticlePtr) sub); |
12647 | 0 | if (tmp2 != 1) ret = 0; |
12648 | 0 | sub = sub->next; |
12649 | 0 | } |
12650 | 0 | tmp = pctxt->state; |
12651 | 0 | xmlAutomataNewCountedTrans(pctxt->am, |
12652 | 0 | tmp, oldstate, counter); |
12653 | 0 | pctxt->state = |
12654 | 0 | xmlAutomataNewCounterTrans(pctxt->am, tmp, NULL, |
12655 | 0 | counter); |
12656 | 0 | if ((particle->minOccurs == 0) || (ret == 1)) { |
12657 | 0 | xmlAutomataNewEpsilon(pctxt->am, |
12658 | 0 | oldstate, pctxt->state); |
12659 | 0 | ret = 1; |
12660 | 0 | } |
12661 | 0 | } else { |
12662 | 0 | sub = particle->children->children; |
12663 | 0 | while (sub != NULL) { |
12664 | 0 | tmp2 = xmlSchemaBuildAContentModel(pctxt, |
12665 | 0 | (xmlSchemaParticlePtr) sub); |
12666 | 0 | if (tmp2 != 1) ret = 0; |
12667 | 0 | sub = sub->next; |
12668 | 0 | } |
12669 | | |
12670 | | /* |
12671 | | * epsilon needed to block previous trans from |
12672 | | * being allowed to enter back from another |
12673 | | * construct |
12674 | | */ |
12675 | 0 | pctxt->state = xmlAutomataNewEpsilon(pctxt->am, |
12676 | 0 | pctxt->state, NULL); |
12677 | |
|
12678 | 0 | if (particle->minOccurs == 0) { |
12679 | 0 | xmlAutomataNewEpsilon(pctxt->am, oldstate, |
12680 | 0 | pctxt->state); |
12681 | 0 | ret = 1; |
12682 | 0 | } |
12683 | 0 | } |
12684 | 0 | } |
12685 | 0 | break; |
12686 | 0 | } |
12687 | 0 | case XML_SCHEMA_TYPE_CHOICE:{ |
12688 | 0 | xmlSchemaTreeItemPtr sub; |
12689 | 0 | xmlAutomataStatePtr start, end; |
12690 | |
|
12691 | 0 | ret = 0; |
12692 | 0 | start = pctxt->state; |
12693 | 0 | end = xmlAutomataNewState(pctxt->am); |
12694 | | |
12695 | | /* |
12696 | | * iterate over the subtypes and remerge the end with an |
12697 | | * epsilon transition |
12698 | | */ |
12699 | 0 | if (particle->maxOccurs == 1) { |
12700 | 0 | sub = particle->children->children; |
12701 | 0 | while (sub != NULL) { |
12702 | 0 | pctxt->state = start; |
12703 | 0 | tmp2 = xmlSchemaBuildAContentModel(pctxt, |
12704 | 0 | (xmlSchemaParticlePtr) sub); |
12705 | 0 | if (tmp2 == 1) ret = 1; |
12706 | 0 | xmlAutomataNewEpsilon(pctxt->am, pctxt->state, end); |
12707 | 0 | sub = sub->next; |
12708 | 0 | } |
12709 | 0 | } else { |
12710 | 0 | int counter; |
12711 | 0 | xmlAutomataStatePtr hop, base; |
12712 | 0 | int maxOccurs = particle->maxOccurs == UNBOUNDED ? |
12713 | 0 | UNBOUNDED : particle->maxOccurs - 1; |
12714 | 0 | int minOccurs = |
12715 | 0 | particle->minOccurs < 1 ? 0 : particle->minOccurs - 1; |
12716 | | |
12717 | | /* |
12718 | | * use a counter to keep track of the number of transitions |
12719 | | * which went through the choice. |
12720 | | */ |
12721 | 0 | counter = |
12722 | 0 | xmlAutomataNewCounter(pctxt->am, minOccurs, maxOccurs); |
12723 | 0 | hop = xmlAutomataNewState(pctxt->am); |
12724 | 0 | base = xmlAutomataNewState(pctxt->am); |
12725 | |
|
12726 | 0 | sub = particle->children->children; |
12727 | 0 | while (sub != NULL) { |
12728 | 0 | pctxt->state = base; |
12729 | 0 | tmp2 = xmlSchemaBuildAContentModel(pctxt, |
12730 | 0 | (xmlSchemaParticlePtr) sub); |
12731 | 0 | if (tmp2 == 1) ret = 1; |
12732 | 0 | xmlAutomataNewEpsilon(pctxt->am, pctxt->state, hop); |
12733 | 0 | sub = sub->next; |
12734 | 0 | } |
12735 | 0 | xmlAutomataNewEpsilon(pctxt->am, start, base); |
12736 | 0 | xmlAutomataNewCountedTrans(pctxt->am, hop, base, counter); |
12737 | 0 | xmlAutomataNewCounterTrans(pctxt->am, hop, end, counter); |
12738 | 0 | if (ret == 1) |
12739 | 0 | xmlAutomataNewEpsilon(pctxt->am, base, end); |
12740 | 0 | } |
12741 | 0 | if (particle->minOccurs == 0) { |
12742 | 0 | xmlAutomataNewEpsilon(pctxt->am, start, end); |
12743 | 0 | ret = 1; |
12744 | 0 | } |
12745 | 0 | pctxt->state = end; |
12746 | 0 | break; |
12747 | 0 | } |
12748 | 0 | case XML_SCHEMA_TYPE_ALL:{ |
12749 | 0 | xmlAutomataStatePtr start, tmp; |
12750 | 0 | xmlSchemaParticlePtr sub; |
12751 | 0 | xmlSchemaElementPtr elemDecl; |
12752 | |
|
12753 | 0 | ret = 1; |
12754 | |
|
12755 | 0 | sub = (xmlSchemaParticlePtr) particle->children->children; |
12756 | 0 | if (sub == NULL) |
12757 | 0 | break; |
12758 | | |
12759 | 0 | ret = 0; |
12760 | |
|
12761 | 0 | start = pctxt->state; |
12762 | 0 | tmp = xmlAutomataNewState(pctxt->am); |
12763 | 0 | xmlAutomataNewEpsilon(pctxt->am, pctxt->state, tmp); |
12764 | 0 | pctxt->state = tmp; |
12765 | 0 | while (sub != NULL) { |
12766 | 0 | pctxt->state = tmp; |
12767 | |
|
12768 | 0 | elemDecl = (xmlSchemaElementPtr) sub->children; |
12769 | 0 | if (elemDecl == NULL) { |
12770 | 0 | PERROR_INT("xmlSchemaBuildAContentModel", |
12771 | 0 | "<element> particle has no term"); |
12772 | 0 | return(ret); |
12773 | 0 | }; |
12774 | | /* |
12775 | | * NOTE: The {max occurs} of all the particles in the |
12776 | | * {particles} of the group must be 0 or 1; this is |
12777 | | * already ensured during the parse of the content of |
12778 | | * <all>. |
12779 | | */ |
12780 | 0 | if (elemDecl->flags & XML_SCHEMAS_ELEM_SUBST_GROUP_HEAD) { |
12781 | 0 | int counter; |
12782 | | |
12783 | | /* |
12784 | | * This is an abstract group, we need to share |
12785 | | * the same counter for all the element transitions |
12786 | | * derived from the group |
12787 | | */ |
12788 | 0 | counter = xmlAutomataNewCounter(pctxt->am, |
12789 | 0 | sub->minOccurs, sub->maxOccurs); |
12790 | 0 | xmlSchemaBuildContentModelForSubstGroup(pctxt, |
12791 | 0 | sub, counter, pctxt->state); |
12792 | 0 | } else { |
12793 | 0 | if ((sub->minOccurs == 1) && |
12794 | 0 | (sub->maxOccurs == 1)) { |
12795 | 0 | xmlAutomataNewOnceTrans2(pctxt->am, pctxt->state, |
12796 | 0 | pctxt->state, |
12797 | 0 | elemDecl->name, |
12798 | 0 | elemDecl->targetNamespace, |
12799 | 0 | 1, 1, elemDecl); |
12800 | 0 | } else if ((sub->minOccurs == 0) && |
12801 | 0 | (sub->maxOccurs == 1)) { |
12802 | |
|
12803 | 0 | xmlAutomataNewCountTrans2(pctxt->am, pctxt->state, |
12804 | 0 | pctxt->state, |
12805 | 0 | elemDecl->name, |
12806 | 0 | elemDecl->targetNamespace, |
12807 | 0 | 0, |
12808 | 0 | 1, |
12809 | 0 | elemDecl); |
12810 | 0 | } |
12811 | 0 | } |
12812 | 0 | sub = (xmlSchemaParticlePtr) sub->next; |
12813 | 0 | } |
12814 | 0 | pctxt->state = |
12815 | 0 | xmlAutomataNewAllTrans(pctxt->am, pctxt->state, NULL, 0); |
12816 | 0 | if (particle->minOccurs == 0) { |
12817 | 0 | xmlAutomataNewEpsilon(pctxt->am, start, pctxt->state); |
12818 | 0 | ret = 1; |
12819 | 0 | } |
12820 | 0 | break; |
12821 | 0 | } |
12822 | 0 | case XML_SCHEMA_TYPE_GROUP: |
12823 | | /* |
12824 | | * If we hit a model group definition, then this means that |
12825 | | * it was empty, thus was not substituted for the containing |
12826 | | * model group. Just do nothing in this case. |
12827 | | * TODO: But the group should be substituted and not occur at |
12828 | | * all in the content model at this point. Fix this. |
12829 | | */ |
12830 | 0 | ret = 1; |
12831 | 0 | break; |
12832 | 0 | default: |
12833 | 0 | xmlSchemaInternalErr2(ACTXT_CAST pctxt, |
12834 | 0 | "xmlSchemaBuildAContentModel", |
12835 | 0 | "found unexpected term of type '%s' in content model", |
12836 | 0 | WXS_ITEM_TYPE_NAME(particle->children), NULL); |
12837 | 0 | return(ret); |
12838 | 0 | } |
12839 | 0 | return(ret); |
12840 | 0 | } |
12841 | | |
12842 | | /** |
12843 | | * Builds the content model of the complex type. |
12844 | | * |
12845 | | * @param type the complex type definition |
12846 | | * @param ctxt the schema parser context |
12847 | | */ |
12848 | | static void |
12849 | | xmlSchemaBuildContentModel(xmlSchemaTypePtr type, |
12850 | | xmlSchemaParserCtxtPtr ctxt) |
12851 | 0 | { |
12852 | 0 | if ((type->type != XML_SCHEMA_TYPE_COMPLEX) || |
12853 | 0 | (type->contModel != NULL) || |
12854 | 0 | ((type->contentType != XML_SCHEMA_CONTENT_ELEMENTS) && |
12855 | 0 | (type->contentType != XML_SCHEMA_CONTENT_MIXED))) |
12856 | 0 | return; |
12857 | | |
12858 | 0 | ctxt->am = NULL; |
12859 | 0 | ctxt->am = xmlNewAutomata(); |
12860 | 0 | if (ctxt->am == NULL) { |
12861 | 0 | xmlSchemaPErrMemory(ctxt); |
12862 | 0 | return; |
12863 | 0 | } |
12864 | 0 | ctxt->state = xmlAutomataGetInitState(ctxt->am); |
12865 | | /* |
12866 | | * Build the automaton. |
12867 | | */ |
12868 | 0 | xmlSchemaBuildAContentModel(ctxt, WXS_TYPE_PARTICLE(type)); |
12869 | 0 | xmlAutomataSetFinalState(ctxt->am, ctxt->state); |
12870 | 0 | type->contModel = xmlAutomataCompile(ctxt->am); |
12871 | 0 | if (type->contModel == NULL) { |
12872 | 0 | xmlSchemaPCustomErr(ctxt, |
12873 | 0 | XML_SCHEMAP_INTERNAL, |
12874 | 0 | WXS_BASIC_CAST type, type->node, |
12875 | 0 | "Failed to compile the content model", NULL); |
12876 | 0 | } else if (xmlRegexpIsDeterminist(type->contModel) != 1) { |
12877 | 0 | xmlSchemaPCustomErr(ctxt, |
12878 | 0 | XML_SCHEMAP_NOT_DETERMINISTIC, |
12879 | | /* XML_SCHEMAS_ERR_NOTDETERMINIST, */ |
12880 | 0 | WXS_BASIC_CAST type, type->node, |
12881 | 0 | "The content model is not determinist", NULL); |
12882 | 0 | } else { |
12883 | 0 | } |
12884 | 0 | ctxt->state = NULL; |
12885 | 0 | xmlFreeAutomata(ctxt->am); |
12886 | 0 | ctxt->am = NULL; |
12887 | 0 | } |
12888 | | |
12889 | | /** |
12890 | | * Resolves the references of an element declaration |
12891 | | * or particle, which has an element declaration as it's |
12892 | | * term. |
12893 | | * |
12894 | | * @param elemDecl the schema element context |
12895 | | * @param ctxt the schema parser context |
12896 | | */ |
12897 | | static void |
12898 | | xmlSchemaResolveElementReferences(xmlSchemaElementPtr elemDecl, |
12899 | | xmlSchemaParserCtxtPtr ctxt) |
12900 | 0 | { |
12901 | 0 | if ((ctxt == NULL) || (elemDecl == NULL) || |
12902 | 0 | ((elemDecl != NULL) && |
12903 | 0 | (elemDecl->flags & XML_SCHEMAS_ELEM_INTERNAL_RESOLVED))) |
12904 | 0 | return; |
12905 | 0 | elemDecl->flags |= XML_SCHEMAS_ELEM_INTERNAL_RESOLVED; |
12906 | |
|
12907 | 0 | if ((elemDecl->subtypes == NULL) && (elemDecl->namedType != NULL)) { |
12908 | 0 | xmlSchemaTypePtr type; |
12909 | | |
12910 | | /* (type definition) ... otherwise the type definition `resolved` |
12911 | | * to by the `actual value` of the type [attribute] ... |
12912 | | */ |
12913 | 0 | type = xmlSchemaGetType(ctxt->schema, elemDecl->namedType, |
12914 | 0 | elemDecl->namedTypeNs); |
12915 | 0 | if (type == NULL) { |
12916 | 0 | xmlSchemaPResCompAttrErr(ctxt, |
12917 | 0 | XML_SCHEMAP_SRC_RESOLVE, |
12918 | 0 | WXS_BASIC_CAST elemDecl, elemDecl->node, |
12919 | 0 | "type", elemDecl->namedType, elemDecl->namedTypeNs, |
12920 | 0 | XML_SCHEMA_TYPE_BASIC, "type definition"); |
12921 | 0 | } else |
12922 | 0 | elemDecl->subtypes = type; |
12923 | 0 | } |
12924 | 0 | if (elemDecl->substGroup != NULL) { |
12925 | 0 | xmlSchemaElementPtr substHead; |
12926 | | |
12927 | | /* |
12928 | | * FIXME TODO: Do we need a new field in _xmlSchemaElement for |
12929 | | * substitutionGroup? |
12930 | | */ |
12931 | 0 | substHead = xmlSchemaGetElem(ctxt->schema, elemDecl->substGroup, |
12932 | 0 | elemDecl->substGroupNs); |
12933 | 0 | if (substHead == NULL) { |
12934 | 0 | xmlSchemaPResCompAttrErr(ctxt, |
12935 | 0 | XML_SCHEMAP_SRC_RESOLVE, |
12936 | 0 | WXS_BASIC_CAST elemDecl, NULL, |
12937 | 0 | "substitutionGroup", elemDecl->substGroup, |
12938 | 0 | elemDecl->substGroupNs, XML_SCHEMA_TYPE_ELEMENT, NULL); |
12939 | 0 | } else { |
12940 | 0 | xmlSchemaResolveElementReferences(substHead, ctxt); |
12941 | | /* |
12942 | | * Set the "substitution group affiliation". |
12943 | | * NOTE that now we use the "refDecl" field for this. |
12944 | | */ |
12945 | 0 | WXS_SUBST_HEAD(elemDecl) = substHead; |
12946 | | /* |
12947 | | * The type definitions is set to: |
12948 | | * SPEC "...the {type definition} of the element |
12949 | | * declaration `resolved` to by the `actual value` |
12950 | | * of the substitutionGroup [attribute], if present" |
12951 | | */ |
12952 | 0 | if (elemDecl->subtypes == NULL) { |
12953 | 0 | if (substHead->subtypes == NULL) { |
12954 | | /* |
12955 | | * This can happen with self-referencing substitution |
12956 | | * groups. The cycle will be detected later, but we have |
12957 | | * to set subtypes to avoid null-pointer dereferences. |
12958 | | */ |
12959 | 0 | elemDecl->subtypes = xmlSchemaGetBuiltInType( |
12960 | 0 | XML_SCHEMAS_ANYTYPE); |
12961 | 0 | } else { |
12962 | 0 | elemDecl->subtypes = substHead->subtypes; |
12963 | 0 | } |
12964 | 0 | } |
12965 | 0 | } |
12966 | 0 | } |
12967 | | /* |
12968 | | * SPEC "The definition of anyType serves as the default type definition |
12969 | | * for element declarations whose XML representation does not specify one." |
12970 | | */ |
12971 | 0 | if ((elemDecl->subtypes == NULL) && |
12972 | 0 | (elemDecl->namedType == NULL) && |
12973 | 0 | (elemDecl->substGroup == NULL)) |
12974 | 0 | elemDecl->subtypes = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE); |
12975 | 0 | } |
12976 | | |
12977 | | /** |
12978 | | * Checks and builds the "member type definitions" property of the union |
12979 | | * simple type. This handles part (1), part (2) is done in |
12980 | | * xmlSchemaFinishMemberTypeDefinitionsProperty |
12981 | | * |
12982 | | * @param ctxt the schema parser context |
12983 | | * @param type the schema simple type definition |
12984 | | * @returns -1 in case of an internal error, 0 otherwise. |
12985 | | */ |
12986 | | static int |
12987 | | xmlSchemaResolveUnionMemberTypes(xmlSchemaParserCtxtPtr ctxt, |
12988 | | xmlSchemaTypePtr type) |
12989 | 0 | { |
12990 | |
|
12991 | 0 | xmlSchemaTypeLinkPtr link, lastLink, newLink; |
12992 | 0 | xmlSchemaTypePtr memberType; |
12993 | | |
12994 | | /* |
12995 | | * SPEC (1) "If the <union> alternative is chosen, then [Definition:] |
12996 | | * define the explicit members as the type definitions `resolved` |
12997 | | * to by the items in the `actual value` of the memberTypes [attribute], |
12998 | | * if any, followed by the type definitions corresponding to the |
12999 | | * <simpleType>s among the [children] of <union>, if any." |
13000 | | */ |
13001 | | /* |
13002 | | * Resolve references. |
13003 | | */ |
13004 | 0 | link = type->memberTypes; |
13005 | 0 | lastLink = NULL; |
13006 | 0 | while (link != NULL) { |
13007 | 0 | const xmlChar *name, *nsName; |
13008 | |
|
13009 | 0 | name = ((xmlSchemaQNameRefPtr) link->type)->name; |
13010 | 0 | nsName = ((xmlSchemaQNameRefPtr) link->type)->targetNamespace; |
13011 | |
|
13012 | 0 | memberType = xmlSchemaGetType(ctxt->schema, name, nsName); |
13013 | 0 | if ((memberType == NULL) || (! WXS_IS_SIMPLE(memberType))) { |
13014 | 0 | xmlSchemaPResCompAttrErr(ctxt, XML_SCHEMAP_SRC_RESOLVE, |
13015 | 0 | WXS_BASIC_CAST type, type->node, "memberTypes", |
13016 | 0 | name, nsName, XML_SCHEMA_TYPE_SIMPLE, NULL); |
13017 | | /* |
13018 | | * Remove the member type link. |
13019 | | */ |
13020 | 0 | if (lastLink == NULL) |
13021 | 0 | type->memberTypes = link->next; |
13022 | 0 | else |
13023 | 0 | lastLink->next = link->next; |
13024 | 0 | newLink = link; |
13025 | 0 | link = link->next; |
13026 | 0 | xmlFree(newLink); |
13027 | 0 | } else { |
13028 | 0 | link->type = memberType; |
13029 | 0 | lastLink = link; |
13030 | 0 | link = link->next; |
13031 | 0 | } |
13032 | 0 | } |
13033 | | /* |
13034 | | * Add local simple types, |
13035 | | */ |
13036 | 0 | memberType = type->subtypes; |
13037 | 0 | while (memberType != NULL) { |
13038 | 0 | link = (xmlSchemaTypeLinkPtr) xmlMalloc(sizeof(xmlSchemaTypeLink)); |
13039 | 0 | if (link == NULL) { |
13040 | 0 | xmlSchemaPErrMemory(ctxt); |
13041 | 0 | return (-1); |
13042 | 0 | } |
13043 | 0 | link->type = memberType; |
13044 | 0 | link->next = NULL; |
13045 | 0 | if (lastLink == NULL) |
13046 | 0 | type->memberTypes = link; |
13047 | 0 | else |
13048 | 0 | lastLink->next = link; |
13049 | 0 | lastLink = link; |
13050 | 0 | memberType = memberType->next; |
13051 | 0 | } |
13052 | 0 | return (0); |
13053 | 0 | } |
13054 | | |
13055 | | /** |
13056 | | * |
13057 | | * @param type the type definition |
13058 | | * @param valType the value type |
13059 | | * @returns 1 if the type has the given value type, or |
13060 | | * is derived from such a type. |
13061 | | */ |
13062 | | static int |
13063 | | xmlSchemaIsDerivedFromBuiltInType(xmlSchemaTypePtr type, int valType) |
13064 | 0 | { |
13065 | 0 | if (type == NULL) |
13066 | 0 | return (0); |
13067 | 0 | if (WXS_IS_COMPLEX(type)) |
13068 | 0 | return (0); |
13069 | 0 | if (type->type == XML_SCHEMA_TYPE_BASIC) { |
13070 | 0 | if (type->builtInType == valType) |
13071 | 0 | return(1); |
13072 | 0 | if ((type->builtInType == XML_SCHEMAS_ANYSIMPLETYPE) || |
13073 | 0 | (type->builtInType == XML_SCHEMAS_ANYTYPE)) |
13074 | 0 | return (0); |
13075 | 0 | return(xmlSchemaIsDerivedFromBuiltInType(type->subtypes, valType)); |
13076 | 0 | } |
13077 | 0 | return(xmlSchemaIsDerivedFromBuiltInType(type->subtypes, valType)); |
13078 | 0 | } |
13079 | | |
13080 | | #if 0 |
13081 | | /** |
13082 | | * |
13083 | | * @param ctxt the schema parser context |
13084 | | * @param type the type definition |
13085 | | * @param valType the value type |
13086 | | * @returns 1 if the type has the given value type, or |
13087 | | * is derived from such a type. |
13088 | | */ |
13089 | | static int |
13090 | | xmlSchemaIsUserDerivedFromBuiltInType(xmlSchemaTypePtr type, int valType) |
13091 | | { |
13092 | | if (type == NULL) |
13093 | | return (0); |
13094 | | if (WXS_IS_COMPLEX(type)) |
13095 | | return (0); |
13096 | | if (type->type == XML_SCHEMA_TYPE_BASIC) { |
13097 | | if (type->builtInType == valType) |
13098 | | return(1); |
13099 | | return (0); |
13100 | | } else |
13101 | | return(xmlSchemaIsDerivedFromBuiltInType(type->subtypes, valType)); |
13102 | | |
13103 | | return (0); |
13104 | | } |
13105 | | |
13106 | | static xmlSchemaTypePtr |
13107 | | xmlSchemaQueryBuiltInType(xmlSchemaTypePtr type) |
13108 | | { |
13109 | | if (type == NULL) |
13110 | | return (NULL); |
13111 | | if (WXS_IS_COMPLEX(type)) |
13112 | | return (NULL); |
13113 | | if (type->type == XML_SCHEMA_TYPE_BASIC) |
13114 | | return(type); |
13115 | | return(xmlSchemaQueryBuiltInType(type->subtypes)); |
13116 | | } |
13117 | | #endif |
13118 | | |
13119 | | /** |
13120 | | * @param type the simpleType definition |
13121 | | * @returns the primitive type of the given type or |
13122 | | * NULL in case of error. |
13123 | | */ |
13124 | | static xmlSchemaTypePtr |
13125 | | xmlSchemaGetPrimitiveType(xmlSchemaTypePtr type) |
13126 | 0 | { |
13127 | |
|
13128 | 0 | while (type != NULL) { |
13129 | | /* |
13130 | | * Note that anySimpleType is actually not a primitive type |
13131 | | * but we need that here. |
13132 | | */ |
13133 | 0 | if ((type->builtInType == XML_SCHEMAS_ANYSIMPLETYPE) || |
13134 | 0 | (type->flags & XML_SCHEMAS_TYPE_BUILTIN_PRIMITIVE)) |
13135 | 0 | return (type); |
13136 | 0 | type = type->baseType; |
13137 | 0 | } |
13138 | | |
13139 | 0 | return (NULL); |
13140 | 0 | } |
13141 | | |
13142 | | #if 0 |
13143 | | /** |
13144 | | * @param type the simpleType definition |
13145 | | * @returns the primitive type of the given type or |
13146 | | * NULL in case of error. |
13147 | | */ |
13148 | | static xmlSchemaTypePtr |
13149 | | xmlSchemaGetBuiltInTypeAncestor(xmlSchemaTypePtr type) |
13150 | | { |
13151 | | if (WXS_IS_LIST(type) || WXS_IS_UNION(type)) |
13152 | | return (0); |
13153 | | while (type != NULL) { |
13154 | | if (type->type == XML_SCHEMA_TYPE_BASIC) |
13155 | | return (type); |
13156 | | type = type->baseType; |
13157 | | } |
13158 | | |
13159 | | return (NULL); |
13160 | | } |
13161 | | #endif |
13162 | | |
13163 | | /** |
13164 | | * Clones the namespace constraints of source |
13165 | | * and assigns them to dest. |
13166 | | * |
13167 | | * @param ctxt the schema parser context |
13168 | | * @param dest the destination wildcard |
13169 | | * @param source the source wildcard |
13170 | | * @returns -1 on internal error, 0 otherwise. |
13171 | | */ |
13172 | | static int |
13173 | | xmlSchemaCloneWildcardNsConstraints(xmlSchemaParserCtxtPtr ctxt, |
13174 | | xmlSchemaWildcardPtr dest, |
13175 | | xmlSchemaWildcardPtr source) |
13176 | 0 | { |
13177 | 0 | xmlSchemaWildcardNsPtr cur, tmp, last; |
13178 | |
|
13179 | 0 | if ((source == NULL) || (dest == NULL)) |
13180 | 0 | return(-1); |
13181 | 0 | dest->any = source->any; |
13182 | 0 | cur = source->nsSet; |
13183 | 0 | last = NULL; |
13184 | 0 | while (cur != NULL) { |
13185 | 0 | tmp = xmlSchemaNewWildcardNsConstraint(ctxt); |
13186 | 0 | if (tmp == NULL) |
13187 | 0 | return(-1); |
13188 | 0 | tmp->value = cur->value; |
13189 | 0 | if (last == NULL) |
13190 | 0 | dest->nsSet = tmp; |
13191 | 0 | else |
13192 | 0 | last->next = tmp; |
13193 | 0 | last = tmp; |
13194 | 0 | cur = cur->next; |
13195 | 0 | } |
13196 | 0 | if (dest->negNsSet != NULL) |
13197 | 0 | xmlSchemaFreeWildcardNsSet(dest->negNsSet); |
13198 | 0 | if (source->negNsSet != NULL) { |
13199 | 0 | dest->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt); |
13200 | 0 | if (dest->negNsSet == NULL) |
13201 | 0 | return(-1); |
13202 | 0 | dest->negNsSet->value = source->negNsSet->value; |
13203 | 0 | } else |
13204 | 0 | dest->negNsSet = NULL; |
13205 | 0 | return(0); |
13206 | 0 | } |
13207 | | |
13208 | | /** |
13209 | | * Unions the namespace constraints of the given wildcards. |
13210 | | * `completeWild` will hold the resulting union. |
13211 | | * |
13212 | | * @param ctxt the schema parser context |
13213 | | * @param completeWild the first wildcard |
13214 | | * @param curWild the second wildcard |
13215 | | * @returns a positive error code on failure, -1 in case of an |
13216 | | * internal error, 0 otherwise. |
13217 | | */ |
13218 | | static int |
13219 | | xmlSchemaUnionWildcards(xmlSchemaParserCtxtPtr ctxt, |
13220 | | xmlSchemaWildcardPtr completeWild, |
13221 | | xmlSchemaWildcardPtr curWild) |
13222 | 0 | { |
13223 | 0 | xmlSchemaWildcardNsPtr cur, curB, tmp; |
13224 | | |
13225 | | /* |
13226 | | * 1 If O1 and O2 are the same value, then that value must be the |
13227 | | * value. |
13228 | | */ |
13229 | 0 | if ((completeWild->any == curWild->any) && |
13230 | 0 | ((completeWild->nsSet == NULL) == (curWild->nsSet == NULL)) && |
13231 | 0 | ((completeWild->negNsSet == NULL) == (curWild->negNsSet == NULL))) { |
13232 | |
|
13233 | 0 | if ((completeWild->negNsSet == NULL) || |
13234 | 0 | (completeWild->negNsSet->value == curWild->negNsSet->value)) { |
13235 | |
|
13236 | 0 | if (completeWild->nsSet != NULL) { |
13237 | 0 | int found = 0; |
13238 | | |
13239 | | /* |
13240 | | * Check equality of sets. |
13241 | | */ |
13242 | 0 | cur = completeWild->nsSet; |
13243 | 0 | while (cur != NULL) { |
13244 | 0 | found = 0; |
13245 | 0 | curB = curWild->nsSet; |
13246 | 0 | while (curB != NULL) { |
13247 | 0 | if (cur->value == curB->value) { |
13248 | 0 | found = 1; |
13249 | 0 | break; |
13250 | 0 | } |
13251 | 0 | curB = curB->next; |
13252 | 0 | } |
13253 | 0 | if (!found) |
13254 | 0 | break; |
13255 | 0 | cur = cur->next; |
13256 | 0 | } |
13257 | 0 | if (found) |
13258 | 0 | return(0); |
13259 | 0 | } else |
13260 | 0 | return(0); |
13261 | 0 | } |
13262 | 0 | } |
13263 | | /* |
13264 | | * 2 If either O1 or O2 is any, then any must be the value |
13265 | | */ |
13266 | 0 | if (completeWild->any != curWild->any) { |
13267 | 0 | if (completeWild->any == 0) { |
13268 | 0 | completeWild->any = 1; |
13269 | 0 | if (completeWild->nsSet != NULL) { |
13270 | 0 | xmlSchemaFreeWildcardNsSet(completeWild->nsSet); |
13271 | 0 | completeWild->nsSet = NULL; |
13272 | 0 | } |
13273 | 0 | if (completeWild->negNsSet != NULL) { |
13274 | 0 | xmlFree(completeWild->negNsSet); |
13275 | 0 | completeWild->negNsSet = NULL; |
13276 | 0 | } |
13277 | 0 | } |
13278 | 0 | return (0); |
13279 | 0 | } |
13280 | | /* |
13281 | | * 3 If both O1 and O2 are sets of (namespace names or `absent`), |
13282 | | * then the union of those sets must be the value. |
13283 | | */ |
13284 | 0 | if ((completeWild->nsSet != NULL) && (curWild->nsSet != NULL)) { |
13285 | 0 | int found; |
13286 | 0 | xmlSchemaWildcardNsPtr start; |
13287 | |
|
13288 | 0 | cur = curWild->nsSet; |
13289 | 0 | start = completeWild->nsSet; |
13290 | 0 | while (cur != NULL) { |
13291 | 0 | found = 0; |
13292 | 0 | curB = start; |
13293 | 0 | while (curB != NULL) { |
13294 | 0 | if (cur->value == curB->value) { |
13295 | 0 | found = 1; |
13296 | 0 | break; |
13297 | 0 | } |
13298 | 0 | curB = curB->next; |
13299 | 0 | } |
13300 | 0 | if (!found) { |
13301 | 0 | tmp = xmlSchemaNewWildcardNsConstraint(ctxt); |
13302 | 0 | if (tmp == NULL) |
13303 | 0 | return (-1); |
13304 | 0 | tmp->value = cur->value; |
13305 | 0 | tmp->next = completeWild->nsSet; |
13306 | 0 | completeWild->nsSet = tmp; |
13307 | 0 | } |
13308 | 0 | cur = cur->next; |
13309 | 0 | } |
13310 | | |
13311 | 0 | return(0); |
13312 | 0 | } |
13313 | | /* |
13314 | | * 4 If the two are negations of different values (namespace names |
13315 | | * or `absent`), then a pair of not and `absent` must be the value. |
13316 | | */ |
13317 | 0 | if ((completeWild->negNsSet != NULL) && |
13318 | 0 | (curWild->negNsSet != NULL) && |
13319 | 0 | (completeWild->negNsSet->value != curWild->negNsSet->value)) { |
13320 | 0 | completeWild->negNsSet->value = NULL; |
13321 | |
|
13322 | 0 | return(0); |
13323 | 0 | } |
13324 | | /* |
13325 | | * 5. |
13326 | | */ |
13327 | 0 | if (((completeWild->negNsSet != NULL) && |
13328 | 0 | (completeWild->negNsSet->value != NULL) && |
13329 | 0 | (curWild->nsSet != NULL)) || |
13330 | 0 | ((curWild->negNsSet != NULL) && |
13331 | 0 | (curWild->negNsSet->value != NULL) && |
13332 | 0 | (completeWild->nsSet != NULL))) { |
13333 | |
|
13334 | 0 | int nsFound, absentFound = 0; |
13335 | |
|
13336 | 0 | if (completeWild->nsSet != NULL) { |
13337 | 0 | cur = completeWild->nsSet; |
13338 | 0 | curB = curWild->negNsSet; |
13339 | 0 | } else { |
13340 | 0 | cur = curWild->nsSet; |
13341 | 0 | curB = completeWild->negNsSet; |
13342 | 0 | } |
13343 | 0 | nsFound = 0; |
13344 | 0 | while (cur != NULL) { |
13345 | 0 | if (cur->value == NULL) |
13346 | 0 | absentFound = 1; |
13347 | 0 | else if (cur->value == curB->value) |
13348 | 0 | nsFound = 1; |
13349 | 0 | if (nsFound && absentFound) |
13350 | 0 | break; |
13351 | 0 | cur = cur->next; |
13352 | 0 | } |
13353 | |
|
13354 | 0 | if (nsFound && absentFound) { |
13355 | | /* |
13356 | | * 5.1 If the set S includes both the negated namespace |
13357 | | * name and `absent`, then any must be the value. |
13358 | | */ |
13359 | 0 | completeWild->any = 1; |
13360 | 0 | if (completeWild->nsSet != NULL) { |
13361 | 0 | xmlSchemaFreeWildcardNsSet(completeWild->nsSet); |
13362 | 0 | completeWild->nsSet = NULL; |
13363 | 0 | } |
13364 | 0 | if (completeWild->negNsSet != NULL) { |
13365 | 0 | xmlFree(completeWild->negNsSet); |
13366 | 0 | completeWild->negNsSet = NULL; |
13367 | 0 | } |
13368 | 0 | } else if (nsFound && (!absentFound)) { |
13369 | | /* |
13370 | | * 5.2 If the set S includes the negated namespace name |
13371 | | * but not `absent`, then a pair of not and `absent` must |
13372 | | * be the value. |
13373 | | */ |
13374 | 0 | if (completeWild->nsSet != NULL) { |
13375 | 0 | xmlSchemaFreeWildcardNsSet(completeWild->nsSet); |
13376 | 0 | completeWild->nsSet = NULL; |
13377 | 0 | } |
13378 | 0 | if (completeWild->negNsSet == NULL) { |
13379 | 0 | completeWild->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt); |
13380 | 0 | if (completeWild->negNsSet == NULL) |
13381 | 0 | return (-1); |
13382 | 0 | } |
13383 | 0 | completeWild->negNsSet->value = NULL; |
13384 | 0 | } else if ((!nsFound) && absentFound) { |
13385 | | /* |
13386 | | * 5.3 If the set S includes `absent` but not the negated |
13387 | | * namespace name, then the union is not expressible. |
13388 | | */ |
13389 | 0 | xmlSchemaPErr(ctxt, completeWild->node, |
13390 | 0 | XML_SCHEMAP_UNION_NOT_EXPRESSIBLE, |
13391 | 0 | "The union of the wildcard is not expressible.\n", |
13392 | 0 | NULL, NULL); |
13393 | 0 | return(XML_SCHEMAP_UNION_NOT_EXPRESSIBLE); |
13394 | 0 | } else if ((!nsFound) && (!absentFound)) { |
13395 | | /* |
13396 | | * 5.4 If the set S does not include either the negated namespace |
13397 | | * name or `absent`, then whichever of O1 or O2 is a pair of not |
13398 | | * and a namespace name must be the value. |
13399 | | */ |
13400 | 0 | if (completeWild->negNsSet == NULL) { |
13401 | 0 | if (completeWild->nsSet != NULL) { |
13402 | 0 | xmlSchemaFreeWildcardNsSet(completeWild->nsSet); |
13403 | 0 | completeWild->nsSet = NULL; |
13404 | 0 | } |
13405 | 0 | completeWild->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt); |
13406 | 0 | if (completeWild->negNsSet == NULL) |
13407 | 0 | return (-1); |
13408 | 0 | completeWild->negNsSet->value = curWild->negNsSet->value; |
13409 | 0 | } |
13410 | 0 | } |
13411 | 0 | return (0); |
13412 | 0 | } |
13413 | | /* |
13414 | | * 6. |
13415 | | */ |
13416 | 0 | if (((completeWild->negNsSet != NULL) && |
13417 | 0 | (completeWild->negNsSet->value == NULL) && |
13418 | 0 | (curWild->nsSet != NULL)) || |
13419 | 0 | ((curWild->negNsSet != NULL) && |
13420 | 0 | (curWild->negNsSet->value == NULL) && |
13421 | 0 | (completeWild->nsSet != NULL))) { |
13422 | |
|
13423 | 0 | if (completeWild->nsSet != NULL) { |
13424 | 0 | cur = completeWild->nsSet; |
13425 | 0 | } else { |
13426 | 0 | cur = curWild->nsSet; |
13427 | 0 | } |
13428 | 0 | while (cur != NULL) { |
13429 | 0 | if (cur->value == NULL) { |
13430 | | /* |
13431 | | * 6.1 If the set S includes `absent`, then any must be the |
13432 | | * value. |
13433 | | */ |
13434 | 0 | completeWild->any = 1; |
13435 | 0 | if (completeWild->nsSet != NULL) { |
13436 | 0 | xmlSchemaFreeWildcardNsSet(completeWild->nsSet); |
13437 | 0 | completeWild->nsSet = NULL; |
13438 | 0 | } |
13439 | 0 | if (completeWild->negNsSet != NULL) { |
13440 | 0 | xmlFree(completeWild->negNsSet); |
13441 | 0 | completeWild->negNsSet = NULL; |
13442 | 0 | } |
13443 | 0 | return (0); |
13444 | 0 | } |
13445 | 0 | cur = cur->next; |
13446 | 0 | } |
13447 | 0 | if (completeWild->negNsSet == NULL) { |
13448 | | /* |
13449 | | * 6.2 If the set S does not include `absent`, then a pair of not |
13450 | | * and `absent` must be the value. |
13451 | | */ |
13452 | 0 | if (completeWild->nsSet != NULL) { |
13453 | 0 | xmlSchemaFreeWildcardNsSet(completeWild->nsSet); |
13454 | 0 | completeWild->nsSet = NULL; |
13455 | 0 | } |
13456 | 0 | completeWild->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt); |
13457 | 0 | if (completeWild->negNsSet == NULL) |
13458 | 0 | return (-1); |
13459 | 0 | completeWild->negNsSet->value = NULL; |
13460 | 0 | } |
13461 | 0 | return (0); |
13462 | 0 | } |
13463 | 0 | return (0); |
13464 | |
|
13465 | 0 | } |
13466 | | |
13467 | | /** |
13468 | | * Intersects the namespace constraints of the given wildcards. |
13469 | | * `completeWild` will hold the resulting intersection. |
13470 | | * |
13471 | | * @param ctxt the schema parser context |
13472 | | * @param completeWild the first wildcard |
13473 | | * @param curWild the second wildcard |
13474 | | * @returns a positive error code on failure, -1 in case of an |
13475 | | * internal error, 0 otherwise. |
13476 | | */ |
13477 | | static int |
13478 | | xmlSchemaIntersectWildcards(xmlSchemaParserCtxtPtr ctxt, |
13479 | | xmlSchemaWildcardPtr completeWild, |
13480 | | xmlSchemaWildcardPtr curWild) |
13481 | 0 | { |
13482 | 0 | xmlSchemaWildcardNsPtr cur, curB, prev, tmp; |
13483 | | |
13484 | | /* |
13485 | | * 1 If O1 and O2 are the same value, then that value must be the |
13486 | | * value. |
13487 | | */ |
13488 | 0 | if ((completeWild->any == curWild->any) && |
13489 | 0 | ((completeWild->nsSet == NULL) == (curWild->nsSet == NULL)) && |
13490 | 0 | ((completeWild->negNsSet == NULL) == (curWild->negNsSet == NULL))) { |
13491 | |
|
13492 | 0 | if ((completeWild->negNsSet == NULL) || |
13493 | 0 | (completeWild->negNsSet->value == curWild->negNsSet->value)) { |
13494 | |
|
13495 | 0 | if (completeWild->nsSet != NULL) { |
13496 | 0 | int found = 0; |
13497 | | |
13498 | | /* |
13499 | | * Check equality of sets. |
13500 | | */ |
13501 | 0 | cur = completeWild->nsSet; |
13502 | 0 | while (cur != NULL) { |
13503 | 0 | found = 0; |
13504 | 0 | curB = curWild->nsSet; |
13505 | 0 | while (curB != NULL) { |
13506 | 0 | if (cur->value == curB->value) { |
13507 | 0 | found = 1; |
13508 | 0 | break; |
13509 | 0 | } |
13510 | 0 | curB = curB->next; |
13511 | 0 | } |
13512 | 0 | if (!found) |
13513 | 0 | break; |
13514 | 0 | cur = cur->next; |
13515 | 0 | } |
13516 | 0 | if (found) |
13517 | 0 | return(0); |
13518 | 0 | } else |
13519 | 0 | return(0); |
13520 | 0 | } |
13521 | 0 | } |
13522 | | /* |
13523 | | * 2 If either O1 or O2 is any, then the other must be the value. |
13524 | | */ |
13525 | 0 | if ((completeWild->any != curWild->any) && (completeWild->any)) { |
13526 | 0 | if (xmlSchemaCloneWildcardNsConstraints(ctxt, completeWild, curWild) == -1) |
13527 | 0 | return(-1); |
13528 | 0 | return(0); |
13529 | 0 | } |
13530 | | /* |
13531 | | * 3 If either O1 or O2 is a pair of not and a value (a namespace |
13532 | | * name or `absent`) and the other is a set of (namespace names or |
13533 | | * `absent`), then that set, minus the negated value if it was in |
13534 | | * the set, minus `absent` if it was in the set, must be the value. |
13535 | | */ |
13536 | 0 | if (((completeWild->negNsSet != NULL) && (curWild->nsSet != NULL)) || |
13537 | 0 | ((curWild->negNsSet != NULL) && (completeWild->nsSet != NULL))) { |
13538 | 0 | const xmlChar *neg; |
13539 | |
|
13540 | 0 | if (completeWild->nsSet == NULL) { |
13541 | 0 | neg = completeWild->negNsSet->value; |
13542 | 0 | if (xmlSchemaCloneWildcardNsConstraints(ctxt, completeWild, curWild) == -1) |
13543 | 0 | return(-1); |
13544 | 0 | } else |
13545 | 0 | neg = curWild->negNsSet->value; |
13546 | | /* |
13547 | | * Remove absent and negated. |
13548 | | */ |
13549 | 0 | prev = NULL; |
13550 | 0 | cur = completeWild->nsSet; |
13551 | 0 | while (cur != NULL) { |
13552 | 0 | if (cur->value == NULL) { |
13553 | 0 | if (prev == NULL) |
13554 | 0 | completeWild->nsSet = cur->next; |
13555 | 0 | else |
13556 | 0 | prev->next = cur->next; |
13557 | 0 | xmlFree(cur); |
13558 | 0 | break; |
13559 | 0 | } |
13560 | 0 | prev = cur; |
13561 | 0 | cur = cur->next; |
13562 | 0 | } |
13563 | 0 | if (neg != NULL) { |
13564 | 0 | prev = NULL; |
13565 | 0 | cur = completeWild->nsSet; |
13566 | 0 | while (cur != NULL) { |
13567 | 0 | if (cur->value == neg) { |
13568 | 0 | if (prev == NULL) |
13569 | 0 | completeWild->nsSet = cur->next; |
13570 | 0 | else |
13571 | 0 | prev->next = cur->next; |
13572 | 0 | xmlFree(cur); |
13573 | 0 | break; |
13574 | 0 | } |
13575 | 0 | prev = cur; |
13576 | 0 | cur = cur->next; |
13577 | 0 | } |
13578 | 0 | } |
13579 | |
|
13580 | 0 | return(0); |
13581 | 0 | } |
13582 | | /* |
13583 | | * 4 If both O1 and O2 are sets of (namespace names or `absent`), |
13584 | | * then the intersection of those sets must be the value. |
13585 | | */ |
13586 | 0 | if ((completeWild->nsSet != NULL) && (curWild->nsSet != NULL)) { |
13587 | 0 | int found; |
13588 | |
|
13589 | 0 | cur = completeWild->nsSet; |
13590 | 0 | prev = NULL; |
13591 | 0 | while (cur != NULL) { |
13592 | 0 | found = 0; |
13593 | 0 | curB = curWild->nsSet; |
13594 | 0 | while (curB != NULL) { |
13595 | 0 | if (cur->value == curB->value) { |
13596 | 0 | found = 1; |
13597 | 0 | break; |
13598 | 0 | } |
13599 | 0 | curB = curB->next; |
13600 | 0 | } |
13601 | 0 | if (!found) { |
13602 | 0 | if (prev == NULL) |
13603 | 0 | completeWild->nsSet = cur->next; |
13604 | 0 | else |
13605 | 0 | prev->next = cur->next; |
13606 | 0 | tmp = cur->next; |
13607 | 0 | xmlFree(cur); |
13608 | 0 | cur = tmp; |
13609 | 0 | continue; |
13610 | 0 | } |
13611 | 0 | prev = cur; |
13612 | 0 | cur = cur->next; |
13613 | 0 | } |
13614 | |
|
13615 | 0 | return(0); |
13616 | 0 | } |
13617 | | /* 5 If the two are negations of different namespace names, |
13618 | | * then the intersection is not expressible |
13619 | | */ |
13620 | 0 | if ((completeWild->negNsSet != NULL) && |
13621 | 0 | (curWild->negNsSet != NULL) && |
13622 | 0 | (completeWild->negNsSet->value != curWild->negNsSet->value) && |
13623 | 0 | (completeWild->negNsSet->value != NULL) && |
13624 | 0 | (curWild->negNsSet->value != NULL)) { |
13625 | |
|
13626 | 0 | xmlSchemaPErr(ctxt, completeWild->node, XML_SCHEMAP_INTERSECTION_NOT_EXPRESSIBLE, |
13627 | 0 | "The intersection of the wildcard is not expressible.\n", |
13628 | 0 | NULL, NULL); |
13629 | 0 | return(XML_SCHEMAP_INTERSECTION_NOT_EXPRESSIBLE); |
13630 | 0 | } |
13631 | | /* |
13632 | | * 6 If the one is a negation of a namespace name and the other |
13633 | | * is a negation of `absent`, then the one which is the negation |
13634 | | * of a namespace name must be the value. |
13635 | | */ |
13636 | 0 | if ((completeWild->negNsSet != NULL) && (curWild->negNsSet != NULL) && |
13637 | 0 | (completeWild->negNsSet->value != curWild->negNsSet->value) && |
13638 | 0 | (completeWild->negNsSet->value == NULL)) { |
13639 | 0 | completeWild->negNsSet->value = curWild->negNsSet->value; |
13640 | 0 | } |
13641 | 0 | return(0); |
13642 | 0 | } |
13643 | | |
13644 | | /** |
13645 | | * Schema Component Constraint: Wildcard Subset (cos-ns-subset) |
13646 | | * |
13647 | | * @param sub the first wildcard |
13648 | | * @param super the second wildcard |
13649 | | * @returns 0 if the namespace constraint of `sub` is an intensional |
13650 | | * subset of `super`, 1 otherwise. |
13651 | | */ |
13652 | | static int |
13653 | | xmlSchemaCheckCOSNSSubset(xmlSchemaWildcardPtr sub, |
13654 | | xmlSchemaWildcardPtr super) |
13655 | 0 | { |
13656 | | /* |
13657 | | * 1 super must be any. |
13658 | | */ |
13659 | 0 | if (super->any) |
13660 | 0 | return (0); |
13661 | | /* |
13662 | | * 2.1 sub must be a pair of not and a namespace name or `absent`. |
13663 | | * 2.2 super must be a pair of not and the same value. |
13664 | | */ |
13665 | 0 | if ((sub->negNsSet != NULL) && |
13666 | 0 | (super->negNsSet != NULL) && |
13667 | 0 | (sub->negNsSet->value == super->negNsSet->value)) |
13668 | 0 | return (0); |
13669 | | /* |
13670 | | * 3.1 sub must be a set whose members are either namespace names or `absent`. |
13671 | | */ |
13672 | 0 | if (sub->nsSet != NULL) { |
13673 | | /* |
13674 | | * 3.2.1 super must be the same set or a superset thereof. |
13675 | | */ |
13676 | 0 | if (super->nsSet != NULL) { |
13677 | 0 | xmlSchemaWildcardNsPtr cur, curB; |
13678 | 0 | int found = 0; |
13679 | |
|
13680 | 0 | cur = sub->nsSet; |
13681 | 0 | while (cur != NULL) { |
13682 | 0 | found = 0; |
13683 | 0 | curB = super->nsSet; |
13684 | 0 | while (curB != NULL) { |
13685 | 0 | if (cur->value == curB->value) { |
13686 | 0 | found = 1; |
13687 | 0 | break; |
13688 | 0 | } |
13689 | 0 | curB = curB->next; |
13690 | 0 | } |
13691 | 0 | if (!found) |
13692 | 0 | return (1); |
13693 | 0 | cur = cur->next; |
13694 | 0 | } |
13695 | 0 | if (found) |
13696 | 0 | return (0); |
13697 | 0 | } else if (super->negNsSet != NULL) { |
13698 | 0 | xmlSchemaWildcardNsPtr cur; |
13699 | | /* |
13700 | | * 3.2.2 super must be a pair of not and a namespace name or |
13701 | | * `absent` and that value must not be in sub's set. |
13702 | | */ |
13703 | 0 | cur = sub->nsSet; |
13704 | 0 | while (cur != NULL) { |
13705 | 0 | if (cur->value == super->negNsSet->value) |
13706 | 0 | return (1); |
13707 | 0 | cur = cur->next; |
13708 | 0 | } |
13709 | 0 | return (0); |
13710 | 0 | } |
13711 | 0 | } |
13712 | 0 | return (1); |
13713 | 0 | } |
13714 | | |
13715 | | static int |
13716 | | xmlSchemaGetEffectiveValueConstraint(xmlSchemaAttributeUsePtr attruse, |
13717 | | int *fixed, |
13718 | | const xmlChar **value, |
13719 | | xmlSchemaValPtr *val) |
13720 | 0 | { |
13721 | 0 | *fixed = 0; |
13722 | 0 | *value = NULL; |
13723 | 0 | if (val != 0) |
13724 | 0 | *val = NULL; |
13725 | |
|
13726 | 0 | if (attruse->defValue != NULL) { |
13727 | 0 | *value = attruse->defValue; |
13728 | 0 | if (val != NULL) |
13729 | 0 | *val = attruse->defVal; |
13730 | 0 | if (attruse->flags & XML_SCHEMA_ATTR_USE_FIXED) |
13731 | 0 | *fixed = 1; |
13732 | 0 | return(1); |
13733 | 0 | } else if ((attruse->attrDecl != NULL) && |
13734 | 0 | (attruse->attrDecl->defValue != NULL)) { |
13735 | 0 | *value = attruse->attrDecl->defValue; |
13736 | 0 | if (val != NULL) |
13737 | 0 | *val = attruse->attrDecl->defVal; |
13738 | 0 | if (attruse->attrDecl->flags & XML_SCHEMAS_ATTR_FIXED) |
13739 | 0 | *fixed = 1; |
13740 | 0 | return(1); |
13741 | 0 | } |
13742 | 0 | return(0); |
13743 | 0 | } |
13744 | | /** |
13745 | | * Validation Rule: Wildcard allows Namespace Name |
13746 | | * (cvc-wildcard-namespace) |
13747 | | * |
13748 | | * @param wild the wildcard |
13749 | | * @param ns the namespace |
13750 | | * @returns 0 if the given namespace matches the wildcard, |
13751 | | * 1 otherwise and -1 on API errors. |
13752 | | */ |
13753 | | static int |
13754 | | xmlSchemaCheckCVCWildcardNamespace(xmlSchemaWildcardPtr wild, |
13755 | | const xmlChar* ns) |
13756 | 0 | { |
13757 | 0 | if (wild == NULL) |
13758 | 0 | return(-1); |
13759 | | |
13760 | 0 | if (wild->any) |
13761 | 0 | return(0); |
13762 | 0 | else if (wild->nsSet != NULL) { |
13763 | 0 | xmlSchemaWildcardNsPtr cur; |
13764 | |
|
13765 | 0 | cur = wild->nsSet; |
13766 | 0 | while (cur != NULL) { |
13767 | 0 | if (xmlStrEqual(cur->value, ns)) |
13768 | 0 | return(0); |
13769 | 0 | cur = cur->next; |
13770 | 0 | } |
13771 | 0 | } else if ((wild->negNsSet != NULL) && (ns != NULL) && |
13772 | 0 | (!xmlStrEqual(wild->negNsSet->value, ns))) |
13773 | 0 | return(0); |
13774 | | |
13775 | 0 | return(1); |
13776 | 0 | } |
13777 | | |
13778 | 0 | #define XML_SCHEMA_ACTION_DERIVE 0 |
13779 | 0 | #define XML_SCHEMA_ACTION_REDEFINE 1 |
13780 | | |
13781 | 0 | #define WXS_ACTION_STR(a) \ |
13782 | 0 | ((a) == XML_SCHEMA_ACTION_DERIVE) ? (const xmlChar *) "base" : (const xmlChar *) "redefined" |
13783 | | |
13784 | | /* |
13785 | | * Schema Component Constraint: |
13786 | | * Derivation Valid (Restriction, Complex) |
13787 | | * derivation-ok-restriction (2) - (4) |
13788 | | * |
13789 | | * ATTENTION: |
13790 | | * In XML Schema 1.1 this will be: |
13791 | | * Validation Rule: |
13792 | | * Checking complex type subsumption (practicalSubsumption) (1, 2 and 3) |
13793 | | * |
13794 | | */ |
13795 | | static int |
13796 | | xmlSchemaCheckDerivationOKRestriction2to4(xmlSchemaParserCtxtPtr pctxt, |
13797 | | int action, |
13798 | | xmlSchemaBasicItemPtr item, |
13799 | | xmlSchemaBasicItemPtr baseItem, |
13800 | | xmlSchemaItemListPtr uses, |
13801 | | xmlSchemaItemListPtr baseUses, |
13802 | | xmlSchemaWildcardPtr wild, |
13803 | | xmlSchemaWildcardPtr baseWild) |
13804 | 0 | { |
13805 | 0 | xmlSchemaAttributeUsePtr cur = NULL, bcur; |
13806 | 0 | int i, j, found; /* err = 0; */ |
13807 | 0 | const xmlChar *bEffValue; |
13808 | 0 | int effFixed; |
13809 | |
|
13810 | 0 | if (uses != NULL) { |
13811 | 0 | for (i = 0; i < uses->nbItems; i++) { |
13812 | 0 | cur = uses->items[i]; |
13813 | 0 | found = 0; |
13814 | 0 | if (baseUses == NULL) |
13815 | 0 | goto not_found; |
13816 | 0 | for (j = 0; j < baseUses->nbItems; j++) { |
13817 | 0 | bcur = baseUses->items[j]; |
13818 | 0 | if ((WXS_ATTRUSE_DECL_NAME(cur) == |
13819 | 0 | WXS_ATTRUSE_DECL_NAME(bcur)) && |
13820 | 0 | (WXS_ATTRUSE_DECL_TNS(cur) == |
13821 | 0 | WXS_ATTRUSE_DECL_TNS(bcur))) |
13822 | 0 | { |
13823 | | /* |
13824 | | * (2.1) "If there is an attribute use in the {attribute |
13825 | | * uses} of the {base type definition} (call this B) whose |
13826 | | * {attribute declaration} has the same {name} and {target |
13827 | | * namespace}, then all of the following must be true:" |
13828 | | */ |
13829 | 0 | found = 1; |
13830 | |
|
13831 | 0 | if ((cur->occurs == XML_SCHEMAS_ATTR_USE_OPTIONAL) && |
13832 | 0 | (bcur->occurs == XML_SCHEMAS_ATTR_USE_REQUIRED)) |
13833 | 0 | { |
13834 | 0 | xmlChar *str = NULL; |
13835 | | /* |
13836 | | * (2.1.1) "one of the following must be true:" |
13837 | | * (2.1.1.1) "B's {required} is false." |
13838 | | * (2.1.1.2) "R's {required} is true." |
13839 | | */ |
13840 | 0 | xmlSchemaPAttrUseErr4(pctxt, |
13841 | 0 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_1, |
13842 | 0 | WXS_ITEM_NODE(item), item, cur, |
13843 | 0 | "The 'optional' attribute use is inconsistent " |
13844 | 0 | "with the corresponding 'required' attribute use of " |
13845 | 0 | "the %s %s", |
13846 | 0 | WXS_ACTION_STR(action), |
13847 | 0 | xmlSchemaGetComponentDesignation(&str, baseItem), |
13848 | 0 | NULL, NULL); |
13849 | 0 | FREE_AND_NULL(str); |
13850 | | /* err = pctxt->err; */ |
13851 | 0 | } else if (xmlSchemaCheckCOSSTDerivedOK(ACTXT_CAST pctxt, |
13852 | 0 | WXS_ATTRUSE_TYPEDEF(cur), |
13853 | 0 | WXS_ATTRUSE_TYPEDEF(bcur), 0) != 0) |
13854 | 0 | { |
13855 | 0 | xmlChar *strA = NULL, *strB = NULL, *strC = NULL; |
13856 | | |
13857 | | /* |
13858 | | * SPEC (2.1.2) "R's {attribute declaration}'s |
13859 | | * {type definition} must be validly derived from |
13860 | | * B's {type definition} given the empty set as |
13861 | | * defined in Type Derivation OK (Simple) ($3.14.6)." |
13862 | | */ |
13863 | 0 | xmlSchemaPAttrUseErr4(pctxt, |
13864 | 0 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_2, |
13865 | 0 | WXS_ITEM_NODE(item), item, cur, |
13866 | 0 | "The attribute declaration's %s " |
13867 | 0 | "is not validly derived from " |
13868 | 0 | "the corresponding %s of the " |
13869 | 0 | "attribute declaration in the %s %s", |
13870 | 0 | xmlSchemaGetComponentDesignation(&strA, |
13871 | 0 | WXS_ATTRUSE_TYPEDEF(cur)), |
13872 | 0 | xmlSchemaGetComponentDesignation(&strB, |
13873 | 0 | WXS_ATTRUSE_TYPEDEF(bcur)), |
13874 | 0 | WXS_ACTION_STR(action), |
13875 | 0 | xmlSchemaGetComponentDesignation(&strC, baseItem)); |
13876 | | /* xmlSchemaGetComponentDesignation(&str, baseItem), */ |
13877 | 0 | FREE_AND_NULL(strA); |
13878 | 0 | FREE_AND_NULL(strB); |
13879 | 0 | FREE_AND_NULL(strC); |
13880 | | /* err = pctxt->err; */ |
13881 | 0 | } else { |
13882 | | /* |
13883 | | * 2.1.3 [Definition:] Let the effective value |
13884 | | * constraint of an attribute use be its {value |
13885 | | * constraint}, if present, otherwise its {attribute |
13886 | | * declaration}'s {value constraint} . |
13887 | | */ |
13888 | 0 | xmlSchemaGetEffectiveValueConstraint(bcur, |
13889 | 0 | &effFixed, &bEffValue, NULL); |
13890 | | /* |
13891 | | * 2.1.3 ... one of the following must be true |
13892 | | * |
13893 | | * 2.1.3.1 B's `effective value constraint` is |
13894 | | * `absent` or default. |
13895 | | */ |
13896 | 0 | if ((bEffValue != NULL) && |
13897 | 0 | (effFixed == 1)) { |
13898 | 0 | const xmlChar *rEffValue = NULL; |
13899 | |
|
13900 | 0 | xmlSchemaGetEffectiveValueConstraint(bcur, |
13901 | 0 | &effFixed, &rEffValue, NULL); |
13902 | | /* |
13903 | | * 2.1.3.2 R's `effective value constraint` is |
13904 | | * fixed with the same string as B's. |
13905 | | * MAYBE TODO: Compare the computed values. |
13906 | | * Hmm, it says "same string" so |
13907 | | * string-equality might really be sufficient. |
13908 | | */ |
13909 | 0 | if ((effFixed == 0) || |
13910 | 0 | (! WXS_ARE_DEFAULT_STR_EQUAL(rEffValue, bEffValue))) |
13911 | 0 | { |
13912 | 0 | xmlChar *str = NULL; |
13913 | |
|
13914 | 0 | xmlSchemaPAttrUseErr4(pctxt, |
13915 | 0 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_3, |
13916 | 0 | WXS_ITEM_NODE(item), item, cur, |
13917 | 0 | "The effective value constraint of the " |
13918 | 0 | "attribute use is inconsistent with " |
13919 | 0 | "its correspondent in the %s %s", |
13920 | 0 | WXS_ACTION_STR(action), |
13921 | 0 | xmlSchemaGetComponentDesignation(&str, |
13922 | 0 | baseItem), |
13923 | 0 | NULL, NULL); |
13924 | 0 | FREE_AND_NULL(str); |
13925 | | /* err = pctxt->err; */ |
13926 | 0 | } |
13927 | 0 | } |
13928 | 0 | } |
13929 | 0 | break; |
13930 | 0 | } |
13931 | 0 | } |
13932 | 0 | not_found: |
13933 | 0 | if (!found) { |
13934 | | /* |
13935 | | * (2.2) "otherwise the {base type definition} must have an |
13936 | | * {attribute wildcard} and the {target namespace} of the |
13937 | | * R's {attribute declaration} must be `valid` with respect |
13938 | | * to that wildcard, as defined in Wildcard allows Namespace |
13939 | | * Name ($3.10.4)." |
13940 | | */ |
13941 | 0 | if ((baseWild == NULL) || |
13942 | 0 | (xmlSchemaCheckCVCWildcardNamespace(baseWild, |
13943 | 0 | (WXS_ATTRUSE_DECL(cur))->targetNamespace) != 0)) |
13944 | 0 | { |
13945 | 0 | xmlChar *str = NULL; |
13946 | |
|
13947 | 0 | xmlSchemaPAttrUseErr4(pctxt, |
13948 | 0 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_2, |
13949 | 0 | WXS_ITEM_NODE(item), item, cur, |
13950 | 0 | "Neither a matching attribute use, " |
13951 | 0 | "nor a matching wildcard exists in the %s %s", |
13952 | 0 | WXS_ACTION_STR(action), |
13953 | 0 | xmlSchemaGetComponentDesignation(&str, baseItem), |
13954 | 0 | NULL, NULL); |
13955 | 0 | FREE_AND_NULL(str); |
13956 | | /* err = pctxt->err; */ |
13957 | 0 | } |
13958 | 0 | } |
13959 | 0 | } |
13960 | 0 | } |
13961 | | /* |
13962 | | * SPEC derivation-ok-restriction (3): |
13963 | | * (3) "For each attribute use in the {attribute uses} of the {base type |
13964 | | * definition} whose {required} is true, there must be an attribute |
13965 | | * use with an {attribute declaration} with the same {name} and |
13966 | | * {target namespace} as its {attribute declaration} in the {attribute |
13967 | | * uses} of the complex type definition itself whose {required} is true. |
13968 | | */ |
13969 | 0 | if (baseUses != NULL) { |
13970 | 0 | for (j = 0; j < baseUses->nbItems; j++) { |
13971 | 0 | bcur = baseUses->items[j]; |
13972 | 0 | if (bcur->occurs != XML_SCHEMAS_ATTR_USE_REQUIRED) |
13973 | 0 | continue; |
13974 | 0 | found = 0; |
13975 | 0 | if (uses != NULL) { |
13976 | 0 | for (i = 0; i < uses->nbItems; i++) { |
13977 | 0 | cur = uses->items[i]; |
13978 | 0 | if ((WXS_ATTRUSE_DECL_NAME(cur) == |
13979 | 0 | WXS_ATTRUSE_DECL_NAME(bcur)) && |
13980 | 0 | (WXS_ATTRUSE_DECL_TNS(cur) == |
13981 | 0 | WXS_ATTRUSE_DECL_TNS(bcur))) { |
13982 | 0 | found = 1; |
13983 | 0 | break; |
13984 | 0 | } |
13985 | 0 | } |
13986 | 0 | } |
13987 | 0 | if (!found) { |
13988 | 0 | xmlChar *strA = NULL, *strB = NULL; |
13989 | |
|
13990 | 0 | xmlSchemaCustomErr4(ACTXT_CAST pctxt, |
13991 | 0 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_3, |
13992 | 0 | NULL, item, |
13993 | 0 | "A matching attribute use for the " |
13994 | 0 | "'required' %s of the %s %s is missing", |
13995 | 0 | xmlSchemaGetComponentDesignation(&strA, bcur), |
13996 | 0 | WXS_ACTION_STR(action), |
13997 | 0 | xmlSchemaGetComponentDesignation(&strB, baseItem), |
13998 | 0 | NULL); |
13999 | 0 | FREE_AND_NULL(strA); |
14000 | 0 | FREE_AND_NULL(strB); |
14001 | 0 | } |
14002 | 0 | } |
14003 | 0 | } |
14004 | | /* |
14005 | | * derivation-ok-restriction (4) |
14006 | | */ |
14007 | 0 | if (wild != NULL) { |
14008 | | /* |
14009 | | * (4) "If there is an {attribute wildcard}, all of the |
14010 | | * following must be true:" |
14011 | | */ |
14012 | 0 | if (baseWild == NULL) { |
14013 | 0 | xmlChar *str = NULL; |
14014 | | |
14015 | | /* |
14016 | | * (4.1) "The {base type definition} must also have one." |
14017 | | */ |
14018 | 0 | xmlSchemaCustomErr4(ACTXT_CAST pctxt, |
14019 | 0 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_1, |
14020 | 0 | NULL, item, |
14021 | 0 | "The %s has an attribute wildcard, " |
14022 | 0 | "but the %s %s '%s' does not have one", |
14023 | 0 | WXS_ITEM_TYPE_NAME(item), |
14024 | 0 | WXS_ACTION_STR(action), |
14025 | 0 | WXS_ITEM_TYPE_NAME(baseItem), |
14026 | 0 | xmlSchemaGetComponentQName(&str, baseItem)); |
14027 | 0 | FREE_AND_NULL(str); |
14028 | 0 | return(pctxt->err); |
14029 | 0 | } else if ((baseWild->any == 0) && |
14030 | 0 | xmlSchemaCheckCOSNSSubset(wild, baseWild)) |
14031 | 0 | { |
14032 | 0 | xmlChar *str = NULL; |
14033 | | /* |
14034 | | * (4.2) "The complex type definition's {attribute wildcard}'s |
14035 | | * {namespace constraint} must be a subset of the {base type |
14036 | | * definition}'s {attribute wildcard}'s {namespace constraint}, |
14037 | | * as defined by Wildcard Subset ($3.10.6)." |
14038 | | */ |
14039 | 0 | xmlSchemaCustomErr4(ACTXT_CAST pctxt, |
14040 | 0 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_2, |
14041 | 0 | NULL, item, |
14042 | 0 | "The attribute wildcard is not a valid " |
14043 | 0 | "subset of the wildcard in the %s %s '%s'", |
14044 | 0 | WXS_ACTION_STR(action), |
14045 | 0 | WXS_ITEM_TYPE_NAME(baseItem), |
14046 | 0 | xmlSchemaGetComponentQName(&str, baseItem), |
14047 | 0 | NULL); |
14048 | 0 | FREE_AND_NULL(str); |
14049 | 0 | return(pctxt->err); |
14050 | 0 | } |
14051 | | /* 4.3 Unless the {base type definition} is the `ur-type |
14052 | | * definition`, the complex type definition's {attribute |
14053 | | * wildcard}'s {process contents} must be identical to or |
14054 | | * stronger than the {base type definition}'s {attribute |
14055 | | * wildcard}'s {process contents}, where strict is stronger |
14056 | | * than lax is stronger than skip. |
14057 | | */ |
14058 | 0 | if ((! WXS_IS_ANYTYPE(baseItem)) && |
14059 | 0 | (wild->processContents < baseWild->processContents)) { |
14060 | 0 | xmlChar *str = NULL; |
14061 | 0 | xmlSchemaCustomErr4(ACTXT_CAST pctxt, |
14062 | 0 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_3, |
14063 | 0 | NULL, baseItem, |
14064 | 0 | "The {process contents} of the attribute wildcard is " |
14065 | 0 | "weaker than the one in the %s %s '%s'", |
14066 | 0 | WXS_ACTION_STR(action), |
14067 | 0 | WXS_ITEM_TYPE_NAME(baseItem), |
14068 | 0 | xmlSchemaGetComponentQName(&str, baseItem), |
14069 | 0 | NULL); |
14070 | 0 | FREE_AND_NULL(str) |
14071 | 0 | return(pctxt->err); |
14072 | 0 | } |
14073 | 0 | } |
14074 | 0 | return(0); |
14075 | 0 | } |
14076 | | |
14077 | | |
14078 | | static int |
14079 | | xmlSchemaExpandAttributeGroupRefs(xmlSchemaParserCtxtPtr pctxt, |
14080 | | xmlSchemaBasicItemPtr item, |
14081 | | xmlSchemaWildcardPtr *completeWild, |
14082 | | xmlSchemaItemListPtr list, |
14083 | | xmlSchemaItemListPtr prohibs); |
14084 | | /** |
14085 | | * Builds the wildcard and the attribute uses on the given complex type. |
14086 | | * |
14087 | | * |
14088 | | * ATTENTION TODO: Experimentally this uses pointer comparisons for |
14089 | | * strings, so recheck this if we start to hardcode some schemata, since |
14090 | | * they might not be in the same dict. |
14091 | | * NOTE: It is allowed to "extend" the xs:anyType type. |
14092 | | * |
14093 | | * @param pctxt the schema parser context |
14094 | | * @param type the complex type definition |
14095 | | * @returns -1 if an internal error occurs, 0 otherwise. |
14096 | | */ |
14097 | | static int |
14098 | | xmlSchemaFixupTypeAttributeUses(xmlSchemaParserCtxtPtr pctxt, |
14099 | | xmlSchemaTypePtr type) |
14100 | 0 | { |
14101 | 0 | xmlSchemaTypePtr baseType = NULL; |
14102 | 0 | xmlSchemaAttributeUsePtr use; |
14103 | 0 | xmlSchemaItemListPtr uses, baseUses, prohibs = NULL; |
14104 | |
|
14105 | 0 | if (type->baseType == NULL) { |
14106 | 0 | PERROR_INT("xmlSchemaFixupTypeAttributeUses", |
14107 | 0 | "no base type"); |
14108 | 0 | return (-1); |
14109 | 0 | } |
14110 | 0 | baseType = type->baseType; |
14111 | 0 | if (WXS_IS_TYPE_NOT_FIXED(baseType)) |
14112 | 0 | if (xmlSchemaTypeFixup(baseType, ACTXT_CAST pctxt) == -1) |
14113 | 0 | return(-1); |
14114 | | |
14115 | 0 | uses = type->attrUses; |
14116 | 0 | baseUses = baseType->attrUses; |
14117 | | /* |
14118 | | * Expand attribute group references. And build the 'complete' |
14119 | | * wildcard, i.e. intersect multiple wildcards. |
14120 | | * Move attribute prohibitions into a separate list. |
14121 | | */ |
14122 | 0 | if (uses != NULL) { |
14123 | 0 | if (WXS_IS_RESTRICTION(type)) { |
14124 | | /* |
14125 | | * This one will transfer all attr. prohibitions |
14126 | | * into pctxt->attrProhibs. |
14127 | | */ |
14128 | 0 | if (xmlSchemaExpandAttributeGroupRefs(pctxt, |
14129 | 0 | WXS_BASIC_CAST type, &(type->attributeWildcard), uses, |
14130 | 0 | pctxt->attrProhibs) == -1) |
14131 | 0 | { |
14132 | 0 | PERROR_INT("xmlSchemaFixupTypeAttributeUses", |
14133 | 0 | "failed to expand attributes"); |
14134 | 0 | return(-1); |
14135 | 0 | } |
14136 | 0 | if (pctxt->attrProhibs->nbItems != 0) |
14137 | 0 | prohibs = pctxt->attrProhibs; |
14138 | 0 | } else { |
14139 | 0 | if (xmlSchemaExpandAttributeGroupRefs(pctxt, |
14140 | 0 | WXS_BASIC_CAST type, &(type->attributeWildcard), uses, |
14141 | 0 | NULL) == -1) |
14142 | 0 | { |
14143 | 0 | PERROR_INT("xmlSchemaFixupTypeAttributeUses", |
14144 | 0 | "failed to expand attributes"); |
14145 | 0 | return(-1); |
14146 | 0 | } |
14147 | 0 | } |
14148 | 0 | } |
14149 | | /* |
14150 | | * Inherit the attribute uses of the base type. |
14151 | | */ |
14152 | 0 | if (baseUses != NULL) { |
14153 | 0 | int i, j; |
14154 | 0 | xmlSchemaAttributeUseProhibPtr pro; |
14155 | |
|
14156 | 0 | if (WXS_IS_RESTRICTION(type)) { |
14157 | 0 | int usesCount; |
14158 | 0 | xmlSchemaAttributeUsePtr tmp; |
14159 | |
|
14160 | 0 | if (uses != NULL) |
14161 | 0 | usesCount = uses->nbItems; |
14162 | 0 | else |
14163 | 0 | usesCount = 0; |
14164 | | |
14165 | | /* Restriction. */ |
14166 | 0 | for (i = 0; i < baseUses->nbItems; i++) { |
14167 | 0 | use = baseUses->items[i]; |
14168 | 0 | if (prohibs) { |
14169 | | /* |
14170 | | * Filter out prohibited uses. |
14171 | | */ |
14172 | 0 | for (j = 0; j < prohibs->nbItems; j++) { |
14173 | 0 | pro = prohibs->items[j]; |
14174 | 0 | if ((WXS_ATTRUSE_DECL_NAME(use) == pro->name) && |
14175 | 0 | (WXS_ATTRUSE_DECL_TNS(use) == |
14176 | 0 | pro->targetNamespace)) |
14177 | 0 | { |
14178 | 0 | goto inherit_next; |
14179 | 0 | } |
14180 | 0 | } |
14181 | 0 | } |
14182 | 0 | if (usesCount) { |
14183 | | /* |
14184 | | * Filter out existing uses. |
14185 | | */ |
14186 | 0 | for (j = 0; j < usesCount; j++) { |
14187 | 0 | tmp = uses->items[j]; |
14188 | 0 | if ((WXS_ATTRUSE_DECL_NAME(use) == |
14189 | 0 | WXS_ATTRUSE_DECL_NAME(tmp)) && |
14190 | 0 | (WXS_ATTRUSE_DECL_TNS(use) == |
14191 | 0 | WXS_ATTRUSE_DECL_TNS(tmp))) |
14192 | 0 | { |
14193 | 0 | goto inherit_next; |
14194 | 0 | } |
14195 | 0 | } |
14196 | 0 | } |
14197 | 0 | if (uses == NULL) { |
14198 | 0 | type->attrUses = xmlSchemaItemListCreate(); |
14199 | 0 | if (type->attrUses == NULL) |
14200 | 0 | goto exit_failure; |
14201 | 0 | uses = type->attrUses; |
14202 | 0 | } |
14203 | 0 | xmlSchemaItemListAddSize(uses, 2, use); |
14204 | 0 | inherit_next: {} |
14205 | 0 | } |
14206 | 0 | } else { |
14207 | | /* Extension. */ |
14208 | 0 | for (i = 0; i < baseUses->nbItems; i++) { |
14209 | 0 | use = baseUses->items[i]; |
14210 | 0 | if (uses == NULL) { |
14211 | 0 | type->attrUses = xmlSchemaItemListCreate(); |
14212 | 0 | if (type->attrUses == NULL) |
14213 | 0 | goto exit_failure; |
14214 | 0 | uses = type->attrUses; |
14215 | 0 | } |
14216 | 0 | xmlSchemaItemListAddSize(uses, baseUses->nbItems, use); |
14217 | 0 | } |
14218 | 0 | } |
14219 | 0 | } |
14220 | | /* |
14221 | | * Shrink attr. uses. |
14222 | | */ |
14223 | 0 | if (uses) { |
14224 | 0 | if (uses->nbItems == 0) { |
14225 | 0 | xmlSchemaItemListFree(uses); |
14226 | 0 | type->attrUses = NULL; |
14227 | 0 | } |
14228 | | /* |
14229 | | * TODO: We could shrink the size of the array |
14230 | | * to fit the actual number of items. |
14231 | | */ |
14232 | 0 | } |
14233 | | /* |
14234 | | * Compute the complete wildcard. |
14235 | | */ |
14236 | 0 | if (WXS_IS_EXTENSION(type)) { |
14237 | 0 | if (baseType->attributeWildcard != NULL) { |
14238 | | /* |
14239 | | * (3.2.2.1) "If the `base wildcard` is non-`absent`, then |
14240 | | * the appropriate case among the following:" |
14241 | | */ |
14242 | 0 | if (type->attributeWildcard != NULL) { |
14243 | | /* |
14244 | | * Union the complete wildcard with the base wildcard. |
14245 | | * SPEC {attribute wildcard} |
14246 | | * (3.2.2.1.2) "otherwise a wildcard whose {process contents} |
14247 | | * and {annotation} are those of the `complete wildcard`, |
14248 | | * and whose {namespace constraint} is the intensional union |
14249 | | * of the {namespace constraint} of the `complete wildcard` |
14250 | | * and of the `base wildcard`, as defined in Attribute |
14251 | | * Wildcard Union ($3.10.6)." |
14252 | | */ |
14253 | 0 | if (xmlSchemaUnionWildcards(pctxt, type->attributeWildcard, |
14254 | 0 | baseType->attributeWildcard) == -1) |
14255 | 0 | goto exit_failure; |
14256 | 0 | } else { |
14257 | | /* |
14258 | | * (3.2.2.1.1) "If the `complete wildcard` is `absent`, |
14259 | | * then the `base wildcard`." |
14260 | | */ |
14261 | 0 | type->attributeWildcard = baseType->attributeWildcard; |
14262 | 0 | } |
14263 | 0 | } else { |
14264 | | /* |
14265 | | * (3.2.2.2) "otherwise (the `base wildcard` is `absent`) the |
14266 | | * `complete wildcard`" |
14267 | | * NOOP |
14268 | | */ |
14269 | 0 | } |
14270 | 0 | } else { |
14271 | | /* |
14272 | | * SPEC {attribute wildcard} |
14273 | | * (3.1) "If the <restriction> alternative is chosen, then the |
14274 | | * `complete wildcard`;" |
14275 | | * NOOP |
14276 | | */ |
14277 | 0 | } |
14278 | | |
14279 | 0 | return (0); |
14280 | | |
14281 | 0 | exit_failure: |
14282 | 0 | return(-1); |
14283 | 0 | } |
14284 | | |
14285 | | /** |
14286 | | * Evaluates if a type definition contains the given "final". |
14287 | | * This does take "finalDefault" into account as well. |
14288 | | * |
14289 | | * @param type the type definition |
14290 | | * @param final the final |
14291 | | * @returns 1 if the type does contain the given "final", |
14292 | | * 0 otherwise. |
14293 | | */ |
14294 | | static int |
14295 | | xmlSchemaTypeFinalContains(xmlSchemaTypePtr type, int final) |
14296 | 0 | { |
14297 | 0 | if (type == NULL) |
14298 | 0 | return (0); |
14299 | 0 | if (type->flags & final) |
14300 | 0 | return (1); |
14301 | 0 | else |
14302 | 0 | return (0); |
14303 | 0 | } |
14304 | | |
14305 | | /** |
14306 | | * @param type the Union Simple Type |
14307 | | * @returns a list of member types of `type` if existing, |
14308 | | * NULL otherwise. |
14309 | | */ |
14310 | | static xmlSchemaTypeLinkPtr |
14311 | | xmlSchemaGetUnionSimpleTypeMemberTypes(xmlSchemaTypePtr type) |
14312 | 0 | { |
14313 | 0 | while ((type != NULL) && (type->type == XML_SCHEMA_TYPE_SIMPLE)) { |
14314 | 0 | if (type->memberTypes != NULL) |
14315 | 0 | return (type->memberTypes); |
14316 | 0 | else |
14317 | 0 | type = type->baseType; |
14318 | 0 | } |
14319 | 0 | return (NULL); |
14320 | 0 | } |
14321 | | |
14322 | | #if 0 |
14323 | | /** |
14324 | | * Schema Component Constraint: Effective Total Range |
14325 | | * (all and sequence) + (choice) |
14326 | | * |
14327 | | * @param particle the particle |
14328 | | * @returns the minimum Effective Total Range. |
14329 | | */ |
14330 | | static int |
14331 | | xmlSchemaGetParticleTotalRangeMin(xmlSchemaParticlePtr particle) |
14332 | | { |
14333 | | if ((particle->children == NULL) || |
14334 | | (particle->minOccurs == 0)) |
14335 | | return (0); |
14336 | | if (particle->children->type == XML_SCHEMA_TYPE_CHOICE) { |
14337 | | int min = -1, cur; |
14338 | | xmlSchemaParticlePtr part = |
14339 | | (xmlSchemaParticlePtr) particle->children->children; |
14340 | | |
14341 | | if (part == NULL) |
14342 | | return (0); |
14343 | | while (part != NULL) { |
14344 | | if ((part->children->type == XML_SCHEMA_TYPE_ELEMENT) || |
14345 | | (part->children->type == XML_SCHEMA_TYPE_ANY)) |
14346 | | cur = part->minOccurs; |
14347 | | else |
14348 | | cur = xmlSchemaGetParticleTotalRangeMin(part); |
14349 | | if (cur == 0) |
14350 | | return (0); |
14351 | | if ((min > cur) || (min == -1)) |
14352 | | min = cur; |
14353 | | part = (xmlSchemaParticlePtr) part->next; |
14354 | | } |
14355 | | return (particle->minOccurs * min); |
14356 | | } else { |
14357 | | /* <all> and <sequence> */ |
14358 | | int sum = 0; |
14359 | | xmlSchemaParticlePtr part = |
14360 | | (xmlSchemaParticlePtr) particle->children->children; |
14361 | | |
14362 | | if (part == NULL) |
14363 | | return (0); |
14364 | | do { |
14365 | | if ((part->children->type == XML_SCHEMA_TYPE_ELEMENT) || |
14366 | | (part->children->type == XML_SCHEMA_TYPE_ANY)) |
14367 | | sum += part->minOccurs; |
14368 | | else |
14369 | | sum += xmlSchemaGetParticleTotalRangeMin(part); |
14370 | | part = (xmlSchemaParticlePtr) part->next; |
14371 | | } while (part != NULL); |
14372 | | return (particle->minOccurs * sum); |
14373 | | } |
14374 | | } |
14375 | | |
14376 | | /** |
14377 | | * Schema Component Constraint: Effective Total Range |
14378 | | * (all and sequence) + (choice) |
14379 | | * |
14380 | | * @param particle the particle |
14381 | | * @returns the maximum Effective Total Range. |
14382 | | */ |
14383 | | static int |
14384 | | xmlSchemaGetParticleTotalRangeMax(xmlSchemaParticlePtr particle) |
14385 | | { |
14386 | | if ((particle->children == NULL) || |
14387 | | (particle->children->children == NULL)) |
14388 | | return (0); |
14389 | | if (particle->children->type == XML_SCHEMA_TYPE_CHOICE) { |
14390 | | int max = -1, cur; |
14391 | | xmlSchemaParticlePtr part = |
14392 | | (xmlSchemaParticlePtr) particle->children->children; |
14393 | | |
14394 | | for (; part != NULL; part = (xmlSchemaParticlePtr) part->next) { |
14395 | | if (part->children == NULL) |
14396 | | continue; |
14397 | | if ((part->children->type == XML_SCHEMA_TYPE_ELEMENT) || |
14398 | | (part->children->type == XML_SCHEMA_TYPE_ANY)) |
14399 | | cur = part->maxOccurs; |
14400 | | else |
14401 | | cur = xmlSchemaGetParticleTotalRangeMax(part); |
14402 | | if (cur == UNBOUNDED) |
14403 | | return (UNBOUNDED); |
14404 | | if ((max < cur) || (max == -1)) |
14405 | | max = cur; |
14406 | | } |
14407 | | /* TODO: Handle overflows? */ |
14408 | | return (particle->maxOccurs * max); |
14409 | | } else { |
14410 | | /* <all> and <sequence> */ |
14411 | | int sum = 0, cur; |
14412 | | xmlSchemaParticlePtr part = |
14413 | | (xmlSchemaParticlePtr) particle->children->children; |
14414 | | |
14415 | | for (; part != NULL; part = (xmlSchemaParticlePtr) part->next) { |
14416 | | if (part->children == NULL) |
14417 | | continue; |
14418 | | if ((part->children->type == XML_SCHEMA_TYPE_ELEMENT) || |
14419 | | (part->children->type == XML_SCHEMA_TYPE_ANY)) |
14420 | | cur = part->maxOccurs; |
14421 | | else |
14422 | | cur = xmlSchemaGetParticleTotalRangeMax(part); |
14423 | | if (cur == UNBOUNDED) |
14424 | | return (UNBOUNDED); |
14425 | | if ((cur > 0) && (particle->maxOccurs == UNBOUNDED)) |
14426 | | return (UNBOUNDED); |
14427 | | sum += cur; |
14428 | | } |
14429 | | /* TODO: Handle overflows? */ |
14430 | | return (particle->maxOccurs * sum); |
14431 | | } |
14432 | | } |
14433 | | #endif |
14434 | | |
14435 | | /** |
14436 | | * @param particle the particle |
14437 | | * @returns 1 if emptiable, 0 otherwise. |
14438 | | */ |
14439 | | static int |
14440 | | xmlSchemaGetParticleEmptiable(xmlSchemaParticlePtr particle) |
14441 | 0 | { |
14442 | 0 | xmlSchemaParticlePtr part; |
14443 | 0 | int emptiable; |
14444 | |
|
14445 | 0 | if ((particle->children == NULL) || (particle->minOccurs == 0)) |
14446 | 0 | return (1); |
14447 | | |
14448 | 0 | part = (xmlSchemaParticlePtr) particle->children->children; |
14449 | 0 | if (part == NULL) |
14450 | 0 | return (1); |
14451 | | |
14452 | 0 | while (part != NULL) { |
14453 | 0 | if ((part->children->type == XML_SCHEMA_TYPE_ELEMENT) || |
14454 | 0 | (part->children->type == XML_SCHEMA_TYPE_ANY)) |
14455 | 0 | emptiable = (part->minOccurs == 0); |
14456 | 0 | else |
14457 | 0 | emptiable = xmlSchemaGetParticleEmptiable(part); |
14458 | 0 | if (particle->children->type == XML_SCHEMA_TYPE_CHOICE) { |
14459 | 0 | if (emptiable) |
14460 | 0 | return (1); |
14461 | 0 | } else { |
14462 | | /* <all> and <sequence> */ |
14463 | 0 | if (!emptiable) |
14464 | 0 | return (0); |
14465 | 0 | } |
14466 | 0 | part = (xmlSchemaParticlePtr) part->next; |
14467 | 0 | } |
14468 | | |
14469 | 0 | if (particle->children->type == XML_SCHEMA_TYPE_CHOICE) |
14470 | 0 | return (0); |
14471 | 0 | else |
14472 | 0 | return (1); |
14473 | 0 | } |
14474 | | |
14475 | | /** |
14476 | | * Schema Component Constraint: Particle Emptiable |
14477 | | * Checks whether the given particle is emptiable. |
14478 | | * |
14479 | | * @param particle the particle |
14480 | | * @returns 1 if emptiable, 0 otherwise. |
14481 | | */ |
14482 | | static int |
14483 | | xmlSchemaIsParticleEmptiable(xmlSchemaParticlePtr particle) |
14484 | 0 | { |
14485 | | /* |
14486 | | * SPEC (1) "Its {min occurs} is 0." |
14487 | | */ |
14488 | 0 | if ((particle == NULL) || (particle->minOccurs == 0) || |
14489 | 0 | (particle->children == NULL)) |
14490 | 0 | return (1); |
14491 | | /* |
14492 | | * SPEC (2) "Its {term} is a group and the minimum part of the |
14493 | | * effective total range of that group, [...] is 0." |
14494 | | */ |
14495 | 0 | if (WXS_IS_MODEL_GROUP(particle->children)) |
14496 | 0 | return (xmlSchemaGetParticleEmptiable(particle)); |
14497 | 0 | return (0); |
14498 | 0 | } |
14499 | | |
14500 | | /** |
14501 | | * Schema Component Constraint: |
14502 | | * Type Derivation OK (Simple) (cos-st-derived-OK) |
14503 | | * |
14504 | | * Checks whether `type` can be validly |
14505 | | * derived from `baseType`. |
14506 | | * |
14507 | | * @param actxt a context |
14508 | | * @param type the derived simple type definition |
14509 | | * @param baseType the base type definition |
14510 | | * @param subset the subset of ('restriction', etc.) |
14511 | | * @returns 0 on success, an positive error code otherwise. |
14512 | | */ |
14513 | | static int |
14514 | | xmlSchemaCheckCOSSTDerivedOK(xmlSchemaAbstractCtxtPtr actxt, |
14515 | | xmlSchemaTypePtr type, |
14516 | | xmlSchemaTypePtr baseType, |
14517 | | int subset) |
14518 | 0 | { |
14519 | | /* |
14520 | | * 1 They are the same type definition. |
14521 | | * TODO: The identity check might have to be more complex than this. |
14522 | | */ |
14523 | 0 | if (type == baseType) |
14524 | 0 | return (0); |
14525 | | /* |
14526 | | * 2.1 restriction is not in the subset, or in the {final} |
14527 | | * of its own {base type definition}; |
14528 | | * |
14529 | | * NOTE that this will be used also via "xsi:type". |
14530 | | * |
14531 | | * TODO: Revise this, it looks strange. How can the "type" |
14532 | | * not be fixed or *in* fixing? |
14533 | | */ |
14534 | 0 | if (WXS_IS_TYPE_NOT_FIXED(type)) |
14535 | 0 | if (xmlSchemaTypeFixup(type, actxt) == -1) |
14536 | 0 | return(-1); |
14537 | 0 | if (WXS_IS_TYPE_NOT_FIXED(baseType)) |
14538 | 0 | if (xmlSchemaTypeFixup(baseType, actxt) == -1) |
14539 | 0 | return(-1); |
14540 | 0 | if ((subset & SUBSET_RESTRICTION) || |
14541 | 0 | (xmlSchemaTypeFinalContains(type->baseType, |
14542 | 0 | XML_SCHEMAS_TYPE_FINAL_RESTRICTION))) { |
14543 | 0 | return (XML_SCHEMAP_COS_ST_DERIVED_OK_2_1); |
14544 | 0 | } |
14545 | | /* 2.2 */ |
14546 | 0 | if (type->baseType == baseType) { |
14547 | | /* |
14548 | | * 2.2.1 D's `base type definition` is B. |
14549 | | */ |
14550 | 0 | return (0); |
14551 | 0 | } |
14552 | | /* |
14553 | | * 2.2.2 D's `base type definition` is not the `ur-type definition` |
14554 | | * and is validly derived from B given the subset, as defined by this |
14555 | | * constraint. |
14556 | | */ |
14557 | 0 | if ((! WXS_IS_ANYTYPE(type->baseType)) && |
14558 | 0 | (xmlSchemaCheckCOSSTDerivedOK(actxt, type->baseType, |
14559 | 0 | baseType, subset) == 0)) { |
14560 | 0 | return (0); |
14561 | 0 | } |
14562 | | /* |
14563 | | * 2.2.3 D's {variety} is list or union and B is the `simple ur-type |
14564 | | * definition`. |
14565 | | */ |
14566 | 0 | if (WXS_IS_ANY_SIMPLE_TYPE(baseType) && |
14567 | 0 | (WXS_IS_LIST(type) || WXS_IS_UNION(type))) { |
14568 | 0 | return (0); |
14569 | 0 | } |
14570 | | /* |
14571 | | * 2.2.4 B's {variety} is union and D is validly derived from a type |
14572 | | * definition in B's {member type definitions} given the subset, as |
14573 | | * defined by this constraint. |
14574 | | * |
14575 | | * NOTE: This seems not to involve built-in types, since there is no |
14576 | | * built-in Union Simple Type. |
14577 | | */ |
14578 | 0 | if (WXS_IS_UNION(baseType)) { |
14579 | 0 | xmlSchemaTypeLinkPtr cur; |
14580 | |
|
14581 | 0 | cur = baseType->memberTypes; |
14582 | 0 | while (cur != NULL) { |
14583 | 0 | if (WXS_IS_TYPE_NOT_FIXED(cur->type)) |
14584 | 0 | if (xmlSchemaTypeFixup(cur->type, actxt) == -1) |
14585 | 0 | return(-1); |
14586 | 0 | if (xmlSchemaCheckCOSSTDerivedOK(actxt, |
14587 | 0 | type, cur->type, subset) == 0) |
14588 | 0 | { |
14589 | | /* |
14590 | | * It just has to be validly derived from at least one |
14591 | | * member-type. |
14592 | | */ |
14593 | 0 | return (0); |
14594 | 0 | } |
14595 | 0 | cur = cur->next; |
14596 | 0 | } |
14597 | 0 | } |
14598 | 0 | return (XML_SCHEMAP_COS_ST_DERIVED_OK_2_2); |
14599 | 0 | } |
14600 | | |
14601 | | /** |
14602 | | * Checks st-props-correct (2) + ct-props-correct (3). |
14603 | | * Circular type definitions are not allowed. |
14604 | | * |
14605 | | * @param pctxt the schema parser context |
14606 | | * @param ctxtType the type definition |
14607 | | * @param ancestor an ancestor of `ctxtType` |
14608 | | * @returns XML_SCHEMAP_ST_PROPS_CORRECT_2 if the given type is |
14609 | | * circular, 0 otherwise. |
14610 | | */ |
14611 | | static int |
14612 | | xmlSchemaCheckTypeDefCircularInternal(xmlSchemaParserCtxtPtr pctxt, |
14613 | | xmlSchemaTypePtr ctxtType, |
14614 | | xmlSchemaTypePtr ancestor) |
14615 | 0 | { |
14616 | 0 | int ret; |
14617 | |
|
14618 | 0 | if ((ancestor == NULL) || (ancestor->type == XML_SCHEMA_TYPE_BASIC)) |
14619 | 0 | return (0); |
14620 | | |
14621 | 0 | if (ctxtType == ancestor) { |
14622 | 0 | xmlSchemaPCustomErr(pctxt, |
14623 | 0 | XML_SCHEMAP_ST_PROPS_CORRECT_2, |
14624 | 0 | WXS_BASIC_CAST ctxtType, WXS_ITEM_NODE(ctxtType), |
14625 | 0 | "The definition is circular", NULL); |
14626 | 0 | return (XML_SCHEMAP_ST_PROPS_CORRECT_2); |
14627 | 0 | } |
14628 | 0 | if (ancestor->flags & XML_SCHEMAS_TYPE_MARKED) { |
14629 | | /* |
14630 | | * Avoid infinite recursion on circular types not yet checked. |
14631 | | */ |
14632 | 0 | return (0); |
14633 | 0 | } |
14634 | 0 | ancestor->flags |= XML_SCHEMAS_TYPE_MARKED; |
14635 | 0 | ret = xmlSchemaCheckTypeDefCircularInternal(pctxt, ctxtType, |
14636 | 0 | ancestor->baseType); |
14637 | 0 | ancestor->flags ^= XML_SCHEMAS_TYPE_MARKED; |
14638 | 0 | return (ret); |
14639 | 0 | } |
14640 | | |
14641 | | /** |
14642 | | * Checks for circular type definitions. |
14643 | | * |
14644 | | * @param item the complex/simple type definition |
14645 | | * @param ctxt the parser context |
14646 | | */ |
14647 | | static void |
14648 | | xmlSchemaCheckTypeDefCircular(xmlSchemaTypePtr item, |
14649 | | xmlSchemaParserCtxtPtr ctxt) |
14650 | 0 | { |
14651 | 0 | if ((item == NULL) || |
14652 | 0 | (item->type == XML_SCHEMA_TYPE_BASIC) || |
14653 | 0 | (item->baseType == NULL)) |
14654 | 0 | return; |
14655 | 0 | xmlSchemaCheckTypeDefCircularInternal(ctxt, item, |
14656 | 0 | item->baseType); |
14657 | 0 | } |
14658 | | |
14659 | | /* |
14660 | | * Simple Type Definition Representation OK (src-simple-type) 4 |
14661 | | * |
14662 | | * "4 Circular union type definition is disallowed. That is, if the |
14663 | | * <union> alternative is chosen, there must not be any entries in the |
14664 | | * memberTypes [attribute] at any depth which resolve to the component |
14665 | | * corresponding to the <simpleType>." |
14666 | | * |
14667 | | * Note that this should work on the *representation* of a component, |
14668 | | * thus assumes any union types in the member types not being yet |
14669 | | * substituted. At this stage we need the variety of the types |
14670 | | * to be already computed. |
14671 | | */ |
14672 | | static int |
14673 | | xmlSchemaCheckUnionTypeDefCircularRecur(xmlSchemaParserCtxtPtr pctxt, |
14674 | | xmlSchemaTypePtr ctxType, |
14675 | | xmlSchemaTypeLinkPtr members) |
14676 | 0 | { |
14677 | 0 | xmlSchemaTypeLinkPtr member; |
14678 | 0 | xmlSchemaTypePtr memberType; |
14679 | |
|
14680 | 0 | member = members; |
14681 | 0 | while (member != NULL) { |
14682 | 0 | memberType = member->type; |
14683 | 0 | while ((memberType != NULL) && |
14684 | 0 | (memberType->type != XML_SCHEMA_TYPE_BASIC)) { |
14685 | 0 | if (memberType == ctxType) { |
14686 | 0 | xmlSchemaPCustomErr(pctxt, |
14687 | 0 | XML_SCHEMAP_SRC_SIMPLE_TYPE_4, |
14688 | 0 | WXS_BASIC_CAST ctxType, NULL, |
14689 | 0 | "The union type definition is circular", NULL); |
14690 | 0 | return (XML_SCHEMAP_SRC_SIMPLE_TYPE_4); |
14691 | 0 | } |
14692 | 0 | if ((WXS_IS_UNION(memberType)) && |
14693 | 0 | ((memberType->flags & XML_SCHEMAS_TYPE_MARKED) == 0)) |
14694 | 0 | { |
14695 | 0 | int res; |
14696 | 0 | memberType->flags |= XML_SCHEMAS_TYPE_MARKED; |
14697 | 0 | res = xmlSchemaCheckUnionTypeDefCircularRecur(pctxt, |
14698 | 0 | ctxType, |
14699 | 0 | xmlSchemaGetUnionSimpleTypeMemberTypes(memberType)); |
14700 | 0 | memberType->flags ^= XML_SCHEMAS_TYPE_MARKED; |
14701 | 0 | if (res != 0) |
14702 | 0 | return(res); |
14703 | 0 | } |
14704 | 0 | memberType = memberType->baseType; |
14705 | 0 | } |
14706 | 0 | member = member->next; |
14707 | 0 | } |
14708 | 0 | return(0); |
14709 | 0 | } |
14710 | | |
14711 | | static int |
14712 | | xmlSchemaCheckUnionTypeDefCircular(xmlSchemaParserCtxtPtr pctxt, |
14713 | | xmlSchemaTypePtr type) |
14714 | 0 | { |
14715 | 0 | if (! WXS_IS_UNION(type)) |
14716 | 0 | return(0); |
14717 | 0 | return(xmlSchemaCheckUnionTypeDefCircularRecur(pctxt, type, |
14718 | 0 | type->memberTypes)); |
14719 | 0 | } |
14720 | | |
14721 | | /** |
14722 | | * Resolves type definition references |
14723 | | * |
14724 | | * @param typeDef the complex/simple type definition |
14725 | | * @param ctxt the parser context |
14726 | | */ |
14727 | | static void |
14728 | | xmlSchemaResolveTypeReferences(xmlSchemaTypePtr typeDef, |
14729 | | xmlSchemaParserCtxtPtr ctxt) |
14730 | 0 | { |
14731 | 0 | if (typeDef == NULL) |
14732 | 0 | return; |
14733 | | |
14734 | | /* |
14735 | | * Resolve the base type. |
14736 | | */ |
14737 | 0 | if (typeDef->baseType == NULL) { |
14738 | 0 | typeDef->baseType = xmlSchemaGetType(ctxt->schema, |
14739 | 0 | typeDef->base, typeDef->baseNs); |
14740 | 0 | if (typeDef->baseType == NULL) { |
14741 | 0 | xmlSchemaPResCompAttrErr(ctxt, |
14742 | 0 | XML_SCHEMAP_SRC_RESOLVE, |
14743 | 0 | WXS_BASIC_CAST typeDef, typeDef->node, |
14744 | 0 | "base", typeDef->base, typeDef->baseNs, |
14745 | 0 | XML_SCHEMA_TYPE_SIMPLE, NULL); |
14746 | 0 | return; |
14747 | 0 | } |
14748 | 0 | } |
14749 | 0 | if (WXS_IS_SIMPLE(typeDef)) { |
14750 | 0 | if (WXS_IS_UNION(typeDef)) { |
14751 | | /* |
14752 | | * Resolve the memberTypes. |
14753 | | */ |
14754 | 0 | xmlSchemaResolveUnionMemberTypes(ctxt, typeDef); |
14755 | 0 | return; |
14756 | 0 | } else if (WXS_IS_LIST(typeDef)) { |
14757 | | /* |
14758 | | * Resolve the itemType. |
14759 | | */ |
14760 | 0 | if ((typeDef->subtypes == NULL) && (typeDef->base != NULL)) { |
14761 | |
|
14762 | 0 | typeDef->subtypes = xmlSchemaGetType(ctxt->schema, |
14763 | 0 | typeDef->base, typeDef->baseNs); |
14764 | |
|
14765 | 0 | if ((typeDef->subtypes == NULL) || |
14766 | 0 | (! WXS_IS_SIMPLE(typeDef->subtypes))) |
14767 | 0 | { |
14768 | 0 | typeDef->subtypes = NULL; |
14769 | 0 | xmlSchemaPResCompAttrErr(ctxt, |
14770 | 0 | XML_SCHEMAP_SRC_RESOLVE, |
14771 | 0 | WXS_BASIC_CAST typeDef, typeDef->node, |
14772 | 0 | "itemType", typeDef->base, typeDef->baseNs, |
14773 | 0 | XML_SCHEMA_TYPE_SIMPLE, NULL); |
14774 | 0 | } |
14775 | 0 | } |
14776 | 0 | return; |
14777 | 0 | } |
14778 | 0 | } |
14779 | | /* |
14780 | | * The ball of letters below means, that if we have a particle |
14781 | | * which has a QName-helper component as its {term}, we want |
14782 | | * to resolve it... |
14783 | | */ |
14784 | 0 | else if ((WXS_TYPE_CONTENTTYPE(typeDef) != NULL) && |
14785 | 0 | ((WXS_TYPE_CONTENTTYPE(typeDef))->type == |
14786 | 0 | XML_SCHEMA_TYPE_PARTICLE) && |
14787 | 0 | (WXS_TYPE_PARTICLE_TERM(typeDef) != NULL) && |
14788 | 0 | ((WXS_TYPE_PARTICLE_TERM(typeDef))->type == |
14789 | 0 | XML_SCHEMA_EXTRA_QNAMEREF)) |
14790 | 0 | { |
14791 | 0 | xmlSchemaQNameRefPtr ref = |
14792 | 0 | WXS_QNAME_CAST WXS_TYPE_PARTICLE_TERM(typeDef); |
14793 | 0 | xmlSchemaModelGroupDefPtr groupDef; |
14794 | | |
14795 | | /* |
14796 | | * URGENT TODO: Test this. |
14797 | | */ |
14798 | 0 | WXS_TYPE_PARTICLE_TERM(typeDef) = NULL; |
14799 | | /* |
14800 | | * Resolve the MG definition reference. |
14801 | | */ |
14802 | 0 | groupDef = |
14803 | 0 | WXS_MODEL_GROUPDEF_CAST xmlSchemaGetNamedComponent(ctxt->schema, |
14804 | 0 | ref->itemType, ref->name, ref->targetNamespace); |
14805 | 0 | if (groupDef == NULL) { |
14806 | 0 | xmlSchemaPResCompAttrErr(ctxt, XML_SCHEMAP_SRC_RESOLVE, |
14807 | 0 | NULL, WXS_ITEM_NODE(WXS_TYPE_PARTICLE(typeDef)), |
14808 | 0 | "ref", ref->name, ref->targetNamespace, ref->itemType, |
14809 | 0 | NULL); |
14810 | | /* Remove the particle. */ |
14811 | 0 | WXS_TYPE_CONTENTTYPE(typeDef) = NULL; |
14812 | 0 | } else if (WXS_MODELGROUPDEF_MODEL(groupDef) == NULL) |
14813 | | /* Remove the particle. */ |
14814 | 0 | WXS_TYPE_CONTENTTYPE(typeDef) = NULL; |
14815 | 0 | else { |
14816 | | /* |
14817 | | * Assign the MG definition's {model group} to the |
14818 | | * particle's {term}. |
14819 | | */ |
14820 | 0 | WXS_TYPE_PARTICLE_TERM(typeDef) = WXS_MODELGROUPDEF_MODEL(groupDef); |
14821 | |
|
14822 | 0 | if (WXS_MODELGROUPDEF_MODEL(groupDef)->type == XML_SCHEMA_TYPE_ALL) { |
14823 | | /* |
14824 | | * SPEC cos-all-limited (1.2) |
14825 | | * "1.2 the {term} property of a particle with |
14826 | | * {max occurs}=1 which is part of a pair which constitutes |
14827 | | * the {content type} of a complex type definition." |
14828 | | */ |
14829 | 0 | if ((WXS_TYPE_PARTICLE(typeDef))->maxOccurs != 1) { |
14830 | 0 | xmlSchemaCustomErr(ACTXT_CAST ctxt, |
14831 | | /* TODO: error code */ |
14832 | 0 | XML_SCHEMAP_COS_ALL_LIMITED, |
14833 | 0 | WXS_ITEM_NODE(WXS_TYPE_PARTICLE(typeDef)), NULL, |
14834 | 0 | "The particle's {max occurs} must be 1, since the " |
14835 | 0 | "reference resolves to an 'all' model group", |
14836 | 0 | NULL, NULL); |
14837 | 0 | } |
14838 | 0 | } |
14839 | 0 | } |
14840 | 0 | } |
14841 | 0 | } |
14842 | | |
14843 | | |
14844 | | |
14845 | | /** |
14846 | | * Checks st-props-correct. |
14847 | | * |
14848 | | * @param ctxt the schema parser context |
14849 | | * @param type the simple type definition |
14850 | | * @returns 0 if the properties are correct, |
14851 | | * if not, a positive error code and -1 on internal |
14852 | | * errors. |
14853 | | */ |
14854 | | static int |
14855 | | xmlSchemaCheckSTPropsCorrect(xmlSchemaParserCtxtPtr ctxt, |
14856 | | xmlSchemaTypePtr type) |
14857 | 0 | { |
14858 | 0 | xmlSchemaTypePtr baseType = type->baseType; |
14859 | 0 | xmlChar *str = NULL; |
14860 | | |
14861 | | /* STATE: error funcs converted. */ |
14862 | | /* |
14863 | | * Schema Component Constraint: Simple Type Definition Properties Correct |
14864 | | * |
14865 | | * NOTE: This is somehow redundant, since we actually built a simple type |
14866 | | * to have all the needed information; this acts as an self test. |
14867 | | */ |
14868 | | /* Base type: If the datatype has been `derived` by `restriction` |
14869 | | * then the Simple Type Definition component from which it is `derived`, |
14870 | | * otherwise the Simple Type Definition for anySimpleType ($4.1.6). |
14871 | | */ |
14872 | 0 | if (baseType == NULL) { |
14873 | | /* |
14874 | | * TODO: Think about: "modulo the impact of Missing |
14875 | | * Sub-components ($5.3)." |
14876 | | */ |
14877 | 0 | xmlSchemaPCustomErr(ctxt, |
14878 | 0 | XML_SCHEMAP_ST_PROPS_CORRECT_1, |
14879 | 0 | WXS_BASIC_CAST type, NULL, |
14880 | 0 | "No base type existent", NULL); |
14881 | 0 | return (XML_SCHEMAP_ST_PROPS_CORRECT_1); |
14882 | |
|
14883 | 0 | } |
14884 | 0 | if (! WXS_IS_SIMPLE(baseType)) { |
14885 | 0 | xmlSchemaPCustomErr(ctxt, |
14886 | 0 | XML_SCHEMAP_ST_PROPS_CORRECT_1, |
14887 | 0 | WXS_BASIC_CAST type, NULL, |
14888 | 0 | "The base type '%s' is not a simple type", |
14889 | 0 | xmlSchemaGetComponentQName(&str, baseType)); |
14890 | 0 | FREE_AND_NULL(str) |
14891 | 0 | return (XML_SCHEMAP_ST_PROPS_CORRECT_1); |
14892 | 0 | } |
14893 | 0 | if ((WXS_IS_LIST(type) || WXS_IS_UNION(type)) && |
14894 | 0 | (WXS_IS_RESTRICTION(type) == 0) && |
14895 | 0 | ((! WXS_IS_ANY_SIMPLE_TYPE(baseType)) && |
14896 | 0 | (baseType->type != XML_SCHEMA_TYPE_SIMPLE))) { |
14897 | 0 | xmlSchemaPCustomErr(ctxt, |
14898 | 0 | XML_SCHEMAP_ST_PROPS_CORRECT_1, |
14899 | 0 | WXS_BASIC_CAST type, NULL, |
14900 | 0 | "A type, derived by list or union, must have " |
14901 | 0 | "the simple ur-type definition as base type, not '%s'", |
14902 | 0 | xmlSchemaGetComponentQName(&str, baseType)); |
14903 | 0 | FREE_AND_NULL(str) |
14904 | 0 | return (XML_SCHEMAP_ST_PROPS_CORRECT_1); |
14905 | 0 | } |
14906 | | /* |
14907 | | * Variety: One of {atomic, list, union}. |
14908 | | */ |
14909 | 0 | if ((! WXS_IS_ATOMIC(type)) && (! WXS_IS_UNION(type)) && |
14910 | 0 | (! WXS_IS_LIST(type))) { |
14911 | 0 | xmlSchemaPCustomErr(ctxt, |
14912 | 0 | XML_SCHEMAP_ST_PROPS_CORRECT_1, |
14913 | 0 | WXS_BASIC_CAST type, NULL, |
14914 | 0 | "The variety is absent", NULL); |
14915 | 0 | return (XML_SCHEMAP_ST_PROPS_CORRECT_1); |
14916 | 0 | } |
14917 | | /* TODO: Finish this. Hmm, is this finished? */ |
14918 | | |
14919 | | /* |
14920 | | * 3 The {final} of the {base type definition} must not contain restriction. |
14921 | | */ |
14922 | 0 | if (xmlSchemaTypeFinalContains(baseType, |
14923 | 0 | XML_SCHEMAS_TYPE_FINAL_RESTRICTION)) { |
14924 | 0 | xmlSchemaPCustomErr(ctxt, |
14925 | 0 | XML_SCHEMAP_ST_PROPS_CORRECT_3, |
14926 | 0 | WXS_BASIC_CAST type, NULL, |
14927 | 0 | "The 'final' of its base type '%s' must not contain " |
14928 | 0 | "'restriction'", |
14929 | 0 | xmlSchemaGetComponentQName(&str, baseType)); |
14930 | 0 | FREE_AND_NULL(str) |
14931 | 0 | return (XML_SCHEMAP_ST_PROPS_CORRECT_3); |
14932 | 0 | } |
14933 | | |
14934 | | /* |
14935 | | * 2 All simple type definitions must be derived ultimately from the `simple |
14936 | | * ur-type definition` (so circular definitions are disallowed). That is, it |
14937 | | * must be possible to reach a built-in primitive datatype or the `simple |
14938 | | * ur-type definition` by repeatedly following the {base type definition}. |
14939 | | * |
14940 | | * NOTE: this is done in xmlSchemaCheckTypeDefCircular(). |
14941 | | */ |
14942 | 0 | return (0); |
14943 | 0 | } |
14944 | | |
14945 | | /** |
14946 | | * Schema Component Constraint: |
14947 | | * Derivation Valid (Restriction, Simple) (cos-st-restricts) |
14948 | | |
14949 | | * Checks if the given `type` (simpleType) is derived validly by restriction. |
14950 | | * STATUS: |
14951 | | * |
14952 | | * @param pctxt the schema parser context |
14953 | | * @param type the simple type definition |
14954 | | * @returns -1 on internal errors, 0 if the type is validly derived, |
14955 | | * a positive error code otherwise. |
14956 | | */ |
14957 | | static int |
14958 | | xmlSchemaCheckCOSSTRestricts(xmlSchemaParserCtxtPtr pctxt, |
14959 | | xmlSchemaTypePtr type) |
14960 | 0 | { |
14961 | 0 | xmlChar *str = NULL; |
14962 | |
|
14963 | 0 | if (type->type != XML_SCHEMA_TYPE_SIMPLE) { |
14964 | 0 | PERROR_INT("xmlSchemaCheckCOSSTRestricts", |
14965 | 0 | "given type is not a user-derived simpleType"); |
14966 | 0 | return (-1); |
14967 | 0 | } |
14968 | | |
14969 | 0 | if (WXS_IS_ATOMIC(type)) { |
14970 | 0 | xmlSchemaTypePtr primitive; |
14971 | | /* |
14972 | | * 1.1 The {base type definition} must be an atomic simple |
14973 | | * type definition or a built-in primitive datatype. |
14974 | | */ |
14975 | 0 | if (! WXS_IS_ATOMIC(type->baseType)) { |
14976 | 0 | xmlSchemaPCustomErr(pctxt, |
14977 | 0 | XML_SCHEMAP_COS_ST_RESTRICTS_1_1, |
14978 | 0 | WXS_BASIC_CAST type, NULL, |
14979 | 0 | "The base type '%s' is not an atomic simple type", |
14980 | 0 | xmlSchemaGetComponentQName(&str, type->baseType)); |
14981 | 0 | FREE_AND_NULL(str) |
14982 | 0 | return (XML_SCHEMAP_COS_ST_RESTRICTS_1_1); |
14983 | 0 | } |
14984 | | /* 1.2 The {final} of the {base type definition} must not contain |
14985 | | * restriction. |
14986 | | */ |
14987 | | /* OPTIMIZE TODO : This is already done in xmlSchemaCheckStPropsCorrect */ |
14988 | 0 | if (xmlSchemaTypeFinalContains(type->baseType, |
14989 | 0 | XML_SCHEMAS_TYPE_FINAL_RESTRICTION)) { |
14990 | 0 | xmlSchemaPCustomErr(pctxt, |
14991 | 0 | XML_SCHEMAP_COS_ST_RESTRICTS_1_2, |
14992 | 0 | WXS_BASIC_CAST type, NULL, |
14993 | 0 | "The final of its base type '%s' must not contain 'restriction'", |
14994 | 0 | xmlSchemaGetComponentQName(&str, type->baseType)); |
14995 | 0 | FREE_AND_NULL(str) |
14996 | 0 | return (XML_SCHEMAP_COS_ST_RESTRICTS_1_2); |
14997 | 0 | } |
14998 | | |
14999 | | /* |
15000 | | * 1.3.1 DF must be an allowed constraining facet for the {primitive |
15001 | | * type definition}, as specified in the appropriate subsection of 3.2 |
15002 | | * Primitive datatypes. |
15003 | | */ |
15004 | 0 | if (type->facets != NULL) { |
15005 | 0 | xmlSchemaFacetPtr facet; |
15006 | 0 | int ok = 1; |
15007 | |
|
15008 | 0 | primitive = xmlSchemaGetPrimitiveType(type); |
15009 | 0 | if (primitive == NULL) { |
15010 | 0 | PERROR_INT("xmlSchemaCheckCOSSTRestricts", |
15011 | 0 | "failed to get primitive type"); |
15012 | 0 | return (-1); |
15013 | 0 | } |
15014 | 0 | facet = type->facets; |
15015 | 0 | do { |
15016 | 0 | if (xmlSchemaIsBuiltInTypeFacet(primitive, facet->type) == 0) { |
15017 | 0 | ok = 0; |
15018 | 0 | xmlSchemaPIllegalFacetAtomicErr(pctxt, |
15019 | 0 | XML_SCHEMAP_COS_ST_RESTRICTS_1_3_1, |
15020 | 0 | type, primitive, facet); |
15021 | 0 | } |
15022 | 0 | facet = facet->next; |
15023 | 0 | } while (facet != NULL); |
15024 | 0 | if (ok == 0) |
15025 | 0 | return (XML_SCHEMAP_COS_ST_RESTRICTS_1_3_1); |
15026 | 0 | } |
15027 | | /* |
15028 | | * SPEC (1.3.2) "If there is a facet of the same kind in the {facets} |
15029 | | * of the {base type definition} (call this BF),then the DF's {value} |
15030 | | * must be a valid restriction of BF's {value} as defined in |
15031 | | * [XML Schemas: Datatypes]." |
15032 | | * |
15033 | | * NOTE (1.3.2) Facet derivation constraints are currently handled in |
15034 | | * xmlSchemaDeriveAndValidateFacets() |
15035 | | */ |
15036 | 0 | } else if (WXS_IS_LIST(type)) { |
15037 | 0 | xmlSchemaTypePtr itemType = NULL; |
15038 | |
|
15039 | 0 | itemType = type->subtypes; |
15040 | 0 | if ((itemType == NULL) || (! WXS_IS_SIMPLE(itemType))) { |
15041 | 0 | PERROR_INT("xmlSchemaCheckCOSSTRestricts", |
15042 | 0 | "failed to evaluate the item type"); |
15043 | 0 | return (-1); |
15044 | 0 | } |
15045 | 0 | if (WXS_IS_TYPE_NOT_FIXED(itemType)) |
15046 | 0 | xmlSchemaTypeFixup(itemType, ACTXT_CAST pctxt); |
15047 | | /* |
15048 | | * 2.1 The {item type definition} must have a {variety} of atomic or |
15049 | | * union (in which case all the {member type definitions} |
15050 | | * must be atomic). |
15051 | | */ |
15052 | 0 | if ((! WXS_IS_ATOMIC(itemType)) && |
15053 | 0 | (! WXS_IS_UNION(itemType))) { |
15054 | 0 | xmlSchemaPCustomErr(pctxt, |
15055 | 0 | XML_SCHEMAP_COS_ST_RESTRICTS_2_1, |
15056 | 0 | WXS_BASIC_CAST type, NULL, |
15057 | 0 | "The item type '%s' does not have a variety of atomic or union", |
15058 | 0 | xmlSchemaGetComponentQName(&str, itemType)); |
15059 | 0 | FREE_AND_NULL(str) |
15060 | 0 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_1); |
15061 | 0 | } else if (WXS_IS_UNION(itemType)) { |
15062 | 0 | xmlSchemaTypeLinkPtr member; |
15063 | |
|
15064 | 0 | member = itemType->memberTypes; |
15065 | 0 | while (member != NULL) { |
15066 | 0 | if (! WXS_IS_ATOMIC(member->type)) { |
15067 | 0 | xmlSchemaPCustomErr(pctxt, |
15068 | 0 | XML_SCHEMAP_COS_ST_RESTRICTS_2_1, |
15069 | 0 | WXS_BASIC_CAST type, NULL, |
15070 | 0 | "The item type is a union type, but the " |
15071 | 0 | "member type '%s' of this item type is not atomic", |
15072 | 0 | xmlSchemaGetComponentQName(&str, member->type)); |
15073 | 0 | FREE_AND_NULL(str) |
15074 | 0 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_1); |
15075 | 0 | } |
15076 | 0 | member = member->next; |
15077 | 0 | } |
15078 | 0 | } |
15079 | | |
15080 | 0 | if (WXS_IS_ANY_SIMPLE_TYPE(type->baseType)) { |
15081 | 0 | xmlSchemaFacetPtr facet; |
15082 | | /* |
15083 | | * This is the case if we have: <simpleType><list .. |
15084 | | */ |
15085 | | /* |
15086 | | * 2.3.1 |
15087 | | * 2.3.1.1 The {final} of the {item type definition} must not |
15088 | | * contain list. |
15089 | | */ |
15090 | 0 | if (xmlSchemaTypeFinalContains(itemType, |
15091 | 0 | XML_SCHEMAS_TYPE_FINAL_LIST)) { |
15092 | 0 | xmlSchemaPCustomErr(pctxt, |
15093 | 0 | XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_1, |
15094 | 0 | WXS_BASIC_CAST type, NULL, |
15095 | 0 | "The final of its item type '%s' must not contain 'list'", |
15096 | 0 | xmlSchemaGetComponentQName(&str, itemType)); |
15097 | 0 | FREE_AND_NULL(str) |
15098 | 0 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_1); |
15099 | 0 | } |
15100 | | /* |
15101 | | * 2.3.1.2 The {facets} must only contain the whiteSpace |
15102 | | * facet component. |
15103 | | * OPTIMIZE TODO: the S4S already disallows any facet |
15104 | | * to be specified. |
15105 | | */ |
15106 | 0 | if (type->facets != NULL) { |
15107 | 0 | facet = type->facets; |
15108 | 0 | do { |
15109 | 0 | if (facet->type != XML_SCHEMA_FACET_WHITESPACE) { |
15110 | 0 | xmlSchemaPIllegalFacetListUnionErr(pctxt, |
15111 | 0 | XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_2, |
15112 | 0 | type, facet); |
15113 | 0 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_2); |
15114 | 0 | } |
15115 | 0 | facet = facet->next; |
15116 | 0 | } while (facet != NULL); |
15117 | 0 | } |
15118 | | /* |
15119 | | * MAYBE TODO: (Hmm, not really) Datatypes states: |
15120 | | * A `list` datatype can be `derived` from an `atomic` datatype |
15121 | | * whose `lexical space` allows space (such as string or anyURI)or |
15122 | | * a `union` datatype any of whose {member type definitions}'s |
15123 | | * `lexical space` allows space. |
15124 | | */ |
15125 | 0 | } else { |
15126 | | /* |
15127 | | * This is the case if we have: <simpleType><restriction ... |
15128 | | * I.e. the variety of "list" is inherited. |
15129 | | */ |
15130 | | /* |
15131 | | * 2.3.2 |
15132 | | * 2.3.2.1 The {base type definition} must have a {variety} of list. |
15133 | | */ |
15134 | 0 | if (! WXS_IS_LIST(type->baseType)) { |
15135 | 0 | xmlSchemaPCustomErr(pctxt, |
15136 | 0 | XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_1, |
15137 | 0 | WXS_BASIC_CAST type, NULL, |
15138 | 0 | "The base type '%s' must be a list type", |
15139 | 0 | xmlSchemaGetComponentQName(&str, type->baseType)); |
15140 | 0 | FREE_AND_NULL(str) |
15141 | 0 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_1); |
15142 | 0 | } |
15143 | | /* |
15144 | | * 2.3.2.2 The {final} of the {base type definition} must not |
15145 | | * contain restriction. |
15146 | | */ |
15147 | 0 | if (xmlSchemaTypeFinalContains(type->baseType, |
15148 | 0 | XML_SCHEMAS_TYPE_FINAL_RESTRICTION)) { |
15149 | 0 | xmlSchemaPCustomErr(pctxt, |
15150 | 0 | XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_2, |
15151 | 0 | WXS_BASIC_CAST type, NULL, |
15152 | 0 | "The 'final' of the base type '%s' must not contain 'restriction'", |
15153 | 0 | xmlSchemaGetComponentQName(&str, type->baseType)); |
15154 | 0 | FREE_AND_NULL(str) |
15155 | 0 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_2); |
15156 | 0 | } |
15157 | | /* |
15158 | | * 2.3.2.3 The {item type definition} must be validly derived |
15159 | | * from the {base type definition}'s {item type definition} given |
15160 | | * the empty set, as defined in Type Derivation OK (Simple) ($3.14.6). |
15161 | | */ |
15162 | 0 | { |
15163 | 0 | xmlSchemaTypePtr baseItemType; |
15164 | |
|
15165 | 0 | baseItemType = type->baseType->subtypes; |
15166 | 0 | if ((baseItemType == NULL) || (! WXS_IS_SIMPLE(baseItemType))) { |
15167 | 0 | PERROR_INT("xmlSchemaCheckCOSSTRestricts", |
15168 | 0 | "failed to eval the item type of a base type"); |
15169 | 0 | return (-1); |
15170 | 0 | } |
15171 | 0 | if ((itemType != baseItemType) && |
15172 | 0 | (xmlSchemaCheckCOSSTDerivedOK(ACTXT_CAST pctxt, itemType, |
15173 | 0 | baseItemType, 0) != 0)) { |
15174 | 0 | xmlChar *strBIT = NULL, *strBT = NULL; |
15175 | 0 | xmlSchemaPCustomErrExt(pctxt, |
15176 | 0 | XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_3, |
15177 | 0 | WXS_BASIC_CAST type, NULL, |
15178 | 0 | "The item type '%s' is not validly derived from " |
15179 | 0 | "the item type '%s' of the base type '%s'", |
15180 | 0 | xmlSchemaGetComponentQName(&str, itemType), |
15181 | 0 | xmlSchemaGetComponentQName(&strBIT, baseItemType), |
15182 | 0 | xmlSchemaGetComponentQName(&strBT, type->baseType)); |
15183 | |
|
15184 | 0 | FREE_AND_NULL(str) |
15185 | 0 | FREE_AND_NULL(strBIT) |
15186 | 0 | FREE_AND_NULL(strBT) |
15187 | 0 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_3); |
15188 | 0 | } |
15189 | 0 | } |
15190 | | |
15191 | 0 | if (type->facets != NULL) { |
15192 | 0 | xmlSchemaFacetPtr facet; |
15193 | 0 | int ok = 1; |
15194 | | /* |
15195 | | * 2.3.2.4 Only length, minLength, maxLength, whiteSpace, pattern |
15196 | | * and enumeration facet components are allowed among the {facets}. |
15197 | | */ |
15198 | 0 | facet = type->facets; |
15199 | 0 | do { |
15200 | 0 | switch (facet->type) { |
15201 | 0 | case XML_SCHEMA_FACET_LENGTH: |
15202 | 0 | case XML_SCHEMA_FACET_MINLENGTH: |
15203 | 0 | case XML_SCHEMA_FACET_MAXLENGTH: |
15204 | 0 | case XML_SCHEMA_FACET_WHITESPACE: |
15205 | | /* |
15206 | | * TODO: 2.5.1.2 List datatypes |
15207 | | * The value of `whiteSpace` is fixed to the value collapse. |
15208 | | */ |
15209 | 0 | case XML_SCHEMA_FACET_PATTERN: |
15210 | 0 | case XML_SCHEMA_FACET_ENUMERATION: |
15211 | 0 | break; |
15212 | 0 | default: { |
15213 | 0 | xmlSchemaPIllegalFacetListUnionErr(pctxt, |
15214 | 0 | XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_4, |
15215 | 0 | type, facet); |
15216 | | /* |
15217 | | * We could return, but it's nicer to report all |
15218 | | * invalid facets. |
15219 | | */ |
15220 | 0 | ok = 0; |
15221 | 0 | } |
15222 | 0 | } |
15223 | 0 | facet = facet->next; |
15224 | 0 | } while (facet != NULL); |
15225 | 0 | if (ok == 0) |
15226 | 0 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_4); |
15227 | | /* |
15228 | | * SPEC (2.3.2.5) (same as 1.3.2) |
15229 | | * |
15230 | | * NOTE (2.3.2.5) This is currently done in |
15231 | | * xmlSchemaDeriveAndValidateFacets() |
15232 | | */ |
15233 | 0 | } |
15234 | 0 | } |
15235 | 0 | } else if (WXS_IS_UNION(type)) { |
15236 | | /* |
15237 | | * 3.1 The {member type definitions} must all have {variety} of |
15238 | | * atomic or list. |
15239 | | */ |
15240 | 0 | xmlSchemaTypeLinkPtr member; |
15241 | |
|
15242 | 0 | member = type->memberTypes; |
15243 | 0 | while (member != NULL) { |
15244 | 0 | if (WXS_IS_TYPE_NOT_FIXED(member->type)) |
15245 | 0 | xmlSchemaTypeFixup(member->type, ACTXT_CAST pctxt); |
15246 | |
|
15247 | 0 | if ((! WXS_IS_ATOMIC(member->type)) && |
15248 | 0 | (! WXS_IS_LIST(member->type))) { |
15249 | 0 | xmlSchemaPCustomErr(pctxt, |
15250 | 0 | XML_SCHEMAP_COS_ST_RESTRICTS_3_1, |
15251 | 0 | WXS_BASIC_CAST type, NULL, |
15252 | 0 | "The member type '%s' is neither an atomic, nor a list type", |
15253 | 0 | xmlSchemaGetComponentQName(&str, member->type)); |
15254 | 0 | FREE_AND_NULL(str) |
15255 | 0 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_1); |
15256 | 0 | } |
15257 | 0 | member = member->next; |
15258 | 0 | } |
15259 | | /* |
15260 | | * 3.3.1 If the {base type definition} is the `simple ur-type |
15261 | | * definition` |
15262 | | */ |
15263 | 0 | if (type->baseType->builtInType == XML_SCHEMAS_ANYSIMPLETYPE) { |
15264 | | /* |
15265 | | * 3.3.1.1 All of the {member type definitions} must have a |
15266 | | * {final} which does not contain union. |
15267 | | */ |
15268 | 0 | member = type->memberTypes; |
15269 | 0 | while (member != NULL) { |
15270 | 0 | if (xmlSchemaTypeFinalContains(member->type, |
15271 | 0 | XML_SCHEMAS_TYPE_FINAL_UNION)) { |
15272 | 0 | xmlSchemaPCustomErr(pctxt, |
15273 | 0 | XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1, |
15274 | 0 | WXS_BASIC_CAST type, NULL, |
15275 | 0 | "The 'final' of member type '%s' contains 'union'", |
15276 | 0 | xmlSchemaGetComponentQName(&str, member->type)); |
15277 | 0 | FREE_AND_NULL(str) |
15278 | 0 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1); |
15279 | 0 | } |
15280 | 0 | member = member->next; |
15281 | 0 | } |
15282 | | /* |
15283 | | * 3.3.1.2 The {facets} must be empty. |
15284 | | */ |
15285 | 0 | if (type->facetSet != NULL) { |
15286 | 0 | xmlSchemaPCustomErr(pctxt, |
15287 | 0 | XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1_2, |
15288 | 0 | WXS_BASIC_CAST type, NULL, |
15289 | 0 | "No facets allowed", NULL); |
15290 | 0 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1_2); |
15291 | 0 | } |
15292 | 0 | } else { |
15293 | | /* |
15294 | | * 3.3.2.1 The {base type definition} must have a {variety} of union. |
15295 | | * I.e. the variety of "list" is inherited. |
15296 | | */ |
15297 | 0 | if (! WXS_IS_UNION(type->baseType)) { |
15298 | 0 | xmlSchemaPCustomErr(pctxt, |
15299 | 0 | XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_1, |
15300 | 0 | WXS_BASIC_CAST type, NULL, |
15301 | 0 | "The base type '%s' is not a union type", |
15302 | 0 | xmlSchemaGetComponentQName(&str, type->baseType)); |
15303 | 0 | FREE_AND_NULL(str) |
15304 | 0 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_1); |
15305 | 0 | } |
15306 | | /* |
15307 | | * 3.3.2.2 The {final} of the {base type definition} must not contain restriction. |
15308 | | */ |
15309 | 0 | if (xmlSchemaTypeFinalContains(type->baseType, |
15310 | 0 | XML_SCHEMAS_TYPE_FINAL_RESTRICTION)) { |
15311 | 0 | xmlSchemaPCustomErr(pctxt, |
15312 | 0 | XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_2, |
15313 | 0 | WXS_BASIC_CAST type, NULL, |
15314 | 0 | "The 'final' of its base type '%s' must not contain 'restriction'", |
15315 | 0 | xmlSchemaGetComponentQName(&str, type->baseType)); |
15316 | 0 | FREE_AND_NULL(str) |
15317 | 0 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_2); |
15318 | 0 | } |
15319 | | /* |
15320 | | * 3.3.2.3 The {member type definitions}, in order, must be validly |
15321 | | * derived from the corresponding type definitions in the {base |
15322 | | * type definition}'s {member type definitions} given the empty set, |
15323 | | * as defined in Type Derivation OK (Simple) ($3.14.6). |
15324 | | */ |
15325 | 0 | { |
15326 | 0 | xmlSchemaTypeLinkPtr baseMember; |
15327 | | |
15328 | | /* |
15329 | | * OPTIMIZE: if the type is restricting, it has no local defined |
15330 | | * member types and inherits the member types of the base type; |
15331 | | * thus a check for equality can be skipped. |
15332 | | */ |
15333 | | /* |
15334 | | * Even worse: I cannot see a scenario where a restricting |
15335 | | * union simple type can have other member types as the member |
15336 | | * types of it's base type. This check seems not necessary with |
15337 | | * respect to the derivation process in libxml2. |
15338 | | * But necessary if constructing types with an API. |
15339 | | */ |
15340 | 0 | if (type->memberTypes != NULL) { |
15341 | 0 | member = type->memberTypes; |
15342 | 0 | baseMember = xmlSchemaGetUnionSimpleTypeMemberTypes(type->baseType); |
15343 | 0 | if ((member == NULL) && (baseMember != NULL)) { |
15344 | 0 | PERROR_INT("xmlSchemaCheckCOSSTRestricts", |
15345 | 0 | "different number of member types in base"); |
15346 | 0 | } |
15347 | 0 | while (member != NULL) { |
15348 | 0 | if (baseMember == NULL) { |
15349 | 0 | PERROR_INT("xmlSchemaCheckCOSSTRestricts", |
15350 | 0 | "different number of member types in base"); |
15351 | 0 | } else if ((member->type != baseMember->type) && |
15352 | 0 | (xmlSchemaCheckCOSSTDerivedOK(ACTXT_CAST pctxt, |
15353 | 0 | member->type, baseMember->type, 0) != 0)) { |
15354 | 0 | xmlChar *strBMT = NULL, *strBT = NULL; |
15355 | |
|
15356 | 0 | xmlSchemaPCustomErrExt(pctxt, |
15357 | 0 | XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_3, |
15358 | 0 | WXS_BASIC_CAST type, NULL, |
15359 | 0 | "The member type %s is not validly " |
15360 | 0 | "derived from its corresponding member " |
15361 | 0 | "type %s of the base type %s", |
15362 | 0 | xmlSchemaGetComponentQName(&str, member->type), |
15363 | 0 | xmlSchemaGetComponentQName(&strBMT, baseMember->type), |
15364 | 0 | xmlSchemaGetComponentQName(&strBT, type->baseType)); |
15365 | 0 | FREE_AND_NULL(str) |
15366 | 0 | FREE_AND_NULL(strBMT) |
15367 | 0 | FREE_AND_NULL(strBT) |
15368 | 0 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_3); |
15369 | 0 | } |
15370 | 0 | member = member->next; |
15371 | 0 | if (baseMember != NULL) |
15372 | 0 | baseMember = baseMember->next; |
15373 | 0 | } |
15374 | 0 | } |
15375 | 0 | } |
15376 | | /* |
15377 | | * 3.3.2.4 Only pattern and enumeration facet components are |
15378 | | * allowed among the {facets}. |
15379 | | */ |
15380 | 0 | if (type->facets != NULL) { |
15381 | 0 | xmlSchemaFacetPtr facet; |
15382 | 0 | int ok = 1; |
15383 | |
|
15384 | 0 | facet = type->facets; |
15385 | 0 | do { |
15386 | 0 | if ((facet->type != XML_SCHEMA_FACET_PATTERN) && |
15387 | 0 | (facet->type != XML_SCHEMA_FACET_ENUMERATION)) { |
15388 | 0 | xmlSchemaPIllegalFacetListUnionErr(pctxt, |
15389 | 0 | XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_4, |
15390 | 0 | type, facet); |
15391 | 0 | ok = 0; |
15392 | 0 | } |
15393 | 0 | facet = facet->next; |
15394 | 0 | } while (facet != NULL); |
15395 | 0 | if (ok == 0) |
15396 | 0 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_4); |
15397 | |
|
15398 | 0 | } |
15399 | | /* |
15400 | | * SPEC (3.3.2.5) (same as 1.3.2) |
15401 | | * |
15402 | | * NOTE (3.3.2.5) This is currently done in |
15403 | | * xmlSchemaDeriveAndValidateFacets() |
15404 | | */ |
15405 | 0 | } |
15406 | 0 | } |
15407 | | |
15408 | 0 | return (0); |
15409 | 0 | } |
15410 | | |
15411 | | #if 0 |
15412 | | /** |
15413 | | * Checks crc-simple-type constraints. |
15414 | | * |
15415 | | * @param ctxt the schema parser context |
15416 | | * @param type the simple type definition |
15417 | | * @returns 0 if the constraints are satisfied, |
15418 | | * if not a positive error code and -1 on internal |
15419 | | * errors. |
15420 | | */ |
15421 | | static int |
15422 | | xmlSchemaCheckSRCSimpleType(xmlSchemaParserCtxtPtr ctxt, |
15423 | | xmlSchemaTypePtr type) |
15424 | | { |
15425 | | /* |
15426 | | * src-simple-type.1 The corresponding simple type definition, if any, |
15427 | | * must satisfy the conditions set out in Constraints on Simple Type |
15428 | | * Definition Schema Components ($3.14.6). |
15429 | | */ |
15430 | | if (WXS_IS_RESTRICTION(type)) { |
15431 | | /* |
15432 | | * src-simple-type.2 "If the <restriction> alternative is chosen, |
15433 | | * either it must have a base [attribute] or a <simpleType> among its |
15434 | | * [children], but not both." |
15435 | | * NOTE: This is checked in the parse function of <restriction>. |
15436 | | */ |
15437 | | /* |
15438 | | * |
15439 | | */ |
15440 | | } else if (WXS_IS_LIST(type)) { |
15441 | | /* src-simple-type.3 "If the <list> alternative is chosen, either it must have |
15442 | | * an itemType [attribute] or a <simpleType> among its [children], |
15443 | | * but not both." |
15444 | | * |
15445 | | * NOTE: This is checked in the parse function of <list>. |
15446 | | */ |
15447 | | } else if (WXS_IS_UNION(type)) { |
15448 | | /* |
15449 | | * src-simple-type.4 is checked in xmlSchemaCheckUnionTypeDefCircular(). |
15450 | | */ |
15451 | | } |
15452 | | return (0); |
15453 | | } |
15454 | | #endif |
15455 | | |
15456 | | static int |
15457 | | xmlSchemaCreateVCtxtOnPCtxt(xmlSchemaParserCtxtPtr ctxt) |
15458 | 0 | { |
15459 | 0 | if (ctxt->vctxt == NULL) { |
15460 | 0 | ctxt->vctxt = xmlSchemaNewValidCtxt(NULL); |
15461 | 0 | if (ctxt->vctxt == NULL) { |
15462 | 0 | xmlSchemaPErr(ctxt, NULL, |
15463 | 0 | XML_SCHEMAP_INTERNAL, |
15464 | 0 | "Internal error: xmlSchemaCreateVCtxtOnPCtxt, " |
15465 | 0 | "failed to create a temp. validation context.\n", |
15466 | 0 | NULL, NULL); |
15467 | 0 | return (-1); |
15468 | 0 | } |
15469 | | /* TODO: Pass user data. */ |
15470 | 0 | xmlSchemaSetValidErrors(ctxt->vctxt, |
15471 | 0 | ctxt->error, ctxt->warning, ctxt->errCtxt); |
15472 | 0 | xmlSchemaSetValidStructuredErrors(ctxt->vctxt, |
15473 | 0 | ctxt->serror, ctxt->errCtxt); |
15474 | 0 | } |
15475 | 0 | return (0); |
15476 | 0 | } |
15477 | | |
15478 | | static int |
15479 | | xmlSchemaVCheckCVCSimpleType(xmlSchemaAbstractCtxtPtr actxt, |
15480 | | xmlNodePtr node, |
15481 | | xmlSchemaTypePtr type, |
15482 | | const xmlChar *value, |
15483 | | xmlSchemaValPtr *retVal, |
15484 | | int fireErrors, |
15485 | | int normalize, |
15486 | | int isNormalized); |
15487 | | |
15488 | | /** |
15489 | | * Schema Component Constraint: Element Default Valid (Immediate) |
15490 | | * (cos-valid-default) |
15491 | | * This will be used by the parser only. For the validator there's |
15492 | | * an other version. |
15493 | | * |
15494 | | * @param pctxt the schema parser context |
15495 | | * @param node an optional node (the holder of the value) |
15496 | | * @param type the simple type definition |
15497 | | * @param value the default value |
15498 | | * @param val resulting value |
15499 | | * @returns 0 if the constraints are satisfied, |
15500 | | * if not, a positive error code and -1 on internal |
15501 | | * errors. |
15502 | | */ |
15503 | | static int |
15504 | | xmlSchemaParseCheckCOSValidDefault(xmlSchemaParserCtxtPtr pctxt, |
15505 | | xmlNodePtr node, |
15506 | | xmlSchemaTypePtr type, |
15507 | | const xmlChar *value, |
15508 | | xmlSchemaValPtr *val) |
15509 | 0 | { |
15510 | 0 | int ret = 0; |
15511 | | |
15512 | | /* |
15513 | | * cos-valid-default: |
15514 | | * Schema Component Constraint: Element Default Valid (Immediate) |
15515 | | * For a string to be a valid default with respect to a type |
15516 | | * definition the appropriate case among the following must be true: |
15517 | | */ |
15518 | 0 | if WXS_IS_COMPLEX(type) { |
15519 | | /* |
15520 | | * Complex type. |
15521 | | * |
15522 | | * SPEC (2.1) "its {content type} must be a simple type definition |
15523 | | * or mixed." |
15524 | | * SPEC (2.2.2) "If the {content type} is mixed, then the {content |
15525 | | * type}'s particle must be `emptiable` as defined by |
15526 | | * Particle Emptiable ($3.9.6)." |
15527 | | */ |
15528 | 0 | if ((! WXS_HAS_SIMPLE_CONTENT(type)) && |
15529 | 0 | ((! WXS_HAS_MIXED_CONTENT(type)) || (! WXS_EMPTIABLE(type)))) { |
15530 | | /* NOTE that this covers (2.2.2) as well. */ |
15531 | 0 | xmlSchemaPCustomErr(pctxt, |
15532 | 0 | XML_SCHEMAP_COS_VALID_DEFAULT_2_1, |
15533 | 0 | WXS_BASIC_CAST type, type->node, |
15534 | 0 | "For a string to be a valid default, the type definition " |
15535 | 0 | "must be a simple type or a complex type with mixed content " |
15536 | 0 | "and a particle emptiable", NULL); |
15537 | 0 | return(XML_SCHEMAP_COS_VALID_DEFAULT_2_1); |
15538 | 0 | } |
15539 | 0 | } |
15540 | | /* |
15541 | | * 1 If the type definition is a simple type definition, then the string |
15542 | | * must be `valid` with respect to that definition as defined by String |
15543 | | * Valid ($3.14.4). |
15544 | | * |
15545 | | * AND |
15546 | | * |
15547 | | * 2.2.1 If the {content type} is a simple type definition, then the |
15548 | | * string must be `valid` with respect to that simple type definition |
15549 | | * as defined by String Valid ($3.14.4). |
15550 | | */ |
15551 | 0 | if (WXS_IS_SIMPLE(type)) |
15552 | 0 | ret = xmlSchemaVCheckCVCSimpleType(ACTXT_CAST pctxt, node, |
15553 | 0 | type, value, val, 1, 1, 0); |
15554 | 0 | else if (WXS_HAS_SIMPLE_CONTENT(type)) |
15555 | 0 | ret = xmlSchemaVCheckCVCSimpleType(ACTXT_CAST pctxt, node, |
15556 | 0 | type->contentTypeDef, value, val, 1, 1, 0); |
15557 | 0 | else |
15558 | 0 | return (ret); |
15559 | | |
15560 | 0 | if (ret < 0) { |
15561 | 0 | PERROR_INT("xmlSchemaParseCheckCOSValidDefault", |
15562 | 0 | "calling xmlSchemaVCheckCVCSimpleType()"); |
15563 | 0 | } |
15564 | |
|
15565 | 0 | return (ret); |
15566 | 0 | } |
15567 | | |
15568 | | /** |
15569 | | * (4.6) Constraints on Complex Type Definition Schema Components |
15570 | | * Schema Component Constraint: |
15571 | | * Complex Type Definition Properties Correct (ct-props-correct) |
15572 | | * STATUS: (seems) complete |
15573 | | * |
15574 | | * @param pctxt the schema parser context |
15575 | | * @param type the complex type definition |
15576 | | * @returns 0 if the constraints are satisfied, a positive |
15577 | | * error code if not and -1 if an internal error occurred. |
15578 | | */ |
15579 | | static int |
15580 | | xmlSchemaCheckCTPropsCorrect(xmlSchemaParserCtxtPtr pctxt, |
15581 | | xmlSchemaTypePtr type) |
15582 | 0 | { |
15583 | | /* |
15584 | | * TODO: Correct the error code; XML_SCHEMAP_SRC_CT_1 is used temporarily. |
15585 | | * |
15586 | | * SPEC (1) "The values of the properties of a complex type definition must |
15587 | | * be as described in the property tableau in The Complex Type Definition |
15588 | | * Schema Component ($3.4.1), modulo the impact of Missing |
15589 | | * Sub-components ($5.3)." |
15590 | | */ |
15591 | 0 | if ((type->baseType != NULL) && |
15592 | 0 | (WXS_IS_SIMPLE(type->baseType)) && |
15593 | 0 | (WXS_IS_EXTENSION(type) == 0)) { |
15594 | | /* |
15595 | | * SPEC (2) "If the {base type definition} is a simple type definition, |
15596 | | * the {derivation method} must be extension." |
15597 | | */ |
15598 | 0 | xmlSchemaCustomErr(ACTXT_CAST pctxt, |
15599 | 0 | XML_SCHEMAP_SRC_CT_1, |
15600 | 0 | NULL, WXS_BASIC_CAST type, |
15601 | 0 | "If the base type is a simple type, the derivation method must be " |
15602 | 0 | "'extension'", NULL, NULL); |
15603 | 0 | return (XML_SCHEMAP_SRC_CT_1); |
15604 | 0 | } |
15605 | | /* |
15606 | | * SPEC (3) "Circular definitions are disallowed, except for the `ur-type |
15607 | | * definition`. That is, it must be possible to reach the `ur-type |
15608 | | * definition` by repeatedly following the {base type definition}." |
15609 | | * |
15610 | | * NOTE (3) is done in xmlSchemaCheckTypeDefCircular(). |
15611 | | */ |
15612 | | /* |
15613 | | * NOTE that (4) and (5) need the following: |
15614 | | * - attribute uses need to be already inherited (apply attr. prohibitions) |
15615 | | * - attribute group references need to be expanded already |
15616 | | * - simple types need to be typefixed already |
15617 | | */ |
15618 | 0 | if (type->attrUses && |
15619 | 0 | (((xmlSchemaItemListPtr) type->attrUses)->nbItems > 1)) |
15620 | 0 | { |
15621 | 0 | xmlSchemaItemListPtr uses = (xmlSchemaItemListPtr) type->attrUses; |
15622 | 0 | xmlSchemaAttributeUsePtr use, tmp; |
15623 | 0 | int i, j, hasId = 0; |
15624 | |
|
15625 | 0 | for (i = uses->nbItems -1; i >= 0; i--) { |
15626 | 0 | use = uses->items[i]; |
15627 | | |
15628 | | /* |
15629 | | * SPEC ct-props-correct |
15630 | | * (4) "Two distinct attribute declarations in the |
15631 | | * {attribute uses} must not have identical {name}s and |
15632 | | * {target namespace}s." |
15633 | | */ |
15634 | 0 | if (i > 0) { |
15635 | 0 | for (j = i -1; j >= 0; j--) { |
15636 | 0 | tmp = uses->items[j]; |
15637 | 0 | if ((WXS_ATTRUSE_DECL_NAME(use) == |
15638 | 0 | WXS_ATTRUSE_DECL_NAME(tmp)) && |
15639 | 0 | (WXS_ATTRUSE_DECL_TNS(use) == |
15640 | 0 | WXS_ATTRUSE_DECL_TNS(tmp))) |
15641 | 0 | { |
15642 | 0 | xmlChar *str = NULL; |
15643 | |
|
15644 | 0 | xmlSchemaCustomErr(ACTXT_CAST pctxt, |
15645 | 0 | XML_SCHEMAP_AG_PROPS_CORRECT, |
15646 | 0 | NULL, WXS_BASIC_CAST type, |
15647 | 0 | "Duplicate %s", |
15648 | 0 | xmlSchemaGetComponentDesignation(&str, use), |
15649 | 0 | NULL); |
15650 | 0 | FREE_AND_NULL(str); |
15651 | | /* |
15652 | | * Remove the duplicate. |
15653 | | */ |
15654 | 0 | if (xmlSchemaItemListRemove(uses, i) == -1) |
15655 | 0 | goto exit_failure; |
15656 | 0 | goto next_use; |
15657 | 0 | } |
15658 | 0 | } |
15659 | 0 | } |
15660 | | /* |
15661 | | * SPEC ct-props-correct |
15662 | | * (5) "Two distinct attribute declarations in the |
15663 | | * {attribute uses} must not have {type definition}s which |
15664 | | * are or are derived from ID." |
15665 | | */ |
15666 | 0 | if (WXS_ATTRUSE_TYPEDEF(use) != NULL) { |
15667 | 0 | if (xmlSchemaIsDerivedFromBuiltInType( |
15668 | 0 | WXS_ATTRUSE_TYPEDEF(use), XML_SCHEMAS_ID)) |
15669 | 0 | { |
15670 | 0 | if (hasId) { |
15671 | 0 | xmlChar *str = NULL; |
15672 | |
|
15673 | 0 | xmlSchemaCustomErr(ACTXT_CAST pctxt, |
15674 | 0 | XML_SCHEMAP_AG_PROPS_CORRECT, |
15675 | 0 | NULL, WXS_BASIC_CAST type, |
15676 | 0 | "There must not exist more than one attribute " |
15677 | 0 | "declaration of type 'xs:ID' " |
15678 | 0 | "(or derived from 'xs:ID'). The %s violates this " |
15679 | 0 | "constraint", |
15680 | 0 | xmlSchemaGetComponentDesignation(&str, use), |
15681 | 0 | NULL); |
15682 | 0 | FREE_AND_NULL(str); |
15683 | 0 | if (xmlSchemaItemListRemove(uses, i) == -1) |
15684 | 0 | goto exit_failure; |
15685 | 0 | } |
15686 | | |
15687 | 0 | hasId = 1; |
15688 | 0 | } |
15689 | 0 | } |
15690 | 0 | next_use: {} |
15691 | 0 | } |
15692 | 0 | } |
15693 | 0 | return (0); |
15694 | 0 | exit_failure: |
15695 | 0 | return(-1); |
15696 | 0 | } |
15697 | | |
15698 | | static int |
15699 | | xmlSchemaAreEqualTypes(xmlSchemaTypePtr typeA, |
15700 | | xmlSchemaTypePtr typeB) |
15701 | 0 | { |
15702 | | /* |
15703 | | * TODO: This should implement component-identity |
15704 | | * in the future. |
15705 | | */ |
15706 | 0 | if ((typeA == NULL) || (typeB == NULL)) |
15707 | 0 | return (0); |
15708 | 0 | return (typeA == typeB); |
15709 | 0 | } |
15710 | | |
15711 | | /** |
15712 | | * Schema Component Constraint: |
15713 | | * Type Derivation OK (Complex) (cos-ct-derived-ok) |
15714 | | * |
15715 | | * STATUS: completed |
15716 | | * |
15717 | | * @param actxt the schema parser context |
15718 | | * @param type the to-be derived complex type definition |
15719 | | * @param baseType the base complex type definition |
15720 | | * @param set the given set |
15721 | | * @returns 0 if the constraints are satisfied, or 1 |
15722 | | * if not. |
15723 | | */ |
15724 | | static int |
15725 | | xmlSchemaCheckCOSCTDerivedOK(xmlSchemaAbstractCtxtPtr actxt, |
15726 | | xmlSchemaTypePtr type, |
15727 | | xmlSchemaTypePtr baseType, |
15728 | | int set) |
15729 | 0 | { |
15730 | 0 | int equal = xmlSchemaAreEqualTypes(type, baseType); |
15731 | | /* TODO: Error codes. */ |
15732 | | /* |
15733 | | * SPEC "For a complex type definition (call it D, for derived) |
15734 | | * to be validly derived from a type definition (call this |
15735 | | * B, for base) given a subset of {extension, restriction} |
15736 | | * all of the following must be true:" |
15737 | | */ |
15738 | 0 | if (! equal) { |
15739 | | /* |
15740 | | * SPEC (1) "If B and D are not the same type definition, then the |
15741 | | * {derivation method} of D must not be in the subset." |
15742 | | */ |
15743 | 0 | if (((set & SUBSET_EXTENSION) && (WXS_IS_EXTENSION(type))) || |
15744 | 0 | ((set & SUBSET_RESTRICTION) && (WXS_IS_RESTRICTION(type)))) |
15745 | 0 | return (1); |
15746 | 0 | } else { |
15747 | | /* |
15748 | | * SPEC (2.1) "B and D must be the same type definition." |
15749 | | */ |
15750 | 0 | return (0); |
15751 | 0 | } |
15752 | | /* |
15753 | | * SPEC (2.2) "B must be D's {base type definition}." |
15754 | | */ |
15755 | 0 | if (type->baseType == baseType) |
15756 | 0 | return (0); |
15757 | | /* |
15758 | | * SPEC (2.3.1) "D's {base type definition} must not be the `ur-type |
15759 | | * definition`." |
15760 | | */ |
15761 | 0 | if (WXS_IS_ANYTYPE(type->baseType)) |
15762 | 0 | return (1); |
15763 | | |
15764 | 0 | if (WXS_IS_COMPLEX(type->baseType)) { |
15765 | | /* |
15766 | | * SPEC (2.3.2.1) "If D's {base type definition} is complex, then it |
15767 | | * must be validly derived from B given the subset as defined by this |
15768 | | * constraint." |
15769 | | */ |
15770 | 0 | return (xmlSchemaCheckCOSCTDerivedOK(actxt, type->baseType, |
15771 | 0 | baseType, set)); |
15772 | 0 | } else { |
15773 | | /* |
15774 | | * SPEC (2.3.2.2) "If D's {base type definition} is simple, then it |
15775 | | * must be validly derived from B given the subset as defined in Type |
15776 | | * Derivation OK (Simple) ($3.14.6). |
15777 | | */ |
15778 | 0 | return (xmlSchemaCheckCOSSTDerivedOK(actxt, type->baseType, |
15779 | 0 | baseType, set)); |
15780 | 0 | } |
15781 | 0 | } |
15782 | | |
15783 | | /** |
15784 | | * Calls: |
15785 | | * Type Derivation OK (Simple) AND Type Derivation OK (Complex) |
15786 | | * |
15787 | | * Checks whether `type` can be validly derived from `baseType`. |
15788 | | * |
15789 | | * @param actxt the schema parser context |
15790 | | * @param type the derived simple type definition |
15791 | | * @param baseType the base type definition |
15792 | | * @param set the given set |
15793 | | * @returns 0 on success, an positive error code otherwise. |
15794 | | */ |
15795 | | static int |
15796 | | xmlSchemaCheckCOSDerivedOK(xmlSchemaAbstractCtxtPtr actxt, |
15797 | | xmlSchemaTypePtr type, |
15798 | | xmlSchemaTypePtr baseType, |
15799 | | int set) |
15800 | 0 | { |
15801 | 0 | if (WXS_IS_SIMPLE(type)) |
15802 | 0 | return (xmlSchemaCheckCOSSTDerivedOK(actxt, type, baseType, set)); |
15803 | 0 | else |
15804 | 0 | return (xmlSchemaCheckCOSCTDerivedOK(actxt, type, baseType, set)); |
15805 | 0 | } |
15806 | | |
15807 | | /** |
15808 | | * (3.4.6) Constraints on Complex Type Definition Schema Components |
15809 | | * Schema Component Constraint: |
15810 | | * Derivation Valid (Extension) (cos-ct-extends) |
15811 | | * |
15812 | | * STATUS: |
15813 | | * missing: |
15814 | | * (1.5) |
15815 | | * (1.4.3.2.2.2) "Particle Valid (Extension)" |
15816 | | * |
15817 | | * @param ctxt the schema parser context |
15818 | | * @param type the complex type definition |
15819 | | * @returns 0 if the constraints are satisfied, a positive |
15820 | | * error code if not and -1 if an internal error occurred. |
15821 | | */ |
15822 | | static int |
15823 | | xmlSchemaCheckCOSCTExtends(xmlSchemaParserCtxtPtr ctxt, |
15824 | | xmlSchemaTypePtr type) |
15825 | 0 | { |
15826 | 0 | xmlSchemaTypePtr base = type->baseType; |
15827 | | /* |
15828 | | * TODO: Correct the error code; XML_SCHEMAP_COS_CT_EXTENDS_1_1 is used |
15829 | | * temporarily only. |
15830 | | */ |
15831 | | /* |
15832 | | * SPEC (1) "If the {base type definition} is a complex type definition, |
15833 | | * then all of the following must be true:" |
15834 | | */ |
15835 | 0 | if (WXS_IS_COMPLEX(base)) { |
15836 | | /* |
15837 | | * SPEC (1.1) "The {final} of the {base type definition} must not |
15838 | | * contain extension." |
15839 | | */ |
15840 | 0 | if (base->flags & XML_SCHEMAS_TYPE_FINAL_EXTENSION) { |
15841 | 0 | xmlSchemaPCustomErr(ctxt, |
15842 | 0 | XML_SCHEMAP_COS_CT_EXTENDS_1_1, |
15843 | 0 | WXS_BASIC_CAST type, NULL, |
15844 | 0 | "The 'final' of the base type definition " |
15845 | 0 | "contains 'extension'", NULL); |
15846 | 0 | return (XML_SCHEMAP_COS_CT_EXTENDS_1_1); |
15847 | 0 | } |
15848 | | |
15849 | | /* |
15850 | | * ATTENTION: The constrains (1.2) and (1.3) are not applied, |
15851 | | * since they are automatically satisfied through the |
15852 | | * inheriting mechanism. |
15853 | | * Note that even if redefining components, the inheriting mechanism |
15854 | | * is used. |
15855 | | */ |
15856 | | #if 0 |
15857 | | /* |
15858 | | * SPEC (1.2) "Its {attribute uses} must be a subset of the {attribute |
15859 | | * uses} |
15860 | | * of the complex type definition itself, that is, for every attribute |
15861 | | * use in the {attribute uses} of the {base type definition}, there |
15862 | | * must be an attribute use in the {attribute uses} of the complex |
15863 | | * type definition itself whose {attribute declaration} has the same |
15864 | | * {name}, {target namespace} and {type definition} as its attribute |
15865 | | * declaration" |
15866 | | */ |
15867 | | if (base->attrUses != NULL) { |
15868 | | int i, j, found; |
15869 | | xmlSchemaAttributeUsePtr use, buse; |
15870 | | |
15871 | | for (i = 0; i < (WXS_LIST_CAST base->attrUses)->nbItems; i ++) { |
15872 | | buse = (WXS_LIST_CAST base->attrUses)->items[i]; |
15873 | | found = 0; |
15874 | | if (type->attrUses != NULL) { |
15875 | | use = (WXS_LIST_CAST type->attrUses)->items[j]; |
15876 | | for (j = 0; j < (WXS_LIST_CAST type->attrUses)->nbItems; j ++) |
15877 | | { |
15878 | | if ((WXS_ATTRUSE_DECL_NAME(use) == |
15879 | | WXS_ATTRUSE_DECL_NAME(buse)) && |
15880 | | (WXS_ATTRUSE_DECL_TNS(use) == |
15881 | | WXS_ATTRUSE_DECL_TNS(buse)) && |
15882 | | (WXS_ATTRUSE_TYPEDEF(use) == |
15883 | | WXS_ATTRUSE_TYPEDEF(buse)) |
15884 | | { |
15885 | | found = 1; |
15886 | | break; |
15887 | | } |
15888 | | } |
15889 | | } |
15890 | | if (! found) { |
15891 | | xmlChar *str = NULL; |
15892 | | |
15893 | | xmlSchemaCustomErr(ACTXT_CAST ctxt, |
15894 | | XML_SCHEMAP_COS_CT_EXTENDS_1_2, |
15895 | | NULL, WXS_BASIC_CAST type, |
15896 | | /* |
15897 | | * TODO: The report does not indicate that also the |
15898 | | * type needs to be the same. |
15899 | | */ |
15900 | | "This type is missing a matching correspondent " |
15901 | | "for its {base type}'s %s in its {attribute uses}", |
15902 | | xmlSchemaGetComponentDesignation(&str, |
15903 | | buse->children), |
15904 | | NULL); |
15905 | | FREE_AND_NULL(str) |
15906 | | } |
15907 | | } |
15908 | | } |
15909 | | /* |
15910 | | * SPEC (1.3) "If it has an {attribute wildcard}, the complex type |
15911 | | * definition must also have one, and the base type definition's |
15912 | | * {attribute wildcard}'s {namespace constraint} must be a subset |
15913 | | * of the complex type definition's {attribute wildcard}'s {namespace |
15914 | | * constraint}, as defined by Wildcard Subset ($3.10.6)." |
15915 | | */ |
15916 | | |
15917 | | /* |
15918 | | * MAYBE TODO: Enable if ever needed. But this will be needed only |
15919 | | * if created the type via a schema construction API. |
15920 | | */ |
15921 | | if (base->attributeWildcard != NULL) { |
15922 | | if (type->attributeWildcard == NULL) { |
15923 | | xmlChar *str = NULL; |
15924 | | |
15925 | | xmlSchemaCustomErr(ACTXT_CAST pctxt, |
15926 | | XML_SCHEMAP_COS_CT_EXTENDS_1_3, |
15927 | | NULL, type, |
15928 | | "The base %s has an attribute wildcard, " |
15929 | | "but this type is missing an attribute wildcard", |
15930 | | xmlSchemaGetComponentDesignation(&str, base)); |
15931 | | FREE_AND_NULL(str) |
15932 | | |
15933 | | } else if (xmlSchemaCheckCOSNSSubset( |
15934 | | base->attributeWildcard, type->attributeWildcard)) |
15935 | | { |
15936 | | xmlChar *str = NULL; |
15937 | | |
15938 | | xmlSchemaCustomErr(ACTXT_CAST pctxt, |
15939 | | XML_SCHEMAP_COS_CT_EXTENDS_1_3, |
15940 | | NULL, type, |
15941 | | "The attribute wildcard is not a valid " |
15942 | | "superset of the one in the base %s", |
15943 | | xmlSchemaGetComponentDesignation(&str, base)); |
15944 | | FREE_AND_NULL(str) |
15945 | | } |
15946 | | } |
15947 | | #endif |
15948 | | /* |
15949 | | * SPEC (1.4) "One of the following must be true:" |
15950 | | */ |
15951 | 0 | if ((type->contentTypeDef != NULL) && |
15952 | 0 | (type->contentTypeDef == base->contentTypeDef)) { |
15953 | | /* |
15954 | | * SPEC (1.4.1) "The {content type} of the {base type definition} |
15955 | | * and the {content type} of the complex type definition itself |
15956 | | * must be the same simple type definition" |
15957 | | * PASS |
15958 | | */ |
15959 | 0 | } else if ((type->contentType == XML_SCHEMA_CONTENT_EMPTY) && |
15960 | 0 | (base->contentType == XML_SCHEMA_CONTENT_EMPTY) ) { |
15961 | | /* |
15962 | | * SPEC (1.4.2) "The {content type} of both the {base type |
15963 | | * definition} and the complex type definition itself must |
15964 | | * be empty." |
15965 | | * PASS |
15966 | | */ |
15967 | 0 | } else { |
15968 | | /* |
15969 | | * SPEC (1.4.3) "All of the following must be true:" |
15970 | | */ |
15971 | 0 | if (type->subtypes == NULL) { |
15972 | | /* |
15973 | | * SPEC 1.4.3.1 The {content type} of the complex type |
15974 | | * definition itself must specify a particle. |
15975 | | */ |
15976 | 0 | xmlSchemaPCustomErr(ctxt, |
15977 | 0 | XML_SCHEMAP_COS_CT_EXTENDS_1_1, |
15978 | 0 | WXS_BASIC_CAST type, NULL, |
15979 | 0 | "The content type must specify a particle", NULL); |
15980 | 0 | return (XML_SCHEMAP_COS_CT_EXTENDS_1_1); |
15981 | 0 | } |
15982 | | /* |
15983 | | * SPEC (1.4.3.2) "One of the following must be true:" |
15984 | | */ |
15985 | 0 | if (base->contentType == XML_SCHEMA_CONTENT_EMPTY) { |
15986 | | /* |
15987 | | * SPEC (1.4.3.2.1) "The {content type} of the {base type |
15988 | | * definition} must be empty. |
15989 | | * PASS |
15990 | | */ |
15991 | 0 | } else { |
15992 | | /* |
15993 | | * SPEC (1.4.3.2.2) "All of the following must be true:" |
15994 | | */ |
15995 | 0 | if ((type->contentType != base->contentType) || |
15996 | 0 | ((type->contentType != XML_SCHEMA_CONTENT_MIXED) && |
15997 | 0 | (type->contentType != XML_SCHEMA_CONTENT_ELEMENTS))) { |
15998 | | /* |
15999 | | * SPEC (1.4.3.2.2.1) "Both {content type}s must be mixed |
16000 | | * or both must be element-only." |
16001 | | */ |
16002 | 0 | xmlSchemaPCustomErr(ctxt, |
16003 | 0 | XML_SCHEMAP_COS_CT_EXTENDS_1_1, |
16004 | 0 | WXS_BASIC_CAST type, NULL, |
16005 | 0 | "The content type of both, the type and its base " |
16006 | 0 | "type, must either 'mixed' or 'element-only'", NULL); |
16007 | 0 | return (XML_SCHEMAP_COS_CT_EXTENDS_1_1); |
16008 | 0 | } |
16009 | | /* |
16010 | | * URGENT TODO SPEC (1.4.3.2.2.2) "The particle of the |
16011 | | * complex type definition must be a `valid extension` |
16012 | | * of the {base type definition}'s particle, as defined |
16013 | | * in Particle Valid (Extension) ($3.9.6)." |
16014 | | * |
16015 | | * NOTE that we won't check "Particle Valid (Extension)", |
16016 | | * since it is ensured by the derivation process in |
16017 | | * xmlSchemaTypeFixup(). We need to implement this when heading |
16018 | | * for a construction API |
16019 | | * TODO: !! This is needed to be checked if redefining a type !! |
16020 | | */ |
16021 | 0 | } |
16022 | | /* |
16023 | | * URGENT TODO (1.5) |
16024 | | */ |
16025 | 0 | } |
16026 | 0 | } else { |
16027 | | /* |
16028 | | * SPEC (2) "If the {base type definition} is a simple type definition, |
16029 | | * then all of the following must be true:" |
16030 | | */ |
16031 | 0 | if (type->contentTypeDef != base) { |
16032 | | /* |
16033 | | * SPEC (2.1) "The {content type} must be the same simple type |
16034 | | * definition." |
16035 | | */ |
16036 | 0 | xmlSchemaPCustomErr(ctxt, |
16037 | 0 | XML_SCHEMAP_COS_CT_EXTENDS_1_1, |
16038 | 0 | WXS_BASIC_CAST type, NULL, |
16039 | 0 | "The content type must be the simple base type", NULL); |
16040 | 0 | return (XML_SCHEMAP_COS_CT_EXTENDS_1_1); |
16041 | 0 | } |
16042 | 0 | if (base->flags & XML_SCHEMAS_TYPE_FINAL_EXTENSION) { |
16043 | | /* |
16044 | | * SPEC (2.2) "The {final} of the {base type definition} must not |
16045 | | * contain extension" |
16046 | | * NOTE that this is the same as (1.1). |
16047 | | */ |
16048 | 0 | xmlSchemaPCustomErr(ctxt, |
16049 | 0 | XML_SCHEMAP_COS_CT_EXTENDS_1_1, |
16050 | 0 | WXS_BASIC_CAST type, NULL, |
16051 | 0 | "The 'final' of the base type definition " |
16052 | 0 | "contains 'extension'", NULL); |
16053 | 0 | return (XML_SCHEMAP_COS_CT_EXTENDS_1_1); |
16054 | 0 | } |
16055 | 0 | } |
16056 | 0 | return (0); |
16057 | 0 | } |
16058 | | |
16059 | | /** |
16060 | | * (3.4.6) Constraints on Complex Type Definition Schema Components |
16061 | | * Schema Component Constraint: |
16062 | | * Derivation Valid (Restriction, Complex) (derivation-ok-restriction) |
16063 | | * |
16064 | | * STATUS: |
16065 | | * missing: |
16066 | | * (5.4.2) ??? |
16067 | | * |
16068 | | * ATTENTION: |
16069 | | * In XML Schema 1.1 this will be: |
16070 | | * Validation Rule: Checking complex type subsumption |
16071 | | * |
16072 | | * @param ctxt the schema parser context |
16073 | | * @param type the complex type definition |
16074 | | * @returns 0 if the constraints are satisfied, a positive |
16075 | | * error code if not and -1 if an internal error occurred. |
16076 | | */ |
16077 | | static int |
16078 | | xmlSchemaCheckDerivationOKRestriction(xmlSchemaParserCtxtPtr ctxt, |
16079 | | xmlSchemaTypePtr type) |
16080 | 0 | { |
16081 | 0 | xmlSchemaTypePtr base; |
16082 | | |
16083 | | /* |
16084 | | * TODO: Correct the error code; XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1 is used |
16085 | | * temporarily only. |
16086 | | */ |
16087 | 0 | base = type->baseType; |
16088 | 0 | if (! WXS_IS_COMPLEX(base)) { |
16089 | 0 | xmlSchemaCustomErr(ACTXT_CAST ctxt, |
16090 | 0 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1, |
16091 | 0 | type->node, WXS_BASIC_CAST type, |
16092 | 0 | "The base type must be a complex type", NULL, NULL); |
16093 | 0 | return(ctxt->err); |
16094 | 0 | } |
16095 | 0 | if (base->flags & XML_SCHEMAS_TYPE_FINAL_RESTRICTION) { |
16096 | | /* |
16097 | | * SPEC (1) "The {base type definition} must be a complex type |
16098 | | * definition whose {final} does not contain restriction." |
16099 | | */ |
16100 | 0 | xmlSchemaCustomErr(ACTXT_CAST ctxt, |
16101 | 0 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1, |
16102 | 0 | type->node, WXS_BASIC_CAST type, |
16103 | 0 | "The 'final' of the base type definition " |
16104 | 0 | "contains 'restriction'", NULL, NULL); |
16105 | 0 | return (ctxt->err); |
16106 | 0 | } |
16107 | | /* |
16108 | | * SPEC (2), (3) and (4) |
16109 | | * Those are handled in a separate function, since the |
16110 | | * same constraints are needed for redefinition of |
16111 | | * attribute groups as well. |
16112 | | */ |
16113 | 0 | if (xmlSchemaCheckDerivationOKRestriction2to4(ctxt, |
16114 | 0 | XML_SCHEMA_ACTION_DERIVE, |
16115 | 0 | WXS_BASIC_CAST type, WXS_BASIC_CAST base, |
16116 | 0 | type->attrUses, base->attrUses, |
16117 | 0 | type->attributeWildcard, |
16118 | 0 | base->attributeWildcard) == -1) |
16119 | 0 | { |
16120 | 0 | return(-1); |
16121 | 0 | } |
16122 | | /* |
16123 | | * SPEC (5) "One of the following must be true:" |
16124 | | */ |
16125 | 0 | if (base->builtInType == XML_SCHEMAS_ANYTYPE) { |
16126 | | /* |
16127 | | * SPEC (5.1) "The {base type definition} must be the |
16128 | | * `ur-type definition`." |
16129 | | * PASS |
16130 | | */ |
16131 | 0 | } else if ((type->contentType == XML_SCHEMA_CONTENT_SIMPLE) || |
16132 | 0 | (type->contentType == XML_SCHEMA_CONTENT_BASIC)) { |
16133 | | /* |
16134 | | * SPEC (5.2.1) "The {content type} of the complex type definition |
16135 | | * must be a simple type definition" |
16136 | | * |
16137 | | * SPEC (5.2.2) "One of the following must be true:" |
16138 | | */ |
16139 | 0 | if ((base->contentType == XML_SCHEMA_CONTENT_SIMPLE) || |
16140 | 0 | (base->contentType == XML_SCHEMA_CONTENT_BASIC)) |
16141 | 0 | { |
16142 | 0 | int err; |
16143 | | /* |
16144 | | * SPEC (5.2.2.1) "The {content type} of the {base type |
16145 | | * definition} must be a simple type definition from which |
16146 | | * the {content type} is validly derived given the empty |
16147 | | * set as defined in Type Derivation OK (Simple) ($3.14.6)." |
16148 | | * |
16149 | | * ATTENTION TODO: This seems not needed if the type implicitly |
16150 | | * derived from the base type. |
16151 | | * |
16152 | | */ |
16153 | 0 | err = xmlSchemaCheckCOSSTDerivedOK(ACTXT_CAST ctxt, |
16154 | 0 | type->contentTypeDef, base->contentTypeDef, 0); |
16155 | 0 | if (err != 0) { |
16156 | 0 | xmlChar *strA = NULL, *strB = NULL; |
16157 | |
|
16158 | 0 | if (err == -1) |
16159 | 0 | return(-1); |
16160 | 0 | xmlSchemaCustomErr(ACTXT_CAST ctxt, |
16161 | 0 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1, |
16162 | 0 | NULL, WXS_BASIC_CAST type, |
16163 | 0 | "The {content type} %s is not validly derived from the " |
16164 | 0 | "base type's {content type} %s", |
16165 | 0 | xmlSchemaGetComponentDesignation(&strA, |
16166 | 0 | type->contentTypeDef), |
16167 | 0 | xmlSchemaGetComponentDesignation(&strB, |
16168 | 0 | base->contentTypeDef)); |
16169 | 0 | FREE_AND_NULL(strA); |
16170 | 0 | FREE_AND_NULL(strB); |
16171 | 0 | return(ctxt->err); |
16172 | 0 | } |
16173 | 0 | } else if ((base->contentType == XML_SCHEMA_CONTENT_MIXED) && |
16174 | 0 | (xmlSchemaIsParticleEmptiable( |
16175 | 0 | (xmlSchemaParticlePtr) base->subtypes))) { |
16176 | | /* |
16177 | | * SPEC (5.2.2.2) "The {base type definition} must be mixed |
16178 | | * and have a particle which is `emptiable` as defined in |
16179 | | * Particle Emptiable ($3.9.6)." |
16180 | | * PASS |
16181 | | */ |
16182 | 0 | } else { |
16183 | 0 | xmlSchemaPCustomErr(ctxt, |
16184 | 0 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1, |
16185 | 0 | WXS_BASIC_CAST type, NULL, |
16186 | 0 | "The content type of the base type must be either " |
16187 | 0 | "a simple type or 'mixed' and an emptiable particle", NULL); |
16188 | 0 | return (ctxt->err); |
16189 | 0 | } |
16190 | 0 | } else if (type->contentType == XML_SCHEMA_CONTENT_EMPTY) { |
16191 | | /* |
16192 | | * SPEC (5.3.1) "The {content type} of the complex type itself must |
16193 | | * be empty" |
16194 | | */ |
16195 | 0 | if (base->contentType == XML_SCHEMA_CONTENT_EMPTY) { |
16196 | | /* |
16197 | | * SPEC (5.3.2.1) "The {content type} of the {base type |
16198 | | * definition} must also be empty." |
16199 | | * PASS |
16200 | | */ |
16201 | 0 | } else if (((base->contentType == XML_SCHEMA_CONTENT_ELEMENTS) || |
16202 | 0 | (base->contentType == XML_SCHEMA_CONTENT_MIXED)) && |
16203 | 0 | xmlSchemaIsParticleEmptiable( |
16204 | 0 | (xmlSchemaParticlePtr) base->subtypes)) { |
16205 | | /* |
16206 | | * SPEC (5.3.2.2) "The {content type} of the {base type |
16207 | | * definition} must be elementOnly or mixed and have a particle |
16208 | | * which is `emptiable` as defined in Particle Emptiable ($3.9.6)." |
16209 | | * PASS |
16210 | | */ |
16211 | 0 | } else { |
16212 | 0 | xmlSchemaPCustomErr(ctxt, |
16213 | 0 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1, |
16214 | 0 | WXS_BASIC_CAST type, NULL, |
16215 | 0 | "The content type of the base type must be either " |
16216 | 0 | "empty or 'mixed' (or 'elements-only') and an emptiable " |
16217 | 0 | "particle", NULL); |
16218 | 0 | return (ctxt->err); |
16219 | 0 | } |
16220 | 0 | } else if ((type->contentType == XML_SCHEMA_CONTENT_ELEMENTS) || |
16221 | 0 | WXS_HAS_MIXED_CONTENT(type)) { |
16222 | | /* |
16223 | | * SPEC (5.4.1.1) "The {content type} of the complex type definition |
16224 | | * itself must be element-only" |
16225 | | */ |
16226 | 0 | if (WXS_HAS_MIXED_CONTENT(type) && (! WXS_HAS_MIXED_CONTENT(base))) { |
16227 | | /* |
16228 | | * SPEC (5.4.1.2) "The {content type} of the complex type |
16229 | | * definition itself and of the {base type definition} must be |
16230 | | * mixed" |
16231 | | */ |
16232 | 0 | xmlSchemaPCustomErr(ctxt, |
16233 | 0 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1, |
16234 | 0 | WXS_BASIC_CAST type, NULL, |
16235 | 0 | "If the content type is 'mixed', then the content type of the " |
16236 | 0 | "base type must also be 'mixed'", NULL); |
16237 | 0 | return (ctxt->err); |
16238 | 0 | } |
16239 | | /* |
16240 | | * SPEC (5.4.2) "The particle of the complex type definition itself |
16241 | | * must be a `valid restriction` of the particle of the {content |
16242 | | * type} of the {base type definition} as defined in Particle Valid |
16243 | | * (Restriction) ($3.9.6). |
16244 | | * |
16245 | | * URGENT TODO: (5.4.2) |
16246 | | */ |
16247 | 0 | } else { |
16248 | 0 | xmlSchemaPCustomErr(ctxt, |
16249 | 0 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1, |
16250 | 0 | WXS_BASIC_CAST type, NULL, |
16251 | 0 | "The type is not a valid restriction of its base type", NULL); |
16252 | 0 | return (ctxt->err); |
16253 | 0 | } |
16254 | 0 | return (0); |
16255 | 0 | } |
16256 | | |
16257 | | /** |
16258 | | * (3.4.6) Constraints on Complex Type Definition Schema Components |
16259 | | * |
16260 | | * @param ctxt the schema parser context |
16261 | | * @param type the complex type definition |
16262 | | * @returns 0 if the constraints are satisfied, a positive |
16263 | | * error code if not and -1 if an internal error occurred. |
16264 | | */ |
16265 | | static int |
16266 | | xmlSchemaCheckCTComponent(xmlSchemaParserCtxtPtr ctxt, |
16267 | | xmlSchemaTypePtr type) |
16268 | 0 | { |
16269 | 0 | int ret; |
16270 | | /* |
16271 | | * Complex Type Definition Properties Correct |
16272 | | */ |
16273 | 0 | ret = xmlSchemaCheckCTPropsCorrect(ctxt, type); |
16274 | 0 | if (ret != 0) |
16275 | 0 | return (ret); |
16276 | 0 | if (WXS_IS_EXTENSION(type)) |
16277 | 0 | ret = xmlSchemaCheckCOSCTExtends(ctxt, type); |
16278 | 0 | else |
16279 | 0 | ret = xmlSchemaCheckDerivationOKRestriction(ctxt, type); |
16280 | 0 | return (ret); |
16281 | 0 | } |
16282 | | |
16283 | | /** |
16284 | | * (3.4.3) Constraints on XML Representations of Complex Type Definitions: |
16285 | | * Schema Representation Constraint: |
16286 | | * Complex Type Definition Representation OK (src-ct) |
16287 | | * |
16288 | | * @param ctxt the schema parser context |
16289 | | * @param type the complex type definition |
16290 | | * @returns 0 if the constraints are satisfied, a positive |
16291 | | * error code if not and -1 if an internal error occurred. |
16292 | | */ |
16293 | | static int |
16294 | | xmlSchemaCheckSRCCT(xmlSchemaParserCtxtPtr ctxt, |
16295 | | xmlSchemaTypePtr type) |
16296 | 0 | { |
16297 | 0 | xmlSchemaTypePtr base; |
16298 | 0 | int ret = 0; |
16299 | | |
16300 | | /* |
16301 | | * TODO: Adjust the error codes here, as I used |
16302 | | * XML_SCHEMAP_SRC_CT_1 only yet. |
16303 | | */ |
16304 | 0 | base = type->baseType; |
16305 | 0 | if (! WXS_HAS_SIMPLE_CONTENT(type)) { |
16306 | | /* |
16307 | | * 1 If the <complexContent> alternative is chosen, the type definition |
16308 | | * `resolved` to by the `actual value` of the base [attribute] |
16309 | | * must be a complex type definition; |
16310 | | */ |
16311 | 0 | if (! WXS_IS_COMPLEX(base)) { |
16312 | 0 | xmlChar *str = NULL; |
16313 | 0 | xmlSchemaPCustomErr(ctxt, |
16314 | 0 | XML_SCHEMAP_SRC_CT_1, |
16315 | 0 | WXS_BASIC_CAST type, type->node, |
16316 | 0 | "If using <complexContent>, the base type is expected to be " |
16317 | 0 | "a complex type. The base type '%s' is a simple type", |
16318 | 0 | xmlSchemaFormatQName(&str, base->targetNamespace, |
16319 | 0 | base->name)); |
16320 | 0 | FREE_AND_NULL(str) |
16321 | 0 | return (XML_SCHEMAP_SRC_CT_1); |
16322 | 0 | } |
16323 | 0 | } else { |
16324 | | /* |
16325 | | * SPEC |
16326 | | * 2 If the <simpleContent> alternative is chosen, all of the |
16327 | | * following must be true: |
16328 | | * 2.1 The type definition `resolved` to by the `actual value` of the |
16329 | | * base [attribute] must be one of the following: |
16330 | | */ |
16331 | 0 | if (WXS_IS_SIMPLE(base)) { |
16332 | 0 | if (WXS_IS_EXTENSION(type) == 0) { |
16333 | 0 | xmlChar *str = NULL; |
16334 | | /* |
16335 | | * 2.1.3 only if the <extension> alternative is also |
16336 | | * chosen, a simple type definition. |
16337 | | */ |
16338 | | /* TODO: Change error code to ..._SRC_CT_2_1_3. */ |
16339 | 0 | xmlSchemaPCustomErr(ctxt, |
16340 | 0 | XML_SCHEMAP_SRC_CT_1, |
16341 | 0 | WXS_BASIC_CAST type, NULL, |
16342 | 0 | "If using <simpleContent> and <restriction>, the base " |
16343 | 0 | "type must be a complex type. The base type '%s' is " |
16344 | 0 | "a simple type", |
16345 | 0 | xmlSchemaFormatQName(&str, base->targetNamespace, |
16346 | 0 | base->name)); |
16347 | 0 | FREE_AND_NULL(str) |
16348 | 0 | return (XML_SCHEMAP_SRC_CT_1); |
16349 | 0 | } |
16350 | 0 | } else { |
16351 | | /* Base type is a complex type. */ |
16352 | 0 | if ((base->contentType == XML_SCHEMA_CONTENT_SIMPLE) || |
16353 | 0 | (base->contentType == XML_SCHEMA_CONTENT_BASIC)) { |
16354 | | /* |
16355 | | * 2.1.1 a complex type definition whose {content type} is a |
16356 | | * simple type definition; |
16357 | | * PASS |
16358 | | */ |
16359 | 0 | if (base->contentTypeDef == NULL) { |
16360 | 0 | xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_INTERNAL, |
16361 | 0 | WXS_BASIC_CAST type, NULL, |
16362 | 0 | "Internal error: xmlSchemaCheckSRCCT, " |
16363 | 0 | "'%s', base type has no content type", |
16364 | 0 | type->name); |
16365 | 0 | return (-1); |
16366 | 0 | } |
16367 | 0 | } else if ((base->contentType == XML_SCHEMA_CONTENT_MIXED) && |
16368 | 0 | (WXS_IS_RESTRICTION(type))) { |
16369 | | |
16370 | | /* |
16371 | | * 2.1.2 only if the <restriction> alternative is also |
16372 | | * chosen, a complex type definition whose {content type} |
16373 | | * is mixed and a particle emptiable. |
16374 | | */ |
16375 | 0 | if (! xmlSchemaIsParticleEmptiable( |
16376 | 0 | (xmlSchemaParticlePtr) base->subtypes)) { |
16377 | 0 | ret = XML_SCHEMAP_SRC_CT_1; |
16378 | 0 | } else |
16379 | | /* |
16380 | | * Attention: at this point the <simpleType> child is in |
16381 | | * ->contentTypeDef (put there during parsing). |
16382 | | */ |
16383 | 0 | if (type->contentTypeDef == NULL) { |
16384 | 0 | xmlChar *str = NULL; |
16385 | | /* |
16386 | | * 2.2 If clause 2.1.2 above is satisfied, then there |
16387 | | * must be a <simpleType> among the [children] of |
16388 | | * <restriction>. |
16389 | | */ |
16390 | | /* TODO: Change error code to ..._SRC_CT_2_2. */ |
16391 | 0 | xmlSchemaPCustomErr(ctxt, |
16392 | 0 | XML_SCHEMAP_SRC_CT_1, |
16393 | 0 | WXS_BASIC_CAST type, NULL, |
16394 | 0 | "A <simpleType> is expected among the children " |
16395 | 0 | "of <restriction>, if <simpleContent> is used and " |
16396 | 0 | "the base type '%s' is a complex type", |
16397 | 0 | xmlSchemaFormatQName(&str, base->targetNamespace, |
16398 | 0 | base->name)); |
16399 | 0 | FREE_AND_NULL(str) |
16400 | 0 | return (XML_SCHEMAP_SRC_CT_1); |
16401 | 0 | } |
16402 | 0 | } else { |
16403 | 0 | ret = XML_SCHEMAP_SRC_CT_1; |
16404 | 0 | } |
16405 | 0 | } |
16406 | 0 | if (ret > 0) { |
16407 | 0 | xmlChar *str = NULL; |
16408 | 0 | if (WXS_IS_RESTRICTION(type)) { |
16409 | 0 | xmlSchemaPCustomErr(ctxt, |
16410 | 0 | XML_SCHEMAP_SRC_CT_1, |
16411 | 0 | WXS_BASIC_CAST type, NULL, |
16412 | 0 | "If <simpleContent> and <restriction> is used, the " |
16413 | 0 | "base type must be a simple type or a complex type with " |
16414 | 0 | "mixed content and particle emptiable. The base type " |
16415 | 0 | "'%s' is none of those", |
16416 | 0 | xmlSchemaFormatQName(&str, base->targetNamespace, |
16417 | 0 | base->name)); |
16418 | 0 | } else { |
16419 | 0 | xmlSchemaPCustomErr(ctxt, |
16420 | 0 | XML_SCHEMAP_SRC_CT_1, |
16421 | 0 | WXS_BASIC_CAST type, NULL, |
16422 | 0 | "If <simpleContent> and <extension> is used, the " |
16423 | 0 | "base type must be a simple type. The base type '%s' " |
16424 | 0 | "is a complex type", |
16425 | 0 | xmlSchemaFormatQName(&str, base->targetNamespace, |
16426 | 0 | base->name)); |
16427 | 0 | } |
16428 | 0 | FREE_AND_NULL(str) |
16429 | 0 | } |
16430 | 0 | } |
16431 | | /* |
16432 | | * SPEC (3) "The corresponding complex type definition component must |
16433 | | * satisfy the conditions set out in Constraints on Complex Type |
16434 | | * Definition Schema Components ($3.4.6);" |
16435 | | * NOTE (3) will be done in xmlSchemaTypeFixup(). |
16436 | | */ |
16437 | | /* |
16438 | | * SPEC (4) If clause 2.2.1 or clause 2.2.2 in the correspondence specification |
16439 | | * above for {attribute wildcard} is satisfied, the intensional |
16440 | | * intersection must be expressible, as defined in Attribute Wildcard |
16441 | | * Intersection ($3.10.6). |
16442 | | * NOTE (4) is done in xmlSchemaFixupTypeAttributeUses(). |
16443 | | */ |
16444 | 0 | return (ret); |
16445 | 0 | } |
16446 | | |
16447 | | #ifdef ENABLE_PARTICLE_RESTRICTION |
16448 | | /** |
16449 | | * (3.9.6) Constraints on Particle Schema Components |
16450 | | * Schema Component Constraint: |
16451 | | * Occurrence Range OK (range-ok) |
16452 | | * |
16453 | | * STATUS: complete |
16454 | | * |
16455 | | * @param ctxt the schema parser context |
16456 | | * @param type the complex type definition |
16457 | | * @returns 0 if the constraints are satisfied, a positive |
16458 | | * error code if not and -1 if an internal error occurred. |
16459 | | */ |
16460 | | static int |
16461 | | xmlSchemaCheckParticleRangeOK(int rmin, int rmax, |
16462 | | int bmin, int bmax) |
16463 | | { |
16464 | | if (rmin < bmin) |
16465 | | return (1); |
16466 | | if ((bmax != UNBOUNDED) && |
16467 | | (rmax > bmax)) |
16468 | | return (1); |
16469 | | return (0); |
16470 | | } |
16471 | | |
16472 | | /** |
16473 | | * (3.9.6) Constraints on Particle Schema Components |
16474 | | * Schema Component Constraint: |
16475 | | * Particle Restriction OK (Elt:Elt -- NameAndTypeOK) |
16476 | | * (rcase-NameAndTypeOK) |
16477 | | * |
16478 | | * STATUS: |
16479 | | * MISSING (3.2.3) |
16480 | | * CLARIFY: (3.2.2) |
16481 | | * |
16482 | | * @param ctxt the schema parser context |
16483 | | * @param r the restricting element declaration particle |
16484 | | * @param b the base element declaration particle |
16485 | | * @returns 0 if the constraints are satisfied, a positive |
16486 | | * error code if not and -1 if an internal error occurred. |
16487 | | */ |
16488 | | static int |
16489 | | xmlSchemaCheckRCaseNameAndTypeOK(xmlSchemaParserCtxtPtr ctxt, |
16490 | | xmlSchemaParticlePtr r, |
16491 | | xmlSchemaParticlePtr b) |
16492 | | { |
16493 | | xmlSchemaElementPtr elemR, elemB; |
16494 | | |
16495 | | /* TODO: Error codes (rcase-NameAndTypeOK). */ |
16496 | | elemR = (xmlSchemaElementPtr) r->children; |
16497 | | elemB = (xmlSchemaElementPtr) b->children; |
16498 | | /* |
16499 | | * SPEC (1) "The declarations' {name}s and {target namespace}s are |
16500 | | * the same." |
16501 | | */ |
16502 | | if ((elemR != elemB) && |
16503 | | ((! xmlStrEqual(elemR->name, elemB->name)) || |
16504 | | (! xmlStrEqual(elemR->targetNamespace, elemB->targetNamespace)))) |
16505 | | return (1); |
16506 | | /* |
16507 | | * SPEC (2) "R's occurrence range is a valid restriction of B's |
16508 | | * occurrence range as defined by Occurrence Range OK ($3.9.6)." |
16509 | | */ |
16510 | | if (xmlSchemaCheckParticleRangeOK(r->minOccurs, r->maxOccurs, |
16511 | | b->minOccurs, b->maxOccurs) != 0) |
16512 | | return (1); |
16513 | | /* |
16514 | | * SPEC (3.1) "Both B's declaration's {scope} and R's declaration's |
16515 | | * {scope} are global." |
16516 | | */ |
16517 | | if (elemR == elemB) |
16518 | | return (0); |
16519 | | /* |
16520 | | * SPEC (3.2.1) "Either B's {nillable} is true or R's {nillable} is false." |
16521 | | */ |
16522 | | if (((elemB->flags & XML_SCHEMAS_ELEM_NILLABLE) == 0) && |
16523 | | (elemR->flags & XML_SCHEMAS_ELEM_NILLABLE)) |
16524 | | return (1); |
16525 | | /* |
16526 | | * SPEC (3.2.2) "either B's declaration's {value constraint} is absent, |
16527 | | * or is not fixed, or R's declaration's {value constraint} is fixed |
16528 | | * with the same value." |
16529 | | */ |
16530 | | if ((elemB->value != NULL) && (elemB->flags & XML_SCHEMAS_ELEM_FIXED) && |
16531 | | ((elemR->value == NULL) || |
16532 | | ((elemR->flags & XML_SCHEMAS_ELEM_FIXED) == 0) || |
16533 | | /* TODO: Equality of the initial value or normalized or canonical? */ |
16534 | | (! xmlStrEqual(elemR->value, elemB->value)))) |
16535 | | return (1); |
16536 | | /* |
16537 | | * TODO: SPEC (3.2.3) "R's declaration's {identity-constraint |
16538 | | * definitions} is a subset of B's declaration's {identity-constraint |
16539 | | * definitions}, if any." |
16540 | | */ |
16541 | | if (elemB->idcs != NULL) { |
16542 | | /* TODO */ |
16543 | | } |
16544 | | /* |
16545 | | * SPEC (3.2.4) "R's declaration's {disallowed substitutions} is a |
16546 | | * superset of B's declaration's {disallowed substitutions}." |
16547 | | */ |
16548 | | if (((elemB->flags & XML_SCHEMAS_ELEM_BLOCK_EXTENSION) && |
16549 | | ((elemR->flags & XML_SCHEMAS_ELEM_BLOCK_EXTENSION) == 0)) || |
16550 | | ((elemB->flags & XML_SCHEMAS_ELEM_BLOCK_RESTRICTION) && |
16551 | | ((elemR->flags & XML_SCHEMAS_ELEM_BLOCK_RESTRICTION) == 0)) || |
16552 | | ((elemB->flags & XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION) && |
16553 | | ((elemR->flags & XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION) == 0))) |
16554 | | return (1); |
16555 | | /* |
16556 | | * SPEC (3.2.5) "R's {type definition} is validly derived given |
16557 | | * {extension, list, union} from B's {type definition}" |
16558 | | * |
16559 | | * BADSPEC TODO: What's the point of adding "list" and "union" to the |
16560 | | * set, if the corresponding constraints handle "restriction" and |
16561 | | * "extension" only? |
16562 | | * |
16563 | | */ |
16564 | | { |
16565 | | int set = 0; |
16566 | | |
16567 | | set |= SUBSET_EXTENSION; |
16568 | | set |= SUBSET_LIST; |
16569 | | set |= SUBSET_UNION; |
16570 | | if (xmlSchemaCheckCOSDerivedOK(ACTXT_CAST ctxt, elemR->subtypes, |
16571 | | elemB->subtypes, set) != 0) |
16572 | | return (1); |
16573 | | } |
16574 | | return (0); |
16575 | | } |
16576 | | |
16577 | | /** |
16578 | | * (3.9.6) Constraints on Particle Schema Components |
16579 | | * Schema Component Constraint: |
16580 | | * Particle Derivation OK (Elt:Any -- NSCompat) |
16581 | | * (rcase-NSCompat) |
16582 | | * |
16583 | | * STATUS: complete |
16584 | | * |
16585 | | * @param ctxt the schema parser context |
16586 | | * @param r the restricting element declaration particle |
16587 | | * @param b the base wildcard particle |
16588 | | * @returns 0 if the constraints are satisfied, a positive |
16589 | | * error code if not and -1 if an internal error occurred. |
16590 | | */ |
16591 | | static int |
16592 | | xmlSchemaCheckRCaseNSCompat(xmlSchemaParserCtxtPtr ctxt, |
16593 | | xmlSchemaParticlePtr r, |
16594 | | xmlSchemaParticlePtr b) |
16595 | | { |
16596 | | /* TODO:Error codes (rcase-NSCompat). */ |
16597 | | /* |
16598 | | * SPEC "For an element declaration particle to be a `valid restriction` |
16599 | | * of a wildcard particle all of the following must be true:" |
16600 | | * |
16601 | | * SPEC (1) "The element declaration's {target namespace} is `valid` |
16602 | | * with respect to the wildcard's {namespace constraint} as defined by |
16603 | | * Wildcard allows Namespace Name ($3.10.4)." |
16604 | | */ |
16605 | | if (xmlSchemaCheckCVCWildcardNamespace((xmlSchemaWildcardPtr) b->children, |
16606 | | ((xmlSchemaElementPtr) r->children)->targetNamespace) != 0) |
16607 | | return (1); |
16608 | | /* |
16609 | | * SPEC (2) "R's occurrence range is a valid restriction of B's |
16610 | | * occurrence range as defined by Occurrence Range OK ($3.9.6)." |
16611 | | */ |
16612 | | if (xmlSchemaCheckParticleRangeOK(r->minOccurs, r->maxOccurs, |
16613 | | b->minOccurs, b->maxOccurs) != 0) |
16614 | | return (1); |
16615 | | |
16616 | | return (0); |
16617 | | } |
16618 | | |
16619 | | /** |
16620 | | * (3.9.6) Constraints on Particle Schema Components |
16621 | | * Schema Component Constraint: |
16622 | | * Particle Derivation OK (Elt:All/Choice/Sequence -- RecurseAsIfGroup) |
16623 | | * (rcase-RecurseAsIfGroup) |
16624 | | * |
16625 | | * STATUS: TODO |
16626 | | * |
16627 | | * @param ctxt the schema parser context |
16628 | | * @param r the restricting element declaration particle |
16629 | | * @param b the base model group particle |
16630 | | * @returns 0 if the constraints are satisfied, a positive |
16631 | | * error code if not and -1 if an internal error occurred. |
16632 | | */ |
16633 | | static int |
16634 | | xmlSchemaCheckRCaseRecurseAsIfGroup(xmlSchemaParserCtxtPtr ctxt, |
16635 | | xmlSchemaParticlePtr r, |
16636 | | xmlSchemaParticlePtr b) |
16637 | | { |
16638 | | /* TODO: Error codes (rcase-RecurseAsIfGroup). */ |
16639 | | TODO |
16640 | | return (0); |
16641 | | } |
16642 | | |
16643 | | /** |
16644 | | * (3.9.6) Constraints on Particle Schema Components |
16645 | | * Schema Component Constraint: |
16646 | | * Particle Derivation OK (Any:Any -- NSSubset) |
16647 | | * (rcase-NSSubset) |
16648 | | * |
16649 | | * STATUS: complete |
16650 | | * |
16651 | | * @param ctxt the schema parser context |
16652 | | * @param r the restricting wildcard particle |
16653 | | * @param b the base wildcard particle |
16654 | | * @returns 0 if the constraints are satisfied, a positive |
16655 | | * error code if not and -1 if an internal error occurred. |
16656 | | */ |
16657 | | static int |
16658 | | xmlSchemaCheckRCaseNSSubset(xmlSchemaParserCtxtPtr ctxt, |
16659 | | xmlSchemaParticlePtr r, |
16660 | | xmlSchemaParticlePtr b, |
16661 | | int isAnyTypeBase) |
16662 | | { |
16663 | | /* TODO: Error codes (rcase-NSSubset). */ |
16664 | | /* |
16665 | | * SPEC (1) "R's occurrence range is a valid restriction of B's |
16666 | | * occurrence range as defined by Occurrence Range OK ($3.9.6)." |
16667 | | */ |
16668 | | if (xmlSchemaCheckParticleRangeOK(r->minOccurs, r->maxOccurs, |
16669 | | b->minOccurs, b->maxOccurs)) |
16670 | | return (1); |
16671 | | /* |
16672 | | * SPEC (2) "R's {namespace constraint} must be an intensional subset |
16673 | | * of B's {namespace constraint} as defined by Wildcard Subset ($3.10.6)." |
16674 | | */ |
16675 | | if (xmlSchemaCheckCOSNSSubset((xmlSchemaWildcardPtr) r->children, |
16676 | | (xmlSchemaWildcardPtr) b->children)) |
16677 | | return (1); |
16678 | | /* |
16679 | | * SPEC (3) "Unless B is the content model wildcard of the `ur-type |
16680 | | * definition`, R's {process contents} must be identical to or stronger |
16681 | | * than B's {process contents}, where strict is stronger than lax is |
16682 | | * stronger than skip." |
16683 | | */ |
16684 | | if (! isAnyTypeBase) { |
16685 | | if ( ((xmlSchemaWildcardPtr) r->children)->processContents < |
16686 | | ((xmlSchemaWildcardPtr) b->children)->processContents) |
16687 | | return (1); |
16688 | | } |
16689 | | |
16690 | | return (0); |
16691 | | } |
16692 | | |
16693 | | /** |
16694 | | * (3.9.6) Constraints on Particle Schema Components |
16695 | | * Schema Component Constraint: |
16696 | | * Particle Valid (Restriction) (cos-particle-restrict) |
16697 | | * |
16698 | | * STATUS: TODO |
16699 | | * |
16700 | | * @param ctxt the schema parser context |
16701 | | * @param type the complex type definition |
16702 | | * @returns 0 if the constraints are satisfied, a positive |
16703 | | * error code if not and -1 if an internal error occurred. |
16704 | | */ |
16705 | | static int |
16706 | | xmlSchemaCheckCOSParticleRestrict(xmlSchemaParserCtxtPtr ctxt, |
16707 | | xmlSchemaParticlePtr r, |
16708 | | xmlSchemaParticlePtr b) |
16709 | | { |
16710 | | int ret = 0; |
16711 | | |
16712 | | /*part = WXS_TYPE_PARTICLE(type); |
16713 | | basePart = WXS_TYPE_PARTICLE(base); |
16714 | | */ |
16715 | | |
16716 | | TODO |
16717 | | |
16718 | | /* |
16719 | | * SPEC (1) "They are the same particle." |
16720 | | */ |
16721 | | if (r == b) |
16722 | | return (0); |
16723 | | |
16724 | | |
16725 | | return (0); |
16726 | | } |
16727 | | |
16728 | | #if 0 |
16729 | | /** |
16730 | | * (3.9.6) Constraints on Particle Schema Components |
16731 | | * Schema Component Constraint: |
16732 | | * Particle Derivation OK (All/Choice/Sequence:Any -- |
16733 | | * NSRecurseCheckCardinality) |
16734 | | * (rcase-NSRecurseCheckCardinality) |
16735 | | * |
16736 | | * STATUS: TODO: subst-groups |
16737 | | * |
16738 | | * @param ctxt the schema parser context |
16739 | | * @param r the model group particle |
16740 | | * @param b the base wildcard particle |
16741 | | * @returns 0 if the constraints are satisfied, a positive |
16742 | | * error code if not and -1 if an internal error occurred. |
16743 | | */ |
16744 | | static int |
16745 | | xmlSchemaCheckRCaseNSRecurseCheckCardinality(xmlSchemaParserCtxtPtr ctxt, |
16746 | | xmlSchemaParticlePtr r, |
16747 | | xmlSchemaParticlePtr b) |
16748 | | { |
16749 | | xmlSchemaParticlePtr part; |
16750 | | /* TODO: Error codes (rcase-NSRecurseCheckCardinality). */ |
16751 | | if ((r->children == NULL) || (r->children->children == NULL)) |
16752 | | return (-1); |
16753 | | /* |
16754 | | * SPEC "For a group particle to be a `valid restriction` of a |
16755 | | * wildcard particle..." |
16756 | | * |
16757 | | * SPEC (1) "Every member of the {particles} of the group is a `valid |
16758 | | * restriction` of the wildcard as defined by |
16759 | | * Particle Valid (Restriction) ($3.9.6)." |
16760 | | */ |
16761 | | part = (xmlSchemaParticlePtr) r->children->children; |
16762 | | do { |
16763 | | if (xmlSchemaCheckCOSParticleRestrict(ctxt, part, b)) |
16764 | | return (1); |
16765 | | part = (xmlSchemaParticlePtr) part->next; |
16766 | | } while (part != NULL); |
16767 | | /* |
16768 | | * SPEC (2) "The effective total range of the group [...] is a |
16769 | | * valid restriction of B's occurrence range as defined by |
16770 | | * Occurrence Range OK ($3.9.6)." |
16771 | | */ |
16772 | | if (xmlSchemaCheckParticleRangeOK( |
16773 | | xmlSchemaGetParticleTotalRangeMin(r), |
16774 | | xmlSchemaGetParticleTotalRangeMax(r), |
16775 | | b->minOccurs, b->maxOccurs) != 0) |
16776 | | return (1); |
16777 | | return (0); |
16778 | | } |
16779 | | #endif |
16780 | | |
16781 | | /** |
16782 | | * (3.9.6) Constraints on Particle Schema Components |
16783 | | * Schema Component Constraint: |
16784 | | * Particle Derivation OK (All:All,Sequence:Sequence -- |
16785 | | Recurse) |
16786 | | * (rcase-Recurse) |
16787 | | * |
16788 | | * STATUS: ? |
16789 | | * TODO: subst-groups |
16790 | | * |
16791 | | * @param ctxt the schema parser context |
16792 | | * @param r the <all> or <sequence> model group particle |
16793 | | * @param b the base <all> or <sequence> model group particle |
16794 | | * @returns 0 if the constraints are satisfied, a positive |
16795 | | * error code if not and -1 if an internal error occurred. |
16796 | | */ |
16797 | | static int |
16798 | | xmlSchemaCheckRCaseRecurse(xmlSchemaParserCtxtPtr ctxt, |
16799 | | xmlSchemaParticlePtr r, |
16800 | | xmlSchemaParticlePtr b) |
16801 | | { |
16802 | | /* xmlSchemaParticlePtr part; */ |
16803 | | /* TODO: Error codes (rcase-Recurse). */ |
16804 | | if ((r->children == NULL) || (b->children == NULL) || |
16805 | | (r->children->type != b->children->type)) |
16806 | | return (-1); |
16807 | | /* |
16808 | | * SPEC "For an all or sequence group particle to be a `valid |
16809 | | * restriction` of another group particle with the same {compositor}..." |
16810 | | * |
16811 | | * SPEC (1) "R's occurrence range is a valid restriction of B's |
16812 | | * occurrence range as defined by Occurrence Range OK ($3.9.6)." |
16813 | | */ |
16814 | | if (xmlSchemaCheckParticleRangeOK(r->minOccurs, r->maxOccurs, |
16815 | | b->minOccurs, b->maxOccurs)) |
16816 | | return (1); |
16817 | | |
16818 | | |
16819 | | return (0); |
16820 | | } |
16821 | | |
16822 | | #endif |
16823 | | |
16824 | | #define FACET_RESTR_MUTUAL_ERR(fac1, fac2) \ |
16825 | 0 | xmlSchemaPCustomErrExt(pctxt, \ |
16826 | 0 | XML_SCHEMAP_INVALID_FACET_VALUE, \ |
16827 | 0 | WXS_BASIC_CAST fac1, fac1->node, \ |
16828 | 0 | "It is an error for both '%s' and '%s' to be specified on the "\ |
16829 | 0 | "same type definition", \ |
16830 | 0 | BAD_CAST xmlSchemaFacetTypeToString(fac1->type), \ |
16831 | 0 | BAD_CAST xmlSchemaFacetTypeToString(fac2->type), NULL); |
16832 | | |
16833 | | #define FACET_RESTR_ERR(fac1, msg) \ |
16834 | 0 | xmlSchemaPCustomErr(pctxt, \ |
16835 | 0 | XML_SCHEMAP_INVALID_FACET_VALUE, \ |
16836 | 0 | WXS_BASIC_CAST fac1, fac1->node, \ |
16837 | 0 | msg, NULL); |
16838 | | |
16839 | | #define FACET_RESTR_FIXED_ERR(fac) \ |
16840 | 0 | xmlSchemaPCustomErr(pctxt, \ |
16841 | 0 | XML_SCHEMAP_INVALID_FACET_VALUE, \ |
16842 | 0 | WXS_BASIC_CAST fac, fac->node, \ |
16843 | 0 | "The base type's facet is 'fixed', thus the value must not " \ |
16844 | 0 | "differ", NULL); |
16845 | | |
16846 | | static void |
16847 | | xmlSchemaDeriveFacetErr(xmlSchemaParserCtxtPtr pctxt, |
16848 | | xmlSchemaFacetPtr facet1, |
16849 | | xmlSchemaFacetPtr facet2, |
16850 | | int lessGreater, |
16851 | | int orEqual, |
16852 | | int ofBase) |
16853 | 0 | { |
16854 | 0 | xmlChar *msg = NULL; |
16855 | |
|
16856 | 0 | msg = xmlStrdup(BAD_CAST "'"); |
16857 | 0 | msg = xmlStrcat(msg, xmlSchemaFacetTypeToString(facet1->type)); |
16858 | 0 | msg = xmlStrcat(msg, BAD_CAST "' has to be"); |
16859 | 0 | if (lessGreater == 0) |
16860 | 0 | msg = xmlStrcat(msg, BAD_CAST " equal to"); |
16861 | 0 | if (lessGreater == 1) |
16862 | 0 | msg = xmlStrcat(msg, BAD_CAST " greater than"); |
16863 | 0 | else |
16864 | 0 | msg = xmlStrcat(msg, BAD_CAST " less than"); |
16865 | |
|
16866 | 0 | if (orEqual) |
16867 | 0 | msg = xmlStrcat(msg, BAD_CAST " or equal to"); |
16868 | 0 | msg = xmlStrcat(msg, BAD_CAST " '"); |
16869 | 0 | msg = xmlStrcat(msg, xmlSchemaFacetTypeToString(facet2->type)); |
16870 | 0 | if (ofBase) |
16871 | 0 | msg = xmlStrcat(msg, BAD_CAST "' of the base type"); |
16872 | 0 | else |
16873 | 0 | msg = xmlStrcat(msg, BAD_CAST "'"); |
16874 | |
|
16875 | 0 | xmlSchemaPCustomErr(pctxt, |
16876 | 0 | XML_SCHEMAP_INVALID_FACET_VALUE, |
16877 | 0 | WXS_BASIC_CAST facet1, NULL, |
16878 | 0 | (const char *) msg, NULL); |
16879 | |
|
16880 | 0 | if (msg != NULL) |
16881 | 0 | xmlFree(msg); |
16882 | 0 | } |
16883 | | |
16884 | | /* |
16885 | | * xmlSchemaDeriveAndValidateFacets: |
16886 | | * |
16887 | | * Schema Component Constraint: Simple Type Restriction (Facets) |
16888 | | * (st-restrict-facets) |
16889 | | */ |
16890 | | static int |
16891 | | xmlSchemaDeriveAndValidateFacets(xmlSchemaParserCtxtPtr pctxt, |
16892 | | xmlSchemaTypePtr type) |
16893 | 0 | { |
16894 | 0 | xmlSchemaTypePtr base = type->baseType; |
16895 | 0 | xmlSchemaFacetLinkPtr link, cur, last = NULL; |
16896 | 0 | xmlSchemaFacetPtr facet, bfacet, |
16897 | 0 | flength = NULL, ftotdig = NULL, ffracdig = NULL, |
16898 | 0 | fmaxlen = NULL, fminlen = NULL, /* facets of the current type */ |
16899 | 0 | fmininc = NULL, fmaxinc = NULL, |
16900 | 0 | fminexc = NULL, fmaxexc = NULL, |
16901 | 0 | bflength = NULL, bftotdig = NULL, bffracdig = NULL, |
16902 | 0 | bfmaxlen = NULL, bfminlen = NULL, /* facets of the base type */ |
16903 | 0 | bfmininc = NULL, bfmaxinc = NULL, |
16904 | 0 | bfminexc = NULL, bfmaxexc = NULL; |
16905 | 0 | int res; /* err = 0, fixedErr; */ |
16906 | | |
16907 | | /* |
16908 | | * SPEC st-restrict-facets 1: |
16909 | | * "The {variety} of R is the same as that of B." |
16910 | | */ |
16911 | | /* |
16912 | | * SPEC st-restrict-facets 2: |
16913 | | * "If {variety} is atomic, the {primitive type definition} |
16914 | | * of R is the same as that of B." |
16915 | | * |
16916 | | * NOTE: we leave 1 & 2 out for now, since this will be |
16917 | | * satisfied by the derivation process. |
16918 | | * CONSTRUCTION TODO: Maybe needed if using a construction API. |
16919 | | */ |
16920 | | /* |
16921 | | * SPEC st-restrict-facets 3: |
16922 | | * "The {facets} of R are the union of S and the {facets} |
16923 | | * of B, eliminating duplicates. To eliminate duplicates, |
16924 | | * when a facet of the same kind occurs in both S and the |
16925 | | * {facets} of B, the one in the {facets} of B is not |
16926 | | * included, with the exception of enumeration and pattern |
16927 | | * facets, for which multiple occurrences with distinct values |
16928 | | * are allowed." |
16929 | | */ |
16930 | |
|
16931 | 0 | if ((type->facetSet == NULL) && (base->facetSet == NULL)) |
16932 | 0 | return (0); |
16933 | | |
16934 | 0 | last = type->facetSet; |
16935 | 0 | if (last != NULL) |
16936 | 0 | while (last->next != NULL) |
16937 | 0 | last = last->next; |
16938 | |
|
16939 | 0 | for (cur = type->facetSet; cur != NULL; cur = cur->next) { |
16940 | 0 | facet = cur->facet; |
16941 | 0 | switch (facet->type) { |
16942 | 0 | case XML_SCHEMA_FACET_LENGTH: |
16943 | 0 | flength = facet; break; |
16944 | 0 | case XML_SCHEMA_FACET_MINLENGTH: |
16945 | 0 | fminlen = facet; break; |
16946 | 0 | case XML_SCHEMA_FACET_MININCLUSIVE: |
16947 | 0 | fmininc = facet; break; |
16948 | 0 | case XML_SCHEMA_FACET_MINEXCLUSIVE: |
16949 | 0 | fminexc = facet; break; |
16950 | 0 | case XML_SCHEMA_FACET_MAXLENGTH: |
16951 | 0 | fmaxlen = facet; break; |
16952 | 0 | case XML_SCHEMA_FACET_MAXINCLUSIVE: |
16953 | 0 | fmaxinc = facet; break; |
16954 | 0 | case XML_SCHEMA_FACET_MAXEXCLUSIVE: |
16955 | 0 | fmaxexc = facet; break; |
16956 | 0 | case XML_SCHEMA_FACET_TOTALDIGITS: |
16957 | 0 | ftotdig = facet; break; |
16958 | 0 | case XML_SCHEMA_FACET_FRACTIONDIGITS: |
16959 | 0 | ffracdig = facet; break; |
16960 | 0 | default: |
16961 | 0 | break; |
16962 | 0 | } |
16963 | 0 | } |
16964 | 0 | for (cur = base->facetSet; cur != NULL; cur = cur->next) { |
16965 | 0 | facet = cur->facet; |
16966 | 0 | switch (facet->type) { |
16967 | 0 | case XML_SCHEMA_FACET_LENGTH: |
16968 | 0 | bflength = facet; break; |
16969 | 0 | case XML_SCHEMA_FACET_MINLENGTH: |
16970 | 0 | bfminlen = facet; break; |
16971 | 0 | case XML_SCHEMA_FACET_MININCLUSIVE: |
16972 | 0 | bfmininc = facet; break; |
16973 | 0 | case XML_SCHEMA_FACET_MINEXCLUSIVE: |
16974 | 0 | bfminexc = facet; break; |
16975 | 0 | case XML_SCHEMA_FACET_MAXLENGTH: |
16976 | 0 | bfmaxlen = facet; break; |
16977 | 0 | case XML_SCHEMA_FACET_MAXINCLUSIVE: |
16978 | 0 | bfmaxinc = facet; break; |
16979 | 0 | case XML_SCHEMA_FACET_MAXEXCLUSIVE: |
16980 | 0 | bfmaxexc = facet; break; |
16981 | 0 | case XML_SCHEMA_FACET_TOTALDIGITS: |
16982 | 0 | bftotdig = facet; break; |
16983 | 0 | case XML_SCHEMA_FACET_FRACTIONDIGITS: |
16984 | 0 | bffracdig = facet; break; |
16985 | 0 | default: |
16986 | 0 | break; |
16987 | 0 | } |
16988 | 0 | } |
16989 | | /* |
16990 | | * length and minLength or maxLength (2.2) + (3.2) |
16991 | | */ |
16992 | 0 | if (flength && (fminlen || fmaxlen)) { |
16993 | 0 | FACET_RESTR_ERR(flength, "It is an error for both 'length' and " |
16994 | 0 | "either of 'minLength' or 'maxLength' to be specified on " |
16995 | 0 | "the same type definition") |
16996 | 0 | } |
16997 | | /* |
16998 | | * Mutual exclusions in the same derivation step. |
16999 | | */ |
17000 | 0 | if ((fmaxinc) && (fmaxexc)) { |
17001 | | /* |
17002 | | * SCC "maxInclusive and maxExclusive" |
17003 | | */ |
17004 | 0 | FACET_RESTR_MUTUAL_ERR(fmaxinc, fmaxexc) |
17005 | 0 | } |
17006 | 0 | if ((fmininc) && (fminexc)) { |
17007 | | /* |
17008 | | * SCC "minInclusive and minExclusive" |
17009 | | */ |
17010 | 0 | FACET_RESTR_MUTUAL_ERR(fmininc, fminexc) |
17011 | 0 | } |
17012 | |
|
17013 | 0 | if (flength && bflength) { |
17014 | | /* |
17015 | | * SCC "length valid restriction" |
17016 | | * The values have to be equal. |
17017 | | */ |
17018 | 0 | res = xmlSchemaCompareValues(flength->val, bflength->val); |
17019 | 0 | if (res == -2) |
17020 | 0 | goto internal_error; |
17021 | 0 | if (res != 0) |
17022 | 0 | xmlSchemaDeriveFacetErr(pctxt, flength, bflength, 0, 0, 1); |
17023 | 0 | if ((res != 0) && (bflength->fixed)) { |
17024 | 0 | FACET_RESTR_FIXED_ERR(flength) |
17025 | 0 | } |
17026 | |
|
17027 | 0 | } |
17028 | 0 | if (fminlen && bfminlen) { |
17029 | | /* |
17030 | | * SCC "minLength valid restriction" |
17031 | | * minLength >= BASE minLength |
17032 | | */ |
17033 | 0 | res = xmlSchemaCompareValues(fminlen->val, bfminlen->val); |
17034 | 0 | if (res == -2) |
17035 | 0 | goto internal_error; |
17036 | 0 | if (res == -1) |
17037 | 0 | xmlSchemaDeriveFacetErr(pctxt, fminlen, bfminlen, 1, 1, 1); |
17038 | 0 | if ((res != 0) && (bfminlen->fixed)) { |
17039 | 0 | FACET_RESTR_FIXED_ERR(fminlen) |
17040 | 0 | } |
17041 | 0 | } |
17042 | 0 | if (fmaxlen && bfmaxlen) { |
17043 | | /* |
17044 | | * SCC "maxLength valid restriction" |
17045 | | * maxLength <= BASE minLength |
17046 | | */ |
17047 | 0 | res = xmlSchemaCompareValues(fmaxlen->val, bfmaxlen->val); |
17048 | 0 | if (res == -2) |
17049 | 0 | goto internal_error; |
17050 | 0 | if (res == 1) |
17051 | 0 | xmlSchemaDeriveFacetErr(pctxt, fmaxlen, bfmaxlen, -1, 1, 1); |
17052 | 0 | if ((res != 0) && (bfmaxlen->fixed)) { |
17053 | 0 | FACET_RESTR_FIXED_ERR(fmaxlen) |
17054 | 0 | } |
17055 | 0 | } |
17056 | | /* |
17057 | | * SCC "length and minLength or maxLength" |
17058 | | */ |
17059 | 0 | if (! flength) |
17060 | 0 | flength = bflength; |
17061 | 0 | if (flength) { |
17062 | 0 | if (! fminlen) |
17063 | 0 | fminlen = bfminlen; |
17064 | 0 | if (fminlen) { |
17065 | | /* (1.1) length >= minLength */ |
17066 | 0 | res = xmlSchemaCompareValues(flength->val, fminlen->val); |
17067 | 0 | if (res == -2) |
17068 | 0 | goto internal_error; |
17069 | 0 | if (res == -1) |
17070 | 0 | xmlSchemaDeriveFacetErr(pctxt, flength, fminlen, 1, 1, 0); |
17071 | 0 | } |
17072 | 0 | if (! fmaxlen) |
17073 | 0 | fmaxlen = bfmaxlen; |
17074 | 0 | if (fmaxlen) { |
17075 | | /* (2.1) length <= maxLength */ |
17076 | 0 | res = xmlSchemaCompareValues(flength->val, fmaxlen->val); |
17077 | 0 | if (res == -2) |
17078 | 0 | goto internal_error; |
17079 | 0 | if (res == 1) |
17080 | 0 | xmlSchemaDeriveFacetErr(pctxt, flength, fmaxlen, -1, 1, 0); |
17081 | 0 | } |
17082 | 0 | } |
17083 | 0 | if (fmaxinc) { |
17084 | | /* |
17085 | | * "maxInclusive" |
17086 | | */ |
17087 | 0 | if (fmininc) { |
17088 | | /* SCC "maxInclusive >= minInclusive" */ |
17089 | 0 | res = xmlSchemaCompareValues(fmaxinc->val, fmininc->val); |
17090 | 0 | if (res == -2) |
17091 | 0 | goto internal_error; |
17092 | 0 | if (res == -1) { |
17093 | 0 | xmlSchemaDeriveFacetErr(pctxt, fmaxinc, fmininc, 1, 1, 0); |
17094 | 0 | } |
17095 | 0 | } |
17096 | | /* |
17097 | | * SCC "maxInclusive valid restriction" |
17098 | | */ |
17099 | 0 | if (bfmaxinc) { |
17100 | | /* maxInclusive <= BASE maxInclusive */ |
17101 | 0 | res = xmlSchemaCompareValues(fmaxinc->val, bfmaxinc->val); |
17102 | 0 | if (res == -2) |
17103 | 0 | goto internal_error; |
17104 | 0 | if (res == 1) |
17105 | 0 | xmlSchemaDeriveFacetErr(pctxt, fmaxinc, bfmaxinc, -1, 1, 1); |
17106 | 0 | if ((res != 0) && (bfmaxinc->fixed)) { |
17107 | 0 | FACET_RESTR_FIXED_ERR(fmaxinc) |
17108 | 0 | } |
17109 | 0 | } |
17110 | 0 | if (bfmaxexc) { |
17111 | | /* maxInclusive < BASE maxExclusive */ |
17112 | 0 | res = xmlSchemaCompareValues(fmaxinc->val, bfmaxexc->val); |
17113 | 0 | if (res == -2) |
17114 | 0 | goto internal_error; |
17115 | 0 | if (res != -1) { |
17116 | 0 | xmlSchemaDeriveFacetErr(pctxt, fmaxinc, bfmaxexc, -1, 0, 1); |
17117 | 0 | } |
17118 | 0 | } |
17119 | 0 | if (bfmininc) { |
17120 | | /* maxInclusive >= BASE minInclusive */ |
17121 | 0 | res = xmlSchemaCompareValues(fmaxinc->val, bfmininc->val); |
17122 | 0 | if (res == -2) |
17123 | 0 | goto internal_error; |
17124 | 0 | if (res == -1) { |
17125 | 0 | xmlSchemaDeriveFacetErr(pctxt, fmaxinc, bfmininc, 1, 1, 1); |
17126 | 0 | } |
17127 | 0 | } |
17128 | 0 | if (bfminexc) { |
17129 | | /* maxInclusive > BASE minExclusive */ |
17130 | 0 | res = xmlSchemaCompareValues(fmaxinc->val, bfminexc->val); |
17131 | 0 | if (res == -2) |
17132 | 0 | goto internal_error; |
17133 | 0 | if (res != 1) { |
17134 | 0 | xmlSchemaDeriveFacetErr(pctxt, fmaxinc, bfminexc, 1, 0, 1); |
17135 | 0 | } |
17136 | 0 | } |
17137 | 0 | } |
17138 | 0 | if (fmaxexc) { |
17139 | | /* |
17140 | | * "maxExclusive >= minExclusive" |
17141 | | */ |
17142 | 0 | if (fminexc) { |
17143 | 0 | res = xmlSchemaCompareValues(fmaxexc->val, fminexc->val); |
17144 | 0 | if (res == -2) |
17145 | 0 | goto internal_error; |
17146 | 0 | if (res == -1) { |
17147 | 0 | xmlSchemaDeriveFacetErr(pctxt, fmaxexc, fminexc, 1, 1, 0); |
17148 | 0 | } |
17149 | 0 | } |
17150 | | /* |
17151 | | * "maxExclusive valid restriction" |
17152 | | */ |
17153 | 0 | if (bfmaxexc) { |
17154 | | /* maxExclusive <= BASE maxExclusive */ |
17155 | 0 | res = xmlSchemaCompareValues(fmaxexc->val, bfmaxexc->val); |
17156 | 0 | if (res == -2) |
17157 | 0 | goto internal_error; |
17158 | 0 | if (res == 1) { |
17159 | 0 | xmlSchemaDeriveFacetErr(pctxt, fmaxexc, bfmaxexc, -1, 1, 1); |
17160 | 0 | } |
17161 | 0 | if ((res != 0) && (bfmaxexc->fixed)) { |
17162 | 0 | FACET_RESTR_FIXED_ERR(fmaxexc) |
17163 | 0 | } |
17164 | 0 | } |
17165 | 0 | if (bfmaxinc) { |
17166 | | /* maxExclusive <= BASE maxInclusive */ |
17167 | 0 | res = xmlSchemaCompareValues(fmaxexc->val, bfmaxinc->val); |
17168 | 0 | if (res == -2) |
17169 | 0 | goto internal_error; |
17170 | 0 | if (res == 1) { |
17171 | 0 | xmlSchemaDeriveFacetErr(pctxt, fmaxexc, bfmaxinc, -1, 1, 1); |
17172 | 0 | } |
17173 | 0 | } |
17174 | 0 | if (bfmininc) { |
17175 | | /* maxExclusive > BASE minInclusive */ |
17176 | 0 | res = xmlSchemaCompareValues(fmaxexc->val, bfmininc->val); |
17177 | 0 | if (res == -2) |
17178 | 0 | goto internal_error; |
17179 | 0 | if (res != 1) { |
17180 | 0 | xmlSchemaDeriveFacetErr(pctxt, fmaxexc, bfmininc, 1, 0, 1); |
17181 | 0 | } |
17182 | 0 | } |
17183 | 0 | if (bfminexc) { |
17184 | | /* maxExclusive > BASE minExclusive */ |
17185 | 0 | res = xmlSchemaCompareValues(fmaxexc->val, bfminexc->val); |
17186 | 0 | if (res == -2) |
17187 | 0 | goto internal_error; |
17188 | 0 | if (res != 1) { |
17189 | 0 | xmlSchemaDeriveFacetErr(pctxt, fmaxexc, bfminexc, 1, 0, 1); |
17190 | 0 | } |
17191 | 0 | } |
17192 | 0 | } |
17193 | 0 | if (fminexc) { |
17194 | | /* |
17195 | | * "minExclusive < maxInclusive" |
17196 | | */ |
17197 | 0 | if (fmaxinc) { |
17198 | 0 | res = xmlSchemaCompareValues(fminexc->val, fmaxinc->val); |
17199 | 0 | if (res == -2) |
17200 | 0 | goto internal_error; |
17201 | 0 | if (res != -1) { |
17202 | 0 | xmlSchemaDeriveFacetErr(pctxt, fminexc, fmaxinc, -1, 0, 0); |
17203 | 0 | } |
17204 | 0 | } |
17205 | | /* |
17206 | | * "minExclusive valid restriction" |
17207 | | */ |
17208 | 0 | if (bfminexc) { |
17209 | | /* minExclusive >= BASE minExclusive */ |
17210 | 0 | res = xmlSchemaCompareValues(fminexc->val, bfminexc->val); |
17211 | 0 | if (res == -2) |
17212 | 0 | goto internal_error; |
17213 | 0 | if (res == -1) { |
17214 | 0 | xmlSchemaDeriveFacetErr(pctxt, fminexc, bfminexc, 1, 1, 1); |
17215 | 0 | } |
17216 | 0 | if ((res != 0) && (bfminexc->fixed)) { |
17217 | 0 | FACET_RESTR_FIXED_ERR(fminexc) |
17218 | 0 | } |
17219 | 0 | } |
17220 | 0 | if (bfmaxinc) { |
17221 | | /* minExclusive <= BASE maxInclusive */ |
17222 | 0 | res = xmlSchemaCompareValues(fminexc->val, bfmaxinc->val); |
17223 | 0 | if (res == -2) |
17224 | 0 | goto internal_error; |
17225 | 0 | if (res == 1) { |
17226 | 0 | xmlSchemaDeriveFacetErr(pctxt, fminexc, bfmaxinc, -1, 1, 1); |
17227 | 0 | } |
17228 | 0 | } |
17229 | 0 | if (bfmininc) { |
17230 | | /* minExclusive >= BASE minInclusive */ |
17231 | 0 | res = xmlSchemaCompareValues(fminexc->val, bfmininc->val); |
17232 | 0 | if (res == -2) |
17233 | 0 | goto internal_error; |
17234 | 0 | if (res == -1) { |
17235 | 0 | xmlSchemaDeriveFacetErr(pctxt, fminexc, bfmininc, 1, 1, 1); |
17236 | 0 | } |
17237 | 0 | } |
17238 | 0 | if (bfmaxexc) { |
17239 | | /* minExclusive < BASE maxExclusive */ |
17240 | 0 | res = xmlSchemaCompareValues(fminexc->val, bfmaxexc->val); |
17241 | 0 | if (res == -2) |
17242 | 0 | goto internal_error; |
17243 | 0 | if (res != -1) { |
17244 | 0 | xmlSchemaDeriveFacetErr(pctxt, fminexc, bfmaxexc, -1, 0, 1); |
17245 | 0 | } |
17246 | 0 | } |
17247 | 0 | } |
17248 | 0 | if (fmininc) { |
17249 | | /* |
17250 | | * "minInclusive < maxExclusive" |
17251 | | */ |
17252 | 0 | if (fmaxexc) { |
17253 | 0 | res = xmlSchemaCompareValues(fmininc->val, fmaxexc->val); |
17254 | 0 | if (res == -2) |
17255 | 0 | goto internal_error; |
17256 | 0 | if (res != -1) { |
17257 | 0 | xmlSchemaDeriveFacetErr(pctxt, fmininc, fmaxexc, -1, 0, 0); |
17258 | 0 | } |
17259 | 0 | } |
17260 | | /* |
17261 | | * "minExclusive valid restriction" |
17262 | | */ |
17263 | 0 | if (bfmininc) { |
17264 | | /* minInclusive >= BASE minInclusive */ |
17265 | 0 | res = xmlSchemaCompareValues(fmininc->val, bfmininc->val); |
17266 | 0 | if (res == -2) |
17267 | 0 | goto internal_error; |
17268 | 0 | if (res == -1) { |
17269 | 0 | xmlSchemaDeriveFacetErr(pctxt, fmininc, bfmininc, 1, 1, 1); |
17270 | 0 | } |
17271 | 0 | if ((res != 0) && (bfmininc->fixed)) { |
17272 | 0 | FACET_RESTR_FIXED_ERR(fmininc) |
17273 | 0 | } |
17274 | 0 | } |
17275 | 0 | if (bfmaxinc) { |
17276 | | /* minInclusive <= BASE maxInclusive */ |
17277 | 0 | res = xmlSchemaCompareValues(fmininc->val, bfmaxinc->val); |
17278 | 0 | if (res == -2) |
17279 | 0 | goto internal_error; |
17280 | 0 | if (res == 1) { |
17281 | 0 | xmlSchemaDeriveFacetErr(pctxt, fmininc, bfmaxinc, -1, 1, 1); |
17282 | 0 | } |
17283 | 0 | } |
17284 | 0 | if (bfminexc) { |
17285 | | /* minInclusive > BASE minExclusive */ |
17286 | 0 | res = xmlSchemaCompareValues(fmininc->val, bfminexc->val); |
17287 | 0 | if (res == -2) |
17288 | 0 | goto internal_error; |
17289 | 0 | if (res != 1) |
17290 | 0 | xmlSchemaDeriveFacetErr(pctxt, fmininc, bfminexc, 1, 0, 1); |
17291 | 0 | } |
17292 | 0 | if (bfmaxexc) { |
17293 | | /* minInclusive < BASE maxExclusive */ |
17294 | 0 | res = xmlSchemaCompareValues(fmininc->val, bfmaxexc->val); |
17295 | 0 | if (res == -2) |
17296 | 0 | goto internal_error; |
17297 | 0 | if (res != -1) |
17298 | 0 | xmlSchemaDeriveFacetErr(pctxt, fmininc, bfmaxexc, -1, 0, 1); |
17299 | 0 | } |
17300 | 0 | } |
17301 | 0 | if (ftotdig && bftotdig) { |
17302 | | /* |
17303 | | * SCC " totalDigits valid restriction" |
17304 | | * totalDigits <= BASE totalDigits |
17305 | | */ |
17306 | 0 | res = xmlSchemaCompareValues(ftotdig->val, bftotdig->val); |
17307 | 0 | if (res == -2) |
17308 | 0 | goto internal_error; |
17309 | 0 | if (res == 1) |
17310 | 0 | xmlSchemaDeriveFacetErr(pctxt, ftotdig, bftotdig, |
17311 | 0 | -1, 1, 1); |
17312 | 0 | if ((res != 0) && (bftotdig->fixed)) { |
17313 | 0 | FACET_RESTR_FIXED_ERR(ftotdig) |
17314 | 0 | } |
17315 | 0 | } |
17316 | 0 | if (ffracdig && bffracdig) { |
17317 | | /* |
17318 | | * SCC "fractionDigits valid restriction" |
17319 | | * fractionDigits <= BASE fractionDigits |
17320 | | */ |
17321 | 0 | res = xmlSchemaCompareValues(ffracdig->val, bffracdig->val); |
17322 | 0 | if (res == -2) |
17323 | 0 | goto internal_error; |
17324 | 0 | if (res == 1) |
17325 | 0 | xmlSchemaDeriveFacetErr(pctxt, ffracdig, bffracdig, |
17326 | 0 | -1, 1, 1); |
17327 | 0 | if ((res != 0) && (bffracdig->fixed)) { |
17328 | 0 | FACET_RESTR_FIXED_ERR(ffracdig) |
17329 | 0 | } |
17330 | 0 | } |
17331 | | /* |
17332 | | * SCC "fractionDigits less than or equal to totalDigits" |
17333 | | */ |
17334 | 0 | if (! ftotdig) |
17335 | 0 | ftotdig = bftotdig; |
17336 | 0 | if (! ffracdig) |
17337 | 0 | ffracdig = bffracdig; |
17338 | 0 | if (ftotdig && ffracdig) { |
17339 | 0 | res = xmlSchemaCompareValues(ffracdig->val, ftotdig->val); |
17340 | 0 | if (res == -2) |
17341 | 0 | goto internal_error; |
17342 | 0 | if (res == 1) |
17343 | 0 | xmlSchemaDeriveFacetErr(pctxt, ffracdig, ftotdig, |
17344 | 0 | -1, 1, 0); |
17345 | 0 | } |
17346 | | /* |
17347 | | * *Enumerations* won' be added here, since only the first set |
17348 | | * of enumerations in the ancestor-or-self axis is used |
17349 | | * for validation, plus we need to use the base type of those |
17350 | | * enumerations for whitespace. |
17351 | | * |
17352 | | * *Patterns*: won't be add here, since they are ORed at |
17353 | | * type level and ANDed at ancestor level. This will |
17354 | | * happen during validation by walking the base axis |
17355 | | * of the type. |
17356 | | */ |
17357 | 0 | for (cur = base->facetSet; cur != NULL; cur = cur->next) { |
17358 | 0 | bfacet = cur->facet; |
17359 | | /* |
17360 | | * Special handling of enumerations and patterns. |
17361 | | * TODO: hmm, they should not appear in the set, so remove this. |
17362 | | */ |
17363 | 0 | if ((bfacet->type == XML_SCHEMA_FACET_PATTERN) || |
17364 | 0 | (bfacet->type == XML_SCHEMA_FACET_ENUMERATION)) |
17365 | 0 | continue; |
17366 | | /* |
17367 | | * Search for a duplicate facet in the current type. |
17368 | | */ |
17369 | 0 | link = type->facetSet; |
17370 | | /* err = 0; */ |
17371 | | /* fixedErr = 0; */ |
17372 | 0 | while (link != NULL) { |
17373 | 0 | facet = link->facet; |
17374 | 0 | if (facet->type == bfacet->type) { |
17375 | 0 | switch (facet->type) { |
17376 | 0 | case XML_SCHEMA_FACET_WHITESPACE: |
17377 | | /* |
17378 | | * The whitespace must be stronger. |
17379 | | */ |
17380 | 0 | if (facet->whitespace < bfacet->whitespace) { |
17381 | 0 | FACET_RESTR_ERR(facet, |
17382 | 0 | "The 'whitespace' value has to be equal to " |
17383 | 0 | "or stronger than the 'whitespace' value of " |
17384 | 0 | "the base type") |
17385 | 0 | } |
17386 | 0 | if ((bfacet->fixed) && |
17387 | 0 | (facet->whitespace != bfacet->whitespace)) { |
17388 | 0 | FACET_RESTR_FIXED_ERR(facet) |
17389 | 0 | } |
17390 | 0 | break; |
17391 | 0 | default: |
17392 | 0 | break; |
17393 | 0 | } |
17394 | | /* Duplicate found. */ |
17395 | 0 | break; |
17396 | 0 | } |
17397 | 0 | link = link->next; |
17398 | 0 | } |
17399 | | /* |
17400 | | * If no duplicate was found: add the base types's facet |
17401 | | * to the set. |
17402 | | */ |
17403 | 0 | if (link == NULL) { |
17404 | 0 | link = (xmlSchemaFacetLinkPtr) |
17405 | 0 | xmlMalloc(sizeof(xmlSchemaFacetLink)); |
17406 | 0 | if (link == NULL) { |
17407 | 0 | xmlSchemaPErrMemory(pctxt); |
17408 | 0 | return (-1); |
17409 | 0 | } |
17410 | 0 | link->facet = cur->facet; |
17411 | 0 | link->next = NULL; |
17412 | 0 | if (last == NULL) |
17413 | 0 | type->facetSet = link; |
17414 | 0 | else |
17415 | 0 | last->next = link; |
17416 | 0 | last = link; |
17417 | 0 | } |
17418 | |
|
17419 | 0 | } |
17420 | | |
17421 | 0 | return (0); |
17422 | 0 | internal_error: |
17423 | 0 | PERROR_INT("xmlSchemaDeriveAndValidateFacets", |
17424 | 0 | "an error occurred"); |
17425 | 0 | return (-1); |
17426 | 0 | } |
17427 | | |
17428 | | static int |
17429 | | xmlSchemaFinishMemberTypeDefinitionsProperty(xmlSchemaParserCtxtPtr pctxt, |
17430 | | xmlSchemaTypePtr type) |
17431 | 0 | { |
17432 | 0 | xmlSchemaTypeLinkPtr link, lastLink, prevLink, subLink, newLink; |
17433 | | /* |
17434 | | * The actual value is then formed by replacing any union type |
17435 | | * definition in the `explicit members` with the members of their |
17436 | | * {member type definitions}, in order. |
17437 | | * |
17438 | | * TODO: There's a bug entry at |
17439 | | * "http://lists.w3.org/Archives/Public/www-xml-schema-comments/2005JulSep/0287.html" |
17440 | | * which indicates that we'll keep the union types the future. |
17441 | | */ |
17442 | 0 | link = type->memberTypes; |
17443 | 0 | while (link != NULL) { |
17444 | |
|
17445 | 0 | if (WXS_IS_TYPE_NOT_FIXED(link->type)) |
17446 | 0 | xmlSchemaTypeFixup(link->type, ACTXT_CAST pctxt); |
17447 | |
|
17448 | 0 | if (WXS_IS_UNION(link->type)) { |
17449 | 0 | subLink = xmlSchemaGetUnionSimpleTypeMemberTypes(link->type); |
17450 | 0 | if (subLink != NULL) { |
17451 | 0 | link->type = subLink->type; |
17452 | 0 | if (subLink->next != NULL) { |
17453 | 0 | lastLink = link->next; |
17454 | 0 | subLink = subLink->next; |
17455 | 0 | prevLink = link; |
17456 | 0 | while (subLink != NULL) { |
17457 | 0 | newLink = (xmlSchemaTypeLinkPtr) |
17458 | 0 | xmlMalloc(sizeof(xmlSchemaTypeLink)); |
17459 | 0 | if (newLink == NULL) { |
17460 | 0 | xmlSchemaPErrMemory(pctxt); |
17461 | 0 | return (-1); |
17462 | 0 | } |
17463 | 0 | newLink->type = subLink->type; |
17464 | 0 | prevLink->next = newLink; |
17465 | 0 | prevLink = newLink; |
17466 | 0 | newLink->next = lastLink; |
17467 | |
|
17468 | 0 | subLink = subLink->next; |
17469 | 0 | } |
17470 | 0 | } |
17471 | 0 | } |
17472 | 0 | } |
17473 | 0 | link = link->next; |
17474 | 0 | } |
17475 | 0 | return (0); |
17476 | 0 | } |
17477 | | |
17478 | | static void |
17479 | | xmlSchemaTypeFixupOptimFacets(xmlSchemaTypePtr type) |
17480 | 0 | { |
17481 | 0 | int has = 0, needVal = 0, normVal = 0; |
17482 | |
|
17483 | 0 | has = (type->baseType->flags & XML_SCHEMAS_TYPE_HAS_FACETS) ? 1 : 0; |
17484 | 0 | if (has) { |
17485 | 0 | needVal = (type->baseType->flags & |
17486 | 0 | XML_SCHEMAS_TYPE_FACETSNEEDVALUE) ? 1 : 0; |
17487 | 0 | normVal = (type->baseType->flags & |
17488 | 0 | XML_SCHEMAS_TYPE_NORMVALUENEEDED) ? 1 : 0; |
17489 | 0 | } |
17490 | 0 | if (type->facets != NULL) { |
17491 | 0 | xmlSchemaFacetPtr fac; |
17492 | |
|
17493 | 0 | for (fac = type->facets; fac != NULL; fac = fac->next) { |
17494 | 0 | switch (fac->type) { |
17495 | 0 | case XML_SCHEMA_FACET_WHITESPACE: |
17496 | 0 | break; |
17497 | 0 | case XML_SCHEMA_FACET_PATTERN: |
17498 | 0 | normVal = 1; |
17499 | 0 | has = 1; |
17500 | 0 | break; |
17501 | 0 | case XML_SCHEMA_FACET_ENUMERATION: |
17502 | 0 | needVal = 1; |
17503 | 0 | normVal = 1; |
17504 | 0 | has = 1; |
17505 | 0 | break; |
17506 | 0 | default: |
17507 | 0 | has = 1; |
17508 | 0 | break; |
17509 | 0 | } |
17510 | 0 | } |
17511 | 0 | } |
17512 | 0 | if (normVal) |
17513 | 0 | type->flags |= XML_SCHEMAS_TYPE_NORMVALUENEEDED; |
17514 | 0 | if (needVal) |
17515 | 0 | type->flags |= XML_SCHEMAS_TYPE_FACETSNEEDVALUE; |
17516 | 0 | if (has) |
17517 | 0 | type->flags |= XML_SCHEMAS_TYPE_HAS_FACETS; |
17518 | |
|
17519 | 0 | if (has && (! needVal) && WXS_IS_ATOMIC(type)) { |
17520 | 0 | xmlSchemaTypePtr prim = xmlSchemaGetPrimitiveType(type); |
17521 | | /* |
17522 | | * OPTIMIZE VAL TODO: Some facets need a computed value. |
17523 | | */ |
17524 | 0 | if ((prim->builtInType != XML_SCHEMAS_ANYSIMPLETYPE) && |
17525 | 0 | (prim->builtInType != XML_SCHEMAS_STRING)) { |
17526 | 0 | type->flags |= XML_SCHEMAS_TYPE_FACETSNEEDVALUE; |
17527 | 0 | } |
17528 | 0 | } |
17529 | 0 | } |
17530 | | |
17531 | | static int |
17532 | | xmlSchemaTypeFixupWhitespace(xmlSchemaTypePtr type) |
17533 | 0 | { |
17534 | | |
17535 | | |
17536 | | /* |
17537 | | * Evaluate the whitespace-facet value. |
17538 | | */ |
17539 | 0 | if (WXS_IS_LIST(type)) { |
17540 | 0 | type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_COLLAPSE; |
17541 | 0 | return (0); |
17542 | 0 | } else if (WXS_IS_UNION(type)) |
17543 | 0 | return (0); |
17544 | | |
17545 | 0 | if (type->facetSet != NULL) { |
17546 | 0 | xmlSchemaFacetLinkPtr lin; |
17547 | |
|
17548 | 0 | for (lin = type->facetSet; lin != NULL; lin = lin->next) { |
17549 | 0 | if (lin->facet->type == XML_SCHEMA_FACET_WHITESPACE) { |
17550 | 0 | switch (lin->facet->whitespace) { |
17551 | 0 | case XML_SCHEMAS_FACET_PRESERVE: |
17552 | 0 | type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_PRESERVE; |
17553 | 0 | break; |
17554 | 0 | case XML_SCHEMAS_FACET_REPLACE: |
17555 | 0 | type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_REPLACE; |
17556 | 0 | break; |
17557 | 0 | case XML_SCHEMAS_FACET_COLLAPSE: |
17558 | 0 | type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_COLLAPSE; |
17559 | 0 | break; |
17560 | 0 | default: |
17561 | 0 | return (-1); |
17562 | 0 | } |
17563 | 0 | return (0); |
17564 | 0 | } |
17565 | 0 | } |
17566 | 0 | } |
17567 | | /* |
17568 | | * For all `atomic` datatypes other than string (and types `derived` |
17569 | | * by `restriction` from it) the value of whiteSpace is fixed to |
17570 | | * collapse |
17571 | | */ |
17572 | 0 | { |
17573 | 0 | xmlSchemaTypePtr anc; |
17574 | |
|
17575 | 0 | for (anc = type->baseType; anc != NULL && |
17576 | 0 | anc->builtInType != XML_SCHEMAS_ANYTYPE; |
17577 | 0 | anc = anc->baseType) { |
17578 | |
|
17579 | 0 | if (anc->type == XML_SCHEMA_TYPE_BASIC) { |
17580 | 0 | if (anc->builtInType == XML_SCHEMAS_NORMSTRING) { |
17581 | 0 | type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_REPLACE; |
17582 | |
|
17583 | 0 | } else if ((anc->builtInType == XML_SCHEMAS_STRING) || |
17584 | 0 | (anc->builtInType == XML_SCHEMAS_ANYSIMPLETYPE)) { |
17585 | 0 | type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_PRESERVE; |
17586 | |
|
17587 | 0 | } else |
17588 | 0 | type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_COLLAPSE; |
17589 | 0 | break; |
17590 | 0 | } |
17591 | 0 | } |
17592 | 0 | } |
17593 | 0 | return (0); |
17594 | 0 | } |
17595 | | |
17596 | | static int |
17597 | | xmlSchemaFixupSimpleTypeStageOne(xmlSchemaParserCtxtPtr pctxt, |
17598 | | xmlSchemaTypePtr type) |
17599 | 0 | { |
17600 | 0 | if (type->type != XML_SCHEMA_TYPE_SIMPLE) |
17601 | 0 | return(0); |
17602 | 0 | if (! WXS_IS_TYPE_NOT_FIXED_1(type)) |
17603 | 0 | return(0); |
17604 | 0 | type->flags |= XML_SCHEMAS_TYPE_FIXUP_1; |
17605 | |
|
17606 | 0 | if (WXS_IS_LIST(type)) { |
17607 | | /* |
17608 | | * Corresponds to <simpleType><list>... |
17609 | | */ |
17610 | 0 | if (type->subtypes == NULL) { |
17611 | | /* |
17612 | | * This one is really needed, so get out. |
17613 | | */ |
17614 | 0 | PERROR_INT("xmlSchemaFixupSimpleTypeStageOne", |
17615 | 0 | "list type has no item-type assigned"); |
17616 | 0 | return(-1); |
17617 | 0 | } |
17618 | 0 | } else if (WXS_IS_UNION(type)) { |
17619 | | /* |
17620 | | * Corresponds to <simpleType><union>... |
17621 | | */ |
17622 | 0 | if (type->memberTypes == NULL) { |
17623 | | /* |
17624 | | * This one is really needed, so get out. |
17625 | | */ |
17626 | 0 | PERROR_INT("xmlSchemaFixupSimpleTypeStageOne", |
17627 | 0 | "union type has no member-types assigned"); |
17628 | 0 | return(-1); |
17629 | 0 | } |
17630 | 0 | } else { |
17631 | | /* |
17632 | | * Corresponds to <simpleType><restriction>... |
17633 | | */ |
17634 | 0 | if (type->baseType == NULL) { |
17635 | 0 | PERROR_INT("xmlSchemaFixupSimpleTypeStageOne", |
17636 | 0 | "type has no base-type assigned"); |
17637 | 0 | return(-1); |
17638 | 0 | } |
17639 | 0 | if (WXS_IS_TYPE_NOT_FIXED_1(type->baseType)) |
17640 | 0 | if (xmlSchemaFixupSimpleTypeStageOne(pctxt, type->baseType) == -1) |
17641 | 0 | return(-1); |
17642 | | /* |
17643 | | * Variety |
17644 | | * If the <restriction> alternative is chosen, then the |
17645 | | * {variety} of the {base type definition}. |
17646 | | */ |
17647 | 0 | if (WXS_IS_ATOMIC(type->baseType)) |
17648 | 0 | type->flags |= XML_SCHEMAS_TYPE_VARIETY_ATOMIC; |
17649 | 0 | else if (WXS_IS_LIST(type->baseType)) { |
17650 | 0 | type->flags |= XML_SCHEMAS_TYPE_VARIETY_LIST; |
17651 | | /* |
17652 | | * Inherit the itemType. |
17653 | | */ |
17654 | 0 | type->subtypes = type->baseType->subtypes; |
17655 | 0 | } else if (WXS_IS_UNION(type->baseType)) { |
17656 | 0 | type->flags |= XML_SCHEMAS_TYPE_VARIETY_UNION; |
17657 | | /* |
17658 | | * NOTE that we won't assign the memberTypes of the base, |
17659 | | * since this will make trouble when freeing them; we will |
17660 | | * use a lookup function to access them instead. |
17661 | | */ |
17662 | 0 | } |
17663 | 0 | } |
17664 | 0 | return(0); |
17665 | 0 | } |
17666 | | |
17667 | | /* |
17668 | | * 3.14.6 Constraints on Simple Type Definition Schema Components |
17669 | | */ |
17670 | | static int |
17671 | | xmlSchemaFixupSimpleTypeStageTwo(xmlSchemaParserCtxtPtr pctxt, |
17672 | | xmlSchemaTypePtr type) |
17673 | 0 | { |
17674 | 0 | int res, olderrs = pctxt->nberrors; |
17675 | |
|
17676 | 0 | if (type->type != XML_SCHEMA_TYPE_SIMPLE) |
17677 | 0 | return(-1); |
17678 | | |
17679 | 0 | if (! WXS_IS_TYPE_NOT_FIXED(type)) |
17680 | 0 | return(0); |
17681 | | |
17682 | 0 | type->flags |= XML_SCHEMAS_TYPE_INTERNAL_RESOLVED; |
17683 | 0 | type->contentType = XML_SCHEMA_CONTENT_SIMPLE; |
17684 | |
|
17685 | 0 | if (type->baseType == NULL) { |
17686 | 0 | PERROR_INT("xmlSchemaFixupSimpleTypeStageTwo", |
17687 | 0 | "missing baseType"); |
17688 | 0 | goto exit_failure; |
17689 | 0 | } |
17690 | 0 | if (WXS_IS_TYPE_NOT_FIXED(type->baseType)) |
17691 | 0 | xmlSchemaTypeFixup(type->baseType, ACTXT_CAST pctxt); |
17692 | | /* |
17693 | | * If a member type of a union is a union itself, we need to substitute |
17694 | | * that member type for its member types. |
17695 | | * NOTE that this might change in WXS 1.1; i.e. we will keep the union |
17696 | | * types in WXS 1.1. |
17697 | | */ |
17698 | 0 | if ((type->memberTypes != NULL) && |
17699 | 0 | (xmlSchemaFinishMemberTypeDefinitionsProperty(pctxt, type) == -1)) |
17700 | 0 | return(-1); |
17701 | | /* |
17702 | | * SPEC src-simple-type 1 |
17703 | | * "The corresponding simple type definition, if any, must satisfy |
17704 | | * the conditions set out in Constraints on Simple Type Definition |
17705 | | * Schema Components ($3.14.6)." |
17706 | | */ |
17707 | | /* |
17708 | | * Schema Component Constraint: Simple Type Definition Properties Correct |
17709 | | * (st-props-correct) |
17710 | | */ |
17711 | 0 | res = xmlSchemaCheckSTPropsCorrect(pctxt, type); |
17712 | 0 | HFAILURE HERROR |
17713 | | /* |
17714 | | * Schema Component Constraint: Derivation Valid (Restriction, Simple) |
17715 | | * (cos-st-restricts) |
17716 | | */ |
17717 | 0 | res = xmlSchemaCheckCOSSTRestricts(pctxt, type); |
17718 | 0 | HFAILURE HERROR |
17719 | | /* |
17720 | | * TODO: Removed the error report, since it got annoying to get an |
17721 | | * extra error report, if anything failed until now. |
17722 | | * Enable this if needed. |
17723 | | * |
17724 | | * xmlSchemaPErr(ctxt, type->node, |
17725 | | * XML_SCHEMAP_SRC_SIMPLE_TYPE_1, |
17726 | | * "Simple type '%s' does not satisfy the constraints " |
17727 | | * "on simple type definitions.\n", |
17728 | | * type->name, NULL); |
17729 | | */ |
17730 | | /* |
17731 | | * Schema Component Constraint: Simple Type Restriction (Facets) |
17732 | | * (st-restrict-facets) |
17733 | | */ |
17734 | 0 | res = xmlSchemaCheckFacetValues(type, pctxt); |
17735 | 0 | HFAILURE HERROR |
17736 | 0 | if ((type->facetSet != NULL) || |
17737 | 0 | (type->baseType->facetSet != NULL)) { |
17738 | 0 | res = xmlSchemaDeriveAndValidateFacets(pctxt, type); |
17739 | 0 | HFAILURE HERROR |
17740 | 0 | } |
17741 | | /* |
17742 | | * Whitespace value. |
17743 | | */ |
17744 | 0 | res = xmlSchemaTypeFixupWhitespace(type); |
17745 | 0 | HFAILURE HERROR |
17746 | 0 | xmlSchemaTypeFixupOptimFacets(type); |
17747 | |
|
17748 | 0 | exit_error: |
17749 | 0 | if (olderrs != pctxt->nberrors) |
17750 | 0 | return(pctxt->err); |
17751 | 0 | return(0); |
17752 | | |
17753 | 0 | exit_failure: |
17754 | 0 | return(-1); |
17755 | 0 | } |
17756 | | |
17757 | | static int |
17758 | | xmlSchemaFixupComplexType(xmlSchemaParserCtxtPtr pctxt, |
17759 | | xmlSchemaTypePtr type) |
17760 | 0 | { |
17761 | 0 | int res = 0, olderrs = pctxt->nberrors; |
17762 | 0 | xmlSchemaTypePtr baseType = type->baseType; |
17763 | |
|
17764 | 0 | if (! WXS_IS_TYPE_NOT_FIXED(type)) |
17765 | 0 | return(0); |
17766 | 0 | type->flags |= XML_SCHEMAS_TYPE_INTERNAL_RESOLVED; |
17767 | 0 | if (baseType == NULL) { |
17768 | 0 | PERROR_INT("xmlSchemaFixupComplexType", |
17769 | 0 | "missing baseType"); |
17770 | 0 | goto exit_failure; |
17771 | 0 | } |
17772 | | /* |
17773 | | * Fixup the base type. |
17774 | | */ |
17775 | 0 | if (WXS_IS_TYPE_NOT_FIXED(baseType)) |
17776 | 0 | xmlSchemaTypeFixup(baseType, ACTXT_CAST pctxt); |
17777 | 0 | if (baseType->flags & XML_SCHEMAS_TYPE_INTERNAL_INVALID) { |
17778 | | /* |
17779 | | * Skip fixup if the base type is invalid. |
17780 | | * TODO: Generate a warning! |
17781 | | */ |
17782 | 0 | return(0); |
17783 | 0 | } |
17784 | | /* |
17785 | | * This basically checks if the base type can be derived. |
17786 | | */ |
17787 | 0 | res = xmlSchemaCheckSRCCT(pctxt, type); |
17788 | 0 | HFAILURE HERROR |
17789 | | /* |
17790 | | * Fixup the content type. |
17791 | | */ |
17792 | 0 | if (type->contentType == XML_SCHEMA_CONTENT_SIMPLE) { |
17793 | | /* |
17794 | | * Corresponds to <complexType><simpleContent>... |
17795 | | */ |
17796 | 0 | if ((WXS_IS_COMPLEX(baseType)) && |
17797 | 0 | (baseType->contentTypeDef != NULL) && |
17798 | 0 | (WXS_IS_RESTRICTION(type))) { |
17799 | 0 | xmlSchemaTypePtr contentBase, content; |
17800 | | #ifdef ENABLE_NAMED_LOCALS |
17801 | | char buf[30]; |
17802 | | const xmlChar *tmpname; |
17803 | | #endif |
17804 | | /* |
17805 | | * SPEC (1) If <restriction> + base type is <complexType>, |
17806 | | * "whose own {content type} is a simple type..." |
17807 | | */ |
17808 | 0 | if (type->contentTypeDef != NULL) { |
17809 | | /* |
17810 | | * SPEC (1.1) "the simple type definition corresponding to the |
17811 | | * <simpleType> among the [children] of <restriction> if there |
17812 | | * is one;" |
17813 | | * Note that this "<simpleType> among the [children]" was put |
17814 | | * into ->contentTypeDef during parsing. |
17815 | | */ |
17816 | 0 | contentBase = type->contentTypeDef; |
17817 | 0 | type->contentTypeDef = NULL; |
17818 | 0 | } else { |
17819 | | /* |
17820 | | * (1.2) "...otherwise (<restriction> has no <simpleType> |
17821 | | * among its [children]), the simple type definition which |
17822 | | * is the {content type} of the ... base type." |
17823 | | */ |
17824 | 0 | contentBase = baseType->contentTypeDef; |
17825 | 0 | } |
17826 | | /* |
17827 | | * SPEC |
17828 | | * "... a simple type definition which restricts the simple |
17829 | | * type definition identified in clause 1.1 or clause 1.2 |
17830 | | * with a set of facet components" |
17831 | | * |
17832 | | * Create the anonymous simple type, which will be the content |
17833 | | * type of the complex type. |
17834 | | */ |
17835 | | #ifdef ENABLE_NAMED_LOCALS |
17836 | | snprintf(buf, 29, "#scST%d", ++(pctxt->counter)); |
17837 | | tmpname = xmlDictLookup(pctxt->dict, BAD_CAST buf, -1); |
17838 | | content = xmlSchemaAddType(pctxt, pctxt->schema, |
17839 | | XML_SCHEMA_TYPE_SIMPLE, tmpname, type->targetNamespace, |
17840 | | type->node, 0); |
17841 | | #else |
17842 | 0 | content = xmlSchemaAddType(pctxt, pctxt->schema, |
17843 | 0 | XML_SCHEMA_TYPE_SIMPLE, NULL, type->targetNamespace, |
17844 | 0 | type->node, 0); |
17845 | 0 | #endif |
17846 | 0 | if (content == NULL) |
17847 | 0 | goto exit_failure; |
17848 | | /* |
17849 | | * We will use the same node as for the <complexType> |
17850 | | * to have it somehow anchored in the schema doc. |
17851 | | */ |
17852 | 0 | content->type = XML_SCHEMA_TYPE_SIMPLE; |
17853 | 0 | content->baseType = contentBase; |
17854 | | /* |
17855 | | * Move the facets, previously anchored on the |
17856 | | * complexType during parsing. |
17857 | | */ |
17858 | 0 | content->facets = type->facets; |
17859 | 0 | type->facets = NULL; |
17860 | 0 | content->facetSet = type->facetSet; |
17861 | 0 | type->facetSet = NULL; |
17862 | |
|
17863 | 0 | type->contentTypeDef = content; |
17864 | 0 | if (WXS_IS_TYPE_NOT_FIXED(contentBase)) |
17865 | 0 | xmlSchemaTypeFixup(contentBase, ACTXT_CAST pctxt); |
17866 | | /* |
17867 | | * Fixup the newly created type. We don't need to check |
17868 | | * for circularity here. |
17869 | | */ |
17870 | 0 | res = xmlSchemaFixupSimpleTypeStageOne(pctxt, content); |
17871 | 0 | HFAILURE HERROR |
17872 | 0 | res = xmlSchemaFixupSimpleTypeStageTwo(pctxt, content); |
17873 | 0 | HFAILURE HERROR |
17874 | |
|
17875 | 0 | } else if ((WXS_IS_COMPLEX(baseType)) && |
17876 | 0 | (baseType->contentType == XML_SCHEMA_CONTENT_MIXED) && |
17877 | 0 | (WXS_IS_RESTRICTION(type))) { |
17878 | | /* |
17879 | | * SPEC (2) If <restriction> + base is a mixed <complexType> with |
17880 | | * an emptiable particle, then a simple type definition which |
17881 | | * restricts the <restriction>'s <simpleType> child. |
17882 | | */ |
17883 | 0 | if ((type->contentTypeDef == NULL) || |
17884 | 0 | (type->contentTypeDef->baseType == NULL)) { |
17885 | | /* |
17886 | | * TODO: Check if this ever happens. |
17887 | | */ |
17888 | 0 | xmlSchemaPCustomErr(pctxt, |
17889 | 0 | XML_SCHEMAP_INTERNAL, |
17890 | 0 | WXS_BASIC_CAST type, NULL, |
17891 | 0 | "Internal error: xmlSchemaTypeFixup, " |
17892 | 0 | "complex type '%s': the <simpleContent><restriction> " |
17893 | 0 | "is missing a <simpleType> child, but was not caught " |
17894 | 0 | "by xmlSchemaCheckSRCCT()", type->name); |
17895 | 0 | goto exit_failure; |
17896 | 0 | } |
17897 | 0 | } else if ((WXS_IS_COMPLEX(baseType)) && WXS_IS_EXTENSION(type)) { |
17898 | | /* |
17899 | | * SPEC (3) If <extension> + base is <complexType> with |
17900 | | * <simpleType> content, "...then the {content type} of that |
17901 | | * complex type definition" |
17902 | | */ |
17903 | 0 | if (baseType->contentTypeDef == NULL) { |
17904 | | /* |
17905 | | * TODO: Check if this ever happens. xmlSchemaCheckSRCCT |
17906 | | * should have caught this already. |
17907 | | */ |
17908 | 0 | xmlSchemaPCustomErr(pctxt, |
17909 | 0 | XML_SCHEMAP_INTERNAL, |
17910 | 0 | WXS_BASIC_CAST type, NULL, |
17911 | 0 | "Internal error: xmlSchemaTypeFixup, " |
17912 | 0 | "complex type '%s': the <extension>ed base type is " |
17913 | 0 | "a complex type with no simple content type", |
17914 | 0 | type->name); |
17915 | 0 | goto exit_failure; |
17916 | 0 | } |
17917 | 0 | type->contentTypeDef = baseType->contentTypeDef; |
17918 | 0 | } else if ((WXS_IS_SIMPLE(baseType)) && WXS_IS_EXTENSION(type)) { |
17919 | | /* |
17920 | | * SPEC (4) <extension> + base is <simpleType> |
17921 | | * "... then that simple type definition" |
17922 | | */ |
17923 | 0 | type->contentTypeDef = baseType; |
17924 | 0 | } else { |
17925 | | /* |
17926 | | * TODO: Check if this ever happens. |
17927 | | */ |
17928 | 0 | xmlSchemaPCustomErr(pctxt, |
17929 | 0 | XML_SCHEMAP_INTERNAL, |
17930 | 0 | WXS_BASIC_CAST type, NULL, |
17931 | 0 | "Internal error: xmlSchemaTypeFixup, " |
17932 | 0 | "complex type '%s' with <simpleContent>: unhandled " |
17933 | 0 | "derivation case", type->name); |
17934 | 0 | goto exit_failure; |
17935 | 0 | } |
17936 | 0 | } else { |
17937 | 0 | int dummySequence = 0; |
17938 | 0 | xmlSchemaParticlePtr particle = |
17939 | 0 | (xmlSchemaParticlePtr) type->subtypes; |
17940 | | /* |
17941 | | * Corresponds to <complexType><complexContent>... |
17942 | | * |
17943 | | * NOTE that the effective mixed was already set during parsing of |
17944 | | * <complexType> and <complexContent>; its flag value is |
17945 | | * XML_SCHEMAS_TYPE_MIXED. |
17946 | | * |
17947 | | * Compute the "effective content": |
17948 | | * (2.1.1) + (2.1.2) + (2.1.3) |
17949 | | */ |
17950 | 0 | if ((particle == NULL) || |
17951 | 0 | ((particle->type == XML_SCHEMA_TYPE_PARTICLE) && |
17952 | 0 | ((particle->children->type == XML_SCHEMA_TYPE_ALL) || |
17953 | 0 | (particle->children->type == XML_SCHEMA_TYPE_SEQUENCE) || |
17954 | 0 | ((particle->children->type == XML_SCHEMA_TYPE_CHOICE) && |
17955 | 0 | (particle->minOccurs == 0))) && |
17956 | 0 | ( ((xmlSchemaTreeItemPtr) particle->children)->children == NULL))) { |
17957 | 0 | if (type->flags & XML_SCHEMAS_TYPE_MIXED) { |
17958 | | /* |
17959 | | * SPEC (2.1.4) "If the `effective mixed` is true, then |
17960 | | * a particle whose properties are as follows:..." |
17961 | | * |
17962 | | * Empty sequence model group with |
17963 | | * minOccurs/maxOccurs = 1 (i.e. a "particle emptiable"). |
17964 | | * NOTE that we sill assign it the <complexType> node to |
17965 | | * somehow anchor it in the doc. |
17966 | | */ |
17967 | 0 | if ((particle == NULL) || |
17968 | 0 | (particle->children->type != XML_SCHEMA_TYPE_SEQUENCE)) { |
17969 | | /* |
17970 | | * Create the particle. |
17971 | | */ |
17972 | 0 | particle = xmlSchemaAddParticle(pctxt, |
17973 | 0 | type->node, 1, 1); |
17974 | 0 | if (particle == NULL) |
17975 | 0 | goto exit_failure; |
17976 | | /* |
17977 | | * Create the model group. |
17978 | | */ /* URGENT TODO: avoid adding to pending items. */ |
17979 | 0 | particle->children = (xmlSchemaTreeItemPtr) |
17980 | 0 | xmlSchemaAddModelGroup(pctxt, pctxt->schema, |
17981 | 0 | XML_SCHEMA_TYPE_SEQUENCE, type->node); |
17982 | 0 | if (particle->children == NULL) |
17983 | 0 | goto exit_failure; |
17984 | | |
17985 | 0 | type->subtypes = (xmlSchemaTypePtr) particle; |
17986 | 0 | } |
17987 | 0 | dummySequence = 1; |
17988 | 0 | type->contentType = XML_SCHEMA_CONTENT_ELEMENTS; |
17989 | 0 | } else { |
17990 | | /* |
17991 | | * SPEC (2.1.5) "otherwise empty" |
17992 | | */ |
17993 | 0 | type->contentType = XML_SCHEMA_CONTENT_EMPTY; |
17994 | 0 | } |
17995 | 0 | } else { |
17996 | | /* |
17997 | | * SPEC (2.2) "otherwise the particle corresponding to the |
17998 | | * <all>, <choice>, <group> or <sequence> among the |
17999 | | * [children]." |
18000 | | */ |
18001 | 0 | type->contentType = XML_SCHEMA_CONTENT_ELEMENTS; |
18002 | 0 | } |
18003 | | /* |
18004 | | * Compute the "content type". |
18005 | | */ |
18006 | 0 | if (WXS_IS_RESTRICTION(type)) { |
18007 | | /* |
18008 | | * SPEC (3.1) "If <restriction>..." |
18009 | | * (3.1.1) + (3.1.2) */ |
18010 | 0 | if (type->contentType != XML_SCHEMA_CONTENT_EMPTY) { |
18011 | 0 | if (type->flags & XML_SCHEMAS_TYPE_MIXED) |
18012 | 0 | type->contentType = XML_SCHEMA_CONTENT_MIXED; |
18013 | 0 | } |
18014 | 0 | } else { |
18015 | | /* |
18016 | | * SPEC (3.2) "If <extension>..." |
18017 | | */ |
18018 | 0 | if (type->contentType == XML_SCHEMA_CONTENT_EMPTY) { |
18019 | | /* |
18020 | | * SPEC (3.2.1) |
18021 | | * "If the `effective content` is empty, then the |
18022 | | * {content type} of the [...] base ..." |
18023 | | */ |
18024 | 0 | type->contentType = baseType->contentType; |
18025 | 0 | type->subtypes = baseType->subtypes; |
18026 | | /* |
18027 | | * Fixes bug #347316: |
18028 | | * This is the case when the base type has a simple |
18029 | | * type definition as content. |
18030 | | */ |
18031 | 0 | type->contentTypeDef = baseType->contentTypeDef; |
18032 | | /* |
18033 | | * NOTE that the effective mixed is ignored here. |
18034 | | */ |
18035 | 0 | } else if (baseType->contentType == XML_SCHEMA_CONTENT_EMPTY) { |
18036 | | /* |
18037 | | * SPEC (3.2.2) |
18038 | | */ |
18039 | 0 | if (type->flags & XML_SCHEMAS_TYPE_MIXED) |
18040 | 0 | type->contentType = XML_SCHEMA_CONTENT_MIXED; |
18041 | 0 | } else { |
18042 | | /* |
18043 | | * SPEC (3.2.3) |
18044 | | */ |
18045 | 0 | if (type->flags & XML_SCHEMAS_TYPE_MIXED) |
18046 | 0 | type->contentType = XML_SCHEMA_CONTENT_MIXED; |
18047 | | /* |
18048 | | * "A model group whose {compositor} is sequence and whose |
18049 | | * {particles} are..." |
18050 | | */ |
18051 | 0 | if ((WXS_TYPE_PARTICLE(type) != NULL) && |
18052 | 0 | (WXS_TYPE_PARTICLE_TERM(type) != NULL) && |
18053 | 0 | ((WXS_TYPE_PARTICLE_TERM(type))->type == |
18054 | 0 | XML_SCHEMA_TYPE_ALL)) |
18055 | 0 | { |
18056 | | /* |
18057 | | * SPEC cos-all-limited (1) |
18058 | | */ |
18059 | 0 | xmlSchemaCustomErr(ACTXT_CAST pctxt, |
18060 | | /* TODO: error code */ |
18061 | 0 | XML_SCHEMAP_COS_ALL_LIMITED, |
18062 | 0 | WXS_ITEM_NODE(type), NULL, |
18063 | 0 | "The type has an 'all' model group in its " |
18064 | 0 | "{content type} and thus cannot be derived from " |
18065 | 0 | "a non-empty type, since this would produce a " |
18066 | 0 | "'sequence' model group containing the 'all' " |
18067 | 0 | "model group; 'all' model groups are not " |
18068 | 0 | "allowed to appear inside other model groups", |
18069 | 0 | NULL, NULL); |
18070 | |
|
18071 | 0 | } else if ((WXS_TYPE_PARTICLE(baseType) != NULL) && |
18072 | 0 | (WXS_TYPE_PARTICLE_TERM(baseType) != NULL) && |
18073 | 0 | ((WXS_TYPE_PARTICLE_TERM(baseType))->type == |
18074 | 0 | XML_SCHEMA_TYPE_ALL)) |
18075 | 0 | { |
18076 | | /* |
18077 | | * SPEC cos-all-limited (1) |
18078 | | */ |
18079 | 0 | xmlSchemaCustomErr(ACTXT_CAST pctxt, |
18080 | | /* TODO: error code */ |
18081 | 0 | XML_SCHEMAP_COS_ALL_LIMITED, |
18082 | 0 | WXS_ITEM_NODE(type), NULL, |
18083 | 0 | "A type cannot be derived by extension from a type " |
18084 | 0 | "which has an 'all' model group in its " |
18085 | 0 | "{content type}, since this would produce a " |
18086 | 0 | "'sequence' model group containing the 'all' " |
18087 | 0 | "model group; 'all' model groups are not " |
18088 | 0 | "allowed to appear inside other model groups", |
18089 | 0 | NULL, NULL); |
18090 | |
|
18091 | 0 | } else if ((!dummySequence) && (baseType->subtypes != NULL)) { |
18092 | 0 | xmlSchemaTreeItemPtr effectiveContent = |
18093 | 0 | (xmlSchemaTreeItemPtr) type->subtypes; |
18094 | | /* |
18095 | | * Create the particle. |
18096 | | */ |
18097 | 0 | particle = xmlSchemaAddParticle(pctxt, |
18098 | 0 | type->node, 1, 1); |
18099 | 0 | if (particle == NULL) |
18100 | 0 | goto exit_failure; |
18101 | | /* |
18102 | | * Create the "sequence" model group. |
18103 | | */ |
18104 | 0 | particle->children = (xmlSchemaTreeItemPtr) |
18105 | 0 | xmlSchemaAddModelGroup(pctxt, pctxt->schema, |
18106 | 0 | XML_SCHEMA_TYPE_SEQUENCE, type->node); |
18107 | 0 | if (particle->children == NULL) |
18108 | 0 | goto exit_failure; |
18109 | 0 | WXS_TYPE_CONTENTTYPE(type) = (xmlSchemaTypePtr) particle; |
18110 | | /* |
18111 | | * SPEC "the particle of the {content type} of |
18112 | | * the ... base ..." |
18113 | | * Create a duplicate of the base type's particle |
18114 | | * and assign its "term" to it. |
18115 | | */ |
18116 | 0 | particle->children->children = |
18117 | 0 | (xmlSchemaTreeItemPtr) xmlSchemaAddParticle(pctxt, |
18118 | 0 | type->node, |
18119 | 0 | ((xmlSchemaParticlePtr) baseType->subtypes)->minOccurs, |
18120 | 0 | ((xmlSchemaParticlePtr) baseType->subtypes)->maxOccurs); |
18121 | 0 | if (particle->children->children == NULL) |
18122 | 0 | goto exit_failure; |
18123 | 0 | particle = (xmlSchemaParticlePtr) |
18124 | 0 | particle->children->children; |
18125 | 0 | particle->children = |
18126 | 0 | ((xmlSchemaParticlePtr) baseType->subtypes)->children; |
18127 | | /* |
18128 | | * SPEC "followed by the `effective content`." |
18129 | | */ |
18130 | 0 | particle->next = effectiveContent; |
18131 | | /* |
18132 | | * This all will result in: |
18133 | | * new-particle |
18134 | | * --> new-sequence( |
18135 | | * new-particle |
18136 | | * --> base-model, |
18137 | | * this-particle |
18138 | | * --> this-model |
18139 | | * ) |
18140 | | */ |
18141 | 0 | } else { |
18142 | | /* |
18143 | | * This is the case when there is already an empty |
18144 | | * <sequence> with minOccurs==maxOccurs==1. |
18145 | | * Just add the base types's content type. |
18146 | | * NOTE that, although we miss to add an intermediate |
18147 | | * <sequence>, this should produce no difference to |
18148 | | * neither the regex compilation of the content model, |
18149 | | * nor to the complex type constraints. |
18150 | | */ |
18151 | 0 | particle->children->children = |
18152 | 0 | (xmlSchemaTreeItemPtr) baseType->subtypes; |
18153 | 0 | } |
18154 | 0 | } |
18155 | 0 | } |
18156 | 0 | } |
18157 | | /* |
18158 | | * Now fixup attribute uses: |
18159 | | * - expand attr. group references |
18160 | | * - intersect attribute wildcards |
18161 | | * - inherit attribute uses of the base type |
18162 | | * - inherit or union attr. wildcards if extending |
18163 | | * - apply attr. use prohibitions if restricting |
18164 | | */ |
18165 | 0 | res = xmlSchemaFixupTypeAttributeUses(pctxt, type); |
18166 | 0 | HFAILURE HERROR |
18167 | | /* |
18168 | | * Apply the complex type component constraints; this will not |
18169 | | * check attributes, since this is done in |
18170 | | * xmlSchemaFixupTypeAttributeUses(). |
18171 | | */ |
18172 | 0 | res = xmlSchemaCheckCTComponent(pctxt, type); |
18173 | 0 | HFAILURE HERROR |
18174 | | |
18175 | 0 | if (olderrs != pctxt->nberrors) |
18176 | 0 | return(pctxt->err); |
18177 | 0 | else |
18178 | 0 | return(0); |
18179 | | |
18180 | 0 | exit_error: |
18181 | 0 | type->flags |= XML_SCHEMAS_TYPE_INTERNAL_INVALID; |
18182 | 0 | return(pctxt->err); |
18183 | | |
18184 | 0 | exit_failure: |
18185 | 0 | type->flags |= XML_SCHEMAS_TYPE_INTERNAL_INVALID; |
18186 | 0 | return(-1); |
18187 | 0 | } |
18188 | | |
18189 | | |
18190 | | /** |
18191 | | * Fixes the content model of the type. |
18192 | | * URGENT TODO: We need an int result! |
18193 | | * |
18194 | | * @param type the schema type definition |
18195 | | * @param actxt the schema parser context |
18196 | | */ |
18197 | | static int |
18198 | | xmlSchemaTypeFixup(xmlSchemaTypePtr type, |
18199 | | xmlSchemaAbstractCtxtPtr actxt) |
18200 | 0 | { |
18201 | 0 | if (type == NULL) |
18202 | 0 | return(0); |
18203 | 0 | if (actxt->type != XML_SCHEMA_CTXT_PARSER) { |
18204 | 0 | AERROR_INT("xmlSchemaTypeFixup", |
18205 | 0 | "this function needs a parser context"); |
18206 | 0 | return(-1); |
18207 | 0 | } |
18208 | 0 | if (! WXS_IS_TYPE_NOT_FIXED(type)) |
18209 | 0 | return(0); |
18210 | 0 | if (type->type == XML_SCHEMA_TYPE_COMPLEX) |
18211 | 0 | return(xmlSchemaFixupComplexType(PCTXT_CAST actxt, type)); |
18212 | 0 | else if (type->type == XML_SCHEMA_TYPE_SIMPLE) |
18213 | 0 | return(xmlSchemaFixupSimpleTypeStageTwo(PCTXT_CAST actxt, type)); |
18214 | 0 | return(0); |
18215 | 0 | } |
18216 | | |
18217 | | /** |
18218 | | * Checks and computes the values of facets. |
18219 | | * |
18220 | | * @param facet the facet |
18221 | | * @param typeDecl the schema type definition |
18222 | | * @param pctxt the schema parser context or NULL |
18223 | | * @param name the optional name of the type |
18224 | | * @returns 0 if valid, a positive error code if not valid and |
18225 | | * -1 in case of an internal or API error. |
18226 | | */ |
18227 | | int |
18228 | | xmlSchemaCheckFacet(xmlSchemaFacet *facet, |
18229 | | xmlSchemaType *typeDecl, |
18230 | | xmlSchemaParserCtxt *pctxt, |
18231 | | const xmlChar * name ATTRIBUTE_UNUSED) |
18232 | 0 | { |
18233 | 0 | int ret = 0, ctxtGiven; |
18234 | |
|
18235 | 0 | if ((facet == NULL) || (typeDecl == NULL)) |
18236 | 0 | return(-1); |
18237 | | /* |
18238 | | * TODO: will the parser context be given if used from |
18239 | | * the relaxNG module? |
18240 | | */ |
18241 | 0 | if (pctxt == NULL) |
18242 | 0 | ctxtGiven = 0; |
18243 | 0 | else |
18244 | 0 | ctxtGiven = 1; |
18245 | |
|
18246 | 0 | switch (facet->type) { |
18247 | 0 | case XML_SCHEMA_FACET_MININCLUSIVE: |
18248 | 0 | case XML_SCHEMA_FACET_MINEXCLUSIVE: |
18249 | 0 | case XML_SCHEMA_FACET_MAXINCLUSIVE: |
18250 | 0 | case XML_SCHEMA_FACET_MAXEXCLUSIVE: |
18251 | 0 | case XML_SCHEMA_FACET_ENUMERATION: { |
18252 | | /* |
18253 | | * Okay we need to validate the value |
18254 | | * at that point. |
18255 | | */ |
18256 | 0 | xmlSchemaTypePtr base; |
18257 | | |
18258 | | /* 4.3.5.5 Constraints on enumeration Schema Components |
18259 | | * Schema Component Constraint: enumeration valid restriction |
18260 | | * It is an `error` if any member of {value} is not in the |
18261 | | * `value space` of {base type definition}. |
18262 | | * |
18263 | | * minInclusive, maxInclusive, minExclusive, maxExclusive: |
18264 | | * The value `must` be in the |
18265 | | * `value space` of the `base type`. |
18266 | | */ |
18267 | | /* |
18268 | | * This function is intended to deliver a compiled value |
18269 | | * on the facet. In this implementation of XML Schemata the |
18270 | | * type holding a facet, won't be a built-in type. |
18271 | | * Thus to ensure that other API |
18272 | | * calls (relaxng) do work, if the given type is a built-in |
18273 | | * type, we will assume that the given built-in type *is |
18274 | | * already* the base type. |
18275 | | */ |
18276 | 0 | if (typeDecl->type != XML_SCHEMA_TYPE_BASIC) { |
18277 | 0 | base = typeDecl->baseType; |
18278 | 0 | if (base == NULL) { |
18279 | 0 | PERROR_INT("xmlSchemaCheckFacet", |
18280 | 0 | "a type user derived type has no base type"); |
18281 | 0 | return (-1); |
18282 | 0 | } |
18283 | 0 | } else |
18284 | 0 | base = typeDecl; |
18285 | | |
18286 | 0 | if (! ctxtGiven) { |
18287 | | /* |
18288 | | * A context is needed if called from RelaxNG. |
18289 | | */ |
18290 | 0 | pctxt = xmlSchemaNewParserCtxt("*"); |
18291 | 0 | if (pctxt == NULL) |
18292 | 0 | return (-1); |
18293 | 0 | } |
18294 | | /* |
18295 | | * NOTE: This call does not check the content nodes, |
18296 | | * since they are not available: |
18297 | | * facet->node is just the node holding the facet |
18298 | | * definition, *not* the attribute holding the *value* |
18299 | | * of the facet. |
18300 | | */ |
18301 | 0 | ret = xmlSchemaVCheckCVCSimpleType( |
18302 | 0 | ACTXT_CAST pctxt, facet->node, base, |
18303 | 0 | facet->value, &(facet->val), 1, 1, 0); |
18304 | 0 | if (ret != 0) { |
18305 | 0 | if (ret < 0) { |
18306 | | /* No error message for RelaxNG. */ |
18307 | 0 | if (ctxtGiven) { |
18308 | 0 | xmlSchemaCustomErr(ACTXT_CAST pctxt, |
18309 | 0 | XML_SCHEMAP_INTERNAL, facet->node, NULL, |
18310 | 0 | "Internal error: xmlSchemaCheckFacet, " |
18311 | 0 | "failed to validate the value '%s' of the " |
18312 | 0 | "facet '%s' against the base type", |
18313 | 0 | facet->value, xmlSchemaFacetTypeToString(facet->type)); |
18314 | 0 | } |
18315 | 0 | goto internal_error; |
18316 | 0 | } |
18317 | 0 | ret = XML_SCHEMAP_INVALID_FACET_VALUE; |
18318 | | /* No error message for RelaxNG. */ |
18319 | 0 | if (ctxtGiven) { |
18320 | 0 | xmlChar *str = NULL; |
18321 | |
|
18322 | 0 | xmlSchemaCustomErr(ACTXT_CAST pctxt, |
18323 | 0 | ret, facet->node, WXS_BASIC_CAST facet, |
18324 | 0 | "The value '%s' of the facet does not validate " |
18325 | 0 | "against the base type '%s'", |
18326 | 0 | facet->value, |
18327 | 0 | xmlSchemaFormatQName(&str, |
18328 | 0 | base->targetNamespace, base->name)); |
18329 | 0 | FREE_AND_NULL(str); |
18330 | 0 | } |
18331 | 0 | goto exit; |
18332 | 0 | } else if (facet->val == NULL) { |
18333 | 0 | if (ctxtGiven) { |
18334 | 0 | PERROR_INT("xmlSchemaCheckFacet", |
18335 | 0 | "value was not computed"); |
18336 | 0 | } |
18337 | | /* TODO */ |
18338 | 0 | } |
18339 | 0 | break; |
18340 | 0 | } |
18341 | 0 | case XML_SCHEMA_FACET_PATTERN: |
18342 | 0 | facet->regexp = xmlRegexpCompile(facet->value); |
18343 | 0 | if (facet->regexp == NULL) { |
18344 | 0 | ret = XML_SCHEMAP_REGEXP_INVALID; |
18345 | | /* No error message for RelaxNG. */ |
18346 | 0 | if (ctxtGiven) { |
18347 | 0 | xmlSchemaCustomErr(ACTXT_CAST pctxt, |
18348 | 0 | ret, facet->node, WXS_BASIC_CAST typeDecl, |
18349 | 0 | "The value '%s' of the facet 'pattern' is not a " |
18350 | 0 | "valid regular expression", |
18351 | 0 | facet->value, NULL); |
18352 | 0 | } |
18353 | 0 | } |
18354 | 0 | break; |
18355 | 0 | case XML_SCHEMA_FACET_TOTALDIGITS: |
18356 | 0 | case XML_SCHEMA_FACET_FRACTIONDIGITS: |
18357 | 0 | case XML_SCHEMA_FACET_LENGTH: |
18358 | 0 | case XML_SCHEMA_FACET_MAXLENGTH: |
18359 | 0 | case XML_SCHEMA_FACET_MINLENGTH: |
18360 | |
|
18361 | 0 | if (facet->type == XML_SCHEMA_FACET_TOTALDIGITS) { |
18362 | 0 | ret = xmlSchemaValidatePredefinedType( |
18363 | 0 | xmlSchemaGetBuiltInType(XML_SCHEMAS_PINTEGER), |
18364 | 0 | facet->value, &(facet->val)); |
18365 | 0 | } else { |
18366 | 0 | ret = xmlSchemaValidatePredefinedType( |
18367 | 0 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NNINTEGER), |
18368 | 0 | facet->value, &(facet->val)); |
18369 | 0 | } |
18370 | 0 | if (ret != 0) { |
18371 | 0 | if (ret < 0) { |
18372 | | /* No error message for RelaxNG. */ |
18373 | 0 | if (ctxtGiven) { |
18374 | 0 | PERROR_INT("xmlSchemaCheckFacet", |
18375 | 0 | "validating facet value"); |
18376 | 0 | } |
18377 | 0 | goto internal_error; |
18378 | 0 | } |
18379 | 0 | ret = XML_SCHEMAP_INVALID_FACET_VALUE; |
18380 | | /* No error message for RelaxNG. */ |
18381 | 0 | if (ctxtGiven) { |
18382 | | /* error code */ |
18383 | 0 | xmlSchemaCustomErr4(ACTXT_CAST pctxt, |
18384 | 0 | ret, facet->node, WXS_BASIC_CAST typeDecl, |
18385 | 0 | "The value '%s' of the facet '%s' is not a valid '%s'", |
18386 | 0 | facet->value, |
18387 | 0 | xmlSchemaFacetTypeToString(facet->type), |
18388 | 0 | (facet->type != XML_SCHEMA_FACET_TOTALDIGITS) ? |
18389 | 0 | BAD_CAST "nonNegativeInteger" : |
18390 | 0 | BAD_CAST "positiveInteger", |
18391 | 0 | NULL); |
18392 | 0 | } |
18393 | 0 | } |
18394 | 0 | break; |
18395 | | |
18396 | 0 | case XML_SCHEMA_FACET_WHITESPACE:{ |
18397 | 0 | if (xmlStrEqual(facet->value, BAD_CAST "preserve")) { |
18398 | 0 | facet->whitespace = XML_SCHEMAS_FACET_PRESERVE; |
18399 | 0 | } else if (xmlStrEqual(facet->value, BAD_CAST "replace")) { |
18400 | 0 | facet->whitespace = XML_SCHEMAS_FACET_REPLACE; |
18401 | 0 | } else if (xmlStrEqual(facet->value, BAD_CAST "collapse")) { |
18402 | 0 | facet->whitespace = XML_SCHEMAS_FACET_COLLAPSE; |
18403 | 0 | } else { |
18404 | 0 | ret = XML_SCHEMAP_INVALID_FACET_VALUE; |
18405 | | /* No error message for RelaxNG. */ |
18406 | 0 | if (ctxtGiven) { |
18407 | | /* error was previously: XML_SCHEMAP_INVALID_WHITE_SPACE */ |
18408 | 0 | xmlSchemaCustomErr(ACTXT_CAST pctxt, |
18409 | 0 | ret, facet->node, WXS_BASIC_CAST typeDecl, |
18410 | 0 | "The value '%s' of the facet 'whitespace' is not " |
18411 | 0 | "valid", facet->value, NULL); |
18412 | 0 | } |
18413 | 0 | } |
18414 | 0 | } |
18415 | 0 | default: |
18416 | 0 | break; |
18417 | 0 | } |
18418 | 0 | exit: |
18419 | 0 | if ((! ctxtGiven) && (pctxt != NULL)) |
18420 | 0 | xmlSchemaFreeParserCtxt(pctxt); |
18421 | 0 | return (ret); |
18422 | 0 | internal_error: |
18423 | 0 | if ((! ctxtGiven) && (pctxt != NULL)) |
18424 | 0 | xmlSchemaFreeParserCtxt(pctxt); |
18425 | 0 | return (-1); |
18426 | 0 | } |
18427 | | |
18428 | | /** |
18429 | | * Checks the default values types, especially for facets |
18430 | | * |
18431 | | * @param typeDecl the schema type definition |
18432 | | * @param pctxt the schema parser context |
18433 | | */ |
18434 | | static int |
18435 | | xmlSchemaCheckFacetValues(xmlSchemaTypePtr typeDecl, |
18436 | | xmlSchemaParserCtxtPtr pctxt) |
18437 | 0 | { |
18438 | 0 | int res, olderrs = pctxt->nberrors; |
18439 | 0 | const xmlChar *name = typeDecl->name; |
18440 | | /* |
18441 | | * NOTE: It is intended to use the facets list, instead |
18442 | | * of facetSet. |
18443 | | */ |
18444 | 0 | if (typeDecl->facets != NULL) { |
18445 | 0 | xmlSchemaFacetPtr facet = typeDecl->facets; |
18446 | | |
18447 | | /* |
18448 | | * Temporarily assign the "schema" to the validation context |
18449 | | * of the parser context. This is needed for NOTATION validation. |
18450 | | */ |
18451 | 0 | if (pctxt->vctxt == NULL) { |
18452 | 0 | if (xmlSchemaCreateVCtxtOnPCtxt(pctxt) == -1) |
18453 | 0 | return(-1); |
18454 | 0 | } |
18455 | 0 | pctxt->vctxt->schema = pctxt->schema; |
18456 | 0 | while (facet != NULL) { |
18457 | 0 | res = xmlSchemaCheckFacet(facet, typeDecl, pctxt, name); |
18458 | 0 | HFAILURE |
18459 | 0 | facet = facet->next; |
18460 | 0 | } |
18461 | 0 | pctxt->vctxt->schema = NULL; |
18462 | 0 | } |
18463 | 0 | if (olderrs != pctxt->nberrors) |
18464 | 0 | return(pctxt->err); |
18465 | 0 | return(0); |
18466 | 0 | exit_failure: |
18467 | 0 | return(-1); |
18468 | 0 | } |
18469 | | |
18470 | | /** |
18471 | | * This one is intended to be used by |
18472 | | * xmlSchemaCheckGroupDefCircular only. |
18473 | | * |
18474 | | * @param groupDef the searched model group |
18475 | | * @param particle the first particle |
18476 | | * @returns the particle with the circular model group definition reference, |
18477 | | * otherwise NULL. |
18478 | | */ |
18479 | | static xmlSchemaTreeItemPtr |
18480 | | xmlSchemaGetCircModelGrDefRef(xmlSchemaModelGroupDefPtr groupDef, |
18481 | | xmlSchemaTreeItemPtr particle) |
18482 | 0 | { |
18483 | 0 | xmlSchemaTreeItemPtr circ = NULL; |
18484 | 0 | xmlSchemaTreeItemPtr term; |
18485 | 0 | xmlSchemaModelGroupDefPtr gdef; |
18486 | |
|
18487 | 0 | for (; particle != NULL; particle = particle->next) { |
18488 | 0 | term = particle->children; |
18489 | 0 | if (term == NULL) |
18490 | 0 | continue; |
18491 | 0 | switch (term->type) { |
18492 | 0 | case XML_SCHEMA_TYPE_GROUP: |
18493 | 0 | gdef = (xmlSchemaModelGroupDefPtr) term; |
18494 | 0 | if (gdef == groupDef) |
18495 | 0 | return (particle); |
18496 | | /* |
18497 | | * Mark this model group definition to avoid infinite |
18498 | | * recursion on circular references not yet examined. |
18499 | | */ |
18500 | 0 | if (gdef->flags & XML_SCHEMA_MODEL_GROUP_DEF_MARKED) |
18501 | 0 | continue; |
18502 | 0 | if (gdef->children != NULL) { |
18503 | 0 | gdef->flags |= XML_SCHEMA_MODEL_GROUP_DEF_MARKED; |
18504 | 0 | circ = xmlSchemaGetCircModelGrDefRef(groupDef, |
18505 | 0 | gdef->children->children); |
18506 | 0 | gdef->flags ^= XML_SCHEMA_MODEL_GROUP_DEF_MARKED; |
18507 | 0 | if (circ != NULL) |
18508 | 0 | return (circ); |
18509 | 0 | } |
18510 | 0 | break; |
18511 | 0 | case XML_SCHEMA_TYPE_SEQUENCE: |
18512 | 0 | case XML_SCHEMA_TYPE_CHOICE: |
18513 | 0 | case XML_SCHEMA_TYPE_ALL: |
18514 | 0 | circ = xmlSchemaGetCircModelGrDefRef(groupDef, term->children); |
18515 | 0 | if (circ != NULL) |
18516 | 0 | return (circ); |
18517 | 0 | break; |
18518 | 0 | default: |
18519 | 0 | break; |
18520 | 0 | } |
18521 | 0 | } |
18522 | 0 | return (NULL); |
18523 | 0 | } |
18524 | | |
18525 | | /** |
18526 | | * Checks for circular references to model group definitions. |
18527 | | * |
18528 | | * @param item the model group definition |
18529 | | * @param ctxt the parser context |
18530 | | */ |
18531 | | static void |
18532 | | xmlSchemaCheckGroupDefCircular(xmlSchemaModelGroupDefPtr item, |
18533 | | xmlSchemaParserCtxtPtr ctxt) |
18534 | 0 | { |
18535 | | /* |
18536 | | * Schema Component Constraint: Model Group Correct |
18537 | | * 2 Circular groups are disallowed. That is, within the {particles} |
18538 | | * of a group there must not be at any depth a particle whose {term} |
18539 | | * is the group itself. |
18540 | | */ |
18541 | 0 | if ((item == NULL) || |
18542 | 0 | (item->type != XML_SCHEMA_TYPE_GROUP) || |
18543 | 0 | (item->children == NULL)) |
18544 | 0 | return; |
18545 | 0 | { |
18546 | 0 | xmlSchemaTreeItemPtr circ; |
18547 | |
|
18548 | 0 | circ = xmlSchemaGetCircModelGrDefRef(item, item->children->children); |
18549 | 0 | if (circ != NULL) { |
18550 | 0 | xmlChar *str = NULL; |
18551 | | /* |
18552 | | * TODO: The error report is not adequate: this constraint |
18553 | | * is defined for model groups but not definitions, but since |
18554 | | * there cannot be any circular model groups without a model group |
18555 | | * definition (if not using a construction API), we check those |
18556 | | * definitions only. |
18557 | | */ |
18558 | 0 | xmlSchemaPCustomErr(ctxt, |
18559 | 0 | XML_SCHEMAP_MG_PROPS_CORRECT_2, |
18560 | 0 | NULL, WXS_ITEM_NODE(circ), |
18561 | 0 | "Circular reference to the model group definition '%s' " |
18562 | 0 | "defined", xmlSchemaFormatQName(&str, |
18563 | 0 | item->targetNamespace, item->name)); |
18564 | 0 | FREE_AND_NULL(str) |
18565 | | /* |
18566 | | * NOTE: We will cut the reference to avoid further |
18567 | | * confusion of the processor. This is a fatal error. |
18568 | | */ |
18569 | 0 | circ->children = NULL; |
18570 | 0 | } |
18571 | 0 | } |
18572 | 0 | } |
18573 | | |
18574 | | /** |
18575 | | * Assigns the model group of model group definitions to the "term" |
18576 | | * of the referencing particle. |
18577 | | * In xmlSchemaResolveModelGroupParticleReferences the model group |
18578 | | * definitions were assigned to the "term", since needed for the |
18579 | | * circularity check. |
18580 | | * |
18581 | | * Schema Component Constraint: |
18582 | | * All Group Limited (cos-all-limited) (1.2) |
18583 | | * @param ctxt the parser context |
18584 | | * @param mg the model group |
18585 | | */ |
18586 | | static void |
18587 | | xmlSchemaModelGroupToModelGroupDefFixup( |
18588 | | xmlSchemaParserCtxtPtr ctxt ATTRIBUTE_UNUSED, |
18589 | | xmlSchemaModelGroupPtr mg) |
18590 | 0 | { |
18591 | 0 | xmlSchemaParticlePtr particle = WXS_MODELGROUP_PARTICLE(mg); |
18592 | |
|
18593 | 0 | while (particle != NULL) { |
18594 | 0 | if ((WXS_PARTICLE_TERM(particle) == NULL) || |
18595 | 0 | ((WXS_PARTICLE_TERM(particle))->type != |
18596 | 0 | XML_SCHEMA_TYPE_GROUP)) |
18597 | 0 | { |
18598 | 0 | particle = WXS_PTC_CAST particle->next; |
18599 | 0 | continue; |
18600 | 0 | } |
18601 | 0 | if (WXS_MODELGROUPDEF_MODEL(WXS_PARTICLE_TERM(particle)) == NULL) { |
18602 | | /* |
18603 | | * TODO: Remove the particle. |
18604 | | */ |
18605 | 0 | WXS_PARTICLE_TERM(particle) = NULL; |
18606 | 0 | particle = WXS_PTC_CAST particle->next; |
18607 | 0 | continue; |
18608 | 0 | } |
18609 | | /* |
18610 | | * Assign the model group to the {term} of the particle. |
18611 | | */ |
18612 | 0 | WXS_PARTICLE_TERM(particle) = |
18613 | 0 | WXS_TREE_CAST WXS_MODELGROUPDEF_MODEL(WXS_PARTICLE_TERM(particle)); |
18614 | |
|
18615 | 0 | particle = WXS_PTC_CAST particle->next; |
18616 | 0 | } |
18617 | 0 | } |
18618 | | |
18619 | | /** |
18620 | | * This one is intended to be used by |
18621 | | * xmlSchemaCheckAttrGroupCircular only. |
18622 | | * |
18623 | | * @param ctxtGr the searched attribute group |
18624 | | * @param list the current attribute list to be processed |
18625 | | * @returns the circular attribute group reference, otherwise NULL. |
18626 | | */ |
18627 | | static xmlSchemaQNameRefPtr |
18628 | | xmlSchemaCheckAttrGroupCircularRecur(xmlSchemaAttributeGroupPtr ctxtGr, |
18629 | | xmlSchemaItemListPtr list) |
18630 | 0 | { |
18631 | 0 | xmlSchemaAttributeGroupPtr gr; |
18632 | 0 | xmlSchemaQNameRefPtr ref, circ; |
18633 | 0 | int i; |
18634 | | /* |
18635 | | * We will search for an attribute group reference which |
18636 | | * references the context attribute group. |
18637 | | */ |
18638 | 0 | for (i = 0; i < list->nbItems; i++) { |
18639 | 0 | ref = list->items[i]; |
18640 | 0 | if ((ref->type == XML_SCHEMA_EXTRA_QNAMEREF) && |
18641 | 0 | (ref->itemType == XML_SCHEMA_TYPE_ATTRIBUTEGROUP) && |
18642 | 0 | (ref->item != NULL)) |
18643 | 0 | { |
18644 | 0 | gr = WXS_ATTR_GROUP_CAST ref->item; |
18645 | 0 | if (gr == ctxtGr) |
18646 | 0 | return(ref); |
18647 | 0 | if (gr->flags & XML_SCHEMAS_ATTRGROUP_MARKED) |
18648 | 0 | continue; |
18649 | | /* |
18650 | | * Mark as visited to avoid infinite recursion on |
18651 | | * circular references not yet examined. |
18652 | | */ |
18653 | 0 | if ((gr->attrUses) && |
18654 | 0 | (gr->flags & XML_SCHEMAS_ATTRGROUP_HAS_REFS)) |
18655 | 0 | { |
18656 | 0 | gr->flags |= XML_SCHEMAS_ATTRGROUP_MARKED; |
18657 | 0 | circ = xmlSchemaCheckAttrGroupCircularRecur(ctxtGr, |
18658 | 0 | (xmlSchemaItemListPtr) gr->attrUses); |
18659 | 0 | gr->flags ^= XML_SCHEMAS_ATTRGROUP_MARKED; |
18660 | 0 | if (circ != NULL) |
18661 | 0 | return (circ); |
18662 | 0 | } |
18663 | |
|
18664 | 0 | } |
18665 | 0 | } |
18666 | 0 | return (NULL); |
18667 | 0 | } |
18668 | | |
18669 | | /** |
18670 | | * Checks for circular references of attribute groups. |
18671 | | * |
18672 | | * @param attrGr the attribute group definition |
18673 | | * @param ctxt the parser context |
18674 | | */ |
18675 | | static int |
18676 | | xmlSchemaCheckAttrGroupCircular(xmlSchemaAttributeGroupPtr attrGr, |
18677 | | xmlSchemaParserCtxtPtr ctxt) |
18678 | 0 | { |
18679 | | /* |
18680 | | * Schema Representation Constraint: |
18681 | | * Attribute Group Definition Representation OK |
18682 | | * 3 Circular group reference is disallowed outside <redefine>. |
18683 | | * That is, unless this element information item's parent is |
18684 | | * <redefine>, then among the [children], if any, there must |
18685 | | * not be an <attributeGroup> with ref [attribute] which resolves |
18686 | | * to the component corresponding to this <attributeGroup>. Indirect |
18687 | | * circularity is also ruled out. That is, when QName resolution |
18688 | | * (Schema Document) ($3.15.3) is applied to a `QName` arising from |
18689 | | * any <attributeGroup>s with a ref [attribute] among the [children], |
18690 | | * it must not be the case that a `QName` is encountered at any depth |
18691 | | * which resolves to the component corresponding to this <attributeGroup>. |
18692 | | */ |
18693 | 0 | if (attrGr->attrUses == NULL) |
18694 | 0 | return(0); |
18695 | 0 | else if ((attrGr->flags & XML_SCHEMAS_ATTRGROUP_HAS_REFS) == 0) |
18696 | 0 | return(0); |
18697 | 0 | else { |
18698 | 0 | xmlSchemaQNameRefPtr circ; |
18699 | |
|
18700 | 0 | circ = xmlSchemaCheckAttrGroupCircularRecur(attrGr, |
18701 | 0 | (xmlSchemaItemListPtr) attrGr->attrUses); |
18702 | 0 | if (circ != NULL) { |
18703 | 0 | xmlChar *str = NULL; |
18704 | | /* |
18705 | | * TODO: Report the referenced attr group as QName. |
18706 | | */ |
18707 | 0 | xmlSchemaPCustomErr(ctxt, |
18708 | 0 | XML_SCHEMAP_SRC_ATTRIBUTE_GROUP_3, |
18709 | 0 | NULL, WXS_ITEM_NODE(WXS_BASIC_CAST circ), |
18710 | 0 | "Circular reference to the attribute group '%s' " |
18711 | 0 | "defined", xmlSchemaGetComponentQName(&str, attrGr)); |
18712 | 0 | FREE_AND_NULL(str); |
18713 | | /* |
18714 | | * NOTE: We will cut the reference to avoid further |
18715 | | * confusion of the processor. |
18716 | | * BADSPEC TODO: The spec should define how to process in this case. |
18717 | | */ |
18718 | 0 | circ->item = NULL; |
18719 | 0 | return(ctxt->err); |
18720 | 0 | } |
18721 | 0 | } |
18722 | 0 | return(0); |
18723 | 0 | } |
18724 | | |
18725 | | static int |
18726 | | xmlSchemaAttributeGroupExpandRefs(xmlSchemaParserCtxtPtr pctxt, |
18727 | | xmlSchemaAttributeGroupPtr attrGr); |
18728 | | |
18729 | | /** |
18730 | | * Substitutes contained attribute group references |
18731 | | * for their attribute uses. Wildcards are intersected. |
18732 | | * Attribute use prohibitions are removed from the list |
18733 | | * and returned via the `prohibs` list. |
18734 | | * Pointlessness of attr. prohibs, if a matching attr. decl |
18735 | | * is existent a well, are checked. |
18736 | | * |
18737 | | * @param pctxt the parser context |
18738 | | * @param item the schema item |
18739 | | * @param completeWild the intersected wildcard to be returned |
18740 | | * @param list the attribute uses |
18741 | | * @param prohibs the attribute prohibitions |
18742 | | */ |
18743 | | static int |
18744 | | xmlSchemaExpandAttributeGroupRefs(xmlSchemaParserCtxtPtr pctxt, |
18745 | | xmlSchemaBasicItemPtr item, |
18746 | | xmlSchemaWildcardPtr *completeWild, |
18747 | | xmlSchemaItemListPtr list, |
18748 | | xmlSchemaItemListPtr prohibs) |
18749 | 0 | { |
18750 | 0 | xmlSchemaAttributeGroupPtr gr; |
18751 | 0 | xmlSchemaAttributeUsePtr use; |
18752 | 0 | xmlSchemaItemListPtr sublist; |
18753 | 0 | int i, j; |
18754 | 0 | int created = (*completeWild == NULL) ? 0 : 1; |
18755 | |
|
18756 | 0 | if (prohibs) |
18757 | 0 | prohibs->nbItems = 0; |
18758 | |
|
18759 | 0 | for (i = 0; i < list->nbItems; i++) { |
18760 | 0 | use = list->items[i]; |
18761 | |
|
18762 | 0 | if (use->type == XML_SCHEMA_EXTRA_ATTR_USE_PROHIB) { |
18763 | 0 | if (prohibs == NULL) { |
18764 | 0 | PERROR_INT("xmlSchemaExpandAttributeGroupRefs", |
18765 | 0 | "unexpected attr prohibition found"); |
18766 | 0 | return(-1); |
18767 | 0 | } |
18768 | | /* |
18769 | | * Remove from attribute uses. |
18770 | | */ |
18771 | 0 | if (xmlSchemaItemListRemove(list, i) == -1) |
18772 | 0 | return(-1); |
18773 | 0 | i--; |
18774 | | /* |
18775 | | * Note that duplicate prohibitions were already |
18776 | | * handled at parsing time. |
18777 | | */ |
18778 | | /* |
18779 | | * Add to list of prohibitions. |
18780 | | */ |
18781 | 0 | xmlSchemaItemListAddSize(prohibs, 2, use); |
18782 | 0 | continue; |
18783 | 0 | } |
18784 | 0 | if ((use->type == XML_SCHEMA_EXTRA_QNAMEREF) && |
18785 | 0 | ((WXS_QNAME_CAST use)->itemType == XML_SCHEMA_TYPE_ATTRIBUTEGROUP)) |
18786 | 0 | { |
18787 | 0 | if ((WXS_QNAME_CAST use)->item == NULL) |
18788 | 0 | return(-1); |
18789 | 0 | gr = WXS_ATTR_GROUP_CAST (WXS_QNAME_CAST use)->item; |
18790 | | /* |
18791 | | * Expand the referenced attr. group. |
18792 | | * TODO: remove this, this is done in a previous step, so |
18793 | | * already done here. |
18794 | | */ |
18795 | 0 | if ((gr->flags & XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED) == 0) { |
18796 | 0 | if (xmlSchemaAttributeGroupExpandRefs(pctxt, gr) == -1) |
18797 | 0 | return(-1); |
18798 | 0 | } |
18799 | | /* |
18800 | | * Build the 'complete' wildcard; i.e. intersect multiple |
18801 | | * wildcards. |
18802 | | */ |
18803 | 0 | if (gr->attributeWildcard != NULL) { |
18804 | 0 | if (*completeWild == NULL) { |
18805 | 0 | *completeWild = gr->attributeWildcard; |
18806 | 0 | } else { |
18807 | 0 | if (! created) { |
18808 | 0 | xmlSchemaWildcardPtr tmpWild; |
18809 | | |
18810 | | /* |
18811 | | * Copy the first encountered wildcard as context, |
18812 | | * except for the annotation. |
18813 | | * |
18814 | | * Although the complete wildcard might not correspond |
18815 | | * to any node in the schema, we will anchor it on |
18816 | | * the node of the owner component. |
18817 | | */ |
18818 | 0 | tmpWild = xmlSchemaAddWildcard(pctxt, pctxt->schema, |
18819 | 0 | XML_SCHEMA_TYPE_ANY_ATTRIBUTE, |
18820 | 0 | WXS_ITEM_NODE(item)); |
18821 | 0 | if (tmpWild == NULL) |
18822 | 0 | return(-1); |
18823 | 0 | if (xmlSchemaCloneWildcardNsConstraints(pctxt, |
18824 | 0 | tmpWild, *completeWild) == -1) |
18825 | 0 | return (-1); |
18826 | 0 | tmpWild->processContents = (*completeWild)->processContents; |
18827 | 0 | *completeWild = tmpWild; |
18828 | 0 | created = 1; |
18829 | 0 | } |
18830 | | |
18831 | 0 | if (xmlSchemaIntersectWildcards(pctxt, *completeWild, |
18832 | 0 | gr->attributeWildcard) == -1) |
18833 | 0 | return(-1); |
18834 | 0 | } |
18835 | 0 | } |
18836 | | /* |
18837 | | * Just remove the reference if the referenced group does not |
18838 | | * contain any attribute uses. |
18839 | | */ |
18840 | 0 | sublist = ((xmlSchemaItemListPtr) gr->attrUses); |
18841 | 0 | if ((sublist == NULL) || sublist->nbItems == 0) { |
18842 | 0 | if (xmlSchemaItemListRemove(list, i) == -1) |
18843 | 0 | return(-1); |
18844 | 0 | i--; |
18845 | 0 | continue; |
18846 | 0 | } |
18847 | | /* |
18848 | | * Add the attribute uses. |
18849 | | */ |
18850 | 0 | list->items[i] = sublist->items[0]; |
18851 | 0 | if (sublist->nbItems != 1) { |
18852 | 0 | for (j = 1; j < sublist->nbItems; j++) { |
18853 | 0 | i++; |
18854 | 0 | if (xmlSchemaItemListInsert(list, |
18855 | 0 | sublist->items[j], i) == -1) |
18856 | 0 | return(-1); |
18857 | 0 | } |
18858 | 0 | } |
18859 | 0 | } |
18860 | |
|
18861 | 0 | } |
18862 | | /* |
18863 | | * Handle pointless prohibitions of declared attributes. |
18864 | | */ |
18865 | 0 | if (prohibs && (prohibs->nbItems != 0) && (list->nbItems != 0)) { |
18866 | 0 | xmlSchemaAttributeUseProhibPtr prohib; |
18867 | |
|
18868 | 0 | for (i = prohibs->nbItems -1; i >= 0; i--) { |
18869 | 0 | prohib = prohibs->items[i]; |
18870 | 0 | for (j = 0; j < list->nbItems; j++) { |
18871 | 0 | use = list->items[j]; |
18872 | |
|
18873 | 0 | if ((prohib->name == WXS_ATTRUSE_DECL_NAME(use)) && |
18874 | 0 | (prohib->targetNamespace == WXS_ATTRUSE_DECL_TNS(use))) |
18875 | 0 | { |
18876 | 0 | xmlChar *str = NULL; |
18877 | |
|
18878 | 0 | xmlSchemaCustomWarning(ACTXT_CAST pctxt, |
18879 | 0 | XML_SCHEMAP_WARN_ATTR_POINTLESS_PROH, |
18880 | 0 | prohib->node, NULL, |
18881 | 0 | "Skipping pointless attribute use prohibition " |
18882 | 0 | "'%s', since a corresponding attribute use " |
18883 | 0 | "exists already in the type definition", |
18884 | 0 | xmlSchemaFormatQName(&str, |
18885 | 0 | prohib->targetNamespace, prohib->name), |
18886 | 0 | NULL, NULL); |
18887 | 0 | FREE_AND_NULL(str); |
18888 | | /* |
18889 | | * Remove the prohibition. |
18890 | | */ |
18891 | 0 | if (xmlSchemaItemListRemove(prohibs, i) == -1) |
18892 | 0 | return(-1); |
18893 | 0 | break; |
18894 | 0 | } |
18895 | 0 | } |
18896 | 0 | } |
18897 | 0 | } |
18898 | 0 | return(0); |
18899 | 0 | } |
18900 | | |
18901 | | /** |
18902 | | * Computation of: |
18903 | | * {attribute uses} property |
18904 | | * {attribute wildcard} property |
18905 | | * |
18906 | | * Substitutes contained attribute group references |
18907 | | * for their attribute uses. Wildcards are intersected. |
18908 | | * |
18909 | | * @param pctxt the parser context |
18910 | | * @param attrGr the attribute group definition |
18911 | | */ |
18912 | | static int |
18913 | | xmlSchemaAttributeGroupExpandRefs(xmlSchemaParserCtxtPtr pctxt, |
18914 | | xmlSchemaAttributeGroupPtr attrGr) |
18915 | 0 | { |
18916 | 0 | if ((attrGr->attrUses == NULL) || |
18917 | 0 | (attrGr->flags & XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED)) |
18918 | 0 | return(0); |
18919 | | |
18920 | 0 | attrGr->flags |= XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED; |
18921 | 0 | if (xmlSchemaExpandAttributeGroupRefs(pctxt, WXS_BASIC_CAST attrGr, |
18922 | 0 | &(attrGr->attributeWildcard), attrGr->attrUses, NULL) == -1) |
18923 | 0 | return(-1); |
18924 | 0 | return(0); |
18925 | 0 | } |
18926 | | |
18927 | | /** |
18928 | | * Substitutes contained attribute group references |
18929 | | * for their attribute uses. Wildcards are intersected. |
18930 | | * |
18931 | | * Schema Component Constraint: |
18932 | | * Attribute Group Definition Properties Correct (ag-props-correct) |
18933 | | * @param pctxt the parser context |
18934 | | * @param attrGr the attribute group definition |
18935 | | */ |
18936 | | static int |
18937 | | xmlSchemaCheckAGPropsCorrect(xmlSchemaParserCtxtPtr pctxt, |
18938 | | xmlSchemaAttributeGroupPtr attrGr) |
18939 | 0 | { |
18940 | | /* |
18941 | | * SPEC ag-props-correct |
18942 | | * (1) "The values of the properties of an attribute group definition |
18943 | | * must be as described in the property tableau in The Attribute |
18944 | | * Group Definition Schema Component ($3.6.1), modulo the impact of |
18945 | | * Missing Sub-components ($5.3);" |
18946 | | */ |
18947 | |
|
18948 | 0 | if ((attrGr->attrUses != NULL) && |
18949 | 0 | (WXS_LIST_CAST attrGr->attrUses)->nbItems > 1) |
18950 | 0 | { |
18951 | 0 | xmlSchemaItemListPtr uses = WXS_LIST_CAST attrGr->attrUses; |
18952 | 0 | xmlSchemaAttributeUsePtr use, tmp; |
18953 | 0 | int i, j, hasId = 0; |
18954 | |
|
18955 | 0 | for (i = uses->nbItems -1; i >= 0; i--) { |
18956 | 0 | use = uses->items[i]; |
18957 | | /* |
18958 | | * SPEC ag-props-correct |
18959 | | * (2) "Two distinct members of the {attribute uses} must not have |
18960 | | * {attribute declaration}s both of whose {name}s match and whose |
18961 | | * {target namespace}s are identical." |
18962 | | */ |
18963 | 0 | if (i > 0) { |
18964 | 0 | for (j = i -1; j >= 0; j--) { |
18965 | 0 | tmp = uses->items[j]; |
18966 | 0 | if ((WXS_ATTRUSE_DECL_NAME(use) == |
18967 | 0 | WXS_ATTRUSE_DECL_NAME(tmp)) && |
18968 | 0 | (WXS_ATTRUSE_DECL_TNS(use) == |
18969 | 0 | WXS_ATTRUSE_DECL_TNS(tmp))) |
18970 | 0 | { |
18971 | 0 | xmlChar *str = NULL; |
18972 | |
|
18973 | 0 | xmlSchemaCustomErr(ACTXT_CAST pctxt, |
18974 | 0 | XML_SCHEMAP_AG_PROPS_CORRECT, |
18975 | 0 | attrGr->node, WXS_BASIC_CAST attrGr, |
18976 | 0 | "Duplicate %s", |
18977 | 0 | xmlSchemaGetComponentDesignation(&str, use), |
18978 | 0 | NULL); |
18979 | 0 | FREE_AND_NULL(str); |
18980 | | /* |
18981 | | * Remove the duplicate. |
18982 | | */ |
18983 | 0 | if (xmlSchemaItemListRemove(uses, i) == -1) |
18984 | 0 | return(-1); |
18985 | 0 | goto next_use; |
18986 | 0 | } |
18987 | 0 | } |
18988 | 0 | } |
18989 | | /* |
18990 | | * SPEC ag-props-correct |
18991 | | * (3) "Two distinct members of the {attribute uses} must not have |
18992 | | * {attribute declaration}s both of whose {type definition}s are or |
18993 | | * are derived from ID." |
18994 | | * TODO: Does 'derived' include member-types of unions? |
18995 | | */ |
18996 | 0 | if (WXS_ATTRUSE_TYPEDEF(use) != NULL) { |
18997 | 0 | if (xmlSchemaIsDerivedFromBuiltInType( |
18998 | 0 | WXS_ATTRUSE_TYPEDEF(use), XML_SCHEMAS_ID)) |
18999 | 0 | { |
19000 | 0 | if (hasId) { |
19001 | 0 | xmlChar *str = NULL; |
19002 | |
|
19003 | 0 | xmlSchemaCustomErr(ACTXT_CAST pctxt, |
19004 | 0 | XML_SCHEMAP_AG_PROPS_CORRECT, |
19005 | 0 | attrGr->node, WXS_BASIC_CAST attrGr, |
19006 | 0 | "There must not exist more than one attribute " |
19007 | 0 | "declaration of type 'xs:ID' " |
19008 | 0 | "(or derived from 'xs:ID'). The %s violates this " |
19009 | 0 | "constraint", |
19010 | 0 | xmlSchemaGetComponentDesignation(&str, use), |
19011 | 0 | NULL); |
19012 | 0 | FREE_AND_NULL(str); |
19013 | 0 | if (xmlSchemaItemListRemove(uses, i) == -1) |
19014 | 0 | return(-1); |
19015 | 0 | } |
19016 | 0 | hasId = 1; |
19017 | 0 | } |
19018 | 0 | } |
19019 | 0 | next_use: {} |
19020 | 0 | } |
19021 | 0 | } |
19022 | 0 | return(0); |
19023 | 0 | } |
19024 | | |
19025 | | /** |
19026 | | * Resolves references to attribute group definitions. |
19027 | | * |
19028 | | * @param ref the schema attribute definition |
19029 | | * @param ctxt the schema parser context |
19030 | | */ |
19031 | | static int |
19032 | | xmlSchemaResolveAttrGroupReferences(xmlSchemaQNameRefPtr ref, |
19033 | | xmlSchemaParserCtxtPtr ctxt) |
19034 | 0 | { |
19035 | 0 | xmlSchemaAttributeGroupPtr group; |
19036 | |
|
19037 | 0 | if (ref->item != NULL) |
19038 | 0 | return(0); |
19039 | 0 | group = xmlSchemaGetAttributeGroup(ctxt->schema, |
19040 | 0 | ref->name, |
19041 | 0 | ref->targetNamespace); |
19042 | 0 | if (group == NULL) { |
19043 | 0 | xmlSchemaPResCompAttrErr(ctxt, |
19044 | 0 | XML_SCHEMAP_SRC_RESOLVE, |
19045 | 0 | NULL, ref->node, |
19046 | 0 | "ref", ref->name, ref->targetNamespace, |
19047 | 0 | ref->itemType, NULL); |
19048 | 0 | return(ctxt->err); |
19049 | 0 | } |
19050 | 0 | ref->item = WXS_BASIC_CAST group; |
19051 | 0 | return(0); |
19052 | 0 | } |
19053 | | |
19054 | | /** |
19055 | | * Schema Component Constraint: |
19056 | | * Attribute Declaration Properties Correct (a-props-correct) |
19057 | | * |
19058 | | * Validates the value constraints of an attribute declaration/use. |
19059 | | * NOTE that this needs the simple type definitions to be already |
19060 | | * built and checked. |
19061 | | * @param pctxt a schema parser context |
19062 | | * @param attr an schema attribute declaration/use |
19063 | | */ |
19064 | | static int |
19065 | | xmlSchemaCheckAttrPropsCorrect(xmlSchemaParserCtxtPtr pctxt, |
19066 | | xmlSchemaAttributePtr attr) |
19067 | 0 | { |
19068 | | |
19069 | | /* |
19070 | | * SPEC a-props-correct (1) |
19071 | | * "The values of the properties of an attribute declaration must |
19072 | | * be as described in the property tableau in The Attribute |
19073 | | * Declaration Schema Component ($3.2.1), modulo the impact of |
19074 | | * Missing Sub-components ($5.3)." |
19075 | | */ |
19076 | |
|
19077 | 0 | if (WXS_ATTR_TYPEDEF(attr) == NULL) |
19078 | 0 | return(0); |
19079 | | |
19080 | 0 | if (attr->defValue != NULL) { |
19081 | 0 | int ret; |
19082 | | |
19083 | | /* |
19084 | | * SPEC a-props-correct (3) |
19085 | | * "If the {type definition} is or is derived from ID then there |
19086 | | * must not be a {value constraint}." |
19087 | | */ |
19088 | 0 | if (xmlSchemaIsDerivedFromBuiltInType( |
19089 | 0 | WXS_ATTR_TYPEDEF(attr), XML_SCHEMAS_ID)) |
19090 | 0 | { |
19091 | 0 | xmlSchemaCustomErr(ACTXT_CAST pctxt, |
19092 | 0 | XML_SCHEMAP_A_PROPS_CORRECT_3, |
19093 | 0 | NULL, WXS_BASIC_CAST attr, |
19094 | 0 | "Value constraints are not allowed if the type definition " |
19095 | 0 | "is or is derived from xs:ID", |
19096 | 0 | NULL, NULL); |
19097 | 0 | return(pctxt->err); |
19098 | 0 | } |
19099 | | /* |
19100 | | * SPEC a-props-correct (2) |
19101 | | * "if there is a {value constraint}, the canonical lexical |
19102 | | * representation of its value must be `valid` with respect |
19103 | | * to the {type definition} as defined in String Valid ($3.14.4)." |
19104 | | * TODO: Don't care about the *canonical* stuff here, this requirement |
19105 | | * will be removed in WXS 1.1 anyway. |
19106 | | */ |
19107 | 0 | ret = xmlSchemaVCheckCVCSimpleType(ACTXT_CAST pctxt, |
19108 | 0 | attr->node, WXS_ATTR_TYPEDEF(attr), |
19109 | 0 | attr->defValue, &(attr->defVal), |
19110 | 0 | 1, 1, 0); |
19111 | 0 | if (ret != 0) { |
19112 | 0 | if (ret < 0) { |
19113 | 0 | PERROR_INT("xmlSchemaCheckAttrPropsCorrect", |
19114 | 0 | "calling xmlSchemaVCheckCVCSimpleType()"); |
19115 | 0 | return(-1); |
19116 | 0 | } |
19117 | 0 | xmlSchemaCustomErr(ACTXT_CAST pctxt, |
19118 | 0 | XML_SCHEMAP_A_PROPS_CORRECT_2, |
19119 | 0 | NULL, WXS_BASIC_CAST attr, |
19120 | 0 | "The value of the value constraint is not valid", |
19121 | 0 | NULL, NULL); |
19122 | 0 | return(pctxt->err); |
19123 | 0 | } |
19124 | 0 | } |
19125 | | |
19126 | 0 | return(0); |
19127 | 0 | } |
19128 | | |
19129 | | static xmlSchemaElementPtr |
19130 | | xmlSchemaCheckSubstGroupCircular(xmlSchemaElementPtr elemDecl, |
19131 | | xmlSchemaElementPtr ancestor) |
19132 | 0 | { |
19133 | 0 | xmlSchemaElementPtr ret; |
19134 | |
|
19135 | 0 | if (WXS_SUBST_HEAD(ancestor) == NULL) |
19136 | 0 | return (NULL); |
19137 | 0 | if (WXS_SUBST_HEAD(ancestor) == elemDecl) |
19138 | 0 | return (ancestor); |
19139 | | |
19140 | 0 | if (WXS_SUBST_HEAD(ancestor)->flags & XML_SCHEMAS_ELEM_CIRCULAR) |
19141 | 0 | return (NULL); |
19142 | 0 | WXS_SUBST_HEAD(ancestor)->flags |= XML_SCHEMAS_ELEM_CIRCULAR; |
19143 | 0 | ret = xmlSchemaCheckSubstGroupCircular(elemDecl, |
19144 | 0 | WXS_SUBST_HEAD(ancestor)); |
19145 | 0 | WXS_SUBST_HEAD(ancestor)->flags ^= XML_SCHEMAS_ELEM_CIRCULAR; |
19146 | |
|
19147 | 0 | return (ret); |
19148 | 0 | } |
19149 | | |
19150 | | /** |
19151 | | * Schema Component Constraint: |
19152 | | * Element Declaration Properties Correct (e-props-correct) |
19153 | | * |
19154 | | * STATUS: |
19155 | | * missing: (6) |
19156 | | * @param pctxt a schema parser context |
19157 | | * @param elemDecl the element declaration |
19158 | | */ |
19159 | | static int |
19160 | | xmlSchemaCheckElemPropsCorrect(xmlSchemaParserCtxtPtr pctxt, |
19161 | | xmlSchemaElementPtr elemDecl) |
19162 | 0 | { |
19163 | 0 | int ret = 0; |
19164 | 0 | xmlSchemaTypePtr typeDef = WXS_ELEM_TYPEDEF(elemDecl); |
19165 | | /* |
19166 | | * SPEC (1) "The values of the properties of an element declaration |
19167 | | * must be as described in the property tableau in The Element |
19168 | | * Declaration Schema Component ($3.3.1), modulo the impact of Missing |
19169 | | * Sub-components ($5.3)." |
19170 | | */ |
19171 | 0 | if (WXS_SUBST_HEAD(elemDecl) != NULL) { |
19172 | 0 | xmlSchemaElementPtr head = WXS_SUBST_HEAD(elemDecl), circ; |
19173 | |
|
19174 | 0 | xmlSchemaCheckElementDeclComponent(head, pctxt); |
19175 | | /* |
19176 | | * SPEC (3) "If there is a non-`absent` {substitution group |
19177 | | * affiliation}, then {scope} must be global." |
19178 | | */ |
19179 | 0 | if ((elemDecl->flags & XML_SCHEMAS_ELEM_GLOBAL) == 0) { |
19180 | 0 | xmlSchemaPCustomErr(pctxt, |
19181 | 0 | XML_SCHEMAP_E_PROPS_CORRECT_3, |
19182 | 0 | WXS_BASIC_CAST elemDecl, NULL, |
19183 | 0 | "Only global element declarations can have a " |
19184 | 0 | "substitution group affiliation", NULL); |
19185 | 0 | ret = XML_SCHEMAP_E_PROPS_CORRECT_3; |
19186 | 0 | } |
19187 | | /* |
19188 | | * TODO: SPEC (6) "Circular substitution groups are disallowed. |
19189 | | * That is, it must not be possible to return to an element declaration |
19190 | | * by repeatedly following the {substitution group affiliation} |
19191 | | * property." |
19192 | | */ |
19193 | 0 | if (head == elemDecl) |
19194 | 0 | circ = head; |
19195 | 0 | else if (WXS_SUBST_HEAD(head) != NULL) |
19196 | 0 | circ = xmlSchemaCheckSubstGroupCircular(head, head); |
19197 | 0 | else |
19198 | 0 | circ = NULL; |
19199 | 0 | if (circ != NULL) { |
19200 | 0 | xmlChar *strA = NULL, *strB = NULL; |
19201 | |
|
19202 | 0 | xmlSchemaPCustomErrExt(pctxt, |
19203 | 0 | XML_SCHEMAP_E_PROPS_CORRECT_6, |
19204 | 0 | WXS_BASIC_CAST circ, NULL, |
19205 | 0 | "The element declaration '%s' defines a circular " |
19206 | 0 | "substitution group to element declaration '%s'", |
19207 | 0 | xmlSchemaGetComponentQName(&strA, circ), |
19208 | 0 | xmlSchemaGetComponentQName(&strB, head), |
19209 | 0 | NULL); |
19210 | 0 | FREE_AND_NULL(strA) |
19211 | 0 | FREE_AND_NULL(strB) |
19212 | 0 | ret = XML_SCHEMAP_E_PROPS_CORRECT_6; |
19213 | 0 | } |
19214 | | /* |
19215 | | * SPEC (4) "If there is a {substitution group affiliation}, |
19216 | | * the {type definition} |
19217 | | * of the element declaration must be validly derived from the {type |
19218 | | * definition} of the {substitution group affiliation}, given the value |
19219 | | * of the {substitution group exclusions} of the {substitution group |
19220 | | * affiliation}, as defined in Type Derivation OK (Complex) ($3.4.6) |
19221 | | * (if the {type definition} is complex) or as defined in |
19222 | | * Type Derivation OK (Simple) ($3.14.6) (if the {type definition} is |
19223 | | * simple)." |
19224 | | * |
19225 | | * NOTE: {substitution group exclusions} means the values of the |
19226 | | * attribute "final". |
19227 | | */ |
19228 | |
|
19229 | 0 | if (typeDef != WXS_ELEM_TYPEDEF(WXS_SUBST_HEAD(elemDecl))) { |
19230 | 0 | int set = 0; |
19231 | |
|
19232 | 0 | if (head->flags & XML_SCHEMAS_ELEM_FINAL_EXTENSION) |
19233 | 0 | set |= SUBSET_EXTENSION; |
19234 | 0 | if (head->flags & XML_SCHEMAS_ELEM_FINAL_RESTRICTION) |
19235 | 0 | set |= SUBSET_RESTRICTION; |
19236 | |
|
19237 | 0 | if (xmlSchemaCheckCOSDerivedOK(ACTXT_CAST pctxt, typeDef, |
19238 | 0 | WXS_ELEM_TYPEDEF(head), set) != 0) { |
19239 | 0 | xmlChar *strA = NULL, *strB = NULL, *strC = NULL; |
19240 | |
|
19241 | 0 | ret = XML_SCHEMAP_E_PROPS_CORRECT_4; |
19242 | 0 | xmlSchemaPCustomErrExt(pctxt, |
19243 | 0 | XML_SCHEMAP_E_PROPS_CORRECT_4, |
19244 | 0 | WXS_BASIC_CAST elemDecl, NULL, |
19245 | 0 | "The type definition '%s' was " |
19246 | 0 | "either rejected by the substitution group " |
19247 | 0 | "affiliation '%s', or not validly derived from its type " |
19248 | 0 | "definition '%s'", |
19249 | 0 | xmlSchemaGetComponentQName(&strA, typeDef), |
19250 | 0 | xmlSchemaGetComponentQName(&strB, head), |
19251 | 0 | xmlSchemaGetComponentQName(&strC, WXS_ELEM_TYPEDEF(head))); |
19252 | 0 | FREE_AND_NULL(strA) |
19253 | 0 | FREE_AND_NULL(strB) |
19254 | 0 | FREE_AND_NULL(strC) |
19255 | 0 | } |
19256 | 0 | } |
19257 | 0 | } |
19258 | | /* |
19259 | | * SPEC (5) "If the {type definition} or {type definition}'s |
19260 | | * {content type} |
19261 | | * is or is derived from ID then there must not be a {value constraint}. |
19262 | | * Note: The use of ID as a type definition for elements goes beyond |
19263 | | * XML 1.0, and should be avoided if backwards compatibility is desired" |
19264 | | */ |
19265 | 0 | if ((elemDecl->value != NULL) && |
19266 | 0 | ((WXS_IS_SIMPLE(typeDef) && |
19267 | 0 | xmlSchemaIsDerivedFromBuiltInType(typeDef, XML_SCHEMAS_ID)) || |
19268 | 0 | (WXS_IS_COMPLEX(typeDef) && |
19269 | 0 | WXS_HAS_SIMPLE_CONTENT(typeDef) && |
19270 | 0 | xmlSchemaIsDerivedFromBuiltInType(typeDef->contentTypeDef, |
19271 | 0 | XML_SCHEMAS_ID)))) { |
19272 | |
|
19273 | 0 | ret = XML_SCHEMAP_E_PROPS_CORRECT_5; |
19274 | 0 | xmlSchemaPCustomErr(pctxt, |
19275 | 0 | XML_SCHEMAP_E_PROPS_CORRECT_5, |
19276 | 0 | WXS_BASIC_CAST elemDecl, NULL, |
19277 | 0 | "The type definition (or type definition's content type) is or " |
19278 | 0 | "is derived from ID; value constraints are not allowed in " |
19279 | 0 | "conjunction with such a type definition", NULL); |
19280 | 0 | } else if (elemDecl->value != NULL) { |
19281 | 0 | int vcret; |
19282 | 0 | xmlNodePtr node = NULL; |
19283 | | |
19284 | | /* |
19285 | | * SPEC (2) "If there is a {value constraint}, the canonical lexical |
19286 | | * representation of its value must be `valid` with respect to the |
19287 | | * {type definition} as defined in Element Default Valid (Immediate) |
19288 | | * ($3.3.6)." |
19289 | | */ |
19290 | 0 | if (typeDef == NULL) { |
19291 | 0 | xmlSchemaPErr(pctxt, elemDecl->node, |
19292 | 0 | XML_SCHEMAP_INTERNAL, |
19293 | 0 | "Internal error: xmlSchemaCheckElemPropsCorrect, " |
19294 | 0 | "type is missing... skipping validation of " |
19295 | 0 | "the value constraint", NULL, NULL); |
19296 | 0 | return (-1); |
19297 | 0 | } |
19298 | 0 | if (elemDecl->node != NULL) { |
19299 | 0 | if (elemDecl->flags & XML_SCHEMAS_ELEM_FIXED) |
19300 | 0 | node = (xmlNodePtr) xmlHasProp(elemDecl->node, |
19301 | 0 | BAD_CAST "fixed"); |
19302 | 0 | else |
19303 | 0 | node = (xmlNodePtr) xmlHasProp(elemDecl->node, |
19304 | 0 | BAD_CAST "default"); |
19305 | 0 | } |
19306 | 0 | vcret = xmlSchemaParseCheckCOSValidDefault(pctxt, node, |
19307 | 0 | typeDef, elemDecl->value, &(elemDecl->defVal)); |
19308 | 0 | if (vcret != 0) { |
19309 | 0 | if (vcret < 0) { |
19310 | 0 | PERROR_INT("xmlSchemaElemCheckValConstr", |
19311 | 0 | "failed to validate the value constraint of an " |
19312 | 0 | "element declaration"); |
19313 | 0 | return (-1); |
19314 | 0 | } |
19315 | 0 | return (vcret); |
19316 | 0 | } |
19317 | 0 | } |
19318 | | |
19319 | 0 | return (ret); |
19320 | 0 | } |
19321 | | |
19322 | | /** |
19323 | | * Schema Component Constraint: |
19324 | | * Substitution Group (cos-equiv-class) |
19325 | | * |
19326 | | * In Libxml2 the subst. groups will be precomputed, in terms of that |
19327 | | * a list will be built for each subst. group head, holding all direct |
19328 | | * referents to this head. |
19329 | | * NOTE that this function needs: |
19330 | | * 1. circular subst. groups to be checked beforehand |
19331 | | * 2. the declaration's type to be derived from the head's type |
19332 | | * |
19333 | | * STATUS: |
19334 | | * |
19335 | | * @param ctxt a schema parser context |
19336 | | * @param elemDecl the element declaration |
19337 | | */ |
19338 | | static void |
19339 | | xmlSchemaCheckElemSubstGroup(xmlSchemaParserCtxtPtr ctxt, |
19340 | | xmlSchemaElementPtr elemDecl) |
19341 | 0 | { |
19342 | 0 | if ((WXS_SUBST_HEAD(elemDecl) == NULL) || |
19343 | | /* SPEC (1) "Its {abstract} is false." */ |
19344 | 0 | (elemDecl->flags & XML_SCHEMAS_ELEM_ABSTRACT)) |
19345 | 0 | return; |
19346 | 0 | { |
19347 | 0 | xmlSchemaElementPtr head; |
19348 | 0 | xmlSchemaTypePtr headType, type; |
19349 | 0 | int set, methSet; |
19350 | | /* |
19351 | | * SPEC (2) "It is validly substitutable for HEAD subject to HEAD's |
19352 | | * {disallowed substitutions} as the blocking constraint, as defined in |
19353 | | * Substitution Group OK (Transitive) ($3.3.6)." |
19354 | | */ |
19355 | 0 | for (head = WXS_SUBST_HEAD(elemDecl); head != NULL; |
19356 | 0 | head = WXS_SUBST_HEAD(head)) { |
19357 | 0 | set = 0; |
19358 | 0 | methSet = 0; |
19359 | | /* |
19360 | | * The blocking constraints. |
19361 | | */ |
19362 | 0 | if (head->flags & XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION) |
19363 | 0 | continue; |
19364 | 0 | headType = head->subtypes; |
19365 | 0 | type = elemDecl->subtypes; |
19366 | 0 | if (headType == type) |
19367 | 0 | goto add_member; |
19368 | 0 | if (head->flags & XML_SCHEMAS_ELEM_BLOCK_RESTRICTION) |
19369 | 0 | set |= XML_SCHEMAS_TYPE_BLOCK_RESTRICTION; |
19370 | 0 | if (head->flags & XML_SCHEMAS_ELEM_BLOCK_EXTENSION) |
19371 | 0 | set |= XML_SCHEMAS_TYPE_BLOCK_EXTENSION; |
19372 | | /* |
19373 | | * SPEC: Substitution Group OK (Transitive) (2.3) |
19374 | | * "The set of all {derivation method}s involved in the |
19375 | | * derivation of D's {type definition} from C's {type definition} |
19376 | | * does not intersect with the union of the blocking constraint, |
19377 | | * C's {prohibited substitutions} (if C is complex, otherwise the |
19378 | | * empty set) and the {prohibited substitutions} (respectively the |
19379 | | * empty set) of any intermediate {type definition}s in the |
19380 | | * derivation of D's {type definition} from C's {type definition}." |
19381 | | */ |
19382 | | /* |
19383 | | * OPTIMIZE TODO: Optimize this a bit, since, if traversing the |
19384 | | * subst.head axis, the methSet does not need to be computed for |
19385 | | * the full depth over and over. |
19386 | | */ |
19387 | | /* |
19388 | | * The set of all {derivation method}s involved in the derivation |
19389 | | */ |
19390 | 0 | while ((type != NULL) && (type != headType) && |
19391 | 0 | (type != type->baseType)) { |
19392 | 0 | if ((WXS_IS_EXTENSION(type)) && |
19393 | 0 | ((methSet & XML_SCHEMAS_TYPE_BLOCK_RESTRICTION) == 0)) |
19394 | 0 | methSet |= XML_SCHEMAS_TYPE_BLOCK_EXTENSION; |
19395 | |
|
19396 | 0 | if (WXS_IS_RESTRICTION(type) && |
19397 | 0 | ((methSet & XML_SCHEMAS_TYPE_BLOCK_RESTRICTION) == 0)) |
19398 | 0 | methSet |= XML_SCHEMAS_TYPE_BLOCK_RESTRICTION; |
19399 | |
|
19400 | 0 | type = type->baseType; |
19401 | 0 | } |
19402 | | /* |
19403 | | * The {prohibited substitutions} of all intermediate types + |
19404 | | * the head's type. |
19405 | | */ |
19406 | 0 | type = elemDecl->subtypes->baseType; |
19407 | 0 | while (type != NULL) { |
19408 | 0 | if (WXS_IS_COMPLEX(type)) { |
19409 | 0 | if ((type->flags & |
19410 | 0 | XML_SCHEMAS_TYPE_BLOCK_EXTENSION) && |
19411 | 0 | ((set & XML_SCHEMAS_TYPE_BLOCK_EXTENSION) == 0)) |
19412 | 0 | set |= XML_SCHEMAS_TYPE_BLOCK_EXTENSION; |
19413 | 0 | if ((type->flags & |
19414 | 0 | XML_SCHEMAS_TYPE_BLOCK_RESTRICTION) && |
19415 | 0 | ((set & XML_SCHEMAS_TYPE_BLOCK_RESTRICTION) == 0)) |
19416 | 0 | set |= XML_SCHEMAS_TYPE_BLOCK_RESTRICTION; |
19417 | 0 | } else |
19418 | 0 | break; |
19419 | 0 | if (type == headType) |
19420 | 0 | break; |
19421 | 0 | type = type->baseType; |
19422 | 0 | } |
19423 | 0 | if ((set != 0) && |
19424 | 0 | (((set & XML_SCHEMAS_TYPE_BLOCK_EXTENSION) && |
19425 | 0 | (methSet & XML_SCHEMAS_TYPE_BLOCK_EXTENSION)) || |
19426 | 0 | ((set & XML_SCHEMAS_TYPE_BLOCK_RESTRICTION) && |
19427 | 0 | (methSet & XML_SCHEMAS_TYPE_BLOCK_RESTRICTION)))) { |
19428 | 0 | continue; |
19429 | 0 | } |
19430 | 0 | add_member: |
19431 | 0 | xmlSchemaAddElementSubstitutionMember(ctxt, head, elemDecl); |
19432 | 0 | if ((head->flags & XML_SCHEMAS_ELEM_SUBST_GROUP_HEAD) == 0) |
19433 | 0 | head->flags |= XML_SCHEMAS_ELEM_SUBST_GROUP_HEAD; |
19434 | 0 | } |
19435 | 0 | } |
19436 | 0 | } |
19437 | | |
19438 | | #ifdef WXS_ELEM_DECL_CONS_ENABLED /* enable when finished */ |
19439 | | /** |
19440 | | * xmlSchemaCheckElementDeclComponent |
19441 | | * |
19442 | | * Schema Component Constraint: Element Declarations Consistent |
19443 | | * |
19444 | | * @param pctxt the schema parser context |
19445 | | * @param ctxtComponent the context component (an element declaration) |
19446 | | * @param ctxtParticle the first particle of the context component |
19447 | | * @param searchParticle the element declaration particle to be analysed |
19448 | | * @param curParticle the current particle |
19449 | | * @param search search flag |
19450 | | */ |
19451 | | static int |
19452 | | xmlSchemaCheckElementDeclConsistent(xmlSchemaParserCtxtPtr pctxt, |
19453 | | xmlSchemaBasicItemPtr ctxtComponent, |
19454 | | xmlSchemaParticlePtr ctxtParticle, |
19455 | | xmlSchemaParticlePtr searchParticle, |
19456 | | xmlSchemaParticlePtr curParticle, |
19457 | | int search) |
19458 | | { |
19459 | | return(0); |
19460 | | |
19461 | | int ret = 0; |
19462 | | xmlSchemaParticlePtr cur = curParticle; |
19463 | | if (curParticle == NULL) { |
19464 | | return(0); |
19465 | | } |
19466 | | if (WXS_PARTICLE_TERM(curParticle) == NULL) { |
19467 | | /* |
19468 | | * Just return in this case. A missing "term" of the particle |
19469 | | * might arise due to an invalid "term" component. |
19470 | | */ |
19471 | | return(0); |
19472 | | } |
19473 | | while (cur != NULL) { |
19474 | | switch (WXS_PARTICLE_TERM(cur)->type) { |
19475 | | case XML_SCHEMA_TYPE_ANY: |
19476 | | break; |
19477 | | case XML_SCHEMA_TYPE_ELEMENT: |
19478 | | if (search == 0) { |
19479 | | ret = xmlSchemaCheckElementDeclConsistent(pctxt, |
19480 | | ctxtComponent, ctxtParticle, cur, ctxtParticle, 1); |
19481 | | if (ret != 0) |
19482 | | return(ret); |
19483 | | } else { |
19484 | | xmlSchemaElementPtr elem = |
19485 | | WXS_ELEM_CAST(WXS_PARTICLE_TERM(cur)); |
19486 | | /* |
19487 | | * SPEC Element Declarations Consistent: |
19488 | | * "If the {particles} contains, either directly, |
19489 | | * indirectly (that is, within the {particles} of a |
19490 | | * contained model group, recursively) or `implicitly` |
19491 | | * two or more element declaration particles with |
19492 | | * the same {name} and {target namespace}, then |
19493 | | * all their type definitions must be the same |
19494 | | * top-level definition [...]" |
19495 | | */ |
19496 | | if (xmlStrEqual(WXS_PARTICLE_TERM_AS_ELEM(cur)->name, |
19497 | | WXS_PARTICLE_TERM_AS_ELEM(searchParticle)->name) && |
19498 | | xmlStrEqual(WXS_PARTICLE_TERM_AS_ELEM(cur)->targetNamespace, |
19499 | | WXS_PARTICLE_TERM_AS_ELEM(searchParticle)->targetNamespace)) |
19500 | | { |
19501 | | xmlChar *strA = NULL, *strB = NULL; |
19502 | | |
19503 | | xmlSchemaCustomErr(ACTXT_CAST pctxt, |
19504 | | /* TODO: error code */ |
19505 | | XML_SCHEMAP_COS_NONAMBIG, |
19506 | | WXS_ITEM_NODE(cur), NULL, |
19507 | | "In the content model of %s, there are multiple " |
19508 | | "element declarations for '%s' with different " |
19509 | | "type definitions", |
19510 | | xmlSchemaGetComponentDesignation(&strA, |
19511 | | ctxtComponent), |
19512 | | xmlSchemaFormatQName(&strB, |
19513 | | WXS_PARTICLE_TERM_AS_ELEM(cur)->targetNamespace, |
19514 | | WXS_PARTICLE_TERM_AS_ELEM(cur)->name)); |
19515 | | FREE_AND_NULL(strA); |
19516 | | FREE_AND_NULL(strB); |
19517 | | return(XML_SCHEMAP_COS_NONAMBIG); |
19518 | | } |
19519 | | } |
19520 | | break; |
19521 | | case XML_SCHEMA_TYPE_SEQUENCE: { |
19522 | | break; |
19523 | | } |
19524 | | case XML_SCHEMA_TYPE_CHOICE:{ |
19525 | | /* |
19526 | | xmlSchemaTreeItemPtr sub; |
19527 | | |
19528 | | sub = WXS_PARTICLE_TERM(particle)->children; (xmlSchemaParticlePtr) |
19529 | | while (sub != NULL) { |
19530 | | ret = xmlSchemaCheckElementDeclConsistent(pctxt, ctxtComponent, |
19531 | | ctxtParticle, ctxtElem); |
19532 | | if (ret != 0) |
19533 | | return(ret); |
19534 | | sub = sub->next; |
19535 | | } |
19536 | | */ |
19537 | | break; |
19538 | | } |
19539 | | case XML_SCHEMA_TYPE_ALL: |
19540 | | break; |
19541 | | case XML_SCHEMA_TYPE_GROUP: |
19542 | | break; |
19543 | | default: |
19544 | | xmlSchemaInternalErr2(ACTXT_CAST pctxt, |
19545 | | "xmlSchemaCheckElementDeclConsistent", |
19546 | | "found unexpected term of type '%s' in content model", |
19547 | | WXS_ITEM_TYPE_NAME(WXS_PARTICLE_TERM(cur)), NULL); |
19548 | | return(-1); |
19549 | | } |
19550 | | cur = (xmlSchemaParticlePtr) cur->next; |
19551 | | } |
19552 | | |
19553 | | exit: |
19554 | | return(ret); |
19555 | | } |
19556 | | #endif |
19557 | | |
19558 | | /** |
19559 | | * xmlSchemaCheckElementDeclComponent |
19560 | | * |
19561 | | * Validates the value constraints of an element declaration. |
19562 | | * Adds substitution group members. |
19563 | | * |
19564 | | * @param elemDecl an schema element declaration/particle |
19565 | | * @param ctxt a schema parser context |
19566 | | */ |
19567 | | static void |
19568 | | xmlSchemaCheckElementDeclComponent(xmlSchemaElementPtr elemDecl, |
19569 | | xmlSchemaParserCtxtPtr ctxt) |
19570 | 0 | { |
19571 | 0 | if (elemDecl == NULL) |
19572 | 0 | return; |
19573 | 0 | if (elemDecl->flags & XML_SCHEMAS_ELEM_INTERNAL_CHECKED) |
19574 | 0 | return; |
19575 | 0 | elemDecl->flags |= XML_SCHEMAS_ELEM_INTERNAL_CHECKED; |
19576 | 0 | if (xmlSchemaCheckElemPropsCorrect(ctxt, elemDecl) == 0) { |
19577 | | /* |
19578 | | * Adds substitution group members. |
19579 | | */ |
19580 | 0 | xmlSchemaCheckElemSubstGroup(ctxt, elemDecl); |
19581 | 0 | } |
19582 | 0 | } |
19583 | | |
19584 | | /** |
19585 | | * Resolves references of a model group's {particles} to |
19586 | | * model group definitions and to element declarations. |
19587 | | * |
19588 | | * @param ctxt a parser context |
19589 | | * @param mg a model group |
19590 | | */ |
19591 | | static void |
19592 | | xmlSchemaResolveModelGroupParticleReferences( |
19593 | | xmlSchemaParserCtxtPtr ctxt, |
19594 | | xmlSchemaModelGroupPtr mg) |
19595 | 0 | { |
19596 | 0 | xmlSchemaParticlePtr particle = WXS_MODELGROUP_PARTICLE(mg); |
19597 | 0 | xmlSchemaQNameRefPtr ref; |
19598 | 0 | xmlSchemaBasicItemPtr refItem; |
19599 | | |
19600 | | /* |
19601 | | * URGENT TODO: Test this. |
19602 | | */ |
19603 | 0 | while (particle != NULL) { |
19604 | 0 | if ((WXS_PARTICLE_TERM(particle) == NULL) || |
19605 | 0 | ((WXS_PARTICLE_TERM(particle))->type != |
19606 | 0 | XML_SCHEMA_EXTRA_QNAMEREF)) |
19607 | 0 | { |
19608 | 0 | goto next_particle; |
19609 | 0 | } |
19610 | 0 | ref = WXS_QNAME_CAST WXS_PARTICLE_TERM(particle); |
19611 | | /* |
19612 | | * Resolve the reference. |
19613 | | * NULL the {term} by default. |
19614 | | */ |
19615 | 0 | particle->children = NULL; |
19616 | |
|
19617 | 0 | refItem = xmlSchemaGetNamedComponent(ctxt->schema, |
19618 | 0 | ref->itemType, ref->name, ref->targetNamespace); |
19619 | 0 | if (refItem == NULL) { |
19620 | 0 | xmlSchemaPResCompAttrErr(ctxt, XML_SCHEMAP_SRC_RESOLVE, |
19621 | 0 | NULL, WXS_ITEM_NODE(particle), "ref", ref->name, |
19622 | 0 | ref->targetNamespace, ref->itemType, NULL); |
19623 | | /* TODO: remove the particle. */ |
19624 | 0 | goto next_particle; |
19625 | 0 | } |
19626 | 0 | if (refItem->type == XML_SCHEMA_TYPE_GROUP) { |
19627 | 0 | if (WXS_MODELGROUPDEF_MODEL(refItem) == NULL) |
19628 | | /* TODO: remove the particle. */ |
19629 | 0 | goto next_particle; |
19630 | | /* |
19631 | | * NOTE that we will assign the model group definition |
19632 | | * itself to the "term" of the particle. This will ease |
19633 | | * the check for circular model group definitions. After |
19634 | | * that the "term" will be assigned the model group of the |
19635 | | * model group definition. |
19636 | | */ |
19637 | 0 | if ((WXS_MODELGROUPDEF_MODEL(refItem))->type == |
19638 | 0 | XML_SCHEMA_TYPE_ALL) { |
19639 | | /* |
19640 | | * SPEC cos-all-limited (1) |
19641 | | * SPEC cos-all-limited (1.2) |
19642 | | * "It appears only as the value of one or both of the |
19643 | | * following properties:" |
19644 | | * (1.1) "the {model group} property of a model group |
19645 | | * definition." |
19646 | | * (1.2) "the {term} property of a particle [... of] the " |
19647 | | * {content type} of a complex type definition." |
19648 | | */ |
19649 | 0 | xmlSchemaCustomErr(ACTXT_CAST ctxt, |
19650 | | /* TODO: error code */ |
19651 | 0 | XML_SCHEMAP_COS_ALL_LIMITED, |
19652 | 0 | WXS_ITEM_NODE(particle), NULL, |
19653 | 0 | "A model group definition is referenced, but " |
19654 | 0 | "it contains an 'all' model group, which " |
19655 | 0 | "cannot be contained by model groups", |
19656 | 0 | NULL, NULL); |
19657 | | /* TODO: remove the particle. */ |
19658 | 0 | goto next_particle; |
19659 | 0 | } |
19660 | 0 | particle->children = (xmlSchemaTreeItemPtr) refItem; |
19661 | 0 | } else { |
19662 | | /* |
19663 | | * TODO: Are referenced element declarations the only |
19664 | | * other components we expect here? |
19665 | | */ |
19666 | 0 | particle->children = (xmlSchemaTreeItemPtr) refItem; |
19667 | 0 | } |
19668 | 0 | next_particle: |
19669 | 0 | particle = WXS_PTC_CAST particle->next; |
19670 | 0 | } |
19671 | 0 | } |
19672 | | |
19673 | | static int |
19674 | | xmlSchemaAreValuesEqual(xmlSchemaValPtr x, |
19675 | | xmlSchemaValPtr y) |
19676 | 0 | { |
19677 | 0 | xmlSchemaTypePtr tx, ty, ptx, pty; |
19678 | 0 | int ret; |
19679 | |
|
19680 | 0 | while (x != NULL) { |
19681 | | /* Same types. */ |
19682 | 0 | tx = xmlSchemaGetBuiltInType(xmlSchemaGetValType(x)); |
19683 | 0 | ty = xmlSchemaGetBuiltInType(xmlSchemaGetValType(y)); |
19684 | 0 | ptx = xmlSchemaGetPrimitiveType(tx); |
19685 | 0 | pty = xmlSchemaGetPrimitiveType(ty); |
19686 | | /* |
19687 | | * (1) if a datatype T' is `derived` by `restriction` from an |
19688 | | * atomic datatype T then the `value space` of T' is a subset of |
19689 | | * the `value space` of T. */ |
19690 | | /* |
19691 | | * (2) if datatypes T' and T'' are `derived` by `restriction` |
19692 | | * from a common atomic ancestor T then the `value space`s of T' |
19693 | | * and T'' may overlap. |
19694 | | */ |
19695 | 0 | if (ptx != pty) |
19696 | 0 | return(0); |
19697 | | /* |
19698 | | * We assume computed values to be normalized, so do a fast |
19699 | | * string comparison for string based types. |
19700 | | */ |
19701 | 0 | if ((ptx->builtInType == XML_SCHEMAS_STRING) || |
19702 | 0 | WXS_IS_ANY_SIMPLE_TYPE(ptx)) { |
19703 | 0 | if (! xmlStrEqual( |
19704 | 0 | xmlSchemaValueGetAsString(x), |
19705 | 0 | xmlSchemaValueGetAsString(y))) |
19706 | 0 | return (0); |
19707 | 0 | } else { |
19708 | 0 | ret = xmlSchemaCompareValuesWhtsp( |
19709 | 0 | x, XML_SCHEMA_WHITESPACE_PRESERVE, |
19710 | 0 | y, XML_SCHEMA_WHITESPACE_PRESERVE); |
19711 | 0 | if (ret == -2) |
19712 | 0 | return(-1); |
19713 | 0 | if (ret != 0) |
19714 | 0 | return(0); |
19715 | 0 | } |
19716 | | /* |
19717 | | * Lists. |
19718 | | */ |
19719 | 0 | x = xmlSchemaValueGetNext(x); |
19720 | 0 | if (x != NULL) { |
19721 | 0 | y = xmlSchemaValueGetNext(y); |
19722 | 0 | if (y == NULL) |
19723 | 0 | return (0); |
19724 | 0 | } else if (xmlSchemaValueGetNext(y) != NULL) |
19725 | 0 | return (0); |
19726 | 0 | else |
19727 | 0 | return (1); |
19728 | 0 | } |
19729 | 0 | return (0); |
19730 | 0 | } |
19731 | | |
19732 | | /** |
19733 | | * Resolves the referenced attribute declaration. |
19734 | | * |
19735 | | * @param ause an attribute use |
19736 | | * @param ctxt a parser context |
19737 | | */ |
19738 | | static int |
19739 | | xmlSchemaResolveAttrUseReferences(xmlSchemaAttributeUsePtr ause, |
19740 | | xmlSchemaParserCtxtPtr ctxt) |
19741 | 0 | { |
19742 | 0 | if ((ctxt == NULL) || (ause == NULL)) |
19743 | 0 | return(-1); |
19744 | 0 | if ((ause->attrDecl == NULL) || |
19745 | 0 | (ause->attrDecl->type != XML_SCHEMA_EXTRA_QNAMEREF)) |
19746 | 0 | return(0); |
19747 | | |
19748 | 0 | { |
19749 | 0 | xmlSchemaQNameRefPtr ref = WXS_QNAME_CAST ause->attrDecl; |
19750 | | |
19751 | | /* |
19752 | | * TODO: Evaluate, what errors could occur if the declaration is not |
19753 | | * found. |
19754 | | */ |
19755 | 0 | ause->attrDecl = xmlSchemaGetAttributeDecl(ctxt->schema, |
19756 | 0 | ref->name, ref->targetNamespace); |
19757 | 0 | if (ause->attrDecl == NULL) { |
19758 | 0 | xmlSchemaPResCompAttrErr(ctxt, |
19759 | 0 | XML_SCHEMAP_SRC_RESOLVE, |
19760 | 0 | WXS_BASIC_CAST ause, ause->node, |
19761 | 0 | "ref", ref->name, ref->targetNamespace, |
19762 | 0 | XML_SCHEMA_TYPE_ATTRIBUTE, NULL); |
19763 | 0 | return(ctxt->err);; |
19764 | 0 | } |
19765 | 0 | } |
19766 | 0 | return(0); |
19767 | 0 | } |
19768 | | |
19769 | | /** |
19770 | | * Schema Component Constraint: |
19771 | | * Attribute Use Correct (au-props-correct) |
19772 | | * |
19773 | | * @param ctxt a parser context |
19774 | | * @param use an attribute use |
19775 | | */ |
19776 | | static int |
19777 | | xmlSchemaCheckAttrUsePropsCorrect(xmlSchemaParserCtxtPtr ctxt, |
19778 | | xmlSchemaAttributeUsePtr use) |
19779 | 0 | { |
19780 | 0 | if ((ctxt == NULL) || (use == NULL)) |
19781 | 0 | return(-1); |
19782 | 0 | if ((use->defValue == NULL) || (WXS_ATTRUSE_DECL(use) == NULL) || |
19783 | 0 | ((WXS_ATTRUSE_DECL(use))->type != XML_SCHEMA_TYPE_ATTRIBUTE)) |
19784 | 0 | return(0); |
19785 | | |
19786 | | /* |
19787 | | * SPEC au-props-correct (1) |
19788 | | * "The values of the properties of an attribute use must be as |
19789 | | * described in the property tableau in The Attribute Use Schema |
19790 | | * Component ($3.5.1), modulo the impact of Missing |
19791 | | * Sub-components ($5.3)." |
19792 | | */ |
19793 | | |
19794 | 0 | if (((WXS_ATTRUSE_DECL(use))->defValue != NULL) && |
19795 | 0 | ((WXS_ATTRUSE_DECL(use))->flags & XML_SCHEMAS_ATTR_FIXED) && |
19796 | 0 | ((use->flags & XML_SCHEMA_ATTR_USE_FIXED) == 0)) |
19797 | 0 | { |
19798 | 0 | xmlSchemaPCustomErr(ctxt, |
19799 | 0 | XML_SCHEMAP_AU_PROPS_CORRECT_2, |
19800 | 0 | WXS_BASIC_CAST use, NULL, |
19801 | 0 | "The attribute declaration has a 'fixed' value constraint " |
19802 | 0 | ", thus the attribute use must also have a 'fixed' value " |
19803 | 0 | "constraint", |
19804 | 0 | NULL); |
19805 | 0 | return(ctxt->err); |
19806 | 0 | } |
19807 | | /* |
19808 | | * Compute and check the value constraint's value. |
19809 | | */ |
19810 | 0 | if ((use->defVal != NULL) && (WXS_ATTRUSE_TYPEDEF(use) != NULL)) { |
19811 | 0 | int ret; |
19812 | | /* |
19813 | | * TODO: The spec seems to be missing a check of the |
19814 | | * value constraint of the attribute use. We will do it here. |
19815 | | */ |
19816 | | /* |
19817 | | * SPEC a-props-correct (3) |
19818 | | */ |
19819 | 0 | if (xmlSchemaIsDerivedFromBuiltInType( |
19820 | 0 | WXS_ATTRUSE_TYPEDEF(use), XML_SCHEMAS_ID)) |
19821 | 0 | { |
19822 | 0 | xmlSchemaCustomErr(ACTXT_CAST ctxt, |
19823 | 0 | XML_SCHEMAP_AU_PROPS_CORRECT, |
19824 | 0 | NULL, WXS_BASIC_CAST use, |
19825 | 0 | "Value constraints are not allowed if the type definition " |
19826 | 0 | "is or is derived from xs:ID", |
19827 | 0 | NULL, NULL); |
19828 | 0 | return(ctxt->err); |
19829 | 0 | } |
19830 | | |
19831 | 0 | ret = xmlSchemaVCheckCVCSimpleType(ACTXT_CAST ctxt, |
19832 | 0 | use->node, WXS_ATTRUSE_TYPEDEF(use), |
19833 | 0 | use->defValue, &(use->defVal), |
19834 | 0 | 1, 1, 0); |
19835 | 0 | if (ret != 0) { |
19836 | 0 | if (ret < 0) { |
19837 | 0 | PERROR_INT2("xmlSchemaCheckAttrUsePropsCorrect", |
19838 | 0 | "calling xmlSchemaVCheckCVCSimpleType()"); |
19839 | 0 | return(-1); |
19840 | 0 | } |
19841 | 0 | xmlSchemaCustomErr(ACTXT_CAST ctxt, |
19842 | 0 | XML_SCHEMAP_AU_PROPS_CORRECT, |
19843 | 0 | NULL, WXS_BASIC_CAST use, |
19844 | 0 | "The value of the value constraint is not valid", |
19845 | 0 | NULL, NULL); |
19846 | 0 | return(ctxt->err); |
19847 | 0 | } |
19848 | 0 | } |
19849 | | /* |
19850 | | * SPEC au-props-correct (2) |
19851 | | * "If the {attribute declaration} has a fixed |
19852 | | * {value constraint}, then if the attribute use itself has a |
19853 | | * {value constraint}, it must also be fixed and its value must match |
19854 | | * that of the {attribute declaration}'s {value constraint}." |
19855 | | */ |
19856 | 0 | if (((WXS_ATTRUSE_DECL(use))->defVal != NULL) && |
19857 | 0 | (((WXS_ATTRUSE_DECL(use))->flags & XML_SCHEMA_ATTR_USE_FIXED) == 0)) |
19858 | 0 | { |
19859 | 0 | if (! xmlSchemaAreValuesEqual(use->defVal, |
19860 | 0 | (WXS_ATTRUSE_DECL(use))->defVal)) |
19861 | 0 | { |
19862 | 0 | xmlSchemaPCustomErr(ctxt, |
19863 | 0 | XML_SCHEMAP_AU_PROPS_CORRECT_2, |
19864 | 0 | WXS_BASIC_CAST use, NULL, |
19865 | 0 | "The 'fixed' value constraint of the attribute use " |
19866 | 0 | "must match the attribute declaration's value " |
19867 | 0 | "constraint '%s'", |
19868 | 0 | (WXS_ATTRUSE_DECL(use))->defValue); |
19869 | 0 | } |
19870 | 0 | return(ctxt->err); |
19871 | 0 | } |
19872 | 0 | return(0); |
19873 | 0 | } |
19874 | | |
19875 | | |
19876 | | |
19877 | | |
19878 | | /** |
19879 | | * Resolves the referenced type definition component. |
19880 | | * |
19881 | | * @param item an attribute declaration |
19882 | | * @param ctxt a parser context |
19883 | | */ |
19884 | | static int |
19885 | | xmlSchemaResolveAttrTypeReferences(xmlSchemaAttributePtr item, |
19886 | | xmlSchemaParserCtxtPtr ctxt) |
19887 | 0 | { |
19888 | | /* |
19889 | | * The simple type definition corresponding to the <simpleType> element |
19890 | | * information item in the [children], if present, otherwise the simple |
19891 | | * type definition `resolved` to by the `actual value` of the type |
19892 | | * [attribute], if present, otherwise the `simple ur-type definition`. |
19893 | | */ |
19894 | 0 | if (item->flags & XML_SCHEMAS_ATTR_INTERNAL_RESOLVED) |
19895 | 0 | return(0); |
19896 | 0 | item->flags |= XML_SCHEMAS_ATTR_INTERNAL_RESOLVED; |
19897 | 0 | if (item->subtypes != NULL) |
19898 | 0 | return(0); |
19899 | 0 | if (item->typeName != NULL) { |
19900 | 0 | xmlSchemaTypePtr type; |
19901 | |
|
19902 | 0 | type = xmlSchemaGetType(ctxt->schema, item->typeName, |
19903 | 0 | item->typeNs); |
19904 | 0 | if ((type == NULL) || (! WXS_IS_SIMPLE(type))) { |
19905 | 0 | xmlSchemaPResCompAttrErr(ctxt, |
19906 | 0 | XML_SCHEMAP_SRC_RESOLVE, |
19907 | 0 | WXS_BASIC_CAST item, item->node, |
19908 | 0 | "type", item->typeName, item->typeNs, |
19909 | 0 | XML_SCHEMA_TYPE_SIMPLE, NULL); |
19910 | 0 | return(ctxt->err); |
19911 | 0 | } else |
19912 | 0 | item->subtypes = type; |
19913 | |
|
19914 | 0 | } else { |
19915 | | /* |
19916 | | * The type defaults to the xs:anySimpleType. |
19917 | | */ |
19918 | 0 | item->subtypes = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE); |
19919 | 0 | } |
19920 | 0 | return(0); |
19921 | 0 | } |
19922 | | |
19923 | | /** |
19924 | | * Resolve keyRef references to key/unique IDCs. |
19925 | | * Schema Component Constraint: |
19926 | | * Identity-constraint Definition Properties Correct (c-props-correct) |
19927 | | * |
19928 | | * @param idc the identity-constraint definition |
19929 | | * @param pctxt the schema parser context |
19930 | | */ |
19931 | | static int |
19932 | | xmlSchemaResolveIDCKeyReferences(xmlSchemaIDCPtr idc, |
19933 | | xmlSchemaParserCtxtPtr pctxt) |
19934 | 0 | { |
19935 | 0 | if (idc->type != XML_SCHEMA_TYPE_IDC_KEYREF) |
19936 | 0 | return(0); |
19937 | 0 | if (idc->ref->name != NULL) { |
19938 | 0 | idc->ref->item = (xmlSchemaBasicItemPtr) |
19939 | 0 | xmlSchemaGetIDC(pctxt->schema, idc->ref->name, |
19940 | 0 | idc->ref->targetNamespace); |
19941 | 0 | if (idc->ref->item == NULL) { |
19942 | | /* |
19943 | | * TODO: It is actually not an error to fail to resolve |
19944 | | * at this stage. BUT we need to be that strict! |
19945 | | */ |
19946 | 0 | xmlSchemaPResCompAttrErr(pctxt, |
19947 | 0 | XML_SCHEMAP_SRC_RESOLVE, |
19948 | 0 | WXS_BASIC_CAST idc, idc->node, |
19949 | 0 | "refer", idc->ref->name, |
19950 | 0 | idc->ref->targetNamespace, |
19951 | 0 | XML_SCHEMA_TYPE_IDC_KEY, NULL); |
19952 | 0 | return(pctxt->err); |
19953 | 0 | } else if (idc->ref->item->type == XML_SCHEMA_TYPE_IDC_KEYREF) { |
19954 | | /* |
19955 | | * SPEC c-props-correct (1) |
19956 | | */ |
19957 | 0 | xmlSchemaCustomErr(ACTXT_CAST pctxt, |
19958 | 0 | XML_SCHEMAP_C_PROPS_CORRECT, |
19959 | 0 | NULL, WXS_BASIC_CAST idc, |
19960 | 0 | "The keyref references a keyref", |
19961 | 0 | NULL, NULL); |
19962 | 0 | idc->ref->item = NULL; |
19963 | 0 | return(pctxt->err); |
19964 | 0 | } else { |
19965 | 0 | if (idc->nbFields != |
19966 | 0 | ((xmlSchemaIDCPtr) idc->ref->item)->nbFields) { |
19967 | 0 | xmlChar *str = NULL; |
19968 | 0 | xmlSchemaIDCPtr refer; |
19969 | |
|
19970 | 0 | refer = (xmlSchemaIDCPtr) idc->ref->item; |
19971 | | /* |
19972 | | * SPEC c-props-correct(2) |
19973 | | * "If the {identity-constraint category} is keyref, |
19974 | | * the cardinality of the {fields} must equal that of |
19975 | | * the {fields} of the {referenced key}. |
19976 | | */ |
19977 | 0 | xmlSchemaCustomErr(ACTXT_CAST pctxt, |
19978 | 0 | XML_SCHEMAP_C_PROPS_CORRECT, |
19979 | 0 | NULL, WXS_BASIC_CAST idc, |
19980 | 0 | "The cardinality of the keyref differs from the " |
19981 | 0 | "cardinality of the referenced key/unique '%s'", |
19982 | 0 | xmlSchemaFormatQName(&str, refer->targetNamespace, |
19983 | 0 | refer->name), |
19984 | 0 | NULL); |
19985 | 0 | FREE_AND_NULL(str) |
19986 | 0 | return(pctxt->err); |
19987 | 0 | } |
19988 | 0 | } |
19989 | 0 | } |
19990 | 0 | return(0); |
19991 | 0 | } |
19992 | | |
19993 | | static int |
19994 | | xmlSchemaResolveAttrUseProhibReferences(xmlSchemaAttributeUseProhibPtr prohib, |
19995 | | xmlSchemaParserCtxtPtr pctxt) |
19996 | 0 | { |
19997 | 0 | if (xmlSchemaGetAttributeDecl(pctxt->schema, prohib->name, |
19998 | 0 | prohib->targetNamespace) == NULL) { |
19999 | |
|
20000 | 0 | xmlSchemaPResCompAttrErr(pctxt, |
20001 | 0 | XML_SCHEMAP_SRC_RESOLVE, |
20002 | 0 | NULL, prohib->node, |
20003 | 0 | "ref", prohib->name, prohib->targetNamespace, |
20004 | 0 | XML_SCHEMA_TYPE_ATTRIBUTE, NULL); |
20005 | 0 | return(XML_SCHEMAP_SRC_RESOLVE); |
20006 | 0 | } |
20007 | 0 | return(0); |
20008 | 0 | } |
20009 | | |
20010 | 0 | #define WXS_REDEFINED_TYPE(c) \ |
20011 | 0 | (((xmlSchemaTypePtr) item)->flags & XML_SCHEMAS_TYPE_REDEFINED) |
20012 | | |
20013 | 0 | #define WXS_REDEFINED_MODEL_GROUP_DEF(c) \ |
20014 | 0 | (((xmlSchemaModelGroupDefPtr) item)->flags & XML_SCHEMA_MODEL_GROUP_DEF_REDEFINED) |
20015 | | |
20016 | 0 | #define WXS_REDEFINED_ATTR_GROUP(c) \ |
20017 | 0 | (((xmlSchemaAttributeGroupPtr) item)->flags & XML_SCHEMAS_ATTRGROUP_REDEFINED) |
20018 | | |
20019 | | static int |
20020 | | xmlSchemaCheckSRCRedefineFirst(xmlSchemaParserCtxtPtr pctxt) |
20021 | 0 | { |
20022 | 0 | int err = 0; |
20023 | 0 | xmlSchemaRedefPtr redef = WXS_CONSTRUCTOR(pctxt)->redefs; |
20024 | 0 | xmlSchemaBasicItemPtr prev, item; |
20025 | 0 | int wasRedefined; |
20026 | |
|
20027 | 0 | if (redef == NULL) |
20028 | 0 | return(0); |
20029 | | |
20030 | 0 | do { |
20031 | 0 | item = redef->item; |
20032 | | /* |
20033 | | * First try to locate the redefined component in the |
20034 | | * schema graph starting with the redefined schema. |
20035 | | * NOTE: According to this schema bug entry: |
20036 | | * http://lists.w3.org/Archives/Public/www-xml-schema-comments/2005OctDec/0019.html |
20037 | | * it's not clear if the referenced component needs to originate |
20038 | | * from the <redefine>d schema _document_ or the schema; the latter |
20039 | | * would include all imported and included sub-schemas of the |
20040 | | * <redefine>d schema. Currently the latter approach is used. |
20041 | | * SUPPLEMENT: It seems that the WG moves towards the latter |
20042 | | * approach, so we are doing it right. |
20043 | | * |
20044 | | */ |
20045 | 0 | prev = xmlSchemaFindRedefCompInGraph( |
20046 | 0 | redef->targetBucket, item->type, |
20047 | 0 | redef->refName, redef->refTargetNs); |
20048 | 0 | if (prev == NULL) { |
20049 | 0 | xmlChar *str = NULL; |
20050 | 0 | xmlNodePtr node; |
20051 | | |
20052 | | /* |
20053 | | * SPEC src-redefine: |
20054 | | * (6.2.1) "The `actual value` of its own name attribute plus |
20055 | | * target namespace must successfully `resolve` to a model |
20056 | | * group definition in I." |
20057 | | * (7.2.1) "The `actual value` of its own name attribute plus |
20058 | | * target namespace must successfully `resolve` to an attribute |
20059 | | * group definition in I." |
20060 | | |
20061 | | * |
20062 | | * Note that, if we are redefining with the use of references |
20063 | | * to components, the spec assumes the src-resolve to be used; |
20064 | | * but this won't assure that we search only *inside* the |
20065 | | * redefined schema. |
20066 | | */ |
20067 | 0 | if (redef->reference) |
20068 | 0 | node = WXS_ITEM_NODE(redef->reference); |
20069 | 0 | else |
20070 | 0 | node = WXS_ITEM_NODE(item); |
20071 | 0 | xmlSchemaCustomErr(ACTXT_CAST pctxt, |
20072 | | /* |
20073 | | * TODO: error code. |
20074 | | * Probably XML_SCHEMAP_SRC_RESOLVE, if this is using the |
20075 | | * reference kind. |
20076 | | */ |
20077 | 0 | XML_SCHEMAP_SRC_REDEFINE, node, NULL, |
20078 | 0 | "The %s '%s' to be redefined could not be found in " |
20079 | 0 | "the redefined schema", |
20080 | 0 | WXS_ITEM_TYPE_NAME(item), |
20081 | 0 | xmlSchemaFormatQName(&str, redef->refTargetNs, |
20082 | 0 | redef->refName)); |
20083 | 0 | FREE_AND_NULL(str); |
20084 | 0 | err = pctxt->err; |
20085 | 0 | redef = redef->next; |
20086 | 0 | continue; |
20087 | 0 | } |
20088 | | /* |
20089 | | * TODO: Obtaining and setting the redefinition state is really |
20090 | | * clumsy. |
20091 | | */ |
20092 | 0 | wasRedefined = 0; |
20093 | 0 | switch (item->type) { |
20094 | 0 | case XML_SCHEMA_TYPE_COMPLEX: |
20095 | 0 | case XML_SCHEMA_TYPE_SIMPLE: |
20096 | 0 | if ((WXS_TYPE_CAST prev)->flags & |
20097 | 0 | XML_SCHEMAS_TYPE_REDEFINED) |
20098 | 0 | { |
20099 | 0 | wasRedefined = 1; |
20100 | 0 | break; |
20101 | 0 | } |
20102 | | /* Mark it as redefined. */ |
20103 | 0 | (WXS_TYPE_CAST prev)->flags |= XML_SCHEMAS_TYPE_REDEFINED; |
20104 | | /* |
20105 | | * Assign the redefined type to the |
20106 | | * base type of the redefining type. |
20107 | | * TODO: How |
20108 | | */ |
20109 | 0 | ((xmlSchemaTypePtr) item)->baseType = |
20110 | 0 | (xmlSchemaTypePtr) prev; |
20111 | 0 | break; |
20112 | 0 | case XML_SCHEMA_TYPE_GROUP: |
20113 | 0 | if ((WXS_MODEL_GROUPDEF_CAST prev)->flags & |
20114 | 0 | XML_SCHEMA_MODEL_GROUP_DEF_REDEFINED) |
20115 | 0 | { |
20116 | 0 | wasRedefined = 1; |
20117 | 0 | break; |
20118 | 0 | } |
20119 | | /* Mark it as redefined. */ |
20120 | 0 | (WXS_MODEL_GROUPDEF_CAST prev)->flags |= |
20121 | 0 | XML_SCHEMA_MODEL_GROUP_DEF_REDEFINED; |
20122 | 0 | if (redef->reference != NULL) { |
20123 | | /* |
20124 | | * Overwrite the QName-reference with the |
20125 | | * referenced model group def. |
20126 | | */ |
20127 | 0 | (WXS_PTC_CAST redef->reference)->children = |
20128 | 0 | WXS_TREE_CAST prev; |
20129 | 0 | } |
20130 | 0 | redef->target = prev; |
20131 | 0 | break; |
20132 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
20133 | 0 | if ((WXS_ATTR_GROUP_CAST prev)->flags & |
20134 | 0 | XML_SCHEMAS_ATTRGROUP_REDEFINED) |
20135 | 0 | { |
20136 | 0 | wasRedefined = 1; |
20137 | 0 | break; |
20138 | 0 | } |
20139 | 0 | (WXS_ATTR_GROUP_CAST prev)->flags |= |
20140 | 0 | XML_SCHEMAS_ATTRGROUP_REDEFINED; |
20141 | 0 | if (redef->reference != NULL) { |
20142 | | /* |
20143 | | * Assign the redefined attribute group to the |
20144 | | * QName-reference component. |
20145 | | * This is the easy case, since we will just |
20146 | | * expand the redefined group. |
20147 | | */ |
20148 | 0 | (WXS_QNAME_CAST redef->reference)->item = prev; |
20149 | 0 | redef->target = NULL; |
20150 | 0 | } else { |
20151 | | /* |
20152 | | * This is the complicated case: we need |
20153 | | * to apply src-redefine (7.2.2) at a later |
20154 | | * stage, i.e. when attribute group references |
20155 | | * have been expanded and simple types have |
20156 | | * been fixed. |
20157 | | */ |
20158 | 0 | redef->target = prev; |
20159 | 0 | } |
20160 | 0 | break; |
20161 | 0 | default: |
20162 | 0 | PERROR_INT("xmlSchemaResolveRedefReferences", |
20163 | 0 | "Unexpected redefined component type"); |
20164 | 0 | return(-1); |
20165 | 0 | } |
20166 | 0 | if (wasRedefined) { |
20167 | 0 | xmlChar *str = NULL; |
20168 | 0 | xmlNodePtr node; |
20169 | |
|
20170 | 0 | if (redef->reference) |
20171 | 0 | node = WXS_ITEM_NODE(redef->reference); |
20172 | 0 | else |
20173 | 0 | node = WXS_ITEM_NODE(redef->item); |
20174 | |
|
20175 | 0 | xmlSchemaCustomErr(ACTXT_CAST pctxt, |
20176 | | /* TODO: error code. */ |
20177 | 0 | XML_SCHEMAP_SRC_REDEFINE, |
20178 | 0 | node, NULL, |
20179 | 0 | "The referenced %s was already redefined. Multiple " |
20180 | 0 | "redefinition of the same component is not supported", |
20181 | 0 | xmlSchemaGetComponentDesignation(&str, prev), |
20182 | 0 | NULL); |
20183 | 0 | FREE_AND_NULL(str) |
20184 | 0 | err = pctxt->err; |
20185 | 0 | redef = redef->next; |
20186 | 0 | continue; |
20187 | 0 | } |
20188 | 0 | redef = redef->next; |
20189 | 0 | } while (redef != NULL); |
20190 | | |
20191 | 0 | return(err); |
20192 | 0 | } |
20193 | | |
20194 | | static int |
20195 | | xmlSchemaCheckSRCRedefineSecond(xmlSchemaParserCtxtPtr pctxt) |
20196 | 0 | { |
20197 | 0 | int err = 0; |
20198 | 0 | xmlSchemaRedefPtr redef = WXS_CONSTRUCTOR(pctxt)->redefs; |
20199 | 0 | xmlSchemaBasicItemPtr item; |
20200 | |
|
20201 | 0 | if (redef == NULL) |
20202 | 0 | return(0); |
20203 | | |
20204 | 0 | do { |
20205 | 0 | if (redef->target == NULL) { |
20206 | 0 | redef = redef->next; |
20207 | 0 | continue; |
20208 | 0 | } |
20209 | 0 | item = redef->item; |
20210 | |
|
20211 | 0 | switch (item->type) { |
20212 | 0 | case XML_SCHEMA_TYPE_SIMPLE: |
20213 | 0 | case XML_SCHEMA_TYPE_COMPLEX: |
20214 | | /* |
20215 | | * Since the spec wants the {name} of the redefined |
20216 | | * type to be 'absent', we'll NULL it. |
20217 | | */ |
20218 | 0 | (WXS_TYPE_CAST redef->target)->name = NULL; |
20219 | | |
20220 | | /* |
20221 | | * TODO: Seems like there's nothing more to do. The normal |
20222 | | * inheritance mechanism is used. But not 100% sure. |
20223 | | */ |
20224 | 0 | break; |
20225 | 0 | case XML_SCHEMA_TYPE_GROUP: |
20226 | | /* |
20227 | | * URGENT TODO: |
20228 | | * SPEC src-redefine: |
20229 | | * (6.2.2) "The {model group} of the model group definition |
20230 | | * which corresponds to it per XML Representation of Model |
20231 | | * Group Definition Schema Components ($3.7.2) must be a |
20232 | | * `valid restriction` of the {model group} of that model |
20233 | | * group definition in I, as defined in Particle Valid |
20234 | | * (Restriction) ($3.9.6)." |
20235 | | */ |
20236 | 0 | break; |
20237 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
20238 | | /* |
20239 | | * SPEC src-redefine: |
20240 | | * (7.2.2) "The {attribute uses} and {attribute wildcard} of |
20241 | | * the attribute group definition which corresponds to it |
20242 | | * per XML Representation of Attribute Group Definition Schema |
20243 | | * Components ($3.6.2) must be `valid restrictions` of the |
20244 | | * {attribute uses} and {attribute wildcard} of that attribute |
20245 | | * group definition in I, as defined in clause 2, clause 3 and |
20246 | | * clause 4 of Derivation Valid (Restriction, Complex) |
20247 | | * ($3.4.6) (where references to the base type definition are |
20248 | | * understood as references to the attribute group definition |
20249 | | * in I)." |
20250 | | */ |
20251 | 0 | err = xmlSchemaCheckDerivationOKRestriction2to4(pctxt, |
20252 | 0 | XML_SCHEMA_ACTION_REDEFINE, |
20253 | 0 | item, redef->target, |
20254 | 0 | (WXS_ATTR_GROUP_CAST item)->attrUses, |
20255 | 0 | (WXS_ATTR_GROUP_CAST redef->target)->attrUses, |
20256 | 0 | (WXS_ATTR_GROUP_CAST item)->attributeWildcard, |
20257 | 0 | (WXS_ATTR_GROUP_CAST redef->target)->attributeWildcard); |
20258 | 0 | if (err == -1) |
20259 | 0 | return(-1); |
20260 | 0 | break; |
20261 | 0 | default: |
20262 | 0 | break; |
20263 | 0 | } |
20264 | 0 | redef = redef->next; |
20265 | 0 | } while (redef != NULL); |
20266 | 0 | return(0); |
20267 | 0 | } |
20268 | | |
20269 | | |
20270 | | static int |
20271 | | xmlSchemaAddComponents(xmlSchemaParserCtxtPtr pctxt, |
20272 | | xmlSchemaBucketPtr bucket) |
20273 | 0 | { |
20274 | 0 | xmlSchemaBasicItemPtr item; |
20275 | 0 | int err; |
20276 | 0 | xmlHashTablePtr *table; |
20277 | 0 | const xmlChar *name; |
20278 | 0 | int i; |
20279 | |
|
20280 | 0 | #define WXS_GET_GLOBAL_HASH(c, slot) { \ |
20281 | 0 | if (WXS_IS_BUCKET_IMPMAIN((c)->type)) \ |
20282 | 0 | table = &(WXS_IMPBUCKET((c))->schema->slot); \ |
20283 | 0 | else \ |
20284 | 0 | table = &(WXS_INCBUCKET((c))->ownerImport->schema->slot); } |
20285 | | |
20286 | | /* |
20287 | | * Add global components to the schema's hash tables. |
20288 | | * This is the place where duplicate components will be |
20289 | | * detected. |
20290 | | * TODO: I think normally we should support imports of the |
20291 | | * same namespace from multiple locations. We don't do currently, |
20292 | | * but if we do then according to: |
20293 | | * http://www.w3.org/Bugs/Public/show_bug.cgi?id=2224 |
20294 | | * we would need, if imported directly, to import redefined |
20295 | | * components as well to be able to catch clashing components. |
20296 | | * (I hope I'll still know what this means after some months :-() |
20297 | | */ |
20298 | 0 | if (bucket == NULL) |
20299 | 0 | return(-1); |
20300 | 0 | if (bucket->flags & XML_SCHEMA_BUCKET_COMPS_ADDED) |
20301 | 0 | return(0); |
20302 | 0 | bucket->flags |= XML_SCHEMA_BUCKET_COMPS_ADDED; |
20303 | |
|
20304 | 0 | for (i = 0; i < bucket->globals->nbItems; i++) { |
20305 | 0 | item = bucket->globals->items[i]; |
20306 | 0 | table = NULL; |
20307 | 0 | switch (item->type) { |
20308 | 0 | case XML_SCHEMA_TYPE_COMPLEX: |
20309 | 0 | case XML_SCHEMA_TYPE_SIMPLE: |
20310 | 0 | if (WXS_REDEFINED_TYPE(item)) |
20311 | 0 | continue; |
20312 | 0 | name = (WXS_TYPE_CAST item)->name; |
20313 | 0 | WXS_GET_GLOBAL_HASH(bucket, typeDecl) |
20314 | 0 | break; |
20315 | 0 | case XML_SCHEMA_TYPE_ELEMENT: |
20316 | 0 | name = (WXS_ELEM_CAST item)->name; |
20317 | 0 | WXS_GET_GLOBAL_HASH(bucket, elemDecl) |
20318 | 0 | break; |
20319 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTE: |
20320 | 0 | name = (WXS_ATTR_CAST item)->name; |
20321 | 0 | WXS_GET_GLOBAL_HASH(bucket, attrDecl) |
20322 | 0 | break; |
20323 | 0 | case XML_SCHEMA_TYPE_GROUP: |
20324 | 0 | if (WXS_REDEFINED_MODEL_GROUP_DEF(item)) |
20325 | 0 | continue; |
20326 | 0 | name = (WXS_MODEL_GROUPDEF_CAST item)->name; |
20327 | 0 | WXS_GET_GLOBAL_HASH(bucket, groupDecl) |
20328 | 0 | break; |
20329 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
20330 | 0 | if (WXS_REDEFINED_ATTR_GROUP(item)) |
20331 | 0 | continue; |
20332 | 0 | name = (WXS_ATTR_GROUP_CAST item)->name; |
20333 | 0 | WXS_GET_GLOBAL_HASH(bucket, attrgrpDecl) |
20334 | 0 | break; |
20335 | 0 | case XML_SCHEMA_TYPE_IDC_KEY: |
20336 | 0 | case XML_SCHEMA_TYPE_IDC_UNIQUE: |
20337 | 0 | case XML_SCHEMA_TYPE_IDC_KEYREF: |
20338 | 0 | name = (WXS_IDC_CAST item)->name; |
20339 | 0 | WXS_GET_GLOBAL_HASH(bucket, idcDef) |
20340 | 0 | break; |
20341 | 0 | case XML_SCHEMA_TYPE_NOTATION: |
20342 | 0 | name = ((xmlSchemaNotationPtr) item)->name; |
20343 | 0 | WXS_GET_GLOBAL_HASH(bucket, notaDecl) |
20344 | 0 | break; |
20345 | 0 | default: |
20346 | 0 | PERROR_INT("xmlSchemaAddComponents", |
20347 | 0 | "Unexpected global component type"); |
20348 | 0 | continue; |
20349 | 0 | } |
20350 | 0 | if (*table == NULL) { |
20351 | 0 | *table = xmlHashCreateDict(10, pctxt->dict); |
20352 | 0 | if (*table == NULL) { |
20353 | 0 | PERROR_INT("xmlSchemaAddComponents", |
20354 | 0 | "failed to create a component hash table"); |
20355 | 0 | return(-1); |
20356 | 0 | } |
20357 | 0 | } |
20358 | 0 | err = xmlHashAddEntry(*table, name, item); |
20359 | 0 | if (err != 0) { |
20360 | 0 | xmlChar *str = NULL; |
20361 | |
|
20362 | 0 | xmlSchemaCustomErr(ACTXT_CAST pctxt, |
20363 | 0 | XML_SCHEMAP_REDEFINED_TYPE, |
20364 | 0 | WXS_ITEM_NODE(item), |
20365 | 0 | WXS_BASIC_CAST item, |
20366 | 0 | "A global %s '%s' does already exist", |
20367 | 0 | WXS_ITEM_TYPE_NAME(item), |
20368 | 0 | xmlSchemaGetComponentQName(&str, item)); |
20369 | 0 | FREE_AND_NULL(str); |
20370 | 0 | } |
20371 | 0 | } |
20372 | | /* |
20373 | | * Process imported/included schemas. |
20374 | | */ |
20375 | 0 | if (bucket->relations != NULL) { |
20376 | 0 | xmlSchemaSchemaRelationPtr rel = bucket->relations; |
20377 | 0 | do { |
20378 | 0 | if ((rel->bucket != NULL) && |
20379 | 0 | ((rel->bucket->flags & XML_SCHEMA_BUCKET_COMPS_ADDED) == 0)) { |
20380 | 0 | if (xmlSchemaAddComponents(pctxt, rel->bucket) == -1) |
20381 | 0 | return(-1); |
20382 | 0 | } |
20383 | 0 | rel = rel->next; |
20384 | 0 | } while (rel != NULL); |
20385 | 0 | } |
20386 | 0 | return(0); |
20387 | 0 | } |
20388 | | |
20389 | | static int |
20390 | | xmlSchemaFixupComponents(xmlSchemaParserCtxtPtr pctxt, |
20391 | | xmlSchemaBucketPtr rootBucket) |
20392 | 0 | { |
20393 | 0 | xmlSchemaConstructionCtxtPtr con = pctxt->constructor; |
20394 | 0 | xmlSchemaTreeItemPtr item, *items; |
20395 | 0 | int nbItems, i, ret = 0; |
20396 | 0 | xmlSchemaBucketPtr oldbucket = con->bucket; |
20397 | 0 | xmlSchemaElementPtr elemDecl; |
20398 | |
|
20399 | 0 | #define FIXHFAILURE if (pctxt->err == XML_SCHEMAP_INTERNAL) goto exit_failure; |
20400 | |
|
20401 | 0 | if ((con->pending == NULL) || |
20402 | 0 | (con->pending->nbItems == 0)) |
20403 | 0 | return(0); |
20404 | | |
20405 | | /* |
20406 | | * Since xmlSchemaFixupComplexType() will create new particles |
20407 | | * (local components), and those particle components need a bucket |
20408 | | * on the constructor, we'll assure here that the constructor has |
20409 | | * a bucket. |
20410 | | * TODO: Think about storing locals _only_ on the main bucket. |
20411 | | */ |
20412 | 0 | if (con->bucket == NULL) |
20413 | 0 | con->bucket = rootBucket; |
20414 | | |
20415 | | /* TODO: |
20416 | | * SPEC (src-redefine): |
20417 | | * (6.2) "If it has no such self-reference, then all of the |
20418 | | * following must be true:" |
20419 | | |
20420 | | * (6.2.2) The {model group} of the model group definition which |
20421 | | * corresponds to it per XML Representation of Model Group |
20422 | | * Definition Schema Components ($3.7.2) must be a `valid |
20423 | | * restriction` of the {model group} of that model group definition |
20424 | | * in I, as defined in Particle Valid (Restriction) ($3.9.6)." |
20425 | | */ |
20426 | 0 | xmlSchemaCheckSRCRedefineFirst(pctxt); |
20427 | | |
20428 | | /* |
20429 | | * Add global components to the schemata's hash tables. |
20430 | | */ |
20431 | 0 | xmlSchemaAddComponents(pctxt, rootBucket); |
20432 | |
|
20433 | 0 | pctxt->ctxtType = NULL; |
20434 | 0 | items = (xmlSchemaTreeItemPtr *) con->pending->items; |
20435 | 0 | nbItems = con->pending->nbItems; |
20436 | | /* |
20437 | | * Now that we have parsed *all* the schema document(s) and converted |
20438 | | * them to schema components, we can resolve references, apply component |
20439 | | * constraints, create the FSA from the content model, etc. |
20440 | | */ |
20441 | | /* |
20442 | | * Resolve references of.. |
20443 | | * |
20444 | | * 1. element declarations: |
20445 | | * - the type definition |
20446 | | * - the substitution group affiliation |
20447 | | * 2. simple/complex types: |
20448 | | * - the base type definition |
20449 | | * - the memberTypes of union types |
20450 | | * - the itemType of list types |
20451 | | * 3. attributes declarations and attribute uses: |
20452 | | * - the type definition |
20453 | | * - if an attribute use, then the attribute declaration |
20454 | | * 4. attribute group references: |
20455 | | * - the attribute group definition |
20456 | | * 5. particles: |
20457 | | * - the term of the particle (e.g. a model group) |
20458 | | * 6. IDC key-references: |
20459 | | * - the referenced IDC 'key' or 'unique' definition |
20460 | | * 7. Attribute prohibitions which had a "ref" attribute. |
20461 | | */ |
20462 | 0 | for (i = 0; i < nbItems; i++) { |
20463 | 0 | item = items[i]; |
20464 | 0 | switch (item->type) { |
20465 | 0 | case XML_SCHEMA_TYPE_ELEMENT: |
20466 | 0 | xmlSchemaResolveElementReferences( |
20467 | 0 | (xmlSchemaElementPtr) item, pctxt); |
20468 | 0 | FIXHFAILURE; |
20469 | 0 | break; |
20470 | 0 | case XML_SCHEMA_TYPE_COMPLEX: |
20471 | 0 | case XML_SCHEMA_TYPE_SIMPLE: |
20472 | 0 | xmlSchemaResolveTypeReferences( |
20473 | 0 | (xmlSchemaTypePtr) item, pctxt); |
20474 | 0 | FIXHFAILURE; |
20475 | 0 | break; |
20476 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTE: |
20477 | 0 | xmlSchemaResolveAttrTypeReferences( |
20478 | 0 | (xmlSchemaAttributePtr) item, pctxt); |
20479 | 0 | FIXHFAILURE; |
20480 | 0 | break; |
20481 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTE_USE: |
20482 | 0 | xmlSchemaResolveAttrUseReferences( |
20483 | 0 | (xmlSchemaAttributeUsePtr) item, pctxt); |
20484 | 0 | FIXHFAILURE; |
20485 | 0 | break; |
20486 | 0 | case XML_SCHEMA_EXTRA_QNAMEREF: |
20487 | 0 | if ((WXS_QNAME_CAST item)->itemType == |
20488 | 0 | XML_SCHEMA_TYPE_ATTRIBUTEGROUP) |
20489 | 0 | { |
20490 | 0 | xmlSchemaResolveAttrGroupReferences( |
20491 | 0 | WXS_QNAME_CAST item, pctxt); |
20492 | 0 | } |
20493 | 0 | FIXHFAILURE; |
20494 | 0 | break; |
20495 | 0 | case XML_SCHEMA_TYPE_SEQUENCE: |
20496 | 0 | case XML_SCHEMA_TYPE_CHOICE: |
20497 | 0 | case XML_SCHEMA_TYPE_ALL: |
20498 | 0 | xmlSchemaResolveModelGroupParticleReferences(pctxt, |
20499 | 0 | WXS_MODEL_GROUP_CAST item); |
20500 | 0 | FIXHFAILURE; |
20501 | 0 | break; |
20502 | 0 | case XML_SCHEMA_TYPE_IDC_KEY: |
20503 | 0 | case XML_SCHEMA_TYPE_IDC_UNIQUE: |
20504 | 0 | case XML_SCHEMA_TYPE_IDC_KEYREF: |
20505 | 0 | xmlSchemaResolveIDCKeyReferences( |
20506 | 0 | (xmlSchemaIDCPtr) item, pctxt); |
20507 | 0 | FIXHFAILURE; |
20508 | 0 | break; |
20509 | 0 | case XML_SCHEMA_EXTRA_ATTR_USE_PROHIB: |
20510 | | /* |
20511 | | * Handle attribute prohibition which had a |
20512 | | * "ref" attribute. |
20513 | | */ |
20514 | 0 | xmlSchemaResolveAttrUseProhibReferences( |
20515 | 0 | WXS_ATTR_PROHIB_CAST item, pctxt); |
20516 | 0 | FIXHFAILURE; |
20517 | 0 | break; |
20518 | 0 | default: |
20519 | 0 | break; |
20520 | 0 | } |
20521 | 0 | } |
20522 | 0 | if (pctxt->nberrors != 0) |
20523 | 0 | goto exit_error; |
20524 | | |
20525 | | /* |
20526 | | * Now that all references are resolved we |
20527 | | * can check for circularity of... |
20528 | | * 1. the base axis of type definitions |
20529 | | * 2. nested model group definitions |
20530 | | * 3. nested attribute group definitions |
20531 | | * TODO: check for circular substitution groups. |
20532 | | */ |
20533 | 0 | for (i = 0; i < nbItems; i++) { |
20534 | 0 | item = items[i]; |
20535 | | /* |
20536 | | * Let's better stop on the first error here. |
20537 | | */ |
20538 | 0 | switch (item->type) { |
20539 | 0 | case XML_SCHEMA_TYPE_COMPLEX: |
20540 | 0 | case XML_SCHEMA_TYPE_SIMPLE: |
20541 | 0 | xmlSchemaCheckTypeDefCircular( |
20542 | 0 | (xmlSchemaTypePtr) item, pctxt); |
20543 | 0 | FIXHFAILURE; |
20544 | 0 | if (pctxt->nberrors != 0) |
20545 | 0 | goto exit_error; |
20546 | 0 | break; |
20547 | 0 | case XML_SCHEMA_TYPE_GROUP: |
20548 | 0 | xmlSchemaCheckGroupDefCircular( |
20549 | 0 | (xmlSchemaModelGroupDefPtr) item, pctxt); |
20550 | 0 | FIXHFAILURE; |
20551 | 0 | if (pctxt->nberrors != 0) |
20552 | 0 | goto exit_error; |
20553 | 0 | break; |
20554 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
20555 | 0 | xmlSchemaCheckAttrGroupCircular( |
20556 | 0 | (xmlSchemaAttributeGroupPtr) item, pctxt); |
20557 | 0 | FIXHFAILURE; |
20558 | 0 | if (pctxt->nberrors != 0) |
20559 | 0 | goto exit_error; |
20560 | 0 | break; |
20561 | 0 | default: |
20562 | 0 | break; |
20563 | 0 | } |
20564 | 0 | } |
20565 | 0 | if (pctxt->nberrors != 0) |
20566 | 0 | goto exit_error; |
20567 | | /* |
20568 | | * Model group definition references: |
20569 | | * Such a reference is reflected by a particle at the component |
20570 | | * level. Until now the 'term' of such particles pointed |
20571 | | * to the model group definition; this was done, in order to |
20572 | | * ease circularity checks. Now we need to set the 'term' of |
20573 | | * such particles to the model group of the model group definition. |
20574 | | */ |
20575 | 0 | for (i = 0; i < nbItems; i++) { |
20576 | 0 | item = items[i]; |
20577 | 0 | switch (item->type) { |
20578 | 0 | case XML_SCHEMA_TYPE_SEQUENCE: |
20579 | 0 | case XML_SCHEMA_TYPE_CHOICE: |
20580 | 0 | xmlSchemaModelGroupToModelGroupDefFixup(pctxt, |
20581 | 0 | WXS_MODEL_GROUP_CAST item); |
20582 | 0 | break; |
20583 | 0 | default: |
20584 | 0 | break; |
20585 | 0 | } |
20586 | 0 | } |
20587 | 0 | if (pctxt->nberrors != 0) |
20588 | 0 | goto exit_error; |
20589 | | /* |
20590 | | * Expand attribute group references of attribute group definitions. |
20591 | | */ |
20592 | 0 | for (i = 0; i < nbItems; i++) { |
20593 | 0 | item = items[i]; |
20594 | 0 | switch (item->type) { |
20595 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
20596 | 0 | if ((! WXS_ATTR_GROUP_EXPANDED(item)) && |
20597 | 0 | WXS_ATTR_GROUP_HAS_REFS(item)) |
20598 | 0 | { |
20599 | 0 | xmlSchemaAttributeGroupExpandRefs(pctxt, |
20600 | 0 | WXS_ATTR_GROUP_CAST item); |
20601 | 0 | FIXHFAILURE; |
20602 | 0 | } |
20603 | 0 | break; |
20604 | 0 | default: |
20605 | 0 | break; |
20606 | 0 | } |
20607 | 0 | } |
20608 | 0 | if (pctxt->nberrors != 0) |
20609 | 0 | goto exit_error; |
20610 | | /* |
20611 | | * First compute the variety of simple types. This is needed as |
20612 | | * a separate step, since otherwise we won't be able to detect |
20613 | | * circular union types in all cases. |
20614 | | */ |
20615 | 0 | for (i = 0; i < nbItems; i++) { |
20616 | 0 | item = items[i]; |
20617 | 0 | switch (item->type) { |
20618 | 0 | case XML_SCHEMA_TYPE_SIMPLE: |
20619 | 0 | if (WXS_IS_TYPE_NOT_FIXED_1((xmlSchemaTypePtr) item)) { |
20620 | 0 | xmlSchemaFixupSimpleTypeStageOne(pctxt, |
20621 | 0 | (xmlSchemaTypePtr) item); |
20622 | 0 | FIXHFAILURE; |
20623 | 0 | } |
20624 | 0 | break; |
20625 | 0 | default: |
20626 | 0 | break; |
20627 | 0 | } |
20628 | 0 | } |
20629 | 0 | if (pctxt->nberrors != 0) |
20630 | 0 | goto exit_error; |
20631 | | /* |
20632 | | * Detect circular union types. Note that this needs the variety to |
20633 | | * be already computed. |
20634 | | */ |
20635 | 0 | for (i = 0; i < nbItems; i++) { |
20636 | 0 | item = items[i]; |
20637 | 0 | switch (item->type) { |
20638 | 0 | case XML_SCHEMA_TYPE_SIMPLE: |
20639 | 0 | if (((xmlSchemaTypePtr) item)->memberTypes != NULL) { |
20640 | 0 | xmlSchemaCheckUnionTypeDefCircular(pctxt, |
20641 | 0 | (xmlSchemaTypePtr) item); |
20642 | 0 | FIXHFAILURE; |
20643 | 0 | } |
20644 | 0 | break; |
20645 | 0 | default: |
20646 | 0 | break; |
20647 | 0 | } |
20648 | 0 | } |
20649 | 0 | if (pctxt->nberrors != 0) |
20650 | 0 | goto exit_error; |
20651 | | |
20652 | | /* |
20653 | | * Do the complete type fixup for simple types. |
20654 | | */ |
20655 | 0 | for (i = 0; i < nbItems; i++) { |
20656 | 0 | item = items[i]; |
20657 | 0 | switch (item->type) { |
20658 | 0 | case XML_SCHEMA_TYPE_SIMPLE: |
20659 | 0 | if (WXS_IS_TYPE_NOT_FIXED(WXS_TYPE_CAST item)) { |
20660 | 0 | xmlSchemaFixupSimpleTypeStageTwo(pctxt, WXS_TYPE_CAST item); |
20661 | 0 | FIXHFAILURE; |
20662 | 0 | } |
20663 | 0 | break; |
20664 | 0 | default: |
20665 | 0 | break; |
20666 | 0 | } |
20667 | 0 | } |
20668 | 0 | if (pctxt->nberrors != 0) |
20669 | 0 | goto exit_error; |
20670 | | /* |
20671 | | * At this point we need build and check all simple types. |
20672 | | */ |
20673 | | /* |
20674 | | * Apply constraints for attribute declarations. |
20675 | | */ |
20676 | 0 | for (i = 0; i < nbItems; i++) { |
20677 | 0 | item = items[i]; |
20678 | 0 | switch (item->type) { |
20679 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTE: |
20680 | 0 | xmlSchemaCheckAttrPropsCorrect(pctxt, WXS_ATTR_CAST item); |
20681 | 0 | FIXHFAILURE; |
20682 | 0 | break; |
20683 | 0 | default: |
20684 | 0 | break; |
20685 | 0 | } |
20686 | 0 | } |
20687 | 0 | if (pctxt->nberrors != 0) |
20688 | 0 | goto exit_error; |
20689 | | /* |
20690 | | * Apply constraints for attribute uses. |
20691 | | */ |
20692 | 0 | for (i = 0; i < nbItems; i++) { |
20693 | 0 | item = items[i]; |
20694 | 0 | switch (item->type) { |
20695 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTE_USE: |
20696 | 0 | if (((xmlSchemaAttributeUsePtr)item)->defValue != NULL) { |
20697 | 0 | xmlSchemaCheckAttrUsePropsCorrect(pctxt, |
20698 | 0 | WXS_ATTR_USE_CAST item); |
20699 | 0 | FIXHFAILURE; |
20700 | 0 | } |
20701 | 0 | break; |
20702 | 0 | default: |
20703 | 0 | break; |
20704 | 0 | } |
20705 | 0 | } |
20706 | 0 | if (pctxt->nberrors != 0) |
20707 | 0 | goto exit_error; |
20708 | | |
20709 | | /* |
20710 | | * Apply constraints for attribute group definitions. |
20711 | | */ |
20712 | 0 | for (i = 0; i < nbItems; i++) { |
20713 | 0 | item = items[i]; |
20714 | 0 | switch (item->type) { |
20715 | 0 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
20716 | 0 | if (( (WXS_ATTR_GROUP_CAST item)->attrUses != NULL) && |
20717 | 0 | ( (WXS_LIST_CAST (WXS_ATTR_GROUP_CAST item)->attrUses)->nbItems > 1)) |
20718 | 0 | { |
20719 | 0 | xmlSchemaCheckAGPropsCorrect(pctxt, WXS_ATTR_GROUP_CAST item); |
20720 | 0 | FIXHFAILURE; |
20721 | 0 | } |
20722 | 0 | break; |
20723 | 0 | default: |
20724 | 0 | break; |
20725 | 0 | } |
20726 | 0 | } |
20727 | 0 | if (pctxt->nberrors != 0) |
20728 | 0 | goto exit_error; |
20729 | | |
20730 | | /* |
20731 | | * Apply constraints for redefinitions. |
20732 | | */ |
20733 | 0 | if (WXS_CONSTRUCTOR(pctxt)->redefs != NULL) |
20734 | 0 | xmlSchemaCheckSRCRedefineSecond(pctxt); |
20735 | 0 | if (pctxt->nberrors != 0) |
20736 | 0 | goto exit_error; |
20737 | | |
20738 | | /* |
20739 | | * Complex types are built and checked. |
20740 | | */ |
20741 | 0 | for (i = 0; i < nbItems; i++) { |
20742 | 0 | item = con->pending->items[i]; |
20743 | 0 | switch (item->type) { |
20744 | 0 | case XML_SCHEMA_TYPE_COMPLEX: |
20745 | 0 | if (WXS_IS_TYPE_NOT_FIXED(WXS_TYPE_CAST item)) { |
20746 | 0 | xmlSchemaFixupComplexType(pctxt, WXS_TYPE_CAST item); |
20747 | 0 | FIXHFAILURE; |
20748 | 0 | } |
20749 | 0 | break; |
20750 | 0 | default: |
20751 | 0 | break; |
20752 | 0 | } |
20753 | 0 | } |
20754 | 0 | if (pctxt->nberrors != 0) |
20755 | 0 | goto exit_error; |
20756 | | |
20757 | | /* |
20758 | | * The list could have changed, since xmlSchemaFixupComplexType() |
20759 | | * will create particles and model groups in some cases. |
20760 | | */ |
20761 | 0 | items = (xmlSchemaTreeItemPtr *) con->pending->items; |
20762 | 0 | nbItems = con->pending->nbItems; |
20763 | | |
20764 | | /* |
20765 | | * Apply some constraints for element declarations. |
20766 | | */ |
20767 | 0 | for (i = 0; i < nbItems; i++) { |
20768 | 0 | item = items[i]; |
20769 | 0 | switch (item->type) { |
20770 | 0 | case XML_SCHEMA_TYPE_ELEMENT: |
20771 | 0 | elemDecl = (xmlSchemaElementPtr) item; |
20772 | |
|
20773 | 0 | if ((elemDecl->flags & XML_SCHEMAS_ELEM_INTERNAL_CHECKED) == 0) |
20774 | 0 | { |
20775 | 0 | xmlSchemaCheckElementDeclComponent( |
20776 | 0 | (xmlSchemaElementPtr) elemDecl, pctxt); |
20777 | 0 | FIXHFAILURE; |
20778 | 0 | } |
20779 | | |
20780 | | #ifdef WXS_ELEM_DECL_CONS_ENABLED |
20781 | | /* |
20782 | | * Schema Component Constraint: Element Declarations Consistent |
20783 | | * Apply this constraint to local types of element declarations. |
20784 | | */ |
20785 | | if ((WXS_ELEM_TYPEDEF(elemDecl) != NULL) && |
20786 | | (WXS_IS_COMPLEX(WXS_ELEM_TYPEDEF(elemDecl))) && |
20787 | | (WXS_TYPE_IS_LOCAL(WXS_ELEM_TYPEDEF(elemDecl)))) |
20788 | | { |
20789 | | xmlSchemaCheckElementDeclConsistent(pctxt, |
20790 | | WXS_BASIC_CAST elemDecl, |
20791 | | WXS_TYPE_PARTICLE(WXS_ELEM_TYPEDEF(elemDecl)), |
20792 | | NULL, NULL, 0); |
20793 | | } |
20794 | | #endif |
20795 | 0 | break; |
20796 | 0 | default: |
20797 | 0 | break; |
20798 | 0 | } |
20799 | 0 | } |
20800 | 0 | if (pctxt->nberrors != 0) |
20801 | 0 | goto exit_error; |
20802 | | |
20803 | | /* |
20804 | | * Finally we can build the automaton from the content model of |
20805 | | * complex types. |
20806 | | */ |
20807 | | |
20808 | 0 | for (i = 0; i < nbItems; i++) { |
20809 | 0 | item = items[i]; |
20810 | 0 | switch (item->type) { |
20811 | 0 | case XML_SCHEMA_TYPE_COMPLEX: |
20812 | 0 | xmlSchemaBuildContentModel((xmlSchemaTypePtr) item, pctxt); |
20813 | | /* FIXHFAILURE; */ |
20814 | 0 | break; |
20815 | 0 | default: |
20816 | 0 | break; |
20817 | 0 | } |
20818 | 0 | } |
20819 | 0 | if (pctxt->nberrors != 0) |
20820 | 0 | goto exit_error; |
20821 | | /* |
20822 | | * URGENT TODO: cos-element-consistent |
20823 | | */ |
20824 | 0 | goto exit; |
20825 | | |
20826 | 0 | exit_error: |
20827 | 0 | ret = pctxt->err; |
20828 | 0 | goto exit; |
20829 | | |
20830 | 0 | exit_failure: |
20831 | 0 | ret = -1; |
20832 | |
|
20833 | 0 | exit: |
20834 | | /* |
20835 | | * Reset the constructor. This is needed for XSI acquisition, since |
20836 | | * those items will be processed over and over again for every XSI |
20837 | | * if not cleared here. |
20838 | | */ |
20839 | 0 | con->bucket = oldbucket; |
20840 | 0 | con->pending->nbItems = 0; |
20841 | 0 | if (con->substGroups != NULL) { |
20842 | 0 | xmlHashFree(con->substGroups, xmlSchemaSubstGroupFreeEntry); |
20843 | 0 | con->substGroups = NULL; |
20844 | 0 | } |
20845 | 0 | if (con->redefs != NULL) { |
20846 | 0 | xmlSchemaRedefListFree(con->redefs); |
20847 | 0 | con->redefs = NULL; |
20848 | 0 | } |
20849 | 0 | return(ret); |
20850 | 0 | } |
20851 | | /** |
20852 | | * parse a schema definition resource and build an internal |
20853 | | * XML Schema structure which can be used to validate instances. |
20854 | | * |
20855 | | * @param ctxt a schema validation context |
20856 | | * @returns the internal XML Schema structure built from the resource or |
20857 | | * NULL in case of error |
20858 | | */ |
20859 | | xmlSchema * |
20860 | | xmlSchemaParse(xmlSchemaParserCtxt *ctxt) |
20861 | 0 | { |
20862 | 0 | xmlSchemaPtr mainSchema = NULL; |
20863 | 0 | xmlSchemaBucketPtr bucket = NULL; |
20864 | 0 | int res; |
20865 | | |
20866 | | /* |
20867 | | * This one is used if the schema to be parsed was specified via |
20868 | | * the API; i.e. not automatically by the validated instance document. |
20869 | | */ |
20870 | |
|
20871 | 0 | if (xmlSchemaInitTypes() < 0) |
20872 | 0 | return (NULL); |
20873 | | |
20874 | 0 | if (ctxt == NULL) |
20875 | 0 | return (NULL); |
20876 | | |
20877 | | /* TODO: Init the context. Is this all we need?*/ |
20878 | 0 | ctxt->nberrors = 0; |
20879 | 0 | ctxt->err = 0; |
20880 | 0 | ctxt->counter = 0; |
20881 | | |
20882 | | /* Create the *main* schema. */ |
20883 | 0 | mainSchema = xmlSchemaNewSchema(ctxt); |
20884 | 0 | if (mainSchema == NULL) |
20885 | 0 | goto exit_failure; |
20886 | | /* |
20887 | | * Create the schema constructor. |
20888 | | */ |
20889 | 0 | if (ctxt->constructor == NULL) { |
20890 | 0 | ctxt->constructor = xmlSchemaConstructionCtxtCreate(ctxt->dict); |
20891 | 0 | if (ctxt->constructor == NULL) |
20892 | 0 | goto exit_failure; |
20893 | | /* Take ownership of the constructor to be able to free it. */ |
20894 | 0 | ctxt->ownsConstructor = 1; |
20895 | 0 | } |
20896 | 0 | ctxt->constructor->mainSchema = mainSchema; |
20897 | | /* |
20898 | | * Locate and add the schema document. |
20899 | | */ |
20900 | 0 | res = xmlSchemaAddSchemaDoc(ctxt, XML_SCHEMA_SCHEMA_MAIN, |
20901 | 0 | ctxt->URL, ctxt->doc, ctxt->buffer, ctxt->size, NULL, |
20902 | 0 | NULL, NULL, &bucket); |
20903 | 0 | if (res == -1) |
20904 | 0 | goto exit_failure; |
20905 | 0 | if (res != 0) |
20906 | 0 | goto exit; |
20907 | | |
20908 | 0 | if (bucket == NULL) { |
20909 | | /* TODO: Error code, actually we failed to *locate* the schema. */ |
20910 | 0 | if (ctxt->URL) |
20911 | 0 | xmlSchemaCustomErr(ACTXT_CAST ctxt, XML_SCHEMAP_FAILED_LOAD, |
20912 | 0 | NULL, NULL, |
20913 | 0 | "Failed to locate the main schema resource at '%s'", |
20914 | 0 | ctxt->URL, NULL); |
20915 | 0 | else |
20916 | 0 | xmlSchemaCustomErr(ACTXT_CAST ctxt, XML_SCHEMAP_FAILED_LOAD, |
20917 | 0 | NULL, NULL, |
20918 | 0 | "Failed to locate the main schema resource", |
20919 | 0 | NULL, NULL); |
20920 | 0 | goto exit; |
20921 | 0 | } |
20922 | | /* Then do the parsing for good. */ |
20923 | 0 | if (xmlSchemaParseNewDocWithContext(ctxt, mainSchema, bucket) == -1) |
20924 | 0 | goto exit_failure; |
20925 | 0 | if (ctxt->nberrors != 0) |
20926 | 0 | goto exit; |
20927 | | |
20928 | 0 | mainSchema->doc = bucket->doc; |
20929 | 0 | mainSchema->preserve = ctxt->preserve; |
20930 | |
|
20931 | 0 | ctxt->schema = mainSchema; |
20932 | |
|
20933 | 0 | if (xmlSchemaFixupComponents(ctxt, WXS_CONSTRUCTOR(ctxt)->mainBucket) == -1) |
20934 | 0 | goto exit_failure; |
20935 | | |
20936 | | /* |
20937 | | * TODO: This is not nice, since we cannot distinguish from the |
20938 | | * result if there was an internal error or not. |
20939 | | */ |
20940 | 0 | exit: |
20941 | 0 | if (ctxt->nberrors != 0) { |
20942 | 0 | if (mainSchema) { |
20943 | 0 | xmlSchemaFree(mainSchema); |
20944 | 0 | mainSchema = NULL; |
20945 | 0 | } |
20946 | 0 | if (ctxt->constructor) { |
20947 | 0 | xmlSchemaConstructionCtxtFree(ctxt->constructor); |
20948 | 0 | ctxt->constructor = NULL; |
20949 | 0 | ctxt->ownsConstructor = 0; |
20950 | 0 | } |
20951 | 0 | } |
20952 | 0 | ctxt->schema = NULL; |
20953 | 0 | return(mainSchema); |
20954 | 0 | exit_failure: |
20955 | | /* |
20956 | | * Quite verbose, but should catch internal errors, which were |
20957 | | * not communicated. |
20958 | | */ |
20959 | 0 | if (mainSchema) { |
20960 | 0 | xmlSchemaFree(mainSchema); |
20961 | 0 | mainSchema = NULL; |
20962 | 0 | } |
20963 | 0 | if (ctxt->constructor) { |
20964 | 0 | xmlSchemaConstructionCtxtFree(ctxt->constructor); |
20965 | 0 | ctxt->constructor = NULL; |
20966 | 0 | ctxt->ownsConstructor = 0; |
20967 | 0 | } |
20968 | 0 | PERROR_INT2("xmlSchemaParse", |
20969 | 0 | "An internal error occurred"); |
20970 | 0 | ctxt->schema = NULL; |
20971 | 0 | return(NULL); |
20972 | 0 | } |
20973 | | |
20974 | | /** |
20975 | | * Set the callback functions used to handle errors for a validation context |
20976 | | * |
20977 | | * @deprecated Use xmlSchemaSetParserStructuredErrors. |
20978 | | * |
20979 | | * @param ctxt a schema validation context |
20980 | | * @param err the error callback |
20981 | | * @param warn the warning callback |
20982 | | * @param ctx contextual data for the callbacks |
20983 | | */ |
20984 | | void |
20985 | | xmlSchemaSetParserErrors(xmlSchemaParserCtxt *ctxt, |
20986 | | xmlSchemaValidityErrorFunc err, |
20987 | | xmlSchemaValidityWarningFunc warn, void *ctx) |
20988 | 0 | { |
20989 | 0 | if (ctxt == NULL) |
20990 | 0 | return; |
20991 | 0 | ctxt->error = err; |
20992 | 0 | ctxt->warning = warn; |
20993 | 0 | ctxt->errCtxt = ctx; |
20994 | 0 | if (ctxt->vctxt != NULL) |
20995 | 0 | xmlSchemaSetValidErrors(ctxt->vctxt, err, warn, ctx); |
20996 | 0 | } |
20997 | | |
20998 | | /** |
20999 | | * Set the structured error callback |
21000 | | * |
21001 | | * @param ctxt a schema parser context |
21002 | | * @param serror the structured error function |
21003 | | * @param ctx the functions context |
21004 | | */ |
21005 | | void |
21006 | | xmlSchemaSetParserStructuredErrors(xmlSchemaParserCtxt *ctxt, |
21007 | | xmlStructuredErrorFunc serror, |
21008 | | void *ctx) |
21009 | 0 | { |
21010 | 0 | if (ctxt == NULL) |
21011 | 0 | return; |
21012 | 0 | ctxt->serror = serror; |
21013 | 0 | ctxt->errCtxt = ctx; |
21014 | 0 | if (ctxt->vctxt != NULL) |
21015 | 0 | xmlSchemaSetValidStructuredErrors(ctxt->vctxt, serror, ctx); |
21016 | 0 | } |
21017 | | |
21018 | | /** |
21019 | | * Get the callback information used to handle errors for a parser context |
21020 | | * |
21021 | | * @param ctxt a XMl-Schema parser context |
21022 | | * @param err the error callback result |
21023 | | * @param warn the warning callback result |
21024 | | * @param ctx contextual data for the callbacks result |
21025 | | * @returns -1 in case of failure, 0 otherwise |
21026 | | */ |
21027 | | int |
21028 | | xmlSchemaGetParserErrors(xmlSchemaParserCtxt *ctxt, |
21029 | | xmlSchemaValidityErrorFunc * err, |
21030 | | xmlSchemaValidityWarningFunc * warn, void **ctx) |
21031 | 0 | { |
21032 | 0 | if (ctxt == NULL) |
21033 | 0 | return(-1); |
21034 | 0 | if (err != NULL) |
21035 | 0 | *err = ctxt->error; |
21036 | 0 | if (warn != NULL) |
21037 | 0 | *warn = ctxt->warning; |
21038 | 0 | if (ctx != NULL) |
21039 | 0 | *ctx = ctxt->errCtxt; |
21040 | 0 | return(0); |
21041 | 0 | } |
21042 | | |
21043 | | /** |
21044 | | * Register a callback function that will be called to load documents |
21045 | | * or external entities. |
21046 | | * |
21047 | | * @since 2.14.0 |
21048 | | * @param ctxt schema parser |
21049 | | * @param loader resource loader |
21050 | | * @param data user data which will be passed to the loader |
21051 | | */ |
21052 | | void |
21053 | | xmlSchemaSetResourceLoader(xmlSchemaParserCtxt *ctxt, |
21054 | 0 | xmlResourceLoader loader, void *data) { |
21055 | 0 | if (ctxt == NULL) |
21056 | 0 | return; |
21057 | 0 | ctxt->resourceLoader = loader; |
21058 | 0 | ctxt->resourceCtxt = data; |
21059 | 0 | } |
21060 | | |
21061 | | /** |
21062 | | * Convert the xmlSchemaTypeType to a char string. |
21063 | | * |
21064 | | * @param type the facet type |
21065 | | * @returns the char string representation of the facet type if the |
21066 | | * type is a facet and an "Internal Error" string otherwise. |
21067 | | */ |
21068 | | static const xmlChar * |
21069 | | xmlSchemaFacetTypeToString(xmlSchemaTypeType type) |
21070 | 0 | { |
21071 | 0 | switch (type) { |
21072 | 0 | case XML_SCHEMA_FACET_PATTERN: |
21073 | 0 | return (BAD_CAST "pattern"); |
21074 | 0 | case XML_SCHEMA_FACET_MAXEXCLUSIVE: |
21075 | 0 | return (BAD_CAST "maxExclusive"); |
21076 | 0 | case XML_SCHEMA_FACET_MAXINCLUSIVE: |
21077 | 0 | return (BAD_CAST "maxInclusive"); |
21078 | 0 | case XML_SCHEMA_FACET_MINEXCLUSIVE: |
21079 | 0 | return (BAD_CAST "minExclusive"); |
21080 | 0 | case XML_SCHEMA_FACET_MININCLUSIVE: |
21081 | 0 | return (BAD_CAST "minInclusive"); |
21082 | 0 | case XML_SCHEMA_FACET_WHITESPACE: |
21083 | 0 | return (BAD_CAST "whiteSpace"); |
21084 | 0 | case XML_SCHEMA_FACET_ENUMERATION: |
21085 | 0 | return (BAD_CAST "enumeration"); |
21086 | 0 | case XML_SCHEMA_FACET_LENGTH: |
21087 | 0 | return (BAD_CAST "length"); |
21088 | 0 | case XML_SCHEMA_FACET_MAXLENGTH: |
21089 | 0 | return (BAD_CAST "maxLength"); |
21090 | 0 | case XML_SCHEMA_FACET_MINLENGTH: |
21091 | 0 | return (BAD_CAST "minLength"); |
21092 | 0 | case XML_SCHEMA_FACET_TOTALDIGITS: |
21093 | 0 | return (BAD_CAST "totalDigits"); |
21094 | 0 | case XML_SCHEMA_FACET_FRACTIONDIGITS: |
21095 | 0 | return (BAD_CAST "fractionDigits"); |
21096 | 0 | default: |
21097 | 0 | break; |
21098 | 0 | } |
21099 | 0 | return (BAD_CAST "Internal Error"); |
21100 | 0 | } |
21101 | | |
21102 | | static xmlSchemaWhitespaceValueType |
21103 | | xmlSchemaGetWhiteSpaceFacetValue(xmlSchemaTypePtr type) |
21104 | 0 | { |
21105 | | /* |
21106 | | * The normalization type can be changed only for types which are derived |
21107 | | * from xsd:string. |
21108 | | */ |
21109 | 0 | if (type->type == XML_SCHEMA_TYPE_BASIC) { |
21110 | | /* |
21111 | | * Note that we assume a whitespace of preserve for anySimpleType. |
21112 | | */ |
21113 | 0 | if ((type->builtInType == XML_SCHEMAS_STRING) || |
21114 | 0 | (type->builtInType == XML_SCHEMAS_ANYSIMPLETYPE)) |
21115 | 0 | return(XML_SCHEMA_WHITESPACE_PRESERVE); |
21116 | 0 | else if (type->builtInType == XML_SCHEMAS_NORMSTRING) |
21117 | 0 | return(XML_SCHEMA_WHITESPACE_REPLACE); |
21118 | 0 | else { |
21119 | | /* |
21120 | | * For all `atomic` datatypes other than string (and types `derived` |
21121 | | * by `restriction` from it) the value of whiteSpace is fixed to |
21122 | | * collapse |
21123 | | * Note that this includes built-in list datatypes. |
21124 | | */ |
21125 | 0 | return(XML_SCHEMA_WHITESPACE_COLLAPSE); |
21126 | 0 | } |
21127 | 0 | } else if (WXS_IS_LIST(type)) { |
21128 | | /* |
21129 | | * For list types the facet "whiteSpace" is fixed to "collapse". |
21130 | | */ |
21131 | 0 | return (XML_SCHEMA_WHITESPACE_COLLAPSE); |
21132 | 0 | } else if (WXS_IS_UNION(type)) { |
21133 | 0 | return (XML_SCHEMA_WHITESPACE_UNKNOWN); |
21134 | 0 | } else if (WXS_IS_ATOMIC(type)) { |
21135 | 0 | if (type->flags & XML_SCHEMAS_TYPE_WHITESPACE_PRESERVE) |
21136 | 0 | return (XML_SCHEMA_WHITESPACE_PRESERVE); |
21137 | 0 | else if (type->flags & XML_SCHEMAS_TYPE_WHITESPACE_REPLACE) |
21138 | 0 | return (XML_SCHEMA_WHITESPACE_REPLACE); |
21139 | 0 | else |
21140 | 0 | return (XML_SCHEMA_WHITESPACE_COLLAPSE); |
21141 | 0 | } |
21142 | 0 | return (-1); |
21143 | 0 | } |
21144 | | |
21145 | | /************************************************************************ |
21146 | | * * |
21147 | | * Simple type validation * |
21148 | | * * |
21149 | | ************************************************************************/ |
21150 | | |
21151 | | |
21152 | | /************************************************************************ |
21153 | | * * |
21154 | | * DOM Validation code * |
21155 | | * * |
21156 | | ************************************************************************/ |
21157 | | |
21158 | | /** |
21159 | | * Expands an existing schema by an additional schema. |
21160 | | * |
21161 | | * @param vctxt a schema validation context |
21162 | | * @param schema the existing schema |
21163 | | * @param node the node that fired the assembling |
21164 | | * @param nsName the namespace name of the new schema |
21165 | | * @param location the location of the schema |
21166 | | * @returns 0 if the new schema is correct, a positive error code |
21167 | | * number otherwise and -1 in case of an internal or API error. |
21168 | | */ |
21169 | | static int |
21170 | | xmlSchemaAssembleByLocation(xmlSchemaValidCtxtPtr vctxt, |
21171 | | xmlSchemaPtr schema, |
21172 | | xmlNodePtr node, |
21173 | | const xmlChar *nsName, |
21174 | | const xmlChar *location) |
21175 | 0 | { |
21176 | 0 | int ret = 0; |
21177 | 0 | xmlSchemaParserCtxtPtr pctxt; |
21178 | 0 | xmlSchemaBucketPtr bucket = NULL; |
21179 | |
|
21180 | 0 | if ((vctxt == NULL) || (schema == NULL)) |
21181 | 0 | return (-1); |
21182 | | |
21183 | 0 | if (vctxt->pctxt == NULL) { |
21184 | 0 | VERROR_INT("xmlSchemaAssembleByLocation", |
21185 | 0 | "no parser context available"); |
21186 | 0 | return(-1); |
21187 | 0 | } |
21188 | 0 | pctxt = vctxt->pctxt; |
21189 | 0 | if (pctxt->constructor == NULL) { |
21190 | 0 | PERROR_INT("xmlSchemaAssembleByLocation", |
21191 | 0 | "no constructor"); |
21192 | 0 | return(-1); |
21193 | 0 | } |
21194 | | /* |
21195 | | * Acquire the schema document. |
21196 | | */ |
21197 | 0 | location = xmlSchemaBuildAbsoluteURI(pctxt->dict, |
21198 | 0 | location, node); |
21199 | | /* |
21200 | | * Note that we pass XML_SCHEMA_SCHEMA_IMPORT here; |
21201 | | * the process will automatically change this to |
21202 | | * XML_SCHEMA_SCHEMA_MAIN if it is the first schema document. |
21203 | | */ |
21204 | 0 | ret = xmlSchemaAddSchemaDoc(pctxt, XML_SCHEMA_SCHEMA_IMPORT, |
21205 | 0 | location, NULL, NULL, 0, node, NULL, nsName, |
21206 | 0 | &bucket); |
21207 | 0 | if (ret != 0) |
21208 | 0 | return(ret); |
21209 | 0 | if (bucket == NULL) { |
21210 | | /* |
21211 | | * Generate a warning that the document could not be located. |
21212 | | */ |
21213 | 0 | xmlSchemaCustomWarning(ACTXT_CAST vctxt, XML_SCHEMAV_MISC, |
21214 | 0 | node, NULL, |
21215 | 0 | "The document at location '%s' could not be acquired", |
21216 | 0 | location, NULL, NULL); |
21217 | 0 | return(ret); |
21218 | 0 | } |
21219 | | /* |
21220 | | * The first located schema will be handled as if all other |
21221 | | * schemas imported by XSI were imported by this first schema. |
21222 | | */ |
21223 | 0 | if ((bucket != NULL) && |
21224 | 0 | (WXS_CONSTRUCTOR(pctxt)->bucket == NULL)) |
21225 | 0 | WXS_CONSTRUCTOR(pctxt)->bucket = bucket; |
21226 | | /* |
21227 | | * TODO: Is this handled like an import? I.e. is it not an error |
21228 | | * if the schema cannot be located? |
21229 | | */ |
21230 | 0 | if ((bucket == NULL) || (! CAN_PARSE_SCHEMA(bucket))) |
21231 | 0 | return(0); |
21232 | | /* |
21233 | | * We will reuse the parser context for every schema imported |
21234 | | * directly via XSI. So reset the context. |
21235 | | */ |
21236 | 0 | pctxt->nberrors = 0; |
21237 | 0 | pctxt->err = 0; |
21238 | 0 | pctxt->doc = bucket->doc; |
21239 | |
|
21240 | 0 | ret = xmlSchemaParseNewDocWithContext(pctxt, schema, bucket); |
21241 | 0 | if (ret == -1) { |
21242 | 0 | pctxt->doc = NULL; |
21243 | 0 | goto exit_failure; |
21244 | 0 | } |
21245 | | /* Paranoid error channelling. */ |
21246 | 0 | if ((ret == 0) && (pctxt->nberrors != 0)) |
21247 | 0 | ret = pctxt->err; |
21248 | 0 | if (pctxt->nberrors == 0) { |
21249 | | /* |
21250 | | * Only bother to fixup pending components, if there was |
21251 | | * no error yet. |
21252 | | * For every XSI acquired schema (and its sub-schemata) we will |
21253 | | * fixup the components. |
21254 | | */ |
21255 | 0 | xmlSchemaFixupComponents(pctxt, bucket); |
21256 | 0 | ret = pctxt->err; |
21257 | | /* |
21258 | | * Not nice, but we need somehow to channel the schema parser |
21259 | | * error to the validation context. |
21260 | | */ |
21261 | 0 | if ((ret != 0) && (vctxt->err == 0)) |
21262 | 0 | vctxt->err = ret; |
21263 | 0 | vctxt->nberrors += pctxt->nberrors; |
21264 | 0 | } else { |
21265 | | /* Add to validation error sum. */ |
21266 | 0 | vctxt->nberrors += pctxt->nberrors; |
21267 | 0 | } |
21268 | 0 | pctxt->doc = NULL; |
21269 | 0 | return(ret); |
21270 | 0 | exit_failure: |
21271 | 0 | pctxt->doc = NULL; |
21272 | 0 | return (-1); |
21273 | 0 | } |
21274 | | |
21275 | | static xmlSchemaAttrInfoPtr |
21276 | | xmlSchemaGetMetaAttrInfo(xmlSchemaValidCtxtPtr vctxt, |
21277 | | int metaType) |
21278 | 0 | { |
21279 | 0 | if (vctxt->nbAttrInfos == 0) |
21280 | 0 | return (NULL); |
21281 | 0 | { |
21282 | 0 | int i; |
21283 | 0 | xmlSchemaAttrInfoPtr iattr; |
21284 | |
|
21285 | 0 | for (i = 0; i < vctxt->nbAttrInfos; i++) { |
21286 | 0 | iattr = vctxt->attrInfos[i]; |
21287 | 0 | if (iattr->metaType == metaType) |
21288 | 0 | return (iattr); |
21289 | 0 | } |
21290 | |
|
21291 | 0 | } |
21292 | 0 | return (NULL); |
21293 | 0 | } |
21294 | | |
21295 | | /** |
21296 | | * Expands an existing schema by an additional schema using |
21297 | | * the xsi:schemaLocation or xsi:noNamespaceSchemaLocation attribute |
21298 | | * of an instance. If xsi:noNamespaceSchemaLocation is used, `noNamespace` |
21299 | | * must be set to 1. |
21300 | | * |
21301 | | * @param vctxt a schema validation context |
21302 | | * @returns 0 if the new schema is correct, a positive error code |
21303 | | * number otherwise and -1 in case of an internal or API error. |
21304 | | */ |
21305 | | static int |
21306 | | xmlSchemaAssembleByXSI(xmlSchemaValidCtxtPtr vctxt) |
21307 | 0 | { |
21308 | 0 | const xmlChar *cur, *end; |
21309 | 0 | const xmlChar *nsname = NULL, *location; |
21310 | 0 | int ret = 0; |
21311 | 0 | xmlSchemaAttrInfoPtr iattr; |
21312 | | |
21313 | | /* |
21314 | | * Parse the value; we will assume an even number of values |
21315 | | * to be given (this is how Xerces and XSV work). |
21316 | | * |
21317 | | * URGENT TODO: !! This needs to work for both |
21318 | | * @noNamespaceSchemaLocation AND @schemaLocation on the same |
21319 | | * element !! |
21320 | | */ |
21321 | 0 | iattr = xmlSchemaGetMetaAttrInfo(vctxt, |
21322 | 0 | XML_SCHEMA_ATTR_INFO_META_XSI_SCHEMA_LOC); |
21323 | 0 | if (iattr == NULL) |
21324 | 0 | iattr = xmlSchemaGetMetaAttrInfo(vctxt, |
21325 | 0 | XML_SCHEMA_ATTR_INFO_META_XSI_NO_NS_SCHEMA_LOC); |
21326 | 0 | if (iattr == NULL) |
21327 | 0 | return (0); |
21328 | 0 | cur = iattr->value; |
21329 | 0 | do { |
21330 | | /* |
21331 | | * TODO: Move the string parsing mechanism away from here. |
21332 | | */ |
21333 | 0 | if (iattr->metaType == XML_SCHEMA_ATTR_INFO_META_XSI_SCHEMA_LOC) { |
21334 | | /* |
21335 | | * Get the namespace name. |
21336 | | */ |
21337 | 0 | while (IS_BLANK_CH(*cur)) |
21338 | 0 | cur++; |
21339 | 0 | end = cur; |
21340 | 0 | while ((*end != 0) && (!(IS_BLANK_CH(*end)))) |
21341 | 0 | end++; |
21342 | 0 | if (end == cur) |
21343 | 0 | break; |
21344 | | /* TODO: Don't use the schema's dict. */ |
21345 | 0 | nsname = xmlDictLookup(vctxt->schema->dict, cur, end - cur); |
21346 | 0 | cur = end; |
21347 | 0 | } |
21348 | | /* |
21349 | | * Get the URI. |
21350 | | */ |
21351 | 0 | while (IS_BLANK_CH(*cur)) |
21352 | 0 | cur++; |
21353 | 0 | end = cur; |
21354 | 0 | while ((*end != 0) && (!(IS_BLANK_CH(*end)))) |
21355 | 0 | end++; |
21356 | 0 | if (end == cur) { |
21357 | 0 | if (iattr->metaType == |
21358 | 0 | XML_SCHEMA_ATTR_INFO_META_XSI_SCHEMA_LOC) |
21359 | 0 | { |
21360 | | /* |
21361 | | * If using @schemaLocation then tuples are expected. |
21362 | | * I.e. the namespace name *and* the document's URI. |
21363 | | */ |
21364 | 0 | xmlSchemaCustomWarning(ACTXT_CAST vctxt, XML_SCHEMAV_MISC, |
21365 | 0 | iattr->node, NULL, |
21366 | 0 | "The value must consist of tuples: the target namespace " |
21367 | 0 | "name and the document's URI", NULL, NULL, NULL); |
21368 | 0 | } |
21369 | 0 | break; |
21370 | 0 | } |
21371 | | /* TODO: Don't use the schema's dict. */ |
21372 | 0 | location = xmlDictLookup(vctxt->schema->dict, cur, end - cur); |
21373 | 0 | cur = end; |
21374 | 0 | ret = xmlSchemaAssembleByLocation(vctxt, vctxt->schema, |
21375 | 0 | iattr->node, nsname, location); |
21376 | 0 | if (ret == -1) { |
21377 | 0 | VERROR_INT("xmlSchemaAssembleByXSI", |
21378 | 0 | "assembling schemata"); |
21379 | 0 | return (-1); |
21380 | 0 | } |
21381 | 0 | } while (*cur != 0); |
21382 | 0 | return (ret); |
21383 | 0 | } |
21384 | | |
21385 | | static const xmlChar * |
21386 | | xmlSchemaLookupNamespace(xmlSchemaValidCtxtPtr vctxt, |
21387 | | const xmlChar *prefix) |
21388 | 0 | { |
21389 | 0 | if (vctxt->sax != NULL) { |
21390 | 0 | int i, j; |
21391 | 0 | xmlSchemaNodeInfoPtr inode; |
21392 | |
|
21393 | 0 | for (i = vctxt->depth; i >= 0; i--) { |
21394 | 0 | if (vctxt->elemInfos[i]->nbNsBindings != 0) { |
21395 | 0 | inode = vctxt->elemInfos[i]; |
21396 | 0 | for (j = 0; j < inode->nbNsBindings * 2; j += 2) { |
21397 | 0 | if (((prefix == NULL) && |
21398 | 0 | (inode->nsBindings[j] == NULL)) || |
21399 | 0 | ((prefix != NULL) && xmlStrEqual(prefix, |
21400 | 0 | inode->nsBindings[j]))) { |
21401 | | |
21402 | | /* |
21403 | | * Note that the namespace bindings are already |
21404 | | * in a string dict. |
21405 | | */ |
21406 | 0 | return (inode->nsBindings[j+1]); |
21407 | 0 | } |
21408 | 0 | } |
21409 | 0 | } |
21410 | 0 | } |
21411 | 0 | return (NULL); |
21412 | 0 | #ifdef LIBXML_READER_ENABLED |
21413 | 0 | } else if (vctxt->reader != NULL) { |
21414 | 0 | xmlChar *nsName; |
21415 | |
|
21416 | 0 | nsName = xmlTextReaderLookupNamespace(vctxt->reader, prefix); |
21417 | 0 | if (nsName != NULL) { |
21418 | 0 | const xmlChar *ret; |
21419 | |
|
21420 | 0 | ret = xmlDictLookup(vctxt->dict, nsName, -1); |
21421 | 0 | xmlFree(nsName); |
21422 | 0 | return (ret); |
21423 | 0 | } else |
21424 | 0 | return (NULL); |
21425 | 0 | #endif |
21426 | 0 | } else { |
21427 | 0 | xmlNsPtr ns; |
21428 | |
|
21429 | 0 | if ((vctxt->inode->node == NULL) || |
21430 | 0 | (vctxt->inode->node->doc == NULL)) { |
21431 | 0 | VERROR_INT("xmlSchemaLookupNamespace", |
21432 | 0 | "no node or node's doc available"); |
21433 | 0 | return (NULL); |
21434 | 0 | } |
21435 | 0 | ns = xmlSearchNs(vctxt->inode->node->doc, |
21436 | 0 | vctxt->inode->node, prefix); |
21437 | 0 | if (ns != NULL) |
21438 | 0 | return (ns->href); |
21439 | 0 | return (NULL); |
21440 | 0 | } |
21441 | 0 | } |
21442 | | |
21443 | | /* |
21444 | | * This one works on the schema of the validation context. |
21445 | | */ |
21446 | | static int |
21447 | | xmlSchemaValidateNotation(xmlSchemaValidCtxtPtr vctxt, |
21448 | | xmlSchemaPtr schema, |
21449 | | xmlNodePtr node, |
21450 | | const xmlChar *value, |
21451 | | xmlSchemaValPtr *val, |
21452 | | int valNeeded) |
21453 | 0 | { |
21454 | 0 | int ret; |
21455 | |
|
21456 | 0 | if (vctxt && (vctxt->schema == NULL)) { |
21457 | 0 | VERROR_INT("xmlSchemaValidateNotation", |
21458 | 0 | "a schema is needed on the validation context"); |
21459 | 0 | return (-1); |
21460 | 0 | } |
21461 | 0 | ret = xmlValidateQName(value, 1); |
21462 | 0 | if (ret != 0) |
21463 | 0 | return (ret); |
21464 | 0 | { |
21465 | 0 | xmlChar *localName = NULL; |
21466 | 0 | xmlChar *prefix = NULL; |
21467 | |
|
21468 | 0 | localName = xmlSplitQName2(value, &prefix); |
21469 | 0 | if (prefix != NULL) { |
21470 | 0 | const xmlChar *nsName = NULL; |
21471 | |
|
21472 | 0 | if (vctxt != NULL) |
21473 | 0 | nsName = xmlSchemaLookupNamespace(vctxt, BAD_CAST prefix); |
21474 | 0 | else if (node != NULL) { |
21475 | 0 | xmlNsPtr ns = xmlSearchNs(node->doc, node, prefix); |
21476 | 0 | if (ns != NULL) |
21477 | 0 | nsName = ns->href; |
21478 | 0 | } else { |
21479 | 0 | xmlFree(prefix); |
21480 | 0 | xmlFree(localName); |
21481 | 0 | return (1); |
21482 | 0 | } |
21483 | 0 | if (nsName == NULL) { |
21484 | 0 | xmlFree(prefix); |
21485 | 0 | xmlFree(localName); |
21486 | 0 | return (1); |
21487 | 0 | } |
21488 | 0 | if (xmlSchemaGetNotation(schema, localName, nsName) != NULL) { |
21489 | 0 | if ((valNeeded) && (val != NULL)) { |
21490 | 0 | (*val) = xmlSchemaNewNOTATIONValue(xmlStrdup(localName), |
21491 | 0 | xmlStrdup(nsName)); |
21492 | 0 | if (*val == NULL) |
21493 | 0 | ret = -1; |
21494 | 0 | } |
21495 | 0 | } else |
21496 | 0 | ret = 1; |
21497 | 0 | xmlFree(prefix); |
21498 | 0 | xmlFree(localName); |
21499 | 0 | } else { |
21500 | 0 | if (xmlSchemaGetNotation(schema, value, NULL) != NULL) { |
21501 | 0 | if (valNeeded && (val != NULL)) { |
21502 | 0 | (*val) = xmlSchemaNewNOTATIONValue( |
21503 | 0 | BAD_CAST xmlStrdup(value), NULL); |
21504 | 0 | if (*val == NULL) |
21505 | 0 | ret = -1; |
21506 | 0 | } |
21507 | 0 | } else |
21508 | 0 | return (1); |
21509 | 0 | } |
21510 | 0 | } |
21511 | 0 | return (ret); |
21512 | 0 | } |
21513 | | |
21514 | | static int |
21515 | | xmlSchemaVAddNodeQName(xmlSchemaValidCtxtPtr vctxt, |
21516 | | const xmlChar* lname, |
21517 | | const xmlChar* nsname) |
21518 | 0 | { |
21519 | 0 | int i; |
21520 | |
|
21521 | 0 | lname = xmlDictLookup(vctxt->dict, lname, -1); |
21522 | 0 | if (lname == NULL) |
21523 | 0 | return(-1); |
21524 | 0 | if (nsname != NULL) { |
21525 | 0 | nsname = xmlDictLookup(vctxt->dict, nsname, -1); |
21526 | 0 | if (nsname == NULL) |
21527 | 0 | return(-1); |
21528 | 0 | } |
21529 | 0 | for (i = 0; i < vctxt->nodeQNames->nbItems; i += 2) { |
21530 | 0 | if ((vctxt->nodeQNames->items [i] == lname) && |
21531 | 0 | (vctxt->nodeQNames->items[i +1] == nsname)) |
21532 | | /* Already there */ |
21533 | 0 | return(i); |
21534 | 0 | } |
21535 | | /* Add new entry. */ |
21536 | 0 | i = vctxt->nodeQNames->nbItems; |
21537 | 0 | if (xmlSchemaItemListAdd(vctxt->nodeQNames, (void *) lname) < 0) { |
21538 | 0 | xmlSchemaVErrMemory(vctxt); |
21539 | 0 | return(-1); |
21540 | 0 | } |
21541 | 0 | if (xmlSchemaItemListAdd(vctxt->nodeQNames, (void *) nsname) < 0) { |
21542 | 0 | vctxt->nodeQNames->nbItems--; |
21543 | 0 | xmlSchemaVErrMemory(vctxt); |
21544 | 0 | return(-1); |
21545 | 0 | } |
21546 | 0 | return(i); |
21547 | 0 | } |
21548 | | |
21549 | | /************************************************************************ |
21550 | | * * |
21551 | | * Validation of identity-constraints (IDC) * |
21552 | | * * |
21553 | | ************************************************************************/ |
21554 | | |
21555 | | /** |
21556 | | * Creates an augmented IDC definition item. |
21557 | | * |
21558 | | * @param payload the IDC definition |
21559 | | * @param data validation context |
21560 | | * @param name unused |
21561 | | * @returns the item, or NULL on internal errors. |
21562 | | */ |
21563 | | static void |
21564 | | xmlSchemaAugmentIDC(void *payload, void *data, |
21565 | | const xmlChar *name ATTRIBUTE_UNUSED) |
21566 | 0 | { |
21567 | 0 | xmlSchemaIDCPtr idcDef = (xmlSchemaIDCPtr) payload; |
21568 | 0 | xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) data; |
21569 | 0 | xmlSchemaIDCAugPtr aidc; |
21570 | |
|
21571 | 0 | aidc = (xmlSchemaIDCAugPtr) xmlMalloc(sizeof(xmlSchemaIDCAug)); |
21572 | 0 | if (aidc == NULL) { |
21573 | 0 | xmlSchemaVErrMemory(vctxt); |
21574 | 0 | return; |
21575 | 0 | } |
21576 | 0 | aidc->keyrefDepth = -1; |
21577 | 0 | aidc->def = idcDef; |
21578 | 0 | aidc->next = NULL; |
21579 | 0 | if (vctxt->aidcs == NULL) |
21580 | 0 | vctxt->aidcs = aidc; |
21581 | 0 | else { |
21582 | 0 | aidc->next = vctxt->aidcs; |
21583 | 0 | vctxt->aidcs = aidc; |
21584 | 0 | } |
21585 | | /* |
21586 | | * Save if we have keyrefs at all. |
21587 | | */ |
21588 | 0 | if ((vctxt->hasKeyrefs == 0) && |
21589 | 0 | (idcDef->type == XML_SCHEMA_TYPE_IDC_KEYREF)) |
21590 | 0 | vctxt->hasKeyrefs = 1; |
21591 | 0 | } |
21592 | | |
21593 | | /** |
21594 | | * Creates an augmented IDC definition for the imported schema. |
21595 | | * |
21596 | | * @param payload the imported schema |
21597 | | * @param data validation context |
21598 | | * @param name unused |
21599 | | */ |
21600 | | static void |
21601 | | xmlSchemaAugmentImportedIDC(void *payload, void *data, |
21602 | 0 | const xmlChar *name ATTRIBUTE_UNUSED) { |
21603 | 0 | xmlSchemaImportPtr imported = (xmlSchemaImportPtr) payload; |
21604 | 0 | xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) data; |
21605 | 0 | if (imported->schema->idcDef != NULL) { |
21606 | 0 | xmlHashScan(imported->schema->idcDef, xmlSchemaAugmentIDC, vctxt); |
21607 | 0 | } |
21608 | 0 | } |
21609 | | |
21610 | | /** |
21611 | | * Creates a new IDC binding. |
21612 | | * |
21613 | | * @param idcDef the IDC definition of this binding |
21614 | | * @returns the new IDC binding, NULL on internal errors. |
21615 | | */ |
21616 | | static xmlSchemaPSVIIDCBindingPtr |
21617 | | xmlSchemaIDCNewBinding(xmlSchemaIDCPtr idcDef) |
21618 | 0 | { |
21619 | 0 | xmlSchemaPSVIIDCBindingPtr ret; |
21620 | |
|
21621 | 0 | ret = (xmlSchemaPSVIIDCBindingPtr) xmlMalloc( |
21622 | 0 | sizeof(xmlSchemaPSVIIDCBinding)); |
21623 | 0 | if (ret == NULL) { |
21624 | 0 | xmlSchemaVErrMemory(NULL); |
21625 | 0 | return (NULL); |
21626 | 0 | } |
21627 | 0 | memset(ret, 0, sizeof(xmlSchemaPSVIIDCBinding)); |
21628 | 0 | ret->definition = idcDef; |
21629 | 0 | return (ret); |
21630 | 0 | } |
21631 | | |
21632 | | /** |
21633 | | * The validation context is used to store IDC node table items. |
21634 | | * They are stored to avoid copying them if IDC node-tables are merged |
21635 | | * with corresponding parent IDC node-tables (bubbling). |
21636 | | * |
21637 | | * @param vctxt the WXS validation context |
21638 | | * @param item the IDC node table item |
21639 | | * @returns 0 if succeeded, -1 on internal errors. |
21640 | | */ |
21641 | | static int |
21642 | | xmlSchemaIDCStoreNodeTableItem(xmlSchemaValidCtxtPtr vctxt, |
21643 | | xmlSchemaPSVIIDCNodePtr item) |
21644 | 0 | { |
21645 | | /* |
21646 | | * Add to global list. |
21647 | | */ |
21648 | 0 | if (vctxt->sizeIdcNodes <= vctxt->nbIdcNodes) { |
21649 | 0 | xmlSchemaPSVIIDCNodePtr *tmp; |
21650 | 0 | int newSize; |
21651 | |
|
21652 | 0 | newSize = xmlGrowCapacity(vctxt->sizeIdcNodes, sizeof(tmp[0]), |
21653 | 0 | 20, XML_MAX_ITEMS); |
21654 | 0 | if (newSize < 0) { |
21655 | 0 | xmlSchemaVErrMemory(vctxt); |
21656 | 0 | return (-1); |
21657 | 0 | } |
21658 | 0 | tmp = xmlRealloc(vctxt->idcNodes, newSize * sizeof(tmp[0])); |
21659 | 0 | if (tmp == NULL) { |
21660 | 0 | xmlSchemaVErrMemory(vctxt); |
21661 | 0 | return (-1); |
21662 | 0 | } |
21663 | | |
21664 | 0 | vctxt->idcNodes = tmp; |
21665 | 0 | vctxt->sizeIdcNodes = newSize; |
21666 | 0 | } |
21667 | | |
21668 | 0 | vctxt->idcNodes[vctxt->nbIdcNodes++] = item; |
21669 | 0 | return (0); |
21670 | 0 | } |
21671 | | |
21672 | | /** |
21673 | | * The validation context is used to store an IDC key. |
21674 | | * |
21675 | | * @param vctxt the WXS validation context |
21676 | | * @param key the IDC key |
21677 | | * @returns 0 if succeeded, -1 on internal errors. |
21678 | | */ |
21679 | | static int |
21680 | | xmlSchemaIDCStoreKey(xmlSchemaValidCtxtPtr vctxt, |
21681 | | xmlSchemaPSVIIDCKeyPtr key) |
21682 | 0 | { |
21683 | | /* |
21684 | | * Add to global list. |
21685 | | */ |
21686 | 0 | if (vctxt->sizeIdcKeys <= vctxt->nbIdcKeys) { |
21687 | 0 | xmlSchemaPSVIIDCKeyPtr *tmp; |
21688 | 0 | int newSize; |
21689 | |
|
21690 | 0 | newSize = xmlGrowCapacity(vctxt->sizeIdcKeys, sizeof(tmp[0]), |
21691 | 0 | 20, XML_MAX_ITEMS); |
21692 | 0 | if (newSize < 0) { |
21693 | 0 | xmlSchemaVErrMemory(vctxt); |
21694 | 0 | return (-1); |
21695 | 0 | } |
21696 | 0 | tmp = xmlRealloc(vctxt->idcKeys, newSize * sizeof(tmp[0])); |
21697 | 0 | if (tmp == NULL) { |
21698 | 0 | xmlSchemaVErrMemory(vctxt); |
21699 | 0 | return (-1); |
21700 | 0 | } |
21701 | | |
21702 | 0 | vctxt->idcKeys = tmp; |
21703 | 0 | vctxt->sizeIdcKeys = newSize; |
21704 | 0 | } |
21705 | | |
21706 | 0 | vctxt->idcKeys[vctxt->nbIdcKeys++] = key; |
21707 | 0 | return (0); |
21708 | 0 | } |
21709 | | |
21710 | | /** |
21711 | | * Appends the IDC node-table item to the binding. |
21712 | | * |
21713 | | * @param bind the IDC binding |
21714 | | * @param ntItem the node-table item |
21715 | | * @returns 0 on success and -1 on internal errors. |
21716 | | */ |
21717 | | static int |
21718 | | xmlSchemaIDCAppendNodeTableItem(xmlSchemaPSVIIDCBindingPtr bind, |
21719 | | xmlSchemaPSVIIDCNodePtr ntItem) |
21720 | 0 | { |
21721 | 0 | if (bind->sizeNodes <= bind->nbNodes) { |
21722 | 0 | xmlSchemaPSVIIDCNodePtr *tmp; |
21723 | 0 | int newSize; |
21724 | |
|
21725 | 0 | newSize = xmlGrowCapacity(bind->sizeNodes, sizeof(tmp[0]), |
21726 | 0 | 10, XML_MAX_ITEMS); |
21727 | 0 | if (newSize < 0) { |
21728 | 0 | xmlSchemaVErrMemory(NULL); |
21729 | 0 | return(-1); |
21730 | 0 | } |
21731 | 0 | tmp = xmlRealloc(bind->nodeTable, newSize * sizeof(tmp[0])); |
21732 | 0 | if (tmp == NULL) { |
21733 | 0 | xmlSchemaVErrMemory(NULL); |
21734 | 0 | return(-1); |
21735 | 0 | } |
21736 | | |
21737 | 0 | bind->nodeTable = tmp; |
21738 | 0 | bind->sizeNodes = newSize; |
21739 | 0 | } |
21740 | | |
21741 | 0 | bind->nodeTable[bind->nbNodes++] = ntItem; |
21742 | 0 | return(0); |
21743 | 0 | } |
21744 | | |
21745 | | /** |
21746 | | * Looks up an PSVI IDC binding, for the IDC definition and |
21747 | | * of the given matcher. If none found, a new one is created |
21748 | | * and added to the IDC table. |
21749 | | * |
21750 | | * @param vctxt the WXS validation context |
21751 | | * @param matcher the IDC matcher |
21752 | | * @returns an IDC binding or NULL on internal errors. |
21753 | | */ |
21754 | | static xmlSchemaPSVIIDCBindingPtr |
21755 | | xmlSchemaIDCAcquireBinding(xmlSchemaValidCtxtPtr vctxt, |
21756 | | xmlSchemaIDCMatcherPtr matcher) |
21757 | 0 | { |
21758 | 0 | xmlSchemaNodeInfoPtr ielem; |
21759 | |
|
21760 | 0 | ielem = vctxt->elemInfos[matcher->depth]; |
21761 | |
|
21762 | 0 | if (ielem->idcTable == NULL) { |
21763 | 0 | ielem->idcTable = xmlSchemaIDCNewBinding(matcher->aidc->def); |
21764 | 0 | if (ielem->idcTable == NULL) |
21765 | 0 | return (NULL); |
21766 | 0 | return(ielem->idcTable); |
21767 | 0 | } else { |
21768 | 0 | xmlSchemaPSVIIDCBindingPtr bind = NULL; |
21769 | |
|
21770 | 0 | bind = ielem->idcTable; |
21771 | 0 | do { |
21772 | 0 | if (bind->definition == matcher->aidc->def) |
21773 | 0 | return(bind); |
21774 | 0 | if (bind->next == NULL) { |
21775 | 0 | bind->next = xmlSchemaIDCNewBinding(matcher->aidc->def); |
21776 | 0 | if (bind->next == NULL) |
21777 | 0 | return (NULL); |
21778 | 0 | return(bind->next); |
21779 | 0 | } |
21780 | 0 | bind = bind->next; |
21781 | 0 | } while (bind != NULL); |
21782 | 0 | } |
21783 | 0 | return (NULL); |
21784 | 0 | } |
21785 | | |
21786 | | static xmlSchemaItemListPtr |
21787 | | xmlSchemaIDCAcquireTargetList(xmlSchemaValidCtxtPtr vctxt, |
21788 | | xmlSchemaIDCMatcherPtr matcher) |
21789 | 0 | { |
21790 | 0 | if (matcher->targets == NULL) { |
21791 | 0 | matcher->targets = xmlSchemaItemListCreate(); |
21792 | 0 | if (matcher->targets == NULL) |
21793 | 0 | xmlSchemaVErrMemory(vctxt); |
21794 | 0 | } |
21795 | 0 | return(matcher->targets); |
21796 | 0 | } |
21797 | | |
21798 | | /** |
21799 | | * Frees an IDC key together with its compiled value. |
21800 | | * |
21801 | | * @param key the IDC key |
21802 | | */ |
21803 | | static void |
21804 | | xmlSchemaIDCFreeKey(xmlSchemaPSVIIDCKeyPtr key) |
21805 | 0 | { |
21806 | 0 | if (key->val != NULL) |
21807 | 0 | xmlSchemaFreeValue(key->val); |
21808 | 0 | xmlFree(key); |
21809 | 0 | } |
21810 | | |
21811 | | /** |
21812 | | * Frees an IDC binding. Note that the node table-items |
21813 | | * are not freed. |
21814 | | */ |
21815 | | static void |
21816 | | xmlSchemaIDCFreeBinding(xmlSchemaPSVIIDCBindingPtr bind) |
21817 | 0 | { |
21818 | 0 | if (bind->nodeTable != NULL) |
21819 | 0 | xmlFree(bind->nodeTable); |
21820 | 0 | if (bind->dupls != NULL) |
21821 | 0 | xmlSchemaItemListFree(bind->dupls); |
21822 | 0 | xmlFree(bind); |
21823 | 0 | } |
21824 | | |
21825 | | /** |
21826 | | * Frees an IDC table, i.e. all the IDC bindings in the list. |
21827 | | * |
21828 | | * @param bind the first IDC binding in the list |
21829 | | */ |
21830 | | static void |
21831 | | xmlSchemaIDCFreeIDCTable(xmlSchemaPSVIIDCBindingPtr bind) |
21832 | 0 | { |
21833 | 0 | xmlSchemaPSVIIDCBindingPtr prev; |
21834 | |
|
21835 | 0 | while (bind != NULL) { |
21836 | 0 | prev = bind; |
21837 | 0 | bind = bind->next; |
21838 | 0 | xmlSchemaIDCFreeBinding(prev); |
21839 | 0 | } |
21840 | 0 | } |
21841 | | |
21842 | | static void |
21843 | | xmlFreeIDCHashEntry (void *payload, const xmlChar *name ATTRIBUTE_UNUSED) |
21844 | 0 | { |
21845 | 0 | xmlIDCHashEntryPtr e = payload, n; |
21846 | 0 | while (e) { |
21847 | 0 | n = e->next; |
21848 | 0 | xmlFree(e); |
21849 | 0 | e = n; |
21850 | 0 | } |
21851 | 0 | } |
21852 | | |
21853 | | /** |
21854 | | * Frees a list of IDC matchers. |
21855 | | * |
21856 | | * @param matcher the first IDC matcher in the list |
21857 | | */ |
21858 | | static void |
21859 | | xmlSchemaIDCFreeMatcherList(xmlSchemaIDCMatcherPtr matcher) |
21860 | 0 | { |
21861 | 0 | xmlSchemaIDCMatcherPtr next; |
21862 | |
|
21863 | 0 | while (matcher != NULL) { |
21864 | 0 | next = matcher->next; |
21865 | 0 | if (matcher->keySeqs != NULL) { |
21866 | 0 | int i; |
21867 | 0 | for (i = 0; i < matcher->sizeKeySeqs; i++) |
21868 | 0 | if (matcher->keySeqs[i] != NULL) |
21869 | 0 | xmlFree(matcher->keySeqs[i]); |
21870 | 0 | xmlFree(matcher->keySeqs); |
21871 | 0 | } |
21872 | 0 | if (matcher->targets != NULL) { |
21873 | 0 | if (matcher->idcType == XML_SCHEMA_TYPE_IDC_KEYREF) { |
21874 | 0 | int i; |
21875 | 0 | xmlSchemaPSVIIDCNodePtr idcNode; |
21876 | | /* |
21877 | | * Node-table items for keyrefs are not stored globally |
21878 | | * to the validation context, since they are not bubbled. |
21879 | | * We need to free them here. |
21880 | | */ |
21881 | 0 | for (i = 0; i < matcher->targets->nbItems; i++) { |
21882 | 0 | idcNode = |
21883 | 0 | (xmlSchemaPSVIIDCNodePtr) matcher->targets->items[i]; |
21884 | 0 | xmlFree(idcNode->keys); |
21885 | 0 | xmlFree(idcNode); |
21886 | 0 | } |
21887 | 0 | } |
21888 | 0 | xmlSchemaItemListFree(matcher->targets); |
21889 | 0 | } |
21890 | 0 | if (matcher->htab != NULL) |
21891 | 0 | xmlHashFree(matcher->htab, xmlFreeIDCHashEntry); |
21892 | 0 | xmlFree(matcher); |
21893 | 0 | matcher = next; |
21894 | 0 | } |
21895 | 0 | } |
21896 | | |
21897 | | /** |
21898 | | * Caches a list of IDC matchers for reuse. |
21899 | | * |
21900 | | * @param vctxt the WXS validation context |
21901 | | * @param matcher the first IDC matcher in the list |
21902 | | */ |
21903 | | static void |
21904 | | xmlSchemaIDCReleaseMatcherList(xmlSchemaValidCtxtPtr vctxt, |
21905 | | xmlSchemaIDCMatcherPtr matcher) |
21906 | 0 | { |
21907 | 0 | xmlSchemaIDCMatcherPtr next; |
21908 | |
|
21909 | 0 | while (matcher != NULL) { |
21910 | 0 | next = matcher->next; |
21911 | 0 | if (matcher->keySeqs != NULL) { |
21912 | 0 | int i; |
21913 | | /* |
21914 | | * Don't free the array, but only the content. |
21915 | | */ |
21916 | 0 | for (i = 0; i < matcher->sizeKeySeqs; i++) |
21917 | 0 | if (matcher->keySeqs[i] != NULL) { |
21918 | 0 | xmlFree(matcher->keySeqs[i]); |
21919 | 0 | matcher->keySeqs[i] = NULL; |
21920 | 0 | } |
21921 | 0 | } |
21922 | 0 | if (matcher->targets) { |
21923 | 0 | if (matcher->idcType == XML_SCHEMA_TYPE_IDC_KEYREF) { |
21924 | 0 | int i; |
21925 | 0 | xmlSchemaPSVIIDCNodePtr idcNode; |
21926 | | /* |
21927 | | * Node-table items for keyrefs are not stored globally |
21928 | | * to the validation context, since they are not bubbled. |
21929 | | * We need to free them here. |
21930 | | */ |
21931 | 0 | for (i = 0; i < matcher->targets->nbItems; i++) { |
21932 | 0 | idcNode = |
21933 | 0 | (xmlSchemaPSVIIDCNodePtr) matcher->targets->items[i]; |
21934 | 0 | xmlFree(idcNode->keys); |
21935 | 0 | xmlFree(idcNode); |
21936 | 0 | } |
21937 | 0 | } |
21938 | 0 | xmlSchemaItemListFree(matcher->targets); |
21939 | 0 | matcher->targets = NULL; |
21940 | 0 | } |
21941 | 0 | if (matcher->htab != NULL) { |
21942 | 0 | xmlHashFree(matcher->htab, xmlFreeIDCHashEntry); |
21943 | 0 | matcher->htab = NULL; |
21944 | 0 | } |
21945 | 0 | matcher->next = NULL; |
21946 | | /* |
21947 | | * Cache the matcher. |
21948 | | */ |
21949 | 0 | if (vctxt->idcMatcherCache != NULL) |
21950 | 0 | matcher->nextCached = vctxt->idcMatcherCache; |
21951 | 0 | vctxt->idcMatcherCache = matcher; |
21952 | |
|
21953 | 0 | matcher = next; |
21954 | 0 | } |
21955 | 0 | } |
21956 | | |
21957 | | /** |
21958 | | * Creates/reuses and activates state objects for the given |
21959 | | * XPath information; if the XPath expression consists of unions, |
21960 | | * multiple state objects are created for every unioned expression. |
21961 | | * |
21962 | | * @param vctxt the WXS validation context |
21963 | | * @param matcher the IDC matcher |
21964 | | * @param sel the XPath information |
21965 | | * @param type "selector" or "field" |
21966 | | * @returns 0 on success and -1 on internal errors. |
21967 | | */ |
21968 | | static int |
21969 | | xmlSchemaIDCAddStateObject(xmlSchemaValidCtxtPtr vctxt, |
21970 | | xmlSchemaIDCMatcherPtr matcher, |
21971 | | xmlSchemaIDCSelectPtr sel, |
21972 | | int type) |
21973 | 0 | { |
21974 | 0 | xmlSchemaIDCStateObjPtr sto; |
21975 | | |
21976 | | /* |
21977 | | * Reuse the state objects from the pool. |
21978 | | */ |
21979 | 0 | if (vctxt->xpathStatePool != NULL) { |
21980 | 0 | sto = vctxt->xpathStatePool; |
21981 | 0 | vctxt->xpathStatePool = sto->next; |
21982 | 0 | sto->next = NULL; |
21983 | 0 | } else { |
21984 | | /* |
21985 | | * Create a new state object. |
21986 | | */ |
21987 | 0 | sto = (xmlSchemaIDCStateObjPtr) xmlMalloc(sizeof(xmlSchemaIDCStateObj)); |
21988 | 0 | if (sto == NULL) { |
21989 | 0 | xmlSchemaVErrMemory(NULL); |
21990 | 0 | return (-1); |
21991 | 0 | } |
21992 | 0 | memset(sto, 0, sizeof(xmlSchemaIDCStateObj)); |
21993 | 0 | } |
21994 | | /* |
21995 | | * Add to global list. |
21996 | | */ |
21997 | 0 | if (vctxt->xpathStates != NULL) |
21998 | 0 | sto->next = vctxt->xpathStates; |
21999 | 0 | vctxt->xpathStates = sto; |
22000 | | |
22001 | | /* |
22002 | | * Free the old xpath validation context. |
22003 | | */ |
22004 | 0 | if (sto->xpathCtxt != NULL) |
22005 | 0 | xmlFreeStreamCtxt((xmlStreamCtxtPtr) sto->xpathCtxt); |
22006 | | |
22007 | | /* |
22008 | | * Create a new XPath (pattern) validation context. |
22009 | | */ |
22010 | 0 | sto->xpathCtxt = (void *) xmlPatternGetStreamCtxt( |
22011 | 0 | (xmlPatternPtr) sel->xpathComp); |
22012 | 0 | if (sto->xpathCtxt == NULL) { |
22013 | 0 | VERROR_INT("xmlSchemaIDCAddStateObject", |
22014 | 0 | "failed to create an XPath validation context"); |
22015 | 0 | return (-1); |
22016 | 0 | } |
22017 | 0 | sto->type = type; |
22018 | 0 | sto->depth = vctxt->depth; |
22019 | 0 | sto->matcher = matcher; |
22020 | 0 | sto->sel = sel; |
22021 | 0 | sto->nbHistory = 0; |
22022 | |
|
22023 | 0 | return (0); |
22024 | 0 | } |
22025 | | |
22026 | | /** |
22027 | | * Evaluates all active XPath state objects. |
22028 | | * |
22029 | | * @param vctxt the WXS validation context |
22030 | | * @param nodeType the nodeType of the current node |
22031 | | * @returns the number of IC "field" state objects which resolved to |
22032 | | * this node, 0 if none resolved and -1 on internal errors. |
22033 | | */ |
22034 | | static int |
22035 | | xmlSchemaXPathEvaluate(xmlSchemaValidCtxtPtr vctxt, |
22036 | | xmlElementType nodeType) |
22037 | 0 | { |
22038 | 0 | xmlSchemaIDCStateObjPtr sto, head = NULL, first; |
22039 | 0 | int res, resolved = 0, depth = vctxt->depth; |
22040 | |
|
22041 | 0 | if (vctxt->xpathStates == NULL) |
22042 | 0 | return (0); |
22043 | | |
22044 | 0 | if (nodeType == XML_ATTRIBUTE_NODE) |
22045 | 0 | depth++; |
22046 | | /* |
22047 | | * Process all active XPath state objects. |
22048 | | */ |
22049 | 0 | first = vctxt->xpathStates; |
22050 | 0 | sto = first; |
22051 | 0 | while (sto != head) { |
22052 | 0 | if (nodeType == XML_ELEMENT_NODE) |
22053 | 0 | res = xmlStreamPush((xmlStreamCtxtPtr) sto->xpathCtxt, |
22054 | 0 | vctxt->inode->localName, vctxt->inode->nsName); |
22055 | 0 | else |
22056 | 0 | res = xmlStreamPushAttr((xmlStreamCtxtPtr) sto->xpathCtxt, |
22057 | 0 | vctxt->inode->localName, vctxt->inode->nsName); |
22058 | |
|
22059 | 0 | if (res == -1) { |
22060 | 0 | VERROR_INT("xmlSchemaXPathEvaluate", |
22061 | 0 | "calling xmlStreamPush()"); |
22062 | 0 | return (-1); |
22063 | 0 | } |
22064 | 0 | if (res == 0) |
22065 | 0 | goto next_sto; |
22066 | | /* |
22067 | | * Full match. |
22068 | | */ |
22069 | | /* |
22070 | | * Register a match in the state object history. |
22071 | | */ |
22072 | 0 | if (sto->sizeHistory <= sto->nbHistory) { |
22073 | 0 | int *tmp; |
22074 | 0 | int newSize; |
22075 | |
|
22076 | 0 | newSize = xmlGrowCapacity(sto->sizeHistory, sizeof(tmp[0]), |
22077 | 0 | 5, XML_MAX_ITEMS); |
22078 | 0 | if (newSize < 0) { |
22079 | 0 | xmlSchemaVErrMemory(vctxt); |
22080 | 0 | return (-1); |
22081 | 0 | } |
22082 | 0 | tmp = xmlRealloc(sto->history, newSize * sizeof(tmp[0])); |
22083 | 0 | if (tmp == NULL) { |
22084 | 0 | xmlSchemaVErrMemory(vctxt); |
22085 | 0 | return (-1); |
22086 | 0 | } |
22087 | | |
22088 | 0 | sto->history = tmp; |
22089 | 0 | sto->sizeHistory = newSize; |
22090 | 0 | } |
22091 | 0 | sto->history[sto->nbHistory++] = depth; |
22092 | |
|
22093 | 0 | if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_SELECTOR) { |
22094 | 0 | xmlSchemaIDCSelectPtr sel; |
22095 | | /* |
22096 | | * Activate state objects for the IDC fields of |
22097 | | * the IDC selector. |
22098 | | */ |
22099 | 0 | sel = sto->matcher->aidc->def->fields; |
22100 | 0 | while (sel != NULL) { |
22101 | 0 | if (xmlSchemaIDCAddStateObject(vctxt, sto->matcher, |
22102 | 0 | sel, XPATH_STATE_OBJ_TYPE_IDC_FIELD) == -1) |
22103 | 0 | return (-1); |
22104 | 0 | sel = sel->next; |
22105 | 0 | } |
22106 | 0 | } else if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_FIELD) { |
22107 | | /* |
22108 | | * An IDC key node was found by the IDC field. |
22109 | | */ |
22110 | | /* |
22111 | | * Notify that the character value of this node is |
22112 | | * needed. |
22113 | | */ |
22114 | 0 | if (resolved == 0) { |
22115 | 0 | if ((vctxt->inode->flags & |
22116 | 0 | XML_SCHEMA_NODE_INFO_VALUE_NEEDED) == 0) |
22117 | 0 | vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_VALUE_NEEDED; |
22118 | 0 | } |
22119 | 0 | resolved++; |
22120 | 0 | } |
22121 | 0 | next_sto: |
22122 | 0 | if (sto->next == NULL) { |
22123 | | /* |
22124 | | * Evaluate field state objects created on this node as well. |
22125 | | */ |
22126 | 0 | head = first; |
22127 | 0 | sto = vctxt->xpathStates; |
22128 | 0 | } else |
22129 | 0 | sto = sto->next; |
22130 | 0 | } |
22131 | 0 | return (resolved); |
22132 | 0 | } |
22133 | | |
22134 | | static const xmlChar * |
22135 | | xmlSchemaFormatIDCKeySequence_1(xmlSchemaValidCtxtPtr vctxt, |
22136 | | xmlChar **buf, |
22137 | | xmlSchemaPSVIIDCKeyPtr *seq, |
22138 | | int count, int for_hash) |
22139 | 0 | { |
22140 | 0 | int i, res; |
22141 | 0 | xmlChar *value = NULL; |
22142 | |
|
22143 | 0 | *buf = xmlStrdup(BAD_CAST "["); |
22144 | 0 | for (i = 0; i < count; i++) { |
22145 | 0 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
22146 | 0 | if (!for_hash) |
22147 | 0 | res = xmlSchemaGetCanonValueWhtspExt(seq[i]->val, |
22148 | 0 | xmlSchemaGetWhiteSpaceFacetValue(seq[i]->type), |
22149 | 0 | &value); |
22150 | 0 | else { |
22151 | 0 | res = xmlSchemaGetCanonValueHash(seq[i]->val, &value); |
22152 | 0 | } |
22153 | 0 | if (res == 0) |
22154 | 0 | *buf = xmlStrcat(*buf, BAD_CAST value); |
22155 | 0 | else { |
22156 | 0 | VERROR_INT("xmlSchemaFormatIDCKeySequence", |
22157 | 0 | "failed to compute a canonical value"); |
22158 | 0 | *buf = xmlStrcat(*buf, BAD_CAST "???"); |
22159 | 0 | } |
22160 | 0 | if (i < count -1) |
22161 | 0 | *buf = xmlStrcat(*buf, BAD_CAST "', "); |
22162 | 0 | else |
22163 | 0 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
22164 | 0 | if (value != NULL) { |
22165 | 0 | xmlFree(value); |
22166 | 0 | value = NULL; |
22167 | 0 | } |
22168 | 0 | } |
22169 | 0 | *buf = xmlStrcat(*buf, BAD_CAST "]"); |
22170 | |
|
22171 | 0 | return (BAD_CAST *buf); |
22172 | 0 | } |
22173 | | |
22174 | | static const xmlChar * |
22175 | | xmlSchemaFormatIDCKeySequence(xmlSchemaValidCtxtPtr vctxt, |
22176 | | xmlChar **buf, |
22177 | | xmlSchemaPSVIIDCKeyPtr *seq, |
22178 | | int count) |
22179 | 0 | { |
22180 | 0 | return xmlSchemaFormatIDCKeySequence_1(vctxt, buf, seq, count, 0); |
22181 | 0 | } |
22182 | | |
22183 | | static const xmlChar * |
22184 | | xmlSchemaHashKeySequence(xmlSchemaValidCtxtPtr vctxt, |
22185 | | xmlChar **buf, |
22186 | | xmlSchemaPSVIIDCKeyPtr *seq, |
22187 | | int count) |
22188 | 0 | { |
22189 | 0 | return xmlSchemaFormatIDCKeySequence_1(vctxt, buf, seq, count, 1); |
22190 | 0 | } |
22191 | | |
22192 | | /** |
22193 | | * Pops all XPath states. |
22194 | | * |
22195 | | * @param vctxt the WXS validation context |
22196 | | * @returns 0 on success and -1 on internal errors. |
22197 | | */ |
22198 | | static int |
22199 | | xmlSchemaXPathPop(xmlSchemaValidCtxtPtr vctxt) |
22200 | 0 | { |
22201 | 0 | xmlSchemaIDCStateObjPtr sto; |
22202 | 0 | int res; |
22203 | |
|
22204 | 0 | if (vctxt->xpathStates == NULL) |
22205 | 0 | return(0); |
22206 | 0 | sto = vctxt->xpathStates; |
22207 | 0 | do { |
22208 | 0 | res = xmlStreamPop((xmlStreamCtxtPtr) sto->xpathCtxt); |
22209 | 0 | if (res == -1) |
22210 | 0 | return (-1); |
22211 | 0 | sto = sto->next; |
22212 | 0 | } while (sto != NULL); |
22213 | 0 | return(0); |
22214 | 0 | } |
22215 | | |
22216 | | /** |
22217 | | * Processes and pops the history items of the IDC state objects. |
22218 | | * IDC key-sequences are validated/created on IDC bindings. |
22219 | | * |
22220 | | * @param vctxt the WXS validation context |
22221 | | * @param depth depth |
22222 | | * @returns 0 on success and -1 on internal errors. |
22223 | | */ |
22224 | | static int |
22225 | | xmlSchemaXPathProcessHistory(xmlSchemaValidCtxtPtr vctxt, |
22226 | | int depth) |
22227 | 0 | { |
22228 | 0 | xmlSchemaIDCStateObjPtr sto, nextsto; |
22229 | 0 | int res, matchDepth; |
22230 | 0 | xmlSchemaPSVIIDCKeyPtr key = NULL; |
22231 | 0 | xmlSchemaTypePtr type = vctxt->inode->typeDef, simpleType = NULL; |
22232 | |
|
22233 | 0 | if (vctxt->xpathStates == NULL) |
22234 | 0 | return (0); |
22235 | 0 | sto = vctxt->xpathStates; |
22236 | | |
22237 | | /* |
22238 | | * Evaluate the state objects. |
22239 | | */ |
22240 | 0 | while (sto != NULL) { |
22241 | 0 | res = xmlStreamPop((xmlStreamCtxtPtr) sto->xpathCtxt); |
22242 | 0 | if (res == -1) { |
22243 | 0 | VERROR_INT("xmlSchemaXPathProcessHistory", |
22244 | 0 | "calling xmlStreamPop()"); |
22245 | 0 | return (-1); |
22246 | 0 | } |
22247 | 0 | if (sto->nbHistory == 0) |
22248 | 0 | goto deregister_check; |
22249 | | |
22250 | 0 | matchDepth = sto->history[sto->nbHistory -1]; |
22251 | | |
22252 | | /* |
22253 | | * Only matches at the current depth are of interest. |
22254 | | */ |
22255 | 0 | if (matchDepth != depth) { |
22256 | 0 | sto = sto->next; |
22257 | 0 | continue; |
22258 | 0 | } |
22259 | 0 | if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_FIELD) { |
22260 | | /* |
22261 | | * NOTE: According to |
22262 | | * http://www.w3.org/Bugs/Public/show_bug.cgi?id=2198 |
22263 | | * ... the simple-content of complex types is also allowed. |
22264 | | */ |
22265 | |
|
22266 | 0 | if (WXS_IS_COMPLEX(type)) { |
22267 | 0 | if (WXS_HAS_SIMPLE_CONTENT(type)) { |
22268 | | /* |
22269 | | * Sanity check for complex types with simple content. |
22270 | | */ |
22271 | 0 | simpleType = type->contentTypeDef; |
22272 | 0 | if (simpleType == NULL) { |
22273 | 0 | VERROR_INT("xmlSchemaXPathProcessHistory", |
22274 | 0 | "field resolves to a CT with simple content " |
22275 | 0 | "but the CT is missing the ST definition"); |
22276 | 0 | return (-1); |
22277 | 0 | } |
22278 | 0 | } else |
22279 | 0 | simpleType = NULL; |
22280 | 0 | } else |
22281 | 0 | simpleType = type; |
22282 | 0 | if (simpleType == NULL) { |
22283 | 0 | xmlChar *str = NULL; |
22284 | | |
22285 | | /* |
22286 | | * Not qualified if the field resolves to a node of non |
22287 | | * simple type. |
22288 | | */ |
22289 | 0 | xmlSchemaCustomErr(ACTXT_CAST vctxt, |
22290 | 0 | XML_SCHEMAV_CVC_IDC, NULL, |
22291 | 0 | WXS_BASIC_CAST sto->matcher->aidc->def, |
22292 | 0 | "The XPath '%s' of a field of %s does evaluate to a node of " |
22293 | 0 | "non-simple type", |
22294 | 0 | sto->sel->xpath, |
22295 | 0 | xmlSchemaGetIDCDesignation(&str, sto->matcher->aidc->def)); |
22296 | 0 | FREE_AND_NULL(str); |
22297 | 0 | sto->nbHistory--; |
22298 | 0 | goto deregister_check; |
22299 | 0 | } |
22300 | | |
22301 | 0 | if ((key == NULL) && (vctxt->inode->val == NULL)) { |
22302 | | /* |
22303 | | * Failed to provide the normalized value; maybe |
22304 | | * the value was invalid. |
22305 | | */ |
22306 | 0 | VERROR(XML_SCHEMAV_CVC_IDC, |
22307 | 0 | WXS_BASIC_CAST sto->matcher->aidc->def, |
22308 | 0 | "Warning: No precomputed value available, the value " |
22309 | 0 | "was either invalid or something strange happened"); |
22310 | 0 | sto->nbHistory--; |
22311 | 0 | goto deregister_check; |
22312 | 0 | } else { |
22313 | 0 | xmlSchemaIDCMatcherPtr matcher = sto->matcher; |
22314 | 0 | xmlSchemaPSVIIDCKeyPtr *keySeq; |
22315 | 0 | int pos, idx; |
22316 | | |
22317 | | /* |
22318 | | * The key will be anchored on the matcher's list of |
22319 | | * key-sequences. The position in this list is determined |
22320 | | * by the target node's depth relative to the matcher's |
22321 | | * depth of creation (i.e. the depth of the scope element). |
22322 | | * |
22323 | | * Element Depth Pos List-entries |
22324 | | * <scope> 0 NULL |
22325 | | * <bar> 1 NULL |
22326 | | * <target/> 2 2 target |
22327 | | * <bar> |
22328 | | * </scope> |
22329 | | * |
22330 | | * The size of the list is only dependent on the depth of |
22331 | | * the tree. |
22332 | | * An entry will be NULLed in selector_leave, i.e. when |
22333 | | * we hit the target's |
22334 | | */ |
22335 | 0 | pos = sto->depth - matcher->depth; |
22336 | 0 | idx = sto->sel->index; |
22337 | | |
22338 | | /* |
22339 | | * Create/grow the array of key-sequences. |
22340 | | */ |
22341 | 0 | if (pos >= matcher->sizeKeySeqs) { |
22342 | 0 | xmlSchemaPSVIIDCKeyPtr **tmp; |
22343 | 0 | int oldSize = matcher->sizeKeySeqs; |
22344 | 0 | int newSize, i; |
22345 | |
|
22346 | 0 | newSize = xmlGrowCapacity(pos, sizeof(tmp[0]), |
22347 | 0 | 10, XML_MAX_ITEMS); |
22348 | 0 | if (newSize < 0) { |
22349 | 0 | xmlSchemaVErrMemory(vctxt); |
22350 | 0 | return (-1); |
22351 | 0 | } |
22352 | 0 | tmp = xmlRealloc(matcher->keySeqs, |
22353 | 0 | newSize * sizeof(tmp[0])); |
22354 | 0 | if (tmp == NULL) { |
22355 | 0 | xmlSchemaVErrMemory(vctxt); |
22356 | 0 | return (-1); |
22357 | 0 | } |
22358 | | |
22359 | 0 | matcher->keySeqs = tmp; |
22360 | 0 | matcher->sizeKeySeqs = newSize; |
22361 | | |
22362 | | /* |
22363 | | * The array needs to be NULLed. |
22364 | | * TODO: Use memset? |
22365 | | */ |
22366 | 0 | for (i = oldSize; i < newSize; i++) |
22367 | 0 | matcher->keySeqs[i] = NULL; |
22368 | 0 | } |
22369 | | |
22370 | | /* |
22371 | | * Get/create the key-sequence. |
22372 | | */ |
22373 | 0 | keySeq = matcher->keySeqs[pos]; |
22374 | 0 | if (keySeq == NULL) { |
22375 | 0 | goto create_sequence; |
22376 | 0 | } else if (keySeq[idx] != NULL) { |
22377 | 0 | xmlChar *str = NULL; |
22378 | | /* |
22379 | | * cvc-identity-constraint: |
22380 | | * 3 For each node in the `target node set` all |
22381 | | * of the {fields}, with that node as the context |
22382 | | * node, evaluate to either an empty node-set or |
22383 | | * a node-set with exactly one member, which must |
22384 | | * have a simple type. |
22385 | | * |
22386 | | * The key was already set; report an error. |
22387 | | */ |
22388 | 0 | xmlSchemaCustomErr(ACTXT_CAST vctxt, |
22389 | 0 | XML_SCHEMAV_CVC_IDC, NULL, |
22390 | 0 | WXS_BASIC_CAST matcher->aidc->def, |
22391 | 0 | "The XPath '%s' of a field of %s evaluates to a " |
22392 | 0 | "node-set with more than one member", |
22393 | 0 | sto->sel->xpath, |
22394 | 0 | xmlSchemaGetIDCDesignation(&str, matcher->aidc->def)); |
22395 | 0 | FREE_AND_NULL(str); |
22396 | 0 | sto->nbHistory--; |
22397 | 0 | goto deregister_check; |
22398 | 0 | } else |
22399 | 0 | goto create_key; |
22400 | | |
22401 | 0 | create_sequence: |
22402 | | /* |
22403 | | * Create a key-sequence. |
22404 | | */ |
22405 | 0 | keySeq = (xmlSchemaPSVIIDCKeyPtr *) xmlMalloc( |
22406 | 0 | matcher->aidc->def->nbFields * |
22407 | 0 | sizeof(xmlSchemaPSVIIDCKeyPtr)); |
22408 | 0 | if (keySeq == NULL) { |
22409 | 0 | xmlSchemaVErrMemory(NULL); |
22410 | 0 | return(-1); |
22411 | 0 | } |
22412 | 0 | memset(keySeq, 0, matcher->aidc->def->nbFields * |
22413 | 0 | sizeof(xmlSchemaPSVIIDCKeyPtr)); |
22414 | 0 | matcher->keySeqs[pos] = keySeq; |
22415 | 0 | create_key: |
22416 | | /* |
22417 | | * Create a key once per node only. |
22418 | | */ |
22419 | 0 | if (key == NULL) { |
22420 | 0 | key = (xmlSchemaPSVIIDCKeyPtr) xmlMalloc( |
22421 | 0 | sizeof(xmlSchemaPSVIIDCKey)); |
22422 | 0 | if (key == NULL) { |
22423 | 0 | xmlSchemaVErrMemory(NULL); |
22424 | 0 | xmlFree(keySeq); |
22425 | 0 | matcher->keySeqs[pos] = NULL; |
22426 | 0 | return(-1); |
22427 | 0 | } |
22428 | | /* |
22429 | | * Consume the compiled value. |
22430 | | */ |
22431 | 0 | key->type = simpleType; |
22432 | 0 | key->val = vctxt->inode->val; |
22433 | 0 | vctxt->inode->val = NULL; |
22434 | | /* |
22435 | | * Store the key in a global list. |
22436 | | */ |
22437 | 0 | if (xmlSchemaIDCStoreKey(vctxt, key) == -1) { |
22438 | 0 | xmlSchemaIDCFreeKey(key); |
22439 | 0 | return (-1); |
22440 | 0 | } |
22441 | 0 | } |
22442 | 0 | keySeq[idx] = key; |
22443 | 0 | } |
22444 | 0 | } else if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_SELECTOR) { |
22445 | |
|
22446 | 0 | xmlSchemaPSVIIDCKeyPtr **keySeq = NULL; |
22447 | | /* xmlSchemaPSVIIDCBindingPtr bind; */ |
22448 | 0 | xmlSchemaPSVIIDCNodePtr ntItem; |
22449 | 0 | xmlSchemaIDCMatcherPtr matcher; |
22450 | 0 | xmlSchemaIDCPtr idc; |
22451 | 0 | xmlSchemaItemListPtr targets; |
22452 | 0 | int pos, i, j, nbKeys; |
22453 | | /* |
22454 | | * Here we have the following scenario: |
22455 | | * An IDC 'selector' state object resolved to a target node, |
22456 | | * during the time this target node was in the |
22457 | | * ancestor-or-self axis, the 'field' state object(s) looked |
22458 | | * out for matching nodes to create a key-sequence for this |
22459 | | * target node. Now we are back to this target node and need |
22460 | | * to put the key-sequence, together with the target node |
22461 | | * itself, into the node-table of the corresponding IDC |
22462 | | * binding. |
22463 | | */ |
22464 | 0 | matcher = sto->matcher; |
22465 | 0 | idc = matcher->aidc->def; |
22466 | 0 | nbKeys = idc->nbFields; |
22467 | 0 | pos = depth - matcher->depth; |
22468 | | /* |
22469 | | * Check if the matcher has any key-sequences at all, plus |
22470 | | * if it has a key-sequence for the current target node. |
22471 | | */ |
22472 | 0 | if ((matcher->keySeqs == NULL) || |
22473 | 0 | (matcher->sizeKeySeqs <= pos)) { |
22474 | 0 | if (idc->type == XML_SCHEMA_TYPE_IDC_KEY) |
22475 | 0 | goto selector_key_error; |
22476 | 0 | else |
22477 | 0 | goto selector_leave; |
22478 | 0 | } |
22479 | | |
22480 | 0 | keySeq = &(matcher->keySeqs[pos]); |
22481 | 0 | if (*keySeq == NULL) { |
22482 | 0 | if (idc->type == XML_SCHEMA_TYPE_IDC_KEY) |
22483 | 0 | goto selector_key_error; |
22484 | 0 | else |
22485 | 0 | goto selector_leave; |
22486 | 0 | } |
22487 | | |
22488 | 0 | for (i = 0; i < nbKeys; i++) { |
22489 | 0 | if ((*keySeq)[i] == NULL) { |
22490 | | /* |
22491 | | * Not qualified, if not all fields did resolve. |
22492 | | */ |
22493 | 0 | if (idc->type == XML_SCHEMA_TYPE_IDC_KEY) { |
22494 | | /* |
22495 | | * All fields of a "key" IDC must resolve. |
22496 | | */ |
22497 | 0 | goto selector_key_error; |
22498 | 0 | } |
22499 | 0 | goto selector_leave; |
22500 | 0 | } |
22501 | 0 | } |
22502 | | /* |
22503 | | * All fields did resolve. |
22504 | | */ |
22505 | | |
22506 | | /* |
22507 | | * 4.1 If the {identity-constraint category} is unique(/key), |
22508 | | * then no two members of the `qualified node set` have |
22509 | | * `key-sequences` whose members are pairwise equal, as |
22510 | | * defined by Equal in [XML Schemas: Datatypes]. |
22511 | | * |
22512 | | * Get the IDC binding from the matcher and check for |
22513 | | * duplicate key-sequences. |
22514 | | */ |
22515 | | #if 0 |
22516 | | bind = xmlSchemaIDCAcquireBinding(vctxt, matcher); |
22517 | | #endif |
22518 | 0 | targets = xmlSchemaIDCAcquireTargetList(vctxt, matcher); |
22519 | 0 | if (targets == NULL) |
22520 | 0 | return(-1); |
22521 | | |
22522 | 0 | if ((idc->type != XML_SCHEMA_TYPE_IDC_KEYREF) && |
22523 | 0 | (targets->nbItems != 0)) { |
22524 | 0 | xmlSchemaPSVIIDCKeyPtr ckey, bkey, *bkeySeq; |
22525 | 0 | xmlIDCHashEntryPtr e; |
22526 | |
|
22527 | 0 | res = 0; |
22528 | |
|
22529 | 0 | if (!matcher->htab) |
22530 | 0 | e = NULL; |
22531 | 0 | else { |
22532 | 0 | xmlChar *value = NULL; |
22533 | 0 | xmlSchemaHashKeySequence(vctxt, &value, *keySeq, nbKeys); |
22534 | 0 | e = xmlHashLookup(matcher->htab, value); |
22535 | 0 | FREE_AND_NULL(value); |
22536 | 0 | } |
22537 | | |
22538 | | /* |
22539 | | * Compare the key-sequences, key by key. |
22540 | | */ |
22541 | 0 | for (;e; e = e->next) { |
22542 | 0 | bkeySeq = |
22543 | 0 | ((xmlSchemaPSVIIDCNodePtr) targets->items[e->index])->keys; |
22544 | 0 | for (j = 0; j < nbKeys; j++) { |
22545 | 0 | ckey = (*keySeq)[j]; |
22546 | 0 | bkey = bkeySeq[j]; |
22547 | 0 | res = xmlSchemaAreValuesEqual(ckey->val, bkey->val); |
22548 | 0 | if (res == -1) { |
22549 | 0 | return (-1); |
22550 | 0 | } else if (res == 0) { |
22551 | | /* |
22552 | | * One of the keys differs, so the key-sequence |
22553 | | * won't be equal; get out. |
22554 | | */ |
22555 | 0 | break; |
22556 | 0 | } |
22557 | 0 | } |
22558 | 0 | if (res == 1) { |
22559 | | /* |
22560 | | * Duplicate key-sequence found. |
22561 | | */ |
22562 | 0 | break; |
22563 | 0 | } |
22564 | 0 | } |
22565 | 0 | if (e) { |
22566 | 0 | xmlChar *str = NULL, *strB = NULL; |
22567 | | /* |
22568 | | * TODO: Try to report the key-sequence. |
22569 | | */ |
22570 | 0 | xmlSchemaCustomErr(ACTXT_CAST vctxt, |
22571 | 0 | XML_SCHEMAV_CVC_IDC, NULL, |
22572 | 0 | WXS_BASIC_CAST idc, |
22573 | 0 | "Duplicate key-sequence %s in %s", |
22574 | 0 | xmlSchemaFormatIDCKeySequence(vctxt, &str, |
22575 | 0 | (*keySeq), nbKeys), |
22576 | 0 | xmlSchemaGetIDCDesignation(&strB, idc)); |
22577 | 0 | FREE_AND_NULL(str); |
22578 | 0 | FREE_AND_NULL(strB); |
22579 | 0 | goto selector_leave; |
22580 | 0 | } |
22581 | 0 | } |
22582 | | /* |
22583 | | * Add a node-table item to the IDC binding. |
22584 | | */ |
22585 | 0 | ntItem = (xmlSchemaPSVIIDCNodePtr) xmlMalloc( |
22586 | 0 | sizeof(xmlSchemaPSVIIDCNode)); |
22587 | 0 | if (ntItem == NULL) { |
22588 | 0 | xmlSchemaVErrMemory(NULL); |
22589 | 0 | xmlFree(*keySeq); |
22590 | 0 | *keySeq = NULL; |
22591 | 0 | return(-1); |
22592 | 0 | } |
22593 | 0 | memset(ntItem, 0, sizeof(xmlSchemaPSVIIDCNode)); |
22594 | | |
22595 | | /* |
22596 | | * Store the node-table item in a global list. |
22597 | | */ |
22598 | 0 | if (idc->type != XML_SCHEMA_TYPE_IDC_KEYREF) { |
22599 | 0 | if (xmlSchemaIDCStoreNodeTableItem(vctxt, ntItem) == -1) { |
22600 | 0 | xmlFree(ntItem); |
22601 | 0 | xmlFree(*keySeq); |
22602 | 0 | *keySeq = NULL; |
22603 | 0 | return (-1); |
22604 | 0 | } |
22605 | 0 | ntItem->nodeQNameID = -1; |
22606 | 0 | } else { |
22607 | | /* |
22608 | | * Save a cached QName for this node on the IDC node, to be |
22609 | | * able to report it, even if the node is not saved. |
22610 | | */ |
22611 | 0 | ntItem->nodeQNameID = xmlSchemaVAddNodeQName(vctxt, |
22612 | 0 | vctxt->inode->localName, vctxt->inode->nsName); |
22613 | 0 | if (ntItem->nodeQNameID == -1) { |
22614 | 0 | xmlFree(ntItem); |
22615 | 0 | xmlFree(*keySeq); |
22616 | 0 | *keySeq = NULL; |
22617 | 0 | return (-1); |
22618 | 0 | } |
22619 | 0 | } |
22620 | | /* |
22621 | | * Init the node-table item: Save the node, position and |
22622 | | * consume the key-sequence. |
22623 | | */ |
22624 | 0 | ntItem->node = vctxt->node; |
22625 | 0 | ntItem->nodeLine = vctxt->inode->nodeLine; |
22626 | 0 | ntItem->keys = *keySeq; |
22627 | 0 | *keySeq = NULL; |
22628 | | #if 0 |
22629 | | if (xmlSchemaIDCAppendNodeTableItem(bind, ntItem) == -1) |
22630 | | #endif |
22631 | 0 | if (xmlSchemaItemListAdd(targets, ntItem) == -1) { |
22632 | 0 | if (idc->type == XML_SCHEMA_TYPE_IDC_KEYREF) { |
22633 | | /* |
22634 | | * Free the item, since keyref items won't be |
22635 | | * put on a global list. |
22636 | | */ |
22637 | 0 | xmlFree(ntItem->keys); |
22638 | 0 | xmlFree(ntItem); |
22639 | 0 | } |
22640 | 0 | return (-1); |
22641 | 0 | } |
22642 | 0 | if (idc->type != XML_SCHEMA_TYPE_IDC_KEYREF) { |
22643 | 0 | xmlChar *value = NULL; |
22644 | 0 | xmlIDCHashEntryPtr r, e; |
22645 | 0 | if (!matcher->htab) |
22646 | 0 | matcher->htab = xmlHashCreate(4); |
22647 | 0 | xmlSchemaHashKeySequence(vctxt, &value, ntItem->keys, nbKeys); |
22648 | 0 | e = xmlMalloc(sizeof *e); |
22649 | 0 | if (e == NULL) { |
22650 | 0 | xmlSchemaVErrMemory(vctxt); |
22651 | 0 | goto mem_error; |
22652 | 0 | } |
22653 | 0 | e->index = targets->nbItems - 1; |
22654 | 0 | r = xmlHashLookup(matcher->htab, value); |
22655 | 0 | if (r) { |
22656 | 0 | e->next = r->next; |
22657 | 0 | r->next = e; |
22658 | 0 | } else { |
22659 | 0 | e->next = NULL; |
22660 | 0 | if (xmlHashAddEntry(matcher->htab, value, e) < 0) { |
22661 | 0 | xmlSchemaVErrMemory(vctxt); |
22662 | 0 | xmlFree(e); |
22663 | 0 | } |
22664 | 0 | } |
22665 | 0 | mem_error: |
22666 | 0 | FREE_AND_NULL(value); |
22667 | 0 | } |
22668 | | |
22669 | 0 | goto selector_leave; |
22670 | 0 | selector_key_error: |
22671 | 0 | { |
22672 | 0 | xmlChar *str = NULL; |
22673 | | /* |
22674 | | * 4.2.1 (KEY) The `target node set` and the |
22675 | | * `qualified node set` are equal, that is, every |
22676 | | * member of the `target node set` is also a member |
22677 | | * of the `qualified node set` and vice versa. |
22678 | | */ |
22679 | 0 | xmlSchemaCustomErr(ACTXT_CAST vctxt, |
22680 | 0 | XML_SCHEMAV_CVC_IDC, NULL, |
22681 | 0 | WXS_BASIC_CAST idc, |
22682 | 0 | "Not all fields of %s evaluate to a node", |
22683 | 0 | xmlSchemaGetIDCDesignation(&str, idc), NULL); |
22684 | 0 | FREE_AND_NULL(str); |
22685 | 0 | } |
22686 | 0 | selector_leave: |
22687 | | /* |
22688 | | * Free the key-sequence if not added to the IDC table. |
22689 | | */ |
22690 | 0 | if ((keySeq != NULL) && (*keySeq != NULL)) { |
22691 | 0 | xmlFree(*keySeq); |
22692 | 0 | *keySeq = NULL; |
22693 | 0 | } |
22694 | 0 | } /* if selector */ |
22695 | | |
22696 | 0 | sto->nbHistory--; |
22697 | |
|
22698 | 0 | deregister_check: |
22699 | | /* |
22700 | | * Deregister state objects if they reach the depth of creation. |
22701 | | */ |
22702 | 0 | if ((sto->nbHistory == 0) && (sto->depth == depth)) { |
22703 | 0 | if (vctxt->xpathStates != sto) { |
22704 | 0 | VERROR_INT("xmlSchemaXPathProcessHistory", |
22705 | 0 | "The state object to be removed is not the first " |
22706 | 0 | "in the list"); |
22707 | 0 | } |
22708 | 0 | nextsto = sto->next; |
22709 | | /* |
22710 | | * Unlink from the list of active XPath state objects. |
22711 | | */ |
22712 | 0 | vctxt->xpathStates = sto->next; |
22713 | 0 | sto->next = vctxt->xpathStatePool; |
22714 | | /* |
22715 | | * Link it to the pool of reusable state objects. |
22716 | | */ |
22717 | 0 | vctxt->xpathStatePool = sto; |
22718 | 0 | sto = nextsto; |
22719 | 0 | } else |
22720 | 0 | sto = sto->next; |
22721 | 0 | } /* while (sto != NULL) */ |
22722 | 0 | return (0); |
22723 | 0 | } |
22724 | | |
22725 | | /** |
22726 | | * Creates helper objects to evaluate IDC selectors/fields |
22727 | | * successively. |
22728 | | * |
22729 | | * @param vctxt the WXS validation context |
22730 | | * @param elemDecl the element declaration |
22731 | | * @returns 0 if OK and -1 on internal errors. |
22732 | | */ |
22733 | | static int |
22734 | | xmlSchemaIDCRegisterMatchers(xmlSchemaValidCtxtPtr vctxt, |
22735 | | xmlSchemaElementPtr elemDecl) |
22736 | 0 | { |
22737 | 0 | xmlSchemaIDCMatcherPtr matcher, last = NULL; |
22738 | 0 | xmlSchemaIDCPtr idc, refIdc; |
22739 | 0 | xmlSchemaIDCAugPtr aidc; |
22740 | |
|
22741 | 0 | idc = (xmlSchemaIDCPtr) elemDecl->idcs; |
22742 | 0 | if (idc == NULL) |
22743 | 0 | return (0); |
22744 | | |
22745 | 0 | if (vctxt->inode->idcMatchers != NULL) { |
22746 | 0 | VERROR_INT("xmlSchemaIDCRegisterMatchers", |
22747 | 0 | "The chain of IDC matchers is expected to be empty"); |
22748 | 0 | return (-1); |
22749 | 0 | } |
22750 | 0 | do { |
22751 | 0 | if (idc->type == XML_SCHEMA_TYPE_IDC_KEYREF) { |
22752 | | /* |
22753 | | * Since IDCs bubbles are expensive we need to know the |
22754 | | * depth at which the bubbles should stop; this will be |
22755 | | * the depth of the top-most keyref IDC. If no keyref |
22756 | | * references a key/unique IDC, the keyrefDepth will |
22757 | | * be -1, indicating that no bubbles are needed. |
22758 | | */ |
22759 | 0 | refIdc = (xmlSchemaIDCPtr) idc->ref->item; |
22760 | 0 | if (refIdc != NULL) { |
22761 | | /* |
22762 | | * Remember that we have keyrefs on this node. |
22763 | | */ |
22764 | 0 | vctxt->inode->hasKeyrefs = 1; |
22765 | | /* |
22766 | | * Lookup the referenced augmented IDC info. |
22767 | | */ |
22768 | 0 | aidc = vctxt->aidcs; |
22769 | 0 | while (aidc != NULL) { |
22770 | 0 | if (aidc->def == refIdc) |
22771 | 0 | break; |
22772 | 0 | aidc = aidc->next; |
22773 | 0 | } |
22774 | 0 | if (aidc == NULL) { |
22775 | 0 | VERROR_INT("xmlSchemaIDCRegisterMatchers", |
22776 | 0 | "Could not find an augmented IDC item for an IDC " |
22777 | 0 | "definition"); |
22778 | 0 | return (-1); |
22779 | 0 | } |
22780 | 0 | if ((aidc->keyrefDepth == -1) || |
22781 | 0 | (vctxt->depth < aidc->keyrefDepth)) |
22782 | 0 | aidc->keyrefDepth = vctxt->depth; |
22783 | 0 | } |
22784 | 0 | } |
22785 | | /* |
22786 | | * Lookup the augmented IDC item for the IDC definition. |
22787 | | */ |
22788 | 0 | aidc = vctxt->aidcs; |
22789 | 0 | while (aidc != NULL) { |
22790 | 0 | if (aidc->def == idc) |
22791 | 0 | break; |
22792 | 0 | aidc = aidc->next; |
22793 | 0 | } |
22794 | 0 | if (aidc == NULL) { |
22795 | 0 | VERROR_INT("xmlSchemaIDCRegisterMatchers", |
22796 | 0 | "Could not find an augmented IDC item for an IDC definition"); |
22797 | 0 | return (-1); |
22798 | 0 | } |
22799 | | /* |
22800 | | * Create an IDC matcher for every IDC definition. |
22801 | | */ |
22802 | 0 | if (vctxt->idcMatcherCache != NULL) { |
22803 | | /* |
22804 | | * Reuse a cached matcher. |
22805 | | */ |
22806 | 0 | matcher = vctxt->idcMatcherCache; |
22807 | 0 | vctxt->idcMatcherCache = matcher->nextCached; |
22808 | 0 | matcher->nextCached = NULL; |
22809 | 0 | } else { |
22810 | 0 | matcher = (xmlSchemaIDCMatcherPtr) |
22811 | 0 | xmlMalloc(sizeof(xmlSchemaIDCMatcher)); |
22812 | 0 | if (matcher == NULL) { |
22813 | 0 | xmlSchemaVErrMemory(vctxt); |
22814 | 0 | return (-1); |
22815 | 0 | } |
22816 | 0 | memset(matcher, 0, sizeof(xmlSchemaIDCMatcher)); |
22817 | 0 | } |
22818 | 0 | if (last == NULL) |
22819 | 0 | vctxt->inode->idcMatchers = matcher; |
22820 | 0 | else |
22821 | 0 | last->next = matcher; |
22822 | 0 | last = matcher; |
22823 | |
|
22824 | 0 | matcher->type = IDC_MATCHER; |
22825 | 0 | matcher->depth = vctxt->depth; |
22826 | 0 | matcher->aidc = aidc; |
22827 | 0 | matcher->idcType = aidc->def->type; |
22828 | | /* |
22829 | | * Init the automaton state object. |
22830 | | */ |
22831 | 0 | if (xmlSchemaIDCAddStateObject(vctxt, matcher, |
22832 | 0 | idc->selector, XPATH_STATE_OBJ_TYPE_IDC_SELECTOR) == -1) |
22833 | 0 | return (-1); |
22834 | | |
22835 | 0 | idc = idc->next; |
22836 | 0 | } while (idc != NULL); |
22837 | 0 | return (0); |
22838 | 0 | } |
22839 | | |
22840 | | static int |
22841 | | xmlSchemaIDCFillNodeTables(xmlSchemaValidCtxtPtr vctxt, |
22842 | | xmlSchemaNodeInfoPtr ielem) |
22843 | 0 | { |
22844 | 0 | xmlSchemaPSVIIDCBindingPtr bind; |
22845 | 0 | int res, i, j, k, nbTargets, nbFields, nbDupls, nbNodeTable; |
22846 | 0 | xmlSchemaPSVIIDCKeyPtr *keys, *ntkeys; |
22847 | 0 | xmlSchemaPSVIIDCNodePtr *targets, *dupls; |
22848 | |
|
22849 | 0 | xmlSchemaIDCMatcherPtr matcher = ielem->idcMatchers; |
22850 | | /* vctxt->createIDCNodeTables */ |
22851 | 0 | while (matcher != NULL) { |
22852 | | /* |
22853 | | * Skip keyref IDCs and empty IDC target-lists. |
22854 | | */ |
22855 | 0 | if ((matcher->aidc->def->type == XML_SCHEMA_TYPE_IDC_KEYREF) || |
22856 | 0 | WXS_ILIST_IS_EMPTY(matcher->targets)) |
22857 | 0 | { |
22858 | 0 | matcher = matcher->next; |
22859 | 0 | continue; |
22860 | 0 | } |
22861 | | /* |
22862 | | * If we _want_ the IDC node-table to be created in any case |
22863 | | * then do so. Otherwise create them only if keyrefs need them. |
22864 | | */ |
22865 | 0 | if ((! vctxt->createIDCNodeTables) && |
22866 | 0 | ((matcher->aidc->keyrefDepth == -1) || |
22867 | 0 | (matcher->aidc->keyrefDepth > vctxt->depth))) |
22868 | 0 | { |
22869 | 0 | matcher = matcher->next; |
22870 | 0 | continue; |
22871 | 0 | } |
22872 | | /* |
22873 | | * Get/create the IDC binding on this element for the IDC definition. |
22874 | | */ |
22875 | 0 | bind = xmlSchemaIDCAcquireBinding(vctxt, matcher); |
22876 | 0 | if (bind == NULL) |
22877 | 0 | goto internal_error; |
22878 | | |
22879 | 0 | if (! WXS_ILIST_IS_EMPTY(bind->dupls)) { |
22880 | 0 | dupls = (xmlSchemaPSVIIDCNodePtr *) bind->dupls->items; |
22881 | 0 | nbDupls = bind->dupls->nbItems; |
22882 | 0 | } else { |
22883 | 0 | dupls = NULL; |
22884 | 0 | nbDupls = 0; |
22885 | 0 | } |
22886 | 0 | if (bind->nodeTable != NULL) { |
22887 | 0 | nbNodeTable = bind->nbNodes; |
22888 | 0 | } else { |
22889 | 0 | nbNodeTable = 0; |
22890 | 0 | } |
22891 | |
|
22892 | 0 | if ((nbNodeTable == 0) && (nbDupls == 0)) { |
22893 | | /* |
22894 | | * Transfer all IDC target-nodes to the IDC node-table. |
22895 | | */ |
22896 | 0 | if (bind->nodeTable != NULL) |
22897 | 0 | xmlFree(bind->nodeTable); |
22898 | 0 | bind->nodeTable = |
22899 | 0 | (xmlSchemaPSVIIDCNodePtr *) matcher->targets->items; |
22900 | 0 | bind->sizeNodes = matcher->targets->sizeItems; |
22901 | 0 | bind->nbNodes = matcher->targets->nbItems; |
22902 | |
|
22903 | 0 | matcher->targets->items = NULL; |
22904 | 0 | matcher->targets->sizeItems = 0; |
22905 | 0 | matcher->targets->nbItems = 0; |
22906 | 0 | if (matcher->htab) { |
22907 | 0 | xmlHashFree(matcher->htab, xmlFreeIDCHashEntry); |
22908 | 0 | matcher->htab = NULL; |
22909 | 0 | } |
22910 | 0 | } else { |
22911 | | /* |
22912 | | * Compare the key-sequences and add to the IDC node-table. |
22913 | | */ |
22914 | 0 | nbTargets = matcher->targets->nbItems; |
22915 | 0 | targets = (xmlSchemaPSVIIDCNodePtr *) matcher->targets->items; |
22916 | 0 | nbFields = matcher->aidc->def->nbFields; |
22917 | 0 | i = 0; |
22918 | 0 | do { |
22919 | 0 | keys = targets[i]->keys; |
22920 | 0 | if (nbDupls) { |
22921 | | /* |
22922 | | * Search in already found duplicates first. |
22923 | | */ |
22924 | 0 | j = 0; |
22925 | 0 | do { |
22926 | 0 | if (nbFields == 1) { |
22927 | 0 | res = xmlSchemaAreValuesEqual(keys[0]->val, |
22928 | 0 | dupls[j]->keys[0]->val); |
22929 | 0 | if (res == -1) |
22930 | 0 | goto internal_error; |
22931 | 0 | if (res == 1) { |
22932 | | /* |
22933 | | * Equal key-sequence. |
22934 | | */ |
22935 | 0 | goto next_target; |
22936 | 0 | } |
22937 | 0 | } else { |
22938 | 0 | res = 0; |
22939 | 0 | ntkeys = dupls[j]->keys; |
22940 | 0 | for (k = 0; k < nbFields; k++) { |
22941 | 0 | res = xmlSchemaAreValuesEqual(keys[k]->val, |
22942 | 0 | ntkeys[k]->val); |
22943 | 0 | if (res == -1) |
22944 | 0 | goto internal_error; |
22945 | 0 | if (res == 0) { |
22946 | | /* |
22947 | | * One of the keys differs. |
22948 | | */ |
22949 | 0 | break; |
22950 | 0 | } |
22951 | 0 | } |
22952 | 0 | if (res == 1) { |
22953 | | /* |
22954 | | * Equal key-sequence found. |
22955 | | */ |
22956 | 0 | goto next_target; |
22957 | 0 | } |
22958 | 0 | } |
22959 | 0 | j++; |
22960 | 0 | } while (j < nbDupls); |
22961 | 0 | } |
22962 | 0 | if (bind->nbNodes) { |
22963 | 0 | j = 0; |
22964 | 0 | do { |
22965 | 0 | if (nbFields == 1) { |
22966 | 0 | res = xmlSchemaAreValuesEqual(keys[0]->val, |
22967 | 0 | bind->nodeTable[j]->keys[0]->val); |
22968 | 0 | if (res == -1) |
22969 | 0 | goto internal_error; |
22970 | 0 | if (res == 0) { |
22971 | | /* |
22972 | | * The key-sequence differs. |
22973 | | */ |
22974 | 0 | goto next_node_table_entry; |
22975 | 0 | } |
22976 | 0 | } else { |
22977 | 0 | res = 0; |
22978 | 0 | ntkeys = bind->nodeTable[j]->keys; |
22979 | 0 | for (k = 0; k < nbFields; k++) { |
22980 | 0 | res = xmlSchemaAreValuesEqual(keys[k]->val, |
22981 | 0 | ntkeys[k]->val); |
22982 | 0 | if (res == -1) |
22983 | 0 | goto internal_error; |
22984 | 0 | if (res == 0) { |
22985 | | /* |
22986 | | * One of the keys differs. |
22987 | | */ |
22988 | 0 | goto next_node_table_entry; |
22989 | 0 | } |
22990 | 0 | } |
22991 | 0 | } |
22992 | | /* |
22993 | | * Add the duplicate to the list of duplicates. |
22994 | | */ |
22995 | 0 | if (bind->dupls == NULL) { |
22996 | 0 | bind->dupls = xmlSchemaItemListCreate(); |
22997 | 0 | if (bind->dupls == NULL) |
22998 | 0 | goto internal_error; |
22999 | 0 | } |
23000 | 0 | if (xmlSchemaItemListAdd(bind->dupls, bind->nodeTable[j]) == -1) |
23001 | 0 | goto internal_error; |
23002 | 0 | dupls = (xmlSchemaPSVIIDCNodePtr *) bind->dupls->items; |
23003 | | /* |
23004 | | * Remove the duplicate entry from the IDC node-table. |
23005 | | */ |
23006 | 0 | bind->nodeTable[j] = bind->nodeTable[bind->nbNodes -1]; |
23007 | 0 | bind->nbNodes--; |
23008 | |
|
23009 | 0 | goto next_target; |
23010 | | |
23011 | 0 | next_node_table_entry: |
23012 | 0 | j++; |
23013 | 0 | } while (j < bind->nbNodes); |
23014 | 0 | } |
23015 | | /* |
23016 | | * If everything is fine, then add the IDC target-node to |
23017 | | * the IDC node-table. |
23018 | | */ |
23019 | 0 | if (xmlSchemaIDCAppendNodeTableItem(bind, targets[i]) == -1) |
23020 | 0 | goto internal_error; |
23021 | | |
23022 | 0 | next_target: |
23023 | 0 | i++; |
23024 | 0 | } while (i < nbTargets); |
23025 | 0 | } |
23026 | 0 | matcher = matcher->next; |
23027 | 0 | } |
23028 | 0 | return(0); |
23029 | | |
23030 | 0 | internal_error: |
23031 | 0 | return(-1); |
23032 | 0 | } |
23033 | | |
23034 | | /** |
23035 | | * Merges IDC bindings of an element at `depth` into the corresponding IDC |
23036 | | * bindings of its parent element. If a duplicate note-table entry is found, |
23037 | | * both, the parent node-table entry and child entry are discarded from the |
23038 | | * node-table of the parent. |
23039 | | * |
23040 | | * @param vctxt the WXS validation context |
23041 | | * @returns 0 if OK and -1 on internal errors. |
23042 | | */ |
23043 | | static int |
23044 | | xmlSchemaBubbleIDCNodeTables(xmlSchemaValidCtxtPtr vctxt) |
23045 | 0 | { |
23046 | 0 | xmlSchemaPSVIIDCBindingPtr bind; /* IDC bindings of the current node. */ |
23047 | 0 | xmlSchemaPSVIIDCBindingPtr *parTable, parBind = NULL; /* parent IDC bindings. */ |
23048 | 0 | xmlSchemaPSVIIDCNodePtr node, parNode = NULL, *dupls, *parNodes; /* node-table entries. */ |
23049 | 0 | xmlSchemaIDCAugPtr aidc; |
23050 | 0 | int i, j, k, ret = 0, nbFields, oldNum, oldDupls; |
23051 | |
|
23052 | 0 | bind = vctxt->inode->idcTable; |
23053 | 0 | if (bind == NULL) { |
23054 | | /* Fine, no table, no bubbles. */ |
23055 | 0 | return (0); |
23056 | 0 | } |
23057 | | |
23058 | 0 | parTable = &(vctxt->elemInfos[vctxt->depth -1]->idcTable); |
23059 | | /* |
23060 | | * Walk all bindings; create new or add to existing bindings. |
23061 | | * Remove duplicate key-sequences. |
23062 | | */ |
23063 | 0 | while (bind != NULL) { |
23064 | |
|
23065 | 0 | if ((bind->nbNodes == 0) && WXS_ILIST_IS_EMPTY(bind->dupls)) |
23066 | 0 | goto next_binding; |
23067 | | /* |
23068 | | * Check if the key/unique IDC table needs to be bubbled. |
23069 | | */ |
23070 | 0 | if (! vctxt->createIDCNodeTables) { |
23071 | 0 | aidc = vctxt->aidcs; |
23072 | 0 | do { |
23073 | 0 | if (aidc->def == bind->definition) { |
23074 | 0 | if ((aidc->keyrefDepth == -1) || |
23075 | 0 | (aidc->keyrefDepth >= vctxt->depth)) { |
23076 | 0 | goto next_binding; |
23077 | 0 | } |
23078 | 0 | break; |
23079 | 0 | } |
23080 | 0 | aidc = aidc->next; |
23081 | 0 | } while (aidc != NULL); |
23082 | 0 | } |
23083 | | |
23084 | 0 | if (parTable != NULL) |
23085 | 0 | parBind = *parTable; |
23086 | | /* |
23087 | | * Search a matching parent binding for the |
23088 | | * IDC definition. |
23089 | | */ |
23090 | 0 | while (parBind != NULL) { |
23091 | 0 | if (parBind->definition == bind->definition) |
23092 | 0 | break; |
23093 | 0 | parBind = parBind->next; |
23094 | 0 | } |
23095 | |
|
23096 | 0 | if (parBind != NULL) { |
23097 | | /* |
23098 | | * Compare every node-table entry of the child node, |
23099 | | * i.e. the key-sequence within, ... |
23100 | | */ |
23101 | 0 | oldNum = parBind->nbNodes; /* Skip newly added items. */ |
23102 | |
|
23103 | 0 | if (! WXS_ILIST_IS_EMPTY(parBind->dupls)) { |
23104 | 0 | oldDupls = parBind->dupls->nbItems; |
23105 | 0 | dupls = (xmlSchemaPSVIIDCNodePtr *) parBind->dupls->items; |
23106 | 0 | } else { |
23107 | 0 | dupls = NULL; |
23108 | 0 | oldDupls = 0; |
23109 | 0 | } |
23110 | |
|
23111 | 0 | parNodes = parBind->nodeTable; |
23112 | 0 | nbFields = bind->definition->nbFields; |
23113 | |
|
23114 | 0 | for (i = 0; i < bind->nbNodes; i++) { |
23115 | 0 | node = bind->nodeTable[i]; |
23116 | 0 | if (node == NULL) |
23117 | 0 | continue; |
23118 | | /* |
23119 | | * ...with every key-sequence of the parent node, already |
23120 | | * evaluated to be a duplicate key-sequence. |
23121 | | */ |
23122 | 0 | if (oldDupls) { |
23123 | 0 | j = 0; |
23124 | 0 | while (j < oldDupls) { |
23125 | 0 | if (nbFields == 1) { |
23126 | 0 | ret = xmlSchemaAreValuesEqual( |
23127 | 0 | node->keys[0]->val, |
23128 | 0 | dupls[j]->keys[0]->val); |
23129 | 0 | if (ret == -1) |
23130 | 0 | goto internal_error; |
23131 | 0 | if (ret == 0) { |
23132 | 0 | j++; |
23133 | 0 | continue; |
23134 | 0 | } |
23135 | 0 | } else { |
23136 | 0 | parNode = dupls[j]; |
23137 | 0 | for (k = 0; k < nbFields; k++) { |
23138 | 0 | ret = xmlSchemaAreValuesEqual( |
23139 | 0 | node->keys[k]->val, |
23140 | 0 | parNode->keys[k]->val); |
23141 | 0 | if (ret == -1) |
23142 | 0 | goto internal_error; |
23143 | 0 | if (ret == 0) |
23144 | 0 | break; |
23145 | 0 | } |
23146 | 0 | } |
23147 | 0 | if (ret == 1) |
23148 | | /* Duplicate found. */ |
23149 | 0 | break; |
23150 | 0 | j++; |
23151 | 0 | } |
23152 | 0 | if (j != oldDupls) { |
23153 | | /* Duplicate found. Skip this entry. */ |
23154 | 0 | continue; |
23155 | 0 | } |
23156 | 0 | } |
23157 | | /* |
23158 | | * ... and with every key-sequence of the parent node. |
23159 | | */ |
23160 | 0 | if (oldNum) { |
23161 | 0 | j = 0; |
23162 | 0 | while (j < oldNum) { |
23163 | 0 | parNode = parNodes[j]; |
23164 | 0 | if (nbFields == 1) { |
23165 | 0 | ret = xmlSchemaAreValuesEqual( |
23166 | 0 | node->keys[0]->val, |
23167 | 0 | parNode->keys[0]->val); |
23168 | 0 | if (ret == -1) |
23169 | 0 | goto internal_error; |
23170 | 0 | if (ret == 0) { |
23171 | 0 | j++; |
23172 | 0 | continue; |
23173 | 0 | } |
23174 | 0 | } else { |
23175 | 0 | for (k = 0; k < nbFields; k++) { |
23176 | 0 | ret = xmlSchemaAreValuesEqual( |
23177 | 0 | node->keys[k]->val, |
23178 | 0 | parNode->keys[k]->val); |
23179 | 0 | if (ret == -1) |
23180 | 0 | goto internal_error; |
23181 | 0 | if (ret == 0) |
23182 | 0 | break; |
23183 | 0 | } |
23184 | 0 | } |
23185 | 0 | if (ret == 1) |
23186 | | /* Duplicate found. */ |
23187 | 0 | break; |
23188 | 0 | j++; |
23189 | 0 | } |
23190 | 0 | if (j != oldNum) { |
23191 | | /* |
23192 | | * Handle duplicates. Move the duplicate in |
23193 | | * the parent's node-table to the list of |
23194 | | * duplicates. |
23195 | | */ |
23196 | 0 | oldNum--; |
23197 | 0 | parBind->nbNodes--; |
23198 | | /* |
23199 | | * Move last old item to pos of duplicate. |
23200 | | */ |
23201 | 0 | parNodes[j] = parNodes[oldNum]; |
23202 | |
|
23203 | 0 | if (parBind->nbNodes != oldNum) { |
23204 | | /* |
23205 | | * If new items exist, move last new item to |
23206 | | * last of old items. |
23207 | | */ |
23208 | 0 | parNodes[oldNum] = |
23209 | 0 | parNodes[parBind->nbNodes]; |
23210 | 0 | } |
23211 | 0 | if (parBind->dupls == NULL) { |
23212 | 0 | parBind->dupls = xmlSchemaItemListCreate(); |
23213 | 0 | if (parBind->dupls == NULL) |
23214 | 0 | goto internal_error; |
23215 | 0 | } |
23216 | 0 | xmlSchemaItemListAdd(parBind->dupls, parNode); |
23217 | 0 | dupls = (xmlSchemaPSVIIDCNodePtr *) |
23218 | 0 | parBind->dupls->items; |
23219 | 0 | } else { |
23220 | | /* |
23221 | | * Add the node-table entry (node and key-sequence) of |
23222 | | * the child node to the node table of the parent node. |
23223 | | */ |
23224 | 0 | if (parBind->nbNodes >= parBind->sizeNodes) { |
23225 | 0 | xmlSchemaPSVIIDCNodePtr *tmp; |
23226 | 0 | int newSize; |
23227 | |
|
23228 | 0 | newSize = xmlGrowCapacity(parBind->sizeNodes, |
23229 | 0 | sizeof(tmp[0]), |
23230 | 0 | 10, XML_MAX_ITEMS); |
23231 | 0 | if (newSize < 0) { |
23232 | 0 | xmlSchemaVErrMemory(vctxt); |
23233 | 0 | goto internal_error; |
23234 | 0 | } |
23235 | 0 | tmp = xmlRealloc(parBind->nodeTable, |
23236 | 0 | newSize * sizeof(tmp[0])); |
23237 | 0 | if (tmp == NULL) { |
23238 | 0 | xmlSchemaVErrMemory(vctxt); |
23239 | 0 | goto internal_error; |
23240 | 0 | } |
23241 | | |
23242 | 0 | parBind->nodeTable = tmp; |
23243 | 0 | parBind->sizeNodes = newSize; |
23244 | 0 | } |
23245 | 0 | parNodes = parBind->nodeTable; |
23246 | | /* |
23247 | | * Append the new node-table entry to the 'new node-table |
23248 | | * entries' section. |
23249 | | */ |
23250 | 0 | parNodes[parBind->nbNodes++] = node; |
23251 | 0 | } |
23252 | |
|
23253 | 0 | } |
23254 | |
|
23255 | 0 | } |
23256 | 0 | } else { |
23257 | | /* |
23258 | | * No binding for the IDC was found: create a new one and |
23259 | | * copy all node-tables. |
23260 | | */ |
23261 | 0 | parBind = xmlSchemaIDCNewBinding(bind->definition); |
23262 | 0 | if (parBind == NULL) |
23263 | 0 | goto internal_error; |
23264 | | |
23265 | | /* |
23266 | | * TODO: Hmm, how to optimize the initial number of |
23267 | | * allocated entries? |
23268 | | */ |
23269 | 0 | if (bind->nbNodes != 0) { |
23270 | | /* |
23271 | | * Add all IDC node-table entries. |
23272 | | */ |
23273 | 0 | if (! vctxt->psviExposeIDCNodeTables) { |
23274 | | /* |
23275 | | * Just move the entries. |
23276 | | * NOTE: this is quite save here, since |
23277 | | * all the keyref lookups have already been |
23278 | | * performed. |
23279 | | */ |
23280 | 0 | parBind->nodeTable = bind->nodeTable; |
23281 | 0 | bind->nodeTable = NULL; |
23282 | 0 | parBind->sizeNodes = bind->sizeNodes; |
23283 | 0 | bind->sizeNodes = 0; |
23284 | 0 | parBind->nbNodes = bind->nbNodes; |
23285 | 0 | bind->nbNodes = 0; |
23286 | 0 | } else { |
23287 | | /* |
23288 | | * Copy the entries. |
23289 | | */ |
23290 | 0 | parBind->nodeTable = (xmlSchemaPSVIIDCNodePtr *) |
23291 | 0 | xmlMalloc(bind->nbNodes * |
23292 | 0 | sizeof(xmlSchemaPSVIIDCNodePtr)); |
23293 | 0 | if (parBind->nodeTable == NULL) { |
23294 | 0 | xmlSchemaVErrMemory(NULL); |
23295 | 0 | xmlSchemaIDCFreeBinding(parBind); |
23296 | 0 | goto internal_error; |
23297 | 0 | } |
23298 | 0 | parBind->sizeNodes = bind->nbNodes; |
23299 | 0 | parBind->nbNodes = bind->nbNodes; |
23300 | 0 | memcpy(parBind->nodeTable, bind->nodeTable, |
23301 | 0 | bind->nbNodes * sizeof(xmlSchemaPSVIIDCNodePtr)); |
23302 | 0 | } |
23303 | 0 | } |
23304 | 0 | if (bind->dupls) { |
23305 | | /* |
23306 | | * Move the duplicates. |
23307 | | */ |
23308 | 0 | if (parBind->dupls != NULL) |
23309 | 0 | xmlSchemaItemListFree(parBind->dupls); |
23310 | 0 | parBind->dupls = bind->dupls; |
23311 | 0 | bind->dupls = NULL; |
23312 | 0 | } |
23313 | 0 | if (parTable != NULL) { |
23314 | 0 | if (*parTable == NULL) |
23315 | 0 | *parTable = parBind; |
23316 | 0 | else { |
23317 | 0 | parBind->next = *parTable; |
23318 | 0 | *parTable = parBind; |
23319 | 0 | } |
23320 | 0 | } |
23321 | 0 | } |
23322 | | |
23323 | 0 | next_binding: |
23324 | 0 | bind = bind->next; |
23325 | 0 | } |
23326 | 0 | return (0); |
23327 | | |
23328 | 0 | internal_error: |
23329 | 0 | return(-1); |
23330 | 0 | } |
23331 | | |
23332 | | /** |
23333 | | * Check the cvc-idc-keyref constraints. |
23334 | | * |
23335 | | * @param vctxt the WXS validation context |
23336 | | */ |
23337 | | static int |
23338 | | xmlSchemaCheckCVCIDCKeyRef(xmlSchemaValidCtxtPtr vctxt) |
23339 | 0 | { |
23340 | 0 | xmlSchemaIDCMatcherPtr matcher; |
23341 | 0 | xmlSchemaPSVIIDCBindingPtr bind; |
23342 | |
|
23343 | 0 | matcher = vctxt->inode->idcMatchers; |
23344 | | /* |
23345 | | * Find a keyref. |
23346 | | */ |
23347 | 0 | while (matcher != NULL) { |
23348 | 0 | if ((matcher->idcType == XML_SCHEMA_TYPE_IDC_KEYREF) && |
23349 | 0 | matcher->targets && |
23350 | 0 | matcher->targets->nbItems) |
23351 | 0 | { |
23352 | 0 | int i, j, k, res, nbFields, hasDupls; |
23353 | 0 | xmlSchemaPSVIIDCKeyPtr *refKeys, *keys; |
23354 | 0 | xmlSchemaPSVIIDCNodePtr refNode = NULL; |
23355 | 0 | xmlHashTablePtr table = NULL; |
23356 | |
|
23357 | 0 | nbFields = matcher->aidc->def->nbFields; |
23358 | | |
23359 | | /* |
23360 | | * Find the IDC node-table for the referenced IDC key/unique. |
23361 | | */ |
23362 | 0 | bind = vctxt->inode->idcTable; |
23363 | 0 | while (bind != NULL) { |
23364 | 0 | if ((xmlSchemaIDCPtr) matcher->aidc->def->ref->item == |
23365 | 0 | bind->definition) |
23366 | 0 | break; |
23367 | 0 | bind = bind->next; |
23368 | 0 | } |
23369 | 0 | hasDupls = (bind && bind->dupls && bind->dupls->nbItems) ? 1 : 0; |
23370 | | /* |
23371 | | * Search for a matching key-sequences. |
23372 | | */ |
23373 | 0 | if (bind) { |
23374 | 0 | table = xmlHashCreate(bind->nbNodes * 2); |
23375 | 0 | for (j = 0; j < bind->nbNodes; j++) { |
23376 | 0 | xmlChar *value; |
23377 | 0 | xmlIDCHashEntryPtr r, e; |
23378 | 0 | keys = bind->nodeTable[j]->keys; |
23379 | 0 | xmlSchemaHashKeySequence(vctxt, &value, keys, nbFields); |
23380 | 0 | e = xmlMalloc(sizeof *e); |
23381 | 0 | if (e == NULL) { |
23382 | 0 | xmlSchemaVErrMemory(vctxt); |
23383 | 0 | goto mem_error; |
23384 | 0 | } |
23385 | 0 | e->index = j; |
23386 | 0 | r = xmlHashLookup(table, value); |
23387 | 0 | if (r) { |
23388 | 0 | e->next = r->next; |
23389 | 0 | r->next = e; |
23390 | 0 | } else { |
23391 | 0 | e->next = NULL; |
23392 | 0 | if (xmlHashAddEntry(table, value, e) < 0) { |
23393 | 0 | xmlSchemaVErrMemory(vctxt); |
23394 | 0 | xmlFree(e); |
23395 | 0 | } |
23396 | 0 | } |
23397 | 0 | mem_error: |
23398 | 0 | FREE_AND_NULL(value); |
23399 | 0 | } |
23400 | 0 | } |
23401 | 0 | for (i = 0; i < matcher->targets->nbItems; i++) { |
23402 | 0 | res = 0; |
23403 | 0 | refNode = matcher->targets->items[i]; |
23404 | 0 | if (bind != NULL) { |
23405 | 0 | xmlChar *value; |
23406 | 0 | xmlIDCHashEntryPtr e; |
23407 | 0 | refKeys = refNode->keys; |
23408 | 0 | xmlSchemaHashKeySequence(vctxt, &value, refKeys, nbFields); |
23409 | 0 | e = xmlHashLookup(table, value); |
23410 | 0 | FREE_AND_NULL(value); |
23411 | 0 | res = 0; |
23412 | 0 | for (;e; e = e->next) { |
23413 | 0 | keys = bind->nodeTable[e->index]->keys; |
23414 | 0 | for (k = 0; k < nbFields; k++) { |
23415 | 0 | res = xmlSchemaAreValuesEqual(keys[k]->val, |
23416 | 0 | refKeys[k]->val); |
23417 | 0 | if (res == 0) |
23418 | 0 | break; |
23419 | 0 | else if (res == -1) { |
23420 | 0 | return (-1); |
23421 | 0 | } |
23422 | 0 | } |
23423 | 0 | if (res == 1) { |
23424 | | /* |
23425 | | * Match found. |
23426 | | */ |
23427 | 0 | break; |
23428 | 0 | } |
23429 | 0 | } |
23430 | 0 | if ((res == 0) && hasDupls) { |
23431 | | /* |
23432 | | * Search in duplicates |
23433 | | */ |
23434 | 0 | for (j = 0; j < bind->dupls->nbItems; j++) { |
23435 | 0 | keys = ((xmlSchemaPSVIIDCNodePtr) |
23436 | 0 | bind->dupls->items[j])->keys; |
23437 | 0 | for (k = 0; k < nbFields; k++) { |
23438 | 0 | res = xmlSchemaAreValuesEqual(keys[k]->val, |
23439 | 0 | refKeys[k]->val); |
23440 | 0 | if (res == 0) |
23441 | 0 | break; |
23442 | 0 | else if (res == -1) { |
23443 | 0 | return (-1); |
23444 | 0 | } |
23445 | 0 | } |
23446 | 0 | if (res == 1) { |
23447 | | /* |
23448 | | * Match in duplicates found. |
23449 | | */ |
23450 | 0 | xmlChar *str = NULL, *strB = NULL; |
23451 | 0 | xmlSchemaKeyrefErr(vctxt, |
23452 | 0 | XML_SCHEMAV_CVC_IDC, refNode, |
23453 | 0 | (xmlSchemaTypePtr) matcher->aidc->def, |
23454 | 0 | "More than one match found for " |
23455 | 0 | "key-sequence %s of keyref '%s'", |
23456 | 0 | xmlSchemaFormatIDCKeySequence(vctxt, &str, |
23457 | 0 | refNode->keys, nbFields), |
23458 | 0 | xmlSchemaGetComponentQName(&strB, |
23459 | 0 | matcher->aidc->def)); |
23460 | 0 | FREE_AND_NULL(str); |
23461 | 0 | FREE_AND_NULL(strB); |
23462 | 0 | break; |
23463 | 0 | } |
23464 | 0 | } |
23465 | 0 | } |
23466 | 0 | } |
23467 | | |
23468 | 0 | if (res == 0) { |
23469 | 0 | xmlChar *str = NULL, *strB = NULL; |
23470 | 0 | xmlSchemaKeyrefErr(vctxt, |
23471 | 0 | XML_SCHEMAV_CVC_IDC, refNode, |
23472 | 0 | (xmlSchemaTypePtr) matcher->aidc->def, |
23473 | 0 | "No match found for key-sequence %s of keyref '%s'", |
23474 | 0 | xmlSchemaFormatIDCKeySequence(vctxt, &str, |
23475 | 0 | refNode->keys, nbFields), |
23476 | 0 | xmlSchemaGetComponentQName(&strB, matcher->aidc->def)); |
23477 | 0 | FREE_AND_NULL(str); |
23478 | 0 | FREE_AND_NULL(strB); |
23479 | 0 | } |
23480 | 0 | } |
23481 | 0 | if (table) { |
23482 | 0 | xmlHashFree(table, xmlFreeIDCHashEntry); |
23483 | 0 | } |
23484 | 0 | } |
23485 | 0 | matcher = matcher->next; |
23486 | 0 | } |
23487 | | /* TODO: Return an error if any error encountered. */ |
23488 | 0 | return (0); |
23489 | 0 | } |
23490 | | |
23491 | | /************************************************************************ |
23492 | | * * |
23493 | | * XML Reader validation code * |
23494 | | * * |
23495 | | ************************************************************************/ |
23496 | | |
23497 | | static xmlSchemaAttrInfoPtr |
23498 | | xmlSchemaGetFreshAttrInfo(xmlSchemaValidCtxtPtr vctxt) |
23499 | 0 | { |
23500 | 0 | xmlSchemaAttrInfoPtr iattr; |
23501 | | /* |
23502 | | * Grow/create list of attribute infos. |
23503 | | */ |
23504 | 0 | if (vctxt->sizeAttrInfos <= vctxt->nbAttrInfos) { |
23505 | 0 | xmlSchemaAttrInfoPtr *tmp; |
23506 | 0 | int oldSize = vctxt->sizeAttrInfos; |
23507 | 0 | int newSize, i; |
23508 | |
|
23509 | 0 | newSize = xmlGrowCapacity(oldSize, sizeof(tmp[0]), 5, XML_MAX_ITEMS); |
23510 | 0 | if (newSize < 0) { |
23511 | 0 | xmlSchemaVErrMemory(vctxt); |
23512 | 0 | return (NULL); |
23513 | 0 | } |
23514 | 0 | tmp = xmlRealloc(vctxt->attrInfos, newSize * sizeof(tmp[0])); |
23515 | 0 | if (tmp == NULL) { |
23516 | 0 | xmlSchemaVErrMemory(vctxt); |
23517 | 0 | return (NULL); |
23518 | 0 | } |
23519 | | |
23520 | 0 | vctxt->attrInfos = tmp; |
23521 | 0 | vctxt->sizeAttrInfos = newSize; |
23522 | |
|
23523 | 0 | for (i = oldSize; i < newSize; i++) |
23524 | 0 | vctxt->attrInfos[i] = NULL; |
23525 | 0 | } |
23526 | | |
23527 | 0 | iattr = vctxt->attrInfos[vctxt->nbAttrInfos]; |
23528 | 0 | if (iattr != NULL) { |
23529 | 0 | if (iattr->localName != NULL) { |
23530 | 0 | VERROR_INT("xmlSchemaGetFreshAttrInfo", |
23531 | 0 | "attr info not cleared"); |
23532 | 0 | return (NULL); |
23533 | 0 | } |
23534 | 0 | iattr->nodeType = XML_ATTRIBUTE_NODE; |
23535 | 0 | vctxt->nbAttrInfos++; |
23536 | 0 | return (iattr); |
23537 | 0 | } |
23538 | | |
23539 | | /* |
23540 | | * Create an attribute info. |
23541 | | */ |
23542 | 0 | iattr = (xmlSchemaAttrInfoPtr) |
23543 | 0 | xmlMalloc(sizeof(xmlSchemaAttrInfo)); |
23544 | 0 | if (iattr == NULL) { |
23545 | 0 | xmlSchemaVErrMemory(vctxt); |
23546 | 0 | return (NULL); |
23547 | 0 | } |
23548 | 0 | memset(iattr, 0, sizeof(xmlSchemaAttrInfo)); |
23549 | 0 | iattr->nodeType = XML_ATTRIBUTE_NODE; |
23550 | 0 | vctxt->attrInfos[vctxt->nbAttrInfos++] = iattr; |
23551 | |
|
23552 | 0 | return (iattr); |
23553 | 0 | } |
23554 | | |
23555 | | static int |
23556 | | xmlSchemaValidatorPushAttribute(xmlSchemaValidCtxtPtr vctxt, |
23557 | | xmlNodePtr attrNode, |
23558 | | int nodeLine, |
23559 | | const xmlChar *localName, |
23560 | | const xmlChar *nsName, |
23561 | | int ownedNames, |
23562 | | xmlChar *value, |
23563 | | int ownedValue) |
23564 | 0 | { |
23565 | 0 | xmlSchemaAttrInfoPtr attr; |
23566 | |
|
23567 | 0 | attr = xmlSchemaGetFreshAttrInfo(vctxt); |
23568 | 0 | if (attr == NULL) { |
23569 | 0 | VERROR_INT("xmlSchemaPushAttribute", |
23570 | 0 | "calling xmlSchemaGetFreshAttrInfo()"); |
23571 | 0 | return (-1); |
23572 | 0 | } |
23573 | 0 | attr->node = attrNode; |
23574 | 0 | attr->nodeLine = nodeLine; |
23575 | 0 | attr->state = XML_SCHEMAS_ATTR_UNKNOWN; |
23576 | 0 | attr->localName = localName; |
23577 | 0 | attr->nsName = nsName; |
23578 | 0 | if (ownedNames) |
23579 | 0 | attr->flags |= XML_SCHEMA_NODE_INFO_FLAG_OWNED_NAMES; |
23580 | | /* |
23581 | | * Evaluate if it's an XSI attribute. |
23582 | | */ |
23583 | 0 | if (nsName != NULL) { |
23584 | 0 | if (xmlStrEqual(localName, BAD_CAST "nil")) { |
23585 | 0 | if (xmlStrEqual(attr->nsName, xmlSchemaInstanceNs)) { |
23586 | 0 | attr->metaType = XML_SCHEMA_ATTR_INFO_META_XSI_NIL; |
23587 | 0 | } |
23588 | 0 | } else if (xmlStrEqual(localName, BAD_CAST "type")) { |
23589 | 0 | if (xmlStrEqual(attr->nsName, xmlSchemaInstanceNs)) { |
23590 | 0 | attr->metaType = XML_SCHEMA_ATTR_INFO_META_XSI_TYPE; |
23591 | 0 | } |
23592 | 0 | } else if (xmlStrEqual(localName, BAD_CAST "schemaLocation")) { |
23593 | 0 | if (xmlStrEqual(attr->nsName, xmlSchemaInstanceNs)) { |
23594 | 0 | attr->metaType = XML_SCHEMA_ATTR_INFO_META_XSI_SCHEMA_LOC; |
23595 | 0 | } |
23596 | 0 | } else if (xmlStrEqual(localName, BAD_CAST "noNamespaceSchemaLocation")) { |
23597 | 0 | if (xmlStrEqual(attr->nsName, xmlSchemaInstanceNs)) { |
23598 | 0 | attr->metaType = XML_SCHEMA_ATTR_INFO_META_XSI_NO_NS_SCHEMA_LOC; |
23599 | 0 | } |
23600 | 0 | } else if (xmlStrEqual(attr->nsName, xmlNamespaceNs)) { |
23601 | 0 | attr->metaType = XML_SCHEMA_ATTR_INFO_META_XMLNS; |
23602 | 0 | } |
23603 | 0 | } |
23604 | 0 | attr->value = value; |
23605 | 0 | if (ownedValue) |
23606 | 0 | attr->flags |= XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES; |
23607 | 0 | if (attr->metaType != 0) |
23608 | 0 | attr->state = XML_SCHEMAS_ATTR_META; |
23609 | 0 | return (0); |
23610 | 0 | } |
23611 | | |
23612 | | /** |
23613 | | * @param vctxt the WXS validation context |
23614 | | * @param ielem the element information item |
23615 | | */ |
23616 | | static void |
23617 | | xmlSchemaClearElemInfo(xmlSchemaValidCtxtPtr vctxt, |
23618 | | xmlSchemaNodeInfoPtr ielem) |
23619 | 0 | { |
23620 | 0 | ielem->hasKeyrefs = 0; |
23621 | 0 | ielem->appliedXPath = 0; |
23622 | 0 | if (ielem->flags & XML_SCHEMA_NODE_INFO_FLAG_OWNED_NAMES) { |
23623 | 0 | FREE_AND_NULL(ielem->localName); |
23624 | 0 | FREE_AND_NULL(ielem->nsName); |
23625 | 0 | } else { |
23626 | 0 | ielem->localName = NULL; |
23627 | 0 | ielem->nsName = NULL; |
23628 | 0 | } |
23629 | 0 | if (ielem->flags & XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES) { |
23630 | 0 | FREE_AND_NULL(ielem->value); |
23631 | 0 | } else { |
23632 | 0 | ielem->value = NULL; |
23633 | 0 | } |
23634 | 0 | if (ielem->val != NULL) { |
23635 | | /* |
23636 | | * PSVI TODO: Be careful not to free it when the value is |
23637 | | * exposed via PSVI. |
23638 | | */ |
23639 | 0 | xmlSchemaFreeValue(ielem->val); |
23640 | 0 | ielem->val = NULL; |
23641 | 0 | } |
23642 | 0 | if (ielem->idcMatchers != NULL) { |
23643 | | /* |
23644 | | * REVISIT OPTIMIZE TODO: Use a pool of IDC matchers. |
23645 | | * Does it work? |
23646 | | */ |
23647 | 0 | xmlSchemaIDCReleaseMatcherList(vctxt, ielem->idcMatchers); |
23648 | | #if 0 |
23649 | | xmlSchemaIDCFreeMatcherList(ielem->idcMatchers); |
23650 | | #endif |
23651 | 0 | ielem->idcMatchers = NULL; |
23652 | 0 | } |
23653 | 0 | if (ielem->idcTable != NULL) { |
23654 | | /* |
23655 | | * OPTIMIZE TODO: Use a pool of IDC tables??. |
23656 | | */ |
23657 | 0 | xmlSchemaIDCFreeIDCTable(ielem->idcTable); |
23658 | 0 | ielem->idcTable = NULL; |
23659 | 0 | } |
23660 | 0 | if (ielem->regexCtxt != NULL) { |
23661 | 0 | xmlRegFreeExecCtxt(ielem->regexCtxt); |
23662 | 0 | ielem->regexCtxt = NULL; |
23663 | 0 | } |
23664 | 0 | if (ielem->nsBindings != NULL) { |
23665 | 0 | xmlFree((xmlChar **)ielem->nsBindings); |
23666 | 0 | ielem->nsBindings = NULL; |
23667 | 0 | ielem->nbNsBindings = 0; |
23668 | 0 | ielem->sizeNsBindings = 0; |
23669 | 0 | } |
23670 | 0 | } |
23671 | | |
23672 | | /** |
23673 | | * Creates/reuses and initializes the element info item for |
23674 | | * the current tree depth. |
23675 | | * |
23676 | | * @param vctxt the schema validation context |
23677 | | * @returns the element info item or NULL on API or internal errors. |
23678 | | */ |
23679 | | static xmlSchemaNodeInfoPtr |
23680 | | xmlSchemaGetFreshElemInfo(xmlSchemaValidCtxtPtr vctxt) |
23681 | 0 | { |
23682 | 0 | xmlSchemaNodeInfoPtr info = NULL; |
23683 | |
|
23684 | 0 | if (vctxt->depth > vctxt->sizeElemInfos) { |
23685 | 0 | VERROR_INT("xmlSchemaGetFreshElemInfo", |
23686 | 0 | "inconsistent depth encountered"); |
23687 | 0 | return (NULL); |
23688 | 0 | } |
23689 | 0 | if (vctxt->sizeElemInfos <= vctxt->depth) { |
23690 | 0 | xmlSchemaNodeInfoPtr *tmp; |
23691 | 0 | int oldSize = vctxt->sizeElemInfos; |
23692 | 0 | int newSize, i; |
23693 | |
|
23694 | 0 | newSize = xmlGrowCapacity(oldSize, sizeof(tmp[0]), 10, XML_MAX_ITEMS); |
23695 | 0 | if (newSize < 0) { |
23696 | 0 | xmlSchemaVErrMemory(vctxt); |
23697 | 0 | return (NULL); |
23698 | 0 | } |
23699 | 0 | tmp = xmlRealloc(vctxt->elemInfos, newSize * sizeof(tmp[0])); |
23700 | 0 | if (tmp == NULL) { |
23701 | 0 | xmlSchemaVErrMemory(vctxt); |
23702 | 0 | return (NULL); |
23703 | 0 | } |
23704 | | |
23705 | 0 | vctxt->elemInfos = tmp; |
23706 | 0 | vctxt->sizeElemInfos = newSize; |
23707 | | |
23708 | | /* |
23709 | | * We need the new memory to be NULLed. |
23710 | | * TODO: Use memset instead? |
23711 | | */ |
23712 | 0 | for (i = oldSize; i < newSize; i++) |
23713 | 0 | vctxt->elemInfos[i] = NULL; |
23714 | 0 | } else |
23715 | 0 | info = vctxt->elemInfos[vctxt->depth]; |
23716 | | |
23717 | 0 | if (info == NULL) { |
23718 | 0 | info = (xmlSchemaNodeInfoPtr) |
23719 | 0 | xmlMalloc(sizeof(xmlSchemaNodeInfo)); |
23720 | 0 | if (info == NULL) { |
23721 | 0 | xmlSchemaVErrMemory(vctxt); |
23722 | 0 | return (NULL); |
23723 | 0 | } |
23724 | 0 | vctxt->elemInfos[vctxt->depth] = info; |
23725 | 0 | } else { |
23726 | 0 | if (info->localName != NULL) { |
23727 | 0 | VERROR_INT("xmlSchemaGetFreshElemInfo", |
23728 | 0 | "elem info has not been cleared"); |
23729 | 0 | return (NULL); |
23730 | 0 | } |
23731 | 0 | } |
23732 | 0 | memset(info, 0, sizeof(xmlSchemaNodeInfo)); |
23733 | 0 | info->nodeType = XML_ELEMENT_NODE; |
23734 | 0 | info->depth = vctxt->depth; |
23735 | |
|
23736 | 0 | return (info); |
23737 | 0 | } |
23738 | | |
23739 | 0 | #define ACTIVATE_ATTRIBUTE(item) vctxt->inode = (xmlSchemaNodeInfoPtr) item; |
23740 | 0 | #define ACTIVATE_ELEM vctxt->inode = vctxt->elemInfos[vctxt->depth]; |
23741 | 0 | #define ACTIVATE_PARENT_ELEM vctxt->inode = vctxt->elemInfos[vctxt->depth -1]; |
23742 | | |
23743 | | static int |
23744 | | xmlSchemaValidateFacets(xmlSchemaAbstractCtxtPtr actxt, |
23745 | | xmlNodePtr node, |
23746 | | xmlSchemaTypePtr type, |
23747 | | xmlSchemaValType valType, |
23748 | | const xmlChar * value, |
23749 | | xmlSchemaValPtr val, |
23750 | | unsigned long length, |
23751 | | int fireErrors) |
23752 | 0 | { |
23753 | 0 | int ret, error = 0, found; |
23754 | |
|
23755 | 0 | xmlSchemaTypePtr tmpType; |
23756 | 0 | xmlSchemaFacetLinkPtr facetLink; |
23757 | 0 | xmlSchemaFacetPtr facet; |
23758 | 0 | unsigned long len = 0; |
23759 | 0 | xmlSchemaWhitespaceValueType ws; |
23760 | | |
23761 | | /* |
23762 | | * In Libxml2, derived built-in types have currently no explicit facets. |
23763 | | */ |
23764 | 0 | if (type->type == XML_SCHEMA_TYPE_BASIC) |
23765 | 0 | return (0); |
23766 | | |
23767 | | /* |
23768 | | * NOTE: Do not jump away, if the facetSet of the given type is |
23769 | | * empty: until now, "pattern" and "enumeration" facets of the |
23770 | | * *base types* need to be checked as well. |
23771 | | */ |
23772 | 0 | if (type->facetSet == NULL) |
23773 | 0 | goto pattern_and_enum; |
23774 | | |
23775 | 0 | if (! WXS_IS_ATOMIC(type)) { |
23776 | 0 | if (WXS_IS_LIST(type)) |
23777 | 0 | goto WXS_IS_LIST; |
23778 | 0 | else |
23779 | 0 | goto pattern_and_enum; |
23780 | 0 | } |
23781 | | |
23782 | | /* |
23783 | | * Whitespace handling is only of importance for string-based |
23784 | | * types. |
23785 | | */ |
23786 | 0 | tmpType = xmlSchemaGetPrimitiveType(type); |
23787 | 0 | if ((tmpType->builtInType == XML_SCHEMAS_STRING) || |
23788 | 0 | WXS_IS_ANY_SIMPLE_TYPE(tmpType)) { |
23789 | 0 | ws = xmlSchemaGetWhiteSpaceFacetValue(type); |
23790 | 0 | } else |
23791 | 0 | ws = XML_SCHEMA_WHITESPACE_COLLAPSE; |
23792 | | |
23793 | | /* |
23794 | | * If the value was not computed (for string or |
23795 | | * anySimpleType based types), then use the provided |
23796 | | * type. |
23797 | | */ |
23798 | 0 | if (val != NULL) |
23799 | 0 | valType = xmlSchemaGetValType(val); |
23800 | |
|
23801 | 0 | ret = 0; |
23802 | 0 | for (facetLink = type->facetSet; facetLink != NULL; |
23803 | 0 | facetLink = facetLink->next) { |
23804 | | /* |
23805 | | * Skip the pattern "whiteSpace": it is used to |
23806 | | * format the character content beforehand. |
23807 | | */ |
23808 | 0 | switch (facetLink->facet->type) { |
23809 | 0 | case XML_SCHEMA_FACET_WHITESPACE: |
23810 | 0 | case XML_SCHEMA_FACET_PATTERN: |
23811 | 0 | case XML_SCHEMA_FACET_ENUMERATION: |
23812 | 0 | continue; |
23813 | 0 | case XML_SCHEMA_FACET_LENGTH: |
23814 | 0 | case XML_SCHEMA_FACET_MINLENGTH: |
23815 | 0 | case XML_SCHEMA_FACET_MAXLENGTH: |
23816 | 0 | ret = xmlSchemaValidateLengthFacetWhtsp(facetLink->facet, |
23817 | 0 | valType, value, val, &len, ws); |
23818 | 0 | break; |
23819 | 0 | default: |
23820 | 0 | ret = xmlSchemaValidateFacetWhtsp(facetLink->facet, ws, |
23821 | 0 | valType, value, val, ws); |
23822 | 0 | break; |
23823 | 0 | } |
23824 | 0 | if (ret < 0) { |
23825 | 0 | AERROR_INT("xmlSchemaValidateFacets", |
23826 | 0 | "validating against a atomic type facet"); |
23827 | 0 | return (-1); |
23828 | 0 | } else if (ret > 0) { |
23829 | 0 | if (fireErrors) |
23830 | 0 | xmlSchemaFacetErr(actxt, ret, node, |
23831 | 0 | value, len, type, facetLink->facet, NULL, NULL, NULL); |
23832 | 0 | else |
23833 | 0 | return (ret); |
23834 | 0 | if (error == 0) |
23835 | 0 | error = ret; |
23836 | 0 | } |
23837 | 0 | ret = 0; |
23838 | 0 | } |
23839 | | |
23840 | 0 | WXS_IS_LIST: |
23841 | 0 | if (! WXS_IS_LIST(type)) |
23842 | 0 | goto pattern_and_enum; |
23843 | | /* |
23844 | | * "length", "minLength" and "maxLength" of list types. |
23845 | | */ |
23846 | 0 | ret = 0; |
23847 | 0 | for (facetLink = type->facetSet; facetLink != NULL; |
23848 | 0 | facetLink = facetLink->next) { |
23849 | |
|
23850 | 0 | switch (facetLink->facet->type) { |
23851 | 0 | case XML_SCHEMA_FACET_LENGTH: |
23852 | 0 | case XML_SCHEMA_FACET_MINLENGTH: |
23853 | 0 | case XML_SCHEMA_FACET_MAXLENGTH: |
23854 | 0 | ret = xmlSchemaValidateListSimpleTypeFacet(facetLink->facet, |
23855 | 0 | value, length, NULL); |
23856 | 0 | break; |
23857 | 0 | default: |
23858 | 0 | continue; |
23859 | 0 | } |
23860 | 0 | if (ret < 0) { |
23861 | 0 | AERROR_INT("xmlSchemaValidateFacets", |
23862 | 0 | "validating against a list type facet"); |
23863 | 0 | return (-1); |
23864 | 0 | } else if (ret > 0) { |
23865 | 0 | if (fireErrors) |
23866 | 0 | xmlSchemaFacetErr(actxt, ret, node, |
23867 | 0 | value, length, type, facetLink->facet, NULL, NULL, NULL); |
23868 | 0 | else |
23869 | 0 | return (ret); |
23870 | 0 | if (error == 0) |
23871 | 0 | error = ret; |
23872 | 0 | } |
23873 | 0 | ret = 0; |
23874 | 0 | } |
23875 | | |
23876 | 0 | pattern_and_enum: |
23877 | 0 | found = 0; |
23878 | | /* |
23879 | | * Process enumerations. Facet values are in the value space |
23880 | | * of the defining type's base type. This seems to be a bug in the |
23881 | | * XML Schema 1.0 spec. Use the whitespace type of the base type. |
23882 | | * Only the first set of enumerations in the ancestor-or-self axis |
23883 | | * is used for validation. |
23884 | | */ |
23885 | 0 | ret = 0; |
23886 | 0 | tmpType = type; |
23887 | 0 | do { |
23888 | 0 | for (facet = tmpType->facets; facet != NULL; facet = facet->next) { |
23889 | 0 | if (facet->type != XML_SCHEMA_FACET_ENUMERATION) |
23890 | 0 | continue; |
23891 | 0 | found = 1; |
23892 | 0 | ret = xmlSchemaAreValuesEqual(facet->val, val); |
23893 | 0 | if (ret == 1) |
23894 | 0 | break; |
23895 | 0 | else if (ret < 0) { |
23896 | 0 | AERROR_INT("xmlSchemaValidateFacets", |
23897 | 0 | "validating against an enumeration facet"); |
23898 | 0 | return (-1); |
23899 | 0 | } |
23900 | 0 | } |
23901 | 0 | if (ret != 0) |
23902 | 0 | break; |
23903 | | /* |
23904 | | * Break on the first set of enumerations. Any additional |
23905 | | * enumerations which might be existent on the ancestors |
23906 | | * of the current type are restricted by this set; thus |
23907 | | * *must* *not* be taken into account. |
23908 | | */ |
23909 | 0 | if (found) |
23910 | 0 | break; |
23911 | 0 | tmpType = tmpType->baseType; |
23912 | 0 | } while ((tmpType != NULL) && |
23913 | 0 | (tmpType->type != XML_SCHEMA_TYPE_BASIC)); |
23914 | 0 | if (found && (ret == 0)) { |
23915 | 0 | ret = XML_SCHEMAV_CVC_ENUMERATION_VALID; |
23916 | 0 | if (fireErrors) { |
23917 | 0 | xmlSchemaFacetErr(actxt, ret, node, |
23918 | 0 | value, 0, type, NULL, NULL, NULL, NULL); |
23919 | 0 | } else |
23920 | 0 | return (ret); |
23921 | 0 | if (error == 0) |
23922 | 0 | error = ret; |
23923 | 0 | } |
23924 | | |
23925 | | /* |
23926 | | * Process patters. Pattern facets are ORed at type level |
23927 | | * and ANDed if derived. Walk the base type axis. |
23928 | | */ |
23929 | 0 | tmpType = type; |
23930 | 0 | facet = NULL; |
23931 | 0 | do { |
23932 | 0 | found = 0; |
23933 | 0 | for (facetLink = tmpType->facetSet; facetLink != NULL; |
23934 | 0 | facetLink = facetLink->next) { |
23935 | 0 | if (facetLink->facet->type != XML_SCHEMA_FACET_PATTERN) |
23936 | 0 | continue; |
23937 | 0 | found = 1; |
23938 | | /* |
23939 | | * NOTE that for patterns, @value needs to be the |
23940 | | * normalized value. |
23941 | | */ |
23942 | 0 | ret = xmlRegexpExec(facetLink->facet->regexp, value); |
23943 | 0 | if (ret == 1) |
23944 | 0 | break; |
23945 | 0 | else if (ret < 0) { |
23946 | 0 | AERROR_INT("xmlSchemaValidateFacets", |
23947 | 0 | "validating against a pattern facet"); |
23948 | 0 | return (-1); |
23949 | 0 | } else { |
23950 | | /* |
23951 | | * Save the last non-validating facet. |
23952 | | */ |
23953 | 0 | facet = facetLink->facet; |
23954 | 0 | } |
23955 | 0 | } |
23956 | 0 | if (found && (ret != 1)) { |
23957 | 0 | ret = XML_SCHEMAV_CVC_PATTERN_VALID; |
23958 | 0 | if (fireErrors) { |
23959 | 0 | xmlSchemaFacetErr(actxt, ret, node, |
23960 | 0 | value, 0, type, facet, NULL, NULL, NULL); |
23961 | 0 | } else |
23962 | 0 | return (ret); |
23963 | 0 | if (error == 0) |
23964 | 0 | error = ret; |
23965 | 0 | break; |
23966 | 0 | } |
23967 | 0 | tmpType = tmpType->baseType; |
23968 | 0 | } while ((tmpType != NULL) && (tmpType->type != XML_SCHEMA_TYPE_BASIC)); |
23969 | | |
23970 | 0 | return (error); |
23971 | 0 | } |
23972 | | |
23973 | | static xmlChar * |
23974 | | xmlSchemaNormalizeValue(xmlSchemaTypePtr type, |
23975 | | const xmlChar *value) |
23976 | 0 | { |
23977 | 0 | switch (xmlSchemaGetWhiteSpaceFacetValue(type)) { |
23978 | 0 | case XML_SCHEMA_WHITESPACE_COLLAPSE: |
23979 | 0 | return (xmlSchemaCollapseString(value)); |
23980 | 0 | case XML_SCHEMA_WHITESPACE_REPLACE: |
23981 | 0 | return (xmlSchemaWhiteSpaceReplace(value)); |
23982 | 0 | default: |
23983 | 0 | return (NULL); |
23984 | 0 | } |
23985 | 0 | } |
23986 | | |
23987 | | static int |
23988 | | xmlSchemaValidateQName(xmlSchemaValidCtxtPtr vctxt, |
23989 | | const xmlChar *value, |
23990 | | xmlSchemaValPtr *val, |
23991 | | int valNeeded) |
23992 | 0 | { |
23993 | 0 | int ret; |
23994 | 0 | xmlChar *stripped; |
23995 | 0 | const xmlChar *nsName; |
23996 | 0 | xmlChar *local, *prefix = NULL; |
23997 | |
|
23998 | 0 | ret = xmlValidateQName(value, 1); |
23999 | 0 | if (ret != 0) { |
24000 | 0 | if (ret == -1) { |
24001 | 0 | VERROR_INT("xmlSchemaValidateQName", |
24002 | 0 | "calling xmlValidateQName()"); |
24003 | 0 | return (-1); |
24004 | 0 | } |
24005 | 0 | return( XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1); |
24006 | 0 | } |
24007 | | /* |
24008 | | * NOTE: xmlSplitQName2 will always return a duplicated |
24009 | | * strings. |
24010 | | */ |
24011 | | /* TODO: Export and use xmlSchemaStrip instead */ |
24012 | 0 | stripped = xmlSchemaCollapseString(value); |
24013 | 0 | local = xmlSplitQName2(stripped ? stripped : value, &prefix); |
24014 | 0 | xmlFree(stripped); |
24015 | 0 | if (local == NULL) |
24016 | 0 | local = xmlStrdup(value); |
24017 | | /* |
24018 | | * OPTIMIZE TODO: Use flags for: |
24019 | | * - is there any namespace binding? |
24020 | | * - is there a default namespace? |
24021 | | */ |
24022 | 0 | nsName = xmlSchemaLookupNamespace(vctxt, prefix); |
24023 | |
|
24024 | 0 | if (prefix != NULL) { |
24025 | 0 | xmlFree(prefix); |
24026 | | /* |
24027 | | * A namespace must be found if the prefix is |
24028 | | * NOT NULL. |
24029 | | */ |
24030 | 0 | if (nsName == NULL) { |
24031 | 0 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1; |
24032 | 0 | xmlSchemaCustomErr(ACTXT_CAST vctxt, ret, NULL, |
24033 | 0 | WXS_BASIC_CAST xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), |
24034 | 0 | "The QName value '%s' has no " |
24035 | 0 | "corresponding namespace declaration in " |
24036 | 0 | "scope", value, NULL); |
24037 | 0 | if (local != NULL) |
24038 | 0 | xmlFree(local); |
24039 | 0 | return (ret); |
24040 | 0 | } |
24041 | 0 | } |
24042 | 0 | if (valNeeded && val) { |
24043 | 0 | if (nsName != NULL) |
24044 | 0 | *val = xmlSchemaNewQNameValue( |
24045 | 0 | BAD_CAST xmlStrdup(nsName), BAD_CAST local); |
24046 | 0 | else |
24047 | 0 | *val = xmlSchemaNewQNameValue(NULL, |
24048 | 0 | BAD_CAST local); |
24049 | 0 | } else |
24050 | 0 | xmlFree(local); |
24051 | 0 | return (0); |
24052 | 0 | } |
24053 | | |
24054 | | /* |
24055 | | * cvc-simple-type |
24056 | | */ |
24057 | | static int |
24058 | | xmlSchemaVCheckCVCSimpleType(xmlSchemaAbstractCtxtPtr actxt, |
24059 | | xmlNodePtr node, |
24060 | | xmlSchemaTypePtr type, |
24061 | | const xmlChar *value, |
24062 | | xmlSchemaValPtr *retVal, |
24063 | | int fireErrors, |
24064 | | int normalize, |
24065 | | int isNormalized) |
24066 | 0 | { |
24067 | 0 | int ret = 0, valNeeded = (retVal) ? 1 : 0; |
24068 | 0 | xmlSchemaValPtr val = NULL; |
24069 | | /* xmlSchemaWhitespaceValueType ws; */ |
24070 | 0 | xmlChar *normValue = NULL; |
24071 | |
|
24072 | 0 | #define NORMALIZE(atype) \ |
24073 | 0 | if ((! isNormalized) && \ |
24074 | 0 | (normalize || (type->flags & XML_SCHEMAS_TYPE_NORMVALUENEEDED))) { \ |
24075 | 0 | normValue = xmlSchemaNormalizeValue(atype, value); \ |
24076 | 0 | if (normValue != NULL) \ |
24077 | 0 | value = normValue; \ |
24078 | 0 | isNormalized = 1; \ |
24079 | 0 | } |
24080 | |
|
24081 | 0 | if ((retVal != NULL) && (*retVal != NULL)) { |
24082 | 0 | xmlSchemaFreeValue(*retVal); |
24083 | 0 | *retVal = NULL; |
24084 | 0 | } |
24085 | | /* |
24086 | | * 3.14.4 Simple Type Definition Validation Rules |
24087 | | * Validation Rule: String Valid |
24088 | | */ |
24089 | | /* |
24090 | | * 1 It is schema-valid with respect to that definition as defined |
24091 | | * by Datatype Valid in [XML Schemas: Datatypes]. |
24092 | | */ |
24093 | | /* |
24094 | | * 2.1 If The definition is ENTITY or is validly derived from ENTITY given |
24095 | | * the empty set, as defined in Type Derivation OK (Simple) ($3.14.6), then |
24096 | | * the string must be a `declared entity name`. |
24097 | | */ |
24098 | | /* |
24099 | | * 2.2 If The definition is ENTITIES or is validly derived from ENTITIES |
24100 | | * given the empty set, as defined in Type Derivation OK (Simple) ($3.14.6), |
24101 | | * then every whitespace-delimited substring of the string must be a `declared |
24102 | | * entity name`. |
24103 | | */ |
24104 | | /* |
24105 | | * 2.3 otherwise no further condition applies. |
24106 | | */ |
24107 | 0 | if ((! valNeeded) && (type->flags & XML_SCHEMAS_TYPE_FACETSNEEDVALUE)) |
24108 | 0 | valNeeded = 1; |
24109 | 0 | if (value == NULL) |
24110 | 0 | value = BAD_CAST ""; |
24111 | 0 | if (WXS_IS_ANY_SIMPLE_TYPE(type) || WXS_IS_ATOMIC(type)) { |
24112 | 0 | xmlSchemaTypePtr biType; /* The built-in type. */ |
24113 | | /* |
24114 | | * SPEC (1.2.1) "if {variety} is `atomic` then the string must `match` |
24115 | | * a literal in the `lexical space` of {base type definition}" |
24116 | | */ |
24117 | | /* |
24118 | | * Whitespace-normalize. |
24119 | | */ |
24120 | 0 | NORMALIZE(type); |
24121 | 0 | if (type->type != XML_SCHEMA_TYPE_BASIC) { |
24122 | | /* |
24123 | | * Get the built-in type. |
24124 | | */ |
24125 | 0 | biType = type->baseType; |
24126 | 0 | while ((biType != NULL) && |
24127 | 0 | (biType->type != XML_SCHEMA_TYPE_BASIC)) |
24128 | 0 | biType = biType->baseType; |
24129 | |
|
24130 | 0 | if (biType == NULL) { |
24131 | 0 | AERROR_INT("xmlSchemaVCheckCVCSimpleType", |
24132 | 0 | "could not get the built-in type"); |
24133 | 0 | goto internal_error; |
24134 | 0 | } |
24135 | 0 | } else |
24136 | 0 | biType = type; |
24137 | | /* |
24138 | | * NOTATIONs need to be processed here, since they need |
24139 | | * to lookup in the hashtable of NOTATION declarations of the schema. |
24140 | | */ |
24141 | 0 | if (actxt->type == XML_SCHEMA_CTXT_VALIDATOR) { |
24142 | 0 | switch (biType->builtInType) { |
24143 | 0 | case XML_SCHEMAS_NOTATION: |
24144 | 0 | ret = xmlSchemaValidateNotation( |
24145 | 0 | (xmlSchemaValidCtxtPtr) actxt, |
24146 | 0 | ((xmlSchemaValidCtxtPtr) actxt)->schema, |
24147 | 0 | NULL, value, &val, valNeeded); |
24148 | 0 | break; |
24149 | 0 | case XML_SCHEMAS_QNAME: |
24150 | 0 | ret = xmlSchemaValidateQName((xmlSchemaValidCtxtPtr) actxt, |
24151 | 0 | value, &val, valNeeded); |
24152 | 0 | break; |
24153 | 0 | default: |
24154 | | /* ws = xmlSchemaGetWhiteSpaceFacetValue(type); */ |
24155 | 0 | if (valNeeded) |
24156 | 0 | ret = xmlSchemaValPredefTypeNodeNoNorm(biType, |
24157 | 0 | value, &val, node); |
24158 | 0 | else |
24159 | 0 | ret = xmlSchemaValPredefTypeNodeNoNorm(biType, |
24160 | 0 | value, NULL, node); |
24161 | 0 | break; |
24162 | 0 | } |
24163 | 0 | } else if (actxt->type == XML_SCHEMA_CTXT_PARSER) { |
24164 | 0 | switch (biType->builtInType) { |
24165 | 0 | case XML_SCHEMAS_NOTATION: |
24166 | 0 | ret = xmlSchemaValidateNotation(NULL, |
24167 | 0 | ((xmlSchemaParserCtxtPtr) actxt)->schema, node, |
24168 | 0 | value, &val, valNeeded); |
24169 | 0 | break; |
24170 | 0 | default: |
24171 | | /* ws = xmlSchemaGetWhiteSpaceFacetValue(type); */ |
24172 | 0 | if (valNeeded) |
24173 | 0 | ret = xmlSchemaValPredefTypeNodeNoNorm(biType, |
24174 | 0 | value, &val, node); |
24175 | 0 | else |
24176 | 0 | ret = xmlSchemaValPredefTypeNodeNoNorm(biType, |
24177 | 0 | value, NULL, node); |
24178 | 0 | break; |
24179 | 0 | } |
24180 | 0 | } else { |
24181 | | /* |
24182 | | * Validation via a public API is not implemented yet. |
24183 | | */ |
24184 | 0 | goto internal_error; |
24185 | 0 | } |
24186 | 0 | if (ret != 0) { |
24187 | 0 | if (ret < 0) { |
24188 | 0 | AERROR_INT("xmlSchemaVCheckCVCSimpleType", |
24189 | 0 | "validating against a built-in type"); |
24190 | 0 | goto internal_error; |
24191 | 0 | } |
24192 | 0 | if (WXS_IS_LIST(type)) |
24193 | 0 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2; |
24194 | 0 | else |
24195 | 0 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1; |
24196 | 0 | } |
24197 | 0 | if ((ret == 0) && (type->flags & XML_SCHEMAS_TYPE_HAS_FACETS)) { |
24198 | | /* |
24199 | | * Check facets. |
24200 | | */ |
24201 | 0 | ret = xmlSchemaValidateFacets(actxt, node, type, |
24202 | 0 | (xmlSchemaValType) biType->builtInType, value, val, |
24203 | 0 | 0, fireErrors); |
24204 | 0 | if (ret != 0) { |
24205 | 0 | if (ret < 0) { |
24206 | 0 | AERROR_INT("xmlSchemaVCheckCVCSimpleType", |
24207 | 0 | "validating facets of atomic simple type"); |
24208 | 0 | goto internal_error; |
24209 | 0 | } |
24210 | 0 | if (WXS_IS_LIST(type)) |
24211 | 0 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2; |
24212 | 0 | else |
24213 | 0 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1; |
24214 | 0 | } |
24215 | 0 | } |
24216 | 0 | else if (fireErrors && (ret > 0)) |
24217 | 0 | xmlSchemaSimpleTypeErr(actxt, ret, node, value, type, 1); |
24218 | 0 | } else if (WXS_IS_LIST(type)) { |
24219 | |
|
24220 | 0 | xmlSchemaTypePtr itemType; |
24221 | 0 | const xmlChar *cur, *end; |
24222 | 0 | xmlChar *tmpValue = NULL; |
24223 | 0 | unsigned long len = 0; |
24224 | 0 | xmlSchemaValPtr prevVal = NULL, curVal = NULL; |
24225 | | /* 1.2.2 if {variety} is `list` then the string must be a sequence |
24226 | | * of white space separated tokens, each of which `match`es a literal |
24227 | | * in the `lexical space` of {item type definition} |
24228 | | */ |
24229 | | /* |
24230 | | * Note that XML_SCHEMAS_TYPE_NORMVALUENEEDED will be set if |
24231 | | * the list type has an enum or pattern facet. |
24232 | | */ |
24233 | 0 | NORMALIZE(type); |
24234 | | /* |
24235 | | * VAL TODO: Optimize validation of empty values. |
24236 | | * VAL TODO: We do not have computed values for lists. |
24237 | | */ |
24238 | 0 | itemType = WXS_LIST_ITEMTYPE(type); |
24239 | 0 | cur = value; |
24240 | 0 | do { |
24241 | 0 | while (IS_BLANK_CH(*cur)) |
24242 | 0 | cur++; |
24243 | 0 | end = cur; |
24244 | 0 | while ((*end != 0) && (!(IS_BLANK_CH(*end)))) |
24245 | 0 | end++; |
24246 | 0 | if (end == cur) |
24247 | 0 | break; |
24248 | 0 | tmpValue = xmlStrndup(cur, end - cur); |
24249 | 0 | len++; |
24250 | |
|
24251 | 0 | if (valNeeded) |
24252 | 0 | ret = xmlSchemaVCheckCVCSimpleType(actxt, node, itemType, |
24253 | 0 | tmpValue, &curVal, fireErrors, 0, 1); |
24254 | 0 | else |
24255 | 0 | ret = xmlSchemaVCheckCVCSimpleType(actxt, node, itemType, |
24256 | 0 | tmpValue, NULL, fireErrors, 0, 1); |
24257 | 0 | FREE_AND_NULL(tmpValue); |
24258 | 0 | if (curVal != NULL) { |
24259 | | /* |
24260 | | * Add to list of computed values. |
24261 | | */ |
24262 | 0 | if (val == NULL) |
24263 | 0 | val = curVal; |
24264 | 0 | else |
24265 | 0 | xmlSchemaValueAppend(prevVal, curVal); |
24266 | 0 | prevVal = curVal; |
24267 | 0 | curVal = NULL; |
24268 | 0 | } |
24269 | 0 | if (ret != 0) { |
24270 | 0 | if (ret < 0) { |
24271 | 0 | AERROR_INT("xmlSchemaVCheckCVCSimpleType", |
24272 | 0 | "validating an item of list simple type"); |
24273 | 0 | goto internal_error; |
24274 | 0 | } |
24275 | 0 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2; |
24276 | 0 | break; |
24277 | 0 | } |
24278 | 0 | cur = end; |
24279 | 0 | } while (*cur != 0); |
24280 | 0 | FREE_AND_NULL(tmpValue); |
24281 | 0 | if ((ret == 0) && (type->flags & XML_SCHEMAS_TYPE_HAS_FACETS)) { |
24282 | | /* |
24283 | | * Apply facets (pattern, enumeration). |
24284 | | */ |
24285 | 0 | ret = xmlSchemaValidateFacets(actxt, node, type, |
24286 | 0 | XML_SCHEMAS_UNKNOWN, value, val, |
24287 | 0 | len, fireErrors); |
24288 | 0 | if (ret != 0) { |
24289 | 0 | if (ret < 0) { |
24290 | 0 | AERROR_INT("xmlSchemaVCheckCVCSimpleType", |
24291 | 0 | "validating facets of list simple type"); |
24292 | 0 | goto internal_error; |
24293 | 0 | } |
24294 | 0 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2; |
24295 | 0 | } |
24296 | 0 | } |
24297 | 0 | if (fireErrors && (ret > 0)) { |
24298 | | /* |
24299 | | * Report the normalized value. |
24300 | | */ |
24301 | 0 | normalize = 1; |
24302 | 0 | NORMALIZE(type); |
24303 | 0 | xmlSchemaSimpleTypeErr(actxt, ret, node, value, type, 1); |
24304 | 0 | } |
24305 | 0 | } else if (WXS_IS_UNION(type)) { |
24306 | 0 | xmlSchemaTypeLinkPtr memberLink; |
24307 | | /* |
24308 | | * TODO: For all datatypes `derived` by `union` whiteSpace does |
24309 | | * not apply directly; however, the normalization behavior of `union` |
24310 | | * types is controlled by the value of whiteSpace on that one of the |
24311 | | * `memberTypes` against which the `union` is successfully validated. |
24312 | | * |
24313 | | * This means that the value is normalized by the first validating |
24314 | | * member type, then the facets of the union type are applied. This |
24315 | | * needs changing of the value! |
24316 | | */ |
24317 | | |
24318 | | /* |
24319 | | * 1.2.3 if {variety} is `union` then the string must `match` a |
24320 | | * literal in the `lexical space` of at least one member of |
24321 | | * {member type definitions} |
24322 | | */ |
24323 | 0 | memberLink = xmlSchemaGetUnionSimpleTypeMemberTypes(type); |
24324 | 0 | if (memberLink == NULL) { |
24325 | 0 | AERROR_INT("xmlSchemaVCheckCVCSimpleType", |
24326 | 0 | "union simple type has no member types"); |
24327 | 0 | goto internal_error; |
24328 | 0 | } |
24329 | | /* |
24330 | | * Always normalize union type values, since we currently |
24331 | | * cannot store the whitespace information with the value |
24332 | | * itself; otherwise a later value-comparison would be |
24333 | | * not possible. |
24334 | | */ |
24335 | 0 | while (memberLink != NULL) { |
24336 | 0 | if (valNeeded) |
24337 | 0 | ret = xmlSchemaVCheckCVCSimpleType(actxt, node, |
24338 | 0 | memberLink->type, value, &val, 0, 1, 0); |
24339 | 0 | else |
24340 | 0 | ret = xmlSchemaVCheckCVCSimpleType(actxt, node, |
24341 | 0 | memberLink->type, value, NULL, 0, 1, 0); |
24342 | 0 | if (ret <= 0) |
24343 | 0 | break; |
24344 | 0 | memberLink = memberLink->next; |
24345 | 0 | } |
24346 | 0 | if (ret != 0) { |
24347 | 0 | if (ret < 0) { |
24348 | 0 | AERROR_INT("xmlSchemaVCheckCVCSimpleType", |
24349 | 0 | "validating members of union simple type"); |
24350 | 0 | goto internal_error; |
24351 | 0 | } |
24352 | 0 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_3; |
24353 | 0 | } |
24354 | | /* |
24355 | | * Apply facets (pattern, enumeration). |
24356 | | */ |
24357 | 0 | if ((ret == 0) && (type->flags & XML_SCHEMAS_TYPE_HAS_FACETS)) { |
24358 | | /* |
24359 | | * The normalization behavior of `union` types is controlled by |
24360 | | * the value of whiteSpace on that one of the `memberTypes` |
24361 | | * against which the `union` is successfully validated. |
24362 | | */ |
24363 | 0 | NORMALIZE(memberLink->type); |
24364 | 0 | ret = xmlSchemaValidateFacets(actxt, node, type, |
24365 | 0 | XML_SCHEMAS_UNKNOWN, value, val, |
24366 | 0 | 0, fireErrors); |
24367 | 0 | if (ret != 0) { |
24368 | 0 | if (ret < 0) { |
24369 | 0 | AERROR_INT("xmlSchemaVCheckCVCSimpleType", |
24370 | 0 | "validating facets of union simple type"); |
24371 | 0 | goto internal_error; |
24372 | 0 | } |
24373 | 0 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_3; |
24374 | 0 | } |
24375 | 0 | } |
24376 | 0 | if (fireErrors && (ret > 0)) |
24377 | 0 | xmlSchemaSimpleTypeErr(actxt, ret, node, value, type, 1); |
24378 | 0 | } |
24379 | | |
24380 | 0 | if (normValue != NULL) |
24381 | 0 | xmlFree(normValue); |
24382 | 0 | if (ret == 0) { |
24383 | 0 | if (retVal != NULL) |
24384 | 0 | *retVal = val; |
24385 | 0 | else if (val != NULL) |
24386 | 0 | xmlSchemaFreeValue(val); |
24387 | 0 | } else if (val != NULL) |
24388 | 0 | xmlSchemaFreeValue(val); |
24389 | 0 | return (ret); |
24390 | 0 | internal_error: |
24391 | 0 | if (normValue != NULL) |
24392 | 0 | xmlFree(normValue); |
24393 | 0 | if (val != NULL) |
24394 | 0 | xmlSchemaFreeValue(val); |
24395 | 0 | return (-1); |
24396 | 0 | } |
24397 | | |
24398 | | static int |
24399 | | xmlSchemaVExpandQName(xmlSchemaValidCtxtPtr vctxt, |
24400 | | const xmlChar *value, |
24401 | | const xmlChar **nsName, |
24402 | | const xmlChar **localName) |
24403 | 0 | { |
24404 | 0 | int ret = 0; |
24405 | |
|
24406 | 0 | if ((nsName == NULL) || (localName == NULL)) |
24407 | 0 | return (-1); |
24408 | 0 | *nsName = NULL; |
24409 | 0 | *localName = NULL; |
24410 | |
|
24411 | 0 | ret = xmlValidateQName(value, 1); |
24412 | 0 | if (ret == -1) |
24413 | 0 | return (-1); |
24414 | 0 | if (ret > 0) { |
24415 | 0 | xmlSchemaSimpleTypeErr(ACTXT_CAST vctxt, |
24416 | 0 | XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1, NULL, |
24417 | 0 | value, xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), 1); |
24418 | 0 | return (1); |
24419 | 0 | } |
24420 | 0 | { |
24421 | 0 | xmlChar *local = NULL; |
24422 | 0 | xmlChar *prefix; |
24423 | | |
24424 | | /* |
24425 | | * NOTE: xmlSplitQName2 will return a duplicated |
24426 | | * string. |
24427 | | */ |
24428 | 0 | local = xmlSplitQName2(value, &prefix); |
24429 | 0 | if (local == NULL) |
24430 | 0 | *localName = xmlDictLookup(vctxt->dict, value, -1); |
24431 | 0 | else { |
24432 | 0 | *localName = xmlDictLookup(vctxt->dict, local, -1); |
24433 | 0 | xmlFree(local); |
24434 | 0 | } |
24435 | |
|
24436 | 0 | *nsName = xmlSchemaLookupNamespace(vctxt, prefix); |
24437 | |
|
24438 | 0 | if (prefix != NULL) { |
24439 | 0 | xmlFree(prefix); |
24440 | | /* |
24441 | | * A namespace must be found if the prefix is NOT NULL. |
24442 | | */ |
24443 | 0 | if (*nsName == NULL) { |
24444 | 0 | xmlSchemaCustomErr(ACTXT_CAST vctxt, |
24445 | 0 | XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1, NULL, |
24446 | 0 | WXS_BASIC_CAST xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), |
24447 | 0 | "The QName value '%s' has no " |
24448 | 0 | "corresponding namespace declaration in scope", |
24449 | 0 | value, NULL); |
24450 | 0 | return (2); |
24451 | 0 | } |
24452 | 0 | } |
24453 | 0 | } |
24454 | 0 | return (0); |
24455 | 0 | } |
24456 | | |
24457 | | static int |
24458 | | xmlSchemaProcessXSIType(xmlSchemaValidCtxtPtr vctxt, |
24459 | | xmlSchemaAttrInfoPtr iattr, |
24460 | | xmlSchemaTypePtr *localType, |
24461 | | xmlSchemaElementPtr elemDecl) |
24462 | 0 | { |
24463 | 0 | int ret = 0; |
24464 | | /* |
24465 | | * cvc-elt (3.3.4) : (4) |
24466 | | * AND |
24467 | | * Schema-Validity Assessment (Element) (cvc-assess-elt) |
24468 | | * (1.2.1.2.1) - (1.2.1.2.4) |
24469 | | * Handle 'xsi:type'. |
24470 | | */ |
24471 | 0 | if (localType == NULL) |
24472 | 0 | return (-1); |
24473 | 0 | *localType = NULL; |
24474 | 0 | if (iattr == NULL) |
24475 | 0 | return (0); |
24476 | 0 | else { |
24477 | 0 | const xmlChar *nsName = NULL, *local = NULL; |
24478 | | /* |
24479 | | * TODO: We should report a *warning* that the type was overridden |
24480 | | * by the instance. |
24481 | | */ |
24482 | 0 | ACTIVATE_ATTRIBUTE(iattr); |
24483 | | /* |
24484 | | * (cvc-elt) (3.3.4) : (4.1) |
24485 | | * (cvc-assess-elt) (1.2.1.2.2) |
24486 | | */ |
24487 | 0 | ret = xmlSchemaVExpandQName(vctxt, iattr->value, |
24488 | 0 | &nsName, &local); |
24489 | 0 | if (ret != 0) { |
24490 | 0 | if (ret < 0) { |
24491 | 0 | VERROR_INT("xmlSchemaValidateElementByDeclaration", |
24492 | 0 | "calling xmlSchemaQNameExpand() to validate the " |
24493 | 0 | "attribute 'xsi:type'"); |
24494 | 0 | goto internal_error; |
24495 | 0 | } |
24496 | 0 | goto exit; |
24497 | 0 | } |
24498 | | /* |
24499 | | * (cvc-elt) (3.3.4) : (4.2) |
24500 | | * (cvc-assess-elt) (1.2.1.2.3) |
24501 | | */ |
24502 | 0 | *localType = xmlSchemaGetType(vctxt->schema, local, nsName); |
24503 | 0 | if (*localType == NULL) { |
24504 | 0 | xmlChar *str = NULL; |
24505 | |
|
24506 | 0 | xmlSchemaCustomErr(ACTXT_CAST vctxt, |
24507 | 0 | XML_SCHEMAV_CVC_ELT_4_2, NULL, |
24508 | 0 | WXS_BASIC_CAST xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), |
24509 | 0 | "The QName value '%s' of the xsi:type attribute does not " |
24510 | 0 | "resolve to a type definition", |
24511 | 0 | xmlSchemaFormatQName(&str, nsName, local), NULL); |
24512 | 0 | FREE_AND_NULL(str); |
24513 | 0 | ret = vctxt->err; |
24514 | 0 | goto exit; |
24515 | 0 | } |
24516 | 0 | if (elemDecl != NULL) { |
24517 | 0 | int set = 0; |
24518 | | |
24519 | | /* |
24520 | | * SPEC cvc-elt (3.3.4) : (4.3) (Type Derivation OK) |
24521 | | * "The `local type definition` must be validly |
24522 | | * derived from the {type definition} given the union of |
24523 | | * the {disallowed substitutions} and the {type definition}'s |
24524 | | * {prohibited substitutions}, as defined in |
24525 | | * Type Derivation OK (Complex) ($3.4.6) |
24526 | | * (if it is a complex type definition), |
24527 | | * or given {disallowed substitutions} as defined in Type |
24528 | | * Derivation OK (Simple) ($3.14.6) (if it is a simple type |
24529 | | * definition)." |
24530 | | * |
24531 | | * {disallowed substitutions}: the "block" on the element decl. |
24532 | | * {prohibited substitutions}: the "block" on the type def. |
24533 | | */ |
24534 | | /* |
24535 | | * OPTIMIZE TODO: We could map types already evaluated |
24536 | | * to be validly derived from other types to avoid checking |
24537 | | * this over and over for the same types. |
24538 | | */ |
24539 | 0 | if ((elemDecl->flags & XML_SCHEMAS_ELEM_BLOCK_EXTENSION) || |
24540 | 0 | (elemDecl->subtypes->flags & |
24541 | 0 | XML_SCHEMAS_TYPE_BLOCK_EXTENSION)) |
24542 | 0 | set |= SUBSET_EXTENSION; |
24543 | |
|
24544 | 0 | if ((elemDecl->flags & XML_SCHEMAS_ELEM_BLOCK_RESTRICTION) || |
24545 | 0 | (elemDecl->subtypes->flags & |
24546 | 0 | XML_SCHEMAS_TYPE_BLOCK_RESTRICTION)) |
24547 | 0 | set |= SUBSET_RESTRICTION; |
24548 | | |
24549 | | /* |
24550 | | * REMOVED and CHANGED since this produced a parser context |
24551 | | * which adds to the string dict of the schema. So this would |
24552 | | * change the schema and we don't want this. We don't need |
24553 | | * the parser context anymore. |
24554 | | * |
24555 | | * if ((vctxt->pctxt == NULL) && |
24556 | | * (xmlSchemaCreatePCtxtOnVCtxt(vctxt) == -1)) |
24557 | | * return (-1); |
24558 | | */ |
24559 | |
|
24560 | 0 | if (xmlSchemaCheckCOSDerivedOK(ACTXT_CAST vctxt, *localType, |
24561 | 0 | elemDecl->subtypes, set) != 0) { |
24562 | 0 | xmlChar *str = NULL; |
24563 | |
|
24564 | 0 | xmlSchemaCustomErr(ACTXT_CAST vctxt, |
24565 | 0 | XML_SCHEMAV_CVC_ELT_4_3, NULL, NULL, |
24566 | 0 | "The type definition '%s', specified by xsi:type, is " |
24567 | 0 | "blocked or not validly derived from the type definition " |
24568 | 0 | "of the element declaration", |
24569 | 0 | xmlSchemaFormatQName(&str, |
24570 | 0 | (*localType)->targetNamespace, |
24571 | 0 | (*localType)->name), |
24572 | 0 | NULL); |
24573 | 0 | FREE_AND_NULL(str); |
24574 | 0 | ret = vctxt->err; |
24575 | 0 | *localType = NULL; |
24576 | 0 | } |
24577 | 0 | } |
24578 | 0 | } |
24579 | 0 | exit: |
24580 | 0 | ACTIVATE_ELEM; |
24581 | 0 | return (ret); |
24582 | 0 | internal_error: |
24583 | 0 | ACTIVATE_ELEM; |
24584 | 0 | return (-1); |
24585 | 0 | } |
24586 | | |
24587 | | static int |
24588 | | xmlSchemaValidateElemDecl(xmlSchemaValidCtxtPtr vctxt) |
24589 | 0 | { |
24590 | 0 | xmlSchemaElementPtr elemDecl = vctxt->inode->decl; |
24591 | 0 | xmlSchemaTypePtr actualType; |
24592 | | |
24593 | | /* |
24594 | | * cvc-elt (3.3.4) : 1 |
24595 | | */ |
24596 | 0 | if (elemDecl == NULL) { |
24597 | 0 | VERROR(XML_SCHEMAV_CVC_ELT_1, NULL, |
24598 | 0 | "No matching declaration available"); |
24599 | 0 | return (vctxt->err); |
24600 | 0 | } |
24601 | 0 | actualType = WXS_ELEM_TYPEDEF(elemDecl); |
24602 | | /* |
24603 | | * cvc-elt (3.3.4) : 2 |
24604 | | */ |
24605 | 0 | if (elemDecl->flags & XML_SCHEMAS_ELEM_ABSTRACT) { |
24606 | 0 | VERROR(XML_SCHEMAV_CVC_ELT_2, NULL, |
24607 | 0 | "The element declaration is abstract"); |
24608 | 0 | return (vctxt->err); |
24609 | 0 | } |
24610 | 0 | if (actualType == NULL) { |
24611 | 0 | VERROR(XML_SCHEMAV_CVC_TYPE_1, NULL, |
24612 | 0 | "The type definition is absent"); |
24613 | 0 | return (XML_SCHEMAV_CVC_TYPE_1); |
24614 | 0 | } |
24615 | 0 | if (vctxt->nbAttrInfos != 0) { |
24616 | 0 | int ret; |
24617 | 0 | xmlSchemaAttrInfoPtr iattr; |
24618 | | /* |
24619 | | * cvc-elt (3.3.4) : 3 |
24620 | | * Handle 'xsi:nil'. |
24621 | | */ |
24622 | 0 | iattr = xmlSchemaGetMetaAttrInfo(vctxt, |
24623 | 0 | XML_SCHEMA_ATTR_INFO_META_XSI_NIL); |
24624 | 0 | if (iattr) { |
24625 | 0 | ACTIVATE_ATTRIBUTE(iattr); |
24626 | | /* |
24627 | | * Validate the value. |
24628 | | */ |
24629 | 0 | ret = xmlSchemaVCheckCVCSimpleType( |
24630 | 0 | ACTXT_CAST vctxt, NULL, |
24631 | 0 | xmlSchemaGetBuiltInType(XML_SCHEMAS_BOOLEAN), |
24632 | 0 | iattr->value, &(iattr->val), 1, 0, 0); |
24633 | 0 | ACTIVATE_ELEM; |
24634 | 0 | if (ret < 0) { |
24635 | 0 | VERROR_INT("xmlSchemaValidateElemDecl", |
24636 | 0 | "calling xmlSchemaVCheckCVCSimpleType() to " |
24637 | 0 | "validate the attribute 'xsi:nil'"); |
24638 | 0 | return (-1); |
24639 | 0 | } |
24640 | 0 | if (ret == 0) { |
24641 | 0 | if ((elemDecl->flags & XML_SCHEMAS_ELEM_NILLABLE) == 0) { |
24642 | | /* |
24643 | | * cvc-elt (3.3.4) : 3.1 |
24644 | | */ |
24645 | 0 | VERROR(XML_SCHEMAV_CVC_ELT_3_1, NULL, |
24646 | 0 | "The element is not 'nillable'"); |
24647 | | /* Does not return an error on purpose. */ |
24648 | 0 | } else { |
24649 | 0 | if (xmlSchemaValueGetAsBoolean(iattr->val)) { |
24650 | | /* |
24651 | | * cvc-elt (3.3.4) : 3.2.2 |
24652 | | */ |
24653 | 0 | if ((elemDecl->flags & XML_SCHEMAS_ELEM_FIXED) && |
24654 | 0 | (elemDecl->value != NULL)) { |
24655 | 0 | VERROR(XML_SCHEMAV_CVC_ELT_3_2_2, NULL, |
24656 | 0 | "The element cannot be 'nilled' because " |
24657 | 0 | "there is a fixed value constraint defined " |
24658 | 0 | "for it"); |
24659 | | /* Does not return an error on purpose. */ |
24660 | 0 | } else |
24661 | 0 | vctxt->inode->flags |= |
24662 | 0 | XML_SCHEMA_ELEM_INFO_NILLED; |
24663 | 0 | } |
24664 | 0 | } |
24665 | 0 | } |
24666 | 0 | } |
24667 | | /* |
24668 | | * cvc-elt (3.3.4) : 4 |
24669 | | * Handle 'xsi:type'. |
24670 | | */ |
24671 | 0 | iattr = xmlSchemaGetMetaAttrInfo(vctxt, |
24672 | 0 | XML_SCHEMA_ATTR_INFO_META_XSI_TYPE); |
24673 | 0 | if (iattr) { |
24674 | 0 | xmlSchemaTypePtr localType = NULL; |
24675 | |
|
24676 | 0 | ret = xmlSchemaProcessXSIType(vctxt, iattr, &localType, |
24677 | 0 | elemDecl); |
24678 | 0 | if (ret != 0) { |
24679 | 0 | if (ret == -1) { |
24680 | 0 | VERROR_INT("xmlSchemaValidateElemDecl", |
24681 | 0 | "calling xmlSchemaProcessXSIType() to " |
24682 | 0 | "process the attribute 'xsi:type'"); |
24683 | 0 | return (-1); |
24684 | 0 | } |
24685 | | /* Does not return an error on purpose. */ |
24686 | 0 | } |
24687 | 0 | if (localType != NULL) { |
24688 | 0 | vctxt->inode->flags |= XML_SCHEMA_ELEM_INFO_LOCAL_TYPE; |
24689 | 0 | actualType = localType; |
24690 | 0 | } |
24691 | 0 | } |
24692 | 0 | } |
24693 | | /* |
24694 | | * IDC: Register identity-constraint XPath matchers. |
24695 | | */ |
24696 | 0 | if ((elemDecl->idcs != NULL) && |
24697 | 0 | (xmlSchemaIDCRegisterMatchers(vctxt, elemDecl) == -1)) |
24698 | 0 | return (-1); |
24699 | | /* |
24700 | | * No actual type definition. |
24701 | | */ |
24702 | 0 | if (actualType == NULL) { |
24703 | 0 | VERROR(XML_SCHEMAV_CVC_TYPE_1, NULL, |
24704 | 0 | "The type definition is absent"); |
24705 | 0 | return (XML_SCHEMAV_CVC_TYPE_1); |
24706 | 0 | } |
24707 | | /* |
24708 | | * Remember the actual type definition. |
24709 | | */ |
24710 | 0 | vctxt->inode->typeDef = actualType; |
24711 | |
|
24712 | 0 | return (0); |
24713 | 0 | } |
24714 | | |
24715 | | static int |
24716 | | xmlSchemaVAttributesSimple(xmlSchemaValidCtxtPtr vctxt) |
24717 | 0 | { |
24718 | 0 | xmlSchemaAttrInfoPtr iattr; |
24719 | 0 | int ret = 0, i; |
24720 | | |
24721 | | /* |
24722 | | * SPEC cvc-type (3.1.1) |
24723 | | * "The attributes of must be empty, excepting those whose namespace |
24724 | | * name is identical to http://www.w3.org/2001/XMLSchema-instance and |
24725 | | * whose local name is one of type, nil, schemaLocation or |
24726 | | * noNamespaceSchemaLocation." |
24727 | | */ |
24728 | 0 | if (vctxt->nbAttrInfos == 0) |
24729 | 0 | return (0); |
24730 | 0 | for (i = 0; i < vctxt->nbAttrInfos; i++) { |
24731 | 0 | iattr = vctxt->attrInfos[i]; |
24732 | 0 | if (! iattr->metaType) { |
24733 | 0 | ACTIVATE_ATTRIBUTE(iattr) |
24734 | 0 | xmlSchemaIllegalAttrErr(ACTXT_CAST vctxt, |
24735 | 0 | XML_SCHEMAV_CVC_TYPE_3_1_1, iattr, NULL); |
24736 | 0 | ret = XML_SCHEMAV_CVC_TYPE_3_1_1; |
24737 | 0 | } |
24738 | 0 | } |
24739 | 0 | ACTIVATE_ELEM |
24740 | 0 | return (ret); |
24741 | 0 | } |
24742 | | |
24743 | | /* |
24744 | | * Cleanup currently used attribute infos. |
24745 | | */ |
24746 | | static void |
24747 | | xmlSchemaClearAttrInfos(xmlSchemaValidCtxtPtr vctxt) |
24748 | 0 | { |
24749 | 0 | int i; |
24750 | 0 | xmlSchemaAttrInfoPtr attr; |
24751 | |
|
24752 | 0 | if (vctxt->nbAttrInfos == 0) |
24753 | 0 | return; |
24754 | 0 | for (i = 0; i < vctxt->nbAttrInfos; i++) { |
24755 | 0 | attr = vctxt->attrInfos[i]; |
24756 | 0 | if (attr->flags & XML_SCHEMA_NODE_INFO_FLAG_OWNED_NAMES) { |
24757 | 0 | if (attr->localName != NULL) |
24758 | 0 | xmlFree((xmlChar *) attr->localName); |
24759 | 0 | if (attr->nsName != NULL) |
24760 | 0 | xmlFree((xmlChar *) attr->nsName); |
24761 | 0 | } |
24762 | 0 | if (attr->flags & XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES) { |
24763 | 0 | if (attr->value != NULL) |
24764 | 0 | xmlFree((xmlChar *) attr->value); |
24765 | 0 | } |
24766 | 0 | if (attr->val != NULL) { |
24767 | 0 | xmlSchemaFreeValue(attr->val); |
24768 | 0 | attr->val = NULL; |
24769 | 0 | } |
24770 | 0 | memset(attr, 0, sizeof(xmlSchemaAttrInfo)); |
24771 | 0 | } |
24772 | 0 | vctxt->nbAttrInfos = 0; |
24773 | 0 | } |
24774 | | |
24775 | | /* |
24776 | | * 3.4.4 Complex Type Definition Validation Rules |
24777 | | * Element Locally Valid (Complex Type) (cvc-complex-type) |
24778 | | * 3.2.4 Attribute Declaration Validation Rules |
24779 | | * Validation Rule: Attribute Locally Valid (cvc-attribute) |
24780 | | * Attribute Locally Valid (Use) (cvc-au) |
24781 | | * |
24782 | | * Only "assessed" attribute information items will be visible to |
24783 | | * IDCs. I.e. not "lax" (without declaration) and "skip" wild attributes. |
24784 | | */ |
24785 | | static int |
24786 | | xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt) |
24787 | 0 | { |
24788 | 0 | xmlSchemaTypePtr type = vctxt->inode->typeDef; |
24789 | 0 | xmlSchemaItemListPtr attrUseList; |
24790 | 0 | xmlSchemaAttributeUsePtr attrUse = NULL; |
24791 | 0 | xmlSchemaAttributePtr attrDecl = NULL; |
24792 | 0 | xmlSchemaAttrInfoPtr iattr, tmpiattr; |
24793 | 0 | int i, j, found, nbAttrs, nbUses; |
24794 | 0 | int xpathRes = 0, res, wildIDs = 0, fixed; |
24795 | 0 | xmlNodePtr defAttrOwnerElem = NULL; |
24796 | | |
24797 | | /* |
24798 | | * SPEC (cvc-attribute) |
24799 | | * (1) "The declaration must not be `absent` (see Missing |
24800 | | * Sub-components ($5.3) for how this can fail to be |
24801 | | * the case)." |
24802 | | * (2) "Its {type definition} must not be absent." |
24803 | | * |
24804 | | * NOTE (1) + (2): This is not handled here, since we currently do not |
24805 | | * allow validation against schemas which have missing sub-components. |
24806 | | * |
24807 | | * SPEC (cvc-complex-type) |
24808 | | * (3) "For each attribute information item in the element information |
24809 | | * item's [attributes] excepting those whose [namespace name] is |
24810 | | * identical to http://www.w3.org/2001/XMLSchema-instance and whose |
24811 | | * [local name] is one of type, nil, schemaLocation or |
24812 | | * noNamespaceSchemaLocation, the appropriate case among the following |
24813 | | * must be true: |
24814 | | * |
24815 | | */ |
24816 | 0 | attrUseList = (xmlSchemaItemListPtr) type->attrUses; |
24817 | | /* |
24818 | | * @nbAttrs is the number of attributes present in the instance. |
24819 | | */ |
24820 | 0 | nbAttrs = vctxt->nbAttrInfos; |
24821 | 0 | if (attrUseList != NULL) |
24822 | 0 | nbUses = attrUseList->nbItems; |
24823 | 0 | else |
24824 | 0 | nbUses = 0; |
24825 | 0 | for (i = 0; i < nbUses; i++) { |
24826 | 0 | found = 0; |
24827 | 0 | attrUse = attrUseList->items[i]; |
24828 | 0 | attrDecl = WXS_ATTRUSE_DECL(attrUse); |
24829 | 0 | for (j = 0; j < nbAttrs; j++) { |
24830 | 0 | iattr = vctxt->attrInfos[j]; |
24831 | | /* |
24832 | | * SPEC (cvc-complex-type) (3) |
24833 | | * Skip meta attributes. |
24834 | | */ |
24835 | 0 | if (iattr->metaType) |
24836 | 0 | continue; |
24837 | 0 | if (iattr->localName[0] != attrDecl->name[0]) |
24838 | 0 | continue; |
24839 | 0 | if (!xmlStrEqual(iattr->localName, attrDecl->name)) |
24840 | 0 | continue; |
24841 | 0 | if (!xmlStrEqual(iattr->nsName, attrDecl->targetNamespace)) |
24842 | 0 | continue; |
24843 | 0 | found = 1; |
24844 | | /* |
24845 | | * SPEC (cvc-complex-type) |
24846 | | * (3.1) "If there is among the {attribute uses} an attribute |
24847 | | * use with an {attribute declaration} whose {name} matches |
24848 | | * the attribute information item's [local name] and whose |
24849 | | * {target namespace} is identical to the attribute information |
24850 | | * item's [namespace name] (where an `absent` {target namespace} |
24851 | | * is taken to be identical to a [namespace name] with no value), |
24852 | | * then the attribute information must be `valid` with respect |
24853 | | * to that attribute use as per Attribute Locally Valid (Use) |
24854 | | * ($3.5.4). In this case the {attribute declaration} of that |
24855 | | * attribute use is the `context-determined declaration` for the |
24856 | | * attribute information item with respect to Schema-Validity |
24857 | | * Assessment (Attribute) ($3.2.4) and |
24858 | | * Assessment Outcome (Attribute) ($3.2.5). |
24859 | | */ |
24860 | 0 | iattr->state = XML_SCHEMAS_ATTR_ASSESSED; |
24861 | 0 | iattr->use = attrUse; |
24862 | | /* |
24863 | | * Context-determined declaration. |
24864 | | */ |
24865 | 0 | iattr->decl = attrDecl; |
24866 | 0 | iattr->typeDef = attrDecl->subtypes; |
24867 | 0 | break; |
24868 | 0 | } |
24869 | |
|
24870 | 0 | if (found) |
24871 | 0 | continue; |
24872 | | |
24873 | 0 | if (attrUse->occurs == XML_SCHEMAS_ATTR_USE_REQUIRED) { |
24874 | | /* |
24875 | | * Handle non-existent, required attributes. |
24876 | | * |
24877 | | * SPEC (cvc-complex-type) |
24878 | | * (4) "The {attribute declaration} of each attribute use in |
24879 | | * the {attribute uses} whose {required} is true matches one |
24880 | | * of the attribute information items in the element information |
24881 | | * item's [attributes] as per clause 3.1 above." |
24882 | | */ |
24883 | 0 | tmpiattr = xmlSchemaGetFreshAttrInfo(vctxt); |
24884 | 0 | if (tmpiattr == NULL) { |
24885 | 0 | VERROR_INT( |
24886 | 0 | "xmlSchemaVAttributesComplex", |
24887 | 0 | "calling xmlSchemaGetFreshAttrInfo()"); |
24888 | 0 | return (-1); |
24889 | 0 | } |
24890 | 0 | tmpiattr->state = XML_SCHEMAS_ATTR_ERR_MISSING; |
24891 | 0 | tmpiattr->use = attrUse; |
24892 | 0 | tmpiattr->decl = attrDecl; |
24893 | 0 | } else if ((attrUse->occurs == XML_SCHEMAS_ATTR_USE_OPTIONAL) && |
24894 | 0 | ((attrUse->defValue != NULL) || |
24895 | 0 | (attrDecl->defValue != NULL))) { |
24896 | | /* |
24897 | | * Handle non-existent, optional, default/fixed attributes. |
24898 | | */ |
24899 | 0 | tmpiattr = xmlSchemaGetFreshAttrInfo(vctxt); |
24900 | 0 | if (tmpiattr == NULL) { |
24901 | 0 | VERROR_INT( |
24902 | 0 | "xmlSchemaVAttributesComplex", |
24903 | 0 | "calling xmlSchemaGetFreshAttrInfo()"); |
24904 | 0 | return (-1); |
24905 | 0 | } |
24906 | 0 | tmpiattr->state = XML_SCHEMAS_ATTR_DEFAULT; |
24907 | 0 | tmpiattr->use = attrUse; |
24908 | 0 | tmpiattr->decl = attrDecl; |
24909 | 0 | tmpiattr->typeDef = attrDecl->subtypes; |
24910 | 0 | tmpiattr->localName = attrDecl->name; |
24911 | 0 | tmpiattr->nsName = attrDecl->targetNamespace; |
24912 | 0 | } |
24913 | 0 | } |
24914 | | |
24915 | 0 | if (vctxt->nbAttrInfos == 0) |
24916 | 0 | return (0); |
24917 | | /* |
24918 | | * Validate against the wildcard. |
24919 | | */ |
24920 | 0 | if (type->attributeWildcard != NULL) { |
24921 | | /* |
24922 | | * SPEC (cvc-complex-type) |
24923 | | * (3.2.1) "There must be an {attribute wildcard}." |
24924 | | */ |
24925 | 0 | for (i = 0; i < nbAttrs; i++) { |
24926 | 0 | iattr = vctxt->attrInfos[i]; |
24927 | | /* |
24928 | | * SPEC (cvc-complex-type) (3) |
24929 | | * Skip meta attributes. |
24930 | | */ |
24931 | 0 | if (iattr->state != XML_SCHEMAS_ATTR_UNKNOWN) |
24932 | 0 | continue; |
24933 | | /* |
24934 | | * SPEC (cvc-complex-type) |
24935 | | * (3.2.2) "The attribute information item must be `valid` with |
24936 | | * respect to it as defined in Item Valid (Wildcard) ($3.10.4)." |
24937 | | * |
24938 | | * SPEC Item Valid (Wildcard) (cvc-wildcard) |
24939 | | * "... its [namespace name] must be `valid` with respect to |
24940 | | * the wildcard constraint, as defined in Wildcard allows |
24941 | | * Namespace Name ($3.10.4)." |
24942 | | */ |
24943 | 0 | if (xmlSchemaCheckCVCWildcardNamespace(type->attributeWildcard, |
24944 | 0 | iattr->nsName) == 0) { |
24945 | | /* |
24946 | | * Handle processContents. |
24947 | | * |
24948 | | * SPEC (cvc-wildcard): |
24949 | | * processContents | context-determined declaration: |
24950 | | * "strict" "mustFind" |
24951 | | * "lax" "none" |
24952 | | * "skip" "skip" |
24953 | | */ |
24954 | 0 | if (type->attributeWildcard->processContents == |
24955 | 0 | XML_SCHEMAS_ANY_SKIP) { |
24956 | | /* |
24957 | | * context-determined declaration = "skip" |
24958 | | * |
24959 | | * SPEC PSVI Assessment Outcome (Attribute) |
24960 | | * [validity] = "notKnown" |
24961 | | * [validation attempted] = "none" |
24962 | | */ |
24963 | 0 | iattr->state = XML_SCHEMAS_ATTR_WILD_SKIP; |
24964 | 0 | continue; |
24965 | 0 | } |
24966 | | /* |
24967 | | * Find an attribute declaration. |
24968 | | */ |
24969 | 0 | iattr->decl = xmlSchemaGetAttributeDecl(vctxt->schema, |
24970 | 0 | iattr->localName, iattr->nsName); |
24971 | 0 | if (iattr->decl != NULL) { |
24972 | 0 | iattr->state = XML_SCHEMAS_ATTR_ASSESSED; |
24973 | | /* |
24974 | | * SPEC (cvc-complex-type) |
24975 | | * (5) "Let [Definition:] the wild IDs be the set of |
24976 | | * all attribute information item to which clause 3.2 |
24977 | | * applied and whose `validation` resulted in a |
24978 | | * `context-determined declaration` of mustFind or no |
24979 | | * `context-determined declaration` at all, and whose |
24980 | | * [local name] and [namespace name] resolve (as |
24981 | | * defined by QName resolution (Instance) ($3.15.4)) to |
24982 | | * an attribute declaration whose {type definition} is |
24983 | | * or is derived from ID. Then all of the following |
24984 | | * must be true:" |
24985 | | */ |
24986 | 0 | iattr->typeDef = WXS_ATTR_TYPEDEF(iattr->decl); |
24987 | 0 | if (xmlSchemaIsDerivedFromBuiltInType( |
24988 | 0 | iattr->typeDef, XML_SCHEMAS_ID)) { |
24989 | | /* |
24990 | | * SPEC (5.1) "There must be no more than one |
24991 | | * item in `wild IDs`." |
24992 | | */ |
24993 | 0 | if (wildIDs != 0) { |
24994 | | /* VAL TODO */ |
24995 | 0 | iattr->state = XML_SCHEMAS_ATTR_ERR_WILD_DUPLICATE_ID; |
24996 | 0 | continue; |
24997 | 0 | } |
24998 | 0 | wildIDs++; |
24999 | | /* |
25000 | | * SPEC (cvc-complex-type) |
25001 | | * (5.2) "If `wild IDs` is non-empty, there must not |
25002 | | * be any attribute uses among the {attribute uses} |
25003 | | * whose {attribute declaration}'s {type definition} |
25004 | | * is or is derived from ID." |
25005 | | */ |
25006 | 0 | if (attrUseList != NULL) { |
25007 | 0 | for (j = 0; j < attrUseList->nbItems; j++) { |
25008 | 0 | if (xmlSchemaIsDerivedFromBuiltInType( |
25009 | 0 | WXS_ATTRUSE_TYPEDEF(attrUseList->items[j]), |
25010 | 0 | XML_SCHEMAS_ID)) { |
25011 | | /* URGENT VAL TODO: implement */ |
25012 | 0 | iattr->state = XML_SCHEMAS_ATTR_ERR_WILD_AND_USE_ID; |
25013 | 0 | break; |
25014 | 0 | } |
25015 | 0 | } |
25016 | 0 | } |
25017 | 0 | } |
25018 | 0 | } else if (type->attributeWildcard->processContents == |
25019 | 0 | XML_SCHEMAS_ANY_LAX) { |
25020 | 0 | iattr->state = XML_SCHEMAS_ATTR_WILD_LAX_NO_DECL; |
25021 | | /* |
25022 | | * SPEC PSVI Assessment Outcome (Attribute) |
25023 | | * [validity] = "notKnown" |
25024 | | * [validation attempted] = "none" |
25025 | | */ |
25026 | 0 | } else { |
25027 | 0 | iattr->state = XML_SCHEMAS_ATTR_ERR_WILD_STRICT_NO_DECL; |
25028 | 0 | } |
25029 | 0 | } |
25030 | 0 | } |
25031 | 0 | } |
25032 | |
|
25033 | 0 | if (vctxt->nbAttrInfos == 0) |
25034 | 0 | return (0); |
25035 | | |
25036 | | /* |
25037 | | * Get the owner element; needed for creation of default attributes. |
25038 | | * This fixes bug #341337, reported by David Grohmann. |
25039 | | */ |
25040 | 0 | if (vctxt->options & XML_SCHEMA_VAL_VC_I_CREATE) { |
25041 | 0 | xmlSchemaNodeInfoPtr ielem = vctxt->elemInfos[vctxt->depth]; |
25042 | 0 | if (ielem && ielem->node && ielem->node->doc) |
25043 | 0 | defAttrOwnerElem = ielem->node; |
25044 | 0 | } |
25045 | | /* |
25046 | | * Validate values, create default attributes, evaluate IDCs. |
25047 | | */ |
25048 | 0 | for (i = 0; i < vctxt->nbAttrInfos; i++) { |
25049 | 0 | iattr = vctxt->attrInfos[i]; |
25050 | | /* |
25051 | | * VAL TODO: Note that we won't try to resolve IDCs to |
25052 | | * "lax" and "skip" validated attributes. Check what to |
25053 | | * do in this case. |
25054 | | */ |
25055 | 0 | if ((iattr->state != XML_SCHEMAS_ATTR_ASSESSED) && |
25056 | 0 | (iattr->state != XML_SCHEMAS_ATTR_DEFAULT)) |
25057 | 0 | continue; |
25058 | | /* |
25059 | | * VAL TODO: What to do if the type definition is missing? |
25060 | | */ |
25061 | 0 | if (iattr->typeDef == NULL) { |
25062 | 0 | iattr->state = XML_SCHEMAS_ATTR_ERR_NO_TYPE; |
25063 | 0 | continue; |
25064 | 0 | } |
25065 | | |
25066 | 0 | ACTIVATE_ATTRIBUTE(iattr); |
25067 | 0 | fixed = 0; |
25068 | 0 | xpathRes = 0; |
25069 | |
|
25070 | 0 | if (vctxt->xpathStates != NULL) { |
25071 | | /* |
25072 | | * Evaluate IDCs. |
25073 | | */ |
25074 | 0 | xpathRes = xmlSchemaXPathEvaluate(vctxt, |
25075 | 0 | XML_ATTRIBUTE_NODE); |
25076 | 0 | if (xpathRes == -1) { |
25077 | 0 | VERROR_INT("xmlSchemaVAttributesComplex", |
25078 | 0 | "calling xmlSchemaXPathEvaluate()"); |
25079 | 0 | goto internal_error; |
25080 | 0 | } |
25081 | 0 | } |
25082 | | |
25083 | 0 | if (iattr->state == XML_SCHEMAS_ATTR_DEFAULT) { |
25084 | | /* |
25085 | | * Default/fixed attributes. |
25086 | | * We need the value only if we need to resolve IDCs or |
25087 | | * will create default attributes. |
25088 | | */ |
25089 | 0 | if ((xpathRes) || (defAttrOwnerElem)) { |
25090 | 0 | if (iattr->use->defValue != NULL) { |
25091 | 0 | iattr->value = (xmlChar *) iattr->use->defValue; |
25092 | 0 | iattr->val = iattr->use->defVal; |
25093 | 0 | } else { |
25094 | 0 | iattr->value = (xmlChar *) iattr->decl->defValue; |
25095 | 0 | iattr->val = iattr->decl->defVal; |
25096 | 0 | } |
25097 | | /* |
25098 | | * IDCs will consume the precomputed default value, |
25099 | | * so we need to clone it. |
25100 | | */ |
25101 | 0 | if (iattr->val == NULL) { |
25102 | 0 | VERROR_INT("xmlSchemaVAttributesComplex", |
25103 | 0 | "default/fixed value on an attribute use was " |
25104 | 0 | "not precomputed"); |
25105 | 0 | goto internal_error; |
25106 | 0 | } |
25107 | 0 | iattr->val = xmlSchemaCopyValue(iattr->val); |
25108 | 0 | if (iattr->val == NULL) { |
25109 | 0 | VERROR_INT("xmlSchemaVAttributesComplex", |
25110 | 0 | "calling xmlSchemaCopyValue()"); |
25111 | 0 | goto internal_error; |
25112 | 0 | } |
25113 | 0 | } |
25114 | | /* |
25115 | | * PSVI: Add the default attribute to the current element. |
25116 | | * VAL TODO: Should we use the *normalized* value? This currently |
25117 | | * uses the *initial* value. |
25118 | | */ |
25119 | | |
25120 | 0 | if (defAttrOwnerElem) { |
25121 | 0 | xmlChar *normValue; |
25122 | 0 | const xmlChar *value; |
25123 | |
|
25124 | 0 | value = iattr->value; |
25125 | | /* |
25126 | | * Normalize the value. |
25127 | | */ |
25128 | 0 | normValue = xmlSchemaNormalizeValue(iattr->typeDef, |
25129 | 0 | iattr->value); |
25130 | 0 | if (normValue != NULL) |
25131 | 0 | value = BAD_CAST normValue; |
25132 | |
|
25133 | 0 | if (iattr->nsName == NULL) { |
25134 | 0 | if (xmlNewProp(defAttrOwnerElem, |
25135 | 0 | iattr->localName, value) == NULL) { |
25136 | 0 | VERROR_INT("xmlSchemaVAttributesComplex", |
25137 | 0 | "calling xmlNewProp()"); |
25138 | 0 | if (normValue != NULL) |
25139 | 0 | xmlFree(normValue); |
25140 | 0 | goto internal_error; |
25141 | 0 | } |
25142 | 0 | } else { |
25143 | 0 | xmlNsPtr ns; |
25144 | |
|
25145 | 0 | ns = xmlSearchNsByHref(defAttrOwnerElem->doc, |
25146 | 0 | defAttrOwnerElem, iattr->nsName); |
25147 | 0 | if (ns == NULL) { |
25148 | 0 | xmlChar prefix[13]; |
25149 | 0 | int counter = 0; |
25150 | | |
25151 | | /* |
25152 | | * Create a namespace declaration on the validation |
25153 | | * root node if no namespace declaration is in scope. |
25154 | | */ |
25155 | 0 | do { |
25156 | 0 | snprintf((char *) prefix, 13, "p%d", counter++); |
25157 | 0 | ns = xmlSearchNs(defAttrOwnerElem->doc, |
25158 | 0 | defAttrOwnerElem, BAD_CAST prefix); |
25159 | 0 | if (counter > 1000) { |
25160 | 0 | VERROR_INT( |
25161 | 0 | "xmlSchemaVAttributesComplex", |
25162 | 0 | "could not compute a ns prefix for a " |
25163 | 0 | "default/fixed attribute"); |
25164 | 0 | if (normValue != NULL) |
25165 | 0 | xmlFree(normValue); |
25166 | 0 | goto internal_error; |
25167 | 0 | } |
25168 | 0 | } while (ns != NULL); |
25169 | 0 | ns = xmlNewNs(vctxt->validationRoot, |
25170 | 0 | iattr->nsName, BAD_CAST prefix); |
25171 | 0 | } |
25172 | | /* |
25173 | | * TODO: |
25174 | | * http://lists.w3.org/Archives/Public/www-xml-schema-comments/2005JulSep/0406.html |
25175 | | * If we have QNames: do we need to ensure there's a |
25176 | | * prefix defined for the QName? |
25177 | | */ |
25178 | 0 | xmlNewNsProp(defAttrOwnerElem, ns, iattr->localName, value); |
25179 | 0 | } |
25180 | 0 | if (normValue != NULL) |
25181 | 0 | xmlFree(normValue); |
25182 | 0 | } |
25183 | | /* |
25184 | | * Go directly to IDC evaluation. |
25185 | | */ |
25186 | 0 | goto eval_idcs; |
25187 | 0 | } |
25188 | | /* |
25189 | | * Validate the value. |
25190 | | */ |
25191 | 0 | if (vctxt->value != NULL) { |
25192 | | /* |
25193 | | * Free last computed value; just for safety reasons. |
25194 | | */ |
25195 | 0 | xmlSchemaFreeValue(vctxt->value); |
25196 | 0 | vctxt->value = NULL; |
25197 | 0 | } |
25198 | | /* |
25199 | | * Note that the attribute *use* can be unavailable, if |
25200 | | * the attribute was a wild attribute. |
25201 | | */ |
25202 | 0 | if ((iattr->decl->flags & XML_SCHEMAS_ATTR_FIXED) || |
25203 | 0 | ((iattr->use != NULL) && |
25204 | 0 | (iattr->use->flags & XML_SCHEMAS_ATTR_FIXED))) |
25205 | 0 | fixed = 1; |
25206 | 0 | else |
25207 | 0 | fixed = 0; |
25208 | | /* |
25209 | | * SPEC (cvc-attribute) |
25210 | | * (3) "The item's `normalized value` must be locally `valid` |
25211 | | * with respect to that {type definition} as per |
25212 | | * String Valid ($3.14.4)." |
25213 | | * |
25214 | | * VAL TODO: Do we already have the |
25215 | | * "normalized attribute value" here? |
25216 | | */ |
25217 | 0 | if (xpathRes || fixed) { |
25218 | 0 | iattr->flags |= XML_SCHEMA_NODE_INFO_VALUE_NEEDED; |
25219 | | /* |
25220 | | * Request a computed value. |
25221 | | */ |
25222 | 0 | res = xmlSchemaVCheckCVCSimpleType( |
25223 | 0 | ACTXT_CAST vctxt, |
25224 | 0 | iattr->node, iattr->typeDef, iattr->value, &(iattr->val), |
25225 | 0 | 1, 1, 0); |
25226 | 0 | } else { |
25227 | 0 | res = xmlSchemaVCheckCVCSimpleType( |
25228 | 0 | ACTXT_CAST vctxt, |
25229 | 0 | iattr->node, iattr->typeDef, iattr->value, NULL, |
25230 | 0 | 1, 0, 0); |
25231 | 0 | } |
25232 | |
|
25233 | 0 | if (res != 0) { |
25234 | 0 | if (res == -1) { |
25235 | 0 | VERROR_INT("xmlSchemaVAttributesComplex", |
25236 | 0 | "calling xmlSchemaStreamValidateSimpleTypeValue()"); |
25237 | 0 | goto internal_error; |
25238 | 0 | } |
25239 | 0 | iattr->state = XML_SCHEMAS_ATTR_INVALID_VALUE; |
25240 | | /* |
25241 | | * SPEC PSVI Assessment Outcome (Attribute) |
25242 | | * [validity] = "invalid" |
25243 | | */ |
25244 | 0 | goto eval_idcs; |
25245 | 0 | } |
25246 | | |
25247 | 0 | if (fixed) { |
25248 | | /* |
25249 | | * SPEC Attribute Locally Valid (Use) (cvc-au) |
25250 | | * "For an attribute information item to be `valid` |
25251 | | * with respect to an attribute use its *normalized* |
25252 | | * value must match the *canonical* lexical |
25253 | | * representation of the attribute use's {value |
25254 | | * constraint}value, if it is present and fixed." |
25255 | | * |
25256 | | * VAL TODO: The requirement for the *canonical* value |
25257 | | * will be removed in XML Schema 1.1. |
25258 | | */ |
25259 | | /* |
25260 | | * SPEC Attribute Locally Valid (cvc-attribute) |
25261 | | * (4) "The item's *actual* value must match the *value* of |
25262 | | * the {value constraint}, if it is present and fixed." |
25263 | | */ |
25264 | 0 | if (iattr->val == NULL) { |
25265 | | /* VAL TODO: A value was not precomputed. */ |
25266 | 0 | goto eval_idcs; |
25267 | 0 | } |
25268 | 0 | if ((iattr->use != NULL) && |
25269 | 0 | (iattr->use->defValue != NULL)) { |
25270 | 0 | if (iattr->use->defVal == NULL) { |
25271 | | /* VAL TODO: A default value was not precomputed. */ |
25272 | 0 | goto eval_idcs; |
25273 | 0 | } |
25274 | 0 | iattr->vcValue = iattr->use->defValue; |
25275 | | /* |
25276 | | if (xmlSchemaCompareValuesWhtsp(attr->val, |
25277 | | (xmlSchemaWhitespaceValueType) ws, |
25278 | | attr->use->defVal, |
25279 | | (xmlSchemaWhitespaceValueType) ws) != 0) { |
25280 | | */ |
25281 | 0 | if (! xmlSchemaAreValuesEqual(iattr->val, iattr->use->defVal)) |
25282 | 0 | iattr->state = XML_SCHEMAS_ATTR_ERR_FIXED_VALUE; |
25283 | 0 | } else { |
25284 | 0 | if (iattr->decl->defVal == NULL) { |
25285 | | /* VAL TODO: A default value was not precomputed. */ |
25286 | 0 | goto eval_idcs; |
25287 | 0 | } |
25288 | 0 | iattr->vcValue = iattr->decl->defValue; |
25289 | | /* |
25290 | | if (xmlSchemaCompareValuesWhtsp(attr->val, |
25291 | | (xmlSchemaWhitespaceValueType) ws, |
25292 | | attrDecl->defVal, |
25293 | | (xmlSchemaWhitespaceValueType) ws) != 0) { |
25294 | | */ |
25295 | 0 | if (! xmlSchemaAreValuesEqual(iattr->val, iattr->decl->defVal)) |
25296 | 0 | iattr->state = XML_SCHEMAS_ATTR_ERR_FIXED_VALUE; |
25297 | 0 | } |
25298 | | /* |
25299 | | * [validity] = "valid" |
25300 | | */ |
25301 | 0 | } |
25302 | 0 | eval_idcs: |
25303 | | /* |
25304 | | * Evaluate IDCs. |
25305 | | */ |
25306 | 0 | if (xpathRes) { |
25307 | 0 | if (xmlSchemaXPathProcessHistory(vctxt, |
25308 | 0 | vctxt->depth +1) == -1) { |
25309 | 0 | VERROR_INT("xmlSchemaVAttributesComplex", |
25310 | 0 | "calling xmlSchemaXPathEvaluate()"); |
25311 | 0 | goto internal_error; |
25312 | 0 | } |
25313 | 0 | } else if (vctxt->xpathStates != NULL) |
25314 | 0 | xmlSchemaXPathPop(vctxt); |
25315 | 0 | } |
25316 | | |
25317 | | /* |
25318 | | * Report errors. |
25319 | | */ |
25320 | 0 | for (i = 0; i < vctxt->nbAttrInfos; i++) { |
25321 | 0 | iattr = vctxt->attrInfos[i]; |
25322 | 0 | if ((iattr->state == XML_SCHEMAS_ATTR_META) || |
25323 | 0 | (iattr->state == XML_SCHEMAS_ATTR_ASSESSED) || |
25324 | 0 | (iattr->state == XML_SCHEMAS_ATTR_WILD_SKIP) || |
25325 | 0 | (iattr->state == XML_SCHEMAS_ATTR_WILD_LAX_NO_DECL)) |
25326 | 0 | continue; |
25327 | 0 | ACTIVATE_ATTRIBUTE(iattr); |
25328 | 0 | switch (iattr->state) { |
25329 | 0 | case XML_SCHEMAS_ATTR_ERR_MISSING: { |
25330 | 0 | xmlChar *str = NULL; |
25331 | 0 | ACTIVATE_ELEM; |
25332 | 0 | xmlSchemaCustomErr(ACTXT_CAST vctxt, |
25333 | 0 | XML_SCHEMAV_CVC_COMPLEX_TYPE_4, NULL, NULL, |
25334 | 0 | "The attribute '%s' is required but missing", |
25335 | 0 | xmlSchemaFormatQName(&str, |
25336 | 0 | iattr->decl->targetNamespace, |
25337 | 0 | iattr->decl->name), |
25338 | 0 | NULL); |
25339 | 0 | FREE_AND_NULL(str) |
25340 | 0 | break; |
25341 | 0 | } |
25342 | 0 | case XML_SCHEMAS_ATTR_ERR_NO_TYPE: |
25343 | 0 | VERROR(XML_SCHEMAV_CVC_ATTRIBUTE_2, NULL, |
25344 | 0 | "The type definition is absent"); |
25345 | 0 | break; |
25346 | 0 | case XML_SCHEMAS_ATTR_ERR_FIXED_VALUE: |
25347 | 0 | xmlSchemaCustomErr(ACTXT_CAST vctxt, |
25348 | 0 | XML_SCHEMAV_CVC_AU, NULL, NULL, |
25349 | 0 | "The value '%s' does not match the fixed " |
25350 | 0 | "value constraint '%s'", |
25351 | 0 | iattr->value, iattr->vcValue); |
25352 | 0 | break; |
25353 | 0 | case XML_SCHEMAS_ATTR_ERR_WILD_STRICT_NO_DECL: |
25354 | 0 | VERROR(XML_SCHEMAV_CVC_WILDCARD, NULL, |
25355 | 0 | "No matching global attribute declaration available, but " |
25356 | 0 | "demanded by the strict wildcard"); |
25357 | 0 | break; |
25358 | 0 | case XML_SCHEMAS_ATTR_UNKNOWN: |
25359 | 0 | if (iattr->metaType) |
25360 | 0 | break; |
25361 | | /* |
25362 | | * MAYBE VAL TODO: One might report different error messages |
25363 | | * for the following errors. |
25364 | | */ |
25365 | 0 | if (type->attributeWildcard == NULL) { |
25366 | 0 | xmlSchemaIllegalAttrErr(ACTXT_CAST vctxt, |
25367 | 0 | XML_SCHEMAV_CVC_COMPLEX_TYPE_3_2_1, iattr, NULL); |
25368 | 0 | } else { |
25369 | 0 | xmlSchemaIllegalAttrErr(ACTXT_CAST vctxt, |
25370 | 0 | XML_SCHEMAV_CVC_COMPLEX_TYPE_3_2_2, iattr, NULL); |
25371 | 0 | } |
25372 | 0 | break; |
25373 | 0 | default: |
25374 | 0 | break; |
25375 | 0 | } |
25376 | 0 | } |
25377 | | |
25378 | 0 | ACTIVATE_ELEM; |
25379 | 0 | return (0); |
25380 | 0 | internal_error: |
25381 | 0 | ACTIVATE_ELEM; |
25382 | 0 | return (-1); |
25383 | 0 | } |
25384 | | |
25385 | | static int |
25386 | | xmlSchemaValidateElemWildcard(xmlSchemaValidCtxtPtr vctxt, |
25387 | | int *skip) |
25388 | 0 | { |
25389 | 0 | xmlSchemaWildcardPtr wild = (xmlSchemaWildcardPtr) vctxt->inode->decl; |
25390 | | /* |
25391 | | * The namespace of the element was already identified to be |
25392 | | * matching the wildcard. |
25393 | | */ |
25394 | 0 | if ((skip == NULL) || (wild == NULL) || |
25395 | 0 | (wild->type != XML_SCHEMA_TYPE_ANY)) { |
25396 | 0 | VERROR_INT("xmlSchemaValidateElemWildcard", |
25397 | 0 | "bad arguments"); |
25398 | 0 | return (-1); |
25399 | 0 | } |
25400 | 0 | *skip = 0; |
25401 | 0 | if (wild->processContents == XML_SCHEMAS_ANY_SKIP) { |
25402 | | /* |
25403 | | * URGENT VAL TODO: Either we need to position the stream to the |
25404 | | * next sibling, or walk the whole subtree. |
25405 | | */ |
25406 | 0 | *skip = 1; |
25407 | 0 | return (0); |
25408 | 0 | } |
25409 | 0 | { |
25410 | 0 | xmlSchemaElementPtr decl = NULL; |
25411 | |
|
25412 | 0 | decl = xmlSchemaGetElem(vctxt->schema, |
25413 | 0 | vctxt->inode->localName, vctxt->inode->nsName); |
25414 | 0 | if (decl != NULL) { |
25415 | 0 | vctxt->inode->decl = decl; |
25416 | 0 | return (0); |
25417 | 0 | } |
25418 | 0 | } |
25419 | 0 | if (wild->processContents == XML_SCHEMAS_ANY_STRICT) { |
25420 | | /* VAL TODO: Change to proper error code. */ |
25421 | 0 | VERROR(XML_SCHEMAV_CVC_ELT_1, NULL, /* WXS_BASIC_CAST wild */ |
25422 | 0 | "No matching global element declaration available, but " |
25423 | 0 | "demanded by the strict wildcard"); |
25424 | 0 | return (vctxt->err); |
25425 | 0 | } |
25426 | 0 | if (vctxt->nbAttrInfos != 0) { |
25427 | 0 | xmlSchemaAttrInfoPtr iattr; |
25428 | | /* |
25429 | | * SPEC Validation Rule: Schema-Validity Assessment (Element) |
25430 | | * (1.2.1.2.1) - (1.2.1.2.3 ) |
25431 | | * |
25432 | | * Use the xsi:type attribute for the type definition. |
25433 | | */ |
25434 | 0 | iattr = xmlSchemaGetMetaAttrInfo(vctxt, |
25435 | 0 | XML_SCHEMA_ATTR_INFO_META_XSI_TYPE); |
25436 | 0 | if (iattr != NULL) { |
25437 | 0 | if (xmlSchemaProcessXSIType(vctxt, iattr, |
25438 | 0 | &(vctxt->inode->typeDef), NULL) == -1) { |
25439 | 0 | VERROR_INT("xmlSchemaValidateElemWildcard", |
25440 | 0 | "calling xmlSchemaProcessXSIType() to " |
25441 | 0 | "process the attribute 'xsi:nil'"); |
25442 | 0 | return (-1); |
25443 | 0 | } |
25444 | | /* |
25445 | | * Don't return an error on purpose. |
25446 | | */ |
25447 | 0 | return (0); |
25448 | 0 | } |
25449 | 0 | } |
25450 | | /* |
25451 | | * SPEC Validation Rule: Schema-Validity Assessment (Element) |
25452 | | * |
25453 | | * Fallback to "anyType". |
25454 | | */ |
25455 | 0 | vctxt->inode->typeDef = |
25456 | 0 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE); |
25457 | 0 | return (0); |
25458 | 0 | } |
25459 | | |
25460 | | /* |
25461 | | * xmlSchemaCheckCOSValidDefault: |
25462 | | * |
25463 | | * This will be called if: not nilled, no content and a default/fixed |
25464 | | * value is provided. |
25465 | | */ |
25466 | | |
25467 | | static int |
25468 | | xmlSchemaCheckCOSValidDefault(xmlSchemaValidCtxtPtr vctxt, |
25469 | | const xmlChar *value, |
25470 | | xmlSchemaValPtr *val) |
25471 | 0 | { |
25472 | 0 | int ret = 0; |
25473 | 0 | xmlSchemaNodeInfoPtr inode = vctxt->inode; |
25474 | | |
25475 | | /* |
25476 | | * cos-valid-default: |
25477 | | * Schema Component Constraint: Element Default Valid (Immediate) |
25478 | | * For a string to be a valid default with respect to a type |
25479 | | * definition the appropriate case among the following must be true: |
25480 | | */ |
25481 | 0 | if WXS_IS_COMPLEX(inode->typeDef) { |
25482 | | /* |
25483 | | * Complex type. |
25484 | | * |
25485 | | * SPEC (2.1) "its {content type} must be a simple type definition |
25486 | | * or mixed." |
25487 | | * SPEC (2.2.2) "If the {content type} is mixed, then the {content |
25488 | | * type}'s particle must be `emptiable` as defined by |
25489 | | * Particle Emptiable ($3.9.6)." |
25490 | | */ |
25491 | 0 | if ((! WXS_HAS_SIMPLE_CONTENT(inode->typeDef)) && |
25492 | 0 | ((! WXS_HAS_MIXED_CONTENT(inode->typeDef)) || |
25493 | 0 | (! WXS_EMPTIABLE(inode->typeDef)))) { |
25494 | 0 | ret = XML_SCHEMAP_COS_VALID_DEFAULT_2_1; |
25495 | | /* NOTE that this covers (2.2.2) as well. */ |
25496 | 0 | VERROR(ret, NULL, |
25497 | 0 | "For a string to be a valid default, the type definition " |
25498 | 0 | "must be a simple type or a complex type with simple content " |
25499 | 0 | "or mixed content and a particle emptiable"); |
25500 | 0 | return(ret); |
25501 | 0 | } |
25502 | 0 | } |
25503 | | /* |
25504 | | * 1 If the type definition is a simple type definition, then the string |
25505 | | * must be `valid` with respect to that definition as defined by String |
25506 | | * Valid ($3.14.4). |
25507 | | * |
25508 | | * AND |
25509 | | * |
25510 | | * 2.2.1 If the {content type} is a simple type definition, then the |
25511 | | * string must be `valid` with respect to that simple type definition |
25512 | | * as defined by String Valid ($3.14.4). |
25513 | | */ |
25514 | 0 | if (WXS_IS_SIMPLE(inode->typeDef)) { |
25515 | |
|
25516 | 0 | ret = xmlSchemaVCheckCVCSimpleType(ACTXT_CAST vctxt, |
25517 | 0 | NULL, inode->typeDef, value, val, 1, 1, 0); |
25518 | |
|
25519 | 0 | } else if (WXS_HAS_SIMPLE_CONTENT(inode->typeDef)) { |
25520 | |
|
25521 | 0 | ret = xmlSchemaVCheckCVCSimpleType(ACTXT_CAST vctxt, |
25522 | 0 | NULL, inode->typeDef->contentTypeDef, value, val, 1, 1, 0); |
25523 | 0 | } |
25524 | 0 | if (ret < 0) { |
25525 | 0 | VERROR_INT("xmlSchemaCheckCOSValidDefault", |
25526 | 0 | "calling xmlSchemaVCheckCVCSimpleType()"); |
25527 | 0 | } |
25528 | 0 | return (ret); |
25529 | 0 | } |
25530 | | |
25531 | | static void |
25532 | | xmlSchemaVContentModelCallback(xmlRegExecCtxtPtr exec ATTRIBUTE_UNUSED, |
25533 | | const xmlChar * name ATTRIBUTE_UNUSED, |
25534 | | void *transdata, void *inputdata) |
25535 | 0 | { |
25536 | 0 | xmlSchemaElementPtr item = (xmlSchemaElementPtr) transdata; |
25537 | 0 | xmlSchemaNodeInfoPtr inode = (xmlSchemaNodeInfoPtr) inputdata; |
25538 | 0 | inode->decl = item; |
25539 | 0 | } |
25540 | | |
25541 | | static int |
25542 | | xmlSchemaValidatorPushElem(xmlSchemaValidCtxtPtr vctxt) |
25543 | 0 | { |
25544 | 0 | vctxt->inode = xmlSchemaGetFreshElemInfo(vctxt); |
25545 | 0 | if (vctxt->inode == NULL) { |
25546 | 0 | VERROR_INT("xmlSchemaValidatorPushElem", |
25547 | 0 | "calling xmlSchemaGetFreshElemInfo()"); |
25548 | 0 | return (-1); |
25549 | 0 | } |
25550 | 0 | vctxt->nbAttrInfos = 0; |
25551 | 0 | return (0); |
25552 | 0 | } |
25553 | | |
25554 | | static int |
25555 | | xmlSchemaVCheckINodeDataType(xmlSchemaValidCtxtPtr vctxt, |
25556 | | xmlSchemaNodeInfoPtr inode, |
25557 | | xmlSchemaTypePtr type, |
25558 | | const xmlChar *value) |
25559 | 0 | { |
25560 | 0 | if (inode->flags & XML_SCHEMA_NODE_INFO_VALUE_NEEDED) |
25561 | 0 | return (xmlSchemaVCheckCVCSimpleType( |
25562 | 0 | ACTXT_CAST vctxt, NULL, |
25563 | 0 | type, value, &(inode->val), 1, 1, 0)); |
25564 | 0 | else |
25565 | 0 | return (xmlSchemaVCheckCVCSimpleType( |
25566 | 0 | ACTXT_CAST vctxt, NULL, |
25567 | 0 | type, value, NULL, 1, 0, 0)); |
25568 | 0 | } |
25569 | | |
25570 | | |
25571 | | |
25572 | | /* |
25573 | | * Process END of element. |
25574 | | */ |
25575 | | static int |
25576 | | xmlSchemaValidatorPopElem(xmlSchemaValidCtxtPtr vctxt) |
25577 | 0 | { |
25578 | 0 | int ret = 0; |
25579 | 0 | xmlSchemaNodeInfoPtr inode = vctxt->inode; |
25580 | |
|
25581 | 0 | if (vctxt->nbAttrInfos != 0) |
25582 | 0 | xmlSchemaClearAttrInfos(vctxt); |
25583 | 0 | if (inode->flags & XML_SCHEMA_NODE_INFO_ERR_NOT_EXPECTED) { |
25584 | | /* |
25585 | | * This element was not expected; |
25586 | | * we will not validate child elements of broken parents. |
25587 | | * Skip validation of all content of the parent. |
25588 | | */ |
25589 | 0 | vctxt->skipDepth = vctxt->depth -1; |
25590 | 0 | goto end_elem; |
25591 | 0 | } |
25592 | 0 | if ((inode->typeDef == NULL) || |
25593 | 0 | (inode->flags & XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE)) { |
25594 | | /* |
25595 | | * 1. the type definition might be missing if the element was |
25596 | | * error prone |
25597 | | * 2. it might be abstract. |
25598 | | */ |
25599 | 0 | goto end_elem; |
25600 | 0 | } |
25601 | | /* |
25602 | | * Check the content model. |
25603 | | */ |
25604 | 0 | if ((inode->typeDef->contentType == XML_SCHEMA_CONTENT_MIXED) || |
25605 | 0 | (inode->typeDef->contentType == XML_SCHEMA_CONTENT_ELEMENTS)) { |
25606 | | |
25607 | | /* |
25608 | | * Workaround for "anyType". |
25609 | | */ |
25610 | 0 | if (inode->typeDef->builtInType == XML_SCHEMAS_ANYTYPE) |
25611 | 0 | goto character_content; |
25612 | | |
25613 | 0 | if ((inode->flags & XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT) == 0) { |
25614 | 0 | xmlChar *values[10]; |
25615 | 0 | int terminal, nbval = 10, nbneg; |
25616 | |
|
25617 | 0 | if (inode->regexCtxt == NULL) { |
25618 | | /* |
25619 | | * Create the regex context. |
25620 | | */ |
25621 | 0 | inode->regexCtxt = |
25622 | 0 | xmlRegNewExecCtxt(inode->typeDef->contModel, |
25623 | 0 | xmlSchemaVContentModelCallback, vctxt); |
25624 | 0 | if (inode->regexCtxt == NULL) { |
25625 | 0 | VERROR_INT("xmlSchemaValidatorPopElem", |
25626 | 0 | "failed to create a regex context"); |
25627 | 0 | goto internal_error; |
25628 | 0 | } |
25629 | 0 | } |
25630 | | |
25631 | | /* |
25632 | | * Do not check further content if the node has been nilled |
25633 | | */ |
25634 | 0 | if (INODE_NILLED(inode)) { |
25635 | 0 | ret = 0; |
25636 | 0 | goto skip_nilled; |
25637 | 0 | } |
25638 | | |
25639 | | /* |
25640 | | * Get hold of the still expected content, since a further |
25641 | | * call to xmlRegExecPushString() will lose this information. |
25642 | | */ |
25643 | 0 | xmlRegExecNextValues(inode->regexCtxt, |
25644 | 0 | &nbval, &nbneg, &values[0], &terminal); |
25645 | 0 | ret = xmlRegExecPushString(inode->regexCtxt, NULL, NULL); |
25646 | 0 | if ((ret<0) || ((ret==0) && (!INODE_NILLED(inode)))) { |
25647 | | /* |
25648 | | * Still missing something. |
25649 | | */ |
25650 | 0 | ret = 1; |
25651 | 0 | inode->flags |= |
25652 | 0 | XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT; |
25653 | 0 | xmlSchemaComplexTypeErr(ACTXT_CAST vctxt, |
25654 | 0 | XML_SCHEMAV_ELEMENT_CONTENT, NULL, NULL, |
25655 | 0 | "Missing child element(s)", |
25656 | 0 | nbval, nbneg, values); |
25657 | 0 | } else { |
25658 | | /* |
25659 | | * Content model is satisfied. |
25660 | | */ |
25661 | 0 | ret = 0; |
25662 | 0 | } |
25663 | |
|
25664 | 0 | } |
25665 | 0 | } |
25666 | | |
25667 | 0 | skip_nilled: |
25668 | |
|
25669 | 0 | if (inode->typeDef->contentType == XML_SCHEMA_CONTENT_ELEMENTS) |
25670 | 0 | goto end_elem; |
25671 | | |
25672 | 0 | character_content: |
25673 | |
|
25674 | 0 | if (vctxt->value != NULL) { |
25675 | 0 | xmlSchemaFreeValue(vctxt->value); |
25676 | 0 | vctxt->value = NULL; |
25677 | 0 | } |
25678 | | /* |
25679 | | * Check character content. |
25680 | | */ |
25681 | 0 | if (inode->decl == NULL) { |
25682 | | /* |
25683 | | * Speedup if no declaration exists. |
25684 | | */ |
25685 | 0 | if (WXS_IS_SIMPLE(inode->typeDef)) { |
25686 | 0 | ret = xmlSchemaVCheckINodeDataType(vctxt, |
25687 | 0 | inode, inode->typeDef, inode->value); |
25688 | 0 | } else if (WXS_HAS_SIMPLE_CONTENT(inode->typeDef)) { |
25689 | 0 | ret = xmlSchemaVCheckINodeDataType(vctxt, |
25690 | 0 | inode, inode->typeDef->contentTypeDef, |
25691 | 0 | inode->value); |
25692 | 0 | } |
25693 | 0 | if (ret < 0) { |
25694 | 0 | VERROR_INT("xmlSchemaValidatorPopElem", |
25695 | 0 | "calling xmlSchemaVCheckCVCSimpleType()"); |
25696 | 0 | goto internal_error; |
25697 | 0 | } |
25698 | 0 | goto end_elem; |
25699 | 0 | } |
25700 | | /* |
25701 | | * cvc-elt (3.3.4) : 5 |
25702 | | * The appropriate case among the following must be true: |
25703 | | */ |
25704 | | /* |
25705 | | * cvc-elt (3.3.4) : 5.1 |
25706 | | * If the declaration has a {value constraint}, |
25707 | | * the item has neither element nor character [children] and |
25708 | | * clause 3.2 has not applied, then all of the following must be true: |
25709 | | */ |
25710 | 0 | if ((inode->decl->value != NULL) && |
25711 | 0 | (inode->flags & XML_SCHEMA_ELEM_INFO_EMPTY) && |
25712 | 0 | (! INODE_NILLED(inode))) { |
25713 | | /* |
25714 | | * cvc-elt (3.3.4) : 5.1.1 |
25715 | | * If the `actual type definition` is a `local type definition` |
25716 | | * then the canonical lexical representation of the {value constraint} |
25717 | | * value must be a valid default for the `actual type definition` as |
25718 | | * defined in Element Default Valid (Immediate) ($3.3.6). |
25719 | | */ |
25720 | | /* |
25721 | | * NOTE: 'local' above means types acquired by xsi:type. |
25722 | | * NOTE: Although the *canonical* value is stated, it is not |
25723 | | * relevant if canonical or not. Additionally XML Schema 1.1 |
25724 | | * will removed this requirement as well. |
25725 | | */ |
25726 | 0 | if (inode->flags & XML_SCHEMA_ELEM_INFO_LOCAL_TYPE) { |
25727 | |
|
25728 | 0 | ret = xmlSchemaCheckCOSValidDefault(vctxt, |
25729 | 0 | inode->decl->value, &(inode->val)); |
25730 | 0 | if (ret != 0) { |
25731 | 0 | if (ret < 0) { |
25732 | 0 | VERROR_INT("xmlSchemaValidatorPopElem", |
25733 | 0 | "calling xmlSchemaCheckCOSValidDefault()"); |
25734 | 0 | goto internal_error; |
25735 | 0 | } |
25736 | 0 | goto end_elem; |
25737 | 0 | } |
25738 | | /* |
25739 | | * Stop here, to avoid redundant validation of the value |
25740 | | * (see following). |
25741 | | */ |
25742 | 0 | goto default_psvi; |
25743 | 0 | } |
25744 | | /* |
25745 | | * cvc-elt (3.3.4) : 5.1.2 |
25746 | | * The element information item with the canonical lexical |
25747 | | * representation of the {value constraint} value used as its |
25748 | | * `normalized value` must be `valid` with respect to the |
25749 | | * `actual type definition` as defined by Element Locally Valid (Type) |
25750 | | * ($3.3.4). |
25751 | | */ |
25752 | 0 | if (WXS_IS_SIMPLE(inode->typeDef)) { |
25753 | 0 | ret = xmlSchemaVCheckINodeDataType(vctxt, |
25754 | 0 | inode, inode->typeDef, inode->decl->value); |
25755 | 0 | } else if (WXS_HAS_SIMPLE_CONTENT(inode->typeDef)) { |
25756 | 0 | ret = xmlSchemaVCheckINodeDataType(vctxt, |
25757 | 0 | inode, inode->typeDef->contentTypeDef, |
25758 | 0 | inode->decl->value); |
25759 | 0 | } |
25760 | 0 | if (ret != 0) { |
25761 | 0 | if (ret < 0) { |
25762 | 0 | VERROR_INT("xmlSchemaValidatorPopElem", |
25763 | 0 | "calling xmlSchemaVCheckCVCSimpleType()"); |
25764 | 0 | goto internal_error; |
25765 | 0 | } |
25766 | 0 | goto end_elem; |
25767 | 0 | } |
25768 | | |
25769 | 0 | default_psvi: |
25770 | | /* |
25771 | | * PSVI: Create a text node on the instance element. |
25772 | | */ |
25773 | 0 | if ((vctxt->options & XML_SCHEMA_VAL_VC_I_CREATE) && |
25774 | 0 | (inode->node != NULL)) { |
25775 | 0 | xmlNodePtr textChild; |
25776 | 0 | xmlChar *normValue; |
25777 | | /* |
25778 | | * VAL TODO: Normalize the value. |
25779 | | */ |
25780 | 0 | normValue = xmlSchemaNormalizeValue(inode->typeDef, |
25781 | 0 | inode->decl->value); |
25782 | 0 | if (normValue != NULL) { |
25783 | 0 | textChild = xmlNewDocText(inode->node->doc, |
25784 | 0 | BAD_CAST normValue); |
25785 | 0 | xmlFree(normValue); |
25786 | 0 | } else |
25787 | 0 | textChild = xmlNewDocText(inode->node->doc, |
25788 | 0 | inode->decl->value); |
25789 | 0 | if (textChild == NULL) { |
25790 | 0 | VERROR_INT("xmlSchemaValidatorPopElem", |
25791 | 0 | "calling xmlNewDocText()"); |
25792 | 0 | goto internal_error; |
25793 | 0 | } else |
25794 | 0 | xmlAddChild(inode->node, textChild); |
25795 | 0 | } |
25796 | |
|
25797 | 0 | } else if (! INODE_NILLED(inode)) { |
25798 | | /* |
25799 | | * 5.2.1 The element information item must be `valid` with respect |
25800 | | * to the `actual type definition` as defined by Element Locally |
25801 | | * Valid (Type) ($3.3.4). |
25802 | | */ |
25803 | 0 | if (WXS_IS_SIMPLE(inode->typeDef)) { |
25804 | | /* |
25805 | | * SPEC (cvc-type) (3.1) |
25806 | | * "If the type definition is a simple type definition, ..." |
25807 | | * (3.1.3) "If clause 3.2 of Element Locally Valid |
25808 | | * (Element) ($3.3.4) did not apply, then the `normalized value` |
25809 | | * must be `valid` with respect to the type definition as defined |
25810 | | * by String Valid ($3.14.4). |
25811 | | */ |
25812 | 0 | ret = xmlSchemaVCheckINodeDataType(vctxt, |
25813 | 0 | inode, inode->typeDef, inode->value); |
25814 | 0 | } else if (WXS_HAS_SIMPLE_CONTENT(inode->typeDef)) { |
25815 | | /* |
25816 | | * SPEC (cvc-type) (3.2) "If the type definition is a complex type |
25817 | | * definition, then the element information item must be |
25818 | | * `valid` with respect to the type definition as per |
25819 | | * Element Locally Valid (Complex Type) ($3.4.4);" |
25820 | | * |
25821 | | * SPEC (cvc-complex-type) (2.2) |
25822 | | * "If the {content type} is a simple type definition, ... |
25823 | | * the `normalized value` of the element information item is |
25824 | | * `valid` with respect to that simple type definition as |
25825 | | * defined by String Valid ($3.14.4)." |
25826 | | */ |
25827 | 0 | ret = xmlSchemaVCheckINodeDataType(vctxt, |
25828 | 0 | inode, inode->typeDef->contentTypeDef, inode->value); |
25829 | 0 | } |
25830 | 0 | if (ret != 0) { |
25831 | 0 | if (ret < 0) { |
25832 | 0 | VERROR_INT("xmlSchemaValidatorPopElem", |
25833 | 0 | "calling xmlSchemaVCheckCVCSimpleType()"); |
25834 | 0 | goto internal_error; |
25835 | 0 | } |
25836 | 0 | goto end_elem; |
25837 | 0 | } |
25838 | | /* |
25839 | | * 5.2.2 If there is a fixed {value constraint} and clause 3.2 has |
25840 | | * not applied, all of the following must be true: |
25841 | | */ |
25842 | 0 | if ((inode->decl->value != NULL) && |
25843 | 0 | (inode->decl->flags & XML_SCHEMAS_ELEM_FIXED)) { |
25844 | | |
25845 | | /* |
25846 | | * TODO: We will need a computed value, when comparison is |
25847 | | * done on computed values. |
25848 | | */ |
25849 | | /* |
25850 | | * 5.2.2.1 The element information item must have no element |
25851 | | * information item [children]. |
25852 | | */ |
25853 | 0 | if (inode->flags & |
25854 | 0 | XML_SCHEMA_ELEM_INFO_HAS_ELEM_CONTENT) { |
25855 | 0 | ret = XML_SCHEMAV_CVC_ELT_5_2_2_1; |
25856 | 0 | VERROR(ret, NULL, |
25857 | 0 | "The content must not contain element nodes since " |
25858 | 0 | "there is a fixed value constraint"); |
25859 | 0 | goto end_elem; |
25860 | 0 | } else { |
25861 | | /* |
25862 | | * 5.2.2.2 The appropriate case among the following must |
25863 | | * be true: |
25864 | | */ |
25865 | 0 | if (WXS_HAS_MIXED_CONTENT(inode->typeDef)) { |
25866 | | /* |
25867 | | * 5.2.2.2.1 If the {content type} of the `actual type |
25868 | | * definition` is mixed, then the *initial value* of the |
25869 | | * item must match the canonical lexical representation |
25870 | | * of the {value constraint} value. |
25871 | | * |
25872 | | * ... the *initial value* of an element information |
25873 | | * item is the string composed of, in order, the |
25874 | | * [character code] of each character information item in |
25875 | | * the [children] of that element information item. |
25876 | | */ |
25877 | 0 | if (! xmlStrEqual(inode->value, inode->decl->value)){ |
25878 | | /* |
25879 | | * VAL TODO: Report invalid & expected values as well. |
25880 | | * VAL TODO: Implement the canonical stuff. |
25881 | | */ |
25882 | 0 | ret = XML_SCHEMAV_CVC_ELT_5_2_2_2_1; |
25883 | 0 | xmlSchemaCustomErr(ACTXT_CAST vctxt, |
25884 | 0 | ret, NULL, NULL, |
25885 | 0 | "The initial value '%s' does not match the fixed " |
25886 | 0 | "value constraint '%s'", |
25887 | 0 | inode->value, inode->decl->value); |
25888 | 0 | goto end_elem; |
25889 | 0 | } |
25890 | 0 | } else if (WXS_HAS_SIMPLE_CONTENT(inode->typeDef)) { |
25891 | | /* |
25892 | | * 5.2.2.2.2 If the {content type} of the `actual type |
25893 | | * definition` is a simple type definition, then the |
25894 | | * *actual value* of the item must match the canonical |
25895 | | * lexical representation of the {value constraint} value. |
25896 | | */ |
25897 | | /* |
25898 | | * VAL TODO: *actual value* is the normalized value, impl. |
25899 | | * this. |
25900 | | * VAL TODO: Report invalid & expected values as well. |
25901 | | * VAL TODO: Implement a comparison with the computed values. |
25902 | | */ |
25903 | 0 | if (! xmlStrEqual(inode->value, |
25904 | 0 | inode->decl->value)) { |
25905 | 0 | ret = XML_SCHEMAV_CVC_ELT_5_2_2_2_2; |
25906 | 0 | xmlSchemaCustomErr(ACTXT_CAST vctxt, |
25907 | 0 | ret, NULL, NULL, |
25908 | 0 | "The actual value '%s' does not match the fixed " |
25909 | 0 | "value constraint '%s'", |
25910 | 0 | inode->value, |
25911 | 0 | inode->decl->value); |
25912 | 0 | goto end_elem; |
25913 | 0 | } |
25914 | 0 | } |
25915 | 0 | } |
25916 | 0 | } |
25917 | 0 | } |
25918 | | |
25919 | 0 | end_elem: |
25920 | 0 | if (vctxt->depth < 0) { |
25921 | | /* TODO: raise error? */ |
25922 | 0 | return (0); |
25923 | 0 | } |
25924 | 0 | if (vctxt->depth == vctxt->skipDepth) |
25925 | 0 | vctxt->skipDepth = -1; |
25926 | | /* |
25927 | | * Evaluate the history of XPath state objects. |
25928 | | */ |
25929 | 0 | if (inode->appliedXPath && |
25930 | 0 | (xmlSchemaXPathProcessHistory(vctxt, vctxt->depth) == -1)) |
25931 | 0 | goto internal_error; |
25932 | | /* |
25933 | | * MAYBE TODO: |
25934 | | * SPEC (6) "The element information item must be `valid` with |
25935 | | * respect to each of the {identity-constraint definitions} as per |
25936 | | * Identity-constraint Satisfied ($3.11.4)." |
25937 | | */ |
25938 | | /* |
25939 | | * PSVI TODO: If we expose IDC node-tables via PSVI then the tables |
25940 | | * need to be built in any case. |
25941 | | * We will currently build IDC node-tables and bubble them only if |
25942 | | * keyrefs do exist. |
25943 | | */ |
25944 | | |
25945 | | /* |
25946 | | * Add the current IDC target-nodes to the IDC node-tables. |
25947 | | */ |
25948 | 0 | if ((inode->idcMatchers != NULL) && |
25949 | 0 | (vctxt->hasKeyrefs || vctxt->createIDCNodeTables)) |
25950 | 0 | { |
25951 | 0 | if (xmlSchemaIDCFillNodeTables(vctxt, inode) == -1) |
25952 | 0 | goto internal_error; |
25953 | 0 | } |
25954 | | /* |
25955 | | * Validate IDC keyrefs. |
25956 | | */ |
25957 | 0 | if (vctxt->inode->hasKeyrefs) |
25958 | 0 | if (xmlSchemaCheckCVCIDCKeyRef(vctxt) == -1) |
25959 | 0 | goto internal_error; |
25960 | | /* |
25961 | | * Merge/free the IDC table. |
25962 | | */ |
25963 | 0 | if (inode->idcTable != NULL) { |
25964 | 0 | if ((vctxt->depth > 0) && |
25965 | 0 | (vctxt->hasKeyrefs || vctxt->createIDCNodeTables)) |
25966 | 0 | { |
25967 | | /* |
25968 | | * Merge the IDC node table with the table of the parent node. |
25969 | | */ |
25970 | 0 | if (xmlSchemaBubbleIDCNodeTables(vctxt) == -1) |
25971 | 0 | goto internal_error; |
25972 | 0 | } |
25973 | 0 | } |
25974 | | /* |
25975 | | * Clear the current ielem. |
25976 | | * VAL TODO: Don't free the PSVI IDC tables if they are |
25977 | | * requested for the PSVI. |
25978 | | */ |
25979 | 0 | xmlSchemaClearElemInfo(vctxt, inode); |
25980 | | /* |
25981 | | * Skip further processing if we are on the validation root. |
25982 | | */ |
25983 | 0 | if (vctxt->depth == 0) { |
25984 | 0 | vctxt->depth--; |
25985 | 0 | vctxt->inode = NULL; |
25986 | 0 | return (0); |
25987 | 0 | } |
25988 | | /* |
25989 | | * Reset the keyrefDepth if needed. |
25990 | | */ |
25991 | 0 | if (vctxt->aidcs != NULL) { |
25992 | 0 | xmlSchemaIDCAugPtr aidc = vctxt->aidcs; |
25993 | 0 | do { |
25994 | 0 | if (aidc->keyrefDepth == vctxt->depth) { |
25995 | | /* |
25996 | | * A 'keyrefDepth' of a key/unique IDC matches the current |
25997 | | * depth, this means that we are leaving the scope of the |
25998 | | * top-most keyref IDC which refers to this IDC. |
25999 | | */ |
26000 | 0 | aidc->keyrefDepth = -1; |
26001 | 0 | } |
26002 | 0 | aidc = aidc->next; |
26003 | 0 | } while (aidc != NULL); |
26004 | 0 | } |
26005 | 0 | vctxt->depth--; |
26006 | 0 | vctxt->inode = vctxt->elemInfos[vctxt->depth]; |
26007 | | /* |
26008 | | * VAL TODO: 7 If the element information item is the `validation root`, it must be |
26009 | | * `valid` per Validation Root Valid (ID/IDREF) ($3.3.4). |
26010 | | */ |
26011 | 0 | return (ret); |
26012 | | |
26013 | 0 | internal_error: |
26014 | 0 | vctxt->err = -1; |
26015 | 0 | return (-1); |
26016 | 0 | } |
26017 | | |
26018 | | /* |
26019 | | * 3.4.4 Complex Type Definition Validation Rules |
26020 | | * Validation Rule: Element Locally Valid (Complex Type) (cvc-complex-type) |
26021 | | */ |
26022 | | static int |
26023 | | xmlSchemaValidateChildElem(xmlSchemaValidCtxtPtr vctxt) |
26024 | 0 | { |
26025 | 0 | xmlSchemaNodeInfoPtr pielem; |
26026 | 0 | xmlSchemaTypePtr ptype; |
26027 | 0 | int ret = 0; |
26028 | |
|
26029 | 0 | if (vctxt->depth <= 0) { |
26030 | 0 | VERROR_INT("xmlSchemaValidateChildElem", |
26031 | 0 | "not intended for the validation root"); |
26032 | 0 | return (-1); |
26033 | 0 | } |
26034 | 0 | pielem = vctxt->elemInfos[vctxt->depth -1]; |
26035 | 0 | if (pielem->flags & XML_SCHEMA_ELEM_INFO_EMPTY) |
26036 | 0 | pielem->flags ^= XML_SCHEMA_ELEM_INFO_EMPTY; |
26037 | | /* |
26038 | | * Handle 'nilled' elements. |
26039 | | */ |
26040 | 0 | if (INODE_NILLED(pielem)) { |
26041 | | /* |
26042 | | * SPEC (cvc-elt) (3.3.4) : (3.2.1) |
26043 | | */ |
26044 | 0 | ACTIVATE_PARENT_ELEM; |
26045 | 0 | ret = XML_SCHEMAV_CVC_ELT_3_2_1; |
26046 | 0 | VERROR(ret, NULL, |
26047 | 0 | "Neither character nor element content is allowed, " |
26048 | 0 | "because the element was 'nilled'"); |
26049 | 0 | ACTIVATE_ELEM; |
26050 | 0 | goto unexpected_elem; |
26051 | 0 | } |
26052 | | |
26053 | 0 | ptype = pielem->typeDef; |
26054 | |
|
26055 | 0 | if (ptype->builtInType == XML_SCHEMAS_ANYTYPE) { |
26056 | | /* |
26057 | | * Workaround for "anyType": we have currently no content model |
26058 | | * assigned for "anyType", so handle it explicitly. |
26059 | | * "anyType" has an unbounded, lax "any" wildcard. |
26060 | | */ |
26061 | 0 | vctxt->inode->decl = xmlSchemaGetElem(vctxt->schema, |
26062 | 0 | vctxt->inode->localName, |
26063 | 0 | vctxt->inode->nsName); |
26064 | |
|
26065 | 0 | if (vctxt->inode->decl == NULL) { |
26066 | 0 | xmlSchemaAttrInfoPtr iattr; |
26067 | | /* |
26068 | | * Process "xsi:type". |
26069 | | * SPEC (cvc-assess-elt) (1.2.1.2.1) - (1.2.1.2.3) |
26070 | | */ |
26071 | 0 | iattr = xmlSchemaGetMetaAttrInfo(vctxt, |
26072 | 0 | XML_SCHEMA_ATTR_INFO_META_XSI_TYPE); |
26073 | 0 | if (iattr != NULL) { |
26074 | 0 | ret = xmlSchemaProcessXSIType(vctxt, iattr, |
26075 | 0 | &(vctxt->inode->typeDef), NULL); |
26076 | 0 | if (ret != 0) { |
26077 | 0 | if (ret == -1) { |
26078 | 0 | VERROR_INT("xmlSchemaValidateChildElem", |
26079 | 0 | "calling xmlSchemaProcessXSIType() to " |
26080 | 0 | "process the attribute 'xsi:nil'"); |
26081 | 0 | return (-1); |
26082 | 0 | } |
26083 | 0 | return (ret); |
26084 | 0 | } |
26085 | 0 | } else { |
26086 | | /* |
26087 | | * Fallback to "anyType". |
26088 | | * |
26089 | | * SPEC (cvc-assess-elt) |
26090 | | * "If the item cannot be `strictly assessed`, [...] |
26091 | | * an element information item's schema validity may be laxly |
26092 | | * assessed if its `context-determined declaration` is not |
26093 | | * skip by `validating` with respect to the `ur-type |
26094 | | * definition` as per Element Locally Valid (Type) ($3.3.4)." |
26095 | | */ |
26096 | 0 | vctxt->inode->typeDef = |
26097 | 0 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE); |
26098 | 0 | } |
26099 | 0 | } |
26100 | 0 | return (0); |
26101 | 0 | } |
26102 | | |
26103 | 0 | switch (ptype->contentType) { |
26104 | 0 | case XML_SCHEMA_CONTENT_EMPTY: |
26105 | | /* |
26106 | | * SPEC (2.1) "If the {content type} is empty, then the |
26107 | | * element information item has no character or element |
26108 | | * information item [children]." |
26109 | | */ |
26110 | 0 | ACTIVATE_PARENT_ELEM |
26111 | 0 | ret = XML_SCHEMAV_CVC_COMPLEX_TYPE_2_1; |
26112 | 0 | VERROR(ret, NULL, |
26113 | 0 | "Element content is not allowed, " |
26114 | 0 | "because the content type is empty"); |
26115 | 0 | ACTIVATE_ELEM |
26116 | 0 | goto unexpected_elem; |
26117 | 0 | break; |
26118 | | |
26119 | 0 | case XML_SCHEMA_CONTENT_MIXED: |
26120 | 0 | case XML_SCHEMA_CONTENT_ELEMENTS: { |
26121 | 0 | xmlRegExecCtxtPtr regexCtxt; |
26122 | 0 | xmlChar *values[10]; |
26123 | 0 | int terminal, nbval = 10, nbneg; |
26124 | | |
26125 | | /* VAL TODO: Optimized "anyType" validation.*/ |
26126 | |
|
26127 | 0 | if (ptype->contModel == NULL) { |
26128 | 0 | VERROR_INT("xmlSchemaValidateChildElem", |
26129 | 0 | "type has elem content but no content model"); |
26130 | 0 | return (-1); |
26131 | 0 | } |
26132 | | /* |
26133 | | * Safety belt for evaluation if the cont. model was already |
26134 | | * examined to be invalid. |
26135 | | */ |
26136 | 0 | if (pielem->flags & XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT) { |
26137 | 0 | VERROR_INT("xmlSchemaValidateChildElem", |
26138 | 0 | "validating elem, but elem content is already invalid"); |
26139 | 0 | return (-1); |
26140 | 0 | } |
26141 | | |
26142 | 0 | regexCtxt = pielem->regexCtxt; |
26143 | 0 | if (regexCtxt == NULL) { |
26144 | | /* |
26145 | | * Create the regex context. |
26146 | | */ |
26147 | 0 | regexCtxt = xmlRegNewExecCtxt(ptype->contModel, |
26148 | 0 | xmlSchemaVContentModelCallback, vctxt); |
26149 | 0 | if (regexCtxt == NULL) { |
26150 | 0 | VERROR_INT("xmlSchemaValidateChildElem", |
26151 | 0 | "failed to create a regex context"); |
26152 | 0 | return (-1); |
26153 | 0 | } |
26154 | 0 | pielem->regexCtxt = regexCtxt; |
26155 | 0 | } |
26156 | | |
26157 | | /* |
26158 | | * SPEC (2.4) "If the {content type} is element-only or mixed, |
26159 | | * then the sequence of the element information item's |
26160 | | * element information item [children], if any, taken in |
26161 | | * order, is `valid` with respect to the {content type}'s |
26162 | | * particle, as defined in Element Sequence Locally Valid |
26163 | | * (Particle) ($3.9.4)." |
26164 | | */ |
26165 | 0 | ret = xmlRegExecPushString2(regexCtxt, |
26166 | 0 | vctxt->inode->localName, |
26167 | 0 | vctxt->inode->nsName, |
26168 | 0 | vctxt->inode); |
26169 | 0 | if (vctxt->err == XML_SCHEMAV_INTERNAL) { |
26170 | 0 | VERROR_INT("xmlSchemaValidateChildElem", |
26171 | 0 | "calling xmlRegExecPushString2()"); |
26172 | 0 | return (-1); |
26173 | 0 | } |
26174 | 0 | if (ret < 0) { |
26175 | 0 | xmlRegExecErrInfo(regexCtxt, NULL, &nbval, &nbneg, |
26176 | 0 | &values[0], &terminal); |
26177 | 0 | xmlSchemaComplexTypeErr(ACTXT_CAST vctxt, |
26178 | 0 | XML_SCHEMAV_ELEMENT_CONTENT, NULL,NULL, |
26179 | 0 | "This element is not expected", |
26180 | 0 | nbval, nbneg, values); |
26181 | 0 | ret = vctxt->err; |
26182 | 0 | goto unexpected_elem; |
26183 | 0 | } else |
26184 | 0 | ret = 0; |
26185 | 0 | } |
26186 | 0 | break; |
26187 | 0 | case XML_SCHEMA_CONTENT_SIMPLE: |
26188 | 0 | case XML_SCHEMA_CONTENT_BASIC: |
26189 | 0 | ACTIVATE_PARENT_ELEM |
26190 | 0 | if (WXS_IS_COMPLEX(ptype)) { |
26191 | | /* |
26192 | | * SPEC (cvc-complex-type) (2.2) |
26193 | | * "If the {content type} is a simple type definition, then |
26194 | | * the element information item has no element information |
26195 | | * item [children], ..." |
26196 | | */ |
26197 | 0 | ret = XML_SCHEMAV_CVC_COMPLEX_TYPE_2_2; |
26198 | 0 | VERROR(ret, NULL, "Element content is not allowed, " |
26199 | 0 | "because the content type is a simple type definition"); |
26200 | 0 | } else { |
26201 | | /* |
26202 | | * SPEC (cvc-type) (3.1.2) "The element information item must |
26203 | | * have no element information item [children]." |
26204 | | */ |
26205 | 0 | ret = XML_SCHEMAV_CVC_TYPE_3_1_2; |
26206 | 0 | VERROR(ret, NULL, "Element content is not allowed, " |
26207 | 0 | "because the type definition is simple"); |
26208 | 0 | } |
26209 | 0 | ACTIVATE_ELEM |
26210 | 0 | ret = vctxt->err; |
26211 | 0 | goto unexpected_elem; |
26212 | 0 | break; |
26213 | | |
26214 | 0 | default: |
26215 | 0 | break; |
26216 | 0 | } |
26217 | 0 | return (ret); |
26218 | 0 | unexpected_elem: |
26219 | | /* |
26220 | | * Pop this element and set the skipDepth to skip |
26221 | | * all further content of the parent element. |
26222 | | */ |
26223 | 0 | vctxt->skipDepth = vctxt->depth; |
26224 | 0 | vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_ERR_NOT_EXPECTED; |
26225 | 0 | pielem->flags |= XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT; |
26226 | 0 | return (ret); |
26227 | 0 | } |
26228 | | |
26229 | 0 | #define XML_SCHEMA_PUSH_TEXT_PERSIST 1 |
26230 | 0 | #define XML_SCHEMA_PUSH_TEXT_CREATED 2 |
26231 | 0 | #define XML_SCHEMA_PUSH_TEXT_VOLATILE 3 |
26232 | | |
26233 | | static int |
26234 | | xmlSchemaVPushText(xmlSchemaValidCtxtPtr vctxt, |
26235 | | int nodeType, const xmlChar *value, int len, |
26236 | | int mode, int *consumed) |
26237 | 0 | { |
26238 | | /* |
26239 | | * Unfortunately we have to duplicate the text sometimes. |
26240 | | * OPTIMIZE: Maybe we could skip it, if: |
26241 | | * 1. content type is simple |
26242 | | * 2. whitespace is "collapse" |
26243 | | * 3. it consists of whitespace only |
26244 | | * |
26245 | | * Process character content. |
26246 | | */ |
26247 | 0 | if (consumed != NULL) |
26248 | 0 | *consumed = 0; |
26249 | 0 | if (INODE_NILLED(vctxt->inode)) { |
26250 | | /* |
26251 | | * SPEC cvc-elt (3.3.4 - 3.2.1) |
26252 | | * "The element information item must have no character or |
26253 | | * element information item [children]." |
26254 | | */ |
26255 | 0 | VERROR(XML_SCHEMAV_CVC_ELT_3_2_1, NULL, |
26256 | 0 | "Neither character nor element content is allowed " |
26257 | 0 | "because the element is 'nilled'"); |
26258 | 0 | return (vctxt->err); |
26259 | 0 | } |
26260 | | /* |
26261 | | * SPEC (2.1) "If the {content type} is empty, then the |
26262 | | * element information item has no character or element |
26263 | | * information item [children]." |
26264 | | */ |
26265 | 0 | if (vctxt->inode->typeDef->contentType == |
26266 | 0 | XML_SCHEMA_CONTENT_EMPTY) { |
26267 | 0 | VERROR(XML_SCHEMAV_CVC_COMPLEX_TYPE_2_1, NULL, |
26268 | 0 | "Character content is not allowed, " |
26269 | 0 | "because the content type is empty"); |
26270 | 0 | return (vctxt->err); |
26271 | 0 | } |
26272 | | |
26273 | 0 | if (vctxt->inode->typeDef->contentType == |
26274 | 0 | XML_SCHEMA_CONTENT_ELEMENTS) { |
26275 | 0 | if ((nodeType != XML_TEXT_NODE) || |
26276 | 0 | (! xmlSchemaIsBlank((xmlChar *) value, len))) { |
26277 | | /* |
26278 | | * SPEC cvc-complex-type (2.3) |
26279 | | * "If the {content type} is element-only, then the |
26280 | | * element information item has no character information |
26281 | | * item [children] other than those whose [character |
26282 | | * code] is defined as a white space in [XML 1.0 (Second |
26283 | | * Edition)]." |
26284 | | */ |
26285 | 0 | VERROR(XML_SCHEMAV_CVC_COMPLEX_TYPE_2_3, NULL, |
26286 | 0 | "Character content other than whitespace is not allowed " |
26287 | 0 | "because the content type is 'element-only'"); |
26288 | 0 | return (vctxt->err); |
26289 | 0 | } |
26290 | 0 | return (0); |
26291 | 0 | } |
26292 | | |
26293 | 0 | if ((value == NULL) || (value[0] == 0)) |
26294 | 0 | return (0); |
26295 | | /* |
26296 | | * Save the value. |
26297 | | * NOTE that even if the content type is *mixed*, we need the |
26298 | | * *initial value* for default/fixed value constraints. |
26299 | | */ |
26300 | 0 | if ((vctxt->inode->typeDef->contentType == XML_SCHEMA_CONTENT_MIXED) && |
26301 | 0 | ((vctxt->inode->decl == NULL) || |
26302 | 0 | (vctxt->inode->decl->value == NULL))) |
26303 | 0 | return (0); |
26304 | | |
26305 | 0 | if (vctxt->inode->value == NULL) { |
26306 | | /* |
26307 | | * Set the value. |
26308 | | */ |
26309 | 0 | switch (mode) { |
26310 | 0 | case XML_SCHEMA_PUSH_TEXT_PERSIST: |
26311 | | /* |
26312 | | * When working on a tree. |
26313 | | */ |
26314 | 0 | vctxt->inode->value = value; |
26315 | 0 | vctxt->inode->flags &= |
26316 | 0 | ~XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES; |
26317 | 0 | break; |
26318 | 0 | case XML_SCHEMA_PUSH_TEXT_CREATED: |
26319 | | /* |
26320 | | * When working with the reader. |
26321 | | * The value will be freed by the element info. |
26322 | | */ |
26323 | 0 | vctxt->inode->value = value; |
26324 | 0 | if (consumed != NULL) |
26325 | 0 | *consumed = 1; |
26326 | 0 | vctxt->inode->flags |= |
26327 | 0 | XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES; |
26328 | 0 | break; |
26329 | 0 | case XML_SCHEMA_PUSH_TEXT_VOLATILE: |
26330 | | /* |
26331 | | * When working with SAX. |
26332 | | * The value will be freed by the element info. |
26333 | | */ |
26334 | 0 | if (len != -1) |
26335 | 0 | vctxt->inode->value = BAD_CAST xmlStrndup(value, len); |
26336 | 0 | else |
26337 | 0 | vctxt->inode->value = BAD_CAST xmlStrdup(value); |
26338 | 0 | vctxt->inode->flags |= |
26339 | 0 | XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES; |
26340 | 0 | break; |
26341 | 0 | default: |
26342 | 0 | break; |
26343 | 0 | } |
26344 | 0 | } else { |
26345 | 0 | if (len < 0) |
26346 | 0 | len = xmlStrlen(value); |
26347 | | /* |
26348 | | * Concat the value. |
26349 | | */ |
26350 | 0 | if (vctxt->inode->flags & XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES) { |
26351 | 0 | vctxt->inode->value = BAD_CAST xmlStrncat( |
26352 | 0 | (xmlChar *) vctxt->inode->value, value, len); |
26353 | 0 | } else { |
26354 | 0 | vctxt->inode->value = |
26355 | 0 | BAD_CAST xmlStrncatNew(vctxt->inode->value, value, len); |
26356 | 0 | vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES; |
26357 | 0 | } |
26358 | 0 | } |
26359 | | |
26360 | 0 | return (0); |
26361 | 0 | } |
26362 | | |
26363 | | static int |
26364 | | xmlSchemaValidateElem(xmlSchemaValidCtxtPtr vctxt) |
26365 | 0 | { |
26366 | 0 | int ret = 0; |
26367 | |
|
26368 | 0 | if ((vctxt->skipDepth != -1) && |
26369 | 0 | (vctxt->depth >= vctxt->skipDepth)) { |
26370 | 0 | VERROR_INT("xmlSchemaValidateElem", |
26371 | 0 | "in skip-state"); |
26372 | 0 | goto internal_error; |
26373 | 0 | } |
26374 | 0 | if (vctxt->xsiAssemble) { |
26375 | | /* |
26376 | | * We will stop validation if there was an error during |
26377 | | * dynamic schema construction. |
26378 | | * Note that we simply set @skipDepth to 0, this could |
26379 | | * mean that a streaming document via SAX would be |
26380 | | * still read to the end but it won't be validated any more. |
26381 | | * TODO: If we are sure how to stop the validation at once |
26382 | | * for all input scenarios, then this should be changed to |
26383 | | * instantly stop the validation. |
26384 | | */ |
26385 | 0 | ret = xmlSchemaAssembleByXSI(vctxt); |
26386 | 0 | if (ret != 0) { |
26387 | 0 | if (ret == -1) |
26388 | 0 | goto internal_error; |
26389 | 0 | vctxt->skipDepth = 0; |
26390 | 0 | return(ret); |
26391 | 0 | } |
26392 | | /* |
26393 | | * Augment the IDC definitions for the main schema and all imported ones |
26394 | | * NOTE: main schema is the first in the imported list |
26395 | | */ |
26396 | 0 | xmlHashScan(vctxt->schema->schemasImports, xmlSchemaAugmentImportedIDC, |
26397 | 0 | vctxt); |
26398 | 0 | } |
26399 | 0 | if (vctxt->depth > 0) { |
26400 | | /* |
26401 | | * Validate this element against the content model |
26402 | | * of the parent. |
26403 | | */ |
26404 | 0 | ret = xmlSchemaValidateChildElem(vctxt); |
26405 | 0 | if (ret != 0) { |
26406 | 0 | if (ret < 0) { |
26407 | 0 | VERROR_INT("xmlSchemaValidateElem", |
26408 | 0 | "calling xmlSchemaStreamValidateChildElement()"); |
26409 | 0 | goto internal_error; |
26410 | 0 | } |
26411 | 0 | goto exit; |
26412 | 0 | } |
26413 | 0 | if (vctxt->depth == vctxt->skipDepth) |
26414 | 0 | goto exit; |
26415 | 0 | if ((vctxt->inode->decl == NULL) && |
26416 | 0 | (vctxt->inode->typeDef == NULL)) { |
26417 | 0 | VERROR_INT("xmlSchemaValidateElem", |
26418 | 0 | "the child element was valid but neither the " |
26419 | 0 | "declaration nor the type was set"); |
26420 | 0 | goto internal_error; |
26421 | 0 | } |
26422 | 0 | } else { |
26423 | | /* |
26424 | | * Get the declaration of the validation root. |
26425 | | */ |
26426 | 0 | vctxt->inode->decl = xmlSchemaGetElem(vctxt->schema, |
26427 | 0 | vctxt->inode->localName, |
26428 | 0 | vctxt->inode->nsName); |
26429 | 0 | if (vctxt->inode->decl == NULL) { |
26430 | 0 | ret = XML_SCHEMAV_CVC_ELT_1; |
26431 | 0 | VERROR(ret, NULL, |
26432 | 0 | "No matching global declaration available " |
26433 | 0 | "for the validation root"); |
26434 | 0 | goto exit; |
26435 | 0 | } |
26436 | 0 | } |
26437 | | |
26438 | 0 | if (vctxt->inode->decl == NULL) |
26439 | 0 | goto type_validation; |
26440 | | |
26441 | 0 | if (vctxt->inode->decl->type == XML_SCHEMA_TYPE_ANY) { |
26442 | 0 | int skip; |
26443 | | /* |
26444 | | * Wildcards. |
26445 | | */ |
26446 | 0 | ret = xmlSchemaValidateElemWildcard(vctxt, &skip); |
26447 | 0 | if (ret != 0) { |
26448 | 0 | if (ret < 0) { |
26449 | 0 | VERROR_INT("xmlSchemaValidateElem", |
26450 | 0 | "calling xmlSchemaValidateElemWildcard()"); |
26451 | 0 | goto internal_error; |
26452 | 0 | } |
26453 | 0 | goto exit; |
26454 | 0 | } |
26455 | 0 | if (skip) { |
26456 | 0 | vctxt->skipDepth = vctxt->depth; |
26457 | 0 | goto exit; |
26458 | 0 | } |
26459 | | /* |
26460 | | * The declaration might be set by the wildcard validation, |
26461 | | * when the processContents is "lax" or "strict". |
26462 | | */ |
26463 | 0 | if (vctxt->inode->decl->type != XML_SCHEMA_TYPE_ELEMENT) { |
26464 | | /* |
26465 | | * Clear the "decl" field to not confuse further processing. |
26466 | | */ |
26467 | 0 | vctxt->inode->decl = NULL; |
26468 | 0 | goto type_validation; |
26469 | 0 | } |
26470 | 0 | } |
26471 | | /* |
26472 | | * Validate against the declaration. |
26473 | | */ |
26474 | 0 | ret = xmlSchemaValidateElemDecl(vctxt); |
26475 | 0 | if (ret != 0) { |
26476 | 0 | if (ret < 0) { |
26477 | 0 | VERROR_INT("xmlSchemaValidateElem", |
26478 | 0 | "calling xmlSchemaValidateElemDecl()"); |
26479 | 0 | goto internal_error; |
26480 | 0 | } |
26481 | 0 | goto exit; |
26482 | 0 | } |
26483 | | /* |
26484 | | * Validate against the type definition. |
26485 | | */ |
26486 | 0 | type_validation: |
26487 | |
|
26488 | 0 | if (vctxt->inode->typeDef == NULL) { |
26489 | 0 | vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE; |
26490 | 0 | ret = XML_SCHEMAV_CVC_TYPE_1; |
26491 | 0 | VERROR(ret, NULL, |
26492 | 0 | "The type definition is absent"); |
26493 | 0 | goto exit; |
26494 | 0 | } |
26495 | 0 | if (vctxt->inode->typeDef->flags & XML_SCHEMAS_TYPE_ABSTRACT) { |
26496 | 0 | vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE; |
26497 | 0 | ret = XML_SCHEMAV_CVC_TYPE_2; |
26498 | 0 | VERROR(ret, NULL, |
26499 | 0 | "The type definition is abstract"); |
26500 | 0 | goto exit; |
26501 | 0 | } |
26502 | | /* |
26503 | | * Evaluate IDCs. Do it here, since new IDC matchers are registered |
26504 | | * during validation against the declaration. This must be done |
26505 | | * _before_ attribute validation. |
26506 | | */ |
26507 | 0 | if (vctxt->xpathStates != NULL) { |
26508 | 0 | ret = xmlSchemaXPathEvaluate(vctxt, XML_ELEMENT_NODE); |
26509 | 0 | vctxt->inode->appliedXPath = 1; |
26510 | 0 | if (ret == -1) { |
26511 | 0 | VERROR_INT("xmlSchemaValidateElem", |
26512 | 0 | "calling xmlSchemaXPathEvaluate()"); |
26513 | 0 | goto internal_error; |
26514 | 0 | } |
26515 | 0 | } |
26516 | | /* |
26517 | | * Validate attributes. |
26518 | | */ |
26519 | 0 | if (WXS_IS_COMPLEX(vctxt->inode->typeDef)) { |
26520 | 0 | if ((vctxt->nbAttrInfos != 0) || |
26521 | 0 | (vctxt->inode->typeDef->attrUses != NULL)) { |
26522 | |
|
26523 | 0 | ret = xmlSchemaVAttributesComplex(vctxt); |
26524 | 0 | } |
26525 | 0 | } else if (vctxt->nbAttrInfos != 0) { |
26526 | |
|
26527 | 0 | ret = xmlSchemaVAttributesSimple(vctxt); |
26528 | 0 | } |
26529 | | /* |
26530 | | * Clear registered attributes. |
26531 | | */ |
26532 | 0 | if (vctxt->nbAttrInfos != 0) |
26533 | 0 | xmlSchemaClearAttrInfos(vctxt); |
26534 | 0 | if (ret == -1) { |
26535 | 0 | VERROR_INT("xmlSchemaValidateElem", |
26536 | 0 | "calling attributes validation"); |
26537 | 0 | goto internal_error; |
26538 | 0 | } |
26539 | | /* |
26540 | | * Don't return an error if attributes are invalid on purpose. |
26541 | | */ |
26542 | 0 | ret = 0; |
26543 | |
|
26544 | 0 | exit: |
26545 | 0 | if (ret != 0) |
26546 | 0 | vctxt->skipDepth = vctxt->depth; |
26547 | 0 | return (ret); |
26548 | 0 | internal_error: |
26549 | 0 | return (-1); |
26550 | 0 | } |
26551 | | |
26552 | | #ifdef XML_SCHEMA_READER_ENABLED |
26553 | | static int |
26554 | | xmlSchemaVReaderWalk(xmlSchemaValidCtxtPtr vctxt) |
26555 | | { |
26556 | | const int WHTSP = 13, SIGN_WHTSP = 14, END_ELEM = 15; |
26557 | | int depth, nodeType, ret = 0, consumed; |
26558 | | xmlSchemaNodeInfoPtr ielem; |
26559 | | |
26560 | | vctxt->depth = -1; |
26561 | | ret = xmlTextReaderRead(vctxt->reader); |
26562 | | /* |
26563 | | * Move to the document element. |
26564 | | */ |
26565 | | while (ret == 1) { |
26566 | | nodeType = xmlTextReaderNodeType(vctxt->reader); |
26567 | | if (nodeType == XML_ELEMENT_NODE) |
26568 | | goto root_found; |
26569 | | ret = xmlTextReaderRead(vctxt->reader); |
26570 | | } |
26571 | | goto exit; |
26572 | | |
26573 | | root_found: |
26574 | | |
26575 | | do { |
26576 | | depth = xmlTextReaderDepth(vctxt->reader); |
26577 | | nodeType = xmlTextReaderNodeType(vctxt->reader); |
26578 | | |
26579 | | if (nodeType == XML_ELEMENT_NODE) { |
26580 | | |
26581 | | vctxt->depth++; |
26582 | | if (xmlSchemaValidatorPushElem(vctxt) == -1) { |
26583 | | VERROR_INT("xmlSchemaVReaderWalk", |
26584 | | "calling xmlSchemaValidatorPushElem()"); |
26585 | | goto internal_error; |
26586 | | } |
26587 | | ielem = vctxt->inode; |
26588 | | ielem->localName = xmlTextReaderLocalName(vctxt->reader); |
26589 | | ielem->nsName = xmlTextReaderNamespaceUri(vctxt->reader); |
26590 | | ielem->flags |= XML_SCHEMA_NODE_INFO_FLAG_OWNED_NAMES; |
26591 | | /* |
26592 | | * Is the element empty? |
26593 | | */ |
26594 | | ret = xmlTextReaderIsEmptyElement(vctxt->reader); |
26595 | | if (ret == -1) { |
26596 | | VERROR_INT("xmlSchemaVReaderWalk", |
26597 | | "calling xmlTextReaderIsEmptyElement()"); |
26598 | | goto internal_error; |
26599 | | } |
26600 | | if (ret) { |
26601 | | ielem->flags |= XML_SCHEMA_ELEM_INFO_EMPTY; |
26602 | | } |
26603 | | /* |
26604 | | * Register attributes. |
26605 | | */ |
26606 | | vctxt->nbAttrInfos = 0; |
26607 | | ret = xmlTextReaderMoveToFirstAttribute(vctxt->reader); |
26608 | | if (ret == -1) { |
26609 | | VERROR_INT("xmlSchemaVReaderWalk", |
26610 | | "calling xmlTextReaderMoveToFirstAttribute()"); |
26611 | | goto internal_error; |
26612 | | } |
26613 | | if (ret == 1) { |
26614 | | do { |
26615 | | /* |
26616 | | * VAL TODO: How do we know that the reader works on a |
26617 | | * node tree, to be able to pass a node here? |
26618 | | */ |
26619 | | if (xmlSchemaValidatorPushAttribute(vctxt, NULL, |
26620 | | (const xmlChar *) xmlTextReaderLocalName(vctxt->reader), |
26621 | | xmlTextReaderNamespaceUri(vctxt->reader), 1, |
26622 | | xmlTextReaderValue(vctxt->reader), 1) == -1) { |
26623 | | |
26624 | | VERROR_INT("xmlSchemaVReaderWalk", |
26625 | | "calling xmlSchemaValidatorPushAttribute()"); |
26626 | | goto internal_error; |
26627 | | } |
26628 | | ret = xmlTextReaderMoveToNextAttribute(vctxt->reader); |
26629 | | if (ret == -1) { |
26630 | | VERROR_INT("xmlSchemaVReaderWalk", |
26631 | | "calling xmlTextReaderMoveToFirstAttribute()"); |
26632 | | goto internal_error; |
26633 | | } |
26634 | | } while (ret == 1); |
26635 | | /* |
26636 | | * Back to element position. |
26637 | | */ |
26638 | | ret = xmlTextReaderMoveToElement(vctxt->reader); |
26639 | | if (ret == -1) { |
26640 | | VERROR_INT("xmlSchemaVReaderWalk", |
26641 | | "calling xmlTextReaderMoveToElement()"); |
26642 | | goto internal_error; |
26643 | | } |
26644 | | } |
26645 | | /* |
26646 | | * Validate the element. |
26647 | | */ |
26648 | | ret= xmlSchemaValidateElem(vctxt); |
26649 | | if (ret != 0) { |
26650 | | if (ret == -1) { |
26651 | | VERROR_INT("xmlSchemaVReaderWalk", |
26652 | | "calling xmlSchemaValidateElem()"); |
26653 | | goto internal_error; |
26654 | | } |
26655 | | goto exit; |
26656 | | } |
26657 | | if (vctxt->depth == vctxt->skipDepth) { |
26658 | | int curDepth; |
26659 | | /* |
26660 | | * Skip all content. |
26661 | | */ |
26662 | | if ((ielem->flags & XML_SCHEMA_ELEM_INFO_EMPTY) == 0) { |
26663 | | ret = xmlTextReaderRead(vctxt->reader); |
26664 | | curDepth = xmlTextReaderDepth(vctxt->reader); |
26665 | | while ((ret == 1) && (curDepth != depth)) { |
26666 | | ret = xmlTextReaderRead(vctxt->reader); |
26667 | | curDepth = xmlTextReaderDepth(vctxt->reader); |
26668 | | } |
26669 | | if (ret < 0) { |
26670 | | /* |
26671 | | * VAL TODO: A reader error occurred; what to do here? |
26672 | | */ |
26673 | | ret = 1; |
26674 | | goto exit; |
26675 | | } |
26676 | | } |
26677 | | goto leave_elem; |
26678 | | } |
26679 | | /* |
26680 | | * READER VAL TODO: Is an END_ELEM really never called |
26681 | | * if the elem is empty? |
26682 | | */ |
26683 | | if (ielem->flags & XML_SCHEMA_ELEM_INFO_EMPTY) |
26684 | | goto leave_elem; |
26685 | | } else if (nodeType == END_ELEM) { |
26686 | | /* |
26687 | | * Process END of element. |
26688 | | */ |
26689 | | leave_elem: |
26690 | | ret = xmlSchemaValidatorPopElem(vctxt); |
26691 | | if (ret != 0) { |
26692 | | if (ret < 0) { |
26693 | | VERROR_INT("xmlSchemaVReaderWalk", |
26694 | | "calling xmlSchemaValidatorPopElem()"); |
26695 | | goto internal_error; |
26696 | | } |
26697 | | goto exit; |
26698 | | } |
26699 | | if (vctxt->depth >= 0) |
26700 | | ielem = vctxt->inode; |
26701 | | else |
26702 | | ielem = NULL; |
26703 | | } else if ((nodeType == XML_TEXT_NODE) || |
26704 | | (nodeType == XML_CDATA_SECTION_NODE) || |
26705 | | (nodeType == WHTSP) || |
26706 | | (nodeType == SIGN_WHTSP)) { |
26707 | | /* |
26708 | | * Process character content. |
26709 | | */ |
26710 | | xmlChar *value; |
26711 | | |
26712 | | if ((nodeType == WHTSP) || (nodeType == SIGN_WHTSP)) |
26713 | | nodeType = XML_TEXT_NODE; |
26714 | | |
26715 | | value = xmlTextReaderValue(vctxt->reader); |
26716 | | ret = xmlSchemaVPushText(vctxt, nodeType, BAD_CAST value, |
26717 | | -1, XML_SCHEMA_PUSH_TEXT_CREATED, &consumed); |
26718 | | if (! consumed) |
26719 | | xmlFree(value); |
26720 | | if (ret == -1) { |
26721 | | VERROR_INT("xmlSchemaVReaderWalk", |
26722 | | "calling xmlSchemaVPushText()"); |
26723 | | goto internal_error; |
26724 | | } |
26725 | | } else if ((nodeType == XML_ENTITY_NODE) || |
26726 | | (nodeType == XML_ENTITY_REF_NODE)) { |
26727 | | /* |
26728 | | * VAL TODO: What to do with entities? |
26729 | | */ |
26730 | | TODO |
26731 | | } |
26732 | | /* |
26733 | | * Read next node. |
26734 | | */ |
26735 | | ret = xmlTextReaderRead(vctxt->reader); |
26736 | | } while (ret == 1); |
26737 | | |
26738 | | exit: |
26739 | | return (ret); |
26740 | | internal_error: |
26741 | | return (-1); |
26742 | | } |
26743 | | #endif |
26744 | | |
26745 | | /************************************************************************ |
26746 | | * * |
26747 | | * SAX validation handlers * |
26748 | | * * |
26749 | | ************************************************************************/ |
26750 | | |
26751 | | /* |
26752 | | * Process text content. |
26753 | | */ |
26754 | | static void |
26755 | | xmlSchemaSAXHandleText(void *ctx, |
26756 | | const xmlChar * ch, |
26757 | | int len) |
26758 | 0 | { |
26759 | 0 | xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctx; |
26760 | |
|
26761 | 0 | if (vctxt->depth < 0) |
26762 | 0 | return; |
26763 | 0 | if ((vctxt->skipDepth != -1) && (vctxt->depth >= vctxt->skipDepth)) |
26764 | 0 | return; |
26765 | 0 | if (vctxt->inode->flags & XML_SCHEMA_ELEM_INFO_EMPTY) |
26766 | 0 | vctxt->inode->flags ^= XML_SCHEMA_ELEM_INFO_EMPTY; |
26767 | 0 | if (xmlSchemaVPushText(vctxt, XML_TEXT_NODE, ch, len, |
26768 | 0 | XML_SCHEMA_PUSH_TEXT_VOLATILE, NULL) == -1) { |
26769 | 0 | VERROR_INT("xmlSchemaSAXHandleCDataSection", |
26770 | 0 | "calling xmlSchemaVPushText()"); |
26771 | 0 | vctxt->err = -1; |
26772 | 0 | xmlStopParser(vctxt->parserCtxt); |
26773 | 0 | } |
26774 | 0 | } |
26775 | | |
26776 | | /* |
26777 | | * Process CDATA content. |
26778 | | */ |
26779 | | static void |
26780 | | xmlSchemaSAXHandleCDataSection(void *ctx, |
26781 | | const xmlChar * ch, |
26782 | | int len) |
26783 | 0 | { |
26784 | 0 | xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctx; |
26785 | |
|
26786 | 0 | if (vctxt->depth < 0) |
26787 | 0 | return; |
26788 | 0 | if ((vctxt->skipDepth != -1) && (vctxt->depth >= vctxt->skipDepth)) |
26789 | 0 | return; |
26790 | 0 | if (vctxt->inode->flags & XML_SCHEMA_ELEM_INFO_EMPTY) |
26791 | 0 | vctxt->inode->flags ^= XML_SCHEMA_ELEM_INFO_EMPTY; |
26792 | 0 | if (xmlSchemaVPushText(vctxt, XML_CDATA_SECTION_NODE, ch, len, |
26793 | 0 | XML_SCHEMA_PUSH_TEXT_VOLATILE, NULL) == -1) { |
26794 | 0 | VERROR_INT("xmlSchemaSAXHandleCDataSection", |
26795 | 0 | "calling xmlSchemaVPushText()"); |
26796 | 0 | vctxt->err = -1; |
26797 | 0 | xmlStopParser(vctxt->parserCtxt); |
26798 | 0 | } |
26799 | 0 | } |
26800 | | |
26801 | | static void |
26802 | | xmlSchemaSAXHandleReference(void *ctx ATTRIBUTE_UNUSED, |
26803 | | const xmlChar * name ATTRIBUTE_UNUSED) |
26804 | 0 | { |
26805 | 0 | xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctx; |
26806 | |
|
26807 | 0 | if (vctxt->depth < 0) |
26808 | 0 | return; |
26809 | 0 | if ((vctxt->skipDepth != -1) && (vctxt->depth >= vctxt->skipDepth)) |
26810 | 0 | return; |
26811 | | /* SAX VAL TODO: What to do here? */ |
26812 | 0 | } |
26813 | | |
26814 | | static void |
26815 | | xmlSchemaSAXHandleStartElementNs(void *ctx, |
26816 | | const xmlChar * localname, |
26817 | | const xmlChar * prefix ATTRIBUTE_UNUSED, |
26818 | | const xmlChar * URI, |
26819 | | int nb_namespaces, |
26820 | | const xmlChar ** namespaces, |
26821 | | int nb_attributes, |
26822 | | int nb_defaulted ATTRIBUTE_UNUSED, |
26823 | | const xmlChar ** attributes) |
26824 | 0 | { |
26825 | 0 | xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctx; |
26826 | 0 | int ret; |
26827 | 0 | xmlSchemaNodeInfoPtr ielem; |
26828 | 0 | int i, j; |
26829 | | |
26830 | | /* |
26831 | | * SAX VAL TODO: What to do with nb_defaulted? |
26832 | | */ |
26833 | | /* |
26834 | | * Skip elements if inside a "skip" wildcard or invalid. |
26835 | | */ |
26836 | 0 | vctxt->depth++; |
26837 | 0 | if ((vctxt->skipDepth != -1) && (vctxt->depth >= vctxt->skipDepth)) |
26838 | 0 | return; |
26839 | | /* |
26840 | | * Push the element. |
26841 | | */ |
26842 | 0 | if (xmlSchemaValidatorPushElem(vctxt) == -1) { |
26843 | 0 | VERROR_INT("xmlSchemaSAXHandleStartElementNs", |
26844 | 0 | "calling xmlSchemaValidatorPushElem()"); |
26845 | 0 | goto internal_error; |
26846 | 0 | } |
26847 | 0 | ielem = vctxt->inode; |
26848 | | /* |
26849 | | * TODO: Is this OK? |
26850 | | */ |
26851 | 0 | ielem->nodeLine = xmlSAX2GetLineNumber(vctxt->parserCtxt); |
26852 | 0 | ielem->localName = localname; |
26853 | 0 | ielem->nsName = URI; |
26854 | 0 | ielem->flags |= XML_SCHEMA_ELEM_INFO_EMPTY; |
26855 | | /* |
26856 | | * Register namespaces on the elem info. |
26857 | | */ |
26858 | 0 | if (nb_namespaces != 0) { |
26859 | | /* |
26860 | | * Although the parser builds its own namespace list, |
26861 | | * we have no access to it, so we'll use an own one. |
26862 | | */ |
26863 | 0 | for (i = 0, j = 0; i < nb_namespaces; i++, j += 2) { |
26864 | | /* |
26865 | | * Store prefix and namespace name. |
26866 | | */ |
26867 | 0 | if (ielem->sizeNsBindings <= ielem->nbNsBindings) { |
26868 | 0 | const xmlChar **tmp; |
26869 | 0 | size_t elemSize = 2 * sizeof(tmp[0]); |
26870 | 0 | int newSize; |
26871 | |
|
26872 | 0 | newSize = xmlGrowCapacity(ielem->sizeNsBindings, elemSize, |
26873 | 0 | 5, XML_MAX_ITEMS); |
26874 | 0 | if (newSize < 0) { |
26875 | 0 | xmlSchemaVErrMemory(vctxt); |
26876 | 0 | goto internal_error; |
26877 | 0 | } |
26878 | 0 | tmp = xmlRealloc(ielem->nsBindings, newSize * elemSize); |
26879 | 0 | if (tmp == NULL) { |
26880 | 0 | xmlSchemaVErrMemory(vctxt); |
26881 | 0 | goto internal_error; |
26882 | 0 | } |
26883 | | |
26884 | 0 | ielem->nsBindings = tmp; |
26885 | 0 | ielem->sizeNsBindings = newSize; |
26886 | 0 | } |
26887 | | |
26888 | 0 | ielem->nsBindings[ielem->nbNsBindings * 2] = namespaces[j]; |
26889 | 0 | if (namespaces[j+1][0] == 0) { |
26890 | | /* |
26891 | | * Handle xmlns="". |
26892 | | */ |
26893 | 0 | ielem->nsBindings[ielem->nbNsBindings * 2 + 1] = NULL; |
26894 | 0 | } else |
26895 | 0 | ielem->nsBindings[ielem->nbNsBindings * 2 + 1] = |
26896 | 0 | namespaces[j+1]; |
26897 | 0 | ielem->nbNsBindings++; |
26898 | 0 | } |
26899 | 0 | } |
26900 | | /* |
26901 | | * Register attributes. |
26902 | | * SAX VAL TODO: We are not adding namespace declaration |
26903 | | * attributes yet. |
26904 | | */ |
26905 | 0 | if (nb_attributes != 0) { |
26906 | 0 | int valueLen, k, l; |
26907 | 0 | xmlChar *value; |
26908 | |
|
26909 | 0 | for (j = 0, i = 0; i < nb_attributes; i++, j += 5) { |
26910 | | /* |
26911 | | * Duplicate the value, changing any & to a literal ampersand. |
26912 | | * |
26913 | | * libxml2 differs from normal SAX here in that it escapes all ampersands |
26914 | | * as & instead of delivering the raw converted string. Changing the |
26915 | | * behavior at this point would break applications that use this API, so |
26916 | | * we are forced to work around it. |
26917 | | */ |
26918 | 0 | valueLen = attributes[j+4] - attributes[j+3]; |
26919 | 0 | value = xmlMalloc(valueLen + 1); |
26920 | 0 | if (value == NULL) { |
26921 | 0 | xmlSchemaVErrMemory(vctxt); |
26922 | 0 | goto internal_error; |
26923 | 0 | } |
26924 | 0 | for (k = 0, l = 0; k < valueLen; l++) { |
26925 | 0 | if (k < valueLen - 4 && |
26926 | 0 | attributes[j+3][k+0] == '&' && |
26927 | 0 | attributes[j+3][k+1] == '#' && |
26928 | 0 | attributes[j+3][k+2] == '3' && |
26929 | 0 | attributes[j+3][k+3] == '8' && |
26930 | 0 | attributes[j+3][k+4] == ';') { |
26931 | 0 | value[l] = '&'; |
26932 | 0 | k += 5; |
26933 | 0 | } else { |
26934 | 0 | value[l] = attributes[j+3][k]; |
26935 | 0 | k++; |
26936 | 0 | } |
26937 | 0 | } |
26938 | 0 | value[l] = '\0'; |
26939 | | /* |
26940 | | * TODO: Set the node line. |
26941 | | */ |
26942 | 0 | ret = xmlSchemaValidatorPushAttribute(vctxt, |
26943 | 0 | NULL, ielem->nodeLine, attributes[j], attributes[j+2], 0, |
26944 | 0 | value, 1); |
26945 | 0 | if (ret == -1) { |
26946 | 0 | VERROR_INT("xmlSchemaSAXHandleStartElementNs", |
26947 | 0 | "calling xmlSchemaValidatorPushAttribute()"); |
26948 | 0 | goto internal_error; |
26949 | 0 | } |
26950 | 0 | } |
26951 | 0 | } |
26952 | | /* |
26953 | | * Validate the element. |
26954 | | */ |
26955 | 0 | ret = xmlSchemaValidateElem(vctxt); |
26956 | 0 | if (ret != 0) { |
26957 | 0 | if (ret == -1) { |
26958 | 0 | VERROR_INT("xmlSchemaSAXHandleStartElementNs", |
26959 | 0 | "calling xmlSchemaValidateElem()"); |
26960 | 0 | goto internal_error; |
26961 | 0 | } |
26962 | 0 | goto exit; |
26963 | 0 | } |
26964 | | |
26965 | 0 | exit: |
26966 | 0 | return; |
26967 | 0 | internal_error: |
26968 | 0 | vctxt->err = -1; |
26969 | 0 | xmlStopParser(vctxt->parserCtxt); |
26970 | 0 | } |
26971 | | |
26972 | | static void |
26973 | | xmlSchemaSAXHandleEndElementNs(void *ctx, |
26974 | | const xmlChar * localname ATTRIBUTE_UNUSED, |
26975 | | const xmlChar * prefix ATTRIBUTE_UNUSED, |
26976 | | const xmlChar * URI ATTRIBUTE_UNUSED) |
26977 | 0 | { |
26978 | 0 | xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctx; |
26979 | 0 | int res; |
26980 | | |
26981 | | /* |
26982 | | * Skip elements if inside a "skip" wildcard or if invalid. |
26983 | | */ |
26984 | 0 | if (vctxt->skipDepth != -1) { |
26985 | 0 | if (vctxt->depth > vctxt->skipDepth) { |
26986 | 0 | vctxt->depth--; |
26987 | 0 | return; |
26988 | 0 | } else |
26989 | 0 | vctxt->skipDepth = -1; |
26990 | 0 | } |
26991 | | /* |
26992 | | * SAX VAL TODO: Just a temporary check. |
26993 | | */ |
26994 | 0 | if ((!xmlStrEqual(vctxt->inode->localName, localname)) || |
26995 | 0 | (!xmlStrEqual(vctxt->inode->nsName, URI))) { |
26996 | 0 | VERROR_INT("xmlSchemaSAXHandleEndElementNs", |
26997 | 0 | "elem pop mismatch"); |
26998 | 0 | } |
26999 | 0 | res = xmlSchemaValidatorPopElem(vctxt); |
27000 | 0 | if (res != 0) { |
27001 | 0 | if (res < 0) { |
27002 | 0 | VERROR_INT("xmlSchemaSAXHandleEndElementNs", |
27003 | 0 | "calling xmlSchemaValidatorPopElem()"); |
27004 | 0 | goto internal_error; |
27005 | 0 | } |
27006 | 0 | goto exit; |
27007 | 0 | } |
27008 | 0 | exit: |
27009 | 0 | return; |
27010 | 0 | internal_error: |
27011 | 0 | vctxt->err = -1; |
27012 | 0 | xmlStopParser(vctxt->parserCtxt); |
27013 | 0 | } |
27014 | | |
27015 | | /************************************************************************ |
27016 | | * * |
27017 | | * Validation interfaces * |
27018 | | * * |
27019 | | ************************************************************************/ |
27020 | | |
27021 | | /** |
27022 | | * Create an XML Schemas validation context based on the given schema. |
27023 | | * |
27024 | | * @param schema a precompiled XML Schemas |
27025 | | * @returns the validation context or NULL in case of error |
27026 | | */ |
27027 | | xmlSchemaValidCtxt * |
27028 | | xmlSchemaNewValidCtxt(xmlSchema *schema) |
27029 | 0 | { |
27030 | 0 | xmlSchemaValidCtxtPtr ret; |
27031 | |
|
27032 | 0 | ret = (xmlSchemaValidCtxtPtr) xmlMalloc(sizeof(xmlSchemaValidCtxt)); |
27033 | 0 | if (ret == NULL) { |
27034 | 0 | xmlSchemaVErrMemory(NULL); |
27035 | 0 | return (NULL); |
27036 | 0 | } |
27037 | 0 | memset(ret, 0, sizeof(xmlSchemaValidCtxt)); |
27038 | 0 | ret->type = XML_SCHEMA_CTXT_VALIDATOR; |
27039 | 0 | ret->dict = xmlDictCreate(); |
27040 | 0 | if (ret->dict == NULL) { |
27041 | 0 | xmlSchemaFreeValidCtxt(ret); |
27042 | 0 | return(NULL); |
27043 | 0 | } |
27044 | 0 | ret->nodeQNames = xmlSchemaItemListCreate(); |
27045 | 0 | if (ret->nodeQNames == NULL) { |
27046 | 0 | xmlSchemaFreeValidCtxt(ret); |
27047 | 0 | return(NULL); |
27048 | 0 | } |
27049 | 0 | ret->schema = schema; |
27050 | 0 | return (ret); |
27051 | 0 | } |
27052 | | |
27053 | | /** |
27054 | | * Workaround to provide file error reporting information when this is |
27055 | | * not provided by current APIs |
27056 | | * |
27057 | | * @param vctxt the schema validation context |
27058 | | * @param filename the file name |
27059 | | */ |
27060 | | void |
27061 | 0 | xmlSchemaValidateSetFilename(xmlSchemaValidCtxt *vctxt, const char *filename) { |
27062 | 0 | if (vctxt == NULL) |
27063 | 0 | return; |
27064 | 0 | if (vctxt->filename != NULL) |
27065 | 0 | xmlFree(vctxt->filename); |
27066 | 0 | if (filename != NULL) |
27067 | 0 | vctxt->filename = (char *) xmlStrdup((const xmlChar *) filename); |
27068 | 0 | else |
27069 | 0 | vctxt->filename = NULL; |
27070 | 0 | } |
27071 | | |
27072 | | /** |
27073 | | * Free the resources associated to the schema validation context; |
27074 | | * leaves some fields alive intended for reuse of the context. |
27075 | | * |
27076 | | * @param vctxt the schema validation context |
27077 | | */ |
27078 | | static void |
27079 | | xmlSchemaClearValidCtxt(xmlSchemaValidCtxtPtr vctxt) |
27080 | 0 | { |
27081 | 0 | if (vctxt == NULL) |
27082 | 0 | return; |
27083 | | |
27084 | | /* |
27085 | | * TODO: Should we clear the flags? |
27086 | | * Might be problematic if one reuses the context |
27087 | | * and assumes that the options remain the same. |
27088 | | */ |
27089 | 0 | vctxt->flags = 0; |
27090 | 0 | vctxt->validationRoot = NULL; |
27091 | 0 | vctxt->doc = NULL; |
27092 | 0 | #ifdef LIBXML_READER_ENABLED |
27093 | 0 | vctxt->reader = NULL; |
27094 | 0 | #endif |
27095 | 0 | vctxt->hasKeyrefs = 0; |
27096 | |
|
27097 | 0 | if (vctxt->value != NULL) { |
27098 | 0 | xmlSchemaFreeValue(vctxt->value); |
27099 | 0 | vctxt->value = NULL; |
27100 | 0 | } |
27101 | | /* |
27102 | | * Augmented IDC information. |
27103 | | */ |
27104 | 0 | if (vctxt->aidcs != NULL) { |
27105 | 0 | xmlSchemaIDCAugPtr cur = vctxt->aidcs, next; |
27106 | 0 | do { |
27107 | 0 | next = cur->next; |
27108 | 0 | xmlFree(cur); |
27109 | 0 | cur = next; |
27110 | 0 | } while (cur != NULL); |
27111 | 0 | vctxt->aidcs = NULL; |
27112 | 0 | } |
27113 | |
|
27114 | 0 | if (vctxt->idcNodes != NULL) { |
27115 | 0 | int i; |
27116 | 0 | xmlSchemaPSVIIDCNodePtr item; |
27117 | |
|
27118 | 0 | for (i = 0; i < vctxt->nbIdcNodes; i++) { |
27119 | 0 | item = vctxt->idcNodes[i]; |
27120 | 0 | xmlFree(item->keys); |
27121 | 0 | xmlFree(item); |
27122 | 0 | } |
27123 | 0 | xmlFree(vctxt->idcNodes); |
27124 | 0 | vctxt->idcNodes = NULL; |
27125 | 0 | vctxt->nbIdcNodes = 0; |
27126 | 0 | vctxt->sizeIdcNodes = 0; |
27127 | 0 | } |
27128 | |
|
27129 | 0 | if (vctxt->idcKeys != NULL) { |
27130 | 0 | int i; |
27131 | 0 | for (i = 0; i < vctxt->nbIdcKeys; i++) |
27132 | 0 | xmlSchemaIDCFreeKey(vctxt->idcKeys[i]); |
27133 | 0 | xmlFree(vctxt->idcKeys); |
27134 | 0 | vctxt->idcKeys = NULL; |
27135 | 0 | vctxt->nbIdcKeys = 0; |
27136 | 0 | vctxt->sizeIdcKeys = 0; |
27137 | 0 | } |
27138 | | |
27139 | | /* |
27140 | | * Note that we won't delete the XPath state pool here. |
27141 | | */ |
27142 | 0 | if (vctxt->xpathStates != NULL) { |
27143 | 0 | xmlSchemaFreeIDCStateObjList(vctxt->xpathStates); |
27144 | 0 | vctxt->xpathStates = NULL; |
27145 | 0 | } |
27146 | | /* |
27147 | | * Attribute info. |
27148 | | */ |
27149 | 0 | if (vctxt->nbAttrInfos != 0) { |
27150 | 0 | xmlSchemaClearAttrInfos(vctxt); |
27151 | 0 | } |
27152 | | /* |
27153 | | * Element info. |
27154 | | */ |
27155 | 0 | if (vctxt->elemInfos != NULL) { |
27156 | 0 | int i; |
27157 | 0 | xmlSchemaNodeInfoPtr ei; |
27158 | |
|
27159 | 0 | for (i = 0; i < vctxt->sizeElemInfos; i++) { |
27160 | 0 | ei = vctxt->elemInfos[i]; |
27161 | 0 | if (ei == NULL) |
27162 | 0 | break; |
27163 | 0 | xmlSchemaClearElemInfo(vctxt, ei); |
27164 | 0 | } |
27165 | 0 | } |
27166 | 0 | xmlSchemaItemListClear(vctxt->nodeQNames); |
27167 | | /* Recreate the dict. */ |
27168 | 0 | xmlDictFree(vctxt->dict); |
27169 | | /* |
27170 | | * TODO: Is is save to recreate it? Do we have a scenario |
27171 | | * where the user provides the dict? |
27172 | | */ |
27173 | 0 | vctxt->dict = xmlDictCreate(); |
27174 | |
|
27175 | 0 | if (vctxt->filename != NULL) { |
27176 | 0 | xmlFree(vctxt->filename); |
27177 | 0 | vctxt->filename = NULL; |
27178 | 0 | } |
27179 | | |
27180 | | /* |
27181 | | * Note that some cleanup functions can move items to the cache, |
27182 | | * so the cache shouldn't be freed too early. |
27183 | | */ |
27184 | 0 | if (vctxt->idcMatcherCache != NULL) { |
27185 | 0 | xmlSchemaIDCMatcherPtr matcher = vctxt->idcMatcherCache, tmp; |
27186 | |
|
27187 | 0 | while (matcher) { |
27188 | 0 | tmp = matcher; |
27189 | 0 | matcher = matcher->nextCached; |
27190 | 0 | xmlSchemaIDCFreeMatcherList(tmp); |
27191 | 0 | } |
27192 | 0 | vctxt->idcMatcherCache = NULL; |
27193 | 0 | } |
27194 | 0 | } |
27195 | | |
27196 | | /** |
27197 | | * Free the resources associated to the schema validation context |
27198 | | * |
27199 | | * @param ctxt the schema validation context |
27200 | | */ |
27201 | | void |
27202 | | xmlSchemaFreeValidCtxt(xmlSchemaValidCtxt *ctxt) |
27203 | 0 | { |
27204 | 0 | if (ctxt == NULL) |
27205 | 0 | return; |
27206 | 0 | if (ctxt->value != NULL) |
27207 | 0 | xmlSchemaFreeValue(ctxt->value); |
27208 | 0 | if (ctxt->pctxt != NULL) |
27209 | 0 | xmlSchemaFreeParserCtxt(ctxt->pctxt); |
27210 | 0 | if (ctxt->idcNodes != NULL) { |
27211 | 0 | int i; |
27212 | 0 | xmlSchemaPSVIIDCNodePtr item; |
27213 | |
|
27214 | 0 | for (i = 0; i < ctxt->nbIdcNodes; i++) { |
27215 | 0 | item = ctxt->idcNodes[i]; |
27216 | 0 | xmlFree(item->keys); |
27217 | 0 | xmlFree(item); |
27218 | 0 | } |
27219 | 0 | xmlFree(ctxt->idcNodes); |
27220 | 0 | } |
27221 | 0 | if (ctxt->idcKeys != NULL) { |
27222 | 0 | int i; |
27223 | 0 | for (i = 0; i < ctxt->nbIdcKeys; i++) |
27224 | 0 | xmlSchemaIDCFreeKey(ctxt->idcKeys[i]); |
27225 | 0 | xmlFree(ctxt->idcKeys); |
27226 | 0 | } |
27227 | |
|
27228 | 0 | if (ctxt->xpathStates != NULL) { |
27229 | 0 | xmlSchemaFreeIDCStateObjList(ctxt->xpathStates); |
27230 | 0 | ctxt->xpathStates = NULL; |
27231 | 0 | } |
27232 | 0 | if (ctxt->xpathStatePool != NULL) { |
27233 | 0 | xmlSchemaFreeIDCStateObjList(ctxt->xpathStatePool); |
27234 | 0 | ctxt->xpathStatePool = NULL; |
27235 | 0 | } |
27236 | | |
27237 | | /* |
27238 | | * Augmented IDC information. |
27239 | | */ |
27240 | 0 | if (ctxt->aidcs != NULL) { |
27241 | 0 | xmlSchemaIDCAugPtr cur = ctxt->aidcs, next; |
27242 | 0 | do { |
27243 | 0 | next = cur->next; |
27244 | 0 | xmlFree(cur); |
27245 | 0 | cur = next; |
27246 | 0 | } while (cur != NULL); |
27247 | 0 | } |
27248 | 0 | if (ctxt->attrInfos != NULL) { |
27249 | 0 | int i; |
27250 | 0 | xmlSchemaAttrInfoPtr attr; |
27251 | | |
27252 | | /* Just a paranoid call to the cleanup. */ |
27253 | 0 | if (ctxt->nbAttrInfos != 0) |
27254 | 0 | xmlSchemaClearAttrInfos(ctxt); |
27255 | 0 | for (i = 0; i < ctxt->sizeAttrInfos; i++) { |
27256 | 0 | attr = ctxt->attrInfos[i]; |
27257 | 0 | xmlFree(attr); |
27258 | 0 | } |
27259 | 0 | xmlFree(ctxt->attrInfos); |
27260 | 0 | } |
27261 | 0 | if (ctxt->elemInfos != NULL) { |
27262 | 0 | int i; |
27263 | 0 | xmlSchemaNodeInfoPtr ei; |
27264 | |
|
27265 | 0 | for (i = 0; i < ctxt->sizeElemInfos; i++) { |
27266 | 0 | ei = ctxt->elemInfos[i]; |
27267 | 0 | if (ei == NULL) |
27268 | 0 | break; |
27269 | 0 | xmlSchemaClearElemInfo(ctxt, ei); |
27270 | 0 | xmlFree(ei); |
27271 | 0 | } |
27272 | 0 | xmlFree(ctxt->elemInfos); |
27273 | 0 | } |
27274 | 0 | if (ctxt->nodeQNames != NULL) |
27275 | 0 | xmlSchemaItemListFree(ctxt->nodeQNames); |
27276 | 0 | if (ctxt->dict != NULL) |
27277 | 0 | xmlDictFree(ctxt->dict); |
27278 | 0 | if (ctxt->filename != NULL) |
27279 | 0 | xmlFree(ctxt->filename); |
27280 | 0 | xmlFree(ctxt); |
27281 | 0 | } |
27282 | | |
27283 | | /** |
27284 | | * Check if any error was detected during validation. |
27285 | | * |
27286 | | * @param ctxt the schema validation context |
27287 | | * @returns 1 if valid so far, 0 if errors were detected, and -1 in case |
27288 | | * of internal error. |
27289 | | */ |
27290 | | int |
27291 | | xmlSchemaIsValid(xmlSchemaValidCtxt *ctxt) |
27292 | 0 | { |
27293 | 0 | if (ctxt == NULL) |
27294 | 0 | return(-1); |
27295 | 0 | return(ctxt->err == 0); |
27296 | 0 | } |
27297 | | |
27298 | | /** |
27299 | | * Set the error and warning callback information |
27300 | | * |
27301 | | * @deprecated Use xmlSchemaSetValidStructuredErrors. |
27302 | | * |
27303 | | * @param ctxt a schema validation context |
27304 | | * @param err the error function |
27305 | | * @param warn the warning function |
27306 | | * @param ctx the functions context |
27307 | | */ |
27308 | | void |
27309 | | xmlSchemaSetValidErrors(xmlSchemaValidCtxt *ctxt, |
27310 | | xmlSchemaValidityErrorFunc err, |
27311 | | xmlSchemaValidityWarningFunc warn, void *ctx) |
27312 | 0 | { |
27313 | 0 | if (ctxt == NULL) |
27314 | 0 | return; |
27315 | 0 | ctxt->error = err; |
27316 | 0 | ctxt->warning = warn; |
27317 | 0 | ctxt->errCtxt = ctx; |
27318 | 0 | if (ctxt->pctxt != NULL) |
27319 | 0 | xmlSchemaSetParserErrors(ctxt->pctxt, err, warn, ctx); |
27320 | 0 | } |
27321 | | |
27322 | | /** |
27323 | | * Set the structured error callback |
27324 | | * |
27325 | | * @param ctxt a schema validation context |
27326 | | * @param serror the structured error function |
27327 | | * @param ctx the functions context |
27328 | | */ |
27329 | | void |
27330 | | xmlSchemaSetValidStructuredErrors(xmlSchemaValidCtxt *ctxt, |
27331 | | xmlStructuredErrorFunc serror, void *ctx) |
27332 | 0 | { |
27333 | 0 | if (ctxt == NULL) |
27334 | 0 | return; |
27335 | 0 | ctxt->serror = serror; |
27336 | 0 | ctxt->error = NULL; |
27337 | 0 | ctxt->warning = NULL; |
27338 | 0 | ctxt->errCtxt = ctx; |
27339 | 0 | if (ctxt->pctxt != NULL) |
27340 | 0 | xmlSchemaSetParserStructuredErrors(ctxt->pctxt, serror, ctx); |
27341 | 0 | } |
27342 | | |
27343 | | /** |
27344 | | * Get the error and warning callback information |
27345 | | * |
27346 | | * @param ctxt a XML-Schema validation context |
27347 | | * @param err the error function result |
27348 | | * @param warn the warning function result |
27349 | | * @param ctx the functions context result |
27350 | | * @returns -1 in case of error and 0 otherwise |
27351 | | */ |
27352 | | int |
27353 | | xmlSchemaGetValidErrors(xmlSchemaValidCtxt *ctxt, |
27354 | | xmlSchemaValidityErrorFunc * err, |
27355 | | xmlSchemaValidityWarningFunc * warn, void **ctx) |
27356 | 0 | { |
27357 | 0 | if (ctxt == NULL) |
27358 | 0 | return (-1); |
27359 | 0 | if (err != NULL) |
27360 | 0 | *err = ctxt->error; |
27361 | 0 | if (warn != NULL) |
27362 | 0 | *warn = ctxt->warning; |
27363 | 0 | if (ctx != NULL) |
27364 | 0 | *ctx = ctxt->errCtxt; |
27365 | 0 | return (0); |
27366 | 0 | } |
27367 | | |
27368 | | |
27369 | | /** |
27370 | | * Sets the options to be used during the validation. |
27371 | | * |
27372 | | * @param ctxt a schema validation context |
27373 | | * @param options a combination of xmlSchemaValidOption |
27374 | | * @returns 0 in case of success, -1 in case of an |
27375 | | * API error. |
27376 | | */ |
27377 | | int |
27378 | | xmlSchemaSetValidOptions(xmlSchemaValidCtxt *ctxt, |
27379 | | int options) |
27380 | | |
27381 | 0 | { |
27382 | 0 | int i; |
27383 | |
|
27384 | 0 | if (ctxt == NULL) |
27385 | 0 | return (-1); |
27386 | | /* |
27387 | | * WARNING: Change the start value if adding to the |
27388 | | * xmlSchemaValidOption. |
27389 | | * TODO: Is there an other, more easy to maintain, |
27390 | | * way? |
27391 | | */ |
27392 | 0 | for (i = 1; i < (int) sizeof(int) * 8; i++) { |
27393 | 0 | if (options & 1<<i) |
27394 | 0 | return (-1); |
27395 | 0 | } |
27396 | 0 | ctxt->options = options; |
27397 | 0 | return (0); |
27398 | 0 | } |
27399 | | |
27400 | | /** |
27401 | | * Get the validation context options. |
27402 | | * |
27403 | | * @param ctxt a schema validation context |
27404 | | * @returns the option combination or -1 on error. |
27405 | | */ |
27406 | | int |
27407 | | xmlSchemaValidCtxtGetOptions(xmlSchemaValidCtxt *ctxt) |
27408 | | |
27409 | 0 | { |
27410 | 0 | if (ctxt == NULL) |
27411 | 0 | return (-1); |
27412 | 0 | else |
27413 | 0 | return (ctxt->options); |
27414 | 0 | } |
27415 | | |
27416 | | static int |
27417 | | xmlSchemaVDocWalk(xmlSchemaValidCtxtPtr vctxt) |
27418 | 0 | { |
27419 | 0 | xmlAttrPtr attr; |
27420 | 0 | int ret = 0; |
27421 | 0 | xmlSchemaNodeInfoPtr ielem = NULL; |
27422 | 0 | xmlNodePtr node, valRoot; |
27423 | 0 | const xmlChar *nsName; |
27424 | | |
27425 | | /* DOC VAL TODO: Move this to the start function. */ |
27426 | 0 | if (vctxt->validationRoot != NULL) |
27427 | 0 | valRoot = vctxt->validationRoot; |
27428 | 0 | else |
27429 | 0 | valRoot = xmlDocGetRootElement(vctxt->doc); |
27430 | 0 | if (valRoot == NULL) { |
27431 | | /* VAL TODO: Error code? */ |
27432 | 0 | VERROR(1, NULL, "The document has no document element"); |
27433 | 0 | return (1); |
27434 | 0 | } |
27435 | 0 | vctxt->depth = -1; |
27436 | 0 | vctxt->validationRoot = valRoot; |
27437 | 0 | node = valRoot; |
27438 | 0 | while (node != NULL) { |
27439 | 0 | if ((vctxt->skipDepth != -1) && (vctxt->depth >= vctxt->skipDepth)) |
27440 | 0 | goto next_sibling; |
27441 | 0 | if (node->type == XML_ELEMENT_NODE) { |
27442 | | |
27443 | | /* |
27444 | | * Init the node-info. |
27445 | | */ |
27446 | 0 | vctxt->depth++; |
27447 | 0 | if (xmlSchemaValidatorPushElem(vctxt) == -1) |
27448 | 0 | goto internal_error; |
27449 | 0 | ielem = vctxt->inode; |
27450 | 0 | ielem->node = node; |
27451 | 0 | ielem->nodeLine = node->line; |
27452 | 0 | ielem->localName = node->name; |
27453 | 0 | if (node->ns != NULL) |
27454 | 0 | ielem->nsName = node->ns->href; |
27455 | 0 | ielem->flags |= XML_SCHEMA_ELEM_INFO_EMPTY; |
27456 | | /* |
27457 | | * Register attributes. |
27458 | | * DOC VAL TODO: We do not register namespace declaration |
27459 | | * attributes yet. |
27460 | | */ |
27461 | 0 | vctxt->nbAttrInfos = 0; |
27462 | 0 | if (node->properties != NULL) { |
27463 | 0 | attr = node->properties; |
27464 | 0 | do { |
27465 | 0 | xmlChar *content; |
27466 | |
|
27467 | 0 | if (attr->ns != NULL) |
27468 | 0 | nsName = attr->ns->href; |
27469 | 0 | else |
27470 | 0 | nsName = NULL; |
27471 | 0 | content = xmlNodeListGetString(attr->doc, |
27472 | 0 | attr->children, 1); |
27473 | 0 | ret = xmlSchemaValidatorPushAttribute(vctxt, |
27474 | 0 | (xmlNodePtr) attr, |
27475 | | /* |
27476 | | * Note that we give it the line number of the |
27477 | | * parent element. |
27478 | | */ |
27479 | 0 | ielem->nodeLine, |
27480 | 0 | attr->name, nsName, 0, |
27481 | 0 | content, 1); |
27482 | 0 | if (ret == -1) { |
27483 | 0 | VERROR_INT("xmlSchemaDocWalk", |
27484 | 0 | "calling xmlSchemaValidatorPushAttribute()"); |
27485 | 0 | xmlFree(content); |
27486 | 0 | goto internal_error; |
27487 | 0 | } |
27488 | 0 | attr = attr->next; |
27489 | 0 | } while (attr); |
27490 | 0 | } |
27491 | | /* |
27492 | | * Validate the element. |
27493 | | */ |
27494 | 0 | ret = xmlSchemaValidateElem(vctxt); |
27495 | 0 | if (ret != 0) { |
27496 | 0 | if (ret == -1) { |
27497 | 0 | VERROR_INT("xmlSchemaDocWalk", |
27498 | 0 | "calling xmlSchemaValidateElem()"); |
27499 | 0 | goto internal_error; |
27500 | 0 | } |
27501 | | /* |
27502 | | * Don't stop validation; just skip the content |
27503 | | * of this element. |
27504 | | */ |
27505 | 0 | goto leave_node; |
27506 | 0 | } |
27507 | 0 | if ((vctxt->skipDepth != -1) && |
27508 | 0 | (vctxt->depth >= vctxt->skipDepth)) |
27509 | 0 | goto leave_node; |
27510 | 0 | } else if ((node->type == XML_TEXT_NODE) || |
27511 | 0 | (node->type == XML_CDATA_SECTION_NODE)) { |
27512 | | /* |
27513 | | * Process character content. |
27514 | | */ |
27515 | 0 | if ((ielem != NULL) && (ielem->flags & XML_SCHEMA_ELEM_INFO_EMPTY)) |
27516 | 0 | ielem->flags ^= XML_SCHEMA_ELEM_INFO_EMPTY; |
27517 | 0 | ret = xmlSchemaVPushText(vctxt, node->type, node->content, |
27518 | 0 | -1, XML_SCHEMA_PUSH_TEXT_PERSIST, NULL); |
27519 | 0 | if (ret < 0) { |
27520 | 0 | VERROR_INT("xmlSchemaVDocWalk", |
27521 | 0 | "calling xmlSchemaVPushText()"); |
27522 | 0 | goto internal_error; |
27523 | 0 | } |
27524 | | /* |
27525 | | * DOC VAL TODO: Should we skip further validation of the |
27526 | | * element content here? |
27527 | | */ |
27528 | 0 | } else if ((node->type == XML_ENTITY_NODE) || |
27529 | 0 | (node->type == XML_ENTITY_REF_NODE)) { |
27530 | | /* |
27531 | | * DOC VAL TODO: What to do with entities? |
27532 | | */ |
27533 | 0 | VERROR_INT("xmlSchemaVDocWalk", |
27534 | 0 | "there is at least one entity reference in the node-tree " |
27535 | 0 | "currently being validated. Processing of entities with " |
27536 | 0 | "this XML Schema processor is not supported (yet). Please " |
27537 | 0 | "substitute entities before validation."); |
27538 | 0 | goto internal_error; |
27539 | 0 | } else { |
27540 | 0 | goto leave_node; |
27541 | | /* |
27542 | | * DOC VAL TODO: XInclude nodes, etc. |
27543 | | */ |
27544 | 0 | } |
27545 | | /* |
27546 | | * Walk the doc. |
27547 | | */ |
27548 | 0 | if (node->children != NULL) { |
27549 | 0 | node = node->children; |
27550 | 0 | continue; |
27551 | 0 | } |
27552 | 0 | leave_node: |
27553 | 0 | if (node->type == XML_ELEMENT_NODE) { |
27554 | | /* |
27555 | | * Leaving the scope of an element. |
27556 | | */ |
27557 | 0 | if (node != vctxt->inode->node) { |
27558 | 0 | VERROR_INT("xmlSchemaVDocWalk", |
27559 | 0 | "element position mismatch"); |
27560 | 0 | goto internal_error; |
27561 | 0 | } |
27562 | 0 | ret = xmlSchemaValidatorPopElem(vctxt); |
27563 | 0 | if (ret != 0) { |
27564 | 0 | if (ret < 0) { |
27565 | 0 | VERROR_INT("xmlSchemaVDocWalk", |
27566 | 0 | "calling xmlSchemaValidatorPopElem()"); |
27567 | 0 | goto internal_error; |
27568 | 0 | } |
27569 | 0 | } |
27570 | 0 | if (node == valRoot) |
27571 | 0 | goto exit; |
27572 | 0 | } |
27573 | 0 | next_sibling: |
27574 | 0 | if (node->next != NULL) |
27575 | 0 | node = node->next; |
27576 | 0 | else { |
27577 | 0 | node = node->parent; |
27578 | 0 | goto leave_node; |
27579 | 0 | } |
27580 | 0 | } |
27581 | | |
27582 | 0 | exit: |
27583 | 0 | return (ret); |
27584 | 0 | internal_error: |
27585 | 0 | return (-1); |
27586 | 0 | } |
27587 | | |
27588 | | static int |
27589 | 0 | xmlSchemaPreRun(xmlSchemaValidCtxtPtr vctxt) { |
27590 | | /* |
27591 | | * Some initialization. |
27592 | | */ |
27593 | 0 | vctxt->err = 0; |
27594 | 0 | vctxt->nberrors = 0; |
27595 | 0 | vctxt->depth = -1; |
27596 | 0 | vctxt->skipDepth = -1; |
27597 | 0 | vctxt->hasKeyrefs = 0; |
27598 | | #ifdef ENABLE_IDC_NODE_TABLES_TEST |
27599 | | vctxt->createIDCNodeTables = 1; |
27600 | | #else |
27601 | 0 | vctxt->createIDCNodeTables = 0; |
27602 | 0 | #endif |
27603 | | /* |
27604 | | * Create a schema + parser if necessary. |
27605 | | */ |
27606 | 0 | if (vctxt->schema == NULL) { |
27607 | 0 | xmlSchemaParserCtxtPtr pctxt; |
27608 | |
|
27609 | 0 | vctxt->xsiAssemble = 1; |
27610 | | /* |
27611 | | * If not schema was given then we will create a schema |
27612 | | * dynamically using XSI schema locations. |
27613 | | * |
27614 | | * Create the schema parser context. |
27615 | | */ |
27616 | 0 | if ((vctxt->pctxt == NULL) && |
27617 | 0 | (xmlSchemaCreatePCtxtOnVCtxt(vctxt) == -1)) |
27618 | 0 | return (-1); |
27619 | 0 | pctxt = vctxt->pctxt; |
27620 | 0 | pctxt->xsiAssemble = 1; |
27621 | | /* |
27622 | | * Create the schema. |
27623 | | */ |
27624 | 0 | vctxt->schema = xmlSchemaNewSchema(pctxt); |
27625 | 0 | if (vctxt->schema == NULL) |
27626 | 0 | return (-1); |
27627 | | /* |
27628 | | * Create the schema construction context. |
27629 | | */ |
27630 | 0 | pctxt->constructor = xmlSchemaConstructionCtxtCreate(pctxt->dict); |
27631 | 0 | if (pctxt->constructor == NULL) |
27632 | 0 | return(-1); |
27633 | 0 | pctxt->constructor->mainSchema = vctxt->schema; |
27634 | | /* |
27635 | | * Take ownership of the constructor to be able to free it. |
27636 | | */ |
27637 | 0 | pctxt->ownsConstructor = 1; |
27638 | 0 | } |
27639 | | /* |
27640 | | * Augment the IDC definitions for the main schema and all imported ones |
27641 | | * NOTE: main schema if the first in the imported list |
27642 | | */ |
27643 | 0 | xmlHashScan(vctxt->schema->schemasImports, xmlSchemaAugmentImportedIDC, |
27644 | 0 | vctxt); |
27645 | |
|
27646 | 0 | return(0); |
27647 | 0 | } |
27648 | | |
27649 | | static void |
27650 | 0 | xmlSchemaPostRun(xmlSchemaValidCtxtPtr vctxt) { |
27651 | 0 | if (vctxt->xsiAssemble) { |
27652 | 0 | if (vctxt->schema != NULL) { |
27653 | 0 | xmlSchemaFree(vctxt->schema); |
27654 | 0 | vctxt->schema = NULL; |
27655 | 0 | } |
27656 | 0 | } |
27657 | 0 | xmlSchemaClearValidCtxt(vctxt); |
27658 | 0 | } |
27659 | | |
27660 | | static int |
27661 | | xmlSchemaVStart(xmlSchemaValidCtxtPtr vctxt) |
27662 | 0 | { |
27663 | 0 | int ret = 0; |
27664 | |
|
27665 | 0 | if (xmlSchemaPreRun(vctxt) < 0) |
27666 | 0 | return(-1); |
27667 | | |
27668 | 0 | if (vctxt->doc != NULL) { |
27669 | | /* |
27670 | | * Tree validation. |
27671 | | */ |
27672 | 0 | ret = xmlSchemaVDocWalk(vctxt); |
27673 | 0 | #ifdef LIBXML_READER_ENABLED |
27674 | 0 | } else if (vctxt->reader != NULL) { |
27675 | | /* |
27676 | | * XML Reader validation. |
27677 | | */ |
27678 | | #ifdef XML_SCHEMA_READER_ENABLED |
27679 | | ret = xmlSchemaVReaderWalk(vctxt); |
27680 | | #endif |
27681 | 0 | #endif |
27682 | 0 | } else if ((vctxt->sax != NULL) && (vctxt->parserCtxt != NULL)) { |
27683 | | /* |
27684 | | * SAX validation. |
27685 | | */ |
27686 | 0 | ret = xmlParseDocument(vctxt->parserCtxt); |
27687 | 0 | } else { |
27688 | 0 | VERROR_INT("xmlSchemaVStart", |
27689 | 0 | "no instance to validate"); |
27690 | 0 | ret = -1; |
27691 | 0 | } |
27692 | |
|
27693 | 0 | xmlSchemaPostRun(vctxt); |
27694 | 0 | if (ret == 0) |
27695 | 0 | ret = vctxt->err; |
27696 | 0 | return (ret); |
27697 | 0 | } |
27698 | | |
27699 | | /** |
27700 | | * Validate a branch of a tree, starting with the given `elem`. |
27701 | | * |
27702 | | * @param ctxt a schema validation context |
27703 | | * @param elem an element node |
27704 | | * @returns 0 if the element and its subtree is valid, a positive error |
27705 | | * code number otherwise and -1 in case of an internal or API error. |
27706 | | */ |
27707 | | int |
27708 | | xmlSchemaValidateOneElement(xmlSchemaValidCtxt *ctxt, xmlNode *elem) |
27709 | 0 | { |
27710 | 0 | if ((ctxt == NULL) || (elem == NULL) || (elem->type != XML_ELEMENT_NODE)) |
27711 | 0 | return (-1); |
27712 | | |
27713 | 0 | if (ctxt->schema == NULL) |
27714 | 0 | return (-1); |
27715 | | |
27716 | 0 | ctxt->doc = elem->doc; |
27717 | 0 | ctxt->node = elem; |
27718 | 0 | ctxt->validationRoot = elem; |
27719 | 0 | return(xmlSchemaVStart(ctxt)); |
27720 | 0 | } |
27721 | | |
27722 | | /** |
27723 | | * Validate a document tree in memory. |
27724 | | * |
27725 | | * @param ctxt a schema validation context |
27726 | | * @param doc a parsed document tree |
27727 | | * @returns 0 if the document is schemas valid, a positive error code |
27728 | | * number otherwise and -1 in case of internal or API error. |
27729 | | */ |
27730 | | int |
27731 | | xmlSchemaValidateDoc(xmlSchemaValidCtxt *ctxt, xmlDoc *doc) |
27732 | 0 | { |
27733 | 0 | if ((ctxt == NULL) || (doc == NULL)) |
27734 | 0 | return (-1); |
27735 | | |
27736 | 0 | ctxt->doc = doc; |
27737 | 0 | ctxt->node = xmlDocGetRootElement(doc); |
27738 | 0 | if (ctxt->node == NULL) { |
27739 | 0 | xmlSchemaCustomErr(ACTXT_CAST ctxt, |
27740 | 0 | XML_SCHEMAV_DOCUMENT_ELEMENT_MISSING, |
27741 | 0 | (xmlNodePtr) doc, NULL, |
27742 | 0 | "The document has no document element", NULL, NULL); |
27743 | 0 | return (ctxt->err); |
27744 | 0 | } |
27745 | 0 | ctxt->validationRoot = ctxt->node; |
27746 | 0 | return (xmlSchemaVStart(ctxt)); |
27747 | 0 | } |
27748 | | |
27749 | | |
27750 | | /************************************************************************ |
27751 | | * * |
27752 | | * Function and data for SAX streaming API * |
27753 | | * * |
27754 | | ************************************************************************/ |
27755 | | typedef struct _xmlSchemaSplitSAXData xmlSchemaSplitSAXData; |
27756 | | typedef xmlSchemaSplitSAXData *xmlSchemaSplitSAXDataPtr; |
27757 | | |
27758 | | struct _xmlSchemaSplitSAXData { |
27759 | | xmlSAXHandlerPtr user_sax; |
27760 | | void *user_data; |
27761 | | xmlSchemaValidCtxtPtr ctxt; |
27762 | | xmlSAXHandlerPtr schemas_sax; |
27763 | | }; |
27764 | | |
27765 | 0 | #define XML_SAX_PLUG_MAGIC 0xdc43ba21 |
27766 | | |
27767 | | struct _xmlSchemaSAXPlug { |
27768 | | unsigned int magic; |
27769 | | |
27770 | | /* the original callbacks information */ |
27771 | | xmlSAXHandlerPtr *user_sax_ptr; |
27772 | | xmlSAXHandlerPtr user_sax; |
27773 | | void **user_data_ptr; |
27774 | | void *user_data; |
27775 | | |
27776 | | /* the block plugged back and validation information */ |
27777 | | xmlSAXHandler schemas_sax; |
27778 | | xmlSchemaValidCtxtPtr ctxt; |
27779 | | }; |
27780 | | |
27781 | | /* All those functions just bounces to the user provided SAX handlers */ |
27782 | | static void |
27783 | | internalSubsetSplit(void *ctx, const xmlChar *name, |
27784 | | const xmlChar *ExternalID, const xmlChar *SystemID) |
27785 | 0 | { |
27786 | 0 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
27787 | 0 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
27788 | 0 | (ctxt->user_sax->internalSubset != NULL)) |
27789 | 0 | ctxt->user_sax->internalSubset(ctxt->user_data, name, ExternalID, |
27790 | 0 | SystemID); |
27791 | 0 | } |
27792 | | |
27793 | | static int |
27794 | | isStandaloneSplit(void *ctx) |
27795 | 0 | { |
27796 | 0 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
27797 | 0 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
27798 | 0 | (ctxt->user_sax->isStandalone != NULL)) |
27799 | 0 | return(ctxt->user_sax->isStandalone(ctxt->user_data)); |
27800 | 0 | return(0); |
27801 | 0 | } |
27802 | | |
27803 | | static int |
27804 | | hasInternalSubsetSplit(void *ctx) |
27805 | 0 | { |
27806 | 0 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
27807 | 0 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
27808 | 0 | (ctxt->user_sax->hasInternalSubset != NULL)) |
27809 | 0 | return(ctxt->user_sax->hasInternalSubset(ctxt->user_data)); |
27810 | 0 | return(0); |
27811 | 0 | } |
27812 | | |
27813 | | static int |
27814 | | hasExternalSubsetSplit(void *ctx) |
27815 | 0 | { |
27816 | 0 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
27817 | 0 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
27818 | 0 | (ctxt->user_sax->hasExternalSubset != NULL)) |
27819 | 0 | return(ctxt->user_sax->hasExternalSubset(ctxt->user_data)); |
27820 | 0 | return(0); |
27821 | 0 | } |
27822 | | |
27823 | | static void |
27824 | | externalSubsetSplit(void *ctx, const xmlChar *name, |
27825 | | const xmlChar *ExternalID, const xmlChar *SystemID) |
27826 | 0 | { |
27827 | 0 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
27828 | 0 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
27829 | 0 | (ctxt->user_sax->externalSubset != NULL)) |
27830 | 0 | ctxt->user_sax->externalSubset(ctxt->user_data, name, ExternalID, |
27831 | 0 | SystemID); |
27832 | 0 | } |
27833 | | |
27834 | | static xmlParserInputPtr |
27835 | | resolveEntitySplit(void *ctx, const xmlChar *publicId, const xmlChar *systemId) |
27836 | 0 | { |
27837 | 0 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
27838 | 0 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
27839 | 0 | (ctxt->user_sax->resolveEntity != NULL)) |
27840 | 0 | return(ctxt->user_sax->resolveEntity(ctxt->user_data, publicId, |
27841 | 0 | systemId)); |
27842 | 0 | return(NULL); |
27843 | 0 | } |
27844 | | |
27845 | | static xmlEntityPtr |
27846 | | getEntitySplit(void *ctx, const xmlChar *name) |
27847 | 0 | { |
27848 | 0 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
27849 | 0 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
27850 | 0 | (ctxt->user_sax->getEntity != NULL)) |
27851 | 0 | return(ctxt->user_sax->getEntity(ctxt->user_data, name)); |
27852 | 0 | return(NULL); |
27853 | 0 | } |
27854 | | |
27855 | | static xmlEntityPtr |
27856 | | getParameterEntitySplit(void *ctx, const xmlChar *name) |
27857 | 0 | { |
27858 | 0 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
27859 | 0 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
27860 | 0 | (ctxt->user_sax->getParameterEntity != NULL)) |
27861 | 0 | return(ctxt->user_sax->getParameterEntity(ctxt->user_data, name)); |
27862 | 0 | return(NULL); |
27863 | 0 | } |
27864 | | |
27865 | | |
27866 | | static void |
27867 | | entityDeclSplit(void *ctx, const xmlChar *name, int type, |
27868 | | const xmlChar *publicId, const xmlChar *systemId, xmlChar *content) |
27869 | 0 | { |
27870 | 0 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
27871 | 0 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
27872 | 0 | (ctxt->user_sax->entityDecl != NULL)) |
27873 | 0 | ctxt->user_sax->entityDecl(ctxt->user_data, name, type, publicId, |
27874 | 0 | systemId, content); |
27875 | 0 | } |
27876 | | |
27877 | | static void |
27878 | | attributeDeclSplit(void *ctx, const xmlChar * elem, |
27879 | | const xmlChar * name, int type, int def, |
27880 | | const xmlChar * defaultValue, xmlEnumerationPtr tree) |
27881 | 0 | { |
27882 | 0 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
27883 | 0 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
27884 | 0 | (ctxt->user_sax->attributeDecl != NULL)) { |
27885 | 0 | ctxt->user_sax->attributeDecl(ctxt->user_data, elem, name, type, |
27886 | 0 | def, defaultValue, tree); |
27887 | 0 | } else { |
27888 | 0 | xmlFreeEnumeration(tree); |
27889 | 0 | } |
27890 | 0 | } |
27891 | | |
27892 | | static void |
27893 | | elementDeclSplit(void *ctx, const xmlChar *name, int type, |
27894 | | xmlElementContentPtr content) |
27895 | 0 | { |
27896 | 0 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
27897 | 0 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
27898 | 0 | (ctxt->user_sax->elementDecl != NULL)) |
27899 | 0 | ctxt->user_sax->elementDecl(ctxt->user_data, name, type, content); |
27900 | 0 | } |
27901 | | |
27902 | | static void |
27903 | | notationDeclSplit(void *ctx, const xmlChar *name, |
27904 | | const xmlChar *publicId, const xmlChar *systemId) |
27905 | 0 | { |
27906 | 0 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
27907 | 0 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
27908 | 0 | (ctxt->user_sax->notationDecl != NULL)) |
27909 | 0 | ctxt->user_sax->notationDecl(ctxt->user_data, name, publicId, |
27910 | 0 | systemId); |
27911 | 0 | } |
27912 | | |
27913 | | static void |
27914 | | unparsedEntityDeclSplit(void *ctx, const xmlChar *name, |
27915 | | const xmlChar *publicId, const xmlChar *systemId, |
27916 | | const xmlChar *notationName) |
27917 | 0 | { |
27918 | 0 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
27919 | 0 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
27920 | 0 | (ctxt->user_sax->unparsedEntityDecl != NULL)) |
27921 | 0 | ctxt->user_sax->unparsedEntityDecl(ctxt->user_data, name, publicId, |
27922 | 0 | systemId, notationName); |
27923 | 0 | } |
27924 | | |
27925 | | static void |
27926 | | setDocumentLocatorSplit(void *ctx, xmlSAXLocatorPtr loc) |
27927 | 0 | { |
27928 | 0 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
27929 | 0 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
27930 | 0 | (ctxt->user_sax->setDocumentLocator != NULL)) |
27931 | 0 | ctxt->user_sax->setDocumentLocator(ctxt->user_data, loc); |
27932 | 0 | } |
27933 | | |
27934 | | static void |
27935 | | startDocumentSplit(void *ctx) |
27936 | 0 | { |
27937 | 0 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
27938 | 0 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
27939 | 0 | (ctxt->user_sax->startDocument != NULL)) |
27940 | 0 | ctxt->user_sax->startDocument(ctxt->user_data); |
27941 | 0 | } |
27942 | | |
27943 | | static void |
27944 | | endDocumentSplit(void *ctx) |
27945 | 0 | { |
27946 | 0 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
27947 | 0 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
27948 | 0 | (ctxt->user_sax->endDocument != NULL)) |
27949 | 0 | ctxt->user_sax->endDocument(ctxt->user_data); |
27950 | 0 | } |
27951 | | |
27952 | | static void |
27953 | | processingInstructionSplit(void *ctx, const xmlChar *target, |
27954 | | const xmlChar *data) |
27955 | 0 | { |
27956 | 0 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
27957 | 0 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
27958 | 0 | (ctxt->user_sax->processingInstruction != NULL)) |
27959 | 0 | ctxt->user_sax->processingInstruction(ctxt->user_data, target, data); |
27960 | 0 | } |
27961 | | |
27962 | | static void |
27963 | | commentSplit(void *ctx, const xmlChar *value) |
27964 | 0 | { |
27965 | 0 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
27966 | 0 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
27967 | 0 | (ctxt->user_sax->comment != NULL)) |
27968 | 0 | ctxt->user_sax->comment(ctxt->user_data, value); |
27969 | 0 | } |
27970 | | |
27971 | | /* |
27972 | | * Varargs error callbacks to the user application, harder ... |
27973 | | */ |
27974 | | |
27975 | | static void |
27976 | 0 | warningSplit(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...) { |
27977 | 0 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
27978 | 0 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
27979 | 0 | (ctxt->user_sax->warning != NULL)) { |
27980 | | /* TODO */ |
27981 | 0 | } |
27982 | 0 | } |
27983 | | static void |
27984 | 0 | errorSplit(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...) { |
27985 | 0 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
27986 | 0 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
27987 | 0 | (ctxt->user_sax->error != NULL)) { |
27988 | | /* TODO */ |
27989 | 0 | } |
27990 | 0 | } |
27991 | | static void |
27992 | 0 | fatalErrorSplit(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...) { |
27993 | 0 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
27994 | 0 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
27995 | 0 | (ctxt->user_sax->fatalError != NULL)) { |
27996 | | /* TODO */ |
27997 | 0 | } |
27998 | 0 | } |
27999 | | |
28000 | | /* |
28001 | | * Those are function where both the user handler and the schemas handler |
28002 | | * need to be called. |
28003 | | */ |
28004 | | static void |
28005 | | charactersSplit(void *ctx, const xmlChar *ch, int len) |
28006 | 0 | { |
28007 | 0 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
28008 | 0 | if (ctxt == NULL) |
28009 | 0 | return; |
28010 | 0 | if ((ctxt->user_sax != NULL) && (ctxt->user_sax->characters != NULL)) |
28011 | 0 | ctxt->user_sax->characters(ctxt->user_data, ch, len); |
28012 | 0 | if (ctxt->ctxt != NULL) |
28013 | 0 | xmlSchemaSAXHandleText(ctxt->ctxt, ch, len); |
28014 | 0 | } |
28015 | | |
28016 | | static void |
28017 | | ignorableWhitespaceSplit(void *ctx, const xmlChar *ch, int len) |
28018 | 0 | { |
28019 | 0 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
28020 | 0 | if (ctxt == NULL) |
28021 | 0 | return; |
28022 | 0 | if ((ctxt->user_sax != NULL) && |
28023 | 0 | (ctxt->user_sax->ignorableWhitespace != NULL)) |
28024 | 0 | ctxt->user_sax->ignorableWhitespace(ctxt->user_data, ch, len); |
28025 | 0 | if (ctxt->ctxt != NULL) |
28026 | 0 | xmlSchemaSAXHandleText(ctxt->ctxt, ch, len); |
28027 | 0 | } |
28028 | | |
28029 | | static void |
28030 | | cdataBlockSplit(void *ctx, const xmlChar *value, int len) |
28031 | 0 | { |
28032 | 0 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
28033 | 0 | if (ctxt == NULL) |
28034 | 0 | return; |
28035 | 0 | if ((ctxt->user_sax != NULL) && |
28036 | 0 | (ctxt->user_sax->cdataBlock != NULL)) |
28037 | 0 | ctxt->user_sax->cdataBlock(ctxt->user_data, value, len); |
28038 | 0 | if (ctxt->ctxt != NULL) |
28039 | 0 | xmlSchemaSAXHandleCDataSection(ctxt->ctxt, value, len); |
28040 | 0 | } |
28041 | | |
28042 | | static void |
28043 | | referenceSplit(void *ctx, const xmlChar *name) |
28044 | 0 | { |
28045 | 0 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
28046 | 0 | if (ctxt == NULL) |
28047 | 0 | return; |
28048 | 0 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
28049 | 0 | (ctxt->user_sax->reference != NULL)) |
28050 | 0 | ctxt->user_sax->reference(ctxt->user_data, name); |
28051 | 0 | if (ctxt->ctxt != NULL) |
28052 | 0 | xmlSchemaSAXHandleReference(ctxt->user_data, name); |
28053 | 0 | } |
28054 | | |
28055 | | static void |
28056 | | startElementNsSplit(void *ctx, const xmlChar * localname, |
28057 | | const xmlChar * prefix, const xmlChar * URI, |
28058 | | int nb_namespaces, const xmlChar ** namespaces, |
28059 | | int nb_attributes, int nb_defaulted, |
28060 | 0 | const xmlChar ** attributes) { |
28061 | 0 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
28062 | 0 | if (ctxt == NULL) |
28063 | 0 | return; |
28064 | 0 | if ((ctxt->user_sax != NULL) && |
28065 | 0 | (ctxt->user_sax->startElementNs != NULL)) |
28066 | 0 | ctxt->user_sax->startElementNs(ctxt->user_data, localname, prefix, |
28067 | 0 | URI, nb_namespaces, namespaces, |
28068 | 0 | nb_attributes, nb_defaulted, |
28069 | 0 | attributes); |
28070 | 0 | if (ctxt->ctxt != NULL) |
28071 | 0 | xmlSchemaSAXHandleStartElementNs(ctxt->ctxt, localname, prefix, |
28072 | 0 | URI, nb_namespaces, namespaces, |
28073 | 0 | nb_attributes, nb_defaulted, |
28074 | 0 | attributes); |
28075 | 0 | } |
28076 | | |
28077 | | static void |
28078 | | endElementNsSplit(void *ctx, const xmlChar * localname, |
28079 | 0 | const xmlChar * prefix, const xmlChar * URI) { |
28080 | 0 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
28081 | 0 | if (ctxt == NULL) |
28082 | 0 | return; |
28083 | 0 | if ((ctxt->user_sax != NULL) && |
28084 | 0 | (ctxt->user_sax->endElementNs != NULL)) |
28085 | 0 | ctxt->user_sax->endElementNs(ctxt->user_data, localname, prefix, URI); |
28086 | 0 | if (ctxt->ctxt != NULL) |
28087 | 0 | xmlSchemaSAXHandleEndElementNs(ctxt->ctxt, localname, prefix, URI); |
28088 | 0 | } |
28089 | | |
28090 | | /** |
28091 | | * Plug a SAX based validation layer in a SAX parsing event flow. |
28092 | | * The original `saxptr` and `dataptr` data are replaced by new pointers |
28093 | | * but the calls to the original will be maintained. |
28094 | | * |
28095 | | * @param ctxt a schema validation context |
28096 | | * @param sax a pointer to the original xmlSAXHandler |
28097 | | * @param user_data a pointer to the original SAX user data pointer |
28098 | | * @returns a pointer to a data structure needed to unplug the validation layer |
28099 | | * or NULL in case of errors. |
28100 | | */ |
28101 | | xmlSchemaSAXPlugStruct * |
28102 | | xmlSchemaSAXPlug(xmlSchemaValidCtxt *ctxt, |
28103 | | xmlSAXHandler **sax, void **user_data) |
28104 | 0 | { |
28105 | 0 | xmlSchemaSAXPlugPtr ret; |
28106 | 0 | xmlSAXHandlerPtr old_sax; |
28107 | |
|
28108 | 0 | if ((ctxt == NULL) || (sax == NULL) || (user_data == NULL)) |
28109 | 0 | return(NULL); |
28110 | | |
28111 | | /* |
28112 | | * We only allow to plug into SAX2 event streams |
28113 | | */ |
28114 | 0 | old_sax = *sax; |
28115 | 0 | if ((old_sax != NULL) && (old_sax->initialized != XML_SAX2_MAGIC)) |
28116 | 0 | return(NULL); |
28117 | 0 | if ((old_sax != NULL) && |
28118 | 0 | (old_sax->startElementNs == NULL) && (old_sax->endElementNs == NULL) && |
28119 | 0 | ((old_sax->startElement != NULL) || (old_sax->endElement != NULL))) |
28120 | 0 | return(NULL); |
28121 | | |
28122 | | /* |
28123 | | * everything seems right allocate the local data needed for that layer |
28124 | | */ |
28125 | 0 | ret = (xmlSchemaSAXPlugPtr) xmlMalloc(sizeof(xmlSchemaSAXPlugStruct)); |
28126 | 0 | if (ret == NULL) { |
28127 | 0 | return(NULL); |
28128 | 0 | } |
28129 | 0 | memset(ret, 0, sizeof(xmlSchemaSAXPlugStruct)); |
28130 | 0 | ret->magic = XML_SAX_PLUG_MAGIC; |
28131 | 0 | ret->schemas_sax.initialized = XML_SAX2_MAGIC; |
28132 | 0 | ret->ctxt = ctxt; |
28133 | 0 | ret->user_sax_ptr = sax; |
28134 | 0 | ret->user_sax = old_sax; |
28135 | 0 | if (old_sax == NULL) { |
28136 | | /* |
28137 | | * go direct, no need for the split block and functions. |
28138 | | */ |
28139 | 0 | ret->schemas_sax.startElementNs = xmlSchemaSAXHandleStartElementNs; |
28140 | 0 | ret->schemas_sax.endElementNs = xmlSchemaSAXHandleEndElementNs; |
28141 | | /* |
28142 | | * Note that we use the same text-function for both, to prevent |
28143 | | * the parser from testing for ignorable whitespace. |
28144 | | */ |
28145 | 0 | ret->schemas_sax.ignorableWhitespace = xmlSchemaSAXHandleText; |
28146 | 0 | ret->schemas_sax.characters = xmlSchemaSAXHandleText; |
28147 | |
|
28148 | 0 | ret->schemas_sax.cdataBlock = xmlSchemaSAXHandleCDataSection; |
28149 | 0 | ret->schemas_sax.reference = xmlSchemaSAXHandleReference; |
28150 | |
|
28151 | 0 | ret->user_data = ctxt; |
28152 | 0 | *user_data = ctxt; |
28153 | 0 | } else { |
28154 | | /* |
28155 | | * for each callback unused by Schemas initialize it to the Split |
28156 | | * routine only if non NULL in the user block, this can speed up |
28157 | | * things at the SAX level. |
28158 | | */ |
28159 | 0 | if (old_sax->internalSubset != NULL) |
28160 | 0 | ret->schemas_sax.internalSubset = internalSubsetSplit; |
28161 | 0 | if (old_sax->isStandalone != NULL) |
28162 | 0 | ret->schemas_sax.isStandalone = isStandaloneSplit; |
28163 | 0 | if (old_sax->hasInternalSubset != NULL) |
28164 | 0 | ret->schemas_sax.hasInternalSubset = hasInternalSubsetSplit; |
28165 | 0 | if (old_sax->hasExternalSubset != NULL) |
28166 | 0 | ret->schemas_sax.hasExternalSubset = hasExternalSubsetSplit; |
28167 | 0 | if (old_sax->resolveEntity != NULL) |
28168 | 0 | ret->schemas_sax.resolveEntity = resolveEntitySplit; |
28169 | 0 | if (old_sax->getEntity != NULL) |
28170 | 0 | ret->schemas_sax.getEntity = getEntitySplit; |
28171 | 0 | if (old_sax->entityDecl != NULL) |
28172 | 0 | ret->schemas_sax.entityDecl = entityDeclSplit; |
28173 | 0 | if (old_sax->notationDecl != NULL) |
28174 | 0 | ret->schemas_sax.notationDecl = notationDeclSplit; |
28175 | 0 | if (old_sax->attributeDecl != NULL) |
28176 | 0 | ret->schemas_sax.attributeDecl = attributeDeclSplit; |
28177 | 0 | if (old_sax->elementDecl != NULL) |
28178 | 0 | ret->schemas_sax.elementDecl = elementDeclSplit; |
28179 | 0 | if (old_sax->unparsedEntityDecl != NULL) |
28180 | 0 | ret->schemas_sax.unparsedEntityDecl = unparsedEntityDeclSplit; |
28181 | 0 | if (old_sax->setDocumentLocator != NULL) |
28182 | 0 | ret->schemas_sax.setDocumentLocator = setDocumentLocatorSplit; |
28183 | 0 | if (old_sax->startDocument != NULL) |
28184 | 0 | ret->schemas_sax.startDocument = startDocumentSplit; |
28185 | 0 | if (old_sax->endDocument != NULL) |
28186 | 0 | ret->schemas_sax.endDocument = endDocumentSplit; |
28187 | 0 | if (old_sax->processingInstruction != NULL) |
28188 | 0 | ret->schemas_sax.processingInstruction = processingInstructionSplit; |
28189 | 0 | if (old_sax->comment != NULL) |
28190 | 0 | ret->schemas_sax.comment = commentSplit; |
28191 | 0 | if (old_sax->warning != NULL) |
28192 | 0 | ret->schemas_sax.warning = warningSplit; |
28193 | 0 | if (old_sax->error != NULL) |
28194 | 0 | ret->schemas_sax.error = errorSplit; |
28195 | 0 | if (old_sax->fatalError != NULL) |
28196 | 0 | ret->schemas_sax.fatalError = fatalErrorSplit; |
28197 | 0 | if (old_sax->getParameterEntity != NULL) |
28198 | 0 | ret->schemas_sax.getParameterEntity = getParameterEntitySplit; |
28199 | 0 | if (old_sax->externalSubset != NULL) |
28200 | 0 | ret->schemas_sax.externalSubset = externalSubsetSplit; |
28201 | | |
28202 | | /* |
28203 | | * the 6 schemas callback have to go to the splitter functions |
28204 | | * Note that we use the same text-function for ignorableWhitespace |
28205 | | * if possible, to prevent the parser from testing for ignorable |
28206 | | * whitespace. |
28207 | | */ |
28208 | 0 | ret->schemas_sax.characters = charactersSplit; |
28209 | 0 | if ((old_sax->ignorableWhitespace != NULL) && |
28210 | 0 | (old_sax->ignorableWhitespace != old_sax->characters)) |
28211 | 0 | ret->schemas_sax.ignorableWhitespace = ignorableWhitespaceSplit; |
28212 | 0 | else |
28213 | 0 | ret->schemas_sax.ignorableWhitespace = charactersSplit; |
28214 | 0 | ret->schemas_sax.cdataBlock = cdataBlockSplit; |
28215 | 0 | ret->schemas_sax.reference = referenceSplit; |
28216 | 0 | ret->schemas_sax.startElementNs = startElementNsSplit; |
28217 | 0 | ret->schemas_sax.endElementNs = endElementNsSplit; |
28218 | |
|
28219 | 0 | ret->user_data_ptr = user_data; |
28220 | 0 | ret->user_data = *user_data; |
28221 | 0 | *user_data = ret; |
28222 | 0 | } |
28223 | | |
28224 | | /* |
28225 | | * plug the pointers back. |
28226 | | */ |
28227 | 0 | *sax = &(ret->schemas_sax); |
28228 | 0 | ctxt->sax = *sax; |
28229 | 0 | ctxt->flags |= XML_SCHEMA_VALID_CTXT_FLAG_STREAM; |
28230 | 0 | xmlSchemaPreRun(ctxt); |
28231 | 0 | return(ret); |
28232 | 0 | } |
28233 | | |
28234 | | /** |
28235 | | * Unplug a SAX based validation layer in a SAX parsing event flow. |
28236 | | * The original pointers used in the call are restored. |
28237 | | * |
28238 | | * @param plug a data structure returned by xmlSchemaSAXPlug |
28239 | | * @returns 0 in case of success and -1 in case of failure. |
28240 | | */ |
28241 | | int |
28242 | | xmlSchemaSAXUnplug(xmlSchemaSAXPlugStruct *plug) |
28243 | 0 | { |
28244 | 0 | xmlSAXHandlerPtr *sax; |
28245 | 0 | void **user_data; |
28246 | |
|
28247 | 0 | if ((plug == NULL) || (plug->magic != XML_SAX_PLUG_MAGIC)) |
28248 | 0 | return(-1); |
28249 | 0 | plug->magic = 0; |
28250 | |
|
28251 | 0 | xmlSchemaPostRun(plug->ctxt); |
28252 | | /* restore the data */ |
28253 | 0 | sax = plug->user_sax_ptr; |
28254 | 0 | *sax = plug->user_sax; |
28255 | 0 | if (plug->user_sax != NULL) { |
28256 | 0 | user_data = plug->user_data_ptr; |
28257 | 0 | *user_data = plug->user_data; |
28258 | 0 | } |
28259 | | |
28260 | | /* free and return */ |
28261 | 0 | xmlFree(plug); |
28262 | 0 | return(0); |
28263 | 0 | } |
28264 | | |
28265 | | /** |
28266 | | * Allows to set a locator function to the validation context, |
28267 | | * which will be used to provide file and line information since |
28268 | | * those are not provided as part of the SAX validation flow |
28269 | | * Setting `f` to NULL disable the locator. |
28270 | | * |
28271 | | * @param vctxt a schema validation context |
28272 | | * @param f the locator function pointer |
28273 | | * @param ctxt the locator context |
28274 | | */ |
28275 | | |
28276 | | void |
28277 | | xmlSchemaValidateSetLocator(xmlSchemaValidCtxt *vctxt, |
28278 | | xmlSchemaValidityLocatorFunc f, |
28279 | | void *ctxt) |
28280 | 0 | { |
28281 | 0 | if (vctxt == NULL) return; |
28282 | 0 | vctxt->locFunc = f; |
28283 | 0 | vctxt->locCtxt = ctxt; |
28284 | 0 | } |
28285 | | |
28286 | | /** |
28287 | | * Internal locator function for the readers |
28288 | | * |
28289 | | * @param ctx the xmlTextReader used |
28290 | | * @param file returned file information |
28291 | | * @param line returned line information |
28292 | | * @returns 0 in case the Schema validation could be (de)activated and |
28293 | | * -1 in case of error. |
28294 | | */ |
28295 | | static int |
28296 | | xmlSchemaValidateStreamLocator(void *ctx, const char **file, |
28297 | 0 | unsigned long *line) { |
28298 | 0 | xmlParserCtxtPtr ctxt; |
28299 | |
|
28300 | 0 | if ((ctx == NULL) || ((file == NULL) && (line == NULL))) |
28301 | 0 | return(-1); |
28302 | | |
28303 | 0 | if (file != NULL) |
28304 | 0 | *file = NULL; |
28305 | 0 | if (line != NULL) |
28306 | 0 | *line = 0; |
28307 | |
|
28308 | 0 | ctxt = (xmlParserCtxtPtr) ctx; |
28309 | 0 | if (ctxt->input != NULL) { |
28310 | 0 | if (file != NULL) |
28311 | 0 | *file = ctxt->input->filename; |
28312 | 0 | if (line != NULL) |
28313 | 0 | *line = ctxt->input->line; |
28314 | 0 | return(0); |
28315 | 0 | } |
28316 | 0 | return(-1); |
28317 | 0 | } |
28318 | | |
28319 | | /** |
28320 | | * @param ctxt a schema validation context |
28321 | | * @param pctxt a parser context |
28322 | | * @returns 0 if the document is schemas valid, a positive error code |
28323 | | * number otherwise and -1 in case of internal or API error. |
28324 | | */ |
28325 | | static int |
28326 | | xmlSchemaValidateStreamInternal(xmlSchemaValidCtxtPtr ctxt, |
28327 | 0 | xmlParserCtxtPtr pctxt) { |
28328 | 0 | xmlSchemaSAXPlugPtr plug = NULL; |
28329 | 0 | int ret; |
28330 | |
|
28331 | 0 | xmlSchemaValidateSetLocator(ctxt, xmlSchemaValidateStreamLocator, pctxt); |
28332 | |
|
28333 | 0 | ctxt->parserCtxt = pctxt; |
28334 | 0 | ctxt->input = pctxt->input->buf; |
28335 | | |
28336 | | /* |
28337 | | * Plug the validation and launch the parsing |
28338 | | */ |
28339 | 0 | plug = xmlSchemaSAXPlug(ctxt, &(pctxt->sax), &(pctxt->userData)); |
28340 | 0 | if (plug == NULL) { |
28341 | 0 | ret = -1; |
28342 | 0 | goto done; |
28343 | 0 | } |
28344 | 0 | ctxt->input = pctxt->input->buf; |
28345 | 0 | ctxt->sax = pctxt->sax; |
28346 | 0 | ctxt->flags |= XML_SCHEMA_VALID_CTXT_FLAG_STREAM; |
28347 | 0 | ret = xmlSchemaVStart(ctxt); |
28348 | |
|
28349 | 0 | if ((ret == 0) && (! ctxt->parserCtxt->wellFormed)) { |
28350 | 0 | ret = ctxt->parserCtxt->errNo; |
28351 | 0 | if (ret == 0) |
28352 | 0 | ret = 1; |
28353 | 0 | } |
28354 | |
|
28355 | 0 | done: |
28356 | 0 | ctxt->parserCtxt = NULL; |
28357 | 0 | ctxt->sax = NULL; |
28358 | 0 | ctxt->input = NULL; |
28359 | 0 | if (plug != NULL) { |
28360 | 0 | xmlSchemaSAXUnplug(plug); |
28361 | 0 | } |
28362 | 0 | return (ret); |
28363 | 0 | } |
28364 | | |
28365 | | /** |
28366 | | * Validate an input based on a flow of SAX event from the parser |
28367 | | * and forward the events to the `sax` handler with the provided `user_data` |
28368 | | * the user provided `sax` handler must be a SAX2 one. |
28369 | | * |
28370 | | * @param ctxt a schema validation context |
28371 | | * @param input the input to use for reading the data |
28372 | | * @param enc an optional encoding information |
28373 | | * @param sax a SAX handler for the resulting events |
28374 | | * @param user_data the context to provide to the SAX handler. |
28375 | | * @returns 0 if the document is schemas valid, a positive error code |
28376 | | * number otherwise and -1 in case of internal or API error. |
28377 | | */ |
28378 | | int |
28379 | | xmlSchemaValidateStream(xmlSchemaValidCtxt *ctxt, |
28380 | | xmlParserInputBuffer *input, xmlCharEncoding enc, |
28381 | | const xmlSAXHandler *sax, void *user_data) |
28382 | 0 | { |
28383 | 0 | xmlParserCtxtPtr pctxt = NULL; |
28384 | 0 | xmlParserInputPtr inputStream = NULL; |
28385 | 0 | int ret; |
28386 | |
|
28387 | 0 | if ((ctxt == NULL) || (input == NULL)) |
28388 | 0 | return (-1); |
28389 | | |
28390 | | /* |
28391 | | * prepare the parser |
28392 | | */ |
28393 | 0 | if (sax != NULL) { |
28394 | 0 | pctxt = xmlNewSAXParserCtxt(sax, user_data); |
28395 | 0 | if (pctxt == NULL) |
28396 | 0 | return (-1); |
28397 | 0 | } else { |
28398 | 0 | pctxt = xmlNewParserCtxt(); |
28399 | 0 | if (pctxt == NULL) |
28400 | 0 | return (-1); |
28401 | | /* We really want pctxt->sax to be NULL here. */ |
28402 | 0 | xmlFree(pctxt->sax); |
28403 | 0 | pctxt->sax = NULL; |
28404 | 0 | } |
28405 | | #if 0 |
28406 | | if (options) |
28407 | | xmlCtxtUseOptions(pctxt, options); |
28408 | | #endif |
28409 | | |
28410 | 0 | inputStream = xmlNewIOInputStream(pctxt, input, enc);; |
28411 | 0 | if (inputStream == NULL) { |
28412 | 0 | ret = -1; |
28413 | 0 | goto done; |
28414 | 0 | } |
28415 | 0 | if (xmlCtxtPushInput(pctxt, inputStream) < 0) { |
28416 | 0 | xmlFreeInputStream(inputStream); |
28417 | 0 | ret = -1; |
28418 | 0 | goto done; |
28419 | 0 | } |
28420 | | |
28421 | 0 | ctxt->enc = enc; |
28422 | |
|
28423 | 0 | ret = xmlSchemaValidateStreamInternal(ctxt, pctxt); |
28424 | |
|
28425 | 0 | done: |
28426 | | /* cleanup */ |
28427 | 0 | if (pctxt != NULL) { |
28428 | 0 | xmlFreeParserCtxt(pctxt); |
28429 | 0 | } |
28430 | 0 | return (ret); |
28431 | 0 | } |
28432 | | |
28433 | | /** |
28434 | | * Do a schemas validation of the given resource, it will use the |
28435 | | * SAX streamable validation internally. |
28436 | | * |
28437 | | * @param ctxt a schema validation context |
28438 | | * @param filename the URI of the instance |
28439 | | * @param options a future set of options, currently unused |
28440 | | * @returns 0 if the document is valid, a positive error code |
28441 | | * number otherwise and -1 in case of an internal or API error. |
28442 | | */ |
28443 | | int |
28444 | | xmlSchemaValidateFile(xmlSchemaValidCtxt *ctxt, |
28445 | | const char * filename, |
28446 | | int options ATTRIBUTE_UNUSED) |
28447 | 0 | { |
28448 | 0 | int ret; |
28449 | 0 | xmlParserCtxtPtr pctxt = NULL; |
28450 | |
|
28451 | 0 | if ((ctxt == NULL) || (filename == NULL)) |
28452 | 0 | return (-1); |
28453 | | |
28454 | 0 | pctxt = xmlCreateURLParserCtxt(filename, 0); |
28455 | 0 | if (pctxt == NULL) |
28456 | 0 | return (-1); |
28457 | | /* We really want pctxt->sax to be NULL here. */ |
28458 | 0 | xmlFree(pctxt->sax); |
28459 | 0 | pctxt->sax = NULL; |
28460 | 0 | ret = xmlSchemaValidateStreamInternal(ctxt, pctxt); |
28461 | 0 | xmlFreeParserCtxt(pctxt); |
28462 | 0 | return (ret); |
28463 | 0 | } |
28464 | | |
28465 | | /** |
28466 | | * allow access to the parser context of the schema validation context |
28467 | | * |
28468 | | * @param ctxt a schema validation context |
28469 | | * @returns the parser context of the schema validation context or NULL |
28470 | | * in case of error. |
28471 | | */ |
28472 | | xmlParserCtxt * |
28473 | | xmlSchemaValidCtxtGetParserCtxt(xmlSchemaValidCtxt *ctxt) |
28474 | 0 | { |
28475 | 0 | if (ctxt == NULL) |
28476 | 0 | return(NULL); |
28477 | 0 | return (ctxt->parserCtxt); |
28478 | 0 | } |
28479 | | |
28480 | | #endif /* LIBXML_SCHEMAS_ENABLED */ |