-
Notifications
You must be signed in to change notification settings - Fork 371
/
xmlschemastypes.c
6195 lines (5768 loc) · 177 KB
/
xmlschemastypes.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* schemastypes.c : implementation of the XML Schema Datatypes
* definition and validity checking
*
* See Copyright for the status of this software.
*
* Daniel Veillard <[email protected]>
*/
/* To avoid EBCDIC trouble when parsing on zOS */
#if defined(__MVS__)
#pragma convert("ISO8859-1")
#endif
#define IN_LIBXML
#include "libxml.h"
#ifdef LIBXML_SCHEMAS_ENABLED
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include <libxml/parserInternals.h>
#include <libxml/hash.h>
#include <libxml/xpath.h>
#include <libxml/uri.h>
#include <string.h>
#include <libxml/xmlschemas.h>
#include <libxml/schemasInternals.h>
#include <libxml/xmlschemastypes.h>
#include "private/error.h"
#ifndef isnan
#define isnan(x) (!((x) == (x)))
#endif
#define XML_SCHEMAS_NAMESPACE_NAME \
(const xmlChar *)"http://www.w3.org/2001/XMLSchema"
#define IS_WSP_REPLACE_CH(c) ((((c) == 0x9) || ((c) == 0xa)) || \
((c) == 0xd))
#define IS_WSP_SPACE_CH(c) ((c) == 0x20)
#define IS_WSP_BLANK_CH(c) IS_BLANK_CH(c)
/* Date value */
typedef struct _xmlSchemaValDate xmlSchemaValDate;
typedef xmlSchemaValDate *xmlSchemaValDatePtr;
struct _xmlSchemaValDate {
long year;
unsigned int mon :4; /* 1 <= mon <= 12 */
unsigned int day :5; /* 1 <= day <= 31 */
unsigned int hour :5; /* 0 <= hour <= 24 */
unsigned int min :6; /* 0 <= min <= 59 */
double sec;
unsigned int tz_flag :1; /* is tzo explicitly set? */
signed int tzo :12; /* -1440 <= tzo <= 1440;
currently only -840 to +840 are needed */
};
/* Duration value */
typedef struct _xmlSchemaValDuration xmlSchemaValDuration;
typedef xmlSchemaValDuration *xmlSchemaValDurationPtr;
struct _xmlSchemaValDuration {
long mon; /* mon stores years also */
long day;
double sec; /* sec stores min and hour also */
};
typedef struct _xmlSchemaValDecimal xmlSchemaValDecimal;
typedef xmlSchemaValDecimal *xmlSchemaValDecimalPtr;
struct _xmlSchemaValDecimal
{
xmlChar *str;
unsigned integralPlaces;
unsigned fractionalPlaces;
};
typedef struct _xmlSchemaValQName xmlSchemaValQName;
typedef xmlSchemaValQName *xmlSchemaValQNamePtr;
struct _xmlSchemaValQName {
xmlChar *name;
xmlChar *uri;
};
typedef struct _xmlSchemaValHex xmlSchemaValHex;
typedef xmlSchemaValHex *xmlSchemaValHexPtr;
struct _xmlSchemaValHex {
xmlChar *str;
unsigned int total;
};
typedef struct _xmlSchemaValBase64 xmlSchemaValBase64;
typedef xmlSchemaValBase64 *xmlSchemaValBase64Ptr;
struct _xmlSchemaValBase64 {
xmlChar *str;
unsigned int total;
};
struct _xmlSchemaVal {
xmlSchemaValType type;
struct _xmlSchemaVal *next;
union {
xmlSchemaValDecimal decimal;
xmlSchemaValDate date;
xmlSchemaValDuration dur;
xmlSchemaValQName qname;
xmlSchemaValHex hex;
xmlSchemaValBase64 base64;
float f;
double d;
int b;
xmlChar *str;
} value;
};
static int xmlSchemaTypesInitialized = 0;
static double xmlSchemaNAN = 0.0;
static double xmlSchemaPINF = 0.0;
static double xmlSchemaNINF = 0.0;
static xmlHashTablePtr xmlSchemaTypesBank = NULL;
/*
* Basic types
*/
static xmlSchemaTypePtr xmlSchemaTypeStringDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeAnyTypeDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeAnySimpleTypeDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeDecimalDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeDatetimeDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeDateDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeTimeDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeGYearDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeGYearMonthDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeGDayDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeGMonthDayDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeGMonthDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeDurationDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeFloatDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeBooleanDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeDoubleDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeHexBinaryDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeBase64BinaryDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeAnyURIDef = NULL;
/*
* Derived types
*/
static xmlSchemaTypePtr xmlSchemaTypePositiveIntegerDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeNonPositiveIntegerDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeNegativeIntegerDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeNonNegativeIntegerDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeIntegerDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeLongDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeIntDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeShortDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeByteDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeUnsignedLongDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeUnsignedIntDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeUnsignedShortDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeUnsignedByteDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeNormStringDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeTokenDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeLanguageDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeNameDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeQNameDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeNCNameDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeIdDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeIdrefDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeIdrefsDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeEntityDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeEntitiesDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeNotationDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeNmtokenDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeNmtokensDef = NULL;
/************************************************************************
* *
* Datatype error handlers *
* *
************************************************************************/
/**
* xmlSchemaTypeErrMemory:
* @extra: extra information
*
* Handle an out of memory condition
*/
static void
xmlSchemaTypeErrMemory(void)
{
xmlRaiseMemoryError(NULL, NULL, NULL, XML_FROM_DATATYPE, NULL);
}
/************************************************************************
* *
* Base types support *
* *
************************************************************************/
/**
* xmlSchemaNewValue:
* @type: the value type
*
* Allocate a new simple type value
*
* Returns a pointer to the new value or NULL in case of error
*/
static xmlSchemaValPtr
xmlSchemaNewValue(xmlSchemaValType type) {
xmlSchemaValPtr value;
value = (xmlSchemaValPtr) xmlMalloc(sizeof(xmlSchemaVal));
if (value == NULL) {
return(NULL);
}
memset(value, 0, sizeof(xmlSchemaVal));
value->type = type;
return(value);
}
static xmlSchemaFacetPtr
xmlSchemaNewMinLengthFacet(int value)
{
xmlSchemaFacetPtr ret;
size_t bufsize;
xmlSchemaValDecimal *decimal;
ret = xmlSchemaNewFacet();
if (ret == NULL) {
return(NULL);
}
ret->type = XML_SCHEMA_FACET_MINLENGTH;
ret->val = xmlSchemaNewValue(XML_SCHEMAS_NNINTEGER);
if (ret->val == NULL) {
xmlFree(ret);
return(NULL);
}
bufsize = snprintf(NULL, 0, "%+d.0", value) + 1;
decimal = &ret->val->value.decimal;
decimal->str = xmlMalloc(bufsize);
if (decimal->str == NULL)
{
xmlSchemaFreeFacet(ret);
return NULL;
}
snprintf((char *)decimal->str, bufsize, "%+d.0", value);
decimal->integralPlaces = bufsize - 4;
decimal->fractionalPlaces = 1;
return (ret);
}
/*
* xmlSchemaInitBasicType:
* @name: the type name
* @type: the value type associated
*
* Initialize one primitive built-in type
*/
static xmlSchemaTypePtr
xmlSchemaInitBasicType(const char *name, xmlSchemaValType type,
xmlSchemaTypePtr baseType) {
xmlSchemaTypePtr ret;
ret = (xmlSchemaTypePtr) xmlMalloc(sizeof(xmlSchemaType));
if (ret == NULL) {
xmlSchemaTypeErrMemory();
return(NULL);
}
memset(ret, 0, sizeof(xmlSchemaType));
ret->name = (const xmlChar *)name;
ret->targetNamespace = XML_SCHEMAS_NAMESPACE_NAME;
ret->type = XML_SCHEMA_TYPE_BASIC;
ret->baseType = baseType;
ret->contentType = XML_SCHEMA_CONTENT_BASIC;
/*
* Primitive types.
*/
switch (type) {
case XML_SCHEMAS_STRING:
case XML_SCHEMAS_DECIMAL:
case XML_SCHEMAS_DATE:
case XML_SCHEMAS_DATETIME:
case XML_SCHEMAS_TIME:
case XML_SCHEMAS_GYEAR:
case XML_SCHEMAS_GYEARMONTH:
case XML_SCHEMAS_GMONTH:
case XML_SCHEMAS_GMONTHDAY:
case XML_SCHEMAS_GDAY:
case XML_SCHEMAS_DURATION:
case XML_SCHEMAS_FLOAT:
case XML_SCHEMAS_DOUBLE:
case XML_SCHEMAS_BOOLEAN:
case XML_SCHEMAS_ANYURI:
case XML_SCHEMAS_HEXBINARY:
case XML_SCHEMAS_BASE64BINARY:
case XML_SCHEMAS_QNAME:
case XML_SCHEMAS_NOTATION:
ret->flags |= XML_SCHEMAS_TYPE_BUILTIN_PRIMITIVE;
break;
default:
break;
}
/*
* Set variety.
*/
switch (type) {
case XML_SCHEMAS_ANYTYPE:
case XML_SCHEMAS_ANYSIMPLETYPE:
break;
case XML_SCHEMAS_IDREFS:
case XML_SCHEMAS_NMTOKENS:
case XML_SCHEMAS_ENTITIES:
ret->flags |= XML_SCHEMAS_TYPE_VARIETY_LIST;
ret->facets = xmlSchemaNewMinLengthFacet(1);
ret->flags |= XML_SCHEMAS_TYPE_HAS_FACETS;
break;
default:
ret->flags |= XML_SCHEMAS_TYPE_VARIETY_ATOMIC;
break;
}
xmlHashAddEntry2(xmlSchemaTypesBank, ret->name,
XML_SCHEMAS_NAMESPACE_NAME, ret);
ret->builtInType = type;
return(ret);
}
static const xmlChar *
xmlSchemaValDecimalGetFractionalPart(const xmlSchemaValDecimal *decimal)
{
/* 2 = sign+dot */
return decimal->str+2+decimal->integralPlaces;
}
static int
xmlSchemaValDecimalIsInteger(const xmlSchemaValDecimal *decimal)
{
return decimal->fractionalPlaces == 1 && xmlSchemaValDecimalGetFractionalPart(decimal)[0] == '0';
}
static unsigned long
xmlSchemaValDecimalGetSignificantDigitCount(const xmlSchemaValDecimal *decimal)
{
unsigned fractionalPlaces = xmlSchemaValDecimalIsInteger(decimal) ? 0 : decimal->fractionalPlaces;
unsigned integralPlaces = decimal->integralPlaces;
if(integralPlaces == 1 && decimal->str[1] == '0')
{
integralPlaces = 0;
}
if(integralPlaces+fractionalPlaces == 0)
{
/* 0, but that's still 1 significant digit */
return 1;
}
return integralPlaces+fractionalPlaces;
}
/**
* @brief Compares two decimals
*
* @param lhs
* @param rhs
* @return positive value if lhs > rhs, negative if lhs < rhs, or 0 if lhs == rhs
*/
static int xmlSchemaValDecimalCompare(const xmlSchemaValDecimal *lhs, const xmlSchemaValDecimal *rhs)
{
int sign = 1;
/* may be +0 and -0 for some reason, handle */
if(strcmp((const char*)lhs->str+1, "0.0") == 0 &&
strcmp((const char*)rhs->str+1, "0.0") == 0)
{
return 0;
}
/* first take care of sign */
if(lhs->str[0] != rhs->str[0])
{
/* ASCII- > ASCII+ */
return rhs->str[0]-lhs->str[0];
}
/* signs are equal, but if negative the comparison must be reversed */
if(lhs->str[0] == '-')
{
sign = -1;
}
/* internal representation never contains leading zeroes, longer decimal representation = larger number */
if(lhs->integralPlaces != rhs->integralPlaces)
{
return ((int)lhs->integralPlaces-(int)rhs->integralPlaces)*sign;
}
/* same length, only digits => lexicographical sorting == numerical sorting.
If integral parts are equal it will compare compare fractional parts. Again, lexicographical is good enough,
length doesn't matter. We'll be starting from 0.1, always comparing like to like, and NULL < '0'
If one is shorter and is equal until end, it must be smaller, since there are no trailing zeroes
and the longer number must therefore have at least one non-zero digit after the other has ended.
+1 to skip the sign
*/
return strcmp((const char*)lhs->str+1, (const char*)rhs->str+1)*sign;
}
static int xmlSchemaValDecimalCompareWithInteger(const xmlSchemaValDecimal *lhs, long rhs)
{
/* can handle integers up to 128 bits, should be good for a while */
char buf[43];
xmlSchemaValDecimal tmpVal;
/* 3 = sign+dot+0+NULL */
tmpVal.integralPlaces = snprintf(buf, sizeof(buf), "%+ld.0", rhs)-3;
tmpVal.str = (xmlChar*)buf;
tmpVal.fractionalPlaces = 1;
return xmlSchemaValDecimalCompare(lhs, &tmpVal);
}
/*
* WARNING: Those type reside normally in xmlschemas.c but are
* redefined here locally in oder of being able to use them for xs:anyType-
* TODO: Remove those definition if we move the types to a header file.
* TODO: Always keep those structs up-to-date with the originals.
*/
#define UNBOUNDED (1 << 30)
typedef struct _xmlSchemaTreeItem xmlSchemaTreeItem;
typedef xmlSchemaTreeItem *xmlSchemaTreeItemPtr;
struct _xmlSchemaTreeItem {
xmlSchemaTypeType type;
xmlSchemaAnnotPtr annot;
xmlSchemaTreeItemPtr next;
xmlSchemaTreeItemPtr children;
};
typedef struct _xmlSchemaParticle xmlSchemaParticle;
typedef xmlSchemaParticle *xmlSchemaParticlePtr;
struct _xmlSchemaParticle {
xmlSchemaTypeType type;
xmlSchemaAnnotPtr annot;
xmlSchemaTreeItemPtr next;
xmlSchemaTreeItemPtr children;
int minOccurs;
int maxOccurs;
xmlNodePtr node;
};
typedef struct _xmlSchemaModelGroup xmlSchemaModelGroup;
typedef xmlSchemaModelGroup *xmlSchemaModelGroupPtr;
struct _xmlSchemaModelGroup {
xmlSchemaTypeType type;
xmlSchemaAnnotPtr annot;
xmlSchemaTreeItemPtr next;
xmlSchemaTreeItemPtr children;
xmlNodePtr node;
};
static xmlSchemaParticlePtr
xmlSchemaAddParticle(void)
{
xmlSchemaParticlePtr ret = NULL;
ret = (xmlSchemaParticlePtr)
xmlMalloc(sizeof(xmlSchemaParticle));
if (ret == NULL) {
xmlSchemaTypeErrMemory();
return (NULL);
}
memset(ret, 0, sizeof(xmlSchemaParticle));
ret->type = XML_SCHEMA_TYPE_PARTICLE;
ret->minOccurs = 1;
ret->maxOccurs = 1;
return (ret);
}
static void
xmlSchemaFreeTypeEntry(void *type, const xmlChar *name ATTRIBUTE_UNUSED) {
xmlSchemaFreeType((xmlSchemaTypePtr) type);
}
/**
* xmlSchemaCleanupTypesInternal:
*
* Cleanup the default XML Schemas type library
*/
static void
xmlSchemaCleanupTypesInternal(void) {
xmlSchemaParticlePtr particle;
/*
* Free xs:anyType.
*/
if (xmlSchemaTypeAnyTypeDef != NULL) {
/* Attribute wildcard. */
xmlSchemaFreeWildcard(xmlSchemaTypeAnyTypeDef->attributeWildcard);
/* Content type. */
particle = (xmlSchemaParticlePtr) xmlSchemaTypeAnyTypeDef->subtypes;
/* Wildcard. */
xmlSchemaFreeWildcard((xmlSchemaWildcardPtr)
particle->children->children->children);
xmlFree((xmlSchemaParticlePtr) particle->children->children);
/* Sequence model group. */
xmlFree((xmlSchemaModelGroupPtr) particle->children);
xmlFree((xmlSchemaParticlePtr) particle);
xmlSchemaTypeAnyTypeDef->subtypes = NULL;
xmlSchemaTypeAnyTypeDef = NULL;
}
xmlHashFree(xmlSchemaTypesBank, xmlSchemaFreeTypeEntry);
xmlSchemaTypesBank = NULL;
/* Note that the xmlSchemaType*Def pointers aren't set to NULL. */
}
/*
* xmlSchemaInitTypes:
*
* Initialize the default XML Schemas type library
*
* Returns 0 on success, -1 on error.
*/
int
xmlSchemaInitTypes(void)
{
if (xmlSchemaTypesInitialized != 0)
return (0);
#if defined(NAN) && defined(INFINITY)
xmlSchemaNAN = NAN;
xmlSchemaPINF = INFINITY;
xmlSchemaNINF = -INFINITY;
#else
/* MSVC doesn't allow division by zero in constant expressions. */
double zero = 0.0;
xmlSchemaNAN = 0.0 / zero;
xmlSchemaPINF = 1.0 / zero;
xmlSchemaNINF = -xmlSchemaPINF;
#endif
xmlSchemaTypesBank = xmlHashCreate(40);
if (xmlSchemaTypesBank == NULL) {
xmlSchemaTypeErrMemory();
goto error;
}
/*
* 3.4.7 Built-in Complex Type Definition
*/
xmlSchemaTypeAnyTypeDef = xmlSchemaInitBasicType("anyType",
XML_SCHEMAS_ANYTYPE,
NULL);
if (xmlSchemaTypeAnyTypeDef == NULL)
goto error;
xmlSchemaTypeAnyTypeDef->baseType = xmlSchemaTypeAnyTypeDef;
xmlSchemaTypeAnyTypeDef->contentType = XML_SCHEMA_CONTENT_MIXED;
/*
* Init the content type.
*/
xmlSchemaTypeAnyTypeDef->contentType = XML_SCHEMA_CONTENT_MIXED;
{
xmlSchemaParticlePtr particle;
xmlSchemaModelGroupPtr sequence;
xmlSchemaWildcardPtr wild;
/* First particle. */
particle = xmlSchemaAddParticle();
if (particle == NULL)
goto error;
xmlSchemaTypeAnyTypeDef->subtypes = (xmlSchemaTypePtr) particle;
/* Sequence model group. */
sequence = (xmlSchemaModelGroupPtr)
xmlMalloc(sizeof(xmlSchemaModelGroup));
if (sequence == NULL) {
xmlSchemaTypeErrMemory();
goto error;
}
memset(sequence, 0, sizeof(xmlSchemaModelGroup));
sequence->type = XML_SCHEMA_TYPE_SEQUENCE;
particle->children = (xmlSchemaTreeItemPtr) sequence;
/* Second particle. */
particle = xmlSchemaAddParticle();
if (particle == NULL)
goto error;
particle->minOccurs = 0;
particle->maxOccurs = UNBOUNDED;
sequence->children = (xmlSchemaTreeItemPtr) particle;
/* The wildcard */
wild = (xmlSchemaWildcardPtr) xmlMalloc(sizeof(xmlSchemaWildcard));
if (wild == NULL) {
xmlSchemaTypeErrMemory();
goto error;
}
memset(wild, 0, sizeof(xmlSchemaWildcard));
wild->type = XML_SCHEMA_TYPE_ANY;
wild->any = 1;
wild->processContents = XML_SCHEMAS_ANY_LAX;
particle->children = (xmlSchemaTreeItemPtr) wild;
/*
* Create the attribute wildcard.
*/
wild = (xmlSchemaWildcardPtr) xmlMalloc(sizeof(xmlSchemaWildcard));
if (wild == NULL) {
xmlSchemaTypeErrMemory();
goto error;
}
memset(wild, 0, sizeof(xmlSchemaWildcard));
wild->any = 1;
wild->processContents = XML_SCHEMAS_ANY_LAX;
xmlSchemaTypeAnyTypeDef->attributeWildcard = wild;
}
xmlSchemaTypeAnySimpleTypeDef = xmlSchemaInitBasicType("anySimpleType",
XML_SCHEMAS_ANYSIMPLETYPE,
xmlSchemaTypeAnyTypeDef);
if (xmlSchemaTypeAnySimpleTypeDef == NULL)
goto error;
/*
* primitive datatypes
*/
xmlSchemaTypeStringDef = xmlSchemaInitBasicType("string",
XML_SCHEMAS_STRING,
xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeStringDef == NULL)
goto error;
xmlSchemaTypeDecimalDef = xmlSchemaInitBasicType("decimal",
XML_SCHEMAS_DECIMAL,
xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeDecimalDef == NULL)
goto error;
xmlSchemaTypeDateDef = xmlSchemaInitBasicType("date",
XML_SCHEMAS_DATE,
xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeDateDef == NULL)
goto error;
xmlSchemaTypeDatetimeDef = xmlSchemaInitBasicType("dateTime",
XML_SCHEMAS_DATETIME,
xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeDatetimeDef == NULL)
goto error;
xmlSchemaTypeTimeDef = xmlSchemaInitBasicType("time",
XML_SCHEMAS_TIME,
xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeTimeDef == NULL)
goto error;
xmlSchemaTypeGYearDef = xmlSchemaInitBasicType("gYear",
XML_SCHEMAS_GYEAR,
xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeGYearDef == NULL)
goto error;
xmlSchemaTypeGYearMonthDef = xmlSchemaInitBasicType("gYearMonth",
XML_SCHEMAS_GYEARMONTH,
xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeGYearMonthDef == NULL)
goto error;
xmlSchemaTypeGMonthDef = xmlSchemaInitBasicType("gMonth",
XML_SCHEMAS_GMONTH,
xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeGMonthDef == NULL)
goto error;
xmlSchemaTypeGMonthDayDef = xmlSchemaInitBasicType("gMonthDay",
XML_SCHEMAS_GMONTHDAY,
xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeGMonthDayDef == NULL)
goto error;
xmlSchemaTypeGDayDef = xmlSchemaInitBasicType("gDay",
XML_SCHEMAS_GDAY,
xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeGDayDef == NULL)
goto error;
xmlSchemaTypeDurationDef = xmlSchemaInitBasicType("duration",
XML_SCHEMAS_DURATION,
xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeDurationDef == NULL)
goto error;
xmlSchemaTypeFloatDef = xmlSchemaInitBasicType("float",
XML_SCHEMAS_FLOAT,
xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeFloatDef == NULL)
goto error;
xmlSchemaTypeDoubleDef = xmlSchemaInitBasicType("double",
XML_SCHEMAS_DOUBLE,
xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeDoubleDef == NULL)
goto error;
xmlSchemaTypeBooleanDef = xmlSchemaInitBasicType("boolean",
XML_SCHEMAS_BOOLEAN,
xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeBooleanDef == NULL)
goto error;
xmlSchemaTypeAnyURIDef = xmlSchemaInitBasicType("anyURI",
XML_SCHEMAS_ANYURI,
xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeAnyURIDef == NULL)
goto error;
xmlSchemaTypeHexBinaryDef = xmlSchemaInitBasicType("hexBinary",
XML_SCHEMAS_HEXBINARY,
xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeHexBinaryDef == NULL)
goto error;
xmlSchemaTypeBase64BinaryDef
= xmlSchemaInitBasicType("base64Binary", XML_SCHEMAS_BASE64BINARY,
xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeBase64BinaryDef == NULL)
goto error;
xmlSchemaTypeNotationDef = xmlSchemaInitBasicType("NOTATION",
XML_SCHEMAS_NOTATION,
xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeNotationDef == NULL)
goto error;
xmlSchemaTypeQNameDef = xmlSchemaInitBasicType("QName",
XML_SCHEMAS_QNAME,
xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeQNameDef == NULL)
goto error;
/*
* derived datatypes
*/
xmlSchemaTypeIntegerDef = xmlSchemaInitBasicType("integer",
XML_SCHEMAS_INTEGER,
xmlSchemaTypeDecimalDef);
if (xmlSchemaTypeIntegerDef == NULL)
goto error;
xmlSchemaTypeNonPositiveIntegerDef =
xmlSchemaInitBasicType("nonPositiveInteger",
XML_SCHEMAS_NPINTEGER,
xmlSchemaTypeIntegerDef);
if (xmlSchemaTypeNonPositiveIntegerDef == NULL)
goto error;
xmlSchemaTypeNegativeIntegerDef =
xmlSchemaInitBasicType("negativeInteger", XML_SCHEMAS_NINTEGER,
xmlSchemaTypeNonPositiveIntegerDef);
if (xmlSchemaTypeNegativeIntegerDef == NULL)
goto error;
xmlSchemaTypeLongDef =
xmlSchemaInitBasicType("long", XML_SCHEMAS_LONG,
xmlSchemaTypeIntegerDef);
if (xmlSchemaTypeLongDef == NULL)
goto error;
xmlSchemaTypeIntDef = xmlSchemaInitBasicType("int", XML_SCHEMAS_INT,
xmlSchemaTypeLongDef);
if (xmlSchemaTypeIntDef == NULL)
goto error;
xmlSchemaTypeShortDef = xmlSchemaInitBasicType("short",
XML_SCHEMAS_SHORT,
xmlSchemaTypeIntDef);
if (xmlSchemaTypeShortDef == NULL)
goto error;
xmlSchemaTypeByteDef = xmlSchemaInitBasicType("byte",
XML_SCHEMAS_BYTE,
xmlSchemaTypeShortDef);
if (xmlSchemaTypeByteDef == NULL)
goto error;
xmlSchemaTypeNonNegativeIntegerDef =
xmlSchemaInitBasicType("nonNegativeInteger",
XML_SCHEMAS_NNINTEGER,
xmlSchemaTypeIntegerDef);
if (xmlSchemaTypeNonNegativeIntegerDef == NULL)
goto error;
xmlSchemaTypeUnsignedLongDef =
xmlSchemaInitBasicType("unsignedLong", XML_SCHEMAS_ULONG,
xmlSchemaTypeNonNegativeIntegerDef);
if (xmlSchemaTypeUnsignedLongDef == NULL)
goto error;
xmlSchemaTypeUnsignedIntDef =
xmlSchemaInitBasicType("unsignedInt", XML_SCHEMAS_UINT,
xmlSchemaTypeUnsignedLongDef);
if (xmlSchemaTypeUnsignedIntDef == NULL)
goto error;
xmlSchemaTypeUnsignedShortDef =
xmlSchemaInitBasicType("unsignedShort", XML_SCHEMAS_USHORT,
xmlSchemaTypeUnsignedIntDef);
if (xmlSchemaTypeUnsignedShortDef == NULL)
goto error;
xmlSchemaTypeUnsignedByteDef =
xmlSchemaInitBasicType("unsignedByte", XML_SCHEMAS_UBYTE,
xmlSchemaTypeUnsignedShortDef);
if (xmlSchemaTypeUnsignedByteDef == NULL)
goto error;
xmlSchemaTypePositiveIntegerDef =
xmlSchemaInitBasicType("positiveInteger", XML_SCHEMAS_PINTEGER,
xmlSchemaTypeNonNegativeIntegerDef);
if (xmlSchemaTypePositiveIntegerDef == NULL)
goto error;
xmlSchemaTypeNormStringDef = xmlSchemaInitBasicType("normalizedString",
XML_SCHEMAS_NORMSTRING,
xmlSchemaTypeStringDef);
if (xmlSchemaTypeNormStringDef == NULL)
goto error;
xmlSchemaTypeTokenDef = xmlSchemaInitBasicType("token",
XML_SCHEMAS_TOKEN,
xmlSchemaTypeNormStringDef);
if (xmlSchemaTypeTokenDef == NULL)
goto error;
xmlSchemaTypeLanguageDef = xmlSchemaInitBasicType("language",
XML_SCHEMAS_LANGUAGE,
xmlSchemaTypeTokenDef);
if (xmlSchemaTypeLanguageDef == NULL)
goto error;
xmlSchemaTypeNameDef = xmlSchemaInitBasicType("Name",
XML_SCHEMAS_NAME,
xmlSchemaTypeTokenDef);
if (xmlSchemaTypeNameDef == NULL)
goto error;
xmlSchemaTypeNmtokenDef = xmlSchemaInitBasicType("NMTOKEN",
XML_SCHEMAS_NMTOKEN,
xmlSchemaTypeTokenDef);
if (xmlSchemaTypeNmtokenDef == NULL)
goto error;
xmlSchemaTypeNCNameDef = xmlSchemaInitBasicType("NCName",
XML_SCHEMAS_NCNAME,
xmlSchemaTypeNameDef);
if (xmlSchemaTypeNCNameDef == NULL)
goto error;
xmlSchemaTypeIdDef = xmlSchemaInitBasicType("ID", XML_SCHEMAS_ID,
xmlSchemaTypeNCNameDef);
if (xmlSchemaTypeIdDef == NULL)
goto error;
xmlSchemaTypeIdrefDef = xmlSchemaInitBasicType("IDREF",
XML_SCHEMAS_IDREF,
xmlSchemaTypeNCNameDef);
if (xmlSchemaTypeIdrefDef == NULL)
goto error;
xmlSchemaTypeEntityDef = xmlSchemaInitBasicType("ENTITY",
XML_SCHEMAS_ENTITY,
xmlSchemaTypeNCNameDef);
if (xmlSchemaTypeEntityDef == NULL)
goto error;
/*
* Derived list types.
*/
/* ENTITIES */
xmlSchemaTypeEntitiesDef = xmlSchemaInitBasicType("ENTITIES",
XML_SCHEMAS_ENTITIES,
xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeEntitiesDef == NULL)
goto error;
xmlSchemaTypeEntitiesDef->subtypes = xmlSchemaTypeEntityDef;
/* IDREFS */
xmlSchemaTypeIdrefsDef = xmlSchemaInitBasicType("IDREFS",
XML_SCHEMAS_IDREFS,
xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeIdrefsDef == NULL)
goto error;
xmlSchemaTypeIdrefsDef->subtypes = xmlSchemaTypeIdrefDef;
/* NMTOKENS */
xmlSchemaTypeNmtokensDef = xmlSchemaInitBasicType("NMTOKENS",
XML_SCHEMAS_NMTOKENS,
xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeNmtokensDef == NULL)
goto error;
xmlSchemaTypeNmtokensDef->subtypes = xmlSchemaTypeNmtokenDef;
xmlSchemaTypesInitialized = 1;
return (0);
error:
xmlSchemaCleanupTypesInternal();
return (-1);
}
/**
* xmlSchemaCleanupTypes:
*
* DEPRECATED: This function will be made private. Call xmlCleanupParser
* to free global state but see the warnings there. xmlCleanupParser
* should be only called once at program exit. In most cases, you don't
* have to call cleanup functions at all.
*
* Cleanup the default XML Schemas type library
*/
void
xmlSchemaCleanupTypes(void) {
if (xmlSchemaTypesInitialized != 0) {
xmlSchemaCleanupTypesInternal();
xmlSchemaTypesInitialized = 0;
}
}
/**
* xmlSchemaIsBuiltInTypeFacet:
* @type: the built-in type
* @facetType: the facet type
*
* Evaluates if a specific facet can be
* used in conjunction with a type.
*
* Returns 1 if the facet can be used with the given built-in type,
* 0 otherwise and -1 in case the type is not a built-in type.
*/
int
xmlSchemaIsBuiltInTypeFacet(xmlSchemaTypePtr type, int facetType)
{
if (type == NULL)
return (-1);
if (type->type != XML_SCHEMA_TYPE_BASIC)
return (-1);
switch (type->builtInType) {
case XML_SCHEMAS_BOOLEAN:
if ((facetType == XML_SCHEMA_FACET_PATTERN) ||
(facetType == XML_SCHEMA_FACET_WHITESPACE))
return (1);
else
return (0);
case XML_SCHEMAS_STRING:
case XML_SCHEMAS_NOTATION:
case XML_SCHEMAS_QNAME:
case XML_SCHEMAS_ANYURI:
case XML_SCHEMAS_BASE64BINARY:
case XML_SCHEMAS_HEXBINARY:
if ((facetType == XML_SCHEMA_FACET_LENGTH) ||
(facetType == XML_SCHEMA_FACET_MINLENGTH) ||
(facetType == XML_SCHEMA_FACET_MAXLENGTH) ||
(facetType == XML_SCHEMA_FACET_PATTERN) ||
(facetType == XML_SCHEMA_FACET_ENUMERATION) ||
(facetType == XML_SCHEMA_FACET_WHITESPACE))
return (1);
else
return (0);
case XML_SCHEMAS_DECIMAL:
if ((facetType == XML_SCHEMA_FACET_TOTALDIGITS) ||
(facetType == XML_SCHEMA_FACET_FRACTIONDIGITS) ||
(facetType == XML_SCHEMA_FACET_PATTERN) ||
(facetType == XML_SCHEMA_FACET_WHITESPACE) ||
(facetType == XML_SCHEMA_FACET_ENUMERATION) ||
(facetType == XML_SCHEMA_FACET_MAXINCLUSIVE) ||
(facetType == XML_SCHEMA_FACET_MAXEXCLUSIVE) ||
(facetType == XML_SCHEMA_FACET_MININCLUSIVE) ||
(facetType == XML_SCHEMA_FACET_MINEXCLUSIVE))
return (1);
else
return (0);
case XML_SCHEMAS_TIME:
case XML_SCHEMAS_GDAY:
case XML_SCHEMAS_GMONTH:
case XML_SCHEMAS_GMONTHDAY:
case XML_SCHEMAS_GYEAR:
case XML_SCHEMAS_GYEARMONTH:
case XML_SCHEMAS_DATE:
case XML_SCHEMAS_DATETIME:
case XML_SCHEMAS_DURATION:
case XML_SCHEMAS_FLOAT:
case XML_SCHEMAS_DOUBLE:
if ((facetType == XML_SCHEMA_FACET_PATTERN) ||
(facetType == XML_SCHEMA_FACET_ENUMERATION) ||
(facetType == XML_SCHEMA_FACET_WHITESPACE) ||
(facetType == XML_SCHEMA_FACET_MAXINCLUSIVE) ||
(facetType == XML_SCHEMA_FACET_MAXEXCLUSIVE) ||
(facetType == XML_SCHEMA_FACET_MININCLUSIVE) ||
(facetType == XML_SCHEMA_FACET_MINEXCLUSIVE))
return (1);
else
return (0);
default:
break;
}
return (0);
}
/**
* xmlSchemaGetBuiltInType:
* @type: the type of the built in type
*
* Gives you the type struct for a built-in
* type by its type id.
*
* Returns the type if found, NULL otherwise.
*/
xmlSchemaTypePtr
xmlSchemaGetBuiltInType(xmlSchemaValType type)
{
if ((xmlSchemaTypesInitialized == 0) &&
(xmlSchemaInitTypes() < 0))
return (NULL);
switch (type) {
case XML_SCHEMAS_ANYSIMPLETYPE:
return (xmlSchemaTypeAnySimpleTypeDef);
case XML_SCHEMAS_STRING:
return (xmlSchemaTypeStringDef);
case XML_SCHEMAS_NORMSTRING:
return (xmlSchemaTypeNormStringDef);
case XML_SCHEMAS_DECIMAL:
return (xmlSchemaTypeDecimalDef);
case XML_SCHEMAS_TIME:
return (xmlSchemaTypeTimeDef);
case XML_SCHEMAS_GDAY:
return (xmlSchemaTypeGDayDef);
case XML_SCHEMAS_GMONTH:
return (xmlSchemaTypeGMonthDef);
case XML_SCHEMAS_GMONTHDAY:
return (xmlSchemaTypeGMonthDayDef);
case XML_SCHEMAS_GYEAR:
return (xmlSchemaTypeGYearDef);
case XML_SCHEMAS_GYEARMONTH:
return (xmlSchemaTypeGYearMonthDef);
case XML_SCHEMAS_DATE:
return (xmlSchemaTypeDateDef);
case XML_SCHEMAS_DATETIME:
return (xmlSchemaTypeDatetimeDef);
case XML_SCHEMAS_DURATION: