blob: d3fe98a4a4cb2365f8688f804ddabc3fe806aff2 [file] [log] [blame]
Daniel Veillard4255d502002-04-16 15:50:10 +00001/*
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
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000010/*
Daniel Veillardb0f397e2003-12-23 23:30:53 +000011 * 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.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015 * - if we don't intend to use the schema for schemas, we
Daniel Veillard01fa6152004-06-29 17:04:39 +000016 * need to validate all schema attributes (ref, type, name)
17 * against their types.
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000018 * - Eliminate item creation for: ??
19 *
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000020 * URGENT TODO:
21 * - For xsi-driven schema acquisition, augment the IDCs after every
22 * acquisition episode (xmlSchemaAugmentIDC).
23 *
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000024 * NOTES:
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025 * - Elimated item creation for: <restriction>, <extension>,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000026 * <simpleContent>, <complexContent>, <list>, <union>
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027 *
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000028 * 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.
Daniel Veillardb0f397e2003-12-23 23:30:53 +000046 */
Daniel Veillard4255d502002-04-16 15:50:10 +000047#define IN_LIBXML
48#include "libxml.h"
49
50#ifdef LIBXML_SCHEMAS_ENABLED
51
52#include <string.h>
53#include <libxml/xmlmemory.h>
54#include <libxml/parser.h>
55#include <libxml/parserInternals.h>
56#include <libxml/hash.h>
Daniel Veillard5a872412002-05-22 06:40:27 +000057#include <libxml/uri.h>
Daniel Veillard4255d502002-04-16 15:50:10 +000058#include <libxml/xmlschemas.h>
59#include <libxml/schemasInternals.h>
60#include <libxml/xmlschemastypes.h>
61#include <libxml/xmlautomata.h>
62#include <libxml/xmlregexp.h>
Daniel Veillardbe9c6322003-11-22 20:37:51 +000063#include <libxml/dict.h>
Kasimier T. Buchcik72d3adc2005-07-08 16:43:37 +000064#include <libxml/encoding.h>
65#include <libxml/xmlIO.h>
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000066#ifdef LIBXML_PATTERN_ENABLED
67#include <libxml/pattern.h>
68#endif
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000069#ifdef LIBXML_READER_ENABLED
70#include <libxml/xmlreader.h>
71#endif
Daniel Veillard4255d502002-04-16 15:50:10 +000072
Daniel Veillarda84c0b32003-06-02 16:58:46 +000073/* #define DEBUG 1 */
Daniel Veillardd0c9c322003-10-10 00:49:42 +000074
Daniel Veillard82bbbd42003-05-11 20:16:09 +000075/* #define DEBUG_CONTENT 1 */
Daniel Veillardd0c9c322003-10-10 00:49:42 +000076
Daniel Veillard82bbbd42003-05-11 20:16:09 +000077/* #define DEBUG_TYPE 1 */
Daniel Veillardd0c9c322003-10-10 00:49:42 +000078
Daniel Veillard118aed72002-09-24 14:13:13 +000079/* #define DEBUG_CONTENT_REGEXP 1 */
Daniel Veillardd0c9c322003-10-10 00:49:42 +000080
Daniel Veillard4255d502002-04-16 15:50:10 +000081/* #define DEBUG_AUTOMATA 1 */
82
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000083/* #define DEBUG_IDC */
84
85/* #define DEBUG_IDC_NODE_TABLE */
86
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000087/* #define WXS_ELEM_DECL_CONS_ENABLED */
88
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000089#ifdef DEBUG_IDC
90 #ifndef DEBUG_IDC_NODE_TABLE
91 #define DEBUG_IDC_NODE_TABLE
92 #endif
Daniel Veillarddee23482008-04-11 12:58:43 +000093#endif
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000094
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000095/* #define ENABLE_PARTICLE_RESTRICTION 1 */
96
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000097#define ENABLE_REDEFINE
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000098
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000099/* #define ENABLE_NAMED_LOCALS */
100
Kasimier T. Buchcik132ba5f2005-11-28 12:32:24 +0000101/* #define ENABLE_IDC_NODE_TABLES_TEST */
Kasimier T. Buchcik27820272005-10-14 14:33:48 +0000102
Kasimier T. Buchcik630215b2005-08-22 10:15:39 +0000103#define DUMP_CONTENT_MODEL
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +0000104
105#ifdef LIBXML_READER_ENABLED
106/* #define XML_SCHEMA_READER_ENABLED */
107#endif
Daniel Veillardc0826a72004-08-10 14:17:33 +0000108
Daniel Veillard4255d502002-04-16 15:50:10 +0000109#define UNBOUNDED (1 << 30)
110#define TODO \
111 xmlGenericError(xmlGenericErrorContext, \
112 "Unimplemented block at %s:%d\n", \
113 __FILE__, __LINE__);
114
William M. Brack2f2a6632004-08-20 23:09:47 +0000115#define XML_SCHEMAS_NO_NAMESPACE (const xmlChar *) "##"
Daniel Veillardc0826a72004-08-10 14:17:33 +0000116
Daniel Veillard4255d502002-04-16 15:50:10 +0000117/*
118 * The XML Schemas namespaces
119 */
120static const xmlChar *xmlSchemaNs = (const xmlChar *)
121 "http://www.w3.org/2001/XMLSchema";
122
123static const xmlChar *xmlSchemaInstanceNs = (const xmlChar *)
124 "http://www.w3.org/2001/XMLSchema-instance";
125
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +0000126static const xmlChar *xmlNamespaceNs = (const xmlChar *)
127 "http://www.w3.org/2000/xmlns/";
128
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000129/*
130* Come casting macros.
131*/
132#define ACTXT_CAST (xmlSchemaAbstractCtxtPtr)
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +0000133#define PCTXT_CAST (xmlSchemaParserCtxtPtr)
134#define VCTXT_CAST (xmlSchemaValidCtxtPtr)
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000135#define WXS_BASIC_CAST (xmlSchemaBasicItemPtr)
136#define WXS_TREE_CAST (xmlSchemaTreeItemPtr)
137#define WXS_PTC_CAST (xmlSchemaParticlePtr)
138#define WXS_TYPE_CAST (xmlSchemaTypePtr)
139#define WXS_ELEM_CAST (xmlSchemaElementPtr)
140#define WXS_ATTR_GROUP_CAST (xmlSchemaAttributeGroupPtr)
141#define WXS_ATTR_CAST (xmlSchemaAttributePtr)
142#define WXS_ATTR_USE_CAST (xmlSchemaAttributeUsePtr)
143#define WXS_ATTR_PROHIB_CAST (xmlSchemaAttributeUseProhibPtr)
144#define WXS_MODEL_GROUPDEF_CAST (xmlSchemaModelGroupDefPtr)
145#define WXS_MODEL_GROUP_CAST (xmlSchemaModelGroupPtr)
146#define WXS_IDC_CAST (xmlSchemaIDCPtr)
147#define WXS_QNAME_CAST (xmlSchemaQNameRefPtr)
148#define WXS_LIST_CAST (xmlSchemaItemListPtr)
Daniel Veillardc0826a72004-08-10 14:17:33 +0000149
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000150/*
151* Macros to query common properties of components.
152*/
153#define WXS_ITEM_NODE(i) xmlSchemaGetComponentNode(WXS_BASIC_CAST (i))
Daniel Veillard4255d502002-04-16 15:50:10 +0000154
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000155#define WXS_ITEM_TYPE_NAME(i) xmlSchemaGetComponentTypeStr(WXS_BASIC_CAST (i))
156/*
157* Macros for element declarations.
158*/
159#define WXS_ELEM_TYPEDEF(e) (e)->subtypes
Daniel Veillardc0826a72004-08-10 14:17:33 +0000160
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000161#define WXS_SUBST_HEAD(item) (item)->refDecl
162/*
163* Macros for attribute declarations.
164*/
165#define WXS_ATTR_TYPEDEF(a) (a)->subtypes
166/*
167* Macros for attribute uses.
168*/
169#define WXS_ATTRUSE_DECL(au) WXS_ATTR_CAST (WXS_ATTR_USE_CAST (au))->attrDecl
Kasimier T. Buchcik87876402004-09-29 13:29:03 +0000170
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000171#define WXS_ATTRUSE_TYPEDEF(au) WXS_ATTR_TYPEDEF(WXS_ATTRUSE_DECL( WXS_ATTR_USE_CAST au))
Kasimier T. Buchcik87876402004-09-29 13:29:03 +0000172
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000173#define WXS_ATTRUSE_DECL_NAME(au) (WXS_ATTRUSE_DECL(au))->name
174
175#define WXS_ATTRUSE_DECL_TNS(au) (WXS_ATTRUSE_DECL(au))->targetNamespace
176/*
177* Macros for attribute groups.
178*/
179#define WXS_ATTR_GROUP_HAS_REFS(ag) ((WXS_ATTR_GROUP_CAST (ag))->flags & XML_SCHEMAS_ATTRGROUP_HAS_REFS)
180#define WXS_ATTR_GROUP_EXPANDED(ag) ((WXS_ATTR_GROUP_CAST (ag))->flags & XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED)
181/*
182* Macros for particles.
183*/
184#define WXS_PARTICLE(p) WXS_PTC_CAST (p)
185
186#define WXS_PARTICLE_TERM(p) (WXS_PARTICLE(p))->children
187
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +0000188#define WXS_PARTICLE_TERM_AS_ELEM(p) (WXS_ELEM_CAST WXS_PARTICLE_TERM(p))
189
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000190#define WXS_PARTICLE_MODEL(p) WXS_MODEL_GROUP_CAST WXS_PARTICLE(p)->children
191/*
192* Macros for model groups definitions.
193*/
194#define WXS_MODELGROUPDEF_MODEL(mgd) (WXS_MODEL_GROUP_CAST (mgd))->children
195/*
196* Macros for model groups.
197*/
198#define WXS_IS_MODEL_GROUP(i) \
199 (((i)->type == XML_SCHEMA_TYPE_SEQUENCE) || \
200 ((i)->type == XML_SCHEMA_TYPE_CHOICE) || \
201 ((i)->type == XML_SCHEMA_TYPE_ALL))
202
203#define WXS_MODELGROUP_PARTICLE(mg) WXS_PTC_CAST (mg)->children
204/*
205* Macros for schema buckets.
206*/
207#define WXS_IS_BUCKET_INCREDEF(t) (((t) == XML_SCHEMA_SCHEMA_INCLUDE) || \
208 ((t) == XML_SCHEMA_SCHEMA_REDEFINE))
209
210#define WXS_IS_BUCKET_IMPMAIN(t) (((t) == XML_SCHEMA_SCHEMA_MAIN) || \
211 ((t) == XML_SCHEMA_SCHEMA_IMPORT))
212
213#define WXS_IMPBUCKET(b) ((xmlSchemaImportPtr) (b))
214
215#define WXS_INCBUCKET(b) ((xmlSchemaIncludePtr) (b))
216/*
217* Macros for complex/simple types.
218*/
219#define WXS_IS_ANYTYPE(i) \
220 (( (i)->type == XML_SCHEMA_TYPE_BASIC) && \
221 ( (WXS_TYPE_CAST (i))->builtInType == XML_SCHEMAS_ANYTYPE))
222
223#define WXS_IS_COMPLEX(i) \
224 (((i)->type == XML_SCHEMA_TYPE_COMPLEX) || \
225 ((i)->builtInType == XML_SCHEMAS_ANYTYPE))
226
227#define WXS_IS_SIMPLE(item) \
228 ((item->type == XML_SCHEMA_TYPE_SIMPLE) || \
229 ((item->type == XML_SCHEMA_TYPE_BASIC) && \
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +0000230 (item->builtInType != XML_SCHEMAS_ANYTYPE)))
Kasimier T. Buchcik87876402004-09-29 13:29:03 +0000231
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000232#define WXS_IS_ANY_SIMPLE_TYPE(i) \
233 (((i)->type == XML_SCHEMA_TYPE_BASIC) && \
234 ((i)->builtInType == XML_SCHEMAS_ANYSIMPLETYPE))
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +0000235
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000236#define WXS_IS_RESTRICTION(t) \
237 ((t)->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION)
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +0000238
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000239#define WXS_IS_EXTENSION(t) \
240 ((t)->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION)
241
242#define WXS_IS_TYPE_NOT_FIXED(i) \
243 (((i)->type != XML_SCHEMA_TYPE_BASIC) && \
244 (((i)->flags & XML_SCHEMAS_TYPE_INTERNAL_RESOLVED) == 0))
245
246#define WXS_IS_TYPE_NOT_FIXED_1(item) \
247 (((item)->type != XML_SCHEMA_TYPE_BASIC) && \
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +0000248 (((item)->flags & XML_SCHEMAS_TYPE_FIXUP_1) == 0))
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +0000249
250#define WXS_TYPE_IS_GLOBAL(t) ((t)->flags & XML_SCHEMAS_TYPE_GLOBAL)
251
252#define WXS_TYPE_IS_LOCAL(t) (((t)->flags & XML_SCHEMAS_TYPE_GLOBAL) == 0)
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000253/*
254* Macros for exclusively for complex types.
255*/
256#define WXS_HAS_COMPLEX_CONTENT(item) \
257 ((item->contentType == XML_SCHEMA_CONTENT_MIXED) || \
258 (item->contentType == XML_SCHEMA_CONTENT_EMPTY) || \
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +0000259 (item->contentType == XML_SCHEMA_CONTENT_ELEMENTS))
260
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000261#define WXS_HAS_SIMPLE_CONTENT(item) \
262 ((item->contentType == XML_SCHEMA_CONTENT_SIMPLE) || \
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +0000263 (item->contentType == XML_SCHEMA_CONTENT_BASIC))
264
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000265#define WXS_HAS_MIXED_CONTENT(item) \
266 (item->contentType == XML_SCHEMA_CONTENT_MIXED)
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +0000267
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000268#define WXS_EMPTIABLE(t) \
269 (xmlSchemaIsParticleEmptiable(WXS_PTC_CAST (t)->subtypes))
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +0000270
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000271#define WXS_TYPE_CONTENTTYPE(t) (t)->subtypes
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +0000272
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000273#define WXS_TYPE_PARTICLE(t) WXS_PTC_CAST (t)->subtypes
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +0000274
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000275#define WXS_TYPE_PARTICLE_TERM(t) WXS_PARTICLE_TERM(WXS_TYPE_PARTICLE(t))
276/*
277* Macros for exclusively for simple types.
278*/
279#define WXS_LIST_ITEMTYPE(t) (t)->subtypes
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +0000280
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000281#define WXS_IS_ATOMIC(t) (t->flags & XML_SCHEMAS_TYPE_VARIETY_ATOMIC)
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +0000282
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000283#define WXS_IS_LIST(t) (t->flags & XML_SCHEMAS_TYPE_VARIETY_LIST)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +0000284
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000285#define WXS_IS_UNION(t) (t->flags & XML_SCHEMAS_TYPE_VARIETY_UNION)
286/*
287* Misc parser context macros.
288*/
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +0000289#define WXS_CONSTRUCTOR(ctx) (ctx)->constructor
290
291#define WXS_HAS_BUCKETS(ctx) \
292( (WXS_CONSTRUCTOR((ctx))->buckets != NULL) && \
293(WXS_CONSTRUCTOR((ctx))->buckets->nbItems > 0) )
294
295#define WXS_SUBST_GROUPS(ctx) WXS_CONSTRUCTOR((ctx))->substGroups
296
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000297#define WXS_BUCKET(ctx) WXS_CONSTRUCTOR((ctx))->bucket
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +0000298
299#define WXS_SCHEMA(ctx) (ctx)->schema
300
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000301#define WXS_ADD_LOCAL(ctx, item) \
302 xmlSchemaAddItemSize(&(WXS_BUCKET(ctx)->locals), 10, item)
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +0000303
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000304#define WXS_ADD_GLOBAL(ctx, item) \
305 xmlSchemaAddItemSize(&(WXS_BUCKET(ctx)->globals), 5, item)
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +0000306
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000307#define WXS_ADD_PENDING(ctx, item) \
308 xmlSchemaAddItemSize(&((ctx)->constructor->pending), 10, item)
309/*
Kasimier T. Buchcik27820272005-10-14 14:33:48 +0000310* xmlSchemaItemList macros.
311*/
312#define WXS_ILIST_IS_EMPTY(l) ((l == NULL) || ((l)->nbItems == 0))
313/*
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000314* Misc macros.
315*/
316#define IS_SCHEMA(node, type) \
317 ((node != NULL) && (node->ns != NULL) && \
318 (xmlStrEqual(node->name, (const xmlChar *) type)) && \
319 (xmlStrEqual(node->ns->href, xmlSchemaNs)))
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +0000320
Kasimier T. Buchcik27820272005-10-14 14:33:48 +0000321#define FREE_AND_NULL(str) if ((str) != NULL) { xmlFree((xmlChar *) (str)); str = NULL; }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +0000322
323/*
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000324* Since we put the default/fixed values into the dict, we can
325* use pointer comparison for those values.
326* REMOVED: (xmlStrEqual((v1), (v2)))
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +0000327*/
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000328#define WXS_ARE_DEFAULT_STR_EQUAL(v1, v2) ((v1) == (v2))
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +0000329
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000330#define INODE_NILLED(item) (item->flags & XML_SCHEMA_ELEM_INFO_NILLED)
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +0000331
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000332#define CAN_PARSE_SCHEMA(b) (((b)->doc != NULL) && ((b)->parsed == 0))
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +0000333
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000334#define HFAILURE if (res == -1) goto exit_failure;
335
336#define HERROR if (res != 0) goto exit_error;
337
338#define HSTOP(ctx) if ((ctx)->stop) goto exit;
339/*
340* Some flags used for various schema constraints.
341*/
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +0000342#define SUBSET_RESTRICTION 1<<0
343#define SUBSET_EXTENSION 1<<1
344#define SUBSET_SUBSTITUTION 1<<2
345#define SUBSET_LIST 1<<3
346#define SUBSET_UNION 1<<4
347
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +0000348typedef struct _xmlSchemaNodeInfo xmlSchemaNodeInfo;
349typedef xmlSchemaNodeInfo *xmlSchemaNodeInfoPtr;
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +0000350
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +0000351typedef struct _xmlSchemaItemList xmlSchemaItemList;
352typedef xmlSchemaItemList *xmlSchemaItemListPtr;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +0000353struct _xmlSchemaItemList {
Kasimier T. Buchcik87876402004-09-29 13:29:03 +0000354 void **items; /* used for dynamic addition of schemata */
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +0000355 int nbItems; /* used for dynamic addition of schemata */
356 int sizeItems; /* used for dynamic addition of schemata */
357};
358
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000359#define XML_SCHEMA_CTXT_PARSER 1
360#define XML_SCHEMA_CTXT_VALIDATOR 2
361
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +0000362typedef struct _xmlSchemaAbstractCtxt xmlSchemaAbstractCtxt;
363typedef xmlSchemaAbstractCtxt *xmlSchemaAbstractCtxtPtr;
364struct _xmlSchemaAbstractCtxt {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000365 int type; /* E.g. XML_SCHEMA_CTXT_VALIDATOR */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +0000366};
367
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +0000368typedef struct _xmlSchemaBucket xmlSchemaBucket;
369typedef xmlSchemaBucket *xmlSchemaBucketPtr;
370
371#define XML_SCHEMA_SCHEMA_MAIN 0
372#define XML_SCHEMA_SCHEMA_IMPORT 1
373#define XML_SCHEMA_SCHEMA_INCLUDE 2
374#define XML_SCHEMA_SCHEMA_REDEFINE 3
375
Kasimier T. Buchcik630215b2005-08-22 10:15:39 +0000376/**
Daniel Veillarddee23482008-04-11 12:58:43 +0000377 * xmlSchemaSchemaRelation:
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +0000378 *
379 * Used to create a graph of schema relationships.
Kasimier T. Buchcik630215b2005-08-22 10:15:39 +0000380 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +0000381typedef struct _xmlSchemaSchemaRelation xmlSchemaSchemaRelation;
382typedef xmlSchemaSchemaRelation *xmlSchemaSchemaRelationPtr;
383struct _xmlSchemaSchemaRelation {
384 xmlSchemaSchemaRelationPtr next;
385 int type; /* E.g. XML_SCHEMA_SCHEMA_IMPORT */
386 const xmlChar *importNamespace;
387 xmlSchemaBucketPtr bucket;
388};
389
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000390#define XML_SCHEMA_BUCKET_MARKED 1<<0
391#define XML_SCHEMA_BUCKET_COMPS_ADDED 1<<1
392
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +0000393struct _xmlSchemaBucket {
394 int type;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000395 int flags;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +0000396 const xmlChar *schemaLocation;
397 const xmlChar *origTargetNamespace;
398 const xmlChar *targetNamespace;
399 xmlDocPtr doc;
400 xmlSchemaSchemaRelationPtr relations;
401 int located;
402 int parsed;
403 int imported;
404 int preserveDoc;
Daniel Veillarddee23482008-04-11 12:58:43 +0000405 xmlSchemaItemListPtr globals; /* Global components. */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +0000406 xmlSchemaItemListPtr locals; /* Local components. */
407};
408
409/**
Daniel Veillarddee23482008-04-11 12:58:43 +0000410 * xmlSchemaImport:
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +0000411 * (extends xmlSchemaBucket)
412 *
413 * Reflects a schema. Holds some information
414 * about the schema and its toplevel components. Duplicate
415 * toplevel components are not checked at this level.
416 */
417typedef struct _xmlSchemaImport xmlSchemaImport;
418typedef xmlSchemaImport *xmlSchemaImportPtr;
419struct _xmlSchemaImport {
420 int type; /* Main OR import OR include. */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000421 int flags;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +0000422 const xmlChar *schemaLocation; /* The URI of the schema document. */
423 /* For chameleon includes, @origTargetNamespace will be NULL */
424 const xmlChar *origTargetNamespace;
Daniel Veillarddee23482008-04-11 12:58:43 +0000425 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +0000426 * For chameleon includes, @targetNamespace will be the
Daniel Veillarddee23482008-04-11 12:58:43 +0000427 * targetNamespace of the including schema.
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +0000428 */
429 const xmlChar *targetNamespace;
430 xmlDocPtr doc; /* The schema node-tree. */
431 /* @relations will hold any included/imported/redefined schemas. */
432 xmlSchemaSchemaRelationPtr relations;
433 int located;
434 int parsed;
435 int imported;
436 int preserveDoc;
437 xmlSchemaItemListPtr globals;
Kasimier T. Buchcik630215b2005-08-22 10:15:39 +0000438 xmlSchemaItemListPtr locals;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +0000439 /* The imported schema. */
440 xmlSchemaPtr schema;
441};
442
443/*
444* (extends xmlSchemaBucket)
445*/
446typedef struct _xmlSchemaInclude xmlSchemaInclude;
447typedef xmlSchemaInclude *xmlSchemaIncludePtr;
448struct _xmlSchemaInclude {
449 int type;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000450 int flags;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +0000451 const xmlChar *schemaLocation;
452 const xmlChar *origTargetNamespace;
453 const xmlChar *targetNamespace;
454 xmlDocPtr doc;
455 xmlSchemaSchemaRelationPtr relations;
456 int located;
457 int parsed;
458 int imported;
459 int preserveDoc;
Daniel Veillarddee23482008-04-11 12:58:43 +0000460 xmlSchemaItemListPtr globals; /* Global components. */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +0000461 xmlSchemaItemListPtr locals; /* Local components. */
462
463 /* The owning main or import schema bucket. */
464 xmlSchemaImportPtr ownerImport;
465};
466
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +0000467/**
468 * xmlSchemaBasicItem:
469 *
470 * The abstract base type for schema components.
471 */
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +0000472typedef struct _xmlSchemaBasicItem xmlSchemaBasicItem;
473typedef xmlSchemaBasicItem *xmlSchemaBasicItemPtr;
474struct _xmlSchemaBasicItem {
475 xmlSchemaTypeType type;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +0000476};
477
478/**
479 * xmlSchemaAnnotItem:
480 *
481 * The abstract base type for annotated schema components.
482 * (Extends xmlSchemaBasicItem)
483 */
484typedef struct _xmlSchemaAnnotItem xmlSchemaAnnotItem;
485typedef xmlSchemaAnnotItem *xmlSchemaAnnotItemPtr;
486struct _xmlSchemaAnnotItem {
487 xmlSchemaTypeType type;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +0000488 xmlSchemaAnnotPtr annot;
489};
490
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +0000491/**
492 * xmlSchemaTreeItem:
493 *
494 * The abstract base type for tree-like structured schema components.
495 * (Extends xmlSchemaAnnotItem)
496 */
497typedef struct _xmlSchemaTreeItem xmlSchemaTreeItem;
498typedef xmlSchemaTreeItem *xmlSchemaTreeItemPtr;
499struct _xmlSchemaTreeItem {
500 xmlSchemaTypeType type;
501 xmlSchemaAnnotPtr annot;
502 xmlSchemaTreeItemPtr next;
503 xmlSchemaTreeItemPtr children;
504};
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +0000505
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000506
507#define XML_SCHEMA_ATTR_USE_FIXED 1<<0
508/**
509 * xmlSchemaAttributeUsePtr:
510 *
511 * The abstract base type for tree-like structured schema components.
512 * (Extends xmlSchemaTreeItem)
513 */
514typedef struct _xmlSchemaAttributeUse xmlSchemaAttributeUse;
515typedef xmlSchemaAttributeUse *xmlSchemaAttributeUsePtr;
516struct _xmlSchemaAttributeUse {
517 xmlSchemaTypeType type;
518 xmlSchemaAnnotPtr annot;
519 xmlSchemaAttributeUsePtr next; /* The next attr. use. */
Daniel Veillarddee23482008-04-11 12:58:43 +0000520 /*
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000521 * The attr. decl. OR a QName-ref. to an attr. decl. OR
522 * a QName-ref. to an attribute group definition.
523 */
524 xmlSchemaAttributePtr attrDecl;
525
526 int flags;
527 xmlNodePtr node;
528 int occurs; /* required, optional */
529 const xmlChar * defValue;
530 xmlSchemaValPtr defVal;
531};
532
533/**
534 * xmlSchemaAttributeUseProhibPtr:
535 *
536 * A helper component to reflect attribute prohibitions.
537 * (Extends xmlSchemaBasicItem)
538 */
539typedef struct _xmlSchemaAttributeUseProhib xmlSchemaAttributeUseProhib;
540typedef xmlSchemaAttributeUseProhib *xmlSchemaAttributeUseProhibPtr;
541struct _xmlSchemaAttributeUseProhib {
542 xmlSchemaTypeType type; /* == XML_SCHEMA_EXTRA_ATTR_USE_PROHIB */
543 xmlNodePtr node;
544 const xmlChar *name;
545 const xmlChar *targetNamespace;
546 int isRef;
547};
548
549/**
550 * xmlSchemaRedef:
551 */
552typedef struct _xmlSchemaRedef xmlSchemaRedef;
553typedef xmlSchemaRedef *xmlSchemaRedefPtr;
554struct _xmlSchemaRedef {
555 xmlSchemaRedefPtr next;
556 xmlSchemaBasicItemPtr item; /* The redefining component. */
557 xmlSchemaBasicItemPtr reference; /* The referencing component. */
558 xmlSchemaBasicItemPtr target; /* The to-be-redefined component. */
559 const xmlChar *refName; /* The name of the to-be-redefined component. */
560 const xmlChar *refTargetNs; /* The target namespace of the
561 to-be-redefined comp. */
562 xmlSchemaBucketPtr targetBucket; /* The redefined schema. */
563};
564
565/**
566 * xmlSchemaConstructionCtxt:
567 */
568typedef struct _xmlSchemaConstructionCtxt xmlSchemaConstructionCtxt;
569typedef xmlSchemaConstructionCtxt *xmlSchemaConstructionCtxtPtr;
570struct _xmlSchemaConstructionCtxt {
571 xmlSchemaPtr mainSchema; /* The main schema. */
572 xmlSchemaBucketPtr mainBucket; /* The main schema bucket */
573 xmlDictPtr dict;
574 xmlSchemaItemListPtr buckets; /* List of schema buckets. */
575 /* xmlSchemaItemListPtr relations; */ /* List of schema relations. */
Daniel Veillarddee23482008-04-11 12:58:43 +0000576 xmlSchemaBucketPtr bucket; /* The current schema bucket */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000577 xmlSchemaItemListPtr pending; /* All Components of all schemas that
578 need to be fixed. */
579 xmlHashTablePtr substGroups;
580 xmlSchemaRedefPtr redefs;
581 xmlSchemaRedefPtr lastRedef;
582};
583
584#define XML_SCHEMAS_PARSE_ERROR 1
585#define SCHEMAS_PARSE_OPTIONS XML_PARSE_NOENT
586
587struct _xmlSchemaParserCtxt {
588 int type;
Kasimier T. Buchcikb63d2fa2006-04-19 11:20:49 +0000589 void *errCtxt; /* user specific error context */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000590 xmlSchemaValidityErrorFunc error; /* the callback in case of errors */
591 xmlSchemaValidityWarningFunc warning; /* the callback in case of warning */
Kasimier T. Buchcikdfbc33a2006-01-03 10:51:59 +0000592 int err;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000593 int nberrors;
594 xmlStructuredErrorFunc serror;
595
596 xmlSchemaConstructionCtxtPtr constructor;
597 int ownsConstructor; /* TODO: Move this to parser *flags*. */
598
599 /* xmlSchemaPtr topschema; */
600 /* xmlHashTablePtr namespaces; */
601
602 xmlSchemaPtr schema; /* The main schema in use */
603 int counter;
604
605 const xmlChar *URL;
606 xmlDocPtr doc;
607 int preserve; /* Whether the doc should be freed */
608
609 const char *buffer;
610 int size;
611
612 /*
613 * Used to build complex element content models
614 */
615 xmlAutomataPtr am;
616 xmlAutomataStatePtr start;
617 xmlAutomataStatePtr end;
618 xmlAutomataStatePtr state;
619
620 xmlDictPtr dict; /* dictionnary for interned string names */
621 xmlSchemaTypePtr ctxtType; /* The current context simple/complex type */
622 int options;
623 xmlSchemaValidCtxtPtr vctxt;
624 int isS4S;
625 int isRedefine;
626 int xsiAssemble;
627 int stop; /* If the parser should stop; i.e. a critical error. */
628 const xmlChar *targetNamespace;
629 xmlSchemaBucketPtr redefined; /* The schema to be redefined. */
630
631 xmlSchemaRedefPtr redef; /* Used for redefinitions. */
Daniel Veillarddee23482008-04-11 12:58:43 +0000632 int redefCounter; /* Used for redefinitions. */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000633 xmlSchemaItemListPtr attrProhibs;
634};
635
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +0000636/**
637 * xmlSchemaQNameRef:
638 *
639 * A component reference item (not a schema component)
640 * (Extends xmlSchemaBasicItem)
641 */
642typedef struct _xmlSchemaQNameRef xmlSchemaQNameRef;
643typedef xmlSchemaQNameRef *xmlSchemaQNameRefPtr;
644struct _xmlSchemaQNameRef {
645 xmlSchemaTypeType type;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000646 xmlSchemaBasicItemPtr item; /* The resolved referenced item. */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +0000647 xmlSchemaTypeType itemType;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +0000648 const xmlChar *name;
649 const xmlChar *targetNamespace;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000650 xmlNodePtr node;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +0000651};
652
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +0000653/**
654 * xmlSchemaParticle:
655 *
656 * A particle component.
657 * (Extends xmlSchemaTreeItem)
658 */
659typedef struct _xmlSchemaParticle xmlSchemaParticle;
660typedef xmlSchemaParticle *xmlSchemaParticlePtr;
661struct _xmlSchemaParticle {
662 xmlSchemaTypeType type;
663 xmlSchemaAnnotPtr annot;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000664 xmlSchemaTreeItemPtr next; /* next particle */
665 xmlSchemaTreeItemPtr children; /* the "term" (e.g. a model group,
666 a group definition, a XML_SCHEMA_EXTRA_QNAMEREF (if a reference),
667 etc.) */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +0000668 int minOccurs;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +0000669 int maxOccurs;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +0000670 xmlNodePtr node;
671};
672
673/**
674 * xmlSchemaModelGroup:
675 *
676 * A model group component.
677 * (Extends xmlSchemaTreeItem)
678 */
679typedef struct _xmlSchemaModelGroup xmlSchemaModelGroup;
680typedef xmlSchemaModelGroup *xmlSchemaModelGroupPtr;
681struct _xmlSchemaModelGroup {
682 xmlSchemaTypeType type; /* XML_SCHEMA_TYPE_SEQUENCE, XML_SCHEMA_TYPE_CHOICE, XML_SCHEMA_TYPE_ALL */
683 xmlSchemaAnnotPtr annot;
684 xmlSchemaTreeItemPtr next; /* not used */
685 xmlSchemaTreeItemPtr children; /* first particle (OR "element decl" OR "wildcard") */
686 xmlNodePtr node;
687};
688
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +0000689#define XML_SCHEMA_MODEL_GROUP_DEF_MARKED 1<<0
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000690#define XML_SCHEMA_MODEL_GROUP_DEF_REDEFINED 1<<1
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +0000691/**
692 * xmlSchemaModelGroupDef:
693 *
694 * A model group definition component.
695 * (Extends xmlSchemaTreeItem)
696 */
697typedef struct _xmlSchemaModelGroupDef xmlSchemaModelGroupDef;
698typedef xmlSchemaModelGroupDef *xmlSchemaModelGroupDefPtr;
699struct _xmlSchemaModelGroupDef {
700 xmlSchemaTypeType type; /* XML_SCHEMA_TYPE_GROUP */
701 xmlSchemaAnnotPtr annot;
702 xmlSchemaTreeItemPtr next; /* not used */
703 xmlSchemaTreeItemPtr children; /* the "model group" */
704 const xmlChar *name;
705 const xmlChar *targetNamespace;
706 xmlNodePtr node;
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +0000707 int flags;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +0000708};
709
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +0000710typedef struct _xmlSchemaIDC xmlSchemaIDC;
711typedef xmlSchemaIDC *xmlSchemaIDCPtr;
712
713/**
714 * xmlSchemaIDCSelect:
715 *
716 * The identity-constraint "field" and "selector" item, holding the
717 * XPath expression.
718 */
719typedef struct _xmlSchemaIDCSelect xmlSchemaIDCSelect;
720typedef xmlSchemaIDCSelect *xmlSchemaIDCSelectPtr;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +0000721struct _xmlSchemaIDCSelect {
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +0000722 xmlSchemaIDCSelectPtr next;
723 xmlSchemaIDCPtr idc;
724 int index; /* an index position if significant for IDC key-sequences */
725 const xmlChar *xpath; /* the XPath expression */
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +0000726 void *xpathComp; /* the compiled XPath expression */
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +0000727};
728
729/**
730 * xmlSchemaIDC:
731 *
732 * The identity-constraint definition component.
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +0000733 * (Extends xmlSchemaAnnotItem)
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +0000734 */
735
736struct _xmlSchemaIDC {
737 xmlSchemaTypeType type;
738 xmlSchemaAnnotPtr annot;
739 xmlSchemaIDCPtr next;
740 xmlNodePtr node;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +0000741 const xmlChar *name;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +0000742 const xmlChar *targetNamespace;
743 xmlSchemaIDCSelectPtr selector;
744 xmlSchemaIDCSelectPtr fields;
745 int nbFields;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +0000746 xmlSchemaQNameRefPtr ref;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +0000747};
748
749/**
750 * xmlSchemaIDCAug:
751 *
752 * The augmented IDC information used for validation.
753 */
754typedef struct _xmlSchemaIDCAug xmlSchemaIDCAug;
755typedef xmlSchemaIDCAug *xmlSchemaIDCAugPtr;
756struct _xmlSchemaIDCAug {
757 xmlSchemaIDCAugPtr next; /* next in a list */
758 xmlSchemaIDCPtr def; /* the IDC definition */
Kasimier T. Buchcik27820272005-10-14 14:33:48 +0000759 int keyrefDepth; /* the lowest tree level to which IDC
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +0000760 tables need to be bubbled upwards */
761};
762
763/**
764 * xmlSchemaPSVIIDCKeySequence:
765 *
766 * The key sequence of a node table item.
767 */
768typedef struct _xmlSchemaPSVIIDCKey xmlSchemaPSVIIDCKey;
769typedef xmlSchemaPSVIIDCKey *xmlSchemaPSVIIDCKeyPtr;
770struct _xmlSchemaPSVIIDCKey {
771 xmlSchemaTypePtr type;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +0000772 xmlSchemaValPtr val;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +0000773};
774
775/**
776 * xmlSchemaPSVIIDCNode:
777 *
778 * The node table item of a node table.
779 */
780typedef struct _xmlSchemaPSVIIDCNode xmlSchemaPSVIIDCNode;
781typedef xmlSchemaPSVIIDCNode *xmlSchemaPSVIIDCNodePtr;
782struct _xmlSchemaPSVIIDCNode {
783 xmlNodePtr node;
784 xmlSchemaPSVIIDCKeyPtr *keys;
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +0000785 int nodeLine;
Daniel Veillarddee23482008-04-11 12:58:43 +0000786 int nodeQNameID;
Kasimier T. Buchcik630215b2005-08-22 10:15:39 +0000787
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +0000788};
789
790/**
791 * xmlSchemaPSVIIDCBinding:
792 *
793 * The identity-constraint binding item of the [identity-constraint table].
794 */
795typedef struct _xmlSchemaPSVIIDCBinding xmlSchemaPSVIIDCBinding;
796typedef xmlSchemaPSVIIDCBinding *xmlSchemaPSVIIDCBindingPtr;
797struct _xmlSchemaPSVIIDCBinding {
798 xmlSchemaPSVIIDCBindingPtr next; /* next binding of a specific node */
799 xmlSchemaIDCPtr definition; /* the IDC definition */
800 xmlSchemaPSVIIDCNodePtr *nodeTable; /* array of key-sequences */
801 int nbNodes; /* number of entries in the node table */
802 int sizeNodes; /* size of the node table */
Kasimier T. Buchcik27820272005-10-14 14:33:48 +0000803 xmlSchemaItemListPtr dupls;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +0000804};
805
Kasimier T. Buchcik27820272005-10-14 14:33:48 +0000806
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +0000807#define XPATH_STATE_OBJ_TYPE_IDC_SELECTOR 1
808#define XPATH_STATE_OBJ_TYPE_IDC_FIELD 2
809
810#define XPATH_STATE_OBJ_MATCHES -2
811#define XPATH_STATE_OBJ_BLOCKED -3
812
813typedef struct _xmlSchemaIDCMatcher xmlSchemaIDCMatcher;
814typedef xmlSchemaIDCMatcher *xmlSchemaIDCMatcherPtr;
815
816/**
817 * xmlSchemaIDCStateObj:
818 *
819 * The state object used to evaluate XPath expressions.
820 */
821typedef struct _xmlSchemaIDCStateObj xmlSchemaIDCStateObj;
822typedef xmlSchemaIDCStateObj *xmlSchemaIDCStateObjPtr;
823struct _xmlSchemaIDCStateObj {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +0000824 int type;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +0000825 xmlSchemaIDCStateObjPtr next; /* next if in a list */
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +0000826 int depth; /* depth of creation */
827 int *history; /* list of (depth, state-id) tuples */
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +0000828 int nbHistory;
829 int sizeHistory;
830 xmlSchemaIDCMatcherPtr matcher; /* the correspondent field/selector
831 matcher */
832 xmlSchemaIDCSelectPtr sel;
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +0000833 void *xpathCtxt;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +0000834};
835
836#define IDC_MATCHER 0
837
838/**
839 * xmlSchemaIDCMatcher:
840 *
Kasimier T. Buchcik27820272005-10-14 14:33:48 +0000841 * Used to evaluate IDC selectors (and fields).
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +0000842 */
843struct _xmlSchemaIDCMatcher {
844 int type;
845 int depth; /* the tree depth at creation time */
846 xmlSchemaIDCMatcherPtr next; /* next in the list */
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +0000847 xmlSchemaIDCMatcherPtr nextCached; /* next in the cache list */
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +0000848 xmlSchemaIDCAugPtr aidc; /* the augmented IDC item */
Kasimier T. Buchcik27820272005-10-14 14:33:48 +0000849 int idcType;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +0000850 xmlSchemaPSVIIDCKeyPtr **keySeqs; /* the key-sequences of the target
851 elements */
852 int sizeKeySeqs;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +0000853 xmlSchemaItemListPtr targets; /* list of target-node
854 (xmlSchemaPSVIIDCNodePtr) entries */
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +0000855};
856
857/*
858* Element info flags.
859*/
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +0000860#define XML_SCHEMA_NODE_INFO_FLAG_OWNED_NAMES 1<<0
861#define XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES 1<<1
862#define XML_SCHEMA_ELEM_INFO_NILLED 1<<2
863#define XML_SCHEMA_ELEM_INFO_LOCAL_TYPE 1<<3
864
865#define XML_SCHEMA_NODE_INFO_VALUE_NEEDED 1<<4
866#define XML_SCHEMA_ELEM_INFO_EMPTY 1<<5
867#define XML_SCHEMA_ELEM_INFO_HAS_CONTENT 1<<6
868
869#define XML_SCHEMA_ELEM_INFO_HAS_ELEM_CONTENT 1<<7
870#define XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT 1<<8
871#define XML_SCHEMA_NODE_INFO_ERR_NOT_EXPECTED 1<<9
872#define XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE 1<<10
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +0000873
874/**
Kasimier T. Buchcik9b77aa02005-03-04 22:04:16 +0000875 * xmlSchemaNodeInfo:
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +0000876 *
877 * Holds information of an element node.
878 */
Kasimier T. Buchcik9b77aa02005-03-04 22:04:16 +0000879struct _xmlSchemaNodeInfo {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +0000880 int nodeType;
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +0000881 xmlNodePtr node;
Daniel Veillarddee23482008-04-11 12:58:43 +0000882 int nodeLine;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +0000883 const xmlChar *localName;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +0000884 const xmlChar *nsName;
885 const xmlChar *value;
886 xmlSchemaValPtr val; /* the pre-computed value if any */
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +0000887 xmlSchemaTypePtr typeDef; /* the complex/simple type definition if any */
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +0000888
Kasimier T. Buchcik630215b2005-08-22 10:15:39 +0000889 int flags; /* combination of node info flags */
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +0000890
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +0000891 int valNeeded;
892 int normVal;
893
894 xmlSchemaElementPtr decl; /* the element/attribute declaration */
895 int depth;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +0000896 xmlSchemaPSVIIDCBindingPtr idcTable; /* the table of PSVI IDC bindings
897 for the scope element*/
898 xmlSchemaIDCMatcherPtr idcMatchers; /* the IDC matchers for the scope
899 element */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +0000900 xmlRegExecCtxtPtr regexCtxt;
901
902 const xmlChar **nsBindings; /* Namespace bindings on this element */
903 int nbNsBindings;
Daniel Veillarddee23482008-04-11 12:58:43 +0000904 int sizeNsBindings;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +0000905
906 int hasKeyrefs;
Kasimier T. Buchcik65c2f1d2005-10-17 12:39:58 +0000907 int appliedXPath; /* Indicates that an XPath has been applied. */
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +0000908};
909
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000910#define XML_SCHEMAS_ATTR_UNKNOWN 1
911#define XML_SCHEMAS_ATTR_ASSESSED 2
912#define XML_SCHEMAS_ATTR_PROHIBITED 3
913#define XML_SCHEMAS_ATTR_ERR_MISSING 4
914#define XML_SCHEMAS_ATTR_INVALID_VALUE 5
915#define XML_SCHEMAS_ATTR_ERR_NO_TYPE 6
916#define XML_SCHEMAS_ATTR_ERR_FIXED_VALUE 7
917#define XML_SCHEMAS_ATTR_DEFAULT 8
918#define XML_SCHEMAS_ATTR_VALIDATE_VALUE 9
919#define XML_SCHEMAS_ATTR_ERR_WILD_STRICT_NO_DECL 10
920#define XML_SCHEMAS_ATTR_HAS_ATTR_USE 11
921#define XML_SCHEMAS_ATTR_HAS_ATTR_DECL 12
922#define XML_SCHEMAS_ATTR_WILD_SKIP 13
923#define XML_SCHEMAS_ATTR_WILD_LAX_NO_DECL 14
924#define XML_SCHEMAS_ATTR_ERR_WILD_DUPLICATE_ID 15
925#define XML_SCHEMAS_ATTR_ERR_WILD_AND_USE_ID 16
926#define XML_SCHEMAS_ATTR_META 17
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +0000927/*
928* @metaType values of xmlSchemaAttrInfo.
929*/
930#define XML_SCHEMA_ATTR_INFO_META_XSI_TYPE 1
931#define XML_SCHEMA_ATTR_INFO_META_XSI_NIL 2
932#define XML_SCHEMA_ATTR_INFO_META_XSI_SCHEMA_LOC 3
933#define XML_SCHEMA_ATTR_INFO_META_XSI_NO_NS_SCHEMA_LOC 4
934#define XML_SCHEMA_ATTR_INFO_META_XMLNS 5
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +0000935
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +0000936typedef struct _xmlSchemaAttrInfo xmlSchemaAttrInfo;
937typedef xmlSchemaAttrInfo *xmlSchemaAttrInfoPtr;
938struct _xmlSchemaAttrInfo {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +0000939 int nodeType;
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +0000940 xmlNodePtr node;
Daniel Veillarddee23482008-04-11 12:58:43 +0000941 int nodeLine;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +0000942 const xmlChar *localName;
943 const xmlChar *nsName;
944 const xmlChar *value;
945 xmlSchemaValPtr val; /* the pre-computed value if any */
946 xmlSchemaTypePtr typeDef; /* the complex/simple type definition if any */
947 int flags; /* combination of node info flags */
948
949 xmlSchemaAttributePtr decl; /* the attribute declaration */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +0000950 xmlSchemaAttributeUsePtr use; /* the attribute use */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +0000951 int state;
952 int metaType;
953 const xmlChar *vcValue; /* the value constraint value */
954 xmlSchemaNodeInfoPtr parent;
955};
956
957
958#define XML_SCHEMA_VALID_CTXT_FLAG_STREAM 1
Daniel Veillard4255d502002-04-16 15:50:10 +0000959/**
960 * xmlSchemaValidCtxt:
961 *
962 * A Schemas validation context
963 */
Daniel Veillard4255d502002-04-16 15:50:10 +0000964struct _xmlSchemaValidCtxt {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +0000965 int type;
Kasimier T. Buchcik90b5ebc2005-11-18 17:18:27 +0000966 void *errCtxt; /* user specific data block */
Daniel Veillardd0c9c322003-10-10 00:49:42 +0000967 xmlSchemaValidityErrorFunc error; /* the callback in case of errors */
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +0000968 xmlSchemaValidityWarningFunc warning; /* the callback in case of warning */
Daniel Veillard659e71e2003-10-10 14:10:40 +0000969 xmlStructuredErrorFunc serror;
Daniel Veillard4255d502002-04-16 15:50:10 +0000970
Daniel Veillardd0c9c322003-10-10 00:49:42 +0000971 xmlSchemaPtr schema; /* The schema in use */
972 xmlDocPtr doc;
Daniel Veillard4255d502002-04-16 15:50:10 +0000973 xmlParserInputBufferPtr input;
Daniel Veillardd0c9c322003-10-10 00:49:42 +0000974 xmlCharEncoding enc;
975 xmlSAXHandlerPtr sax;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +0000976 xmlParserCtxtPtr parserCtxt;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +0000977 void *user_data; /* TODO: What is this for? */
Daniel Veillard4255d502002-04-16 15:50:10 +0000978
Daniel Veillardd0c9c322003-10-10 00:49:42 +0000979 int err;
980 int nberrors;
Daniel Veillard4255d502002-04-16 15:50:10 +0000981
Daniel Veillardd0c9c322003-10-10 00:49:42 +0000982 xmlNodePtr node;
983 xmlNodePtr cur;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +0000984 /* xmlSchemaTypePtr type; */
Daniel Veillard4255d502002-04-16 15:50:10 +0000985
Daniel Veillardd0c9c322003-10-10 00:49:42 +0000986 xmlRegExecCtxtPtr regexp;
987 xmlSchemaValPtr value;
Daniel Veillard4255d502002-04-16 15:50:10 +0000988
Daniel Veillardc0826a72004-08-10 14:17:33 +0000989 int valueWS;
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +0000990 int options;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +0000991 xmlNodePtr validationRoot;
Kasimier T. Buchcik87876402004-09-29 13:29:03 +0000992 xmlSchemaParserCtxtPtr pctxt;
993 int xsiAssemble;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +0000994
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +0000995 int depth;
Kasimier T. Buchcik9b77aa02005-03-04 22:04:16 +0000996 xmlSchemaNodeInfoPtr *elemInfos; /* array of element informations */
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +0000997 int sizeElemInfos;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +0000998 xmlSchemaNodeInfoPtr inode; /* the current element information */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +0000999
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00001000 xmlSchemaIDCAugPtr aidcs; /* a list of augmented IDC informations */
1001
1002 xmlSchemaIDCStateObjPtr xpathStates; /* first active state object. */
1003 xmlSchemaIDCStateObjPtr xpathStatePool; /* first stored state object. */
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +00001004 xmlSchemaIDCMatcherPtr idcMatcherCache; /* Cache for IDC matcher objects. */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001005
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00001006 xmlSchemaPSVIIDCNodePtr *idcNodes; /* list of all IDC node-table entries*/
1007 int nbIdcNodes;
1008 int sizeIdcNodes;
1009
1010 xmlSchemaPSVIIDCKeyPtr *idcKeys; /* list of all IDC node-table entries */
1011 int nbIdcKeys;
1012 int sizeIdcKeys;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00001013
1014 int flags;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001015
1016 xmlDictPtr dict;
1017
Daniel Veillard39e5c892005-07-03 22:48:50 +00001018#ifdef LIBXML_READER_ENABLED
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001019 xmlTextReaderPtr reader;
Daniel Veillard39e5c892005-07-03 22:48:50 +00001020#endif
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001021
1022 xmlSchemaAttrInfoPtr *attrInfos;
1023 int nbAttrInfos;
1024 int sizeAttrInfos;
1025
1026 int skipDepth;
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +00001027 xmlSchemaItemListPtr nodeQNames;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +00001028 int hasKeyrefs;
1029 int createIDCNodeTables;
1030 int psviExposeIDCNodeTables;
Daniel Veillard4255d502002-04-16 15:50:10 +00001031};
1032
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +00001033/**
1034 * xmlSchemaSubstGroup:
1035 *
1036 *
1037 */
1038typedef struct _xmlSchemaSubstGroup xmlSchemaSubstGroup;
1039typedef xmlSchemaSubstGroup *xmlSchemaSubstGroupPtr;
1040struct _xmlSchemaSubstGroup {
1041 xmlSchemaElementPtr head;
1042 xmlSchemaItemListPtr members;
1043};
1044
Daniel Veillard4255d502002-04-16 15:50:10 +00001045/************************************************************************
1046 * *
1047 * Some predeclarations *
1048 * *
1049 ************************************************************************/
Daniel Veillardd0c9c322003-10-10 00:49:42 +00001050
Daniel Veillardbd2904b2003-11-25 15:38:59 +00001051static int xmlSchemaParseInclude(xmlSchemaParserCtxtPtr ctxt,
1052 xmlSchemaPtr schema,
1053 xmlNodePtr node);
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +00001054static int xmlSchemaParseRedefine(xmlSchemaParserCtxtPtr ctxt,
1055 xmlSchemaPtr schema,
1056 xmlNodePtr node);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00001057static int
1058xmlSchemaTypeFixup(xmlSchemaTypePtr type,
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +00001059 xmlSchemaAbstractCtxtPtr ctxt);
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +00001060static const xmlChar *
Daniel Veillard01fa6152004-06-29 17:04:39 +00001061xmlSchemaFacetTypeToString(xmlSchemaTypeType type);
1062static int
William M. Brack2f2a6632004-08-20 23:09:47 +00001063xmlSchemaParseImport(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
1064 xmlNodePtr node);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00001065static int
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00001066xmlSchemaCheckFacetValues(xmlSchemaTypePtr typeDecl,
1067 xmlSchemaParserCtxtPtr ctxt);
Kasimier T. Buchcik7f3efa92005-03-07 17:41:58 +00001068static void
1069xmlSchemaClearValidCtxt(xmlSchemaValidCtxtPtr vctxt);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001070static xmlSchemaWhitespaceValueType
Kasimier T. Buchcik478d6932005-03-16 16:29:18 +00001071xmlSchemaGetWhiteSpaceFacetValue(xmlSchemaTypePtr type);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00001072static xmlSchemaTreeItemPtr
1073xmlSchemaParseModelGroup(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
1074 xmlNodePtr node, xmlSchemaTypeType type,
1075 int withParticle);
1076static const xmlChar *
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001077xmlSchemaGetComponentTypeStr(xmlSchemaBasicItemPtr item);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00001078static xmlSchemaTypeLinkPtr
1079xmlSchemaGetUnionSimpleTypeMemberTypes(xmlSchemaTypePtr type);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001080static void
1081xmlSchemaInternalErr(xmlSchemaAbstractCtxtPtr actxt,
1082 const char *funcName,
1083 const char *message);
1084static int
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +00001085xmlSchemaCheckCOSSTDerivedOK(xmlSchemaAbstractCtxtPtr ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001086 xmlSchemaTypePtr type,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001087 xmlSchemaTypePtr baseType,
1088 int subset);
1089static void
1090xmlSchemaCheckElementDeclComponent(xmlSchemaElementPtr elemDecl,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00001091 xmlSchemaParserCtxtPtr ctxt);
1092static void
1093xmlSchemaComponentListFree(xmlSchemaItemListPtr list);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001094static xmlSchemaQNameRefPtr
1095xmlSchemaParseAttributeGroupRef(xmlSchemaParserCtxtPtr pctxt,
1096 xmlSchemaPtr schema,
1097 xmlNodePtr node);
William M. Brack87640d52004-04-17 14:58:15 +00001098
Daniel Veillardd0c9c322003-10-10 00:49:42 +00001099/************************************************************************
1100 * *
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001101 * Helper functions *
Daniel Veillardd0c9c322003-10-10 00:49:42 +00001102 * *
1103 ************************************************************************/
1104
1105/**
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001106 * xmlSchemaItemTypeToStr:
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001107 * @type: the type of the schema item
1108 *
1109 * Returns the component name of a schema item.
1110 */
1111static const xmlChar *
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001112xmlSchemaItemTypeToStr(xmlSchemaTypeType type)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001113{
1114 switch (type) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001115 case XML_SCHEMA_TYPE_BASIC:
1116 return(BAD_CAST "simple type definition");
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001117 case XML_SCHEMA_TYPE_SIMPLE:
1118 return(BAD_CAST "simple type definition");
1119 case XML_SCHEMA_TYPE_COMPLEX:
1120 return(BAD_CAST "complex type definition");
1121 case XML_SCHEMA_TYPE_ELEMENT:
1122 return(BAD_CAST "element declaration");
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001123 case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
1124 return(BAD_CAST "attribute use");
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001125 case XML_SCHEMA_TYPE_ATTRIBUTE:
1126 return(BAD_CAST "attribute declaration");
1127 case XML_SCHEMA_TYPE_GROUP:
1128 return(BAD_CAST "model group definition");
1129 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1130 return(BAD_CAST "attribute group definition");
1131 case XML_SCHEMA_TYPE_NOTATION:
1132 return(BAD_CAST "notation declaration");
1133 case XML_SCHEMA_TYPE_SEQUENCE:
1134 return(BAD_CAST "model group (sequence)");
1135 case XML_SCHEMA_TYPE_CHOICE:
1136 return(BAD_CAST "model group (choice)");
1137 case XML_SCHEMA_TYPE_ALL:
1138 return(BAD_CAST "model group (all)");
1139 case XML_SCHEMA_TYPE_PARTICLE:
1140 return(BAD_CAST "particle");
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +00001141 case XML_SCHEMA_TYPE_IDC_UNIQUE:
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00001142 return(BAD_CAST "unique identity-constraint");
1143 /* return(BAD_CAST "IDC (unique)"); */
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +00001144 case XML_SCHEMA_TYPE_IDC_KEY:
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00001145 return(BAD_CAST "key identity-constraint");
1146 /* return(BAD_CAST "IDC (key)"); */
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +00001147 case XML_SCHEMA_TYPE_IDC_KEYREF:
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00001148 return(BAD_CAST "keyref identity-constraint");
1149 /* return(BAD_CAST "IDC (keyref)"); */
Kasimier T. Buchcik11162b72005-07-28 00:50:22 +00001150 case XML_SCHEMA_TYPE_ANY:
1151 return(BAD_CAST "wildcard (any)");
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +00001152 case XML_SCHEMA_EXTRA_QNAMEREF:
1153 return(BAD_CAST "[helper component] QName reference");
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001154 case XML_SCHEMA_EXTRA_ATTR_USE_PROHIB:
1155 return(BAD_CAST "[helper component] attribute use prohibition");
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001156 default:
1157 return(BAD_CAST "Not a schema component");
1158 }
1159}
1160
1161/**
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001162 * xmlSchemaGetComponentTypeStr:
1163 * @type: the type of the schema item
1164 *
1165 * Returns the component name of a schema item.
1166 */
1167static const xmlChar *
1168xmlSchemaGetComponentTypeStr(xmlSchemaBasicItemPtr item)
1169{
1170 switch (item->type) {
1171 case XML_SCHEMA_TYPE_BASIC:
1172 if (WXS_IS_COMPLEX(WXS_TYPE_CAST item))
1173 return(BAD_CAST "complex type definition");
1174 else
Daniel Veillarddee23482008-04-11 12:58:43 +00001175 return(BAD_CAST "simple type definition");
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001176 default:
1177 return(xmlSchemaItemTypeToStr(item->type));
1178 }
1179}
1180
1181/**
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001182 * xmlSchemaGetComponentNode:
1183 * @item: a schema component
1184 *
1185 * Returns node associated with the schema component.
1186 * NOTE that such a node need not be available; plus, a component's
1187 * node need not to reflect the component directly, since there is no
1188 * one-to-one relationship between the XML Schema representation and
1189 * the component representation.
1190 */
1191static xmlNodePtr
1192xmlSchemaGetComponentNode(xmlSchemaBasicItemPtr item)
1193{
1194 switch (item->type) {
1195 case XML_SCHEMA_TYPE_ELEMENT:
1196 return (((xmlSchemaElementPtr) item)->node);
1197 case XML_SCHEMA_TYPE_ATTRIBUTE:
1198 return (((xmlSchemaAttributePtr) item)->node);
1199 case XML_SCHEMA_TYPE_COMPLEX:
1200 case XML_SCHEMA_TYPE_SIMPLE:
1201 return (((xmlSchemaTypePtr) item)->node);
1202 case XML_SCHEMA_TYPE_ANY:
1203 case XML_SCHEMA_TYPE_ANY_ATTRIBUTE:
1204 return (((xmlSchemaWildcardPtr) item)->node);
1205 case XML_SCHEMA_TYPE_PARTICLE:
1206 return (((xmlSchemaParticlePtr) item)->node);
1207 case XML_SCHEMA_TYPE_SEQUENCE:
1208 case XML_SCHEMA_TYPE_CHOICE:
1209 case XML_SCHEMA_TYPE_ALL:
1210 return (((xmlSchemaModelGroupPtr) item)->node);
1211 case XML_SCHEMA_TYPE_GROUP:
1212 return (((xmlSchemaModelGroupDefPtr) item)->node);
1213 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1214 return (((xmlSchemaAttributeGroupPtr) item)->node);
1215 case XML_SCHEMA_TYPE_IDC_UNIQUE:
1216 case XML_SCHEMA_TYPE_IDC_KEY:
1217 case XML_SCHEMA_TYPE_IDC_KEYREF:
1218 return (((xmlSchemaIDCPtr) item)->node);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001219 case XML_SCHEMA_EXTRA_QNAMEREF:
1220 return(((xmlSchemaQNameRefPtr) item)->node);
1221 /* TODO: What to do with NOTATIONs?
1222 case XML_SCHEMA_TYPE_NOTATION:
1223 return (((xmlSchemaNotationPtr) item)->node);
1224 */
1225 case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
1226 return (((xmlSchemaAttributeUsePtr) item)->node);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001227 default:
1228 return (NULL);
1229 }
1230}
1231
1232#if 0
1233/**
1234 * xmlSchemaGetNextComponent:
1235 * @item: a schema component
1236 *
1237 * Returns the next sibling of the schema component.
1238 */
1239static xmlSchemaBasicItemPtr
1240xmlSchemaGetNextComponent(xmlSchemaBasicItemPtr item)
1241{
1242 switch (item->type) {
1243 case XML_SCHEMA_TYPE_ELEMENT:
1244 return ((xmlSchemaBasicItemPtr) ((xmlSchemaElementPtr) item)->next);
1245 case XML_SCHEMA_TYPE_ATTRIBUTE:
1246 return ((xmlSchemaBasicItemPtr) ((xmlSchemaAttributePtr) item)->next);
1247 case XML_SCHEMA_TYPE_COMPLEX:
1248 case XML_SCHEMA_TYPE_SIMPLE:
1249 return ((xmlSchemaBasicItemPtr) ((xmlSchemaTypePtr) item)->next);
1250 case XML_SCHEMA_TYPE_ANY:
1251 case XML_SCHEMA_TYPE_ANY_ATTRIBUTE:
1252 return (NULL);
1253 case XML_SCHEMA_TYPE_PARTICLE:
1254 return ((xmlSchemaBasicItemPtr) ((xmlSchemaParticlePtr) item)->next);
1255 case XML_SCHEMA_TYPE_SEQUENCE:
1256 case XML_SCHEMA_TYPE_CHOICE:
1257 case XML_SCHEMA_TYPE_ALL:
1258 return (NULL);
1259 case XML_SCHEMA_TYPE_GROUP:
1260 return (NULL);
1261 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1262 return ((xmlSchemaBasicItemPtr) ((xmlSchemaAttributeGroupPtr) item)->next);
1263 case XML_SCHEMA_TYPE_IDC_UNIQUE:
1264 case XML_SCHEMA_TYPE_IDC_KEY:
1265 case XML_SCHEMA_TYPE_IDC_KEYREF:
1266 return ((xmlSchemaBasicItemPtr) ((xmlSchemaIDCPtr) item)->next);
1267 default:
1268 return (NULL);
1269 }
1270}
1271#endif
1272
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001273
1274/**
1275 * xmlSchemaFormatQName:
1276 * @buf: the string buffer
1277 * @namespaceName: the namespace name
1278 * @localName: the local name
1279 *
1280 * Returns the given QName in the format "{namespaceName}localName" or
1281 * just "localName" if @namespaceName is NULL.
1282 *
1283 * Returns the localName if @namespaceName is NULL, a formatted
1284 * string otherwise.
1285 */
1286static const xmlChar*
1287xmlSchemaFormatQName(xmlChar **buf,
1288 const xmlChar *namespaceName,
1289 const xmlChar *localName)
1290{
1291 FREE_AND_NULL(*buf)
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001292 if (namespaceName != NULL) {
1293 *buf = xmlStrdup(BAD_CAST "{");
1294 *buf = xmlStrcat(*buf, namespaceName);
1295 *buf = xmlStrcat(*buf, BAD_CAST "}");
1296 }
1297 if (localName != NULL) {
1298 if (namespaceName == NULL)
1299 return(localName);
1300 *buf = xmlStrcat(*buf, localName);
1301 } else {
1302 *buf = xmlStrcat(*buf, BAD_CAST "(NULL)");
Daniel Veillarddee23482008-04-11 12:58:43 +00001303 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001304 return ((const xmlChar *) *buf);
1305}
1306
Daniel Veillarddee23482008-04-11 12:58:43 +00001307static const xmlChar*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001308xmlSchemaFormatQNameNs(xmlChar **buf, xmlNsPtr ns, const xmlChar *localName)
1309{
1310 if (ns != NULL)
1311 return (xmlSchemaFormatQName(buf, ns->href, localName));
1312 else
1313 return (xmlSchemaFormatQName(buf, NULL, localName));
1314}
1315
1316static const xmlChar *
1317xmlSchemaGetComponentName(xmlSchemaBasicItemPtr item)
1318{
1319 switch (item->type) {
1320 case XML_SCHEMA_TYPE_ELEMENT:
1321 return (((xmlSchemaElementPtr) item)->name);
1322 case XML_SCHEMA_TYPE_ATTRIBUTE:
1323 return (((xmlSchemaAttributePtr) item)->name);
1324 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1325 return (((xmlSchemaAttributeGroupPtr) item)->name);
1326 case XML_SCHEMA_TYPE_BASIC:
1327 case XML_SCHEMA_TYPE_SIMPLE:
1328 case XML_SCHEMA_TYPE_COMPLEX:
1329 return (((xmlSchemaTypePtr) item)->name);
1330 case XML_SCHEMA_TYPE_GROUP:
1331 return (((xmlSchemaModelGroupDefPtr) item)->name);
1332 case XML_SCHEMA_TYPE_IDC_KEY:
1333 case XML_SCHEMA_TYPE_IDC_UNIQUE:
1334 case XML_SCHEMA_TYPE_IDC_KEYREF:
1335 return (((xmlSchemaIDCPtr) item)->name);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001336 case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
1337 if (WXS_ATTRUSE_DECL(item) != NULL) {
1338 return(xmlSchemaGetComponentName(
1339 WXS_BASIC_CAST WXS_ATTRUSE_DECL(item)));
1340 } else
1341 return(NULL);
1342 case XML_SCHEMA_EXTRA_QNAMEREF:
1343 return (((xmlSchemaQNameRefPtr) item)->name);
1344 case XML_SCHEMA_TYPE_NOTATION:
1345 return (((xmlSchemaNotationPtr) item)->name);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001346 default:
1347 /*
1348 * Other components cannot have names.
1349 */
1350 break;
1351 }
1352 return (NULL);
1353}
1354
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001355#define xmlSchemaGetQNameRefName(r) (WXS_QNAME_CAST (r))->name
1356#define xmlSchemaGetQNameRefTargetNs(r) (WXS_QNAME_CAST (r))->targetNamespace
1357/*
1358static const xmlChar *
1359xmlSchemaGetQNameRefName(void *ref)
1360{
1361 return(((xmlSchemaQNameRefPtr) ref)->name);
1362}
1363
1364static const xmlChar *
1365xmlSchemaGetQNameRefTargetNs(void *ref)
1366{
1367 return(((xmlSchemaQNameRefPtr) ref)->targetNamespace);
1368}
1369*/
1370
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001371static const xmlChar *
1372xmlSchemaGetComponentTargetNs(xmlSchemaBasicItemPtr item)
1373{
1374 switch (item->type) {
1375 case XML_SCHEMA_TYPE_ELEMENT:
1376 return (((xmlSchemaElementPtr) item)->targetNamespace);
1377 case XML_SCHEMA_TYPE_ATTRIBUTE:
1378 return (((xmlSchemaAttributePtr) item)->targetNamespace);
1379 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1380 return (((xmlSchemaAttributeGroupPtr) item)->targetNamespace);
1381 case XML_SCHEMA_TYPE_BASIC:
1382 return (BAD_CAST "http://www.w3.org/2001/XMLSchema");
1383 case XML_SCHEMA_TYPE_SIMPLE:
1384 case XML_SCHEMA_TYPE_COMPLEX:
1385 return (((xmlSchemaTypePtr) item)->targetNamespace);
1386 case XML_SCHEMA_TYPE_GROUP:
1387 return (((xmlSchemaModelGroupDefPtr) item)->targetNamespace);
1388 case XML_SCHEMA_TYPE_IDC_KEY:
1389 case XML_SCHEMA_TYPE_IDC_UNIQUE:
1390 case XML_SCHEMA_TYPE_IDC_KEYREF:
1391 return (((xmlSchemaIDCPtr) item)->targetNamespace);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001392 case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
1393 if (WXS_ATTRUSE_DECL(item) != NULL) {
1394 return(xmlSchemaGetComponentTargetNs(
1395 WXS_BASIC_CAST WXS_ATTRUSE_DECL(item)));
1396 }
1397 /* TODO: Will returning NULL break something? */
1398 break;
1399 case XML_SCHEMA_EXTRA_QNAMEREF:
1400 return (((xmlSchemaQNameRefPtr) item)->targetNamespace);
1401 case XML_SCHEMA_TYPE_NOTATION:
1402 return (((xmlSchemaNotationPtr) item)->targetNamespace);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001403 default:
1404 /*
1405 * Other components cannot have names.
1406 */
1407 break;
1408 }
1409 return (NULL);
1410}
1411
1412static const xmlChar*
1413xmlSchemaGetComponentQName(xmlChar **buf,
1414 void *item)
1415{
1416 return (xmlSchemaFormatQName(buf,
1417 xmlSchemaGetComponentTargetNs((xmlSchemaBasicItemPtr) item),
1418 xmlSchemaGetComponentName((xmlSchemaBasicItemPtr) item)));
1419}
1420
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00001421static const xmlChar*
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001422xmlSchemaGetComponentDesignation(xmlChar **buf, void *item)
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00001423{
1424 xmlChar *str = NULL;
1425
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001426 *buf = xmlStrcat(*buf, WXS_ITEM_TYPE_NAME(item));
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00001427 *buf = xmlStrcat(*buf, BAD_CAST " '");
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001428 *buf = xmlStrcat(*buf, xmlSchemaGetComponentQName(&str,
1429 (xmlSchemaBasicItemPtr) item));
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00001430 *buf = xmlStrcat(*buf, BAD_CAST "'");
1431 FREE_AND_NULL(str);
1432 return(*buf);
1433}
1434
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001435static const xmlChar*
1436xmlSchemaGetIDCDesignation(xmlChar **buf, xmlSchemaIDCPtr idc)
1437{
1438 return(xmlSchemaGetComponentDesignation(buf, idc));
1439}
1440
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001441/**
1442 * xmlSchemaWildcardPCToString:
1443 * @pc: the type of processContents
1444 *
1445 * Returns a string representation of the type of
1446 * processContents.
1447 */
1448static const xmlChar *
1449xmlSchemaWildcardPCToString(int pc)
1450{
1451 switch (pc) {
1452 case XML_SCHEMAS_ANY_SKIP:
1453 return (BAD_CAST "skip");
1454 case XML_SCHEMAS_ANY_LAX:
1455 return (BAD_CAST "lax");
1456 case XML_SCHEMAS_ANY_STRICT:
1457 return (BAD_CAST "strict");
1458 default:
1459 return (BAD_CAST "invalid process contents");
1460 }
1461}
1462
1463/**
1464 * xmlSchemaGetCanonValueWhtspExt:
1465 * @val: the precomputed value
1466 * @retValue: the returned value
1467 * @ws: the whitespace type of the value
1468 *
1469 * Get a the cononical representation of the value.
1470 * The caller has to free the returned retValue.
1471 *
1472 * Returns 0 if the value could be built and -1 in case of
1473 * API errors or if the value type is not supported yet.
1474 */
1475static int
1476xmlSchemaGetCanonValueWhtspExt(xmlSchemaValPtr val,
1477 xmlSchemaWhitespaceValueType ws,
1478 xmlChar **retValue)
1479{
1480 int list;
1481 xmlSchemaValType valType;
1482 const xmlChar *value, *value2 = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +00001483
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001484
1485 if ((retValue == NULL) || (val == NULL))
1486 return (-1);
1487 list = xmlSchemaValueGetNext(val) ? 1 : 0;
1488 *retValue = NULL;
1489 do {
Daniel Veillarddee23482008-04-11 12:58:43 +00001490 value = NULL;
1491 valType = xmlSchemaGetValType(val);
1492 switch (valType) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001493 case XML_SCHEMAS_STRING:
1494 case XML_SCHEMAS_NORMSTRING:
1495 case XML_SCHEMAS_ANYSIMPLETYPE:
1496 value = xmlSchemaValueGetAsString(val);
1497 if (value != NULL) {
1498 if (ws == XML_SCHEMA_WHITESPACE_COLLAPSE)
1499 value2 = xmlSchemaCollapseString(value);
1500 else if (ws == XML_SCHEMA_WHITESPACE_REPLACE)
1501 value2 = xmlSchemaWhiteSpaceReplace(value);
1502 if (value2 != NULL)
1503 value = value2;
1504 }
Daniel Veillarddee23482008-04-11 12:58:43 +00001505 break;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001506 default:
1507 if (xmlSchemaGetCanonValue(val, &value2) == -1) {
1508 if (value2 != NULL)
1509 xmlFree((xmlChar *) value2);
1510 goto internal_error;
1511 }
1512 value = value2;
1513 }
1514 if (*retValue == NULL)
1515 if (value == NULL) {
1516 if (! list)
1517 *retValue = xmlStrdup(BAD_CAST "");
1518 } else
1519 *retValue = xmlStrdup(value);
1520 else if (value != NULL) {
1521 /* List. */
1522 *retValue = xmlStrcat((xmlChar *) *retValue, BAD_CAST " ");
1523 *retValue = xmlStrcat((xmlChar *) *retValue, value);
1524 }
1525 FREE_AND_NULL(value2)
1526 val = xmlSchemaValueGetNext(val);
1527 } while (val != NULL);
1528
1529 return (0);
1530internal_error:
1531 if (*retValue != NULL)
1532 xmlFree((xmlChar *) (*retValue));
1533 if (value2 != NULL)
1534 xmlFree((xmlChar *) value2);
1535 return (-1);
1536}
1537
1538/**
1539 * xmlSchemaFormatItemForReport:
1540 * @buf: the string buffer
1541 * @itemDes: the designation of the item
1542 * @itemName: the name of the item
Daniel Veillarddee23482008-04-11 12:58:43 +00001543 * @item: the item as an object
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001544 * @itemNode: the node of the item
1545 * @local: the local name
1546 * @parsing: if the function is used during the parse
1547 *
1548 * Returns a representation of the given item used
Daniel Veillarddee23482008-04-11 12:58:43 +00001549 * for error reports.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001550 *
Daniel Veillarddee23482008-04-11 12:58:43 +00001551 * The following order is used to build the resulting
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001552 * designation if the arguments are not NULL:
1553 * 1a. If itemDes not NULL -> itemDes
1554 * 1b. If (itemDes not NULL) and (itemName not NULL)
1555 * -> itemDes + itemName
1556 * 2. If the preceding was NULL and (item not NULL) -> item
1557 * 3. If the preceding was NULL and (itemNode not NULL) -> itemNode
Daniel Veillarddee23482008-04-11 12:58:43 +00001558 *
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001559 * If the itemNode is an attribute node, the name of the attribute
1560 * will be appended to the result.
1561 *
1562 * Returns the formatted string and sets @buf to the resulting value.
Daniel Veillarddee23482008-04-11 12:58:43 +00001563 */
1564static xmlChar*
1565xmlSchemaFormatItemForReport(xmlChar **buf,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001566 const xmlChar *itemDes,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001567 xmlSchemaBasicItemPtr item,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001568 xmlNodePtr itemNode)
1569{
1570 xmlChar *str = NULL;
1571 int named = 1;
1572
1573 if (*buf != NULL) {
1574 xmlFree(*buf);
1575 *buf = NULL;
1576 }
Daniel Veillarddee23482008-04-11 12:58:43 +00001577
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001578 if (itemDes != NULL) {
Daniel Veillarddee23482008-04-11 12:58:43 +00001579 *buf = xmlStrdup(itemDes);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001580 } else if (item != NULL) {
1581 switch (item->type) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001582 case XML_SCHEMA_TYPE_BASIC: {
1583 xmlSchemaTypePtr type = WXS_TYPE_CAST item;
1584
1585 if (WXS_IS_ATOMIC(type))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001586 *buf = xmlStrdup(BAD_CAST "atomic type 'xs:");
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001587 else if (WXS_IS_LIST(type))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001588 *buf = xmlStrdup(BAD_CAST "list type 'xs:");
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001589 else if (WXS_IS_UNION(type))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001590 *buf = xmlStrdup(BAD_CAST "union type 'xs:");
1591 else
1592 *buf = xmlStrdup(BAD_CAST "simple type 'xs:");
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001593 *buf = xmlStrcat(*buf, type->name);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001594 *buf = xmlStrcat(*buf, BAD_CAST "'");
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001595 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001596 break;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001597 case XML_SCHEMA_TYPE_SIMPLE: {
1598 xmlSchemaTypePtr type = WXS_TYPE_CAST item;
1599
1600 if (type->flags & XML_SCHEMAS_TYPE_GLOBAL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001601 *buf = xmlStrdup(BAD_CAST"");
1602 } else {
1603 *buf = xmlStrdup(BAD_CAST "local ");
1604 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001605 if (WXS_IS_ATOMIC(type))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001606 *buf = xmlStrcat(*buf, BAD_CAST "atomic type");
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001607 else if (WXS_IS_LIST(type))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001608 *buf = xmlStrcat(*buf, BAD_CAST "list type");
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001609 else if (WXS_IS_UNION(type))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001610 *buf = xmlStrcat(*buf, BAD_CAST "union type");
1611 else
1612 *buf = xmlStrcat(*buf, BAD_CAST "simple type");
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001613 if (type->flags & XML_SCHEMAS_TYPE_GLOBAL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001614 *buf = xmlStrcat(*buf, BAD_CAST " '");
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001615 *buf = xmlStrcat(*buf, type->name);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001616 *buf = xmlStrcat(*buf, BAD_CAST "'");
1617 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001618 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001619 break;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001620 case XML_SCHEMA_TYPE_COMPLEX: {
1621 xmlSchemaTypePtr type = WXS_TYPE_CAST item;
1622
1623 if (type->flags & XML_SCHEMAS_TYPE_GLOBAL)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001624 *buf = xmlStrdup(BAD_CAST "");
1625 else
1626 *buf = xmlStrdup(BAD_CAST "local ");
1627 *buf = xmlStrcat(*buf, BAD_CAST "complex type");
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001628 if (type->flags & XML_SCHEMAS_TYPE_GLOBAL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001629 *buf = xmlStrcat(*buf, BAD_CAST " '");
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001630 *buf = xmlStrcat(*buf, type->name);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001631 *buf = xmlStrcat(*buf, BAD_CAST "'");
1632 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001633 }
1634 break;
1635 case XML_SCHEMA_TYPE_ATTRIBUTE_USE: {
1636 xmlSchemaAttributeUsePtr ause;
Daniel Veillarddee23482008-04-11 12:58:43 +00001637
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001638 ause = WXS_ATTR_USE_CAST item;
1639 *buf = xmlStrdup(BAD_CAST "attribute use ");
1640 if (WXS_ATTRUSE_DECL(ause) != NULL) {
1641 *buf = xmlStrcat(*buf, BAD_CAST "'");
1642 *buf = xmlStrcat(*buf,
1643 xmlSchemaGetComponentQName(&str, WXS_ATTRUSE_DECL(ause)));
1644 FREE_AND_NULL(str)
1645 *buf = xmlStrcat(*buf, BAD_CAST "'");
1646 } else {
1647 *buf = xmlStrcat(*buf, BAD_CAST "(unknown)");
1648 }
1649 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001650 break;
1651 case XML_SCHEMA_TYPE_ATTRIBUTE: {
1652 xmlSchemaAttributePtr attr;
Daniel Veillarddee23482008-04-11 12:58:43 +00001653
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001654 attr = (xmlSchemaAttributePtr) item;
1655 *buf = xmlStrdup(BAD_CAST "attribute decl.");
1656 *buf = xmlStrcat(*buf, BAD_CAST " '");
1657 *buf = xmlStrcat(*buf, xmlSchemaFormatQName(&str,
1658 attr->targetNamespace, attr->name));
1659 FREE_AND_NULL(str)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001660 *buf = xmlStrcat(*buf, BAD_CAST "'");
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001661 }
1662 break;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001663 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1664 xmlSchemaGetComponentDesignation(buf, item);
1665 break;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001666 case XML_SCHEMA_TYPE_ELEMENT: {
1667 xmlSchemaElementPtr elem;
1668
Daniel Veillarddee23482008-04-11 12:58:43 +00001669 elem = (xmlSchemaElementPtr) item;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001670 *buf = xmlStrdup(BAD_CAST "element decl.");
1671 *buf = xmlStrcat(*buf, BAD_CAST " '");
1672 *buf = xmlStrcat(*buf, xmlSchemaFormatQName(&str,
1673 elem->targetNamespace, elem->name));
1674 *buf = xmlStrcat(*buf, BAD_CAST "'");
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001675 }
1676 break;
1677 case XML_SCHEMA_TYPE_IDC_UNIQUE:
1678 case XML_SCHEMA_TYPE_IDC_KEY:
Daniel Veillarddee23482008-04-11 12:58:43 +00001679 case XML_SCHEMA_TYPE_IDC_KEYREF:
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001680 if (item->type == XML_SCHEMA_TYPE_IDC_UNIQUE)
1681 *buf = xmlStrdup(BAD_CAST "unique '");
1682 else if (item->type == XML_SCHEMA_TYPE_IDC_KEY)
1683 *buf = xmlStrdup(BAD_CAST "key '");
1684 else
1685 *buf = xmlStrdup(BAD_CAST "keyRef '");
1686 *buf = xmlStrcat(*buf, ((xmlSchemaIDCPtr) item)->name);
1687 *buf = xmlStrcat(*buf, BAD_CAST "'");
1688 break;
1689 case XML_SCHEMA_TYPE_ANY:
1690 case XML_SCHEMA_TYPE_ANY_ATTRIBUTE:
1691 *buf = xmlStrdup(xmlSchemaWildcardPCToString(
1692 ((xmlSchemaWildcardPtr) item)->processContents));
1693 *buf = xmlStrcat(*buf, BAD_CAST " wildcard");
1694 break;
1695 case XML_SCHEMA_FACET_MININCLUSIVE:
1696 case XML_SCHEMA_FACET_MINEXCLUSIVE:
1697 case XML_SCHEMA_FACET_MAXINCLUSIVE:
1698 case XML_SCHEMA_FACET_MAXEXCLUSIVE:
1699 case XML_SCHEMA_FACET_TOTALDIGITS:
1700 case XML_SCHEMA_FACET_FRACTIONDIGITS:
1701 case XML_SCHEMA_FACET_PATTERN:
1702 case XML_SCHEMA_FACET_ENUMERATION:
1703 case XML_SCHEMA_FACET_WHITESPACE:
1704 case XML_SCHEMA_FACET_LENGTH:
1705 case XML_SCHEMA_FACET_MAXLENGTH:
1706 case XML_SCHEMA_FACET_MINLENGTH:
1707 *buf = xmlStrdup(BAD_CAST "facet '");
1708 *buf = xmlStrcat(*buf, xmlSchemaFacetTypeToString(item->type));
1709 *buf = xmlStrcat(*buf, BAD_CAST "'");
1710 break;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001711 case XML_SCHEMA_TYPE_GROUP: {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001712 *buf = xmlStrdup(BAD_CAST "model group def.");
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001713 *buf = xmlStrcat(*buf, BAD_CAST " '");
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001714 *buf = xmlStrcat(*buf, xmlSchemaGetComponentQName(&str, item));
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001715 *buf = xmlStrcat(*buf, BAD_CAST "'");
1716 FREE_AND_NULL(str)
1717 }
1718 break;
1719 case XML_SCHEMA_TYPE_SEQUENCE:
1720 case XML_SCHEMA_TYPE_CHOICE:
1721 case XML_SCHEMA_TYPE_ALL:
1722 case XML_SCHEMA_TYPE_PARTICLE:
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001723 *buf = xmlStrdup(WXS_ITEM_TYPE_NAME(item));
1724 break;
1725 case XML_SCHEMA_TYPE_NOTATION: {
1726 *buf = xmlStrdup(WXS_ITEM_TYPE_NAME(item));
1727 *buf = xmlStrcat(*buf, BAD_CAST " '");
1728 *buf = xmlStrcat(*buf, xmlSchemaGetComponentQName(&str, item));
1729 *buf = xmlStrcat(*buf, BAD_CAST "'");
1730 FREE_AND_NULL(str);
1731 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001732 default:
1733 named = 0;
1734 }
Daniel Veillarddee23482008-04-11 12:58:43 +00001735 } else
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001736 named = 0;
1737
1738 if ((named == 0) && (itemNode != NULL)) {
1739 xmlNodePtr elem;
1740
1741 if (itemNode->type == XML_ATTRIBUTE_NODE)
1742 elem = itemNode->parent;
Daniel Veillarddee23482008-04-11 12:58:43 +00001743 else
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001744 elem = itemNode;
1745 *buf = xmlStrdup(BAD_CAST "Element '");
1746 if (elem->ns != NULL) {
1747 *buf = xmlStrcat(*buf,
1748 xmlSchemaFormatQName(&str, elem->ns->href, elem->name));
1749 FREE_AND_NULL(str)
1750 } else
1751 *buf = xmlStrcat(*buf, elem->name);
1752 *buf = xmlStrcat(*buf, BAD_CAST "'");
Daniel Veillarddee23482008-04-11 12:58:43 +00001753
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001754 }
1755 if ((itemNode != NULL) && (itemNode->type == XML_ATTRIBUTE_NODE)) {
1756 *buf = xmlStrcat(*buf, BAD_CAST ", attribute '");
1757 if (itemNode->ns != NULL) {
1758 *buf = xmlStrcat(*buf, xmlSchemaFormatQName(&str,
1759 itemNode->ns->href, itemNode->name));
1760 FREE_AND_NULL(str)
1761 } else
1762 *buf = xmlStrcat(*buf, itemNode->name);
1763 *buf = xmlStrcat(*buf, BAD_CAST "'");
1764 }
1765 FREE_AND_NULL(str)
Daniel Veillarddee23482008-04-11 12:58:43 +00001766
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001767 return (*buf);
1768}
1769
1770/**
1771 * xmlSchemaFormatFacetEnumSet:
1772 * @buf: the string buffer
1773 * @type: the type holding the enumeration facets
1774 *
1775 * Builds a string consisting of all enumeration elements.
1776 *
1777 * Returns a string of all enumeration elements.
1778 */
1779static const xmlChar *
1780xmlSchemaFormatFacetEnumSet(xmlSchemaAbstractCtxtPtr actxt,
1781 xmlChar **buf, xmlSchemaTypePtr type)
1782{
1783 xmlSchemaFacetPtr facet;
1784 xmlSchemaWhitespaceValueType ws;
1785 xmlChar *value = NULL;
Kasimier T. Buchcikb63d2fa2006-04-19 11:20:49 +00001786 int res, found = 0;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001787
1788 if (*buf != NULL)
Daniel Veillarddee23482008-04-11 12:58:43 +00001789 xmlFree(*buf);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001790 *buf = NULL;
1791
1792 do {
1793 /*
1794 * Use the whitespace type of the base type.
Daniel Veillarddee23482008-04-11 12:58:43 +00001795 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001796 ws = xmlSchemaGetWhiteSpaceFacetValue(type->baseType);
1797 for (facet = type->facets; facet != NULL; facet = facet->next) {
1798 if (facet->type != XML_SCHEMA_FACET_ENUMERATION)
1799 continue;
Kasimier T. Buchcikb63d2fa2006-04-19 11:20:49 +00001800 found = 1;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001801 res = xmlSchemaGetCanonValueWhtspExt(facet->val,
1802 ws, &value);
1803 if (res == -1) {
1804 xmlSchemaInternalErr(actxt,
1805 "xmlSchemaFormatFacetEnumSet",
1806 "compute the canonical lexical representation");
1807 if (*buf != NULL)
1808 xmlFree(*buf);
1809 *buf = NULL;
1810 return (NULL);
1811 }
1812 if (*buf == NULL)
1813 *buf = xmlStrdup(BAD_CAST "'");
1814 else
1815 *buf = xmlStrcat(*buf, BAD_CAST ", '");
1816 *buf = xmlStrcat(*buf, BAD_CAST value);
1817 *buf = xmlStrcat(*buf, BAD_CAST "'");
1818 if (value != NULL) {
1819 xmlFree((xmlChar *)value);
1820 value = NULL;
1821 }
1822 }
Kasimier T. Buchcikb63d2fa2006-04-19 11:20:49 +00001823 /*
1824 * The enumeration facet of a type restricts the enumeration
1825 * facet of the ancestor type; i.e., such restricted enumerations
1826 * do not belong to the set of the given type. Thus we break
1827 * on the first found enumeration.
1828 */
1829 if (found)
1830 break;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001831 type = type->baseType;
1832 } while ((type != NULL) && (type->type != XML_SCHEMA_TYPE_BASIC));
1833
1834 return ((const xmlChar *) *buf);
1835}
1836
1837/************************************************************************
1838 * *
1839 * Error functions *
1840 * *
1841 ************************************************************************/
1842
1843#if 0
1844static void
1845xmlSchemaErrMemory(const char *msg)
1846{
1847 __xmlSimpleError(XML_FROM_SCHEMASP, XML_ERR_NO_MEMORY, NULL, NULL,
1848 msg);
1849}
1850#endif
1851
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00001852static void
1853xmlSchemaPSimpleErr(const char *msg)
1854{
1855 __xmlSimpleError(XML_FROM_SCHEMASP, XML_ERR_NO_MEMORY, NULL, NULL,
1856 msg);
1857}
1858
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001859/**
Daniel Veillardd0c9c322003-10-10 00:49:42 +00001860 * xmlSchemaPErrMemory:
1861 * @node: a context node
1862 * @extra: extra informations
1863 *
1864 * Handle an out of memory condition
1865 */
1866static void
1867xmlSchemaPErrMemory(xmlSchemaParserCtxtPtr ctxt,
1868 const char *extra, xmlNodePtr node)
1869{
1870 if (ctxt != NULL)
1871 ctxt->nberrors++;
1872 __xmlSimpleError(XML_FROM_SCHEMASP, XML_ERR_NO_MEMORY, node, NULL,
1873 extra);
1874}
1875
1876/**
1877 * xmlSchemaPErr:
1878 * @ctxt: the parsing context
1879 * @node: the context node
1880 * @error: the error code
1881 * @msg: the error message
1882 * @str1: extra data
1883 * @str2: extra data
Daniel Veillarddee23482008-04-11 12:58:43 +00001884 *
Daniel Veillardd0c9c322003-10-10 00:49:42 +00001885 * Handle a parser error
1886 */
1887static void
1888xmlSchemaPErr(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int error,
1889 const char *msg, const xmlChar * str1, const xmlChar * str2)
1890{
1891 xmlGenericErrorFunc channel = NULL;
Daniel Veillard659e71e2003-10-10 14:10:40 +00001892 xmlStructuredErrorFunc schannel = NULL;
Daniel Veillardd0c9c322003-10-10 00:49:42 +00001893 void *data = NULL;
1894
1895 if (ctxt != NULL) {
1896 ctxt->nberrors++;
Kasimier T. Buchcik940ab0c2005-10-19 17:00:53 +00001897 ctxt->err = error;
Daniel Veillardd0c9c322003-10-10 00:49:42 +00001898 channel = ctxt->error;
Kasimier T. Buchcik90b5ebc2005-11-18 17:18:27 +00001899 data = ctxt->errCtxt;
Daniel Veillard659e71e2003-10-10 14:10:40 +00001900 schannel = ctxt->serror;
Daniel Veillardd0c9c322003-10-10 00:49:42 +00001901 }
Daniel Veillard659e71e2003-10-10 14:10:40 +00001902 __xmlRaiseError(schannel, channel, data, ctxt, node, XML_FROM_SCHEMASP,
Daniel Veillardd0c9c322003-10-10 00:49:42 +00001903 error, XML_ERR_ERROR, NULL, 0,
1904 (const char *) str1, (const char *) str2, NULL, 0, 0,
1905 msg, str1, str2);
1906}
1907
1908/**
1909 * xmlSchemaPErr2:
1910 * @ctxt: the parsing context
1911 * @node: the context node
1912 * @node: the current child
1913 * @error: the error code
1914 * @msg: the error message
1915 * @str1: extra data
1916 * @str2: extra data
Daniel Veillarddee23482008-04-11 12:58:43 +00001917 *
Daniel Veillardd0c9c322003-10-10 00:49:42 +00001918 * Handle a parser error
1919 */
1920static void
1921xmlSchemaPErr2(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node,
1922 xmlNodePtr child, int error,
1923 const char *msg, const xmlChar * str1, const xmlChar * str2)
1924{
1925 if (child != NULL)
1926 xmlSchemaPErr(ctxt, child, error, msg, str1, str2);
1927 else
1928 xmlSchemaPErr(ctxt, node, error, msg, str1, str2);
1929}
1930
Daniel Veillard01fa6152004-06-29 17:04:39 +00001931
Daniel Veillardd0c9c322003-10-10 00:49:42 +00001932/**
Daniel Veillard3646d642004-06-02 19:19:14 +00001933 * xmlSchemaPErrExt:
1934 * @ctxt: the parsing context
1935 * @node: the context node
Daniel Veillarddee23482008-04-11 12:58:43 +00001936 * @error: the error code
Daniel Veillard3646d642004-06-02 19:19:14 +00001937 * @strData1: extra data
1938 * @strData2: extra data
1939 * @strData3: extra data
1940 * @msg: the message
1941 * @str1: extra parameter for the message display
1942 * @str2: extra parameter for the message display
1943 * @str3: extra parameter for the message display
1944 * @str4: extra parameter for the message display
1945 * @str5: extra parameter for the message display
Daniel Veillarddee23482008-04-11 12:58:43 +00001946 *
Daniel Veillard3646d642004-06-02 19:19:14 +00001947 * Handle a parser error
1948 */
1949static void
1950xmlSchemaPErrExt(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int error,
Daniel Veillarddee23482008-04-11 12:58:43 +00001951 const xmlChar * strData1, const xmlChar * strData2,
1952 const xmlChar * strData3, const char *msg, const xmlChar * str1,
Daniel Veillard3646d642004-06-02 19:19:14 +00001953 const xmlChar * str2, const xmlChar * str3, const xmlChar * str4,
1954 const xmlChar * str5)
1955{
1956
1957 xmlGenericErrorFunc channel = NULL;
1958 xmlStructuredErrorFunc schannel = NULL;
1959 void *data = NULL;
1960
1961 if (ctxt != NULL) {
1962 ctxt->nberrors++;
Kasimier T. Buchcik940ab0c2005-10-19 17:00:53 +00001963 ctxt->err = error;
Daniel Veillard3646d642004-06-02 19:19:14 +00001964 channel = ctxt->error;
Kasimier T. Buchcik90b5ebc2005-11-18 17:18:27 +00001965 data = ctxt->errCtxt;
Daniel Veillard3646d642004-06-02 19:19:14 +00001966 schannel = ctxt->serror;
1967 }
1968 __xmlRaiseError(schannel, channel, data, ctxt, node, XML_FROM_SCHEMASP,
1969 error, XML_ERR_ERROR, NULL, 0,
Daniel Veillarddee23482008-04-11 12:58:43 +00001970 (const char *) strData1, (const char *) strData2,
1971 (const char *) strData3, 0, 0, msg, str1, str2,
William M. Brack803812b2004-06-03 02:11:24 +00001972 str3, str4, str5);
Daniel Veillard3646d642004-06-02 19:19:14 +00001973}
Daniel Veillard01fa6152004-06-29 17:04:39 +00001974
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00001975/************************************************************************
1976 * *
1977 * Allround error functions *
1978 * *
1979 ************************************************************************/
Daniel Veillard3646d642004-06-02 19:19:14 +00001980
1981/**
Daniel Veillardd0c9c322003-10-10 00:49:42 +00001982 * xmlSchemaVTypeErrMemory:
1983 * @node: a context node
1984 * @extra: extra informations
1985 *
1986 * Handle an out of memory condition
1987 */
1988static void
1989xmlSchemaVErrMemory(xmlSchemaValidCtxtPtr ctxt,
1990 const char *extra, xmlNodePtr node)
1991{
1992 if (ctxt != NULL) {
1993 ctxt->nberrors++;
Kasimier T. Buchcikbea23542004-08-25 20:35:45 +00001994 ctxt->err = XML_SCHEMAV_INTERNAL;
Daniel Veillardd0c9c322003-10-10 00:49:42 +00001995 }
1996 __xmlSimpleError(XML_FROM_SCHEMASV, XML_ERR_NO_MEMORY, node, NULL,
1997 extra);
1998}
1999
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00002000static void
2001xmlSchemaPSimpleInternalErr(xmlNodePtr node,
2002 const char *msg, const xmlChar *str)
2003{
2004 __xmlSimpleError(XML_FROM_SCHEMASP, XML_SCHEMAP_INTERNAL, node,
2005 msg, (const char *) str);
2006}
2007
2008#define WXS_ERROR_TYPE_ERROR 1
2009#define WXS_ERROR_TYPE_WARNING 2
Daniel Veillardd0c9c322003-10-10 00:49:42 +00002010/**
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002011 * xmlSchemaErr3:
Daniel Veillardd0c9c322003-10-10 00:49:42 +00002012 * @ctxt: the validation context
2013 * @node: the context node
2014 * @error: the error code
2015 * @msg: the error message
2016 * @str1: extra data
2017 * @str2: extra data
2018 * @str3: extra data
Daniel Veillarddee23482008-04-11 12:58:43 +00002019 *
Daniel Veillardd0c9c322003-10-10 00:49:42 +00002020 * Handle a validation error
2021 */
2022static void
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002023xmlSchemaErr4Line(xmlSchemaAbstractCtxtPtr ctxt,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00002024 xmlErrorLevel errorLevel,
2025 int error, xmlNodePtr node, int line, const char *msg,
2026 const xmlChar *str1, const xmlChar *str2,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002027 const xmlChar *str3, const xmlChar *str4)
Daniel Veillardd0c9c322003-10-10 00:49:42 +00002028{
Daniel Veillard659e71e2003-10-10 14:10:40 +00002029 xmlStructuredErrorFunc schannel = NULL;
Daniel Veillardd0c9c322003-10-10 00:49:42 +00002030 xmlGenericErrorFunc channel = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +00002031 void *data = NULL;
2032
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002033 if (ctxt != NULL) {
2034 if (ctxt->type == XML_SCHEMA_CTXT_VALIDATOR) {
2035 xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctxt;
Daniel Veillard971771e2005-07-09 17:32:57 +00002036 const char *file = NULL;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00002037 if (errorLevel != XML_ERR_WARNING) {
2038 vctxt->nberrors++;
2039 vctxt->err = error;
Daniel Veillarddee23482008-04-11 12:58:43 +00002040 channel = vctxt->error;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00002041 } else {
2042 channel = vctxt->warning;
2043 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002044 schannel = vctxt->serror;
Kasimier T. Buchcik90b5ebc2005-11-18 17:18:27 +00002045 data = vctxt->errCtxt;
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +00002046
2047 /*
2048 * Error node. If we specify a line number, then
2049 * do not channel any node to the error function.
2050 */
2051 if (line == 0) {
2052 if ((node == NULL) &&
2053 (vctxt->depth >= 0) &&
2054 (vctxt->inode != NULL)) {
2055 node = vctxt->inode->node;
2056 }
2057 /*
2058 * Get filename and line if no node-tree.
2059 */
2060 if ((node == NULL) &&
2061 (vctxt->parserCtxt != NULL) &&
2062 (vctxt->parserCtxt->input != NULL)) {
2063 file = vctxt->parserCtxt->input->filename;
2064 line = vctxt->parserCtxt->input->line;
2065 }
2066 } else {
2067 /*
2068 * Override the given node's (if any) position
2069 * and channel only the given line number.
2070 */
2071 node = NULL;
2072 /*
2073 * Get filename.
2074 */
2075 if (vctxt->doc != NULL)
2076 file = (const char *) vctxt->doc->URL;
2077 else if ((vctxt->parserCtxt != NULL) &&
2078 (vctxt->parserCtxt->input != NULL))
2079 file = vctxt->parserCtxt->input->filename;
Daniel Veillarddee23482008-04-11 12:58:43 +00002080 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002081 __xmlRaiseError(schannel, channel, data, ctxt,
2082 node, XML_FROM_SCHEMASV,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00002083 error, errorLevel, file, line,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002084 (const char *) str1, (const char *) str2,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002085 (const char *) str3, 0, 0, msg, str1, str2, str3, str4);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002086
2087 } else if (ctxt->type == XML_SCHEMA_CTXT_PARSER) {
2088 xmlSchemaParserCtxtPtr pctxt = (xmlSchemaParserCtxtPtr) ctxt;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00002089 if (errorLevel != XML_ERR_WARNING) {
2090 pctxt->nberrors++;
2091 pctxt->err = error;
Daniel Veillarddee23482008-04-11 12:58:43 +00002092 channel = pctxt->error;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00002093 } else {
2094 channel = pctxt->warning;
2095 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002096 schannel = pctxt->serror;
Kasimier T. Buchcik90b5ebc2005-11-18 17:18:27 +00002097 data = pctxt->errCtxt;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002098 __xmlRaiseError(schannel, channel, data, ctxt,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00002099 node, XML_FROM_SCHEMASP, error,
2100 errorLevel, NULL, 0,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002101 (const char *) str1, (const char *) str2,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002102 (const char *) str3, 0, 0, msg, str1, str2, str3, str4);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002103 } else {
2104 TODO
2105 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00002106 }
Kasimier T. Buchcik9b77aa02005-03-04 22:04:16 +00002107}
2108
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +00002109/**
2110 * xmlSchemaErr3:
2111 * @ctxt: the validation context
2112 * @node: the context node
2113 * @error: the error code
2114 * @msg: the error message
2115 * @str1: extra data
2116 * @str2: extra data
2117 * @str3: extra data
Daniel Veillarddee23482008-04-11 12:58:43 +00002118 *
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +00002119 * Handle a validation error
2120 */
2121static void
Daniel Veillarddee23482008-04-11 12:58:43 +00002122xmlSchemaErr3(xmlSchemaAbstractCtxtPtr actxt,
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +00002123 int error, xmlNodePtr node, const char *msg,
2124 const xmlChar *str1, const xmlChar *str2, const xmlChar *str3)
2125{
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002126 xmlSchemaErr4Line(actxt, XML_ERR_ERROR, error, node, 0,
2127 msg, str1, str2, str3, NULL);
2128}
2129
2130static void
Daniel Veillarddee23482008-04-11 12:58:43 +00002131xmlSchemaErr4(xmlSchemaAbstractCtxtPtr actxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002132 int error, xmlNodePtr node, const char *msg,
2133 const xmlChar *str1, const xmlChar *str2,
2134 const xmlChar *str3, const xmlChar *str4)
2135{
2136 xmlSchemaErr4Line(actxt, XML_ERR_ERROR, error, node, 0,
2137 msg, str1, str2, str3, str4);
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +00002138}
2139
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002140static void
2141xmlSchemaErr(xmlSchemaAbstractCtxtPtr actxt,
2142 int error, xmlNodePtr node, const char *msg,
2143 const xmlChar *str1, const xmlChar *str2)
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00002144{
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002145 xmlSchemaErr4(actxt, error, node, msg, str1, str2, NULL, NULL);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00002146}
2147
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002148static xmlChar *
2149xmlSchemaFormatNodeForError(xmlChar ** msg,
2150 xmlSchemaAbstractCtxtPtr actxt,
2151 xmlNodePtr node)
Daniel Veillardc0826a72004-08-10 14:17:33 +00002152{
2153 xmlChar *str = NULL;
2154
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002155 *msg = NULL;
Kasimier T. Buchcik69dea3a2005-11-07 14:02:44 +00002156 if ((node != NULL) &&
2157 (node->type != XML_ELEMENT_NODE) &&
2158 (node->type != XML_ATTRIBUTE_NODE))
2159 {
Daniel Veillarddee23482008-04-11 12:58:43 +00002160 /*
Kasimier T. Buchcik69dea3a2005-11-07 14:02:44 +00002161 * Don't try to format other nodes than element and
2162 * attribute nodes.
2163 * Play save and return an empty string.
2164 */
2165 *msg = xmlStrdup(BAD_CAST "");
2166 return(*msg);
2167 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002168 if (node != NULL) {
2169 /*
2170 * Work on tree nodes.
2171 */
2172 if (node->type == XML_ATTRIBUTE_NODE) {
2173 xmlNodePtr elem = node->parent;
Daniel Veillarddee23482008-04-11 12:58:43 +00002174
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002175 *msg = xmlStrdup(BAD_CAST "Element '");
2176 if (elem->ns != NULL)
2177 *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2178 elem->ns->href, elem->name));
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00002179 else
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002180 *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2181 NULL, elem->name));
2182 FREE_AND_NULL(str);
2183 *msg = xmlStrcat(*msg, BAD_CAST "', ");
Daniel Veillarddee23482008-04-11 12:58:43 +00002184 *msg = xmlStrcat(*msg, BAD_CAST "attribute '");
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002185 } else {
2186 *msg = xmlStrdup(BAD_CAST "Element '");
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00002187 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002188 if (node->ns != NULL)
2189 *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2190 node->ns->href, node->name));
Daniel Veillardc0826a72004-08-10 14:17:33 +00002191 else
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002192 *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2193 NULL, node->name));
2194 FREE_AND_NULL(str);
2195 *msg = xmlStrcat(*msg, BAD_CAST "': ");
2196 } else if (actxt->type == XML_SCHEMA_CTXT_VALIDATOR) {
2197 xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) actxt;
2198 /*
2199 * Work on node infos.
Daniel Veillarddee23482008-04-11 12:58:43 +00002200 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002201 if (vctxt->inode->nodeType == XML_ATTRIBUTE_NODE) {
2202 xmlSchemaNodeInfoPtr ielem =
2203 vctxt->elemInfos[vctxt->depth];
2204
2205 *msg = xmlStrdup(BAD_CAST "Element '");
2206 *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2207 ielem->nsName, ielem->localName));
2208 FREE_AND_NULL(str);
2209 *msg = xmlStrcat(*msg, BAD_CAST "', ");
Daniel Veillarddee23482008-04-11 12:58:43 +00002210 *msg = xmlStrcat(*msg, BAD_CAST "attribute '");
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002211 } else {
2212 *msg = xmlStrdup(BAD_CAST "Element '");
2213 }
2214 *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2215 vctxt->inode->nsName, vctxt->inode->localName));
2216 FREE_AND_NULL(str);
2217 *msg = xmlStrcat(*msg, BAD_CAST "': ");
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00002218 } else if (actxt->type == XML_SCHEMA_CTXT_PARSER) {
Daniel Veillarddee23482008-04-11 12:58:43 +00002219 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00002220 * Hmm, no node while parsing?
2221 * Return an empty string, in case NULL will break something.
2222 */
2223 *msg = xmlStrdup(BAD_CAST "");
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002224 } else {
2225 TODO
2226 return (NULL);
Daniel Veillardc0826a72004-08-10 14:17:33 +00002227 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002228 /*
2229 * VAL TODO: The output of the given schema component is currently
2230 * disabled.
2231 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002232#if 0
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002233 if ((type != NULL) && (xmlSchemaIsGlobalItem(type))) {
2234 *msg = xmlStrcat(*msg, BAD_CAST " [");
2235 *msg = xmlStrcat(*msg, xmlSchemaFormatItemForReport(&str,
2236 NULL, type, NULL, 0));
2237 FREE_AND_NULL(str)
2238 *msg = xmlStrcat(*msg, BAD_CAST "]");
Daniel Veillardc0826a72004-08-10 14:17:33 +00002239 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002240#endif
2241 return (*msg);
Daniel Veillardc0826a72004-08-10 14:17:33 +00002242}
2243
Daniel Veillardc0826a72004-08-10 14:17:33 +00002244static void
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +00002245xmlSchemaInternalErr2(xmlSchemaAbstractCtxtPtr actxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002246 const char *funcName,
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +00002247 const char *message,
2248 const xmlChar *str1,
2249 const xmlChar *str2)
Daniel Veillardc0826a72004-08-10 14:17:33 +00002250{
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002251 xmlChar *msg = NULL;
2252
Daniel Veillard14b56432006-03-09 18:41:40 +00002253 if (actxt == NULL)
2254 return;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002255 msg = xmlStrdup(BAD_CAST "Internal error: ");
2256 msg = xmlStrcat(msg, BAD_CAST funcName);
Daniel Veillarddee23482008-04-11 12:58:43 +00002257 msg = xmlStrcat(msg, BAD_CAST ", ");
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002258 msg = xmlStrcat(msg, BAD_CAST message);
2259 msg = xmlStrcat(msg, BAD_CAST ".\n");
2260
2261 if (actxt->type == XML_SCHEMA_CTXT_VALIDATOR)
2262 xmlSchemaErr(actxt, XML_SCHEMAV_INTERNAL, NULL,
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +00002263 (const char *) msg, str1, str2);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002264
Daniel Veillarddee23482008-04-11 12:58:43 +00002265 else if (actxt->type == XML_SCHEMA_CTXT_PARSER)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002266 xmlSchemaErr(actxt, XML_SCHEMAP_INTERNAL, NULL,
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +00002267 (const char *) msg, str1, str2);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002268
2269 FREE_AND_NULL(msg)
Daniel Veillardc0826a72004-08-10 14:17:33 +00002270}
2271
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002272static void
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +00002273xmlSchemaInternalErr(xmlSchemaAbstractCtxtPtr actxt,
2274 const char *funcName,
2275 const char *message)
2276{
2277 xmlSchemaInternalErr2(actxt, funcName, message, NULL, NULL);
2278}
2279
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00002280#if 0
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +00002281static void
2282xmlSchemaPInternalErr(xmlSchemaParserCtxtPtr pctxt,
2283 const char *funcName,
2284 const char *message,
2285 const xmlChar *str1,
2286 const xmlChar *str2)
2287{
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00002288 xmlSchemaInternalErr2(ACTXT_CAST pctxt, funcName, message,
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +00002289 str1, str2);
2290}
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00002291#endif
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +00002292
2293static void
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002294xmlSchemaCustomErr4(xmlSchemaAbstractCtxtPtr actxt,
2295 xmlParserErrors error,
2296 xmlNodePtr node,
2297 xmlSchemaBasicItemPtr item,
2298 const char *message,
2299 const xmlChar *str1, const xmlChar *str2,
2300 const xmlChar *str3, const xmlChar *str4)
2301{
2302 xmlChar *msg = NULL;
2303
2304 if ((node == NULL) && (item != NULL) &&
2305 (actxt->type == XML_SCHEMA_CTXT_PARSER)) {
2306 node = WXS_ITEM_NODE(item);
2307 xmlSchemaFormatItemForReport(&msg, NULL, item, NULL);
2308 msg = xmlStrcat(msg, BAD_CAST ": ");
2309 } else
2310 xmlSchemaFormatNodeForError(&msg, actxt, node);
2311 msg = xmlStrcat(msg, (const xmlChar *) message);
Daniel Veillarddee23482008-04-11 12:58:43 +00002312 msg = xmlStrcat(msg, BAD_CAST ".\n");
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002313 xmlSchemaErr4(actxt, error, node,
2314 (const char *) msg, str1, str2, str3, str4);
2315 FREE_AND_NULL(msg)
2316}
2317
2318static void
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002319xmlSchemaCustomErr(xmlSchemaAbstractCtxtPtr actxt,
2320 xmlParserErrors error,
2321 xmlNodePtr node,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002322 xmlSchemaBasicItemPtr item,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002323 const char *message,
2324 const xmlChar *str1,
2325 const xmlChar *str2)
Kasimier T. Buchcik478d6932005-03-16 16:29:18 +00002326{
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002327 xmlSchemaCustomErr4(actxt, error, node, item,
Daniel Veillarddee23482008-04-11 12:58:43 +00002328 message, str1, str2, NULL, NULL);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002329}
2330
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002331
2332
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +00002333static void
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00002334xmlSchemaCustomWarning(xmlSchemaAbstractCtxtPtr actxt,
2335 xmlParserErrors error,
2336 xmlNodePtr node,
2337 xmlSchemaTypePtr type ATTRIBUTE_UNUSED,
2338 const char *message,
2339 const xmlChar *str1,
2340 const xmlChar *str2,
2341 const xmlChar *str3)
2342{
2343 xmlChar *msg = NULL;
2344
2345 xmlSchemaFormatNodeForError(&msg, actxt, node);
2346 msg = xmlStrcat(msg, (const xmlChar *) message);
Daniel Veillarddee23482008-04-11 12:58:43 +00002347 msg = xmlStrcat(msg, BAD_CAST ".\n");
2348
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00002349 /* URGENT TODO: Set the error code to something sane. */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002350 xmlSchemaErr4Line(actxt, XML_ERR_WARNING, error, node, 0,
2351 (const char *) msg, str1, str2, str3, NULL);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00002352
2353 FREE_AND_NULL(msg)
2354}
2355
2356
2357
2358static void
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +00002359xmlSchemaKeyrefErr(xmlSchemaValidCtxtPtr vctxt,
2360 xmlParserErrors error,
2361 xmlSchemaPSVIIDCNodePtr idcNode,
2362 xmlSchemaTypePtr type ATTRIBUTE_UNUSED,
2363 const char *message,
2364 const xmlChar *str1,
2365 const xmlChar *str2)
2366{
2367 xmlChar *msg = NULL, *qname = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +00002368
2369 msg = xmlStrdup(BAD_CAST "Element '%s': ");
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +00002370 msg = xmlStrcat(msg, (const xmlChar *) message);
2371 msg = xmlStrcat(msg, BAD_CAST ".\n");
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002372 xmlSchemaErr4Line(ACTXT_CAST vctxt, XML_ERR_ERROR,
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +00002373 error, NULL, idcNode->nodeLine, (const char *) msg,
2374 xmlSchemaFormatQName(&qname,
2375 vctxt->nodeQNames->items[idcNode->nodeQNameID +1],
Daniel Veillarddee23482008-04-11 12:58:43 +00002376 vctxt->nodeQNames->items[idcNode->nodeQNameID]),
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002377 str1, str2, NULL);
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +00002378 FREE_AND_NULL(qname);
2379 FREE_AND_NULL(msg);
2380}
2381
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002382static int
2383xmlSchemaEvalErrorNodeType(xmlSchemaAbstractCtxtPtr actxt,
2384 xmlNodePtr node)
2385{
2386 if (node != NULL)
2387 return (node->type);
2388 if ((actxt->type == XML_SCHEMA_CTXT_VALIDATOR) &&
2389 (((xmlSchemaValidCtxtPtr) actxt)->inode != NULL))
2390 return ( ((xmlSchemaValidCtxtPtr) actxt)->inode->nodeType);
2391 return (-1);
2392}
2393
2394static int
2395xmlSchemaIsGlobalItem(xmlSchemaTypePtr item)
2396{
2397 switch (item->type) {
2398 case XML_SCHEMA_TYPE_COMPLEX:
2399 case XML_SCHEMA_TYPE_SIMPLE:
2400 if (item->flags & XML_SCHEMAS_TYPE_GLOBAL)
2401 return(1);
Kasimier T. Buchcik478d6932005-03-16 16:29:18 +00002402 break;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002403 case XML_SCHEMA_TYPE_GROUP:
2404 return (1);
2405 case XML_SCHEMA_TYPE_ELEMENT:
2406 if ( ((xmlSchemaElementPtr) item)->flags &
2407 XML_SCHEMAS_ELEM_GLOBAL)
2408 return(1);
Kasimier T. Buchcik478d6932005-03-16 16:29:18 +00002409 break;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002410 case XML_SCHEMA_TYPE_ATTRIBUTE:
2411 if ( ((xmlSchemaAttributePtr) item)->flags &
2412 XML_SCHEMAS_ATTR_GLOBAL)
2413 return(1);
2414 break;
2415 /* Note that attribute groups are always global. */
Kasimier T. Buchcik478d6932005-03-16 16:29:18 +00002416 default:
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002417 return(1);
2418 }
Kasimier T. Buchcik478d6932005-03-16 16:29:18 +00002419 return (0);
2420}
2421
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002422static void
2423xmlSchemaSimpleTypeErr(xmlSchemaAbstractCtxtPtr actxt,
2424 xmlParserErrors error,
2425 xmlNodePtr node,
2426 const xmlChar *value,
2427 xmlSchemaTypePtr type,
2428 int displayValue)
2429{
2430 xmlChar *msg = NULL;
2431
2432 xmlSchemaFormatNodeForError(&msg, actxt, node);
2433
2434 if (displayValue || (xmlSchemaEvalErrorNodeType(actxt, node) ==
2435 XML_ATTRIBUTE_NODE))
2436 msg = xmlStrcat(msg, BAD_CAST "'%s' is not a valid value of ");
2437 else
2438 msg = xmlStrcat(msg, BAD_CAST "The character content is not a valid "
2439 "value of ");
2440
2441 if (! xmlSchemaIsGlobalItem(type))
2442 msg = xmlStrcat(msg, BAD_CAST "the local ");
2443 else
2444 msg = xmlStrcat(msg, BAD_CAST "the ");
2445
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002446 if (WXS_IS_ATOMIC(type))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002447 msg = xmlStrcat(msg, BAD_CAST "atomic type");
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002448 else if (WXS_IS_LIST(type))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002449 msg = xmlStrcat(msg, BAD_CAST "list type");
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002450 else if (WXS_IS_UNION(type))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002451 msg = xmlStrcat(msg, BAD_CAST "union type");
2452
2453 if (xmlSchemaIsGlobalItem(type)) {
2454 xmlChar *str = NULL;
2455 msg = xmlStrcat(msg, BAD_CAST " '");
2456 if (type->builtInType != 0) {
2457 msg = xmlStrcat(msg, BAD_CAST "xs:");
2458 msg = xmlStrcat(msg, type->name);
Daniel Veillarddee23482008-04-11 12:58:43 +00002459 } else
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002460 msg = xmlStrcat(msg,
2461 xmlSchemaFormatQName(&str,
2462 type->targetNamespace, type->name));
2463 msg = xmlStrcat(msg, BAD_CAST "'");
2464 FREE_AND_NULL(str);
2465 }
2466 msg = xmlStrcat(msg, BAD_CAST ".\n");
2467 if (displayValue || (xmlSchemaEvalErrorNodeType(actxt, node) ==
2468 XML_ATTRIBUTE_NODE))
2469 xmlSchemaErr(actxt, error, node, (const char *) msg, value, NULL);
2470 else
2471 xmlSchemaErr(actxt, error, node, (const char *) msg, NULL, NULL);
2472 FREE_AND_NULL(msg)
2473}
2474
Daniel Veillardc0826a72004-08-10 14:17:33 +00002475static const xmlChar *
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002476xmlSchemaFormatErrorNodeQName(xmlChar ** str,
2477 xmlSchemaNodeInfoPtr ni,
2478 xmlNodePtr node)
Daniel Veillardc0826a72004-08-10 14:17:33 +00002479{
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002480 if (node != NULL) {
2481 if (node->ns != NULL)
2482 return (xmlSchemaFormatQName(str, node->ns->href, node->name));
2483 else
2484 return (xmlSchemaFormatQName(str, NULL, node->name));
2485 } else if (ni != NULL)
2486 return (xmlSchemaFormatQName(str, ni->nsName, ni->localName));
2487 return (NULL);
Daniel Veillardc0826a72004-08-10 14:17:33 +00002488}
2489
Daniel Veillardc0826a72004-08-10 14:17:33 +00002490static void
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002491xmlSchemaIllegalAttrErr(xmlSchemaAbstractCtxtPtr actxt,
2492 xmlParserErrors error,
2493 xmlSchemaAttrInfoPtr ni,
2494 xmlNodePtr node)
Daniel Veillardc0826a72004-08-10 14:17:33 +00002495{
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002496 xmlChar *msg = NULL, *str = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +00002497
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002498 xmlSchemaFormatNodeForError(&msg, actxt, node);
2499 msg = xmlStrcat(msg, BAD_CAST "The attribute '%s' is not allowed.\n");
2500 xmlSchemaErr(actxt, error, node, (const char *) msg,
2501 xmlSchemaFormatErrorNodeQName(&str, (xmlSchemaNodeInfoPtr) ni, node),
Daniel Veillarddee23482008-04-11 12:58:43 +00002502 NULL);
Daniel Veillardc0826a72004-08-10 14:17:33 +00002503 FREE_AND_NULL(str)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002504 FREE_AND_NULL(msg)
Daniel Veillardc0826a72004-08-10 14:17:33 +00002505}
2506
Daniel Veillardc0826a72004-08-10 14:17:33 +00002507static void
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002508xmlSchemaComplexTypeErr(xmlSchemaAbstractCtxtPtr actxt,
2509 xmlParserErrors error,
2510 xmlNodePtr node,
2511 xmlSchemaTypePtr type ATTRIBUTE_UNUSED,
Kasimier T. Buchcikc3af19d2005-01-13 12:10:11 +00002512 const char *message,
2513 int nbval,
2514 int nbneg,
2515 xmlChar **values)
2516{
2517 xmlChar *str = NULL, *msg = NULL;
2518 xmlChar *localName, *nsName;
2519 const xmlChar *cur, *end;
Daniel Veillard6a0baa02005-12-10 11:11:12 +00002520 int i;
Daniel Veillarddee23482008-04-11 12:58:43 +00002521
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002522 xmlSchemaFormatNodeForError(&msg, actxt, node);
Kasimier T. Buchcikc3af19d2005-01-13 12:10:11 +00002523 msg = xmlStrcat(msg, (const xmlChar *) message);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002524 msg = xmlStrcat(msg, BAD_CAST ".");
Kasimier T. Buchcikc3af19d2005-01-13 12:10:11 +00002525 /*
2526 * Note that is does not make sense to report that we have a
2527 * wildcard here, since the wildcard might be unfolded into
2528 * multiple transitions.
2529 */
2530 if (nbval + nbneg > 0) {
2531 if (nbval + nbneg > 1) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002532 str = xmlStrdup(BAD_CAST " Expected is one of ( ");
Kasimier T. Buchcikc3af19d2005-01-13 12:10:11 +00002533 } else
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002534 str = xmlStrdup(BAD_CAST " Expected is ( ");
Kasimier T. Buchcikc3af19d2005-01-13 12:10:11 +00002535 nsName = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +00002536
Kasimier T. Buchcikc3af19d2005-01-13 12:10:11 +00002537 for (i = 0; i < nbval + nbneg; i++) {
2538 cur = values[i];
Daniel Veillard77005e62005-07-19 16:26:18 +00002539 if (cur == NULL)
2540 continue;
2541 if ((cur[0] == 'n') && (cur[1] == 'o') && (cur[2] == 't') &&
2542 (cur[3] == ' ')) {
Daniel Veillard77005e62005-07-19 16:26:18 +00002543 cur += 4;
Daniel Veillard6e65e152005-08-09 11:09:52 +00002544 str = xmlStrcat(str, BAD_CAST "##other");
Daniel Veillard77005e62005-07-19 16:26:18 +00002545 }
Kasimier T. Buchcikc3af19d2005-01-13 12:10:11 +00002546 /*
2547 * Get the local name.
2548 */
2549 localName = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +00002550
Kasimier T. Buchcikc3af19d2005-01-13 12:10:11 +00002551 end = cur;
2552 if (*end == '*') {
2553 localName = xmlStrdup(BAD_CAST "*");
Kasimier T. Buchcikc0e833f2005-04-19 15:02:20 +00002554 end++;
Kasimier T. Buchcikc3af19d2005-01-13 12:10:11 +00002555 } else {
2556 while ((*end != 0) && (*end != '|'))
2557 end++;
Kasimier T. Buchcikc3af19d2005-01-13 12:10:11 +00002558 localName = xmlStrncat(localName, BAD_CAST cur, end - cur);
Daniel Veillarddee23482008-04-11 12:58:43 +00002559 }
2560 if (*end != 0) {
Kasimier T. Buchcikc0e833f2005-04-19 15:02:20 +00002561 end++;
Kasimier T. Buchcikc3af19d2005-01-13 12:10:11 +00002562 /*
2563 * Skip "*|*" if they come with negated expressions, since
2564 * they represent the same negated wildcard.
2565 */
2566 if ((nbneg == 0) || (*end != '*') || (*localName != '*')) {
2567 /*
2568 * Get the namespace name.
2569 */
2570 cur = end;
2571 if (*end == '*') {
2572 nsName = xmlStrdup(BAD_CAST "{*}");
2573 } else {
2574 while (*end != 0)
2575 end++;
Daniel Veillarddee23482008-04-11 12:58:43 +00002576
Kasimier T. Buchcikc3af19d2005-01-13 12:10:11 +00002577 if (i >= nbval)
2578 nsName = xmlStrdup(BAD_CAST "{##other:");
2579 else
2580 nsName = xmlStrdup(BAD_CAST "{");
Daniel Veillarddee23482008-04-11 12:58:43 +00002581
Kasimier T. Buchcikc3af19d2005-01-13 12:10:11 +00002582 nsName = xmlStrncat(nsName, BAD_CAST cur, end - cur);
2583 nsName = xmlStrcat(nsName, BAD_CAST "}");
2584 }
2585 str = xmlStrcat(str, BAD_CAST nsName);
2586 FREE_AND_NULL(nsName)
2587 } else {
2588 FREE_AND_NULL(localName);
2589 continue;
2590 }
Daniel Veillarddee23482008-04-11 12:58:43 +00002591 }
Kasimier T. Buchcikc3af19d2005-01-13 12:10:11 +00002592 str = xmlStrcat(str, BAD_CAST localName);
2593 FREE_AND_NULL(localName);
Daniel Veillarddee23482008-04-11 12:58:43 +00002594
Kasimier T. Buchcikc3af19d2005-01-13 12:10:11 +00002595 if (i < nbval + nbneg -1)
2596 str = xmlStrcat(str, BAD_CAST ", ");
Daniel Veillarddee23482008-04-11 12:58:43 +00002597 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002598 str = xmlStrcat(str, BAD_CAST " ).\n");
Kasimier T. Buchcikc3af19d2005-01-13 12:10:11 +00002599 msg = xmlStrcat(msg, BAD_CAST str);
2600 FREE_AND_NULL(str)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002601 } else
2602 msg = xmlStrcat(msg, BAD_CAST "\n");
2603 xmlSchemaErr(actxt, error, node, (const char *) msg, NULL, NULL);
Kasimier T. Buchcikc3af19d2005-01-13 12:10:11 +00002604 xmlFree(msg);
2605}
2606
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002607static void
2608xmlSchemaFacetErr(xmlSchemaAbstractCtxtPtr actxt,
2609 xmlParserErrors error,
2610 xmlNodePtr node,
2611 const xmlChar *value,
2612 unsigned long length,
2613 xmlSchemaTypePtr type,
2614 xmlSchemaFacetPtr facet,
2615 const char *message,
2616 const xmlChar *str1,
2617 const xmlChar *str2)
2618{
2619 xmlChar *str = NULL, *msg = NULL;
2620 xmlSchemaTypeType facetType;
2621 int nodeType = xmlSchemaEvalErrorNodeType(actxt, node);
2622
2623 xmlSchemaFormatNodeForError(&msg, actxt, node);
2624 if (error == XML_SCHEMAV_CVC_ENUMERATION_VALID) {
2625 facetType = XML_SCHEMA_FACET_ENUMERATION;
2626 /*
2627 * If enumerations are validated, one must not expect the
2628 * facet to be given.
Daniel Veillarddee23482008-04-11 12:58:43 +00002629 */
2630 } else
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002631 facetType = facet->type;
2632 msg = xmlStrcat(msg, BAD_CAST "[");
2633 msg = xmlStrcat(msg, BAD_CAST "facet '");
2634 msg = xmlStrcat(msg, xmlSchemaFacetTypeToString(facetType));
2635 msg = xmlStrcat(msg, BAD_CAST "'] ");
2636 if (message == NULL) {
2637 /*
2638 * Use a default message.
2639 */
2640 if ((facetType == XML_SCHEMA_FACET_LENGTH) ||
2641 (facetType == XML_SCHEMA_FACET_MINLENGTH) ||
2642 (facetType == XML_SCHEMA_FACET_MAXLENGTH)) {
2643
2644 char len[25], actLen[25];
2645
2646 /* FIXME, TODO: What is the max expected string length of the
2647 * this value?
2648 */
2649 if (nodeType == XML_ATTRIBUTE_NODE)
2650 msg = xmlStrcat(msg, BAD_CAST "The value '%s' has a length of '%s'; ");
2651 else
2652 msg = xmlStrcat(msg, BAD_CAST "The value has a length of '%s'; ");
2653
2654 snprintf(len, 24, "%lu", xmlSchemaGetFacetValueAsULong(facet));
2655 snprintf(actLen, 24, "%lu", length);
2656
2657 if (facetType == XML_SCHEMA_FACET_LENGTH)
Daniel Veillarddee23482008-04-11 12:58:43 +00002658 msg = xmlStrcat(msg,
2659 BAD_CAST "this differs from the allowed length of '%s'.\n");
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002660 else if (facetType == XML_SCHEMA_FACET_MAXLENGTH)
Daniel Veillarddee23482008-04-11 12:58:43 +00002661 msg = xmlStrcat(msg,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002662 BAD_CAST "this exceeds the allowed maximum length of '%s'.\n");
2663 else if (facetType == XML_SCHEMA_FACET_MINLENGTH)
Daniel Veillarddee23482008-04-11 12:58:43 +00002664 msg = xmlStrcat(msg,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002665 BAD_CAST "this underruns the allowed minimum length of '%s'.\n");
Daniel Veillarddee23482008-04-11 12:58:43 +00002666
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002667 if (nodeType == XML_ATTRIBUTE_NODE)
2668 xmlSchemaErr3(actxt, error, node, (const char *) msg,
2669 value, (const xmlChar *) actLen, (const xmlChar *) len);
Daniel Veillarddee23482008-04-11 12:58:43 +00002670 else
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002671 xmlSchemaErr(actxt, error, node, (const char *) msg,
2672 (const xmlChar *) actLen, (const xmlChar *) len);
Daniel Veillarddee23482008-04-11 12:58:43 +00002673
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002674 } else if (facetType == XML_SCHEMA_FACET_ENUMERATION) {
2675 msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not an element "
2676 "of the set {%s}.\n");
Daniel Veillarddee23482008-04-11 12:58:43 +00002677 xmlSchemaErr(actxt, error, node, (const char *) msg, value,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002678 xmlSchemaFormatFacetEnumSet(actxt, &str, type));
2679 } else if (facetType == XML_SCHEMA_FACET_PATTERN) {
2680 msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not accepted "
2681 "by the pattern '%s'.\n");
Daniel Veillarddee23482008-04-11 12:58:43 +00002682 xmlSchemaErr(actxt, error, node, (const char *) msg, value,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002683 facet->value);
2684 } else if (facetType == XML_SCHEMA_FACET_MININCLUSIVE) {
2685 msg = xmlStrcat(msg, BAD_CAST "The value '%s' is less than the "
2686 "minimum value allowed ('%s').\n");
2687 xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2688 facet->value);
2689 } else if (facetType == XML_SCHEMA_FACET_MAXINCLUSIVE) {
2690 msg = xmlStrcat(msg, BAD_CAST "The value '%s' is greater than the "
2691 "maximum value allowed ('%s').\n");
2692 xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2693 facet->value);
2694 } else if (facetType == XML_SCHEMA_FACET_MINEXCLUSIVE) {
Kasimier T. Buchcikf39e8d12005-11-30 11:03:24 +00002695 msg = xmlStrcat(msg, BAD_CAST "The value '%s' must be greater than "
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002696 "'%s'.\n");
2697 xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2698 facet->value);
2699 } else if (facetType == XML_SCHEMA_FACET_MAXEXCLUSIVE) {
Kasimier T. Buchcikf39e8d12005-11-30 11:03:24 +00002700 msg = xmlStrcat(msg, BAD_CAST "The value '%s' must be less than "
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002701 "'%s'.\n");
2702 xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2703 facet->value);
2704 } else if (facetType == XML_SCHEMA_FACET_TOTALDIGITS) {
2705 msg = xmlStrcat(msg, BAD_CAST "The value '%s' has more "
2706 "digits than are allowed ('%s').\n");
2707 xmlSchemaErr(actxt, error, node, (const char*) msg, value,
2708 facet->value);
2709 } else if (facetType == XML_SCHEMA_FACET_FRACTIONDIGITS) {
2710 msg = xmlStrcat(msg, BAD_CAST "The value '%s' has more fractional "
2711 "digits than are allowed ('%s').\n");
2712 xmlSchemaErr(actxt, error, node, (const char*) msg, value,
2713 facet->value);
Daniel Veillarddee23482008-04-11 12:58:43 +00002714 } else if (nodeType == XML_ATTRIBUTE_NODE) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002715 msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not facet-valid.\n");
Daniel Veillarddee23482008-04-11 12:58:43 +00002716 xmlSchemaErr(actxt, error, node, (const char *) msg, value, NULL);
2717 } else {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002718 msg = xmlStrcat(msg, BAD_CAST "The value is not facet-valid.\n");
2719 xmlSchemaErr(actxt, error, node, (const char *) msg, NULL, NULL);
2720 }
2721 } else {
2722 msg = xmlStrcat(msg, (const xmlChar *) message);
2723 msg = xmlStrcat(msg, BAD_CAST ".\n");
2724 xmlSchemaErr(actxt, error, node, (const char *) msg, str1, str2);
Daniel Veillarddee23482008-04-11 12:58:43 +00002725 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002726 FREE_AND_NULL(str)
2727 xmlFree(msg);
2728}
2729
2730#define VERROR(err, type, msg) \
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00002731 xmlSchemaCustomErr(ACTXT_CAST vctxt, err, NULL, type, msg, NULL, NULL);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002732
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00002733#define VERROR_INT(func, msg) xmlSchemaInternalErr(ACTXT_CAST vctxt, func, msg);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002734
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00002735#define PERROR_INT(func, msg) xmlSchemaInternalErr(ACTXT_CAST pctxt, func, msg);
2736#define PERROR_INT2(func, msg) xmlSchemaInternalErr(ACTXT_CAST ctxt, func, msg);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002737
2738#define AERROR_INT(func, msg) xmlSchemaInternalErr(actxt, func, msg);
2739
2740
Kasimier T. Buchcikc3af19d2005-01-13 12:10:11 +00002741/**
Daniel Veillardc0826a72004-08-10 14:17:33 +00002742 * xmlSchemaPMissingAttrErr:
2743 * @ctxt: the schema validation context
2744 * @ownerDes: the designation of the owner
2745 * @ownerName: the name of the owner
2746 * @ownerItem: the owner as a schema object
2747 * @ownerElem: the owner as an element node
2748 * @node: the parent element node of the missing attribute node
2749 * @type: the corresponding type of the attribute node
2750 *
2751 * Reports an illegal attribute.
2752 */
2753static void
2754xmlSchemaPMissingAttrErr(xmlSchemaParserCtxtPtr ctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002755 xmlParserErrors error,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002756 xmlSchemaBasicItemPtr ownerItem,
Daniel Veillardc0826a72004-08-10 14:17:33 +00002757 xmlNodePtr ownerElem,
2758 const char *name,
2759 const char *message)
2760{
2761 xmlChar *des = NULL;
2762
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002763 xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem);
2764
Daniel Veillardc0826a72004-08-10 14:17:33 +00002765 if (message != NULL)
2766 xmlSchemaPErr(ctxt, ownerElem, error, "%s: %s.\n", BAD_CAST des, BAD_CAST message);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002767 else
2768 xmlSchemaPErr(ctxt, ownerElem, error,
2769 "%s: The attribute '%s' is required but missing.\n",
Daniel Veillardc0826a72004-08-10 14:17:33 +00002770 BAD_CAST des, BAD_CAST name);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002771 FREE_AND_NULL(des);
Daniel Veillardc0826a72004-08-10 14:17:33 +00002772}
2773
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002774
Daniel Veillardc0826a72004-08-10 14:17:33 +00002775/**
2776 * xmlSchemaPResCompAttrErr:
2777 * @ctxt: the schema validation context
2778 * @error: the error code
2779 * @ownerDes: the designation of the owner
2780 * @ownerItem: the owner as a schema object
2781 * @ownerElem: the owner as an element node
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002782 * @name: the name of the attribute holding the QName
Daniel Veillardc0826a72004-08-10 14:17:33 +00002783 * @refName: the referenced local name
2784 * @refURI: the referenced namespace URI
2785 * @message: optional message
2786 *
2787 * Used to report QName attribute values that failed to resolve
2788 * to schema components.
2789 */
2790static void
2791xmlSchemaPResCompAttrErr(xmlSchemaParserCtxtPtr ctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002792 xmlParserErrors error,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002793 xmlSchemaBasicItemPtr ownerItem,
Daniel Veillardc0826a72004-08-10 14:17:33 +00002794 xmlNodePtr ownerElem,
2795 const char *name,
2796 const xmlChar *refName,
2797 const xmlChar *refURI,
2798 xmlSchemaTypeType refType,
2799 const char *refTypeStr)
2800{
2801 xmlChar *des = NULL, *strA = NULL;
2802
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002803 xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem);
Daniel Veillardc0826a72004-08-10 14:17:33 +00002804 if (refTypeStr == NULL)
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002805 refTypeStr = (const char *) xmlSchemaItemTypeToStr(refType);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002806 xmlSchemaPErrExt(ctxt, ownerElem, error,
Daniel Veillardc0826a72004-08-10 14:17:33 +00002807 NULL, NULL, NULL,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002808 "%s, attribute '%s': The QName value '%s' does not resolve to a(n) "
2809 "%s.\n", BAD_CAST des, BAD_CAST name,
2810 xmlSchemaFormatQName(&strA, refURI, refName),
Daniel Veillardc0826a72004-08-10 14:17:33 +00002811 BAD_CAST refTypeStr, NULL);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002812 FREE_AND_NULL(des)
Daniel Veillardc0826a72004-08-10 14:17:33 +00002813 FREE_AND_NULL(strA)
2814}
2815
William M. Brack2f2a6632004-08-20 23:09:47 +00002816/**
2817 * xmlSchemaPCustomAttrErr:
2818 * @ctxt: the schema parser context
2819 * @error: the error code
2820 * @ownerDes: the designation of the owner
2821 * @ownerItem: the owner as a schema object
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002822 * @attr: the illegal attribute node
William M. Brack2f2a6632004-08-20 23:09:47 +00002823 *
2824 * Reports an illegal attribute during the parse.
2825 */
Daniel Veillardc0826a72004-08-10 14:17:33 +00002826static void
2827xmlSchemaPCustomAttrErr(xmlSchemaParserCtxtPtr ctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002828 xmlParserErrors error,
William M. Brack2f2a6632004-08-20 23:09:47 +00002829 xmlChar **ownerDes,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002830 xmlSchemaBasicItemPtr ownerItem,
William M. Brack2f2a6632004-08-20 23:09:47 +00002831 xmlAttrPtr attr,
2832 const char *msg)
Daniel Veillardc0826a72004-08-10 14:17:33 +00002833{
2834 xmlChar *des = NULL;
2835
2836 if (ownerDes == NULL)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002837 xmlSchemaFormatItemForReport(&des, NULL, ownerItem, attr->parent);
Daniel Veillardc0826a72004-08-10 14:17:33 +00002838 else if (*ownerDes == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002839 xmlSchemaFormatItemForReport(ownerDes, NULL, ownerItem, attr->parent);
Daniel Veillardc0826a72004-08-10 14:17:33 +00002840 des = *ownerDes;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002841 } else
2842 des = *ownerDes;
Daniel Veillard14b56432006-03-09 18:41:40 +00002843 if (attr == NULL) {
2844 xmlSchemaPErrExt(ctxt, NULL, error, NULL, NULL, NULL,
2845 "%s, attribute '%s': %s.\n",
Daniel Veillardaac7c682006-03-10 13:40:16 +00002846 BAD_CAST des, (const xmlChar *) "Unknown",
2847 (const xmlChar *) msg, NULL, NULL);
Daniel Veillard14b56432006-03-09 18:41:40 +00002848 } else {
2849 xmlSchemaPErrExt(ctxt, (xmlNodePtr) attr, error, NULL, NULL, NULL,
2850 "%s, attribute '%s': %s.\n",
2851 BAD_CAST des, attr->name, (const xmlChar *) msg, NULL, NULL);
2852 }
Daniel Veillardc0826a72004-08-10 14:17:33 +00002853 if (ownerDes == NULL)
2854 FREE_AND_NULL(des);
2855}
2856
2857/**
2858 * xmlSchemaPIllegalAttrErr:
William M. Brack2f2a6632004-08-20 23:09:47 +00002859 * @ctxt: the schema parser context
Daniel Veillardc0826a72004-08-10 14:17:33 +00002860 * @error: the error code
William M. Brack2f2a6632004-08-20 23:09:47 +00002861 * @ownerDes: the designation of the attribute's owner
2862 * @ownerItem: the attribute's owner item
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002863 * @attr: the illegal attribute node
Daniel Veillardc0826a72004-08-10 14:17:33 +00002864 *
William M. Brack2f2a6632004-08-20 23:09:47 +00002865 * Reports an illegal attribute during the parse.
Daniel Veillardc0826a72004-08-10 14:17:33 +00002866 */
2867static void
2868xmlSchemaPIllegalAttrErr(xmlSchemaParserCtxtPtr ctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002869 xmlParserErrors error,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002870 xmlSchemaBasicItemPtr ownerComp ATTRIBUTE_UNUSED,
Daniel Veillardc0826a72004-08-10 14:17:33 +00002871 xmlAttrPtr attr)
2872{
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002873 xmlChar *strA = NULL, *strB = NULL;
Daniel Veillardc0826a72004-08-10 14:17:33 +00002874
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002875 xmlSchemaFormatNodeForError(&strA, ACTXT_CAST ctxt, attr->parent);
2876 xmlSchemaErr4(ACTXT_CAST ctxt, error, (xmlNodePtr) attr,
2877 "%sThe attribute '%s' is not allowed.\n", BAD_CAST strA,
2878 xmlSchemaFormatQNameNs(&strB, attr->ns, attr->name),
2879 NULL, NULL);
Daniel Veillardc0826a72004-08-10 14:17:33 +00002880 FREE_AND_NULL(strA);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002881 FREE_AND_NULL(strB);
Daniel Veillardc0826a72004-08-10 14:17:33 +00002882}
2883
William M. Brack2f2a6632004-08-20 23:09:47 +00002884/**
2885 * xmlSchemaPCustomErr:
2886 * @ctxt: the schema parser context
2887 * @error: the error code
2888 * @itemDes: the designation of the schema item
2889 * @item: the schema item
2890 * @itemElem: the node of the schema item
2891 * @message: the error message
2892 * @str1: an optional param for the error message
2893 * @str2: an optional param for the error message
2894 * @str3: an optional param for the error message
2895 *
2896 * Reports an error during parsing.
2897 */
Daniel Veillardc0826a72004-08-10 14:17:33 +00002898static void
2899xmlSchemaPCustomErrExt(xmlSchemaParserCtxtPtr ctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002900 xmlParserErrors error,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002901 xmlSchemaBasicItemPtr item,
Daniel Veillardc0826a72004-08-10 14:17:33 +00002902 xmlNodePtr itemElem,
2903 const char *message,
2904 const xmlChar *str1,
2905 const xmlChar *str2,
2906 const xmlChar *str3)
2907{
2908 xmlChar *des = NULL, *msg = NULL;
2909
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002910 xmlSchemaFormatItemForReport(&des, NULL, item, itemElem);
Daniel Veillardc0826a72004-08-10 14:17:33 +00002911 msg = xmlStrdup(BAD_CAST "%s: ");
2912 msg = xmlStrcat(msg, (const xmlChar *) message);
2913 msg = xmlStrcat(msg, BAD_CAST ".\n");
2914 if ((itemElem == NULL) && (item != NULL))
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002915 itemElem = WXS_ITEM_NODE(item);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002916 xmlSchemaPErrExt(ctxt, itemElem, error, NULL, NULL, NULL,
Daniel Veillardc0826a72004-08-10 14:17:33 +00002917 (const char *) msg, BAD_CAST des, str1, str2, str3, NULL);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002918 FREE_AND_NULL(des);
Daniel Veillardc0826a72004-08-10 14:17:33 +00002919 FREE_AND_NULL(msg);
2920}
2921
William M. Brack2f2a6632004-08-20 23:09:47 +00002922/**
2923 * xmlSchemaPCustomErr:
2924 * @ctxt: the schema parser context
2925 * @error: the error code
2926 * @itemDes: the designation of the schema item
2927 * @item: the schema item
2928 * @itemElem: the node of the schema item
2929 * @message: the error message
2930 * @str1: the optional param for the error message
2931 *
2932 * Reports an error during parsing.
2933 */
Daniel Veillardc0826a72004-08-10 14:17:33 +00002934static void
2935xmlSchemaPCustomErr(xmlSchemaParserCtxtPtr ctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002936 xmlParserErrors error,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002937 xmlSchemaBasicItemPtr item,
Daniel Veillardc0826a72004-08-10 14:17:33 +00002938 xmlNodePtr itemElem,
2939 const char *message,
2940 const xmlChar *str1)
2941{
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002942 xmlSchemaPCustomErrExt(ctxt, error, item, itemElem, message,
Daniel Veillardc0826a72004-08-10 14:17:33 +00002943 str1, NULL, NULL);
2944}
2945
William M. Brack2f2a6632004-08-20 23:09:47 +00002946/**
2947 * xmlSchemaPAttrUseErr:
2948 * @ctxt: the schema parser context
2949 * @error: the error code
2950 * @itemDes: the designation of the schema type
2951 * @item: the schema type
2952 * @itemElem: the node of the schema type
2953 * @attr: the invalid schema attribute
2954 * @message: the error message
2955 * @str1: the optional param for the error message
2956 *
2957 * Reports an attribute use error during parsing.
2958 */
Daniel Veillardc0826a72004-08-10 14:17:33 +00002959static void
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002960xmlSchemaPAttrUseErr4(xmlSchemaParserCtxtPtr ctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002961 xmlParserErrors error,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002962 xmlNodePtr node,
2963 xmlSchemaBasicItemPtr ownerItem,
2964 const xmlSchemaAttributeUsePtr attruse,
Daniel Veillardc0826a72004-08-10 14:17:33 +00002965 const char *message,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002966 const xmlChar *str1, const xmlChar *str2,
2967 const xmlChar *str3,const xmlChar *str4)
Daniel Veillardc0826a72004-08-10 14:17:33 +00002968{
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002969 xmlChar *str = NULL, *msg = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +00002970
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002971 xmlSchemaFormatItemForReport(&msg, NULL, ownerItem, NULL);
Daniel Veillarddee23482008-04-11 12:58:43 +00002972 msg = xmlStrcat(msg, BAD_CAST ", ");
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002973 msg = xmlStrcat(msg,
2974 BAD_CAST xmlSchemaFormatItemForReport(&str, NULL,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002975 WXS_BASIC_CAST attruse, NULL));
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002976 FREE_AND_NULL(str);
2977 msg = xmlStrcat(msg, BAD_CAST ": ");
Daniel Veillardc0826a72004-08-10 14:17:33 +00002978 msg = xmlStrcat(msg, (const xmlChar *) message);
2979 msg = xmlStrcat(msg, BAD_CAST ".\n");
Daniel Veillarddee23482008-04-11 12:58:43 +00002980 xmlSchemaErr4(ACTXT_CAST ctxt, error, node,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002981 (const char *) msg, str1, str2, str3, str4);
Daniel Veillardc0826a72004-08-10 14:17:33 +00002982 xmlFree(msg);
2983}
2984
William M. Brack2f2a6632004-08-20 23:09:47 +00002985/**
2986 * xmlSchemaPIllegalFacetAtomicErr:
2987 * @ctxt: the schema parser context
2988 * @error: the error code
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002989 * @type: the schema type
2990 * @baseType: the base type of type
William M. Brack2f2a6632004-08-20 23:09:47 +00002991 * @facet: the illegal facet
2992 *
2993 * Reports an illegal facet for atomic simple types.
2994 */
Daniel Veillardc0826a72004-08-10 14:17:33 +00002995static void
2996xmlSchemaPIllegalFacetAtomicErr(xmlSchemaParserCtxtPtr ctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00002997 xmlParserErrors error,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00002998 xmlSchemaTypePtr type,
2999 xmlSchemaTypePtr baseType,
Daniel Veillardc0826a72004-08-10 14:17:33 +00003000 xmlSchemaFacetPtr facet)
3001{
3002 xmlChar *des = NULL, *strT = NULL;
3003
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003004 xmlSchemaFormatItemForReport(&des, NULL, WXS_BASIC_CAST type, type->node);
3005 xmlSchemaPErrExt(ctxt, type->node, error, NULL, NULL, NULL,
Daniel Veillardc0826a72004-08-10 14:17:33 +00003006 "%s: The facet '%s' is not allowed on types derived from the "
3007 "type %s.\n",
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +00003008 BAD_CAST des, xmlSchemaFacetTypeToString(facet->type),
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003009 xmlSchemaFormatItemForReport(&strT, NULL, WXS_BASIC_CAST baseType, NULL),
Daniel Veillardc0826a72004-08-10 14:17:33 +00003010 NULL, NULL);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003011 FREE_AND_NULL(des);
Daniel Veillardc0826a72004-08-10 14:17:33 +00003012 FREE_AND_NULL(strT);
3013}
3014
William M. Brack2f2a6632004-08-20 23:09:47 +00003015/**
3016 * xmlSchemaPIllegalFacetListUnionErr:
3017 * @ctxt: the schema parser context
3018 * @error: the error code
3019 * @itemDes: the designation of the schema item involved
3020 * @item: the schema item involved
3021 * @facet: the illegal facet
3022 *
3023 * Reports an illegal facet for <list> and <union>.
3024 */
Daniel Veillardc0826a72004-08-10 14:17:33 +00003025static void
3026xmlSchemaPIllegalFacetListUnionErr(xmlSchemaParserCtxtPtr ctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003027 xmlParserErrors error,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003028 xmlSchemaTypePtr type,
Daniel Veillardc0826a72004-08-10 14:17:33 +00003029 xmlSchemaFacetPtr facet)
3030{
Daniel Veillardb2947172006-03-27 09:45:01 +00003031 xmlChar *des = NULL;
Daniel Veillardc0826a72004-08-10 14:17:33 +00003032
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003033 xmlSchemaFormatItemForReport(&des, NULL, WXS_BASIC_CAST type,
3034 type->node);
3035 xmlSchemaPErr(ctxt, type->node, error,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003036 "%s: The facet '%s' is not allowed.\n",
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +00003037 BAD_CAST des, xmlSchemaFacetTypeToString(facet->type));
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003038 FREE_AND_NULL(des);
Daniel Veillardc0826a72004-08-10 14:17:33 +00003039}
3040
3041/**
3042 * xmlSchemaPMutualExclAttrErr:
3043 * @ctxt: the schema validation context
3044 * @error: the error code
3045 * @elemDes: the designation of the parent element node
3046 * @attr: the bad attribute node
3047 * @type: the corresponding type of the attribute node
3048 *
3049 * Reports an illegal attribute.
3050 */
3051static void
3052xmlSchemaPMutualExclAttrErr(xmlSchemaParserCtxtPtr ctxt,
3053 xmlParserErrors error,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003054 xmlSchemaBasicItemPtr ownerItem,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003055 xmlAttrPtr attr,
Daniel Veillardc0826a72004-08-10 14:17:33 +00003056 const char *name1,
3057 const char *name2)
3058{
3059 xmlChar *des = NULL;
3060
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003061 xmlSchemaFormatItemForReport(&des, NULL, WXS_BASIC_CAST ownerItem, attr->parent);
Daniel Veillardc0826a72004-08-10 14:17:33 +00003062 xmlSchemaPErrExt(ctxt, (xmlNodePtr) attr, error, NULL, NULL, NULL,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003063 "%s: The attributes '%s' and '%s' are mutually exclusive.\n",
Daniel Veillardc0826a72004-08-10 14:17:33 +00003064 BAD_CAST des, BAD_CAST name1, BAD_CAST name2, NULL, NULL);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003065 FREE_AND_NULL(des);
Daniel Veillardc0826a72004-08-10 14:17:33 +00003066}
3067
3068/**
3069 * xmlSchemaPSimpleTypeErr:
3070 * @ctxt: the schema validation context
3071 * @error: the error code
William M. Brack2f2a6632004-08-20 23:09:47 +00003072 * @type: the type specifier
Daniel Veillardc0826a72004-08-10 14:17:33 +00003073 * @ownerDes: the designation of the owner
Daniel Veillarddee23482008-04-11 12:58:43 +00003074 * @ownerItem: the schema object if existent
Daniel Veillardc0826a72004-08-10 14:17:33 +00003075 * @node: the validated node
3076 * @value: the validated value
3077 *
3078 * Reports a simple type validation error.
3079 * TODO: Should this report the value of an element as well?
3080 */
3081static void
Daniel Veillarddee23482008-04-11 12:58:43 +00003082xmlSchemaPSimpleTypeErr(xmlSchemaParserCtxtPtr ctxt,
Daniel Veillardc0826a72004-08-10 14:17:33 +00003083 xmlParserErrors error,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003084 xmlSchemaBasicItemPtr ownerItem ATTRIBUTE_UNUSED,
Daniel Veillardc0826a72004-08-10 14:17:33 +00003085 xmlNodePtr node,
William M. Brack2f2a6632004-08-20 23:09:47 +00003086 xmlSchemaTypePtr type,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003087 const char *expected,
Daniel Veillardc0826a72004-08-10 14:17:33 +00003088 const xmlChar *value,
3089 const char *message,
3090 const xmlChar *str1,
3091 const xmlChar *str2)
3092{
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003093 xmlChar *msg = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +00003094
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003095 xmlSchemaFormatNodeForError(&msg, ACTXT_CAST ctxt, node);
Daniel Veillardc0826a72004-08-10 14:17:33 +00003096 if (message == NULL) {
3097 /*
3098 * Use default messages.
Daniel Veillarddee23482008-04-11 12:58:43 +00003099 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003100 if (type != NULL) {
3101 if (node->type == XML_ATTRIBUTE_NODE)
3102 msg = xmlStrcat(msg, BAD_CAST "'%s' is not a valid value of ");
3103 else
3104 msg = xmlStrcat(msg, BAD_CAST "The character content is not a "
Daniel Veillarddee23482008-04-11 12:58:43 +00003105 "valid value of ");
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003106 if (! xmlSchemaIsGlobalItem(type))
3107 msg = xmlStrcat(msg, BAD_CAST "the local ");
3108 else
3109 msg = xmlStrcat(msg, BAD_CAST "the ");
Daniel Veillarddee23482008-04-11 12:58:43 +00003110
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003111 if (WXS_IS_ATOMIC(type))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003112 msg = xmlStrcat(msg, BAD_CAST "atomic type");
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003113 else if (WXS_IS_LIST(type))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003114 msg = xmlStrcat(msg, BAD_CAST "list type");
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003115 else if (WXS_IS_UNION(type))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003116 msg = xmlStrcat(msg, BAD_CAST "union type");
Daniel Veillarddee23482008-04-11 12:58:43 +00003117
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003118 if (xmlSchemaIsGlobalItem(type)) {
3119 xmlChar *str = NULL;
3120 msg = xmlStrcat(msg, BAD_CAST " '");
3121 if (type->builtInType != 0) {
3122 msg = xmlStrcat(msg, BAD_CAST "xs:");
3123 msg = xmlStrcat(msg, type->name);
Daniel Veillarddee23482008-04-11 12:58:43 +00003124 } else
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003125 msg = xmlStrcat(msg,
3126 xmlSchemaFormatQName(&str,
3127 type->targetNamespace, type->name));
3128 msg = xmlStrcat(msg, BAD_CAST "'.");
3129 FREE_AND_NULL(str);
3130 }
Daniel Veillardc0826a72004-08-10 14:17:33 +00003131 } else {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003132 if (node->type == XML_ATTRIBUTE_NODE)
3133 msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not valid.");
3134 else
3135 msg = xmlStrcat(msg, BAD_CAST "The character content is not "
3136 "valid.");
Daniel Veillarddee23482008-04-11 12:58:43 +00003137 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003138 if (expected) {
3139 msg = xmlStrcat(msg, BAD_CAST " Expected is '");
3140 msg = xmlStrcat(msg, BAD_CAST expected);
3141 msg = xmlStrcat(msg, BAD_CAST "'.\n");
3142 } else
3143 msg = xmlStrcat(msg, BAD_CAST "\n");
Daniel Veillardc0826a72004-08-10 14:17:33 +00003144 if (node->type == XML_ATTRIBUTE_NODE)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003145 xmlSchemaPErr(ctxt, node, error, (const char *) msg, value, NULL);
3146 else
3147 xmlSchemaPErr(ctxt, node, error, (const char *) msg, NULL, NULL);
3148 } else {
Kasimier T. Buchcik2c9aac02005-07-21 22:14:12 +00003149 msg = xmlStrcat(msg, BAD_CAST message);
Kasimier T. Buchcik11162b72005-07-28 00:50:22 +00003150 msg = xmlStrcat(msg, BAD_CAST ".\n");
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003151 xmlSchemaPErrExt(ctxt, node, error, NULL, NULL, NULL,
Kasimier T. Buchcik2c9aac02005-07-21 22:14:12 +00003152 (const char*) msg, str1, str2, NULL, NULL, NULL);
Daniel Veillardc0826a72004-08-10 14:17:33 +00003153 }
Daniel Veillarddee23482008-04-11 12:58:43 +00003154 /* Cleanup. */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003155 FREE_AND_NULL(msg)
Daniel Veillardc0826a72004-08-10 14:17:33 +00003156}
3157
William M. Brack2f2a6632004-08-20 23:09:47 +00003158/**
3159 * xmlSchemaPContentErr:
3160 * @ctxt: the schema parser context
3161 * @error: the error code
3162 * @onwerDes: the designation of the holder of the content
3163 * @ownerItem: the owner item of the holder of the content
3164 * @ownerElem: the node of the holder of the content
3165 * @child: the invalid child node
3166 * @message: the optional error message
3167 * @content: the optional string describing the correct content
3168 *
3169 * Reports an error concerning the content of a schema element.
3170 */
Daniel Veillardc0826a72004-08-10 14:17:33 +00003171static void
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003172xmlSchemaPContentErr(xmlSchemaParserCtxtPtr ctxt,
Daniel Veillardc0826a72004-08-10 14:17:33 +00003173 xmlParserErrors error,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003174 xmlSchemaBasicItemPtr ownerItem,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003175 xmlNodePtr ownerElem,
Daniel Veillardc0826a72004-08-10 14:17:33 +00003176 xmlNodePtr child,
3177 const char *message,
3178 const char *content)
3179{
3180 xmlChar *des = NULL;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003181
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003182 xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem);
Daniel Veillardc0826a72004-08-10 14:17:33 +00003183 if (message != NULL)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003184 xmlSchemaPErr2(ctxt, ownerElem, child, error,
3185 "%s: %s.\n",
Daniel Veillardc0826a72004-08-10 14:17:33 +00003186 BAD_CAST des, BAD_CAST message);
3187 else {
3188 if (content != NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003189 xmlSchemaPErr2(ctxt, ownerElem, child, error,
3190 "%s: The content is not valid. Expected is %s.\n",
Daniel Veillardc0826a72004-08-10 14:17:33 +00003191 BAD_CAST des, BAD_CAST content);
3192 } else {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003193 xmlSchemaPErr2(ctxt, ownerElem, child, error,
3194 "%s: The content is not valid.\n",
Daniel Veillardc0826a72004-08-10 14:17:33 +00003195 BAD_CAST des, NULL);
3196 }
3197 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003198 FREE_AND_NULL(des)
Daniel Veillardc0826a72004-08-10 14:17:33 +00003199}
3200
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003201/************************************************************************
3202 * *
3203 * Streamable error functions *
3204 * *
3205 ************************************************************************/
Kasimier T. Buchcik8b418172004-11-17 13:14:27 +00003206
Kasimier T. Buchcik9b77aa02005-03-04 22:04:16 +00003207
Kasimier T. Buchcik9b77aa02005-03-04 22:04:16 +00003208
Kasimier T. Buchcik9b77aa02005-03-04 22:04:16 +00003209
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003210/************************************************************************
3211 * *
3212 * Validation helper functions *
3213 * *
3214 ************************************************************************/
Kasimier T. Buchcik9b77aa02005-03-04 22:04:16 +00003215
Daniel Veillardc0826a72004-08-10 14:17:33 +00003216
Daniel Veillard4255d502002-04-16 15:50:10 +00003217/************************************************************************
3218 * *
3219 * Allocation functions *
3220 * *
3221 ************************************************************************/
3222
3223/**
Kasimier T. Buchcik87876402004-09-29 13:29:03 +00003224 * xmlSchemaNewSchemaForParserCtxt:
William M. Brack08171912003-12-29 02:52:11 +00003225 * @ctxt: a schema validation context
Daniel Veillard4255d502002-04-16 15:50:10 +00003226 *
3227 * Allocate a new Schema structure.
3228 *
3229 * Returns the newly allocated structure or NULL in case or error
3230 */
3231static xmlSchemaPtr
3232xmlSchemaNewSchema(xmlSchemaParserCtxtPtr ctxt)
3233{
3234 xmlSchemaPtr ret;
3235
3236 ret = (xmlSchemaPtr) xmlMalloc(sizeof(xmlSchema));
3237 if (ret == NULL) {
Daniel Veillardd0c9c322003-10-10 00:49:42 +00003238 xmlSchemaPErrMemory(ctxt, "allocating schema", NULL);
Daniel Veillard4255d502002-04-16 15:50:10 +00003239 return (NULL);
3240 }
3241 memset(ret, 0, sizeof(xmlSchema));
Daniel Veillardbe9c6322003-11-22 20:37:51 +00003242 ret->dict = ctxt->dict;
Daniel Veillard500a1de2004-03-22 15:22:58 +00003243 xmlDictReference(ret->dict);
Daniel Veillard4255d502002-04-16 15:50:10 +00003244
3245 return (ret);
3246}
3247
3248/**
3249 * xmlSchemaNewFacet:
Daniel Veillard4255d502002-04-16 15:50:10 +00003250 *
3251 * Allocate a new Facet structure.
3252 *
3253 * Returns the newly allocated structure or NULL in case or error
3254 */
Daniel Veillard8bc6cf92003-02-27 17:42:22 +00003255xmlSchemaFacetPtr
3256xmlSchemaNewFacet(void)
Daniel Veillard4255d502002-04-16 15:50:10 +00003257{
3258 xmlSchemaFacetPtr ret;
3259
3260 ret = (xmlSchemaFacetPtr) xmlMalloc(sizeof(xmlSchemaFacet));
3261 if (ret == NULL) {
Daniel Veillard4255d502002-04-16 15:50:10 +00003262 return (NULL);
3263 }
3264 memset(ret, 0, sizeof(xmlSchemaFacet));
3265
3266 return (ret);
3267}
3268
3269/**
3270 * xmlSchemaNewAnnot:
William M. Brack08171912003-12-29 02:52:11 +00003271 * @ctxt: a schema validation context
Daniel Veillard4255d502002-04-16 15:50:10 +00003272 * @node: a node
3273 *
3274 * Allocate a new annotation structure.
3275 *
3276 * Returns the newly allocated structure or NULL in case or error
3277 */
3278static xmlSchemaAnnotPtr
3279xmlSchemaNewAnnot(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node)
3280{
3281 xmlSchemaAnnotPtr ret;
3282
3283 ret = (xmlSchemaAnnotPtr) xmlMalloc(sizeof(xmlSchemaAnnot));
3284 if (ret == NULL) {
Daniel Veillardd0c9c322003-10-10 00:49:42 +00003285 xmlSchemaPErrMemory(ctxt, "allocating annotation", node);
Daniel Veillard4255d502002-04-16 15:50:10 +00003286 return (NULL);
3287 }
3288 memset(ret, 0, sizeof(xmlSchemaAnnot));
3289 ret->content = node;
3290 return (ret);
3291}
3292
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +00003293static xmlSchemaItemListPtr
Kasimier T. Buchcik630215b2005-08-22 10:15:39 +00003294xmlSchemaItemListCreate(void)
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +00003295{
3296 xmlSchemaItemListPtr ret;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003297
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +00003298 ret = xmlMalloc(sizeof(xmlSchemaItemList));
3299 if (ret == NULL) {
3300 xmlSchemaPErrMemory(NULL,
3301 "allocating an item list structure", NULL);
3302 return (NULL);
3303 }
3304 memset(ret, 0, sizeof(xmlSchemaItemList));
3305 return (ret);
3306}
3307
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +00003308static void
3309xmlSchemaItemListClear(xmlSchemaItemListPtr list)
3310{
3311 if (list->items != NULL) {
3312 xmlFree(list->items);
3313 list->items = NULL;
3314 }
3315 list->nbItems = 0;
3316 list->sizeItems = 0;
3317}
3318
3319static int
3320xmlSchemaItemListAdd(xmlSchemaItemListPtr list, void *item)
3321{
3322 if (list->items == NULL) {
3323 list->items = (void **) xmlMalloc(
3324 20 * sizeof(void *));
3325 if (list->items == NULL) {
3326 xmlSchemaPErrMemory(NULL, "allocating new item list", NULL);
3327 return(-1);
3328 }
3329 list->sizeItems = 20;
3330 } else if (list->sizeItems <= list->nbItems) {
3331 list->sizeItems *= 2;
3332 list->items = (void **) xmlRealloc(list->items,
3333 list->sizeItems * sizeof(void *));
3334 if (list->items == NULL) {
3335 xmlSchemaPErrMemory(NULL, "growing item list", NULL);
3336 list->sizeItems = 0;
3337 return(-1);
3338 }
3339 }
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +00003340 list->items[list->nbItems++] = item;
3341 return(0);
3342}
3343
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003344static int
3345xmlSchemaItemListAddSize(xmlSchemaItemListPtr list,
3346 int initialSize,
3347 void *item)
3348{
3349 if (list->items == NULL) {
3350 if (initialSize <= 0)
3351 initialSize = 1;
3352 list->items = (void **) xmlMalloc(
3353 initialSize * sizeof(void *));
3354 if (list->items == NULL) {
3355 xmlSchemaPErrMemory(NULL, "allocating new item list", NULL);
3356 return(-1);
3357 }
3358 list->sizeItems = initialSize;
3359 } else if (list->sizeItems <= list->nbItems) {
3360 list->sizeItems *= 2;
3361 list->items = (void **) xmlRealloc(list->items,
3362 list->sizeItems * sizeof(void *));
3363 if (list->items == NULL) {
3364 xmlSchemaPErrMemory(NULL, "growing item list", NULL);
3365 list->sizeItems = 0;
3366 return(-1);
3367 }
3368 }
3369 list->items[list->nbItems++] = item;
3370 return(0);
3371}
3372
3373static int
3374xmlSchemaItemListInsert(xmlSchemaItemListPtr list, void *item, int idx)
Daniel Veillarddee23482008-04-11 12:58:43 +00003375{
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003376 if (list->items == NULL) {
3377 list->items = (void **) xmlMalloc(
3378 20 * sizeof(void *));
3379 if (list->items == NULL) {
3380 xmlSchemaPErrMemory(NULL, "allocating new item list", NULL);
3381 return(-1);
3382 }
3383 list->sizeItems = 20;
3384 } else if (list->sizeItems <= list->nbItems) {
3385 list->sizeItems *= 2;
3386 list->items = (void **) xmlRealloc(list->items,
3387 list->sizeItems * sizeof(void *));
3388 if (list->items == NULL) {
3389 xmlSchemaPErrMemory(NULL, "growing item list", NULL);
3390 list->sizeItems = 0;
3391 return(-1);
3392 }
3393 }
3394 /*
3395 * Just append if the index is greater/equal than the item count.
3396 */
3397 if (idx >= list->nbItems) {
3398 list->items[list->nbItems++] = item;
3399 } else {
3400 int i;
3401 for (i = list->nbItems; i > idx; i--)
3402 list->items[i] = list->items[i-1];
3403 list->items[idx] = item;
3404 list->nbItems++;
3405 }
3406 return(0);
3407}
3408
3409#if 0 /* enable if ever needed */
3410static int
3411xmlSchemaItemListInsertSize(xmlSchemaItemListPtr list,
3412 int initialSize,
3413 void *item,
3414 int idx)
Daniel Veillarddee23482008-04-11 12:58:43 +00003415{
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003416 if (list->items == NULL) {
3417 if (initialSize <= 0)
3418 initialSize = 1;
3419 list->items = (void **) xmlMalloc(
3420 initialSize * sizeof(void *));
3421 if (list->items == NULL) {
3422 xmlSchemaPErrMemory(NULL, "allocating new item list", NULL);
3423 return(-1);
3424 }
3425 list->sizeItems = initialSize;
3426 } else if (list->sizeItems <= list->nbItems) {
3427 list->sizeItems *= 2;
3428 list->items = (void **) xmlRealloc(list->items,
3429 list->sizeItems * sizeof(void *));
3430 if (list->items == NULL) {
3431 xmlSchemaPErrMemory(NULL, "growing item list", NULL);
3432 list->sizeItems = 0;
3433 return(-1);
3434 }
3435 }
3436 /*
3437 * Just append if the index is greater/equal than the item count.
3438 */
3439 if (idx >= list->nbItems) {
3440 list->items[list->nbItems++] = item;
3441 } else {
3442 int i;
3443 for (i = list->nbItems; i > idx; i--)
3444 list->items[i] = list->items[i-1];
3445 list->items[idx] = item;
3446 list->nbItems++;
3447 }
3448 return(0);
3449}
3450#endif
3451
3452static int
3453xmlSchemaItemListRemove(xmlSchemaItemListPtr list, int idx)
3454{
3455 int i;
3456 if ((list->items == NULL) || (idx >= list->nbItems)) {
3457 xmlSchemaPSimpleErr("Internal error: xmlSchemaItemListRemove, "
3458 "index error.\n");
3459 return(-1);
3460 }
3461
3462 if (list->nbItems == 1) {
3463 /* TODO: Really free the list? */
3464 xmlFree(list->items);
3465 list->items = NULL;
3466 list->nbItems = 0;
3467 list->sizeItems = 0;
3468 } else if (list->nbItems -1 == idx) {
3469 list->nbItems--;
Daniel Veillarddee23482008-04-11 12:58:43 +00003470 } else {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003471 for (i = idx; i < list->nbItems -1; i++)
3472 list->items[i] = list->items[i+1];
3473 list->nbItems--;
3474 }
3475 return(0);
3476}
3477
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +00003478/**
Kasimier T. Buchcik630215b2005-08-22 10:15:39 +00003479 * xmlSchemaItemListFree:
3480 * @annot: a schema type structure
3481 *
3482 * Deallocate a annotation structure
3483 */
3484static void
3485xmlSchemaItemListFree(xmlSchemaItemListPtr list)
3486{
3487 if (list == NULL)
3488 return;
3489 if (list->items != NULL)
3490 xmlFree(list->items);
3491 xmlFree(list);
3492}
3493
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003494static void
3495xmlSchemaBucketFree(xmlSchemaBucketPtr bucket)
Kasimier T. Buchcik630215b2005-08-22 10:15:39 +00003496{
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003497 if (bucket == NULL)
3498 return;
3499 if (bucket->globals != NULL) {
3500 xmlSchemaComponentListFree(bucket->globals);
3501 xmlSchemaItemListFree(bucket->globals);
3502 }
3503 if (bucket->locals != NULL) {
3504 xmlSchemaComponentListFree(bucket->locals);
Daniel Veillarddee23482008-04-11 12:58:43 +00003505 xmlSchemaItemListFree(bucket->locals);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003506 }
3507 if (bucket->relations != NULL) {
3508 xmlSchemaSchemaRelationPtr prev, cur = bucket->relations;
3509 do {
Daniel Veillarddee23482008-04-11 12:58:43 +00003510 prev = cur;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003511 cur = cur->next;
3512 xmlFree(prev);
3513 } while (cur != NULL);
3514 }
3515 if ((! bucket->preserveDoc) && (bucket->doc != NULL)) {
3516 xmlFreeDoc(bucket->doc);
Daniel Veillarddee23482008-04-11 12:58:43 +00003517 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003518 if (bucket->type == XML_SCHEMA_SCHEMA_IMPORT) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003519 if (WXS_IMPBUCKET(bucket)->schema != NULL)
3520 xmlSchemaFree(WXS_IMPBUCKET(bucket)->schema);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003521 }
3522 xmlFree(bucket);
3523}
Kasimier T. Buchcik630215b2005-08-22 10:15:39 +00003524
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003525static xmlSchemaBucketPtr
3526xmlSchemaBucketCreate(xmlSchemaParserCtxtPtr pctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003527 int type, const xmlChar *targetNamespace)
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003528{
3529 xmlSchemaBucketPtr ret;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003530 int size;
3531 xmlSchemaPtr mainSchema;
3532
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003533 if (WXS_CONSTRUCTOR(pctxt)->mainSchema == NULL) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003534 PERROR_INT("xmlSchemaBucketCreate",
3535 "no main schema on constructor");
Kasimier T. Buchcik630215b2005-08-22 10:15:39 +00003536 return(NULL);
3537 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003538 mainSchema = WXS_CONSTRUCTOR(pctxt)->mainSchema;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003539 /* Create the schema bucket. */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003540 if (WXS_IS_BUCKET_INCREDEF(type))
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003541 size = sizeof(xmlSchemaInclude);
3542 else
3543 size = sizeof(xmlSchemaImport);
3544 ret = (xmlSchemaBucketPtr) xmlMalloc(size);
3545 if (ret == NULL) {
3546 xmlSchemaPErrMemory(NULL, "allocating schema bucket", NULL);
3547 return(NULL);
3548 }
3549 memset(ret, 0, size);
3550 ret->targetNamespace = targetNamespace;
3551 ret->type = type;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003552 ret->globals = xmlSchemaItemListCreate();
3553 if (ret->globals == NULL) {
3554 xmlFree(ret);
3555 return(NULL);
3556 }
3557 ret->locals = xmlSchemaItemListCreate();
3558 if (ret->locals == NULL) {
3559 xmlFree(ret);
3560 return(NULL);
3561 }
Daniel Veillarddee23482008-04-11 12:58:43 +00003562 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003563 * The following will assure that only the first bucket is marked as
3564 * XML_SCHEMA_SCHEMA_MAIN and it points to the *main* schema.
3565 * For each following import buckets an xmlSchema will be created.
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +00003566 * An xmlSchema will be created for every distinct targetNamespace.
3567 * We assign the targetNamespace to the schemata here.
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003568 */
3569 if (! WXS_HAS_BUCKETS(pctxt)) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003570 if (WXS_IS_BUCKET_INCREDEF(type)) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003571 PERROR_INT("xmlSchemaBucketCreate",
3572 "first bucket but it's an include or redefine");
3573 xmlSchemaBucketFree(ret);
3574 return(NULL);
3575 }
Daniel Veillarddee23482008-04-11 12:58:43 +00003576 /* Force the type to be XML_SCHEMA_SCHEMA_MAIN. */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003577 ret->type = XML_SCHEMA_SCHEMA_MAIN;
3578 /* Point to the *main* schema. */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003579 WXS_CONSTRUCTOR(pctxt)->mainBucket = ret;
3580 WXS_IMPBUCKET(ret)->schema = mainSchema;
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +00003581 /*
3582 * Ensure that the main schema gets a targetNamespace.
3583 */
3584 mainSchema->targetNamespace = targetNamespace;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003585 } else {
Daniel Veillarddee23482008-04-11 12:58:43 +00003586 if (type == XML_SCHEMA_SCHEMA_MAIN) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003587 PERROR_INT("xmlSchemaBucketCreate",
3588 "main bucket but it's not the first one");
3589 xmlSchemaBucketFree(ret);
3590 return(NULL);
Daniel Veillarddee23482008-04-11 12:58:43 +00003591 } else if (type == XML_SCHEMA_SCHEMA_IMPORT) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003592 /*
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +00003593 * Create a schema for imports and assign the
3594 * targetNamespace.
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003595 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003596 WXS_IMPBUCKET(ret)->schema = xmlSchemaNewSchema(pctxt);
3597 if (WXS_IMPBUCKET(ret)->schema == NULL) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003598 xmlSchemaBucketFree(ret);
3599 return(NULL);
3600 }
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +00003601 WXS_IMPBUCKET(ret)->schema->targetNamespace = targetNamespace;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003602 }
Daniel Veillarddee23482008-04-11 12:58:43 +00003603 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003604 if (WXS_IS_BUCKET_IMPMAIN(type)) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003605 int res;
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +00003606 /*
3607 * Imports go into the "schemasImports" slot of the main *schema*.
3608 * Note that we create an import entry for the main schema as well; i.e.,
3609 * even if there's only one schema, we'll get an import.
3610 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003611 if (mainSchema->schemasImports == NULL) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003612 mainSchema->schemasImports = xmlHashCreateDict(5,
3613 WXS_CONSTRUCTOR(pctxt)->dict);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003614 if (mainSchema->schemasImports == NULL) {
3615 xmlSchemaBucketFree(ret);
3616 return(NULL);
3617 }
3618 }
3619 if (targetNamespace == NULL)
3620 res = xmlHashAddEntry(mainSchema->schemasImports,
3621 XML_SCHEMAS_NO_NAMESPACE, ret);
3622 else
3623 res = xmlHashAddEntry(mainSchema->schemasImports,
3624 targetNamespace, ret);
3625 if (res != 0) {
3626 PERROR_INT("xmlSchemaBucketCreate",
3627 "failed to add the schema bucket to the hash");
3628 xmlSchemaBucketFree(ret);
3629 return(NULL);
3630 }
3631 } else {
3632 /* Set the @ownerImport of an include bucket. */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003633 if (WXS_IS_BUCKET_IMPMAIN(WXS_CONSTRUCTOR(pctxt)->bucket->type))
3634 WXS_INCBUCKET(ret)->ownerImport =
3635 WXS_IMPBUCKET(WXS_CONSTRUCTOR(pctxt)->bucket);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003636 else
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003637 WXS_INCBUCKET(ret)->ownerImport =
3638 WXS_INCBUCKET(WXS_CONSTRUCTOR(pctxt)->bucket)->ownerImport;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003639
3640 /* Includes got into the "includes" slot of the *main* schema. */
3641 if (mainSchema->includes == NULL) {
3642 mainSchema->includes = xmlSchemaItemListCreate();
3643 if (mainSchema->includes == NULL) {
3644 xmlSchemaBucketFree(ret);
3645 return(NULL);
Daniel Veillarddee23482008-04-11 12:58:43 +00003646 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003647 }
3648 xmlSchemaItemListAdd(mainSchema->includes, ret);
3649 }
Daniel Veillarddee23482008-04-11 12:58:43 +00003650 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003651 * Add to list of all buckets; this is used for lookup
3652 * during schema construction time only.
3653 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003654 if (xmlSchemaItemListAdd(WXS_CONSTRUCTOR(pctxt)->buckets, ret) == -1)
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003655 return(NULL);
Kasimier T. Buchcik630215b2005-08-22 10:15:39 +00003656 return(ret);
3657}
3658
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +00003659static int
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003660xmlSchemaAddItemSize(xmlSchemaItemListPtr *list, int initialSize, void *item)
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +00003661{
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003662 if (*list == NULL) {
3663 *list = xmlSchemaItemListCreate();
3664 if (*list == NULL)
3665 return(-1);
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +00003666 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003667 xmlSchemaItemListAddSize(*list, initialSize, item);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00003668 return(0);
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +00003669}
3670
3671/**
Daniel Veillardfdc91562002-07-01 21:52:03 +00003672 * xmlSchemaFreeAnnot:
3673 * @annot: a schema type structure
3674 *
3675 * Deallocate a annotation structure
3676 */
3677static void
3678xmlSchemaFreeAnnot(xmlSchemaAnnotPtr annot)
3679{
3680 if (annot == NULL)
3681 return;
Kasimier T. Buchcik004b5462005-08-08 12:43:09 +00003682 if (annot->next == NULL) {
3683 xmlFree(annot);
3684 } else {
3685 xmlSchemaAnnotPtr prev;
3686
3687 do {
3688 prev = annot;
3689 annot = annot->next;
3690 xmlFree(prev);
3691 } while (annot != NULL);
3692 }
Daniel Veillardfdc91562002-07-01 21:52:03 +00003693}
3694
3695/**
Daniel Veillard4255d502002-04-16 15:50:10 +00003696 * xmlSchemaFreeNotation:
3697 * @schema: a schema notation structure
3698 *
3699 * Deallocate a Schema Notation structure.
3700 */
3701static void
3702xmlSchemaFreeNotation(xmlSchemaNotationPtr nota)
3703{
3704 if (nota == NULL)
3705 return;
Daniel Veillard4255d502002-04-16 15:50:10 +00003706 xmlFree(nota);
3707}
3708
3709/**
3710 * xmlSchemaFreeAttribute:
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003711 * @attr: an attribute declaration
Daniel Veillard4255d502002-04-16 15:50:10 +00003712 *
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003713 * Deallocates an attribute declaration structure.
Daniel Veillard4255d502002-04-16 15:50:10 +00003714 */
3715static void
3716xmlSchemaFreeAttribute(xmlSchemaAttributePtr attr)
3717{
3718 if (attr == NULL)
3719 return;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003720 if (attr->annot != NULL)
Daniel Veillardc0826a72004-08-10 14:17:33 +00003721 xmlSchemaFreeAnnot(attr->annot);
Kasimier T. Buchcik87876402004-09-29 13:29:03 +00003722 if (attr->defVal != NULL)
3723 xmlSchemaFreeValue(attr->defVal);
Daniel Veillard4255d502002-04-16 15:50:10 +00003724 xmlFree(attr);
3725}
3726
3727/**
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003728 * xmlSchemaFreeAttributeUse:
3729 * @use: an attribute use
3730 *
3731 * Deallocates an attribute use structure.
3732 */
3733static void
3734xmlSchemaFreeAttributeUse(xmlSchemaAttributeUsePtr use)
3735{
3736 if (use == NULL)
3737 return;
3738 if (use->annot != NULL)
3739 xmlSchemaFreeAnnot(use->annot);
3740 if (use->defVal != NULL)
3741 xmlSchemaFreeValue(use->defVal);
3742 xmlFree(use);
3743}
3744
3745/**
3746 * xmlSchemaFreeAttributeUseProhib:
3747 * @prohib: an attribute use prohibition
3748 *
3749 * Deallocates an attribute use structure.
3750 */
3751static void
3752xmlSchemaFreeAttributeUseProhib(xmlSchemaAttributeUseProhibPtr prohib)
3753{
3754 if (prohib == NULL)
3755 return;
3756 xmlFree(prohib);
3757}
3758
3759/**
Daniel Veillard3646d642004-06-02 19:19:14 +00003760 * xmlSchemaFreeWildcardNsSet:
3761 * set: a schema wildcard namespace
3762 *
Daniel Veillard01fa6152004-06-29 17:04:39 +00003763 * Deallocates a list of wildcard constraint structures.
Daniel Veillard3646d642004-06-02 19:19:14 +00003764 */
3765static void
3766xmlSchemaFreeWildcardNsSet(xmlSchemaWildcardNsPtr set)
3767{
3768 xmlSchemaWildcardNsPtr next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003769
Daniel Veillard3646d642004-06-02 19:19:14 +00003770 while (set != NULL) {
3771 next = set->next;
3772 xmlFree(set);
3773 set = next;
3774 }
3775}
3776
3777/**
3778 * xmlSchemaFreeWildcard:
Daniel Veillard01fa6152004-06-29 17:04:39 +00003779 * @wildcard: a wildcard structure
Daniel Veillard3646d642004-06-02 19:19:14 +00003780 *
Daniel Veillard01fa6152004-06-29 17:04:39 +00003781 * Deallocates a wildcard structure.
Daniel Veillard3646d642004-06-02 19:19:14 +00003782 */
Daniel Veillard01fa6152004-06-29 17:04:39 +00003783void
Daniel Veillard3646d642004-06-02 19:19:14 +00003784xmlSchemaFreeWildcard(xmlSchemaWildcardPtr wildcard)
3785{
3786 if (wildcard == NULL)
3787 return;
3788 if (wildcard->annot != NULL)
3789 xmlSchemaFreeAnnot(wildcard->annot);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003790 if (wildcard->nsSet != NULL)
3791 xmlSchemaFreeWildcardNsSet(wildcard->nsSet);
3792 if (wildcard->negNsSet != NULL)
3793 xmlFree(wildcard->negNsSet);
Daniel Veillard3646d642004-06-02 19:19:14 +00003794 xmlFree(wildcard);
3795}
3796
3797/**
Daniel Veillard4255d502002-04-16 15:50:10 +00003798 * xmlSchemaFreeAttributeGroup:
3799 * @schema: a schema attribute group structure
3800 *
3801 * Deallocate a Schema Attribute Group structure.
3802 */
3803static void
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003804xmlSchemaFreeAttributeGroup(xmlSchemaAttributeGroupPtr attrGr)
Daniel Veillard4255d502002-04-16 15:50:10 +00003805{
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003806 if (attrGr == NULL)
Daniel Veillard4255d502002-04-16 15:50:10 +00003807 return;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003808 if (attrGr->annot != NULL)
3809 xmlSchemaFreeAnnot(attrGr->annot);
3810 if (attrGr->attrUses != NULL)
3811 xmlSchemaItemListFree(WXS_LIST_CAST attrGr->attrUses);
3812 xmlFree(attrGr);
Daniel Veillard3646d642004-06-02 19:19:14 +00003813}
3814
3815/**
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00003816 * xmlSchemaFreeQNameRef:
3817 * @item: a QName reference structure
3818 *
3819 * Deallocatea a QName reference structure.
3820 */
3821static void
3822xmlSchemaFreeQNameRef(xmlSchemaQNameRefPtr item)
3823{
3824 xmlFree(item);
3825}
3826
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +00003827/**
Daniel Veillard01fa6152004-06-29 17:04:39 +00003828 * xmlSchemaFreeTypeLinkList:
3829 * @alink: a type link
3830 *
3831 * Deallocate a list of types.
3832 */
3833static void
3834xmlSchemaFreeTypeLinkList(xmlSchemaTypeLinkPtr link)
3835{
3836 xmlSchemaTypeLinkPtr next;
3837
3838 while (link != NULL) {
3839 next = link->next;
3840 xmlFree(link);
3841 link = next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003842 }
Daniel Veillard01fa6152004-06-29 17:04:39 +00003843}
3844
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +00003845static void
3846xmlSchemaFreeIDCStateObjList(xmlSchemaIDCStateObjPtr sto)
3847{
3848 xmlSchemaIDCStateObjPtr next;
3849 while (sto != NULL) {
3850 next = sto->next;
3851 if (sto->history != NULL)
3852 xmlFree(sto->history);
3853 if (sto->xpathCtxt != NULL)
3854 xmlFreeStreamCtxt((xmlStreamCtxtPtr) sto->xpathCtxt);
3855 xmlFree(sto);
3856 sto = next;
3857 }
3858}
3859
3860/**
3861 * xmlSchemaFreeIDC:
3862 * @idc: a identity-constraint definition
3863 *
3864 * Deallocates an identity-constraint definition.
3865 */
3866static void
3867xmlSchemaFreeIDC(xmlSchemaIDCPtr idcDef)
3868{
3869 xmlSchemaIDCSelectPtr cur, prev;
3870
3871 if (idcDef == NULL)
3872 return;
3873 if (idcDef->annot != NULL)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003874 xmlSchemaFreeAnnot(idcDef->annot);
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +00003875 /* Selector */
3876 if (idcDef->selector != NULL) {
3877 if (idcDef->selector->xpathComp != NULL)
3878 xmlFreePattern((xmlPatternPtr) idcDef->selector->xpathComp);
3879 xmlFree(idcDef->selector);
3880 }
3881 /* Fields */
3882 if (idcDef->fields != NULL) {
3883 cur = idcDef->fields;
3884 do {
3885 prev = cur;
3886 cur = cur->next;
3887 if (prev->xpathComp != NULL)
3888 xmlFreePattern((xmlPatternPtr) prev->xpathComp);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003889 xmlFree(prev);
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +00003890 } while (cur != NULL);
3891 }
3892 xmlFree(idcDef);
3893}
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +00003894
Daniel Veillard01fa6152004-06-29 17:04:39 +00003895/**
Daniel Veillard4255d502002-04-16 15:50:10 +00003896 * xmlSchemaFreeElement:
3897 * @schema: a schema element structure
3898 *
3899 * Deallocate a Schema Element structure.
3900 */
3901static void
3902xmlSchemaFreeElement(xmlSchemaElementPtr elem)
3903{
3904 if (elem == NULL)
3905 return;
Daniel Veillard32370232002-10-16 14:08:14 +00003906 if (elem->annot != NULL)
3907 xmlSchemaFreeAnnot(elem->annot);
Daniel Veillard4255d502002-04-16 15:50:10 +00003908 if (elem->contModel != NULL)
Daniel Veillardd0c9c322003-10-10 00:49:42 +00003909 xmlRegFreeRegexp(elem->contModel);
Kasimier T. Buchcik87876402004-09-29 13:29:03 +00003910 if (elem->defVal != NULL)
3911 xmlSchemaFreeValue(elem->defVal);
Daniel Veillard4255d502002-04-16 15:50:10 +00003912 xmlFree(elem);
3913}
3914
3915/**
3916 * xmlSchemaFreeFacet:
3917 * @facet: a schema facet structure
3918 *
3919 * Deallocate a Schema Facet structure.
3920 */
Daniel Veillard8bc6cf92003-02-27 17:42:22 +00003921void
Daniel Veillard4255d502002-04-16 15:50:10 +00003922xmlSchemaFreeFacet(xmlSchemaFacetPtr facet)
3923{
3924 if (facet == NULL)
3925 return;
Daniel Veillard4255d502002-04-16 15:50:10 +00003926 if (facet->val != NULL)
Daniel Veillardd0c9c322003-10-10 00:49:42 +00003927 xmlSchemaFreeValue(facet->val);
Daniel Veillard4255d502002-04-16 15:50:10 +00003928 if (facet->regexp != NULL)
Daniel Veillardd0c9c322003-10-10 00:49:42 +00003929 xmlRegFreeRegexp(facet->regexp);
Daniel Veillardfdc91562002-07-01 21:52:03 +00003930 if (facet->annot != NULL)
Daniel Veillardd0c9c322003-10-10 00:49:42 +00003931 xmlSchemaFreeAnnot(facet->annot);
Daniel Veillard4255d502002-04-16 15:50:10 +00003932 xmlFree(facet);
3933}
3934
3935/**
3936 * xmlSchemaFreeType:
3937 * @type: a schema type structure
3938 *
3939 * Deallocate a Schema Type structure.
3940 */
3941void
3942xmlSchemaFreeType(xmlSchemaTypePtr type)
3943{
3944 if (type == NULL)
3945 return;
Daniel Veillard4255d502002-04-16 15:50:10 +00003946 if (type->annot != NULL)
Daniel Veillard32370232002-10-16 14:08:14 +00003947 xmlSchemaFreeAnnot(type->annot);
Daniel Veillard4255d502002-04-16 15:50:10 +00003948 if (type->facets != NULL) {
Daniel Veillardd0c9c322003-10-10 00:49:42 +00003949 xmlSchemaFacetPtr facet, next;
Daniel Veillard4255d502002-04-16 15:50:10 +00003950
Daniel Veillardd0c9c322003-10-10 00:49:42 +00003951 facet = type->facets;
3952 while (facet != NULL) {
3953 next = facet->next;
3954 xmlSchemaFreeFacet(facet);
3955 facet = next;
3956 }
Daniel Veillard4255d502002-04-16 15:50:10 +00003957 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00003958 if (type->attrUses != NULL)
3959 xmlSchemaItemListFree((xmlSchemaItemListPtr) type->attrUses);
Daniel Veillard01fa6152004-06-29 17:04:39 +00003960 if (type->memberTypes != NULL)
3961 xmlSchemaFreeTypeLinkList(type->memberTypes);
3962 if (type->facetSet != NULL) {
3963 xmlSchemaFacetLinkPtr next, link;
3964
3965 link = type->facetSet;
3966 do {
3967 next = link->next;
3968 xmlFree(link);
3969 link = next;
3970 } while (link != NULL);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00003971 }
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +00003972 if (type->contModel != NULL)
3973 xmlRegFreeRegexp(type->contModel);
Daniel Veillard4255d502002-04-16 15:50:10 +00003974 xmlFree(type);
3975}
3976
3977/**
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00003978 * xmlSchemaFreeModelGroupDef:
3979 * @item: a schema model group definition
3980 *
3981 * Deallocates a schema model group definition.
3982 */
3983static void
3984xmlSchemaFreeModelGroupDef(xmlSchemaModelGroupDefPtr item)
3985{
3986 if (item->annot != NULL)
3987 xmlSchemaFreeAnnot(item->annot);
3988 xmlFree(item);
3989}
3990
3991/**
3992 * xmlSchemaFreeModelGroup:
3993 * @item: a schema model group
3994 *
3995 * Deallocates a schema model group structure.
3996 */
3997static void
3998xmlSchemaFreeModelGroup(xmlSchemaModelGroupPtr item)
3999{
4000 if (item->annot != NULL)
4001 xmlSchemaFreeAnnot(item->annot);
4002 xmlFree(item);
4003}
4004
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004005static void
4006xmlSchemaComponentListFree(xmlSchemaItemListPtr list)
4007{
4008 if ((list == NULL) || (list->nbItems == 0))
4009 return;
4010 {
4011 xmlSchemaTreeItemPtr item;
4012 xmlSchemaTreeItemPtr *items = (xmlSchemaTreeItemPtr *) list->items;
4013 int i;
4014
4015 for (i = 0; i < list->nbItems; i++) {
4016 item = items[i];
4017 if (item == NULL)
Daniel Veillarddee23482008-04-11 12:58:43 +00004018 continue;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004019 switch (item->type) {
4020 case XML_SCHEMA_TYPE_SIMPLE:
4021 case XML_SCHEMA_TYPE_COMPLEX:
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00004022 xmlSchemaFreeType((xmlSchemaTypePtr) item);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004023 break;
4024 case XML_SCHEMA_TYPE_ATTRIBUTE:
4025 xmlSchemaFreeAttribute((xmlSchemaAttributePtr) item);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00004026 break;
4027 case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
4028 xmlSchemaFreeAttributeUse((xmlSchemaAttributeUsePtr) item);
4029 break;
4030 case XML_SCHEMA_EXTRA_ATTR_USE_PROHIB:
4031 xmlSchemaFreeAttributeUseProhib(
4032 (xmlSchemaAttributeUseProhibPtr) item);
4033 break;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004034 case XML_SCHEMA_TYPE_ELEMENT:
4035 xmlSchemaFreeElement((xmlSchemaElementPtr) item);
4036 break;
4037 case XML_SCHEMA_TYPE_PARTICLE:
4038 if (item->annot != NULL)
4039 xmlSchemaFreeAnnot(item->annot);
4040 xmlFree(item);
4041 break;
4042 case XML_SCHEMA_TYPE_SEQUENCE:
4043 case XML_SCHEMA_TYPE_CHOICE:
4044 case XML_SCHEMA_TYPE_ALL:
4045 xmlSchemaFreeModelGroup((xmlSchemaModelGroupPtr) item);
4046 break;
4047 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
4048 xmlSchemaFreeAttributeGroup(
4049 (xmlSchemaAttributeGroupPtr) item);
4050 break;
4051 case XML_SCHEMA_TYPE_GROUP:
4052 xmlSchemaFreeModelGroupDef(
4053 (xmlSchemaModelGroupDefPtr) item);
4054 break;
4055 case XML_SCHEMA_TYPE_ANY:
4056 case XML_SCHEMA_TYPE_ANY_ATTRIBUTE:
4057 xmlSchemaFreeWildcard((xmlSchemaWildcardPtr) item);
4058 break;
4059 case XML_SCHEMA_TYPE_IDC_KEY:
4060 case XML_SCHEMA_TYPE_IDC_UNIQUE:
4061 case XML_SCHEMA_TYPE_IDC_KEYREF:
4062 xmlSchemaFreeIDC((xmlSchemaIDCPtr) item);
4063 break;
4064 case XML_SCHEMA_TYPE_NOTATION:
4065 xmlSchemaFreeNotation((xmlSchemaNotationPtr) item);
4066 break;
4067 case XML_SCHEMA_EXTRA_QNAMEREF:
4068 xmlSchemaFreeQNameRef((xmlSchemaQNameRefPtr) item);
4069 break;
4070 default: {
4071 /* TODO: This should never be hit. */
4072 xmlSchemaPSimpleInternalErr(NULL,
4073 "Internal error: xmlSchemaComponentListFree, "
4074 "unexpected component type '%s'\n",
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00004075 (const xmlChar *) WXS_ITEM_TYPE_NAME(item));
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004076 }
4077 break;
4078 }
4079 }
4080 list->nbItems = 0;
4081 }
4082}
4083
Daniel Veillardb0f397e2003-12-23 23:30:53 +00004084/**
Daniel Veillard4255d502002-04-16 15:50:10 +00004085 * xmlSchemaFree:
4086 * @schema: a schema structure
4087 *
4088 * Deallocate a Schema structure.
4089 */
4090void
4091xmlSchemaFree(xmlSchemaPtr schema)
4092{
4093 if (schema == NULL)
4094 return;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004095 /* @volatiles is not used anymore :-/ */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00004096 if (schema->volatiles != NULL)
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004097 TODO
4098 /*
4099 * Note that those slots are not responsible for freeing
4100 * schema components anymore; this will now be done by
4101 * the schema buckets.
4102 */
Daniel Veillard4255d502002-04-16 15:50:10 +00004103 if (schema->notaDecl != NULL)
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004104 xmlHashFree(schema->notaDecl, NULL);
Daniel Veillard4255d502002-04-16 15:50:10 +00004105 if (schema->attrDecl != NULL)
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004106 xmlHashFree(schema->attrDecl, NULL);
Daniel Veillard4255d502002-04-16 15:50:10 +00004107 if (schema->attrgrpDecl != NULL)
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004108 xmlHashFree(schema->attrgrpDecl, NULL);
Daniel Veillard4255d502002-04-16 15:50:10 +00004109 if (schema->elemDecl != NULL)
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004110 xmlHashFree(schema->elemDecl, NULL);
Daniel Veillard4255d502002-04-16 15:50:10 +00004111 if (schema->typeDecl != NULL)
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004112 xmlHashFree(schema->typeDecl, NULL);
Daniel Veillarda84c0b32003-06-02 16:58:46 +00004113 if (schema->groupDecl != NULL)
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004114 xmlHashFree(schema->groupDecl, NULL);
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +00004115 if (schema->idcDef != NULL)
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004116 xmlHashFree(schema->idcDef, NULL);
4117
Daniel Veillard1d913862003-11-21 00:28:39 +00004118 if (schema->schemasImports != NULL)
4119 xmlHashFree(schema->schemasImports,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004120 (xmlHashDeallocator) xmlSchemaBucketFree);
Daniel Veillardbd2904b2003-11-25 15:38:59 +00004121 if (schema->includes != NULL) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004122 xmlSchemaItemListPtr list = (xmlSchemaItemListPtr) schema->includes;
4123 int i;
4124 for (i = 0; i < list->nbItems; i++) {
Daniel Veillarddee23482008-04-11 12:58:43 +00004125 xmlSchemaBucketFree((xmlSchemaBucketPtr) list->items[i]);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004126 }
4127 xmlSchemaItemListFree(list);
Daniel Veillardbd2904b2003-11-25 15:38:59 +00004128 }
Daniel Veillard4255d502002-04-16 15:50:10 +00004129 if (schema->annot != NULL)
Daniel Veillardd0c9c322003-10-10 00:49:42 +00004130 xmlSchemaFreeAnnot(schema->annot);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004131 /* Never free the doc here, since this will be done by the buckets. */
4132
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004133 xmlDictFree(schema->dict);
Daniel Veillard4255d502002-04-16 15:50:10 +00004134 xmlFree(schema);
4135}
4136
4137/************************************************************************
4138 * *
Daniel Veillard4255d502002-04-16 15:50:10 +00004139 * Debug functions *
4140 * *
4141 ************************************************************************/
4142
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00004143#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillardd0c9c322003-10-10 00:49:42 +00004144
Kasimier T. Buchcikee8e8ae2005-10-17 14:15:37 +00004145static void
4146xmlSchemaTypeDump(xmlSchemaTypePtr type, FILE * output); /* forward */
4147
Daniel Veillard4255d502002-04-16 15:50:10 +00004148/**
4149 * xmlSchemaElementDump:
4150 * @elem: an element
4151 * @output: the file output
4152 *
4153 * Dump the element
4154 */
4155static void
4156xmlSchemaElementDump(xmlSchemaElementPtr elem, FILE * output,
Daniel Veillardd0c9c322003-10-10 00:49:42 +00004157 const xmlChar * name ATTRIBUTE_UNUSED,
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004158 const xmlChar * namespace ATTRIBUTE_UNUSED,
4159 const xmlChar * context ATTRIBUTE_UNUSED)
Daniel Veillard4255d502002-04-16 15:50:10 +00004160{
4161 if (elem == NULL)
4162 return;
4163
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00004164
4165 fprintf(output, "Element");
4166 if (elem->flags & XML_SCHEMAS_ELEM_GLOBAL)
4167 fprintf(output, " (global)");
Kasimier T. Buchcikee8e8ae2005-10-17 14:15:37 +00004168 fprintf(output, ": '%s' ", elem->name);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00004169 if (namespace != NULL)
Kasimier T. Buchcikee8e8ae2005-10-17 14:15:37 +00004170 fprintf(output, "ns '%s'", namespace);
Daniel Veillard4255d502002-04-16 15:50:10 +00004171 fprintf(output, "\n");
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00004172#if 0
Daniel Veillard4255d502002-04-16 15:50:10 +00004173 if ((elem->minOccurs != 1) || (elem->maxOccurs != 1)) {
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004174 fprintf(output, " min %d ", elem->minOccurs);
Daniel Veillardd0c9c322003-10-10 00:49:42 +00004175 if (elem->maxOccurs >= UNBOUNDED)
4176 fprintf(output, "max: unbounded\n");
4177 else if (elem->maxOccurs != 1)
4178 fprintf(output, "max: %d\n", elem->maxOccurs);
4179 else
4180 fprintf(output, "\n");
Daniel Veillard4255d502002-04-16 15:50:10 +00004181 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00004182#endif
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004183 /*
4184 * Misc other properties.
4185 */
4186 if ((elem->flags & XML_SCHEMAS_ELEM_NILLABLE) ||
4187 (elem->flags & XML_SCHEMAS_ELEM_ABSTRACT) ||
4188 (elem->flags & XML_SCHEMAS_ELEM_FIXED) ||
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00004189 (elem->flags & XML_SCHEMAS_ELEM_DEFAULT)) {
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004190 fprintf(output, " props: ");
4191 if (elem->flags & XML_SCHEMAS_ELEM_FIXED)
4192 fprintf(output, "[fixed] ");
4193 if (elem->flags & XML_SCHEMAS_ELEM_DEFAULT)
4194 fprintf(output, "[default] ");
4195 if (elem->flags & XML_SCHEMAS_ELEM_ABSTRACT)
4196 fprintf(output, "[abstract] ");
4197 if (elem->flags & XML_SCHEMAS_ELEM_NILLABLE)
4198 fprintf(output, "[nillable] ");
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004199 fprintf(output, "\n");
Daniel Veillard4255d502002-04-16 15:50:10 +00004200 }
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004201 /*
4202 * Default/fixed value.
4203 */
Daniel Veillard4255d502002-04-16 15:50:10 +00004204 if (elem->value != NULL)
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004205 fprintf(output, " value: '%s'\n", elem->value);
4206 /*
4207 * Type.
4208 */
4209 if (elem->namedType != NULL) {
Kasimier T. Buchcikee8e8ae2005-10-17 14:15:37 +00004210 fprintf(output, " type: '%s' ", elem->namedType);
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004211 if (elem->namedTypeNs != NULL)
Kasimier T. Buchcikee8e8ae2005-10-17 14:15:37 +00004212 fprintf(output, "ns '%s'\n", elem->namedTypeNs);
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004213 else
4214 fprintf(output, "\n");
Kasimier T. Buchcikee8e8ae2005-10-17 14:15:37 +00004215 } else if (elem->subtypes != NULL) {
4216 /*
4217 * Dump local types.
4218 */
4219 xmlSchemaTypeDump(elem->subtypes, output);
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004220 }
4221 /*
4222 * Substitution group.
4223 */
4224 if (elem->substGroup != NULL) {
Kasimier T. Buchcikee8e8ae2005-10-17 14:15:37 +00004225 fprintf(output, " substitutionGroup: '%s' ", elem->substGroup);
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004226 if (elem->substGroupNs != NULL)
Kasimier T. Buchcikee8e8ae2005-10-17 14:15:37 +00004227 fprintf(output, "ns '%s'\n", elem->substGroupNs);
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004228 else
4229 fprintf(output, "\n");
4230 }
Daniel Veillard4255d502002-04-16 15:50:10 +00004231}
4232
4233/**
4234 * xmlSchemaAnnotDump:
4235 * @output: the file output
4236 * @annot: a annotation
4237 *
4238 * Dump the annotation
4239 */
4240static void
4241xmlSchemaAnnotDump(FILE * output, xmlSchemaAnnotPtr annot)
4242{
4243 xmlChar *content;
4244
4245 if (annot == NULL)
4246 return;
4247
4248 content = xmlNodeGetContent(annot->content);
4249 if (content != NULL) {
4250 fprintf(output, " Annot: %s\n", content);
4251 xmlFree(content);
4252 } else
4253 fprintf(output, " Annot: empty\n");
4254}
4255
4256/**
Kasimier T. Buchcikee8e8ae2005-10-17 14:15:37 +00004257 * xmlSchemaContentModelDump:
4258 * @particle: the schema particle
4259 * @output: the file output
4260 * @depth: the depth used for intentation
Daniel Veillard4255d502002-04-16 15:50:10 +00004261 *
4262 * Dump a SchemaType structure
4263 */
4264static void
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00004265xmlSchemaContentModelDump(xmlSchemaParticlePtr particle, FILE * output, int depth)
4266{
4267 xmlChar *str = NULL;
4268 xmlSchemaTreeItemPtr term;
4269 char shift[100];
4270 int i;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004271
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00004272 if (particle == NULL)
4273 return;
4274 for (i = 0;((i < depth) && (i < 25));i++)
4275 shift[2 * i] = shift[2 * i + 1] = ' ';
4276 shift[2 * i] = shift[2 * i + 1] = 0;
Daniel Veillardbccae2d2009-06-04 11:22:45 +02004277 fprintf(output, "%s", shift);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00004278 if (particle->children == NULL) {
4279 fprintf(output, "MISSING particle term\n");
4280 return;
4281 }
4282 term = particle->children;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00004283 if (term == NULL) {
4284 fprintf(output, "(NULL)");
4285 } else {
4286 switch (term->type) {
4287 case XML_SCHEMA_TYPE_ELEMENT:
4288 fprintf(output, "ELEM '%s'", xmlSchemaFormatQName(&str,
4289 ((xmlSchemaElementPtr)term)->targetNamespace,
4290 ((xmlSchemaElementPtr)term)->name));
Kasimier T. Buchcikee8e8ae2005-10-17 14:15:37 +00004291 FREE_AND_NULL(str);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00004292 break;
4293 case XML_SCHEMA_TYPE_SEQUENCE:
4294 fprintf(output, "SEQUENCE");
4295 break;
4296 case XML_SCHEMA_TYPE_CHOICE:
4297 fprintf(output, "CHOICE");
4298 break;
4299 case XML_SCHEMA_TYPE_ALL:
4300 fprintf(output, "ALL");
4301 break;
4302 case XML_SCHEMA_TYPE_ANY:
4303 fprintf(output, "ANY");
4304 break;
4305 default:
4306 fprintf(output, "UNKNOWN\n");
4307 return;
4308 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00004309 }
4310 if (particle->minOccurs != 1)
4311 fprintf(output, " min: %d", particle->minOccurs);
4312 if (particle->maxOccurs >= UNBOUNDED)
4313 fprintf(output, " max: unbounded");
4314 else if (particle->maxOccurs != 1)
4315 fprintf(output, " max: %d", particle->maxOccurs);
4316 fprintf(output, "\n");
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00004317 if (term &&
4318 ((term->type == XML_SCHEMA_TYPE_SEQUENCE) ||
4319 (term->type == XML_SCHEMA_TYPE_CHOICE) ||
4320 (term->type == XML_SCHEMA_TYPE_ALL)) &&
4321 (term->children != NULL)) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00004322 xmlSchemaContentModelDump((xmlSchemaParticlePtr) term->children,
4323 output, depth +1);
4324 }
4325 if (particle->next != NULL)
4326 xmlSchemaContentModelDump((xmlSchemaParticlePtr) particle->next,
4327 output, depth);
4328}
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00004329
4330/**
4331 * xmlSchemaAttrUsesDump:
4332 * @uses: attribute uses list
Daniel Veillarddee23482008-04-11 12:58:43 +00004333 * @output: the file output
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00004334 *
4335 * Dumps a list of attribute use components.
4336 */
4337static void
4338xmlSchemaAttrUsesDump(xmlSchemaItemListPtr uses, FILE * output)
4339{
4340 xmlSchemaAttributeUsePtr use;
4341 xmlSchemaAttributeUseProhibPtr prohib;
4342 xmlSchemaQNameRefPtr ref;
4343 const xmlChar *name, *tns;
4344 xmlChar *str = NULL;
4345 int i;
4346
4347 if ((uses == NULL) || (uses->nbItems == 0))
4348 return;
4349
Daniel Veillarddee23482008-04-11 12:58:43 +00004350 fprintf(output, " attributes:\n");
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00004351 for (i = 0; i < uses->nbItems; i++) {
4352 use = uses->items[i];
4353 if (use->type == XML_SCHEMA_EXTRA_ATTR_USE_PROHIB) {
4354 fprintf(output, " [prohibition] ");
4355 prohib = (xmlSchemaAttributeUseProhibPtr) use;
4356 name = prohib->name;
4357 tns = prohib->targetNamespace;
4358 } else if (use->type == XML_SCHEMA_EXTRA_QNAMEREF) {
4359 fprintf(output, " [reference] ");
4360 ref = (xmlSchemaQNameRefPtr) use;
4361 name = ref->name;
4362 tns = ref->targetNamespace;
4363 } else {
4364 fprintf(output, " [use] ");
4365 name = WXS_ATTRUSE_DECL_NAME(use);
4366 tns = WXS_ATTRUSE_DECL_TNS(use);
4367 }
Kasimier T. Buchcikee8e8ae2005-10-17 14:15:37 +00004368 fprintf(output, "'%s'\n",
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00004369 (const char *) xmlSchemaFormatQName(&str, tns, name));
4370 FREE_AND_NULL(str);
4371 }
4372}
4373
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00004374/**
4375 * xmlSchemaTypeDump:
4376 * @output: the file output
4377 * @type: a type structure
4378 *
4379 * Dump a SchemaType structure
4380 */
4381static void
Daniel Veillard4255d502002-04-16 15:50:10 +00004382xmlSchemaTypeDump(xmlSchemaTypePtr type, FILE * output)
4383{
4384 if (type == NULL) {
4385 fprintf(output, "Type: NULL\n");
4386 return;
4387 }
4388 fprintf(output, "Type: ");
4389 if (type->name != NULL)
Kasimier T. Buchcikee8e8ae2005-10-17 14:15:37 +00004390 fprintf(output, "'%s' ", type->name);
Daniel Veillard4255d502002-04-16 15:50:10 +00004391 else
Kasimier T. Buchcikee8e8ae2005-10-17 14:15:37 +00004392 fprintf(output, "(no name) ");
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004393 if (type->targetNamespace != NULL)
Kasimier T. Buchcikee8e8ae2005-10-17 14:15:37 +00004394 fprintf(output, "ns '%s' ", type->targetNamespace);
Daniel Veillard4255d502002-04-16 15:50:10 +00004395 switch (type->type) {
4396 case XML_SCHEMA_TYPE_BASIC:
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004397 fprintf(output, "[basic] ");
Daniel Veillard4255d502002-04-16 15:50:10 +00004398 break;
4399 case XML_SCHEMA_TYPE_SIMPLE:
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004400 fprintf(output, "[simple] ");
Daniel Veillard4255d502002-04-16 15:50:10 +00004401 break;
4402 case XML_SCHEMA_TYPE_COMPLEX:
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004403 fprintf(output, "[complex] ");
Daniel Veillard4255d502002-04-16 15:50:10 +00004404 break;
4405 case XML_SCHEMA_TYPE_SEQUENCE:
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004406 fprintf(output, "[sequence] ");
Daniel Veillard4255d502002-04-16 15:50:10 +00004407 break;
4408 case XML_SCHEMA_TYPE_CHOICE:
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004409 fprintf(output, "[choice] ");
Daniel Veillard4255d502002-04-16 15:50:10 +00004410 break;
4411 case XML_SCHEMA_TYPE_ALL:
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004412 fprintf(output, "[all] ");
Daniel Veillard4255d502002-04-16 15:50:10 +00004413 break;
4414 case XML_SCHEMA_TYPE_UR:
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004415 fprintf(output, "[ur] ");
Daniel Veillard4255d502002-04-16 15:50:10 +00004416 break;
4417 case XML_SCHEMA_TYPE_RESTRICTION:
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004418 fprintf(output, "[restriction] ");
Daniel Veillard4255d502002-04-16 15:50:10 +00004419 break;
4420 case XML_SCHEMA_TYPE_EXTENSION:
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004421 fprintf(output, "[extension] ");
Daniel Veillard4255d502002-04-16 15:50:10 +00004422 break;
4423 default:
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004424 fprintf(output, "[unknown type %d] ", type->type);
Daniel Veillard4255d502002-04-16 15:50:10 +00004425 break;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004426 }
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004427 fprintf(output, "content: ");
Daniel Veillard4255d502002-04-16 15:50:10 +00004428 switch (type->contentType) {
Daniel Veillardd0c9c322003-10-10 00:49:42 +00004429 case XML_SCHEMA_CONTENT_UNKNOWN:
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004430 fprintf(output, "[unknown] ");
Daniel Veillardd0c9c322003-10-10 00:49:42 +00004431 break;
4432 case XML_SCHEMA_CONTENT_EMPTY:
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004433 fprintf(output, "[empty] ");
Daniel Veillardd0c9c322003-10-10 00:49:42 +00004434 break;
4435 case XML_SCHEMA_CONTENT_ELEMENTS:
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004436 fprintf(output, "[element] ");
Daniel Veillardd0c9c322003-10-10 00:49:42 +00004437 break;
4438 case XML_SCHEMA_CONTENT_MIXED:
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004439 fprintf(output, "[mixed] ");
Daniel Veillardd0c9c322003-10-10 00:49:42 +00004440 break;
4441 case XML_SCHEMA_CONTENT_MIXED_OR_ELEMENTS:
Daniel Veillardb7c6ac42004-06-29 22:01:27 +00004442 /* not used. */
Daniel Veillardd0c9c322003-10-10 00:49:42 +00004443 break;
4444 case XML_SCHEMA_CONTENT_BASIC:
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004445 fprintf(output, "[basic] ");
Daniel Veillardd0c9c322003-10-10 00:49:42 +00004446 break;
4447 case XML_SCHEMA_CONTENT_SIMPLE:
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004448 fprintf(output, "[simple] ");
Daniel Veillardd0c9c322003-10-10 00:49:42 +00004449 break;
4450 case XML_SCHEMA_CONTENT_ANY:
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004451 fprintf(output, "[any] ");
Daniel Veillardd0c9c322003-10-10 00:49:42 +00004452 break;
Daniel Veillard4255d502002-04-16 15:50:10 +00004453 }
4454 fprintf(output, "\n");
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004455 if (type->base != NULL) {
Kasimier T. Buchcikee8e8ae2005-10-17 14:15:37 +00004456 fprintf(output, " base type: '%s'", type->base);
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004457 if (type->baseNs != NULL)
Kasimier T. Buchcikee8e8ae2005-10-17 14:15:37 +00004458 fprintf(output, " ns '%s'\n", type->baseNs);
Kasimier T. Buchcikf500aec2005-01-19 16:30:24 +00004459 else
4460 fprintf(output, "\n");
4461 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00004462 if (type->attrUses != NULL)
4463 xmlSchemaAttrUsesDump(type->attrUses, output);
Daniel Veillard4255d502002-04-16 15:50:10 +00004464 if (type->annot != NULL)
4465 xmlSchemaAnnotDump(output, type->annot);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00004466#ifdef DUMP_CONTENT_MODEL
4467 if ((type->type == XML_SCHEMA_TYPE_COMPLEX) &&
4468 (type->subtypes != NULL)) {
4469 xmlSchemaContentModelDump((xmlSchemaParticlePtr) type->subtypes,
4470 output, 1);
Daniel Veillard4255d502002-04-16 15:50:10 +00004471 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00004472#endif
Daniel Veillard4255d502002-04-16 15:50:10 +00004473}
4474
4475/**
4476 * xmlSchemaDump:
4477 * @output: the file output
4478 * @schema: a schema structure
4479 *
4480 * Dump a Schema structure.
4481 */
4482void
4483xmlSchemaDump(FILE * output, xmlSchemaPtr schema)
4484{
Daniel Veillardce682bc2004-11-05 17:22:25 +00004485 if (output == NULL)
4486 return;
Daniel Veillard4255d502002-04-16 15:50:10 +00004487 if (schema == NULL) {
4488 fprintf(output, "Schemas: NULL\n");
4489 return;
4490 }
4491 fprintf(output, "Schemas: ");
4492 if (schema->name != NULL)
4493 fprintf(output, "%s, ", schema->name);
4494 else
4495 fprintf(output, "no name, ");
4496 if (schema->targetNamespace != NULL)
Daniel Veillard580ced82003-03-21 21:22:48 +00004497 fprintf(output, "%s", (const char *) schema->targetNamespace);
Daniel Veillard4255d502002-04-16 15:50:10 +00004498 else
4499 fprintf(output, "no target namespace");
4500 fprintf(output, "\n");
4501 if (schema->annot != NULL)
4502 xmlSchemaAnnotDump(output, schema->annot);
Daniel Veillard4255d502002-04-16 15:50:10 +00004503 xmlHashScan(schema->typeDecl, (xmlHashScanner) xmlSchemaTypeDump,
4504 output);
4505 xmlHashScanFull(schema->elemDecl,
Daniel Veillardd0c9c322003-10-10 00:49:42 +00004506 (xmlHashScannerFull) xmlSchemaElementDump, output);
Daniel Veillard4255d502002-04-16 15:50:10 +00004507}
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00004508
Kasimier T. Buchcik27820272005-10-14 14:33:48 +00004509#ifdef DEBUG_IDC_NODE_TABLE
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00004510/**
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004511 * xmlSchemaDebugDumpIDCTable:
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00004512 * @vctxt: the WXS validation context
4513 *
4514 * Displays the current IDC table for debug purposes.
4515 */
4516static void
4517xmlSchemaDebugDumpIDCTable(FILE * output,
4518 const xmlChar *namespaceName,
4519 const xmlChar *localName,
4520 xmlSchemaPSVIIDCBindingPtr bind)
4521{
Kasimier T. Buchcik27820272005-10-14 14:33:48 +00004522 xmlChar *str = NULL;
4523 const xmlChar *value;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00004524 xmlSchemaPSVIIDCNodePtr tab;
4525 xmlSchemaPSVIIDCKeyPtr key;
4526 int i, j, res;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004527
Kasimier T. Buchcikf39e8d12005-11-30 11:03:24 +00004528 fprintf(output, "IDC: TABLES on '%s'\n",
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004529 xmlSchemaFormatQName(&str, namespaceName, localName));
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00004530 FREE_AND_NULL(str)
4531
4532 if (bind == NULL)
4533 return;
4534 do {
Kasimier T. Buchcikf39e8d12005-11-30 11:03:24 +00004535 fprintf(output, "IDC: BINDING '%s' (%d)\n",
Daniel Veillarddee23482008-04-11 12:58:43 +00004536 xmlSchemaGetComponentQName(&str,
Kasimier T. Buchcikf39e8d12005-11-30 11:03:24 +00004537 bind->definition), bind->nbNodes);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004538 FREE_AND_NULL(str)
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00004539 for (i = 0; i < bind->nbNodes; i++) {
4540 tab = bind->nodeTable[i];
4541 fprintf(output, " ( ");
4542 for (j = 0; j < bind->definition->nbFields; j++) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004543 key = tab->keys[j];
4544 if ((key != NULL) && (key->val != NULL)) {
4545 res = xmlSchemaGetCanonValue(key->val, &value);
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +00004546 if (res >= 0)
Kasimier T. Buchcikf39e8d12005-11-30 11:03:24 +00004547 fprintf(output, "'%s' ", value);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00004548 else
Kasimier T. Buchcik87250a92005-01-28 15:59:53 +00004549 fprintf(output, "CANON-VALUE-FAILED ");
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004550 if (res == 0)
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +00004551 FREE_AND_NULL(value)
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00004552 } else if (key != NULL)
Kasimier T. Buchcik87250a92005-01-28 15:59:53 +00004553 fprintf(output, "(no val), ");
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00004554 else
4555 fprintf(output, "(key missing), ");
4556 }
4557 fprintf(output, ")\n");
4558 }
Kasimier T. Buchcik27820272005-10-14 14:33:48 +00004559 if (bind->dupls && bind->dupls->nbItems) {
Kasimier T. Buchcikf39e8d12005-11-30 11:03:24 +00004560 fprintf(output, "IDC: dupls (%d):\n", bind->dupls->nbItems);
Kasimier T. Buchcik27820272005-10-14 14:33:48 +00004561 for (i = 0; i < bind->dupls->nbItems; i++) {
4562 tab = bind->dupls->items[i];
4563 fprintf(output, " ( ");
4564 for (j = 0; j < bind->definition->nbFields; j++) {
4565 key = tab->keys[j];
4566 if ((key != NULL) && (key->val != NULL)) {
4567 res = xmlSchemaGetCanonValue(key->val, &value);
4568 if (res >= 0)
Kasimier T. Buchcikf39e8d12005-11-30 11:03:24 +00004569 fprintf(output, "'%s' ", value);
Kasimier T. Buchcik27820272005-10-14 14:33:48 +00004570 else
4571 fprintf(output, "CANON-VALUE-FAILED ");
4572 if (res == 0)
4573 FREE_AND_NULL(value)
4574 } else if (key != NULL)
4575 fprintf(output, "(no val), ");
4576 else
4577 fprintf(output, "(key missing), ");
4578 }
4579 fprintf(output, ")\n");
4580 }
4581 }
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00004582 bind = bind->next;
4583 } while (bind != NULL);
4584}
Kasimier T. Buchcikbd2a7d12005-02-16 12:27:25 +00004585#endif /* DEBUG_IDC */
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00004586#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillard4255d502002-04-16 15:50:10 +00004587
4588/************************************************************************
Daniel Veillardbe9c6322003-11-22 20:37:51 +00004589 * *
4590 * Utilities *
4591 * *
4592 ************************************************************************/
Daniel Veillardbe9c6322003-11-22 20:37:51 +00004593
Daniel Veillardc0826a72004-08-10 14:17:33 +00004594/**
4595 * xmlSchemaGetPropNode:
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004596 * @node: the element node
Daniel Veillardc0826a72004-08-10 14:17:33 +00004597 * @name: the name of the attribute
4598 *
4599 * Seeks an attribute with a name of @name in
4600 * no namespace.
4601 *
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004602 * Returns the attribute or NULL if not present.
Daniel Veillardc0826a72004-08-10 14:17:33 +00004603 */
Daniel Veillardb7c6ac42004-06-29 22:01:27 +00004604static xmlAttrPtr
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004605xmlSchemaGetPropNode(xmlNodePtr node, const char *name)
Daniel Veillard01fa6152004-06-29 17:04:39 +00004606{
4607 xmlAttrPtr prop;
4608
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004609 if ((node == NULL) || (name == NULL))
Daniel Veillardc0826a72004-08-10 14:17:33 +00004610 return(NULL);
Daniel Veillard01fa6152004-06-29 17:04:39 +00004611 prop = node->properties;
4612 while (prop != NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004613 if ((prop->ns == NULL) && xmlStrEqual(prop->name, BAD_CAST name))
Daniel Veillardc0826a72004-08-10 14:17:33 +00004614 return(prop);
4615 prop = prop->next;
4616 }
4617 return (NULL);
4618}
4619
4620/**
4621 * xmlSchemaGetPropNodeNs:
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004622 * @node: the element node
Daniel Veillardc0826a72004-08-10 14:17:33 +00004623 * @uri: the uri
4624 * @name: the name of the attribute
4625 *
4626 * Seeks an attribute with a local name of @name and
4627 * a namespace URI of @uri.
4628 *
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004629 * Returns the attribute or NULL if not present.
Daniel Veillardc0826a72004-08-10 14:17:33 +00004630 */
4631static xmlAttrPtr
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004632xmlSchemaGetPropNodeNs(xmlNodePtr node, const char *uri, const char *name)
Daniel Veillardc0826a72004-08-10 14:17:33 +00004633{
4634 xmlAttrPtr prop;
4635
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004636 if ((node == NULL) || (name == NULL))
Daniel Veillarddee23482008-04-11 12:58:43 +00004637 return(NULL);
Daniel Veillardc0826a72004-08-10 14:17:33 +00004638 prop = node->properties;
4639 while (prop != NULL) {
4640 if ((prop->ns != NULL) &&
4641 xmlStrEqual(prop->name, BAD_CAST name) &&
4642 xmlStrEqual(prop->ns->href, BAD_CAST uri))
Daniel Veillard01fa6152004-06-29 17:04:39 +00004643 return(prop);
4644 prop = prop->next;
4645 }
4646 return (NULL);
4647}
4648
4649static const xmlChar *
4650xmlSchemaGetNodeContent(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node)
4651{
4652 xmlChar *val;
4653 const xmlChar *ret;
4654
4655 val = xmlNodeGetContent(node);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004656 if (val == NULL)
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +00004657 val = xmlStrdup((xmlChar *)"");
Daniel Veillard01fa6152004-06-29 17:04:39 +00004658 ret = xmlDictLookup(ctxt->dict, val, -1);
4659 xmlFree(val);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004660 return(ret);
Daniel Veillard01fa6152004-06-29 17:04:39 +00004661}
4662
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00004663static const xmlChar *
4664xmlSchemaGetNodeContentNoDict(xmlNodePtr node)
4665{
4666 return((const xmlChar*) xmlNodeGetContent(node));
4667}
4668
Daniel Veillardbe9c6322003-11-22 20:37:51 +00004669/**
4670 * xmlSchemaGetProp:
4671 * @ctxt: the parser context
4672 * @node: the node
4673 * @name: the property name
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004674 *
Daniel Veillardbe9c6322003-11-22 20:37:51 +00004675 * Read a attribute value and internalize the string
4676 *
4677 * Returns the string or NULL if not present.
4678 */
4679static const xmlChar *
4680xmlSchemaGetProp(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node,
4681 const char *name)
4682{
4683 xmlChar *val;
4684 const xmlChar *ret;
4685
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004686 val = xmlGetNoNsProp(node, BAD_CAST name);
Daniel Veillardbe9c6322003-11-22 20:37:51 +00004687 if (val == NULL)
4688 return(NULL);
4689 ret = xmlDictLookup(ctxt->dict, val, -1);
4690 xmlFree(val);
4691 return(ret);
4692}
4693
Daniel Veillardbe9c6322003-11-22 20:37:51 +00004694/************************************************************************
Daniel Veillard4255d502002-04-16 15:50:10 +00004695 * *
4696 * Parsing functions *
4697 * *
4698 ************************************************************************/
4699
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004700#define WXS_FIND_GLOBAL_ITEM(slot) \
4701 if (xmlStrEqual(nsName, schema->targetNamespace)) { \
4702 ret = xmlHashLookup(schema->slot, name); \
4703 if (ret != NULL) goto exit; \
4704 } \
4705 if (xmlHashSize(schema->schemasImports) > 1) { \
4706 xmlSchemaImportPtr import; \
4707 if (nsName == NULL) \
4708 import = xmlHashLookup(schema->schemasImports, \
4709 XML_SCHEMAS_NO_NAMESPACE); \
4710 else \
4711 import = xmlHashLookup(schema->schemasImports, nsName); \
4712 if (import == NULL) \
4713 goto exit; \
4714 ret = xmlHashLookup(import->schema->slot, name); \
4715 }
4716
Daniel Veillard4255d502002-04-16 15:50:10 +00004717/**
Daniel Veillardbe9c6322003-11-22 20:37:51 +00004718 * xmlSchemaGetElem:
Kasimier T. Buchcikbea23542004-08-25 20:35:45 +00004719 * @schema: the schema context
Daniel Veillardbe9c6322003-11-22 20:37:51 +00004720 * @name: the element name
4721 * @ns: the element namespace
4722 *
Kasimier T. Buchcikbea23542004-08-25 20:35:45 +00004723 * Lookup a global element declaration in the schema.
Daniel Veillardbe9c6322003-11-22 20:37:51 +00004724 *
Kasimier T. Buchcikbea23542004-08-25 20:35:45 +00004725 * Returns the element declaration or NULL if not found.
Daniel Veillardbe9c6322003-11-22 20:37:51 +00004726 */
4727static xmlSchemaElementPtr
4728xmlSchemaGetElem(xmlSchemaPtr schema, const xmlChar * name,
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +00004729 const xmlChar * nsName)
Daniel Veillardbe9c6322003-11-22 20:37:51 +00004730{
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004731 xmlSchemaElementPtr ret = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +00004732
Daniel Veillardbe9c6322003-11-22 20:37:51 +00004733 if ((name == NULL) || (schema == NULL))
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004734 return(NULL);
4735 if (schema != NULL) {
4736 WXS_FIND_GLOBAL_ITEM(elemDecl)
Daniel Veillarddee23482008-04-11 12:58:43 +00004737 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004738exit:
Daniel Veillardbe9c6322003-11-22 20:37:51 +00004739#ifdef DEBUG
4740 if (ret == NULL) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004741 if (nsName == NULL)
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00004742 fprintf(stderr, "Unable to lookup element decl. %s", name);
Daniel Veillardbe9c6322003-11-22 20:37:51 +00004743 else
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00004744 fprintf(stderr, "Unable to lookup element decl. %s:%s", name,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004745 nsName);
Daniel Veillardbe9c6322003-11-22 20:37:51 +00004746 }
4747#endif
4748 return (ret);
4749}
4750
4751/**
Daniel Veillard4255d502002-04-16 15:50:10 +00004752 * xmlSchemaGetType:
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004753 * @schema: the main schema
4754 * @name: the type's name
4755 * nsName: the type's namespace
Daniel Veillard4255d502002-04-16 15:50:10 +00004756 *
4757 * Lookup a type in the schemas or the predefined types
4758 *
Daniel Veillarda84c0b32003-06-02 16:58:46 +00004759 * Returns the group definition or NULL if not found.
Daniel Veillard4255d502002-04-16 15:50:10 +00004760 */
4761static xmlSchemaTypePtr
4762xmlSchemaGetType(xmlSchemaPtr schema, const xmlChar * name,
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +00004763 const xmlChar * nsName)
Daniel Veillardd0c9c322003-10-10 00:49:42 +00004764{
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004765 xmlSchemaTypePtr ret = NULL;
Daniel Veillard4255d502002-04-16 15:50:10 +00004766
4767 if (name == NULL)
Daniel Veillarddee23482008-04-11 12:58:43 +00004768 return (NULL);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004769 /* First try the built-in types. */
Daniel Veillarddee23482008-04-11 12:58:43 +00004770 if ((nsName != NULL) && xmlStrEqual(nsName, xmlSchemaNs)) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004771 ret = xmlSchemaGetPredefinedType(name, nsName);
4772 if (ret != NULL)
4773 goto exit;
4774 /*
4775 * Note that we try the parsed schemas as well here
4776 * since one might have parsed the S4S, which contain more
4777 * than the built-in types.
4778 * TODO: Can we optimize this?
4779 */
4780 }
Daniel Veillard4255d502002-04-16 15:50:10 +00004781 if (schema != NULL) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004782 WXS_FIND_GLOBAL_ITEM(typeDecl)
Daniel Veillarddee23482008-04-11 12:58:43 +00004783 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004784exit:
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00004785
Daniel Veillard4255d502002-04-16 15:50:10 +00004786#ifdef DEBUG
4787 if (ret == NULL) {
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +00004788 if (nsName == NULL)
Daniel Veillardd0c9c322003-10-10 00:49:42 +00004789 fprintf(stderr, "Unable to lookup type %s", name);
4790 else
4791 fprintf(stderr, "Unable to lookup type %s:%s", name,
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +00004792 nsName);
Daniel Veillard4255d502002-04-16 15:50:10 +00004793 }
4794#endif
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004795 return (ret);
Daniel Veillard4255d502002-04-16 15:50:10 +00004796}
4797
Daniel Veillard3646d642004-06-02 19:19:14 +00004798/**
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004799 * xmlSchemaGetAttributeDecl:
4800 * @schema: the context of the schema
Daniel Veillard3646d642004-06-02 19:19:14 +00004801 * @name: the name of the attribute
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004802 * @ns: the target namespace of the attribute
Daniel Veillard3646d642004-06-02 19:19:14 +00004803 *
4804 * Lookup a an attribute in the schema or imported schemas
4805 *
4806 * Returns the attribute declaration or NULL if not found.
4807 */
4808static xmlSchemaAttributePtr
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004809xmlSchemaGetAttributeDecl(xmlSchemaPtr schema, const xmlChar * name,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004810 const xmlChar * nsName)
Daniel Veillard3646d642004-06-02 19:19:14 +00004811{
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004812 xmlSchemaAttributePtr ret = NULL;
Daniel Veillard3646d642004-06-02 19:19:14 +00004813
4814 if ((name == NULL) || (schema == NULL))
4815 return (NULL);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004816 if (schema != NULL) {
4817 WXS_FIND_GLOBAL_ITEM(attrDecl)
Daniel Veillard3646d642004-06-02 19:19:14 +00004818 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004819exit:
Daniel Veillard3646d642004-06-02 19:19:14 +00004820#ifdef DEBUG
4821 if (ret == NULL) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004822 if (nsName == NULL)
Daniel Veillard3646d642004-06-02 19:19:14 +00004823 fprintf(stderr, "Unable to lookup attribute %s", name);
4824 else
4825 fprintf(stderr, "Unable to lookup attribute %s:%s", name,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004826 nsName);
Daniel Veillard3646d642004-06-02 19:19:14 +00004827 }
4828#endif
4829 return (ret);
4830}
4831
4832/**
4833 * xmlSchemaGetAttributeGroup:
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004834 * @schema: the context of the schema
Daniel Veillard3646d642004-06-02 19:19:14 +00004835 * @name: the name of the attribute group
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004836 * @ns: the target namespace of the attribute group
Daniel Veillard3646d642004-06-02 19:19:14 +00004837 *
4838 * Lookup a an attribute group in the schema or imported schemas
4839 *
4840 * Returns the attribute group definition or NULL if not found.
4841 */
4842static xmlSchemaAttributeGroupPtr
4843xmlSchemaGetAttributeGroup(xmlSchemaPtr schema, const xmlChar * name,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004844 const xmlChar * nsName)
Daniel Veillard3646d642004-06-02 19:19:14 +00004845{
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004846 xmlSchemaAttributeGroupPtr ret = NULL;
Daniel Veillard3646d642004-06-02 19:19:14 +00004847
4848 if ((name == NULL) || (schema == NULL))
4849 return (NULL);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004850 if (schema != NULL) {
4851 WXS_FIND_GLOBAL_ITEM(attrgrpDecl)
4852 }
4853exit:
4854 /* TODO:
4855 if ((ret != NULL) && (ret->redef != NULL)) {
4856 * Return the last redefinition. *
4857 ret = ret->redef;
Daniel Veillard3646d642004-06-02 19:19:14 +00004858 }
William M. Brack2f2a6632004-08-20 23:09:47 +00004859 */
Daniel Veillard3646d642004-06-02 19:19:14 +00004860#ifdef DEBUG
4861 if (ret == NULL) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004862 if (nsName == NULL)
Daniel Veillard3646d642004-06-02 19:19:14 +00004863 fprintf(stderr, "Unable to lookup attribute group %s", name);
4864 else
4865 fprintf(stderr, "Unable to lookup attribute group %s:%s", name,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004866 nsName);
Daniel Veillard3646d642004-06-02 19:19:14 +00004867 }
4868#endif
4869 return (ret);
4870}
4871
4872/**
4873 * xmlSchemaGetGroup:
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004874 * @schema: the context of the schema
Daniel Veillard3646d642004-06-02 19:19:14 +00004875 * @name: the name of the group
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004876 * @ns: the target namespace of the group
Daniel Veillard3646d642004-06-02 19:19:14 +00004877 *
4878 * Lookup a group in the schema or imported schemas
4879 *
4880 * Returns the group definition or NULL if not found.
4881 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004882static xmlSchemaModelGroupDefPtr
Daniel Veillard3646d642004-06-02 19:19:14 +00004883xmlSchemaGetGroup(xmlSchemaPtr schema, const xmlChar * name,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004884 const xmlChar * nsName)
Daniel Veillard3646d642004-06-02 19:19:14 +00004885{
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004886 xmlSchemaModelGroupDefPtr ret = NULL;
Daniel Veillard3646d642004-06-02 19:19:14 +00004887
4888 if ((name == NULL) || (schema == NULL))
4889 return (NULL);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004890 if (schema != NULL) {
4891 WXS_FIND_GLOBAL_ITEM(groupDecl)
Daniel Veillard3646d642004-06-02 19:19:14 +00004892 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004893exit:
Daniel Veillarddee23482008-04-11 12:58:43 +00004894
Daniel Veillard3646d642004-06-02 19:19:14 +00004895#ifdef DEBUG
4896 if (ret == NULL) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004897 if (nsName == NULL)
Daniel Veillard3646d642004-06-02 19:19:14 +00004898 fprintf(stderr, "Unable to lookup group %s", name);
4899 else
4900 fprintf(stderr, "Unable to lookup group %s:%s", name,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004901 nsName);
Daniel Veillard3646d642004-06-02 19:19:14 +00004902 }
4903#endif
4904 return (ret);
4905}
4906
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004907static xmlSchemaNotationPtr
4908xmlSchemaGetNotation(xmlSchemaPtr schema,
4909 const xmlChar *name,
4910 const xmlChar *nsName)
4911{
4912 xmlSchemaNotationPtr ret = NULL;
4913
4914 if ((name == NULL) || (schema == NULL))
4915 return (NULL);
4916 if (schema != NULL) {
4917 WXS_FIND_GLOBAL_ITEM(notaDecl)
4918 }
4919exit:
4920 return (ret);
4921}
4922
4923static xmlSchemaIDCPtr
4924xmlSchemaGetIDC(xmlSchemaPtr schema,
4925 const xmlChar *name,
4926 const xmlChar *nsName)
4927{
4928 xmlSchemaIDCPtr ret = NULL;
4929
4930 if ((name == NULL) || (schema == NULL))
4931 return (NULL);
4932 if (schema != NULL) {
4933 WXS_FIND_GLOBAL_ITEM(idcDef)
4934 }
4935exit:
4936 return (ret);
4937}
4938
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00004939/**
4940 * xmlSchemaGetNamedComponent:
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004941 * @schema: the schema
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00004942 * @name: the name of the group
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004943 * @ns: the target namespace of the group
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00004944 *
4945 * Lookup a group in the schema or imported schemas
4946 *
4947 * Returns the group definition or NULL if not found.
4948 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004949static xmlSchemaBasicItemPtr
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00004950xmlSchemaGetNamedComponent(xmlSchemaPtr schema,
4951 xmlSchemaTypeType itemType,
4952 const xmlChar *name,
4953 const xmlChar *targetNs)
4954{
4955 switch (itemType) {
4956 case XML_SCHEMA_TYPE_GROUP:
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004957 return ((xmlSchemaBasicItemPtr) xmlSchemaGetGroup(schema,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00004958 name, targetNs));
4959 case XML_SCHEMA_TYPE_ELEMENT:
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004960 return ((xmlSchemaBasicItemPtr) xmlSchemaGetElem(schema,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00004961 name, targetNs));
4962 default:
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00004963 TODO
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00004964 return (NULL);
4965 }
4966}
4967
Daniel Veillard4255d502002-04-16 15:50:10 +00004968/************************************************************************
4969 * *
4970 * Parsing functions *
4971 * *
4972 ************************************************************************/
4973
4974#define IS_BLANK_NODE(n) \
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004975 (((n)->type == XML_TEXT_NODE) && (xmlSchemaIsBlank((n)->content, -1)))
Daniel Veillard4255d502002-04-16 15:50:10 +00004976
4977/**
4978 * xmlSchemaIsBlank:
4979 * @str: a string
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004980 * @len: the length of the string or -1
Daniel Veillard4255d502002-04-16 15:50:10 +00004981 *
4982 * Check if a string is ignorable
4983 *
4984 * Returns 1 if the string is NULL or made of blanks chars, 0 otherwise
4985 */
4986static int
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004987xmlSchemaIsBlank(xmlChar * str, int len)
Daniel Veillardd0c9c322003-10-10 00:49:42 +00004988{
Daniel Veillard4255d502002-04-16 15:50:10 +00004989 if (str == NULL)
Daniel Veillardd0c9c322003-10-10 00:49:42 +00004990 return (1);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00004991 if (len < 0) {
4992 while (*str != 0) {
4993 if (!(IS_BLANK_CH(*str)))
4994 return (0);
4995 str++;
4996 }
4997 } else while ((*str != 0) && (len != 0)) {
4998 if (!(IS_BLANK_CH(*str)))
4999 return (0);
5000 str++;
5001 len--;
Daniel Veillard4255d502002-04-16 15:50:10 +00005002 }
Daniel Veillarddee23482008-04-11 12:58:43 +00005003
Daniel Veillardd0c9c322003-10-10 00:49:42 +00005004 return (1);
Daniel Veillard4255d502002-04-16 15:50:10 +00005005}
5006
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005007#define WXS_COMP_NAME(c, t) ((t) (c))->name
5008#define WXS_COMP_TNS(c, t) ((t) (c))->targetNamespace
5009/*
5010* xmlSchemaFindRedefCompInGraph:
5011* ATTENTION TODO: This uses pointer comp. for strings.
5012*/
5013static xmlSchemaBasicItemPtr
5014xmlSchemaFindRedefCompInGraph(xmlSchemaBucketPtr bucket,
5015 xmlSchemaTypeType type,
5016 const xmlChar *name,
5017 const xmlChar *nsName)
5018{
5019 xmlSchemaBasicItemPtr ret;
5020 int i;
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +00005021
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005022 if ((bucket == NULL) || (name == NULL))
5023 return(NULL);
5024 if ((bucket->globals == NULL) ||
5025 (bucket->globals->nbItems == 0))
5026 goto subschemas;
5027 /*
5028 * Search in global components.
5029 */
5030 for (i = 0; i < bucket->globals->nbItems; i++) {
5031 ret = bucket->globals->items[i];
5032 if (ret->type == type) {
5033 switch (type) {
5034 case XML_SCHEMA_TYPE_COMPLEX:
5035 case XML_SCHEMA_TYPE_SIMPLE:
5036 if ((WXS_COMP_NAME(ret, xmlSchemaTypePtr) == name) &&
5037 (WXS_COMP_TNS(ret, xmlSchemaTypePtr) ==
5038 nsName))
5039 {
5040 return(ret);
5041 }
5042 break;
5043 case XML_SCHEMA_TYPE_GROUP:
5044 if ((WXS_COMP_NAME(ret,
5045 xmlSchemaModelGroupDefPtr) == name) &&
5046 (WXS_COMP_TNS(ret,
5047 xmlSchemaModelGroupDefPtr) == nsName))
5048 {
5049 return(ret);
5050 }
5051 break;
5052 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
5053 if ((WXS_COMP_NAME(ret,
5054 xmlSchemaAttributeGroupPtr) == name) &&
5055 (WXS_COMP_TNS(ret,
5056 xmlSchemaAttributeGroupPtr) == nsName))
5057 {
5058 return(ret);
5059 }
Kasimier T. Buchcik5d2998b2005-11-22 17:36:01 +00005060 break;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005061 default:
5062 /* Should not be hit. */
5063 return(NULL);
Daniel Veillarddee23482008-04-11 12:58:43 +00005064 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005065 }
5066 }
5067subschemas:
5068 /*
5069 * Process imported/included schemas.
5070 */
5071 if (bucket->relations != NULL) {
5072 xmlSchemaSchemaRelationPtr rel = bucket->relations;
5073
5074 /*
5075 * TODO: Marking the bucket will not avoid multiple searches
5076 * in the same schema, but avoids at least circularity.
5077 */
5078 bucket->flags |= XML_SCHEMA_BUCKET_MARKED;
5079 do {
5080 if ((rel->bucket != NULL) &&
5081 ((rel->bucket->flags & XML_SCHEMA_BUCKET_MARKED) == 0)) {
5082 ret = xmlSchemaFindRedefCompInGraph(rel->bucket,
5083 type, name, nsName);
5084 if (ret != NULL)
5085 return(ret);
5086 }
5087 rel = rel->next;
5088 } while (rel != NULL);
5089 bucket->flags ^= XML_SCHEMA_BUCKET_MARKED;
5090 }
5091 return(NULL);
5092}
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +00005093
5094/**
Daniel Veillard4255d502002-04-16 15:50:10 +00005095 * xmlSchemaAddNotation:
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +00005096 * @ctxt: a schema parser context
Daniel Veillard4255d502002-04-16 15:50:10 +00005097 * @schema: the schema being built
5098 * @name: the item name
5099 *
Daniel Veillardc0826a72004-08-10 14:17:33 +00005100 * Add an XML schema annotation declaration
Daniel Veillard4255d502002-04-16 15:50:10 +00005101 * *WARNING* this interface is highly subject to change
5102 *
5103 * Returns the new struture or NULL in case of error
5104 */
5105static xmlSchemaNotationPtr
5106xmlSchemaAddNotation(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005107 const xmlChar *name, const xmlChar *nsName,
5108 xmlNodePtr node ATTRIBUTE_UNUSED)
Daniel Veillard4255d502002-04-16 15:50:10 +00005109{
5110 xmlSchemaNotationPtr ret = NULL;
Daniel Veillard4255d502002-04-16 15:50:10 +00005111
5112 if ((ctxt == NULL) || (schema == NULL) || (name == NULL))
5113 return (NULL);
5114
Daniel Veillard4255d502002-04-16 15:50:10 +00005115 ret = (xmlSchemaNotationPtr) xmlMalloc(sizeof(xmlSchemaNotation));
5116 if (ret == NULL) {
Daniel Veillardd0c9c322003-10-10 00:49:42 +00005117 xmlSchemaPErrMemory(ctxt, "add annotation", NULL);
Daniel Veillard4255d502002-04-16 15:50:10 +00005118 return (NULL);
5119 }
5120 memset(ret, 0, sizeof(xmlSchemaNotation));
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005121 ret->type = XML_SCHEMA_TYPE_NOTATION;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005122 ret->name = name;
5123 ret->targetNamespace = nsName;
5124 /* TODO: do we need the node to be set?
5125 * ret->node = node;*/
5126 WXS_ADD_GLOBAL(ctxt, ret);
Daniel Veillard4255d502002-04-16 15:50:10 +00005127 return (ret);
5128}
5129
Daniel Veillard4255d502002-04-16 15:50:10 +00005130/**
5131 * xmlSchemaAddAttribute:
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +00005132 * @ctxt: a schema parser context
Daniel Veillard4255d502002-04-16 15:50:10 +00005133 * @schema: the schema being built
5134 * @name: the item name
Daniel Veillardbe9c6322003-11-22 20:37:51 +00005135 * @namespace: the namespace
Daniel Veillard4255d502002-04-16 15:50:10 +00005136 *
5137 * Add an XML schema Attrribute declaration
5138 * *WARNING* this interface is highly subject to change
5139 *
5140 * Returns the new struture or NULL in case of error
5141 */
5142static xmlSchemaAttributePtr
5143xmlSchemaAddAttribute(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005144 const xmlChar * name, const xmlChar * nsName,
Kasimier T. Buchcik87250a92005-01-28 15:59:53 +00005145 xmlNodePtr node, int topLevel)
Daniel Veillard4255d502002-04-16 15:50:10 +00005146{
5147 xmlSchemaAttributePtr ret = NULL;
Daniel Veillard4255d502002-04-16 15:50:10 +00005148
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005149 if ((ctxt == NULL) || (schema == NULL))
Daniel Veillard4255d502002-04-16 15:50:10 +00005150 return (NULL);
5151
5152 ret = (xmlSchemaAttributePtr) xmlMalloc(sizeof(xmlSchemaAttribute));
5153 if (ret == NULL) {
Daniel Veillardd0c9c322003-10-10 00:49:42 +00005154 xmlSchemaPErrMemory(ctxt, "allocating attribute", NULL);
Daniel Veillard4255d502002-04-16 15:50:10 +00005155 return (NULL);
5156 }
5157 memset(ret, 0, sizeof(xmlSchemaAttribute));
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005158 ret->type = XML_SCHEMA_TYPE_ATTRIBUTE;
5159 ret->node = node;
5160 ret->name = name;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005161 ret->targetNamespace = nsName;
5162
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005163 if (topLevel)
5164 WXS_ADD_GLOBAL(ctxt, ret);
5165 else
5166 WXS_ADD_LOCAL(ctxt, ret);
5167 WXS_ADD_PENDING(ctxt, ret);
Daniel Veillard4255d502002-04-16 15:50:10 +00005168 return (ret);
5169}
5170
5171/**
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005172 * xmlSchemaAddAttributeUse:
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +00005173 * @ctxt: a schema parser context
Daniel Veillard4255d502002-04-16 15:50:10 +00005174 * @schema: the schema being built
5175 * @name: the item name
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005176 * @namespace: the namespace
Daniel Veillard4255d502002-04-16 15:50:10 +00005177 *
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005178 * Add an XML schema Attrribute declaration
5179 * *WARNING* this interface is highly subject to change
5180 *
5181 * Returns the new struture or NULL in case of error
5182 */
5183static xmlSchemaAttributeUsePtr
5184xmlSchemaAddAttributeUse(xmlSchemaParserCtxtPtr pctxt,
5185 xmlNodePtr node)
5186{
5187 xmlSchemaAttributeUsePtr ret = NULL;
5188
5189 if (pctxt == NULL)
5190 return (NULL);
5191
5192 ret = (xmlSchemaAttributeUsePtr) xmlMalloc(sizeof(xmlSchemaAttributeUse));
5193 if (ret == NULL) {
5194 xmlSchemaPErrMemory(pctxt, "allocating attribute", NULL);
5195 return (NULL);
5196 }
5197 memset(ret, 0, sizeof(xmlSchemaAttributeUse));
5198 ret->type = XML_SCHEMA_TYPE_ATTRIBUTE_USE;
5199 ret->node = node;
5200
5201 WXS_ADD_LOCAL(pctxt, ret);
5202 return (ret);
5203}
5204
5205/*
5206* xmlSchemaAddRedef:
5207*
5208* Adds a redefinition information. This is used at a later stage to:
5209* resolve references to the redefined components and to check constraints.
5210*/
5211static xmlSchemaRedefPtr
Daniel Veillarddee23482008-04-11 12:58:43 +00005212xmlSchemaAddRedef(xmlSchemaParserCtxtPtr pctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005213 xmlSchemaBucketPtr targetBucket,
5214 void *item,
5215 const xmlChar *refName,
5216 const xmlChar *refTargetNs)
5217{
5218 xmlSchemaRedefPtr ret;
5219
5220 ret = (xmlSchemaRedefPtr)
5221 xmlMalloc(sizeof(xmlSchemaRedef));
5222 if (ret == NULL) {
5223 xmlSchemaPErrMemory(pctxt,
5224 "allocating redefinition info", NULL);
5225 return (NULL);
5226 }
5227 memset(ret, 0, sizeof(xmlSchemaRedef));
5228 ret->item = item;
5229 ret->targetBucket = targetBucket;
5230 ret->refName = refName;
5231 ret->refTargetNs = refTargetNs;
5232 if (WXS_CONSTRUCTOR(pctxt)->redefs == NULL)
5233 WXS_CONSTRUCTOR(pctxt)->redefs = ret;
5234 else
5235 WXS_CONSTRUCTOR(pctxt)->lastRedef->next = ret;
5236 WXS_CONSTRUCTOR(pctxt)->lastRedef = ret;
5237
5238 return (ret);
5239}
5240
5241/**
5242 * xmlSchemaAddAttributeGroupDefinition:
5243 * @ctxt: a schema parser context
5244 * @schema: the schema being built
5245 * @name: the item name
5246 * @nsName: the target namespace
5247 * @node: the corresponding node
5248 *
5249 * Add an XML schema Attrribute Group definition.
Daniel Veillard4255d502002-04-16 15:50:10 +00005250 *
5251 * Returns the new struture or NULL in case of error
5252 */
5253static xmlSchemaAttributeGroupPtr
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005254xmlSchemaAddAttributeGroupDefinition(xmlSchemaParserCtxtPtr pctxt,
5255 xmlSchemaPtr schema ATTRIBUTE_UNUSED,
5256 const xmlChar *name,
5257 const xmlChar *nsName,
5258 xmlNodePtr node)
Daniel Veillard4255d502002-04-16 15:50:10 +00005259{
5260 xmlSchemaAttributeGroupPtr ret = NULL;
Daniel Veillard4255d502002-04-16 15:50:10 +00005261
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005262 if ((pctxt == NULL) || (name == NULL))
Daniel Veillard4255d502002-04-16 15:50:10 +00005263 return (NULL);
5264
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005265 ret = (xmlSchemaAttributeGroupPtr)
Daniel Veillardd0c9c322003-10-10 00:49:42 +00005266 xmlMalloc(sizeof(xmlSchemaAttributeGroup));
Daniel Veillard4255d502002-04-16 15:50:10 +00005267 if (ret == NULL) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005268 xmlSchemaPErrMemory(pctxt, "allocating attribute group", NULL);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005269 return (NULL);
Daniel Veillard4255d502002-04-16 15:50:10 +00005270 }
5271 memset(ret, 0, sizeof(xmlSchemaAttributeGroup));
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005272 ret->type = XML_SCHEMA_TYPE_ATTRIBUTEGROUP;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005273 ret->name = name;
5274 ret->targetNamespace = nsName;
Daniel Veillarddee23482008-04-11 12:58:43 +00005275 ret->node = node;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005276
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005277 /* TODO: Remove the flag. */
5278 ret->flags |= XML_SCHEMAS_ATTRGROUP_GLOBAL;
5279 if (pctxt->isRedefine) {
5280 pctxt->redef = xmlSchemaAddRedef(pctxt, pctxt->redefined,
5281 ret, name, nsName);
5282 if (pctxt->redef == NULL) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005283 xmlFree(ret);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005284 return(NULL);
Daniel Veillarddee23482008-04-11 12:58:43 +00005285 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005286 pctxt->redefCounter = 0;
5287 }
5288 WXS_ADD_GLOBAL(pctxt, ret);
5289 WXS_ADD_PENDING(pctxt, ret);
Daniel Veillard4255d502002-04-16 15:50:10 +00005290 return (ret);
5291}
5292
5293/**
5294 * xmlSchemaAddElement:
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +00005295 * @ctxt: a schema parser context
Daniel Veillard4255d502002-04-16 15:50:10 +00005296 * @schema: the schema being built
5297 * @name: the type name
5298 * @namespace: the type namespace
5299 *
5300 * Add an XML schema Element declaration
5301 * *WARNING* this interface is highly subject to change
5302 *
5303 * Returns the new struture or NULL in case of error
5304 */
5305static xmlSchemaElementPtr
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005306xmlSchemaAddElement(xmlSchemaParserCtxtPtr ctxt,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005307 const xmlChar * name, const xmlChar * nsName,
William M. Brack2f2a6632004-08-20 23:09:47 +00005308 xmlNodePtr node, int topLevel)
Daniel Veillard4255d502002-04-16 15:50:10 +00005309{
5310 xmlSchemaElementPtr ret = NULL;
Daniel Veillard4255d502002-04-16 15:50:10 +00005311
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005312 if ((ctxt == NULL) || (name == NULL))
Daniel Veillard4255d502002-04-16 15:50:10 +00005313 return (NULL);
5314
Daniel Veillard4255d502002-04-16 15:50:10 +00005315 ret = (xmlSchemaElementPtr) xmlMalloc(sizeof(xmlSchemaElement));
5316 if (ret == NULL) {
Daniel Veillardd0c9c322003-10-10 00:49:42 +00005317 xmlSchemaPErrMemory(ctxt, "allocating element", NULL);
Daniel Veillard4255d502002-04-16 15:50:10 +00005318 return (NULL);
5319 }
5320 memset(ret, 0, sizeof(xmlSchemaElement));
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005321 ret->type = XML_SCHEMA_TYPE_ELEMENT;
5322 ret->name = name;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005323 ret->targetNamespace = nsName;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005324 ret->node = node;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005325
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005326 if (topLevel)
5327 WXS_ADD_GLOBAL(ctxt, ret);
5328 else
5329 WXS_ADD_LOCAL(ctxt, ret);
5330 WXS_ADD_PENDING(ctxt, ret);
Daniel Veillard4255d502002-04-16 15:50:10 +00005331 return (ret);
5332}
5333
5334/**
5335 * xmlSchemaAddType:
Daniel Veillard01fa6152004-06-29 17:04:39 +00005336 * @ctxt: a schema parser context
Daniel Veillard4255d502002-04-16 15:50:10 +00005337 * @schema: the schema being built
5338 * @name: the item name
Daniel Veillardbe9c6322003-11-22 20:37:51 +00005339 * @namespace: the namespace
Daniel Veillard4255d502002-04-16 15:50:10 +00005340 *
Daniel Veillard01fa6152004-06-29 17:04:39 +00005341 * Add an XML schema item
Daniel Veillard4255d502002-04-16 15:50:10 +00005342 * *WARNING* this interface is highly subject to change
5343 *
5344 * Returns the new struture or NULL in case of error
5345 */
5346static xmlSchemaTypePtr
5347xmlSchemaAddType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005348 xmlSchemaTypeType type,
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +00005349 const xmlChar * name, const xmlChar * nsName,
5350 xmlNodePtr node, int topLevel)
Daniel Veillard4255d502002-04-16 15:50:10 +00005351{
5352 xmlSchemaTypePtr ret = NULL;
Daniel Veillard4255d502002-04-16 15:50:10 +00005353
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005354 if ((ctxt == NULL) || (schema == NULL))
Daniel Veillard4255d502002-04-16 15:50:10 +00005355 return (NULL);
5356
5357 ret = (xmlSchemaTypePtr) xmlMalloc(sizeof(xmlSchemaType));
5358 if (ret == NULL) {
Daniel Veillardd0c9c322003-10-10 00:49:42 +00005359 xmlSchemaPErrMemory(ctxt, "allocating type", NULL);
Daniel Veillard4255d502002-04-16 15:50:10 +00005360 return (NULL);
5361 }
5362 memset(ret, 0, sizeof(xmlSchemaType));
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005363 ret->type = type;
5364 ret->name = name;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005365 ret->targetNamespace = nsName;
5366 ret->node = node;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005367 if (topLevel) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005368 if (ctxt->isRedefine) {
5369 ctxt->redef = xmlSchemaAddRedef(ctxt, ctxt->redefined,
5370 ret, name, nsName);
5371 if (ctxt->redef == NULL) {
5372 xmlFree(ret);
5373 return(NULL);
Daniel Veillarddee23482008-04-11 12:58:43 +00005374 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005375 ctxt->redefCounter = 0;
5376 }
5377 WXS_ADD_GLOBAL(ctxt, ret);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005378 } else
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005379 WXS_ADD_LOCAL(ctxt, ret);
Daniel Veillarddee23482008-04-11 12:58:43 +00005380 WXS_ADD_PENDING(ctxt, ret);
Daniel Veillarda84c0b32003-06-02 16:58:46 +00005381 return (ret);
5382}
5383
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00005384static xmlSchemaQNameRefPtr
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005385xmlSchemaNewQNameRef(xmlSchemaParserCtxtPtr pctxt,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00005386 xmlSchemaTypeType refType,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00005387 const xmlChar *refName,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00005388 const xmlChar *refNs)
5389{
5390 xmlSchemaQNameRefPtr ret;
5391
5392 ret = (xmlSchemaQNameRefPtr)
5393 xmlMalloc(sizeof(xmlSchemaQNameRef));
5394 if (ret == NULL) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005395 xmlSchemaPErrMemory(pctxt,
5396 "allocating QName reference item", NULL);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00005397 return (NULL);
5398 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005399 ret->node = NULL;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00005400 ret->type = XML_SCHEMA_EXTRA_QNAMEREF;
5401 ret->name = refName;
5402 ret->targetNamespace = refNs;
5403 ret->item = NULL;
5404 ret->itemType = refType;
5405 /*
5406 * Store the reference item in the schema.
5407 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005408 WXS_ADD_LOCAL(pctxt, ret);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00005409 return (ret);
5410}
5411
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005412static xmlSchemaAttributeUseProhibPtr
5413xmlSchemaAddAttributeUseProhib(xmlSchemaParserCtxtPtr pctxt)
5414{
5415 xmlSchemaAttributeUseProhibPtr ret;
5416
5417 ret = (xmlSchemaAttributeUseProhibPtr)
5418 xmlMalloc(sizeof(xmlSchemaAttributeUseProhib));
5419 if (ret == NULL) {
5420 xmlSchemaPErrMemory(pctxt,
5421 "allocating attribute use prohibition", NULL);
5422 return (NULL);
5423 }
5424 memset(ret, 0, sizeof(xmlSchemaAttributeUseProhib));
5425 ret->type = XML_SCHEMA_EXTRA_ATTR_USE_PROHIB;
5426 WXS_ADD_LOCAL(pctxt, ret);
5427 return (ret);
5428}
5429
5430
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00005431/**
5432 * xmlSchemaAddModelGroup:
5433 * @ctxt: a schema parser context
5434 * @schema: the schema being built
5435 * @type: the "compositor" type of the model group
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00005436 * @node: the node in the schema doc
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00005437 *
5438 * Adds a schema model group
5439 * *WARNING* this interface is highly subject to change
5440 *
5441 * Returns the new struture or NULL in case of error
5442 */
5443static xmlSchemaModelGroupPtr
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005444xmlSchemaAddModelGroup(xmlSchemaParserCtxtPtr ctxt,
5445 xmlSchemaPtr schema,
5446 xmlSchemaTypeType type,
5447 xmlNodePtr node)
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00005448{
5449 xmlSchemaModelGroupPtr ret = NULL;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00005450
5451 if ((ctxt == NULL) || (schema == NULL))
5452 return (NULL);
5453
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00005454 ret = (xmlSchemaModelGroupPtr)
5455 xmlMalloc(sizeof(xmlSchemaModelGroup));
5456 if (ret == NULL) {
5457 xmlSchemaPErrMemory(ctxt, "allocating model group component",
5458 NULL);
5459 return (NULL);
5460 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005461 memset(ret, 0, sizeof(xmlSchemaModelGroup));
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00005462 ret->type = type;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00005463 ret->node = node;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005464 WXS_ADD_LOCAL(ctxt, ret);
5465 if ((type == XML_SCHEMA_TYPE_SEQUENCE) ||
5466 (type == XML_SCHEMA_TYPE_CHOICE))
5467 WXS_ADD_PENDING(ctxt, ret);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00005468 return (ret);
5469}
5470
5471
5472/**
5473 * xmlSchemaAddParticle:
5474 * @ctxt: a schema parser context
5475 * @schema: the schema being built
5476 * @node: the corresponding node in the schema doc
5477 * @min: the minOccurs
5478 * @max: the maxOccurs
5479 *
5480 * Adds an XML schema particle component.
5481 * *WARNING* this interface is highly subject to change
5482 *
5483 * Returns the new struture or NULL in case of error
5484 */
5485static xmlSchemaParticlePtr
Kasimier T. Buchcik4c0aa162006-02-20 14:47:08 +00005486xmlSchemaAddParticle(xmlSchemaParserCtxtPtr ctxt,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00005487 xmlNodePtr node, int min, int max)
5488{
5489 xmlSchemaParticlePtr ret = NULL;
Kasimier T. Buchcik4c0aa162006-02-20 14:47:08 +00005490 if (ctxt == NULL)
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00005491 return (NULL);
5492
5493#ifdef DEBUG
5494 fprintf(stderr, "Adding particle component\n");
5495#endif
5496 ret = (xmlSchemaParticlePtr)
5497 xmlMalloc(sizeof(xmlSchemaParticle));
5498 if (ret == NULL) {
5499 xmlSchemaPErrMemory(ctxt, "allocating particle component",
5500 NULL);
5501 return (NULL);
5502 }
5503 ret->type = XML_SCHEMA_TYPE_PARTICLE;
5504 ret->annot = NULL;
5505 ret->node = node;
5506 ret->minOccurs = min;
5507 ret->maxOccurs = max;
5508 ret->next = NULL;
5509 ret->children = NULL;
5510
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005511 WXS_ADD_LOCAL(ctxt, ret);
Daniel Veillarddee23482008-04-11 12:58:43 +00005512 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005513 * Note that addition to pending components will be done locally
5514 * to the specific parsing function, since the most particles
5515 * need not to be fixed up (i.e. the reference to be resolved).
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005516 * REMOVED: WXS_ADD_PENDING(ctxt, ret);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005517 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00005518 return (ret);
5519}
5520
Daniel Veillarda84c0b32003-06-02 16:58:46 +00005521/**
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005522 * xmlSchemaAddModelGroupDefinition:
Daniel Veillarda84c0b32003-06-02 16:58:46 +00005523 * @ctxt: a schema validation context
5524 * @schema: the schema being built
5525 * @name: the group name
5526 *
5527 * Add an XML schema Group definition
5528 *
5529 * Returns the new struture or NULL in case of error
5530 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00005531static xmlSchemaModelGroupDefPtr
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005532xmlSchemaAddModelGroupDefinition(xmlSchemaParserCtxtPtr ctxt,
5533 xmlSchemaPtr schema,
5534 const xmlChar *name,
5535 const xmlChar *nsName,
5536 xmlNodePtr node)
Daniel Veillarda84c0b32003-06-02 16:58:46 +00005537{
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00005538 xmlSchemaModelGroupDefPtr ret = NULL;
Daniel Veillarda84c0b32003-06-02 16:58:46 +00005539
5540 if ((ctxt == NULL) || (schema == NULL) || (name == NULL))
5541 return (NULL);
5542
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005543 ret = (xmlSchemaModelGroupDefPtr)
5544 xmlMalloc(sizeof(xmlSchemaModelGroupDef));
Daniel Veillarda84c0b32003-06-02 16:58:46 +00005545 if (ret == NULL) {
Daniel Veillardd0c9c322003-10-10 00:49:42 +00005546 xmlSchemaPErrMemory(ctxt, "adding group", NULL);
Daniel Veillarda84c0b32003-06-02 16:58:46 +00005547 return (NULL);
5548 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00005549 memset(ret, 0, sizeof(xmlSchemaModelGroupDef));
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005550 ret->name = name;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00005551 ret->type = XML_SCHEMA_TYPE_GROUP;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00005552 ret->node = node;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005553 ret->targetNamespace = nsName;
5554
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005555 if (ctxt->isRedefine) {
5556 ctxt->redef = xmlSchemaAddRedef(ctxt, ctxt->redefined,
5557 ret, name, nsName);
5558 if (ctxt->redef == NULL) {
5559 xmlFree(ret);
5560 return(NULL);
Daniel Veillarddee23482008-04-11 12:58:43 +00005561 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005562 ctxt->redefCounter = 0;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00005563 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005564 WXS_ADD_GLOBAL(ctxt, ret);
5565 WXS_ADD_PENDING(ctxt, ret);
Daniel Veillard4255d502002-04-16 15:50:10 +00005566 return (ret);
5567}
5568
Daniel Veillard3646d642004-06-02 19:19:14 +00005569/**
5570 * xmlSchemaNewWildcardNs:
5571 * @ctxt: a schema validation context
5572 *
5573 * Creates a new wildcard namespace constraint.
5574 *
5575 * Returns the new struture or NULL in case of error
5576 */
5577static xmlSchemaWildcardNsPtr
5578xmlSchemaNewWildcardNsConstraint(xmlSchemaParserCtxtPtr ctxt)
5579{
5580 xmlSchemaWildcardNsPtr ret;
5581
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00005582 ret = (xmlSchemaWildcardNsPtr)
Daniel Veillard3646d642004-06-02 19:19:14 +00005583 xmlMalloc(sizeof(xmlSchemaWildcardNs));
5584 if (ret == NULL) {
5585 xmlSchemaPErrMemory(ctxt, "creating wildcard namespace constraint", NULL);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00005586 return (NULL);
Daniel Veillard3646d642004-06-02 19:19:14 +00005587 }
5588 ret->value = NULL;
5589 ret->next = NULL;
5590 return (ret);
5591}
5592
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005593static xmlSchemaIDCPtr
5594xmlSchemaAddIDC(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
5595 const xmlChar *name, const xmlChar *nsName,
5596 int category, xmlNodePtr node)
5597{
Daniel Veillarddee23482008-04-11 12:58:43 +00005598 xmlSchemaIDCPtr ret = NULL;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005599
5600 if ((ctxt == NULL) || (schema == NULL) || (name == NULL))
5601 return (NULL);
5602
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005603 ret = (xmlSchemaIDCPtr) xmlMalloc(sizeof(xmlSchemaIDC));
5604 if (ret == NULL) {
5605 xmlSchemaPErrMemory(ctxt,
5606 "allocating an identity-constraint definition", NULL);
5607 return (NULL);
5608 }
5609 memset(ret, 0, sizeof(xmlSchemaIDC));
5610 /* The target namespace of the parent element declaration. */
5611 ret->targetNamespace = nsName;
5612 ret->name = name;
5613 ret->type = category;
Daniel Veillarddee23482008-04-11 12:58:43 +00005614 ret->node = node;
5615
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005616 WXS_ADD_GLOBAL(ctxt, ret);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005617 /*
5618 * Only keyrefs need to be fixup up.
5619 */
5620 if (category == XML_SCHEMA_TYPE_IDC_KEYREF)
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005621 WXS_ADD_PENDING(ctxt, ret);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005622 return (ret);
5623}
5624
Daniel Veillard3646d642004-06-02 19:19:14 +00005625/**
5626 * xmlSchemaAddWildcard:
5627 * @ctxt: a schema validation context
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00005628 * @schema: a schema
5629 *
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00005630 * Adds a wildcard.
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00005631 * It corresponds to a xsd:anyAttribute and xsd:any.
Daniel Veillard3646d642004-06-02 19:19:14 +00005632 *
5633 * Returns the new struture or NULL in case of error
5634 */
5635static xmlSchemaWildcardPtr
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00005636xmlSchemaAddWildcard(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
5637 xmlSchemaTypeType type, xmlNodePtr node)
Daniel Veillard3646d642004-06-02 19:19:14 +00005638{
5639 xmlSchemaWildcardPtr ret = NULL;
5640
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00005641 if ((ctxt == NULL) || (schema == NULL))
Daniel Veillard3646d642004-06-02 19:19:14 +00005642 return (NULL);
5643
5644 ret = (xmlSchemaWildcardPtr) xmlMalloc(sizeof(xmlSchemaWildcard));
5645 if (ret == NULL) {
5646 xmlSchemaPErrMemory(ctxt, "adding wildcard", NULL);
5647 return (NULL);
5648 }
5649 memset(ret, 0, sizeof(xmlSchemaWildcard));
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00005650 ret->type = type;
Daniel Veillarddee23482008-04-11 12:58:43 +00005651 ret->node = node;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005652 WXS_ADD_LOCAL(ctxt, ret);
Daniel Veillard3646d642004-06-02 19:19:14 +00005653 return (ret);
5654}
5655
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005656static void
5657xmlSchemaSubstGroupFree(xmlSchemaSubstGroupPtr group)
5658{
5659 if (group == NULL)
5660 return;
5661 if (group->members != NULL)
5662 xmlSchemaItemListFree(group->members);
5663 xmlFree(group);
5664}
5665
5666static xmlSchemaSubstGroupPtr
5667xmlSchemaSubstGroupAdd(xmlSchemaParserCtxtPtr pctxt,
5668 xmlSchemaElementPtr head)
5669{
5670 xmlSchemaSubstGroupPtr ret;
5671
5672 /* Init subst group hash. */
5673 if (WXS_SUBST_GROUPS(pctxt) == NULL) {
5674 WXS_SUBST_GROUPS(pctxt) = xmlHashCreateDict(10, pctxt->dict);
5675 if (WXS_SUBST_GROUPS(pctxt) == NULL)
5676 return(NULL);
5677 }
5678 /* Create a new substitution group. */
5679 ret = (xmlSchemaSubstGroupPtr) xmlMalloc(sizeof(xmlSchemaSubstGroup));
5680 if (ret == NULL) {
5681 xmlSchemaPErrMemory(NULL,
5682 "allocating a substitution group container", NULL);
5683 return(NULL);
5684 }
5685 memset(ret, 0, sizeof(xmlSchemaSubstGroup));
5686 ret->head = head;
5687 /* Create list of members. */
5688 ret->members = xmlSchemaItemListCreate();
5689 if (ret->members == NULL) {
5690 xmlSchemaSubstGroupFree(ret);
5691 return(NULL);
5692 }
5693 /* Add subst group to hash. */
5694 if (xmlHashAddEntry2(WXS_SUBST_GROUPS(pctxt),
5695 head->name, head->targetNamespace, ret) != 0) {
5696 PERROR_INT("xmlSchemaSubstGroupAdd",
5697 "failed to add a new substitution container");
5698 xmlSchemaSubstGroupFree(ret);
5699 return(NULL);
5700 }
5701 return(ret);
5702}
5703
5704static xmlSchemaSubstGroupPtr
5705xmlSchemaSubstGroupGet(xmlSchemaParserCtxtPtr pctxt,
5706 xmlSchemaElementPtr head)
Daniel Veillarddee23482008-04-11 12:58:43 +00005707{
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005708 if (WXS_SUBST_GROUPS(pctxt) == NULL)
5709 return(NULL);
5710 return(xmlHashLookup2(WXS_SUBST_GROUPS(pctxt),
5711 head->name, head->targetNamespace));
5712
5713}
5714
5715/**
5716 * xmlSchemaAddElementSubstitutionMember:
5717 * @pctxt: a schema parser context
5718 * @head: the head of the substitution group
5719 * @member: the new member of the substitution group
5720 *
5721 * Allocate a new annotation structure.
5722 *
5723 * Returns the newly allocated structure or NULL in case or error
5724 */
5725static int
5726xmlSchemaAddElementSubstitutionMember(xmlSchemaParserCtxtPtr pctxt,
5727 xmlSchemaElementPtr head,
5728 xmlSchemaElementPtr member)
5729{
5730 xmlSchemaSubstGroupPtr substGroup = NULL;
5731
5732 if ((pctxt == NULL) || (head == NULL) || (member == NULL))
5733 return (-1);
5734
5735 substGroup = xmlSchemaSubstGroupGet(pctxt, head);
5736 if (substGroup == NULL)
5737 substGroup = xmlSchemaSubstGroupAdd(pctxt, head);
5738 if (substGroup == NULL)
5739 return(-1);
5740 if (xmlSchemaItemListAdd(substGroup->members, member) == -1)
5741 return(-1);
5742 return(0);
5743}
5744
Daniel Veillard4255d502002-04-16 15:50:10 +00005745/************************************************************************
5746 * *
5747 * Utilities for parsing *
5748 * *
5749 ************************************************************************/
5750
Daniel Veillard4255d502002-04-16 15:50:10 +00005751/**
Daniel Veillardc0826a72004-08-10 14:17:33 +00005752 * xmlSchemaPValAttrNodeQNameValue:
5753 * @ctxt: a schema parser context
5754 * @schema: the schema context
5755 * @ownerDes: the designation of the parent element
5756 * @ownerItem: the parent as a schema object
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00005757 * @value: the QName value
Daniel Veillardc0826a72004-08-10 14:17:33 +00005758 * @local: the resulting local part if found, the attribute value otherwise
5759 * @uri: the resulting namespace URI if found
5760 *
5761 * Extracts the local name and the URI of a QName value and validates it.
5762 * This one is intended to be used on attribute values that
5763 * should resolve to schema components.
5764 *
5765 * Returns 0, in case the QName is valid, a positive error code
5766 * if not valid and -1 if an internal error occurs.
5767 */
5768static int
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00005769xmlSchemaPValAttrNodeQNameValue(xmlSchemaParserCtxtPtr ctxt,
Daniel Veillardc0826a72004-08-10 14:17:33 +00005770 xmlSchemaPtr schema,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005771 xmlSchemaBasicItemPtr ownerItem,
Daniel Veillardc0826a72004-08-10 14:17:33 +00005772 xmlAttrPtr attr,
5773 const xmlChar *value,
5774 const xmlChar **uri,
Daniel Veillardc0826a72004-08-10 14:17:33 +00005775 const xmlChar **local)
5776{
5777 const xmlChar *pref;
5778 xmlNsPtr ns;
5779 int len, ret;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00005780
Daniel Veillardc0826a72004-08-10 14:17:33 +00005781 *uri = NULL;
5782 *local = NULL;
Daniel Veillardc0826a72004-08-10 14:17:33 +00005783 ret = xmlValidateQName(value, 1);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00005784 if (ret > 0) {
5785 xmlSchemaPSimpleTypeErr(ctxt,
5786 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
5787 ownerItem, (xmlNodePtr) attr,
5788 xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME),
5789 NULL, value, NULL, NULL, NULL);
Daniel Veillardc0826a72004-08-10 14:17:33 +00005790 *local = value;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00005791 return (ctxt->err);
Daniel Veillardc0826a72004-08-10 14:17:33 +00005792 } else if (ret < 0)
5793 return (-1);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00005794
5795 if (!strchr((char *) value, ':')) {
Daniel Veillard24505b02005-07-28 23:49:35 +00005796 ns = xmlSearchNs(attr->doc, attr->parent, NULL);
Daniel Veillardc0826a72004-08-10 14:17:33 +00005797 if (ns)
5798 *uri = xmlDictLookup(ctxt->dict, ns->href, -1);
5799 else if (schema->flags & XML_SCHEMAS_INCLUDING_CONVERT_NS) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005800 /* TODO: move XML_SCHEMAS_INCLUDING_CONVERT_NS to the
5801 * parser context. */
Daniel Veillardc0826a72004-08-10 14:17:33 +00005802 /*
5803 * This one takes care of included schemas with no
5804 * target namespace.
5805 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00005806 *uri = ctxt->targetNamespace;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00005807 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00005808 *local = xmlDictLookup(ctxt->dict, value, -1);
Daniel Veillardc0826a72004-08-10 14:17:33 +00005809 return (0);
5810 }
5811 /*
5812 * At this point xmlSplitQName3 has to return a local name.
5813 */
5814 *local = xmlSplitQName3(value, &len);
5815 *local = xmlDictLookup(ctxt->dict, *local, -1);
5816 pref = xmlDictLookup(ctxt->dict, value, len);
Daniel Veillardc0826a72004-08-10 14:17:33 +00005817 ns = xmlSearchNs(attr->doc, attr->parent, pref);
5818 if (ns == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00005819 xmlSchemaPSimpleTypeErr(ctxt,
Daniel Veillardc0826a72004-08-10 14:17:33 +00005820 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00005821 ownerItem, (xmlNodePtr) attr,
5822 xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), NULL, value,
5823 "The value '%s' of simple type 'xs:QName' has no "
5824 "corresponding namespace declaration in scope", value, NULL);
Daniel Veillardc0826a72004-08-10 14:17:33 +00005825 return (ctxt->err);
5826 } else {
5827 *uri = xmlDictLookup(ctxt->dict, ns->href, -1);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00005828 }
Daniel Veillardc0826a72004-08-10 14:17:33 +00005829 return (0);
5830}
5831
5832/**
5833 * xmlSchemaPValAttrNodeQName:
5834 * @ctxt: a schema parser context
5835 * @schema: the schema context
5836 * @ownerDes: the designation of the owner element
5837 * @ownerItem: the owner as a schema object
5838 * @attr: the attribute node
5839 * @local: the resulting local part if found, the attribute value otherwise
5840 * @uri: the resulting namespace URI if found
5841 *
5842 * Extracts and validates the QName of an attribute value.
5843 * This one is intended to be used on attribute values that
5844 * should resolve to schema components.
5845 *
5846 * Returns 0, in case the QName is valid, a positive error code
5847 * if not valid and -1 if an internal error occurs.
5848 */
5849static int
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00005850xmlSchemaPValAttrNodeQName(xmlSchemaParserCtxtPtr ctxt,
Daniel Veillardc0826a72004-08-10 14:17:33 +00005851 xmlSchemaPtr schema,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005852 xmlSchemaBasicItemPtr ownerItem,
Daniel Veillardc0826a72004-08-10 14:17:33 +00005853 xmlAttrPtr attr,
5854 const xmlChar **uri,
Daniel Veillardc0826a72004-08-10 14:17:33 +00005855 const xmlChar **local)
5856{
5857 const xmlChar *value;
5858
5859 value = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00005860 return (xmlSchemaPValAttrNodeQNameValue(ctxt, schema,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005861 ownerItem, attr, value, uri, local));
Daniel Veillardc0826a72004-08-10 14:17:33 +00005862}
5863
5864/**
5865 * xmlSchemaPValAttrQName:
5866 * @ctxt: a schema parser context
5867 * @schema: the schema context
5868 * @ownerDes: the designation of the parent element
5869 * @ownerItem: the owner as a schema object
5870 * @ownerElem: the parent node of the attribute
5871 * @name: the name of the attribute
5872 * @local: the resulting local part if found, the attribute value otherwise
5873 * @uri: the resulting namespace URI if found
5874 *
5875 * Extracts and validates the QName of an attribute value.
5876 *
5877 * Returns 0, in case the QName is valid, a positive error code
5878 * if not valid and -1 if an internal error occurs.
5879 */
5880static int
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00005881xmlSchemaPValAttrQName(xmlSchemaParserCtxtPtr ctxt,
5882 xmlSchemaPtr schema,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005883 xmlSchemaBasicItemPtr ownerItem,
Daniel Veillardc0826a72004-08-10 14:17:33 +00005884 xmlNodePtr ownerElem,
5885 const char *name,
5886 const xmlChar **uri,
Daniel Veillardc0826a72004-08-10 14:17:33 +00005887 const xmlChar **local)
5888{
5889 xmlAttrPtr attr;
5890
5891 attr = xmlSchemaGetPropNode(ownerElem, name);
5892 if (attr == NULL) {
5893 *local = NULL;
5894 *uri = NULL;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00005895 return (0);
Daniel Veillardc0826a72004-08-10 14:17:33 +00005896 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00005897 return (xmlSchemaPValAttrNodeQName(ctxt, schema,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005898 ownerItem, attr, uri, local));
Daniel Veillardc0826a72004-08-10 14:17:33 +00005899}
5900
5901/**
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +00005902 * xmlSchemaPValAttrID:
5903 * @ctxt: a schema parser context
5904 * @schema: the schema context
5905 * @ownerDes: the designation of the parent element
5906 * @ownerItem: the owner as a schema object
5907 * @ownerElem: the parent node of the attribute
5908 * @name: the name of the attribute
5909 *
5910 * Extracts and validates the ID of an attribute value.
5911 *
5912 * Returns 0, in case the ID is valid, a positive error code
5913 * if not valid and -1 if an internal error occurs.
5914 */
5915static int
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005916xmlSchemaPValAttrNodeID(xmlSchemaParserCtxtPtr ctxt, xmlAttrPtr attr)
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +00005917{
5918 int ret;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005919 const xmlChar *value;
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +00005920
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +00005921 if (attr == NULL)
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005922 return(0);
5923 value = xmlSchemaGetNodeContentNoDict((xmlNodePtr) attr);
5924 ret = xmlValidateNCName(value, 1);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00005925 if (ret == 0) {
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +00005926 /*
5927 * NOTE: the IDness might have already be declared in the DTD
5928 */
5929 if (attr->atype != XML_ATTRIBUTE_ID) {
5930 xmlIDPtr res;
5931 xmlChar *strip;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00005932
5933 /*
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +00005934 * TODO: Use xmlSchemaStrip here; it's not exported at this
5935 * moment.
5936 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005937 strip = xmlSchemaCollapseString(value);
5938 if (strip != NULL) {
5939 xmlFree((xmlChar *) value);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00005940 value = strip;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005941 }
5942 res = xmlAddID(NULL, attr->doc, value, attr);
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +00005943 if (res == NULL) {
5944 ret = XML_SCHEMAP_S4S_ATTR_INVALID_VALUE;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00005945 xmlSchemaPSimpleTypeErr(ctxt,
5946 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005947 NULL, (xmlNodePtr) attr,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00005948 xmlSchemaGetBuiltInType(XML_SCHEMAS_ID),
5949 NULL, NULL, "Duplicate value '%s' of simple "
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005950 "type 'xs:ID'", value, NULL);
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +00005951 } else
5952 attr->atype = XML_ATTRIBUTE_ID;
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +00005953 }
5954 } else if (ret > 0) {
5955 ret = XML_SCHEMAP_S4S_ATTR_INVALID_VALUE;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00005956 xmlSchemaPSimpleTypeErr(ctxt,
5957 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005958 NULL, (xmlNodePtr) attr,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00005959 xmlSchemaGetBuiltInType(XML_SCHEMAS_ID),
5960 NULL, NULL, "The value '%s' of simple type 'xs:ID' is "
5961 "not a valid 'xs:NCName'",
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005962 value, NULL);
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +00005963 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005964 if (value != NULL)
5965 xmlFree((xmlChar *)value);
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +00005966
5967 return (ret);
5968}
5969
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00005970static int
5971xmlSchemaPValAttrID(xmlSchemaParserCtxtPtr ctxt,
5972 xmlNodePtr ownerElem,
5973 const xmlChar *name)
5974{
5975 xmlAttrPtr attr;
5976
5977 attr = xmlSchemaGetPropNode(ownerElem, (const char *) name);
5978 if (attr == NULL)
5979 return(0);
5980 return(xmlSchemaPValAttrNodeID(ctxt, attr));
5981
5982}
5983
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +00005984/**
Daniel Veillard4255d502002-04-16 15:50:10 +00005985 * xmlGetMaxOccurs:
5986 * @ctxt: a schema validation context
5987 * @node: a subtree containing XML Schema informations
5988 *
5989 * Get the maxOccurs property
5990 *
5991 * Returns the default if not found, or the value
5992 */
5993static int
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00005994xmlGetMaxOccurs(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node,
5995 int min, int max, int def, const char *expected)
Daniel Veillardd0c9c322003-10-10 00:49:42 +00005996{
Daniel Veillardbe9c6322003-11-22 20:37:51 +00005997 const xmlChar *val, *cur;
Daniel Veillard4255d502002-04-16 15:50:10 +00005998 int ret = 0;
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00005999 xmlAttrPtr attr;
Daniel Veillard4255d502002-04-16 15:50:10 +00006000
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00006001 attr = xmlSchemaGetPropNode(node, "maxOccurs");
6002 if (attr == NULL)
6003 return (def);
6004 val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
Daniel Veillard4255d502002-04-16 15:50:10 +00006005
6006 if (xmlStrEqual(val, (const xmlChar *) "unbounded")) {
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00006007 if (max != UNBOUNDED) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006008 xmlSchemaPSimpleTypeErr(ctxt,
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00006009 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
6010 /* XML_SCHEMAP_INVALID_MINOCCURS, */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006011 NULL, (xmlNodePtr) attr, NULL, expected,
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00006012 val, NULL, NULL, NULL);
6013 return (def);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006014 } else
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00006015 return (UNBOUNDED); /* encoding it with -1 might be another option */
Daniel Veillard4255d502002-04-16 15:50:10 +00006016 }
6017
6018 cur = val;
William M. Brack76e95df2003-10-18 16:20:14 +00006019 while (IS_BLANK_CH(*cur))
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006020 cur++;
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00006021 if (*cur == 0) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006022 xmlSchemaPSimpleTypeErr(ctxt,
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00006023 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
6024 /* XML_SCHEMAP_INVALID_MINOCCURS, */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006025 NULL, (xmlNodePtr) attr, NULL, expected,
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00006026 val, NULL, NULL, NULL);
6027 return (def);
6028 }
Daniel Veillard4255d502002-04-16 15:50:10 +00006029 while ((*cur >= '0') && (*cur <= '9')) {
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006030 ret = ret * 10 + (*cur - '0');
6031 cur++;
Daniel Veillard4255d502002-04-16 15:50:10 +00006032 }
William M. Brack76e95df2003-10-18 16:20:14 +00006033 while (IS_BLANK_CH(*cur))
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006034 cur++;
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00006035 /*
6036 * TODO: Restrict the maximal value to Integer.
6037 */
6038 if ((*cur != 0) || (ret < min) || ((max != -1) && (ret > max))) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006039 xmlSchemaPSimpleTypeErr(ctxt,
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00006040 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
6041 /* XML_SCHEMAP_INVALID_MINOCCURS, */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006042 NULL, (xmlNodePtr) attr, NULL, expected,
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00006043 val, NULL, NULL, NULL);
6044 return (def);
Daniel Veillard4255d502002-04-16 15:50:10 +00006045 }
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006046 return (ret);
Daniel Veillard4255d502002-04-16 15:50:10 +00006047}
6048
6049/**
6050 * xmlGetMinOccurs:
6051 * @ctxt: a schema validation context
6052 * @node: a subtree containing XML Schema informations
6053 *
6054 * Get the minOccurs property
6055 *
6056 * Returns the default if not found, or the value
6057 */
6058static int
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006059xmlGetMinOccurs(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node,
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00006060 int min, int max, int def, const char *expected)
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006061{
Daniel Veillardbe9c6322003-11-22 20:37:51 +00006062 const xmlChar *val, *cur;
Daniel Veillard4255d502002-04-16 15:50:10 +00006063 int ret = 0;
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00006064 xmlAttrPtr attr;
Daniel Veillard4255d502002-04-16 15:50:10 +00006065
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00006066 attr = xmlSchemaGetPropNode(node, "minOccurs");
6067 if (attr == NULL)
6068 return (def);
6069 val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
Daniel Veillard4255d502002-04-16 15:50:10 +00006070 cur = val;
William M. Brack76e95df2003-10-18 16:20:14 +00006071 while (IS_BLANK_CH(*cur))
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006072 cur++;
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00006073 if (*cur == 0) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006074 xmlSchemaPSimpleTypeErr(ctxt,
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00006075 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
6076 /* XML_SCHEMAP_INVALID_MINOCCURS, */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006077 NULL, (xmlNodePtr) attr, NULL, expected,
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00006078 val, NULL, NULL, NULL);
6079 return (def);
6080 }
Daniel Veillard4255d502002-04-16 15:50:10 +00006081 while ((*cur >= '0') && (*cur <= '9')) {
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006082 ret = ret * 10 + (*cur - '0');
6083 cur++;
Daniel Veillard4255d502002-04-16 15:50:10 +00006084 }
William M. Brack76e95df2003-10-18 16:20:14 +00006085 while (IS_BLANK_CH(*cur))
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006086 cur++;
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00006087 /*
6088 * TODO: Restrict the maximal value to Integer.
6089 */
6090 if ((*cur != 0) || (ret < min) || ((max != -1) && (ret > max))) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006091 xmlSchemaPSimpleTypeErr(ctxt,
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00006092 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
6093 /* XML_SCHEMAP_INVALID_MINOCCURS, */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006094 NULL, (xmlNodePtr) attr, NULL, expected,
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00006095 val, NULL, NULL, NULL);
6096 return (def);
Daniel Veillard4255d502002-04-16 15:50:10 +00006097 }
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006098 return (ret);
Daniel Veillard4255d502002-04-16 15:50:10 +00006099}
6100
6101/**
Kasimier T. Buchcik87876402004-09-29 13:29:03 +00006102 * xmlSchemaPGetBoolNodeValue:
6103 * @ctxt: a schema validation context
6104 * @ownerDes: owner designation
6105 * @ownerItem: the owner as a schema item
6106 * @node: the node holding the value
6107 *
6108 * Converts a boolean string value into 1 or 0.
6109 *
6110 * Returns 0 or 1.
6111 */
6112static int
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006113xmlSchemaPGetBoolNodeValue(xmlSchemaParserCtxtPtr ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006114 xmlSchemaBasicItemPtr ownerItem,
Kasimier T. Buchcik87876402004-09-29 13:29:03 +00006115 xmlNodePtr node)
6116{
6117 xmlChar *value = NULL;
6118 int res = 0;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006119
Kasimier T. Buchcik87876402004-09-29 13:29:03 +00006120 value = xmlNodeGetContent(node);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006121 /*
Kasimier T. Buchcik87876402004-09-29 13:29:03 +00006122 * 3.2.2.1 Lexical representation
Rob Richardsc6947bb2008-06-29 15:04:41 +00006123 * An instance of a datatype that is defined as �boolean�
Kasimier T. Buchcik87876402004-09-29 13:29:03 +00006124 * can have the following legal literals {true, false, 1, 0}.
6125 */
6126 if (xmlStrEqual(BAD_CAST value, BAD_CAST "true"))
6127 res = 1;
6128 else if (xmlStrEqual(BAD_CAST value, BAD_CAST "false"))
6129 res = 0;
6130 else if (xmlStrEqual(BAD_CAST value, BAD_CAST "1"))
6131 res = 1;
6132 else if (xmlStrEqual(BAD_CAST value, BAD_CAST "0"))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006133 res = 0;
Kasimier T. Buchcik87876402004-09-29 13:29:03 +00006134 else {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006135 xmlSchemaPSimpleTypeErr(ctxt,
Kasimier T. Buchcik87876402004-09-29 13:29:03 +00006136 XML_SCHEMAP_INVALID_BOOLEAN,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006137 ownerItem, node,
6138 xmlSchemaGetBuiltInType(XML_SCHEMAS_BOOLEAN),
6139 NULL, BAD_CAST value,
Kasimier T. Buchcik87876402004-09-29 13:29:03 +00006140 NULL, NULL, NULL);
6141 }
6142 if (value != NULL)
6143 xmlFree(value);
6144 return (res);
6145}
6146
6147/**
Daniel Veillard4255d502002-04-16 15:50:10 +00006148 * xmlGetBooleanProp:
6149 * @ctxt: a schema validation context
6150 * @node: a subtree containing XML Schema informations
6151 * @name: the attribute name
6152 * @def: the default value
6153 *
Daniel Veillardc0826a72004-08-10 14:17:33 +00006154 * Evaluate if a boolean property is set
Daniel Veillard4255d502002-04-16 15:50:10 +00006155 *
6156 * Returns the default if not found, 0 if found to be false,
Daniel Veillardc0826a72004-08-10 14:17:33 +00006157 * 1 if found to be true
Daniel Veillard4255d502002-04-16 15:50:10 +00006158 */
6159static int
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006160xmlGetBooleanProp(xmlSchemaParserCtxtPtr ctxt,
Daniel Veillardc0826a72004-08-10 14:17:33 +00006161 xmlNodePtr node,
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006162 const char *name, int def)
6163{
Daniel Veillardbe9c6322003-11-22 20:37:51 +00006164 const xmlChar *val;
Daniel Veillard4255d502002-04-16 15:50:10 +00006165
Daniel Veillardbe9c6322003-11-22 20:37:51 +00006166 val = xmlSchemaGetProp(ctxt, node, name);
Daniel Veillard4255d502002-04-16 15:50:10 +00006167 if (val == NULL)
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006168 return (def);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006169 /*
Daniel Veillardc0826a72004-08-10 14:17:33 +00006170 * 3.2.2.1 Lexical representation
Rob Richardsc6947bb2008-06-29 15:04:41 +00006171 * An instance of a datatype that is defined as �boolean�
Daniel Veillardc0826a72004-08-10 14:17:33 +00006172 * can have the following legal literals {true, false, 1, 0}.
6173 */
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006174 if (xmlStrEqual(val, BAD_CAST "true"))
6175 def = 1;
6176 else if (xmlStrEqual(val, BAD_CAST "false"))
6177 def = 0;
Daniel Veillardc0826a72004-08-10 14:17:33 +00006178 else if (xmlStrEqual(val, BAD_CAST "1"))
6179 def = 1;
6180 else if (xmlStrEqual(val, BAD_CAST "0"))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006181 def = 0;
6182 else {
6183 xmlSchemaPSimpleTypeErr(ctxt,
Daniel Veillardc0826a72004-08-10 14:17:33 +00006184 XML_SCHEMAP_INVALID_BOOLEAN,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006185 NULL,
Kasimier T. Buchcik25799ce2005-02-15 14:39:48 +00006186 (xmlNodePtr) xmlSchemaGetPropNode(node, name),
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006187 xmlSchemaGetBuiltInType(XML_SCHEMAS_BOOLEAN),
6188 NULL, val, NULL, NULL, NULL);
Daniel Veillard4255d502002-04-16 15:50:10 +00006189 }
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006190 return (def);
Daniel Veillard4255d502002-04-16 15:50:10 +00006191}
6192
6193/************************************************************************
6194 * *
6195 * Shema extraction from an Infoset *
6196 * *
6197 ************************************************************************/
6198static xmlSchemaTypePtr xmlSchemaParseSimpleType(xmlSchemaParserCtxtPtr
6199 ctxt, xmlSchemaPtr schema,
Daniel Veillard3646d642004-06-02 19:19:14 +00006200 xmlNodePtr node,
6201 int topLevel);
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006202static xmlSchemaTypePtr xmlSchemaParseComplexType(xmlSchemaParserCtxtPtr
6203 ctxt,
Daniel Veillard4255d502002-04-16 15:50:10 +00006204 xmlSchemaPtr schema,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006205 xmlNodePtr node,
Daniel Veillard3646d642004-06-02 19:19:14 +00006206 int topLevel);
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006207static xmlSchemaTypePtr xmlSchemaParseRestriction(xmlSchemaParserCtxtPtr
6208 ctxt,
Daniel Veillard4255d502002-04-16 15:50:10 +00006209 xmlSchemaPtr schema,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00006210 xmlNodePtr node,
6211 xmlSchemaTypeType parentType);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006212static xmlSchemaBasicItemPtr
6213xmlSchemaParseLocalAttribute(xmlSchemaParserCtxtPtr pctxt,
6214 xmlSchemaPtr schema,
6215 xmlNodePtr node,
6216 xmlSchemaItemListPtr uses,
6217 int parentType);
Daniel Veillard4255d502002-04-16 15:50:10 +00006218static xmlSchemaTypePtr xmlSchemaParseList(xmlSchemaParserCtxtPtr ctxt,
6219 xmlSchemaPtr schema,
6220 xmlNodePtr node);
Daniel Veillard3646d642004-06-02 19:19:14 +00006221static xmlSchemaWildcardPtr
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006222xmlSchemaParseAnyAttribute(xmlSchemaParserCtxtPtr ctxt,
6223 xmlSchemaPtr schema, xmlNodePtr node);
Daniel Veillard4255d502002-04-16 15:50:10 +00006224
6225/**
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +00006226 * xmlSchemaPValAttrNodeValue:
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006227 *
Daniel Veillard01fa6152004-06-29 17:04:39 +00006228 * @ctxt: a schema parser context
Daniel Veillardc0826a72004-08-10 14:17:33 +00006229 * @ownerDes: the designation of the parent element
6230 * @ownerItem: the schema object owner if existent
6231 * @attr: the schema attribute node being validated
6232 * @value: the value
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006233 * @type: the built-in type to be validated against
Daniel Veillard01fa6152004-06-29 17:04:39 +00006234 *
6235 * Validates a value against the given built-in type.
6236 * This one is intended to be used internally for validation
6237 * of schema attribute values during parsing of the schema.
6238 *
6239 * Returns 0 if the value is valid, a positive error code
6240 * number otherwise and -1 in case of an internal or API error.
6241 */
6242static int
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006243xmlSchemaPValAttrNodeValue(xmlSchemaParserCtxtPtr pctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006244 xmlSchemaBasicItemPtr ownerItem,
Daniel Veillardc0826a72004-08-10 14:17:33 +00006245 xmlAttrPtr attr,
6246 const xmlChar *value,
6247 xmlSchemaTypePtr type)
Daniel Veillard01fa6152004-06-29 17:04:39 +00006248{
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006249
6250 int ret = 0;
Daniel Veillardc0826a72004-08-10 14:17:33 +00006251
6252 /*
6253 * NOTE: Should we move this to xmlschematypes.c? Hmm, but this
6254 * one is really meant to be used internally, so better not.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006255 */
6256 if ((pctxt == NULL) || (type == NULL) || (attr == NULL))
Daniel Veillard01fa6152004-06-29 17:04:39 +00006257 return (-1);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006258 if (type->type != XML_SCHEMA_TYPE_BASIC) {
6259 PERROR_INT("xmlSchemaPValAttrNodeValue",
6260 "the given type is not a built-in type");
6261 return (-1);
6262 }
Daniel Veillard01fa6152004-06-29 17:04:39 +00006263 switch (type->builtInType) {
6264 case XML_SCHEMAS_NCNAME:
Kasimier T. Buchcik91feaf82004-11-12 14:04:58 +00006265 case XML_SCHEMAS_QNAME:
6266 case XML_SCHEMAS_ANYURI:
6267 case XML_SCHEMAS_TOKEN:
6268 case XML_SCHEMAS_LANGUAGE:
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006269 ret = xmlSchemaValPredefTypeNode(type, value, NULL,
6270 (xmlNodePtr) attr);
Kasimier T. Buchcik91feaf82004-11-12 14:04:58 +00006271 break;
Daniel Veillard01fa6152004-06-29 17:04:39 +00006272 default: {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006273 PERROR_INT("xmlSchemaPValAttrNodeValue",
Kasimier T. Buchcik69dea3a2005-11-07 14:02:44 +00006274 "validation using the given type is not supported while "
6275 "parsing a schema");
Daniel Veillard01fa6152004-06-29 17:04:39 +00006276 return (-1);
6277 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006278 }
Daniel Veillardc0826a72004-08-10 14:17:33 +00006279 /*
6280 * TODO: Should we use the S4S error codes instead?
6281 */
Kasimier T. Buchcik91feaf82004-11-12 14:04:58 +00006282 if (ret < 0) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006283 PERROR_INT("xmlSchemaPValAttrNodeValue",
6284 "failed to validate a schema attribute value");
Kasimier T. Buchcik91feaf82004-11-12 14:04:58 +00006285 return (-1);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006286 } else if (ret > 0) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006287 if (WXS_IS_LIST(type))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006288 ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2;
6289 else
6290 ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1;
Daniel Veillarddee23482008-04-11 12:58:43 +00006291 xmlSchemaPSimpleTypeErr(pctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006292 ret, ownerItem, (xmlNodePtr) attr,
6293 type, NULL, value, NULL, NULL, NULL);
6294 }
Daniel Veillard01fa6152004-06-29 17:04:39 +00006295 return (ret);
6296}
6297
6298/**
Daniel Veillardc0826a72004-08-10 14:17:33 +00006299 * xmlSchemaPValAttrNode:
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006300 *
Daniel Veillardc0826a72004-08-10 14:17:33 +00006301 * @ctxt: a schema parser context
6302 * @ownerDes: the designation of the parent element
6303 * @ownerItem: the schema object owner if existent
6304 * @attr: the schema attribute node being validated
6305 * @type: the built-in type to be validated against
6306 * @value: the resulting value if any
6307 *
6308 * Extracts and validates a value against the given built-in type.
6309 * This one is intended to be used internally for validation
6310 * of schema attribute values during parsing of the schema.
6311 *
6312 * Returns 0 if the value is valid, a positive error code
6313 * number otherwise and -1 in case of an internal or API error.
6314 */
6315static int
6316xmlSchemaPValAttrNode(xmlSchemaParserCtxtPtr ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006317 xmlSchemaBasicItemPtr ownerItem,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006318 xmlAttrPtr attr,
Daniel Veillardc0826a72004-08-10 14:17:33 +00006319 xmlSchemaTypePtr type,
6320 const xmlChar **value)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006321{
Daniel Veillardc0826a72004-08-10 14:17:33 +00006322 const xmlChar *val;
6323
6324 if ((ctxt == NULL) || (type == NULL) || (attr == NULL))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006325 return (-1);
6326
Daniel Veillardc0826a72004-08-10 14:17:33 +00006327 val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
6328 if (value != NULL)
6329 *value = val;
6330
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006331 return (xmlSchemaPValAttrNodeValue(ctxt, ownerItem, attr,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006332 val, type));
Daniel Veillardc0826a72004-08-10 14:17:33 +00006333}
6334
6335/**
6336 * xmlSchemaPValAttr:
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006337 *
Daniel Veillardc0826a72004-08-10 14:17:33 +00006338 * @ctxt: a schema parser context
6339 * @node: the element node of the attribute
6340 * @ownerDes: the designation of the parent element
6341 * @ownerItem: the schema object owner if existent
6342 * @ownerElem: the owner element node
6343 * @name: the name of the schema attribute node
6344 * @type: the built-in type to be validated against
6345 * @value: the resulting value if any
6346 *
6347 * Extracts and validates a value against the given built-in type.
6348 * This one is intended to be used internally for validation
6349 * of schema attribute values during parsing of the schema.
6350 *
6351 * Returns 0 if the value is valid, a positive error code
6352 * number otherwise and -1 in case of an internal or API error.
6353 */
6354static int
Daniel Veillarddee23482008-04-11 12:58:43 +00006355xmlSchemaPValAttr(xmlSchemaParserCtxtPtr ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006356 xmlSchemaBasicItemPtr ownerItem,
Daniel Veillardc0826a72004-08-10 14:17:33 +00006357 xmlNodePtr ownerElem,
6358 const char *name,
6359 xmlSchemaTypePtr type,
6360 const xmlChar **value)
6361{
6362 xmlAttrPtr attr;
6363
6364 if ((ctxt == NULL) || (type == NULL)) {
6365 if (value != NULL)
6366 *value = NULL;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006367 return (-1);
Daniel Veillardc0826a72004-08-10 14:17:33 +00006368 }
6369 if (type->type != XML_SCHEMA_TYPE_BASIC) {
6370 if (value != NULL)
6371 *value = NULL;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006372 xmlSchemaPErr(ctxt, ownerElem,
Kasimier T. Buchcikbea23542004-08-25 20:35:45 +00006373 XML_SCHEMAP_INTERNAL,
Daniel Veillardc0826a72004-08-10 14:17:33 +00006374 "Internal error: xmlSchemaPValAttr, the given "
6375 "type '%s' is not a built-in type.\n",
6376 type->name, NULL);
6377 return (-1);
6378 }
6379 attr = xmlSchemaGetPropNode(ownerElem, name);
6380 if (attr == NULL) {
6381 if (value != NULL)
6382 *value = NULL;
6383 return (0);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006384 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006385 return (xmlSchemaPValAttrNode(ctxt, ownerItem, attr,
Daniel Veillardc0826a72004-08-10 14:17:33 +00006386 type, value));
6387}
Kasimier T. Buchcikb474fa42005-03-11 12:34:42 +00006388
6389static int
6390xmlSchemaCheckReference(xmlSchemaParserCtxtPtr pctxt,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00006391 xmlSchemaPtr schema ATTRIBUTE_UNUSED,
Kasimier T. Buchcikb474fa42005-03-11 12:34:42 +00006392 xmlNodePtr node,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006393 xmlAttrPtr attr,
Kasimier T. Buchcikb474fa42005-03-11 12:34:42 +00006394 const xmlChar *namespaceName)
6395{
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00006396 /* TODO: Pointer comparison instead? */
6397 if (xmlStrEqual(pctxt->targetNamespace, namespaceName))
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006398 return (0);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006399 if (xmlStrEqual(xmlSchemaNs, namespaceName))
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006400 return (0);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00006401 /*
6402 * Check if the referenced namespace was <import>ed.
6403 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006404 if (WXS_BUCKET(pctxt)->relations != NULL) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00006405 xmlSchemaSchemaRelationPtr rel;
6406
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006407 rel = WXS_BUCKET(pctxt)->relations;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00006408 do {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006409 if (WXS_IS_BUCKET_IMPMAIN(rel->type) &&
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00006410 xmlStrEqual(namespaceName, rel->importNamespace))
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006411 return (0);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00006412 rel = rel->next;
6413 } while (rel != NULL);
Kasimier T. Buchcikb474fa42005-03-11 12:34:42 +00006414 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00006415 /*
6416 * No matching <import>ed namespace found.
6417 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006418 {
6419 xmlNodePtr n = (attr != NULL) ? (xmlNodePtr) attr : node;
6420
6421 if (namespaceName == NULL)
6422 xmlSchemaCustomErr(ACTXT_CAST pctxt,
6423 XML_SCHEMAP_SRC_RESOLVE, n, NULL,
6424 "References from this schema to components in no "
6425 "namespace are not allowed, since not indicated by an "
6426 "import statement", NULL, NULL);
6427 else
6428 xmlSchemaCustomErr(ACTXT_CAST pctxt,
6429 XML_SCHEMAP_SRC_RESOLVE, n, NULL,
6430 "References from this schema to components in the "
6431 "namespace '%s' are not allowed, since not indicated by an "
6432 "import statement", namespaceName, NULL);
6433 }
6434 return (XML_SCHEMAP_SRC_RESOLVE);
Kasimier T. Buchcikb474fa42005-03-11 12:34:42 +00006435}
6436
Daniel Veillardc0826a72004-08-10 14:17:33 +00006437/**
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006438 * xmlSchemaParseLocalAttributes:
Daniel Veillard4255d502002-04-16 15:50:10 +00006439 * @ctxt: a schema validation context
6440 * @schema: the schema being built
6441 * @node: a subtree containing XML Schema informations
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00006442 * @type: the hosting type where the attributes will be anchored
Daniel Veillard4255d502002-04-16 15:50:10 +00006443 *
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006444 * Parses attribute uses and attribute declarations and
Daniel Veillarddee23482008-04-11 12:58:43 +00006445 * attribute group references.
Daniel Veillard4255d502002-04-16 15:50:10 +00006446 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006447static int
6448xmlSchemaParseLocalAttributes(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
6449 xmlNodePtr *child, xmlSchemaItemListPtr *list,
6450 int parentType, int *hasRefs)
Daniel Veillard4255d502002-04-16 15:50:10 +00006451{
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006452 void *item;
Daniel Veillard4255d502002-04-16 15:50:10 +00006453
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006454 while ((IS_SCHEMA((*child), "attribute")) ||
6455 (IS_SCHEMA((*child), "attributeGroup"))) {
6456 if (IS_SCHEMA((*child), "attribute")) {
6457 item = xmlSchemaParseLocalAttribute(ctxt, schema, *child,
6458 *list, parentType);
6459 } else {
6460 item = xmlSchemaParseAttributeGroupRef(ctxt, schema, *child);
6461 if ((item != NULL) && (hasRefs != NULL))
6462 *hasRefs = 1;
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006463 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006464 if (item != NULL) {
6465 if (*list == NULL) {
6466 /* TODO: Customize grow factor. */
6467 *list = xmlSchemaItemListCreate();
6468 if (*list == NULL)
6469 return(-1);
6470 }
6471 if (xmlSchemaItemListAddSize(*list, 2, item) == -1)
6472 return(-1);
6473 }
6474 *child = (*child)->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006475 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006476 return (0);
Daniel Veillard4255d502002-04-16 15:50:10 +00006477}
6478
6479/**
6480 * xmlSchemaParseAnnotation:
6481 * @ctxt: a schema validation context
6482 * @schema: the schema being built
6483 * @node: a subtree containing XML Schema informations
6484 *
6485 * parse a XML schema Attrribute declaration
6486 * *WARNING* this interface is highly subject to change
6487 *
William M. Bracke7091952004-05-11 15:09:58 +00006488 * Returns -1 in case of error, 0 if the declaration is improper and
Daniel Veillard4255d502002-04-16 15:50:10 +00006489 * 1 in case of success.
6490 */
6491static xmlSchemaAnnotPtr
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +00006492xmlSchemaParseAnnotation(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int needed)
Daniel Veillard4255d502002-04-16 15:50:10 +00006493{
6494 xmlSchemaAnnotPtr ret;
Daniel Veillardc0826a72004-08-10 14:17:33 +00006495 xmlNodePtr child = NULL;
6496 xmlAttrPtr attr;
6497 int barked = 0;
Daniel Veillard4255d502002-04-16 15:50:10 +00006498
Daniel Veillardc0826a72004-08-10 14:17:33 +00006499 /*
6500 * INFO: S4S completed.
6501 */
6502 /*
6503 * id = ID
6504 * {any attributes with non-schema namespace . . .}>
6505 * Content: (appinfo | documentation)*
6506 */
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +00006507 if ((ctxt == NULL) || (node == NULL))
Daniel Veillard4255d502002-04-16 15:50:10 +00006508 return (NULL);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006509 if (needed)
6510 ret = xmlSchemaNewAnnot(ctxt, node);
6511 else
6512 ret = NULL;
Daniel Veillardc0826a72004-08-10 14:17:33 +00006513 attr = node->properties;
6514 while (attr != NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006515 if (((attr->ns == NULL) &&
Daniel Veillardc0826a72004-08-10 14:17:33 +00006516 (!xmlStrEqual(attr->name, BAD_CAST "id"))) ||
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006517 ((attr->ns != NULL) &&
Daniel Veillardc0826a72004-08-10 14:17:33 +00006518 xmlStrEqual(attr->ns->href, xmlSchemaNs))) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006519
6520 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006521 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Daniel Veillardc0826a72004-08-10 14:17:33 +00006522 }
6523 attr = attr->next;
6524 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006525 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
Daniel Veillardc0826a72004-08-10 14:17:33 +00006526 /*
6527 * And now for the children...
6528 */
6529 child = node->children;
6530 while (child != NULL) {
6531 if (IS_SCHEMA(child, "appinfo")) {
6532 /* TODO: make available the content of "appinfo". */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006533 /*
Daniel Veillardc0826a72004-08-10 14:17:33 +00006534 * source = anyURI
6535 * {any attributes with non-schema namespace . . .}>
6536 * Content: ({any})*
6537 */
6538 attr = child->properties;
6539 while (attr != NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006540 if (((attr->ns == NULL) &&
Daniel Veillardc0826a72004-08-10 14:17:33 +00006541 (!xmlStrEqual(attr->name, BAD_CAST "source"))) ||
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006542 ((attr->ns != NULL) &&
Daniel Veillardc0826a72004-08-10 14:17:33 +00006543 xmlStrEqual(attr->ns->href, xmlSchemaNs))) {
Daniel Veillard4255d502002-04-16 15:50:10 +00006544
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006545 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006546 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Daniel Veillardc0826a72004-08-10 14:17:33 +00006547 }
6548 attr = attr->next;
6549 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006550 xmlSchemaPValAttr(ctxt, NULL, child, "source",
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006551 xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), NULL);
Daniel Veillardc0826a72004-08-10 14:17:33 +00006552 child = child->next;
6553 } else if (IS_SCHEMA(child, "documentation")) {
6554 /* TODO: make available the content of "documentation". */
6555 /*
6556 * source = anyURI
6557 * {any attributes with non-schema namespace . . .}>
6558 * Content: ({any})*
6559 */
6560 attr = child->properties;
6561 while (attr != NULL) {
6562 if (attr->ns == NULL) {
6563 if (!xmlStrEqual(attr->name, BAD_CAST "source")) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006564 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006565 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Daniel Veillardc0826a72004-08-10 14:17:33 +00006566 }
6567 } else {
6568 if (xmlStrEqual(attr->ns->href, xmlSchemaNs) ||
6569 (xmlStrEqual(attr->name, BAD_CAST "lang") &&
6570 (!xmlStrEqual(attr->ns->href, XML_XML_NAMESPACE)))) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006571
6572 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006573 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Daniel Veillardc0826a72004-08-10 14:17:33 +00006574 }
6575 }
6576 attr = attr->next;
6577 }
6578 /*
6579 * Attribute "xml:lang".
6580 */
6581 attr = xmlSchemaGetPropNodeNs(child, (const char *) XML_XML_NAMESPACE, "lang");
6582 if (attr != NULL)
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006583 xmlSchemaPValAttrNode(ctxt, NULL, attr,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006584 xmlSchemaGetBuiltInType(XML_SCHEMAS_LANGUAGE), NULL);
Daniel Veillardc0826a72004-08-10 14:17:33 +00006585 child = child->next;
6586 } else {
6587 if (!barked)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006588 xmlSchemaPContentErr(ctxt,
6589 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006590 NULL, node, child, NULL, "(appinfo | documentation)*");
Daniel Veillardc0826a72004-08-10 14:17:33 +00006591 barked = 1;
6592 child = child->next;
6593 }
6594 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006595
Daniel Veillard4255d502002-04-16 15:50:10 +00006596 return (ret);
6597}
6598
6599/**
6600 * xmlSchemaParseFacet:
6601 * @ctxt: a schema validation context
6602 * @schema: the schema being built
6603 * @node: a subtree containing XML Schema informations
6604 *
6605 * parse a XML schema Facet declaration
6606 * *WARNING* this interface is highly subject to change
6607 *
6608 * Returns the new type structure or NULL in case of error
6609 */
6610static xmlSchemaFacetPtr
6611xmlSchemaParseFacet(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006612 xmlNodePtr node)
Daniel Veillard4255d502002-04-16 15:50:10 +00006613{
6614 xmlSchemaFacetPtr facet;
6615 xmlNodePtr child = NULL;
Daniel Veillardbe9c6322003-11-22 20:37:51 +00006616 const xmlChar *value;
Daniel Veillard4255d502002-04-16 15:50:10 +00006617
6618 if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
6619 return (NULL);
6620
Daniel Veillard8bc6cf92003-02-27 17:42:22 +00006621 facet = xmlSchemaNewFacet();
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006622 if (facet == NULL) {
6623 xmlSchemaPErrMemory(ctxt, "allocating facet", node);
6624 return (NULL);
6625 }
Daniel Veillard4255d502002-04-16 15:50:10 +00006626 facet->node = node;
Daniel Veillardbe9c6322003-11-22 20:37:51 +00006627 value = xmlSchemaGetProp(ctxt, node, "value");
Daniel Veillard4255d502002-04-16 15:50:10 +00006628 if (value == NULL) {
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006629 xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_FACET_NO_VALUE,
6630 "Facet %s has no value\n", node->name, NULL);
6631 xmlSchemaFreeFacet(facet);
Daniel Veillard4255d502002-04-16 15:50:10 +00006632 return (NULL);
6633 }
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006634 if (IS_SCHEMA(node, "minInclusive")) {
Daniel Veillard4255d502002-04-16 15:50:10 +00006635 facet->type = XML_SCHEMA_FACET_MININCLUSIVE;
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006636 } else if (IS_SCHEMA(node, "minExclusive")) {
Daniel Veillard4255d502002-04-16 15:50:10 +00006637 facet->type = XML_SCHEMA_FACET_MINEXCLUSIVE;
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006638 } else if (IS_SCHEMA(node, "maxInclusive")) {
Daniel Veillard4255d502002-04-16 15:50:10 +00006639 facet->type = XML_SCHEMA_FACET_MAXINCLUSIVE;
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006640 } else if (IS_SCHEMA(node, "maxExclusive")) {
Daniel Veillard4255d502002-04-16 15:50:10 +00006641 facet->type = XML_SCHEMA_FACET_MAXEXCLUSIVE;
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006642 } else if (IS_SCHEMA(node, "totalDigits")) {
Daniel Veillard4255d502002-04-16 15:50:10 +00006643 facet->type = XML_SCHEMA_FACET_TOTALDIGITS;
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006644 } else if (IS_SCHEMA(node, "fractionDigits")) {
Daniel Veillard4255d502002-04-16 15:50:10 +00006645 facet->type = XML_SCHEMA_FACET_FRACTIONDIGITS;
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006646 } else if (IS_SCHEMA(node, "pattern")) {
Daniel Veillard4255d502002-04-16 15:50:10 +00006647 facet->type = XML_SCHEMA_FACET_PATTERN;
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006648 } else if (IS_SCHEMA(node, "enumeration")) {
Daniel Veillard4255d502002-04-16 15:50:10 +00006649 facet->type = XML_SCHEMA_FACET_ENUMERATION;
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006650 } else if (IS_SCHEMA(node, "whiteSpace")) {
Daniel Veillard4255d502002-04-16 15:50:10 +00006651 facet->type = XML_SCHEMA_FACET_WHITESPACE;
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006652 } else if (IS_SCHEMA(node, "length")) {
Daniel Veillard4255d502002-04-16 15:50:10 +00006653 facet->type = XML_SCHEMA_FACET_LENGTH;
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006654 } else if (IS_SCHEMA(node, "maxLength")) {
Daniel Veillard4255d502002-04-16 15:50:10 +00006655 facet->type = XML_SCHEMA_FACET_MAXLENGTH;
6656 } else if (IS_SCHEMA(node, "minLength")) {
6657 facet->type = XML_SCHEMA_FACET_MINLENGTH;
6658 } else {
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006659 xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_UNKNOWN_FACET_TYPE,
6660 "Unknown facet type %s\n", node->name, NULL);
6661 xmlSchemaFreeFacet(facet);
6662 return (NULL);
Daniel Veillard4255d502002-04-16 15:50:10 +00006663 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006664 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
Daniel Veillard4255d502002-04-16 15:50:10 +00006665 facet->value = value;
Daniel Veillard01fa6152004-06-29 17:04:39 +00006666 if ((facet->type != XML_SCHEMA_FACET_PATTERN) &&
6667 (facet->type != XML_SCHEMA_FACET_ENUMERATION)) {
6668 const xmlChar *fixed;
6669
6670 fixed = xmlSchemaGetProp(ctxt, node, "fixed");
6671 if (fixed != NULL) {
6672 if (xmlStrEqual(fixed, BAD_CAST "true"))
6673 facet->fixed = 1;
6674 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006675 }
Daniel Veillard4255d502002-04-16 15:50:10 +00006676 child = node->children;
6677
6678 if (IS_SCHEMA(child, "annotation")) {
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +00006679 facet->annot = xmlSchemaParseAnnotation(ctxt, child, 1);
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006680 child = child->next;
Daniel Veillard4255d502002-04-16 15:50:10 +00006681 }
6682 if (child != NULL) {
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006683 xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_UNKNOWN_FACET_CHILD,
6684 "Facet %s has unexpected child content\n",
6685 node->name, NULL);
Daniel Veillard4255d502002-04-16 15:50:10 +00006686 }
6687 return (facet);
6688}
6689
6690/**
Daniel Veillardc0826a72004-08-10 14:17:33 +00006691 * xmlSchemaParseWildcardNs:
6692 * @ctxt: a schema parser context
6693 * @wildc: the wildcard, already created
6694 * @node: a subtree containing XML Schema informations
6695 *
6696 * Parses the attribute "processContents" and "namespace"
6697 * of a xsd:anyAttribute and xsd:any.
6698 * *WARNING* this interface is highly subject to change
6699 *
6700 * Returns 0 if everything goes fine, a positive error code
6701 * if something is not valid and -1 if an internal error occurs.
6702 */
6703static int
6704xmlSchemaParseWildcardNs(xmlSchemaParserCtxtPtr ctxt,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00006705 xmlSchemaPtr schema ATTRIBUTE_UNUSED,
Daniel Veillardc0826a72004-08-10 14:17:33 +00006706 xmlSchemaWildcardPtr wildc,
6707 xmlNodePtr node)
6708{
6709 const xmlChar *pc, *ns, *dictnsItem;
6710 int ret = 0;
6711 xmlChar *nsItem;
6712 xmlSchemaWildcardNsPtr tmp, lastNs = NULL;
6713 xmlAttrPtr attr;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006714
Daniel Veillardc0826a72004-08-10 14:17:33 +00006715 pc = xmlSchemaGetProp(ctxt, node, "processContents");
6716 if ((pc == NULL)
6717 || (xmlStrEqual(pc, (const xmlChar *) "strict"))) {
6718 wildc->processContents = XML_SCHEMAS_ANY_STRICT;
6719 } else if (xmlStrEqual(pc, (const xmlChar *) "skip")) {
6720 wildc->processContents = XML_SCHEMAS_ANY_SKIP;
6721 } else if (xmlStrEqual(pc, (const xmlChar *) "lax")) {
6722 wildc->processContents = XML_SCHEMAS_ANY_LAX;
6723 } else {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006724 xmlSchemaPSimpleTypeErr(ctxt,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00006725 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006726 NULL, node,
6727 NULL, "(strict | skip | lax)", pc,
Daniel Veillardc0826a72004-08-10 14:17:33 +00006728 NULL, NULL, NULL);
6729 wildc->processContents = XML_SCHEMAS_ANY_STRICT;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00006730 ret = XML_SCHEMAP_S4S_ATTR_INVALID_VALUE;
Daniel Veillardc0826a72004-08-10 14:17:33 +00006731 }
6732 /*
6733 * Build the namespace constraints.
6734 */
6735 attr = xmlSchemaGetPropNode(node, "namespace");
6736 ns = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +00006737 if ((attr == NULL) || (xmlStrEqual(ns, BAD_CAST "##any")))
Daniel Veillardc0826a72004-08-10 14:17:33 +00006738 wildc->any = 1;
6739 else if (xmlStrEqual(ns, BAD_CAST "##other")) {
6740 wildc->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006741 if (wildc->negNsSet == NULL) {
Daniel Veillardc0826a72004-08-10 14:17:33 +00006742 return (-1);
6743 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00006744 wildc->negNsSet->value = ctxt->targetNamespace;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006745 } else {
Daniel Veillardc0826a72004-08-10 14:17:33 +00006746 const xmlChar *end, *cur;
6747
6748 cur = ns;
6749 do {
6750 while (IS_BLANK_CH(*cur))
6751 cur++;
6752 end = cur;
6753 while ((*end != 0) && (!(IS_BLANK_CH(*end))))
6754 end++;
6755 if (end == cur)
6756 break;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006757 nsItem = xmlStrndup(cur, end - cur);
Daniel Veillardc0826a72004-08-10 14:17:33 +00006758 if ((xmlStrEqual(nsItem, BAD_CAST "##other")) ||
6759 (xmlStrEqual(nsItem, BAD_CAST "##any"))) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006760 xmlSchemaPSimpleTypeErr(ctxt,
Daniel Veillardc0826a72004-08-10 14:17:33 +00006761 XML_SCHEMAP_WILDCARD_INVALID_NS_MEMBER,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006762 NULL, (xmlNodePtr) attr,
6763 NULL,
6764 "((##any | ##other) | List of (xs:anyURI | "
6765 "(##targetNamespace | ##local)))",
Daniel Veillardc0826a72004-08-10 14:17:33 +00006766 nsItem, NULL, NULL, NULL);
6767 ret = XML_SCHEMAP_WILDCARD_INVALID_NS_MEMBER;
6768 } else {
6769 if (xmlStrEqual(nsItem, BAD_CAST "##targetNamespace")) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00006770 dictnsItem = ctxt->targetNamespace;
Daniel Veillardc0826a72004-08-10 14:17:33 +00006771 } else if (xmlStrEqual(nsItem, BAD_CAST "##local")) {
6772 dictnsItem = NULL;
6773 } else {
6774 /*
6775 * Validate the item (anyURI).
6776 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006777 xmlSchemaPValAttrNodeValue(ctxt, NULL, attr,
Daniel Veillardc0826a72004-08-10 14:17:33 +00006778 nsItem, xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI));
6779 dictnsItem = xmlDictLookup(ctxt->dict, nsItem, -1);
6780 }
6781 /*
6782 * Avoid dublicate namespaces.
6783 */
6784 tmp = wildc->nsSet;
6785 while (tmp != NULL) {
6786 if (dictnsItem == tmp->value)
6787 break;
6788 tmp = tmp->next;
6789 }
6790 if (tmp == NULL) {
6791 tmp = xmlSchemaNewWildcardNsConstraint(ctxt);
6792 if (tmp == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006793 xmlFree(nsItem);
Daniel Veillardc0826a72004-08-10 14:17:33 +00006794 return (-1);
6795 }
6796 tmp->value = dictnsItem;
6797 tmp->next = NULL;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006798 if (wildc->nsSet == NULL)
Daniel Veillardc0826a72004-08-10 14:17:33 +00006799 wildc->nsSet = tmp;
6800 else
6801 lastNs->next = tmp;
6802 lastNs = tmp;
6803 }
6804
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006805 }
Daniel Veillardc0826a72004-08-10 14:17:33 +00006806 xmlFree(nsItem);
6807 cur = end;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006808 } while (*cur != 0);
Daniel Veillardc0826a72004-08-10 14:17:33 +00006809 }
6810 return (ret);
6811}
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00006812
6813static int
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006814xmlSchemaPCheckParticleCorrect_2(xmlSchemaParserCtxtPtr ctxt,
6815 xmlSchemaParticlePtr item ATTRIBUTE_UNUSED,
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00006816 xmlNodePtr node,
6817 int minOccurs,
6818 int maxOccurs) {
6819
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00006820 if ((maxOccurs == 0) && ( minOccurs == 0))
6821 return (0);
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00006822 if (maxOccurs != UNBOUNDED) {
6823 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006824 * TODO: Maybe we should better not create the particle,
6825 * if min/max is invalid, since it could confuse the build of the
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00006826 * content model.
6827 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006828 /*
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00006829 * 3.9.6 Schema Component Constraint: Particle Correct
6830 *
6831 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006832 if (maxOccurs < 1) {
6833 /*
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00006834 * 2.2 {max occurs} must be greater than or equal to 1.
6835 */
6836 xmlSchemaPCustomAttrErr(ctxt,
6837 XML_SCHEMAP_P_PROPS_CORRECT_2_2,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00006838 NULL, NULL,
6839 xmlSchemaGetPropNode(node, "maxOccurs"),
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00006840 "The value must be greater than or equal to 1");
6841 return (XML_SCHEMAP_P_PROPS_CORRECT_2_2);
6842 } else if (minOccurs > maxOccurs) {
6843 /*
6844 * 2.1 {min occurs} must not be greater than {max occurs}.
6845 */
6846 xmlSchemaPCustomAttrErr(ctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006847 XML_SCHEMAP_P_PROPS_CORRECT_2_1,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00006848 NULL, NULL,
6849 xmlSchemaGetPropNode(node, "minOccurs"),
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00006850 "The value must not be greater than the value of 'maxOccurs'");
6851 return (XML_SCHEMAP_P_PROPS_CORRECT_2_1);
6852 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006853 }
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00006854 return (0);
6855}
6856
Daniel Veillardc0826a72004-08-10 14:17:33 +00006857/**
Daniel Veillard4255d502002-04-16 15:50:10 +00006858 * xmlSchemaParseAny:
6859 * @ctxt: a schema validation context
6860 * @schema: the schema being built
6861 * @node: a subtree containing XML Schema informations
6862 *
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00006863 * Parsea a XML schema <any> element. A particle and wildcard
6864 * will be created (except if minOccurs==maxOccurs==0, in this case
6865 * nothing will be created).
Daniel Veillard4255d502002-04-16 15:50:10 +00006866 * *WARNING* this interface is highly subject to change
6867 *
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00006868 * Returns the particle or NULL in case of error or if minOccurs==maxOccurs==0
Daniel Veillard4255d502002-04-16 15:50:10 +00006869 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00006870static xmlSchemaParticlePtr
Daniel Veillard4255d502002-04-16 15:50:10 +00006871xmlSchemaParseAny(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
6872 xmlNodePtr node)
6873{
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00006874 xmlSchemaParticlePtr particle;
Daniel Veillard4255d502002-04-16 15:50:10 +00006875 xmlNodePtr child = NULL;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00006876 xmlSchemaWildcardPtr wild;
6877 int min, max;
6878 xmlAttrPtr attr;
6879 xmlSchemaAnnotPtr annot = NULL;
Daniel Veillard4255d502002-04-16 15:50:10 +00006880
6881 if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
6882 return (NULL);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00006883 /*
6884 * Check for illegal attributes.
6885 */
6886 attr = node->properties;
6887 while (attr != NULL) {
6888 if (attr->ns == NULL) {
6889 if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
6890 (!xmlStrEqual(attr->name, BAD_CAST "minOccurs")) &&
6891 (!xmlStrEqual(attr->name, BAD_CAST "maxOccurs")) &&
6892 (!xmlStrEqual(attr->name, BAD_CAST "namespace")) &&
6893 (!xmlStrEqual(attr->name, BAD_CAST "processContents"))) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006894 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006895 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00006896 }
6897 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006898 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006899 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00006900 }
6901 attr = attr->next;
6902 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006903 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00006904 /*
6905 * minOccurs/maxOccurs.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006906 */
6907 max = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1,
6908 "(xs:nonNegativeInteger | unbounded)");
6909 min = xmlGetMinOccurs(ctxt, node, 0, -1, 1,
6910 "xs:nonNegativeInteger");
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00006911 xmlSchemaPCheckParticleCorrect_2(ctxt, NULL, node, min, max);
6912 /*
6913 * Create & parse the wildcard.
6914 */
6915 wild = xmlSchemaAddWildcard(ctxt, schema, XML_SCHEMA_TYPE_ANY, node);
6916 if (wild == NULL)
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00006917 return (NULL);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00006918 xmlSchemaParseWildcardNs(ctxt, schema, wild, node);
Kasimier T. Buchcik31113c72005-01-13 16:57:20 +00006919 /*
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00006920 * And now for the children...
Kasimier T. Buchcik31113c72005-01-13 16:57:20 +00006921 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006922 child = node->children;
Daniel Veillard4255d502002-04-16 15:50:10 +00006923 if (IS_SCHEMA(child, "annotation")) {
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +00006924 annot = xmlSchemaParseAnnotation(ctxt, child, 1);
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006925 child = child->next;
Daniel Veillard4255d502002-04-16 15:50:10 +00006926 }
6927 if (child != NULL) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00006928 xmlSchemaPContentErr(ctxt,
6929 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006930 NULL, node, child,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00006931 NULL, "(annotation?)");
Daniel Veillard4255d502002-04-16 15:50:10 +00006932 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00006933 /*
6934 * No component if minOccurs==maxOccurs==0.
6935 */
6936 if ((min == 0) && (max == 0)) {
6937 /* Don't free the wildcard, since it's already on the list. */
6938 return (NULL);
6939 }
6940 /*
6941 * Create the particle.
6942 */
Kasimier T. Buchcik4c0aa162006-02-20 14:47:08 +00006943 particle = xmlSchemaAddParticle(ctxt, node, min, max);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00006944 if (particle == NULL)
6945 return (NULL);
6946 particle->annot = annot;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00006947 particle->children = (xmlSchemaTreeItemPtr) wild;
Daniel Veillard4255d502002-04-16 15:50:10 +00006948
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00006949 return (particle);
Daniel Veillard4255d502002-04-16 15:50:10 +00006950}
6951
6952/**
6953 * xmlSchemaParseNotation:
6954 * @ctxt: a schema validation context
6955 * @schema: the schema being built
6956 * @node: a subtree containing XML Schema informations
6957 *
6958 * parse a XML schema Notation declaration
6959 *
6960 * Returns the new structure or NULL in case of error
6961 */
6962static xmlSchemaNotationPtr
6963xmlSchemaParseNotation(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006964 xmlNodePtr node)
Daniel Veillard4255d502002-04-16 15:50:10 +00006965{
Daniel Veillardbe9c6322003-11-22 20:37:51 +00006966 const xmlChar *name;
Daniel Veillard4255d502002-04-16 15:50:10 +00006967 xmlSchemaNotationPtr ret;
6968 xmlNodePtr child = NULL;
6969
6970 if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
6971 return (NULL);
Daniel Veillardbe9c6322003-11-22 20:37:51 +00006972 name = xmlSchemaGetProp(ctxt, node, "name");
Daniel Veillard4255d502002-04-16 15:50:10 +00006973 if (name == NULL) {
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006974 xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_NOTATION_NO_NAME,
6975 "Notation has no name\n", NULL, NULL);
Daniel Veillard4255d502002-04-16 15:50:10 +00006976 return (NULL);
6977 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006978 ret = xmlSchemaAddNotation(ctxt, schema, name,
6979 ctxt->targetNamespace, node);
6980 if (ret == NULL)
Daniel Veillard4255d502002-04-16 15:50:10 +00006981 return (NULL);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006982 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
Kasimier T. Buchcikff858ca2005-02-18 11:37:58 +00006983
Daniel Veillard4255d502002-04-16 15:50:10 +00006984 child = node->children;
6985 if (IS_SCHEMA(child, "annotation")) {
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +00006986 ret->annot = xmlSchemaParseAnnotation(ctxt, child, 1);
Daniel Veillardd0c9c322003-10-10 00:49:42 +00006987 child = child->next;
Daniel Veillard4255d502002-04-16 15:50:10 +00006988 }
6989 if (child != NULL) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00006990 xmlSchemaPContentErr(ctxt,
6991 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00006992 NULL, node, child,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00006993 NULL, "(annotation?)");
Daniel Veillard4255d502002-04-16 15:50:10 +00006994 }
6995
6996 return (ret);
6997}
6998
6999/**
7000 * xmlSchemaParseAnyAttribute:
7001 * @ctxt: a schema validation context
7002 * @schema: the schema being built
7003 * @node: a subtree containing XML Schema informations
7004 *
7005 * parse a XML schema AnyAttrribute declaration
7006 * *WARNING* this interface is highly subject to change
7007 *
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +00007008 * Returns a wildcard or NULL.
Daniel Veillard4255d502002-04-16 15:50:10 +00007009 */
Daniel Veillard3646d642004-06-02 19:19:14 +00007010static xmlSchemaWildcardPtr
Daniel Veillardd0c9c322003-10-10 00:49:42 +00007011xmlSchemaParseAnyAttribute(xmlSchemaParserCtxtPtr ctxt,
7012 xmlSchemaPtr schema, xmlNodePtr node)
Daniel Veillard4255d502002-04-16 15:50:10 +00007013{
Daniel Veillard3646d642004-06-02 19:19:14 +00007014 xmlSchemaWildcardPtr ret;
Daniel Veillard4255d502002-04-16 15:50:10 +00007015 xmlNodePtr child = NULL;
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +00007016 xmlAttrPtr attr;
Daniel Veillard4255d502002-04-16 15:50:10 +00007017
7018 if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
7019 return (NULL);
7020
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00007021 ret = xmlSchemaAddWildcard(ctxt, schema, XML_SCHEMA_TYPE_ANY_ATTRIBUTE,
7022 node);
Daniel Veillard4255d502002-04-16 15:50:10 +00007023 if (ret == NULL) {
7024 return (NULL);
7025 }
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +00007026 /*
7027 * Check for illegal attributes.
7028 */
7029 attr = node->properties;
7030 while (attr != NULL) {
7031 if (attr->ns == NULL) {
7032 if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
7033 (!xmlStrEqual(attr->name, BAD_CAST "namespace")) &&
7034 (!xmlStrEqual(attr->name, BAD_CAST "processContents"))) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007035 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007036 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +00007037 }
7038 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007039 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007040 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +00007041 }
7042 attr = attr->next;
7043 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007044 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +00007045 /*
7046 * Parse the namespace list.
7047 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007048 if (xmlSchemaParseWildcardNs(ctxt, schema, ret, node) != 0)
Daniel Veillardc0826a72004-08-10 14:17:33 +00007049 return (NULL);
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +00007050 /*
7051 * And now for the children...
7052 */
Daniel Veillard4255d502002-04-16 15:50:10 +00007053 child = node->children;
7054 if (IS_SCHEMA(child, "annotation")) {
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +00007055 ret->annot = xmlSchemaParseAnnotation(ctxt, child, 1);
Daniel Veillardd0c9c322003-10-10 00:49:42 +00007056 child = child->next;
Daniel Veillard4255d502002-04-16 15:50:10 +00007057 }
7058 if (child != NULL) {
Daniel Veillardc0826a72004-08-10 14:17:33 +00007059 xmlSchemaPContentErr(ctxt,
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +00007060 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007061 NULL, node, child,
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +00007062 NULL, "(annotation?)");
Daniel Veillard4255d502002-04-16 15:50:10 +00007063 }
7064
7065 return (ret);
7066}
7067
7068
7069/**
7070 * xmlSchemaParseAttribute:
7071 * @ctxt: a schema validation context
7072 * @schema: the schema being built
7073 * @node: a subtree containing XML Schema informations
7074 *
7075 * parse a XML schema Attrribute declaration
7076 * *WARNING* this interface is highly subject to change
7077 *
William M. Bracke7091952004-05-11 15:09:58 +00007078 * Returns the attribute declaration.
Daniel Veillard4255d502002-04-16 15:50:10 +00007079 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007080static xmlSchemaBasicItemPtr
7081xmlSchemaParseLocalAttribute(xmlSchemaParserCtxtPtr pctxt,
7082 xmlSchemaPtr schema,
7083 xmlNodePtr node,
7084 xmlSchemaItemListPtr uses,
7085 int parentType)
Daniel Veillard4255d502002-04-16 15:50:10 +00007086{
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007087 const xmlChar *attrValue, *name = NULL, *ns = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +00007088 xmlSchemaAttributeUsePtr use = NULL;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007089 xmlNodePtr child = NULL;
7090 xmlAttrPtr attr;
7091 const xmlChar *tmpNs = NULL, *tmpName = NULL, *defValue = NULL;
7092 int isRef = 0, occurs = XML_SCHEMAS_ATTR_USE_OPTIONAL;
7093 int nberrors, hasForm = 0, defValueType = 0;
7094
7095#define WXS_ATTR_DEF_VAL_DEFAULT 1
7096#define WXS_ATTR_DEF_VAL_FIXED 2
7097
7098 /*
7099 * 3.2.3 Constraints on XML Representations of Attribute Declarations
7100 */
7101
7102 if ((pctxt == NULL) || (schema == NULL) || (node == NULL))
7103 return (NULL);
7104 attr = xmlSchemaGetPropNode(node, "ref");
7105 if (attr != NULL) {
7106 if (xmlSchemaPValAttrNodeQName(pctxt, schema,
7107 NULL, attr, &tmpNs, &tmpName) != 0) {
7108 return (NULL);
7109 }
7110 if (xmlSchemaCheckReference(pctxt, schema, node, attr, tmpNs) != 0)
7111 return(NULL);
7112 isRef = 1;
7113 }
7114 nberrors = pctxt->nberrors;
7115 /*
7116 * Check for illegal attributes.
7117 */
7118 attr = node->properties;
7119 while (attr != NULL) {
7120 if (attr->ns == NULL) {
7121 if (isRef) {
7122 if (xmlStrEqual(attr->name, BAD_CAST "id")) {
7123 xmlSchemaPValAttrNodeID(pctxt, attr);
7124 goto attr_next;
7125 } else if (xmlStrEqual(attr->name, BAD_CAST "ref")) {
7126 goto attr_next;
7127 }
7128 } else {
7129 if (xmlStrEqual(attr->name, BAD_CAST "name")) {
7130 goto attr_next;
7131 } else if (xmlStrEqual(attr->name, BAD_CAST "id")) {
7132 xmlSchemaPValAttrNodeID(pctxt, attr);
7133 goto attr_next;
7134 } else if (xmlStrEqual(attr->name, BAD_CAST "type")) {
7135 xmlSchemaPValAttrNodeQName(pctxt, schema, NULL,
7136 attr, &tmpNs, &tmpName);
7137 goto attr_next;
7138 } else if (xmlStrEqual(attr->name, BAD_CAST "form")) {
7139 /*
7140 * Evaluate the target namespace
7141 */
Daniel Veillarddee23482008-04-11 12:58:43 +00007142 hasForm = 1;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007143 attrValue = xmlSchemaGetNodeContent(pctxt,
7144 (xmlNodePtr) attr);
7145 if (xmlStrEqual(attrValue, BAD_CAST "qualified")) {
7146 ns = pctxt->targetNamespace;
7147 } else if (!xmlStrEqual(attrValue, BAD_CAST "unqualified"))
7148 {
7149 xmlSchemaPSimpleTypeErr(pctxt,
7150 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
7151 NULL, (xmlNodePtr) attr,
7152 NULL, "(qualified | unqualified)",
7153 attrValue, NULL, NULL, NULL);
7154 }
7155 goto attr_next;
7156 }
7157 }
7158 if (xmlStrEqual(attr->name, BAD_CAST "use")) {
7159
7160 attrValue = xmlSchemaGetNodeContent(pctxt, (xmlNodePtr) attr);
7161 /* TODO: Maybe we need to normalize the value beforehand. */
7162 if (xmlStrEqual(attrValue, BAD_CAST "optional"))
7163 occurs = XML_SCHEMAS_ATTR_USE_OPTIONAL;
7164 else if (xmlStrEqual(attrValue, BAD_CAST "prohibited"))
7165 occurs = XML_SCHEMAS_ATTR_USE_PROHIBITED;
7166 else if (xmlStrEqual(attrValue, BAD_CAST "required"))
7167 occurs = XML_SCHEMAS_ATTR_USE_REQUIRED;
7168 else {
7169 xmlSchemaPSimpleTypeErr(pctxt,
7170 XML_SCHEMAP_INVALID_ATTR_USE,
7171 NULL, (xmlNodePtr) attr,
7172 NULL, "(optional | prohibited | required)",
7173 attrValue, NULL, NULL, NULL);
7174 }
7175 goto attr_next;
7176 } else if (xmlStrEqual(attr->name, BAD_CAST "default")) {
7177 /*
7178 * 3.2.3 : 1
7179 * default and fixed must not both be present.
7180 */
7181 if (defValue) {
7182 xmlSchemaPMutualExclAttrErr(pctxt,
7183 XML_SCHEMAP_SRC_ATTRIBUTE_1,
7184 NULL, attr, "default", "fixed");
7185 } else {
7186 defValue = xmlSchemaGetNodeContent(pctxt, (xmlNodePtr) attr);
7187 defValueType = WXS_ATTR_DEF_VAL_DEFAULT;
7188 }
7189 goto attr_next;
7190 } else if (xmlStrEqual(attr->name, BAD_CAST "fixed")) {
7191 /*
7192 * 3.2.3 : 1
7193 * default and fixed must not both be present.
7194 */
7195 if (defValue) {
7196 xmlSchemaPMutualExclAttrErr(pctxt,
7197 XML_SCHEMAP_SRC_ATTRIBUTE_1,
7198 NULL, attr, "default", "fixed");
7199 } else {
7200 defValue = xmlSchemaGetNodeContent(pctxt, (xmlNodePtr) attr);
7201 defValueType = WXS_ATTR_DEF_VAL_FIXED;
7202 }
7203 goto attr_next;
7204 }
7205 } else if (! xmlStrEqual(attr->ns->href, xmlSchemaNs))
7206 goto attr_next;
7207
7208 xmlSchemaPIllegalAttrErr(pctxt,
7209 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
7210
7211attr_next:
7212 attr = attr->next;
Daniel Veillarddee23482008-04-11 12:58:43 +00007213 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007214 /*
7215 * 3.2.3 : 2
7216 * If default and use are both present, use must have
7217 * the actual value optional.
7218 */
7219 if ((defValueType == WXS_ATTR_DEF_VAL_DEFAULT) &&
7220 (occurs != XML_SCHEMAS_ATTR_USE_OPTIONAL)) {
7221 xmlSchemaPSimpleTypeErr(pctxt,
7222 XML_SCHEMAP_SRC_ATTRIBUTE_2,
7223 NULL, node, NULL,
7224 "(optional | prohibited | required)", NULL,
7225 "The value of the attribute 'use' must be 'optional' "
7226 "if the attribute 'default' is present",
7227 NULL, NULL);
7228 }
7229 /*
7230 * We want correct attributes.
7231 */
7232 if (nberrors != pctxt->nberrors)
7233 return(NULL);
7234 if (! isRef) {
7235 xmlSchemaAttributePtr attrDecl;
7236
7237 /* TODO: move XML_SCHEMAS_QUALIF_ATTR to the parser. */
7238 if ((! hasForm) && (schema->flags & XML_SCHEMAS_QUALIF_ATTR))
Daniel Veillarddee23482008-04-11 12:58:43 +00007239 ns = pctxt->targetNamespace;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007240 /*
7241 * 3.2.6 Schema Component Constraint: xsi: Not Allowed
7242 * TODO: Move this to the component layer.
7243 */
7244 if (xmlStrEqual(ns, xmlSchemaInstanceNs)) {
7245 xmlSchemaCustomErr(ACTXT_CAST pctxt,
7246 XML_SCHEMAP_NO_XSI,
7247 node, NULL,
7248 "The target namespace must not match '%s'",
7249 xmlSchemaInstanceNs, NULL);
7250 }
7251 attr = xmlSchemaGetPropNode(node, "name");
7252 if (attr == NULL) {
7253 xmlSchemaPMissingAttrErr(pctxt, XML_SCHEMAP_S4S_ATTR_MISSING,
7254 NULL, node, "name", NULL);
7255 return (NULL);
7256 }
7257 if (xmlSchemaPValAttrNode(pctxt, NULL, attr,
7258 xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) {
7259 return (NULL);
7260 }
7261 /*
7262 * 3.2.6 Schema Component Constraint: xmlns Not Allowed
7263 * TODO: Move this to the component layer.
7264 */
7265 if (xmlStrEqual(name, BAD_CAST "xmlns")) {
7266 xmlSchemaPSimpleTypeErr(pctxt,
7267 XML_SCHEMAP_NO_XMLNS,
7268 NULL, (xmlNodePtr) attr,
7269 xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), NULL, NULL,
7270 "The value of the attribute must not match 'xmlns'",
7271 NULL, NULL);
7272 return (NULL);
7273 }
7274 if (occurs == XML_SCHEMAS_ATTR_USE_PROHIBITED)
7275 goto check_children;
7276 /*
7277 * Create the attribute use component.
7278 */
7279 use = xmlSchemaAddAttributeUse(pctxt, node);
7280 if (use == NULL)
7281 return(NULL);
7282 use->occurs = occurs;
7283 /*
7284 * Create the attribute declaration.
7285 */
7286 attrDecl = xmlSchemaAddAttribute(pctxt, schema, name, ns, node, 0);
7287 if (attrDecl == NULL)
7288 return (NULL);
7289 if (tmpName != NULL) {
7290 attrDecl->typeName = tmpName;
7291 attrDecl->typeNs = tmpNs;
7292 }
7293 use->attrDecl = attrDecl;
7294 /*
7295 * Value constraint.
Daniel Veillarddee23482008-04-11 12:58:43 +00007296 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007297 if (defValue != NULL) {
7298 attrDecl->defValue = defValue;
7299 if (defValueType == WXS_ATTR_DEF_VAL_FIXED)
7300 attrDecl->flags |= XML_SCHEMAS_ATTR_FIXED;
7301 }
7302 } else if (occurs != XML_SCHEMAS_ATTR_USE_PROHIBITED) {
7303 xmlSchemaQNameRefPtr ref;
7304
7305 /*
7306 * Create the attribute use component.
7307 */
7308 use = xmlSchemaAddAttributeUse(pctxt, node);
7309 if (use == NULL)
7310 return(NULL);
7311 /*
7312 * We need to resolve the reference at later stage.
7313 */
7314 WXS_ADD_PENDING(pctxt, use);
7315 use->occurs = occurs;
7316 /*
7317 * Create a QName reference to the attribute declaration.
7318 */
7319 ref = xmlSchemaNewQNameRef(pctxt, XML_SCHEMA_TYPE_ATTRIBUTE,
7320 tmpName, tmpNs);
7321 if (ref == NULL)
7322 return(NULL);
7323 /*
7324 * Assign the reference. This will be substituted for the
7325 * referenced attribute declaration when the QName is resolved.
7326 */
7327 use->attrDecl = WXS_ATTR_CAST ref;
7328 /*
7329 * Value constraint.
7330 */
7331 if (defValue != NULL)
7332 use->defValue = defValue;
7333 if (defValueType == WXS_ATTR_DEF_VAL_FIXED)
7334 use->flags |= XML_SCHEMA_ATTR_USE_FIXED;
7335 }
Daniel Veillarddee23482008-04-11 12:58:43 +00007336
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007337check_children:
7338 /*
7339 * And now for the children...
7340 */
7341 child = node->children;
7342 if (occurs == XML_SCHEMAS_ATTR_USE_PROHIBITED) {
Daniel Veillarddee23482008-04-11 12:58:43 +00007343 xmlSchemaAttributeUseProhibPtr prohib;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007344
7345 if (IS_SCHEMA(child, "annotation")) {
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +00007346 xmlSchemaParseAnnotation(pctxt, child, 0);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007347 child = child->next;
7348 }
7349 if (child != NULL) {
7350 xmlSchemaPContentErr(pctxt,
7351 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
7352 NULL, node, child, NULL,
7353 "(annotation?)");
7354 }
7355 /*
7356 * Check for pointlessness of attribute prohibitions.
7357 */
Daniel Veillarddee23482008-04-11 12:58:43 +00007358 if (parentType == XML_SCHEMA_TYPE_ATTRIBUTEGROUP) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007359 xmlSchemaCustomWarning(ACTXT_CAST pctxt,
7360 XML_SCHEMAP_WARN_ATTR_POINTLESS_PROH,
7361 node, NULL,
7362 "Skipping attribute use prohibition, since it is "
7363 "pointless inside an <attributeGroup>",
7364 NULL, NULL, NULL);
7365 return(NULL);
7366 } else if (parentType == XML_SCHEMA_TYPE_EXTENSION) {
7367 xmlSchemaCustomWarning(ACTXT_CAST pctxt,
7368 XML_SCHEMAP_WARN_ATTR_POINTLESS_PROH,
7369 node, NULL,
7370 "Skipping attribute use prohibition, since it is "
7371 "pointless when extending a type",
7372 NULL, NULL, NULL);
7373 return(NULL);
7374 }
7375 if (! isRef) {
Daniel Veillarddee23482008-04-11 12:58:43 +00007376 tmpName = name;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007377 tmpNs = ns;
7378 }
7379 /*
7380 * Check for duplicate attribute prohibitions.
7381 */
7382 if (uses) {
7383 int i;
Daniel Veillarddee23482008-04-11 12:58:43 +00007384
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007385 for (i = 0; i < uses->nbItems; i++) {
7386 use = uses->items[i];
7387 if ((use->type == XML_SCHEMA_EXTRA_ATTR_USE_PROHIB) &&
7388 (tmpName == (WXS_ATTR_PROHIB_CAST use)->name) &&
7389 (tmpNs == (WXS_ATTR_PROHIB_CAST use)->targetNamespace))
7390 {
7391 xmlChar *str = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +00007392
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007393 xmlSchemaCustomWarning(ACTXT_CAST pctxt,
7394 XML_SCHEMAP_WARN_ATTR_POINTLESS_PROH,
7395 node, NULL,
7396 "Skipping duplicate attribute use prohibition '%s'",
7397 xmlSchemaFormatQName(&str, tmpNs, tmpName),
7398 NULL, NULL);
Daniel Veillarddee23482008-04-11 12:58:43 +00007399 FREE_AND_NULL(str)
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007400 return(NULL);
Daniel Veillarddee23482008-04-11 12:58:43 +00007401 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007402 }
7403 }
7404 /*
7405 * Create the attribute prohibition helper component.
7406 */
7407 prohib = xmlSchemaAddAttributeUseProhib(pctxt);
7408 if (prohib == NULL)
7409 return(NULL);
7410 prohib->node = node;
7411 prohib->name = tmpName;
7412 prohib->targetNamespace = tmpNs;
7413 if (isRef) {
7414 /*
7415 * We need at least to resolve to the attribute declaration.
7416 */
7417 WXS_ADD_PENDING(pctxt, prohib);
7418 }
7419 return(WXS_BASIC_CAST prohib);
Daniel Veillarddee23482008-04-11 12:58:43 +00007420 } else {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007421 if (IS_SCHEMA(child, "annotation")) {
7422 /*
7423 * TODO: Should this go into the attr decl?
7424 */
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +00007425 use->annot = xmlSchemaParseAnnotation(pctxt, child, 1);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007426 child = child->next;
7427 }
7428 if (isRef) {
7429 if (child != NULL) {
7430 if (IS_SCHEMA(child, "simpleType"))
7431 /*
7432 * 3.2.3 : 3.2
7433 * If ref is present, then all of <simpleType>,
7434 * form and type must be absent.
7435 */
7436 xmlSchemaPContentErr(pctxt,
7437 XML_SCHEMAP_SRC_ATTRIBUTE_3_2,
7438 NULL, node, child, NULL,
7439 "(annotation?)");
7440 else
7441 xmlSchemaPContentErr(pctxt,
7442 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
7443 NULL, node, child, NULL,
7444 "(annotation?)");
7445 }
7446 } else {
7447 if (IS_SCHEMA(child, "simpleType")) {
7448 if (WXS_ATTRUSE_DECL(use)->typeName != NULL) {
7449 /*
7450 * 3.2.3 : 4
7451 * type and <simpleType> must not both be present.
7452 */
7453 xmlSchemaPContentErr(pctxt, XML_SCHEMAP_SRC_ATTRIBUTE_4,
7454 NULL, node, child,
7455 "The attribute 'type' and the <simpleType> child "
7456 "are mutually exclusive", NULL);
7457 } else
7458 WXS_ATTRUSE_TYPEDEF(use) =
7459 xmlSchemaParseSimpleType(pctxt, schema, child, 0);
7460 child = child->next;
7461 }
7462 if (child != NULL)
7463 xmlSchemaPContentErr(pctxt, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
7464 NULL, node, child, NULL,
7465 "(annotation?, simpleType?)");
7466 }
Daniel Veillarddee23482008-04-11 12:58:43 +00007467 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007468 return (WXS_BASIC_CAST use);
7469}
7470
7471
7472static xmlSchemaAttributePtr
7473xmlSchemaParseGlobalAttribute(xmlSchemaParserCtxtPtr pctxt,
7474 xmlSchemaPtr schema,
7475 xmlNodePtr node)
7476{
7477 const xmlChar *attrValue;
Daniel Veillard4255d502002-04-16 15:50:10 +00007478 xmlSchemaAttributePtr ret;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007479 xmlNodePtr child = NULL;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007480 xmlAttrPtr attr;
William M. Bracke7091952004-05-11 15:09:58 +00007481
7482 /*
7483 * Note that the w3c spec assumes the schema to be validated with schema
7484 * for schemas beforehand.
7485 *
7486 * 3.2.3 Constraints on XML Representations of Attribute Declarations
William M. Bracke7091952004-05-11 15:09:58 +00007487 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007488 if ((pctxt == NULL) || (schema == NULL) || (node == NULL))
Daniel Veillarddee23482008-04-11 12:58:43 +00007489 return (NULL);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007490 /*
7491 * 3.2.3 : 3.1
7492 * One of ref or name must be present, but not both
7493 */
7494 attr = xmlSchemaGetPropNode(node, "name");
7495 if (attr == NULL) {
7496 xmlSchemaPMissingAttrErr(pctxt, XML_SCHEMAP_S4S_ATTR_MISSING,
7497 NULL, node, "name", NULL);
Daniel Veillardc0826a72004-08-10 14:17:33 +00007498 return (NULL);
7499 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007500 if (xmlSchemaPValAttrNode(pctxt, NULL, attr,
7501 xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &attrValue) != 0) {
7502 return (NULL);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007503 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007504 /*
7505 * 3.2.6 Schema Component Constraint: xmlns Not Allowed
7506 * TODO: Move this to the component layer.
7507 */
7508 if (xmlStrEqual(attrValue, BAD_CAST "xmlns")) {
7509 xmlSchemaPSimpleTypeErr(pctxt,
7510 XML_SCHEMAP_NO_XMLNS,
7511 NULL, (xmlNodePtr) attr,
7512 xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), NULL, NULL,
7513 "The value of the attribute must not match 'xmlns'",
7514 NULL, NULL);
7515 return (NULL);
7516 }
7517 /*
7518 * 3.2.6 Schema Component Constraint: xsi: Not Allowed
7519 * TODO: Move this to the component layer.
7520 * Or better leave it here and add it to the component layer
7521 * if we have a schema construction API.
7522 */
7523 if (xmlStrEqual(pctxt->targetNamespace, xmlSchemaInstanceNs)) {
7524 xmlSchemaCustomErr(ACTXT_CAST pctxt,
7525 XML_SCHEMAP_NO_XSI, node, NULL,
7526 "The target namespace must not match '%s'",
7527 xmlSchemaInstanceNs, NULL);
7528 }
7529
7530 ret = xmlSchemaAddAttribute(pctxt, schema, attrValue,
7531 pctxt->targetNamespace, node, 1);
7532 if (ret == NULL)
7533 return (NULL);
7534 ret->flags |= XML_SCHEMAS_ATTR_GLOBAL;
Daniel Veillarddee23482008-04-11 12:58:43 +00007535
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007536 /*
7537 * Check for illegal attributes.
7538 */
7539 attr = node->properties;
7540 while (attr != NULL) {
7541 if (attr->ns == NULL) {
7542 if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
7543 (!xmlStrEqual(attr->name, BAD_CAST "default")) &&
7544 (!xmlStrEqual(attr->name, BAD_CAST "fixed")) &&
7545 (!xmlStrEqual(attr->name, BAD_CAST "name")) &&
7546 (!xmlStrEqual(attr->name, BAD_CAST "type")))
7547 {
7548 xmlSchemaPIllegalAttrErr(pctxt,
Daniel Veillarddee23482008-04-11 12:58:43 +00007549 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007550 }
7551 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
7552 xmlSchemaPIllegalAttrErr(pctxt,
7553 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
7554 }
7555 attr = attr->next;
7556 }
7557 xmlSchemaPValAttrQName(pctxt, schema, NULL,
7558 node, "type", &ret->typeNs, &ret->typeName);
Daniel Veillarddee23482008-04-11 12:58:43 +00007559
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007560 xmlSchemaPValAttrID(pctxt, node, BAD_CAST "id");
William M. Bracke7091952004-05-11 15:09:58 +00007561 /*
Daniel Veillardc0826a72004-08-10 14:17:33 +00007562 * Attribute "fixed".
William M. Bracke7091952004-05-11 15:09:58 +00007563 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007564 ret->defValue = xmlSchemaGetProp(pctxt, node, "fixed");
Daniel Veillardc0826a72004-08-10 14:17:33 +00007565 if (ret->defValue != NULL)
7566 ret->flags |= XML_SCHEMAS_ATTR_FIXED;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007567 /*
Daniel Veillardc0826a72004-08-10 14:17:33 +00007568 * Attribute "default".
7569 */
7570 attr = xmlSchemaGetPropNode(node, "default");
7571 if (attr != NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007572 /*
Daniel Veillardc0826a72004-08-10 14:17:33 +00007573 * 3.2.3 : 1
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007574 * default and fixed must not both be present.
Daniel Veillardc0826a72004-08-10 14:17:33 +00007575 */
7576 if (ret->flags & XML_SCHEMAS_ATTR_FIXED) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007577 xmlSchemaPMutualExclAttrErr(pctxt, XML_SCHEMAP_SRC_ATTRIBUTE_1,
7578 WXS_BASIC_CAST ret, attr, "default", "fixed");
Daniel Veillardc0826a72004-08-10 14:17:33 +00007579 } else
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007580 ret->defValue = xmlSchemaGetNodeContent(pctxt, (xmlNodePtr) attr);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007581 }
Daniel Veillardc0826a72004-08-10 14:17:33 +00007582 /*
7583 * And now for the children...
7584 */
Daniel Veillard4255d502002-04-16 15:50:10 +00007585 child = node->children;
7586 if (IS_SCHEMA(child, "annotation")) {
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +00007587 ret->annot = xmlSchemaParseAnnotation(pctxt, child, 1);
Daniel Veillardd0c9c322003-10-10 00:49:42 +00007588 child = child->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007589 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007590 if (IS_SCHEMA(child, "simpleType")) {
7591 if (ret->typeName != NULL) {
7592 /*
7593 * 3.2.3 : 4
7594 * type and <simpleType> must not both be present.
7595 */
7596 xmlSchemaPContentErr(pctxt, XML_SCHEMAP_SRC_ATTRIBUTE_4,
7597 NULL, node, child,
7598 "The attribute 'type' and the <simpleType> child "
7599 "are mutually exclusive", NULL);
7600 } else
7601 ret->subtypes = xmlSchemaParseSimpleType(pctxt, schema, child, 0);
7602 child = child->next;
Daniel Veillard4255d502002-04-16 15:50:10 +00007603 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007604 if (child != NULL)
7605 xmlSchemaPContentErr(pctxt, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
7606 NULL, node, child, NULL,
7607 "(annotation?, simpleType?)");
7608
Daniel Veillard4255d502002-04-16 15:50:10 +00007609 return (ret);
7610}
7611
7612/**
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007613 * xmlSchemaParseAttributeGroupRef:
Daniel Veillard4255d502002-04-16 15:50:10 +00007614 * @ctxt: a schema validation context
7615 * @schema: the schema being built
7616 * @node: a subtree containing XML Schema informations
7617 *
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007618 * Parse an attribute group definition reference.
7619 * Note that a reference to an attribute group does not
7620 * correspond to any component at all.
Daniel Veillard4255d502002-04-16 15:50:10 +00007621 * *WARNING* this interface is highly subject to change
7622 *
7623 * Returns the attribute group or NULL in case of error.
7624 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007625static xmlSchemaQNameRefPtr
7626xmlSchemaParseAttributeGroupRef(xmlSchemaParserCtxtPtr pctxt,
7627 xmlSchemaPtr schema,
7628 xmlNodePtr node)
Daniel Veillard4255d502002-04-16 15:50:10 +00007629{
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007630 xmlSchemaQNameRefPtr ret;
Daniel Veillard4255d502002-04-16 15:50:10 +00007631 xmlNodePtr child = NULL;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007632 xmlAttrPtr attr;
7633 const xmlChar *refNs = NULL, *ref = NULL;
Daniel Veillard4255d502002-04-16 15:50:10 +00007634
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007635 if ((pctxt == NULL) || (schema == NULL) || (node == NULL))
Daniel Veillard4255d502002-04-16 15:50:10 +00007636 return (NULL);
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +00007637
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007638 attr = xmlSchemaGetPropNode(node, "ref");
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007639 if (attr == NULL) {
7640 xmlSchemaPMissingAttrErr(pctxt,
7641 XML_SCHEMAP_S4S_ATTR_MISSING,
7642 NULL, node, "ref", NULL);
7643 return (NULL);
Daniel Veillarddee23482008-04-11 12:58:43 +00007644 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007645 xmlSchemaPValAttrNodeQName(pctxt, schema,
7646 NULL, attr, &refNs, &ref);
7647 if (xmlSchemaCheckReference(pctxt, schema, node, attr, refNs) != 0)
7648 return(NULL);
Daniel Veillarddee23482008-04-11 12:58:43 +00007649
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +00007650 /*
7651 * Check for illegal attributes.
7652 */
7653 attr = node->properties;
7654 while (attr != NULL) {
7655 if (attr->ns == NULL) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007656 if ((!xmlStrEqual(attr->name, BAD_CAST "ref")) &&
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007657 (!xmlStrEqual(attr->name, BAD_CAST "id")))
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +00007658 {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007659 xmlSchemaPIllegalAttrErr(pctxt,
7660 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +00007661 }
7662 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007663 xmlSchemaPIllegalAttrErr(pctxt,
7664 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +00007665 }
7666 attr = attr->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007667 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00007668 /* Attribute ID */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007669 xmlSchemaPValAttrID(pctxt, node, BAD_CAST "id");
7670
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +00007671 /*
7672 * And now for the children...
7673 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007674 child = node->children;
Daniel Veillard4255d502002-04-16 15:50:10 +00007675 if (IS_SCHEMA(child, "annotation")) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007676 /*
7677 * TODO: We do not have a place to store the annotation, do we?
7678 */
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +00007679 xmlSchemaParseAnnotation(pctxt, child, 0);
Daniel Veillardd0c9c322003-10-10 00:49:42 +00007680 child = child->next;
Daniel Veillard4255d502002-04-16 15:50:10 +00007681 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007682 if (child != NULL) {
7683 xmlSchemaPContentErr(pctxt,
7684 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
7685 NULL, node, child, NULL,
7686 "(annotation?)");
7687 }
7688
7689 /*
7690 * Handle attribute group redefinitions.
7691 */
7692 if (pctxt->isRedefine && pctxt->redef &&
7693 (pctxt->redef->item->type ==
7694 XML_SCHEMA_TYPE_ATTRIBUTEGROUP) &&
7695 (ref == pctxt->redef->refName) &&
7696 (refNs == pctxt->redef->refTargetNs))
7697 {
7698 /*
7699 * SPEC src-redefine:
7700 * (7.1) "If it has an <attributeGroup> among its contents
Rob Richardsc6947bb2008-06-29 15:04:41 +00007701 * the �actual value� of whose ref [attribute] is the same
7702 * as the �actual value� of its own name attribute plus
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007703 * target namespace, then it must have exactly one such group."
7704 */
7705 if (pctxt->redefCounter != 0) {
7706 xmlChar *str = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +00007707
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007708 xmlSchemaCustomErr(ACTXT_CAST pctxt,
7709 XML_SCHEMAP_SRC_REDEFINE, node, NULL,
7710 "The redefining attribute group definition "
7711 "'%s' must not contain more than one "
7712 "reference to the redefined definition",
7713 xmlSchemaFormatQName(&str, refNs, ref), NULL);
7714 FREE_AND_NULL(str);
7715 return(NULL);
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +00007716 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007717 pctxt->redefCounter++;
7718 /*
7719 * URGENT TODO: How to ensure that the reference will not be
7720 * handled by the normal component resolution mechanism?
7721 */
7722 ret = xmlSchemaNewQNameRef(pctxt,
7723 XML_SCHEMA_TYPE_ATTRIBUTEGROUP, ref, refNs);
7724 if (ret == NULL)
7725 return(NULL);
7726 ret->node = node;
7727 pctxt->redef->reference = WXS_BASIC_CAST ret;
7728 } else {
7729 /*
7730 * Create a QName-reference helper component. We will substitute this
7731 * component for the attribute uses of the referenced attribute group
7732 * definition.
7733 */
7734 ret = xmlSchemaNewQNameRef(pctxt,
7735 XML_SCHEMA_TYPE_ATTRIBUTEGROUP, ref, refNs);
7736 if (ret == NULL)
7737 return(NULL);
7738 ret->node = node;
7739 /* Add to pending items, to be able to resolve the reference. */
7740 WXS_ADD_PENDING(pctxt, ret);
Daniel Veillarddee23482008-04-11 12:58:43 +00007741 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007742 return (ret);
7743}
7744
7745/**
7746 * xmlSchemaParseAttributeGroupDefinition:
7747 * @pctxt: a schema validation context
7748 * @schema: the schema being built
7749 * @node: a subtree containing XML Schema informations
7750 *
7751 * parse a XML schema Attribute Group declaration
7752 * *WARNING* this interface is highly subject to change
7753 *
7754 * Returns the attribute group definition or NULL in case of error.
7755 */
7756static xmlSchemaAttributeGroupPtr
7757xmlSchemaParseAttributeGroupDefinition(xmlSchemaParserCtxtPtr pctxt,
7758 xmlSchemaPtr schema,
7759 xmlNodePtr node)
7760{
7761 const xmlChar *name;
7762 xmlSchemaAttributeGroupPtr ret;
7763 xmlNodePtr child = NULL;
7764 xmlAttrPtr attr;
7765 int hasRefs = 0;
7766
7767 if ((pctxt == NULL) || (schema == NULL) || (node == NULL))
7768 return (NULL);
7769
7770 attr = xmlSchemaGetPropNode(node, "name");
7771 if (attr == NULL) {
7772 xmlSchemaPMissingAttrErr(pctxt,
7773 XML_SCHEMAP_S4S_ATTR_MISSING,
7774 NULL, node, "name", NULL);
7775 return (NULL);
7776 }
7777 /*
7778 * The name is crucial, exit if invalid.
7779 */
7780 if (xmlSchemaPValAttrNode(pctxt,
7781 NULL, attr,
7782 xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) {
7783 return (NULL);
7784 }
7785 ret = xmlSchemaAddAttributeGroupDefinition(pctxt, schema,
7786 name, pctxt->targetNamespace, node);
7787 if (ret == NULL)
Daniel Veillarddee23482008-04-11 12:58:43 +00007788 return (NULL);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007789 /*
7790 * Check for illegal attributes.
7791 */
7792 attr = node->properties;
7793 while (attr != NULL) {
7794 if (attr->ns == NULL) {
7795 if ((!xmlStrEqual(attr->name, BAD_CAST "name")) &&
7796 (!xmlStrEqual(attr->name, BAD_CAST "id")))
7797 {
7798 xmlSchemaPIllegalAttrErr(pctxt,
7799 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
7800 }
7801 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
7802 xmlSchemaPIllegalAttrErr(pctxt,
7803 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
7804 }
7805 attr = attr->next;
7806 }
7807 /* Attribute ID */
7808 xmlSchemaPValAttrID(pctxt, node, BAD_CAST "id");
7809 /*
7810 * And now for the children...
7811 */
7812 child = node->children;
7813 if (IS_SCHEMA(child, "annotation")) {
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +00007814 ret->annot = xmlSchemaParseAnnotation(pctxt, child, 1);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007815 child = child->next;
7816 }
7817 /*
7818 * Parse contained attribute decls/refs.
7819 */
7820 if (xmlSchemaParseLocalAttributes(pctxt, schema, &child,
7821 (xmlSchemaItemListPtr *) &(ret->attrUses),
7822 XML_SCHEMA_TYPE_ATTRIBUTEGROUP, &hasRefs) == -1)
7823 return(NULL);
7824 if (hasRefs)
7825 ret->flags |= XML_SCHEMAS_ATTRGROUP_HAS_REFS;
7826 /*
7827 * Parse the attribute wildcard.
7828 */
7829 if (IS_SCHEMA(child, "anyAttribute")) {
7830 ret->attributeWildcard = xmlSchemaParseAnyAttribute(pctxt,
7831 schema, child);
7832 child = child->next;
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +00007833 }
Daniel Veillard4255d502002-04-16 15:50:10 +00007834 if (child != NULL) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007835 xmlSchemaPContentErr(pctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007836 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00007837 NULL, node, child, NULL,
7838 "(annotation?, ((attribute | attributeGroup)*, anyAttribute?))");
Daniel Veillard4255d502002-04-16 15:50:10 +00007839 }
Daniel Veillard4255d502002-04-16 15:50:10 +00007840 return (ret);
7841}
7842
7843/**
William M. Brack2f2a6632004-08-20 23:09:47 +00007844 * xmlSchemaPValAttrFormDefault:
7845 * @value: the value
7846 * @flags: the flags to be modified
7847 * @flagQualified: the specific flag for "qualified"
7848 *
7849 * Returns 0 if the value is valid, 1 otherwise.
7850 */
7851static int
7852xmlSchemaPValAttrFormDefault(const xmlChar *value,
7853 int *flags,
7854 int flagQualified)
7855{
7856 if (xmlStrEqual(value, BAD_CAST "qualified")) {
7857 if ((*flags & flagQualified) == 0)
7858 *flags |= flagQualified;
7859 } else if (!xmlStrEqual(value, BAD_CAST "unqualified"))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007860 return (1);
7861
William M. Brack2f2a6632004-08-20 23:09:47 +00007862 return (0);
7863}
7864
7865/**
Daniel Veillardc0826a72004-08-10 14:17:33 +00007866 * xmlSchemaPValAttrBlockFinal:
7867 * @value: the value
7868 * @flags: the flags to be modified
7869 * @flagAll: the specific flag for "#all"
7870 * @flagExtension: the specific flag for "extension"
7871 * @flagRestriction: the specific flag for "restriction"
7872 * @flagSubstitution: the specific flag for "substitution"
7873 * @flagList: the specific flag for "list"
7874 * @flagUnion: the specific flag for "union"
7875 *
7876 * Validates the value of the attribute "final" and "block". The value
7877 * is converted into the specified flag values and returned in @flags.
7878 *
7879 * Returns 0 if the value is valid, 1 otherwise.
7880 */
7881
7882static int
7883xmlSchemaPValAttrBlockFinal(const xmlChar *value,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007884 int *flags,
Daniel Veillardc0826a72004-08-10 14:17:33 +00007885 int flagAll,
7886 int flagExtension,
7887 int flagRestriction,
7888 int flagSubstitution,
7889 int flagList,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007890 int flagUnion)
Daniel Veillardc0826a72004-08-10 14:17:33 +00007891{
7892 int ret = 0;
7893
7894 /*
7895 * TODO: This does not check for dublicate entries.
7896 */
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +00007897 if ((flags == NULL) || (value == NULL))
7898 return (-1);
7899 if (value[0] == 0)
7900 return (0);
Daniel Veillardc0826a72004-08-10 14:17:33 +00007901 if (xmlStrEqual(value, BAD_CAST "#all")) {
7902 if (flagAll != -1)
7903 *flags |= flagAll;
7904 else {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007905 if (flagExtension != -1)
7906 *flags |= flagExtension;
7907 if (flagRestriction != -1)
Daniel Veillardc0826a72004-08-10 14:17:33 +00007908 *flags |= flagRestriction;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007909 if (flagSubstitution != -1)
Daniel Veillardc0826a72004-08-10 14:17:33 +00007910 *flags |= flagSubstitution;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007911 if (flagList != -1)
Daniel Veillardc0826a72004-08-10 14:17:33 +00007912 *flags |= flagList;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007913 if (flagUnion != -1)
Daniel Veillardc0826a72004-08-10 14:17:33 +00007914 *flags |= flagUnion;
7915 }
7916 } else {
7917 const xmlChar *end, *cur = value;
7918 xmlChar *item;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007919
Daniel Veillardc0826a72004-08-10 14:17:33 +00007920 do {
7921 while (IS_BLANK_CH(*cur))
7922 cur++;
7923 end = cur;
7924 while ((*end != 0) && (!(IS_BLANK_CH(*end))))
7925 end++;
7926 if (end == cur)
7927 break;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007928 item = xmlStrndup(cur, end - cur);
Daniel Veillardc0826a72004-08-10 14:17:33 +00007929 if (xmlStrEqual(item, BAD_CAST "extension")) {
7930 if (flagExtension != -1) {
7931 if ((*flags & flagExtension) == 0)
7932 *flags |= flagExtension;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007933 } else
Daniel Veillardc0826a72004-08-10 14:17:33 +00007934 ret = 1;
7935 } else if (xmlStrEqual(item, BAD_CAST "restriction")) {
7936 if (flagRestriction != -1) {
7937 if ((*flags & flagRestriction) == 0)
7938 *flags |= flagRestriction;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007939 } else
Daniel Veillardc0826a72004-08-10 14:17:33 +00007940 ret = 1;
7941 } else if (xmlStrEqual(item, BAD_CAST "substitution")) {
7942 if (flagSubstitution != -1) {
7943 if ((*flags & flagSubstitution) == 0)
7944 *flags |= flagSubstitution;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007945 } else
Daniel Veillardc0826a72004-08-10 14:17:33 +00007946 ret = 1;
7947 } else if (xmlStrEqual(item, BAD_CAST "list")) {
7948 if (flagList != -1) {
7949 if ((*flags & flagList) == 0)
7950 *flags |= flagList;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007951 } else
Daniel Veillardc0826a72004-08-10 14:17:33 +00007952 ret = 1;
7953 } else if (xmlStrEqual(item, BAD_CAST "union")) {
7954 if (flagUnion != -1) {
7955 if ((*flags & flagUnion) == 0)
7956 *flags |= flagUnion;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007957 } else
Daniel Veillardc0826a72004-08-10 14:17:33 +00007958 ret = 1;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007959 } else
Daniel Veillardc0826a72004-08-10 14:17:33 +00007960 ret = 1;
7961 if (item != NULL)
7962 xmlFree(item);
7963 cur = end;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007964 } while ((ret == 0) && (*cur != 0));
7965 }
7966
Daniel Veillardc0826a72004-08-10 14:17:33 +00007967 return (ret);
7968}
7969
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00007970static int
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007971xmlSchemaCheckCSelectorXPath(xmlSchemaParserCtxtPtr ctxt,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00007972 xmlSchemaIDCPtr idc,
7973 xmlSchemaIDCSelectPtr selector,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00007974 xmlAttrPtr attr,
7975 int isField)
7976{
7977 xmlNodePtr node;
7978
7979 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007980 * c-selector-xpath:
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00007981 * Schema Component Constraint: Selector Value OK
7982 *
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007983 * TODO: 1 The {selector} must be a valid XPath expression, as defined
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00007984 * in [XPath].
7985 */
7986 if (selector == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00007987 xmlSchemaPErr(ctxt, idc->node,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00007988 XML_SCHEMAP_INTERNAL,
7989 "Internal error: xmlSchemaCheckCSelectorXPath, "
7990 "the selector is not specified.\n", NULL, NULL);
7991 return (-1);
7992 }
7993 if (attr == NULL)
7994 node = idc->node;
7995 else
7996 node = (xmlNodePtr) attr;
7997 if (selector->xpath == NULL) {
7998 xmlSchemaPCustomErr(ctxt,
7999 /* TODO: Adjust error code. */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008000 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008001 NULL, node,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008002 "The XPath expression of the selector is not valid", NULL);
8003 return (XML_SCHEMAP_S4S_ATTR_INVALID_VALUE);
8004 } else {
Kasimier T. Buchcikbd2a7d12005-02-16 12:27:25 +00008005 const xmlChar **nsArray = NULL;
8006 xmlNsPtr *nsList = NULL;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008007 /*
8008 * Compile the XPath expression.
8009 */
8010 /*
8011 * TODO: We need the array of in-scope namespaces for compilation.
Kasimier T. Buchcikbd2a7d12005-02-16 12:27:25 +00008012 * TODO: Call xmlPatterncompile with different options for selector/
8013 * field.
8014 */
Daniel Veillard14b56432006-03-09 18:41:40 +00008015 if (attr == NULL)
Daniel Veillardaac7c682006-03-10 13:40:16 +00008016 nsList = NULL;
Daniel Veillard14b56432006-03-09 18:41:40 +00008017 else
8018 nsList = xmlGetNsList(attr->doc, attr->parent);
Kasimier T. Buchcikbd2a7d12005-02-16 12:27:25 +00008019 /*
8020 * Build an array of prefixes and namespaces.
8021 */
8022 if (nsList != NULL) {
8023 int i, count = 0;
Kasimier T. Buchcikbd2a7d12005-02-16 12:27:25 +00008024
8025 for (i = 0; nsList[i] != NULL; i++)
8026 count++;
8027
8028 nsArray = (const xmlChar **) xmlMalloc(
8029 (count * 2 + 1) * sizeof(const xmlChar *));
8030 if (nsArray == NULL) {
8031 xmlSchemaPErrMemory(ctxt, "allocating a namespace array",
8032 NULL);
Kasimier T. Buchcik940ab0c2005-10-19 17:00:53 +00008033 xmlFree(nsList);
Kasimier T. Buchcikbd2a7d12005-02-16 12:27:25 +00008034 return (-1);
8035 }
8036 for (i = 0; i < count; i++) {
Kasimier T. Buchcikbd2a7d12005-02-16 12:27:25 +00008037 nsArray[2 * i] = nsList[i]->href;
8038 nsArray[2 * i + 1] = nsList[i]->prefix;
8039 }
8040 nsArray[count * 2] = NULL;
8041 xmlFree(nsList);
8042 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008043 /*
8044 * TODO: Differentiate between "selector" and "field".
8045 */
Kasimier T. Buchcikbd2a7d12005-02-16 12:27:25 +00008046 if (isField)
8047 selector->xpathComp = (void *) xmlPatterncompile(selector->xpath,
Kasimier T. Buchcik9ca11bf2005-06-14 19:24:47 +00008048 NULL, XML_PATTERN_XSFIELD, nsArray);
Kasimier T. Buchcikbd2a7d12005-02-16 12:27:25 +00008049 else
8050 selector->xpathComp = (void *) xmlPatterncompile(selector->xpath,
Kasimier T. Buchcik9ca11bf2005-06-14 19:24:47 +00008051 NULL, XML_PATTERN_XSSEL, nsArray);
Kasimier T. Buchcikbd2a7d12005-02-16 12:27:25 +00008052 if (nsArray != NULL)
8053 xmlFree((xmlChar **) nsArray);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008054
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +00008055 if (selector->xpathComp == NULL) {
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008056 xmlSchemaPCustomErr(ctxt,
Kasimier T. Buchcik25799ce2005-02-15 14:39:48 +00008057 /* TODO: Adjust error code? */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008058 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008059 NULL, node,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008060 "The XPath expression '%s' could not be "
8061 "compiled", selector->xpath);
8062 return (XML_SCHEMAP_S4S_ATTR_INVALID_VALUE);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008063 }
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008064 }
8065 return (0);
8066}
8067
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008068#define ADD_ANNOTATION(annot) \
8069 xmlSchemaAnnotPtr cur = item->annot; \
8070 if (item->annot == NULL) { \
8071 item->annot = annot; \
8072 return (annot); \
8073 } \
8074 cur = item->annot; \
8075 if (cur->next != NULL) { \
8076 cur = cur->next; \
8077 } \
8078 cur->next = annot;
8079
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008080/**
8081 * xmlSchemaAssignAnnotation:
8082 * @item: the schema component
8083 * @annot: the annotation
8084 *
8085 * Adds the annotation to the given schema component.
8086 *
8087 * Returns the given annotaion.
8088 */
8089static xmlSchemaAnnotPtr
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008090xmlSchemaAddAnnotation(xmlSchemaAnnotItemPtr annItem,
8091 xmlSchemaAnnotPtr annot)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008092{
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008093 if ((annItem == NULL) || (annot == NULL))
8094 return (NULL);
8095 switch (annItem->type) {
8096 case XML_SCHEMA_TYPE_ELEMENT: {
8097 xmlSchemaElementPtr item = (xmlSchemaElementPtr) annItem;
8098 ADD_ANNOTATION(annot)
8099 }
8100 break;
8101 case XML_SCHEMA_TYPE_ATTRIBUTE: {
8102 xmlSchemaAttributePtr item = (xmlSchemaAttributePtr) annItem;
8103 ADD_ANNOTATION(annot)
8104 }
8105 break;
8106 case XML_SCHEMA_TYPE_ANY_ATTRIBUTE:
8107 case XML_SCHEMA_TYPE_ANY: {
8108 xmlSchemaWildcardPtr item = (xmlSchemaWildcardPtr) annItem;
8109 ADD_ANNOTATION(annot)
8110 }
8111 break;
8112 case XML_SCHEMA_TYPE_PARTICLE:
8113 case XML_SCHEMA_TYPE_IDC_KEY:
8114 case XML_SCHEMA_TYPE_IDC_KEYREF:
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008115 case XML_SCHEMA_TYPE_IDC_UNIQUE: {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008116 xmlSchemaAnnotItemPtr item = (xmlSchemaAnnotItemPtr) annItem;
8117 ADD_ANNOTATION(annot)
8118 }
8119 break;
8120 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: {
8121 xmlSchemaAttributeGroupPtr item =
8122 (xmlSchemaAttributeGroupPtr) annItem;
8123 ADD_ANNOTATION(annot)
8124 }
8125 break;
8126 case XML_SCHEMA_TYPE_NOTATION: {
8127 xmlSchemaNotationPtr item = (xmlSchemaNotationPtr) annItem;
8128 ADD_ANNOTATION(annot)
8129 }
8130 break;
8131 case XML_SCHEMA_FACET_MININCLUSIVE:
8132 case XML_SCHEMA_FACET_MINEXCLUSIVE:
8133 case XML_SCHEMA_FACET_MAXINCLUSIVE:
8134 case XML_SCHEMA_FACET_MAXEXCLUSIVE:
8135 case XML_SCHEMA_FACET_TOTALDIGITS:
8136 case XML_SCHEMA_FACET_FRACTIONDIGITS:
8137 case XML_SCHEMA_FACET_PATTERN:
8138 case XML_SCHEMA_FACET_ENUMERATION:
8139 case XML_SCHEMA_FACET_WHITESPACE:
8140 case XML_SCHEMA_FACET_LENGTH:
8141 case XML_SCHEMA_FACET_MAXLENGTH:
8142 case XML_SCHEMA_FACET_MINLENGTH: {
8143 xmlSchemaFacetPtr item = (xmlSchemaFacetPtr) annItem;
8144 ADD_ANNOTATION(annot)
8145 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008146 break;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008147 case XML_SCHEMA_TYPE_SIMPLE:
8148 case XML_SCHEMA_TYPE_COMPLEX: {
8149 xmlSchemaTypePtr item = (xmlSchemaTypePtr) annItem;
8150 ADD_ANNOTATION(annot)
8151 }
8152 break;
8153 case XML_SCHEMA_TYPE_GROUP: {
8154 xmlSchemaModelGroupDefPtr item = (xmlSchemaModelGroupDefPtr) annItem;
8155 ADD_ANNOTATION(annot)
8156 }
8157 break;
8158 case XML_SCHEMA_TYPE_SEQUENCE:
8159 case XML_SCHEMA_TYPE_CHOICE:
8160 case XML_SCHEMA_TYPE_ALL: {
8161 xmlSchemaModelGroupPtr item = (xmlSchemaModelGroupPtr) annItem;
8162 ADD_ANNOTATION(annot)
8163 }
8164 break;
8165 default:
8166 xmlSchemaPCustomErr(NULL,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008167 XML_SCHEMAP_INTERNAL,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008168 NULL, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008169 "Internal error: xmlSchemaAddAnnotation, "
8170 "The item is not a annotated schema component", NULL);
8171 break;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008172 }
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008173 return (annot);
8174}
8175
8176/**
8177 * xmlSchemaParseIDCSelectorAndField:
8178 * @ctxt: a schema validation context
8179 * @schema: the schema being built
8180 * @node: a subtree containing XML Schema informations
8181 *
8182 * Parses a XML Schema identity-contraint definition's
8183 * <selector> and <field> elements.
8184 *
8185 * Returns the parsed identity-constraint definition.
8186 */
8187static xmlSchemaIDCSelectPtr
Daniel Veillarddee23482008-04-11 12:58:43 +00008188xmlSchemaParseIDCSelectorAndField(xmlSchemaParserCtxtPtr ctxt,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008189 xmlSchemaIDCPtr idc,
8190 xmlNodePtr node,
8191 int isField)
8192{
8193 xmlSchemaIDCSelectPtr item;
8194 xmlNodePtr child = NULL;
8195 xmlAttrPtr attr;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008196
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008197 /*
8198 * Check for illegal attributes.
8199 */
8200 attr = node->properties;
8201 while (attr != NULL) {
8202 if (attr->ns == NULL) {
8203 if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
8204 (!xmlStrEqual(attr->name, BAD_CAST "xpath"))) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008205 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008206 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008207 }
8208 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008209 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008210 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008211 }
8212 attr = attr->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008213 }
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008214 /*
8215 * Create the item.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008216 */
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008217 item = (xmlSchemaIDCSelectPtr) xmlMalloc(sizeof(xmlSchemaIDCSelect));
8218 if (item == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008219 xmlSchemaPErrMemory(ctxt,
8220 "allocating a 'selector' of an identity-constraint definition",
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008221 NULL);
8222 return (NULL);
8223 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008224 memset(item, 0, sizeof(xmlSchemaIDCSelect));
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008225 /*
8226 * Attribute "xpath" (mandatory).
8227 */
8228 attr = xmlSchemaGetPropNode(node, "xpath");
8229 if (attr == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008230 xmlSchemaPMissingAttrErr(ctxt,
8231 XML_SCHEMAP_S4S_ATTR_MISSING,
8232 NULL, node,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008233 "name", NULL);
8234 } else {
8235 item->xpath = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
8236 /*
8237 * URGENT TODO: "field"s have an other syntax than "selector"s.
8238 */
8239
Kasimier T. Buchcikbd2a7d12005-02-16 12:27:25 +00008240 if (xmlSchemaCheckCSelectorXPath(ctxt, idc, item, attr,
8241 isField) == -1) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008242 xmlSchemaPErr(ctxt,
8243 (xmlNodePtr) attr,
8244 XML_SCHEMAP_INTERNAL,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008245 "Internal error: xmlSchemaParseIDCSelectorAndField, "
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008246 "validating the XPath expression of a IDC selector.\n",
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008247 NULL, NULL);
8248 }
8249
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008250 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008251 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008252 /*
8253 * And now for the children...
8254 */
8255 child = node->children;
8256 if (IS_SCHEMA(child, "annotation")) {
8257 /*
8258 * Add the annotation to the parent IDC.
8259 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008260 xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) idc,
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +00008261 xmlSchemaParseAnnotation(ctxt, child, 1));
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008262 child = child->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008263 }
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008264 if (child != NULL) {
8265 xmlSchemaPContentErr(ctxt,
8266 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008267 NULL, node, child,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008268 NULL, "(annotation?)");
8269 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008270
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008271 return (item);
8272}
8273
8274/**
8275 * xmlSchemaParseIDC:
8276 * @ctxt: a schema validation context
8277 * @schema: the schema being built
8278 * @node: a subtree containing XML Schema informations
8279 *
8280 * Parses a XML Schema identity-contraint definition.
8281 *
8282 * Returns the parsed identity-constraint definition.
8283 */
8284static xmlSchemaIDCPtr
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008285xmlSchemaParseIDC(xmlSchemaParserCtxtPtr ctxt,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008286 xmlSchemaPtr schema,
8287 xmlNodePtr node,
8288 xmlSchemaTypeType idcCategory,
8289 const xmlChar *targetNamespace)
8290{
8291 xmlSchemaIDCPtr item = NULL;
8292 xmlNodePtr child = NULL;
8293 xmlAttrPtr attr;
8294 const xmlChar *name = NULL;
8295 xmlSchemaIDCSelectPtr field = NULL, lastField = NULL;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008296
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008297 /*
8298 * Check for illegal attributes.
8299 */
8300 attr = node->properties;
8301 while (attr != NULL) {
8302 if (attr->ns == NULL) {
8303 if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
8304 (!xmlStrEqual(attr->name, BAD_CAST "name")) &&
8305 ((idcCategory != XML_SCHEMA_TYPE_IDC_KEYREF) ||
8306 (!xmlStrEqual(attr->name, BAD_CAST "refer")))) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008307 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008308 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008309 }
8310 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008311 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008312 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008313 }
8314 attr = attr->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008315 }
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008316 /*
8317 * Attribute "name" (mandatory).
8318 */
8319 attr = xmlSchemaGetPropNode(node, "name");
8320 if (attr == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008321 xmlSchemaPMissingAttrErr(ctxt,
8322 XML_SCHEMAP_S4S_ATTR_MISSING,
8323 NULL, node,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008324 "name", NULL);
8325 return (NULL);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008326 } else if (xmlSchemaPValAttrNode(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008327 NULL, attr,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008328 xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) {
8329 return (NULL);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008330 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00008331 /* Create the component. */
8332 item = xmlSchemaAddIDC(ctxt, schema, name, targetNamespace,
8333 idcCategory, node);
8334 if (item == NULL)
8335 return(NULL);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008336
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008337 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008338 if (idcCategory == XML_SCHEMA_TYPE_IDC_KEYREF) {
8339 /*
8340 * Attribute "refer" (mandatory).
8341 */
8342 attr = xmlSchemaGetPropNode(node, "refer");
8343 if (attr == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008344 xmlSchemaPMissingAttrErr(ctxt,
8345 XML_SCHEMAP_S4S_ATTR_MISSING,
8346 NULL, node,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008347 "refer", NULL);
8348 } else {
8349 /*
8350 * Create a reference item.
8351 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00008352 item->ref = xmlSchemaNewQNameRef(ctxt, XML_SCHEMA_TYPE_IDC_KEY,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008353 NULL, NULL);
8354 if (item->ref == NULL)
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008355 return (NULL);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008356 xmlSchemaPValAttrNodeQName(ctxt, schema,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008357 NULL, attr,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008358 &(item->ref->targetNamespace),
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008359 &(item->ref->name));
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008360 xmlSchemaCheckReference(ctxt, schema, node, attr,
Kasimier T. Buchcikb474fa42005-03-11 12:34:42 +00008361 item->ref->targetNamespace);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008362 }
8363 }
8364 /*
8365 * And now for the children...
8366 */
8367 child = node->children;
8368 if (IS_SCHEMA(child, "annotation")) {
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +00008369 item->annot = xmlSchemaParseAnnotation(ctxt, child, 1);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008370 child = child->next;
8371 }
Kasimier T. Buchcikff858ca2005-02-18 11:37:58 +00008372 if (child == NULL) {
8373 xmlSchemaPContentErr(ctxt,
8374 XML_SCHEMAP_S4S_ELEM_MISSING,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008375 NULL, node, child,
Kasimier T. Buchcikff858ca2005-02-18 11:37:58 +00008376 "A child element is missing",
8377 "(annotation?, (selector, field+))");
8378 }
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008379 /*
8380 * Child element <selector>.
8381 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008382 if (IS_SCHEMA(child, "selector")) {
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +00008383 item->selector = xmlSchemaParseIDCSelectorAndField(ctxt,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008384 item, child, 0);
8385 child = child->next;
8386 /*
8387 * Child elements <field>.
8388 */
8389 if (IS_SCHEMA(child, "field")) {
8390 do {
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +00008391 field = xmlSchemaParseIDCSelectorAndField(ctxt,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008392 item, child, 1);
8393 if (field != NULL) {
8394 field->index = item->nbFields;
8395 item->nbFields++;
8396 if (lastField != NULL)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008397 lastField->next = field;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008398 else
8399 item->fields = field;
8400 lastField = field;
8401 }
8402 child = child->next;
8403 } while (IS_SCHEMA(child, "field"));
8404 } else {
8405 xmlSchemaPContentErr(ctxt,
8406 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008407 NULL, node, child,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008408 NULL, "(annotation?, (selector, field+))");
8409 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008410 }
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008411 if (child != NULL) {
8412 xmlSchemaPContentErr(ctxt,
8413 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008414 NULL, node, child,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008415 NULL, "(annotation?, (selector, field+))");
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008416 }
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008417
8418 return (item);
8419}
8420
Daniel Veillardc0826a72004-08-10 14:17:33 +00008421/**
Daniel Veillard4255d502002-04-16 15:50:10 +00008422 * xmlSchemaParseElement:
8423 * @ctxt: a schema validation context
8424 * @schema: the schema being built
8425 * @node: a subtree containing XML Schema informations
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008426 * @topLevel: indicates if this is global declaration
Daniel Veillard4255d502002-04-16 15:50:10 +00008427 *
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008428 * Parses a XML schema element declaration.
Daniel Veillard4255d502002-04-16 15:50:10 +00008429 * *WARNING* this interface is highly subject to change
8430 *
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008431 * Returns the element declaration or a particle; NULL in case
8432 * of an error or if the particle has minOccurs==maxOccurs==0.
Daniel Veillard4255d502002-04-16 15:50:10 +00008433 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008434static xmlSchemaBasicItemPtr
Daniel Veillard4255d502002-04-16 15:50:10 +00008435xmlSchemaParseElement(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008436 xmlNodePtr node, int *isElemRef, int topLevel)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008437{
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008438 xmlSchemaElementPtr decl = NULL;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008439 xmlSchemaParticlePtr particle = NULL;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008440 xmlSchemaAnnotPtr annot = NULL;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008441 xmlNodePtr child = NULL;
8442 xmlAttrPtr attr, nameAttr;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008443 int min, max, isRef = 0;
8444 xmlChar *des = NULL;
William M. Bracke7091952004-05-11 15:09:58 +00008445
8446 /* 3.3.3 Constraints on XML Representations of Element Declarations */
8447 /* TODO: Complete implementation of 3.3.6 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008448
Daniel Veillard4255d502002-04-16 15:50:10 +00008449 if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008450 return (NULL);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008451
8452 if (isElemRef != NULL)
8453 *isElemRef = 0;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008454 /*
8455 * If we get a "ref" attribute on a local <element> we will assume it's
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008456 * a reference - even if there's a "name" attribute; this seems to be more
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008457 * robust.
8458 */
Daniel Veillardc0826a72004-08-10 14:17:33 +00008459 nameAttr = xmlSchemaGetPropNode(node, "name");
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008460 attr = xmlSchemaGetPropNode(node, "ref");
Daniel Veillardc0826a72004-08-10 14:17:33 +00008461 if ((topLevel) || (attr == NULL)) {
8462 if (nameAttr == NULL) {
8463 xmlSchemaPMissingAttrErr(ctxt,
8464 XML_SCHEMAP_S4S_ATTR_MISSING,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008465 NULL, node, "name", NULL);
Daniel Veillardc0826a72004-08-10 14:17:33 +00008466 return (NULL);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008467 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008468 } else
Daniel Veillardc0826a72004-08-10 14:17:33 +00008469 isRef = 1;
Daniel Veillardc0826a72004-08-10 14:17:33 +00008470
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008471 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008472 child = node->children;
8473 if (IS_SCHEMA(child, "annotation")) {
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +00008474 annot = xmlSchemaParseAnnotation(ctxt, child, 1);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008475 child = child->next;
8476 }
8477 /*
8478 * Skip particle part if a global declaration.
8479 */
8480 if (topLevel)
8481 goto declaration_part;
8482 /*
8483 * The particle part ==================================================
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008484 */
8485 min = xmlGetMinOccurs(ctxt, node, 0, -1, 1, "xs:nonNegativeInteger");
8486 max = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1, "(xs:nonNegativeInteger | unbounded)");
8487 xmlSchemaPCheckParticleCorrect_2(ctxt, NULL, node, min, max);
Kasimier T. Buchcik4c0aa162006-02-20 14:47:08 +00008488 particle = xmlSchemaAddParticle(ctxt, node, min, max);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008489 if (particle == NULL)
8490 goto return_null;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008491
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008492 /* ret->flags |= XML_SCHEMAS_ELEM_REF; */
8493
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008494 if (isRef) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008495 const xmlChar *refNs = NULL, *ref = NULL;
8496 xmlSchemaQNameRefPtr refer = NULL;
Daniel Veillardc0826a72004-08-10 14:17:33 +00008497 /*
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008498 * The reference part =============================================
Daniel Veillardc0826a72004-08-10 14:17:33 +00008499 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008500 if (isElemRef != NULL)
8501 *isElemRef = 1;
8502
Daniel Veillardc0826a72004-08-10 14:17:33 +00008503 xmlSchemaPValAttrNodeQName(ctxt, schema,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008504 NULL, attr, &refNs, &ref);
8505 xmlSchemaCheckReference(ctxt, schema, node, attr, refNs);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008506 /*
8507 * SPEC (3.3.3 : 2.1) "One of ref or name must be present, but not both"
Daniel Veillardc0826a72004-08-10 14:17:33 +00008508 */
8509 if (nameAttr != NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008510 xmlSchemaPMutualExclAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008511 XML_SCHEMAP_SRC_ELEMENT_2_1, NULL, nameAttr, "ref", "name");
Daniel Veillardc0826a72004-08-10 14:17:33 +00008512 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008513 /*
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008514 * Check for illegal attributes.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008515 */
Daniel Veillardc0826a72004-08-10 14:17:33 +00008516 attr = node->properties;
8517 while (attr != NULL) {
8518 if (attr->ns == NULL) {
Kasimier T. Buchcik87876402004-09-29 13:29:03 +00008519 if (xmlStrEqual(attr->name, BAD_CAST "ref") ||
8520 xmlStrEqual(attr->name, BAD_CAST "name") ||
8521 xmlStrEqual(attr->name, BAD_CAST "id") ||
8522 xmlStrEqual(attr->name, BAD_CAST "maxOccurs") ||
8523 xmlStrEqual(attr->name, BAD_CAST "minOccurs"))
8524 {
8525 attr = attr->next;
8526 continue;
8527 } else {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008528 /* SPEC (3.3.3 : 2.2) */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008529 xmlSchemaPCustomAttrErr(ctxt,
Daniel Veillardc0826a72004-08-10 14:17:33 +00008530 XML_SCHEMAP_SRC_ELEMENT_2_2,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008531 NULL, NULL, attr,
Daniel Veillardc0826a72004-08-10 14:17:33 +00008532 "Only the attributes 'minOccurs', 'maxOccurs' and "
8533 "'id' are allowed in addition to 'ref'");
8534 break;
8535 }
8536 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
8537 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008538 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Daniel Veillardc0826a72004-08-10 14:17:33 +00008539 }
8540 attr = attr->next;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008541 }
Daniel Veillardc0826a72004-08-10 14:17:33 +00008542 /*
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008543 * No children except <annotation> expected.
Daniel Veillardc0826a72004-08-10 14:17:33 +00008544 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008545 if (child != NULL) {
8546 xmlSchemaPContentErr(ctxt, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008547 NULL, node, child, NULL, "(annotation?)");
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008548 }
8549 if ((min == 0) && (max == 0))
8550 goto return_null;
8551 /*
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008552 * Create the reference item and attach it to the particle.
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008553 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00008554 refer = xmlSchemaNewQNameRef(ctxt, XML_SCHEMA_TYPE_ELEMENT,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008555 ref, refNs);
8556 if (refer == NULL)
8557 goto return_null;
8558 particle->children = (xmlSchemaTreeItemPtr) refer;
8559 particle->annot = annot;
8560 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00008561 * Add the particle to pending components, since the reference
8562 * need to be resolved.
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008563 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008564 WXS_ADD_PENDING(ctxt, particle);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008565 return ((xmlSchemaBasicItemPtr) particle);
8566 }
8567 /*
8568 * The declaration part ===============================================
8569 */
8570declaration_part:
8571 {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00008572 const xmlChar *ns = NULL, *fixed, *name, *attrValue;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008573 xmlSchemaIDCPtr curIDC = NULL, lastIDC = NULL;
8574
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008575 if (xmlSchemaPValAttrNode(ctxt, NULL, nameAttr,
Daniel Veillardc0826a72004-08-10 14:17:33 +00008576 xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0)
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008577 goto return_null;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008578 /*
Daniel Veillardc0826a72004-08-10 14:17:33 +00008579 * Evaluate the target namespace.
8580 */
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00008581 if (topLevel) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00008582 ns = ctxt->targetNamespace;
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00008583 } else {
8584 attr = xmlSchemaGetPropNode(node, "form");
8585 if (attr != NULL) {
8586 attrValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
8587 if (xmlStrEqual(attrValue, BAD_CAST "qualified")) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00008588 ns = ctxt->targetNamespace;
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00008589 } else if (!xmlStrEqual(attrValue, BAD_CAST "unqualified")) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008590 xmlSchemaPSimpleTypeErr(ctxt,
8591 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
8592 NULL, (xmlNodePtr) attr,
8593 NULL, "(qualified | unqualified)",
8594 attrValue, NULL, NULL, NULL);
Kasimier T. Buchcikb4a9e642004-08-30 10:56:53 +00008595 }
8596 } else if (schema->flags & XML_SCHEMAS_QUALIF_ELEM)
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00008597 ns = ctxt->targetNamespace;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008598 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008599 decl = xmlSchemaAddElement(ctxt, name, ns, node, topLevel);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008600 if (decl == NULL) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008601 goto return_null;
William M. Bracke7091952004-05-11 15:09:58 +00008602 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008603 /*
Daniel Veillardc0826a72004-08-10 14:17:33 +00008604 * Check for illegal attributes.
8605 */
William M. Bracke7091952004-05-11 15:09:58 +00008606 attr = node->properties;
8607 while (attr != NULL) {
Daniel Veillardc0826a72004-08-10 14:17:33 +00008608 if (attr->ns == NULL) {
8609 if ((!xmlStrEqual(attr->name, BAD_CAST "name")) &&
8610 (!xmlStrEqual(attr->name, BAD_CAST "type")) &&
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008611 (!xmlStrEqual(attr->name, BAD_CAST "id")) &&
Daniel Veillardc0826a72004-08-10 14:17:33 +00008612 (!xmlStrEqual(attr->name, BAD_CAST "default")) &&
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008613 (!xmlStrEqual(attr->name, BAD_CAST "fixed")) &&
Daniel Veillardc0826a72004-08-10 14:17:33 +00008614 (!xmlStrEqual(attr->name, BAD_CAST "block")) &&
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008615 (!xmlStrEqual(attr->name, BAD_CAST "nillable")))
8616 {
8617 if (topLevel == 0) {
Kasimier T. Buchcik87876402004-09-29 13:29:03 +00008618 if ((!xmlStrEqual(attr->name, BAD_CAST "maxOccurs")) &&
Daniel Veillardc0826a72004-08-10 14:17:33 +00008619 (!xmlStrEqual(attr->name, BAD_CAST "minOccurs")) &&
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008620 (!xmlStrEqual(attr->name, BAD_CAST "form")))
Kasimier T. Buchcik87876402004-09-29 13:29:03 +00008621 {
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +00008622 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008623 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Daniel Veillardc0826a72004-08-10 14:17:33 +00008624 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008625 } else if ((!xmlStrEqual(attr->name, BAD_CAST "final")) &&
8626 (!xmlStrEqual(attr->name, BAD_CAST "abstract")) &&
Daniel Veillardc0826a72004-08-10 14:17:33 +00008627 (!xmlStrEqual(attr->name, BAD_CAST "substitutionGroup"))) {
8628
8629 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008630 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Daniel Veillardc0826a72004-08-10 14:17:33 +00008631 }
8632 }
8633 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008634
Daniel Veillardc0826a72004-08-10 14:17:33 +00008635 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008636 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
William M. Bracke7091952004-05-11 15:09:58 +00008637 }
8638 attr = attr->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008639 }
William M. Bracke7091952004-05-11 15:09:58 +00008640 /*
Daniel Veillardc0826a72004-08-10 14:17:33 +00008641 * Extract/validate attributes.
8642 */
8643 if (topLevel) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008644 /*
Daniel Veillardc0826a72004-08-10 14:17:33 +00008645 * Process top attributes of global element declarations here.
8646 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008647 decl->flags |= XML_SCHEMAS_ELEM_GLOBAL;
8648 decl->flags |= XML_SCHEMAS_ELEM_TOPLEVEL;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008649 xmlSchemaPValAttrQName(ctxt, schema,
8650 NULL, node, "substitutionGroup",
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008651 &(decl->substGroupNs), &(decl->substGroup));
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008652 if (xmlGetBooleanProp(ctxt, node, "abstract", 0))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008653 decl->flags |= XML_SCHEMAS_ELEM_ABSTRACT;
Daniel Veillardc0826a72004-08-10 14:17:33 +00008654 /*
8655 * Attribute "final".
8656 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008657 attr = xmlSchemaGetPropNode(node, "final");
Daniel Veillardc0826a72004-08-10 14:17:33 +00008658 if (attr == NULL) {
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +00008659 if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_EXTENSION)
8660 decl->flags |= XML_SCHEMAS_ELEM_FINAL_EXTENSION;
8661 if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION)
8662 decl->flags |= XML_SCHEMAS_ELEM_FINAL_RESTRICTION;
Daniel Veillardc0826a72004-08-10 14:17:33 +00008663 } else {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008664 attrValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
8665 if (xmlSchemaPValAttrBlockFinal(attrValue, &(decl->flags),
Daniel Veillardc0826a72004-08-10 14:17:33 +00008666 -1,
8667 XML_SCHEMAS_ELEM_FINAL_EXTENSION,
8668 XML_SCHEMAS_ELEM_FINAL_RESTRICTION, -1, -1, -1) != 0) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008669 xmlSchemaPSimpleTypeErr(ctxt,
Daniel Veillardc0826a72004-08-10 14:17:33 +00008670 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008671 NULL, (xmlNodePtr) attr,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008672 NULL, "(#all | List of (extension | restriction))",
Daniel Veillardc0826a72004-08-10 14:17:33 +00008673 attrValue, NULL, NULL, NULL);
8674 }
8675 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008676 }
Daniel Veillardc0826a72004-08-10 14:17:33 +00008677 /*
8678 * Attribute "block".
8679 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008680 attr = xmlSchemaGetPropNode(node, "block");
Daniel Veillardc0826a72004-08-10 14:17:33 +00008681 if (attr == NULL) {
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +00008682 /*
8683 * Apply default "block" values.
8684 */
8685 if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION)
8686 decl->flags |= XML_SCHEMAS_ELEM_BLOCK_RESTRICTION;
8687 if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION)
8688 decl->flags |= XML_SCHEMAS_ELEM_BLOCK_EXTENSION;
8689 if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION)
8690 decl->flags |= XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION;
Daniel Veillardc0826a72004-08-10 14:17:33 +00008691 } else {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008692 attrValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
8693 if (xmlSchemaPValAttrBlockFinal(attrValue, &(decl->flags),
Daniel Veillardc0826a72004-08-10 14:17:33 +00008694 -1,
8695 XML_SCHEMAS_ELEM_BLOCK_EXTENSION,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008696 XML_SCHEMAS_ELEM_BLOCK_RESTRICTION,
Daniel Veillardc0826a72004-08-10 14:17:33 +00008697 XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION, -1, -1) != 0) {
8698 xmlSchemaPSimpleTypeErr(ctxt,
8699 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008700 NULL, (xmlNodePtr) attr,
William M. Brack2f2a6632004-08-20 23:09:47 +00008701 NULL, "(#all | List of (extension | "
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008702 "restriction | substitution))", attrValue,
8703 NULL, NULL, NULL);
Daniel Veillardc0826a72004-08-10 14:17:33 +00008704 }
8705 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008706 if (xmlGetBooleanProp(ctxt, node, "nillable", 0))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008707 decl->flags |= XML_SCHEMAS_ELEM_NILLABLE;
Daniel Veillardd0c9c322003-10-10 00:49:42 +00008708
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008709 attr = xmlSchemaGetPropNode(node, "type");
8710 if (attr != NULL) {
8711 xmlSchemaPValAttrNodeQName(ctxt, schema,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008712 NULL, attr,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008713 &(decl->namedTypeNs), &(decl->namedType));
8714 xmlSchemaCheckReference(ctxt, schema, node,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008715 attr, decl->namedTypeNs);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008716 }
8717 decl->value = xmlSchemaGetProp(ctxt, node, "default");
8718 attr = xmlSchemaGetPropNode(node, "fixed");
Daniel Veillardc0826a72004-08-10 14:17:33 +00008719 if (attr != NULL) {
8720 fixed = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008721 if (decl->value != NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008722 /*
8723 * 3.3.3 : 1
8724 * default and fixed must not both be present.
Daniel Veillardc0826a72004-08-10 14:17:33 +00008725 */
8726 xmlSchemaPMutualExclAttrErr(ctxt,
8727 XML_SCHEMAP_SRC_ELEMENT_1,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008728 NULL, attr, "default", "fixed");
Daniel Veillardc0826a72004-08-10 14:17:33 +00008729 } else {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008730 decl->flags |= XML_SCHEMAS_ELEM_FIXED;
8731 decl->value = fixed;
Daniel Veillardc0826a72004-08-10 14:17:33 +00008732 }
William M. Bracke7091952004-05-11 15:09:58 +00008733 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008734 /*
8735 * And now for the children...
8736 */
William M. Bracke7091952004-05-11 15:09:58 +00008737 if (IS_SCHEMA(child, "complexType")) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008738 /*
8739 * 3.3.3 : 3
Daniel Veillardc0826a72004-08-10 14:17:33 +00008740 * "type" and either <simpleType> or <complexType> are mutually
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008741 * exclusive
Daniel Veillardc0826a72004-08-10 14:17:33 +00008742 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008743 if (decl->namedType != NULL) {
Daniel Veillardc0826a72004-08-10 14:17:33 +00008744 xmlSchemaPContentErr(ctxt,
8745 XML_SCHEMAP_SRC_ELEMENT_3,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008746 NULL, node, child,
Daniel Veillardc0826a72004-08-10 14:17:33 +00008747 "The attribute 'type' and the <complexType> child are "
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008748 "mutually exclusive", NULL);
William M. Bracke7091952004-05-11 15:09:58 +00008749 } else
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008750 WXS_ELEM_TYPEDEF(decl) = xmlSchemaParseComplexType(ctxt, schema, child, 0);
William M. Bracke7091952004-05-11 15:09:58 +00008751 child = child->next;
8752 } else if (IS_SCHEMA(child, "simpleType")) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008753 /*
8754 * 3.3.3 : 3
Daniel Veillardc0826a72004-08-10 14:17:33 +00008755 * "type" and either <simpleType> or <complexType> are
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008756 * mutually exclusive
Daniel Veillardc0826a72004-08-10 14:17:33 +00008757 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008758 if (decl->namedType != NULL) {
Daniel Veillardc0826a72004-08-10 14:17:33 +00008759 xmlSchemaPContentErr(ctxt,
8760 XML_SCHEMAP_SRC_ELEMENT_3,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008761 NULL, node, child,
Daniel Veillardc0826a72004-08-10 14:17:33 +00008762 "The attribute 'type' and the <simpleType> child are "
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008763 "mutually exclusive", NULL);
William M. Bracke7091952004-05-11 15:09:58 +00008764 } else
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008765 WXS_ELEM_TYPEDEF(decl) = xmlSchemaParseSimpleType(ctxt, schema, child, 0);
William M. Bracke7091952004-05-11 15:09:58 +00008766 child = child->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008767 }
William M. Bracke7091952004-05-11 15:09:58 +00008768 while ((IS_SCHEMA(child, "unique")) ||
Daniel Veillardc0826a72004-08-10 14:17:33 +00008769 (IS_SCHEMA(child, "key")) || (IS_SCHEMA(child, "keyref"))) {
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008770 if (IS_SCHEMA(child, "unique")) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008771 curIDC = xmlSchemaParseIDC(ctxt, schema, child,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008772 XML_SCHEMA_TYPE_IDC_UNIQUE, decl->targetNamespace);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008773 } else if (IS_SCHEMA(child, "key")) {
8774 curIDC = xmlSchemaParseIDC(ctxt, schema, child,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008775 XML_SCHEMA_TYPE_IDC_KEY, decl->targetNamespace);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008776 } else if (IS_SCHEMA(child, "keyref")) {
8777 curIDC = xmlSchemaParseIDC(ctxt, schema, child,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008778 XML_SCHEMA_TYPE_IDC_KEYREF, decl->targetNamespace);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008779 }
8780 if (lastIDC != NULL)
8781 lastIDC->next = curIDC;
8782 else
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008783 decl->idcs = (void *) curIDC;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008784 lastIDC = curIDC;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +00008785 child = child->next;
William M. Bracke7091952004-05-11 15:09:58 +00008786 }
8787 if (child != NULL) {
Daniel Veillardc0826a72004-08-10 14:17:33 +00008788 xmlSchemaPContentErr(ctxt,
8789 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008790 NULL, node, child,
Daniel Veillardc0826a72004-08-10 14:17:33 +00008791 NULL, "(annotation?, ((simpleType | complexType)?, "
8792 "(unique | key | keyref)*))");
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008793 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008794 decl->annot = annot;
Daniel Veillardc0826a72004-08-10 14:17:33 +00008795 }
Daniel Veillardc0826a72004-08-10 14:17:33 +00008796 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008797 * NOTE: Element Declaration Representation OK 4. will be checked at a
Daniel Veillardc0826a72004-08-10 14:17:33 +00008798 * different layer.
8799 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008800 FREE_AND_NULL(des)
8801 if (topLevel)
8802 return ((xmlSchemaBasicItemPtr) decl);
8803 else {
8804 particle->children = (xmlSchemaTreeItemPtr) decl;
8805 return ((xmlSchemaBasicItemPtr) particle);
8806 }
8807
8808return_null:
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008809 FREE_AND_NULL(des);
8810 if (annot != NULL) {
8811 if (particle != NULL)
8812 particle->annot = NULL;
8813 if (decl != NULL)
8814 decl->annot = NULL;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008815 xmlSchemaFreeAnnot(annot);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008816 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008817 return (NULL);
Daniel Veillard4255d502002-04-16 15:50:10 +00008818}
8819
8820/**
8821 * xmlSchemaParseUnion:
8822 * @ctxt: a schema validation context
8823 * @schema: the schema being built
8824 * @node: a subtree containing XML Schema informations
8825 *
8826 * parse a XML schema Union definition
8827 * *WARNING* this interface is highly subject to change
8828 *
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008829 * Returns -1 in case of internal error, 0 in case of success and a positive
8830 * error code otherwise.
Daniel Veillard4255d502002-04-16 15:50:10 +00008831 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008832static int
Daniel Veillard4255d502002-04-16 15:50:10 +00008833xmlSchemaParseUnion(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
Daniel Veillardd0c9c322003-10-10 00:49:42 +00008834 xmlNodePtr node)
Daniel Veillard4255d502002-04-16 15:50:10 +00008835{
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008836 xmlSchemaTypePtr type;
Daniel Veillard4255d502002-04-16 15:50:10 +00008837 xmlNodePtr child = NULL;
William M. Brack2f2a6632004-08-20 23:09:47 +00008838 xmlAttrPtr attr;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008839 const xmlChar *cur = NULL;
Daniel Veillard4255d502002-04-16 15:50:10 +00008840
8841 if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008842 return (-1);
8843 /* Not a component, don't create it. */
8844 type = ctxt->ctxtType;
8845 /*
8846 * Mark the simple type as being of variety "union".
8847 */
8848 type->flags |= XML_SCHEMAS_TYPE_VARIETY_UNION;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008849 /*
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +00008850 * SPEC (Base type) (2) "If the <list> or <union> alternative is chosen,
Rob Richardsc6947bb2008-06-29 15:04:41 +00008851 * then the �simple ur-type definition�."
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +00008852 */
8853 type->baseType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE);
William M. Brack2f2a6632004-08-20 23:09:47 +00008854 /*
8855 * Check for illegal attributes.
8856 */
8857 attr = node->properties;
8858 while (attr != NULL) {
8859 if (attr->ns == NULL) {
8860 if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
8861 (!xmlStrEqual(attr->name, BAD_CAST "memberTypes"))) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008862 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008863 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
William M. Brack2f2a6632004-08-20 23:09:47 +00008864 }
8865 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008866 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008867 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
William M. Brack2f2a6632004-08-20 23:09:47 +00008868 }
8869 attr = attr->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008870 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008871 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
William M. Brack2f2a6632004-08-20 23:09:47 +00008872 /*
8873 * Attribute "memberTypes". This is a list of QNames.
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008874 * TODO: Check the value to contain anything.
William M. Brack2f2a6632004-08-20 23:09:47 +00008875 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008876 attr = xmlSchemaGetPropNode(node, "memberTypes");
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008877 if (attr != NULL) {
8878 const xmlChar *end;
8879 xmlChar *tmp;
8880 const xmlChar *localName, *nsName;
8881 xmlSchemaTypeLinkPtr link, lastLink = NULL;
8882 xmlSchemaQNameRefPtr ref;
8883
8884 cur = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008885 type->base = cur;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008886 do {
8887 while (IS_BLANK_CH(*cur))
8888 cur++;
8889 end = cur;
8890 while ((*end != 0) && (!(IS_BLANK_CH(*end))))
8891 end++;
8892 if (end == cur)
8893 break;
8894 tmp = xmlStrndup(cur, end - cur);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008895 if (xmlSchemaPValAttrNodeQNameValue(ctxt, schema,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008896 NULL, attr, BAD_CAST tmp, &nsName, &localName) == 0) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008897 /*
8898 * Create the member type link.
8899 */
8900 link = (xmlSchemaTypeLinkPtr)
8901 xmlMalloc(sizeof(xmlSchemaTypeLink));
8902 if (link == NULL) {
8903 xmlSchemaPErrMemory(ctxt, "xmlSchemaParseUnion, "
8904 "allocating a type link", NULL);
8905 return (-1);
8906 }
8907 link->type = NULL;
8908 link->next = NULL;
8909 if (lastLink == NULL)
8910 type->memberTypes = link;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008911 else
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008912 lastLink->next = link;
8913 lastLink = link;
8914 /*
8915 * Create a reference item.
8916 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00008917 ref = xmlSchemaNewQNameRef(ctxt, XML_SCHEMA_TYPE_SIMPLE,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008918 localName, nsName);
8919 if (ref == NULL) {
8920 FREE_AND_NULL(tmp)
8921 return (-1);
8922 }
8923 /*
8924 * Assign the reference to the link, it will be resolved
8925 * later during fixup of the union simple type.
8926 */
8927 link->type = (xmlSchemaTypePtr) ref;
8928 }
8929 FREE_AND_NULL(tmp)
8930 cur = end;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008931 } while (*cur != 0);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008932
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008933 }
William M. Brack2f2a6632004-08-20 23:09:47 +00008934 /*
8935 * And now for the children...
8936 */
Daniel Veillard4255d502002-04-16 15:50:10 +00008937 child = node->children;
8938 if (IS_SCHEMA(child, "annotation")) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008939 /*
8940 * Add the annotation to the simple type ancestor.
8941 */
8942 xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) type,
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +00008943 xmlSchemaParseAnnotation(ctxt, child, 1));
Daniel Veillardd0c9c322003-10-10 00:49:42 +00008944 child = child->next;
Daniel Veillard4255d502002-04-16 15:50:10 +00008945 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008946 if (IS_SCHEMA(child, "simpleType")) {
8947 xmlSchemaTypePtr subtype, last = NULL;
8948
8949 /*
8950 * Anchor the member types in the "subtypes" field of the
8951 * simple type.
8952 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008953 while (IS_SCHEMA(child, "simpleType")) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008954 subtype = (xmlSchemaTypePtr)
8955 xmlSchemaParseSimpleType(ctxt, schema, child, 0);
8956 if (subtype != NULL) {
8957 if (last == NULL) {
8958 type->subtypes = subtype;
8959 last = subtype;
8960 } else {
8961 last->next = subtype;
8962 last = subtype;
8963 }
8964 last->next = NULL;
8965 }
8966 child = child->next;
8967 }
Daniel Veillard4255d502002-04-16 15:50:10 +00008968 }
8969 if (child != NULL) {
William M. Brack2f2a6632004-08-20 23:09:47 +00008970 xmlSchemaPContentErr(ctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008971 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008972 NULL, node, child, NULL, "(annotation?, simpleType*)");
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008973 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008974 if ((attr == NULL) && (type->subtypes == NULL)) {
8975 /*
8976 * src-union-memberTypes-or-simpleTypes
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008977 * Either the memberTypes [attribute] of the <union> element must
8978 * be non-empty or there must be at least one simpleType [child].
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008979 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008980 xmlSchemaPCustomErr(ctxt,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008981 XML_SCHEMAP_SRC_UNION_MEMBERTYPES_OR_SIMPLETYPES,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00008982 NULL, node,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008983 "Either the attribute 'memberTypes' or "
8984 "at least one <simpleType> child must be present", NULL);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00008985 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00008986 return (0);
Daniel Veillard4255d502002-04-16 15:50:10 +00008987}
8988
8989/**
8990 * xmlSchemaParseList:
8991 * @ctxt: a schema validation context
8992 * @schema: the schema being built
8993 * @node: a subtree containing XML Schema informations
8994 *
8995 * parse a XML schema List definition
8996 * *WARNING* this interface is highly subject to change
8997 *
William M. Bracke7091952004-05-11 15:09:58 +00008998 * Returns -1 in case of error, 0 if the declaration is improper and
Daniel Veillard4255d502002-04-16 15:50:10 +00008999 * 1 in case of success.
9000 */
9001static xmlSchemaTypePtr
9002xmlSchemaParseList(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
Daniel Veillardd0c9c322003-10-10 00:49:42 +00009003 xmlNodePtr node)
Daniel Veillard4255d502002-04-16 15:50:10 +00009004{
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009005 xmlSchemaTypePtr type;
Daniel Veillard4255d502002-04-16 15:50:10 +00009006 xmlNodePtr child = NULL;
William M. Brack2f2a6632004-08-20 23:09:47 +00009007 xmlAttrPtr attr;
Daniel Veillard4255d502002-04-16 15:50:10 +00009008
9009 if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
9010 return (NULL);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009011 /* Not a component, don't create it. */
9012 type = ctxt->ctxtType;
9013 /*
9014 * Mark the type as being of variety "list".
9015 */
9016 type->flags |= XML_SCHEMAS_TYPE_VARIETY_LIST;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009017 /*
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +00009018 * SPEC (Base type) (2) "If the <list> or <union> alternative is chosen,
Rob Richardsc6947bb2008-06-29 15:04:41 +00009019 * then the �simple ur-type definition�."
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +00009020 */
9021 type->baseType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE);
William M. Brack2f2a6632004-08-20 23:09:47 +00009022 /*
9023 * Check for illegal attributes.
9024 */
9025 attr = node->properties;
9026 while (attr != NULL) {
9027 if (attr->ns == NULL) {
9028 if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
9029 (!xmlStrEqual(attr->name, BAD_CAST "itemType"))) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009030 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009031 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
William M. Brack2f2a6632004-08-20 23:09:47 +00009032 }
9033 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009034 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009035 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
William M. Brack2f2a6632004-08-20 23:09:47 +00009036 }
9037 attr = attr->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009038 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009039
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009040 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009041
William M. Brack2f2a6632004-08-20 23:09:47 +00009042 /*
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009043 * Attribute "itemType". NOTE that we will use the "ref" and "refNs"
9044 * fields for holding the reference to the itemType.
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009045 *
9046 * REVAMP TODO: Use the "base" and "baseNs" fields, since we will remove
9047 * the "ref" fields.
William M. Brack2f2a6632004-08-20 23:09:47 +00009048 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009049 xmlSchemaPValAttrQName(ctxt, schema, NULL,
9050 node, "itemType", &(type->baseNs), &(type->base));
William M. Brack2f2a6632004-08-20 23:09:47 +00009051 /*
9052 * And now for the children...
9053 */
Daniel Veillard4255d502002-04-16 15:50:10 +00009054 child = node->children;
9055 if (IS_SCHEMA(child, "annotation")) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009056 xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) type,
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +00009057 xmlSchemaParseAnnotation(ctxt, child, 1));
Daniel Veillardd0c9c322003-10-10 00:49:42 +00009058 child = child->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009059 }
William M. Brack2f2a6632004-08-20 23:09:47 +00009060 if (IS_SCHEMA(child, "simpleType")) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009061 /*
9062 * src-list-itemType-or-simpleType
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009063 * Either the itemType [attribute] or the <simpleType> [child] of
9064 * the <list> element must be present, but not both.
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009065 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009066 if (type->base != NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009067 xmlSchemaPCustomErr(ctxt,
William M. Brack2f2a6632004-08-20 23:09:47 +00009068 XML_SCHEMAP_SRC_SIMPLE_TYPE_1,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009069 NULL, node,
William M. Brack2f2a6632004-08-20 23:09:47 +00009070 "The attribute 'itemType' and the <simpleType> child "
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009071 "are mutually exclusive", NULL);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009072 } else {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009073 type->subtypes = xmlSchemaParseSimpleType(ctxt, schema, child, 0);
William M. Brack2f2a6632004-08-20 23:09:47 +00009074 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009075 child = child->next;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009076 } else if (type->base == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009077 xmlSchemaPCustomErr(ctxt,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009078 XML_SCHEMAP_SRC_SIMPLE_TYPE_1,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009079 NULL, node,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009080 "Either the attribute 'itemType' or the <simpleType> child "
9081 "must be present", NULL);
Daniel Veillard4255d502002-04-16 15:50:10 +00009082 }
9083 if (child != NULL) {
William M. Brack2f2a6632004-08-20 23:09:47 +00009084 xmlSchemaPContentErr(ctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009085 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009086 NULL, node, child, NULL, "(annotation?, simpleType?)");
Daniel Veillard4255d502002-04-16 15:50:10 +00009087 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009088 if ((type->base == NULL) &&
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009089 (type->subtypes == NULL) &&
9090 (xmlSchemaGetPropNode(node, "itemType") == NULL)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009091 xmlSchemaPCustomErr(ctxt,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009092 XML_SCHEMAP_SRC_SIMPLE_TYPE_1,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009093 NULL, node,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009094 "Either the attribute 'itemType' or the <simpleType> child "
9095 "must be present", NULL);
9096 }
9097 return (NULL);
Daniel Veillard4255d502002-04-16 15:50:10 +00009098}
Daniel Veillardd0c9c322003-10-10 00:49:42 +00009099
Daniel Veillard4255d502002-04-16 15:50:10 +00009100/**
9101 * xmlSchemaParseSimpleType:
9102 * @ctxt: a schema validation context
9103 * @schema: the schema being built
9104 * @node: a subtree containing XML Schema informations
9105 *
9106 * parse a XML schema Simple Type definition
9107 * *WARNING* this interface is highly subject to change
9108 *
William M. Bracke7091952004-05-11 15:09:58 +00009109 * Returns -1 in case of error, 0 if the declaration is improper and
Daniel Veillardc0826a72004-08-10 14:17:33 +00009110 * 1 in case of success.
Daniel Veillard4255d502002-04-16 15:50:10 +00009111 */
9112static xmlSchemaTypePtr
9113xmlSchemaParseSimpleType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
Daniel Veillard3646d642004-06-02 19:19:14 +00009114 xmlNodePtr node, int topLevel)
Daniel Veillard4255d502002-04-16 15:50:10 +00009115{
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009116 xmlSchemaTypePtr type, oldCtxtType;
Daniel Veillard4255d502002-04-16 15:50:10 +00009117 xmlNodePtr child = NULL;
Daniel Veillardc0826a72004-08-10 14:17:33 +00009118 const xmlChar *attrValue = NULL;
Daniel Veillardc0826a72004-08-10 14:17:33 +00009119 xmlAttrPtr attr;
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +00009120 int hasRestriction = 0;
Daniel Veillard4255d502002-04-16 15:50:10 +00009121
9122 if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
9123 return (NULL);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009124
Daniel Veillardc0826a72004-08-10 14:17:33 +00009125 if (topLevel) {
Kasimier T. Buchcik87876402004-09-29 13:29:03 +00009126 attr = xmlSchemaGetPropNode(node, "name");
Daniel Veillardc0826a72004-08-10 14:17:33 +00009127 if (attr == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009128 xmlSchemaPMissingAttrErr(ctxt,
9129 XML_SCHEMAP_S4S_ATTR_MISSING,
9130 NULL, node,
Daniel Veillardc0826a72004-08-10 14:17:33 +00009131 "name", NULL);
9132 return (NULL);
Kasimier T. Buchcik9ca11bf2005-06-14 19:24:47 +00009133 } else {
9134 if (xmlSchemaPValAttrNode(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009135 NULL, attr,
Kasimier T. Buchcik9ca11bf2005-06-14 19:24:47 +00009136 xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &attrValue) != 0)
9137 return (NULL);
9138 /*
9139 * Skip built-in types.
9140 */
9141 if (ctxt->isS4S) {
9142 xmlSchemaTypePtr biType;
9143
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +00009144 if (ctxt->isRedefine) {
9145 /*
9146 * REDEFINE: Disallow redefinition of built-in-types.
9147 * TODO: It seems that the spec does not say anything
9148 * about this case.
9149 */
9150 xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_SRC_REDEFINE,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009151 NULL, node,
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +00009152 "Redefinition of built-in simple types is not "
9153 "supported", NULL);
9154 return(NULL);
9155 }
Kasimier T. Buchcik9ca11bf2005-06-14 19:24:47 +00009156 biType = xmlSchemaGetPredefinedType(attrValue, xmlSchemaNs);
9157 if (biType != NULL)
9158 return (biType);
9159 }
Daniel Veillard01fa6152004-06-29 17:04:39 +00009160 }
Daniel Veillardc0826a72004-08-10 14:17:33 +00009161 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009162 /*
9163 * TargetNamespace:
Rob Richardsc6947bb2008-06-29 15:04:41 +00009164 * SPEC "The �actual value� of the targetNamespace [attribute]
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009165 * of the <schema> ancestor element information item if present,
Rob Richardsc6947bb2008-06-29 15:04:41 +00009166 * otherwise �absent�.
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009167 */
Daniel Veillardc0826a72004-08-10 14:17:33 +00009168 if (topLevel == 0) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009169#ifdef ENABLE_NAMED_LOCALS
Kasimier T. Buchcik87876402004-09-29 13:29:03 +00009170 char buf[40];
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009171#endif
Daniel Veillard01fa6152004-06-29 17:04:39 +00009172 /*
Daniel Veillardc0826a72004-08-10 14:17:33 +00009173 * Parse as local simple type definition.
Daniel Veillard01fa6152004-06-29 17:04:39 +00009174 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009175#ifdef ENABLE_NAMED_LOCALS
Kasimier T. Buchcik87250a92005-01-28 15:59:53 +00009176 snprintf(buf, 39, "#ST%d", ctxt->counter++ + 1);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009177 type = xmlSchemaAddType(ctxt, schema,
9178 XML_SCHEMA_TYPE_SIMPLE,
9179 xmlDictLookup(ctxt->dict, (const xmlChar *)buf, -1),
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009180 ctxt->targetNamespace, node, 0);
9181#else
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009182 type = xmlSchemaAddType(ctxt, schema,
9183 XML_SCHEMA_TYPE_SIMPLE,
9184 NULL, ctxt->targetNamespace, node, 0);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009185#endif
Daniel Veillardc0826a72004-08-10 14:17:33 +00009186 if (type == NULL)
9187 return (NULL);
Daniel Veillardc0826a72004-08-10 14:17:33 +00009188 type->type = XML_SCHEMA_TYPE_SIMPLE;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009189 type->contentType = XML_SCHEMA_CONTENT_SIMPLE;
Daniel Veillardc0826a72004-08-10 14:17:33 +00009190 /*
9191 * Check for illegal attributes.
9192 */
9193 attr = node->properties;
9194 while (attr != NULL) {
9195 if (attr->ns == NULL) {
9196 if (!xmlStrEqual(attr->name, BAD_CAST "id")) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009197 xmlSchemaPIllegalAttrErr(ctxt,
Daniel Veillarddee23482008-04-11 12:58:43 +00009198 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Daniel Veillard01fa6152004-06-29 17:04:39 +00009199 }
Daniel Veillardc0826a72004-08-10 14:17:33 +00009200 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009201 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009202 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Daniel Veillardc0826a72004-08-10 14:17:33 +00009203 }
9204 attr = attr->next;
Daniel Veillard01fa6152004-06-29 17:04:39 +00009205 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009206 } else {
Daniel Veillardc0826a72004-08-10 14:17:33 +00009207 /*
9208 * Parse as global simple type definition.
Kasimier T. Buchcik87876402004-09-29 13:29:03 +00009209 *
9210 * Note that attrValue is the value of the attribute "name" here.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009211 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009212 type = xmlSchemaAddType(ctxt, schema, XML_SCHEMA_TYPE_SIMPLE,
9213 attrValue, ctxt->targetNamespace, node, 1);
Daniel Veillardc0826a72004-08-10 14:17:33 +00009214 if (type == NULL)
9215 return (NULL);
Daniel Veillardc0826a72004-08-10 14:17:33 +00009216 type->type = XML_SCHEMA_TYPE_SIMPLE;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009217 type->contentType = XML_SCHEMA_CONTENT_SIMPLE;
Daniel Veillardc0826a72004-08-10 14:17:33 +00009218 type->flags |= XML_SCHEMAS_TYPE_GLOBAL;
9219 /*
9220 * Check for illegal attributes.
9221 */
9222 attr = node->properties;
9223 while (attr != NULL) {
9224 if (attr->ns == NULL) {
9225 if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
9226 (!xmlStrEqual(attr->name, BAD_CAST "name")) &&
Kasimier T. Buchcik87876402004-09-29 13:29:03 +00009227 (!xmlStrEqual(attr->name, BAD_CAST "final"))) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009228 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009229 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Daniel Veillardc0826a72004-08-10 14:17:33 +00009230 }
9231 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009232 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009233 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Daniel Veillardc0826a72004-08-10 14:17:33 +00009234 }
9235 attr = attr->next;
9236 }
9237 /*
9238 * Attribute "final".
9239 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009240 attr = xmlSchemaGetPropNode(node, "final");
Daniel Veillardc0826a72004-08-10 14:17:33 +00009241 if (attr == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009242 if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION)
9243 type->flags |= XML_SCHEMAS_TYPE_FINAL_RESTRICTION;
9244 if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_LIST)
9245 type->flags |= XML_SCHEMAS_TYPE_FINAL_LIST;
9246 if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_UNION)
9247 type->flags |= XML_SCHEMAS_TYPE_FINAL_UNION;
Daniel Veillardc0826a72004-08-10 14:17:33 +00009248 } else {
9249 attrValue = xmlSchemaGetProp(ctxt, node, "final");
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009250 if (xmlSchemaPValAttrBlockFinal(attrValue, &(type->flags),
9251 -1, -1, XML_SCHEMAS_TYPE_FINAL_RESTRICTION, -1,
Daniel Veillardc0826a72004-08-10 14:17:33 +00009252 XML_SCHEMAS_TYPE_FINAL_LIST,
9253 XML_SCHEMAS_TYPE_FINAL_UNION) != 0) {
9254
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009255 xmlSchemaPSimpleTypeErr(ctxt,
Daniel Veillardc0826a72004-08-10 14:17:33 +00009256 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009257 WXS_BASIC_CAST type, (xmlNodePtr) attr,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009258 NULL, "(#all | List of (list | union | restriction)",
Daniel Veillardc0826a72004-08-10 14:17:33 +00009259 attrValue, NULL, NULL, NULL);
9260 }
9261 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009262 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009263 type->targetNamespace = ctxt->targetNamespace;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009264 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
Daniel Veillardc0826a72004-08-10 14:17:33 +00009265 /*
9266 * And now for the children...
9267 */
Kasimier T. Buchcik87876402004-09-29 13:29:03 +00009268 oldCtxtType = ctxt->ctxtType;
Daniel Veillarddee23482008-04-11 12:58:43 +00009269
Daniel Veillardc0826a72004-08-10 14:17:33 +00009270 ctxt->ctxtType = type;
Daniel Veillarddee23482008-04-11 12:58:43 +00009271
Daniel Veillard4255d502002-04-16 15:50:10 +00009272 child = node->children;
9273 if (IS_SCHEMA(child, "annotation")) {
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +00009274 type->annot = xmlSchemaParseAnnotation(ctxt, child, 1);
Daniel Veillardd0c9c322003-10-10 00:49:42 +00009275 child = child->next;
Daniel Veillard4255d502002-04-16 15:50:10 +00009276 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009277 if (child == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009278 xmlSchemaPContentErr(ctxt, XML_SCHEMAP_S4S_ELEM_MISSING,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009279 NULL, node, child, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009280 "(annotation?, (restriction | list | union))");
Daniel Veillarddee23482008-04-11 12:58:43 +00009281 } else if (IS_SCHEMA(child, "restriction")) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009282 xmlSchemaParseRestriction(ctxt, schema, child,
Daniel Veillarddee23482008-04-11 12:58:43 +00009283 XML_SCHEMA_TYPE_SIMPLE);
9284 hasRestriction = 1;
Daniel Veillardd0c9c322003-10-10 00:49:42 +00009285 child = child->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009286 } else if (IS_SCHEMA(child, "list")) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009287 xmlSchemaParseList(ctxt, schema, child);
Daniel Veillardd0c9c322003-10-10 00:49:42 +00009288 child = child->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009289 } else if (IS_SCHEMA(child, "union")) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009290 xmlSchemaParseUnion(ctxt, schema, child);
Daniel Veillardd0c9c322003-10-10 00:49:42 +00009291 child = child->next;
Daniel Veillard4255d502002-04-16 15:50:10 +00009292 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009293 if (child != NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009294 xmlSchemaPContentErr(ctxt, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009295 NULL, node, child, NULL,
Daniel Veillardc0826a72004-08-10 14:17:33 +00009296 "(annotation?, (restriction | list | union))");
Daniel Veillard4255d502002-04-16 15:50:10 +00009297 }
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +00009298 /*
9299 * REDEFINE: SPEC src-redefine (5)
9300 * "Within the [children], each <simpleType> must have a
Rob Richardsc6947bb2008-06-29 15:04:41 +00009301 * <restriction> among its [children] ... the �actual value� of whose
9302 * base [attribute] must be the same as the �actual value� of its own
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +00009303 * name attribute plus target namespace;"
9304 */
9305 if (topLevel && ctxt->isRedefine && (! hasRestriction)) {
9306 xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_SRC_REDEFINE,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009307 NULL, node, "This is a redefinition, thus the "
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +00009308 "<simpleType> must have a <restriction> child", NULL);
9309 }
Daniel Veillarddee23482008-04-11 12:58:43 +00009310
Kasimier T. Buchcik87876402004-09-29 13:29:03 +00009311 ctxt->ctxtType = oldCtxtType;
Daniel Veillard4255d502002-04-16 15:50:10 +00009312 return (type);
9313}
9314
Daniel Veillard4255d502002-04-16 15:50:10 +00009315/**
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009316 * xmlSchemaParseModelGroupDefRef:
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009317 * @ctxt: the parser context
9318 * @schema: the schema being built
9319 * @node: the node
Daniel Veillard4255d502002-04-16 15:50:10 +00009320 *
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009321 * Parses a reference to a model group definition.
Daniel Veillard4255d502002-04-16 15:50:10 +00009322 *
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009323 * We will return a particle component with a qname-component or
9324 * NULL in case of an error.
Daniel Veillard4255d502002-04-16 15:50:10 +00009325 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009326static xmlSchemaTreeItemPtr
9327xmlSchemaParseModelGroupDefRef(xmlSchemaParserCtxtPtr ctxt,
9328 xmlSchemaPtr schema,
9329 xmlNodePtr node)
Daniel Veillard4255d502002-04-16 15:50:10 +00009330{
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009331 xmlSchemaParticlePtr item;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009332 xmlNodePtr child = NULL;
Kasimier T. Buchcikb474fa42005-03-11 12:34:42 +00009333 xmlAttrPtr attr;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009334 const xmlChar *ref = NULL, *refNs = NULL;
9335 int min, max;
9336
9337 if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009338 return (NULL);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009339
9340 attr = xmlSchemaGetPropNode(node, "ref");
9341 if (attr == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009342 xmlSchemaPMissingAttrErr(ctxt,
9343 XML_SCHEMAP_S4S_ATTR_MISSING,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009344 NULL, node, "ref", NULL);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009345 return (NULL);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009346 } else if (xmlSchemaPValAttrNodeQName(ctxt, schema, NULL,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009347 attr, &refNs, &ref) != 0) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009348 return (NULL);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009349 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009350 xmlSchemaCheckReference(ctxt, schema, node, attr, refNs);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009351 min = xmlGetMinOccurs(ctxt, node, 0, -1, 1, "xs:nonNegativeInteger");
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009352 max = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009353 "(xs:nonNegativeInteger | unbounded)");
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009354 /*
9355 * Check for illegal attributes.
9356 */
9357 attr = node->properties;
9358 while (attr != NULL) {
9359 if (attr->ns == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009360 if ((!xmlStrEqual(attr->name, BAD_CAST "ref")) &&
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009361 (!xmlStrEqual(attr->name, BAD_CAST "id")) &&
9362 (!xmlStrEqual(attr->name, BAD_CAST "minOccurs")) &&
9363 (!xmlStrEqual(attr->name, BAD_CAST "maxOccurs"))) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009364 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009365 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009366 }
9367 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009368 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009369 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009370 }
9371 attr = attr->next;
9372 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009373 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
Kasimier T. Buchcik4c0aa162006-02-20 14:47:08 +00009374 item = xmlSchemaAddParticle(ctxt, node, min, max);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009375 if (item == NULL)
Daniel Veillarddee23482008-04-11 12:58:43 +00009376 return (NULL);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009377 /*
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009378 * Create a qname-reference and set as the term; it will be substituted
9379 * for the model group after the reference has been resolved.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009380 */
9381 item->children = (xmlSchemaTreeItemPtr)
Daniel Veillarddee23482008-04-11 12:58:43 +00009382 xmlSchemaNewQNameRef(ctxt, XML_SCHEMA_TYPE_GROUP, ref, refNs);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009383 xmlSchemaPCheckParticleCorrect_2(ctxt, item, node, min, max);
9384 /*
9385 * And now for the children...
9386 */
9387 child = node->children;
9388 /* TODO: Is annotation even allowed for a model group reference? */
9389 if (IS_SCHEMA(child, "annotation")) {
9390 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009391 * TODO: What to do exactly with the annotation?
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009392 */
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +00009393 item->annot = xmlSchemaParseAnnotation(ctxt, child, 1);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009394 child = child->next;
9395 }
9396 if (child != NULL) {
9397 xmlSchemaPContentErr(ctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009398 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009399 NULL, node, child, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009400 "(annotation?)");
9401 }
9402 /*
9403 * Corresponds to no component at all if minOccurs==maxOccurs==0.
9404 */
9405 if ((min == 0) && (max == 0))
9406 return (NULL);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009407
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009408 return ((xmlSchemaTreeItemPtr) item);
9409}
9410
9411/**
9412 * xmlSchemaParseModelGroupDefinition:
9413 * @ctxt: a schema validation context
9414 * @schema: the schema being built
9415 * @node: a subtree containing XML Schema informations
9416 *
9417 * Parses a XML schema model group definition.
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009418 *
9419 * Note that the contraint src-redefine (6.2) can't be applied until
9420 * references have been resolved. So we will do this at the
9421 * component fixup level.
Daniel Veillarddee23482008-04-11 12:58:43 +00009422 *
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009423 * *WARNING* this interface is highly subject to change
9424 *
9425 * Returns -1 in case of error, 0 if the declaration is improper and
9426 * 1 in case of success.
9427 */
9428static xmlSchemaModelGroupDefPtr
9429xmlSchemaParseModelGroupDefinition(xmlSchemaParserCtxtPtr ctxt,
9430 xmlSchemaPtr schema,
9431 xmlNodePtr node)
9432{
9433 xmlSchemaModelGroupDefPtr item;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009434 xmlNodePtr child = NULL;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009435 xmlAttrPtr attr;
9436 const xmlChar *name;
Daniel Veillard4255d502002-04-16 15:50:10 +00009437
9438 if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009439 return (NULL);
9440
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009441 attr = xmlSchemaGetPropNode(node, "name");
9442 if (attr == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009443 xmlSchemaPMissingAttrErr(ctxt,
9444 XML_SCHEMAP_S4S_ATTR_MISSING,
9445 NULL, node,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009446 "name", NULL);
9447 return (NULL);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009448 } else if (xmlSchemaPValAttrNode(ctxt, NULL, attr,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009449 xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) {
9450 return (NULL);
9451 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009452 item = xmlSchemaAddModelGroupDefinition(ctxt, schema, name,
9453 ctxt->targetNamespace, node);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009454 if (item == NULL)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009455 return (NULL);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009456 /*
9457 * Check for illegal attributes.
9458 */
9459 attr = node->properties;
9460 while (attr != NULL) {
9461 if (attr->ns == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009462 if ((!xmlStrEqual(attr->name, BAD_CAST "name")) &&
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009463 (!xmlStrEqual(attr->name, BAD_CAST "id"))) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009464 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009465 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Kasimier T. Buchcikb474fa42005-03-11 12:34:42 +00009466 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009467 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009468 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009469 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Kasimier T. Buchcikb474fa42005-03-11 12:34:42 +00009470 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009471 attr = attr->next;
9472 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009473 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009474 /*
9475 * And now for the children...
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009476 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009477 child = node->children;
9478 if (IS_SCHEMA(child, "annotation")) {
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +00009479 item->annot = xmlSchemaParseAnnotation(ctxt, child, 1);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009480 child = child->next;
9481 }
9482 if (IS_SCHEMA(child, "all")) {
9483 item->children = xmlSchemaParseModelGroup(ctxt, schema, child,
9484 XML_SCHEMA_TYPE_ALL, 0);
9485 child = child->next;
9486 } else if (IS_SCHEMA(child, "choice")) {
9487 item->children = xmlSchemaParseModelGroup(ctxt, schema, child,
9488 XML_SCHEMA_TYPE_CHOICE, 0);
9489 child = child->next;
9490 } else if (IS_SCHEMA(child, "sequence")) {
9491 item->children = xmlSchemaParseModelGroup(ctxt, schema, child,
9492 XML_SCHEMA_TYPE_SEQUENCE, 0);
9493 child = child->next;
9494 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009495
Daniel Veillarddee23482008-04-11 12:58:43 +00009496
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009497
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009498 if (child != NULL) {
9499 xmlSchemaPContentErr(ctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009500 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009501 NULL, node, child, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009502 "(annotation?, (all | choice | sequence)?)");
Kasimier T. Buchcikb474fa42005-03-11 12:34:42 +00009503 }
Kasimier T. Buchcikb474fa42005-03-11 12:34:42 +00009504 return (item);
Daniel Veillard4255d502002-04-16 15:50:10 +00009505}
9506
9507/**
Daniel Veillardbd2904b2003-11-25 15:38:59 +00009508 * xmlSchemaCleanupDoc:
9509 * @ctxt: a schema validation context
9510 * @node: the root of the document.
9511 *
9512 * removes unwanted nodes in a schemas document tree
9513 */
9514static void
9515xmlSchemaCleanupDoc(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr root)
9516{
9517 xmlNodePtr delete, cur;
9518
9519 if ((ctxt == NULL) || (root == NULL)) return;
9520
9521 /*
9522 * Remove all the blank text nodes
9523 */
9524 delete = NULL;
9525 cur = root;
9526 while (cur != NULL) {
9527 if (delete != NULL) {
9528 xmlUnlinkNode(delete);
9529 xmlFreeNode(delete);
9530 delete = NULL;
9531 }
9532 if (cur->type == XML_TEXT_NODE) {
9533 if (IS_BLANK_NODE(cur)) {
9534 if (xmlNodeGetSpacePreserve(cur) != 1) {
9535 delete = cur;
9536 }
9537 }
9538 } else if ((cur->type != XML_ELEMENT_NODE) &&
9539 (cur->type != XML_CDATA_SECTION_NODE)) {
9540 delete = cur;
9541 goto skip_children;
9542 }
9543
9544 /*
9545 * Skip to next node
9546 */
9547 if (cur->children != NULL) {
9548 if ((cur->children->type != XML_ENTITY_DECL) &&
9549 (cur->children->type != XML_ENTITY_REF_NODE) &&
9550 (cur->children->type != XML_ENTITY_NODE)) {
9551 cur = cur->children;
9552 continue;
9553 }
9554 }
9555 skip_children:
9556 if (cur->next != NULL) {
9557 cur = cur->next;
9558 continue;
9559 }
9560
9561 do {
9562 cur = cur->parent;
9563 if (cur == NULL)
9564 break;
9565 if (cur == root) {
9566 cur = NULL;
9567 break;
9568 }
9569 if (cur->next != NULL) {
9570 cur = cur->next;
9571 break;
9572 }
9573 } while (cur != NULL);
9574 }
9575 if (delete != NULL) {
9576 xmlUnlinkNode(delete);
9577 xmlFreeNode(delete);
9578 delete = NULL;
9579 }
9580}
9581
William M. Brack2f2a6632004-08-20 23:09:47 +00009582
William M. Brack2f2a6632004-08-20 23:09:47 +00009583static void
9584xmlSchemaClearSchemaDefaults(xmlSchemaPtr schema)
9585{
9586 if (schema->flags & XML_SCHEMAS_QUALIF_ELEM)
9587 schema->flags ^= XML_SCHEMAS_QUALIF_ELEM;
9588
9589 if (schema->flags & XML_SCHEMAS_QUALIF_ATTR)
9590 schema->flags ^= XML_SCHEMAS_QUALIF_ATTR;
9591
9592 if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_EXTENSION)
9593 schema->flags ^= XML_SCHEMAS_FINAL_DEFAULT_EXTENSION;
9594 if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION)
9595 schema->flags ^= XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION;
9596 if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_LIST)
9597 schema->flags ^= XML_SCHEMAS_FINAL_DEFAULT_LIST;
9598 if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_UNION)
9599 schema->flags ^= XML_SCHEMAS_FINAL_DEFAULT_UNION;
9600
9601 if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION)
9602 schema->flags ^= XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION;
9603 if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION)
9604 schema->flags ^= XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION;
9605 if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION)
9606 schema->flags ^= XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION;
9607}
9608
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009609static int
9610xmlSchemaParseSchemaElement(xmlSchemaParserCtxtPtr ctxt,
William M. Brack2f2a6632004-08-20 23:09:47 +00009611 xmlSchemaPtr schema,
9612 xmlNodePtr node)
9613{
9614 xmlAttrPtr attr;
9615 const xmlChar *val;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009616 int res = 0, oldErrs = ctxt->nberrors;
William M. Brack2f2a6632004-08-20 23:09:47 +00009617
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009618 /*
9619 * Those flags should be moved to the parser context flags,
9620 * since they are not visible at the component level. I.e.
9621 * they are used if processing schema *documents* only.
9622 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009623 res = xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009624 HFAILURE;
Kasimier T. Buchcikb474fa42005-03-11 12:34:42 +00009625
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009626 /*
9627 * Since the version is of type xs:token, we won't bother to
9628 * check it.
9629 */
9630 /* REMOVED:
9631 attr = xmlSchemaGetPropNode(node, "version");
9632 if (attr != NULL) {
9633 res = xmlSchemaPValAttrNode(ctxt, NULL, NULL, attr,
Daniel Veillarddee23482008-04-11 12:58:43 +00009634 xmlSchemaGetBuiltInType(XML_SCHEMAS_TOKEN), &val);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009635 HFAILURE;
9636 }
9637 */
9638 attr = xmlSchemaGetPropNode(node, "targetNamespace");
9639 if (attr != NULL) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009640 res = xmlSchemaPValAttrNode(ctxt, NULL, attr,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009641 xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), NULL);
9642 HFAILURE;
9643 if (res != 0) {
9644 ctxt->stop = XML_SCHEMAP_S4S_ATTR_INVALID_VALUE;
9645 goto exit;
9646 }
9647 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009648 attr = xmlSchemaGetPropNode(node, "elementFormDefault");
William M. Brack2f2a6632004-08-20 23:09:47 +00009649 if (attr != NULL) {
9650 val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009651 res = xmlSchemaPValAttrFormDefault(val, &schema->flags,
9652 XML_SCHEMAS_QUALIF_ELEM);
9653 HFAILURE;
9654 if (res != 0) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009655 xmlSchemaPSimpleTypeErr(ctxt,
William M. Brack2f2a6632004-08-20 23:09:47 +00009656 XML_SCHEMAP_ELEMFORMDEFAULT_VALUE,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009657 NULL, (xmlNodePtr) attr, NULL,
William M. Brack2f2a6632004-08-20 23:09:47 +00009658 "(qualified | unqualified)", val, NULL, NULL, NULL);
9659 }
9660 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009661 attr = xmlSchemaGetPropNode(node, "attributeFormDefault");
William M. Brack2f2a6632004-08-20 23:09:47 +00009662 if (attr != NULL) {
9663 val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009664 res = xmlSchemaPValAttrFormDefault(val, &schema->flags,
9665 XML_SCHEMAS_QUALIF_ATTR);
9666 HFAILURE;
9667 if (res != 0) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009668 xmlSchemaPSimpleTypeErr(ctxt,
William M. Brack2f2a6632004-08-20 23:09:47 +00009669 XML_SCHEMAP_ATTRFORMDEFAULT_VALUE,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009670 NULL, (xmlNodePtr) attr, NULL,
William M. Brack2f2a6632004-08-20 23:09:47 +00009671 "(qualified | unqualified)", val, NULL, NULL, NULL);
9672 }
9673 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009674 attr = xmlSchemaGetPropNode(node, "finalDefault");
William M. Brack2f2a6632004-08-20 23:09:47 +00009675 if (attr != NULL) {
9676 val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009677 res = xmlSchemaPValAttrBlockFinal(val, &(schema->flags), -1,
William M. Brack2f2a6632004-08-20 23:09:47 +00009678 XML_SCHEMAS_FINAL_DEFAULT_EXTENSION,
9679 XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION,
9680 -1,
9681 XML_SCHEMAS_FINAL_DEFAULT_LIST,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009682 XML_SCHEMAS_FINAL_DEFAULT_UNION);
9683 HFAILURE;
9684 if (res != 0) {
William M. Brack2f2a6632004-08-20 23:09:47 +00009685 xmlSchemaPSimpleTypeErr(ctxt,
9686 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009687 NULL, (xmlNodePtr) attr, NULL,
William M. Brack2f2a6632004-08-20 23:09:47 +00009688 "(#all | List of (extension | restriction | list | union))",
9689 val, NULL, NULL, NULL);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009690 }
William M. Brack2f2a6632004-08-20 23:09:47 +00009691 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009692 attr = xmlSchemaGetPropNode(node, "blockDefault");
William M. Brack2f2a6632004-08-20 23:09:47 +00009693 if (attr != NULL) {
Daniel Veillarddee23482008-04-11 12:58:43 +00009694 val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009695 res = xmlSchemaPValAttrBlockFinal(val, &(schema->flags), -1,
William M. Brack2f2a6632004-08-20 23:09:47 +00009696 XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION,
9697 XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009698 XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION, -1, -1);
9699 HFAILURE;
9700 if (res != 0) {
9701 xmlSchemaPSimpleTypeErr(ctxt,
William M. Brack2f2a6632004-08-20 23:09:47 +00009702 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009703 NULL, (xmlNodePtr) attr, NULL,
William M. Brack2f2a6632004-08-20 23:09:47 +00009704 "(#all | List of (extension | restriction | substitution))",
9705 val, NULL, NULL, NULL);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009706 }
William M. Brack2f2a6632004-08-20 23:09:47 +00009707 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009708
9709exit:
9710 if (oldErrs != ctxt->nberrors)
9711 res = ctxt->err;
9712 return(res);
9713exit_failure:
9714 return(-1);
William M. Brack2f2a6632004-08-20 23:09:47 +00009715}
9716
Daniel Veillardbd2904b2003-11-25 15:38:59 +00009717/**
9718 * xmlSchemaParseSchemaTopLevel:
9719 * @ctxt: a schema validation context
9720 * @schema: the schemas
9721 * @nodes: the list of top level nodes
9722 *
9723 * Returns the internal XML Schema structure built from the resource or
9724 * NULL in case of error
9725 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009726static int
Daniel Veillardbd2904b2003-11-25 15:38:59 +00009727xmlSchemaParseSchemaTopLevel(xmlSchemaParserCtxtPtr ctxt,
9728 xmlSchemaPtr schema, xmlNodePtr nodes)
9729{
9730 xmlNodePtr child;
9731 xmlSchemaAnnotPtr annot;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009732 int res = 0, oldErrs, tmpOldErrs;
Daniel Veillardbd2904b2003-11-25 15:38:59 +00009733
9734 if ((ctxt == NULL) || (schema == NULL) || (nodes == NULL))
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009735 return(-1);
Daniel Veillardbd2904b2003-11-25 15:38:59 +00009736
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009737 oldErrs = ctxt->nberrors;
Daniel Veillardbd2904b2003-11-25 15:38:59 +00009738 child = nodes;
9739 while ((IS_SCHEMA(child, "include")) ||
9740 (IS_SCHEMA(child, "import")) ||
9741 (IS_SCHEMA(child, "redefine")) ||
9742 (IS_SCHEMA(child, "annotation"))) {
9743 if (IS_SCHEMA(child, "annotation")) {
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +00009744 annot = xmlSchemaParseAnnotation(ctxt, child, 1);
Daniel Veillardbd2904b2003-11-25 15:38:59 +00009745 if (schema->annot == NULL)
9746 schema->annot = annot;
9747 else
9748 xmlSchemaFreeAnnot(annot);
9749 } else if (IS_SCHEMA(child, "import")) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009750 tmpOldErrs = ctxt->nberrors;
9751 res = xmlSchemaParseImport(ctxt, schema, child);
9752 HFAILURE;
9753 HSTOP(ctxt);
9754 if (tmpOldErrs != ctxt->nberrors)
Daniel Veillarddee23482008-04-11 12:58:43 +00009755 goto exit;
Daniel Veillardbd2904b2003-11-25 15:38:59 +00009756 } else if (IS_SCHEMA(child, "include")) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009757 tmpOldErrs = ctxt->nberrors;
9758 res = xmlSchemaParseInclude(ctxt, schema, child);
9759 HFAILURE;
9760 HSTOP(ctxt);
9761 if (tmpOldErrs != ctxt->nberrors)
Daniel Veillarddee23482008-04-11 12:58:43 +00009762 goto exit;
Daniel Veillardbd2904b2003-11-25 15:38:59 +00009763 } else if (IS_SCHEMA(child, "redefine")) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009764 tmpOldErrs = ctxt->nberrors;
9765 res = xmlSchemaParseRedefine(ctxt, schema, child);
9766 HFAILURE;
9767 HSTOP(ctxt);
9768 if (tmpOldErrs != ctxt->nberrors)
9769 goto exit;
Daniel Veillardbd2904b2003-11-25 15:38:59 +00009770 }
9771 child = child->next;
9772 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009773 /*
9774 * URGENT TODO: Change the functions to return int results.
9775 * We need especially to catch internal errors.
9776 */
Daniel Veillardbd2904b2003-11-25 15:38:59 +00009777 while (child != NULL) {
9778 if (IS_SCHEMA(child, "complexType")) {
Daniel Veillard3646d642004-06-02 19:19:14 +00009779 xmlSchemaParseComplexType(ctxt, schema, child, 1);
Daniel Veillardbd2904b2003-11-25 15:38:59 +00009780 child = child->next;
9781 } else if (IS_SCHEMA(child, "simpleType")) {
Daniel Veillard3646d642004-06-02 19:19:14 +00009782 xmlSchemaParseSimpleType(ctxt, schema, child, 1);
Daniel Veillardbd2904b2003-11-25 15:38:59 +00009783 child = child->next;
9784 } else if (IS_SCHEMA(child, "element")) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009785 xmlSchemaParseElement(ctxt, schema, child, NULL, 1);
Daniel Veillardbd2904b2003-11-25 15:38:59 +00009786 child = child->next;
9787 } else if (IS_SCHEMA(child, "attribute")) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009788 xmlSchemaParseGlobalAttribute(ctxt, schema, child);
Daniel Veillardbd2904b2003-11-25 15:38:59 +00009789 child = child->next;
9790 } else if (IS_SCHEMA(child, "attributeGroup")) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009791 xmlSchemaParseAttributeGroupDefinition(ctxt, schema, child);
Daniel Veillardbd2904b2003-11-25 15:38:59 +00009792 child = child->next;
9793 } else if (IS_SCHEMA(child, "group")) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +00009794 xmlSchemaParseModelGroupDefinition(ctxt, schema, child);
Daniel Veillardbd2904b2003-11-25 15:38:59 +00009795 child = child->next;
9796 } else if (IS_SCHEMA(child, "notation")) {
9797 xmlSchemaParseNotation(ctxt, schema, child);
9798 child = child->next;
9799 } else {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009800 xmlSchemaPContentErr(ctxt,
9801 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009802 NULL, child->parent, child,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009803 NULL, "((include | import | redefine | annotation)*, "
9804 "(((simpleType | complexType | group | attributeGroup) "
9805 "| element | attribute | notation), annotation*)*)");
Daniel Veillardbd2904b2003-11-25 15:38:59 +00009806 child = child->next;
9807 }
9808 while (IS_SCHEMA(child, "annotation")) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009809 /*
9810 * TODO: We should add all annotations.
9811 */
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +00009812 annot = xmlSchemaParseAnnotation(ctxt, child, 1);
Daniel Veillardbd2904b2003-11-25 15:38:59 +00009813 if (schema->annot == NULL)
9814 schema->annot = annot;
9815 else
9816 xmlSchemaFreeAnnot(annot);
9817 child = child->next;
9818 }
9819 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009820exit:
Daniel Veillard01fa6152004-06-29 17:04:39 +00009821 ctxt->ctxtType = NULL;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009822 if (oldErrs != ctxt->nberrors)
9823 res = ctxt->err;
9824 return(res);
9825exit_failure:
9826 return(-1);
Daniel Veillardbd2904b2003-11-25 15:38:59 +00009827}
9828
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009829static xmlSchemaSchemaRelationPtr
9830xmlSchemaSchemaRelationCreate(void)
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +00009831{
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009832 xmlSchemaSchemaRelationPtr ret;
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +00009833
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009834 ret = (xmlSchemaSchemaRelationPtr)
9835 xmlMalloc(sizeof(xmlSchemaSchemaRelation));
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +00009836 if (ret == NULL) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009837 xmlSchemaPErrMemory(NULL, "allocating schema relation", NULL);
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +00009838 return(NULL);
9839 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009840 memset(ret, 0, sizeof(xmlSchemaSchemaRelation));
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +00009841 return(ret);
9842}
9843
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009844#if 0
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +00009845static void
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009846xmlSchemaSchemaRelationFree(xmlSchemaSchemaRelationPtr rel)
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +00009847{
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009848 xmlFree(rel);
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +00009849}
9850#endif
9851
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009852static void
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009853xmlSchemaRedefListFree(xmlSchemaRedefPtr redef)
9854{
9855 xmlSchemaRedefPtr prev;
9856
9857 while (redef != NULL) {
9858 prev = redef;
9859 redef = redef->next;
9860 xmlFree(prev);
9861 }
9862}
9863
9864static void
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009865xmlSchemaConstructionCtxtFree(xmlSchemaConstructionCtxtPtr con)
9866{
9867 /*
9868 * After the construction context has been freed, there will be
9869 * no schema graph available any more. Only the schema buckets
9870 * will stay alive, which are put into the "schemasImports" and
9871 * "includes" slots of the xmlSchema.
9872 */
9873 if (con->buckets != NULL)
9874 xmlSchemaItemListFree(con->buckets);
9875 if (con->pending != NULL)
9876 xmlSchemaItemListFree(con->pending);
9877 if (con->substGroups != NULL)
9878 xmlHashFree(con->substGroups,
9879 (xmlHashDeallocator) xmlSchemaSubstGroupFree);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009880 if (con->redefs != NULL)
9881 xmlSchemaRedefListFree(con->redefs);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009882 if (con->dict != NULL)
9883 xmlDictFree(con->dict);
9884 xmlFree(con);
9885}
9886
Daniel Veillarddee23482008-04-11 12:58:43 +00009887static xmlSchemaConstructionCtxtPtr
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009888xmlSchemaConstructionCtxtCreate(xmlDictPtr dict)
9889{
9890 xmlSchemaConstructionCtxtPtr ret;
9891
9892 ret = (xmlSchemaConstructionCtxtPtr)
9893 xmlMalloc(sizeof(xmlSchemaConstructionCtxt));
9894 if (ret == NULL) {
9895 xmlSchemaPErrMemory(NULL,
9896 "allocating schema construction context", NULL);
9897 return (NULL);
9898 }
9899 memset(ret, 0, sizeof(xmlSchemaConstructionCtxt));
9900
9901 ret->buckets = xmlSchemaItemListCreate();
9902 if (ret->buckets == NULL) {
9903 xmlSchemaPErrMemory(NULL,
9904 "allocating list of schema buckets", NULL);
9905 xmlFree(ret);
9906 return (NULL);
9907 }
9908 ret->pending = xmlSchemaItemListCreate();
9909 if (ret->pending == NULL) {
9910 xmlSchemaPErrMemory(NULL,
9911 "allocating list of pending global components", NULL);
9912 xmlSchemaConstructionCtxtFree(ret);
9913 return (NULL);
9914 }
9915 ret->dict = dict;
9916 xmlDictReference(dict);
9917 return(ret);
9918}
9919
Kasimier T. Buchcik630215b2005-08-22 10:15:39 +00009920static xmlSchemaParserCtxtPtr
9921xmlSchemaParserCtxtCreate(void)
9922{
9923 xmlSchemaParserCtxtPtr ret;
9924
9925 ret = (xmlSchemaParserCtxtPtr) xmlMalloc(sizeof(xmlSchemaParserCtxt));
9926 if (ret == NULL) {
9927 xmlSchemaPErrMemory(NULL, "allocating schema parser context",
9928 NULL);
9929 return (NULL);
9930 }
9931 memset(ret, 0, sizeof(xmlSchemaParserCtxt));
9932 ret->type = XML_SCHEMA_CTXT_PARSER;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +00009933 ret->attrProhibs = xmlSchemaItemListCreate();
9934 if (ret->attrProhibs == NULL) {
9935 xmlFree(ret);
9936 return(NULL);
9937 }
Kasimier T. Buchcik630215b2005-08-22 10:15:39 +00009938 return(ret);
9939}
9940
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009941/**
9942 * xmlSchemaNewParserCtxtUseDict:
9943 * @URL: the location of the schema
9944 * @dict: the dictionary to be used
9945 *
9946 * Create an XML Schemas parse context for that file/resource expected
9947 * to contain an XML Schemas file.
9948 *
9949 * Returns the parser context or NULL in case of error
9950 */
9951static xmlSchemaParserCtxtPtr
9952xmlSchemaNewParserCtxtUseDict(const char *URL, xmlDictPtr dict)
9953{
9954 xmlSchemaParserCtxtPtr ret;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009955
Kasimier T. Buchcik630215b2005-08-22 10:15:39 +00009956 ret = xmlSchemaParserCtxtCreate();
Daniel Veillarddee23482008-04-11 12:58:43 +00009957 if (ret == NULL)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009958 return (NULL);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009959 ret->dict = dict;
Daniel Veillarddee23482008-04-11 12:58:43 +00009960 xmlDictReference(dict);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009961 if (URL != NULL)
9962 ret->URL = xmlDictLookup(dict, (const xmlChar *) URL, -1);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009963 return (ret);
9964}
9965
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +00009966static int
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009967xmlSchemaCreatePCtxtOnVCtxt(xmlSchemaValidCtxtPtr vctxt)
9968{
9969 if (vctxt->pctxt == NULL) {
9970 if (vctxt->schema != NULL)
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009971 vctxt->pctxt =
9972 xmlSchemaNewParserCtxtUseDict("*", vctxt->schema->dict);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009973 else
9974 vctxt->pctxt = xmlSchemaNewParserCtxt("*");
9975 if (vctxt->pctxt == NULL) {
9976 VERROR_INT("xmlSchemaCreatePCtxtOnVCtxt",
9977 "failed to create a temp. parser context");
9978 return (-1);
9979 }
9980 /* TODO: Pass user data. */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009981 xmlSchemaSetParserErrors(vctxt->pctxt, vctxt->error,
Kasimier T. Buchcik90b5ebc2005-11-18 17:18:27 +00009982 vctxt->warning, vctxt->errCtxt);
9983 xmlSchemaSetParserStructuredErrors(vctxt->pctxt, vctxt->serror,
9984 vctxt->errCtxt);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +00009985 }
9986 return (0);
9987}
9988
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +00009989/**
9990 * xmlSchemaGetSchemaBucket:
9991 * @pctxt: the schema parser context
9992 * @schemaLocation: the URI of the schema document
9993 *
9994 * Returns a schema bucket if it was already parsed.
9995 *
9996 * Returns a schema bucket if it was already parsed from
9997 * @schemaLocation, NULL otherwise.
9998 */
9999static xmlSchemaBucketPtr
10000xmlSchemaGetSchemaBucket(xmlSchemaParserCtxtPtr pctxt,
10001 const xmlChar *schemaLocation)
10002{
10003 xmlSchemaBucketPtr cur;
10004 xmlSchemaItemListPtr list;
10005
10006 list = pctxt->constructor->buckets;
10007 if (list->nbItems == 0)
10008 return(NULL);
10009 else {
10010 int i;
10011 for (i = 0; i < list->nbItems; i++) {
10012 cur = (xmlSchemaBucketPtr) list->items[i];
10013 /* Pointer comparison! */
10014 if (cur->schemaLocation == schemaLocation)
10015 return(cur);
10016 }
10017 }
10018 return(NULL);
10019}
10020
10021static xmlSchemaBucketPtr
10022xmlSchemaGetChameleonSchemaBucket(xmlSchemaParserCtxtPtr pctxt,
10023 const xmlChar *schemaLocation,
10024 const xmlChar *targetNamespace)
10025{
10026 xmlSchemaBucketPtr cur;
10027 xmlSchemaItemListPtr list;
10028
10029 list = pctxt->constructor->buckets;
10030 if (list->nbItems == 0)
10031 return(NULL);
10032 else {
10033 int i;
10034 for (i = 0; i < list->nbItems; i++) {
10035 cur = (xmlSchemaBucketPtr) list->items[i];
10036 /* Pointer comparison! */
10037 if ((cur->origTargetNamespace == NULL) &&
10038 (cur->schemaLocation == schemaLocation) &&
10039 (cur->targetNamespace == targetNamespace))
10040 return(cur);
10041 }
10042 }
10043 return(NULL);
10044}
10045
10046
10047#define IS_BAD_SCHEMA_DOC(b) \
10048 (((b)->doc == NULL) && ((b)->schemaLocation != NULL))
10049
10050static xmlSchemaBucketPtr
10051xmlSchemaGetSchemaBucketByTNS(xmlSchemaParserCtxtPtr pctxt,
10052 const xmlChar *targetNamespace,
10053 int imported)
10054{
10055 xmlSchemaBucketPtr cur;
10056 xmlSchemaItemListPtr list;
10057
10058 list = pctxt->constructor->buckets;
10059 if (list->nbItems == 0)
10060 return(NULL);
10061 else {
10062 int i;
10063 for (i = 0; i < list->nbItems; i++) {
10064 cur = (xmlSchemaBucketPtr) list->items[i];
10065 if ((! IS_BAD_SCHEMA_DOC(cur)) &&
10066 (cur->origTargetNamespace == targetNamespace) &&
10067 ((imported && cur->imported) ||
10068 ((!imported) && (!cur->imported))))
10069 return(cur);
10070 }
10071 }
10072 return(NULL);
10073}
10074
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000010075static int
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010076xmlSchemaParseNewDocWithContext(xmlSchemaParserCtxtPtr pctxt,
10077 xmlSchemaPtr schema,
10078 xmlSchemaBucketPtr bucket)
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000010079{
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010080 int oldFlags;
10081 xmlDocPtr oldDoc;
10082 xmlNodePtr node;
10083 int ret, oldErrs;
10084 xmlSchemaBucketPtr oldbucket = pctxt->constructor->bucket;
Daniel Veillarddee23482008-04-11 12:58:43 +000010085
10086 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010087 * Save old values; reset the *main* schema.
10088 * URGENT TODO: This is not good; move the per-document information
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000010089 * to the parser. Get rid of passing the main schema to the
10090 * parsing functions.
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010091 */
10092 oldFlags = schema->flags;
10093 oldDoc = schema->doc;
10094 if (schema->flags != 0)
10095 xmlSchemaClearSchemaDefaults(schema);
Daniel Veillarddee23482008-04-11 12:58:43 +000010096 schema->doc = bucket->doc;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010097 pctxt->schema = schema;
Daniel Veillarddee23482008-04-11 12:58:43 +000010098 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010099 * Keep the current target namespace on the parser *not* on the
10100 * main schema.
10101 */
10102 pctxt->targetNamespace = bucket->targetNamespace;
10103 WXS_CONSTRUCTOR(pctxt)->bucket = bucket;
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000010104
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010105 if ((bucket->targetNamespace != NULL) &&
10106 xmlStrEqual(bucket->targetNamespace, xmlSchemaNs)) {
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000010107 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010108 * We are parsing the schema for schemas!
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000010109 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010110 pctxt->isS4S = 1;
Daniel Veillarddee23482008-04-11 12:58:43 +000010111 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010112 /* Mark it as parsed, even if parsing fails. */
10113 bucket->parsed++;
10114 /* Compile the schema doc. */
10115 node = xmlDocGetRootElement(bucket->doc);
10116 ret = xmlSchemaParseSchemaElement(pctxt, schema, node);
10117 if (ret != 0)
10118 goto exit;
10119 /* An empty schema; just get out. */
10120 if (node->children == NULL)
10121 goto exit;
10122 oldErrs = pctxt->nberrors;
10123 ret = xmlSchemaParseSchemaTopLevel(pctxt, schema, node->children);
10124 if (ret != 0)
10125 goto exit;
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000010126 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010127 * TODO: Not nice, but I'm not 100% sure we will get always an error
10128 * as a result of the obove functions; so better rely on pctxt->err
10129 * as well.
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000010130 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010131 if ((ret == 0) && (oldErrs != pctxt->nberrors)) {
10132 ret = pctxt->err;
10133 goto exit;
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000010134 }
Daniel Veillarddee23482008-04-11 12:58:43 +000010135
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010136exit:
10137 WXS_CONSTRUCTOR(pctxt)->bucket = oldbucket;
10138 /* Restore schema values. */
10139 schema->doc = oldDoc;
10140 schema->flags = oldFlags;
10141 return(ret);
10142}
10143
10144static int
10145xmlSchemaParseNewDoc(xmlSchemaParserCtxtPtr pctxt,
10146 xmlSchemaPtr schema,
10147 xmlSchemaBucketPtr bucket)
10148{
10149 xmlSchemaParserCtxtPtr newpctxt;
10150 int res = 0;
10151
10152 if (bucket == NULL)
10153 return(0);
10154 if (bucket->parsed) {
10155 PERROR_INT("xmlSchemaParseNewDoc",
10156 "reparsing a schema doc");
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000010157 return(-1);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000010158 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010159 if (bucket->doc == NULL) {
10160 PERROR_INT("xmlSchemaParseNewDoc",
10161 "parsing a schema doc, but there's no doc");
10162 return(-1);
Kasimier T. Buchcik5dd55d92004-11-26 12:35:21 +000010163 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010164 if (pctxt->constructor == NULL) {
10165 PERROR_INT("xmlSchemaParseNewDoc",
10166 "no constructor");
10167 return(-1);
Daniel Veillarddee23482008-04-11 12:58:43 +000010168 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010169 /* Create and init the temporary parser context. */
10170 newpctxt = xmlSchemaNewParserCtxtUseDict(
10171 (const char *) bucket->schemaLocation, pctxt->dict);
10172 if (newpctxt == NULL)
10173 return(-1);
10174 newpctxt->constructor = pctxt->constructor;
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000010175 /*
Daniel Veillarddee23482008-04-11 12:58:43 +000010176 * TODO: Can we avoid that the parser knows about the main schema?
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010177 * It would be better if he knows about the current schema bucket
10178 * only.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000010179 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010180 newpctxt->schema = schema;
10181 xmlSchemaSetParserErrors(newpctxt, pctxt->error, pctxt->warning,
Kasimier T. Buchcik90b5ebc2005-11-18 17:18:27 +000010182 pctxt->errCtxt);
10183 xmlSchemaSetParserStructuredErrors(newpctxt, pctxt->serror,
10184 pctxt->errCtxt);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010185 newpctxt->counter = pctxt->counter;
Daniel Veillarddee23482008-04-11 12:58:43 +000010186
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000010187
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010188 res = xmlSchemaParseNewDocWithContext(newpctxt, schema, bucket);
Daniel Veillarddee23482008-04-11 12:58:43 +000010189
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010190 /* Channel back errors and cleanup the temporary parser context. */
10191 if (res != 0)
10192 pctxt->err = res;
10193 pctxt->nberrors += newpctxt->nberrors;
10194 pctxt->counter = newpctxt->counter;
Daniel Veillarddee23482008-04-11 12:58:43 +000010195 newpctxt->constructor = NULL;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010196 /* Free the parser context. */
10197 xmlSchemaFreeParserCtxt(newpctxt);
10198 return(res);
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000010199}
William M. Brack2f2a6632004-08-20 23:09:47 +000010200
Kasimier T. Buchcikb474fa42005-03-11 12:34:42 +000010201static void
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010202xmlSchemaSchemaRelationAddChild(xmlSchemaBucketPtr bucket,
10203 xmlSchemaSchemaRelationPtr rel)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000010204{
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010205 xmlSchemaSchemaRelationPtr cur = bucket->relations;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000010206
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010207 if (cur == NULL) {
10208 bucket->relations = rel;
10209 return;
10210 }
10211 while (cur->next != NULL)
10212 cur = cur->next;
10213 cur->next = rel;
10214}
10215
10216
10217static const xmlChar *
10218xmlSchemaBuildAbsoluteURI(xmlDictPtr dict, const xmlChar* location,
10219 xmlNodePtr ctxtNode)
Daniel Veillarddee23482008-04-11 12:58:43 +000010220{
Kasimier T. Buchcikb474fa42005-03-11 12:34:42 +000010221 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010222 * Build an absolue location URI.
Kasimier T. Buchcikb474fa42005-03-11 12:34:42 +000010223 */
Daniel Veillarddee23482008-04-11 12:58:43 +000010224 if (location != NULL) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010225 if (ctxtNode == NULL)
10226 return(location);
10227 else {
10228 xmlChar *base, *URI;
10229 const xmlChar *ret = NULL;
Kasimier T. Buchcik630215b2005-08-22 10:15:39 +000010230
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010231 base = xmlNodeGetBase(ctxtNode->doc, ctxtNode);
10232 if (base == NULL) {
10233 URI = xmlBuildURI(location, ctxtNode->doc->URL);
10234 } else {
10235 URI = xmlBuildURI(location, base);
10236 xmlFree(base);
10237 }
10238 if (URI != NULL) {
10239 ret = xmlDictLookup(dict, URI, -1);
10240 xmlFree(URI);
10241 return(ret);
10242 }
10243 }
10244 }
10245 return(NULL);
10246}
Daniel Veillarddee23482008-04-11 12:58:43 +000010247
Kasimier T. Buchcik630215b2005-08-22 10:15:39 +000010248
Kasimier T. Buchcik630215b2005-08-22 10:15:39 +000010249
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010250/**
10251 * xmlSchemaAddSchemaDoc:
10252 * @pctxt: a schema validation context
10253 * @schema: the schema being built
10254 * @node: a subtree containing XML Schema informations
10255 *
10256 * Parse an included (and to-be-redefined) XML schema document.
10257 *
10258 * Returns 0 on success, a positive error code on errors and
10259 * -1 in case of an internal or API error.
10260 */
10261
10262static int
10263xmlSchemaAddSchemaDoc(xmlSchemaParserCtxtPtr pctxt,
10264 int type, /* import or include or redefine */
10265 const xmlChar *schemaLocation,
10266 xmlDocPtr schemaDoc,
10267 const char *schemaBuffer,
10268 int schemaBufferLen,
10269 xmlNodePtr invokingNode,
Daniel Veillarddee23482008-04-11 12:58:43 +000010270 const xmlChar *sourceTargetNamespace,
10271 const xmlChar *importNamespace,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010272 xmlSchemaBucketPtr *bucket)
10273{
10274 const xmlChar *targetNamespace = NULL;
10275 xmlSchemaSchemaRelationPtr relation = NULL;
10276 xmlDocPtr doc = NULL;
10277 int res = 0, err = 0, located = 0, preserveDoc = 0;
10278 xmlSchemaBucketPtr bkt = NULL;
10279
10280 if (bucket != NULL)
10281 *bucket = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000010282
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010283 switch (type) {
10284 case XML_SCHEMA_SCHEMA_IMPORT:
10285 case XML_SCHEMA_SCHEMA_MAIN:
10286 err = XML_SCHEMAP_SRC_IMPORT;
10287 break;
10288 case XML_SCHEMA_SCHEMA_INCLUDE:
10289 err = XML_SCHEMAP_SRC_INCLUDE;
10290 break;
10291 case XML_SCHEMA_SCHEMA_REDEFINE:
10292 err = XML_SCHEMAP_SRC_REDEFINE;
10293 break;
Daniel Veillarddee23482008-04-11 12:58:43 +000010294 }
10295
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010296
10297 /* Special handling for the main schema:
10298 * skip the location and relation logic and just parse the doc.
10299 * We need just a bucket to be returned in this case.
Daniel Veillarddee23482008-04-11 12:58:43 +000010300 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010301 if ((type == XML_SCHEMA_SCHEMA_MAIN) || (! WXS_HAS_BUCKETS(pctxt)))
Daniel Veillarddee23482008-04-11 12:58:43 +000010302 goto doc_load;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010303
Daniel Veillarddee23482008-04-11 12:58:43 +000010304 /* Note that we expect the location to be an absulute URI. */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010305 if (schemaLocation != NULL) {
10306 bkt = xmlSchemaGetSchemaBucket(pctxt, schemaLocation);
10307 if ((bkt != NULL) &&
10308 (pctxt->constructor->bucket == bkt)) {
10309 /* Report self-imports/inclusions/redefinitions. */
Daniel Veillarddee23482008-04-11 12:58:43 +000010310
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010311 xmlSchemaCustomErr(ACTXT_CAST pctxt, err,
10312 invokingNode, NULL,
10313 "The schema must not import/include/redefine itself",
10314 NULL, NULL);
10315 goto exit;
10316 }
Kasimier T. Buchcik9ca11bf2005-06-14 19:24:47 +000010317 }
Kasimier T. Buchcikb474fa42005-03-11 12:34:42 +000010318 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010319 * Create a relation for the graph of schemas.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000010320 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010321 relation = xmlSchemaSchemaRelationCreate();
10322 if (relation == NULL)
Daniel Veillarddee23482008-04-11 12:58:43 +000010323 return(-1);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010324 xmlSchemaSchemaRelationAddChild(pctxt->constructor->bucket,
10325 relation);
10326 relation->type = type;
10327
Kasimier T. Buchcikb474fa42005-03-11 12:34:42 +000010328 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010329 * Save the namespace import information.
Kasimier T. Buchcikb474fa42005-03-11 12:34:42 +000010330 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000010331 if (WXS_IS_BUCKET_IMPMAIN(type)) {
Daniel Veillarddee23482008-04-11 12:58:43 +000010332 relation->importNamespace = importNamespace;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010333 if (schemaLocation == NULL) {
10334 /*
10335 * No location; this is just an import of the namespace.
10336 * Note that we don't assign a bucket to the relation
10337 * in this case.
10338 */
10339 goto exit;
10340 }
10341 targetNamespace = importNamespace;
10342 }
10343
10344 /* Did we already fetch the doc? */
Daniel Veillarddee23482008-04-11 12:58:43 +000010345 if (bkt != NULL) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000010346 if ((WXS_IS_BUCKET_IMPMAIN(type)) && (! bkt->imported)) {
Jason Childsd9960722009-08-07 19:01:32 +020010347 /*
10348 * We included/redefined and then try to import a schema,
10349 * but the new location provided for import was different.
10350 */
Daniel Veillard734e7662007-06-26 11:30:31 +000010351 if (schemaLocation == NULL)
10352 schemaLocation = BAD_CAST "in_memory_buffer";
Jason Childsd9960722009-08-07 19:01:32 +020010353 if (!xmlStrEqual(schemaLocation,
10354 bkt->schemaLocation)) {
10355 xmlSchemaCustomErr(ACTXT_CAST pctxt, err,
10356 invokingNode, NULL,
10357 "The schema document '%s' cannot be imported, since "
10358 "it was already included or redefined",
10359 schemaLocation, NULL);
10360 goto exit;
10361 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000010362 } else if ((! WXS_IS_BUCKET_IMPMAIN(type)) && (bkt->imported)) {
Jason Childsd9960722009-08-07 19:01:32 +020010363 /*
10364 * We imported and then try to include/redefine a schema,
10365 * but the new location provided for the include/redefine
10366 * was different.
10367 */
Daniel Veillard734e7662007-06-26 11:30:31 +000010368 if (schemaLocation == NULL)
10369 schemaLocation = BAD_CAST "in_memory_buffer";
Jason Childsd9960722009-08-07 19:01:32 +020010370 if (!xmlStrEqual(schemaLocation,
10371 bkt->schemaLocation)) {
10372 xmlSchemaCustomErr(ACTXT_CAST pctxt, err,
10373 invokingNode, NULL,
10374 "The schema document '%s' cannot be included or "
10375 "redefined, since it was already imported",
10376 schemaLocation, NULL);
10377 goto exit;
10378 }
Daniel Veillarddee23482008-04-11 12:58:43 +000010379 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010380 }
Daniel Veillarddee23482008-04-11 12:58:43 +000010381
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000010382 if (WXS_IS_BUCKET_IMPMAIN(type)) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010383 /*
10384 * Given that the schemaLocation [attribute] is only a hint, it is open
10385 * to applications to ignore all but the first <import> for a given
Rob Richardsc6947bb2008-06-29 15:04:41 +000010386 * namespace, regardless of the �actual value� of schemaLocation, but
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010387 * such a strategy risks missing useful information when new
10388 * schemaLocations are offered.
10389 *
10390 * We will use the first <import> that comes with a location.
10391 * Further <import>s *with* a location, will result in an error.
10392 * TODO: Better would be to just report a warning here, but
10393 * we'll try it this way until someone complains.
10394 *
10395 * Schema Document Location Strategy:
10396 * 3 Based on the namespace name, identify an existing schema document,
10397 * either as a resource which is an XML document or a <schema> element
10398 * information item, in some local schema repository;
10399 * 5 Attempt to resolve the namespace name to locate such a resource.
10400 *
10401 * NOTE: (3) and (5) are not supported.
Daniel Veillarddee23482008-04-11 12:58:43 +000010402 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010403 if (bkt != NULL) {
10404 relation->bucket = bkt;
10405 goto exit;
10406 }
10407 bkt = xmlSchemaGetSchemaBucketByTNS(pctxt,
10408 importNamespace, 1);
10409
Daniel Veillarddee23482008-04-11 12:58:43 +000010410 if (bkt != NULL) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010411 relation->bucket = bkt;
10412 if (bkt->schemaLocation == NULL) {
10413 /* First given location of the schema; load the doc. */
10414 bkt->schemaLocation = schemaLocation;
10415 } else {
10416 if (!xmlStrEqual(schemaLocation,
10417 bkt->schemaLocation)) {
10418 /*
10419 * Additional location given; just skip it.
10420 * URGENT TODO: We should report a warning here.
10421 * res = XML_SCHEMAP_SRC_IMPORT;
10422 */
Daniel Veillard734e7662007-06-26 11:30:31 +000010423 if (schemaLocation == NULL)
10424 schemaLocation = BAD_CAST "in_memory_buffer";
10425
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010426 xmlSchemaCustomWarning(ACTXT_CAST pctxt,
10427 XML_SCHEMAP_WARN_SKIP_SCHEMA,
10428 invokingNode, NULL,
10429 "Skipping import of schema located at '%s' for the "
10430 "namespace '%s', since this namespace was already "
10431 "imported with the schema located at '%s'",
10432 schemaLocation, importNamespace, bkt->schemaLocation);
10433 }
10434 goto exit;
10435 }
Daniel Veillarddee23482008-04-11 12:58:43 +000010436 }
10437 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010438 * No bucket + first location: load the doc and create a
10439 * bucket.
10440 */
10441 } else {
10442 /* <include> and <redefine> */
10443 if (bkt != NULL) {
Daniel Veillarddee23482008-04-11 12:58:43 +000010444
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010445 if ((bkt->origTargetNamespace == NULL) &&
10446 (bkt->targetNamespace != sourceTargetNamespace)) {
10447 xmlSchemaBucketPtr chamel;
Daniel Veillarddee23482008-04-11 12:58:43 +000010448
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010449 /*
10450 * Chameleon include/redefine: skip loading only if it was
10451 * aleady build for the targetNamespace of the including
10452 * schema.
10453 */
10454 /*
10455 * URGENT TODO: If the schema is a chameleon-include then copy
10456 * the components into the including schema and modify the
10457 * targetNamespace of those components, do nothing otherwise.
10458 * NOTE: This is currently worked-around by compiling the
10459 * chameleon for every destinct including targetNamespace; thus
10460 * not performant at the moment.
10461 * TODO: Check when the namespace in wildcards for chameleons
10462 * needs to be converted: before we built wildcard intersections
10463 * or after.
10464 * Answer: after!
10465 */
10466 chamel = xmlSchemaGetChameleonSchemaBucket(pctxt,
10467 schemaLocation, sourceTargetNamespace);
10468 if (chamel != NULL) {
10469 /* A fitting chameleon was already parsed; NOP. */
10470 relation->bucket = chamel;
10471 goto exit;
10472 }
Daniel Veillarddee23482008-04-11 12:58:43 +000010473 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010474 * We need to parse the chameleon again for a different
10475 * targetNamespace.
10476 * CHAMELEON TODO: Optimize this by only parsing the
10477 * chameleon once, and then copying the components to
10478 * the new targetNamespace.
10479 */
10480 bkt = NULL;
10481 } else {
10482 relation->bucket = bkt;
10483 goto exit;
Daniel Veillarddee23482008-04-11 12:58:43 +000010484 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010485 }
10486 }
10487 if ((bkt != NULL) && (bkt->doc != NULL)) {
10488 PERROR_INT("xmlSchemaAddSchemaDoc",
10489 "trying to load a schema doc, but a doc is already "
10490 "assigned to the schema bucket");
10491 goto exit_failure;
10492 }
10493
10494doc_load:
10495 /*
10496 * Load the document.
10497 */
10498 if (schemaDoc != NULL) {
10499 doc = schemaDoc;
10500 /* Don' free this one, since it was provided by the caller. */
10501 preserveDoc = 1;
10502 /* TODO: Does the context or the doc hold the location? */
10503 if (schemaDoc->URL != NULL)
10504 schemaLocation = xmlDictLookup(pctxt->dict,
10505 schemaDoc->URL, -1);
Daniel Veillard734e7662007-06-26 11:30:31 +000010506 else
10507 schemaLocation = BAD_CAST "in_memory_buffer";
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010508 } else if ((schemaLocation != NULL) || (schemaBuffer != NULL)) {
10509 xmlParserCtxtPtr parserCtxt;
10510
10511 parserCtxt = xmlNewParserCtxt();
10512 if (parserCtxt == NULL) {
10513 xmlSchemaPErrMemory(NULL, "xmlSchemaGetDoc, "
10514 "allocating a parser context", NULL);
10515 goto exit_failure;
10516 }
10517 if ((pctxt->dict != NULL) && (parserCtxt->dict != NULL)) {
10518 /*
10519 * TODO: Do we have to burden the schema parser dict with all
10520 * the content of the schema doc?
10521 */
10522 xmlDictFree(parserCtxt->dict);
10523 parserCtxt->dict = pctxt->dict;
10524 xmlDictReference(parserCtxt->dict);
10525 }
10526 if (schemaLocation != NULL) {
10527 /* Parse from file. */
10528 doc = xmlCtxtReadFile(parserCtxt, (const char *) schemaLocation,
10529 NULL, SCHEMAS_PARSE_OPTIONS);
10530 } else if (schemaBuffer != NULL) {
10531 /* Parse from memory buffer. */
10532 doc = xmlCtxtReadMemory(parserCtxt, schemaBuffer, schemaBufferLen,
10533 NULL, NULL, SCHEMAS_PARSE_OPTIONS);
10534 schemaLocation = xmlStrdup(BAD_CAST "in_memory_buffer");
10535 if (doc != NULL)
Daniel Veillarddee23482008-04-11 12:58:43 +000010536 doc->URL = schemaLocation;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010537 }
10538 /*
10539 * For <import>:
10540 * 2.1 The referent is (a fragment of) a resource which is an
10541 * XML document (see clause 1.1), which in turn corresponds to
10542 * a <schema> element information item in a well-formed information
10543 * set, which in turn corresponds to a valid schema.
10544 * TODO: (2.1) fragments of XML documents are not supported.
10545 *
10546 * 2.2 The referent is a <schema> element information item in
10547 * a well-formed information set, which in turn corresponds
10548 * to a valid schema.
10549 * TODO: (2.2) is not supported.
10550 */
10551 if (doc == NULL) {
10552 xmlErrorPtr lerr;
10553 lerr = xmlGetLastError();
10554 /*
10555 * Check if this a parser error, or if the document could
10556 * just not be located.
10557 * TODO: Try to find specific error codes to react only on
10558 * localisation failures.
10559 */
10560 if ((lerr == NULL) || (lerr->domain != XML_FROM_IO)) {
10561 /*
10562 * We assume a parser error here.
10563 */
10564 located = 1;
10565 /* TODO: Error code ?? */
10566 res = XML_SCHEMAP_SRC_IMPORT_2_1;
10567 xmlSchemaCustomErr(ACTXT_CAST pctxt, res,
10568 invokingNode, NULL,
10569 "Failed to parse the XML resource '%s'",
Daniel Veillard734e7662007-06-26 11:30:31 +000010570 schemaLocation, NULL);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010571 }
10572 }
10573 xmlFreeParserCtxt(parserCtxt);
10574 if ((doc == NULL) && located)
10575 goto exit_error;
10576 } else {
10577 xmlSchemaPErr(pctxt, NULL,
10578 XML_SCHEMAP_NOTHING_TO_PARSE,
10579 "No information for parsing was provided with the "
10580 "given schema parser context.\n",
10581 NULL, NULL);
10582 goto exit_failure;
10583 }
10584 /*
10585 * Preprocess the document.
10586 */
10587 if (doc != NULL) {
10588 xmlNodePtr docElem = NULL;
10589
Daniel Veillarddee23482008-04-11 12:58:43 +000010590 located = 1;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010591 docElem = xmlDocGetRootElement(doc);
10592 if (docElem == NULL) {
10593 xmlSchemaCustomErr(ACTXT_CAST pctxt, XML_SCHEMAP_NOROOT,
Daniel Veillarddee23482008-04-11 12:58:43 +000010594 invokingNode, NULL,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010595 "The document '%s' has no document element",
10596 schemaLocation, NULL);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010597 goto exit_error;
10598 }
10599 /*
10600 * Remove all the blank text nodes.
10601 */
10602 xmlSchemaCleanupDoc(pctxt, docElem);
10603 /*
10604 * Check the schema's top level element.
10605 */
10606 if (!IS_SCHEMA(docElem, "schema")) {
10607 xmlSchemaCustomErr(ACTXT_CAST pctxt, XML_SCHEMAP_NOT_SCHEMA,
10608 invokingNode, NULL,
10609 "The XML document '%s' is not a schema document",
10610 schemaLocation, NULL);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010611 goto exit_error;
10612 }
Daniel Veillarddee23482008-04-11 12:58:43 +000010613 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010614 * Note that we don't apply a type check for the
10615 * targetNamespace value here.
10616 */
10617 targetNamespace = xmlSchemaGetProp(pctxt, docElem,
10618 "targetNamespace");
10619 }
Daniel Veillarddee23482008-04-11 12:58:43 +000010620
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010621/* after_doc_loading: */
10622 if ((bkt == NULL) && located) {
10623 /* Only create a bucket if the schema was located. */
10624 bkt = xmlSchemaBucketCreate(pctxt, type,
10625 targetNamespace);
10626 if (bkt == NULL)
10627 goto exit_failure;
10628 }
10629 if (bkt != NULL) {
10630 bkt->schemaLocation = schemaLocation;
10631 bkt->located = located;
10632 if (doc != NULL) {
10633 bkt->doc = doc;
10634 bkt->targetNamespace = targetNamespace;
10635 bkt->origTargetNamespace = targetNamespace;
10636 if (preserveDoc)
10637 bkt->preserveDoc = 1;
10638 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000010639 if (WXS_IS_BUCKET_IMPMAIN(type))
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010640 bkt->imported++;
10641 /*
10642 * Add it to the graph of schemas.
10643 */
10644 if (relation != NULL)
10645 relation->bucket = bkt;
10646 }
Daniel Veillarddee23482008-04-11 12:58:43 +000010647
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010648exit:
10649 /*
10650 * Return the bucket explicitely; this is needed for the
10651 * main schema.
10652 */
10653 if (bucket != NULL)
Daniel Veillarddee23482008-04-11 12:58:43 +000010654 *bucket = bkt;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010655 return (0);
10656
10657exit_error:
10658 if ((doc != NULL) && (! preserveDoc)) {
10659 xmlFreeDoc(doc);
10660 if (bkt != NULL)
10661 bkt->doc = NULL;
10662 }
10663 return(pctxt->err);
10664
10665exit_failure:
10666 if ((doc != NULL) && (! preserveDoc)) {
10667 xmlFreeDoc(doc);
10668 if (bkt != NULL)
10669 bkt->doc = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000010670 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010671 return (-1);
Kasimier T. Buchcikb474fa42005-03-11 12:34:42 +000010672}
10673
William M. Brack2f2a6632004-08-20 23:09:47 +000010674/**
10675 * xmlSchemaParseImport:
10676 * @ctxt: a schema validation context
10677 * @schema: the schema being built
10678 * @node: a subtree containing XML Schema informations
10679 *
10680 * parse a XML schema Import definition
10681 * *WARNING* this interface is highly subject to change
10682 *
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000010683 * Returns 0 in case of success, a positive error code if
10684 * not valid and -1 in case of an internal error.
William M. Brack2f2a6632004-08-20 23:09:47 +000010685 */
10686static int
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000010687xmlSchemaParseImport(xmlSchemaParserCtxtPtr pctxt, xmlSchemaPtr schema,
William M. Brack2f2a6632004-08-20 23:09:47 +000010688 xmlNodePtr node)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000010689{
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000010690 xmlNodePtr child;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000010691 const xmlChar *namespaceName = NULL, *schemaLocation = NULL;
10692 const xmlChar *thisTargetNamespace;
William M. Brack2f2a6632004-08-20 23:09:47 +000010693 xmlAttrPtr attr;
Kasimier T. Buchcikb474fa42005-03-11 12:34:42 +000010694 int ret = 0;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010695 xmlSchemaBucketPtr bucket = NULL;
William M. Brack2f2a6632004-08-20 23:09:47 +000010696
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000010697 if ((pctxt == NULL) || (schema == NULL) || (node == NULL))
William M. Brack2f2a6632004-08-20 23:09:47 +000010698 return (-1);
10699
10700 /*
10701 * Check for illegal attributes.
10702 */
10703 attr = node->properties;
10704 while (attr != NULL) {
10705 if (attr->ns == NULL) {
10706 if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
10707 (!xmlStrEqual(attr->name, BAD_CAST "namespace")) &&
10708 (!xmlStrEqual(attr->name, BAD_CAST "schemaLocation"))) {
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000010709 xmlSchemaPIllegalAttrErr(pctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000010710 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
William M. Brack2f2a6632004-08-20 23:09:47 +000010711 }
10712 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000010713 xmlSchemaPIllegalAttrErr(pctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000010714 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
William M. Brack2f2a6632004-08-20 23:09:47 +000010715 }
10716 attr = attr->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000010717 }
William M. Brack2f2a6632004-08-20 23:09:47 +000010718 /*
10719 * Extract and validate attributes.
10720 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000010721 if (xmlSchemaPValAttr(pctxt, NULL, node,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000010722 "namespace", xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI),
Kasimier T. Buchcikb474fa42005-03-11 12:34:42 +000010723 &namespaceName) != 0) {
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000010724 xmlSchemaPSimpleTypeErr(pctxt,
10725 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000010726 NULL, node,
10727 xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI),
Kasimier T. Buchcikb474fa42005-03-11 12:34:42 +000010728 NULL, namespaceName, NULL, NULL, NULL);
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000010729 return (pctxt->err);
William M. Brack2f2a6632004-08-20 23:09:47 +000010730 }
10731
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000010732 if (xmlSchemaPValAttr(pctxt, NULL, node,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000010733 "schemaLocation", xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI),
William M. Brack2f2a6632004-08-20 23:09:47 +000010734 &schemaLocation) != 0) {
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000010735 xmlSchemaPSimpleTypeErr(pctxt,
10736 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000010737 NULL, node,
10738 xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI),
Kasimier T. Buchcikb474fa42005-03-11 12:34:42 +000010739 NULL, namespaceName, NULL, NULL, NULL);
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000010740 return (pctxt->err);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000010741 }
William M. Brack2f2a6632004-08-20 23:09:47 +000010742 /*
10743 * And now for the children...
10744 */
10745 child = node->children;
10746 if (IS_SCHEMA(child, "annotation")) {
10747 /*
10748 * the annotation here is simply discarded ...
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000010749 * TODO: really?
William M. Brack2f2a6632004-08-20 23:09:47 +000010750 */
10751 child = child->next;
10752 }
10753 if (child != NULL) {
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000010754 xmlSchemaPContentErr(pctxt,
10755 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000010756 NULL, node, child, NULL,
William M. Brack2f2a6632004-08-20 23:09:47 +000010757 "(annotation?)");
10758 }
10759 /*
10760 * Apply additional constraints.
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000010761 *
10762 * Note that it is important to use the original @targetNamespace
10763 * (or none at all), to rule out imports of schemas _with_ a
10764 * @targetNamespace if the importing schema is a chameleon schema
10765 * (with no @targetNamespace).
William M. Brack2f2a6632004-08-20 23:09:47 +000010766 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000010767 thisTargetNamespace = WXS_BUCKET(pctxt)->origTargetNamespace;
Kasimier T. Buchcikb474fa42005-03-11 12:34:42 +000010768 if (namespaceName != NULL) {
William M. Brack2f2a6632004-08-20 23:09:47 +000010769 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000010770 * 1.1 If the namespace [attribute] is present, then its �actual value�
10771 * must not match the �actual value� of the enclosing <schema>'s
William M. Brack2f2a6632004-08-20 23:09:47 +000010772 * targetNamespace [attribute].
10773 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000010774 if (xmlStrEqual(thisTargetNamespace, namespaceName)) {
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000010775 xmlSchemaPCustomErr(pctxt,
William M. Brack2f2a6632004-08-20 23:09:47 +000010776 XML_SCHEMAP_SRC_IMPORT_1_1,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000010777 NULL, node,
William M. Brack2f2a6632004-08-20 23:09:47 +000010778 "The value of the attribute 'namespace' must not match "
10779 "the target namespace '%s' of the importing schema",
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000010780 thisTargetNamespace);
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000010781 return (pctxt->err);
William M. Brack2f2a6632004-08-20 23:09:47 +000010782 }
10783 } else {
10784 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000010785 * 1.2 If the namespace [attribute] is not present, then the enclosing
William M. Brack2f2a6632004-08-20 23:09:47 +000010786 * <schema> must have a targetNamespace [attribute].
10787 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000010788 if (thisTargetNamespace == NULL) {
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000010789 xmlSchemaPCustomErr(pctxt,
William M. Brack2f2a6632004-08-20 23:09:47 +000010790 XML_SCHEMAP_SRC_IMPORT_1_2,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000010791 NULL, node,
William M. Brack2f2a6632004-08-20 23:09:47 +000010792 "The attribute 'namespace' must be existent if "
10793 "the importing schema has no target namespace",
10794 NULL);
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000010795 return (pctxt->err);
William M. Brack2f2a6632004-08-20 23:09:47 +000010796 }
10797 }
William M. Brack2f2a6632004-08-20 23:09:47 +000010798 /*
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000010799 * Locate and acquire the schema document.
William M. Brack2f2a6632004-08-20 23:09:47 +000010800 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010801 if (schemaLocation != NULL)
10802 schemaLocation = xmlSchemaBuildAbsoluteURI(pctxt->dict,
10803 schemaLocation, node);
10804 ret = xmlSchemaAddSchemaDoc(pctxt, XML_SCHEMA_SCHEMA_IMPORT,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000010805 schemaLocation, NULL, NULL, 0, node, thisTargetNamespace,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010806 namespaceName, &bucket);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000010807
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010808 if (ret != 0)
10809 return(ret);
10810
10811 /*
10812 * For <import>: "It is *not* an error for the application
10813 * schema reference strategy to fail."
10814 * So just don't parse if no schema document was found.
10815 * Note that we will get no bucket if the schema could not be
10816 * located or if there was no schemaLocation.
10817 */
10818 if ((bucket == NULL) && (schemaLocation != NULL)) {
10819 xmlSchemaCustomWarning(ACTXT_CAST pctxt,
10820 XML_SCHEMAP_WARN_UNLOCATED_SCHEMA,
10821 node, NULL,
10822 "Failed to locate a schema at location '%s'. "
10823 "Skipping the import", schemaLocation, NULL, NULL);
10824 }
Daniel Veillarddee23482008-04-11 12:58:43 +000010825
10826 if ((bucket != NULL) && CAN_PARSE_SCHEMA(bucket)) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010827 ret = xmlSchemaParseNewDoc(pctxt, schema, bucket);
10828 }
Daniel Veillarddee23482008-04-11 12:58:43 +000010829
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010830 return (ret);
William M. Brack2f2a6632004-08-20 23:09:47 +000010831}
10832
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000010833static int
10834xmlSchemaParseIncludeOrRedefineAttrs(xmlSchemaParserCtxtPtr pctxt,
10835 xmlSchemaPtr schema,
10836 xmlNodePtr node,
10837 xmlChar **schemaLocation,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010838 int type)
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000010839{
10840 xmlAttrPtr attr;
10841
10842 if ((pctxt == NULL) || (schema == NULL) || (node == NULL) ||
10843 (schemaLocation == NULL))
10844 return (-1);
10845
10846 *schemaLocation = NULL;
10847 /*
10848 * Check for illegal attributes.
10849 * Applies for both <include> and <redefine>.
10850 */
10851 attr = node->properties;
10852 while (attr != NULL) {
10853 if (attr->ns == NULL) {
10854 if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
10855 (!xmlStrEqual(attr->name, BAD_CAST "schemaLocation"))) {
10856 xmlSchemaPIllegalAttrErr(pctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000010857 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000010858 }
10859 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
10860 xmlSchemaPIllegalAttrErr(pctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000010861 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000010862 }
10863 attr = attr->next;
10864 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000010865 xmlSchemaPValAttrID(pctxt, node, BAD_CAST "id");
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000010866 /*
10867 * Preliminary step, extract the URI-Reference and make an URI
10868 * from the base.
10869 */
10870 /*
10871 * Attribute "schemaLocation" is mandatory.
10872 */
10873 attr = xmlSchemaGetPropNode(node, "schemaLocation");
10874 if (attr != NULL) {
10875 xmlChar *base = NULL;
10876 xmlChar *uri = NULL;
10877
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000010878 if (xmlSchemaPValAttrNode(pctxt, NULL, attr,
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000010879 xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI),
10880 (const xmlChar **) schemaLocation) != 0)
10881 goto exit_error;
10882 base = xmlNodeGetBase(node->doc, node);
10883 if (base == NULL) {
10884 uri = xmlBuildURI(*schemaLocation, node->doc->URL);
10885 } else {
10886 uri = xmlBuildURI(*schemaLocation, base);
10887 xmlFree(base);
10888 }
10889 if (uri == NULL) {
10890 PERROR_INT("xmlSchemaParseIncludeOrRedefine",
10891 "could not build an URI from the schemaLocation")
10892 goto exit_failure;
10893 }
10894 (*schemaLocation) = (xmlChar *) xmlDictLookup(pctxt->dict, uri, -1);
10895 xmlFree(uri);
10896 } else {
10897 xmlSchemaPMissingAttrErr(pctxt,
10898 XML_SCHEMAP_S4S_ATTR_MISSING,
10899 NULL, node, "schemaLocation", NULL);
10900 goto exit_error;
10901 }
10902 /*
10903 * Report self-inclusion and self-redefinition.
10904 */
10905 if (xmlStrEqual(*schemaLocation, pctxt->URL)) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010906 if (type == XML_SCHEMA_SCHEMA_REDEFINE) {
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000010907 xmlSchemaPCustomErr(pctxt,
10908 XML_SCHEMAP_SRC_REDEFINE,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000010909 NULL, node,
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000010910 "The schema document '%s' cannot redefine itself.",
Daniel Veillarddee23482008-04-11 12:58:43 +000010911 *schemaLocation);
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000010912 } else {
10913 xmlSchemaPCustomErr(pctxt,
10914 XML_SCHEMAP_SRC_INCLUDE,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000010915 NULL, node,
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000010916 "The schema document '%s' cannot include itself.",
10917 *schemaLocation);
10918 }
10919 goto exit_error;
10920 }
Daniel Veillarddee23482008-04-11 12:58:43 +000010921
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000010922 return(0);
10923exit_error:
10924 return(pctxt->err);
10925exit_failure:
10926 return(-1);
10927}
10928
10929static int
10930xmlSchemaParseIncludeOrRedefine(xmlSchemaParserCtxtPtr pctxt,
10931 xmlSchemaPtr schema,
10932 xmlNodePtr node,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010933 int type)
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000010934{
10935 xmlNodePtr child = NULL;
10936 const xmlChar *schemaLocation = NULL;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000010937 int res = 0; /* hasRedefinitions = 0 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010938 int isChameleon = 0, wasChameleon = 0;
10939 xmlSchemaBucketPtr bucket = NULL;
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000010940
10941 if ((pctxt == NULL) || (schema == NULL) || (node == NULL))
10942 return (-1);
10943
10944 /*
Kasimier T. Buchcik630215b2005-08-22 10:15:39 +000010945 * Parse attributes. Note that the returned schemaLocation will
10946 * be already converted to an absolute URI.
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000010947 */
10948 res = xmlSchemaParseIncludeOrRedefineAttrs(pctxt, schema,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010949 node, (xmlChar **) (&schemaLocation), type);
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000010950 if (res != 0)
Daniel Veillarddee23482008-04-11 12:58:43 +000010951 return(res);
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000010952 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010953 * Load and add the schema document.
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000010954 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010955 res = xmlSchemaAddSchemaDoc(pctxt, type, schemaLocation, NULL,
10956 NULL, 0, node, pctxt->targetNamespace, NULL, &bucket);
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000010957 if (res != 0)
Daniel Veillarddee23482008-04-11 12:58:43 +000010958 return(res);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010959 /*
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000010960 * If we get no schema bucket back, then this means that the schema
10961 * document could not be located or was broken XML or was not
10962 * a schema document.
Daniel Veillarddee23482008-04-11 12:58:43 +000010963 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010964 if ((bucket == NULL) || (bucket->doc == NULL)) {
10965 if (type == XML_SCHEMA_SCHEMA_INCLUDE) {
10966 /*
10967 * WARNING for <include>:
10968 * We will raise an error if the schema cannot be located
10969 * for inclusions, since the that was the feedback from the
10970 * schema people. I.e. the following spec piece will *not* be
10971 * satisfied:
Rob Richardsc6947bb2008-06-29 15:04:41 +000010972 * SPEC src-include: "It is not an error for the �actual value� of the
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010973 * schemaLocation [attribute] to fail to resolve it all, in which
10974 * case no corresponding inclusion is performed.
10975 * So do we need a warning report here?"
10976 */
10977 res = XML_SCHEMAP_SRC_INCLUDE;
10978 xmlSchemaCustomErr(ACTXT_CAST pctxt, res,
10979 node, NULL,
10980 "Failed to load the document '%s' for inclusion",
10981 schemaLocation, NULL);
10982 } else {
10983 /*
10984 * NOTE: This was changed to raise an error even if no redefinitions
10985 * are specified.
10986 *
10987 * SPEC src-redefine (1)
10988 * "If there are any element information items among the [children]
Rob Richardsc6947bb2008-06-29 15:04:41 +000010989 * other than <annotation> then the �actual value� of the
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000010990 * schemaLocation [attribute] must successfully resolve."
10991 * TODO: Ask the WG if a the location has always to resolve
10992 * here as well!
10993 */
10994 res = XML_SCHEMAP_SRC_REDEFINE;
10995 xmlSchemaCustomErr(ACTXT_CAST pctxt, res,
10996 node, NULL,
10997 "Failed to load the document '%s' for redefinition",
10998 schemaLocation, NULL);
10999 }
11000 } else {
11001 /*
11002 * Check targetNamespace sanity before parsing the new schema.
11003 * TODO: Note that we won't check further content if the
11004 * targetNamespace was bad.
Daniel Veillarddee23482008-04-11 12:58:43 +000011005 */
11006 if (bucket->origTargetNamespace != NULL) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000011007 /*
11008 * SPEC src-include (2.1)
Rob Richardsc6947bb2008-06-29 15:04:41 +000011009 * "SII has a targetNamespace [attribute], and its �actual
11010 * value� is identical to the �actual value� of the targetNamespace
11011 * [attribute] of SII� (which must have such an [attribute])."
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000011012 */
11013 if (pctxt->targetNamespace == NULL) {
11014 xmlSchemaCustomErr(ACTXT_CAST pctxt,
11015 XML_SCHEMAP_SRC_INCLUDE,
11016 node, NULL,
11017 "The target namespace of the included/redefined schema "
11018 "'%s' has to be absent, since the including/redefining "
11019 "schema has no target namespace",
11020 schemaLocation, NULL);
11021 goto exit_error;
11022 } else if (!xmlStrEqual(bucket->origTargetNamespace,
11023 pctxt->targetNamespace)) {
11024 /* TODO: Change error function. */
11025 xmlSchemaPCustomErrExt(pctxt,
11026 XML_SCHEMAP_SRC_INCLUDE,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011027 NULL, node,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000011028 "The target namespace '%s' of the included/redefined "
11029 "schema '%s' differs from '%s' of the "
11030 "including/redefining schema",
11031 bucket->origTargetNamespace, schemaLocation,
11032 pctxt->targetNamespace);
11033 goto exit_error;
11034 }
Daniel Veillarddee23482008-04-11 12:58:43 +000011035 } else if (pctxt->targetNamespace != NULL) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000011036 /*
11037 * Chameleons: the original target namespace will
11038 * differ from the resulting namespace.
11039 */
11040 isChameleon = 1;
11041 if (bucket->parsed &&
Jason Childsedc68aa2009-08-07 20:29:33 +020011042 bucket->origTargetNamespace != NULL) {
11043 xmlSchemaCustomErr(ACTXT_CAST pctxt,
11044 XML_SCHEMAP_SRC_INCLUDE,
11045 node, NULL,
11046 "The target namespace of the included/redefined schema "
11047 "'%s' has to be absent or the same as the "
11048 "including/redefining schema's target namespace",
11049 schemaLocation, NULL);
11050 goto exit_error;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000011051 }
11052 bucket->targetNamespace = pctxt->targetNamespace;
11053 }
Daniel Veillarddee23482008-04-11 12:58:43 +000011054 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000011055 /*
11056 * Parse the schema.
Daniel Veillarddee23482008-04-11 12:58:43 +000011057 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000011058 if (bucket && (!bucket->parsed) && (bucket->doc != NULL)) {
11059 if (isChameleon) {
11060 /* TODO: Get rid of this flag on the schema itself. */
11061 if ((schema->flags & XML_SCHEMAS_INCLUDING_CONVERT_NS) == 0) {
11062 schema->flags |= XML_SCHEMAS_INCLUDING_CONVERT_NS;
11063 } else
11064 wasChameleon = 1;
11065 }
11066 xmlSchemaParseNewDoc(pctxt, schema, bucket);
11067 /* Restore chameleon flag. */
11068 if (isChameleon && (!wasChameleon))
11069 schema->flags ^= XML_SCHEMAS_INCLUDING_CONVERT_NS;
11070 }
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000011071 /*
11072 * And now for the children...
11073 */
Daniel Veillarddee23482008-04-11 12:58:43 +000011074 child = node->children;
11075 if (type == XML_SCHEMA_SCHEMA_REDEFINE) {
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000011076 /*
11077 * Parse (simpleType | complexType | group | attributeGroup))*
11078 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011079 pctxt->redefined = bucket;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000011080 /*
11081 * How to proceed if the redefined schema was not located?
11082 */
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000011083 pctxt->isRedefine = 1;
11084 while (IS_SCHEMA(child, "annotation") ||
11085 IS_SCHEMA(child, "simpleType") ||
11086 IS_SCHEMA(child, "complexType") ||
11087 IS_SCHEMA(child, "group") ||
11088 IS_SCHEMA(child, "attributeGroup")) {
11089 if (IS_SCHEMA(child, "annotation")) {
11090 /*
11091 * TODO: discard or not?
11092 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011093 } else if (IS_SCHEMA(child, "simpleType")) {
11094 xmlSchemaParseSimpleType(pctxt, schema, child, 1);
11095 } else if (IS_SCHEMA(child, "complexType")) {
11096 xmlSchemaParseComplexType(pctxt, schema, child, 1);
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000011097 /* hasRedefinitions = 1; */
Daniel Veillarddee23482008-04-11 12:58:43 +000011098 } else if (IS_SCHEMA(child, "group")) {
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000011099 /* hasRedefinitions = 1; */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011100 xmlSchemaParseModelGroupDefinition(pctxt,
11101 schema, child);
11102 } else if (IS_SCHEMA(child, "attributeGroup")) {
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000011103 /* hasRedefinitions = 1; */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011104 xmlSchemaParseAttributeGroupDefinition(pctxt, schema,
11105 child);
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000011106 }
11107 child = child->next;
11108 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011109 pctxt->redefined = NULL;
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000011110 pctxt->isRedefine = 0;
11111 } else {
11112 if (IS_SCHEMA(child, "annotation")) {
11113 /*
11114 * TODO: discard or not?
11115 */
11116 child = child->next;
11117 }
Daniel Veillarddee23482008-04-11 12:58:43 +000011118 }
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000011119 if (child != NULL) {
Kasimier T. Buchcik630215b2005-08-22 10:15:39 +000011120 res = XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000011121 if (type == XML_SCHEMA_SCHEMA_REDEFINE) {
11122 xmlSchemaPContentErr(pctxt, res,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011123 NULL, node, child, NULL,
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000011124 "(annotation | (simpleType | complexType | group | attributeGroup))*");
11125 } else {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000011126 xmlSchemaPContentErr(pctxt, res,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011127 NULL, node, child, NULL,
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000011128 "(annotation?)");
Daniel Veillarddee23482008-04-11 12:58:43 +000011129 }
11130 }
Kasimier T. Buchcik630215b2005-08-22 10:15:39 +000011131 return(res);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000011132
11133exit_error:
11134 return(pctxt->err);
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000011135}
11136
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000011137static int
11138xmlSchemaParseRedefine(xmlSchemaParserCtxtPtr pctxt, xmlSchemaPtr schema,
11139 xmlNodePtr node)
11140{
11141 int res;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000011142#ifndef ENABLE_REDEFINE
11143 TODO
11144 return(0);
11145#endif
11146 res = xmlSchemaParseIncludeOrRedefine(pctxt, schema, node,
11147 XML_SCHEMA_SCHEMA_REDEFINE);
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000011148 if (res != 0)
11149 return(res);
11150 return(0);
11151}
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000011152
11153static int
11154xmlSchemaParseInclude(xmlSchemaParserCtxtPtr pctxt, xmlSchemaPtr schema,
11155 xmlNodePtr node)
11156{
11157 int res;
11158
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000011159 res = xmlSchemaParseIncludeOrRedefine(pctxt, schema, node,
11160 XML_SCHEMA_SCHEMA_INCLUDE);
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000011161 if (res != 0)
11162 return(res);
11163 return(0);
11164}
11165
Daniel Veillardbd2904b2003-11-25 15:38:59 +000011166/**
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011167 * xmlSchemaParseModelGroup:
Daniel Veillard4255d502002-04-16 15:50:10 +000011168 * @ctxt: a schema validation context
11169 * @schema: the schema being built
11170 * @node: a subtree containing XML Schema informations
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011171 * @type: the "compositor" type
11172 * @particleNeeded: if a a model group with a particle
Daniel Veillard4255d502002-04-16 15:50:10 +000011173 *
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011174 * parse a XML schema Sequence definition.
11175 * Applies parts of:
11176 * Schema Representation Constraint:
11177 * Redefinition Constraints and Semantics (src-redefine)
11178 * (6.1), (6.1.1), (6.1.2)
11179 *
Daniel Veillarddee23482008-04-11 12:58:43 +000011180 * Schema Component Constraint:
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011181 * All Group Limited (cos-all-limited) (2)
11182 * TODO: Actually this should go to component-level checks,
11183 * but is done here due to performance. Move it to an other layer
11184 * is schema construction via an API is implemented.
11185 *
Daniel Veillard4255d502002-04-16 15:50:10 +000011186 * *WARNING* this interface is highly subject to change
11187 *
William M. Bracke7091952004-05-11 15:09:58 +000011188 * Returns -1 in case of error, 0 if the declaration is improper and
Daniel Veillard4255d502002-04-16 15:50:10 +000011189 * 1 in case of success.
11190 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011191static xmlSchemaTreeItemPtr
11192xmlSchemaParseModelGroup(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
11193 xmlNodePtr node, xmlSchemaTypeType type,
11194 int withParticle)
Daniel Veillard4255d502002-04-16 15:50:10 +000011195{
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011196 xmlSchemaModelGroupPtr item;
11197 xmlSchemaParticlePtr particle = NULL;
Daniel Veillard4255d502002-04-16 15:50:10 +000011198 xmlNodePtr child = NULL;
William M. Brack2f2a6632004-08-20 23:09:47 +000011199 xmlAttrPtr attr;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011200 int min = 1, max = 1, isElemRef, hasRefs = 0;
Daniel Veillard4255d502002-04-16 15:50:10 +000011201
11202 if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011203 return (NULL);
11204 /*
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011205 * Create a model group with the given compositor.
William M. Brack2f2a6632004-08-20 23:09:47 +000011206 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000011207 item = xmlSchemaAddModelGroup(ctxt, schema, type, node);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011208 if (item == NULL)
11209 return (NULL);
11210
11211 if (withParticle) {
11212 if (type == XML_SCHEMA_TYPE_ALL) {
11213 min = xmlGetMinOccurs(ctxt, node, 0, 1, 1, "(0 | 1)");
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011214 max = xmlGetMaxOccurs(ctxt, node, 1, 1, 1, "1");
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011215 } else {
11216 /* choice + sequence */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011217 min = xmlGetMinOccurs(ctxt, node, 0, -1, 1, "xs:nonNegativeInteger");
11218 max = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1,
11219 "(xs:nonNegativeInteger | unbounded)");
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000011220 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011221 xmlSchemaPCheckParticleCorrect_2(ctxt, NULL, node, min, max);
11222 /*
11223 * Create a particle
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011224 */
Kasimier T. Buchcik4c0aa162006-02-20 14:47:08 +000011225 particle = xmlSchemaAddParticle(ctxt, node, min, max);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011226 if (particle == NULL)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011227 return (NULL);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011228 particle->children = (xmlSchemaTreeItemPtr) item;
11229 /*
11230 * Check for illegal attributes.
11231 */
11232 attr = node->properties;
11233 while (attr != NULL) {
11234 if (attr->ns == NULL) {
11235 if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
11236 (!xmlStrEqual(attr->name, BAD_CAST "maxOccurs")) &&
11237 (!xmlStrEqual(attr->name, BAD_CAST "minOccurs"))) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011238 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011239 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011240 }
11241 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011242 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011243 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
William M. Brack2f2a6632004-08-20 23:09:47 +000011244 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011245 attr = attr->next;
William M. Brack2f2a6632004-08-20 23:09:47 +000011246 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011247 } else {
11248 /*
11249 * Check for illegal attributes.
11250 */
11251 attr = node->properties;
11252 while (attr != NULL) {
11253 if (attr->ns == NULL) {
11254 if (!xmlStrEqual(attr->name, BAD_CAST "id")) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011255 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011256 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011257 }
11258 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011259 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011260 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011261 }
11262 attr = attr->next;
11263 }
William M. Brack2f2a6632004-08-20 23:09:47 +000011264 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011265
William M. Brack2f2a6632004-08-20 23:09:47 +000011266 /*
11267 * Extract and validate attributes.
11268 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011269 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
William M. Brack2f2a6632004-08-20 23:09:47 +000011270 /*
11271 * And now for the children...
11272 */
Daniel Veillard4255d502002-04-16 15:50:10 +000011273 child = node->children;
11274 if (IS_SCHEMA(child, "annotation")) {
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000011275 item->annot = xmlSchemaParseAnnotation(ctxt, child, 1);
Daniel Veillardd0c9c322003-10-10 00:49:42 +000011276 child = child->next;
Daniel Veillard4255d502002-04-16 15:50:10 +000011277 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011278 if (type == XML_SCHEMA_TYPE_ALL) {
11279 xmlSchemaParticlePtr part, last = NULL;
11280
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011281 while (IS_SCHEMA(child, "element")) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011282 part = (xmlSchemaParticlePtr) xmlSchemaParseElement(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011283 schema, child, &isElemRef, 0);
11284 /*
11285 * SPEC cos-all-limited (2)
11286 * "The {max occurs} of all the particles in the {particles}
11287 * of the ('all') group must be 0 or 1.
11288 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011289 if (part != NULL) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011290 if (isElemRef)
11291 hasRefs++;
11292 if (part->minOccurs > 1) {
11293 xmlSchemaPCustomErr(ctxt,
11294 XML_SCHEMAP_COS_ALL_LIMITED,
11295 NULL, child,
11296 "Invalid value for minOccurs (must be 0 or 1)",
11297 NULL);
11298 /* Reset to 1. */
11299 part->minOccurs = 1;
11300 }
11301 if (part->maxOccurs > 1) {
11302 xmlSchemaPCustomErr(ctxt,
11303 XML_SCHEMAP_COS_ALL_LIMITED,
11304 NULL, child,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011305 "Invalid value for maxOccurs (must be 0 or 1)",
11306 NULL);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011307 /* Reset to 1. */
11308 part->maxOccurs = 1;
11309 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011310 if (last == NULL)
11311 item->children = (xmlSchemaTreeItemPtr) part;
11312 else
11313 last->next = (xmlSchemaTreeItemPtr) part;
11314 last = part;
11315 }
11316 child = child->next;
11317 }
11318 if (child != NULL) {
11319 xmlSchemaPContentErr(ctxt,
11320 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011321 NULL, node, child, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011322 "(annotation?, (annotation?, element*)");
11323 }
11324 } else {
11325 /* choice + sequence */
11326 xmlSchemaTreeItemPtr part = NULL, last = NULL;
11327
11328 while ((IS_SCHEMA(child, "element")) ||
11329 (IS_SCHEMA(child, "group")) ||
11330 (IS_SCHEMA(child, "any")) ||
11331 (IS_SCHEMA(child, "choice")) ||
11332 (IS_SCHEMA(child, "sequence"))) {
11333
11334 if (IS_SCHEMA(child, "element")) {
11335 part = (xmlSchemaTreeItemPtr)
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011336 xmlSchemaParseElement(ctxt, schema, child, &isElemRef, 0);
11337 if (part && isElemRef)
11338 hasRefs++;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011339 } else if (IS_SCHEMA(child, "group")) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011340 part =
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011341 xmlSchemaParseModelGroupDefRef(ctxt, schema, child);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011342 if (part != NULL)
11343 hasRefs++;
11344 /*
11345 * Handle redefinitions.
11346 */
11347 if (ctxt->isRedefine && ctxt->redef &&
11348 (ctxt->redef->item->type == XML_SCHEMA_TYPE_GROUP) &&
11349 part && part->children)
11350 {
11351 if ((xmlSchemaGetQNameRefName(part->children) ==
11352 ctxt->redef->refName) &&
11353 (xmlSchemaGetQNameRefTargetNs(part->children) ==
11354 ctxt->redef->refTargetNs))
11355 {
11356 /*
11357 * SPEC src-redefine:
11358 * (6.1) "If it has a <group> among its contents at
Rob Richardsc6947bb2008-06-29 15:04:41 +000011359 * some level the �actual value� of whose ref
11360 * [attribute] is the same as the �actual value� of
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011361 * its own name attribute plus target namespace, then
11362 * all of the following must be true:"
11363 * (6.1.1) "It must have exactly one such group."
11364 */
11365 if (ctxt->redefCounter != 0) {
11366 xmlChar *str = NULL;
11367
11368 xmlSchemaCustomErr(ACTXT_CAST ctxt,
11369 XML_SCHEMAP_SRC_REDEFINE, child, NULL,
11370 "The redefining model group definition "
11371 "'%s' must not contain more than one "
11372 "reference to the redefined definition",
11373 xmlSchemaFormatQName(&str,
11374 ctxt->redef->refTargetNs,
11375 ctxt->redef->refName),
11376 NULL);
11377 FREE_AND_NULL(str)
11378 part = NULL;
11379 } else if (((WXS_PARTICLE(part))->minOccurs != 1) ||
11380 ((WXS_PARTICLE(part))->maxOccurs != 1))
11381 {
11382 xmlChar *str = NULL;
11383 /*
11384 * SPEC src-redefine:
Rob Richardsc6947bb2008-06-29 15:04:41 +000011385 * (6.1.2) "The �actual value� of both that
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011386 * group's minOccurs and maxOccurs [attribute]
Rob Richardsc6947bb2008-06-29 15:04:41 +000011387 * must be 1 (or �absent�).
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011388 */
11389 xmlSchemaCustomErr(ACTXT_CAST ctxt,
11390 XML_SCHEMAP_SRC_REDEFINE, child, NULL,
11391 "The redefining model group definition "
11392 "'%s' must not contain a reference to the "
11393 "redefined definition with a "
11394 "maxOccurs/minOccurs other than 1",
11395 xmlSchemaFormatQName(&str,
11396 ctxt->redef->refTargetNs,
11397 ctxt->redef->refName),
11398 NULL);
11399 FREE_AND_NULL(str)
11400 part = NULL;
11401 }
11402 ctxt->redef->reference = WXS_BASIC_CAST part;
11403 ctxt->redefCounter++;
Daniel Veillarddee23482008-04-11 12:58:43 +000011404 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011405 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011406 } else if (IS_SCHEMA(child, "any")) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011407 part = (xmlSchemaTreeItemPtr)
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011408 xmlSchemaParseAny(ctxt, schema, child);
11409 } else if (IS_SCHEMA(child, "choice")) {
11410 part = xmlSchemaParseModelGroup(ctxt, schema, child,
11411 XML_SCHEMA_TYPE_CHOICE, 1);
11412 } else if (IS_SCHEMA(child, "sequence")) {
11413 part = xmlSchemaParseModelGroup(ctxt, schema, child,
11414 XML_SCHEMA_TYPE_SEQUENCE, 1);
11415 }
11416 if (part != NULL) {
11417 if (last == NULL)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011418 item->children = part;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011419 else
11420 last->next = part;
11421 last = part;
11422 }
11423 child = child->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011424 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011425 if (child != NULL) {
11426 xmlSchemaPContentErr(ctxt,
11427 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011428 NULL, node, child, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011429 "(annotation?, (element | group | choice | sequence | any)*)");
11430 }
Daniel Veillard4255d502002-04-16 15:50:10 +000011431 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011432 if ((max == 0) && (min == 0))
11433 return (NULL);
11434 if (hasRefs) {
11435 /*
11436 * We need to resolve references.
11437 */
11438 WXS_ADD_PENDING(ctxt, item);
11439 }
11440 if (withParticle)
Daniel Veillarddee23482008-04-11 12:58:43 +000011441 return ((xmlSchemaTreeItemPtr) particle);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011442 else
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011443 return ((xmlSchemaTreeItemPtr) item);
Daniel Veillard4255d502002-04-16 15:50:10 +000011444}
11445
11446/**
11447 * xmlSchemaParseRestriction:
11448 * @ctxt: a schema validation context
11449 * @schema: the schema being built
11450 * @node: a subtree containing XML Schema informations
Daniel Veillard4255d502002-04-16 15:50:10 +000011451 *
11452 * parse a XML schema Restriction definition
11453 * *WARNING* this interface is highly subject to change
11454 *
11455 * Returns the type definition or NULL in case of error
11456 */
11457static xmlSchemaTypePtr
11458xmlSchemaParseRestriction(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011459 xmlNodePtr node, xmlSchemaTypeType parentType)
Daniel Veillard4255d502002-04-16 15:50:10 +000011460{
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011461 xmlSchemaTypePtr type;
Daniel Veillard4255d502002-04-16 15:50:10 +000011462 xmlNodePtr child = NULL;
William M. Brack2f2a6632004-08-20 23:09:47 +000011463 xmlAttrPtr attr;
Daniel Veillard4255d502002-04-16 15:50:10 +000011464
11465 if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
11466 return (NULL);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011467 /* Not a component, don't create it. */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011468 type = ctxt->ctxtType;
11469 type->flags |= XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011470
11471 /*
William M. Brack2f2a6632004-08-20 23:09:47 +000011472 * Check for illegal attributes.
11473 */
11474 attr = node->properties;
11475 while (attr != NULL) {
11476 if (attr->ns == NULL) {
11477 if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
11478 (!xmlStrEqual(attr->name, BAD_CAST "base"))) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011479 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011480 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
William M. Brack2f2a6632004-08-20 23:09:47 +000011481 }
11482 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011483 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011484 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
William M. Brack2f2a6632004-08-20 23:09:47 +000011485 }
11486 attr = attr->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011487 }
William M. Brack2f2a6632004-08-20 23:09:47 +000011488 /*
11489 * Extract and validate attributes.
11490 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011491 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
William M. Brack2f2a6632004-08-20 23:09:47 +000011492 /*
Daniel Veillarddee23482008-04-11 12:58:43 +000011493 * Attribute
William M. Brack2f2a6632004-08-20 23:09:47 +000011494 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011495 /*
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000011496 * Extract the base type. The "base" attribute is mandatory if inside
11497 * a complex type or if redefining.
11498 *
11499 * SPEC (1.2) "...otherwise (<restriction> has no <simpleType> "
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011500 * among its [children]), the simple type definition which is
Rob Richardsc6947bb2008-06-29 15:04:41 +000011501 * the {content type} of the type definition �resolved� to by
11502 * the �actual value� of the base [attribute]"
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011503 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011504 if (xmlSchemaPValAttrQName(ctxt, schema, NULL, node, "base",
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000011505 &(type->baseNs), &(type->base)) == 0)
11506 {
11507 if ((type->base == NULL) && (type->type == XML_SCHEMA_TYPE_COMPLEX)) {
11508 xmlSchemaPMissingAttrErr(ctxt,
11509 XML_SCHEMAP_S4S_ATTR_MISSING,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011510 NULL, node, "base", NULL);
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000011511 } else if ((ctxt->isRedefine) &&
11512 (type->flags & XML_SCHEMAS_TYPE_GLOBAL))
11513 {
11514 if (type->base == NULL) {
11515 xmlSchemaPMissingAttrErr(ctxt,
11516 XML_SCHEMAP_S4S_ATTR_MISSING,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011517 NULL, node, "base", NULL);
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000011518 } else if ((! xmlStrEqual(type->base, type->name)) ||
11519 (! xmlStrEqual(type->baseNs, type->targetNamespace)))
11520 {
11521 xmlChar *str1 = NULL, *str2 = NULL;
11522 /*
11523 * REDEFINE: SPEC src-redefine (5)
11524 * "Within the [children], each <simpleType> must have a
Rob Richardsc6947bb2008-06-29 15:04:41 +000011525 * <restriction> among its [children] ... the �actual value� of
11526 * whose base [attribute] must be the same as the �actual value�
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000011527 * of its own name attribute plus target namespace;"
11528 */
11529 xmlSchemaPCustomErrExt(ctxt, XML_SCHEMAP_SRC_REDEFINE,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011530 NULL, node, "This is a redefinition, but the QName "
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000011531 "value '%s' of the 'base' attribute does not match the "
11532 "type's designation '%s'",
11533 xmlSchemaFormatQName(&str1, type->baseNs, type->base),
Daniel Veillardfef73a52006-03-27 09:38:57 +000011534 xmlSchemaFormatQName(&str2, type->targetNamespace,
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000011535 type->name), NULL);
11536 FREE_AND_NULL(str1);
11537 FREE_AND_NULL(str2);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011538 /* Avoid confusion and erase the values. */
11539 type->base = NULL;
11540 type->baseNs = NULL;
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000011541 }
Daniel Veillarddee23482008-04-11 12:58:43 +000011542 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011543 }
William M. Brack2f2a6632004-08-20 23:09:47 +000011544 /*
11545 * And now for the children...
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011546 */
Daniel Veillard4255d502002-04-16 15:50:10 +000011547 child = node->children;
11548 if (IS_SCHEMA(child, "annotation")) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011549 /*
11550 * Add the annotation to the simple type ancestor.
11551 */
11552 xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) type,
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000011553 xmlSchemaParseAnnotation(ctxt, child, 1));
Daniel Veillardd0c9c322003-10-10 00:49:42 +000011554 child = child->next;
Daniel Veillard4255d502002-04-16 15:50:10 +000011555 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011556 if (parentType == XML_SCHEMA_TYPE_SIMPLE) {
11557 /*
11558 * Corresponds to <simpleType><restriction><simpleType>.
11559 */
William M. Brack2f2a6632004-08-20 23:09:47 +000011560 if (IS_SCHEMA(child, "simpleType")) {
11561 if (type->base != NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011562 /*
William M. Brack2f2a6632004-08-20 23:09:47 +000011563 * src-restriction-base-or-simpleType
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011564 * Either the base [attribute] or the simpleType [child] of the
11565 * <restriction> element must be present, but not both.
William M. Brack2f2a6632004-08-20 23:09:47 +000011566 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011567 xmlSchemaPContentErr(ctxt,
William M. Brack2f2a6632004-08-20 23:09:47 +000011568 XML_SCHEMAP_SRC_RESTRICTION_BASE_OR_SIMPLETYPE,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011569 NULL, node, child,
William M. Brack2f2a6632004-08-20 23:09:47 +000011570 "The attribute 'base' and the <simpleType> child are "
11571 "mutually exclusive", NULL);
11572 } else {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011573 type->baseType = (xmlSchemaTypePtr)
William M. Brack2f2a6632004-08-20 23:09:47 +000011574 xmlSchemaParseSimpleType(ctxt, schema, child, 0);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011575 }
William M. Brack2f2a6632004-08-20 23:09:47 +000011576 child = child->next;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011577 } else if (type->base == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011578 xmlSchemaPContentErr(ctxt,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011579 XML_SCHEMAP_SRC_RESTRICTION_BASE_OR_SIMPLETYPE,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011580 NULL, node, child,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011581 "Either the attribute 'base' or a <simpleType> child "
11582 "must be present", NULL);
William M. Brack2f2a6632004-08-20 23:09:47 +000011583 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011584 } else if (parentType == XML_SCHEMA_TYPE_COMPLEX_CONTENT) {
11585 /*
11586 * Corresponds to <complexType><complexContent><restriction>...
11587 * followed by:
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011588 *
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011589 * Model groups <all>, <choice> and <sequence>.
11590 */
11591 if (IS_SCHEMA(child, "all")) {
11592 type->subtypes = (xmlSchemaTypePtr)
11593 xmlSchemaParseModelGroup(ctxt, schema, child,
11594 XML_SCHEMA_TYPE_ALL, 1);
Daniel Veillard01fa6152004-06-29 17:04:39 +000011595 child = child->next;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011596 } else if (IS_SCHEMA(child, "choice")) {
11597 type->subtypes = (xmlSchemaTypePtr)
11598 xmlSchemaParseModelGroup(ctxt,
11599 schema, child, XML_SCHEMA_TYPE_CHOICE, 1);
11600 child = child->next;
11601 } else if (IS_SCHEMA(child, "sequence")) {
11602 type->subtypes = (xmlSchemaTypePtr)
11603 xmlSchemaParseModelGroup(ctxt, schema, child,
11604 XML_SCHEMA_TYPE_SEQUENCE, 1);
11605 child = child->next;
11606 /*
11607 * Model group reference <group>.
11608 */
Daniel Veillarddee23482008-04-11 12:58:43 +000011609 } else if (IS_SCHEMA(child, "group")) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011610 type->subtypes = (xmlSchemaTypePtr)
11611 xmlSchemaParseModelGroupDefRef(ctxt, schema, child);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011612 /*
11613 * Note that the reference will be resolved in
11614 * xmlSchemaResolveTypeReferences();
11615 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011616 child = child->next;
11617 }
11618 } else if (parentType == XML_SCHEMA_TYPE_SIMPLE_CONTENT) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011619 /*
11620 * Corresponds to <complexType><simpleContent><restriction>...
11621 *
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011622 * "1.1 the simple type definition corresponding to the <simpleType>
11623 * among the [children] of <restriction> if there is one;"
11624 */
11625 if (IS_SCHEMA(child, "simpleType")) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011626 /*
11627 * We will store the to-be-restricted simple type in
11628 * type->contentTypeDef *temporarily*.
11629 */
11630 type->contentTypeDef = (xmlSchemaTypePtr)
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011631 xmlSchemaParseSimpleType(ctxt, schema, child, 0);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011632 if ( type->contentTypeDef == NULL)
11633 return (NULL);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011634 child = child->next;
11635 }
William M. Brack2f2a6632004-08-20 23:09:47 +000011636 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011637
11638 if ((parentType == XML_SCHEMA_TYPE_SIMPLE) ||
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011639 (parentType == XML_SCHEMA_TYPE_SIMPLE_CONTENT)) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011640 xmlSchemaFacetPtr facet, lastfacet = NULL;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011641 /*
11642 * Corresponds to <complexType><simpleContent><restriction>...
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011643 * <simpleType><restriction>...
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011644 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011645
Daniel Veillard01fa6152004-06-29 17:04:39 +000011646 /*
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011647 * Add the facets to the simple type ancestor.
Daniel Veillard01fa6152004-06-29 17:04:39 +000011648 */
Daniel Veillardc0826a72004-08-10 14:17:33 +000011649 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011650 * TODO: Datatypes: 4.1.3 Constraints on XML Representation of
11651 * Simple Type Definition Schema Representation Constraint:
Daniel Veillardc0826a72004-08-10 14:17:33 +000011652 * *Single Facet Value*
11653 */
Daniel Veillard01fa6152004-06-29 17:04:39 +000011654 while ((IS_SCHEMA(child, "minInclusive")) ||
11655 (IS_SCHEMA(child, "minExclusive")) ||
11656 (IS_SCHEMA(child, "maxInclusive")) ||
11657 (IS_SCHEMA(child, "maxExclusive")) ||
11658 (IS_SCHEMA(child, "totalDigits")) ||
11659 (IS_SCHEMA(child, "fractionDigits")) ||
11660 (IS_SCHEMA(child, "pattern")) ||
11661 (IS_SCHEMA(child, "enumeration")) ||
11662 (IS_SCHEMA(child, "whiteSpace")) ||
11663 (IS_SCHEMA(child, "length")) ||
11664 (IS_SCHEMA(child, "maxLength")) ||
11665 (IS_SCHEMA(child, "minLength"))) {
11666 facet = xmlSchemaParseFacet(ctxt, schema, child);
11667 if (facet != NULL) {
11668 if (lastfacet == NULL)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011669 type->facets = facet;
Daniel Veillard01fa6152004-06-29 17:04:39 +000011670 else
11671 lastfacet->next = facet;
11672 lastfacet = facet;
11673 lastfacet->next = NULL;
11674 }
11675 child = child->next;
11676 }
11677 /*
11678 * Create links for derivation and validation.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011679 */
11680 if (type->facets != NULL) {
Daniel Veillard01fa6152004-06-29 17:04:39 +000011681 xmlSchemaFacetLinkPtr facetLink, lastFacetLink = NULL;
11682
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011683 facet = type->facets;
11684 do {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011685 facetLink = (xmlSchemaFacetLinkPtr)
11686 xmlMalloc(sizeof(xmlSchemaFacetLink));
Daniel Veillard01fa6152004-06-29 17:04:39 +000011687 if (facetLink == NULL) {
William M. Brack2f2a6632004-08-20 23:09:47 +000011688 xmlSchemaPErrMemory(ctxt, "allocating a facet link", NULL);
Daniel Veillard01fa6152004-06-29 17:04:39 +000011689 xmlFree(facetLink);
11690 return (NULL);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011691 }
Daniel Veillard01fa6152004-06-29 17:04:39 +000011692 facetLink->facet = facet;
11693 facetLink->next = NULL;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011694 if (lastFacetLink == NULL)
11695 type->facetSet = facetLink;
Daniel Veillard01fa6152004-06-29 17:04:39 +000011696 else
11697 lastFacetLink->next = facetLink;
11698 lastFacetLink = facetLink;
11699 facet = facet->next;
11700 } while (facet != NULL);
11701 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011702 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011703 if (type->type == XML_SCHEMA_TYPE_COMPLEX) {
11704 /*
11705 * Attribute uses/declarations.
11706 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011707 if (xmlSchemaParseLocalAttributes(ctxt, schema, &child,
11708 (xmlSchemaItemListPtr *) &(type->attrUses),
11709 XML_SCHEMA_TYPE_RESTRICTION, NULL) == -1)
11710 return(NULL);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011711 /*
11712 * Attribute wildcard.
11713 */
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000011714 if (IS_SCHEMA(child, "anyAttribute")) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011715 type->attributeWildcard =
11716 xmlSchemaParseAnyAttribute(ctxt, schema, child);
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000011717 child = child->next;
11718 }
11719 }
Daniel Veillard4255d502002-04-16 15:50:10 +000011720 if (child != NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011721 if (parentType == XML_SCHEMA_TYPE_COMPLEX_CONTENT) {
11722 xmlSchemaPContentErr(ctxt,
11723 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011724 NULL, node, child, NULL,
William M. Brack2f2a6632004-08-20 23:09:47 +000011725 "annotation?, (group | all | choice | sequence)?, "
11726 "((attribute | attributeGroup)*, anyAttribute?))");
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011727 } else if (parentType == XML_SCHEMA_TYPE_SIMPLE_CONTENT) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011728 xmlSchemaPContentErr(ctxt,
11729 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011730 NULL, node, child, NULL,
William M. Brack2f2a6632004-08-20 23:09:47 +000011731 "(annotation?, (simpleType?, (minExclusive | minInclusive | "
11732 "maxExclusive | maxInclusive | totalDigits | fractionDigits | "
11733 "length | minLength | maxLength | enumeration | whiteSpace | "
11734 "pattern)*)?, ((attribute | attributeGroup)*, anyAttribute?))");
11735 } else {
11736 /* Simple type */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011737 xmlSchemaPContentErr(ctxt,
11738 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011739 NULL, node, child, NULL,
William M. Brack2f2a6632004-08-20 23:09:47 +000011740 "(annotation?, (simpleType?, (minExclusive | minInclusive | "
11741 "maxExclusive | maxInclusive | totalDigits | fractionDigits | "
11742 "length | minLength | maxLength | enumeration | whiteSpace | "
11743 "pattern)*))");
11744 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011745 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011746 return (NULL);
Daniel Veillard4255d502002-04-16 15:50:10 +000011747}
11748
11749/**
11750 * xmlSchemaParseExtension:
11751 * @ctxt: a schema validation context
11752 * @schema: the schema being built
11753 * @node: a subtree containing XML Schema informations
11754 *
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011755 * Parses an <extension>, which is found inside a
11756 * <simpleContent> or <complexContent>.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011757 * *WARNING* this interface is highly subject to change.
Daniel Veillard4255d502002-04-16 15:50:10 +000011758 *
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011759 * TODO: Returns the type definition or NULL in case of error
Daniel Veillard4255d502002-04-16 15:50:10 +000011760 */
11761static xmlSchemaTypePtr
11762xmlSchemaParseExtension(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011763 xmlNodePtr node, xmlSchemaTypeType parentType)
Daniel Veillard4255d502002-04-16 15:50:10 +000011764{
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011765 xmlSchemaTypePtr type;
Daniel Veillard4255d502002-04-16 15:50:10 +000011766 xmlNodePtr child = NULL;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011767 xmlAttrPtr attr;
Daniel Veillard4255d502002-04-16 15:50:10 +000011768
11769 if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
11770 return (NULL);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011771 /* Not a component, don't create it. */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011772 type = ctxt->ctxtType;
11773 type->flags |= XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION;
Daniel Veillard4255d502002-04-16 15:50:10 +000011774
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011775 /*
11776 * Check for illegal attributes.
11777 */
11778 attr = node->properties;
11779 while (attr != NULL) {
11780 if (attr->ns == NULL) {
11781 if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
11782 (!xmlStrEqual(attr->name, BAD_CAST "base"))) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011783 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011784 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011785 }
11786 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011787 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011788 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011789 }
11790 attr = attr->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011791 }
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +000011792
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011793 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011794
Kasimier T. Buchcik289dbb42005-03-17 12:39:31 +000011795 /*
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011796 * Attribute "base" - mandatory.
Kasimier T. Buchcik289dbb42005-03-17 12:39:31 +000011797 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011798 if ((xmlSchemaPValAttrQName(ctxt, schema, NULL, node,
11799 "base", &(type->baseNs), &(type->base)) == 0) &&
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011800 (type->base == NULL)) {
Kasimier T. Buchcik289dbb42005-03-17 12:39:31 +000011801 xmlSchemaPMissingAttrErr(ctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011802 XML_SCHEMAP_S4S_ATTR_MISSING,
11803 NULL, node, "base", NULL);
11804 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011805 /*
11806 * And now for the children...
11807 */
Daniel Veillard4255d502002-04-16 15:50:10 +000011808 child = node->children;
11809 if (IS_SCHEMA(child, "annotation")) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011810 /*
11811 * Add the annotation to the type ancestor.
11812 */
11813 xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) type,
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000011814 xmlSchemaParseAnnotation(ctxt, child, 1));
Daniel Veillardd0c9c322003-10-10 00:49:42 +000011815 child = child->next;
Daniel Veillard4255d502002-04-16 15:50:10 +000011816 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011817 if (parentType == XML_SCHEMA_TYPE_COMPLEX_CONTENT) {
11818 /*
11819 * Corresponds to <complexType><complexContent><extension>... and:
11820 *
11821 * Model groups <all>, <choice>, <sequence> and <group>.
11822 */
11823 if (IS_SCHEMA(child, "all")) {
11824 type->subtypes = (xmlSchemaTypePtr)
11825 xmlSchemaParseModelGroup(ctxt, schema,
11826 child, XML_SCHEMA_TYPE_ALL, 1);
11827 child = child->next;
11828 } else if (IS_SCHEMA(child, "choice")) {
11829 type->subtypes = (xmlSchemaTypePtr)
11830 xmlSchemaParseModelGroup(ctxt, schema,
11831 child, XML_SCHEMA_TYPE_CHOICE, 1);
11832 child = child->next;
11833 } else if (IS_SCHEMA(child, "sequence")) {
11834 type->subtypes = (xmlSchemaTypePtr)
11835 xmlSchemaParseModelGroup(ctxt, schema,
11836 child, XML_SCHEMA_TYPE_SEQUENCE, 1);
11837 child = child->next;
11838 } else if (IS_SCHEMA(child, "group")) {
11839 type->subtypes = (xmlSchemaTypePtr)
11840 xmlSchemaParseModelGroupDefRef(ctxt, schema, child);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011841 /*
11842 * Note that the reference will be resolved in
11843 * xmlSchemaResolveTypeReferences();
11844 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011845 child = child->next;
11846 }
Daniel Veillard4255d502002-04-16 15:50:10 +000011847 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011848 if (child != NULL) {
11849 /*
11850 * Attribute uses/declarations.
11851 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011852 if (xmlSchemaParseLocalAttributes(ctxt, schema, &child,
11853 (xmlSchemaItemListPtr *) &(type->attrUses),
11854 XML_SCHEMA_TYPE_EXTENSION, NULL) == -1)
11855 return(NULL);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011856 /*
11857 * Attribute wildcard.
11858 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011859 if (IS_SCHEMA(child, "anyAttribute")) {
11860 ctxt->ctxtType->attributeWildcard =
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000011861 xmlSchemaParseAnyAttribute(ctxt, schema, child);
11862 child = child->next;
11863 }
11864 }
Daniel Veillard4255d502002-04-16 15:50:10 +000011865 if (child != NULL) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011866 if (parentType == XML_SCHEMA_TYPE_COMPLEX_CONTENT) {
11867 /* Complex content extension. */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011868 xmlSchemaPContentErr(ctxt,
11869 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011870 NULL, node, child, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011871 "(annotation?, ((group | all | choice | sequence)?, "
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011872 "((attribute | attributeGroup)*, anyAttribute?)))");
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011873 } else {
11874 /* Simple content extension. */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011875 xmlSchemaPContentErr(ctxt,
11876 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011877 NULL, node, child, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011878 "(annotation?, ((attribute | attributeGroup)*, "
11879 "anyAttribute?))");
11880 }
Daniel Veillard4255d502002-04-16 15:50:10 +000011881 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011882 return (NULL);
Daniel Veillard4255d502002-04-16 15:50:10 +000011883}
11884
11885/**
11886 * xmlSchemaParseSimpleContent:
11887 * @ctxt: a schema validation context
11888 * @schema: the schema being built
11889 * @node: a subtree containing XML Schema informations
11890 *
11891 * parse a XML schema SimpleContent definition
11892 * *WARNING* this interface is highly subject to change
11893 *
11894 * Returns the type definition or NULL in case of error
11895 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011896static int
Daniel Veillardd0c9c322003-10-10 00:49:42 +000011897xmlSchemaParseSimpleContent(xmlSchemaParserCtxtPtr ctxt,
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000011898 xmlSchemaPtr schema, xmlNodePtr node,
11899 int *hasRestrictionOrExtension)
Daniel Veillard4255d502002-04-16 15:50:10 +000011900{
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011901 xmlSchemaTypePtr type;
Daniel Veillard4255d502002-04-16 15:50:10 +000011902 xmlNodePtr child = NULL;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011903 xmlAttrPtr attr;
Daniel Veillard4255d502002-04-16 15:50:10 +000011904
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000011905 if ((ctxt == NULL) || (schema == NULL) || (node == NULL) ||
11906 (hasRestrictionOrExtension == NULL))
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011907 return (-1);
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000011908 *hasRestrictionOrExtension = 0;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011909 /* Not a component, don't create it. */
11910 type = ctxt->ctxtType;
11911 type->contentType = XML_SCHEMA_CONTENT_SIMPLE;
11912 /*
11913 * Check for illegal attributes.
11914 */
11915 attr = node->properties;
11916 while (attr != NULL) {
11917 if (attr->ns == NULL) {
11918 if ((!xmlStrEqual(attr->name, BAD_CAST "id"))) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011919 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011920 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011921 }
11922 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011923 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011924 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011925 }
11926 attr = attr->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011927 }
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +000011928
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011929 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
Daniel Veillard4255d502002-04-16 15:50:10 +000011930
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011931 /*
11932 * And now for the children...
11933 */
Daniel Veillard4255d502002-04-16 15:50:10 +000011934 child = node->children;
11935 if (IS_SCHEMA(child, "annotation")) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011936 /*
11937 * Add the annotation to the complex type ancestor.
11938 */
11939 xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) type,
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000011940 xmlSchemaParseAnnotation(ctxt, child, 1));
Daniel Veillardd0c9c322003-10-10 00:49:42 +000011941 child = child->next;
Daniel Veillard4255d502002-04-16 15:50:10 +000011942 }
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000011943 if (child == NULL) {
11944 xmlSchemaPContentErr(ctxt,
11945 XML_SCHEMAP_S4S_ELEM_MISSING,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011946 NULL, node, NULL, NULL,
Daniel Veillarddee23482008-04-11 12:58:43 +000011947 "(annotation?, (restriction | extension))");
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000011948 }
Kasimier T. Buchcik630215b2005-08-22 10:15:39 +000011949 if (child == NULL) {
11950 xmlSchemaPContentErr(ctxt,
11951 XML_SCHEMAP_S4S_ELEM_MISSING,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011952 NULL, node, NULL, NULL,
Daniel Veillarddee23482008-04-11 12:58:43 +000011953 "(annotation?, (restriction | extension))");
Kasimier T. Buchcik630215b2005-08-22 10:15:39 +000011954 }
Daniel Veillard4255d502002-04-16 15:50:10 +000011955 if (IS_SCHEMA(child, "restriction")) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011956 xmlSchemaParseRestriction(ctxt, schema, child,
11957 XML_SCHEMA_TYPE_SIMPLE_CONTENT);
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000011958 (*hasRestrictionOrExtension) = 1;
Daniel Veillardd0c9c322003-10-10 00:49:42 +000011959 child = child->next;
Daniel Veillard4255d502002-04-16 15:50:10 +000011960 } else if (IS_SCHEMA(child, "extension")) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011961 xmlSchemaParseExtension(ctxt, schema, child,
11962 XML_SCHEMA_TYPE_SIMPLE_CONTENT);
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000011963 (*hasRestrictionOrExtension) = 1;
Daniel Veillardd0c9c322003-10-10 00:49:42 +000011964 child = child->next;
Daniel Veillard4255d502002-04-16 15:50:10 +000011965 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000011966 if (child != NULL) {
11967 xmlSchemaPContentErr(ctxt,
11968 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000011969 NULL, node, child, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011970 "(annotation?, (restriction | extension))");
Daniel Veillard4255d502002-04-16 15:50:10 +000011971 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011972 return (0);
Daniel Veillard4255d502002-04-16 15:50:10 +000011973}
11974
11975/**
11976 * xmlSchemaParseComplexContent:
11977 * @ctxt: a schema validation context
11978 * @schema: the schema being built
11979 * @node: a subtree containing XML Schema informations
11980 *
11981 * parse a XML schema ComplexContent definition
11982 * *WARNING* this interface is highly subject to change
11983 *
11984 * Returns the type definition or NULL in case of error
11985 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011986static int
Daniel Veillardd0c9c322003-10-10 00:49:42 +000011987xmlSchemaParseComplexContent(xmlSchemaParserCtxtPtr ctxt,
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000011988 xmlSchemaPtr schema, xmlNodePtr node,
11989 int *hasRestrictionOrExtension)
Daniel Veillard4255d502002-04-16 15:50:10 +000011990{
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011991 xmlSchemaTypePtr type;
Daniel Veillard4255d502002-04-16 15:50:10 +000011992 xmlNodePtr child = NULL;
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000011993 xmlAttrPtr attr;
Daniel Veillard4255d502002-04-16 15:50:10 +000011994
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000011995 if ((ctxt == NULL) || (schema == NULL) || (node == NULL) ||
11996 (hasRestrictionOrExtension == NULL))
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011997 return (-1);
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000011998 *hasRestrictionOrExtension = 0;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000011999 /* Not a component, don't create it. */
12000 type = ctxt->ctxtType;
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012001 /*
12002 * Check for illegal attributes.
12003 */
12004 attr = node->properties;
12005 while (attr != NULL) {
12006 if (attr->ns == NULL) {
12007 if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012008 (!xmlStrEqual(attr->name, BAD_CAST "mixed")))
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012009 {
12010 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000012011 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012012 }
12013 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
12014 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000012015 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012016 }
12017 attr = attr->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012018 }
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +000012019
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000012020 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +000012021
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012022 /*
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012023 * Set the 'mixed' on the complex type ancestor.
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012024 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000012025 if (xmlGetBooleanProp(ctxt, node, "mixed", 0)) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012026 if ((type->flags & XML_SCHEMAS_TYPE_MIXED) == 0)
12027 type->flags |= XML_SCHEMAS_TYPE_MIXED;
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012028 }
Daniel Veillard4255d502002-04-16 15:50:10 +000012029 child = node->children;
12030 if (IS_SCHEMA(child, "annotation")) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012031 /*
12032 * Add the annotation to the complex type ancestor.
12033 */
12034 xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) type,
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000012035 xmlSchemaParseAnnotation(ctxt, child, 1));
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012036 child = child->next;
Daniel Veillard4255d502002-04-16 15:50:10 +000012037 }
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000012038 if (child == NULL) {
12039 xmlSchemaPContentErr(ctxt,
12040 XML_SCHEMAP_S4S_ELEM_MISSING,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000012041 NULL, node, NULL,
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000012042 NULL, "(annotation?, (restriction | extension))");
12043 }
Kasimier T. Buchcik630215b2005-08-22 10:15:39 +000012044 if (child == NULL) {
12045 xmlSchemaPContentErr(ctxt,
12046 XML_SCHEMAP_S4S_ELEM_MISSING,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000012047 NULL, node, NULL,
Kasimier T. Buchcik630215b2005-08-22 10:15:39 +000012048 NULL, "(annotation?, (restriction | extension))");
12049 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012050 if (IS_SCHEMA(child, "restriction")) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012051 xmlSchemaParseRestriction(ctxt, schema, child,
12052 XML_SCHEMA_TYPE_COMPLEX_CONTENT);
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000012053 (*hasRestrictionOrExtension) = 1;
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012054 child = child->next;
Daniel Veillard4255d502002-04-16 15:50:10 +000012055 } else if (IS_SCHEMA(child, "extension")) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012056 xmlSchemaParseExtension(ctxt, schema, child,
12057 XML_SCHEMA_TYPE_COMPLEX_CONTENT);
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000012058 (*hasRestrictionOrExtension) = 1;
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012059 child = child->next;
Daniel Veillard4255d502002-04-16 15:50:10 +000012060 }
Daniel Veillard4255d502002-04-16 15:50:10 +000012061 if (child != NULL) {
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012062 xmlSchemaPContentErr(ctxt,
12063 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000012064 NULL, node, child,
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012065 NULL, "(annotation?, (restriction | extension))");
Daniel Veillard4255d502002-04-16 15:50:10 +000012066 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012067 return (0);
Daniel Veillard4255d502002-04-16 15:50:10 +000012068}
12069
12070/**
12071 * xmlSchemaParseComplexType:
12072 * @ctxt: a schema validation context
12073 * @schema: the schema being built
12074 * @node: a subtree containing XML Schema informations
12075 *
12076 * parse a XML schema Complex Type definition
12077 * *WARNING* this interface is highly subject to change
12078 *
12079 * Returns the type definition or NULL in case of error
12080 */
12081static xmlSchemaTypePtr
12082xmlSchemaParseComplexType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
Daniel Veillard3646d642004-06-02 19:19:14 +000012083 xmlNodePtr node, int topLevel)
Daniel Veillard4255d502002-04-16 15:50:10 +000012084{
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012085 xmlSchemaTypePtr type, ctxtType;
Daniel Veillard4255d502002-04-16 15:50:10 +000012086 xmlNodePtr child = NULL;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000012087 const xmlChar *name = NULL;
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012088 xmlAttrPtr attr;
12089 const xmlChar *attrValue;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000012090#ifdef ENABLE_NAMED_LOCALS
Daniel Veillard1a380b82004-10-21 16:00:06 +000012091 char buf[40];
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000012092#endif
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000012093 int final = 0, block = 0, hasRestrictionOrExtension = 0;
Daniel Veillard1a380b82004-10-21 16:00:06 +000012094
Daniel Veillard4255d502002-04-16 15:50:10 +000012095
12096 if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
12097 return (NULL);
12098
Daniel Veillard01fa6152004-06-29 17:04:39 +000012099 ctxtType = ctxt->ctxtType;
12100
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012101 if (topLevel) {
12102 attr = xmlSchemaGetPropNode(node, "name");
12103 if (attr == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012104 xmlSchemaPMissingAttrErr(ctxt,
12105 XML_SCHEMAP_S4S_ATTR_MISSING, NULL, node, "name", NULL);
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012106 return (NULL);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000012107 } else if (xmlSchemaPValAttrNode(ctxt, NULL, attr,
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012108 xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) {
12109 return (NULL);
Daniel Veillarddee23482008-04-11 12:58:43 +000012110 }
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012111 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012112
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012113 if (topLevel == 0) {
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012114 /*
12115 * Parse as local complex type definition.
12116 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000012117#ifdef ENABLE_NAMED_LOCALS
Kasimier T. Buchcik87250a92005-01-28 15:59:53 +000012118 snprintf(buf, 39, "#CT%d", ctxt->counter++ + 1);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000012119 type = xmlSchemaAddType(ctxt, schema,
12120 XML_SCHEMA_TYPE_COMPLEX,
12121 xmlDictLookup(ctxt->dict, (const xmlChar *)buf, -1),
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000012122 ctxt->targetNamespace, node, 0);
12123#else
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000012124 type = xmlSchemaAddType(ctxt, schema,
12125 XML_SCHEMA_TYPE_COMPLEX,
12126 NULL, ctxt->targetNamespace, node, 0);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000012127#endif
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012128 if (type == NULL)
12129 return (NULL);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012130 name = type->name;
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012131 type->node = node;
12132 type->type = XML_SCHEMA_TYPE_COMPLEX;
12133 /*
12134 * TODO: We need the target namespace.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012135 */
12136 } else {
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012137 /*
12138 * Parse as global complex type definition.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012139 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000012140 type = xmlSchemaAddType(ctxt, schema,
12141 XML_SCHEMA_TYPE_COMPLEX,
12142 name, ctxt->targetNamespace, node, 1);
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012143 if (type == NULL)
12144 return (NULL);
12145 type->node = node;
12146 type->type = XML_SCHEMA_TYPE_COMPLEX;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012147 type->flags |= XML_SCHEMAS_TYPE_GLOBAL;
Kasimier T. Buchcik31113c72005-01-13 16:57:20 +000012148 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000012149 type->targetNamespace = ctxt->targetNamespace;
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012150 /*
12151 * Handle attributes.
12152 */
12153 attr = node->properties;
12154 while (attr != NULL) {
12155 if (attr->ns == NULL) {
12156 if (xmlStrEqual(attr->name, BAD_CAST "id")) {
12157 /*
12158 * Attribute "id".
12159 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000012160 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012161 } else if (xmlStrEqual(attr->name, BAD_CAST "mixed")) {
12162 /*
12163 * Attribute "mixed".
12164 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000012165 if (xmlSchemaPGetBoolNodeValue(ctxt,
12166 NULL, (xmlNodePtr) attr))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012167 type->flags |= XML_SCHEMAS_TYPE_MIXED;
12168 } else if (topLevel) {
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012169 /*
12170 * Attributes of global complex type definitions.
12171 */
12172 if (xmlStrEqual(attr->name, BAD_CAST "name")) {
12173 /* Pass. */
12174 } else if (xmlStrEqual(attr->name, BAD_CAST "abstract")) {
12175 /*
12176 * Attribute "abstract".
12177 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000012178 if (xmlSchemaPGetBoolNodeValue(ctxt,
12179 NULL, (xmlNodePtr) attr))
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012180 type->flags |= XML_SCHEMAS_TYPE_ABSTRACT;
12181 } else if (xmlStrEqual(attr->name, BAD_CAST "final")) {
12182 /*
12183 * Attribute "final".
12184 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012185 attrValue = xmlSchemaGetNodeContent(ctxt,
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012186 (xmlNodePtr) attr);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012187 if (xmlSchemaPValAttrBlockFinal(attrValue,
12188 &(type->flags),
12189 -1,
12190 XML_SCHEMAS_TYPE_FINAL_EXTENSION,
12191 XML_SCHEMAS_TYPE_FINAL_RESTRICTION,
12192 -1, -1, -1) != 0)
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012193 {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012194 xmlSchemaPSimpleTypeErr(ctxt,
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012195 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000012196 NULL, (xmlNodePtr) attr, NULL,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012197 "(#all | List of (extension | restriction))",
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012198 attrValue, NULL, NULL, NULL);
Daniel Veillarddee23482008-04-11 12:58:43 +000012199 } else
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012200 final = 1;
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012201 } else if (xmlStrEqual(attr->name, BAD_CAST "block")) {
12202 /*
12203 * Attribute "block".
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012204 */
12205 attrValue = xmlSchemaGetNodeContent(ctxt,
12206 (xmlNodePtr) attr);
12207 if (xmlSchemaPValAttrBlockFinal(attrValue, &(type->flags),
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012208 -1,
12209 XML_SCHEMAS_TYPE_BLOCK_EXTENSION,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012210 XML_SCHEMAS_TYPE_BLOCK_RESTRICTION,
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012211 -1, -1, -1) != 0) {
12212 xmlSchemaPSimpleTypeErr(ctxt,
12213 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000012214 NULL, (xmlNodePtr) attr, NULL,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012215 "(#all | List of (extension | restriction)) ",
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012216 attrValue, NULL, NULL, NULL);
Daniel Veillarddee23482008-04-11 12:58:43 +000012217 } else
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012218 block = 1;
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012219 } else {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012220 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000012221 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012222 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012223 } else {
12224 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000012225 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012226 }
12227 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
Daniel Veillarddee23482008-04-11 12:58:43 +000012228 xmlSchemaPIllegalAttrErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000012229 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012230 }
12231 attr = attr->next;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012232 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012233 if (! block) {
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000012234 /*
12235 * Apply default "block" values.
12236 */
12237 if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION)
12238 type->flags |= XML_SCHEMAS_TYPE_BLOCK_RESTRICTION;
12239 if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION)
12240 type->flags |= XML_SCHEMAS_TYPE_BLOCK_EXTENSION;
12241 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012242 if (! final) {
12243 /*
12244 * Apply default "block" values.
12245 */
12246 if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION)
12247 type->flags |= XML_SCHEMAS_TYPE_FINAL_RESTRICTION;
12248 if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_EXTENSION)
12249 type->flags |= XML_SCHEMAS_TYPE_FINAL_EXTENSION;
12250 }
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012251 /*
12252 * And now for the children...
12253 */
Daniel Veillard4255d502002-04-16 15:50:10 +000012254 child = node->children;
12255 if (IS_SCHEMA(child, "annotation")) {
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000012256 type->annot = xmlSchemaParseAnnotation(ctxt, child, 1);
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012257 child = child->next;
Daniel Veillard4255d502002-04-16 15:50:10 +000012258 }
Daniel Veillard01fa6152004-06-29 17:04:39 +000012259 ctxt->ctxtType = type;
Daniel Veillard4255d502002-04-16 15:50:10 +000012260 if (IS_SCHEMA(child, "simpleContent")) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012261 /*
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000012262 * <complexType><simpleContent>...
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012263 * 3.4.3 : 2.2
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012264 * Specifying mixed='true' when the <simpleContent>
12265 * alternative is chosen has no effect
12266 */
William M. Bracke7091952004-05-11 15:09:58 +000012267 if (type->flags & XML_SCHEMAS_TYPE_MIXED)
12268 type->flags ^= XML_SCHEMAS_TYPE_MIXED;
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000012269 xmlSchemaParseSimpleContent(ctxt, schema, child,
12270 &hasRestrictionOrExtension);
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012271 child = child->next;
Daniel Veillard4255d502002-04-16 15:50:10 +000012272 } else if (IS_SCHEMA(child, "complexContent")) {
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000012273 /*
12274 * <complexType><complexContent>...
12275 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012276 type->contentType = XML_SCHEMA_CONTENT_EMPTY;
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000012277 xmlSchemaParseComplexContent(ctxt, schema, child,
12278 &hasRestrictionOrExtension);
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012279 child = child->next;
Daniel Veillard4255d502002-04-16 15:50:10 +000012280 } else {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012281 /*
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000012282 * E.g <complexType><sequence>... or <complexType><attribute>... etc.
12283 *
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012284 * SPEC
12285 * "...the third alternative (neither <simpleContent> nor
12286 * <complexContent>) is chosen. This case is understood as shorthand
Rob Richardsc6947bb2008-06-29 15:04:41 +000012287 * for complex content restricting the �ur-type definition�, and the
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012288 * details of the mappings should be modified as necessary.
12289 */
12290 type->baseType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE);
12291 type->flags |= XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION;
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012292 /*
12293 * Parse model groups.
12294 */
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012295 if (IS_SCHEMA(child, "all")) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012296 type->subtypes = (xmlSchemaTypePtr)
12297 xmlSchemaParseModelGroup(ctxt, schema, child,
12298 XML_SCHEMA_TYPE_ALL, 1);
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012299 child = child->next;
12300 } else if (IS_SCHEMA(child, "choice")) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012301 type->subtypes = (xmlSchemaTypePtr)
12302 xmlSchemaParseModelGroup(ctxt, schema, child,
12303 XML_SCHEMA_TYPE_CHOICE, 1);
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012304 child = child->next;
12305 } else if (IS_SCHEMA(child, "sequence")) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012306 type->subtypes = (xmlSchemaTypePtr)
12307 xmlSchemaParseModelGroup(ctxt, schema, child,
12308 XML_SCHEMA_TYPE_SEQUENCE, 1);
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012309 child = child->next;
12310 } else if (IS_SCHEMA(child, "group")) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012311 type->subtypes = (xmlSchemaTypePtr)
12312 xmlSchemaParseModelGroupDefRef(ctxt, schema, child);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000012313 /*
12314 * Note that the reference will be resolved in
12315 * xmlSchemaResolveTypeReferences();
12316 */
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012317 child = child->next;
12318 }
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012319 /*
12320 * Parse attribute decls/refs.
12321 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000012322 if (xmlSchemaParseLocalAttributes(ctxt, schema, &child,
12323 (xmlSchemaItemListPtr *) &(type->attrUses),
12324 XML_SCHEMA_TYPE_RESTRICTION, NULL) == -1)
12325 return(NULL);
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012326 /*
12327 * Parse attribute wildcard.
12328 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012329 if (IS_SCHEMA(child, "anyAttribute")) {
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000012330 type->attributeWildcard = xmlSchemaParseAnyAttribute(ctxt, schema, child);
12331 child = child->next;
12332 }
Daniel Veillard4255d502002-04-16 15:50:10 +000012333 }
12334 if (child != NULL) {
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012335 xmlSchemaPContentErr(ctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012336 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000012337 NULL, node, child,
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012338 NULL, "(annotation?, (simpleContent | complexContent | "
12339 "((group | all | choice | sequence)?, ((attribute | "
12340 "attributeGroup)*, anyAttribute?))))");
Daniel Veillard4255d502002-04-16 15:50:10 +000012341 }
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000012342 /*
12343 * REDEFINE: SPEC src-redefine (5)
12344 */
12345 if (topLevel && ctxt->isRedefine && (! hasRestrictionOrExtension)) {
12346 xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_SRC_REDEFINE,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000012347 NULL, node, "This is a redefinition, thus the "
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000012348 "<complexType> must have a <restriction> or <extension> "
12349 "grand-child", NULL);
12350 }
Daniel Veillard01fa6152004-06-29 17:04:39 +000012351 ctxt->ctxtType = ctxtType;
Daniel Veillard4255d502002-04-16 15:50:10 +000012352 return (type);
12353}
12354
Daniel Veillard4255d502002-04-16 15:50:10 +000012355/************************************************************************
12356 * *
12357 * Validating using Schemas *
12358 * *
12359 ************************************************************************/
12360
12361/************************************************************************
12362 * *
12363 * Reading/Writing Schemas *
12364 * *
12365 ************************************************************************/
12366
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000012367#if 0 /* Will be enabled if it is clear what options are needed. */
12368/**
12369 * xmlSchemaParserCtxtSetOptions:
12370 * @ctxt: a schema parser context
12371 * @options: a combination of xmlSchemaParserOption
12372 *
12373 * Sets the options to be used during the parse.
12374 *
12375 * Returns 0 in case of success, -1 in case of an
12376 * API error.
12377 */
12378static int
12379xmlSchemaParserCtxtSetOptions(xmlSchemaParserCtxtPtr ctxt,
12380 int options)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012381
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000012382{
12383 int i;
12384
12385 if (ctxt == NULL)
12386 return (-1);
12387 /*
12388 * WARNING: Change the start value if adding to the
12389 * xmlSchemaParseOption.
12390 */
12391 for (i = 1; i < (int) sizeof(int) * 8; i++) {
12392 if (options & 1<<i) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012393 return (-1);
12394 }
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000012395 }
12396 ctxt->options = options;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012397 return (0);
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000012398}
12399
12400/**
12401 * xmlSchemaValidCtxtGetOptions:
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012402 * @ctxt: a schema parser context
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000012403 *
12404 * Returns the option combination of the parser context.
12405 */
12406static int
12407xmlSchemaParserCtxtGetOptions(xmlSchemaParserCtxtPtr ctxt)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012408
12409{
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000012410 if (ctxt == NULL)
12411 return (-1);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012412 else
12413 return (ctxt->options);
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000012414}
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000012415#endif
12416
Daniel Veillard4255d502002-04-16 15:50:10 +000012417/**
12418 * xmlSchemaNewParserCtxt:
12419 * @URL: the location of the schema
12420 *
12421 * Create an XML Schemas parse context for that file/resource expected
12422 * to contain an XML Schemas file.
12423 *
12424 * Returns the parser context or NULL in case of error
12425 */
12426xmlSchemaParserCtxtPtr
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012427xmlSchemaNewParserCtxt(const char *URL)
12428{
Daniel Veillard4255d502002-04-16 15:50:10 +000012429 xmlSchemaParserCtxtPtr ret;
12430
12431 if (URL == NULL)
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012432 return (NULL);
Daniel Veillard4255d502002-04-16 15:50:10 +000012433
Kasimier T. Buchcik630215b2005-08-22 10:15:39 +000012434 ret = xmlSchemaParserCtxtCreate();
12435 if (ret == NULL)
12436 return(NULL);
Daniel Veillardbe9c6322003-11-22 20:37:51 +000012437 ret->dict = xmlDictCreate();
12438 ret->URL = xmlDictLookup(ret->dict, (const xmlChar *) URL, -1);
Daniel Veillard4255d502002-04-16 15:50:10 +000012439 return (ret);
12440}
12441
12442/**
Daniel Veillard6045c902002-10-09 21:13:59 +000012443 * xmlSchemaNewMemParserCtxt:
12444 * @buffer: a pointer to a char array containing the schemas
12445 * @size: the size of the array
12446 *
12447 * Create an XML Schemas parse context for that memory buffer expected
12448 * to contain an XML Schemas file.
12449 *
12450 * Returns the parser context or NULL in case of error
12451 */
12452xmlSchemaParserCtxtPtr
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012453xmlSchemaNewMemParserCtxt(const char *buffer, int size)
12454{
Daniel Veillard6045c902002-10-09 21:13:59 +000012455 xmlSchemaParserCtxtPtr ret;
12456
12457 if ((buffer == NULL) || (size <= 0))
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012458 return (NULL);
Kasimier T. Buchcik630215b2005-08-22 10:15:39 +000012459 ret = xmlSchemaParserCtxtCreate();
12460 if (ret == NULL)
12461 return(NULL);
Daniel Veillard6045c902002-10-09 21:13:59 +000012462 ret->buffer = buffer;
12463 ret->size = size;
Daniel Veillarddee23482008-04-11 12:58:43 +000012464 ret->dict = xmlDictCreate();
Daniel Veillard6045c902002-10-09 21:13:59 +000012465 return (ret);
12466}
12467
12468/**
Daniel Veillard9d751502003-10-29 13:21:47 +000012469 * xmlSchemaNewDocParserCtxt:
12470 * @doc: a preparsed document tree
12471 *
12472 * Create an XML Schemas parse context for that document.
12473 * NB. The document may be modified during the parsing process.
12474 *
12475 * Returns the parser context or NULL in case of error
12476 */
12477xmlSchemaParserCtxtPtr
12478xmlSchemaNewDocParserCtxt(xmlDocPtr doc)
12479{
12480 xmlSchemaParserCtxtPtr ret;
12481
12482 if (doc == NULL)
12483 return (NULL);
Kasimier T. Buchcik630215b2005-08-22 10:15:39 +000012484 ret = xmlSchemaParserCtxtCreate();
12485 if (ret == NULL)
12486 return(NULL);
Daniel Veillard9d751502003-10-29 13:21:47 +000012487 ret->doc = doc;
William M. Brackcf9eadf2003-12-25 13:24:05 +000012488 ret->dict = xmlDictCreate();
Daniel Veillarddda22c12004-01-24 08:31:30 +000012489 /* The application has responsibility for the document */
12490 ret->preserve = 1;
Daniel Veillard9d751502003-10-29 13:21:47 +000012491
12492 return (ret);
12493}
12494
12495/**
Daniel Veillard4255d502002-04-16 15:50:10 +000012496 * xmlSchemaFreeParserCtxt:
12497 * @ctxt: the schema parser context
12498 *
12499 * Free the resources associated to the schema parser context
12500 */
12501void
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012502xmlSchemaFreeParserCtxt(xmlSchemaParserCtxtPtr ctxt)
12503{
Daniel Veillard4255d502002-04-16 15:50:10 +000012504 if (ctxt == NULL)
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012505 return;
Daniel Veillarddda22c12004-01-24 08:31:30 +000012506 if (ctxt->doc != NULL && !ctxt->preserve)
Daniel Veillarddee23482008-04-11 12:58:43 +000012507 xmlFreeDoc(ctxt->doc);
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012508 if (ctxt->vctxt != NULL) {
12509 xmlSchemaFreeValidCtxt(ctxt->vctxt);
12510 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000012511 if (ctxt->ownsConstructor && (ctxt->constructor != NULL)) {
12512 xmlSchemaConstructionCtxtFree(ctxt->constructor);
12513 ctxt->constructor = NULL;
12514 ctxt->ownsConstructor = 0;
12515 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000012516 if (ctxt->attrProhibs != NULL)
12517 xmlSchemaItemListFree(ctxt->attrProhibs);
Daniel Veillardbe9c6322003-11-22 20:37:51 +000012518 xmlDictFree(ctxt->dict);
Daniel Veillard4255d502002-04-16 15:50:10 +000012519 xmlFree(ctxt);
12520}
12521
12522/************************************************************************
12523 * *
12524 * Building the content models *
12525 * *
12526 ************************************************************************/
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012527
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000012528static void
12529xmlSchemaBuildContentModelForSubstGroup(xmlSchemaParserCtxtPtr pctxt,
Daniel Veillarda980bef2005-07-18 21:34:03 +000012530 xmlSchemaParticlePtr particle, int counter, xmlAutomataStatePtr end)
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000012531{
Daniel Veillarda980bef2005-07-18 21:34:03 +000012532 xmlAutomataStatePtr start, tmp;
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000012533 xmlSchemaElementPtr elemDecl, member;
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000012534 xmlSchemaSubstGroupPtr substGroup;
12535 int i;
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000012536
12537 elemDecl = (xmlSchemaElementPtr) particle->children;
12538 /*
12539 * Wrap the substitution group with a CHOICE.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012540 */
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000012541 start = pctxt->state;
Daniel Veillarda980bef2005-07-18 21:34:03 +000012542 if (end == NULL)
12543 end = xmlAutomataNewState(pctxt->am);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000012544 substGroup = xmlSchemaSubstGroupGet(pctxt, elemDecl);
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000012545 if (substGroup == NULL) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000012546 xmlSchemaPErr(pctxt, WXS_ITEM_NODE(particle),
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000012547 XML_SCHEMAP_INTERNAL,
12548 "Internal error: xmlSchemaBuildContentModelForSubstGroup, "
12549 "declaration is marked having a subst. group but none "
12550 "available.\n", elemDecl->name, NULL);
12551 return;
12552 }
Daniel Veillarda980bef2005-07-18 21:34:03 +000012553 if (counter >= 0) {
12554 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000012555 * NOTE that we put the declaration in, even if it's abstract.
12556 * However, an error will be raised during *validation* if an element
12557 * information item shall be validated against an abstract element
12558 * declaration.
Daniel Veillarda980bef2005-07-18 21:34:03 +000012559 */
12560 tmp = xmlAutomataNewCountedTrans(pctxt->am, start, NULL, counter);
12561 xmlAutomataNewTransition2(pctxt->am, tmp, end,
12562 elemDecl->name, elemDecl->targetNamespace, elemDecl);
12563 /*
12564 * Add subst. group members.
12565 */
12566 for (i = 0; i < substGroup->members->nbItems; i++) {
12567 member = (xmlSchemaElementPtr) substGroup->members->items[i];
12568 xmlAutomataNewTransition2(pctxt->am, tmp, end,
12569 member->name, member->targetNamespace, member);
12570 }
12571 } else if (particle->maxOccurs == 1) {
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000012572 /*
12573 * NOTE that we put the declaration in, even if it's abstract,
12574 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012575 xmlAutomataNewEpsilon(pctxt->am,
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000012576 xmlAutomataNewTransition2(pctxt->am,
12577 start, NULL,
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000012578 elemDecl->name, elemDecl->targetNamespace, elemDecl), end);
12579 /*
12580 * Add subst. group members.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012581 */
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000012582 for (i = 0; i < substGroup->members->nbItems; i++) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012583 member = (xmlSchemaElementPtr) substGroup->members->items[i];
Kasimier T. Buchcik92b394f2006-05-09 19:59:54 +000012584 /*
12585 * NOTE: This fixes bug #341150. xmlAutomataNewOnceTrans2()
12586 * was incorrectly used instead of xmlAutomataNewTransition2()
12587 * (seems like a copy&paste bug from the XML_SCHEMA_TYPE_ALL
12588 * section in xmlSchemaBuildAContentModel() ).
Daniel Veillarddee23482008-04-11 12:58:43 +000012589 * TODO: Check if xmlAutomataNewOnceTrans2() was instead
Kasimier T. Buchcik92b394f2006-05-09 19:59:54 +000012590 * intended for the above "counter" section originally. I.e.,
12591 * check xs:all with subst-groups.
12592 *
12593 * tmp = xmlAutomataNewOnceTrans2(pctxt->am, start, NULL,
12594 * member->name, member->targetNamespace,
12595 * 1, 1, member);
12596 */
12597 tmp = xmlAutomataNewTransition2(pctxt->am, start, NULL,
Daniel Veillarddee23482008-04-11 12:58:43 +000012598 member->name, member->targetNamespace, member);
Daniel Veillarda980bef2005-07-18 21:34:03 +000012599 xmlAutomataNewEpsilon(pctxt->am, tmp, end);
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000012600 }
12601 } else {
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000012602 xmlAutomataStatePtr hop;
12603 int maxOccurs = particle->maxOccurs == UNBOUNDED ?
12604 UNBOUNDED : particle->maxOccurs - 1;
12605 int minOccurs = particle->minOccurs < 1 ? 0 : particle->minOccurs - 1;
12606
12607 counter =
12608 xmlAutomataNewCounter(pctxt->am, minOccurs,
12609 maxOccurs);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012610 hop = xmlAutomataNewState(pctxt->am);
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000012611
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012612 xmlAutomataNewEpsilon(pctxt->am,
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000012613 xmlAutomataNewTransition2(pctxt->am,
12614 start, NULL,
12615 elemDecl->name, elemDecl->targetNamespace, elemDecl),
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000012616 hop);
12617 /*
Daniel Veillarda980bef2005-07-18 21:34:03 +000012618 * Add subst. group members.
12619 */
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000012620 for (i = 0; i < substGroup->members->nbItems; i++) {
12621 member = (xmlSchemaElementPtr) substGroup->members->items[i];
12622 xmlAutomataNewEpsilon(pctxt->am,
12623 xmlAutomataNewTransition2(pctxt->am,
12624 start, NULL,
12625 member->name, member->targetNamespace, member),
12626 hop);
12627 }
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000012628 xmlAutomataNewCountedTrans(pctxt->am, hop, start, counter);
12629 xmlAutomataNewCounterTrans(pctxt->am, hop, end, counter);
12630 }
12631 if (particle->minOccurs == 0)
12632 xmlAutomataNewEpsilon(pctxt->am, start, end);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012633 pctxt->state = end;
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000012634}
12635
12636static void
12637xmlSchemaBuildContentModelForElement(xmlSchemaParserCtxtPtr ctxt,
12638 xmlSchemaParticlePtr particle)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012639{
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000012640 if (((xmlSchemaElementPtr) particle->children)->flags &
12641 XML_SCHEMAS_ELEM_SUBST_GROUP_HEAD) {
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000012642 /*
12643 * Substitution groups.
12644 */
Daniel Veillarda980bef2005-07-18 21:34:03 +000012645 xmlSchemaBuildContentModelForSubstGroup(ctxt, particle, -1, NULL);
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000012646 } else {
12647 xmlSchemaElementPtr elemDecl;
12648 xmlAutomataStatePtr start;
12649
12650 elemDecl = (xmlSchemaElementPtr) particle->children;
12651
12652 if (elemDecl->flags & XML_SCHEMAS_ELEM_ABSTRACT)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012653 return;
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000012654 if (particle->maxOccurs == 1) {
12655 start = ctxt->state;
12656 ctxt->state = xmlAutomataNewTransition2(ctxt->am, start, NULL,
Daniel Veillarda980bef2005-07-18 21:34:03 +000012657 elemDecl->name, elemDecl->targetNamespace, elemDecl);
12658 } else if ((particle->maxOccurs >= UNBOUNDED) &&
12659 (particle->minOccurs < 2)) {
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000012660 /* Special case. */
Daniel Veillarddee23482008-04-11 12:58:43 +000012661 start = ctxt->state;
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000012662 ctxt->state = xmlAutomataNewTransition2(ctxt->am, start, NULL,
Daniel Veillarddee23482008-04-11 12:58:43 +000012663 elemDecl->name, elemDecl->targetNamespace, elemDecl);
Kasimier T. Buchcik7ca5aed2005-12-12 15:13:40 +000012664 ctxt->state = xmlAutomataNewTransition2(ctxt->am, ctxt->state, ctxt->state,
Daniel Veillarddee23482008-04-11 12:58:43 +000012665 elemDecl->name, elemDecl->targetNamespace, elemDecl);
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000012666 } else {
12667 int counter;
12668 int maxOccurs = particle->maxOccurs == UNBOUNDED ?
12669 UNBOUNDED : particle->maxOccurs - 1;
12670 int minOccurs = particle->minOccurs < 1 ?
12671 0 : particle->minOccurs - 1;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012672
12673 start = xmlAutomataNewEpsilon(ctxt->am, ctxt->state, NULL);
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000012674 counter = xmlAutomataNewCounter(ctxt->am, minOccurs, maxOccurs);
12675 ctxt->state = xmlAutomataNewTransition2(ctxt->am, start, NULL,
12676 elemDecl->name, elemDecl->targetNamespace, elemDecl);
12677 xmlAutomataNewCountedTrans(ctxt->am, ctxt->state, start, counter);
12678 ctxt->state = xmlAutomataNewCounterTrans(ctxt->am, ctxt->state,
12679 NULL, counter);
12680 }
12681 if (particle->minOccurs == 0)
12682 xmlAutomataNewEpsilon(ctxt->am, start, ctxt->state);
12683 }
12684}
12685
Daniel Veillard4255d502002-04-16 15:50:10 +000012686/**
12687 * xmlSchemaBuildAContentModel:
Daniel Veillard4255d502002-04-16 15:50:10 +000012688 * @ctxt: the schema parser context
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012689 * @particle: the particle component
12690 * @name: the complex type's name whose content is being built
Daniel Veillard4255d502002-04-16 15:50:10 +000012691 *
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000012692 * Create the automaton for the {content type} of a complex type.
12693 *
Daniel Veillard4255d502002-04-16 15:50:10 +000012694 */
12695static void
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012696xmlSchemaBuildAContentModel(xmlSchemaParserCtxtPtr pctxt,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000012697 xmlSchemaParticlePtr particle)
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012698{
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012699 if (particle == NULL) {
Daniel Veillarddee23482008-04-11 12:58:43 +000012700 PERROR_INT("xmlSchemaBuildAContentModel", "particle is NULL");
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012701 return;
Daniel Veillard4255d502002-04-16 15:50:10 +000012702 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012703 if (particle->children == NULL) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000012704 /*
12705 * Just return in this case. A missing "term" of the particle
12706 * might arise due to an invalid "term" component.
12707 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012708 return;
12709 }
12710
12711 switch (particle->children->type) {
12712 case XML_SCHEMA_TYPE_ANY: {
Daniel Veillardc0826a72004-08-10 14:17:33 +000012713 xmlAutomataStatePtr start, end;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012714 xmlSchemaWildcardPtr wild;
Daniel Veillardc0826a72004-08-10 14:17:33 +000012715 xmlSchemaWildcardNsPtr ns;
Daniel Veillard32370232002-10-16 14:08:14 +000012716
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012717 wild = (xmlSchemaWildcardPtr) particle->children;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012718
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012719 start = pctxt->state;
12720 end = xmlAutomataNewState(pctxt->am);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012721
12722 if (particle->maxOccurs == 1) {
Daniel Veillardc0826a72004-08-10 14:17:33 +000012723 if (wild->any == 1) {
12724 /*
12725 * We need to add both transitions:
12726 *
12727 * 1. the {"*", "*"} for elements in a namespace.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012728 */
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012729 pctxt->state =
12730 xmlAutomataNewTransition2(pctxt->am,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012731 start, NULL, BAD_CAST "*", BAD_CAST "*", wild);
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012732 xmlAutomataNewEpsilon(pctxt->am, pctxt->state, end);
Daniel Veillardc0826a72004-08-10 14:17:33 +000012733 /*
12734 * 2. the {"*"} for elements in no namespace.
12735 */
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012736 pctxt->state =
12737 xmlAutomataNewTransition2(pctxt->am,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012738 start, NULL, BAD_CAST "*", NULL, wild);
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012739 xmlAutomataNewEpsilon(pctxt->am, pctxt->state, end);
Daniel Veillardc0826a72004-08-10 14:17:33 +000012740
12741 } else if (wild->nsSet != NULL) {
12742 ns = wild->nsSet;
12743 do {
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012744 pctxt->state = start;
12745 pctxt->state = xmlAutomataNewTransition2(pctxt->am,
12746 pctxt->state, NULL, BAD_CAST "*", ns->value, wild);
12747 xmlAutomataNewEpsilon(pctxt->am, pctxt->state, end);
Daniel Veillardc0826a72004-08-10 14:17:33 +000012748 ns = ns->next;
12749 } while (ns != NULL);
12750
12751 } else if (wild->negNsSet != NULL) {
Daniel Veillard6e65e152005-08-09 11:09:52 +000012752 pctxt->state = xmlAutomataNewNegTrans(pctxt->am,
12753 start, end, BAD_CAST "*", wild->negNsSet->value,
12754 wild);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012755 }
Daniel Veillardc0826a72004-08-10 14:17:33 +000012756 } else {
12757 int counter;
12758 xmlAutomataStatePtr hop;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012759 int maxOccurs =
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012760 particle->maxOccurs == UNBOUNDED ? UNBOUNDED : particle->maxOccurs - 1;
Daniel Veillardc0826a72004-08-10 14:17:33 +000012761 int minOccurs =
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012762 particle->minOccurs < 1 ? 0 : particle->minOccurs - 1;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012763
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012764 counter = xmlAutomataNewCounter(pctxt->am, minOccurs, maxOccurs);
12765 hop = xmlAutomataNewState(pctxt->am);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012766 if (wild->any == 1) {
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012767 pctxt->state =
12768 xmlAutomataNewTransition2(pctxt->am,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012769 start, NULL, BAD_CAST "*", BAD_CAST "*", wild);
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012770 xmlAutomataNewEpsilon(pctxt->am, pctxt->state, hop);
12771 pctxt->state =
12772 xmlAutomataNewTransition2(pctxt->am,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012773 start, NULL, BAD_CAST "*", NULL, wild);
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012774 xmlAutomataNewEpsilon(pctxt->am, pctxt->state, hop);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012775 } else if (wild->nsSet != NULL) {
Daniel Veillardc0826a72004-08-10 14:17:33 +000012776 ns = wild->nsSet;
12777 do {
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012778 pctxt->state =
12779 xmlAutomataNewTransition2(pctxt->am,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012780 start, NULL, BAD_CAST "*", ns->value, wild);
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012781 xmlAutomataNewEpsilon(pctxt->am, pctxt->state, hop);
Daniel Veillardc0826a72004-08-10 14:17:33 +000012782 ns = ns->next;
12783 } while (ns != NULL);
12784
12785 } else if (wild->negNsSet != NULL) {
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012786 pctxt->state = xmlAutomataNewNegTrans(pctxt->am,
Daniel Veillard9efc4762005-07-19 14:33:55 +000012787 start, hop, BAD_CAST "*", wild->negNsSet->value,
12788 wild);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012789 }
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012790 xmlAutomataNewCountedTrans(pctxt->am, hop, start, counter);
12791 xmlAutomataNewCounterTrans(pctxt->am, hop, end, counter);
Daniel Veillardc0826a72004-08-10 14:17:33 +000012792 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012793 if (particle->minOccurs == 0) {
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012794 xmlAutomataNewEpsilon(pctxt->am, start, end);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012795 }
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012796 pctxt->state = end;
Daniel Veillardc0826a72004-08-10 14:17:33 +000012797 break;
12798 }
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000012799 case XML_SCHEMA_TYPE_ELEMENT:
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012800 xmlSchemaBuildContentModelForElement(pctxt, particle);
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000012801 break;
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012802 case XML_SCHEMA_TYPE_SEQUENCE:{
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012803 xmlSchemaTreeItemPtr sub;
Daniel Veillardb39bc392002-10-26 19:29:51 +000012804
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012805 /*
12806 * If max and min occurances are default (1) then
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012807 * simply iterate over the particles of the <sequence>.
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012808 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012809 if ((particle->minOccurs == 1) && (particle->maxOccurs == 1)) {
12810 sub = particle->children->children;
12811 while (sub != NULL) {
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012812 xmlSchemaBuildAContentModel(pctxt,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000012813 (xmlSchemaParticlePtr) sub);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012814 sub = sub->next;
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012815 }
12816 } else {
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012817 xmlAutomataStatePtr oldstate = pctxt->state;
Daniel Veillardb39bc392002-10-26 19:29:51 +000012818
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012819 if (particle->maxOccurs >= UNBOUNDED) {
12820 if (particle->minOccurs > 1) {
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012821 xmlAutomataStatePtr tmp;
12822 int counter;
Daniel Veillardb39bc392002-10-26 19:29:51 +000012823
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012824 pctxt->state = xmlAutomataNewEpsilon(pctxt->am,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012825 oldstate, NULL);
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012826 oldstate = pctxt->state;
Daniel Veillardb39bc392002-10-26 19:29:51 +000012827
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012828 counter = xmlAutomataNewCounter(pctxt->am,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012829 particle->minOccurs - 1, UNBOUNDED);
Daniel Veillardb39bc392002-10-26 19:29:51 +000012830
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012831 sub = particle->children->children;
12832 while (sub != NULL) {
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012833 xmlSchemaBuildAContentModel(pctxt,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000012834 (xmlSchemaParticlePtr) sub);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012835 sub = sub->next;
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012836 }
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012837 tmp = pctxt->state;
12838 xmlAutomataNewCountedTrans(pctxt->am, tmp,
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012839 oldstate, counter);
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012840 pctxt->state =
12841 xmlAutomataNewCounterTrans(pctxt->am, tmp,
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012842 NULL, counter);
Daniel Veillardb39bc392002-10-26 19:29:51 +000012843
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012844 } else {
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012845 pctxt->state = xmlAutomataNewEpsilon(pctxt->am,
Daniel Veillardafc05b62005-07-17 06:11:19 +000012846 oldstate, NULL);
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012847 oldstate = pctxt->state;
Daniel Veillardafc05b62005-07-17 06:11:19 +000012848
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012849 sub = particle->children->children;
12850 while (sub != NULL) {
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012851 xmlSchemaBuildAContentModel(pctxt,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000012852 (xmlSchemaParticlePtr) sub);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012853 sub = sub->next;
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012854 }
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012855 xmlAutomataNewEpsilon(pctxt->am, pctxt->state,
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012856 oldstate);
Daniel Veillardafc05b62005-07-17 06:11:19 +000012857 /*
12858 * epsilon needed to block previous trans from
12859 * being allowed to enter back from another
12860 * construct
12861 */
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012862 pctxt->state = xmlAutomataNewEpsilon(pctxt->am,
12863 pctxt->state, NULL);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012864 if (particle->minOccurs == 0) {
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012865 xmlAutomataNewEpsilon(pctxt->am,
12866 oldstate, pctxt->state);
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012867 }
12868 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012869 } else if ((particle->maxOccurs > 1)
12870 || (particle->minOccurs > 1)) {
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012871 xmlAutomataStatePtr tmp;
12872 int counter;
Daniel Veillardb39bc392002-10-26 19:29:51 +000012873
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012874 pctxt->state = xmlAutomataNewEpsilon(pctxt->am,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012875 oldstate, NULL);
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012876 oldstate = pctxt->state;
Daniel Veillard4255d502002-04-16 15:50:10 +000012877
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012878 counter = xmlAutomataNewCounter(pctxt->am,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012879 particle->minOccurs - 1,
12880 particle->maxOccurs - 1);
Daniel Veillard4255d502002-04-16 15:50:10 +000012881
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012882 sub = particle->children->children;
12883 while (sub != NULL) {
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012884 xmlSchemaBuildAContentModel(pctxt,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000012885 (xmlSchemaParticlePtr) sub);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012886 sub = sub->next;
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012887 }
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012888 tmp = pctxt->state;
12889 xmlAutomataNewCountedTrans(pctxt->am,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012890 tmp, oldstate, counter);
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012891 pctxt->state =
12892 xmlAutomataNewCounterTrans(pctxt->am, tmp, NULL,
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012893 counter);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012894 if (particle->minOccurs == 0) {
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012895 xmlAutomataNewEpsilon(pctxt->am,
12896 oldstate, pctxt->state);
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012897 }
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012898 } else {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012899 sub = particle->children->children;
12900 while (sub != NULL) {
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012901 xmlSchemaBuildAContentModel(pctxt,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000012902 (xmlSchemaParticlePtr) sub);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012903 sub = sub->next;
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012904 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012905 if (particle->minOccurs == 0) {
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012906 xmlAutomataNewEpsilon(pctxt->am, oldstate,
12907 pctxt->state);
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012908 }
12909 }
12910 }
12911 break;
12912 }
12913 case XML_SCHEMA_TYPE_CHOICE:{
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012914 xmlSchemaTreeItemPtr sub;
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012915 xmlAutomataStatePtr start, end;
Daniel Veillardb509f152002-04-17 16:28:10 +000012916
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012917 start = pctxt->state;
12918 end = xmlAutomataNewState(pctxt->am);
Daniel Veillard7646b182002-04-20 06:41:40 +000012919
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012920 /*
12921 * iterate over the subtypes and remerge the end with an
12922 * epsilon transition
12923 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012924 if (particle->maxOccurs == 1) {
12925 sub = particle->children->children;
12926 while (sub != NULL) {
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012927 pctxt->state = start;
12928 xmlSchemaBuildAContentModel(pctxt,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000012929 (xmlSchemaParticlePtr) sub);
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012930 xmlAutomataNewEpsilon(pctxt->am, pctxt->state, end);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012931 sub = sub->next;
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012932 }
12933 } else {
12934 int counter;
Daniel Veillardafc05b62005-07-17 06:11:19 +000012935 xmlAutomataStatePtr hop, base;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012936 int maxOccurs = particle->maxOccurs == UNBOUNDED ?
12937 UNBOUNDED : particle->maxOccurs - 1;
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012938 int minOccurs =
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012939 particle->minOccurs < 1 ? 0 : particle->minOccurs - 1;
Daniel Veillard7646b182002-04-20 06:41:40 +000012940
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012941 /*
12942 * use a counter to keep track of the number of transtions
12943 * which went through the choice.
12944 */
12945 counter =
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012946 xmlAutomataNewCounter(pctxt->am, minOccurs, maxOccurs);
12947 hop = xmlAutomataNewState(pctxt->am);
12948 base = xmlAutomataNewState(pctxt->am);
Daniel Veillard6231e842002-04-18 11:54:04 +000012949
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012950 sub = particle->children->children;
12951 while (sub != NULL) {
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012952 pctxt->state = base;
12953 xmlSchemaBuildAContentModel(pctxt,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000012954 (xmlSchemaParticlePtr) sub);
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012955 xmlAutomataNewEpsilon(pctxt->am, pctxt->state, hop);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012956 sub = sub->next;
Daniel Veillarda980bef2005-07-18 21:34:03 +000012957 }
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012958 xmlAutomataNewEpsilon(pctxt->am, start, base);
12959 xmlAutomataNewCountedTrans(pctxt->am, hop, base, counter);
12960 xmlAutomataNewCounterTrans(pctxt->am, hop, end, counter);
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012961 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012962 if (particle->minOccurs == 0) {
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012963 xmlAutomataNewEpsilon(pctxt->am, start, end);
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012964 }
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012965 pctxt->state = end;
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012966 break;
12967 }
12968 case XML_SCHEMA_TYPE_ALL:{
Kasimier T. Buchcik2c9aac02005-07-21 22:14:12 +000012969 xmlAutomataStatePtr start;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012970 xmlSchemaParticlePtr sub;
12971 xmlSchemaElementPtr elemDecl;
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012972 int lax;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012973
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012974 sub = (xmlSchemaParticlePtr) particle->children->children;
12975 if (sub == NULL)
Daniel Veillardd0c9c322003-10-10 00:49:42 +000012976 break;
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012977 start = pctxt->state;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012978 while (sub != NULL) {
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012979 pctxt->state = start;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012980
12981 elemDecl = (xmlSchemaElementPtr) sub->children;
12982 if (elemDecl == NULL) {
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000012983 PERROR_INT("xmlSchemaBuildAContentModel",
12984 "<element> particle has no term");
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000012985 return;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012986 };
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000012987 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012988 * NOTE: The {max occurs} of all the particles in the
Kasimier T. Buchcikff858ca2005-02-18 11:37:58 +000012989 * {particles} of the group must be 0 or 1; this is
12990 * already ensured during the parse of the content of
12991 * <all>.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012992 */
Daniel Veillarda980bef2005-07-18 21:34:03 +000012993 if (elemDecl->flags & XML_SCHEMAS_ELEM_SUBST_GROUP_HEAD) {
12994 int counter;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000012995
Daniel Veillarda980bef2005-07-18 21:34:03 +000012996 /*
12997 * This is an abstract group, we need to share
12998 * the same counter for all the element transitions
12999 * derived from the group
13000 */
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000013001 counter = xmlAutomataNewCounter(pctxt->am,
Daniel Veillarda980bef2005-07-18 21:34:03 +000013002 sub->minOccurs, sub->maxOccurs);
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000013003 xmlSchemaBuildContentModelForSubstGroup(pctxt,
13004 sub, counter, pctxt->state);
Daniel Veillarda980bef2005-07-18 21:34:03 +000013005 } else {
13006 if ((sub->minOccurs == 1) &&
13007 (sub->maxOccurs == 1)) {
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000013008 xmlAutomataNewOnceTrans2(pctxt->am, pctxt->state,
13009 pctxt->state,
Daniel Veillarda980bef2005-07-18 21:34:03 +000013010 elemDecl->name,
13011 elemDecl->targetNamespace,
13012 1, 1, elemDecl);
13013 } else if ((sub->minOccurs == 0) &&
13014 (sub->maxOccurs == 1)) {
13015
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000013016 xmlAutomataNewCountTrans2(pctxt->am, pctxt->state,
13017 pctxt->state,
Daniel Veillarda980bef2005-07-18 21:34:03 +000013018 elemDecl->name,
13019 elemDecl->targetNamespace,
13020 0,
13021 1,
13022 elemDecl);
13023 }
13024 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000013025 sub = (xmlSchemaParticlePtr) sub->next;
Daniel Veillardd0c9c322003-10-10 00:49:42 +000013026 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000013027 lax = particle->minOccurs == 0;
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000013028 pctxt->state =
13029 xmlAutomataNewAllTrans(pctxt->am, pctxt->state, NULL, lax);
Daniel Veillardd0c9c322003-10-10 00:49:42 +000013030 break;
13031 }
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000013032 case XML_SCHEMA_TYPE_GROUP:
13033 /*
13034 * If we hit a model group definition, then this means that
13035 * it was empty, thus was not substituted for the containing
13036 * model group. Just do nothing in this case.
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000013037 * TODO: But the group should be substituted and not occur at
13038 * all in the content model at this point. Fix this.
Kasimier T. Buchcik041c5ff2005-07-23 14:42:34 +000013039 */
13040 break;
Daniel Veillardd0c9c322003-10-10 00:49:42 +000013041 default:
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000013042 xmlSchemaInternalErr2(ACTXT_CAST pctxt,
13043 "xmlSchemaBuildAContentModel",
13044 "found unexpected term of type '%s' in content model",
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013045 WXS_ITEM_TYPE_NAME(particle->children), NULL);
Daniel Veillardd0c9c322003-10-10 00:49:42 +000013046 return;
Daniel Veillard4255d502002-04-16 15:50:10 +000013047 }
13048}
Daniel Veillardd0c9c322003-10-10 00:49:42 +000013049
Daniel Veillard4255d502002-04-16 15:50:10 +000013050/**
13051 * xmlSchemaBuildContentModel:
Daniel Veillard4255d502002-04-16 15:50:10 +000013052 * @ctxt: the schema parser context
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013053 * @type: the complex type definition
Daniel Veillarda84c0b32003-06-02 16:58:46 +000013054 * @name: the element name
Daniel Veillard4255d502002-04-16 15:50:10 +000013055 *
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000013056 * Builds the content model of the complex type.
Daniel Veillard4255d502002-04-16 15:50:10 +000013057 */
13058static void
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000013059xmlSchemaBuildContentModel(xmlSchemaTypePtr type,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000013060 xmlSchemaParserCtxtPtr ctxt)
Daniel Veillardd0c9c322003-10-10 00:49:42 +000013061{
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000013062 if ((type->type != XML_SCHEMA_TYPE_COMPLEX) ||
13063 (type->contModel != NULL) ||
13064 ((type->contentType != XML_SCHEMA_CONTENT_ELEMENTS) &&
13065 (type->contentType != XML_SCHEMA_CONTENT_MIXED)))
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000013066 return;
Daniel Veillarddecd64d2002-04-18 14:41:51 +000013067
13068#ifdef DEBUG_CONTENT
13069 xmlGenericError(xmlGenericErrorContext,
Daniel Veillardd0c9c322003-10-10 00:49:42 +000013070 "Building content model for %s\n", name);
Daniel Veillarddecd64d2002-04-18 14:41:51 +000013071#endif
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013072 ctxt->am = NULL;
Daniel Veillard4255d502002-04-16 15:50:10 +000013073 ctxt->am = xmlNewAutomata();
13074 if (ctxt->am == NULL) {
Daniel Veillardd0c9c322003-10-10 00:49:42 +000013075 xmlGenericError(xmlGenericErrorContext,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000013076 "Cannot create automata for complex type %s\n", type->name);
Daniel Veillardd0c9c322003-10-10 00:49:42 +000013077 return;
Daniel Veillard4255d502002-04-16 15:50:10 +000013078 }
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000013079 ctxt->state = xmlAutomataGetInitState(ctxt->am);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013080 /*
13081 * Build the automaton.
13082 */
13083 xmlSchemaBuildAContentModel(ctxt, WXS_TYPE_PARTICLE(type));
Daniel Veillard4255d502002-04-16 15:50:10 +000013084 xmlAutomataSetFinalState(ctxt->am, ctxt->state);
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000013085 type->contModel = xmlAutomataCompile(ctxt->am);
13086 if (type->contModel == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013087 xmlSchemaPCustomErr(ctxt,
13088 XML_SCHEMAP_INTERNAL,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013089 WXS_BASIC_CAST type, type->node,
Daniel Veillardc0826a72004-08-10 14:17:33 +000013090 "Failed to compile the content model", NULL);
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000013091 } else if (xmlRegexpIsDeterminist(type->contModel) != 1) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013092 xmlSchemaPCustomErr(ctxt,
Kasimier T. Buchcikbea23542004-08-25 20:35:45 +000013093 XML_SCHEMAP_NOT_DETERMINISTIC,
13094 /* XML_SCHEMAS_ERR_NOTDETERMINIST, */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013095 WXS_BASIC_CAST type, type->node,
Daniel Veillardc0826a72004-08-10 14:17:33 +000013096 "The content model is not determinist", NULL);
Daniel Veillarde19fc232002-04-22 16:01:24 +000013097 } else {
Daniel Veillard118aed72002-09-24 14:13:13 +000013098#ifdef DEBUG_CONTENT_REGEXP
Daniel Veillardd0c9c322003-10-10 00:49:42 +000013099 xmlGenericError(xmlGenericErrorContext,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000013100 "Content model of %s:\n", type->name);
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000013101 xmlRegexpPrint(stderr, type->contModel);
Daniel Veillard4255d502002-04-16 15:50:10 +000013102#endif
Daniel Veillarde19fc232002-04-22 16:01:24 +000013103 }
Daniel Veillarda84c0b32003-06-02 16:58:46 +000013104 ctxt->state = NULL;
Daniel Veillard4255d502002-04-16 15:50:10 +000013105 xmlFreeAutomata(ctxt->am);
13106 ctxt->am = NULL;
13107}
13108
13109/**
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000013110 * xmlSchemaResolveElementReferences:
Daniel Veillard4255d502002-04-16 15:50:10 +000013111 * @elem: the schema element context
13112 * @ctxt: the schema parser context
13113 *
Daniel Veillardc0826a72004-08-10 14:17:33 +000013114 * Resolves the references of an element declaration
13115 * or particle, which has an element declaration as it's
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013116 * term.
Daniel Veillard4255d502002-04-16 15:50:10 +000013117 */
13118static void
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000013119xmlSchemaResolveElementReferences(xmlSchemaElementPtr elemDecl,
13120 xmlSchemaParserCtxtPtr ctxt)
Daniel Veillard4255d502002-04-16 15:50:10 +000013121{
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013122 if ((ctxt == NULL) || (elemDecl == NULL) ||
13123 ((elemDecl != NULL) &&
13124 (elemDecl->flags & XML_SCHEMAS_ELEM_INTERNAL_RESOLVED)))
Daniel Veillardd0c9c322003-10-10 00:49:42 +000013125 return;
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000013126 elemDecl->flags |= XML_SCHEMAS_ELEM_INTERNAL_RESOLVED;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013127
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000013128 if ((elemDecl->subtypes == NULL) && (elemDecl->namedType != NULL)) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000013129 xmlSchemaTypePtr type;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013130
Rob Richardsc6947bb2008-06-29 15:04:41 +000013131 /* (type definition) ... otherwise the type definition �resolved�
13132 * to by the �actual value� of the type [attribute] ...
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013133 */
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000013134 type = xmlSchemaGetType(ctxt->schema, elemDecl->namedType,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013135 elemDecl->namedTypeNs);
13136 if (type == NULL) {
Daniel Veillardc0826a72004-08-10 14:17:33 +000013137 xmlSchemaPResCompAttrErr(ctxt,
Daniel Veillard01fa6152004-06-29 17:04:39 +000013138 XML_SCHEMAP_SRC_RESOLVE,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013139 WXS_BASIC_CAST elemDecl, elemDecl->node,
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000013140 "type", elemDecl->namedType, elemDecl->namedTypeNs,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000013141 XML_SCHEMA_TYPE_BASIC, "type definition");
13142 } else
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000013143 elemDecl->subtypes = type;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000013144 }
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000013145 if (elemDecl->substGroup != NULL) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000013146 xmlSchemaElementPtr substHead;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013147
Daniel Veillardc0826a72004-08-10 14:17:33 +000013148 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013149 * FIXME TODO: Do we need a new field in _xmlSchemaElement for
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000013150 * substitutionGroup?
Daniel Veillard01fa6152004-06-29 17:04:39 +000013151 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013152 substHead = xmlSchemaGetElem(ctxt->schema, elemDecl->substGroup,
13153 elemDecl->substGroupNs);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000013154 if (substHead == NULL) {
13155 xmlSchemaPResCompAttrErr(ctxt,
Daniel Veillardc0826a72004-08-10 14:17:33 +000013156 XML_SCHEMAP_SRC_RESOLVE,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013157 WXS_BASIC_CAST elemDecl, NULL,
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000013158 "substitutionGroup", elemDecl->substGroup,
13159 elemDecl->substGroupNs, XML_SCHEMA_TYPE_ELEMENT, NULL);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000013160 } else {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000013161 xmlSchemaResolveElementReferences(substHead, ctxt);
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000013162 /*
13163 * Set the "substitution group affiliation".
13164 * NOTE that now we use the "refDecl" field for this.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013165 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013166 WXS_SUBST_HEAD(elemDecl) = substHead;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000013167 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000013168 * The type definitions is set to:
13169 * SPEC "...the {type definition} of the element
Rob Richardsc6947bb2008-06-29 15:04:41 +000013170 * declaration �resolved� to by the �actual value�
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000013171 * of the substitutionGroup [attribute], if present"
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000013172 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013173 if (elemDecl->subtypes == NULL)
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000013174 elemDecl->subtypes = substHead->subtypes;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000013175 }
13176 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000013177 /*
13178 * SPEC "The definition of anyType serves as the default type definition
13179 * for element declarations whose XML representation does not specify one."
13180 */
13181 if ((elemDecl->subtypes == NULL) &&
13182 (elemDecl->namedType == NULL) &&
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000013183 (elemDecl->substGroup == NULL))
13184 elemDecl->subtypes = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE);
William M. Bracke7091952004-05-11 15:09:58 +000013185}
13186
13187/**
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000013188 * xmlSchemaResolveUnionMemberTypes:
William M. Bracke7091952004-05-11 15:09:58 +000013189 * @ctxt: the schema parser context
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000013190 * @type: the schema simple type definition
William M. Bracke7091952004-05-11 15:09:58 +000013191 *
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000013192 * Checks and builds the "member type definitions" property of the union
13193 * simple type. This handles part (1), part (2) is done in
13194 * xmlSchemaFinishMemberTypeDefinitionsProperty()
13195 *
Daniel Veillard01fa6152004-06-29 17:04:39 +000013196 * Returns -1 in case of an internal error, 0 otherwise.
William M. Bracke7091952004-05-11 15:09:58 +000013197 */
Daniel Veillard01fa6152004-06-29 17:04:39 +000013198static int
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000013199xmlSchemaResolveUnionMemberTypes(xmlSchemaParserCtxtPtr ctxt,
13200 xmlSchemaTypePtr type)
Daniel Veillard377e1a92004-04-16 16:30:05 +000013201{
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013202
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000013203 xmlSchemaTypeLinkPtr link, lastLink, newLink;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000013204 xmlSchemaTypePtr memberType;
Daniel Veillard377e1a92004-04-16 16:30:05 +000013205
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013206 /*
13207 * SPEC (1) "If the <union> alternative is chosen, then [Definition:]
Rob Richardsc6947bb2008-06-29 15:04:41 +000013208 * define the explicit members as the type definitions �resolved�
13209 * to by the items in the �actual value� of the memberTypes [attribute],
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013210 * if any, followed by the type definitions corresponding to the
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000013211 * <simpleType>s among the [children] of <union>, if any."
Daniel Veillard01fa6152004-06-29 17:04:39 +000013212 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000013213 /*
13214 * Resolve references.
13215 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013216 link = type->memberTypes;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000013217 lastLink = NULL;
13218 while (link != NULL) {
13219 const xmlChar *name, *nsName;
Daniel Veillardc0826a72004-08-10 14:17:33 +000013220
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000013221 name = ((xmlSchemaQNameRefPtr) link->type)->name;
13222 nsName = ((xmlSchemaQNameRefPtr) link->type)->targetNamespace;
13223
13224 memberType = xmlSchemaGetType(ctxt->schema, name, nsName);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013225 if ((memberType == NULL) || (! WXS_IS_SIMPLE(memberType))) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000013226 xmlSchemaPResCompAttrErr(ctxt, XML_SCHEMAP_SRC_RESOLVE,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013227 WXS_BASIC_CAST type, type->node, "memberTypes",
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000013228 name, nsName, XML_SCHEMA_TYPE_SIMPLE, NULL);
13229 /*
13230 * Remove the member type link.
13231 */
13232 if (lastLink == NULL)
13233 type->memberTypes = link->next;
13234 else
13235 lastLink->next = link->next;
13236 newLink = link;
13237 link = link->next;
13238 xmlFree(newLink);
13239 } else {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013240 link->type = memberType;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000013241 lastLink = link;
13242 link = link->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013243 }
13244 }
Daniel Veillard01fa6152004-06-29 17:04:39 +000013245 /*
13246 * Add local simple types,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013247 */
Daniel Veillard01fa6152004-06-29 17:04:39 +000013248 memberType = type->subtypes;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013249 while (memberType != NULL) {
Daniel Veillard01fa6152004-06-29 17:04:39 +000013250 link = (xmlSchemaTypeLinkPtr) xmlMalloc(sizeof(xmlSchemaTypeLink));
13251 if (link == NULL) {
13252 xmlSchemaPErrMemory(ctxt, "allocating a type link", NULL);
13253 return (-1);
13254 }
13255 link->type = memberType;
13256 link->next = NULL;
13257 if (lastLink == NULL)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013258 type->memberTypes = link;
13259 else
Daniel Veillard01fa6152004-06-29 17:04:39 +000013260 lastLink->next = link;
13261 lastLink = link;
13262 memberType = memberType->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013263 }
Daniel Veillard01fa6152004-06-29 17:04:39 +000013264 return (0);
Daniel Veillard377e1a92004-04-16 16:30:05 +000013265}
13266
Daniel Veillard4255d502002-04-16 15:50:10 +000013267/**
Daniel Veillard3646d642004-06-02 19:19:14 +000013268 * xmlSchemaIsDerivedFromBuiltInType:
13269 * @ctxt: the schema parser context
13270 * @type: the type definition
13271 * @valType: the value type
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013272 *
Daniel Veillard3646d642004-06-02 19:19:14 +000013273 *
13274 * Returns 1 if the type has the given value type, or
13275 * is derived from such a type.
13276 */
William M. Brack803812b2004-06-03 02:11:24 +000013277static int
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013278xmlSchemaIsDerivedFromBuiltInType(xmlSchemaTypePtr type, int valType)
Daniel Veillard3646d642004-06-02 19:19:14 +000013279{
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013280 if (type == NULL)
13281 return (0);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013282 if (WXS_IS_COMPLEX(type))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013283 return (0);
13284 if (type->type == XML_SCHEMA_TYPE_BASIC) {
13285 if (type->builtInType == valType)
13286 return(1);
13287 if ((type->builtInType == XML_SCHEMAS_ANYSIMPLETYPE) ||
13288 (type->builtInType == XML_SCHEMAS_ANYTYPE))
13289 return (0);
13290 return(xmlSchemaIsDerivedFromBuiltInType(type->subtypes, valType));
Daniel Veillard6a0baa02005-12-10 11:11:12 +000013291 }
13292 return(xmlSchemaIsDerivedFromBuiltInType(type->subtypes, valType));
Daniel Veillard3646d642004-06-02 19:19:14 +000013293}
13294
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013295#if 0
13296/**
13297 * xmlSchemaIsDerivedFromBuiltInType:
13298 * @ctxt: the schema parser context
13299 * @type: the type definition
13300 * @valType: the value type
13301 *
13302 *
13303 * Returns 1 if the type has the given value type, or
13304 * is derived from such a type.
13305 */
13306static int
13307xmlSchemaIsUserDerivedFromBuiltInType(xmlSchemaTypePtr type, int valType)
13308{
13309 if (type == NULL)
13310 return (0);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013311 if (WXS_IS_COMPLEX(type))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013312 return (0);
13313 if (type->type == XML_SCHEMA_TYPE_BASIC) {
13314 if (type->builtInType == valType)
13315 return(1);
13316 return (0);
13317 } else
13318 return(xmlSchemaIsDerivedFromBuiltInType(type->subtypes, valType));
13319
13320 return (0);
13321}
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013322
13323static xmlSchemaTypePtr
13324xmlSchemaQueryBuiltInType(xmlSchemaTypePtr type)
13325{
13326 if (type == NULL)
13327 return (NULL);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013328 if (WXS_IS_COMPLEX(type))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013329 return (NULL);
13330 if (type->type == XML_SCHEMA_TYPE_BASIC)
Daniel Veillard6a0baa02005-12-10 11:11:12 +000013331 return(type);
13332 return(xmlSchemaQueryBuiltInType(type->subtypes));
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013333}
Daniel Veillard15724252008-08-30 15:01:04 +000013334#endif
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013335
Daniel Veillard3646d642004-06-02 19:19:14 +000013336/**
Kasimier T. Buchcik6e224f12005-02-17 11:10:44 +000013337 * xmlSchemaGetPrimitiveType:
Daniel Veillard01fa6152004-06-29 17:04:39 +000013338 * @type: the simpleType definition
13339 *
13340 * Returns the primitive type of the given type or
13341 * NULL in case of error.
13342 */
13343static xmlSchemaTypePtr
13344xmlSchemaGetPrimitiveType(xmlSchemaTypePtr type)
13345{
Kasimier T. Buchcik9b77aa02005-03-04 22:04:16 +000013346
Daniel Veillard01fa6152004-06-29 17:04:39 +000013347 while (type != NULL) {
Kasimier T. Buchcik9b77aa02005-03-04 22:04:16 +000013348 /*
13349 * Note that anySimpleType is actually not a primitive type
13350 * but we need that here.
13351 */
13352 if ((type->builtInType == XML_SCHEMAS_ANYSIMPLETYPE) ||
13353 (type->flags & XML_SCHEMAS_TYPE_BUILTIN_PRIMITIVE))
Daniel Veillard01fa6152004-06-29 17:04:39 +000013354 return (type);
13355 type = type->baseType;
13356 }
13357
13358 return (NULL);
13359}
13360
Kasimier T. Buchcik9b77aa02005-03-04 22:04:16 +000013361#if 0
Kasimier T. Buchcik6e224f12005-02-17 11:10:44 +000013362/**
13363 * xmlSchemaGetBuiltInTypeAncestor:
13364 * @type: the simpleType definition
13365 *
13366 * Returns the primitive type of the given type or
13367 * NULL in case of error.
13368 */
13369static xmlSchemaTypePtr
13370xmlSchemaGetBuiltInTypeAncestor(xmlSchemaTypePtr type)
13371{
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013372 if (WXS_IS_LIST(type) || WXS_IS_UNION(type))
Kasimier T. Buchcik478d6932005-03-16 16:29:18 +000013373 return (0);
Kasimier T. Buchcik6e224f12005-02-17 11:10:44 +000013374 while (type != NULL) {
13375 if (type->type == XML_SCHEMA_TYPE_BASIC)
13376 return (type);
13377 type = type->baseType;
13378 }
13379
13380 return (NULL);
13381}
Kasimier T. Buchcik9b77aa02005-03-04 22:04:16 +000013382#endif
Kasimier T. Buchcik6e224f12005-02-17 11:10:44 +000013383
Daniel Veillard01fa6152004-06-29 17:04:39 +000013384/**
Daniel Veillard50355f02004-06-08 17:52:16 +000013385 * xmlSchemaCloneWildcardNsConstraints:
13386 * @ctxt: the schema parser context
13387 * @dest: the destination wildcard
13388 * @source: the source wildcard
13389 *
13390 * Clones the namespace constraints of source
13391 * and assignes them to dest.
13392 * Returns -1 on internal error, 0 otherwise.
13393 */
Daniel Veillard3646d642004-06-02 19:19:14 +000013394static int
13395xmlSchemaCloneWildcardNsConstraints(xmlSchemaParserCtxtPtr ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013396 xmlSchemaWildcardPtr dest,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013397 xmlSchemaWildcardPtr source)
Daniel Veillard3646d642004-06-02 19:19:14 +000013398{
13399 xmlSchemaWildcardNsPtr cur, tmp, last;
13400
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013401 if ((source == NULL) || (dest == NULL))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013402 return(-1);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013403 dest->any = source->any;
Daniel Veillard3646d642004-06-02 19:19:14 +000013404 cur = source->nsSet;
13405 last = NULL;
13406 while (cur != NULL) {
13407 tmp = xmlSchemaNewWildcardNsConstraint(ctxt);
13408 if (tmp == NULL)
13409 return(-1);
13410 tmp->value = cur->value;
13411 if (last == NULL)
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013412 dest->nsSet = tmp;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013413 else
Daniel Veillard3646d642004-06-02 19:19:14 +000013414 last->next = tmp;
13415 last = tmp;
13416 cur = cur->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013417 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013418 if (dest->negNsSet != NULL)
13419 xmlSchemaFreeWildcardNsSet(dest->negNsSet);
Daniel Veillard3646d642004-06-02 19:19:14 +000013420 if (source->negNsSet != NULL) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013421 dest->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt);
13422 if (dest->negNsSet == NULL)
Daniel Veillard3646d642004-06-02 19:19:14 +000013423 return(-1);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013424 dest->negNsSet->value = source->negNsSet->value;
Daniel Veillard3646d642004-06-02 19:19:14 +000013425 } else
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013426 dest->negNsSet = NULL;
Daniel Veillard3646d642004-06-02 19:19:14 +000013427 return(0);
13428}
13429
Daniel Veillard50355f02004-06-08 17:52:16 +000013430/**
13431 * xmlSchemaUnionWildcards:
13432 * @ctxt: the schema parser context
13433 * @completeWild: the first wildcard
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013434 * @curWild: the second wildcard
Daniel Veillard50355f02004-06-08 17:52:16 +000013435 *
13436 * Unions the namespace constraints of the given wildcards.
13437 * @completeWild will hold the resulting union.
13438 * Returns a positive error code on failure, -1 in case of an
13439 * internal error, 0 otherwise.
13440 */
Daniel Veillard3646d642004-06-02 19:19:14 +000013441static int
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013442xmlSchemaUnionWildcards(xmlSchemaParserCtxtPtr ctxt,
Daniel Veillard3646d642004-06-02 19:19:14 +000013443 xmlSchemaWildcardPtr completeWild,
13444 xmlSchemaWildcardPtr curWild)
13445{
13446 xmlSchemaWildcardNsPtr cur, curB, tmp;
13447
13448 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013449 * 1 If O1 and O2 are the same value, then that value must be the
Daniel Veillard3646d642004-06-02 19:19:14 +000013450 * value.
13451 */
13452 if ((completeWild->any == curWild->any) &&
13453 ((completeWild->nsSet == NULL) == (curWild->nsSet == NULL)) &&
13454 ((completeWild->negNsSet == NULL) == (curWild->negNsSet == NULL))) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013455
Daniel Veillard3646d642004-06-02 19:19:14 +000013456 if ((completeWild->negNsSet == NULL) ||
13457 (completeWild->negNsSet->value == curWild->negNsSet->value)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013458
Daniel Veillard3646d642004-06-02 19:19:14 +000013459 if (completeWild->nsSet != NULL) {
William M. Brack803812b2004-06-03 02:11:24 +000013460 int found = 0;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013461
13462 /*
13463 * Check equality of sets.
Daniel Veillard3646d642004-06-02 19:19:14 +000013464 */
13465 cur = completeWild->nsSet;
13466 while (cur != NULL) {
13467 found = 0;
13468 curB = curWild->nsSet;
13469 while (curB != NULL) {
13470 if (cur->value == curB->value) {
13471 found = 1;
13472 break;
13473 }
13474 curB = curB->next;
13475 }
13476 if (!found)
13477 break;
13478 cur = cur->next;
13479 }
13480 if (found)
13481 return(0);
13482 } else
13483 return(0);
13484 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013485 }
Daniel Veillard3646d642004-06-02 19:19:14 +000013486 /*
13487 * 2 If either O1 or O2 is any, then any must be the value
13488 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013489 if (completeWild->any != curWild->any) {
Daniel Veillard3646d642004-06-02 19:19:14 +000013490 if (completeWild->any == 0) {
13491 completeWild->any = 1;
13492 if (completeWild->nsSet != NULL) {
13493 xmlSchemaFreeWildcardNsSet(completeWild->nsSet);
13494 completeWild->nsSet = NULL;
13495 }
13496 if (completeWild->negNsSet != NULL) {
13497 xmlFree(completeWild->negNsSet);
13498 completeWild->negNsSet = NULL;
13499 }
13500 }
Daniel Veillard50355f02004-06-08 17:52:16 +000013501 return (0);
Daniel Veillard3646d642004-06-02 19:19:14 +000013502 }
13503 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000013504 * 3 If both O1 and O2 are sets of (namespace names or �absent�),
Daniel Veillard3646d642004-06-02 19:19:14 +000013505 * then the union of those sets must be the value.
13506 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013507 if ((completeWild->nsSet != NULL) && (curWild->nsSet != NULL)) {
Daniel Veillard3646d642004-06-02 19:19:14 +000013508 int found;
13509 xmlSchemaWildcardNsPtr start;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013510
Daniel Veillard3646d642004-06-02 19:19:14 +000013511 cur = curWild->nsSet;
13512 start = completeWild->nsSet;
13513 while (cur != NULL) {
13514 found = 0;
13515 curB = start;
13516 while (curB != NULL) {
13517 if (cur->value == curB->value) {
13518 found = 1;
13519 break;
13520 }
13521 curB = curB->next;
13522 }
13523 if (!found) {
13524 tmp = xmlSchemaNewWildcardNsConstraint(ctxt);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013525 if (tmp == NULL)
Daniel Veillard3646d642004-06-02 19:19:14 +000013526 return (-1);
13527 tmp->value = cur->value;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013528 tmp->next = completeWild->nsSet;
Daniel Veillard3646d642004-06-02 19:19:14 +000013529 completeWild->nsSet = tmp;
13530 }
13531 cur = cur->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013532 }
13533
Daniel Veillard3646d642004-06-02 19:19:14 +000013534 return(0);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013535 }
Daniel Veillard3646d642004-06-02 19:19:14 +000013536 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013537 * 4 If the two are negations of different values (namespace names
Rob Richardsc6947bb2008-06-29 15:04:41 +000013538 * or �absent�), then a pair of not and �absent� must be the value.
Daniel Veillard3646d642004-06-02 19:19:14 +000013539 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013540 if ((completeWild->negNsSet != NULL) &&
Daniel Veillard3646d642004-06-02 19:19:14 +000013541 (curWild->negNsSet != NULL) &&
13542 (completeWild->negNsSet->value != curWild->negNsSet->value)) {
13543 completeWild->negNsSet->value = NULL;
Daniel Veillard50355f02004-06-08 17:52:16 +000013544
13545 return(0);
Daniel Veillard3646d642004-06-02 19:19:14 +000013546 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013547 /*
Daniel Veillard3646d642004-06-02 19:19:14 +000013548 * 5.
13549 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013550 if (((completeWild->negNsSet != NULL) &&
Daniel Veillard3646d642004-06-02 19:19:14 +000013551 (completeWild->negNsSet->value != NULL) &&
13552 (curWild->nsSet != NULL)) ||
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013553 ((curWild->negNsSet != NULL) &&
Daniel Veillard3646d642004-06-02 19:19:14 +000013554 (curWild->negNsSet->value != NULL) &&
13555 (completeWild->nsSet != NULL))) {
13556
13557 int nsFound, absentFound = 0;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013558
Daniel Veillard3646d642004-06-02 19:19:14 +000013559 if (completeWild->nsSet != NULL) {
13560 cur = completeWild->nsSet;
13561 curB = curWild->negNsSet;
13562 } else {
13563 cur = curWild->nsSet;
13564 curB = completeWild->negNsSet;
13565 }
13566 nsFound = 0;
13567 while (cur != NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013568 if (cur->value == NULL)
Daniel Veillard3646d642004-06-02 19:19:14 +000013569 absentFound = 1;
13570 else if (cur->value == curB->value)
13571 nsFound = 1;
13572 if (nsFound && absentFound)
13573 break;
13574 cur = cur->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013575 }
Daniel Veillard3646d642004-06-02 19:19:14 +000013576
13577 if (nsFound && absentFound) {
13578 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013579 * 5.1 If the set S includes both the negated namespace
Rob Richardsc6947bb2008-06-29 15:04:41 +000013580 * name and �absent�, then any must be the value.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013581 */
Daniel Veillard3646d642004-06-02 19:19:14 +000013582 completeWild->any = 1;
13583 if (completeWild->nsSet != NULL) {
13584 xmlSchemaFreeWildcardNsSet(completeWild->nsSet);
13585 completeWild->nsSet = NULL;
13586 }
13587 if (completeWild->negNsSet != NULL) {
13588 xmlFree(completeWild->negNsSet);
13589 completeWild->negNsSet = NULL;
13590 }
13591 } else if (nsFound && (!absentFound)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013592 /*
13593 * 5.2 If the set S includes the negated namespace name
Rob Richardsc6947bb2008-06-29 15:04:41 +000013594 * but not �absent�, then a pair of not and �absent� must
Daniel Veillard3646d642004-06-02 19:19:14 +000013595 * be the value.
13596 */
13597 if (completeWild->nsSet != NULL) {
13598 xmlSchemaFreeWildcardNsSet(completeWild->nsSet);
13599 completeWild->nsSet = NULL;
13600 }
13601 if (completeWild->negNsSet == NULL) {
13602 completeWild->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt);
13603 if (completeWild->negNsSet == NULL)
13604 return (-1);
13605 }
13606 completeWild->negNsSet->value = NULL;
13607 } else if ((!nsFound) && absentFound) {
13608 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000013609 * 5.3 If the set S includes �absent� but not the negated
Daniel Veillard3646d642004-06-02 19:19:14 +000013610 * namespace name, then the union is not expressible.
13611 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013612 xmlSchemaPErr(ctxt, completeWild->node,
Daniel Veillard3646d642004-06-02 19:19:14 +000013613 XML_SCHEMAP_UNION_NOT_EXPRESSIBLE,
Daniel Veillardc0826a72004-08-10 14:17:33 +000013614 "The union of the wilcard is not expressible.\n",
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013615 NULL, NULL);
Daniel Veillard50355f02004-06-08 17:52:16 +000013616 return(XML_SCHEMAP_UNION_NOT_EXPRESSIBLE);
Daniel Veillard3646d642004-06-02 19:19:14 +000013617 } else if ((!nsFound) && (!absentFound)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013618 /*
13619 * 5.4 If the set S does not include either the negated namespace
Rob Richardsc6947bb2008-06-29 15:04:41 +000013620 * name or �absent�, then whichever of O1 or O2 is a pair of not
Daniel Veillard3646d642004-06-02 19:19:14 +000013621 * and a namespace name must be the value.
13622 */
13623 if (completeWild->negNsSet == NULL) {
13624 if (completeWild->nsSet != NULL) {
13625 xmlSchemaFreeWildcardNsSet(completeWild->nsSet);
13626 completeWild->nsSet = NULL;
13627 }
13628 completeWild->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt);
13629 if (completeWild->negNsSet == NULL)
13630 return (-1);
13631 completeWild->negNsSet->value = curWild->negNsSet->value;
13632 }
13633 }
13634 return (0);
13635 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013636 /*
Daniel Veillard3646d642004-06-02 19:19:14 +000013637 * 6.
13638 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013639 if (((completeWild->negNsSet != NULL) &&
Daniel Veillard3646d642004-06-02 19:19:14 +000013640 (completeWild->negNsSet->value == NULL) &&
13641 (curWild->nsSet != NULL)) ||
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013642 ((curWild->negNsSet != NULL) &&
Daniel Veillard3646d642004-06-02 19:19:14 +000013643 (curWild->negNsSet->value == NULL) &&
13644 (completeWild->nsSet != NULL))) {
13645
13646 if (completeWild->nsSet != NULL) {
13647 cur = completeWild->nsSet;
13648 } else {
13649 cur = curWild->nsSet;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013650 }
Daniel Veillard3646d642004-06-02 19:19:14 +000013651 while (cur != NULL) {
13652 if (cur->value == NULL) {
13653 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000013654 * 6.1 If the set S includes �absent�, then any must be the
Daniel Veillard3646d642004-06-02 19:19:14 +000013655 * value.
13656 */
13657 completeWild->any = 1;
13658 if (completeWild->nsSet != NULL) {
13659 xmlSchemaFreeWildcardNsSet(completeWild->nsSet);
13660 completeWild->nsSet = NULL;
13661 }
13662 if (completeWild->negNsSet != NULL) {
13663 xmlFree(completeWild->negNsSet);
13664 completeWild->negNsSet = NULL;
13665 }
13666 return (0);
13667 }
13668 cur = cur->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013669 }
Daniel Veillard3646d642004-06-02 19:19:14 +000013670 if (completeWild->negNsSet == NULL) {
13671 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000013672 * 6.2 If the set S does not include �absent�, then a pair of not
13673 * and �absent� must be the value.
Daniel Veillard3646d642004-06-02 19:19:14 +000013674 */
13675 if (completeWild->nsSet != NULL) {
13676 xmlSchemaFreeWildcardNsSet(completeWild->nsSet);
13677 completeWild->nsSet = NULL;
13678 }
13679 completeWild->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt);
13680 if (completeWild->negNsSet == NULL)
13681 return (-1);
13682 completeWild->negNsSet->value = NULL;
13683 }
13684 return (0);
13685 }
13686 return (0);
13687
13688}
13689
Daniel Veillard50355f02004-06-08 17:52:16 +000013690/**
13691 * xmlSchemaIntersectWildcards:
13692 * @ctxt: the schema parser context
13693 * @completeWild: the first wildcard
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013694 * @curWild: the second wildcard
Daniel Veillard50355f02004-06-08 17:52:16 +000013695 *
13696 * Intersects the namespace constraints of the given wildcards.
13697 * @completeWild will hold the resulting intersection.
13698 * Returns a positive error code on failure, -1 in case of an
13699 * internal error, 0 otherwise.
13700 */
Daniel Veillard3646d642004-06-02 19:19:14 +000013701static int
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013702xmlSchemaIntersectWildcards(xmlSchemaParserCtxtPtr ctxt,
Daniel Veillard3646d642004-06-02 19:19:14 +000013703 xmlSchemaWildcardPtr completeWild,
13704 xmlSchemaWildcardPtr curWild)
13705{
William M. Brack803812b2004-06-03 02:11:24 +000013706 xmlSchemaWildcardNsPtr cur, curB, prev, tmp;
Daniel Veillard3646d642004-06-02 19:19:14 +000013707
13708 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013709 * 1 If O1 and O2 are the same value, then that value must be the
Daniel Veillard3646d642004-06-02 19:19:14 +000013710 * value.
13711 */
13712 if ((completeWild->any == curWild->any) &&
13713 ((completeWild->nsSet == NULL) == (curWild->nsSet == NULL)) &&
13714 ((completeWild->negNsSet == NULL) == (curWild->negNsSet == NULL))) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013715
Daniel Veillard3646d642004-06-02 19:19:14 +000013716 if ((completeWild->negNsSet == NULL) ||
13717 (completeWild->negNsSet->value == curWild->negNsSet->value)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013718
Daniel Veillard3646d642004-06-02 19:19:14 +000013719 if (completeWild->nsSet != NULL) {
William M. Brack803812b2004-06-03 02:11:24 +000013720 int found = 0;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013721
13722 /*
13723 * Check equality of sets.
Daniel Veillard3646d642004-06-02 19:19:14 +000013724 */
13725 cur = completeWild->nsSet;
13726 while (cur != NULL) {
13727 found = 0;
13728 curB = curWild->nsSet;
13729 while (curB != NULL) {
13730 if (cur->value == curB->value) {
13731 found = 1;
13732 break;
13733 }
13734 curB = curB->next;
13735 }
13736 if (!found)
13737 break;
13738 cur = cur->next;
13739 }
13740 if (found)
13741 return(0);
13742 } else
13743 return(0);
13744 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013745 }
Daniel Veillard3646d642004-06-02 19:19:14 +000013746 /*
13747 * 2 If either O1 or O2 is any, then the other must be the value.
13748 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013749 if ((completeWild->any != curWild->any) && (completeWild->any)) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013750 if (xmlSchemaCloneWildcardNsConstraints(ctxt, completeWild, curWild) == -1)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013751 return(-1);
Daniel Veillard3646d642004-06-02 19:19:14 +000013752 return(0);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013753 }
Daniel Veillard3646d642004-06-02 19:19:14 +000013754 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013755 * 3 If either O1 or O2 is a pair of not and a value (a namespace
Rob Richardsc6947bb2008-06-29 15:04:41 +000013756 * name or �absent�) and the other is a set of (namespace names or
13757 * �absent�), then that set, minus the negated value if it was in
13758 * the set, minus �absent� if it was in the set, must be the value.
Daniel Veillard3646d642004-06-02 19:19:14 +000013759 */
13760 if (((completeWild->negNsSet != NULL) && (curWild->nsSet != NULL)) ||
13761 ((curWild->negNsSet != NULL) && (completeWild->nsSet != NULL))) {
13762 const xmlChar *neg;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013763
Daniel Veillard3646d642004-06-02 19:19:14 +000013764 if (completeWild->nsSet == NULL) {
13765 neg = completeWild->negNsSet->value;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013766 if (xmlSchemaCloneWildcardNsConstraints(ctxt, completeWild, curWild) == -1)
Daniel Veillard3646d642004-06-02 19:19:14 +000013767 return(-1);
13768 } else
13769 neg = curWild->negNsSet->value;
13770 /*
13771 * Remove absent and negated.
13772 */
13773 prev = NULL;
13774 cur = completeWild->nsSet;
13775 while (cur != NULL) {
13776 if (cur->value == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013777 if (prev == NULL)
Daniel Veillard3646d642004-06-02 19:19:14 +000013778 completeWild->nsSet = cur->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013779 else
Daniel Veillard3646d642004-06-02 19:19:14 +000013780 prev->next = cur->next;
13781 xmlFree(cur);
13782 break;
13783 }
13784 prev = cur;
13785 cur = cur->next;
13786 }
13787 if (neg != NULL) {
13788 prev = NULL;
13789 cur = completeWild->nsSet;
13790 while (cur != NULL) {
13791 if (cur->value == neg) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013792 if (prev == NULL)
Daniel Veillard3646d642004-06-02 19:19:14 +000013793 completeWild->nsSet = cur->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013794 else
Daniel Veillard3646d642004-06-02 19:19:14 +000013795 prev->next = cur->next;
13796 xmlFree(cur);
13797 break;
13798 }
13799 prev = cur;
13800 cur = cur->next;
13801 }
13802 }
13803
13804 return(0);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013805 }
Daniel Veillard3646d642004-06-02 19:19:14 +000013806 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000013807 * 4 If both O1 and O2 are sets of (namespace names or �absent�),
Daniel Veillard3646d642004-06-02 19:19:14 +000013808 * then the intersection of those sets must be the value.
13809 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013810 if ((completeWild->nsSet != NULL) && (curWild->nsSet != NULL)) {
Daniel Veillard3646d642004-06-02 19:19:14 +000013811 int found;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013812
Daniel Veillard3646d642004-06-02 19:19:14 +000013813 cur = completeWild->nsSet;
13814 prev = NULL;
13815 while (cur != NULL) {
13816 found = 0;
13817 curB = curWild->nsSet;
13818 while (curB != NULL) {
13819 if (cur->value == curB->value) {
13820 found = 1;
13821 break;
13822 }
13823 curB = curB->next;
13824 }
13825 if (!found) {
13826 if (prev == NULL)
13827 completeWild->nsSet = cur->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013828 else
Daniel Veillard3646d642004-06-02 19:19:14 +000013829 prev->next = cur->next;
13830 tmp = cur->next;
13831 xmlFree(cur);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013832 cur = tmp;
Daniel Veillard3646d642004-06-02 19:19:14 +000013833 continue;
13834 }
13835 prev = cur;
13836 cur = cur->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013837 }
13838
Daniel Veillard3646d642004-06-02 19:19:14 +000013839 return(0);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013840 }
13841 /* 5 If the two are negations of different namespace names,
Daniel Veillard3646d642004-06-02 19:19:14 +000013842 * then the intersection is not expressible
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013843 */
13844 if ((completeWild->negNsSet != NULL) &&
Daniel Veillard3646d642004-06-02 19:19:14 +000013845 (curWild->negNsSet != NULL) &&
13846 (completeWild->negNsSet->value != curWild->negNsSet->value) &&
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013847 (completeWild->negNsSet->value != NULL) &&
Daniel Veillard3646d642004-06-02 19:19:14 +000013848 (curWild->negNsSet->value != NULL)) {
13849
13850 xmlSchemaPErr(ctxt, completeWild->node, XML_SCHEMAP_INTERSECTION_NOT_EXPRESSIBLE,
Daniel Veillardc0826a72004-08-10 14:17:33 +000013851 "The intersection of the wilcard is not expressible.\n",
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013852 NULL, NULL);
Daniel Veillard50355f02004-06-08 17:52:16 +000013853 return(XML_SCHEMAP_INTERSECTION_NOT_EXPRESSIBLE);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013854 }
13855 /*
13856 * 6 If the one is a negation of a namespace name and the other
Rob Richardsc6947bb2008-06-29 15:04:41 +000013857 * is a negation of �absent�, then the one which is the negation
Daniel Veillard3646d642004-06-02 19:19:14 +000013858 * of a namespace name must be the value.
13859 */
13860 if ((completeWild->negNsSet != NULL) && (curWild->negNsSet != NULL) &&
13861 (completeWild->negNsSet->value != curWild->negNsSet->value) &&
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013862 (completeWild->negNsSet->value == NULL)) {
13863 completeWild->negNsSet->value = curWild->negNsSet->value;
Daniel Veillard3646d642004-06-02 19:19:14 +000013864 }
13865 return(0);
13866}
13867
Daniel Veillard50355f02004-06-08 17:52:16 +000013868/**
13869 * xmlSchemaIsWildcardNsConstraintSubset:
13870 * @ctxt: the schema parser context
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000013871 * @sub: the first wildcard
13872 * @super: the second wildcard
Daniel Veillard50355f02004-06-08 17:52:16 +000013873 *
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000013874 * Schema Component Constraint: Wildcard Subset (cos-ns-subset)
13875 *
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013876 * Returns 0 if the namespace constraint of @sub is an intensional
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000013877 * subset of @super, 1 otherwise.
Daniel Veillard50355f02004-06-08 17:52:16 +000013878 */
13879static int
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000013880xmlSchemaCheckCOSNSSubset(xmlSchemaWildcardPtr sub,
13881 xmlSchemaWildcardPtr super)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013882{
Daniel Veillard50355f02004-06-08 17:52:16 +000013883 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013884 * 1 super must be any.
Daniel Veillard50355f02004-06-08 17:52:16 +000013885 */
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000013886 if (super->any)
13887 return (0);
Daniel Veillard50355f02004-06-08 17:52:16 +000013888 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000013889 * 2.1 sub must be a pair of not and a namespace name or �absent�.
Daniel Veillard50355f02004-06-08 17:52:16 +000013890 * 2.2 super must be a pair of not and the same value.
13891 */
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000013892 if ((sub->negNsSet != NULL) &&
13893 (super->negNsSet != NULL) &&
13894 (sub->negNsSet->value == sub->negNsSet->value))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013895 return (0);
13896 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000013897 * 3.1 sub must be a set whose members are either namespace names or �absent�.
Daniel Veillard50355f02004-06-08 17:52:16 +000013898 */
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000013899 if (sub->nsSet != NULL) {
Daniel Veillard50355f02004-06-08 17:52:16 +000013900 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013901 * 3.2.1 super must be the same set or a superset thereof.
Daniel Veillard50355f02004-06-08 17:52:16 +000013902 */
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000013903 if (super->nsSet != NULL) {
Daniel Veillard50355f02004-06-08 17:52:16 +000013904 xmlSchemaWildcardNsPtr cur, curB;
13905 int found = 0;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013906
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000013907 cur = sub->nsSet;
Daniel Veillard50355f02004-06-08 17:52:16 +000013908 while (cur != NULL) {
13909 found = 0;
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000013910 curB = super->nsSet;
Daniel Veillard50355f02004-06-08 17:52:16 +000013911 while (curB != NULL) {
13912 if (cur->value == curB->value) {
13913 found = 1;
13914 break;
13915 }
13916 curB = curB->next;
13917 }
13918 if (!found)
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000013919 return (1);
Daniel Veillard50355f02004-06-08 17:52:16 +000013920 cur = cur->next;
13921 }
13922 if (found)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013923 return (0);
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000013924 } else if (super->negNsSet != NULL) {
Daniel Veillard50355f02004-06-08 17:52:16 +000013925 xmlSchemaWildcardNsPtr cur;
13926 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013927 * 3.2.2 super must be a pair of not and a namespace name or
Rob Richardsc6947bb2008-06-29 15:04:41 +000013928 * �absent� and that value must not be in sub's set.
Daniel Veillard50355f02004-06-08 17:52:16 +000013929 */
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000013930 cur = sub->nsSet;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013931 while (cur != NULL) {
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000013932 if (cur->value == super->negNsSet->value)
13933 return (1);
Daniel Veillard50355f02004-06-08 17:52:16 +000013934 cur = cur->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013935 }
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000013936 return (0);
Daniel Veillard50355f02004-06-08 17:52:16 +000013937 }
13938 }
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000013939 return (1);
Daniel Veillard50355f02004-06-08 17:52:16 +000013940}
13941
Daniel Veillard50355f02004-06-08 17:52:16 +000013942static int
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013943xmlSchemaGetEffectiveValueConstraint(xmlSchemaAttributeUsePtr attruse,
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000013944 int *fixed,
13945 const xmlChar **value,
13946 xmlSchemaValPtr *val)
13947{
13948 *fixed = 0;
13949 *value = NULL;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013950 if (val != 0)
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000013951 *val = NULL;
13952
Daniel Veillarddee23482008-04-11 12:58:43 +000013953 if (attruse->defValue != NULL) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013954 *value = attruse->defValue;
Kasimier T. Buchcik65c2f1d2005-10-17 12:39:58 +000013955 if (val != NULL)
13956 *val = attruse->defVal;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013957 if (attruse->flags & XML_SCHEMA_ATTR_USE_FIXED)
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000013958 *fixed = 1;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013959 return(1);
Kasimier T. Buchcik65c2f1d2005-10-17 12:39:58 +000013960 } else if ((attruse->attrDecl != NULL) &&
13961 (attruse->attrDecl->defValue != NULL)) {
13962 *value = attruse->attrDecl->defValue;
13963 if (val != NULL)
13964 *val = attruse->attrDecl->defVal;
13965 if (attruse->attrDecl->flags & XML_SCHEMAS_ATTR_FIXED)
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013966 *fixed = 1;
13967 return(1);
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000013968 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013969 return(0);
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000013970}
Daniel Veillard3646d642004-06-02 19:19:14 +000013971/**
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013972 * xmlSchemaCheckCVCWildcardNamespace:
Daniel Veillard3646d642004-06-02 19:19:14 +000013973 * @wild: the wildcard
13974 * @ns: the namespace
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013975 *
13976 * Validation Rule: Wildcard allows Namespace Name
13977 * (cvc-wildcard-namespace)
13978 *
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013979 * Returns 0 if the given namespace matches the wildcard,
13980 * 1 otherwise and -1 on API errors.
Daniel Veillard3646d642004-06-02 19:19:14 +000013981 */
13982static int
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013983xmlSchemaCheckCVCWildcardNamespace(xmlSchemaWildcardPtr wild,
13984 const xmlChar* ns)
Daniel Veillard3646d642004-06-02 19:19:14 +000013985{
13986 if (wild == NULL)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000013987 return(-1);
Daniel Veillard3646d642004-06-02 19:19:14 +000013988
13989 if (wild->any)
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013990 return(0);
Daniel Veillard3646d642004-06-02 19:19:14 +000013991 else if (wild->nsSet != NULL) {
13992 xmlSchemaWildcardNsPtr cur;
13993
13994 cur = wild->nsSet;
13995 while (cur != NULL) {
13996 if (xmlStrEqual(cur->value, ns))
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000013997 return(0);
Daniel Veillard3646d642004-06-02 19:19:14 +000013998 cur = cur->next;
13999 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014000 } else if ((wild->negNsSet != NULL) && (ns != NULL) &&
Daniel Veillard3646d642004-06-02 19:19:14 +000014001 (!xmlStrEqual(wild->negNsSet->value, ns)))
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014002 return(0);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014003
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014004 return(1);
14005}
14006
14007#define XML_SCHEMA_ACTION_DERIVE 0
14008#define XML_SCHEMA_ACTION_REDEFINE 1
14009
14010#define WXS_ACTION_STR(a) \
14011((a) == XML_SCHEMA_ACTION_DERIVE) ? (const xmlChar *) "base" : (const xmlChar *) "redefined"
14012
14013/*
14014* Schema Component Constraint:
14015* Derivation Valid (Restriction, Complex)
14016* derivation-ok-restriction (2) - (4)
14017*
14018* ATTENTION:
14019* In XML Schema 1.1 this will be:
14020* Validation Rule:
14021* Checking complex type subsumption (practicalSubsumption) (1, 2 and 3)
14022*
14023*/
14024static int
14025xmlSchemaCheckDerivationOKRestriction2to4(xmlSchemaParserCtxtPtr pctxt,
14026 int action,
14027 xmlSchemaBasicItemPtr item,
14028 xmlSchemaBasicItemPtr baseItem,
14029 xmlSchemaItemListPtr uses,
14030 xmlSchemaItemListPtr baseUses,
14031 xmlSchemaWildcardPtr wild,
14032 xmlSchemaWildcardPtr baseWild)
Daniel Veillarddee23482008-04-11 12:58:43 +000014033{
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014034 xmlSchemaAttributeUsePtr cur = NULL, bcur;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000014035 int i, j, found; /* err = 0; */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014036 const xmlChar *bEffValue;
14037 int effFixed;
Daniel Veillarddee23482008-04-11 12:58:43 +000014038
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014039 if (uses != NULL) {
14040 for (i = 0; i < uses->nbItems; i++) {
14041 cur = uses->items[i];
14042 found = 0;
14043 if (baseUses == NULL)
14044 goto not_found;
14045 for (j = 0; j < baseUses->nbItems; j++) {
Daniel Veillarddee23482008-04-11 12:58:43 +000014046 bcur = baseUses->items[j];
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014047 if ((WXS_ATTRUSE_DECL_NAME(cur) ==
14048 WXS_ATTRUSE_DECL_NAME(bcur)) &&
14049 (WXS_ATTRUSE_DECL_TNS(cur) ==
14050 WXS_ATTRUSE_DECL_TNS(bcur)))
14051 {
14052 /*
14053 * (2.1) "If there is an attribute use in the {attribute
14054 * uses} of the {base type definition} (call this B) whose
14055 * {attribute declaration} has the same {name} and {target
14056 * namespace}, then all of the following must be true:"
14057 */
14058 found = 1;
Daniel Veillarddee23482008-04-11 12:58:43 +000014059
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014060 if ((cur->occurs == XML_SCHEMAS_ATTR_USE_OPTIONAL) &&
14061 (bcur->occurs == XML_SCHEMAS_ATTR_USE_REQUIRED))
14062 {
14063 xmlChar *str = NULL;
14064 /*
14065 * (2.1.1) "one of the following must be true:"
14066 * (2.1.1.1) "B's {required} is false."
14067 * (2.1.1.2) "R's {required} is true."
14068 */
14069 xmlSchemaPAttrUseErr4(pctxt,
14070 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_1,
14071 WXS_ITEM_NODE(item), item, cur,
14072 "The 'optional' attribute use is inconsistent "
14073 "with the corresponding 'required' attribute use of "
14074 "the %s %s",
14075 WXS_ACTION_STR(action),
14076 xmlSchemaGetComponentDesignation(&str, baseItem),
14077 NULL, NULL);
14078 FREE_AND_NULL(str);
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000014079 /* err = pctxt->err; */
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000014080 } else if (xmlSchemaCheckCOSSTDerivedOK(ACTXT_CAST pctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014081 WXS_ATTRUSE_TYPEDEF(cur),
14082 WXS_ATTRUSE_TYPEDEF(bcur), 0) != 0)
14083 {
14084 xmlChar *strA = NULL, *strB = NULL, *strC = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000014085
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014086 /*
14087 * SPEC (2.1.2) "R's {attribute declaration}'s
14088 * {type definition} must be validly derived from
14089 * B's {type definition} given the empty set as
Rob Richardsc6947bb2008-06-29 15:04:41 +000014090 * defined in Type Derivation OK (Simple) (�3.14.6)."
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014091 */
14092 xmlSchemaPAttrUseErr4(pctxt,
14093 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_2,
14094 WXS_ITEM_NODE(item), item, cur,
14095 "The attribute declaration's %s "
14096 "is not validly derived from "
14097 "the corresponding %s of the "
14098 "attribute declaration in the %s %s",
14099 xmlSchemaGetComponentDesignation(&strA,
14100 WXS_ATTRUSE_TYPEDEF(cur)),
14101 xmlSchemaGetComponentDesignation(&strB,
14102 WXS_ATTRUSE_TYPEDEF(bcur)),
14103 WXS_ACTION_STR(action),
14104 xmlSchemaGetComponentDesignation(&strC, baseItem));
14105 /* xmlSchemaGetComponentDesignation(&str, baseItem), */
14106 FREE_AND_NULL(strA);
14107 FREE_AND_NULL(strB);
14108 FREE_AND_NULL(strC);
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000014109 /* err = pctxt->err; */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014110 } else {
14111 /*
14112 * 2.1.3 [Definition:] Let the effective value
14113 * constraint of an attribute use be its {value
14114 * constraint}, if present, otherwise its {attribute
14115 * declaration}'s {value constraint} .
14116 */
14117 xmlSchemaGetEffectiveValueConstraint(bcur,
14118 &effFixed, &bEffValue, NULL);
14119 /*
14120 * 2.1.3 ... one of the following must be true
14121 *
Rob Richardsc6947bb2008-06-29 15:04:41 +000014122 * 2.1.3.1 B's �effective value constraint� is
14123 * �absent� or default.
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014124 */
14125 if ((bEffValue != NULL) &&
14126 (effFixed == 1)) {
14127 const xmlChar *rEffValue = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000014128
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014129 xmlSchemaGetEffectiveValueConstraint(bcur,
14130 &effFixed, &rEffValue, NULL);
14131 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000014132 * 2.1.3.2 R's �effective value constraint� is
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014133 * fixed with the same string as B's.
14134 * MAYBE TODO: Compare the computed values.
14135 * Hmm, it says "same string" so
14136 * string-equality might really be sufficient.
14137 */
14138 if ((effFixed == 0) ||
14139 (! WXS_ARE_DEFAULT_STR_EQUAL(rEffValue, bEffValue)))
14140 {
14141 xmlChar *str = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000014142
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014143 xmlSchemaPAttrUseErr4(pctxt,
14144 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_3,
14145 WXS_ITEM_NODE(item), item, cur,
14146 "The effective value constraint of the "
14147 "attribute use is inconsistent with "
14148 "its correspondent in the %s %s",
14149 WXS_ACTION_STR(action),
14150 xmlSchemaGetComponentDesignation(&str,
14151 baseItem),
14152 NULL, NULL);
14153 FREE_AND_NULL(str);
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000014154 /* err = pctxt->err; */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014155 }
14156 }
14157 }
14158 break;
14159 }
14160 }
Daniel Veillarddee23482008-04-11 12:58:43 +000014161not_found:
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014162 if (!found) {
14163 /*
14164 * (2.2) "otherwise the {base type definition} must have an
14165 * {attribute wildcard} and the {target namespace} of the
Rob Richardsc6947bb2008-06-29 15:04:41 +000014166 * R's {attribute declaration} must be �valid� with respect
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014167 * to that wildcard, as defined in Wildcard allows Namespace
Rob Richardsc6947bb2008-06-29 15:04:41 +000014168 * Name (�3.10.4)."
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014169 */
14170 if ((baseWild == NULL) ||
14171 (xmlSchemaCheckCVCWildcardNamespace(baseWild,
14172 (WXS_ATTRUSE_DECL(cur))->targetNamespace) != 0))
14173 {
14174 xmlChar *str = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000014175
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014176 xmlSchemaPAttrUseErr4(pctxt,
14177 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_2,
14178 WXS_ITEM_NODE(item), item, cur,
14179 "Neither a matching attribute use, "
14180 "nor a matching wildcard exists in the %s %s",
14181 WXS_ACTION_STR(action),
14182 xmlSchemaGetComponentDesignation(&str, baseItem),
14183 NULL, NULL);
14184 FREE_AND_NULL(str);
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000014185 /* err = pctxt->err; */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014186 }
14187 }
14188 }
14189 }
14190 /*
Daniel Veillarddee23482008-04-11 12:58:43 +000014191 * SPEC derivation-ok-restriction (3):
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014192 * (3) "For each attribute use in the {attribute uses} of the {base type
14193 * definition} whose {required} is true, there must be an attribute
14194 * use with an {attribute declaration} with the same {name} and
14195 * {target namespace} as its {attribute declaration} in the {attribute
14196 * uses} of the complex type definition itself whose {required} is true.
14197 */
14198 if (baseUses != NULL) {
14199 for (j = 0; j < baseUses->nbItems; j++) {
14200 bcur = baseUses->items[j];
14201 if (bcur->occurs != XML_SCHEMAS_ATTR_USE_REQUIRED)
14202 continue;
14203 found = 0;
14204 if (uses != NULL) {
14205 for (i = 0; i < uses->nbItems; i++) {
Daniel Veillarddee23482008-04-11 12:58:43 +000014206 cur = uses->items[i];
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014207 if ((WXS_ATTRUSE_DECL_NAME(cur) ==
14208 WXS_ATTRUSE_DECL_NAME(bcur)) &&
14209 (WXS_ATTRUSE_DECL_TNS(cur) ==
14210 WXS_ATTRUSE_DECL_TNS(bcur))) {
14211 found = 1;
14212 break;
14213 }
14214 }
14215 }
14216 if (!found) {
14217 xmlChar *strA = NULL, *strB = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000014218
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014219 xmlSchemaCustomErr4(ACTXT_CAST pctxt,
14220 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_3,
14221 NULL, item,
14222 "A matching attribute use for the "
14223 "'required' %s of the %s %s is missing",
14224 xmlSchemaGetComponentDesignation(&strA, bcur),
14225 WXS_ACTION_STR(action),
14226 xmlSchemaGetComponentDesignation(&strB, baseItem),
14227 NULL);
14228 FREE_AND_NULL(strA);
14229 FREE_AND_NULL(strB);
14230 }
14231 }
14232 }
14233 /*
14234 * derivation-ok-restriction (4)
14235 */
14236 if (wild != NULL) {
14237 /*
14238 * (4) "If there is an {attribute wildcard}, all of the
14239 * following must be true:"
Daniel Veillarddee23482008-04-11 12:58:43 +000014240 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014241 if (baseWild == NULL) {
14242 xmlChar *str = NULL;
14243
14244 /*
14245 * (4.1) "The {base type definition} must also have one."
Daniel Veillarddee23482008-04-11 12:58:43 +000014246 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014247 xmlSchemaCustomErr4(ACTXT_CAST pctxt,
14248 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_1,
14249 NULL, item,
14250 "The %s has an attribute wildcard, "
14251 "but the %s %s '%s' does not have one",
Daniel Veillarddee23482008-04-11 12:58:43 +000014252 WXS_ITEM_TYPE_NAME(item),
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014253 WXS_ACTION_STR(action),
14254 WXS_ITEM_TYPE_NAME(baseItem),
14255 xmlSchemaGetComponentQName(&str, baseItem));
14256 FREE_AND_NULL(str);
14257 return(pctxt->err);
14258 } else if ((baseWild->any == 0) &&
14259 xmlSchemaCheckCOSNSSubset(wild, baseWild))
14260 {
14261 xmlChar *str = NULL;
14262 /*
14263 * (4.2) "The complex type definition's {attribute wildcard}'s
14264 * {namespace constraint} must be a subset of the {base type
14265 * definition}'s {attribute wildcard}'s {namespace constraint},
Rob Richardsc6947bb2008-06-29 15:04:41 +000014266 * as defined by Wildcard Subset (�3.10.6)."
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014267 */
14268 xmlSchemaCustomErr4(ACTXT_CAST pctxt,
14269 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_2,
14270 NULL, item,
14271 "The attribute wildcard is not a valid "
14272 "subset of the wildcard in the %s %s '%s'",
14273 WXS_ACTION_STR(action),
14274 WXS_ITEM_TYPE_NAME(baseItem),
14275 xmlSchemaGetComponentQName(&str, baseItem),
14276 NULL);
14277 FREE_AND_NULL(str);
14278 return(pctxt->err);
14279 }
Rob Richardsc6947bb2008-06-29 15:04:41 +000014280 /* 4.3 Unless the {base type definition} is the �ur-type
14281 * definition�, the complex type definition's {attribute
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014282 * wildcard}'s {process contents} must be identical to or
14283 * stronger than the {base type definition}'s {attribute
14284 * wildcard}'s {process contents}, where strict is stronger
14285 * than lax is stronger than skip.
14286 */
14287 if ((! WXS_IS_ANYTYPE(baseItem)) &&
14288 (wild->processContents < baseWild->processContents)) {
14289 xmlChar *str = NULL;
14290 xmlSchemaCustomErr4(ACTXT_CAST pctxt,
14291 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_3,
14292 NULL, baseItem,
14293 "The {process contents} of the attribute wildcard is "
14294 "weaker than the one in the %s %s '%s'",
14295 WXS_ACTION_STR(action),
14296 WXS_ITEM_TYPE_NAME(baseItem),
14297 xmlSchemaGetComponentQName(&str, baseItem),
14298 NULL);
14299 FREE_AND_NULL(str)
14300 return(pctxt->err);
14301 }
14302 }
Daniel Veillard3646d642004-06-02 19:19:14 +000014303 return(0);
14304}
14305
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014306
14307static int
14308xmlSchemaExpandAttributeGroupRefs(xmlSchemaParserCtxtPtr pctxt,
14309 xmlSchemaBasicItemPtr item,
14310 xmlSchemaWildcardPtr *completeWild,
14311 xmlSchemaItemListPtr list,
14312 xmlSchemaItemListPtr prohibs);
Daniel Veillard3646d642004-06-02 19:19:14 +000014313/**
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014314 * xmlSchemaFixupTypeAttributeUses:
Daniel Veillard3646d642004-06-02 19:19:14 +000014315 * @ctxt: the schema parser context
14316 * @type: the complex type definition
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014317 *
Daniel Veillard3646d642004-06-02 19:19:14 +000014318 *
14319 * Builds the wildcard and the attribute uses on the given complex type.
14320 * Returns -1 if an internal error occurs, 0 otherwise.
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014321 *
14322 * ATTENTION TODO: Experimantally this uses pointer comparisons for
14323 * strings, so recheck this if we start to hardcode some schemata, since
14324 * they might not be in the same dict.
14325 * NOTE: It is allowed to "extend" the xs:anyType type.
Daniel Veillard3646d642004-06-02 19:19:14 +000014326 */
14327static int
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014328xmlSchemaFixupTypeAttributeUses(xmlSchemaParserCtxtPtr pctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014329 xmlSchemaTypePtr type)
Daniel Veillard3646d642004-06-02 19:19:14 +000014330{
14331 xmlSchemaTypePtr baseType = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000014332 xmlSchemaAttributeUsePtr use;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014333 xmlSchemaItemListPtr uses, baseUses, prohibs = NULL;
Daniel Veillard3646d642004-06-02 19:19:14 +000014334
Daniel Veillard01fa6152004-06-29 17:04:39 +000014335 if (type->baseType == NULL) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014336 PERROR_INT("xmlSchemaFixupTypeAttributeUses",
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014337 "no base type");
Daniel Veillard01fa6152004-06-29 17:04:39 +000014338 return (-1);
14339 }
Daniel Veillarddee23482008-04-11 12:58:43 +000014340 baseType = type->baseType;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014341 if (WXS_IS_TYPE_NOT_FIXED(baseType))
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000014342 if (xmlSchemaTypeFixup(baseType, ACTXT_CAST pctxt) == -1)
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014343 return(-1);
14344
14345 uses = type->attrUses;
14346 baseUses = baseType->attrUses;
Daniel Veillardb7c6ac42004-06-29 22:01:27 +000014347 /*
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014348 * Expand attribute group references. And build the 'complete'
14349 * wildcard, i.e. intersect multiple wildcards.
14350 * Move attribute prohibitions into a separate list.
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000014351 */
Daniel Veillarddee23482008-04-11 12:58:43 +000014352 if (uses != NULL) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014353 if (WXS_IS_RESTRICTION(type)) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000014354 /*
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014355 * This one will transfer all attr. prohibitions
14356 * into pctxt->attrProhibs.
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000014357 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014358 if (xmlSchemaExpandAttributeGroupRefs(pctxt,
14359 WXS_BASIC_CAST type, &(type->attributeWildcard), uses,
14360 pctxt->attrProhibs) == -1)
14361 {
14362 PERROR_INT("xmlSchemaFixupTypeAttributeUses",
14363 "failed to expand attributes");
14364 }
14365 if (pctxt->attrProhibs->nbItems != 0)
14366 prohibs = pctxt->attrProhibs;
14367 } else {
14368 if (xmlSchemaExpandAttributeGroupRefs(pctxt,
14369 WXS_BASIC_CAST type, &(type->attributeWildcard), uses,
14370 NULL) == -1)
14371 {
14372 PERROR_INT("xmlSchemaFixupTypeAttributeUses",
14373 "failed to expand attributes");
14374 }
14375 }
14376 }
14377 /*
14378 * Inherit the attribute uses of the base type.
14379 */
14380 if (baseUses != NULL) {
14381 int i, j;
14382 xmlSchemaAttributeUseProhibPtr pro;
14383
14384 if (WXS_IS_RESTRICTION(type)) {
14385 int usesCount;
Daniel Veillarddee23482008-04-11 12:58:43 +000014386 xmlSchemaAttributeUsePtr tmp;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014387
14388 if (uses != NULL)
14389 usesCount = uses->nbItems;
14390 else
14391 usesCount = 0;
14392
14393 /* Restriction. */
14394 for (i = 0; i < baseUses->nbItems; i++) {
14395 use = baseUses->items[i];
14396 if (prohibs) {
14397 /*
14398 * Filter out prohibited uses.
14399 */
14400 for (j = 0; j < prohibs->nbItems; j++) {
14401 pro = prohibs->items[j];
14402 if ((WXS_ATTRUSE_DECL_NAME(use) == pro->name) &&
14403 (WXS_ATTRUSE_DECL_TNS(use) ==
14404 pro->targetNamespace))
14405 {
14406 goto inherit_next;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000014407 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000014408 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014409 }
14410 if (usesCount) {
14411 /*
14412 * Filter out existing uses.
14413 */
14414 for (j = 0; j < usesCount; j++) {
14415 tmp = uses->items[j];
14416 if ((WXS_ATTRUSE_DECL_NAME(use) ==
14417 WXS_ATTRUSE_DECL_NAME(tmp)) &&
14418 (WXS_ATTRUSE_DECL_TNS(use) ==
14419 WXS_ATTRUSE_DECL_TNS(tmp)))
14420 {
14421 goto inherit_next;
14422 }
14423 }
14424 }
14425 if (uses == NULL) {
14426 type->attrUses = xmlSchemaItemListCreate();
14427 if (type->attrUses == NULL)
14428 goto exit_failure;
14429 uses = type->attrUses;
14430 }
14431 xmlSchemaItemListAddSize(uses, 2, use);
14432inherit_next: {}
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000014433 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014434 } else {
14435 /* Extension. */
Daniel Veillarddee23482008-04-11 12:58:43 +000014436 for (i = 0; i < baseUses->nbItems; i++) {
14437 use = baseUses->items[i];
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014438 if (uses == NULL) {
14439 type->attrUses = xmlSchemaItemListCreate();
14440 if (type->attrUses == NULL)
14441 goto exit_failure;
14442 uses = type->attrUses;
14443 }
Daniel Veillarddee23482008-04-11 12:58:43 +000014444 xmlSchemaItemListAddSize(uses, baseUses->nbItems, use);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014445 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000014446 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014447 }
14448 /*
14449 * Shrink attr. uses.
14450 */
14451 if (uses) {
14452 if (uses->nbItems == 0) {
14453 xmlSchemaItemListFree(uses);
14454 type->attrUses = NULL;
14455 }
14456 /*
14457 * TODO: We could shrink the size of the array
14458 * to fit the actual number of items.
14459 */
14460 }
14461 /*
14462 * Compute the complete wildcard.
14463 */
Daniel Veillarddee23482008-04-11 12:58:43 +000014464 if (WXS_IS_EXTENSION(type)) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014465 if (baseType->attributeWildcard != NULL) {
Daniel Veillardb7c6ac42004-06-29 22:01:27 +000014466 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000014467 * (3.2.2.1) "If the �base wildcard� is non-�absent�, then
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014468 * the appropriate case among the following:"
Daniel Veillardb7c6ac42004-06-29 22:01:27 +000014469 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014470 if (type->attributeWildcard != NULL) {
14471 /*
14472 * Union the complete wildcard with the base wildcard.
14473 * SPEC {attribute wildcard}
14474 * (3.2.2.1.2) "otherwise a wildcard whose {process contents}
Rob Richardsc6947bb2008-06-29 15:04:41 +000014475 * and {annotation} are those of the �complete wildcard�,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014476 * and whose {namespace constraint} is the intensional union
Rob Richardsc6947bb2008-06-29 15:04:41 +000014477 * of the {namespace constraint} of the �complete wildcard�
14478 * and of the �base wildcard�, as defined in Attribute
14479 * Wildcard Union (�3.10.6)."
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014480 */
14481 if (xmlSchemaUnionWildcards(pctxt, type->attributeWildcard,
14482 baseType->attributeWildcard) == -1)
Daniel Veillarddee23482008-04-11 12:58:43 +000014483 goto exit_failure;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014484 } else {
14485 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000014486 * (3.2.2.1.1) "If the �complete wildcard� is �absent�,
14487 * then the �base wildcard�."
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014488 */
14489 type->attributeWildcard = baseType->attributeWildcard;
Daniel Veillarddee23482008-04-11 12:58:43 +000014490 }
Daniel Veillardb7c6ac42004-06-29 22:01:27 +000014491 } else {
14492 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000014493 * (3.2.2.2) "otherwise (the �base wildcard� is �absent�) the
14494 * �complete wildcard"
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014495 * NOOP
Daniel Veillardb7c6ac42004-06-29 22:01:27 +000014496 */
Daniel Veillard50355f02004-06-08 17:52:16 +000014497 }
Daniel Veillard3646d642004-06-02 19:19:14 +000014498 } else {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014499 /*
14500 * SPEC {attribute wildcard}
14501 * (3.1) "If the <restriction> alternative is chosen, then the
Rob Richardsc6947bb2008-06-29 15:04:41 +000014502 * �complete wildcard�;"
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014503 * NOOP
14504 */
Daniel Veillard50355f02004-06-08 17:52:16 +000014505 }
Daniel Veillarddee23482008-04-11 12:58:43 +000014506
Daniel Veillard3646d642004-06-02 19:19:14 +000014507 return (0);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014508
14509exit_failure:
14510 return(-1);
Daniel Veillard3646d642004-06-02 19:19:14 +000014511}
14512
14513/**
Daniel Veillard01fa6152004-06-29 17:04:39 +000014514 * xmlSchemaTypeFinalContains:
14515 * @schema: the schema
14516 * @type: the type definition
14517 * @final: the final
14518 *
14519 * Evaluates if a type definition contains the given "final".
14520 * This does take "finalDefault" into account as well.
14521 *
14522 * Returns 1 if the type does containt the given "final",
14523 * 0 otherwise.
14524 */
14525static int
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014526xmlSchemaTypeFinalContains(xmlSchemaTypePtr type, int final)
Daniel Veillard01fa6152004-06-29 17:04:39 +000014527{
Daniel Veillard01fa6152004-06-29 17:04:39 +000014528 if (type == NULL)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014529 return (0);
14530 if (type->flags & final)
Daniel Veillard01fa6152004-06-29 17:04:39 +000014531 return (1);
14532 else
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014533 return (0);
Daniel Veillard01fa6152004-06-29 17:04:39 +000014534}
14535
14536/**
14537 * xmlSchemaGetUnionSimpleTypeMemberTypes:
14538 * @type: the Union Simple Type
14539 *
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014540 * Returns a list of member types of @type if existing,
Daniel Veillard01fa6152004-06-29 17:04:39 +000014541 * returns NULL otherwise.
14542 */
Daniel Veillardb7c6ac42004-06-29 22:01:27 +000014543static xmlSchemaTypeLinkPtr
Daniel Veillard01fa6152004-06-29 17:04:39 +000014544xmlSchemaGetUnionSimpleTypeMemberTypes(xmlSchemaTypePtr type)
14545{
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000014546 while ((type != NULL) && (type->type == XML_SCHEMA_TYPE_SIMPLE)) {
Daniel Veillard01fa6152004-06-29 17:04:39 +000014547 if (type->memberTypes != NULL)
14548 return (type->memberTypes);
14549 else
14550 type = type->baseType;
14551 }
14552 return (NULL);
14553}
14554
14555/**
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000014556 * xmlSchemaGetParticleTotalRangeMin:
14557 * @particle: the particle
14558 *
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014559 * Schema Component Constraint: Effective Total Range
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000014560 * (all and sequence) + (choice)
14561 *
14562 * Returns the minimun Effective Total Range.
14563 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000014564static int
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000014565xmlSchemaGetParticleTotalRangeMin(xmlSchemaParticlePtr particle)
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000014566{
14567 if ((particle->children == NULL) ||
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000014568 (particle->minOccurs == 0))
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000014569 return (0);
14570 if (particle->children->type == XML_SCHEMA_TYPE_CHOICE) {
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000014571 int min = -1, cur;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014572 xmlSchemaParticlePtr part =
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000014573 (xmlSchemaParticlePtr) particle->children->children;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000014574
14575 if (part == NULL)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014576 return (0);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000014577 while (part != NULL) {
14578 if ((part->children->type == XML_SCHEMA_TYPE_ELEMENT) ||
14579 (part->children->type == XML_SCHEMA_TYPE_ANY))
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000014580 cur = part->minOccurs;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000014581 else
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000014582 cur = xmlSchemaGetParticleTotalRangeMin(part);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000014583 if (cur == 0)
14584 return (0);
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000014585 if ((min > cur) || (min == -1))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014586 min = cur;
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000014587 part = (xmlSchemaParticlePtr) part->next;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000014588 }
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000014589 return (particle->minOccurs * min);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000014590 } else {
14591 /* <all> and <sequence> */
14592 int sum = 0;
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000014593 xmlSchemaParticlePtr part =
14594 (xmlSchemaParticlePtr) particle->children->children;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000014595
14596 if (part == NULL)
14597 return (0);
14598 do {
14599 if ((part->children->type == XML_SCHEMA_TYPE_ELEMENT) ||
14600 (part->children->type == XML_SCHEMA_TYPE_ANY))
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000014601 sum += part->minOccurs;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000014602 else
14603 sum += xmlSchemaGetParticleTotalRangeMin(part);
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000014604 part = (xmlSchemaParticlePtr) part->next;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000014605 } while (part != NULL);
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000014606 return (particle->minOccurs * sum);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000014607 }
14608}
14609
Daniel Veillard15724252008-08-30 15:01:04 +000014610#if 0
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000014611/**
14612 * xmlSchemaGetParticleTotalRangeMax:
14613 * @particle: the particle
14614 *
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014615 * Schema Component Constraint: Effective Total Range
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000014616 * (all and sequence) + (choice)
14617 *
14618 * Returns the maximum Effective Total Range.
14619 */
14620static int
14621xmlSchemaGetParticleTotalRangeMax(xmlSchemaParticlePtr particle)
14622{
14623 if ((particle->children == NULL) ||
14624 (particle->children->children == NULL))
14625 return (0);
14626 if (particle->children->type == XML_SCHEMA_TYPE_CHOICE) {
14627 int max = -1, cur;
14628 xmlSchemaParticlePtr part =
14629 (xmlSchemaParticlePtr) particle->children->children;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000014630
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000014631 for (; part != NULL; part = (xmlSchemaParticlePtr) part->next) {
14632 if (part->children == NULL)
14633 continue;
14634 if ((part->children->type == XML_SCHEMA_TYPE_ELEMENT) ||
14635 (part->children->type == XML_SCHEMA_TYPE_ANY))
14636 cur = part->maxOccurs;
14637 else
14638 cur = xmlSchemaGetParticleTotalRangeMax(part);
14639 if (cur == UNBOUNDED)
14640 return (UNBOUNDED);
14641 if ((max < cur) || (max == -1))
14642 max = cur;
14643 }
14644 /* TODO: Handle overflows? */
14645 return (particle->maxOccurs * max);
14646 } else {
14647 /* <all> and <sequence> */
14648 int sum = 0, cur;
14649 xmlSchemaParticlePtr part =
14650 (xmlSchemaParticlePtr) particle->children->children;
14651
14652 for (; part != NULL; part = (xmlSchemaParticlePtr) part->next) {
14653 if (part->children == NULL)
14654 continue;
14655 if ((part->children->type == XML_SCHEMA_TYPE_ELEMENT) ||
14656 (part->children->type == XML_SCHEMA_TYPE_ANY))
14657 cur = part->maxOccurs;
14658 else
14659 cur = xmlSchemaGetParticleTotalRangeMax(part);
14660 if (cur == UNBOUNDED)
14661 return (UNBOUNDED);
14662 if ((cur > 0) && (particle->maxOccurs == UNBOUNDED))
14663 return (UNBOUNDED);
14664 sum += cur;
14665 }
14666 /* TODO: Handle overflows? */
14667 return (particle->maxOccurs * sum);
14668 }
14669}
Daniel Veillard15724252008-08-30 15:01:04 +000014670#endif
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000014671
14672/**
14673 * xmlSchemaIsParticleEmptiable:
14674 * @particle: the particle
14675 *
14676 * Schema Component Constraint: Particle Emptiable
14677 * Checks whether the given particle is emptiable.
14678 *
14679 * Returns 1 if emptiable, 0 otherwise.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014680 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000014681static int
14682xmlSchemaIsParticleEmptiable(xmlSchemaParticlePtr particle)
14683{
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000014684 /*
14685 * SPEC (1) "Its {min occurs} is 0."
14686 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000014687 if ((particle == NULL) || (particle->minOccurs == 0) ||
14688 (particle->children == NULL))
14689 return (1);
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000014690 /*
14691 * SPEC (2) "Its {term} is a group and the minimum part of the
14692 * effective total range of that group, [...] is 0."
14693 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014694 if (WXS_IS_MODEL_GROUP(particle->children)) {
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000014695 if (xmlSchemaGetParticleTotalRangeMin(particle) == 0)
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000014696 return (1);
14697 }
14698 return (0);
Daniel Veillard01fa6152004-06-29 17:04:39 +000014699}
14700
14701/**
14702 * xmlSchemaCheckCOSSTDerivedOK:
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000014703 * @actxt: a context
Daniel Veillard01fa6152004-06-29 17:04:39 +000014704 * @type: the derived simple type definition
14705 * @baseType: the base type definition
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000014706 * @subset: the subset of ('restriction', ect.)
Daniel Veillard01fa6152004-06-29 17:04:39 +000014707 *
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014708 * Schema Component Constraint:
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000014709 * Type Derivation OK (Simple) (cos-st-derived-OK)
14710 *
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014711 * Checks wheter @type can be validly
Daniel Veillard01fa6152004-06-29 17:04:39 +000014712 * derived from @baseType.
14713 *
14714 * Returns 0 on success, an positive error code otherwise.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014715 */
Daniel Veillard01fa6152004-06-29 17:04:39 +000014716static int
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000014717xmlSchemaCheckCOSSTDerivedOK(xmlSchemaAbstractCtxtPtr actxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014718 xmlSchemaTypePtr type,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014719 xmlSchemaTypePtr baseType,
14720 int subset)
14721{
Daniel Veillard01fa6152004-06-29 17:04:39 +000014722 /*
Daniel Veillard01fa6152004-06-29 17:04:39 +000014723 * 1 They are the same type definition.
14724 * TODO: The identy check might have to be more complex than this.
14725 */
14726 if (type == baseType)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014727 return (0);
14728 /*
Daniel Veillard01fa6152004-06-29 17:04:39 +000014729 * 2.1 restriction is not in the subset, or in the {final}
14730 * of its own {base type definition};
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000014731 *
14732 * NOTE that this will be used also via "xsi:type".
14733 *
14734 * TODO: Revise this, it looks strange. How can the "type"
14735 * not be fixed or *in* fixing?
Daniel Veillard01fa6152004-06-29 17:04:39 +000014736 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014737 if (WXS_IS_TYPE_NOT_FIXED(type))
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000014738 if (xmlSchemaTypeFixup(type, actxt) == -1)
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014739 return(-1);
14740 if (WXS_IS_TYPE_NOT_FIXED(baseType))
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000014741 if (xmlSchemaTypeFixup(baseType, actxt) == -1)
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014742 return(-1);
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000014743 if ((subset & SUBSET_RESTRICTION) ||
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014744 (xmlSchemaTypeFinalContains(type->baseType,
14745 XML_SCHEMAS_TYPE_FINAL_RESTRICTION))) {
14746 return (XML_SCHEMAP_COS_ST_DERIVED_OK_2_1);
Daniel Veillard01fa6152004-06-29 17:04:39 +000014747 }
14748 /* 2.2 */
14749 if (type->baseType == baseType) {
14750 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000014751 * 2.2.1 D's �base type definition� is B.
Daniel Veillard01fa6152004-06-29 17:04:39 +000014752 */
14753 return (0);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014754 }
14755 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000014756 * 2.2.2 D's �base type definition� is not the �ur-type definition�
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014757 * and is validly derived from B given the subset, as defined by this
14758 * constraint.
Daniel Veillard01fa6152004-06-29 17:04:39 +000014759 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014760 if ((! WXS_IS_ANYTYPE(type->baseType)) &&
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000014761 (xmlSchemaCheckCOSSTDerivedOK(actxt, type->baseType,
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000014762 baseType, subset) == 0)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014763 return (0);
14764 }
14765 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000014766 * 2.2.3 D's {variety} is list or union and B is the �simple ur-type
14767 * definition�.
Daniel Veillard01fa6152004-06-29 17:04:39 +000014768 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014769 if (WXS_IS_ANY_SIMPLE_TYPE(baseType) &&
14770 (WXS_IS_LIST(type) || WXS_IS_UNION(type))) {
Daniel Veillard01fa6152004-06-29 17:04:39 +000014771 return (0);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014772 }
14773 /*
14774 * 2.2.4 B's {variety} is union and D is validly derived from a type
14775 * definition in B's {member type definitions} given the subset, as
Daniel Veillard01fa6152004-06-29 17:04:39 +000014776 * defined by this constraint.
14777 *
14778 * NOTE: This seems not to involve built-in types, since there is no
14779 * built-in Union Simple Type.
14780 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014781 if (WXS_IS_UNION(baseType)) {
Daniel Veillard01fa6152004-06-29 17:04:39 +000014782 xmlSchemaTypeLinkPtr cur;
14783
14784 cur = baseType->memberTypes;
14785 while (cur != NULL) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014786 if (WXS_IS_TYPE_NOT_FIXED(cur->type))
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000014787 if (xmlSchemaTypeFixup(cur->type, actxt) == -1)
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014788 return(-1);
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000014789 if (xmlSchemaCheckCOSSTDerivedOK(actxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014790 type, cur->type, subset) == 0)
14791 {
14792 /*
14793 * It just has to be validly derived from at least one
14794 * member-type.
14795 */
Daniel Veillard01fa6152004-06-29 17:04:39 +000014796 return (0);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014797 }
Daniel Veillard01fa6152004-06-29 17:04:39 +000014798 cur = cur->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014799 }
Daniel Veillard01fa6152004-06-29 17:04:39 +000014800 }
Daniel Veillard01fa6152004-06-29 17:04:39 +000014801 return (XML_SCHEMAP_COS_ST_DERIVED_OK_2_2);
14802}
14803
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000014804/**
14805 * xmlSchemaCheckTypeDefCircularInternal:
14806 * @pctxt: the schema parser context
14807 * @ctxtType: the type definition
14808 * @ancestor: an ancestor of @ctxtType
14809 *
14810 * Checks st-props-correct (2) + ct-props-correct (3).
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014811 * Circular type definitions are not allowed.
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000014812 *
14813 * Returns XML_SCHEMAP_ST_PROPS_CORRECT_2 if the given type is
14814 * circular, 0 otherwise.
14815 */
14816static int
14817xmlSchemaCheckTypeDefCircularInternal(xmlSchemaParserCtxtPtr pctxt,
14818 xmlSchemaTypePtr ctxtType,
14819 xmlSchemaTypePtr ancestor)
14820{
14821 int ret;
14822
14823 if ((ancestor == NULL) || (ancestor->type == XML_SCHEMA_TYPE_BASIC))
14824 return (0);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014825
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000014826 if (ctxtType == ancestor) {
14827 xmlSchemaPCustomErr(pctxt,
14828 XML_SCHEMAP_ST_PROPS_CORRECT_2,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014829 WXS_BASIC_CAST ctxtType, WXS_ITEM_NODE(ctxtType),
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000014830 "The definition is circular", NULL);
14831 return (XML_SCHEMAP_ST_PROPS_CORRECT_2);
14832 }
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000014833 if (ancestor->flags & XML_SCHEMAS_TYPE_MARKED) {
14834 /*
14835 * Avoid inifinite recursion on circular types not yet checked.
14836 */
14837 return (0);
14838 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000014839 ancestor->flags |= XML_SCHEMAS_TYPE_MARKED;
14840 ret = xmlSchemaCheckTypeDefCircularInternal(pctxt, ctxtType,
14841 ancestor->baseType);
14842 ancestor->flags ^= XML_SCHEMAS_TYPE_MARKED;
14843 return (ret);
14844}
14845
14846/**
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000014847 * xmlSchemaCheckTypeDefCircular:
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000014848 * @item: the complex/simple type definition
14849 * @ctxt: the parser context
14850 * @name: the name
14851 *
14852 * Checks for circular type definitions.
14853 */
14854static void
14855xmlSchemaCheckTypeDefCircular(xmlSchemaTypePtr item,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000014856 xmlSchemaParserCtxtPtr ctxt)
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000014857{
14858 if ((item == NULL) ||
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014859 (item->type == XML_SCHEMA_TYPE_BASIC) ||
14860 (item->baseType == NULL))
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000014861 return;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014862 xmlSchemaCheckTypeDefCircularInternal(ctxt, item,
14863 item->baseType);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000014864}
Daniel Veillard01fa6152004-06-29 17:04:39 +000014865
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000014866/*
14867* Simple Type Definition Representation OK (src-simple-type) 4
14868*
14869* "4 Circular union type definition is disallowed. That is, if the
14870* <union> alternative is chosen, there must not be any entries in the
14871* memberTypes [attribute] at any depth which resolve to the component
14872* corresponding to the <simpleType>."
14873*
14874* Note that this should work on the *representation* of a component,
14875* thus assumes any union types in the member types not being yet
14876* substituted. At this stage we need the variety of the types
14877* to be already computed.
14878*/
14879static int
14880xmlSchemaCheckUnionTypeDefCircularRecur(xmlSchemaParserCtxtPtr pctxt,
14881 xmlSchemaTypePtr ctxType,
14882 xmlSchemaTypeLinkPtr members)
Daniel Veillarddee23482008-04-11 12:58:43 +000014883{
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000014884 xmlSchemaTypeLinkPtr member;
14885 xmlSchemaTypePtr memberType;
Daniel Veillarddee23482008-04-11 12:58:43 +000014886
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000014887 member = members;
14888 while (member != NULL) {
14889 memberType = member->type;
14890 while ((memberType != NULL) &&
14891 (memberType->type != XML_SCHEMA_TYPE_BASIC)) {
14892 if (memberType == ctxType) {
14893 xmlSchemaPCustomErr(pctxt,
14894 XML_SCHEMAP_SRC_SIMPLE_TYPE_4,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014895 WXS_BASIC_CAST ctxType, NULL,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000014896 "The union type definition is circular", NULL);
14897 return (XML_SCHEMAP_SRC_SIMPLE_TYPE_4);
14898 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014899 if ((WXS_IS_UNION(memberType)) &&
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000014900 ((memberType->flags & XML_SCHEMAS_TYPE_MARKED) == 0))
14901 {
14902 int res;
14903 memberType->flags |= XML_SCHEMAS_TYPE_MARKED;
14904 res = xmlSchemaCheckUnionTypeDefCircularRecur(pctxt,
14905 ctxType,
14906 xmlSchemaGetUnionSimpleTypeMemberTypes(memberType));
14907 memberType->flags ^= XML_SCHEMAS_TYPE_MARKED;
14908 if (res != 0)
14909 return(res);
14910 }
14911 memberType = memberType->baseType;
14912 }
14913 member = member->next;
14914 }
14915 return(0);
14916}
14917
14918static int
14919xmlSchemaCheckUnionTypeDefCircular(xmlSchemaParserCtxtPtr pctxt,
14920 xmlSchemaTypePtr type)
14921{
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014922 if (! WXS_IS_UNION(type))
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000014923 return(0);
14924 return(xmlSchemaCheckUnionTypeDefCircularRecur(pctxt, type,
14925 type->memberTypes));
14926}
14927
Daniel Veillard01fa6152004-06-29 17:04:39 +000014928/**
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000014929 * xmlSchemaResolveTypeReferences:
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000014930 * @item: the complex/simple type definition
14931 * @ctxt: the parser context
14932 * @name: the name
14933 *
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000014934 * Resolvese type definition references
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000014935 */
14936static void
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000014937xmlSchemaResolveTypeReferences(xmlSchemaTypePtr typeDef,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014938 xmlSchemaParserCtxtPtr ctxt)
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000014939{
14940 if (typeDef == NULL)
14941 return;
14942
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000014943 /*
14944 * Resolve the base type.
14945 */
14946 if (typeDef->baseType == NULL) {
14947 typeDef->baseType = xmlSchemaGetType(ctxt->schema,
14948 typeDef->base, typeDef->baseNs);
14949 if (typeDef->baseType == NULL) {
14950 xmlSchemaPResCompAttrErr(ctxt,
14951 XML_SCHEMAP_SRC_RESOLVE,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014952 WXS_BASIC_CAST typeDef, typeDef->node,
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000014953 "base", typeDef->base, typeDef->baseNs,
14954 XML_SCHEMA_TYPE_SIMPLE, NULL);
14955 return;
14956 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014957 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014958 if (WXS_IS_SIMPLE(typeDef)) {
14959 if (WXS_IS_UNION(typeDef)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014960 /*
14961 * Resolve the memberTypes.
14962 */
14963 xmlSchemaResolveUnionMemberTypes(ctxt, typeDef);
14964 return;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014965 } else if (WXS_IS_LIST(typeDef)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014966 /*
14967 * Resolve the itemType.
14968 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014969 if ((typeDef->subtypes == NULL) && (typeDef->base != NULL)) {
14970
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014971 typeDef->subtypes = xmlSchemaGetType(ctxt->schema,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014972 typeDef->base, typeDef->baseNs);
14973
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014974 if ((typeDef->subtypes == NULL) ||
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014975 (! WXS_IS_SIMPLE(typeDef->subtypes)))
14976 {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014977 typeDef->subtypes = NULL;
14978 xmlSchemaPResCompAttrErr(ctxt,
14979 XML_SCHEMAP_SRC_RESOLVE,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014980 WXS_BASIC_CAST typeDef, typeDef->node,
14981 "itemType", typeDef->base, typeDef->baseNs,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000014982 XML_SCHEMA_TYPE_SIMPLE, NULL);
14983 }
14984 }
14985 return;
14986 }
Daniel Veillarddee23482008-04-11 12:58:43 +000014987 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000014988 /*
14989 * The ball of letters below means, that if we have a particle
14990 * which has a QName-helper component as its {term}, we want
14991 * to resolve it...
14992 */
14993 else if ((WXS_TYPE_CONTENTTYPE(typeDef) != NULL) &&
14994 ((WXS_TYPE_CONTENTTYPE(typeDef))->type ==
14995 XML_SCHEMA_TYPE_PARTICLE) &&
14996 (WXS_TYPE_PARTICLE_TERM(typeDef) != NULL) &&
14997 ((WXS_TYPE_PARTICLE_TERM(typeDef))->type ==
14998 XML_SCHEMA_EXTRA_QNAMEREF))
14999 {
15000 xmlSchemaQNameRefPtr ref =
15001 WXS_QNAME_CAST WXS_TYPE_PARTICLE_TERM(typeDef);
15002 xmlSchemaModelGroupDefPtr groupDef;
15003
15004 /*
15005 * URGENT TODO: Test this.
15006 */
15007 WXS_TYPE_PARTICLE_TERM(typeDef) = NULL;
15008 /*
15009 * Resolve the MG definition reference.
15010 */
15011 groupDef =
15012 WXS_MODEL_GROUPDEF_CAST xmlSchemaGetNamedComponent(ctxt->schema,
15013 ref->itemType, ref->name, ref->targetNamespace);
15014 if (groupDef == NULL) {
15015 xmlSchemaPResCompAttrErr(ctxt, XML_SCHEMAP_SRC_RESOLVE,
15016 NULL, WXS_ITEM_NODE(WXS_TYPE_PARTICLE(typeDef)),
15017 "ref", ref->name, ref->targetNamespace, ref->itemType,
15018 NULL);
15019 /* Remove the particle. */
15020 WXS_TYPE_CONTENTTYPE(typeDef) = NULL;
15021 } else if (WXS_MODELGROUPDEF_MODEL(groupDef) == NULL)
15022 /* Remove the particle. */
15023 WXS_TYPE_CONTENTTYPE(typeDef) = NULL;
15024 else {
15025 /*
15026 * Assign the MG definition's {model group} to the
15027 * particle's {term}.
15028 */
15029 WXS_TYPE_PARTICLE_TERM(typeDef) = WXS_MODELGROUPDEF_MODEL(groupDef);
Daniel Veillarddee23482008-04-11 12:58:43 +000015030
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015031 if (WXS_MODELGROUPDEF_MODEL(groupDef)->type == XML_SCHEMA_TYPE_ALL) {
15032 /*
15033 * SPEC cos-all-limited (1.2)
15034 * "1.2 the {term} property of a particle with
15035 * {max occurs}=1 which is part of a pair which constitutes
15036 * the {content type} of a complex type definition."
15037 */
15038 if ((WXS_TYPE_PARTICLE(typeDef))->maxOccurs != 1) {
15039 xmlSchemaCustomErr(ACTXT_CAST ctxt,
15040 /* TODO: error code */
15041 XML_SCHEMAP_COS_ALL_LIMITED,
15042 WXS_ITEM_NODE(WXS_TYPE_PARTICLE(typeDef)), NULL,
15043 "The particle's {max occurs} must be 1, since the "
15044 "reference resolves to an 'all' model group",
15045 NULL, NULL);
15046 }
15047 }
15048 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015049 }
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000015050}
15051
15052
15053
15054/**
Daniel Veillard01fa6152004-06-29 17:04:39 +000015055 * xmlSchemaCheckSTPropsCorrect:
15056 * @ctxt: the schema parser context
15057 * @type: the simple type definition
15058 *
15059 * Checks st-props-correct.
15060 *
15061 * Returns 0 if the properties are correct,
15062 * if not, a positive error code and -1 on internal
15063 * errors.
15064 */
15065static int
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015066xmlSchemaCheckSTPropsCorrect(xmlSchemaParserCtxtPtr ctxt,
Daniel Veillard01fa6152004-06-29 17:04:39 +000015067 xmlSchemaTypePtr type)
15068{
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000015069 xmlSchemaTypePtr baseType = type->baseType;
Daniel Veillardc0826a72004-08-10 14:17:33 +000015070 xmlChar *str = NULL;
Daniel Veillard01fa6152004-06-29 17:04:39 +000015071
Daniel Veillardc0826a72004-08-10 14:17:33 +000015072 /* STATE: error funcs converted. */
Daniel Veillard01fa6152004-06-29 17:04:39 +000015073 /*
15074 * Schema Component Constraint: Simple Type Definition Properties Correct
15075 *
15076 * NOTE: This is somehow redundant, since we actually built a simple type
15077 * to have all the needed information; this acts as an self test.
15078 */
Rob Richardsc6947bb2008-06-29 15:04:41 +000015079 /* Base type: If the datatype has been �derived� by �restriction�
15080 * then the Simple Type Definition component from which it is �derived�,
15081 * otherwise the Simple Type Definition for anySimpleType (�4.1.6).
Daniel Veillard01fa6152004-06-29 17:04:39 +000015082 */
15083 if (baseType == NULL) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015084 /*
15085 * TODO: Think about: "modulo the impact of Missing
Rob Richardsc6947bb2008-06-29 15:04:41 +000015086 * Sub-components (�5.3)."
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015087 */
Daniel Veillardc0826a72004-08-10 14:17:33 +000015088 xmlSchemaPCustomErr(ctxt,
Daniel Veillard01fa6152004-06-29 17:04:39 +000015089 XML_SCHEMAP_ST_PROPS_CORRECT_1,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015090 WXS_BASIC_CAST type, NULL,
Daniel Veillardc0826a72004-08-10 14:17:33 +000015091 "No base type existent", NULL);
Daniel Veillard01fa6152004-06-29 17:04:39 +000015092 return (XML_SCHEMAP_ST_PROPS_CORRECT_1);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015093
Daniel Veillard01fa6152004-06-29 17:04:39 +000015094 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015095 if (! WXS_IS_SIMPLE(baseType)) {
Daniel Veillardc0826a72004-08-10 14:17:33 +000015096 xmlSchemaPCustomErr(ctxt,
Daniel Veillard01fa6152004-06-29 17:04:39 +000015097 XML_SCHEMAP_ST_PROPS_CORRECT_1,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015098 WXS_BASIC_CAST type, NULL,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015099 "The base type '%s' is not a simple type",
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015100 xmlSchemaGetComponentQName(&str, baseType));
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015101 FREE_AND_NULL(str)
Daniel Veillard01fa6152004-06-29 17:04:39 +000015102 return (XML_SCHEMAP_ST_PROPS_CORRECT_1);
15103 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015104 if ( (WXS_IS_LIST(type) || WXS_IS_UNION(type)) &&
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000015105 (WXS_IS_RESTRICTION(type) == 0) &&
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015106 (! WXS_IS_ANY_SIMPLE_TYPE(baseType))) {
Daniel Veillardc0826a72004-08-10 14:17:33 +000015107 xmlSchemaPCustomErr(ctxt,
Daniel Veillard01fa6152004-06-29 17:04:39 +000015108 XML_SCHEMAP_ST_PROPS_CORRECT_1,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015109 WXS_BASIC_CAST type, NULL,
Daniel Veillardbf9c1da2008-08-26 07:46:42 +000015110 "A type, derived by list or union, must have "
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015111 "the simple ur-type definition as base type, not '%s'",
15112 xmlSchemaGetComponentQName(&str, baseType));
Daniel Veillardc0826a72004-08-10 14:17:33 +000015113 FREE_AND_NULL(str)
Daniel Veillard01fa6152004-06-29 17:04:39 +000015114 return (XML_SCHEMAP_ST_PROPS_CORRECT_1);
15115 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015116 /*
15117 * Variety: One of {atomic, list, union}.
Daniel Veillard01fa6152004-06-29 17:04:39 +000015118 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015119 if ((! WXS_IS_ATOMIC(type)) && (! WXS_IS_UNION(type)) &&
15120 (! WXS_IS_LIST(type))) {
Daniel Veillardc0826a72004-08-10 14:17:33 +000015121 xmlSchemaPCustomErr(ctxt,
Daniel Veillard01fa6152004-06-29 17:04:39 +000015122 XML_SCHEMAP_ST_PROPS_CORRECT_1,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015123 WXS_BASIC_CAST type, NULL,
Daniel Veillardc0826a72004-08-10 14:17:33 +000015124 "The variety is absent", NULL);
Daniel Veillard01fa6152004-06-29 17:04:39 +000015125 return (XML_SCHEMAP_ST_PROPS_CORRECT_1);
15126 }
Daniel Veillardc0826a72004-08-10 14:17:33 +000015127 /* TODO: Finish this. Hmm, is this finished? */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015128
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015129 /*
15130 * 3 The {final} of the {base type definition} must not contain restriction.
15131 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015132 if (xmlSchemaTypeFinalContains(baseType,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015133 XML_SCHEMAS_TYPE_FINAL_RESTRICTION)) {
15134 xmlSchemaPCustomErr(ctxt,
15135 XML_SCHEMAP_ST_PROPS_CORRECT_3,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015136 WXS_BASIC_CAST type, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015137 "The 'final' of its base type '%s' must not contain "
15138 "'restriction'",
15139 xmlSchemaGetComponentQName(&str, baseType));
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015140 FREE_AND_NULL(str)
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015141 return (XML_SCHEMAP_ST_PROPS_CORRECT_3);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015142 }
Daniel Veillard01fa6152004-06-29 17:04:39 +000015143
15144 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000015145 * 2 All simple type definitions must be derived ultimately from the �simple
15146 * ur-type definition (so� circular definitions are disallowed). That is, it
15147 * must be possible to reach a built-in primitive datatype or the �simple
15148 * ur-type definition� by repeatedly following the {base type definition}.
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015149 *
15150 * NOTE: this is done in xmlSchemaCheckTypeDefCircular().
Daniel Veillard01fa6152004-06-29 17:04:39 +000015151 */
Daniel Veillard01fa6152004-06-29 17:04:39 +000015152 return (0);
15153}
15154
15155/**
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015156 * xmlSchemaCheckCOSSTRestricts:
Daniel Veillard01fa6152004-06-29 17:04:39 +000015157 * @ctxt: the schema parser context
15158 * @type: the simple type definition
15159 *
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000015160 * Schema Component Constraint:
15161 * Derivation Valid (Restriction, Simple) (cos-st-restricts)
15162
15163 * Checks if the given @type (simpleType) is derived validly by restriction.
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015164 * STATUS:
Daniel Veillard01fa6152004-06-29 17:04:39 +000015165 *
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015166 * Returns -1 on internal errors, 0 if the type is validly derived,
Daniel Veillard01fa6152004-06-29 17:04:39 +000015167 * a positive error code otherwise.
15168 */
15169static int
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015170xmlSchemaCheckCOSSTRestricts(xmlSchemaParserCtxtPtr pctxt,
Daniel Veillardc0826a72004-08-10 14:17:33 +000015171 xmlSchemaTypePtr type)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015172{
Daniel Veillardc0826a72004-08-10 14:17:33 +000015173 xmlChar *str = NULL;
15174
Daniel Veillard01fa6152004-06-29 17:04:39 +000015175 if (type->type != XML_SCHEMA_TYPE_SIMPLE) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015176 PERROR_INT("xmlSchemaCheckCOSSTRestricts",
15177 "given type is not a user-derived simpleType");
Daniel Veillard01fa6152004-06-29 17:04:39 +000015178 return (-1);
15179 }
15180
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015181 if (WXS_IS_ATOMIC(type)) {
Daniel Veillard01fa6152004-06-29 17:04:39 +000015182 xmlSchemaTypePtr primitive;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015183 /*
15184 * 1.1 The {base type definition} must be an atomic simple
Daniel Veillard01fa6152004-06-29 17:04:39 +000015185 * type definition or a built-in primitive datatype.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015186 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015187 if (! WXS_IS_ATOMIC(type->baseType)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015188 xmlSchemaPCustomErr(pctxt,
Daniel Veillard01fa6152004-06-29 17:04:39 +000015189 XML_SCHEMAP_COS_ST_RESTRICTS_1_1,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015190 WXS_BASIC_CAST type, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015191 "The base type '%s' is not an atomic simple type",
15192 xmlSchemaGetComponentQName(&str, type->baseType));
Daniel Veillardc0826a72004-08-10 14:17:33 +000015193 FREE_AND_NULL(str)
Daniel Veillard01fa6152004-06-29 17:04:39 +000015194 return (XML_SCHEMAP_COS_ST_RESTRICTS_1_1);
15195 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015196 /* 1.2 The {final} of the {base type definition} must not contain
Daniel Veillard01fa6152004-06-29 17:04:39 +000015197 * restriction.
15198 */
Daniel Veillardc0826a72004-08-10 14:17:33 +000015199 /* OPTIMIZE TODO : This is already done in xmlSchemaCheckStPropsCorrect */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015200 if (xmlSchemaTypeFinalContains(type->baseType,
Daniel Veillard01fa6152004-06-29 17:04:39 +000015201 XML_SCHEMAS_TYPE_FINAL_RESTRICTION)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015202 xmlSchemaPCustomErr(pctxt,
Daniel Veillard01fa6152004-06-29 17:04:39 +000015203 XML_SCHEMAP_COS_ST_RESTRICTS_1_2,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015204 WXS_BASIC_CAST type, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015205 "The final of its base type '%s' must not contain 'restriction'",
15206 xmlSchemaGetComponentQName(&str, type->baseType));
Daniel Veillardc0826a72004-08-10 14:17:33 +000015207 FREE_AND_NULL(str)
Daniel Veillard01fa6152004-06-29 17:04:39 +000015208 return (XML_SCHEMAP_COS_ST_RESTRICTS_1_2);
15209 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015210
15211 /*
Daniel Veillard01fa6152004-06-29 17:04:39 +000015212 * 1.3.1 DF must be an allowed constraining facet for the {primitive
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015213 * type definition}, as specified in the appropriate subsection of 3.2
Daniel Veillard01fa6152004-06-29 17:04:39 +000015214 * Primitive datatypes.
15215 */
15216 if (type->facets != NULL) {
15217 xmlSchemaFacetPtr facet;
15218 int ok = 1;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015219
Daniel Veillard01fa6152004-06-29 17:04:39 +000015220 primitive = xmlSchemaGetPrimitiveType(type);
15221 if (primitive == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015222 PERROR_INT("xmlSchemaCheckCOSSTRestricts",
15223 "failed to get primitive type");
Daniel Veillard01fa6152004-06-29 17:04:39 +000015224 return (-1);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015225 }
Daniel Veillard01fa6152004-06-29 17:04:39 +000015226 facet = type->facets;
15227 do {
15228 if (xmlSchemaIsBuiltInTypeFacet(primitive, facet->type) == 0) {
Daniel Veillardc0826a72004-08-10 14:17:33 +000015229 ok = 0;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015230 xmlSchemaPIllegalFacetAtomicErr(pctxt,
Daniel Veillard01fa6152004-06-29 17:04:39 +000015231 XML_SCHEMAP_COS_ST_RESTRICTS_1_3_1,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015232 type, primitive, facet);
Daniel Veillard01fa6152004-06-29 17:04:39 +000015233 }
15234 facet = facet->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015235 } while (facet != NULL);
Daniel Veillard01fa6152004-06-29 17:04:39 +000015236 if (ok == 0)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015237 return (XML_SCHEMAP_COS_ST_RESTRICTS_1_3_1);
Daniel Veillard01fa6152004-06-29 17:04:39 +000015238 }
15239 /*
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000015240 * SPEC (1.3.2) "If there is a facet of the same kind in the {facets}
15241 * of the {base type definition} (call this BF),then the DF's {value}
15242 * must be a valid restriction of BF's {value} as defined in
15243 * [XML Schemas: Datatypes]."
15244 *
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015245 * NOTE (1.3.2) Facet derivation constraints are currently handled in
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000015246 * xmlSchemaDeriveAndValidateFacets()
Daniel Veillard01fa6152004-06-29 17:04:39 +000015247 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015248 } else if (WXS_IS_LIST(type)) {
Daniel Veillard01fa6152004-06-29 17:04:39 +000015249 xmlSchemaTypePtr itemType = NULL;
15250
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015251 itemType = type->subtypes;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015252 if ((itemType == NULL) || (! WXS_IS_SIMPLE(itemType))) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015253 PERROR_INT("xmlSchemaCheckCOSSTRestricts",
15254 "failed to evaluate the item type");
Daniel Veillard01fa6152004-06-29 17:04:39 +000015255 return (-1);
15256 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015257 if (WXS_IS_TYPE_NOT_FIXED(itemType))
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000015258 xmlSchemaTypeFixup(itemType, ACTXT_CAST pctxt);
Daniel Veillard01fa6152004-06-29 17:04:39 +000015259 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015260 * 2.1 The {item type definition} must have a {variety} of atomic or
15261 * union (in which case all the {member type definitions}
Daniel Veillard01fa6152004-06-29 17:04:39 +000015262 * must be atomic).
15263 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015264 if ((! WXS_IS_ATOMIC(itemType)) &&
15265 (! WXS_IS_UNION(itemType))) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015266 xmlSchemaPCustomErr(pctxt,
Daniel Veillard01fa6152004-06-29 17:04:39 +000015267 XML_SCHEMAP_COS_ST_RESTRICTS_2_1,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015268 WXS_BASIC_CAST type, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015269 "The item type '%s' does not have a variety of atomic or union",
15270 xmlSchemaGetComponentQName(&str, itemType));
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015271 FREE_AND_NULL(str)
Daniel Veillard01fa6152004-06-29 17:04:39 +000015272 return (XML_SCHEMAP_COS_ST_RESTRICTS_2_1);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015273 } else if (WXS_IS_UNION(itemType)) {
Daniel Veillard01fa6152004-06-29 17:04:39 +000015274 xmlSchemaTypeLinkPtr member;
15275
15276 member = itemType->memberTypes;
15277 while (member != NULL) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015278 if (! WXS_IS_ATOMIC(member->type)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015279 xmlSchemaPCustomErr(pctxt,
Daniel Veillard01fa6152004-06-29 17:04:39 +000015280 XML_SCHEMAP_COS_ST_RESTRICTS_2_1,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015281 WXS_BASIC_CAST type, NULL,
Daniel Veillardc0826a72004-08-10 14:17:33 +000015282 "The item type is a union type, but the "
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015283 "member type '%s' of this item type is not atomic",
15284 xmlSchemaGetComponentQName(&str, member->type));
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015285 FREE_AND_NULL(str)
Daniel Veillard01fa6152004-06-29 17:04:39 +000015286 return (XML_SCHEMAP_COS_ST_RESTRICTS_2_1);
15287 }
15288 member = member->next;
15289 }
15290 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015291
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015292 if (WXS_IS_ANY_SIMPLE_TYPE(type->baseType)) {
Daniel Veillard01fa6152004-06-29 17:04:39 +000015293 xmlSchemaFacetPtr facet;
15294 /*
15295 * This is the case if we have: <simpleType><list ..
15296 */
15297 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015298 * 2.3.1
15299 * 2.3.1.1 The {final} of the {item type definition} must not
Daniel Veillard01fa6152004-06-29 17:04:39 +000015300 * contain list.
15301 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015302 if (xmlSchemaTypeFinalContains(itemType,
15303 XML_SCHEMAS_TYPE_FINAL_LIST)) {
15304 xmlSchemaPCustomErr(pctxt,
Daniel Veillard01fa6152004-06-29 17:04:39 +000015305 XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_1,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015306 WXS_BASIC_CAST type, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015307 "The final of its item type '%s' must not contain 'list'",
15308 xmlSchemaGetComponentQName(&str, itemType));
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015309 FREE_AND_NULL(str)
Daniel Veillard01fa6152004-06-29 17:04:39 +000015310 return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_1);
15311 }
15312 /*
15313 * 2.3.1.2 The {facets} must only contain the whiteSpace
15314 * facet component.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015315 * OPTIMIZE TODO: the S4S already disallows any facet
15316 * to be specified.
Daniel Veillard01fa6152004-06-29 17:04:39 +000015317 */
15318 if (type->facets != NULL) {
15319 facet = type->facets;
15320 do {
Daniel Veillardc0826a72004-08-10 14:17:33 +000015321 if (facet->type != XML_SCHEMA_FACET_WHITESPACE) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015322 xmlSchemaPIllegalFacetListUnionErr(pctxt,
Daniel Veillard01fa6152004-06-29 17:04:39 +000015323 XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_2,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015324 type, facet);
Daniel Veillard01fa6152004-06-29 17:04:39 +000015325 return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_2);
15326 }
15327 facet = facet->next;
15328 } while (facet != NULL);
15329 }
15330 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015331 * MAYBE TODO: (Hmm, not really) Datatypes states:
Rob Richardsc6947bb2008-06-29 15:04:41 +000015332 * A �list� datatype can be �derived� from an �atomic� datatype
15333 * whose �lexical space� allows space (such as string or anyURI)or
15334 * a �union� datatype any of whose {member type definitions}'s
15335 * �lexical space� allows space.
Daniel Veillard01fa6152004-06-29 17:04:39 +000015336 */
15337 } else {
15338 /*
15339 * This is the case if we have: <simpleType><restriction ...
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015340 * I.e. the variety of "list" is inherited.
Daniel Veillard01fa6152004-06-29 17:04:39 +000015341 */
15342 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015343 * 2.3.2
Daniel Veillard01fa6152004-06-29 17:04:39 +000015344 * 2.3.2.1 The {base type definition} must have a {variety} of list.
15345 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015346 if (! WXS_IS_LIST(type->baseType)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015347 xmlSchemaPCustomErr(pctxt,
Daniel Veillard01fa6152004-06-29 17:04:39 +000015348 XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_1,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015349 WXS_BASIC_CAST type, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015350 "The base type '%s' must be a list type",
15351 xmlSchemaGetComponentQName(&str, type->baseType));
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015352 FREE_AND_NULL(str)
Daniel Veillard01fa6152004-06-29 17:04:39 +000015353 return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_1);
15354 }
15355 /*
15356 * 2.3.2.2 The {final} of the {base type definition} must not
15357 * contain restriction.
15358 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015359 if (xmlSchemaTypeFinalContains(type->baseType,
Daniel Veillard01fa6152004-06-29 17:04:39 +000015360 XML_SCHEMAS_TYPE_FINAL_RESTRICTION)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015361 xmlSchemaPCustomErr(pctxt,
Daniel Veillard01fa6152004-06-29 17:04:39 +000015362 XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_2,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015363 WXS_BASIC_CAST type, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015364 "The 'final' of the base type '%s' must not contain 'restriction'",
15365 xmlSchemaGetComponentQName(&str, type->baseType));
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015366 FREE_AND_NULL(str)
Daniel Veillard01fa6152004-06-29 17:04:39 +000015367 return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_2);
15368 }
15369 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015370 * 2.3.2.3 The {item type definition} must be validly derived
Daniel Veillard01fa6152004-06-29 17:04:39 +000015371 * from the {base type definition}'s {item type definition} given
Rob Richardsc6947bb2008-06-29 15:04:41 +000015372 * the empty set, as defined in Type Derivation OK (Simple) (�3.14.6).
Daniel Veillard01fa6152004-06-29 17:04:39 +000015373 */
15374 {
15375 xmlSchemaTypePtr baseItemType;
15376
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015377 baseItemType = type->baseType->subtypes;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015378 if ((baseItemType == NULL) || (! WXS_IS_SIMPLE(baseItemType))) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015379 PERROR_INT("xmlSchemaCheckCOSSTRestricts",
15380 "failed to eval the item type of a base type");
Daniel Veillard01fa6152004-06-29 17:04:39 +000015381 return (-1);
15382 }
15383 if ((itemType != baseItemType) &&
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000015384 (xmlSchemaCheckCOSSTDerivedOK(ACTXT_CAST pctxt, itemType,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015385 baseItemType, 0) != 0)) {
Daniel Veillardc0826a72004-08-10 14:17:33 +000015386 xmlChar *strBIT = NULL, *strBT = NULL;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015387 xmlSchemaPCustomErrExt(pctxt,
Daniel Veillardc0826a72004-08-10 14:17:33 +000015388 XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_3,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015389 WXS_BASIC_CAST type, NULL,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015390 "The item type '%s' is not validly derived from "
15391 "the item type '%s' of the base type '%s'",
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015392 xmlSchemaGetComponentQName(&str, itemType),
15393 xmlSchemaGetComponentQName(&strBIT, baseItemType),
15394 xmlSchemaGetComponentQName(&strBT, type->baseType));
Daniel Veillardc0826a72004-08-10 14:17:33 +000015395
15396 FREE_AND_NULL(str)
15397 FREE_AND_NULL(strBIT)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015398 FREE_AND_NULL(strBT)
Daniel Veillard01fa6152004-06-29 17:04:39 +000015399 return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_3);
15400 }
15401 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015402
Daniel Veillard01fa6152004-06-29 17:04:39 +000015403 if (type->facets != NULL) {
15404 xmlSchemaFacetPtr facet;
15405 int ok = 1;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015406 /*
15407 * 2.3.2.4 Only length, minLength, maxLength, whiteSpace, pattern
Daniel Veillard01fa6152004-06-29 17:04:39 +000015408 * and enumeration facet components are allowed among the {facets}.
15409 */
15410 facet = type->facets;
15411 do {
15412 switch (facet->type) {
15413 case XML_SCHEMA_FACET_LENGTH:
15414 case XML_SCHEMA_FACET_MINLENGTH:
15415 case XML_SCHEMA_FACET_MAXLENGTH:
15416 case XML_SCHEMA_FACET_WHITESPACE:
15417 /*
15418 * TODO: 2.5.1.2 List datatypes
Rob Richardsc6947bb2008-06-29 15:04:41 +000015419 * The value of �whiteSpace� is fixed to the value collapse.
Daniel Veillard01fa6152004-06-29 17:04:39 +000015420 */
15421 case XML_SCHEMA_FACET_PATTERN:
15422 case XML_SCHEMA_FACET_ENUMERATION:
15423 break;
15424 default: {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015425 xmlSchemaPIllegalFacetListUnionErr(pctxt,
Daniel Veillard01fa6152004-06-29 17:04:39 +000015426 XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_4,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015427 type, facet);
Daniel Veillard01fa6152004-06-29 17:04:39 +000015428 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015429 * We could return, but it's nicer to report all
Daniel Veillard01fa6152004-06-29 17:04:39 +000015430 * invalid facets.
15431 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015432 ok = 0;
Daniel Veillard01fa6152004-06-29 17:04:39 +000015433 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015434 }
Daniel Veillard01fa6152004-06-29 17:04:39 +000015435 facet = facet->next;
15436 } while (facet != NULL);
15437 if (ok == 0)
15438 return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_4);
15439 /*
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000015440 * SPEC (2.3.2.5) (same as 1.3.2)
15441 *
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015442 * NOTE (2.3.2.5) This is currently done in
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000015443 * xmlSchemaDeriveAndValidateFacets()
Daniel Veillard01fa6152004-06-29 17:04:39 +000015444 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015445 }
Daniel Veillard01fa6152004-06-29 17:04:39 +000015446 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015447 } else if (WXS_IS_UNION(type)) {
Daniel Veillard01fa6152004-06-29 17:04:39 +000015448 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015449 * 3.1 The {member type definitions} must all have {variety} of
Daniel Veillard01fa6152004-06-29 17:04:39 +000015450 * atomic or list.
15451 */
15452 xmlSchemaTypeLinkPtr member;
15453
15454 member = type->memberTypes;
15455 while (member != NULL) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015456 if (WXS_IS_TYPE_NOT_FIXED(member->type))
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000015457 xmlSchemaTypeFixup(member->type, ACTXT_CAST pctxt);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015458
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015459 if ((! WXS_IS_ATOMIC(member->type)) &&
15460 (! WXS_IS_LIST(member->type))) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015461 xmlSchemaPCustomErr(pctxt,
Daniel Veillard01fa6152004-06-29 17:04:39 +000015462 XML_SCHEMAP_COS_ST_RESTRICTS_3_1,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015463 WXS_BASIC_CAST type, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015464 "The member type '%s' is neither an atomic, nor a list type",
15465 xmlSchemaGetComponentQName(&str, member->type));
Daniel Veillardc0826a72004-08-10 14:17:33 +000015466 FREE_AND_NULL(str)
Daniel Veillard01fa6152004-06-29 17:04:39 +000015467 return (XML_SCHEMAP_COS_ST_RESTRICTS_3_1);
15468 }
15469 member = member->next;
15470 }
15471 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000015472 * 3.3.1 If the {base type definition} is the �simple ur-type
15473 * definition�
Daniel Veillard01fa6152004-06-29 17:04:39 +000015474 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015475 if (type->baseType->builtInType == XML_SCHEMAS_ANYSIMPLETYPE) {
Daniel Veillard01fa6152004-06-29 17:04:39 +000015476 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015477 * 3.3.1.1 All of the {member type definitions} must have a
Daniel Veillard01fa6152004-06-29 17:04:39 +000015478 * {final} which does not contain union.
15479 */
15480 member = type->memberTypes;
15481 while (member != NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015482 if (xmlSchemaTypeFinalContains(member->type,
Daniel Veillard01fa6152004-06-29 17:04:39 +000015483 XML_SCHEMAS_TYPE_FINAL_UNION)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015484 xmlSchemaPCustomErr(pctxt,
Daniel Veillard01fa6152004-06-29 17:04:39 +000015485 XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015486 WXS_BASIC_CAST type, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015487 "The 'final' of member type '%s' contains 'union'",
15488 xmlSchemaGetComponentQName(&str, member->type));
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015489 FREE_AND_NULL(str)
Daniel Veillard01fa6152004-06-29 17:04:39 +000015490 return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1);
15491 }
15492 member = member->next;
15493 }
15494 /*
15495 * 3.3.1.2 The {facets} must be empty.
15496 */
15497 if (type->facetSet != NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015498 xmlSchemaPCustomErr(pctxt,
Daniel Veillard01fa6152004-06-29 17:04:39 +000015499 XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1_2,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015500 WXS_BASIC_CAST type, NULL,
Daniel Veillardc0826a72004-08-10 14:17:33 +000015501 "No facets allowed", NULL);
Daniel Veillard01fa6152004-06-29 17:04:39 +000015502 return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1_2);
15503 }
15504 } else {
15505 /*
15506 * 3.3.2.1 The {base type definition} must have a {variety} of union.
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015507 * I.e. the variety of "list" is inherited.
Daniel Veillard01fa6152004-06-29 17:04:39 +000015508 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015509 if (! WXS_IS_UNION(type->baseType)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015510 xmlSchemaPCustomErr(pctxt,
Daniel Veillard01fa6152004-06-29 17:04:39 +000015511 XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_1,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015512 WXS_BASIC_CAST type, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015513 "The base type '%s' is not a union type",
15514 xmlSchemaGetComponentQName(&str, type->baseType));
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015515 FREE_AND_NULL(str)
Daniel Veillard01fa6152004-06-29 17:04:39 +000015516 return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_1);
15517 }
15518 /*
15519 * 3.3.2.2 The {final} of the {base type definition} must not contain restriction.
15520 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015521 if (xmlSchemaTypeFinalContains(type->baseType,
Daniel Veillard01fa6152004-06-29 17:04:39 +000015522 XML_SCHEMAS_TYPE_FINAL_RESTRICTION)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015523 xmlSchemaPCustomErr(pctxt,
Daniel Veillard01fa6152004-06-29 17:04:39 +000015524 XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_2,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015525 WXS_BASIC_CAST type, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015526 "The 'final' of its base type '%s' must not contain 'restriction'",
15527 xmlSchemaGetComponentQName(&str, type->baseType));
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015528 FREE_AND_NULL(str)
Daniel Veillard01fa6152004-06-29 17:04:39 +000015529 return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_2);
15530 }
15531 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015532 * 3.3.2.3 The {member type definitions}, in order, must be validly
15533 * derived from the corresponding type definitions in the {base
15534 * type definition}'s {member type definitions} given the empty set,
Rob Richardsc6947bb2008-06-29 15:04:41 +000015535 * as defined in Type Derivation OK (Simple) (�3.14.6).
Daniel Veillard01fa6152004-06-29 17:04:39 +000015536 */
15537 {
15538 xmlSchemaTypeLinkPtr baseMember;
15539
15540 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015541 * OPTIMIZE: if the type is restricting, it has no local defined
15542 * member types and inherits the member types of the base type;
Daniel Veillard01fa6152004-06-29 17:04:39 +000015543 * thus a check for equality can be skipped.
15544 */
15545 /*
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000015546 * Even worse: I cannot see a scenario where a restricting
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015547 * union simple type can have other member types as the member
Daniel Veillard01fa6152004-06-29 17:04:39 +000015548 * types of it's base type. This check seems not necessary with
15549 * respect to the derivation process in libxml2.
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000015550 * But necessary if constructing types with an API.
Daniel Veillard01fa6152004-06-29 17:04:39 +000015551 */
15552 if (type->memberTypes != NULL) {
15553 member = type->memberTypes;
15554 baseMember = xmlSchemaGetUnionSimpleTypeMemberTypes(type->baseType);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015555 if ((member == NULL) && (baseMember != NULL)) {
15556 PERROR_INT("xmlSchemaCheckCOSSTRestricts",
15557 "different number of member types in base");
15558 }
Daniel Veillard01fa6152004-06-29 17:04:39 +000015559 while (member != NULL) {
15560 if (baseMember == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015561 PERROR_INT("xmlSchemaCheckCOSSTRestricts",
15562 "different number of member types in base");
Daniel Veillard14b56432006-03-09 18:41:40 +000015563 } else if ((member->type != baseMember->type) &&
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000015564 (xmlSchemaCheckCOSSTDerivedOK(ACTXT_CAST pctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015565 member->type, baseMember->type, 0) != 0)) {
Daniel Veillardc0826a72004-08-10 14:17:33 +000015566 xmlChar *strBMT = NULL, *strBT = NULL;
15567
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015568 xmlSchemaPCustomErrExt(pctxt,
Daniel Veillardc0826a72004-08-10 14:17:33 +000015569 XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_3,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015570 WXS_BASIC_CAST type, NULL,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015571 "The member type %s is not validly "
15572 "derived from its corresponding member "
15573 "type %s of the base type %s",
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015574 xmlSchemaGetComponentQName(&str, member->type),
15575 xmlSchemaGetComponentQName(&strBMT, baseMember->type),
15576 xmlSchemaGetComponentQName(&strBT, type->baseType));
Daniel Veillardc0826a72004-08-10 14:17:33 +000015577 FREE_AND_NULL(str)
15578 FREE_AND_NULL(strBMT)
15579 FREE_AND_NULL(strBT)
Daniel Veillard01fa6152004-06-29 17:04:39 +000015580 return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_3);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015581 }
Daniel Veillard01fa6152004-06-29 17:04:39 +000015582 member = member->next;
15583 baseMember = baseMember->next;
15584 }
15585 }
15586 }
15587 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015588 * 3.3.2.4 Only pattern and enumeration facet components are
Daniel Veillard01fa6152004-06-29 17:04:39 +000015589 * allowed among the {facets}.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015590 */
Daniel Veillard01fa6152004-06-29 17:04:39 +000015591 if (type->facets != NULL) {
15592 xmlSchemaFacetPtr facet;
15593 int ok = 1;
15594
15595 facet = type->facets;
15596 do {
15597 if ((facet->type != XML_SCHEMA_FACET_PATTERN) &&
15598 (facet->type != XML_SCHEMA_FACET_ENUMERATION)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015599 xmlSchemaPIllegalFacetListUnionErr(pctxt,
Daniel Veillardc0826a72004-08-10 14:17:33 +000015600 XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_4,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015601 type, facet);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015602 ok = 0;
15603 }
Daniel Veillard01fa6152004-06-29 17:04:39 +000015604 facet = facet->next;
15605 } while (facet != NULL);
15606 if (ok == 0)
15607 return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_4);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015608
Daniel Veillard01fa6152004-06-29 17:04:39 +000015609 }
15610 /*
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000015611 * SPEC (3.3.2.5) (same as 1.3.2)
15612 *
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015613 * NOTE (3.3.2.5) This is currently done in
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000015614 * xmlSchemaDeriveAndValidateFacets()
Daniel Veillard01fa6152004-06-29 17:04:39 +000015615 */
15616 }
15617 }
15618
15619 return (0);
15620}
15621
15622/**
15623 * xmlSchemaCheckSRCSimpleType:
15624 * @ctxt: the schema parser context
15625 * @type: the simple type definition
15626 *
Daniel Veillarddee23482008-04-11 12:58:43 +000015627 * Checks crc-simple-type constraints.
Daniel Veillard01fa6152004-06-29 17:04:39 +000015628 *
15629 * Returns 0 if the constraints are satisfied,
15630 * if not a positive error code and -1 on internal
15631 * errors.
15632 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000015633#if 0
Daniel Veillard01fa6152004-06-29 17:04:39 +000015634static int
15635xmlSchemaCheckSRCSimpleType(xmlSchemaParserCtxtPtr ctxt,
15636 xmlSchemaTypePtr type)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015637{
15638 /*
Daniel Veillard01fa6152004-06-29 17:04:39 +000015639 * src-simple-type.1 The corresponding simple type definition, if any,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015640 * must satisfy the conditions set out in Constraints on Simple Type
Rob Richardsc6947bb2008-06-29 15:04:41 +000015641 * Definition Schema Components (�3.14.6).
Daniel Veillarddee23482008-04-11 12:58:43 +000015642 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000015643 if (WXS_IS_RESTRICTION(type)) {
Daniel Veillard01fa6152004-06-29 17:04:39 +000015644 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000015645 * src-simple-type.2 "If the <restriction> alternative is chosen,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015646 * either it must have a base [attribute] or a <simpleType> among its
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000015647 * [children], but not both."
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015648 * NOTE: This is checked in the parse function of <restriction>.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015649 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000015650 /*
Daniel Veillarddee23482008-04-11 12:58:43 +000015651 *
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000015652 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015653 } else if (WXS_IS_LIST(type)) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000015654 /* src-simple-type.3 "If the <list> alternative is chosen, either it must have
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015655 * an itemType [attribute] or a <simpleType> among its [children],
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000015656 * but not both."
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015657 *
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000015658 * NOTE: This is checked in the parse function of <list>.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015659 */
Daniel Veillarddee23482008-04-11 12:58:43 +000015660 } else if (WXS_IS_UNION(type)) {
15661 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000015662 * src-simple-type.4 is checked in xmlSchemaCheckUnionTypeDefCircular().
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015663 */
Daniel Veillard01fa6152004-06-29 17:04:39 +000015664 }
Daniel Veillard01fa6152004-06-29 17:04:39 +000015665 return (0);
15666}
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000015667#endif
Daniel Veillard01fa6152004-06-29 17:04:39 +000015668
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000015669static int
15670xmlSchemaCreateVCtxtOnPCtxt(xmlSchemaParserCtxtPtr ctxt)
15671{
15672 if (ctxt->vctxt == NULL) {
15673 ctxt->vctxt = xmlSchemaNewValidCtxt(NULL);
15674 if (ctxt->vctxt == NULL) {
15675 xmlSchemaPErr(ctxt, NULL,
Kasimier T. Buchcikbea23542004-08-25 20:35:45 +000015676 XML_SCHEMAP_INTERNAL,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015677 "Internal error: xmlSchemaCreateVCtxtOnPCtxt, "
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000015678 "failed to create a temp. validation context.\n",
15679 NULL, NULL);
15680 return (-1);
15681 }
15682 /* TODO: Pass user data. */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000015683 xmlSchemaSetValidErrors(ctxt->vctxt,
Kasimier T. Buchcik90b5ebc2005-11-18 17:18:27 +000015684 ctxt->error, ctxt->warning, ctxt->errCtxt);
15685 xmlSchemaSetValidStructuredErrors(ctxt->vctxt,
15686 ctxt->serror, ctxt->errCtxt);
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000015687 }
15688 return (0);
15689}
15690
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015691static int
15692xmlSchemaVCheckCVCSimpleType(xmlSchemaAbstractCtxtPtr actxt,
15693 xmlNodePtr node,
15694 xmlSchemaTypePtr type,
15695 const xmlChar *value,
15696 xmlSchemaValPtr *retVal,
15697 int fireErrors,
15698 int normalize,
15699 int isNormalized);
15700
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000015701/**
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015702 * xmlSchemaParseCheckCOSValidDefault:
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015703 * @pctxt: the schema parser context
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000015704 * @type: the simple type definition
15705 * @value: the default value
15706 * @node: an optional node (the holder of the value)
15707 *
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015708 * Schema Component Constraint: Element Default Valid (Immediate)
15709 * (cos-valid-default)
15710 * This will be used by the parser only. For the validator there's
15711 * an other version.
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000015712 *
15713 * Returns 0 if the constraints are satisfied,
15714 * if not, a positive error code and -1 on internal
15715 * errors.
15716 */
15717static int
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015718xmlSchemaParseCheckCOSValidDefault(xmlSchemaParserCtxtPtr pctxt,
15719 xmlNodePtr node,
15720 xmlSchemaTypePtr type,
15721 const xmlChar *value,
15722 xmlSchemaValPtr *val)
15723{
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000015724 int ret = 0;
15725
15726 /*
15727 * cos-valid-default:
15728 * Schema Component Constraint: Element Default Valid (Immediate)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015729 * For a string to be a valid default with respect to a type
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000015730 * definition the appropriate case among the following must be true:
15731 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015732 if WXS_IS_COMPLEX(type) {
William M. Brack2f2a6632004-08-20 23:09:47 +000015733 /*
15734 * Complex type.
15735 *
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000015736 * SPEC (2.1) "its {content type} must be a simple type definition
15737 * or mixed."
15738 * SPEC (2.2.2) "If the {content type} is mixed, then the {content
Rob Richardsc6947bb2008-06-29 15:04:41 +000015739 * type}'s particle must be �emptiable� as defined by
15740 * Particle Emptiable (�3.9.6)."
William M. Brack2f2a6632004-08-20 23:09:47 +000015741 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015742 if ((! WXS_HAS_SIMPLE_CONTENT(type)) &&
15743 ((! WXS_HAS_MIXED_CONTENT(type)) || (! WXS_EMPTIABLE(type)))) {
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000015744 /* NOTE that this covers (2.2.2) as well. */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015745 xmlSchemaPCustomErr(pctxt,
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000015746 XML_SCHEMAP_COS_VALID_DEFAULT_2_1,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015747 WXS_BASIC_CAST type, type->node,
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000015748 "For a string to be a valid default, the type definition "
15749 "must be a simple type or a complex type with mixed content "
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015750 "and a particle emptiable", NULL);
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000015751 return(XML_SCHEMAP_COS_VALID_DEFAULT_2_1);
15752 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015753 }
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000015754 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015755 * 1 If the type definition is a simple type definition, then the string
Rob Richardsc6947bb2008-06-29 15:04:41 +000015756 * must be �valid� with respect to that definition as defined by String
15757 * Valid (�3.14.4).
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000015758 *
15759 * AND
15760 *
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015761 * 2.2.1 If the {content type} is a simple type definition, then the
Rob Richardsc6947bb2008-06-29 15:04:41 +000015762 * string must be �valid� with respect to that simple type definition
15763 * as defined by String Valid (�3.14.4).
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015764 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015765 if (WXS_IS_SIMPLE(type))
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000015766 ret = xmlSchemaVCheckCVCSimpleType(ACTXT_CAST pctxt, node,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015767 type, value, val, 1, 1, 0);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015768 else if (WXS_HAS_SIMPLE_CONTENT(type))
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000015769 ret = xmlSchemaVCheckCVCSimpleType(ACTXT_CAST pctxt, node,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015770 type->contentTypeDef, value, val, 1, 1, 0);
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000015771 else
15772 return (ret);
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000015773
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015774 if (ret < 0) {
15775 PERROR_INT("xmlSchemaParseCheckCOSValidDefault",
15776 "calling xmlSchemaVCheckCVCSimpleType()");
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000015777 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015778
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000015779 return (ret);
William M. Brack2f2a6632004-08-20 23:09:47 +000015780}
15781
15782/**
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015783 * xmlSchemaCheckCTPropsCorrect:
William M. Brack2f2a6632004-08-20 23:09:47 +000015784 * @ctxt: the schema parser context
15785 * @type: the complex type definition
15786 *
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015787 *.(4.6) Constraints on Complex Type Definition Schema Components
15788 * Schema Component Constraint:
15789 * Complex Type Definition Properties Correct (ct-props-correct)
15790 * STATUS: (seems) complete
William M. Brack2f2a6632004-08-20 23:09:47 +000015791 *
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015792 * Returns 0 if the constraints are satisfied, a positive
15793 * error code if not and -1 if an internal error occured.
William M. Brack2f2a6632004-08-20 23:09:47 +000015794 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015795static int
15796xmlSchemaCheckCTPropsCorrect(xmlSchemaParserCtxtPtr pctxt,
15797 xmlSchemaTypePtr type)
William M. Brack2f2a6632004-08-20 23:09:47 +000015798{
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015799 /*
15800 * TODO: Correct the error code; XML_SCHEMAP_SRC_CT_1 is used temporarily.
15801 *
15802 * SPEC (1) "The values of the properties of a complex type definition must
15803 * be as described in the property tableau in The Complex Type Definition
Rob Richardsc6947bb2008-06-29 15:04:41 +000015804 * Schema Component (�3.4.1), modulo the impact of Missing
15805 * Sub-components (�5.3)."
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015806 */
15807 if ((type->baseType != NULL) &&
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015808 (WXS_IS_SIMPLE(type->baseType)) &&
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000015809 (WXS_IS_EXTENSION(type) == 0)) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015810 /*
15811 * SPEC (2) "If the {base type definition} is a simple type definition,
15812 * the {derivation method} must be extension."
15813 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015814 xmlSchemaCustomErr(ACTXT_CAST pctxt,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015815 XML_SCHEMAP_SRC_CT_1,
Daniel Veillarddee23482008-04-11 12:58:43 +000015816 NULL, WXS_BASIC_CAST type,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015817 "If the base type is a simple type, the derivation method must be "
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015818 "'extension'", NULL, NULL);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015819 return (XML_SCHEMAP_SRC_CT_1);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015820 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015821 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000015822 * SPEC (3) "Circular definitions are disallowed, except for the �ur-type
15823 * definition�. That is, it must be possible to reach the �ur-type
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015824 * definition by repeatedly following the {base type definition}."
15825 *
15826 * NOTE (3) is done in xmlSchemaCheckTypeDefCircular().
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015827 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015828 /*
15829 * NOTE that (4) and (5) need the following:
15830 * - attribute uses need to be already inherited (apply attr. prohibitions)
15831 * - attribute group references need to be expanded already
15832 * - simple types need to be typefixed already
Daniel Veillarddee23482008-04-11 12:58:43 +000015833 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015834 if (type->attrUses &&
15835 (((xmlSchemaItemListPtr) type->attrUses)->nbItems > 1))
15836 {
15837 xmlSchemaItemListPtr uses = (xmlSchemaItemListPtr) type->attrUses;
15838 xmlSchemaAttributeUsePtr use, tmp;
15839 int i, j, hasId = 0;
15840
15841 for (i = uses->nbItems -1; i >= 0; i--) {
15842 use = uses->items[i];
Daniel Veillarddee23482008-04-11 12:58:43 +000015843
15844 /*
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015845 * SPEC ct-props-correct
15846 * (4) "Two distinct attribute declarations in the
15847 * {attribute uses} must not have identical {name}s and
15848 * {target namespace}s."
15849 */
15850 if (i > 0) {
15851 for (j = i -1; j >= 0; j--) {
15852 tmp = uses->items[j];
15853 if ((WXS_ATTRUSE_DECL_NAME(use) ==
15854 WXS_ATTRUSE_DECL_NAME(tmp)) &&
15855 (WXS_ATTRUSE_DECL_TNS(use) ==
15856 WXS_ATTRUSE_DECL_TNS(tmp)))
15857 {
15858 xmlChar *str = NULL;
15859
15860 xmlSchemaCustomErr(ACTXT_CAST pctxt,
15861 XML_SCHEMAP_AG_PROPS_CORRECT,
15862 NULL, WXS_BASIC_CAST type,
15863 "Duplicate %s",
15864 xmlSchemaGetComponentDesignation(&str, use),
15865 NULL);
15866 FREE_AND_NULL(str);
15867 /*
15868 * Remove the duplicate.
15869 */
15870 if (xmlSchemaItemListRemove(uses, i) == -1)
15871 goto exit_failure;
15872 goto next_use;
15873 }
15874 }
15875 }
15876 /*
15877 * SPEC ct-props-correct
15878 * (5) "Two distinct attribute declarations in the
15879 * {attribute uses} must not have {type definition}s which
15880 * are or are derived from ID."
15881 */
15882 if (WXS_ATTRUSE_TYPEDEF(use) != NULL) {
15883 if (xmlSchemaIsDerivedFromBuiltInType(
15884 WXS_ATTRUSE_TYPEDEF(use), XML_SCHEMAS_ID))
Daniel Veillarddee23482008-04-11 12:58:43 +000015885 {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015886 if (hasId) {
15887 xmlChar *str = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000015888
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015889 xmlSchemaCustomErr(ACTXT_CAST pctxt,
15890 XML_SCHEMAP_AG_PROPS_CORRECT,
15891 NULL, WXS_BASIC_CAST type,
15892 "There must not exist more than one attribute "
15893 "declaration of type 'xs:ID' "
15894 "(or derived from 'xs:ID'). The %s violates this "
15895 "constraint",
15896 xmlSchemaGetComponentDesignation(&str, use),
15897 NULL);
15898 FREE_AND_NULL(str);
15899 if (xmlSchemaItemListRemove(uses, i) == -1)
15900 goto exit_failure;
15901 }
Daniel Veillarddee23482008-04-11 12:58:43 +000015902
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015903 hasId = 1;
15904 }
15905 }
15906next_use: {}
15907 }
15908 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000015909 return (0);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015910exit_failure:
15911 return(-1);
William M. Brack2f2a6632004-08-20 23:09:47 +000015912}
15913
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000015914static int
15915xmlSchemaAreEqualTypes(xmlSchemaTypePtr typeA,
15916 xmlSchemaTypePtr typeB)
15917{
15918 /*
15919 * TODO: This should implement component-identity
15920 * in the future.
15921 */
15922 if ((typeA == NULL) || (typeB == NULL))
15923 return (0);
15924 return (typeA == typeB);
15925}
15926
15927/**
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000015928 * xmlSchemaCheckCOSCTDerivedOK:
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000015929 * @ctxt: the schema parser context
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000015930 * @type: the to-be derived complex type definition
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000015931 * @baseType: the base complex type definition
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000015932 * @set: the given set
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000015933 *
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015934 * Schema Component Constraint:
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000015935 * Type Derivation OK (Complex) (cos-ct-derived-ok)
15936 *
15937 * STATUS: completed
15938 *
15939 * Returns 0 if the constraints are satisfied, or 1
15940 * if not.
15941 */
15942static int
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000015943xmlSchemaCheckCOSCTDerivedOK(xmlSchemaAbstractCtxtPtr actxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015944 xmlSchemaTypePtr type,
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000015945 xmlSchemaTypePtr baseType,
15946 int set)
15947{
15948 int equal = xmlSchemaAreEqualTypes(type, baseType);
15949 /* TODO: Error codes. */
15950 /*
15951 * SPEC "For a complex type definition (call it D, for derived)
15952 * to be validly derived from a type definition (call this
15953 * B, for base) given a subset of {extension, restriction}
15954 * all of the following must be true:"
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015955 */
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000015956 if (! equal) {
15957 /*
15958 * SPEC (1) "If B and D are not the same type definition, then the
15959 * {derivation method} of D must not be in the subset."
15960 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000015961 if (((set & SUBSET_EXTENSION) && (WXS_IS_EXTENSION(type))) ||
15962 ((set & SUBSET_RESTRICTION) && (WXS_IS_RESTRICTION(type))))
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000015963 return (1);
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000015964 } else {
15965 /*
15966 * SPEC (2.1) "B and D must be the same type definition."
15967 */
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000015968 return (0);
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000015969 }
15970 /*
15971 * SPEC (2.2) "B must be D's {base type definition}."
15972 */
15973 if (type->baseType == baseType)
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000015974 return (0);
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000015975 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000015976 * SPEC (2.3.1) "D's {base type definition} must not be the �ur-type
15977 * definition�."
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000015978 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015979 if (WXS_IS_ANYTYPE(type->baseType))
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000015980 return (1);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015981
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015982 if (WXS_IS_COMPLEX(type->baseType)) {
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000015983 /*
15984 * SPEC (2.3.2.1) "If D's {base type definition} is complex, then it
15985 * must be validly derived from B given the subset as defined by this
15986 * constraint."
15987 */
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000015988 return (xmlSchemaCheckCOSCTDerivedOK(actxt, type->baseType,
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000015989 baseType, set));
15990 } else {
15991 /*
15992 * SPEC (2.3.2.2) "If D's {base type definition} is simple, then it
15993 * must be validly derived from B given the subset as defined in Type
Rob Richardsc6947bb2008-06-29 15:04:41 +000015994 * Derivation OK (Simple) (�3.14.6).
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000015995 */
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000015996 return (xmlSchemaCheckCOSSTDerivedOK(actxt, type->baseType,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000015997 baseType, set));
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000015998 }
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000015999}
16000
16001/**
16002 * xmlSchemaCheckCOSDerivedOK:
16003 * @type: the derived simple type definition
16004 * @baseType: the base type definition
16005 *
16006 * Calls:
16007 * Type Derivation OK (Simple) AND Type Derivation OK (Complex)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016008 *
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000016009 * Checks wheter @type can be validly derived from @baseType.
16010 *
16011 * Returns 0 on success, an positive error code otherwise.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016012 */
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000016013static int
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000016014xmlSchemaCheckCOSDerivedOK(xmlSchemaAbstractCtxtPtr actxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016015 xmlSchemaTypePtr type,
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000016016 xmlSchemaTypePtr baseType,
16017 int set)
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000016018{
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016019 if (WXS_IS_SIMPLE(type))
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000016020 return (xmlSchemaCheckCOSSTDerivedOK(actxt, type, baseType, set));
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000016021 else
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000016022 return (xmlSchemaCheckCOSCTDerivedOK(actxt, type, baseType, set));
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000016023}
16024
William M. Brack2f2a6632004-08-20 23:09:47 +000016025/**
16026 * xmlSchemaCheckCOSCTExtends:
16027 * @ctxt: the schema parser context
16028 * @type: the complex type definition
16029 *
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016030 * (3.4.6) Constraints on Complex Type Definition Schema Components
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016031 * Schema Component Constraint:
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016032 * Derivation Valid (Extension) (cos-ct-extends)
16033 *
16034 * STATUS:
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016035 * missing:
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016036 * (1.5)
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016037 * (1.4.3.2.2.2) "Particle Valid (Extension)"
William M. Brack2f2a6632004-08-20 23:09:47 +000016038 *
16039 * Returns 0 if the constraints are satisfied, a positive
16040 * error code if not and -1 if an internal error occured.
16041 */
16042static int
16043xmlSchemaCheckCOSCTExtends(xmlSchemaParserCtxtPtr ctxt,
16044 xmlSchemaTypePtr type)
16045{
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016046 xmlSchemaTypePtr base = type->baseType;
16047 /*
16048 * TODO: Correct the error code; XML_SCHEMAP_COS_CT_EXTENDS_1_1 is used
16049 * temporarily only.
William M. Brack2f2a6632004-08-20 23:09:47 +000016050 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016051 /*
16052 * SPEC (1) "If the {base type definition} is a complex type definition,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016053 * then all of the following must be true:"
16054 */
Daniel Veillarddee23482008-04-11 12:58:43 +000016055 if (WXS_IS_COMPLEX(base)) {
William M. Brack2f2a6632004-08-20 23:09:47 +000016056 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016057 * SPEC (1.1) "The {final} of the {base type definition} must not
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016058 * contain extension."
William M. Brack2f2a6632004-08-20 23:09:47 +000016059 */
16060 if (base->flags & XML_SCHEMAS_TYPE_FINAL_EXTENSION) {
16061 xmlSchemaPCustomErr(ctxt,
16062 XML_SCHEMAP_COS_CT_EXTENDS_1_1,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016063 WXS_BASIC_CAST type, NULL,
William M. Brack2f2a6632004-08-20 23:09:47 +000016064 "The 'final' of the base type definition "
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016065 "contains 'extension'", NULL);
William M. Brack2f2a6632004-08-20 23:09:47 +000016066 return (XML_SCHEMAP_COS_CT_EXTENDS_1_1);
16067 }
Daniel Veillarddee23482008-04-11 12:58:43 +000016068
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016069 /*
16070 * ATTENTION: The constrains (1.2) and (1.3) are not applied,
16071 * since they are automatically satisfied through the
16072 * inheriting mechanism.
16073 * Note that even if redefining components, the inheriting mechanism
16074 * is used.
16075 */
16076#if 0
William M. Brack2f2a6632004-08-20 23:09:47 +000016077 /*
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016078 * SPEC (1.2) "Its {attribute uses} must be a subset of the {attribute
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016079 * uses}
16080 * of the complex type definition itself, that is, for every attribute
16081 * use in the {attribute uses} of the {base type definition}, there
16082 * must be an attribute use in the {attribute uses} of the complex
16083 * type definition itself whose {attribute declaration} has the same
16084 * {name}, {target namespace} and {type definition} as its attribute
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016085 * declaration"
William M. Brack2f2a6632004-08-20 23:09:47 +000016086 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016087 if (base->attrUses != NULL) {
16088 int i, j, found;
16089 xmlSchemaAttributeUsePtr use, buse;
William M. Brack2f2a6632004-08-20 23:09:47 +000016090
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016091 for (i = 0; i < (WXS_LIST_CAST base->attrUses)->nbItems; i ++) {
16092 buse = (WXS_LIST_CAST base->attrUses)->items[i];
16093 found = 0;
16094 if (type->attrUses != NULL) {
16095 use = (WXS_LIST_CAST type->attrUses)->items[j];
16096 for (j = 0; j < (WXS_LIST_CAST type->attrUses)->nbItems; j ++)
16097 {
16098 if ((WXS_ATTRUSE_DECL_NAME(use) ==
16099 WXS_ATTRUSE_DECL_NAME(buse)) &&
16100 (WXS_ATTRUSE_DECL_TNS(use) ==
16101 WXS_ATTRUSE_DECL_TNS(buse)) &&
16102 (WXS_ATTRUSE_TYPEDEF(use) ==
16103 WXS_ATTRUSE_TYPEDEF(buse))
16104 {
16105 found = 1;
16106 break;
16107 }
16108 }
16109 }
16110 if (! found) {
16111 xmlChar *str = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000016112
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016113 xmlSchemaCustomErr(ACTXT_CAST ctxt,
16114 XML_SCHEMAP_COS_CT_EXTENDS_1_2,
16115 NULL, WXS_BASIC_CAST type,
Daniel Veillarddee23482008-04-11 12:58:43 +000016116 /*
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016117 * TODO: The report does not indicate that also the
16118 * type needs to be the same.
16119 */
16120 "This type is missing a matching correspondent "
16121 "for its {base type}'s %s in its {attribute uses}",
16122 xmlSchemaGetComponentDesignation(&str,
16123 buse->children),
16124 NULL);
16125 FREE_AND_NULL(str)
16126 }
16127 }
16128 }
William M. Brack2f2a6632004-08-20 23:09:47 +000016129 /*
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016130 * SPEC (1.3) "If it has an {attribute wildcard}, the complex type
16131 * definition must also have one, and the base type definition's
16132 * {attribute wildcard}'s {namespace constraint} must be a subset
16133 * of the complex type definition's {attribute wildcard}'s {namespace
Rob Richardsc6947bb2008-06-29 15:04:41 +000016134 * constraint}, as defined by Wildcard Subset (�3.10.6)."
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016135 */
Daniel Veillarddee23482008-04-11 12:58:43 +000016136
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016137 /*
16138 * MAYBE TODO: Enable if ever needed. But this will be needed only
16139 * if created the type via a schema construction API.
16140 */
16141 if (base->attributeWildcard != NULL) {
16142 if (type->attributeWilcard == NULL) {
16143 xmlChar *str = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000016144
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016145 xmlSchemaCustomErr(ACTXT_CAST pctxt,
16146 XML_SCHEMAP_COS_CT_EXTENDS_1_3,
16147 NULL, type,
16148 "The base %s has an attribute wildcard, "
16149 "but this type is missing an attribute wildcard",
16150 xmlSchemaGetComponentDesignation(&str, base));
16151 FREE_AND_NULL(str)
16152
16153 } else if (xmlSchemaCheckCOSNSSubset(
16154 base->attributeWildcard, type->attributeWildcard))
16155 {
16156 xmlChar *str = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000016157
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016158 xmlSchemaCustomErr(ACTXT_CAST pctxt,
16159 XML_SCHEMAP_COS_CT_EXTENDS_1_3,
16160 NULL, type,
16161 "The attribute wildcard is not a valid "
16162 "superset of the one in the base %s",
16163 xmlSchemaGetComponentDesignation(&str, base));
16164 FREE_AND_NULL(str)
16165 }
16166 }
16167#endif
16168 /*
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016169 * SPEC (1.4) "One of the following must be true:"
William M. Brack2f2a6632004-08-20 23:09:47 +000016170 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016171 if ((type->contentTypeDef != NULL) &&
16172 (type->contentTypeDef == base->contentTypeDef)) {
16173 /*
16174 * SPEC (1.4.1) "The {content type} of the {base type definition}
16175 * and the {content type} of the complex type definition itself
16176 * must be the same simple type definition"
16177 * PASS
16178 */
16179 } else if ((type->contentType == XML_SCHEMA_CONTENT_EMPTY) &&
16180 (base->contentType == XML_SCHEMA_CONTENT_EMPTY) ) {
16181 /*
16182 * SPEC (1.4.2) "The {content type} of both the {base type
16183 * definition} and the complex type definition itself must
16184 * be empty."
16185 * PASS
16186 */
16187 } else {
16188 /*
16189 * SPEC (1.4.3) "All of the following must be true:"
16190 */
16191 if (type->subtypes == NULL) {
16192 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016193 * SPEC 1.4.3.1 The {content type} of the complex type
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016194 * definition itself must specify a particle.
16195 */
16196 xmlSchemaPCustomErr(ctxt,
16197 XML_SCHEMAP_COS_CT_EXTENDS_1_1,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016198 WXS_BASIC_CAST type, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016199 "The content type must specify a particle", NULL);
16200 return (XML_SCHEMAP_COS_CT_EXTENDS_1_1);
16201 }
16202 /*
16203 * SPEC (1.4.3.2) "One of the following must be true:"
16204 */
16205 if (base->contentType == XML_SCHEMA_CONTENT_EMPTY) {
16206 /*
16207 * SPEC (1.4.3.2.1) "The {content type} of the {base type
16208 * definition} must be empty.
16209 * PASS
16210 */
16211 } else {
16212 /*
16213 * SPEC (1.4.3.2.2) "All of the following must be true:"
16214 */
16215 if ((type->contentType != base->contentType) ||
16216 ((type->contentType != XML_SCHEMA_CONTENT_MIXED) &&
16217 (type->contentType != XML_SCHEMA_CONTENT_ELEMENTS))) {
16218 /*
16219 * SPEC (1.4.3.2.2.1) "Both {content type}s must be mixed
16220 * or both must be element-only."
16221 */
16222 xmlSchemaPCustomErr(ctxt,
16223 XML_SCHEMAP_COS_CT_EXTENDS_1_1,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016224 WXS_BASIC_CAST type, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016225 "The content type of both, the type and its base "
16226 "type, must either 'mixed' or 'element-only'", NULL);
16227 return (XML_SCHEMAP_COS_CT_EXTENDS_1_1);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016228 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016229 /*
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016230 * URGENT TODO SPEC (1.4.3.2.2.2) "The particle of the
Rob Richardsc6947bb2008-06-29 15:04:41 +000016231 * complex type definition must be a �valid extension�
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016232 * of the {base type definition}'s particle, as defined
Rob Richardsc6947bb2008-06-29 15:04:41 +000016233 * in Particle Valid (Extension) (�3.9.6)."
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016234 *
16235 * NOTE that we won't check "Particle Valid (Extension)",
16236 * since it is ensured by the derivation process in
16237 * xmlSchemaTypeFixup(). We need to implement this when heading
16238 * for a construction API
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016239 * TODO: !! This is needed to be checked if redefining a type !!
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016240 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016241 }
16242 /*
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016243 * URGENT TODO (1.5)
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016244 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016245 }
William M. Brack2f2a6632004-08-20 23:09:47 +000016246 } else {
16247 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016248 * SPEC (2) "If the {base type definition} is a simple type definition,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016249 * then all of the following must be true:"
William M. Brack2f2a6632004-08-20 23:09:47 +000016250 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016251 if (type->contentTypeDef != base) {
16252 /*
16253 * SPEC (2.1) "The {content type} must be the same simple type
16254 * definition."
16255 */
16256 xmlSchemaPCustomErr(ctxt,
16257 XML_SCHEMAP_COS_CT_EXTENDS_1_1,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016258 WXS_BASIC_CAST type, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016259 "The content type must be the simple base type", NULL);
16260 return (XML_SCHEMAP_COS_CT_EXTENDS_1_1);
16261 }
16262 if (base->flags & XML_SCHEMAS_TYPE_FINAL_EXTENSION) {
16263 /*
16264 * SPEC (2.2) "The {final} of the {base type definition} must not
16265 * contain extension"
16266 * NOTE that this is the same as (1.1).
16267 */
16268 xmlSchemaPCustomErr(ctxt,
16269 XML_SCHEMAP_COS_CT_EXTENDS_1_1,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016270 WXS_BASIC_CAST type, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016271 "The 'final' of the base type definition "
16272 "contains 'extension'", NULL);
16273 return (XML_SCHEMAP_COS_CT_EXTENDS_1_1);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016274 }
William M. Brack2f2a6632004-08-20 23:09:47 +000016275 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016276 return (0);
William M. Brack2f2a6632004-08-20 23:09:47 +000016277}
16278
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016279/**
16280 * xmlSchemaCheckDerivationOKRestriction:
16281 * @ctxt: the schema parser context
16282 * @type: the complex type definition
16283 *
16284 * (3.4.6) Constraints on Complex Type Definition Schema Components
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016285 * Schema Component Constraint:
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016286 * Derivation Valid (Restriction, Complex) (derivation-ok-restriction)
16287 *
16288 * STATUS:
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016289 * missing:
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016290 * (5.4.2) ???
16291 *
16292 * ATTENTION:
16293 * In XML Schema 1.1 this will be:
16294 * Validation Rule: Checking complex type subsumption
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016295 *
16296 * Returns 0 if the constraints are satisfied, a positive
16297 * error code if not and -1 if an internal error occured.
16298 */
16299static int
16300xmlSchemaCheckDerivationOKRestriction(xmlSchemaParserCtxtPtr ctxt,
16301 xmlSchemaTypePtr type)
16302{
16303 xmlSchemaTypePtr base;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016304
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016305 /*
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016306 * TODO: Correct the error code; XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1 is used
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016307 * temporarily only.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016308 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016309 base = type->baseType;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016310 if (! WXS_IS_COMPLEX(base)) {
Daniel Veillarddee23482008-04-11 12:58:43 +000016311 xmlSchemaCustomErr(ACTXT_CAST ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016312 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1,
16313 type->node, WXS_BASIC_CAST type,
16314 "The base type must be a complex type", NULL, NULL);
16315 return(ctxt->err);
16316 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016317 if (base->flags & XML_SCHEMAS_TYPE_FINAL_RESTRICTION) {
16318 /*
16319 * SPEC (1) "The {base type definition} must be a complex type
16320 * definition whose {final} does not contain restriction."
16321 */
Daniel Veillarddee23482008-04-11 12:58:43 +000016322 xmlSchemaCustomErr(ACTXT_CAST ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016323 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1,
16324 type->node, WXS_BASIC_CAST type,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016325 "The 'final' of the base type definition "
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016326 "contains 'restriction'", NULL, NULL);
16327 return (ctxt->err);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016328 }
16329 /*
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016330 * SPEC (2), (3) and (4)
16331 * Those are handled in a separate function, since the
16332 * same constraints are needed for redefinition of
16333 * attribute groups as well.
16334 */
16335 if (xmlSchemaCheckDerivationOKRestriction2to4(ctxt,
16336 XML_SCHEMA_ACTION_DERIVE,
16337 WXS_BASIC_CAST type, WXS_BASIC_CAST base,
16338 type->attrUses, base->attrUses,
16339 type->attributeWildcard,
16340 base->attributeWildcard) == -1)
16341 {
16342 return(-1);
16343 }
16344 /*
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016345 * SPEC (5) "One of the following must be true:"
16346 */
16347 if (base->builtInType == XML_SCHEMAS_ANYTYPE) {
16348 /*
16349 * SPEC (5.1) "The {base type definition} must be the
Rob Richardsc6947bb2008-06-29 15:04:41 +000016350 * �ur-type definition�."
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016351 * PASS
16352 */
16353 } else if ((type->contentType == XML_SCHEMA_CONTENT_SIMPLE) ||
16354 (type->contentType == XML_SCHEMA_CONTENT_BASIC)) {
16355 /*
16356 * SPEC (5.2.1) "The {content type} of the complex type definition
16357 * must be a simple type definition"
16358 *
16359 * SPEC (5.2.2) "One of the following must be true:"
16360 */
16361 if ((base->contentType == XML_SCHEMA_CONTENT_SIMPLE) ||
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016362 (base->contentType == XML_SCHEMA_CONTENT_BASIC))
16363 {
16364 int err;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016365 /*
16366 * SPEC (5.2.2.1) "The {content type} of the {base type
16367 * definition} must be a simple type definition from which
16368 * the {content type} is validly derived given the empty
Rob Richardsc6947bb2008-06-29 15:04:41 +000016369 * set as defined in Type Derivation OK (Simple) (�3.14.6)."
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016370 *
16371 * ATTENTION TODO: This seems not needed if the type implicitely
16372 * derived from the base type.
Daniel Veillarddee23482008-04-11 12:58:43 +000016373 *
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016374 */
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000016375 err = xmlSchemaCheckCOSSTDerivedOK(ACTXT_CAST ctxt,
16376 type->contentTypeDef, base->contentTypeDef, 0);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016377 if (err != 0) {
16378 xmlChar *strA = NULL, *strB = NULL;
16379
16380 if (err == -1)
16381 return(-1);
16382 xmlSchemaCustomErr(ACTXT_CAST ctxt,
16383 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1,
16384 NULL, WXS_BASIC_CAST type,
16385 "The {content type} %s is not validly derived from the "
16386 "base type's {content type} %s",
16387 xmlSchemaGetComponentDesignation(&strA,
16388 type->contentTypeDef),
16389 xmlSchemaGetComponentDesignation(&strB,
16390 base->contentTypeDef));
16391 FREE_AND_NULL(strA);
16392 FREE_AND_NULL(strB);
16393 return(ctxt->err);
16394 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016395 } else if ((base->contentType == XML_SCHEMA_CONTENT_MIXED) &&
16396 (xmlSchemaIsParticleEmptiable(
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016397 (xmlSchemaParticlePtr) base->subtypes))) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016398 /*
16399 * SPEC (5.2.2.2) "The {base type definition} must be mixed
Rob Richardsc6947bb2008-06-29 15:04:41 +000016400 * and have a particle which is �emptiable� as defined in
16401 * Particle Emptiable (�3.9.6)."
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016402 * PASS
16403 */
16404 } else {
16405 xmlSchemaPCustomErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016406 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1,
16407 WXS_BASIC_CAST type, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016408 "The content type of the base type must be either "
16409 "a simple type or 'mixed' and an emptiable particle", NULL);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016410 return (ctxt->err);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016411 }
16412 } else if (type->contentType == XML_SCHEMA_CONTENT_EMPTY) {
16413 /*
16414 * SPEC (5.3.1) "The {content type} of the complex type itself must
16415 * be empty"
16416 */
16417 if (base->contentType == XML_SCHEMA_CONTENT_EMPTY) {
16418 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016419 * SPEC (5.3.2.1) "The {content type} of the {base type
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016420 * definition} must also be empty."
16421 * PASS
16422 */
16423 } else if (((base->contentType == XML_SCHEMA_CONTENT_ELEMENTS) ||
16424 (base->contentType == XML_SCHEMA_CONTENT_MIXED)) &&
16425 xmlSchemaIsParticleEmptiable(
16426 (xmlSchemaParticlePtr) base->subtypes)) {
16427 /*
16428 * SPEC (5.3.2.2) "The {content type} of the {base type
16429 * definition} must be elementOnly or mixed and have a particle
Rob Richardsc6947bb2008-06-29 15:04:41 +000016430 * which is �emptiable� as defined in Particle Emptiable (�3.9.6)."
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016431 * PASS
16432 */
16433 } else {
16434 xmlSchemaPCustomErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016435 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1,
16436 WXS_BASIC_CAST type, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016437 "The content type of the base type must be either "
16438 "empty or 'mixed' (or 'elements-only') and an emptiable "
16439 "particle", NULL);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016440 return (ctxt->err);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016441 }
16442 } else if ((type->contentType == XML_SCHEMA_CONTENT_ELEMENTS) ||
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016443 WXS_HAS_MIXED_CONTENT(type)) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016444 /*
16445 * SPEC (5.4.1.1) "The {content type} of the complex type definition
16446 * itself must be element-only"
Daniel Veillarddee23482008-04-11 12:58:43 +000016447 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016448 if (WXS_HAS_MIXED_CONTENT(type) && (! WXS_HAS_MIXED_CONTENT(base))) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016449 /*
16450 * SPEC (5.4.1.2) "The {content type} of the complex type
16451 * definition itself and of the {base type definition} must be
16452 * mixed"
16453 */
16454 xmlSchemaPCustomErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016455 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1,
16456 WXS_BASIC_CAST type, NULL,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016457 "If the content type is 'mixed', then the content type of the "
16458 "base type must also be 'mixed'", NULL);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016459 return (ctxt->err);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016460 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016461 /*
16462 * SPEC (5.4.2) "The particle of the complex type definition itself
Rob Richardsc6947bb2008-06-29 15:04:41 +000016463 * must be a �valid restriction� of the particle of the {content
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016464 * type} of the {base type definition} as defined in Particle Valid
Rob Richardsc6947bb2008-06-29 15:04:41 +000016465 * (Restriction) (�3.9.6).
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016466 *
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000016467 * URGENT TODO: (5.4.2)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016468 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016469 } else {
16470 xmlSchemaPCustomErr(ctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016471 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1,
16472 WXS_BASIC_CAST type, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016473 "The type is not a valid restriction of its base type", NULL);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016474 return (ctxt->err);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016475 }
16476 return (0);
16477}
16478
16479/**
Kasimier T. Buchcik5e371a02005-04-05 15:08:05 +000016480 * xmlSchemaCheckCTComponent:
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016481 * @ctxt: the schema parser context
16482 * @type: the complex type definition
16483 *
16484 * (3.4.6) Constraints on Complex Type Definition Schema Components
16485 *
16486 * Returns 0 if the constraints are satisfied, a positive
16487 * error code if not and -1 if an internal error occured.
16488 */
16489static int
16490xmlSchemaCheckCTComponent(xmlSchemaParserCtxtPtr ctxt,
16491 xmlSchemaTypePtr type)
16492{
16493 int ret;
16494 /*
16495 * Complex Type Definition Properties Correct
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016496 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016497 ret = xmlSchemaCheckCTPropsCorrect(ctxt, type);
16498 if (ret != 0)
16499 return (ret);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000016500 if (WXS_IS_EXTENSION(type))
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016501 ret = xmlSchemaCheckCOSCTExtends(ctxt, type);
16502 else
16503 ret = xmlSchemaCheckDerivationOKRestriction(ctxt, type);
16504 return (ret);
16505}
16506
16507/**
16508 * xmlSchemaCheckSRCCT:
16509 * @ctxt: the schema parser context
16510 * @type: the complex type definition
16511 *
16512 * (3.4.3) Constraints on XML Representations of Complex Type Definitions:
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016513 * Schema Representation Constraint:
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016514 * Complex Type Definition Representation OK (src-ct)
16515 *
16516 * Returns 0 if the constraints are satisfied, a positive
16517 * error code if not and -1 if an internal error occured.
16518 */
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000016519static int
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016520xmlSchemaCheckSRCCT(xmlSchemaParserCtxtPtr ctxt,
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000016521 xmlSchemaTypePtr type)
16522{
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016523 xmlSchemaTypePtr base;
16524 int ret = 0;
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000016525
16526 /*
16527 * TODO: Adjust the error codes here, as I used
16528 * XML_SCHEMAP_SRC_CT_1 only yet.
16529 */
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000016530 base = type->baseType;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016531 if (! WXS_HAS_SIMPLE_CONTENT(type)) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016532 /*
16533 * 1 If the <complexContent> alternative is chosen, the type definition
Rob Richardsc6947bb2008-06-29 15:04:41 +000016534 * �resolved� to by the �actual value� of the base [attribute]
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016535 * must be a complex type definition;
16536 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016537 if (! WXS_IS_COMPLEX(base)) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016538 xmlChar *str = NULL;
16539 xmlSchemaPCustomErr(ctxt,
16540 XML_SCHEMAP_SRC_CT_1,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016541 WXS_BASIC_CAST type, type->node,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016542 "If using <complexContent>, the base type is expected to be "
16543 "a complex type. The base type '%s' is a simple type",
16544 xmlSchemaFormatQName(&str, base->targetNamespace,
16545 base->name));
16546 FREE_AND_NULL(str)
16547 return (XML_SCHEMAP_SRC_CT_1);
16548 }
16549 } else {
16550 /*
16551 * SPEC
16552 * 2 If the <simpleContent> alternative is chosen, all of the
16553 * following must be true:
Rob Richardsc6947bb2008-06-29 15:04:41 +000016554 * 2.1 The type definition �resolved� to by the �actual value� of the
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016555 * base [attribute] must be one of the following:
16556 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016557 if (WXS_IS_SIMPLE(base)) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000016558 if (WXS_IS_EXTENSION(type) == 0) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016559 xmlChar *str = NULL;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016560 /*
16561 * 2.1.3 only if the <extension> alternative is also
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016562 * chosen, a simple type definition.
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000016563 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016564 /* TODO: Change error code to ..._SRC_CT_2_1_3. */
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000016565 xmlSchemaPCustomErr(ctxt,
16566 XML_SCHEMAP_SRC_CT_1,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016567 WXS_BASIC_CAST type, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016568 "If using <simpleContent> and <restriction>, the base "
16569 "type must be a complex type. The base type '%s' is "
16570 "a simple type",
16571 xmlSchemaFormatQName(&str, base->targetNamespace,
16572 base->name));
16573 FREE_AND_NULL(str)
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000016574 return (XML_SCHEMAP_SRC_CT_1);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016575 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016576 } else {
16577 /* Base type is a complex type. */
16578 if ((base->contentType == XML_SCHEMA_CONTENT_SIMPLE) ||
16579 (base->contentType == XML_SCHEMA_CONTENT_BASIC)) {
16580 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016581 * 2.1.1 a complex type definition whose {content type} is a
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016582 * simple type definition;
16583 * PASS
16584 */
16585 if (base->contentTypeDef == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016586 xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_INTERNAL,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016587 WXS_BASIC_CAST type, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016588 "Internal error: xmlSchemaCheckSRCCT, "
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016589 "'%s', base type has no content type",
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016590 type->name);
16591 return (-1);
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000016592 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016593 } else if ((base->contentType == XML_SCHEMA_CONTENT_MIXED) &&
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000016594 (WXS_IS_RESTRICTION(type))) {
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000016595
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016596 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016597 * 2.1.2 only if the <restriction> alternative is also
16598 * chosen, a complex type definition whose {content type}
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016599 * is mixed and a particle emptiable.
16600 */
16601 if (! xmlSchemaIsParticleEmptiable(
16602 (xmlSchemaParticlePtr) base->subtypes)) {
16603 ret = XML_SCHEMAP_SRC_CT_1;
Daniel Veillarddee23482008-04-11 12:58:43 +000016604 } else
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016605 /*
16606 * Attention: at this point the <simpleType> child is in
16607 * ->contentTypeDef (put there during parsing).
Daniel Veillarddee23482008-04-11 12:58:43 +000016608 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016609 if (type->contentTypeDef == NULL) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016610 xmlChar *str = NULL;
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000016611 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016612 * 2.2 If clause 2.1.2 above is satisfied, then there
16613 * must be a <simpleType> among the [children] of
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000016614 * <restriction>.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016615 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016616 /* TODO: Change error code to ..._SRC_CT_2_2. */
16617 xmlSchemaPCustomErr(ctxt,
16618 XML_SCHEMAP_SRC_CT_1,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016619 WXS_BASIC_CAST type, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016620 "A <simpleType> is expected among the children "
16621 "of <restriction>, if <simpleContent> is used and "
16622 "the base type '%s' is a complex type",
16623 xmlSchemaFormatQName(&str, base->targetNamespace,
16624 base->name));
16625 FREE_AND_NULL(str)
16626 return (XML_SCHEMAP_SRC_CT_1);
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000016627 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016628 } else {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016629 ret = XML_SCHEMAP_SRC_CT_1;
16630 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016631 }
16632 if (ret > 0) {
16633 xmlChar *str = NULL;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000016634 if (WXS_IS_RESTRICTION(type)) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016635 xmlSchemaPCustomErr(ctxt,
16636 XML_SCHEMAP_SRC_CT_1,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016637 WXS_BASIC_CAST type, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016638 "If <simpleContent> and <restriction> is used, the "
16639 "base type must be a simple type or a complex type with "
16640 "mixed content and particle emptiable. The base type "
16641 "'%s' is none of those",
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016642 xmlSchemaFormatQName(&str, base->targetNamespace,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016643 base->name));
16644 } else {
16645 xmlSchemaPCustomErr(ctxt,
16646 XML_SCHEMAP_SRC_CT_1,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016647 WXS_BASIC_CAST type, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016648 "If <simpleContent> and <extension> is used, the "
16649 "base type must be a simple type. The base type '%s' "
16650 "is a complex type",
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016651 xmlSchemaFormatQName(&str, base->targetNamespace,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016652 base->name));
16653 }
16654 FREE_AND_NULL(str)
16655 }
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000016656 }
16657 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016658 * SPEC (3) "The corresponding complex type definition component must
16659 * satisfy the conditions set out in Constraints on Complex Type
Rob Richardsc6947bb2008-06-29 15:04:41 +000016660 * Definition Schema Components (�3.4.6);"
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016661 * NOTE (3) will be done in xmlSchemaTypeFixup().
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016662 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016663 /*
16664 * SPEC (4) If clause 2.2.1 or clause 2.2.2 in the correspondence specification
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016665 * above for {attribute wildcard} is satisfied, the intensional
16666 * intersection must be expressible, as defined in Attribute Wildcard
Rob Richardsc6947bb2008-06-29 15:04:41 +000016667 * Intersection (�3.10.6).
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016668 * NOTE (4) is done in xmlSchemaFixupTypeAttributeUses().
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000016669 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000016670 return (ret);
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000016671}
William M. Brack2f2a6632004-08-20 23:09:47 +000016672
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000016673#ifdef ENABLE_PARTICLE_RESTRICTION
16674/**
16675 * xmlSchemaCheckParticleRangeOK:
16676 * @ctxt: the schema parser context
16677 * @type: the complex type definition
16678 *
16679 * (3.9.6) Constraints on Particle Schema Components
16680 * Schema Component Constraint:
16681 * Occurrence Range OK (range-ok)
16682 *
16683 * STATUS: complete
16684 *
16685 * Returns 0 if the constraints are satisfied, a positive
16686 * error code if not and -1 if an internal error occured.
16687 */
16688static int
16689xmlSchemaCheckParticleRangeOK(int rmin, int rmax,
16690 int bmin, int bmax)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016691{
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000016692 if (rmin < bmin)
16693 return (1);
16694 if ((bmax != UNBOUNDED) &&
16695 (rmax > bmax))
16696 return (1);
16697 return (0);
16698}
16699
16700/**
16701 * xmlSchemaCheckRCaseNameAndTypeOK:
16702 * @ctxt: the schema parser context
16703 * @r: the restricting element declaration particle
16704 * @b: the base element declaration particle
16705 *
16706 * (3.9.6) Constraints on Particle Schema Components
16707 * Schema Component Constraint:
16708 * Particle Restriction OK (Elt:Elt -- NameAndTypeOK)
16709 * (rcase-NameAndTypeOK)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016710 *
16711 * STATUS:
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000016712 * MISSING (3.2.3)
16713 * CLARIFY: (3.2.2)
16714 *
16715 * Returns 0 if the constraints are satisfied, a positive
16716 * error code if not and -1 if an internal error occured.
16717 */
16718static int
16719xmlSchemaCheckRCaseNameAndTypeOK(xmlSchemaParserCtxtPtr ctxt,
16720 xmlSchemaParticlePtr r,
16721 xmlSchemaParticlePtr b)
16722{
16723 xmlSchemaElementPtr elemR, elemB;
16724
16725 /* TODO: Error codes (rcase-NameAndTypeOK). */
16726 elemR = (xmlSchemaElementPtr) r->children;
16727 elemB = (xmlSchemaElementPtr) b->children;
16728 /*
16729 * SPEC (1) "The declarations' {name}s and {target namespace}s are
16730 * the same."
16731 */
16732 if ((elemR != elemB) &&
16733 ((! xmlStrEqual(elemR->name, elemB->name)) ||
16734 (! xmlStrEqual(elemR->targetNamespace, elemB->targetNamespace))))
16735 return (1);
16736 /*
16737 * SPEC (2) "R's occurrence range is a valid restriction of B's
Rob Richardsc6947bb2008-06-29 15:04:41 +000016738 * occurrence range as defined by Occurrence Range OK (�3.9.6)."
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000016739 */
16740 if (xmlSchemaCheckParticleRangeOK(r->minOccurs, r->maxOccurs,
16741 b->minOccurs, b->maxOccurs) != 0)
16742 return (1);
16743 /*
16744 * SPEC (3.1) "Both B's declaration's {scope} and R's declaration's
16745 * {scope} are global."
16746 */
16747 if (elemR == elemB)
16748 return (0);
16749 /*
16750 * SPEC (3.2.1) "Either B's {nillable} is true or R's {nillable} is false."
16751 */
16752 if (((elemB->flags & XML_SCHEMAS_ELEM_NILLABLE) == 0) &&
16753 (elemR->flags & XML_SCHEMAS_ELEM_NILLABLE))
16754 return (1);
16755 /*
16756 * SPEC (3.2.2) "either B's declaration's {value constraint} is absent,
16757 * or is not fixed, or R's declaration's {value constraint} is fixed
16758 * with the same value."
16759 */
16760 if ((elemB->value != NULL) && (elemB->flags & XML_SCHEMAS_ELEM_FIXED) &&
16761 ((elemR->value == NULL) ||
16762 ((elemR->flags & XML_SCHEMAS_ELEM_FIXED) == 0) ||
16763 /* TODO: Equality of the initial value or normalized or canonical? */
16764 (! xmlStrEqual(elemR->value, elemB->value))))
16765 return (1);
16766 /*
16767 * TODO: SPEC (3.2.3) "R's declaration's {identity-constraint
16768 * definitions} is a subset of B's declaration's {identity-constraint
16769 * definitions}, if any."
16770 */
16771 if (elemB->idcs != NULL) {
16772 /* TODO */
16773 }
16774 /*
16775 * SPEC (3.2.4) "R's declaration's {disallowed substitutions} is a
16776 * superset of B's declaration's {disallowed substitutions}."
16777 */
16778 if (((elemB->flags & XML_SCHEMAS_ELEM_BLOCK_EXTENSION) &&
16779 ((elemR->flags & XML_SCHEMAS_ELEM_BLOCK_EXTENSION) == 0)) ||
16780 ((elemB->flags & XML_SCHEMAS_ELEM_BLOCK_RESTRICTION) &&
16781 ((elemR->flags & XML_SCHEMAS_ELEM_BLOCK_RESTRICTION) == 0)) ||
16782 ((elemB->flags & XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION) &&
16783 ((elemR->flags & XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION) == 0)))
16784 return (1);
16785 /*
16786 * SPEC (3.2.5) "R's {type definition} is validly derived given
16787 * {extension, list, union} from B's {type definition}"
16788 *
16789 * BADSPEC TODO: What's the point of adding "list" and "union" to the
16790 * set, if the corresponding constraints handle "restriction" and
16791 * "extension" only?
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016792 *
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000016793 */
16794 {
16795 int set = 0;
16796
16797 set |= SUBSET_EXTENSION;
16798 set |= SUBSET_LIST;
16799 set |= SUBSET_UNION;
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000016800 if (xmlSchemaCheckCOSDerivedOK(ACTXT_CAST ctxt, elemR->subtypes,
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000016801 elemB->subtypes, set) != 0)
16802 return (1);
16803 }
16804 return (0);
16805}
16806
16807/**
16808 * xmlSchemaCheckRCaseNSCompat:
16809 * @ctxt: the schema parser context
16810 * @r: the restricting element declaration particle
16811 * @b: the base wildcard particle
16812 *
16813 * (3.9.6) Constraints on Particle Schema Components
16814 * Schema Component Constraint:
16815 * Particle Derivation OK (Elt:Any -- NSCompat)
16816 * (rcase-NSCompat)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016817 *
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000016818 * STATUS: complete
16819 *
16820 * Returns 0 if the constraints are satisfied, a positive
16821 * error code if not and -1 if an internal error occured.
16822 */
16823static int
16824xmlSchemaCheckRCaseNSCompat(xmlSchemaParserCtxtPtr ctxt,
16825 xmlSchemaParticlePtr r,
16826 xmlSchemaParticlePtr b)
16827{
16828 /* TODO:Error codes (rcase-NSCompat). */
16829 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000016830 * SPEC "For an element declaration particle to be a �valid restriction�
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000016831 * of a wildcard particle all of the following must be true:"
16832 *
Rob Richardsc6947bb2008-06-29 15:04:41 +000016833 * SPEC (1) "The element declaration's {target namespace} is �valid�
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000016834 * with respect to the wildcard's {namespace constraint} as defined by
Rob Richardsc6947bb2008-06-29 15:04:41 +000016835 * Wildcard allows Namespace Name (�3.10.4)."
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000016836 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016837 if (xmlSchemaCheckCVCWildcardNamespace((xmlSchemaWildcardPtr) b->children,
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000016838 ((xmlSchemaElementPtr) r->children)->targetNamespace) != 0)
16839 return (1);
16840 /*
16841 * SPEC (2) "R's occurrence range is a valid restriction of B's
Rob Richardsc6947bb2008-06-29 15:04:41 +000016842 * occurrence range as defined by Occurrence Range OK (�3.9.6)."
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000016843 */
16844 if (xmlSchemaCheckParticleRangeOK(r->minOccurs, r->maxOccurs,
16845 b->minOccurs, b->maxOccurs) != 0)
16846 return (1);
16847
16848 return (0);
16849}
16850
16851/**
16852 * xmlSchemaCheckRCaseRecurseAsIfGroup:
16853 * @ctxt: the schema parser context
16854 * @r: the restricting element declaration particle
16855 * @b: the base model group particle
16856 *
16857 * (3.9.6) Constraints on Particle Schema Components
16858 * Schema Component Constraint:
16859 * Particle Derivation OK (Elt:All/Choice/Sequence -- RecurseAsIfGroup)
16860 * (rcase-RecurseAsIfGroup)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016861 *
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000016862 * STATUS: TODO
16863 *
16864 * Returns 0 if the constraints are satisfied, a positive
16865 * error code if not and -1 if an internal error occured.
16866 */
16867static int
16868xmlSchemaCheckRCaseRecurseAsIfGroup(xmlSchemaParserCtxtPtr ctxt,
16869 xmlSchemaParticlePtr r,
16870 xmlSchemaParticlePtr b)
16871{
16872 /* TODO: Error codes (rcase-RecurseAsIfGroup). */
16873 TODO
16874 return (0);
16875}
16876
16877/**
16878 * xmlSchemaCheckRCaseNSSubset:
16879 * @ctxt: the schema parser context
16880 * @r: the restricting wildcard particle
16881 * @b: the base wildcard particle
16882 *
16883 * (3.9.6) Constraints on Particle Schema Components
16884 * Schema Component Constraint:
16885 * Particle Derivation OK (Any:Any -- NSSubset)
16886 * (rcase-NSSubset)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016887 *
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000016888 * STATUS: complete
16889 *
16890 * Returns 0 if the constraints are satisfied, a positive
16891 * error code if not and -1 if an internal error occured.
16892 */
16893static int
16894xmlSchemaCheckRCaseNSSubset(xmlSchemaParserCtxtPtr ctxt,
16895 xmlSchemaParticlePtr r,
16896 xmlSchemaParticlePtr b,
16897 int isAnyTypeBase)
16898{
16899 /* TODO: Error codes (rcase-NSSubset). */
16900 /*
16901 * SPEC (1) "R's occurrence range is a valid restriction of B's
Rob Richardsc6947bb2008-06-29 15:04:41 +000016902 * occurrence range as defined by Occurrence Range OK (�3.9.6)."
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000016903 */
16904 if (xmlSchemaCheckParticleRangeOK(r->minOccurs, r->maxOccurs,
16905 b->minOccurs, b->maxOccurs))
16906 return (1);
16907 /*
16908 * SPEC (2) "R's {namespace constraint} must be an intensional subset
Rob Richardsc6947bb2008-06-29 15:04:41 +000016909 * of B's {namespace constraint} as defined by Wildcard Subset (�3.10.6)."
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000016910 */
16911 if (xmlSchemaCheckCOSNSSubset((xmlSchemaWildcardPtr) r->children,
16912 (xmlSchemaWildcardPtr) b->children))
16913 return (1);
16914 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000016915 * SPEC (3) "Unless B is the content model wildcard of the �ur-type
16916 * definition�, R's {process contents} must be identical to or stronger
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000016917 * than B's {process contents}, where strict is stronger than lax is
16918 * stronger than skip."
16919 */
16920 if (! isAnyTypeBase) {
16921 if ( ((xmlSchemaWildcardPtr) r->children)->processContents <
16922 ((xmlSchemaWildcardPtr) b->children)->processContents)
16923 return (1);
16924 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016925
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000016926 return (0);
16927}
16928
16929/**
16930 * xmlSchemaCheckCOSParticleRestrict:
16931 * @ctxt: the schema parser context
16932 * @type: the complex type definition
16933 *
16934 * (3.9.6) Constraints on Particle Schema Components
16935 * Schema Component Constraint:
16936 * Particle Valid (Restriction) (cos-particle-restrict)
16937 *
16938 * STATUS: TODO
16939 *
16940 * Returns 0 if the constraints are satisfied, a positive
16941 * error code if not and -1 if an internal error occured.
16942 */
16943static int
16944xmlSchemaCheckCOSParticleRestrict(xmlSchemaParserCtxtPtr ctxt,
16945 xmlSchemaParticlePtr r,
16946 xmlSchemaParticlePtr b)
16947{
16948 int ret = 0;
16949
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000016950 /*part = WXS_TYPE_PARTICLE(type);
16951 basePart = WXS_TYPE_PARTICLE(base);
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000016952 */
16953
16954 TODO
16955
16956 /*
16957 * SPEC (1) "They are the same particle."
16958 */
16959 if (r == b)
16960 return (0);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016961
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000016962
16963 return (0);
16964}
16965
Daniel Veillard15724252008-08-30 15:01:04 +000016966#if 0
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000016967/**
16968 * xmlSchemaCheckRCaseNSRecurseCheckCardinality:
16969 * @ctxt: the schema parser context
16970 * @r: the model group particle
16971 * @b: the base wildcard particle
16972 *
16973 * (3.9.6) Constraints on Particle Schema Components
16974 * Schema Component Constraint:
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016975 * Particle Derivation OK (All/Choice/Sequence:Any --
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000016976 * NSRecurseCheckCardinality)
16977 * (rcase-NSRecurseCheckCardinality)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000016978 *
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000016979 * STATUS: TODO: subst-groups
16980 *
16981 * Returns 0 if the constraints are satisfied, a positive
16982 * error code if not and -1 if an internal error occured.
16983 */
16984static int
16985xmlSchemaCheckRCaseNSRecurseCheckCardinality(xmlSchemaParserCtxtPtr ctxt,
16986 xmlSchemaParticlePtr r,
16987 xmlSchemaParticlePtr b)
16988{
16989 xmlSchemaParticlePtr part;
16990 /* TODO: Error codes (rcase-NSRecurseCheckCardinality). */
16991 if ((r->children == NULL) || (r->children->children == NULL))
16992 return (-1);
16993 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000016994 * SPEC "For a group particle to be a �valid restriction� of a
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000016995 * wildcard particle..."
16996 *
Rob Richardsc6947bb2008-06-29 15:04:41 +000016997 * SPEC (1) "Every member of the {particles} of the group is a �valid
16998 * restriction� of the wildcard as defined by
16999 * Particle Valid (Restriction) (�3.9.6)."
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000017000 */
17001 part = (xmlSchemaParticlePtr) r->children->children;
17002 do {
17003 if (xmlSchemaCheckCOSParticleRestrict(ctxt, part, b))
17004 return (1);
17005 part = (xmlSchemaParticlePtr) part->next;
17006 } while (part != NULL);
17007 /*
17008 * SPEC (2) "The effective total range of the group [...] is a
17009 * valid restriction of B's occurrence range as defined by
Rob Richardsc6947bb2008-06-29 15:04:41 +000017010 * Occurrence Range OK (�3.9.6)."
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000017011 */
17012 if (xmlSchemaCheckParticleRangeOK(
17013 xmlSchemaGetParticleTotalRangeMin(r),
17014 xmlSchemaGetParticleTotalRangeMax(r),
17015 b->minOccurs, b->maxOccurs) != 0)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017016 return (1);
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000017017 return (0);
17018}
Daniel Veillard15724252008-08-30 15:01:04 +000017019#endif
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000017020
17021/**
17022 * xmlSchemaCheckRCaseRecurse:
17023 * @ctxt: the schema parser context
17024 * @r: the <all> or <sequence> model group particle
17025 * @b: the base <all> or <sequence> model group particle
17026 *
17027 * (3.9.6) Constraints on Particle Schema Components
17028 * Schema Component Constraint:
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017029 * Particle Derivation OK (All:All,Sequence:Sequence --
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000017030 Recurse)
17031 * (rcase-Recurse)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017032 *
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000017033 * STATUS: ?
17034 * TODO: subst-groups
17035 *
17036 * Returns 0 if the constraints are satisfied, a positive
17037 * error code if not and -1 if an internal error occured.
17038 */
17039static int
17040xmlSchemaCheckRCaseRecurse(xmlSchemaParserCtxtPtr ctxt,
17041 xmlSchemaParticlePtr r,
17042 xmlSchemaParticlePtr b)
17043{
17044 /* xmlSchemaParticlePtr part; */
17045 /* TODO: Error codes (rcase-Recurse). */
17046 if ((r->children == NULL) || (b->children == NULL) ||
17047 (r->children->type != b->children->type))
17048 return (-1);
17049 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000017050 * SPEC "For an all or sequence group particle to be a �valid
17051 * restriction� of another group particle with the same {compositor}..."
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000017052 *
17053 * SPEC (1) "R's occurrence range is a valid restriction of B's
Rob Richardsc6947bb2008-06-29 15:04:41 +000017054 * occurrence range as defined by Occurrence Range OK (�3.9.6)."
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000017055 */
17056 if (xmlSchemaCheckParticleRangeOK(r->minOccurs, r->maxOccurs,
17057 b->minOccurs, b->maxOccurs))
17058 return (1);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017059
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000017060
17061 return (0);
17062}
17063
17064#endif
17065
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017066#define FACET_RESTR_MUTUAL_ERR(fac1, fac2) \
17067 xmlSchemaPCustomErrExt(pctxt, \
17068 XML_SCHEMAP_INVALID_FACET_VALUE, \
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000017069 WXS_BASIC_CAST fac1, fac1->node, \
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017070 "It is an error for both '%s' and '%s' to be specified on the "\
17071 "same type definition", \
17072 BAD_CAST xmlSchemaFacetTypeToString(fac1->type), \
17073 BAD_CAST xmlSchemaFacetTypeToString(fac2->type), NULL);
17074
17075#define FACET_RESTR_ERR(fac1, msg) \
17076 xmlSchemaPCustomErr(pctxt, \
17077 XML_SCHEMAP_INVALID_FACET_VALUE, \
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000017078 WXS_BASIC_CAST fac1, fac1->node, \
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017079 msg, NULL);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017080
17081#define FACET_RESTR_FIXED_ERR(fac) \
17082 xmlSchemaPCustomErr(pctxt, \
17083 XML_SCHEMAP_INVALID_FACET_VALUE, \
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000017084 WXS_BASIC_CAST fac, fac->node, \
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017085 "The base type's facet is 'fixed', thus the value must not " \
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017086 "differ", NULL);
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017087
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000017088static void
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017089xmlSchemaDeriveFacetErr(xmlSchemaParserCtxtPtr pctxt,
17090 xmlSchemaFacetPtr facet1,
17091 xmlSchemaFacetPtr facet2,
17092 int lessGreater,
17093 int orEqual,
17094 int ofBase)
17095{
17096 xmlChar *msg = NULL;
17097
17098 msg = xmlStrdup(BAD_CAST "'");
17099 msg = xmlStrcat(msg, xmlSchemaFacetTypeToString(facet1->type));
17100 msg = xmlStrcat(msg, BAD_CAST "' has to be");
17101 if (lessGreater == 0)
17102 msg = xmlStrcat(msg, BAD_CAST " equal to");
17103 if (lessGreater == 1)
17104 msg = xmlStrcat(msg, BAD_CAST " greater than");
17105 else
17106 msg = xmlStrcat(msg, BAD_CAST " less than");
17107
17108 if (orEqual)
17109 msg = xmlStrcat(msg, BAD_CAST " or equal to");
17110 msg = xmlStrcat(msg, BAD_CAST " '");
17111 msg = xmlStrcat(msg, xmlSchemaFacetTypeToString(facet2->type));
17112 if (ofBase)
17113 msg = xmlStrcat(msg, BAD_CAST "' of the base type");
17114 else
17115 msg = xmlStrcat(msg, BAD_CAST "'");
17116
17117 xmlSchemaPCustomErr(pctxt,
17118 XML_SCHEMAP_INVALID_FACET_VALUE,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000017119 WXS_BASIC_CAST facet1, NULL,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017120 (const char *) msg, NULL);
17121
17122 if (msg != NULL)
17123 xmlFree(msg);
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000017124}
17125
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017126/*
17127* xmlSchemaDeriveAndValidateFacets:
17128*
17129* Schema Component Constraint: Simple Type Restriction (Facets)
17130* (st-restrict-facets)
17131*/
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000017132static int
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017133xmlSchemaDeriveAndValidateFacets(xmlSchemaParserCtxtPtr pctxt,
17134 xmlSchemaTypePtr type)
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000017135{
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017136 xmlSchemaTypePtr base = type->baseType;
17137 xmlSchemaFacetLinkPtr link, cur, last = NULL;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017138 xmlSchemaFacetPtr facet, bfacet,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017139 flength = NULL, ftotdig = NULL, ffracdig = NULL,
17140 fmaxlen = NULL, fminlen = NULL, /* facets of the current type */
17141 fmininc = NULL, fmaxinc = NULL,
17142 fminexc = NULL, fmaxexc = NULL,
17143 bflength = NULL, bftotdig = NULL, bffracdig = NULL,
17144 bfmaxlen = NULL, bfminlen = NULL, /* facets of the base type */
17145 bfmininc = NULL, bfmaxinc = NULL,
17146 bfminexc = NULL, bfmaxexc = NULL;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000017147 int res; /* err = 0, fixedErr; */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017148
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017149 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017150 * SPEC st-restrict-facets 1:
Daniel Veillarddee23482008-04-11 12:58:43 +000017151 * "The {variety} of R is the same as that of B."
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017152 */
17153 /*
17154 * SPEC st-restrict-facets 2:
17155 * "If {variety} is atomic, the {primitive type definition}
17156 * of R is the same as that of B."
17157 *
17158 * NOTE: we leave 1 & 2 out for now, since this will be
17159 * satisfied by the derivation process.
17160 * CONSTRUCTION TODO: Maybe needed if using a construction API.
17161 */
17162 /*
17163 * SPEC st-restrict-facets 3:
17164 * "The {facets} of R are the union of S and the {facets}
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017165 * of B, eliminating duplicates. To eliminate duplicates,
17166 * when a facet of the same kind occurs in both S and the
17167 * {facets} of B, the one in the {facets} of B is not
17168 * included, with the exception of enumeration and pattern
17169 * facets, for which multiple occurrences with distinct values
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017170 * are allowed."
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017171 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017172
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017173 if ((type->facetSet == NULL) && (base->facetSet == NULL))
17174 return (0);
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000017175
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017176 last = type->facetSet;
17177 if (last != NULL)
17178 while (last->next != NULL)
17179 last = last->next;
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000017180
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017181 for (cur = type->facetSet; cur != NULL; cur = cur->next) {
17182 facet = cur->facet;
17183 switch (facet->type) {
17184 case XML_SCHEMA_FACET_LENGTH:
17185 flength = facet; break;
17186 case XML_SCHEMA_FACET_MINLENGTH:
17187 fminlen = facet; break;
17188 case XML_SCHEMA_FACET_MININCLUSIVE:
17189 fmininc = facet; break;
17190 case XML_SCHEMA_FACET_MINEXCLUSIVE:
17191 fminexc = facet; break;
17192 case XML_SCHEMA_FACET_MAXLENGTH:
17193 fmaxlen = facet; break;
17194 case XML_SCHEMA_FACET_MAXINCLUSIVE:
17195 fmaxinc = facet; break;
17196 case XML_SCHEMA_FACET_MAXEXCLUSIVE:
17197 fmaxexc = facet; break;
17198 case XML_SCHEMA_FACET_TOTALDIGITS:
17199 ftotdig = facet; break;
17200 case XML_SCHEMA_FACET_FRACTIONDIGITS:
17201 ffracdig = facet; break;
17202 default:
17203 break;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017204 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017205 }
17206 for (cur = base->facetSet; cur != NULL; cur = cur->next) {
17207 facet = cur->facet;
17208 switch (facet->type) {
17209 case XML_SCHEMA_FACET_LENGTH:
17210 bflength = facet; break;
17211 case XML_SCHEMA_FACET_MINLENGTH:
17212 bfminlen = facet; break;
17213 case XML_SCHEMA_FACET_MININCLUSIVE:
17214 bfmininc = facet; break;
17215 case XML_SCHEMA_FACET_MINEXCLUSIVE:
17216 bfminexc = facet; break;
17217 case XML_SCHEMA_FACET_MAXLENGTH:
17218 bfmaxlen = facet; break;
17219 case XML_SCHEMA_FACET_MAXINCLUSIVE:
17220 bfmaxinc = facet; break;
17221 case XML_SCHEMA_FACET_MAXEXCLUSIVE:
17222 bfmaxexc = facet; break;
17223 case XML_SCHEMA_FACET_TOTALDIGITS:
17224 bftotdig = facet; break;
17225 case XML_SCHEMA_FACET_FRACTIONDIGITS:
17226 bffracdig = facet; break;
17227 default:
17228 break;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017229 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017230 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017231 /*
17232 * length and minLength or maxLength (2.2) + (3.2)
17233 */
17234 if (flength && (fminlen || fmaxlen)) {
17235 FACET_RESTR_ERR(flength, "It is an error for both 'length' and "
17236 "either of 'minLength' or 'maxLength' to be specified on "
17237 "the same type definition")
17238 }
17239 /*
17240 * Mutual exclusions in the same derivation step.
17241 */
17242 if ((fmaxinc) && (fmaxexc)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017243 /*
17244 * SCC "maxInclusive and maxExclusive"
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017245 */
17246 FACET_RESTR_MUTUAL_ERR(fmaxinc, fmaxexc)
17247 }
17248 if ((fmininc) && (fminexc)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017249 /*
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017250 * SCC "minInclusive and minExclusive"
17251 */
17252 FACET_RESTR_MUTUAL_ERR(fmininc, fminexc)
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000017253 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017254
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017255 if (flength && bflength) {
17256 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017257 * SCC "length valid restriction"
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017258 * The values have to be equal.
17259 */
17260 res = xmlSchemaCompareValues(flength->val, bflength->val);
17261 if (res == -2)
17262 goto internal_error;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017263 if (res != 0)
17264 xmlSchemaDeriveFacetErr(pctxt, flength, bflength, 0, 0, 1);
17265 if ((res != 0) && (bflength->fixed)) {
17266 FACET_RESTR_FIXED_ERR(flength)
17267 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017268
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017269 }
17270 if (fminlen && bfminlen) {
17271 /*
17272 * SCC "minLength valid restriction"
17273 * minLength >= BASE minLength
17274 */
17275 res = xmlSchemaCompareValues(fminlen->val, bfminlen->val);
17276 if (res == -2)
17277 goto internal_error;
17278 if (res == -1)
17279 xmlSchemaDeriveFacetErr(pctxt, fminlen, bfminlen, 1, 1, 1);
17280 if ((res != 0) && (bfminlen->fixed)) {
17281 FACET_RESTR_FIXED_ERR(fminlen)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017282 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017283 }
17284 if (fmaxlen && bfmaxlen) {
17285 /*
17286 * SCC "maxLength valid restriction"
17287 * maxLength <= BASE minLength
17288 */
17289 res = xmlSchemaCompareValues(fmaxlen->val, bfmaxlen->val);
17290 if (res == -2)
17291 goto internal_error;
17292 if (res == 1)
17293 xmlSchemaDeriveFacetErr(pctxt, fmaxlen, bfmaxlen, -1, 1, 1);
17294 if ((res != 0) && (bfmaxlen->fixed)) {
17295 FACET_RESTR_FIXED_ERR(fmaxlen)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017296 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017297 }
17298 /*
17299 * SCC "length and minLength or maxLength"
17300 */
17301 if (! flength)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017302 flength = bflength;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017303 if (flength) {
17304 if (! fminlen)
Miroslav Bajtos8f58f892009-08-07 17:22:12 +020017305 fminlen = bfminlen;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017306 if (fminlen) {
17307 /* (1.1) length >= minLength */
17308 res = xmlSchemaCompareValues(flength->val, fminlen->val);
17309 if (res == -2)
17310 goto internal_error;
17311 if (res == -1)
17312 xmlSchemaDeriveFacetErr(pctxt, flength, fminlen, 1, 1, 0);
17313 }
17314 if (! fmaxlen)
17315 fmaxlen = bfmaxlen;
17316 if (fmaxlen) {
17317 /* (2.1) length <= maxLength */
17318 res = xmlSchemaCompareValues(flength->val, fmaxlen->val);
17319 if (res == -2)
17320 goto internal_error;
17321 if (res == 1)
17322 xmlSchemaDeriveFacetErr(pctxt, flength, fmaxlen, -1, 1, 0);
17323 }
17324 }
17325 if (fmaxinc) {
17326 /*
17327 * "maxInclusive"
17328 */
17329 if (fmininc) {
17330 /* SCC "maxInclusive >= minInclusive" */
17331 res = xmlSchemaCompareValues(fmaxinc->val, fmininc->val);
17332 if (res == -2)
17333 goto internal_error;
17334 if (res == -1) {
17335 xmlSchemaDeriveFacetErr(pctxt, fmaxinc, fmininc, 1, 1, 0);
17336 }
17337 }
17338 /*
17339 * SCC "maxInclusive valid restriction"
17340 */
17341 if (bfmaxinc) {
17342 /* maxInclusive <= BASE maxInclusive */
17343 res = xmlSchemaCompareValues(fmaxinc->val, bfmaxinc->val);
17344 if (res == -2)
17345 goto internal_error;
17346 if (res == 1)
17347 xmlSchemaDeriveFacetErr(pctxt, fmaxinc, bfmaxinc, -1, 1, 1);
17348 if ((res != 0) && (bfmaxinc->fixed)) {
17349 FACET_RESTR_FIXED_ERR(fmaxinc)
17350 }
17351 }
17352 if (bfmaxexc) {
17353 /* maxInclusive < BASE maxExclusive */
17354 res = xmlSchemaCompareValues(fmaxinc->val, bfmaxexc->val);
17355 if (res == -2)
17356 goto internal_error;
17357 if (res != -1) {
17358 xmlSchemaDeriveFacetErr(pctxt, fmaxinc, bfmaxexc, -1, 0, 1);
17359 }
17360 }
17361 if (bfmininc) {
17362 /* maxInclusive >= BASE minInclusive */
17363 res = xmlSchemaCompareValues(fmaxinc->val, bfmininc->val);
17364 if (res == -2)
17365 goto internal_error;
17366 if (res == -1) {
17367 xmlSchemaDeriveFacetErr(pctxt, fmaxinc, bfmininc, 1, 1, 1);
17368 }
17369 }
17370 if (bfminexc) {
17371 /* maxInclusive > BASE minExclusive */
17372 res = xmlSchemaCompareValues(fmaxinc->val, bfminexc->val);
17373 if (res == -2)
17374 goto internal_error;
17375 if (res != 1) {
17376 xmlSchemaDeriveFacetErr(pctxt, fmaxinc, bfminexc, 1, 0, 1);
17377 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017378 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017379 }
17380 if (fmaxexc) {
17381 /*
17382 * "maxExclusive >= minExclusive"
17383 */
17384 if (fminexc) {
17385 res = xmlSchemaCompareValues(fmaxexc->val, fminexc->val);
17386 if (res == -2)
17387 goto internal_error;
17388 if (res == -1) {
17389 xmlSchemaDeriveFacetErr(pctxt, fmaxexc, fminexc, 1, 1, 0);
17390 }
17391 }
17392 /*
17393 * "maxExclusive valid restriction"
17394 */
17395 if (bfmaxexc) {
17396 /* maxExclusive <= BASE maxExclusive */
17397 res = xmlSchemaCompareValues(fmaxexc->val, bfmaxexc->val);
17398 if (res == -2)
17399 goto internal_error;
17400 if (res == 1) {
17401 xmlSchemaDeriveFacetErr(pctxt, fmaxexc, bfmaxexc, -1, 1, 1);
17402 }
17403 if ((res != 0) && (bfmaxexc->fixed)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017404 FACET_RESTR_FIXED_ERR(fmaxexc)
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017405 }
17406 }
17407 if (bfmaxinc) {
17408 /* maxExclusive <= BASE maxInclusive */
17409 res = xmlSchemaCompareValues(fmaxexc->val, bfmaxinc->val);
17410 if (res == -2)
17411 goto internal_error;
17412 if (res == 1) {
17413 xmlSchemaDeriveFacetErr(pctxt, fmaxexc, bfmaxinc, -1, 1, 1);
17414 }
17415 }
17416 if (bfmininc) {
17417 /* maxExclusive > BASE minInclusive */
17418 res = xmlSchemaCompareValues(fmaxexc->val, bfmininc->val);
17419 if (res == -2)
17420 goto internal_error;
17421 if (res != 1) {
17422 xmlSchemaDeriveFacetErr(pctxt, fmaxexc, bfmininc, 1, 0, 1);
17423 }
17424 }
17425 if (bfminexc) {
17426 /* maxExclusive > BASE minExclusive */
17427 res = xmlSchemaCompareValues(fmaxexc->val, bfminexc->val);
17428 if (res == -2)
17429 goto internal_error;
17430 if (res != 1) {
17431 xmlSchemaDeriveFacetErr(pctxt, fmaxexc, bfminexc, 1, 0, 1);
17432 }
17433 }
17434 }
17435 if (fminexc) {
17436 /*
17437 * "minExclusive < maxInclusive"
17438 */
17439 if (fmaxinc) {
17440 res = xmlSchemaCompareValues(fminexc->val, fmaxinc->val);
17441 if (res == -2)
17442 goto internal_error;
17443 if (res != -1) {
17444 xmlSchemaDeriveFacetErr(pctxt, fminexc, fmaxinc, -1, 0, 0);
17445 }
17446 }
17447 /*
17448 * "minExclusive valid restriction"
17449 */
17450 if (bfminexc) {
17451 /* minExclusive >= BASE minExclusive */
17452 res = xmlSchemaCompareValues(fminexc->val, bfminexc->val);
17453 if (res == -2)
17454 goto internal_error;
17455 if (res == -1) {
17456 xmlSchemaDeriveFacetErr(pctxt, fminexc, bfminexc, 1, 1, 1);
17457 }
17458 if ((res != 0) && (bfminexc->fixed)) {
17459 FACET_RESTR_FIXED_ERR(fminexc)
17460 }
17461 }
17462 if (bfmaxinc) {
17463 /* minExclusive <= BASE maxInclusive */
17464 res = xmlSchemaCompareValues(fminexc->val, bfmaxinc->val);
17465 if (res == -2)
17466 goto internal_error;
17467 if (res == 1) {
17468 xmlSchemaDeriveFacetErr(pctxt, fminexc, bfmaxinc, -1, 1, 1);
17469 }
17470 }
17471 if (bfmininc) {
17472 /* minExclusive >= BASE minInclusive */
17473 res = xmlSchemaCompareValues(fminexc->val, bfmininc->val);
17474 if (res == -2)
17475 goto internal_error;
17476 if (res == -1) {
17477 xmlSchemaDeriveFacetErr(pctxt, fminexc, bfmininc, 1, 1, 1);
17478 }
17479 }
17480 if (bfmaxexc) {
17481 /* minExclusive < BASE maxExclusive */
17482 res = xmlSchemaCompareValues(fminexc->val, bfmaxexc->val);
17483 if (res == -2)
17484 goto internal_error;
17485 if (res != -1) {
17486 xmlSchemaDeriveFacetErr(pctxt, fminexc, bfmaxexc, -1, 0, 1);
17487 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017488 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017489 }
17490 if (fmininc) {
17491 /*
17492 * "minInclusive < maxExclusive"
17493 */
17494 if (fmaxexc) {
17495 res = xmlSchemaCompareValues(fmininc->val, fmaxexc->val);
17496 if (res == -2)
17497 goto internal_error;
17498 if (res != -1) {
17499 xmlSchemaDeriveFacetErr(pctxt, fmininc, fmaxexc, -1, 0, 0);
17500 }
17501 }
17502 /*
17503 * "minExclusive valid restriction"
17504 */
17505 if (bfmininc) {
17506 /* minInclusive >= BASE minInclusive */
17507 res = xmlSchemaCompareValues(fmininc->val, bfmininc->val);
17508 if (res == -2)
17509 goto internal_error;
17510 if (res == -1) {
17511 xmlSchemaDeriveFacetErr(pctxt, fmininc, bfmininc, 1, 1, 1);
17512 }
17513 if ((res != 0) && (bfmininc->fixed)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017514 FACET_RESTR_FIXED_ERR(fmininc)
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017515 }
17516 }
17517 if (bfmaxinc) {
17518 /* minInclusive <= BASE maxInclusive */
17519 res = xmlSchemaCompareValues(fmininc->val, bfmaxinc->val);
17520 if (res == -2)
17521 goto internal_error;
Daniel Veillard0a119eb2005-07-20 13:46:00 +000017522 if (res == 1) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017523 xmlSchemaDeriveFacetErr(pctxt, fmininc, bfmaxinc, -1, 1, 1);
17524 }
17525 }
17526 if (bfminexc) {
17527 /* minInclusive > BASE minExclusive */
17528 res = xmlSchemaCompareValues(fmininc->val, bfminexc->val);
17529 if (res == -2)
17530 goto internal_error;
17531 if (res != 1)
17532 xmlSchemaDeriveFacetErr(pctxt, fmininc, bfminexc, 1, 0, 1);
17533 }
17534 if (bfmaxexc) {
17535 /* minInclusive < BASE maxExclusive */
17536 res = xmlSchemaCompareValues(fmininc->val, bfmaxexc->val);
17537 if (res == -2)
17538 goto internal_error;
17539 if (res != -1)
17540 xmlSchemaDeriveFacetErr(pctxt, fmininc, bfmaxexc, -1, 0, 1);
17541 }
17542 }
17543 if (ftotdig && bftotdig) {
17544 /*
17545 * SCC " totalDigits valid restriction"
17546 * totalDigits <= BASE totalDigits
17547 */
17548 res = xmlSchemaCompareValues(ftotdig->val, bftotdig->val);
17549 if (res == -2)
17550 goto internal_error;
17551 if (res == 1)
17552 xmlSchemaDeriveFacetErr(pctxt, ftotdig, bftotdig,
17553 -1, 1, 1);
17554 if ((res != 0) && (bftotdig->fixed)) {
17555 FACET_RESTR_FIXED_ERR(ftotdig)
17556 }
17557 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017558 if (ffracdig && bffracdig) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017559 /*
17560 * SCC "fractionDigits valid restriction"
17561 * fractionDigits <= BASE fractionDigits
17562 */
17563 res = xmlSchemaCompareValues(ffracdig->val, bffracdig->val);
17564 if (res == -2)
17565 goto internal_error;
17566 if (res == 1)
17567 xmlSchemaDeriveFacetErr(pctxt, ffracdig, bffracdig,
17568 -1, 1, 1);
17569 if ((res != 0) && (bffracdig->fixed)) {
17570 FACET_RESTR_FIXED_ERR(ffracdig)
17571 }
17572 }
17573 /*
17574 * SCC "fractionDigits less than or equal to totalDigits"
17575 */
17576 if (! ftotdig)
17577 ftotdig = bftotdig;
17578 if (! ffracdig)
17579 ffracdig = bffracdig;
17580 if (ftotdig && ffracdig) {
17581 res = xmlSchemaCompareValues(ffracdig->val, ftotdig->val);
17582 if (res == -2)
17583 goto internal_error;
17584 if (res == 1)
17585 xmlSchemaDeriveFacetErr(pctxt, ffracdig, ftotdig,
17586 -1, 1, 0);
17587 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017588 /*
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017589 * *Enumerations* won' be added here, since only the first set
17590 * of enumerations in the ancestor-or-self axis is used
17591 * for validation, plus we need to use the base type of those
17592 * enumerations for whitespace.
17593 *
17594 * *Patterns*: won't be add here, since they are ORed at
17595 * type level and ANDed at ancestor level. This will
17596 * happed during validation by walking the base axis
17597 * of the type.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017598 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017599 for (cur = base->facetSet; cur != NULL; cur = cur->next) {
17600 bfacet = cur->facet;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017601 /*
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017602 * Special handling of enumerations and patterns.
17603 * TODO: hmm, they should not appear in the set, so remove this.
17604 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017605 if ((bfacet->type == XML_SCHEMA_FACET_PATTERN) ||
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017606 (bfacet->type == XML_SCHEMA_FACET_ENUMERATION))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017607 continue;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017608 /*
17609 * Search for a duplicate facet in the current type.
17610 */
17611 link = type->facetSet;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000017612 /* err = 0; */
17613 /* fixedErr = 0; */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017614 while (link != NULL) {
17615 facet = link->facet;
17616 if (facet->type == bfacet->type) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017617 switch (facet->type) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017618 case XML_SCHEMA_FACET_WHITESPACE:
17619 /*
17620 * The whitespace must be stronger.
17621 */
17622 if (facet->whitespace < bfacet->whitespace) {
Rob Richardsc6947bb2008-06-29 15:04:41 +000017623 FACET_RESTR_ERR(facet,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017624 "The 'whitespace' value has to be equal to "
17625 "or stronger than the 'whitespace' value of "
17626 "the base type")
17627 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017628 if ((bfacet->fixed) &&
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017629 (facet->whitespace != bfacet->whitespace)) {
17630 FACET_RESTR_FIXED_ERR(facet)
17631 }
17632 break;
17633 default:
17634 break;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017635 }
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017636 /* Duplicate found. */
17637 break;
17638 }
17639 link = link->next;
17640 }
17641 /*
17642 * If no duplicate was found: add the base types's facet
17643 * to the set.
17644 */
17645 if (link == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017646 link = (xmlSchemaFacetLinkPtr)
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017647 xmlMalloc(sizeof(xmlSchemaFacetLink));
17648 if (link == NULL) {
17649 xmlSchemaPErrMemory(pctxt,
17650 "deriving facets, creating a facet link", NULL);
17651 return (-1);
17652 }
17653 link->facet = cur->facet;
17654 link->next = NULL;
17655 if (last == NULL)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017656 type->facetSet = link;
17657 else
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017658 last->next = link;
17659 last = link;
17660 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017661
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017662 }
17663
17664 return (0);
17665internal_error:
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017666 PERROR_INT("xmlSchemaDeriveAndValidateFacets",
17667 "an error occured");
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017668 return (-1);
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000017669}
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000017670
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000017671static int
17672xmlSchemaFinishMemberTypeDefinitionsProperty(xmlSchemaParserCtxtPtr pctxt,
17673 xmlSchemaTypePtr type)
17674{
17675 xmlSchemaTypeLinkPtr link, lastLink, prevLink, subLink, newLink;
17676 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017677 * The actual value is then formed by replacing any union type
Rob Richardsc6947bb2008-06-29 15:04:41 +000017678 * definition in the �explicit members� with the members of their
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000017679 * {member type definitions}, in order.
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000017680 *
17681 * TODO: There's a bug entry at
17682 * "http://lists.w3.org/Archives/Public/www-xml-schema-comments/2005JulSep/0287.html"
17683 * which indicates that we'll keep the union types the future.
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000017684 */
17685 link = type->memberTypes;
17686 while (link != NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017687
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000017688 if (WXS_IS_TYPE_NOT_FIXED(link->type))
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000017689 xmlSchemaTypeFixup(link->type, ACTXT_CAST pctxt);
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000017690
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000017691 if (WXS_IS_UNION(link->type)) {
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000017692 subLink = xmlSchemaGetUnionSimpleTypeMemberTypes(link->type);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017693 if (subLink != NULL) {
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000017694 link->type = subLink->type;
17695 if (subLink->next != NULL) {
17696 lastLink = link->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017697 subLink = subLink->next;
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000017698 prevLink = link;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017699 while (subLink != NULL) {
17700 newLink = (xmlSchemaTypeLinkPtr)
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000017701 xmlMalloc(sizeof(xmlSchemaTypeLink));
17702 if (newLink == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017703 xmlSchemaPErrMemory(pctxt, "allocating a type link",
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000017704 NULL);
17705 return (-1);
17706 }
17707 newLink->type = subLink->type;
17708 prevLink->next = newLink;
17709 prevLink = newLink;
17710 newLink->next = lastLink;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017711
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000017712 subLink = subLink->next;
17713 }
17714 }
17715 }
17716 }
17717 link = link->next;
17718 }
17719 return (0);
17720}
17721
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017722static void
17723xmlSchemaTypeFixupOptimFacets(xmlSchemaTypePtr type)
Daniel Veillarddee23482008-04-11 12:58:43 +000017724{
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017725 int has = 0, needVal = 0, normVal = 0;
17726
17727 has = (type->baseType->flags & XML_SCHEMAS_TYPE_HAS_FACETS) ? 1 : 0;
17728 if (has) {
17729 needVal = (type->baseType->flags &
17730 XML_SCHEMAS_TYPE_FACETSNEEDVALUE) ? 1 : 0;
17731 normVal = (type->baseType->flags &
17732 XML_SCHEMAS_TYPE_NORMVALUENEEDED) ? 1 : 0;
17733 }
17734 if (type->facets != NULL) {
17735 xmlSchemaFacetPtr fac;
Daniel Veillarddee23482008-04-11 12:58:43 +000017736
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017737 for (fac = type->facets; fac != NULL; fac = fac->next) {
17738 switch (fac->type) {
17739 case XML_SCHEMA_FACET_WHITESPACE:
17740 break;
17741 case XML_SCHEMA_FACET_PATTERN:
17742 normVal = 1;
17743 has = 1;
17744 break;
17745 case XML_SCHEMA_FACET_ENUMERATION:
17746 needVal = 1;
17747 normVal = 1;
17748 has = 1;
17749 break;
17750 default:
17751 has = 1;
17752 break;
17753 }
Daniel Veillarddee23482008-04-11 12:58:43 +000017754 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017755 }
17756 if (normVal)
17757 type->flags |= XML_SCHEMAS_TYPE_NORMVALUENEEDED;
17758 if (needVal)
17759 type->flags |= XML_SCHEMAS_TYPE_FACETSNEEDVALUE;
17760 if (has)
17761 type->flags |= XML_SCHEMAS_TYPE_HAS_FACETS;
17762
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000017763 if (has && (! needVal) && WXS_IS_ATOMIC(type)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017764 xmlSchemaTypePtr prim = xmlSchemaGetPrimitiveType(type);
17765 /*
17766 * OPTIMIZE VAL TODO: Some facets need a computed value.
17767 */
17768 if ((prim->builtInType != XML_SCHEMAS_ANYSIMPLETYPE) &&
17769 (prim->builtInType != XML_SCHEMAS_STRING)) {
17770 type->flags |= XML_SCHEMAS_TYPE_FACETSNEEDVALUE;
Daniel Veillarddee23482008-04-11 12:58:43 +000017771 }
17772 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017773}
17774
17775static int
17776xmlSchemaTypeFixupWhitespace(xmlSchemaTypePtr type)
17777{
Daniel Veillarddee23482008-04-11 12:58:43 +000017778
17779
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017780 /*
17781 * Evaluate the whitespace-facet value.
Daniel Veillarddee23482008-04-11 12:58:43 +000017782 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000017783 if (WXS_IS_LIST(type)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017784 type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_COLLAPSE;
17785 return (0);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000017786 } else if (WXS_IS_UNION(type))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017787 return (0);
Daniel Veillarddee23482008-04-11 12:58:43 +000017788
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017789 if (type->facetSet != NULL) {
17790 xmlSchemaFacetLinkPtr lin;
17791
17792 for (lin = type->facetSet; lin != NULL; lin = lin->next) {
17793 if (lin->facet->type == XML_SCHEMA_FACET_WHITESPACE) {
17794 switch (lin->facet->whitespace) {
17795 case XML_SCHEMAS_FACET_PRESERVE:
17796 type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_PRESERVE;
17797 break;
17798 case XML_SCHEMAS_FACET_REPLACE:
17799 type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_REPLACE;
17800 break;
17801 case XML_SCHEMAS_FACET_COLLAPSE:
17802 type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_COLLAPSE;
17803 break;
17804 default:
17805 return (-1);
17806 }
17807 return (0);
17808 }
17809 }
17810 }
17811 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000017812 * For all �atomic� datatypes other than string (and types �derived�
17813 * by �restriction� from it) the value of whiteSpace is fixed to
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017814 * collapse
17815 */
17816 {
17817 xmlSchemaTypePtr anc;
17818
Daniel Veillarddee23482008-04-11 12:58:43 +000017819 for (anc = type->baseType; anc != NULL &&
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017820 anc->builtInType != XML_SCHEMAS_ANYTYPE;
17821 anc = anc->baseType) {
17822
17823 if (anc->type == XML_SCHEMA_TYPE_BASIC) {
Daniel Veillarddee23482008-04-11 12:58:43 +000017824 if (anc->builtInType == XML_SCHEMAS_NORMSTRING) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017825 type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_REPLACE;
17826
17827 } else if ((anc->builtInType == XML_SCHEMAS_STRING) ||
Daniel Veillarddee23482008-04-11 12:58:43 +000017828 (anc->builtInType == XML_SCHEMAS_ANYSIMPLETYPE)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017829 type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_PRESERVE;
17830
17831 } else
17832 type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_COLLAPSE;
17833 break;
17834 }
17835 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017836 }
17837 return (0);
17838}
17839
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017840static int
17841xmlSchemaFixupSimpleTypeStageOne(xmlSchemaParserCtxtPtr pctxt,
17842 xmlSchemaTypePtr type)
Daniel Veillard4255d502002-04-16 15:50:10 +000017843{
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017844 if (type->type != XML_SCHEMA_TYPE_SIMPLE)
17845 return(0);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000017846 if (! WXS_IS_TYPE_NOT_FIXED_1(type))
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017847 return(0);
17848 type->flags |= XML_SCHEMAS_TYPE_FIXUP_1;
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000017849
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000017850 if (WXS_IS_LIST(type)) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017851 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017852 * Corresponds to <simpleType><list>...
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017853 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017854 if (type->subtypes == NULL) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017855 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017856 * This one is really needed, so get out.
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017857 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017858 PERROR_INT("xmlSchemaFixupSimpleTypeStageOne",
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017859 "list type has no item-type assigned");
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017860 return(-1);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017861 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000017862 } else if (WXS_IS_UNION(type)) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017863 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017864 * Corresponds to <simpleType><union>...
Daniel Veillarddee23482008-04-11 12:58:43 +000017865 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017866 if (type->memberTypes == NULL) {
17867 /*
17868 * This one is really needed, so get out.
17869 */
17870 PERROR_INT("xmlSchemaFixupSimpleTypeStageOne",
17871 "union type has no member-types assigned");
17872 return(-1);
Daniel Veillarddee23482008-04-11 12:58:43 +000017873 }
17874 } else {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017875 /*
17876 * Corresponds to <simpleType><restriction>...
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017877 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017878 if (type->baseType == NULL) {
17879 PERROR_INT("xmlSchemaFixupSimpleTypeStageOne",
17880 "type has no base-type assigned");
17881 return(-1);
17882 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000017883 if (WXS_IS_TYPE_NOT_FIXED_1(type->baseType))
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017884 if (xmlSchemaFixupSimpleTypeStageOne(pctxt, type->baseType) == -1)
17885 return(-1);
17886 /*
17887 * Variety
17888 * If the <restriction> alternative is chosen, then the
17889 * {variety} of the {base type definition}.
17890 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000017891 if (WXS_IS_ATOMIC(type->baseType))
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017892 type->flags |= XML_SCHEMAS_TYPE_VARIETY_ATOMIC;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000017893 else if (WXS_IS_LIST(type->baseType)) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017894 type->flags |= XML_SCHEMAS_TYPE_VARIETY_LIST;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017895 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017896 * Inherit the itemType.
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017897 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017898 type->subtypes = type->baseType->subtypes;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000017899 } else if (WXS_IS_UNION(type->baseType)) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017900 type->flags |= XML_SCHEMAS_TYPE_VARIETY_UNION;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017901 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017902 * NOTE that we won't assign the memberTypes of the base,
17903 * since this will make trouble when freeing them; we will
17904 * use a lookup function to access them instead.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017905 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017906 }
Daniel Veillardd0c9c322003-10-10 00:49:42 +000017907 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017908 return(0);
17909}
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017910
Daniel Veillard8651f532002-04-17 09:06:27 +000017911#ifdef DEBUG_TYPE
Daniel Veillard67952602006-01-05 15:29:44 +000017912static void
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017913xmlSchemaDebugFixedType(xmlSchemaParserCtxtPtr pctxt,
17914 xmlSchemaTypePtr type)
17915{
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017916 if (type->node != NULL) {
Daniel Veillardd0c9c322003-10-10 00:49:42 +000017917 xmlGenericError(xmlGenericErrorContext,
17918 "Type of %s : %s:%d :", name,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017919 type->node->doc->URL,
17920 xmlGetLineNo(type->node));
Daniel Veillarddecd64d2002-04-18 14:41:51 +000017921 } else {
Daniel Veillardd0c9c322003-10-10 00:49:42 +000017922 xmlGenericError(xmlGenericErrorContext, "Type of %s :", name);
Daniel Veillarddecd64d2002-04-18 14:41:51 +000017923 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000017924 if ((WXS_IS_SIMPLE(type)) || (WXS_IS_COMPLEX(type))) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017925 switch (type->contentType) {
17926 case XML_SCHEMA_CONTENT_SIMPLE:
17927 xmlGenericError(xmlGenericErrorContext, "simple\n");
17928 break;
17929 case XML_SCHEMA_CONTENT_ELEMENTS:
17930 xmlGenericError(xmlGenericErrorContext, "elements\n");
17931 break;
17932 case XML_SCHEMA_CONTENT_UNKNOWN:
17933 xmlGenericError(xmlGenericErrorContext, "unknown !!!\n");
17934 break;
17935 case XML_SCHEMA_CONTENT_EMPTY:
17936 xmlGenericError(xmlGenericErrorContext, "empty\n");
17937 break;
17938 case XML_SCHEMA_CONTENT_MIXED:
17939 if (xmlSchemaIsParticleEmptiable((xmlSchemaParticlePtr)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000017940 type->subtypes))
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000017941 xmlGenericError(xmlGenericErrorContext,
17942 "mixed as emptiable particle\n");
17943 else
17944 xmlGenericError(xmlGenericErrorContext, "mixed\n");
17945 break;
17946 /* Removed, since not used. */
17947 /*
17948 case XML_SCHEMA_CONTENT_MIXED_OR_ELEMENTS:
17949 xmlGenericError(xmlGenericErrorContext, "mixed or elems\n");
17950 break;
17951 */
17952 case XML_SCHEMA_CONTENT_BASIC:
17953 xmlGenericError(xmlGenericErrorContext, "basic\n");
17954 break;
17955 default:
17956 xmlGenericError(xmlGenericErrorContext,
17957 "not registered !!!\n");
17958 break;
17959 }
Daniel Veillard8651f532002-04-17 09:06:27 +000017960 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017961}
Daniel Veillard8651f532002-04-17 09:06:27 +000017962#endif
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017963
17964/*
17965* 3.14.6 Constraints on Simple Type Definition Schema Components
17966*/
17967static int
17968xmlSchemaFixupSimpleTypeStageTwo(xmlSchemaParserCtxtPtr pctxt,
17969 xmlSchemaTypePtr type)
17970{
17971 int res, olderrs = pctxt->nberrors;
17972
17973 if (type->type != XML_SCHEMA_TYPE_SIMPLE)
17974 return(-1);
17975
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000017976 if (! WXS_IS_TYPE_NOT_FIXED(type))
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017977 return(0);
17978
17979 type->flags |= XML_SCHEMAS_TYPE_INTERNAL_RESOLVED;
17980 type->contentType = XML_SCHEMA_CONTENT_SIMPLE;
17981
17982 if (type->baseType == NULL) {
17983 PERROR_INT("xmlSchemaFixupSimpleTypeStageTwo",
17984 "missing baseType");
17985 goto exit_failure;
17986 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000017987 if (WXS_IS_TYPE_NOT_FIXED(type->baseType))
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000017988 xmlSchemaTypeFixup(type->baseType, ACTXT_CAST pctxt);
Daniel Veillarddee23482008-04-11 12:58:43 +000017989 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017990 * If a member type of a union is a union itself, we need to substitute
17991 * that member type for its member types.
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000017992 * NOTE that this might change in WXS 1.1; i.e. we will keep the union
17993 * types in WXS 1.1.
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017994 */
17995 if ((type->memberTypes != NULL) &&
17996 (xmlSchemaFinishMemberTypeDefinitionsProperty(pctxt, type) == -1))
Daniel Veillarddee23482008-04-11 12:58:43 +000017997 return(-1);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000017998 /*
Daniel Veillarddee23482008-04-11 12:58:43 +000017999 * SPEC src-simple-type 1
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018000 * "The corresponding simple type definition, if any, must satisfy
18001 * the conditions set out in Constraints on Simple Type Definition
Rob Richardsc6947bb2008-06-29 15:04:41 +000018002 * Schema Components (�3.14.6)."
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018003 */
18004 /*
18005 * Schema Component Constraint: Simple Type Definition Properties Correct
18006 * (st-props-correct)
18007 */
18008 res = xmlSchemaCheckSTPropsCorrect(pctxt, type);
18009 HFAILURE HERROR
Daniel Veillarddee23482008-04-11 12:58:43 +000018010 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018011 * Schema Component Constraint: Derivation Valid (Restriction, Simple)
18012 * (cos-st-restricts)
18013 */
18014 res = xmlSchemaCheckCOSSTRestricts(pctxt, type);
18015 HFAILURE HERROR
18016 /*
18017 * TODO: Removed the error report, since it got annoying to get an
18018 * extra error report, if anything failed until now.
18019 * Enable this if needed.
18020 *
18021 * xmlSchemaPErr(ctxt, type->node,
18022 * XML_SCHEMAP_SRC_SIMPLE_TYPE_1,
18023 * "Simple type '%s' does not satisfy the constraints "
18024 * "on simple type definitions.\n",
18025 * type->name, NULL);
18026 */
18027 /*
18028 * Schema Component Constraint: Simple Type Restriction (Facets)
18029 * (st-restrict-facets)
18030 */
18031 res = xmlSchemaCheckFacetValues(type, pctxt);
18032 HFAILURE HERROR
18033 if ((type->facetSet != NULL) ||
18034 (type->baseType->facetSet != NULL)) {
18035 res = xmlSchemaDeriveAndValidateFacets(pctxt, type);
18036 HFAILURE HERROR
18037 }
18038 /*
18039 * Whitespace value.
18040 */
18041 res = xmlSchemaTypeFixupWhitespace(type);
18042 HFAILURE HERROR
Daniel Veillarddee23482008-04-11 12:58:43 +000018043 xmlSchemaTypeFixupOptimFacets(type);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018044
18045exit_error:
18046#ifdef DEBUG_TYPE
18047 xmlSchemaDebugFixedType(pctxt, type);
18048#endif
18049 if (olderrs != pctxt->nberrors)
18050 return(pctxt->err);
18051 return(0);
18052
18053exit_failure:
18054#ifdef DEBUG_TYPE
18055 xmlSchemaDebugFixedType(pctxt, type);
18056#endif
18057 return(-1);
18058}
18059
18060static int
18061xmlSchemaFixupComplexType(xmlSchemaParserCtxtPtr pctxt,
18062 xmlSchemaTypePtr type)
18063{
18064 int res = 0, olderrs = pctxt->nberrors;
18065 xmlSchemaTypePtr baseType = type->baseType;
18066
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018067 if (! WXS_IS_TYPE_NOT_FIXED(type))
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018068 return(0);
18069 type->flags |= XML_SCHEMAS_TYPE_INTERNAL_RESOLVED;
18070 if (baseType == NULL) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018071 PERROR_INT("xmlSchemaFixupComplexType",
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018072 "missing baseType");
18073 goto exit_failure;
Daniel Veillarddee23482008-04-11 12:58:43 +000018074 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018075 /*
18076 * Fixup the base type.
18077 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018078 if (WXS_IS_TYPE_NOT_FIXED(baseType))
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000018079 xmlSchemaTypeFixup(baseType, ACTXT_CAST pctxt);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018080 if (baseType->flags & XML_SCHEMAS_TYPE_INTERNAL_INVALID) {
18081 /*
18082 * Skip fixup if the base type is invalid.
18083 * TODO: Generate a warning!
18084 */
18085 return(0);
Daniel Veillarddee23482008-04-11 12:58:43 +000018086 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018087 /*
18088 * This basically checks if the base type can be derived.
18089 */
18090 res = xmlSchemaCheckSRCCT(pctxt, type);
Daniel Veillarddee23482008-04-11 12:58:43 +000018091 HFAILURE HERROR
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018092 /*
18093 * Fixup the content type.
18094 */
18095 if (type->contentType == XML_SCHEMA_CONTENT_SIMPLE) {
18096 /*
18097 * Corresponds to <complexType><simpleContent>...
18098 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018099 if ((WXS_IS_COMPLEX(baseType)) &&
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018100 (baseType->contentTypeDef != NULL) &&
18101 (WXS_IS_RESTRICTION(type))) {
18102 xmlSchemaTypePtr contentBase, content;
18103#ifdef ENABLE_NAMED_LOCALS
18104 char buf[30];
18105 const xmlChar *tmpname;
18106#endif
18107 /*
18108 * SPEC (1) If <restriction> + base type is <complexType>,
18109 * "whose own {content type} is a simple type..."
18110 */
18111 if (type->contentTypeDef != NULL) {
18112 /*
18113 * SPEC (1.1) "the simple type definition corresponding to the
18114 * <simpleType> among the [children] of <restriction> if there
18115 * is one;"
18116 * Note that this "<simpleType> among the [children]" was put
18117 * into ->contentTypeDef during parsing.
18118 */
18119 contentBase = type->contentTypeDef;
18120 type->contentTypeDef = NULL;
18121 } else {
18122 /*
18123 * (1.2) "...otherwise (<restriction> has no <simpleType>
18124 * among its [children]), the simple type definition which
18125 * is the {content type} of the ... base type."
18126 */
18127 contentBase = baseType->contentTypeDef;
18128 }
18129 /*
18130 * SPEC
18131 * "... a simple type definition which restricts the simple
18132 * type definition identified in clause 1.1 or clause 1.2
18133 * with a set of facet components"
18134 *
18135 * Create the anonymous simple type, which will be the content
18136 * type of the complex type.
18137 */
18138#ifdef ENABLE_NAMED_LOCALS
18139 snprintf(buf, 29, "#scST%d", ++(pctxt->counter));
18140 tmpname = xmlDictLookup(pctxt->dict, BAD_CAST buf, -1);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018141 content = xmlSchemaAddType(pctxt, pctxt->schema,
18142 XML_SCHEMA_TYPE_SIMPLE, tmpname, type->targetNamespace,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018143 type->node, 0);
18144#else
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018145 content = xmlSchemaAddType(pctxt, pctxt->schema,
18146 XML_SCHEMA_TYPE_SIMPLE, NULL, type->targetNamespace,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018147 type->node, 0);
18148#endif
18149 if (content == NULL)
18150 goto exit_failure;
18151 /*
18152 * We will use the same node as for the <complexType>
18153 * to have it somehow anchored in the schema doc.
18154 */
18155 content->type = XML_SCHEMA_TYPE_SIMPLE;
18156 content->baseType = contentBase;
18157 /*
18158 * Move the facets, previously anchored on the
18159 * complexType during parsing.
18160 */
18161 content->facets = type->facets;
18162 type->facets = NULL;
18163 content->facetSet = type->facetSet;
18164 type->facetSet = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000018165
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018166 type->contentTypeDef = content;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018167 if (WXS_IS_TYPE_NOT_FIXED(contentBase))
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000018168 xmlSchemaTypeFixup(contentBase, ACTXT_CAST pctxt);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018169 /*
18170 * Fixup the newly created type. We don't need to check
18171 * for circularity here.
18172 */
18173 res = xmlSchemaFixupSimpleTypeStageOne(pctxt, content);
Daniel Veillarddee23482008-04-11 12:58:43 +000018174 HFAILURE HERROR
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018175 res = xmlSchemaFixupSimpleTypeStageTwo(pctxt, content);
Daniel Veillarddee23482008-04-11 12:58:43 +000018176 HFAILURE HERROR
18177
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018178 } else if ((WXS_IS_COMPLEX(baseType)) &&
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018179 (baseType->contentType == XML_SCHEMA_CONTENT_MIXED) &&
18180 (WXS_IS_RESTRICTION(type))) {
18181 /*
18182 * SPEC (2) If <restriction> + base is a mixed <complexType> with
18183 * an emptiable particle, then a simple type definition which
18184 * restricts the <restriction>'s <simpleType> child.
18185 */
18186 if ((type->contentTypeDef == NULL) ||
18187 (type->contentTypeDef->baseType == NULL)) {
18188 /*
18189 * TODO: Check if this ever happens.
18190 */
18191 xmlSchemaPCustomErr(pctxt,
18192 XML_SCHEMAP_INTERNAL,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018193 WXS_BASIC_CAST type, NULL,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018194 "Internal error: xmlSchemaTypeFixup, "
18195 "complex type '%s': the <simpleContent><restriction> "
18196 "is missing a <simpleType> child, but was not catched "
18197 "by xmlSchemaCheckSRCCT()", type->name);
18198 goto exit_failure;
18199 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018200 } else if ((WXS_IS_COMPLEX(baseType)) && WXS_IS_EXTENSION(type)) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018201 /*
18202 * SPEC (3) If <extension> + base is <complexType> with
18203 * <simpleType> content, "...then the {content type} of that
18204 * complex type definition"
18205 */
18206 if (baseType->contentTypeDef == NULL) {
18207 /*
18208 * TODO: Check if this ever happens. xmlSchemaCheckSRCCT
18209 * should have catched this already.
18210 */
18211 xmlSchemaPCustomErr(pctxt,
18212 XML_SCHEMAP_INTERNAL,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018213 WXS_BASIC_CAST type, NULL,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018214 "Internal error: xmlSchemaTypeFixup, "
18215 "complex type '%s': the <extension>ed base type is "
18216 "a complex type with no simple content type",
18217 type->name);
18218 goto exit_failure;
18219 }
18220 type->contentTypeDef = baseType->contentTypeDef;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018221 } else if ((WXS_IS_SIMPLE(baseType)) && WXS_IS_EXTENSION(type)) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018222 /*
18223 * SPEC (4) <extension> + base is <simpleType>
18224 * "... then that simple type definition"
18225 */
18226 type->contentTypeDef = baseType;
18227 } else {
18228 /*
18229 * TODO: Check if this ever happens.
18230 */
18231 xmlSchemaPCustomErr(pctxt,
18232 XML_SCHEMAP_INTERNAL,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018233 WXS_BASIC_CAST type, NULL,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018234 "Internal error: xmlSchemaTypeFixup, "
18235 "complex type '%s' with <simpleContent>: unhandled "
18236 "derivation case", type->name);
18237 goto exit_failure;
18238 }
18239 } else {
18240 int dummySequence = 0;
18241 xmlSchemaParticlePtr particle =
18242 (xmlSchemaParticlePtr) type->subtypes;
18243 /*
18244 * Corresponds to <complexType><complexContent>...
18245 *
18246 * NOTE that the effective mixed was already set during parsing of
18247 * <complexType> and <complexContent>; its flag value is
18248 * XML_SCHEMAS_TYPE_MIXED.
18249 *
18250 * Compute the "effective content":
18251 * (2.1.1) + (2.1.2) + (2.1.3)
18252 */
18253 if ((particle == NULL) ||
18254 ((particle->type == XML_SCHEMA_TYPE_PARTICLE) &&
18255 ((particle->children->type == XML_SCHEMA_TYPE_ALL) ||
18256 (particle->children->type == XML_SCHEMA_TYPE_SEQUENCE) ||
18257 ((particle->children->type == XML_SCHEMA_TYPE_CHOICE) &&
18258 (particle->minOccurs == 0))) &&
18259 ( ((xmlSchemaTreeItemPtr) particle->children)->children == NULL))) {
18260 if (type->flags & XML_SCHEMAS_TYPE_MIXED) {
18261 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000018262 * SPEC (2.1.4) "If the �effective mixed� is true, then
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018263 * a particle whose properties are as follows:..."
18264 *
18265 * Empty sequence model group with
18266 * minOccurs/maxOccurs = 1 (i.e. a "particle emptiable").
18267 * NOTE that we sill assign it the <complexType> node to
18268 * somehow anchor it in the doc.
18269 */
18270 if ((particle == NULL) ||
18271 (particle->children->type != XML_SCHEMA_TYPE_SEQUENCE)) {
18272 /*
18273 * Create the particle.
18274 */
Kasimier T. Buchcik4c0aa162006-02-20 14:47:08 +000018275 particle = xmlSchemaAddParticle(pctxt,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018276 type->node, 1, 1);
18277 if (particle == NULL)
18278 goto exit_failure;
18279 /*
18280 * Create the model group.
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018281 */ /* URGENT TODO: avoid adding to pending items. */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018282 particle->children = (xmlSchemaTreeItemPtr)
18283 xmlSchemaAddModelGroup(pctxt, pctxt->schema,
18284 XML_SCHEMA_TYPE_SEQUENCE, type->node);
18285 if (particle->children == NULL)
18286 goto exit_failure;
Daniel Veillarddee23482008-04-11 12:58:43 +000018287
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018288 type->subtypes = (xmlSchemaTypePtr) particle;
18289 }
18290 dummySequence = 1;
18291 type->contentType = XML_SCHEMA_CONTENT_ELEMENTS;
18292 } else {
18293 /*
18294 * SPEC (2.1.5) "otherwise empty"
18295 */
18296 type->contentType = XML_SCHEMA_CONTENT_EMPTY;
18297 }
18298 } else {
18299 /*
18300 * SPEC (2.2) "otherwise the particle corresponding to the
18301 * <all>, <choice>, <group> or <sequence> among the
18302 * [children]."
18303 */
18304 type->contentType = XML_SCHEMA_CONTENT_ELEMENTS;
18305 }
18306 /*
18307 * Compute the "content type".
18308 */
18309 if (WXS_IS_RESTRICTION(type)) {
18310 /*
18311 * SPEC (3.1) "If <restriction>..."
18312 * (3.1.1) + (3.1.2) */
18313 if (type->contentType != XML_SCHEMA_CONTENT_EMPTY) {
18314 if (type->flags & XML_SCHEMAS_TYPE_MIXED)
18315 type->contentType = XML_SCHEMA_CONTENT_MIXED;
18316 }
18317 } else {
18318 /*
18319 * SPEC (3.2) "If <extension>..."
18320 */
18321 if (type->contentType == XML_SCHEMA_CONTENT_EMPTY) {
18322 /*
18323 * SPEC (3.2.1)
Rob Richardsc6947bb2008-06-29 15:04:41 +000018324 * "If the �effective content� is empty, then the
Kasimier T. Buchcikf896d442006-07-12 15:18:08 +000018325 * {content type} of the [...] base ..."
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018326 */
18327 type->contentType = baseType->contentType;
18328 type->subtypes = baseType->subtypes;
18329 /*
Kasimier T. Buchcikf896d442006-07-12 15:18:08 +000018330 * Fixes bug #347316:
18331 * This is the case when the base type has a simple
18332 * type definition as content.
18333 */
18334 type->contentTypeDef = baseType->contentTypeDef;
18335 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018336 * NOTE that the effective mixed is ignored here.
18337 */
18338 } else if (baseType->contentType == XML_SCHEMA_CONTENT_EMPTY) {
18339 /*
18340 * SPEC (3.2.2)
18341 */
18342 if (type->flags & XML_SCHEMAS_TYPE_MIXED)
18343 type->contentType = XML_SCHEMA_CONTENT_MIXED;
18344 } else {
18345 /*
18346 * SPEC (3.2.3)
18347 */
18348 if (type->flags & XML_SCHEMAS_TYPE_MIXED)
18349 type->contentType = XML_SCHEMA_CONTENT_MIXED;
18350 /*
18351 * "A model group whose {compositor} is sequence and whose
18352 * {particles} are..."
18353 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018354 if ((WXS_TYPE_PARTICLE(type) != NULL) &&
18355 (WXS_TYPE_PARTICLE_TERM(type) != NULL) &&
18356 ((WXS_TYPE_PARTICLE_TERM(type))->type ==
18357 XML_SCHEMA_TYPE_ALL))
18358 {
18359 /*
18360 * SPEC cos-all-limited (1)
18361 */
18362 xmlSchemaCustomErr(ACTXT_CAST pctxt,
18363 /* TODO: error code */
18364 XML_SCHEMAP_COS_ALL_LIMITED,
18365 WXS_ITEM_NODE(type), NULL,
18366 "The type has an 'all' model group in its "
18367 "{content type} and thus cannot be derived from "
18368 "a non-empty type, since this would produce a "
18369 "'sequence' model group containing the 'all' "
18370 "model group; 'all' model groups are not "
18371 "allowed to appear inside other model groups",
18372 NULL, NULL);
18373
18374 } else if ((WXS_TYPE_PARTICLE(baseType) != NULL) &&
18375 (WXS_TYPE_PARTICLE_TERM(baseType) != NULL) &&
18376 ((WXS_TYPE_PARTICLE_TERM(baseType))->type ==
18377 XML_SCHEMA_TYPE_ALL))
18378 {
18379 /*
18380 * SPEC cos-all-limited (1)
18381 */
18382 xmlSchemaCustomErr(ACTXT_CAST pctxt,
18383 /* TODO: error code */
18384 XML_SCHEMAP_COS_ALL_LIMITED,
18385 WXS_ITEM_NODE(type), NULL,
18386 "A type cannot be derived by extension from a type "
18387 "which has an 'all' model group in its "
18388 "{content type}, since this would produce a "
18389 "'sequence' model group containing the 'all' "
18390 "model group; 'all' model groups are not "
18391 "allowed to appear inside other model groups",
18392 NULL, NULL);
18393
18394 } else if (! dummySequence) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018395 xmlSchemaTreeItemPtr effectiveContent =
18396 (xmlSchemaTreeItemPtr) type->subtypes;
18397 /*
18398 * Create the particle.
18399 */
Kasimier T. Buchcik4c0aa162006-02-20 14:47:08 +000018400 particle = xmlSchemaAddParticle(pctxt,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018401 type->node, 1, 1);
18402 if (particle == NULL)
18403 goto exit_failure;
18404 /*
18405 * Create the "sequence" model group.
18406 */
18407 particle->children = (xmlSchemaTreeItemPtr)
18408 xmlSchemaAddModelGroup(pctxt, pctxt->schema,
18409 XML_SCHEMA_TYPE_SEQUENCE, type->node);
18410 if (particle->children == NULL)
18411 goto exit_failure;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018412 WXS_TYPE_CONTENTTYPE(type) = (xmlSchemaTypePtr) particle;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018413 /*
18414 * SPEC "the particle of the {content type} of
18415 * the ... base ..."
18416 * Create a duplicate of the base type's particle
18417 * and assign its "term" to it.
18418 */
18419 particle->children->children =
18420 (xmlSchemaTreeItemPtr) xmlSchemaAddParticle(pctxt,
Kasimier T. Buchcik4c0aa162006-02-20 14:47:08 +000018421 type->node,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018422 ((xmlSchemaParticlePtr) type->subtypes)->minOccurs,
18423 ((xmlSchemaParticlePtr) type->subtypes)->maxOccurs);
18424 if (particle->children->children == NULL)
18425 goto exit_failure;
18426 particle = (xmlSchemaParticlePtr)
18427 particle->children->children;
18428 particle->children =
18429 ((xmlSchemaParticlePtr) baseType->subtypes)->children;
18430 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000018431 * SPEC "followed by the �effective content�."
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018432 */
18433 particle->next = effectiveContent;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018434 /*
18435 * This all will result in:
18436 * new-particle
18437 * --> new-sequence(
18438 * new-particle
18439 * --> base-model,
18440 * this-particle
18441 * --> this-model
18442 * )
18443 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018444 } else {
18445 /*
18446 * This is the case when there is already an empty
18447 * <sequence> with minOccurs==maxOccurs==1.
18448 * Just add the base types's content type.
18449 * NOTE that, although we miss to add an intermediate
18450 * <sequence>, this should produce no difference to
18451 * neither the regex compilation of the content model,
18452 * nor to the complex type contraints.
18453 */
18454 particle->children->children =
18455 (xmlSchemaTreeItemPtr) baseType->subtypes;
18456 }
18457 }
18458 }
18459 }
18460 /*
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018461 * Now fixup attribute uses:
18462 * - expand attr. group references
18463 * - intersect attribute wildcards
18464 * - inherit attribute uses of the base type
18465 * - inherit or union attr. wildcards if extending
18466 * - apply attr. use prohibitions if restricting
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018467 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018468 res = xmlSchemaFixupTypeAttributeUses(pctxt, type);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018469 HFAILURE HERROR
18470 /*
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018471 * Apply the complex type component constraints; this will not
18472 * check attributes, since this is done in
18473 * xmlSchemaFixupTypeAttributeUses().
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018474 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018475 res = xmlSchemaCheckCTComponent(pctxt, type);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018476 HFAILURE HERROR
18477
18478#ifdef DEBUG_TYPE
18479 xmlSchemaDebugFixedType(pctxt, type);
18480#endif
18481 if (olderrs != pctxt->nberrors)
18482 return(pctxt->err);
18483 else
18484 return(0);
18485
18486exit_error:
18487 type->flags |= XML_SCHEMAS_TYPE_INTERNAL_INVALID;
18488#ifdef DEBUG_TYPE
18489 xmlSchemaDebugFixedType(pctxt, type);
18490#endif
18491 return(pctxt->err);
18492
18493exit_failure:
18494 type->flags |= XML_SCHEMAS_TYPE_INTERNAL_INVALID;
18495#ifdef DEBUG_TYPE
18496 xmlSchemaDebugFixedType(pctxt, type);
18497#endif
18498 return(-1);
18499}
18500
18501
18502/**
18503 * xmlSchemaTypeFixup:
18504 * @typeDecl: the schema type definition
18505 * @ctxt: the schema parser context
18506 *
18507 * Fixes the content model of the type.
18508 * URGENT TODO: We need an int result!
18509 */
18510static int
18511xmlSchemaTypeFixup(xmlSchemaTypePtr type,
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000018512 xmlSchemaAbstractCtxtPtr actxt)
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018513{
18514 if (type == NULL)
18515 return(0);
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000018516 if (actxt->type != XML_SCHEMA_CTXT_PARSER) {
18517 AERROR_INT("xmlSchemaTypeFixup",
18518 "this function needs a parser context");
18519 return(-1);
18520 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018521 if (! WXS_IS_TYPE_NOT_FIXED(type))
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018522 return(0);
18523 if (type->type == XML_SCHEMA_TYPE_COMPLEX)
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000018524 return(xmlSchemaFixupComplexType(PCTXT_CAST actxt, type));
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018525 else if (type->type == XML_SCHEMA_TYPE_SIMPLE)
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000018526 return(xmlSchemaFixupSimpleTypeStageTwo(PCTXT_CAST actxt, type));
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018527 return(0);
Daniel Veillard4255d502002-04-16 15:50:10 +000018528}
18529
18530/**
Daniel Veillard8bc6cf92003-02-27 17:42:22 +000018531 * xmlSchemaCheckFacet:
18532 * @facet: the facet
18533 * @typeDecl: the schema type definition
Daniel Veillard81562d22005-06-15 13:27:56 +000018534 * @pctxt: the schema parser context or NULL
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018535 * @name: the optional name of the type
Daniel Veillard8bc6cf92003-02-27 17:42:22 +000018536 *
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018537 * Checks and computes the values of facets.
Daniel Veillard8bc6cf92003-02-27 17:42:22 +000018538 *
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018539 * Returns 0 if valid, a positive error code if not valid and
18540 * -1 in case of an internal or API error.
Daniel Veillard8bc6cf92003-02-27 17:42:22 +000018541 */
18542int
18543xmlSchemaCheckFacet(xmlSchemaFacetPtr facet,
Daniel Veillardd0c9c322003-10-10 00:49:42 +000018544 xmlSchemaTypePtr typeDecl,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018545 xmlSchemaParserCtxtPtr pctxt,
18546 const xmlChar * name ATTRIBUTE_UNUSED)
Daniel Veillard8bc6cf92003-02-27 17:42:22 +000018547{
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018548 int ret = 0, ctxtGiven;
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000018549
Daniel Veillardce682bc2004-11-05 17:22:25 +000018550 if ((facet == NULL) || (typeDecl == NULL))
18551 return(-1);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018552 /*
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000018553 * TODO: will the parser context be given if used from
18554 * the relaxNG module?
18555 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018556 if (pctxt == NULL)
18557 ctxtGiven = 0;
18558 else
18559 ctxtGiven = 1;
Daniel Veillard8bc6cf92003-02-27 17:42:22 +000018560
Daniel Veillard8bc6cf92003-02-27 17:42:22 +000018561 switch (facet->type) {
Daniel Veillardd0c9c322003-10-10 00:49:42 +000018562 case XML_SCHEMA_FACET_MININCLUSIVE:
18563 case XML_SCHEMA_FACET_MINEXCLUSIVE:
18564 case XML_SCHEMA_FACET_MAXINCLUSIVE:
Daniel Veillardf4b05d02004-07-05 13:10:37 +000018565 case XML_SCHEMA_FACET_MAXEXCLUSIVE:
18566 case XML_SCHEMA_FACET_ENUMERATION: {
Daniel Veillardd0c9c322003-10-10 00:49:42 +000018567 /*
18568 * Okay we need to validate the value
18569 * at that point.
18570 */
Daniel Veillard01fa6152004-06-29 17:04:39 +000018571 xmlSchemaTypePtr base;
Daniel Veillardf4b05d02004-07-05 13:10:37 +000018572
18573 /* 4.3.5.5 Constraints on enumeration Schema Components
18574 * Schema Component Constraint: enumeration valid restriction
Rob Richardsc6947bb2008-06-29 15:04:41 +000018575 * It is an �error� if any member of {value} is not in the
18576 * �value space� of {base type definition}.
Daniel Veillardf4b05d02004-07-05 13:10:37 +000018577 *
18578 * minInclusive, maxInclusive, minExclusive, maxExclusive:
Rob Richardsc6947bb2008-06-29 15:04:41 +000018579 * The value �must� be in the
18580 * �value space� of the �base type�.
Daniel Veillardf4b05d02004-07-05 13:10:37 +000018581 */
18582 /*
18583 * This function is intended to deliver a compiled value
Kasimier T. Buchcik478d6932005-03-16 16:29:18 +000018584 * on the facet. In this implementation of XML Schemata the
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018585 * type holding a facet, won't be a built-in type.
Kasimier T. Buchcik478d6932005-03-16 16:29:18 +000018586 * Thus to ensure that other API
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018587 * calls (relaxng) do work, if the given type is a built-in
Daniel Veillardf4b05d02004-07-05 13:10:37 +000018588 * type, we will assume that the given built-in type *is
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018589 * already* the base type.
Daniel Veillardf4b05d02004-07-05 13:10:37 +000018590 */
18591 if (typeDecl->type != XML_SCHEMA_TYPE_BASIC) {
18592 base = typeDecl->baseType;
18593 if (base == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018594 PERROR_INT("xmlSchemaCheckFacet",
18595 "a type user derived type has no base type");
Daniel Veillardf4b05d02004-07-05 13:10:37 +000018596 return (-1);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018597 }
Daniel Veillardf4b05d02004-07-05 13:10:37 +000018598 } else
18599 base = typeDecl;
Daniel Veillarddee23482008-04-11 12:58:43 +000018600
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018601 if (! ctxtGiven) {
18602 /*
18603 * A context is needed if called from RelaxNG.
Daniel Veillarddee23482008-04-11 12:58:43 +000018604 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018605 pctxt = xmlSchemaNewParserCtxt("*");
18606 if (pctxt == NULL)
18607 return (-1);
Daniel Veillard01fa6152004-06-29 17:04:39 +000018608 }
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000018609 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018610 * NOTE: This call does not check the content nodes,
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000018611 * since they are not available:
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018612 * facet->node is just the node holding the facet
18613 * definition, *not* the attribute holding the *value*
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000018614 * of the facet.
Daniel Veillarddee23482008-04-11 12:58:43 +000018615 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018616 ret = xmlSchemaVCheckCVCSimpleType(
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018617 ACTXT_CAST pctxt, facet->node, base,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018618 facet->value, &(facet->val), 1, 1, 0);
18619 if (ret != 0) {
18620 if (ret < 0) {
18621 /* No error message for RelaxNG. */
Daniel Veillarddee23482008-04-11 12:58:43 +000018622 if (ctxtGiven) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018623 xmlSchemaCustomErr(ACTXT_CAST pctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018624 XML_SCHEMAP_INTERNAL, facet->node, NULL,
Daniel Veillarddee23482008-04-11 12:58:43 +000018625 "Internal error: xmlSchemaCheckFacet, "
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018626 "failed to validate the value '%s' of the "
18627 "facet '%s' against the base type",
18628 facet->value, xmlSchemaFacetTypeToString(facet->type));
18629 }
18630 goto internal_error;
18631 }
18632 ret = XML_SCHEMAP_INVALID_FACET_VALUE;
18633 /* No error message for RelaxNG. */
18634 if (ctxtGiven) {
Kasimier T. Buchcik478d6932005-03-16 16:29:18 +000018635 xmlChar *str = NULL;
18636
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018637 xmlSchemaCustomErr(ACTXT_CAST pctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018638 ret, facet->node, WXS_BASIC_CAST facet,
Kasimier T. Buchcik478d6932005-03-16 16:29:18 +000018639 "The value '%s' of the facet does not validate "
18640 "against the base type '%s'",
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018641 facet->value,
18642 xmlSchemaFormatQName(&str,
18643 base->targetNamespace, base->name));
18644 FREE_AND_NULL(str);
Kasimier T. Buchcik478d6932005-03-16 16:29:18 +000018645 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018646 goto exit;
18647 } else if (facet->val == NULL) {
18648 if (ctxtGiven) {
18649 PERROR_INT("xmlSchemaCheckFacet",
18650 "value was not computed");
18651 }
18652 TODO
18653 }
Daniel Veillardd0c9c322003-10-10 00:49:42 +000018654 break;
18655 }
Daniel Veillardd0c9c322003-10-10 00:49:42 +000018656 case XML_SCHEMA_FACET_PATTERN:
18657 facet->regexp = xmlRegexpCompile(facet->value);
18658 if (facet->regexp == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018659 ret = XML_SCHEMAP_REGEXP_INVALID;
18660 /* No error message for RelaxNG. */
18661 if (ctxtGiven) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018662 xmlSchemaCustomErr(ACTXT_CAST pctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018663 ret, facet->node, WXS_BASIC_CAST typeDecl,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018664 "The value '%s' of the facet 'pattern' is not a "
18665 "valid regular expression",
18666 facet->value, NULL);
18667 }
Daniel Veillardd0c9c322003-10-10 00:49:42 +000018668 }
18669 break;
18670 case XML_SCHEMA_FACET_TOTALDIGITS:
18671 case XML_SCHEMA_FACET_FRACTIONDIGITS:
18672 case XML_SCHEMA_FACET_LENGTH:
18673 case XML_SCHEMA_FACET_MAXLENGTH:
Kasimier T. Buchcik69dea3a2005-11-07 14:02:44 +000018674 case XML_SCHEMA_FACET_MINLENGTH:
18675
18676 if (facet->type == XML_SCHEMA_FACET_TOTALDIGITS) {
18677 ret = xmlSchemaValidatePredefinedType(
18678 xmlSchemaGetBuiltInType(XML_SCHEMAS_PINTEGER),
18679 facet->value, &(facet->val));
18680 } else {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018681 ret = xmlSchemaValidatePredefinedType(
18682 xmlSchemaGetBuiltInType(XML_SCHEMAS_NNINTEGER),
18683 facet->value, &(facet->val));
Kasimier T. Buchcik69dea3a2005-11-07 14:02:44 +000018684 }
18685 if (ret != 0) {
18686 if (ret < 0) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018687 /* No error message for RelaxNG. */
18688 if (ctxtGiven) {
Kasimier T. Buchcik69dea3a2005-11-07 14:02:44 +000018689 PERROR_INT("xmlSchemaCheckFacet",
18690 "validating facet value");
18691 }
18692 goto internal_error;
18693 }
18694 ret = XML_SCHEMAP_INVALID_FACET_VALUE;
18695 /* No error message for RelaxNG. */
18696 if (ctxtGiven) {
18697 /* error code */
18698 xmlSchemaCustomErr4(ACTXT_CAST pctxt,
18699 ret, facet->node, WXS_BASIC_CAST typeDecl,
Daniel Veillarddee23482008-04-11 12:58:43 +000018700 "The value '%s' of the facet '%s' is not a valid '%s'",
Kasimier T. Buchcik69dea3a2005-11-07 14:02:44 +000018701 facet->value,
18702 xmlSchemaFacetTypeToString(facet->type),
Daniel Veillarddee23482008-04-11 12:58:43 +000018703 (facet->type != XML_SCHEMA_FACET_TOTALDIGITS) ?
Kasimier T. Buchcik69dea3a2005-11-07 14:02:44 +000018704 BAD_CAST "nonNegativeInteger" :
18705 BAD_CAST "positiveInteger",
18706 NULL);
18707 }
18708 }
18709 break;
Daniel Veillarddee23482008-04-11 12:58:43 +000018710
Daniel Veillardd0c9c322003-10-10 00:49:42 +000018711 case XML_SCHEMA_FACET_WHITESPACE:{
18712 if (xmlStrEqual(facet->value, BAD_CAST "preserve")) {
18713 facet->whitespace = XML_SCHEMAS_FACET_PRESERVE;
18714 } else if (xmlStrEqual(facet->value, BAD_CAST "replace")) {
18715 facet->whitespace = XML_SCHEMAS_FACET_REPLACE;
18716 } else if (xmlStrEqual(facet->value, BAD_CAST "collapse")) {
18717 facet->whitespace = XML_SCHEMAS_FACET_COLLAPSE;
18718 } else {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018719 ret = XML_SCHEMAP_INVALID_FACET_VALUE;
18720 /* No error message for RelaxNG. */
18721 if (ctxtGiven) {
Kasimier T. Buchcik478d6932005-03-16 16:29:18 +000018722 /* error was previously: XML_SCHEMAP_INVALID_WHITE_SPACE */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018723 xmlSchemaCustomErr(ACTXT_CAST pctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018724 ret, facet->node, WXS_BASIC_CAST typeDecl,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018725 "The value '%s' of the facet 'whitespace' is not "
18726 "valid", facet->value, NULL);
Daniel Veillardd0c9c322003-10-10 00:49:42 +000018727 }
Daniel Veillardd0c9c322003-10-10 00:49:42 +000018728 }
18729 }
18730 default:
18731 break;
Daniel Veillard8bc6cf92003-02-27 17:42:22 +000018732 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018733exit:
18734 if ((! ctxtGiven) && (pctxt != NULL))
18735 xmlSchemaFreeParserCtxt(pctxt);
Daniel Veillardd0c9c322003-10-10 00:49:42 +000018736 return (ret);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018737internal_error:
18738 if ((! ctxtGiven) && (pctxt != NULL))
18739 xmlSchemaFreeParserCtxt(pctxt);
18740 return (-1);
Daniel Veillard8bc6cf92003-02-27 17:42:22 +000018741}
18742
18743/**
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000018744 * xmlSchemaCheckFacetValues:
Daniel Veillard4255d502002-04-16 15:50:10 +000018745 * @typeDecl: the schema type definition
18746 * @ctxt: the schema parser context
18747 *
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018748 * Checks the default values types, especially for facets
Daniel Veillard4255d502002-04-16 15:50:10 +000018749 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018750static int
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000018751xmlSchemaCheckFacetValues(xmlSchemaTypePtr typeDecl,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018752 xmlSchemaParserCtxtPtr pctxt)
Daniel Veillard4255d502002-04-16 15:50:10 +000018753{
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018754 int res, olderrs = pctxt->nberrors;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018755 const xmlChar *name = typeDecl->name;
Daniel Veillard01fa6152004-06-29 17:04:39 +000018756 /*
18757 * NOTE: It is intended to use the facets list, instead
18758 * of facetSet.
18759 */
18760 if (typeDecl->facets != NULL) {
18761 xmlSchemaFacetPtr facet = typeDecl->facets;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018762
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +000018763 /*
18764 * Temporarily assign the "schema" to the validation context
18765 * of the parser context. This is needed for NOTATION validation.
18766 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018767 if (pctxt->vctxt == NULL) {
18768 if (xmlSchemaCreateVCtxtOnPCtxt(pctxt) == -1)
18769 return(-1);
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +000018770 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018771 pctxt->vctxt->schema = pctxt->schema;
Daniel Veillard01fa6152004-06-29 17:04:39 +000018772 while (facet != NULL) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018773 res = xmlSchemaCheckFacet(facet, typeDecl, pctxt, name);
18774 HFAILURE
Daniel Veillard01fa6152004-06-29 17:04:39 +000018775 facet = facet->next;
18776 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018777 pctxt->vctxt->schema = NULL;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018778 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018779 if (olderrs != pctxt->nberrors)
18780 return(pctxt->err);
18781 return(0);
18782exit_failure:
18783 return(-1);
Daniel Veillard4255d502002-04-16 15:50:10 +000018784}
18785
18786/**
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000018787 * xmlSchemaGetCircModelGrDefRef:
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000018788 * @ctxtMGroup: the searched model group
18789 * @selfMGroup: the second searched model group
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018790 * @particle: the first particle
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000018791 *
18792 * This one is intended to be used by
18793 * xmlSchemaCheckGroupDefCircular only.
18794 *
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000018795 * Returns the particle with the circular model group definition reference,
18796 * otherwise NULL.
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000018797 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000018798static xmlSchemaTreeItemPtr
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000018799xmlSchemaGetCircModelGrDefRef(xmlSchemaModelGroupDefPtr groupDef,
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000018800 xmlSchemaTreeItemPtr particle)
18801{
18802 xmlSchemaTreeItemPtr circ = NULL;
18803 xmlSchemaTreeItemPtr term;
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000018804 xmlSchemaModelGroupDefPtr gdef;
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000018805
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000018806 for (; particle != NULL; particle = particle->next) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000018807 term = particle->children;
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000018808 if (term == NULL)
18809 continue;
18810 switch (term->type) {
18811 case XML_SCHEMA_TYPE_GROUP:
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018812 gdef = (xmlSchemaModelGroupDefPtr) term;
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000018813 if (gdef == groupDef)
18814 return (particle);
18815 /*
18816 * Mark this model group definition to avoid infinite
18817 * recursion on circular references not yet examined.
18818 */
18819 if (gdef->flags & XML_SCHEMA_MODEL_GROUP_DEF_MARKED)
18820 continue;
18821 if (gdef->children != NULL) {
18822 gdef->flags |= XML_SCHEMA_MODEL_GROUP_DEF_MARKED;
18823 circ = xmlSchemaGetCircModelGrDefRef(groupDef,
18824 gdef->children->children);
18825 gdef->flags ^= XML_SCHEMA_MODEL_GROUP_DEF_MARKED;
18826 if (circ != NULL)
18827 return (circ);
18828 }
18829 break;
18830 case XML_SCHEMA_TYPE_SEQUENCE:
18831 case XML_SCHEMA_TYPE_CHOICE:
18832 case XML_SCHEMA_TYPE_ALL:
18833 circ = xmlSchemaGetCircModelGrDefRef(groupDef, term->children);
18834 if (circ != NULL)
18835 return (circ);
18836 break;
18837 default:
18838 break;
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000018839 }
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000018840 }
18841 return (NULL);
18842}
18843
18844/**
18845 * xmlSchemaCheckGroupDefCircular:
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000018846 * @item: the model group definition
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000018847 * @ctxt: the parser context
18848 * @name: the name
18849 *
18850 * Checks for circular references to model group definitions.
18851 */
18852static void
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000018853xmlSchemaCheckGroupDefCircular(xmlSchemaModelGroupDefPtr item,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000018854 xmlSchemaParserCtxtPtr ctxt)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018855{
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000018856 /*
18857 * Schema Component Constraint: Model Group Correct
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018858 * 2 Circular groups are disallowed. That is, within the {particles}
18859 * of a group there must not be at any depth a particle whose {term}
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000018860 * is the group itself.
18861 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000018862 if ((item == NULL) ||
18863 (item->type != XML_SCHEMA_TYPE_GROUP) ||
18864 (item->children == NULL))
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000018865 return;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000018866 {
18867 xmlSchemaTreeItemPtr circ;
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000018868
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000018869 circ = xmlSchemaGetCircModelGrDefRef(item, item->children->children);
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000018870 if (circ != NULL) {
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000018871 xmlChar *str = NULL;
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000018872 /*
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000018873 * TODO: The error report is not adequate: this constraint
18874 * is defined for model groups but not definitions, but since
18875 * there cannot be any circular model groups without a model group
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018876 * definition (if not using a construction API), we check those
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000018877 * defintions only.
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000018878 */
18879 xmlSchemaPCustomErr(ctxt,
18880 XML_SCHEMAP_MG_PROPS_CORRECT_2,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018881 NULL, WXS_ITEM_NODE(circ),
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000018882 "Circular reference to the model group definition '%s' "
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000018883 "defined", xmlSchemaFormatQName(&str,
18884 item->targetNamespace, item->name));
18885 FREE_AND_NULL(str)
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000018886 /*
18887 * NOTE: We will cut the reference to avoid further
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000018888 * confusion of the processor. This is a fatal error.
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000018889 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000018890 circ->children = NULL;
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000018891 }
18892 }
18893}
18894
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000018895/**
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018896 * xmlSchemaModelGroupToModelGroupDefFixup:
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000018897 * @ctxt: the parser context
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018898 * @mg: the model group
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018899 *
18900 * Assigns the model group of model group definitions to the "term"
18901 * of the referencing particle.
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018902 * In xmlSchemaResolveModelGroupParticleReferences the model group
18903 * definitions were assigned to the "term", since needed for the
18904 * circularity check.
18905 *
18906 * Schema Component Constraint:
18907 * All Group Limited (cos-all-limited) (1.2)
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000018908 */
18909static void
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018910xmlSchemaModelGroupToModelGroupDefFixup(
18911 xmlSchemaParserCtxtPtr ctxt ATTRIBUTE_UNUSED,
18912 xmlSchemaModelGroupPtr mg)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018913{
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018914 xmlSchemaParticlePtr particle = WXS_MODELGROUP_PARTICLE(mg);
18915
18916 while (particle != NULL) {
18917 if ((WXS_PARTICLE_TERM(particle) == NULL) ||
18918 ((WXS_PARTICLE_TERM(particle))->type !=
18919 XML_SCHEMA_TYPE_GROUP))
18920 {
18921 particle = WXS_PTC_CAST particle->next;
18922 continue;
Daniel Veillarddee23482008-04-11 12:58:43 +000018923 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018924 if (WXS_MODELGROUPDEF_MODEL(WXS_PARTICLE_TERM(particle)) == NULL) {
18925 /*
18926 * TODO: Remove the particle.
18927 */
18928 WXS_PARTICLE_TERM(particle) = NULL;
18929 particle = WXS_PTC_CAST particle->next;
18930 continue;
18931 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018932 /*
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018933 * Assign the model group to the {term} of the particle.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018934 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018935 WXS_PARTICLE_TERM(particle) =
18936 WXS_TREE_CAST WXS_MODELGROUPDEF_MODEL(WXS_PARTICLE_TERM(particle));
18937
18938 particle = WXS_PTC_CAST particle->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018939 }
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000018940}
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000018941
18942/**
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018943 * xmlSchemaCheckAttrGroupCircularRecur:
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000018944 * @ctxtGr: the searched attribute group
18945 * @attr: the current attribute list to be processed
18946 *
18947 * This one is intended to be used by
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018948 * xmlSchemaCheckAttrGroupCircular only.
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000018949 *
18950 * Returns the circular attribute grou reference, otherwise NULL.
18951 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018952static xmlSchemaQNameRefPtr
18953xmlSchemaCheckAttrGroupCircularRecur(xmlSchemaAttributeGroupPtr ctxtGr,
18954 xmlSchemaItemListPtr list)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018955{
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018956 xmlSchemaAttributeGroupPtr gr;
18957 xmlSchemaQNameRefPtr ref, circ;
18958 int i;
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000018959 /*
18960 * We will search for an attribute group reference which
18961 * references the context attribute group.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018962 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018963 for (i = 0; i < list->nbItems; i++) {
18964 ref = list->items[i];
18965 if ((ref->type == XML_SCHEMA_EXTRA_QNAMEREF) &&
18966 (ref->itemType == XML_SCHEMA_TYPE_ATTRIBUTEGROUP) &&
18967 (ref->item != NULL))
18968 {
18969 gr = WXS_ATTR_GROUP_CAST ref->item;
18970 if (gr == ctxtGr)
18971 return(ref);
18972 if (gr->flags & XML_SCHEMAS_ATTRGROUP_MARKED)
Daniel Veillarddee23482008-04-11 12:58:43 +000018973 continue;
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000018974 /*
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018975 * Mark as visited to avoid infinite recursion on
18976 * circular references not yet examined.
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000018977 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018978 if ((gr->attrUses) &&
18979 (gr->flags & XML_SCHEMAS_ATTRGROUP_HAS_REFS))
18980 {
18981 gr->flags |= XML_SCHEMAS_ATTRGROUP_MARKED;
18982 circ = xmlSchemaCheckAttrGroupCircularRecur(ctxtGr,
Daniel Veillarddee23482008-04-11 12:58:43 +000018983 (xmlSchemaItemListPtr) gr->attrUses);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018984 gr->flags ^= XML_SCHEMAS_ATTRGROUP_MARKED;
18985 if (circ != NULL)
18986 return (circ);
18987 }
Daniel Veillarddee23482008-04-11 12:58:43 +000018988
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000018989 }
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000018990 }
18991 return (NULL);
18992}
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000018993
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000018994/**
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000018995 * xmlSchemaCheckAttrGroupCircular:
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000018996 * attrGr: the attribute group definition
18997 * @ctxt: the parser context
18998 * @name: the name
18999 *
19000 * Checks for circular references of attribute groups.
19001 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019002static int
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000019003xmlSchemaCheckAttrGroupCircular(xmlSchemaAttributeGroupPtr attrGr,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019004 xmlSchemaParserCtxtPtr ctxt)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019005{
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000019006 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019007 * Schema Representation Constraint:
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000019008 * Attribute Group Definition Representation OK
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019009 * 3 Circular group reference is disallowed outside <redefine>.
19010 * That is, unless this element information item's parent is
19011 * <redefine>, then among the [children], if any, there must
19012 * not be an <attributeGroup> with ref [attribute] which resolves
19013 * to the component corresponding to this <attributeGroup>. Indirect
19014 * circularity is also ruled out. That is, when QName resolution
Rob Richardsc6947bb2008-06-29 15:04:41 +000019015 * (Schema Document) (�3.15.3) is applied to a �QName� arising from
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019016 * any <attributeGroup>s with a ref [attribute] among the [children],
Rob Richardsc6947bb2008-06-29 15:04:41 +000019017 * it must not be the case that a �QName� is encountered at any depth
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000019018 * which resolves to the component corresponding to this <attributeGroup>.
19019 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019020 if (attrGr->attrUses == NULL)
19021 return(0);
19022 else if ((attrGr->flags & XML_SCHEMAS_ATTRGROUP_HAS_REFS) == 0)
19023 return(0);
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000019024 else {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019025 xmlSchemaQNameRefPtr circ;
Daniel Veillarddee23482008-04-11 12:58:43 +000019026
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019027 circ = xmlSchemaCheckAttrGroupCircularRecur(attrGr,
Daniel Veillarddee23482008-04-11 12:58:43 +000019028 (xmlSchemaItemListPtr) attrGr->attrUses);
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000019029 if (circ != NULL) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019030 xmlChar *str = NULL;
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000019031 /*
19032 * TODO: Report the referenced attr group as QName.
19033 */
19034 xmlSchemaPCustomErr(ctxt,
19035 XML_SCHEMAP_SRC_ATTRIBUTE_GROUP_3,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019036 NULL, WXS_ITEM_NODE(WXS_BASIC_CAST circ),
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000019037 "Circular reference to the attribute group '%s' "
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019038 "defined", xmlSchemaGetComponentQName(&str, attrGr));
19039 FREE_AND_NULL(str);
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000019040 /*
19041 * NOTE: We will cut the reference to avoid further
19042 * confusion of the processor.
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019043 * BADSPEC TODO: The spec should define how to process in this case.
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000019044 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019045 circ->item = NULL;
19046 return(ctxt->err);
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000019047 }
19048 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019049 return(0);
19050}
19051
19052static int
19053xmlSchemaAttributeGroupExpandRefs(xmlSchemaParserCtxtPtr pctxt,
19054 xmlSchemaAttributeGroupPtr attrGr);
19055
19056/**
19057 * xmlSchemaExpandAttributeGroupRefs:
19058 * @pctxt: the parser context
19059 * @node: the node of the component holding the attribute uses
Daniel Veillarddee23482008-04-11 12:58:43 +000019060 * @completeWild: the intersected wildcard to be returned
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019061 * @list: the attribute uses
19062 *
19063 * Substitutes contained attribute group references
19064 * for their attribute uses. Wilcards are intersected.
19065 * Attribute use prohibitions are removed from the list
19066 * and returned via the @prohibs list.
19067 * Pointlessness of attr. prohibs, if a matching attr. decl
19068 * is existent a well, are checked.
19069 */
19070static int
19071xmlSchemaExpandAttributeGroupRefs(xmlSchemaParserCtxtPtr pctxt,
19072 xmlSchemaBasicItemPtr item,
19073 xmlSchemaWildcardPtr *completeWild,
19074 xmlSchemaItemListPtr list,
19075 xmlSchemaItemListPtr prohibs)
19076{
19077 xmlSchemaAttributeGroupPtr gr;
19078 xmlSchemaAttributeUsePtr use;
19079 xmlSchemaItemListPtr sublist;
19080 int i, j;
19081 int created = (*completeWild == NULL) ? 0 : 1;
19082
19083 if (prohibs)
19084 prohibs->nbItems = 0;
19085
19086 for (i = 0; i < list->nbItems; i++) {
19087 use = list->items[i];
19088
Daniel Veillarddee23482008-04-11 12:58:43 +000019089 if (use->type == XML_SCHEMA_EXTRA_ATTR_USE_PROHIB) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019090 if (prohibs == NULL) {
19091 PERROR_INT("xmlSchemaExpandAttributeGroupRefs",
19092 "unexpected attr prohibition found");
19093 return(-1);
19094 }
19095 /*
19096 * Remove from attribute uses.
19097 */
19098 if (xmlSchemaItemListRemove(list, i) == -1)
19099 return(-1);
19100 i--;
19101 /*
19102 * Note that duplicate prohibitions were already
19103 * handled at parsing time.
Daniel Veillarddee23482008-04-11 12:58:43 +000019104 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019105 /*
19106 * Add to list of prohibitions.
19107 */
19108 xmlSchemaItemListAddSize(prohibs, 2, use);
19109 continue;
19110 }
19111 if ((use->type == XML_SCHEMA_EXTRA_QNAMEREF) &&
19112 ((WXS_QNAME_CAST use)->itemType == XML_SCHEMA_TYPE_ATTRIBUTEGROUP))
19113 {
19114 if ((WXS_QNAME_CAST use)->item == NULL)
19115 return(-1);
19116 gr = WXS_ATTR_GROUP_CAST (WXS_QNAME_CAST use)->item;
19117 /*
19118 * Expand the referenced attr. group.
19119 * TODO: remove this, this is done in a previous step, so
19120 * already done here.
19121 */
19122 if ((gr->flags & XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED) == 0) {
19123 if (xmlSchemaAttributeGroupExpandRefs(pctxt, gr) == -1)
19124 return(-1);
19125 }
19126 /*
19127 * Build the 'complete' wildcard; i.e. intersect multiple
19128 * wildcards.
19129 */
19130 if (gr->attributeWildcard != NULL) {
19131 if (*completeWild == NULL) {
19132 *completeWild = gr->attributeWildcard;
19133 } else {
19134 if (! created) {
19135 xmlSchemaWildcardPtr tmpWild;
19136
19137 /*
19138 * Copy the first encountered wildcard as context,
19139 * except for the annotation.
19140 *
19141 * Although the complete wildcard might not correspond
19142 * to any node in the schema, we will anchor it on
19143 * the node of the owner component.
19144 */
19145 tmpWild = xmlSchemaAddWildcard(pctxt, pctxt->schema,
19146 XML_SCHEMA_TYPE_ANY_ATTRIBUTE,
19147 WXS_ITEM_NODE(item));
19148 if (tmpWild == NULL)
19149 return(-1);
19150 if (xmlSchemaCloneWildcardNsConstraints(pctxt,
19151 tmpWild, *completeWild) == -1)
19152 return (-1);
19153 tmpWild->processContents = (*completeWild)->processContents;
19154 *completeWild = tmpWild;
19155 created = 1;
19156 }
Daniel Veillarddee23482008-04-11 12:58:43 +000019157
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019158 if (xmlSchemaIntersectWildcards(pctxt, *completeWild,
19159 gr->attributeWildcard) == -1)
19160 return(-1);
19161 }
19162 }
19163 /*
19164 * Just remove the reference if the referenced group does not
19165 * contain any attribute uses.
19166 */
William M. Brack06559b32007-03-14 09:34:15 +000019167 sublist = ((xmlSchemaItemListPtr) gr->attrUses);
19168 if ((sublist == NULL) || sublist->nbItems == 0) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019169 if (xmlSchemaItemListRemove(list, i) == -1)
19170 return(-1);
19171 i--;
19172 continue;
19173 }
19174 /*
19175 * Add the attribute uses.
19176 */
William M. Brack06559b32007-03-14 09:34:15 +000019177 list->items[i] = sublist->items[0];
19178 if (sublist->nbItems != 1) {
19179 for (j = 1; j < sublist->nbItems; j++) {
19180 i++;
19181 if (xmlSchemaItemListInsert(list,
19182 sublist->items[j], i) == -1)
19183 return(-1);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019184 }
William M. Brack06559b32007-03-14 09:34:15 +000019185 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019186 }
19187
19188 }
19189 /*
19190 * Handle pointless prohibitions of declared attributes.
19191 */
19192 if (prohibs && (prohibs->nbItems != 0) && (list->nbItems != 0)) {
19193 xmlSchemaAttributeUseProhibPtr prohib;
19194
19195 for (i = prohibs->nbItems -1; i >= 0; i--) {
19196 prohib = prohibs->items[i];
19197 for (j = 0; j < list->nbItems; j++) {
19198 use = list->items[j];
19199
19200 if ((prohib->name == WXS_ATTRUSE_DECL_NAME(use)) &&
19201 (prohib->targetNamespace == WXS_ATTRUSE_DECL_TNS(use)))
19202 {
19203 xmlChar *str = NULL;
19204
19205 xmlSchemaCustomWarning(ACTXT_CAST pctxt,
19206 XML_SCHEMAP_WARN_ATTR_POINTLESS_PROH,
19207 prohib->node, NULL,
19208 "Skipping pointless attribute use prohibition "
19209 "'%s', since a corresponding attribute use "
19210 "exists already in the type definition",
19211 xmlSchemaFormatQName(&str,
19212 prohib->targetNamespace, prohib->name),
19213 NULL, NULL);
19214 FREE_AND_NULL(str);
19215 /*
19216 * Remove the prohibition.
19217 */
19218 if (xmlSchemaItemListRemove(prohibs, i) == -1)
19219 return(-1);
19220 break;
19221 }
19222 }
19223 }
19224 }
19225 return(0);
19226}
19227
19228/**
19229 * xmlSchemaAttributeGroupExpandRefs:
19230 * @pctxt: the parser context
Daniel Veillarddee23482008-04-11 12:58:43 +000019231 * @attrGr: the attribute group definition
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019232 *
19233 * Computation of:
19234 * {attribute uses} property
19235 * {attribute wildcard} property
19236 *
19237 * Substitutes contained attribute group references
19238 * for their attribute uses. Wilcards are intersected.
19239 */
19240static int
19241xmlSchemaAttributeGroupExpandRefs(xmlSchemaParserCtxtPtr pctxt,
19242 xmlSchemaAttributeGroupPtr attrGr)
Daniel Veillarddee23482008-04-11 12:58:43 +000019243{
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019244 if ((attrGr->attrUses == NULL) ||
19245 (attrGr->flags & XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED))
19246 return(0);
19247
19248 attrGr->flags |= XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED;
19249 if (xmlSchemaExpandAttributeGroupRefs(pctxt, WXS_BASIC_CAST attrGr,
19250 &(attrGr->attributeWildcard), attrGr->attrUses, NULL) == -1)
Daniel Veillarddee23482008-04-11 12:58:43 +000019251 return(-1);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019252 return(0);
19253}
19254
19255/**
19256 * xmlSchemaAttributeGroupExpandRefs:
19257 * @pctxt: the parser context
Daniel Veillarddee23482008-04-11 12:58:43 +000019258 * @attrGr: the attribute group definition
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019259 *
19260 * Substitutes contained attribute group references
19261 * for their attribute uses. Wilcards are intersected.
Daniel Veillarddee23482008-04-11 12:58:43 +000019262 *
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019263 * Schema Component Constraint:
Daniel Veillarddee23482008-04-11 12:58:43 +000019264 * Attribute Group Definition Properties Correct (ag-props-correct)
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019265 */
19266static int
19267xmlSchemaCheckAGPropsCorrect(xmlSchemaParserCtxtPtr pctxt,
19268 xmlSchemaAttributeGroupPtr attrGr)
Daniel Veillarddee23482008-04-11 12:58:43 +000019269{
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019270 /*
19271 * SPEC ag-props-correct
19272 * (1) "The values of the properties of an attribute group definition
19273 * must be as described in the property tableau in The Attribute
Rob Richardsc6947bb2008-06-29 15:04:41 +000019274 * Group Definition Schema Component (�3.6.1), modulo the impact of
19275 * Missing Sub-components (�5.3);"
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019276 */
Daniel Veillarddee23482008-04-11 12:58:43 +000019277
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019278 if ((attrGr->attrUses != NULL) &&
19279 (WXS_LIST_CAST attrGr->attrUses)->nbItems > 1)
19280 {
19281 xmlSchemaItemListPtr uses = WXS_LIST_CAST attrGr->attrUses;
19282 xmlSchemaAttributeUsePtr use, tmp;
19283 int i, j, hasId = 0;
19284
19285 for (i = uses->nbItems -1; i >= 0; i--) {
Daniel Veillarddee23482008-04-11 12:58:43 +000019286 use = uses->items[i];
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019287 /*
19288 * SPEC ag-props-correct
19289 * (2) "Two distinct members of the {attribute uses} must not have
19290 * {attribute declaration}s both of whose {name}s match and whose
19291 * {target namespace}s are identical."
19292 */
19293 if (i > 0) {
19294 for (j = i -1; j >= 0; j--) {
19295 tmp = uses->items[j];
19296 if ((WXS_ATTRUSE_DECL_NAME(use) ==
19297 WXS_ATTRUSE_DECL_NAME(tmp)) &&
19298 (WXS_ATTRUSE_DECL_TNS(use) ==
19299 WXS_ATTRUSE_DECL_TNS(tmp)))
19300 {
19301 xmlChar *str = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000019302
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019303 xmlSchemaCustomErr(ACTXT_CAST pctxt,
19304 XML_SCHEMAP_AG_PROPS_CORRECT,
19305 attrGr->node, WXS_BASIC_CAST attrGr,
19306 "Duplicate %s",
19307 xmlSchemaGetComponentDesignation(&str, use),
19308 NULL);
19309 FREE_AND_NULL(str);
19310 /*
19311 * Remove the duplicate.
19312 */
19313 if (xmlSchemaItemListRemove(uses, i) == -1)
19314 return(-1);
19315 goto next_use;
19316 }
19317 }
19318 }
19319 /*
19320 * SPEC ag-props-correct
19321 * (3) "Two distinct members of the {attribute uses} must not have
19322 * {attribute declaration}s both of whose {type definition}s are or
19323 * are derived from ID."
19324 * TODO: Does 'derived' include member-types of unions?
19325 */
Daniel Veillarddee23482008-04-11 12:58:43 +000019326 if (WXS_ATTRUSE_TYPEDEF(use) != NULL) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019327 if (xmlSchemaIsDerivedFromBuiltInType(
19328 WXS_ATTRUSE_TYPEDEF(use), XML_SCHEMAS_ID))
Daniel Veillarddee23482008-04-11 12:58:43 +000019329 {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019330 if (hasId) {
19331 xmlChar *str = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000019332
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019333 xmlSchemaCustomErr(ACTXT_CAST pctxt,
19334 XML_SCHEMAP_AG_PROPS_CORRECT,
19335 attrGr->node, WXS_BASIC_CAST attrGr,
19336 "There must not exist more than one attribute "
19337 "declaration of type 'xs:ID' "
19338 "(or derived from 'xs:ID'). The %s violates this "
19339 "constraint",
19340 xmlSchemaGetComponentDesignation(&str, use),
19341 NULL);
19342 FREE_AND_NULL(str);
19343 if (xmlSchemaItemListRemove(uses, i) == -1)
19344 return(-1);
Daniel Veillarddee23482008-04-11 12:58:43 +000019345 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019346 hasId = 1;
19347 }
19348 }
19349next_use: {}
19350 }
19351 }
19352 return(0);
Kasimier T. Buchcik383434b2004-09-03 18:55:35 +000019353}
19354
19355/**
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000019356 * xmlSchemaResolveAttrGroupReferences:
Daniel Veillard13e04c62002-04-23 17:51:29 +000019357 * @attrgrpDecl: the schema attribute definition
19358 * @ctxt: the schema parser context
19359 * @name: the attribute name
19360 *
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019361 * Resolves references to attribute group definitions.
Daniel Veillard13e04c62002-04-23 17:51:29 +000019362 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019363static int
19364xmlSchemaResolveAttrGroupReferences(xmlSchemaQNameRefPtr ref,
19365 xmlSchemaParserCtxtPtr ctxt)
Daniel Veillard13e04c62002-04-23 17:51:29 +000019366{
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019367 xmlSchemaAttributeGroupPtr group;
Daniel Veillard13e04c62002-04-23 17:51:29 +000019368
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019369 if (ref->item != NULL)
19370 return(0);
19371 group = xmlSchemaGetAttributeGroup(ctxt->schema,
19372 ref->name,
19373 ref->targetNamespace);
19374 if (group == NULL) {
19375 xmlSchemaPResCompAttrErr(ctxt,
19376 XML_SCHEMAP_SRC_RESOLVE,
19377 NULL, ref->node,
19378 "ref", ref->name, ref->targetNamespace,
19379 ref->itemType, NULL);
19380 return(ctxt->err);
Daniel Veillard3646d642004-06-02 19:19:14 +000019381 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019382 ref->item = WXS_BASIC_CAST group;
19383 return(0);
Daniel Veillard13e04c62002-04-23 17:51:29 +000019384}
19385
19386/**
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019387 * xmlSchemaCheckAttrPropsCorrect:
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000019388 * @item: an schema attribute declaration/use
19389 * @ctxt: a schema parser context
19390 * @name: the name of the attribute
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019391 *
19392 *
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019393 * Schema Component Constraint:
19394 * Attribute Declaration Properties Correct (a-props-correct)
Daniel Veillard4255d502002-04-16 15:50:10 +000019395 *
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019396 * Validates the value constraints of an attribute declaration/use.
19397 * NOTE that this needs the simle type definitions to be already
19398 * builded and checked.
Daniel Veillard4255d502002-04-16 15:50:10 +000019399 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019400static int
19401xmlSchemaCheckAttrPropsCorrect(xmlSchemaParserCtxtPtr pctxt,
19402 xmlSchemaAttributePtr attr)
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000019403{
19404
19405 /*
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019406 * SPEC a-props-correct (1)
19407 * "The values of the properties of an attribute declaration must
19408 * be as described in the property tableau in The Attribute
Rob Richardsc6947bb2008-06-29 15:04:41 +000019409 * Declaration Schema Component (�3.2.1), modulo the impact of
19410 * Missing Sub-components (�5.3)."
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000019411 */
Daniel Veillarddee23482008-04-11 12:58:43 +000019412
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019413 if (WXS_ATTR_TYPEDEF(attr) == NULL)
19414 return(0);
19415
19416 if (attr->defValue != NULL) {
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000019417 int ret;
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000019418
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019419 /*
19420 * SPEC a-props-correct (3)
19421 * "If the {type definition} is or is derived from ID then there
19422 * must not be a {value constraint}."
19423 */
19424 if (xmlSchemaIsDerivedFromBuiltInType(
19425 WXS_ATTR_TYPEDEF(attr), XML_SCHEMAS_ID))
19426 {
19427 xmlSchemaCustomErr(ACTXT_CAST pctxt,
19428 XML_SCHEMAP_A_PROPS_CORRECT_3,
19429 NULL, WXS_BASIC_CAST attr,
19430 "Value constraints are not allowed if the type definition "
19431 "is or is derived from xs:ID",
19432 NULL, NULL);
19433 return(pctxt->err);
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000019434 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019435 /*
19436 * SPEC a-props-correct (2)
19437 * "if there is a {value constraint}, the canonical lexical
Rob Richardsc6947bb2008-06-29 15:04:41 +000019438 * representation of its value must be �valid� with respect
19439 * to the {type definition} as defined in String Valid (�3.14.4)."
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019440 * TODO: Don't care about the *cononical* stuff here, this requirement
19441 * will be removed in WXS 1.1 anyway.
19442 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000019443 ret = xmlSchemaVCheckCVCSimpleType(ACTXT_CAST pctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019444 attr->node, WXS_ATTR_TYPEDEF(attr),
19445 attr->defValue, &(attr->defVal),
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019446 1, 1, 0);
19447 if (ret != 0) {
19448 if (ret < 0) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019449 PERROR_INT("xmlSchemaCheckAttrPropsCorrect",
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019450 "calling xmlSchemaVCheckCVCSimpleType()");
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019451 return(-1);
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000019452 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000019453 xmlSchemaCustomErr(ACTXT_CAST pctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019454 XML_SCHEMAP_A_PROPS_CORRECT_2,
19455 NULL, WXS_BASIC_CAST attr,
19456 "The value of the value constraint is not valid",
19457 NULL, NULL);
19458 return(pctxt->err);
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000019459 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019460 }
Daniel Veillarddee23482008-04-11 12:58:43 +000019461
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019462 return(0);
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000019463}
19464
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000019465static xmlSchemaElementPtr
19466xmlSchemaCheckSubstGroupCircular(xmlSchemaElementPtr elemDecl,
19467 xmlSchemaElementPtr ancestor)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019468{
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000019469 xmlSchemaElementPtr ret;
19470
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019471 if (WXS_SUBST_HEAD(ancestor) == NULL)
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000019472 return (NULL);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019473 if (WXS_SUBST_HEAD(ancestor) == elemDecl)
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000019474 return (ancestor);
19475
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019476 if (WXS_SUBST_HEAD(ancestor)->flags & XML_SCHEMAS_ELEM_CIRCULAR)
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000019477 return (NULL);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019478 WXS_SUBST_HEAD(ancestor)->flags |= XML_SCHEMAS_ELEM_CIRCULAR;
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000019479 ret = xmlSchemaCheckSubstGroupCircular(elemDecl,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019480 WXS_SUBST_HEAD(ancestor));
19481 WXS_SUBST_HEAD(ancestor)->flags ^= XML_SCHEMAS_ELEM_CIRCULAR;
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000019482
19483 return (ret);
19484}
19485
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000019486/**
19487 * xmlSchemaCheckElemPropsCorrect:
19488 * @ctxt: a schema parser context
19489 * @decl: the element declaration
19490 * @name: the name of the attribute
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019491 *
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000019492 * Schema Component Constraint:
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019493 * Element Declaration Properties Correct (e-props-correct)
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000019494 *
19495 * STATUS:
19496 * missing: (6)
19497 */
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000019498static int
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000019499xmlSchemaCheckElemPropsCorrect(xmlSchemaParserCtxtPtr pctxt,
19500 xmlSchemaElementPtr elemDecl)
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000019501{
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000019502 int ret = 0;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019503 xmlSchemaTypePtr typeDef = WXS_ELEM_TYPEDEF(elemDecl);
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000019504 /*
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000019505 * SPEC (1) "The values of the properties of an element declaration
19506 * must be as described in the property tableau in The Element
Rob Richardsc6947bb2008-06-29 15:04:41 +000019507 * Declaration Schema Component (�3.3.1), modulo the impact of Missing
19508 * Sub-components (�5.3)."
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019509 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019510 if (WXS_SUBST_HEAD(elemDecl) != NULL) {
19511 xmlSchemaElementPtr head = WXS_SUBST_HEAD(elemDecl), circ;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019512
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000019513 xmlSchemaCheckElementDeclComponent(head, pctxt);
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000019514 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000019515 * SPEC (3) "If there is a non-�absent� {substitution group
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000019516 * affiliation}, then {scope} must be global."
19517 */
19518 if ((elemDecl->flags & XML_SCHEMAS_ELEM_GLOBAL) == 0) {
19519 xmlSchemaPCustomErr(pctxt,
19520 XML_SCHEMAP_E_PROPS_CORRECT_3,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019521 WXS_BASIC_CAST elemDecl, NULL,
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000019522 "Only global element declarations can have a "
19523 "substitution group affiliation", NULL);
19524 ret = XML_SCHEMAP_E_PROPS_CORRECT_3;
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000019525 }
19526 /*
19527 * TODO: SPEC (6) "Circular substitution groups are disallowed.
19528 * That is, it must not be possible to return to an element declaration
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019529 * by repeatedly following the {substitution group affiliation}
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000019530 * property."
19531 */
19532 if (head == elemDecl)
19533 circ = head;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019534 else if (WXS_SUBST_HEAD(head) != NULL)
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000019535 circ = xmlSchemaCheckSubstGroupCircular(head, head);
19536 else
19537 circ = NULL;
19538 if (circ != NULL) {
19539 xmlChar *strA = NULL, *strB = NULL;
19540
19541 xmlSchemaPCustomErrExt(pctxt,
19542 XML_SCHEMAP_E_PROPS_CORRECT_6,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019543 WXS_BASIC_CAST circ, NULL,
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000019544 "The element declaration '%s' defines a circular "
19545 "substitution group to element declaration '%s'",
19546 xmlSchemaGetComponentQName(&strA, circ),
19547 xmlSchemaGetComponentQName(&strB, head),
19548 NULL);
19549 FREE_AND_NULL(strA)
19550 FREE_AND_NULL(strB)
19551 ret = XML_SCHEMAP_E_PROPS_CORRECT_6;
19552 }
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000019553 /*
19554 * SPEC (4) "If there is a {substitution group affiliation},
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019555 * the {type definition}
19556 * of the element declaration must be validly derived from the {type
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000019557 * definition} of the {substitution group affiliation}, given the value
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019558 * of the {substitution group exclusions} of the {substitution group
Rob Richardsc6947bb2008-06-29 15:04:41 +000019559 * affiliation}, as defined in Type Derivation OK (Complex) (�3.4.6)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019560 * (if the {type definition} is complex) or as defined in
Rob Richardsc6947bb2008-06-29 15:04:41 +000019561 * Type Derivation OK (Simple) (�3.14.6) (if the {type definition} is
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000019562 * simple)."
19563 *
19564 * NOTE: {substitution group exclusions} means the values of the
19565 * attribute "final".
19566 */
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000019567
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019568 if (typeDef != WXS_ELEM_TYPEDEF(WXS_SUBST_HEAD(elemDecl))) {
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000019569 int set = 0;
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000019570
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019571 if (head->flags & XML_SCHEMAS_ELEM_FINAL_EXTENSION)
19572 set |= SUBSET_EXTENSION;
19573 if (head->flags & XML_SCHEMAS_ELEM_FINAL_RESTRICTION)
19574 set |= SUBSET_RESTRICTION;
19575
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000019576 if (xmlSchemaCheckCOSDerivedOK(ACTXT_CAST pctxt, typeDef,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019577 WXS_ELEM_TYPEDEF(head), set) != 0) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019578 xmlChar *strA = NULL, *strB = NULL, *strC = NULL;
19579
19580 ret = XML_SCHEMAP_E_PROPS_CORRECT_4;
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000019581 xmlSchemaPCustomErrExt(pctxt,
19582 XML_SCHEMAP_E_PROPS_CORRECT_4,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019583 WXS_BASIC_CAST elemDecl, NULL,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019584 "The type definition '%s' was "
19585 "either rejected by the substitution group "
19586 "affiliation '%s', or not validly derived from its type "
19587 "definition '%s'",
19588 xmlSchemaGetComponentQName(&strA, typeDef),
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000019589 xmlSchemaGetComponentQName(&strB, head),
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019590 xmlSchemaGetComponentQName(&strC, WXS_ELEM_TYPEDEF(head)));
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000019591 FREE_AND_NULL(strA)
19592 FREE_AND_NULL(strB)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019593 FREE_AND_NULL(strC)
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000019594 }
19595 }
19596 }
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000019597 /*
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000019598 * SPEC (5) "If the {type definition} or {type definition}'s
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019599 * {content type}
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000019600 * is or is derived from ID then there must not be a {value constraint}.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019601 * Note: The use of ID as a type definition for elements goes beyond
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000019602 * XML 1.0, and should be avoided if backwards compatibility is desired"
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000019603 */
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000019604 if ((elemDecl->value != NULL) &&
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019605 ((WXS_IS_SIMPLE(typeDef) &&
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019606 xmlSchemaIsDerivedFromBuiltInType(typeDef, XML_SCHEMAS_ID)) ||
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019607 (WXS_IS_COMPLEX(typeDef) &&
19608 WXS_HAS_SIMPLE_CONTENT(typeDef) &&
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019609 xmlSchemaIsDerivedFromBuiltInType(typeDef->contentTypeDef,
19610 XML_SCHEMAS_ID)))) {
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000019611
19612 ret = XML_SCHEMAP_E_PROPS_CORRECT_5;
19613 xmlSchemaPCustomErr(pctxt,
19614 XML_SCHEMAP_E_PROPS_CORRECT_5,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019615 WXS_BASIC_CAST elemDecl, NULL,
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000019616 "The type definition (or type definition's content type) is or "
19617 "is derived from ID; value constraints are not allowed in "
19618 "conjunction with such a type definition", NULL);
19619 } else if (elemDecl->value != NULL) {
19620 int vcret;
19621 xmlNodePtr node = NULL;
19622
19623 /*
19624 * SPEC (2) "If there is a {value constraint}, the canonical lexical
Rob Richardsc6947bb2008-06-29 15:04:41 +000019625 * representation of its value must be �valid� with respect to the
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000019626 * {type definition} as defined in Element Default Valid (Immediate)
Rob Richardsc6947bb2008-06-29 15:04:41 +000019627 * (�3.3.6)."
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019628 */
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000019629 if (typeDef == NULL) {
19630 xmlSchemaPErr(pctxt, elemDecl->node,
19631 XML_SCHEMAP_INTERNAL,
19632 "Internal error: xmlSchemaCheckElemPropsCorrect, "
19633 "type is missing... skipping validation of "
19634 "the value constraint", NULL, NULL);
19635 return (-1);
19636 }
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000019637 if (elemDecl->node != NULL) {
19638 if (elemDecl->flags & XML_SCHEMAS_ELEM_FIXED)
19639 node = (xmlNodePtr) xmlHasProp(elemDecl->node,
19640 BAD_CAST "fixed");
19641 else
19642 node = (xmlNodePtr) xmlHasProp(elemDecl->node,
19643 BAD_CAST "default");
19644 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019645 vcret = xmlSchemaParseCheckCOSValidDefault(pctxt, node,
19646 typeDef, elemDecl->value, &(elemDecl->defVal));
19647 if (vcret != 0) {
19648 if (vcret < 0) {
19649 PERROR_INT("xmlSchemaElemCheckValConstr",
19650 "failed to validate the value constraint of an "
19651 "element declaration");
19652 return (-1);
19653 }
19654 return (vcret);
19655 }
19656 }
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000019657
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000019658 return (ret);
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000019659}
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000019660
19661/**
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000019662 * xmlSchemaCheckElemSubstGroup:
19663 * @ctxt: a schema parser context
19664 * @decl: the element declaration
19665 * @name: the name of the attribute
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019666 *
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000019667 * Schema Component Constraint:
19668 * Substitution Group (cos-equiv-class)
19669 *
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019670 * In Libxml2 the subst. groups will be precomputed, in terms of that
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000019671 * a list will be built for each subst. group head, holding all direct
19672 * referents to this head.
19673 * NOTE that this function needs:
19674 * 1. circular subst. groups to be checked beforehand
19675 * 2. the declaration's type to be derived from the head's type
19676 *
19677 * STATUS:
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019678 *
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000019679 */
19680static void
19681xmlSchemaCheckElemSubstGroup(xmlSchemaParserCtxtPtr ctxt,
19682 xmlSchemaElementPtr elemDecl)
19683{
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019684 if ((WXS_SUBST_HEAD(elemDecl) == NULL) ||
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000019685 /* SPEC (1) "Its {abstract} is false." */
19686 (elemDecl->flags & XML_SCHEMAS_ELEM_ABSTRACT))
19687 return;
19688 {
19689 xmlSchemaElementPtr head;
19690 xmlSchemaTypePtr headType, type;
19691 int set, methSet;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019692 /*
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000019693 * SPEC (2) "It is validly substitutable for HEAD subject to HEAD's
19694 * {disallowed substitutions} as the blocking constraint, as defined in
Rob Richardsc6947bb2008-06-29 15:04:41 +000019695 * Substitution Group OK (Transitive) (�3.3.6)."
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000019696 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019697 for (head = WXS_SUBST_HEAD(elemDecl); head != NULL;
19698 head = WXS_SUBST_HEAD(head)) {
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000019699 set = 0;
19700 methSet = 0;
19701 /*
19702 * The blocking constraints.
19703 */
19704 if (head->flags & XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION)
19705 continue;
19706 headType = head->subtypes;
19707 type = elemDecl->subtypes;
19708 if (headType == type)
19709 goto add_member;
19710 if (head->flags & XML_SCHEMAS_ELEM_BLOCK_RESTRICTION)
19711 set |= XML_SCHEMAS_TYPE_BLOCK_RESTRICTION;
19712 if (head->flags & XML_SCHEMAS_ELEM_BLOCK_EXTENSION)
19713 set |= XML_SCHEMAS_TYPE_BLOCK_EXTENSION;
19714 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019715 * SPEC: Substitution Group OK (Transitive) (2.3)
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000019716 * "The set of all {derivation method}s involved in the
19717 * derivation of D's {type definition} from C's {type definition}
19718 * does not intersect with the union of the blocking constraint,
19719 * C's {prohibited substitutions} (if C is complex, otherwise the
19720 * empty set) and the {prohibited substitutions} (respectively the
19721 * empty set) of any intermediate {type definition}s in the
19722 * derivation of D's {type definition} from C's {type definition}."
19723 */
19724 /*
19725 * OPTIMIZE TODO: Optimize this a bit, since, if traversing the
19726 * subst.head axis, the methSet does not need to be computed for
19727 * the full depth over and over.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019728 */
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000019729 /*
19730 * The set of all {derivation method}s involved in the derivation
19731 */
19732 while ((type != NULL) && (type != headType)) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000019733 if ((WXS_IS_EXTENSION(type)) &&
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000019734 ((methSet & XML_SCHEMAS_TYPE_BLOCK_RESTRICTION) == 0))
19735 methSet |= XML_SCHEMAS_TYPE_BLOCK_EXTENSION;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019736
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000019737 if (WXS_IS_RESTRICTION(type) &&
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000019738 ((methSet & XML_SCHEMAS_TYPE_BLOCK_RESTRICTION) == 0))
19739 methSet |= XML_SCHEMAS_TYPE_BLOCK_RESTRICTION;
19740
19741 type = type->baseType;
19742 }
19743 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019744 * The {prohibited substitutions} of all intermediate types +
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000019745 * the head's type.
19746 */
19747 type = elemDecl->subtypes->baseType;
19748 while (type != NULL) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019749 if (WXS_IS_COMPLEX(type)) {
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000019750 if ((type->flags &
19751 XML_SCHEMAS_TYPE_BLOCK_EXTENSION) &&
19752 ((set & XML_SCHEMAS_TYPE_BLOCK_EXTENSION) == 0))
19753 set |= XML_SCHEMAS_TYPE_BLOCK_EXTENSION;
19754 if ((type->flags &
19755 XML_SCHEMAS_TYPE_BLOCK_RESTRICTION) &&
19756 ((set & XML_SCHEMAS_TYPE_BLOCK_RESTRICTION) == 0))
19757 set |= XML_SCHEMAS_TYPE_BLOCK_RESTRICTION;
19758 } else
19759 break;
19760 if (type == headType)
19761 break;
19762 type = type->baseType;
19763 }
19764 if ((set != 0) &&
19765 (((set & XML_SCHEMAS_TYPE_BLOCK_EXTENSION) &&
19766 (methSet & XML_SCHEMAS_TYPE_BLOCK_EXTENSION)) ||
19767 ((set & XML_SCHEMAS_TYPE_BLOCK_RESTRICTION) &&
19768 (methSet & XML_SCHEMAS_TYPE_BLOCK_RESTRICTION)))) {
19769 continue;
19770 }
19771add_member:
19772 xmlSchemaAddElementSubstitutionMember(ctxt, head, elemDecl);
19773 if ((head->flags & XML_SCHEMAS_ELEM_SUBST_GROUP_HEAD) == 0)
19774 head->flags |= XML_SCHEMAS_ELEM_SUBST_GROUP_HEAD;
19775 }
19776 }
19777}
19778
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000019779#ifdef WXS_ELEM_DECL_CONS_ENABLED /* enable when finished */
19780/**
19781 * xmlSchemaCheckElementDeclComponent
19782 * @pctxt: the schema parser context
19783 * @ctxtComponent: the context component (an element declaration)
19784 * @ctxtParticle: the first particle of the context component
19785 * @searchParticle: the element declaration particle to be analysed
19786 *
Daniel Veillarddee23482008-04-11 12:58:43 +000019787 * Schema Component Constraint: Element Declarations Consistent
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000019788 */
19789static int
19790xmlSchemaCheckElementDeclConsistent(xmlSchemaParserCtxtPtr pctxt,
19791 xmlSchemaBasicItemPtr ctxtComponent,
Daniel Veillarddee23482008-04-11 12:58:43 +000019792 xmlSchemaParticlePtr ctxtParticle,
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000019793 xmlSchemaParticlePtr searchParticle,
19794 xmlSchemaParticlePtr curParticle,
19795 int search)
19796{
19797 return(0);
19798
19799 int ret = 0;
19800 xmlSchemaParticlePtr cur = curParticle;
Daniel Veillarddee23482008-04-11 12:58:43 +000019801 if (curParticle == NULL) {
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000019802 return(0);
19803 }
19804 if (WXS_PARTICLE_TERM(curParticle) == NULL) {
19805 /*
19806 * Just return in this case. A missing "term" of the particle
19807 * might arise due to an invalid "term" component.
19808 */
19809 return(0);
Daniel Veillarddee23482008-04-11 12:58:43 +000019810 }
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000019811 while (cur != NULL) {
19812 switch (WXS_PARTICLE_TERM(cur)->type) {
19813 case XML_SCHEMA_TYPE_ANY:
19814 break;
19815 case XML_SCHEMA_TYPE_ELEMENT:
19816 if (search == 0) {
19817 ret = xmlSchemaCheckElementDeclConsistent(pctxt,
19818 ctxtComponent, ctxtParticle, cur, ctxtParticle, 1);
19819 if (ret != 0)
Daniel Veillarddee23482008-04-11 12:58:43 +000019820 return(ret);
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000019821 } else {
19822 xmlSchemaElementPtr elem =
19823 WXS_ELEM_CAST(WXS_PARTICLE_TERM(cur));
19824 /*
19825 * SPEC Element Declarations Consistent:
19826 * "If the {particles} contains, either directly,
19827 * indirectly (that is, within the {particles} of a
Rob Richardsc6947bb2008-06-29 15:04:41 +000019828 * contained model group, recursively) or �implicitly�
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000019829 * two or more element declaration particles with
19830 * the same {name} and {target namespace}, then
19831 * all their type definitions must be the same
19832 * top-level definition [...]"
19833 */
19834 if (xmlStrEqual(WXS_PARTICLE_TERM_AS_ELEM(cur)->name,
19835 WXS_PARTICLE_TERM_AS_ELEM(searchParticle)->name) &&
19836 xmlStrEqual(WXS_PARTICLE_TERM_AS_ELEM(cur)->targetNamespace,
19837 WXS_PARTICLE_TERM_AS_ELEM(searchParticle)->targetNamespace))
19838 {
19839 xmlChar *strA = NULL, *strB = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000019840
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000019841 xmlSchemaCustomErr(ACTXT_CAST pctxt,
19842 /* TODO: error code */
19843 XML_SCHEMAP_COS_NONAMBIG,
19844 WXS_ITEM_NODE(cur), NULL,
19845 "In the content model of %s, there are multiple "
19846 "element declarations for '%s' with different "
19847 "type definitions",
19848 xmlSchemaGetComponentDesignation(&strA,
19849 ctxtComponent),
19850 xmlSchemaFormatQName(&strB,
19851 WXS_PARTICLE_TERM_AS_ELEM(cur)->targetNamespace,
19852 WXS_PARTICLE_TERM_AS_ELEM(cur)->name));
19853 FREE_AND_NULL(strA);
19854 FREE_AND_NULL(strB);
19855 return(XML_SCHEMAP_COS_NONAMBIG);
19856 }
Daniel Veillarddee23482008-04-11 12:58:43 +000019857 }
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000019858 break;
Daniel Veillarddee23482008-04-11 12:58:43 +000019859 case XML_SCHEMA_TYPE_SEQUENCE: {
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000019860 break;
19861 }
19862 case XML_SCHEMA_TYPE_CHOICE:{
19863 /*
19864 xmlSchemaTreeItemPtr sub;
Daniel Veillarddee23482008-04-11 12:58:43 +000019865
19866 sub = WXS_PARTICLE_TERM(particle)->children; (xmlSchemaParticlePtr)
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000019867 while (sub != NULL) {
19868 ret = xmlSchemaCheckElementDeclConsistent(pctxt, ctxtComponent,
19869 ctxtParticle, ctxtElem);
19870 if (ret != 0)
19871 return(ret);
19872 sub = sub->next;
19873 }
19874 */
19875 break;
19876 }
19877 case XML_SCHEMA_TYPE_ALL:
19878 break;
19879 case XML_SCHEMA_TYPE_GROUP:
19880 break;
19881 default:
19882 xmlSchemaInternalErr2(ACTXT_CAST pctxt,
19883 "xmlSchemaCheckElementDeclConsistent",
19884 "found unexpected term of type '%s' in content model",
19885 WXS_ITEM_TYPE_NAME(WXS_PARTICLE_TERM(cur)), NULL);
19886 return(-1);
19887 }
19888 cur = (xmlSchemaParticlePtr) cur->next;
19889 }
19890
19891exit:
19892 return(ret);
19893}
19894#endif
19895
Kasimier T. Buchcik016d92e2005-04-08 20:08:40 +000019896/**
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000019897 * xmlSchemaCheckElementDeclComponent
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000019898 * @item: an schema element declaration/particle
19899 * @ctxt: a schema parser context
19900 * @name: the name of the attribute
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019901 *
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000019902 * Validates the value constraints of an element declaration.
Daniel Veillarddee23482008-04-11 12:58:43 +000019903 * Adds substitution group members.
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000019904 */
19905static void
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000019906xmlSchemaCheckElementDeclComponent(xmlSchemaElementPtr elemDecl,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000019907 xmlSchemaParserCtxtPtr ctxt)
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000019908{
19909 if (elemDecl == NULL)
19910 return;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000019911 if (elemDecl->flags & XML_SCHEMAS_ELEM_INTERNAL_CHECKED)
19912 return;
19913 elemDecl->flags |= XML_SCHEMAS_ELEM_INTERNAL_CHECKED;
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000019914 if (xmlSchemaCheckElemPropsCorrect(ctxt, elemDecl) == 0) {
19915 /*
19916 * Adds substitution group members.
19917 */
Daniel Veillarddee23482008-04-11 12:58:43 +000019918 xmlSchemaCheckElemSubstGroup(ctxt, elemDecl);
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000019919 }
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000019920}
19921
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000019922/**
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019923 * xmlSchemaResolveModelGroupParticleReferences:
19924 * @particle: a particle component
19925 * @ctxt: a parser context
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000019926 *
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019927 * Resolves references of a model group's {particles} to
19928 * model group definitions and to element declarations.
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000019929 */
19930static void
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019931xmlSchemaResolveModelGroupParticleReferences(
19932 xmlSchemaParserCtxtPtr ctxt,
19933 xmlSchemaModelGroupPtr mg)
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000019934{
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019935 xmlSchemaParticlePtr particle = WXS_MODELGROUP_PARTICLE(mg);
19936 xmlSchemaQNameRefPtr ref;
19937 xmlSchemaBasicItemPtr refItem;
19938
19939 /*
19940 * URGENT TODO: Test this.
19941 */
19942 while (particle != NULL) {
19943 if ((WXS_PARTICLE_TERM(particle) == NULL) ||
19944 ((WXS_PARTICLE_TERM(particle))->type !=
19945 XML_SCHEMA_EXTRA_QNAMEREF))
19946 {
19947 goto next_particle;
Daniel Veillarddee23482008-04-11 12:58:43 +000019948 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019949 ref = WXS_QNAME_CAST WXS_PARTICLE_TERM(particle);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000019950 /*
19951 * Resolve the reference.
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019952 * NULL the {term} by default.
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000019953 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019954 particle->children = NULL;
19955
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000019956 refItem = xmlSchemaGetNamedComponent(ctxt->schema,
19957 ref->itemType, ref->name, ref->targetNamespace);
19958 if (refItem == NULL) {
19959 xmlSchemaPResCompAttrErr(ctxt, XML_SCHEMAP_SRC_RESOLVE,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019960 NULL, WXS_ITEM_NODE(particle), "ref", ref->name,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000019961 ref->targetNamespace, ref->itemType, NULL);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019962 /* TODO: remove the particle. */
19963 goto next_particle;
Daniel Veillarddee23482008-04-11 12:58:43 +000019964 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019965 if (refItem->type == XML_SCHEMA_TYPE_GROUP) {
19966 if (WXS_MODELGROUPDEF_MODEL(refItem) == NULL)
19967 /* TODO: remove the particle. */
19968 goto next_particle;
19969 /*
19970 * NOTE that we will assign the model group definition
19971 * itself to the "term" of the particle. This will ease
19972 * the check for circular model group definitions. After
19973 * that the "term" will be assigned the model group of the
19974 * model group definition.
19975 */
19976 if ((WXS_MODELGROUPDEF_MODEL(refItem))->type ==
19977 XML_SCHEMA_TYPE_ALL) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000019978 /*
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019979 * SPEC cos-all-limited (1)
19980 * SPEC cos-all-limited (1.2)
19981 * "It appears only as the value of one or both of the
19982 * following properties:"
19983 * (1.1) "the {model group} property of a model group
19984 * definition."
19985 * (1.2) "the {term} property of a particle [... of] the "
19986 * {content type} of a complex type definition."
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000019987 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000019988 xmlSchemaCustomErr(ACTXT_CAST ctxt,
19989 /* TODO: error code */
19990 XML_SCHEMAP_COS_ALL_LIMITED,
19991 WXS_ITEM_NODE(particle), NULL,
19992 "A model group definition is referenced, but "
19993 "it contains an 'all' model group, which "
19994 "cannot be contained by model groups",
19995 NULL, NULL);
19996 /* TODO: remove the particle. */
19997 goto next_particle;
19998 }
19999 particle->children = (xmlSchemaTreeItemPtr) refItem;
20000 } else {
20001 /*
20002 * TODO: Are referenced element declarations the only
20003 * other components we expect here?
20004 */
20005 particle->children = (xmlSchemaTreeItemPtr) refItem;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000020006 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020007next_particle:
20008 particle = WXS_PTC_CAST particle->next;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000020009 }
20010}
20011
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000020012static int
20013xmlSchemaAreValuesEqual(xmlSchemaValPtr x,
Daniel Veillarddee23482008-04-11 12:58:43 +000020014 xmlSchemaValPtr y)
20015{
20016 xmlSchemaTypePtr tx, ty, ptx, pty;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000020017 int ret;
20018
20019 while (x != NULL) {
20020 /* Same types. */
20021 tx = xmlSchemaGetBuiltInType(xmlSchemaGetValType(x));
20022 ty = xmlSchemaGetBuiltInType(xmlSchemaGetValType(y));
20023 ptx = xmlSchemaGetPrimitiveType(tx);
20024 pty = xmlSchemaGetPrimitiveType(ty);
20025 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000020026 * (1) if a datatype T' is �derived� by �restriction� from an
20027 * atomic datatype T then the �value space� of T' is a subset of
20028 * the �value space� of T. */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000020029 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000020030 * (2) if datatypes T' and T'' are �derived� by �restriction�
20031 * from a common atomic ancestor T then the �value space�s of T'
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000020032 * and T'' may overlap.
20033 */
20034 if (ptx != pty)
20035 return(0);
20036 /*
20037 * We assume computed values to be normalized, so do a fast
20038 * string comparison for string based types.
20039 */
20040 if ((ptx->builtInType == XML_SCHEMAS_STRING) ||
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020041 WXS_IS_ANY_SIMPLE_TYPE(ptx)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000020042 if (! xmlStrEqual(
20043 xmlSchemaValueGetAsString(x),
20044 xmlSchemaValueGetAsString(y)))
20045 return (0);
20046 } else {
20047 ret = xmlSchemaCompareValuesWhtsp(
20048 x, XML_SCHEMA_WHITESPACE_PRESERVE,
20049 y, XML_SCHEMA_WHITESPACE_PRESERVE);
20050 if (ret == -2)
20051 return(-1);
20052 if (ret != 0)
20053 return(0);
20054 }
20055 /*
20056 * Lists.
20057 */
20058 x = xmlSchemaValueGetNext(x);
20059 if (x != NULL) {
20060 y = xmlSchemaValueGetNext(y);
20061 if (y == NULL)
Daniel Veillarddee23482008-04-11 12:58:43 +000020062 return (0);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000020063 } else if (xmlSchemaValueGetNext(y) != NULL)
20064 return (0);
20065 else
20066 return (1);
20067 }
20068 return (0);
20069}
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000020070
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000020071/**
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020072 * xmlSchemaResolveAttrUseReferences:
20073 * @item: an attribute use
20074 * @ctxt: a parser context
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000020075 *
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020076 * Resolves the referenced attribute declaration.
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000020077 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020078static int
20079xmlSchemaResolveAttrUseReferences(xmlSchemaAttributeUsePtr ause,
20080 xmlSchemaParserCtxtPtr ctxt)
Daniel Veillard4255d502002-04-16 15:50:10 +000020081{
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020082 if ((ctxt == NULL) || (ause == NULL))
20083 return(-1);
20084 if ((ause->attrDecl == NULL) ||
20085 (ause->attrDecl->type != XML_SCHEMA_EXTRA_QNAMEREF))
20086 return(0);
20087
20088 {
20089 xmlSchemaQNameRefPtr ref = WXS_QNAME_CAST ause->attrDecl;
20090
20091 /*
20092 * TODO: Evaluate, what errors could occur if the declaration is not
20093 * found.
20094 */
20095 ause->attrDecl = xmlSchemaGetAttributeDecl(ctxt->schema,
20096 ref->name, ref->targetNamespace);
20097 if (ause->attrDecl == NULL) {
20098 xmlSchemaPResCompAttrErr(ctxt,
20099 XML_SCHEMAP_SRC_RESOLVE,
20100 WXS_BASIC_CAST ause, ause->node,
20101 "ref", ref->name, ref->targetNamespace,
20102 XML_SCHEMA_TYPE_ATTRIBUTE, NULL);
20103 return(ctxt->err);;
20104 }
20105 }
20106 return(0);
20107}
20108
20109/**
20110 * xmlSchemaCheckAttrUsePropsCorrect:
20111 * @ctxt: a parser context
Daniel Veillarddee23482008-04-11 12:58:43 +000020112 * @use: an attribute use
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020113 *
20114 * Schema Component Constraint:
20115 * Attribute Use Correct (au-props-correct)
Daniel Veillarddee23482008-04-11 12:58:43 +000020116 *
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020117 */
20118static int
20119xmlSchemaCheckAttrUsePropsCorrect(xmlSchemaParserCtxtPtr ctxt,
20120 xmlSchemaAttributeUsePtr use)
20121{
20122 if ((ctxt == NULL) || (use == NULL))
20123 return(-1);
20124 if ((use->defValue == NULL) || (WXS_ATTRUSE_DECL(use) == NULL) ||
20125 ((WXS_ATTRUSE_DECL(use))->type != XML_SCHEMA_TYPE_ATTRIBUTE))
Daniel Veillarddee23482008-04-11 12:58:43 +000020126 return(0);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020127
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000020128 /*
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020129 * SPEC au-props-correct (1)
20130 * "The values of the properties of an attribute use must be as
20131 * described in the property tableau in The Attribute Use Schema
Rob Richardsc6947bb2008-06-29 15:04:41 +000020132 * Component (�3.5.1), modulo the impact of Missing
20133 * Sub-components (�5.3)."
Daniel Veillardc0826a72004-08-10 14:17:33 +000020134 */
Daniel Veillarddee23482008-04-11 12:58:43 +000020135
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020136 if (((WXS_ATTRUSE_DECL(use))->defValue != NULL) &&
20137 ((WXS_ATTRUSE_DECL(use))->flags & XML_SCHEMAS_ATTR_FIXED) &&
20138 ((use->flags & XML_SCHEMA_ATTR_USE_FIXED) == 0))
20139 {
20140 xmlSchemaPCustomErr(ctxt,
20141 XML_SCHEMAP_AU_PROPS_CORRECT_2,
20142 WXS_BASIC_CAST use, NULL,
20143 "The attribute declaration has a 'fixed' value constraint "
20144 ", thus the attribute use must also have a 'fixed' value "
20145 "constraint",
20146 NULL);
20147 return(ctxt->err);
20148 }
20149 /*
20150 * Compute and check the value constraint's value.
20151 */
20152 if ((use->defVal != NULL) && (WXS_ATTRUSE_TYPEDEF(use) != NULL)) {
20153 int ret;
20154 /*
Daniel Veillarddee23482008-04-11 12:58:43 +000020155 * TODO: The spec seems to be missing a check of the
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020156 * value constraint of the attribute use. We will do it here.
20157 */
20158 /*
20159 * SPEC a-props-correct (3)
20160 */
20161 if (xmlSchemaIsDerivedFromBuiltInType(
20162 WXS_ATTRUSE_TYPEDEF(use), XML_SCHEMAS_ID))
20163 {
20164 xmlSchemaCustomErr(ACTXT_CAST ctxt,
20165 XML_SCHEMAP_AU_PROPS_CORRECT,
20166 NULL, WXS_BASIC_CAST use,
20167 "Value constraints are not allowed if the type definition "
20168 "is or is derived from xs:ID",
20169 NULL, NULL);
20170 return(ctxt->err);
20171 }
Daniel Veillarddee23482008-04-11 12:58:43 +000020172
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020173 ret = xmlSchemaVCheckCVCSimpleType(ACTXT_CAST ctxt,
20174 use->node, WXS_ATTRUSE_TYPEDEF(use),
20175 use->defValue, &(use->defVal),
20176 1, 1, 0);
20177 if (ret != 0) {
20178 if (ret < 0) {
20179 PERROR_INT2("xmlSchemaCheckAttrUsePropsCorrect",
20180 "calling xmlSchemaVCheckCVCSimpleType()");
20181 return(-1);
20182 }
20183 xmlSchemaCustomErr(ACTXT_CAST ctxt,
20184 XML_SCHEMAP_AU_PROPS_CORRECT,
20185 NULL, WXS_BASIC_CAST use,
20186 "The value of the value constraint is not valid",
20187 NULL, NULL);
20188 return(ctxt->err);
20189 }
20190 }
20191 /*
20192 * SPEC au-props-correct (2)
20193 * "If the {attribute declaration} has a fixed
20194 * {value constraint}, then if the attribute use itself has a
20195 * {value constraint}, it must also be fixed and its value must match
20196 * that of the {attribute declaration}'s {value constraint}."
20197 */
20198 if (((WXS_ATTRUSE_DECL(use))->defVal != NULL) &&
20199 (((WXS_ATTRUSE_DECL(use))->flags & XML_SCHEMA_ATTR_USE_FIXED) == 0))
20200 {
20201 if (! xmlSchemaAreValuesEqual(use->defVal,
20202 (WXS_ATTRUSE_DECL(use))->defVal))
20203 {
20204 xmlSchemaPCustomErr(ctxt,
20205 XML_SCHEMAP_AU_PROPS_CORRECT_2,
20206 WXS_BASIC_CAST use, NULL,
20207 "The 'fixed' value constraint of the attribute use "
20208 "must match the attribute declaration's value "
20209 "constraint '%s'",
20210 (WXS_ATTRUSE_DECL(use))->defValue);
20211 }
20212 return(ctxt->err);
20213 }
20214 return(0);
20215}
20216
20217
20218
20219
20220/**
20221 * xmlSchemaResolveAttrTypeReferences:
20222 * @item: an attribute declaration
Daniel Veillarddee23482008-04-11 12:58:43 +000020223 * @ctxt: a parser context
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020224 *
20225 * Resolves the referenced type definition component.
20226 */
20227static int
20228xmlSchemaResolveAttrTypeReferences(xmlSchemaAttributePtr item,
20229 xmlSchemaParserCtxtPtr ctxt)
20230{
Daniel Veillard01fa6152004-06-29 17:04:39 +000020231 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000020232 * The simple type definition corresponding to the <simpleType> element
20233 * information item in the [children], if present, otherwise the simple
Rob Richardsc6947bb2008-06-29 15:04:41 +000020234 * type definition �resolved� to by the �actual value� of the type
20235 * [attribute], if present, otherwise the �simple ur-type definition�.
Daniel Veillard01fa6152004-06-29 17:04:39 +000020236 */
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000020237 if (item->flags & XML_SCHEMAS_ATTR_INTERNAL_RESOLVED)
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020238 return(0);
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000020239 item->flags |= XML_SCHEMAS_ATTR_INTERNAL_RESOLVED;
20240 if (item->subtypes != NULL)
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020241 return(0);
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000020242 if (item->typeName != NULL) {
Daniel Veillardd0c9c322003-10-10 00:49:42 +000020243 xmlSchemaTypePtr type;
Daniel Veillard4255d502002-04-16 15:50:10 +000020244
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000020245 type = xmlSchemaGetType(ctxt->schema, item->typeName,
20246 item->typeNs);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020247 if ((type == NULL) || (! WXS_IS_SIMPLE(type))) {
Daniel Veillardc0826a72004-08-10 14:17:33 +000020248 xmlSchemaPResCompAttrErr(ctxt,
Daniel Veillard01fa6152004-06-29 17:04:39 +000020249 XML_SCHEMAP_SRC_RESOLVE,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020250 WXS_BASIC_CAST item, item->node,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000020251 "type", item->typeName, item->typeNs,
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000020252 XML_SCHEMA_TYPE_SIMPLE, NULL);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020253 return(ctxt->err);
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000020254 } else
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000020255 item->subtypes = type;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000020256
Daniel Veillard3646d642004-06-02 19:19:14 +000020257 } else {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020258 /*
20259 * The type defaults to the xs:anySimpleType.
20260 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000020261 item->subtypes = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE);
20262 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020263 return(0);
Daniel Veillard4255d502002-04-16 15:50:10 +000020264}
20265
20266/**
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000020267 * xmlSchemaResolveIDCKeyReferences:
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000020268 * @idc: the identity-constraint definition
20269 * @ctxt: the schema parser context
20270 * @name: the attribute name
20271 *
20272 * Resolve keyRef references to key/unique IDCs.
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000020273 * Schema Component Constraint:
20274 * Identity-constraint Definition Properties Correct (c-props-correct)
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000020275 */
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000020276static int
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000020277xmlSchemaResolveIDCKeyReferences(xmlSchemaIDCPtr idc,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020278 xmlSchemaParserCtxtPtr pctxt)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000020279{
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000020280 if (idc->type != XML_SCHEMA_TYPE_IDC_KEYREF)
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000020281 return(0);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000020282 if (idc->ref->name != NULL) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000020283 idc->ref->item = (xmlSchemaBasicItemPtr)
20284 xmlSchemaGetIDC(pctxt->schema, idc->ref->name,
20285 idc->ref->targetNamespace);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000020286 if (idc->ref->item == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000020287 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000020288 * TODO: It is actually not an error to fail to resolve
20289 * at this stage. BUT we need to be that strict!
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000020290 */
Kasimier T. Buchcikc306d902005-07-08 21:37:44 +000020291 xmlSchemaPResCompAttrErr(pctxt,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000020292 XML_SCHEMAP_SRC_RESOLVE,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020293 WXS_BASIC_CAST idc, idc->node,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000020294 "refer", idc->ref->name,
20295 idc->ref->targetNamespace,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000020296 XML_SCHEMA_TYPE_IDC_KEY, NULL);
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000020297 return(pctxt->err);
20298 } else if (idc->ref->item->type == XML_SCHEMA_TYPE_IDC_KEYREF) {
20299 /*
20300 * SPEC c-props-correct (1)
20301 */
20302 xmlSchemaCustomErr(ACTXT_CAST pctxt,
20303 XML_SCHEMAP_C_PROPS_CORRECT,
20304 NULL, WXS_BASIC_CAST idc,
20305 "The keyref references a keyref",
20306 NULL, NULL);
20307 idc->ref->item = NULL;
20308 return(pctxt->err);
Kasimier T. Buchcikc306d902005-07-08 21:37:44 +000020309 } else {
20310 if (idc->nbFields !=
20311 ((xmlSchemaIDCPtr) idc->ref->item)->nbFields) {
20312 xmlChar *str = NULL;
20313 xmlSchemaIDCPtr refer;
Daniel Veillarddee23482008-04-11 12:58:43 +000020314
Kasimier T. Buchcikc306d902005-07-08 21:37:44 +000020315 refer = (xmlSchemaIDCPtr) idc->ref->item;
20316 /*
20317 * SPEC c-props-correct(2)
20318 * "If the {identity-constraint category} is keyref,
20319 * the cardinality of the {fields} must equal that of
20320 * the {fields} of the {referenced key}.
20321 */
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000020322 xmlSchemaCustomErr(ACTXT_CAST pctxt,
Kasimier T. Buchcikc306d902005-07-08 21:37:44 +000020323 XML_SCHEMAP_C_PROPS_CORRECT,
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000020324 NULL, WXS_BASIC_CAST idc,
Kasimier T. Buchcikc306d902005-07-08 21:37:44 +000020325 "The cardinality of the keyref differs from the "
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000020326 "cardinality of the referenced key/unique '%s'",
Kasimier T. Buchcikc306d902005-07-08 21:37:44 +000020327 xmlSchemaFormatQName(&str, refer->targetNamespace,
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000020328 refer->name),
20329 NULL);
Kasimier T. Buchcikc306d902005-07-08 21:37:44 +000020330 FREE_AND_NULL(str)
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000020331 return(pctxt->err);
Kasimier T. Buchcikc306d902005-07-08 21:37:44 +000020332 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000020333 }
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000020334 }
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000020335 return(0);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000020336}
20337
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020338static int
20339xmlSchemaResolveAttrUseProhibReferences(xmlSchemaAttributeUseProhibPtr prohib,
20340 xmlSchemaParserCtxtPtr pctxt)
20341{
20342 if (xmlSchemaGetAttributeDecl(pctxt->schema, prohib->name,
20343 prohib->targetNamespace) == NULL) {
20344
20345 xmlSchemaPResCompAttrErr(pctxt,
20346 XML_SCHEMAP_SRC_RESOLVE,
20347 NULL, prohib->node,
20348 "ref", prohib->name, prohib->targetNamespace,
20349 XML_SCHEMA_TYPE_ATTRIBUTE, NULL);
20350 return(XML_SCHEMAP_SRC_RESOLVE);
20351 }
20352 return(0);
20353}
20354
20355#define WXS_REDEFINED_TYPE(c) \
20356(((xmlSchemaTypePtr) item)->flags & XML_SCHEMAS_TYPE_REDEFINED)
20357
20358#define WXS_REDEFINED_MODEL_GROUP_DEF(c) \
20359(((xmlSchemaModelGroupDefPtr) item)->flags & XML_SCHEMA_MODEL_GROUP_DEF_REDEFINED)
20360
20361#define WXS_REDEFINED_ATTR_GROUP(c) \
20362(((xmlSchemaAttributeGroupPtr) item)->flags & XML_SCHEMAS_ATTRGROUP_REDEFINED)
20363
20364static int
20365xmlSchemaCheckSRCRedefineFirst(xmlSchemaParserCtxtPtr pctxt)
20366{
20367 int err = 0;
20368 xmlSchemaRedefPtr redef = WXS_CONSTRUCTOR(pctxt)->redefs;
20369 xmlSchemaBasicItemPtr prev, item;
20370 int wasRedefined;
20371
20372 if (redef == NULL)
Daniel Veillarddee23482008-04-11 12:58:43 +000020373 return(0);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020374
20375 do {
20376 item = redef->item;
20377 /*
20378 * First try to locate the redefined component in the
20379 * schema graph starting with the redefined schema.
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000020380 * NOTE: According to this schema bug entry:
20381 * http://lists.w3.org/Archives/Public/www-xml-schema-comments/2005OctDec/0019.html
20382 * it's not clear if the referenced component needs to originate
20383 * from the <redefine>d schema _document_ or the schema; the latter
20384 * would include all imported and included sub-schemas of the
20385 * <redefine>d schema. Currenlty we latter approach is used.
20386 * SUPPLEMENT: It seems that the WG moves towards the latter
20387 * approach, so we are doing it right.
Daniel Veillarddee23482008-04-11 12:58:43 +000020388 *
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020389 */
20390 prev = xmlSchemaFindRedefCompInGraph(
20391 redef->targetBucket, item->type,
20392 redef->refName, redef->refTargetNs);
20393 if (prev == NULL) {
20394 xmlChar *str = NULL;
20395 xmlNodePtr node;
20396
20397 /*
20398 * SPEC src-redefine:
Rob Richardsc6947bb2008-06-29 15:04:41 +000020399 * (6.2.1) "The �actual value� of its own name attribute plus
20400 * target namespace must successfully �resolve� to a model
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020401 * group definition in I."
Rob Richardsc6947bb2008-06-29 15:04:41 +000020402 * (7.2.1) "The �actual value� of its own name attribute plus
20403 * target namespace must successfully �resolve� to an attribute
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020404 * group definition in I."
20405
20406 *
20407 * Note that, if we are redefining with the use of references
20408 * to components, the spec assumes the src-resolve to be used;
20409 * but this won't assure that we search only *inside* the
20410 * redefined schema.
20411 */
20412 if (redef->reference)
20413 node = WXS_ITEM_NODE(redef->reference);
20414 else
20415 node = WXS_ITEM_NODE(item);
20416 xmlSchemaCustomErr(ACTXT_CAST pctxt,
20417 /*
20418 * TODO: error code.
20419 * Probably XML_SCHEMAP_SRC_RESOLVE, if this is using the
Daniel Veillarddee23482008-04-11 12:58:43 +000020420 * reference kind.
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020421 */
20422 XML_SCHEMAP_SRC_REDEFINE, node, NULL,
Kasimier T. Buchcik5d2998b2005-11-22 17:36:01 +000020423 "The %s '%s' to be redefined could not be found in "
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020424 "the redefined schema",
20425 WXS_ITEM_TYPE_NAME(item),
20426 xmlSchemaFormatQName(&str, redef->refTargetNs,
20427 redef->refName));
Daniel Veillarddee23482008-04-11 12:58:43 +000020428 FREE_AND_NULL(str);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020429 err = pctxt->err;
20430 redef = redef->next;
20431 continue;
20432 }
20433 /*
20434 * TODO: Obtaining and setting the redefinition state is really
20435 * clumsy.
20436 */
20437 wasRedefined = 0;
20438 switch (item->type) {
20439 case XML_SCHEMA_TYPE_COMPLEX:
20440 case XML_SCHEMA_TYPE_SIMPLE:
20441 if ((WXS_TYPE_CAST prev)->flags &
20442 XML_SCHEMAS_TYPE_REDEFINED)
20443 {
20444 wasRedefined = 1;
20445 break;
20446 }
20447 /* Mark it as redefined. */
20448 (WXS_TYPE_CAST prev)->flags |= XML_SCHEMAS_TYPE_REDEFINED;
20449 /*
20450 * Assign the redefined type to the
20451 * base type of the redefining type.
20452 * TODO: How
20453 */
Daniel Veillarddee23482008-04-11 12:58:43 +000020454 ((xmlSchemaTypePtr) item)->baseType =
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020455 (xmlSchemaTypePtr) prev;
20456 break;
20457 case XML_SCHEMA_TYPE_GROUP:
20458 if ((WXS_MODEL_GROUPDEF_CAST prev)->flags &
20459 XML_SCHEMA_MODEL_GROUP_DEF_REDEFINED)
20460 {
20461 wasRedefined = 1;
20462 break;
20463 }
20464 /* Mark it as redefined. */
20465 (WXS_MODEL_GROUPDEF_CAST prev)->flags |=
20466 XML_SCHEMA_MODEL_GROUP_DEF_REDEFINED;
20467 if (redef->reference != NULL) {
20468 /*
20469 * Overwrite the QName-reference with the
20470 * referenced model group def.
20471 */
20472 (WXS_PTC_CAST redef->reference)->children =
20473 WXS_TREE_CAST prev;
20474 }
20475 redef->target = prev;
20476 break;
20477 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
20478 if ((WXS_ATTR_GROUP_CAST prev)->flags &
20479 XML_SCHEMAS_ATTRGROUP_REDEFINED)
20480 {
20481 wasRedefined = 1;
20482 break;
20483 }
20484 (WXS_ATTR_GROUP_CAST prev)->flags |=
20485 XML_SCHEMAS_ATTRGROUP_REDEFINED;
20486 if (redef->reference != NULL) {
20487 /*
20488 * Assign the redefined attribute group to the
20489 * QName-reference component.
20490 * This is the easy case, since we will just
20491 * expand the redefined group.
20492 */
20493 (WXS_QNAME_CAST redef->reference)->item = prev;
20494 redef->target = NULL;
20495 } else {
20496 /*
20497 * This is the complicated case: we need
20498 * to apply src-redefine (7.2.2) at a later
20499 * stage, i.e. when attribute group references
20500 * have beed expanded and simple types have
20501 * beed fixed.
20502 */
20503 redef->target = prev;
20504 }
20505 break;
20506 default:
20507 PERROR_INT("xmlSchemaResolveRedefReferences",
20508 "Unexpected redefined component type");
Daniel Veillarddee23482008-04-11 12:58:43 +000020509 return(-1);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020510 }
20511 if (wasRedefined) {
20512 xmlChar *str = NULL;
20513 xmlNodePtr node;
20514
20515 if (redef->reference)
20516 node = WXS_ITEM_NODE(redef->reference);
20517 else
20518 node = WXS_ITEM_NODE(redef->item);
Daniel Veillarddee23482008-04-11 12:58:43 +000020519
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020520 xmlSchemaCustomErr(ACTXT_CAST pctxt,
20521 /* TODO: error code. */
20522 XML_SCHEMAP_SRC_REDEFINE,
20523 node, NULL,
20524 "The referenced %s was already redefined. Multiple "
20525 "redefinition of the same component is not supported",
20526 xmlSchemaGetComponentDesignation(&str, prev),
20527 NULL);
Daniel Veillarddee23482008-04-11 12:58:43 +000020528 FREE_AND_NULL(str)
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020529 err = pctxt->err;
20530 redef = redef->next;
20531 continue;
20532 }
Daniel Veillarddee23482008-04-11 12:58:43 +000020533 redef = redef->next;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020534 } while (redef != NULL);
20535
20536 return(err);
20537}
20538
20539static int
20540xmlSchemaCheckSRCRedefineSecond(xmlSchemaParserCtxtPtr pctxt)
20541{
20542 int err = 0;
20543 xmlSchemaRedefPtr redef = WXS_CONSTRUCTOR(pctxt)->redefs;
20544 xmlSchemaBasicItemPtr item;
20545
20546 if (redef == NULL)
Daniel Veillarddee23482008-04-11 12:58:43 +000020547 return(0);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020548
20549 do {
20550 if (redef->target == NULL) {
20551 redef = redef->next;
20552 continue;
20553 }
20554 item = redef->item;
Daniel Veillarddee23482008-04-11 12:58:43 +000020555
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020556 switch (item->type) {
20557 case XML_SCHEMA_TYPE_SIMPLE:
20558 case XML_SCHEMA_TYPE_COMPLEX:
20559 /*
20560 * Since the spec wants the {name} of the redefined
20561 * type to be 'absent', we'll NULL it.
20562 */
20563 (WXS_TYPE_CAST redef->target)->name = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000020564
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020565 /*
20566 * TODO: Seems like there's nothing more to do. The normal
20567 * inheritance mechanism is used. But not 100% sure.
20568 */
20569 break;
20570 case XML_SCHEMA_TYPE_GROUP:
20571 /*
20572 * URGENT TODO:
20573 * SPEC src-redefine:
20574 * (6.2.2) "The {model group} of the model group definition
20575 * which corresponds to it per XML Representation of Model
Rob Richardsc6947bb2008-06-29 15:04:41 +000020576 * Group Definition Schema Components (�3.7.2) must be a
20577 * �valid restriction� of the {model group} of that model
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020578 * group definition in I, as defined in Particle Valid
Rob Richardsc6947bb2008-06-29 15:04:41 +000020579 * (Restriction) (�3.9.6)."
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020580 */
20581 break;
20582 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
20583 /*
20584 * SPEC src-redefine:
20585 * (7.2.2) "The {attribute uses} and {attribute wildcard} of
20586 * the attribute group definition which corresponds to it
20587 * per XML Representation of Attribute Group Definition Schema
Rob Richardsc6947bb2008-06-29 15:04:41 +000020588 * Components (�3.6.2) must be �valid restrictions� of the
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020589 * {attribute uses} and {attribute wildcard} of that attribute
20590 * group definition in I, as defined in clause 2, clause 3 and
20591 * clause 4 of Derivation Valid (Restriction, Complex)
Rob Richardsc6947bb2008-06-29 15:04:41 +000020592 * (�3.4.6) (where references to the base type definition are
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020593 * understood as references to the attribute group definition
20594 * in I)."
20595 */
20596 err = xmlSchemaCheckDerivationOKRestriction2to4(pctxt,
20597 XML_SCHEMA_ACTION_REDEFINE,
20598 item, redef->target,
20599 (WXS_ATTR_GROUP_CAST item)->attrUses,
20600 (WXS_ATTR_GROUP_CAST redef->target)->attrUses,
20601 (WXS_ATTR_GROUP_CAST item)->attributeWildcard,
20602 (WXS_ATTR_GROUP_CAST redef->target)->attributeWildcard);
20603 if (err == -1)
20604 return(-1);
20605 break;
20606 default:
20607 break;
20608 }
20609 redef = redef->next;
20610 } while (redef != NULL);
20611 return(0);
20612}
Daniel Veillarddee23482008-04-11 12:58:43 +000020613
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020614
20615static int
20616xmlSchemaAddComponents(xmlSchemaParserCtxtPtr pctxt,
20617 xmlSchemaBucketPtr bucket)
20618{
20619 xmlSchemaBasicItemPtr item;
20620 int err;
20621 xmlHashTablePtr *table;
20622 const xmlChar *name;
20623 int i;
20624
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000020625#define WXS_GET_GLOBAL_HASH(c, slot) { \
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020626 if (WXS_IS_BUCKET_IMPMAIN((c)->type)) \
20627 table = &(WXS_IMPBUCKET((c))->schema->slot); \
20628 else \
20629 table = &(WXS_INCBUCKET((c))->ownerImport->schema->slot); }
20630
20631 /*
20632 * Add global components to the schema's hash tables.
20633 * This is the place where duplicate components will be
20634 * detected.
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000020635 * TODO: I think normally we should support imports of the
20636 * same namespace from multiple locations. We don't do currently,
20637 * but if we do then according to:
20638 * http://www.w3.org/Bugs/Public/show_bug.cgi?id=2224
20639 * we would need, if imported directly, to import redefined
20640 * components as well to be able to catch clashing components.
20641 * (I hope I'll still know what this means after some months :-()
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020642 */
20643 if (bucket == NULL)
20644 return(-1);
20645 if (bucket->flags & XML_SCHEMA_BUCKET_COMPS_ADDED)
20646 return(0);
Daniel Veillarddee23482008-04-11 12:58:43 +000020647 bucket->flags |= XML_SCHEMA_BUCKET_COMPS_ADDED;
20648
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020649 for (i = 0; i < bucket->globals->nbItems; i++) {
20650 item = bucket->globals->items[i];
20651 table = NULL;
20652 switch (item->type) {
20653 case XML_SCHEMA_TYPE_COMPLEX:
20654 case XML_SCHEMA_TYPE_SIMPLE:
20655 if (WXS_REDEFINED_TYPE(item))
20656 continue;
20657 name = (WXS_TYPE_CAST item)->name;
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000020658 WXS_GET_GLOBAL_HASH(bucket, typeDecl)
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020659 break;
20660 case XML_SCHEMA_TYPE_ELEMENT:
20661 name = (WXS_ELEM_CAST item)->name;
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000020662 WXS_GET_GLOBAL_HASH(bucket, elemDecl)
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020663 break;
20664 case XML_SCHEMA_TYPE_ATTRIBUTE:
20665 name = (WXS_ATTR_CAST item)->name;
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000020666 WXS_GET_GLOBAL_HASH(bucket, attrDecl)
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020667 break;
20668 case XML_SCHEMA_TYPE_GROUP:
20669 if (WXS_REDEFINED_MODEL_GROUP_DEF(item))
20670 continue;
20671 name = (WXS_MODEL_GROUPDEF_CAST item)->name;
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000020672 WXS_GET_GLOBAL_HASH(bucket, groupDecl)
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020673 break;
20674 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
20675 if (WXS_REDEFINED_ATTR_GROUP(item))
20676 continue;
20677 name = (WXS_ATTR_GROUP_CAST item)->name;
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000020678 WXS_GET_GLOBAL_HASH(bucket, attrgrpDecl)
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020679 break;
20680 case XML_SCHEMA_TYPE_IDC_KEY:
20681 case XML_SCHEMA_TYPE_IDC_UNIQUE:
20682 case XML_SCHEMA_TYPE_IDC_KEYREF:
20683 name = (WXS_IDC_CAST item)->name;
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000020684 WXS_GET_GLOBAL_HASH(bucket, idcDef)
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020685 break;
20686 case XML_SCHEMA_TYPE_NOTATION:
20687 name = ((xmlSchemaNotationPtr) item)->name;
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000020688 WXS_GET_GLOBAL_HASH(bucket, notaDecl)
Daniel Veillarddee23482008-04-11 12:58:43 +000020689 break;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020690 default:
20691 PERROR_INT("xmlSchemaAddComponents",
20692 "Unexpected global component type");
Daniel Veillarddee23482008-04-11 12:58:43 +000020693 continue;
20694 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020695 if (*table == NULL) {
20696 *table = xmlHashCreateDict(10, pctxt->dict);
20697 if (*table == NULL) {
20698 PERROR_INT("xmlSchemaAddComponents",
20699 "failed to create a component hash table");
20700 return(-1);
20701 }
Daniel Veillarddee23482008-04-11 12:58:43 +000020702 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020703 err = xmlHashAddEntry(*table, name, item);
Daniel Veillarddee23482008-04-11 12:58:43 +000020704 if (err != 0) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020705 xmlChar *str = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000020706
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020707 xmlSchemaCustomErr(ACTXT_CAST pctxt,
20708 XML_SCHEMAP_REDEFINED_TYPE,
20709 WXS_ITEM_NODE(item),
20710 WXS_BASIC_CAST item,
20711 "A global %s '%s' does already exist",
20712 WXS_ITEM_TYPE_NAME(item),
20713 xmlSchemaGetComponentQName(&str, item));
Daniel Veillarddee23482008-04-11 12:58:43 +000020714 FREE_AND_NULL(str);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020715 }
20716 }
20717 /*
20718 * Process imported/included schemas.
20719 */
20720 if (bucket->relations != NULL) {
20721 xmlSchemaSchemaRelationPtr rel = bucket->relations;
20722 do {
20723 if ((rel->bucket != NULL) &&
20724 ((rel->bucket->flags & XML_SCHEMA_BUCKET_COMPS_ADDED) == 0)) {
20725 if (xmlSchemaAddComponents(pctxt, rel->bucket) == -1)
20726 return(-1);
20727 }
20728 rel = rel->next;
20729 } while (rel != NULL);
20730 }
20731 return(0);
20732}
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000020733
20734static int
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000020735xmlSchemaFixupComponents(xmlSchemaParserCtxtPtr pctxt,
20736 xmlSchemaBucketPtr rootBucket)
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000020737{
20738 xmlSchemaConstructionCtxtPtr con = pctxt->constructor;
20739 xmlSchemaTreeItemPtr item, *items;
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000020740 int nbItems, i, ret = 0;
Kasimier T. Buchcik4c0aa162006-02-20 14:47:08 +000020741 xmlSchemaBucketPtr oldbucket = con->bucket;
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000020742 xmlSchemaElementPtr elemDecl;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000020743
20744#define FIXHFAILURE if (pctxt->err == XML_SCHEMAP_INTERNAL) goto exit_failure;
20745
20746 if ((con->pending == NULL) ||
20747 (con->pending->nbItems == 0))
Daniel Veillarddee23482008-04-11 12:58:43 +000020748 return(0);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020749
Kasimier T. Buchcik4c0aa162006-02-20 14:47:08 +000020750 /*
20751 * Since xmlSchemaFixupComplexType() will create new particles
20752 * (local components), and those particle components need a bucket
20753 * on the constructor, we'll assure here that the constructor has
20754 * a bucket.
Daniel Veillarddee23482008-04-11 12:58:43 +000020755 * TODO: Think about storing locals _only_ on the main bucket.
20756 */
Kasimier T. Buchcik4c0aa162006-02-20 14:47:08 +000020757 if (con->bucket == NULL)
Daniel Veillarddee23482008-04-11 12:58:43 +000020758 con->bucket = rootBucket;
Kasimier T. Buchcik4c0aa162006-02-20 14:47:08 +000020759
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020760 /* TODO:
20761 * SPEC (src-redefine):
20762 * (6.2) "If it has no such self-reference, then all of the
20763 * following must be true:"
Daniel Veillarddee23482008-04-11 12:58:43 +000020764
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020765 * (6.2.2) The {model group} of the model group definition which
20766 * corresponds to it per XML Representation of Model Group
Rob Richardsc6947bb2008-06-29 15:04:41 +000020767 * Definition Schema Components (�3.7.2) must be a �valid
20768 * restriction� of the {model group} of that model group definition
20769 * in I, as defined in Particle Valid (Restriction) (�3.9.6)."
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020770 */
20771 xmlSchemaCheckSRCRedefineFirst(pctxt);
20772
20773 /*
20774 * Add global components to the schemata's hash tables.
Daniel Veillarddee23482008-04-11 12:58:43 +000020775 */
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000020776 xmlSchemaAddComponents(pctxt, rootBucket);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000020777
20778 pctxt->ctxtType = NULL;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000020779 items = (xmlSchemaTreeItemPtr *) con->pending->items;
20780 nbItems = con->pending->nbItems;
20781 /*
20782 * Now that we have parsed *all* the schema document(s) and converted
20783 * them to schema components, we can resolve references, apply component
20784 * constraints, create the FSA from the content model, etc.
Daniel Veillarddee23482008-04-11 12:58:43 +000020785 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000020786 /*
20787 * Resolve references of..
20788 *
20789 * 1. element declarations:
20790 * - the type definition
20791 * - the substitution group affiliation
20792 * 2. simple/complex types:
20793 * - the base type definition
20794 * - the memberTypes of union types
20795 * - the itemType of list types
20796 * 3. attributes declarations and attribute uses:
20797 * - the type definition
20798 * - if an attribute use, then the attribute declaration
20799 * 4. attribute group references:
20800 * - the attribute group definition
20801 * 5. particles:
20802 * - the term of the particle (e.g. a model group)
20803 * 6. IDC key-references:
20804 * - the referenced IDC 'key' or 'unique' definition
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020805 * 7. Attribute prohibitions which had a "ref" attribute.
Daniel Veillarddee23482008-04-11 12:58:43 +000020806 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000020807 for (i = 0; i < nbItems; i++) {
20808 item = items[i];
20809 switch (item->type) {
20810 case XML_SCHEMA_TYPE_ELEMENT:
20811 xmlSchemaResolveElementReferences(
20812 (xmlSchemaElementPtr) item, pctxt);
20813 FIXHFAILURE;
20814 break;
20815 case XML_SCHEMA_TYPE_COMPLEX:
20816 case XML_SCHEMA_TYPE_SIMPLE:
20817 xmlSchemaResolveTypeReferences(
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020818 (xmlSchemaTypePtr) item, pctxt);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000020819 FIXHFAILURE;
20820 break;
20821 case XML_SCHEMA_TYPE_ATTRIBUTE:
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020822 xmlSchemaResolveAttrTypeReferences(
20823 (xmlSchemaAttributePtr) item, pctxt);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000020824 FIXHFAILURE;
20825 break;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020826 case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
20827 xmlSchemaResolveAttrUseReferences(
20828 (xmlSchemaAttributeUsePtr) item, pctxt);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000020829 FIXHFAILURE;
20830 break;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020831 case XML_SCHEMA_EXTRA_QNAMEREF:
Daniel Veillarddee23482008-04-11 12:58:43 +000020832 if ((WXS_QNAME_CAST item)->itemType ==
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020833 XML_SCHEMA_TYPE_ATTRIBUTEGROUP)
20834 {
20835 xmlSchemaResolveAttrGroupReferences(
20836 WXS_QNAME_CAST item, pctxt);
20837 }
20838 FIXHFAILURE;
20839 break;
20840 case XML_SCHEMA_TYPE_SEQUENCE:
20841 case XML_SCHEMA_TYPE_CHOICE:
20842 case XML_SCHEMA_TYPE_ALL:
20843 xmlSchemaResolveModelGroupParticleReferences(pctxt,
20844 WXS_MODEL_GROUP_CAST item);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000020845 FIXHFAILURE;
20846 break;
20847 case XML_SCHEMA_TYPE_IDC_KEY:
20848 case XML_SCHEMA_TYPE_IDC_UNIQUE:
20849 case XML_SCHEMA_TYPE_IDC_KEYREF:
20850 xmlSchemaResolveIDCKeyReferences(
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020851 (xmlSchemaIDCPtr) item, pctxt);
20852 FIXHFAILURE;
20853 break;
20854 case XML_SCHEMA_EXTRA_ATTR_USE_PROHIB:
20855 /*
20856 * Handle attribue prohibition which had a
20857 * "ref" attribute.
20858 */
20859 xmlSchemaResolveAttrUseProhibReferences(
20860 WXS_ATTR_PROHIB_CAST item, pctxt);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000020861 FIXHFAILURE;
20862 break;
20863 default:
20864 break;
20865 }
20866 }
20867 if (pctxt->nberrors != 0)
20868 goto exit_error;
Daniel Veillarddee23482008-04-11 12:58:43 +000020869
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000020870 /*
20871 * Now that all references are resolved we
20872 * can check for circularity of...
Daniel Veillarddee23482008-04-11 12:58:43 +000020873 * 1. the base axis of type definitions
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000020874 * 2. nested model group definitions
20875 * 3. nested attribute group definitions
20876 * TODO: check for circual substitution groups.
20877 */
20878 for (i = 0; i < nbItems; i++) {
20879 item = items[i];
20880 /*
20881 * Let's better stop on the first error here.
20882 */
20883 switch (item->type) {
20884 case XML_SCHEMA_TYPE_COMPLEX:
20885 case XML_SCHEMA_TYPE_SIMPLE:
20886 xmlSchemaCheckTypeDefCircular(
20887 (xmlSchemaTypePtr) item, pctxt);
20888 FIXHFAILURE;
20889 if (pctxt->nberrors != 0)
20890 goto exit_error;
20891 break;
20892 case XML_SCHEMA_TYPE_GROUP:
20893 xmlSchemaCheckGroupDefCircular(
20894 (xmlSchemaModelGroupDefPtr) item, pctxt);
20895 FIXHFAILURE;
20896 if (pctxt->nberrors != 0)
20897 goto exit_error;
20898 break;
20899 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
20900 xmlSchemaCheckAttrGroupCircular(
20901 (xmlSchemaAttributeGroupPtr) item, pctxt);
20902 FIXHFAILURE;
20903 if (pctxt->nberrors != 0)
20904 goto exit_error;
20905 break;
20906 default:
20907 break;
Daniel Veillarddee23482008-04-11 12:58:43 +000020908 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000020909 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020910 if (pctxt->nberrors != 0)
20911 goto exit_error;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000020912 /*
20913 * Model group definition references:
20914 * Such a reference is reflected by a particle at the component
20915 * level. Until now the 'term' of such particles pointed
20916 * to the model group definition; this was done, in order to
20917 * ease circularity checks. Now we need to set the 'term' of
20918 * such particles to the model group of the model group definition.
20919 */
20920 for (i = 0; i < nbItems; i++) {
20921 item = items[i];
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020922 switch (item->type) {
20923 case XML_SCHEMA_TYPE_SEQUENCE:
Daniel Veillarddee23482008-04-11 12:58:43 +000020924 case XML_SCHEMA_TYPE_CHOICE:
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020925 xmlSchemaModelGroupToModelGroupDefFixup(pctxt,
20926 WXS_MODEL_GROUP_CAST item);
20927 break;
20928 default:
20929 break;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000020930 }
20931 }
20932 if (pctxt->nberrors != 0)
20933 goto exit_error;
20934 /*
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020935 * Expand attribute group references of attribute group definitions.
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000020936 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020937 for (i = 0; i < nbItems; i++) {
20938 item = items[i];
20939 switch (item->type) {
20940 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
20941 if ((! WXS_ATTR_GROUP_EXPANDED(item)) &&
20942 WXS_ATTR_GROUP_HAS_REFS(item))
20943 {
20944 xmlSchemaAttributeGroupExpandRefs(pctxt,
20945 WXS_ATTR_GROUP_CAST item);
20946 FIXHFAILURE;
20947 }
20948 break;
20949 default:
20950 break;
20951 }
20952 }
20953 if (pctxt->nberrors != 0)
20954 goto exit_error;
Daniel Veillarddee23482008-04-11 12:58:43 +000020955 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000020956 * First compute the variety of simple types. This is needed as
20957 * a seperate step, since otherwise we won't be able to detect
20958 * circular union types in all cases.
20959 */
20960 for (i = 0; i < nbItems; i++) {
20961 item = items[i];
20962 switch (item->type) {
20963 case XML_SCHEMA_TYPE_SIMPLE:
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020964 if (WXS_IS_TYPE_NOT_FIXED_1((xmlSchemaTypePtr) item)) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000020965 xmlSchemaFixupSimpleTypeStageOne(pctxt,
20966 (xmlSchemaTypePtr) item);
20967 FIXHFAILURE;
20968 }
20969 break;
20970 default:
20971 break;
20972 }
20973 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020974 if (pctxt->nberrors != 0)
20975 goto exit_error;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000020976 /*
20977 * Detect circular union types. Note that this needs the variety to
20978 * be already computed.
20979 */
20980 for (i = 0; i < nbItems; i++) {
20981 item = items[i];
20982 switch (item->type) {
20983 case XML_SCHEMA_TYPE_SIMPLE:
20984 if (((xmlSchemaTypePtr) item)->memberTypes != NULL) {
Daniel Veillarddee23482008-04-11 12:58:43 +000020985 xmlSchemaCheckUnionTypeDefCircular(pctxt,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000020986 (xmlSchemaTypePtr) item);
20987 FIXHFAILURE;
20988 }
20989 break;
20990 default:
20991 break;
20992 }
20993 }
20994 if (pctxt->nberrors != 0)
20995 goto exit_error;
Daniel Veillarddee23482008-04-11 12:58:43 +000020996
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000020997 /*
20998 * Do the complete type fixup for simple types.
20999 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021000 for (i = 0; i < nbItems; i++) {
21001 item = items[i];
21002 switch (item->type) {
21003 case XML_SCHEMA_TYPE_SIMPLE:
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000021004 if (WXS_IS_TYPE_NOT_FIXED(WXS_TYPE_CAST item)) {
21005 xmlSchemaFixupSimpleTypeStageTwo(pctxt, WXS_TYPE_CAST item);
21006 FIXHFAILURE;
21007 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021008 break;
21009 default:
21010 break;
21011 }
21012 }
21013 if (pctxt->nberrors != 0)
21014 goto exit_error;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021015 /*
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000021016 * At this point we need build and check all simple types.
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000021017 */
21018 /*
21019 * Apply contraints for attribute declarations.
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021020 */
21021 for (i = 0; i < nbItems; i++) {
21022 item = items[i];
21023 switch (item->type) {
Daniel Veillarddee23482008-04-11 12:58:43 +000021024 case XML_SCHEMA_TYPE_ATTRIBUTE:
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000021025 xmlSchemaCheckAttrPropsCorrect(pctxt, WXS_ATTR_CAST item);
21026 FIXHFAILURE;
Daniel Veillarddee23482008-04-11 12:58:43 +000021027 break;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000021028 default:
21029 break;
21030 }
21031 }
21032 if (pctxt->nberrors != 0)
21033 goto exit_error;
21034 /*
21035 * Apply constraints for attribute uses.
Daniel Veillarddee23482008-04-11 12:58:43 +000021036 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000021037 for (i = 0; i < nbItems; i++) {
21038 item = items[i];
21039 switch (item->type) {
21040 case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
21041 if (((xmlSchemaAttributeUsePtr)item)->defValue != NULL) {
21042 xmlSchemaCheckAttrUsePropsCorrect(pctxt,
21043 WXS_ATTR_USE_CAST item);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021044 FIXHFAILURE;
21045 }
21046 break;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000021047 default:
21048 break;
21049 }
21050 }
21051 if (pctxt->nberrors != 0)
21052 goto exit_error;
21053
21054 /*
21055 * Apply constraints for attribute group definitions.
21056 */
21057 for (i = 0; i < nbItems; i++) {
21058 item = items[i];
21059 switch (item->type) {
21060 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
21061 if (( (WXS_ATTR_GROUP_CAST item)->attrUses != NULL) &&
21062 ( (WXS_LIST_CAST (WXS_ATTR_GROUP_CAST item)->attrUses)->nbItems > 1))
21063 {
21064 xmlSchemaCheckAGPropsCorrect(pctxt, WXS_ATTR_GROUP_CAST item);
21065 FIXHFAILURE;
21066 }
21067 break;
21068 default:
21069 break;
21070 }
21071 }
21072 if (pctxt->nberrors != 0)
21073 goto exit_error;
21074
21075 /*
21076 * Apply constraints for redefinitions.
21077 */
21078 if (WXS_CONSTRUCTOR(pctxt)->redefs != NULL)
21079 xmlSchemaCheckSRCRedefineSecond(pctxt);
21080 if (pctxt->nberrors != 0)
21081 goto exit_error;
21082
Daniel Veillarddee23482008-04-11 12:58:43 +000021083 /*
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000021084 * Complex types are builded and checked.
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000021085 */
21086 for (i = 0; i < nbItems; i++) {
21087 item = con->pending->items[i];
21088 switch (item->type) {
21089 case XML_SCHEMA_TYPE_COMPLEX:
21090 if (WXS_IS_TYPE_NOT_FIXED(WXS_TYPE_CAST item)) {
21091 xmlSchemaFixupComplexType(pctxt, WXS_TYPE_CAST item);
21092 FIXHFAILURE;
21093 }
21094 break;
21095 default:
21096 break;
21097 }
21098 }
21099 if (pctxt->nberrors != 0)
21100 goto exit_error;
21101
21102 /*
21103 * The list could have changed, since xmlSchemaFixupComplexType()
21104 * will create particles and model groups in some cases.
21105 */
21106 items = (xmlSchemaTreeItemPtr *) con->pending->items;
Daniel Veillarddee23482008-04-11 12:58:43 +000021107 nbItems = con->pending->nbItems;
21108
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000021109 /*
21110 * Apply some constraints for element declarations.
21111 */
21112 for (i = 0; i < nbItems; i++) {
21113 item = items[i];
21114 switch (item->type) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021115 case XML_SCHEMA_TYPE_ELEMENT:
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000021116 elemDecl = (xmlSchemaElementPtr) item;
Daniel Veillarddee23482008-04-11 12:58:43 +000021117
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000021118 if ((elemDecl->flags & XML_SCHEMAS_ELEM_INTERNAL_CHECKED) == 0)
21119 {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021120 xmlSchemaCheckElementDeclComponent(
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000021121 (xmlSchemaElementPtr) elemDecl, pctxt);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021122 FIXHFAILURE;
21123 }
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000021124
21125#ifdef WXS_ELEM_DECL_CONS_ENABLED
21126 /*
21127 * Schema Component Constraint: Element Declarations Consistent
21128 * Apply this constraint to local types of element declarations.
21129 */
21130 if ((WXS_ELEM_TYPEDEF(elemDecl) != NULL) &&
21131 (WXS_IS_COMPLEX(WXS_ELEM_TYPEDEF(elemDecl))) &&
21132 (WXS_TYPE_IS_LOCAL(WXS_ELEM_TYPEDEF(elemDecl))))
21133 {
21134 xmlSchemaCheckElementDeclConsistent(pctxt,
21135 WXS_BASIC_CAST elemDecl,
21136 WXS_TYPE_PARTICLE(WXS_ELEM_TYPEDEF(elemDecl)),
21137 NULL, NULL, 0);
21138 }
21139#endif
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021140 break;
21141 default:
21142 break;
21143 }
21144 }
21145 if (pctxt->nberrors != 0)
21146 goto exit_error;
Daniel Veillarddee23482008-04-11 12:58:43 +000021147
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021148 /*
21149 * Finally we can build the automaton from the content model of
21150 * complex types.
21151 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000021152
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021153 for (i = 0; i < nbItems; i++) {
21154 item = items[i];
21155 switch (item->type) {
21156 case XML_SCHEMA_TYPE_COMPLEX:
21157 xmlSchemaBuildContentModel((xmlSchemaTypePtr) item, pctxt);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000021158 /* FIXHFAILURE; */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021159 break;
21160 default:
21161 break;
21162 }
21163 }
21164 if (pctxt->nberrors != 0)
21165 goto exit_error;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021166 /*
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000021167 * URGENT TODO: cos-element-consistent
Daniel Veillarddee23482008-04-11 12:58:43 +000021168 */
21169 goto exit;
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000021170
Daniel Veillarddee23482008-04-11 12:58:43 +000021171exit_error:
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000021172 ret = pctxt->err;
Kasimier T. Buchcik4c0aa162006-02-20 14:47:08 +000021173 goto exit;
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000021174
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021175exit_failure:
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000021176 ret = -1;
21177
21178exit:
21179 /*
21180 * Reset the constructor. This is needed for XSI acquisition, since
21181 * those items will be processed over and over again for every XSI
21182 * if not cleared here.
21183 */
Kasimier T. Buchcik4c0aa162006-02-20 14:47:08 +000021184 con->bucket = oldbucket;
Daniel Veillarddee23482008-04-11 12:58:43 +000021185 con->pending->nbItems = 0;
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000021186 if (con->substGroups != NULL) {
21187 xmlHashFree(con->substGroups,
21188 (xmlHashDeallocator) xmlSchemaSubstGroupFree);
21189 con->substGroups = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000021190 }
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000021191 if (con->redefs != NULL) {
21192 xmlSchemaRedefListFree(con->redefs);
21193 con->redefs = NULL;
21194 }
21195 return(ret);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021196}
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000021197/**
Daniel Veillard4255d502002-04-16 15:50:10 +000021198 * xmlSchemaParse:
21199 * @ctxt: a schema validation context
Daniel Veillard4255d502002-04-16 15:50:10 +000021200 *
Daniel Veillard01c13b52002-12-10 15:19:08 +000021201 * parse a schema definition resource and build an internal
Daniel Veillard4255d502002-04-16 15:50:10 +000021202 * XML Shema struture which can be used to validate instances.
Daniel Veillard4255d502002-04-16 15:50:10 +000021203 *
21204 * Returns the internal XML Schema structure built from the resource or
21205 * NULL in case of error
21206 */
21207xmlSchemaPtr
21208xmlSchemaParse(xmlSchemaParserCtxtPtr ctxt)
21209{
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000021210 xmlSchemaPtr mainSchema = NULL;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021211 xmlSchemaBucketPtr bucket = NULL;
21212 int res;
Daniel Veillard4255d502002-04-16 15:50:10 +000021213
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000021214 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021215 * This one is used if the schema to be parsed was specified via
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000021216 * the API; i.e. not automatically by the validated instance document.
21217 */
21218
Daniel Veillard4255d502002-04-16 15:50:10 +000021219 xmlSchemaInitTypes();
21220
Daniel Veillard6045c902002-10-09 21:13:59 +000021221 if (ctxt == NULL)
Daniel Veillard4255d502002-04-16 15:50:10 +000021222 return (NULL);
21223
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021224 /* TODO: Init the context. Is this all we need?*/
Daniel Veillard75bb3bb2003-05-12 15:25:56 +000021225 ctxt->nberrors = 0;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021226 ctxt->err = 0;
Daniel Veillard4255d502002-04-16 15:50:10 +000021227 ctxt->counter = 0;
Daniel Veillard4255d502002-04-16 15:50:10 +000021228
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021229 /* Create the *main* schema. */
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000021230 mainSchema = xmlSchemaNewSchema(ctxt);
21231 if (mainSchema == NULL)
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021232 goto exit_failure;
Daniel Veillard4255d502002-04-16 15:50:10 +000021233 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021234 * Create the schema constructor.
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000021235 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021236 if (ctxt->constructor == NULL) {
21237 ctxt->constructor = xmlSchemaConstructionCtxtCreate(ctxt->dict);
21238 if (ctxt->constructor == NULL)
21239 return(NULL);
21240 /* Take ownership of the constructor to be able to free it. */
21241 ctxt->ownsConstructor = 1;
21242 }
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000021243 ctxt->constructor->mainSchema = mainSchema;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021244 /*
21245 * Locate and add the schema document.
21246 */
21247 res = xmlSchemaAddSchemaDoc(ctxt, XML_SCHEMA_SCHEMA_MAIN,
21248 ctxt->URL, ctxt->doc, ctxt->buffer, ctxt->size, NULL,
21249 NULL, NULL, &bucket);
21250 if (res == -1)
21251 goto exit_failure;
21252 if (res != 0)
Daniel Veillarddee23482008-04-11 12:58:43 +000021253 goto exit;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021254
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021255 if (bucket == NULL) {
21256 /* TODO: Error code, actually we failed to *locate* the schema. */
Daniel Veillarddee23482008-04-11 12:58:43 +000021257 if (ctxt->URL)
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021258 xmlSchemaCustomErr(ACTXT_CAST ctxt, XML_SCHEMAP_FAILED_LOAD,
21259 NULL, NULL,
21260 "Failed to locate the main schema resource at '%s'",
21261 ctxt->URL, NULL);
21262 else
21263 xmlSchemaCustomErr(ACTXT_CAST ctxt, XML_SCHEMAP_FAILED_LOAD,
21264 NULL, NULL,
21265 "Failed to locate the main schema resource",
21266 NULL, NULL);
21267 goto exit;
Daniel Veillarddee23482008-04-11 12:58:43 +000021268 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021269 /* Then do the parsing for good. */
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000021270 if (xmlSchemaParseNewDocWithContext(ctxt, mainSchema, bucket) == -1)
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021271 goto exit_failure;
Kasimier T. Buchcik1a99a392005-04-08 11:23:56 +000021272 if (ctxt->nberrors != 0)
21273 goto exit;
Daniel Veillarddee23482008-04-11 12:58:43 +000021274
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000021275 mainSchema->doc = bucket->doc;
21276 mainSchema->preserve = ctxt->preserve;
Daniel Veillarddee23482008-04-11 12:58:43 +000021277
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000021278 ctxt->schema = mainSchema;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000021279
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000021280 if (xmlSchemaFixupComponents(ctxt, WXS_CONSTRUCTOR(ctxt)->mainBucket) == -1)
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021281 goto exit_failure;
21282
21283 /*
21284 * TODO: This is not nice, since we cannot distinguish from the
21285 * result if there was an internal error or not.
21286 */
Daniel Veillarddee23482008-04-11 12:58:43 +000021287exit:
21288 if (ctxt->nberrors != 0) {
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000021289 if (mainSchema) {
21290 xmlSchemaFree(mainSchema);
21291 mainSchema = NULL;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021292 }
21293 if (ctxt->constructor) {
21294 xmlSchemaConstructionCtxtFree(ctxt->constructor);
21295 ctxt->constructor = NULL;
21296 ctxt->ownsConstructor = 0;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000021297 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021298 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021299 ctxt->schema = NULL;
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000021300 return(mainSchema);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021301exit_failure:
Daniel Veillarddee23482008-04-11 12:58:43 +000021302 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021303 * Quite verbose, but should catch internal errors, which were
21304 * not communitated.
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000021305 */
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000021306 if (mainSchema) {
21307 xmlSchemaFree(mainSchema);
21308 mainSchema = NULL;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021309 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021310 if (ctxt->constructor) {
21311 xmlSchemaConstructionCtxtFree(ctxt->constructor);
21312 ctxt->constructor = NULL;
21313 ctxt->ownsConstructor = 0;
Daniel Veillard75bb3bb2003-05-12 15:25:56 +000021314 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021315 PERROR_INT2("xmlSchemaParse",
Daniel Veillarddee23482008-04-11 12:58:43 +000021316 "An internal error occured");
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021317 ctxt->schema = NULL;
21318 return(NULL);
Daniel Veillard4255d502002-04-16 15:50:10 +000021319}
Daniel Veillardd0c9c322003-10-10 00:49:42 +000021320
Daniel Veillard4255d502002-04-16 15:50:10 +000021321/**
Daniel Veillard01c13b52002-12-10 15:19:08 +000021322 * xmlSchemaSetParserErrors:
Daniel Veillard4255d502002-04-16 15:50:10 +000021323 * @ctxt: a schema validation context
Daniel Veillard01c13b52002-12-10 15:19:08 +000021324 * @err: the error callback
21325 * @warn: the warning callback
21326 * @ctx: contextual data for the callbacks
Daniel Veillard4255d502002-04-16 15:50:10 +000021327 *
Daniel Veillard01c13b52002-12-10 15:19:08 +000021328 * Set the callback functions used to handle errors for a validation context
Daniel Veillard4255d502002-04-16 15:50:10 +000021329 */
21330void
21331xmlSchemaSetParserErrors(xmlSchemaParserCtxtPtr ctxt,
Daniel Veillardd0c9c322003-10-10 00:49:42 +000021332 xmlSchemaValidityErrorFunc err,
21333 xmlSchemaValidityWarningFunc warn, void *ctx)
21334{
Daniel Veillard4255d502002-04-16 15:50:10 +000021335 if (ctxt == NULL)
Daniel Veillardd0c9c322003-10-10 00:49:42 +000021336 return;
Daniel Veillard4255d502002-04-16 15:50:10 +000021337 ctxt->error = err;
21338 ctxt->warning = warn;
Kasimier T. Buchcik90b5ebc2005-11-18 17:18:27 +000021339 ctxt->errCtxt = ctx;
21340 if (ctxt->vctxt != NULL)
21341 xmlSchemaSetValidErrors(ctxt->vctxt, err, warn, ctx);
21342}
21343
21344/**
21345 * xmlSchemaSetParserStructuredErrors:
21346 * @ctxt: a schema parser context
21347 * @serror: the structured error function
21348 * @ctx: the functions context
21349 *
21350 * Set the structured error callback
21351 */
21352void
21353xmlSchemaSetParserStructuredErrors(xmlSchemaParserCtxtPtr ctxt,
21354 xmlStructuredErrorFunc serror,
21355 void *ctx)
21356{
21357 if (ctxt == NULL)
21358 return;
21359 ctxt->serror = serror;
21360 ctxt->errCtxt = ctx;
21361 if (ctxt->vctxt != NULL)
21362 xmlSchemaSetValidStructuredErrors(ctxt->vctxt, serror, ctx);
Daniel Veillard4255d502002-04-16 15:50:10 +000021363}
21364
Daniel Veillardd3b9cd82003-04-09 11:24:17 +000021365/**
Daniel Veillard259f0df2004-08-18 09:13:18 +000021366 * xmlSchemaGetParserErrors:
21367 * @ctxt: a XMl-Schema parser context
21368 * @err: the error callback result
21369 * @warn: the warning callback result
21370 * @ctx: contextual data for the callbacks result
21371 *
21372 * Get the callback information used to handle errors for a parser context
21373 *
21374 * Returns -1 in case of failure, 0 otherwise
21375 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021376int
Daniel Veillard259f0df2004-08-18 09:13:18 +000021377xmlSchemaGetParserErrors(xmlSchemaParserCtxtPtr ctxt,
Kasimier T. Buchcik90b5ebc2005-11-18 17:18:27 +000021378 xmlSchemaValidityErrorFunc * err,
21379 xmlSchemaValidityWarningFunc * warn, void **ctx)
Daniel Veillard259f0df2004-08-18 09:13:18 +000021380{
21381 if (ctxt == NULL)
21382 return(-1);
21383 if (err != NULL)
21384 *err = ctxt->error;
21385 if (warn != NULL)
21386 *warn = ctxt->warning;
21387 if (ctx != NULL)
Kasimier T. Buchcik90b5ebc2005-11-18 17:18:27 +000021388 *ctx = ctxt->errCtxt;
Daniel Veillard259f0df2004-08-18 09:13:18 +000021389 return(0);
21390}
21391
21392/**
Daniel Veillardd3b9cd82003-04-09 11:24:17 +000021393 * xmlSchemaFacetTypeToString:
21394 * @type: the facet type
21395 *
21396 * Convert the xmlSchemaTypeType to a char string.
21397 *
21398 * Returns the char string representation of the facet type if the
21399 * type is a facet and an "Internal Error" string otherwise.
21400 */
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +000021401static const xmlChar *
Daniel Veillardd3b9cd82003-04-09 11:24:17 +000021402xmlSchemaFacetTypeToString(xmlSchemaTypeType type)
21403{
21404 switch (type) {
21405 case XML_SCHEMA_FACET_PATTERN:
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +000021406 return (BAD_CAST "pattern");
Daniel Veillardd0c9c322003-10-10 00:49:42 +000021407 case XML_SCHEMA_FACET_MAXEXCLUSIVE:
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +000021408 return (BAD_CAST "maxExclusive");
Daniel Veillardd0c9c322003-10-10 00:49:42 +000021409 case XML_SCHEMA_FACET_MAXINCLUSIVE:
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +000021410 return (BAD_CAST "maxInclusive");
Daniel Veillardd0c9c322003-10-10 00:49:42 +000021411 case XML_SCHEMA_FACET_MINEXCLUSIVE:
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +000021412 return (BAD_CAST "minExclusive");
Daniel Veillardd0c9c322003-10-10 00:49:42 +000021413 case XML_SCHEMA_FACET_MININCLUSIVE:
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +000021414 return (BAD_CAST "minInclusive");
Daniel Veillardd0c9c322003-10-10 00:49:42 +000021415 case XML_SCHEMA_FACET_WHITESPACE:
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +000021416 return (BAD_CAST "whiteSpace");
Daniel Veillardd0c9c322003-10-10 00:49:42 +000021417 case XML_SCHEMA_FACET_ENUMERATION:
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +000021418 return (BAD_CAST "enumeration");
Daniel Veillardd0c9c322003-10-10 00:49:42 +000021419 case XML_SCHEMA_FACET_LENGTH:
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +000021420 return (BAD_CAST "length");
Daniel Veillardd0c9c322003-10-10 00:49:42 +000021421 case XML_SCHEMA_FACET_MAXLENGTH:
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +000021422 return (BAD_CAST "maxLength");
Daniel Veillardd0c9c322003-10-10 00:49:42 +000021423 case XML_SCHEMA_FACET_MINLENGTH:
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +000021424 return (BAD_CAST "minLength");
Daniel Veillardd0c9c322003-10-10 00:49:42 +000021425 case XML_SCHEMA_FACET_TOTALDIGITS:
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +000021426 return (BAD_CAST "totalDigits");
Daniel Veillardd0c9c322003-10-10 00:49:42 +000021427 case XML_SCHEMA_FACET_FRACTIONDIGITS:
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +000021428 return (BAD_CAST "fractionDigits");
Daniel Veillardd3b9cd82003-04-09 11:24:17 +000021429 default:
21430 break;
21431 }
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +000021432 return (BAD_CAST "Internal Error");
Daniel Veillardd3b9cd82003-04-09 11:24:17 +000021433}
21434
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021435static xmlSchemaWhitespaceValueType
Daniel Veillardc0826a72004-08-10 14:17:33 +000021436xmlSchemaGetWhiteSpaceFacetValue(xmlSchemaTypePtr type)
21437{
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021438 /*
21439 * The normalization type can be changed only for types which are derived
Daniel Veillardc0826a72004-08-10 14:17:33 +000021440 * from xsd:string.
21441 */
21442 if (type->type == XML_SCHEMA_TYPE_BASIC) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021443 /*
21444 * Note that we assume a whitespace of preserve for anySimpleType.
21445 */
21446 if ((type->builtInType == XML_SCHEMAS_STRING) ||
21447 (type->builtInType == XML_SCHEMAS_ANYSIMPLETYPE))
21448 return(XML_SCHEMA_WHITESPACE_PRESERVE);
Kasimier T. Buchcik91feaf82004-11-12 14:04:58 +000021449 else if (type->builtInType == XML_SCHEMAS_NORMSTRING)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021450 return(XML_SCHEMA_WHITESPACE_REPLACE);
Daniel Veillardc0826a72004-08-10 14:17:33 +000021451 else {
21452 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000021453 * For all �atomic� datatypes other than string (and types �derived�
21454 * by �restriction� from it) the value of whiteSpace is fixed to
Daniel Veillardc0826a72004-08-10 14:17:33 +000021455 * collapse
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021456 * Note that this includes built-in list datatypes.
Daniel Veillardc0826a72004-08-10 14:17:33 +000021457 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021458 return(XML_SCHEMA_WHITESPACE_COLLAPSE);
Daniel Veillardc0826a72004-08-10 14:17:33 +000021459 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000021460 } else if (WXS_IS_LIST(type)) {
Kasimier T. Buchcik478d6932005-03-16 16:29:18 +000021461 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021462 * For list types the facet "whiteSpace" is fixed to "collapse".
Kasimier T. Buchcik478d6932005-03-16 16:29:18 +000021463 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021464 return (XML_SCHEMA_WHITESPACE_COLLAPSE);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000021465 } else if (WXS_IS_UNION(type)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021466 return (XML_SCHEMA_WHITESPACE_UNKNOWN);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000021467 } else if (WXS_IS_ATOMIC(type)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021468 if (type->flags & XML_SCHEMAS_TYPE_WHITESPACE_PRESERVE)
21469 return (XML_SCHEMA_WHITESPACE_PRESERVE);
21470 else if (type->flags & XML_SCHEMAS_TYPE_WHITESPACE_REPLACE)
21471 return (XML_SCHEMA_WHITESPACE_REPLACE);
21472 else
21473 return (XML_SCHEMA_WHITESPACE_COLLAPSE);
Kasimier T. Buchcik478d6932005-03-16 16:29:18 +000021474 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021475 return (-1);
Daniel Veillardd3b9cd82003-04-09 11:24:17 +000021476}
21477
Daniel Veillard4255d502002-04-16 15:50:10 +000021478/************************************************************************
21479 * *
21480 * Simple type validation *
21481 * *
21482 ************************************************************************/
Daniel Veillard377e1a92004-04-16 16:30:05 +000021483
Daniel Veillard4255d502002-04-16 15:50:10 +000021484
21485/************************************************************************
21486 * *
21487 * DOM Validation code *
21488 * *
21489 ************************************************************************/
21490
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000021491/**
21492 * xmlSchemaAssembleByLocation:
21493 * @pctxt: a schema parser context
21494 * @vctxt: a schema validation context
21495 * @schema: the existing schema
21496 * @node: the node that fired the assembling
21497 * @nsName: the namespace name of the new schema
21498 * @location: the location of the schema
21499 *
21500 * Expands an existing schema by an additional schema.
21501 *
21502 * Returns 0 if the new schema is correct, a positive error code
21503 * number otherwise and -1 in case of an internal or API error.
21504 */
21505static int
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021506xmlSchemaAssembleByLocation(xmlSchemaValidCtxtPtr vctxt,
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000021507 xmlSchemaPtr schema,
21508 xmlNodePtr node,
21509 const xmlChar *nsName,
21510 const xmlChar *location)
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000021511{
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021512 int ret = 0;
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000021513 xmlSchemaParserCtxtPtr pctxt;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021514 xmlSchemaBucketPtr bucket = NULL;
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000021515
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000021516 if ((vctxt == NULL) || (schema == NULL))
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000021517 return (-1);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021518
21519 if (vctxt->pctxt == NULL) {
21520 VERROR_INT("xmlSchemaAssembleByLocation",
21521 "no parser context available");
21522 return(-1);
21523 }
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000021524 pctxt = vctxt->pctxt;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021525 if (pctxt->constructor == NULL) {
21526 PERROR_INT("xmlSchemaAssembleByLocation",
21527 "no constructor");
21528 return(-1);
21529 }
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000021530 /*
21531 * Acquire the schema document.
21532 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021533 location = xmlSchemaBuildAbsoluteURI(pctxt->dict,
21534 location, node);
21535 /*
21536 * Note that we pass XML_SCHEMA_SCHEMA_IMPORT here;
21537 * the process will automatically change this to
21538 * XML_SCHEMA_SCHEMA_MAIN if it is the first schema document.
21539 */
21540 ret = xmlSchemaAddSchemaDoc(pctxt, XML_SCHEMA_SCHEMA_IMPORT,
Daniel Veillarddee23482008-04-11 12:58:43 +000021541 location, NULL, NULL, 0, node, NULL, nsName,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021542 &bucket);
21543 if (ret != 0)
Daniel Veillarddee23482008-04-11 12:58:43 +000021544 return(ret);
21545 if (bucket == NULL) {
Kasimier T. Buchcike5f810f2006-05-30 09:41:25 +000021546 /*
21547 * Generate a warning that the document could not be located.
21548 */
21549 xmlSchemaCustomWarning(ACTXT_CAST vctxt, XML_SCHEMAV_MISC,
21550 node, NULL,
21551 "The document at location '%s' could not be acquired",
21552 location, NULL, NULL);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021553 return(ret);
Kasimier T. Buchcike5f810f2006-05-30 09:41:25 +000021554 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021555 /*
21556 * The first located schema will be handled as if all other
21557 * schemas imported by XSI were imported by this first schema.
21558 */
21559 if ((bucket != NULL) &&
21560 (WXS_CONSTRUCTOR(pctxt)->bucket == NULL))
21561 WXS_CONSTRUCTOR(pctxt)->bucket = bucket;
21562 /*
21563 * TODO: Is this handled like an import? I.e. is it not an error
21564 * if the schema cannot be located?
21565 */
21566 if ((bucket == NULL) || (! CAN_PARSE_SCHEMA(bucket)))
21567 return(0);
21568 /*
21569 * We will reuse the parser context for every schema imported
21570 * directly via XSI. So reset the context.
21571 */
21572 pctxt->nberrors = 0;
21573 pctxt->err = 0;
21574 pctxt->doc = bucket->doc;
Daniel Veillarddee23482008-04-11 12:58:43 +000021575
21576 ret = xmlSchemaParseNewDocWithContext(pctxt, schema, bucket);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021577 if (ret == -1) {
21578 pctxt->doc = NULL;
21579 goto exit_failure;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021580 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021581 /* Paranoid error channelling. */
21582 if ((ret == 0) && (pctxt->nberrors != 0))
Daniel Veillarddee23482008-04-11 12:58:43 +000021583 ret = pctxt->err;
21584 if (pctxt->nberrors == 0) {
21585 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021586 * Only bother to fixup pending components, if there was
21587 * no error yet.
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000021588 * For every XSI acquired schema (and its sub-schemata) we will
21589 * fixup the components.
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021590 */
Kasimier T. Buchcik1869be52006-02-20 13:37:55 +000021591 xmlSchemaFixupComponents(pctxt, bucket);
Kasimier T. Buchcik215406f2005-12-07 12:14:09 +000021592 ret = pctxt->err;
21593 /*
21594 * Not nice, but we need somehow to channel the schema parser
21595 * error to the validation context.
21596 */
21597 if ((ret != 0) && (vctxt->err == 0))
21598 vctxt->err = ret;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021599 vctxt->nberrors += pctxt->nberrors;
21600 } else {
Daniel Veillarddee23482008-04-11 12:58:43 +000021601 /* Add to validation error sum. */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021602 vctxt->nberrors += pctxt->nberrors;
21603 }
21604 pctxt->doc = NULL;
21605 return(ret);
21606exit_failure:
21607 pctxt->doc = NULL;
21608 return (-1);
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000021609}
21610
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021611static xmlSchemaAttrInfoPtr
Daniel Veillarddee23482008-04-11 12:58:43 +000021612xmlSchemaGetMetaAttrInfo(xmlSchemaValidCtxtPtr vctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021613 int metaType)
21614{
21615 if (vctxt->nbAttrInfos == 0)
21616 return (NULL);
21617 {
21618 int i;
21619 xmlSchemaAttrInfoPtr iattr;
21620
21621 for (i = 0; i < vctxt->nbAttrInfos; i++) {
21622 iattr = vctxt->attrInfos[i];
21623 if (iattr->metaType == metaType)
21624 return (iattr);
21625 }
21626
21627 }
21628 return (NULL);
21629}
21630
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000021631/**
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021632 * xmlSchemaAssembleByXSI:
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000021633 * @vctxt: a schema validation context
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000021634 *
21635 * Expands an existing schema by an additional schema using
21636 * the xsi:schemaLocation or xsi:noNamespaceSchemaLocation attribute
21637 * of an instance. If xsi:noNamespaceSchemaLocation is used, @noNamespace
21638 * must be set to 1.
21639 *
21640 * Returns 0 if the new schema is correct, a positive error code
21641 * number otherwise and -1 in case of an internal or API error.
21642 */
21643static int
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021644xmlSchemaAssembleByXSI(xmlSchemaValidCtxtPtr vctxt)
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000021645{
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000021646 const xmlChar *cur, *end;
21647 const xmlChar *nsname = NULL, *location;
21648 int count = 0;
21649 int ret = 0;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021650 xmlSchemaAttrInfoPtr iattr;
21651
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000021652 /*
21653 * Parse the value; we will assume an even number of values
21654 * to be given (this is how Xerces and XSV work).
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000021655 *
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000021656 * URGENT TODO: !! This needs to work for both
21657 * @noNamespaceSchemaLocation AND @schemaLocation on the same
21658 * element !!
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000021659 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021660 iattr = xmlSchemaGetMetaAttrInfo(vctxt,
21661 XML_SCHEMA_ATTR_INFO_META_XSI_SCHEMA_LOC);
21662 if (iattr == NULL)
Kasimier T. Buchcik81755ea2005-11-23 16:39:27 +000021663 iattr = xmlSchemaGetMetaAttrInfo(vctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021664 XML_SCHEMA_ATTR_INFO_META_XSI_NO_NS_SCHEMA_LOC);
21665 if (iattr == NULL)
21666 return (0);
21667 cur = iattr->value;
21668 do {
Kasimier T. Buchcike5f810f2006-05-30 09:41:25 +000021669 /*
21670 * TODO: Move the string parsing mechanism away from here.
21671 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021672 if (iattr->metaType == XML_SCHEMA_ATTR_INFO_META_XSI_SCHEMA_LOC) {
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000021673 /*
21674 * Get the namespace name.
21675 */
21676 while (IS_BLANK_CH(*cur))
21677 cur++;
21678 end = cur;
21679 while ((*end != 0) && (!(IS_BLANK_CH(*end))))
21680 end++;
21681 if (end == cur)
21682 break;
Kasimier T. Buchcike5f810f2006-05-30 09:41:25 +000021683 count++; /* TODO: Don't use the schema's dict. */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021684 nsname = xmlDictLookup(vctxt->schema->dict, cur, end - cur);
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000021685 cur = end;
21686 }
21687 /*
21688 * Get the URI.
21689 */
21690 while (IS_BLANK_CH(*cur))
21691 cur++;
21692 end = cur;
21693 while ((*end != 0) && (!(IS_BLANK_CH(*end))))
21694 end++;
Kasimier T. Buchcike5f810f2006-05-30 09:41:25 +000021695 if (end == cur) {
21696 if (iattr->metaType ==
21697 XML_SCHEMA_ATTR_INFO_META_XSI_SCHEMA_LOC)
21698 {
21699 /*
21700 * If using @schemaLocation then tuples are expected.
21701 * I.e. the namespace name *and* the document's URI.
Daniel Veillarddee23482008-04-11 12:58:43 +000021702 */
Kasimier T. Buchcike5f810f2006-05-30 09:41:25 +000021703 xmlSchemaCustomWarning(ACTXT_CAST vctxt, XML_SCHEMAV_MISC,
21704 iattr->node, NULL,
21705 "The value must consist of tuples: the target namespace "
21706 "name and the document's URI", NULL, NULL, NULL);
21707 }
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000021708 break;
Kasimier T. Buchcike5f810f2006-05-30 09:41:25 +000021709 }
21710 count++; /* TODO: Don't use the schema's dict. */
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000021711 location = xmlDictLookup(vctxt->schema->dict, cur, end - cur);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021712 cur = end;
21713 ret = xmlSchemaAssembleByLocation(vctxt, vctxt->schema,
21714 iattr->node, nsname, location);
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000021715 if (ret == -1) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021716 VERROR_INT("xmlSchemaAssembleByXSI",
21717 "assembling schemata");
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000021718 return (-1);
21719 }
21720 } while (*cur != 0);
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000021721 return (ret);
21722}
21723
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021724static const xmlChar *
21725xmlSchemaLookupNamespace(xmlSchemaValidCtxtPtr vctxt,
21726 const xmlChar *prefix)
21727{
21728 if (vctxt->sax != NULL) {
21729 int i, j;
21730 xmlSchemaNodeInfoPtr inode;
Daniel Veillarddee23482008-04-11 12:58:43 +000021731
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021732 for (i = vctxt->depth; i >= 0; i--) {
21733 if (vctxt->elemInfos[i]->nbNsBindings != 0) {
21734 inode = vctxt->elemInfos[i];
21735 for (j = 0; j < inode->nbNsBindings * 2; j += 2) {
21736 if (((prefix == NULL) &&
21737 (inode->nsBindings[j] == NULL)) ||
21738 ((prefix != NULL) && xmlStrEqual(prefix,
21739 inode->nsBindings[j]))) {
21740
21741 /*
21742 * Note that the namespace bindings are already
21743 * in a string dict.
21744 */
Daniel Veillarddee23482008-04-11 12:58:43 +000021745 return (inode->nsBindings[j+1]);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021746 }
21747 }
21748 }
21749 }
21750 return (NULL);
Daniel Veillard438ebbd2008-05-12 12:58:46 +000021751#ifdef LIBXML_READER_ENABLED
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021752 } else if (vctxt->reader != NULL) {
21753 xmlChar *nsName;
Daniel Veillarddee23482008-04-11 12:58:43 +000021754
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021755 nsName = xmlTextReaderLookupNamespace(vctxt->reader, prefix);
21756 if (nsName != NULL) {
21757 const xmlChar *ret;
21758
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021759 ret = xmlDictLookup(vctxt->dict, nsName, -1);
21760 xmlFree(nsName);
21761 return (ret);
21762 } else
21763 return (NULL);
Daniel Veillard39e5c892005-07-03 22:48:50 +000021764#endif
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021765 } else {
21766 xmlNsPtr ns;
21767
21768 if ((vctxt->inode->node == NULL) ||
21769 (vctxt->inode->node->doc == NULL)) {
21770 VERROR_INT("xmlSchemaLookupNamespace",
21771 "no node or node's doc avaliable");
21772 return (NULL);
21773 }
21774 ns = xmlSearchNs(vctxt->inode->node->doc,
21775 vctxt->inode->node, prefix);
21776 if (ns != NULL)
21777 return (ns->href);
21778 return (NULL);
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000021779 }
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000021780}
21781
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021782/*
21783* This one works on the schema of the validation context.
21784*/
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +000021785static int
Daniel Veillarddee23482008-04-11 12:58:43 +000021786xmlSchemaValidateNotation(xmlSchemaValidCtxtPtr vctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021787 xmlSchemaPtr schema,
21788 xmlNodePtr node,
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +000021789 const xmlChar *value,
21790 xmlSchemaValPtr *val,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021791 int valNeeded)
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +000021792{
21793 int ret;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021794
21795 if (vctxt && (vctxt->schema == NULL)) {
21796 VERROR_INT("xmlSchemaValidateNotation",
21797 "a schema is needed on the validation context");
21798 return (-1);
21799 }
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +000021800 ret = xmlValidateQName(value, 1);
21801 if (ret != 0)
21802 return (ret);
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +000021803 {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021804 xmlChar *localName = NULL;
21805 xmlChar *prefix = NULL;
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +000021806
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021807 localName = xmlSplitQName2(value, &prefix);
21808 if (prefix != NULL) {
21809 const xmlChar *nsName = NULL;
21810
Daniel Veillarddee23482008-04-11 12:58:43 +000021811 if (vctxt != NULL)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021812 nsName = xmlSchemaLookupNamespace(vctxt, BAD_CAST prefix);
21813 else if (node != NULL) {
21814 xmlNsPtr ns = xmlSearchNs(node->doc, node, prefix);
21815 if (ns != NULL)
21816 nsName = ns->href;
21817 } else {
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +000021818 xmlFree(prefix);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021819 xmlFree(localName);
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +000021820 return (1);
21821 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021822 if (nsName == NULL) {
21823 xmlFree(prefix);
21824 xmlFree(localName);
21825 return (1);
21826 }
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021827 if (xmlSchemaGetNotation(schema, localName, nsName) != NULL) {
Daniel Veillard77fbc3e2008-03-24 14:06:19 +000021828 if ((valNeeded) && (val != NULL)) {
21829 (*val) = xmlSchemaNewNOTATIONValue(xmlStrdup(localName),
21830 xmlStrdup(nsName));
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021831 if (*val == NULL)
21832 ret = -1;
21833 }
21834 } else
Kasimier T. Buchcikb06b4de2005-02-17 19:00:23 +000021835 ret = 1;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021836 xmlFree(prefix);
21837 xmlFree(localName);
21838 } else {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000021839 if (xmlSchemaGetNotation(schema, value, NULL) != NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021840 if (valNeeded && (val != NULL)) {
21841 (*val) = xmlSchemaNewNOTATIONValue(
21842 BAD_CAST xmlStrdup(value), NULL);
21843 if (*val == NULL)
21844 ret = -1;
21845 }
21846 } else
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000021847 return (1);
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000021848 }
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000021849 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021850 return (ret);
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000021851}
21852
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000021853static int
21854xmlSchemaVAddNodeQName(xmlSchemaValidCtxtPtr vctxt,
21855 const xmlChar* lname,
21856 const xmlChar* nsname)
21857{
21858 int i;
21859
21860 lname = xmlDictLookup(vctxt->dict, lname, -1);
21861 if (lname == NULL)
21862 return(-1);
21863 if (nsname != NULL) {
21864 nsname = xmlDictLookup(vctxt->dict, nsname, -1);
21865 if (nsname == NULL)
21866 return(-1);
21867 }
21868 for (i = 0; i < vctxt->nodeQNames->nbItems; i += 2) {
21869 if ((vctxt->nodeQNames->items [i] == lname) &&
21870 (vctxt->nodeQNames->items[i +1] == nsname))
21871 /* Already there */
21872 return(i);
21873 }
21874 /* Add new entry. */
21875 i = vctxt->nodeQNames->nbItems;
21876 xmlSchemaItemListAdd(vctxt->nodeQNames, (void *) lname);
21877 xmlSchemaItemListAdd(vctxt->nodeQNames, (void *) nsname);
21878 return(i);
21879}
21880
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000021881/************************************************************************
21882 * *
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021883 * Validation of identity-constraints (IDC) *
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000021884 * *
21885 ************************************************************************/
21886
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000021887/**
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000021888 * xmlSchemaAugmentIDC:
21889 * @idcDef: the IDC definition
21890 *
21891 * Creates an augmented IDC definition item.
21892 *
21893 * Returns the item, or NULL on internal errors.
21894 */
21895static void
21896xmlSchemaAugmentIDC(xmlSchemaIDCPtr idcDef,
21897 xmlSchemaValidCtxtPtr vctxt)
21898{
21899 xmlSchemaIDCAugPtr aidc;
21900
21901 aidc = (xmlSchemaIDCAugPtr) xmlMalloc(sizeof(xmlSchemaIDCAug));
21902 if (aidc == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021903 xmlSchemaVErrMemory(vctxt,
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000021904 "xmlSchemaAugmentIDC: allocating an augmented IDC definition",
21905 NULL);
21906 return;
21907 }
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000021908 aidc->keyrefDepth = -1;
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000021909 aidc->def = idcDef;
21910 aidc->next = NULL;
21911 if (vctxt->aidcs == NULL)
21912 vctxt->aidcs = aidc;
21913 else {
21914 aidc->next = vctxt->aidcs;
21915 vctxt->aidcs = aidc;
21916 }
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000021917 /*
21918 * Save if we have keyrefs at all.
21919 */
21920 if ((vctxt->hasKeyrefs == 0) &&
21921 (idcDef->type == XML_SCHEMA_TYPE_IDC_KEYREF))
21922 vctxt->hasKeyrefs = 1;
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000021923}
21924
21925/**
Daniel Veillard3888f472007-08-23 09:29:03 +000021926 * xmlSchemaAugmentImportedIDC:
21927 * @imported: the imported schema
21928 *
21929 * Creates an augmented IDC definition for the imported schema.
21930 */
21931static void
21932xmlSchemaAugmentImportedIDC(xmlSchemaImportPtr imported, xmlSchemaValidCtxtPtr vctxt) {
21933 if (imported->schema->idcDef != NULL) {
21934 xmlHashScan(imported->schema->idcDef ,
21935 (xmlHashScanner) xmlSchemaAugmentIDC, vctxt);
21936 }
21937}
21938
21939/**
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000021940 * xmlSchemaIDCNewBinding:
21941 * @idcDef: the IDC definition of this binding
21942 *
21943 * Creates a new IDC binding.
21944 *
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000021945 * Returns the new IDC binding, NULL on internal errors.
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000021946 */
21947static xmlSchemaPSVIIDCBindingPtr
21948xmlSchemaIDCNewBinding(xmlSchemaIDCPtr idcDef)
21949{
21950 xmlSchemaPSVIIDCBindingPtr ret;
21951
21952 ret = (xmlSchemaPSVIIDCBindingPtr) xmlMalloc(
21953 sizeof(xmlSchemaPSVIIDCBinding));
21954 if (ret == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021955 xmlSchemaVErrMemory(NULL,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000021956 "allocating a PSVI IDC binding item", NULL);
21957 return (NULL);
21958 }
21959 memset(ret, 0, sizeof(xmlSchemaPSVIIDCBinding));
21960 ret->definition = idcDef;
21961 return (ret);
21962}
21963
21964/**
21965 * xmlSchemaIDCStoreNodeTableItem:
21966 * @vctxt: the WXS validation context
21967 * @item: the IDC node table item
21968 *
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000021969 * The validation context is used to store IDC node table items.
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000021970 * They are stored to avoid copying them if IDC node-tables are merged
21971 * with corresponding parent IDC node-tables (bubbling).
21972 *
21973 * Returns 0 if succeeded, -1 on internal errors.
21974 */
21975static int
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021976xmlSchemaIDCStoreNodeTableItem(xmlSchemaValidCtxtPtr vctxt,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000021977 xmlSchemaPSVIIDCNodePtr item)
21978{
21979 /*
21980 * Add to gobal list.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021981 */
21982 if (vctxt->idcNodes == NULL) {
21983 vctxt->idcNodes = (xmlSchemaPSVIIDCNodePtr *)
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000021984 xmlMalloc(20 * sizeof(xmlSchemaPSVIIDCNodePtr));
21985 if (vctxt->idcNodes == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021986 xmlSchemaVErrMemory(vctxt,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000021987 "allocating the IDC node table item list", NULL);
21988 return (-1);
21989 }
21990 vctxt->sizeIdcNodes = 20;
21991 } else if (vctxt->sizeIdcNodes <= vctxt->nbIdcNodes) {
21992 vctxt->sizeIdcNodes *= 2;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021993 vctxt->idcNodes = (xmlSchemaPSVIIDCNodePtr *)
21994 xmlRealloc(vctxt->idcNodes, vctxt->sizeIdcNodes *
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000021995 sizeof(xmlSchemaPSVIIDCNodePtr));
21996 if (vctxt->idcNodes == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000021997 xmlSchemaVErrMemory(vctxt,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000021998 "re-allocating the IDC node table item list", NULL);
21999 return (-1);
22000 }
22001 }
22002 vctxt->idcNodes[vctxt->nbIdcNodes++] = item;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022003
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022004 return (0);
22005}
22006
22007/**
22008 * xmlSchemaIDCStoreKey:
22009 * @vctxt: the WXS validation context
22010 * @item: the IDC key
22011 *
22012 * The validation context is used to store an IDC key.
22013 *
22014 * Returns 0 if succeeded, -1 on internal errors.
22015 */
22016static int
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022017xmlSchemaIDCStoreKey(xmlSchemaValidCtxtPtr vctxt,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022018 xmlSchemaPSVIIDCKeyPtr key)
22019{
22020 /*
22021 * Add to gobal list.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022022 */
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022023 if (vctxt->idcKeys == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022024 vctxt->idcKeys = (xmlSchemaPSVIIDCKeyPtr *)
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022025 xmlMalloc(40 * sizeof(xmlSchemaPSVIIDCKeyPtr));
22026 if (vctxt->idcKeys == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022027 xmlSchemaVErrMemory(vctxt,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022028 "allocating the IDC key storage list", NULL);
22029 return (-1);
22030 }
22031 vctxt->sizeIdcKeys = 40;
22032 } else if (vctxt->sizeIdcKeys <= vctxt->nbIdcKeys) {
22033 vctxt->sizeIdcKeys *= 2;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022034 vctxt->idcKeys = (xmlSchemaPSVIIDCKeyPtr *)
22035 xmlRealloc(vctxt->idcKeys, vctxt->sizeIdcKeys *
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022036 sizeof(xmlSchemaPSVIIDCKeyPtr));
22037 if (vctxt->idcKeys == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022038 xmlSchemaVErrMemory(vctxt,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022039 "re-allocating the IDC key storage list", NULL);
22040 return (-1);
22041 }
22042 }
22043 vctxt->idcKeys[vctxt->nbIdcKeys++] = key;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022044
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022045 return (0);
22046}
22047
22048/**
22049 * xmlSchemaIDCAppendNodeTableItem:
22050 * @bind: the IDC binding
22051 * @ntItem: the node-table item
22052 *
22053 * Appends the IDC node-table item to the binding.
22054 *
22055 * Returns 0 on success and -1 on internal errors.
22056 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022057static int
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022058xmlSchemaIDCAppendNodeTableItem(xmlSchemaPSVIIDCBindingPtr bind,
22059 xmlSchemaPSVIIDCNodePtr ntItem)
22060{
22061 if (bind->nodeTable == NULL) {
22062 bind->sizeNodes = 10;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022063 bind->nodeTable = (xmlSchemaPSVIIDCNodePtr *)
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022064 xmlMalloc(10 * sizeof(xmlSchemaPSVIIDCNodePtr));
22065 if (bind->nodeTable == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022066 xmlSchemaVErrMemory(NULL,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022067 "allocating an array of IDC node-table items", NULL);
22068 return(-1);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022069 }
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022070 } else if (bind->sizeNodes <= bind->nbNodes) {
22071 bind->sizeNodes *= 2;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022072 bind->nodeTable = (xmlSchemaPSVIIDCNodePtr *)
22073 xmlRealloc(bind->nodeTable, bind->sizeNodes *
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022074 sizeof(xmlSchemaPSVIIDCNodePtr));
22075 if (bind->nodeTable == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022076 xmlSchemaVErrMemory(NULL,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022077 "re-allocating an array of IDC node-table items", NULL);
22078 return(-1);
22079 }
22080 }
22081 bind->nodeTable[bind->nbNodes++] = ntItem;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022082 return(0);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022083}
22084
22085/**
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022086 * xmlSchemaIDCAcquireBinding:
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022087 * @vctxt: the WXS validation context
22088 * @matcher: the IDC matcher
22089 *
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022090 * Looks up an PSVI IDC binding, for the IDC definition and
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022091 * of the given matcher. If none found, a new one is created
22092 * and added to the IDC table.
22093 *
22094 * Returns an IDC binding or NULL on internal errors.
22095 */
22096static xmlSchemaPSVIIDCBindingPtr
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022097xmlSchemaIDCAcquireBinding(xmlSchemaValidCtxtPtr vctxt,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022098 xmlSchemaIDCMatcherPtr matcher)
22099{
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022100 xmlSchemaNodeInfoPtr ielem;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022101
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022102 ielem = vctxt->elemInfos[matcher->depth];
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022103
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022104 if (ielem->idcTable == NULL) {
22105 ielem->idcTable = xmlSchemaIDCNewBinding(matcher->aidc->def);
22106 if (ielem->idcTable == NULL)
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022107 return (NULL);
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022108 return(ielem->idcTable);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022109 } else {
22110 xmlSchemaPSVIIDCBindingPtr bind = NULL;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022111
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022112 bind = ielem->idcTable;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022113 do {
22114 if (bind->definition == matcher->aidc->def)
22115 return(bind);
22116 if (bind->next == NULL) {
22117 bind->next = xmlSchemaIDCNewBinding(matcher->aidc->def);
22118 if (bind->next == NULL)
22119 return (NULL);
22120 return(bind->next);
22121 }
22122 bind = bind->next;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022123 } while (bind != NULL);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022124 }
22125 return (NULL);
22126}
22127
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022128static xmlSchemaItemListPtr
22129xmlSchemaIDCAcquireTargetList(xmlSchemaValidCtxtPtr vctxt ATTRIBUTE_UNUSED,
22130 xmlSchemaIDCMatcherPtr matcher)
22131{
22132 if (matcher->targets == NULL)
22133 matcher->targets = xmlSchemaItemListCreate();
22134 return(matcher->targets);
22135}
22136
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022137/**
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022138 * xmlSchemaIDCFreeKey:
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022139 * @key: the IDC key
22140 *
22141 * Frees an IDC key together with its compiled value.
22142 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022143static void
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022144xmlSchemaIDCFreeKey(xmlSchemaPSVIIDCKeyPtr key)
22145{
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022146 if (key->val != NULL)
22147 xmlSchemaFreeValue(key->val);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022148 xmlFree(key);
22149}
22150
22151/**
22152 * xmlSchemaIDCFreeBinding:
22153 *
22154 * Frees an IDC binding. Note that the node table-items
22155 * are not freed.
22156 */
Kasimier T. Buchcikbd2a7d12005-02-16 12:27:25 +000022157static void
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022158xmlSchemaIDCFreeBinding(xmlSchemaPSVIIDCBindingPtr bind)
22159{
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022160 if (bind->nodeTable != NULL)
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022161 xmlFree(bind->nodeTable);
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022162 if (bind->dupls != NULL)
Daniel Veillarddee23482008-04-11 12:58:43 +000022163 xmlSchemaItemListFree(bind->dupls);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022164 xmlFree(bind);
22165}
22166
22167/**
22168 * xmlSchemaIDCFreeIDCTable:
22169 * @bind: the first IDC binding in the list
22170 *
22171 * Frees an IDC table, i.e. all the IDC bindings in the list.
22172 */
22173static void
22174xmlSchemaIDCFreeIDCTable(xmlSchemaPSVIIDCBindingPtr bind)
22175{
22176 xmlSchemaPSVIIDCBindingPtr prev;
22177
22178 while (bind != NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022179 prev = bind;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022180 bind = bind->next;
22181 xmlSchemaIDCFreeBinding(prev);
22182 }
22183}
22184
22185/**
22186 * xmlSchemaIDCFreeMatcherList:
22187 * @matcher: the first IDC matcher in the list
22188 *
22189 * Frees a list of IDC matchers.
22190 */
22191static void
22192xmlSchemaIDCFreeMatcherList(xmlSchemaIDCMatcherPtr matcher)
22193{
22194 xmlSchemaIDCMatcherPtr next;
22195
22196 while (matcher != NULL) {
22197 next = matcher->next;
Daniel Veillarddee23482008-04-11 12:58:43 +000022198 if (matcher->keySeqs != NULL) {
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022199 int i;
22200 for (i = 0; i < matcher->sizeKeySeqs; i++)
22201 if (matcher->keySeqs[i] != NULL)
22202 xmlFree(matcher->keySeqs[i]);
Daniel Veillarddee23482008-04-11 12:58:43 +000022203 xmlFree(matcher->keySeqs);
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022204 }
22205 if (matcher->targets != NULL) {
22206 if (matcher->idcType == XML_SCHEMA_TYPE_IDC_KEYREF) {
22207 int i;
22208 xmlSchemaPSVIIDCNodePtr idcNode;
22209 /*
22210 * Node-table items for keyrefs are not stored globally
22211 * to the validation context, since they are not bubbled.
22212 * We need to free them here.
22213 */
22214 for (i = 0; i < matcher->targets->nbItems; i++) {
22215 idcNode =
22216 (xmlSchemaPSVIIDCNodePtr) matcher->targets->items[i];
22217 xmlFree(idcNode->keys);
22218 xmlFree(idcNode);
22219 }
22220 }
22221 xmlSchemaItemListFree(matcher->targets);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022222 }
22223 xmlFree(matcher);
22224 matcher = next;
22225 }
22226}
22227
22228/**
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000022229 * xmlSchemaIDCReleaseMatcherList:
22230 * @vctxt: the WXS validation context
22231 * @matcher: the first IDC matcher in the list
22232 *
22233 * Caches a list of IDC matchers for reuse.
22234 */
22235static void
22236xmlSchemaIDCReleaseMatcherList(xmlSchemaValidCtxtPtr vctxt,
22237 xmlSchemaIDCMatcherPtr matcher)
22238{
22239 xmlSchemaIDCMatcherPtr next;
22240
22241 while (matcher != NULL) {
22242 next = matcher->next;
Daniel Veillarddee23482008-04-11 12:58:43 +000022243 if (matcher->keySeqs != NULL) {
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000022244 int i;
22245 /*
22246 * Don't free the array, but only the content.
22247 */
22248 for (i = 0; i < matcher->sizeKeySeqs; i++)
22249 if (matcher->keySeqs[i] != NULL) {
22250 xmlFree(matcher->keySeqs[i]);
22251 matcher->keySeqs[i] = NULL;
22252 }
22253 }
22254 if (matcher->targets) {
22255 if (matcher->idcType == XML_SCHEMA_TYPE_IDC_KEYREF) {
22256 int i;
22257 xmlSchemaPSVIIDCNodePtr idcNode;
22258 /*
22259 * Node-table items for keyrefs are not stored globally
22260 * to the validation context, since they are not bubbled.
22261 * We need to free them here.
22262 */
22263 for (i = 0; i < matcher->targets->nbItems; i++) {
22264 idcNode =
22265 (xmlSchemaPSVIIDCNodePtr) matcher->targets->items[i];
22266 xmlFree(idcNode->keys);
22267 xmlFree(idcNode);
22268 }
22269 }
22270 xmlSchemaItemListFree(matcher->targets);
22271 matcher->targets = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000022272 }
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000022273 matcher->next = NULL;
22274 /*
22275 * Cache the matcher.
22276 */
22277 if (vctxt->idcMatcherCache != NULL)
22278 matcher->nextCached = vctxt->idcMatcherCache;
22279 vctxt->idcMatcherCache = matcher;
22280
22281 matcher = next;
22282 }
22283}
22284
22285/**
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022286 * xmlSchemaIDCAddStateObject:
22287 * @vctxt: the WXS validation context
22288 * @matcher: the IDC matcher
22289 * @sel: the XPath information
22290 * @parent: the parent "selector" state object if any
22291 * @type: "selector" or "field"
22292 *
22293 * Creates/reuses and activates state objects for the given
22294 * XPath information; if the XPath expression consists of unions,
22295 * multiple state objects are created for every unioned expression.
22296 *
22297 * Returns 0 on success and -1 on internal errors.
22298 */
22299static int
22300xmlSchemaIDCAddStateObject(xmlSchemaValidCtxtPtr vctxt,
22301 xmlSchemaIDCMatcherPtr matcher,
22302 xmlSchemaIDCSelectPtr sel,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022303 int type)
22304{
22305 xmlSchemaIDCStateObjPtr sto;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022306
22307 /*
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022308 * Reuse the state objects from the pool.
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022309 */
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022310 if (vctxt->xpathStatePool != NULL) {
22311 sto = vctxt->xpathStatePool;
22312 vctxt->xpathStatePool = sto->next;
22313 sto->next = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000022314 } else {
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022315 /*
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022316 * Create a new state object.
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022317 */
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022318 sto = (xmlSchemaIDCStateObjPtr) xmlMalloc(sizeof(xmlSchemaIDCStateObj));
22319 if (sto == NULL) {
22320 xmlSchemaVErrMemory(NULL,
22321 "allocating an IDC state object", NULL);
22322 return (-1);
22323 }
22324 memset(sto, 0, sizeof(xmlSchemaIDCStateObj));
Daniel Veillarddee23482008-04-11 12:58:43 +000022325 }
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022326 /*
Daniel Veillarddee23482008-04-11 12:58:43 +000022327 * Add to global list.
22328 */
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022329 if (vctxt->xpathStates != NULL)
22330 sto->next = vctxt->xpathStates;
22331 vctxt->xpathStates = sto;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022332
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022333 /*
22334 * Free the old xpath validation context.
22335 */
22336 if (sto->xpathCtxt != NULL)
22337 xmlFreeStreamCtxt((xmlStreamCtxtPtr) sto->xpathCtxt);
22338
22339 /*
22340 * Create a new XPath (pattern) validation context.
22341 */
22342 sto->xpathCtxt = (void *) xmlPatternGetStreamCtxt(
22343 (xmlPatternPtr) sel->xpathComp);
22344 if (sto->xpathCtxt == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022345 VERROR_INT("xmlSchemaIDCAddStateObject",
22346 "failed to create an XPath validation context");
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022347 return (-1);
Daniel Veillarddee23482008-04-11 12:58:43 +000022348 }
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022349 sto->type = type;
22350 sto->depth = vctxt->depth;
22351 sto->matcher = matcher;
22352 sto->sel = sel;
22353 sto->nbHistory = 0;
Daniel Veillarddee23482008-04-11 12:58:43 +000022354
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022355#ifdef DEBUG_IDC
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022356 xmlGenericError(xmlGenericErrorContext, "IDC: STO push '%s'\n",
22357 sto->sel->xpath);
22358#endif
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022359 return (0);
22360}
22361
22362/**
22363 * xmlSchemaXPathEvaluate:
22364 * @vctxt: the WXS validation context
22365 * @nodeType: the nodeType of the current node
22366 *
22367 * Evaluates all active XPath state objects.
22368 *
22369 * Returns the number of IC "field" state objects which resolved to
22370 * this node, 0 if none resolved and -1 on internal errors.
22371 */
22372static int
22373xmlSchemaXPathEvaluate(xmlSchemaValidCtxtPtr vctxt,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022374 xmlElementType nodeType)
22375{
22376 xmlSchemaIDCStateObjPtr sto, head = NULL, first;
Kasimier T. Buchcikbd2a7d12005-02-16 12:27:25 +000022377 int res, resolved = 0, depth = vctxt->depth;
Daniel Veillarddee23482008-04-11 12:58:43 +000022378
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022379 if (vctxt->xpathStates == NULL)
22380 return (0);
Kasimier T. Buchcikbd2a7d12005-02-16 12:27:25 +000022381
22382 if (nodeType == XML_ATTRIBUTE_NODE)
22383 depth++;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022384#ifdef DEBUG_IDC
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022385 {
22386 xmlChar *str = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000022387 xmlGenericError(xmlGenericErrorContext,
22388 "IDC: EVAL on %s, depth %d, type %d\n",
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022389 xmlSchemaFormatQName(&str, vctxt->inode->nsName,
22390 vctxt->inode->localName), depth, nodeType);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022391 FREE_AND_NULL(str)
22392 }
22393#endif
22394 /*
22395 * Process all active XPath state objects.
22396 */
22397 first = vctxt->xpathStates;
22398 sto = first;
22399 while (sto != head) {
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022400#ifdef DEBUG_IDC
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022401 if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_SELECTOR)
Daniel Veillarddee23482008-04-11 12:58:43 +000022402 xmlGenericError(xmlGenericErrorContext, "IDC: ['%s'] selector '%s'\n",
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022403 sto->matcher->aidc->def->name, sto->sel->xpath);
22404 else
Daniel Veillarddee23482008-04-11 12:58:43 +000022405 xmlGenericError(xmlGenericErrorContext, "IDC: ['%s'] field '%s'\n",
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022406 sto->matcher->aidc->def->name, sto->sel->xpath);
22407#endif
Kasimier T. Buchcikbd2a7d12005-02-16 12:27:25 +000022408 if (nodeType == XML_ELEMENT_NODE)
22409 res = xmlStreamPush((xmlStreamCtxtPtr) sto->xpathCtxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022410 vctxt->inode->localName, vctxt->inode->nsName);
Kasimier T. Buchcikbd2a7d12005-02-16 12:27:25 +000022411 else
22412 res = xmlStreamPushAttr((xmlStreamCtxtPtr) sto->xpathCtxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022413 vctxt->inode->localName, vctxt->inode->nsName);
Kasimier T. Buchcikbd2a7d12005-02-16 12:27:25 +000022414
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022415 if (res == -1) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022416 VERROR_INT("xmlSchemaXPathEvaluate",
22417 "calling xmlStreamPush()");
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022418 return (-1);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022419 }
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022420 if (res == 0)
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022421 goto next_sto;
22422 /*
22423 * Full match.
22424 */
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022425#ifdef DEBUG_IDC
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022426 xmlGenericError(xmlGenericErrorContext, "IDC: "
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022427 "MATCH\n");
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022428#endif
22429 /*
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022430 * Register a match in the state object history.
22431 */
22432 if (sto->history == NULL) {
22433 sto->history = (int *) xmlMalloc(5 * sizeof(int));
22434 if (sto->history == NULL) {
Daniel Veillarddee23482008-04-11 12:58:43 +000022435 xmlSchemaVErrMemory(NULL,
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022436 "allocating the state object history", NULL);
22437 return(-1);
22438 }
Daniel Veillard6f9b0872006-08-12 14:09:01 +000022439 sto->sizeHistory = 5;
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022440 } else if (sto->sizeHistory <= sto->nbHistory) {
22441 sto->sizeHistory *= 2;
22442 sto->history = (int *) xmlRealloc(sto->history,
22443 sto->sizeHistory * sizeof(int));
22444 if (sto->history == NULL) {
Daniel Veillarddee23482008-04-11 12:58:43 +000022445 xmlSchemaVErrMemory(NULL,
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022446 "re-allocating the state object history", NULL);
22447 return(-1);
22448 }
Daniel Veillarddee23482008-04-11 12:58:43 +000022449 }
Kasimier T. Buchcikbd2a7d12005-02-16 12:27:25 +000022450 sto->history[sto->nbHistory++] = depth;
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022451
22452#ifdef DEBUG_IDC
22453 xmlGenericError(xmlGenericErrorContext, "IDC: push match '%d'\n",
22454 vctxt->depth);
22455#endif
22456
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022457 if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_SELECTOR) {
22458 xmlSchemaIDCSelectPtr sel;
22459 /*
22460 * Activate state objects for the IDC fields of
22461 * the IDC selector.
22462 */
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022463#ifdef DEBUG_IDC
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022464 xmlGenericError(xmlGenericErrorContext, "IDC: "
22465 "activating field states\n");
22466#endif
22467 sel = sto->matcher->aidc->def->fields;
22468 while (sel != NULL) {
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022469 if (xmlSchemaIDCAddStateObject(vctxt, sto->matcher,
22470 sel, XPATH_STATE_OBJ_TYPE_IDC_FIELD) == -1)
22471 return (-1);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022472 sel = sel->next;
22473 }
22474 } else if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_FIELD) {
22475 /*
Kasimier T. Buchcik9ca11bf2005-06-14 19:24:47 +000022476 * An IDC key node was found by the IDC field.
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022477 */
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022478#ifdef DEBUG_IDC
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022479 xmlGenericError(xmlGenericErrorContext,
22480 "IDC: key found\n");
22481#endif
22482 /*
22483 * Notify that the character value of this node is
22484 * needed.
22485 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022486 if (resolved == 0) {
22487 if ((vctxt->inode->flags &
22488 XML_SCHEMA_NODE_INFO_VALUE_NEEDED) == 0)
22489 vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_VALUE_NEEDED;
22490 }
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022491 resolved++;
22492 }
22493next_sto:
22494 if (sto->next == NULL) {
22495 /*
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022496 * Evaluate field state objects created on this node as well.
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022497 */
22498 head = first;
22499 sto = vctxt->xpathStates;
22500 } else
22501 sto = sto->next;
22502 }
22503 return (resolved);
22504}
22505
Kasimier T. Buchcikc872afb2005-04-18 10:57:04 +000022506static const xmlChar *
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022507xmlSchemaFormatIDCKeySequence(xmlSchemaValidCtxtPtr vctxt,
Kasimier T. Buchcikc872afb2005-04-18 10:57:04 +000022508 xmlChar **buf,
22509 xmlSchemaPSVIIDCKeyPtr *seq,
22510 int count)
22511{
22512 int i, res;
Kasimier T. Buchcik77e76822005-11-11 12:52:32 +000022513 xmlChar *value = NULL;
Kasimier T. Buchcikc872afb2005-04-18 10:57:04 +000022514
22515 *buf = xmlStrdup(BAD_CAST "[");
22516 for (i = 0; i < count; i++) {
22517 *buf = xmlStrcat(*buf, BAD_CAST "'");
Daniel Veillarddee23482008-04-11 12:58:43 +000022518 res = xmlSchemaGetCanonValueWhtspExt(seq[i]->val,
Kasimier T. Buchcik77e76822005-11-11 12:52:32 +000022519 xmlSchemaGetWhiteSpaceFacetValue(seq[i]->type),
22520 &value);
Kasimier T. Buchcikc872afb2005-04-18 10:57:04 +000022521 if (res == 0)
Kasimier T. Buchcik77e76822005-11-11 12:52:32 +000022522 *buf = xmlStrcat(*buf, BAD_CAST value);
Kasimier T. Buchcikc872afb2005-04-18 10:57:04 +000022523 else {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022524 VERROR_INT("xmlSchemaFormatIDCKeySequence",
22525 "failed to compute a canonical value");
Kasimier T. Buchcikc872afb2005-04-18 10:57:04 +000022526 *buf = xmlStrcat(*buf, BAD_CAST "???");
22527 }
22528 if (i < count -1)
22529 *buf = xmlStrcat(*buf, BAD_CAST "', ");
22530 else
22531 *buf = xmlStrcat(*buf, BAD_CAST "'");
22532 if (value != NULL) {
Kasimier T. Buchcik77e76822005-11-11 12:52:32 +000022533 xmlFree(value);
Kasimier T. Buchcikc872afb2005-04-18 10:57:04 +000022534 value = NULL;
22535 }
22536 }
22537 *buf = xmlStrcat(*buf, BAD_CAST "]");
22538
22539 return (BAD_CAST *buf);
22540}
22541
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022542/**
Kasimier T. Buchcik800cbac2005-08-09 12:31:55 +000022543 * xmlSchemaXPathPop:
22544 * @vctxt: the WXS validation context
22545 *
22546 * Pops all XPath states.
22547 *
22548 * Returns 0 on success and -1 on internal errors.
22549 */
22550static int
22551xmlSchemaXPathPop(xmlSchemaValidCtxtPtr vctxt)
22552{
22553 xmlSchemaIDCStateObjPtr sto;
22554 int res;
22555
22556 if (vctxt->xpathStates == NULL)
22557 return(0);
22558 sto = vctxt->xpathStates;
22559 do {
22560 res = xmlStreamPop((xmlStreamCtxtPtr) sto->xpathCtxt);
22561 if (res == -1)
22562 return (-1);
22563 sto = sto->next;
22564 } while (sto != NULL);
22565 return(0);
22566}
22567
22568/**
Kasimier T. Buchcik25799ce2005-02-15 14:39:48 +000022569 * xmlSchemaXPathProcessHistory:
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022570 * @vctxt: the WXS validation context
22571 * @type: the simple/complex type of the current node if any at all
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022572 * @val: the precompiled value
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022573 *
22574 * Processes and pops the history items of the IDC state objects.
22575 * IDC key-sequences are validated/created on IDC bindings.
Daniel Veillarddee23482008-04-11 12:58:43 +000022576 *
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022577 * Returns 0 on success and -1 on internal errors.
22578 */
22579static int
Kasimier T. Buchcik25799ce2005-02-15 14:39:48 +000022580xmlSchemaXPathProcessHistory(xmlSchemaValidCtxtPtr vctxt,
Kasimier T. Buchcikbd2a7d12005-02-16 12:27:25 +000022581 int depth)
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022582{
22583 xmlSchemaIDCStateObjPtr sto, nextsto;
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022584 int res, matchDepth;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022585 xmlSchemaPSVIIDCKeyPtr key = NULL;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022586 xmlSchemaTypePtr type = vctxt->inode->typeDef, simpleType = NULL;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022587
22588 if (vctxt->xpathStates == NULL)
22589 return (0);
22590 sto = vctxt->xpathStates;
22591
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022592#ifdef DEBUG_IDC
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022593 {
22594 xmlChar *str = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000022595 xmlGenericError(xmlGenericErrorContext,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022596 "IDC: BACK on %s, depth %d\n",
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022597 xmlSchemaFormatQName(&str, vctxt->inode->nsName,
22598 vctxt->inode->localName), vctxt->depth);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022599 FREE_AND_NULL(str)
22600 }
Daniel Veillarddee23482008-04-11 12:58:43 +000022601#endif
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022602 /*
22603 * Evaluate the state objects.
22604 */
22605 while (sto != NULL) {
Kasimier T. Buchcikc63fbbf2005-06-15 12:54:05 +000022606 res = xmlStreamPop((xmlStreamCtxtPtr) sto->xpathCtxt);
22607 if (res == -1) {
22608 VERROR_INT("xmlSchemaXPathProcessHistory",
22609 "calling xmlStreamPop()");
22610 return (-1);
22611 }
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022612#ifdef DEBUG_IDC
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000022613 xmlGenericError(xmlGenericErrorContext, "IDC: stream pop '%s'\n",
22614 sto->sel->xpath);
Kasimier T. Buchcik25799ce2005-02-15 14:39:48 +000022615#endif
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022616 if (sto->nbHistory == 0)
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022617 goto deregister_check;
22618
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022619 matchDepth = sto->history[sto->nbHistory -1];
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022620
22621 /*
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022622 * Only matches at the current depth are of interest.
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022623 */
Kasimier T. Buchcikbd2a7d12005-02-16 12:27:25 +000022624 if (matchDepth != depth) {
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022625 sto = sto->next;
22626 continue;
Daniel Veillarddee23482008-04-11 12:58:43 +000022627 }
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022628 if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_FIELD) {
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022629 /*
22630 * NOTE: According to
22631 * http://www.w3.org/Bugs/Public/show_bug.cgi?id=2198
22632 * ... the simple-content of complex types is also allowed.
22633 */
Daniel Veillarddee23482008-04-11 12:58:43 +000022634
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022635 if (WXS_IS_COMPLEX(type)) {
22636 if (WXS_HAS_SIMPLE_CONTENT(type)) {
22637 /*
22638 * Sanity check for complex types with simple content.
22639 */
22640 simpleType = type->contentTypeDef;
22641 if (simpleType == NULL) {
22642 VERROR_INT("xmlSchemaXPathProcessHistory",
22643 "field resolves to a CT with simple content "
22644 "but the CT is missing the ST definition");
22645 return (-1);
22646 }
22647 } else
22648 simpleType = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000022649 } else
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022650 simpleType = type;
22651 if (simpleType == NULL) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000022652 xmlChar *str = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000022653
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022654 /*
22655 * Not qualified if the field resolves to a node of non
22656 * simple type.
Daniel Veillarddee23482008-04-11 12:58:43 +000022657 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000022658 xmlSchemaCustomErr(ACTXT_CAST vctxt,
Daniel Veillarddee23482008-04-11 12:58:43 +000022659 XML_SCHEMAV_CVC_IDC, NULL,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000022660 WXS_BASIC_CAST sto->matcher->aidc->def,
22661 "The XPath '%s' of a field of %s does evaluate to a node of "
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000022662 "non-simple type",
22663 sto->sel->xpath,
22664 xmlSchemaGetIDCDesignation(&str, sto->matcher->aidc->def));
22665 FREE_AND_NULL(str);
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022666 sto->nbHistory--;
22667 goto deregister_check;
22668 }
Daniel Veillarddee23482008-04-11 12:58:43 +000022669
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022670 if ((key == NULL) && (vctxt->inode->val == NULL)) {
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022671 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022672 * Failed to provide the normalized value; maybe
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022673 * the value was invalid.
Kasimier T. Buchcik9b77aa02005-03-04 22:04:16 +000022674 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022675 VERROR(XML_SCHEMAV_CVC_IDC,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000022676 WXS_BASIC_CAST sto->matcher->aidc->def,
Kasimier T. Buchcik6e224f12005-02-17 11:10:44 +000022677 "Warning: No precomputed value available, the value "
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022678 "was either invalid or something strange happend");
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022679 sto->nbHistory--;
22680 goto deregister_check;
22681 } else {
22682 xmlSchemaIDCMatcherPtr matcher = sto->matcher;
22683 xmlSchemaPSVIIDCKeyPtr *keySeq;
Kasimier T. Buchcikbd2a7d12005-02-16 12:27:25 +000022684 int pos, idx;
Daniel Veillarddee23482008-04-11 12:58:43 +000022685
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022686 /*
22687 * The key will be anchored on the matcher's list of
22688 * key-sequences. The position in this list is determined
22689 * by the target node's depth relative to the matcher's
22690 * depth of creation (i.e. the depth of the scope element).
Daniel Veillarddee23482008-04-11 12:58:43 +000022691 *
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022692 * Element Depth Pos List-entries
22693 * <scope> 0 NULL
22694 * <bar> 1 NULL
22695 * <target/> 2 2 target
22696 * <bar>
22697 * </scope>
22698 *
22699 * The size of the list is only dependant on the depth of
22700 * the tree.
22701 * An entry will be NULLed in selector_leave, i.e. when
Daniel Veillarddee23482008-04-11 12:58:43 +000022702 * we hit the target's
22703 */
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022704 pos = sto->depth - matcher->depth;
Kasimier T. Buchcikbd2a7d12005-02-16 12:27:25 +000022705 idx = sto->sel->index;
Daniel Veillarddee23482008-04-11 12:58:43 +000022706
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022707 /*
22708 * Create/grow the array of key-sequences.
22709 */
22710 if (matcher->keySeqs == NULL) {
Daniel Veillarddee23482008-04-11 12:58:43 +000022711 if (pos > 9)
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022712 matcher->sizeKeySeqs = pos * 2;
22713 else
22714 matcher->sizeKeySeqs = 10;
Daniel Veillarddee23482008-04-11 12:58:43 +000022715 matcher->keySeqs = (xmlSchemaPSVIIDCKeyPtr **)
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022716 xmlMalloc(matcher->sizeKeySeqs *
Daniel Veillarddee23482008-04-11 12:58:43 +000022717 sizeof(xmlSchemaPSVIIDCKeyPtr *));
22718 if (matcher->keySeqs == NULL) {
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022719 xmlSchemaVErrMemory(NULL,
22720 "allocating an array of key-sequences",
22721 NULL);
22722 return(-1);
22723 }
22724 memset(matcher->keySeqs, 0,
22725 matcher->sizeKeySeqs *
22726 sizeof(xmlSchemaPSVIIDCKeyPtr *));
Daniel Veillarddee23482008-04-11 12:58:43 +000022727 } else if (pos >= matcher->sizeKeySeqs) {
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022728 int i = matcher->sizeKeySeqs;
Daniel Veillarddee23482008-04-11 12:58:43 +000022729
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022730 matcher->sizeKeySeqs *= 2;
22731 matcher->keySeqs = (xmlSchemaPSVIIDCKeyPtr **)
22732 xmlRealloc(matcher->keySeqs,
22733 matcher->sizeKeySeqs *
22734 sizeof(xmlSchemaPSVIIDCKeyPtr *));
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022735 if (matcher->keySeqs == NULL) {
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022736 xmlSchemaVErrMemory(NULL,
22737 "reallocating an array of key-sequences",
22738 NULL);
22739 return (-1);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022740 }
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022741 /*
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022742 * The array needs to be NULLed.
22743 * TODO: Use memset?
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022744 */
Daniel Veillarddee23482008-04-11 12:58:43 +000022745 for (; i < matcher->sizeKeySeqs; i++)
22746 matcher->keySeqs[i] = NULL;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022747 }
Daniel Veillarddee23482008-04-11 12:58:43 +000022748
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022749 /*
22750 * Get/create the key-sequence.
22751 */
Daniel Veillarddee23482008-04-11 12:58:43 +000022752 keySeq = matcher->keySeqs[pos];
22753 if (keySeq == NULL) {
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022754 goto create_sequence;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022755 } else if (keySeq[idx] != NULL) {
22756 xmlChar *str = NULL;
22757 /*
22758 * cvc-identity-constraint:
Rob Richardsc6947bb2008-06-29 15:04:41 +000022759 * 3 For each node in the �target node set� all
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022760 * of the {fields}, with that node as the context
22761 * node, evaluate to either an empty node-set or
22762 * a node-set with exactly one member, which must
22763 * have a simple type.
Daniel Veillarddee23482008-04-11 12:58:43 +000022764 *
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022765 * The key was already set; report an error.
22766 */
Daniel Veillarddee23482008-04-11 12:58:43 +000022767 xmlSchemaCustomErr(ACTXT_CAST vctxt,
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022768 XML_SCHEMAV_CVC_IDC, NULL,
22769 WXS_BASIC_CAST matcher->aidc->def,
22770 "The XPath '%s' of a field of %s evaluates to a "
22771 "node-set with more than one member",
22772 sto->sel->xpath,
22773 xmlSchemaGetIDCDesignation(&str, matcher->aidc->def));
22774 FREE_AND_NULL(str);
22775 sto->nbHistory--;
22776 goto deregister_check;
22777 } else
Daniel Veillarddee23482008-04-11 12:58:43 +000022778 goto create_key;
22779
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022780create_sequence:
22781 /*
22782 * Create a key-sequence.
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022783 */
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022784 keySeq = (xmlSchemaPSVIIDCKeyPtr *) xmlMalloc(
Daniel Veillarddee23482008-04-11 12:58:43 +000022785 matcher->aidc->def->nbFields *
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022786 sizeof(xmlSchemaPSVIIDCKeyPtr));
22787 if (keySeq == NULL) {
Daniel Veillarddee23482008-04-11 12:58:43 +000022788 xmlSchemaVErrMemory(NULL,
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022789 "allocating an IDC key-sequence", NULL);
Daniel Veillarddee23482008-04-11 12:58:43 +000022790 return(-1);
22791 }
22792 memset(keySeq, 0, matcher->aidc->def->nbFields *
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022793 sizeof(xmlSchemaPSVIIDCKeyPtr));
22794 matcher->keySeqs[pos] = keySeq;
22795create_key:
22796 /*
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022797 * Create a key once per node only.
Daniel Veillarddee23482008-04-11 12:58:43 +000022798 */
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022799 if (key == NULL) {
22800 key = (xmlSchemaPSVIIDCKeyPtr) xmlMalloc(
22801 sizeof(xmlSchemaPSVIIDCKey));
22802 if (key == NULL) {
22803 xmlSchemaVErrMemory(NULL,
22804 "allocating a IDC key", NULL);
22805 xmlFree(keySeq);
22806 matcher->keySeqs[pos] = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000022807 return(-1);
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022808 }
22809 /*
22810 * Consume the compiled value.
22811 */
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022812 key->type = simpleType;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022813 key->val = vctxt->inode->val;
22814 vctxt->inode->val = NULL;
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022815 /*
22816 * Store the key in a global list.
22817 */
22818 if (xmlSchemaIDCStoreKey(vctxt, key) == -1) {
22819 xmlSchemaIDCFreeKey(key);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022820 return (-1);
22821 }
22822 }
Daniel Veillarddee23482008-04-11 12:58:43 +000022823 keySeq[idx] = key;
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022824 }
22825 } else if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_SELECTOR) {
Daniel Veillarddee23482008-04-11 12:58:43 +000022826
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022827 xmlSchemaPSVIIDCKeyPtr **keySeq = NULL;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022828 /* xmlSchemaPSVIIDCBindingPtr bind; */
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022829 xmlSchemaPSVIIDCNodePtr ntItem;
22830 xmlSchemaIDCMatcherPtr matcher;
22831 xmlSchemaIDCPtr idc;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022832 xmlSchemaItemListPtr targets;
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022833 int pos, i, j, nbKeys;
22834 /*
22835 * Here we have the following scenario:
22836 * An IDC 'selector' state object resolved to a target node,
Daniel Veillarddee23482008-04-11 12:58:43 +000022837 * during the time this target node was in the
22838 * ancestor-or-self axis, the 'field' state object(s) looked
22839 * out for matching nodes to create a key-sequence for this
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022840 * target node. Now we are back to this target node and need
Daniel Veillarddee23482008-04-11 12:58:43 +000022841 * to put the key-sequence, together with the target node
22842 * itself, into the node-table of the corresponding IDC
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022843 * binding.
22844 */
22845 matcher = sto->matcher;
22846 idc = matcher->aidc->def;
22847 nbKeys = idc->nbFields;
Daniel Veillarddee23482008-04-11 12:58:43 +000022848 pos = depth - matcher->depth;
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022849 /*
22850 * Check if the matcher has any key-sequences at all, plus
22851 * if it has a key-sequence for the current target node.
Daniel Veillarddee23482008-04-11 12:58:43 +000022852 */
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022853 if ((matcher->keySeqs == NULL) ||
22854 (matcher->sizeKeySeqs <= pos)) {
22855 if (idc->type == XML_SCHEMA_TYPE_IDC_KEY)
22856 goto selector_key_error;
22857 else
22858 goto selector_leave;
22859 }
Daniel Veillarddee23482008-04-11 12:58:43 +000022860
22861 keySeq = &(matcher->keySeqs[pos]);
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022862 if (*keySeq == NULL) {
22863 if (idc->type == XML_SCHEMA_TYPE_IDC_KEY)
22864 goto selector_key_error;
22865 else
22866 goto selector_leave;
22867 }
Daniel Veillarddee23482008-04-11 12:58:43 +000022868
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022869 for (i = 0; i < nbKeys; i++) {
22870 if ((*keySeq)[i] == NULL) {
22871 /*
22872 * Not qualified, if not all fields did resolve.
22873 */
22874 if (idc->type == XML_SCHEMA_TYPE_IDC_KEY) {
22875 /*
22876 * All fields of a "key" IDC must resolve.
22877 */
22878 goto selector_key_error;
Daniel Veillarddee23482008-04-11 12:58:43 +000022879 }
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022880 goto selector_leave;
22881 }
22882 }
22883 /*
22884 * All fields did resolve.
22885 */
Daniel Veillarddee23482008-04-11 12:58:43 +000022886
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022887 /*
22888 * 4.1 If the {identity-constraint category} is unique(/key),
Rob Richardsc6947bb2008-06-29 15:04:41 +000022889 * then no two members of the �qualified node set� have
22890 * �key-sequences� whose members are pairwise equal, as
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022891 * defined by Equal in [XML Schemas: Datatypes].
22892 *
22893 * Get the IDC binding from the matcher and check for
22894 * duplicate key-sequences.
22895 */
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022896#if 0
22897 bind = xmlSchemaIDCAcquireBinding(vctxt, matcher);
22898#endif
22899 targets = xmlSchemaIDCAcquireTargetList(vctxt, matcher);
Daniel Veillarddee23482008-04-11 12:58:43 +000022900 if ((idc->type != XML_SCHEMA_TYPE_IDC_KEYREF) &&
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022901 (targets->nbItems != 0)) {
Kasimier T. Buchcikbd2a7d12005-02-16 12:27:25 +000022902 xmlSchemaPSVIIDCKeyPtr ckey, bkey, *bkeySeq;
Daniel Veillarddee23482008-04-11 12:58:43 +000022903
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022904 i = 0;
Kasimier T. Buchcikbd2a7d12005-02-16 12:27:25 +000022905 res = 0;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022906 /*
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022907 * Compare the key-sequences, key by key.
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022908 */
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022909 do {
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022910 bkeySeq =
22911 ((xmlSchemaPSVIIDCNodePtr) targets->items[i])->keys;
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022912 for (j = 0; j < nbKeys; j++) {
Kasimier T. Buchcikbd2a7d12005-02-16 12:27:25 +000022913 ckey = (*keySeq)[j];
Daniel Veillarddee23482008-04-11 12:58:43 +000022914 bkey = bkeySeq[j];
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022915 res = xmlSchemaAreValuesEqual(ckey->val, bkey->val);
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022916 if (res == -1) {
22917 return (-1);
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022918 } else if (res == 0) {
22919 /*
22920 * One of the keys differs, so the key-sequence
22921 * won't be equal; get out.
22922 */
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022923 break;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022924 }
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022925 }
22926 if (res == 1) {
22927 /*
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022928 * Duplicate key-sequence found.
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022929 */
22930 break;
22931 }
22932 i++;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022933 } while (i < targets->nbItems);
22934 if (i != targets->nbItems) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000022935 xmlChar *str = NULL, *strB = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000022936 /*
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022937 * TODO: Try to report the key-sequence.
22938 */
Daniel Veillarddee23482008-04-11 12:58:43 +000022939 xmlSchemaCustomErr(ACTXT_CAST vctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000022940 XML_SCHEMAV_CVC_IDC, NULL,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000022941 WXS_BASIC_CAST idc,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000022942 "Duplicate key-sequence %s in %s",
Kasimier T. Buchcikc872afb2005-04-18 10:57:04 +000022943 xmlSchemaFormatIDCKeySequence(vctxt, &str,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000022944 (*keySeq), nbKeys),
22945 xmlSchemaGetIDCDesignation(&strB, idc));
22946 FREE_AND_NULL(str);
22947 FREE_AND_NULL(strB);
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022948 goto selector_leave;
22949 }
22950 }
22951 /*
22952 * Add a node-table item to the IDC binding.
22953 */
22954 ntItem = (xmlSchemaPSVIIDCNodePtr) xmlMalloc(
22955 sizeof(xmlSchemaPSVIIDCNode));
22956 if (ntItem == NULL) {
Daniel Veillarddee23482008-04-11 12:58:43 +000022957 xmlSchemaVErrMemory(NULL,
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022958 "allocating an IDC node-table item", NULL);
22959 xmlFree(*keySeq);
22960 *keySeq = NULL;
22961 return(-1);
Daniel Veillarddee23482008-04-11 12:58:43 +000022962 }
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000022963 memset(ntItem, 0, sizeof(xmlSchemaPSVIIDCNode));
Daniel Veillarddee23482008-04-11 12:58:43 +000022964
22965 /*
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022966 * Store the node-table item in a global list.
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022967 */
22968 if (idc->type != XML_SCHEMA_TYPE_IDC_KEYREF) {
22969 if (xmlSchemaIDCStoreNodeTableItem(vctxt, ntItem) == -1) {
22970 xmlFree(ntItem);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022971 xmlFree(*keySeq);
22972 *keySeq = NULL;
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022973 return (-1);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000022974 }
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000022975 ntItem->nodeQNameID = -1;
22976 } else {
22977 /*
22978 * Save a cached QName for this node on the IDC node, to be
22979 * able to report it, even if the node is not saved.
22980 */
22981 ntItem->nodeQNameID = xmlSchemaVAddNodeQName(vctxt,
22982 vctxt->inode->localName, vctxt->inode->nsName);
22983 if (ntItem->nodeQNameID == -1) {
22984 xmlFree(ntItem);
22985 xmlFree(*keySeq);
22986 *keySeq = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000022987 return (-1);
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000022988 }
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022989 }
22990 /*
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000022991 * Init the node-table item: Save the node, position and
22992 * consume the key-sequence.
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022993 */
22994 ntItem->node = vctxt->node;
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000022995 ntItem->nodeLine = vctxt->inode->nodeLine;
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000022996 ntItem->keys = *keySeq;
22997 *keySeq = NULL;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000022998#if 0
Daniel Veillarddee23482008-04-11 12:58:43 +000022999 if (xmlSchemaIDCAppendNodeTableItem(bind, ntItem) == -1)
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023000#endif
23001 if (xmlSchemaItemListAdd(targets, ntItem) == -1) {
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000023002 if (idc->type == XML_SCHEMA_TYPE_IDC_KEYREF) {
Daniel Veillarddee23482008-04-11 12:58:43 +000023003 /*
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000023004 * Free the item, since keyref items won't be
23005 * put on a global list.
23006 */
23007 xmlFree(ntItem->keys);
23008 xmlFree(ntItem);
23009 }
23010 return (-1);
23011 }
Daniel Veillarddee23482008-04-11 12:58:43 +000023012
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000023013 goto selector_leave;
23014selector_key_error:
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000023015 {
23016 xmlChar *str = NULL;
23017 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000023018 * 4.2.1 (KEY) The �target node set� and the
23019 * �qualified node set� are equal, that is, every
23020 * member of the �target node set� is also a member
23021 * of the �qualified node set� and vice versa.
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000023022 */
Daniel Veillarddee23482008-04-11 12:58:43 +000023023 xmlSchemaCustomErr(ACTXT_CAST vctxt,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000023024 XML_SCHEMAV_CVC_IDC, NULL,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000023025 WXS_BASIC_CAST idc,
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000023026 "Not all fields of %s evaluate to a node",
23027 xmlSchemaGetIDCDesignation(&str, idc), NULL);
23028 FREE_AND_NULL(str);
23029 }
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000023030selector_leave:
23031 /*
23032 * Free the key-sequence if not added to the IDC table.
23033 */
Kasimier T. Buchcik25799ce2005-02-15 14:39:48 +000023034 if ((keySeq != NULL) && (*keySeq != NULL)) {
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000023035 xmlFree(*keySeq);
23036 *keySeq = NULL;
23037 }
23038 } /* if selector */
Daniel Veillarddee23482008-04-11 12:58:43 +000023039
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023040 sto->nbHistory--;
23041
23042deregister_check:
23043 /*
23044 * Deregister state objects if they reach the depth of creation.
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023045 */
Kasimier T. Buchcikbd2a7d12005-02-16 12:27:25 +000023046 if ((sto->nbHistory == 0) && (sto->depth == depth)) {
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023047#ifdef DEBUG_IDC
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023048 xmlGenericError(xmlGenericErrorContext, "IDC: STO pop '%s'\n",
23049 sto->sel->xpath);
23050#endif
23051 if (vctxt->xpathStates != sto) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000023052 VERROR_INT("xmlSchemaXPathProcessHistory",
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023053 "The state object to be removed is not the first "
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000023054 "in the list");
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023055 }
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023056 nextsto = sto->next;
23057 /*
23058 * Unlink from the list of active XPath state objects.
23059 */
23060 vctxt->xpathStates = sto->next;
23061 sto->next = vctxt->xpathStatePool;
23062 /*
23063 * Link it to the pool of reusable state objects.
23064 */
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000023065 vctxt->xpathStatePool = sto;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023066 sto = nextsto;
23067 } else
23068 sto = sto->next;
23069 } /* while (sto != NULL) */
23070 return (0);
23071}
23072
23073/**
23074 * xmlSchemaIDCRegisterMatchers:
23075 * @vctxt: the WXS validation context
23076 * @elemDecl: the element declaration
23077 *
23078 * Creates helper objects to evaluate IDC selectors/fields
23079 * successively.
23080 *
23081 * Returns 0 if OK and -1 on internal errors.
23082 */
23083static int
23084xmlSchemaIDCRegisterMatchers(xmlSchemaValidCtxtPtr vctxt,
23085 xmlSchemaElementPtr elemDecl)
23086{
23087 xmlSchemaIDCMatcherPtr matcher, last = NULL;
23088 xmlSchemaIDCPtr idc, refIdc;
23089 xmlSchemaIDCAugPtr aidc;
Daniel Veillarddee23482008-04-11 12:58:43 +000023090
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023091 idc = (xmlSchemaIDCPtr) elemDecl->idcs;
23092 if (idc == NULL)
23093 return (0);
Daniel Veillarddee23482008-04-11 12:58:43 +000023094
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023095#ifdef DEBUG_IDC
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023096 {
23097 xmlChar *str = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000023098 xmlGenericError(xmlGenericErrorContext,
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000023099 "IDC: REGISTER on %s, depth %d\n",
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000023100 (char *) xmlSchemaFormatQName(&str, vctxt->inode->nsName,
23101 vctxt->inode->localName), vctxt->depth);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023102 FREE_AND_NULL(str)
23103 }
23104#endif
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000023105 if (vctxt->inode->idcMatchers != NULL) {
23106 VERROR_INT("xmlSchemaIDCRegisterMatchers",
23107 "The chain of IDC matchers is expected to be empty");
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023108 return (-1);
23109 }
23110 do {
23111 if (idc->type == XML_SCHEMA_TYPE_IDC_KEYREF) {
23112 /*
23113 * Since IDCs bubbles are expensive we need to know the
23114 * depth at which the bubbles should stop; this will be
23115 * the depth of the top-most keyref IDC. If no keyref
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023116 * references a key/unique IDC, the keyrefDepth will
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023117 * be -1, indicating that no bubbles are needed.
23118 */
23119 refIdc = (xmlSchemaIDCPtr) idc->ref->item;
23120 if (refIdc != NULL) {
23121 /*
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023122 * Remember that we have keyrefs on this node.
23123 */
23124 vctxt->inode->hasKeyrefs = 1;
23125 /*
23126 * Lookup the referenced augmented IDC info.
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023127 */
23128 aidc = vctxt->aidcs;
23129 while (aidc != NULL) {
23130 if (aidc->def == refIdc)
23131 break;
23132 aidc = aidc->next;
23133 }
23134 if (aidc == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000023135 VERROR_INT("xmlSchemaIDCRegisterMatchers",
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023136 "Could not find an augmented IDC item for an IDC "
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000023137 "definition");
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023138 return (-1);
Daniel Veillarddee23482008-04-11 12:58:43 +000023139 }
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023140 if ((aidc->keyrefDepth == -1) ||
23141 (vctxt->depth < aidc->keyrefDepth))
23142 aidc->keyrefDepth = vctxt->depth;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023143 }
23144 }
23145 /*
23146 * Lookup the augmented IDC item for the IDC definition.
23147 */
23148 aidc = vctxt->aidcs;
23149 while (aidc != NULL) {
23150 if (aidc->def == idc)
23151 break;
23152 aidc = aidc->next;
23153 }
23154 if (aidc == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000023155 VERROR_INT("xmlSchemaIDCRegisterMatchers",
23156 "Could not find an augmented IDC item for an IDC definition");
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023157 return (-1);
23158 }
23159 /*
23160 * Create an IDC matcher for every IDC definition.
23161 */
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000023162 if (vctxt->idcMatcherCache != NULL) {
23163 /*
23164 * Reuse a cached matcher.
23165 */
23166 matcher = vctxt->idcMatcherCache;
23167 vctxt->idcMatcherCache = matcher->nextCached;
23168 matcher->nextCached = NULL;
23169 } else {
Daniel Veillarddee23482008-04-11 12:58:43 +000023170 matcher = (xmlSchemaIDCMatcherPtr)
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000023171 xmlMalloc(sizeof(xmlSchemaIDCMatcher));
23172 if (matcher == NULL) {
Daniel Veillarddee23482008-04-11 12:58:43 +000023173 xmlSchemaVErrMemory(vctxt,
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000023174 "allocating an IDC matcher", NULL);
23175 return (-1);
23176 }
23177 memset(matcher, 0, sizeof(xmlSchemaIDCMatcher));
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023178 }
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023179 if (last == NULL)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000023180 vctxt->inode->idcMatchers = matcher;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023181 else
23182 last->next = matcher;
23183 last = matcher;
23184
23185 matcher->type = IDC_MATCHER;
Daniel Veillarddee23482008-04-11 12:58:43 +000023186 matcher->depth = vctxt->depth;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023187 matcher->aidc = aidc;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023188 matcher->idcType = aidc->def->type;
Daniel Veillarddee23482008-04-11 12:58:43 +000023189#ifdef DEBUG_IDC
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023190 xmlGenericError(xmlGenericErrorContext, "IDC: register matcher\n");
Daniel Veillarddee23482008-04-11 12:58:43 +000023191#endif
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023192 /*
Daniel Veillarddee23482008-04-11 12:58:43 +000023193 * Init the automaton state object.
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023194 */
Daniel Veillarddee23482008-04-11 12:58:43 +000023195 if (xmlSchemaIDCAddStateObject(vctxt, matcher,
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000023196 idc->selector, XPATH_STATE_OBJ_TYPE_IDC_SELECTOR) == -1)
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023197 return (-1);
23198
23199 idc = idc->next;
23200 } while (idc != NULL);
23201 return (0);
23202}
23203
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023204static int
23205xmlSchemaIDCFillNodeTables(xmlSchemaValidCtxtPtr vctxt,
23206 xmlSchemaNodeInfoPtr ielem)
23207{
23208 xmlSchemaPSVIIDCBindingPtr bind;
23209 int res, i, j, k, nbTargets, nbFields, nbDupls, nbNodeTable;
23210 xmlSchemaPSVIIDCKeyPtr *keys, *ntkeys;
23211 xmlSchemaPSVIIDCNodePtr *targets, *dupls;
Daniel Veillarddee23482008-04-11 12:58:43 +000023212
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023213 xmlSchemaIDCMatcherPtr matcher = ielem->idcMatchers;
23214 /* vctxt->createIDCNodeTables */
23215 while (matcher != NULL) {
23216 /*
23217 * Skip keyref IDCs and empty IDC target-lists.
23218 */
23219 if ((matcher->aidc->def->type == XML_SCHEMA_TYPE_IDC_KEYREF) ||
23220 WXS_ILIST_IS_EMPTY(matcher->targets))
23221 {
23222 matcher = matcher->next;
23223 continue;
23224 }
23225 /*
23226 * If we _want_ the IDC node-table to be created in any case
23227 * then do so. Otherwise create them only if keyrefs need them.
23228 */
23229 if ((! vctxt->createIDCNodeTables) &&
23230 ((matcher->aidc->keyrefDepth == -1) ||
23231 (matcher->aidc->keyrefDepth > vctxt->depth)))
23232 {
23233 matcher = matcher->next;
23234 continue;
23235 }
23236 /*
23237 * Get/create the IDC binding on this element for the IDC definition.
23238 */
23239 bind = xmlSchemaIDCAcquireBinding(vctxt, matcher);
23240
23241 if (! WXS_ILIST_IS_EMPTY(bind->dupls)) {
23242 dupls = (xmlSchemaPSVIIDCNodePtr *) bind->dupls->items;
23243 nbDupls = bind->dupls->nbItems;
23244 } else {
23245 dupls = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000023246 nbDupls = 0;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023247 }
23248 if (bind->nodeTable != NULL) {
23249 nbNodeTable = bind->nbNodes;
23250 } else {
23251 nbNodeTable = 0;
23252 }
23253
23254 if ((nbNodeTable == 0) && (nbDupls == 0)) {
23255 /*
23256 * Transfer all IDC target-nodes to the IDC node-table.
23257 */
23258 bind->nodeTable =
Daniel Veillarddee23482008-04-11 12:58:43 +000023259 (xmlSchemaPSVIIDCNodePtr *) matcher->targets->items;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023260 bind->sizeNodes = matcher->targets->sizeItems;
23261 bind->nbNodes = matcher->targets->nbItems;
23262
23263 matcher->targets->items = NULL;
23264 matcher->targets->sizeItems = 0;
Daniel Veillarddee23482008-04-11 12:58:43 +000023265 matcher->targets->nbItems = 0;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023266 } else {
23267 /*
23268 * Compare the key-sequences and add to the IDC node-table.
23269 */
23270 nbTargets = matcher->targets->nbItems;
Daniel Veillarddee23482008-04-11 12:58:43 +000023271 targets = (xmlSchemaPSVIIDCNodePtr *) matcher->targets->items;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023272 nbFields = matcher->aidc->def->nbFields;
23273 i = 0;
23274 do {
23275 keys = targets[i]->keys;
Daniel Veillarddee23482008-04-11 12:58:43 +000023276 if (nbDupls) {
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023277 /*
23278 * Search in already found duplicates first.
23279 */
23280 j = 0;
Daniel Veillarddee23482008-04-11 12:58:43 +000023281 do {
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023282 if (nbFields == 1) {
23283 res = xmlSchemaAreValuesEqual(keys[0]->val,
23284 dupls[j]->keys[0]->val);
23285 if (res == -1)
23286 goto internal_error;
23287 if (res == 1) {
23288 /*
23289 * Equal key-sequence.
23290 */
23291 goto next_target;
23292 }
23293 } else {
23294 res = 0;
23295 ntkeys = dupls[j]->keys;
23296 for (k = 0; k < nbFields; k++) {
23297 res = xmlSchemaAreValuesEqual(keys[k]->val,
23298 ntkeys[k]->val);
23299 if (res == -1)
23300 goto internal_error;
23301 if (res == 0) {
23302 /*
23303 * One of the keys differs.
23304 */
23305 break;
23306 }
23307 }
23308 if (res == 1) {
23309 /*
23310 * Equal key-sequence found.
23311 */
23312 goto next_target;
23313 }
23314 }
23315 j++;
Daniel Veillarddee23482008-04-11 12:58:43 +000023316 } while (j < nbDupls);
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023317 }
23318 if (nbNodeTable) {
23319 j = 0;
Daniel Veillarddee23482008-04-11 12:58:43 +000023320 do {
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023321 if (nbFields == 1) {
23322 res = xmlSchemaAreValuesEqual(keys[0]->val,
23323 bind->nodeTable[j]->keys[0]->val);
23324 if (res == -1)
23325 goto internal_error;
23326 if (res == 0) {
23327 /*
23328 * The key-sequence differs.
23329 */
23330 goto next_node_table_entry;
23331 }
23332 } else {
23333 res = 0;
23334 ntkeys = bind->nodeTable[j]->keys;
23335 for (k = 0; k < nbFields; k++) {
23336 res = xmlSchemaAreValuesEqual(keys[k]->val,
23337 ntkeys[k]->val);
23338 if (res == -1)
23339 goto internal_error;
23340 if (res == 0) {
23341 /*
23342 * One of the keys differs.
23343 */
23344 goto next_node_table_entry;
23345 }
23346 }
Daniel Veillarddee23482008-04-11 12:58:43 +000023347 }
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023348 /*
23349 * Add the duplicate to the list of duplicates.
23350 */
23351 if (bind->dupls == NULL) {
23352 bind->dupls = xmlSchemaItemListCreate();
23353 if (bind->dupls == NULL)
23354 goto internal_error;
Daniel Veillarddee23482008-04-11 12:58:43 +000023355 }
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023356 if (xmlSchemaItemListAdd(bind->dupls, bind->nodeTable[j]) == -1)
23357 goto internal_error;
23358 /*
23359 * Remove the duplicate entry from the IDC node-table.
23360 */
23361 bind->nodeTable[j] = bind->nodeTable[bind->nbNodes -1];
23362 bind->nbNodes--;
23363
23364 goto next_target;
23365
23366next_node_table_entry:
23367 j++;
23368 } while (j < nbNodeTable);
23369 }
23370 /*
23371 * If everything is fine, then add the IDC target-node to
23372 * the IDC node-table.
23373 */
23374 if (xmlSchemaIDCAppendNodeTableItem(bind, targets[i]) == -1)
23375 goto internal_error;
23376
23377next_target:
23378 i++;
23379 } while (i < nbTargets);
23380 }
23381 matcher = matcher->next;
23382 }
23383 return(0);
23384
23385internal_error:
23386 return(-1);
23387}
23388
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023389/**
Daniel Veillarddee23482008-04-11 12:58:43 +000023390 * xmlSchemaBubbleIDCNodeTables:
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023391 * @depth: the current tree depth
23392 *
Daniel Veillarddee23482008-04-11 12:58:43 +000023393 * Merges IDC bindings of an element at @depth into the corresponding IDC
23394 * bindings of its parent element. If a duplicate note-table entry is found,
23395 * both, the parent node-table entry and child entry are discarded from the
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023396 * node-table of the parent.
23397 *
23398 * Returns 0 if OK and -1 on internal errors.
23399 */
23400static int
23401xmlSchemaBubbleIDCNodeTables(xmlSchemaValidCtxtPtr vctxt)
23402{
23403 xmlSchemaPSVIIDCBindingPtr bind; /* IDC bindings of the current node. */
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023404 xmlSchemaPSVIIDCBindingPtr *parTable, parBind = NULL; /* parent IDC bindings. */
23405 xmlSchemaPSVIIDCNodePtr node, parNode = NULL, *dupls, *parNodes; /* node-table entries. */
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023406 xmlSchemaIDCAugPtr aidc;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023407 int i, j, k, ret = 0, nbFields, oldNum, oldDupls;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023408
Daniel Veillarddee23482008-04-11 12:58:43 +000023409 bind = vctxt->inode->idcTable;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023410 if (bind == NULL) {
23411 /* Fine, no table, no bubbles. */
23412 return (0);
23413 }
Daniel Veillarddee23482008-04-11 12:58:43 +000023414
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023415 parTable = &(vctxt->elemInfos[vctxt->depth -1]->idcTable);
23416 /*
23417 * Walk all bindings; create new or add to existing bindings.
23418 * Remove duplicate key-sequences.
23419 */
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023420 while (bind != NULL) {
Daniel Veillarddee23482008-04-11 12:58:43 +000023421
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023422 if ((bind->nbNodes == 0) && WXS_ILIST_IS_EMPTY(bind->dupls))
23423 goto next_binding;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023424 /*
23425 * Check if the key/unique IDC table needs to be bubbled.
23426 */
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023427 if (! vctxt->createIDCNodeTables) {
23428 aidc = vctxt->aidcs;
23429 do {
23430 if (aidc->def == bind->definition) {
Daniel Veillarddee23482008-04-11 12:58:43 +000023431 if ((aidc->keyrefDepth == -1) ||
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023432 (aidc->keyrefDepth >= vctxt->depth)) {
23433 goto next_binding;
23434 }
23435 break;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023436 }
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023437 aidc = aidc->next;
23438 } while (aidc != NULL);
23439 }
Kasimier T. Buchcik0a598522005-01-31 17:02:07 +000023440
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023441 if (parTable != NULL)
23442 parBind = *parTable;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023443 /*
23444 * Search a matching parent binding for the
23445 * IDC definition.
23446 */
Daniel Veillarddee23482008-04-11 12:58:43 +000023447 while (parBind != NULL) {
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023448 if (parBind->definition == bind->definition)
23449 break;
23450 parBind = parBind->next;
23451 }
23452
23453 if (parBind != NULL) {
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023454 /*
Daniel Veillarddee23482008-04-11 12:58:43 +000023455 * Compare every node-table entry of the child node,
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023456 * i.e. the key-sequence within, ...
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023457 */
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023458 oldNum = parBind->nbNodes; /* Skip newly added items. */
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023459
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023460 if (! WXS_ILIST_IS_EMPTY(parBind->dupls)) {
23461 oldDupls = parBind->dupls->nbItems;
23462 dupls = (xmlSchemaPSVIIDCNodePtr *) parBind->dupls->items;
23463 } else {
23464 dupls = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000023465 oldDupls = 0;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023466 }
Daniel Veillarddee23482008-04-11 12:58:43 +000023467
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023468 parNodes = parBind->nodeTable;
23469 nbFields = bind->definition->nbFields;
Daniel Veillarddee23482008-04-11 12:58:43 +000023470
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023471 for (i = 0; i < bind->nbNodes; i++) {
23472 node = bind->nodeTable[i];
23473 if (node == NULL)
23474 continue;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023475 /*
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023476 * ...with every key-sequence of the parent node, already
23477 * evaluated to be a duplicate key-sequence.
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023478 */
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023479 if (oldDupls) {
Daniel Veillarddee23482008-04-11 12:58:43 +000023480 j = 0;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023481 while (j < oldDupls) {
23482 if (nbFields == 1) {
23483 ret = xmlSchemaAreValuesEqual(
23484 node->keys[0]->val,
23485 dupls[j]->keys[0]->val);
23486 if (ret == -1)
23487 goto internal_error;
23488 if (ret == 0) {
23489 j++;
23490 continue;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023491 }
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023492 } else {
23493 parNode = dupls[j];
23494 for (k = 0; k < nbFields; k++) {
23495 ret = xmlSchemaAreValuesEqual(
23496 node->keys[k]->val,
23497 parNode->keys[k]->val);
23498 if (ret == -1)
23499 goto internal_error;
23500 if (ret == 0)
23501 break;
23502 }
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023503 }
23504 if (ret == 1)
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023505 /* Duplicate found. */
23506 break;
23507 j++;
23508 }
23509 if (j != oldDupls) {
23510 /* Duplicate found. Skip this entry. */
23511 continue;
23512 }
Daniel Veillarddee23482008-04-11 12:58:43 +000023513 }
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023514 /*
23515 * ... and with every key-sequence of the parent node.
23516 */
23517 if (oldNum) {
Daniel Veillarddee23482008-04-11 12:58:43 +000023518 j = 0;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023519 while (j < oldNum) {
Kasimier T. Buchcikf39e8d12005-11-30 11:03:24 +000023520 parNode = parNodes[j];
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023521 if (nbFields == 1) {
23522 ret = xmlSchemaAreValuesEqual(
23523 node->keys[0]->val,
Kasimier T. Buchcikf39e8d12005-11-30 11:03:24 +000023524 parNode->keys[0]->val);
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023525 if (ret == -1)
23526 goto internal_error;
23527 if (ret == 0) {
23528 j++;
23529 continue;
23530 }
Daniel Veillarddee23482008-04-11 12:58:43 +000023531 } else {
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023532 for (k = 0; k < nbFields; k++) {
23533 ret = xmlSchemaAreValuesEqual(
23534 node->keys[k]->val,
23535 parNode->keys[k]->val);
23536 if (ret == -1)
23537 goto internal_error;
23538 if (ret == 0)
23539 break;
23540 }
23541 }
23542 if (ret == 1)
23543 /* Duplicate found. */
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023544 break;
23545 j++;
23546 }
23547 if (j != oldNum) {
23548 /*
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023549 * Handle duplicates. Move the duplicate in
23550 * the parent's node-table to the list of
23551 * duplicates.
Daniel Veillarddee23482008-04-11 12:58:43 +000023552 */
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023553 oldNum--;
23554 parBind->nbNodes--;
23555 /*
23556 * Move last old item to pos of duplicate.
23557 */
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023558 parNodes[j] = parNodes[oldNum];
Daniel Veillarddee23482008-04-11 12:58:43 +000023559
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023560 if (parBind->nbNodes != oldNum) {
23561 /*
Daniel Veillarddee23482008-04-11 12:58:43 +000023562 * If new items exist, move last new item to
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023563 * last of old items.
23564 */
Daniel Veillarddee23482008-04-11 12:58:43 +000023565 parNodes[oldNum] =
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023566 parNodes[parBind->nbNodes];
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023567 }
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023568 if (parBind->dupls == NULL) {
23569 parBind->dupls = xmlSchemaItemListCreate();
23570 if (parBind->dupls == NULL)
23571 goto internal_error;
23572 }
Daniel Veillarddee23482008-04-11 12:58:43 +000023573 xmlSchemaItemListAdd(parBind->dupls, parNode);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023574 } else {
23575 /*
Daniel Veillarddee23482008-04-11 12:58:43 +000023576 * Add the node-table entry (node and key-sequence) of
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023577 * the child node to the node table of the parent node.
23578 */
Daniel Veillarddee23482008-04-11 12:58:43 +000023579 if (parBind->nodeTable == NULL) {
23580 parBind->nodeTable = (xmlSchemaPSVIIDCNodePtr *)
Kasimier T. Buchcikb34ad1b2005-03-21 20:10:31 +000023581 xmlMalloc(10 * sizeof(xmlSchemaPSVIIDCNodePtr));
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023582 if (parBind->nodeTable == NULL) {
Daniel Veillarddee23482008-04-11 12:58:43 +000023583 xmlSchemaVErrMemory(NULL,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023584 "allocating IDC list of node-table items", NULL);
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023585 goto internal_error;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023586 }
23587 parBind->sizeNodes = 1;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023588 } else if (parBind->nbNodes >= parBind->sizeNodes) {
Kasimier T. Buchcikb34ad1b2005-03-21 20:10:31 +000023589 parBind->sizeNodes *= 2;
Daniel Veillarddee23482008-04-11 12:58:43 +000023590 parBind->nodeTable = (xmlSchemaPSVIIDCNodePtr *)
23591 xmlRealloc(parBind->nodeTable, parBind->sizeNodes *
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023592 sizeof(xmlSchemaPSVIIDCNodePtr));
23593 if (parBind->nodeTable == NULL) {
Daniel Veillarddee23482008-04-11 12:58:43 +000023594 xmlSchemaVErrMemory(NULL,
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023595 "re-allocating IDC list of node-table items", NULL);
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023596 goto internal_error;
Daniel Veillarddee23482008-04-11 12:58:43 +000023597 }
Kasimier T. Buchcik132ba5f2005-11-28 12:32:24 +000023598 }
23599 parNodes = parBind->nodeTable;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023600 /*
23601 * Append the new node-table entry to the 'new node-table
23602 * entries' section.
23603 */
Kasimier T. Buchcik132ba5f2005-11-28 12:32:24 +000023604 parNodes[parBind->nbNodes++] = node;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023605 }
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023606
Daniel Veillarddee23482008-04-11 12:58:43 +000023607 }
23608
23609 }
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023610 } else {
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023611 /*
23612 * No binding for the IDC was found: create a new one and
23613 * copy all node-tables.
23614 */
23615 parBind = xmlSchemaIDCNewBinding(bind->definition);
23616 if (parBind == NULL)
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023617 goto internal_error;
Daniel Veillarddee23482008-04-11 12:58:43 +000023618
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023619 /*
23620 * TODO: Hmm, how to optimize the initial number of
23621 * allocated entries?
23622 */
23623 if (bind->nbNodes != 0) {
23624 /*
23625 * Add all IDC node-table entries.
23626 */
23627 if (! vctxt->psviExposeIDCNodeTables) {
23628 /*
23629 * Just move the entries.
23630 * NOTE: this is quite save here, since
23631 * all the keyref lookups have already been
23632 * performed.
23633 */
23634 parBind->nodeTable = bind->nodeTable;
23635 bind->nodeTable = NULL;
23636 parBind->sizeNodes = bind->sizeNodes;
23637 bind->sizeNodes = 0;
23638 parBind->nbNodes = bind->nbNodes;
23639 bind->nbNodes = 0;
23640 } else {
23641 /*
23642 * Copy the entries.
23643 */
Daniel Veillarddee23482008-04-11 12:58:43 +000023644 parBind->nodeTable = (xmlSchemaPSVIIDCNodePtr *)
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023645 xmlMalloc(bind->nbNodes *
23646 sizeof(xmlSchemaPSVIIDCNodePtr));
23647 if (parBind->nodeTable == NULL) {
Daniel Veillarddee23482008-04-11 12:58:43 +000023648 xmlSchemaVErrMemory(NULL,
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023649 "allocating an array of IDC node-table "
23650 "items", NULL);
23651 xmlSchemaIDCFreeBinding(parBind);
23652 goto internal_error;
23653 }
23654 parBind->sizeNodes = bind->nbNodes;
23655 parBind->nbNodes = bind->nbNodes;
23656 memcpy(parBind->nodeTable, bind->nodeTable,
23657 bind->nbNodes * sizeof(xmlSchemaPSVIIDCNodePtr));
23658 }
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023659 }
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023660 if (bind->dupls) {
23661 /*
23662 * Move the duplicates.
23663 */
23664 if (parBind->dupls != NULL)
23665 xmlSchemaItemListFree(parBind->dupls);
23666 parBind->dupls = bind->dupls;
Daniel Veillarddee23482008-04-11 12:58:43 +000023667 bind->dupls = NULL;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023668 }
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023669 if (*parTable == NULL)
23670 *parTable = parBind;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023671 else {
23672 parBind->next = *parTable;
23673 *parTable = parBind;
Daniel Veillarddee23482008-04-11 12:58:43 +000023674 }
23675 }
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023676
23677next_binding:
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023678 bind = bind->next;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023679 }
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023680 return (0);
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023681
23682internal_error:
23683 return(-1);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023684}
23685
23686/**
23687 * xmlSchemaCheckCVCIDCKeyRef:
23688 * @vctxt: the WXS validation context
23689 * @elemDecl: the element declaration
23690 *
23691 * Check the cvc-idc-keyref constraints.
23692 */
23693static int
23694xmlSchemaCheckCVCIDCKeyRef(xmlSchemaValidCtxtPtr vctxt)
23695{
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023696 xmlSchemaIDCMatcherPtr matcher;
23697 xmlSchemaPSVIIDCBindingPtr bind;
Daniel Veillarddee23482008-04-11 12:58:43 +000023698
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023699 matcher = vctxt->inode->idcMatchers;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023700 /*
23701 * Find a keyref.
23702 */
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023703 while (matcher != NULL) {
23704 if ((matcher->idcType == XML_SCHEMA_TYPE_IDC_KEYREF) &&
23705 matcher->targets &&
23706 matcher->targets->nbItems)
23707 {
23708 int i, j, k, res, nbFields, hasDupls;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023709 xmlSchemaPSVIIDCKeyPtr *refKeys, *keys;
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000023710 xmlSchemaPSVIIDCNodePtr refNode = NULL;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023711
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023712 nbFields = matcher->aidc->def->nbFields;
23713
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023714 /*
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023715 * Find the IDC node-table for the referenced IDC key/unique.
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023716 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000023717 bind = vctxt->inode->idcTable;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023718 while (bind != NULL) {
Daniel Veillarddee23482008-04-11 12:58:43 +000023719 if ((xmlSchemaIDCPtr) matcher->aidc->def->ref->item ==
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023720 bind->definition)
23721 break;
23722 bind = bind->next;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023723 }
23724 hasDupls = (bind && bind->dupls && bind->dupls->nbItems) ? 1 : 0;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023725 /*
23726 * Search for a matching key-sequences.
23727 */
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023728 for (i = 0; i < matcher->targets->nbItems; i++) {
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023729 res = 0;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023730 refNode = matcher->targets->items[i];
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000023731 if (bind != NULL) {
23732 refKeys = refNode->keys;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023733 for (j = 0; j < bind->nbNodes; j++) {
23734 keys = bind->nodeTable[j]->keys;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023735 for (k = 0; k < nbFields; k++) {
23736 res = xmlSchemaAreValuesEqual(keys[k]->val,
23737 refKeys[k]->val);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023738 if (res == 0)
23739 break;
23740 else if (res == -1) {
23741 return (-1);
23742 }
23743 }
23744 if (res == 1) {
23745 /*
23746 * Match found.
23747 */
23748 break;
23749 }
23750 }
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023751 if ((res == 0) && hasDupls) {
23752 /*
23753 * Search in duplicates
23754 */
23755 for (j = 0; j < bind->dupls->nbItems; j++) {
23756 keys = ((xmlSchemaPSVIIDCNodePtr)
23757 bind->dupls->items[j])->keys;
23758 for (k = 0; k < nbFields; k++) {
23759 res = xmlSchemaAreValuesEqual(keys[k]->val,
23760 refKeys[k]->val);
23761 if (res == 0)
23762 break;
23763 else if (res == -1) {
23764 return (-1);
23765 }
23766 }
23767 if (res == 1) {
23768 /*
23769 * Match in duplicates found.
23770 */
23771 xmlChar *str = NULL, *strB = NULL;
23772 xmlSchemaKeyrefErr(vctxt,
23773 XML_SCHEMAV_CVC_IDC, refNode,
23774 (xmlSchemaTypePtr) matcher->aidc->def,
23775 "More than one match found for "
23776 "key-sequence %s of keyref '%s'",
23777 xmlSchemaFormatIDCKeySequence(vctxt, &str,
23778 refNode->keys, nbFields),
23779 xmlSchemaGetComponentQName(&strB,
23780 matcher->aidc->def));
23781 FREE_AND_NULL(str);
23782 FREE_AND_NULL(strB);
23783 break;
23784 }
23785 }
23786 }
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023787 }
Daniel Veillarddee23482008-04-11 12:58:43 +000023788
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023789 if (res == 0) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000023790 xmlChar *str = NULL, *strB = NULL;
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000023791 xmlSchemaKeyrefErr(vctxt,
23792 XML_SCHEMAV_CVC_IDC, refNode,
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023793 (xmlSchemaTypePtr) matcher->aidc->def,
23794 "No match found for key-sequence %s of keyref '%s'",
Kasimier T. Buchcikc872afb2005-04-18 10:57:04 +000023795 xmlSchemaFormatIDCKeySequence(vctxt, &str,
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023796 refNode->keys, nbFields),
23797 xmlSchemaGetComponentQName(&strB, matcher->aidc->def));
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000023798 FREE_AND_NULL(str);
23799 FREE_AND_NULL(strB);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023800 }
23801 }
23802 }
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023803 matcher = matcher->next;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023804 }
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023805 /* TODO: Return an error if any error encountered. */
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023806 return (0);
23807}
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023808
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000023809/************************************************************************
23810 * *
23811 * XML Reader validation code *
23812 * *
23813 ************************************************************************/
23814
23815static xmlSchemaAttrInfoPtr
23816xmlSchemaGetFreshAttrInfo(xmlSchemaValidCtxtPtr vctxt)
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023817{
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000023818 xmlSchemaAttrInfoPtr iattr;
23819 /*
23820 * Grow/create list of attribute infos.
23821 */
23822 if (vctxt->attrInfos == NULL) {
23823 vctxt->attrInfos = (xmlSchemaAttrInfoPtr *)
23824 xmlMalloc(sizeof(xmlSchemaAttrInfoPtr));
23825 vctxt->sizeAttrInfos = 1;
23826 if (vctxt->attrInfos == NULL) {
23827 xmlSchemaVErrMemory(vctxt,
23828 "allocating attribute info list", NULL);
23829 return (NULL);
23830 }
23831 } else if (vctxt->sizeAttrInfos <= vctxt->nbAttrInfos) {
23832 vctxt->sizeAttrInfos++;
23833 vctxt->attrInfos = (xmlSchemaAttrInfoPtr *)
23834 xmlRealloc(vctxt->attrInfos,
23835 vctxt->sizeAttrInfos * sizeof(xmlSchemaAttrInfoPtr));
23836 if (vctxt->attrInfos == NULL) {
23837 xmlSchemaVErrMemory(vctxt,
23838 "re-allocating attribute info list", NULL);
23839 return (NULL);
23840 }
23841 } else {
23842 iattr = vctxt->attrInfos[vctxt->nbAttrInfos++];
23843 if (iattr->localName != NULL) {
23844 VERROR_INT("xmlSchemaGetFreshAttrInfo",
23845 "attr info not cleared");
23846 return (NULL);
23847 }
23848 iattr->nodeType = XML_ATTRIBUTE_NODE;
23849 return (iattr);
23850 }
23851 /*
23852 * Create an attribute info.
23853 */
23854 iattr = (xmlSchemaAttrInfoPtr)
23855 xmlMalloc(sizeof(xmlSchemaAttrInfo));
23856 if (iattr == NULL) {
23857 xmlSchemaVErrMemory(vctxt, "creating new attribute info", NULL);
23858 return (NULL);
23859 }
23860 memset(iattr, 0, sizeof(xmlSchemaAttrInfo));
23861 iattr->nodeType = XML_ATTRIBUTE_NODE;
23862 vctxt->attrInfos[vctxt->nbAttrInfos++] = iattr;
23863
23864 return (iattr);
23865}
23866
23867static int
23868xmlSchemaValidatorPushAttribute(xmlSchemaValidCtxtPtr vctxt,
23869 xmlNodePtr attrNode,
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000023870 int nodeLine,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000023871 const xmlChar *localName,
Daniel Veillarddee23482008-04-11 12:58:43 +000023872 const xmlChar *nsName,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000023873 int ownedNames,
23874 xmlChar *value,
23875 int ownedValue)
23876{
23877 xmlSchemaAttrInfoPtr attr;
23878
23879 attr = xmlSchemaGetFreshAttrInfo(vctxt);
23880 if (attr == NULL) {
23881 VERROR_INT("xmlSchemaPushAttribute",
23882 "calling xmlSchemaGetFreshAttrInfo()");
23883 return (-1);
23884 }
23885 attr->node = attrNode;
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000023886 attr->nodeLine = nodeLine;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000023887 attr->state = XML_SCHEMAS_ATTR_UNKNOWN;
23888 attr->localName = localName;
23889 attr->nsName = nsName;
23890 if (ownedNames)
23891 attr->flags |= XML_SCHEMA_NODE_INFO_FLAG_OWNED_NAMES;
23892 /*
23893 * Evaluate if it's an XSI attribute.
23894 */
23895 if (nsName != NULL) {
23896 if (xmlStrEqual(localName, BAD_CAST "nil")) {
23897 if (xmlStrEqual(attr->nsName, xmlSchemaInstanceNs)) {
Daniel Veillarddee23482008-04-11 12:58:43 +000023898 attr->metaType = XML_SCHEMA_ATTR_INFO_META_XSI_NIL;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000023899 }
23900 } else if (xmlStrEqual(localName, BAD_CAST "type")) {
23901 if (xmlStrEqual(attr->nsName, xmlSchemaInstanceNs)) {
23902 attr->metaType = XML_SCHEMA_ATTR_INFO_META_XSI_TYPE;
23903 }
23904 } else if (xmlStrEqual(localName, BAD_CAST "schemaLocation")) {
23905 if (xmlStrEqual(attr->nsName, xmlSchemaInstanceNs)) {
23906 attr->metaType = XML_SCHEMA_ATTR_INFO_META_XSI_SCHEMA_LOC;
23907 }
23908 } else if (xmlStrEqual(localName, BAD_CAST "noNamespaceSchemaLocation")) {
23909 if (xmlStrEqual(attr->nsName, xmlSchemaInstanceNs)) {
23910 attr->metaType = XML_SCHEMA_ATTR_INFO_META_XSI_NO_NS_SCHEMA_LOC;
23911 }
23912 } else if (xmlStrEqual(attr->nsName, xmlNamespaceNs)) {
23913 attr->metaType = XML_SCHEMA_ATTR_INFO_META_XMLNS;
23914 }
23915 }
23916 attr->value = value;
23917 if (ownedValue)
23918 attr->flags |= XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES;
23919 if (attr->metaType != 0)
23920 attr->state = XML_SCHEMAS_ATTR_META;
23921 return (0);
23922}
23923
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000023924/**
23925 * xmlSchemaClearElemInfo:
23926 * @vctxt: the WXS validation context
23927 * @ielem: the element information item
23928 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000023929static void
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000023930xmlSchemaClearElemInfo(xmlSchemaValidCtxtPtr vctxt,
23931 xmlSchemaNodeInfoPtr ielem)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000023932{
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023933 ielem->hasKeyrefs = 0;
Kasimier T. Buchcik65c2f1d2005-10-17 12:39:58 +000023934 ielem->appliedXPath = 0;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000023935 if (ielem->flags & XML_SCHEMA_NODE_INFO_FLAG_OWNED_NAMES) {
23936 FREE_AND_NULL(ielem->localName);
23937 FREE_AND_NULL(ielem->nsName);
23938 } else {
23939 ielem->localName = NULL;
23940 ielem->nsName = NULL;
23941 }
23942 if (ielem->flags & XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES) {
23943 FREE_AND_NULL(ielem->value);
23944 } else {
23945 ielem->value = NULL;
23946 }
23947 if (ielem->val != NULL) {
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023948 /*
23949 * PSVI TODO: Be careful not to free it when the value is
23950 * exposed via PSVI.
23951 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000023952 xmlSchemaFreeValue(ielem->val);
23953 ielem->val = NULL;
23954 }
23955 if (ielem->idcMatchers != NULL) {
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023956 /*
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000023957 * REVISIT OPTIMIZE TODO: Use a pool of IDC matchers.
23958 * Does it work?
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023959 */
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000023960 xmlSchemaIDCReleaseMatcherList(vctxt, ielem->idcMatchers);
23961#if 0
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000023962 xmlSchemaIDCFreeMatcherList(ielem->idcMatchers);
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000023963#endif
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000023964 ielem->idcMatchers = NULL;
23965 }
23966 if (ielem->idcTable != NULL) {
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000023967 /*
23968 * OPTIMIZE TODO: Use a pool of IDC tables??.
23969 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000023970 xmlSchemaIDCFreeIDCTable(ielem->idcTable);
23971 ielem->idcTable = NULL;
23972 }
23973 if (ielem->regexCtxt != NULL) {
23974 xmlRegFreeExecCtxt(ielem->regexCtxt);
23975 ielem->regexCtxt = NULL;
23976 }
23977 if (ielem->nsBindings != NULL) {
23978 xmlFree((xmlChar **)ielem->nsBindings);
23979 ielem->nsBindings = NULL;
23980 ielem->nbNsBindings = 0;
23981 ielem->sizeNsBindings = 0;
23982 }
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023983}
23984
23985/**
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000023986 * xmlSchemaGetFreshElemInfo:
23987 * @vctxt: the schema validation context
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023988 *
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000023989 * Creates/reuses and initializes the element info item for
23990 * the currect tree depth.
23991 *
23992 * Returns the element info item or NULL on API or internal errors.
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023993 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000023994static xmlSchemaNodeInfoPtr
23995xmlSchemaGetFreshElemInfo(xmlSchemaValidCtxtPtr vctxt)
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000023996{
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000023997 xmlSchemaNodeInfoPtr info = NULL;
23998
23999 if (vctxt->depth > vctxt->sizeElemInfos) {
24000 VERROR_INT("xmlSchemaGetFreshElemInfo",
24001 "inconsistent depth encountered");
24002 return (NULL);
24003 }
24004 if (vctxt->elemInfos == NULL) {
24005 vctxt->elemInfos = (xmlSchemaNodeInfoPtr *)
24006 xmlMalloc(10 * sizeof(xmlSchemaNodeInfoPtr));
24007 if (vctxt->elemInfos == NULL) {
24008 xmlSchemaVErrMemory(vctxt,
24009 "allocating the element info array", NULL);
24010 return (NULL);
24011 }
24012 memset(vctxt->elemInfos, 0, 10 * sizeof(xmlSchemaNodeInfoPtr));
24013 vctxt->sizeElemInfos = 10;
24014 } else if (vctxt->sizeElemInfos <= vctxt->depth) {
24015 int i = vctxt->sizeElemInfos;
24016
24017 vctxt->sizeElemInfos *= 2;
24018 vctxt->elemInfos = (xmlSchemaNodeInfoPtr *)
24019 xmlRealloc(vctxt->elemInfos, vctxt->sizeElemInfos *
24020 sizeof(xmlSchemaNodeInfoPtr));
24021 if (vctxt->elemInfos == NULL) {
24022 xmlSchemaVErrMemory(vctxt,
24023 "re-allocating the element info array", NULL);
24024 return (NULL);
24025 }
24026 /*
24027 * We need the new memory to be NULLed.
24028 * TODO: Use memset instead?
24029 */
24030 for (; i < vctxt->sizeElemInfos; i++)
24031 vctxt->elemInfos[i] = NULL;
24032 } else
24033 info = vctxt->elemInfos[vctxt->depth];
24034
24035 if (info == NULL) {
24036 info = (xmlSchemaNodeInfoPtr)
24037 xmlMalloc(sizeof(xmlSchemaNodeInfo));
24038 if (info == NULL) {
24039 xmlSchemaVErrMemory(vctxt,
24040 "allocating an element info", NULL);
24041 return (NULL);
24042 }
24043 vctxt->elemInfos[vctxt->depth] = info;
24044 } else {
24045 if (info->localName != NULL) {
24046 VERROR_INT("xmlSchemaGetFreshElemInfo",
24047 "elem info has not been cleared");
24048 return (NULL);
24049 }
24050 }
24051 memset(info, 0, sizeof(xmlSchemaNodeInfo));
24052 info->nodeType = XML_ELEMENT_NODE;
24053 info->depth = vctxt->depth;
24054
24055 return (info);
24056}
24057
24058#define ACTIVATE_ATTRIBUTE(item) vctxt->inode = (xmlSchemaNodeInfoPtr) item;
24059#define ACTIVATE_ELEM vctxt->inode = vctxt->elemInfos[vctxt->depth];
24060#define ACTIVATE_PARENT_ELEM vctxt->inode = vctxt->elemInfos[vctxt->depth -1];
24061
24062static int
24063xmlSchemaValidateFacets(xmlSchemaAbstractCtxtPtr actxt,
24064 xmlNodePtr node,
24065 xmlSchemaTypePtr type,
24066 xmlSchemaValType valType,
24067 const xmlChar * value,
24068 xmlSchemaValPtr val,
24069 unsigned long length,
24070 int fireErrors)
24071{
24072 int ret, error = 0;
24073
24074 xmlSchemaTypePtr tmpType;
24075 xmlSchemaFacetLinkPtr facetLink;
24076 xmlSchemaFacetPtr facet;
24077 unsigned long len = 0;
24078 xmlSchemaWhitespaceValueType ws;
24079
24080 /*
24081 * In Libxml2, derived built-in types have currently no explicit facets.
24082 */
24083 if (type->type == XML_SCHEMA_TYPE_BASIC)
Kasimier T. Buchcikbd2a7d12005-02-16 12:27:25 +000024084 return (0);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024085
24086 /*
24087 * NOTE: Do not jump away, if the facetSet of the given type is
24088 * empty: until now, "pattern" and "enumeration" facets of the
24089 * *base types* need to be checked as well.
24090 */
24091 if (type->facetSet == NULL)
24092 goto pattern_and_enum;
24093
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000024094 if (! WXS_IS_ATOMIC(type)) {
24095 if (WXS_IS_LIST(type))
24096 goto WXS_IS_LIST;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024097 else
24098 goto pattern_and_enum;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000024099 }
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000024100 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024101 * Whitespace handling is only of importance for string-based
24102 * types.
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000024103 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024104 tmpType = xmlSchemaGetPrimitiveType(type);
24105 if ((tmpType->builtInType == XML_SCHEMAS_STRING) ||
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000024106 WXS_IS_ANY_SIMPLE_TYPE(tmpType)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024107 ws = xmlSchemaGetWhiteSpaceFacetValue(type);
24108 } else
24109 ws = XML_SCHEMA_WHITESPACE_COLLAPSE;
24110 /*
24111 * If the value was not computed (for string or
24112 * anySimpleType based types), then use the provided
24113 * type.
24114 */
24115 if (val == NULL)
24116 valType = valType;
24117 else
24118 valType = xmlSchemaGetValType(val);
Daniel Veillarddee23482008-04-11 12:58:43 +000024119
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024120 ret = 0;
24121 for (facetLink = type->facetSet; facetLink != NULL;
24122 facetLink = facetLink->next) {
24123 /*
24124 * Skip the pattern "whiteSpace": it is used to
24125 * format the character content beforehand.
24126 */
24127 switch (facetLink->facet->type) {
24128 case XML_SCHEMA_FACET_WHITESPACE:
24129 case XML_SCHEMA_FACET_PATTERN:
24130 case XML_SCHEMA_FACET_ENUMERATION:
24131 continue;
24132 case XML_SCHEMA_FACET_LENGTH:
24133 case XML_SCHEMA_FACET_MINLENGTH:
24134 case XML_SCHEMA_FACET_MAXLENGTH:
24135 ret = xmlSchemaValidateLengthFacetWhtsp(facetLink->facet,
24136 valType, value, val, &len, ws);
24137 break;
24138 default:
24139 ret = xmlSchemaValidateFacetWhtsp(facetLink->facet, ws,
24140 valType, value, val, ws);
24141 break;
24142 }
24143 if (ret < 0) {
24144 AERROR_INT("xmlSchemaValidateFacets",
24145 "validating against a atomic type facet");
24146 return (-1);
24147 } else if (ret > 0) {
24148 if (fireErrors)
24149 xmlSchemaFacetErr(actxt, ret, node,
24150 value, len, type, facetLink->facet, NULL, NULL, NULL);
24151 else
24152 return (ret);
24153 if (error == 0)
24154 error = ret;
24155 }
24156 ret = 0;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000024157 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024158
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000024159WXS_IS_LIST:
24160 if (! WXS_IS_LIST(type))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024161 goto pattern_and_enum;
24162 /*
24163 * "length", "minLength" and "maxLength" of list types.
24164 */
24165 ret = 0;
24166 for (facetLink = type->facetSet; facetLink != NULL;
24167 facetLink = facetLink->next) {
Daniel Veillarddee23482008-04-11 12:58:43 +000024168
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024169 switch (facetLink->facet->type) {
24170 case XML_SCHEMA_FACET_LENGTH:
24171 case XML_SCHEMA_FACET_MINLENGTH:
Daniel Veillarddee23482008-04-11 12:58:43 +000024172 case XML_SCHEMA_FACET_MAXLENGTH:
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024173 ret = xmlSchemaValidateListSimpleTypeFacet(facetLink->facet,
24174 value, length, NULL);
24175 break;
24176 default:
24177 continue;
24178 }
24179 if (ret < 0) {
24180 AERROR_INT("xmlSchemaValidateFacets",
24181 "validating against a list type facet");
24182 return (-1);
24183 } else if (ret > 0) {
Daniel Veillarddee23482008-04-11 12:58:43 +000024184 if (fireErrors)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024185 xmlSchemaFacetErr(actxt, ret, node,
24186 value, length, type, facetLink->facet, NULL, NULL, NULL);
24187 else
24188 return (ret);
24189 if (error == 0)
24190 error = ret;
24191 }
24192 ret = 0;
24193 }
24194
24195pattern_and_enum:
24196 if (error >= 0) {
24197 int found = 0;
24198 /*
24199 * Process enumerations. Facet values are in the value space
24200 * of the defining type's base type. This seems to be a bug in the
24201 * XML Schema 1.0 spec. Use the whitespace type of the base type.
24202 * Only the first set of enumerations in the ancestor-or-self axis
24203 * is used for validation.
24204 */
24205 ret = 0;
24206 tmpType = type;
24207 do {
24208 for (facet = tmpType->facets; facet != NULL; facet = facet->next) {
24209 if (facet->type != XML_SCHEMA_FACET_ENUMERATION)
24210 continue;
24211 found = 1;
24212 ret = xmlSchemaAreValuesEqual(facet->val, val);
24213 if (ret == 1)
24214 break;
24215 else if (ret < 0) {
24216 AERROR_INT("xmlSchemaValidateFacets",
24217 "validating against an enumeration facet");
24218 return (-1);
24219 }
24220 }
24221 if (ret != 0)
24222 break;
Kasimier T. Buchcikb63d2fa2006-04-19 11:20:49 +000024223 /*
24224 * Break on the first set of enumerations. Any additional
24225 * enumerations which might be existent on the ancestors
24226 * of the current type are restricted by this set; thus
24227 * *must* *not* be taken into account.
24228 */
24229 if (found)
24230 break;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024231 tmpType = tmpType->baseType;
24232 } while ((tmpType != NULL) &&
24233 (tmpType->type != XML_SCHEMA_TYPE_BASIC));
24234 if (found && (ret == 0)) {
24235 ret = XML_SCHEMAV_CVC_ENUMERATION_VALID;
24236 if (fireErrors) {
24237 xmlSchemaFacetErr(actxt, ret, node,
24238 value, 0, type, NULL, NULL, NULL, NULL);
24239 } else
24240 return (ret);
24241 if (error == 0)
24242 error = ret;
24243 }
24244 }
24245
24246 if (error >= 0) {
24247 int found;
24248 /*
24249 * Process patters. Pattern facets are ORed at type level
24250 * and ANDed if derived. Walk the base type axis.
24251 */
24252 tmpType = type;
24253 facet = NULL;
24254 do {
24255 found = 0;
24256 for (facetLink = tmpType->facetSet; facetLink != NULL;
24257 facetLink = facetLink->next) {
24258 if (facetLink->facet->type != XML_SCHEMA_FACET_PATTERN)
24259 continue;
24260 found = 1;
Daniel Veillarddee23482008-04-11 12:58:43 +000024261 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024262 * NOTE that for patterns, @value needs to be the
24263 * normalized vaule.
24264 */
24265 ret = xmlRegexpExec(facetLink->facet->regexp, value);
24266 if (ret == 1)
24267 break;
24268 else if (ret < 0) {
24269 AERROR_INT("xmlSchemaValidateFacets",
24270 "validating against a pattern facet");
24271 return (-1);
24272 } else {
Daniel Veillarddee23482008-04-11 12:58:43 +000024273 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024274 * Save the last non-validating facet.
24275 */
24276 facet = facetLink->facet;
24277 }
24278 }
24279 if (found && (ret != 1)) {
24280 ret = XML_SCHEMAV_CVC_PATTERN_VALID;
24281 if (fireErrors) {
24282 xmlSchemaFacetErr(actxt, ret, node,
24283 value, 0, type, facet, NULL, NULL, NULL);
24284 } else
24285 return (ret);
24286 if (error == 0)
24287 error = ret;
24288 break;
24289 }
24290 tmpType = tmpType->baseType;
24291 } while ((tmpType != NULL) && (tmpType->type != XML_SCHEMA_TYPE_BASIC));
24292 }
24293
24294 return (error);
24295}
Daniel Veillarddee23482008-04-11 12:58:43 +000024296
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024297static xmlChar *
24298xmlSchemaNormalizeValue(xmlSchemaTypePtr type,
24299 const xmlChar *value)
24300{
Daniel Veillarddee23482008-04-11 12:58:43 +000024301 switch (xmlSchemaGetWhiteSpaceFacetValue(type)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024302 case XML_SCHEMA_WHITESPACE_COLLAPSE:
24303 return (xmlSchemaCollapseString(value));
24304 case XML_SCHEMA_WHITESPACE_REPLACE:
24305 return (xmlSchemaWhiteSpaceReplace(value));
24306 default:
24307 return (NULL);
24308 }
24309}
24310
24311static int
24312xmlSchemaValidateQName(xmlSchemaValidCtxtPtr vctxt,
24313 const xmlChar *value,
24314 xmlSchemaValPtr *val,
24315 int valNeeded)
24316{
24317 int ret;
24318 const xmlChar *nsName;
24319 xmlChar *local, *prefix = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000024320
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024321 ret = xmlValidateQName(value, 1);
24322 if (ret != 0) {
24323 if (ret == -1) {
24324 VERROR_INT("xmlSchemaValidateQName",
24325 "calling xmlValidateQName()");
24326 return (-1);
24327 }
24328 return( XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1);
24329 }
24330 /*
24331 * NOTE: xmlSplitQName2 will always return a duplicated
24332 * strings.
24333 */
24334 local = xmlSplitQName2(value, &prefix);
24335 if (local == NULL)
24336 local = xmlStrdup(value);
24337 /*
24338 * OPTIMIZE TODO: Use flags for:
24339 * - is there any namespace binding?
24340 * - is there a default namespace?
24341 */
24342 nsName = xmlSchemaLookupNamespace(vctxt, prefix);
Daniel Veillarddee23482008-04-11 12:58:43 +000024343
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024344 if (prefix != NULL) {
24345 xmlFree(prefix);
24346 /*
24347 * A namespace must be found if the prefix is
24348 * NOT NULL.
24349 */
24350 if (nsName == NULL) {
24351 ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000024352 xmlSchemaCustomErr(ACTXT_CAST vctxt, ret, NULL,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000024353 WXS_BASIC_CAST xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME),
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024354 "The QName value '%s' has no "
24355 "corresponding namespace declaration in "
24356 "scope", value, NULL);
24357 if (local != NULL)
24358 xmlFree(local);
24359 return (ret);
24360 }
24361 }
24362 if (valNeeded && val) {
24363 if (nsName != NULL)
24364 *val = xmlSchemaNewQNameValue(
24365 BAD_CAST xmlStrdup(nsName), BAD_CAST local);
24366 else
24367 *val = xmlSchemaNewQNameValue(NULL,
24368 BAD_CAST local);
24369 } else
24370 xmlFree(local);
24371 return (0);
24372}
24373
24374/*
24375* cvc-simple-type
24376*/
24377static int
24378xmlSchemaVCheckCVCSimpleType(xmlSchemaAbstractCtxtPtr actxt,
24379 xmlNodePtr node,
24380 xmlSchemaTypePtr type,
24381 const xmlChar *value,
24382 xmlSchemaValPtr *retVal,
24383 int fireErrors,
24384 int normalize,
24385 int isNormalized)
24386{
24387 int ret = 0, valNeeded = (retVal) ? 1 : 0;
24388 xmlSchemaValPtr val = NULL;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000024389 /* xmlSchemaWhitespaceValueType ws; */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024390 xmlChar *normValue = NULL;
24391
24392#define NORMALIZE(atype) \
24393 if ((! isNormalized) && \
24394 (normalize || (type->flags & XML_SCHEMAS_TYPE_NORMVALUENEEDED))) { \
24395 normValue = xmlSchemaNormalizeValue(atype, value); \
24396 if (normValue != NULL) \
24397 value = normValue; \
24398 isNormalized = 1; \
24399 }
Daniel Veillarddee23482008-04-11 12:58:43 +000024400
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024401 if ((retVal != NULL) && (*retVal != NULL)) {
24402 xmlSchemaFreeValue(*retVal);
24403 *retVal = NULL;
24404 }
24405 /*
24406 * 3.14.4 Simple Type Definition Validation Rules
24407 * Validation Rule: String Valid
24408 */
24409 /*
24410 * 1 It is schema-valid with respect to that definition as defined
24411 * by Datatype Valid in [XML Schemas: Datatypes].
24412 */
24413 /*
24414 * 2.1 If The definition is ENTITY or is validly derived from ENTITY given
Rob Richardsc6947bb2008-06-29 15:04:41 +000024415 * the empty set, as defined in Type Derivation OK (Simple) (�3.14.6), then
24416 * the string must be a �declared entity name�.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024417 */
24418 /*
24419 * 2.2 If The definition is ENTITIES or is validly derived from ENTITIES
Rob Richardsc6947bb2008-06-29 15:04:41 +000024420 * given the empty set, as defined in Type Derivation OK (Simple) (�3.14.6),
24421 * then every whitespace-delimited substring of the string must be a �declared
24422 * entity name�.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024423 */
24424 /*
24425 * 2.3 otherwise no further condition applies.
24426 */
24427 if ((! valNeeded) && (type->flags & XML_SCHEMAS_TYPE_FACETSNEEDVALUE))
24428 valNeeded = 1;
Kasimier T. Buchcik9c215eb2005-06-21 08:38:49 +000024429 if (value == NULL)
24430 value = BAD_CAST "";
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000024431 if (WXS_IS_ANY_SIMPLE_TYPE(type) || WXS_IS_ATOMIC(type)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024432 xmlSchemaTypePtr biType; /* The built-in type. */
24433 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000024434 * SPEC (1.2.1) "if {variety} is �atomic� then the string must �match�
24435 * a literal in the �lexical space� of {base type definition}"
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024436 */
24437 /*
24438 * Whitespace-normalize.
24439 */
24440 NORMALIZE(type);
24441 if (type->type != XML_SCHEMA_TYPE_BASIC) {
24442 /*
24443 * Get the built-in type.
24444 */
24445 biType = type->baseType;
24446 while ((biType != NULL) &&
24447 (biType->type != XML_SCHEMA_TYPE_BASIC))
24448 biType = biType->baseType;
24449
24450 if (biType == NULL) {
24451 AERROR_INT("xmlSchemaVCheckCVCSimpleType",
24452 "could not get the built-in type");
24453 goto internal_error;
24454 }
24455 } else
24456 biType = type;
24457 /*
24458 * NOTATIONs need to be processed here, since they need
24459 * to lookup in the hashtable of NOTATION declarations of the schema.
24460 */
Daniel Veillarddee23482008-04-11 12:58:43 +000024461 if (actxt->type == XML_SCHEMA_CTXT_VALIDATOR) {
24462 switch (biType->builtInType) {
24463 case XML_SCHEMAS_NOTATION:
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024464 ret = xmlSchemaValidateNotation(
24465 (xmlSchemaValidCtxtPtr) actxt,
24466 ((xmlSchemaValidCtxtPtr) actxt)->schema,
24467 NULL, value, &val, valNeeded);
24468 break;
24469 case XML_SCHEMAS_QNAME:
24470 ret = xmlSchemaValidateQName((xmlSchemaValidCtxtPtr) actxt,
24471 value, &val, valNeeded);
24472 break;
24473 default:
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000024474 /* ws = xmlSchemaGetWhiteSpaceFacetValue(type); */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024475 if (valNeeded)
24476 ret = xmlSchemaValPredefTypeNodeNoNorm(biType,
Wayne Jensen99f7ac72009-08-07 21:27:44 +020024477 value, &val, node);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024478 else
24479 ret = xmlSchemaValPredefTypeNodeNoNorm(biType,
Wayne Jensen99f7ac72009-08-07 21:27:44 +020024480 value, NULL, node);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024481 break;
24482 }
Daniel Veillarddee23482008-04-11 12:58:43 +000024483 } else if (actxt->type == XML_SCHEMA_CTXT_PARSER) {
24484 switch (biType->builtInType) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024485 case XML_SCHEMAS_NOTATION:
24486 ret = xmlSchemaValidateNotation(NULL,
24487 ((xmlSchemaParserCtxtPtr) actxt)->schema, node,
24488 value, &val, valNeeded);
24489 break;
24490 default:
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000024491 /* ws = xmlSchemaGetWhiteSpaceFacetValue(type); */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024492 if (valNeeded)
24493 ret = xmlSchemaValPredefTypeNodeNoNorm(biType,
24494 value, &val, node);
24495 else
24496 ret = xmlSchemaValPredefTypeNodeNoNorm(biType,
24497 value, NULL, node);
24498 break;
Daniel Veillarddee23482008-04-11 12:58:43 +000024499 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024500 } else {
24501 /*
24502 * Validation via a public API is not implemented yet.
24503 */
24504 TODO
24505 goto internal_error;
24506 }
24507 if (ret != 0) {
24508 if (ret < 0) {
24509 AERROR_INT("xmlSchemaVCheckCVCSimpleType",
24510 "validating against a built-in type");
24511 goto internal_error;
24512 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000024513 if (WXS_IS_LIST(type))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024514 ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2;
24515 else
Daniel Veillarddee23482008-04-11 12:58:43 +000024516 ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024517 }
24518 if ((ret == 0) && (type->flags & XML_SCHEMAS_TYPE_HAS_FACETS)) {
24519 /*
24520 * Check facets.
24521 */
24522 ret = xmlSchemaValidateFacets(actxt, node, type,
24523 (xmlSchemaValType) biType->builtInType, value, val,
24524 0, fireErrors);
24525 if (ret != 0) {
24526 if (ret < 0) {
24527 AERROR_INT("xmlSchemaVCheckCVCSimpleType",
24528 "validating facets of atomic simple type");
24529 goto internal_error;
24530 }
Daniel Veillarddee23482008-04-11 12:58:43 +000024531 if (WXS_IS_LIST(type))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024532 ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2;
24533 else
Daniel Veillarddee23482008-04-11 12:58:43 +000024534 ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024535 }
24536 }
24537 if (fireErrors && (ret > 0))
24538 xmlSchemaSimpleTypeErr(actxt, ret, node, value, type, 1);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000024539 } else if (WXS_IS_LIST(type)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024540
24541 xmlSchemaTypePtr itemType;
24542 const xmlChar *cur, *end;
24543 xmlChar *tmpValue = NULL;
24544 unsigned long len = 0;
24545 xmlSchemaValPtr prevVal = NULL, curVal = NULL;
Rob Richardsc6947bb2008-06-29 15:04:41 +000024546 /* 1.2.2 if {variety} is �list� then the string must be a sequence
24547 * of white space separated tokens, each of which �match�es a literal
24548 * in the �lexical space� of {item type definition}
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024549 */
24550 /*
24551 * Note that XML_SCHEMAS_TYPE_NORMVALUENEEDED will be set if
24552 * the list type has an enum or pattern facet.
24553 */
24554 NORMALIZE(type);
24555 /*
24556 * VAL TODO: Optimize validation of empty values.
24557 * VAL TODO: We do not have computed values for lists.
24558 */
Daniel Veillarddee23482008-04-11 12:58:43 +000024559 itemType = WXS_LIST_ITEMTYPE(type);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024560 cur = value;
24561 do {
24562 while (IS_BLANK_CH(*cur))
24563 cur++;
24564 end = cur;
24565 while ((*end != 0) && (!(IS_BLANK_CH(*end))))
24566 end++;
24567 if (end == cur)
24568 break;
24569 tmpValue = xmlStrndup(cur, end - cur);
24570 len++;
24571
24572 if (valNeeded)
24573 ret = xmlSchemaVCheckCVCSimpleType(actxt, node, itemType,
24574 tmpValue, &curVal, fireErrors, 0, 1);
24575 else
24576 ret = xmlSchemaVCheckCVCSimpleType(actxt, node, itemType,
24577 tmpValue, NULL, fireErrors, 0, 1);
24578 FREE_AND_NULL(tmpValue);
24579 if (curVal != NULL) {
24580 /*
24581 * Add to list of computed values.
24582 */
24583 if (val == NULL)
24584 val = curVal;
24585 else
24586 xmlSchemaValueAppend(prevVal, curVal);
24587 prevVal = curVal;
24588 curVal = NULL;
24589 }
24590 if (ret != 0) {
24591 if (ret < 0) {
24592 AERROR_INT("xmlSchemaVCheckCVCSimpleType",
24593 "validating an item of list simple type");
24594 goto internal_error;
24595 }
24596 ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2;
24597 break;
Daniel Veillarddee23482008-04-11 12:58:43 +000024598 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024599 cur = end;
24600 } while (*cur != 0);
24601 FREE_AND_NULL(tmpValue);
24602 if ((ret == 0) && (type->flags & XML_SCHEMAS_TYPE_HAS_FACETS)) {
24603 /*
24604 * Apply facets (pattern, enumeration).
24605 */
24606 ret = xmlSchemaValidateFacets(actxt, node, type,
24607 XML_SCHEMAS_UNKNOWN, value, val,
24608 len, fireErrors);
24609 if (ret != 0) {
24610 if (ret < 0) {
24611 AERROR_INT("xmlSchemaVCheckCVCSimpleType",
24612 "validating facets of list simple type");
24613 goto internal_error;
24614 }
24615 ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2;
24616 }
24617 }
24618 if (fireErrors && (ret > 0)) {
Daniel Veillarddee23482008-04-11 12:58:43 +000024619 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024620 * Report the normalized value.
24621 */
24622 normalize = 1;
24623 NORMALIZE(type);
24624 xmlSchemaSimpleTypeErr(actxt, ret, node, value, type, 1);
24625 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000024626 } else if (WXS_IS_UNION(type)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024627 xmlSchemaTypeLinkPtr memberLink;
24628 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000024629 * TODO: For all datatypes �derived� by �union� whiteSpace does
24630 * not apply directly; however, the normalization behavior of �union�
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024631 * types is controlled by the value of whiteSpace on that one of the
Rob Richardsc6947bb2008-06-29 15:04:41 +000024632 * �memberTypes� against which the �union� is successfully validated.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024633 *
24634 * This means that the value is normalized by the first validating
24635 * member type, then the facets of the union type are applied. This
24636 * needs changing of the value!
24637 */
24638
24639 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000024640 * 1.2.3 if {variety} is �union� then the string must �match� a
24641 * literal in the �lexical space� of at least one member of
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024642 * {member type definitions}
24643 */
24644 memberLink = xmlSchemaGetUnionSimpleTypeMemberTypes(type);
24645 if (memberLink == NULL) {
24646 AERROR_INT("xmlSchemaVCheckCVCSimpleType",
24647 "union simple type has no member types");
24648 goto internal_error;
Daniel Veillarddee23482008-04-11 12:58:43 +000024649 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024650 /*
24651 * Always normalize union type values, since we currently
24652 * cannot store the whitespace information with the value
24653 * itself; otherwise a later value-comparison would be
24654 * not possible.
24655 */
24656 while (memberLink != NULL) {
Daniel Veillarddee23482008-04-11 12:58:43 +000024657 if (valNeeded)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024658 ret = xmlSchemaVCheckCVCSimpleType(actxt, node,
24659 memberLink->type, value, &val, 0, 1, 0);
24660 else
24661 ret = xmlSchemaVCheckCVCSimpleType(actxt, node,
24662 memberLink->type, value, NULL, 0, 1, 0);
24663 if (ret <= 0)
24664 break;
24665 memberLink = memberLink->next;
24666 }
24667 if (ret != 0) {
24668 if (ret < 0) {
24669 AERROR_INT("xmlSchemaVCheckCVCSimpleType",
24670 "validating members of union simple type");
24671 goto internal_error;
24672 }
24673 ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_3;
24674 }
24675 /*
24676 * Apply facets (pattern, enumeration).
24677 */
24678 if ((ret == 0) && (type->flags & XML_SCHEMAS_TYPE_HAS_FACETS)) {
24679 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000024680 * The normalization behavior of �union� types is controlled by
24681 * the value of whiteSpace on that one of the �memberTypes�
24682 * against which the �union� is successfully validated.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024683 */
24684 NORMALIZE(memberLink->type);
24685 ret = xmlSchemaValidateFacets(actxt, node, type,
24686 XML_SCHEMAS_UNKNOWN, value, val,
24687 0, fireErrors);
24688 if (ret != 0) {
24689 if (ret < 0) {
24690 AERROR_INT("xmlSchemaVCheckCVCSimpleType",
24691 "validating facets of union simple type");
24692 goto internal_error;
24693 }
Daniel Veillarddee23482008-04-11 12:58:43 +000024694 ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_3;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024695 }
24696 }
24697 if (fireErrors && (ret > 0))
24698 xmlSchemaSimpleTypeErr(actxt, ret, node, value, type, 1);
24699 }
24700
24701 if (normValue != NULL)
24702 xmlFree(normValue);
24703 if (ret == 0) {
24704 if (retVal != NULL)
24705 *retVal = val;
24706 else if (val != NULL)
24707 xmlSchemaFreeValue(val);
24708 } else if (val != NULL)
24709 xmlSchemaFreeValue(val);
24710 return (ret);
24711internal_error:
24712 if (normValue != NULL)
24713 xmlFree(normValue);
24714 if (val != NULL)
24715 xmlSchemaFreeValue(val);
24716 return (-1);
24717}
24718
24719static int
24720xmlSchemaVExpandQName(xmlSchemaValidCtxtPtr vctxt,
24721 const xmlChar *value,
24722 const xmlChar **nsName,
24723 const xmlChar **localName)
24724{
24725 int ret = 0;
24726
24727 if ((nsName == NULL) || (localName == NULL))
24728 return (-1);
24729 *nsName = NULL;
24730 *localName = NULL;
24731
24732 ret = xmlValidateQName(value, 1);
24733 if (ret == -1)
24734 return (-1);
24735 if (ret > 0) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000024736 xmlSchemaSimpleTypeErr(ACTXT_CAST vctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024737 XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1, NULL,
24738 value, xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), 1);
24739 return (1);
24740 }
24741 {
24742 xmlChar *local = NULL;
24743 xmlChar *prefix;
24744
24745 /*
24746 * NOTE: xmlSplitQName2 will return a duplicated
24747 * string.
24748 */
24749 local = xmlSplitQName2(value, &prefix);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024750 if (local == NULL)
24751 *localName = xmlDictLookup(vctxt->dict, value, -1);
24752 else {
24753 *localName = xmlDictLookup(vctxt->dict, local, -1);
24754 xmlFree(local);
24755 }
24756
24757 *nsName = xmlSchemaLookupNamespace(vctxt, prefix);
24758
24759 if (prefix != NULL) {
24760 xmlFree(prefix);
24761 /*
24762 * A namespace must be found if the prefix is NOT NULL.
24763 */
24764 if (*nsName == NULL) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000024765 xmlSchemaCustomErr(ACTXT_CAST vctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024766 XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1, NULL,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000024767 WXS_BASIC_CAST xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME),
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024768 "The QName value '%s' has no "
24769 "corresponding namespace declaration in scope",
24770 value, NULL);
24771 return (2);
24772 }
24773 }
24774 }
24775 return (0);
24776}
24777
24778static int
24779xmlSchemaProcessXSIType(xmlSchemaValidCtxtPtr vctxt,
24780 xmlSchemaAttrInfoPtr iattr,
24781 xmlSchemaTypePtr *localType,
24782 xmlSchemaElementPtr elemDecl)
24783{
24784 int ret = 0;
24785 /*
24786 * cvc-elt (3.3.4) : (4)
24787 * AND
24788 * Schema-Validity Assessment (Element) (cvc-assess-elt)
24789 * (1.2.1.2.1) - (1.2.1.2.4)
24790 * Handle 'xsi:type'.
24791 */
24792 if (localType == NULL)
24793 return (-1);
24794 *localType = NULL;
24795 if (iattr == NULL)
24796 return (0);
24797 else {
24798 const xmlChar *nsName = NULL, *local = NULL;
24799 /*
24800 * TODO: We should report a *warning* that the type was overriden
24801 * by the instance.
24802 */
24803 ACTIVATE_ATTRIBUTE(iattr);
24804 /*
24805 * (cvc-elt) (3.3.4) : (4.1)
24806 * (cvc-assess-elt) (1.2.1.2.2)
24807 */
24808 ret = xmlSchemaVExpandQName(vctxt, iattr->value,
24809 &nsName, &local);
24810 if (ret != 0) {
24811 if (ret < 0) {
24812 VERROR_INT("xmlSchemaValidateElementByDeclaration",
24813 "calling xmlSchemaQNameExpand() to validate the "
24814 "attribute 'xsi:type'");
24815 goto internal_error;
24816 }
24817 goto exit;
24818 }
24819 /*
24820 * (cvc-elt) (3.3.4) : (4.2)
24821 * (cvc-assess-elt) (1.2.1.2.3)
24822 */
24823 *localType = xmlSchemaGetType(vctxt->schema, local, nsName);
24824 if (*localType == NULL) {
24825 xmlChar *str = NULL;
24826
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000024827 xmlSchemaCustomErr(ACTXT_CAST vctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024828 XML_SCHEMAV_CVC_ELT_4_2, NULL,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000024829 WXS_BASIC_CAST xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME),
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024830 "The QName value '%s' of the xsi:type attribute does not "
24831 "resolve to a type definition",
24832 xmlSchemaFormatQName(&str, nsName, local), NULL);
24833 FREE_AND_NULL(str);
24834 ret = vctxt->err;
24835 goto exit;
24836 }
24837 if (elemDecl != NULL) {
24838 int set = 0;
24839
24840 /*
24841 * SPEC cvc-elt (3.3.4) : (4.3) (Type Derivation OK)
Rob Richardsc6947bb2008-06-29 15:04:41 +000024842 * "The �local type definition� must be validly
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024843 * derived from the {type definition} given the union of
24844 * the {disallowed substitutions} and the {type definition}'s
24845 * {prohibited substitutions}, as defined in
Rob Richardsc6947bb2008-06-29 15:04:41 +000024846 * Type Derivation OK (Complex) (�3.4.6)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024847 * (if it is a complex type definition),
24848 * or given {disallowed substitutions} as defined in Type
Rob Richardsc6947bb2008-06-29 15:04:41 +000024849 * Derivation OK (Simple) (�3.14.6) (if it is a simple type
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024850 * definition)."
24851 *
24852 * {disallowed substitutions}: the "block" on the element decl.
24853 * {prohibited substitutions}: the "block" on the type def.
24854 */
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000024855 /*
24856 * OPTIMIZE TODO: We could map types already evaluated
24857 * to be validly derived from other types to avoid checking
24858 * this over and over for the same types.
24859 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024860 if ((elemDecl->flags & XML_SCHEMAS_ELEM_BLOCK_EXTENSION) ||
24861 (elemDecl->subtypes->flags &
24862 XML_SCHEMAS_TYPE_BLOCK_EXTENSION))
24863 set |= SUBSET_EXTENSION;
24864
24865 if ((elemDecl->flags & XML_SCHEMAS_ELEM_BLOCK_RESTRICTION) ||
24866 (elemDecl->subtypes->flags &
24867 XML_SCHEMAS_TYPE_BLOCK_RESTRICTION))
24868 set |= SUBSET_RESTRICTION;
24869
Kasimier T. Buchcikf326e772005-10-20 11:06:00 +000024870 /*
24871 * REMOVED and CHANGED since this produced a parser context
24872 * which adds to the string dict of the schema. So this would
24873 * change the schema and we don't want this. We don't need
24874 * the parser context anymore.
24875 *
24876 * if ((vctxt->pctxt == NULL) &&
24877 * (xmlSchemaCreatePCtxtOnVCtxt(vctxt) == -1))
24878 * return (-1);
24879 */
24880
24881 if (xmlSchemaCheckCOSDerivedOK(ACTXT_CAST vctxt, *localType,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024882 elemDecl->subtypes, set) != 0) {
24883 xmlChar *str = NULL;
24884
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000024885 xmlSchemaCustomErr(ACTXT_CAST vctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024886 XML_SCHEMAV_CVC_ELT_4_3, NULL, NULL,
24887 "The type definition '%s', specified by xsi:type, is "
24888 "blocked or not validly derived from the type definition "
24889 "of the element declaration",
24890 xmlSchemaFormatQName(&str,
24891 (*localType)->targetNamespace,
24892 (*localType)->name),
24893 NULL);
24894 FREE_AND_NULL(str);
24895 ret = vctxt->err;
24896 *localType = NULL;
24897 }
24898 }
24899 }
24900exit:
24901 ACTIVATE_ELEM;
24902 return (ret);
24903internal_error:
24904 ACTIVATE_ELEM;
24905 return (-1);
24906}
24907
24908static int
24909xmlSchemaValidateElemDecl(xmlSchemaValidCtxtPtr vctxt)
24910{
24911 xmlSchemaElementPtr elemDecl = vctxt->inode->decl;
Daniel Veillard14b56432006-03-09 18:41:40 +000024912 xmlSchemaTypePtr actualType;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024913
24914 /*
24915 * cvc-elt (3.3.4) : 1
24916 */
24917 if (elemDecl == NULL) {
24918 VERROR(XML_SCHEMAV_CVC_ELT_1, NULL,
24919 "No matching declaration available");
24920 return (vctxt->err);
24921 }
Daniel Veillard14b56432006-03-09 18:41:40 +000024922 actualType = WXS_ELEM_TYPEDEF(elemDecl);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024923 /*
24924 * cvc-elt (3.3.4) : 2
24925 */
24926 if (elemDecl->flags & XML_SCHEMAS_ELEM_ABSTRACT) {
24927 VERROR(XML_SCHEMAV_CVC_ELT_2, NULL,
24928 "The element declaration is abstract");
24929 return (vctxt->err);
24930 }
24931 if (actualType == NULL) {
24932 VERROR(XML_SCHEMAV_CVC_TYPE_1, NULL,
24933 "The type definition is absent");
24934 return (XML_SCHEMAV_CVC_TYPE_1);
24935 }
24936 if (vctxt->nbAttrInfos != 0) {
24937 int ret;
24938 xmlSchemaAttrInfoPtr iattr;
24939 /*
24940 * cvc-elt (3.3.4) : 3
24941 * Handle 'xsi:nil'.
24942 */
24943 iattr = xmlSchemaGetMetaAttrInfo(vctxt,
24944 XML_SCHEMA_ATTR_INFO_META_XSI_NIL);
24945 if (iattr) {
24946 ACTIVATE_ATTRIBUTE(iattr);
24947 /*
24948 * Validate the value.
24949 */
24950 ret = xmlSchemaVCheckCVCSimpleType(
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000024951 ACTXT_CAST vctxt, NULL,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000024952 xmlSchemaGetBuiltInType(XML_SCHEMAS_BOOLEAN),
24953 iattr->value, &(iattr->val), 1, 0, 0);
24954 ACTIVATE_ELEM;
24955 if (ret < 0) {
24956 VERROR_INT("xmlSchemaValidateElemDecl",
24957 "calling xmlSchemaVCheckCVCSimpleType() to "
24958 "validate the attribute 'xsi:nil'");
24959 return (-1);
24960 }
24961 if (ret == 0) {
24962 if ((elemDecl->flags & XML_SCHEMAS_ELEM_NILLABLE) == 0) {
24963 /*
24964 * cvc-elt (3.3.4) : 3.1
24965 */
24966 VERROR(XML_SCHEMAV_CVC_ELT_3_1, NULL,
24967 "The element is not 'nillable'");
24968 /* Does not return an error on purpose. */
24969 } else {
24970 if (xmlSchemaValueGetAsBoolean(iattr->val)) {
24971 /*
24972 * cvc-elt (3.3.4) : 3.2.2
24973 */
24974 if ((elemDecl->flags & XML_SCHEMAS_ELEM_FIXED) &&
24975 (elemDecl->value != NULL)) {
24976 VERROR(XML_SCHEMAV_CVC_ELT_3_2_2, NULL,
24977 "The element cannot be 'nilled' because "
24978 "there is a fixed value constraint defined "
24979 "for it");
24980 /* Does not return an error on purpose. */
24981 } else
24982 vctxt->inode->flags |=
24983 XML_SCHEMA_ELEM_INFO_NILLED;
24984 }
24985 }
24986 }
24987 }
24988 /*
24989 * cvc-elt (3.3.4) : 4
24990 * Handle 'xsi:type'.
24991 */
24992 iattr = xmlSchemaGetMetaAttrInfo(vctxt,
24993 XML_SCHEMA_ATTR_INFO_META_XSI_TYPE);
24994 if (iattr) {
24995 xmlSchemaTypePtr localType = NULL;
24996
24997 ret = xmlSchemaProcessXSIType(vctxt, iattr, &localType,
24998 elemDecl);
24999 if (ret != 0) {
25000 if (ret == -1) {
25001 VERROR_INT("xmlSchemaValidateElemDecl",
25002 "calling xmlSchemaProcessXSIType() to "
25003 "process the attribute 'xsi:type'");
25004 return (-1);
25005 }
25006 /* Does not return an error on purpose. */
25007 }
25008 if (localType != NULL) {
25009 vctxt->inode->flags |= XML_SCHEMA_ELEM_INFO_LOCAL_TYPE;
25010 actualType = localType;
25011 }
25012 }
25013 }
25014 /*
25015 * IDC: Register identity-constraint XPath matchers.
25016 */
25017 if ((elemDecl->idcs != NULL) &&
25018 (xmlSchemaIDCRegisterMatchers(vctxt, elemDecl) == -1))
25019 return (-1);
25020 /*
25021 * No actual type definition.
25022 */
25023 if (actualType == NULL) {
25024 VERROR(XML_SCHEMAV_CVC_TYPE_1, NULL,
25025 "The type definition is absent");
25026 return (XML_SCHEMAV_CVC_TYPE_1);
25027 }
25028 /*
25029 * Remember the actual type definition.
25030 */
25031 vctxt->inode->typeDef = actualType;
25032
25033 return (0);
25034}
25035
25036static int
25037xmlSchemaVAttributesSimple(xmlSchemaValidCtxtPtr vctxt)
25038{
25039 xmlSchemaAttrInfoPtr iattr;
25040 int ret = 0, i;
25041
25042 /*
25043 * SPEC cvc-type (3.1.1)
25044 * "The attributes of must be empty, excepting those whose namespace
25045 * name is identical to http://www.w3.org/2001/XMLSchema-instance and
25046 * whose local name is one of type, nil, schemaLocation or
25047 * noNamespaceSchemaLocation."
25048 */
25049 if (vctxt->nbAttrInfos == 0)
25050 return (0);
25051 for (i = 0; i < vctxt->nbAttrInfos; i++) {
25052 iattr = vctxt->attrInfos[i];
25053 if (! iattr->metaType) {
25054 ACTIVATE_ATTRIBUTE(iattr)
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000025055 xmlSchemaIllegalAttrErr(ACTXT_CAST vctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025056 XML_SCHEMAV_CVC_TYPE_3_1_1, iattr, NULL);
25057 ret = XML_SCHEMAV_CVC_TYPE_3_1_1;
25058 }
25059 }
25060 ACTIVATE_ELEM
25061 return (ret);
25062}
25063
25064/*
25065* Cleanup currently used attribute infos.
25066*/
25067static void
25068xmlSchemaClearAttrInfos(xmlSchemaValidCtxtPtr vctxt)
25069{
25070 int i;
25071 xmlSchemaAttrInfoPtr attr;
25072
25073 if (vctxt->nbAttrInfos == 0)
25074 return;
25075 for (i = 0; i < vctxt->nbAttrInfos; i++) {
25076 attr = vctxt->attrInfos[i];
25077 if (attr->flags & XML_SCHEMA_NODE_INFO_FLAG_OWNED_NAMES) {
25078 if (attr->localName != NULL)
25079 xmlFree((xmlChar *) attr->localName);
25080 if (attr->nsName != NULL)
25081 xmlFree((xmlChar *) attr->nsName);
25082 }
25083 if (attr->flags & XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES) {
25084 if (attr->value != NULL)
25085 xmlFree((xmlChar *) attr->value);
25086 }
25087 if (attr->val != NULL) {
25088 xmlSchemaFreeValue(attr->val);
25089 attr->val = NULL;
25090 }
25091 memset(attr, 0, sizeof(xmlSchemaAttrInfo));
25092 }
25093 vctxt->nbAttrInfos = 0;
25094}
25095
25096/*
25097* 3.4.4 Complex Type Definition Validation Rules
25098* Element Locally Valid (Complex Type) (cvc-complex-type)
25099* 3.2.4 Attribute Declaration Validation Rules
25100* Validation Rule: Attribute Locally Valid (cvc-attribute)
25101* Attribute Locally Valid (Use) (cvc-au)
25102*
25103* Only "assessed" attribute information items will be visible to
25104* IDCs. I.e. not "lax" (without declaration) and "skip" wild attributes.
25105*/
25106static int
25107xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt)
25108{
Daniel Veillarddee23482008-04-11 12:58:43 +000025109 xmlSchemaTypePtr type = vctxt->inode->typeDef;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025110 xmlSchemaItemListPtr attrUseList;
25111 xmlSchemaAttributeUsePtr attrUse = NULL;
25112 xmlSchemaAttributePtr attrDecl = NULL;
Daniel Veillarddee23482008-04-11 12:58:43 +000025113 xmlSchemaAttrInfoPtr iattr, tmpiattr;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025114 int i, j, found, nbAttrs, nbUses;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025115 int xpathRes = 0, res, wildIDs = 0, fixed;
Kasimier T. Buchcik9b02e292006-05-11 16:25:44 +000025116 xmlNodePtr defAttrOwnerElem = NULL;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025117
25118 /*
25119 * SPEC (cvc-attribute)
Rob Richardsc6947bb2008-06-29 15:04:41 +000025120 * (1) "The declaration must not be �absent� (see Missing
25121 * Sub-components (�5.3) for how this can fail to be
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025122 * the case)."
25123 * (2) "Its {type definition} must not be absent."
25124 *
25125 * NOTE (1) + (2): This is not handled here, since we currently do not
25126 * allow validation against schemas which have missing sub-components.
25127 *
25128 * SPEC (cvc-complex-type)
25129 * (3) "For each attribute information item in the element information
25130 * item's [attributes] excepting those whose [namespace name] is
25131 * identical to http://www.w3.org/2001/XMLSchema-instance and whose
25132 * [local name] is one of type, nil, schemaLocation or
25133 * noNamespaceSchemaLocation, the appropriate case among the following
25134 * must be true:
25135 *
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025136 */
25137 attrUseList = (xmlSchemaItemListPtr) type->attrUses;
25138 /*
25139 * @nbAttrs is the number of attributes present in the instance.
25140 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025141 nbAttrs = vctxt->nbAttrInfos;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025142 if (attrUseList != NULL)
25143 nbUses = attrUseList->nbItems;
25144 else
25145 nbUses = 0;
25146 for (i = 0; i < nbUses; i++) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025147 found = 0;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025148 attrUse = attrUseList->items[i];
25149 attrDecl = WXS_ATTRUSE_DECL(attrUse);
25150 for (j = 0; j < nbAttrs; j++) {
25151 iattr = vctxt->attrInfos[j];
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025152 /*
25153 * SPEC (cvc-complex-type) (3)
25154 * Skip meta attributes.
25155 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025156 if (iattr->metaType)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025157 continue;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025158 if (iattr->localName[0] != attrDecl->name[0])
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025159 continue;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025160 if (!xmlStrEqual(iattr->localName, attrDecl->name))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025161 continue;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025162 if (!xmlStrEqual(iattr->nsName, attrDecl->targetNamespace))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025163 continue;
25164 found = 1;
25165 /*
25166 * SPEC (cvc-complex-type)
25167 * (3.1) "If there is among the {attribute uses} an attribute
25168 * use with an {attribute declaration} whose {name} matches
25169 * the attribute information item's [local name] and whose
25170 * {target namespace} is identical to the attribute information
Rob Richardsc6947bb2008-06-29 15:04:41 +000025171 * item's [namespace name] (where an �absent� {target namespace}
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025172 * is taken to be identical to a [namespace name] with no value),
Rob Richardsc6947bb2008-06-29 15:04:41 +000025173 * then the attribute information must be �valid� with respect
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025174 * to that attribute use as per Attribute Locally Valid (Use)
Rob Richardsc6947bb2008-06-29 15:04:41 +000025175 * (�3.5.4). In this case the {attribute declaration} of that
25176 * attribute use is the �context-determined declaration� for the
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025177 * attribute information item with respect to Schema-Validity
Rob Richardsc6947bb2008-06-29 15:04:41 +000025178 * Assessment (Attribute) (�3.2.4) and
25179 * Assessment Outcome (Attribute) (�3.2.5).
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025180 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025181 iattr->state = XML_SCHEMAS_ATTR_ASSESSED;
25182 iattr->use = attrUse;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025183 /*
25184 * Context-determined declaration.
25185 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025186 iattr->decl = attrDecl;
25187 iattr->typeDef = attrDecl->subtypes;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025188 break;
25189 }
25190
25191 if (found)
25192 continue;
25193
25194 if (attrUse->occurs == XML_SCHEMAS_ATTR_USE_REQUIRED) {
25195 /*
25196 * Handle non-existent, required attributes.
25197 *
25198 * SPEC (cvc-complex-type)
25199 * (4) "The {attribute declaration} of each attribute use in
25200 * the {attribute uses} whose {required} is true matches one
25201 * of the attribute information items in the element information
25202 * item's [attributes] as per clause 3.1 above."
25203 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025204 tmpiattr = xmlSchemaGetFreshAttrInfo(vctxt);
25205 if (tmpiattr == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025206 VERROR_INT(
25207 "xmlSchemaVAttributesComplex",
25208 "calling xmlSchemaGetFreshAttrInfo()");
25209 return (-1);
25210 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025211 tmpiattr->state = XML_SCHEMAS_ATTR_ERR_MISSING;
25212 tmpiattr->use = attrUse;
Daniel Veillarddee23482008-04-11 12:58:43 +000025213 tmpiattr->decl = attrDecl;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025214 } else if ((attrUse->occurs == XML_SCHEMAS_ATTR_USE_OPTIONAL) &&
25215 ((attrUse->defValue != NULL) ||
25216 (attrDecl->defValue != NULL))) {
25217 /*
25218 * Handle non-existent, optional, default/fixed attributes.
25219 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025220 tmpiattr = xmlSchemaGetFreshAttrInfo(vctxt);
25221 if (tmpiattr == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025222 VERROR_INT(
25223 "xmlSchemaVAttributesComplex",
25224 "calling xmlSchemaGetFreshAttrInfo()");
25225 return (-1);
25226 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025227 tmpiattr->state = XML_SCHEMAS_ATTR_DEFAULT;
25228 tmpiattr->use = attrUse;
25229 tmpiattr->decl = attrDecl;
25230 tmpiattr->typeDef = attrDecl->subtypes;
25231 tmpiattr->localName = attrDecl->name;
25232 tmpiattr->nsName = attrDecl->targetNamespace;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025233 }
25234 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025235
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025236 if (vctxt->nbAttrInfos == 0)
25237 return (0);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025238 nbUses = vctxt->nbAttrInfos;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025239 /*
25240 * Validate against the wildcard.
25241 */
25242 if (type->attributeWildcard != NULL) {
25243 /*
25244 * SPEC (cvc-complex-type)
25245 * (3.2.1) "There must be an {attribute wildcard}."
25246 */
25247 for (i = 0; i < nbAttrs; i++) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025248 iattr = vctxt->attrInfos[i];
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025249 /*
25250 * SPEC (cvc-complex-type) (3)
25251 * Skip meta attributes.
25252 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025253 if (iattr->state != XML_SCHEMAS_ATTR_UNKNOWN)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025254 continue;
25255 /*
25256 * SPEC (cvc-complex-type)
Rob Richardsc6947bb2008-06-29 15:04:41 +000025257 * (3.2.2) "The attribute information item must be �valid� with
25258 * respect to it as defined in Item Valid (Wildcard) (�3.10.4)."
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025259 *
25260 * SPEC Item Valid (Wildcard) (cvc-wildcard)
Rob Richardsc6947bb2008-06-29 15:04:41 +000025261 * "... its [namespace name] must be �valid� with respect to
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025262 * the wildcard constraint, as defined in Wildcard allows
Rob Richardsc6947bb2008-06-29 15:04:41 +000025263 * Namespace Name (�3.10.4)."
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025264 */
25265 if (xmlSchemaCheckCVCWildcardNamespace(type->attributeWildcard,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025266 iattr->nsName) == 0) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025267 /*
25268 * Handle processContents.
25269 *
25270 * SPEC (cvc-wildcard):
25271 * processContents | context-determined declaration:
25272 * "strict" "mustFind"
25273 * "lax" "none"
25274 * "skip" "skip"
25275 */
25276 if (type->attributeWildcard->processContents ==
25277 XML_SCHEMAS_ANY_SKIP) {
25278 /*
25279 * context-determined declaration = "skip"
25280 *
25281 * SPEC PSVI Assessment Outcome (Attribute)
25282 * [validity] = "notKnown"
25283 * [validation attempted] = "none"
25284 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025285 iattr->state = XML_SCHEMAS_ATTR_WILD_SKIP;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025286 continue;
25287 }
25288 /*
25289 * Find an attribute declaration.
25290 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025291 iattr->decl = xmlSchemaGetAttributeDecl(vctxt->schema,
25292 iattr->localName, iattr->nsName);
25293 if (iattr->decl != NULL) {
25294 iattr->state = XML_SCHEMAS_ATTR_ASSESSED;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025295 /*
25296 * SPEC (cvc-complex-type)
25297 * (5) "Let [Definition:] the wild IDs be the set of
25298 * all attribute information item to which clause 3.2
Rob Richardsc6947bb2008-06-29 15:04:41 +000025299 * applied and whose �validation� resulted in a
25300 * �context-determined declaration� of mustFind or no
25301 * �context-determined declaration� at all, and whose
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025302 * [local name] and [namespace name] resolve (as
Rob Richardsc6947bb2008-06-29 15:04:41 +000025303 * defined by QName resolution (Instance) (�3.15.4)) to
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025304 * an attribute declaration whose {type definition} is
25305 * or is derived from ID. Then all of the following
25306 * must be true:"
25307 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025308 iattr->typeDef = WXS_ATTR_TYPEDEF(iattr->decl);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025309 if (xmlSchemaIsDerivedFromBuiltInType(
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025310 iattr->typeDef, XML_SCHEMAS_ID)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025311 /*
25312 * SPEC (5.1) "There must be no more than one
Rob Richardsc6947bb2008-06-29 15:04:41 +000025313 * item in �wild IDs�."
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025314 */
25315 if (wildIDs != 0) {
25316 /* VAL TODO */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025317 iattr->state = XML_SCHEMAS_ATTR_ERR_WILD_DUPLICATE_ID;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025318 TODO
25319 continue;
25320 }
25321 wildIDs++;
25322 /*
25323 * SPEC (cvc-complex-type)
Rob Richardsc6947bb2008-06-29 15:04:41 +000025324 * (5.2) "If �wild IDs� is non-empty, there must not
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025325 * be any attribute uses among the {attribute uses}
25326 * whose {attribute declaration}'s {type definition}
25327 * is or is derived from ID."
25328 */
Daniel Veillard2cdd17e2009-07-27 21:16:13 +020025329 if (attrUseList != NULL) {
25330 for (j = 0; j < attrUseList->nbItems; j++) {
25331 if (xmlSchemaIsDerivedFromBuiltInType(
25332 WXS_ATTRUSE_TYPEDEF(attrUseList->items[j]),
25333 XML_SCHEMAS_ID)) {
25334 /* URGENT VAL TODO: implement */
25335 iattr->state = XML_SCHEMAS_ATTR_ERR_WILD_AND_USE_ID;
25336 TODO
25337 break;
25338 }
25339 }
25340 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025341 }
25342 } else if (type->attributeWildcard->processContents ==
25343 XML_SCHEMAS_ANY_LAX) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025344 iattr->state = XML_SCHEMAS_ATTR_WILD_LAX_NO_DECL;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025345 /*
25346 * SPEC PSVI Assessment Outcome (Attribute)
25347 * [validity] = "notKnown"
25348 * [validation attempted] = "none"
25349 */
25350 } else {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025351 iattr->state = XML_SCHEMAS_ATTR_ERR_WILD_STRICT_NO_DECL;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025352 }
25353 }
25354 }
25355 }
25356
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025357 if (vctxt->nbAttrInfos == 0)
25358 return (0);
25359
25360 /*
Kasimier T. Buchcik9b02e292006-05-11 16:25:44 +000025361 * Get the owner element; needed for creation of default attributes.
25362 * This fixes bug #341337, reported by David Grohmann.
25363 */
25364 if (vctxt->options & XML_SCHEMA_VAL_VC_I_CREATE) {
25365 xmlSchemaNodeInfoPtr ielem = vctxt->elemInfos[vctxt->depth];
25366 if (ielem && ielem->node && ielem->node->doc)
25367 defAttrOwnerElem = ielem->node;
25368 }
25369 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025370 * Validate values, create default attributes, evaluate IDCs.
25371 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025372 for (i = 0; i < vctxt->nbAttrInfos; i++) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025373 iattr = vctxt->attrInfos[i];
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025374 /*
25375 * VAL TODO: Note that we won't try to resolve IDCs to
25376 * "lax" and "skip" validated attributes. Check what to
25377 * do in this case.
25378 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025379 if ((iattr->state != XML_SCHEMAS_ATTR_ASSESSED) &&
25380 (iattr->state != XML_SCHEMAS_ATTR_DEFAULT))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025381 continue;
25382 /*
25383 * VAL TODO: What to do if the type definition is missing?
25384 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025385 if (iattr->typeDef == NULL) {
25386 iattr->state = XML_SCHEMAS_ATTR_ERR_NO_TYPE;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025387 continue;
25388 }
25389
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025390 ACTIVATE_ATTRIBUTE(iattr);
Kasimier T. Buchcik828f6542005-06-09 11:23:39 +000025391 fixed = 0;
25392 xpathRes = 0;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025393
25394 if (vctxt->xpathStates != NULL) {
25395 /*
25396 * Evaluate IDCs.
25397 */
25398 xpathRes = xmlSchemaXPathEvaluate(vctxt,
25399 XML_ATTRIBUTE_NODE);
25400 if (xpathRes == -1) {
25401 VERROR_INT("xmlSchemaVAttributesComplex",
25402 "calling xmlSchemaXPathEvaluate()");
25403 goto internal_error;
25404 }
25405 }
25406
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025407 if (iattr->state == XML_SCHEMAS_ATTR_DEFAULT) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025408 /*
25409 * Default/fixed attributes.
Kasimier T. Buchcik9b02e292006-05-11 16:25:44 +000025410 * We need the value only if we need to resolve IDCs or
25411 * will create default attributes.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025412 */
Kasimier T. Buchcik9b02e292006-05-11 16:25:44 +000025413 if ((xpathRes) || (defAttrOwnerElem)) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025414 if (iattr->use->defValue != NULL) {
25415 iattr->value = (xmlChar *) iattr->use->defValue;
25416 iattr->val = iattr->use->defVal;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025417 } else {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025418 iattr->value = (xmlChar *) iattr->decl->defValue;
25419 iattr->val = iattr->decl->defVal;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025420 }
25421 /*
25422 * IDCs will consume the precomputed default value,
25423 * so we need to clone it.
25424 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025425 if (iattr->val == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025426 VERROR_INT("xmlSchemaVAttributesComplex",
25427 "default/fixed value on an attribute use was "
25428 "not precomputed");
25429 goto internal_error;
25430 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025431 iattr->val = xmlSchemaCopyValue(iattr->val);
25432 if (iattr->val == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025433 VERROR_INT("xmlSchemaVAttributesComplex",
25434 "calling xmlSchemaCopyValue()");
25435 goto internal_error;
25436 }
25437 }
25438 /*
25439 * PSVI: Add the default attribute to the current element.
25440 * VAL TODO: Should we use the *normalized* value? This currently
25441 * uses the *initial* value.
25442 */
Daniel Veillarddee23482008-04-11 12:58:43 +000025443
Kasimier T. Buchcik9b02e292006-05-11 16:25:44 +000025444 if (defAttrOwnerElem) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025445 xmlChar *normValue;
25446 const xmlChar *value;
25447
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025448 value = iattr->value;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025449 /*
25450 * Normalize the value.
25451 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025452 normValue = xmlSchemaNormalizeValue(iattr->typeDef,
25453 iattr->value);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025454 if (normValue != NULL)
25455 value = BAD_CAST normValue;
25456
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025457 if (iattr->nsName == NULL) {
Kasimier T. Buchcik9b02e292006-05-11 16:25:44 +000025458 if (xmlNewProp(defAttrOwnerElem,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025459 iattr->localName, value) == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025460 VERROR_INT("xmlSchemaVAttributesComplex",
25461 "callling xmlNewProp()");
25462 if (normValue != NULL)
25463 xmlFree(normValue);
25464 goto internal_error;
25465 }
25466 } else {
25467 xmlNsPtr ns;
25468
Kasimier T. Buchcik9b02e292006-05-11 16:25:44 +000025469 ns = xmlSearchNsByHref(defAttrOwnerElem->doc,
25470 defAttrOwnerElem, iattr->nsName);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025471 if (ns == NULL) {
25472 xmlChar prefix[12];
25473 int counter = 0;
25474
25475 /*
25476 * Create a namespace declaration on the validation
25477 * root node if no namespace declaration is in scope.
25478 */
25479 do {
25480 snprintf((char *) prefix, 12, "p%d", counter++);
Kasimier T. Buchcik9b02e292006-05-11 16:25:44 +000025481 ns = xmlSearchNs(defAttrOwnerElem->doc,
25482 defAttrOwnerElem, BAD_CAST prefix);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025483 if (counter > 1000) {
25484 VERROR_INT(
25485 "xmlSchemaVAttributesComplex",
25486 "could not compute a ns prefix for a "
25487 "default/fixed attribute");
25488 if (normValue != NULL)
25489 xmlFree(normValue);
25490 goto internal_error;
25491 }
25492 } while (ns != NULL);
25493 ns = xmlNewNs(vctxt->validationRoot,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025494 iattr->nsName, BAD_CAST prefix);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025495 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025496 /*
25497 * TODO:
25498 * http://lists.w3.org/Archives/Public/www-xml-schema-comments/2005JulSep/0406.html
25499 * If we have QNames: do we need to ensure there's a
25500 * prefix defined for the QName?
25501 */
Kasimier T. Buchcik9b02e292006-05-11 16:25:44 +000025502 xmlNewNsProp(defAttrOwnerElem, ns, iattr->localName, value);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025503 }
25504 if (normValue != NULL)
25505 xmlFree(normValue);
25506 }
25507 /*
25508 * Go directly to IDC evaluation.
25509 */
25510 goto eval_idcs;
25511 }
25512 /*
25513 * Validate the value.
25514 */
25515 if (vctxt->value != NULL) {
25516 /*
25517 * Free last computed value; just for safety reasons.
25518 */
25519 xmlSchemaFreeValue(vctxt->value);
25520 vctxt->value = NULL;
25521 }
25522 /*
25523 * Note that the attribute *use* can be unavailable, if
25524 * the attribute was a wild attribute.
25525 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025526 if ((iattr->decl->flags & XML_SCHEMAS_ATTR_FIXED) ||
25527 ((iattr->use != NULL) &&
25528 (iattr->use->flags & XML_SCHEMAS_ATTR_FIXED)))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025529 fixed = 1;
25530 else
25531 fixed = 0;
25532 /*
25533 * SPEC (cvc-attribute)
Rob Richardsc6947bb2008-06-29 15:04:41 +000025534 * (3) "The item's �normalized value� must be locally �valid�
Daniel Veillarddee23482008-04-11 12:58:43 +000025535 * with respect to that {type definition} as per
Rob Richardsc6947bb2008-06-29 15:04:41 +000025536 * String Valid (�3.14.4)."
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025537 *
25538 * VAL TODO: Do we already have the
25539 * "normalized attribute value" here?
25540 */
25541 if (xpathRes || fixed) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025542 iattr->flags |= XML_SCHEMA_NODE_INFO_VALUE_NEEDED;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025543 /*
25544 * Request a computed value.
25545 */
25546 res = xmlSchemaVCheckCVCSimpleType(
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000025547 ACTXT_CAST vctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025548 iattr->node, iattr->typeDef, iattr->value, &(iattr->val),
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025549 1, 1, 0);
25550 } else {
25551 res = xmlSchemaVCheckCVCSimpleType(
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000025552 ACTXT_CAST vctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025553 iattr->node, iattr->typeDef, iattr->value, NULL,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025554 1, 0, 0);
25555 }
Daniel Veillarddee23482008-04-11 12:58:43 +000025556
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025557 if (res != 0) {
25558 if (res == -1) {
25559 VERROR_INT("xmlSchemaVAttributesComplex",
25560 "calling xmlSchemaStreamValidateSimpleTypeValue()");
25561 goto internal_error;
25562 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025563 iattr->state = XML_SCHEMAS_ATTR_INVALID_VALUE;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025564 /*
25565 * SPEC PSVI Assessment Outcome (Attribute)
25566 * [validity] = "invalid"
25567 */
25568 goto eval_idcs;
25569 }
25570
Daniel Veillarddee23482008-04-11 12:58:43 +000025571 if (fixed) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025572 /*
25573 * SPEC Attribute Locally Valid (Use) (cvc-au)
Rob Richardsc6947bb2008-06-29 15:04:41 +000025574 * "For an attribute information item to be�valid�
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025575 * with respect to an attribute use its *normalized*
Rob Richardsc6947bb2008-06-29 15:04:41 +000025576 * value� must match the *canonical* lexical
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025577 * representation of the attribute use's {value
25578 * constraint}value, if it is present and fixed."
25579 *
25580 * VAL TODO: The requirement for the *canonical* value
25581 * will be removed in XML Schema 1.1.
25582 */
25583 /*
25584 * SPEC Attribute Locally Valid (cvc-attribute)
Rob Richardsc6947bb2008-06-29 15:04:41 +000025585 * (4) "The item's *actual* value� must match the *value* of
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025586 * the {value constraint}, if it is present and fixed."
25587 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025588 if (iattr->val == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025589 /* VAL TODO: A value was not precomputed. */
25590 TODO
25591 goto eval_idcs;
25592 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025593 if ((iattr->use != NULL) &&
25594 (iattr->use->defValue != NULL)) {
25595 if (iattr->use->defVal == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025596 /* VAL TODO: A default value was not precomputed. */
25597 TODO
25598 goto eval_idcs;
25599 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025600 iattr->vcValue = iattr->use->defValue;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025601 /*
25602 if (xmlSchemaCompareValuesWhtsp(attr->val,
25603 (xmlSchemaWhitespaceValueType) ws,
25604 attr->use->defVal,
25605 (xmlSchemaWhitespaceValueType) ws) != 0) {
25606 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025607 if (! xmlSchemaAreValuesEqual(iattr->val, iattr->use->defVal))
25608 iattr->state = XML_SCHEMAS_ATTR_ERR_FIXED_VALUE;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025609 } else {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025610 if (iattr->decl->defVal == NULL) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025611 /* VAL TODO: A default value was not precomputed. */
25612 TODO
25613 goto eval_idcs;
25614 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025615 iattr->vcValue = iattr->decl->defValue;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025616 /*
25617 if (xmlSchemaCompareValuesWhtsp(attr->val,
25618 (xmlSchemaWhitespaceValueType) ws,
25619 attrDecl->defVal,
25620 (xmlSchemaWhitespaceValueType) ws) != 0) {
25621 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025622 if (! xmlSchemaAreValuesEqual(iattr->val, iattr->decl->defVal))
25623 iattr->state = XML_SCHEMAS_ATTR_ERR_FIXED_VALUE;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025624 }
25625 /*
25626 * [validity] = "valid"
25627 */
25628 }
25629eval_idcs:
25630 /*
25631 * Evaluate IDCs.
25632 */
25633 if (xpathRes) {
25634 if (xmlSchemaXPathProcessHistory(vctxt,
25635 vctxt->depth +1) == -1) {
25636 VERROR_INT("xmlSchemaVAttributesComplex",
25637 "calling xmlSchemaXPathEvaluate()");
25638 goto internal_error;
25639 }
Kasimier T. Buchcik800cbac2005-08-09 12:31:55 +000025640 } else if (vctxt->xpathStates != NULL)
25641 xmlSchemaXPathPop(vctxt);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025642 }
25643
25644 /*
25645 * Report errors.
25646 */
25647 for (i = 0; i < vctxt->nbAttrInfos; i++) {
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025648 iattr = vctxt->attrInfos[i];
25649 if ((iattr->state == XML_SCHEMAS_ATTR_META) ||
25650 (iattr->state == XML_SCHEMAS_ATTR_ASSESSED) ||
25651 (iattr->state == XML_SCHEMAS_ATTR_WILD_SKIP) ||
25652 (iattr->state == XML_SCHEMAS_ATTR_WILD_LAX_NO_DECL))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025653 continue;
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025654 ACTIVATE_ATTRIBUTE(iattr);
25655 switch (iattr->state) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025656 case XML_SCHEMAS_ATTR_ERR_MISSING: {
25657 xmlChar *str = NULL;
25658 ACTIVATE_ELEM;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000025659 xmlSchemaCustomErr(ACTXT_CAST vctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025660 XML_SCHEMAV_CVC_COMPLEX_TYPE_4, NULL, NULL,
25661 "The attribute '%s' is required but missing",
25662 xmlSchemaFormatQName(&str,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025663 iattr->decl->targetNamespace,
25664 iattr->decl->name),
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025665 NULL);
25666 FREE_AND_NULL(str)
25667 break;
25668 }
25669 case XML_SCHEMAS_ATTR_ERR_NO_TYPE:
25670 VERROR(XML_SCHEMAV_CVC_ATTRIBUTE_2, NULL,
25671 "The type definition is absent");
25672 break;
25673 case XML_SCHEMAS_ATTR_ERR_FIXED_VALUE:
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000025674 xmlSchemaCustomErr(ACTXT_CAST vctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025675 XML_SCHEMAV_CVC_AU, NULL, NULL,
25676 "The value '%s' does not match the fixed "
Daniel Veillarddee23482008-04-11 12:58:43 +000025677 "value constraint '%s'",
25678 iattr->value, iattr->vcValue);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025679 break;
25680 case XML_SCHEMAS_ATTR_ERR_WILD_STRICT_NO_DECL:
25681 VERROR(XML_SCHEMAV_CVC_WILDCARD, NULL,
25682 "No matching global attribute declaration available, but "
25683 "demanded by the strict wildcard");
25684 break;
25685 case XML_SCHEMAS_ATTR_UNKNOWN:
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025686 if (iattr->metaType)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025687 break;
25688 /*
25689 * MAYBE VAL TODO: One might report different error messages
25690 * for the following errors.
25691 */
25692 if (type->attributeWildcard == NULL) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000025693 xmlSchemaIllegalAttrErr(ACTXT_CAST vctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025694 XML_SCHEMAV_CVC_COMPLEX_TYPE_3_2_1, iattr, NULL);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025695 } else {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000025696 xmlSchemaIllegalAttrErr(ACTXT_CAST vctxt,
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025697 XML_SCHEMAV_CVC_COMPLEX_TYPE_3_2_2, iattr, NULL);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025698 }
25699 break;
25700 default:
25701 break;
25702 }
25703 }
25704
25705 ACTIVATE_ELEM;
25706 return (0);
25707internal_error:
25708 ACTIVATE_ELEM;
25709 return (-1);
25710}
25711
25712static int
25713xmlSchemaValidateElemWildcard(xmlSchemaValidCtxtPtr vctxt,
25714 int *skip)
25715{
25716 xmlSchemaWildcardPtr wild = (xmlSchemaWildcardPtr) vctxt->inode->decl;
25717 /*
25718 * The namespace of the element was already identified to be
25719 * matching the wildcard.
25720 */
25721 if ((skip == NULL) || (wild == NULL) ||
25722 (wild->type != XML_SCHEMA_TYPE_ANY)) {
25723 VERROR_INT("xmlSchemaValidateElemWildcard",
25724 "bad arguments");
25725 return (-1);
25726 }
25727 *skip = 0;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025728 if (wild->processContents == XML_SCHEMAS_ANY_SKIP) {
25729 /*
25730 * URGENT VAL TODO: Either we need to position the stream to the
25731 * next sibling, or walk the whole subtree.
25732 */
25733 *skip = 1;
25734 return (0);
25735 }
25736 {
25737 xmlSchemaElementPtr decl = NULL;
25738
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000025739 decl = xmlSchemaGetElem(vctxt->schema,
Daniel Veillarddee23482008-04-11 12:58:43 +000025740 vctxt->inode->localName, vctxt->inode->nsName);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025741 if (decl != NULL) {
25742 vctxt->inode->decl = decl;
25743 return (0);
25744 }
25745 }
25746 if (wild->processContents == XML_SCHEMAS_ANY_STRICT) {
25747 /* VAL TODO: Change to proper error code. */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025748 VERROR(XML_SCHEMAV_CVC_ELT_1, NULL, /* WXS_BASIC_CAST wild */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025749 "No matching global element declaration available, but "
25750 "demanded by the strict wildcard");
25751 return (vctxt->err);
25752 }
25753 if (vctxt->nbAttrInfos != 0) {
25754 xmlSchemaAttrInfoPtr iattr;
25755 /*
25756 * SPEC Validation Rule: Schema-Validity Assessment (Element)
25757 * (1.2.1.2.1) - (1.2.1.2.3 )
25758 *
25759 * Use the xsi:type attribute for the type definition.
25760 */
25761 iattr = xmlSchemaGetMetaAttrInfo(vctxt,
25762 XML_SCHEMA_ATTR_INFO_META_XSI_TYPE);
25763 if (iattr != NULL) {
25764 if (xmlSchemaProcessXSIType(vctxt, iattr,
25765 &(vctxt->inode->typeDef), NULL) == -1) {
25766 VERROR_INT("xmlSchemaValidateElemWildcard",
25767 "calling xmlSchemaProcessXSIType() to "
25768 "process the attribute 'xsi:nil'");
25769 return (-1);
25770 }
25771 /*
25772 * Don't return an error on purpose.
25773 */
25774 return (0);
25775 }
25776 }
25777 /*
25778 * SPEC Validation Rule: Schema-Validity Assessment (Element)
25779 *
25780 * Fallback to "anyType".
25781 */
25782 vctxt->inode->typeDef =
25783 xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE);
25784 return (0);
25785}
25786
25787/*
25788* xmlSchemaCheckCOSValidDefault:
25789*
25790* This will be called if: not nilled, no content and a default/fixed
25791* value is provided.
25792*/
25793
25794static int
25795xmlSchemaCheckCOSValidDefault(xmlSchemaValidCtxtPtr vctxt,
25796 const xmlChar *value,
25797 xmlSchemaValPtr *val)
Daniel Veillarddee23482008-04-11 12:58:43 +000025798{
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025799 int ret = 0;
25800 xmlSchemaNodeInfoPtr inode = vctxt->inode;
25801
25802 /*
25803 * cos-valid-default:
25804 * Schema Component Constraint: Element Default Valid (Immediate)
Daniel Veillarddee23482008-04-11 12:58:43 +000025805 * For a string to be a valid default with respect to a type
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025806 * definition the appropriate case among the following must be true:
Daniel Veillarddee23482008-04-11 12:58:43 +000025807 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025808 if WXS_IS_COMPLEX(inode->typeDef) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025809 /*
25810 * Complex type.
25811 *
25812 * SPEC (2.1) "its {content type} must be a simple type definition
25813 * or mixed."
25814 * SPEC (2.2.2) "If the {content type} is mixed, then the {content
Rob Richardsc6947bb2008-06-29 15:04:41 +000025815 * type}'s particle must be �emptiable� as defined by
25816 * Particle Emptiable (�3.9.6)."
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025817 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025818 if ((! WXS_HAS_SIMPLE_CONTENT(inode->typeDef)) &&
25819 ((! WXS_HAS_MIXED_CONTENT(inode->typeDef)) ||
25820 (! WXS_EMPTIABLE(inode->typeDef)))) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025821 ret = XML_SCHEMAP_COS_VALID_DEFAULT_2_1;
25822 /* NOTE that this covers (2.2.2) as well. */
25823 VERROR(ret, NULL,
25824 "For a string to be a valid default, the type definition "
25825 "must be a simple type or a complex type with simple content "
25826 "or mixed content and a particle emptiable");
25827 return(ret);
25828 }
Daniel Veillarddee23482008-04-11 12:58:43 +000025829 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025830 /*
Daniel Veillarddee23482008-04-11 12:58:43 +000025831 * 1 If the type definition is a simple type definition, then the string
Rob Richardsc6947bb2008-06-29 15:04:41 +000025832 * must be �valid� with respect to that definition as defined by String
25833 * Valid (�3.14.4).
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025834 *
25835 * AND
25836 *
Daniel Veillarddee23482008-04-11 12:58:43 +000025837 * 2.2.1 If the {content type} is a simple type definition, then the
Rob Richardsc6947bb2008-06-29 15:04:41 +000025838 * string must be �valid� with respect to that simple type definition
25839 * as defined by String Valid (�3.14.4).
Daniel Veillarddee23482008-04-11 12:58:43 +000025840 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025841 if (WXS_IS_SIMPLE(inode->typeDef)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025842
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000025843 ret = xmlSchemaVCheckCVCSimpleType(ACTXT_CAST vctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025844 NULL, inode->typeDef, value, val, 1, 1, 0);
25845
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000025846 } else if (WXS_HAS_SIMPLE_CONTENT(inode->typeDef)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025847
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000025848 ret = xmlSchemaVCheckCVCSimpleType(ACTXT_CAST vctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025849 NULL, inode->typeDef->contentTypeDef, value, val, 1, 1, 0);
25850 }
25851 if (ret < 0) {
25852 VERROR_INT("xmlSchemaCheckCOSValidDefault",
25853 "calling xmlSchemaVCheckCVCSimpleType()");
Daniel Veillarddee23482008-04-11 12:58:43 +000025854 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025855 return (ret);
25856}
25857
25858static void
25859xmlSchemaVContentModelCallback(xmlSchemaValidCtxtPtr vctxt ATTRIBUTE_UNUSED,
25860 const xmlChar * name ATTRIBUTE_UNUSED,
25861 xmlSchemaElementPtr item,
25862 xmlSchemaNodeInfoPtr inode)
25863{
25864 inode->decl = item;
25865#ifdef DEBUG_CONTENT
25866 {
25867 xmlChar *str = NULL;
25868
25869 if (item->type == XML_SCHEMA_TYPE_ELEMENT) {
25870 xmlGenericError(xmlGenericErrorContext,
25871 "AUTOMATON callback for '%s' [declaration]\n",
25872 xmlSchemaFormatQName(&str,
25873 inode->localName, inode->nsName));
25874 } else {
25875 xmlGenericError(xmlGenericErrorContext,
25876 "AUTOMATON callback for '%s' [wildcard]\n",
25877 xmlSchemaFormatQName(&str,
25878 inode->localName, inode->nsName));
25879
25880 }
25881 FREE_AND_NULL(str)
25882 }
25883#endif
25884}
25885
25886static int
25887xmlSchemaValidatorPushElem(xmlSchemaValidCtxtPtr vctxt)
Daniel Veillarddee23482008-04-11 12:58:43 +000025888{
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025889 vctxt->inode = xmlSchemaGetFreshElemInfo(vctxt);
25890 if (vctxt->inode == NULL) {
25891 VERROR_INT("xmlSchemaValidatorPushElem",
25892 "calling xmlSchemaGetFreshElemInfo()");
25893 return (-1);
Daniel Veillarddee23482008-04-11 12:58:43 +000025894 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025895 vctxt->nbAttrInfos = 0;
25896 return (0);
25897}
25898
25899static int
25900xmlSchemaVCheckINodeDataType(xmlSchemaValidCtxtPtr vctxt,
25901 xmlSchemaNodeInfoPtr inode,
25902 xmlSchemaTypePtr type,
25903 const xmlChar *value)
25904{
25905 if (inode->flags & XML_SCHEMA_NODE_INFO_VALUE_NEEDED)
25906 return (xmlSchemaVCheckCVCSimpleType(
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000025907 ACTXT_CAST vctxt, NULL,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025908 type, value, &(inode->val), 1, 1, 0));
25909 else
25910 return (xmlSchemaVCheckCVCSimpleType(
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000025911 ACTXT_CAST vctxt, NULL,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025912 type, value, NULL, 1, 0, 0));
25913}
25914
25915
25916
Daniel Veillarddee23482008-04-11 12:58:43 +000025917/*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025918* Process END of element.
25919*/
25920static int
25921xmlSchemaValidatorPopElem(xmlSchemaValidCtxtPtr vctxt)
25922{
25923 int ret = 0;
25924 xmlSchemaNodeInfoPtr inode = vctxt->inode;
25925
25926 if (vctxt->nbAttrInfos != 0)
25927 xmlSchemaClearAttrInfos(vctxt);
25928 if (inode->flags & XML_SCHEMA_NODE_INFO_ERR_NOT_EXPECTED) {
25929 /*
25930 * This element was not expected;
25931 * we will not validate child elements of broken parents.
25932 * Skip validation of all content of the parent.
25933 */
25934 vctxt->skipDepth = vctxt->depth -1;
25935 goto end_elem;
Daniel Veillarddee23482008-04-11 12:58:43 +000025936 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025937 if ((inode->typeDef == NULL) ||
25938 (inode->flags & XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE)) {
25939 /*
Kasimier T. Buchcik84a56e32005-06-16 12:44:35 +000025940 * 1. the type definition might be missing if the element was
25941 * error prone
25942 * 2. it might be abstract.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025943 */
25944 goto end_elem;
25945 }
25946 /*
25947 * Check the content model.
25948 */
25949 if ((inode->typeDef->contentType == XML_SCHEMA_CONTENT_MIXED) ||
25950 (inode->typeDef->contentType == XML_SCHEMA_CONTENT_ELEMENTS)) {
25951
25952 /*
25953 * Workaround for "anyType".
25954 */
25955 if (inode->typeDef->builtInType == XML_SCHEMAS_ANYTYPE)
Daniel Veillarddee23482008-04-11 12:58:43 +000025956 goto character_content;
25957
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025958 if ((inode->flags & XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT) == 0) {
25959 xmlChar *values[10];
25960 int terminal, nbval = 10, nbneg;
25961
25962 if (inode->regexCtxt == NULL) {
25963 /*
25964 * Create the regex context.
25965 */
25966 inode->regexCtxt =
25967 xmlRegNewExecCtxt(inode->typeDef->contModel,
25968 (xmlRegExecCallbacks) xmlSchemaVContentModelCallback,
25969 vctxt);
25970 if (inode->regexCtxt == NULL) {
25971 VERROR_INT("xmlSchemaValidatorPopElem",
25972 "failed to create a regex context");
25973 goto internal_error;
25974 }
25975#ifdef DEBUG_AUTOMATA
25976 xmlGenericError(xmlGenericErrorContext,
25977 "AUTOMATON create on '%s'\n", inode->localName);
Daniel Veillarddee23482008-04-11 12:58:43 +000025978#endif
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025979 }
25980 /*
25981 * Get hold of the still expected content, since a further
25982 * call to xmlRegExecPushString() will loose this information.
Daniel Veillarddee23482008-04-11 12:58:43 +000025983 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025984 xmlRegExecNextValues(inode->regexCtxt,
25985 &nbval, &nbneg, &values[0], &terminal);
25986 ret = xmlRegExecPushString(inode->regexCtxt, NULL, NULL);
Daniel Veillard65fcf272007-07-11 17:55:30 +000025987 if ((ret<0) || ((ret==0) && (!INODE_NILLED(inode)))) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025988 /*
25989 * Still missing something.
25990 */
25991 ret = 1;
25992 inode->flags |=
25993 XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000025994 xmlSchemaComplexTypeErr(ACTXT_CAST vctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000025995 XML_SCHEMAV_ELEMENT_CONTENT, NULL, NULL,
25996 "Missing child element(s)",
25997 nbval, nbneg, values);
25998#ifdef DEBUG_AUTOMATA
25999 xmlGenericError(xmlGenericErrorContext,
26000 "AUTOMATON missing ERROR on '%s'\n",
26001 inode->localName);
26002#endif
26003 } else {
26004 /*
26005 * Content model is satisfied.
26006 */
26007 ret = 0;
26008#ifdef DEBUG_AUTOMATA
26009 xmlGenericError(xmlGenericErrorContext,
26010 "AUTOMATON succeeded on '%s'\n",
26011 inode->localName);
26012#endif
26013 }
26014
26015 }
26016 }
26017 if (inode->typeDef->contentType == XML_SCHEMA_CONTENT_ELEMENTS)
26018 goto end_elem;
26019
26020character_content:
26021
26022 if (vctxt->value != NULL) {
26023 xmlSchemaFreeValue(vctxt->value);
26024 vctxt->value = NULL;
26025 }
26026 /*
26027 * Check character content.
26028 */
26029 if (inode->decl == NULL) {
26030 /*
26031 * Speedup if no declaration exists.
26032 */
Daniel Veillarddee23482008-04-11 12:58:43 +000026033 if (WXS_IS_SIMPLE(inode->typeDef)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026034 ret = xmlSchemaVCheckINodeDataType(vctxt,
26035 inode, inode->typeDef, inode->value);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000026036 } else if (WXS_HAS_SIMPLE_CONTENT(inode->typeDef)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026037 ret = xmlSchemaVCheckINodeDataType(vctxt,
26038 inode, inode->typeDef->contentTypeDef,
26039 inode->value);
Daniel Veillarddee23482008-04-11 12:58:43 +000026040 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026041 if (ret < 0) {
26042 VERROR_INT("xmlSchemaValidatorPopElem",
26043 "calling xmlSchemaVCheckCVCSimpleType()");
26044 goto internal_error;
26045 }
26046 goto end_elem;
26047 }
26048 /*
Daniel Veillarddee23482008-04-11 12:58:43 +000026049 * cvc-elt (3.3.4) : 5
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026050 * The appropriate case among the following must be true:
26051 */
26052 /*
Daniel Veillarddee23482008-04-11 12:58:43 +000026053 * cvc-elt (3.3.4) : 5.1
26054 * If the declaration has a {value constraint},
26055 * the item has neither element nor character [children] and
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026056 * clause 3.2 has not applied, then all of the following must be true:
26057 */
26058 if ((inode->decl->value != NULL) &&
Daniel Veillarddee23482008-04-11 12:58:43 +000026059 (inode->flags & XML_SCHEMA_ELEM_INFO_EMPTY) &&
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026060 (! INODE_NILLED(inode))) {
26061 /*
Daniel Veillarddee23482008-04-11 12:58:43 +000026062 * cvc-elt (3.3.4) : 5.1.1
Rob Richardsc6947bb2008-06-29 15:04:41 +000026063 * If the �actual type definition� is a �local type definition�
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026064 * then the canonical lexical representation of the {value constraint}
Rob Richardsc6947bb2008-06-29 15:04:41 +000026065 * value must be a valid default for the �actual type definition� as
26066 * defined in Element Default Valid (Immediate) (�3.3.6).
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026067 */
Daniel Veillarddee23482008-04-11 12:58:43 +000026068 /*
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000026069 * NOTE: 'local' above means types acquired by xsi:type.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026070 * NOTE: Although the *canonical* value is stated, it is not
26071 * relevant if canonical or not. Additionally XML Schema 1.1
26072 * will removed this requirement as well.
26073 */
26074 if (inode->flags & XML_SCHEMA_ELEM_INFO_LOCAL_TYPE) {
26075
26076 ret = xmlSchemaCheckCOSValidDefault(vctxt,
26077 inode->decl->value, &(inode->val));
26078 if (ret != 0) {
26079 if (ret < 0) {
26080 VERROR_INT("xmlSchemaValidatorPopElem",
26081 "calling xmlSchemaCheckCOSValidDefault()");
26082 goto internal_error;
26083 }
26084 goto end_elem;
26085 }
26086 /*
26087 * Stop here, to avoid redundant validation of the value
26088 * (see following).
26089 */
26090 goto default_psvi;
Daniel Veillarddee23482008-04-11 12:58:43 +000026091 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026092 /*
Daniel Veillarddee23482008-04-11 12:58:43 +000026093 * cvc-elt (3.3.4) : 5.1.2
26094 * The element information item with the canonical lexical
26095 * representation of the {value constraint} value used as its
Rob Richardsc6947bb2008-06-29 15:04:41 +000026096 * �normalized value� must be �valid� with respect to the
26097 * �actual type definition� as defined by Element Locally Valid (Type)
26098 * (�3.3.4).
Daniel Veillarddee23482008-04-11 12:58:43 +000026099 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000026100 if (WXS_IS_SIMPLE(inode->typeDef)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026101 ret = xmlSchemaVCheckINodeDataType(vctxt,
26102 inode, inode->typeDef, inode->decl->value);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000026103 } else if (WXS_HAS_SIMPLE_CONTENT(inode->typeDef)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026104 ret = xmlSchemaVCheckINodeDataType(vctxt,
26105 inode, inode->typeDef->contentTypeDef,
Daniel Veillarddee23482008-04-11 12:58:43 +000026106 inode->decl->value);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026107 }
26108 if (ret != 0) {
26109 if (ret < 0) {
26110 VERROR_INT("xmlSchemaValidatorPopElem",
26111 "calling xmlSchemaVCheckCVCSimpleType()");
26112 goto internal_error;
26113 }
26114 goto end_elem;
26115 }
26116
26117default_psvi:
26118 /*
26119 * PSVI: Create a text node on the instance element.
26120 */
26121 if ((vctxt->options & XML_SCHEMA_VAL_VC_I_CREATE) &&
26122 (inode->node != NULL)) {
26123 xmlNodePtr textChild;
26124 xmlChar *normValue;
26125 /*
26126 * VAL TODO: Normalize the value.
Daniel Veillarddee23482008-04-11 12:58:43 +000026127 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026128 normValue = xmlSchemaNormalizeValue(inode->typeDef,
26129 inode->decl->value);
26130 if (normValue != NULL) {
26131 textChild = xmlNewText(BAD_CAST normValue);
26132 xmlFree(normValue);
26133 } else
26134 textChild = xmlNewText(inode->decl->value);
26135 if (textChild == NULL) {
26136 VERROR_INT("xmlSchemaValidatorPopElem",
26137 "calling xmlNewText()");
26138 goto internal_error;
26139 } else
Daniel Veillarddee23482008-04-11 12:58:43 +000026140 xmlAddChild(inode->node, textChild);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026141 }
Daniel Veillarddee23482008-04-11 12:58:43 +000026142
26143 } else if (! INODE_NILLED(inode)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026144 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000026145 * 5.2.1 The element information item must be �valid� with respect
26146 * to the �actual type definition� as defined by Element Locally
26147 * Valid (Type) (�3.3.4).
Daniel Veillarddee23482008-04-11 12:58:43 +000026148 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000026149 if (WXS_IS_SIMPLE(inode->typeDef)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026150 /*
26151 * SPEC (cvc-type) (3.1)
26152 * "If the type definition is a simple type definition, ..."
26153 * (3.1.3) "If clause 3.2 of Element Locally Valid
Rob Richardsc6947bb2008-06-29 15:04:41 +000026154 * (Element) (�3.3.4) did not apply, then the �normalized value�
26155 * must be �valid� with respect to the type definition as defined
26156 * by String Valid (�3.14.4).
Daniel Veillarddee23482008-04-11 12:58:43 +000026157 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026158 ret = xmlSchemaVCheckINodeDataType(vctxt,
26159 inode, inode->typeDef, inode->value);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000026160 } else if (WXS_HAS_SIMPLE_CONTENT(inode->typeDef)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026161 /*
26162 * SPEC (cvc-type) (3.2) "If the type definition is a complex type
26163 * definition, then the element information item must be
Rob Richardsc6947bb2008-06-29 15:04:41 +000026164 * �valid� with respect to the type definition as per
26165 * Element Locally Valid (Complex Type) (�3.4.4);"
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026166 *
26167 * SPEC (cvc-complex-type) (2.2)
Daniel Veillarddee23482008-04-11 12:58:43 +000026168 * "If the {content type} is a simple type definition, ...
Rob Richardsc6947bb2008-06-29 15:04:41 +000026169 * the �normalized value� of the element information item is
26170 * �valid� with respect to that simple type definition as
26171 * defined by String Valid (�3.14.4)."
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026172 */
26173 ret = xmlSchemaVCheckINodeDataType(vctxt,
26174 inode, inode->typeDef->contentTypeDef, inode->value);
Daniel Veillarddee23482008-04-11 12:58:43 +000026175 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026176 if (ret != 0) {
26177 if (ret < 0) {
26178 VERROR_INT("xmlSchemaValidatorPopElem",
26179 "calling xmlSchemaVCheckCVCSimpleType()");
26180 goto internal_error;
26181 }
26182 goto end_elem;
26183 }
26184 /*
Daniel Veillarddee23482008-04-11 12:58:43 +000026185 * 5.2.2 If there is a fixed {value constraint} and clause 3.2 has
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026186 * not applied, all of the following must be true:
26187 */
26188 if ((inode->decl->value != NULL) &&
26189 (inode->decl->flags & XML_SCHEMAS_ELEM_FIXED)) {
26190
26191 /*
26192 * TODO: We will need a computed value, when comparison is
26193 * done on computed values.
26194 */
26195 /*
Daniel Veillarddee23482008-04-11 12:58:43 +000026196 * 5.2.2.1 The element information item must have no element
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026197 * information item [children].
26198 */
26199 if (inode->flags &
26200 XML_SCHEMA_ELEM_INFO_HAS_ELEM_CONTENT) {
26201 ret = XML_SCHEMAV_CVC_ELT_5_2_2_1;
26202 VERROR(ret, NULL,
26203 "The content must not containt element nodes since "
26204 "there is a fixed value constraint");
26205 goto end_elem;
26206 } else {
26207 /*
Daniel Veillarddee23482008-04-11 12:58:43 +000026208 * 5.2.2.2 The appropriate case among the following must
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026209 * be true:
Daniel Veillarddee23482008-04-11 12:58:43 +000026210 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000026211 if (WXS_HAS_MIXED_CONTENT(inode->typeDef)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026212 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000026213 * 5.2.2.2.1 If the {content type} of the �actual type
26214 * definition� is mixed, then the *initial value* of the
Daniel Veillarddee23482008-04-11 12:58:43 +000026215 * item must match the canonical lexical representation
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026216 * of the {value constraint} value.
26217 *
Daniel Veillarddee23482008-04-11 12:58:43 +000026218 * ... the *initial value* of an element information
26219 * item is the string composed of, in order, the
26220 * [character code] of each character information item in
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026221 * the [children] of that element information item.
Daniel Veillarddee23482008-04-11 12:58:43 +000026222 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026223 if (! xmlStrEqual(inode->value, inode->decl->value)){
Daniel Veillarddee23482008-04-11 12:58:43 +000026224 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026225 * VAL TODO: Report invalid & expected values as well.
26226 * VAL TODO: Implement the canonical stuff.
26227 */
26228 ret = XML_SCHEMAV_CVC_ELT_5_2_2_2_1;
Daniel Veillarddee23482008-04-11 12:58:43 +000026229 xmlSchemaCustomErr(ACTXT_CAST vctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026230 ret, NULL, NULL,
26231 "The initial value '%s' does not match the fixed "
26232 "value constraint '%s'",
26233 inode->value, inode->decl->value);
26234 goto end_elem;
26235 }
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000026236 } else if (WXS_HAS_SIMPLE_CONTENT(inode->typeDef)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026237 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000026238 * 5.2.2.2.2 If the {content type} of the �actual type
26239 * definition� is a simple type definition, then the
Daniel Veillarddee23482008-04-11 12:58:43 +000026240 * *actual value* of the item must match the canonical
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026241 * lexical representation of the {value constraint} value.
26242 */
26243 /*
26244 * VAL TODO: *actual value* is the normalized value, impl.
26245 * this.
26246 * VAL TODO: Report invalid & expected values as well.
26247 * VAL TODO: Implement a comparison with the computed values.
26248 */
26249 if (! xmlStrEqual(inode->value,
26250 inode->decl->value)) {
26251 ret = XML_SCHEMAV_CVC_ELT_5_2_2_2_2;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000026252 xmlSchemaCustomErr(ACTXT_CAST vctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026253 ret, NULL, NULL,
26254 "The actual value '%s' does not match the fixed "
Daniel Veillarddee23482008-04-11 12:58:43 +000026255 "value constraint '%s'",
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026256 inode->value,
26257 inode->decl->value);
26258 goto end_elem;
Daniel Veillarddee23482008-04-11 12:58:43 +000026259 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026260 }
Daniel Veillarddee23482008-04-11 12:58:43 +000026261 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026262 }
26263 }
Daniel Veillarddee23482008-04-11 12:58:43 +000026264
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026265end_elem:
26266 if (vctxt->depth < 0) {
26267 /* TODO: raise error? */
26268 return (0);
26269 }
26270 if (vctxt->depth == vctxt->skipDepth)
26271 vctxt->skipDepth = -1;
26272 /*
26273 * Evaluate the history of XPath state objects.
Daniel Veillarddee23482008-04-11 12:58:43 +000026274 */
Kasimier T. Buchcik65c2f1d2005-10-17 12:39:58 +000026275 if (inode->appliedXPath &&
26276 (xmlSchemaXPathProcessHistory(vctxt, vctxt->depth) == -1))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026277 goto internal_error;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000026278 /*
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000026279 * MAYBE TODO:
Rob Richardsc6947bb2008-06-29 15:04:41 +000026280 * SPEC (6) "The element information item must be �valid� with
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000026281 * respect to each of the {identity-constraint definitions} as per
Rob Richardsc6947bb2008-06-29 15:04:41 +000026282 * Identity-constraint Satisfied (�3.11.4)."
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000026283 */
26284 /*
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000026285 * PSVI TODO: If we expose IDC node-tables via PSVI then the tables
26286 * need to be built in any case.
26287 * We will currently build IDC node-tables and bubble them only if
26288 * keyrefs do exist.
26289 */
Daniel Veillarddee23482008-04-11 12:58:43 +000026290
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000026291 /*
26292 * Add the current IDC target-nodes to the IDC node-tables.
26293 */
26294 if ((inode->idcMatchers != NULL) &&
26295 (vctxt->hasKeyrefs || vctxt->createIDCNodeTables))
26296 {
26297 if (xmlSchemaIDCFillNodeTables(vctxt, inode) == -1)
26298 goto internal_error;
26299 }
26300 /*
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000026301 * Validate IDC keyrefs.
26302 */
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000026303 if (vctxt->inode->hasKeyrefs)
26304 if (xmlSchemaCheckCVCIDCKeyRef(vctxt) == -1)
26305 goto internal_error;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000026306 /*
26307 * Merge/free the IDC table.
26308 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026309 if (inode->idcTable != NULL) {
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000026310#ifdef DEBUG_IDC_NODE_TABLE
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000026311 xmlSchemaDebugDumpIDCTable(stdout,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026312 inode->nsName,
26313 inode->localName,
26314 inode->idcTable);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000026315#endif
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000026316 if ((vctxt->depth > 0) &&
26317 (vctxt->hasKeyrefs || vctxt->createIDCNodeTables))
26318 {
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000026319 /*
26320 * Merge the IDC node table with the table of the parent node.
26321 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026322 if (xmlSchemaBubbleIDCNodeTables(vctxt) == -1)
26323 goto internal_error;
Daniel Veillarddee23482008-04-11 12:58:43 +000026324 }
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000026325 }
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000026326 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026327 * Clear the current ielem.
26328 * VAL TODO: Don't free the PSVI IDC tables if they are
26329 * requested for the PSVI.
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000026330 */
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000026331 xmlSchemaClearElemInfo(vctxt, inode);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000026332 /*
26333 * Skip further processing if we are on the validation root.
26334 */
26335 if (vctxt->depth == 0) {
26336 vctxt->depth--;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026337 vctxt->inode = NULL;
Kasimier T. Buchcikbd2a7d12005-02-16 12:27:25 +000026338 return (0);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000026339 }
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000026340 /*
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000026341 * Reset the keyrefDepth if needed.
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000026342 */
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000026343 if (vctxt->aidcs != NULL) {
26344 xmlSchemaIDCAugPtr aidc = vctxt->aidcs;
26345 do {
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000026346 if (aidc->keyrefDepth == vctxt->depth) {
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000026347 /*
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000026348 * A 'keyrefDepth' of a key/unique IDC matches the current
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000026349 * depth, this means that we are leaving the scope of the
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000026350 * top-most keyref IDC which refers to this IDC.
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000026351 */
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000026352 aidc->keyrefDepth = -1;
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000026353 }
26354 aidc = aidc->next;
26355 } while (aidc != NULL);
26356 }
Daniel Veillarddee23482008-04-11 12:58:43 +000026357 vctxt->depth--;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026358 vctxt->inode = vctxt->elemInfos[vctxt->depth];
Kasimier T. Buchcik25799ce2005-02-15 14:39:48 +000026359 /*
Rob Richardsc6947bb2008-06-29 15:04:41 +000026360 * VAL TODO: 7 If the element information item is the �validation root�, it must be
26361 * �valid� per Validation Root Valid (ID/IDREF) (�3.3.4).
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000026362 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026363 return (ret);
26364
26365internal_error:
26366 vctxt->err = -1;
26367 return (-1);
Daniel Veillard4255d502002-04-16 15:50:10 +000026368}
26369
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026370/*
26371* 3.4.4 Complex Type Definition Validation Rules
26372* Validation Rule: Element Locally Valid (Complex Type) (cvc-complex-type)
26373*/
Daniel Veillardc0826a72004-08-10 14:17:33 +000026374static int
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026375xmlSchemaValidateChildElem(xmlSchemaValidCtxtPtr vctxt)
William M. Brack2f2a6632004-08-20 23:09:47 +000026376{
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026377 xmlSchemaNodeInfoPtr pielem;
26378 xmlSchemaTypePtr ptype;
Daniel Veillard01fa6152004-06-29 17:04:39 +000026379 int ret = 0;
Daniel Veillard3646d642004-06-02 19:19:14 +000026380
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026381 if (vctxt->depth <= 0) {
26382 VERROR_INT("xmlSchemaValidateChildElem",
26383 "not intended for the validation root");
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000026384 return (-1);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026385 }
26386 pielem = vctxt->elemInfos[vctxt->depth -1];
26387 if (pielem->flags & XML_SCHEMA_ELEM_INFO_EMPTY)
26388 pielem->flags ^= XML_SCHEMA_ELEM_INFO_EMPTY;
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000026389 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026390 * Handle 'nilled' elements.
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000026391 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026392 if (INODE_NILLED(pielem)) {
26393 /*
26394 * SPEC (cvc-elt) (3.3.4) : (3.2.1)
26395 */
26396 ACTIVATE_PARENT_ELEM;
26397 ret = XML_SCHEMAV_CVC_ELT_3_2_1;
26398 VERROR(ret, NULL,
26399 "Neither character nor element content is allowed, "
26400 "because the element was 'nilled'");
26401 ACTIVATE_ELEM;
26402 goto unexpected_elem;
26403 }
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000026404
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026405 ptype = pielem->typeDef;
26406
26407 if (ptype->builtInType == XML_SCHEMAS_ANYTYPE) {
26408 /*
26409 * Workaround for "anyType": we have currently no content model
26410 * assigned for "anyType", so handle it explicitely.
26411 * "anyType" has an unbounded, lax "any" wildcard.
26412 */
26413 vctxt->inode->decl = xmlSchemaGetElem(vctxt->schema,
26414 vctxt->inode->localName,
26415 vctxt->inode->nsName);
26416
26417 if (vctxt->inode->decl == NULL) {
26418 xmlSchemaAttrInfoPtr iattr;
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000026419 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026420 * Process "xsi:type".
26421 * SPEC (cvc-assess-elt) (1.2.1.2.1) - (1.2.1.2.3)
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000026422 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026423 iattr = xmlSchemaGetMetaAttrInfo(vctxt,
26424 XML_SCHEMA_ATTR_INFO_META_XSI_TYPE);
26425 if (iattr != NULL) {
26426 ret = xmlSchemaProcessXSIType(vctxt, iattr,
26427 &(vctxt->inode->typeDef), NULL);
26428 if (ret != 0) {
26429 if (ret == -1) {
26430 VERROR_INT("xmlSchemaValidateChildElem",
26431 "calling xmlSchemaProcessXSIType() to "
26432 "process the attribute 'xsi:nil'");
Kasimier T. Buchcikbd2a7d12005-02-16 12:27:25 +000026433 return (-1);
Kasimier T. Buchcik187ea5f2005-04-19 11:25:43 +000026434 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026435 return (ret);
Daniel Veillard01fa6152004-06-29 17:04:39 +000026436 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026437 } else {
26438 /*
26439 * Fallback to "anyType".
26440 *
26441 * SPEC (cvc-assess-elt)
Rob Richardsc6947bb2008-06-29 15:04:41 +000026442 * "If the item cannot be �strictly assessed�, [...]
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026443 * an element information item's schema validity may be laxly
Rob Richardsc6947bb2008-06-29 15:04:41 +000026444 * assessed if its �context-determined declaration� is not
26445 * skip by �validating� with respect to the �ur-type
26446 * definition� as per Element Locally Valid (Type) (�3.3.4)."
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026447 */
26448 vctxt->inode->typeDef =
26449 xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE);
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000026450 }
26451 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026452 return (0);
26453 }
26454
26455 switch (ptype->contentType) {
26456 case XML_SCHEMA_CONTENT_EMPTY:
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000026457 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026458 * SPEC (2.1) "If the {content type} is empty, then the
26459 * element information item has no character or element
26460 * information item [children]."
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000026461 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026462 ACTIVATE_PARENT_ELEM
26463 ret = XML_SCHEMAV_CVC_COMPLEX_TYPE_2_1;
26464 VERROR(ret, NULL,
26465 "Element content is not allowed, "
26466 "because the content type is empty");
26467 ACTIVATE_ELEM
26468 goto unexpected_elem;
26469 break;
26470
26471 case XML_SCHEMA_CONTENT_MIXED:
26472 case XML_SCHEMA_CONTENT_ELEMENTS: {
26473 xmlRegExecCtxtPtr regexCtxt;
26474 xmlChar *values[10];
26475 int terminal, nbval = 10, nbneg;
26476
26477 /* VAL TODO: Optimized "anyType" validation.*/
26478
26479 if (ptype->contModel == NULL) {
26480 VERROR_INT("xmlSchemaValidateChildElem",
26481 "type has elem content but no content model");
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000026482 return (-1);
Kasimier T. Buchcik478d6932005-03-16 16:29:18 +000026483 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026484 /*
26485 * Safety belf for evaluation if the cont. model was already
26486 * examined to be invalid.
26487 */
26488 if (pielem->flags & XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT) {
26489 VERROR_INT("xmlSchemaValidateChildElem",
26490 "validating elem, but elem content is already invalid");
26491 return (-1);
26492 }
Kasimier T. Buchcikc3af19d2005-01-13 12:10:11 +000026493
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026494 regexCtxt = pielem->regexCtxt;
26495 if (regexCtxt == NULL) {
26496 /*
26497 * Create the regex context.
26498 */
26499 regexCtxt = xmlRegNewExecCtxt(ptype->contModel,
26500 (xmlRegExecCallbacks) xmlSchemaVContentModelCallback,
26501 vctxt);
26502 if (regexCtxt == NULL) {
26503 VERROR_INT("xmlSchemaValidateChildElem",
26504 "failed to create a regex context");
26505 return (-1);
26506 }
26507 pielem->regexCtxt = regexCtxt;
26508#ifdef DEBUG_AUTOMATA
26509 xmlGenericError(xmlGenericErrorContext, "AUTOMATA create on '%s'\n",
26510 pielem->localName);
26511#endif
26512 }
26513
26514 /*
26515 * SPEC (2.4) "If the {content type} is element-only or mixed,
26516 * then the sequence of the element information item's
26517 * element information item [children], if any, taken in
Rob Richardsc6947bb2008-06-29 15:04:41 +000026518 * order, is �valid� with respect to the {content type}'s
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026519 * particle, as defined in Element Sequence Locally Valid
Rob Richardsc6947bb2008-06-29 15:04:41 +000026520 * (Particle) (�3.9.4)."
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026521 */
26522 ret = xmlRegExecPushString2(regexCtxt,
26523 vctxt->inode->localName,
26524 vctxt->inode->nsName,
26525 vctxt->inode);
26526#ifdef DEBUG_AUTOMATA
26527 if (ret < 0)
26528 xmlGenericError(xmlGenericErrorContext,
26529 "AUTOMATON push ERROR for '%s' on '%s'\n",
26530 vctxt->inode->localName, pielem->localName);
26531 else
26532 xmlGenericError(xmlGenericErrorContext,
26533 "AUTOMATON push OK for '%s' on '%s'\n",
26534 vctxt->inode->localName, pielem->localName);
26535#endif
26536 if (vctxt->err == XML_SCHEMAV_INTERNAL) {
26537 VERROR_INT("xmlSchemaValidateChildElem",
26538 "calling xmlRegExecPushString2()");
26539 return (-1);
26540 }
26541 if (ret < 0) {
26542 xmlRegExecErrInfo(regexCtxt, NULL, &nbval, &nbneg,
26543 &values[0], &terminal);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000026544 xmlSchemaComplexTypeErr(ACTXT_CAST vctxt,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026545 XML_SCHEMAV_ELEMENT_CONTENT, NULL,NULL,
26546 "This element is not expected",
26547 nbval, nbneg, values);
26548 ret = vctxt->err;
26549 goto unexpected_elem;
26550 } else
26551 ret = 0;
Daniel Veillard01fa6152004-06-29 17:04:39 +000026552 }
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000026553 break;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026554 case XML_SCHEMA_CONTENT_SIMPLE:
26555 case XML_SCHEMA_CONTENT_BASIC:
26556 ACTIVATE_PARENT_ELEM
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000026557 if (WXS_IS_COMPLEX(ptype)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026558 /*
26559 * SPEC (cvc-complex-type) (2.2)
26560 * "If the {content type} is a simple type definition, then
26561 * the element information item has no element information
26562 * item [children], ..."
26563 */
26564 ret = XML_SCHEMAV_CVC_COMPLEX_TYPE_2_2;
26565 VERROR(ret, NULL, "Element content is not allowed, "
26566 "because the content type is a simple type definition");
26567 } else {
26568 /*
26569 * SPEC (cvc-type) (3.1.2) "The element information item must
26570 * have no element information item [children]."
26571 */
26572 ret = XML_SCHEMAV_CVC_TYPE_3_1_2;
26573 VERROR(ret, NULL, "Element content is not allowed, "
26574 "because the type definition is simple");
26575 }
26576 ACTIVATE_ELEM
26577 ret = vctxt->err;
26578 goto unexpected_elem;
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000026579 break;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026580
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000026581 default:
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000026582 break;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026583 }
26584 return (ret);
26585unexpected_elem:
26586 /*
26587 * Pop this element and set the skipDepth to skip
26588 * all further content of the parent element.
26589 */
26590 vctxt->skipDepth = vctxt->depth;
26591 vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_ERR_NOT_EXPECTED;
26592 pielem->flags |= XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT;
26593 return (ret);
26594}
26595
26596#define XML_SCHEMA_PUSH_TEXT_PERSIST 1
26597#define XML_SCHEMA_PUSH_TEXT_CREATED 2
26598#define XML_SCHEMA_PUSH_TEXT_VOLATILE 3
26599
26600static int
26601xmlSchemaVPushText(xmlSchemaValidCtxtPtr vctxt,
26602 int nodeType, const xmlChar *value, int len,
26603 int mode, int *consumed)
26604{
26605 /*
26606 * Unfortunately we have to duplicate the text sometimes.
26607 * OPTIMIZE: Maybe we could skip it, if:
26608 * 1. content type is simple
26609 * 2. whitespace is "collapse"
26610 * 3. it consists of whitespace only
26611 *
26612 * Process character content.
26613 */
26614 if (consumed != NULL)
26615 *consumed = 0;
26616 if (INODE_NILLED(vctxt->inode)) {
Daniel Veillarddee23482008-04-11 12:58:43 +000026617 /*
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026618 * SPEC cvc-elt (3.3.4 - 3.2.1)
26619 * "The element information item must have no character or
26620 * element information item [children]."
26621 */
26622 VERROR(XML_SCHEMAV_CVC_ELT_3_2_1, NULL,
26623 "Neither character nor element content is allowed "
26624 "because the element is 'nilled'");
26625 return (vctxt->err);
26626 }
26627 /*
26628 * SPEC (2.1) "If the {content type} is empty, then the
26629 * element information item has no character or element
26630 * information item [children]."
26631 */
26632 if (vctxt->inode->typeDef->contentType ==
Daniel Veillarddee23482008-04-11 12:58:43 +000026633 XML_SCHEMA_CONTENT_EMPTY) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026634 VERROR(XML_SCHEMAV_CVC_COMPLEX_TYPE_2_1, NULL,
26635 "Character content is not allowed, "
26636 "because the content type is empty");
26637 return (vctxt->err);
26638 }
26639
26640 if (vctxt->inode->typeDef->contentType ==
26641 XML_SCHEMA_CONTENT_ELEMENTS) {
26642 if ((nodeType != XML_TEXT_NODE) ||
26643 (! xmlSchemaIsBlank((xmlChar *) value, len))) {
Daniel Veillarddee23482008-04-11 12:58:43 +000026644 /*
26645 * SPEC cvc-complex-type (2.3)
26646 * "If the {content type} is element-only, then the
26647 * element information item has no character information
26648 * item [children] other than those whose [character
26649 * code] is defined as a white space in [XML 1.0 (Second
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026650 * Edition)]."
26651 */
26652 VERROR(XML_SCHEMAV_CVC_COMPLEX_TYPE_2_3, NULL,
26653 "Character content other than whitespace is not allowed "
26654 "because the content type is 'element-only'");
26655 return (vctxt->err);
26656 }
26657 return (0);
26658 }
Daniel Veillarddee23482008-04-11 12:58:43 +000026659
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026660 if ((value == NULL) || (value[0] == 0))
26661 return (0);
26662 /*
26663 * Save the value.
26664 * NOTE that even if the content type is *mixed*, we need the
26665 * *initial value* for default/fixed value constraints.
26666 */
26667 if ((vctxt->inode->typeDef->contentType == XML_SCHEMA_CONTENT_MIXED) &&
26668 ((vctxt->inode->decl == NULL) ||
26669 (vctxt->inode->decl->value == NULL)))
26670 return (0);
Daniel Veillarddee23482008-04-11 12:58:43 +000026671
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026672 if (vctxt->inode->value == NULL) {
26673 /*
26674 * Set the value.
26675 */
26676 switch (mode) {
26677 case XML_SCHEMA_PUSH_TEXT_PERSIST:
26678 /*
26679 * When working on a tree.
26680 */
26681 vctxt->inode->value = value;
26682 break;
26683 case XML_SCHEMA_PUSH_TEXT_CREATED:
26684 /*
26685 * When working with the reader.
26686 * The value will be freed by the element info.
26687 */
26688 vctxt->inode->value = value;
26689 if (consumed != NULL)
26690 *consumed = 1;
26691 vctxt->inode->flags |=
26692 XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES;
26693 break;
26694 case XML_SCHEMA_PUSH_TEXT_VOLATILE:
26695 /*
26696 * When working with SAX.
26697 * The value will be freed by the element info.
26698 */
26699 if (len != -1)
26700 vctxt->inode->value = BAD_CAST xmlStrndup(value, len);
26701 else
26702 vctxt->inode->value = BAD_CAST xmlStrdup(value);
26703 vctxt->inode->flags |=
26704 XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES;
26705 break;
26706 default:
26707 break;
26708 }
Kasimier T. Buchcik5bb0c082005-12-20 10:48:33 +000026709 } else {
26710 if (len < 0)
26711 len = xmlStrlen(value);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026712 /*
26713 * Concat the value.
Daniel Veillarddee23482008-04-11 12:58:43 +000026714 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026715 if (vctxt->inode->flags & XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES) {
Kasimier T. Buchcik9c215eb2005-06-21 08:38:49 +000026716 vctxt->inode->value = BAD_CAST xmlStrncat(
26717 (xmlChar *) vctxt->inode->value, value, len);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026718 } else {
26719 vctxt->inode->value =
Kasimier T. Buchcik84a56e32005-06-16 12:44:35 +000026720 BAD_CAST xmlStrncatNew(vctxt->inode->value, value, len);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026721 vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES;
26722 }
Daniel Veillarddee23482008-04-11 12:58:43 +000026723 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026724
26725 return (0);
Daniel Veillard4255d502002-04-16 15:50:10 +000026726}
26727
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000026728static int
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026729xmlSchemaValidateElem(xmlSchemaValidCtxtPtr vctxt)
Kasimier T. Buchcik9b77aa02005-03-04 22:04:16 +000026730{
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000026731 int ret = 0;
Daniel Veillard4255d502002-04-16 15:50:10 +000026732
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026733 if ((vctxt->skipDepth != -1) &&
26734 (vctxt->depth >= vctxt->skipDepth)) {
26735 VERROR_INT("xmlSchemaValidateElem",
26736 "in skip-state");
26737 goto internal_error;
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000026738 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026739 if (vctxt->xsiAssemble) {
Daniel Veillarddee23482008-04-11 12:58:43 +000026740 /*
Kasimier T. Buchcik215406f2005-12-07 12:14:09 +000026741 * We will stop validation if there was an error during
26742 * dynamic schema construction.
26743 * Note that we simply set @skipDepth to 0, this could
26744 * mean that a streaming document via SAX would be
26745 * still read to the end but it won't be validated any more.
26746 * TODO: If we are sure how to stop the validation at once
26747 * for all input scenarios, then this should be changed to
26748 * instantly stop the validation.
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000026749 */
Kasimier T. Buchcik215406f2005-12-07 12:14:09 +000026750 ret = xmlSchemaAssembleByXSI(vctxt);
26751 if (ret != 0) {
26752 if (ret == -1)
26753 goto internal_error;
26754 vctxt->skipDepth = 0;
26755 return(ret);
26756 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026757 }
26758 if (vctxt->depth > 0) {
26759 /*
26760 * Validate this element against the content model
26761 * of the parent.
26762 */
26763 ret = xmlSchemaValidateChildElem(vctxt);
26764 if (ret != 0) {
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000026765 if (ret < 0) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026766 VERROR_INT("xmlSchemaValidateElem",
26767 "calling xmlSchemaStreamValidateChildElement()");
26768 goto internal_error;
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000026769 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026770 goto exit;
26771 }
26772 if (vctxt->depth == vctxt->skipDepth)
26773 goto exit;
26774 if ((vctxt->inode->decl == NULL) &&
26775 (vctxt->inode->typeDef == NULL)) {
26776 VERROR_INT("xmlSchemaValidateElem",
26777 "the child element was valid but neither the "
26778 "declaration nor the type was set");
26779 goto internal_error;
26780 }
26781 } else {
26782 /*
26783 * Get the declaration of the validation root.
26784 */
26785 vctxt->inode->decl = xmlSchemaGetElem(vctxt->schema,
26786 vctxt->inode->localName,
26787 vctxt->inode->nsName);
26788 if (vctxt->inode->decl == NULL) {
Kasimier T. Buchcik9ca11bf2005-06-14 19:24:47 +000026789 ret = XML_SCHEMAV_CVC_ELT_1;
26790 VERROR(ret, NULL,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026791 "No matching global declaration available "
26792 "for the validation root");
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026793 goto exit;
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000026794 }
26795 }
Kasimier T. Buchcik7f3efa92005-03-07 17:41:58 +000026796
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026797 if (vctxt->inode->decl == NULL)
26798 goto type_validation;
26799
26800 if (vctxt->inode->decl->type == XML_SCHEMA_TYPE_ANY) {
26801 int skip;
26802 /*
26803 * Wildcards.
26804 */
26805 ret = xmlSchemaValidateElemWildcard(vctxt, &skip);
26806 if (ret != 0) {
26807 if (ret < 0) {
26808 VERROR_INT("xmlSchemaValidateElem",
26809 "calling xmlSchemaValidateElemWildcard()");
26810 goto internal_error;
26811 }
26812 goto exit;
26813 }
26814 if (skip) {
26815 vctxt->skipDepth = vctxt->depth;
26816 goto exit;
26817 }
26818 /*
26819 * The declaration might be set by the wildcard validation,
26820 * when the processContents is "lax" or "strict".
26821 */
26822 if (vctxt->inode->decl->type != XML_SCHEMA_TYPE_ELEMENT) {
26823 /*
26824 * Clear the "decl" field to not confuse further processing.
26825 */
26826 vctxt->inode->decl = NULL;
26827 goto type_validation;
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000026828 }
Daniel Veillard4255d502002-04-16 15:50:10 +000026829 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026830 /*
26831 * Validate against the declaration.
26832 */
26833 ret = xmlSchemaValidateElemDecl(vctxt);
26834 if (ret != 0) {
26835 if (ret < 0) {
26836 VERROR_INT("xmlSchemaValidateElem",
26837 "calling xmlSchemaValidateElemDecl()");
26838 goto internal_error;
26839 }
26840 goto exit;
26841 }
Kasimier T. Buchcik9ca11bf2005-06-14 19:24:47 +000026842 /*
26843 * Validate against the type definition.
26844 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026845type_validation:
26846
26847 if (vctxt->inode->typeDef == NULL) {
26848 vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE;
26849 ret = XML_SCHEMAV_CVC_TYPE_1;
26850 VERROR(ret, NULL,
26851 "The type definition is absent");
26852 goto exit;
Daniel Veillarddee23482008-04-11 12:58:43 +000026853 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026854 if (vctxt->inode->typeDef->flags & XML_SCHEMAS_TYPE_ABSTRACT) {
26855 vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE;
26856 ret = XML_SCHEMAV_CVC_TYPE_2;
26857 VERROR(ret, NULL,
Daniel Veillarddee23482008-04-11 12:58:43 +000026858 "The type definition is abstract");
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026859 goto exit;
26860 }
26861 /*
Kasimier T. Buchcik9ca11bf2005-06-14 19:24:47 +000026862 * Evaluate IDCs. Do it here, since new IDC matchers are registered
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026863 * during validation against the declaration. This must be done
26864 * _before_ attribute validation.
26865 */
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000026866 if (vctxt->xpathStates != NULL) {
26867 ret = xmlSchemaXPathEvaluate(vctxt, XML_ELEMENT_NODE);
Kasimier T. Buchcik65c2f1d2005-10-17 12:39:58 +000026868 vctxt->inode->appliedXPath = 1;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000026869 if (ret == -1) {
26870 VERROR_INT("xmlSchemaValidateElem",
26871 "calling xmlSchemaXPathEvaluate()");
26872 goto internal_error;
26873 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026874 }
26875 /*
26876 * Validate attributes.
26877 */
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000026878 if (WXS_IS_COMPLEX(vctxt->inode->typeDef)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026879 if ((vctxt->nbAttrInfos != 0) ||
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000026880 (vctxt->inode->typeDef->attrUses != NULL)) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026881
26882 ret = xmlSchemaVAttributesComplex(vctxt);
26883 }
26884 } else if (vctxt->nbAttrInfos != 0) {
26885
26886 ret = xmlSchemaVAttributesSimple(vctxt);
26887 }
26888 /*
26889 * Clear registered attributes.
26890 */
26891 if (vctxt->nbAttrInfos != 0)
26892 xmlSchemaClearAttrInfos(vctxt);
26893 if (ret == -1) {
26894 VERROR_INT("xmlSchemaValidateElem",
26895 "calling attributes validation");
26896 goto internal_error;
26897 }
26898 /*
26899 * Don't return an error if attributes are invalid on purpose.
26900 */
26901 ret = 0;
26902
26903exit:
26904 if (ret != 0)
26905 vctxt->skipDepth = vctxt->depth;
26906 return (ret);
26907internal_error:
26908 return (-1);
Daniel Veillard4255d502002-04-16 15:50:10 +000026909}
26910
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026911#ifdef XML_SCHEMA_READER_ENABLED
26912static int
26913xmlSchemaVReaderWalk(xmlSchemaValidCtxtPtr vctxt)
Kasimier T. Buchcik5eba91f2004-09-08 09:17:27 +000026914{
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026915 const int WHTSP = 13, SIGN_WHTSP = 14, END_ELEM = 15;
26916 int depth, nodeType, ret = 0, consumed;
26917 xmlSchemaNodeInfoPtr ielem;
Kasimier T. Buchcik5eba91f2004-09-08 09:17:27 +000026918
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026919 vctxt->depth = -1;
26920 ret = xmlTextReaderRead(vctxt->reader);
26921 /*
26922 * Move to the document element.
26923 */
26924 while (ret == 1) {
26925 nodeType = xmlTextReaderNodeType(vctxt->reader);
26926 if (nodeType == XML_ELEMENT_NODE)
26927 goto root_found;
26928 ret = xmlTextReaderRead(vctxt->reader);
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000026929 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026930 goto exit;
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000026931
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026932root_found:
26933
26934 do {
26935 depth = xmlTextReaderDepth(vctxt->reader);
26936 nodeType = xmlTextReaderNodeType(vctxt->reader);
26937
26938 if (nodeType == XML_ELEMENT_NODE) {
Daniel Veillarddee23482008-04-11 12:58:43 +000026939
Kasimier T. Buchcik84a56e32005-06-16 12:44:35 +000026940 vctxt->depth++;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000026941 if (xmlSchemaValidatorPushElem(vctxt) == -1) {
26942 VERROR_INT("xmlSchemaVReaderWalk",
26943 "calling xmlSchemaValidatorPushElem()");
26944 goto internal_error;
26945 }
26946 ielem = vctxt->inode;
26947 ielem->localName = xmlTextReaderLocalName(vctxt->reader);
26948 ielem->nsName = xmlTextReaderNamespaceUri(vctxt->reader);
26949 ielem->flags |= XML_SCHEMA_NODE_INFO_FLAG_OWNED_NAMES;
26950 /*
26951 * Is the element empty?
26952 */
26953 ret = xmlTextReaderIsEmptyElement(vctxt->reader);
26954 if (ret == -1) {
26955 VERROR_INT("xmlSchemaVReaderWalk",
26956 "calling xmlTextReaderIsEmptyElement()");
26957 goto internal_error;
26958 }
26959 if (ret) {
26960 ielem->flags |= XML_SCHEMA_ELEM_INFO_EMPTY;
26961 }
26962 /*
26963 * Register attributes.
26964 */
26965 vctxt->nbAttrInfos = 0;
26966 ret = xmlTextReaderMoveToFirstAttribute(vctxt->reader);
26967 if (ret == -1) {
26968 VERROR_INT("xmlSchemaVReaderWalk",
26969 "calling xmlTextReaderMoveToFirstAttribute()");
26970 goto internal_error;
26971 }
26972 if (ret == 1) {
26973 do {
26974 /*
26975 * VAL TODO: How do we know that the reader works on a
26976 * node tree, to be able to pass a node here?
26977 */
26978 if (xmlSchemaValidatorPushAttribute(vctxt, NULL,
26979 (const xmlChar *) xmlTextReaderLocalName(vctxt->reader),
26980 xmlTextReaderNamespaceUri(vctxt->reader), 1,
26981 xmlTextReaderValue(vctxt->reader), 1) == -1) {
26982
26983 VERROR_INT("xmlSchemaVReaderWalk",
26984 "calling xmlSchemaValidatorPushAttribute()");
26985 goto internal_error;
26986 }
26987 ret = xmlTextReaderMoveToNextAttribute(vctxt->reader);
26988 if (ret == -1) {
26989 VERROR_INT("xmlSchemaVReaderWalk",
26990 "calling xmlTextReaderMoveToFirstAttribute()");
26991 goto internal_error;
26992 }
26993 } while (ret == 1);
26994 /*
26995 * Back to element position.
26996 */
26997 ret = xmlTextReaderMoveToElement(vctxt->reader);
26998 if (ret == -1) {
26999 VERROR_INT("xmlSchemaVReaderWalk",
27000 "calling xmlTextReaderMoveToElement()");
27001 goto internal_error;
27002 }
27003 }
27004 /*
27005 * Validate the element.
27006 */
27007 ret= xmlSchemaValidateElem(vctxt);
27008 if (ret != 0) {
27009 if (ret == -1) {
27010 VERROR_INT("xmlSchemaVReaderWalk",
27011 "calling xmlSchemaValidateElem()");
27012 goto internal_error;
27013 }
27014 goto exit;
27015 }
27016 if (vctxt->depth == vctxt->skipDepth) {
27017 int curDepth;
27018 /*
27019 * Skip all content.
27020 */
27021 if ((ielem->flags & XML_SCHEMA_ELEM_INFO_EMPTY) == 0) {
27022 ret = xmlTextReaderRead(vctxt->reader);
27023 curDepth = xmlTextReaderDepth(vctxt->reader);
27024 while ((ret == 1) && (curDepth != depth)) {
27025 ret = xmlTextReaderRead(vctxt->reader);
27026 curDepth = xmlTextReaderDepth(vctxt->reader);
27027 }
27028 if (ret < 0) {
27029 /*
27030 * VAL TODO: A reader error occured; what to do here?
27031 */
27032 ret = 1;
27033 goto exit;
27034 }
27035 }
27036 goto leave_elem;
27037 }
27038 /*
27039 * READER VAL TODO: Is an END_ELEM really never called
27040 * if the elem is empty?
27041 */
27042 if (ielem->flags & XML_SCHEMA_ELEM_INFO_EMPTY)
27043 goto leave_elem;
27044 } else if (nodeType == END_ELEM) {
27045 /*
27046 * Process END of element.
27047 */
27048leave_elem:
27049 ret = xmlSchemaValidatorPopElem(vctxt);
27050 if (ret != 0) {
27051 if (ret < 0) {
27052 VERROR_INT("xmlSchemaVReaderWalk",
27053 "calling xmlSchemaValidatorPopElem()");
27054 goto internal_error;
27055 }
27056 goto exit;
27057 }
27058 if (vctxt->depth >= 0)
27059 ielem = vctxt->inode;
27060 else
27061 ielem = NULL;
27062 } else if ((nodeType == XML_TEXT_NODE) ||
27063 (nodeType == XML_CDATA_SECTION_NODE) ||
27064 (nodeType == WHTSP) ||
27065 (nodeType == SIGN_WHTSP)) {
27066 /*
27067 * Process character content.
27068 */
27069 xmlChar *value;
27070
27071 if ((nodeType == WHTSP) || (nodeType == SIGN_WHTSP))
27072 nodeType = XML_TEXT_NODE;
27073
27074 value = xmlTextReaderValue(vctxt->reader);
27075 ret = xmlSchemaVPushText(vctxt, nodeType, BAD_CAST value,
27076 -1, XML_SCHEMA_PUSH_TEXT_CREATED, &consumed);
27077 if (! consumed)
27078 xmlFree(value);
27079 if (ret == -1) {
27080 VERROR_INT("xmlSchemaVReaderWalk",
27081 "calling xmlSchemaVPushText()");
27082 goto internal_error;
27083 }
27084 } else if ((nodeType == XML_ENTITY_NODE) ||
27085 (nodeType == XML_ENTITY_REF_NODE)) {
27086 /*
27087 * VAL TODO: What to do with entities?
27088 */
27089 TODO
27090 }
27091 /*
27092 * Read next node.
27093 */
27094 ret = xmlTextReaderRead(vctxt->reader);
27095 } while (ret == 1);
27096
27097exit:
27098 return (ret);
27099internal_error:
27100 return (-1);
Daniel Veillard4255d502002-04-16 15:50:10 +000027101}
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027102#endif
Daniel Veillard4255d502002-04-16 15:50:10 +000027103
27104/************************************************************************
27105 * *
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027106 * SAX validation handlers *
Daniel Veillard4255d502002-04-16 15:50:10 +000027107 * *
27108 ************************************************************************/
27109
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027110/*
27111* Process text content.
27112*/
27113static void
Daniel Veillarddee23482008-04-11 12:58:43 +000027114xmlSchemaSAXHandleText(void *ctx,
27115 const xmlChar * ch,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027116 int len)
27117{
27118 xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctx;
27119
27120 if (vctxt->depth < 0)
27121 return;
27122 if ((vctxt->skipDepth != -1) && (vctxt->depth >= vctxt->skipDepth))
27123 return;
27124 if (vctxt->inode->flags & XML_SCHEMA_ELEM_INFO_EMPTY)
27125 vctxt->inode->flags ^= XML_SCHEMA_ELEM_INFO_EMPTY;
27126 if (xmlSchemaVPushText(vctxt, XML_TEXT_NODE, ch, len,
27127 XML_SCHEMA_PUSH_TEXT_VOLATILE, NULL) == -1) {
27128 VERROR_INT("xmlSchemaSAXHandleCDataSection",
27129 "calling xmlSchemaVPushText()");
27130 vctxt->err = -1;
27131 xmlStopParser(vctxt->parserCtxt);
27132 }
27133}
27134
27135/*
27136* Process CDATA content.
27137*/
27138static void
Daniel Veillarddee23482008-04-11 12:58:43 +000027139xmlSchemaSAXHandleCDataSection(void *ctx,
27140 const xmlChar * ch,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027141 int len)
Daniel Veillarddee23482008-04-11 12:58:43 +000027142{
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027143 xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctx;
27144
27145 if (vctxt->depth < 0)
27146 return;
27147 if ((vctxt->skipDepth != -1) && (vctxt->depth >= vctxt->skipDepth))
27148 return;
27149 if (vctxt->inode->flags & XML_SCHEMA_ELEM_INFO_EMPTY)
27150 vctxt->inode->flags ^= XML_SCHEMA_ELEM_INFO_EMPTY;
27151 if (xmlSchemaVPushText(vctxt, XML_CDATA_SECTION_NODE, ch, len,
27152 XML_SCHEMA_PUSH_TEXT_VOLATILE, NULL) == -1) {
27153 VERROR_INT("xmlSchemaSAXHandleCDataSection",
27154 "calling xmlSchemaVPushText()");
27155 vctxt->err = -1;
27156 xmlStopParser(vctxt->parserCtxt);
27157 }
27158}
27159
27160static void
27161xmlSchemaSAXHandleReference(void *ctx ATTRIBUTE_UNUSED,
27162 const xmlChar * name ATTRIBUTE_UNUSED)
27163{
27164 xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctx;
27165
27166 if (vctxt->depth < 0)
27167 return;
27168 if ((vctxt->skipDepth != -1) && (vctxt->depth >= vctxt->skipDepth))
27169 return;
27170 /* SAX VAL TODO: What to do here? */
27171 TODO
27172}
27173
27174static void
27175xmlSchemaSAXHandleStartElementNs(void *ctx,
Daniel Veillarddee23482008-04-11 12:58:43 +000027176 const xmlChar * localname,
27177 const xmlChar * prefix ATTRIBUTE_UNUSED,
27178 const xmlChar * URI,
27179 int nb_namespaces,
27180 const xmlChar ** namespaces,
27181 int nb_attributes,
27182 int nb_defaulted ATTRIBUTE_UNUSED,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027183 const xmlChar ** attributes)
Daniel Veillarddee23482008-04-11 12:58:43 +000027184{
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027185 xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctx;
27186 int ret;
27187 xmlSchemaNodeInfoPtr ielem;
27188 int i, j;
Daniel Veillarddee23482008-04-11 12:58:43 +000027189
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027190 /*
27191 * SAX VAL TODO: What to do with nb_defaulted?
27192 */
27193 /*
Kasimier T. Buchcik84a56e32005-06-16 12:44:35 +000027194 * Skip elements if inside a "skip" wildcard or invalid.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027195 */
Kasimier T. Buchcik84a56e32005-06-16 12:44:35 +000027196 vctxt->depth++;
27197 if ((vctxt->skipDepth != -1) && (vctxt->depth >= vctxt->skipDepth))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027198 return;
27199 /*
27200 * Push the element.
27201 */
27202 if (xmlSchemaValidatorPushElem(vctxt) == -1) {
27203 VERROR_INT("xmlSchemaSAXHandleStartElementNs",
27204 "calling xmlSchemaValidatorPushElem()");
27205 goto internal_error;
27206 }
27207 ielem = vctxt->inode;
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000027208 /*
27209 * TODO: Is this OK?
27210 */
27211 ielem->nodeLine = xmlSAX2GetLineNumber(vctxt->parserCtxt);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027212 ielem->localName = localname;
27213 ielem->nsName = URI;
27214 ielem->flags |= XML_SCHEMA_ELEM_INFO_EMPTY;
27215 /*
27216 * Register namespaces on the elem info.
Daniel Veillarddee23482008-04-11 12:58:43 +000027217 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027218 if (nb_namespaces != 0) {
27219 /*
27220 * Although the parser builds its own namespace list,
27221 * we have no access to it, so we'll use an own one.
27222 */
Daniel Veillarddee23482008-04-11 12:58:43 +000027223 for (i = 0, j = 0; i < nb_namespaces; i++, j += 2) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027224 /*
27225 * Store prefix and namespace name.
Daniel Veillarddee23482008-04-11 12:58:43 +000027226 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027227 if (ielem->nsBindings == NULL) {
27228 ielem->nsBindings =
27229 (const xmlChar **) xmlMalloc(10 *
27230 sizeof(const xmlChar *));
27231 if (ielem->nsBindings == NULL) {
27232 xmlSchemaVErrMemory(vctxt,
27233 "allocating namespace bindings for SAX validation",
27234 NULL);
27235 goto internal_error;
27236 }
27237 ielem->nbNsBindings = 0;
27238 ielem->sizeNsBindings = 5;
27239 } else if (ielem->sizeNsBindings <= ielem->nbNsBindings) {
27240 ielem->sizeNsBindings *= 2;
27241 ielem->nsBindings =
27242 (const xmlChar **) xmlRealloc(
27243 (void *) ielem->nsBindings,
Kasimier T. Buchcik84a56e32005-06-16 12:44:35 +000027244 ielem->sizeNsBindings * 2 * sizeof(const xmlChar *));
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027245 if (ielem->nsBindings == NULL) {
27246 xmlSchemaVErrMemory(vctxt,
27247 "re-allocating namespace bindings for SAX validation",
27248 NULL);
27249 goto internal_error;
27250 }
27251 }
27252
27253 ielem->nsBindings[ielem->nbNsBindings * 2] = namespaces[j];
27254 if (namespaces[j+1][0] == 0) {
27255 /*
27256 * Handle xmlns="".
27257 */
27258 ielem->nsBindings[ielem->nbNsBindings * 2 + 1] = NULL;
27259 } else
27260 ielem->nsBindings[ielem->nbNsBindings * 2 + 1] =
27261 namespaces[j+1];
Daniel Veillarddee23482008-04-11 12:58:43 +000027262 ielem->nbNsBindings++;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027263 }
27264 }
27265 /*
27266 * Register attributes.
27267 * SAX VAL TODO: We are not adding namespace declaration
27268 * attributes yet.
27269 */
27270 if (nb_attributes != 0) {
27271 xmlChar *value;
27272
27273 for (j = 0, i = 0; i < nb_attributes; i++, j += 5) {
27274 /*
27275 * Duplicate the value.
Daniel Veillarddee23482008-04-11 12:58:43 +000027276 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027277 value = xmlStrndup(attributes[j+3],
27278 attributes[j+4] - attributes[j+3]);
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000027279 /*
27280 * TODO: Set the node line.
27281 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027282 ret = xmlSchemaValidatorPushAttribute(vctxt,
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000027283 NULL, ielem->nodeLine, attributes[j], attributes[j+2], 0,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027284 value, 1);
27285 if (ret == -1) {
27286 VERROR_INT("xmlSchemaSAXHandleStartElementNs",
27287 "calling xmlSchemaValidatorPushAttribute()");
27288 goto internal_error;
27289 }
27290 }
27291 }
27292 /*
27293 * Validate the element.
27294 */
27295 ret = xmlSchemaValidateElem(vctxt);
27296 if (ret != 0) {
27297 if (ret == -1) {
27298 VERROR_INT("xmlSchemaSAXHandleStartElementNs",
27299 "calling xmlSchemaValidateElem()");
27300 goto internal_error;
27301 }
27302 goto exit;
Daniel Veillarddee23482008-04-11 12:58:43 +000027303 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027304
27305exit:
27306 return;
27307internal_error:
27308 vctxt->err = -1;
27309 xmlStopParser(vctxt->parserCtxt);
27310 return;
27311}
27312
27313static void
27314xmlSchemaSAXHandleEndElementNs(void *ctx,
27315 const xmlChar * localname ATTRIBUTE_UNUSED,
27316 const xmlChar * prefix ATTRIBUTE_UNUSED,
27317 const xmlChar * URI ATTRIBUTE_UNUSED)
27318{
27319 xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctx;
27320 int res;
27321
27322 /*
Kasimier T. Buchcik84a56e32005-06-16 12:44:35 +000027323 * Skip elements if inside a "skip" wildcard or if invalid.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027324 */
27325 if (vctxt->skipDepth != -1) {
27326 if (vctxt->depth > vctxt->skipDepth) {
27327 vctxt->depth--;
27328 return;
27329 } else
27330 vctxt->skipDepth = -1;
27331 }
27332 /*
27333 * SAX VAL TODO: Just a temporary check.
27334 */
27335 if ((!xmlStrEqual(vctxt->inode->localName, localname)) ||
27336 (!xmlStrEqual(vctxt->inode->nsName, URI))) {
27337 VERROR_INT("xmlSchemaSAXHandleEndElementNs",
27338 "elem pop mismatch");
27339 }
27340 res = xmlSchemaValidatorPopElem(vctxt);
27341 if (res != 0) {
27342 if (res < 0) {
27343 VERROR_INT("xmlSchemaSAXHandleEndElementNs",
27344 "calling xmlSchemaValidatorPopElem()");
27345 goto internal_error;
27346 }
27347 goto exit;
27348 }
27349exit:
27350 return;
27351internal_error:
27352 vctxt->err = -1;
27353 xmlStopParser(vctxt->parserCtxt);
27354 return;
27355}
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027356
Daniel Veillard4255d502002-04-16 15:50:10 +000027357/************************************************************************
27358 * *
27359 * Validation interfaces *
27360 * *
27361 ************************************************************************/
27362
27363/**
27364 * xmlSchemaNewValidCtxt:
27365 * @schema: a precompiled XML Schemas
27366 *
Kasimier T. Buchcik7f3efa92005-03-07 17:41:58 +000027367 * Create an XML Schemas validation context based on the given schema.
Daniel Veillard4255d502002-04-16 15:50:10 +000027368 *
27369 * Returns the validation context or NULL in case of error
27370 */
27371xmlSchemaValidCtxtPtr
Daniel Veillardd0c9c322003-10-10 00:49:42 +000027372xmlSchemaNewValidCtxt(xmlSchemaPtr schema)
27373{
Daniel Veillard4255d502002-04-16 15:50:10 +000027374 xmlSchemaValidCtxtPtr ret;
27375
27376 ret = (xmlSchemaValidCtxtPtr) xmlMalloc(sizeof(xmlSchemaValidCtxt));
27377 if (ret == NULL) {
Daniel Veillardd0c9c322003-10-10 00:49:42 +000027378 xmlSchemaVErrMemory(NULL, "allocating validation context", NULL);
Daniel Veillard4255d502002-04-16 15:50:10 +000027379 return (NULL);
27380 }
27381 memset(ret, 0, sizeof(xmlSchemaValidCtxt));
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027382 ret->type = XML_SCHEMA_CTXT_VALIDATOR;
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000027383 ret->dict = xmlDictCreate();
Kasimier T. Buchcik630215b2005-08-22 10:15:39 +000027384 ret->nodeQNames = xmlSchemaItemListCreate();
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027385 ret->schema = schema;
Daniel Veillard4255d502002-04-16 15:50:10 +000027386 return (ret);
27387}
27388
27389/**
Kasimier T. Buchcik7f3efa92005-03-07 17:41:58 +000027390 * xmlSchemaClearValidCtxt:
27391 * @ctxt: the schema validation context
27392 *
27393 * Free the resources associated to the schema validation context;
27394 * leaves some fields alive intended for reuse of the context.
27395 */
27396static void
27397xmlSchemaClearValidCtxt(xmlSchemaValidCtxtPtr vctxt)
27398{
27399 if (vctxt == NULL)
27400 return;
27401
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000027402 /*
27403 * TODO: Should we clear the flags?
27404 * Might be problematic if one reuses the context
27405 * and assumes that the options remain the same.
27406 */
Kasimier T. Buchcikaba15f72005-04-01 15:17:27 +000027407 vctxt->flags = 0;
Kasimier T. Buchcik7f3efa92005-03-07 17:41:58 +000027408 vctxt->validationRoot = NULL;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027409 vctxt->doc = NULL;
Daniel Veillard39e5c892005-07-03 22:48:50 +000027410#ifdef LIBXML_READER_ENABLED
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027411 vctxt->reader = NULL;
Daniel Veillard39e5c892005-07-03 22:48:50 +000027412#endif
Daniel Veillarddee23482008-04-11 12:58:43 +000027413 vctxt->hasKeyrefs = 0;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000027414
Kasimier T. Buchcik7f3efa92005-03-07 17:41:58 +000027415 if (vctxt->value != NULL) {
27416 xmlSchemaFreeValue(vctxt->value);
27417 vctxt->value = NULL;
27418 }
27419 /*
27420 * Augmented IDC information.
27421 */
27422 if (vctxt->aidcs != NULL) {
27423 xmlSchemaIDCAugPtr cur = vctxt->aidcs, next;
27424 do {
27425 next = cur->next;
27426 xmlFree(cur);
27427 cur = next;
27428 } while (cur != NULL);
27429 vctxt->aidcs = NULL;
27430 }
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000027431 if (vctxt->idcMatcherCache != NULL) {
27432 xmlSchemaIDCMatcherPtr matcher = vctxt->idcMatcherCache, tmp;
27433
27434 while (matcher) {
27435 tmp = matcher;
27436 matcher = matcher->nextCached;
27437 xmlSchemaIDCFreeMatcherList(tmp);
27438 }
27439 vctxt->idcMatcherCache = NULL;
27440 }
27441
27442
Kasimier T. Buchcik7f3efa92005-03-07 17:41:58 +000027443 if (vctxt->idcNodes != NULL) {
27444 int i;
27445 xmlSchemaPSVIIDCNodePtr item;
27446
27447 for (i = 0; i < vctxt->nbIdcNodes; i++) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027448 item = vctxt->idcNodes[i];
Kasimier T. Buchcik7f3efa92005-03-07 17:41:58 +000027449 xmlFree(item->keys);
27450 xmlFree(item);
27451 }
27452 xmlFree(vctxt->idcNodes);
27453 vctxt->idcNodes = NULL;
Daniel Veillard1131e112006-08-07 11:02:54 +000027454 vctxt->nbIdcNodes = 0;
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000027455 vctxt->sizeIdcNodes = 0;
Kasimier T. Buchcik7f3efa92005-03-07 17:41:58 +000027456 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027457 /*
Kasimier T. Buchcik7f3efa92005-03-07 17:41:58 +000027458 * Note that we won't delete the XPath state pool here.
27459 */
27460 if (vctxt->xpathStates != NULL) {
27461 xmlSchemaFreeIDCStateObjList(vctxt->xpathStates);
27462 vctxt->xpathStates = NULL;
27463 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027464 /*
27465 * Attribute info.
27466 */
27467 if (vctxt->nbAttrInfos != 0) {
27468 xmlSchemaClearAttrInfos(vctxt);
Kasimier T. Buchcik7f3efa92005-03-07 17:41:58 +000027469 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027470 /*
27471 * Element info.
27472 */
Kasimier T. Buchcik7f3efa92005-03-07 17:41:58 +000027473 if (vctxt->elemInfos != NULL) {
27474 int i;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027475 xmlSchemaNodeInfoPtr ei;
27476
Kasimier T. Buchcik7f3efa92005-03-07 17:41:58 +000027477 for (i = 0; i < vctxt->sizeElemInfos; i++) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027478 ei = vctxt->elemInfos[i];
27479 if (ei == NULL)
Kasimier T. Buchcik7f3efa92005-03-07 17:41:58 +000027480 break;
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000027481 xmlSchemaClearElemInfo(vctxt, ei);
Kasimier T. Buchcik7f3efa92005-03-07 17:41:58 +000027482 }
Daniel Veillarddee23482008-04-11 12:58:43 +000027483 }
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000027484 xmlSchemaItemListClear(vctxt->nodeQNames);
27485 /* Recreate the dict. */
27486 xmlDictFree(vctxt->dict);
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000027487 /*
27488 * TODO: Is is save to recreate it? Do we have a scenario
27489 * where the user provides the dict?
27490 */
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000027491 vctxt->dict = xmlDictCreate();
Kasimier T. Buchcik7f3efa92005-03-07 17:41:58 +000027492}
27493
27494/**
Daniel Veillard4255d502002-04-16 15:50:10 +000027495 * xmlSchemaFreeValidCtxt:
27496 * @ctxt: the schema validation context
27497 *
27498 * Free the resources associated to the schema validation context
27499 */
27500void
Daniel Veillardd0c9c322003-10-10 00:49:42 +000027501xmlSchemaFreeValidCtxt(xmlSchemaValidCtxtPtr ctxt)
27502{
Daniel Veillard4255d502002-04-16 15:50:10 +000027503 if (ctxt == NULL)
Daniel Veillardd0c9c322003-10-10 00:49:42 +000027504 return;
Daniel Veillard88c58912002-04-23 07:12:20 +000027505 if (ctxt->value != NULL)
Daniel Veillardd0c9c322003-10-10 00:49:42 +000027506 xmlSchemaFreeValue(ctxt->value);
Kasimier T. Buchcik7f3efa92005-03-07 17:41:58 +000027507 if (ctxt->pctxt != NULL)
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000027508 xmlSchemaFreeParserCtxt(ctxt->pctxt);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000027509 if (ctxt->idcNodes != NULL) {
27510 int i;
27511 xmlSchemaPSVIIDCNodePtr item;
27512
27513 for (i = 0; i < ctxt->nbIdcNodes; i++) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027514 item = ctxt->idcNodes[i];
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000027515 xmlFree(item->keys);
27516 xmlFree(item);
27517 }
27518 xmlFree(ctxt->idcNodes);
27519 }
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000027520 if (ctxt->idcKeys != NULL) {
27521 int i;
27522 for (i = 0; i < ctxt->nbIdcKeys; i++)
27523 xmlSchemaIDCFreeKey(ctxt->idcKeys[i]);
27524 xmlFree(ctxt->idcKeys);
27525 }
27526
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000027527 if (ctxt->xpathStates != NULL) {
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000027528 xmlSchemaFreeIDCStateObjList(ctxt->xpathStates);
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000027529 ctxt->xpathStates = NULL;
27530 }
27531 if (ctxt->xpathStatePool != NULL) {
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000027532 xmlSchemaFreeIDCStateObjList(ctxt->xpathStatePool);
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000027533 ctxt->xpathStatePool = NULL;
27534 }
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000027535
27536 /*
27537 * Augmented IDC information.
27538 */
27539 if (ctxt->aidcs != NULL) {
27540 xmlSchemaIDCAugPtr cur = ctxt->aidcs, next;
27541 do {
27542 next = cur->next;
27543 xmlFree(cur);
27544 cur = next;
27545 } while (cur != NULL);
27546 }
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027547 if (ctxt->attrInfos != NULL) {
27548 int i;
27549 xmlSchemaAttrInfoPtr attr;
27550
27551 /* Just a paranoid call to the cleanup. */
27552 if (ctxt->nbAttrInfos != 0)
27553 xmlSchemaClearAttrInfos(ctxt);
27554 for (i = 0; i < ctxt->sizeAttrInfos; i++) {
27555 attr = ctxt->attrInfos[i];
27556 xmlFree(attr);
27557 }
27558 xmlFree(ctxt->attrInfos);
Kasimier T. Buchcikbd2a7d12005-02-16 12:27:25 +000027559 }
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000027560 if (ctxt->elemInfos != NULL) {
27561 int i;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027562 xmlSchemaNodeInfoPtr ei;
27563
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000027564 for (i = 0; i < ctxt->sizeElemInfos; i++) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027565 ei = ctxt->elemInfos[i];
27566 if (ei == NULL)
Kasimier T. Buchcik7f3efa92005-03-07 17:41:58 +000027567 break;
Kasimier T. Buchcikdeb58712006-08-15 12:52:30 +000027568 xmlSchemaClearElemInfo(ctxt, ei);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027569 xmlFree(ei);
Kasimier T. Buchcike8a550b2005-01-27 12:49:31 +000027570 }
27571 xmlFree(ctxt->elemInfos);
27572 }
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000027573 if (ctxt->nodeQNames != NULL)
Kasimier T. Buchcik630215b2005-08-22 10:15:39 +000027574 xmlSchemaItemListFree(ctxt->nodeQNames);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027575 if (ctxt->dict != NULL)
27576 xmlDictFree(ctxt->dict);
Daniel Veillard4255d502002-04-16 15:50:10 +000027577 xmlFree(ctxt);
27578}
27579
27580/**
Daniel Veillardf10ae122005-07-10 19:03:16 +000027581 * xmlSchemaIsValid:
27582 * @ctxt: the schema validation context
27583 *
27584 * Check if any error was detected during validation.
Daniel Veillarddee23482008-04-11 12:58:43 +000027585 *
Daniel Veillardf10ae122005-07-10 19:03:16 +000027586 * Returns 1 if valid so far, 0 if errors were detected, and -1 in case
27587 * of internal error.
27588 */
27589int
27590xmlSchemaIsValid(xmlSchemaValidCtxtPtr ctxt)
27591{
27592 if (ctxt == NULL)
27593 return(-1);
27594 return(ctxt->err == 0);
27595}
27596
27597/**
Daniel Veillard4255d502002-04-16 15:50:10 +000027598 * xmlSchemaSetValidErrors:
27599 * @ctxt: a schema validation context
27600 * @err: the error function
27601 * @warn: the warning function
Daniel Veillarda9b66d02002-12-11 14:23:49 +000027602 * @ctx: the functions context
Daniel Veillard4255d502002-04-16 15:50:10 +000027603 *
William M. Brack2f2a6632004-08-20 23:09:47 +000027604 * Set the error and warning callback informations
Daniel Veillard4255d502002-04-16 15:50:10 +000027605 */
27606void
27607xmlSchemaSetValidErrors(xmlSchemaValidCtxtPtr ctxt,
Daniel Veillardd0c9c322003-10-10 00:49:42 +000027608 xmlSchemaValidityErrorFunc err,
27609 xmlSchemaValidityWarningFunc warn, void *ctx)
27610{
Daniel Veillard4255d502002-04-16 15:50:10 +000027611 if (ctxt == NULL)
Daniel Veillardd0c9c322003-10-10 00:49:42 +000027612 return;
Daniel Veillard4255d502002-04-16 15:50:10 +000027613 ctxt->error = err;
27614 ctxt->warning = warn;
Kasimier T. Buchcik90b5ebc2005-11-18 17:18:27 +000027615 ctxt->errCtxt = ctx;
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000027616 if (ctxt->pctxt != NULL)
27617 xmlSchemaSetParserErrors(ctxt->pctxt, err, warn, ctx);
Daniel Veillard4255d502002-04-16 15:50:10 +000027618}
27619
27620/**
Daniel Veillardda0aa4c2005-07-13 23:07:49 +000027621 * xmlSchemaSetValidStructuredErrors:
27622 * @ctxt: a schema validation context
27623 * @serror: the structured error function
27624 * @ctx: the functions context
27625 *
27626 * Set the structured error callback
27627 */
27628void
27629xmlSchemaSetValidStructuredErrors(xmlSchemaValidCtxtPtr ctxt,
Kasimier T. Buchcik90b5ebc2005-11-18 17:18:27 +000027630 xmlStructuredErrorFunc serror, void *ctx)
Daniel Veillardda0aa4c2005-07-13 23:07:49 +000027631{
27632 if (ctxt == NULL)
27633 return;
27634 ctxt->serror = serror;
27635 ctxt->error = NULL;
27636 ctxt->warning = NULL;
Kasimier T. Buchcik90b5ebc2005-11-18 17:18:27 +000027637 ctxt->errCtxt = ctx;
27638 if (ctxt->pctxt != NULL)
27639 xmlSchemaSetParserStructuredErrors(ctxt->pctxt, serror, ctx);
Daniel Veillardda0aa4c2005-07-13 23:07:49 +000027640}
27641
27642/**
Daniel Veillard259f0df2004-08-18 09:13:18 +000027643 * xmlSchemaGetValidErrors:
Daniel Veillarddee23482008-04-11 12:58:43 +000027644 * @ctxt: a XML-Schema validation context
Daniel Veillard259f0df2004-08-18 09:13:18 +000027645 * @err: the error function result
27646 * @warn: the warning function result
27647 * @ctx: the functions context result
27648 *
27649 * Get the error and warning callback informations
27650 *
27651 * Returns -1 in case of error and 0 otherwise
27652 */
27653int
27654xmlSchemaGetValidErrors(xmlSchemaValidCtxtPtr ctxt,
Kasimier T. Buchcik90b5ebc2005-11-18 17:18:27 +000027655 xmlSchemaValidityErrorFunc * err,
27656 xmlSchemaValidityWarningFunc * warn, void **ctx)
Daniel Veillard259f0df2004-08-18 09:13:18 +000027657{
27658 if (ctxt == NULL)
27659 return (-1);
27660 if (err != NULL)
27661 *err = ctxt->error;
27662 if (warn != NULL)
27663 *warn = ctxt->warning;
27664 if (ctx != NULL)
Kasimier T. Buchcik90b5ebc2005-11-18 17:18:27 +000027665 *ctx = ctxt->errCtxt;
Daniel Veillard259f0df2004-08-18 09:13:18 +000027666 return (0);
27667}
27668
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000027669
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000027670/**
Daniel Veillard6927b102004-10-27 17:29:04 +000027671 * xmlSchemaSetValidOptions:
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000027672 * @ctxt: a schema validation context
27673 * @options: a combination of xmlSchemaValidOption
27674 *
27675 * Sets the options to be used during the validation.
27676 *
27677 * Returns 0 in case of success, -1 in case of an
27678 * API error.
27679 */
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000027680int
27681xmlSchemaSetValidOptions(xmlSchemaValidCtxtPtr ctxt,
27682 int options)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027683
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000027684{
27685 int i;
27686
27687 if (ctxt == NULL)
27688 return (-1);
27689 /*
27690 * WARNING: Change the start value if adding to the
27691 * xmlSchemaValidOption.
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000027692 * TODO: Is there an other, more easy to maintain,
27693 * way?
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000027694 */
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000027695 for (i = 1; i < (int) sizeof(int) * 8; i++) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027696 if (options & 1<<i)
27697 return (-1);
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000027698 }
27699 ctxt->options = options;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027700 return (0);
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000027701}
27702
27703/**
Daniel Veillard6927b102004-10-27 17:29:04 +000027704 * xmlSchemaValidCtxtGetOptions:
Daniel Veillarddee23482008-04-11 12:58:43 +000027705 * @ctxt: a schema validation context
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000027706 *
William M. Brack21e4ef22005-01-02 09:53:13 +000027707 * Get the validation context options.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027708 *
William M. Brack21e4ef22005-01-02 09:53:13 +000027709 * Returns the option combination or -1 on error.
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000027710 */
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000027711int
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000027712xmlSchemaValidCtxtGetOptions(xmlSchemaValidCtxtPtr ctxt)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027713
27714{
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000027715 if (ctxt == NULL)
27716 return (-1);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027717 else
27718 return (ctxt->options);
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000027719}
Kasimier T. Buchcik87876402004-09-29 13:29:03 +000027720
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027721static int
27722xmlSchemaVDocWalk(xmlSchemaValidCtxtPtr vctxt)
27723{
27724 xmlAttrPtr attr;
27725 int ret = 0;
27726 xmlSchemaNodeInfoPtr ielem = NULL;
27727 xmlNodePtr node, valRoot;
27728 const xmlChar *nsName;
27729
27730 /* DOC VAL TODO: Move this to the start function. */
27731 valRoot = xmlDocGetRootElement(vctxt->doc);
27732 if (valRoot == NULL) {
27733 /* VAL TODO: Error code? */
27734 VERROR(1, NULL, "The document has no document element");
27735 return (1);
27736 }
27737 vctxt->depth = -1;
27738 vctxt->validationRoot = valRoot;
27739 node = valRoot;
27740 while (node != NULL) {
27741 if ((vctxt->skipDepth != -1) && (vctxt->depth >= vctxt->skipDepth))
27742 goto next_sibling;
27743 if (node->type == XML_ELEMENT_NODE) {
27744
27745 /*
27746 * Init the node-info.
27747 */
Kasimier T. Buchcik84a56e32005-06-16 12:44:35 +000027748 vctxt->depth++;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027749 if (xmlSchemaValidatorPushElem(vctxt) == -1)
27750 goto internal_error;
27751 ielem = vctxt->inode;
27752 ielem->node = node;
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000027753 ielem->nodeLine = node->line;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027754 ielem->localName = node->name;
27755 if (node->ns != NULL)
27756 ielem->nsName = node->ns->href;
27757 ielem->flags |= XML_SCHEMA_ELEM_INFO_EMPTY;
27758 /*
27759 * Register attributes.
27760 * DOC VAL TODO: We do not register namespace declaration
27761 * attributes yet.
27762 */
27763 vctxt->nbAttrInfos = 0;
27764 if (node->properties != NULL) {
27765 attr = node->properties;
27766 do {
27767 if (attr->ns != NULL)
27768 nsName = attr->ns->href;
27769 else
27770 nsName = NULL;
27771 ret = xmlSchemaValidatorPushAttribute(vctxt,
27772 (xmlNodePtr) attr,
Daniel Veillarddee23482008-04-11 12:58:43 +000027773 /*
Kasimier T. Buchcik764b3d62005-08-12 12:25:23 +000027774 * Note that we give it the line number of the
27775 * parent element.
27776 */
27777 ielem->nodeLine,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027778 attr->name, nsName, 0,
27779 xmlNodeListGetString(attr->doc, attr->children, 1), 1);
27780 if (ret == -1) {
27781 VERROR_INT("xmlSchemaDocWalk",
27782 "calling xmlSchemaValidatorPushAttribute()");
27783 goto internal_error;
27784 }
27785 attr = attr->next;
27786 } while (attr);
27787 }
27788 /*
27789 * Validate the element.
27790 */
27791 ret = xmlSchemaValidateElem(vctxt);
27792 if (ret != 0) {
27793 if (ret == -1) {
27794 VERROR_INT("xmlSchemaDocWalk",
27795 "calling xmlSchemaValidateElem()");
27796 goto internal_error;
27797 }
27798 /*
27799 * Don't stop validation; just skip the content
27800 * of this element.
27801 */
27802 goto leave_node;
27803 }
27804 if ((vctxt->skipDepth != -1) &&
27805 (vctxt->depth >= vctxt->skipDepth))
27806 goto leave_node;
27807 } else if ((node->type == XML_TEXT_NODE) ||
27808 (node->type == XML_CDATA_SECTION_NODE)) {
27809 /*
27810 * Process character content.
27811 */
Daniel Veillard14b56432006-03-09 18:41:40 +000027812 if ((ielem != NULL) && (ielem->flags & XML_SCHEMA_ELEM_INFO_EMPTY))
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027813 ielem->flags ^= XML_SCHEMA_ELEM_INFO_EMPTY;
27814 ret = xmlSchemaVPushText(vctxt, node->type, node->content,
27815 -1, XML_SCHEMA_PUSH_TEXT_PERSIST, NULL);
27816 if (ret < 0) {
27817 VERROR_INT("xmlSchemaVDocWalk",
27818 "calling xmlSchemaVPushText()");
27819 goto internal_error;
27820 }
27821 /*
27822 * DOC VAL TODO: Should we skip further validation of the
27823 * element content here?
27824 */
27825 } else if ((node->type == XML_ENTITY_NODE) ||
27826 (node->type == XML_ENTITY_REF_NODE)) {
27827 /*
27828 * DOC VAL TODO: What to do with entities?
Daniel Veillarddee23482008-04-11 12:58:43 +000027829 */
Kasimier T. Buchcik146a9822006-05-04 17:19:07 +000027830 VERROR_INT("xmlSchemaVDocWalk",
27831 "there is at least one entity reference in the node-tree "
27832 "currently being validated. Processing of entities with "
27833 "this XML Schema processor is not supported (yet). Please "
27834 "substitute entities before validation.");
27835 goto internal_error;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027836 } else {
27837 goto leave_node;
27838 /*
27839 * DOC VAL TODO: XInclude nodes, etc.
27840 */
27841 }
27842 /*
27843 * Walk the doc.
27844 */
27845 if (node->children != NULL) {
27846 node = node->children;
27847 continue;
27848 }
27849leave_node:
27850 if (node->type == XML_ELEMENT_NODE) {
27851 /*
27852 * Leaving the scope of an element.
27853 */
27854 if (node != vctxt->inode->node) {
27855 VERROR_INT("xmlSchemaVDocWalk",
27856 "element position mismatch");
27857 goto internal_error;
27858 }
27859 ret = xmlSchemaValidatorPopElem(vctxt);
27860 if (ret != 0) {
27861 if (ret < 0) {
27862 VERROR_INT("xmlSchemaVDocWalk",
27863 "calling xmlSchemaValidatorPopElem()");
27864 goto internal_error;
27865 }
27866 }
27867 if (node == valRoot)
27868 goto exit;
27869 }
27870next_sibling:
27871 if (node->next != NULL)
27872 node = node->next;
27873 else {
27874 node = node->parent;
27875 goto leave_node;
27876 }
27877 }
27878
27879exit:
27880 return (ret);
27881internal_error:
27882 return (-1);
27883}
27884
27885static int
Daniel Veillardf10ae122005-07-10 19:03:16 +000027886xmlSchemaPreRun(xmlSchemaValidCtxtPtr vctxt) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027887 /*
27888 * Some initialization.
Daniel Veillarddee23482008-04-11 12:58:43 +000027889 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027890 vctxt->err = 0;
27891 vctxt->nberrors = 0;
27892 vctxt->depth = -1;
27893 vctxt->skipDepth = -1;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000027894 vctxt->xsiAssemble = 0;
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000027895 vctxt->hasKeyrefs = 0;
Kasimier T. Buchcik132ba5f2005-11-28 12:32:24 +000027896#ifdef ENABLE_IDC_NODE_TABLES_TEST
Kasimier T. Buchcik27820272005-10-14 14:33:48 +000027897 vctxt->createIDCNodeTables = 1;
27898#else
27899 vctxt->createIDCNodeTables = 0;
27900#endif
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027901 /*
27902 * Create a schema + parser if necessary.
27903 */
27904 if (vctxt->schema == NULL) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000027905 xmlSchemaParserCtxtPtr pctxt;
Daniel Veillarddee23482008-04-11 12:58:43 +000027906
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000027907 vctxt->xsiAssemble = 1;
Daniel Veillarddee23482008-04-11 12:58:43 +000027908 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000027909 * If not schema was given then we will create a schema
27910 * dynamically using XSI schema locations.
27911 *
27912 * Create the schema parser context.
27913 */
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027914 if ((vctxt->pctxt == NULL) &&
27915 (xmlSchemaCreatePCtxtOnVCtxt(vctxt) == -1))
27916 return (-1);
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000027917 pctxt = vctxt->pctxt;
27918 pctxt->xsiAssemble = 1;
27919 /*
27920 * Create the schema.
27921 */
27922 vctxt->schema = xmlSchemaNewSchema(pctxt);
27923 if (vctxt->schema == NULL)
Daniel Veillarddee23482008-04-11 12:58:43 +000027924 return (-1);
27925 /*
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000027926 * Create the schema construction context.
27927 */
27928 pctxt->constructor = xmlSchemaConstructionCtxtCreate(pctxt->dict);
27929 if (pctxt->constructor == NULL)
27930 return(-1);
Kasimier T. Buchcik570faa52005-10-10 13:18:40 +000027931 pctxt->constructor->mainSchema = vctxt->schema;
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000027932 /*
27933 * Take ownership of the constructor to be able to free it.
27934 */
27935 pctxt->ownsConstructor = 1;
Daniel Veillarddee23482008-04-11 12:58:43 +000027936 }
27937 /*
27938 * Augment the IDC definitions for the main schema and all imported ones
Daniel Veillard3888f472007-08-23 09:29:03 +000027939 * NOTE: main schema if the first in the imported list
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027940 */
Daniel Veillard3888f472007-08-23 09:29:03 +000027941 xmlHashScan(vctxt->schema->schemasImports,(xmlHashScanner)xmlSchemaAugmentImportedIDC, vctxt);
Daniel Veillarddee23482008-04-11 12:58:43 +000027942
Daniel Veillardf10ae122005-07-10 19:03:16 +000027943 return(0);
27944}
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027945
Daniel Veillardf10ae122005-07-10 19:03:16 +000027946static void
27947xmlSchemaPostRun(xmlSchemaValidCtxtPtr vctxt) {
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027948 if (vctxt->xsiAssemble) {
27949 if (vctxt->schema != NULL) {
27950 xmlSchemaFree(vctxt->schema);
27951 vctxt->schema = NULL;
27952 }
27953 }
27954 xmlSchemaClearValidCtxt(vctxt);
Daniel Veillardf10ae122005-07-10 19:03:16 +000027955}
27956
27957static int
27958xmlSchemaVStart(xmlSchemaValidCtxtPtr vctxt)
27959{
27960 int ret = 0;
27961
27962 if (xmlSchemaPreRun(vctxt) < 0)
27963 return(-1);
27964
27965 if (vctxt->doc != NULL) {
27966 /*
27967 * Tree validation.
27968 */
27969 ret = xmlSchemaVDocWalk(vctxt);
27970#ifdef LIBXML_READER_ENABLED
27971 } else if (vctxt->reader != NULL) {
27972 /*
27973 * XML Reader validation.
27974 */
27975#ifdef XML_SCHEMA_READER_ENABLED
27976 ret = xmlSchemaVReaderWalk(vctxt);
27977#endif
27978#endif
27979 } else if ((vctxt->sax != NULL) && (vctxt->parserCtxt != NULL)) {
27980 /*
27981 * SAX validation.
27982 */
27983 ret = xmlParseDocument(vctxt->parserCtxt);
27984 } else {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000027985 VERROR_INT("xmlSchemaVStart",
Daniel Veillardf10ae122005-07-10 19:03:16 +000027986 "no instance to validate");
27987 ret = -1;
27988 }
27989
27990 xmlSchemaPostRun(vctxt);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000027991 if (ret == 0)
27992 ret = vctxt->err;
27993 return (ret);
27994}
27995
27996/**
27997 * xmlSchemaValidateOneElement:
27998 * @ctxt: a schema validation context
27999 * @elem: an element node
28000 *
28001 * Validate a branch of a tree, starting with the given @elem.
28002 *
28003 * Returns 0 if the element and its subtree is valid, a positive error
28004 * code number otherwise and -1 in case of an internal or API error.
28005 */
28006int
28007xmlSchemaValidateOneElement(xmlSchemaValidCtxtPtr ctxt, xmlNodePtr elem)
28008{
28009 if ((ctxt == NULL) || (elem == NULL) || (elem->type != XML_ELEMENT_NODE))
28010 return (-1);
28011
28012 if (ctxt->schema == NULL)
28013 return (-1);
28014
28015 ctxt->doc = elem->doc;
28016 ctxt->node = elem;
28017 ctxt->validationRoot = elem;
28018 return(xmlSchemaVStart(ctxt));
28019}
Kasimier T. Buchcik876a6db2004-09-16 11:31:52 +000028020
Daniel Veillard259f0df2004-08-18 09:13:18 +000028021/**
Daniel Veillard4255d502002-04-16 15:50:10 +000028022 * xmlSchemaValidateDoc:
28023 * @ctxt: a schema validation context
28024 * @doc: a parsed document tree
28025 *
28026 * Validate a document tree in memory.
28027 *
28028 * Returns 0 if the document is schemas valid, a positive error code
28029 * number otherwise and -1 in case of internal or API error.
28030 */
28031int
Daniel Veillardd0c9c322003-10-10 00:49:42 +000028032xmlSchemaValidateDoc(xmlSchemaValidCtxtPtr ctxt, xmlDocPtr doc)
28033{
Daniel Veillard4255d502002-04-16 15:50:10 +000028034 if ((ctxt == NULL) || (doc == NULL))
Daniel Veillardd0c9c322003-10-10 00:49:42 +000028035 return (-1);
Daniel Veillard4255d502002-04-16 15:50:10 +000028036
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000028037 ctxt->doc = doc;
Kasimier T. Buchcik7f3efa92005-03-07 17:41:58 +000028038 ctxt->node = xmlDocGetRootElement(doc);
28039 if (ctxt->node == NULL) {
Kasimier T. Buchcik22c0c462005-09-12 19:09:46 +000028040 xmlSchemaCustomErr(ACTXT_CAST ctxt,
Kasimier T. Buchcik7f3efa92005-03-07 17:41:58 +000028041 XML_SCHEMAV_DOCUMENT_ELEMENT_MISSING,
28042 (xmlNodePtr) doc, NULL,
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000028043 "The document has no document element", NULL, NULL);
Kasimier T. Buchcik7f3efa92005-03-07 17:41:58 +000028044 return (ctxt->err);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000028045 }
Kasimier T. Buchcik7f3efa92005-03-07 17:41:58 +000028046 ctxt->validationRoot = ctxt->node;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000028047 return (xmlSchemaVStart(ctxt));
Daniel Veillard4255d502002-04-16 15:50:10 +000028048}
28049
Daniel Veillardcdc82732005-07-08 15:04:06 +000028050
28051/************************************************************************
28052 * *
28053 * Function and data for SAX streaming API *
28054 * *
28055 ************************************************************************/
28056typedef struct _xmlSchemaSplitSAXData xmlSchemaSplitSAXData;
28057typedef xmlSchemaSplitSAXData *xmlSchemaSplitSAXDataPtr;
28058
28059struct _xmlSchemaSplitSAXData {
28060 xmlSAXHandlerPtr user_sax;
28061 void *user_data;
28062 xmlSchemaValidCtxtPtr ctxt;
28063 xmlSAXHandlerPtr schemas_sax;
28064};
28065
Daniel Veillard971771e2005-07-09 17:32:57 +000028066#define XML_SAX_PLUG_MAGIC 0xdc43ba21
28067
28068struct _xmlSchemaSAXPlug {
28069 unsigned int magic;
28070
28071 /* the original callbacks informations */
28072 xmlSAXHandlerPtr *user_sax_ptr;
28073 xmlSAXHandlerPtr user_sax;
28074 void **user_data_ptr;
28075 void *user_data;
28076
28077 /* the block plugged back and validation informations */
28078 xmlSAXHandler schemas_sax;
28079 xmlSchemaValidCtxtPtr ctxt;
28080};
28081
Daniel Veillardcdc82732005-07-08 15:04:06 +000028082/* All those functions just bounces to the user provided SAX handlers */
28083static void
28084internalSubsetSplit(void *ctx, const xmlChar *name,
28085 const xmlChar *ExternalID, const xmlChar *SystemID)
28086{
Daniel Veillard971771e2005-07-09 17:32:57 +000028087 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
Daniel Veillardcdc82732005-07-08 15:04:06 +000028088 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28089 (ctxt->user_sax->internalSubset != NULL))
28090 ctxt->user_sax->internalSubset(ctxt->user_data, name, ExternalID,
28091 SystemID);
28092}
28093
28094static int
28095isStandaloneSplit(void *ctx)
28096{
Daniel Veillard971771e2005-07-09 17:32:57 +000028097 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
Daniel Veillardcdc82732005-07-08 15:04:06 +000028098 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28099 (ctxt->user_sax->isStandalone != NULL))
28100 return(ctxt->user_sax->isStandalone(ctxt->user_data));
28101 return(0);
28102}
28103
28104static int
28105hasInternalSubsetSplit(void *ctx)
28106{
Daniel Veillard971771e2005-07-09 17:32:57 +000028107 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
Daniel Veillardcdc82732005-07-08 15:04:06 +000028108 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28109 (ctxt->user_sax->hasInternalSubset != NULL))
28110 return(ctxt->user_sax->hasInternalSubset(ctxt->user_data));
28111 return(0);
28112}
28113
28114static int
28115hasExternalSubsetSplit(void *ctx)
28116{
Daniel Veillard971771e2005-07-09 17:32:57 +000028117 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
Daniel Veillardcdc82732005-07-08 15:04:06 +000028118 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28119 (ctxt->user_sax->hasExternalSubset != NULL))
28120 return(ctxt->user_sax->hasExternalSubset(ctxt->user_data));
28121 return(0);
28122}
28123
28124static void
28125externalSubsetSplit(void *ctx, const xmlChar *name,
28126 const xmlChar *ExternalID, const xmlChar *SystemID)
28127{
Daniel Veillard971771e2005-07-09 17:32:57 +000028128 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
Daniel Veillardcdc82732005-07-08 15:04:06 +000028129 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
Daniel Veillardb3e45362008-03-26 13:39:31 +000028130 (ctxt->user_sax->externalSubset != NULL))
28131 ctxt->user_sax->externalSubset(ctxt->user_data, name, ExternalID,
Daniel Veillardcdc82732005-07-08 15:04:06 +000028132 SystemID);
28133}
28134
28135static xmlParserInputPtr
28136resolveEntitySplit(void *ctx, const xmlChar *publicId, const xmlChar *systemId)
28137{
Daniel Veillard971771e2005-07-09 17:32:57 +000028138 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
Daniel Veillardcdc82732005-07-08 15:04:06 +000028139 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28140 (ctxt->user_sax->resolveEntity != NULL))
28141 return(ctxt->user_sax->resolveEntity(ctxt->user_data, publicId,
28142 systemId));
28143 return(NULL);
28144}
28145
28146static xmlEntityPtr
28147getEntitySplit(void *ctx, const xmlChar *name)
28148{
Daniel Veillard971771e2005-07-09 17:32:57 +000028149 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
Daniel Veillardcdc82732005-07-08 15:04:06 +000028150 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28151 (ctxt->user_sax->getEntity != NULL))
28152 return(ctxt->user_sax->getEntity(ctxt->user_data, name));
28153 return(NULL);
28154}
28155
28156static xmlEntityPtr
28157getParameterEntitySplit(void *ctx, const xmlChar *name)
28158{
Daniel Veillard971771e2005-07-09 17:32:57 +000028159 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
Daniel Veillardcdc82732005-07-08 15:04:06 +000028160 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28161 (ctxt->user_sax->getParameterEntity != NULL))
28162 return(ctxt->user_sax->getParameterEntity(ctxt->user_data, name));
28163 return(NULL);
28164}
28165
28166
28167static void
28168entityDeclSplit(void *ctx, const xmlChar *name, int type,
28169 const xmlChar *publicId, const xmlChar *systemId, xmlChar *content)
28170{
Daniel Veillard971771e2005-07-09 17:32:57 +000028171 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
Daniel Veillardcdc82732005-07-08 15:04:06 +000028172 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28173 (ctxt->user_sax->entityDecl != NULL))
28174 ctxt->user_sax->entityDecl(ctxt->user_data, name, type, publicId,
28175 systemId, content);
28176}
28177
28178static void
28179attributeDeclSplit(void *ctx, const xmlChar * elem,
28180 const xmlChar * name, int type, int def,
28181 const xmlChar * defaultValue, xmlEnumerationPtr tree)
28182{
Daniel Veillard971771e2005-07-09 17:32:57 +000028183 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
Daniel Veillardcdc82732005-07-08 15:04:06 +000028184 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28185 (ctxt->user_sax->attributeDecl != NULL)) {
28186 ctxt->user_sax->attributeDecl(ctxt->user_data, elem, name, type,
28187 def, defaultValue, tree);
28188 } else {
28189 xmlFreeEnumeration(tree);
28190 }
28191}
28192
28193static void
28194elementDeclSplit(void *ctx, const xmlChar *name, int type,
28195 xmlElementContentPtr content)
28196{
Daniel Veillard971771e2005-07-09 17:32:57 +000028197 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
Daniel Veillardcdc82732005-07-08 15:04:06 +000028198 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28199 (ctxt->user_sax->elementDecl != NULL))
28200 ctxt->user_sax->elementDecl(ctxt->user_data, name, type, content);
28201}
28202
28203static void
28204notationDeclSplit(void *ctx, const xmlChar *name,
28205 const xmlChar *publicId, const xmlChar *systemId)
28206{
Daniel Veillard971771e2005-07-09 17:32:57 +000028207 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
Daniel Veillardcdc82732005-07-08 15:04:06 +000028208 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28209 (ctxt->user_sax->notationDecl != NULL))
28210 ctxt->user_sax->notationDecl(ctxt->user_data, name, publicId,
28211 systemId);
28212}
28213
28214static void
28215unparsedEntityDeclSplit(void *ctx, const xmlChar *name,
28216 const xmlChar *publicId, const xmlChar *systemId,
28217 const xmlChar *notationName)
28218{
Daniel Veillard971771e2005-07-09 17:32:57 +000028219 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
Daniel Veillardcdc82732005-07-08 15:04:06 +000028220 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28221 (ctxt->user_sax->unparsedEntityDecl != NULL))
28222 ctxt->user_sax->unparsedEntityDecl(ctxt->user_data, name, publicId,
28223 systemId, notationName);
28224}
28225
28226static void
28227setDocumentLocatorSplit(void *ctx, xmlSAXLocatorPtr loc)
28228{
Daniel Veillard971771e2005-07-09 17:32:57 +000028229 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
Daniel Veillardcdc82732005-07-08 15:04:06 +000028230 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28231 (ctxt->user_sax->setDocumentLocator != NULL))
28232 ctxt->user_sax->setDocumentLocator(ctxt->user_data, loc);
28233}
28234
28235static void
28236startDocumentSplit(void *ctx)
28237{
Daniel Veillard971771e2005-07-09 17:32:57 +000028238 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
Daniel Veillardcdc82732005-07-08 15:04:06 +000028239 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28240 (ctxt->user_sax->startDocument != NULL))
28241 ctxt->user_sax->startDocument(ctxt->user_data);
28242}
28243
28244static void
28245endDocumentSplit(void *ctx)
28246{
Daniel Veillard971771e2005-07-09 17:32:57 +000028247 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
Daniel Veillardcdc82732005-07-08 15:04:06 +000028248 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28249 (ctxt->user_sax->endDocument != NULL))
28250 ctxt->user_sax->endDocument(ctxt->user_data);
28251}
28252
28253static void
28254processingInstructionSplit(void *ctx, const xmlChar *target,
28255 const xmlChar *data)
28256{
Daniel Veillard971771e2005-07-09 17:32:57 +000028257 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
Daniel Veillardcdc82732005-07-08 15:04:06 +000028258 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28259 (ctxt->user_sax->processingInstruction != NULL))
28260 ctxt->user_sax->processingInstruction(ctxt->user_data, target, data);
28261}
28262
28263static void
28264commentSplit(void *ctx, const xmlChar *value)
28265{
Daniel Veillard971771e2005-07-09 17:32:57 +000028266 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
Daniel Veillardcdc82732005-07-08 15:04:06 +000028267 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28268 (ctxt->user_sax->comment != NULL))
28269 ctxt->user_sax->comment(ctxt->user_data, value);
28270}
28271
28272/*
28273 * Varargs error callbacks to the user application, harder ...
28274 */
28275
Daniel Veillardffa3c742005-07-21 13:24:09 +000028276static void XMLCDECL
Daniel Veillardafc05b62005-07-17 06:11:19 +000028277warningSplit(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...) {
Daniel Veillard971771e2005-07-09 17:32:57 +000028278 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
Daniel Veillardcdc82732005-07-08 15:04:06 +000028279 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28280 (ctxt->user_sax->warning != NULL)) {
28281 TODO
28282 }
28283}
Daniel Veillardffa3c742005-07-21 13:24:09 +000028284static void XMLCDECL
Daniel Veillardafc05b62005-07-17 06:11:19 +000028285errorSplit(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...) {
Daniel Veillard971771e2005-07-09 17:32:57 +000028286 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
Daniel Veillardcdc82732005-07-08 15:04:06 +000028287 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28288 (ctxt->user_sax->error != NULL)) {
28289 TODO
28290 }
28291}
Daniel Veillardffa3c742005-07-21 13:24:09 +000028292static void XMLCDECL
Daniel Veillardafc05b62005-07-17 06:11:19 +000028293fatalErrorSplit(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...) {
Daniel Veillard971771e2005-07-09 17:32:57 +000028294 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
Daniel Veillardcdc82732005-07-08 15:04:06 +000028295 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28296 (ctxt->user_sax->fatalError != NULL)) {
28297 TODO
28298 }
28299}
28300
28301/*
28302 * Those are function where both the user handler and the schemas handler
28303 * need to be called.
28304 */
28305static void
28306charactersSplit(void *ctx, const xmlChar *ch, int len)
28307{
Daniel Veillard971771e2005-07-09 17:32:57 +000028308 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
Daniel Veillardcdc82732005-07-08 15:04:06 +000028309 if (ctxt == NULL)
28310 return;
28311 if ((ctxt->user_sax != NULL) && (ctxt->user_sax->characters != NULL))
28312 ctxt->user_sax->characters(ctxt->user_data, ch, len);
28313 if (ctxt->ctxt != NULL)
28314 xmlSchemaSAXHandleText(ctxt->ctxt, ch, len);
28315}
28316
28317static void
28318ignorableWhitespaceSplit(void *ctx, const xmlChar *ch, int len)
28319{
Daniel Veillard971771e2005-07-09 17:32:57 +000028320 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
Daniel Veillardcdc82732005-07-08 15:04:06 +000028321 if (ctxt == NULL)
28322 return;
28323 if ((ctxt->user_sax != NULL) &&
28324 (ctxt->user_sax->ignorableWhitespace != NULL))
28325 ctxt->user_sax->ignorableWhitespace(ctxt->user_data, ch, len);
28326 if (ctxt->ctxt != NULL)
28327 xmlSchemaSAXHandleText(ctxt->ctxt, ch, len);
28328}
28329
28330static void
28331cdataBlockSplit(void *ctx, const xmlChar *value, int len)
28332{
Daniel Veillard971771e2005-07-09 17:32:57 +000028333 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
Daniel Veillardcdc82732005-07-08 15:04:06 +000028334 if (ctxt == NULL)
28335 return;
28336 if ((ctxt->user_sax != NULL) &&
Daniel Veillard7d0ca5e2008-02-05 08:43:52 +000028337 (ctxt->user_sax->cdataBlock != NULL))
28338 ctxt->user_sax->cdataBlock(ctxt->user_data, value, len);
Daniel Veillardcdc82732005-07-08 15:04:06 +000028339 if (ctxt->ctxt != NULL)
28340 xmlSchemaSAXHandleCDataSection(ctxt->ctxt, value, len);
28341}
28342
28343static void
28344referenceSplit(void *ctx, const xmlChar *name)
28345{
Daniel Veillard971771e2005-07-09 17:32:57 +000028346 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
Daniel Veillard14b56432006-03-09 18:41:40 +000028347 if (ctxt == NULL)
28348 return;
Daniel Veillardcdc82732005-07-08 15:04:06 +000028349 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28350 (ctxt->user_sax->reference != NULL))
28351 ctxt->user_sax->reference(ctxt->user_data, name);
28352 if (ctxt->ctxt != NULL)
28353 xmlSchemaSAXHandleReference(ctxt->user_data, name);
28354}
28355
28356static void
Daniel Veillarddee23482008-04-11 12:58:43 +000028357startElementNsSplit(void *ctx, const xmlChar * localname,
28358 const xmlChar * prefix, const xmlChar * URI,
28359 int nb_namespaces, const xmlChar ** namespaces,
28360 int nb_attributes, int nb_defaulted,
Daniel Veillardcdc82732005-07-08 15:04:06 +000028361 const xmlChar ** attributes) {
Daniel Veillard971771e2005-07-09 17:32:57 +000028362 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
Daniel Veillardcdc82732005-07-08 15:04:06 +000028363 if (ctxt == NULL)
28364 return;
28365 if ((ctxt->user_sax != NULL) &&
28366 (ctxt->user_sax->startElementNs != NULL))
28367 ctxt->user_sax->startElementNs(ctxt->user_data, localname, prefix,
28368 URI, nb_namespaces, namespaces,
28369 nb_attributes, nb_defaulted,
28370 attributes);
28371 if (ctxt->ctxt != NULL)
28372 xmlSchemaSAXHandleStartElementNs(ctxt->ctxt, localname, prefix,
28373 URI, nb_namespaces, namespaces,
28374 nb_attributes, nb_defaulted,
28375 attributes);
28376}
28377
28378static void
Daniel Veillarddee23482008-04-11 12:58:43 +000028379endElementNsSplit(void *ctx, const xmlChar * localname,
Daniel Veillardcdc82732005-07-08 15:04:06 +000028380 const xmlChar * prefix, const xmlChar * URI) {
Daniel Veillard971771e2005-07-09 17:32:57 +000028381 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
Daniel Veillardcdc82732005-07-08 15:04:06 +000028382 if (ctxt == NULL)
28383 return;
28384 if ((ctxt->user_sax != NULL) &&
28385 (ctxt->user_sax->endElementNs != NULL))
28386 ctxt->user_sax->endElementNs(ctxt->user_data, localname, prefix, URI);
28387 if (ctxt->ctxt != NULL)
28388 xmlSchemaSAXHandleEndElementNs(ctxt->ctxt, localname, prefix, URI);
28389}
28390
Daniel Veillard4255d502002-04-16 15:50:10 +000028391/**
Daniel Veillard971771e2005-07-09 17:32:57 +000028392 * xmlSchemaSAXPlug:
28393 * @ctxt: a schema validation context
Daniel Veillard1f33c4d2005-07-10 21:38:31 +000028394 * @sax: a pointer to the original xmlSAXHandlerPtr
28395 * @user_data: a pointer to the original SAX user data pointer
Daniel Veillard971771e2005-07-09 17:32:57 +000028396 *
28397 * Plug a SAX based validation layer in a SAX parsing event flow.
28398 * The original @saxptr and @dataptr data are replaced by new pointers
28399 * but the calls to the original will be maintained.
28400 *
28401 * Returns a pointer to a data structure needed to unplug the validation layer
28402 * or NULL in case of errors.
28403 */
28404xmlSchemaSAXPlugPtr
28405xmlSchemaSAXPlug(xmlSchemaValidCtxtPtr ctxt,
28406 xmlSAXHandlerPtr *sax, void **user_data)
28407{
28408 xmlSchemaSAXPlugPtr ret;
28409 xmlSAXHandlerPtr old_sax;
28410
28411 if ((ctxt == NULL) || (sax == NULL) || (user_data == NULL))
28412 return(NULL);
28413
28414 /*
28415 * We only allow to plug into SAX2 event streams
28416 */
28417 old_sax = *sax;
28418 if ((old_sax != NULL) && (old_sax->initialized != XML_SAX2_MAGIC))
28419 return(NULL);
Daniel Veillarddee23482008-04-11 12:58:43 +000028420 if ((old_sax != NULL) &&
Daniel Veillard971771e2005-07-09 17:32:57 +000028421 (old_sax->startElementNs == NULL) && (old_sax->endElementNs == NULL) &&
28422 ((old_sax->startElement != NULL) || (old_sax->endElement != NULL)))
28423 return(NULL);
28424
28425 /*
28426 * everything seems right allocate the local data needed for that layer
28427 */
28428 ret = (xmlSchemaSAXPlugPtr) xmlMalloc(sizeof(xmlSchemaSAXPlugStruct));
28429 if (ret == NULL) {
28430 return(NULL);
28431 }
28432 memset(ret, 0, sizeof(xmlSchemaSAXPlugStruct));
28433 ret->magic = XML_SAX_PLUG_MAGIC;
28434 ret->schemas_sax.initialized = XML_SAX2_MAGIC;
28435 ret->ctxt = ctxt;
28436 ret->user_sax_ptr = sax;
28437 ret->user_sax = old_sax;
Daniel Veillarddee23482008-04-11 12:58:43 +000028438 if (old_sax == NULL) {
Daniel Veillard971771e2005-07-09 17:32:57 +000028439 /*
28440 * go direct, no need for the split block and functions.
28441 */
28442 ret->schemas_sax.startElementNs = xmlSchemaSAXHandleStartElementNs;
28443 ret->schemas_sax.endElementNs = xmlSchemaSAXHandleEndElementNs;
28444 /*
28445 * Note that we use the same text-function for both, to prevent
28446 * the parser from testing for ignorable whitespace.
28447 */
28448 ret->schemas_sax.ignorableWhitespace = xmlSchemaSAXHandleText;
28449 ret->schemas_sax.characters = xmlSchemaSAXHandleText;
28450
28451 ret->schemas_sax.cdataBlock = xmlSchemaSAXHandleCDataSection;
28452 ret->schemas_sax.reference = xmlSchemaSAXHandleReference;
28453
28454 ret->user_data = ctxt;
28455 *user_data = ctxt;
28456 } else {
28457 /*
28458 * for each callback unused by Schemas initialize it to the Split
Daniel Veillarddee23482008-04-11 12:58:43 +000028459 * routine only if non NULL in the user block, this can speed up
Daniel Veillard971771e2005-07-09 17:32:57 +000028460 * things at the SAX level.
28461 */
28462 if (old_sax->internalSubset != NULL)
28463 ret->schemas_sax.internalSubset = internalSubsetSplit;
28464 if (old_sax->isStandalone != NULL)
28465 ret->schemas_sax.isStandalone = isStandaloneSplit;
28466 if (old_sax->hasInternalSubset != NULL)
28467 ret->schemas_sax.hasInternalSubset = hasInternalSubsetSplit;
28468 if (old_sax->hasExternalSubset != NULL)
28469 ret->schemas_sax.hasExternalSubset = hasExternalSubsetSplit;
28470 if (old_sax->resolveEntity != NULL)
28471 ret->schemas_sax.resolveEntity = resolveEntitySplit;
28472 if (old_sax->getEntity != NULL)
28473 ret->schemas_sax.getEntity = getEntitySplit;
28474 if (old_sax->entityDecl != NULL)
28475 ret->schemas_sax.entityDecl = entityDeclSplit;
28476 if (old_sax->notationDecl != NULL)
28477 ret->schemas_sax.notationDecl = notationDeclSplit;
28478 if (old_sax->attributeDecl != NULL)
28479 ret->schemas_sax.attributeDecl = attributeDeclSplit;
28480 if (old_sax->elementDecl != NULL)
28481 ret->schemas_sax.elementDecl = elementDeclSplit;
28482 if (old_sax->unparsedEntityDecl != NULL)
28483 ret->schemas_sax.unparsedEntityDecl = unparsedEntityDeclSplit;
28484 if (old_sax->setDocumentLocator != NULL)
28485 ret->schemas_sax.setDocumentLocator = setDocumentLocatorSplit;
28486 if (old_sax->startDocument != NULL)
28487 ret->schemas_sax.startDocument = startDocumentSplit;
28488 if (old_sax->endDocument != NULL)
28489 ret->schemas_sax.endDocument = endDocumentSplit;
28490 if (old_sax->processingInstruction != NULL)
28491 ret->schemas_sax.processingInstruction = processingInstructionSplit;
28492 if (old_sax->comment != NULL)
28493 ret->schemas_sax.comment = commentSplit;
28494 if (old_sax->warning != NULL)
28495 ret->schemas_sax.warning = warningSplit;
28496 if (old_sax->error != NULL)
28497 ret->schemas_sax.error = errorSplit;
28498 if (old_sax->fatalError != NULL)
28499 ret->schemas_sax.fatalError = fatalErrorSplit;
28500 if (old_sax->getParameterEntity != NULL)
28501 ret->schemas_sax.getParameterEntity = getParameterEntitySplit;
28502 if (old_sax->externalSubset != NULL)
28503 ret->schemas_sax.externalSubset = externalSubsetSplit;
28504
28505 /*
28506 * the 6 schemas callback have to go to the splitter functions
28507 * Note that we use the same text-function for ignorableWhitespace
28508 * if possible, to prevent the parser from testing for ignorable
28509 * whitespace.
28510 */
28511 ret->schemas_sax.characters = charactersSplit;
28512 if ((old_sax->ignorableWhitespace != NULL) &&
28513 (old_sax->ignorableWhitespace != old_sax->characters))
28514 ret->schemas_sax.ignorableWhitespace = ignorableWhitespaceSplit;
28515 else
28516 ret->schemas_sax.ignorableWhitespace = charactersSplit;
28517 ret->schemas_sax.cdataBlock = cdataBlockSplit;
28518 ret->schemas_sax.reference = referenceSplit;
28519 ret->schemas_sax.startElementNs = startElementNsSplit;
28520 ret->schemas_sax.endElementNs = endElementNsSplit;
28521
28522 ret->user_data_ptr = user_data;
28523 ret->user_data = *user_data;
28524 *user_data = ret;
28525 }
28526
28527 /*
28528 * plug the pointers back.
28529 */
28530 *sax = &(ret->schemas_sax);
Daniel Veillardf10ae122005-07-10 19:03:16 +000028531 ctxt->sax = *sax;
28532 ctxt->flags |= XML_SCHEMA_VALID_CTXT_FLAG_STREAM;
28533 xmlSchemaPreRun(ctxt);
Daniel Veillard971771e2005-07-09 17:32:57 +000028534 return(ret);
28535}
28536
28537/**
28538 * xmlSchemaSAXUnplug:
28539 * @plug: a data structure returned by xmlSchemaSAXPlug
28540 *
28541 * Unplug a SAX based validation layer in a SAX parsing event flow.
28542 * The original pointers used in the call are restored.
28543 *
28544 * Returns 0 in case of success and -1 in case of failure.
28545 */
28546int
28547xmlSchemaSAXUnplug(xmlSchemaSAXPlugPtr plug)
28548{
28549 xmlSAXHandlerPtr *sax;
28550 void **user_data;
28551
28552 if ((plug == NULL) || (plug->magic != XML_SAX_PLUG_MAGIC))
28553 return(-1);
28554 plug->magic = 0;
28555
Daniel Veillardf10ae122005-07-10 19:03:16 +000028556 xmlSchemaPostRun(plug->ctxt);
Daniel Veillard971771e2005-07-09 17:32:57 +000028557 /* restore the data */
28558 sax = plug->user_sax_ptr;
28559 *sax = plug->user_sax;
28560 if (plug->user_sax != NULL) {
28561 user_data = plug->user_data_ptr;
28562 *user_data = plug->user_data;
28563 }
28564
28565 /* free and return */
28566 xmlFree(plug);
28567 return(0);
28568}
28569
28570/**
Daniel Veillard4255d502002-04-16 15:50:10 +000028571 * xmlSchemaValidateStream:
28572 * @ctxt: a schema validation context
28573 * @input: the input to use for reading the data
28574 * @enc: an optional encoding information
28575 * @sax: a SAX handler for the resulting events
28576 * @user_data: the context to provide to the SAX handler.
28577 *
Daniel Veillardcdc82732005-07-08 15:04:06 +000028578 * Validate an input based on a flow of SAX event from the parser
28579 * and forward the events to the @sax handler with the provided @user_data
28580 * the user provided @sax handler must be a SAX2 one.
Daniel Veillard4255d502002-04-16 15:50:10 +000028581 *
28582 * Returns 0 if the document is schemas valid, a positive error code
28583 * number otherwise and -1 in case of internal or API error.
28584 */
Daniel Veillardd0c9c322003-10-10 00:49:42 +000028585int
Daniel Veillard4255d502002-04-16 15:50:10 +000028586xmlSchemaValidateStream(xmlSchemaValidCtxtPtr ctxt,
Daniel Veillardd0c9c322003-10-10 00:49:42 +000028587 xmlParserInputBufferPtr input, xmlCharEncoding enc,
28588 xmlSAXHandlerPtr sax, void *user_data)
28589{
Daniel Veillard971771e2005-07-09 17:32:57 +000028590 xmlSchemaSAXPlugPtr plug = NULL;
28591 xmlSAXHandlerPtr old_sax = NULL;
28592 xmlParserCtxtPtr pctxt = NULL;
28593 xmlParserInputPtr inputStream = NULL;
Daniel Veillardcdc82732005-07-08 15:04:06 +000028594 int ret;
28595
Daniel Veillard4255d502002-04-16 15:50:10 +000028596 if ((ctxt == NULL) || (input == NULL))
Daniel Veillardd0c9c322003-10-10 00:49:42 +000028597 return (-1);
Daniel Veillardcdc82732005-07-08 15:04:06 +000028598
Daniel Veillardcdc82732005-07-08 15:04:06 +000028599 /*
28600 * prepare the parser
28601 */
28602 pctxt = xmlNewParserCtxt();
28603 if (pctxt == NULL)
28604 return (-1);
28605 old_sax = pctxt->sax;
Daniel Veillard971771e2005-07-09 17:32:57 +000028606 pctxt->sax = sax;
28607 pctxt->userData = user_data;
Daniel Veillardcdc82732005-07-08 15:04:06 +000028608#if 0
28609 if (options)
28610 xmlCtxtUseOptions(pctxt, options);
28611#endif
Daniel Veillarddee23482008-04-11 12:58:43 +000028612 pctxt->linenumbers = 1;
Daniel Veillardcdc82732005-07-08 15:04:06 +000028613
Daniel Veillardf0af8ec2005-07-08 17:27:33 +000028614 inputStream = xmlNewIOInputStream(pctxt, input, enc);;
Daniel Veillardcdc82732005-07-08 15:04:06 +000028615 if (inputStream == NULL) {
28616 ret = -1;
28617 goto done;
28618 }
28619 inputPush(pctxt, inputStream);
28620 ctxt->parserCtxt = pctxt;
28621 ctxt->input = input;
28622
28623 /*
Daniel Veillard971771e2005-07-09 17:32:57 +000028624 * Plug the validation and launch the parsing
Daniel Veillardcdc82732005-07-08 15:04:06 +000028625 */
Daniel Veillard971771e2005-07-09 17:32:57 +000028626 plug = xmlSchemaSAXPlug(ctxt, &(pctxt->sax), &(pctxt->userData));
28627 if (plug == NULL) {
28628 ret = -1;
28629 goto done;
28630 }
28631 ctxt->input = input;
28632 ctxt->enc = enc;
28633 ctxt->sax = pctxt->sax;
Daniel Veillardcdc82732005-07-08 15:04:06 +000028634 ctxt->flags |= XML_SCHEMA_VALID_CTXT_FLAG_STREAM;
28635 ret = xmlSchemaVStart(ctxt);
28636
28637 if ((ret == 0) && (! ctxt->parserCtxt->wellFormed)) {
28638 ret = ctxt->parserCtxt->errNo;
28639 if (ret == 0)
28640 ret = 1;
Daniel Veillard33fe2882008-04-10 08:09:25 +000028641 }
Daniel Veillardcdc82732005-07-08 15:04:06 +000028642
28643done:
Daniel Veillard971771e2005-07-09 17:32:57 +000028644 ctxt->parserCtxt = NULL;
28645 ctxt->sax = NULL;
28646 ctxt->input = NULL;
28647 if (plug != NULL) {
28648 xmlSchemaSAXUnplug(plug);
28649 }
Daniel Veillardcdc82732005-07-08 15:04:06 +000028650 /* cleanup */
Daniel Veillard971771e2005-07-09 17:32:57 +000028651 if (pctxt != NULL) {
28652 pctxt->sax = old_sax;
28653 xmlFreeParserCtxt(pctxt);
28654 }
Daniel Veillardcdc82732005-07-08 15:04:06 +000028655 return (ret);
Daniel Veillard4255d502002-04-16 15:50:10 +000028656}
28657
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000028658/**
28659 * xmlSchemaValidateFile:
28660 * @ctxt: a schema validation context
Daniel Veillard81562d22005-06-15 13:27:56 +000028661 * @filename: the URI of the instance
28662 * @options: a future set of options, currently unused
28663 *
28664 * Do a schemas validation of the given resource, it will use the
28665 * SAX streamable validation internally.
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000028666 *
28667 * Returns 0 if the document is valid, a positive error code
28668 * number otherwise and -1 in case of an internal or API error.
28669 */
28670int
28671xmlSchemaValidateFile(xmlSchemaValidCtxtPtr ctxt,
Kasimier T. Buchcikc63fbbf2005-06-15 12:54:05 +000028672 const char * filename,
28673 int options ATTRIBUTE_UNUSED)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000028674{
28675 int ret;
Kasimier T. Buchcik72d3adc2005-07-08 16:43:37 +000028676 xmlParserInputBufferPtr input;
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000028677
28678 if ((ctxt == NULL) || (filename == NULL))
28679 return (-1);
Daniel Veillarddee23482008-04-11 12:58:43 +000028680
Kasimier T. Buchcik72d3adc2005-07-08 16:43:37 +000028681 input = xmlParserInputBufferCreateFilename(filename,
28682 XML_CHAR_ENCODING_NONE);
28683 if (input == NULL)
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000028684 return (-1);
Kasimier T. Buchcik72d3adc2005-07-08 16:43:37 +000028685 ret = xmlSchemaValidateStream(ctxt, input, XML_CHAR_ENCODING_NONE,
Daniel Veillarddee23482008-04-11 12:58:43 +000028686 NULL, NULL);
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000028687 return (ret);
Daniel Veillard81562d22005-06-15 13:27:56 +000028688}
Kasimier T. Buchcik4efd90d2005-06-09 10:32:53 +000028689
Daniel Veillarddee23482008-04-11 12:58:43 +000028690/**
28691 * xmlSchemaValidCtxtGetParserCtxt:
28692 * @ctxt: a schema validation context
28693 *
28694 * allow access to the parser context of the schema validation context
28695 *
28696 * Returns the parser context of the schema validation context or NULL
28697 * in case of error.
28698 */
28699xmlParserCtxtPtr
28700xmlSchemaValidCtxtGetParserCtxt(xmlSchemaValidCtxtPtr ctxt)
28701{
28702 if (ctxt == NULL)
28703 return(NULL);
28704 return (ctxt->parserCtxt);
28705}
28706
Daniel Veillard5d4644e2005-04-01 13:11:58 +000028707#define bottom_xmlschemas
28708#include "elfgcchack.h"
Daniel Veillard4255d502002-04-16 15:50:10 +000028709#endif /* LIBXML_SCHEMAS_ENABLED */