Coverage Report

Created: 2024-02-28 06:15

/src/libprotobuf-mutator/build/examples/libxml2/external.libxml2/src/external.libxml2/xmlschemas.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * schemas.c : implementation of the XML Schema handling and
3
 *             schema validity checking
4
 *
5
 * See Copyright for the status of this software.
6
 *
7
 * Daniel Veillard <veillard@redhat.com>
8
 */
9
10
/*
11
 * TODO:
12
 *   - when types are redefined in includes, check that all
13
 *     types in the redef list are equal
14
 *     -> need a type equality operation.
15
 *   - if we don't intend to use the schema for schemas, we
16
 *     need to validate all schema attributes (ref, type, name)
17
 *     against their types.
18
 *   - Eliminate item creation for: ??
19
 *
20
 * URGENT TODO:
21
 *   - For xsi-driven schema acquisition, augment the IDCs after every
22
 *     acquisition episode (xmlSchemaAugmentIDC).
23
 *
24
 * NOTES:
25
 *   - Eliminated item creation for: <restriction>, <extension>,
26
 *     <simpleContent>, <complexContent>, <list>, <union>
27
 *
28
 * PROBLEMS:
29
 *   - http://lists.w3.org/Archives/Public/www-xml-schema-comments/2005JulSep/0337.html
30
 *     IDC XPath expression and chameleon includes: the targetNamespace is changed, so
31
 *     XPath will have trouble to resolve to this namespace, since not known.
32
 *
33
 *
34
 * CONSTRAINTS:
35
 *
36
 * Schema Component Constraint:
37
 *   All Group Limited (cos-all-limited)
38
 *   Status: complete
39
 *   (1.2)
40
 *     In xmlSchemaGroupDefReferenceTermFixup() and
41
 *   (2)
42
 *     In xmlSchemaParseModelGroup()
43
 *     TODO: Actually this should go to component-level checks,
44
 *     but is done here due to performance. Move it to an other layer
45
 *     is schema construction via an API is implemented.
46
 */
47
48
/* To avoid EBCDIC trouble when parsing on zOS */
49
#if defined(__MVS__)
50
#pragma convert("ISO8859-1")
51
#endif
52
53
#define IN_LIBXML
54
#include "libxml.h"
55
56
#ifdef LIBXML_SCHEMAS_ENABLED
57
58
#include <string.h>
59
#include <libxml/xmlmemory.h>
60
#include <libxml/parser.h>
61
#include <libxml/parserInternals.h>
62
#include <libxml/hash.h>
63
#include <libxml/uri.h>
64
#include <libxml/xmlschemas.h>
65
#include <libxml/schemasInternals.h>
66
#include <libxml/xmlschemastypes.h>
67
#include <libxml/xmlautomata.h>
68
#include <libxml/xmlregexp.h>
69
#include <libxml/dict.h>
70
#include <libxml/encoding.h>
71
#include <libxml/xmlIO.h>
72
#ifdef LIBXML_PATTERN_ENABLED
73
#include <libxml/pattern.h>
74
#endif
75
#ifdef LIBXML_READER_ENABLED
76
#include <libxml/xmlreader.h>
77
#endif
78
79
#include "private/error.h"
80
#include "private/string.h"
81
82
/* #define WXS_ELEM_DECL_CONS_ENABLED */
83
84
/* #define ENABLE_PARTICLE_RESTRICTION 1 */
85
86
#define ENABLE_REDEFINE
87
88
/* #define ENABLE_NAMED_LOCALS */
89
90
/* #define ENABLE_IDC_NODE_TABLES_TEST */
91
92
#define DUMP_CONTENT_MODEL
93
94
#ifdef LIBXML_READER_ENABLED
95
/* #define XML_SCHEMA_READER_ENABLED */
96
#endif
97
98
0
#define UNBOUNDED (1 << 30)
99
100
0
#define XML_SCHEMAS_NO_NAMESPACE (const xmlChar *) "##"
101
102
/*
103
 * The XML Schemas namespaces
104
 */
105
static const xmlChar *xmlSchemaNs = (const xmlChar *)
106
    "http://www.w3.org/2001/XMLSchema";
107
108
static const xmlChar *xmlSchemaInstanceNs = (const xmlChar *)
109
    "http://www.w3.org/2001/XMLSchema-instance";
110
111
static const xmlChar *xmlNamespaceNs = (const xmlChar *)
112
    "http://www.w3.org/2000/xmlns/";
113
114
/*
115
* Come casting macros.
116
*/
117
0
#define ACTXT_CAST (xmlSchemaAbstractCtxtPtr)
118
0
#define PCTXT_CAST (xmlSchemaParserCtxtPtr)
119
#define VCTXT_CAST (xmlSchemaValidCtxtPtr)
120
0
#define WXS_BASIC_CAST (xmlSchemaBasicItemPtr)
121
0
#define WXS_TREE_CAST (xmlSchemaTreeItemPtr)
122
0
#define WXS_PTC_CAST (xmlSchemaParticlePtr)
123
0
#define WXS_TYPE_CAST (xmlSchemaTypePtr)
124
0
#define WXS_ELEM_CAST (xmlSchemaElementPtr)
125
0
#define WXS_ATTR_GROUP_CAST (xmlSchemaAttributeGroupPtr)
126
0
#define WXS_ATTR_CAST (xmlSchemaAttributePtr)
127
0
#define WXS_ATTR_USE_CAST (xmlSchemaAttributeUsePtr)
128
0
#define WXS_ATTR_PROHIB_CAST (xmlSchemaAttributeUseProhibPtr)
129
0
#define WXS_MODEL_GROUPDEF_CAST (xmlSchemaModelGroupDefPtr)
130
0
#define WXS_MODEL_GROUP_CAST (xmlSchemaModelGroupPtr)
131
0
#define WXS_IDC_CAST (xmlSchemaIDCPtr)
132
0
#define WXS_QNAME_CAST (xmlSchemaQNameRefPtr)
133
0
#define WXS_LIST_CAST (xmlSchemaItemListPtr)
134
135
/*
136
* Macros to query common properties of components.
137
*/
138
0
#define WXS_ITEM_NODE(i) xmlSchemaGetComponentNode(WXS_BASIC_CAST (i))
139
140
0
#define WXS_ITEM_TYPE_NAME(i) xmlSchemaGetComponentTypeStr(WXS_BASIC_CAST (i))
141
/*
142
* Macros for element declarations.
143
*/
144
0
#define WXS_ELEM_TYPEDEF(e) (e)->subtypes
145
146
0
#define WXS_SUBST_HEAD(item) (item)->refDecl
147
/*
148
* Macros for attribute declarations.
149
*/
150
0
#define WXS_ATTR_TYPEDEF(a) (a)->subtypes
151
/*
152
* Macros for attribute uses.
153
*/
154
0
#define WXS_ATTRUSE_DECL(au) (WXS_ATTR_USE_CAST (au))->attrDecl
155
156
0
#define WXS_ATTRUSE_TYPEDEF(au) WXS_ATTR_TYPEDEF(WXS_ATTRUSE_DECL( WXS_ATTR_USE_CAST au))
157
158
0
#define WXS_ATTRUSE_DECL_NAME(au) (WXS_ATTRUSE_DECL(au))->name
159
160
0
#define WXS_ATTRUSE_DECL_TNS(au) (WXS_ATTRUSE_DECL(au))->targetNamespace
161
/*
162
* Macros for attribute groups.
163
*/
164
0
#define WXS_ATTR_GROUP_HAS_REFS(ag) ((WXS_ATTR_GROUP_CAST (ag))->flags & XML_SCHEMAS_ATTRGROUP_HAS_REFS)
165
0
#define WXS_ATTR_GROUP_EXPANDED(ag) ((WXS_ATTR_GROUP_CAST (ag))->flags & XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED)
166
/*
167
* Macros for particles.
168
*/
169
0
#define WXS_PARTICLE(p) WXS_PTC_CAST (p)
170
171
0
#define WXS_PARTICLE_TERM(p) (WXS_PARTICLE(p))->children
172
173
#define WXS_PARTICLE_TERM_AS_ELEM(p) (WXS_ELEM_CAST WXS_PARTICLE_TERM(p))
174
175
#define WXS_PARTICLE_MODEL(p) WXS_MODEL_GROUP_CAST WXS_PARTICLE(p)->children
176
/*
177
* Macros for model groups definitions.
178
*/
179
0
#define WXS_MODELGROUPDEF_MODEL(mgd) (WXS_MODEL_GROUP_CAST (mgd))->children
180
/*
181
* Macros for model groups.
182
*/
183
#define WXS_IS_MODEL_GROUP(i) \
184
0
    (((i)->type == XML_SCHEMA_TYPE_SEQUENCE) || \
185
0
     ((i)->type == XML_SCHEMA_TYPE_CHOICE) || \
186
0
     ((i)->type == XML_SCHEMA_TYPE_ALL))
187
188
0
#define WXS_MODELGROUP_PARTICLE(mg) WXS_PTC_CAST (mg)->children
189
/*
190
* Macros for schema buckets.
191
*/
192
0
#define WXS_IS_BUCKET_INCREDEF(t) (((t) == XML_SCHEMA_SCHEMA_INCLUDE) || \
193
0
    ((t) == XML_SCHEMA_SCHEMA_REDEFINE))
194
195
0
#define WXS_IS_BUCKET_IMPMAIN(t) (((t) == XML_SCHEMA_SCHEMA_MAIN) || \
196
0
    ((t) == XML_SCHEMA_SCHEMA_IMPORT))
197
198
0
#define WXS_IMPBUCKET(b) ((xmlSchemaImportPtr) (b))
199
200
0
#define WXS_INCBUCKET(b) ((xmlSchemaIncludePtr) (b))
201
/*
202
* Macros for complex/simple types.
203
*/
204
#define WXS_IS_ANYTYPE(i) \
205
0
     (( (i)->type == XML_SCHEMA_TYPE_BASIC) && \
206
0
      ( (WXS_TYPE_CAST (i))->builtInType == XML_SCHEMAS_ANYTYPE))
207
208
#define WXS_IS_COMPLEX(i) \
209
0
    (((i)->type == XML_SCHEMA_TYPE_COMPLEX) || \
210
0
     ((i)->builtInType == XML_SCHEMAS_ANYTYPE))
211
212
#define WXS_IS_SIMPLE(item) \
213
0
    ((item->type == XML_SCHEMA_TYPE_SIMPLE) || \
214
0
     ((item->type == XML_SCHEMA_TYPE_BASIC) && \
215
0
      (item->builtInType != XML_SCHEMAS_ANYTYPE)))
216
217
#define WXS_IS_ANY_SIMPLE_TYPE(i) \
218
0
    (((i)->type == XML_SCHEMA_TYPE_BASIC) && \
219
0
      ((i)->builtInType == XML_SCHEMAS_ANYSIMPLETYPE))
220
221
#define WXS_IS_RESTRICTION(t) \
222
0
    ((t)->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION)
223
224
#define WXS_IS_EXTENSION(t) \
225
0
    ((t)->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION)
226
227
#define WXS_IS_TYPE_NOT_FIXED(i) \
228
0
    (((i)->type != XML_SCHEMA_TYPE_BASIC) && \
229
0
     (((i)->flags & XML_SCHEMAS_TYPE_INTERNAL_RESOLVED) == 0))
230
231
#define WXS_IS_TYPE_NOT_FIXED_1(item) \
232
0
    (((item)->type != XML_SCHEMA_TYPE_BASIC) && \
233
0
     (((item)->flags & XML_SCHEMAS_TYPE_FIXUP_1) == 0))
234
235
#define WXS_TYPE_IS_GLOBAL(t) ((t)->flags & XML_SCHEMAS_TYPE_GLOBAL)
236
237
#define WXS_TYPE_IS_LOCAL(t) (((t)->flags & XML_SCHEMAS_TYPE_GLOBAL) == 0)
238
/*
239
* Macros for exclusively for complex types.
240
*/
241
#define WXS_HAS_COMPLEX_CONTENT(item) \
242
    ((item->contentType == XML_SCHEMA_CONTENT_MIXED) || \
243
     (item->contentType == XML_SCHEMA_CONTENT_EMPTY) || \
244
     (item->contentType == XML_SCHEMA_CONTENT_ELEMENTS))
245
246
#define WXS_HAS_SIMPLE_CONTENT(item) \
247
0
    ((item->contentType == XML_SCHEMA_CONTENT_SIMPLE) || \
248
0
     (item->contentType == XML_SCHEMA_CONTENT_BASIC))
249
250
#define WXS_HAS_MIXED_CONTENT(item) \
251
0
    (item->contentType == XML_SCHEMA_CONTENT_MIXED)
252
253
#define WXS_EMPTIABLE(t) \
254
0
    (xmlSchemaIsParticleEmptiable(WXS_PTC_CAST (t)->subtypes))
255
256
0
#define WXS_TYPE_CONTENTTYPE(t) (t)->subtypes
257
258
0
#define WXS_TYPE_PARTICLE(t) WXS_PTC_CAST (t)->subtypes
259
260
0
#define WXS_TYPE_PARTICLE_TERM(t) WXS_PARTICLE_TERM(WXS_TYPE_PARTICLE(t))
261
/*
262
* Macros for exclusively for simple types.
263
*/
264
0
#define WXS_LIST_ITEMTYPE(t) (t)->subtypes
265
266
0
#define WXS_IS_ATOMIC(t) (t->flags & XML_SCHEMAS_TYPE_VARIETY_ATOMIC)
267
268
0
#define WXS_IS_LIST(t) (t->flags & XML_SCHEMAS_TYPE_VARIETY_LIST)
269
270
0
#define WXS_IS_UNION(t) (t->flags & XML_SCHEMAS_TYPE_VARIETY_UNION)
271
/*
272
* Misc parser context macros.
273
*/
274
0
#define WXS_CONSTRUCTOR(ctx) (ctx)->constructor
275
276
0
#define WXS_HAS_BUCKETS(ctx) \
277
0
( (WXS_CONSTRUCTOR((ctx))->buckets != NULL) && \
278
0
(WXS_CONSTRUCTOR((ctx))->buckets->nbItems > 0) )
279
280
0
#define WXS_SUBST_GROUPS(ctx) WXS_CONSTRUCTOR((ctx))->substGroups
281
282
0
#define WXS_BUCKET(ctx) WXS_CONSTRUCTOR((ctx))->bucket
283
284
#define WXS_SCHEMA(ctx) (ctx)->schema
285
286
#define WXS_ADD_LOCAL(ctx, item) \
287
0
    do { \
288
0
        if (xmlSchemaAddItemSize(&(WXS_BUCKET(ctx)->locals), 10, item) < 0) { \
289
0
            xmlFree(item); \
290
0
            item = NULL; \
291
0
        } \
292
0
    } while (0)
293
294
#define WXS_ADD_GLOBAL(ctx, item) \
295
0
    do { \
296
0
        if (xmlSchemaAddItemSize(&(WXS_BUCKET(ctx)->globals), 5, item) < 0) { \
297
0
            xmlFree(item); \
298
0
            item = NULL; \
299
0
        } \
300
0
    } while (0)
301
302
#define WXS_ADD_PENDING(ctx, item) \
303
0
    xmlSchemaAddItemSize(&((ctx)->constructor->pending), 10, item)
304
/*
305
* xmlSchemaItemList macros.
306
*/
307
0
#define WXS_ILIST_IS_EMPTY(l) ((l == NULL) || ((l)->nbItems == 0))
308
/*
309
* Misc macros.
310
*/
311
#define IS_SCHEMA(node, type) \
312
0
   ((node != NULL) && (node->ns != NULL) && \
313
0
    (xmlStrEqual(node->name, (const xmlChar *) type)) && \
314
0
    (xmlStrEqual(node->ns->href, xmlSchemaNs)))
315
316
0
#define FREE_AND_NULL(str) if ((str) != NULL) { xmlFree((xmlChar *) (str)); str = NULL; }
317
318
/*
319
* Since we put the default/fixed values into the dict, we can
320
* use pointer comparison for those values.
321
* REMOVED: (xmlStrEqual((v1), (v2)))
322
*/
323
0
#define WXS_ARE_DEFAULT_STR_EQUAL(v1, v2) ((v1) == (v2))
324
325
0
#define INODE_NILLED(item) (item->flags & XML_SCHEMA_ELEM_INFO_NILLED)
326
327
0
#define CAN_PARSE_SCHEMA(b) (((b)->doc != NULL) && ((b)->parsed == 0))
328
329
0
#define HFAILURE if (res == -1) goto exit_failure;
330
331
0
#define HERROR if (res != 0) goto exit_error;
332
333
0
#define HSTOP(ctx) if ((ctx)->stop) goto exit;
334
/*
335
* Some flags used for various schema constraints.
336
*/
337
0
#define SUBSET_RESTRICTION  1<<0
338
0
#define SUBSET_EXTENSION    1<<1
339
#define SUBSET_SUBSTITUTION 1<<2
340
#define SUBSET_LIST         1<<3
341
#define SUBSET_UNION        1<<4
342
343
typedef struct _xmlSchemaNodeInfo xmlSchemaNodeInfo;
344
typedef xmlSchemaNodeInfo *xmlSchemaNodeInfoPtr;
345
346
typedef struct _xmlSchemaItemList xmlSchemaItemList;
347
typedef xmlSchemaItemList *xmlSchemaItemListPtr;
348
struct _xmlSchemaItemList {
349
    void **items;  /* used for dynamic addition of schemata */
350
    int nbItems; /* used for dynamic addition of schemata */
351
    int sizeItems; /* used for dynamic addition of schemata */
352
};
353
354
0
#define XML_SCHEMA_CTXT_PARSER 1
355
0
#define XML_SCHEMA_CTXT_VALIDATOR 2
356
357
typedef struct _xmlSchemaAbstractCtxt xmlSchemaAbstractCtxt;
358
typedef xmlSchemaAbstractCtxt *xmlSchemaAbstractCtxtPtr;
359
struct _xmlSchemaAbstractCtxt {
360
    int type; /* E.g. XML_SCHEMA_CTXT_VALIDATOR */
361
    void *dummy; /* Fix alignment issues */
362
};
363
364
typedef struct _xmlSchemaBucket xmlSchemaBucket;
365
typedef xmlSchemaBucket *xmlSchemaBucketPtr;
366
367
0
#define XML_SCHEMA_SCHEMA_MAIN 0
368
0
#define XML_SCHEMA_SCHEMA_IMPORT 1
369
0
#define XML_SCHEMA_SCHEMA_INCLUDE 2
370
0
#define XML_SCHEMA_SCHEMA_REDEFINE 3
371
372
/**
373
 * xmlSchemaSchemaRelation:
374
 *
375
 * Used to create a graph of schema relationships.
376
 */
377
typedef struct _xmlSchemaSchemaRelation xmlSchemaSchemaRelation;
378
typedef xmlSchemaSchemaRelation *xmlSchemaSchemaRelationPtr;
379
struct _xmlSchemaSchemaRelation {
380
    xmlSchemaSchemaRelationPtr next;
381
    int type; /* E.g. XML_SCHEMA_SCHEMA_IMPORT */
382
    const xmlChar *importNamespace;
383
    xmlSchemaBucketPtr bucket;
384
};
385
386
0
#define XML_SCHEMA_BUCKET_MARKED 1<<0
387
0
#define XML_SCHEMA_BUCKET_COMPS_ADDED 1<<1
388
389
struct _xmlSchemaBucket {
390
    int type;
391
    int flags;
392
    const xmlChar *schemaLocation;
393
    const xmlChar *origTargetNamespace;
394
    const xmlChar *targetNamespace;
395
    xmlDocPtr doc;
396
    xmlSchemaSchemaRelationPtr relations;
397
    int located;
398
    int parsed;
399
    int imported;
400
    int preserveDoc;
401
    xmlSchemaItemListPtr globals; /* Global components. */
402
    xmlSchemaItemListPtr locals; /* Local components. */
403
};
404
405
/**
406
 * xmlSchemaImport:
407
 * (extends xmlSchemaBucket)
408
 *
409
 * Reflects a schema. Holds some information
410
 * about the schema and its toplevel components. Duplicate
411
 * toplevel components are not checked at this level.
412
 */
413
typedef struct _xmlSchemaImport xmlSchemaImport;
414
typedef xmlSchemaImport *xmlSchemaImportPtr;
415
struct _xmlSchemaImport {
416
    int type; /* Main OR import OR include. */
417
    int flags;
418
    const xmlChar *schemaLocation; /* The URI of the schema document. */
419
    /* For chameleon includes, @origTargetNamespace will be NULL */
420
    const xmlChar *origTargetNamespace;
421
    /*
422
    * For chameleon includes, @targetNamespace will be the
423
    * targetNamespace of the including schema.
424
    */
425
    const xmlChar *targetNamespace;
426
    xmlDocPtr doc; /* The schema node-tree. */
427
    /* @relations will hold any included/imported/redefined schemas. */
428
    xmlSchemaSchemaRelationPtr relations;
429
    int located;
430
    int parsed;
431
    int imported;
432
    int preserveDoc;
433
    xmlSchemaItemListPtr globals;
434
    xmlSchemaItemListPtr locals;
435
    /* The imported schema. */
436
    xmlSchemaPtr schema;
437
};
438
439
/*
440
* (extends xmlSchemaBucket)
441
*/
442
typedef struct _xmlSchemaInclude xmlSchemaInclude;
443
typedef xmlSchemaInclude *xmlSchemaIncludePtr;
444
struct _xmlSchemaInclude {
445
    int type;
446
    int flags;
447
    const xmlChar *schemaLocation;
448
    const xmlChar *origTargetNamespace;
449
    const xmlChar *targetNamespace;
450
    xmlDocPtr doc;
451
    xmlSchemaSchemaRelationPtr relations;
452
    int located;
453
    int parsed;
454
    int imported;
455
    int preserveDoc;
456
    xmlSchemaItemListPtr globals; /* Global components. */
457
    xmlSchemaItemListPtr locals; /* Local components. */
458
459
    /* The owning main or import schema bucket. */
460
    xmlSchemaImportPtr ownerImport;
461
};
462
463
/**
464
 * xmlSchemaBasicItem:
465
 *
466
 * The abstract base type for schema components.
467
 */
468
typedef struct _xmlSchemaBasicItem xmlSchemaBasicItem;
469
typedef xmlSchemaBasicItem *xmlSchemaBasicItemPtr;
470
struct _xmlSchemaBasicItem {
471
    xmlSchemaTypeType type;
472
    void *dummy; /* Fix alignment issues */
473
};
474
475
/**
476
 * xmlSchemaAnnotItem:
477
 *
478
 * The abstract base type for annotated schema components.
479
 * (Extends xmlSchemaBasicItem)
480
 */
481
typedef struct _xmlSchemaAnnotItem xmlSchemaAnnotItem;
482
typedef xmlSchemaAnnotItem *xmlSchemaAnnotItemPtr;
483
struct _xmlSchemaAnnotItem {
484
    xmlSchemaTypeType type;
485
    xmlSchemaAnnotPtr annot;
486
};
487
488
/**
489
 * xmlSchemaTreeItem:
490
 *
491
 * The abstract base type for tree-like structured schema components.
492
 * (Extends xmlSchemaAnnotItem)
493
 */
494
typedef struct _xmlSchemaTreeItem xmlSchemaTreeItem;
495
typedef xmlSchemaTreeItem *xmlSchemaTreeItemPtr;
496
struct _xmlSchemaTreeItem {
497
    xmlSchemaTypeType type;
498
    xmlSchemaAnnotPtr annot;
499
    xmlSchemaTreeItemPtr next;
500
    xmlSchemaTreeItemPtr children;
501
};
502
503
504
0
#define XML_SCHEMA_ATTR_USE_FIXED 1<<0
505
/**
506
 * xmlSchemaAttributeUsePtr:
507
 *
508
 * The abstract base type for tree-like structured schema components.
509
 * (Extends xmlSchemaTreeItem)
510
 */
511
typedef struct _xmlSchemaAttributeUse xmlSchemaAttributeUse;
512
typedef xmlSchemaAttributeUse *xmlSchemaAttributeUsePtr;
513
struct _xmlSchemaAttributeUse {
514
    xmlSchemaTypeType type;
515
    xmlSchemaAnnotPtr annot;
516
    xmlSchemaAttributeUsePtr next; /* The next attr. use. */
517
    /*
518
    * The attr. decl. OR a QName-ref. to an attr. decl. OR
519
    * a QName-ref. to an attribute group definition.
520
    */
521
    xmlSchemaAttributePtr attrDecl;
522
523
    int flags;
524
    xmlNodePtr node;
525
    int occurs; /* required, optional */
526
    const xmlChar * defValue;
527
    xmlSchemaValPtr defVal;
528
};
529
530
/**
531
 * xmlSchemaAttributeUseProhibPtr:
532
 *
533
 * A helper component to reflect attribute prohibitions.
534
 * (Extends xmlSchemaBasicItem)
535
 */
536
typedef struct _xmlSchemaAttributeUseProhib xmlSchemaAttributeUseProhib;
537
typedef xmlSchemaAttributeUseProhib *xmlSchemaAttributeUseProhibPtr;
538
struct _xmlSchemaAttributeUseProhib {
539
    xmlSchemaTypeType type; /* == XML_SCHEMA_EXTRA_ATTR_USE_PROHIB */
540
    xmlNodePtr node;
541
    const xmlChar *name;
542
    const xmlChar *targetNamespace;
543
    int isRef;
544
};
545
546
/**
547
 * xmlSchemaRedef:
548
 */
549
typedef struct _xmlSchemaRedef xmlSchemaRedef;
550
typedef xmlSchemaRedef *xmlSchemaRedefPtr;
551
struct _xmlSchemaRedef {
552
    xmlSchemaRedefPtr next;
553
    xmlSchemaBasicItemPtr item; /* The redefining component. */
554
    xmlSchemaBasicItemPtr reference; /* The referencing component. */
555
    xmlSchemaBasicItemPtr target; /* The to-be-redefined component. */
556
    const xmlChar *refName; /* The name of the to-be-redefined component. */
557
    const xmlChar *refTargetNs; /* The target namespace of the
558
                                   to-be-redefined comp. */
559
    xmlSchemaBucketPtr targetBucket; /* The redefined schema. */
560
};
561
562
/**
563
 * xmlSchemaConstructionCtxt:
564
 */
