⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlschemastypes.c

📁 xml开源解析代码.版本为libxml2-2.6.29,可支持GB3212.网络消息发送XML时很有用.
💻 C
📖 第 1 页 / 共 5 页
字号:
/* * schemastypes.c : implementation of the XML Schema Datatypes *             definition and validity checking * * See Copyright for the status of this software. * * Daniel Veillard <veillard@redhat.com> */#define IN_LIBXML#include "libxml.h"#ifdef LIBXML_SCHEMAS_ENABLED#include <string.h>#include <libxml/xmlmemory.h>#include <libxml/parser.h>#include <libxml/parserInternals.h>#include <libxml/hash.h>#include <libxml/valid.h>#include <libxml/xpath.h>#include <libxml/uri.h>#include <libxml/xmlschemas.h>#include <libxml/schemasInternals.h>#include <libxml/xmlschemastypes.h>#ifdef HAVE_MATH_H#include <math.h>#endif#ifdef HAVE_FLOAT_H#include <float.h>#endif#define DEBUG#ifndef LIBXML_XPATH_ENABLEDextern double xmlXPathNAN;extern double xmlXPathPINF;extern double xmlXPathNINF;#endif#define TODO 								\    xmlGenericError(xmlGenericErrorContext,				\	    "Unimplemented block at %s:%d\n",				\            __FILE__, __LINE__);#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   <= 23   */    unsigned int	min	:6;	/* 0 <=  min    <= 59	*/    double		sec;    unsigned int	tz_flag	:1;	/* is tzo explicitely 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 {    /* would use long long but not portable */    unsigned long lo;    unsigned long mi;    unsigned long hi;    unsigned int extra;    unsigned int sign:1;    unsigned int frac:7;    unsigned int total:8;};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 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 informations * * Handle an out of memory condition */static voidxmlSchemaTypeErrMemory(xmlNodePtr node, const char *extra){    __xmlSimpleError(XML_FROM_DATATYPE, XML_ERR_NO_MEMORY, node, NULL, extra);}/************************************************************************ *									* * 			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 xmlSchemaValPtrxmlSchemaNewValue(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 xmlSchemaFacetPtrxmlSchemaNewMinLengthFacet(int value){    xmlSchemaFacetPtr ret;    ret = xmlSchemaNewFacet();    if (ret == NULL) {        return(NULL);    }    ret->type = XML_SCHEMA_FACET_MINLENGTH;    ret->val = xmlSchemaNewValue(XML_SCHEMAS_NNINTEGER);    ret->val->value.decimal.lo = value;    return (ret);}/* * xmlSchemaInitBasicType: * @name:  the type name * @type:  the value type associated * * Initialize one primitive built-in type */static xmlSchemaTypePtrxmlSchemaInitBasicType(const char *name, xmlSchemaValType type, 		       xmlSchemaTypePtr baseType) {    xmlSchemaTypePtr ret;    ret = (xmlSchemaTypePtr) xmlMalloc(sizeof(xmlSchemaType));    if (ret == NULL) {        xmlSchemaTypeErrMemory(NULL, "could not initialize basic types");	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);}/** 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 xmlSchemaParticlePtrxmlSchemaAddParticle(void){    xmlSchemaParticlePtr ret = NULL;    ret = (xmlSchemaParticlePtr)	xmlMalloc(sizeof(xmlSchemaParticle));    if (ret == NULL) {	xmlSchemaTypeErrMemory(NULL, "allocating particle component");	return (NULL);    }    memset(ret, 0, sizeof(xmlSchemaParticle));    ret->type = XML_SCHEMA_TYPE_PARTICLE;    ret->minOccurs = 1;    ret->maxOccurs = 1;    return (ret);}/* * xmlSchemaInitTypes: * * Initialize the default XML Schemas type library */voidxmlSchemaInitTypes(void){    if (xmlSchemaTypesInitialized != 0)        return;    xmlSchemaTypesBank = xmlHashCreate(40);        /*    * 3.4.7 Built-in Complex Type Definition    */    xmlSchemaTypeAnyTypeDef = xmlSchemaInitBasicType("anyType",                                                     XML_SCHEMAS_ANYTYPE, 						     NULL);    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)	    return;	xmlSchemaTypeAnyTypeDef->subtypes = (xmlSchemaTypePtr) particle;	/* Sequence model group. */	sequence = (xmlSchemaModelGroupPtr)	    xmlMalloc(sizeof(xmlSchemaModelGroup));	if (sequence == NULL) {	    xmlSchemaTypeErrMemory(NULL, "allocating model group component");	    return;	}	memset(sequence, 0, sizeof(xmlSchemaModelGroup));	sequence->type = XML_SCHEMA_TYPE_SEQUENCE;		particle->children = (xmlSchemaTreeItemPtr) sequence;	/* Second particle. */	particle = xmlSchemaAddParticle();	if (particle == NULL)	    return;	particle->minOccurs = 0;	particle->maxOccurs = UNBOUNDED;	sequence->children = (xmlSchemaTreeItemPtr) particle;	/* The wildcard */	wild = (xmlSchemaWildcardPtr) xmlMalloc(sizeof(xmlSchemaWildcard));	if (wild == NULL) {	    xmlSchemaTypeErrMemory(NULL, "allocating wildcard component");	    return;	}	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(NULL, "could not create an attribute "		"wildcard on anyType");	    return;	}	memset(wild, 0, sizeof(xmlSchemaWildcard));	wild->any = 1;	wild->processContents = XML_SCHEMAS_ANY_LAX;		xmlSchemaTypeAnyTypeDef->attributeWildcard = wild;    }    xmlSchemaTypeAnySimpleTypeDef = xmlSchemaInitBasicType("anySimpleType",                                                            XML_SCHEMAS_ANYSIMPLETYPE,							   xmlSchemaTypeAnyTypeDef);    /*

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -