From f338529585ff7a9a7c9d494b82af23fa9b9da45f Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 18 Nov 2012 00:20:27 +0100 Subject: [PATCH] (libxml2) LIBXML_VALID_ENABLED removed --- android/native/libxml2/SAX2.c | 165 - android/native/libxml2/elfgcchack.h | 324 -- android/native/libxml2/libxml/parser.h | 13 - android/native/libxml2/libxml/valid.h | 101 - android/native/libxml2/libxml/xmlversion.h | 9 - android/native/libxml2/parser.c | 314 -- android/native/libxml2/valid.c | 3947 -------------------- android/native/libxml2/xmllint.c | 203 - 8 files changed, 5076 deletions(-) diff --git a/android/native/libxml2/SAX2.c b/android/native/libxml2/SAX2.c index 671d36361b..d9264b6ee8 100644 --- a/android/native/libxml2/SAX2.c +++ b/android/native/libxml2/SAX2.c @@ -744,14 +744,6 @@ xmlSAX2AttributeDecl(void *ctx, const xmlChar *elem, const xmlChar *fullname, xmlFreeEnumeration(tree); return; } -#ifdef LIBXML_VALID_ENABLED - if (ctxt->vctxt.valid == 0) - ctxt->valid = 0; - if ((attr != NULL) && (ctxt->validate) && (ctxt->wellFormed) && - (ctxt->myDoc->intSubset != NULL)) - ctxt->valid &= xmlValidateAttributeDecl(&ctxt->vctxt, ctxt->myDoc, - attr); -#endif /* LIBXML_VALID_ENABLED */ if (prefix != NULL) xmlFree(prefix); if (name != NULL) @@ -794,14 +786,6 @@ xmlSAX2ElementDecl(void *ctx, const xmlChar * name, int type, name, NULL); return; } -#ifdef LIBXML_VALID_ENABLED - if (elem == NULL) - ctxt->valid = 0; - if (ctxt->validate && ctxt->wellFormed && - ctxt->myDoc && ctxt->myDoc->intSubset) - ctxt->valid &= - xmlValidateElementDecl(&ctxt->vctxt, ctxt->myDoc, elem); -#endif /* LIBXML_VALID_ENABLED */ } /** @@ -845,13 +829,6 @@ xmlSAX2NotationDecl(void *ctx, const xmlChar *name, name, NULL); return; } -#ifdef LIBXML_VALID_ENABLED - if (nota == NULL) ctxt->valid = 0; - if ((ctxt->validate) && (ctxt->wellFormed) && - (ctxt->myDoc->intSubset != NULL)) - ctxt->valid &= xmlValidateNotationDecl(&ctxt->vctxt, ctxt->myDoc, - nota); -#endif /* LIBXML_VALID_ENABLED */ } /** @@ -1011,11 +988,6 @@ xmlSAX2EndDocument(void *ctx) "SAX.xmlSAX2EndDocument()\n"); #endif if (ctx == NULL) return; -#ifdef LIBXML_VALID_ENABLED - if (ctxt->validate && ctxt->wellFormed && - ctxt->myDoc && ctxt->myDoc->intSubset) - ctxt->valid &= xmlValidateDocumentFinal(&ctxt->vctxt, ctxt->myDoc); -#endif /* LIBXML_VALID_ENABLED */ /* * Grab the encoding if it was added on-the-fly @@ -1116,37 +1088,6 @@ skip: return(ret); } -#ifdef LIBXML_VALID_ENABLED -/* - * xmlSAX2DecodeAttrEntities: - * @ctxt: the parser context - * @str: the input string - * @len: the string length - * - * Remove the entities from an attribute value - * - * Returns the newly allocated string or NULL if not needed or error - */ -static xmlChar * -xmlSAX2DecodeAttrEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, - const xmlChar *end) { - const xmlChar *in; - xmlChar *ret; - - in = str; - while (in < end) - if (*in++ == '&') - goto decode; - return(NULL); -decode: - ctxt->depth++; - ret = xmlStringLenDecodeEntities(ctxt, str, end - str, - XML_SUBSTITUTE_REF, 0,0,0); - ctxt->depth--; - return(ret); -} -#endif /* LIBXML_VALID_ENABLED */ - /** * xmlSAX2AttributeNs: * @ctx: the user data (XML parser context) @@ -1262,76 +1203,6 @@ xmlSAX2AttributeNs(xmlParserCtxtPtr ctxt, } } -#ifdef LIBXML_VALID_ENABLED - if ((!ctxt->html) && ctxt->validate && ctxt->wellFormed && - ctxt->myDoc && ctxt->myDoc->intSubset) { - /* - * If we don't substitute entities, the validation should be - * done on a value with replaced entities anyway. - */ - if (!ctxt->replaceEntities) { - dup = xmlSAX2DecodeAttrEntities(ctxt, value, valueend); - if (dup == NULL) { - if (*valueend == 0) { - ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt, - ctxt->myDoc, ctxt->node, ret, value); - } else { - /* - * That should already be normalized. - * cheaper to finally allocate here than duplicate - * entry points in the full validation code - */ - dup = xmlStrndup(value, valueend - value); - - ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt, - ctxt->myDoc, ctxt->node, ret, dup); - } - } else { - /* - * dup now contains a string of the flattened attribute - * content with entities substitued. Check if we need to - * apply an extra layer of normalization. - * It need to be done twice ... it's an extra burden related - * to the ability to keep references in attributes - */ - if (ctxt->attsSpecial != NULL) { - xmlChar *nvalnorm; - xmlChar fn[50]; - xmlChar *fullname; - - fullname = xmlBuildQName(localname, prefix, fn, 50); - if (fullname != NULL) { - ctxt->vctxt.valid = 1; - nvalnorm = xmlValidCtxtNormalizeAttributeValue( - &ctxt->vctxt, ctxt->myDoc, - ctxt->node, fullname, dup); - if (ctxt->vctxt.valid != 1) - ctxt->valid = 0; - - if ((fullname != fn) && (fullname != localname)) - xmlFree(fullname); - if (nvalnorm != NULL) { - xmlFree(dup); - dup = nvalnorm; - } - } - } - - ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt, - ctxt->myDoc, ctxt->node, ret, dup); - } - } else { - /* - * if entities already have been substitued, then - * the attribute as passed is already normalized - */ - dup = xmlStrndup(value, valueend - value); - - ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt, - ctxt->myDoc, ctxt->node, ret, dup); - } - } else -#endif /* LIBXML_VALID_ENABLED */ if (((ctxt->loadsubset & XML_SKIP_IDS) == 0) && (((ctxt->replaceEntities == 0) && (ctxt->external != 2)) || ((ctxt->replaceEntities != 0) && (ctxt->inSubset == 0)))) { @@ -1349,13 +1220,6 @@ xmlSAX2AttributeNs(xmlParserCtxtPtr ctxt, */ if (dup == NULL) dup = xmlStrndup(value, valueend - value); -#ifdef LIBXML_VALID_ENABLED - if (xmlValidateNCName(dup, 1) != 0) { - xmlErrValid(ctxt, XML_DTD_XMLID_VALUE, - "xml:id : attribute value %s is not an NCName\n", - (const char *) dup, NULL); - } -#endif xmlAddID(&ctxt->vctxt, ctxt->myDoc, dup, ret); } else if (xmlIsID(ctxt->myDoc, ctxt->node, ret)) { /* might be worth duplicate entry points and not copy */ @@ -1512,13 +1376,6 @@ xmlSAX2StartElementNs(void *ctx, */ continue; } -#ifdef LIBXML_VALID_ENABLED - if ((!ctxt->html) && ctxt->validate && ctxt->wellFormed && - ctxt->myDoc && ctxt->myDoc->intSubset) { - ctxt->valid &= xmlValidateOneNamespace(&ctxt->vctxt, ctxt->myDoc, - ret, prefix, ns, uri); - } -#endif /* LIBXML_VALID_ENABLED */ } ctxt->nodemem = -1; @@ -1607,23 +1464,6 @@ xmlSAX2StartElementNs(void *ctx, } } -#ifdef LIBXML_VALID_ENABLED - /* - * If it's the Document root, finish the DTD validation and - * check the document root element for validity - */ - if ((ctxt->validate) && (ctxt->vctxt.finishDtd == XML_CTXT_FINISH_DTD_0)) { - int chk; - - chk = xmlValidateDtdFinal(&ctxt->vctxt, ctxt->myDoc); - if (chk <= 0) - ctxt->valid = 0; - if (chk < 0) - ctxt->wellFormed = 0; - ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc); - ctxt->vctxt.finishDtd = XML_CTXT_FINISH_DTD_1; - } -#endif /* LIBXML_VALID_ENABLED */ } /** @@ -1657,11 +1497,6 @@ xmlSAX2EndElementNs(void *ctx, } ctxt->nodemem = -1; -#ifdef LIBXML_VALID_ENABLED - if (ctxt->validate && ctxt->wellFormed && - ctxt->myDoc && ctxt->myDoc->intSubset) - ctxt->valid &= xmlValidateOneElement(&ctxt->vctxt, ctxt->myDoc, cur); -#endif /* LIBXML_VALID_ENABLED */ /* * end of parsing of this node. diff --git a/android/native/libxml2/elfgcchack.h b/android/native/libxml2/elfgcchack.h index c5a0cf4269..c9b7c3f5f0 100644 --- a/android/native/libxml2/elfgcchack.h +++ b/android/native/libxml2/elfgcchack.h @@ -1743,18 +1743,6 @@ extern __typeof (xmlFreeURI) xmlFreeURI__internal_alias __attribute((visibility( #endif #endif -#if defined(LIBXML_VALID_ENABLED) -#ifdef bottom_valid -#undef xmlFreeValidCtxt -extern __typeof (xmlFreeValidCtxt) xmlFreeValidCtxt __attribute((alias("xmlFreeValidCtxt__internal_alias"))); -#else -#ifndef xmlFreeValidCtxt -extern __typeof (xmlFreeValidCtxt) xmlFreeValidCtxt__internal_alias __attribute((visibility("hidden"))); -#define xmlFreeValidCtxt xmlFreeValidCtxt__internal_alias -#endif -#endif -#endif - #ifdef bottom_xmlmemory #undef xmlGcMemGet extern __typeof (xmlGcMemGet) xmlGcMemGet __attribute((alias("xmlGcMemGet__internal_alias"))); @@ -2349,18 +2337,6 @@ extern __typeof (xmlHashUpdateEntry3) xmlHashUpdateEntry3__internal_alias __attr #endif #endif -#if defined(LIBXML_VALID_ENABLED) -#ifdef bottom_parser -#undef xmlIOParseDTD -extern __typeof (xmlIOParseDTD) xmlIOParseDTD __attribute((alias("xmlIOParseDTD__internal_alias"))); -#else -#ifndef xmlIOParseDTD -extern __typeof (xmlIOParseDTD) xmlIOParseDTD__internal_alias __attribute((visibility("hidden"))); -#define xmlIOParseDTD xmlIOParseDTD__internal_alias -#endif -#endif -#endif - #ifdef bottom_encoding #undef xmlInitCharEncodingHandlers extern __typeof (xmlInitCharEncodingHandlers) xmlInitCharEncodingHandlers __attribute((alias("xmlInitCharEncodingHandlers__internal_alias"))); @@ -3488,18 +3464,6 @@ extern __typeof (xmlNewTextReaderFilename) xmlNewTextReaderFilename__internal_al #endif #endif -#if defined(LIBXML_VALID_ENABLED) -#ifdef bottom_valid -#undef xmlNewValidCtxt -extern __typeof (xmlNewValidCtxt) xmlNewValidCtxt __attribute((alias("xmlNewValidCtxt__internal_alias"))); -#else -#ifndef xmlNewValidCtxt -extern __typeof (xmlNewValidCtxt) xmlNewValidCtxt__internal_alias __attribute((visibility("hidden"))); -#define xmlNewValidCtxt xmlNewValidCtxt__internal_alias -#endif -#endif -#endif - #ifdef bottom_parserInternals #undef xmlNextChar extern __typeof (xmlNextChar) xmlNextChar __attribute((alias("xmlNextChar__internal_alias"))); @@ -3847,18 +3811,6 @@ extern __typeof (xmlParseCtxtExternalEntity) xmlParseCtxtExternalEntity__interna #endif #endif -#if defined(LIBXML_VALID_ENABLED) -#ifdef bottom_parser -#undef xmlParseDTD -extern __typeof (xmlParseDTD) xmlParseDTD __attribute((alias("xmlParseDTD__internal_alias"))); -#else -#ifndef xmlParseDTD -extern __typeof (xmlParseDTD) xmlParseDTD__internal_alias __attribute((visibility("hidden"))); -#define xmlParseDTD xmlParseDTD__internal_alias -#endif -#endif -#endif - #ifdef bottom_parser #undef xmlParseDefaultDecl extern __typeof (xmlParseDefaultDecl) xmlParseDefaultDecl __attribute((alias("xmlParseDefaultDecl__internal_alias"))); @@ -5189,18 +5141,6 @@ extern __typeof (xmlSAX2UnparsedEntityDecl) xmlSAX2UnparsedEntityDecl__internal_ #endif #endif -#if defined(LIBXML_VALID_ENABLED) -#ifdef bottom_parser -#undef xmlSAXParseDTD -extern __typeof (xmlSAXParseDTD) xmlSAXParseDTD __attribute((alias("xmlSAXParseDTD__internal_alias"))); -#else -#ifndef xmlSAXParseDTD -extern __typeof (xmlSAXParseDTD) xmlSAXParseDTD__internal_alias __attribute((visibility("hidden"))); -#define xmlSAXParseDTD xmlSAXParseDTD__internal_alias -#endif -#endif -#endif - #ifdef bottom_SAX2 #undef xmlSAXVersion extern __typeof (xmlSAXVersion) xmlSAXVersion __attribute((alias("xmlSAXVersion__internal_alias"))); @@ -6794,150 +6734,6 @@ extern __typeof (xmlUnsetProp) xmlUnsetProp__internal_alias __attribute((visibil #endif #endif -#if defined(LIBXML_VALID_ENABLED) -#ifdef bottom_valid -#undef xmlValidCtxtNormalizeAttributeValue -extern __typeof (xmlValidCtxtNormalizeAttributeValue) xmlValidCtxtNormalizeAttributeValue __attribute((alias("xmlValidCtxtNormalizeAttributeValue__internal_alias"))); -#else -#ifndef xmlValidCtxtNormalizeAttributeValue -extern __typeof (xmlValidCtxtNormalizeAttributeValue) xmlValidCtxtNormalizeAttributeValue__internal_alias __attribute((visibility("hidden"))); -#define xmlValidCtxtNormalizeAttributeValue xmlValidCtxtNormalizeAttributeValue__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_VALID_ENABLED) -#ifdef bottom_valid -#undef xmlValidGetPotentialChildren -extern __typeof (xmlValidGetPotentialChildren) xmlValidGetPotentialChildren __attribute((alias("xmlValidGetPotentialChildren__internal_alias"))); -#else -#ifndef xmlValidGetPotentialChildren -extern __typeof (xmlValidGetPotentialChildren) xmlValidGetPotentialChildren__internal_alias __attribute((visibility("hidden"))); -#define xmlValidGetPotentialChildren xmlValidGetPotentialChildren__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_VALID_ENABLED) -#ifdef bottom_valid -#undef xmlValidGetValidElements -extern __typeof (xmlValidGetValidElements) xmlValidGetValidElements __attribute((alias("xmlValidGetValidElements__internal_alias"))); -#else -#ifndef xmlValidGetValidElements -extern __typeof (xmlValidGetValidElements) xmlValidGetValidElements__internal_alias __attribute((visibility("hidden"))); -#define xmlValidGetValidElements xmlValidGetValidElements__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_VALID_ENABLED) -#ifdef bottom_valid -#undef xmlValidNormalizeAttributeValue -extern __typeof (xmlValidNormalizeAttributeValue) xmlValidNormalizeAttributeValue __attribute((alias("xmlValidNormalizeAttributeValue__internal_alias"))); -#else -#ifndef xmlValidNormalizeAttributeValue -extern __typeof (xmlValidNormalizeAttributeValue) xmlValidNormalizeAttributeValue__internal_alias __attribute((visibility("hidden"))); -#define xmlValidNormalizeAttributeValue xmlValidNormalizeAttributeValue__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_VALID_ENABLED) -#ifdef bottom_valid -#undef xmlValidateAttributeDecl -extern __typeof (xmlValidateAttributeDecl) xmlValidateAttributeDecl __attribute((alias("xmlValidateAttributeDecl__internal_alias"))); -#else -#ifndef xmlValidateAttributeDecl -extern __typeof (xmlValidateAttributeDecl) xmlValidateAttributeDecl__internal_alias __attribute((visibility("hidden"))); -#define xmlValidateAttributeDecl xmlValidateAttributeDecl__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_VALID_ENABLED) -#ifdef bottom_valid -#undef xmlValidateAttributeValue -extern __typeof (xmlValidateAttributeValue) xmlValidateAttributeValue __attribute((alias("xmlValidateAttributeValue__internal_alias"))); -#else -#ifndef xmlValidateAttributeValue -extern __typeof (xmlValidateAttributeValue) xmlValidateAttributeValue__internal_alias __attribute((visibility("hidden"))); -#define xmlValidateAttributeValue xmlValidateAttributeValue__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_VALID_ENABLED) -#ifdef bottom_valid -#undef xmlValidateDocument -extern __typeof (xmlValidateDocument) xmlValidateDocument __attribute((alias("xmlValidateDocument__internal_alias"))); -#else -#ifndef xmlValidateDocument -extern __typeof (xmlValidateDocument) xmlValidateDocument__internal_alias __attribute((visibility("hidden"))); -#define xmlValidateDocument xmlValidateDocument__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_VALID_ENABLED) -#ifdef bottom_valid -#undef xmlValidateDocumentFinal -extern __typeof (xmlValidateDocumentFinal) xmlValidateDocumentFinal __attribute((alias("xmlValidateDocumentFinal__internal_alias"))); -#else -#ifndef xmlValidateDocumentFinal -extern __typeof (xmlValidateDocumentFinal) xmlValidateDocumentFinal__internal_alias __attribute((visibility("hidden"))); -#define xmlValidateDocumentFinal xmlValidateDocumentFinal__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_VALID_ENABLED) -#ifdef bottom_valid -#undef xmlValidateDtd -extern __typeof (xmlValidateDtd) xmlValidateDtd __attribute((alias("xmlValidateDtd__internal_alias"))); -#else -#ifndef xmlValidateDtd -extern __typeof (xmlValidateDtd) xmlValidateDtd__internal_alias __attribute((visibility("hidden"))); -#define xmlValidateDtd xmlValidateDtd__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_VALID_ENABLED) -#ifdef bottom_valid -#undef xmlValidateDtdFinal -extern __typeof (xmlValidateDtdFinal) xmlValidateDtdFinal __attribute((alias("xmlValidateDtdFinal__internal_alias"))); -#else -#ifndef xmlValidateDtdFinal -extern __typeof (xmlValidateDtdFinal) xmlValidateDtdFinal__internal_alias __attribute((visibility("hidden"))); -#define xmlValidateDtdFinal xmlValidateDtdFinal__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_VALID_ENABLED) -#ifdef bottom_valid -#undef xmlValidateElement -extern __typeof (xmlValidateElement) xmlValidateElement __attribute((alias("xmlValidateElement__internal_alias"))); -#else -#ifndef xmlValidateElement -extern __typeof (xmlValidateElement) xmlValidateElement__internal_alias __attribute((visibility("hidden"))); -#define xmlValidateElement xmlValidateElement__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_VALID_ENABLED) -#ifdef bottom_valid -#undef xmlValidateElementDecl -extern __typeof (xmlValidateElementDecl) xmlValidateElementDecl __attribute((alias("xmlValidateElementDecl__internal_alias"))); -#else -#ifndef xmlValidateElementDecl -extern __typeof (xmlValidateElementDecl) xmlValidateElementDecl__internal_alias __attribute((visibility("hidden"))); -#define xmlValidateElementDecl xmlValidateElementDecl__internal_alias -#endif -#endif -#endif - #if defined(LIBXML_TREE_ENABLED) #ifdef bottom_tree #undef xmlValidateNCName @@ -6974,114 +6770,6 @@ extern __typeof (xmlValidateName) xmlValidateName__internal_alias __attribute((v #endif #endif -#if defined(LIBXML_VALID_ENABLED) -#ifdef bottom_valid -#undef xmlValidateNameValue -extern __typeof (xmlValidateNameValue) xmlValidateNameValue __attribute((alias("xmlValidateNameValue__internal_alias"))); -#else -#ifndef xmlValidateNameValue -extern __typeof (xmlValidateNameValue) xmlValidateNameValue__internal_alias __attribute((visibility("hidden"))); -#define xmlValidateNameValue xmlValidateNameValue__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_VALID_ENABLED) -#ifdef bottom_valid -#undef xmlValidateNamesValue -extern __typeof (xmlValidateNamesValue) xmlValidateNamesValue __attribute((alias("xmlValidateNamesValue__internal_alias"))); -#else -#ifndef xmlValidateNamesValue -extern __typeof (xmlValidateNamesValue) xmlValidateNamesValue__internal_alias __attribute((visibility("hidden"))); -#define xmlValidateNamesValue xmlValidateNamesValue__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_VALID_ENABLED) -#ifdef bottom_valid -#undef xmlValidateNmtokenValue -extern __typeof (xmlValidateNmtokenValue) xmlValidateNmtokenValue __attribute((alias("xmlValidateNmtokenValue__internal_alias"))); -#else -#ifndef xmlValidateNmtokenValue -extern __typeof (xmlValidateNmtokenValue) xmlValidateNmtokenValue__internal_alias __attribute((visibility("hidden"))); -#define xmlValidateNmtokenValue xmlValidateNmtokenValue__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_VALID_ENABLED) -#ifdef bottom_valid -#undef xmlValidateNmtokensValue -extern __typeof (xmlValidateNmtokensValue) xmlValidateNmtokensValue __attribute((alias("xmlValidateNmtokensValue__internal_alias"))); -#else -#ifndef xmlValidateNmtokensValue -extern __typeof (xmlValidateNmtokensValue) xmlValidateNmtokensValue__internal_alias __attribute((visibility("hidden"))); -#define xmlValidateNmtokensValue xmlValidateNmtokensValue__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_VALID_ENABLED) -#ifdef bottom_valid -#undef xmlValidateNotationDecl -extern __typeof (xmlValidateNotationDecl) xmlValidateNotationDecl __attribute((alias("xmlValidateNotationDecl__internal_alias"))); -#else -#ifndef xmlValidateNotationDecl -extern __typeof (xmlValidateNotationDecl) xmlValidateNotationDecl__internal_alias __attribute((visibility("hidden"))); -#define xmlValidateNotationDecl xmlValidateNotationDecl__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_VALID_ENABLED) -#ifdef bottom_valid -#undef xmlValidateNotationUse -extern __typeof (xmlValidateNotationUse) xmlValidateNotationUse __attribute((alias("xmlValidateNotationUse__internal_alias"))); -#else -#ifndef xmlValidateNotationUse -extern __typeof (xmlValidateNotationUse) xmlValidateNotationUse__internal_alias __attribute((visibility("hidden"))); -#define xmlValidateNotationUse xmlValidateNotationUse__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_VALID_ENABLED) -#ifdef bottom_valid -#undef xmlValidateOneAttribute -extern __typeof (xmlValidateOneAttribute) xmlValidateOneAttribute __attribute((alias("xmlValidateOneAttribute__internal_alias"))); -#else -#ifndef xmlValidateOneAttribute -extern __typeof (xmlValidateOneAttribute) xmlValidateOneAttribute__internal_alias __attribute((visibility("hidden"))); -#define xmlValidateOneAttribute xmlValidateOneAttribute__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_VALID_ENABLED) -#ifdef bottom_valid -#undef xmlValidateOneElement -extern __typeof (xmlValidateOneElement) xmlValidateOneElement __attribute((alias("xmlValidateOneElement__internal_alias"))); -#else -#ifndef xmlValidateOneElement -extern __typeof (xmlValidateOneElement) xmlValidateOneElement__internal_alias __attribute((visibility("hidden"))); -#define xmlValidateOneElement xmlValidateOneElement__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_VALID_ENABLED) -#ifdef bottom_valid -#undef xmlValidateOneNamespace -extern __typeof (xmlValidateOneNamespace) xmlValidateOneNamespace __attribute((alias("xmlValidateOneNamespace__internal_alias"))); -#else -#ifndef xmlValidateOneNamespace -extern __typeof (xmlValidateOneNamespace) xmlValidateOneNamespace__internal_alias __attribute((visibility("hidden"))); -#define xmlValidateOneNamespace xmlValidateOneNamespace__internal_alias -#endif -#endif -#endif - #if defined(LIBXML_TREE_ENABLED) #ifdef bottom_tree #undef xmlValidateQName @@ -7094,18 +6782,6 @@ extern __typeof (xmlValidateQName) xmlValidateQName__internal_alias __attribute( #endif #endif -#if defined(LIBXML_VALID_ENABLED) -#ifdef bottom_valid -#undef xmlValidateRoot -extern __typeof (xmlValidateRoot) xmlValidateRoot __attribute((alias("xmlValidateRoot__internal_alias"))); -#else -#ifndef xmlValidateRoot -extern __typeof (xmlValidateRoot) xmlValidateRoot__internal_alias __attribute((visibility("hidden"))); -#define xmlValidateRoot xmlValidateRoot__internal_alias -#endif -#endif -#endif - #endif #endif #endif diff --git a/android/native/libxml2/libxml/parser.h b/android/native/libxml2/libxml/parser.h index de3f9c33ac..df5266a59f 100644 --- a/android/native/libxml2/libxml/parser.h +++ b/android/native/libxml2/libxml/parser.h @@ -854,19 +854,6 @@ XMLPUBFUN int XMLCALL XMLPUBFUN int XMLCALL xmlParseExtParsedEnt (xmlParserCtxtPtr ctxt); -#ifdef LIBXML_VALID_ENABLED -XMLPUBFUN xmlDtdPtr XMLCALL - xmlSAXParseDTD (xmlSAXHandlerPtr sax, - const xmlChar *ExternalID, - const xmlChar *SystemID); -XMLPUBFUN xmlDtdPtr XMLCALL - xmlParseDTD (const xmlChar *ExternalID, - const xmlChar *SystemID); -XMLPUBFUN xmlDtdPtr XMLCALL - xmlIOParseDTD (xmlSAXHandlerPtr sax, - xmlParserInputBufferPtr input, - xmlCharEncoding enc); -#endif /* LIBXML_VALID_ENABLE */ XMLPUBFUN xmlParserErrors XMLCALL xmlParseInNodeContext (xmlNodePtr node, const char *data, diff --git a/android/native/libxml2/libxml/valid.h b/android/native/libxml2/libxml/valid.h index 5396edc8a9..c1437fcedb 100644 --- a/android/native/libxml2/libxml/valid.h +++ b/android/native/libxml2/libxml/valid.h @@ -268,84 +268,6 @@ XMLPUBFUN xmlListPtr XMLCALL /** * The public function calls related to validity checking. */ -#ifdef LIBXML_VALID_ENABLED -/* Allocate/Release Validation Contexts */ -XMLPUBFUN xmlValidCtxtPtr XMLCALL - xmlNewValidCtxt(void); -XMLPUBFUN void XMLCALL - xmlFreeValidCtxt(xmlValidCtxtPtr); - -XMLPUBFUN int XMLCALL - xmlValidateRoot (xmlValidCtxtPtr ctxt, - xmlDocPtr doc); -XMLPUBFUN int XMLCALL - xmlValidateElementDecl (xmlValidCtxtPtr ctxt, - xmlDocPtr doc, - xmlElementPtr elem); -XMLPUBFUN xmlChar * XMLCALL - xmlValidNormalizeAttributeValue(xmlDocPtr doc, - xmlNodePtr elem, - const xmlChar *name, - const xmlChar *value); -XMLPUBFUN xmlChar * XMLCALL - xmlValidCtxtNormalizeAttributeValue(xmlValidCtxtPtr ctxt, - xmlDocPtr doc, - xmlNodePtr elem, - const xmlChar *name, - const xmlChar *value); -XMLPUBFUN int XMLCALL - xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt, - xmlDocPtr doc, - xmlAttributePtr attr); -XMLPUBFUN int XMLCALL - xmlValidateAttributeValue(xmlAttributeType type, - const xmlChar *value); -XMLPUBFUN int XMLCALL - xmlValidateNotationDecl (xmlValidCtxtPtr ctxt, - xmlDocPtr doc, - xmlNotationPtr nota); -XMLPUBFUN int XMLCALL - xmlValidateDtd (xmlValidCtxtPtr ctxt, - xmlDocPtr doc, - xmlDtdPtr dtd); -XMLPUBFUN int XMLCALL - xmlValidateDtdFinal (xmlValidCtxtPtr ctxt, - xmlDocPtr doc); -XMLPUBFUN int XMLCALL - xmlValidateDocument (xmlValidCtxtPtr ctxt, - xmlDocPtr doc); -XMLPUBFUN int XMLCALL - xmlValidateElement (xmlValidCtxtPtr ctxt, - xmlDocPtr doc, - xmlNodePtr elem); -XMLPUBFUN int XMLCALL - xmlValidateOneElement (xmlValidCtxtPtr ctxt, - xmlDocPtr doc, - xmlNodePtr elem); -XMLPUBFUN int XMLCALL - xmlValidateOneAttribute (xmlValidCtxtPtr ctxt, - xmlDocPtr doc, - xmlNodePtr elem, - xmlAttrPtr attr, - const xmlChar *value); -XMLPUBFUN int XMLCALL - xmlValidateOneNamespace (xmlValidCtxtPtr ctxt, - xmlDocPtr doc, - xmlNodePtr elem, - const xmlChar *prefix, - xmlNsPtr ns, - const xmlChar *value); -XMLPUBFUN int XMLCALL - xmlValidateDocumentFinal(xmlValidCtxtPtr ctxt, - xmlDocPtr doc); -#endif /* LIBXML_VALID_ENABLED */ - -#if defined(LIBXML_VALID_ENABLED) -XMLPUBFUN int XMLCALL - xmlValidateNotationUse (xmlValidCtxtPtr ctxt, - xmlDocPtr doc, - const xmlChar *notationName); -#endif /* LIBXML_VALID_ENABLED */ XMLPUBFUN int XMLCALL xmlIsMixedElement (xmlDocPtr doc, @@ -370,29 +292,6 @@ XMLPUBFUN xmlElementPtr XMLCALL xmlGetDtdElementDesc (xmlDtdPtr dtd, const xmlChar *name); -#ifdef LIBXML_VALID_ENABLED - -XMLPUBFUN int XMLCALL - xmlValidGetPotentialChildren(xmlElementContent *ctree, - const xmlChar **names, - int *len, - int max); - -XMLPUBFUN int XMLCALL - xmlValidGetValidElements(xmlNode *prev, - xmlNode *next, - const xmlChar **names, - int max); -XMLPUBFUN int XMLCALL - xmlValidateNameValue (const xmlChar *value); -XMLPUBFUN int XMLCALL - xmlValidateNamesValue (const xmlChar *value); -XMLPUBFUN int XMLCALL - xmlValidateNmtokenValue (const xmlChar *value); -XMLPUBFUN int XMLCALL - xmlValidateNmtokensValue(const xmlChar *value); - -#endif /* LIBXML_VALID_ENABLED */ #ifdef __cplusplus } #endif diff --git a/android/native/libxml2/libxml/xmlversion.h b/android/native/libxml2/libxml/xmlversion.h index 8b2f80648a..820c0779fe 100644 --- a/android/native/libxml2/libxml/xmlversion.h +++ b/android/native/libxml2/libxml/xmlversion.h @@ -112,15 +112,6 @@ XMLPUBFUN void XMLCALL xmlCheckVersion(int version); #define LIBXML_READER_ENABLED #endif -/** - * LIBXML_VALID_ENABLED: - * - * Whether the DTD validation support is configured in - */ -#if 0 -#define LIBXML_VALID_ENABLED -#endif - /** * LIBXML_ICONV_ENABLED: * diff --git a/android/native/libxml2/parser.c b/android/native/libxml2/parser.c index e75a5100b0..5f31e19069 100644 --- a/android/native/libxml2/parser.c +++ b/android/native/libxml2/parser.c @@ -793,11 +793,7 @@ xmlHasFeature(xmlFeature feature) case XML_WITH_HTTP: return(0); case XML_WITH_VALID: -#ifdef LIBXML_VALID_ENABLED - return(1); -#else return(0); -#endif case XML_WITH_HTML: return(0); case XML_WITH_LEGACY: @@ -9073,17 +9069,6 @@ xmlParseElement(xmlParserCtxtPtr ctxt) { namePush(ctxt, name); ret = ctxt->node; -#ifdef LIBXML_VALID_ENABLED - /* - * [ VC: Root Element Type ] - * The Name in the document type declaration must match the element - * type of the root element. - */ - if (ctxt->validate && ctxt->wellFormed && ctxt->myDoc && - ctxt->node && (ctxt->node == ctxt->myDoc->children)) - ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc); -#endif /* LIBXML_VALID_ENABLED */ - /* * Check for an Empty Element. */ @@ -10444,16 +10429,6 @@ xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) { ctxt->sax->endDocument(ctxt->userData); goto done; } -#ifdef LIBXML_VALID_ENABLED - /* - * [ VC: Root Element Type ] - * The Name in the document type declaration must match - * the element type of the root element. - */ - if (ctxt->validate && ctxt->wellFormed && ctxt->myDoc && - ctxt->node && (ctxt->node == ctxt->myDoc->children)) - ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc); -#endif /* LIBXML_VALID_ENABLED */ /* * Check for an Empty Element. @@ -11450,287 +11425,6 @@ xmlCreateIOParserCtxt(xmlSAXHandlerPtr sax, void *user_data, return(ctxt); } -#ifdef LIBXML_VALID_ENABLED -/************************************************************************ - * * - * Front ends when parsing a DTD * - * * - ************************************************************************/ - -/** - * xmlIOParseDTD: - * @sax: the SAX handler block or NULL - * @input: an Input Buffer - * @enc: the charset encoding if known - * - * Load and parse a DTD - * - * Returns the resulting xmlDtdPtr or NULL in case of error. - * @input will be freed by the function in any case. - */ - -xmlDtdPtr -xmlIOParseDTD(xmlSAXHandlerPtr sax, xmlParserInputBufferPtr input, - xmlCharEncoding enc) { - xmlDtdPtr ret = NULL; - xmlParserCtxtPtr ctxt; - xmlParserInputPtr pinput = NULL; - xmlChar start[4]; - - if (input == NULL) - return(NULL); - - ctxt = xmlNewParserCtxt(); - if (ctxt == NULL) { - xmlFreeParserInputBuffer(input); - return(NULL); - } - - /* - * Set-up the SAX context - */ - if (sax != NULL) { - if (ctxt->sax != NULL) - xmlFree(ctxt->sax); - ctxt->sax = sax; - ctxt->userData = ctxt; - } - xmlDetectSAX2(ctxt); - - /* - * generate a parser input from the I/O handler - */ - - pinput = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE); - if (pinput == NULL) { - if (sax != NULL) ctxt->sax = NULL; - xmlFreeParserInputBuffer(input); - xmlFreeParserCtxt(ctxt); - return(NULL); - } - - /* - * plug some encoding conversion routines here. - */ - if (xmlPushInput(ctxt, pinput) < 0) { - if (sax != NULL) ctxt->sax = NULL; - xmlFreeParserCtxt(ctxt); - return(NULL); - } - if (enc != XML_CHAR_ENCODING_NONE) { - xmlSwitchEncoding(ctxt, enc); - } - - pinput->filename = NULL; - pinput->line = 1; - pinput->col = 1; - pinput->base = ctxt->input->cur; - pinput->cur = ctxt->input->cur; - pinput->free = NULL; - - /* - * let's parse that entity knowing it's an external subset. - */ - ctxt->inSubset = 2; - ctxt->myDoc = xmlNewDoc(BAD_CAST "1.0"); - if (ctxt->myDoc == NULL) { - xmlErrMemory(ctxt, "New Doc failed"); - return(NULL); - } - ctxt->myDoc->properties = XML_DOC_INTERNAL; - ctxt->myDoc->extSubset = xmlNewDtd(ctxt->myDoc, BAD_CAST "none", - BAD_CAST "none", BAD_CAST "none"); - - if ((enc == XML_CHAR_ENCODING_NONE) && - ((ctxt->input->end - ctxt->input->cur) >= 4)) { - /* - * Get the 4 first bytes and decode the charset - * if enc != XML_CHAR_ENCODING_NONE - * plug some encoding conversion routines. - */ - start[0] = RAW; - start[1] = NXT(1); - start[2] = NXT(2); - start[3] = NXT(3); - enc = xmlDetectCharEncoding(start, 4); - if (enc != XML_CHAR_ENCODING_NONE) { - xmlSwitchEncoding(ctxt, enc); - } - } - - xmlParseExternalSubset(ctxt, BAD_CAST "none", BAD_CAST "none"); - - if (ctxt->myDoc != NULL) { - if (ctxt->wellFormed) { - ret = ctxt->myDoc->extSubset; - ctxt->myDoc->extSubset = NULL; - if (ret != NULL) { - xmlNodePtr tmp; - - ret->doc = NULL; - tmp = ret->children; - while (tmp != NULL) { - tmp->doc = NULL; - tmp = tmp->next; - } - } - } else { - ret = NULL; - } - xmlFreeDoc(ctxt->myDoc); - ctxt->myDoc = NULL; - } - if (sax != NULL) ctxt->sax = NULL; - xmlFreeParserCtxt(ctxt); - - return(ret); -} - -/** - * xmlSAXParseDTD: - * @sax: the SAX handler block - * @ExternalID: a NAME* containing the External ID of the DTD - * @SystemID: a NAME* containing the URL to the DTD - * - * Load and parse an external subset. - * - * Returns the resulting xmlDtdPtr or NULL in case of error. - */ - -xmlDtdPtr -xmlSAXParseDTD(xmlSAXHandlerPtr sax, const xmlChar *ExternalID, - const xmlChar *SystemID) { - xmlDtdPtr ret = NULL; - xmlParserCtxtPtr ctxt; - xmlParserInputPtr input = NULL; - xmlCharEncoding enc; - xmlChar* systemIdCanonic; - - if ((ExternalID == NULL) && (SystemID == NULL)) return(NULL); - - ctxt = xmlNewParserCtxt(); - if (ctxt == NULL) { - return(NULL); - } - - /* - * Set-up the SAX context - */ - if (sax != NULL) { - if (ctxt->sax != NULL) - xmlFree(ctxt->sax); - ctxt->sax = sax; - ctxt->userData = ctxt; - } - - /* - * Canonicalise the system ID - */ - systemIdCanonic = xmlCanonicPath(SystemID); - if ((SystemID != NULL) && (systemIdCanonic == NULL)) { - xmlFreeParserCtxt(ctxt); - return(NULL); - } - - /* - * Ask the Entity resolver to load the damn thing - */ - - if ((ctxt->sax != NULL) && (ctxt->sax->resolveEntity != NULL)) - input = ctxt->sax->resolveEntity(ctxt->userData, ExternalID, - systemIdCanonic); - if (input == NULL) { - if (sax != NULL) ctxt->sax = NULL; - xmlFreeParserCtxt(ctxt); - if (systemIdCanonic != NULL) - xmlFree(systemIdCanonic); - return(NULL); - } - - /* - * plug some encoding conversion routines here. - */ - if (xmlPushInput(ctxt, input) < 0) { - if (sax != NULL) ctxt->sax = NULL; - xmlFreeParserCtxt(ctxt); - if (systemIdCanonic != NULL) - xmlFree(systemIdCanonic); - return(NULL); - } - if ((ctxt->input->end - ctxt->input->cur) >= 4) { - enc = xmlDetectCharEncoding(ctxt->input->cur, 4); - xmlSwitchEncoding(ctxt, enc); - } - - if (input->filename == NULL) - input->filename = (char *) systemIdCanonic; - else - xmlFree(systemIdCanonic); - input->line = 1; - input->col = 1; - input->base = ctxt->input->cur; - input->cur = ctxt->input->cur; - input->free = NULL; - - /* - * let's parse that entity knowing it's an external subset. - */ - ctxt->inSubset = 2; - ctxt->myDoc = xmlNewDoc(BAD_CAST "1.0"); - if (ctxt->myDoc == NULL) { - xmlErrMemory(ctxt, "New Doc failed"); - if (sax != NULL) ctxt->sax = NULL; - xmlFreeParserCtxt(ctxt); - return(NULL); - } - ctxt->myDoc->properties = XML_DOC_INTERNAL; - ctxt->myDoc->extSubset = xmlNewDtd(ctxt->myDoc, BAD_CAST "none", - ExternalID, SystemID); - xmlParseExternalSubset(ctxt, ExternalID, SystemID); - - if (ctxt->myDoc != NULL) { - if (ctxt->wellFormed) { - ret = ctxt->myDoc->extSubset; - ctxt->myDoc->extSubset = NULL; - if (ret != NULL) { - xmlNodePtr tmp; - - ret->doc = NULL; - tmp = ret->children; - while (tmp != NULL) { - tmp->doc = NULL; - tmp = tmp->next; - } - } - } else { - ret = NULL; - } - xmlFreeDoc(ctxt->myDoc); - ctxt->myDoc = NULL; - } - if (sax != NULL) ctxt->sax = NULL; - xmlFreeParserCtxt(ctxt); - - return(ret); -} - - -/** - * xmlParseDTD: - * @ExternalID: a NAME* containing the External ID of the DTD - * @SystemID: a NAME* containing the URL to the DTD - * - * Load and parse an external subset. - * - * Returns the resulting xmlDtdPtr or NULL in case of error. - */ - -xmlDtdPtr -xmlParseDTD(const xmlChar *ExternalID, const xmlChar *SystemID) { - return(xmlSAXParseDTD(NULL, ExternalID, SystemID)); -} -#endif /* LIBXML_VALID_ENABLED */ - /************************************************************************ * * * Front ends when parsing an Entity * @@ -12288,14 +11982,6 @@ xmlParseBalancedChunkMemoryInternal(xmlParserCtxtPtr oldctxt, cur = ctxt->myDoc->children->children; *lst = cur; while (cur != NULL) { -#ifdef LIBXML_VALID_ENABLED - if ((oldctxt->validate) && (oldctxt->wellFormed) && - (oldctxt->myDoc) && (oldctxt->myDoc->intSubset) && - (cur->type == XML_ELEMENT_NODE)) { - oldctxt->valid &= xmlValidateElement(&oldctxt->vctxt, - oldctxt->myDoc, cur); - } -#endif /* LIBXML_VALID_ENABLED */ cur->parent = NULL; cur = cur->next; } diff --git a/android/native/libxml2/valid.c b/android/native/libxml2/valid.c index bfe25a5424..eff74fb16d 100644 --- a/android/native/libxml2/valid.c +++ b/android/native/libxml2/valid.c @@ -36,11 +36,6 @@ static xmlElementPtr xmlGetDtdElementDesc2(xmlDtdPtr dtd, const xmlChar *name, "Unimplemented block at %s:%d\n", \ __FILE__, __LINE__); -#ifdef LIBXML_VALID_ENABLED -static int -xmlValidateAttributeValueInternal(xmlDocPtr doc, xmlAttributeType type, - const xmlChar *value); -#endif /************************************************************************ * * * Error handling routines * @@ -125,471 +120,6 @@ xmlErrValid(xmlValidCtxtPtr ctxt, xmlParserErrors error, "%s", msg); } -#if defined(LIBXML_VALID_ENABLED) -/** - * xmlErrValidNode: - * @ctxt: an XML validation parser context - * @node: the node raising the error - * @error: the error number - * @str1: extra informations - * @str2: extra informations - * @str3: extra informations - * - * Handle a validation error, provide contextual informations - */ -static void -xmlErrValidNode(xmlValidCtxtPtr ctxt, - xmlNodePtr node, xmlParserErrors error, - const char *msg, const xmlChar * str1, - const xmlChar * str2, const xmlChar * str3) -{ - xmlStructuredErrorFunc schannel = NULL; - xmlGenericErrorFunc channel = NULL; - xmlParserCtxtPtr pctxt = NULL; - void *data = NULL; - - if (ctxt != NULL) { - channel = ctxt->error; - data = ctxt->userData; - /* Use the special values to detect if it is part of a parsing - context */ - if ((ctxt->finishDtd == XML_CTXT_FINISH_DTD_0) || - (ctxt->finishDtd == XML_CTXT_FINISH_DTD_1)) { - long delta = (char *) ctxt - (char *) ctxt->userData; - if ((delta > 0) && (delta < 250)) - pctxt = ctxt->userData; - } - } - __xmlRaiseError(schannel, channel, data, pctxt, node, XML_FROM_VALID, error, - XML_ERR_ERROR, NULL, 0, - (const char *) str1, - (const char *) str1, - (const char *) str3, 0, 0, msg, str1, str2, str3); -} -#endif /* LIBXML_VALID_ENABLED */ - -#ifdef LIBXML_VALID_ENABLED -/** - * xmlErrValidNodeNr: - * @ctxt: an XML validation parser context - * @node: the node raising the error - * @error: the error number - * @str1: extra informations - * @int2: extra informations - * @str3: extra informations - * - * Handle a validation error, provide contextual informations - */ -static void -xmlErrValidNodeNr(xmlValidCtxtPtr ctxt, - xmlNodePtr node, xmlParserErrors error, - const char *msg, const xmlChar * str1, - int int2, const xmlChar * str3) -{ - xmlStructuredErrorFunc schannel = NULL; - xmlGenericErrorFunc channel = NULL; - xmlParserCtxtPtr pctxt = NULL; - void *data = NULL; - - if (ctxt != NULL) { - channel = ctxt->error; - data = ctxt->userData; - /* Use the special values to detect if it is part of a parsing - context */ - if ((ctxt->finishDtd == XML_CTXT_FINISH_DTD_0) || - (ctxt->finishDtd == XML_CTXT_FINISH_DTD_1)) { - long delta = (char *) ctxt - (char *) ctxt->userData; - if ((delta > 0) && (delta < 250)) - pctxt = ctxt->userData; - } - } - __xmlRaiseError(schannel, channel, data, pctxt, node, XML_FROM_VALID, error, - XML_ERR_ERROR, NULL, 0, - (const char *) str1, - (const char *) str3, - NULL, int2, 0, msg, str1, int2, str3); -} - -/** - * xmlErrValidWarning: - * @ctxt: an XML validation parser context - * @node: the node raising the error - * @error: the error number - * @str1: extra information - * @str2: extra information - * @str3: extra information - * - * Handle a validation error, provide contextual information - */ -static void -xmlErrValidWarning(xmlValidCtxtPtr ctxt, - xmlNodePtr node, xmlParserErrors error, - const char *msg, const xmlChar * str1, - const xmlChar * str2, const xmlChar * str3) -{ - xmlStructuredErrorFunc schannel = NULL; - xmlGenericErrorFunc channel = NULL; - xmlParserCtxtPtr pctxt = NULL; - void *data = NULL; - - if (ctxt != NULL) { - channel = ctxt->warning; - data = ctxt->userData; - /* Use the special values to detect if it is part of a parsing - context */ - if ((ctxt->finishDtd == XML_CTXT_FINISH_DTD_0) || - (ctxt->finishDtd == XML_CTXT_FINISH_DTD_1)) { - long delta = (char *) ctxt - (char *) ctxt->userData; - if ((delta > 0) && (delta < 250)) - pctxt = ctxt->userData; - } - } - __xmlRaiseError(schannel, channel, data, pctxt, node, XML_FROM_VALID, error, - XML_ERR_WARNING, NULL, 0, - (const char *) str1, - (const char *) str1, - (const char *) str3, 0, 0, msg, str1, str2, str3); -} - - -/* - * If regexp are not enabled, it uses a home made algorithm less - * complex and easier to - * debug/maintain than a generic NFA -> DFA state based algo. The - * only restriction is on the deepness of the tree limited by the - * size of the occurs bitfield - * - * this is the content of a saved state for rollbacks - */ - -#define ROLLBACK_OR 0 -#define ROLLBACK_PARENT 1 - -typedef struct _xmlValidState { - xmlElementContentPtr cont; /* pointer to the content model subtree */ - xmlNodePtr node; /* pointer to the current node in the list */ - long occurs;/* bitfield for multiple occurrences */ - unsigned char depth; /* current depth in the overall tree */ - unsigned char state; /* ROLLBACK_XXX */ -} _xmlValidState; - -#define MAX_RECURSE 25000 -#define MAX_DEPTH ((sizeof(_xmlValidState.occurs)) * 8) -#define CONT ctxt->vstate->cont -#define NODE ctxt->vstate->node -#define DEPTH ctxt->vstate->depth -#define OCCURS ctxt->vstate->occurs -#define STATE ctxt->vstate->state - -#define OCCURRENCE (ctxt->vstate->occurs & (1 << DEPTH)) -#define PARENT_OCCURRENCE (ctxt->vstate->occurs & ((1 << DEPTH) - 1)) - -#define SET_OCCURRENCE ctxt->vstate->occurs |= (1 << DEPTH) -#define RESET_OCCURRENCE ctxt->vstate->occurs &= ((1 << DEPTH) - 1) - -static int -vstateVPush(xmlValidCtxtPtr ctxt, xmlElementContentPtr cont, - xmlNodePtr node, unsigned char depth, long occurs, - unsigned char state) { - int i = ctxt->vstateNr - 1; - - if (ctxt->vstateNr > MAX_RECURSE) { - return(-1); - } - if (ctxt->vstateTab == NULL) { - ctxt->vstateMax = 8; - ctxt->vstateTab = (xmlValidState *) xmlMalloc( - ctxt->vstateMax * sizeof(ctxt->vstateTab[0])); - if (ctxt->vstateTab == NULL) { - xmlVErrMemory(ctxt, "malloc failed"); - return(-1); - } - } - if (ctxt->vstateNr >= ctxt->vstateMax) { - xmlValidState *tmp; - - tmp = (xmlValidState *) xmlRealloc(ctxt->vstateTab, - 2 * ctxt->vstateMax * sizeof(ctxt->vstateTab[0])); - if (tmp == NULL) { - xmlVErrMemory(ctxt, "malloc failed"); - return(-1); - } - ctxt->vstateMax *= 2; - ctxt->vstateTab = tmp; - ctxt->vstate = &ctxt->vstateTab[0]; - } - /* - * Don't push on the stack a state already here - */ - if ((i >= 0) && (ctxt->vstateTab[i].cont == cont) && - (ctxt->vstateTab[i].node == node) && - (ctxt->vstateTab[i].depth == depth) && - (ctxt->vstateTab[i].occurs == occurs) && - (ctxt->vstateTab[i].state == state)) - return(ctxt->vstateNr); - ctxt->vstateTab[ctxt->vstateNr].cont = cont; - ctxt->vstateTab[ctxt->vstateNr].node = node; - ctxt->vstateTab[ctxt->vstateNr].depth = depth; - ctxt->vstateTab[ctxt->vstateNr].occurs = occurs; - ctxt->vstateTab[ctxt->vstateNr].state = state; - return(ctxt->vstateNr++); -} - -static int -vstateVPop(xmlValidCtxtPtr ctxt) { - if (ctxt->vstateNr <= 1) return(-1); - ctxt->vstateNr--; - ctxt->vstate = &ctxt->vstateTab[0]; - ctxt->vstate->cont = ctxt->vstateTab[ctxt->vstateNr].cont; - ctxt->vstate->node = ctxt->vstateTab[ctxt->vstateNr].node; - ctxt->vstate->depth = ctxt->vstateTab[ctxt->vstateNr].depth; - ctxt->vstate->occurs = ctxt->vstateTab[ctxt->vstateNr].occurs; - ctxt->vstate->state = ctxt->vstateTab[ctxt->vstateNr].state; - return(ctxt->vstateNr); -} - -static int -nodeVPush(xmlValidCtxtPtr ctxt, xmlNodePtr value) -{ - if (ctxt->nodeMax <= 0) { - ctxt->nodeMax = 4; - ctxt->nodeTab = - (xmlNodePtr *) xmlMalloc(ctxt->nodeMax * - sizeof(ctxt->nodeTab[0])); - if (ctxt->nodeTab == NULL) { - xmlVErrMemory(ctxt, "malloc failed"); - ctxt->nodeMax = 0; - return (0); - } - } - if (ctxt->nodeNr >= ctxt->nodeMax) { - xmlNodePtr *tmp; - tmp = (xmlNodePtr *) xmlRealloc(ctxt->nodeTab, - ctxt->nodeMax * 2 * sizeof(ctxt->nodeTab[0])); - if (tmp == NULL) { - xmlVErrMemory(ctxt, "realloc failed"); - return (0); - } - ctxt->nodeMax *= 2; - ctxt->nodeTab = tmp; - } - ctxt->nodeTab[ctxt->nodeNr] = value; - ctxt->node = value; - return (ctxt->nodeNr++); -} -static xmlNodePtr -nodeVPop(xmlValidCtxtPtr ctxt) -{ - xmlNodePtr ret; - - if (ctxt->nodeNr <= 0) - return (NULL); - ctxt->nodeNr--; - if (ctxt->nodeNr > 0) - ctxt->node = ctxt->nodeTab[ctxt->nodeNr - 1]; - else - ctxt->node = NULL; - ret = ctxt->nodeTab[ctxt->nodeNr]; - ctxt->nodeTab[ctxt->nodeNr] = NULL; - return (ret); -} - -#ifdef DEBUG_VALID_ALGO -static void -xmlValidPrintNode(xmlNodePtr cur) { - if (cur == NULL) { - xmlGenericError(xmlGenericErrorContext, "null"); - return; - } - switch (cur->type) { - case XML_ELEMENT_NODE: - xmlGenericError(xmlGenericErrorContext, "%s ", cur->name); - break; - case XML_TEXT_NODE: - xmlGenericError(xmlGenericErrorContext, "text "); - break; - case XML_CDATA_SECTION_NODE: - xmlGenericError(xmlGenericErrorContext, "cdata "); - break; - case XML_ENTITY_REF_NODE: - xmlGenericError(xmlGenericErrorContext, "&%s; ", cur->name); - break; - case XML_PI_NODE: - xmlGenericError(xmlGenericErrorContext, "pi(%s) ", cur->name); - break; - case XML_COMMENT_NODE: - xmlGenericError(xmlGenericErrorContext, "comment "); - break; - case XML_ATTRIBUTE_NODE: - xmlGenericError(xmlGenericErrorContext, "?attr? "); - break; - case XML_ENTITY_NODE: - xmlGenericError(xmlGenericErrorContext, "?ent? "); - break; - case XML_DOCUMENT_NODE: - xmlGenericError(xmlGenericErrorContext, "?doc? "); - break; - case XML_DOCUMENT_TYPE_NODE: - xmlGenericError(xmlGenericErrorContext, "?doctype? "); - break; - case XML_DOCUMENT_FRAG_NODE: - xmlGenericError(xmlGenericErrorContext, "?frag? "); - break; - case XML_NOTATION_NODE: - xmlGenericError(xmlGenericErrorContext, "?nota? "); - break; - case XML_HTML_DOCUMENT_NODE: - xmlGenericError(xmlGenericErrorContext, "?html? "); - break; - case XML_DTD_NODE: - xmlGenericError(xmlGenericErrorContext, "?dtd? "); - break; - case XML_ELEMENT_DECL: - xmlGenericError(xmlGenericErrorContext, "?edecl? "); - break; - case XML_ATTRIBUTE_DECL: - xmlGenericError(xmlGenericErrorContext, "?adecl? "); - break; - case XML_ENTITY_DECL: - xmlGenericError(xmlGenericErrorContext, "?entdecl? "); - break; - case XML_NAMESPACE_DECL: - xmlGenericError(xmlGenericErrorContext, "?nsdecl? "); - break; - case XML_XINCLUDE_START: - xmlGenericError(xmlGenericErrorContext, "incstart "); - break; - case XML_XINCLUDE_END: - xmlGenericError(xmlGenericErrorContext, "incend "); - break; - } -} - -static void -xmlValidPrintNodeList(xmlNodePtr cur) { - if (cur == NULL) - xmlGenericError(xmlGenericErrorContext, "null "); - while (cur != NULL) { - xmlValidPrintNode(cur); - cur = cur->next; - } -} - -static void -xmlValidDebug(xmlNodePtr cur, xmlElementContentPtr cont) { - char expr[5000]; - - expr[0] = 0; - xmlGenericError(xmlGenericErrorContext, "valid: "); - xmlValidPrintNodeList(cur); - xmlGenericError(xmlGenericErrorContext, "against "); - xmlSnprintfElementContent(expr, 5000, cont, 1); - xmlGenericError(xmlGenericErrorContext, "%s\n", expr); -} - -static void -xmlValidDebugState(xmlValidStatePtr state) { - xmlGenericError(xmlGenericErrorContext, "("); - if (state->cont == NULL) - xmlGenericError(xmlGenericErrorContext, "null,"); - else - switch (state->cont->type) { - case XML_ELEMENT_CONTENT_PCDATA: - xmlGenericError(xmlGenericErrorContext, "pcdata,"); - break; - case XML_ELEMENT_CONTENT_ELEMENT: - xmlGenericError(xmlGenericErrorContext, "%s,", - state->cont->name); - break; - case XML_ELEMENT_CONTENT_SEQ: - xmlGenericError(xmlGenericErrorContext, "seq,"); - break; - case XML_ELEMENT_CONTENT_OR: - xmlGenericError(xmlGenericErrorContext, "or,"); - break; - } - xmlValidPrintNode(state->node); - xmlGenericError(xmlGenericErrorContext, ",%d,%X,%d)", - state->depth, state->occurs, state->state); -} - -static void -xmlValidStateDebug(xmlValidCtxtPtr ctxt) { - int i, j; - - xmlGenericError(xmlGenericErrorContext, "state: "); - xmlValidDebugState(ctxt->vstate); - xmlGenericError(xmlGenericErrorContext, " stack: %d ", - ctxt->vstateNr - 1); - for (i = 0, j = ctxt->vstateNr - 1;(i < 3) && (j > 0);i++,j--) - xmlValidDebugState(&ctxt->vstateTab[j]); - xmlGenericError(xmlGenericErrorContext, "\n"); -} - -/***** -#define DEBUG_VALID_STATE(n,c) xmlValidDebug(n,c); - *****/ - -#define DEBUG_VALID_STATE(n,c) xmlValidStateDebug(ctxt); -#define DEBUG_VALID_MSG(m) \ - xmlGenericError(xmlGenericErrorContext, "%s\n", m); - -#else -#define DEBUG_VALID_STATE(n,c) -#define DEBUG_VALID_MSG(m) -#endif - -/* TODO: use hash table for accesses to elem and attribute definitions */ - - -#define CHECK_DTD \ - if (doc == NULL) return(0); \ - else if ((doc->intSubset == NULL) && \ - (doc->extSubset == NULL)) return(0) - -/**************************************************************** - * * - * Util functions for data allocation/deallocation * - * * - ****************************************************************/ - -/** - * xmlNewValidCtxt: - * - * Allocate a validation context structure. - * - * Returns NULL if not, otherwise the new validation context structure - */ -xmlValidCtxtPtr xmlNewValidCtxt(void) { - xmlValidCtxtPtr ret; - - if ((ret = xmlMalloc(sizeof (xmlValidCtxt))) == NULL) { - xmlVErrMemory(NULL, "malloc failed"); - return (NULL); - } - - (void) memset(ret, 0, sizeof (xmlValidCtxt)); - - return (ret); -} - -/** - * xmlFreeValidCtxt: - * @cur: the validation context to free - * - * Free a validation context structure. - */ -void -xmlFreeValidCtxt(xmlValidCtxtPtr cur) { - if (cur->vstateTab != NULL) - xmlFree(cur->vstateTab); - if (cur->nodeTab != NULL) - xmlFree(cur->nodeTab); - xmlFree(cur); -} - -#endif /* LIBXML_VALID_ENABLED */ - /** * xmlNewDocElementContent: * @doc: the document @@ -1073,14 +603,6 @@ xmlAddElementDecl(xmlValidCtxtPtr ctxt, ret = xmlHashLookup2(table, name, ns); if (ret != NULL) { if (ret->etype != XML_ELEMENT_TYPE_UNDEFINED) { -#ifdef LIBXML_VALID_ENABLED - /* - * The element is already defined in this DTD. - */ - xmlErrValidNode(ctxt, (xmlNodePtr) dtd, XML_DTD_ELEM_REDEFINED, - "Redefinition of element %s\n", - name, NULL, NULL); -#endif /* LIBXML_VALID_ENABLED */ if (uqname != NULL) xmlFree(uqname); if (ns != NULL) @@ -1124,14 +646,6 @@ xmlAddElementDecl(xmlValidCtxtPtr ctxt, * Insertion must not fail */ if (xmlHashAddEntry2(table, name, ns, ret)) { -#ifdef LIBXML_VALID_ENABLED - /* - * The element is already defined in this DTD. - */ - xmlErrValidNode(ctxt, (xmlNodePtr) dtd, XML_DTD_ELEM_REDEFINED, - "Redefinition of element %s\n", - name, NULL, NULL); -#endif /* LIBXML_VALID_ENABLED */ xmlFreeElement(ret); if (uqname != NULL) xmlFree(uqname); @@ -1306,39 +820,6 @@ xmlCopyEnumeration(xmlEnumerationPtr cur) { } #endif /* LIBXML_TREE_ENABLED */ -#ifdef LIBXML_VALID_ENABLED -/** - * xmlScanIDAttributeDecl: - * @ctxt: the validation context - * @elem: the element name - * @err: whether to raise errors here - * - * Verify that the element don't have too many ID attributes - * declared. - * - * Returns the number of ID attributes found. - */ -static int -xmlScanIDAttributeDecl(xmlValidCtxtPtr ctxt, xmlElementPtr elem, int err) { - xmlAttributePtr cur; - int ret = 0; - - if (elem == NULL) return(0); - cur = elem->attributes; - while (cur != NULL) { - if (cur->atype == XML_ATTRIBUTE_ID) { - ret ++; - if ((ret > 1) && (err)) - xmlErrValidNode(ctxt, (xmlNodePtr) elem, XML_DTD_MULTIPLE_ID, - "Element %s has too many ID attributes defined : %s\n", - elem->name, cur->name, NULL); - } - cur = cur->nexth; - } - return(ret); -} -#endif /* LIBXML_VALID_ENABLED */ - /** * xmlFreeAttribute: * @elem: An attribute @@ -1424,49 +905,6 @@ xmlAddAttributeDecl(xmlValidCtxtPtr ctxt, if (dtd->doc != NULL) dict = dtd->doc->dict; -#ifdef LIBXML_VALID_ENABLED - /* - * Check the type and possibly the default value. - */ - switch (type) { - case XML_ATTRIBUTE_CDATA: - break; - case XML_ATTRIBUTE_ID: - break; - case XML_ATTRIBUTE_IDREF: - break; - case XML_ATTRIBUTE_IDREFS: - break; - case XML_ATTRIBUTE_ENTITY: - break; - case XML_ATTRIBUTE_ENTITIES: - break; - case XML_ATTRIBUTE_NMTOKEN: - break; - case XML_ATTRIBUTE_NMTOKENS: - break; - case XML_ATTRIBUTE_ENUMERATION: - break; - case XML_ATTRIBUTE_NOTATION: - break; - default: - xmlErrValid(ctxt, XML_ERR_INTERNAL_ERROR, - "Internal: ATTRIBUTE struct corrupted invalid type\n", - NULL); - xmlFreeEnumeration(tree); - return(NULL); - } - if ((defaultValue != NULL) && - (!xmlValidateAttributeValueInternal(dtd->doc, type, defaultValue))) { - xmlErrValidNode(ctxt, (xmlNodePtr) dtd, XML_DTD_ATTRIBUTE_DEFAULT, - "Attribute %s of %s: invalid default value\n", - elem, name, defaultValue); - defaultValue = NULL; - if (ctxt != NULL) - ctxt->valid = 0; - } -#endif /* LIBXML_VALID_ENABLED */ - /* * Check first that an attribute defined in the external subset wasn't * already defined in the internal subset @@ -1539,14 +977,6 @@ xmlAddAttributeDecl(xmlValidCtxtPtr ctxt, * Search the DTD for previous declarations of the ATTLIST */ if (xmlHashAddEntry3(table, ret->name, ret->prefix, ret->elem, ret) < 0) { -#ifdef LIBXML_VALID_ENABLED - /* - * The attribute is already defined in this DTD. - */ - xmlErrValidWarning(ctxt, (xmlNodePtr) dtd, XML_DTD_ATTRIBUTE_REDEFINED, - "Attribute %s of element %s: already defined\n", - name, elem, NULL); -#endif /* LIBXML_VALID_ENABLED */ xmlFreeAttribute(ret); return(NULL); } @@ -1558,16 +988,6 @@ xmlAddAttributeDecl(xmlValidCtxtPtr ctxt, elemDef = xmlGetDtdElementDesc2(dtd, elem, 1); if (elemDef != NULL) { -#ifdef LIBXML_VALID_ENABLED - if ((type == XML_ATTRIBUTE_ID) && - (xmlScanIDAttributeDecl(NULL, elemDef, 1) != 0)) { - xmlErrValidNode(ctxt, (xmlNodePtr) dtd, XML_DTD_MULTIPLE_ID, - "Element %s has too may ID attributes defined : %s\n", - elem, name, NULL); - if (ctxt != NULL) - ctxt->valid = 0; - } -#endif /* LIBXML_VALID_ENABLED */ /* * Insert namespace default def first they need to be @@ -1764,11 +1184,6 @@ xmlAddNotationDecl(xmlValidCtxtPtr ctxt, xmlDtdPtr dtd, * Check the DTD for previous declarations of the ATTLIST */ if (xmlHashAddEntry(table, name, ret)) { -#ifdef LIBXML_VALID_ENABLED - xmlErrValid(NULL, XML_DTD_NOTATION_REDEFINED, - "xmlAddNotationDecl: %s already defined\n", - (const char *) name); -#endif /* LIBXML_VALID_ENABLED */ xmlFreeNotation(ret); return(NULL); } @@ -1941,16 +1356,6 @@ xmlAddID(xmlValidCtxtPtr ctxt, xmlDocPtr doc, const xmlChar *value, ret->lineno = xmlGetLineNo(attr->parent); if (xmlHashAddEntry(table, value, ret) < 0) { -#ifdef LIBXML_VALID_ENABLED - /* - * The id is already defined in this DTD. - */ - if ((ctxt != NULL) && (ctxt->error != NULL)) { - xmlErrValidNode(ctxt, attr->parent, XML_DTD_ID_REDEFINED, - "ID %s already defined\n", - value, NULL, NULL); - } -#endif /* LIBXML_VALID_ENABLED */ xmlFreeID(ret); return(NULL); } @@ -2646,40 +2051,6 @@ xmlGetDtdNotationDesc(xmlDtdPtr dtd, const xmlChar *name) { return(xmlHashLookup(table, name)); } -#if defined(LIBXML_VALID_ENABLED) -/** - * xmlValidateNotationUse: - * @ctxt: the validation context - * @doc: the document - * @notationName: the notation name to check - * - * Validate that the given name match a notation declaration. - * - [ VC: Notation Declared ] - * - * returns 1 if valid or 0 otherwise - */ - -int -xmlValidateNotationUse(xmlValidCtxtPtr ctxt, xmlDocPtr doc, - const xmlChar *notationName) { - xmlNotationPtr notaDecl; - if ((doc == NULL) || (doc->intSubset == NULL) || - (notationName == NULL)) return(-1); - - notaDecl = xmlGetDtdNotationDesc(doc->intSubset, notationName); - if ((notaDecl == NULL) && (doc->extSubset != NULL)) - notaDecl = xmlGetDtdNotationDesc(doc->extSubset, notationName); - - if ((notaDecl == NULL) && (ctxt != NULL)) { - xmlErrValidNode(ctxt, (xmlNodePtr) doc, XML_DTD_UNKNOWN_NOTATION, - "NOTATION %s is not declared\n", - notationName, NULL, NULL); - return(0); - } - return(1); -} -#endif /* LIBXML_VALID_ENABLED */ - /** * xmlIsMixedElement: * @doc: the document @@ -2718,3323 +2089,5 @@ xmlIsMixedElement(xmlDocPtr doc, const xmlChar *name) { return(1); } -#ifdef LIBXML_VALID_ENABLED - -static int -xmlIsDocNameStartChar(xmlDocPtr doc, int c) { - if ((doc == NULL) || (doc->properties & XML_DOC_OLD10) == 0) { - /* - * Use the new checks of production [4] [4a] amd [5] of the - * Update 5 of XML-1.0 - */ - if (((c >= 'a') && (c <= 'z')) || - ((c >= 'A') && (c <= 'Z')) || - (c == '_') || (c == ':') || - ((c >= 0xC0) && (c <= 0xD6)) || - ((c >= 0xD8) && (c <= 0xF6)) || - ((c >= 0xF8) && (c <= 0x2FF)) || - ((c >= 0x370) && (c <= 0x37D)) || - ((c >= 0x37F) && (c <= 0x1FFF)) || - ((c >= 0x200C) && (c <= 0x200D)) || - ((c >= 0x2070) && (c <= 0x218F)) || - ((c >= 0x2C00) && (c <= 0x2FEF)) || - ((c >= 0x3001) && (c <= 0xD7FF)) || - ((c >= 0xF900) && (c <= 0xFDCF)) || - ((c >= 0xFDF0) && (c <= 0xFFFD)) || - ((c >= 0x10000) && (c <= 0xEFFFF))) - return(1); - } else { - if (IS_LETTER(c) || (c == '_') || (c == ':')) - return(1); - } - return(0); -} - -static int -xmlIsDocNameChar(xmlDocPtr doc, int c) { - if ((doc == NULL) || (doc->properties & XML_DOC_OLD10) == 0) { - /* - * Use the new checks of production [4] [4a] amd [5] of the - * Update 5 of XML-1.0 - */ - if (((c >= 'a') && (c <= 'z')) || - ((c >= 'A') && (c <= 'Z')) || - ((c >= '0') && (c <= '9')) || /* !start */ - (c == '_') || (c == ':') || - (c == '-') || (c == '.') || (c == 0xB7) || /* !start */ - ((c >= 0xC0) && (c <= 0xD6)) || - ((c >= 0xD8) && (c <= 0xF6)) || - ((c >= 0xF8) && (c <= 0x2FF)) || - ((c >= 0x300) && (c <= 0x36F)) || /* !start */ - ((c >= 0x370) && (c <= 0x37D)) || - ((c >= 0x37F) && (c <= 0x1FFF)) || - ((c >= 0x200C) && (c <= 0x200D)) || - ((c >= 0x203F) && (c <= 0x2040)) || /* !start */ - ((c >= 0x2070) && (c <= 0x218F)) || - ((c >= 0x2C00) && (c <= 0x2FEF)) || - ((c >= 0x3001) && (c <= 0xD7FF)) || - ((c >= 0xF900) && (c <= 0xFDCF)) || - ((c >= 0xFDF0) && (c <= 0xFFFD)) || - ((c >= 0x10000) && (c <= 0xEFFFF))) - return(1); - } else { - if ((IS_LETTER(c)) || (IS_DIGIT(c)) || - (c == '.') || (c == '-') || - (c == '_') || (c == ':') || - (IS_COMBINING(c)) || - (IS_EXTENDER(c))) - return(1); - } - return(0); -} - -/** - * xmlValidateNameValue: - * @doc: pointer to the document or NULL - * @value: an Name value - * - * Validate that the given value match Name production - * - * returns 1 if valid or 0 otherwise - */ - -static int -xmlValidateNameValueInternal(xmlDocPtr doc, const xmlChar *value) { - const xmlChar *cur; - int val, len; - - if (value == NULL) return(0); - cur = value; - val = xmlStringCurrentChar(NULL, cur, &len); - cur += len; - if (!xmlIsDocNameStartChar(doc, val)) - return(0); - - val = xmlStringCurrentChar(NULL, cur, &len); - cur += len; - while (xmlIsDocNameChar(doc, val)) { - val = xmlStringCurrentChar(NULL, cur, &len); - cur += len; - } - - if (val != 0) return(0); - - return(1); -} - -/** - * xmlValidateNameValue: - * @value: an Name value - * - * Validate that the given value match Name production - * - * returns 1 if valid or 0 otherwise - */ - -int -xmlValidateNameValue(const xmlChar *value) { - return(xmlValidateNameValueInternal(NULL, value)); -} - -/** - * xmlValidateNamesValueInternal: - * @doc: pointer to the document or NULL - * @value: an Names value - * - * Validate that the given value match Names production - * - * returns 1 if valid or 0 otherwise - */ - -static int -xmlValidateNamesValueInternal(xmlDocPtr doc, const xmlChar *value) { - const xmlChar *cur; - int val, len; - - if (value == NULL) return(0); - cur = value; - val = xmlStringCurrentChar(NULL, cur, &len); - cur += len; - - if (!xmlIsDocNameStartChar(doc, val)) - return(0); - - val = xmlStringCurrentChar(NULL, cur, &len); - cur += len; - while (xmlIsDocNameChar(doc, val)) { - val = xmlStringCurrentChar(NULL, cur, &len); - cur += len; - } - - /* Should not test IS_BLANK(val) here -- see erratum E20*/ - while (val == 0x20) { - while (val == 0x20) { - val = xmlStringCurrentChar(NULL, cur, &len); - cur += len; - } - - if (!xmlIsDocNameStartChar(doc, val)) - return(0); - - val = xmlStringCurrentChar(NULL, cur, &len); - cur += len; - - while (xmlIsDocNameChar(doc, val)) { - val = xmlStringCurrentChar(NULL, cur, &len); - cur += len; - } - } - - if (val != 0) return(0); - - return(1); -} - -/** - * xmlValidateNamesValue: - * @value: an Names value - * - * Validate that the given value match Names production - * - * returns 1 if valid or 0 otherwise - */ - -int -xmlValidateNamesValue(const xmlChar *value) { - return(xmlValidateNamesValueInternal(NULL, value)); -} - -/** - * xmlValidateNmtokenValueInternal: - * @doc: pointer to the document or NULL - * @value: an Nmtoken value - * - * Validate that the given value match Nmtoken production - * - * [ VC: Name Token ] - * - * returns 1 if valid or 0 otherwise - */ - -static int -xmlValidateNmtokenValueInternal(xmlDocPtr doc, const xmlChar *value) { - const xmlChar *cur; - int val, len; - - if (value == NULL) return(0); - cur = value; - val = xmlStringCurrentChar(NULL, cur, &len); - cur += len; - - if (!xmlIsDocNameChar(doc, val)) - return(0); - - val = xmlStringCurrentChar(NULL, cur, &len); - cur += len; - while (xmlIsDocNameChar(doc, val)) { - val = xmlStringCurrentChar(NULL, cur, &len); - cur += len; - } - - if (val != 0) return(0); - - return(1); -} - -/** - * xmlValidateNmtokenValue: - * @value: an Nmtoken value - * - * Validate that the given value match Nmtoken production - * - * [ VC: Name Token ] - * - * returns 1 if valid or 0 otherwise - */ - -int -xmlValidateNmtokenValue(const xmlChar *value) { - return(xmlValidateNmtokenValueInternal(NULL, value)); -} - -/** - * xmlValidateNmtokensValueInternal: - * @doc: pointer to the document or NULL - * @value: an Nmtokens value - * - * Validate that the given value match Nmtokens production - * - * [ VC: Name Token ] - * - * returns 1 if valid or 0 otherwise - */ - -static int -xmlValidateNmtokensValueInternal(xmlDocPtr doc, const xmlChar *value) { - const xmlChar *cur; - int val, len; - - if (value == NULL) return(0); - cur = value; - val = xmlStringCurrentChar(NULL, cur, &len); - cur += len; - - while (IS_BLANK(val)) { - val = xmlStringCurrentChar(NULL, cur, &len); - cur += len; - } - - if (!xmlIsDocNameChar(doc, val)) - return(0); - - while (xmlIsDocNameChar(doc, val)) { - val = xmlStringCurrentChar(NULL, cur, &len); - cur += len; - } - - /* Should not test IS_BLANK(val) here -- see erratum E20*/ - while (val == 0x20) { - while (val == 0x20) { - val = xmlStringCurrentChar(NULL, cur, &len); - cur += len; - } - if (val == 0) return(1); - - if (!xmlIsDocNameChar(doc, val)) - return(0); - - val = xmlStringCurrentChar(NULL, cur, &len); - cur += len; - - while (xmlIsDocNameChar(doc, val)) { - val = xmlStringCurrentChar(NULL, cur, &len); - cur += len; - } - } - - if (val != 0) return(0); - - return(1); -} - -/** - * xmlValidateNmtokensValue: - * @value: an Nmtokens value - * - * Validate that the given value match Nmtokens production - * - * [ VC: Name Token ] - * - * returns 1 if valid or 0 otherwise - */ - -int -xmlValidateNmtokensValue(const xmlChar *value) { - return(xmlValidateNmtokensValueInternal(NULL, value)); -} - -/** - * xmlValidateNotationDecl: - * @ctxt: the validation context - * @doc: a document instance - * @nota: a notation definition - * - * Try to validate a single notation definition - * basically it does the following checks as described by the - * XML-1.0 recommendation: - * - it seems that no validity constraint exists on notation declarations - * But this function get called anyway ... - * - * returns 1 if valid or 0 otherwise - */ - -int -xmlValidateNotationDecl(xmlValidCtxtPtr ctxt ATTRIBUTE_UNUSED, xmlDocPtr doc ATTRIBUTE_UNUSED, - xmlNotationPtr nota ATTRIBUTE_UNUSED) { - int ret = 1; - - return(ret); -} - -/** - * xmlValidateAttributeValueInternal: - * @doc: the document - * @type: an attribute type - * @value: an attribute value - * - * Validate that the given attribute value match the proper production - * - * returns 1 if valid or 0 otherwise - */ - -static int -xmlValidateAttributeValueInternal(xmlDocPtr doc, xmlAttributeType type, - const xmlChar *value) { - switch (type) { - case XML_ATTRIBUTE_ENTITIES: - case XML_ATTRIBUTE_IDREFS: - return(xmlValidateNamesValueInternal(doc, value)); - case XML_ATTRIBUTE_ENTITY: - case XML_ATTRIBUTE_IDREF: - case XML_ATTRIBUTE_ID: - case XML_ATTRIBUTE_NOTATION: - return(xmlValidateNameValueInternal(doc, value)); - case XML_ATTRIBUTE_NMTOKENS: - case XML_ATTRIBUTE_ENUMERATION: - return(xmlValidateNmtokensValueInternal(doc, value)); - case XML_ATTRIBUTE_NMTOKEN: - return(xmlValidateNmtokenValueInternal(doc, value)); - case XML_ATTRIBUTE_CDATA: - break; - } - return(1); -} - -/** - * xmlValidateAttributeValue: - * @type: an attribute type - * @value: an attribute value - * - * Validate that the given attribute value match the proper production - * - * [ VC: ID ] - * Values of type ID must match the Name production.... - * - * [ VC: IDREF ] - * Values of type IDREF must match the Name production, and values - * of type IDREFS must match Names ... - * - * [ VC: Entity Name ] - * Values of type ENTITY must match the Name production, values - * of type ENTITIES must match Names ... - * - * [ VC: Name Token ] - * Values of type NMTOKEN must match the Nmtoken production; values - * of type NMTOKENS must match Nmtokens. - * - * returns 1 if valid or 0 otherwise - */ -int -xmlValidateAttributeValue(xmlAttributeType type, const xmlChar *value) { - return(xmlValidateAttributeValueInternal(NULL, type, value)); -} - -/** - * xmlValidateAttributeValue2: - * @ctxt: the validation context - * @doc: the document - * @name: the attribute name (used for error reporting only) - * @type: the attribute type - * @value: the attribute value - * - * Validate that the given attribute value match a given type. - * This typically cannot be done before having finished parsing - * the subsets. - * - * [ VC: IDREF ] - * Values of type IDREF must match one of the declared IDs - * Values of type IDREFS must match a sequence of the declared IDs - * each Name must match the value of an ID attribute on some element - * in the XML document; i.e. IDREF values must match the value of - * some ID attribute - * - * [ VC: Entity Name ] - * Values of type ENTITY must match one declared entity - * Values of type ENTITIES must match a sequence of declared entities - * - * [ VC: Notation Attributes ] - * all notation names in the declaration must be declared. - * - * returns 1 if valid or 0 otherwise - */ - -static int -xmlValidateAttributeValue2(xmlValidCtxtPtr ctxt, xmlDocPtr doc, - const xmlChar *name, xmlAttributeType type, const xmlChar *value) { - int ret = 1; - switch (type) { - case XML_ATTRIBUTE_IDREFS: - case XML_ATTRIBUTE_IDREF: - case XML_ATTRIBUTE_ID: - case XML_ATTRIBUTE_NMTOKENS: - case XML_ATTRIBUTE_ENUMERATION: - case XML_ATTRIBUTE_NMTOKEN: - case XML_ATTRIBUTE_CDATA: - break; - case XML_ATTRIBUTE_ENTITY: { - xmlEntityPtr ent; - - ent = xmlGetDocEntity(doc, value); - /* yeah it's a bit messy... */ - if ((ent == NULL) && (doc->standalone == 1)) { - doc->standalone = 0; - ent = xmlGetDocEntity(doc, value); - } - if (ent == NULL) { - xmlErrValidNode(ctxt, (xmlNodePtr) doc, - XML_DTD_UNKNOWN_ENTITY, - "ENTITY attribute %s reference an unknown entity \"%s\"\n", - name, value, NULL); - ret = 0; - } else if (ent->etype != XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) { - xmlErrValidNode(ctxt, (xmlNodePtr) doc, - XML_DTD_ENTITY_TYPE, - "ENTITY attribute %s reference an entity \"%s\" of wrong type\n", - name, value, NULL); - ret = 0; - } - break; - } - case XML_ATTRIBUTE_ENTITIES: { - xmlChar *dup, *nam = NULL, *cur, save; - xmlEntityPtr ent; - - dup = xmlStrdup(value); - if (dup == NULL) - return(0); - cur = dup; - while (*cur != 0) { - nam = cur; - while ((*cur != 0) && (!IS_BLANK_CH(*cur))) cur++; - save = *cur; - *cur = 0; - ent = xmlGetDocEntity(doc, nam); - if (ent == NULL) { - xmlErrValidNode(ctxt, (xmlNodePtr) doc, - XML_DTD_UNKNOWN_ENTITY, - "ENTITIES attribute %s reference an unknown entity \"%s\"\n", - name, nam, NULL); - ret = 0; - } else if (ent->etype != XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) { - xmlErrValidNode(ctxt, (xmlNodePtr) doc, - XML_DTD_ENTITY_TYPE, - "ENTITIES attribute %s reference an entity \"%s\" of wrong type\n", - name, nam, NULL); - ret = 0; - } - if (save == 0) - break; - *cur = save; - while (IS_BLANK_CH(*cur)) cur++; - } - xmlFree(dup); - break; - } - case XML_ATTRIBUTE_NOTATION: { - xmlNotationPtr nota; - - nota = xmlGetDtdNotationDesc(doc->intSubset, value); - if ((nota == NULL) && (doc->extSubset != NULL)) - nota = xmlGetDtdNotationDesc(doc->extSubset, value); - - if (nota == NULL) { - xmlErrValidNode(ctxt, (xmlNodePtr) doc, - XML_DTD_UNKNOWN_NOTATION, - "NOTATION attribute %s reference an unknown notation \"%s\"\n", - name, value, NULL); - ret = 0; - } - break; - } - } - return(ret); -} - -/** - * xmlValidCtxtNormalizeAttributeValue: - * @ctxt: the validation context - * @doc: the document - * @elem: the parent - * @name: the attribute name - * @value: the attribute value - * @ctxt: the validation context or NULL - * - * Does the validation related extra step of the normalization of attribute - * values: - * - * If the declared value is not CDATA, then the XML processor must further - * process the normalized attribute value by discarding any leading and - * trailing space (#x20) characters, and by replacing sequences of space - * (#x20) characters by single space (#x20) character. - * - * Also check VC: Standalone Document Declaration in P32, and update - * ctxt->valid accordingly - * - * returns a new normalized string if normalization is needed, NULL otherwise - * the caller must free the returned value. - */ - -xmlChar * -xmlValidCtxtNormalizeAttributeValue(xmlValidCtxtPtr ctxt, xmlDocPtr doc, - xmlNodePtr elem, const xmlChar *name, const xmlChar *value) { - xmlChar *ret, *dst; - const xmlChar *src; - xmlAttributePtr attrDecl = NULL; - int extsubset = 0; - - if (doc == NULL) return(NULL); - if (elem == NULL) return(NULL); - if (name == NULL) return(NULL); - if (value == NULL) return(NULL); - - if ((elem->ns != NULL) && (elem->ns->prefix != NULL)) { - xmlChar fn[50]; - xmlChar *fullname; - - fullname = xmlBuildQName(elem->name, elem->ns->prefix, fn, 50); - if (fullname == NULL) - return(NULL); - attrDecl = xmlGetDtdAttrDesc(doc->intSubset, fullname, name); - if ((attrDecl == NULL) && (doc->extSubset != NULL)) { - attrDecl = xmlGetDtdAttrDesc(doc->extSubset, fullname, name); - if (attrDecl != NULL) - extsubset = 1; - } - if ((fullname != fn) && (fullname != elem->name)) - xmlFree(fullname); - } - if ((attrDecl == NULL) && (doc->intSubset != NULL)) - attrDecl = xmlGetDtdAttrDesc(doc->intSubset, elem->name, name); - if ((attrDecl == NULL) && (doc->extSubset != NULL)) { - attrDecl = xmlGetDtdAttrDesc(doc->extSubset, elem->name, name); - if (attrDecl != NULL) - extsubset = 1; - } - - if (attrDecl == NULL) - return(NULL); - if (attrDecl->atype == XML_ATTRIBUTE_CDATA) - return(NULL); - - ret = xmlStrdup(value); - if (ret == NULL) - return(NULL); - src = value; - dst = ret; - while (*src == 0x20) src++; - while (*src != 0) { - if (*src == 0x20) { - while (*src == 0x20) src++; - if (*src != 0) - *dst++ = 0x20; - } else { - *dst++ = *src++; - } - } - *dst = 0; - if ((doc->standalone) && (extsubset == 1) && (!xmlStrEqual(value, ret))) { - xmlErrValidNode(ctxt, elem, XML_DTD_NOT_STANDALONE, -"standalone: %s on %s value had to be normalized based on external subset declaration\n", - name, elem->name, NULL); - ctxt->valid = 0; - } - return(ret); -} - -/** - * xmlValidNormalizeAttributeValue: - * @doc: the document - * @elem: the parent - * @name: the attribute name - * @value: the attribute value - * - * Does the validation related extra step of the normalization of attribute - * values: - * - * If the declared value is not CDATA, then the XML processor must further - * process the normalized attribute value by discarding any leading and - * trailing space (#x20) characters, and by replacing sequences of space - * (#x20) characters by single space (#x20) character. - * - * Returns a new normalized string if normalization is needed, NULL otherwise - * the caller must free the returned value. - */ - -xmlChar * -xmlValidNormalizeAttributeValue(xmlDocPtr doc, xmlNodePtr elem, - const xmlChar *name, const xmlChar *value) { - xmlChar *ret, *dst; - const xmlChar *src; - xmlAttributePtr attrDecl = NULL; - - if (doc == NULL) return(NULL); - if (elem == NULL) return(NULL); - if (name == NULL) return(NULL); - if (value == NULL) return(NULL); - - if ((elem->ns != NULL) && (elem->ns->prefix != NULL)) { - xmlChar fn[50]; - xmlChar *fullname; - - fullname = xmlBuildQName(elem->name, elem->ns->prefix, fn, 50); - if (fullname == NULL) - return(NULL); - if ((fullname != fn) && (fullname != elem->name)) - xmlFree(fullname); - } - attrDecl = xmlGetDtdAttrDesc(doc->intSubset, elem->name, name); - if ((attrDecl == NULL) && (doc->extSubset != NULL)) - attrDecl = xmlGetDtdAttrDesc(doc->extSubset, elem->name, name); - - if (attrDecl == NULL) - return(NULL); - if (attrDecl->atype == XML_ATTRIBUTE_CDATA) - return(NULL); - - ret = xmlStrdup(value); - if (ret == NULL) - return(NULL); - src = value; - dst = ret; - while (*src == 0x20) src++; - while (*src != 0) { - if (*src == 0x20) { - while (*src == 0x20) src++; - if (*src != 0) - *dst++ = 0x20; - } else { - *dst++ = *src++; - } - } - *dst = 0; - return(ret); -} - -static void -xmlValidateAttributeIdCallback(xmlAttributePtr attr, int *count, - const xmlChar* name ATTRIBUTE_UNUSED) { - if (attr->atype == XML_ATTRIBUTE_ID) (*count)++; -} - -/** - * xmlValidateAttributeDecl: - * @ctxt: the validation context - * @doc: a document instance - * @attr: an attribute definition - * - * Try to validate a single attribute definition - * basically it does the following checks as described by the - * XML-1.0 recommendation: - * - [ VC: Attribute Default Legal ] - * - [ VC: Enumeration ] - * - [ VC: ID Attribute Default ] - * - * The ID/IDREF uniqueness and matching are done separately - * - * returns 1 if valid or 0 otherwise - */ - -int -xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt, xmlDocPtr doc, - xmlAttributePtr attr) { - int ret = 1; - int val; - CHECK_DTD; - if(attr == NULL) return(1); - - /* Attribute Default Legal */ - /* Enumeration */ - if (attr->defaultValue != NULL) { - val = xmlValidateAttributeValueInternal(doc, attr->atype, - attr->defaultValue); - if (val == 0) { - xmlErrValidNode(ctxt, (xmlNodePtr) attr, XML_DTD_ATTRIBUTE_DEFAULT, - "Syntax of default value for attribute %s of %s is not valid\n", - attr->name, attr->elem, NULL); - } - ret &= val; - } - - /* ID Attribute Default */ - if ((attr->atype == XML_ATTRIBUTE_ID)&& - (attr->def != XML_ATTRIBUTE_IMPLIED) && - (attr->def != XML_ATTRIBUTE_REQUIRED)) { - xmlErrValidNode(ctxt, (xmlNodePtr) attr, XML_DTD_ID_FIXED, - "ID attribute %s of %s is not valid must be #IMPLIED or #REQUIRED\n", - attr->name, attr->elem, NULL); - ret = 0; - } - - /* One ID per Element Type */ - if (attr->atype == XML_ATTRIBUTE_ID) { - int nbId; - - /* the trick is that we parse DtD as their own internal subset */ - xmlElementPtr elem = xmlGetDtdElementDesc(doc->intSubset, - attr->elem); - if (elem != NULL) { - nbId = xmlScanIDAttributeDecl(NULL, elem, 0); - } else { - xmlAttributeTablePtr table; - - /* - * The attribute may be declared in the internal subset and the - * element in the external subset. - */ - nbId = 0; - if (doc->intSubset != NULL) { - table = (xmlAttributeTablePtr) doc->intSubset->attributes; - xmlHashScan3(table, NULL, NULL, attr->elem, (xmlHashScanner) - xmlValidateAttributeIdCallback, &nbId); - } - } - if (nbId > 1) { - - xmlErrValidNodeNr(ctxt, (xmlNodePtr) attr, XML_DTD_ID_SUBSET, - "Element %s has %d ID attribute defined in the internal subset : %s\n", - attr->elem, nbId, attr->name); - } else if (doc->extSubset != NULL) { - int extId = 0; - elem = xmlGetDtdElementDesc(doc->extSubset, attr->elem); - if (elem != NULL) { - extId = xmlScanIDAttributeDecl(NULL, elem, 0); - } - if (extId > 1) { - xmlErrValidNodeNr(ctxt, (xmlNodePtr) attr, XML_DTD_ID_SUBSET, - "Element %s has %d ID attribute defined in the external subset : %s\n", - attr->elem, extId, attr->name); - } else if (extId + nbId > 1) { - xmlErrValidNode(ctxt, (xmlNodePtr) attr, XML_DTD_ID_SUBSET, -"Element %s has ID attributes defined in the internal and external subset : %s\n", - attr->elem, attr->name, NULL); - } - } - } - - /* Validity Constraint: Enumeration */ - if ((attr->defaultValue != NULL) && (attr->tree != NULL)) { - xmlEnumerationPtr tree = attr->tree; - while (tree != NULL) { - if (xmlStrEqual(tree->name, attr->defaultValue)) break; - tree = tree->next; - } - if (tree == NULL) { - xmlErrValidNode(ctxt, (xmlNodePtr) attr, XML_DTD_ATTRIBUTE_VALUE, -"Default value \"%s\" for attribute %s of %s is not among the enumerated set\n", - attr->defaultValue, attr->name, attr->elem); - ret = 0; - } - } - - return(ret); -} - -/** - * xmlValidateElementDecl: - * @ctxt: the validation context - * @doc: a document instance - * @elem: an element definition - * - * Try to validate a single element definition - * basically it does the following checks as described by the - * XML-1.0 recommendation: - * - [ VC: One ID per Element Type ] - * - [ VC: No Duplicate Types ] - * - [ VC: Unique Element Type Declaration ] - * - * returns 1 if valid or 0 otherwise - */ - -int -xmlValidateElementDecl(xmlValidCtxtPtr ctxt, xmlDocPtr doc, - xmlElementPtr elem) { - int ret = 1; - xmlElementPtr tst; - - CHECK_DTD; - - if (elem == NULL) return(1); - - /* No Duplicate Types */ - if (elem->etype == XML_ELEMENT_TYPE_MIXED) { - xmlElementContentPtr cur, next; - const xmlChar *name; - - cur = elem->content; - while (cur != NULL) { - if (cur->type != XML_ELEMENT_CONTENT_OR) break; - if (cur->c1 == NULL) break; - if (cur->c1->type == XML_ELEMENT_CONTENT_ELEMENT) { - name = cur->c1->name; - next = cur->c2; - while (next != NULL) { - if (next->type == XML_ELEMENT_CONTENT_ELEMENT) { - if ((xmlStrEqual(next->name, name)) && - (xmlStrEqual(next->prefix, cur->c1->prefix))) { - if (cur->c1->prefix == NULL) { - xmlErrValidNode(ctxt, (xmlNodePtr) elem, XML_DTD_CONTENT_ERROR, - "Definition of %s has duplicate references of %s\n", - elem->name, name, NULL); - } else { - xmlErrValidNode(ctxt, (xmlNodePtr) elem, XML_DTD_CONTENT_ERROR, - "Definition of %s has duplicate references of %s:%s\n", - elem->name, cur->c1->prefix, name); - } - ret = 0; - } - break; - } - if (next->c1 == NULL) break; - if (next->c1->type != XML_ELEMENT_CONTENT_ELEMENT) break; - if ((xmlStrEqual(next->c1->name, name)) && - (xmlStrEqual(next->c1->prefix, cur->c1->prefix))) { - if (cur->c1->prefix == NULL) { - xmlErrValidNode(ctxt, (xmlNodePtr) elem, XML_DTD_CONTENT_ERROR, - "Definition of %s has duplicate references to %s\n", - elem->name, name, NULL); - } else { - xmlErrValidNode(ctxt, (xmlNodePtr) elem, XML_DTD_CONTENT_ERROR, - "Definition of %s has duplicate references to %s:%s\n", - elem->name, cur->c1->prefix, name); - } - ret = 0; - } - next = next->c2; - } - } - cur = cur->c2; - } - } - - /* VC: Unique Element Type Declaration */ - tst = xmlGetDtdElementDesc(doc->intSubset, elem->name); - if ((tst != NULL ) && (tst != elem) && - ((tst->prefix == elem->prefix) || - (xmlStrEqual(tst->prefix, elem->prefix))) && - (tst->etype != XML_ELEMENT_TYPE_UNDEFINED)) { - xmlErrValidNode(ctxt, (xmlNodePtr) elem, XML_DTD_ELEM_REDEFINED, - "Redefinition of element %s\n", - elem->name, NULL, NULL); - ret = 0; - } - tst = xmlGetDtdElementDesc(doc->extSubset, elem->name); - if ((tst != NULL ) && (tst != elem) && - ((tst->prefix == elem->prefix) || - (xmlStrEqual(tst->prefix, elem->prefix))) && - (tst->etype != XML_ELEMENT_TYPE_UNDEFINED)) { - xmlErrValidNode(ctxt, (xmlNodePtr) elem, XML_DTD_ELEM_REDEFINED, - "Redefinition of element %s\n", - elem->name, NULL, NULL); - ret = 0; - } - /* One ID per Element Type - * already done when registering the attribute - if (xmlScanIDAttributeDecl(ctxt, elem) > 1) { - ret = 0; - } */ - return(ret); -} - -/** - * xmlValidateOneAttribute: - * @ctxt: the validation context - * @doc: a document instance - * @elem: an element instance - * @attr: an attribute instance - * @value: the attribute value (without entities processing) - * - * Try to validate a single attribute for an element - * basically it does the following checks as described by the - * XML-1.0 recommendation: - * - [ VC: Attribute Value Type ] - * - [ VC: Fixed Attribute Default ] - * - [ VC: Entity Name ] - * - [ VC: Name Token ] - * - [ VC: ID ] - * - [ VC: IDREF ] - * - [ VC: Entity Name ] - * - [ VC: Notation Attributes ] - * - * The ID/IDREF uniqueness and matching are done separately - * - * returns 1 if valid or 0 otherwise - */ - -int -xmlValidateOneAttribute(xmlValidCtxtPtr ctxt, xmlDocPtr doc, - xmlNodePtr elem, xmlAttrPtr attr, const xmlChar *value) -{ - xmlAttributePtr attrDecl = NULL; - int val; - int ret = 1; - - CHECK_DTD; - if ((elem == NULL) || (elem->name == NULL)) return(0); - if ((attr == NULL) || (attr->name == NULL)) return(0); - - if ((elem->ns != NULL) && (elem->ns->prefix != NULL)) { - xmlChar fn[50]; - xmlChar *fullname; - - fullname = xmlBuildQName(elem->name, elem->ns->prefix, fn, 50); - if (fullname == NULL) - return(0); - if (attr->ns != NULL) { - attrDecl = xmlGetDtdQAttrDesc(doc->intSubset, fullname, - attr->name, attr->ns->prefix); - if ((attrDecl == NULL) && (doc->extSubset != NULL)) - attrDecl = xmlGetDtdQAttrDesc(doc->extSubset, fullname, - attr->name, attr->ns->prefix); - } else { - attrDecl = xmlGetDtdAttrDesc(doc->intSubset, fullname, attr->name); - if ((attrDecl == NULL) && (doc->extSubset != NULL)) - attrDecl = xmlGetDtdAttrDesc(doc->extSubset, - fullname, attr->name); - } - if ((fullname != fn) && (fullname != elem->name)) - xmlFree(fullname); - } - if (attrDecl == NULL) { - if (attr->ns != NULL) { - attrDecl = xmlGetDtdQAttrDesc(doc->intSubset, elem->name, - attr->name, attr->ns->prefix); - if ((attrDecl == NULL) && (doc->extSubset != NULL)) - attrDecl = xmlGetDtdQAttrDesc(doc->extSubset, elem->name, - attr->name, attr->ns->prefix); - } else { - attrDecl = xmlGetDtdAttrDesc(doc->intSubset, - elem->name, attr->name); - if ((attrDecl == NULL) && (doc->extSubset != NULL)) - attrDecl = xmlGetDtdAttrDesc(doc->extSubset, - elem->name, attr->name); - } - } - - - /* Validity Constraint: Attribute Value Type */ - if (attrDecl == NULL) { - xmlErrValidNode(ctxt, elem, XML_DTD_UNKNOWN_ATTRIBUTE, - "No declaration for attribute %s of element %s\n", - attr->name, elem->name, NULL); - return(0); - } - attr->atype = attrDecl->atype; - - val = xmlValidateAttributeValueInternal(doc, attrDecl->atype, value); - if (val == 0) { - xmlErrValidNode(ctxt, elem, XML_DTD_ATTRIBUTE_VALUE, - "Syntax of value for attribute %s of %s is not valid\n", - attr->name, elem->name, NULL); - ret = 0; - } - - /* Validity constraint: Fixed Attribute Default */ - if (attrDecl->def == XML_ATTRIBUTE_FIXED) { - if (!xmlStrEqual(value, attrDecl->defaultValue)) { - xmlErrValidNode(ctxt, elem, XML_DTD_ATTRIBUTE_DEFAULT, - "Value for attribute %s of %s is different from default \"%s\"\n", - attr->name, elem->name, attrDecl->defaultValue); - ret = 0; - } - } - - /* Validity Constraint: ID uniqueness */ - if (attrDecl->atype == XML_ATTRIBUTE_ID) { - if (xmlAddID(ctxt, doc, value, attr) == NULL) - ret = 0; - } - - if ((attrDecl->atype == XML_ATTRIBUTE_IDREF) || - (attrDecl->atype == XML_ATTRIBUTE_IDREFS)) { - if (xmlAddRef(ctxt, doc, value, attr) == NULL) - ret = 0; - } - - /* Validity Constraint: Notation Attributes */ - if (attrDecl->atype == XML_ATTRIBUTE_NOTATION) { - xmlEnumerationPtr tree = attrDecl->tree; - xmlNotationPtr nota; - - /* First check that the given NOTATION was declared */ - nota = xmlGetDtdNotationDesc(doc->intSubset, value); - if (nota == NULL) - nota = xmlGetDtdNotationDesc(doc->extSubset, value); - - if (nota == NULL) { - xmlErrValidNode(ctxt, elem, XML_DTD_UNKNOWN_NOTATION, - "Value \"%s\" for attribute %s of %s is not a declared Notation\n", - value, attr->name, elem->name); - ret = 0; - } - - /* Second, verify that it's among the list */ - while (tree != NULL) { - if (xmlStrEqual(tree->name, value)) break; - tree = tree->next; - } - if (tree == NULL) { - xmlErrValidNode(ctxt, elem, XML_DTD_NOTATION_VALUE, -"Value \"%s\" for attribute %s of %s is not among the enumerated notations\n", - value, attr->name, elem->name); - ret = 0; - } - } - - /* Validity Constraint: Enumeration */ - if (attrDecl->atype == XML_ATTRIBUTE_ENUMERATION) { - xmlEnumerationPtr tree = attrDecl->tree; - while (tree != NULL) { - if (xmlStrEqual(tree->name, value)) break; - tree = tree->next; - } - if (tree == NULL) { - xmlErrValidNode(ctxt, elem, XML_DTD_ATTRIBUTE_VALUE, - "Value \"%s\" for attribute %s of %s is not among the enumerated set\n", - value, attr->name, elem->name); - ret = 0; - } - } - - /* Fixed Attribute Default */ - if ((attrDecl->def == XML_ATTRIBUTE_FIXED) && - (!xmlStrEqual(attrDecl->defaultValue, value))) { - xmlErrValidNode(ctxt, elem, XML_DTD_ATTRIBUTE_VALUE, - "Value for attribute %s of %s must be \"%s\"\n", - attr->name, elem->name, attrDecl->defaultValue); - ret = 0; - } - - /* Extra check for the attribute value */ - ret &= xmlValidateAttributeValue2(ctxt, doc, attr->name, - attrDecl->atype, value); - - return(ret); -} - -/** - * xmlValidateOneNamespace: - * @ctxt: the validation context - * @doc: a document instance - * @elem: an element instance - * @prefix: the namespace prefix - * @ns: an namespace declaration instance - * @value: the attribute value (without entities processing) - * - * Try to validate a single namespace declaration for an element - * basically it does the following checks as described by the - * XML-1.0 recommendation: - * - [ VC: Attribute Value Type ] - * - [ VC: Fixed Attribute Default ] - * - [ VC: Entity Name ] - * - [ VC: Name Token ] - * - [ VC: ID ] - * - [ VC: IDREF ] - * - [ VC: Entity Name ] - * - [ VC: Notation Attributes ] - * - * The ID/IDREF uniqueness and matching are done separately - * - * returns 1 if valid or 0 otherwise - */ - -int -xmlValidateOneNamespace(xmlValidCtxtPtr ctxt, xmlDocPtr doc, -xmlNodePtr elem, const xmlChar *prefix, xmlNsPtr ns, const xmlChar *value) { - /* xmlElementPtr elemDecl; */ - xmlAttributePtr attrDecl = NULL; - int val; - int ret = 1; - - CHECK_DTD; - if ((elem == NULL) || (elem->name == NULL)) return(0); - if ((ns == NULL) || (ns->href == NULL)) return(0); - - if (prefix != NULL) { - xmlChar fn[50]; - xmlChar *fullname; - - fullname = xmlBuildQName(elem->name, prefix, fn, 50); - if (fullname == NULL) { - xmlVErrMemory(ctxt, "Validating namespace"); - return(0); - } - if (ns->prefix != NULL) { - attrDecl = xmlGetDtdQAttrDesc(doc->intSubset, fullname, - ns->prefix, BAD_CAST "xmlns"); - if ((attrDecl == NULL) && (doc->extSubset != NULL)) - attrDecl = xmlGetDtdQAttrDesc(doc->extSubset, fullname, - ns->prefix, BAD_CAST "xmlns"); - } else { - attrDecl = xmlGetDtdAttrDesc(doc->intSubset, fullname, - BAD_CAST "xmlns"); - if ((attrDecl == NULL) && (doc->extSubset != NULL)) - attrDecl = xmlGetDtdAttrDesc(doc->extSubset, fullname, - BAD_CAST "xmlns"); - } - if ((fullname != fn) && (fullname != elem->name)) - xmlFree(fullname); - } - if (attrDecl == NULL) { - if (ns->prefix != NULL) { - attrDecl = xmlGetDtdQAttrDesc(doc->intSubset, elem->name, - ns->prefix, BAD_CAST "xmlns"); - if ((attrDecl == NULL) && (doc->extSubset != NULL)) - attrDecl = xmlGetDtdQAttrDesc(doc->extSubset, elem->name, - ns->prefix, BAD_CAST "xmlns"); - } else { - attrDecl = xmlGetDtdAttrDesc(doc->intSubset, - elem->name, BAD_CAST "xmlns"); - if ((attrDecl == NULL) && (doc->extSubset != NULL)) - attrDecl = xmlGetDtdAttrDesc(doc->extSubset, - elem->name, BAD_CAST "xmlns"); - } - } - - - /* Validity Constraint: Attribute Value Type */ - if (attrDecl == NULL) { - if (ns->prefix != NULL) { - xmlErrValidNode(ctxt, elem, XML_DTD_UNKNOWN_ATTRIBUTE, - "No declaration for attribute xmlns:%s of element %s\n", - ns->prefix, elem->name, NULL); - } else { - xmlErrValidNode(ctxt, elem, XML_DTD_UNKNOWN_ATTRIBUTE, - "No declaration for attribute xmlns of element %s\n", - elem->name, NULL, NULL); - } - return(0); - } - - val = xmlValidateAttributeValueInternal(doc, attrDecl->atype, value); - if (val == 0) { - if (ns->prefix != NULL) { - xmlErrValidNode(ctxt, elem, XML_DTD_INVALID_DEFAULT, - "Syntax of value for attribute xmlns:%s of %s is not valid\n", - ns->prefix, elem->name, NULL); - } else { - xmlErrValidNode(ctxt, elem, XML_DTD_INVALID_DEFAULT, - "Syntax of value for attribute xmlns of %s is not valid\n", - elem->name, NULL, NULL); - } - ret = 0; - } - - /* Validity constraint: Fixed Attribute Default */ - if (attrDecl->def == XML_ATTRIBUTE_FIXED) { - if (!xmlStrEqual(value, attrDecl->defaultValue)) { - if (ns->prefix != NULL) { - xmlErrValidNode(ctxt, elem, XML_DTD_ATTRIBUTE_DEFAULT, - "Value for attribute xmlns:%s of %s is different from default \"%s\"\n", - ns->prefix, elem->name, attrDecl->defaultValue); - } else { - xmlErrValidNode(ctxt, elem, XML_DTD_ATTRIBUTE_DEFAULT, - "Value for attribute xmlns of %s is different from default \"%s\"\n", - elem->name, attrDecl->defaultValue, NULL); - } - ret = 0; - } - } - - /* Validity Constraint: ID uniqueness */ - if (attrDecl->atype == XML_ATTRIBUTE_ID) { - if (xmlAddID(ctxt, doc, value, (xmlAttrPtr) ns) == NULL) - ret = 0; - } - - if ((attrDecl->atype == XML_ATTRIBUTE_IDREF) || - (attrDecl->atype == XML_ATTRIBUTE_IDREFS)) { - if (xmlAddRef(ctxt, doc, value, (xmlAttrPtr) ns) == NULL) - ret = 0; - } - - /* Validity Constraint: Notation Attributes */ - if (attrDecl->atype == XML_ATTRIBUTE_NOTATION) { - xmlEnumerationPtr tree = attrDecl->tree; - xmlNotationPtr nota; - - /* First check that the given NOTATION was declared */ - nota = xmlGetDtdNotationDesc(doc->intSubset, value); - if (nota == NULL) - nota = xmlGetDtdNotationDesc(doc->extSubset, value); - - if (nota == NULL) { - if (ns->prefix != NULL) { - xmlErrValidNode(ctxt, elem, XML_DTD_UNKNOWN_NOTATION, - "Value \"%s\" for attribute xmlns:%s of %s is not a declared Notation\n", - value, ns->prefix, elem->name); - } else { - xmlErrValidNode(ctxt, elem, XML_DTD_UNKNOWN_NOTATION, - "Value \"%s\" for attribute xmlns of %s is not a declared Notation\n", - value, elem->name, NULL); - } - ret = 0; - } - - /* Second, verify that it's among the list */ - while (tree != NULL) { - if (xmlStrEqual(tree->name, value)) break; - tree = tree->next; - } - if (tree == NULL) { - if (ns->prefix != NULL) { - xmlErrValidNode(ctxt, elem, XML_DTD_NOTATION_VALUE, -"Value \"%s\" for attribute xmlns:%s of %s is not among the enumerated notations\n", - value, ns->prefix, elem->name); - } else { - xmlErrValidNode(ctxt, elem, XML_DTD_NOTATION_VALUE, -"Value \"%s\" for attribute xmlns of %s is not among the enumerated notations\n", - value, elem->name, NULL); - } - ret = 0; - } - } - - /* Validity Constraint: Enumeration */ - if (attrDecl->atype == XML_ATTRIBUTE_ENUMERATION) { - xmlEnumerationPtr tree = attrDecl->tree; - while (tree != NULL) { - if (xmlStrEqual(tree->name, value)) break; - tree = tree->next; - } - if (tree == NULL) { - if (ns->prefix != NULL) { - xmlErrValidNode(ctxt, elem, XML_DTD_ATTRIBUTE_VALUE, -"Value \"%s\" for attribute xmlns:%s of %s is not among the enumerated set\n", - value, ns->prefix, elem->name); - } else { - xmlErrValidNode(ctxt, elem, XML_DTD_ATTRIBUTE_VALUE, -"Value \"%s\" for attribute xmlns of %s is not among the enumerated set\n", - value, elem->name, NULL); - } - ret = 0; - } - } - - /* Fixed Attribute Default */ - if ((attrDecl->def == XML_ATTRIBUTE_FIXED) && - (!xmlStrEqual(attrDecl->defaultValue, value))) { - if (ns->prefix != NULL) { - xmlErrValidNode(ctxt, elem, XML_DTD_ELEM_NAMESPACE, - "Value for attribute xmlns:%s of %s must be \"%s\"\n", - ns->prefix, elem->name, attrDecl->defaultValue); - } else { - xmlErrValidNode(ctxt, elem, XML_DTD_ELEM_NAMESPACE, - "Value for attribute xmlns of %s must be \"%s\"\n", - elem->name, attrDecl->defaultValue, NULL); - } - ret = 0; - } - - /* Extra check for the attribute value */ - if (ns->prefix != NULL) { - ret &= xmlValidateAttributeValue2(ctxt, doc, ns->prefix, - attrDecl->atype, value); - } else { - ret &= xmlValidateAttributeValue2(ctxt, doc, BAD_CAST "xmlns", - attrDecl->atype, value); - } - - return(ret); -} - -/** - * xmlValidateSkipIgnorable: - * @ctxt: the validation context - * @child: the child list - * - * Skip ignorable elements w.r.t. the validation process - * - * returns the first element to consider for validation of the content model - */ - -static xmlNodePtr -xmlValidateSkipIgnorable(xmlNodePtr child) { - while (child != NULL) { - switch (child->type) { - /* These things are ignored (skipped) during validation. */ - case XML_PI_NODE: - case XML_COMMENT_NODE: - case XML_XINCLUDE_START: - case XML_XINCLUDE_END: - child = child->next; - break; - case XML_TEXT_NODE: - if (xmlIsBlankNode(child)) - child = child->next; - else - return(child); - break; - /* keep current node */ - default: - return(child); - } - } - return(child); -} - -/** - * xmlValidateElementType: - * @ctxt: the validation context - * - * Try to validate the content model of an element internal function - * - * returns 1 if valid or 0 ,-1 in case of error, -2 if an entity - * reference is found and -3 if the validation succeeded but - * the content model is not determinist. - */ - -static int -xmlValidateElementType(xmlValidCtxtPtr ctxt) { - int ret = -1; - int determinist = 1; - - NODE = xmlValidateSkipIgnorable(NODE); - if ((NODE == NULL) && (CONT == NULL)) - return(1); - if ((NODE == NULL) && - ((CONT->ocur == XML_ELEMENT_CONTENT_MULT) || - (CONT->ocur == XML_ELEMENT_CONTENT_OPT))) { - return(1); - } - if (CONT == NULL) return(-1); - if ((NODE != NULL) && (NODE->type == XML_ENTITY_REF_NODE)) - return(-2); - - /* - * We arrive here when more states need to be examined - */ -cont: - - /* - * We just recovered from a rollback generated by a possible - * epsilon transition, go directly to the analysis phase - */ - if (STATE == ROLLBACK_PARENT) { - DEBUG_VALID_MSG("restored parent branch"); - DEBUG_VALID_STATE(NODE, CONT) - ret = 1; - goto analyze; - } - - DEBUG_VALID_STATE(NODE, CONT) - /* - * we may have to save a backup state here. This is the equivalent - * of handling epsilon transition in NFAs. - */ - if ((CONT != NULL) && - ((CONT->parent == NULL) || - (CONT->parent->type != XML_ELEMENT_CONTENT_OR)) && - ((CONT->ocur == XML_ELEMENT_CONTENT_MULT) || - (CONT->ocur == XML_ELEMENT_CONTENT_OPT) || - ((CONT->ocur == XML_ELEMENT_CONTENT_PLUS) && (OCCURRENCE)))) { - DEBUG_VALID_MSG("saving parent branch"); - if (vstateVPush(ctxt, CONT, NODE, DEPTH, OCCURS, ROLLBACK_PARENT) < 0) - return(0); - } - - - /* - * Check first if the content matches - */ - switch (CONT->type) { - case XML_ELEMENT_CONTENT_PCDATA: - if (NODE == NULL) { - DEBUG_VALID_MSG("pcdata failed no node"); - ret = 0; - break; - } - if (NODE->type == XML_TEXT_NODE) { - DEBUG_VALID_MSG("pcdata found, skip to next"); - /* - * go to next element in the content model - * skipping ignorable elems - */ - do { - NODE = NODE->next; - NODE = xmlValidateSkipIgnorable(NODE); - if ((NODE != NULL) && - (NODE->type == XML_ENTITY_REF_NODE)) - return(-2); - } while ((NODE != NULL) && - ((NODE->type != XML_ELEMENT_NODE) && - (NODE->type != XML_TEXT_NODE) && - (NODE->type != XML_CDATA_SECTION_NODE))); - ret = 1; - break; - } else { - DEBUG_VALID_MSG("pcdata failed"); - ret = 0; - break; - } - break; - case XML_ELEMENT_CONTENT_ELEMENT: - if (NODE == NULL) { - DEBUG_VALID_MSG("element failed no node"); - ret = 0; - break; - } - ret = ((NODE->type == XML_ELEMENT_NODE) && - (xmlStrEqual(NODE->name, CONT->name))); - if (ret == 1) { - if ((NODE->ns == NULL) || (NODE->ns->prefix == NULL)) { - ret = (CONT->prefix == NULL); - } else if (CONT->prefix == NULL) { - ret = 0; - } else { - ret = xmlStrEqual(NODE->ns->prefix, CONT->prefix); - } - } - if (ret == 1) { - DEBUG_VALID_MSG("element found, skip to next"); - /* - * go to next element in the content model - * skipping ignorable elems - */ - do { - NODE = NODE->next; - NODE = xmlValidateSkipIgnorable(NODE); - if ((NODE != NULL) && - (NODE->type == XML_ENTITY_REF_NODE)) - return(-2); - } while ((NODE != NULL) && - ((NODE->type != XML_ELEMENT_NODE) && - (NODE->type != XML_TEXT_NODE) && - (NODE->type != XML_CDATA_SECTION_NODE))); - } else { - DEBUG_VALID_MSG("element failed"); - ret = 0; - break; - } - break; - case XML_ELEMENT_CONTENT_OR: - /* - * Small optimization. - */ - if (CONT->c1->type == XML_ELEMENT_CONTENT_ELEMENT) { - if ((NODE == NULL) || - (!xmlStrEqual(NODE->name, CONT->c1->name))) { - DEPTH++; - CONT = CONT->c2; - goto cont; - } - if ((NODE->ns == NULL) || (NODE->ns->prefix == NULL)) { - ret = (CONT->c1->prefix == NULL); - } else if (CONT->c1->prefix == NULL) { - ret = 0; - } else { - ret = xmlStrEqual(NODE->ns->prefix, CONT->c1->prefix); - } - if (ret == 0) { - DEPTH++; - CONT = CONT->c2; - goto cont; - } - } - - /* - * save the second branch 'or' branch - */ - DEBUG_VALID_MSG("saving 'or' branch"); - if (vstateVPush(ctxt, CONT->c2, NODE, (unsigned char)(DEPTH + 1), - OCCURS, ROLLBACK_OR) < 0) - return(-1); - DEPTH++; - CONT = CONT->c1; - goto cont; - case XML_ELEMENT_CONTENT_SEQ: - /* - * Small optimization. - */ - if ((CONT->c1->type == XML_ELEMENT_CONTENT_ELEMENT) && - ((CONT->c1->ocur == XML_ELEMENT_CONTENT_OPT) || - (CONT->c1->ocur == XML_ELEMENT_CONTENT_MULT))) { - if ((NODE == NULL) || - (!xmlStrEqual(NODE->name, CONT->c1->name))) { - DEPTH++; - CONT = CONT->c2; - goto cont; - } - if ((NODE->ns == NULL) || (NODE->ns->prefix == NULL)) { - ret = (CONT->c1->prefix == NULL); - } else if (CONT->c1->prefix == NULL) { - ret = 0; - } else { - ret = xmlStrEqual(NODE->ns->prefix, CONT->c1->prefix); - } - if (ret == 0) { - DEPTH++; - CONT = CONT->c2; - goto cont; - } - } - DEPTH++; - CONT = CONT->c1; - goto cont; - } - - /* - * At this point handle going up in the tree - */ - if (ret == -1) { - DEBUG_VALID_MSG("error found returning"); - return(ret); - } -analyze: - while (CONT != NULL) { - /* - * First do the analysis depending on the occurrence model at - * this level. - */ - if (ret == 0) { - switch (CONT->ocur) { - xmlNodePtr cur; - - case XML_ELEMENT_CONTENT_ONCE: - cur = ctxt->vstate->node; - DEBUG_VALID_MSG("Once branch failed, rollback"); - if (vstateVPop(ctxt) < 0 ) { - DEBUG_VALID_MSG("exhaustion, failed"); - return(0); - } - if (cur != ctxt->vstate->node) - determinist = -3; - goto cont; - case XML_ELEMENT_CONTENT_PLUS: - if (OCCURRENCE == 0) { - cur = ctxt->vstate->node; - DEBUG_VALID_MSG("Plus branch failed, rollback"); - if (vstateVPop(ctxt) < 0 ) { - DEBUG_VALID_MSG("exhaustion, failed"); - return(0); - } - if (cur != ctxt->vstate->node) - determinist = -3; - goto cont; - } - DEBUG_VALID_MSG("Plus branch found"); - ret = 1; - break; - case XML_ELEMENT_CONTENT_MULT: -#ifdef DEBUG_VALID_ALGO - if (OCCURRENCE == 0) { - DEBUG_VALID_MSG("Mult branch failed"); - } else { - DEBUG_VALID_MSG("Mult branch found"); - } -#endif - ret = 1; - break; - case XML_ELEMENT_CONTENT_OPT: - DEBUG_VALID_MSG("Option branch failed"); - ret = 1; - break; - } - } else { - switch (CONT->ocur) { - case XML_ELEMENT_CONTENT_OPT: - DEBUG_VALID_MSG("Option branch succeeded"); - ret = 1; - break; - case XML_ELEMENT_CONTENT_ONCE: - DEBUG_VALID_MSG("Once branch succeeded"); - ret = 1; - break; - case XML_ELEMENT_CONTENT_PLUS: - if (STATE == ROLLBACK_PARENT) { - DEBUG_VALID_MSG("Plus branch rollback"); - ret = 1; - break; - } - if (NODE == NULL) { - DEBUG_VALID_MSG("Plus branch exhausted"); - ret = 1; - break; - } - DEBUG_VALID_MSG("Plus branch succeeded, continuing"); - SET_OCCURRENCE; - goto cont; - case XML_ELEMENT_CONTENT_MULT: - if (STATE == ROLLBACK_PARENT) { - DEBUG_VALID_MSG("Mult branch rollback"); - ret = 1; - break; - } - if (NODE == NULL) { - DEBUG_VALID_MSG("Mult branch exhausted"); - ret = 1; - break; - } - DEBUG_VALID_MSG("Mult branch succeeded, continuing"); - /* SET_OCCURRENCE; */ - goto cont; - } - } - STATE = 0; - - /* - * Then act accordingly at the parent level - */ - RESET_OCCURRENCE; - if (CONT->parent == NULL) - break; - - switch (CONT->parent->type) { - case XML_ELEMENT_CONTENT_PCDATA: - DEBUG_VALID_MSG("Error: parent pcdata"); - return(-1); - case XML_ELEMENT_CONTENT_ELEMENT: - DEBUG_VALID_MSG("Error: parent element"); - return(-1); - case XML_ELEMENT_CONTENT_OR: - if (ret == 1) { - DEBUG_VALID_MSG("Or succeeded"); - CONT = CONT->parent; - DEPTH--; - } else { - DEBUG_VALID_MSG("Or failed"); - CONT = CONT->parent; - DEPTH--; - } - break; - case XML_ELEMENT_CONTENT_SEQ: - if (ret == 0) { - DEBUG_VALID_MSG("Sequence failed"); - CONT = CONT->parent; - DEPTH--; - } else if (CONT == CONT->parent->c1) { - DEBUG_VALID_MSG("Sequence testing 2nd branch"); - CONT = CONT->parent->c2; - goto cont; - } else { - DEBUG_VALID_MSG("Sequence succeeded"); - CONT = CONT->parent; - DEPTH--; - } - } - } - if (NODE != NULL) { - xmlNodePtr cur; - - cur = ctxt->vstate->node; - DEBUG_VALID_MSG("Failed, remaining input, rollback"); - if (vstateVPop(ctxt) < 0 ) { - DEBUG_VALID_MSG("exhaustion, failed"); - return(0); - } - if (cur != ctxt->vstate->node) - determinist = -3; - goto cont; - } - if (ret == 0) { - xmlNodePtr cur; - - cur = ctxt->vstate->node; - DEBUG_VALID_MSG("Failure, rollback"); - if (vstateVPop(ctxt) < 0 ) { - DEBUG_VALID_MSG("exhaustion, failed"); - return(0); - } - if (cur != ctxt->vstate->node) - determinist = -3; - goto cont; - } - return(determinist); -} - -/** - * xmlSnprintfElements: - * @buf: an output buffer - * @size: the size of the buffer - * @content: An element - * @glob: 1 if one must print the englobing parenthesis, 0 otherwise - * - * This will dump the list of elements to the buffer - * Intended just for the debug routine - */ -static void -xmlSnprintfElements(char *buf, int size, xmlNodePtr node, int glob) { - xmlNodePtr cur; - int len; - - if (node == NULL) return; - if (glob) strcat(buf, "("); - cur = node; - while (cur != NULL) { - len = strlen(buf); - if (size - len < 50) { - if ((size - len > 4) && (buf[len - 1] != '.')) - strcat(buf, " ..."); - return; - } - switch (cur->type) { - case XML_ELEMENT_NODE: - if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) { - if (size - len < xmlStrlen(cur->ns->prefix) + 10) { - if ((size - len > 4) && (buf[len - 1] != '.')) - strcat(buf, " ..."); - return; - } - strcat(buf, (char *) cur->ns->prefix); - strcat(buf, ":"); - } - if (size - len < xmlStrlen(cur->name) + 10) { - if ((size - len > 4) && (buf[len - 1] != '.')) - strcat(buf, " ..."); - return; - } - strcat(buf, (char *) cur->name); - if (cur->next != NULL) - strcat(buf, " "); - break; - case XML_TEXT_NODE: - if (xmlIsBlankNode(cur)) - break; - case XML_CDATA_SECTION_NODE: - case XML_ENTITY_REF_NODE: - strcat(buf, "CDATA"); - if (cur->next != NULL) - strcat(buf, " "); - break; - case XML_ATTRIBUTE_NODE: - case XML_DOCUMENT_NODE: - case XML_HTML_DOCUMENT_NODE: - case XML_DOCUMENT_TYPE_NODE: - case XML_DOCUMENT_FRAG_NODE: - case XML_NOTATION_NODE: - case XML_NAMESPACE_DECL: - strcat(buf, "???"); - if (cur->next != NULL) - strcat(buf, " "); - break; - case XML_ENTITY_NODE: - case XML_PI_NODE: - case XML_DTD_NODE: - case XML_COMMENT_NODE: - case XML_ELEMENT_DECL: - case XML_ATTRIBUTE_DECL: - case XML_ENTITY_DECL: - case XML_XINCLUDE_START: - case XML_XINCLUDE_END: - break; - } - cur = cur->next; - } - if (glob) strcat(buf, ")"); -} - -/** - * xmlValidateElementContent: - * @ctxt: the validation context - * @child: the child list - * @elemDecl: pointer to the element declaration - * @warn: emit the error message - * @parent: the parent element (for error reporting) - * - * Try to validate the content model of an element - * - * returns 1 if valid or 0 if not and -1 in case of error - */ - -static int -xmlValidateElementContent(xmlValidCtxtPtr ctxt, xmlNodePtr child, - xmlElementPtr elemDecl, int warn, xmlNodePtr parent) { - int ret = 1; - xmlNodePtr repl = NULL, last = NULL, tmp; - xmlNodePtr cur; - xmlElementContentPtr cont; - const xmlChar *name; - - if (elemDecl == NULL) - return(-1); - cont = elemDecl->content; - name = elemDecl->name; - - /* - * Allocate the stack - */ - ctxt->vstateMax = 8; - ctxt->vstateTab = (xmlValidState *) xmlMalloc( - ctxt->vstateMax * sizeof(ctxt->vstateTab[0])); - if (ctxt->vstateTab == NULL) { - xmlVErrMemory(ctxt, "malloc failed"); - return(-1); - } - /* - * The first entry in the stack is reserved to the current state - */ - ctxt->nodeMax = 0; - ctxt->nodeNr = 0; - ctxt->nodeTab = NULL; - ctxt->vstate = &ctxt->vstateTab[0]; - ctxt->vstateNr = 1; - CONT = cont; - NODE = child; - DEPTH = 0; - OCCURS = 0; - STATE = 0; - ret = xmlValidateElementType(ctxt); - if ((ret == -3) && (warn)) { - xmlErrValidWarning(ctxt, child, XML_DTD_CONTENT_NOT_DETERMINIST, - "Content model for Element %s is ambiguous\n", - name, NULL, NULL); - } else if (ret == -2) { - /* - * An entities reference appeared at this level. - * Buid a minimal representation of this node content - * sufficient to run the validation process on it - */ - DEBUG_VALID_MSG("Found an entity reference, linearizing"); - cur = child; - while (cur != NULL) { - switch (cur->type) { - case XML_ENTITY_REF_NODE: - /* - * Push the current node to be able to roll back - * and process within the entity - */ - if ((cur->children != NULL) && - (cur->children->children != NULL)) { - nodeVPush(ctxt, cur); - cur = cur->children->children; - continue; - } - break; - case XML_TEXT_NODE: - if (xmlIsBlankNode(cur)) - break; - /* no break on purpose */ - case XML_CDATA_SECTION_NODE: - /* no break on purpose */ - case XML_ELEMENT_NODE: - /* - * Allocate a new node and minimally fills in - * what's required - */ - tmp = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); - if (tmp == NULL) { - xmlVErrMemory(ctxt, "malloc failed"); - xmlFreeNodeList(repl); - ret = -1; - goto done; - } - tmp->type = cur->type; - tmp->name = cur->name; - tmp->ns = cur->ns; - tmp->next = NULL; - tmp->content = NULL; - if (repl == NULL) - repl = last = tmp; - else { - last->next = tmp; - last = tmp; - } - if (cur->type == XML_CDATA_SECTION_NODE) { - /* - * E59 spaces in CDATA does not match the - * nonterminal S - */ - tmp->content = xmlStrdup(BAD_CAST "CDATA"); - } - break; - default: - break; - } - /* - * Switch to next element - */ - cur = cur->next; - while (cur == NULL) { - cur = nodeVPop(ctxt); - if (cur == NULL) - break; - cur = cur->next; - } - } - - /* - * Relaunch the validation - */ - ctxt->vstate = &ctxt->vstateTab[0]; - ctxt->vstateNr = 1; - CONT = cont; - NODE = repl; - DEPTH = 0; - OCCURS = 0; - STATE = 0; - ret = xmlValidateElementType(ctxt); - } - if ((warn) && ((ret != 1) && (ret != -3))) { - if (ctxt != NULL) { - char expr[5000]; - char list[5000]; - - expr[0] = 0; - xmlSnprintfElementContent(&expr[0], 5000, cont, 1); - list[0] = 0; - if (repl != NULL) - xmlSnprintfElements(&list[0], 5000, repl, 1); - else - xmlSnprintfElements(&list[0], 5000, child, 1); - - if (name != NULL) { - xmlErrValidNode(ctxt, parent, XML_DTD_CONTENT_MODEL, - "Element %s content does not follow the DTD, expecting %s, got %s\n", - name, BAD_CAST expr, BAD_CAST list); - } else { - xmlErrValidNode(ctxt, parent, XML_DTD_CONTENT_MODEL, - "Element content does not follow the DTD, expecting %s, got %s\n", - BAD_CAST expr, BAD_CAST list, NULL); - } - } else { - if (name != NULL) { - xmlErrValidNode(ctxt, parent, XML_DTD_CONTENT_MODEL, - "Element %s content does not follow the DTD\n", - name, NULL, NULL); - } else { - xmlErrValidNode(ctxt, parent, XML_DTD_CONTENT_MODEL, - "Element content does not follow the DTD\n", - NULL, NULL, NULL); - } - } - ret = 0; - } - if (ret == -3) - ret = 1; - -done: - /* - * Deallocate the copy if done, and free up the validation stack - */ - while (repl != NULL) { - tmp = repl->next; - xmlFree(repl); - repl = tmp; - } - ctxt->vstateMax = 0; - if (ctxt->vstateTab != NULL) { - xmlFree(ctxt->vstateTab); - ctxt->vstateTab = NULL; - } - ctxt->nodeMax = 0; - ctxt->nodeNr = 0; - if (ctxt->nodeTab != NULL) { - xmlFree(ctxt->nodeTab); - ctxt->nodeTab = NULL; - } - return(ret); - -} - -/** - * xmlValidateCdataElement: - * @ctxt: the validation context - * @doc: a document instance - * @elem: an element instance - * - * Check that an element follows #CDATA - * - * returns 1 if valid or 0 otherwise - */ -static int -xmlValidateOneCdataElement(xmlValidCtxtPtr ctxt, xmlDocPtr doc, - xmlNodePtr elem) { - int ret = 1; - xmlNodePtr cur, child; - - if ((ctxt == NULL) || (doc == NULL) || (elem == NULL)) - return(0); - - child = elem->children; - - cur = child; - while (cur != NULL) { - switch (cur->type) { - case XML_ENTITY_REF_NODE: - /* - * Push the current node to be able to roll back - * and process within the entity - */ - if ((cur->children != NULL) && - (cur->children->children != NULL)) { - nodeVPush(ctxt, cur); - cur = cur->children->children; - continue; - } - break; - case XML_COMMENT_NODE: - case XML_PI_NODE: - case XML_TEXT_NODE: - case XML_CDATA_SECTION_NODE: - break; - default: - ret = 0; - goto done; - } - /* - * Switch to next element - */ - cur = cur->next; - while (cur == NULL) { - cur = nodeVPop(ctxt); - if (cur == NULL) - break; - cur = cur->next; - } - } -done: - ctxt->nodeMax = 0; - ctxt->nodeNr = 0; - if (ctxt->nodeTab != NULL) { - xmlFree(ctxt->nodeTab); - ctxt->nodeTab = NULL; - } - return(ret); -} - -/** - * xmlValidateCheckMixed: - * @ctxt: the validation context - * @cont: the mixed content model - * @qname: the qualified name as appearing in the serialization - * - * Check if the given node is part of the content model. - * - * Returns 1 if yes, 0 if no, -1 in case of error - */ -static int -xmlValidateCheckMixed(xmlValidCtxtPtr ctxt, - xmlElementContentPtr cont, const xmlChar *qname) { - const xmlChar *name; - int plen; - name = xmlSplitQName3(qname, &plen); - - if (name == NULL) { - while (cont != NULL) { - if (cont->type == XML_ELEMENT_CONTENT_ELEMENT) { - if ((cont->prefix == NULL) && (xmlStrEqual(cont->name, qname))) - return(1); - } else if ((cont->type == XML_ELEMENT_CONTENT_OR) && - (cont->c1 != NULL) && - (cont->c1->type == XML_ELEMENT_CONTENT_ELEMENT)){ - if ((cont->c1->prefix == NULL) && - (xmlStrEqual(cont->c1->name, qname))) - return(1); - } else if ((cont->type != XML_ELEMENT_CONTENT_OR) || - (cont->c1 == NULL) || - (cont->c1->type != XML_ELEMENT_CONTENT_PCDATA)){ - xmlErrValid(NULL, XML_DTD_MIXED_CORRUPT, - "Internal: MIXED struct corrupted\n", - NULL); - break; - } - cont = cont->c2; - } - } else { - while (cont != NULL) { - if (cont->type == XML_ELEMENT_CONTENT_ELEMENT) { - if ((cont->prefix != NULL) && - (xmlStrncmp(cont->prefix, qname, plen) == 0) && - (xmlStrEqual(cont->name, name))) - return(1); - } else if ((cont->type == XML_ELEMENT_CONTENT_OR) && - (cont->c1 != NULL) && - (cont->c1->type == XML_ELEMENT_CONTENT_ELEMENT)){ - if ((cont->c1->prefix != NULL) && - (xmlStrncmp(cont->c1->prefix, qname, plen) == 0) && - (xmlStrEqual(cont->c1->name, name))) - return(1); - } else if ((cont->type != XML_ELEMENT_CONTENT_OR) || - (cont->c1 == NULL) || - (cont->c1->type != XML_ELEMENT_CONTENT_PCDATA)){ - xmlErrValid(ctxt, XML_DTD_MIXED_CORRUPT, - "Internal: MIXED struct corrupted\n", - NULL); - break; - } - cont = cont->c2; - } - } - return(0); -} - -/** - * xmlValidGetElemDecl: - * @ctxt: the validation context - * @doc: a document instance - * @elem: an element instance - * @extsubset: pointer, (out) indicate if the declaration was found - * in the external subset. - * - * Finds a declaration associated to an element in the document. - * - * returns the pointer to the declaration or NULL if not found. - */ -static xmlElementPtr -xmlValidGetElemDecl(xmlValidCtxtPtr ctxt, xmlDocPtr doc, - xmlNodePtr elem, int *extsubset) { - xmlElementPtr elemDecl = NULL; - const xmlChar *prefix = NULL; - - if ((ctxt == NULL) || (doc == NULL) || - (elem == NULL) || (elem->name == NULL)) - return(NULL); - if (extsubset != NULL) - *extsubset = 0; - - /* - * Fetch the declaration for the qualified name - */ - if ((elem->ns != NULL) && (elem->ns->prefix != NULL)) - prefix = elem->ns->prefix; - - if (prefix != NULL) { - elemDecl = xmlGetDtdQElementDesc(doc->intSubset, - elem->name, prefix); - if ((elemDecl == NULL) && (doc->extSubset != NULL)) { - elemDecl = xmlGetDtdQElementDesc(doc->extSubset, - elem->name, prefix); - if ((elemDecl != NULL) && (extsubset != NULL)) - *extsubset = 1; - } - } - - /* - * Fetch the declaration for the non qualified name - * This is "non-strict" validation should be done on the - * full QName but in that case being flexible makes sense. - */ - if (elemDecl == NULL) { - elemDecl = xmlGetDtdElementDesc(doc->intSubset, elem->name); - if ((elemDecl == NULL) && (doc->extSubset != NULL)) { - elemDecl = xmlGetDtdElementDesc(doc->extSubset, elem->name); - if ((elemDecl != NULL) && (extsubset != NULL)) - *extsubset = 1; - } - } - if (elemDecl == NULL) { - xmlErrValidNode(ctxt, elem, - XML_DTD_UNKNOWN_ELEM, - "No declaration for element %s\n", - elem->name, NULL, NULL); - } - return(elemDecl); -} - -/** - * xmlValidateOneElement: - * @ctxt: the validation context - * @doc: a document instance - * @elem: an element instance - * - * Try to validate a single element and it's attributes, - * basically it does the following checks as described by the - * XML-1.0 recommendation: - * - [ VC: Element Valid ] - * - [ VC: Required Attribute ] - * Then call xmlValidateOneAttribute() for each attribute present. - * - * The ID/IDREF checkings are done separately - * - * returns 1 if valid or 0 otherwise - */ - -int -xmlValidateOneElement(xmlValidCtxtPtr ctxt, xmlDocPtr doc, - xmlNodePtr elem) { - xmlElementPtr elemDecl = NULL; - xmlElementContentPtr cont; - xmlAttributePtr attr; - xmlNodePtr child; - int ret = 1, tmp; - const xmlChar *name; - int extsubset = 0; - - CHECK_DTD; - - if (elem == NULL) return(0); - switch (elem->type) { - case XML_ATTRIBUTE_NODE: - xmlErrValidNode(ctxt, elem, XML_ERR_INTERNAL_ERROR, - "Attribute element not expected\n", NULL, NULL ,NULL); - return(0); - case XML_TEXT_NODE: - if (elem->children != NULL) { - xmlErrValidNode(ctxt, elem, XML_ERR_INTERNAL_ERROR, - "Text element has children !\n", - NULL,NULL,NULL); - return(0); - } - if (elem->ns != NULL) { - xmlErrValidNode(ctxt, elem, XML_ERR_INTERNAL_ERROR, - "Text element has namespace !\n", - NULL,NULL,NULL); - return(0); - } - if (elem->content == NULL) { - xmlErrValidNode(ctxt, elem, XML_ERR_INTERNAL_ERROR, - "Text element has no content !\n", - NULL,NULL,NULL); - return(0); - } - return(1); - case XML_XINCLUDE_START: - case XML_XINCLUDE_END: - return(1); - case XML_CDATA_SECTION_NODE: - case XML_ENTITY_REF_NODE: - case XML_PI_NODE: - case XML_COMMENT_NODE: - return(1); - case XML_ENTITY_NODE: - xmlErrValidNode(ctxt, elem, XML_ERR_INTERNAL_ERROR, - "Entity element not expected\n", NULL, NULL ,NULL); - return(0); - case XML_NOTATION_NODE: - xmlErrValidNode(ctxt, elem, XML_ERR_INTERNAL_ERROR, - "Notation element not expected\n", NULL, NULL ,NULL); - return(0); - case XML_DOCUMENT_NODE: - case XML_DOCUMENT_TYPE_NODE: - case XML_DOCUMENT_FRAG_NODE: - xmlErrValidNode(ctxt, elem, XML_ERR_INTERNAL_ERROR, - "Document element not expected\n", NULL, NULL ,NULL); - return(0); - case XML_HTML_DOCUMENT_NODE: - xmlErrValidNode(ctxt, elem, XML_ERR_INTERNAL_ERROR, - "HTML Document not expected\n", NULL, NULL ,NULL); - return(0); - case XML_ELEMENT_NODE: - break; - default: - xmlErrValidNode(ctxt, elem, XML_ERR_INTERNAL_ERROR, - "unknown element type\n", NULL, NULL ,NULL); - return(0); - } - - /* - * Fetch the declaration - */ - elemDecl = xmlValidGetElemDecl(ctxt, doc, elem, &extsubset); - if (elemDecl == NULL) - return(0); - - /* - * If vstateNr is not zero that means continuous validation is - * activated, do not try to check the content model at that level. - */ - if (ctxt->vstateNr == 0) { - /* Check that the element content matches the definition */ - switch (elemDecl->etype) { - case XML_ELEMENT_TYPE_UNDEFINED: - xmlErrValidNode(ctxt, elem, XML_DTD_UNKNOWN_ELEM, - "No declaration for element %s\n", - elem->name, NULL, NULL); - return(0); - case XML_ELEMENT_TYPE_EMPTY: - if (elem->children != NULL) { - xmlErrValidNode(ctxt, elem, XML_DTD_NOT_EMPTY, - "Element %s was declared EMPTY this one has content\n", - elem->name, NULL, NULL); - ret = 0; - } - break; - case XML_ELEMENT_TYPE_ANY: - /* I don't think anything is required then */ - break; - case XML_ELEMENT_TYPE_MIXED: - - /* simple case of declared as #PCDATA */ - if ((elemDecl->content != NULL) && - (elemDecl->content->type == XML_ELEMENT_CONTENT_PCDATA)) { - ret = xmlValidateOneCdataElement(ctxt, doc, elem); - if (!ret) { - xmlErrValidNode(ctxt, elem, XML_DTD_NOT_PCDATA, - "Element %s was declared #PCDATA but contains non text nodes\n", - elem->name, NULL, NULL); - } - break; - } - child = elem->children; - /* Hum, this start to get messy */ - while (child != NULL) { - if (child->type == XML_ELEMENT_NODE) { - name = child->name; - if ((child->ns != NULL) && (child->ns->prefix != NULL)) { - xmlChar fn[50]; - xmlChar *fullname; - - fullname = xmlBuildQName(child->name, child->ns->prefix, - fn, 50); - if (fullname == NULL) - return(0); - cont = elemDecl->content; - while (cont != NULL) { - if (cont->type == XML_ELEMENT_CONTENT_ELEMENT) { - if (xmlStrEqual(cont->name, fullname)) - break; - } else if ((cont->type == XML_ELEMENT_CONTENT_OR) && - (cont->c1 != NULL) && - (cont->c1->type == XML_ELEMENT_CONTENT_ELEMENT)){ - if (xmlStrEqual(cont->c1->name, fullname)) - break; - } else if ((cont->type != XML_ELEMENT_CONTENT_OR) || - (cont->c1 == NULL) || - (cont->c1->type != XML_ELEMENT_CONTENT_PCDATA)){ - xmlErrValid(NULL, XML_DTD_MIXED_CORRUPT, - "Internal: MIXED struct corrupted\n", - NULL); - break; - } - cont = cont->c2; - } - if ((fullname != fn) && (fullname != child->name)) - xmlFree(fullname); - if (cont != NULL) - goto child_ok; - } - cont = elemDecl->content; - while (cont != NULL) { - if (cont->type == XML_ELEMENT_CONTENT_ELEMENT) { - if (xmlStrEqual(cont->name, name)) break; - } else if ((cont->type == XML_ELEMENT_CONTENT_OR) && - (cont->c1 != NULL) && - (cont->c1->type == XML_ELEMENT_CONTENT_ELEMENT)) { - if (xmlStrEqual(cont->c1->name, name)) break; - } else if ((cont->type != XML_ELEMENT_CONTENT_OR) || - (cont->c1 == NULL) || - (cont->c1->type != XML_ELEMENT_CONTENT_PCDATA)) { - xmlErrValid(ctxt, XML_DTD_MIXED_CORRUPT, - "Internal: MIXED struct corrupted\n", - NULL); - break; - } - cont = cont->c2; - } - if (cont == NULL) { - xmlErrValidNode(ctxt, elem, XML_DTD_INVALID_CHILD, - "Element %s is not declared in %s list of possible children\n", - name, elem->name, NULL); - ret = 0; - } - } -child_ok: - child = child->next; - } - break; - case XML_ELEMENT_TYPE_ELEMENT: - if ((doc->standalone == 1) && (extsubset == 1)) { - /* - * VC: Standalone Document Declaration - * - element types with element content, if white space - * occurs directly within any instance of those types. - */ - child = elem->children; - while (child != NULL) { - if (child->type == XML_TEXT_NODE) { - const xmlChar *content = child->content; - - while (IS_BLANK_CH(*content)) - content++; - if (*content == 0) { - xmlErrValidNode(ctxt, elem, - XML_DTD_STANDALONE_WHITE_SPACE, -"standalone: %s declared in the external subset contains white spaces nodes\n", - elem->name, NULL, NULL); - ret = 0; - break; - } - } - child =child->next; - } - } - child = elem->children; - cont = elemDecl->content; - tmp = xmlValidateElementContent(ctxt, child, elemDecl, 1, elem); - if (tmp <= 0) - ret = tmp; - break; - } - } /* not continuous */ - - /* [ VC: Required Attribute ] */ - attr = elemDecl->attributes; - while (attr != NULL) { - if (attr->def == XML_ATTRIBUTE_REQUIRED) { - int qualified = -1; - - if ((attr->prefix == NULL) && - (xmlStrEqual(attr->name, BAD_CAST "xmlns"))) { - xmlNsPtr ns; - - ns = elem->nsDef; - while (ns != NULL) { - if (ns->prefix == NULL) - goto found; - ns = ns->next; - } - } else if (xmlStrEqual(attr->prefix, BAD_CAST "xmlns")) { - xmlNsPtr ns; - - ns = elem->nsDef; - while (ns != NULL) { - if (xmlStrEqual(attr->name, ns->prefix)) - goto found; - ns = ns->next; - } - } else { - xmlAttrPtr attrib; - - attrib = elem->properties; - while (attrib != NULL) { - if (xmlStrEqual(attrib->name, attr->name)) { - if (attr->prefix != NULL) { - xmlNsPtr nameSpace = attrib->ns; - - if (nameSpace == NULL) - nameSpace = elem->ns; - /* - * qualified names handling is problematic, having a - * different prefix should be possible but DTDs don't - * allow to define the URI instead of the prefix :-( - */ - if (nameSpace == NULL) { - if (qualified < 0) - qualified = 0; - } else if (!xmlStrEqual(nameSpace->prefix, - attr->prefix)) { - if (qualified < 1) - qualified = 1; - } else - goto found; - } else { - /* - * We should allow applications to define namespaces - * for their application even if the DTD doesn't - * carry one, otherwise, basically we would always - * break. - */ - goto found; - } - } - attrib = attrib->next; - } - } - if (qualified == -1) { - if (attr->prefix == NULL) { - xmlErrValidNode(ctxt, elem, XML_DTD_MISSING_ATTRIBUTE, - "Element %s does not carry attribute %s\n", - elem->name, attr->name, NULL); - ret = 0; - } else { - xmlErrValidNode(ctxt, elem, XML_DTD_MISSING_ATTRIBUTE, - "Element %s does not carry attribute %s:%s\n", - elem->name, attr->prefix,attr->name); - ret = 0; - } - } else if (qualified == 0) { - xmlErrValidWarning(ctxt, elem, XML_DTD_NO_PREFIX, - "Element %s required attribute %s:%s has no prefix\n", - elem->name, attr->prefix, attr->name); - } else if (qualified == 1) { - xmlErrValidWarning(ctxt, elem, XML_DTD_DIFFERENT_PREFIX, - "Element %s required attribute %s:%s has different prefix\n", - elem->name, attr->prefix, attr->name); - } - } else if (attr->def == XML_ATTRIBUTE_FIXED) { - /* - * Special tests checking #FIXED namespace declarations - * have the right value since this is not done as an - * attribute checking - */ - if ((attr->prefix == NULL) && - (xmlStrEqual(attr->name, BAD_CAST "xmlns"))) { - xmlNsPtr ns; - - ns = elem->nsDef; - while (ns != NULL) { - if (ns->prefix == NULL) { - if (!xmlStrEqual(attr->defaultValue, ns->href)) { - xmlErrValidNode(ctxt, elem, - XML_DTD_ELEM_DEFAULT_NAMESPACE, - "Element %s namespace name for default namespace does not match the DTD\n", - elem->name, NULL, NULL); - ret = 0; - } - goto found; - } - ns = ns->next; - } - } else if (xmlStrEqual(attr->prefix, BAD_CAST "xmlns")) { - xmlNsPtr ns; - - ns = elem->nsDef; - while (ns != NULL) { - if (xmlStrEqual(attr->name, ns->prefix)) { - if (!xmlStrEqual(attr->defaultValue, ns->href)) { - xmlErrValidNode(ctxt, elem, XML_DTD_ELEM_NAMESPACE, - "Element %s namespace name for %s does not match the DTD\n", - elem->name, ns->prefix, NULL); - ret = 0; - } - goto found; - } - ns = ns->next; - } - } - } -found: - attr = attr->nexth; - } - return(ret); -} - -/** - * xmlValidateRoot: - * @ctxt: the validation context - * @doc: a document instance - * - * Try to validate a the root element - * basically it does the following check as described by the - * XML-1.0 recommendation: - * - [ VC: Root Element Type ] - * it doesn't try to recurse or apply other check to the element - * - * returns 1 if valid or 0 otherwise - */ - -int -xmlValidateRoot(xmlValidCtxtPtr ctxt, xmlDocPtr doc) { - xmlNodePtr root; - int ret; - - if (doc == NULL) return(0); - - root = xmlDocGetRootElement(doc); - if ((root == NULL) || (root->name == NULL)) { - xmlErrValid(ctxt, XML_DTD_NO_ROOT, - "no root element\n", NULL); - return(0); - } - - /* - * When doing post validation against a separate DTD, those may - * no internal subset has been generated - */ - if ((doc->intSubset != NULL) && - (doc->intSubset->name != NULL)) { - /* - * Check first the document root against the NQName - */ - if (!xmlStrEqual(doc->intSubset->name, root->name)) { - if ((root->ns != NULL) && (root->ns->prefix != NULL)) { - xmlChar fn[50]; - xmlChar *fullname; - - fullname = xmlBuildQName(root->name, root->ns->prefix, fn, 50); - if (fullname == NULL) { - xmlVErrMemory(ctxt, NULL); - return(0); - } - ret = xmlStrEqual(doc->intSubset->name, fullname); - if ((fullname != fn) && (fullname != root->name)) - xmlFree(fullname); - if (ret == 1) - goto name_ok; - } - if ((xmlStrEqual(doc->intSubset->name, BAD_CAST "HTML")) && - (xmlStrEqual(root->name, BAD_CAST "html"))) - goto name_ok; - xmlErrValidNode(ctxt, root, XML_DTD_ROOT_NAME, - "root and DTD name do not match '%s' and '%s'\n", - root->name, doc->intSubset->name, NULL); - return(0); - } - } -name_ok: - return(1); -} - - -/** - * xmlValidateElement: - * @ctxt: the validation context - * @doc: a document instance - * @elem: an element instance - * - * Try to validate the subtree under an element - * - * returns 1 if valid or 0 otherwise - */ - -int -xmlValidateElement(xmlValidCtxtPtr ctxt, xmlDocPtr doc, xmlNodePtr elem) { - xmlNodePtr child; - xmlAttrPtr attr; - xmlNsPtr ns; - const xmlChar *value; - int ret = 1; - - if (elem == NULL) return(0); - - /* - * XInclude elements were added after parsing in the infoset, - * they don't really mean anything validation wise. - */ - if ((elem->type == XML_XINCLUDE_START) || - (elem->type == XML_XINCLUDE_END)) - return(1); - - CHECK_DTD; - - /* - * Entities references have to be handled separately - */ - if (elem->type == XML_ENTITY_REF_NODE) { - return(1); - } - - ret &= xmlValidateOneElement(ctxt, doc, elem); - if (elem->type == XML_ELEMENT_NODE) { - attr = elem->properties; - while (attr != NULL) { - value = xmlNodeListGetString(doc, attr->children, 0); - ret &= xmlValidateOneAttribute(ctxt, doc, elem, attr, value); - if (value != NULL) - xmlFree((char *)value); - attr= attr->next; - } - ns = elem->nsDef; - while (ns != NULL) { - if (elem->ns == NULL) - ret &= xmlValidateOneNamespace(ctxt, doc, elem, NULL, - ns, ns->href); - else - ret &= xmlValidateOneNamespace(ctxt, doc, elem, - elem->ns->prefix, ns, ns->href); - ns = ns->next; - } - } - child = elem->children; - while (child != NULL) { - ret &= xmlValidateElement(ctxt, doc, child); - child = child->next; - } - - return(ret); -} - -/** - * xmlValidateRef: - * @ref: A reference to be validated - * @ctxt: Validation context - * @name: Name of ID we are searching for - * - */ -static void -xmlValidateRef(xmlRefPtr ref, xmlValidCtxtPtr ctxt, - const xmlChar *name) { - xmlAttrPtr id; - xmlAttrPtr attr; - - if (ref == NULL) - return; - if ((ref->attr == NULL) && (ref->name == NULL)) - return; - attr = ref->attr; - if (attr == NULL) { - xmlChar *dup, *str = NULL, *cur, save; - - dup = xmlStrdup(name); - if (dup == NULL) { - ctxt->valid = 0; - return; - } - cur = dup; - while (*cur != 0) { - str = cur; - while ((*cur != 0) && (!IS_BLANK_CH(*cur))) cur++; - save = *cur; - *cur = 0; - id = xmlGetID(ctxt->doc, str); - if (id == NULL) { - xmlErrValidNodeNr(ctxt, NULL, XML_DTD_UNKNOWN_ID, - "attribute %s line %d references an unknown ID \"%s\"\n", - ref->name, ref->lineno, str); - ctxt->valid = 0; - } - if (save == 0) - break; - *cur = save; - while (IS_BLANK_CH(*cur)) cur++; - } - xmlFree(dup); - } else if (attr->atype == XML_ATTRIBUTE_IDREF) { - id = xmlGetID(ctxt->doc, name); - if (id == NULL) { - xmlErrValidNode(ctxt, attr->parent, XML_DTD_UNKNOWN_ID, - "IDREF attribute %s references an unknown ID \"%s\"\n", - attr->name, name, NULL); - ctxt->valid = 0; - } - } else if (attr->atype == XML_ATTRIBUTE_IDREFS) { - xmlChar *dup, *str = NULL, *cur, save; - - dup = xmlStrdup(name); - if (dup == NULL) { - xmlVErrMemory(ctxt, "IDREFS split"); - ctxt->valid = 0; - return; - } - cur = dup; - while (*cur != 0) { - str = cur; - while ((*cur != 0) && (!IS_BLANK_CH(*cur))) cur++; - save = *cur; - *cur = 0; - id = xmlGetID(ctxt->doc, str); - if (id == NULL) { - xmlErrValidNode(ctxt, attr->parent, XML_DTD_UNKNOWN_ID, - "IDREFS attribute %s references an unknown ID \"%s\"\n", - attr->name, str, NULL); - ctxt->valid = 0; - } - if (save == 0) - break; - *cur = save; - while (IS_BLANK_CH(*cur)) cur++; - } - xmlFree(dup); - } -} - -/** - * xmlWalkValidateList: - * @data: Contents of current link - * @user: Value supplied by the user - * - * Returns 0 to abort the walk or 1 to continue - */ -static int -xmlWalkValidateList(const void *data, const void *user) -{ - xmlValidateMemoPtr memo = (xmlValidateMemoPtr)user; - xmlValidateRef((xmlRefPtr)data, memo->ctxt, memo->name); - return 1; -} - -/** - * xmlValidateCheckRefCallback: - * @ref_list: List of references - * @ctxt: Validation context - * @name: Name of ID we are searching for - * - */ -static void -xmlValidateCheckRefCallback(xmlListPtr ref_list, xmlValidCtxtPtr ctxt, - const xmlChar *name) { - xmlValidateMemo memo; - - if (ref_list == NULL) - return; - memo.ctxt = ctxt; - memo.name = name; - - xmlListWalk(ref_list, xmlWalkValidateList, &memo); - -} - -/** - * xmlValidateDocumentFinal: - * @ctxt: the validation context - * @doc: a document instance - * - * Does the final step for the document validation once all the - * incremental validation steps have been completed - * - * basically it does the following checks described by the XML Rec - * - * Check all the IDREF/IDREFS attributes definition for validity - * - * returns 1 if valid or 0 otherwise - */ - -int -xmlValidateDocumentFinal(xmlValidCtxtPtr ctxt, xmlDocPtr doc) { - xmlRefTablePtr table; - unsigned int save; - - if (ctxt == NULL) - return(0); - if (doc == NULL) { - xmlErrValid(ctxt, XML_DTD_NO_DOC, - "xmlValidateDocumentFinal: doc == NULL\n", NULL); - return(0); - } - - /* trick to get correct line id report */ - save = ctxt->finishDtd; - ctxt->finishDtd = 0; - - /* - * Check all the NOTATION/NOTATIONS attributes - */ - /* - * Check all the ENTITY/ENTITIES attributes definition for validity - */ - /* - * Check all the IDREF/IDREFS attributes definition for validity - */ - table = (xmlRefTablePtr) doc->refs; - ctxt->doc = doc; - ctxt->valid = 1; - xmlHashScan(table, (xmlHashScanner) xmlValidateCheckRefCallback, ctxt); - - ctxt->finishDtd = save; - return(ctxt->valid); -} - -/** - * xmlValidateDtd: - * @ctxt: the validation context - * @doc: a document instance - * @dtd: a dtd instance - * - * Try to validate the document against the dtd instance - * - * Basically it does check all the definitions in the DtD. - * Note the the internal subset (if present) is de-coupled - * (i.e. not used), which could give problems if ID or IDREF - * is present. - * - * returns 1 if valid or 0 otherwise - */ - -int -xmlValidateDtd(xmlValidCtxtPtr ctxt, xmlDocPtr doc, xmlDtdPtr dtd) { - int ret; - xmlDtdPtr oldExt, oldInt; - xmlNodePtr root; - - if (dtd == NULL) return(0); - if (doc == NULL) return(0); - oldExt = doc->extSubset; - oldInt = doc->intSubset; - doc->extSubset = dtd; - doc->intSubset = NULL; - ret = xmlValidateRoot(ctxt, doc); - if (ret == 0) { - doc->extSubset = oldExt; - doc->intSubset = oldInt; - return(ret); - } - if (doc->ids != NULL) { - xmlFreeIDTable(doc->ids); - doc->ids = NULL; - } - if (doc->refs != NULL) { - xmlFreeRefTable(doc->refs); - doc->refs = NULL; - } - root = xmlDocGetRootElement(doc); - ret = xmlValidateElement(ctxt, doc, root); - ret &= xmlValidateDocumentFinal(ctxt, doc); - doc->extSubset = oldExt; - doc->intSubset = oldInt; - return(ret); -} - -static void -xmlValidateNotationCallback(xmlEntityPtr cur, xmlValidCtxtPtr ctxt, - const xmlChar *name ATTRIBUTE_UNUSED) { - if (cur == NULL) - return; - if (cur->etype == XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) { - xmlChar *notation = cur->content; - - if (notation != NULL) { - int ret; - - ret = xmlValidateNotationUse(ctxt, cur->doc, notation); - if (ret != 1) { - ctxt->valid = 0; - } - } - } -} - -static void -xmlValidateAttributeCallback(xmlAttributePtr cur, xmlValidCtxtPtr ctxt, - const xmlChar *name ATTRIBUTE_UNUSED) { - int ret; - xmlDocPtr doc; - xmlElementPtr elem = NULL; - - if (cur == NULL) - return; - switch (cur->atype) { - case XML_ATTRIBUTE_CDATA: - case XML_ATTRIBUTE_ID: - case XML_ATTRIBUTE_IDREF : - case XML_ATTRIBUTE_IDREFS: - case XML_ATTRIBUTE_NMTOKEN: - case XML_ATTRIBUTE_NMTOKENS: - case XML_ATTRIBUTE_ENUMERATION: - break; - case XML_ATTRIBUTE_ENTITY: - case XML_ATTRIBUTE_ENTITIES: - case XML_ATTRIBUTE_NOTATION: - if (cur->defaultValue != NULL) { - - ret = xmlValidateAttributeValue2(ctxt, ctxt->doc, cur->name, - cur->atype, cur->defaultValue); - if ((ret == 0) && (ctxt->valid == 1)) - ctxt->valid = 0; - } - if (cur->tree != NULL) { - xmlEnumerationPtr tree = cur->tree; - while (tree != NULL) { - ret = xmlValidateAttributeValue2(ctxt, ctxt->doc, - cur->name, cur->atype, tree->name); - if ((ret == 0) && (ctxt->valid == 1)) - ctxt->valid = 0; - tree = tree->next; - } - } - } - if (cur->atype == XML_ATTRIBUTE_NOTATION) { - doc = cur->doc; - if (cur->elem == NULL) { - xmlErrValid(ctxt, XML_ERR_INTERNAL_ERROR, - "xmlValidateAttributeCallback(%s): internal error\n", - (const char *) cur->name); - return; - } - - if (doc != NULL) - elem = xmlGetDtdElementDesc(doc->intSubset, cur->elem); - if ((elem == NULL) && (doc != NULL)) - elem = xmlGetDtdElementDesc(doc->extSubset, cur->elem); - if ((elem == NULL) && (cur->parent != NULL) && - (cur->parent->type == XML_DTD_NODE)) - elem = xmlGetDtdElementDesc((xmlDtdPtr) cur->parent, cur->elem); - if (elem == NULL) { - xmlErrValidNode(ctxt, NULL, XML_DTD_UNKNOWN_ELEM, - "attribute %s: could not find decl for element %s\n", - cur->name, cur->elem, NULL); - return; - } - if (elem->etype == XML_ELEMENT_TYPE_EMPTY) { - xmlErrValidNode(ctxt, NULL, XML_DTD_EMPTY_NOTATION, - "NOTATION attribute %s declared for EMPTY element %s\n", - cur->name, cur->elem, NULL); - ctxt->valid = 0; - } - } -} - -/** - * xmlValidateDtdFinal: - * @ctxt: the validation context - * @doc: a document instance - * - * Does the final step for the dtds validation once all the - * subsets have been parsed - * - * basically it does the following checks described by the XML Rec - * - check that ENTITY and ENTITIES type attributes default or - * possible values matches one of the defined entities. - * - check that NOTATION type attributes default or - * possible values matches one of the defined notations. - * - * returns 1 if valid or 0 if invalid and -1 if not well-formed - */ - -int -xmlValidateDtdFinal(xmlValidCtxtPtr ctxt, xmlDocPtr doc) { - xmlDtdPtr dtd; - xmlAttributeTablePtr table; - xmlEntitiesTablePtr entities; - - if ((doc == NULL) || (ctxt == NULL)) return(0); - if ((doc->intSubset == NULL) && (doc->extSubset == NULL)) - return(0); - ctxt->doc = doc; - ctxt->valid = 1; - dtd = doc->intSubset; - if ((dtd != NULL) && (dtd->attributes != NULL)) { - table = (xmlAttributeTablePtr) dtd->attributes; - xmlHashScan(table, (xmlHashScanner) xmlValidateAttributeCallback, ctxt); - } - if ((dtd != NULL) && (dtd->entities != NULL)) { - entities = (xmlEntitiesTablePtr) dtd->entities; - xmlHashScan(entities, (xmlHashScanner) xmlValidateNotationCallback, - ctxt); - } - dtd = doc->extSubset; - if ((dtd != NULL) && (dtd->attributes != NULL)) { - table = (xmlAttributeTablePtr) dtd->attributes; - xmlHashScan(table, (xmlHashScanner) xmlValidateAttributeCallback, ctxt); - } - if ((dtd != NULL) && (dtd->entities != NULL)) { - entities = (xmlEntitiesTablePtr) dtd->entities; - xmlHashScan(entities, (xmlHashScanner) xmlValidateNotationCallback, - ctxt); - } - return(ctxt->valid); -} - -/** - * xmlValidateDocument: - * @ctxt: the validation context - * @doc: a document instance - * - * Try to validate the document instance - * - * basically it does the all the checks described by the XML Rec - * i.e. validates the internal and external subset (if present) - * and validate the document tree. - * - * returns 1 if valid or 0 otherwise - */ - -int -xmlValidateDocument(xmlValidCtxtPtr ctxt, xmlDocPtr doc) { - int ret; - xmlNodePtr root; - - if (doc == NULL) - return(0); - if ((doc->intSubset == NULL) && (doc->extSubset == NULL)) { - xmlErrValid(ctxt, XML_DTD_NO_DTD, - "no DTD found!\n", NULL); - return(0); - } - if ((doc->intSubset != NULL) && ((doc->intSubset->SystemID != NULL) || - (doc->intSubset->ExternalID != NULL)) && (doc->extSubset == NULL)) { - xmlChar *sysID; - if (doc->intSubset->SystemID != NULL) { - sysID = xmlBuildURI(doc->intSubset->SystemID, - doc->URL); - if (sysID == NULL) { - xmlErrValid(ctxt, XML_DTD_LOAD_ERROR, - "Could not build URI for external subset \"%s\"\n", - (const char *) doc->intSubset->SystemID); - return 0; - } - } else - sysID = NULL; - doc->extSubset = xmlParseDTD(doc->intSubset->ExternalID, - (const xmlChar *)sysID); - if (sysID != NULL) - xmlFree(sysID); - if (doc->extSubset == NULL) { - if (doc->intSubset->SystemID != NULL) { - xmlErrValid(ctxt, XML_DTD_LOAD_ERROR, - "Could not load the external subset \"%s\"\n", - (const char *) doc->intSubset->SystemID); - } else { - xmlErrValid(ctxt, XML_DTD_LOAD_ERROR, - "Could not load the external subset \"%s\"\n", - (const char *) doc->intSubset->ExternalID); - } - return(0); - } - } - - if (doc->ids != NULL) { - xmlFreeIDTable(doc->ids); - doc->ids = NULL; - } - if (doc->refs != NULL) { - xmlFreeRefTable(doc->refs); - doc->refs = NULL; - } - ret = xmlValidateDtdFinal(ctxt, doc); - if (!xmlValidateRoot(ctxt, doc)) return(0); - - root = xmlDocGetRootElement(doc); - ret &= xmlValidateElement(ctxt, doc, root); - ret &= xmlValidateDocumentFinal(ctxt, doc); - return(ret); -} - -/************************************************************************ - * * - * Routines for dynamic validation editing * - * * - ************************************************************************/ - -/** - * xmlValidGetPotentialChildren: - * @ctree: an element content tree - * @names: an array to store the list of child names - * @len: a pointer to the number of element in the list - * @max: the size of the array - * - * Build/extend a list of potential children allowed by the content tree - * - * returns the number of element in the list, or -1 in case of error. - */ - -int -xmlValidGetPotentialChildren(xmlElementContent *ctree, - const xmlChar **names, - int *len, int max) { - int i; - - if ((ctree == NULL) || (names == NULL) || (len == NULL)) - return(-1); - if (*len >= max) return(*len); - - switch (ctree->type) { - case XML_ELEMENT_CONTENT_PCDATA: - for (i = 0; i < *len;i++) - if (xmlStrEqual(BAD_CAST "#PCDATA", names[i])) return(*len); - names[(*len)++] = BAD_CAST "#PCDATA"; - break; - case XML_ELEMENT_CONTENT_ELEMENT: - for (i = 0; i < *len;i++) - if (xmlStrEqual(ctree->name, names[i])) return(*len); - names[(*len)++] = ctree->name; - break; - case XML_ELEMENT_CONTENT_SEQ: - xmlValidGetPotentialChildren(ctree->c1, names, len, max); - xmlValidGetPotentialChildren(ctree->c2, names, len, max); - break; - case XML_ELEMENT_CONTENT_OR: - xmlValidGetPotentialChildren(ctree->c1, names, len, max); - xmlValidGetPotentialChildren(ctree->c2, names, len, max); - break; - } - - return(*len); -} - -/* - * Dummy function to suppress messages while we try out valid elements - */ -static void XMLCDECL xmlNoValidityErr(void *ctx ATTRIBUTE_UNUSED, - const char *msg ATTRIBUTE_UNUSED, ...) { - return; -} - -/** - * xmlValidGetValidElements: - * @prev: an element to insert after - * @next: an element to insert next - * @names: an array to store the list of child names - * @max: the size of the array - * - * This function returns the list of authorized children to insert - * within an existing tree while respecting the validity constraints - * forced by the Dtd. The insertion point is defined using @prev and - * @next in the following ways: - * to insert before 'node': xmlValidGetValidElements(node->prev, node, ... - * to insert next 'node': xmlValidGetValidElements(node, node->next, ... - * to replace 'node': xmlValidGetValidElements(node->prev, node->next, ... - * to prepend a child to 'node': xmlValidGetValidElements(NULL, node->childs, - * to append a child to 'node': xmlValidGetValidElements(node->last, NULL, ... - * - * pointers to the element names are inserted at the beginning of the array - * and do not need to be freed. - * - * returns the number of element in the list, or -1 in case of error. If - * the function returns the value @max the caller is invited to grow the - * receiving array and retry. - */ - -int -xmlValidGetValidElements(xmlNode *prev, xmlNode *next, const xmlChar **names, - int max) { - xmlValidCtxt vctxt; - int nb_valid_elements = 0; - const xmlChar *elements[256]; - int nb_elements = 0, i; - const xmlChar *name; - - xmlNode *ref_node; - xmlNode *parent; - xmlNode *test_node; - - xmlNode *prev_next; - xmlNode *next_prev; - xmlNode *parent_childs; - xmlNode *parent_last; - - xmlElement *element_desc; - - if (prev == NULL && next == NULL) - return(-1); - - if (names == NULL) return(-1); - if (max <= 0) return(-1); - - memset(&vctxt, 0, sizeof (xmlValidCtxt)); - vctxt.error = xmlNoValidityErr; /* this suppresses err/warn output */ - - nb_valid_elements = 0; - ref_node = prev ? prev : next; - parent = ref_node->parent; - - /* - * Retrieves the parent element declaration - */ - element_desc = xmlGetDtdElementDesc(parent->doc->intSubset, - parent->name); - if ((element_desc == NULL) && (parent->doc->extSubset != NULL)) - element_desc = xmlGetDtdElementDesc(parent->doc->extSubset, - parent->name); - if (element_desc == NULL) return(-1); - - /* - * Do a backup of the current tree structure - */ - prev_next = prev ? prev->next : NULL; - next_prev = next ? next->prev : NULL; - parent_childs = parent->children; - parent_last = parent->last; - - /* - * Creates a dummy node and insert it into the tree - */ - test_node = xmlNewDocNode (ref_node->doc, NULL, BAD_CAST "", NULL); - test_node->parent = parent; - test_node->prev = prev; - test_node->next = next; - name = test_node->name; - - if (prev) prev->next = test_node; - else parent->children = test_node; - - if (next) next->prev = test_node; - else parent->last = test_node; - - /* - * Insert each potential child node and check if the parent is - * still valid - */ - nb_elements = xmlValidGetPotentialChildren(element_desc->content, - elements, &nb_elements, 256); - - for (i = 0;i < nb_elements;i++) { - test_node->name = elements[i]; - if (xmlValidateOneElement(&vctxt, parent->doc, parent)) { - int j; - - for (j = 0; j < nb_valid_elements;j++) - if (xmlStrEqual(elements[i], names[j])) break; - names[nb_valid_elements++] = elements[i]; - if (nb_valid_elements >= max) break; - } - } - - /* - * Restore the tree structure - */ - if (prev) prev->next = prev_next; - if (next) next->prev = next_prev; - parent->children = parent_childs; - parent->last = parent_last; - - /* - * Free up the dummy node - */ - test_node->name = name; - xmlFreeNode(test_node); - - return(nb_valid_elements); -} -#endif /* LIBXML_VALID_ENABLED */ - #define bottom_valid #include "elfgcchack.h" diff --git a/android/native/libxml2/xmllint.c b/android/native/libxml2/xmllint.c index ec75af895f..4715ad5d16 100644 --- a/android/native/libxml2/xmllint.c +++ b/android/native/libxml2/xmllint.c @@ -108,12 +108,6 @@ static int noenc = 0; static int noblanks = 0; static int noout = 0; static int nowrap = 0; -#ifdef LIBXML_VALID_ENABLED -static int valid = 0; -static int postvalid = 0; -static char * dtdvalid = NULL; -static char * dtdvalidfpi = NULL; -#endif static int repeat = 0; static int insert = 0; static int htmlout = 0; @@ -1635,11 +1629,6 @@ static void streamFile(char *filename) { if (reader != NULL) { -#ifdef LIBXML_VALID_ENABLED - if (valid) - xmlTextReaderSetParserProp(reader, XML_PARSER_VALIDATE, 1); - else -#endif /* LIBXML_VALID_ENABLED */ xmlTextReaderSetParserProp(reader, XML_PARSER_LOADDTD, 1); /* @@ -1656,23 +1645,9 @@ static void streamFile(char *filename) { ret = xmlTextReaderRead(reader); } if ((timing) && (!repeat)) { -#ifdef LIBXML_VALID_ENABLED - if (valid) - endTimer("Parsing and validating"); - else -#endif endTimer("Parsing"); } -#ifdef LIBXML_VALID_ENABLED - if (valid) { - if (xmlTextReaderIsValid(reader) != 1) { - xmlGenericError(xmlGenericErrorContext, - "Document %s does not validate\n", filename); - progresult = XMLLINT_ERR_VALID; - } - } -#endif /* LIBXML_VALID_ENABLED */ /* * Done, cleanup and status */ @@ -1866,25 +1841,6 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { munmap((char *) base, info.st_size); close(fd); #endif -#ifdef LIBXML_VALID_ENABLED - } else if (valid) { - xmlParserCtxtPtr ctxt = NULL; - - if (rectxt == NULL) - ctxt = xmlNewParserCtxt(); - else - ctxt = rectxt; - if (ctxt == NULL) { - doc = NULL; - } else { - doc = xmlCtxtReadFile(ctxt, filename, NULL, options); - - if (ctxt->valid == 0) - progresult = XMLLINT_ERR_RDFILE; - if (rectxt == NULL) - xmlFreeParserCtxt(ctxt); - } -#endif /* LIBXML_VALID_ENABLED */ } else { if (rectxt != NULL) doc = xmlCtxtReadFile(rectxt, filename, NULL, options); @@ -1943,121 +1899,12 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { } #endif /* LIBXML_TREE_ENABLED */ -#ifdef LIBXML_VALID_ENABLED - if ((insert) && (!html)) { - const xmlChar* list[256]; - int nb, i; - xmlNodePtr node; - - if (doc->children != NULL) { - node = doc->children; - while ((node != NULL) && (node->last == NULL)) node = node->next; - if (node != NULL) { - nb = xmlValidGetValidElements(node->last, NULL, list, 256); - if (nb < 0) { - fprintf(stderr, "could not get valid list of elements\n"); - } else if (nb == 0) { - fprintf(stderr, "No element can be inserted under root\n"); - } else { - fprintf(stderr, "%d element types can be inserted under root:\n", - nb); - for (i = 0;i < nb;i++) { - fprintf(stderr, "%s\n", (char *) list[i]); - } - } - } - } - }else -#endif /* LIBXML_VALID_ENABLED */ #ifdef LIBXML_READER_ENABLED if (walker) { walkDoc(doc); } #endif /* LIBXML_READER_ENABLED */ -#ifdef LIBXML_VALID_ENABLED - /* - * A posteriori validation test - */ - if ((dtdvalid != NULL) || (dtdvalidfpi != NULL)) { - xmlDtdPtr dtd; - - if ((timing) && (!repeat)) { - startTimer(); - } - if (dtdvalid != NULL) - dtd = xmlParseDTD(NULL, (const xmlChar *)dtdvalid); - else - dtd = xmlParseDTD((const xmlChar *)dtdvalidfpi, NULL); - if ((timing) && (!repeat)) { - endTimer("Parsing DTD"); - } - if (dtd == NULL) { - if (dtdvalid != NULL) - xmlGenericError(xmlGenericErrorContext, - "Could not parse DTD %s\n", dtdvalid); - else - xmlGenericError(xmlGenericErrorContext, - "Could not parse DTD %s\n", dtdvalidfpi); - progresult = XMLLINT_ERR_DTD; - } else { - xmlValidCtxtPtr cvp; - - if ((cvp = xmlNewValidCtxt()) == NULL) { - xmlGenericError(xmlGenericErrorContext, - "Couldn't allocate validation context\n"); - exit(-1); - } - cvp->userData = (void *) stderr; - cvp->error = (xmlValidityErrorFunc) fprintf; - cvp->warning = (xmlValidityWarningFunc) fprintf; - - if ((timing) && (!repeat)) { - startTimer(); - } - if (!xmlValidateDtd(cvp, doc, dtd)) { - if (dtdvalid != NULL) - xmlGenericError(xmlGenericErrorContext, - "Document %s does not validate against %s\n", - filename, dtdvalid); - else - xmlGenericError(xmlGenericErrorContext, - "Document %s does not validate against %s\n", - filename, dtdvalidfpi); - progresult = XMLLINT_ERR_VALID; - } - if ((timing) && (!repeat)) { - endTimer("Validating against DTD"); - } - xmlFreeValidCtxt(cvp); - xmlFreeDtd(dtd); - } - } else if (postvalid) { - xmlValidCtxtPtr cvp; - - if ((cvp = xmlNewValidCtxt()) == NULL) { - xmlGenericError(xmlGenericErrorContext, - "Couldn't allocate validation context\n"); - exit(-1); - } - - if ((timing) && (!repeat)) { - startTimer(); - } - cvp->userData = (void *) stderr; - cvp->error = (xmlValidityErrorFunc) fprintf; - cvp->warning = (xmlValidityWarningFunc) fprintf; - if (!xmlValidateDocument(cvp, doc)) { - xmlGenericError(xmlGenericErrorContext, - "Document %s does not validate\n", filename); - progresult = XMLLINT_ERR_VALID; - } - if ((timing) && (!repeat)) { - endTimer("Validating"); - } - xmlFreeValidCtxt(cvp); - } -#endif /* LIBXML_VALID_ENABLED */ /* * free it. @@ -2137,12 +1984,6 @@ static void usage(const char *name) { printf("\t--nocompact : do not generate compact text nodes\n"); printf("\t--htmlout : output results as HTML\n"); printf("\t--nowrap : do not put HTML doc wrapper\n"); -#ifdef LIBXML_VALID_ENABLED - printf("\t--valid : validate the document in addition to std well-formed check\n"); - printf("\t--postvalid : do a posteriori validation, i.e after parsing\n"); - printf("\t--dtdvalid URL : do a posteriori validation against a given DTD\n"); - printf("\t--dtdvalidfpi FPI : same but name the DTD with a Public Identifier\n"); -#endif /* LIBXML_VALID_ENABLED */ printf("\t--timing : print some timings\n"); printf("\t--output file or -o file: save to a given file\n"); printf("\t--repeat : repeat 100 times, for timing or profiling\n"); @@ -2265,30 +2106,6 @@ main(int argc, char **argv) { dtdattrs++; options |= XML_PARSE_DTDATTR; } -#ifdef LIBXML_VALID_ENABLED - else if ((!strcmp(argv[i], "-valid")) || - (!strcmp(argv[i], "--valid"))) { - valid++; - options |= XML_PARSE_DTDVALID; - } else if ((!strcmp(argv[i], "-postvalid")) || - (!strcmp(argv[i], "--postvalid"))) { - postvalid++; - loaddtd++; - options |= XML_PARSE_DTDLOAD; - } else if ((!strcmp(argv[i], "-dtdvalid")) || - (!strcmp(argv[i], "--dtdvalid"))) { - i++; - dtdvalid = argv[i]; - loaddtd++; - options |= XML_PARSE_DTDLOAD; - } else if ((!strcmp(argv[i], "-dtdvalidfpi")) || - (!strcmp(argv[i], "--dtdvalidfpi"))) { - i++; - dtdvalidfpi = argv[i]; - loaddtd++; - options |= XML_PARSE_DTDLOAD; - } -#endif /* LIBXML_VALID_ENABLED */ else if ((!strcmp(argv[i], "-dropdtd")) || (!strcmp(argv[i], "--dropdtd"))) dropdtd++; @@ -2435,9 +2252,6 @@ main(int argc, char **argv) { if (dtdattrs) xmlLoadExtDtdDefaultValue |= XML_COMPLETE_ATTRS; if (noent != 0) xmlSubstituteEntitiesDefault(1); -#ifdef LIBXML_VALID_ENABLED - if (valid != 0) xmlDoValidityCheckingDefaultValue = 1; -#endif /* LIBXML_VALID_ENABLED */ if ((htmlout) && (!nowrap)) { xmlGenericError(xmlGenericErrorContext, "