565
typedef struct _xmlSchemaConstructionCtxt xmlSchemaConstructionCtxt;
566
typedef xmlSchemaConstructionCtxt *xmlSchemaConstructionCtxtPtr;
567
struct _xmlSchemaConstructionCtxt {
568
    xmlSchemaPtr mainSchema; /* The main schema. */
569
    xmlSchemaBucketPtr mainBucket; /* The main schema bucket */
570
    xmlDictPtr dict;
571
    xmlSchemaItemListPtr buckets; /* List of schema buckets. */
572
    /* xmlSchemaItemListPtr relations; */ /* List of schema relations. */
573
    xmlSchemaBucketPtr bucket; /* The current schema bucket */
574
    xmlSchemaItemListPtr pending; /* All Components of all schemas that
575
                                     need to be fixed. */
576
    xmlHashTablePtr substGroups;
577
    xmlSchemaRedefPtr redefs;
578
    xmlSchemaRedefPtr lastRedef;
579
};
580
581
#define XML_SCHEMAS_PARSE_ERROR   1
582
0
#define SCHEMAS_PARSE_OPTIONS XML_PARSE_NOENT
583
584
struct _xmlSchemaParserCtxt {
585
    int type;
586
    void *errCtxt;             /* user specific error context */
587
    xmlSchemaValidityErrorFunc error;   /* the callback in case of errors */
588
    xmlSchemaValidityWarningFunc warning;       /* the callback in case of warning */
589
    int err;
590
    int nberrors;
591
    xmlStructuredErrorFunc serror;
592
593
    xmlSchemaConstructionCtxtPtr constructor;
594
    int ownsConstructor; /* TODO: Move this to parser *flags*. */
595
596
    /* xmlSchemaPtr topschema;  */
597
    /* xmlHashTablePtr namespaces;  */
598
599
    xmlSchemaPtr schema;        /* The main schema in use */
600
    int counter;
601
602
    const xmlChar *URL;
603
    xmlDocPtr doc;
604
    int preserve;   /* Whether the doc should be freed  */
605
606
    const char *buffer;
607
    int size;
608
609
    /*
610
     * Used to build complex element content models
611
     */
612
    xmlAutomataPtr am;
613
    xmlAutomataStatePtr start;
614
    xmlAutomataStatePtr end;
615
    xmlAutomataStatePtr state;
616
617
    xmlDictPtr dict;    /* dictionary for interned string names */
618
    xmlSchemaTypePtr ctxtType; /* The current context simple/complex type */
619
    int options;
620
    xmlSchemaValidCtxtPtr vctxt;
621
    int isS4S;
622
    int isRedefine;
623
    int xsiAssemble;
624
    int stop; /* If the parser should stop; i.e. a critical error. */
625
    const xmlChar *targetNamespace;
626
    xmlSchemaBucketPtr redefined; /* The schema to be redefined. */
627
628
    xmlSchemaRedefPtr redef; /* Used for redefinitions. */
629
    int redefCounter; /* Used for redefinitions. */
630
    xmlSchemaItemListPtr attrProhibs;
631
};
632
633
/**
634
 * xmlSchemaQNameRef:
635
 *
636
 * A component reference item (not a schema component)
637
 * (Extends xmlSchemaBasicItem)
638
 */
639
typedef struct _xmlSchemaQNameRef xmlSchemaQNameRef;
640
typedef xmlSchemaQNameRef *xmlSchemaQNameRefPtr;
641
struct _xmlSchemaQNameRef {
642
    xmlSchemaTypeType type;
643
    xmlSchemaBasicItemPtr item; /* The resolved referenced item. */
644
    xmlSchemaTypeType itemType;
645
    const xmlChar *name;
646
    const xmlChar *targetNamespace;
647
    xmlNodePtr node;
648
};
649
650
/**
651
 * xmlSchemaParticle:
652
 *
653
 * A particle component.
654
 * (Extends xmlSchemaTreeItem)
655
 */
656
typedef struct _xmlSchemaParticle xmlSchemaParticle;
657
typedef xmlSchemaParticle *xmlSchemaParticlePtr;
658
struct _xmlSchemaParticle {
659
    xmlSchemaTypeType type;
660
    xmlSchemaAnnotPtr annot;
661
    xmlSchemaTreeItemPtr next; /* next particle */
662
    xmlSchemaTreeItemPtr children; /* the "term" (e.g. a model group,
663
  a group definition, a XML_SCHEMA_EXTRA_QNAMEREF (if a reference),
664
        etc.) */
665
    int minOccurs;
666
    int maxOccurs;
667
    xmlNodePtr node;
668
};
669
670
/**
671
 * xmlSchemaModelGroup:
672
 *
673
 * A model group component.
674
 * (Extends xmlSchemaTreeItem)
675
 */
676
typedef struct _xmlSchemaModelGroup xmlSchemaModelGroup;
677
typedef xmlSchemaModelGroup *xmlSchemaModelGroupPtr;
678
struct _xmlSchemaModelGroup {
679
    xmlSchemaTypeType type; /* XML_SCHEMA_TYPE_SEQUENCE, XML_SCHEMA_TYPE_CHOICE, XML_SCHEMA_TYPE_ALL */
680
    xmlSchemaAnnotPtr annot;
681
    xmlSchemaTreeItemPtr next; /* not used */
682
    xmlSchemaTreeItemPtr children; /* first particle (OR "element decl" OR "wildcard") */
683
    xmlNodePtr node;
684
};
685
686
0
#define XML_SCHEMA_MODEL_GROUP_DEF_MARKED 1<<0
687
0
#define XML_SCHEMA_MODEL_GROUP_DEF_REDEFINED 1<<1
688
/**
689
 * xmlSchemaModelGroupDef:
690
 *
691
 * A model group definition component.
692
 * (Extends xmlSchemaTreeItem)
693
 */
694
typedef struct _xmlSchemaModelGroupDef xmlSchemaModelGroupDef;
695
typedef xmlSchemaModelGroupDef *xmlSchemaModelGroupDefPtr;
696
struct _xmlSchemaModelGroupDef {
697
    xmlSchemaTypeType type; /* XML_SCHEMA_TYPE_GROUP */
698
    xmlSchemaAnnotPtr annot;
699
    xmlSchemaTreeItemPtr next; /* not used */
700
    xmlSchemaTreeItemPtr children; /* the "model group" */
701
    const xmlChar *name;
702
    const xmlChar *targetNamespace;
703
    xmlNodePtr node;
704
    int flags;
705
};
706
707
typedef struct _xmlSchemaIDC xmlSchemaIDC;
708
typedef xmlSchemaIDC *xmlSchemaIDCPtr;
709
710
/**
711
 * xmlSchemaIDCSelect:
712
 *
713
 * The identity-constraint "field" and "selector" item, holding the
714
 * XPath expression.
715
 */
716
typedef struct _xmlSchemaIDCSelect xmlSchemaIDCSelect;
717
typedef xmlSchemaIDCSelect *xmlSchemaIDCSelectPtr;
718
struct _xmlSchemaIDCSelect {
719
    xmlSchemaIDCSelectPtr next;
720
    xmlSchemaIDCPtr idc;
721
    int index; /* an index position if significant for IDC key-sequences */
722
    const xmlChar *xpath; /* the XPath expression */
723
    void *xpathComp; /* the compiled XPath expression */
724
};
725
726
/**
727
 * xmlSchemaIDC:
728
 *
729
 * The identity-constraint definition component.
730
 * (Extends xmlSchemaAnnotItem)
731
 */
732
733
struct _xmlSchemaIDC {
734
    xmlSchemaTypeType type;
735
    xmlSchemaAnnotPtr annot;
736
    xmlSchemaIDCPtr next;
737
    xmlNodePtr node;
738
    const xmlChar *name;
739
    const xmlChar *targetNamespace;
740
    xmlSchemaIDCSelectPtr selector;
741
    xmlSchemaIDCSelectPtr fields;
742
    int nbFields;
743
    xmlSchemaQNameRefPtr ref;
744
};
745
746
/**
747
 * xmlSchemaIDCAug:
748
 *
749
 * The augmented IDC information used for validation.
750
 */
751
typedef struct _xmlSchemaIDCAug xmlSchemaIDCAug;
752
typedef xmlSchemaIDCAug *xmlSchemaIDCAugPtr;
753
struct _xmlSchemaIDCAug {
754
    xmlSchemaIDCAugPtr next; /* next in a list */
755
    xmlSchemaIDCPtr def; /* the IDC definition */
756
    int keyrefDepth; /* the lowest tree level to which IDC
757
                        tables need to be bubbled upwards */
758
};
759
760
/**
761
 * xmlSchemaPSVIIDCKeySequence:
762
 *
763
 * The key sequence of a node table item.
764
 */
765
typedef struct _xmlSchemaPSVIIDCKey xmlSchemaPSVIIDCKey;
766
typedef xmlSchemaPSVIIDCKey *xmlSchemaPSVIIDCKeyPtr;
767
struct _xmlSchemaPSVIIDCKey {
768
    xmlSchemaTypePtr type;
769
    xmlSchemaValPtr val;
770
};
771
772
/**
773
 * xmlSchemaPSVIIDCNode:
774
 *
775
 * The node table item of a node table.
776
 */
777
typedef struct _xmlSchemaPSVIIDCNode xmlSchemaPSVIIDCNode;
778
typedef xmlSchemaPSVIIDCNode *xmlSchemaPSVIIDCNodePtr;
779
struct _xmlSchemaPSVIIDCNode {
780
    xmlNodePtr node;
781
    xmlSchemaPSVIIDCKeyPtr *keys;
782
    int nodeLine;
783
    int nodeQNameID;
784
785
};
786
787
/**
788
 * xmlSchemaPSVIIDCBinding:
789
 *
790
 * The identity-constraint binding item of the [identity-constraint table].
791
 */
792
typedef struct _xmlSchemaPSVIIDCBinding xmlSchemaPSVIIDCBinding;
793
typedef xmlSchemaPSVIIDCBinding *xmlSchemaPSVIIDCBindingPtr;
794
struct _xmlSchemaPSVIIDCBinding {
795
    xmlSchemaPSVIIDCBindingPtr next; /* next binding of a specific node */
796
    xmlSchemaIDCPtr definition; /* the IDC definition */
797
    xmlSchemaPSVIIDCNodePtr *nodeTable; /* array of key-sequences */
798
    int nbNodes; /* number of entries in the node table */
799
    int sizeNodes; /* size of the node table */
800
    xmlSchemaItemListPtr dupls;
801
};
802
803
804
0
#define XPATH_STATE_OBJ_TYPE_IDC_SELECTOR 1
805
0
#define XPATH_STATE_OBJ_TYPE_IDC_FIELD 2
806
807
#define XPATH_STATE_OBJ_MATCHES -2
808
#define XPATH_STATE_OBJ_BLOCKED -3
809
810
typedef struct _xmlSchemaIDCMatcher xmlSchemaIDCMatcher;
811
typedef xmlSchemaIDCMatcher *xmlSchemaIDCMatcherPtr;
812
813
/**
814
 * xmlSchemaIDCStateObj:
815
 *
816
 * The state object used to evaluate XPath expressions.
817
 */
818
typedef struct _xmlSchemaIDCStateObj xmlSchemaIDCStateObj;
819
typedef xmlSchemaIDCStateObj *xmlSchemaIDCStateObjPtr;
820
struct _xmlSchemaIDCStateObj {
821
    int type;
822
    xmlSchemaIDCStateObjPtr next; /* next if in a list */
823
    int depth; /* depth of creation */
824
    int *history; /* list of (depth, state-id) tuples */
825
    int nbHistory;
826
    int sizeHistory;
827
    xmlSchemaIDCMatcherPtr matcher; /* the correspondent field/selector
828
                                       matcher */
829
    xmlSchemaIDCSelectPtr sel;
830
    void *xpathCtxt;
831
};
832
833
0
#define IDC_MATCHER 0
834
835
/**
836
 * xmlSchemaIDCMatcher:
837
 *
838
 * Used to evaluate IDC selectors (and fields).
839
 */
840
struct _xmlSchemaIDCMatcher {
841
    int type;
842
    int depth; /* the tree depth at creation time */
843
    xmlSchemaIDCMatcherPtr next; /* next in the list */
844
    xmlSchemaIDCMatcherPtr nextCached; /* next in the cache list */
845
    xmlSchemaIDCAugPtr aidc; /* the augmented IDC item */
846
    int idcType;
847
    xmlSchemaPSVIIDCKeyPtr **keySeqs; /* the key-sequences of the target
848
                                         elements */
849
    int sizeKeySeqs;
850
    xmlSchemaItemListPtr targets; /* list of target-node
851
                                     (xmlSchemaPSVIIDCNodePtr) entries */
852
    xmlHashTablePtr htab;
853
};
854
855
/*
856
* Element info flags.
857
*/
858
0
#define XML_SCHEMA_NODE_INFO_FLAG_OWNED_NAMES  1<<0
859
0
#define XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES 1<<1
860
0
#define XML_SCHEMA_ELEM_INFO_NILLED        1<<2
861
0
#define XML_SCHEMA_ELEM_INFO_LOCAL_TYPE        1<<3
862
863
0
#define XML_SCHEMA_NODE_INFO_VALUE_NEEDED      1<<4
864
0
#define XML_SCHEMA_ELEM_INFO_EMPTY             1<<5
865
#define XML_SCHEMA_ELEM_INFO_HAS_CONTENT       1<<6
866
867
0
#define XML_SCHEMA_ELEM_INFO_HAS_ELEM_CONTENT  1<<7
868
0
#define XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT  1<<8
869
0
#define XML_SCHEMA_NODE_INFO_ERR_NOT_EXPECTED  1<<9
870
0
#define XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE  1<<10
871
872
/**
873
 * xmlSchemaNodeInfo:
874
 *
875
 * Holds information of an element node.
876
 */
877
struct _xmlSchemaNodeInfo {
878
    int nodeType;
879
    xmlNodePtr node;
880
    int nodeLine;
881
    const xmlChar *localName;
882
    const xmlChar *nsName;
883
    const xmlChar *value;
884
    xmlSchemaValPtr val; /* the pre-computed value if any */
885
    xmlSchemaTypePtr typeDef; /* the complex/simple type definition if any */
886
887
    int flags; /* combination of node info flags */
888
889
    int valNeeded;
890
    int normVal;
891
892
    xmlSchemaElementPtr decl; /* the element/attribute declaration */
893
    int depth;
894
    xmlSchemaPSVIIDCBindingPtr idcTable; /* the table of PSVI IDC bindings
895
                                            for the scope element*/
896
    xmlSchemaIDCMatcherPtr idcMatchers; /* the IDC matchers for the scope
897
                                           element */
898
    xmlRegExecCtxtPtr regexCtxt;
899
900
    const xmlChar **nsBindings; /* Namespace bindings on this element */
901
    int nbNsBindings;
902
    int sizeNsBindings;
903
904
    int hasKeyrefs;
905
    int appliedXPath; /* Indicates that an XPath has been applied. */
906
};
907
908
0
#define XML_SCHEMAS_ATTR_UNKNOWN 1
909
0
#define XML_SCHEMAS_ATTR_ASSESSED 2
910
#define XML_SCHEMAS_ATTR_PROHIBITED 3
911
0
#define XML_SCHEMAS_ATTR_ERR_MISSING 4
912
0
#define XML_SCHEMAS_ATTR_INVALID_VALUE 5
913
0
#define XML_SCHEMAS_ATTR_ERR_NO_TYPE 6
914
0
#define XML_SCHEMAS_ATTR_ERR_FIXED_VALUE 7
915
0
#define XML_SCHEMAS_ATTR_DEFAULT 8
916
#define XML_SCHEMAS_ATTR_VALIDATE_VALUE 9
917
0
#define XML_SCHEMAS_ATTR_ERR_WILD_STRICT_NO_DECL 10
918
#define XML_SCHEMAS_ATTR_HAS_ATTR_USE 11
919
#define XML_SCHEMAS_ATTR_HAS_ATTR_DECL 12
920
0
#define XML_SCHEMAS_ATTR_WILD_SKIP 13
921
0
#define XML_SCHEMAS_ATTR_WILD_LAX_NO_DECL 14
922
0
#define XML_SCHEMAS_ATTR_ERR_WILD_DUPLICATE_ID 15
923
0
#define XML_SCHEMAS_ATTR_ERR_WILD_AND_USE_ID 16
924
0
#define XML_SCHEMAS_ATTR_META 17
925
/*
926
* @metaType values of xmlSchemaAttrInfo.
927
*/
928
0
#define XML_SCHEMA_ATTR_INFO_META_XSI_TYPE 1
929
0
#define XML_SCHEMA_ATTR_INFO_META_XSI_NIL 2
930
0
#define XML_SCHEMA_ATTR_INFO_META_XSI_SCHEMA_LOC 3
931
0
#define XML_SCHEMA_ATTR_INFO_META_XSI_NO_NS_SCHEMA_LOC 4
932
0
#define XML_SCHEMA_ATTR_INFO_META_XMLNS 5
933
934
typedef struct _xmlSchemaAttrInfo xmlSchemaAttrInfo;
935
typedef xmlSchemaAttrInfo *xmlSchemaAttrInfoPtr;
936
struct _xmlSchemaAttrInfo {
937
    int nodeType;
938
    xmlNodePtr node;
939
    int nodeLine;
940
    const xmlChar *localName;
941
    const xmlChar *nsName;
942
    const xmlChar *value;
943
    xmlSchemaValPtr val; /* the pre-computed value if any */
944
    xmlSchemaTypePtr typeDef; /* the complex/simple type definition if any */
945
    int flags; /* combination of node info flags */
946
947
    xmlSchemaAttributePtr decl; /* the attribute declaration */
948
    xmlSchemaAttributeUsePtr use;  /* the attribute use */
949
    int state;
950
    int metaType;
951
    const xmlChar *vcValue; /* the value constraint value */
952
    xmlSchemaNodeInfoPtr parent;
953
};
954
955
956
0
#define XML_SCHEMA_VALID_CTXT_FLAG_STREAM 1
957
/**
958
 * xmlSchemaValidCtxt:
959
 *
960
 * A Schemas validation context
961
 */
962
struct _xmlSchemaValidCtxt {
963
    int type;
964
    void *errCtxt;             /* user specific data block */
965
    xmlSchemaValidityErrorFunc error;   /* the callback in case of errors */
966
    xmlSchemaValidityWarningFunc warning; /* the callback in case of warning */
967
    xmlStructuredErrorFunc serror;
968
969
    xmlSchemaPtr schema;        /* The schema in use */
970
    xmlDocPtr doc;
971
    xmlParserInputBufferPtr input;
972
    xmlCharEncoding enc;
973
    xmlSAXHandlerPtr sax;
974
    xmlParserCtxtPtr parserCtxt;
975
    void *user_data; /* TODO: What is this for? */
976
    char *filename;
977
978
    int err;
979
    int nberrors;
980
981
    xmlNodePtr node;
982
    xmlNodePtr cur;
983
    /* xmlSchemaTypePtr type; */
984
985
    xmlRegExecCtxtPtr regexp;
986
    xmlSchemaValPtr value;
987
988
    int valueWS;
989
    int options;
990
    xmlNodePtr validationRoot;
991
    xmlSchemaParserCtxtPtr pctxt;
992
    int xsiAssemble;
993
994
    int depth;
995
    xmlSchemaNodeInfoPtr *elemInfos; /* array of element information */
996
    int sizeElemInfos;
997
    xmlSchemaNodeInfoPtr inode; /* the current element information */
998
999
    xmlSchemaIDCAugPtr aidcs; /* a list of augmented IDC information */
1000
1001
    xmlSchemaIDCStateObjPtr xpathStates; /* first active state object. */
1002
    xmlSchemaIDCStateObjPtr xpathStatePool; /* first stored state object. */
1003
    xmlSchemaIDCMatcherPtr idcMatcherCache; /* Cache for IDC matcher objects. */
1004
1005
    xmlSchemaPSVIIDCNodePtr *idcNodes; /* list of all IDC node-table entries*/
1006
    int nbIdcNodes;
1007
    int sizeIdcNodes;
1008
1009
    xmlSchemaPSVIIDCKeyPtr *idcKeys; /* list of all IDC node-table entries */
1010
    int nbIdcKeys;
1011
    int sizeIdcKeys;
1012
1013
    int flags;
1014
1015
    xmlDictPtr dict;
1016
1017
#ifdef LIBXML_READER_ENABLED
1018
    xmlTextReaderPtr reader;
1019
#endif
1020
1021
    xmlSchemaAttrInfoPtr *attrInfos;
1022
    int nbAttrInfos;
1023
    int sizeAttrInfos;
1024
1025
    int skipDepth;
1026
    xmlSchemaItemListPtr nodeQNames;
1027
    int hasKeyrefs;
1028
    int createIDCNodeTables;
1029
    int psviExposeIDCNodeTables;
1030
1031
    /* Locator for error reporting in streaming mode */
1032
    xmlSchemaValidityLocatorFunc locFunc;
1033
    void *locCtxt;
1034
};
1035
1036
/**
1037
 * xmlSchemaSubstGroup:
1038
 *
1039
 *
1040
 */
1041
typedef struct _xmlSchemaSubstGroup xmlSchemaSubstGroup;
1042
typedef xmlSchemaSubstGroup *xmlSchemaSubstGroupPtr;
1043
struct _xmlSchemaSubstGroup {
1044
    xmlSchemaElementPtr head;
1045
    xmlSchemaItemListPtr members;
1046
};
1047
1048
/**
1049
 * xmlIDCHashEntry:
1050
 *
1051
 * an entry in hash tables to quickly look up keys/uniques
1052
 */
1053
typedef struct _xmlIDCHashEntry xmlIDCHashEntry;
1054
typedef xmlIDCHashEntry *xmlIDCHashEntryPtr;
1055
struct _xmlIDCHashEntry {
1056
    xmlIDCHashEntryPtr next; /* next item with same hash */
1057
    int index;               /* index into associated item list */
1058
};
1059
1060
/************************************************************************
1061
 *                  *
1062
 *      Some predeclarations        *
1063
 *                  *
1064
 ************************************************************************/
1065
1066
static int xmlSchemaParseInclude(xmlSchemaParserCtxtPtr ctxt,
1067
                                 xmlSchemaPtr schema,
1068
                                 xmlNodePtr node);
1069
static int xmlSchemaParseRedefine(xmlSchemaParserCtxtPtr ctxt,
1070
                                 xmlSchemaPtr schema,
1071
                                 xmlNodePtr node);
1072
static int
1073
xmlSchemaTypeFixup(xmlSchemaTypePtr type,
1074
                   xmlSchemaAbstractCtxtPtr ctxt);
1075
static const xmlChar *
1076
xmlSchemaFacetTypeToString(xmlSchemaTypeType type);
1077
static int
1078
xmlSchemaParseImport(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
1079
                     xmlNodePtr node);
1080
static int
1081
xmlSchemaCheckFacetValues(xmlSchemaTypePtr typeDecl,
1082
                       xmlSchemaParserCtxtPtr ctxt);
1083
static void
1084
xmlSchemaClearValidCtxt(xmlSchemaValidCtxtPtr vctxt);
1085
static xmlSchemaWhitespaceValueType
1086
xmlSchemaGetWhiteSpaceFacetValue(xmlSchemaTypePtr type);
1087
static xmlSchemaTreeItemPtr
1088
xmlSchemaParseModelGroup(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
1089
       xmlNodePtr node, xmlSchemaTypeType type,
1090
       int withParticle);
1091
static const xmlChar *
1092
xmlSchemaGetComponentTypeStr(xmlSchemaBasicItemPtr item);
1093
static xmlSchemaTypeLinkPtr
1094
xmlSchemaGetUnionSimpleTypeMemberTypes(xmlSchemaTypePtr type);
1095
static void
1096
xmlSchemaInternalErr(xmlSchemaAbstractCtxtPtr actxt,
1097
         const char *funcName,
1098
         const char *message) LIBXML_ATTR_FORMAT(3,0);
1099
static int
1100
xmlSchemaCheckCOSSTDerivedOK(xmlSchemaAbstractCtxtPtr ctxt,
1101
           xmlSchemaTypePtr type,
1102
           xmlSchemaTypePtr baseType,
1103
           int subset);
1104
static void
1105
xmlSchemaCheckElementDeclComponent(xmlSchemaElementPtr elemDecl,
1106
           xmlSchemaParserCtxtPtr ctxt);
1107
static void
1108
xmlSchemaComponentListFree(xmlSchemaItemListPtr list);
1109
static xmlSchemaQNameRefPtr
1110
xmlSchemaParseAttributeGroupRef(xmlSchemaParserCtxtPtr pctxt,
1111
        xmlSchemaPtr schema,
1112
        xmlNodePtr node);
1113
1114
/************************************************************************
1115
 *                  *
1116
 *      Helper functions              *
1117
 *                  *
1118
 ************************************************************************/
1119
1120
/**
1121
 * xmlSchemaItemTypeToStr:
1122
 * @type: the type of the schema item
1123
 *
1124
 * Returns the component name of a schema item.
1125
 */
1126
static const xmlChar *
1127
xmlSchemaItemTypeToStr(xmlSchemaTypeType type)
1128
0
{
1129
0
    switch (type) {
1130
0
  case XML_SCHEMA_TYPE_BASIC:
1131
0
      return(BAD_CAST "simple type definition");
1132
0
  case XML_SCHEMA_TYPE_SIMPLE:
1133
0
      return(BAD_CAST "simple type definition");
1134
0
  case XML_SCHEMA_TYPE_COMPLEX:
1135
0
      return(BAD_CAST "complex type definition");
1136
0
  case XML_SCHEMA_TYPE_ELEMENT:
1137
0
      return(BAD_CAST "element declaration");
1138
0
  case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
1139
0
      return(BAD_CAST "attribute use");
1140
0
  case XML_SCHEMA_TYPE_ATTRIBUTE:
1141
0
      return(BAD_CAST "attribute declaration");
1142
0
  case XML_SCHEMA_TYPE_GROUP:
1143
0
      return(BAD_CAST "model group definition");
1144
0
  case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1145
0
      return(BAD_CAST "attribute group definition");
1146
0
  case XML_SCHEMA_TYPE_NOTATION:
1147
0
      return(BAD_CAST "notation declaration");
1148
0
  case XML_SCHEMA_TYPE_SEQUENCE:
1149
0
      return(BAD_CAST "model group (sequence)");
1150
0
  case XML_SCHEMA_TYPE_CHOICE:
1151
0
      return(BAD_CAST "model group (choice)");
1152
0
  case XML_SCHEMA_TYPE_ALL:
1153
0
      return(BAD_CAST "model group (all)");
1154
0
  case XML_SCHEMA_TYPE_PARTICLE:
1155
0
      return(BAD_CAST "particle");
1156
0
  case XML_SCHEMA_TYPE_IDC_UNIQUE:
1157
0
      return(BAD_CAST "unique identity-constraint");
1158
      /* return(BAD_CAST "IDC (unique)"); */
1159
0
  case XML_SCHEMA_TYPE_IDC_KEY:
1160
0
      return(BAD_CAST "key identity-constraint");
1161
      /* return(BAD_CAST "IDC (key)"); */
1162
0
  case XML_SCHEMA_TYPE_IDC_KEYREF:
1163
0
      return(BAD_CAST "keyref identity-constraint");
1164
      /* return(BAD_CAST "IDC (keyref)"); */
1165
0
  case XML_SCHEMA_TYPE_ANY:
1166
0
      return(BAD_CAST "wildcard (any)");
1167
0
  case XML_SCHEMA_EXTRA_QNAMEREF:
1168
0
      return(BAD_CAST "[helper component] QName reference");
1169
0
  case XML_SCHEMA_EXTRA_ATTR_USE_PROHIB:
1170
0
      return(BAD_CAST "[helper component] attribute use prohibition");
1171
0
  default:
1172
0
      return(BAD_CAST "Not a schema component");
1173
0
    }
1174
0
}
1175
1176
/**
1177
 * xmlSchemaGetComponentTypeStr:
1178
 * @type: the type of the schema item
1179
 *
1180
 * Returns the component name of a schema item.
1181
 */
1182
static const xmlChar *
1183
xmlSchemaGetComponentTypeStr(xmlSchemaBasicItemPtr item)
1184
0
{
1185
0
    switch (item->type) {
1186
0
  case XML_SCHEMA_TYPE_BASIC:
1187
0
      if (WXS_IS_COMPLEX(WXS_TYPE_CAST item))
1188
0
    return(BAD_CAST "complex type definition");
1189
0
      else
1190
0
    return(BAD_CAST "simple type definition");
1191
0
  default:
1192
0
      return(xmlSchemaItemTypeToStr(item->type));
1193
0
    }
1194
0
}
1195
1196
/**
1197
 * xmlSchemaGetComponentNode:
1198
 * @item: a schema component
1199
 *
1200
 * Returns node associated with the schema component.
1201
 * NOTE that such a node need not be available; plus, a component's
1202
 * node need not to reflect the component directly, since there is no
1203
 * one-to-one relationship between the XML Schema representation and
1204
 * the component representation.
1205
 */
