ReactOS  0.4.15-dev-3303-g1ade494
xmlschemas.c
Go to the documentation of this file.
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  * - Eliminated item creation for: <restriction>, <extension>,
26  * <simpleContent>, <complexContent>, <list>, <union>
27  *
28  * PROBLEMS:
29  * - http://lists.w3.org/Archives/Public/www-xml-schema-comments/2005JulSep/0337.html
30  * IDC XPath expression and chameleon includes: the targetNamespace is changed, so
31  * XPath will have trouble to resolve to this namespace, since not known.
32  *
33  *
34  * CONSTRAINTS:
35  *
36  * Schema Component Constraint:
37  * All Group Limited (cos-all-limited)
38  * Status: complete
39  * (1.2)
40  * In xmlSchemaGroupDefReferenceTermFixup() and
41  * (2)
42  * In xmlSchemaParseModelGroup()
43  * TODO: Actually this should go to component-level checks,
44  * but is done here due to performance. Move it to an other layer
45  * is schema construction via an API is implemented.
46  */
47 
48 /* To avoid EBCDIC trouble when parsing on zOS */
49 #if defined(__MVS__)
50 #pragma convert("ISO8859-1")
51 #endif
52 
53 #define IN_LIBXML
54 #include "libxml.h"
55 
56 #ifdef LIBXML_SCHEMAS_ENABLED
57 
58 #include <string.h>
59 #include <libxml/xmlmemory.h>
60 #include <libxml/parser.h>
61 #include <libxml/parserInternals.h>
62 #include <libxml/hash.h>
63 #include <libxml/uri.h>
64 #include <libxml/xmlschemas.h>
66 #include <libxml/xmlschemastypes.h>
67 #include <libxml/xmlautomata.h>
68 #include <libxml/xmlregexp.h>
69 #include <libxml/dict.h>
70 #include <libxml/encoding.h>
71 #include <libxml/xmlIO.h>
72 #ifdef LIBXML_PATTERN_ENABLED
73 #include <libxml/pattern.h>
74 #endif
75 #ifdef LIBXML_READER_ENABLED
76 #include <libxml/xmlreader.h>
77 #endif
78 
79 /* #define DEBUG 1 */
80 
81 /* #define DEBUG_CONTENT 1 */
82 
83 /* #define DEBUG_TYPE 1 */
84 
85 /* #define DEBUG_CONTENT_REGEXP 1 */
86 
87 /* #define DEBUG_AUTOMATA 1 */
88 
89 /* #define DEBUG_IDC */
90 
91 /* #define DEBUG_IDC_NODE_TABLE */
92 
93 /* #define WXS_ELEM_DECL_CONS_ENABLED */
94 
95 #ifdef DEBUG_IDC
96  #ifndef DEBUG_IDC_NODE_TABLE
97  #define DEBUG_IDC_NODE_TABLE
98  #endif
99 #endif
100 
101 /* #define ENABLE_PARTICLE_RESTRICTION 1 */
102 
103 #define ENABLE_REDEFINE
104 
105 /* #define ENABLE_NAMED_LOCALS */
106 
107 /* #define ENABLE_IDC_NODE_TABLES_TEST */
108 
109 #define DUMP_CONTENT_MODEL
110 
111 #ifdef LIBXML_READER_ENABLED
112 /* #define XML_SCHEMA_READER_ENABLED */
113 #endif
114 
115 #define UNBOUNDED (1 << 30)
116 #define TODO \
117  xmlGenericError(xmlGenericErrorContext, \
118  "Unimplemented block at %s:%d\n", \
119  __FILE__, __LINE__);
120 
121 #define XML_SCHEMAS_NO_NAMESPACE (const xmlChar *) "##"
122 
123 /*
124  * The XML Schemas namespaces
125  */
126 static const xmlChar *xmlSchemaNs = (const xmlChar *)
127  "http://www.w3.org/2001/XMLSchema";
128 
129 static const xmlChar *xmlSchemaInstanceNs = (const xmlChar *)
130  "http://www.w3.org/2001/XMLSchema-instance";
131 
132 static const xmlChar *xmlNamespaceNs = (const xmlChar *)
133  "http://www.w3.org/2000/xmlns/";
134 
135 /*
136 * Come casting macros.
137 */
138 #define ACTXT_CAST (xmlSchemaAbstractCtxtPtr)
139 #define PCTXT_CAST (xmlSchemaParserCtxtPtr)
140 #define VCTXT_CAST (xmlSchemaValidCtxtPtr)
141 #define WXS_BASIC_CAST (xmlSchemaBasicItemPtr)
142 #define WXS_TREE_CAST (xmlSchemaTreeItemPtr)
143 #define WXS_PTC_CAST (xmlSchemaParticlePtr)
144 #define WXS_TYPE_CAST (xmlSchemaTypePtr)
145 #define WXS_ELEM_CAST (xmlSchemaElementPtr)
146 #define WXS_ATTR_GROUP_CAST (xmlSchemaAttributeGroupPtr)
147 #define WXS_ATTR_CAST (xmlSchemaAttributePtr)
148 #define WXS_ATTR_USE_CAST (xmlSchemaAttributeUsePtr)
149 #define WXS_ATTR_PROHIB_CAST (xmlSchemaAttributeUseProhibPtr)
150 #define WXS_MODEL_GROUPDEF_CAST (xmlSchemaModelGroupDefPtr)
151 #define WXS_MODEL_GROUP_CAST (xmlSchemaModelGroupPtr)
152 #define WXS_IDC_CAST (xmlSchemaIDCPtr)
153 #define WXS_QNAME_CAST (xmlSchemaQNameRefPtr)
154 #define WXS_LIST_CAST (xmlSchemaItemListPtr)
155 
156 /*
157 * Macros to query common properties of components.
158 */
159 #define WXS_ITEM_NODE(i) xmlSchemaGetComponentNode(WXS_BASIC_CAST (i))
160 
161 #define WXS_ITEM_TYPE_NAME(i) xmlSchemaGetComponentTypeStr(WXS_BASIC_CAST (i))
162 /*
163 * Macros for element declarations.
164 */
165 #define WXS_ELEM_TYPEDEF(e) (e)->subtypes
166 
167 #define WXS_SUBST_HEAD(item) (item)->refDecl
168 /*
169 * Macros for attribute declarations.
170 */
171 #define WXS_ATTR_TYPEDEF(a) (a)->subtypes
172 /*
173 * Macros for attribute uses.
174 */
175 #define WXS_ATTRUSE_DECL(au) (WXS_ATTR_USE_CAST (au))->attrDecl
176 
177 #define WXS_ATTRUSE_TYPEDEF(au) WXS_ATTR_TYPEDEF(WXS_ATTRUSE_DECL( WXS_ATTR_USE_CAST au))
178 
179 #define WXS_ATTRUSE_DECL_NAME(au) (WXS_ATTRUSE_DECL(au))->name
180 
181 #define WXS_ATTRUSE_DECL_TNS(au) (WXS_ATTRUSE_DECL(au))->targetNamespace
182 /*
183 * Macros for attribute groups.
184 */
185 #define WXS_ATTR_GROUP_HAS_REFS(ag) ((WXS_ATTR_GROUP_CAST (ag))->flags & XML_SCHEMAS_ATTRGROUP_HAS_REFS)
186 #define WXS_ATTR_GROUP_EXPANDED(ag) ((WXS_ATTR_GROUP_CAST (ag))->flags & XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED)
187 /*
188 * Macros for particles.
189 */
190 #define WXS_PARTICLE(p) WXS_PTC_CAST (p)
191 
192 #define WXS_PARTICLE_TERM(p) (WXS_PARTICLE(p))->children
193 
194 #define WXS_PARTICLE_TERM_AS_ELEM(p) (WXS_ELEM_CAST WXS_PARTICLE_TERM(p))
195 
196 #define WXS_PARTICLE_MODEL(p) WXS_MODEL_GROUP_CAST WXS_PARTICLE(p)->children
197 /*
198 * Macros for model groups definitions.
199 */
200 #define WXS_MODELGROUPDEF_MODEL(mgd) (WXS_MODEL_GROUP_CAST (mgd))->children
201 /*
202 * Macros for model groups.
203 */
204 #define WXS_IS_MODEL_GROUP(i) \
205  (((i)->type == XML_SCHEMA_TYPE_SEQUENCE) || \
206  ((i)->type == XML_SCHEMA_TYPE_CHOICE) || \
207  ((i)->type == XML_SCHEMA_TYPE_ALL))
208 
209 #define WXS_MODELGROUP_PARTICLE(mg) WXS_PTC_CAST (mg)->children
210 /*
211 * Macros for schema buckets.
212 */
213 #define WXS_IS_BUCKET_INCREDEF(t) (((t) == XML_SCHEMA_SCHEMA_INCLUDE) || \
214  ((t) == XML_SCHEMA_SCHEMA_REDEFINE))
215 
216 #define WXS_IS_BUCKET_IMPMAIN(t) (((t) == XML_SCHEMA_SCHEMA_MAIN) || \
217  ((t) == XML_SCHEMA_SCHEMA_IMPORT))
218 
219 #define WXS_IMPBUCKET(b) ((xmlSchemaImportPtr) (b))
220 
221 #define WXS_INCBUCKET(b) ((xmlSchemaIncludePtr) (b))
222 /*
223 * Macros for complex/simple types.
224 */
225 #define WXS_IS_ANYTYPE(i) \
226  (( (i)->type == XML_SCHEMA_TYPE_BASIC) && \
227  ( (WXS_TYPE_CAST (i))->builtInType == XML_SCHEMAS_ANYTYPE))
228 
229 #define WXS_IS_COMPLEX(i) \
230  (((i)->type == XML_SCHEMA_TYPE_COMPLEX) || \
231  ((i)->builtInType == XML_SCHEMAS_ANYTYPE))
232 
233 #define WXS_IS_SIMPLE(item) \
234  ((item->type == XML_SCHEMA_TYPE_SIMPLE) || \
235  ((item->type == XML_SCHEMA_TYPE_BASIC) && \
236  (item->builtInType != XML_SCHEMAS_ANYTYPE)))
237 
238 #define WXS_IS_ANY_SIMPLE_TYPE(i) \
239  (((i)->type == XML_SCHEMA_TYPE_BASIC) && \
240  ((i)->builtInType == XML_SCHEMAS_ANYSIMPLETYPE))
241 
242 #define WXS_IS_RESTRICTION(t) \
243  ((t)->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION)
244 
245 #define WXS_IS_EXTENSION(t) \
246  ((t)->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION)
247 
248 #define WXS_IS_TYPE_NOT_FIXED(i) \
249  (((i)->type != XML_SCHEMA_TYPE_BASIC) && \
250  (((i)->flags & XML_SCHEMAS_TYPE_INTERNAL_RESOLVED) == 0))
251 
252 #define WXS_IS_TYPE_NOT_FIXED_1(item) \
253  (((item)->type != XML_SCHEMA_TYPE_BASIC) && \
254  (((item)->flags & XML_SCHEMAS_TYPE_FIXUP_1) == 0))
255 
256 #define WXS_TYPE_IS_GLOBAL(t) ((t)->flags & XML_SCHEMAS_TYPE_GLOBAL)
257 
258 #define WXS_TYPE_IS_LOCAL(t) (((t)->flags & XML_SCHEMAS_TYPE_GLOBAL) == 0)
259 /*
260 * Macros for exclusively for complex types.
261 */
262 #define WXS_HAS_COMPLEX_CONTENT(item) \
263  ((item->contentType == XML_SCHEMA_CONTENT_MIXED) || \
264  (item->contentType == XML_SCHEMA_CONTENT_EMPTY) || \
265  (item->contentType == XML_SCHEMA_CONTENT_ELEMENTS))
266 
267 #define WXS_HAS_SIMPLE_CONTENT(item) \
268  ((item->contentType == XML_SCHEMA_CONTENT_SIMPLE) || \
269  (item->contentType == XML_SCHEMA_CONTENT_BASIC))
270 
271 #define WXS_HAS_MIXED_CONTENT(item) \
272  (item->contentType == XML_SCHEMA_CONTENT_MIXED)
273 
274 #define WXS_EMPTIABLE(t) \
275  (xmlSchemaIsParticleEmptiable(WXS_PTC_CAST (t)->subtypes))
276 
277 #define WXS_TYPE_CONTENTTYPE(t) (t)->subtypes
278 
279 #define WXS_TYPE_PARTICLE(t) WXS_PTC_CAST (t)->subtypes
280 
281 #define WXS_TYPE_PARTICLE_TERM(t) WXS_PARTICLE_TERM(WXS_TYPE_PARTICLE(t))
282 /*
283 * Macros for exclusively for simple types.
284 */
285 #define WXS_LIST_ITEMTYPE(t) (t)->subtypes
286 
287 #define WXS_IS_ATOMIC(t) (t->flags & XML_SCHEMAS_TYPE_VARIETY_ATOMIC)
288 
289 #define WXS_IS_LIST(t) (t->flags & XML_SCHEMAS_TYPE_VARIETY_LIST)
290 
291 #define WXS_IS_UNION(t) (t->flags & XML_SCHEMAS_TYPE_VARIETY_UNION)
292 /*
293 * Misc parser context macros.
294 */
295 #define WXS_CONSTRUCTOR(ctx) (ctx)->constructor
296 
297 #define WXS_HAS_BUCKETS(ctx) \
298 ( (WXS_CONSTRUCTOR((ctx))->buckets != NULL) && \
299 (WXS_CONSTRUCTOR((ctx))->buckets->nbItems > 0) )
300 
301 #define WXS_SUBST_GROUPS(ctx) WXS_CONSTRUCTOR((ctx))->substGroups
302 
303 #define WXS_BUCKET(ctx) WXS_CONSTRUCTOR((ctx))->bucket
304 
305 #define WXS_SCHEMA(ctx) (ctx)->schema
306 
307 #define WXS_ADD_LOCAL(ctx, item) \
308  xmlSchemaAddItemSize(&(WXS_BUCKET(ctx)->locals), 10, item)
309 
310 #define WXS_ADD_GLOBAL(ctx, item) \
311  xmlSchemaAddItemSize(&(WXS_BUCKET(ctx)->globals), 5, item)
312 
313 #define WXS_ADD_PENDING(ctx, item) \
314  xmlSchemaAddItemSize(&((ctx)->constructor->pending), 10, item)
315 /*
316 * xmlSchemaItemList macros.
317 */
318 #define WXS_ILIST_IS_EMPTY(l) ((l == NULL) || ((l)->nbItems == 0))
319 /*
320 * Misc macros.
321 */
322 #define IS_SCHEMA(node, type) \
323  ((node != NULL) && (node->ns != NULL) && \
324  (xmlStrEqual(node->name, (const xmlChar *) type)) && \
325  (xmlStrEqual(node->ns->href, xmlSchemaNs)))
326 
327 #define FREE_AND_NULL(str) if ((str) != NULL) { xmlFree((xmlChar *) (str)); str = NULL; }
328 
329 /*
330 * Since we put the default/fixed values into the dict, we can
331 * use pointer comparison for those values.
332 * REMOVED: (xmlStrEqual((v1), (v2)))
333 */
334 #define WXS_ARE_DEFAULT_STR_EQUAL(v1, v2) ((v1) == (v2))
335 
336 #define INODE_NILLED(item) (item->flags & XML_SCHEMA_ELEM_INFO_NILLED)
337 
338 #define CAN_PARSE_SCHEMA(b) (((b)->doc != NULL) && ((b)->parsed == 0))
339 
340 #define HFAILURE if (res == -1) goto exit_failure;
341 
342 #define HERROR if (res != 0) goto exit_error;
343 
344 #define HSTOP(ctx) if ((ctx)->stop) goto exit;
345 /*
346 * Some flags used for various schema constraints.
347 */
348 #define SUBSET_RESTRICTION 1<<0
349 #define SUBSET_EXTENSION 1<<1
350 #define SUBSET_SUBSTITUTION 1<<2
351 #define SUBSET_LIST 1<<3
352 #define SUBSET_UNION 1<<4
353 
354 typedef struct _xmlSchemaNodeInfo xmlSchemaNodeInfo;
355 typedef xmlSchemaNodeInfo *xmlSchemaNodeInfoPtr;
356 
357 typedef struct _xmlSchemaItemList xmlSchemaItemList;
358 typedef xmlSchemaItemList *xmlSchemaItemListPtr;
359 struct _xmlSchemaItemList {
360  void **items; /* used for dynamic addition of schemata */
361  int nbItems; /* used for dynamic addition of schemata */
362  int sizeItems; /* used for dynamic addition of schemata */
363 };
364 
365 #define XML_SCHEMA_CTXT_PARSER 1
366 #define XML_SCHEMA_CTXT_VALIDATOR 2
367 
368 typedef struct _xmlSchemaAbstractCtxt xmlSchemaAbstractCtxt;
369 typedef xmlSchemaAbstractCtxt *xmlSchemaAbstractCtxtPtr;
370 struct _xmlSchemaAbstractCtxt {
371  int type; /* E.g. XML_SCHEMA_CTXT_VALIDATOR */
372  void *dummy; /* Fix alignment issues */
373 };
374 
375 typedef struct _xmlSchemaBucket xmlSchemaBucket;
376 typedef xmlSchemaBucket *xmlSchemaBucketPtr;
377 
378 #define XML_SCHEMA_SCHEMA_MAIN 0
379 #define XML_SCHEMA_SCHEMA_IMPORT 1
380 #define XML_SCHEMA_SCHEMA_INCLUDE 2
381 #define XML_SCHEMA_SCHEMA_REDEFINE 3
382 
388 typedef struct _xmlSchemaSchemaRelation xmlSchemaSchemaRelation;
389 typedef xmlSchemaSchemaRelation *xmlSchemaSchemaRelationPtr;
390 struct _xmlSchemaSchemaRelation {
391  xmlSchemaSchemaRelationPtr next;
392  int type; /* E.g. XML_SCHEMA_SCHEMA_IMPORT */
393  const xmlChar *importNamespace;
394  xmlSchemaBucketPtr bucket;
395 };
396 
397 #define XML_SCHEMA_BUCKET_MARKED 1<<0
398 #define XML_SCHEMA_BUCKET_COMPS_ADDED 1<<1
399 
400 struct _xmlSchemaBucket {
401  int type;
402  int flags;
403  const xmlChar *schemaLocation;
404  const xmlChar *origTargetNamespace;
405  const xmlChar *targetNamespace;
406  xmlDocPtr doc;
407  xmlSchemaSchemaRelationPtr relations;
408  int located;
409  int parsed;
410  int imported;
411  int preserveDoc;
412  xmlSchemaItemListPtr globals; /* Global components. */
413  xmlSchemaItemListPtr locals; /* Local components. */
414 };
415 
424 typedef struct _xmlSchemaImport xmlSchemaImport;
425 typedef xmlSchemaImport *xmlSchemaImportPtr;
426 struct _xmlSchemaImport {
427  int type; /* Main OR import OR include. */
428  int flags;
429  const xmlChar *schemaLocation; /* The URI of the schema document. */
430  /* For chameleon includes, @origTargetNamespace will be NULL */
431  const xmlChar *origTargetNamespace;
432  /*
433  * For chameleon includes, @targetNamespace will be the
434  * targetNamespace of the including schema.
435  */
436  const xmlChar *targetNamespace;
437  xmlDocPtr doc; /* The schema node-tree. */
438  /* @relations will hold any included/imported/redefined schemas. */
439  xmlSchemaSchemaRelationPtr relations;
440  int located;
441  int parsed;
442  int imported;
443  int preserveDoc;
444  xmlSchemaItemListPtr globals;
445  xmlSchemaItemListPtr locals;
446  /* The imported schema. */
447  xmlSchemaPtr schema;
448 };
449 
450 /*
451 * (extends xmlSchemaBucket)
452 */
453 typedef struct _xmlSchemaInclude xmlSchemaInclude;
454 typedef xmlSchemaInclude *xmlSchemaIncludePtr;
455 struct _xmlSchemaInclude {
456  int type;
457  int flags;
458  const xmlChar *schemaLocation;
459  const xmlChar *origTargetNamespace;
460  const xmlChar *targetNamespace;
461  xmlDocPtr doc;
462  xmlSchemaSchemaRelationPtr relations;
463  int located;
464  int parsed;
465  int imported;
466  int preserveDoc;
467  xmlSchemaItemListPtr globals; /* Global components. */
468  xmlSchemaItemListPtr locals; /* Local components. */
469 
470  /* The owning main or import schema bucket. */
471  xmlSchemaImportPtr ownerImport;
472 };
473 
479 typedef struct _xmlSchemaBasicItem xmlSchemaBasicItem;
480 typedef xmlSchemaBasicItem *xmlSchemaBasicItemPtr;
481 struct _xmlSchemaBasicItem {
482  xmlSchemaTypeType type;
483  void *dummy; /* Fix alignment issues */
484 };
485 
492 typedef struct _xmlSchemaAnnotItem xmlSchemaAnnotItem;
493 typedef xmlSchemaAnnotItem *xmlSchemaAnnotItemPtr;
494 struct _xmlSchemaAnnotItem {
495  xmlSchemaTypeType type;
496  xmlSchemaAnnotPtr annot;
497 };
498 
505 typedef struct _xmlSchemaTreeItem xmlSchemaTreeItem;
506 typedef xmlSchemaTreeItem *xmlSchemaTreeItemPtr;
507 struct _xmlSchemaTreeItem {
508  xmlSchemaTypeType type;
509  xmlSchemaAnnotPtr annot;
510  xmlSchemaTreeItemPtr next;
511  xmlSchemaTreeItemPtr children;
512 };
513 
514 
515 #define XML_SCHEMA_ATTR_USE_FIXED 1<<0
516 
522 typedef struct _xmlSchemaAttributeUse xmlSchemaAttributeUse;
523 typedef xmlSchemaAttributeUse *xmlSchemaAttributeUsePtr;
524 struct _xmlSchemaAttributeUse {
525  xmlSchemaTypeType type;
526  xmlSchemaAnnotPtr annot;
527  xmlSchemaAttributeUsePtr next; /* The next attr. use. */
528  /*
529  * The attr. decl. OR a QName-ref. to an attr. decl. OR
530  * a QName-ref. to an attribute group definition.
531  */
532  xmlSchemaAttributePtr attrDecl;
533 
534  int flags;
536  int occurs; /* required, optional */
537  const xmlChar * defValue;
538  xmlSchemaValPtr defVal;
539 };
540 
547 typedef struct _xmlSchemaAttributeUseProhib xmlSchemaAttributeUseProhib;
548 typedef xmlSchemaAttributeUseProhib *xmlSchemaAttributeUseProhibPtr;
549 struct _xmlSchemaAttributeUseProhib {
550  xmlSchemaTypeType type; /* == XML_SCHEMA_EXTRA_ATTR_USE_PROHIB */
552  const xmlChar *name;
553  const xmlChar *targetNamespace;
554  int isRef;
555 };
556 
560 typedef struct _xmlSchemaRedef xmlSchemaRedef;
561 typedef xmlSchemaRedef *xmlSchemaRedefPtr;
562 struct _xmlSchemaRedef {
563  xmlSchemaRedefPtr next;
564  xmlSchemaBasicItemPtr item; /* The redefining component. */
565  xmlSchemaBasicItemPtr reference; /* The referencing component. */
566  xmlSchemaBasicItemPtr target; /* The to-be-redefined component. */
567  const xmlChar *refName; /* The name of the to-be-redefined component. */
568  const xmlChar *refTargetNs; /* The target namespace of the
569  to-be-redefined comp. */
570  xmlSchemaBucketPtr targetBucket; /* The redefined schema. */
571 };
572 
576 typedef struct _xmlSchemaConstructionCtxt xmlSchemaConstructionCtxt;
577 typedef xmlSchemaConstructionCtxt *xmlSchemaConstructionCtxtPtr;
578 struct _xmlSchemaConstructionCtxt {
579  xmlSchemaPtr mainSchema; /* The main schema. */
580  xmlSchemaBucketPtr mainBucket; /* The main schema bucket */
581  xmlDictPtr dict;
582  xmlSchemaItemListPtr buckets; /* List of schema buckets. */
583  /* xmlSchemaItemListPtr relations; */ /* List of schema relations. */
584  xmlSchemaBucketPtr bucket; /* The current schema bucket */
585  xmlSchemaItemListPtr pending; /* All Components of all schemas that
586  need to be fixed. */
587  xmlHashTablePtr substGroups;
588  xmlSchemaRedefPtr redefs;
589  xmlSchemaRedefPtr lastRedef;
590 };
591 
592 #define XML_SCHEMAS_PARSE_ERROR 1
593 #define SCHEMAS_PARSE_OPTIONS XML_PARSE_NOENT
594 
595 struct _xmlSchemaParserCtxt {
596  int type;
597  void *errCtxt; /* user specific error context */
598  xmlSchemaValidityErrorFunc error; /* the callback in case of errors */
599  xmlSchemaValidityWarningFunc warning; /* the callback in case of warning */
600  int err;
601  int nberrors;
602  xmlStructuredErrorFunc serror;
603 
604  xmlSchemaConstructionCtxtPtr constructor;
605  int ownsConstructor; /* TODO: Move this to parser *flags*. */
606 
607  /* xmlSchemaPtr topschema; */
608  /* xmlHashTablePtr namespaces; */
609 
610  xmlSchemaPtr schema; /* The main schema in use */
611  int counter;
612 
613  const xmlChar *URL;
614  xmlDocPtr doc;
615  int preserve; /* Whether the doc should be freed */
616 
617  const char *buffer;
618  int size;
619 
620  /*
621  * Used to build complex element content models
622  */
623  xmlAutomataPtr am;
624  xmlAutomataStatePtr start;
625  xmlAutomataStatePtr end;
626  xmlAutomataStatePtr state;
627 
628  xmlDictPtr dict; /* dictionary for interned string names */
629  xmlSchemaTypePtr ctxtType; /* The current context simple/complex type */
630  int options;
631  xmlSchemaValidCtxtPtr vctxt;
632  int isS4S;
633  int isRedefine;
634  int xsiAssemble;
635  int stop; /* If the parser should stop; i.e. a critical error. */
636  const xmlChar *targetNamespace;
637  xmlSchemaBucketPtr redefined; /* The schema to be redefined. */
638 
639  xmlSchemaRedefPtr redef; /* Used for redefinitions. */
640  int redefCounter; /* Used for redefinitions. */
641  xmlSchemaItemListPtr attrProhibs;
642 };
643 
650 typedef struct _xmlSchemaQNameRef xmlSchemaQNameRef;
651 typedef xmlSchemaQNameRef *xmlSchemaQNameRefPtr;
652 struct _xmlSchemaQNameRef {
653  xmlSchemaTypeType type;
654  xmlSchemaBasicItemPtr item; /* The resolved referenced item. */
655  xmlSchemaTypeType itemType;
656  const xmlChar *name;
657  const xmlChar *targetNamespace;
659 };
660 
667 typedef struct _xmlSchemaParticle xmlSchemaParticle;
668 typedef xmlSchemaParticle *xmlSchemaParticlePtr;
669 struct _xmlSchemaParticle {
670  xmlSchemaTypeType type;
671  xmlSchemaAnnotPtr annot;
672  xmlSchemaTreeItemPtr next; /* next particle */
673  xmlSchemaTreeItemPtr children; /* the "term" (e.g. a model group,
674  a group definition, a XML_SCHEMA_EXTRA_QNAMEREF (if a reference),
675  etc.) */
676  int minOccurs;
677  int maxOccurs;
679 };
680 
687 typedef struct _xmlSchemaModelGroup xmlSchemaModelGroup;
688 typedef xmlSchemaModelGroup *xmlSchemaModelGroupPtr;
689 struct _xmlSchemaModelGroup {
690  xmlSchemaTypeType type; /* XML_SCHEMA_TYPE_SEQUENCE, XML_SCHEMA_TYPE_CHOICE, XML_SCHEMA_TYPE_ALL */
691  xmlSchemaAnnotPtr annot;
692  xmlSchemaTreeItemPtr next; /* not used */
693  xmlSchemaTreeItemPtr children; /* first particle (OR "element decl" OR "wildcard") */
695 };
696 
697 #define XML_SCHEMA_MODEL_GROUP_DEF_MARKED 1<<0
698 #define XML_SCHEMA_MODEL_GROUP_DEF_REDEFINED 1<<1
699 
705 typedef struct _xmlSchemaModelGroupDef xmlSchemaModelGroupDef;
706 typedef xmlSchemaModelGroupDef *xmlSchemaModelGroupDefPtr;
707 struct _xmlSchemaModelGroupDef {
708  xmlSchemaTypeType type; /* XML_SCHEMA_TYPE_GROUP */
709  xmlSchemaAnnotPtr annot;
710  xmlSchemaTreeItemPtr next; /* not used */
711  xmlSchemaTreeItemPtr children; /* the "model group" */
712  const xmlChar *name;
713  const xmlChar *targetNamespace;
715  int flags;
716 };
717 
718 typedef struct _xmlSchemaIDC xmlSchemaIDC;
719 typedef xmlSchemaIDC *xmlSchemaIDCPtr;
720 
727 typedef struct _xmlSchemaIDCSelect xmlSchemaIDCSelect;
728 typedef xmlSchemaIDCSelect *xmlSchemaIDCSelectPtr;
729 struct _xmlSchemaIDCSelect {
730  xmlSchemaIDCSelectPtr next;
731  xmlSchemaIDCPtr idc;
732  int index; /* an index position if significant for IDC key-sequences */
733  const xmlChar *xpath; /* the XPath expression */
734  void *xpathComp; /* the compiled XPath expression */
735 };
736 
744 struct _xmlSchemaIDC {
745  xmlSchemaTypeType type;
746  xmlSchemaAnnotPtr annot;
747  xmlSchemaIDCPtr next;
749  const xmlChar *name;
750  const xmlChar *targetNamespace;
751  xmlSchemaIDCSelectPtr selector;
752  xmlSchemaIDCSelectPtr fields;
753  int nbFields;
754  xmlSchemaQNameRefPtr ref;
755 };
756 
762 typedef struct _xmlSchemaIDCAug xmlSchemaIDCAug;
763 typedef xmlSchemaIDCAug *xmlSchemaIDCAugPtr;
764 struct _xmlSchemaIDCAug {
765  xmlSchemaIDCAugPtr next; /* next in a list */
766  xmlSchemaIDCPtr def; /* the IDC definition */
767  int keyrefDepth; /* the lowest tree level to which IDC
768  tables need to be bubbled upwards */
769 };
770 
776 typedef struct _xmlSchemaPSVIIDCKey xmlSchemaPSVIIDCKey;
777 typedef xmlSchemaPSVIIDCKey *xmlSchemaPSVIIDCKeyPtr;
778 struct _xmlSchemaPSVIIDCKey {
779  xmlSchemaTypePtr type;
780  xmlSchemaValPtr val;
781 };
782 
788 typedef struct _xmlSchemaPSVIIDCNode xmlSchemaPSVIIDCNode;
789 typedef xmlSchemaPSVIIDCNode *xmlSchemaPSVIIDCNodePtr;
790 struct _xmlSchemaPSVIIDCNode {
792  xmlSchemaPSVIIDCKeyPtr *keys;
793  int nodeLine;
794  int nodeQNameID;
795 
796 };
797 
803 typedef struct _xmlSchemaPSVIIDCBinding xmlSchemaPSVIIDCBinding;
804 typedef xmlSchemaPSVIIDCBinding *xmlSchemaPSVIIDCBindingPtr;
805 struct _xmlSchemaPSVIIDCBinding {
806  xmlSchemaPSVIIDCBindingPtr next; /* next binding of a specific node */
807  xmlSchemaIDCPtr definition; /* the IDC definition */
808  xmlSchemaPSVIIDCNodePtr *nodeTable; /* array of key-sequences */
809  int nbNodes; /* number of entries in the node table */
810  int sizeNodes; /* size of the node table */
811  xmlSchemaItemListPtr dupls;
812 };
813 
814 
815 #define XPATH_STATE_OBJ_TYPE_IDC_SELECTOR 1
816 #define XPATH_STATE_OBJ_TYPE_IDC_FIELD 2
817 
818 #define XPATH_STATE_OBJ_MATCHES -2
819 #define XPATH_STATE_OBJ_BLOCKED -3
820 
821 typedef struct _xmlSchemaIDCMatcher xmlSchemaIDCMatcher;
822 typedef xmlSchemaIDCMatcher *xmlSchemaIDCMatcherPtr;
823 
829 typedef struct _xmlSchemaIDCStateObj xmlSchemaIDCStateObj;
830 typedef xmlSchemaIDCStateObj *xmlSchemaIDCStateObjPtr;
831 struct _xmlSchemaIDCStateObj {
832  int type;
833  xmlSchemaIDCStateObjPtr next; /* next if in a list */
834  int depth; /* depth of creation */
835  int *history; /* list of (depth, state-id) tuples */
836  int nbHistory;
837  int sizeHistory;
838  xmlSchemaIDCMatcherPtr matcher; /* the correspondent field/selector
839  matcher */
840  xmlSchemaIDCSelectPtr sel;
841  void *xpathCtxt;
842 };
843 
844 #define IDC_MATCHER 0
845 
851 struct _xmlSchemaIDCMatcher {
852  int type;
853  int depth; /* the tree depth at creation time */
854  xmlSchemaIDCMatcherPtr next; /* next in the list */
855  xmlSchemaIDCMatcherPtr nextCached; /* next in the cache list */
856  xmlSchemaIDCAugPtr aidc; /* the augmented IDC item */
857  int idcType;
858  xmlSchemaPSVIIDCKeyPtr **keySeqs; /* the key-sequences of the target
859  elements */
860  int sizeKeySeqs;
861  xmlSchemaItemListPtr targets; /* list of target-node
862  (xmlSchemaPSVIIDCNodePtr) entries */
863  xmlHashTablePtr htab;
864 };
865 
866 /*
867 * Element info flags.
868 */
869 #define XML_SCHEMA_NODE_INFO_FLAG_OWNED_NAMES 1<<0
870 #define XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES 1<<1
871 #define XML_SCHEMA_ELEM_INFO_NILLED 1<<2
872 #define XML_SCHEMA_ELEM_INFO_LOCAL_TYPE 1<<3
873 
874 #define XML_SCHEMA_NODE_INFO_VALUE_NEEDED 1<<4
875 #define XML_SCHEMA_ELEM_INFO_EMPTY 1<<5
876 #define XML_SCHEMA_ELEM_INFO_HAS_CONTENT 1<<6
877 
878 #define XML_SCHEMA_ELEM_INFO_HAS_ELEM_CONTENT 1<<7
879 #define XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT 1<<8
880 #define XML_SCHEMA_NODE_INFO_ERR_NOT_EXPECTED 1<<9
881 #define XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE 1<<10
882 
888 struct _xmlSchemaNodeInfo {
889  int nodeType;
891  int nodeLine;
892  const xmlChar *localName;
893  const xmlChar *nsName;
894  const xmlChar *value;
895  xmlSchemaValPtr val; /* the pre-computed value if any */
896  xmlSchemaTypePtr typeDef; /* the complex/simple type definition if any */
897 
898  int flags; /* combination of node info flags */
899 
900  int valNeeded;
901  int normVal;
902 
903  xmlSchemaElementPtr decl; /* the element/attribute declaration */
904  int depth;
905  xmlSchemaPSVIIDCBindingPtr idcTable; /* the table of PSVI IDC bindings
906  for the scope element*/
907  xmlSchemaIDCMatcherPtr idcMatchers; /* the IDC matchers for the scope
908  element */
909  xmlRegExecCtxtPtr regexCtxt;
910 
911  const xmlChar **nsBindings; /* Namespace bindings on this element */
912  int nbNsBindings;
913  int sizeNsBindings;
914 
915  int hasKeyrefs;
916  int appliedXPath; /* Indicates that an XPath has been applied. */
917 };
918 
919 #define XML_SCHEMAS_ATTR_UNKNOWN 1
920 #define XML_SCHEMAS_ATTR_ASSESSED 2
921 #define XML_SCHEMAS_ATTR_PROHIBITED 3
922 #define XML_SCHEMAS_ATTR_ERR_MISSING 4
923 #define XML_SCHEMAS_ATTR_INVALID_VALUE 5
924 #define XML_SCHEMAS_ATTR_ERR_NO_TYPE 6
925 #define XML_SCHEMAS_ATTR_ERR_FIXED_VALUE 7
926 #define XML_SCHEMAS_ATTR_DEFAULT 8
927 #define XML_SCHEMAS_ATTR_VALIDATE_VALUE 9
928 #define XML_SCHEMAS_ATTR_ERR_WILD_STRICT_NO_DECL 10
929 #define XML_SCHEMAS_ATTR_HAS_ATTR_USE 11
930 #define XML_SCHEMAS_ATTR_HAS_ATTR_DECL 12
931 #define XML_SCHEMAS_ATTR_WILD_SKIP 13
932 #define XML_SCHEMAS_ATTR_WILD_LAX_NO_DECL 14
933 #define XML_SCHEMAS_ATTR_ERR_WILD_DUPLICATE_ID 15
934 #define XML_SCHEMAS_ATTR_ERR_WILD_AND_USE_ID 16
935 #define XML_SCHEMAS_ATTR_META 17
936 /*
937 * @metaType values of xmlSchemaAttrInfo.
938 */
939 #define XML_SCHEMA_ATTR_INFO_META_XSI_TYPE 1
940 #define XML_SCHEMA_ATTR_INFO_META_XSI_NIL 2
941 #define XML_SCHEMA_ATTR_INFO_META_XSI_SCHEMA_LOC 3
942 #define XML_SCHEMA_ATTR_INFO_META_XSI_NO_NS_SCHEMA_LOC 4
943 #define XML_SCHEMA_ATTR_INFO_META_XMLNS 5
944 
945 typedef struct _xmlSchemaAttrInfo xmlSchemaAttrInfo;
946 typedef xmlSchemaAttrInfo *xmlSchemaAttrInfoPtr;
947 struct _xmlSchemaAttrInfo {
948  int nodeType;
950  int nodeLine;
951  const xmlChar *localName;
952  const xmlChar *nsName;
953  const xmlChar *value;
954  xmlSchemaValPtr val; /* the pre-computed value if any */
955  xmlSchemaTypePtr typeDef; /* the complex/simple type definition if any */
956  int flags; /* combination of node info flags */
957 
958  xmlSchemaAttributePtr decl; /* the attribute declaration */
959  xmlSchemaAttributeUsePtr use; /* the attribute use */
960  int state;
961  int metaType;
962  const xmlChar *vcValue; /* the value constraint value */
963  xmlSchemaNodeInfoPtr parent;
964 };
965 
966 
967 #define XML_SCHEMA_VALID_CTXT_FLAG_STREAM 1
968 
973 struct _xmlSchemaValidCtxt {
974  int type;
975  void *errCtxt; /* user specific data block */
976  xmlSchemaValidityErrorFunc error; /* the callback in case of errors */
977  xmlSchemaValidityWarningFunc warning; /* the callback in case of warning */
978  xmlStructuredErrorFunc serror;
979 
980  xmlSchemaPtr schema; /* The schema in use */
981  xmlDocPtr doc;
983  xmlCharEncoding enc;
985  xmlParserCtxtPtr parserCtxt;
986  void *user_data; /* TODO: What is this for? */
987  char *filename;
988 
989  int err;
990  int nberrors;
991 
993  xmlNodePtr cur;
994  /* xmlSchemaTypePtr type; */
995 
996  xmlRegExecCtxtPtr regexp;
997  xmlSchemaValPtr value;
998 
999  int valueWS;
1000  int options;
1001  xmlNodePtr validationRoot;
1002  xmlSchemaParserCtxtPtr pctxt;
1003  int xsiAssemble;
1004 
1005  int depth;
1006  xmlSchemaNodeInfoPtr *elemInfos; /* array of element information */
1007  int sizeElemInfos;
1008  xmlSchemaNodeInfoPtr inode; /* the current element information */
1009 
1010  xmlSchemaIDCAugPtr aidcs; /* a list of augmented IDC information */
1011 
1012  xmlSchemaIDCStateObjPtr xpathStates; /* first active state object. */
1013  xmlSchemaIDCStateObjPtr xpathStatePool; /* first stored state object. */
1014  xmlSchemaIDCMatcherPtr idcMatcherCache; /* Cache for IDC matcher objects. */
1015 
1016  xmlSchemaPSVIIDCNodePtr *idcNodes; /* list of all IDC node-table entries*/
1017  int nbIdcNodes;
1018  int sizeIdcNodes;
1019 
1020  xmlSchemaPSVIIDCKeyPtr *idcKeys; /* list of all IDC node-table entries */
1021  int nbIdcKeys;
1022  int sizeIdcKeys;
1023 
1024  int flags;
1025 
1026  xmlDictPtr dict;
1027 
1028 #ifdef LIBXML_READER_ENABLED
1029  xmlTextReaderPtr reader;
1030 #endif
1031 
1032  xmlSchemaAttrInfoPtr *attrInfos;
1033  int nbAttrInfos;
1034  int sizeAttrInfos;
1035 
1036  int skipDepth;
1037  xmlSchemaItemListPtr nodeQNames;
1038  int hasKeyrefs;
1039  int createIDCNodeTables;
1040  int psviExposeIDCNodeTables;
1041 
1042  /* Locator for error reporting in streaming mode */
1043  xmlSchemaValidityLocatorFunc locFunc;
1044  void *locCtxt;
1045 };
1046 
1052 typedef struct _xmlSchemaSubstGroup xmlSchemaSubstGroup;
1053 typedef xmlSchemaSubstGroup *xmlSchemaSubstGroupPtr;
1054 struct _xmlSchemaSubstGroup {
1055  xmlSchemaElementPtr head;
1056  xmlSchemaItemListPtr members;
1057 };
1058 
1064 typedef struct _xmlIDCHashEntry xmlIDCHashEntry;
1065 typedef xmlIDCHashEntry *xmlIDCHashEntryPtr;
1066 struct _xmlIDCHashEntry {
1067  xmlIDCHashEntryPtr next; /* next item with same hash */
1068  int index; /* index into associated item list */
1069 };
1070 
1071 /************************************************************************
1072  * *
1073  * Some predeclarations *
1074  * *
1075  ************************************************************************/
1076 
1077 static int xmlSchemaParseInclude(xmlSchemaParserCtxtPtr ctxt,
1078  xmlSchemaPtr schema,
1079  xmlNodePtr node);
1080 static int xmlSchemaParseRedefine(xmlSchemaParserCtxtPtr ctxt,
1081  xmlSchemaPtr schema,
1082  xmlNodePtr node);
1083 static int
1084 xmlSchemaTypeFixup(xmlSchemaTypePtr type,
1085  xmlSchemaAbstractCtxtPtr ctxt);
1086 static const xmlChar *
1087 xmlSchemaFacetTypeToString(xmlSchemaTypeType type);
1088 static int
1089 xmlSchemaParseImport(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
1090  xmlNodePtr node);
1091 static int
1092 xmlSchemaCheckFacetValues(xmlSchemaTypePtr typeDecl,
1093  xmlSchemaParserCtxtPtr ctxt);
1094 static void
1095 xmlSchemaClearValidCtxt(xmlSchemaValidCtxtPtr vctxt);
1096 static xmlSchemaWhitespaceValueType
1097 xmlSchemaGetWhiteSpaceFacetValue(xmlSchemaTypePtr type);
1098 static xmlSchemaTreeItemPtr
1099 xmlSchemaParseModelGroup(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
1100  xmlNodePtr node, xmlSchemaTypeType type,
1101  int withParticle);
1102 static const xmlChar *
1103 xmlSchemaGetComponentTypeStr(xmlSchemaBasicItemPtr item);
1104 static xmlSchemaTypeLinkPtr
1105 xmlSchemaGetUnionSimpleTypeMemberTypes(xmlSchemaTypePtr type);
1106 static void
1107 xmlSchemaInternalErr(xmlSchemaAbstractCtxtPtr actxt,
1108  const char *funcName,
1109  const char *message) LIBXML_ATTR_FORMAT(3,0);
1110 static int
1111 xmlSchemaCheckCOSSTDerivedOK(xmlSchemaAbstractCtxtPtr ctxt,
1112  xmlSchemaTypePtr type,
1113  xmlSchemaTypePtr baseType,
1114  int subset);
1115 static void
1116 xmlSchemaCheckElementDeclComponent(xmlSchemaElementPtr elemDecl,
1117  xmlSchemaParserCtxtPtr ctxt);
1118 static void
1119 xmlSchemaComponentListFree(xmlSchemaItemListPtr list);
1120 static xmlSchemaQNameRefPtr
1121 xmlSchemaParseAttributeGroupRef(xmlSchemaParserCtxtPtr pctxt,
1122  xmlSchemaPtr schema,
1123  xmlNodePtr node);
1124 
1125 /************************************************************************
1126  * *
1127  * Helper functions *
1128  * *
1129  ************************************************************************/
1130 
1137 static const xmlChar *
1138 xmlSchemaItemTypeToStr(xmlSchemaTypeType type)
1139 {
1140  switch (type) {
1141  case XML_SCHEMA_TYPE_BASIC:
1142  return(BAD_CAST "simple type definition");
1143  case XML_SCHEMA_TYPE_SIMPLE:
1144  return(BAD_CAST "simple type definition");
1145  case XML_SCHEMA_TYPE_COMPLEX:
1146  return(BAD_CAST "complex type definition");
1147  case XML_SCHEMA_TYPE_ELEMENT:
1148  return(BAD_CAST "element declaration");
1149  case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
1150  return(BAD_CAST "attribute use");
1151  case XML_SCHEMA_TYPE_ATTRIBUTE:
1152  return(BAD_CAST "attribute declaration");
1153  case XML_SCHEMA_TYPE_GROUP:
1154  return(BAD_CAST "model group definition");
1155  case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1156  return(BAD_CAST "attribute group definition");
1157  case XML_SCHEMA_TYPE_NOTATION:
1158  return(BAD_CAST "notation declaration");
1159  case XML_SCHEMA_TYPE_SEQUENCE:
1160  return(BAD_CAST "model group (sequence)");
1161  case XML_SCHEMA_TYPE_CHOICE:
1162  return(BAD_CAST "model group (choice)");
1163  case XML_SCHEMA_TYPE_ALL:
1164  return(BAD_CAST "model group (all)");
1165  case XML_SCHEMA_TYPE_PARTICLE:
1166  return(BAD_CAST "particle");
1167  case XML_SCHEMA_TYPE_IDC_UNIQUE:
1168  return(BAD_CAST "unique identity-constraint");
1169  /* return(BAD_CAST "IDC (unique)"); */
1170  case XML_SCHEMA_TYPE_IDC_KEY:
1171  return(BAD_CAST "key identity-constraint");
1172  /* return(BAD_CAST "IDC (key)"); */
1173  case XML_SCHEMA_TYPE_IDC_KEYREF:
1174  return(BAD_CAST "keyref identity-constraint");
1175  /* return(BAD_CAST "IDC (keyref)"); */
1176  case XML_SCHEMA_TYPE_ANY:
1177  return(BAD_CAST "wildcard (any)");
1178  case XML_SCHEMA_EXTRA_QNAMEREF:
1179  return(BAD_CAST "[helper component] QName reference");
1180  case XML_SCHEMA_EXTRA_ATTR_USE_PROHIB:
1181  return(BAD_CAST "[helper component] attribute use prohibition");
1182  default:
1183  return(BAD_CAST "Not a schema component");
1184  }
1185 }
1186 
1193 static const xmlChar *
1194 xmlSchemaGetComponentTypeStr(xmlSchemaBasicItemPtr item)
1195 {
1196  switch (item->type) {
1197  case XML_SCHEMA_TYPE_BASIC:
1198  if (WXS_IS_COMPLEX(WXS_TYPE_CAST item))
1199  return(BAD_CAST "complex type definition");
1200  else
1201  return(BAD_CAST "simple type definition");
1202  default:
1203  return(xmlSchemaItemTypeToStr(item->type));
1204  }
1205 }
1206 
1217 static xmlNodePtr
1218 xmlSchemaGetComponentNode(xmlSchemaBasicItemPtr item)
1219 {
1220  switch (item->type) {
1221  case XML_SCHEMA_TYPE_ELEMENT:
1222  return (((xmlSchemaElementPtr) item)->node);
1223  case XML_SCHEMA_TYPE_ATTRIBUTE:
1224  return (((xmlSchemaAttributePtr) item)->node);
1225  case XML_SCHEMA_TYPE_COMPLEX:
1226  case XML_SCHEMA_TYPE_SIMPLE:
1227  return (((xmlSchemaTypePtr) item)->node);
1228  case XML_SCHEMA_TYPE_ANY:
1229  case XML_SCHEMA_TYPE_ANY_ATTRIBUTE:
1230  return (((xmlSchemaWildcardPtr) item)->node);
1231  case XML_SCHEMA_TYPE_PARTICLE:
1232  return (((xmlSchemaParticlePtr) item)->node);
1233  case XML_SCHEMA_TYPE_SEQUENCE:
1234  case XML_SCHEMA_TYPE_CHOICE:
1235  case XML_SCHEMA_TYPE_ALL:
1236  return (((xmlSchemaModelGroupPtr) item)->node);
1237  case XML_SCHEMA_TYPE_GROUP:
1238  return (((xmlSchemaModelGroupDefPtr) item)->node);
1239  case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1240  return (((xmlSchemaAttributeGroupPtr) item)->node);
1241  case XML_SCHEMA_TYPE_IDC_UNIQUE:
1242  case XML_SCHEMA_TYPE_IDC_KEY:
1243  case XML_SCHEMA_TYPE_IDC_KEYREF:
1244  return (((xmlSchemaIDCPtr) item)->node);
1245  case XML_SCHEMA_EXTRA_QNAMEREF:
1246  return(((xmlSchemaQNameRefPtr) item)->node);
1247  /* TODO: What to do with NOTATIONs?
1248  case XML_SCHEMA_TYPE_NOTATION:
1249  return (((xmlSchemaNotationPtr) item)->node);
1250  */
1251  case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
1252  return (((xmlSchemaAttributeUsePtr) item)->node);
1253  default:
1254  return (NULL);
1255  }
1256 }
1257 
1258 #if 0
1259 
1265 static xmlSchemaBasicItemPtr
1266 xmlSchemaGetNextComponent(xmlSchemaBasicItemPtr item)
1267 {
1268  switch (item->type) {
1269  case XML_SCHEMA_TYPE_ELEMENT:
1270  return ((xmlSchemaBasicItemPtr) ((xmlSchemaElementPtr) item)->next);
1271  case XML_SCHEMA_TYPE_ATTRIBUTE:
1272  return ((xmlSchemaBasicItemPtr) ((xmlSchemaAttributePtr) item)->next);
1273  case XML_SCHEMA_TYPE_COMPLEX:
1274  case XML_SCHEMA_TYPE_SIMPLE:
1275  return ((xmlSchemaBasicItemPtr) ((xmlSchemaTypePtr) item)->next);
1276  case XML_SCHEMA_TYPE_ANY:
1277  case XML_SCHEMA_TYPE_ANY_ATTRIBUTE:
1278  return (NULL);
1279  case XML_SCHEMA_TYPE_PARTICLE:
1280  return ((xmlSchemaBasicItemPtr) ((xmlSchemaParticlePtr) item)->next);
1281  case XML_SCHEMA_TYPE_SEQUENCE:
1282  case XML_SCHEMA_TYPE_CHOICE:
1283  case XML_SCHEMA_TYPE_ALL:
1284  return (NULL);
1285  case XML_SCHEMA_TYPE_GROUP:
1286  return (NULL);
1287  case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1288  return ((xmlSchemaBasicItemPtr) ((xmlSchemaAttributeGroupPtr) item)->next);
1289  case XML_SCHEMA_TYPE_IDC_UNIQUE:
1290  case XML_SCHEMA_TYPE_IDC_KEY:
1291  case XML_SCHEMA_TYPE_IDC_KEYREF:
1292  return ((xmlSchemaBasicItemPtr) ((xmlSchemaIDCPtr) item)->next);
1293  default:
1294  return (NULL);
1295  }
1296 }
1297 #endif
1298 
1299 
1312 static const xmlChar*
1313 xmlSchemaFormatQName(xmlChar **buf,
1314  const xmlChar *namespaceName,
1315  const xmlChar *localName)
1316 {
1317  FREE_AND_NULL(*buf)
1318  if (namespaceName != NULL) {
1319  *buf = xmlStrdup(BAD_CAST "{");
1320  *buf = xmlStrcat(*buf, namespaceName);
1321  *buf = xmlStrcat(*buf, BAD_CAST "}");
1322  }
1323  if (localName != NULL) {
1324  if (namespaceName == NULL)
1325  return(localName);
1326  *buf = xmlStrcat(*buf, localName);
1327  } else {
1328  *buf = xmlStrcat(*buf, BAD_CAST "(NULL)");
1329  }
1330  return ((const xmlChar *) *buf);
1331 }
1332 
1333 static const xmlChar*
1334 xmlSchemaFormatQNameNs(xmlChar **buf, xmlNsPtr ns, const xmlChar *localName)
1335 {
1336  if (ns != NULL)
1337  return (xmlSchemaFormatQName(buf, ns->href, localName));
1338  else
1339  return (xmlSchemaFormatQName(buf, NULL, localName));
1340 }
1341 
1342 static const xmlChar *
1343 xmlSchemaGetComponentName(xmlSchemaBasicItemPtr item)
1344 {
1345  switch (item->type) {
1346  case XML_SCHEMA_TYPE_ELEMENT:
1347  return (((xmlSchemaElementPtr) item)->name);
1348  case XML_SCHEMA_TYPE_ATTRIBUTE:
1349  return (((xmlSchemaAttributePtr) item)->name);
1350  case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1351  return (((xmlSchemaAttributeGroupPtr) item)->name);
1352  case XML_SCHEMA_TYPE_BASIC:
1353  case XML_SCHEMA_TYPE_SIMPLE:
1354  case XML_SCHEMA_TYPE_COMPLEX:
1355  return (((xmlSchemaTypePtr) item)->name);
1356  case XML_SCHEMA_TYPE_GROUP:
1357  return (((xmlSchemaModelGroupDefPtr) item)->name);
1358  case XML_SCHEMA_TYPE_IDC_KEY:
1359  case XML_SCHEMA_TYPE_IDC_UNIQUE:
1360  case XML_SCHEMA_TYPE_IDC_KEYREF:
1361  return (((xmlSchemaIDCPtr) item)->name);
1362  case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
1363  if (WXS_ATTRUSE_DECL(item) != NULL) {
1364  return(xmlSchemaGetComponentName(
1365  WXS_BASIC_CAST WXS_ATTRUSE_DECL(item)));
1366  } else
1367  return(NULL);
1368  case XML_SCHEMA_EXTRA_QNAMEREF:
1369  return (((xmlSchemaQNameRefPtr) item)->name);
1370  case XML_SCHEMA_TYPE_NOTATION:
1371  return (((xmlSchemaNotationPtr) item)->name);
1372  default:
1373  /*
1374  * Other components cannot have names.
1375  */
1376  break;
1377  }
1378  return (NULL);
1379 }
1380 
1381 #define xmlSchemaGetQNameRefName(r) (WXS_QNAME_CAST (r))->name
1382 #define xmlSchemaGetQNameRefTargetNs(r) (WXS_QNAME_CAST (r))->targetNamespace
1383 /*
1384 static const xmlChar *
1385 xmlSchemaGetQNameRefName(void *ref)
1386 {
1387  return(((xmlSchemaQNameRefPtr) ref)->name);
1388 }
1389 
1390 static const xmlChar *
1391 xmlSchemaGetQNameRefTargetNs(void *ref)
1392 {
1393  return(((xmlSchemaQNameRefPtr) ref)->targetNamespace);
1394 }
1395 */
1396 
1397 static const xmlChar *
1398 xmlSchemaGetComponentTargetNs(xmlSchemaBasicItemPtr item)
1399 {
1400  switch (item->type) {
1401  case XML_SCHEMA_TYPE_ELEMENT:
1402  return (((xmlSchemaElementPtr) item)->targetNamespace);
1403  case XML_SCHEMA_TYPE_ATTRIBUTE:
1404  return (((xmlSchemaAttributePtr) item)->targetNamespace);
1405  case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1406  return (((xmlSchemaAttributeGroupPtr) item)->targetNamespace);
1407  case XML_SCHEMA_TYPE_BASIC:
1408  return (BAD_CAST "http://www.w3.org/2001/XMLSchema");
1409  case XML_SCHEMA_TYPE_SIMPLE:
1410  case XML_SCHEMA_TYPE_COMPLEX:
1411  return (((xmlSchemaTypePtr) item)->targetNamespace);
1412  case XML_SCHEMA_TYPE_GROUP:
1413  return (((xmlSchemaModelGroupDefPtr) item)->targetNamespace);
1414  case XML_SCHEMA_TYPE_IDC_KEY:
1415  case XML_SCHEMA_TYPE_IDC_UNIQUE:
1416  case XML_SCHEMA_TYPE_IDC_KEYREF:
1417  return (((xmlSchemaIDCPtr) item)->targetNamespace);
1418  case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
1419  if (WXS_ATTRUSE_DECL(item) != NULL) {
1420  return(xmlSchemaGetComponentTargetNs(
1421  WXS_BASIC_CAST WXS_ATTRUSE_DECL(item)));
1422  }
1423  /* TODO: Will returning NULL break something? */
1424  break;
1425  case XML_SCHEMA_EXTRA_QNAMEREF:
1426  return (((xmlSchemaQNameRefPtr) item)->targetNamespace);
1427  case XML_SCHEMA_TYPE_NOTATION:
1428  return (((xmlSchemaNotationPtr) item)->targetNamespace);
1429  default:
1430  /*
1431  * Other components cannot have names.
1432  */
1433  break;
1434  }
1435  return (NULL);
1436 }
1437 
1438 static const xmlChar*
1439 xmlSchemaGetComponentQName(xmlChar **buf,
1440  void *item)
1441 {
1442  return (xmlSchemaFormatQName(buf,
1443  xmlSchemaGetComponentTargetNs((xmlSchemaBasicItemPtr) item),
1444  xmlSchemaGetComponentName((xmlSchemaBasicItemPtr) item)));
1445 }
1446 
1447 static const xmlChar*
1448 xmlSchemaGetComponentDesignation(xmlChar **buf, void *item)
1449 {
1450  xmlChar *str = NULL;
1451 
1452  *buf = xmlStrcat(*buf, WXS_ITEM_TYPE_NAME(item));
1453  *buf = xmlStrcat(*buf, BAD_CAST " '");
1454  *buf = xmlStrcat(*buf, xmlSchemaGetComponentQName(&str,
1455  (xmlSchemaBasicItemPtr) item));
1456  *buf = xmlStrcat(*buf, BAD_CAST "'");
1457  FREE_AND_NULL(str);
1458  return(*buf);
1459 }
1460 
1461 static const xmlChar*
1462 xmlSchemaGetIDCDesignation(xmlChar **buf, xmlSchemaIDCPtr idc)
1463 {
1464  return(xmlSchemaGetComponentDesignation(buf, idc));
1465 }
1466 
1474 static const xmlChar *
1475 xmlSchemaWildcardPCToString(int pc)
1476 {
1477  switch (pc) {
1478  case XML_SCHEMAS_ANY_SKIP:
1479  return (BAD_CAST "skip");
1480  case XML_SCHEMAS_ANY_LAX:
1481  return (BAD_CAST "lax");
1482  case XML_SCHEMAS_ANY_STRICT:
1483  return (BAD_CAST "strict");
1484  default:
1485  return (BAD_CAST "invalid process contents");
1486  }
1487 }
1488 
1502 static int
1503 xmlSchemaGetCanonValueWhtspExt_1(xmlSchemaValPtr val,
1504  xmlSchemaWhitespaceValueType ws,
1505  xmlChar **retValue,
1506  int for_hash)
1507 {
1508  int list;
1509  xmlSchemaValType valType;
1510  const xmlChar *value, *value2 = NULL;
1511 
1512 
1513  if ((retValue == NULL) || (val == NULL))
1514  return (-1);
1515  list = xmlSchemaValueGetNext(val) ? 1 : 0;
1516  *retValue = NULL;
1517  do {
1518  value = NULL;
1519  valType = xmlSchemaGetValType(val);
1520  switch (valType) {
1521  case XML_SCHEMAS_STRING:
1522  case XML_SCHEMAS_NORMSTRING:
1523  case XML_SCHEMAS_ANYSIMPLETYPE:
1524  value = xmlSchemaValueGetAsString(val);
1525  if (value != NULL) {
1526  if (ws == XML_SCHEMA_WHITESPACE_COLLAPSE)
1527  value2 = xmlSchemaCollapseString(value);
1528  else if (ws == XML_SCHEMA_WHITESPACE_REPLACE)
1529  value2 = xmlSchemaWhiteSpaceReplace(value);
1530  if (value2 != NULL)
1531  value = value2;
1532  }
1533  break;
1534  default:
1535  if (xmlSchemaGetCanonValue(val, &value2) == -1) {
1536  if (value2 != NULL)
1537  xmlFree((xmlChar *) value2);
1538  goto internal_error;
1539  }
1540  if (for_hash && valType == XML_SCHEMAS_DECIMAL) {
1541  /* We can mostly use the canonical value for hashing,
1542  except in the case of decimal. There the canonical
1543  representation requires a trailing '.0' even for
1544  non-fractional numbers, but for the derived integer
1545  types it forbids any decimal point. Nevertheless they
1546  compare equal if the value is equal. We need to generate
1547  the same hash value for this to work, and it's easiest
1548  to just cut off the useless '.0' suffix for the
1549  decimal type. */
1550  int len = xmlStrlen(value2);
1551  if (len > 2 && value2[len-1] == '0' && value2[len-2] == '.')
1552  ((xmlChar*)value2)[len-2] = 0;
1553  }
1554  value = value2;
1555  }
1556  if (*retValue == NULL)
1557  if (value == NULL) {
1558  if (! list)
1559  *retValue = xmlStrdup(BAD_CAST "");
1560  } else
1561  *retValue = xmlStrdup(value);
1562  else if (value != NULL) {
1563  /* List. */
1564  *retValue = xmlStrcat((xmlChar *) *retValue, BAD_CAST " ");
1565  *retValue = xmlStrcat((xmlChar *) *retValue, value);
1566  }
1567  FREE_AND_NULL(value2)
1568  val = xmlSchemaValueGetNext(val);
1569  } while (val != NULL);
1570 
1571  return (0);
1572 internal_error:
1573  if (*retValue != NULL)
1574  xmlFree((xmlChar *) (*retValue));
1575  if (value2 != NULL)
1576  xmlFree((xmlChar *) value2);
1577  return (-1);
1578 }
1579 
1580 static int
1581 xmlSchemaGetCanonValueWhtspExt(xmlSchemaValPtr val,
1582  xmlSchemaWhitespaceValueType ws,
1583  xmlChar **retValue)
1584 {
1585  return xmlSchemaGetCanonValueWhtspExt_1(val, ws, retValue, 0);
1586 }
1587 
1588 static int
1589 xmlSchemaGetCanonValueHash(xmlSchemaValPtr val,
1590  xmlChar **retValue)
1591 {
1592  return xmlSchemaGetCanonValueWhtspExt_1(val, XML_SCHEMA_WHITESPACE_COLLAPSE,
1593  retValue, 1);
1594 }
1595 
1622 static xmlChar*
1623 xmlSchemaFormatItemForReport(xmlChar **buf,
1624  const xmlChar *itemDes,
1625  xmlSchemaBasicItemPtr item,
1626  xmlNodePtr itemNode)
1627 {
1628  xmlChar *str = NULL;
1629  int named = 1;
1630 
1631  if (*buf != NULL) {
1632  xmlFree(*buf);
1633  *buf = NULL;
1634  }
1635 
1636  if (itemDes != NULL) {
1637  *buf = xmlStrdup(itemDes);
1638  } else if (item != NULL) {
1639  switch (item->type) {
1640  case XML_SCHEMA_TYPE_BASIC: {
1641  xmlSchemaTypePtr type = WXS_TYPE_CAST item;
1642 
1643  if (WXS_IS_ATOMIC(type))
1644  *buf = xmlStrdup(BAD_CAST "atomic type 'xs:");
1645  else if (WXS_IS_LIST(type))
1646  *buf = xmlStrdup(BAD_CAST "list type 'xs:");
1647  else if (WXS_IS_UNION(type))
1648  *buf = xmlStrdup(BAD_CAST "union type 'xs:");
1649  else
1650  *buf = xmlStrdup(BAD_CAST "simple type 'xs:");
1651  *buf = xmlStrcat(*buf, type->name);
1652  *buf = xmlStrcat(*buf, BAD_CAST "'");
1653  }
1654  break;
1655  case XML_SCHEMA_TYPE_SIMPLE: {
1656  xmlSchemaTypePtr type = WXS_TYPE_CAST item;
1657 
1658  if (type->flags & XML_SCHEMAS_TYPE_GLOBAL) {
1659  *buf = xmlStrdup(BAD_CAST"");
1660  } else {
1661  *buf = xmlStrdup(BAD_CAST "local ");
1662  }
1663  if (WXS_IS_ATOMIC(type))
1664  *buf = xmlStrcat(*buf, BAD_CAST "atomic type");
1665  else if (WXS_IS_LIST(type))
1666  *buf = xmlStrcat(*buf, BAD_CAST "list type");
1667  else if (WXS_IS_UNION(type))
1668  *buf = xmlStrcat(*buf, BAD_CAST "union type");
1669  else
1670  *buf = xmlStrcat(*buf, BAD_CAST "simple type");
1671  if (type->flags & XML_SCHEMAS_TYPE_GLOBAL) {
1672  *buf = xmlStrcat(*buf, BAD_CAST " '");
1673  *buf = xmlStrcat(*buf, type->name);
1674  *buf = xmlStrcat(*buf, BAD_CAST "'");
1675  }
1676  }
1677  break;
1678  case XML_SCHEMA_TYPE_COMPLEX: {
1679  xmlSchemaTypePtr type = WXS_TYPE_CAST item;
1680 
1681  if (type->flags & XML_SCHEMAS_TYPE_GLOBAL)
1682  *buf = xmlStrdup(BAD_CAST "");
1683  else
1684  *buf = xmlStrdup(BAD_CAST "local ");
1685  *buf = xmlStrcat(*buf, BAD_CAST "complex type");
1686  if (type->flags & XML_SCHEMAS_TYPE_GLOBAL) {
1687  *buf = xmlStrcat(*buf, BAD_CAST " '");
1688  *buf = xmlStrcat(*buf, type->name);
1689  *buf = xmlStrcat(*buf, BAD_CAST "'");
1690  }
1691  }
1692  break;
1693  case XML_SCHEMA_TYPE_ATTRIBUTE_USE: {
1694  xmlSchemaAttributeUsePtr ause;
1695 
1696  ause = WXS_ATTR_USE_CAST item;
1697  *buf = xmlStrdup(BAD_CAST "attribute use ");
1698  if (WXS_ATTRUSE_DECL(ause) != NULL) {
1699  *buf = xmlStrcat(*buf, BAD_CAST "'");
1700  *buf = xmlStrcat(*buf,
1701  xmlSchemaGetComponentQName(&str, WXS_ATTRUSE_DECL(ause)));
1702  FREE_AND_NULL(str)
1703  *buf = xmlStrcat(*buf, BAD_CAST "'");
1704  } else {
1705  *buf = xmlStrcat(*buf, BAD_CAST "(unknown)");
1706  }
1707  }
1708  break;
1709  case XML_SCHEMA_TYPE_ATTRIBUTE: {
1710  xmlSchemaAttributePtr attr;
1711 
1712  attr = (xmlSchemaAttributePtr) item;
1713  *buf = xmlStrdup(BAD_CAST "attribute decl.");
1714  *buf = xmlStrcat(*buf, BAD_CAST " '");
1715  *buf = xmlStrcat(*buf, xmlSchemaFormatQName(&str,
1716  attr->targetNamespace, attr->name));
1717  FREE_AND_NULL(str)
1718  *buf = xmlStrcat(*buf, BAD_CAST "'");
1719  }
1720  break;
1721  case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1722  xmlSchemaGetComponentDesignation(buf, item);
1723  break;
1724  case XML_SCHEMA_TYPE_ELEMENT: {
1725  xmlSchemaElementPtr elem;
1726 
1727  elem = (xmlSchemaElementPtr) item;
1728  *buf = xmlStrdup(BAD_CAST "element decl.");
1729  *buf = xmlStrcat(*buf, BAD_CAST " '");
1730  *buf = xmlStrcat(*buf, xmlSchemaFormatQName(&str,
1731  elem->targetNamespace, elem->name));
1732  *buf = xmlStrcat(*buf, BAD_CAST "'");
1733  }
1734  break;
1735  case XML_SCHEMA_TYPE_IDC_UNIQUE:
1736  case XML_SCHEMA_TYPE_IDC_KEY:
1737  case XML_SCHEMA_TYPE_IDC_KEYREF:
1738  if (item->type == XML_SCHEMA_TYPE_IDC_UNIQUE)
1739  *buf = xmlStrdup(BAD_CAST "unique '");
1740  else if (item->type == XML_SCHEMA_TYPE_IDC_KEY)
1741  *buf = xmlStrdup(BAD_CAST "key '");
1742  else
1743  *buf = xmlStrdup(BAD_CAST "keyRef '");
1744  *buf = xmlStrcat(*buf, ((xmlSchemaIDCPtr) item)->name);
1745  *buf = xmlStrcat(*buf, BAD_CAST "'");
1746  break;
1747  case XML_SCHEMA_TYPE_ANY:
1748  case XML_SCHEMA_TYPE_ANY_ATTRIBUTE:
1749  *buf = xmlStrdup(xmlSchemaWildcardPCToString(
1750  ((xmlSchemaWildcardPtr) item)->processContents));
1751  *buf = xmlStrcat(*buf, BAD_CAST " wildcard");
1752  break;
1753  case XML_SCHEMA_FACET_MININCLUSIVE:
1754  case XML_SCHEMA_FACET_MINEXCLUSIVE:
1755  case XML_SCHEMA_FACET_MAXINCLUSIVE:
1756  case XML_SCHEMA_FACET_MAXEXCLUSIVE:
1757  case XML_SCHEMA_FACET_TOTALDIGITS:
1758  case XML_SCHEMA_FACET_FRACTIONDIGITS:
1759  case XML_SCHEMA_FACET_PATTERN:
1760  case XML_SCHEMA_FACET_ENUMERATION:
1761  case XML_SCHEMA_FACET_WHITESPACE:
1762  case XML_SCHEMA_FACET_LENGTH:
1763  case XML_SCHEMA_FACET_MAXLENGTH:
1764  case XML_SCHEMA_FACET_MINLENGTH:
1765  *buf = xmlStrdup(BAD_CAST "facet '");
1766  *buf = xmlStrcat(*buf, xmlSchemaFacetTypeToString(item->type));
1767  *buf = xmlStrcat(*buf, BAD_CAST "'");
1768  break;
1769  case XML_SCHEMA_TYPE_GROUP: {
1770  *buf = xmlStrdup(BAD_CAST "model group def.");
1771  *buf = xmlStrcat(*buf, BAD_CAST " '");
1772  *buf = xmlStrcat(*buf, xmlSchemaGetComponentQName(&str, item));
1773  *buf = xmlStrcat(*buf, BAD_CAST "'");
1774  FREE_AND_NULL(str)
1775  }
1776  break;
1777  case XML_SCHEMA_TYPE_SEQUENCE:
1778  case XML_SCHEMA_TYPE_CHOICE:
1779  case XML_SCHEMA_TYPE_ALL:
1780  case XML_SCHEMA_TYPE_PARTICLE:
1781  *buf = xmlStrdup(WXS_ITEM_TYPE_NAME(item));
1782  break;
1783  case XML_SCHEMA_TYPE_NOTATION: {
1784  *buf = xmlStrdup(WXS_ITEM_TYPE_NAME(item));
1785  *buf = xmlStrcat(*buf, BAD_CAST " '");
1786  *buf = xmlStrcat(*buf, xmlSchemaGetComponentQName(&str, item));
1787  *buf = xmlStrcat(*buf, BAD_CAST "'");
1788  FREE_AND_NULL(str);
1789  }
1790  /* Falls through. */
1791  default:
1792  named = 0;
1793  }
1794  } else
1795  named = 0;
1796 
1797  if ((named == 0) && (itemNode != NULL)) {
1798  xmlNodePtr elem;
1799 
1800  if (itemNode->type == XML_ATTRIBUTE_NODE)
1801  elem = itemNode->parent;
1802  else
1803  elem = itemNode;
1804  *buf = xmlStrdup(BAD_CAST "Element '");
1805  if (elem->ns != NULL) {
1806  *buf = xmlStrcat(*buf,
1807  xmlSchemaFormatQName(&str, elem->ns->href, elem->name));
1808  FREE_AND_NULL(str)
1809  } else
1810  *buf = xmlStrcat(*buf, elem->name);
1811  *buf = xmlStrcat(*buf, BAD_CAST "'");
1812 
1813  }
1814  if ((itemNode != NULL) && (itemNode->type == XML_ATTRIBUTE_NODE)) {
1815  *buf = xmlStrcat(*buf, BAD_CAST ", attribute '");
1816  if (itemNode->ns != NULL) {
1817  *buf = xmlStrcat(*buf, xmlSchemaFormatQName(&str,
1818  itemNode->ns->href, itemNode->name));
1819  FREE_AND_NULL(str)
1820  } else
1821  *buf = xmlStrcat(*buf, itemNode->name);
1822  *buf = xmlStrcat(*buf, BAD_CAST "'");
1823  }
1824  FREE_AND_NULL(str)
1825 
1826  return (xmlEscapeFormatString(buf));
1827 }
1828 
1838 static const xmlChar *
1839 xmlSchemaFormatFacetEnumSet(xmlSchemaAbstractCtxtPtr actxt,
1840  xmlChar **buf, xmlSchemaTypePtr type)
1841 {
1842  xmlSchemaFacetPtr facet;
1843  xmlSchemaWhitespaceValueType ws;
1844  xmlChar *value = NULL;
1845  int res, found = 0;
1846 
1847  if (*buf != NULL)
1848  xmlFree(*buf);
1849  *buf = NULL;
1850 
1851  do {
1852  /*
1853  * Use the whitespace type of the base type.
1854  */
1855  ws = xmlSchemaGetWhiteSpaceFacetValue(type->baseType);
1856  for (facet = type->facets; facet != NULL; facet = facet->next) {
1857  if (facet->type != XML_SCHEMA_FACET_ENUMERATION)
1858  continue;
1859  found = 1;
1860  res = xmlSchemaGetCanonValueWhtspExt(facet->val,
1861  ws, &value);
1862  if (res == -1) {
1863  xmlSchemaInternalErr(actxt,
1864  "xmlSchemaFormatFacetEnumSet",
1865  "compute the canonical lexical representation");
1866  if (*buf != NULL)
1867  xmlFree(*buf);
1868  *buf = NULL;
1869  return (NULL);
1870  }
1871  if (*buf == NULL)
1872  *buf = xmlStrdup(BAD_CAST "'");
1873  else
1874  *buf = xmlStrcat(*buf, BAD_CAST ", '");
1875  *buf = xmlStrcat(*buf, BAD_CAST value);
1876  *buf = xmlStrcat(*buf, BAD_CAST "'");
1877  if (value != NULL) {
1878  xmlFree((xmlChar *)value);
1879  value = NULL;
1880  }
1881  }
1882  /*
1883  * The enumeration facet of a type restricts the enumeration
1884  * facet of the ancestor type; i.e., such restricted enumerations
1885  * do not belong to the set of the given type. Thus we break
1886  * on the first found enumeration.
1887  */
1888  if (found)
1889  break;
1890  type = type->baseType;
1891  } while ((type != NULL) && (type->type != XML_SCHEMA_TYPE_BASIC));
1892 
1893  return ((const xmlChar *) *buf);
1894 }
1895 
1896 /************************************************************************
1897  * *
1898  * Error functions *
1899  * *
1900  ************************************************************************/
1901 
1902 #if 0
1903 static void
1904 xmlSchemaErrMemory(const char *msg)
1905 {
1906  __xmlSimpleError(XML_FROM_SCHEMASP, XML_ERR_NO_MEMORY, NULL, NULL,
1907  msg);
1908 }
1909 #endif
1910 
1911 static void
1912 xmlSchemaPSimpleErr(const char *msg)
1913 {
1914  __xmlSimpleError(XML_FROM_SCHEMASP, XML_ERR_NO_MEMORY, NULL, NULL,
1915  msg);
1916 }
1917 
1925 static void
1926 xmlSchemaPErrMemory(xmlSchemaParserCtxtPtr ctxt,
1927  const char *extra, xmlNodePtr node)
1928 {
1929  if (ctxt != NULL)
1930  ctxt->nberrors++;
1931  __xmlSimpleError(XML_FROM_SCHEMASP, XML_ERR_NO_MEMORY, node, NULL,
1932  extra);
1933 }
1934 
1946 static void LIBXML_ATTR_FORMAT(4,0)
1947 xmlSchemaPErr(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int error,
1948  const char *msg, const xmlChar * str1, const xmlChar * str2)
1949 {
1950  xmlGenericErrorFunc channel = NULL;
1951  xmlStructuredErrorFunc schannel = NULL;
1952  void *data = NULL;
1953 
1954  if (ctxt != NULL) {
1955  ctxt->nberrors++;
1956  ctxt->err = error;
1957  channel = ctxt->error;
1958  data = ctxt->errCtxt;
1959  schannel = ctxt->serror;
1960  }
1961  __xmlRaiseError(schannel, channel, data, ctxt, node, XML_FROM_SCHEMASP,
1962  error, XML_ERR_ERROR, NULL, 0,
1963  (const char *) str1, (const char *) str2, NULL, 0, 0,
1964  msg, str1, str2);
1965 }
1966 
1979 static void LIBXML_ATTR_FORMAT(5,0)
1980 xmlSchemaPErr2(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node,
1981  xmlNodePtr child, int error,
1982  const char *msg, const xmlChar * str1, const xmlChar * str2)
1983 {
1984  if (child != NULL)
1985  xmlSchemaPErr(ctxt, child, error, msg, str1, str2);
1986  else
1987  xmlSchemaPErr(ctxt, node, error, msg, str1, str2);
1988 }
1989 
1990 
2008 static void LIBXML_ATTR_FORMAT(7,0)
2009 xmlSchemaPErrExt(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int error,
2010  const xmlChar * strData1, const xmlChar * strData2,
2011  const xmlChar * strData3, const char *msg, const xmlChar * str1,
2012  const xmlChar * str2, const xmlChar * str3, const xmlChar * str4,
2013  const xmlChar * str5)
2014 {
2015 
2016  xmlGenericErrorFunc channel = NULL;
2017  xmlStructuredErrorFunc schannel = NULL;
2018  void *data = NULL;
2019 
2020  if (ctxt != NULL) {
2021  ctxt->nberrors++;
2022  ctxt->err = error;
2023  channel = ctxt->error;
2024  data = ctxt->errCtxt;
2025  schannel = ctxt->serror;
2026  }
2027  __xmlRaiseError(schannel, channel, data, ctxt, node, XML_FROM_SCHEMASP,
2028  error, XML_ERR_ERROR, NULL, 0,
2029  (const char *) strData1, (const char *) strData2,
2030  (const char *) strData3, 0, 0, msg, str1, str2,
2031  str3, str4, str5);
2032 }
2033 
2034 /************************************************************************
2035  * *
2036  * Allround error functions *
2037  * *
2038  ************************************************************************/
2039 
2047 static void
2048 xmlSchemaVErrMemory(xmlSchemaValidCtxtPtr ctxt,
2049  const char *extra, xmlNodePtr node)
2050 {
2051  if (ctxt != NULL) {
2052  ctxt->nberrors++;
2053  ctxt->err = XML_SCHEMAV_INTERNAL;
2054  }
2055  __xmlSimpleError(XML_FROM_SCHEMASV, XML_ERR_NO_MEMORY, node, NULL,
2056  extra);
2057 }
2058 
2059 static void LIBXML_ATTR_FORMAT(2,0)
2060 xmlSchemaPSimpleInternalErr(xmlNodePtr node,
2061  const char *msg, const xmlChar *str)
2062 {
2063  __xmlSimpleError(XML_FROM_SCHEMASP, XML_SCHEMAP_INTERNAL, node,
2064  msg, (const char *) str);
2065 }
2066 
2067 #define WXS_ERROR_TYPE_ERROR 1
2068 #define WXS_ERROR_TYPE_WARNING 2
2069 
2084 static void LIBXML_ATTR_FORMAT(6,0)
2085 xmlSchemaErr4Line(xmlSchemaAbstractCtxtPtr ctxt,
2086  xmlErrorLevel errorLevel,
2087  int error, xmlNodePtr node, int line, const char *msg,
2088  const xmlChar *str1, const xmlChar *str2,
2089  const xmlChar *str3, const xmlChar *str4)
2090 {
2091  xmlStructuredErrorFunc schannel = NULL;
2092  xmlGenericErrorFunc channel = NULL;
2093  void *data = NULL;
2094 
2095  if (ctxt != NULL) {
2096  if (ctxt->type == XML_SCHEMA_CTXT_VALIDATOR) {
2097  xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctxt;
2098  const char *file = NULL;
2099  int col = 0;
2100  if (errorLevel != XML_ERR_WARNING) {
2101  vctxt->nberrors++;
2102  vctxt->err = error;
2103  channel = vctxt->error;
2104  } else {
2105  channel = vctxt->warning;
2106  }
2107  schannel = vctxt->serror;
2108  data = vctxt->errCtxt;
2109 
2110  /*
2111  * Error node. If we specify a line number, then
2112  * do not channel any node to the error function.
2113  */
2114  if (line == 0) {
2115  if ((node == NULL) &&
2116  (vctxt->depth >= 0) &&
2117  (vctxt->inode != NULL)) {
2118  node = vctxt->inode->node;
2119  }
2120  /*
2121  * Get filename and line if no node-tree.
2122  */
2123  if ((node == NULL) &&
2124  (vctxt->parserCtxt != NULL) &&
2125  (vctxt->parserCtxt->input != NULL)) {
2126  file = vctxt->parserCtxt->input->filename;
2127  line = vctxt->parserCtxt->input->line;
2128  col = vctxt->parserCtxt->input->col;
2129  }
2130  } else {
2131  /*
2132  * Override the given node's (if any) position
2133  * and channel only the given line number.
2134  */
2135  node = NULL;
2136  /*
2137  * Get filename.
2138  */
2139  if (vctxt->doc != NULL)
2140  file = (const char *) vctxt->doc->URL;
2141  else if ((vctxt->parserCtxt != NULL) &&
2142  (vctxt->parserCtxt->input != NULL))
2143  file = vctxt->parserCtxt->input->filename;
2144  }
2145  if (vctxt->locFunc != NULL) {
2146  if ((file == NULL) || (line == 0)) {
2147  unsigned long l;
2148  const char *f;
2149  vctxt->locFunc(vctxt->locCtxt, &f, &l);
2150  if (file == NULL)
2151  file = f;
2152  if (line == 0)
2153  line = (int) l;
2154  }
2155  }
2156  if ((file == NULL) && (vctxt->filename != NULL))
2157  file = vctxt->filename;
2158 
2159  __xmlRaiseError(schannel, channel, data, ctxt,
2161  error, errorLevel, file, line,
2162  (const char *) str1, (const char *) str2,
2163  (const char *) str3, 0, col, msg, str1, str2, str3, str4);
2164 
2165  } else if (ctxt->type == XML_SCHEMA_CTXT_PARSER) {
2166  xmlSchemaParserCtxtPtr pctxt = (xmlSchemaParserCtxtPtr) ctxt;
2167  if (errorLevel != XML_ERR_WARNING) {
2168  pctxt->nberrors++;
2169  pctxt->err = error;
2170  channel = pctxt->error;
2171  } else {
2172  channel = pctxt->warning;
2173  }
2174  schannel = pctxt->serror;
2175  data = pctxt->errCtxt;
2176  __xmlRaiseError(schannel, channel, data, ctxt,
2178  errorLevel, NULL, 0,
2179  (const char *) str1, (const char *) str2,
2180  (const char *) str3, 0, 0, msg, str1, str2, str3, str4);
2181  } else {
2182  TODO
2183  }
2184  }
2185 }
2186 
2199 static void LIBXML_ATTR_FORMAT(4,0)
2200 xmlSchemaErr3(xmlSchemaAbstractCtxtPtr actxt,
2201  int error, xmlNodePtr node, const char *msg,
2202  const xmlChar *str1, const xmlChar *str2, const xmlChar *str3)
2203 {
2204  xmlSchemaErr4Line(actxt, XML_ERR_ERROR, error, node, 0,
2205  msg, str1, str2, str3, NULL);
2206 }
2207 
2208 static void LIBXML_ATTR_FORMAT(4,0)
2209 xmlSchemaErr4(xmlSchemaAbstractCtxtPtr actxt,
2210  int error, xmlNodePtr node, const char *msg,
2211  const xmlChar *str1, const xmlChar *str2,
2212  const xmlChar *str3, const xmlChar *str4)
2213 {
2214  xmlSchemaErr4Line(actxt, XML_ERR_ERROR, error, node, 0,
2215  msg, str1, str2, str3, str4);
2216 }
2217 
2218 static void LIBXML_ATTR_FORMAT(4,0)
2219 xmlSchemaErr(xmlSchemaAbstractCtxtPtr actxt,
2220  int error, xmlNodePtr node, const char *msg,
2221  const xmlChar *str1, const xmlChar *str2)
2222 {
2223  xmlSchemaErr4(actxt, error, node, msg, str1, str2, NULL, NULL);
2224 }
2225 
2226 static xmlChar *
2227 xmlSchemaFormatNodeForError(xmlChar ** msg,
2228  xmlSchemaAbstractCtxtPtr actxt,
2229  xmlNodePtr node)
2230 {
2231  xmlChar *str = NULL;
2232 
2233  *msg = NULL;
2234  if ((node != NULL) &&
2235  (node->type != XML_ELEMENT_NODE) &&
2236  (node->type != XML_ATTRIBUTE_NODE))
2237  {
2238  /*
2239  * Don't try to format other nodes than element and
2240  * attribute nodes.
2241  * Play safe and return an empty string.
2242  */
2243  *msg = xmlStrdup(BAD_CAST "");
2244  return(*msg);
2245  }
2246  if (node != NULL) {
2247  /*
2248  * Work on tree nodes.
2249  */
2250  if (node->type == XML_ATTRIBUTE_NODE) {
2251  xmlNodePtr elem = node->parent;
2252 
2253  *msg = xmlStrdup(BAD_CAST "Element '");
2254  if (elem->ns != NULL)
2255  *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2256  elem->ns->href, elem->name));
2257  else
2258  *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2259  NULL, elem->name));
2260  FREE_AND_NULL(str);
2261  *msg = xmlStrcat(*msg, BAD_CAST "', ");
2262  *msg = xmlStrcat(*msg, BAD_CAST "attribute '");
2263  } else {
2264  *msg = xmlStrdup(BAD_CAST "Element '");
2265  }
2266  if (node->ns != NULL)
2267  *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2268  node->ns->href, node->name));
2269  else
2270  *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2271  NULL, node->name));
2272  FREE_AND_NULL(str);
2273  *msg = xmlStrcat(*msg, BAD_CAST "': ");
2274  } else if (actxt->type == XML_SCHEMA_CTXT_VALIDATOR) {
2275  xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) actxt;
2276  /*
2277  * Work on node infos.
2278  */
2279  if (vctxt->inode->nodeType == XML_ATTRIBUTE_NODE) {
2280  xmlSchemaNodeInfoPtr ielem =
2281  vctxt->elemInfos[vctxt->depth];
2282 
2283  *msg = xmlStrdup(BAD_CAST "Element '");
2284  *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2285  ielem->nsName, ielem->localName));
2286  FREE_AND_NULL(str);
2287  *msg = xmlStrcat(*msg, BAD_CAST "', ");
2288  *msg = xmlStrcat(*msg, BAD_CAST "attribute '");
2289  } else {
2290  *msg = xmlStrdup(BAD_CAST "Element '");
2291  }
2292  *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2293  vctxt->inode->nsName, vctxt->inode->localName));
2294  FREE_AND_NULL(str);
2295  *msg = xmlStrcat(*msg, BAD_CAST "': ");
2296  } else if (actxt->type == XML_SCHEMA_CTXT_PARSER) {
2297  /*
2298  * Hmm, no node while parsing?
2299  * Return an empty string, in case NULL will break something.
2300  */
2301  *msg = xmlStrdup(BAD_CAST "");
2302  } else {
2303  TODO
2304  return (NULL);
2305  }
2306 
2307  /*
2308  * xmlSchemaFormatItemForReport() also returns an escaped format
2309  * string, so do this before calling it below (in the future).
2310  */
2312 
2313  /*
2314  * VAL TODO: The output of the given schema component is currently
2315  * disabled.
2316  */
2317 #if 0
2318  if ((type != NULL) && (xmlSchemaIsGlobalItem(type))) {
2319  *msg = xmlStrcat(*msg, BAD_CAST " [");
2320  *msg = xmlStrcat(*msg, xmlSchemaFormatItemForReport(&str,
2321  NULL, type, NULL, 0));
2322  FREE_AND_NULL(str)
2323  *msg = xmlStrcat(*msg, BAD_CAST "]");
2324  }
2325 #endif
2326  return (*msg);
2327 }
2328 
2329 static void LIBXML_ATTR_FORMAT(3,0)
2330 xmlSchemaInternalErr2(xmlSchemaAbstractCtxtPtr actxt,
2331  const char *funcName,
2332  const char *message,
2333  const xmlChar *str1,
2334  const xmlChar *str2)
2335 {
2336  xmlChar *msg = NULL;
2337 
2338  if (actxt == NULL)
2339  return;
2340  msg = xmlStrdup(BAD_CAST "Internal error: %s, ");
2342  msg = xmlStrcat(msg, BAD_CAST ".\n");
2343 
2344  if (actxt->type == XML_SCHEMA_CTXT_VALIDATOR)
2345  xmlSchemaErr3(actxt, XML_SCHEMAV_INTERNAL, NULL,
2346  (const char *) msg, (const xmlChar *) funcName, str1, str2);
2347  else if (actxt->type == XML_SCHEMA_CTXT_PARSER)
2348  xmlSchemaErr3(actxt, XML_SCHEMAP_INTERNAL, NULL,
2349  (const char *) msg, (const xmlChar *) funcName, str1, str2);
2350 
2351  FREE_AND_NULL(msg)
2352 }
2353 
2354 static void LIBXML_ATTR_FORMAT(3,0)
2355 xmlSchemaInternalErr(xmlSchemaAbstractCtxtPtr actxt,
2356  const char *funcName,
2357  const char *message)
2358 {
2359  xmlSchemaInternalErr2(actxt, funcName, message, NULL, NULL);
2360 }
2361 
2362 #if 0
2363 static void LIBXML_ATTR_FORMAT(3,0)
2364 xmlSchemaPInternalErr(xmlSchemaParserCtxtPtr pctxt,
2365  const char *funcName,
2366  const char *message,
2367  const xmlChar *str1,
2368  const xmlChar *str2)
2369 {
2370  xmlSchemaInternalErr2(ACTXT_CAST pctxt, funcName, message,
2371  str1, str2);
2372 }
2373 #endif
2374 
2375 static void LIBXML_ATTR_FORMAT(5,0)
2376 xmlSchemaCustomErr4(xmlSchemaAbstractCtxtPtr actxt,
2378  xmlNodePtr node,
2379  xmlSchemaBasicItemPtr item,
2380  const char *message,
2381  const xmlChar *str1, const xmlChar *str2,
2382  const xmlChar *str3, const xmlChar *str4)
2383 {
2384  xmlChar *msg = NULL;
2385 
2386  if ((node == NULL) && (item != NULL) &&
2387  (actxt->type == XML_SCHEMA_CTXT_PARSER)) {
2388  node = WXS_ITEM_NODE(item);
2389  xmlSchemaFormatItemForReport(&msg, NULL, item, NULL);
2390  msg = xmlStrcat(msg, BAD_CAST ": ");
2391  } else
2392  xmlSchemaFormatNodeForError(&msg, actxt, node);
2393  msg = xmlStrcat(msg, (const xmlChar *) message);
2394  msg = xmlStrcat(msg, BAD_CAST ".\n");
2395  xmlSchemaErr4(actxt, error, node,
2396  (const char *) msg, str1, str2, str3, str4);
2397  FREE_AND_NULL(msg)
2398 }
2399 
2400 static void LIBXML_ATTR_FORMAT(5,0)
2401 xmlSchemaCustomErr(xmlSchemaAbstractCtxtPtr actxt,
2403  xmlNodePtr node,
2404  xmlSchemaBasicItemPtr item,
2405  const char *message,
2406  const xmlChar *str1,
2407  const xmlChar *str2)
2408 {
2409  xmlSchemaCustomErr4(actxt, error, node, item,
2410  message, str1, str2, NULL, NULL);
2411 }
2412 
2413 
2414 
2415 static void LIBXML_ATTR_FORMAT(5,0)
2416 xmlSchemaCustomWarning(xmlSchemaAbstractCtxtPtr actxt,
2418  xmlNodePtr node,
2419  xmlSchemaTypePtr type ATTRIBUTE_UNUSED,
2420  const char *message,
2421  const xmlChar *str1,
2422  const xmlChar *str2,
2423  const xmlChar *str3)
2424 {
2425  xmlChar *msg = NULL;
2426 
2427  xmlSchemaFormatNodeForError(&msg, actxt, node);
2428  msg = xmlStrcat(msg, (const xmlChar *) message);
2429  msg = xmlStrcat(msg, BAD_CAST ".\n");
2430 
2431  /* URGENT TODO: Set the error code to something sane. */
2432  xmlSchemaErr4Line(actxt, XML_ERR_WARNING, error, node, 0,
2433  (const char *) msg, str1, str2, str3, NULL);
2434 
2435  FREE_AND_NULL(msg)
2436 }
2437 
2438 
2439 
2440 static void LIBXML_ATTR_FORMAT(5,0)
2441 xmlSchemaKeyrefErr(xmlSchemaValidCtxtPtr vctxt,
2443  xmlSchemaPSVIIDCNodePtr idcNode,
2444  xmlSchemaTypePtr type ATTRIBUTE_UNUSED,
2445  const char *message,
2446  const xmlChar *str1,
2447  const xmlChar *str2)
2448 {
2449  xmlChar *msg = NULL, *qname = NULL;
2450 
2451  msg = xmlStrdup(BAD_CAST "Element '%s': ");
2452  msg = xmlStrcat(msg, (const xmlChar *) message);
2453  msg = xmlStrcat(msg, BAD_CAST ".\n");
2454  xmlSchemaErr4Line(ACTXT_CAST vctxt, XML_ERR_ERROR,
2455  error, NULL, idcNode->nodeLine, (const char *) msg,
2456  xmlSchemaFormatQName(&qname,
2457  vctxt->nodeQNames->items[idcNode->nodeQNameID +1],
2458  vctxt->nodeQNames->items[idcNode->nodeQNameID]),
2459  str1, str2, NULL);
2460  FREE_AND_NULL(qname);
2461  FREE_AND_NULL(msg);
2462 }
2463 
2464 static int
2465 xmlSchemaEvalErrorNodeType(xmlSchemaAbstractCtxtPtr actxt,
2466  xmlNodePtr node)
2467 {
2468  if (node != NULL)
2469  return (node->type);
2470  if ((actxt->type == XML_SCHEMA_CTXT_VALIDATOR) &&
2471  (((xmlSchemaValidCtxtPtr) actxt)->inode != NULL))
2472  return ( ((xmlSchemaValidCtxtPtr) actxt)->inode->nodeType);
2473  return (-1);
2474 }
2475 
2476 static int
2477 xmlSchemaIsGlobalItem(xmlSchemaTypePtr item)
2478 {
2479  switch (item->type) {
2480  case XML_SCHEMA_TYPE_COMPLEX:
2481  case XML_SCHEMA_TYPE_SIMPLE:
2482  if (item->flags & XML_SCHEMAS_TYPE_GLOBAL)
2483  return(1);
2484  break;
2485  case XML_SCHEMA_TYPE_GROUP:
2486  return (1);
2487  case XML_SCHEMA_TYPE_ELEMENT:
2488  if ( ((xmlSchemaElementPtr) item)->flags &
2489  XML_SCHEMAS_ELEM_GLOBAL)
2490  return(1);
2491  break;
2492  case XML_SCHEMA_TYPE_ATTRIBUTE:
2493  if ( ((xmlSchemaAttributePtr) item)->flags &
2494  XML_SCHEMAS_ATTR_GLOBAL)
2495  return(1);
2496  break;
2497  /* Note that attribute groups are always global. */
2498  default:
2499  return(1);
2500  }
2501  return (0);
2502 }
2503 
2504 static void
2505 xmlSchemaSimpleTypeErr(xmlSchemaAbstractCtxtPtr actxt,
2507  xmlNodePtr node,
2508  const xmlChar *value,
2509  xmlSchemaTypePtr type,
2510  int displayValue)
2511 {
2512  xmlChar *msg = NULL;
2513 
2514  xmlSchemaFormatNodeForError(&msg, actxt, node);
2515 
2516  if (displayValue || (xmlSchemaEvalErrorNodeType(actxt, node) ==
2518  msg = xmlStrcat(msg, BAD_CAST "'%s' is not a valid value of ");
2519  else
2520  msg = xmlStrcat(msg, BAD_CAST "The character content is not a valid "
2521  "value of ");
2522 
2523  if (! xmlSchemaIsGlobalItem(type))
2524  msg = xmlStrcat(msg, BAD_CAST "the local ");
2525  else
2526  msg = xmlStrcat(msg, BAD_CAST "the ");
2527 
2528  if (WXS_IS_ATOMIC(type))
2529  msg = xmlStrcat(msg, BAD_CAST "atomic type");
2530  else if (WXS_IS_LIST(type))
2531  msg = xmlStrcat(msg, BAD_CAST "list type");
2532  else if (WXS_IS_UNION(type))
2533  msg = xmlStrcat(msg, BAD_CAST "union type");
2534 
2535  if (xmlSchemaIsGlobalItem(type)) {
2536  xmlChar *str = NULL;
2537  msg = xmlStrcat(msg, BAD_CAST " '");
2538  if (type->builtInType != 0) {
2539  msg = xmlStrcat(msg, BAD_CAST "xs:");
2540  str = xmlStrdup(type->name);
2541  } else {
2542  const xmlChar *qName = xmlSchemaFormatQName(&str, type->targetNamespace, type->name);
2543  if (!str)
2544  str = xmlStrdup(qName);
2545  }
2547  msg = xmlStrcat(msg, BAD_CAST "'");
2548  FREE_AND_NULL(str);
2549  }
2550  msg = xmlStrcat(msg, BAD_CAST ".\n");
2551  if (displayValue || (xmlSchemaEvalErrorNodeType(actxt, node) ==
2553  xmlSchemaErr(actxt, error, node, (const char *) msg, value, NULL);
2554  else
2555  xmlSchemaErr(actxt, error, node, (const char *) msg, NULL, NULL);
2556  FREE_AND_NULL(msg)
2557 }
2558 
2559 static const xmlChar *
2560 xmlSchemaFormatErrorNodeQName(xmlChar ** str,
2561  xmlSchemaNodeInfoPtr ni,
2562  xmlNodePtr node)
2563 {
2564  if (node != NULL) {
2565  if (node->ns != NULL)
2566  return (xmlSchemaFormatQName(str, node->ns->href, node->name));
2567  else
2568  return (xmlSchemaFormatQName(str, NULL, node->name));
2569  } else if (ni != NULL)
2570  return (xmlSchemaFormatQName(str, ni->nsName, ni->localName));
2571  return (NULL);
2572 }
2573 
2574 static void
2575 xmlSchemaIllegalAttrErr(xmlSchemaAbstractCtxtPtr actxt,
2577  xmlSchemaAttrInfoPtr ni,
2578  xmlNodePtr node)
2579 {
2580  xmlChar *msg = NULL, *str = NULL;
2581 
2582  xmlSchemaFormatNodeForError(&msg, actxt, node);
2583  msg = xmlStrcat(msg, BAD_CAST "The attribute '%s' is not allowed.\n");
2584  xmlSchemaErr(actxt, error, node, (const char *) msg,
2585  xmlSchemaFormatErrorNodeQName(&str, (xmlSchemaNodeInfoPtr) ni, node),
2586  NULL);
2587  FREE_AND_NULL(str)
2588  FREE_AND_NULL(msg)
2589 }
2590 
2591 static void LIBXML_ATTR_FORMAT(5,0)
2592 xmlSchemaComplexTypeErr(xmlSchemaAbstractCtxtPtr actxt,
2594  xmlNodePtr node,
2595  xmlSchemaTypePtr type ATTRIBUTE_UNUSED,
2596  const char *message,
2597  int nbval,
2598  int nbneg,
2599  xmlChar **values)
2600 {
2601  xmlChar *str = NULL, *msg = NULL;
2602  xmlChar *localName, *nsName;
2603  const xmlChar *cur, *end;
2604  int i;
2605 
2606  xmlSchemaFormatNodeForError(&msg, actxt, node);
2607  msg = xmlStrcat(msg, (const xmlChar *) message);
2608  msg = xmlStrcat(msg, BAD_CAST ".");
2609  /*
2610  * Note that is does not make sense to report that we have a
2611  * wildcard here, since the wildcard might be unfolded into
2612  * multiple transitions.
2613  */
2614  if (nbval + nbneg > 0) {
2615  if (nbval + nbneg > 1) {
2616  str = xmlStrdup(BAD_CAST " Expected is one of ( ");
2617  } else
2618  str = xmlStrdup(BAD_CAST " Expected is ( ");
2619  nsName = NULL;
2620 
2621  for (i = 0; i < nbval + nbneg; i++) {
2622  cur = values[i];
2623  if (cur == NULL)
2624  continue;
2625  if ((cur[0] == 'n') && (cur[1] == 'o') && (cur[2] == 't') &&
2626  (cur[3] == ' ')) {
2627  cur += 4;
2628  str = xmlStrcat(str, BAD_CAST "##other");
2629  }
2630  /*
2631  * Get the local name.
2632  */
2633  localName = NULL;
2634 
2635  end = cur;
2636  if (*end == '*') {
2637  localName = xmlStrdup(BAD_CAST "*");
2638  end++;
2639  } else {
2640  while ((*end != 0) && (*end != '|'))
2641  end++;
2642  localName = xmlStrncat(localName, BAD_CAST cur, end - cur);
2643  }
2644  if (*end != 0) {
2645  end++;
2646  /*
2647  * Skip "*|*" if they come with negated expressions, since
2648  * they represent the same negated wildcard.
2649  */
2650  if ((nbneg == 0) || (*end != '*') || (*localName != '*')) {
2651  /*
2652  * Get the namespace name.
2653  */
2654  cur = end;
2655  if (*end == '*') {
2656  nsName = xmlStrdup(BAD_CAST "{*}");
2657  } else {
2658  while (*end != 0)
2659  end++;
2660 
2661  if (i >= nbval)
2662  nsName = xmlStrdup(BAD_CAST "{##other:");
2663  else
2664  nsName = xmlStrdup(BAD_CAST "{");
2665 
2666  nsName = xmlStrncat(nsName, BAD_CAST cur, end - cur);
2667  nsName = xmlStrcat(nsName, BAD_CAST "}");
2668  }
2669  str = xmlStrcat(str, BAD_CAST nsName);
2670  FREE_AND_NULL(nsName)
2671  } else {
2672  FREE_AND_NULL(localName);
2673  continue;
2674  }
2675  }
2676  str = xmlStrcat(str, BAD_CAST localName);
2677  FREE_AND_NULL(localName);
2678 
2679  if (i < nbval + nbneg -1)
2680  str = xmlStrcat(str, BAD_CAST ", ");
2681  }
2682  str = xmlStrcat(str, BAD_CAST " ).\n");
2684  FREE_AND_NULL(str)
2685  } else
2686  msg = xmlStrcat(msg, BAD_CAST "\n");
2687  xmlSchemaErr(actxt, error, node, (const char *) msg, NULL, NULL);
2688  xmlFree(msg);
2689 }
2690 
2691 static void LIBXML_ATTR_FORMAT(8,0)
2692 xmlSchemaFacetErr(xmlSchemaAbstractCtxtPtr actxt,
2694  xmlNodePtr node,
2695  const xmlChar *value,
2696  unsigned long length,
2697  xmlSchemaTypePtr type,
2698  xmlSchemaFacetPtr facet,
2699  const char *message,
2700  const xmlChar *str1,
2701  const xmlChar *str2)
2702 {
2703  xmlChar *str = NULL, *msg = NULL;
2704  xmlSchemaTypeType facetType;
2705  int nodeType = xmlSchemaEvalErrorNodeType(actxt, node);
2706 
2707  xmlSchemaFormatNodeForError(&msg, actxt, node);
2709  facetType = XML_SCHEMA_FACET_ENUMERATION;
2710  /*
2711  * If enumerations are validated, one must not expect the
2712  * facet to be given.
2713  */
2714  } else
2715  facetType = facet->type;
2716  msg = xmlStrcat(msg, BAD_CAST "[");
2717  msg = xmlStrcat(msg, BAD_CAST "facet '");
2718  msg = xmlStrcat(msg, xmlSchemaFacetTypeToString(facetType));
2719  msg = xmlStrcat(msg, BAD_CAST "'] ");
2720  if (message == NULL) {
2721  /*
2722  * Use a default message.
2723  */
2724  if ((facetType == XML_SCHEMA_FACET_LENGTH) ||
2725  (facetType == XML_SCHEMA_FACET_MINLENGTH) ||
2726  (facetType == XML_SCHEMA_FACET_MAXLENGTH)) {
2727 
2728  char len[25], actLen[25];
2729 
2730  /* FIXME, TODO: What is the max expected string length of the
2731  * this value?
2732  */
2733  if (nodeType == XML_ATTRIBUTE_NODE)
2734  msg = xmlStrcat(msg, BAD_CAST "The value '%s' has a length of '%s'; ");
2735  else
2736  msg = xmlStrcat(msg, BAD_CAST "The value has a length of '%s'; ");
2737 
2738  snprintf(len, 24, "%lu", xmlSchemaGetFacetValueAsULong(facet));
2739  snprintf(actLen, 24, "%lu", length);
2740 
2741  if (facetType == XML_SCHEMA_FACET_LENGTH)
2742  msg = xmlStrcat(msg,
2743  BAD_CAST "this differs from the allowed length of '%s'.\n");
2744  else if (facetType == XML_SCHEMA_FACET_MAXLENGTH)
2745  msg = xmlStrcat(msg,
2746  BAD_CAST "this exceeds the allowed maximum length of '%s'.\n");
2747  else if (facetType == XML_SCHEMA_FACET_MINLENGTH)
2748  msg = xmlStrcat(msg,
2749  BAD_CAST "this underruns the allowed minimum length of '%s'.\n");
2750 
2751  if (nodeType == XML_ATTRIBUTE_NODE)
2752  xmlSchemaErr3(actxt, error, node, (const char *) msg,
2753  value, (const xmlChar *) actLen, (const xmlChar *) len);
2754  else
2755  xmlSchemaErr(actxt, error, node, (const char *) msg,
2756  (const xmlChar *) actLen, (const xmlChar *) len);
2757 
2758  } else if (facetType == XML_SCHEMA_FACET_ENUMERATION) {
2759  msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not an element "
2760  "of the set {%s}.\n");
2761  xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2762  xmlSchemaFormatFacetEnumSet(actxt, &str, type));
2763  } else if (facetType == XML_SCHEMA_FACET_PATTERN) {
2764  msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not accepted "
2765  "by the pattern '%s'.\n");
2766  xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2767  facet->value);
2768  } else if (facetType == XML_SCHEMA_FACET_MININCLUSIVE) {
2769  msg = xmlStrcat(msg, BAD_CAST "The value '%s' is less than the "
2770  "minimum value allowed ('%s').\n");
2771  xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2772  facet->value);
2773  } else if (facetType == XML_SCHEMA_FACET_MAXINCLUSIVE) {
2774  msg = xmlStrcat(msg, BAD_CAST "The value '%s' is greater than the "
2775  "maximum value allowed ('%s').\n");
2776  xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2777  facet->value);
2778  } else if (facetType == XML_SCHEMA_FACET_MINEXCLUSIVE) {
2779  msg = xmlStrcat(msg, BAD_CAST "The value '%s' must be greater than "
2780  "'%s'.\n");
2781  xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2782  facet->value);
2783  } else if (facetType == XML_SCHEMA_FACET_MAXEXCLUSIVE) {
2784  msg = xmlStrcat(msg, BAD_CAST "The value '%s' must be less than "
2785  "'%s'.\n");
2786  xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2787  facet->value);
2788  } else if (facetType == XML_SCHEMA_FACET_TOTALDIGITS) {
2789  msg = xmlStrcat(msg, BAD_CAST "The value '%s' has more "
2790  "digits than are allowed ('%s').\n");
2791  xmlSchemaErr(actxt, error, node, (const char*) msg, value,
2792  facet->value);
2793  } else if (facetType == XML_SCHEMA_FACET_FRACTIONDIGITS) {
2794  msg = xmlStrcat(msg, BAD_CAST "The value '%s' has more fractional "
2795  "digits than are allowed ('%s').\n");
2796  xmlSchemaErr(actxt, error, node, (const char*) msg, value,
2797  facet->value);
2798  } else if (nodeType == XML_ATTRIBUTE_NODE) {
2799  msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not facet-valid.\n");
2800  xmlSchemaErr(actxt, error, node, (const char *) msg, value, NULL);
2801  } else {
2802  msg = xmlStrcat(msg, BAD_CAST "The value is not facet-valid.\n");
2803  xmlSchemaErr(actxt, error, node, (const char *) msg, NULL, NULL);
2804  }
2805  } else {
2806  msg = xmlStrcat(msg, (const xmlChar *) message);
2807  msg = xmlStrcat(msg, BAD_CAST ".\n");
2808  xmlSchemaErr(actxt, error, node, (const char *) msg, str1, str2);
2809  }
2810  FREE_AND_NULL(str)
2811  xmlFree(msg);
2812 }
2813 
2814 #define VERROR(err, type, msg) \
2815  xmlSchemaCustomErr(ACTXT_CAST vctxt, err, NULL, type, msg, NULL, NULL);
2816 
2817 #define VERROR_INT(func, msg) xmlSchemaInternalErr(ACTXT_CAST vctxt, func, msg);
2818 
2819 #define PERROR_INT(func, msg) xmlSchemaInternalErr(ACTXT_CAST pctxt, func, msg);
2820 #define PERROR_INT2(func, msg) xmlSchemaInternalErr(ACTXT_CAST ctxt, func, msg);
2821 
2822 #define AERROR_INT(func, msg) xmlSchemaInternalErr(actxt, func, msg);
2823 
2824 
2835 static void
2836 xmlSchemaPMissingAttrErr(xmlSchemaParserCtxtPtr ctxt,
2838  xmlSchemaBasicItemPtr ownerItem,
2839  xmlNodePtr ownerElem,
2840  const char *name,
2841  const char *message)
2842 {
2843  xmlChar *des = NULL;
2844 
2845  xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem);
2846 
2847  if (message != NULL)
2848  xmlSchemaPErr(ctxt, ownerElem, error, "%s: %s.\n", BAD_CAST des, BAD_CAST message);
2849  else
2850  xmlSchemaPErr(ctxt, ownerElem, error,
2851  "%s: The attribute '%s' is required but missing.\n",
2853  FREE_AND_NULL(des);
2854 }
2855 
2856 
2871 static void
2872 xmlSchemaPResCompAttrErr(xmlSchemaParserCtxtPtr ctxt,
2874  xmlSchemaBasicItemPtr ownerItem,
2875  xmlNodePtr ownerElem,
2876  const char *name,
2877  const xmlChar *refName,
2878  const xmlChar *refURI,
2879  xmlSchemaTypeType refType,
2880  const char *refTypeStr)
2881 {
2882  xmlChar *des = NULL, *strA = NULL;
2883 
2884  xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem);
2885  if (refTypeStr == NULL)
2886  refTypeStr = (const char *) xmlSchemaItemTypeToStr(refType);
2887  xmlSchemaPErrExt(ctxt, ownerElem, error,
2888  NULL, NULL, NULL,
2889  "%s, attribute '%s': The QName value '%s' does not resolve to a(n) "
2890  "%s.\n", BAD_CAST des, BAD_CAST name,
2891  xmlSchemaFormatQName(&strA, refURI, refName),
2892  BAD_CAST refTypeStr, NULL);
2893  FREE_AND_NULL(des)
2894  FREE_AND_NULL(strA)
2895 }
2896 
2907 static void
2908 xmlSchemaPCustomAttrErr(xmlSchemaParserCtxtPtr ctxt,
2910  xmlChar **ownerDes,
2911  xmlSchemaBasicItemPtr ownerItem,
2912  xmlAttrPtr attr,
2913  const char *msg)
2914 {
2915  xmlChar *des = NULL;
2916 
2917  if (ownerDes == NULL)
2918  xmlSchemaFormatItemForReport(&des, NULL, ownerItem, attr->parent);
2919  else if (*ownerDes == NULL) {
2920  xmlSchemaFormatItemForReport(ownerDes, NULL, ownerItem, attr->parent);
2921  des = *ownerDes;
2922  } else
2923  des = *ownerDes;
2924  if (attr == NULL) {
2925  xmlSchemaPErrExt(ctxt, NULL, error, NULL, NULL, NULL,
2926  "%s, attribute '%s': %s.\n",
2927  BAD_CAST des, (const xmlChar *) "Unknown",
2928  (const xmlChar *) msg, NULL, NULL);
2929  } else {
2930  xmlSchemaPErrExt(ctxt, (xmlNodePtr) attr, error, NULL, NULL, NULL,
2931  "%s, attribute '%s': %s.\n",
2932  BAD_CAST des, attr->name, (const xmlChar *) msg, NULL, NULL);
2933  }
2934  if (ownerDes == NULL)
2935  FREE_AND_NULL(des);
2936 }
2937 
2947 static void
2948 xmlSchemaPIllegalAttrErr(xmlSchemaParserCtxtPtr ctxt,
2950  xmlSchemaBasicItemPtr ownerComp ATTRIBUTE_UNUSED,
2951  xmlAttrPtr attr)
2952 {
2953  xmlChar *strA = NULL, *strB = NULL;
2954 
2955  xmlSchemaFormatNodeForError(&strA, ACTXT_CAST ctxt, attr->parent);
2956  xmlSchemaErr4(ACTXT_CAST ctxt, error, (xmlNodePtr) attr,
2957  "%sThe attribute '%s' is not allowed.\n", BAD_CAST strA,
2958  xmlSchemaFormatQNameNs(&strB, attr->ns, attr->name),
2959  NULL, NULL);
2960  FREE_AND_NULL(strA);
2961  FREE_AND_NULL(strB);
2962 }
2963 
2978 static void LIBXML_ATTR_FORMAT(5,0)
2979 xmlSchemaPCustomErrExt(xmlSchemaParserCtxtPtr ctxt,
2981  xmlSchemaBasicItemPtr item,
2982  xmlNodePtr itemElem,
2983  const char *message,
2984  const xmlChar *str1,
2985  const xmlChar *str2,
2986  const xmlChar *str3)
2987 {
2988  xmlChar *des = NULL, *msg = NULL;
2989 
2990  xmlSchemaFormatItemForReport(&des, NULL, item, itemElem);
2991  msg = xmlStrdup(BAD_CAST "%s: ");
2992  msg = xmlStrcat(msg, (const xmlChar *) message);
2993  msg = xmlStrcat(msg, BAD_CAST ".\n");
2994  if ((itemElem == NULL) && (item != NULL))
2995  itemElem = WXS_ITEM_NODE(item);
2996  xmlSchemaPErrExt(ctxt, itemElem, error, NULL, NULL, NULL,
2997  (const char *) msg, BAD_CAST des, str1, str2, str3, NULL);
2998  FREE_AND_NULL(des);
2999  FREE_AND_NULL(msg);
3000 }
3001 
3014 static void LIBXML_ATTR_FORMAT(5,0)
3015 xmlSchemaPCustomErr(xmlSchemaParserCtxtPtr ctxt,
3017  xmlSchemaBasicItemPtr item,
3018  xmlNodePtr itemElem,
3019  const char *message,
3020  const xmlChar *str1)
3021 {
3022  xmlSchemaPCustomErrExt(ctxt, error, item, itemElem, message,
3023  str1, NULL, NULL);
3024 }
3025 
3039 static void LIBXML_ATTR_FORMAT(6,0)
3040 xmlSchemaPAttrUseErr4(xmlSchemaParserCtxtPtr ctxt,
3042  xmlNodePtr node,
3043  xmlSchemaBasicItemPtr ownerItem,
3044  const xmlSchemaAttributeUsePtr attruse,
3045  const char *message,
3046  const xmlChar *str1, const xmlChar *str2,
3047  const xmlChar *str3,const xmlChar *str4)
3048 {
3049  xmlChar *str = NULL, *msg = NULL;
3050 
3051  xmlSchemaFormatItemForReport(&msg, NULL, ownerItem, NULL);
3052  msg = xmlStrcat(msg, BAD_CAST ", ");
3053  msg = xmlStrcat(msg,
3054  BAD_CAST xmlSchemaFormatItemForReport(&str, NULL,
3055  WXS_BASIC_CAST attruse, NULL));
3056  FREE_AND_NULL(str);
3057  msg = xmlStrcat(msg, BAD_CAST ": ");
3058  msg = xmlStrcat(msg, (const xmlChar *) message);
3059  msg = xmlStrcat(msg, BAD_CAST ".\n");
3060  xmlSchemaErr4(ACTXT_CAST ctxt, error, node,
3061  (const char *) msg, str1, str2, str3, str4);
3062  xmlFree(msg);
3063 }
3064 
3075 static void
3076 xmlSchemaPIllegalFacetAtomicErr(xmlSchemaParserCtxtPtr ctxt,
3078  xmlSchemaTypePtr type,
3079  xmlSchemaTypePtr baseType,
3080  xmlSchemaFacetPtr facet)
3081 {
3082  xmlChar *des = NULL, *strT = NULL;
3083 
3084  xmlSchemaFormatItemForReport(&des, NULL, WXS_BASIC_CAST type, type->node);
3085  xmlSchemaPErrExt(ctxt, type->node, error, NULL, NULL, NULL,
3086  "%s: The facet '%s' is not allowed on types derived from the "
3087  "type %s.\n",
3088  BAD_CAST des, xmlSchemaFacetTypeToString(facet->type),
3089  xmlSchemaFormatItemForReport(&strT, NULL, WXS_BASIC_CAST baseType, NULL),
3090  NULL, NULL);
3091  FREE_AND_NULL(des);
3092  FREE_AND_NULL(strT);
3093 }
3094 
3105 static void
3106 xmlSchemaPIllegalFacetListUnionErr(xmlSchemaParserCtxtPtr ctxt,
3108  xmlSchemaTypePtr type,
3109  xmlSchemaFacetPtr facet)
3110 {
3111  xmlChar *des = NULL;
3112 
3113  xmlSchemaFormatItemForReport(&des, NULL, WXS_BASIC_CAST type,
3114  type->node);
3115  xmlSchemaPErr(ctxt, type->node, error,
3116  "%s: The facet '%s' is not allowed.\n",
3117  BAD_CAST des, xmlSchemaFacetTypeToString(facet->type));
3118  FREE_AND_NULL(des);
3119 }
3120 
3131 static void
3132 xmlSchemaPMutualExclAttrErr(xmlSchemaParserCtxtPtr ctxt,
3134  xmlSchemaBasicItemPtr ownerItem,
3135  xmlAttrPtr attr,
3136  const char *name1,
3137  const char *name2)
3138 {
3139  xmlChar *des = NULL;
3140 
3141  xmlSchemaFormatItemForReport(&des, NULL, WXS_BASIC_CAST ownerItem, attr->parent);
3142  xmlSchemaPErrExt(ctxt, (xmlNodePtr) attr, error, NULL, NULL, NULL,
3143  "%s: The attributes '%s' and '%s' are mutually exclusive.\n",
3145  FREE_AND_NULL(des);
3146 }
3147 
3160 static void LIBXML_ATTR_FORMAT(8,0)
3161 xmlSchemaPSimpleTypeErr(xmlSchemaParserCtxtPtr ctxt,
3163  xmlSchemaBasicItemPtr ownerItem ATTRIBUTE_UNUSED,
3164  xmlNodePtr node,
3165  xmlSchemaTypePtr type,
3166  const char *expected,
3167  const xmlChar *value,
3168  const char *message,
3169  const xmlChar *str1,
3170  const xmlChar *str2)
3171 {
3172  xmlChar *msg = NULL;
3173 
3174  xmlSchemaFormatNodeForError(&msg, ACTXT_CAST ctxt, node);
3175  if (message == NULL) {
3176  /*
3177  * Use default messages.
3178  */
3179  if (type != NULL) {
3180  if (node->type == XML_ATTRIBUTE_NODE)
3181  msg = xmlStrcat(msg, BAD_CAST "'%s' is not a valid value of ");
3182  else
3183  msg = xmlStrcat(msg, BAD_CAST "The character content is not a "
3184  "valid value of ");
3185  if (! xmlSchemaIsGlobalItem(type))
3186  msg = xmlStrcat(msg, BAD_CAST "the local ");
3187  else
3188  msg = xmlStrcat(msg, BAD_CAST "the ");
3189 
3190  if (WXS_IS_ATOMIC(type))
3191  msg = xmlStrcat(msg, BAD_CAST "atomic type");
3192  else if (WXS_IS_LIST(type))
3193  msg = xmlStrcat(msg, BAD_CAST "list type");
3194  else if (WXS_IS_UNION(type))
3195  msg = xmlStrcat(msg, BAD_CAST "union type");
3196 
3197  if (xmlSchemaIsGlobalItem(type)) {
3198  xmlChar *str = NULL;
3199  msg = xmlStrcat(msg, BAD_CAST " '");
3200  if (type->builtInType != 0) {
3201  msg = xmlStrcat(msg, BAD_CAST "xs:");
3202  str = xmlStrdup(type->name);
3203  } else {
3204  const xmlChar *qName = xmlSchemaFormatQName(&str, type->targetNamespace, type->name);
3205  if (!str)
3206  str = xmlStrdup(qName);
3207  }
3209  msg = xmlStrcat(msg, BAD_CAST "'.");
3210  FREE_AND_NULL(str);
3211  }
3212  } else {
3213  if (node->type == XML_ATTRIBUTE_NODE)
3214  msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not valid.");
3215  else
3216  msg = xmlStrcat(msg, BAD_CAST "The character content is not "
3217  "valid.");
3218  }
3219  if (expected) {
3220  xmlChar *expectedEscaped = xmlCharStrdup(expected);
3221  msg = xmlStrcat(msg, BAD_CAST " Expected is '");
3222  msg = xmlStrcat(msg, xmlEscapeFormatString(&expectedEscaped));
3223  FREE_AND_NULL(expectedEscaped);
3224  msg = xmlStrcat(msg, BAD_CAST "'.\n");
3225  } else
3226  msg = xmlStrcat(msg, BAD_CAST "\n");
3227  if (node->type == XML_ATTRIBUTE_NODE)
3228  xmlSchemaPErr(ctxt, node, error, (const char *) msg, value, NULL);
3229  else
3230  xmlSchemaPErr(ctxt, node, error, (const char *) msg, NULL, NULL);
3231  } else {
3233  msg = xmlStrcat(msg, BAD_CAST ".\n");
3234  xmlSchemaPErrExt(ctxt, node, error, NULL, NULL, NULL,
3235  (const char*) msg, str1, str2, NULL, NULL, NULL);
3236  }
3237  /* Cleanup. */
3238  FREE_AND_NULL(msg)
3239 }
3240 
3253 static void
3254 xmlSchemaPContentErr(xmlSchemaParserCtxtPtr ctxt,
3256  xmlSchemaBasicItemPtr ownerItem,
3257  xmlNodePtr ownerElem,
3258  xmlNodePtr child,
3259  const char *message,
3260  const char *content)
3261 {
3262  xmlChar *des = NULL;
3263 
3264  xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem);
3265  if (message != NULL)
3266  xmlSchemaPErr2(ctxt, ownerElem, child, error,
3267  "%s: %s.\n",
3269  else {
3270  if (content != NULL) {
3271  xmlSchemaPErr2(ctxt, ownerElem, child, error,
3272  "%s: The content is not valid. Expected is %s.\n",
3274  } else {
3275  xmlSchemaPErr2(ctxt, ownerElem, child, error,
3276  "%s: The content is not valid.\n",
3277  BAD_CAST des, NULL);
3278  }
3279  }
3280  FREE_AND_NULL(des)
3281 }
3282 
3283 /************************************************************************
3284  * *
3285  * Streamable error functions *
3286  * *
3287  ************************************************************************/
3288 
3289 
3290 
3291 
3292 /************************************************************************
3293  * *
3294  * Validation helper functions *
3295  * *
3296  ************************************************************************/
3297 
3298 
3299 /************************************************************************
3300  * *
3301  * Allocation functions *
3302  * *
3303  ************************************************************************/
3304 
3313 static xmlSchemaPtr
3314 xmlSchemaNewSchema(xmlSchemaParserCtxtPtr ctxt)
3315 {
3316  xmlSchemaPtr ret;
3317 
3318  ret = (xmlSchemaPtr) xmlMalloc(sizeof(xmlSchema));
3319  if (ret == NULL) {
3320  xmlSchemaPErrMemory(ctxt, "allocating schema", NULL);
3321  return (NULL);
3322  }
3323  memset(ret, 0, sizeof(xmlSchema));
3324  ret->dict = ctxt->dict;
3325  xmlDictReference(ret->dict);
3326 
3327  return (ret);
3328 }
3329 
3337 xmlSchemaFacetPtr
3338 xmlSchemaNewFacet(void)
3339 {
3340  xmlSchemaFacetPtr ret;
3341 
3342  ret = (xmlSchemaFacetPtr) xmlMalloc(sizeof(xmlSchemaFacet));
3343  if (ret == NULL) {
3344  return (NULL);
3345  }
3346  memset(ret, 0, sizeof(xmlSchemaFacet));
3347 
3348  return (ret);
3349 }
3350 
3360 static xmlSchemaAnnotPtr
3361 xmlSchemaNewAnnot(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node)
3362 {
3363  xmlSchemaAnnotPtr ret;
3364 
3365  ret = (xmlSchemaAnnotPtr) xmlMalloc(sizeof(xmlSchemaAnnot));
3366  if (ret == NULL) {
3367  xmlSchemaPErrMemory(ctxt, "allocating annotation", node);
3368  return (NULL);
3369  }
3370  memset(ret, 0, sizeof(xmlSchemaAnnot));
3371  ret->content = node;
3372  return (ret);
3373 }
3374 
3375 static xmlSchemaItemListPtr
3376 xmlSchemaItemListCreate(void)
3377 {
3378  xmlSchemaItemListPtr ret;
3379 
3380  ret = xmlMalloc(sizeof(xmlSchemaItemList));
3381  if (ret == NULL) {
3382  xmlSchemaPErrMemory(NULL,
3383  "allocating an item list structure", NULL);
3384  return (NULL);
3385  }
3386  memset(ret, 0, sizeof(xmlSchemaItemList));
3387  return (ret);
3388 }
3389 
3390 static void
3391 xmlSchemaItemListClear(xmlSchemaItemListPtr list)
3392 {
3393  if (list->items != NULL) {
3394  xmlFree(list->items);
3395  list->items = NULL;
3396  }
3397  list->nbItems = 0;
3398  list->sizeItems = 0;
3399 }
3400 
3401 static int
3402 xmlSchemaItemListAdd(xmlSchemaItemListPtr list, void *item)
3403 {
3404  if (list->items == NULL) {
3405  list->items = (void **) xmlMalloc(
3406  20 * sizeof(void *));
3407  if (list->items == NULL) {
3408  xmlSchemaPErrMemory(NULL, "allocating new item list", NULL);
3409  return(-1);
3410  }
3411  list->sizeItems = 20;
3412  } else if (list->sizeItems <= list->nbItems) {
3413  list->sizeItems *= 2;
3414  list->items = (void **) xmlRealloc(list->items,
3415  list->sizeItems * sizeof(void *));
3416  if (list->items == NULL) {
3417  xmlSchemaPErrMemory(NULL, "growing item list", NULL);
3418  list->sizeItems = 0;
3419  return(-1);
3420  }
3421  }
3422  list->items[list->nbItems++] = item;
3423  return(0);
3424 }
3425 
3426 static int
3427 xmlSchemaItemListAddSize(xmlSchemaItemListPtr list,
3428  int initialSize,
3429  void *item)
3430 {
3431  if (list->items == NULL) {
3432  if (initialSize <= 0)
3433  initialSize = 1;
3434  list->items = (void **) xmlMalloc(
3435  initialSize * sizeof(void *));
3436  if (list->items == NULL) {
3437  xmlSchemaPErrMemory(NULL, "allocating new item list", NULL);
3438  return(-1);
3439  }
3440  list->sizeItems = initialSize;
3441  } else if (list->sizeItems <= list->nbItems) {
3442  list->sizeItems *= 2;
3443  list->items = (void **) xmlRealloc(list->items,
3444  list->sizeItems * sizeof(void *));
3445  if (list->items == NULL) {
3446  xmlSchemaPErrMemory(NULL, "growing item list", NULL);
3447  list->sizeItems = 0;
3448  return(-1);
3449  }
3450  }
3451  list->items[list->nbItems++] = item;
3452  return(0);
3453 }
3454 
3455 static int
3456 xmlSchemaItemListInsert(xmlSchemaItemListPtr list, void *item, int idx)
3457 {
3458  if (list->items == NULL) {
3459  list->items = (void **) xmlMalloc(
3460  20 * sizeof(void *));
3461  if (list->items == NULL) {
3462  xmlSchemaPErrMemory(NULL, "allocating new item list", NULL);
3463  return(-1);
3464  }
3465  list->sizeItems = 20;
3466  } else if (list->sizeItems <= list->nbItems) {
3467  list->sizeItems *= 2;
3468  list->items = (void **) xmlRealloc(list->items,
3469  list->sizeItems * sizeof(void *));
3470  if (list->items == NULL) {
3471  xmlSchemaPErrMemory(NULL, "growing item list", NULL);
3472  list->sizeItems = 0;
3473  return(-1);
3474  }
3475  }
3476  /*
3477  * Just append if the index is greater/equal than the item count.
3478  */
3479  if (idx >= list->nbItems) {
3480  list->items[list->nbItems++] = item;
3481  } else {
3482  int i;
3483  for (i = list->nbItems; i > idx; i--)
3484  list->items[i] = list->items[i-1];
3485  list->items[idx] = item;
3486  list->nbItems++;
3487  }
3488  return(0);
3489 }
3490 
3491 #if 0 /* enable if ever needed */
3492 static int
3493 xmlSchemaItemListInsertSize(xmlSchemaItemListPtr list,
3494  int initialSize,
3495  void *item,
3496  int idx)
3497 {
3498  if (list->items == NULL) {
3499  if (initialSize <= 0)
3500  initialSize = 1;
3501  list->items = (void **) xmlMalloc(
3502  initialSize * sizeof(void *));
3503  if (list->items == NULL) {
3504  xmlSchemaPErrMemory(NULL, "allocating new item list", NULL);
3505  return(-1);
3506  }
3507  list->sizeItems = initialSize;
3508  } else if (list->sizeItems <= list->nbItems) {
3509  list->sizeItems *= 2;
3510  list->items = (void **) xmlRealloc(list->items,
3511  list->sizeItems * sizeof(void *));
3512  if (list->items == NULL) {
3513  xmlSchemaPErrMemory(NULL, "growing item list", NULL);
3514  list->sizeItems = 0;
3515  return(-1);
3516  }
3517  }
3518  /*
3519  * Just append if the index is greater/equal than the item count.
3520  */
3521  if (idx >= list->nbItems) {
3522  list->items[list->nbItems++] = item;
3523  } else {
3524  int i;
3525  for (i = list->nbItems; i > idx; i--)
3526  list->items[i] = list->items[i-1];
3527  list->items[idx] = item;
3528  list->nbItems++;
3529  }
3530  return(0);
3531 }
3532 #endif
3533 
3534 static int
3535 xmlSchemaItemListRemove(xmlSchemaItemListPtr list, int idx)
3536 {
3537  int i;
3538  if ((list->items == NULL) || (idx >= list->nbItems)) {
3539  xmlSchemaPSimpleErr("Internal error: xmlSchemaItemListRemove, "
3540  "index error.\n");
3541  return(-1);
3542  }
3543 
3544  if (list->nbItems == 1) {
3545  /* TODO: Really free the list? */
3546  xmlFree(list->items);
3547  list->items = NULL;
3548  list->nbItems = 0;
3549  list->sizeItems = 0;
3550  } else if (list->nbItems -1 == idx) {
3551  list->nbItems--;
3552  } else {
3553  for (i = idx; i < list->nbItems -1; i++)
3554  list->items[i] = list->items[i+1];
3555  list->nbItems--;
3556  }
3557  return(0);
3558 }
3559 
3566 static void
3567 xmlSchemaItemListFree(xmlSchemaItemListPtr list)
3568 {
3569  if (list == NULL)
3570  return;
3571  if (list->items != NULL)
3572  xmlFree(list->items);
3573  xmlFree(list);
3574 }
3575 
3576 static void
3577 xmlSchemaBucketFree(xmlSchemaBucketPtr bucket)
3578 {
3579  if (bucket == NULL)
3580  return;
3581  if (bucket->globals != NULL) {
3582  xmlSchemaComponentListFree(bucket->globals);
3583  xmlSchemaItemListFree(bucket->globals);
3584  }
3585  if (bucket->locals != NULL) {
3586  xmlSchemaComponentListFree(bucket->locals);
3587  xmlSchemaItemListFree(bucket->locals);
3588  }
3589  if (bucket->relations != NULL) {
3590  xmlSchemaSchemaRelationPtr prev, cur = bucket->relations;
3591  do {
3592  prev = cur;
3593  cur = cur->next;
3594  xmlFree(prev);
3595  } while (cur != NULL);
3596  }
3597  if ((! bucket->preserveDoc) && (bucket->doc != NULL)) {
3598  xmlFreeDoc(bucket->doc);
3599  }
3600  if (bucket->type == XML_SCHEMA_SCHEMA_IMPORT) {
3601  if (WXS_IMPBUCKET(bucket)->schema != NULL)
3602  xmlSchemaFree(WXS_IMPBUCKET(bucket)->schema);
3603  }
3604  xmlFree(bucket);
3605 }
3606 
3607 static void
3608 xmlSchemaBucketFreeEntry(void *bucket, const xmlChar *name ATTRIBUTE_UNUSED)
3609 {
3610  xmlSchemaBucketFree((xmlSchemaBucketPtr) bucket);
3611 }
3612 
3613 static xmlSchemaBucketPtr
3614 xmlSchemaBucketCreate(xmlSchemaParserCtxtPtr pctxt,
3615  int type, const xmlChar *targetNamespace)
3616 {
3617  xmlSchemaBucketPtr ret;
3618  int size;
3619  xmlSchemaPtr mainSchema;
3620 
3621  if (WXS_CONSTRUCTOR(pctxt)->mainSchema == NULL) {
3622  PERROR_INT("xmlSchemaBucketCreate",
3623  "no main schema on constructor");
3624  return(NULL);
3625  }
3626  mainSchema = WXS_CONSTRUCTOR(pctxt)->mainSchema;
3627  /* Create the schema bucket. */
3628  if (WXS_IS_BUCKET_INCREDEF(type))
3629  size = sizeof(xmlSchemaInclude);
3630  else
3631  size = sizeof(xmlSchemaImport);
3632  ret = (xmlSchemaBucketPtr) xmlMalloc(size);
3633  if (ret == NULL) {
3634  xmlSchemaPErrMemory(NULL, "allocating schema bucket", NULL);
3635  return(NULL);
3636  }
3637  memset(ret, 0, size);
3638  ret->targetNamespace = targetNamespace;
3639  ret->type = type;
3640  ret->globals = xmlSchemaItemListCreate();
3641  if (ret->globals == NULL) {
3642  xmlFree(ret);
3643  return(NULL);
3644  }
3645  ret->locals = xmlSchemaItemListCreate();
3646  if (ret->locals == NULL) {
3647  xmlFree(ret);
3648  return(NULL);
3649  }
3650  /*
3651  * The following will assure that only the first bucket is marked as
3652  * XML_SCHEMA_SCHEMA_MAIN and it points to the *main* schema.
3653  * For each following import buckets an xmlSchema will be created.
3654  * An xmlSchema will be created for every distinct targetNamespace.
3655  * We assign the targetNamespace to the schemata here.
3656  */
3657  if (! WXS_HAS_BUCKETS(pctxt)) {
3658  if (WXS_IS_BUCKET_INCREDEF(type)) {
3659  PERROR_INT("xmlSchemaBucketCreate",
3660  "first bucket but it's an include or redefine");
3661  xmlSchemaBucketFree(ret);
3662  return(NULL);
3663  }
3664  /* Force the type to be XML_SCHEMA_SCHEMA_MAIN. */
3665  ret->type = XML_SCHEMA_SCHEMA_MAIN;
3666  /* Point to the *main* schema. */
3667  WXS_CONSTRUCTOR(pctxt)->mainBucket = ret;
3668  WXS_IMPBUCKET(ret)->schema = mainSchema;
3669  /*
3670  * Ensure that the main schema gets a targetNamespace.
3671  */
3672  mainSchema->targetNamespace = targetNamespace;
3673  } else {
3674  if (type == XML_SCHEMA_SCHEMA_MAIN) {
3675  PERROR_INT("xmlSchemaBucketCreate",
3676  "main bucket but it's not the first one");
3677  xmlSchemaBucketFree(ret);
3678  return(NULL);
3679  } else if (type == XML_SCHEMA_SCHEMA_IMPORT) {
3680  /*
3681  * Create a schema for imports and assign the
3682  * targetNamespace.
3683  */
3684  WXS_IMPBUCKET(ret)->schema = xmlSchemaNewSchema(pctxt);
3685  if (WXS_IMPBUCKET(ret)->schema == NULL) {
3686  xmlSchemaBucketFree(ret);
3687  return(NULL);
3688  }
3689  WXS_IMPBUCKET(ret)->schema->targetNamespace = targetNamespace;
3690  }
3691  }
3692  if (WXS_IS_BUCKET_IMPMAIN(type)) {
3693  int res;
3694  /*
3695  * Imports go into the "schemasImports" slot of the main *schema*.
3696  * Note that we create an import entry for the main schema as well; i.e.,
3697  * even if there's only one schema, we'll get an import.
3698  */
3699  if (mainSchema->schemasImports == NULL) {
3700  mainSchema->schemasImports = xmlHashCreateDict(5,
3701  WXS_CONSTRUCTOR(pctxt)->dict);
3702  if (mainSchema->schemasImports == NULL) {
3703  xmlSchemaBucketFree(ret);
3704  return(NULL);
3705  }
3706  }
3707  if (targetNamespace == NULL)
3708  res = xmlHashAddEntry(mainSchema->schemasImports,
3709  XML_SCHEMAS_NO_NAMESPACE, ret);
3710  else
3711  res = xmlHashAddEntry(mainSchema->schemasImports,
3712  targetNamespace, ret);
3713  if (res != 0) {
3714  PERROR_INT("xmlSchemaBucketCreate",
3715  "failed to add the schema bucket to the hash");
3716  xmlSchemaBucketFree(ret);
3717  return(NULL);
3718  }
3719  } else {
3720  /* Set the @ownerImport of an include bucket. */
3721  if (WXS_IS_BUCKET_IMPMAIN(WXS_CONSTRUCTOR(pctxt)->bucket->type))
3722  WXS_INCBUCKET(ret)->ownerImport =
3723  WXS_IMPBUCKET(WXS_CONSTRUCTOR(pctxt)->bucket);
3724  else
3725  WXS_INCBUCKET(ret)->ownerImport =
3726  WXS_INCBUCKET(WXS_CONSTRUCTOR(pctxt)->bucket)->ownerImport;
3727 
3728  /* Includes got into the "includes" slot of the *main* schema. */
3729  if (mainSchema->includes == NULL) {
3730  mainSchema->includes = xmlSchemaItemListCreate();
3731  if (mainSchema->includes == NULL) {
3732  xmlSchemaBucketFree(ret);
3733  return(NULL);
3734  }
3735  }
3736  xmlSchemaItemListAdd(mainSchema->includes, ret);
3737  }
3738  /*
3739  * Add to list of all buckets; this is used for lookup
3740  * during schema construction time only.
3741  */
3742  if (xmlSchemaItemListAdd(WXS_CONSTRUCTOR(pctxt)->buckets, ret) == -1)
3743  return(NULL);
3744  return(ret);
3745 }
3746 
3747 static int
3748 xmlSchemaAddItemSize(xmlSchemaItemListPtr *list, int initialSize, void *item)
3749 {
3750  if (*list == NULL) {
3751  *list = xmlSchemaItemListCreate();
3752  if (*list == NULL)
3753  return(-1);
3754  }
3755  xmlSchemaItemListAddSize(*list, initialSize, item);
3756  return(0);
3757 }
3758 
3765 static void
3766 xmlSchemaFreeAnnot(xmlSchemaAnnotPtr annot)
3767 {
3768  if (annot == NULL)
3769  return;
3770  if (annot->next == NULL) {
3771  xmlFree(annot);
3772  } else {
3773  xmlSchemaAnnotPtr prev;
3774 
3775  do {
3776  prev = annot;
3777  annot = annot->next;
3778  xmlFree(prev);
3779  } while (annot != NULL);
3780  }
3781 }
3782 
3789 static void
3790 xmlSchemaFreeNotation(xmlSchemaNotationPtr nota)
3791 {
3792  if (nota == NULL)
3793  return;
3794  xmlFree(nota);
3795 }
3796 
3803 static void
3804 xmlSchemaFreeAttribute(xmlSchemaAttributePtr attr)
3805 {
3806  if (attr == NULL)
3807  return;
3808  if (attr->annot != NULL)
3809  xmlSchemaFreeAnnot(attr->annot);
3810  if (attr->defVal != NULL)
3811  xmlSchemaFreeValue(attr->defVal);
3812  xmlFree(attr);
3813 }
3814 
3821 static void
3822 xmlSchemaFreeAttributeUse(xmlSchemaAttributeUsePtr use)
3823 {
3824  if (use == NULL)
3825  return;
3826  if (use->annot != NULL)
3827  xmlSchemaFreeAnnot(use->annot);
3828  if (use->defVal != NULL)
3829  xmlSchemaFreeValue(use->defVal);
3830  xmlFree(use);
3831 }
3832 
3839 static void
3840 xmlSchemaFreeAttributeUseProhib(xmlSchemaAttributeUseProhibPtr prohib)
3841 {
3842  if (prohib == NULL)
3843  return;
3844  xmlFree(prohib);
3845 }
3846 
3853 static void
3854 xmlSchemaFreeWildcardNsSet(xmlSchemaWildcardNsPtr set)
3855 {
3856  xmlSchemaWildcardNsPtr next;
3857 
3858  while (set != NULL) {
3859  next = set->next;
3860  xmlFree(set);
3861  set = next;
3862  }
3863 }
3864 
3871 void
3872 xmlSchemaFreeWildcard(xmlSchemaWildcardPtr wildcard)
3873 {
3874  if (wildcard == NULL)
3875  return;
3876  if (wildcard->annot != NULL)
3877  xmlSchemaFreeAnnot(wildcard->annot);
3878  if (wildcard->nsSet != NULL)
3879  xmlSchemaFreeWildcardNsSet(wildcard->nsSet);
3880  if (wildcard->negNsSet != NULL)
3881  xmlFree(wildcard->negNsSet);
3882  xmlFree(wildcard);
3883 }
3884 
3891 static void
3892 xmlSchemaFreeAttributeGroup(xmlSchemaAttributeGroupPtr attrGr)
3893 {
3894  if (attrGr == NULL)
3895  return;
3896  if (attrGr->annot != NULL)
3897  xmlSchemaFreeAnnot(attrGr->annot);
3898  if (attrGr->attrUses != NULL)
3899  xmlSchemaItemListFree(WXS_LIST_CAST attrGr->attrUses);
3900  xmlFree(attrGr);
3901 }
3902 
3909 static void
3910 xmlSchemaFreeQNameRef(xmlSchemaQNameRefPtr item)
3911 {
3912  xmlFree(item);
3913 }
3914 
3921 static void
3922 xmlSchemaFreeTypeLinkList(xmlSchemaTypeLinkPtr link)
3923 {
3924  xmlSchemaTypeLinkPtr next;
3925 
3926  while (link != NULL) {
3927  next = link->next;
3928  xmlFree(link);
3929  link = next;
3930  }
3931 }
3932 
3933 static void
3934 xmlSchemaFreeIDCStateObjList(xmlSchemaIDCStateObjPtr sto)
3935 {
3936  xmlSchemaIDCStateObjPtr next;
3937  while (sto != NULL) {
3938  next = sto->next;
3939  if (sto->history != NULL)
3940  xmlFree(sto->history);
3941  if (sto->xpathCtxt != NULL)
3942  xmlFreeStreamCtxt((xmlStreamCtxtPtr) sto->xpathCtxt);
3943  xmlFree(sto);
3944  sto = next;
3945  }
3946 }
3947 
3954 static void
3955 xmlSchemaFreeIDC(xmlSchemaIDCPtr idcDef)
3956 {
3957  xmlSchemaIDCSelectPtr cur, prev;
3958 
3959  if (idcDef == NULL)
3960  return;
3961  if (idcDef->annot != NULL)
3962  xmlSchemaFreeAnnot(idcDef->annot);
3963  /* Selector */
3964  if (idcDef->selector != NULL) {
3965  if (idcDef->selector->xpathComp != NULL)
3966  xmlFreePattern((xmlPatternPtr) idcDef->selector->xpathComp);
3967  xmlFree(idcDef->selector);
3968  }
3969  /* Fields */
3970  if (idcDef->fields != NULL) {
3971  cur = idcDef->fields;
3972  do {
3973  prev = cur;
3974  cur = cur->next;
3975  if (prev->xpathComp != NULL)
3976  xmlFreePattern((xmlPatternPtr) prev->xpathComp);
3977  xmlFree(prev);
3978  } while (cur != NULL);
3979  }
3980  xmlFree(idcDef);
3981 }
3982 
3989 static void
3990 xmlSchemaFreeElement(xmlSchemaElementPtr elem)
3991 {
3992  if (elem == NULL)
3993  return;
3994  if (elem->annot != NULL)
3995  xmlSchemaFreeAnnot(elem->annot);
3996  if (elem->contModel != NULL)
3997  xmlRegFreeRegexp(elem->contModel);
3998  if (elem->defVal != NULL)
3999  xmlSchemaFreeValue(elem->defVal);
4000  xmlFree(elem);
4001 }
4002 
4009 void
4010 xmlSchemaFreeFacet(xmlSchemaFacetPtr facet)
4011 {
4012  if (facet == NULL)
4013  return;
4014  if (facet->val != NULL)
4015  xmlSchemaFreeValue(facet->val);
4016  if (facet->regexp != NULL)
4017  xmlRegFreeRegexp(facet->regexp);
4018  if (facet->annot != NULL)
4019  xmlSchemaFreeAnnot(facet->annot);
4020  xmlFree(facet);
4021 }
4022 
4029 void
4030 xmlSchemaFreeType(xmlSchemaTypePtr type)
4031 {
4032  if (type == NULL)
4033  return;
4034  if (type->annot != NULL)
4035  xmlSchemaFreeAnnot(type->annot);
4036  if (type->facets != NULL) {
4037  xmlSchemaFacetPtr facet, next;
4038 
4039  facet = type->facets;
4040  while (facet != NULL) {
4041  next = facet->next;
4042  xmlSchemaFreeFacet(facet);
4043  facet = next;
4044  }
4045  }
4046  if (type->attrUses != NULL)
4047  xmlSchemaItemListFree((xmlSchemaItemListPtr) type->attrUses);
4048  if (type->memberTypes != NULL)
4049  xmlSchemaFreeTypeLinkList(type->memberTypes);
4050  if (type->facetSet != NULL) {
4051  xmlSchemaFacetLinkPtr next, link;
4052 
4053  link = type->facetSet;
4054  do {
4055  next = link->next;
4056  xmlFree(link);
4057  link = next;
4058  } while (link != NULL);
4059  }
4060  if (type->contModel != NULL)
4061  xmlRegFreeRegexp(type->contModel);
4062  xmlFree(type);
4063 }
4064 
4071 static void
4072 xmlSchemaFreeModelGroupDef(xmlSchemaModelGroupDefPtr item)
4073 {
4074  if (item->annot != NULL)
4075  xmlSchemaFreeAnnot(item->annot);
4076  xmlFree(item);
4077 }
4078 
4085 static void
4086 xmlSchemaFreeModelGroup(xmlSchemaModelGroupPtr item)
4087 {
4088  if (item->annot != NULL)
4089  xmlSchemaFreeAnnot(item->annot);
4090  xmlFree(item);
4091 }
4092 
4093 static void
4094 xmlSchemaComponentListFree(xmlSchemaItemListPtr list)
4095 {
4096  if ((list == NULL) || (list->nbItems == 0))
4097  return;
4098  {
4099  xmlSchemaTreeItemPtr item;
4100  xmlSchemaTreeItemPtr *items = (xmlSchemaTreeItemPtr *) list->items;
4101  int i;
4102 
4103  for (i = 0; i < list->nbItems; i++) {
4104  item = items[i];
4105  if (item == NULL)
4106  continue;
4107  switch (item->type) {
4108  case XML_SCHEMA_TYPE_SIMPLE:
4109  case XML_SCHEMA_TYPE_COMPLEX:
4110  xmlSchemaFreeType((xmlSchemaTypePtr) item);
4111  break;
4112  case XML_SCHEMA_TYPE_ATTRIBUTE:
4113  xmlSchemaFreeAttribute((xmlSchemaAttributePtr) item);
4114  break;
4115  case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
4116  xmlSchemaFreeAttributeUse((xmlSchemaAttributeUsePtr) item);
4117  break;
4118  case XML_SCHEMA_EXTRA_ATTR_USE_PROHIB:
4119  xmlSchemaFreeAttributeUseProhib(
4120  (xmlSchemaAttributeUseProhibPtr) item);
4121  break;
4122  case XML_SCHEMA_TYPE_ELEMENT:
4123  xmlSchemaFreeElement((xmlSchemaElementPtr) item);
4124  break;
4125  case XML_SCHEMA_TYPE_PARTICLE:
4126  if (item->annot != NULL)
4127  xmlSchemaFreeAnnot(item->annot);
4128  xmlFree(item);
4129  break;
4130  case XML_SCHEMA_TYPE_SEQUENCE:
4131  case XML_SCHEMA_TYPE_CHOICE:
4132  case XML_SCHEMA_TYPE_ALL:
4133  xmlSchemaFreeModelGroup((xmlSchemaModelGroupPtr) item);
4134  break;
4135  case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
4136  xmlSchemaFreeAttributeGroup(
4137  (xmlSchemaAttributeGroupPtr) item);
4138  break;
4139  case XML_SCHEMA_TYPE_GROUP:
4140  xmlSchemaFreeModelGroupDef(
4141  (xmlSchemaModelGroupDefPtr) item);
4142  break;
4143  case XML_SCHEMA_TYPE_ANY:
4144  case XML_SCHEMA_TYPE_ANY_ATTRIBUTE:
4145  xmlSchemaFreeWildcard((xmlSchemaWildcardPtr) item);
4146  break;
4147  case XML_SCHEMA_TYPE_IDC_KEY:
4148  case XML_SCHEMA_TYPE_IDC_UNIQUE:
4149  case XML_SCHEMA_TYPE_IDC_KEYREF:
4150  xmlSchemaFreeIDC((xmlSchemaIDCPtr) item);
4151  break;
4152  case XML_SCHEMA_TYPE_NOTATION:
4153  xmlSchemaFreeNotation((xmlSchemaNotationPtr) item);
4154  break;
4155  case XML_SCHEMA_EXTRA_QNAMEREF:
4156  xmlSchemaFreeQNameRef((xmlSchemaQNameRefPtr) item);
4157  break;
4158  default: {
4159  /* TODO: This should never be hit. */
4160  xmlSchemaPSimpleInternalErr(NULL,
4161  "Internal error: xmlSchemaComponentListFree, "
4162  "unexpected component type '%s'\n",
4163  (const xmlChar *) WXS_ITEM_TYPE_NAME(item));
4164  }
4165  break;
4166  }
4167  }
4168  list->nbItems = 0;
4169  }
4170 }
4171 
4178 void
4179 xmlSchemaFree(xmlSchemaPtr schema)
4180 {
4181  if (schema == NULL)
4182  return;
4183  /* @volatiles is not used anymore :-/ */
4184  if (schema->volatiles != NULL)
4185  TODO
4186  /*
4187  * Note that those slots are not responsible for freeing
4188  * schema components anymore; this will now be done by
4189  * the schema buckets.
4190  */
4191  if (schema->notaDecl != NULL)
4192  xmlHashFree(schema->notaDecl, NULL);
4193  if (schema->attrDecl != NULL)
4194  xmlHashFree(schema->attrDecl, NULL);
4195  if (schema->attrgrpDecl != NULL)
4196  xmlHashFree(schema->attrgrpDecl, NULL);
4197  if (schema->elemDecl != NULL)
4198  xmlHashFree(schema->elemDecl, NULL);
4199  if (schema->typeDecl != NULL)
4200  xmlHashFree(schema->typeDecl, NULL);
4201  if (schema->groupDecl != NULL)
4202  xmlHashFree(schema->groupDecl, NULL);
4203  if (schema->idcDef != NULL)
4204  xmlHashFree(schema->idcDef, NULL);
4205 
4206  if (schema->schemasImports != NULL)
4207  xmlHashFree(schema->schemasImports, xmlSchemaBucketFreeEntry);
4208  if (schema->includes != NULL) {
4209  xmlSchemaItemListPtr list = (xmlSchemaItemListPtr) schema->includes;
4210  int i;
4211  for (i = 0; i < list->nbItems; i++) {
4212  xmlSchemaBucketFree((xmlSchemaBucketPtr) list->items[i]);
4213  }
4214  xmlSchemaItemListFree(list);
4215  }
4216  if (schema->annot != NULL)
4217  xmlSchemaFreeAnnot(schema->annot);
4218  /* Never free the doc here, since this will be done by the buckets. */
4219 
4220  xmlDictFree(schema->dict);
4221  xmlFree(schema);
4222 }
4223 
4224 /************************************************************************
4225  * *
4226  * Debug functions *
4227  * *
4228  ************************************************************************/
4229 
4230 #ifdef LIBXML_OUTPUT_ENABLED
4231 
4232 static void
4233 xmlSchemaTypeDump(xmlSchemaTypePtr type, FILE * output); /* forward */
4234 
4242 static void
4243 xmlSchemaElementDump(void *payload, void *data,
4244  const xmlChar * name ATTRIBUTE_UNUSED,
4245  const xmlChar * namespace ATTRIBUTE_UNUSED,
4247 {
4248  xmlSchemaElementPtr elem = (xmlSchemaElementPtr) payload;
4249  FILE *output = (FILE *) data;
4250  if (elem == NULL)
4251  return;
4252 
4253 
4254  fprintf(output, "Element");
4255  if (elem->flags & XML_SCHEMAS_ELEM_GLOBAL)
4256  fprintf(output, " (global)");
4257  fprintf(output, ": '%s' ", elem->name);
4258  if (namespace != NULL)
4259  fprintf(output, "ns '%s'", namespace);
4260  fprintf(output, "\n");
4261 #if 0
4262  if ((elem->minOccurs != 1) || (elem->maxOccurs != 1)) {
4263  fprintf(output, " min %d ", elem->minOccurs);
4264  if (elem->maxOccurs >= UNBOUNDED)
4265  fprintf(output, "max: unbounded\n");
4266  else if (elem->maxOccurs != 1)
4267  fprintf(output, "max: %d\n", elem->maxOccurs);
4268  else
4269  fprintf(output, "\n");
4270  }
4271 #endif
4272  /*
4273  * Misc other properties.
4274  */
4275  if ((elem->flags & XML_SCHEMAS_ELEM_NILLABLE) ||
4276  (elem->flags & XML_SCHEMAS_ELEM_ABSTRACT) ||
4277  (elem->flags & XML_SCHEMAS_ELEM_FIXED) ||
4278  (elem->flags & XML_SCHEMAS_ELEM_DEFAULT)) {
4279  fprintf(output, " props: ");
4280  if (elem->flags & XML_SCHEMAS_ELEM_FIXED)
4281  fprintf(output, "[fixed] ");
4282  if (elem->flags & XML_SCHEMAS_ELEM_DEFAULT)
4283  fprintf(output, "[default] ");
4284  if (elem->flags & XML_SCHEMAS_ELEM_ABSTRACT)
4285  fprintf(output, "[abstract] ");
4286  if (elem->flags & XML_SCHEMAS_ELEM_NILLABLE)
4287  fprintf(output, "[nillable] ");
4288  fprintf(output, "\n");
4289  }
4290  /*
4291  * Default/fixed value.
4292  */
4293  if (elem->value != NULL)
4294  fprintf(output, " value: '%s'\n", elem->value);
4295  /*
4296  * Type.
4297  */
4298  if (elem->namedType != NULL) {
4299  fprintf(output, " type: '%s' ", elem->namedType);
4300  if (elem->namedTypeNs != NULL)
4301  fprintf(output, "ns '%s'\n", elem->namedTypeNs);
4302  else
4303  fprintf(output, "\n");
4304  } else if (elem->subtypes != NULL) {
4305  /*
4306  * Dump local types.
4307  */
4308  xmlSchemaTypeDump(elem->subtypes, output);
4309  }
4310  /*
4311  * Substitution group.
4312  */
4313  if (elem->substGroup != NULL) {
4314  fprintf(output, " substitutionGroup: '%s' ", elem->substGroup);
4315  if (elem->substGroupNs != NULL)
4316  fprintf(output, "ns '%s'\n", elem->substGroupNs);
4317  else
4318  fprintf(output, "\n");
4319  }
4320 }
4321 
4329 static void
4330 xmlSchemaAnnotDump(FILE * output, xmlSchemaAnnotPtr annot)
4331 {
4332  xmlChar *content;
4333 
4334  if (annot == NULL)
4335  return;
4336 
4337  content = xmlNodeGetContent(annot->content);
4338  if (content != NULL) {
4339  fprintf(output, " Annot: %s\n", content);
4340  xmlFree(content);
4341  } else
4342  fprintf(output, " Annot: empty\n");
4343 }
4344 
4353 static void
4354 xmlSchemaContentModelDump(xmlSchemaParticlePtr particle, FILE * output, int depth)
4355 {
4356  xmlChar *str = NULL;
4357  xmlSchemaTreeItemPtr term;
4358  char shift[100];
4359  int i;
4360 
4361  if (particle == NULL)
4362  return;
4363  for (i = 0;((i < depth) && (i < 25));i++)
4364  shift[2 * i] = shift[2 * i + 1] = ' ';
4365  shift[2 * i] = shift[2 * i + 1] = 0;
4366  fprintf(output, "%s", shift);
4367  if (particle->children == NULL) {
4368  fprintf(output, "MISSING particle term\n");
4369  return;
4370  }
4371  term = particle->children;
4372  if (term == NULL) {
4373  fprintf(output, "(NULL)");
4374  } else {
4375  switch (term->type) {
4376  case XML_SCHEMA_TYPE_ELEMENT:
4377  fprintf(output, "ELEM '%s'", xmlSchemaFormatQName(&str,
4378  ((xmlSchemaElementPtr)term)->targetNamespace,
4379  ((xmlSchemaElementPtr)term)->name));
4380  FREE_AND_NULL(str);
4381  break;
4382  case XML_SCHEMA_TYPE_SEQUENCE:
4383  fprintf(output, "SEQUENCE");
4384  break;
4385  case XML_SCHEMA_TYPE_CHOICE:
4386  fprintf(output, "CHOICE");
4387  break;
4388  case XML_SCHEMA_TYPE_ALL:
4389  fprintf(output, "ALL");
4390  break;
4391  case XML_SCHEMA_TYPE_ANY:
4392  fprintf(output, "ANY");
4393  break;
4394  default:
4395  fprintf(output, "UNKNOWN\n");
4396  return;
4397  }
4398  }
4399  if (particle->minOccurs != 1)
4400  fprintf(output, " min: %d", particle->minOccurs);
4401  if (particle->maxOccurs >= UNBOUNDED)
4402  fprintf(output, " max: unbounded");
4403  else if (particle->maxOccurs != 1)
4404  fprintf(output, " max: %d", particle->maxOccurs);
4405  fprintf(output, "\n");
4406  if (term &&
4407  ((term->type == XML_SCHEMA_TYPE_SEQUENCE) ||
4408  (term->type == XML_SCHEMA_TYPE_CHOICE) ||
4409  (term->type == XML_SCHEMA_TYPE_ALL)) &&
4410  (term->children != NULL)) {
4411  xmlSchemaContentModelDump((xmlSchemaParticlePtr) term->children,
4412  output, depth +1);
4413  }
4414  if (particle->next != NULL)
4415  xmlSchemaContentModelDump((xmlSchemaParticlePtr) particle->next,
4416  output, depth);
4417 }
4418 
4426 static void
4427 xmlSchemaAttrUsesDump(xmlSchemaItemListPtr uses, FILE * output)
4428 {
4429  xmlSchemaAttributeUsePtr use;
4430  xmlSchemaAttributeUseProhibPtr prohib;
4431  xmlSchemaQNameRefPtr ref;
4432  const xmlChar *name, *tns;
4433  xmlChar *str = NULL;
4434  int i;
4435 
4436  if ((uses == NULL) || (uses->nbItems == 0))
4437  return;
4438 
4439  fprintf(output, " attributes:\n");
4440  for (i = 0; i < uses->nbItems; i++) {
4441  use = uses->items[i];
4442  if (use->type == XML_SCHEMA_EXTRA_ATTR_USE_PROHIB) {
4443  fprintf(output, " [prohibition] ");
4444  prohib = (xmlSchemaAttributeUseProhibPtr) use;
4445  name = prohib->name;
4446  tns = prohib->targetNamespace;
4447  } else if (use->type == XML_SCHEMA_EXTRA_QNAMEREF) {
4448  fprintf(output, " [reference] ");
4449  ref = (xmlSchemaQNameRefPtr) use;
4450  name = ref->name;
4451  tns = ref->targetNamespace;
4452  } else {
4453  fprintf(output, " [use] ");
4454  name = WXS_ATTRUSE_DECL_NAME(use);
4455  tns = WXS_ATTRUSE_DECL_TNS(use);
4456  }
4457  fprintf(output, "'%s'\n",
4458  (const char *) xmlSchemaFormatQName(&str, tns, name));
4459  FREE_AND_NULL(str);
4460  }
4461 }
4462 
4470 static void
4471 xmlSchemaTypeDump(xmlSchemaTypePtr type, FILE * output)
4472 {
4473  if (type == NULL) {
4474  fprintf(output, "Type: NULL\n");
4475  return;
4476  }
4477  fprintf(output, "Type: ");
4478  if (type->name != NULL)
4479  fprintf(output, "'%s' ", type->name);
4480  else
4481  fprintf(output, "(no name) ");
4482  if (type->targetNamespace != NULL)
4483  fprintf(output, "ns '%s' ", type->targetNamespace);
4484  switch (type->type) {
4485  case XML_SCHEMA_TYPE_BASIC:
4486  fprintf(output, "[basic] ");
4487  break;
4488  case XML_SCHEMA_TYPE_SIMPLE:
4489  fprintf(output, "[simple] ");
4490  break;
4491  case XML_SCHEMA_TYPE_COMPLEX:
4492  fprintf(output, "[complex] ");
4493  break;
4494  case XML_SCHEMA_TYPE_SEQUENCE:
4495  fprintf(output, "[sequence] ");
4496  break;
4497  case XML_SCHEMA_TYPE_CHOICE:
4498  fprintf(output, "[choice] ");
4499  break;
4500  case XML_SCHEMA_TYPE_ALL:
4501  fprintf(output, "[all] ");
4502  break;
4503  case XML_SCHEMA_TYPE_UR:
4504  fprintf(output, "[ur] ");
4505  break;
4506  case XML_SCHEMA_TYPE_RESTRICTION:
4507  fprintf(output, "[restriction] ");
4508  break;
4509  case XML_SCHEMA_TYPE_EXTENSION:
4510  fprintf(output, "[extension] ");
4511  break;
4512  default:
4513  fprintf(output, "[unknown type %d] ", type->type);
4514  break;
4515  }
4516  fprintf(output, "content: ");
4517  switch (type->contentType) {
4518  case XML_SCHEMA_CONTENT_UNKNOWN:
4519  fprintf(output, "[unknown] ");
4520  break;
4521  case XML_SCHEMA_CONTENT_EMPTY:
4522  fprintf(output, "[empty] ");
4523  break;
4524  case XML_SCHEMA_CONTENT_ELEMENTS:
4525  fprintf(output, "[element] ");
4526  break;
4527  case XML_SCHEMA_CONTENT_MIXED:
4528  fprintf(output, "[mixed] ");
4529  break;
4530  case XML_SCHEMA_CONTENT_MIXED_OR_ELEMENTS:
4531  /* not used. */
4532  break;
4533  case XML_SCHEMA_CONTENT_BASIC:
4534  fprintf(output, "[basic] ");
4535  break;
4536  case XML_SCHEMA_CONTENT_SIMPLE:
4537  fprintf(output, "[simple] ");
4538  break;
4539  case XML_SCHEMA_CONTENT_ANY:
4540  fprintf(output, "[any] ");
4541  break;
4542  }
4543  fprintf(output, "\n");
4544  if (type->base != NULL) {
4545  fprintf(output, " base type: '%s'", type->base);
4546  if (type->baseNs != NULL)
4547  fprintf(output, " ns '%s'\n", type->baseNs);
4548  else
4549  fprintf(output, "\n");
4550  }
4551  if (type->attrUses != NULL)
4552  xmlSchemaAttrUsesDump(type->attrUses, output);
4553  if (type->annot != NULL)
4554  xmlSchemaAnnotDump(output, type->annot);
4555 #ifdef DUMP_CONTENT_MODEL
4556  if ((type->type == XML_SCHEMA_TYPE_COMPLEX) &&
4557  (type->subtypes != NULL)) {
4558  xmlSchemaContentModelDump((xmlSchemaParticlePtr) type->subtypes,
4559  output, 1);
4560  }
4561 #endif
4562 }
4563 
4564 static void
4565 xmlSchemaTypeDumpEntry(void *type, void *output,
4566  const xmlChar *name ATTRIBUTE_UNUSED)
4567 {
4568  xmlSchemaTypeDump((xmlSchemaTypePtr) type, (FILE *) output);
4569 }
4570 
4578 void
4579 xmlSchemaDump(FILE * output, xmlSchemaPtr schema)
4580 {
4581  if (output == NULL)
4582  return;
4583  if (schema == NULL) {
4584  fprintf(output, "Schemas: NULL\n");
4585  return;
4586  }
4587  fprintf(output, "Schemas: ");
4588  if (schema->name != NULL)
4589  fprintf(output, "%s, ", schema->name);
4590  else
4591  fprintf(output, "no name, ");
4592  if (schema->targetNamespace != NULL)
4593  fprintf(output, "%s", (const char *) schema->targetNamespace);
4594  else
4595  fprintf(output, "no target namespace");
4596  fprintf(output, "\n");
4597  if (schema->annot != NULL)
4598  xmlSchemaAnnotDump(output, schema->annot);
4599  xmlHashScan(schema->typeDecl, xmlSchemaTypeDumpEntry, output);
4600  xmlHashScanFull(schema->elemDecl, xmlSchemaElementDump, output);
4601 }
4602 
4603 #ifdef DEBUG_IDC_NODE_TABLE
4604 
4610 static void
4611 xmlSchemaDebugDumpIDCTable(FILE * output,
4612  const xmlChar *namespaceName,
4613  const xmlChar *localName,
4614  xmlSchemaPSVIIDCBindingPtr bind)
4615 {
4616  xmlChar *str = NULL;
4617  const xmlChar *value;
4618  xmlSchemaPSVIIDCNodePtr tab;
4619  xmlSchemaPSVIIDCKeyPtr key;
4620  int i, j, res;
4621 
4622  fprintf(output, "IDC: TABLES on '%s'\n",
4623  xmlSchemaFormatQName(&str, namespaceName, localName));
4624  FREE_AND_NULL(str)
4625 
4626  if (bind == NULL)
4627  return;
4628  do {
4629  fprintf(output, "IDC: BINDING '%s' (%d)\n",
4630  xmlSchemaGetComponentQName(&str,
4631  bind->definition), bind->nbNodes);
4632  FREE_AND_NULL(str)
4633  for (i = 0; i < bind->nbNodes; i++) {
4634  tab = bind->nodeTable[i];
4635  fprintf(output, " ( ");
4636  for (j = 0; j < bind->definition->nbFields; j++) {
4637  key = tab->keys[j];
4638  if ((key != NULL) && (key->val != NULL)) {
4639  res = xmlSchemaGetCanonValue(key->val, &value);
4640  if (res >= 0)
4641  fprintf(output, "'%s' ", value);
4642  else
4643  fprintf(output, "CANON-VALUE-FAILED ");
4644  if (res == 0)
4645  FREE_AND_NULL(value)
4646  } else if (key != NULL)
4647  fprintf(output, "(no val), ");
4648  else
4649  fprintf(output, "(key missing), ");
4650  }
4651  fprintf(output, ")\n");
4652  }
4653  if (bind->dupls && bind->dupls->nbItems) {
4654  fprintf(output, "IDC: dupls (%d):\n", bind->dupls->nbItems);
4655  for (i = 0; i < bind->dupls->nbItems; i++) {
4656  tab = bind->dupls->items[i];
4657  fprintf(output, " ( ");
4658  for (j = 0; j < bind->definition->nbFields; j++) {
4659  key = tab->keys[j];
4660  if ((key != NULL) && (key->val != NULL)) {
4661  res = xmlSchemaGetCanonValue(key->val, &value);
4662  if (res >= 0)
4663  fprintf(output, "'%s' ", value);
4664  else
4665  fprintf(output, "CANON-VALUE-FAILED ");
4666  if (res == 0)
4667  FREE_AND_NULL(value)
4668  } else if (key != NULL)
4669  fprintf(output, "(no val), ");
4670  else
4671  fprintf(output, "(key missing), ");
4672  }
4673  fprintf(output, ")\n");
4674  }
4675  }
4676  bind = bind->next;
4677  } while (bind != NULL);
4678 }
4679 #endif /* DEBUG_IDC */
4680 #endif /* LIBXML_OUTPUT_ENABLED */
4681 
4682 /************************************************************************
4683  * *
4684  * Utilities *
4685  * *
4686  ************************************************************************/
4687 
4698 static xmlAttrPtr
4699 xmlSchemaGetPropNode(xmlNodePtr node, const char *name)
4700 {
4701  xmlAttrPtr prop;
4702 
4703  if ((node == NULL) || (name == NULL))
4704  return(NULL);
4705  prop = node->properties;
4706  while (prop != NULL) {
4707  if ((prop->ns == NULL) && xmlStrEqual(prop->name, BAD_CAST name))
4708  return(prop);
4709  prop = prop->next;
4710  }
4711  return (NULL);
4712 }
4713 
4725 static xmlAttrPtr
4726 xmlSchemaGetPropNodeNs(xmlNodePtr node, const char *uri, const char *name)
4727 {
4728  xmlAttrPtr prop;
4729 
4730  if ((node == NULL) || (name == NULL))
4731  return(NULL);
4732  prop = node->properties;
4733  while (prop != NULL) {
4734  if ((prop->ns != NULL) &&
4735  xmlStrEqual(prop->name, BAD_CAST name) &&
4736  xmlStrEqual(prop->ns->href, BAD_CAST uri))
4737  return(prop);
4738  prop = prop->next;
4739  }
4740  return (NULL);
4741 }
4742 
4743 static const xmlChar *
4744 xmlSchemaGetNodeContent(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node)
4745 {
4746  xmlChar *val;
4747  const xmlChar *ret;
4748 
4750  if (val == NULL)
4751  val = xmlStrdup((xmlChar *)"");
4752  ret = xmlDictLookup(ctxt->dict, val, -1);
4753  xmlFree(val);
4754  return(ret);
4755 }
4756 
4757 static const xmlChar *
4758 xmlSchemaGetNodeContentNoDict(xmlNodePtr node)
4759 {
4760  return((const xmlChar*) xmlNodeGetContent(node));
4761 }
4762 
4773 static const xmlChar *
4774 xmlSchemaGetProp(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node,
4775  const char *name)
4776 {
4777  xmlChar *val;
4778  const xmlChar *ret;
4779 
4781  if (val == NULL)
4782  return(NULL);
4783  ret = xmlDictLookup(ctxt->dict, val, -1);
4784  xmlFree(val);
4785  return(ret);
4786 }
4787 
4788 /************************************************************************
4789  * *
4790  * Parsing functions *
4791  * *
4792  ************************************************************************/
4793 
4794 #define WXS_FIND_GLOBAL_ITEM(slot) \
4795  if (xmlStrEqual(nsName, schema->targetNamespace)) { \
4796  ret = xmlHashLookup(schema->slot, name); \
4797  if (ret != NULL) goto exit; \
4798  } \
4799  if (xmlHashSize(schema->schemasImports) > 1) { \
4800  xmlSchemaImportPtr import; \
4801  if (nsName == NULL) \
4802  import = xmlHashLookup(schema->schemasImports, \
4803  XML_SCHEMAS_NO_NAMESPACE); \
4804  else \
4805  import = xmlHashLookup(schema->schemasImports, nsName); \
4806  if (import == NULL) \
4807  goto exit; \
4808  ret = xmlHashLookup(import->schema->slot, name); \
4809  }
4810 
4821 static xmlSchemaElementPtr
4822 xmlSchemaGetElem(xmlSchemaPtr schema, const xmlChar * name,
4823  const xmlChar * nsName)
4824 {
4825  xmlSchemaElementPtr ret = NULL;
4826 
4827  if ((name == NULL) || (schema == NULL))
4828  return(NULL);
4829  if (schema != NULL) {
4830  WXS_FIND_GLOBAL_ITEM(elemDecl)
4831  }
4832 exit:
4833 #ifdef DEBUG
4834  if (ret == NULL) {
4835  if (nsName == NULL)
4836  fprintf(stderr, "Unable to lookup element decl. %s", name);
4837  else
4838  fprintf(stderr, "Unable to lookup element decl. %s:%s", name,
4839  nsName);
4840  }
4841 #endif
4842  return (ret);
4843 }
4844 
4855 static xmlSchemaTypePtr
4856 xmlSchemaGetType(xmlSchemaPtr schema, const xmlChar * name,
4857  const xmlChar * nsName)
4858 {
4859  xmlSchemaTypePtr ret = NULL;
4860 
4861  if (name == NULL)
4862  return (NULL);
4863  /* First try the built-in types. */
4864  if ((nsName != NULL) && xmlStrEqual(nsName, xmlSchemaNs)) {
4865  ret = xmlSchemaGetPredefinedType(name, nsName);
4866  if (ret != NULL)
4867  goto exit;
4868  /*
4869  * Note that we try the parsed schemas as well here
4870  * since one might have parsed the S4S, which contain more
4871  * than the built-in types.
4872  * TODO: Can we optimize this?
4873  */
4874  }
4875  if (schema != NULL) {
4876  WXS_FIND_GLOBAL_ITEM(typeDecl)
4877  }
4878 exit:
4879 
4880 #ifdef DEBUG
4881  if (ret == NULL) {
4882  if (nsName == NULL)
4883  fprintf(stderr, "Unable to lookup type %s", name);
4884  else
4885  fprintf(stderr, "Unable to lookup type %s:%s", name,
4886  nsName);
4887  }
4888 #endif
4889  return (ret);
4890 }
4891 
4902 static xmlSchemaAttributePtr
4903 xmlSchemaGetAttributeDecl(xmlSchemaPtr schema, const xmlChar * name,
4904  const xmlChar * nsName)
4905 {
4906  xmlSchemaAttributePtr ret = NULL;
4907 
4908  if ((name == NULL) || (schema == NULL))
4909  return (NULL);
4910  if (schema != NULL) {
4911  WXS_FIND_GLOBAL_ITEM(attrDecl)
4912  }
4913 exit:
4914 #ifdef DEBUG
4915  if (ret == NULL) {
4916  if (nsName == NULL)
4917  fprintf(stderr, "Unable to lookup attribute %s", name);
4918  else
4919  fprintf(stderr, "Unable to lookup attribute %s:%s", name,
4920  nsName);
4921  }
4922 #endif
4923  return (ret);
4924 }
4925 
4936 static xmlSchemaAttributeGroupPtr
4937 xmlSchemaGetAttributeGroup(xmlSchemaPtr schema, const xmlChar * name,
4938  const xmlChar * nsName)
4939 {
4940  xmlSchemaAttributeGroupPtr ret = NULL;
4941 
4942  if ((name == NULL) || (schema == NULL))
4943  return (NULL);
4944  if (schema != NULL) {
4945  WXS_FIND_GLOBAL_ITEM(attrgrpDecl)
4946  }
4947 exit:
4948  /* TODO:
4949  if ((ret != NULL) && (ret->redef != NULL)) {
4950  * Return the last redefinition. *
4951  ret = ret->redef;
4952  }
4953  */
4954 #ifdef DEBUG
4955  if (ret == NULL) {
4956  if (nsName == NULL)
4957  fprintf(stderr, "Unable to lookup attribute group %s", name);
4958  else
4959  fprintf(stderr, "Unable to lookup attribute group %s:%s", name,
4960  nsName);
4961  }
4962 #endif
4963  return (ret);
4964 }
4965 
4976 static xmlSchemaModelGroupDefPtr
4977 xmlSchemaGetGroup(xmlSchemaPtr schema, const xmlChar * name,
4978  const xmlChar * nsName)
4979 {
4980  xmlSchemaModelGroupDefPtr ret = NULL;
4981 
4982  if ((name == NULL) || (schema == NULL))
4983  return (NULL);
4984  if (schema != NULL) {
4985  WXS_FIND_GLOBAL_ITEM(groupDecl)
4986  }
4987 exit:
4988 
4989 #ifdef DEBUG
4990  if (ret == NULL) {
4991  if (nsName == NULL)
4992  fprintf(stderr, "Unable to lookup group %s", name);
4993  else
4994  fprintf(stderr, "Unable to lookup group %s:%s", name,
4995  nsName);
4996  }
4997 #endif
4998  return (ret);
4999 }
5000 
5001 static xmlSchemaNotationPtr
5002 xmlSchemaGetNotation(xmlSchemaPtr schema,
5003  const xmlChar *name,
5004  const xmlChar *nsName)
5005 {
5006  xmlSchemaNotationPtr ret = NULL;
5007 
5008  if ((name == NULL) || (schema == NULL))
5009  return (NULL);
5010  if (schema != NULL) {
5011  WXS_FIND_GLOBAL_ITEM(notaDecl)
5012  }
5013 exit:
5014  return (ret);
5015 }
5016 
5017 static xmlSchemaIDCPtr
5018 xmlSchemaGetIDC(xmlSchemaPtr schema,
5019  const xmlChar *name,
5020  const xmlChar *nsName)
5021 {
5022  xmlSchemaIDCPtr ret = NULL;
5023 
5024  if ((name == NULL) || (schema == NULL))
5025  return (NULL);
5026  if (schema != NULL) {
5027  WXS_FIND_GLOBAL_ITEM(idcDef)
5028  }
5029 exit:
5030  return (ret);
5031 }
5032 
5043 static xmlSchemaBasicItemPtr
5044 xmlSchemaGetNamedComponent(xmlSchemaPtr schema,
5045  xmlSchemaTypeType itemType,
5046  const xmlChar *name,
5047  const xmlChar *targetNs)
5048 {
5049  switch (itemType) {
5050  case XML_SCHEMA_TYPE_GROUP:
5051  return ((xmlSchemaBasicItemPtr) xmlSchemaGetGroup(schema,
5052  name, targetNs));
5053  case XML_SCHEMA_TYPE_ELEMENT:
5054  return ((xmlSchemaBasicItemPtr) xmlSchemaGetElem(schema,
5055  name, targetNs));
5056  default:
5057  TODO
5058  return (NULL);
5059  }
5060 }
5061 
5062 /************************************************************************
5063  * *
5064  * Parsing functions *
5065  * *
5066  ************************************************************************/
5067 
5068 #define IS_BLANK_NODE(n) \
5069  (((n)->type == XML_TEXT_NODE) && (xmlSchemaIsBlank((n)->content, -1)))
5070 
5080 static int
5081 xmlSchemaIsBlank(xmlChar * str, int len)
5082 {
5083  if (str == NULL)
5084  return (1);
5085  if (len < 0) {
5086  while (*str != 0) {
5087  if (!(IS_BLANK_CH(*str)))
5088  return (0);
5089  str++;
5090  }
5091  } else while ((*str != 0) && (len != 0)) {
5092  if (!(IS_BLANK_CH(*str)))
5093  return (0);
5094  str++;
5095  len--;
5096  }
5097 
5098  return (1);
5099 }
5100 
5101 #define WXS_COMP_NAME(c, t) ((t) (c))->name
5102 #define WXS_COMP_TNS(c, t) ((t) (c))->targetNamespace
5103 /*
5104 * xmlSchemaFindRedefCompInGraph:
5105 * ATTENTION TODO: This uses pointer comp. for strings.
5106 */
5107 static xmlSchemaBasicItemPtr
5108 xmlSchemaFindRedefCompInGraph(xmlSchemaBucketPtr bucket,
5109  xmlSchemaTypeType type,
5110  const xmlChar *name,
5111  const xmlChar *nsName)
5112 {
5113  xmlSchemaBasicItemPtr ret;
5114  int i;
5115 
5116  if ((bucket == NULL) || (name == NULL))
5117  return(NULL);
5118  if ((bucket->globals == NULL) ||
5119  (bucket->globals->nbItems == 0))
5120  goto subschemas;
5121  /*
5122  * Search in global components.
5123  */
5124  for (i = 0; i < bucket->globals->nbItems; i++) {
5125  ret = bucket->globals->items[i];
5126  if (ret->type == type) {
5127  switch (type) {
5128  case XML_SCHEMA_TYPE_COMPLEX:
5129  case XML_SCHEMA_TYPE_SIMPLE:
5130  if ((WXS_COMP_NAME(ret, xmlSchemaTypePtr) == name) &&
5131  (WXS_COMP_TNS(ret, xmlSchemaTypePtr) ==
5132  nsName))
5133  {
5134  return(ret);
5135  }
5136  break;
5137  case XML_SCHEMA_TYPE_GROUP:
5138  if ((WXS_COMP_NAME(ret,
5139  xmlSchemaModelGroupDefPtr) == name) &&
5140  (WXS_COMP_TNS(ret,
5141  xmlSchemaModelGroupDefPtr) == nsName))
5142  {
5143  return(ret);
5144  }
5145  break;
5146  case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
5147  if ((WXS_COMP_NAME(ret,
5148  xmlSchemaAttributeGroupPtr) == name) &&
5149  (WXS_COMP_TNS(ret,
5150  xmlSchemaAttributeGroupPtr) == nsName))
5151  {
5152  return(ret);
5153  }
5154  break;
5155  default:
5156  /* Should not be hit. */
5157  return(NULL);
5158  }
5159  }
5160  }
5161 subschemas:
5162  /*
5163  * Process imported/included schemas.
5164  */
5165  if (bucket->relations != NULL) {
5166  xmlSchemaSchemaRelationPtr rel = bucket->relations;
5167 
5168  /*
5169  * TODO: Marking the bucket will not avoid multiple searches
5170  * in the same schema, but avoids at least circularity.
5171  */
5172  bucket->flags |= XML_SCHEMA_BUCKET_MARKED;
5173  do {
5174  if ((rel->bucket != NULL) &&
5175  ((rel->bucket->flags & XML_SCHEMA_BUCKET_MARKED) == 0)) {
5176  ret = xmlSchemaFindRedefCompInGraph(rel->bucket,
5177  type, name, nsName);
5178  if (ret != NULL)
5179  return(ret);
5180  }
5181  rel = rel->next;
5182  } while (rel != NULL);
5183  bucket->flags ^= XML_SCHEMA_BUCKET_MARKED;
5184  }
5185  return(NULL);
5186 }
5187 
5199 static xmlSchemaNotationPtr
5200 xmlSchemaAddNotation(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
5201  const xmlChar *name, const xmlChar *nsName,
5203 {
5204  xmlSchemaNotationPtr ret = NULL;
5205 
5206  if ((ctxt == NULL) || (schema == NULL) || (name == NULL))
5207  return (NULL);
5208 
5209  ret = (xmlSchemaNotationPtr) xmlMalloc(sizeof(xmlSchemaNotation));
5210  if (ret == NULL) {
5211  xmlSchemaPErrMemory(ctxt, "add annotation", NULL);
5212  return (NULL);
5213  }
5214  memset(ret, 0, sizeof(xmlSchemaNotation));
5215  ret->type = XML_SCHEMA_TYPE_NOTATION;
5216  ret->name = name;
5217  ret->targetNamespace = nsName;
5218  /* TODO: do we need the node to be set?
5219  * ret->node = node;*/
5220  WXS_ADD_GLOBAL(ctxt, ret);
5221  return (ret);
5222 }
5223 
5236 static xmlSchemaAttributePtr
5237 xmlSchemaAddAttribute(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
5238  const xmlChar * name, const xmlChar * nsName,
5239  xmlNodePtr node, int topLevel)
5240 {
5241  xmlSchemaAttributePtr ret = NULL;
5242 
5243  if ((ctxt == NULL) || (schema == NULL))
5244  return (NULL);
5245 
5246  ret = (xmlSchemaAttributePtr) xmlMalloc(sizeof(xmlSchemaAttribute));
5247  if (ret == NULL) {
5248  xmlSchemaPErrMemory(ctxt, "allocating attribute", NULL);
5249  return (NULL);
5250  }
5251  memset(ret, 0, sizeof(xmlSchemaAttribute));
5252  ret->type = XML_SCHEMA_TYPE_ATTRIBUTE;
5253  ret->node = node;
5254  ret->name = name;
5255  ret->targetNamespace = nsName;
5256 
5257  if (topLevel)
5258  WXS_ADD_GLOBAL(ctxt, ret);
5259  else
5260  WXS_ADD_LOCAL(ctxt, ret);
5261  WXS_ADD_PENDING(ctxt, ret);
5262  return (ret);
5263 }
5264 
5277 static xmlSchemaAttributeUsePtr
5278 xmlSchemaAddAttributeUse(xmlSchemaParserCtxtPtr pctxt,
5279  xmlNodePtr node)
5280 {
5281  xmlSchemaAttributeUsePtr ret = NULL;
5282 
5283  if (pctxt == NULL)
5284  return (NULL);
5285 
5286  ret = (xmlSchemaAttributeUsePtr) xmlMalloc(sizeof(xmlSchemaAttributeUse));
5287  if (ret == NULL) {
5288  xmlSchemaPErrMemory(pctxt, "allocating attribute", NULL);
5289  return (NULL);
5290  }
5291  memset(ret, 0, sizeof(xmlSchemaAttributeUse));
5292  ret->type = XML_SCHEMA_TYPE_ATTRIBUTE_USE;
5293  ret->node = node;
5294 
5295  WXS_ADD_LOCAL(pctxt, ret);
5296  return (ret);
5297 }
5298 
5299 /*
5300 * xmlSchemaAddRedef:
5301 *
5302 * Adds a redefinition information. This is used at a later stage to:
5303 * resolve references to the redefined components and to check constraints.
5304 */
5305 static xmlSchemaRedefPtr
5306 xmlSchemaAddRedef(xmlSchemaParserCtxtPtr pctxt,
5307  xmlSchemaBucketPtr targetBucket,
5308  void *item,
5309  const xmlChar *refName,
5310  const xmlChar *refTargetNs)
5311 {
5312  xmlSchemaRedefPtr ret;
5313 
5314  ret = (xmlSchemaRedefPtr)
5315  xmlMalloc(sizeof(xmlSchemaRedef));
5316  if (ret == NULL) {
5317  xmlSchemaPErrMemory(pctxt,
5318  "allocating redefinition info", NULL);
5319  return (NULL);
5320  }
5321  memset(ret, 0, sizeof(xmlSchemaRedef));
5322  ret->item = item;
5323  ret->targetBucket = targetBucket;
5324  ret->refName = refName;
5325  ret->refTargetNs = refTargetNs;
5326  if (WXS_CONSTRUCTOR(pctxt)->redefs == NULL)
5327  WXS_CONSTRUCTOR(pctxt)->redefs = ret;
5328  else
5329  WXS_CONSTRUCTOR(pctxt)->lastRedef->next = ret;
5330  WXS_CONSTRUCTOR(pctxt)->lastRedef = ret;
5331 
5332  return (ret);
5333 }
5334 
5347 static xmlSchemaAttributeGroupPtr
5348 xmlSchemaAddAttributeGroupDefinition(xmlSchemaParserCtxtPtr pctxt,
5349  xmlSchemaPtr schema ATTRIBUTE_UNUSED,
5350  const xmlChar *name,
5351  const xmlChar *nsName,
5352  xmlNodePtr node)
5353 {
5354  xmlSchemaAttributeGroupPtr ret = NULL;
5355 
5356  if ((pctxt == NULL) || (name == NULL))
5357  return (NULL);
5358 
5359  ret = (xmlSchemaAttributeGroupPtr)
5360  xmlMalloc(sizeof(xmlSchemaAttributeGroup));
5361  if (ret == NULL) {
5362  xmlSchemaPErrMemory(pctxt, "allocating attribute group", NULL);
5363  return (NULL);
5364  }
5365  memset(ret, 0, sizeof(xmlSchemaAttributeGroup));
5366  ret->type = XML_SCHEMA_TYPE_ATTRIBUTEGROUP;
5367  ret->name = name;
5368  ret->targetNamespace = nsName;
5369  ret->node = node;
5370 
5371  /* TODO: Remove the flag. */
5372  ret->flags |= XML_SCHEMAS_ATTRGROUP_GLOBAL;
5373  if (pctxt->isRedefine) {
5374  pctxt->redef = xmlSchemaAddRedef(pctxt, pctxt->redefined,
5375  ret, name, nsName);
5376  if (pctxt->redef == NULL) {
5377  xmlFree(ret);
5378  return(NULL);
5379  }
5380  pctxt->redefCounter = 0;
5381  }
5382  WXS_ADD_GLOBAL(pctxt, ret);
5383  WXS_ADD_PENDING(pctxt, ret);
5384  return (ret);
5385 }
5386 
5399 static xmlSchemaElementPtr
5400 xmlSchemaAddElement(xmlSchemaParserCtxtPtr ctxt,
5401  const xmlChar * name, const xmlChar * nsName,
5402  xmlNodePtr node, int topLevel)
5403 {
5404  xmlSchemaElementPtr ret = NULL;
5405 
5406  if ((ctxt == NULL) || (name == NULL))
5407  return (NULL);
5408 
5409  ret = (xmlSchemaElementPtr) xmlMalloc(sizeof(xmlSchemaElement));
5410  if (ret == NULL) {
5411  xmlSchemaPErrMemory(ctxt, "allocating element", NULL);
5412  return (NULL);
5413  }
5414  memset(ret, 0, sizeof(xmlSchemaElement));
5415  ret->type = XML_SCHEMA_TYPE_ELEMENT;
5416  ret->name = name;
5417  ret->targetNamespace = nsName;
5418  ret->node = node;
5419 
5420  if (topLevel)
5421  WXS_ADD_GLOBAL(ctxt, ret);
5422  else
5423  WXS_ADD_LOCAL(ctxt, ret);
5424  WXS_ADD_PENDING(ctxt, ret);
5425  return (ret);
5426 }
5427 
5440 static xmlSchemaTypePtr
5441 xmlSchemaAddType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
5442  xmlSchemaTypeType type,
5443  const xmlChar * name, const xmlChar * nsName,
5444  xmlNodePtr node, int topLevel)
5445 {
5446  xmlSchemaTypePtr ret = NULL;
5447 
5448  if ((ctxt == NULL) || (schema == NULL))
5449  return (NULL);
5450 
5451  ret = (xmlSchemaTypePtr) xmlMalloc(sizeof(xmlSchemaType));
5452  if (ret == NULL) {
5453  xmlSchemaPErrMemory(ctxt, "allocating type", NULL);
5454  return (NULL);
5455  }
5456  memset(ret, 0, sizeof(xmlSchemaType));
5457  ret->type = type;
5458  ret->name = name;
5459  ret->targetNamespace = nsName;
5460  ret->node = node;
5461  if (topLevel) {
5462  if (ctxt->isRedefine) {
5463  ctxt->redef = xmlSchemaAddRedef(ctxt, ctxt->redefined,
5464  ret, name, nsName);
5465  if (ctxt->redef == NULL) {
5466  xmlFree(ret);
5467  return(NULL);
5468  }
5469  ctxt->redefCounter = 0;
5470  }
5471  WXS_ADD_GLOBAL(ctxt, ret);
5472  } else
5473  WXS_ADD_LOCAL(ctxt, ret);
5474  WXS_ADD_PENDING(ctxt, ret);
5475  return (ret);
5476 }
5477 
5478 static xmlSchemaQNameRefPtr
5479 xmlSchemaNewQNameRef(xmlSchemaParserCtxtPtr pctxt,
5480  xmlSchemaTypeType refType,
5481  const xmlChar *refName,
5482  const xmlChar *refNs)
5483 {
5484  xmlSchemaQNameRefPtr ret;
5485 
5486  ret = (xmlSchemaQNameRefPtr)
5487  xmlMalloc(sizeof(xmlSchemaQNameRef));
5488  if (ret == NULL) {
5489  xmlSchemaPErrMemory(pctxt,
5490  "allocating QName reference item", NULL);
5491  return (NULL);
5492  }
5493  ret->node = NULL;
5494  ret->type = XML_SCHEMA_EXTRA_QNAMEREF;
5495  ret->name = refName;
5496  ret->targetNamespace = refNs;
5497  ret->item = NULL;
5498  ret->itemType = refType;
5499  /*
5500  * Store the reference item in the schema.
5501  */
5502  WXS_ADD_LOCAL(pctxt, ret);
5503  return (ret);
5504 }
5505 
5506 static xmlSchemaAttributeUseProhibPtr
5507 xmlSchemaAddAttributeUseProhib(xmlSchemaParserCtxtPtr pctxt)
5508 {
5509  xmlSchemaAttributeUseProhibPtr ret;
5510 
5511  ret = (xmlSchemaAttributeUseProhibPtr)
5512  xmlMalloc(sizeof(xmlSchemaAttributeUseProhib));
5513  if (ret == NULL) {
5514  xmlSchemaPErrMemory(pctxt,
5515  "allocating attribute use prohibition", NULL);
5516  return (NULL);
5517  }
5518  memset(ret, 0, sizeof(xmlSchemaAttributeUseProhib));
5519  ret->type = XML_SCHEMA_EXTRA_ATTR_USE_PROHIB;
5520  WXS_ADD_LOCAL(pctxt, ret);
5521  return (ret);
5522 }
5523 
5524 
5537 static xmlSchemaModelGroupPtr
5538 xmlSchemaAddModelGroup(xmlSchemaParserCtxtPtr ctxt,
5539  xmlSchemaPtr schema,
5540  xmlSchemaTypeType type,
5541  xmlNodePtr node)
5542 {
5543  xmlSchemaModelGroupPtr ret = NULL;
5544 
5545  if ((ctxt == NULL) || (schema == NULL))
5546  return (NULL);
5547 
5548  ret = (xmlSchemaModelGroupPtr)
5549  xmlMalloc(sizeof(xmlSchemaModelGroup));
5550  if (ret == NULL) {
5551  xmlSchemaPErrMemory(ctxt, "allocating model group component",
5552  NULL);
5553  return (NULL);
5554  }
5555  memset(ret, 0, sizeof(xmlSchemaModelGroup));
5556  ret->type = type;
5557  ret->node = node;
5558  WXS_ADD_LOCAL(ctxt, ret);
5559  if ((type == XML_SCHEMA_TYPE_SEQUENCE) ||
5560  (type == XML_SCHEMA_TYPE_CHOICE))
5561  WXS_ADD_PENDING(ctxt, ret);
5562  return (ret);
5563 }
5564 
5565 
5579 static xmlSchemaParticlePtr
5580 xmlSchemaAddParticle(xmlSchemaParserCtxtPtr ctxt,
5581  xmlNodePtr node, int min, int max)
5582 {
5583  xmlSchemaParticlePtr ret = NULL;
5584  if (ctxt == NULL)
5585  return (NULL);
5586 
5587 #ifdef DEBUG
5588  fprintf(stderr, "Adding particle component\n");
5589 #endif
5590  ret = (xmlSchemaParticlePtr)
5591  xmlMalloc(sizeof(xmlSchemaParticle));
5592  if (ret == NULL) {
5593  xmlSchemaPErrMemory(ctxt, "allocating particle component",
5594  NULL);
5595  return (NULL);
5596  }
5597  ret->type = XML_SCHEMA_TYPE_PARTICLE;
5598  ret->annot = NULL;
5599  ret->node = node;
5600  ret->minOccurs = min;
5601  ret->maxOccurs = max;
5602  ret->next = NULL;
5603  ret->children = NULL;
5604 
5605  WXS_ADD_LOCAL(ctxt, ret);
5606  /*
5607  * Note that addition to pending components will be done locally
5608  * to the specific parsing function, since the most particles
5609  * need not to be fixed up (i.e. the reference to be resolved).
5610  * REMOVED: WXS_ADD_PENDING(ctxt, ret);
5611  */
5612  return (ret);
5613 }
5614 
5625 static xmlSchemaModelGroupDefPtr
5626 xmlSchemaAddModelGroupDefinition(xmlSchemaParserCtxtPtr ctxt,
5627  xmlSchemaPtr schema,
5628  const xmlChar *name,
5629  const xmlChar *nsName,
5630  xmlNodePtr node)
5631 {
5632  xmlSchemaModelGroupDefPtr ret = NULL;
5633 
5634  if ((ctxt == NULL) || (schema == NULL) || (name == NULL))
5635  return (NULL);
5636 
5637  ret = (xmlSchemaModelGroupDefPtr)
5638  xmlMalloc(sizeof(xmlSchemaModelGroupDef));
5639  if (ret == NULL) {
5640  xmlSchemaPErrMemory(ctxt, "adding group", NULL);
5641  return (NULL);
5642  }
5643  memset(ret, 0, sizeof(xmlSchemaModelGroupDef));
5644  ret->name = name;
5645  ret->type = XML_SCHEMA_TYPE_GROUP;
5646  ret->node = node;
5647  ret->targetNamespace = nsName;
5648 
5649  if (ctxt->isRedefine) {
5650  ctxt->redef = xmlSchemaAddRedef(ctxt, ctxt->redefined,
5651  ret, name, nsName);
5652  if (ctxt->redef == NULL) {
5653  xmlFree(ret);
5654  return(NULL);
5655  }
5656  ctxt->redefCounter = 0;
5657  }
5658  WXS_ADD_GLOBAL(ctxt, ret);
5659  WXS_ADD_PENDING(ctxt, ret);
5660  return (ret);
5661 }
5662 
5671 static xmlSchemaWildcardNsPtr
5672 xmlSchemaNewWildcardNsConstraint(xmlSchemaParserCtxtPtr ctxt)