Coverage Report

Created: 2024-02-11 06:24

/src/libxml2/xmlschemas.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * schemas.c : implementation of the XML Schema handling and
3
 *             schema validity checking
4
 *
5
 * See Copyright for the status of this software.
6
 *
7
 * 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
45.9k
#define UNBOUNDED (1 << 30)
99
100
11.5k
#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
396k
#define ACTXT_CAST (xmlSchemaAbstractCtxtPtr)
118
1.06k
#define PCTXT_CAST (xmlSchemaParserCtxtPtr)
119
#define VCTXT_CAST (xmlSchemaValidCtxtPtr)
120
120k
#define WXS_BASIC_CAST (xmlSchemaBasicItemPtr)
121
24
#define WXS_TREE_CAST (xmlSchemaTreeItemPtr)
122
70.6k
#define WXS_PTC_CAST (xmlSchemaParticlePtr)
123
25.7k
#define WXS_TYPE_CAST (xmlSchemaTypePtr)
124
3.21k
#define WXS_ELEM_CAST (xmlSchemaElementPtr)
125
2.34k
#define WXS_ATTR_GROUP_CAST (xmlSchemaAttributeGroupPtr)
126
4.17k
#define WXS_ATTR_CAST (xmlSchemaAttributePtr)
127
41.9k
#define WXS_ATTR_USE_CAST (xmlSchemaAttributeUsePtr)
128
316
#define WXS_ATTR_PROHIB_CAST (xmlSchemaAttributeUseProhibPtr)
129
258
#define WXS_MODEL_GROUPDEF_CAST (xmlSchemaModelGroupDefPtr)
130
4.10k
#define WXS_MODEL_GROUP_CAST (xmlSchemaModelGroupPtr)
131
29
#define WXS_IDC_CAST (xmlSchemaIDCPtr)
132
6.55k
#define WXS_QNAME_CAST (xmlSchemaQNameRefPtr)
133
384
#define WXS_LIST_CAST (xmlSchemaItemListPtr)
134
135
/*
136
* Macros to query common properties of components.
137
*/
138
3.35k
#define WXS_ITEM_NODE(i) xmlSchemaGetComponentNode(WXS_BASIC_CAST (i))
139
140
2.52k
#define WXS_ITEM_TYPE_NAME(i) xmlSchemaGetComponentTypeStr(WXS_BASIC_CAST (i))
141
/*
142
* Macros for element declarations.
143
*/
144
13.1k
#define WXS_ELEM_TYPEDEF(e) (e)->subtypes
145
146
7.52k
#define WXS_SUBST_HEAD(item) (item)->refDecl
147
/*
148
* Macros for attribute declarations.
149
*/
150
4.56k
#define WXS_ATTR_TYPEDEF(a) (a)->subtypes
151
/*
152
* Macros for attribute uses.
153
*/
154
41.7k
#define WXS_ATTRUSE_DECL(au) (WXS_ATTR_USE_CAST (au))->attrDecl
155
156
2.17k
#define WXS_ATTRUSE_TYPEDEF(au) WXS_ATTR_TYPEDEF(WXS_ATTRUSE_DECL( WXS_ATTR_USE_CAST au))
157
158
33.6k
#define WXS_ATTRUSE_DECL_NAME(au) (WXS_ATTRUSE_DECL(au))->name
159
160
2.63k
#define WXS_ATTRUSE_DECL_TNS(au) (WXS_ATTRUSE_DECL(au))->targetNamespace
161
/*
162
* Macros for attribute groups.
163
*/
164
310
#define WXS_ATTR_GROUP_HAS_REFS(ag) ((WXS_ATTR_GROUP_CAST (ag))->flags & XML_SCHEMAS_ATTRGROUP_HAS_REFS)
165
330
#define WXS_ATTR_GROUP_EXPANDED(ag) ((WXS_ATTR_GROUP_CAST (ag))->flags & XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED)
166
/*
167
* Macros for particles.
168
*/
169
45.0k
#define WXS_PARTICLE(p) WXS_PTC_CAST (p)
170
171
45.0k
#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
173
#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
49
    (((i)->type == XML_SCHEMA_TYPE_SEQUENCE) || \
185
49
     ((i)->type == XML_SCHEMA_TYPE_CHOICE) || \
186
49
     ((i)->type == XML_SCHEMA_TYPE_ALL))
187
188
3.92k
#define WXS_MODELGROUP_PARTICLE(mg) WXS_PTC_CAST (mg)->children
189
/*
190
* Macros for schema buckets.
191
*/
192
25.1k
#define WXS_IS_BUCKET_INCREDEF(t) (((t) == XML_SCHEMA_SCHEMA_INCLUDE) || \
193
25.1k
    ((t) == XML_SCHEMA_SCHEMA_REDEFINE))
194
195
44.3k
#define WXS_IS_BUCKET_IMPMAIN(t) (((t) == XML_SCHEMA_SCHEMA_MAIN) || \
196
44.3k
    ((t) == XML_SCHEMA_SCHEMA_IMPORT))
197
198
25.8k
#define WXS_IMPBUCKET(b) ((xmlSchemaImportPtr) (b))
199
200
156
#define WXS_INCBUCKET(b) ((xmlSchemaIncludePtr) (b))
201
/*
202
* Macros for complex/simple types.
203
*/
204
#define WXS_IS_ANYTYPE(i) \
205
375
     (( (i)->type == XML_SCHEMA_TYPE_BASIC) && \
206
375
      ( (WXS_TYPE_CAST (i))->builtInType == XML_SCHEMAS_ANYTYPE))
207
208
#define WXS_IS_COMPLEX(i) \
209
16.1k
    (((i)->type == XML_SCHEMA_TYPE_COMPLEX) || \
210
12.6k
     ((i)->builtInType == XML_SCHEMAS_ANYTYPE))
211
212
#define WXS_IS_SIMPLE(item) \
213
34.6k
    ((item->type == XML_SCHEMA_TYPE_SIMPLE) || \
214
34.6k
     ((item->type == XML_SCHEMA_TYPE_BASIC) && \
215
20.7k
      (item->builtInType != XML_SCHEMAS_ANYTYPE)))
216
217
#define WXS_IS_ANY_SIMPLE_TYPE(i) \
218
303k
    (((i)->type == XML_SCHEMA_TYPE_BASIC) && \
219
303k
      ((i)->builtInType == XML_SCHEMAS_ANYSIMPLETYPE))
220
221
#define WXS_IS_RESTRICTION(t) \
222
3.00k
    ((t)->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION)
223
224
#define WXS_IS_EXTENSION(t) \
225
3.40k
    ((t)->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION)
226
227
#define WXS_IS_TYPE_NOT_FIXED(i) \
228
35.7k
    (((i)->type != XML_SCHEMA_TYPE_BASIC) && \
229
35.7k
     (((i)->flags & XML_SCHEMAS_TYPE_INTERNAL_RESOLVED) == 0))
230
231
#define WXS_IS_TYPE_NOT_FIXED_1(item) \
232
25.8k
    (((item)->type != XML_SCHEMA_TYPE_BASIC) && \
233
25.8k
     (((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
4.58k
    ((item->contentType == XML_SCHEMA_CONTENT_SIMPLE) || \
248
4.58k
     (item->contentType == XML_SCHEMA_CONTENT_BASIC))
249
250
#define WXS_HAS_MIXED_CONTENT(item) \
251
31
    (item->contentType == XML_SCHEMA_CONTENT_MIXED)
252
253
#define WXS_EMPTIABLE(t) \
254
11
    (xmlSchemaIsParticleEmptiable(WXS_PTC_CAST (t)->subtypes))
255
256
3.88k
#define WXS_TYPE_CONTENTTYPE(t) (t)->subtypes
257
258
622
#define WXS_TYPE_PARTICLE(t) WXS_PTC_CAST (t)->subtypes
259
260
1.99k
#define WXS_TYPE_PARTICLE_TERM(t) WXS_PARTICLE_TERM(WXS_TYPE_PARTICLE(t))
261
/*
262
* Macros for exclusively for simple types.
263
*/
264
6.33k
#define WXS_LIST_ITEMTYPE(t) (t)->subtypes
265
266
392k
#define WXS_IS_ATOMIC(t) (t->flags & XML_SCHEMAS_TYPE_VARIETY_ATOMIC)
267
268
179k
#define WXS_IS_LIST(t) (t->flags & XML_SCHEMAS_TYPE_VARIETY_LIST)
269
270
61.8k
#define WXS_IS_UNION(t) (t->flags & XML_SCHEMAS_TYPE_VARIETY_UNION)
271
/*
272
* Misc parser context macros.
273
*/
274
315k
#define WXS_CONSTRUCTOR(ctx) (ctx)->constructor
275
276
17.3k
#define WXS_HAS_BUCKETS(ctx) \
277
17.3k
( (WXS_CONSTRUCTOR((ctx))->buckets != NULL) && \
278
17.3k
(WXS_CONSTRUCTOR((ctx))->buckets->nbItems > 0) )
279
280
93
#define WXS_SUBST_GROUPS(ctx) WXS_CONSTRUCTOR((ctx))->substGroups
281
282
173k
#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
119k
    do { \
288
119k
        if (xmlSchemaAddItemSize(&(WXS_BUCKET(ctx)->locals), 10, item) < 0) { \
289
0
            xmlFree(item); \
290
0
            item = NULL; \
291
0
        } \
292
119k
    } while (0)
293
294
#define WXS_ADD_GLOBAL(ctx, item) \
295
46.6k
    do { \
296
46.6k
        if (xmlSchemaAddItemSize(&(WXS_BUCKET(ctx)->globals), 5, item) < 0) { \
297
0
            xmlFree(item); \
298
0
            item = NULL; \
299
0
        } \
300
46.6k
    } while (0)
301
302
#define WXS_ADD_PENDING(ctx, item) \
303
79.5k
    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
3.03M
   ((node != NULL) && (node->ns != NULL) && \
313
3.03M
    (xmlStrEqual(node->name, (const xmlChar *) type)) && \
314
3.03M
    (xmlStrEqual(node->ns->href, xmlSchemaNs)))
315
316
2.47M
#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
219
#define CAN_PARSE_SCHEMA(b) (((b)->doc != NULL) && ((b)->parsed == 0))
328
329
184k
#define HFAILURE if (res == -1) goto exit_failure;
330
331
39.5k
#define HERROR if (res != 0) goto exit_error;
332
333
4.72k
#define HSTOP(ctx) if ((ctx)->stop) goto exit;
334
/*
335
* Some flags used for various schema constraints.
336
*/
337
22
#define SUBSET_RESTRICTION  1<<0
338
3
#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
432k
#define XML_SCHEMA_CTXT_PARSER 1
355
407k
#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
152k
#define XML_SCHEMA_SCHEMA_MAIN 0
368
28.8k
#define XML_SCHEMA_SCHEMA_IMPORT 1
369
25.4k
#define XML_SCHEMA_SCHEMA_INCLUDE 2
370
25.1k
#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
16.0k
#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
998
#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
29.4k
#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
208
#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
9.15k
{
1129
9.15k
    switch (type) {
1130
0
  case XML_SCHEMA_TYPE_BASIC:
1131
0
      return(BAD_CAST "simple type definition");
1132
6.24k
  case XML_SCHEMA_TYPE_SIMPLE:
1133
6.24k
      return(BAD_CAST "simple type definition");
1134
768
  case XML_SCHEMA_TYPE_COMPLEX:
1135
768
      return(BAD_CAST "complex type definition");
1136
351
  case XML_SCHEMA_TYPE_ELEMENT:
1137
351
      return(BAD_CAST "element declaration");
1138
1.10k
  case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
1139
1.10k
      return(BAD_CAST "attribute use");
1140
84
  case XML_SCHEMA_TYPE_ATTRIBUTE:
1141
84
      return(BAD_CAST "attribute declaration");
1142
73
  case XML_SCHEMA_TYPE_GROUP:
1143
73
      return(BAD_CAST "model group definition");
1144
521
  case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1145
521
      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
1
  case XML_SCHEMA_TYPE_IDC_KEY:
1160
1
      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
9.15k
    }
1174
9.15k
}
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
2.52k
{
1185
2.52k
    switch (item->type) {
1186
2
  case XML_SCHEMA_TYPE_BASIC:
1187
2
      if (WXS_IS_COMPLEX(WXS_TYPE_CAST item))
1188
0
    return(BAD_CAST "complex type definition");
1189
2
      else
1190
2
    return(BAD_CAST "simple type definition");
1191
2.51k
  default:
1192
2.51k
      return(xmlSchemaItemTypeToStr(item->type));
1193
2.52k
    }
1194
2.52k
}
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
3.35k
{
1209
3.35k
    switch (item->type) {
1210
201
  case XML_SCHEMA_TYPE_ELEMENT:
1211
201
      return (((xmlSchemaElementPtr) item)->node);
1212
127
  case XML_SCHEMA_TYPE_ATTRIBUTE:
1213
127
      return (((xmlSchemaAttributePtr) item)->node);
1214
1.89k
  case XML_SCHEMA_TYPE_COMPLEX:
1215
2.23k
  case XML_SCHEMA_TYPE_SIMPLE:
1216
2.23k
      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
171
  case XML_SCHEMA_TYPE_PARTICLE:
1221
171
      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
37
  case XML_SCHEMA_TYPE_GROUP:
1227
37
      return (((xmlSchemaModelGroupDefPtr) item)->node);
1228
46
  case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1229
46
      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
7
  case XML_SCHEMA_EXTRA_QNAMEREF:
1235
7
      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
534
  default:
1243
534
      return (NULL);
1244
3.35k
    }
1245
3.35k
}
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
714k
{
1306
714k
    FREE_AND_NULL(*buf)
1307
714k
    if (namespaceName != NULL) {
1308
550k
  *buf = xmlStrdup(BAD_CAST "{");
1309
550k
  *buf = xmlStrcat(*buf, namespaceName);
1310
550k
  *buf = xmlStrcat(*buf, BAD_CAST "}");
1311
550k
    }
1312
714k
    if (localName != NULL) {
1313
702k
  if (namespaceName == NULL)
1314
151k
      return(localName);
1315
550k
  *buf = xmlStrcat(*buf, localName);
1316
550k
    } else {
1317
12.4k
  *buf = xmlStrcat(*buf, BAD_CAST "(NULL)");
1318
12.4k
    }
1319
562k
    return ((const xmlChar *) *buf);
1320
714k
}
1321
1322
static const xmlChar*
1323
xmlSchemaFormatQNameNs(xmlChar **buf, xmlNsPtr ns, const xmlChar *localName)
1324
28.3k
{
1325
28.3k
    if (ns != NULL)
1326
3.31k
  return (xmlSchemaFormatQName(buf, ns->href, localName));
1327
25.0k
    else
1328
25.0k
  return (xmlSchemaFormatQName(buf, NULL, localName));
1329
28.3k
}
1330
1331
static const xmlChar *
1332
xmlSchemaGetComponentName(xmlSchemaBasicItemPtr item)
1333
3.75k
{
1334
3.75k
    if (item == NULL) {
1335
0
        return (NULL);
1336
0
    }
1337
3.75k
    switch (item->type) {
1338
214
  case XML_SCHEMA_TYPE_ELEMENT:
1339
214
      return (((xmlSchemaElementPtr) item)->name);
1340
1.25k
  case XML_SCHEMA_TYPE_ATTRIBUTE:
1341
1.25k
      return (((xmlSchemaAttributePtr) item)->name);
1342
45
  case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1343
45
      return (((xmlSchemaAttributeGroupPtr) item)->name);
1344
4
  case XML_SCHEMA_TYPE_BASIC:
1345
341
  case XML_SCHEMA_TYPE_SIMPLE:
1346
1.09k
  case XML_SCHEMA_TYPE_COMPLEX:
1347
1.09k
      return (((xmlSchemaTypePtr) item)->name);
1348
37
  case XML_SCHEMA_TYPE_GROUP:
1349
37
      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
1.10k
  case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
1355
1.10k
      if (WXS_ATTRUSE_DECL(item) != NULL) {
1356
1.10k
    return(xmlSchemaGetComponentName(
1357
1.10k
        WXS_BASIC_CAST WXS_ATTRUSE_DECL(item)));
1358
1.10k
      } 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
3.75k
    }
1370
0
    return (NULL);
1371
3.75k
}
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
3.75k
{
1392
3.75k
    if (item == NULL) {
1393
0
        return (NULL);
1394
0
    }
1395
3.75k
    switch (item->type) {
1396
214
  case XML_SCHEMA_TYPE_ELEMENT:
1397
214
      return (((xmlSchemaElementPtr) item)->targetNamespace);
1398
1.25k
  case XML_SCHEMA_TYPE_ATTRIBUTE:
1399
1.25k
      return (((xmlSchemaAttributePtr) item)->targetNamespace);
1400
45
  case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1401
45
      return (((xmlSchemaAttributeGroupPtr) item)->targetNamespace);
1402
4
  case XML_SCHEMA_TYPE_BASIC:
1403
4
      return (BAD_CAST "http://www.w3.org/2001/XMLSchema");
1404
337
  case XML_SCHEMA_TYPE_SIMPLE:
1405
1.09k
  case XML_SCHEMA_TYPE_COMPLEX:
1406
1.09k
      return (((xmlSchemaTypePtr) item)->targetNamespace);
1407
37
  case XML_SCHEMA_TYPE_GROUP:
1408
37
      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
1.10k
  case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
1414
1.10k
      if (WXS_ATTRUSE_DECL(item) != NULL) {
1415
1.10k
    return(xmlSchemaGetComponentTargetNs(
1416
1.10k
        WXS_BASIC_CAST WXS_ATTRUSE_DECL(item)));
1417
1.10k
      }
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
3.75k
    }
1430
0
    return (NULL);
1431
3.75k
}
1432
1433
static const xmlChar*
1434
xmlSchemaGetComponentQName(xmlChar **buf,
1435
         void *item)
1436
2.65k
{
1437
2.65k
    return (xmlSchemaFormatQName(buf,
1438
2.65k
  xmlSchemaGetComponentTargetNs((xmlSchemaBasicItemPtr) item),
1439
2.65k
  xmlSchemaGetComponentName((xmlSchemaBasicItemPtr) item)));
1440
2.65k
}
1441
1442
static const xmlChar*
1443
xmlSchemaGetComponentDesignation(xmlChar **buf, void *item)
1444
1.21k
{
1445
1.21k
    xmlChar *str = NULL;
1446
1447
1.21k
    *buf = xmlStrcat(*buf, WXS_ITEM_TYPE_NAME(item));
1448
1.21k
    *buf = xmlStrcat(*buf, BAD_CAST " '");
1449
1.21k
    *buf = xmlStrcat(*buf, xmlSchemaGetComponentQName(&str,
1450
1.21k
  (xmlSchemaBasicItemPtr) item));
1451
1.21k
    *buf = xmlStrcat(*buf, BAD_CAST "'");
1452
1.21k
    FREE_AND_NULL(str);
1453
1.21k
    return(*buf);
1454
1.21k
}
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
6.94k
{
1503
6.94k
    int list;
1504
6.94k
    xmlSchemaValType valType;
1505
6.94k
    const xmlChar *value, *value2 = NULL;
1506
1507
1508
6.94k
    if ((retValue == NULL) || (val == NULL))
1509
7
  return (-1);
1510
6.93k
    list = xmlSchemaValueGetNext(val) ? 1 : 0;
1511
6.93k
    *retValue = NULL;
1512
6.93k
    do {
1513
6.93k
  value = NULL;
1514
6.93k
  valType = xmlSchemaGetValType(val);
1515
6.93k
  switch (valType) {
1516
307
      case XML_SCHEMAS_STRING:
1517
307
      case XML_SCHEMAS_NORMSTRING:
1518
307
      case XML_SCHEMAS_ANYSIMPLETYPE:
1519
307
    value = xmlSchemaValueGetAsString(val);
1520
307
    if (value != NULL) {
1521
307
        if (ws == XML_SCHEMA_WHITESPACE_COLLAPSE)
1522
0
      value2 = xmlSchemaCollapseString(value);
1523
307
        else if (ws == XML_SCHEMA_WHITESPACE_REPLACE)
1524
0
      value2 = xmlSchemaWhiteSpaceReplace(value);
1525
307
        if (value2 != NULL)
1526
0
      value = value2;
1527
307
    }
1528
307
    break;
1529
6.62k
      default:
1530
6.62k
    if (xmlSchemaGetCanonValue(val, &value2) == -1) {
1531
0
        if (value2 != NULL)
1532
0
      xmlFree((xmlChar *) value2);
1533
0
        goto internal_error;
1534
0
    }
1535
6.62k
    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
6.62k
    value = value2;
1550
6.93k
  }
1551
6.93k
  if (*retValue == NULL)
1552
6.93k
      if (value == NULL) {
1553
0
    if (! list)
1554
0
        *retValue = xmlStrdup(BAD_CAST "");
1555
0
      } else
1556
6.93k
    *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
6.93k
  FREE_AND_NULL(value2)
1563
6.93k
  val = xmlSchemaValueGetNext(val);
1564
6.93k
    } while (val != NULL);
1565
1566
6.93k
    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
6.93k
}
1574
1575
static int
1576
xmlSchemaGetCanonValueWhtspExt(xmlSchemaValPtr val,
1577
             xmlSchemaWhitespaceValueType ws,
1578
             xmlChar **retValue)
1579
6.94k
{
1580
6.94k
    return xmlSchemaGetCanonValueWhtspExt_1(val, ws, retValue, 0);
1581
6.94k
}
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
136k
{
1623
136k
    xmlChar *str = NULL;
1624
136k
    int named = 1;
1625
1626
136k
    if (*buf != NULL) {
1627
0
  xmlFree(*buf);
1628
0
  *buf = NULL;
1629
0
    }
1630
1631
136k
    if (itemDes != NULL) {
1632
0
  *buf = xmlStrdup(itemDes);
1633
136k
    } else if (item != NULL) {
1634
9.42k
  switch (item->type) {
1635
305
  case XML_SCHEMA_TYPE_BASIC: {
1636
305
      xmlSchemaTypePtr type = WXS_TYPE_CAST item;
1637
1638
305
      if (WXS_IS_ATOMIC(type))
1639
305
    *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
305
      *buf = xmlStrcat(*buf, type->name);
1647
305
      *buf = xmlStrcat(*buf, BAD_CAST "'");
1648
305
      }
1649
305
      break;
1650
6.33k
  case XML_SCHEMA_TYPE_SIMPLE: {
1651
6.33k
      xmlSchemaTypePtr type = WXS_TYPE_CAST item;
1652
1653
6.33k
      if (type->flags & XML_SCHEMAS_TYPE_GLOBAL) {
1654
516
    *buf = xmlStrdup(BAD_CAST"");
1655
5.81k
      } else {
1656
5.81k
    *buf = xmlStrdup(BAD_CAST "local ");
1657
5.81k
      }
1658
6.33k
      if (WXS_IS_ATOMIC(type))
1659
305
    *buf = xmlStrcat(*buf, BAD_CAST "atomic type");
1660
6.02k
      else if (WXS_IS_LIST(type))
1661
201
    *buf = xmlStrcat(*buf, BAD_CAST "list type");
1662
5.82k
      else if (WXS_IS_UNION(type))
1663
5.61k
    *buf = xmlStrcat(*buf, BAD_CAST "union type");
1664
216
      else
1665
216
    *buf = xmlStrcat(*buf, BAD_CAST "simple type");
1666
6.33k
      if (type->flags & XML_SCHEMAS_TYPE_GLOBAL) {
1667
516
    *buf = xmlStrcat(*buf, BAD_CAST " '");
1668
516
    *buf = xmlStrcat(*buf, type->name);
1669
516
    *buf = xmlStrcat(*buf, BAD_CAST "'");
1670
516
      }
1671
6.33k
      }
1672
6.33k
      break;
1673
1.33k
  case XML_SCHEMA_TYPE_COMPLEX: {
1674
1.33k
      xmlSchemaTypePtr type = WXS_TYPE_CAST item;
1675
1676
1.33k
      if (type->flags & XML_SCHEMAS_TYPE_GLOBAL)
1677
1.08k
    *buf = xmlStrdup(BAD_CAST "");
1678
248
      else
1679
248
    *buf = xmlStrdup(BAD_CAST "local ");
1680
1.33k
      *buf = xmlStrcat(*buf, BAD_CAST "complex type");
1681
1.33k
      if (type->flags & XML_SCHEMAS_TYPE_GLOBAL) {
1682
1.08k
    *buf = xmlStrcat(*buf, BAD_CAST " '");
1683
1.08k
    *buf = xmlStrcat(*buf, type->name);
1684
1.08k
    *buf = xmlStrcat(*buf, BAD_CAST "'");
1685
1.08k
      }
1686
1.33k
      }
1687
1.33k
      break;
1688
146
  case XML_SCHEMA_TYPE_ATTRIBUTE_USE: {
1689
146
    xmlSchemaAttributeUsePtr ause;
1690
1691
146
    ause = WXS_ATTR_USE_CAST item;
1692
146
    *buf = xmlStrdup(BAD_CAST "attribute use ");
1693
146
    if (WXS_ATTRUSE_DECL(ause) != NULL) {
1694
107
        *buf = xmlStrcat(*buf, BAD_CAST "'");
1695
107
        *buf = xmlStrcat(*buf,
1696
107
      xmlSchemaGetComponentQName(&str, WXS_ATTRUSE_DECL(ause)));
1697
107
        FREE_AND_NULL(str)
1698
107
      *buf = xmlStrcat(*buf, BAD_CAST "'");
1699
107
    } else {
1700
39
        *buf = xmlStrcat(*buf, BAD_CAST "(unknown)");
1701
39
    }
1702
146
      }
1703
146
      break;
1704
239
  case XML_SCHEMA_TYPE_ATTRIBUTE: {
1705
239
    xmlSchemaAttributePtr attr;
1706
1707
239
    attr = (xmlSchemaAttributePtr) item;
1708
239
    *buf = xmlStrdup(BAD_CAST "attribute decl.");
1709
239
    *buf = xmlStrcat(*buf, BAD_CAST " '");
1710
239
    *buf = xmlStrcat(*buf, xmlSchemaFormatQName(&str,
1711
239
        attr->targetNamespace, attr->name));
1712
239
    FREE_AND_NULL(str)
1713
239
        *buf = xmlStrcat(*buf, BAD_CAST "'");
1714
239
      }
1715
239
      break;
1716
0
  case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1717
0
      xmlSchemaGetComponentDesignation(buf, item);
1718
0
      break;
1719
259
  case XML_SCHEMA_TYPE_ELEMENT: {
1720
259
    xmlSchemaElementPtr elem;
1721
1722
259
    elem = (xmlSchemaElementPtr) item;
1723
259
    *buf = xmlStrdup(BAD_CAST "element decl.");
1724
259
    *buf = xmlStrcat(*buf, BAD_CAST " '");
1725
259
    *buf = xmlStrcat(*buf, xmlSchemaFormatQName(&str,
1726
259
        elem->targetNamespace, elem->name));
1727
259
    *buf = xmlStrcat(*buf, BAD_CAST "'");
1728
259
      }
1729
259
      break;
1730
0
  case XML_SCHEMA_TYPE_IDC_UNIQUE:
1731
0
  case XML_SCHEMA_TYPE_IDC_KEY:
1732
1
  case XML_SCHEMA_TYPE_IDC_KEYREF:
1733
1
      if (item->type == XML_SCHEMA_TYPE_IDC_UNIQUE)
1734
0
    *buf = xmlStrdup(BAD_CAST "unique '");
1735
1
      else if (item->type == XML_SCHEMA_TYPE_IDC_KEY)
1736
0
    *buf = xmlStrdup(BAD_CAST "key '");
1737
1
      else
1738
1
    *buf = xmlStrdup(BAD_CAST "keyRef '");
1739
1
      *buf = xmlStrcat(*buf, ((xmlSchemaIDCPtr) item)->name);
1740
1
      *buf = xmlStrcat(*buf, BAD_CAST "'");
1741
1
      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
117
  case XML_SCHEMA_FACET_MININCLUSIVE:
1749
271
  case XML_SCHEMA_FACET_MINEXCLUSIVE:
1750
459
  case XML_SCHEMA_FACET_MAXINCLUSIVE:
1751
586
  case XML_SCHEMA_FACET_MAXEXCLUSIVE:
1752
588
  case XML_SCHEMA_FACET_TOTALDIGITS:
1753
606
  case XML_SCHEMA_FACET_FRACTIONDIGITS:
1754
606
  case XML_SCHEMA_FACET_PATTERN:
1755
606
  case XML_SCHEMA_FACET_ENUMERATION:
1756
633
  case XML_SCHEMA_FACET_WHITESPACE:
1757
804
  case XML_SCHEMA_FACET_LENGTH:
1758
806
  case XML_SCHEMA_FACET_MAXLENGTH:
1759
810
  case XML_SCHEMA_FACET_MINLENGTH:
1760
810
      *buf = xmlStrdup(BAD_CAST "facet '");
1761
810
      *buf = xmlStrcat(*buf, xmlSchemaFacetTypeToString(item->type));
1762
810
      *buf = xmlStrcat(*buf, BAD_CAST "'");
1763
810
      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
9.42k
  }
1789
9.42k
    } else
1790
126k
  named = 0;
1791
1792
136k
    if ((named == 0) && (itemNode != NULL)) {
1793
126k
  xmlNodePtr elem;
1794
1795
126k
  if (itemNode->type == XML_ATTRIBUTE_NODE)
1796
19.5k
      elem = itemNode->parent;
1797
107k
  else
1798
107k
      elem = itemNode;
1799
126k
  *buf = xmlStrdup(BAD_CAST "Element '");
1800
126k
  if (elem->ns != NULL) {
1801
126k
      *buf = xmlStrcat(*buf,
1802
126k
    xmlSchemaFormatQName(&str, elem->ns->href, elem->name));
1803
126k
      FREE_AND_NULL(str)
1804
126k
  } else
1805
0
      *buf = xmlStrcat(*buf, elem->name);
1806
126k
  *buf = xmlStrcat(*buf, BAD_CAST "'");
1807
1808
126k
    }
1809
136k
    if ((itemNode != NULL) && (itemNode->type == XML_ATTRIBUTE_NODE)) {
1810
19.5k
  *buf = xmlStrcat(*buf, BAD_CAST ", attribute '");
1811
19.5k
  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
19.5k
      *buf = xmlStrcat(*buf, itemNode->name);
1817
19.5k
  *buf = xmlStrcat(*buf, BAD_CAST "'");
1818
19.5k
    }
1819
136k
    FREE_AND_NULL(str)
1820
1821
136k
    return (xmlEscapeFormatString(buf));
1822
136k
}
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
6.43k
{
1837
6.43k
    xmlSchemaFacetPtr facet;
1838
6.43k
    xmlSchemaWhitespaceValueType ws;
1839
6.43k
    xmlChar *value = NULL;
1840
6.43k
    int res, found = 0;
1841
1842
6.43k
    if (*buf != NULL)
1843
0
  xmlFree(*buf);
1844
6.43k
    *buf = NULL;
1845
1846
6.46k
    do {
1847
  /*
1848
  * Use the whitespace type of the base type.
1849
  */
1850
6.46k
  ws = xmlSchemaGetWhiteSpaceFacetValue(type->baseType);
1851
51.3k
  for (facet = type->facets; facet != NULL; facet = facet->next) {
1852
44.9k
      if (facet->type != XML_SCHEMA_FACET_ENUMERATION)
1853
37.9k
    continue;
1854
6.94k
      found = 1;
1855
6.94k
      res = xmlSchemaGetCanonValueWhtspExt(facet->val,
1856
6.94k
    ws, &value);
1857
6.94k
      if (res == -1) {
1858
7
    xmlSchemaInternalErr(actxt,
1859
7
        "xmlSchemaFormatFacetEnumSet",
1860
7
        "compute the canonical lexical representation");
1861
7
    if (*buf != NULL)
1862
0
        xmlFree(*buf);
1863
7
    *buf = NULL;
1864
7
    return (NULL);
1865
7
      }
1866
6.93k
      if (*buf == NULL)
1867
6.42k
    *buf = xmlStrdup(BAD_CAST "'");
1868
506
      else
1869
506
    *buf = xmlStrcat(*buf, BAD_CAST ", '");
1870
6.93k
      *buf = xmlStrcat(*buf, BAD_CAST value);
1871
6.93k
      *buf = xmlStrcat(*buf, BAD_CAST "'");
1872
6.93k
      if (value != NULL) {
1873
6.93k
    xmlFree((xmlChar *)value);
1874
6.93k
    value = NULL;
1875
6.93k
      }
1876
6.93k
  }
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
6.45k
  if (found)
1884
6.42k
      break;
1885
32
  type = type->baseType;
1886
32
    } while ((type != NULL) && (type->type != XML_SCHEMA_TYPE_BASIC));
1887
1888
6.42k
    return ((const xmlChar *) *buf);
1889
6.43k
}
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
499k
                  int col, const char *msg, ...) {
1927
499k
    xmlGenericErrorFunc channel = NULL;
1928
499k
    xmlStructuredErrorFunc schannel = NULL;
1929
499k
    void *data = NULL;
1930
499k
    int res;
1931
499k
    va_list ap;
1932
1933
499k
    if (ctxt != NULL) {
1934
        /* Don't overwrite memory errors */
1935
499k
        if (ctxt->err == XML_ERR_NO_MEMORY)
1936
0
            return;
1937
1938
499k
        if (level == XML_ERR_WARNING) {
1939
111
            channel = ctxt->warning;
1940
499k
        } else {
1941
499k
            ctxt->nberrors++;
1942
499k
            ctxt->err = code;
1943
499k
            channel = ctxt->error;
1944
499k
        }
1945
499k
        data = ctxt->errCtxt;
1946
499k
        schannel = ctxt->serror;
1947
499k
    }
1948
1949
499k
    if ((channel == NULL) && (schannel == NULL)) {
1950
0
        channel = xmlGenericError;
1951
0
        data = xmlGenericErrorContext;
1952
0
    }
1953
1954
499k
    va_start(ap, msg);
1955
499k
    res = xmlVRaiseError(schannel, channel, data, ctxt, node,
1956
499k
                         XML_FROM_SCHEMASP, code, level, file, line,
1957
499k
                         (const char *) str1,
1958
499k
                         (const char *) str2,
1959
499k
                         (const char *) str3,
1960
499k
                         0, col, msg, ap);
1961
499k
    va_end(ap);
1962
1963
499k
    if (res < 0)
1964
0
        xmlSchemaPErrMemory(ctxt);
1965
499k
}
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
205k
{
1982
205k
    xmlSchemaPErrFull(ctxt, node, code, XML_ERR_ERROR, NULL, 0,
1983
205k
                      str1, str2, NULL, 0, msg, str1, str2);
1984
205k
}
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
86.8k
{
2003
86.8k
    if (child != NULL)
2004
83.6k
        xmlSchemaPErr(ctxt, child, error, msg, str1, str2);
2005
3.19k
    else
2006
3.19k
        xmlSchemaPErr(ctxt, node, error, msg, str1, str2);
2007
86.8k
}
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
48.1k
{
2034
48.1k
    xmlSchemaPErrFull(ctxt, node, code, XML_ERR_ERROR, NULL, 0,
2035
48.1k
                      strData1, strData2, strData3, 0,
2036
48.1k
                      msg, str1, str2, str3, str4, str5);
2037
48.1k
}
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
246k
{
2139
246k
    if (ctxt != NULL) {
2140
246k
  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
246k
  } else if (ctxt->type == XML_SCHEMA_CTXT_PARSER) {
2204
246k
      xmlSchemaParserCtxtPtr pctxt = (xmlSchemaParserCtxtPtr) ctxt;
2205
2206
246k
            xmlSchemaPErrFull(pctxt, node, code, errorLevel,
2207
246k
                              NULL, 0, str1, str2, str3, 0,
2208
246k
                              msg, str1, str2, str3, str4);
2209
246k
  }
2210
246k
    }
2211
246k
}
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
247
{
2230
247
    xmlSchemaErr4Line(actxt, XML_ERR_ERROR, error, node, 0,
2231
247
  msg, str1, str2, str3, NULL);
2232
247
}
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
245k
{
2240
245k
    xmlSchemaErr4Line(actxt, XML_ERR_ERROR, error, node, 0,
2241
245k
  msg, str1, str2, str3, str4);
2242
245k
}
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
104k
{
2249
104k
    xmlSchemaErr4(actxt, error, node, msg, str1, str2, NULL, NULL);
2250
104k
}
2251
2252
static xmlChar *
2253
xmlSchemaFormatNodeForError(xmlChar ** msg,
2254
          xmlSchemaAbstractCtxtPtr actxt,
2255
          xmlNodePtr node)
2256
363k
{
2257
363k
    xmlChar *str = NULL;
2258
2259
363k
    *msg = NULL;
2260
363k
    if ((node != NULL) &&
2261
363k
  (node->type != XML_ELEMENT_NODE) &&
2262
363k
  (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
363k
    if (node != NULL) {
2273
  /*
2274
  * Work on tree nodes.
2275
  */
2276
346k
  if (node->type == XML_ATTRIBUTE_NODE) {
2277
122k
      xmlNodePtr elem = node->parent;
2278
2279
122k
      *msg = xmlStrdup(BAD_CAST "Element '");
2280
122k
      if (elem->ns != NULL)
2281
122k
    *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2282
122k
        elem->ns->href, elem->name));
2283
0
      else
2284
0
    *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2285
0
        NULL, elem->name));
2286
122k
      FREE_AND_NULL(str);
2287
122k
      *msg = xmlStrcat(*msg, BAD_CAST "', ");
2288
122k
      *msg = xmlStrcat(*msg, BAD_CAST "attribute '");
2289
223k
  } else {
2290
223k
      *msg = xmlStrdup(BAD_CAST "Element '");
2291
223k
  }
2292
346k
  if (node->ns != NULL)
2293
223k
      *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2294
223k
      node->ns->href, node->name));
2295
122k
  else
2296
122k
      *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2297
122k
      NULL, node->name));
2298
346k
  FREE_AND_NULL(str);
2299
346k
  *msg = xmlStrcat(*msg, BAD_CAST "': ");
2300
346k
    } 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
16.6k
    } 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
16.6k
  *msg = xmlStrdup(BAD_CAST "");
2328
16.6k
    } 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
363k
    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
363k
    return (*msg);
2353
363k
}
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
247
{
2362
247
    xmlChar *msg = NULL;
2363
2364
247
    if (actxt == NULL)
2365
0
        return;
2366
247
    msg = xmlStrdup(BAD_CAST "Internal error: %s, ");
2367
247
    msg = xmlStrcat(msg, BAD_CAST message);
2368
247
    msg = xmlStrcat(msg, BAD_CAST ".\n");
2369
2370
247
    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
247
    else if (actxt->type == XML_SCHEMA_CTXT_PARSER)
2374
247
  xmlSchemaErr3(actxt, XML_SCHEMAP_INTERNAL, NULL,
2375
247
      (const char *) msg, (const xmlChar *) funcName, str1, str2);
2376
2377
247
    FREE_AND_NULL(msg)
2378
247
}
2379
2380
static void LIBXML_ATTR_FORMAT(3,0)
2381
xmlSchemaInternalErr(xmlSchemaAbstractCtxtPtr actxt,
2382
         const char *funcName,
2383
         const char *message)