1206
static xmlNodePtr
1207
xmlSchemaGetComponentNode(xmlSchemaBasicItemPtr item)
1208
0
{
1209
0
    switch (item->type) {
1210
0
  case XML_SCHEMA_TYPE_ELEMENT:
1211
0
      return (((xmlSchemaElementPtr) item)->node);
1212
0
  case XML_SCHEMA_TYPE_ATTRIBUTE:
1213
0
      return (((xmlSchemaAttributePtr) item)->node);
1214
0
  case XML_SCHEMA_TYPE_COMPLEX:
1215
0
  case XML_SCHEMA_TYPE_SIMPLE:
1216
0
      return (((xmlSchemaTypePtr) item)->node);
1217
0
  case XML_SCHEMA_TYPE_ANY:
1218
0
  case XML_SCHEMA_TYPE_ANY_ATTRIBUTE:
1219
0
      return (((xmlSchemaWildcardPtr) item)->node);
1220
0
  case XML_SCHEMA_TYPE_PARTICLE:
1221
0
      return (((xmlSchemaParticlePtr) item)->node);
1222
0
  case XML_SCHEMA_TYPE_SEQUENCE:
1223
0
  case XML_SCHEMA_TYPE_CHOICE:
1224
0
  case XML_SCHEMA_TYPE_ALL:
1225
0
      return (((xmlSchemaModelGroupPtr) item)->node);
1226
0
  case XML_SCHEMA_TYPE_GROUP:
1227
0
      return (((xmlSchemaModelGroupDefPtr) item)->node);
1228
0
  case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1229
0
      return (((xmlSchemaAttributeGroupPtr) item)->node);
1230
0
  case XML_SCHEMA_TYPE_IDC_UNIQUE:
1231
0
  case XML_SCHEMA_TYPE_IDC_KEY:
1232
0
  case XML_SCHEMA_TYPE_IDC_KEYREF:
1233
0
      return (((xmlSchemaIDCPtr) item)->node);
1234
0
  case XML_SCHEMA_EXTRA_QNAMEREF:
1235
0
      return(((xmlSchemaQNameRefPtr) item)->node);
1236
  /* TODO: What to do with NOTATIONs?
1237
  case XML_SCHEMA_TYPE_NOTATION:
1238
      return (((xmlSchemaNotationPtr) item)->node);
1239
  */
1240
0
  case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
1241
0
      return (((xmlSchemaAttributeUsePtr) item)->node);
1242
0
  default:
1243
0
      return (NULL);
1244
0
    }
1245
0
}
1246
1247
#if 0
1248
/**
1249
 * xmlSchemaGetNextComponent:
1250
 * @item: a schema component
1251
 *
1252
 * Returns the next sibling of the schema component.
1253
 */
1254
static xmlSchemaBasicItemPtr
1255
xmlSchemaGetNextComponent(xmlSchemaBasicItemPtr item)
1256
{
1257
    switch (item->type) {
1258
  case XML_SCHEMA_TYPE_ELEMENT:
1259
      return ((xmlSchemaBasicItemPtr) ((xmlSchemaElementPtr) item)->next);
1260
  case XML_SCHEMA_TYPE_ATTRIBUTE:
1261
      return ((xmlSchemaBasicItemPtr) ((xmlSchemaAttributePtr) item)->next);
1262
  case XML_SCHEMA_TYPE_COMPLEX:
1263
  case XML_SCHEMA_TYPE_SIMPLE:
1264
      return ((xmlSchemaBasicItemPtr) ((xmlSchemaTypePtr) item)->next);
1265
  case XML_SCHEMA_TYPE_ANY:
1266
  case XML_SCHEMA_TYPE_ANY_ATTRIBUTE:
1267
      return (NULL);
1268
  case XML_SCHEMA_TYPE_PARTICLE:
1269
      return ((xmlSchemaBasicItemPtr) ((xmlSchemaParticlePtr) item)->next);
1270
  case XML_SCHEMA_TYPE_SEQUENCE:
1271
  case XML_SCHEMA_TYPE_CHOICE:
1272
  case XML_SCHEMA_TYPE_ALL:
1273
      return (NULL);
1274
  case XML_SCHEMA_TYPE_GROUP:
1275
      return (NULL);
1276
  case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1277
      return ((xmlSchemaBasicItemPtr) ((xmlSchemaAttributeGroupPtr) item)->next);
1278
  case XML_SCHEMA_TYPE_IDC_UNIQUE:
1279
  case XML_SCHEMA_TYPE_IDC_KEY:
1280
  case XML_SCHEMA_TYPE_IDC_KEYREF:
1281
      return ((xmlSchemaBasicItemPtr) ((xmlSchemaIDCPtr) item)->next);
1282
  default:
1283
      return (NULL);
1284
    }
1285
}
1286
#endif
1287
1288
1289
/**
1290
 * xmlSchemaFormatQName:
1291
 * @buf: the string buffer
1292
 * @namespaceName:  the namespace name
1293
 * @localName: the local name
1294
 *
1295
 * Returns the given QName in the format "{namespaceName}localName" or
1296
 * just "localName" if @namespaceName is NULL.
1297
 *
1298
 * Returns the localName if @namespaceName is NULL, a formatted
1299
 * string otherwise.
1300
 */
1301
static const xmlChar*
1302
xmlSchemaFormatQName(xmlChar **buf,
1303
         const xmlChar *namespaceName,
1304
         const xmlChar *localName)
1305
0
{
1306
0
    FREE_AND_NULL(*buf)
1307
0
    if (namespaceName != NULL) {
1308
0
  *buf = xmlStrdup(BAD_CAST "{");
1309
0
  *buf = xmlStrcat(*buf, namespaceName);
1310
0
  *buf = xmlStrcat(*buf, BAD_CAST "}");
1311
0
    }
1312
0
    if (localName != NULL) {
1313
0
  if (namespaceName == NULL)
1314
0
      return(localName);
1315
0
  *buf = xmlStrcat(*buf, localName);
1316
0
    } else {
1317
0
  *buf = xmlStrcat(*buf, BAD_CAST "(NULL)");
1318
0
    }
1319
0
    return ((const xmlChar *) *buf);
1320
0
}
1321
1322
static const xmlChar*
1323
xmlSchemaFormatQNameNs(xmlChar **buf, xmlNsPtr ns, const xmlChar *localName)
1324
0
{
1325
0
    if (ns != NULL)
1326
0
  return (xmlSchemaFormatQName(buf, ns->href, localName));
1327
0
    else
1328
0
  return (xmlSchemaFormatQName(buf, NULL, localName));
1329
0
}
1330
1331
static const xmlChar *
1332
xmlSchemaGetComponentName(xmlSchemaBasicItemPtr item)
1333
0
{
1334
0
    if (item == NULL) {
1335
0
        return (NULL);
1336
0
    }
1337
0
    switch (item->type) {
1338
0
  case XML_SCHEMA_TYPE_ELEMENT:
1339
0
      return (((xmlSchemaElementPtr) item)->name);
1340
0
  case XML_SCHEMA_TYPE_ATTRIBUTE:
1341
0
      return (((xmlSchemaAttributePtr) item)->name);
1342
0
  case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1343
0
      return (((xmlSchemaAttributeGroupPtr) item)->name);
1344
0
  case XML_SCHEMA_TYPE_BASIC:
1345
0
  case XML_SCHEMA_TYPE_SIMPLE:
1346
0
  case XML_SCHEMA_TYPE_COMPLEX:
1347
0
      return (((xmlSchemaTypePtr) item)->name);
1348
0
  case XML_SCHEMA_TYPE_GROUP:
1349
0
      return (((xmlSchemaModelGroupDefPtr) item)->name);
1350
0
  case XML_SCHEMA_TYPE_IDC_KEY:
1351
0
  case XML_SCHEMA_TYPE_IDC_UNIQUE:
1352
0
  case XML_SCHEMA_TYPE_IDC_KEYREF:
1353
0
      return (((xmlSchemaIDCPtr) item)->name);
1354
0
  case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
1355
0
      if (WXS_ATTRUSE_DECL(item) != NULL) {
1356
0
    return(xmlSchemaGetComponentName(
1357
0
        WXS_BASIC_CAST WXS_ATTRUSE_DECL(item)));
1358
0
      } else
1359
0
    return(NULL);
1360
0
  case XML_SCHEMA_EXTRA_QNAMEREF:
1361
0
      return (((xmlSchemaQNameRefPtr) item)->name);
1362
0
  case XML_SCHEMA_TYPE_NOTATION:
1363
0
      return (((xmlSchemaNotationPtr) item)->name);
1364
0
  default:
1365
      /*
1366
      * Other components cannot have names.
1367
      */
1368
0
      break;
1369
0
    }
1370
0
    return (NULL);
1371
0
}
1372
1373
0
#define xmlSchemaGetQNameRefName(r) (WXS_QNAME_CAST (r))->name
1374
0
#define xmlSchemaGetQNameRefTargetNs(r) (WXS_QNAME_CAST (r))->targetNamespace
1375
/*
1376
static const xmlChar *
1377
xmlSchemaGetQNameRefName(void *ref)
1378
{
1379
    return(((xmlSchemaQNameRefPtr) ref)->name);
1380
}
1381
1382
static const xmlChar *
1383
xmlSchemaGetQNameRefTargetNs(void *ref)
1384
{
1385
    return(((xmlSchemaQNameRefPtr) ref)->targetNamespace);
1386
}
1387
*/
1388
1389
static const xmlChar *
1390
xmlSchemaGetComponentTargetNs(xmlSchemaBasicItemPtr item)
1391
0
{
1392
0
    if (item == NULL) {
1393
0
        return (NULL);
1394
0
    }
1395
0
    switch (item->type) {
1396
0
  case XML_SCHEMA_TYPE_ELEMENT:
1397
0
      return (((xmlSchemaElementPtr) item)->targetNamespace);
1398
0
  case XML_SCHEMA_TYPE_ATTRIBUTE:
1399
0
      return (((xmlSchemaAttributePtr) item)->targetNamespace);
1400
0
  case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1401
0
      return (((xmlSchemaAttributeGroupPtr) item)->targetNamespace);
1402
0
  case XML_SCHEMA_TYPE_BASIC:
1403
0
      return (BAD_CAST "http://www.w3.org/2001/XMLSchema");
1404
0
  case XML_SCHEMA_TYPE_SIMPLE:
1405
0
  case XML_SCHEMA_TYPE_COMPLEX:
1406
0
      return (((xmlSchemaTypePtr) item)->targetNamespace);
1407
0
  case XML_SCHEMA_TYPE_GROUP:
1408
0
      return (((xmlSchemaModelGroupDefPtr) item)->targetNamespace);
1409
0
  case XML_SCHEMA_TYPE_IDC_KEY:
1410
0
  case XML_SCHEMA_TYPE_IDC_UNIQUE:
1411
0
  case XML_SCHEMA_TYPE_IDC_KEYREF:
1412
0
      return (((xmlSchemaIDCPtr) item)->targetNamespace);
1413
0
  case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
1414
0
      if (WXS_ATTRUSE_DECL(item) != NULL) {
1415
0
    return(xmlSchemaGetComponentTargetNs(
1416
0
        WXS_BASIC_CAST WXS_ATTRUSE_DECL(item)));
1417
0
      }
1418
      /* TODO: Will returning NULL break something? */
1419
0
      break;
1420
0
  case XML_SCHEMA_EXTRA_QNAMEREF:
1421
0
      return (((xmlSchemaQNameRefPtr) item)->targetNamespace);
1422
0
  case XML_SCHEMA_TYPE_NOTATION:
1423
0
      return (((xmlSchemaNotationPtr) item)->targetNamespace);
1424
0
  default:
1425
      /*
1426
      * Other components cannot have names.
1427
      */
1428
0
      break;
1429
0
    }
1430
0
    return (NULL);
1431
0
}
1432
1433
static const xmlChar*
1434
xmlSchemaGetComponentQName(xmlChar **buf,
1435
         void *item)
1436
0
{
1437
0
    return (xmlSchemaFormatQName(buf,
1438
0
  xmlSchemaGetComponentTargetNs((xmlSchemaBasicItemPtr) item),
1439
0
  xmlSchemaGetComponentName((xmlSchemaBasicItemPtr) item)));
1440
0
}
1441
1442
static const xmlChar*
1443
xmlSchemaGetComponentDesignation(xmlChar **buf, void *item)
1444
0
{
1445
0
    xmlChar *str = NULL;
1446
1447
0
    *buf = xmlStrcat(*buf, WXS_ITEM_TYPE_NAME(item));
1448
0
    *buf = xmlStrcat(*buf, BAD_CAST " '");
1449
0
    *buf = xmlStrcat(*buf, xmlSchemaGetComponentQName(&str,
1450
0
  (xmlSchemaBasicItemPtr) item));
1451
0
    *buf = xmlStrcat(*buf, BAD_CAST "'");
1452
0
    FREE_AND_NULL(str);
1453
0
    return(*buf);
1454
0
}
1455
1456
static const xmlChar*
1457
xmlSchemaGetIDCDesignation(xmlChar **buf, xmlSchemaIDCPtr idc)
1458
0
{
1459
0
    return(xmlSchemaGetComponentDesignation(buf, idc));
1460
0
}
1461
1462
/**
1463
 * xmlSchemaWildcardPCToString:
1464
 * @pc: the type of processContents
1465
 *
1466
 * Returns a string representation of the type of
1467
 * processContents.
1468
 */
1469
static const xmlChar *
1470
xmlSchemaWildcardPCToString(int pc)
1471
0
{
1472
0
    switch (pc) {
1473
0
  case XML_SCHEMAS_ANY_SKIP:
1474
0
      return (BAD_CAST "skip");
1475
0
  case XML_SCHEMAS_ANY_LAX:
1476
0
      return (BAD_CAST "lax");
1477
0
  case XML_SCHEMAS_ANY_STRICT:
1478
0
      return (BAD_CAST "strict");
1479
0
  default:
1480
0
      return (BAD_CAST "invalid process contents");
1481
0
    }
1482
0
}
1483
1484
/**
1485
 * xmlSchemaGetCanonValueWhtspExt:
1486
 * @val: the precomputed value
1487
 * @retValue: the returned value
1488
 * @ws: the whitespace type of the value
1489
 * @for_hash: non-zero if this is supposed to generate a string for hashing
1490
 *
1491
 * Get a the canonical representation of the value.
1492
 * The caller has to free the returned retValue.
1493
 *
1494
 * Returns 0 if the value could be built and -1 in case of
1495
 *         API errors or if the value type is not supported yet.
1496
 */
1497
static int
1498
xmlSchemaGetCanonValueWhtspExt_1(xmlSchemaValPtr val,
1499
               xmlSchemaWhitespaceValueType ws,
1500
               xmlChar **retValue,
1501
         int for_hash)
1502
0
{
1503
0
    int list;
1504
0
    xmlSchemaValType valType;
1505
0
    const xmlChar *value, *value2 = NULL;
1506
1507
1508
0
    if ((retValue == NULL) || (val == NULL))
1509
0
  return (-1);
1510
0
    list = xmlSchemaValueGetNext(val) ? 1 : 0;
1511
0
    *retValue = NULL;
1512
0
    do {
1513
0
  value = NULL;
1514
0
  valType = xmlSchemaGetValType(val);
1515
0
  switch (valType) {
1516
0
      case XML_SCHEMAS_STRING:
1517
0
      case XML_SCHEMAS_NORMSTRING:
1518
0
      case XML_SCHEMAS_ANYSIMPLETYPE:
1519
0
    value = xmlSchemaValueGetAsString(val);
1520
0
    if (value != NULL) {
1521
0
        if (ws == XML_SCHEMA_WHITESPACE_COLLAPSE)
1522
0
      value2 = xmlSchemaCollapseString(value);
1523
0
        else if (ws == XML_SCHEMA_WHITESPACE_REPLACE)
1524
0
      value2 = xmlSchemaWhiteSpaceReplace(value);
1525
0
        if (value2 != NULL)
1526
0
      value = value2;
1527
0
    }
1528
0
    break;
1529
0
      default:
1530
0
    if (xmlSchemaGetCanonValue(val, &value2) == -1) {
1531
0
        if (value2 != NULL)
1532
0
      xmlFree((xmlChar *) value2);
1533
0
        goto internal_error;
1534
0
    }
1535
0
    if (for_hash && valType == XML_SCHEMAS_DECIMAL) {
1536
        /* We can mostly use the canonical value for hashing,
1537
           except in the case of decimal.  There the canonical
1538
           representation requires a trailing '.0' even for
1539
           non-fractional numbers, but for the derived integer
1540
           types it forbids any decimal point.  Nevertheless they
1541
           compare equal if the value is equal.  We need to generate
1542
           the same hash value for this to work, and it's easiest
1543
           to just cut off the useless '.0' suffix for the
1544
           decimal type.  */
1545
0
        int len = xmlStrlen(value2);
1546
0
        if (len > 2 && value2[len-1] == '0' && value2[len-2] == '.')
1547
0
          ((xmlChar*)value2)[len-2] = 0;
1548
0
    }
1549
0
    value = value2;
1550
0
  }
1551
0
  if (*retValue == NULL)
1552
0
      if (value == NULL) {
1553
0
    if (! list)
1554
0
        *retValue = xmlStrdup(BAD_CAST "");
1555
0
      } else
1556
0
    *retValue = xmlStrdup(value);
1557
0
  else if (value != NULL) {
1558
      /* List. */
1559
0
      *retValue = xmlStrcat((xmlChar *) *retValue, BAD_CAST " ");
1560
0
      *retValue = xmlStrcat((xmlChar *) *retValue, value);
1561
0
  }
1562
0
  FREE_AND_NULL(value2)
1563
0
  val = xmlSchemaValueGetNext(val);
1564
0
    } while (val != NULL);
1565
1566
0
    return (0);
1567
0
internal_error:
1568
0
    if (*retValue != NULL)
1569
0
  xmlFree((xmlChar *) (*retValue));
1570
0
    if (value2 != NULL)
1571
0
  xmlFree((xmlChar *) value2);
1572
0
    return (-1);
1573
0
}
1574
1575
static int
1576
xmlSchemaGetCanonValueWhtspExt(xmlSchemaValPtr val,
1577
             xmlSchemaWhitespaceValueType ws,
1578
             xmlChar **retValue)
1579
0
{
1580
0
    return xmlSchemaGetCanonValueWhtspExt_1(val, ws, retValue, 0);
1581
0
}
1582
1583
static int
1584
xmlSchemaGetCanonValueHash(xmlSchemaValPtr val,
1585
         xmlChar **retValue)
1586
0
{
1587
0
    return xmlSchemaGetCanonValueWhtspExt_1(val, XML_SCHEMA_WHITESPACE_COLLAPSE,
1588
0
              retValue, 1);
1589
0
}
1590
1591
/**
1592
 * xmlSchemaFormatItemForReport:
1593
 * @buf: the string buffer
1594
 * @itemDes: the designation of the item
1595
 * @itemName: the name of the item
1596
 * @item: the item as an object
1597
 * @itemNode: the node of the item
1598
 * @local: the local name
1599
 * @parsing: if the function is used during the parse
1600
 *
1601
 * Returns a representation of the given item used
1602
 * for error reports.
1603
 *
1604
 * The following order is used to build the resulting
1605
 * designation if the arguments are not NULL:
1606
 * 1a. If itemDes not NULL -> itemDes
1607
 * 1b. If (itemDes not NULL) and (itemName not NULL)
1608
 *     -> itemDes + itemName
1609
 * 2. If the preceding was NULL and (item not NULL) -> item
1610
 * 3. If the preceding was NULL and (itemNode not NULL) -> itemNode
1611
 *
1612
 * If the itemNode is an attribute node, the name of the attribute
1613
 * will be appended to the result.
1614
 *
1615
 * Returns the formatted string and sets @buf to the resulting value.
1616
 */
1617
static xmlChar*
1618
xmlSchemaFormatItemForReport(xmlChar **buf,
1619
         const xmlChar *itemDes,
1620
         xmlSchemaBasicItemPtr item,
1621
         xmlNodePtr itemNode)
1622
0
{
1623
0
    xmlChar *str = NULL;
1624
0
    int named = 1;
1625
1626
0
    if (*buf != NULL) {
1627
0
  xmlFree(*buf);
1628
0
  *buf = NULL;
1629
0
    }
1630
1631
0
    if (itemDes != NULL) {
1632
0
  *buf = xmlStrdup(itemDes);
1633
0
    } else if (item != NULL) {
1634
0
  switch (item->type) {
1635
0
  case XML_SCHEMA_TYPE_BASIC: {
1636
0
      xmlSchemaTypePtr type = WXS_TYPE_CAST item;
1637
1638
0
      if (WXS_IS_ATOMIC(type))
1639
0
    *buf = xmlStrdup(BAD_CAST "atomic type 'xs:");
1640
0
      else if (WXS_IS_LIST(type))
1641
0
    *buf = xmlStrdup(BAD_CAST "list type 'xs:");
1642
0
      else if (WXS_IS_UNION(type))
1643
0
    *buf = xmlStrdup(BAD_CAST "union type 'xs:");
1644
0
      else
1645
0
    *buf = xmlStrdup(BAD_CAST "simple type 'xs:");
1646
0
      *buf = xmlStrcat(*buf, type->name);
1647
0
      *buf = xmlStrcat(*buf, BAD_CAST "'");
1648
0
      }
1649
0
      break;
1650
0
  case XML_SCHEMA_TYPE_SIMPLE: {
1651
0
      xmlSchemaTypePtr type = WXS_TYPE_CAST item;
1652
1653
0
      if (type->flags & XML_SCHEMAS_TYPE_GLOBAL) {
1654
0
    *buf = xmlStrdup(BAD_CAST"");
1655
0
      } else {
1656
0
    *buf = xmlStrdup(BAD_CAST "local ");
1657
0
      }
1658
0
      if (WXS_IS_ATOMIC(type))
1659
0
    *buf = xmlStrcat(*buf, BAD_CAST "atomic type");
1660
0
      else if (WXS_IS_LIST(type))
1661
0
    *buf = xmlStrcat(*buf, BAD_CAST "list type");
1662
0
      else if (WXS_IS_UNION(type))
1663
0
    *buf = xmlStrcat(*buf, BAD_CAST "union type");
1664
0
      else
1665
0
    *buf = xmlStrcat(*buf, BAD_CAST "simple type");
1666
0
      if (type->flags & XML_SCHEMAS_TYPE_GLOBAL) {
1667
0
    *buf = xmlStrcat(*buf, BAD_CAST " '");
1668
0
    *buf = xmlStrcat(*buf, type->name);
1669
0
    *buf = xmlStrcat(*buf, BAD_CAST "'");
1670
0
      }
1671
0
      }
1672
0
      break;
1673
0
  case XML_SCHEMA_TYPE_COMPLEX: {
1674
0
      xmlSchemaTypePtr type = WXS_TYPE_CAST item;
1675
1676
0
      if (type->flags & XML_SCHEMAS_TYPE_GLOBAL)
1677
0
    *buf = xmlStrdup(BAD_CAST "");
1678
0
      else
1679
0
    *buf = xmlStrdup(BAD_CAST "local ");
1680
0
      *buf = xmlStrcat(*buf, BAD_CAST "complex type");
1681
0
      if (type->flags & XML_SCHEMAS_TYPE_GLOBAL) {
1682
0
    *buf = xmlStrcat(*buf, BAD_CAST " '");
1683
0
    *buf = xmlStrcat(*buf, type->name);
1684
0
    *buf = xmlStrcat(*buf, BAD_CAST "'");
1685
0
      }
1686
0
      }
1687
0
      break;
1688
0
  case XML_SCHEMA_TYPE_ATTRIBUTE_USE: {
1689
0
    xmlSchemaAttributeUsePtr ause;
1690
1691
0
    ause = WXS_ATTR_USE_CAST item;
1692
0
    *buf = xmlStrdup(BAD_CAST "attribute use ");
1693
0
    if (WXS_ATTRUSE_DECL(ause) != NULL) {
1694
0
        *buf = xmlStrcat(*buf, BAD_CAST "'");
1695
0
        *buf = xmlStrcat(*buf,
1696
0
      xmlSchemaGetComponentQName(&str, WXS_ATTRUSE_DECL(ause)));
1697
0
        FREE_AND_NULL(str)
1698
0
      *buf = xmlStrcat(*buf, BAD_CAST "'");
1699
0
    } else {
1700
0
        *buf = xmlStrcat(*buf, BAD_CAST "(unknown)");
1701
0
    }
1702
0
      }
1703
0
      break;
1704
0
  case XML_SCHEMA_TYPE_ATTRIBUTE: {
1705
0
    xmlSchemaAttributePtr attr;
1706
1707
0
    attr = (xmlSchemaAttributePtr) item;
1708
0
    *buf = xmlStrdup(BAD_CAST "attribute decl.");
1709
0
    *buf = xmlStrcat(*buf, BAD_CAST " '");
1710
0
    *buf = xmlStrcat(*buf, xmlSchemaFormatQName(&str,
1711
0
        attr->targetNamespace, attr->name));
1712
0
    FREE_AND_NULL(str)
1713
0
        *buf = xmlStrcat(*buf, BAD_CAST "'");
1714
0
      }
1715
0
      break;
1716
0
  case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1717
0
      xmlSchemaGetComponentDesignation(buf, item);
1718
0
      break;
1719
0
  case XML_SCHEMA_TYPE_ELEMENT: {
1720
0
    xmlSchemaElementPtr elem;
1721
1722
0
    elem = (xmlSchemaElementPtr) item;
1723
0
    *buf = xmlStrdup(BAD_CAST "element decl.");
1724
0
    *buf = xmlStrcat(*buf, BAD_CAST " '");
1725
0
    *buf = xmlStrcat(*buf, xmlSchemaFormatQName(&str,
1726
0
        elem->targetNamespace, elem->name));
1727
0
    *buf = xmlStrcat(*buf, BAD_CAST "'");
1728
0
      }
1729
0
      break;
1730
0
  case XML_SCHEMA_TYPE_IDC_UNIQUE:
1731
0
  case XML_SCHEMA_TYPE_IDC_KEY:
1732
0
  case XML_SCHEMA_TYPE_IDC_KEYREF:
1733
0
      if (item->type == XML_SCHEMA_TYPE_IDC_UNIQUE)
1734
0
    *buf = xmlStrdup(BAD_CAST "unique '");
1735
0
      else if (item->type == XML_SCHEMA_TYPE_IDC_KEY)
1736
0
    *buf = xmlStrdup(BAD_CAST "key '");
1737
0
      else
1738
0
    *buf = xmlStrdup(BAD_CAST "keyRef '");
1739
0
      *buf = xmlStrcat(*buf, ((xmlSchemaIDCPtr) item)->name);
1740
0
      *buf = xmlStrcat(*buf, BAD_CAST "'");
1741
0
      break;
1742
0
  case XML_SCHEMA_TYPE_ANY:
1743
0
  case XML_SCHEMA_TYPE_ANY_ATTRIBUTE:
1744
0
      *buf = xmlStrdup(xmlSchemaWildcardPCToString(
1745
0
        ((xmlSchemaWildcardPtr) item)->processContents));
1746
0
      *buf = xmlStrcat(*buf, BAD_CAST " wildcard");
1747
0
      break;
1748
0
  case XML_SCHEMA_FACET_MININCLUSIVE:
1749
0
  case XML_SCHEMA_FACET_MINEXCLUSIVE:
1750
0
  case XML_SCHEMA_FACET_MAXINCLUSIVE:
1751
0
  case XML_SCHEMA_FACET_MAXEXCLUSIVE:
1752
0
  case XML_SCHEMA_FACET_TOTALDIGITS:
1753
0
  case XML_SCHEMA_FACET_FRACTIONDIGITS:
1754
0
  case XML_SCHEMA_FACET_PATTERN:
1755
0
  case XML_SCHEMA_FACET_ENUMERATION:
1756
0
  case XML_SCHEMA_FACET_WHITESPACE:
1757
0
  case XML_SCHEMA_FACET_LENGTH:
1758
0
  case XML_SCHEMA_FACET_MAXLENGTH:
1759
0
  case XML_SCHEMA_FACET_MINLENGTH:
1760
0
      *buf = xmlStrdup(BAD_CAST "facet '");
1761
0
      *buf = xmlStrcat(*buf, xmlSchemaFacetTypeToString(item->type));
1762
0
      *buf = xmlStrcat(*buf, BAD_CAST "'");
1763
0
      break;
1764
0
  case XML_SCHEMA_TYPE_GROUP: {
1765
0
    *buf = xmlStrdup(BAD_CAST "model group def.");
1766
0
    *buf = xmlStrcat(*buf, BAD_CAST " '");
1767
0
    *buf = xmlStrcat(*buf, xmlSchemaGetComponentQName(&str, item));
1768
0
    *buf = xmlStrcat(*buf, BAD_CAST "'");
1769
0
    FREE_AND_NULL(str)
1770
0
      }
1771
0
      break;
1772
0
  case XML_SCHEMA_TYPE_SEQUENCE:
1773
0
  case XML_SCHEMA_TYPE_CHOICE:
1774
0
  case XML_SCHEMA_TYPE_ALL:
1775
0
  case XML_SCHEMA_TYPE_PARTICLE:
1776
0
      *buf = xmlStrdup(WXS_ITEM_TYPE_NAME(item));
1777
0
      break;
1778
0
  case XML_SCHEMA_TYPE_NOTATION: {
1779
0
    *buf = xmlStrdup(WXS_ITEM_TYPE_NAME(item));
1780
0
    *buf = xmlStrcat(*buf, BAD_CAST " '");
1781
0
    *buf = xmlStrcat(*buf, xmlSchemaGetComponentQName(&str, item));
1782
0
    *buf = xmlStrcat(*buf, BAD_CAST "'");
1783
0
    FREE_AND_NULL(str);
1784
0
      }
1785
            /* Falls through. */
1786
0
  default:
1787
0
      named = 0;
1788
0
  }
1789
0
    } else
1790
0
  named = 0;
1791
1792
0
    if ((named == 0) && (itemNode != NULL)) {
1793
0
  xmlNodePtr elem;
1794
1795
0
  if (itemNode->type == XML_ATTRIBUTE_NODE)
1796
0
      elem = itemNode->parent;
1797
0
  else
1798
0
      elem = itemNode;
1799
0
  *buf = xmlStrdup(BAD_CAST "Element '");
1800
0
  if (elem->ns != NULL) {
1801
0
      *buf = xmlStrcat(*buf,
1802
0
    xmlSchemaFormatQName(&str, elem->ns->href, elem->name));
1803
0
      FREE_AND_NULL(str)
1804
0
  } else
1805
0
      *buf = xmlStrcat(*buf, elem->name);
1806
0
  *buf = xmlStrcat(*buf, BAD_CAST "'");
1807
1808
0
    }
1809
0
    if ((itemNode != NULL) && (itemNode->type == XML_ATTRIBUTE_NODE)) {
1810
0
  *buf = xmlStrcat(*buf, BAD_CAST ", attribute '");
1811
0
  if (itemNode->ns != NULL) {
1812
0
      *buf = xmlStrcat(*buf, xmlSchemaFormatQName(&str,
1813
0
    itemNode->ns->href, itemNode->name));
1814
0
      FREE_AND_NULL(str)
1815
0
  } else
1816
0
      *buf = xmlStrcat(*buf, itemNode->name);
1817
0
  *buf = xmlStrcat(*buf, BAD_CAST "'");
1818
0
    }
1819
0
    FREE_AND_NULL(str)
1820
1821
0
    return (xmlEscapeFormatString(buf));
1822
0
}
1823
1824
/**
1825
 * xmlSchemaFormatFacetEnumSet:
1826
 * @buf: the string buffer
1827
 * @type: the type holding the enumeration facets
1828
 *
1829
 * Builds a string consisting of all enumeration elements.
1830
 *
1831
 * Returns a string of all enumeration elements.
1832
 */
