[LIBXML2]
[reactos.git] / reactos / sdk / lib / 3rdparty / libxml2 / xmlschemas.c
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 * Daniel Veillard <veillard@redhat.com>
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 * - Elimated 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 #define IN_LIBXML
48 #include "libxml.h"
49
50 #ifdef LIBXML_SCHEMAS_ENABLED
51
52 #include <string.h>
53 #include <libxml/xmlmemory.h>
54 #include <libxml/parser.h>
55 #include <libxml/parserInternals.h>
56 #include <libxml/hash.h>
57 #include <libxml/uri.h>
58 #include <libxml/xmlschemas.h>
59 #include <libxml/schemasInternals.h>
60 #include <libxml/xmlschemastypes.h>
61 #include <libxml/xmlautomata.h>
62 #include <libxml/xmlregexp.h>
63 #include <libxml/dict.h>
64 #include <libxml/encoding.h>
65 #include <libxml/xmlIO.h>
66 #ifdef LIBXML_PATTERN_ENABLED
67 #include <libxml/pattern.h>
68 #endif
69 #ifdef LIBXML_READER_ENABLED
70 #include <libxml/xmlreader.h>
71 #endif
72
73 /* #define DEBUG 1 */
74
75 /* #define DEBUG_CONTENT 1 */
76
77 /* #define DEBUG_TYPE 1 */
78
79 /* #define DEBUG_CONTENT_REGEXP 1 */
80
81 /* #define DEBUG_AUTOMATA 1 */
82
83 /* #define DEBUG_IDC */
84
85 /* #define DEBUG_IDC_NODE_TABLE */
86
87 /* #define WXS_ELEM_DECL_CONS_ENABLED */
88
89 #ifdef DEBUG_IDC
90 #ifndef DEBUG_IDC_NODE_TABLE
91 #define DEBUG_IDC_NODE_TABLE
92 #endif
93 #endif
94
95 /* #define ENABLE_PARTICLE_RESTRICTION 1 */
96
97 #define ENABLE_REDEFINE
98
99 /* #define ENABLE_NAMED_LOCALS */
100
101 /* #define ENABLE_IDC_NODE_TABLES_TEST */
102
103 #define DUMP_CONTENT_MODEL
104
105 #ifdef LIBXML_READER_ENABLED
106 /* #define XML_SCHEMA_READER_ENABLED */
107 #endif
108
109 #define UNBOUNDED (1 << 30)
110 #define TODO \
111 xmlGenericError(xmlGenericErrorContext, \
112 "Unimplemented block at %s:%d\n", \
113 __FILE__, __LINE__);
114
115 #define XML_SCHEMAS_NO_NAMESPACE (const xmlChar *) "##"
116
117 /*
118 * The XML Schemas namespaces
119 */
120 static const xmlChar *xmlSchemaNs = (const xmlChar *)
121 "http://www.w3.org/2001/XMLSchema";
122
123 static const xmlChar *xmlSchemaInstanceNs = (const xmlChar *)
124 "http://www.w3.org/2001/XMLSchema-instance";
125
126 static const xmlChar *xmlNamespaceNs = (const xmlChar *)
127 "http://www.w3.org/2000/xmlns/";
128
129 /*
130 * Come casting macros.
131 */
132 #define ACTXT_CAST (xmlSchemaAbstractCtxtPtr)
133 #define PCTXT_CAST (xmlSchemaParserCtxtPtr)
134 #define VCTXT_CAST (xmlSchemaValidCtxtPtr)
135 #define WXS_BASIC_CAST (xmlSchemaBasicItemPtr)
136 #define WXS_TREE_CAST (xmlSchemaTreeItemPtr)
137 #define WXS_PTC_CAST (xmlSchemaParticlePtr)
138 #define WXS_TYPE_CAST (xmlSchemaTypePtr)
139 #define WXS_ELEM_CAST (xmlSchemaElementPtr)
140 #define WXS_ATTR_GROUP_CAST (xmlSchemaAttributeGroupPtr)
141 #define WXS_ATTR_CAST (xmlSchemaAttributePtr)
142 #define WXS_ATTR_USE_CAST (xmlSchemaAttributeUsePtr)
143 #define WXS_ATTR_PROHIB_CAST (xmlSchemaAttributeUseProhibPtr)
144 #define WXS_MODEL_GROUPDEF_CAST (xmlSchemaModelGroupDefPtr)
145 #define WXS_MODEL_GROUP_CAST (xmlSchemaModelGroupPtr)
146 #define WXS_IDC_CAST (xmlSchemaIDCPtr)
147 #define WXS_QNAME_CAST (xmlSchemaQNameRefPtr)
148 #define WXS_LIST_CAST (xmlSchemaItemListPtr)
149
150 /*
151 * Macros to query common properties of components.
152 */
153 #define WXS_ITEM_NODE(i) xmlSchemaGetComponentNode(WXS_BASIC_CAST (i))
154
155 #define WXS_ITEM_TYPE_NAME(i) xmlSchemaGetComponentTypeStr(WXS_BASIC_CAST (i))
156 /*
157 * Macros for element declarations.
158 */
159 #define WXS_ELEM_TYPEDEF(e) (e)->subtypes
160
161 #define WXS_SUBST_HEAD(item) (item)->refDecl
162 /*
163 * Macros for attribute declarations.
164 */
165 #define WXS_ATTR_TYPEDEF(a) (a)->subtypes
166 /*
167 * Macros for attribute uses.
168 */
169 #define WXS_ATTRUSE_DECL(au) WXS_ATTR_CAST (WXS_ATTR_USE_CAST (au))->attrDecl
170
171 #define WXS_ATTRUSE_TYPEDEF(au) WXS_ATTR_TYPEDEF(WXS_ATTRUSE_DECL( WXS_ATTR_USE_CAST au))
172
173 #define WXS_ATTRUSE_DECL_NAME(au) (WXS_ATTRUSE_DECL(au))->name
174
175 #define WXS_ATTRUSE_DECL_TNS(au) (WXS_ATTRUSE_DECL(au))->targetNamespace
176 /*
177 * Macros for attribute groups.
178 */
179 #define WXS_ATTR_GROUP_HAS_REFS(ag) ((WXS_ATTR_GROUP_CAST (ag))->flags & XML_SCHEMAS_ATTRGROUP_HAS_REFS)
180 #define WXS_ATTR_GROUP_EXPANDED(ag) ((WXS_ATTR_GROUP_CAST (ag))->flags & XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED)
181 /*
182 * Macros for particles.
183 */
184 #define WXS_PARTICLE(p) WXS_PTC_CAST (p)
185
186 #define WXS_PARTICLE_TERM(p) (WXS_PARTICLE(p))->children
187
188 #define WXS_PARTICLE_TERM_AS_ELEM(p) (WXS_ELEM_CAST WXS_PARTICLE_TERM(p))
189
190 #define WXS_PARTICLE_MODEL(p) WXS_MODEL_GROUP_CAST WXS_PARTICLE(p)->children
191 /*
192 * Macros for model groups definitions.
193 */
194 #define WXS_MODELGROUPDEF_MODEL(mgd) (WXS_MODEL_GROUP_CAST (mgd))->children
195 /*
196 * Macros for model groups.
197 */
198 #define WXS_IS_MODEL_GROUP(i) \
199 (((i)->type == XML_SCHEMA_TYPE_SEQUENCE) || \
200 ((i)->type == XML_SCHEMA_TYPE_CHOICE) || \
201 ((i)->type == XML_SCHEMA_TYPE_ALL))
202
203 #define WXS_MODELGROUP_PARTICLE(mg) WXS_PTC_CAST (mg)->children
204 /*
205 * Macros for schema buckets.
206 */
207 #define WXS_IS_BUCKET_INCREDEF(t) (((t) == XML_SCHEMA_SCHEMA_INCLUDE) || \
208 ((t) == XML_SCHEMA_SCHEMA_REDEFINE))
209
210 #define WXS_IS_BUCKET_IMPMAIN(t) (((t) == XML_SCHEMA_SCHEMA_MAIN) || \
211 ((t) == XML_SCHEMA_SCHEMA_IMPORT))
212
213 #define WXS_IMPBUCKET(b) ((xmlSchemaImportPtr) (b))
214
215 #define WXS_INCBUCKET(b) ((xmlSchemaIncludePtr) (b))
216 /*
217 * Macros for complex/simple types.
218 */
219 #define WXS_IS_ANYTYPE(i) \
220 (( (i)->type == XML_SCHEMA_TYPE_BASIC) && \
221 ( (WXS_TYPE_CAST (i))->builtInType == XML_SCHEMAS_ANYTYPE))
222
223 #define WXS_IS_COMPLEX(i) \
224 (((i)->type == XML_SCHEMA_TYPE_COMPLEX) || \
225 ((i)->builtInType == XML_SCHEMAS_ANYTYPE))
226
227 #define WXS_IS_SIMPLE(item) \
228 ((item->type == XML_SCHEMA_TYPE_SIMPLE) || \
229 ((item->type == XML_SCHEMA_TYPE_BASIC) && \
230 (item->builtInType != XML_SCHEMAS_ANYTYPE)))
231
232 #define WXS_IS_ANY_SIMPLE_TYPE(i) \
233 (((i)->type == XML_SCHEMA_TYPE_BASIC) && \
234 ((i)->builtInType == XML_SCHEMAS_ANYSIMPLETYPE))
235
236 #define WXS_IS_RESTRICTION(t) \
237 ((t)->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION)
238
239 #define WXS_IS_EXTENSION(t) \
240 ((t)->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION)
241
242 #define WXS_IS_TYPE_NOT_FIXED(i) \
243 (((i)->type != XML_SCHEMA_TYPE_BASIC) && \
244 (((i)->flags & XML_SCHEMAS_TYPE_INTERNAL_RESOLVED) == 0))
245
246 #define WXS_IS_TYPE_NOT_FIXED_1(item) \
247 (((item)->type != XML_SCHEMA_TYPE_BASIC) && \
248 (((item)->flags & XML_SCHEMAS_TYPE_FIXUP_1) == 0))
249
250 #define WXS_TYPE_IS_GLOBAL(t) ((t)->flags & XML_SCHEMAS_TYPE_GLOBAL)
251
252 #define WXS_TYPE_IS_LOCAL(t) (((t)->flags & XML_SCHEMAS_TYPE_GLOBAL) == 0)
253 /*
254 * Macros for exclusively for complex types.
255 */
256 #define WXS_HAS_COMPLEX_CONTENT(item) \
257 ((item->contentType == XML_SCHEMA_CONTENT_MIXED) || \
258 (item->contentType == XML_SCHEMA_CONTENT_EMPTY) || \
259 (item->contentType == XML_SCHEMA_CONTENT_ELEMENTS))
260
261 #define WXS_HAS_SIMPLE_CONTENT(item) \
262 ((item->contentType == XML_SCHEMA_CONTENT_SIMPLE) || \
263 (item->contentType == XML_SCHEMA_CONTENT_BASIC))
264
265 #define WXS_HAS_MIXED_CONTENT(item) \
266 (item->contentType == XML_SCHEMA_CONTENT_MIXED)
267
268 #define WXS_EMPTIABLE(t) \
269 (xmlSchemaIsParticleEmptiable(WXS_PTC_CAST (t)->subtypes))
270
271 #define WXS_TYPE_CONTENTTYPE(t) (t)->subtypes
272
273 #define WXS_TYPE_PARTICLE(t) WXS_PTC_CAST (t)->subtypes
274
275 #define WXS_TYPE_PARTICLE_TERM(t) WXS_PARTICLE_TERM(WXS_TYPE_PARTICLE(t))
276 /*
277 * Macros for exclusively for simple types.
278 */
279 #define WXS_LIST_ITEMTYPE(t) (t)->subtypes
280
281 #define WXS_IS_ATOMIC(t) (t->flags & XML_SCHEMAS_TYPE_VARIETY_ATOMIC)
282
283 #define WXS_IS_LIST(t) (t->flags & XML_SCHEMAS_TYPE_VARIETY_LIST)
284
285 #define WXS_IS_UNION(t) (t->flags & XML_SCHEMAS_TYPE_VARIETY_UNION)
286 /*
287 * Misc parser context macros.
288 */
289 #define WXS_CONSTRUCTOR(ctx) (ctx)->constructor
290
291 #define WXS_HAS_BUCKETS(ctx) \
292 ( (WXS_CONSTRUCTOR((ctx))->buckets != NULL) && \
293 (WXS_CONSTRUCTOR((ctx))->buckets->nbItems > 0) )
294
295 #define WXS_SUBST_GROUPS(ctx) WXS_CONSTRUCTOR((ctx))->substGroups
296
297 #define WXS_BUCKET(ctx) WXS_CONSTRUCTOR((ctx))->bucket
298
299 #define WXS_SCHEMA(ctx) (ctx)->schema
300
301 #define WXS_ADD_LOCAL(ctx, item) \
302 xmlSchemaAddItemSize(&(WXS_BUCKET(ctx)->locals), 10, item)
303
304 #define WXS_ADD_GLOBAL(ctx, item) \
305 xmlSchemaAddItemSize(&(WXS_BUCKET(ctx)->globals), 5, item)
306
307 #define WXS_ADD_PENDING(ctx, item) \
308 xmlSchemaAddItemSize(&((ctx)->constructor->pending), 10, item)
309 /*
310 * xmlSchemaItemList macros.
311 */
312 #define WXS_ILIST_IS_EMPTY(l) ((l == NULL) || ((l)->nbItems == 0))
313 /*
314 * Misc macros.
315 */
316 #define IS_SCHEMA(node, type) \
317 ((node != NULL) && (node->ns != NULL) && \
318 (xmlStrEqual(node->name, (const xmlChar *) type)) && \
319 (xmlStrEqual(node->ns->href, xmlSchemaNs)))
320
321 #define FREE_AND_NULL(str) if ((str) != NULL) { xmlFree((xmlChar *) (str)); str = NULL; }
322
323 /*
324 * Since we put the default/fixed values into the dict, we can
325 * use pointer comparison for those values.
326 * REMOVED: (xmlStrEqual((v1), (v2)))
327 */
328 #define WXS_ARE_DEFAULT_STR_EQUAL(v1, v2) ((v1) == (v2))
329
330 #define INODE_NILLED(item) (item->flags & XML_SCHEMA_ELEM_INFO_NILLED)
331
332 #define CAN_PARSE_SCHEMA(b) (((b)->doc != NULL) && ((b)->parsed == 0))
333
334 #define HFAILURE if (res == -1) goto exit_failure;
335
336 #define HERROR if (res != 0) goto exit_error;
337
338 #define HSTOP(ctx) if ((ctx)->stop) goto exit;
339 /*
340 * Some flags used for various schema constraints.
341 */
342 #define SUBSET_RESTRICTION 1<<0
343 #define SUBSET_EXTENSION 1<<1
344 #define SUBSET_SUBSTITUTION 1<<2
345 #define SUBSET_LIST 1<<3
346 #define SUBSET_UNION 1<<4
347
348 typedef struct _xmlSchemaNodeInfo xmlSchemaNodeInfo;
349 typedef xmlSchemaNodeInfo *xmlSchemaNodeInfoPtr;
350
351 typedef struct _xmlSchemaItemList xmlSchemaItemList;
352 typedef xmlSchemaItemList *xmlSchemaItemListPtr;
353 struct _xmlSchemaItemList {
354 void **items; /* used for dynamic addition of schemata */
355 int nbItems; /* used for dynamic addition of schemata */
356 int sizeItems; /* used for dynamic addition of schemata */
357 };
358
359 #define XML_SCHEMA_CTXT_PARSER 1
360 #define XML_SCHEMA_CTXT_VALIDATOR 2
361
362 typedef struct _xmlSchemaAbstractCtxt xmlSchemaAbstractCtxt;
363 typedef xmlSchemaAbstractCtxt *xmlSchemaAbstractCtxtPtr;
364 struct _xmlSchemaAbstractCtxt {
365 int type; /* E.g. XML_SCHEMA_CTXT_VALIDATOR */
366 };
367
368 typedef struct _xmlSchemaBucket xmlSchemaBucket;
369 typedef xmlSchemaBucket *xmlSchemaBucketPtr;
370
371 #define XML_SCHEMA_SCHEMA_MAIN 0
372 #define XML_SCHEMA_SCHEMA_IMPORT 1
373 #define XML_SCHEMA_SCHEMA_INCLUDE 2
374 #define XML_SCHEMA_SCHEMA_REDEFINE 3
375
376 /**
377 * xmlSchemaSchemaRelation:
378 *
379 * Used to create a graph of schema relationships.
380 */
381 typedef struct _xmlSchemaSchemaRelation xmlSchemaSchemaRelation;
382 typedef xmlSchemaSchemaRelation *xmlSchemaSchemaRelationPtr;
383 struct _xmlSchemaSchemaRelation {
384 xmlSchemaSchemaRelationPtr next;
385 int type; /* E.g. XML_SCHEMA_SCHEMA_IMPORT */
386 const xmlChar *importNamespace;
387 xmlSchemaBucketPtr bucket;
388 };
389
390 #define XML_SCHEMA_BUCKET_MARKED 1<<0
391 #define XML_SCHEMA_BUCKET_COMPS_ADDED 1<<1
392
393 struct _xmlSchemaBucket {
394 int type;
395 int flags;
396 const xmlChar *schemaLocation;
397 const xmlChar *origTargetNamespace;
398 const xmlChar *targetNamespace;
399 xmlDocPtr doc;
400 xmlSchemaSchemaRelationPtr relations;
401 int located;
402 int parsed;
403 int imported;
404 int preserveDoc;
405 xmlSchemaItemListPtr globals; /* Global components. */
406 xmlSchemaItemListPtr locals; /* Local components. */
407 };
408
409 /**
410 * xmlSchemaImport:
411 * (extends xmlSchemaBucket)
412 *
413 * Reflects a schema. Holds some information
414 * about the schema and its toplevel components. Duplicate
415 * toplevel components are not checked at this level.
416 */
417 typedef struct _xmlSchemaImport xmlSchemaImport;
418 typedef xmlSchemaImport *xmlSchemaImportPtr;
419 struct _xmlSchemaImport {
420 int type; /* Main OR import OR include. */
421 int flags;
422 const xmlChar *schemaLocation; /* The URI of the schema document. */
423 /* For chameleon includes, @origTargetNamespace will be NULL */
424 const xmlChar *origTargetNamespace;
425 /*
426 * For chameleon includes, @targetNamespace will be the
427 * targetNamespace of the including schema.
428 */
429 const xmlChar *targetNamespace;
430 xmlDocPtr doc; /* The schema node-tree. */
431 /* @relations will hold any included/imported/redefined schemas. */
432 xmlSchemaSchemaRelationPtr relations;
433 int located;
434 int parsed;
435 int imported;
436 int preserveDoc;
437 xmlSchemaItemListPtr globals;
438 xmlSchemaItemListPtr locals;
439 /* The imported schema. */
440 xmlSchemaPtr schema;
441 };
442
443 /*
444 * (extends xmlSchemaBucket)
445 */
446 typedef struct _xmlSchemaInclude xmlSchemaInclude;
447 typedef xmlSchemaInclude *xmlSchemaIncludePtr;
448 struct _xmlSchemaInclude {
449 int type;
450 int flags;
451 const xmlChar *schemaLocation;
452 const xmlChar *origTargetNamespace;
453 const xmlChar *targetNamespace;
454 xmlDocPtr doc;
455 xmlSchemaSchemaRelationPtr relations;
456 int located;
457 int parsed;
458 int imported;
459 int preserveDoc;
460 xmlSchemaItemListPtr globals; /* Global components. */
461 xmlSchemaItemListPtr locals; /* Local components. */
462
463 /* The owning main or import schema bucket. */
464 xmlSchemaImportPtr ownerImport;
465 };
466
467 /**
468 * xmlSchemaBasicItem:
469 *
470 * The abstract base type for schema components.
471 */
472 typedef struct _xmlSchemaBasicItem xmlSchemaBasicItem;
473 typedef xmlSchemaBasicItem *xmlSchemaBasicItemPtr;
474 struct _xmlSchemaBasicItem {
475 xmlSchemaTypeType type;
476 };
477
478 /**
479 * xmlSchemaAnnotItem:
480 *
481 * The abstract base type for annotated schema components.
482 * (Extends xmlSchemaBasicItem)
483 */
484 typedef struct _xmlSchemaAnnotItem xmlSchemaAnnotItem;
485 typedef xmlSchemaAnnotItem *xmlSchemaAnnotItemPtr;
486 struct _xmlSchemaAnnotItem {
487 xmlSchemaTypeType type;
488 xmlSchemaAnnotPtr annot;
489 };
490
491 /**
492 * xmlSchemaTreeItem:
493 *
494 * The abstract base type for tree-like structured schema components.
495 * (Extends xmlSchemaAnnotItem)
496 */
497 typedef struct _xmlSchemaTreeItem xmlSchemaTreeItem;
498 typedef xmlSchemaTreeItem *xmlSchemaTreeItemPtr;
499 struct _xmlSchemaTreeItem {
500 xmlSchemaTypeType type;
501 xmlSchemaAnnotPtr annot;
502 xmlSchemaTreeItemPtr next;
503 xmlSchemaTreeItemPtr children;
504 };
505
506
507 #define XML_SCHEMA_ATTR_USE_FIXED 1<<0
508 /**
509 * xmlSchemaAttributeUsePtr:
510 *
511 * The abstract base type for tree-like structured schema components.
512 * (Extends xmlSchemaTreeItem)
513 */
514 typedef struct _xmlSchemaAttributeUse xmlSchemaAttributeUse;
515 typedef xmlSchemaAttributeUse *xmlSchemaAttributeUsePtr;
516 struct _xmlSchemaAttributeUse {
517 xmlSchemaTypeType type;
518 xmlSchemaAnnotPtr annot;
519 xmlSchemaAttributeUsePtr next; /* The next attr. use. */
520 /*
521 * The attr. decl. OR a QName-ref. to an attr. decl. OR
522 * a QName-ref. to an attribute group definition.
523 */
524 xmlSchemaAttributePtr attrDecl;
525
526 int flags;
527 xmlNodePtr node;
528 int occurs; /* required, optional */
529 const xmlChar * defValue;
530 xmlSchemaValPtr defVal;
531 };
532
533 /**
534 * xmlSchemaAttributeUseProhibPtr:
535 *
536 * A helper component to reflect attribute prohibitions.
537 * (Extends xmlSchemaBasicItem)
538 */
539 typedef struct _xmlSchemaAttributeUseProhib xmlSchemaAttributeUseProhib;
540 typedef xmlSchemaAttributeUseProhib *xmlSchemaAttributeUseProhibPtr;
541 struct _xmlSchemaAttributeUseProhib {
542 xmlSchemaTypeType type; /* == XML_SCHEMA_EXTRA_ATTR_USE_PROHIB */
543 xmlNodePtr node;
544 const xmlChar *name;
545 const xmlChar *targetNamespace;
546 int isRef;
547 };
548
549 /**
550 * xmlSchemaRedef:
551 */
552 typedef struct _xmlSchemaRedef xmlSchemaRedef;
553 typedef xmlSchemaRedef *xmlSchemaRedefPtr;
554 struct _xmlSchemaRedef {
555 xmlSchemaRedefPtr next;
556 xmlSchemaBasicItemPtr item; /* The redefining component. */
557 xmlSchemaBasicItemPtr reference; /* The referencing component. */
558 xmlSchemaBasicItemPtr target; /* The to-be-redefined component. */
559 const xmlChar *refName; /* The name of the to-be-redefined component. */
560 const xmlChar *refTargetNs; /* The target namespace of the
561 to-be-redefined comp. */
562 xmlSchemaBucketPtr targetBucket; /* The redefined schema. */
563 };
564
565 /**
566 * xmlSchemaConstructionCtxt:
567 */
568 typedef struct _xmlSchemaConstructionCtxt xmlSchemaConstructionCtxt;
569 typedef xmlSchemaConstructionCtxt *xmlSchemaConstructionCtxtPtr;
570 struct _xmlSchemaConstructionCtxt {
571 xmlSchemaPtr mainSchema; /* The main schema. */
572 xmlSchemaBucketPtr mainBucket; /* The main schema bucket */
573 xmlDictPtr dict;
574 xmlSchemaItemListPtr buckets; /* List of schema buckets. */
575 /* xmlSchemaItemListPtr relations; */ /* List of schema relations. */
576 xmlSchemaBucketPtr bucket; /* The current schema bucket */
577 xmlSchemaItemListPtr pending; /* All Components of all schemas that
578 need to be fixed. */
579 xmlHashTablePtr substGroups;
580 xmlSchemaRedefPtr redefs;
581 xmlSchemaRedefPtr lastRedef;
582 };
583
584 #define XML_SCHEMAS_PARSE_ERROR 1
585 #define SCHEMAS_PARSE_OPTIONS XML_PARSE_NOENT
586
587 struct _xmlSchemaParserCtxt {
588 int type;
589 void *errCtxt; /* user specific error context */
590 xmlSchemaValidityErrorFunc error; /* the callback in case of errors */
591 xmlSchemaValidityWarningFunc warning; /* the callback in case of warning */
592 int err;
593 int nberrors;
594 xmlStructuredErrorFunc serror;
595
596 xmlSchemaConstructionCtxtPtr constructor;
597 int ownsConstructor; /* TODO: Move this to parser *flags*. */
598
599 /* xmlSchemaPtr topschema; */
600 /* xmlHashTablePtr namespaces; */
601
602 xmlSchemaPtr schema; /* The main schema in use */
603 int counter;
604
605 const xmlChar *URL;
606 xmlDocPtr doc;
607 int preserve; /* Whether the doc should be freed */
608
609 const char *buffer;
610 int size;
611
612 /*
613 * Used to build complex element content models
614 */
615 xmlAutomataPtr am;
616 xmlAutomataStatePtr start;
617 xmlAutomataStatePtr end;
618 xmlAutomataStatePtr state;
619
620 xmlDictPtr dict; /* dictionary for interned string names */
621 xmlSchemaTypePtr ctxtType; /* The current context simple/complex type */
622 int options;
623 xmlSchemaValidCtxtPtr vctxt;
624 int isS4S;
625 int isRedefine;
626 int xsiAssemble;
627 int stop; /* If the parser should stop; i.e. a critical error. */
628 const xmlChar *targetNamespace;
629 xmlSchemaBucketPtr redefined; /* The schema to be redefined. */
630
631 xmlSchemaRedefPtr redef; /* Used for redefinitions. */
632 int redefCounter; /* Used for redefinitions. */
633 xmlSchemaItemListPtr attrProhibs;
634 };
635
636 /**
637 * xmlSchemaQNameRef:
638 *
639 * A component reference item (not a schema component)
640 * (Extends xmlSchemaBasicItem)
641 */
642 typedef struct _xmlSchemaQNameRef xmlSchemaQNameRef;
643 typedef xmlSchemaQNameRef *xmlSchemaQNameRefPtr;
644 struct _xmlSchemaQNameRef {
645 xmlSchemaTypeType type;
646 xmlSchemaBasicItemPtr item; /* The resolved referenced item. */
647 xmlSchemaTypeType itemType;
648 const xmlChar *name;
649 const xmlChar *targetNamespace;
650 xmlNodePtr node;
651 };
652
653 /**
654 * xmlSchemaParticle:
655 *
656 * A particle component.
657 * (Extends xmlSchemaTreeItem)
658 */
659 typedef struct _xmlSchemaParticle xmlSchemaParticle;
660 typedef xmlSchemaParticle *xmlSchemaParticlePtr;
661 struct _xmlSchemaParticle {
662 xmlSchemaTypeType type;
663 xmlSchemaAnnotPtr annot;
664 xmlSchemaTreeItemPtr next; /* next particle */
665 xmlSchemaTreeItemPtr children; /* the "term" (e.g. a model group,
666 a group definition, a XML_SCHEMA_EXTRA_QNAMEREF (if a reference),
667 etc.) */
668 int minOccurs;
669 int maxOccurs;
670 xmlNodePtr node;
671 };
672
673 /**
674 * xmlSchemaModelGroup:
675 *
676 * A model group component.
677 * (Extends xmlSchemaTreeItem)
678 */
679 typedef struct _xmlSchemaModelGroup xmlSchemaModelGroup;
680 typedef xmlSchemaModelGroup *xmlSchemaModelGroupPtr;
681 struct _xmlSchemaModelGroup {
682 xmlSchemaTypeType type; /* XML_SCHEMA_TYPE_SEQUENCE, XML_SCHEMA_TYPE_CHOICE, XML_SCHEMA_TYPE_ALL */
683 xmlSchemaAnnotPtr annot;
684 xmlSchemaTreeItemPtr next; /* not used */
685 xmlSchemaTreeItemPtr children; /* first particle (OR "element decl" OR "wildcard") */
686 xmlNodePtr node;
687 };
688
689 #define XML_SCHEMA_MODEL_GROUP_DEF_MARKED 1<<0
690 #define XML_SCHEMA_MODEL_GROUP_DEF_REDEFINED 1<<1
691 /**
692 * xmlSchemaModelGroupDef:
693 *
694 * A model group definition component.
695 * (Extends xmlSchemaTreeItem)
696 */
697 typedef struct _xmlSchemaModelGroupDef xmlSchemaModelGroupDef;
698 typedef xmlSchemaModelGroupDef *xmlSchemaModelGroupDefPtr;
699 struct _xmlSchemaModelGroupDef {
700 xmlSchemaTypeType type; /* XML_SCHEMA_TYPE_GROUP */
701 xmlSchemaAnnotPtr annot;
702 xmlSchemaTreeItemPtr next; /* not used */
703 xmlSchemaTreeItemPtr children; /* the "model group" */
704 const xmlChar *name;
705 const xmlChar *targetNamespace;
706 xmlNodePtr node;
707 int flags;
708 };
709
710 typedef struct _xmlSchemaIDC xmlSchemaIDC;
711 typedef xmlSchemaIDC *xmlSchemaIDCPtr;
712
713 /**
714 * xmlSchemaIDCSelect:
715 *
716 * The identity-constraint "field" and "selector" item, holding the
717 * XPath expression.
718 */
719 typedef struct _xmlSchemaIDCSelect xmlSchemaIDCSelect;
720 typedef xmlSchemaIDCSelect *xmlSchemaIDCSelectPtr;
721 struct _xmlSchemaIDCSelect {
722 xmlSchemaIDCSelectPtr next;
723 xmlSchemaIDCPtr idc;
724 int index; /* an index position if significant for IDC key-sequences */
725 const xmlChar *xpath; /* the XPath expression */
726 void *xpathComp; /* the compiled XPath expression */
727 };
728
729 /**
730 * xmlSchemaIDC:
731 *
732 * The identity-constraint definition component.
733 * (Extends xmlSchemaAnnotItem)
734 */
735
736 struct _xmlSchemaIDC {
737 xmlSchemaTypeType type;
738 xmlSchemaAnnotPtr annot;
739 xmlSchemaIDCPtr next;
740 xmlNodePtr node;
741 const xmlChar *name;
742 const xmlChar *targetNamespace;
743 xmlSchemaIDCSelectPtr selector;
744 xmlSchemaIDCSelectPtr fields;
745 int nbFields;
746 xmlSchemaQNameRefPtr ref;
747 };
748
749 /**
750 * xmlSchemaIDCAug:
751 *
752 * The augmented IDC information used for validation.
753 */
754 typedef struct _xmlSchemaIDCAug xmlSchemaIDCAug;
755 typedef xmlSchemaIDCAug *xmlSchemaIDCAugPtr;
756 struct _xmlSchemaIDCAug {
757 xmlSchemaIDCAugPtr next; /* next in a list */
758 xmlSchemaIDCPtr def; /* the IDC definition */
759 int keyrefDepth; /* the lowest tree level to which IDC
760 tables need to be bubbled upwards */
761 };
762
763 /**
764 * xmlSchemaPSVIIDCKeySequence:
765 *
766 * The key sequence of a node table item.
767 */
768 typedef struct _xmlSchemaPSVIIDCKey xmlSchemaPSVIIDCKey;
769 typedef xmlSchemaPSVIIDCKey *xmlSchemaPSVIIDCKeyPtr;
770 struct _xmlSchemaPSVIIDCKey {
771 xmlSchemaTypePtr type;
772 xmlSchemaValPtr val;
773 };
774
775 /**
776 * xmlSchemaPSVIIDCNode:
777 *
778 * The node table item of a node table.
779 */
780 typedef struct _xmlSchemaPSVIIDCNode xmlSchemaPSVIIDCNode;
781 typedef xmlSchemaPSVIIDCNode *xmlSchemaPSVIIDCNodePtr;
782 struct _xmlSchemaPSVIIDCNode {
783 xmlNodePtr node;
784 xmlSchemaPSVIIDCKeyPtr *keys;
785 int nodeLine;
786 int nodeQNameID;
787
788 };
789
790 /**
791 * xmlSchemaPSVIIDCBinding:
792 *
793 * The identity-constraint binding item of the [identity-constraint table].
794 */
795 typedef struct _xmlSchemaPSVIIDCBinding xmlSchemaPSVIIDCBinding;
796 typedef xmlSchemaPSVIIDCBinding *xmlSchemaPSVIIDCBindingPtr;
797 struct _xmlSchemaPSVIIDCBinding {
798 xmlSchemaPSVIIDCBindingPtr next; /* next binding of a specific node */
799 xmlSchemaIDCPtr definition; /* the IDC definition */
800 xmlSchemaPSVIIDCNodePtr *nodeTable; /* array of key-sequences */
801 int nbNodes; /* number of entries in the node table */
802 int sizeNodes; /* size of the node table */
803 xmlSchemaItemListPtr dupls;
804 };
805
806
807 #define XPATH_STATE_OBJ_TYPE_IDC_SELECTOR 1
808 #define XPATH_STATE_OBJ_TYPE_IDC_FIELD 2
809
810 #define XPATH_STATE_OBJ_MATCHES -2
811 #define XPATH_STATE_OBJ_BLOCKED -3
812
813 typedef struct _xmlSchemaIDCMatcher xmlSchemaIDCMatcher;
814 typedef xmlSchemaIDCMatcher *xmlSchemaIDCMatcherPtr;
815
816 /**
817 * xmlSchemaIDCStateObj:
818 *
819 * The state object used to evaluate XPath expressions.
820 */
821 typedef struct _xmlSchemaIDCStateObj xmlSchemaIDCStateObj;
822 typedef xmlSchemaIDCStateObj *xmlSchemaIDCStateObjPtr;
823 struct _xmlSchemaIDCStateObj {
824 int type;
825 xmlSchemaIDCStateObjPtr next; /* next if in a list */
826 int depth; /* depth of creation */
827 int *history; /* list of (depth, state-id) tuples */
828 int nbHistory;
829 int sizeHistory;
830 xmlSchemaIDCMatcherPtr matcher; /* the correspondent field/selector
831 matcher */
832 xmlSchemaIDCSelectPtr sel;
833 void *xpathCtxt;
834 };
835
836 #define IDC_MATCHER 0
837
838 /**
839 * xmlSchemaIDCMatcher:
840 *
841 * Used to evaluate IDC selectors (and fields).
842 */
843 struct _xmlSchemaIDCMatcher {
844 int type;
845 int depth; /* the tree depth at creation time */
846 xmlSchemaIDCMatcherPtr next; /* next in the list */
847 xmlSchemaIDCMatcherPtr nextCached; /* next in the cache list */
848 xmlSchemaIDCAugPtr aidc; /* the augmented IDC item */
849 int idcType;
850 xmlSchemaPSVIIDCKeyPtr **keySeqs; /* the key-sequences of the target
851 elements */
852 int sizeKeySeqs;
853 xmlSchemaItemListPtr targets; /* list of target-node
854 (xmlSchemaPSVIIDCNodePtr) entries */
855 };
856
857 /*
858 * Element info flags.
859 */
860 #define XML_SCHEMA_NODE_INFO_FLAG_OWNED_NAMES 1<<0
861 #define XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES 1<<1
862 #define XML_SCHEMA_ELEM_INFO_NILLED 1<<2
863 #define XML_SCHEMA_ELEM_INFO_LOCAL_TYPE 1<<3
864
865 #define XML_SCHEMA_NODE_INFO_VALUE_NEEDED 1<<4
866 #define XML_SCHEMA_ELEM_INFO_EMPTY 1<<5
867 #define XML_SCHEMA_ELEM_INFO_HAS_CONTENT 1<<6
868
869 #define XML_SCHEMA_ELEM_INFO_HAS_ELEM_CONTENT 1<<7
870 #define XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT 1<<8
871 #define XML_SCHEMA_NODE_INFO_ERR_NOT_EXPECTED 1<<9
872 #define XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE 1<<10
873
874 /**
875 * xmlSchemaNodeInfo:
876 *
877 * Holds information of an element node.
878 */
879 struct _xmlSchemaNodeInfo {
880 int nodeType;
881 xmlNodePtr node;
882 int nodeLine;
883 const xmlChar *localName;
884 const xmlChar *nsName;
885 const xmlChar *value;
886 xmlSchemaValPtr val; /* the pre-computed value if any */
887 xmlSchemaTypePtr typeDef; /* the complex/simple type definition if any */
888
889 int flags; /* combination of node info flags */
890
891 int valNeeded;
892 int normVal;
893
894 xmlSchemaElementPtr decl; /* the element/attribute declaration */
895 int depth;
896 xmlSchemaPSVIIDCBindingPtr idcTable; /* the table of PSVI IDC bindings
897 for the scope element*/
898 xmlSchemaIDCMatcherPtr idcMatchers; /* the IDC matchers for the scope
899 element */
900 xmlRegExecCtxtPtr regexCtxt;
901
902 const xmlChar **nsBindings; /* Namespace bindings on this element */
903 int nbNsBindings;
904 int sizeNsBindings;
905
906 int hasKeyrefs;
907 int appliedXPath; /* Indicates that an XPath has been applied. */
908 };
909
910 #define XML_SCHEMAS_ATTR_UNKNOWN 1
911 #define XML_SCHEMAS_ATTR_ASSESSED 2
912 #define XML_SCHEMAS_ATTR_PROHIBITED 3
913 #define XML_SCHEMAS_ATTR_ERR_MISSING 4
914 #define XML_SCHEMAS_ATTR_INVALID_VALUE 5
915 #define XML_SCHEMAS_ATTR_ERR_NO_TYPE 6
916 #define XML_SCHEMAS_ATTR_ERR_FIXED_VALUE 7
917 #define XML_SCHEMAS_ATTR_DEFAULT 8
918 #define XML_SCHEMAS_ATTR_VALIDATE_VALUE 9
919 #define XML_SCHEMAS_ATTR_ERR_WILD_STRICT_NO_DECL 10
920 #define XML_SCHEMAS_ATTR_HAS_ATTR_USE 11
921 #define XML_SCHEMAS_ATTR_HAS_ATTR_DECL 12
922 #define XML_SCHEMAS_ATTR_WILD_SKIP 13
923 #define XML_SCHEMAS_ATTR_WILD_LAX_NO_DECL 14
924 #define XML_SCHEMAS_ATTR_ERR_WILD_DUPLICATE_ID 15
925 #define XML_SCHEMAS_ATTR_ERR_WILD_AND_USE_ID 16
926 #define XML_SCHEMAS_ATTR_META 17
927 /*
928 * @metaType values of xmlSchemaAttrInfo.
929 */
930 #define XML_SCHEMA_ATTR_INFO_META_XSI_TYPE 1
931 #define XML_SCHEMA_ATTR_INFO_META_XSI_NIL 2
932 #define XML_SCHEMA_ATTR_INFO_META_XSI_SCHEMA_LOC 3
933 #define XML_SCHEMA_ATTR_INFO_META_XSI_NO_NS_SCHEMA_LOC 4
934 #define XML_SCHEMA_ATTR_INFO_META_XMLNS 5
935
936 typedef struct _xmlSchemaAttrInfo xmlSchemaAttrInfo;
937 typedef xmlSchemaAttrInfo *xmlSchemaAttrInfoPtr;
938 struct _xmlSchemaAttrInfo {
939 int nodeType;
940 xmlNodePtr node;
941 int nodeLine;
942 const xmlChar *localName;
943 const xmlChar *nsName;
944 const xmlChar *value;
945 xmlSchemaValPtr val; /* the pre-computed value if any */
946 xmlSchemaTypePtr typeDef; /* the complex/simple type definition if any */
947 int flags; /* combination of node info flags */
948
949 xmlSchemaAttributePtr decl; /* the attribute declaration */
950 xmlSchemaAttributeUsePtr use; /* the attribute use */
951 int state;
952 int metaType;
953 const xmlChar *vcValue; /* the value constraint value */
954 xmlSchemaNodeInfoPtr parent;
955 };
956
957
958 #define XML_SCHEMA_VALID_CTXT_FLAG_STREAM 1
959 /**
960 * xmlSchemaValidCtxt:
961 *
962 * A Schemas validation context
963 */
964 struct _xmlSchemaValidCtxt {
965 int type;
966 void *errCtxt; /* user specific data block */
967 xmlSchemaValidityErrorFunc error; /* the callback in case of errors */
968 xmlSchemaValidityWarningFunc warning; /* the callback in case of warning */
969 xmlStructuredErrorFunc serror;
970
971 xmlSchemaPtr schema; /* The schema in use */
972 xmlDocPtr doc;
973 xmlParserInputBufferPtr input;
974 xmlCharEncoding enc;
975 xmlSAXHandlerPtr sax;
976 xmlParserCtxtPtr parserCtxt;
977 void *user_data; /* TODO: What is this for? */
978 char *filename;
979
980 int err;
981 int nberrors;
982
983 xmlNodePtr node;
984 xmlNodePtr cur;
985 /* xmlSchemaTypePtr type; */
986
987 xmlRegExecCtxtPtr regexp;
988 xmlSchemaValPtr value;
989
990 int valueWS;
991 int options;
992 xmlNodePtr validationRoot;
993 xmlSchemaParserCtxtPtr pctxt;
994 int xsiAssemble;
995
996 int depth;
997 xmlSchemaNodeInfoPtr *elemInfos; /* array of element informations */
998 int sizeElemInfos;
999 xmlSchemaNodeInfoPtr inode; /* the current element information */
1000
1001 xmlSchemaIDCAugPtr aidcs; /* a list of augmented IDC informations */
1002
1003 xmlSchemaIDCStateObjPtr xpathStates; /* first active state object. */
1004 xmlSchemaIDCStateObjPtr xpathStatePool; /* first stored state object. */
1005 xmlSchemaIDCMatcherPtr idcMatcherCache; /* Cache for IDC matcher objects. */
1006
1007 xmlSchemaPSVIIDCNodePtr *idcNodes; /* list of all IDC node-table entries*/
1008 int nbIdcNodes;
1009 int sizeIdcNodes;
1010
1011 xmlSchemaPSVIIDCKeyPtr *idcKeys; /* list of all IDC node-table entries */
1012 int nbIdcKeys;
1013 int sizeIdcKeys;
1014
1015 int flags;
1016
1017 xmlDictPtr dict;
1018
1019 #ifdef LIBXML_READER_ENABLED
1020 xmlTextReaderPtr reader;
1021 #endif
1022
1023 xmlSchemaAttrInfoPtr *attrInfos;
1024 int nbAttrInfos;
1025 int sizeAttrInfos;
1026
1027 int skipDepth;
1028 xmlSchemaItemListPtr nodeQNames;
1029 int hasKeyrefs;
1030 int createIDCNodeTables;
1031 int psviExposeIDCNodeTables;
1032
1033 /* Locator for error reporting in streaming mode */
1034 xmlSchemaValidityLocatorFunc locFunc;
1035 void *locCtxt;
1036 };
1037
1038 /**
1039 * xmlSchemaSubstGroup:
1040 *
1041 *
1042 */
1043 typedef struct _xmlSchemaSubstGroup xmlSchemaSubstGroup;
1044 typedef xmlSchemaSubstGroup *xmlSchemaSubstGroupPtr;
1045 struct _xmlSchemaSubstGroup {
1046 xmlSchemaElementPtr head;
1047 xmlSchemaItemListPtr members;
1048 };
1049
1050 /************************************************************************
1051 * *
1052 * Some predeclarations *
1053 * *
1054 ************************************************************************/
1055
1056 static int xmlSchemaParseInclude(xmlSchemaParserCtxtPtr ctxt,
1057 xmlSchemaPtr schema,
1058 xmlNodePtr node);
1059 static int xmlSchemaParseRedefine(xmlSchemaParserCtxtPtr ctxt,
1060 xmlSchemaPtr schema,
1061 xmlNodePtr node);
1062 static int
1063 xmlSchemaTypeFixup(xmlSchemaTypePtr type,
1064 xmlSchemaAbstractCtxtPtr ctxt);
1065 static const xmlChar *
1066 xmlSchemaFacetTypeToString(xmlSchemaTypeType type);
1067 static int
1068 xmlSchemaParseImport(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
1069 xmlNodePtr node);
1070 static int
1071 xmlSchemaCheckFacetValues(xmlSchemaTypePtr typeDecl,
1072 xmlSchemaParserCtxtPtr ctxt);
1073 static void
1074 xmlSchemaClearValidCtxt(xmlSchemaValidCtxtPtr vctxt);
1075 static xmlSchemaWhitespaceValueType
1076 xmlSchemaGetWhiteSpaceFacetValue(xmlSchemaTypePtr type);
1077 static xmlSchemaTreeItemPtr
1078 xmlSchemaParseModelGroup(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
1079 xmlNodePtr node, xmlSchemaTypeType type,
1080 int withParticle);
1081 static const xmlChar *
1082 xmlSchemaGetComponentTypeStr(xmlSchemaBasicItemPtr item);
1083 static xmlSchemaTypeLinkPtr
1084 xmlSchemaGetUnionSimpleTypeMemberTypes(xmlSchemaTypePtr type);
1085 static void
1086 xmlSchemaInternalErr(xmlSchemaAbstractCtxtPtr actxt,
1087 const char *funcName,
1088 const char *message) LIBXML_ATTR_FORMAT(3,0);
1089 static int
1090 xmlSchemaCheckCOSSTDerivedOK(xmlSchemaAbstractCtxtPtr ctxt,
1091 xmlSchemaTypePtr type,
1092 xmlSchemaTypePtr baseType,
1093 int subset);
1094 static void
1095 xmlSchemaCheckElementDeclComponent(xmlSchemaElementPtr elemDecl,
1096 xmlSchemaParserCtxtPtr ctxt);
1097 static void
1098 xmlSchemaComponentListFree(xmlSchemaItemListPtr list);
1099 static xmlSchemaQNameRefPtr
1100 xmlSchemaParseAttributeGroupRef(xmlSchemaParserCtxtPtr pctxt,
1101 xmlSchemaPtr schema,
1102 xmlNodePtr node);
1103
1104 /************************************************************************
1105 * *
1106 * Helper functions *
1107 * *
1108 ************************************************************************/
1109
1110 /**
1111 * xmlSchemaItemTypeToStr:
1112 * @type: the type of the schema item
1113 *
1114 * Returns the component name of a schema item.
1115 */
1116 static const xmlChar *
1117 xmlSchemaItemTypeToStr(xmlSchemaTypeType type)
1118 {
1119 switch (type) {
1120 case XML_SCHEMA_TYPE_BASIC:
1121 return(BAD_CAST "simple type definition");
1122 case XML_SCHEMA_TYPE_SIMPLE:
1123 return(BAD_CAST "simple type definition");
1124 case XML_SCHEMA_TYPE_COMPLEX:
1125 return(BAD_CAST "complex type definition");
1126 case XML_SCHEMA_TYPE_ELEMENT:
1127 return(BAD_CAST "element declaration");
1128 case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
1129 return(BAD_CAST "attribute use");
1130 case XML_SCHEMA_TYPE_ATTRIBUTE:
1131 return(BAD_CAST "attribute declaration");
1132 case XML_SCHEMA_TYPE_GROUP:
1133 return(BAD_CAST "model group definition");
1134 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1135 return(BAD_CAST "attribute group definition");
1136 case XML_SCHEMA_TYPE_NOTATION:
1137 return(BAD_CAST "notation declaration");
1138 case XML_SCHEMA_TYPE_SEQUENCE:
1139 return(BAD_CAST "model group (sequence)");
1140 case XML_SCHEMA_TYPE_CHOICE:
1141 return(BAD_CAST "model group (choice)");
1142 case XML_SCHEMA_TYPE_ALL:
1143 return(BAD_CAST "model group (all)");
1144 case XML_SCHEMA_TYPE_PARTICLE:
1145 return(BAD_CAST "particle");
1146 case XML_SCHEMA_TYPE_IDC_UNIQUE:
1147 return(BAD_CAST "unique identity-constraint");
1148 /* return(BAD_CAST "IDC (unique)"); */
1149 case XML_SCHEMA_TYPE_IDC_KEY:
1150 return(BAD_CAST "key identity-constraint");
1151 /* return(BAD_CAST "IDC (key)"); */
1152 case XML_SCHEMA_TYPE_IDC_KEYREF:
1153 return(BAD_CAST "keyref identity-constraint");
1154 /* return(BAD_CAST "IDC (keyref)"); */
1155 case XML_SCHEMA_TYPE_ANY:
1156 return(BAD_CAST "wildcard (any)");
1157 case XML_SCHEMA_EXTRA_QNAMEREF:
1158 return(BAD_CAST "[helper component] QName reference");
1159 case XML_SCHEMA_EXTRA_ATTR_USE_PROHIB:
1160 return(BAD_CAST "[helper component] attribute use prohibition");
1161 default:
1162 return(BAD_CAST "Not a schema component");
1163 }
1164 }
1165
1166 /**
1167 * xmlSchemaGetComponentTypeStr:
1168 * @type: the type of the schema item
1169 *
1170 * Returns the component name of a schema item.
1171 */
1172 static const xmlChar *
1173 xmlSchemaGetComponentTypeStr(xmlSchemaBasicItemPtr item)
1174 {
1175 switch (item->type) {
1176 case XML_SCHEMA_TYPE_BASIC:
1177 if (WXS_IS_COMPLEX(WXS_TYPE_CAST item))
1178 return(BAD_CAST "complex type definition");
1179 else
1180 return(BAD_CAST "simple type definition");
1181 default:
1182 return(xmlSchemaItemTypeToStr(item->type));
1183 }
1184 }
1185
1186 /**
1187 * xmlSchemaGetComponentNode:
1188 * @item: a schema component
1189 *
1190 * Returns node associated with the schema component.
1191 * NOTE that such a node need not be available; plus, a component's
1192 * node need not to reflect the component directly, since there is no
1193 * one-to-one relationship between the XML Schema representation and
1194 * the component representation.
1195 */
1196 static xmlNodePtr
1197 xmlSchemaGetComponentNode(xmlSchemaBasicItemPtr item)
1198 {
1199 switch (item->type) {
1200 case XML_SCHEMA_TYPE_ELEMENT:
1201 return (((xmlSchemaElementPtr) item)->node);
1202 case XML_SCHEMA_TYPE_ATTRIBUTE:
1203 return (((xmlSchemaAttributePtr) item)->node);
1204 case XML_SCHEMA_TYPE_COMPLEX:
1205 case XML_SCHEMA_TYPE_SIMPLE:
1206 return (((xmlSchemaTypePtr) item)->node);
1207 case XML_SCHEMA_TYPE_ANY:
1208 case XML_SCHEMA_TYPE_ANY_ATTRIBUTE:
1209 return (((xmlSchemaWildcardPtr) item)->node);
1210 case XML_SCHEMA_TYPE_PARTICLE:
1211 return (((xmlSchemaParticlePtr) item)->node);
1212 case XML_SCHEMA_TYPE_SEQUENCE:
1213 case XML_SCHEMA_TYPE_CHOICE:
1214 case XML_SCHEMA_TYPE_ALL:
1215 return (((xmlSchemaModelGroupPtr) item)->node);
1216 case XML_SCHEMA_TYPE_GROUP:
1217 return (((xmlSchemaModelGroupDefPtr) item)->node);
1218 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1219 return (((xmlSchemaAttributeGroupPtr) item)->node);
1220 case XML_SCHEMA_TYPE_IDC_UNIQUE:
1221 case XML_SCHEMA_TYPE_IDC_KEY:
1222 case XML_SCHEMA_TYPE_IDC_KEYREF:
1223 return (((xmlSchemaIDCPtr) item)->node);
1224 case XML_SCHEMA_EXTRA_QNAMEREF:
1225 return(((xmlSchemaQNameRefPtr) item)->node);
1226 /* TODO: What to do with NOTATIONs?
1227 case XML_SCHEMA_TYPE_NOTATION:
1228 return (((xmlSchemaNotationPtr) item)->node);
1229 */
1230 case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
1231 return (((xmlSchemaAttributeUsePtr) item)->node);
1232 default:
1233 return (NULL);
1234 }
1235 }
1236
1237 #if 0
1238 /**
1239 * xmlSchemaGetNextComponent:
1240 * @item: a schema component
1241 *
1242 * Returns the next sibling of the schema component.
1243 */
1244 static xmlSchemaBasicItemPtr
1245 xmlSchemaGetNextComponent(xmlSchemaBasicItemPtr item)
1246 {
1247 switch (item->type) {
1248 case XML_SCHEMA_TYPE_ELEMENT:
1249 return ((xmlSchemaBasicItemPtr) ((xmlSchemaElementPtr) item)->next);
1250 case XML_SCHEMA_TYPE_ATTRIBUTE:
1251 return ((xmlSchemaBasicItemPtr) ((xmlSchemaAttributePtr) item)->next);
1252 case XML_SCHEMA_TYPE_COMPLEX:
1253 case XML_SCHEMA_TYPE_SIMPLE:
1254 return ((xmlSchemaBasicItemPtr) ((xmlSchemaTypePtr) item)->next);
1255 case XML_SCHEMA_TYPE_ANY:
1256 case XML_SCHEMA_TYPE_ANY_ATTRIBUTE:
1257 return (NULL);
1258 case XML_SCHEMA_TYPE_PARTICLE:
1259 return ((xmlSchemaBasicItemPtr) ((xmlSchemaParticlePtr) item)->next);
1260 case XML_SCHEMA_TYPE_SEQUENCE:
1261 case XML_SCHEMA_TYPE_CHOICE:
1262 case XML_SCHEMA_TYPE_ALL:
1263 return (NULL);
1264 case XML_SCHEMA_TYPE_GROUP:
1265 return (NULL);
1266 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1267 return ((xmlSchemaBasicItemPtr) ((xmlSchemaAttributeGroupPtr) item)->next);
1268 case XML_SCHEMA_TYPE_IDC_UNIQUE:
1269 case XML_SCHEMA_TYPE_IDC_KEY:
1270 case XML_SCHEMA_TYPE_IDC_KEYREF:
1271 return ((xmlSchemaBasicItemPtr) ((xmlSchemaIDCPtr) item)->next);
1272 default:
1273 return (NULL);
1274 }
1275 }
1276 #endif
1277
1278
1279 /**
1280 * xmlSchemaFormatQName:
1281 * @buf: the string buffer
1282 * @namespaceName: the namespace name
1283 * @localName: the local name
1284 *
1285 * Returns the given QName in the format "{namespaceName}localName" or
1286 * just "localName" if @namespaceName is NULL.
1287 *
1288 * Returns the localName if @namespaceName is NULL, a formatted
1289 * string otherwise.
1290 */
1291 static const xmlChar*
1292 xmlSchemaFormatQName(xmlChar **buf,
1293 const xmlChar *namespaceName,
1294 const xmlChar *localName)
1295 {
1296 FREE_AND_NULL(*buf)
1297 if (namespaceName != NULL) {
1298 *buf = xmlStrdup(BAD_CAST "{");
1299 *buf = xmlStrcat(*buf, namespaceName);
1300 *buf = xmlStrcat(*buf, BAD_CAST "}");
1301 }
1302 if (localName != NULL) {
1303 if (namespaceName == NULL)
1304 return(localName);
1305 *buf = xmlStrcat(*buf, localName);
1306 } else {
1307 *buf = xmlStrcat(*buf, BAD_CAST "(NULL)");
1308 }
1309 return ((const xmlChar *) *buf);
1310 }
1311
1312 static const xmlChar*
1313 xmlSchemaFormatQNameNs(xmlChar **buf, xmlNsPtr ns, const xmlChar *localName)
1314 {
1315 if (ns != NULL)
1316 return (xmlSchemaFormatQName(buf, ns->href, localName));
1317 else
1318 return (xmlSchemaFormatQName(buf, NULL, localName));
1319 }
1320
1321 static const xmlChar *
1322 xmlSchemaGetComponentName(xmlSchemaBasicItemPtr item)
1323 {
1324 switch (item->type) {
1325 case XML_SCHEMA_TYPE_ELEMENT:
1326 return (((xmlSchemaElementPtr) item)->name);
1327 case XML_SCHEMA_TYPE_ATTRIBUTE:
1328 return (((xmlSchemaAttributePtr) item)->name);
1329 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1330 return (((xmlSchemaAttributeGroupPtr) item)->name);
1331 case XML_SCHEMA_TYPE_BASIC:
1332 case XML_SCHEMA_TYPE_SIMPLE:
1333 case XML_SCHEMA_TYPE_COMPLEX:
1334 return (((xmlSchemaTypePtr) item)->name);
1335 case XML_SCHEMA_TYPE_GROUP:
1336 return (((xmlSchemaModelGroupDefPtr) item)->name);
1337 case XML_SCHEMA_TYPE_IDC_KEY:
1338 case XML_SCHEMA_TYPE_IDC_UNIQUE:
1339 case XML_SCHEMA_TYPE_IDC_KEYREF:
1340 return (((xmlSchemaIDCPtr) item)->name);
1341 case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
1342 if (WXS_ATTRUSE_DECL(item) != NULL) {
1343 return(xmlSchemaGetComponentName(
1344 WXS_BASIC_CAST WXS_ATTRUSE_DECL(item)));
1345 } else
1346 return(NULL);
1347 case XML_SCHEMA_EXTRA_QNAMEREF:
1348 return (((xmlSchemaQNameRefPtr) item)->name);
1349 case XML_SCHEMA_TYPE_NOTATION:
1350 return (((xmlSchemaNotationPtr) item)->name);
1351 default:
1352 /*
1353 * Other components cannot have names.
1354 */
1355 break;
1356 }
1357 return (NULL);
1358 }
1359
1360 #define xmlSchemaGetQNameRefName(r) (WXS_QNAME_CAST (r))->name
1361 #define xmlSchemaGetQNameRefTargetNs(r) (WXS_QNAME_CAST (r))->targetNamespace
1362 /*
1363 static const xmlChar *
1364 xmlSchemaGetQNameRefName(void *ref)
1365 {
1366 return(((xmlSchemaQNameRefPtr) ref)->name);
1367 }
1368
1369 static const xmlChar *
1370 xmlSchemaGetQNameRefTargetNs(void *ref)
1371 {
1372 return(((xmlSchemaQNameRefPtr) ref)->targetNamespace);
1373 }
1374 */
1375
1376 static const xmlChar *
1377 xmlSchemaGetComponentTargetNs(xmlSchemaBasicItemPtr item)
1378 {
1379 switch (item->type) {
1380 case XML_SCHEMA_TYPE_ELEMENT:
1381 return (((xmlSchemaElementPtr) item)->targetNamespace);
1382 case XML_SCHEMA_TYPE_ATTRIBUTE:
1383 return (((xmlSchemaAttributePtr) item)->targetNamespace);
1384 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1385 return (((xmlSchemaAttributeGroupPtr) item)->targetNamespace);
1386 case XML_SCHEMA_TYPE_BASIC:
1387 return (BAD_CAST "http://www.w3.org/2001/XMLSchema");
1388 case XML_SCHEMA_TYPE_SIMPLE:
1389 case XML_SCHEMA_TYPE_COMPLEX:
1390 return (((xmlSchemaTypePtr) item)->targetNamespace);
1391 case XML_SCHEMA_TYPE_GROUP:
1392 return (((xmlSchemaModelGroupDefPtr) item)->targetNamespace);
1393 case XML_SCHEMA_TYPE_IDC_KEY:
1394 case XML_SCHEMA_TYPE_IDC_UNIQUE:
1395 case XML_SCHEMA_TYPE_IDC_KEYREF:
1396 return (((xmlSchemaIDCPtr) item)->targetNamespace);
1397 case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
1398 if (WXS_ATTRUSE_DECL(item) != NULL) {
1399 return(xmlSchemaGetComponentTargetNs(
1400 WXS_BASIC_CAST WXS_ATTRUSE_DECL(item)));
1401 }
1402 /* TODO: Will returning NULL break something? */
1403 break;
1404 case XML_SCHEMA_EXTRA_QNAMEREF:
1405 return (((xmlSchemaQNameRefPtr) item)->targetNamespace);
1406 case XML_SCHEMA_TYPE_NOTATION:
1407 return (((xmlSchemaNotationPtr) item)->targetNamespace);
1408 default:
1409 /*
1410 * Other components cannot have names.
1411 */
1412 break;
1413 }
1414 return (NULL);
1415 }
1416
1417 static const xmlChar*
1418 xmlSchemaGetComponentQName(xmlChar **buf,
1419 void *item)
1420 {
1421 return (xmlSchemaFormatQName(buf,
1422 xmlSchemaGetComponentTargetNs((xmlSchemaBasicItemPtr) item),
1423 xmlSchemaGetComponentName((xmlSchemaBasicItemPtr) item)));
1424 }
1425
1426 static const xmlChar*
1427 xmlSchemaGetComponentDesignation(xmlChar **buf, void *item)
1428 {
1429 xmlChar *str = NULL;
1430
1431 *buf = xmlStrcat(*buf, WXS_ITEM_TYPE_NAME(item));
1432 *buf = xmlStrcat(*buf, BAD_CAST " '");
1433 *buf = xmlStrcat(*buf, xmlSchemaGetComponentQName(&str,
1434 (xmlSchemaBasicItemPtr) item));
1435 *buf = xmlStrcat(*buf, BAD_CAST "'");
1436 FREE_AND_NULL(str);
1437 return(*buf);
1438 }
1439
1440 static const xmlChar*
1441 xmlSchemaGetIDCDesignation(xmlChar **buf, xmlSchemaIDCPtr idc)
1442 {
1443 return(xmlSchemaGetComponentDesignation(buf, idc));
1444 }
1445
1446 /**
1447 * xmlSchemaWildcardPCToString:
1448 * @pc: the type of processContents
1449 *
1450 * Returns a string representation of the type of
1451 * processContents.
1452 */
1453 static const xmlChar *
1454 xmlSchemaWildcardPCToString(int pc)
1455 {
1456 switch (pc) {
1457 case XML_SCHEMAS_ANY_SKIP:
1458 return (BAD_CAST "skip");
1459 case XML_SCHEMAS_ANY_LAX:
1460 return (BAD_CAST "lax");
1461 case XML_SCHEMAS_ANY_STRICT:
1462 return (BAD_CAST "strict");
1463 default:
1464 return (BAD_CAST "invalid process contents");
1465 }
1466 }
1467
1468 /**
1469 * xmlSchemaGetCanonValueWhtspExt:
1470 * @val: the precomputed value
1471 * @retValue: the returned value
1472 * @ws: the whitespace type of the value
1473 *
1474 * Get a the canonical representation of the value.
1475 * The caller has to free the returned retValue.
1476 *
1477 * Returns 0 if the value could be built and -1 in case of
1478 * API errors or if the value type is not supported yet.
1479 */
1480 static int
1481 xmlSchemaGetCanonValueWhtspExt(xmlSchemaValPtr val,
1482 xmlSchemaWhitespaceValueType ws,
1483 xmlChar **retValue)
1484 {
1485 int list;
1486 xmlSchemaValType valType;
1487 const xmlChar *value, *value2 = NULL;
1488
1489
1490 if ((retValue == NULL) || (val == NULL))
1491 return (-1);
1492 list = xmlSchemaValueGetNext(val) ? 1 : 0;
1493 *retValue = NULL;
1494 do {
1495 value = NULL;
1496 valType = xmlSchemaGetValType(val);
1497 switch (valType) {
1498 case XML_SCHEMAS_STRING:
1499 case XML_SCHEMAS_NORMSTRING:
1500 case XML_SCHEMAS_ANYSIMPLETYPE:
1501 value = xmlSchemaValueGetAsString(val);
1502 if (value != NULL) {
1503 if (ws == XML_SCHEMA_WHITESPACE_COLLAPSE)
1504 value2 = xmlSchemaCollapseString(value);
1505 else if (ws == XML_SCHEMA_WHITESPACE_REPLACE)
1506 value2 = xmlSchemaWhiteSpaceReplace(value);
1507 if (value2 != NULL)
1508 value = value2;
1509 }
1510 break;
1511 default:
1512 if (xmlSchemaGetCanonValue(val, &value2) == -1) {
1513 if (value2 != NULL)
1514 xmlFree((xmlChar *) value2);
1515 goto internal_error;
1516 }
1517 value = value2;
1518 }
1519 if (*retValue == NULL)
1520 if (value == NULL) {
1521 if (! list)
1522 *retValue = xmlStrdup(BAD_CAST "");
1523 } else
1524 *retValue = xmlStrdup(value);
1525 else if (value != NULL) {
1526 /* List. */
1527 *retValue = xmlStrcat((xmlChar *) *retValue, BAD_CAST " ");
1528 *retValue = xmlStrcat((xmlChar *) *retValue, value);
1529 }
1530 FREE_AND_NULL(value2)
1531 val = xmlSchemaValueGetNext(val);
1532 } while (val != NULL);
1533
1534 return (0);
1535 internal_error:
1536 if (*retValue != NULL)
1537 xmlFree((xmlChar *) (*retValue));
1538 if (value2 != NULL)
1539 xmlFree((xmlChar *) value2);
1540 return (-1);
1541 }
1542
1543 /**
1544 * xmlSchemaFormatItemForReport:
1545 * @buf: the string buffer
1546 * @itemDes: the designation of the item
1547 * @itemName: the name of the item
1548 * @item: the item as an object
1549 * @itemNode: the node of the item
1550 * @local: the local name
1551 * @parsing: if the function is used during the parse
1552 *
1553 * Returns a representation of the given item used
1554 * for error reports.
1555 *
1556 * The following order is used to build the resulting
1557 * designation if the arguments are not NULL:
1558 * 1a. If itemDes not NULL -> itemDes
1559 * 1b. If (itemDes not NULL) and (itemName not NULL)
1560 * -> itemDes + itemName
1561 * 2. If the preceding was NULL and (item not NULL) -> item
1562 * 3. If the preceding was NULL and (itemNode not NULL) -> itemNode
1563 *
1564 * If the itemNode is an attribute node, the name of the attribute
1565 * will be appended to the result.
1566 *
1567 * Returns the formatted string and sets @buf to the resulting value.
1568 */
1569 static xmlChar*
1570 xmlSchemaFormatItemForReport(xmlChar **buf,
1571 const xmlChar *itemDes,
1572 xmlSchemaBasicItemPtr item,
1573 xmlNodePtr itemNode)
1574 {
1575 xmlChar *str = NULL;
1576 int named = 1;
1577
1578 if (*buf != NULL) {
1579 xmlFree(*buf);
1580 *buf = NULL;
1581 }
1582
1583 if (itemDes != NULL) {
1584 *buf = xmlStrdup(itemDes);
1585 } else if (item != NULL) {
1586 switch (item->type) {
1587 case XML_SCHEMA_TYPE_BASIC: {
1588 xmlSchemaTypePtr type = WXS_TYPE_CAST item;
1589
1590 if (WXS_IS_ATOMIC(type))
1591 *buf = xmlStrdup(BAD_CAST "atomic type 'xs:");
1592 else if (WXS_IS_LIST(type))
1593 *buf = xmlStrdup(BAD_CAST "list type 'xs:");
1594 else if (WXS_IS_UNION(type))
1595 *buf = xmlStrdup(BAD_CAST "union type 'xs:");
1596 else
1597 *buf = xmlStrdup(BAD_CAST "simple type 'xs:");
1598 *buf = xmlStrcat(*buf, type->name);
1599 *buf = xmlStrcat(*buf, BAD_CAST "'");
1600 }
1601 break;
1602 case XML_SCHEMA_TYPE_SIMPLE: {
1603 xmlSchemaTypePtr type = WXS_TYPE_CAST item;
1604
1605 if (type->flags & XML_SCHEMAS_TYPE_GLOBAL) {
1606 *buf = xmlStrdup(BAD_CAST"");
1607 } else {
1608 *buf = xmlStrdup(BAD_CAST "local ");
1609 }
1610 if (WXS_IS_ATOMIC(type))
1611 *buf = xmlStrcat(*buf, BAD_CAST "atomic type");
1612 else if (WXS_IS_LIST(type))
1613 *buf = xmlStrcat(*buf, BAD_CAST "list type");
1614 else if (WXS_IS_UNION(type))
1615 *buf = xmlStrcat(*buf, BAD_CAST "union type");
1616 else
1617 *buf = xmlStrcat(*buf, BAD_CAST "simple type");
1618 if (type->flags & XML_SCHEMAS_TYPE_GLOBAL) {
1619 *buf = xmlStrcat(*buf, BAD_CAST " '");
1620 *buf = xmlStrcat(*buf, type->name);
1621 *buf = xmlStrcat(*buf, BAD_CAST "'");
1622 }
1623 }
1624 break;
1625 case XML_SCHEMA_TYPE_COMPLEX: {
1626 xmlSchemaTypePtr type = WXS_TYPE_CAST item;
1627
1628 if (type->flags & XML_SCHEMAS_TYPE_GLOBAL)
1629 *buf = xmlStrdup(BAD_CAST "");
1630 else
1631 *buf = xmlStrdup(BAD_CAST "local ");
1632 *buf = xmlStrcat(*buf, BAD_CAST "complex type");
1633 if (type->flags & XML_SCHEMAS_TYPE_GLOBAL) {
1634 *buf = xmlStrcat(*buf, BAD_CAST " '");
1635 *buf = xmlStrcat(*buf, type->name);
1636 *buf = xmlStrcat(*buf, BAD_CAST "'");
1637 }
1638 }
1639 break;
1640 case XML_SCHEMA_TYPE_ATTRIBUTE_USE: {
1641 xmlSchemaAttributeUsePtr ause;
1642
1643 ause = WXS_ATTR_USE_CAST item;
1644 *buf = xmlStrdup(BAD_CAST "attribute use ");
1645 if (WXS_ATTRUSE_DECL(ause) != NULL) {
1646 *buf = xmlStrcat(*buf, BAD_CAST "'");
1647 *buf = xmlStrcat(*buf,
1648 xmlSchemaGetComponentQName(&str, WXS_ATTRUSE_DECL(ause)));
1649 FREE_AND_NULL(str)
1650 *buf = xmlStrcat(*buf, BAD_CAST "'");
1651 } else {
1652 *buf = xmlStrcat(*buf, BAD_CAST "(unknown)");
1653 }
1654 }
1655 break;
1656 case XML_SCHEMA_TYPE_ATTRIBUTE: {
1657 xmlSchemaAttributePtr attr;
1658
1659 attr = (xmlSchemaAttributePtr) item;
1660 *buf = xmlStrdup(BAD_CAST "attribute decl.");
1661 *buf = xmlStrcat(*buf, BAD_CAST " '");
1662 *buf = xmlStrcat(*buf, xmlSchemaFormatQName(&str,
1663 attr->targetNamespace, attr->name));
1664 FREE_AND_NULL(str)
1665 *buf = xmlStrcat(*buf, BAD_CAST "'");
1666 }
1667 break;
1668 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1669 xmlSchemaGetComponentDesignation(buf, item);
1670 break;
1671 case XML_SCHEMA_TYPE_ELEMENT: {
1672 xmlSchemaElementPtr elem;
1673
1674 elem = (xmlSchemaElementPtr) item;
1675 *buf = xmlStrdup(BAD_CAST "element decl.");
1676 *buf = xmlStrcat(*buf, BAD_CAST " '");
1677 *buf = xmlStrcat(*buf, xmlSchemaFormatQName(&str,
1678 elem->targetNamespace, elem->name));
1679 *buf = xmlStrcat(*buf, BAD_CAST "'");
1680 }
1681 break;
1682 case XML_SCHEMA_TYPE_IDC_UNIQUE:
1683 case XML_SCHEMA_TYPE_IDC_KEY:
1684 case XML_SCHEMA_TYPE_IDC_KEYREF:
1685 if (item->type == XML_SCHEMA_TYPE_IDC_UNIQUE)
1686 *buf = xmlStrdup(BAD_CAST "unique '");
1687 else if (item->type == XML_SCHEMA_TYPE_IDC_KEY)
1688 *buf = xmlStrdup(BAD_CAST "key '");
1689 else
1690 *buf = xmlStrdup(BAD_CAST "keyRef '");
1691 *buf = xmlStrcat(*buf, ((xmlSchemaIDCPtr) item)->name);
1692 *buf = xmlStrcat(*buf, BAD_CAST "'");
1693 break;
1694 case XML_SCHEMA_TYPE_ANY:
1695 case XML_SCHEMA_TYPE_ANY_ATTRIBUTE:
1696 *buf = xmlStrdup(xmlSchemaWildcardPCToString(
1697 ((xmlSchemaWildcardPtr) item)->processContents));
1698 *buf = xmlStrcat(*buf, BAD_CAST " wildcard");
1699 break;
1700 case XML_SCHEMA_FACET_MININCLUSIVE:
1701 case XML_SCHEMA_FACET_MINEXCLUSIVE:
1702 case XML_SCHEMA_FACET_MAXINCLUSIVE:
1703 case XML_SCHEMA_FACET_MAXEXCLUSIVE:
1704 case XML_SCHEMA_FACET_TOTALDIGITS:
1705 case XML_SCHEMA_FACET_FRACTIONDIGITS:
1706 case XML_SCHEMA_FACET_PATTERN:
1707 case XML_SCHEMA_FACET_ENUMERATION:
1708 case XML_SCHEMA_FACET_WHITESPACE:
1709 case XML_SCHEMA_FACET_LENGTH:
1710 case XML_SCHEMA_FACET_MAXLENGTH:
1711 case XML_SCHEMA_FACET_MINLENGTH:
1712 *buf = xmlStrdup(BAD_CAST "facet '");
1713 *buf = xmlStrcat(*buf, xmlSchemaFacetTypeToString(item->type));
1714 *buf = xmlStrcat(*buf, BAD_CAST "'");
1715 break;
1716 case XML_SCHEMA_TYPE_GROUP: {
1717 *buf = xmlStrdup(BAD_CAST "model group def.");
1718 *buf = xmlStrcat(*buf, BAD_CAST " '");
1719 *buf = xmlStrcat(*buf, xmlSchemaGetComponentQName(&str, item));
1720 *buf = xmlStrcat(*buf, BAD_CAST "'");
1721 FREE_AND_NULL(str)
1722 }
1723 break;
1724 case XML_SCHEMA_TYPE_SEQUENCE:
1725 case XML_SCHEMA_TYPE_CHOICE:
1726 case XML_SCHEMA_TYPE_ALL:
1727 case XML_SCHEMA_TYPE_PARTICLE:
1728 *buf = xmlStrdup(WXS_ITEM_TYPE_NAME(item));
1729 break;
1730 case XML_SCHEMA_TYPE_NOTATION: {
1731 *buf = xmlStrdup(WXS_ITEM_TYPE_NAME(item));
1732 *buf = xmlStrcat(*buf, BAD_CAST " '");
1733 *buf = xmlStrcat(*buf, xmlSchemaGetComponentQName(&str, item));
1734 *buf = xmlStrcat(*buf, BAD_CAST "'");
1735 FREE_AND_NULL(str);
1736 }
1737 default:
1738 named = 0;
1739 }
1740 } else
1741 named = 0;
1742
1743 if ((named == 0) && (itemNode != NULL)) {
1744 xmlNodePtr elem;
1745
1746 if (itemNode->type == XML_ATTRIBUTE_NODE)
1747 elem = itemNode->parent;
1748 else
1749 elem = itemNode;
1750 *buf = xmlStrdup(BAD_CAST "Element '");
1751 if (elem->ns != NULL) {
1752 *buf = xmlStrcat(*buf,
1753 xmlSchemaFormatQName(&str, elem->ns->href, elem->name));
1754 FREE_AND_NULL(str)
1755 } else
1756 *buf = xmlStrcat(*buf, elem->name);
1757 *buf = xmlStrcat(*buf, BAD_CAST "'");
1758
1759 }
1760 if ((itemNode != NULL) && (itemNode->type == XML_ATTRIBUTE_NODE)) {
1761 *buf = xmlStrcat(*buf, BAD_CAST ", attribute '");
1762 if (itemNode->ns != NULL) {
1763 *buf = xmlStrcat(*buf, xmlSchemaFormatQName(&str,
1764 itemNode->ns->href, itemNode->name));
1765 FREE_AND_NULL(str)
1766 } else
1767 *buf = xmlStrcat(*buf, itemNode->name);
1768 *buf = xmlStrcat(*buf, BAD_CAST "'");
1769 }
1770 FREE_AND_NULL(str)
1771
1772 return (xmlEscapeFormatString(buf));
1773 }
1774
1775 /**
1776 * xmlSchemaFormatFacetEnumSet:
1777 * @buf: the string buffer
1778 * @type: the type holding the enumeration facets
1779 *
1780 * Builds a string consisting of all enumeration elements.
1781 *
1782 * Returns a string of all enumeration elements.
1783 */
1784 static const xmlChar *
1785 xmlSchemaFormatFacetEnumSet(xmlSchemaAbstractCtxtPtr actxt,
1786 xmlChar **buf, xmlSchemaTypePtr type)
1787 {
1788 xmlSchemaFacetPtr facet;
1789 xmlSchemaWhitespaceValueType ws;
1790 xmlChar *value = NULL;
1791 int res, found = 0;
1792
1793 if (*buf != NULL)
1794 xmlFree(*buf);
1795 *buf = NULL;
1796
1797 do {
1798 /*
1799 * Use the whitespace type of the base type.
1800 */
1801 ws = xmlSchemaGetWhiteSpaceFacetValue(type->baseType);
1802 for (facet = type->facets; facet != NULL; facet = facet->next) {
1803 if (facet->type != XML_SCHEMA_FACET_ENUMERATION)
1804 continue;
1805 found = 1;
1806 res = xmlSchemaGetCanonValueWhtspExt(facet->val,
1807 ws, &value);
1808 if (res == -1) {
1809 xmlSchemaInternalErr(actxt,
1810 "xmlSchemaFormatFacetEnumSet",
1811 "compute the canonical lexical representation");
1812 if (*buf != NULL)
1813 xmlFree(*buf);
1814 *buf = NULL;
1815 return (NULL);
1816 }
1817 if (*buf == NULL)
1818 *buf = xmlStrdup(BAD_CAST "'");
1819 else
1820 *buf = xmlStrcat(*buf, BAD_CAST ", '");
1821 *buf = xmlStrcat(*buf, BAD_CAST value);
1822 *buf = xmlStrcat(*buf, BAD_CAST "'");
1823 if (value != NULL) {
1824 xmlFree((xmlChar *)value);
1825 value = NULL;
1826 }
1827 }
1828 /*
1829 * The enumeration facet of a type restricts the enumeration
1830 * facet of the ancestor type; i.e., such restricted enumerations
1831 * do not belong to the set of the given type. Thus we break
1832 * on the first found enumeration.
1833 */
1834 if (found)
1835 break;
1836 type = type->baseType;
1837 } while ((type != NULL) && (type->type != XML_SCHEMA_TYPE_BASIC));
1838
1839 return ((const xmlChar *) *buf);
1840 }
1841
1842 /************************************************************************
1843 * *
1844 * Error functions *
1845 * *
1846 ************************************************************************/
1847
1848 #if 0
1849 static void
1850 xmlSchemaErrMemory(const char *msg)
1851 {
1852 __xmlSimpleError(XML_FROM_SCHEMASP, XML_ERR_NO_MEMORY, NULL, NULL,
1853 msg);
1854 }
1855 #endif
1856
1857 static void
1858 xmlSchemaPSimpleErr(const char *msg)
1859 {
1860 __xmlSimpleError(XML_FROM_SCHEMASP, XML_ERR_NO_MEMORY, NULL, NULL,
1861 msg);
1862 }
1863
1864 /**
1865 * xmlSchemaPErrMemory:
1866 * @node: a context node
1867 * @extra: extra informations
1868 *
1869 * Handle an out of memory condition
1870 */
1871 static void
1872 xmlSchemaPErrMemory(xmlSchemaParserCtxtPtr ctxt,
1873 const char *extra, xmlNodePtr node)
1874 {
1875 if (ctxt != NULL)
1876 ctxt->nberrors++;
1877 __xmlSimpleError(XML_FROM_SCHEMASP, XML_ERR_NO_MEMORY, node, NULL,
1878 extra);
1879 }
1880
1881 /**
1882 * xmlSchemaPErr:
1883 * @ctxt: the parsing context
1884 * @node: the context node
1885 * @error: the error code
1886 * @msg: the error message
1887 * @str1: extra data
1888 * @str2: extra data
1889 *
1890 * Handle a parser error
1891 */
1892 static void LIBXML_ATTR_FORMAT(4,0)
1893 xmlSchemaPErr(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int error,
1894 const char *msg, const xmlChar * str1, const xmlChar * str2)
1895 {
1896 xmlGenericErrorFunc channel = NULL;
1897 xmlStructuredErrorFunc schannel = NULL;
1898 void *data = NULL;
1899
1900 if (ctxt != NULL) {
1901 ctxt->nberrors++;
1902 ctxt->err = error;
1903 channel = ctxt->error;
1904 data = ctxt->errCtxt;
1905 schannel = ctxt->serror;
1906 }
1907 __xmlRaiseError(schannel, channel, data, ctxt, node, XML_FROM_SCHEMASP,
1908 error, XML_ERR_ERROR, NULL, 0,
1909 (const char *) str1, (const char *) str2, NULL, 0, 0,
1910 msg, str1, str2);
1911 }
1912
1913 /**
1914 * xmlSchemaPErr2:
1915 * @ctxt: the parsing context
1916 * @node: the context node
1917 * @node: the current child
1918 * @error: the error code
1919 * @msg: the error message
1920 * @str1: extra data
1921 * @str2: extra data
1922 *
1923 * Handle a parser error
1924 */
1925 static void LIBXML_ATTR_FORMAT(5,0)
1926 xmlSchemaPErr2(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node,
1927 xmlNodePtr child, int error,
1928 const char *msg, const xmlChar * str1, const xmlChar * str2)
1929 {
1930 if (child != NULL)
1931 xmlSchemaPErr(ctxt, child, error, msg, str1, str2);
1932 else
1933 xmlSchemaPErr(ctxt, node, error, msg, str1, str2);
1934 }
1935
1936
1937 /**
1938 * xmlSchemaPErrExt:
1939 * @ctxt: the parsing context
1940 * @node: the context node
1941 * @error: the error code
1942 * @strData1: extra data
1943 * @strData2: extra data
1944 * @strData3: extra data
1945 * @msg: the message
1946 * @str1: extra parameter for the message display
1947 * @str2: extra parameter for the message display
1948 * @str3: extra parameter for the message display
1949 * @str4: extra parameter for the message display
1950 * @str5: extra parameter for the message display
1951 *
1952 * Handle a parser error
1953 */
1954 static void LIBXML_ATTR_FORMAT(7,0)
1955 xmlSchemaPErrExt(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int error,
1956 const xmlChar * strData1, const xmlChar * strData2,
1957 const xmlChar * strData3, const char *msg, const xmlChar * str1,
1958 const xmlChar * str2, const xmlChar * str3, const xmlChar * str4,
1959 const xmlChar * str5)
1960 {
1961
1962 xmlGenericErrorFunc channel = NULL;
1963 xmlStructuredErrorFunc schannel = NULL;
1964 void *data = NULL;
1965
1966 if (ctxt != NULL) {
1967 ctxt->nberrors++;
1968 ctxt->err = error;
1969 channel = ctxt->error;
1970 data = ctxt->errCtxt;
1971 schannel = ctxt->serror;
1972 }
1973 __xmlRaiseError(schannel, channel, data, ctxt, node, XML_FROM_SCHEMASP,
1974 error, XML_ERR_ERROR, NULL, 0,
1975 (const char *) strData1, (const char *) strData2,
1976 (const char *) strData3, 0, 0, msg, str1, str2,
1977 str3, str4, str5);
1978 }
1979
1980 /************************************************************************
1981 * *
1982 * Allround error functions *
1983 * *
1984 ************************************************************************/
1985
1986 /**
1987 * xmlSchemaVTypeErrMemory:
1988 * @node: a context node
1989 * @extra: extra informations
1990 *
1991 * Handle an out of memory condition
1992 */
1993 static void
1994 xmlSchemaVErrMemory(xmlSchemaValidCtxtPtr ctxt,
1995 const char *extra, xmlNodePtr node)
1996 {
1997 if (ctxt != NULL) {
1998 ctxt->nberrors++;
1999 ctxt->err = XML_SCHEMAV_INTERNAL;
2000 }
2001 __xmlSimpleError(XML_FROM_SCHEMASV, XML_ERR_NO_MEMORY, node, NULL,
2002 extra);
2003 }
2004
2005 static void LIBXML_ATTR_FORMAT(2,0)
2006 xmlSchemaPSimpleInternalErr(xmlNodePtr node,
2007 const char *msg, const xmlChar *str)
2008 {
2009 __xmlSimpleError(XML_FROM_SCHEMASP, XML_SCHEMAP_INTERNAL, node,
2010 msg, (const char *) str);
2011 }
2012
2013 #define WXS_ERROR_TYPE_ERROR 1
2014 #define WXS_ERROR_TYPE_WARNING 2
2015 /**
2016 * xmlSchemaErr4Line:
2017 * @ctxt: the validation context
2018 * @errorLevel: the error level
2019 * @error: the error code
2020 * @node: the context node
2021 * @line: the line number
2022 * @msg: the error message
2023 * @str1: extra data
2024 * @str2: extra data
2025 * @str3: extra data
2026 * @str4: extra data
2027 *
2028 * Handle a validation error
2029 */
2030 static void LIBXML_ATTR_FORMAT(6,0)
2031 xmlSchemaErr4Line(xmlSchemaAbstractCtxtPtr ctxt,
2032 xmlErrorLevel errorLevel,
2033 int error, xmlNodePtr node, int line, const char *msg,
2034 const xmlChar *str1, const xmlChar *str2,
2035 const xmlChar *str3, const xmlChar *str4)
2036 {
2037 xmlStructuredErrorFunc schannel = NULL;
2038 xmlGenericErrorFunc channel = NULL;
2039 void *data = NULL;
2040
2041 if (ctxt != NULL) {
2042 if (ctxt->type == XML_SCHEMA_CTXT_VALIDATOR) {
2043 xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctxt;
2044 const char *file = NULL;
2045 int col = 0;
2046 if (errorLevel != XML_ERR_WARNING) {
2047 vctxt->nberrors++;
2048 vctxt->err = error;
2049 channel = vctxt->error;
2050 } else {
2051 channel = vctxt->warning;
2052 }
2053 schannel = vctxt->serror;
2054 data = vctxt->errCtxt;
2055
2056 /*
2057 * Error node. If we specify a line number, then
2058 * do not channel any node to the error function.
2059 */
2060 if (line == 0) {
2061 if ((node == NULL) &&
2062 (vctxt->depth >= 0) &&
2063 (vctxt->inode != NULL)) {
2064 node = vctxt->inode->node;
2065 }
2066 /*
2067 * Get filename and line if no node-tree.
2068 */
2069 if ((node == NULL) &&
2070 (vctxt->parserCtxt != NULL) &&
2071 (vctxt->parserCtxt->input != NULL)) {
2072 file = vctxt->parserCtxt->input->filename;
2073 line = vctxt->parserCtxt->input->line;
2074 col = vctxt->parserCtxt->input->col;
2075 }
2076 } else {
2077 /*
2078 * Override the given node's (if any) position
2079 * and channel only the given line number.
2080 */
2081 node = NULL;
2082 /*
2083 * Get filename.
2084 */
2085 if (vctxt->doc != NULL)
2086 file = (const char *) vctxt->doc->URL;
2087 else if ((vctxt->parserCtxt != NULL) &&
2088 (vctxt->parserCtxt->input != NULL))
2089 file = vctxt->parserCtxt->input->filename;
2090 }
2091 if (vctxt->locFunc != NULL) {
2092 if ((file == NULL) || (line == 0)) {
2093 unsigned long l;
2094 const char *f;
2095 vctxt->locFunc(vctxt->locCtxt, &f, &l);
2096 if (file == NULL)
2097 file = f;
2098 if (line == 0)
2099 line = (int) l;
2100 }
2101 }
2102 if ((file == NULL) && (vctxt->filename != NULL))
2103 file = vctxt->filename;
2104
2105 __xmlRaiseError(schannel, channel, data, ctxt,
2106 node, XML_FROM_SCHEMASV,
2107 error, errorLevel, file, line,
2108 (const char *) str1, (const char *) str2,
2109 (const char *) str3, 0, col, msg, str1, str2, str3, str4);
2110
2111 } else if (ctxt->type == XML_SCHEMA_CTXT_PARSER) {
2112 xmlSchemaParserCtxtPtr pctxt = (xmlSchemaParserCtxtPtr) ctxt;
2113 if (errorLevel != XML_ERR_WARNING) {
2114 pctxt->nberrors++;
2115 pctxt->err = error;
2116 channel = pctxt->error;
2117 } else {
2118 channel = pctxt->warning;
2119 }
2120 schannel = pctxt->serror;
2121 data = pctxt->errCtxt;
2122 __xmlRaiseError(schannel, channel, data, ctxt,
2123 node, XML_FROM_SCHEMASP, error,
2124 errorLevel, NULL, 0,
2125 (const char *) str1, (const char *) str2,
2126 (const char *) str3, 0, 0, msg, str1, str2, str3, str4);
2127 } else {
2128 TODO
2129 }
2130 }
2131 }
2132
2133 /**
2134 * xmlSchemaErr3:
2135 * @ctxt: the validation context
2136 * @node: the context node
2137 * @error: the error code
2138 * @msg: the error message
2139 * @str1: extra data
2140 * @str2: extra data
2141 * @str3: extra data
2142 *
2143 * Handle a validation error
2144 */
2145 static void LIBXML_ATTR_FORMAT(4,0)
2146 xmlSchemaErr3(xmlSchemaAbstractCtxtPtr actxt,
2147 int error, xmlNodePtr node, const char *msg,
2148 const xmlChar *str1, const xmlChar *str2, const xmlChar *str3)
2149 {
2150 xmlSchemaErr4Line(actxt, XML_ERR_ERROR, error, node, 0,
2151 msg, str1, str2, str3, NULL);
2152 }
2153
2154 static void LIBXML_ATTR_FORMAT(4,0)
2155 xmlSchemaErr4(xmlSchemaAbstractCtxtPtr actxt,
2156 int error, xmlNodePtr node, const char *msg,
2157 const xmlChar *str1, const xmlChar *str2,
2158 const xmlChar *str3, const xmlChar *str4)
2159 {
2160 xmlSchemaErr4Line(actxt, XML_ERR_ERROR, error, node, 0,
2161 msg, str1, str2, str3, str4);
2162 }
2163
2164 static void LIBXML_ATTR_FORMAT(4,0)
2165 xmlSchemaErr(xmlSchemaAbstractCtxtPtr actxt,
2166 int error, xmlNodePtr node, const char *msg,
2167 const xmlChar *str1, const xmlChar *str2)
2168 {
2169 xmlSchemaErr4(actxt, error, node, msg, str1, str2, NULL, NULL);
2170 }
2171
2172 static xmlChar *
2173 xmlSchemaFormatNodeForError(xmlChar ** msg,
2174 xmlSchemaAbstractCtxtPtr actxt,
2175 xmlNodePtr node)
2176 {
2177 xmlChar *str = NULL;
2178
2179 *msg = NULL;
2180 if ((node != NULL) &&
2181 (node->type != XML_ELEMENT_NODE) &&
2182 (node->type != XML_ATTRIBUTE_NODE))
2183 {
2184 /*
2185 * Don't try to format other nodes than element and
2186 * attribute nodes.
2187 * Play safe and return an empty string.
2188 */
2189 *msg = xmlStrdup(BAD_CAST "");
2190 return(*msg);
2191 }
2192 if (node != NULL) {
2193 /*
2194 * Work on tree nodes.
2195 */
2196 if (node->type == XML_ATTRIBUTE_NODE) {
2197 xmlNodePtr elem = node->parent;
2198
2199 *msg = xmlStrdup(BAD_CAST "Element '");
2200 if (elem->ns != NULL)
2201 *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2202 elem->ns->href, elem->name));
2203 else
2204 *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2205 NULL, elem->name));
2206 FREE_AND_NULL(str);
2207 *msg = xmlStrcat(*msg, BAD_CAST "', ");
2208 *msg = xmlStrcat(*msg, BAD_CAST "attribute '");
2209 } else {
2210 *msg = xmlStrdup(BAD_CAST "Element '");
2211 }
2212 if (node->ns != NULL)
2213 *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2214 node->ns->href, node->name));
2215 else
2216 *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2217 NULL, node->name));
2218 FREE_AND_NULL(str);
2219 *msg = xmlStrcat(*msg, BAD_CAST "': ");
2220 } else if (actxt->type == XML_SCHEMA_CTXT_VALIDATOR) {
2221 xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) actxt;
2222 /*
2223 * Work on node infos.
2224 */
2225 if (vctxt->inode->nodeType == XML_ATTRIBUTE_NODE) {
2226 xmlSchemaNodeInfoPtr ielem =
2227 vctxt->elemInfos[vctxt->depth];
2228
2229 *msg = xmlStrdup(BAD_CAST "Element '");
2230 *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2231 ielem->nsName, ielem->localName));
2232 FREE_AND_NULL(str);
2233 *msg = xmlStrcat(*msg, BAD_CAST "', ");
2234 *msg = xmlStrcat(*msg, BAD_CAST "attribute '");
2235 } else {
2236 *msg = xmlStrdup(BAD_CAST "Element '");
2237 }
2238 *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2239 vctxt->inode->nsName, vctxt->inode->localName));
2240 FREE_AND_NULL(str);
2241 *msg = xmlStrcat(*msg, BAD_CAST "': ");
2242 } else if (actxt->type == XML_SCHEMA_CTXT_PARSER) {
2243 /*
2244 * Hmm, no node while parsing?
2245 * Return an empty string, in case NULL will break something.
2246 */
2247 *msg = xmlStrdup(BAD_CAST "");
2248 } else {
2249 TODO
2250 return (NULL);
2251 }
2252
2253 /*
2254 * xmlSchemaFormatItemForReport() also returns an escaped format
2255 * string, so do this before calling it below (in the future).
2256 */
2257 xmlEscapeFormatString(msg);
2258
2259 /*
2260 * VAL TODO: The output of the given schema component is currently
2261 * disabled.
2262 */
2263 #if 0
2264 if ((type != NULL) && (xmlSchemaIsGlobalItem(type))) {
2265 *msg = xmlStrcat(*msg, BAD_CAST " [");
2266 *msg = xmlStrcat(*msg, xmlSchemaFormatItemForReport(&str,
2267 NULL, type, NULL, 0));
2268 FREE_AND_NULL(str)
2269 *msg = xmlStrcat(*msg, BAD_CAST "]");
2270 }
2271 #endif
2272 return (*msg);
2273 }
2274
2275 static void LIBXML_ATTR_FORMAT(3,0)
2276 xmlSchemaInternalErr2(xmlSchemaAbstractCtxtPtr actxt,
2277 const char *funcName,
2278 const char *message,
2279 const xmlChar *str1,
2280 const xmlChar *str2)
2281 {
2282 xmlChar *msg = NULL;
2283
2284 if (actxt == NULL)
2285 return;
2286 msg = xmlStrdup(BAD_CAST "Internal error: %s, ");
2287 msg = xmlStrcat(msg, BAD_CAST message);
2288 msg = xmlStrcat(msg, BAD_CAST ".\n");
2289
2290 if (actxt->type == XML_SCHEMA_CTXT_VALIDATOR)
2291 xmlSchemaErr3(actxt, XML_SCHEMAV_INTERNAL, NULL,
2292 (const char *) msg, (const xmlChar *) funcName, str1, str2);
2293 else if (actxt->type == XML_SCHEMA_CTXT_PARSER)
2294 xmlSchemaErr3(actxt, XML_SCHEMAP_INTERNAL, NULL,
2295 (const char *) msg, (const xmlChar *) funcName, str1, str2);
2296
2297 FREE_AND_NULL(msg)
2298 }
2299
2300 static void LIBXML_ATTR_FORMAT(3,0)
2301 xmlSchemaInternalErr(xmlSchemaAbstractCtxtPtr actxt,
2302 const char *funcName,
2303 const char *message)
2304 {
2305 xmlSchemaInternalErr2(actxt, funcName, message, NULL, NULL);
2306 }
2307
2308 #if 0
2309 static void LIBXML_ATTR_FORMAT(3,0)
2310 xmlSchemaPInternalErr(xmlSchemaParserCtxtPtr pctxt,
2311 const char *funcName,
2312 const char *message,
2313 const xmlChar *str1,
2314 const xmlChar *str2)
2315 {
2316 xmlSchemaInternalErr2(ACTXT_CAST pctxt, funcName, message,
2317 str1, str2);
2318 }
2319 #endif
2320
2321 static void LIBXML_ATTR_FORMAT(5,0)
2322 xmlSchemaCustomErr4(xmlSchemaAbstractCtxtPtr actxt,
2323 xmlParserErrors error,
2324 xmlNodePtr node,
2325 xmlSchemaBasicItemPtr item,
2326 const char *message,
2327 const xmlChar *str1, const xmlChar *str2,
2328 const xmlChar *str3, const xmlChar *str4)
2329 {
2330 xmlChar *msg = NULL;
2331
2332 if ((node == NULL) && (item != NULL) &&
2333 (actxt->type == XML_SCHEMA_CTXT_PARSER)) {
2334 node = WXS_ITEM_NODE(item);
2335 xmlSchemaFormatItemForReport(&msg, NULL, item, NULL);
2336 msg = xmlStrcat(msg, BAD_CAST ": ");
2337 } else
2338 xmlSchemaFormatNodeForError(&msg, actxt, node);
2339 msg = xmlStrcat(msg, (const xmlChar *) message);
2340 msg = xmlStrcat(msg, BAD_CAST ".\n");
2341 xmlSchemaErr4(actxt, error, node,
2342 (const char *) msg, str1, str2, str3, str4);
2343 FREE_AND_NULL(msg)
2344 }
2345
2346 static void LIBXML_ATTR_FORMAT(5,0)
2347 xmlSchemaCustomErr(xmlSchemaAbstractCtxtPtr actxt,
2348 xmlParserErrors error,
2349 xmlNodePtr node,
2350 xmlSchemaBasicItemPtr item,
2351 const char *message,
2352 const xmlChar *str1,
2353 const xmlChar *str2)
2354 {
2355 xmlSchemaCustomErr4(actxt, error, node, item,
2356 message, str1, str2, NULL, NULL);
2357 }
2358
2359
2360
2361 static void LIBXML_ATTR_FORMAT(5,0)
2362 xmlSchemaCustomWarning(xmlSchemaAbstractCtxtPtr actxt,
2363 xmlParserErrors error,
2364 xmlNodePtr node,
2365 xmlSchemaTypePtr type ATTRIBUTE_UNUSED,
2366 const char *message,
2367 const xmlChar *str1,
2368 const xmlChar *str2,
2369 const xmlChar *str3)
2370 {
2371 xmlChar *msg = NULL;
2372
2373 xmlSchemaFormatNodeForError(&msg, actxt, node);
2374 msg = xmlStrcat(msg, (const xmlChar *) message);
2375 msg = xmlStrcat(msg, BAD_CAST ".\n");
2376
2377 /* URGENT TODO: Set the error code to something sane. */
2378 xmlSchemaErr4Line(actxt, XML_ERR_WARNING, error, node, 0,
2379 (const char *) msg, str1, str2, str3, NULL);
2380
2381 FREE_AND_NULL(msg)
2382 }
2383
2384
2385
2386 static void LIBXML_ATTR_FORMAT(5,0)
2387 xmlSchemaKeyrefErr(xmlSchemaValidCtxtPtr vctxt,
2388 xmlParserErrors error,
2389 xmlSchemaPSVIIDCNodePtr idcNode,
2390 xmlSchemaTypePtr type ATTRIBUTE_UNUSED,
2391 const char *message,
2392 const xmlChar *str1,
2393 const xmlChar *str2)
2394 {
2395 xmlChar *msg = NULL, *qname = NULL;
2396
2397 msg = xmlStrdup(BAD_CAST "Element '%s': ");
2398 msg = xmlStrcat(msg, (const xmlChar *) message);
2399 msg = xmlStrcat(msg, BAD_CAST ".\n");
2400 xmlSchemaErr4Line(ACTXT_CAST vctxt, XML_ERR_ERROR,
2401 error, NULL, idcNode->nodeLine, (const char *) msg,
2402 xmlSchemaFormatQName(&qname,
2403 vctxt->nodeQNames->items[idcNode->nodeQNameID +1],
2404 vctxt->nodeQNames->items[idcNode->nodeQNameID]),
2405 str1, str2, NULL);
2406 FREE_AND_NULL(qname);
2407 FREE_AND_NULL(msg);
2408 }
2409
2410 static int
2411 xmlSchemaEvalErrorNodeType(xmlSchemaAbstractCtxtPtr actxt,
2412 xmlNodePtr node)
2413 {
2414 if (node != NULL)
2415 return (node->type);
2416 if ((actxt->type == XML_SCHEMA_CTXT_VALIDATOR) &&
2417 (((xmlSchemaValidCtxtPtr) actxt)->inode != NULL))
2418 return ( ((xmlSchemaValidCtxtPtr) actxt)->inode->nodeType);
2419 return (-1);
2420 }
2421
2422 static int
2423 xmlSchemaIsGlobalItem(xmlSchemaTypePtr item)
2424 {
2425 switch (item->type) {
2426 case XML_SCHEMA_TYPE_COMPLEX:
2427 case XML_SCHEMA_TYPE_SIMPLE:
2428 if (item->flags & XML_SCHEMAS_TYPE_GLOBAL)
2429 return(1);
2430 break;
2431 case XML_SCHEMA_TYPE_GROUP:
2432 return (1);
2433 case XML_SCHEMA_TYPE_ELEMENT:
2434 if ( ((xmlSchemaElementPtr) item)->flags &
2435 XML_SCHEMAS_ELEM_GLOBAL)
2436 return(1);
2437 break;
2438 case XML_SCHEMA_TYPE_ATTRIBUTE:
2439 if ( ((xmlSchemaAttributePtr) item)->flags &
2440 XML_SCHEMAS_ATTR_GLOBAL)
2441 return(1);
2442 break;
2443 /* Note that attribute groups are always global. */
2444 default:
2445 return(1);
2446 }
2447 return (0);
2448 }
2449
2450 static void
2451 xmlSchemaSimpleTypeErr(xmlSchemaAbstractCtxtPtr actxt,
2452 xmlParserErrors error,
2453 xmlNodePtr node,
2454 const xmlChar *value,
2455 xmlSchemaTypePtr type,
2456 int displayValue)
2457 {
2458 xmlChar *msg = NULL;
2459
2460 xmlSchemaFormatNodeForError(&msg, actxt, node);
2461
2462 if (displayValue || (xmlSchemaEvalErrorNodeType(actxt, node) ==
2463 XML_ATTRIBUTE_NODE))
2464 msg = xmlStrcat(msg, BAD_CAST "'%s' is not a valid value of ");
2465 else
2466 msg = xmlStrcat(msg, BAD_CAST "The character content is not a valid "
2467 "value of ");
2468
2469 if (! xmlSchemaIsGlobalItem(type))
2470 msg = xmlStrcat(msg, BAD_CAST "the local ");
2471 else
2472 msg = xmlStrcat(msg, BAD_CAST "the ");
2473
2474 if (WXS_IS_ATOMIC(type))
2475 msg = xmlStrcat(msg, BAD_CAST "atomic type");
2476 else if (WXS_IS_LIST(type))
2477 msg = xmlStrcat(msg, BAD_CAST "list type");
2478 else if (WXS_IS_UNION(type))
2479 msg = xmlStrcat(msg, BAD_CAST "union type");
2480
2481 if (xmlSchemaIsGlobalItem(type)) {
2482 xmlChar *str = NULL;
2483 msg = xmlStrcat(msg, BAD_CAST " '");
2484 if (type->builtInType != 0) {
2485 msg = xmlStrcat(msg, BAD_CAST "xs:");
2486 str = xmlStrdup(type->name);
2487 } else {
2488 const xmlChar *qName = xmlSchemaFormatQName(&str, type->targetNamespace, type->name);
2489 if (!str)
2490 str = xmlStrdup(qName);
2491 }
2492 msg = xmlStrcat(msg, xmlEscapeFormatString(&str));
2493 msg = xmlStrcat(msg, BAD_CAST "'");
2494 FREE_AND_NULL(str);
2495 }
2496 msg = xmlStrcat(msg, BAD_CAST ".\n");
2497 if (displayValue || (xmlSchemaEvalErrorNodeType(actxt, node) ==
2498 XML_ATTRIBUTE_NODE))
2499 xmlSchemaErr(actxt, error, node, (const char *) msg, value, NULL);
2500 else
2501 xmlSchemaErr(actxt, error, node, (const char *) msg, NULL, NULL);
2502 FREE_AND_NULL(msg)
2503 }
2504
2505 static const xmlChar *
2506 xmlSchemaFormatErrorNodeQName(xmlChar ** str,
2507 xmlSchemaNodeInfoPtr ni,
2508 xmlNodePtr node)
2509 {
2510 if (node != NULL) {
2511 if (node->ns != NULL)
2512 return (xmlSchemaFormatQName(str, node->ns->href, node->name));
2513 else
2514 return (xmlSchemaFormatQName(str, NULL, node->name));
2515 } else if (ni != NULL)
2516 return (xmlSchemaFormatQName(str, ni->nsName, ni->localName));
2517 return (NULL);
2518 }
2519
2520 static void
2521 xmlSchemaIllegalAttrErr(xmlSchemaAbstractCtxtPtr actxt,
2522 xmlParserErrors error,
2523 xmlSchemaAttrInfoPtr ni,
2524 xmlNodePtr node)
2525 {
2526 xmlChar *msg = NULL, *str = NULL;
2527
2528 xmlSchemaFormatNodeForError(&msg, actxt, node);
2529 msg = xmlStrcat(msg, BAD_CAST "The attribute '%s' is not allowed.\n");
2530 xmlSchemaErr(actxt, error, node, (const char *) msg,
2531 xmlSchemaFormatErrorNodeQName(&str, (xmlSchemaNodeInfoPtr) ni, node),
2532 NULL);
2533 FREE_AND_NULL(str)
2534 FREE_AND_NULL(msg)
2535 }
2536
2537 static void LIBXML_ATTR_FORMAT(5,0)
2538 xmlSchemaComplexTypeErr(xmlSchemaAbstractCtxtPtr actxt,
2539 xmlParserErrors error,
2540 xmlNodePtr node,
2541 xmlSchemaTypePtr type ATTRIBUTE_UNUSED,
2542 const char *message,
2543 int nbval,
2544 int nbneg,
2545 xmlChar **values)
2546 {
2547 xmlChar *str = NULL, *msg = NULL;
2548 xmlChar *localName, *nsName;
2549 const xmlChar *cur, *end;
2550 int i;
2551
2552 xmlSchemaFormatNodeForError(&msg, actxt, node);
2553 msg = xmlStrcat(msg, (const xmlChar *) message);
2554 msg = xmlStrcat(msg, BAD_CAST ".");
2555 /*
2556 * Note that is does not make sense to report that we have a
2557 * wildcard here, since the wildcard might be unfolded into
2558 * multiple transitions.
2559 */
2560 if (nbval + nbneg > 0) {
2561 if (nbval + nbneg > 1) {
2562 str = xmlStrdup(BAD_CAST " Expected is one of ( ");
2563 } else
2564 str = xmlStrdup(BAD_CAST " Expected is ( ");
2565 nsName = NULL;
2566
2567 for (i = 0; i < nbval + nbneg; i++) {
2568 cur = values[i];
2569 if (cur == NULL)
2570 continue;
2571 if ((cur[0] == 'n') && (cur[1] == 'o') && (cur[2] == 't') &&
2572 (cur[3] == ' ')) {
2573 cur += 4;
2574 str = xmlStrcat(str, BAD_CAST "##other");
2575 }
2576 /*
2577 * Get the local name.
2578 */
2579 localName = NULL;
2580
2581 end = cur;
2582 if (*end == '*') {
2583 localName = xmlStrdup(BAD_CAST "*");
2584 end++;
2585 } else {
2586 while ((*end != 0) && (*end != '|'))
2587 end++;
2588 localName = xmlStrncat(localName, BAD_CAST cur, end - cur);
2589 }
2590 if (*end != 0) {
2591 end++;
2592 /*
2593 * Skip "*|*" if they come with negated expressions, since
2594 * they represent the same negated wildcard.
2595 */
2596 if ((nbneg == 0) || (*end != '*') || (*localName != '*')) {
2597 /*
2598 * Get the namespace name.
2599 */
2600 cur = end;
2601 if (*end == '*') {
2602 nsName = xmlStrdup(BAD_CAST "{*}");
2603 } else {
2604 while (*end != 0)
2605 end++;
2606
2607 if (i >= nbval)
2608 nsName = xmlStrdup(BAD_CAST "{##other:");
2609 else
2610 nsName = xmlStrdup(BAD_CAST "{");
2611
2612 nsName = xmlStrncat(nsName, BAD_CAST cur, end - cur);
2613 nsName = xmlStrcat(nsName, BAD_CAST "}");
2614 }
2615 str = xmlStrcat(str, BAD_CAST nsName);
2616 FREE_AND_NULL(nsName)
2617 } else {
2618 FREE_AND_NULL(localName);
2619 continue;
2620 }
2621 }
2622 str = xmlStrcat(str, BAD_CAST localName);
2623 FREE_AND_NULL(localName);
2624
2625 if (i < nbval + nbneg -1)
2626 str = xmlStrcat(str, BAD_CAST ", ");
2627 }
2628 str = xmlStrcat(str, BAD_CAST " ).\n");
2629 msg = xmlStrcat(msg, xmlEscapeFormatString(&str));
2630 FREE_AND_NULL(str)
2631 } else
2632 msg = xmlStrcat(msg, BAD_CAST "\n");
2633 xmlSchemaErr(actxt, error, node, (const char *) msg, NULL, NULL);
2634 xmlFree(msg);
2635 }
2636
2637 static void LIBXML_ATTR_FORMAT(8,0)
2638 xmlSchemaFacetErr(xmlSchemaAbstractCtxtPtr actxt,
2639 xmlParserErrors error,
2640 xmlNodePtr node,
2641 const xmlChar *value,
2642 unsigned long length,
2643 xmlSchemaTypePtr type,
2644 xmlSchemaFacetPtr facet,
2645 const char *message,
2646 const xmlChar *str1,
2647 const xmlChar *str2)
2648 {
2649 xmlChar *str = NULL, *msg = NULL;
2650 xmlSchemaTypeType facetType;
2651 int nodeType = xmlSchemaEvalErrorNodeType(actxt, node);
2652
2653 xmlSchemaFormatNodeForError(&msg, actxt, node);
2654 if (error == XML_SCHEMAV_CVC_ENUMERATION_VALID) {
2655 facetType = XML_SCHEMA_FACET_ENUMERATION;
2656 /*
2657 * If enumerations are validated, one must not expect the
2658 * facet to be given.
2659 */
2660 } else
2661 facetType = facet->type;
2662 msg = xmlStrcat(msg, BAD_CAST "[");
2663 msg = xmlStrcat(msg, BAD_CAST "facet '");
2664 msg = xmlStrcat(msg, xmlSchemaFacetTypeToString(facetType));
2665 msg = xmlStrcat(msg, BAD_CAST "'] ");
2666 if (message == NULL) {
2667 /*
2668 * Use a default message.
2669 */
2670 if ((facetType == XML_SCHEMA_FACET_LENGTH) ||
2671 (facetType == XML_SCHEMA_FACET_MINLENGTH) ||
2672 (facetType == XML_SCHEMA_FACET_MAXLENGTH)) {
2673
2674 char len[25], actLen[25];
2675
2676 /* FIXME, TODO: What is the max expected string length of the
2677 * this value?
2678 */
2679 if (nodeType == XML_ATTRIBUTE_NODE)
2680 msg = xmlStrcat(msg, BAD_CAST "The value '%s' has a length of '%s'; ");
2681 else
2682 msg = xmlStrcat(msg, BAD_CAST "The value has a length of '%s'; ");
2683
2684 snprintf(len, 24, "%lu", xmlSchemaGetFacetValueAsULong(facet));
2685 snprintf(actLen, 24, "%lu", length);
2686
2687 if (facetType == XML_SCHEMA_FACET_LENGTH)
2688 msg = xmlStrcat(msg,
2689 BAD_CAST "this differs from the allowed length of '%s'.\n");
2690 else if (facetType == XML_SCHEMA_FACET_MAXLENGTH)
2691 msg = xmlStrcat(msg,
2692 BAD_CAST "this exceeds the allowed maximum length of '%s'.\n");
2693 else if (facetType == XML_SCHEMA_FACET_MINLENGTH)
2694 msg = xmlStrcat(msg,
2695 BAD_CAST "this underruns the allowed minimum length of '%s'.\n");
2696
2697 if (nodeType == XML_ATTRIBUTE_NODE)
2698 xmlSchemaErr3(actxt, error, node, (const char *) msg,
2699 value, (const xmlChar *) actLen, (const xmlChar *) len);
2700 else
2701 xmlSchemaErr(actxt, error, node, (const char *) msg,
2702 (const xmlChar *) actLen, (const xmlChar *) len);
2703
2704 } else if (facetType == XML_SCHEMA_FACET_ENUMERATION) {
2705 msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not an element "
2706 "of the set {%s}.\n");
2707 xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2708 xmlSchemaFormatFacetEnumSet(actxt, &str, type));
2709 } else if (facetType == XML_SCHEMA_FACET_PATTERN) {
2710 msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not accepted "
2711 "by the pattern '%s'.\n");
2712 xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2713 facet->value);
2714 } else if (facetType == XML_SCHEMA_FACET_MININCLUSIVE) {
2715 msg = xmlStrcat(msg, BAD_CAST "The value '%s' is less than the "
2716 "minimum value allowed ('%s').\n");
2717 xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2718 facet->value);
2719 } else if (facetType == XML_SCHEMA_FACET_MAXINCLUSIVE) {
2720 msg = xmlStrcat(msg, BAD_CAST "The value '%s' is greater than the "
2721 "maximum value allowed ('%s').\n");
2722 xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2723 facet->value);
2724 } else if (facetType == XML_SCHEMA_FACET_MINEXCLUSIVE) {
2725 msg = xmlStrcat(msg, BAD_CAST "The value '%s' must be greater than "
2726 "'%s'.\n");
2727 xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2728 facet->value);
2729 } else if (facetType == XML_SCHEMA_FACET_MAXEXCLUSIVE) {
2730 msg = xmlStrcat(msg, BAD_CAST "The value '%s' must be less than "
2731 "'%s'.\n");
2732 xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2733 facet->value);
2734 } else if (facetType == XML_SCHEMA_FACET_TOTALDIGITS) {
2735 msg = xmlStrcat(msg, BAD_CAST "The value '%s' has more "
2736 "digits than are allowed ('%s').\n");
2737 xmlSchemaErr(actxt, error, node, (const char*) msg, value,
2738 facet->value);
2739 } else if (facetType == XML_SCHEMA_FACET_FRACTIONDIGITS) {
2740 msg = xmlStrcat(msg, BAD_CAST "The value '%s' has more fractional "
2741 "digits than are allowed ('%s').\n");
2742 xmlSchemaErr(actxt, error, node, (const char*) msg, value,
2743 facet->value);
2744 } else if (nodeType == XML_ATTRIBUTE_NODE) {
2745 msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not facet-valid.\n");
2746 xmlSchemaErr(actxt, error, node, (const char *) msg, value, NULL);
2747 } else {
2748 msg = xmlStrcat(msg, BAD_CAST "The value is not facet-valid.\n");
2749 xmlSchemaErr(actxt, error, node, (const char *) msg, NULL, NULL);
2750 }
2751 } else {
2752 msg = xmlStrcat(msg, (const xmlChar *) message);
2753 msg = xmlStrcat(msg, BAD_CAST ".\n");
2754 xmlSchemaErr(actxt, error, node, (const char *) msg, str1, str2);
2755 }
2756 FREE_AND_NULL(str)
2757 xmlFree(msg);
2758 }
2759
2760 #define VERROR(err, type, msg) \
2761 xmlSchemaCustomErr(ACTXT_CAST vctxt, err, NULL, type, msg, NULL, NULL);
2762
2763 #define VERROR_INT(func, msg) xmlSchemaInternalErr(ACTXT_CAST vctxt, func, msg);
2764
2765 #define PERROR_INT(func, msg) xmlSchemaInternalErr(ACTXT_CAST pctxt, func, msg);
2766 #define PERROR_INT2(func, msg) xmlSchemaInternalErr(ACTXT_CAST ctxt, func, msg);
2767
2768 #define AERROR_INT(func, msg) xmlSchemaInternalErr(actxt, func, msg);
2769
2770
2771 /**
2772 * xmlSchemaPMissingAttrErr:
2773 * @ctxt: the schema validation context
2774 * @ownerDes: the designation of the owner
2775 * @ownerName: the name of the owner
2776 * @ownerItem: the owner as a schema object
2777 * @ownerElem: the owner as an element node
2778 * @node: the parent element node of the missing attribute node
2779 * @type: the corresponding type of the attribute node
2780 *
2781 * Reports an illegal attribute.
2782 */
2783 static void
2784 xmlSchemaPMissingAttrErr(xmlSchemaParserCtxtPtr ctxt,
2785 xmlParserErrors error,
2786 xmlSchemaBasicItemPtr ownerItem,
2787 xmlNodePtr ownerElem,
2788 const char *name,
2789 const char *message)
2790 {
2791 xmlChar *des = NULL;
2792
2793 xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem);
2794
2795 if (message != NULL)
2796 xmlSchemaPErr(ctxt, ownerElem, error, "%s: %s.\n", BAD_CAST des, BAD_CAST message);
2797 else
2798 xmlSchemaPErr(ctxt, ownerElem, error,
2799 "%s: The attribute '%s' is required but missing.\n",
2800 BAD_CAST des, BAD_CAST name);
2801 FREE_AND_NULL(des);
2802 }
2803
2804
2805 /**
2806 * xmlSchemaPResCompAttrErr:
2807 * @ctxt: the schema validation context
2808 * @error: the error code
2809 * @ownerDes: the designation of the owner
2810 * @ownerItem: the owner as a schema object
2811 * @ownerElem: the owner as an element node
2812 * @name: the name of the attribute holding the QName
2813 * @refName: the referenced local name
2814 * @refURI: the referenced namespace URI
2815 * @message: optional message
2816 *
2817 * Used to report QName attribute values that failed to resolve
2818 * to schema components.
2819 */
2820 static void
2821 xmlSchemaPResCompAttrErr(xmlSchemaParserCtxtPtr ctxt,
2822 xmlParserErrors error,
2823 xmlSchemaBasicItemPtr ownerItem,
2824 xmlNodePtr ownerElem,
2825 const char *name,
2826 const xmlChar *refName,
2827 const xmlChar *refURI,
2828 xmlSchemaTypeType refType,
2829 const char *refTypeStr)
2830 {
2831 xmlChar *des = NULL, *strA = NULL;
2832
2833 xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem);
2834 if (refTypeStr == NULL)
2835 refTypeStr = (const char *) xmlSchemaItemTypeToStr(refType);
2836 xmlSchemaPErrExt(ctxt, ownerElem, error,
2837 NULL, NULL, NULL,
2838 "%s, attribute '%s': The QName value '%s' does not resolve to a(n) "
2839 "%s.\n", BAD_CAST des, BAD_CAST name,
2840 xmlSchemaFormatQName(&strA, refURI, refName),
2841 BAD_CAST refTypeStr, NULL);
2842 FREE_AND_NULL(des)
2843 FREE_AND_NULL(strA)
2844 }
2845
2846 /**
2847 * xmlSchemaPCustomAttrErr:
2848 * @ctxt: the schema parser context
2849 * @error: the error code
2850 * @ownerDes: the designation of the owner
2851 * @ownerItem: the owner as a schema object
2852 * @attr: the illegal attribute node
2853 *
2854 * Reports an illegal attribute during the parse.
2855 */
2856 static void
2857 xmlSchemaPCustomAttrErr(xmlSchemaParserCtxtPtr ctxt,
2858 xmlParserErrors error,
2859 xmlChar **ownerDes,
2860 xmlSchemaBasicItemPtr ownerItem,
2861 xmlAttrPtr attr,
2862 const char *msg)
2863 {
2864 xmlChar *des = NULL;
2865
2866 if (ownerDes == NULL)
2867 xmlSchemaFormatItemForReport(&des, NULL, ownerItem, attr->parent);
2868 else if (*ownerDes == NULL) {
2869 xmlSchemaFormatItemForReport(ownerDes, NULL, ownerItem, attr->parent);
2870 des = *ownerDes;
2871 } else
2872 des = *ownerDes;
2873 if (attr == NULL) {
2874 xmlSchemaPErrExt(ctxt, NULL, error, NULL, NULL, NULL,
2875 "%s, attribute '%s': %s.\n",
2876 BAD_CAST des, (const xmlChar *) "Unknown",
2877 (const xmlChar *) msg, NULL, NULL);
2878 } else {
2879 xmlSchemaPErrExt(ctxt, (xmlNodePtr) attr, error, NULL, NULL, NULL,
2880 "%s, attribute '%s': %s.\n",
2881 BAD_CAST des, attr->name, (const xmlChar *) msg, NULL, NULL);
2882 }
2883 if (ownerDes == NULL)
2884 FREE_AND_NULL(des);
2885 }
2886
2887 /**
2888 * xmlSchemaPIllegalAttrErr:
2889 * @ctxt: the schema parser context
2890 * @error: the error code
2891 * @ownerDes: the designation of the attribute's owner
2892 * @ownerItem: the attribute's owner item
2893 * @attr: the illegal attribute node
2894 *
2895 * Reports an illegal attribute during the parse.
2896 */
2897 static void
2898 xmlSchemaPIllegalAttrErr(xmlSchemaParserCtxtPtr ctxt,
2899 xmlParserErrors error,
2900 xmlSchemaBasicItemPtr ownerComp ATTRIBUTE_UNUSED,
2901 xmlAttrPtr attr)
2902 {
2903 xmlChar *strA = NULL, *strB = NULL;
2904
2905 xmlSchemaFormatNodeForError(&strA, ACTXT_CAST ctxt, attr->parent);
2906 xmlSchemaErr4(ACTXT_CAST ctxt, error, (xmlNodePtr) attr,
2907 "%sThe attribute '%s' is not allowed.\n", BAD_CAST strA,
2908 xmlSchemaFormatQNameNs(&strB, attr->ns, attr->name),
2909 NULL, NULL);
2910 FREE_AND_NULL(strA);
2911 FREE_AND_NULL(strB);
2912 }
2913
2914 /**
2915 * xmlSchemaPCustomErr:
2916 * @ctxt: the schema parser context
2917 * @error: the error code
2918 * @itemDes: the designation of the schema item
2919 * @item: the schema item
2920 * @itemElem: the node of the schema item
2921 * @message: the error message
2922 * @str1: an optional param for the error message
2923 * @str2: an optional param for the error message
2924 * @str3: an optional param for the error message
2925 *
2926 * Reports an error during parsing.
2927 */
2928 static void LIBXML_ATTR_FORMAT(5,0)
2929 xmlSchemaPCustomErrExt(xmlSchemaParserCtxtPtr ctxt,
2930 xmlParserErrors error,
2931 xmlSchemaBasicItemPtr item,
2932 xmlNodePtr itemElem,
2933 const char *message,
2934 const xmlChar *str1,
2935 const xmlChar *str2,
2936 const xmlChar *str3)
2937 {
2938 xmlChar *des = NULL, *msg = NULL;
2939
2940 xmlSchemaFormatItemForReport(&des, NULL, item, itemElem);
2941 msg = xmlStrdup(BAD_CAST "%s: ");
2942 msg = xmlStrcat(msg, (const xmlChar *) message);
2943 msg = xmlStrcat(msg, BAD_CAST ".\n");
2944 if ((itemElem == NULL) && (item != NULL))
2945 itemElem = WXS_ITEM_NODE(item);
2946 xmlSchemaPErrExt(ctxt, itemElem, error, NULL, NULL, NULL,
2947 (const char *) msg, BAD_CAST des, str1, str2, str3, NULL);
2948 FREE_AND_NULL(des);
2949 FREE_AND_NULL(msg);
2950 }
2951
2952 /**
2953 * xmlSchemaPCustomErr:
2954 * @ctxt: the schema parser context
2955 * @error: the error code
2956 * @itemDes: the designation of the schema item
2957 * @item: the schema item
2958 * @itemElem: the node of the schema item
2959 * @message: the error message
2960 * @str1: the optional param for the error message
2961 *
2962 * Reports an error during parsing.
2963 */
2964 static void LIBXML_ATTR_FORMAT(5,0)
2965 xmlSchemaPCustomErr(xmlSchemaParserCtxtPtr ctxt,
2966 xmlParserErrors error,
2967 xmlSchemaBasicItemPtr item,
2968 xmlNodePtr itemElem,
2969 const char *message,
2970 const xmlChar *str1)
2971 {
2972 xmlSchemaPCustomErrExt(ctxt, error, item, itemElem, message,
2973 str1, NULL, NULL);
2974 }
2975
2976 /**
2977 * xmlSchemaPAttrUseErr:
2978 * @ctxt: the schema parser context
2979 * @error: the error code
2980 * @itemDes: the designation of the schema type
2981 * @item: the schema type
2982 * @itemElem: the node of the schema type
2983 * @attr: the invalid schema attribute
2984 * @message: the error message
2985 * @str1: the optional param for the error message
2986 *
2987 * Reports an attribute use error during parsing.
2988 */
2989 static void LIBXML_ATTR_FORMAT(6,0)
2990 xmlSchemaPAttrUseErr4(xmlSchemaParserCtxtPtr ctxt,
2991 xmlParserErrors error,
2992 xmlNodePtr node,
2993 xmlSchemaBasicItemPtr ownerItem,
2994 const xmlSchemaAttributeUsePtr attruse,
2995 const char *message,
2996 const xmlChar *str1, const xmlChar *str2,
2997 const xmlChar *str3,const xmlChar *str4)
2998 {
2999 xmlChar *str = NULL, *msg = NULL;
3000
3001 xmlSchemaFormatItemForReport(&msg, NULL, ownerItem, NULL);
3002 msg = xmlStrcat(msg, BAD_CAST ", ");
3003 msg = xmlStrcat(msg,
3004 BAD_CAST xmlSchemaFormatItemForReport(&str, NULL,
3005 WXS_BASIC_CAST attruse, NULL));
3006 FREE_AND_NULL(str);
3007 msg = xmlStrcat(msg, BAD_CAST ": ");
3008 msg = xmlStrcat(msg, (const xmlChar *) message);
3009 msg = xmlStrcat(msg, BAD_CAST ".\n");
3010 xmlSchemaErr4(ACTXT_CAST ctxt, error, node,
3011 (const char *) msg, str1, str2, str3, str4);
3012 xmlFree(msg);
3013 }
3014
3015 /**
3016 * xmlSchemaPIllegalFacetAtomicErr:
3017 * @ctxt: the schema parser context
3018 * @error: the error code
3019 * @type: the schema type
3020 * @baseType: the base type of type
3021 * @facet: the illegal facet
3022 *
3023 * Reports an illegal facet for atomic simple types.
3024 */
3025 static void
3026 xmlSchemaPIllegalFacetAtomicErr(xmlSchemaParserCtxtPtr ctxt,
3027 xmlParserErrors error,
3028 xmlSchemaTypePtr type,
3029 xmlSchemaTypePtr baseType,
3030 xmlSchemaFacetPtr facet)
3031 {
3032 xmlChar *des = NULL, *strT = NULL;
3033
3034 xmlSchemaFormatItemForReport(&des, NULL, WXS_BASIC_CAST type, type->node);
3035 xmlSchemaPErrExt(ctxt, type->node, error, NULL, NULL, NULL,
3036 "%s: The facet '%s' is not allowed on types derived from the "
3037 "type %s.\n",
3038 BAD_CAST des, xmlSchemaFacetTypeToString(facet->type),
3039 xmlSchemaFormatItemForReport(&strT, NULL, WXS_BASIC_CAST baseType, NULL),
3040 NULL, NULL);
3041 FREE_AND_NULL(des);
3042 FREE_AND_NULL(strT);
3043 }
3044
3045 /**
3046 * xmlSchemaPIllegalFacetListUnionErr:
3047 * @ctxt: the schema parser context
3048 * @error: the error code
3049 * @itemDes: the designation of the schema item involved
3050 * @item: the schema item involved
3051 * @facet: the illegal facet
3052 *
3053 * Reports an illegal facet for <list> and <union>.
3054 */
3055 static void
3056 xmlSchemaPIllegalFacetListUnionErr(xmlSchemaParserCtxtPtr ctxt,
3057 xmlParserErrors error,
3058 xmlSchemaTypePtr type,
3059 xmlSchemaFacetPtr facet)
3060 {
3061 xmlChar *des = NULL;
3062
3063 xmlSchemaFormatItemForReport(&des, NULL, WXS_BASIC_CAST type,
3064 type->node);
3065 xmlSchemaPErr(ctxt, type->node, error,
3066 "%s: The facet '%s' is not allowed.\n",
3067 BAD_CAST des, xmlSchemaFacetTypeToString(facet->type));
3068 FREE_AND_NULL(des);
3069 }
3070
3071 /**
3072 * xmlSchemaPMutualExclAttrErr:
3073 * @ctxt: the schema validation context
3074 * @error: the error code
3075 * @elemDes: the designation of the parent element node
3076 * @attr: the bad attribute node
3077 * @type: the corresponding type of the attribute node
3078 *
3079 * Reports an illegal attribute.
3080 */
3081 static void
3082 xmlSchemaPMutualExclAttrErr(xmlSchemaParserCtxtPtr ctxt,
3083 xmlParserErrors error,
3084 xmlSchemaBasicItemPtr ownerItem,
3085 xmlAttrPtr attr,
3086 const char *name1,
3087 const char *name2)
3088 {
3089 xmlChar *des = NULL;
3090
3091 xmlSchemaFormatItemForReport(&des, NULL, WXS_BASIC_CAST ownerItem, attr->parent);
3092 xmlSchemaPErrExt(ctxt, (xmlNodePtr) attr, error, NULL, NULL, NULL,
3093 "%s: The attributes '%s' and '%s' are mutually exclusive.\n",
3094 BAD_CAST des, BAD_CAST name1, BAD_CAST name2, NULL, NULL);
3095 FREE_AND_NULL(des);
3096 }
3097
3098 /**
3099 * xmlSchemaPSimpleTypeErr:
3100 * @ctxt: the schema validation context
3101 * @error: the error code
3102 * @type: the type specifier
3103 * @ownerDes: the designation of the owner
3104 * @ownerItem: the schema object if existent
3105 * @node: the validated node
3106 * @value: the validated value
3107 *
3108 * Reports a simple type validation error.
3109 * TODO: Should this report the value of an element as well?
3110 */
3111 static void LIBXML_ATTR_FORMAT(8,0)
3112 xmlSchemaPSimpleTypeErr(xmlSchemaParserCtxtPtr ctxt,
3113 xmlParserErrors error,
3114 xmlSchemaBasicItemPtr ownerItem ATTRIBUTE_UNUSED,
3115 xmlNodePtr node,
3116 xmlSchemaTypePtr type,
3117 const char *expected,
3118 const xmlChar *value,
3119 const char *message,
3120 const xmlChar *str1,
3121 const xmlChar *str2)
3122 {
3123 xmlChar *msg = NULL;
3124
3125 xmlSchemaFormatNodeForError(&msg, ACTXT_CAST ctxt, node);
3126 if (message == NULL) {
3127 /*
3128 * Use default messages.
3129 */
3130 if (type != NULL) {
3131 if (node->type == XML_ATTRIBUTE_NODE)
3132 msg = xmlStrcat(msg, BAD_CAST "'%s' is not a valid value of ");
3133 else
3134 msg = xmlStrcat(msg, BAD_CAST "The character content is not a "
3135 "valid value of ");
3136 if (! xmlSchemaIsGlobalItem(type))
3137 msg = xmlStrcat(msg, BAD_CAST "the local ");
3138 else
3139 msg = xmlStrcat(msg, BAD_CAST "the ");
3140
3141 if (WXS_IS_ATOMIC(type))
3142 msg = xmlStrcat(msg, BAD_CAST "atomic type");
3143 else if (WXS_IS_LIST(type))
3144 msg = xmlStrcat(msg, BAD_CAST "list type");
3145 else if (WXS_IS_UNION(type))
3146 msg = xmlStrcat(msg, BAD_CAST "union type");
3147
3148 if (xmlSchemaIsGlobalItem(type)) {
3149 xmlChar *str = NULL;
3150 msg = xmlStrcat(msg, BAD_CAST " '");
3151