2384
247
{
2385
247
    xmlSchemaInternalErr2(actxt, funcName, message, NULL, NULL);
2386
247
}
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
112k
{
2410
112k
    xmlChar *msg = NULL;
2411
2412
112k
    if ((node == NULL) && (item != NULL) &&
2413
112k
  (actxt->type == XML_SCHEMA_CTXT_PARSER)) {
2414
1.20k
  node = WXS_ITEM_NODE(item);
2415
1.20k
  xmlSchemaFormatItemForReport(&msg, NULL, item, NULL);
2416
1.20k
  msg = xmlStrcat(msg, BAD_CAST ": ");
2417
1.20k
    } else
2418
111k
  xmlSchemaFormatNodeForError(&msg, actxt, node);
2419
112k
    msg = xmlStrcat(msg, (const xmlChar *) message);
2420
112k
    msg = xmlStrcat(msg, BAD_CAST ".\n");
2421
112k
    xmlSchemaErr4(actxt, error, node,
2422
112k
  (const char *) msg, str1, str2, str3, str4);
2423
112k
    FREE_AND_NULL(msg)
2424
112k
}
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
111k
{
2435
111k
    xmlSchemaCustomErr4(actxt, error, node, item,
2436
111k
  message, str1, str2, NULL, NULL);
2437
111k
}
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
111
{
2451
111
    xmlChar *msg = NULL;
2452
2453
111
    xmlSchemaFormatNodeForError(&msg, actxt, node);
2454
111
    msg = xmlStrcat(msg, (const xmlChar *) message);
2455
111
    msg = xmlStrcat(msg, BAD_CAST ".\n");
2456
2457
    /* URGENT TODO: Set the error code to something sane. */
2458
111
    xmlSchemaErr4Line(actxt, XML_ERR_WARNING, error, node, 0,
2459
111
  (const char *) msg, str1, str2, str3, NULL);
2460
2461
111
    FREE_AND_NULL(msg)
2462
111
}
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
26.4k
{
2494
26.4k
    if (node != NULL)
2495
26.4k
  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
346k
{
2505
346k
    switch (item->type) {
2506
0
  case XML_SCHEMA_TYPE_COMPLEX:
2507
12.7k
  case XML_SCHEMA_TYPE_SIMPLE:
2508
12.7k
      if (item->flags & XML_SCHEMAS_TYPE_GLOBAL)
2509
746
    return(1);
2510
11.9k
      break;
2511
11.9k
  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
333k
  default:
2525
333k
      return(1);
2526
346k
    }
2527
11.9k
    return (0);
2528
346k
}
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
78.4k
{
2538
78.4k
    xmlChar *msg = NULL;
2539
2540
78.4k
    xmlSchemaFormatNodeForError(&msg, actxt, node);
2541
2542
78.4k
    if (displayValue || (xmlSchemaEvalErrorNodeType(actxt, node) ==
2543
0
      XML_ATTRIBUTE_NODE))
2544
78.4k
  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
78.4k
    if (! xmlSchemaIsGlobalItem(type))
2550
5.98k
  msg = xmlStrcat(msg, BAD_CAST "the local ");
2551
72.4k
    else
2552
72.4k
  msg = xmlStrcat(msg, BAD_CAST "the ");
2553
2554
78.4k
    if (WXS_IS_ATOMIC(type))
2555
75.1k
  msg = xmlStrcat(msg, BAD_CAST "atomic type");
2556
3.29k
    else if (WXS_IS_LIST(type))
2557
3.19k
  msg = xmlStrcat(msg, BAD_CAST "list type");
2558
104
    else if (WXS_IS_UNION(type))
2559
104
  msg = xmlStrcat(msg, BAD_CAST "union type");
2560
2561
78.4k
    if (xmlSchemaIsGlobalItem(type)) {
2562
72.4k
  xmlChar *str = NULL;
2563
72.4k
  msg = xmlStrcat(msg, BAD_CAST " '");
2564
72.4k
  if (type->builtInType != 0) {
2565
72.0k
      msg = xmlStrcat(msg, BAD_CAST "xs:");
2566
72.0k
      str = xmlStrdup(type->name);
2567
72.0k
  } else {
2568
373
      const xmlChar *qName = xmlSchemaFormatQName(&str, type->targetNamespace, type->name);
2569
373
      if (!str)
2570
269
    str = xmlStrdup(qName);
2571
373
  }
2572
72.4k
  msg = xmlStrcat(msg, xmlEscapeFormatString(&str));
2573
72.4k
  msg = xmlStrcat(msg, BAD_CAST "'");
2574
72.4k
  FREE_AND_NULL(str);
2575
72.4k
    }
2576
78.4k
    msg = xmlStrcat(msg, BAD_CAST ".\n");
2577
78.4k
    if (displayValue || (xmlSchemaEvalErrorNodeType(actxt, node) ==
2578
0
      XML_ATTRIBUTE_NODE))
2579
78.4k
  xmlSchemaErr(actxt, error, node, (const char *) msg, value, NULL);
2580
0
    else
2581
0
  xmlSchemaErr(actxt, error, node, (const char *) msg, NULL, NULL);
2582
78.4k
    FREE_AND_NULL(msg)
2583
78.4k
}
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
26.4k
{
2729
26.4k
    xmlChar *str = NULL, *msg = NULL;
2730
26.4k
    xmlSchemaTypeType facetType;
2731
26.4k
    int nodeType = xmlSchemaEvalErrorNodeType(actxt, node);
2732
2733
26.4k
    xmlSchemaFormatNodeForError(&msg, actxt, node);
2734
26.4k
    if (error == XML_SCHEMAV_CVC_ENUMERATION_VALID) {
2735
6.43k
  facetType = XML_SCHEMA_FACET_ENUMERATION;
2736
  /*
2737
  * If enumerations are validated, one must not expect the
2738
  * facet to be given.
2739
  */
2740
6.43k
    } else
2741
19.9k
  facetType = facet->type;
2742
26.4k
    msg = xmlStrcat(msg, BAD_CAST "[");
2743
26.4k
    msg = xmlStrcat(msg, BAD_CAST "facet '");
2744
26.4k
    msg = xmlStrcat(msg, xmlSchemaFacetTypeToString(facetType));
2745
26.4k
    msg = xmlStrcat(msg, BAD_CAST "'] ");
2746
26.4k
    if (message == NULL) {
2747
  /*
2748
  * Use a default message.
2749
  */
2750
26.4k
  if ((facetType == XML_SCHEMA_FACET_LENGTH) ||
2751
26.4k
      (facetType == XML_SCHEMA_FACET_MINLENGTH) ||
2752
26.4k
      (facetType == XML_SCHEMA_FACET_MAXLENGTH)) {
2753
2754
1.03k
      char len[25], actLen[25];
2755
2756
      /* FIXME, TODO: What is the max expected string length of the
2757
      * this value?
2758
      */
2759
1.03k
      if (nodeType == XML_ATTRIBUTE_NODE)
2760
0
    msg = xmlStrcat(msg, BAD_CAST "The value '%s' has a length of '%s'; ");
2761
1.03k
      else
2762
1.03k
    msg = xmlStrcat(msg, BAD_CAST "The value has a length of '%s'; ");
2763
2764
1.03k
      snprintf(len, 24, "%lu", xmlSchemaGetFacetValueAsULong(facet));
2765
1.03k
      snprintf(actLen, 24, "%lu", length);
2766
2767
1.03k
      if (facetType == XML_SCHEMA_FACET_LENGTH)
2768
428
    msg = xmlStrcat(msg,
2769
428
    BAD_CAST "this differs from the allowed length of '%s'.\n");
2770
605
      else if (facetType == XML_SCHEMA_FACET_MAXLENGTH)
2771
344
    msg = xmlStrcat(msg,
2772
344
    BAD_CAST "this exceeds the allowed maximum length of '%s'.\n");
2773
261
      else if (facetType == XML_SCHEMA_FACET_MINLENGTH)
2774
261
    msg = xmlStrcat(msg,
2775
261
    BAD_CAST "this underruns the allowed minimum length of '%s'.\n");
2776
2777
1.03k
      if (nodeType == XML_ATTRIBUTE_NODE)
2778
0
    xmlSchemaErr3(actxt, error, node, (const char *) msg,
2779
0
        value, (const xmlChar *) actLen, (const xmlChar *) len);
2780
1.03k
      else
2781
1.03k
    xmlSchemaErr(actxt, error, node, (const char *) msg,
2782
1.03k
        (const xmlChar *) actLen, (const xmlChar *) len);
2783
2784
25.3k
  } else if (facetType == XML_SCHEMA_FACET_ENUMERATION) {
2785
6.43k
      msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not an element "
2786
6.43k
    "of the set {%s}.\n");
2787
6.43k
      xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2788
6.43k
    xmlSchemaFormatFacetEnumSet(actxt, &str, type));
2789
18.9k
  } else if (facetType == XML_SCHEMA_FACET_PATTERN) {
2790
6.77k
      msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not accepted "
2791
6.77k
    "by the pattern '%s'.\n");
2792
6.77k
      xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2793
6.77k
    facet->value);
2794
12.1k
  } else if (facetType == XML_SCHEMA_FACET_MININCLUSIVE) {
2795
213
      msg = xmlStrcat(msg, BAD_CAST "The value '%s' is less than the "
2796
213
    "minimum value allowed ('%s').\n");
2797
213
      xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2798
213
    facet->value);
2799
11.9k
  } else if (facetType == XML_SCHEMA_FACET_MAXINCLUSIVE) {
2800
7.51k
      msg = xmlStrcat(msg, BAD_CAST "The value '%s' is greater than the "
2801
7.51k
    "maximum value allowed ('%s').\n");
2802
7.51k
      xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2803
7.51k
    facet->value);
2804
7.51k
  } else if (facetType == XML_SCHEMA_FACET_MINEXCLUSIVE) {
2805
124
      msg = xmlStrcat(msg, BAD_CAST "The value '%s' must be greater than "
2806
124
    "'%s'.\n");
2807
124
      xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2808
124
    facet->value);
2809
4.32k
  } else if (facetType == XML_SCHEMA_FACET_MAXEXCLUSIVE) {
2810
3.94k
      msg = xmlStrcat(msg, BAD_CAST "The value '%s' must be less than "
2811
3.94k
    "'%s'.\n");
2812
3.94k
      xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2813
3.94k
    facet->value);
2814
3.94k
  } else if (facetType == XML_SCHEMA_FACET_TOTALDIGITS) {
2815
374
      msg = xmlStrcat(msg, BAD_CAST "The value '%s' has more "
2816
374
    "digits than are allowed ('%s').\n");
2817
374
      xmlSchemaErr(actxt, error, node, (const char*) msg, value,
2818
374
    facet->value);
2819
374
  } 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
26.4k
    } 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
26.4k
    FREE_AND_NULL(str)
2837
26.4k
    xmlFree(msg);
2838
26.4k
}
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
92
#define PERROR_INT(func, msg) xmlSchemaInternalErr(ACTXT_CAST pctxt, func, msg);
2846
100
#define PERROR_INT2(func, msg) xmlSchemaInternalErr(ACTXT_CAST ctxt, func, msg);
2847
2848
48
#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
16.6k
{
2869
16.6k
    xmlChar *des = NULL;
2870
2871
16.6k
    xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem);
2872
2873
16.6k
    if (message != NULL)
2874
0
  xmlSchemaPErr(ctxt, ownerElem, error, "%s: %s.\n", BAD_CAST des, BAD_CAST message);
2875
16.6k
    else
2876
16.6k
  xmlSchemaPErr(ctxt, ownerElem, error,
2877
16.6k
      "%s: The attribute '%s' is required but missing.\n",
2878
16.6k
      BAD_CAST des, BAD_CAST name);
2879
16.6k
    FREE_AND_NULL(des);
2880
16.6k
}
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
6.85k
{
2908
6.85k
    xmlChar *des = NULL, *strA = NULL;
2909
2910
6.85k
    xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem);
2911
6.85k
    if (refTypeStr == NULL)
2912
6.63k
  refTypeStr = (const char *) xmlSchemaItemTypeToStr(refType);
2913
6.85k
    xmlSchemaPErrExt(ctxt, ownerElem, error,
2914
6.85k
      NULL, NULL, NULL,
2915
6.85k
      "%s, attribute '%s': The QName value '%s' does not resolve to a(n) "
2916
6.85k
      "%s.\n", BAD_CAST des, BAD_CAST name,
2917
6.85k
      xmlSchemaFormatQName(&strA, refURI, refName),
2918
6.85k
      BAD_CAST refTypeStr, NULL);
2919
6.85k
    FREE_AND_NULL(des)
2920
6.85k
    FREE_AND_NULL(strA)
2921
6.85k
}
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
2.17k
{
2941
2.17k
    xmlChar *des = NULL;
2942
2943
2.17k
    if (ownerDes == NULL)
2944
2.17k
  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
2.17k
    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
2.17k
    } else {
2956
2.17k
  xmlSchemaPErrExt(ctxt, (xmlNodePtr) attr, error, NULL, NULL, NULL,
2957
2.17k
      "%s, attribute '%s': %s.\n",
2958
2.17k
      BAD_CAST des, attr->name, (const xmlChar *) msg, NULL, NULL);
2959
2.17k
    }
2960
2.17k
    if (ownerDes == NULL)
2961
2.17k
  FREE_AND_NULL(des);
2962
2.17k
}
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
28.3k
{
2979
28.3k
    xmlChar *strA = NULL, *strB = NULL;
2980
2981
28.3k
    xmlSchemaFormatNodeForError(&strA, ACTXT_CAST ctxt, attr->parent);
2982
28.3k
    xmlSchemaErr4(ACTXT_CAST ctxt, error, (xmlNodePtr) attr,
2983
28.3k
  "%sThe attribute '%s' is not allowed.\n", BAD_CAST strA,
2984
28.3k
  xmlSchemaFormatQNameNs(&strB, attr->ns, attr->name),
2985
28.3k
  NULL, NULL);
2986
28.3k
    FREE_AND_NULL(strA);
2987
28.3k
    FREE_AND_NULL(strB);
2988
28.3k
}
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
20.9k
{
3014
20.9k
    xmlChar *des = NULL, *msg = NULL;
3015
3016
20.9k
    xmlSchemaFormatItemForReport(&des, NULL, item, itemElem);
3017
20.9k
    msg = xmlStrdup(BAD_CAST "%s: ");
3018
20.9k
    msg = xmlStrcat(msg, (const xmlChar *) message);
3019
20.9k
    msg = xmlStrcat(msg, BAD_CAST ".\n");
3020
20.9k
    if ((itemElem == NULL) && (item != NULL))
3021
557
  itemElem = WXS_ITEM_NODE(item);
3022
20.9k
    xmlSchemaPErrExt(ctxt, itemElem, error, NULL, NULL, NULL,
3023
20.9k
  (const char *) msg, BAD_CAST des, str1, str2, str3, NULL);
3024
20.9k
    FREE_AND_NULL(des);
3025
20.9k
    FREE_AND_NULL(msg);
3026
20.9k
}
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
20.7k
{
3048
20.7k
    xmlSchemaPCustomErrExt(ctxt, error, item, itemElem, message,
3049
20.7k
  str1, NULL, NULL);
3050
20.7k
}
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
107
{
3075
107
    xmlChar *str = NULL, *msg = NULL;
3076
3077
107
    xmlSchemaFormatItemForReport(&msg, NULL, ownerItem, NULL);
3078
107
    msg = xmlStrcat(msg, BAD_CAST ", ");
3079
107
    msg = xmlStrcat(msg,
3080
107
  BAD_CAST xmlSchemaFormatItemForReport(&str, NULL,
3081
107
  WXS_BASIC_CAST attruse, NULL));
3082
107
    FREE_AND_NULL(str);
3083
107
    msg = xmlStrcat(msg, BAD_CAST ": ");
3084
107
    msg = xmlStrcat(msg, (const xmlChar *) message);
3085
107
    msg = xmlStrcat(msg, BAD_CAST ".\n");
3086
107
    xmlSchemaErr4(ACTXT_CAST ctxt, error, node,
3087
107
  (const char *) msg, str1, str2, str3, str4);
3088
107
    xmlFree(msg);
3089
107
}
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
305
{
3108
305
    xmlChar *des = NULL, *strT = NULL;
3109
3110
305
    xmlSchemaFormatItemForReport(&des, NULL, WXS_BASIC_CAST type, type->node);
3111
305
    xmlSchemaPErrExt(ctxt, type->node, error, NULL, NULL, NULL,
3112
305
  "%s: The facet '%s' is not allowed on types derived from the "
3113
305
  "type %s.\n",
3114
305
  BAD_CAST des, xmlSchemaFacetTypeToString(facet->type),
3115
305
  xmlSchemaFormatItemForReport(&strT, NULL, WXS_BASIC_CAST baseType, NULL),
3116
305
  NULL, NULL);
3117
305
    FREE_AND_NULL(des);
3118
305
    FREE_AND_NULL(strT);
3119
305
}
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
200
{
3137
200
    xmlChar *des = NULL;
3138
3139
200
    xmlSchemaFormatItemForReport(&des, NULL, WXS_BASIC_CAST type,
3140
200
  type->node);
3141
200
    xmlSchemaPErr(ctxt, type->node, error,
3142
200
  "%s: The facet '%s' is not allowed.\n",
3143
200
  BAD_CAST des, xmlSchemaFacetTypeToString(facet->type));
3144
200
    FREE_AND_NULL(des);
3145
200
}
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
715
{
3165
715
    xmlChar *des = NULL;
3166
3167
715
    xmlSchemaFormatItemForReport(&des, NULL, WXS_BASIC_CAST ownerItem, attr->parent);
3168
715
    xmlSchemaPErrExt(ctxt, (xmlNodePtr) attr, error, NULL, NULL, NULL,
3169
715
  "%s: The attributes '%s' and '%s' are mutually exclusive.\n",
3170
715
  BAD_CAST des, BAD_CAST name1, BAD_CAST name2, NULL, NULL);
3171
715
    FREE_AND_NULL(des);
3172
715
}
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
118k
{
3198
118k
    xmlChar *msg = NULL;
3199
3200
118k
    xmlSchemaFormatNodeForError(&msg, ACTXT_CAST ctxt, node);
3201
118k
    if (message == NULL) {
3202
  /*
3203
  * Use default messages.
3204
  */
3205
101k
  if (type != NULL) {
3206
94.9k
      if (node->type == XML_ATTRIBUTE_NODE)
3207
94.9k
    msg = xmlStrcat(msg, BAD_CAST "'%s' is not a valid value of ");
3208
2
      else
3209
2
    msg = xmlStrcat(msg, BAD_CAST "The character content is not a "
3210
2
    "valid value of ");
3211
94.9k
      if (! xmlSchemaIsGlobalItem(type))
3212
0
    msg = xmlStrcat(msg, BAD_CAST "the local ");
3213
94.9k
      else
3214
94.9k
    msg = xmlStrcat(msg, BAD_CAST "the ");
3215
3216
94.9k
      if (WXS_IS_ATOMIC(type))
3217
94.9k
    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
94.9k
      if (xmlSchemaIsGlobalItem(type)) {
3224
94.9k
    xmlChar *str = NULL;
3225
94.9k
    msg = xmlStrcat(msg, BAD_CAST " '");
3226
94.9k
    if (type->builtInType != 0) {
3227
94.9k
        msg = xmlStrcat(msg, BAD_CAST "xs:");
3228
94.9k
        str = xmlStrdup(type->name);
3229
94.9k
    } else {
3230
0
        const xmlChar *qName = xmlSchemaFormatQName(&str, type->targetNamespace, type->name);
3231
0
        if (!str)
3232
0
      str = xmlStrdup(qName);
3233
0
    }
3234
94.9k
    msg = xmlStrcat(msg, xmlEscapeFormatString(&str));
3235
94.9k
    msg = xmlStrcat(msg, BAD_CAST "'.");
3236
94.9k
    FREE_AND_NULL(str);
3237
94.9k
      }
3238
94.9k
  } else {
3239
6.73k
      if (node->type == XML_ATTRIBUTE_NODE)
3240
6.70k
    msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not valid.");
3241
39
      else
3242
39
    msg = xmlStrcat(msg, BAD_CAST "The character content is not "
3243
39
    "valid.");
3244
6.73k
  }
3245
101k
  if (expected) {
3246
6.73k
      xmlChar *expectedEscaped = xmlCharStrdup(expected);
3247
6.73k
      msg = xmlStrcat(msg, BAD_CAST " Expected is '");
3248
6.73k
      msg = xmlStrcat(msg, xmlEscapeFormatString(&expectedEscaped));
3249
6.73k
      FREE_AND_NULL(expectedEscaped);
3250
6.73k
      msg = xmlStrcat(msg, BAD_CAST "'.\n");
3251
6.73k
  } else
3252
94.9k
      msg = xmlStrcat(msg, BAD_CAST "\n");
3253
101k
  if (node->type == XML_ATTRIBUTE_NODE)
3254
101k
      xmlSchemaPErr(ctxt, node, error, (const char *) msg, value, NULL);
3255
41
  else
3256
41
      xmlSchemaPErr(ctxt, node, error, (const char *) msg, NULL, NULL);
3257
101k
    } else {
3258
17.1k
  msg = xmlStrcat(msg, BAD_CAST message);
3259
17.1k
  msg = xmlStrcat(msg, BAD_CAST ".\n");
3260
17.1k
  xmlSchemaPErrExt(ctxt, node, error, NULL, NULL, NULL,
3261
17.1k
       (const char*) msg, str1, str2, NULL, NULL, NULL);
3262
17.1k
    }
3263
    /* Cleanup. */
3264
118k
    FREE_AND_NULL(msg)
3265
118k
}
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
86.4k
{
3288
86.4k
    xmlChar *des = NULL;
3289
3290
86.4k
    xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem);
3291
86.4k
    if (message != NULL)
3292
911
  xmlSchemaPErr2(ctxt, ownerElem, child, error,
3293
911
      "%s: %s.\n",
3294
911
      BAD_CAST des, BAD_CAST message);
3295
85.5k
    else {
3296
85.5k
  if (content != NULL) {
3297
85.5k
      xmlSchemaPErr2(ctxt, ownerElem, child, error,
3298
85.5k
    "%s: The content is not valid. Expected is %s.\n",
3299
85.5k
    BAD_CAST des, BAD_CAST content);
3300
85.5k
  } 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
85.5k
    }
3306
86.4k
    FREE_AND_NULL(des)
3307
86.4k
}
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
29.2k
{
3342
29.2k
    xmlSchemaPtr ret;
3343
3344
29.2k
    ret = (xmlSchemaPtr) xmlMalloc(sizeof(xmlSchema));
3345
29.2k
    if (ret == NULL) {
3346
0
        xmlSchemaPErrMemory(ctxt);
3347
0
        return (NULL);
3348
0
    }
3349
29.2k
    memset(ret, 0, sizeof(xmlSchema));
3350
29.2k
    ret->dict = ctxt->dict;
3351
29.2k
    xmlDictReference(ret->dict);
3352
3353
29.2k
    return (ret);
3354
29.2k
}
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
128k
{
3366
128k
    xmlSchemaFacetPtr ret;
3367
3368
128k
    ret = (xmlSchemaFacetPtr) xmlMalloc(sizeof(xmlSchemaFacet));
3369
128k
    if (ret == NULL) {
3370
0
        return (NULL);
3371
0
    }
3372
128k
    memset(ret, 0, sizeof(xmlSchemaFacet));
3373
3374
128k
    return (ret);
3375
128k
}
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
4.31k
{
3389
4.31k
    xmlSchemaAnnotPtr ret;
3390
3391
4.31k
    ret = (xmlSchemaAnnotPtr) xmlMalloc(sizeof(xmlSchemaAnnot));
3392
4.31k
    if (ret == NULL) {
3393
0
        xmlSchemaPErrMemory(ctxt);
3394
0
        return (NULL);
3395
0
    }
3396
4.31k
    memset(ret, 0, sizeof(xmlSchemaAnnot));
3397
4.31k
    ret->content = node;
3398
4.31k
    return (ret);
3399
4.31k
}
3400
3401
static xmlSchemaItemListPtr
3402
xmlSchemaItemListCreate(void)
3403
122k
{
3404
122k
    xmlSchemaItemListPtr ret;
3405
3406
122k
    ret = xmlMalloc(sizeof(xmlSchemaItemList));
3407
122k
    if (ret == NULL) {
3408
0
  xmlSchemaPErrMemory(NULL);
3409
0
  return (NULL);
3410
0
    }
3411
122k
    memset(ret, 0, sizeof(xmlSchemaItemList));
3412
122k
    return (ret);
3413
122k
}
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
12.8k
{
3429
12.8k
    if (list->sizeItems <= list->nbItems) {
3430
12.5k
        void **tmp;
3431
12.5k
        size_t newSize = list->sizeItems == 0 ? 20 : list->sizeItems * 2;
3432
3433
12.5k
  tmp = (void **) xmlRealloc(list->items, newSize * sizeof(void *));
3434
12.5k
  if (tmp == NULL) {
3435
0
      xmlSchemaPErrMemory(NULL);
3436
0
      return(-1);
3437
0
  }
3438
12.5k
        list->items = tmp;
3439
12.5k
  list->sizeItems = newSize;
3440
12.5k
    }
3441
12.8k
    list->items[list->nbItems++] = item;
3442
12.8k
    return(0);
3443
12.8k
}
3444
3445
static int
3446
xmlSchemaItemListAddSize(xmlSchemaItemListPtr list,
3447
       int initialSize,
3448
       void *item)
3449
253k
{
3450
253k
    if (list->items == NULL) {
3451
30.6k
  if (initialSize <= 0)
3452
0
      initialSize = 1;
3453
30.6k
  list->items = (void **) xmlMalloc(
3454
30.6k
      initialSize * sizeof(void *));
3455
30.6k
  if (list->items == NULL) {
3456
0
      xmlSchemaPErrMemory(NULL);
3457
0
      return(-1);
3458
0
  }
3459
30.6k
  list->sizeItems = initialSize;
3460
223k
    } else if (list->sizeItems <= list->nbItems) {
3461
9.04k
        void **tmp;
3462
3463
9.04k
  list->sizeItems *= 2;
3464
9.04k
  tmp = (void **) xmlRealloc(list->items,
3465
9.04k
      list->sizeItems * sizeof(void *));
3466
9.04k
  if (tmp == NULL) {
3467
0
      xmlSchemaPErrMemory(NULL);
3468
0
      list->sizeItems /= 2;
3469
0
      return(-1);
3470
0
  }
3471
9.04k
        list->items = tmp;
3472
9.04k
    }
3473
253k
    list->items[list->nbItems++] = item;
3474
253k
    return(0);
3475
253k
}
3476
3477
static int
3478
xmlSchemaItemListInsert(xmlSchemaItemListPtr list, void *item, int idx)
3479
37
{
3480
37
    if (list->sizeItems <= list->nbItems) {
3481
6
        void **tmp;
3482
6
        size_t newSize = list->sizeItems == 0 ? 20 : list->sizeItems * 2;
3483
3484
6
  tmp = (void **) xmlRealloc(list->items, newSize * sizeof(void *));
3485
6
  if (tmp == NULL) {
3486
0
      xmlSchemaPErrMemory(NULL);
3487
0
      return(-1);
3488
0
  }
3489
6
        list->items = tmp;
3490
6
  list->sizeItems = newSize;
3491
6
    }
3492
    /*
3493
    * Just append if the index is greater/equal than the item count.
3494
    */
3495
37
    if (idx >= list->nbItems) {
3496
32
  list->items[list->nbItems++] = item;
3497
32
    } else {
3498
5
  int i;
3499
10
  for (i = list->nbItems; i > idx; i--)
3500
5
      list->items[i] = list->items[i-1];
3501
5
  list->items[idx] = item;
3502
5
  list->nbItems++;
3503
5
    }
3504
37
    return(0);
3505
37
}
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
1.73k
{
3553
1.73k
    int i;
3554
1.73k
    if ((list->items == NULL) || (idx >= list->nbItems))
3555
0
  return(-1);
3556
3557
1.73k
    if (list->nbItems == 1) {
3558
  /* TODO: Really free the list? */
3559
172
  xmlFree(list->items);
3560
172
  list->items = NULL;
3561
172
  list->nbItems = 0;
3562
172
  list->sizeItems = 0;
3563
1.56k
    } else if (list->nbItems -1 == idx) {
3564
163
  list->nbItems--;
3565
1.40k
    } else {
3566
11.2k
  for (i = idx; i < list->nbItems -1; i++)
3567
9.89k
      list->items[i] = list->items[i+1];
3568
1.40k
  list->nbItems--;
3569
1.40k
    }
3570
1.73k
    return(0);
3571
1.73k
}
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
122k
{
3582
122k
    if (list == NULL)
3583
0
  return;
3584
122k
    if (list->items != NULL)
3585
42.9k
  xmlFree(list->items);
3586
122k
    xmlFree(list);
3587
122k
}
3588
3589
static void
3590
xmlSchemaBucketFree(xmlSchemaBucketPtr bucket)
3591
12.6k
{
3592
12.6k
    if (bucket == NULL)
3593
0
  return;
3594
12.6k
    if (bucket->globals != NULL) {
3595
12.6k
  xmlSchemaComponentListFree(bucket->globals);
3596
12.6k
  xmlSchemaItemListFree(bucket->globals);
3597
12.6k
    }
3598
12.6k
    if (bucket->locals != NULL) {
3599
12.6k
  xmlSchemaComponentListFree(bucket->locals);
3600
12.6k
  xmlSchemaItemListFree(bucket->locals);
3601
12.6k
    }
3602
12.6k
    if (bucket->relations != NULL) {
3603
457
  xmlSchemaSchemaRelationPtr prev, cur = bucket->relations;
3604
4.70k
  do {
3605
4.70k
      prev = cur;
3606
4.70k
      cur = cur->next;
3607
4.70k
      xmlFree(prev);
3608
4.70k
  } while (cur != NULL);
3609
457
    }
3610
12.6k
    if ((! bucket->preserveDoc) && (bucket->doc != NULL)) {
3611
12.6k
  xmlFreeDoc(bucket->doc);
3612
12.6k
    }
3613
12.6k
    if (bucket->type == XML_SCHEMA_SCHEMA_IMPORT) {
3614
159
  if (WXS_IMPBUCKET(bucket)->schema != NULL)
3615
159
      xmlSchemaFree(WXS_IMPBUCKET(bucket)->schema);
3616
159
    }
3617
12.6k
    xmlFree(bucket);
3618
12.6k
}
3619
3620
static void
3621
xmlSchemaBucketFreeEntry(void *bucket, const xmlChar *name ATTRIBUTE_UNUSED)
3622
12.5k
{
3623
12.5k
    xmlSchemaBucketFree((xmlSchemaBucketPtr) bucket);
3624
12.5k
}
3625
3626
static xmlSchemaBucketPtr
3627
xmlSchemaBucketCreate(xmlSchemaParserCtxtPtr pctxt,
3628
       int type, const xmlChar *targetNamespace)
3629
12.6k
{
3630
12.6k
    xmlSchemaBucketPtr ret;
3631
12.6k
    int size;
3632
12.6k
    xmlSchemaPtr mainSchema;
3633
3634
12.6k
    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
12.6k
    mainSchema = WXS_CONSTRUCTOR(pctxt)->mainSchema;
3640
    /* Create the schema bucket. */
3641
12.6k
    if (WXS_IS_BUCKET_INCREDEF(type))
3642
107
  size = sizeof(xmlSchemaInclude);
3643
12.5k
    else
3644
12.5k
  size = sizeof(xmlSchemaImport);
3645
12.6k
    ret = (xmlSchemaBucketPtr) xmlMalloc(size);
3646
12.6k
    if (ret == NULL) {
3647
0
  xmlSchemaPErrMemory(NULL);
3648
0
  return(NULL);
3649
0
    }
3650
12.6k
    memset(ret, 0, size);
3651
12.6k
    ret->targetNamespace = targetNamespace;
3652
12.6k
    ret->type = type;
3653
12.6k
    ret->globals = xmlSchemaItemListCreate();
3654
12.6k
    if (ret->globals == NULL) {
3655
0
  xmlSchemaBucketFree(ret);
3656
0
  return(NULL);
3657
0
    }
3658
12.6k
    ret->locals = xmlSchemaItemListCreate();
3659
12.6k
    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
12.6k
    if (! WXS_HAS_BUCKETS(pctxt)) {
3671
12.4k
  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
12.4k
  ret->type = XML_SCHEMA_SCHEMA_MAIN;
3679
  /* Point to the *main* schema. */
3680
12.4k
  WXS_CONSTRUCTOR(pctxt)->mainBucket = ret;
3681
12.4k
  WXS_IMPBUCKET(ret)->schema = mainSchema;
3682
  /*
3683
  * Ensure that the main schema gets a targetNamespace.
3684
  */
3685
12.4k
  mainSchema->targetNamespace = targetNamespace;
3686
12.4k
    } else {
3687
266
  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
266
  } else if (type == XML_SCHEMA_SCHEMA_IMPORT) {
3693
      /*
3694
      * Create a schema for imports and assign the
3695
      * targetNamespace.
3696
      */
3697
159
      WXS_IMPBUCKET(ret)->schema = xmlSchemaNewSchema(pctxt);
3698
159
      if (WXS_IMPBUCKET(ret)->schema == NULL) {
3699
0
    xmlSchemaBucketFree(ret);
3700
0
    return(NULL);
3701
0
      }
3702
159
      WXS_IMPBUCKET(ret)->schema->targetNamespace = targetNamespace;
3703
159
  }
3704
266
    }