1833
static const xmlChar *
1834
xmlSchemaFormatFacetEnumSet(xmlSchemaAbstractCtxtPtr actxt,
1835
          xmlChar **buf, xmlSchemaTypePtr type)
1836
0
{
1837
0
    xmlSchemaFacetPtr facet;
1838
0
    xmlSchemaWhitespaceValueType ws;
1839
0
    xmlChar *value = NULL;
1840
0
    int res, found = 0;
1841
1842
0
    if (*buf != NULL)
1843
0
  xmlFree(*buf);
1844
0
    *buf = NULL;
1845
1846
0
    do {
1847
  /*
1848
  * Use the whitespace type of the base type.
1849
  */
1850
0
  ws = xmlSchemaGetWhiteSpaceFacetValue(type->baseType);
1851
0
  for (facet = type->facets; facet != NULL; facet = facet->next) {
1852
0
      if (facet->type != XML_SCHEMA_FACET_ENUMERATION)
1853
0
    continue;
1854
0
      found = 1;
1855
0
      res = xmlSchemaGetCanonValueWhtspExt(facet->val,
1856
0
    ws, &value);
1857
0
      if (res == -1) {
1858
0
    xmlSchemaInternalErr(actxt,
1859
0
        "xmlSchemaFormatFacetEnumSet",
1860
0
        "compute the canonical lexical representation");
1861
0
    if (*buf != NULL)
1862
0
        xmlFree(*buf);
1863
0
    *buf = NULL;
1864
0
    return (NULL);
1865
0
      }
1866
0
      if (*buf == NULL)
1867
0
    *buf = xmlStrdup(BAD_CAST "'");
1868
0
      else
1869
0
    *buf = xmlStrcat(*buf, BAD_CAST ", '");
1870
0
      *buf = xmlStrcat(*buf, BAD_CAST value);
1871
0
      *buf = xmlStrcat(*buf, BAD_CAST "'");
1872
0
      if (value != NULL) {
1873
0
    xmlFree((xmlChar *)value);
1874
0
    value = NULL;
1875
0
      }
1876
0
  }
1877
  /*
1878
  * The enumeration facet of a type restricts the enumeration
1879
  * facet of the ancestor type; i.e., such restricted enumerations
1880
  * do not belong to the set of the given type. Thus we break
1881
  * on the first found enumeration.
1882
  */
1883
0
  if (found)
1884
0
      break;
1885
0
  type = type->baseType;
1886
0
    } while ((type != NULL) && (type->type != XML_SCHEMA_TYPE_BASIC));
1887
1888
0
    return ((const xmlChar *) *buf);
1889
0
}
1890
1891
/************************************************************************
1892
 *                  *
1893
 *      Error functions               *
1894
 *                  *
1895
 ************************************************************************/
1896
1897
/**
1898
 * xmlSchemaPErrMemory:
1899
 * @node: a context node
1900
 * @extra:  extra information
1901
 *
1902
 * Handle an out of memory condition
1903
 */
1904
static void
1905
xmlSchemaPErrMemory(xmlSchemaParserCtxtPtr ctxt)
1906
0
{
1907
0
    xmlGenericErrorFunc channel = NULL;
1908
0
    xmlStructuredErrorFunc schannel = NULL;
1909
0
    void *data = NULL;
1910
1911
0
    if (ctxt != NULL) {
1912
0
        ctxt->nberrors++;
1913
0
        ctxt->err = XML_ERR_NO_MEMORY;
1914
0
        channel = ctxt->error;
1915
0
        schannel = ctxt->serror;
1916
0
        data = ctxt->errCtxt;
1917
0
    }
1918
1919
0
    xmlRaiseMemoryError(schannel, channel, data, XML_FROM_SCHEMASP, NULL);
1920
0
}
1921
1922
static void LIBXML_ATTR_FORMAT(11,12)
1923
xmlSchemaPErrFull(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int code,
1924
                  xmlErrorLevel level, const char *file, int line,
1925
                  const xmlChar *str1, const xmlChar *str2, const xmlChar *str3,
1926
0
                  int col, const char *msg, ...) {
1927
0
    xmlGenericErrorFunc channel = NULL;
1928
0
    xmlStructuredErrorFunc schannel = NULL;
1929
0
    void *data = NULL;
1930
0
    int res;
1931
0
    va_list ap;
1932
1933
0
    if (ctxt != NULL) {
1934
        /* Don't overwrite memory errors */
1935
0
        if (ctxt->err == XML_ERR_NO_MEMORY)
1936
0
            return;
1937
1938
0
        if (level == XML_ERR_WARNING) {
1939
0
            channel = ctxt->warning;
1940
0
        } else {
1941
0
            ctxt->nberrors++;
1942
0
            ctxt->err = code;
1943
0
            channel = ctxt->error;
1944
0
        }
1945
0
        data = ctxt->errCtxt;
1946
0
        schannel = ctxt->serror;
1947
0
    }
1948
1949
0
    if ((channel == NULL) && (schannel == NULL)) {
1950
0
        channel = xmlGenericError;
1951
0
        data = xmlGenericErrorContext;
1952
0
    }
1953
1954
0
    va_start(ap, msg);
1955
0
    res = xmlVRaiseError(schannel, channel, data, ctxt, node,
1956
0
                         XML_FROM_SCHEMASP, code, level, file, line,
1957
0
                         (const char *) str1,
1958
0
                         (const char *) str2,
1959
0
                         (const char *) str3,
1960
0
                         0, col, msg, ap);
1961
0
    va_end(ap);
1962
1963
0
    if (res < 0)
1964
0
        xmlSchemaPErrMemory(ctxt);
1965
0
}
1966
1967
/**
1968
 * xmlSchemaPErr:
1969
 * @ctxt: the parsing context
1970
 * @node: the context node
1971
 * @error: the error code
1972
 * @msg: the error message
1973
 * @str1: extra data
1974
 * @str2: extra data
1975
 *
1976
 * Handle a parser error
1977
 */
1978
static void LIBXML_ATTR_FORMAT(4,0)
1979
xmlSchemaPErr(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int code,
1980
              const char *msg, const xmlChar * str1, const xmlChar * str2)
1981
0
{
1982
0
    xmlSchemaPErrFull(ctxt, node, code, XML_ERR_ERROR, NULL, 0,
1983
0
                      str1, str2, NULL, 0, msg, str1, str2);
1984
0
}
1985
1986
/**
1987
 * xmlSchemaPErr2:
1988
 * @ctxt: the parsing context
1989
 * @node: the context node
1990
 * @node: the current child
1991
 * @error: the error code
1992
 * @msg: the error message
1993
 * @str1: extra data
1994
 * @str2: extra data
1995
 *
1996
 * Handle a parser error
1997
 */
1998
static void LIBXML_ATTR_FORMAT(5,0)
1999
xmlSchemaPErr2(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node,
2000
               xmlNodePtr child, int error,
2001
               const char *msg, const xmlChar * str1, const xmlChar * str2)
2002
0
{
2003
0
    if (child != NULL)
2004
0
        xmlSchemaPErr(ctxt, child, error, msg, str1, str2);
2005
0
    else
2006
0
        xmlSchemaPErr(ctxt, node, error, msg, str1, str2);
2007
0
}
2008
2009
2010
/**
2011
 * xmlSchemaPErrExt:
2012
 * @ctxt: the parsing context
2013
 * @node: the context node
2014
 * @error: the error code
2015
 * @strData1: extra data
2016
 * @strData2: extra data
2017
 * @strData3: extra data
2018
 * @msg: the message
2019
 * @str1:  extra parameter for the message display
2020
 * @str2:  extra parameter for the message display
2021
 * @str3:  extra parameter for the message display
2022
 * @str4:  extra parameter for the message display
2023
 * @str5:  extra parameter for the message display
2024
 *
2025
 * Handle a parser error
2026
 */
2027
static void LIBXML_ATTR_FORMAT(7,0)
2028
xmlSchemaPErrExt(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int code,
2029
    const xmlChar * strData1, const xmlChar * strData2,
2030
    const xmlChar * strData3, const char *msg, const xmlChar * str1,
2031
    const xmlChar * str2, const xmlChar * str3, const xmlChar * str4,
2032
    const xmlChar * str5)
2033
0
{
2034
0
    xmlSchemaPErrFull(ctxt, node, code, XML_ERR_ERROR, NULL, 0,
2035
0
                      strData1, strData2, strData3, 0,
2036
0
                      msg, str1, str2, str3, str4, str5);
2037
0
}
2038
2039
/************************************************************************
2040
 *                  *
2041
 *      Allround error functions      *
2042
 *                  *
2043
 ************************************************************************/
2044
2045
/**
2046
 * xmlSchemaVTypeErrMemory:
2047
 * @node: a context node
2048
 * @extra:  extra information
2049
 *
2050
 * Handle an out of memory condition
2051
 */
2052
static void
2053
xmlSchemaVErrMemory(xmlSchemaValidCtxtPtr ctxt)
2054
0
{
2055
0
    xmlGenericErrorFunc channel = NULL;
2056
0
    xmlStructuredErrorFunc schannel = NULL;
2057
0
    void *data = NULL;
2058
2059
0
    if (ctxt != NULL) {
2060
0
        ctxt->nberrors++;
2061
0
        ctxt->err = XML_ERR_NO_MEMORY;
2062
0
        channel = ctxt->error;
2063
0
        schannel = ctxt->serror;
2064
0
        data = ctxt->errCtxt;
2065
0
    }
2066
2067
0
    xmlRaiseMemoryError(schannel, channel, data, XML_FROM_SCHEMASV, NULL);
2068
0
}
2069
2070
static void LIBXML_ATTR_FORMAT(11,12)
2071
xmlSchemaVErrFull(xmlSchemaValidCtxtPtr ctxt, xmlNodePtr node, int code,
2072
                  xmlErrorLevel level, const char *file, int line,
2073
                  const xmlChar *str1, const xmlChar *str2, const xmlChar *str3,
2074
0
                  int col, const char *msg, ...) {
2075
0
    xmlGenericErrorFunc channel = NULL;
2076
0
    xmlStructuredErrorFunc schannel = NULL;
2077
0
    void *data = NULL;
2078
0
    int res;
2079
0
    va_list ap;
2080
2081
0
    if (ctxt != NULL) {
2082
        /* Don't overwrite memory errors */
2083
0
        if (ctxt->err == XML_ERR_NO_MEMORY)
2084
0
            return;
2085
2086
0
        if (level == XML_ERR_WARNING) {
2087
0
            channel = ctxt->warning;
2088
0
        } else {
2089
0
            ctxt->nberrors++;
2090
0
            ctxt->err = code;
2091
0
            channel = ctxt->error;
2092
0
        }
2093
0
        data = ctxt->errCtxt;
2094
0
        schannel = ctxt->serror;
2095
0
    }
2096
2097
0
    if ((channel == NULL) && (schannel == NULL)) {
2098
0
        channel = xmlGenericError;
2099
0
        data = xmlGenericErrorContext;
2100
0
    }
2101
2102
0
    va_start(ap, msg);
2103
0
    res = xmlVRaiseError(schannel, channel, data, ctxt, node,
2104
0
                         XML_FROM_SCHEMASV, code, level, file, line,
2105
0
                         (const char *) str1,
2106
0
                         (const char *) str2,
2107
0
                         (const char *) str3,
2108
0
                         0, col, msg, ap);
2109
0
    va_end(ap);
2110
2111
0
    if (res < 0)
2112
0
        xmlSchemaVErrMemory(ctxt);
2113
0
}
2114
2115
#define WXS_ERROR_TYPE_ERROR 1
2116
#define WXS_ERROR_TYPE_WARNING 2
2117
/**
2118
 * xmlSchemaErr4Line:
2119
 * @ctxt: the validation context
2120
 * @errorLevel: the error level
2121
 * @error: the error code
2122
 * @node: the context node
2123
 * @line: the line number
2124
 * @msg: the error message
2125
 * @str1: extra data
2126
 * @str2: extra data
2127
 * @str3: extra data
2128
 * @str4: extra data
2129
 *
2130
 * Handle a validation error
2131
 */
2132
static void LIBXML_ATTR_FORMAT(6,0)
2133
xmlSchemaErr4Line(xmlSchemaAbstractCtxtPtr ctxt,
2134
      xmlErrorLevel errorLevel,
2135
      int code, xmlNodePtr node, int line, const char *msg,
2136
      const xmlChar *str1, const xmlChar *str2,
2137
      const xmlChar *str3, const xmlChar *str4)
2138
0
{
2139
0
    if (ctxt != NULL) {
2140
0
  if (ctxt->type == XML_SCHEMA_CTXT_VALIDATOR) {
2141
0
      xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctxt;
2142
0
      const char *file = NULL;
2143
0
      int col = 0;
2144
2145
      /*
2146
      * Error node. If we specify a line number, then
2147
      * do not channel any node to the error function.
2148
      */
2149
0
      if (line == 0) {
2150
0
    if ((node == NULL) &&
2151
0
        (vctxt->depth >= 0) &&
2152
0
        (vctxt->inode != NULL)) {
2153
0
        node = vctxt->inode->node;
2154
0
    }
2155
    /*
2156
    * Get filename and line if no node-tree.
2157
    */
2158
0
    if ((node == NULL) &&
2159
0
        (vctxt->parserCtxt != NULL) &&
2160
0
        (vctxt->parserCtxt->input != NULL)) {
2161
0
        file = vctxt->parserCtxt->input->filename;
2162
0
                    if (vctxt->inode != NULL) {
2163
0
            line = vctxt->inode->nodeLine;
2164
0
                        col = 0;
2165
0
                    } else {
2166
                        /* This is inaccurate. */
2167
0
            line = vctxt->parserCtxt->input->line;
2168
0
            col = vctxt->parserCtxt->input->col;
2169
0
                    }
2170
0
    }
2171
0
      } else {
2172
    /*
2173
    * Override the given node's (if any) position
2174
    * and channel only the given line number.
2175
    */
2176
0
    node = NULL;
2177
    /*
2178
    * Get filename.
2179
    */
2180
0
    if (vctxt->doc != NULL)
2181
0
        file = (const char *) vctxt->doc->URL;
2182
0
    else if ((vctxt->parserCtxt != NULL) &&
2183
0
        (vctxt->parserCtxt->input != NULL))
2184
0
        file = vctxt->parserCtxt->input->filename;
2185
0
      }
2186
0
      if (vctxt->locFunc != NULL) {
2187
0
          if ((file == NULL) || (line == 0)) {
2188
0
        unsigned long l;
2189
0
        const char *f;
2190
0
        vctxt->locFunc(vctxt->locCtxt, &f, &l);
2191
0
        if (file == NULL)
2192
0
            file = f;
2193
0
        if (line == 0)
2194
0
            line = (int) l;
2195
0
    }
2196
0
      }
2197
0
      if ((file == NULL) && (vctxt->filename != NULL))
2198
0
          file = vctxt->filename;
2199
2200
0
            xmlSchemaVErrFull(vctxt, node, code, errorLevel,
2201
0
                              file, line, str1, str2, str3, col,
2202
0
                              msg, str1, str2, str3, str4);
2203
0
  } else if (ctxt->type == XML_SCHEMA_CTXT_PARSER) {
2204
0
      xmlSchemaParserCtxtPtr pctxt = (xmlSchemaParserCtxtPtr) ctxt;
2205
2206
0
            xmlSchemaPErrFull(pctxt, node, code, errorLevel,
2207
0
                              NULL, 0, str1, str2, str3, 0,
2208
0
                              msg, str1, str2, str3, str4);
2209
0
  }
2210
0
    }
2211
0
}
2212
2213
/**
2214
 * xmlSchemaErr3:
2215
 * @ctxt: the validation context
2216
 * @node: the context node
2217
 * @error: the error code
2218
 * @msg: the error message
2219
 * @str1: extra data
2220
 * @str2: extra data
2221
 * @str3: extra data
2222
 *
2223
 * Handle a validation error
2224
 */
2225
static void LIBXML_ATTR_FORMAT(4,0)
2226
xmlSchemaErr3(xmlSchemaAbstractCtxtPtr actxt,
2227
        int error, xmlNodePtr node, const char *msg,
2228
        const xmlChar *str1, const xmlChar *str2, const xmlChar *str3)
2229
0
{
2230
0
    xmlSchemaErr4Line(actxt, XML_ERR_ERROR, error, node, 0,
2231
0
  msg, str1, str2, str3, NULL);
2232
0
}
2233
2234
static void LIBXML_ATTR_FORMAT(4,0)
2235
xmlSchemaErr4(xmlSchemaAbstractCtxtPtr actxt,
2236
        int error, xmlNodePtr node, const char *msg,
2237
        const xmlChar *str1, const xmlChar *str2,
2238
        const xmlChar *str3, const xmlChar *str4)
2239
0
{
2240
0
    xmlSchemaErr4Line(actxt, XML_ERR_ERROR, error, node, 0,
2241
0
  msg, str1, str2, str3, str4);
2242
0
}
2243
2244
static void LIBXML_ATTR_FORMAT(4,0)
2245
xmlSchemaErr(xmlSchemaAbstractCtxtPtr actxt,
2246
       int error, xmlNodePtr node, const char *msg,
2247
       const xmlChar *str1, const xmlChar *str2)
2248
0
{
2249
0
    xmlSchemaErr4(actxt, error, node, msg, str1, str2, NULL, NULL);
2250
0
}
2251
2252
static xmlChar *
2253
xmlSchemaFormatNodeForError(xmlChar ** msg,
2254
          xmlSchemaAbstractCtxtPtr actxt,
2255
          xmlNodePtr node)
2256
0
{
2257
0
    xmlChar *str = NULL;
2258
2259
0
    *msg = NULL;
2260
0
    if ((node != NULL) &&
2261
0
  (node->type != XML_ELEMENT_NODE) &&
2262
0
  (node->type != XML_ATTRIBUTE_NODE))
2263
0
    {
2264
  /*
2265
  * Don't try to format other nodes than element and
2266
  * attribute nodes.
2267
  * Play safe and return an empty string.
2268
  */
2269
0
  *msg = xmlStrdup(BAD_CAST "");
2270
0
  return(*msg);
2271
0
    }
2272
0
    if (node != NULL) {
2273
  /*
2274
  * Work on tree nodes.
2275
  */
2276
0
  if (node->type == XML_ATTRIBUTE_NODE) {
2277
0
      xmlNodePtr elem = node->parent;
2278
2279
0
      *msg = xmlStrdup(BAD_CAST "Element '");
2280
0
      if (elem->ns != NULL)
2281
0
    *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2282
0
        elem->ns->href, elem->name));
2283
0
      else
2284
0
    *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2285
0
        NULL, elem->name));
2286
0
      FREE_AND_NULL(str);
2287
0
      *msg = xmlStrcat(*msg, BAD_CAST "', ");
2288
0
      *msg = xmlStrcat(*msg, BAD_CAST "attribute '");
2289
0
  } else {
2290
0
      *msg = xmlStrdup(BAD_CAST "Element '");
2291
0
  }
2292
0
  if (node->ns != NULL)
2293
0
      *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2294
0
      node->ns->href, node->name));
2295
0
  else
2296
0
      *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2297
0
      NULL, node->name));
2298
0
  FREE_AND_NULL(str);
2299
0
  *msg = xmlStrcat(*msg, BAD_CAST "': ");
2300
0
    } else if (actxt->type == XML_SCHEMA_CTXT_VALIDATOR) {
2301
0
  xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) actxt;
2302
  /*
2303
  * Work on node infos.
2304
  */
2305
0
  if (vctxt->inode->nodeType == XML_ATTRIBUTE_NODE) {
2306
0
      xmlSchemaNodeInfoPtr ielem =
2307
0
    vctxt->elemInfos[vctxt->depth];
2308
2309
0
      *msg = xmlStrdup(BAD_CAST "Element '");
2310
0
      *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2311
0
    ielem->nsName, ielem->localName));
2312
0
      FREE_AND_NULL(str);
2313
0
      *msg = xmlStrcat(*msg, BAD_CAST "', ");
2314
0
      *msg = xmlStrcat(*msg, BAD_CAST "attribute '");
2315
0
  } else {
2316
0
      *msg = xmlStrdup(BAD_CAST "Element '");
2317
0
  }
2318
0
  *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2319
0
      vctxt->inode->nsName, vctxt->inode->localName));
2320
0
  FREE_AND_NULL(str);
2321
0
  *msg = xmlStrcat(*msg, BAD_CAST "': ");
2322
0
    } else if (actxt->type == XML_SCHEMA_CTXT_PARSER) {
2323
  /*
2324
  * Hmm, no node while parsing?
2325
  * Return an empty string, in case NULL will break something.
2326
  */
2327
0
  *msg = xmlStrdup(BAD_CAST "");
2328
0
    } else {
2329
  /* TODO */
2330
0
  return (NULL);
2331
0
    }
2332
2333
    /*
2334
     * xmlSchemaFormatItemForReport() also returns an escaped format
2335
     * string, so do this before calling it below (in the future).
2336
     */
2337
0
    xmlEscapeFormatString(msg);
2338
2339
    /*
2340
    * VAL TODO: The output of the given schema component is currently
2341
    * disabled.
2342
    */
2343
#if 0
2344
    if ((type != NULL) && (xmlSchemaIsGlobalItem(type))) {
2345
  *msg = xmlStrcat(*msg, BAD_CAST " [");
2346
  *msg = xmlStrcat(*msg, xmlSchemaFormatItemForReport(&str,
2347
      NULL, type, NULL, 0));
2348
  FREE_AND_NULL(str)
2349
  *msg = xmlStrcat(*msg, BAD_CAST "]");
2350
    }
2351
#endif
2352
0
    return (*msg);
2353
0
}
2354
2355
static void LIBXML_ATTR_FORMAT(3,0)
2356
xmlSchemaInternalErr2(xmlSchemaAbstractCtxtPtr actxt,
2357
         const char *funcName,
2358
         const char *message,
2359
         const xmlChar *str1,
2360
         const xmlChar *str2)
2361
0
{
2362
0
    xmlChar *msg = NULL;
2363
2364
0
    if (actxt == NULL)
2365
0
        return;
2366
0
    msg = xmlStrdup(BAD_CAST "Internal error: %s, ");
2367
0
    msg = xmlStrcat(msg, BAD_CAST message);
2368
0
    msg = xmlStrcat(msg, BAD_CAST ".\n");
2369
2370
0
    if (actxt->type == XML_SCHEMA_CTXT_VALIDATOR)
2371
0
  xmlSchemaErr3(actxt, XML_SCHEMAV_INTERNAL, NULL,
2372
0
      (const char *) msg, (const xmlChar *) funcName, str1, str2);
2373
0
    else if (actxt->type == XML_SCHEMA_CTXT_PARSER)
2374
0
  xmlSchemaErr3(actxt, XML_SCHEMAP_INTERNAL, NULL,
2375
0
      (const char *) msg, (const xmlChar *) funcName, str1, str2);
2376
2377
0
    FREE_AND_NULL(msg)
2378
0
}
2379
2380
static void LIBXML_ATTR_FORMAT(3,0)
2381
xmlSchemaInternalErr(xmlSchemaAbstractCtxtPtr actxt,
2382
         const char *funcName,
2383
         const char *message)
