xmlschemastypes.c revision 1f978fcb45a94792ad69b8928ce672591462b905
/*
* 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/parserInternals.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
#ifndef VBOX /* Avoid warnings about redefining DEBUG */
#define DEBUG
#endif /* !VBOX */
#ifndef LIBXML_XPATH_ENABLED
extern double xmlXPathNAN;
extern double xmlXPathPINF;
extern double xmlXPathNINF;
#endif
#define TODO \
"Unimplemented block at %s:%d\n", \
#define XML_SCHEMAS_NAMESPACE_NAME \
(const xmlChar *)"http://www.w3.org/2001/XMLSchema"
((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;
double sec;
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 {
};
typedef struct _xmlSchemaValHex xmlSchemaValHex;
typedef xmlSchemaValHex *xmlSchemaValHexPtr;
struct _xmlSchemaValHex {
unsigned int total;
};
typedef struct _xmlSchemaValBase64 xmlSchemaValBase64;
typedef xmlSchemaValBase64 *xmlSchemaValBase64Ptr;
struct _xmlSchemaValBase64 {
unsigned int total;
};
struct _xmlSchemaVal {
struct _xmlSchemaVal *next;
union {
float f;
double d;
int b;
} value;
};
static int xmlSchemaTypesInitialized = 0;
/*
* Basic types
*/
/*
* Derived types
*/
/************************************************************************
* *
* Datatype error handlers *
* *
************************************************************************/
/**
* xmlSchemaTypeErrMemory:
* @extra: extra informations
*
* Handle an out of memory condition
*/
static void
{
}
/************************************************************************
* *
* 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
return(NULL);
}
return(value);
}
static xmlSchemaFacetPtr
{
ret = xmlSchemaNewFacet();
return(NULL);
}
return (ret);
}
/*
* xmlSchemaInitBasicType:
* @name: the type name
* @type: the value type associated
*
* Initialize one primitive built-in type
*/
static xmlSchemaTypePtr
return(NULL);
}
/*
* 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:
break;
default:
break;
}
/*
* Set variety.
*/
switch (type) {
case XML_SCHEMAS_ANYTYPE:
break;
case XML_SCHEMAS_IDREFS:
case XML_SCHEMAS_NMTOKENS:
case XML_SCHEMAS_ENTITIES:
break;
default:
break;
}
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.
*/
typedef struct _xmlSchemaTreeItem xmlSchemaTreeItem;
typedef xmlSchemaTreeItem *xmlSchemaTreeItemPtr;
struct _xmlSchemaTreeItem {
};
typedef struct _xmlSchemaParticle xmlSchemaParticle;
typedef xmlSchemaParticle *xmlSchemaParticlePtr;
struct _xmlSchemaParticle {
int minOccurs;
int maxOccurs;
};
typedef struct _xmlSchemaModelGroup xmlSchemaModelGroup;
typedef xmlSchemaModelGroup *xmlSchemaModelGroupPtr;
struct _xmlSchemaModelGroup {
};
static xmlSchemaParticlePtr
xmlSchemaAddParticle(void)
{
xmlMalloc(sizeof(xmlSchemaParticle));
return (NULL);
}
return (ret);
}
/*
* xmlSchemaInitTypes:
*
* Initialize the default XML Schemas type library
*/
void
xmlSchemaInitTypes(void)
{
if (xmlSchemaTypesInitialized != 0)
return;
/*
* 3.4.7 Built-in Complex Type Definition
*/
NULL);
/*
* Init the content type.
*/
{
/* First particle. */
return;
/* Sequence model group. */
xmlMalloc(sizeof(xmlSchemaModelGroup));
return;
}
/* Second particle. */
return;
/* The wildcard */
return;
}
/*
* Create the attribute wildcard.
*/
"wildcard on anyType");
return;
}
}
/*
* primitive datatypes
*/
/*
* derived datatypes
*/
xmlSchemaInitBasicType("nonPositiveInteger",
xmlSchemaInitBasicType("nonNegativeInteger",
/*
* Derived list types.
*/
/* ENTITIES */
/* IDREFS */
/* NMTOKENS */
}
/**
* xmlSchemaCleanupTypes:
*
* Cleanup the default XML Schemas type library
*/
void
xmlSchemaCleanupTypes(void) {
if (xmlSchemaTypesInitialized == 0)
return;
/*
* Free xs:anyType.
*/
{
/* Attribute wildcard. */
/* Content type. */
/* Wildcard. */
/* Sequence model group. */
}
}
/**
* 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
{
return (-1);
return (-1);
switch (type->builtInType) {
case XML_SCHEMAS_BOOLEAN:
if ((facetType == XML_SCHEMA_FACET_PATTERN) ||
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) ||
return (1);
else
return (0);
case XML_SCHEMAS_DECIMAL:
if ((facetType == XML_SCHEMA_FACET_TOTALDIGITS) ||
(facetType == XML_SCHEMA_FACET_PATTERN) ||
(facetType == XML_SCHEMA_FACET_WHITESPACE) ||
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_WHITESPACE) ||
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.
*/
{
if (xmlSchemaTypesInitialized == 0)
switch (type) {
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:
return (xmlSchemaTypeDurationDef);
case XML_SCHEMAS_FLOAT:
return (xmlSchemaTypeFloatDef);
case XML_SCHEMAS_DOUBLE:
return (xmlSchemaTypeDoubleDef);
case XML_SCHEMAS_BOOLEAN:
return (xmlSchemaTypeBooleanDef);
case XML_SCHEMAS_TOKEN:
return (xmlSchemaTypeTokenDef);
case XML_SCHEMAS_LANGUAGE:
return (xmlSchemaTypeLanguageDef);
case XML_SCHEMAS_NMTOKEN:
return (xmlSchemaTypeNmtokenDef);
case XML_SCHEMAS_NMTOKENS:
return (xmlSchemaTypeNmtokensDef);
case XML_SCHEMAS_NAME:
return (xmlSchemaTypeNameDef);
case XML_SCHEMAS_QNAME:
return (xmlSchemaTypeQNameDef);
case XML_SCHEMAS_NCNAME:
return (xmlSchemaTypeNCNameDef);
case XML_SCHEMAS_ID:
return (xmlSchemaTypeIdDef);
case XML_SCHEMAS_IDREF:
return (xmlSchemaTypeIdrefDef);
case XML_SCHEMAS_IDREFS:
return (xmlSchemaTypeIdrefsDef);
case XML_SCHEMAS_ENTITY:
return (xmlSchemaTypeEntityDef);
case XML_SCHEMAS_ENTITIES:
return (xmlSchemaTypeEntitiesDef);
case XML_SCHEMAS_NOTATION:
return (xmlSchemaTypeNotationDef);
case XML_SCHEMAS_ANYURI:
return (xmlSchemaTypeAnyURIDef);
case XML_SCHEMAS_INTEGER:
return (xmlSchemaTypeIntegerDef);
case XML_SCHEMAS_NPINTEGER:
return (xmlSchemaTypeNonPositiveIntegerDef);
case XML_SCHEMAS_NINTEGER:
return (xmlSchemaTypeNegativeIntegerDef);
case XML_SCHEMAS_NNINTEGER:
return (xmlSchemaTypeNonNegativeIntegerDef);
case XML_SCHEMAS_PINTEGER:
return (xmlSchemaTypePositiveIntegerDef);
case XML_SCHEMAS_INT:
return (xmlSchemaTypeIntDef);
case XML_SCHEMAS_UINT:
return (xmlSchemaTypeUnsignedIntDef);
case XML_SCHEMAS_LONG:
return (xmlSchemaTypeLongDef);
case XML_SCHEMAS_ULONG:
return (xmlSchemaTypeUnsignedLongDef);
case XML_SCHEMAS_SHORT:
return (xmlSchemaTypeShortDef);
case XML_SCHEMAS_USHORT:
return (xmlSchemaTypeUnsignedShortDef);
case XML_SCHEMAS_BYTE:
return (xmlSchemaTypeByteDef);
case XML_SCHEMAS_UBYTE:
return (xmlSchemaTypeUnsignedByteDef);
case XML_SCHEMAS_HEXBINARY:
return (xmlSchemaTypeHexBinaryDef);
case XML_SCHEMAS_BASE64BINARY:
return (xmlSchemaTypeBase64BinaryDef);
case XML_SCHEMAS_ANYTYPE:
return (xmlSchemaTypeAnyTypeDef);
default:
return (NULL);
}
}
/**
* xmlSchemaValueAppend:
* @prev: the value
* @cur: the value to be appended
*
* Appends a next sibling to a list of computed values.
*
* Returns 0 if succeeded and -1 on API errors.
*/
int
return (-1);
return (0);
}
/**
* xmlSchemaValueGetNext:
* @cur: the value
*
* Accessor for the next sibling of a list of computed values.
*
* Returns the next value or NULL if there was none, or on
* API errors.
*/
return (NULL);
}
/**
* xmlSchemaValueGetAsString:
* @val: the value
*
* Accessor for the string value of a computed value.
*
* Returns the string value or NULL if there was none, or on
* API errors.
*/
const xmlChar *
{
return (NULL);
case XML_SCHEMAS_STRING:
case XML_SCHEMAS_NORMSTRING:
case XML_SCHEMAS_TOKEN:
case XML_SCHEMAS_LANGUAGE:
case XML_SCHEMAS_NMTOKEN:
case XML_SCHEMAS_NAME:
case XML_SCHEMAS_NCNAME:
case XML_SCHEMAS_ID:
case XML_SCHEMAS_IDREF:
case XML_SCHEMAS_ENTITY:
case XML_SCHEMAS_ANYURI:
default:
break;
}
return (NULL);
}
/**
* xmlSchemaValueGetAsBoolean:
* @val: the value
*
* Accessor for the boolean value of a computed value.
*
* Returns 1 if true and 0 if false, or in case of an error. Hmm.
*/
int
{
return (0);
}
/**
* xmlSchemaNewStringValue:
* @type: the value type
* @value: the value
*
* Allocate a new simple type value. The type can be
* of XML_SCHEMAS_STRING.
* WARNING: This one is intended to be expanded for other
* string based types. We need this for anySimpleType as well.
* The given value is consumed and freed with the struct.
*
* Returns a pointer to the new value or NULL in case of error
*/
{
if (type != XML_SCHEMAS_STRING)
return(NULL);
return(NULL);
}
return(val);
}
/**
* xmlSchemaNewNOTATIONValue:
* @name: the notation name
* @ns: the notation namespace name or NULL
*
* Allocate a new NOTATION value.
* The given values are consumed and freed with the struct.
*
* Returns a pointer to the new value or NULL in case of error
*/
{
return (NULL);
return(val);
}
/**
* xmlSchemaNewQNameValue:
* @namespaceName: the namespace name
* @localName: the local name
*
* Allocate a new QName value.
* The given values are consumed and freed with the struct.
*
* Returns a pointer to the new value or NULL in case of an error.
*/
{
return (NULL);
return(val);
}
/**
* xmlSchemaFreeValue:
* @value: the value to free
*
* Cleanup the default XML Schemas type library
*/
void
case XML_SCHEMAS_STRING:
case XML_SCHEMAS_NORMSTRING:
case XML_SCHEMAS_TOKEN:
case XML_SCHEMAS_LANGUAGE:
case XML_SCHEMAS_NMTOKEN:
case XML_SCHEMAS_NMTOKENS:
case XML_SCHEMAS_NAME:
case XML_SCHEMAS_NCNAME:
case XML_SCHEMAS_ID:
case XML_SCHEMAS_IDREF:
case XML_SCHEMAS_IDREFS:
case XML_SCHEMAS_ENTITY:
case XML_SCHEMAS_ENTITIES:
case XML_SCHEMAS_ANYURI:
break;
case XML_SCHEMAS_NOTATION:
case XML_SCHEMAS_QNAME:
break;
case XML_SCHEMAS_HEXBINARY:
break;
case XML_SCHEMAS_BASE64BINARY:
break;
default:
break;
}
}
}
/**
* xmlSchemaGetPredefinedType:
* @name: the type name
* @ns: the URI of the namespace usually "http://www.w3.org/2001/XMLSchema"
*
* Lookup a type in the default XML Schemas type library
*
* Returns the type if found, NULL otherwise
*/
if (xmlSchemaTypesInitialized == 0)
return(NULL);
}
/**
* xmlSchemaGetBuiltInListSimpleTypeItemType:
* @type: the built-in simple type.
*
* Lookup function
*
* Returns the item type of @type as defined by the built-in datatype
* hierarchy of XML Schema Part 2: Datatypes, or NULL in case of an error.
*/
{
return (NULL);
switch (type->builtInType) {
case XML_SCHEMAS_NMTOKENS:
return (xmlSchemaTypeNmtokenDef );
case XML_SCHEMAS_IDREFS:
return (xmlSchemaTypeIdrefDef);
case XML_SCHEMAS_ENTITIES:
return (xmlSchemaTypeEntityDef);
default:
return (NULL);
}
}
/****************************************************************
* *
* Convenience macros and functions *
* *
****************************************************************/
#define IS_TZO_CHAR(c) \
((c == 0) || (c == 'Z') || (c == '+') || (c == '-'))
/* VALID_DAY should only be used when month is unknown */
#define IS_LEAP(y) \
(((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0))
static const unsigned int daysInMonth[12] =
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
static const unsigned int daysInMonthLeap[12] =
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
#define VALID_MDAY(dt) \
#define VALID_DATE(dt) \
#define VALID_TIME(dt) \
#define VALID_DATETIME(dt) \
#define SECS_PER_MIN (60)
static const long dayInYearByMonth[12] =
{ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
static const long dayInLeapYearByMonth[12] =
{ 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 };
#ifdef DEBUG
#define DEBUG_DATE(dt) \
"type=%o %04ld-%02u-%02uT%02u:%02u:%03f", \
else \
else \
#else
#define DEBUG_DATE(dt)
#endif
/**
* _xmlSchemaParseGYear:
* @dt: pointer to a date structure
* @str: pointer to the string to analyze
*
* Parses a xs:gYear without time zone and fills in the appropriate
* field of the @dt structure. @str is updated to point just after the
* xs:gYear. It is supposed that @dt->year is big enough to contain
* the year.
*
* Returns 0 or the error code
*/
static int
return -1;
if (*cur == '-') {
isneg = 1;
cur++;
}
cur++;
digcnt++;
}
/* year must be at least 4 digits (CCYY); over 4
* digits cannot have a leading zero. */
return 1;
if (isneg)
return 2;
return 0;
}
/**
* PARSE_2_DIGITS:
* @num: the integer to fill in
* @cur: an #xmlChar *
* @invalid: an integer
*
* Parses a 2-digits integer and updates @num with the value. @cur is
* updated to point just after the integer.
* In case of error, @invalid is set to %TRUE, values of @num and
* @cur are undefined.
*/
invalid = 1; \
else \
cur += 2;
/**
* PARSE_FLOAT:
* @num: the double to fill in
* @cur: an #xmlChar *
* @invalid: an integer
*
* Parses a float and updates @num with the value. @cur is
* updated to point just after the float. The float must have a
* 2-digits integer part and may or may not have a decimal part.
* In case of error, @invalid is set to %TRUE, values of @num and
* @cur are undefined.
*/
double mult = 1; \
cur++; \
invalid = 1; \
mult /= 10; \
cur++; \
} \
}
/**
* _xmlSchemaParseGMonth:
* @dt: pointer to a date structure
* @str: pointer to the string to analyze
*
* Parses a xs:gMonth without time zone and fills in the appropriate
* field of the @dt structure. @str is updated to point just after the
* xs:gMonth.
*
* Returns 0 or the error code
*/
static int
int ret = 0;
unsigned int value = 0;
if (ret != 0)
return ret;
if (!VALID_MONTH(value))
return 2;
return 0;
}
/**
* _xmlSchemaParseGDay:
* @dt: pointer to a date structure
* @str: pointer to the string to analyze
*
* Parses a xs:gDay without time zone and fills in the appropriate
* field of the @dt structure. @str is updated to point just after the
* xs:gDay.
*
* Returns 0 or the error code
*/
static int
int ret = 0;
unsigned int value = 0;
if (ret != 0)
return ret;
return 2;
return 0;
}
/**
* _xmlSchemaParseTime:
* @dt: pointer to a date structure
* @str: pointer to the string to analyze
*
* Parses a xs:time without time zone and fills in the appropriate
* fields of the @dt structure. @str is updated to point just after the
* xs:time.
* In case of error, values of @dt fields are undefined.
*
* Returns 0 or the error code
*/
static int
int ret = 0;
int value = 0;
if (ret != 0)
return ret;
if (*cur != ':')
return 1;
if (!VALID_HOUR(value))
return 2;
cur++;
/* the ':' insures this string is xs:time */
if (ret != 0)
return ret;
return 2;
if (*cur != ':')
return 1;
cur++;
if (ret != 0)
return ret;
return 2;
return 0;
}
/**
* _xmlSchemaParseTimeZone:
* @dt: pointer to a date structure
* @str: pointer to the string to analyze
*
* Parses a time zone without time zone and fills in the appropriate
* field of the @dt structure. @str is updated to point just after the
* time zone.
*
* Returns 0 or the error code
*/
static int
int ret = 0;
return -1;
switch (*cur) {
case 0:
break;
case 'Z':
cur++;
break;
case '+':
case '-': {
cur++;
if (ret != 0)
return ret;
if (!VALID_HOUR(tmp))
return 2;
if (*cur != ':')
return 1;
cur++;
if (ret != 0)
return ret;
return 2;
if (isneg)
return 2;
break;
}
default:
return 1;
}
return 0;
}
/**
* _xmlSchemaBase64Decode:
* @ch: a character
*
* Converts a base64 encoded character to its base 64 value.
*
* Returns 0-63 (value), 64 (pad), or -1 (not recognized)
*/
static int
return -1;
}
/****************************************************************
* *
* *
****************************************************************/
/**
* PARSE_DIGITS:
* @num: the integer to fill in
* @cur: an #xmlChar *
* @num_type: an integer flag
*
* Parses a digits integer and updates @num with the value. @cur is
* updated to point just after the integer.
* In case of error, @num_type is set to -1, values of @num and
* @cur are undefined.
*/
num_type = -1; \
else \
cur++; \
}
/**
* PARSE_NUM:
* @num: the double to fill in
* @cur: an #xmlChar *
* @num_type: an integer flag
*
* Parses a float or integer and updates @num with the value. @cur is
* updated to point just after the number. If the number is a float,
* then it must have an integer part and a decimal part; @num_type will
* be set to 1. If there is no decimal part, @num_type is set to zero.
* In case of error, @num_type is set to -1, values of @num and
* @cur are undefined.
*/
num = 0; \
double mult = 1; \
cur++; \
num_type = -1; \
else \
num_type = 1; \
mult /= 10; \
cur++; \
} \
}
/**
* xmlSchemaValidateDates:
* @type: the expected type or XML_SCHEMAS_UNKNOWN
* @dateTime: string to analyze
* @val: the return computed value
*
* Check that @dateTime conforms to the lexical space of one of the date types.
* if true a value is computed and returned in @val.
*
* Returns 0 if this validates, a positive error code number otherwise
* and -1 in case of internal or API error.
*/
static int
int collapse) {
int ret;
#define RETURN_TYPE_IF_VALID(t) \
if (IS_TZO_CHAR(*cur)) { \
if (ret == 0) { \
if (*cur != 0) \
goto error; \
goto done; \
} \
}
return -1;
if (collapse)
return 1;
return -1;
/*
* It's an incomplete date (xs:gMonthDay, xs:gMonth or
* xs:gDay)
*/
cur += 2;
/* is it an xs:gDay? */
if (*cur == '-') {
if (type == XML_SCHEMAS_GMONTH)
goto error;
++cur;
if (ret != 0)
goto error;
goto error;
}
/*
* it should be an xs:gMonthDay or xs:gMonth
*/
if (ret != 0)
goto error;
/*
* a '-' char could indicate this type is xs:gMonthDay or
* a negative time zone offset. Check for xs:gMonthDay first.
* Also the first three char's of a negative tzo (-MM:SS) can
* appear to be a valid day; so even if the day portion
* of the xs:gMonthDay verifies, we must insure it was not
* a tzo.
*/
if (*cur == '-') {
cur++;
/*
* we can use the VALID_MDAY macro to validate the month
* and day because the leap year test will flag year zero
* as a leap year (even though zero is an invalid year).
* FUTURE TODO: Zero will become valid in XML Schema 1.1
* probably.
*/
goto error;
}
}
/*
* not xs:gMonthDay so rewind and check if just xs:gMonth
* with an optional time zone.
*/
}
goto error;
}
/*
* It's a right-truncated date or an xs:time.
* Try to parse an xs:time then fallback on right-truncated dates.
*/
if (ret == 0) {
/* it's an xs:time */
}
}
/* fallback on date parsing */
if (ret != 0)
goto error;
/* is it an xs:gYear? */
if (*cur != '-')
goto error;
cur++;
if (ret != 0)
goto error;
/* is it an xs:gYearMonth? */
if (*cur != '-')
goto error;
cur++;
goto error;
/* is it an xs:date? */
if (*cur != 'T')
goto error;
cur++;
/* it should be an xs:dateTime */
if (ret != 0)
goto error;
if (collapse)
goto error;
done:
#if 1
goto error;
#else
/*
* insure the parsed type is equal to or less significant (right
* truncated) than the desired type.
*/
/* time only matches time */
goto error;
if ((type == XML_SCHEMAS_DATETIME) &&
goto error;
if ((type == XML_SCHEMAS_DATE) &&
goto error;
goto error;
goto error;
}
#endif
else
return 0;
return 1;
}
/**
* xmlSchemaValidateDuration:
* @type: the predefined type
* @duration: string to analyze
* @val: the return computed value
*
* Check that @duration conforms to the lexical space of the duration type.
* if true a value is computed and returned in @val.
*
* Returns 0 if this validates, a positive error code number otherwise
* and -1 in case of internal or API error.
*/
static int
int collapse) {
int isneg = 0;
unsigned int seq = 0;
double num;
int num_type = 0; /* -1 = invalid, 0 = int, 1 = floating */
return -1;
if (collapse)
if (*cur == '-') {
isneg = 1;
cur++;
}
/* duration must start with 'P' (after sign) */
if (*cur++ != 'P')
return 1;
if (*cur == 0)
return 1;
return -1;
while (*cur != 0) {
goto error;
/* T designator must be present for time items */
if (*cur == 'T') {
if (seq <= 3) {
seq = 3;
cur++;
} else
return 1;
} else if (seq == 3)
goto error;
/* parse the number portion of the item */
goto error;
/* update duration based on item type */
/* verify numeric type; only seconds can be float */
goto error;
switch (seq) {
case 0:
break;
case 1:
break;
default:
/* convert to seconds using multiplier */
seq++;
break;
}
break; /* exit loop */
}
/* no date designators found? */
goto error;
}
cur++;
if (collapse)
}
if (isneg) {
}
else
return 0;
return 1;
}
/**
* xmlSchemaStrip:
* @value: a value
*
* Removes the leading and ending spaces of a string
*
* Returns the new string or NULL if no change was required.
*/
static xmlChar *
f = end;
end--;
end++;
}
/**
* xmlSchemaWhiteSpaceReplace:
* @value: a value
*
* Replaces 0xd, 0x9 and 0xa with a space.
*
* Returns the new string or NULL if no change was required.
*/
xmlChar *
return(NULL);
while ((*cur != 0) &&
cur++;
}
if (*cur == 0)
return (NULL);
/* TODO FIXME: I guess gcc will bark at this. */
do {
*mcur = ' ';
mcur++;
} while (*mcur != 0);
return(ret);
}
/**
* xmlSchemaCollapseString:
* @value: a value
*
* Removes and normalize white spaces in the string
*
* Returns the new string or NULL if no change was required.
*/
xmlChar *
xmlChar *g;
int col = 0;
while (*end != 0) {
break;
break;
}
end++;
}
if (col == 0) {
f = end;
end--;
end++;
}
end = g;
while (*end != 0) {
if (IS_BLANK_CH(*end)) {
end++;
if (*end != 0)
*g++ = ' ';
} else
*g++ = *end++;
}
*g = 0;
}
/**
* xmlSchemaValAtomicListNode:
* @type: the predefined atomic type for a token in the list
* @value: the list value to check
* @ret: the return computed value
* @node: the node containing the value
*
* Check that a value conforms to the lexical space of the predefined
* list type. if true a value is computed and returned in @ret.
*
* Returns the number of items if this validates, a negative error code
* number otherwise
*/
static int
int nb_values = 0;
int tmp = 0;
return(-1);
}
return(-1);
}
}
/*
* Split the list
*/
while (*cur != 0) {
if (IS_BLANK_CH(*cur)) {
*cur = 0;
cur++;
} else {
nb_values++;
cur++;
}
}
if (nb_values == 0) {
return(nb_values);
}
if (tmp != 0)
break;
}
/* TODO what return value ? c.f. bug #158628
if (ret != NULL) {
TODO
} */
if (tmp == 0)
return(nb_values);
return(-1);
}
/**
* xmlSchemaParseUInt:
* @str: pointer to the string R/W
* @llo: pointer to the low result
* @lmi: pointer to the mid result
* @lhi: pointer to the high result
*
* Parse an unsigned long into 3 fields.
*
* Returns the number of significant digits in the number or
* -1 if overflow of the capacity
*/
static int
int ret = 0, i = 0;
cur++;
}
}
if (i > 24) {
return(-1);
}
while (i > 16) {
i--;
}
while (i > 8) {
i--;
}
while (i > 0) {
i--;
}
return(ret);
}
/**
* xmlSchemaValAtomicType:
* @type: the predefined type
* @value: the value to check
* @val: the return computed value
* @node: the node containing the value
* flags: flags to control the vlidation
*
* Check that a value conforms to the lexical space of the atomic type.
* if true a value is computed and returned in @val.
* This checks the value space for list types as well (IDREFS, NMTOKENS).
*
* Returns 0 if this validates, a positive error code number otherwise
* and -1 in case of internal or API error.
*/
static int
{
int ret = 0;
if (xmlSchemaTypesInitialized == 0)
return (-1);
/*
* validating a non existant text node is similar to validating
* an empty one.
*/
else
}
}
switch (type->builtInType) {
case XML_SCHEMAS_UNKNOWN:
goto error;
case XML_SCHEMAS_ANYTYPE:
if (v != NULL) {
*val = v;
} else {
goto error;
}
}
goto return0;
case XML_SCHEMAS_STRING:
if (! normOnTheFly) {
if (ws == XML_SCHEMA_WHITESPACE_REPLACE) {
while (*cur != 0) {
goto return1;
} else {
cur++;
}
}
} else if (ws == XML_SCHEMA_WHITESPACE_COLLAPSE) {
while (*cur != 0) {
goto return1;
} else if IS_WSP_SPACE_CH(*cur) {
cur++;
if IS_WSP_SPACE_CH(*cur)
goto return1;
} else {
cur++;
}
}
}
}
if (applyNorm) {
if (ws == XML_SCHEMA_WHITESPACE_COLLAPSE)
else if (ws == XML_SCHEMA_WHITESPACE_REPLACE)
}
if (v != NULL) {
*val = v;
} else {
goto error;
}
}
goto return0;
case XML_SCHEMAS_NORMSTRING:{
if (normOnTheFly) {
if (applyNorm) {
if (ws == XML_SCHEMA_WHITESPACE_COLLAPSE)
else
}
} else {
while (*cur != 0) {
goto return1;
} else {
cur++;
}
}
}
if (v != NULL) {
*val = v;
} else {
goto error;
}
}
goto return0;
}
case XML_SCHEMAS_DECIMAL:{
goto return1;
/*
* xs:decimal has a whitespace-facet value of 'collapse'.
*/
if (normOnTheFly)
/*
* First we handle an optional sign.
*/
neg = 0;
if (*cur == '-') {
neg = 1;
cur++;
} else if (*cur == '+')
cur++;
/*
* Disallow: "", "-", "- "
*/
if (*cur == 0)
goto return1;
/*
* Next we "pre-parse" the number, in preparation for calling
* the common routine xmlSchemaParseUInt. We get rid of any
* leading zeroes (because we have reserved only 25 chars),
* and note the position of a decimal point.
*/
len = 0;
integ = ~0u;
hasLeadingZeroes = 0;
/*
* Skip leading zeroes.
*/
while (*cur == '0') {
cur++;
hasLeadingZeroes = 1;
}
if (*cur != 0) {
do {
len++;
} else if (*cur == '.') {
cur++;
do {
len++;
} else
break;
} while (len < 24);
/*
* Disallow "." but allow "00."
*/
if ((len == 0) && (!hasLeadingZeroes))
goto return1;
break;
} else
break;
} while (len < 24);
}
if (normOnTheFly)
if (*cur != 0)
goto return1; /* error if any extraneous chars */
if (v != NULL) {
/*
* Now evaluate the significant digits of the number
*/
if (len != 0) {
if (integ != ~0u) {
/*
* Get rid of trailing zeroes in the
* fractional part.
*/
cptr--;
len--;
}
}
/*
* Terminate the (preparsed) string.
*/
if (len != 0) {
*cptr = 0;
}
}
/*
* Set the total digits to 1 if a zero value.
*/
if (len == 0) {
/* Speedup for zero values. */
} else {
if (integ == ~0u)
else
}
*val = v;
}
}
goto return0;
}
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:
break;
case XML_SCHEMAS_DURATION:
break;
case XML_SCHEMAS_FLOAT:
case XML_SCHEMAS_DOUBLE:{
int neg = 0;
if (normOnTheFly)
cur += 3;
if (*cur != 0)
goto return1;
if (type == xmlSchemaTypeFloatDef) {
if (v != NULL) {
v->value.f = (float) xmlXPathNAN;
} else {
goto error;
}
} else {
if (v != NULL) {
v->value.d = xmlXPathNAN;
} else {
goto error;
}
}
*val = v;
}
goto return0;
}
if (*cur == '-') {
neg = 1;
cur++;
}
cur += 3;
if (*cur != 0)
goto return1;
if (type == xmlSchemaTypeFloatDef) {
if (v != NULL) {
if (neg)
v->value.f = (float) xmlXPathNINF;
else
v->value.f = (float) xmlXPathPINF;
} else {
goto error;
}
} else {
if (v != NULL) {
if (neg)
v->value.d = xmlXPathNINF;
else
v->value.d = xmlXPathPINF;
} else {
goto error;
}
}
*val = v;
}
goto return0;
}
cur++;
goto return1;
cur++;
}
if (*cur == '.') {
cur++;
cur++;
}
cur++;
cur++;
cur++;
}
if (normOnTheFly)
if (*cur != 0)
goto return1;
if (type == xmlSchemaTypeFloatDef) {
if (v != NULL) {
/*
* TODO: sscanf seems not to give the correct
* E.g. "1E-149" results in zero.
*/
&(v->value.f)) == 1) {
*val = v;
} else {
goto return1;
}
} else {
goto error;
}
} else {
if (v != NULL) {
/*
* TODO: sscanf seems not to give the correct
*/
&(v->value.d)) == 1) {
*val = v;
} else {
goto return1;
}
} else {
goto error;
}
}
}
goto return0;
}
case XML_SCHEMAS_BOOLEAN:{
if (normOnTheFly) {
if (*cur == '0') {
ret = 0;
cur++;
} else if (*cur == '1') {
ret = 1;
cur++;
} else if (*cur == 't') {
cur++;
(*cur++ == 'e')) {
ret = 1;
} else
goto return1;
} else if (*cur == 'f') {
cur++;
ret = 0;
} else
goto return1;
} else
goto return1;
if (*cur != 0) {
if (*cur != 0)
goto return1;
}
} else {
ret = 0;
ret = 1;
&& (cur[4] == 0))
ret = 1;
ret = 0;
else
goto return1;
}
if (v != NULL) {
*val = v;
} else {
goto error;
}
}
goto return0;
}
case XML_SCHEMAS_TOKEN:{
if (! normOnTheFly) {
while (*cur != 0) {
goto return1;
} else if (*cur == ' ') {
cur++;
if (*cur == 0)
goto return1;
if (*cur == ' ')
goto return1;
} else {
cur++;
}
}
}
if (v != NULL) {
*val = v;
} else {
goto error;
}
}
goto return0;
}
case XML_SCHEMAS_LANGUAGE:
if (normOnTheFly) {
}
if (v != NULL) {
*val = v;
} else {
goto error;
}
}
goto return0;
}
goto return1;
case XML_SCHEMAS_NMTOKEN:
if (v != NULL) {
*val = v;
} else {
goto error;
}
}
goto return0;
}
goto return1;
case XML_SCHEMAS_NMTOKENS:
if (ret > 0)
ret = 0;
else
ret = 1;
goto done;
case XML_SCHEMAS_NAME:
if (v != NULL) {
*val = v;
} else {
goto error;
}
}
goto done;
case XML_SCHEMAS_QNAME:{
if (ret != 0)
goto done;
goto return1;
}
}
if (v == NULL) {
goto error;
}
else
*val = v;
} else
goto done;
}
case XML_SCHEMAS_NCNAME:
if (v != NULL) {
*val = v;
} else {
goto error;
}
}
goto done;
case XML_SCHEMAS_ID:
if (v != NULL) {
*val = v;
} else {
goto error;
}
}
/*
* NOTE: the IDness might have already be declared in the DTD
*/
} else
ret = 2;
} else {
}
}
}
goto done;
case XML_SCHEMAS_IDREF:
if (v == NULL)
goto error;
*val = v;
}
} else
}
goto done;
case XML_SCHEMAS_IDREFS:
if (ret < 0)
ret = 2;
else
ret = 0;
}
goto done;
case XML_SCHEMAS_ENTITY:{
ret = 3;
if (ret == 0) {
} else {
}
ret = 4;
}
TODO;
}
}
goto done;
}
case XML_SCHEMAS_ENTITIES:
goto return3;
if (ret <= 0)
ret = 1;
else
ret = 0;
}
goto done;
case XML_SCHEMAS_NOTATION:{
ret = 1;
}
}
ret = 3;
if (ret == 0) {
if (ret == 1)
ret = 0;
else
ret = 1;
}
if (v != NULL) {
else
*val = v;
} else {
goto error;
}
}
goto done;
}
case XML_SCHEMAS_ANYURI:{
if (*value != 0) {
if (normOnTheFly) {
}
goto return1;
}
if (v == NULL)
goto error;
*val = v;
}
goto return0;
}
case XML_SCHEMAS_HEXBINARY:{
int total, i = 0;
goto return1;
if (normOnTheFly)
i++;
cur++;
}
if (normOnTheFly)
if (*cur != 0)
goto return1;
if ((i % 2) != 0)
goto return1;
if (v == NULL)
goto error;
/*
* Copy only the normalized piece.
* CRITICAL TODO: Check this.
*/
xmlFree(v);
goto return1;
}
while (i-- > 0) {
if (*base >= 'a')
base++;
}
*val = v;
}
goto return0;
}
case XML_SCHEMAS_BASE64BINARY:{
/* ISSUE:
*
* Ignore all stray characters? (yes, currently)
* Worry about long lines? (no, currently)
*
* rfc2045.txt:
*
* "The encoded output stream must be represented in lines of
* no more than 76 characters each. All line breaks or other
* characters not found in Table 1 must be ignored by decoding
* software. In base64 data, characters other than those in
* Table 1, line breaks, and other white space probably
* indicate a transmission error, about which a warning
* message or even a message rejection might be appropriate
* under some circumstances." */
goto return1;
int decc;
if (decc < 0) ;
else if (decc < 64)
i++;
else
break;
}
int decc;
if (decc < 0) ;
else if (decc < 64)
goto return1;
if (decc == 64)
pad++;
}
/* rfc2045.txt: "Special processing is performed if fewer than
* 24 bits are available at the end of the data being encoded.
* A full encoding quantum is always completed at the end of a
* body. When fewer than 24 input bits are available in an
* input group, zero bits are added (on the right) to form an
* integral number of 6-bit groups. Padding at the end of the
* data is performed using the "=" character. Since all
* base64 input is an integral number of octets, only the
* following cases can arise: (1) the final quantum of
* encoding input is an integral multiple of 24 bits; here,
* the final unit of encoded output will be an integral
* multiple ofindent: Standard input:701: Warning:old style
* assignment ambiguity in "=*". Assuming "= *" 4 characters
* with no "=" padding, (2) the final
* quantum of encoding input is exactly 8 bits; here, the
* final unit of encoded output will be two characters
* followed by two "=" padding characters, or (3) the final
* quantum of encoding input is exactly 16 bits; here, the
* final unit of encoded output will be three characters
* followed by one "=" padding character." */
if (pad == 0) {
if (i % 4 != 0)
goto return1;
} else if (pad == 1) {
int decc;
if (i % 4 != 3)
goto return1;
--cur;
/* 16bits in 24bits means 2 pad bits: nnnnnn nnmmmm mmmm00*/
/* 00111100 -> 0x3c */
if (decc & ~0x3c)
goto return1;
total += 2;
} else if (pad == 2) {
int decc;
if (i % 4 != 2)
goto return1;
--cur;
/* 8bits in 12bits means 4 pad bits: nnnnnn nn0000 */
/* 00110000 -> 0x30 */
if (decc & ~0x30)
goto return1;
total += 1;
} else
goto return1;
if (v == NULL)
goto error;
base =
sizeof(xmlChar));
xmlFree(v);
goto return1;
}
if (_xmlSchemaBase64Decode(*cur) >= 0) {
++base;
}
*base = 0;
*val = v;
}
goto return0;
}
case XML_SCHEMAS_INTEGER:
case XML_SCHEMAS_PINTEGER:
case XML_SCHEMAS_NPINTEGER:
case XML_SCHEMAS_NINTEGER:
case XML_SCHEMAS_NNINTEGER:{
int sign = 0;
goto return1;
if (normOnTheFly)
if (*cur == '-') {
sign = 1;
cur++;
} else if (*cur == '+')
cur++;
if (ret == -1)
goto return1;
if (normOnTheFly)
if (*cur != 0)
goto return1;
if ((sign == 0) &&
goto return1;
if (sign == 1)
goto return1;
goto return1;
if (sign == 0)
goto return1;
goto return1;
if ((sign == 1) &&
goto return1;
}
if (v != NULL) {
if (ret == 0)
ret++;
*val = v;
}
}
goto return0;
}
case XML_SCHEMAS_LONG:
case XML_SCHEMAS_BYTE:
case XML_SCHEMAS_SHORT:
case XML_SCHEMAS_INT:{
int sign = 0;
goto return1;
if (*cur == '-') {
sign = 1;
cur++;
} else if (*cur == '+')
cur++;
if (ret < 0)
goto return1;
if (*cur != 0)
goto return1;
if (hi >= 922) {
if (hi > 922)
goto return1;
if (mi >= 33720368) {
if (mi > 33720368)
goto return1;
goto return1;
goto return1;
}
}
if (hi != 0)
goto return1;
if (mi >= 21) {
if (mi > 21)
goto return1;
goto return1;
goto return1;
}
goto return1;
goto return1;
goto return1;
goto return1;
goto return1;
goto return1;
}
if (v != NULL) {
*val = v;
}
}
goto return0;
}
case XML_SCHEMAS_UINT:
case XML_SCHEMAS_ULONG:
case XML_SCHEMAS_USHORT:
case XML_SCHEMAS_UBYTE:{
goto return1;
if (ret < 0)
goto return1;
if (*cur != 0)
goto return1;
if (hi >= 1844) {
if (hi > 1844)
goto return1;
if (mi >= 67440737) {
if (mi > 67440737)
goto return1;
if (lo > 9551615)
goto return1;
}
}
if (hi != 0)
goto return1;
if (mi >= 42) {
if (mi > 42)
goto return1;
if (lo > 94967295)
goto return1;
}
goto return1;
if (lo > 65535)
goto return1;
goto return1;
if (lo > 255)
goto return1;
}
if (v != NULL) {
*val = v;
}
}
goto return0;
}
}
done:
return (ret);
return (3);
return (1);
return (0);
return (-1);
}
/**
* xmlSchemaValPredefTypeNode:
* @type: the predefined type
* @value: the value to check
* @val: the return computed value
* @node: the node containing the value
*
* Check that a value conforms to the lexical space of the predefined type.
* if true a value is computed and returned in @val.
*
* Returns 0 if this validates, a positive error code number otherwise
* and -1 in case of internal or API error.
*/
int
}
/**
* xmlSchemaValPredefTypeNodeNoNorm:
* @type: the predefined type
* @value: the value to check
* @val: the return computed value
* @node: the node containing the value
*
* Check that a value conforms to the lexical space of the predefined type.
* if true a value is computed and returned in @val.
* This one does apply any normalization to the value.
*
* Returns 0 if this validates, a positive error code number otherwise
* and -1 in case of internal or API error.
*/
int
}
/**
* xmlSchemaValidatePredefinedType:
* @type: the predefined type
* @value: the value to check
* @val: the return computed value
*
* Check that a value conforms to the lexical space of the predefined type.
* if true a value is computed and returned in @val.
*
* Returns 0 if this validates, a positive error code number otherwise
* and -1 in case of internal or API error.
*/
int
xmlSchemaValPtr *val) {
}
/**
* xmlSchemaCompareDecimals:
* @x: a first decimal value
* @y: a second decimal value
*
* Compare 2 decimals
*
* Returns -1 if x < y, 0 if x == y, 1 if x > y and -2 in case of error
*/
static int
{
/*
* First test: If x is -ve and not zero
*/
/*
* Then if y is -ve and not zero reverse the compare
*/
order = -1;
/*
* Otherwise (y >= 0) we have the answer
*/
else
return (-1);
/*
* If x is not -ve and y is -ve we have the answer
*/
return (1);
}
/*
* If it's not simply determined by a difference in sign,
* then we need to compare the actual values of the two nums.
* To do this, we start by looking at the integral parts.
* If the number of integral digits differ, then we have our
* answer.
*/
/*
* NOTE: We changed the "total" for values like "0.1"
* (or "-0.1" or ".1") to be 1, which was 2 previously.
* Therefore the special case, when such values are
* compared with 0, needs to be handled separately;
* otherwise a zero would be recognized incorrectly as
* greater than those values. This has the nice side effect
* that we gain an overall optimized comparison with zeroes.
* Note that a "0" has a "total" of 1 already.
*/
if (integx == 1) {
if (integy != 1)
return -order;
return -order;
else
return(0);
}
}
if (integy == 1) {
if (integx != 1)
return order;
return order;
else
return(0);
}
}
return order;
return -order;
/*
* If the number of integral digits is the same for both numbers,
* then things get a little more complicated. We need to "normalize"
* the numbers in order to properly compare them. To do this, we
* look at the total length of each number (length => number of
* significant digits), and divide the "shorter" by 10 (decreasing
* the length) until they are of equal length.
*/
if (dlen < 0) { /* y has more digits than x */
swp = x;
} else { /* x has more digits than y */
swp = y;
}
hi = 0;
dlen -= 8;
}
while (dlen > 0) {
dlen--;
}
return order;
return order;
return order;
return 0;
} else {
return order;
}
}
}
}
return -order;
}
/**
* xmlSchemaCompareDurations:
* @x: a first duration value
* @y: a second duration value
*
* Compare 2 durations
*
* Returns -1 if x < y, 0 if x == y, 1 if x > y, 2 if x <> y, and -2 in
* case of error
*/
static int
{
double sec;
int invert = 1;
{ 0, 28, 59, 89, 120, 150, 181, 212, 242, 273, 303, 334, },
{ 0, 31, 62, 92, 123, 153, 184, 215, 245, 276, 306, 337} };
return -2;
/* months */
/* seconds */
/* days */
/* easy test */
if (mon == 0) {
if (day == 0)
if (sec == 0.0)
return 0;
else if (sec < 0.0)
return -1;
else
return 1;
else if (day < 0)
return -1;
else
return 1;
}
if (mon > 0) {
return 1;
else {
}
return -1;
} else {
invert = -1;
}
if (myear == 0) {
minday = 0;
maxday = 0;
} else {
}
return(0); /* can this really happen ? */
return(-invert);
return(invert);
/* indeterminate */
return 2;
}
/*
*/
/**
* xmlSchemaDupVal:
* @v: the #xmlSchemaValPtr value to duplicate
*
* Makes a copy of @v. The calling program is responsible for freeing
* the returned value.
*
* returns a pointer to a duplicated #xmlSchemaValPtr or NULL if error.
*/
static xmlSchemaValPtr
{
return NULL;
return ret;
}
/**
* xmlSchemaCopyValue:
* @val: the precomputed value to be copied
*
* Copies the precomputed value. This duplicates any string within.
*
* Returns the copy or NULL if a copy for a data-type is not implemented.
*/
{
/*
* Copy the string values.
*/
case XML_SCHEMAS_ANYTYPE:
case XML_SCHEMAS_IDREFS:
case XML_SCHEMAS_ENTITIES:
case XML_SCHEMAS_NMTOKENS:
return (NULL);
case XML_SCHEMAS_STRING:
case XML_SCHEMAS_NORMSTRING:
case XML_SCHEMAS_TOKEN:
case XML_SCHEMAS_LANGUAGE:
case XML_SCHEMAS_NAME:
case XML_SCHEMAS_NCNAME:
case XML_SCHEMAS_ID:
case XML_SCHEMAS_IDREF:
case XML_SCHEMAS_ENTITY:
case XML_SCHEMAS_NMTOKEN:
case XML_SCHEMAS_ANYURI:
break;
case XML_SCHEMAS_QNAME:
case XML_SCHEMAS_NOTATION:
break;
case XML_SCHEMAS_HEXBINARY:
break;
case XML_SCHEMAS_BASE64BINARY:
break;
default:
break;
}
else
}
return (ret);
}
/**
* _xmlSchemaDateAdd:
* @dt: an #xmlSchemaValPtr
* @dur: an #xmlSchemaValPtr of type #XS_DURATION
*
* is either #XML_SCHEMAS_DATETIME, #XML_SCHEMAS_DATE, #XML_SCHEMAS_GYEARMONTH,
* or #XML_SCHEMAS_GYEAR. The returned #xmlSchemaVal is the same type as
* @dt. The calling program is responsible for freeing the returned value.
*
* Returns a pointer to a new #xmlSchemaVal or NULL if error.
*/
static xmlSchemaValPtr
{
xmlSchemaValDatePtr r, d;
return NULL;
return NULL;
/* make a copy so we don't alter the original value */
return NULL;
}
/* normalization */
if (d->mon == 0)
d->mon = 1;
/* normalize for time zone offset */
d->tzo = 0;
/* normalization */
if (d->day == 0)
d->day = 1;
/* month */
/* year (may be modified later) */
if (r->year == 0) {
if (d->year > 0)
r->year--;
else
r->year++;
}
/* time zone */
/* seconds */
if (r->sec != 0.0) {
}
/* minute */
/* hours */
/*
* days
* Note we use tempdays because the temporary values may need more
* than 5 bits
*/
else if (d->day < 1)
tempdays = 1;
else
while (1) {
if (tempdays < 1) {
if (tyr == 0)
tyr--;
/*
* Coverity detected an overrun in daysInMonth
* of size 12 at position 12 with index variable "((r)->mon - 1)"
*/
if (tmon < 0)
tmon = 0;
if (tmon > 12)
tmon = 12;
carry = -1;
carry = 1;
} else
break;
if (r->year == 0) {
if (temp < 1)
r->year--;
else
r->year++;
}
}
/*
*/
}
}
return ret;
}
/**
* xmlSchemaDateNormalize:
* @offset: number of seconds to adjust @dt by.
*
* Normalize @dt to GMT time. The @offset parameter is subtracted from
* the return value is a time-zone offset is present on @dt.
*
* Returns a normalized copy of @dt or NULL if error.
*/
static xmlSchemaValPtr
{
return NULL;
return xmlSchemaDupVal(dt);
return NULL;
return NULL;
/* ret->value.date.tzo = 0; */
return ret;
}
/**
* _xmlSchemaDateCastYMToDays:
* @dt: an #xmlSchemaValPtr
*
* Convert mon and year of @dt to total number of days. Take the
* number of years since (or before) 1 AD and add the number of leap
* years. This is a function because negative
* years must be handled a little differently and there is no zero year.
*
* Returns number of days.
*/
static long
{
long ret;
int mon;
else
return ret;
}
/**
* TIME_TO_NUMBER:
* @dt: an #xmlSchemaValPtr
*
* Calculates the number of seconds in the time portion of @dt.
*
* Returns seconds.
*/
#define TIME_TO_NUMBER(dt) \
/**
* xmlSchemaCompareDates:
*
*
* Returns -1 if x < y, 0 if x == y, 1 if x > y, 2 if x <> y, and -2 in
* case of error
*/
static int
{
return -2;
p1 = xmlSchemaDateNormalize(x, 0);
/* normalize y + 14:00 */
return -1;
double sec;
if (sec < 0.0) {
return -1;
} else {
int ret = 0;
/* normalize y - 14:00 */
ret = 1;
if (sec > 0.0)
ret = 1;
else
}
if (ret != 0)
return(ret);
}
} else {
}
}
q1 = xmlSchemaDateNormalize(y, 0);
/* normalize x - 14:00 */
return -1;
double sec;
if (sec < 0.0) {
return -1;
} else {
int ret = 0;
/* normalize x + 14:00 */
ret = 1;
if (sec > 0.0)
ret = 1;
else
}
if (ret != 0)
return(ret);
}
} else {
}
}
/*
* if the same type then calculate the difference
*/
int ret = 0;
q1 = xmlSchemaDateNormalize(y, 0);
p1 = xmlSchemaDateNormalize(x, 0);
ret = -1;
ret = 1;
} else {
double sec;
if (sec < 0.0)
ret = -1;
else if (sec > 0.0)
ret = 1;
}
return(ret);
}
switch (x->type) {
case XML_SCHEMAS_DATETIME:
xmask = 0xf;
break;
case XML_SCHEMAS_DATE:
xmask = 0x7;
break;
case XML_SCHEMAS_GYEAR:
xmask = 0x1;
break;
case XML_SCHEMAS_GMONTH:
xmask = 0x2;
break;
case XML_SCHEMAS_GDAY:
xmask = 0x3;
break;
case XML_SCHEMAS_GYEARMONTH:
xmask = 0x3;
break;
case XML_SCHEMAS_GMONTHDAY:
xmask = 0x6;
break;
case XML_SCHEMAS_TIME:
xmask = 0x8;
break;
default:
xmask = 0;
break;
}
switch (y->type) {
case XML_SCHEMAS_DATETIME:
ymask = 0xf;
break;
case XML_SCHEMAS_DATE:
ymask = 0x7;
break;
case XML_SCHEMAS_GYEAR:
ymask = 0x1;
break;
case XML_SCHEMAS_GMONTH:
ymask = 0x2;
break;
case XML_SCHEMAS_GDAY:
ymask = 0x3;
break;
case XML_SCHEMAS_GYEARMONTH:
ymask = 0x3;
break;
case XML_SCHEMAS_GMONTHDAY:
ymask = 0x6;
break;
case XML_SCHEMAS_TIME:
ymask = 0x8;
break;
default:
ymask = 0;
break;
}
/* year */
if (xor_mask & 1)
return 2; /* indeterminate */
else if (and_mask & 1) {
return -1;
return 1;
}
/* month */
if (xor_mask & 2)
return 2; /* indeterminate */
else if (and_mask & 2) {
return -1;
return 1;
}
/* day */
if (xor_mask & 4)
return 2; /* indeterminate */
else if (and_mask & 4) {
return -1;
return 1;
}
/* time */
if (xor_mask & 8)
return 2; /* indeterminate */
else if (and_mask & 8) {
return -1;
return 1;
return -1;
return 1;
return -1;
return 1;
}
return 0;
}
/**
* xmlSchemaComparePreserveReplaceStrings:
* @x: a first string value
* @y: a second string value
* @invert: inverts the result if x < y or x > y.
*
* Compare 2 string for their normalized values.
* @x is a string with whitespace of "preserve", @y is
* a string with a whitespace of "replace". I.e. @x could
* be an "xsd:string" and @y an "xsd:normalizedString".
*
* Returns -1 if x < y, 0 if x == y, 1 if x > y, and -2 in
* case of error
*/
static int
const xmlChar *y,
int invert)
{
int tmp;
while ((*x != 0) && (*y != 0)) {
if (IS_WSP_REPLACE_CH(*y)) {
if (! IS_WSP_SPACE_CH(*x)) {
if ((*x - 0x20) < 0) {
if (invert)
return(1);
else
return(-1);
} else {
if (invert)
return(-1);
else
return(1);
}
}
} else {
tmp = *x - *y;
if (tmp < 0) {
if (invert)
return(1);
else
return(-1);
}
if (tmp > 0) {
if (invert)
return(-1);
else
return(1);
}
}
x++;
y++;
}
if (*x != 0) {
if (invert)
return(-1);
else
return(1);
}
if (*y != 0) {
if (invert)
return(1);
else
return(-1);
}
return(0);
}
/**
* xmlSchemaComparePreserveCollapseStrings:
* @x: a first string value
* @y: a second string value
*
* Compare 2 string for their normalized values.
* @x is a string with whitespace of "preserve", @y is
* a string with a whitespace of "collapse". I.e. @x could
* be an "xsd:string" and @y an "xsd:normalizedString".
*
* Returns -1 if x < y, 0 if x == y, 1 if x > y, and -2 in
* case of error
*/
static int
const xmlChar *y,
int invert)
{
int tmp;
/*
* Skip leading blank chars of the collapsed string.
*/
while IS_WSP_BLANK_CH(*y)
y++;
while ((*x != 0) && (*y != 0)) {
if IS_WSP_BLANK_CH(*y) {
if (! IS_WSP_SPACE_CH(*x)) {
/*
* The yv character would have been replaced to 0x20.
*/
if ((*x - 0x20) < 0) {
if (invert)
return(1);
else
return(-1);
} else {
if (invert)
return(-1);
else
return(1);
}
}
x++;
y++;
/*
* Skip contiguous blank chars of the collapsed string.
*/
while IS_WSP_BLANK_CH(*y)
y++;
} else {
tmp = *x++ - *y++;
if (tmp < 0) {
if (invert)
return(1);
else
return(-1);
}
if (tmp > 0) {
if (invert)
return(-1);
else
return(1);
}
}
}
if (*x != 0) {
if (invert)
return(-1);
else
return(1);
}
if (*y != 0) {
/*
* Skip trailing blank chars of the collapsed string.
*/
while IS_WSP_BLANK_CH(*y)
y++;
if (*y != 0) {
if (invert)
return(1);
else
return(-1);
}
}
return(0);
}
/**
* xmlSchemaComparePreserveCollapseStrings:
* @x: a first string value
* @y: a second string value
*
* Compare 2 string for their normalized values.
* @x is a string with whitespace of "preserve", @y is
* a string with a whitespace of "collapse". I.e. @x could
* be an "xsd:string" and @y an "xsd:normalizedString".
*
* Returns -1 if x < y, 0 if x == y, 1 if x > y, and -2 in
* case of error
*/
static int
const xmlChar *y,
int invert)
{
int tmp;
/*
* Skip leading blank chars of the collapsed string.
*/
while IS_WSP_BLANK_CH(*y)
y++;
while ((*x != 0) && (*y != 0)) {
if IS_WSP_BLANK_CH(*y) {
if (! IS_WSP_BLANK_CH(*x)) {
/*
* The yv character would have been replaced to 0x20.
*/
if ((*x - 0x20) < 0) {
if (invert)
return(1);
else
return(-1);
} else {
if (invert)
return(-1);
else
return(1);
}
}
x++;
y++;
/*
* Skip contiguous blank chars of the collapsed string.
*/
while IS_WSP_BLANK_CH(*y)
y++;
} else {
if IS_WSP_BLANK_CH(*x) {
/*
* The xv character would have been replaced to 0x20.
*/
if ((0x20 - *y) < 0) {
if (invert)
return(1);
else
return(-1);
} else {
if (invert)
return(-1);
else
return(1);
}
}
tmp = *x++ - *y++;
if (tmp < 0)
return(-1);
if (tmp > 0)
return(1);
}
}
if (*x != 0) {
if (invert)
return(-1);
else
return(1);
}
if (*y != 0) {
/*
* Skip trailing blank chars of the collapsed string.
*/
while IS_WSP_BLANK_CH(*y)
y++;
if (*y != 0) {
if (invert)
return(1);
else
return(-1);
}
}
return(0);
}
/**
* xmlSchemaCompareReplacedStrings:
* @x: a first string value
* @y: a second string value
*
* Compare 2 string for their normalized values.
*
* Returns -1 if x < y, 0 if x == y, 1 if x > y, and -2 in
* case of error
*/
static int
xmlSchemaCompareReplacedStrings(const xmlChar *x,
const xmlChar *y)
{
int tmp;
while ((*x != 0) && (*y != 0)) {
if IS_WSP_BLANK_CH(*y) {
if (! IS_WSP_BLANK_CH(*x)) {
if ((*x - 0x20) < 0)
return(-1);
else
return(1);
}
} else {
if IS_WSP_BLANK_CH(*x) {
if ((0x20 - *y) < 0)
return(-1);
else
return(1);
}
tmp = *x - *y;
if (tmp < 0)
return(-1);
if (tmp > 0)
return(1);
}
x++;
y++;
}
if (*x != 0)
return(1);
if (*y != 0)
return(-1);
return(0);
}
/**
* xmlSchemaCompareNormStrings:
* @x: a first string value
* @y: a second string value
*
* Compare 2 string for their normalized values.
*
* Returns -1 if x < y, 0 if x == y, 1 if x > y, and -2 in
* case of error
*/
static int
xmlSchemaCompareNormStrings(const xmlChar *x,
const xmlChar *y) {
int tmp;
while (IS_BLANK_CH(*x)) x++;
while (IS_BLANK_CH(*y)) y++;
while ((*x != 0) && (*y != 0)) {
if (IS_BLANK_CH(*x)) {
if (!IS_BLANK_CH(*y)) {
tmp = *x - *y;
return(tmp);
}
while (IS_BLANK_CH(*x)) x++;
while (IS_BLANK_CH(*y)) y++;
} else {
tmp = *x++ - *y++;
if (tmp < 0)
return(-1);
if (tmp > 0)
return(1);
}
}
if (*x != 0) {
while (IS_BLANK_CH(*x)) x++;
if (*x != 0)
return(1);
}
if (*y != 0) {
while (IS_BLANK_CH(*y)) y++;
if (*y != 0)
return(-1);
}
return(0);
}
/**
* xmlSchemaCompareFloats:
* @x: a first float or double value
* @y: a second float or double value
*
* Compare 2 values
*
* Returns -1 if x < y, 0 if x == y, 1 if x > y, 2 if x <> y, and -2 in
* case of error
*/
static int
return(-2);
/*
* Cast everything to doubles.
*/
if (x->type == XML_SCHEMAS_DOUBLE)
else if (x->type == XML_SCHEMAS_FLOAT)
else
return(-2);
if (y->type == XML_SCHEMAS_DOUBLE)
else if (y->type == XML_SCHEMAS_FLOAT)
else
return(-2);
/*
* Check for special cases.
*/
if (xmlXPathIsNaN(d1)) {
if (xmlXPathIsNaN(d2))
return(0);
return(1);
}
if (xmlXPathIsNaN(d2))
return(-1);
if (d1 == xmlXPathPINF) {
if (d2 == xmlXPathPINF)
return(0);
return(1);
}
if (d2 == xmlXPathPINF)
return(-1);
if (d1 == xmlXPathNINF) {
if (d2 == xmlXPathNINF)
return(0);
return(-1);
}
if (d2 == xmlXPathNINF)
return(1);
/*
* basic tests, the last one we should have equality, but
* portability is more important than speed and handling
* NaN or Inf in a portable way is always a challenge, so ...
*/
return(-1);
return(1);
return(0);
return(2);
}
/**
* xmlSchemaCompareValues:
* @x: a first value
* @xvalue: the first value as a string (optional)
* @xwtsp: the whitespace type
* @y: a second value
* @xvalue: the second value as a string (optional)
* @ywtsp: the whitespace type
*
* Compare 2 values
*
* Returns -1 if x < y, 0 if x == y, 1 if x > y, 2 if x <> y, 3 if not
* comparable and -2 in case of error
*/
static int
{
switch (xtype) {
case XML_SCHEMAS_UNKNOWN:
case XML_SCHEMAS_ANYTYPE:
return(-2);
case XML_SCHEMAS_INTEGER:
case XML_SCHEMAS_NPINTEGER:
case XML_SCHEMAS_NINTEGER:
case XML_SCHEMAS_NNINTEGER:
case XML_SCHEMAS_PINTEGER:
case XML_SCHEMAS_INT:
case XML_SCHEMAS_UINT:
case XML_SCHEMAS_LONG:
case XML_SCHEMAS_ULONG:
case XML_SCHEMAS_SHORT:
case XML_SCHEMAS_USHORT:
case XML_SCHEMAS_BYTE:
case XML_SCHEMAS_UBYTE:
case XML_SCHEMAS_DECIMAL:
return(-2);
return(xmlSchemaCompareDecimals(x, y));
if ((ytype == XML_SCHEMAS_DECIMAL) ||
(ytype == XML_SCHEMAS_INTEGER) ||
(ytype == XML_SCHEMAS_NPINTEGER) ||
(ytype == XML_SCHEMAS_NINTEGER) ||
(ytype == XML_SCHEMAS_NNINTEGER) ||
(ytype == XML_SCHEMAS_PINTEGER) ||
(ytype == XML_SCHEMAS_INT) ||
(ytype == XML_SCHEMAS_UINT) ||
(ytype == XML_SCHEMAS_LONG) ||
(ytype == XML_SCHEMAS_ULONG) ||
(ytype == XML_SCHEMAS_SHORT) ||
(ytype == XML_SCHEMAS_USHORT) ||
(ytype == XML_SCHEMAS_BYTE) ||
(ytype == XML_SCHEMAS_UBYTE))
return(xmlSchemaCompareDecimals(x, y));
return(-2);
case XML_SCHEMAS_DURATION:
return(-2);
if (ytype == XML_SCHEMAS_DURATION)
return(xmlSchemaCompareDurations(x, y));
return(-2);
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:
return(-2);
if ((ytype == XML_SCHEMAS_DATETIME) ||
(ytype == XML_SCHEMAS_TIME) ||
(ytype == XML_SCHEMAS_GDAY) ||
(ytype == XML_SCHEMAS_GMONTH) ||
(ytype == XML_SCHEMAS_GMONTHDAY) ||
(ytype == XML_SCHEMAS_GYEAR) ||
(ytype == XML_SCHEMAS_DATE) ||
(ytype == XML_SCHEMAS_GYEARMONTH))
return (xmlSchemaCompareDates(x, y));
return (-2);
/*
* Note that we will support comparison of string types against
* anySimpleType as well.
*/
case XML_SCHEMAS_STRING:
case XML_SCHEMAS_NORMSTRING:
case XML_SCHEMAS_TOKEN:
case XML_SCHEMAS_LANGUAGE:
case XML_SCHEMAS_NMTOKEN:
case XML_SCHEMAS_NAME:
case XML_SCHEMAS_NCNAME:
case XML_SCHEMAS_ID:
case XML_SCHEMAS_IDREF:
case XML_SCHEMAS_ENTITY:
case XML_SCHEMAS_ANYURI:
{
if (x == NULL)
else
if (y == NULL)
else
/*
* TODO: Compare those against QName.
*/
if (ytype == XML_SCHEMAS_QNAME) {
if (y == NULL)
return(-2);
return (-2);
}
if ((ytype == XML_SCHEMAS_ANYSIMPLETYPE) ||
(ytype == XML_SCHEMAS_STRING) ||
(ytype == XML_SCHEMAS_NORMSTRING) ||
(ytype == XML_SCHEMAS_TOKEN) ||
(ytype == XML_SCHEMAS_LANGUAGE) ||
(ytype == XML_SCHEMAS_NMTOKEN) ||
(ytype == XML_SCHEMAS_NAME) ||
(ytype == XML_SCHEMAS_NCNAME) ||
(ytype == XML_SCHEMAS_ID) ||
(ytype == XML_SCHEMAS_IDREF) ||
(ytype == XML_SCHEMAS_ENTITY) ||
(ytype == XML_SCHEMAS_ANYURI)) {
if (xws == XML_SCHEMA_WHITESPACE_PRESERVE) {
if (yws == XML_SCHEMA_WHITESPACE_PRESERVE) {
/* TODO: What about x < y or x > y. */
return (0);
else
return (2);
} else if (yws == XML_SCHEMA_WHITESPACE_REPLACE)
else if (yws == XML_SCHEMA_WHITESPACE_COLLAPSE)
} else if (xws == XML_SCHEMA_WHITESPACE_REPLACE) {
if (yws == XML_SCHEMA_WHITESPACE_PRESERVE)
if (yws == XML_SCHEMA_WHITESPACE_REPLACE)
if (yws == XML_SCHEMA_WHITESPACE_COLLAPSE)
} else if (xws == XML_SCHEMA_WHITESPACE_COLLAPSE) {
if (yws == XML_SCHEMA_WHITESPACE_PRESERVE)
if (yws == XML_SCHEMA_WHITESPACE_REPLACE)
if (yws == XML_SCHEMA_WHITESPACE_COLLAPSE)
} else
return (-2);
}
return (-2);
}
case XML_SCHEMAS_QNAME:
case XML_SCHEMAS_NOTATION:
return(-2);
if ((ytype == XML_SCHEMAS_QNAME) ||
(ytype == XML_SCHEMAS_NOTATION)) {
return(0);
return(2);
}
return (-2);
case XML_SCHEMAS_FLOAT:
case XML_SCHEMAS_DOUBLE:
return(-2);
if ((ytype == XML_SCHEMAS_FLOAT) ||
(ytype == XML_SCHEMAS_DOUBLE))
return (xmlSchemaCompareFloats(x, y));
return (-2);
case XML_SCHEMAS_BOOLEAN:
return(-2);
if (ytype == XML_SCHEMAS_BOOLEAN) {
return(0);
if (x->value.b == 0)
return(-1);
return(1);
}
return (-2);
case XML_SCHEMAS_HEXBINARY:
return(-2);
if (ytype == XML_SCHEMAS_HEXBINARY) {
if (ret > 0)
return(1);
else if (ret == 0)
return(0);
}
return(1);
return(-1);
}
return (-2);
case XML_SCHEMAS_BASE64BINARY:
return(-2);
if (ytype == XML_SCHEMAS_BASE64BINARY) {
if (ret > 0)
return(1);
else if (ret == 0)
return(0);
else
return(-1);
}
return(1);
else
return(-1);
}
return (-2);
case XML_SCHEMAS_IDREFS:
case XML_SCHEMAS_ENTITIES:
case XML_SCHEMAS_NMTOKENS:
break;
}
return -2;
}
/**
* xmlSchemaCompareValues:
* @x: a first value
* @y: a second value
*
* Compare 2 values
*
* Returns -1 if x < y, 0 if x == y, 1 if x > y, 2 if x <> y, and -2 in
* case of error
*/
int
return(-2);
if (x->type == XML_SCHEMAS_STRING)
else if (x->type == XML_SCHEMAS_NORMSTRING)
else
if (y->type == XML_SCHEMAS_STRING)
else if (x->type == XML_SCHEMAS_NORMSTRING)
else
}
/**
* xmlSchemaCompareValuesWhtsp:
* @x: a first value
* @xws: the whitespace value of x
* @y: a second value
* @yws: the whitespace value of y
*
* Compare 2 values
*
* Returns -1 if x < y, 0 if x == y, 1 if x > y, 2 if x <> y, and -2 in
* case of error
*/
int
{
return(-2);
}
/**
* xmlSchemaCompareValuesWhtspExt:
* @x: a first value
* @xws: the whitespace value of x
* @y: a second value
* @yws: the whitespace value of y
*
* Compare 2 values
*
* Returns -1 if x < y, 0 if x == y, 1 if x > y, 2 if x <> y, and -2 in
* case of error
*/
static int
{
}
/**
* xmlSchemaNormLen:
* @value: a string
*
* Computes the UTF8 length of the normalized value of the string
*
* Returns the length or -1 in case of error.
*/
static int
int ret = 0;
return(-1);
while (*utf != 0) {
if (utf[0] & 0x80) {
return(-1);
return(-1);
return(-1);
utf += 4;
} else {
utf += 3;
}
} else {
utf += 2;
}
} else if (IS_BLANK_CH(*utf)) {
if (*utf == 0)
break;
} else {
utf++;
}
ret++;
}
return(ret);
}
/**
* xmlSchemaGetFacetValueAsULong:
* @facet: an schemas type facet
*
* Extract the value of a facet
*
* Returns the value as a long
*/
unsigned long
{
/*
* TODO: Check if this is a decimal.
*/
return 0;
}
/**
* xmlSchemaValidateListSimpleTypeFacet:
* @facet: the facet to check
* @value: the lexical repr of the value to validate
* @actualLen: the number of list items
* @expectedLen: the resulting expected number of list items
*
* Checks the value of a list simple type against a facet.
*
* Returns 0 if the value is valid, a positive error code
* number otherwise and -1 in case of an internal error.
*/
int
unsigned long actualLen,
unsigned long *expectedLen)
{
return(-1);
/*
* TODO: Check if this will work with large numbers.
* (compare value.decimal.mi and value.decimal.hi as well?).
*/
if (expectedLen != NULL)
return (XML_SCHEMAV_CVC_LENGTH_VALID);
}
if (expectedLen != NULL)
return (XML_SCHEMAV_CVC_MINLENGTH_VALID);
}
if (expectedLen != NULL)
return (XML_SCHEMAV_CVC_MAXLENGTH_VALID);
}
} else
/*
* NOTE: That we can pass NULL as xmlSchemaValPtr to
* xmlSchemaValidateFacet, since the remaining facet types
* are: XML_SCHEMA_FACET_PATTERN, XML_SCHEMA_FACET_ENUMERATION.
*/
return (0);
}
/**
* xmlSchemaValidateLengthFacet:
* @type: the built-in type
* @facet: the facet to check
* @value: the lexical repr. of the value to be validated
* @val: the precomputed value
* @ws: the whitespace type of the value
* @length: the actual length of the value
*
* Checka a value against a "length", "minLength" and "maxLength"
* facet; sets @length to the computed length of @value.
*
* Returns 0 if the value is valid, a positive error code
* otherwise and -1 in case of an internal or API error.
*/
static int
unsigned long *length,
{
unsigned int len = 0;
return (-1);
*length = 0;
return (-1);
/*
* TODO: length, maxLength and minLength must be of type
* nonNegativeInteger only. Check if decimal is used somehow.
*/
return(-1);
}
else {
switch (valType) {
case XML_SCHEMAS_STRING:
case XML_SCHEMAS_NORMSTRING:
if (ws == XML_SCHEMA_WHITESPACE_UNKNOWN) {
/*
* This is to ensure API compatibility with the old
* xmlSchemaValidateLengthFacet(). Anyway, this was and
* is not the correct handling.
* TODO: Get rid of this case somehow.
*/
if (valType == XML_SCHEMAS_STRING)
else
if (ws == XML_SCHEMA_WHITESPACE_COLLAPSE)
else
/*
* Should be OK for "preserve" as well.
*/
}
break;
case XML_SCHEMAS_IDREF:
case XML_SCHEMAS_TOKEN:
case XML_SCHEMAS_LANGUAGE:
case XML_SCHEMAS_NMTOKEN:
case XML_SCHEMAS_NAME:
case XML_SCHEMAS_NCNAME:
case XML_SCHEMAS_ID:
/*
* FIXME: What exactly to do with anyURI?
*/
case XML_SCHEMAS_ANYURI:
break;
case XML_SCHEMAS_QNAME:
case XML_SCHEMAS_NOTATION:
/*
* For QName and NOTATION, those facets are
* deprecated and should be ignored.
*/
return (0);
default:
}
}
/*
* TODO: Return the whole expected value, i.e. "lo", "mi" and "hi".
*/
return(XML_SCHEMAV_CVC_LENGTH_VALID);
return(XML_SCHEMAV_CVC_MINLENGTH_VALID);
} else {
return(XML_SCHEMAV_CVC_MAXLENGTH_VALID);
}
return (0);
}
/**
* xmlSchemaValidateLengthFacet:
* @type: the built-in type
* @facet: the facet to check
* @value: the lexical repr. of the value to be validated
* @val: the precomputed value
* @length: the actual length of the value
*
* Checka a value against a "length", "minLength" and "maxLength"
* facet; sets @length to the computed length of @value.
*
* Returns 0 if the value is valid, a positive error code
* otherwise and -1 in case of an internal or API error.
*/
int
unsigned long *length)
{
return(-1);
}
/**
* xmlSchemaValidateLengthFacetWhtsp:
* @facet: the facet to check
* @valType: the built-in type
* @value: the lexical repr. of the value to be validated
* @val: the precomputed value
* @ws: the whitespace type of the value
* @length: the actual length of the value
*
* Checka a value against a "length", "minLength" and "maxLength"
* facet; sets @length to the computed length of @value.
*
* Returns 0 if the value is valid, a positive error code
* otherwise and -1 in case of an internal or API error.
*/
int
unsigned long *length,
{
}
/**
* xmlSchemaValidateFacetInternal:
* @facet: the facet to check
* @fws: the whitespace type of the facet's value
* @valType: the built-in type of the value
* @value: the lexical repr of the value to validate
* @val: the precomputed value
* @ws: the whitespace type of the value
*
* Check a value against a facet condition
*
* Returns 0 if the element is schemas valid, a positive error code
* number otherwise and -1 in case of internal or API error.
*/
static int
{
int ret;
return(-1);
case XML_SCHEMA_FACET_PATTERN:
/*
* NOTE that for patterns, the @value needs to be the normalized
* value, *not* the lexical initial value or the canonical value.
*/
return(-1);
if (ret == 1)
return(0);
if (ret == 0)
return(XML_SCHEMAV_CVC_PATTERN_VALID);
return(ret);
if (ret == -2)
return(-1);
if (ret == -1)
return(0);
return(XML_SCHEMAV_CVC_MAXEXCLUSIVE_VALID);
if (ret == -2)
return(-1);
return(0);
return(XML_SCHEMAV_CVC_MAXINCLUSIVE_VALID);
if (ret == -2)
return(-1);
if (ret == 1)
return(0);
return(XML_SCHEMAV_CVC_MINEXCLUSIVE_VALID);
if (ret == -2)
return(-1);
return(0);
return(XML_SCHEMAV_CVC_MININCLUSIVE_VALID);
/* TODO whitespaces */
/*
* NOTE: Whitespace should be handled to normalize
* the value to be validated against a the facets;
* not to normalize the value in-between.
*/
return(0);
if (ws == XML_SCHEMA_WHITESPACE_UNKNOWN) {
/*
* This is to ensure API compatibility with the old
* xmlSchemaValidateFacet().
* TODO: Get rid of this case.
*/
return(0);
} else {
if (ret == -2)
return(-1);
if (ret == 0)
return(0);
}
return(XML_SCHEMAV_CVC_ENUMERATION_VALID);
case XML_SCHEMA_FACET_LENGTH:
/*
* SPEC (1.3) "if {primitive type definition} is QName or NOTATION,
* then any {value} is facet-valid."
*/
if ((valType == XML_SCHEMAS_QNAME) ||
(valType == XML_SCHEMAS_NOTATION))
return (0);
/* No break on purpose. */
case XML_SCHEMA_FACET_MINLENGTH: {
unsigned int len = 0;
if ((valType == XML_SCHEMAS_QNAME) ||
(valType == XML_SCHEMAS_NOTATION))
return (0);
/*
* TODO: length, maxLength and minLength must be of type
* nonNegativeInteger only. Check if decimal is used somehow.
*/
return(-1);
}
else {
switch (valType) {
case XML_SCHEMAS_STRING:
case XML_SCHEMAS_NORMSTRING:
if (ws == XML_SCHEMA_WHITESPACE_UNKNOWN) {
/*
* This is to ensure API compatibility with the old
* xmlSchemaValidateFacet(). Anyway, this was and
* is not the correct handling.
* TODO: Get rid of this case somehow.
*/
if (valType == XML_SCHEMAS_STRING)
else
if (ws == XML_SCHEMA_WHITESPACE_COLLAPSE)
else
/*
* Should be OK for "preserve" as well.
*/
}
break;
case XML_SCHEMAS_IDREF:
case XML_SCHEMAS_TOKEN:
case XML_SCHEMAS_LANGUAGE:
case XML_SCHEMAS_NMTOKEN:
case XML_SCHEMAS_NAME:
case XML_SCHEMAS_NCNAME:
case XML_SCHEMAS_ID:
case XML_SCHEMAS_ANYURI:
break;
default:
}
}
return(XML_SCHEMAV_CVC_LENGTH_VALID);
return(XML_SCHEMAV_CVC_MINLENGTH_VALID);
} else {
return(XML_SCHEMAV_CVC_MAXLENGTH_VALID);
}
break;
}
return(-1);
}
return(-1);
}
return(XML_SCHEMAV_CVC_TOTALDIGITS_VALID);
return(XML_SCHEMAV_CVC_FRACTIONDIGITS_VALID);
}
break;
default:
}
return(0);
}
/**
* xmlSchemaValidateFacet:
* @base: the base type
* @facet: the facet to check
* @value: the lexical repr of the value to validate
* @val: the precomputed value
*
* Check a value against a facet condition
*
* Returns 0 if the element is schemas valid, a positive error code
* number otherwise and -1 in case of internal or API error.
*/
int
{
/*
* This tries to ensure API compatibility regarding the old
* xmlSchemaValidateFacet() and the new xmlSchemaValidateFacetInternal() and
* xmlSchemaValidateFacetWhtsp().
*/
return(xmlSchemaValidateFacetInternal(facet,
return(xmlSchemaValidateFacetInternal(facet,
return(-1);
}
/**
* xmlSchemaValidateFacetWhtsp:
* @facet: the facet to check
* @fws: the whitespace type of the facet's value
* @valType: the built-in type of the value
* @value: the lexical (or normalized for pattern) repr of the value to validate
* @val: the precomputed value
* @ws: the whitespace type of the value
*
* Check a value against a facet condition. This takes value normalization
* according to the specified whitespace types into account.
* Note that @value needs to be the *normalized* value if the facet
* is of type "pattern".
*
* Returns 0 if the element is schemas valid, a positive error code
* number otherwise and -1 in case of internal or API error.
*/
int
{
}
#if 0
#ifndef DBL_DIG
#define DBL_DIG 16
#endif
#ifndef DBL_EPSILON
#define DBL_EPSILON 1E-9
#endif
#define INTEGER_DIGITS DBL_DIG
/**
* xmlXPathFormatNumber:
* @number: number to format
* @buffer: output buffer
* @buffersize: size of output buffer
*
* Convert the number into a string representation.
*/
static void
{
switch (xmlXPathIsInf(number)) {
case 1:
if (buffersize > (int)sizeof("INF"))
break;
case -1:
if (buffersize > (int)sizeof("-INF"))
break;
default:
if (xmlXPathIsNaN(number)) {
if (buffersize > (int)sizeof("NaN"))
} else if (number == 0) {
} else {
/* 3 is sign, decimal point, and terminating zero */
int integer_place, fraction_place;
char *ptr;
char *after_fraction;
double absolute_value;
int size;
/*
* Result is in work, and after_fraction points
* just past the fractional part.
* Use scientific notation
*/
/* Remove fractional trailing zeroes */
while (*(--ptr) == '0')
;
if (*ptr != '.')
ptr++;
while ((*ptr++ = *after_fraction++) != 0);
/* Finally copy result back to caller */
if (size > buffersize) {
size = buffersize;
}
}
break;
}
}
#endif
/**
* xmlSchemaGetCanonValue:
* @val: the precomputed value
* @retValue: the returned value
*
* Get a the cononical lexical representation of the value.
* The caller has to FREE the returned retValue.
*
* WARNING: Some value types are not supported yet, resulting
* in a @retValue of "???".
*
* TODO: XML Schema 1.0 does not define canonical representations
* for: duration, gYearMonth, gYear, gMonthDay, gMonth, gDay,
* anyURI, QName, NOTATION. This will be fixed in XML Schema 1.1.
*
*
* Returns 0 if the value could be built, 1 if the value type is
* not supported yet and -1 in case of API errors.
*/
int
{
return (-1);
case XML_SCHEMAS_STRING:
else
*retValue =
break;
case XML_SCHEMAS_NORMSTRING:
else {
}
break;
case XML_SCHEMAS_TOKEN:
case XML_SCHEMAS_LANGUAGE:
case XML_SCHEMAS_NMTOKEN:
case XML_SCHEMAS_NAME:
case XML_SCHEMAS_NCNAME:
case XML_SCHEMAS_ID:
case XML_SCHEMAS_IDREF:
case XML_SCHEMAS_ENTITY:
case XML_SCHEMAS_NOTATION: /* Unclear */
case XML_SCHEMAS_ANYURI: /* Unclear */
return (-1);
*retValue =
*retValue =
break;
case XML_SCHEMAS_QNAME:
/* TODO: Unclear in XML Schema 1.0. */
return (0);
} else {
BAD_CAST "}");
}
break;
case XML_SCHEMAS_DECIMAL:
/*
* TODO: Lookout for a more simple implementation.
*/
} else {
int bufsize;
/* Add room for the decimal point as well. */
bufsize++;
bufsize++;
return(-1);
*offs++ = '-';
*offs++ = '0';
*offs++ = '.';
}
else
/*
* Insert the decimal point.
*/
} else {
unsigned int i = 0;
/*
* Insert missing zeroes behind the decimal point.
*/
while (*(offs + i) != 0)
i++;
}
}
} else {
/*
* Append decimal point and zero.
*/
*offs-- = 0;
*offs-- = '0';
*offs-- = '.';
}
}
break;
case XML_SCHEMAS_INTEGER:
case XML_SCHEMAS_PINTEGER:
case XML_SCHEMAS_NPINTEGER:
case XML_SCHEMAS_NINTEGER:
case XML_SCHEMAS_NNINTEGER:
case XML_SCHEMAS_LONG:
case XML_SCHEMAS_BYTE:
case XML_SCHEMAS_SHORT:
case XML_SCHEMAS_INT:
case XML_SCHEMAS_UINT:
case XML_SCHEMAS_ULONG:
case XML_SCHEMAS_USHORT:
case XML_SCHEMAS_UBYTE:
else {
/* Add room for the decimal point as well. */
bufsize++;
return(-1);
else
else
} else {
else
}
}
break;
case XML_SCHEMAS_BOOLEAN:
else
break;
case XML_SCHEMAS_DURATION: {
char buf[100];
unsigned long year;
/* TODO: Unclear in XML Schema 1.0 */
/*
* TODO: This results in a normalized output of the value
* - which is NOT conformant to the spec -
* since the exact values of each property are not
* recoverable. Think about extending the structure to
* provide a field for every property.
*/
if (left > 0) {
if (left > 0) {
}
}
else
}
break;
case XML_SCHEMAS_GYEAR: {
char buf[30];
/* TODO: Unclear in XML Schema 1.0 */
/* TODO: What to do with the timezone? */
}
break;
case XML_SCHEMAS_GMONTH: {
/* TODO: Unclear in XML Schema 1.0 */
/* TODO: What to do with the timezone? */
return(-1);
}
break;
case XML_SCHEMAS_GDAY: {
/* TODO: Unclear in XML Schema 1.0 */
/* TODO: What to do with the timezone? */
return(-1);
}
break;
case XML_SCHEMAS_GMONTHDAY: {
/* TODO: Unclear in XML Schema 1.0 */
/* TODO: What to do with the timezone? */
return(-1);
}
break;
case XML_SCHEMAS_GYEARMONTH: {
char buf[35];
/* TODO: Unclear in XML Schema 1.0 */
/* TODO: What to do with the timezone? */
else
}
break;
case XML_SCHEMAS_TIME:
{
char buf[30];
return (-1);
/*
* TODO: Check if "%.14g" is portable.
*/
"%02u:%02u:%02.14gZ",
} else {
"%02u:%02u:%02.14g",
}
}
break;
case XML_SCHEMAS_DATE:
{
char buf[30];
return (-1);
/*
* TODO: Append the canonical value of the
* recoverable timezone and not "Z".
*/
"%04ld:%02u:%02uZ",
} else {
"%04ld:%02u:%02u",
}
}
break;
case XML_SCHEMAS_DATETIME:
{
char buf[50];
return (-1);
/*
* TODO: Check if "%.14g" is portable.
*/
"%04ld:%02u:%02uT%02u:%02u:%02.14gZ",
} else {
"%04ld:%02u:%02uT%02u:%02u:%02.14g",
}
}
break;
case XML_SCHEMAS_HEXBINARY:
break;
case XML_SCHEMAS_BASE64BINARY:
/*
* TODO: Is the following spec piece implemented?:
* SPEC: "Note: For some values the canonical form defined
* above does not conform to [RFC 2045], which requires breaking
* with linefeeds at appropriate intervals."
*/
break;
case XML_SCHEMAS_FLOAT: {
char buf[30];
/*
* |m| < 16777216, -149 <= e <= 104.
* TODO: Handle, NaN, INF, -INF. The format is not
* yet conformant. The c type float does not cover
* the whole range.
*/
}
break;
case XML_SCHEMAS_DOUBLE: {
char buf[40];
/* |m| < 9007199254740992, -1075 <= e <= 970 */
/*
* TODO: Handle, NaN, INF, -INF. The format is not
* yet conformant. The c type float does not cover
* the whole range.
*/
}
break;
default:
return (1);
}
return(-1);
return (0);
}
/**
* xmlSchemaGetCanonValueWhtsp:
* @val: the precomputed value
* @retValue: the returned value
* @ws: the whitespace type of the value
*
* Get a the cononical representation of the value.
* The caller has to free the returned @retValue.
*
* Returns 0 if the value could be built, 1 if the value type is
* not supported yet and -1 in case of API errors.
*/
int
{
return (-1);
if ((ws == XML_SCHEMA_WHITESPACE_UNKNOWN) ||
return (-1);
case XML_SCHEMAS_STRING:
else if (ws == XML_SCHEMA_WHITESPACE_COLLAPSE)
else if (ws == XML_SCHEMA_WHITESPACE_REPLACE)
break;
case XML_SCHEMAS_NORMSTRING:
else {
if (ws == XML_SCHEMA_WHITESPACE_COLLAPSE)
else
}
break;
default:
}
return (0);
}
/**
* xmlSchemaGetValType:
* @val: a schemas value
*
* Accessor for the type of a value
*
* Returns the xmlSchemaValType of the value
*/
{
return(XML_SCHEMAS_UNKNOWN);
}
#define bottom_xmlschemastypes
#include "elfgcchack.h"
#endif /* LIBXML_SCHEMAS_ENABLED */