3705
12.6k
    if (WXS_IS_BUCKET_IMPMAIN(type)) {
3706
12.5k
  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
12.5k
  if (mainSchema->schemasImports == NULL) {
3713
12.4k
      mainSchema->schemasImports = xmlHashCreateDict(5,
3714
12.4k
    WXS_CONSTRUCTOR(pctxt)->dict);
3715
12.4k
      if (mainSchema->schemasImports == NULL) {
3716
0
    xmlSchemaBucketFree(ret);
3717
0
    return(NULL);
3718
0
      }
3719
12.4k
  }
3720
12.5k
  if (targetNamespace == NULL)
3721
11.4k
      res = xmlHashAddEntry(mainSchema->schemasImports,
3722
11.4k
    XML_SCHEMAS_NO_NAMESPACE, ret);
3723
1.10k
  else
3724
1.10k
      res = xmlHashAddEntry(mainSchema->schemasImports,
3725
1.10k
    targetNamespace, ret);
3726
12.5k
  if (res != 0) {
3727
2
      PERROR_INT("xmlSchemaBucketCreate",
3728
2
    "failed to add the schema bucket to the hash");
3729
2
      xmlSchemaBucketFree(ret);
3730
2
      return(NULL);
3731
2
  }
3732
12.5k
    } else {
3733
  /* Set the @ownerImport of an include bucket. */
3734
107
  if (WXS_IS_BUCKET_IMPMAIN(WXS_CONSTRUCTOR(pctxt)->bucket->type))
3735
106
      WXS_INCBUCKET(ret)->ownerImport =
3736
106
    WXS_IMPBUCKET(WXS_CONSTRUCTOR(pctxt)->bucket);
3737
1
  else
3738
1
      WXS_INCBUCKET(ret)->ownerImport =
3739
1
    WXS_INCBUCKET(WXS_CONSTRUCTOR(pctxt)->bucket)->ownerImport;
3740
3741
  /* Includes got into the "includes" slot of the *main* schema. */
3742
107
  if (mainSchema->includes == NULL) {
3743
69
      mainSchema->includes = xmlSchemaItemListCreate();
3744
69
      if (mainSchema->includes == NULL) {
3745
0
    xmlSchemaBucketFree(ret);
3746
0
    return(NULL);
3747
0
      }
3748
69
  }
3749
107
  if (xmlSchemaItemListAdd(mainSchema->includes, ret) < 0) {
3750
0
      xmlSchemaBucketFree(ret);
3751
0
      return(NULL);
3752
0
        }
3753
107
    }
3754
    /*
3755
    * Add to list of all buckets; this is used for lookup
3756
    * during schema construction time only.
3757
    */
3758
12.6k
    if (xmlSchemaItemListAdd(WXS_CONSTRUCTOR(pctxt)->buckets, ret) == -1)
3759
0
  return(NULL);
3760
12.6k
    return(ret);
3761
12.6k
}
3762
3763
static int
3764
xmlSchemaAddItemSize(xmlSchemaItemListPtr *list, int initialSize, void *item)
3765
245k
{
3766
245k
    if (*list == NULL) {
3767
0
  *list = xmlSchemaItemListCreate();
3768
0
  if (*list == NULL)
3769
0
      return(-1);
3770
0
    }
3771
245k
    return(xmlSchemaItemListAddSize(*list, initialSize, item));
3772
245k
}
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
4.25k
{
3783
4.25k
    if (annot == NULL)
3784
0
        return;
3785
4.25k
    if (annot->next == NULL) {
3786
4.19k
  xmlFree(annot);
3787
4.19k
    } else {
3788
60
  xmlSchemaAnnotPtr prev;
3789
3790
120
  do {
3791
120
      prev = annot;
3792
120
      annot = annot->next;
3793
120
      xmlFree(prev);
3794
120
  } while (annot != NULL);
3795
60
    }
3796
4.25k
}
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
1.43k
{
3807
1.43k
    if (nota == NULL)
3808
0
        return;
3809
1.43k
    if (nota->annot != NULL)
3810
312
  xmlSchemaFreeAnnot(nota->annot);
3811
1.43k
    xmlFree(nota);
3812
1.43k
}
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
5.57k
{
3823
5.57k
    if (attr == NULL)
3824
0
        return;
3825
5.57k
    if (attr->annot != NULL)
3826
99
  xmlSchemaFreeAnnot(attr->annot);
3827
5.57k
    if (attr->defVal != NULL)
3828
44
  xmlSchemaFreeValue(attr->defVal);
3829
5.57k
    xmlFree(attr);
3830
5.57k
}
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
4.46k
{
3841
4.46k
    if (use == NULL)
3842
0
        return;
3843
4.46k
    if (use->annot != NULL)
3844
85
  xmlSchemaFreeAnnot(use->annot);
3845
4.46k
    if (use->defVal != NULL)
3846
0
  xmlSchemaFreeValue(use->defVal);
3847
4.46k
    xmlFree(use);
3848
4.46k
}
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
431
{
3859
431
    if (prohib == NULL)
3860
0
        return;
3861
431
    xmlFree(prohib);
3862
431
}
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
3.86k
{
3873
3.86k
    xmlSchemaWildcardNsPtr next;
3874
3875
44.3k
    while (set != NULL) {
3876
40.4k
  next = set->next;
3877
40.4k
  xmlFree(set);
3878
40.4k
  set = next;
3879
40.4k
    }
3880
3.86k
}
3881
3882
/**
3883
 * xmlSchemaFreeWildcard:
3884
 * @wildcard:  a wildcard structure
3885
 *
3886
 * Deallocates a wildcard structure.
3887
 */
3888
void
3889
xmlSchemaFreeWildcard(xmlSchemaWildcardPtr wildcard)
3890
8.72k
{
3891
8.72k
    if (wildcard == NULL)
3892
0
        return;
3893
8.72k
    if (wildcard->annot != NULL)
3894
0
        xmlSchemaFreeAnnot(wildcard->annot);
3895
8.72k
    if (wildcard->nsSet != NULL)
3896
3.77k
  xmlSchemaFreeWildcardNsSet(wildcard->nsSet);
3897
8.72k
    if (wildcard->negNsSet != NULL)
3898
1.11k
  xmlFree(wildcard->negNsSet);
3899
8.72k
    xmlFree(wildcard);
3900
8.72k
}
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
2.35k
{
3911
2.35k
    if (attrGr == NULL)
3912
0
        return;
3913
2.35k
    if (attrGr->annot != NULL)
3914
1
        xmlSchemaFreeAnnot(attrGr->annot);
3915
2.35k
    if (attrGr->attrUses != NULL)
3916
285
  xmlSchemaItemListFree(WXS_LIST_CAST attrGr->attrUses);
3917
2.35k
    xmlFree(attrGr);
3918
2.35k
}
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
59.6k
{
3929
59.6k
    xmlFree(item);
3930
59.6k
}
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
2.28k
{
3941
2.28k
    xmlSchemaTypeLinkPtr next;
3942
3943
48.0k
    while (link != NULL) {
3944
45.7k
  next = link->next;
3945
45.7k
  xmlFree(link);
3946
45.7k
  link = next;
3947
45.7k
    }
3948
2.28k
}
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
3.62k
{
3974
3.62k
    xmlSchemaIDCSelectPtr cur, prev;
3975
3976
3.62k
    if (idcDef == NULL)
3977
0
  return;
3978
3.62k
    if (idcDef->annot != NULL)
3979
54
        xmlSchemaFreeAnnot(idcDef->annot);
3980
    /* Selector */
3981
3.62k
    if (idcDef->selector != NULL) {
3982
2.11k
  if (idcDef->selector->xpathComp != NULL)
3983
339
      xmlFreePattern((xmlPatternPtr) idcDef->selector->xpathComp);
3984
2.11k
  xmlFree(idcDef->selector);
3985
2.11k
    }
3986
    /* Fields */
3987
3.62k
    if (idcDef->fields != NULL) {
3988
1.30k
  cur = idcDef->fields;
3989
21.9k
  do {
3990
21.9k
      prev = cur;
3991
21.9k
      cur = cur->next;
3992
21.9k
      if (prev->xpathComp != NULL)
3993
2.44k
    xmlFreePattern((xmlPatternPtr) prev->xpathComp);
3994
21.9k
      xmlFree(prev);
3995
21.9k
  } while (cur != NULL);
3996
1.30k
    }
3997
3.62k
    xmlFree(idcDef);
3998
3.62k
}
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
23.6k
{
4009
23.6k
    if (elem == NULL)
4010
0
        return;
4011
23.6k
    if (elem->annot != NULL)
4012
131
        xmlSchemaFreeAnnot(elem->annot);
4013
23.6k
    if (elem->contModel != NULL)
4014
0
        xmlRegFreeRegexp(elem->contModel);
4015
23.6k
    if (elem->defVal != NULL)
4016
383
  xmlSchemaFreeValue(elem->defVal);
4017
23.6k
    xmlFree(elem);
4018
23.6k
}
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
128k
{
4029
128k
    if (facet == NULL)
4030
0
        return;
4031
128k
    if (facet->val != NULL)
4032
25.9k
        xmlSchemaFreeValue(facet->val);
4033
128k
    if (facet->regexp != NULL)
4034
7.28k
        xmlRegFreeRegexp(facet->regexp);
4035
128k
    if (facet->annot != NULL)
4036
86
        xmlSchemaFreeAnnot(facet->annot);
4037
128k
    xmlFree(facet);
4038
128k
}
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
27.1k
{
4049
27.1k
    if (type == NULL)
4050
0
        return;
4051
27.1k
    if (type->annot != NULL)
4052
531
        xmlSchemaFreeAnnot(type->annot);
4053
27.1k
    if (type->facets != NULL) {
4054
9.11k
        xmlSchemaFacetPtr facet, next;
4055
4056
9.11k
        facet = type->facets;
4057
137k
        while (facet != NULL) {
4058
128k
            next = facet->next;
4059
128k
            xmlSchemaFreeFacet(facet);
4060
128k
            facet = next;
4061
128k
        }
4062
9.11k
    }
4063
27.1k
    if (type->attrUses != NULL)
4064
2.06k
  xmlSchemaItemListFree((xmlSchemaItemListPtr) type->attrUses);
4065
27.1k
    if (type->memberTypes != NULL)
4066
2.28k
  xmlSchemaFreeTypeLinkList(type->memberTypes);
4067
27.1k
    if (type->facetSet != NULL) {
4068
9.14k
  xmlSchemaFacetLinkPtr next, link;
4069
4070
9.14k
  link = type->facetSet;
4071
129k
  do {
4072
129k
      next = link->next;
4073
129k
      xmlFree(link);
4074
129k
      link = next;
4075
129k
  } while (link != NULL);
4076
9.14k
    }
4077
27.1k
    if (type->contModel != NULL)
4078
616
        xmlRegFreeRegexp(type->contModel);
4079
27.1k
    xmlFree(type);
4080
27.1k
}
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
2.52k
{
4091
2.52k
    if (item->annot != NULL)
4092
33
  xmlSchemaFreeAnnot(item->annot);
4093
2.52k
    xmlFree(item);
4094
2.52k
}
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
5.54k
{
4105
5.54k
    if (item->annot != NULL)
4106
78
  xmlSchemaFreeAnnot(item->annot);
4107
5.54k
    xmlFree(item);
4108
5.54k
}
4109
4110
static void
4111
xmlSchemaComponentListFree(xmlSchemaItemListPtr list)
4112
25.3k
{
4113
25.3k
    if ((list == NULL) || (list->nbItems == 0))
4114
8.94k
  return;
4115
16.4k
    {
4116
16.4k
  xmlSchemaTreeItemPtr item;
4117
16.4k
  xmlSchemaTreeItemPtr *items = (xmlSchemaTreeItemPtr *) list->items;
4118
16.4k
  int i;
4119
4120
182k
  for (i = 0; i < list->nbItems; i++) {
4121
166k
      item = items[i];
4122
166k
      if (item == NULL)
4123
0
    continue;
4124
166k
      switch (item->type) {
4125
14.4k
    case XML_SCHEMA_TYPE_SIMPLE:
4126
27.1k
    case XML_SCHEMA_TYPE_COMPLEX:
4127
27.1k
        xmlSchemaFreeType((xmlSchemaTypePtr) item);
4128
27.1k
        break;
4129
5.57k
    case XML_SCHEMA_TYPE_ATTRIBUTE:
4130
5.57k
        xmlSchemaFreeAttribute((xmlSchemaAttributePtr) item);
4131
5.57k
        break;
4132
4.46k
    case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
4133
4.46k
        xmlSchemaFreeAttributeUse((xmlSchemaAttributeUsePtr) item);
4134
4.46k
        break;
4135
431
    case XML_SCHEMA_EXTRA_ATTR_USE_PROHIB:
4136
431
        xmlSchemaFreeAttributeUseProhib(
4137
431
      (xmlSchemaAttributeUseProhibPtr) item);
4138
431
        break;
4139
23.6k
    case XML_SCHEMA_TYPE_ELEMENT:
4140
23.6k
        xmlSchemaFreeElement((xmlSchemaElementPtr) item);
4141
23.6k
        break;
4142
21.1k
    case XML_SCHEMA_TYPE_PARTICLE:
4143
21.1k
        if (item->annot != NULL)
4144
11
      xmlSchemaFreeAnnot(item->annot);
4145
21.1k
        xmlFree(item);
4146
21.1k
        break;
4147
2.86k
    case XML_SCHEMA_TYPE_SEQUENCE:
4148
5.40k
    case XML_SCHEMA_TYPE_CHOICE:
4149
5.54k
    case XML_SCHEMA_TYPE_ALL:
4150
5.54k
        xmlSchemaFreeModelGroup((xmlSchemaModelGroupPtr) item);
4151
5.54k
        break;
4152
2.35k
    case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
4153
2.35k
        xmlSchemaFreeAttributeGroup(
4154
2.35k
      (xmlSchemaAttributeGroupPtr) item);
4155
2.35k
        break;
4156
2.52k
    case XML_SCHEMA_TYPE_GROUP:
4157
2.52k
        xmlSchemaFreeModelGroupDef(
4158
2.52k
      (xmlSchemaModelGroupDefPtr) item);
4159
2.52k
        break;
4160
6.27k
    case XML_SCHEMA_TYPE_ANY:
4161
8.72k
    case XML_SCHEMA_TYPE_ANY_ATTRIBUTE:
4162
8.72k
        xmlSchemaFreeWildcard((xmlSchemaWildcardPtr) item);
4163
8.72k
        break;
4164
24
    case XML_SCHEMA_TYPE_IDC_KEY:
4165
49
    case XML_SCHEMA_TYPE_IDC_UNIQUE:
4166
3.62k
    case XML_SCHEMA_TYPE_IDC_KEYREF:
4167
3.62k
        xmlSchemaFreeIDC((xmlSchemaIDCPtr) item);
4168
3.62k
        break;
4169
1.43k
    case XML_SCHEMA_TYPE_NOTATION:
4170
1.43k
        xmlSchemaFreeNotation((xmlSchemaNotationPtr) item);
4171
1.43k
        break;
4172
59.6k
    case XML_SCHEMA_EXTRA_QNAMEREF:
4173
59.6k
        xmlSchemaFreeQNameRef((xmlSchemaQNameRefPtr) item);
4174
59.6k
        break;
4175
0
    default:
4176
        /* TODO: This should never be hit. */
4177
0
        break;
4178
166k
      }
4179
166k
  }
4180
16.4k
  list->nbItems = 0;
4181
16.4k
    }
4182
16.4k
}
4183
4184
/**
4185
 * xmlSchemaFree:
4186
 * @schema:  a schema structure
4187
 *
4188
 * Deallocate a Schema structure.
4189
 */
4190
void
4191
xmlSchemaFree(xmlSchemaPtr schema)
4192
55.2k
{
4193
55.2k
    if (schema == NULL)
4194
26.0k
        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
29.2k
    if (schema->notaDecl != NULL)
4201
0
        xmlHashFree(schema->notaDecl, NULL);
4202
29.2k
    if (schema->attrDecl != NULL)
4203
369
        xmlHashFree(schema->attrDecl, NULL);
4204
29.2k
    if (schema->attrgrpDecl != NULL)
4205
235
        xmlHashFree(schema->attrgrpDecl, NULL);
4206
29.2k
    if (schema->elemDecl != NULL)
4207
2.30k
        xmlHashFree(schema->elemDecl, NULL);
4208
29.2k
    if (schema->typeDecl != NULL)
4209
5.72k
        xmlHashFree(schema->typeDecl, NULL);
4210
29.2k
    if (schema->groupDecl != NULL)
4211
158
        xmlHashFree(schema->groupDecl, NULL);
4212
29.2k
    if (schema->idcDef != NULL)
4213
12
        xmlHashFree(schema->idcDef, NULL);
4214
4215
29.2k
    if (schema->schemasImports != NULL)
4216
12.4k
  xmlHashFree(schema->schemasImports, xmlSchemaBucketFreeEntry);
4217
29.2k
    if (schema->includes != NULL) {
4218
69
  xmlSchemaItemListPtr list = (xmlSchemaItemListPtr) schema->includes;
4219
69
  int i;
4220
176
  for (i = 0; i < list->nbItems; i++) {
4221
107
      xmlSchemaBucketFree((xmlSchemaBucketPtr) list->items[i]);
4222
107
  }
4223
69
  xmlSchemaItemListFree(list);
4224
69
    }
4225
29.2k
    if (schema->annot != NULL)
4226
830
        xmlSchemaFreeAnnot(schema->annot);
4227
    /* Never free the doc here, since this will be done by the buckets. */
4228
4229
29.2k
    xmlDictFree(schema->dict);
4230
29.2k
    xmlFree(schema);
4231
29.2k
}
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
676k
{
4633
676k
    xmlAttrPtr prop;
4634
4635
676k
    if ((node == NULL) || (name == NULL))
4636
0
  return(NULL);
4637
676k
    prop = node->properties;
4638
1.38M
    while (prop != NULL) {
4639
857k
        if ((prop->ns == NULL) && xmlStrEqual(prop->name, BAD_CAST name))
4640
145k
      return(prop);
4641
711k
  prop = prop->next;
4642
711k
    }
4643
531k
    return (NULL);
4644
676k
}
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
1.03k
{
4660
1.03k
    xmlAttrPtr prop;
4661
4662
1.03k
    if ((node == NULL) || (name == NULL))
4663
0
  return(NULL);
4664
1.03k
    prop = node->properties;
4665
1.84k
    while (prop != NULL) {
4666
1.00k
  if ((prop->ns != NULL) &&
4667
1.00k
      xmlStrEqual(prop->name, BAD_CAST name) &&
4668
1.00k
      xmlStrEqual(prop->ns->href, BAD_CAST uri))
4669
204
      return(prop);
4670
802
  prop = prop->next;
4671
802
    }
4672
834
    return (NULL);
4673
1.03k
}
4674
4675
static const xmlChar *
4676
xmlSchemaGetNodeContent(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node)
4677
149k
{
4678
149k
    xmlChar *val;
4679
149k
    const xmlChar *ret;
4680
4681
149k
    val = xmlNodeGetContent(node);
4682
149k
    if (val == NULL)
4683
3.39k
  val = xmlStrdup((xmlChar *)"");
4684
149k
    ret = xmlDictLookup(ctxt->dict, val, -1);
4685
149k
    xmlFree(val);
4686
149k
    if (ret == NULL)
4687
0
        xmlSchemaPErrMemory(ctxt);
4688
149k
    return(ret);
4689
149k
}
4690
4691
static const xmlChar *
4692
xmlSchemaGetNodeContentNoDict(xmlNodePtr node)
4693
5.07k
{
4694
5.07k
    return((const xmlChar*) xmlNodeGetContent(node));
4695
5.07k
}
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
286k
{
4711
286k
    xmlChar *val;
4712
286k
    const xmlChar *ret;
4713
4714
286k
    val = xmlGetNoNsProp(node, BAD_CAST name);
4715
286k
    if (val == NULL)
4716
148k
        return(NULL);
4717
138k
    ret = xmlDictLookup(ctxt->dict, val, -1);
4718
138k
    xmlFree(val);
4719
138k
    return(ret);
4720
286k
}
4721
4722
/************************************************************************
4723
 *                  *
4724
 *      Parsing functions       *
4725
 *                  *
4726
 ************************************************************************/
4727
4728
#define WXS_FIND_GLOBAL_ITEM(slot)      \
4729
11.0k
    if (xmlStrEqual(nsName, schema->targetNamespace)) { \
4730
4.78k
  ret = xmlHashLookup(schema->slot, name); \
4731
4.78k
  if (ret != NULL) goto exit; \
4732
4.78k
    } \
4733
11.0k
    if (xmlHashSize(schema->schemasImports) > 1) { \
4734
456
  xmlSchemaImportPtr import; \
4735
456
  if (nsName == NULL) \
4736
456
      import = xmlHashLookup(schema->schemasImports, \
4737
108
    XML_SCHEMAS_NO_NAMESPACE); \
4738
456
  else \
4739
456
      import = xmlHashLookup(schema->schemasImports, nsName); \
4740
456
  if (import == NULL) \
4741
456
      goto exit; \
4742
456
  ret = xmlHashLookup(import->schema->slot, name); \
4743
414
    }
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
1.13k
{
4759
1.13k
    xmlSchemaElementPtr ret = NULL;
4760
4761
1.13k
    if ((name == NULL) || (schema == NULL))
4762
0
        return(NULL);
4763
1.13k
    if (schema != NULL) {
4764
1.13k
  WXS_FIND_GLOBAL_ITEM(elemDecl)
4765
257
    }
4766
1.13k
exit:
4767
1.13k
    return (ret);
4768
1.13k
}
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
20.8k
{
4784
20.8k
    xmlSchemaTypePtr ret = NULL;
4785
4786
20.8k
    if (name == NULL)
4787
0
        return (NULL);
4788
    /* First try the built-in types. */
4789
20.8k
    if ((nsName != NULL) && xmlStrEqual(nsName, xmlSchemaNs)) {
4790
18.8k
  ret = xmlSchemaGetPredefinedType(name, nsName);
4791
18.8k
  if (ret != NULL)
4792
12.9k
      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
18.8k
    }
4800
7.87k
    if (schema != NULL) {
4801
7.87k
  WXS_FIND_GLOBAL_ITEM(typeDecl)
4802
6.18k
    }
4803
20.8k
exit:
4804
4805
20.8k
    return (ret);
4806
7.87k
}
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
173
{
4822
173
    xmlSchemaAttributePtr ret = NULL;
4823
4824
173
    if ((name == NULL) || (schema == NULL))
4825
0
        return (NULL);
4826
173
    if (schema != NULL) {
4827
173
  WXS_FIND_GLOBAL_ITEM(attrDecl)
4828
97
    }
4829
173
exit:
4830
173
    return (ret);
4831
173
}
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
1.73k
{
4847
1.73k
    xmlSchemaAttributeGroupPtr ret = NULL;
4848
4849
1.73k
    if ((name == NULL) || (schema == NULL))
4850
0
        return (NULL);
4851
1.73k
    if (schema != NULL) {
4852
1.73k
  WXS_FIND_GLOBAL_ITEM(attrgrpDecl)
4853
497
    }
4854
1.73k
exit:
4855
    /* TODO:
4856
    if ((ret != NULL) && (ret->redef != NULL)) {
4857
  * Return the last redefinition. *
4858
  ret = ret->redef;
4859
    }
4860
    */
4861
1.73k
    return (ret);
4862
1.73k
}
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
88
{
4878
88
    xmlSchemaModelGroupDefPtr ret = NULL;
4879
4880
88
    if ((name == NULL) || (schema == NULL))
4881
0
        return (NULL);
4882
88
    if (schema != NULL) {
4883
88
  WXS_FIND_GLOBAL_ITEM(groupDecl)
4884
43
    }
4885
88
exit:
4886
4887
88
    return (ret);
4888
88
}
4889
4890
static xmlSchemaNotationPtr
4891
xmlSchemaGetNotation(xmlSchemaPtr schema,
4892
         const xmlChar *name,
4893
         const xmlChar *nsName)
4894
17
{
4895
17
    xmlSchemaNotationPtr ret = NULL;
4896
4897
17
    if ((name == NULL) || (schema == NULL))
4898
0
        return (NULL);
4899
17
    if (schema != NULL) {
4900
17
  WXS_FIND_GLOBAL_ITEM(notaDecl)
4901
17
    }
4902
17
exit:
4903
17
    return (ret);
4904
17
}
4905
4906
static xmlSchemaIDCPtr
4907
xmlSchemaGetIDC(xmlSchemaPtr schema,
4908
    const xmlChar *name,
4909
    const xmlChar *nsName)
4910
4
{
4911
4
    xmlSchemaIDCPtr ret = NULL;
4912
4913
4
    if ((name == NULL) || (schema == NULL))
4914
0
        return (NULL);
4915
4
    if (schema != NULL) {
4916
4
  WXS_FIND_GLOBAL_ITEM(idcDef)
4917
1
    }
4918
4
exit:
4919
4
    return (ret);
4920
4
}
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
 *
4930
 * Returns the group definition or NULL if not found.
4931
 */
4932
static xmlSchemaBasicItemPtr
4933
xmlSchemaGetNamedComponent(xmlSchemaPtr schema,
4934
         xmlSchemaTypeType itemType,
4935
         const xmlChar *name,
4936
         const xmlChar *targetNs)
4937
1.12k
{
4938
1.12k
    switch (itemType) {
4939
88
  case XML_SCHEMA_TYPE_GROUP:
4940
88
      return ((xmlSchemaBasicItemPtr) xmlSchemaGetGroup(schema,
4941
88
    name, targetNs));
4942
1.03k
  case XML_SCHEMA_TYPE_ELEMENT:
4943
1.03k
      return ((xmlSchemaBasicItemPtr) xmlSchemaGetElem(schema,
4944
1.03k
    name, targetNs));
4945
0
  default:
4946
      /* TODO */
4947
0
      return (NULL);
4948
1.12k
    }
4949
1.12k
}
4950
4951
/************************************************************************
4952
 *                  *
4953
 *      Parsing functions       *
4954
 *                  *
4955
 ************************************************************************/
4956
4957
#define IS_BLANK_NODE(n)            \
4958
384k
    (((n)->type == XML_TEXT_NODE) && (xmlSchemaIsBlank((n)->content, -1)))
4959
4960
/**
4961
 * xmlSchemaIsBlank:
4962
 * @str:  a string
4963
 * @len: the length of the string or -1
4964
 *
4965
 * Check if a string is ignorable
4966
 *
4967
 * Returns 1 if the string is NULL or made of blanks chars, 0 otherwise
4968
 */
4969
static int
4970
xmlSchemaIsBlank(xmlChar * str, int len)
4971
384k
{
4972
384k
    if (str == NULL)
4973
0
        return (1);
4974
384k
    if (len < 0) {
4975
1.82M
  while (*str != 0) {
4976
1.52M
      if (!(IS_BLANK_CH(*str)))
4977
93.6k
    return (0);
4978
1.43M
      str++;
4979
1.43M
  }
4980
384k
    } else while ((*str != 0) && (len != 0)) {
4981
0
  if (!(IS_BLANK_CH(*str)))
4982
0
      return (0);
4983
0
  str++;
4984
0
  len--;
4985
0
    }
4986
4987
290k
    return (1);
4988
384k
}
4989
4990
0
#define WXS_COMP_NAME(c, t) ((t) (c))->name
4991
0
#define WXS_COMP_TNS(c, t) ((t) (c))->targetNamespace
4992
/*
4993
* xmlSchemaFindRedefCompInGraph:
4994
* ATTENTION TODO: This uses pointer comp. for strings.
4995
*/
4996
static xmlSchemaBasicItemPtr
4997
xmlSchemaFindRedefCompInGraph(xmlSchemaBucketPtr bucket,
4998
            xmlSchemaTypeType type,
4999
            const xmlChar *name,
5000
            const xmlChar *nsName)