2384
0
{
2385
0
    xmlSchemaInternalErr2(actxt, funcName, message, NULL, NULL);
2386
0
}
2387
2388
#if 0
2389
static void LIBXML_ATTR_FORMAT(3,0)
2390
xmlSchemaPInternalErr(xmlSchemaParserCtxtPtr pctxt,
2391
         const char *funcName,
2392
         const char *message,
2393
         const xmlChar *str1,
2394
         const xmlChar *str2)
2395
{
2396
    xmlSchemaInternalErr2(ACTXT_CAST pctxt, funcName, message,
2397
  str1, str2);
2398
}
2399
#endif
2400
2401
static void LIBXML_ATTR_FORMAT(5,0)
2402
xmlSchemaCustomErr4(xmlSchemaAbstractCtxtPtr actxt,
2403
       xmlParserErrors error,
2404
       xmlNodePtr node,
2405
       xmlSchemaBasicItemPtr item,
2406
       const char *message,
2407
       const xmlChar *str1, const xmlChar *str2,
2408
       const xmlChar *str3, const xmlChar *str4)
2409
0
{
2410
0
    xmlChar *msg = NULL;
2411
2412
0
    if ((node == NULL) && (item != NULL) &&
2413
0
  (actxt->type == XML_SCHEMA_CTXT_PARSER)) {
2414
0
  node = WXS_ITEM_NODE(item);
2415
0
  xmlSchemaFormatItemForReport(&msg, NULL, item, NULL);
2416
0
  msg = xmlStrcat(msg, BAD_CAST ": ");
2417
0
    } else
2418
0
  xmlSchemaFormatNodeForError(&msg, actxt, node);
2419
0
    msg = xmlStrcat(msg, (const xmlChar *) message);
2420
0
    msg = xmlStrcat(msg, BAD_CAST ".\n");
2421
0
    xmlSchemaErr4(actxt, error, node,
2422
0
  (const char *) msg, str1, str2, str3, str4);
2423
0
    FREE_AND_NULL(msg)
2424
0
}
2425
2426
static void LIBXML_ATTR_FORMAT(5,0)
2427
xmlSchemaCustomErr(xmlSchemaAbstractCtxtPtr actxt,
2428
       xmlParserErrors error,
2429
       xmlNodePtr node,
2430
       xmlSchemaBasicItemPtr item,
2431
       const char *message,
2432
       const xmlChar *str1,
2433
       const xmlChar *str2)
2434
0
{
2435
0
    xmlSchemaCustomErr4(actxt, error, node, item,
2436
0
  message, str1, str2, NULL, NULL);
2437
0
}
2438
2439
2440
2441
static void LIBXML_ATTR_FORMAT(5,0)
2442
xmlSchemaCustomWarning(xmlSchemaAbstractCtxtPtr actxt,
2443
       xmlParserErrors error,
2444
       xmlNodePtr node,
2445
       xmlSchemaTypePtr type ATTRIBUTE_UNUSED,
2446
       const char *message,
2447
       const xmlChar *str1,
2448
       const xmlChar *str2,
2449
       const xmlChar *str3)
2450
0
{
2451
0
    xmlChar *msg = NULL;
2452
2453
0
    xmlSchemaFormatNodeForError(&msg, actxt, node);
2454
0
    msg = xmlStrcat(msg, (const xmlChar *) message);
2455
0
    msg = xmlStrcat(msg, BAD_CAST ".\n");
2456
2457
    /* URGENT TODO: Set the error code to something sane. */
2458
0
    xmlSchemaErr4Line(actxt, XML_ERR_WARNING, error, node, 0,
2459
0
  (const char *) msg, str1, str2, str3, NULL);
2460
2461
0
    FREE_AND_NULL(msg)
2462
0
}
2463
2464
2465
2466
static void LIBXML_ATTR_FORMAT(5,0)
2467
xmlSchemaKeyrefErr(xmlSchemaValidCtxtPtr vctxt,
2468
       xmlParserErrors error,
2469
       xmlSchemaPSVIIDCNodePtr idcNode,
2470
       xmlSchemaTypePtr type ATTRIBUTE_UNUSED,
2471
       const char *message,
2472
       const xmlChar *str1,
2473
       const xmlChar *str2)
2474
0
{
2475
0
    xmlChar *msg = NULL, *qname = NULL;
2476
2477
0
    msg = xmlStrdup(BAD_CAST "Element '%s': ");
2478
0
    msg = xmlStrcat(msg, (const xmlChar *) message);
2479
0
    msg = xmlStrcat(msg, BAD_CAST ".\n");
2480
0
    xmlSchemaErr4Line(ACTXT_CAST vctxt, XML_ERR_ERROR,
2481
0
  error, NULL, idcNode->nodeLine, (const char *) msg,
2482
0
  xmlSchemaFormatQName(&qname,
2483
0
      vctxt->nodeQNames->items[idcNode->nodeQNameID +1],
2484
0
      vctxt->nodeQNames->items[idcNode->nodeQNameID]),
2485
0
  str1, str2, NULL);
2486
0
    FREE_AND_NULL(qname);
2487
0
    FREE_AND_NULL(msg);
2488
0
}
2489
2490
static int
2491
xmlSchemaEvalErrorNodeType(xmlSchemaAbstractCtxtPtr actxt,
2492
         xmlNodePtr node)
2493
0
{
2494
0
    if (node != NULL)
2495
0
  return (node->type);
2496
0
    if ((actxt->type == XML_SCHEMA_CTXT_VALIDATOR) &&
2497
0
  (((xmlSchemaValidCtxtPtr) actxt)->inode != NULL))
2498
0
  return ( ((xmlSchemaValidCtxtPtr) actxt)->inode->nodeType);
2499
0
    return (-1);
2500
0
}
2501
2502
static int
2503
xmlSchemaIsGlobalItem(xmlSchemaTypePtr item)
2504
0
{
2505
0
    switch (item->type) {
2506
0
  case XML_SCHEMA_TYPE_COMPLEX:
2507
0
  case XML_SCHEMA_TYPE_SIMPLE:
2508
0
      if (item->flags & XML_SCHEMAS_TYPE_GLOBAL)
2509
0
    return(1);
2510
0
      break;
2511
0
  case XML_SCHEMA_TYPE_GROUP:
2512
0
      return (1);
2513
0
  case XML_SCHEMA_TYPE_ELEMENT:
2514
0
      if ( ((xmlSchemaElementPtr) item)->flags &
2515
0
    XML_SCHEMAS_ELEM_GLOBAL)
2516
0
    return(1);
2517
0
      break;
2518
0
  case XML_SCHEMA_TYPE_ATTRIBUTE:
2519
0
      if ( ((xmlSchemaAttributePtr) item)->flags &
2520
0
    XML_SCHEMAS_ATTR_GLOBAL)
2521
0
    return(1);
2522
0
      break;
2523
  /* Note that attribute groups are always global. */
2524
0
  default:
2525
0
      return(1);
2526
0
    }
2527
0
    return (0);
2528
0
}
2529
2530
static void
2531
xmlSchemaSimpleTypeErr(xmlSchemaAbstractCtxtPtr actxt,
2532
           xmlParserErrors error,
2533
           xmlNodePtr node,
2534
           const xmlChar *value,
2535
           xmlSchemaTypePtr type,
2536
           int displayValue)
2537
0
{
2538
0
    xmlChar *msg = NULL;
2539
2540
0
    xmlSchemaFormatNodeForError(&msg, actxt, node);
2541
2542
0
    if (displayValue || (xmlSchemaEvalErrorNodeType(actxt, node) ==
2543
0
      XML_ATTRIBUTE_NODE))
2544
0
  msg = xmlStrcat(msg, BAD_CAST "'%s' is not a valid value of ");
2545
0
    else
2546
0
  msg = xmlStrcat(msg, BAD_CAST "The character content is not a valid "
2547
0
      "value of ");
2548
2549
0
    if (! xmlSchemaIsGlobalItem(type))
2550
0
  msg = xmlStrcat(msg, BAD_CAST "the local ");
2551
0
    else
2552
0
  msg = xmlStrcat(msg, BAD_CAST "the ");
2553
2554
0
    if (WXS_IS_ATOMIC(type))
2555
0
  msg = xmlStrcat(msg, BAD_CAST "atomic type");
2556
0
    else if (WXS_IS_LIST(type))
2557
0
  msg = xmlStrcat(msg, BAD_CAST "list type");
2558
0
    else if (WXS_IS_UNION(type))
2559
0
  msg = xmlStrcat(msg, BAD_CAST "union type");
2560
2561
0
    if (xmlSchemaIsGlobalItem(type)) {
2562
0
  xmlChar *str = NULL;
2563
0
  msg = xmlStrcat(msg, BAD_CAST " '");
2564
0
  if (type->builtInType != 0) {
2565
0
      msg = xmlStrcat(msg, BAD_CAST "xs:");
2566
0
      str = xmlStrdup(type->name);
2567
0
  } else {
2568
0
      const xmlChar *qName = xmlSchemaFormatQName(&str, type->targetNamespace, type->name);
2569
0
      if (!str)
2570
0
    str = xmlStrdup(qName);
2571
0
  }
2572
0
  msg = xmlStrcat(msg, xmlEscapeFormatString(&str));
2573
0
  msg = xmlStrcat(msg, BAD_CAST "'");
2574
0
  FREE_AND_NULL(str);
2575
0
    }
2576
0
    msg = xmlStrcat(msg, BAD_CAST ".\n");
2577
0
    if (displayValue || (xmlSchemaEvalErrorNodeType(actxt, node) ==
2578
0
      XML_ATTRIBUTE_NODE))
2579
0
  xmlSchemaErr(actxt, error, node, (const char *) msg, value, NULL);
2580
0
    else
2581
0
  xmlSchemaErr(actxt, error, node, (const char *) msg, NULL, NULL);
2582
0
    FREE_AND_NULL(msg)
2583
0
}
2584
2585
static const xmlChar *
2586
xmlSchemaFormatErrorNodeQName(xmlChar ** str,
2587
            xmlSchemaNodeInfoPtr ni,
2588
            xmlNodePtr node)
2589
0
{
2590
0
    if (node != NULL) {
2591
0
  if (node->ns != NULL)
2592
0
      return (xmlSchemaFormatQName(str, node->ns->href, node->name));
2593
0
  else
2594
0
      return (xmlSchemaFormatQName(str, NULL, node->name));
2595
0
    } else if (ni != NULL)
2596
0
  return (xmlSchemaFormatQName(str, ni->nsName, ni->localName));
2597
0
    return (NULL);
2598
0
}
2599
2600
static void
2601
xmlSchemaIllegalAttrErr(xmlSchemaAbstractCtxtPtr actxt,
2602
      xmlParserErrors error,
2603
      xmlSchemaAttrInfoPtr ni,
2604
      xmlNodePtr node)
2605
0
{
2606
0
    xmlChar *msg = NULL, *str = NULL;
2607
2608
0
    xmlSchemaFormatNodeForError(&msg, actxt, node);
2609
0
    msg = xmlStrcat(msg, BAD_CAST "The attribute '%s' is not allowed.\n");
2610
0
    xmlSchemaErr(actxt, error, node, (const char *) msg,
2611
0
  xmlSchemaFormatErrorNodeQName(&str, (xmlSchemaNodeInfoPtr) ni, node),
2612
0
  NULL);
2613
0
    FREE_AND_NULL(str)
2614
0
    FREE_AND_NULL(msg)
2615
0
}
2616
2617
static void LIBXML_ATTR_FORMAT(5,0)
2618
xmlSchemaComplexTypeErr(xmlSchemaAbstractCtxtPtr actxt,
2619
            xmlParserErrors error,
2620
            xmlNodePtr node,
2621
      xmlSchemaTypePtr type ATTRIBUTE_UNUSED,
2622
      const char *message,
2623
      int nbval,
2624
      int nbneg,
2625
      xmlChar **values)
2626
0
{
2627
0
    xmlChar *str = NULL, *msg = NULL;
2628
0
    xmlChar *localName, *nsName;
2629
0
    const xmlChar *cur, *end;
2630
0
    int i;
2631
2632
0
    xmlSchemaFormatNodeForError(&msg, actxt, node);
2633
0
    msg = xmlStrcat(msg, (const xmlChar *) message);
2634
0
    msg = xmlStrcat(msg, BAD_CAST ".");
2635
    /*
2636
    * Note that is does not make sense to report that we have a
2637
    * wildcard here, since the wildcard might be unfolded into
2638
    * multiple transitions.
2639
    */
2640
0
    if (nbval + nbneg > 0) {
2641
0
  if (nbval + nbneg > 1) {
2642
0
      str = xmlStrdup(BAD_CAST " Expected is one of ( ");
2643
0
  } else
2644
0
      str = xmlStrdup(BAD_CAST " Expected is ( ");
2645
0
  nsName = NULL;
2646
2647
0
  for (i = 0; i < nbval + nbneg; i++) {
2648
0
      cur = values[i];
2649
0
      if (cur == NULL)
2650
0
          continue;
2651
0
      if ((cur[0] == 'n') && (cur[1] == 'o') && (cur[2] == 't') &&
2652
0
          (cur[3] == ' ')) {
2653
0
    cur += 4;
2654
0
    str = xmlStrcat(str, BAD_CAST "##other");
2655
0
      }
2656
      /*
2657
      * Get the local name.
2658
      */
2659
0
      localName = NULL;
2660
2661
0
      end = cur;
2662
0
      if (*end == '*') {
2663
0
    localName = xmlStrdup(BAD_CAST "*");
2664
0
    end++;
2665
0
      } else {
2666
0
    while ((*end != 0) && (*end != '|'))
2667
0
        end++;
2668
0
    localName = xmlStrncat(localName, BAD_CAST cur, end - cur);
2669
0
      }
2670
0
      if (*end != 0) {
2671
0
    end++;
2672
    /*
2673
    * Skip "*|*" if they come with negated expressions, since
2674
    * they represent the same negated wildcard.
2675
    */
2676
0
    if ((nbneg == 0) || (*end != '*') || (*localName != '*')) {
2677
        /*
2678
        * Get the namespace name.
2679
        */
2680
0
        cur = end;
2681
0
        if (*end == '*') {
2682
0
      nsName = xmlStrdup(BAD_CAST "{*}");
2683
0
        } else {
2684
0
      while (*end != 0)
2685
0
          end++;
2686
2687
0
      if (i >= nbval)
2688
0
          nsName = xmlStrdup(BAD_CAST "{##other:");
2689
0
      else
2690
0
          nsName = xmlStrdup(BAD_CAST "{");
2691
2692
0
      nsName = xmlStrncat(nsName, BAD_CAST cur, end - cur);
2693
0
      nsName = xmlStrcat(nsName, BAD_CAST "}");
2694
0
        }
2695
0
        str = xmlStrcat(str, BAD_CAST nsName);
2696
0
        FREE_AND_NULL(nsName)
2697
0
    } else {
2698
0
        FREE_AND_NULL(localName);
2699
0
        continue;
2700
0
    }
2701
0
      }
2702
0
      str = xmlStrcat(str, BAD_CAST localName);
2703
0
      FREE_AND_NULL(localName);
2704
2705
0
      if (i < nbval + nbneg -1)
2706
0
    str = xmlStrcat(str, BAD_CAST ", ");
2707
0
  }
2708
0
  str = xmlStrcat(str, BAD_CAST " ).\n");
2709
0
  msg = xmlStrcat(msg, xmlEscapeFormatString(&str));
2710
0
  FREE_AND_NULL(str)
2711
0
    } else
2712
0
      msg = xmlStrcat(msg, BAD_CAST "\n");
2713
0
    xmlSchemaErr(actxt, error, node, (const char *) msg, NULL, NULL);
2714
0
    xmlFree(msg);
2715
0
}
2716
2717
static void LIBXML_ATTR_FORMAT(8,0)
2718
xmlSchemaFacetErr(xmlSchemaAbstractCtxtPtr actxt,
2719
      xmlParserErrors error,
2720
      xmlNodePtr node,
2721
      const xmlChar *value,
2722
      unsigned long length,
2723
      xmlSchemaTypePtr type,
2724
      xmlSchemaFacetPtr facet,
2725
      const char *message,
2726
      const xmlChar *str1,
2727
      const xmlChar *str2)
2728
0
{
2729
0
    xmlChar *str = NULL, *msg = NULL;
2730
0
    xmlSchemaTypeType facetType;
2731
0
    int nodeType = xmlSchemaEvalErrorNodeType(actxt, node);
2732
2733
0
    xmlSchemaFormatNodeForError(&msg, actxt, node);
2734
0
    if (error == XML_SCHEMAV_CVC_ENUMERATION_VALID) {
2735
0
  facetType = XML_SCHEMA_FACET_ENUMERATION;
2736
  /*
2737
  * If enumerations are validated, one must not expect the
2738
  * facet to be given.
2739
  */
2740
0
    } else
2741
0
  facetType = facet->type;
2742
0
    msg = xmlStrcat(msg, BAD_CAST "[");
2743
0
    msg = xmlStrcat(msg, BAD_CAST "facet '");
2744
0
    msg = xmlStrcat(msg, xmlSchemaFacetTypeToString(facetType));
2745
0
    msg = xmlStrcat(msg, BAD_CAST "'] ");
2746
0
    if (message == NULL) {
2747
  /*
2748
  * Use a default message.
2749
  */
2750
0
  if ((facetType == XML_SCHEMA_FACET_LENGTH) ||
2751
0
      (facetType == XML_SCHEMA_FACET_MINLENGTH) ||
2752
0
      (facetType == XML_SCHEMA_FACET_MAXLENGTH)) {
2753
2754
0
      char len[25], actLen[25];
2755
2756
      /* FIXME, TODO: What is the max expected string length of the
2757
      * this value?
2758
      */
2759
0
      if (nodeType == XML_ATTRIBUTE_NODE)
2760
0
    msg = xmlStrcat(msg, BAD_CAST "The value '%s' has a length of '%s'; ");
2761
0
      else
2762
0
    msg = xmlStrcat(msg, BAD_CAST "The value has a length of '%s'; ");
2763
2764
0
      snprintf(len, 24, "%lu", xmlSchemaGetFacetValueAsULong(facet));
2765
0
      snprintf(actLen, 24, "%lu", length);
2766
2767
0
      if (facetType == XML_SCHEMA_FACET_LENGTH)
2768
0
    msg = xmlStrcat(msg,
2769
0
    BAD_CAST "this differs from the allowed length of '%s'.\n");
2770
0
      else if (facetType == XML_SCHEMA_FACET_MAXLENGTH)
2771
0
    msg = xmlStrcat(msg,
2772
0
    BAD_CAST "this exceeds the allowed maximum length of '%s'.\n");
2773
0
      else if (facetType == XML_SCHEMA_FACET_MINLENGTH)
2774
0
    msg = xmlStrcat(msg,
2775
0
    BAD_CAST "this underruns the allowed minimum length of '%s'.\n");
2776
2777
0
      if (nodeType == XML_ATTRIBUTE_NODE)
2778
0
    xmlSchemaErr3(actxt, error, node, (const char *) msg,
2779
0
        value, (const xmlChar *) actLen, (const xmlChar *) len);
2780
0
      else
2781
0
    xmlSchemaErr(actxt, error, node, (const char *) msg,
2782
0
        (const xmlChar *) actLen, (const xmlChar *) len);
2783
2784
0
  } else if (facetType == XML_SCHEMA_FACET_ENUMERATION) {
2785
0
      msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not an element "
2786
0
    "of the set {%s}.\n");
2787
0
      xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2788
0
    xmlSchemaFormatFacetEnumSet(actxt, &str, type));
2789
0
  } else if (facetType == XML_SCHEMA_FACET_PATTERN) {
2790
0
      msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not accepted "
2791
0
    "by the pattern '%s'.\n");
2792
0
      xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2793
0
    facet->value);
2794
0
  } else if (facetType == XML_SCHEMA_FACET_MININCLUSIVE) {
2795
0
      msg = xmlStrcat(msg, BAD_CAST "The value '%s' is less than the "
2796
0
    "minimum value allowed ('%s').\n");
2797
0
      xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2798
0
    facet->value);
2799
0
  } else if (facetType == XML_SCHEMA_FACET_MAXINCLUSIVE) {
2800
0
      msg = xmlStrcat(msg, BAD_CAST "The value '%s' is greater than the "
2801
0
    "maximum value allowed ('%s').\n");
2802
0
      xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2803
0
    facet->value);
2804
0
  } else if (facetType == XML_SCHEMA_FACET_MINEXCLUSIVE) {
2805
0
      msg = xmlStrcat(msg, BAD_CAST "The value '%s' must be greater than "
2806
0
    "'%s'.\n");
2807
0
      xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2808
0
    facet->value);
2809
0
  } else if (facetType == XML_SCHEMA_FACET_MAXEXCLUSIVE) {
2810
0
      msg = xmlStrcat(msg, BAD_CAST "The value '%s' must be less than "
2811
0
    "'%s'.\n");
2812
0
      xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2813
0
    facet->value);
2814
0
  } else if (facetType == XML_SCHEMA_FACET_TOTALDIGITS) {
2815
0
      msg = xmlStrcat(msg, BAD_CAST "The value '%s' has more "
2816
0
    "digits than are allowed ('%s').\n");
2817
0
      xmlSchemaErr(actxt, error, node, (const char*) msg, value,
2818
0
    facet->value);
2819
0
  } else if (facetType == XML_SCHEMA_FACET_FRACTIONDIGITS) {
2820
0
      msg = xmlStrcat(msg, BAD_CAST "The value '%s' has more fractional "
2821
0
    "digits than are allowed ('%s').\n");
2822
0
      xmlSchemaErr(actxt, error, node, (const char*) msg, value,
2823
0
    facet->value);
2824
0
  } else if (nodeType == XML_ATTRIBUTE_NODE) {
2825
0
      msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not facet-valid.\n");
2826
0
      xmlSchemaErr(actxt, error, node, (const char *) msg, value, NULL);
2827
0
  } else {
2828
0
      msg = xmlStrcat(msg, BAD_CAST "The value is not facet-valid.\n");
2829
0
      xmlSchemaErr(actxt, error, node, (const char *) msg, NULL, NULL);
2830
0
  }
2831
0
    } else {
2832
0
  msg = xmlStrcat(msg, (const xmlChar *) message);
2833
0
  msg = xmlStrcat(msg, BAD_CAST ".\n");
2834
0
  xmlSchemaErr(actxt, error, node, (const char *) msg, str1, str2);
2835
0
    }
2836
0
    FREE_AND_NULL(str)
2837
0
    xmlFree(msg);
2838
0
}
2839
2840
#define VERROR(err, type, msg) \
2841
0
    xmlSchemaCustomErr(ACTXT_CAST vctxt, err, NULL, type, msg, NULL, NULL);
2842
2843
0
#define VERROR_INT(func, msg) xmlSchemaInternalErr(ACTXT_CAST vctxt, func, msg);
2844
2845
0
#define PERROR_INT(func, msg) xmlSchemaInternalErr(ACTXT_CAST pctxt, func, msg);
2846
0
#define PERROR_INT2(func, msg) xmlSchemaInternalErr(ACTXT_CAST ctxt, func, msg);
2847
2848
0
#define AERROR_INT(func, msg) xmlSchemaInternalErr(actxt, func, msg);
2849
2850
2851
/**
2852
 * xmlSchemaPMissingAttrErr:
2853
 * @ctxt: the schema validation context
2854
 * @ownerItem: the owner as a schema object
2855
 * @ownerElem: the owner as an element node
2856
 * @node: the parent element node of the missing attribute node
2857
 * @type: the corresponding type of the attribute node
2858
 *
2859
 * Reports an illegal attribute.
2860
 */
2861
static void
2862
xmlSchemaPMissingAttrErr(xmlSchemaParserCtxtPtr ctxt,
2863
       xmlParserErrors error,
2864
       xmlSchemaBasicItemPtr ownerItem,
2865
       xmlNodePtr ownerElem,
2866
       const char *name,
2867
       const char *message)
2868
0
{
2869
0
    xmlChar *des = NULL;
2870
2871
0
    xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem);
2872
2873
0
    if (message != NULL)
2874
0
  xmlSchemaPErr(ctxt, ownerElem, error, "%s: %s.\n", BAD_CAST des, BAD_CAST message);
2875
0
    else
2876
0
  xmlSchemaPErr(ctxt, ownerElem, error,
2877
0
      "%s: The attribute '%s' is required but missing.\n",
2878
0
      BAD_CAST des, BAD_CAST name);
2879
0
    FREE_AND_NULL(des);
2880
0
}
2881
2882
2883
/**
2884
 * xmlSchemaPResCompAttrErr:
2885
 * @ctxt: the schema validation context
2886
 * @error: the error code
2887
 * @ownerItem: the owner as a schema object
2888
 * @ownerElem: the owner as an element node
2889
 * @name: the name of the attribute holding the QName
2890
 * @refName: the referenced local name
2891
 * @refURI: the referenced namespace URI
2892
 * @message: optional message
2893
 *
2894
 * Used to report QName attribute values that failed to resolve
2895
 * to schema components.
2896
 */
2897
static void
2898
xmlSchemaPResCompAttrErr(xmlSchemaParserCtxtPtr ctxt,
2899
       xmlParserErrors error,
2900
       xmlSchemaBasicItemPtr ownerItem,
2901
       xmlNodePtr ownerElem,
2902
       const char *name,
2903
       const xmlChar *refName,
2904
       const xmlChar *refURI,
2905
       xmlSchemaTypeType refType,
2906
       const char *refTypeStr)
2907
0
{
2908
0
    xmlChar *des = NULL, *strA = NULL;
2909
2910
0
    xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem);
2911
0
    if (refTypeStr == NULL)
2912
0
  refTypeStr = (const char *) xmlSchemaItemTypeToStr(refType);
2913
0
    xmlSchemaPErrExt(ctxt, ownerElem, error,
2914
0
      NULL, NULL, NULL,
2915
0
      "%s, attribute '%s': The QName value '%s' does not resolve to a(n) "
2916
0
      "%s.\n", BAD_CAST des, BAD_CAST name,
2917
0
      xmlSchemaFormatQName(&strA, refURI, refName),
2918
0
      BAD_CAST refTypeStr, NULL);
2919
0
    FREE_AND_NULL(des)
2920
0
    FREE_AND_NULL(strA)
2921
0
}
2922
2923
/**
2924
 * xmlSchemaPCustomAttrErr:
2925
 * @ctxt: the schema parser context
2926
 * @error: the error code
2927
 * @ownerDes: the designation of the owner
2928
 * @ownerItem: the owner as a schema object
2929
 * @attr: the illegal attribute node
2930
 *
2931
 * Reports an illegal attribute during the parse.
2932
 */
2933
static void
2934
xmlSchemaPCustomAttrErr(xmlSchemaParserCtxtPtr ctxt,
2935
      xmlParserErrors error,
2936
      xmlChar **ownerDes,
2937
      xmlSchemaBasicItemPtr ownerItem,
2938
      xmlAttrPtr attr,
2939
      const char *msg)
2940
0
{
2941
0
    xmlChar *des = NULL;
2942
2943
0
    if (ownerDes == NULL)
2944
0
  xmlSchemaFormatItemForReport(&des, NULL, ownerItem, attr->parent);
2945
0
    else if (*ownerDes == NULL) {
2946
0
  xmlSchemaFormatItemForReport(ownerDes, NULL, ownerItem, attr->parent);
2947
0
  des = *ownerDes;
2948
0
    } else
2949
0
  des = *ownerDes;
2950
0
    if (attr == NULL) {
2951
0
  xmlSchemaPErrExt(ctxt, NULL, error, NULL, NULL, NULL,
2952
0
      "%s, attribute '%s': %s.\n",
2953
0
      BAD_CAST des, (const xmlChar *) "Unknown",
2954
0
      (const xmlChar *) msg, NULL, NULL);
2955
0
    } else {
2956
0
  xmlSchemaPErrExt(ctxt, (xmlNodePtr) attr, error, NULL, NULL, NULL,
2957
0
      "%s, attribute '%s': %s.\n",
2958
0
      BAD_CAST des, attr->name, (const xmlChar *) msg, NULL, NULL);
2959
0
    }
2960
0
    if (ownerDes == NULL)
2961
0
  FREE_AND_NULL(des);
2962
0
}
2963
2964
/**
2965
 * xmlSchemaPIllegalAttrErr:
2966
 * @ctxt: the schema parser context
2967
 * @error: the error code
2968
 * @ownerItem: the attribute's owner item
2969
 * @attr: the illegal attribute node
2970
 *
2971
 * Reports an illegal attribute during the parse.
2972
 */
2973
static void
2974
xmlSchemaPIllegalAttrErr(xmlSchemaParserCtxtPtr ctxt,
2975
       xmlParserErrors error,
2976
       xmlSchemaBasicItemPtr ownerComp ATTRIBUTE_UNUSED,
2977
       xmlAttrPtr attr)
2978
0
{
2979
0
    xmlChar *strA = NULL, *strB = NULL;
2980
2981
0
    xmlSchemaFormatNodeForError(&strA, ACTXT_CAST ctxt, attr->parent);
2982
0
    xmlSchemaErr4(ACTXT_CAST ctxt, error, (xmlNodePtr) attr,
2983
0
  "%sThe attribute '%s' is not allowed.\n", BAD_CAST strA,
2984
0
  xmlSchemaFormatQNameNs(&strB, attr->ns, attr->name),
2985
0
  NULL, NULL);
2986
0
    FREE_AND_NULL(strA);
2987
0
    FREE_AND_NULL(strB);
2988
0
}
2989
2990
/**
2991
 * xmlSchemaPCustomErr:
2992
 * @ctxt: the schema parser context
2993
 * @error: the error code
2994
 * @itemDes: the designation of the schema item
2995
 * @item: the schema item
2996
 * @itemElem: the node of the schema item
2997
 * @message: the error message
2998
 * @str1: an optional param for the error message
2999
 * @str2: an optional param for the error message
3000
 * @str3: an optional param for the error message
3001
 *
3002
 * Reports an error during parsing.
3003
 */
3004
static void LIBXML_ATTR_FORMAT(5,0)
3005
xmlSchemaPCustomErrExt(xmlSchemaParserCtxtPtr ctxt,
3006
        xmlParserErrors error,
3007
        xmlSchemaBasicItemPtr item,
3008
        xmlNodePtr itemElem,
3009
        const char *message,
3010
        const xmlChar *str1,
3011
        const xmlChar *str2,
3012
        const xmlChar *str3)
3013
0
{
3014
0
    xmlChar *des = NULL, *msg = NULL;
3015
3016
0
    xmlSchemaFormatItemForReport(&des, NULL, item, itemElem);
3017
0
    msg = xmlStrdup(BAD_CAST "%s: ");
3018
0
    msg = xmlStrcat(msg, (const xmlChar *) message);
3019
0
    msg = xmlStrcat(msg, BAD_CAST ".\n");
3020
0
    if ((itemElem == NULL) && (item != NULL))
3021
0
  itemElem = WXS_ITEM_NODE(item);
3022
0
    xmlSchemaPErrExt(ctxt, itemElem, error, NULL, NULL, NULL,
3023
0
  (const char *) msg, BAD_CAST des, str1, str2, str3, NULL);
3024
0
    FREE_AND_NULL(des);
3025
0
    FREE_AND_NULL(msg);
3026
0
}
3027
3028
/**
3029
 * xmlSchemaPCustomErr:
3030
 * @ctxt: the schema parser context
3031
 * @error: the error code
3032
 * @itemDes: the designation of the schema item
3033
 * @item: the schema item
3034
 * @itemElem: the node of the schema item
3035
 * @message: the error message
3036
 * @str1: the optional param for the error message
3037
 *
3038
 * Reports an error during parsing.
3039
 */
3040
static void LIBXML_ATTR_FORMAT(5,0)
3041
xmlSchemaPCustomErr(xmlSchemaParserCtxtPtr ctxt,
3042
        xmlParserErrors error,
3043
        xmlSchemaBasicItemPtr item,
3044
        xmlNodePtr itemElem,
3045
        const char *message,
3046
        const xmlChar *str1)
3047
0
{
3048
0
    xmlSchemaPCustomErrExt(ctxt, error, item, itemElem, message,
3049
0
  str1, NULL, NULL);
3050
0
}
3051
3052
/**
3053
 * xmlSchemaPAttrUseErr:
3054
 * @ctxt: the schema parser context
3055
 * @error: the error code
3056
 * @itemDes: the designation of the schema type
3057
 * @item: the schema type
3058
 * @itemElem: the node of the schema type
3059
 * @attr: the invalid schema attribute
3060
 * @message: the error message
3061
 * @str1: the optional param for the error message
3062
 *
3063
 * Reports an attribute use error during parsing.
3064
 */
3065
static void LIBXML_ATTR_FORMAT(6,0)
3066
xmlSchemaPAttrUseErr4(xmlSchemaParserCtxtPtr ctxt,
3067
        xmlParserErrors error,
3068
        xmlNodePtr node,
3069
        xmlSchemaBasicItemPtr ownerItem,
3070
        const xmlSchemaAttributeUsePtr attruse,
3071
        const char *message,
3072
        const xmlChar *str1, const xmlChar *str2,
3073
        const xmlChar *str3,const xmlChar *str4)
3074
0
{
3075
0
    xmlChar *str = NULL, *msg = NULL;
3076
3077
0
    xmlSchemaFormatItemForReport(&msg, NULL, ownerItem, NULL);
3078
0
    msg = xmlStrcat(msg, BAD_CAST ", ");
3079
0
    msg = xmlStrcat(msg,
3080
0
  BAD_CAST xmlSchemaFormatItemForReport(&str, NULL,
3081
0
  WXS_BASIC_CAST attruse, NULL));
3082
0
    FREE_AND_NULL(str);
3083
0
    msg = xmlStrcat(msg, BAD_CAST ": ");
3084
0
    msg = xmlStrcat(msg, (const xmlChar *) message);
3085
0
    msg = xmlStrcat(msg, BAD_CAST ".\n");
3086
0
    xmlSchemaErr4(ACTXT_CAST ctxt, error, node,
3087
0
  (const char *) msg, str1, str2, str3, str4);
3088
0
    xmlFree(msg);
3089
0
}
3090
3091
/**
3092
 * xmlSchemaPIllegalFacetAtomicErr:
3093
 * @ctxt: the schema parser context
3094
 * @error: the error code
3095
 * @type: the schema type
3096
 * @baseType: the base type of type
3097
 * @facet: the illegal facet
3098
 *
3099
 * Reports an illegal facet for atomic simple types.
3100
 */
3101
static void
3102
xmlSchemaPIllegalFacetAtomicErr(xmlSchemaParserCtxtPtr ctxt,
3103
        xmlParserErrors error,
3104
        xmlSchemaTypePtr type,
3105
        xmlSchemaTypePtr baseType,
3106
        xmlSchemaFacetPtr facet)
3107
0
{
3108
0
    xmlChar *des = NULL, *strT = NULL;
3109
3110
0
    xmlSchemaFormatItemForReport(&des, NULL, WXS_BASIC_CAST type, type->node);
3111
0
    xmlSchemaPErrExt(ctxt, type->node, error, NULL, NULL, NULL,
3112
0
  "%s: The facet '%s' is not allowed on types derived from the "
3113
0
  "type %s.\n",
3114
0
  BAD_CAST des, xmlSchemaFacetTypeToString(facet->type),
3115
0
  xmlSchemaFormatItemForReport(&strT, NULL, WXS_BASIC_CAST baseType, NULL),
3116
0
  NULL, NULL);
3117
0
    FREE_AND_NULL(des);
3118
0
    FREE_AND_NULL(strT);
3119
0
}
3120
3121
/**
3122
 * xmlSchemaPIllegalFacetListUnionErr:
3123
 * @ctxt: the schema parser context
3124
 * @error: the error code
3125
 * @itemDes: the designation of the schema item involved
3126
 * @item: the schema item involved
3127
 * @facet: the illegal facet
3128
 *
3129
 * Reports an illegal facet for <list> and <union>.
3130
 */
3131
static void
3132
xmlSchemaPIllegalFacetListUnionErr(xmlSchemaParserCtxtPtr ctxt,
3133
        xmlParserErrors error,
3134
        xmlSchemaTypePtr type,
3135
        xmlSchemaFacetPtr facet)
3136
0
{
3137
0
    xmlChar *des = NULL;
3138
3139
0
    xmlSchemaFormatItemForReport(&des, NULL, WXS_BASIC_CAST type,
3140
0
  type->node);
3141
0
    xmlSchemaPErr(ctxt, type->node, error,
3142
0
  "%s: The facet '%s' is not allowed.\n",
3143
0
  BAD_CAST des, xmlSchemaFacetTypeToString(facet->type));
3144
0
    FREE_AND_NULL(des);
3145
0
}
3146
3147
/**
3148
 * xmlSchemaPMutualExclAttrErr:
3149
 * @ctxt: the schema validation context
3150
 * @error: the error code
3151
 * @elemDes: the designation of the parent element node
3152
 * @attr: the bad attribute node
3153
 * @type: the corresponding type of the attribute node
3154
 *
3155
 * Reports an illegal attribute.
3156
 */
3157
static void
3158
xmlSchemaPMutualExclAttrErr(xmlSchemaParserCtxtPtr ctxt,
3159
       xmlParserErrors error,
3160
       xmlSchemaBasicItemPtr ownerItem,
3161
       xmlAttrPtr attr,
3162
       const char *name1,
3163
       const char *name2)
3164
0
{
3165
0
    xmlChar *des = NULL;
3166
3167
0
    xmlSchemaFormatItemForReport(&des, NULL, WXS_BASIC_CAST ownerItem, attr->parent);
3168
0
    xmlSchemaPErrExt(ctxt, (xmlNodePtr) attr, error, NULL, NULL, NULL,
3169
0
  "%s: The attributes '%s' and '%s' are mutually exclusive.\n",
3170
0
  BAD_CAST des, BAD_CAST name1, BAD_CAST name2, NULL, NULL);
3171
0
    FREE_AND_NULL(des);
3172
0
}
3173
3174
/**
3175
 * xmlSchemaPSimpleTypeErr:
3176
 * @ctxt:  the schema validation context
3177
 * @error: the error code
3178
 * @type: the type specifier
3179
 * @ownerItem: the schema object if existent
3180
 * @node: the validated node
3181
 * @value: the validated value
3182
 *
3183
 * Reports a simple type validation error.
3184
 * TODO: Should this report the value of an element as well?
3185
 */
3186
static void LIBXML_ATTR_FORMAT(8,0)
3187
xmlSchemaPSimpleTypeErr(xmlSchemaParserCtxtPtr ctxt,
3188
      xmlParserErrors error,
3189
      xmlSchemaBasicItemPtr ownerItem ATTRIBUTE_UNUSED,
3190
      xmlNodePtr node,
3191
      xmlSchemaTypePtr type,
3192
      const char *expected,
3193
      const xmlChar *value,
3194
      const char *message,
3195
      const xmlChar *str1,
3196
      const xmlChar *str2)
3197
0
{
3198
0
    xmlChar *msg = NULL;
3199
3200
0
    xmlSchemaFormatNodeForError(&msg, ACTXT_CAST ctxt, node);
3201
0
    if (message == NULL) {
3202
  /*
3203
  * Use default messages.
3204
  */
3205
0
  if (type != NULL) {
3206
0
      if (node->type == XML_ATTRIBUTE_NODE)
3207
0
    msg = xmlStrcat(msg, BAD_CAST "'%s' is not a valid value of ");
3208
0
      else
3209
0
    msg = xmlStrcat(msg, BAD_CAST "The character content is not a "
3210
0
    "valid value of ");
3211
0
      if (! xmlSchemaIsGlobalItem(type))
3212
0
    msg = xmlStrcat(msg, BAD_CAST "the local ");
3213
0
      else
3214
0
    msg = xmlStrcat(msg, BAD_CAST "the ");
3215
3216
0
      if (WXS_IS_ATOMIC(type))
3217
0
    msg = xmlStrcat(msg, BAD_CAST "atomic type");
3218
0
      else if (WXS_IS_LIST(type))
3219
0
    msg = xmlStrcat(msg, BAD_CAST "list type");
3220
0
      else if (WXS_IS_UNION(type))
3221
0
    msg = xmlStrcat(msg, BAD_CAST "union type");
3222
3223
0
      if (xmlSchemaIsGlobalItem(type)) {
3224
0
    xmlChar *str = NULL;
3225
0
    msg = xmlStrcat(msg, BAD_CAST " '");
3226
0
    if (type->builtInType != 0) {
3227
0
        msg = xmlStrcat(msg, BAD_CAST "xs:");
3228
0
        str = xmlStrdup(type->name);
3229
0
    } else {
3230
0
        const xmlChar *qName = xmlSchemaFormatQName(&str, type->targetNamespace, type->name);
3231
0
        if (!str)
3232
0
      str = xmlStrdup(qName);
3233
0
    }
3234
0
    msg = xmlStrcat(msg, xmlEscapeFormatString(&str));
3235
0
    msg = xmlStrcat(msg, BAD_CAST "'.");
3236
0
    FREE_AND_NULL(str);
3237
0
      }
3238
0
  } else {
3239
0
      if (node->type == XML_ATTRIBUTE_NODE)
3240
0
    msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not valid.");
3241
0
      else
3242
0
    msg = xmlStrcat(msg, BAD_CAST "The character content is not "
3243
0
    "valid.");
3244
0
  }
3245
0
  if (expected) {
3246
0
      xmlChar *expectedEscaped = xmlCharStrdup(expected);
3247
0
      msg = xmlStrcat(msg, BAD_CAST " Expected is '");
3248
0
      msg = xmlStrcat(msg, xmlEscapeFormatString(&expectedEscaped));
3249
0
      FREE_AND_NULL(expectedEscaped);
3250
0
      msg = xmlStrcat(msg, BAD_CAST "'.\n");
3251
0
  } else
3252
0
      msg = xmlStrcat(msg, BAD_CAST "\n");
3253
0
  if (node->type == XML_ATTRIBUTE_NODE)
3254
0
      xmlSchemaPErr(ctxt, node, error, (const char *) msg, value, NULL);
3255
0
  else
3256
0
      xmlSchemaPErr(ctxt, node, error, (const char *) msg, NULL, NULL);
3257
0
    } else {
3258
0
  msg = xmlStrcat(msg, BAD_CAST message);
3259
0
  msg = xmlStrcat(msg, BAD_CAST ".\n");
3260
0
  xmlSchemaPErrExt(ctxt, node, error, NULL, NULL, NULL,
3261
0
       (const char*) msg, str1, str2, NULL, NULL, NULL);
3262
0
    }
3263
    /* Cleanup. */
3264
0
    FREE_AND_NULL(msg)
3265
0
}
3266
3267
/**
3268
 * xmlSchemaPContentErr:
3269
 * @ctxt: the schema parser context
3270
 * @error: the error code
3271
 * @ownerItem: the owner item of the holder of the content
3272
 * @ownerElem: the node of the holder of the content
3273
 * @child: the invalid child node
3274
 * @message: the optional error message
3275
 * @content: the optional string describing the correct content
3276
 *
3277
 * Reports an error concerning the content of a schema element.
3278
 */
3279
static void
3280
xmlSchemaPContentErr(xmlSchemaParserCtxtPtr ctxt,
3281
         xmlParserErrors error,
3282
         xmlSchemaBasicItemPtr ownerItem,
3283
         xmlNodePtr ownerElem,
3284
         xmlNodePtr child,
3285
         const char *message,
3286
         const char *content)
3287
0
{
3288
0
    xmlChar *des = NULL;
3289
3290
0
    xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem);
3291
0
    if (message != NULL)
3292
0
  xmlSchemaPErr2(ctxt, ownerElem, child, error,
3293
0
      "%s: %s.\n",
3294
0
      BAD_CAST des, BAD_CAST message);
3295
0
    else {
3296
0
  if (content != NULL) {
3297
0
      xmlSchemaPErr2(ctxt, ownerElem, child, error,
3298
0
    "%s: The content is not valid. Expected is %s.\n",
3299
0
    BAD_CAST des, BAD_CAST content);
3300
0
  } else {
3301
0
      xmlSchemaPErr2(ctxt, ownerElem, child, error,
3302
0
    "%s: The content is not valid.\n",
3303
0
    BAD_CAST des, NULL);
3304
0
  }
3305
0
    }
3306
0
    FREE_AND_NULL(des)
3307
0
}
3308
3309
/************************************************************************
3310
 *                  *
3311
 *      Streamable error functions                      *
3312
 *                  *
3313
 ************************************************************************/
3314
3315
3316
3317
3318
/************************************************************************
3319
 *                  *
3320
 *      Validation helper functions     *
3321
 *                  *
3322
 ************************************************************************/
3323
3324
3325
/************************************************************************
3326
 *                  *
3327
 *      Allocation functions        *
3328
 *                  *
3329
 ************************************************************************/
3330
3331
/**
3332
 * xmlSchemaNewSchemaForParserCtxt:
3333
 * @ctxt:  a schema validation context
3334
 *
3335
 * Allocate a new Schema structure.
3336
 *
3337
 * Returns the newly allocated structure or NULL in case or error
3338
 */
3339
static xmlSchemaPtr
3340
xmlSchemaNewSchema(xmlSchemaParserCtxtPtr ctxt)
3341
0
{
3342
0
    xmlSchemaPtr ret;
3343
3344
0
    ret = (xmlSchemaPtr) xmlMalloc(sizeof(xmlSchema));
3345
0
    if (ret == NULL) {
3346
0
        xmlSchemaPErrMemory(ctxt);
3347
0
        return (NULL);
3348
0
    }
3349
0
    memset(ret, 0, sizeof(xmlSchema));
3350
0
    ret->dict = ctxt->dict;
3351
0
    xmlDictReference(ret->dict);
3352
3353
0
    return (ret);
3354
0
}
3355
3356
/**
3357
 * xmlSchemaNewFacet:
3358
 *
3359
 * Allocate a new Facet structure.
3360
 *
3361
 * Returns the newly allocated structure or NULL in case or error
3362
 */
3363
xmlSchemaFacetPtr
3364
xmlSchemaNewFacet(void)
3365
0
{
3366
0
    xmlSchemaFacetPtr ret;
3367
3368
0
    ret = (xmlSchemaFacetPtr) xmlMalloc(sizeof(xmlSchemaFacet));
3369
0
    if (ret == NULL) {
3370
0
        return (NULL);
3371
0
    }
3372
0
    memset(ret, 0, sizeof(xmlSchemaFacet));
3373
3374
0
    return (ret);
3375
0
}
3376
3377
/**
3378
 * xmlSchemaNewAnnot:
3379
 * @ctxt:  a schema validation context
3380
 * @node:  a node
3381
 *
3382
 * Allocate a new annotation structure.
3383
 *
3384
 * Returns the newly allocated structure or NULL in case or error
3385
 */
3386
static xmlSchemaAnnotPtr
3387
xmlSchemaNewAnnot(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node)
3388
0
{
3389
0
    xmlSchemaAnnotPtr ret;
3390
3391
0
    ret = (xmlSchemaAnnotPtr) xmlMalloc(sizeof(xmlSchemaAnnot));
3392
0
    if (ret == NULL) {
3393
0
        xmlSchemaPErrMemory(ctxt);
3394
0
        return (NULL);
3395
0
    }
3396
0
    memset(ret, 0, sizeof(xmlSchemaAnnot));
3397
0
    ret->content = node;
3398
0
    return (ret);
3399
0
}
3400
3401
static xmlSchemaItemListPtr
3402
xmlSchemaItemListCreate(void)
3403
0
{
3404
0
    xmlSchemaItemListPtr ret;
3405
3406
0
    ret = xmlMalloc(sizeof(xmlSchemaItemList));
3407
0
    if (ret == NULL) {
3408
0
  xmlSchemaPErrMemory(NULL);
3409
0
  return (NULL);
3410
0
    }
3411
0
    memset(ret, 0, sizeof(xmlSchemaItemList));
3412
0
    return (ret);
3413
0
}
3414
3415
static void
3416
xmlSchemaItemListClear(xmlSchemaItemListPtr list)
3417
0
{
3418
0
    if (list->items != NULL) {
3419
0
  xmlFree(list->items);
3420
0
  list->items = NULL;
3421
0
    }
3422
0
    list->nbItems = 0;
3423
0
    list->sizeItems = 0;
3424
0
}
3425
3426
static int
3427
xmlSchemaItemListAdd(xmlSchemaItemListPtr list, void *item)
3428
0
{
3429
0
    if (list->sizeItems <= list->nbItems) {
3430
0
        void **tmp;
3431
0
        size_t newSize = list->sizeItems == 0 ? 20 : list->sizeItems * 2;
3432
3433
0
  tmp = (void **) xmlRealloc(list->items, newSize * sizeof(void *));
3434
0
  if (tmp == NULL) {
3435
0
      xmlSchemaPErrMemory(NULL);
3436
0
      return(-1);
3437
0
  }
3438
0
        list->items = tmp;
3439
0
  list->sizeItems = newSize;
3440
0
    }
3441
0
    list->items[list->nbItems++] = item;
3442
0
    return(0);
3443
0
}
3444
3445
static int
3446
xmlSchemaItemListAddSize(xmlSchemaItemListPtr list,
3447
       int initialSize,
3448
       void *item)
3449
0
{
3450
0
    if (list->items == NULL) {
3451
0
  if (initialSize <= 0)
3452
0
      initialSize = 1;
3453
0
  list->items = (void **) xmlMalloc(
3454
0
      initialSize * sizeof(void *));
3455
0
  if (list->items == NULL) {
3456
0
      xmlSchemaPErrMemory(NULL);
3457
0
      return(-1);
3458
0
  }
3459
0
  list->sizeItems = initialSize;
3460
0
    } else if (list->sizeItems <= list->nbItems) {
3461
0
        void **tmp;
3462
3463
0
  list->sizeItems *= 2;
3464
0
  tmp = (void **) xmlRealloc(list->items,
3465
0
      list->sizeItems * sizeof(void *));
3466
0
  if (tmp == NULL) {
3467
0
      xmlSchemaPErrMemory(NULL);
3468
0
      list->sizeItems /= 2;
3469
0
      return(-1);
3470
0
  }
3471
0
        list->items = tmp;
3472
0
    }
3473
0
    list->items[list->nbItems++] = item;
3474
0
    return(0);
3475
0
}
3476
3477
static int
3478
xmlSchemaItemListInsert(xmlSchemaItemListPtr list, void *item, int idx)
3479
0
{
3480
0
    if (list->sizeItems <= list->nbItems) {
3481
0
        void **tmp;
3482
0
        size_t newSize = list->sizeItems == 0 ? 20 : list->sizeItems * 2;
3483
3484
0
  tmp = (void **) xmlRealloc(list->items, newSize * sizeof(void *));
3485
0
  if (tmp == NULL) {
3486
0
      xmlSchemaPErrMemory(NULL);
3487
0
      return(-1);
3488
0
  }
3489
0
        list->items = tmp;
3490
0
  list->sizeItems = newSize;
3491
0
    }
3492
    /*
3493
    * Just append if the index is greater/equal than the item count.
3494
    */
3495
0
    if (idx >= list->nbItems) {
3496
0
  list->items[list->nbItems++] = item;
3497
0
    } else {
3498
0
  int i;
3499
0
  for (i = list->nbItems; i > idx; i--)
3500
0
      list->items[i] = list->items[i-1];
3501
0
  list->items[idx] = item;
3502
0
  list->nbItems++;
3503
0
    }
3504
0
    return(0);
3505
0
}
3506
3507
#if 0 /* enable if ever needed */
3508
static int
3509
xmlSchemaItemListInsertSize(xmlSchemaItemListPtr list,
3510
          int initialSize,
3511
          void *item,
3512
          int idx)
3513
{
3514
    if (list->items == NULL) {
3515
  if (initialSize <= 0)
3516
      initialSize = 1;
3517
  list->items = (void **) xmlMalloc(
3518
      initialSize * sizeof(void *));
3519
  if (list->items == NULL) {
3520
      xmlSchemaPErrMemory(NULL);
3521
      return(-1);
3522
  }
3523
  list->sizeItems = initialSize;
3524
    } else if (list->sizeItems <= list->nbItems) {
3525
  list->sizeItems *= 2;
3526
  list->items = (void **) xmlRealloc(list->items,
3527
      list->sizeItems * sizeof(void *));
3528
  if (list->items == NULL) {
3529
      xmlSchemaPErrMemory(NULL);
3530
      list->sizeItems = 0;
3531
      return(-1);
3532
  }
3533
    }
3534
    /*
3535
    * Just append if the index is greater/equal than the item count.
3536
    */
3537
    if (idx >= list->nbItems) {
3538
  list->items[list->nbItems++] = item;
3539
    } else {
3540
  int i;
3541
  for (i = list->nbItems; i > idx; i--)
3542
      list->items[i] = list->items[i-1];
3543
  list->items[idx] = item;
3544
  list->nbItems++;
3545
    }
3546
    return(0);
3547
}
3548
#endif
3549
3550
static int
3551
xmlSchemaItemListRemove(xmlSchemaItemListPtr list, int idx)
3552
0
{
3553
0
    int i;
3554
0
    if ((list->items == NULL) || (idx >= list->nbItems))
3555
0
  return(-1);
3556
3557
0
    if (list->nbItems == 1) {
3558
  /* TODO: Really free the list? */
3559
0
  xmlFree(list->items);
3560
0
  list->items = NULL;
3561
0
  list->nbItems = 0;
3562
0
  list->sizeItems = 0;
3563
0
    } else if (list->nbItems -1 == idx) {
3564
0
  list->nbItems--;
3565
0
    } else {
3566
0
  for (i = idx; i < list->nbItems -1; i++)
3567
0
      list->items[i] = list->items[i+1];
3568
0
  list->nbItems--;
3569
0
    }
3570
0
    return(0);
3571
0
}
3572
3573
/**
3574
 * xmlSchemaItemListFree:
3575
 * @annot:  a schema type structure
3576
 *
3577
 * Deallocate a annotation structure
3578
 */
3579
static void
3580
xmlSchemaItemListFree(xmlSchemaItemListPtr list)
3581
0
{
3582
0
    if (list == NULL)
3583
0
  return;
3584
0
    if (list->items != NULL)
3585
0
  xmlFree(list->items);
3586
0
    xmlFree(list);
3587
0
}
3588
3589
static void
3590
xmlSchemaBucketFree(xmlSchemaBucketPtr bucket)
3591
0
{
3592
0
    if (bucket == NULL)
3593
0
  return;
3594
0
    if (bucket->globals != NULL) {
3595
0
  xmlSchemaComponentListFree(bucket->globals);
3596
0
  xmlSchemaItemListFree(bucket->globals);
3597
0
    }
3598
0
    if (bucket->locals != NULL) {
3599
0
  xmlSchemaComponentListFree(bucket->locals);
3600
0
  xmlSchemaItemListFree(bucket->locals);
3601
0
    }
3602
0
    if (bucket->relations != NULL) {
3603
0
  xmlSchemaSchemaRelationPtr prev, cur = bucket->relations;
3604
0
  do {
3605
0
      prev = cur;
3606
0
      cur = cur->next;
3607
0
      xmlFree(prev);
3608
0
  } while (cur != NULL);
3609
0
    }
3610
0
    if ((! bucket->preserveDoc) && (bucket->doc != NULL)) {
3611
0
  xmlFreeDoc(bucket->doc);
3612
0
    }
3613
0
    if (bucket->type == XML_SCHEMA_SCHEMA_IMPORT) {
3614
0
  if (WXS_IMPBUCKET(bucket)->schema != NULL)
3615
0
      xmlSchemaFree(WXS_IMPBUCKET(bucket)->schema);
3616
0
    }
3617
0
    xmlFree(bucket);
3618
0
}
3619
3620
static void
3621
xmlSchemaBucketFreeEntry(void *bucket, const xmlChar *name ATTRIBUTE_UNUSED)
3622
0
{
3623
0
    xmlSchemaBucketFree((xmlSchemaBucketPtr) bucket);
3624
0
}
3625
3626
static xmlSchemaBucketPtr
3627
xmlSchemaBucketCreate(xmlSchemaParserCtxtPtr pctxt,
3628
       int type, const xmlChar *targetNamespace)
3629
0
{
3630
0
    xmlSchemaBucketPtr ret;
3631
0
    int size;
3632
0
    xmlSchemaPtr mainSchema;
3633
3634
0
    if (WXS_CONSTRUCTOR(pctxt)->mainSchema == NULL) {
3635
0
  PERROR_INT("xmlSchemaBucketCreate",
3636
0
      "no main schema on constructor");
3637
0
  return(NULL);
3638
0
    }
3639
0
    mainSchema = WXS_CONSTRUCTOR(pctxt)->mainSchema;
3640
    /* Create the schema bucket. */
3641
0
    if (WXS_IS_BUCKET_INCREDEF(type))
3642
0
  size = sizeof(xmlSchemaInclude);
3643
0
    else
3644
0
  size = sizeof(xmlSchemaImport);
3645
0
    ret = (xmlSchemaBucketPtr) xmlMalloc(size);
3646
0
    if (ret == NULL) {
3647
0
  xmlSchemaPErrMemory(NULL);
3648
0
  return(NULL);
3649
0
    }
3650
0
    memset(ret, 0, size);
3651
0
    ret->targetNamespace = targetNamespace;
3652
0
    ret->type = type;
3653
0
    ret->globals = xmlSchemaItemListCreate();
3654
0
    if (ret->globals == NULL) {
3655
0
  xmlSchemaBucketFree(ret);
3656
0
  return(NULL);
3657
0
    }
3658
0
    ret->locals = xmlSchemaItemListCreate();
3659
0
    if (ret->locals == NULL) {
3660
0
  xmlSchemaBucketFree(ret);
3661
0
  return(NULL);
3662
0
    }
3663
    /*
3664
    * The following will assure that only the first bucket is marked as
3665
    * XML_SCHEMA_SCHEMA_MAIN and it points to the *main* schema.
3666
    * For each following import buckets an xmlSchema will be created.
3667
    * An xmlSchema will be created for every distinct targetNamespace.
3668
    * We assign the targetNamespace to the schemata here.
3669
    */
3670
0
    if (! WXS_HAS_BUCKETS(pctxt)) {
3671
0
  if (WXS_IS_BUCKET_INCREDEF(type)) {
3672
0
      PERROR_INT("xmlSchemaBucketCreate",
3673
0
    "first bucket but it's an include or redefine");
3674
0
      xmlSchemaBucketFree(ret);
3675
0
      return(NULL);
3676
0
  }
3677
  /* Force the type to be XML_SCHEMA_SCHEMA_MAIN. */
3678
0
  ret->type = XML_SCHEMA_SCHEMA_MAIN;
3679
  /* Point to the *main* schema. */
3680
0
  WXS_CONSTRUCTOR(pctxt)->mainBucket = ret;
3681
0
  WXS_IMPBUCKET(ret)->schema = mainSchema;
3682
  /*
3683
  * Ensure that the main schema gets a targetNamespace.
3684
  */
3685
0
  mainSchema->targetNamespace = targetNamespace;
3686
0
    } else {
3687
0
  if (type == XML_SCHEMA_SCHEMA_MAIN) {
3688
0
      PERROR_INT("xmlSchemaBucketCreate",
3689
0
    "main bucket but it's not the first one");
3690
0
      xmlSchemaBucketFree(ret);
3691
0
      return(NULL);
3692
0
  } else if (type == XML_SCHEMA_SCHEMA_IMPORT) {
3693
      /*
3694
      * Create a schema for imports and assign the
3695
      * targetNamespace.
3696
      */
3697
0
      WXS_IMPBUCKET(ret)->schema = xmlSchemaNewSchema(pctxt);
3698
0
      if (WXS_IMPBUCKET(ret)->schema == NULL) {
3699
0
    xmlSchemaBucketFree(ret);
3700
0
    return(NULL);
3701
0
      }
3702
0
      WXS_IMPBUCKET(ret)->schema->targetNamespace = targetNamespace;
3703
0
  }
3704
0
    }
3705
0
    if (WXS_IS_BUCKET_IMPMAIN(type)) {
3706
0
  int res;
3707
  /*
3708
  * Imports go into the "schemasImports" slot of the main *schema*.
3709
  * Note that we create an import entry for the main schema as well; i.e.,
3710
  * even if there's only one schema, we'll get an import.
3711
  */
3712
0
  if (mainSchema->schemasImports == NULL) {
3713
0
      mainSchema->schemasImports = xmlHashCreateDict(5,
3714
0
    WXS_CONSTRUCTOR(pctxt)->dict);
3715
0
      if (mainSchema->schemasImports == NULL) {
3716
0
    xmlSchemaBucketFree(ret);
3717
0
    return(NULL);
3718
0
      }
3719
0
  }
3720
0
  if (targetNamespace == NULL)
3721
0
      res = xmlHashAddEntry(mainSchema->schemasImports,
3722
0
    XML_SCHEMAS_NO_NAMESPACE, ret);
3723
0
  else
3724
0
      res = xmlHashAddEntry(mainSchema->schemasImports,
3725
0
    targetNamespace, ret);
3726
0
  if (res != 0) {
3727
0
      PERROR_INT("xmlSchemaBucketCreate",
3728
0
    "failed to add the schema bucket to the hash");
3729
0
      xmlSchemaBucketFree(ret);
3730
0
      return(NULL);
3731
0
  }
3732
0
    } else {
3733
  /* Set the @ownerImport of an include bucket. */
3734
0
  if (WXS_IS_BUCKET_IMPMAIN(WXS_CONSTRUCTOR(pctxt)->bucket->type))
3735
0
      WXS_INCBUCKET(ret)->ownerImport =
3736
0
    WXS_IMPBUCKET(WXS_CONSTRUCTOR(pctxt)->bucket);
3737
0
  else
3738
0
      WXS_INCBUCKET(ret)->ownerImport =
3739
0
    WXS_INCBUCKET(WXS_CONSTRUCTOR(pctxt)->bucket)->ownerImport;
3740
3741
  /* Includes got into the "includes" slot of the *main* schema. */
3742
0
  if (mainSchema->includes == NULL) {
3743
0
      mainSchema->includes = xmlSchemaItemListCreate();
3744
0
      if (mainSchema->includes == NULL) {
3745
0
    xmlSchemaBucketFree(ret);
3746
0
    return(NULL);
3747
0
      }
3748
0
  }
3749
0
  if (xmlSchemaItemListAdd(mainSchema->includes, ret) < 0) {
3750
0
      xmlSchemaBucketFree(ret);
3751
0
      return(NULL);
3752
0
        }
3753
0
    }
3754
    /*
3755
    * Add to list of all buckets; this is used for lookup
3756
    * during schema construction time only.
3757
    */
3758
0
    if (xmlSchemaItemListAdd(WXS_CONSTRUCTOR(pctxt)->buckets, ret) == -1)
3759
0
  return(NULL);
3760
0
    return(ret);
3761
0
}
3762
3763
static int
3764
xmlSchemaAddItemSize(xmlSchemaItemListPtr *list, int initialSize, void *item)
3765
0
{
3766
0
    if (*list == NULL) {
3767
0
  *list = xmlSchemaItemListCreate();
3768
0
  if (*list == NULL)
3769
0
      return(-1);
3770
0
    }
3771
0
    return(xmlSchemaItemListAddSize(*list, initialSize, item));
3772
0
}
3773
3774
/**
3775
 * xmlSchemaFreeAnnot:
3776
 * @annot:  a schema type structure
3777
 *
3778
 * Deallocate a annotation structure
3779
 */
3780
static void
3781
xmlSchemaFreeAnnot(xmlSchemaAnnotPtr annot)
3782
0
{
3783
0
    if (annot == NULL)
3784
0
        return;
3785
0
    if (annot->next == NULL) {
3786
0
  xmlFree(annot);
3787
0
    } else {
3788
0
  xmlSchemaAnnotPtr prev;
3789
3790
0
  do {
3791
0
      prev = annot;
3792
0
      annot = annot->next;
3793
0
      xmlFree(prev);
3794
0
  } while (annot != NULL);
3795
0
    }
3796
0
}
3797
3798
/**
3799
 * xmlSchemaFreeNotation:
3800
 * @schema:  a schema notation structure
3801
 *
3802
 * Deallocate a Schema Notation structure.
3803
 */
3804
static void
3805
xmlSchemaFreeNotation(xmlSchemaNotationPtr nota)
3806
0
{
3807
0
    if (nota == NULL)
3808
0
        return;
3809
0
    if (nota->annot != NULL)
3810
0
  xmlSchemaFreeAnnot(nota->annot);
3811
0
    xmlFree(nota);
3812
0
}
3813
3814
/**
3815
 * xmlSchemaFreeAttribute:
3816
 * @attr:  an attribute declaration
3817
 *
3818
 * Deallocates an attribute declaration structure.
3819
 */
3820
static void
3821
xmlSchemaFreeAttribute(xmlSchemaAttributePtr attr)
3822
0
{
3823
0
    if (attr == NULL)
3824
0
        return;
3825
0
    if (attr->annot != NULL)
3826
0
  xmlSchemaFreeAnnot(attr->annot);
3827
0
    if (attr->defVal != NULL)
3828
0
  xmlSchemaFreeValue(attr->defVal);
3829
0
    xmlFree(attr);
3830
0
}
3831
3832
/**
3833
 * xmlSchemaFreeAttributeUse:
3834
 * @use:  an attribute use
3835
 *
3836
 * Deallocates an attribute use structure.
3837
 */
3838
static void
3839
xmlSchemaFreeAttributeUse(xmlSchemaAttributeUsePtr use)
3840
0
{
3841
0
    if (use == NULL)
3842
0
        return;
3843
0
    if (use->annot != NULL)
3844
0
  xmlSchemaFreeAnnot(use->annot);
3845
0
    if (use->defVal != NULL)
3846
0
  xmlSchemaFreeValue(use->defVal);
3847
0
    xmlFree(use);
3848
0
}
3849
3850
/**
3851
 * xmlSchemaFreeAttributeUseProhib:
3852
 * @prohib:  an attribute use prohibition
3853
 *
3854
 * Deallocates an attribute use structure.
3855
 */
3856
static void
3857
xmlSchemaFreeAttributeUseProhib(xmlSchemaAttributeUseProhibPtr prohib)
3858
0
{
3859
0
    if (prohib == NULL)
3860
0
        return;
3861
0
    xmlFree(prohib);
3862
0
}
3863
3864
/**
3865
 * xmlSchemaFreeWildcardNsSet:
3866
 * set:  a schema wildcard namespace
3867
 *
3868
 * Deallocates a list of wildcard constraint structures.
3869
 */
3870
static void
3871
xmlSchemaFreeWildcardNsSet(xmlSchemaWildcardNsPtr set)
3872
0
{
3873
0
    xmlSchemaWildcardNsPtr next;
3874
3875
0
    while (set != NULL) {
3876
0
  next = set->next;
3877
0
  xmlFree(set);
3878
0
  set = next;
3879
0
    }
3880
0
}
3881
3882
/**
3883
 * xmlSchemaFreeWildcard:
3884
 * @wildcard:  a wildcard structure
3885
 *
3886
 * Deallocates a wildcard structure.
3887
 */
3888
void
3889
xmlSchemaFreeWildcard(xmlSchemaWildcardPtr wildcard)
3890
0
{
3891
0
    if (wildcard == NULL)
3892
0
        return;
3893
0
    if (wildcard->annot != NULL)
3894
0
        xmlSchemaFreeAnnot(wildcard->annot);
3895
0
    if (wildcard->nsSet != NULL)
3896
0
  xmlSchemaFreeWildcardNsSet(wildcard->nsSet);
3897
0
    if (wildcard->negNsSet != NULL)
3898
0
  xmlFree(wildcard->negNsSet);
3899
0
    xmlFree(wildcard);
3900
0
}
3901
3902
/**
3903
 * xmlSchemaFreeAttributeGroup:
3904
 * @schema:  a schema attribute group structure
3905
 *
3906
 * Deallocate a Schema Attribute Group structure.
3907
 */
3908
static void
3909
xmlSchemaFreeAttributeGroup(xmlSchemaAttributeGroupPtr attrGr)
3910
0
{
3911
0
    if (attrGr == NULL)
3912
0
        return;
3913
0
    if (attrGr->annot != NULL)
3914
0
        xmlSchemaFreeAnnot(attrGr->annot);
3915
0
    if (attrGr->attrUses != NULL)
3916
0
  xmlSchemaItemListFree(WXS_LIST_CAST attrGr->attrUses);
3917
0
    xmlFree(attrGr);
3918
0
}
3919
3920
/**
3921
 * xmlSchemaFreeQNameRef:
3922
 * @item: a QName reference structure
3923
 *
3924
 * Deallocatea a QName reference structure.
3925
 */
3926
static void
3927
xmlSchemaFreeQNameRef(xmlSchemaQNameRefPtr item)
3928
0
{
3929
0
    xmlFree(item);
3930
0
}
3931
3932
/**
3933
 * xmlSchemaFreeTypeLinkList:
3934
 * @alink: a type link
3935
 *
3936
 * Deallocate a list of types.
3937
 */
3938
static void
3939
xmlSchemaFreeTypeLinkList(xmlSchemaTypeLinkPtr link)
3940
0
{
3941
0
    xmlSchemaTypeLinkPtr next;
3942
3943
0
    while (link != NULL) {
3944
0
  next = link->next;
3945
0
  xmlFree(link);
3946
0
  link = next;
3947
0
    }
3948
0
}
3949
3950
static void
3951
xmlSchemaFreeIDCStateObjList(xmlSchemaIDCStateObjPtr sto)
3952
0
{
3953
0
    xmlSchemaIDCStateObjPtr next;
3954
0
    while (sto != NULL) {
3955
0
  next = sto->next;
3956
0
  if (sto->history != NULL)
3957
0
      xmlFree(sto->history);
3958
0
  if (sto->xpathCtxt != NULL)
3959
0
      xmlFreeStreamCtxt((xmlStreamCtxtPtr) sto->xpathCtxt);
3960
0
  xmlFree(sto);
3961
0
  sto = next;
3962
0
    }
3963
0
}
3964
3965
/**
3966
 * xmlSchemaFreeIDC:
3967
 * @idc: a identity-constraint definition
3968
 *
3969
 * Deallocates an identity-constraint definition.
3970
 */
3971
static void
3972
xmlSchemaFreeIDC(xmlSchemaIDCPtr idcDef)
3973
0
{
3974
0
    xmlSchemaIDCSelectPtr cur, prev;
3975
3976
0
    if (idcDef == NULL)
3977
0
  return;
3978
0
    if (idcDef->annot != NULL)
3979
0
        xmlSchemaFreeAnnot(idcDef->annot);
3980
    /* Selector */
3981
0
    if (idcDef->selector != NULL) {
3982
0
  if (idcDef->selector->xpathComp != NULL)
3983
0
      xmlFreePattern((xmlPatternPtr) idcDef->selector->xpathComp);
3984
0
  xmlFree(idcDef->selector);
3985
0
    }
3986
    /* Fields */
3987
0
    if (idcDef->fields != NULL) {
3988
0
  cur = idcDef->fields;
3989
0
  do {
3990
0
      prev = cur;
3991
0
      cur = cur->next;
3992
0
      if (prev->xpathComp != NULL)
3993
0
    xmlFreePattern((xmlPatternPtr) prev->xpathComp);
3994
0
      xmlFree(prev);
3995
0
  } while (cur != NULL);
3996
0
    }
3997
0
    xmlFree(idcDef);
3998
0
}
3999
4000
/**
4001
 * xmlSchemaFreeElement:
4002
 * @schema:  a schema element structure
4003
 *
4004
 * Deallocate a Schema Element structure.
4005
 */
4006
static void
4007
xmlSchemaFreeElement(xmlSchemaElementPtr elem)
4008
0
{
4009
0
    if (elem == NULL)
4010
0
        return;
4011
0
    if (elem->annot != NULL)
4012
0
        xmlSchemaFreeAnnot(elem->annot);
4013
0
    if (elem->contModel != NULL)
4014
0
        xmlRegFreeRegexp(elem->contModel);
4015
0
    if (elem->defVal != NULL)
4016
0
  xmlSchemaFreeValue(elem->defVal);
4017
0
    xmlFree(elem);
4018
0
}
4019
4020
/**
4021
 * xmlSchemaFreeFacet:
4022
 * @facet:  a schema facet structure
4023
 *
4024
 * Deallocate a Schema Facet structure.
4025
 */
4026
void
4027
xmlSchemaFreeFacet(xmlSchemaFacetPtr facet)
4028
0
{
4029
0
    if (facet == NULL)
4030
0
        return;
4031
0
    if (facet->val != NULL)
4032
0
        xmlSchemaFreeValue(facet->val);
4033
0
    if (facet->regexp != NULL)
4034
0
        xmlRegFreeRegexp(facet->regexp);
4035
0
    if (facet->annot != NULL)
4036
0
        xmlSchemaFreeAnnot(facet->annot);
4037
0
    xmlFree(facet);
4038
0
}
4039
4040
/**
4041
 * xmlSchemaFreeType:
4042
 * @type:  a schema type structure
4043
 *
4044
 * Deallocate a Schema Type structure.
4045
 */
4046
void
4047
xmlSchemaFreeType(xmlSchemaTypePtr type)
4048
0
{
4049
0
    if (type == NULL)
4050
0
        return;
4051
0
    if (type->annot != NULL)
4052
0
        xmlSchemaFreeAnnot(type->annot);
4053
0
    if (type->facets != NULL) {
4054
0
        xmlSchemaFacetPtr facet, next;
4055
4056
0
        facet = type->facets;
4057
0
        while (facet != NULL) {
4058
0
            next = facet->next;
4059
0
            xmlSchemaFreeFacet(facet);
4060
0
            facet = next;
4061
0
        }
4062
0
    }
4063
0
    if (type->attrUses != NULL)
4064
0
  xmlSchemaItemListFree((xmlSchemaItemListPtr) type->attrUses);
4065
0
    if (type->memberTypes != NULL)
4066
0
  xmlSchemaFreeTypeLinkList(type->memberTypes);
4067
0
    if (type->facetSet != NULL) {
4068
0
  xmlSchemaFacetLinkPtr next, link;
4069
4070
0
  link = type->facetSet;
4071
0
  do {
4072
0
      next = link->next;
4073
0
      xmlFree(link);
4074
0
      link = next;
4075
0
  } while (link != NULL);
4076
0
    }
4077
0
    if (type->contModel != NULL)
4078
0
        xmlRegFreeRegexp(type->contModel);
4079
0
    xmlFree(type);
4080
0
}
4081
4082
/**
4083
 * xmlSchemaFreeModelGroupDef:
4084
 * @item:  a schema model group definition
4085
 *
4086
 * Deallocates a schema model group definition.
4087
 */
4088
static void
4089
xmlSchemaFreeModelGroupDef(xmlSchemaModelGroupDefPtr item)
4090
0
{
4091
0
    if (item->annot != NULL)
4092
0
  xmlSchemaFreeAnnot(item->annot);
4093
0
    xmlFree(item);
4094
0
}
4095
4096
/**
4097
 * xmlSchemaFreeModelGroup:
4098
 * @item:  a schema model group
4099
 *
4100
 * Deallocates a schema model group structure.
4101
 */
4102
static void
4103
xmlSchemaFreeModelGroup(xmlSchemaModelGroupPtr item)
4104
0
{
4105
0
    if (item->annot != NULL)
4106
0
  xmlSchemaFreeAnnot(item->annot);
4107
0
    xmlFree(item);
4108
0
}
4109
4110
static void
4111
xmlSchemaComponentListFree(xmlSchemaItemListPtr list)
4112
0
{
4113
0
    if ((list == NULL) || (list->nbItems == 0))
4114
0
  return;
4115
0
    {
4116
0
  xmlSchemaTreeItemPtr item;
4117
0
  xmlSchemaTreeItemPtr *items = (xmlSchemaTreeItemPtr *) list->items;
4118
0
  int i;
4119
4120
0
  for (i = 0; i < list->nbItems; i++) {
4121
0
      item = items[i];
4122
0
      if (item == NULL)
4123
0
    continue;
4124
0
      switch (item->type) {
4125
0
    case XML_SCHEMA_TYPE_SIMPLE:
4126
0
    case XML_SCHEMA_TYPE_COMPLEX:
4127
0
        xmlSchemaFreeType((xmlSchemaTypePtr) item);
4128
0
        break;
4129
0
    case XML_SCHEMA_TYPE_ATTRIBUTE:
4130
0
        xmlSchemaFreeAttribute((xmlSchemaAttributePtr) item);
4131
0
        break;
4132
0
    case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
4133
0
        xmlSchemaFreeAttributeUse((xmlSchemaAttributeUsePtr) item);
4134
0
        break;
4135
0
    case XML_SCHEMA_EXTRA_ATTR_USE_PROHIB:
4136
0
        xmlSchemaFreeAttributeUseProhib(
4137
0
      (xmlSchemaAttributeUseProhibPtr) item);
4138
0
        break;
4139
0
    case XML_SCHEMA_TYPE_ELEMENT:
4140
0
        xmlSchemaFreeElement((xmlSchemaElementPtr) item);
4141
0
        break;
4142
0
    case XML_SCHEMA_TYPE_PARTICLE:
4143
0
        if (item->annot != NULL)
4144
0
      xmlSchemaFreeAnnot(item->annot);
4145
0
        xmlFree(item);
4146
0
        break;
4147
0
    case XML_SCHEMA_TYPE_SEQUENCE:
4148
0
    case XML_SCHEMA_TYPE_CHOICE:
4149
0
    case XML_SCHEMA_TYPE_ALL:
4150
0
        xmlSchemaFreeModelGroup((xmlSchemaModelGroupPtr) item);
4151
0
        break;
4152
0
    case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
4153
0
        xmlSchemaFreeAttributeGroup(
4154
0
      (xmlSchemaAttributeGroupPtr) item);
4155
0
        break;
4156
0
    case XML_SCHEMA_TYPE_GROUP:
4157
0
        xmlSchemaFreeModelGroupDef(
4158
0
      (xmlSchemaModelGroupDefPtr) item);
4159
0
        break;
4160
0
    case XML_SCHEMA_TYPE_ANY:
4161
0
    case XML_SCHEMA_TYPE_ANY_ATTRIBUTE:
4162
0
        xmlSchemaFreeWildcard((xmlSchemaWildcardPtr) item);
4163
0
        break;
4164
0
    case XML_SCHEMA_TYPE_IDC_KEY:
4165
0
    case XML_SCHEMA_TYPE_IDC_UNIQUE:
4166
0
    case XML_SCHEMA_TYPE_IDC_KEYREF:
4167
0
        xmlSchemaFreeIDC((xmlSchemaIDCPtr) item);
4168
0
        break;
4169
0
    case XML_SCHEMA_TYPE_NOTATION:
4170
0
        xmlSchemaFreeNotation((xmlSchemaNotationPtr) item);
4171
0
        break;
4172
0
    case XML_SCHEMA_EXTRA_QNAMEREF:
4173
0
        xmlSchemaFreeQNameRef((xmlSchemaQNameRefPtr) item);
4174
0
        break;
4175
0
    default:
4176
        /* TODO: This should never be hit. */
4177
0
        break;
4178
0
      }
4179
0
  }
4180
0
  list->nbItems = 0;
4181
0
    }
4182
0
}
4183
4184
/**
4185
 * xmlSchemaFree:
4186
 * @schema:  a schema structure
4187
 *
4188
 * Deallocate a Schema structure.
4189
 */
4190
void
4191
xmlSchemaFree(xmlSchemaPtr schema)
4192
0
{
4193
0
    if (schema == NULL)
4194
0
        return;
4195
    /*
4196
    * Note that those slots are not responsible for freeing
4197
    * schema components anymore; this will now be done by
4198
    * the schema buckets.
4199
    */
4200
0
    if (schema->notaDecl != NULL)
4201
0
        xmlHashFree(schema->notaDecl, NULL);
4202
0
    if (schema->attrDecl != NULL)
4203
0
        xmlHashFree(schema->attrDecl, NULL);
4204
0
    if (schema->attrgrpDecl != NULL)
4205
0
        xmlHashFree(schema->attrgrpDecl, NULL);
4206
0
    if (schema->elemDecl != NULL)
4207
0
        xmlHashFree(schema->elemDecl, NULL);
4208
0
    if (schema->typeDecl != NULL)
4209
0
        xmlHashFree(schema->typeDecl, NULL);
4210
0
    if (schema->groupDecl != NULL)
4211
0
        xmlHashFree(schema->groupDecl, NULL);
4212
0
    if (schema->idcDef != NULL)
4213
0
        xmlHashFree(schema->idcDef, NULL);
4214
4215
0
    if (schema->schemasImports != NULL)
4216
0
  xmlHashFree(schema->schemasImports, xmlSchemaBucketFreeEntry);
4217
0
    if (schema->includes != NULL) {
4218
0
  xmlSchemaItemListPtr list = (xmlSchemaItemListPtr) schema->includes;
4219
0
  int i;
4220
0
  for (i = 0; i < list->nbItems; i++) {
4221
0
      xmlSchemaBucketFree((xmlSchemaBucketPtr) list->items[i]);
4222
0
  }
4223
0
  xmlSchemaItemListFree(list);
4224
0
    }
4225
0
    if (schema->annot != NULL)
4226
0
        xmlSchemaFreeAnnot(schema->annot);
4227
    /* Never free the doc here, since this will be done by the buckets. */
4228
4229
0
    xmlDictFree(schema->dict);
4230
0
    xmlFree(schema);
4231
0
}
4232
4233
/************************************************************************
4234
 *                  *
4235
 *      Debug functions         *
4236
 *                  *
4237
 ************************************************************************/
4238
4239
#ifdef LIBXML_OUTPUT_ENABLED
4240
4241
static void
4242
xmlSchemaTypeDump(xmlSchemaTypePtr type, FILE * output); /* forward */
4243
4244
/**
4245
 * xmlSchemaElementDump:
4246
 * @elem:  an element
4247
 * @output:  the file output
4248
 *
4249
 * Dump the element
4250
 */
4251
static void
4252
xmlSchemaElementDump(void *payload, void *data,
4253
                     const xmlChar * name ATTRIBUTE_UNUSED,
4254
         const xmlChar * namespace ATTRIBUTE_UNUSED,
4255
                     const xmlChar * context ATTRIBUTE_UNUSED)
4256
0
{
4257
0
    xmlSchemaElementPtr elem = (xmlSchemaElementPtr) payload;
4258
0
    FILE *output = (FILE *) data;
4259
0
    if (elem == NULL)
4260
0
        return;
4261
4262
4263
0
    fprintf(output, "Element");
4264
0
    if (elem->flags & XML_SCHEMAS_ELEM_GLOBAL)
4265
0
  fprintf(output, " (global)");
4266
0
    fprintf(output, ": '%s' ", elem->name);
4267
0
    if (namespace != NULL)
4268
0
  fprintf(output, "ns '%s'", namespace);
4269
0
    fprintf(output, "\n");
4270
#if 0
4271
    if ((elem->minOccurs != 1) || (elem->maxOccurs != 1)) {
4272
  fprintf(output, "  min %d ", elem->minOccurs);
4273
        if (elem->maxOccurs >= UNBOUNDED)
4274
            fprintf(output, "max: unbounded\n");
4275
        else if (elem->maxOccurs != 1)
4276
            fprintf(output, "max: %d\n", elem->maxOccurs);
4277
        else
4278
            fprintf(output, "\n");
4279
    }
4280
#endif
4281
    /*
4282
    * Misc other properties.
4283
    */
4284
0
    if ((elem->flags & XML_SCHEMAS_ELEM_NILLABLE) ||
4285
0
  (elem->flags & XML_SCHEMAS_ELEM_ABSTRACT) ||
4286
0
  (elem->flags & XML_SCHEMAS_ELEM_FIXED) ||
4287
0
  (elem->flags & XML_SCHEMAS_ELEM_DEFAULT)) {
4288
0
  fprintf(output, "  props: ");
4289
0
  if (elem->flags & XML_SCHEMAS_ELEM_FIXED)
4290
0
      fprintf(output, "[fixed] ");
4291
0
  if (elem->flags & XML_SCHEMAS_ELEM_DEFAULT)
4292
0
      fprintf(output, "[default] ");
4293
0
  if (elem->flags & XML_SCHEMAS_ELEM_ABSTRACT)
4294
0
      fprintf(output, "[abstract] ");
4295
0
  if (elem->flags & XML_SCHEMAS_ELEM_NILLABLE)
4296
0
      fprintf(output, "[nillable] ");
4297
0
  fprintf(output, "\n");
4298
0
    }
4299
    /*
4300
    * Default/fixed value.
4301
    */
4302
0
    if (elem->value != NULL)
4303
0
  fprintf(output, "  value: '%s'\n", elem->value);
4304
    /*
4305
    * Type.
4306
    */
4307
0
    if (elem->namedType != NULL) {
4308
0
  fprintf(output, "  type: '%s' ", elem->namedType);
4309
0
  if (elem->namedTypeNs != NULL)
4310
0
      fprintf(output, "ns '%s'\n", elem->namedTypeNs);
4311
0
  else
4312
0
      fprintf(output, "\n");
4313
0
    } else if (elem->subtypes != NULL) {
4314
  /*
4315
  * Dump local types.
4316
  */
4317
0
  xmlSchemaTypeDump(elem->subtypes, output);
4318
0
    }
4319
    /*
4320
    * Substitution group.
4321
    */
4322
0
    if (elem->substGroup != NULL) {
4323
0
  fprintf(output, "  substitutionGroup: '%s' ", elem->substGroup);
4324
0
  if (elem->substGroupNs != NULL)
4325
0
      fprintf(output, "ns '%s'\n", elem->substGroupNs);
4326
0
  else
4327
0
      fprintf(output, "\n");
4328
0
    }
4329
0
}
4330
4331
/**
4332
 * xmlSchemaAnnotDump:
4333
 * @output:  the file output
4334
 * @annot:  a annotation
4335
 *
4336
 * Dump the annotation
4337
 */
4338
static void
4339
xmlSchemaAnnotDump(FILE * output, xmlSchemaAnnotPtr annot)
4340
0
{
4341
0
    xmlChar *content;
4342
4343
0
    if (annot == NULL)
4344
0
        return;
4345
4346
0
    content = xmlNodeGetContent(annot->content);
4347
0
    if (content != NULL) {
4348
0
        fprintf(output, "  Annot: %s\n", content);
4349
0
        xmlFree(content);
4350
0
    } else
4351
0
        fprintf(output, "  Annot: empty\n");
4352
0
}
4353
4354
/**
4355
 * xmlSchemaContentModelDump:
4356
 * @particle: the schema particle
4357
 * @output: the file output
4358
 * @depth: the depth used for indentation
4359
 *
4360
 * Dump a SchemaType structure
4361
 */
4362
static void
4363
xmlSchemaContentModelDump(xmlSchemaParticlePtr particle, FILE * output, int depth)
4364
0
{
4365
0
    xmlChar *str = NULL;
4366
0
    xmlSchemaTreeItemPtr term;
4367
0
    char shift[100];
4368
0
    int i;
4369
4370
0
    if (particle == NULL)
4371
0
  return;
4372
0
    for (i = 0;((i < depth) && (i < 25));i++)
4373
0
        shift[2 * i] = shift[2 * i + 1] = ' ';
4374
0
    shift[2 * i] = shift[2 * i + 1] = 0;
4375
0
    fprintf(output, "%s", shift);
4376
0
    if (particle->children == NULL) {
4377
0
  fprintf(output, "MISSING particle term\n");
4378
0
  return;
4379
0
    }
4380
0
    term = particle->children;
4381
0
    if (term == NULL) {
4382
0
  fprintf(output, "(NULL)");
4383
0
    } else {
4384
0
  switch (term->type) {
4385
0
      case XML_SCHEMA_TYPE_ELEMENT:
4386
0
    fprintf(output, "ELEM '%s'", xmlSchemaFormatQName(&str,
4387
0
        ((xmlSchemaElementPtr)term)->targetNamespace,
4388
0
        ((xmlSchemaElementPtr)term)->name));
4389
0
    FREE_AND_NULL(str);
4390
0
    break;
4391
0
      case XML_SCHEMA_TYPE_SEQUENCE:
4392
0
    fprintf(output, "SEQUENCE");
4393
0
    break;
4394
0
      case XML_SCHEMA_TYPE_CHOICE:
4395
0
    fprintf(output, "CHOICE");
4396
0
    break;
4397
0
      case XML_SCHEMA_TYPE_ALL:
4398
0
    fprintf(output, "ALL");
4399
0
    break;
4400
0
      case XML_SCHEMA_TYPE_ANY:
4401
0
    fprintf(output, "ANY");
4402
0
    break;
4403
0
      default:
4404
0
    fprintf(output, "UNKNOWN\n");
4405
0
    return;
4406
0
  }
4407
0
    }
4408
0
    if (particle->minOccurs != 1)
4409
0
  fprintf(output, " min: %d", particle->minOccurs);
4410
0
    if (particle->maxOccurs >= UNBOUNDED)
4411
0
  fprintf(output, " max: unbounded");
4412
0
    else if (particle->maxOccurs != 1)
4413
0
  fprintf(output, " max: %d", particle->maxOccurs);
4414
0
    fprintf(output, "\n");
4415
0
    if (term &&
4416
0
  ((term->type == XML_SCHEMA_TYPE_SEQUENCE) ||
4417
0
   (term->type == XML_SCHEMA_TYPE_CHOICE) ||
4418
0
   (term->type == XML_SCHEMA_TYPE_ALL)) &&
4419
0
   (term->children != NULL)) {
4420
0
  xmlSchemaContentModelDump((xmlSchemaParticlePtr) term->children,
4421
0
      output, depth +1);
4422
0
    }
4423
0
    if (particle->next != NULL)
4424
0
  xmlSchemaContentModelDump((xmlSchemaParticlePtr) particle->next,
4425
0
    output, depth);
4426
0
}
4427
4428
/**
4429
 * xmlSchemaAttrUsesDump:
4430
 * @uses:  attribute uses list
4431
 * @output:  the file output
4432
 *
4433
 * Dumps a list of attribute use components.
4434
 */
4435
static void
4436
xmlSchemaAttrUsesDump(xmlSchemaItemListPtr uses, FILE * output)
4437
0
{
4438
0
    xmlSchemaAttributeUsePtr use;
4439
0
    xmlSchemaAttributeUseProhibPtr prohib;
4440
0
    xmlSchemaQNameRefPtr ref;
4441
0
    const xmlChar *name, *tns;
4442
0
    xmlChar *str = NULL;
4443
0
    int i;
4444
4445
0
    if ((uses == NULL) || (uses->nbItems == 0))
4446
0
        return;
4447
4448
0
    fprintf(output, "  attributes:\n");
4449
0
    for (i = 0; i < uses->nbItems; i++) {
4450
0
  use = uses->items[i];
4451
0
  if (use->type == XML_SCHEMA_EXTRA_ATTR_USE_PROHIB) {
4452
0
      fprintf(output, "  [prohibition] ");
4453
0
      prohib = (xmlSchemaAttributeUseProhibPtr) use;
4454
0
      name = prohib->name;
4455
0
      tns = prohib->targetNamespace;
4456
0
  } else if (use->type == XML_SCHEMA_EXTRA_QNAMEREF) {
4457
0
      fprintf(output, "  [reference] ");
4458
0
      ref = (xmlSchemaQNameRefPtr) use;
4459
0
      name = ref->name;
4460
0
      tns = ref->targetNamespace;
4461
0
  } else {
4462
0
      fprintf(output, "  [use] ");
4463
0
      name = WXS_ATTRUSE_DECL_NAME(use);
4464
0
      tns = WXS_ATTRUSE_DECL_TNS(use);
4465
0
  }
4466
0
  fprintf(output, "'%s'\n",
4467
0
      (const char *) xmlSchemaFormatQName(&str, tns, name));
4468
0
  FREE_AND_NULL(str);
4469
0
    }
4470
0
}
4471
4472
/**
4473
 * xmlSchemaTypeDump:
4474
 * @output:  the file output
4475
 * @type:  a type structure
4476
 *
4477
 * Dump a SchemaType structure
4478
 */
4479
static void
4480
xmlSchemaTypeDump(xmlSchemaTypePtr type, FILE * output)
4481
0
{
4482
0
    if (type == NULL) {
4483
0
        fprintf(output, "Type: NULL\n");
4484
0
        return;
4485
0
    }
4486
0
    fprintf(output, "Type: ");
4487
0
    if (type->name != NULL)
4488
0
        fprintf(output, "'%s' ", type->name);
4489
0
    else
4490
0
        fprintf(output, "(no name) ");
4491
0
    if (type->targetNamespace != NULL)
4492
0
  fprintf(output, "ns '%s' ", type->targetNamespace);
4493
0
    switch (type->type) {
4494
0
        case XML_SCHEMA_TYPE_BASIC:
4495
0
            fprintf(output, "[basic] ");
4496
0
            break;
4497
0
        case XML_SCHEMA_TYPE_SIMPLE:
4498
0
            fprintf(output, "[simple] ");
4499
0
            break;
4500
0
        case XML_SCHEMA_TYPE_COMPLEX:
4501
0
            fprintf(output, "[complex] ");
4502
0
            break;
4503
0
        case XML_SCHEMA_TYPE_SEQUENCE:
4504
0
            fprintf(output, "[sequence] ");
4505
0
            break;
4506
0
        case XML_SCHEMA_TYPE_CHOICE:
4507
0
            fprintf(output, "[choice] ");
4508
0
            break;
4509
0
        case XML_SCHEMA_TYPE_ALL:
4510
0
            fprintf(output, "[all] ");
4511
0
            break;
4512
0
        case XML_SCHEMA_TYPE_UR:
4513
0
            fprintf(output, "[ur] ");
4514
0
            break;
4515
0
        case XML_SCHEMA_TYPE_RESTRICTION:
4516
0
            fprintf(output, "[restriction] ");
4517
0
            break;
4518
0
        case XML_SCHEMA_TYPE_EXTENSION:
4519
0
            fprintf(output, "[extension] ");
4520
0
            break;
4521
0
        default:
4522
0
            fprintf(output, "[unknown type %d] ", type->type);
4523
0
            break;
4524
0
    }
4525
0
    fprintf(output, "content: ");
4526
0
    switch (type->contentType) {
4527
0
        case XML_SCHEMA_CONTENT_UNKNOWN:
4528
0
            fprintf(output, "[unknown] ");
4529
0
            break;
4530
0
        case XML_SCHEMA_CONTENT_EMPTY:
4531
0
            fprintf(output, "[empty] ");
4532
0
            break;
4533
0
        case XML_SCHEMA_CONTENT_ELEMENTS:
4534
0
            fprintf(output, "[element] ");
4535
0
            break;
4536
0
        case XML_SCHEMA_CONTENT_MIXED:
4537
0
            fprintf(output, "[mixed] ");
4538
0
            break;
4539
0
        case XML_SCHEMA_CONTENT_MIXED_OR_ELEMENTS:
4540
  /* not used. */
4541
0
            break;
4542
0
        case XML_SCHEMA_CONTENT_BASIC:
4543
0
            fprintf(output, "[basic] ");
4544
0
            break;
4545
0
        case XML_SCHEMA_CONTENT_SIMPLE:
4546
0
            fprintf(output, "[simple] ");
4547
0
            break;
4548
0
        case XML_SCHEMA_CONTENT_ANY:
4549
0
            fprintf(output, "[any] ");
4550
0
            break;
4551
0
    }
4552
0
    fprintf(output, "\n");
4553
0
    if (type->base != NULL) {
4554
0
        fprintf(output, "  base type: '%s'", type->base);
4555
0
  if (type->baseNs != NULL)
4556
0
      fprintf(output, " ns '%s'\n", type->baseNs);
4557
0
  else
4558
0
      fprintf(output, "\n");
4559
0
    }
4560
0
    if (type->attrUses != NULL)
4561
0
  xmlSchemaAttrUsesDump(type->attrUses, output);
4562
0
    if (type->annot != NULL)
4563
0
        xmlSchemaAnnotDump(output, type->annot);
4564
0
#ifdef DUMP_CONTENT_MODEL
4565
0
    if ((type->type == XML_SCHEMA_TYPE_COMPLEX) &&
4566
0
  (type->subtypes != NULL)) {
4567
0
  xmlSchemaContentModelDump((xmlSchemaParticlePtr) type->subtypes,
4568
0
      output, 1);
4569
0
    }
4570
0
#endif
4571
0
}
4572
4573
static void
4574
xmlSchemaTypeDumpEntry(void *type, void *output,
4575
                       const xmlChar *name ATTRIBUTE_UNUSED)
4576
0
{
4577
0
    xmlSchemaTypeDump((xmlSchemaTypePtr) type, (FILE *) output);
4578
0
}
4579
4580
/**
4581
 * xmlSchemaDump:
4582
 * @output:  the file output
4583
 * @schema:  a schema structure
4584
 *
4585
 * Dump a Schema structure.
4586
 */
4587
void
4588
xmlSchemaDump(FILE * output, xmlSchemaPtr schema)
4589
0
{
4590
0
    if (output == NULL)
4591
0
        return;
4592
0
    if (schema == NULL) {
4593
0
        fprintf(output, "Schemas: NULL\n");
4594
0
        return;
4595
0
    }
4596
0
    fprintf(output, "Schemas: ");
4597
0
    if (schema->name != NULL)
4598
0
        fprintf(output, "%s, ", schema->name);
4599
0
    else
4600
0
        fprintf(output, "no name, ");
4601
0
    if (schema->targetNamespace != NULL)
4602
0
        fprintf(output, "%s", (const char *) schema->targetNamespace);
4603
0
    else
4604
0
        fprintf(output, "no target namespace");
4605
0
    fprintf(output, "\n");
4606
0
    if (schema->annot != NULL)
4607
0
        xmlSchemaAnnotDump(output, schema->annot);
4608
0
    xmlHashScan(schema->typeDecl, xmlSchemaTypeDumpEntry, output);
4609
0
    xmlHashScanFull(schema->elemDecl, xmlSchemaElementDump, output);
4610
0
}
4611
4612
#endif /* LIBXML_OUTPUT_ENABLED */
4613
4614
/************************************************************************
4615
 *                  *
4616
 *      Utilities         *
4617
 *                  *
4618
 ************************************************************************/
4619
4620
/**
4621
 * xmlSchemaGetPropNode:
4622
 * @node: the element node
4623
 * @name: the name of the attribute
4624
 *
4625
 * Seeks an attribute with a name of @name in
4626
 * no namespace.
4627
 *
4628
 * Returns the attribute or NULL if not present.
4629
 */
4630
static xmlAttrPtr
4631
xmlSchemaGetPropNode(xmlNodePtr node, const char *name)
4632
0
{
4633
0
    xmlAttrPtr prop;
4634
4635
0
    if ((node == NULL) || (name == NULL))
4636
0
  return(NULL);
4637
0
    prop = node->properties;
4638
0
    while (prop != NULL) {
4639
0
        if ((prop->ns == NULL) && xmlStrEqual(prop->name, BAD_CAST name))
4640
0
      return(prop);
4641
0
  prop = prop->next;
4642
0
    }
4643
0
    return (NULL);
4644
0
}
4645
4646
/**
4647
 * xmlSchemaGetPropNodeNs:
4648
 * @node: the element node
4649
 * @uri: the uri
4650
 * @name: the name of the attribute
4651
 *
4652
 * Seeks an attribute with a local name of @name and
4653
 * a namespace URI of @uri.
4654
 *
4655
 * Returns the attribute or NULL if not present.
4656
 */
4657
static xmlAttrPtr
4658
xmlSchemaGetPropNodeNs(xmlNodePtr node, const char *uri, const char *name)
4659
0
{
4660
0
    xmlAttrPtr prop;
4661
4662
0
    if ((node == NULL) || (name == NULL))
4663
0
  return(NULL);
4664
0
    prop = node->properties;
4665
0
    while (prop != NULL) {
4666
0
  if ((prop->ns != NULL) &&
4667
0
      xmlStrEqual(prop->name, BAD_CAST name) &&
4668
0
      xmlStrEqual(prop->ns->href, BAD_CAST uri))
4669
0
      return(prop);
4670
0
  prop = prop->next;
4671
0
    }
4672
0
    return (NULL);
4673
0
}
4674
4675
static const xmlChar *
4676
xmlSchemaGetNodeContent(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node)
4677
0
{
4678
0
    xmlChar *val;
4679
0
    const xmlChar *ret;
4680
4681
0
    val = xmlNodeGetContent(node);
4682
0
    if (val == NULL)
4683
0
  val = xmlStrdup((xmlChar *)"");
4684
0
    ret = xmlDictLookup(ctxt->dict, val, -1);
4685
0
    xmlFree(val);
4686
0
    if (ret == NULL)
4687
0
        xmlSchemaPErrMemory(ctxt);
4688
0
    return(ret);
4689
0
}
4690
4691
static const xmlChar *
4692
xmlSchemaGetNodeContentNoDict(xmlNodePtr node)
4693
0
{
4694
0
    return((const xmlChar*) xmlNodeGetContent(node));
4695
0
}
4696
4697
/**
4698
 * xmlSchemaGetProp:
4699
 * @ctxt: the parser context
4700
 * @node: the node
4701
 * @name: the property name
4702
 *
4703
 * Read a attribute value and internalize the string
4704
 *
4705
 * Returns the string or NULL if not present.
4706
 */
4707
static const xmlChar *
4708
xmlSchemaGetProp(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node,
4709
                 const char *name)
4710
0
{
4711
0
    xmlChar *val;
4712
0
    const xmlChar *ret;
4713
4714
0
    val = xmlGetNoNsProp(node, BAD_CAST name);
4715
0
    if (val == NULL)
4716
0
        return(NULL);
4717
0
    ret = xmlDictLookup(ctxt->dict, val, -1);
4718
0
    xmlFree(val);
4719
0
    return(ret);
4720
0
}
4721
4722
/************************************************************************
4723
 *                  *
4724
 *      Parsing functions       *
4725
 *                  *
4726
 ************************************************************************/
4727
4728
#define WXS_FIND_GLOBAL_ITEM(slot)      \
4729
0
    if (xmlStrEqual(nsName, schema->targetNamespace)) { \
4730
0
  ret = xmlHashLookup(schema->slot, name); \
4731
0
  if (ret != NULL) goto exit; \
4732
0
    } \
4733
0
    if (xmlHashSize(schema->schemasImports) > 1) { \
4734
0
  xmlSchemaImportPtr import; \
4735
0
  if (nsName == NULL) \
4736
0
      import = xmlHashLookup(schema->schemasImports, \
4737
0
    XML_SCHEMAS_NO_NAMESPACE); \
4738
0
  else \
4739
0
      import = xmlHashLookup(schema->schemasImports, nsName); \
4740
0
  if (import == NULL) \
4741
0
      goto exit; \
4742
0
  ret = xmlHashLookup(import->schema->slot, name); \
4743
0
    }
4744
4745
/**
4746
 * xmlSchemaGetElem:
4747
 * @schema:  the schema context
4748
 * @name:  the element name
4749
 * @ns:  the element namespace
4750
 *
4751
 * Lookup a global element declaration in the schema.
4752
 *
4753
 * Returns the element declaration or NULL if not found.
4754
 */
4755
static xmlSchemaElementPtr
4756
xmlSchemaGetElem(xmlSchemaPtr schema, const xmlChar * name,
4757
                 const xmlChar * nsName)
4758
0
{
4759
0
    xmlSchemaElementPtr ret = NULL;
4760
4761
0
    if ((name == NULL) || (schema == NULL))
4762
0
        return(NULL);
4763
0
    if (schema != NULL) {
4764
0
  WXS_FIND_GLOBAL_ITEM(elemDecl)
4765
0
    }
4766
0
exit:
4767
0
    return (ret);
4768
0
}
4769
4770
/**
4771
 * xmlSchemaGetType:
4772
 * @schema:  the main schema
4773
 * @name:  the type's name
4774
 * nsName:  the type's namespace
4775
 *
4776
 * Lookup a type in the schemas or the predefined types
4777
 *
4778
 * Returns the group definition or NULL if not found.
4779
 */
4780
static xmlSchemaTypePtr
4781
xmlSchemaGetType(xmlSchemaPtr schema, const xmlChar * name,
4782
                 const xmlChar * nsName)
4783
0
{
4784
0
    xmlSchemaTypePtr ret = NULL;
4785
4786
0
    if (name == NULL)
4787
0
        return (NULL);
4788
    /* First try the built-in types. */
4789
0
    if ((nsName != NULL) && xmlStrEqual(nsName, xmlSchemaNs)) {
4790
0
  ret = xmlSchemaGetPredefinedType(name, nsName);
4791
0
  if (ret != NULL)
4792
0
      goto exit;
4793
  /*
4794
  * Note that we try the parsed schemas as well here
4795
  * since one might have parsed the S4S, which contain more
4796
  * than the built-in types.
4797
  * TODO: Can we optimize this?
4798
  */
4799
0
    }
4800
0
    if (schema != NULL) {
4801
0
  WXS_FIND_GLOBAL_ITEM(typeDecl)
4802
0
    }
4803
0
exit:
4804
4805
0
    return (ret);
4806
0
}
4807
4808
/**
4809
 * xmlSchemaGetAttributeDecl:
4810
 * @schema:  the context of the schema
4811
 * @name:  the name of the attribute
4812
 * @ns:  the target namespace of the attribute
4813
 *
4814
 * Lookup a an attribute in the schema or imported schemas
4815
 *
4816
 * Returns the attribute declaration or NULL if not found.
4817
 */
4818
static xmlSchemaAttributePtr
4819
xmlSchemaGetAttributeDecl(xmlSchemaPtr schema, const xmlChar * name,
4820
                 const xmlChar * nsName)
4821
0
{
4822
0
    xmlSchemaAttributePtr ret = NULL;
4823
4824
0
    if ((name == NULL) || (schema == NULL))
4825
0
        return (NULL);
4826
0
    if (schema != NULL) {
4827
0
  WXS_FIND_GLOBAL_ITEM(attrDecl)
4828
0
    }
4829
0
exit:
4830
0
    return (ret);
4831
0
}
4832
4833
/**
4834
 * xmlSchemaGetAttributeGroup:
4835
 * @schema:  the context of the schema
4836
 * @name:  the name of the attribute group
4837
 * @ns:  the target namespace of the attribute group
4838
 *
4839
 * Lookup a an attribute group in the schema or imported schemas
4840
 *
4841
 * Returns the attribute group definition or NULL if not found.
4842
 */
4843
static xmlSchemaAttributeGroupPtr
4844
xmlSchemaGetAttributeGroup(xmlSchemaPtr schema, const xmlChar * name,
4845
                 const xmlChar * nsName)
4846
0
{
4847
0
    xmlSchemaAttributeGroupPtr ret = NULL;
4848
4849
0
    if ((name == NULL) || (schema == NULL))
4850
0
        return (NULL);
4851
0
    if (schema != NULL) {
4852
0
  WXS_FIND_GLOBAL_ITEM(attrgrpDecl)
4853
0
    }
4854
0
exit:
4855
    /* TODO:
4856
    if ((ret != NULL) && (ret->redef != NULL)) {
4857
  * Return the last redefinition. *
4858
  ret = ret->redef;
4859
    }
4860
    */
4861
0
    return (ret);
4862
0
}
4863
4864
/**
4865
 * xmlSchemaGetGroup:
4866
 * @schema:  the context of the schema
4867
 * @name:  the name of the group
4868
 * @ns:  the target namespace of the group
4869
 *
4870
 * Lookup a group in the schema or imported schemas
4871
 *
4872
 * Returns the group definition or NULL if not found.
4873
 */
4874
static xmlSchemaModelGroupDefPtr
4875
xmlSchemaGetGroup(xmlSchemaPtr schema, const xmlChar * name,
4876
                 const xmlChar * nsName)
4877
0
{
4878
0
    xmlSchemaModelGroupDefPtr ret = NULL;
4879
4880
0
    if ((name == NULL) || (schema == NULL))
4881
0
        return (NULL);
4882
0
    if (schema != NULL) {
4883
0
  WXS_FIND_GLOBAL_ITEM(groupDecl)
4884
0
    }
4885
0
exit:
4886
4887
0
    return (ret);
4888
0
}
4889
4890
static xmlSchemaNotationPtr
4891
xmlSchemaGetNotation(xmlSchemaPtr schema,
4892
         const xmlChar *name,
4893
         const xmlChar *nsName)
4894
0
{
4895
0
    xmlSchemaNotationPtr ret = NULL;
4896
4897
0
    if ((name == NULL) || (schema == NULL))
4898
0
        return (NULL);
4899
0
    if (schema != NULL) {
4900
0
  WXS_FIND_GLOBAL_ITEM(notaDecl)
4901
0
    }
4902
0
exit:
4903
0
    return (ret);
4904
0
}
4905
4906
static xmlSchemaIDCPtr
4907
xmlSchemaGetIDC(xmlSchemaPtr schema,
4908
    const xmlChar *name,
4909
    const xmlChar *nsName)
4910
0
{
4911
0
    xmlSchemaIDCPtr ret = NULL;
4912
4913
0
    if ((name == NULL) || (schema == NULL))
4914
0
        return (NULL);
4915
0
    if (schema != NULL) {
4916
0
  WXS_FIND_GLOBAL_ITEM(idcDef)
4917
0
    }
4918
0
exit:
4919
0
    return (ret);
4920
0
}
4921
4922
/**
4923
 * xmlSchemaGetNamedComponent:
4924
 * @schema:  the schema
4925
 * @name:  the name of the group
4926
 * @ns:  the target namespace of the group
4927
 *
4928
 * Lookup a group in the schema or imported schemas
4929