Commit 03a53c34 authored by Daniel Veillard's avatar Daniel Veillard

added checking for names values and dictionnaries generates a tons of

* debugXML.c include/libxml/xmlerror.h: added checking for names
  values and dictionnaries generates a tons of errors
* SAX2.ccatalog.c parser.c relaxng.c tree.c xinclude.c xmlwriter.c
  include/libxml/tree.h: fixing the errors in the regression tests
Daniel
parent 1227fb3c
Tue Oct 26 18:09:59 CEST 2004 Daniel Veillard <daniel@veillard.com>
* debugXML.c include/libxml/xmlerror.h: added checking for names
values and dictionnaries generates a tons of errors
* SAX2.ccatalog.c parser.c relaxng.c tree.c xinclude.c xmlwriter.c
include/libxml/tree.h: fixing the errors in the regression tests
Mon Oct 25 16:04:22 PDT 2004 William Brack <wbrack@mmm.com.hk>
* parser.c: modified the handling of _private for entity
......
......@@ -277,7 +277,7 @@ NStests : xmllint$(EXEEXT)
log=`$(CHECKER) $(top_builddir)/xmllint $$i 2> error.$$name > result.$$name ; \
grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0"; \
diff $(srcdir)/result/namespaces/$$name result.$$name ; \
diff $(srcdir)/result/namespaces/$$name.err error.$$name` ; \
diff $(srcdir)/result/namespaces/$$name.err error.$$name`; \
if [ -n "$$log" ] ; then echo $$name result ; echo $$log ; fi ; \
rm result.$$name error.$$name ; \
fi ; fi ; done)
......
......@@ -2364,7 +2364,7 @@ xmlSAX2ProcessingInstruction(void *ctx, const xmlChar *target,
"SAX.xmlSAX2ProcessingInstruction(%s, %s)\n", target, data);
#endif
ret = xmlNewPI(target, data);
ret = xmlNewDocPI(ctxt->myDoc, target, data);
if (ret == NULL) return;
parent = ctxt->node;
......
......@@ -912,6 +912,7 @@ xmlParseCatalogFile(const char *filename) {
ctxt->validate = 0;
ctxt->loadsubset = 0;
ctxt->pedantic = 0;
ctxt->dictNames = 1;
xmlParseDocument(ctxt);
......
......@@ -42,8 +42,10 @@ struct _xmlDebugCtxt {
int depth; /* current depth */
xmlDocPtr doc; /* current document */
xmlNodePtr node; /* current node */
xmlDictPtr dict; /* the doc dictionnary */
int check; /* do just checkings */
int errors; /* number of errors found */
int nodict; /* if the document has no dictionnary */
};
static void xmlCtxtDumpNodeList(xmlDebugCtxtPtr ctxt, xmlNodePtr node);
......@@ -57,6 +59,9 @@ xmlCtxtDumpInitCtxt(xmlDebugCtxtPtr ctxt)
ctxt->check = 0;
ctxt->errors = 0;
ctxt->output = stdout;
ctxt->doc = NULL;
ctxt->node = NULL;
ctxt->dict = NULL;
for (i = 0; i < 100; i++)
ctxt->shift[i] = ' ';
ctxt->shift[100] = 0;
......@@ -222,20 +227,69 @@ xmlCtxtCheckString(xmlDebugCtxtPtr ctxt, const xmlChar * str)
if (str == NULL) return;
if (ctxt->check) {
if (!xmlCheckUTF8(str)) {
xmlDebugErr3(ctxt, XML_CHECK_NOT_DTD,
xmlDebugErr3(ctxt, XML_CHECK_NOT_UTF8,
"String is not UTF-8 %s", (const char *) str);
}
}
}
/**
* xmlCtxtCheckName:
* @ctxt: the debug context
* @name: the name
*
* Do debugging on the name, for example the dictionnary status and
* conformance to the Name production.
*/
static void
xmlCtxtCheckName(xmlDebugCtxtPtr ctxt, const xmlChar * name)
{
if (ctxt->check) {
if (name == NULL) {
xmlDebugErr(ctxt, XML_CHECK_NO_NAME, "Name is NULL");
return;
}
if (xmlValidateName(name, 0)) {
xmlDebugErr3(ctxt, XML_CHECK_NOT_NCNAME,
"Name is not an NCName '%s'", (const char *) name);
}
if ((ctxt->dict != NULL) &&
(!xmlDictOwns(ctxt->dict, name))) {
xmlDebugErr3(ctxt, XML_CHECK_OUTSIDE_DICT,
"Name is not from the document dictionnary '%s'",
(const char *) name);
}
}
}
static void
xmlCtxtGenericNodeCheck(xmlDebugCtxtPtr ctxt, xmlNodePtr node) {
xmlDocPtr doc;
xmlDictPtr dict;
doc = node->doc;
if (node->parent == NULL)
xmlDebugErr(ctxt, XML_CHECK_NO_PARENT,
"Node has no parent\n");
if (node->doc == NULL)
if (node->doc == NULL) {
xmlDebugErr(ctxt, XML_CHECK_NO_DOC,
"Node has no doc\n");
dict = NULL;
} else {
dict = doc->dict;
if ((dict == NULL) && (ctxt->nodict == 0)) {
xmlDebugErr(ctxt, XML_CHECK_NO_DICT,
"Document has no dictionnary\n");
ctxt->nodict = 1;
}
if (ctxt->doc == NULL)
ctxt->doc = doc;
if (ctxt->dict == NULL) {
ctxt->dict = dict;
}
}
if ((node->parent != NULL) && (node->doc != node->parent->doc) &&
(!xmlStrEqual(node->name, BAD_CAST "pseudoroot")))
xmlDebugErr(ctxt, XML_CHECK_WRONG_DOC,
......@@ -292,6 +346,60 @@ xmlCtxtGenericNodeCheck(xmlDebugCtxtPtr ctxt, xmlNodePtr node) {
if (node->content != NULL)
xmlCtxtCheckString(ctxt, (const xmlChar *) node->content);
}
switch (node->type) {
case XML_ELEMENT_NODE:
case XML_ATTRIBUTE_NODE:
xmlCtxtCheckName(ctxt, node->name);
break;
case XML_TEXT_NODE:
if ((node->name == xmlStringText) ||
(node->name == xmlStringTextNoenc))
break;
/* some case of entity substitution can lead to this */
if ((ctxt->dict != NULL) &&
(node->name == xmlDictLookup(ctxt->dict, "nbktext", 7)))
break;
xmlDebugErr3(ctxt, XML_CHECK_WRONG_NAME,
"Text node has wrong name '%s'",
(const char *) node->name);
break;
case XML_COMMENT_NODE:
if (node->name == xmlStringComment)
break;
xmlDebugErr3(ctxt, XML_CHECK_WRONG_NAME,
"Comment node has wrong name '%s'",
(const char *) node->name);
break;
case XML_PI_NODE:
xmlCtxtCheckName(ctxt, node->name);
break;
case XML_CDATA_SECTION_NODE:
if (node->name == NULL)
break;
xmlDebugErr3(ctxt, XML_CHECK_NAME_NOT_NULL,
"CData section has non NULL name '%s'",
(const char *) node->name);
break;
case XML_ENTITY_REF_NODE:
case XML_ENTITY_NODE:
case XML_DOCUMENT_TYPE_NODE:
case XML_DOCUMENT_FRAG_NODE:
case XML_NOTATION_NODE:
case XML_DTD_NODE:
case XML_ELEMENT_DECL:
case XML_ATTRIBUTE_DECL:
case XML_ENTITY_DECL:
case XML_NAMESPACE_DECL:
case XML_XINCLUDE_START:
case XML_XINCLUDE_END:
#ifdef LIBXML_DOCB_ENABLED
case XML_DOCB_DOCUMENT_NODE:
#endif
case XML_DOCUMENT_NODE:
case XML_HTML_DOCUMENT_NODE:
break;
}
}
static void
......
......@@ -15,7 +15,7 @@ install-data-local:
$(mkinstalldirs) $(DESTDIR)$(HTML_DIR)
-@INSTALL@ -m 0644 $(srcdir)/*.html $(srcdir)/*.c $(srcdir)/*.xml $(srcdir)/*.xsl $(srcdir)/*.res $(DESTDIR)$(HTML_DIR)
EXTRA_DIST=examples.xsl index.py test1.xml examples.xml test2.xml writer.xml test3.xml tst.xml reader1.res reader3.res tree1.res tree2.res io1.res io2.res xpath1.res xpath2.res
EXTRA_DIST=examples.xsl index.py test1.xml examples.xml test2.xml writer.xml test3.xml tst.xml reader1.res reader3.res tree1.res tree2.res io1.res io2.res xpath1.res xpath2.res reader4.res
noinst_PROGRAMS=xpath1 parse1 parse2 tree1 tree2 testWriter reader1 reader2 reader3 io1 parse3 parse4 io2 xpath2 reader4
......
......@@ -723,6 +723,10 @@ XMLPUBFUN xmlNodePtr XMLCALL
const xmlChar *content);
XMLPUBFUN xmlNodePtr XMLCALL
xmlNewText (const xmlChar *content);
XMLPUBFUN xmlNodePtr XMLCALL
xmlNewDocPI (xmlDocPtr doc,
const xmlChar *name,
const xmlChar *content);
XMLPUBFUN xmlNodePtr XMLCALL
xmlNewPI (const xmlChar *name,
const xmlChar *content);
......@@ -755,6 +759,9 @@ XMLPUBFUN xmlNodePtr XMLCALL
xmlDocCopyNode (const xmlNodePtr node,
xmlDocPtr doc,
int recursive);
XMLPUBFUN xmlNodePtr XMLCALL
xmlDocCopyNodeList (xmlDocPtr doc,
const xmlNodePtr node);
XMLPUBFUN xmlNodePtr XMLCALL
xmlCopyNodeList (const xmlNodePtr node);
#ifdef LIBXML_TREE_ENABLED
......
......@@ -777,7 +777,12 @@ typedef enum {
XML_CHECK_WRONG_PARENT,/* 5029 */
XML_CHECK_NS_SCOPE, /* 5030 */
XML_CHECK_NS_ANCESTOR, /* 5031 */
XML_CHECK_NOT_UTF8 /* 5032 */
XML_CHECK_NOT_UTF8, /* 5032 */
XML_CHECK_NO_DICT, /* 5033 */
XML_CHECK_NOT_NCNAME, /* 5034 */
XML_CHECK_OUTSIDE_DICT, /* 5035 */
XML_CHECK_WRONG_NAME, /* 5036 */
XML_CHECK_NAME_NOT_NULL /* 5037 */
#if 0
XML_CHECK_, /* 5033 */
XML_CHECK_X /* 503 */
......
......@@ -5643,7 +5643,7 @@ xmlParseReference(xmlParserCtxtPtr ctxt) {
cur = ent->children;
while (cur != NULL) {
nw = xmlCopyNode(cur, 1);
nw = xmlDocCopyNode(cur, ctxt->myDoc, 1);
if (nw != NULL) {
if (nw->_private == NULL)
nw->_private = cur->_private;
......@@ -5687,7 +5687,7 @@ xmlParseReference(xmlParserCtxtPtr ctxt) {
next = cur->next;
cur->next = NULL;
cur->parent = NULL;
nw = xmlCopyNode(cur, 1);
nw = xmlDocCopyNode(cur, ctxt->myDoc, 1);
if (nw != NULL) {
if (nw->_private == NULL)
nw->_private = cur->_private;
......@@ -9937,6 +9937,7 @@ xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *user_data,
xmlFreeParserInputBuffer(buf);
return(NULL);
}
ctxt->dictNames = 1;
ctxt->pushTab = (void **) xmlMalloc(ctxt->nameMax * 3 * sizeof(xmlChar *));
if (ctxt->pushTab == NULL) {
xmlErrMemory(ctxt, NULL);
......@@ -10385,6 +10386,10 @@ xmlParseCtxtExternalEntity(xmlParserCtxtPtr ctx, const xmlChar *URL,
xmlFreeParserCtxt(ctxt);
return(-1);
}
if (ctx->myDoc->dict) {
newDoc->dict = ctx->myDoc->dict;
xmlDictReference(newDoc->dict);
}
if (ctx->myDoc != NULL) {
newDoc->intSubset = ctx->myDoc->intSubset;
newDoc->extSubset = ctx->myDoc->extSubset;
......@@ -10596,7 +10601,12 @@ xmlParseExternalEntityPrivate(xmlDocPtr doc, xmlParserCtxtPtr oldctxt,
if (doc != NULL) {
newDoc->intSubset = doc->intSubset;
newDoc->extSubset = doc->extSubset;
newDoc->dict = doc->dict;
} else if (oldctxt != NULL) {
newDoc->dict = oldctxt->dict;
}
xmlDictReference(newDoc->dict);
if (doc->URL != NULL) {
newDoc->URL = xmlStrdup(doc->URL);
}
......@@ -10827,6 +10837,8 @@ xmlParseBalancedChunkMemoryInternal(xmlParserCtxtPtr oldctxt,
xmlFreeParserCtxt(ctxt);
return(XML_ERR_INTERNAL_ERROR);
}
newDoc->dict = ctxt->dict;
xmlDictReference(newDoc->dict);
ctxt->myDoc = newDoc;
} else {
ctxt->myDoc = oldctxt->myDoc;
......@@ -10838,8 +10850,9 @@ xmlParseBalancedChunkMemoryInternal(xmlParserCtxtPtr oldctxt,
ctxt->sax = oldsax;
ctxt->dict = NULL;
xmlFreeParserCtxt(ctxt);
if (newDoc != NULL)
if (newDoc != NULL) {
xmlFreeDoc(newDoc);
}
return(XML_ERR_INTERNAL_ERROR);
}
ctxt->myDoc->children = NULL;
......@@ -10913,8 +10926,9 @@ xmlParseBalancedChunkMemoryInternal(xmlParserCtxtPtr oldctxt,
ctxt->attsDefault = NULL;
ctxt->attsSpecial = NULL;
xmlFreeParserCtxt(ctxt);
if (newDoc != NULL)
if (newDoc != NULL) {
xmlFreeDoc(newDoc);
}
return(ret);
}
......@@ -11179,6 +11193,8 @@ xmlParseBalancedChunkMemoryRecover(xmlDocPtr doc, xmlSAXHandlerPtr sax,
xmlFreeParserCtxt(ctxt);
return(-1);
}
newDoc->dict = ctxt->dict;
xmlDictReference(newDoc->dict);
if (doc != NULL) {
newDoc->intSubset = doc->intSubset;
newDoc->extSubset = doc->extSubset;
......
......@@ -647,6 +647,56 @@ Class xmlDoc(xmlNode)
# functions from module xpointer
xpointerNewContext()
Class xpathContext()
# accessors
contextDoc()
contextNode()
contextPosition()
contextSize()
function()
functionURI()
setContextDoc()
setContextNode()
# functions from module python
registerXPathFunction()
# functions from module xpath
xpathEval()
xpathEvalExpression()
xpathFreeContext()
# functions from module xpathInternals
xpathNewParserContext()
xpathNsLookup()
xpathRegisterAllFunctions()
xpathRegisterNs()
xpathRegisteredFuncsCleanup()
xpathRegisteredNsCleanup()
xpathRegisteredVariablesCleanup()
xpathVariableLookup()
xpathVariableLookupNS()
# functions from module xpointer
xpointerEval()
Class xmlAttribute(xmlNode)
Class catalog()
# functions from module catalog
add()
catalogIsEmpty()
convertSGMLCatalog()
dump()
remove()
resolve()
resolvePublic()
resolveSystem()
resolveURI()
Class xmlElement(xmlNode)
Class xmlAttr(xmlNode)
......@@ -665,12 +715,100 @@ Class xmlAttr(xmlNode)
# functions from module valid
removeID()
removeRef()
Class xmlTextReader(xmlTextReaderCore)
# functions from module xmlreader
AttributeCount()
BaseUri()
Close()
CurrentDoc()
CurrentNode()
Depth()
Expand()
GetAttribute()
GetAttributeNo()
GetAttributeNs()
GetParserProp()
GetRemainder()
HasAttributes()
HasValue()
IsDefault()
IsEmptyElement()
IsValid()
LocalName()
LookupNamespace()
MoveToAttribute()
MoveToAttributeNo()
MoveToAttributeNs()
MoveToElement()
MoveToFirstAttribute()
MoveToNextAttribute()
Name()
NamespaceUri()
NewDoc()
NewFd()
NewFile()
NewMemory()
NewWalker()
Next()
NextSibling()
NodeType()
Normalization()
Prefix()
Preserve()
QuoteChar()
Read()
ReadAttributeValue()
ReadInnerXml()
ReadOuterXml()
ReadState()
ReadString()
RelaxNGSetSchema()
RelaxNGValidate()
SetParserProp()
String()
Value()
XmlLang()
Class xmlReg()
# functions from module xmlregexp
regexpExec()
regexpIsDeterminist()
regexpPrint()
Class xmlEntity(xmlNode)
# functions from module parserInternals
handleEntity()
Class relaxNgSchema()
# functions from module relaxng
relaxNGDump()
relaxNGDumpTree()
relaxNGNewValidCtxt()
# functions from module xmlreader
RelaxNGSetSchema()
Class Schema()
# functions from module xmlschemas
schemaDump()
schemaNewValidCtxt()
Class Error()
# accessors
code()
domain()
file()
level()
line()
message()
# functions from module xmlerror
copyError()
resetError()
Class relaxNgValidCtxt()
# functions from module relaxng
......@@ -679,6 +817,73 @@ Class relaxNgValidCtxt()
relaxNGValidatePopElement()
relaxNGValidatePushCData()
relaxNGValidatePushElement()
Class xpathParserContext()
# accessors
context()
# functions from module xpathInternals
xpathAddValues()
xpathBooleanFunction()
xpathCeilingFunction()
xpathCompareValues()
xpathConcatFunction()
xpathContainsFunction()
xpathCountFunction()
xpathDivValues()
xpathEqualValues()
xpathErr()
xpathEvalExpr()
xpathFalseFunction()
xpathFloorFunction()
xpathFreeParserContext()
xpathIdFunction()
xpathLangFunction()
xpathLastFunction()
xpathLocalNameFunction()
xpathModValues()
xpathMultValues()
xpathNamespaceURIFunction()
xpathNextAncestor()
xpathNextAncestorOrSelf()
xpathNextAttribute()
xpathNextChild()
xpathNextDescendant()
xpathNextDescendantOrSelf()
xpathNextFollowing()
xpathNextFollowingSibling()
xpathNextNamespace()
xpathNextParent()
xpathNextPreceding()
xpathNextPrecedingSibling()
xpathNextSelf()
xpathNormalizeFunction()
xpathNotEqualValues()
xpathNotFunction()
xpathNumberFunction()
xpathParseNCName()
xpathParseName()
xpathPopBoolean()
xpathPopNumber()
xpathPopString()
xpathPositionFunction()
xpathRoot()
xpathRoundFunction()
xpathStartsWithFunction()
xpathStringFunction()
xpathStringLengthFunction()
xpathSubValues()
xpathSubstringAfterFunction()
xpathSubstringBeforeFunction()
xpathSubstringFunction()
xpathSumFunction()
xpathTranslateFunction()
xpathTrueFunction()
xpathValueFlipSign()
xpatherror()
# functions from module xpointer
xpointerEvalRangePredicate()
xpointerRangeToFunction()
Class parserCtxt(parserCtxtCore)
......@@ -786,94 +991,6 @@ Class xmlDtd(xmlNode)
dtdElementDesc()
dtdQAttrDesc()
dtdQElementDesc()
Class relaxNgParserCtxt()
# functions from module relaxng
relaxNGParse()
relaxParserSetFlag()
Class xpathParserContext()
# accessors
context()
# functions from module xpathInternals
xpathAddValues()
xpathBooleanFunction()
xpathCeilingFunction()
xpathCompareValues()
xpathConcatFunction()
xpathContainsFunction()
xpathCountFunction()
xpathDivValues()
xpathEqualValues()
xpathErr()
xpathEvalExpr()
xpathFalseFunction()
xpathFloorFunction()
xpathFreeParserContext()
xpathIdFunction()
xpathLangFunction()
xpathLastFunction()
xpathLocalNameFunction()
xpathModValues()
xpathMultValues()
xpathNamespaceURIFunction()
xpathNextAncestor()
xpathNextAncestorOrSelf()
xpathNextAttribute()
xpathNextChild()
xpathNextDescendant()
xpathNextDescendantOrSelf()
xpathNextFollowing()
xpathNextFollowingSibling()
xpathNextNamespace()
xpathNextParent()
xpathNextPreceding()
xpathNextPrecedingSibling()
xpathNextSelf()
xpathNormalizeFunction()
xpathNotEqualValues()
xpathNotFunction()
xpathNumberFunction()
xpathParseNCName()
xpathParseName()
xpathPopBoolean()
xpathPopNumber()
xpathPopString()
xpathPositionFunction()
xpathRoot()
xpathRoundFunction()
xpathStartsWithFunction()
xpathStringFunction()
xpathStringLengthFunction()
xpathSubValues()
xpathSubstringAfterFunction()
xpathSubstringBeforeFunction()
xpathSubstringFunction()
xpathSumFunction()
xpathTranslateFunction()
xpathTrueFunction()
xpathValueFlipSign()
xpatherror()
# functions from module xpointer
xpointerEvalRangePredicate()
xpointerRangeToFunction()
Class SchemaParserCtxt()
# functions from module xmlschemas
schemaParse()
Class catalog()
# functions from module catalog
add()