5001
0
{
5002
0
    xmlSchemaBasicItemPtr ret;
5003
0
    int i;
5004
5005
0
    if ((bucket == NULL) || (name == NULL))
5006
0
  return(NULL);
5007
0
    if ((bucket->globals == NULL) ||
5008
0
  (bucket->globals->nbItems == 0))
5009
0
  goto subschemas;
5010
    /*
5011
    * Search in global components.
5012
    */
5013
0
    for (i = 0; i < bucket->globals->nbItems; i++) {
5014
0
  ret = bucket->globals->items[i];
5015
0
  if (ret->type == type) {
5016
0
      switch (type) {
5017
0
    case XML_SCHEMA_TYPE_COMPLEX:
5018
0
    case XML_SCHEMA_TYPE_SIMPLE:
5019
0
        if ((WXS_COMP_NAME(ret, xmlSchemaTypePtr) == name) &&
5020
0
      (WXS_COMP_TNS(ret, xmlSchemaTypePtr) ==
5021
0
      nsName))
5022
0
        {
5023
0
      return(ret);
5024
0
        }
5025
0
        break;
5026
0
    case XML_SCHEMA_TYPE_GROUP:
5027
0
        if ((WXS_COMP_NAME(ret,
5028
0
          xmlSchemaModelGroupDefPtr) == name) &&
5029
0
      (WXS_COMP_TNS(ret,
5030
0
          xmlSchemaModelGroupDefPtr) == nsName))
5031
0
        {
5032
0
      return(ret);
5033
0
        }
5034
0
        break;
5035
0
    case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
5036
0
        if ((WXS_COMP_NAME(ret,
5037
0
          xmlSchemaAttributeGroupPtr) == name) &&
5038
0
      (WXS_COMP_TNS(ret,
5039
0
          xmlSchemaAttributeGroupPtr) == nsName))
5040
0
        {
5041
0
      return(ret);
5042
0
        }
5043
0
        break;
5044
0
    default:
5045
        /* Should not be hit. */
5046
0
        return(NULL);
5047
0
      }
5048
0
  }
5049
0
    }
5050
0
subschemas:
5051
    /*
5052
    * Process imported/included schemas.
5053
    */
5054
0
    if (bucket->relations != NULL) {
5055
0
  xmlSchemaSchemaRelationPtr rel = bucket->relations;
5056
5057
  /*
5058
  * TODO: Marking the bucket will not avoid multiple searches
5059
  * in the same schema, but avoids at least circularity.
5060
  */
5061
0
  bucket->flags |= XML_SCHEMA_BUCKET_MARKED;
5062
0
  do {
5063
0
      if ((rel->bucket != NULL) &&
5064
0
    ((rel->bucket->flags & XML_SCHEMA_BUCKET_MARKED) == 0)) {
5065
0
    ret = xmlSchemaFindRedefCompInGraph(rel->bucket,
5066
0
        type, name, nsName);
5067
0
    if (ret != NULL)
5068
0
        return(ret);
5069
0
      }
5070
0
      rel = rel->next;
5071
0
  } while (rel != NULL);
5072
0
   bucket->flags ^= XML_SCHEMA_BUCKET_MARKED;
5073
0
    }
5074
0
    return(NULL);
5075
0
}
5076
5077
/**
5078
 * xmlSchemaAddNotation:
5079
 * @ctxt:  a schema parser context
5080
 * @schema:  the schema being built
5081
 * @name:  the item name
5082
 *
5083
 * Add an XML schema annotation declaration
5084
 * *WARNING* this interface is highly subject to change
5085
 *
5086
 * Returns the new structure or NULL in case of error
5087
 */
5088
static xmlSchemaNotationPtr
5089
xmlSchemaAddNotation(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
5090
                     const xmlChar *name, const xmlChar *nsName,
5091
         xmlNodePtr node ATTRIBUTE_UNUSED)
5092
1.43k
{
5093
1.43k
    xmlSchemaNotationPtr ret = NULL;
5094
5095
1.43k
    if ((ctxt == NULL) || (schema == NULL) || (name == NULL))
5096
0
        return (NULL);
5097
5098
1.43k
    ret = (xmlSchemaNotationPtr) xmlMalloc(sizeof(xmlSchemaNotation));
5099
1.43k
    if (ret == NULL) {
5100
0
        xmlSchemaPErrMemory(ctxt);
5101
0
        return (NULL);
5102
0
    }
5103
1.43k
    memset(ret, 0, sizeof(xmlSchemaNotation));
5104
1.43k
    ret->type = XML_SCHEMA_TYPE_NOTATION;
5105
1.43k
    ret->name = name;
5106
1.43k
    ret->targetNamespace = nsName;
5107
    /* TODO: do we need the node to be set?
5108
    * ret->node = node;*/
5109
1.43k
    WXS_ADD_GLOBAL(ctxt, ret);
5110
1.43k
    return (ret);
5111
1.43k
}
5112
5113
/**
5114
 * xmlSchemaAddAttribute:
5115
 * @ctxt:  a schema parser context
5116
 * @schema:  the schema being built
5117
 * @name:  the item name
5118
 * @namespace:  the namespace
5119
 *
5120
 * Add an XML schema Attribute declaration
5121
 * *WARNING* this interface is highly subject to change
5122
 *
5123
 * Returns the new structure or NULL in case of error
5124
 */
5125
static xmlSchemaAttributePtr
5126
xmlSchemaAddAttribute(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
5127
                      const xmlChar * name, const xmlChar * nsName,
5128
          xmlNodePtr node, int topLevel)
5129
5.57k
{
5130
5.57k
    xmlSchemaAttributePtr ret = NULL;
5131
5132
5.57k
    if ((ctxt == NULL) || (schema == NULL))
5133
0
        return (NULL);
5134
5135
5.57k
    ret = (xmlSchemaAttributePtr) xmlMalloc(sizeof(xmlSchemaAttribute));
5136
5.57k
    if (ret == NULL) {
5137
0
        xmlSchemaPErrMemory(ctxt);
5138
0
        return (NULL);
5139
0
    }
5140
5.57k
    memset(ret, 0, sizeof(xmlSchemaAttribute));
5141
5.57k
    ret->type = XML_SCHEMA_TYPE_ATTRIBUTE;
5142
5.57k
    ret->node = node;
5143
5.57k
    ret->name = name;
5144
5.57k
    ret->targetNamespace = nsName;
5145
5146
5.57k
    if (topLevel)
5147
2.68k
  WXS_ADD_GLOBAL(ctxt, ret);
5148
2.89k
    else
5149
2.89k
  WXS_ADD_LOCAL(ctxt, ret);
5150
5.57k
    WXS_ADD_PENDING(ctxt, ret);
5151
5.57k
    return (ret);
5152
5.57k
}
5153
5154
/**
5155
 * xmlSchemaAddAttributeUse:
5156
 * @ctxt:  a schema parser context
5157
 * @schema:  the schema being built
5158
 * @name:  the item name
5159
 * @namespace:  the namespace
5160
 *
5161
 * Add an XML schema Attribute declaration
5162
 * *WARNING* this interface is highly subject to change
5163
 *
5164
 * Returns the new structure or NULL in case of error
5165
 */
5166
static xmlSchemaAttributeUsePtr
5167
xmlSchemaAddAttributeUse(xmlSchemaParserCtxtPtr pctxt,
5168
       xmlNodePtr node)
5169
4.46k
{
5170
4.46k
    xmlSchemaAttributeUsePtr ret = NULL;
5171
5172
4.46k
    if (pctxt == NULL)
5173
0
        return (NULL);
5174
5175
4.46k
    ret = (xmlSchemaAttributeUsePtr) xmlMalloc(sizeof(xmlSchemaAttributeUse));
5176
4.46k
    if (ret == NULL) {
5177
0
        xmlSchemaPErrMemory(pctxt);
5178
0
        return (NULL);
5179
0
    }
5180
4.46k
    memset(ret, 0, sizeof(xmlSchemaAttributeUse));
5181
4.46k
    ret->type = XML_SCHEMA_TYPE_ATTRIBUTE_USE;
5182
4.46k
    ret->node = node;
5183
5184
4.46k
    WXS_ADD_LOCAL(pctxt, ret);
5185
4.46k
    return (ret);
5186
4.46k
}
5187
5188
/*
5189
* xmlSchemaAddRedef:
5190
*
5191
* Adds a redefinition information. This is used at a later stage to:
5192
* resolve references to the redefined components and to check constraints.
5193
*/
5194
static xmlSchemaRedefPtr
5195
xmlSchemaAddRedef(xmlSchemaParserCtxtPtr pctxt,
5196
      xmlSchemaBucketPtr targetBucket,
5197
      void *item,
5198
      const xmlChar *refName,
5199
      const xmlChar *refTargetNs)
5200
0
{
5201
0
    xmlSchemaRedefPtr ret;
5202
5203
0
    ret = (xmlSchemaRedefPtr)
5204
0
  xmlMalloc(sizeof(xmlSchemaRedef));
5205
0
    if (ret == NULL) {
5206
0
  xmlSchemaPErrMemory(pctxt);
5207
0
  return (NULL);
5208
0
    }
5209
0
    memset(ret, 0, sizeof(xmlSchemaRedef));
5210
0
    ret->item = item;
5211
0
    ret->targetBucket = targetBucket;
5212
0
    ret->refName = refName;
5213
0
    ret->refTargetNs = refTargetNs;
5214
0
    if (WXS_CONSTRUCTOR(pctxt)->redefs == NULL)
5215
0
  WXS_CONSTRUCTOR(pctxt)->redefs = ret;
5216
0
    else
5217
0
  WXS_CONSTRUCTOR(pctxt)->lastRedef->next = ret;
5218
0
    WXS_CONSTRUCTOR(pctxt)->lastRedef = ret;
5219
5220
0
    return (ret);
5221
0
}
5222
5223
/**
5224
 * xmlSchemaAddAttributeGroupDefinition:
5225
 * @ctxt:  a schema parser context
5226
 * @schema:  the schema being built
5227
 * @name:  the item name
5228
 * @nsName:  the target namespace
5229
 * @node: the corresponding node
5230
 *
5231
 * Add an XML schema Attribute Group definition.
5232
 *
5233
 * Returns the new structure or NULL in case of error
5234
 */
5235
static xmlSchemaAttributeGroupPtr
5236
xmlSchemaAddAttributeGroupDefinition(xmlSchemaParserCtxtPtr pctxt,
5237
                           xmlSchemaPtr schema ATTRIBUTE_UNUSED,
5238
         const xmlChar *name,
5239
         const xmlChar *nsName,
5240
         xmlNodePtr node)
5241
2.35k
{
5242
2.35k
    xmlSchemaAttributeGroupPtr ret = NULL;
5243
5244
2.35k
    if ((pctxt == NULL) || (name == NULL))
5245
0
        return (NULL);
5246
5247
2.35k
    ret = (xmlSchemaAttributeGroupPtr)
5248
2.35k
        xmlMalloc(sizeof(xmlSchemaAttributeGroup));
5249
2.35k
    if (ret == NULL) {
5250
0
  xmlSchemaPErrMemory(pctxt);
5251
0
  return (NULL);
5252
0
    }
5253
2.35k
    memset(ret, 0, sizeof(xmlSchemaAttributeGroup));
5254
2.35k
    ret->type = XML_SCHEMA_TYPE_ATTRIBUTEGROUP;
5255
2.35k
    ret->name = name;
5256
2.35k
    ret->targetNamespace = nsName;
5257
2.35k
    ret->node = node;
5258
5259
    /* TODO: Remove the flag. */
5260
2.35k
    ret->flags |= XML_SCHEMAS_ATTRGROUP_GLOBAL;
5261
2.35k
    if (pctxt->isRedefine) {
5262
0
  pctxt->redef = xmlSchemaAddRedef(pctxt, pctxt->redefined,
5263
0
      ret, name, nsName);
5264
0
  if (pctxt->redef == NULL) {
5265
0
      xmlFree(ret);
5266
0
      return(NULL);
5267
0
  }
5268
0
  pctxt->redefCounter = 0;
5269
0
    }
5270
2.35k
    WXS_ADD_GLOBAL(pctxt, ret);
5271
2.35k
    WXS_ADD_PENDING(pctxt, ret);
5272
2.35k
    return (ret);
5273
2.35k
}
5274
5275
/**
5276
 * xmlSchemaAddElement:
5277
 * @ctxt:  a schema parser context
5278
 * @schema:  the schema being built
5279
 * @name:  the type name
5280
 * @namespace:  the type namespace
5281
 *
5282
 * Add an XML schema Element declaration
5283
 * *WARNING* this interface is highly subject to change
5284
 *
5285
 * Returns the new structure or NULL in case of error
5286
 */
5287
static xmlSchemaElementPtr
5288
xmlSchemaAddElement(xmlSchemaParserCtxtPtr ctxt,
5289
                    const xmlChar * name, const xmlChar * nsName,
5290
        xmlNodePtr node, int topLevel)
5291
23.6k
{
5292
23.6k
    xmlSchemaElementPtr ret = NULL;
5293
5294
23.6k
    if ((ctxt == NULL) || (name == NULL))
5295
0
        return (NULL);
5296
5297
23.6k
    ret = (xmlSchemaElementPtr) xmlMalloc(sizeof(xmlSchemaElement));
5298
23.6k
    if (ret == NULL) {
5299
0
        xmlSchemaPErrMemory(ctxt);
5300
0
        return (NULL);
5301
0
    }
5302
23.6k
    memset(ret, 0, sizeof(xmlSchemaElement));
5303
23.6k
    ret->type = XML_SCHEMA_TYPE_ELEMENT;
5304
23.6k
    ret->name = name;
5305
23.6k
    ret->targetNamespace = nsName;
5306
23.6k
    ret->node = node;
5307
5308
23.6k
    if (topLevel)
5309
17.7k
  WXS_ADD_GLOBAL(ctxt, ret);
5310
5.91k
    else
5311
5.91k
  WXS_ADD_LOCAL(ctxt, ret);
5312
23.6k
    WXS_ADD_PENDING(ctxt, ret);
5313
23.6k
    return (ret);
5314
23.6k
}
5315
5316
/**
5317
 * xmlSchemaAddType:
5318
 * @ctxt:  a schema parser context
5319
 * @schema:  the schema being built
5320
 * @name:  the item name
5321
 * @namespace:  the namespace
5322
 *
5323
 * Add an XML schema item
5324
 * *WARNING* this interface is highly subject to change
5325
 *
5326
 * Returns the new structure or NULL in case of error
5327
 */
5328
static xmlSchemaTypePtr
5329
xmlSchemaAddType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
5330
     xmlSchemaTypeType type,
5331
                 const xmlChar * name, const xmlChar * nsName,
5332
     xmlNodePtr node, int topLevel)
5333
27.1k
{
5334
27.1k
    xmlSchemaTypePtr ret = NULL;
5335
5336
27.1k
    if ((ctxt == NULL) || (schema == NULL))
5337
0
        return (NULL);
5338
5339
27.1k
    ret = (xmlSchemaTypePtr) xmlMalloc(sizeof(xmlSchemaType));
5340
27.1k
    if (ret == NULL) {
5341
0
        xmlSchemaPErrMemory(ctxt);
5342
0
        return (NULL);
5343
0
    }
5344
27.1k
    memset(ret, 0, sizeof(xmlSchemaType));
5345
27.1k
    ret->type = type;
5346
27.1k
    ret->name = name;