You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ca...@apache.org on 2005/04/05 17:12:37 UTC
cvs commit: xml-xerces/c/src/xercesc/validators/schema TraverseSchema.cpp
cargilld 2005/04/05 08:12:37
Modified: c/src/xercesc/internal DGXMLScanner.cpp IGXMLScanner.cpp
IGXMLScanner2.cpp ReaderMgr.cpp ReaderMgr.hpp
SGXMLScanner.cpp XMLScanner.cpp
c/src/xercesc/validators/DTD DTDScanner.cpp
c/src/xercesc/validators/schema TraverseSchema.cpp
Log:
Implement support for disabling default entity resolution.
Revision Changes Path
1.63 +49 -42 xml-xerces/c/src/xercesc/internal/DGXMLScanner.cpp
Index: DGXMLScanner.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/DGXMLScanner.cpp,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -r1.62 -r1.63
--- DGXMLScanner.cpp 4 Apr 2005 15:11:37 -0000 1.62
+++ DGXMLScanner.cpp 5 Apr 2005 15:12:36 -0000 1.63
@@ -980,46 +980,48 @@
if (fUseCachedGrammar && !hasIntSubset)
{
srcUsed = resolveSystemId(sysId, pubId);
- janSrc.reset(srcUsed);
- Grammar* grammar = fGrammarResolver->getGrammar(srcUsed->getSystemId());
+ if (srcUsed) {
+ janSrc.reset(srcUsed);
+ Grammar* grammar = fGrammarResolver->getGrammar(srcUsed->getSystemId());
- if (grammar && grammar->getGrammarType() == Grammar::DTDGrammarType) {
+ if (grammar && grammar->getGrammarType() == Grammar::DTDGrammarType) {
- fDTDGrammar = (DTDGrammar*) grammar;
- fGrammar = fDTDGrammar;
- fValidator->setGrammar(fGrammar);
- // If we don't report at least the external subset boundaries,
- // an advanced document handler cannot know when the DTD end,
- // since we've already sent a doctype decl that indicates there's
- // there's an external subset.
- if (fDocTypeHandler)
- {
- fDocTypeHandler->startExtSubset();
- fDocTypeHandler->endExtSubset();
- }
- // we *cannot* identify the root element on
- // cached grammars; else we risk breaking multithreaded
- // applications. - NG
- /*******
- rootDecl = (DTDElementDecl*) fGrammar->getElemDecl(fEmptyNamespaceId, 0, bbRootName.getRawBuffer(), Grammar::TOP_LEVEL_SCOPE);
-
- if (rootDecl)
- ((DTDGrammar*)fGrammar)->setRootElemId(rootDecl->getId());
- else {
- rootDecl = new (fGrammarPoolMemoryManager) DTDElementDecl
- (
- bbRootName.getRawBuffer()
- , fEmptyNamespaceId
- , DTDElementDecl::Any
- , fGrammarPoolMemoryManager
- );
- rootDecl->setCreateReason(DTDElementDecl::AsRootElem);
- rootDecl->setExternalElemDeclaration(true);
- ((DTDGrammar*)fGrammar)->setRootElemId(fGrammar->putElemDecl(rootDecl));
- }
- *********/
+ fDTDGrammar = (DTDGrammar*) grammar;
+ fGrammar = fDTDGrammar;
+ fValidator->setGrammar(fGrammar);
+ // If we don't report at least the external subset boundaries,
+ // an advanced document handler cannot know when the DTD end,
+ // since we've already sent a doctype decl that indicates there's
+ // there's an external subset.
+ if (fDocTypeHandler)
+ {
+ fDocTypeHandler->startExtSubset();
+ fDocTypeHandler->endExtSubset();
+ }
+ // we *cannot* identify the root element on
+ // cached grammars; else we risk breaking multithreaded
+ // applications. - NG
+ /*******
+ rootDecl = (DTDElementDecl*) fGrammar->getElemDecl(fEmptyNamespaceId, 0, bbRootName.getRawBuffer(), Grammar::TOP_LEVEL_SCOPE);
+
+ if (rootDecl)
+ ((DTDGrammar*)fGrammar)->setRootElemId(rootDecl->getId());
+ else {
+ rootDecl = new (fGrammarPoolMemoryManager) DTDElementDecl
+ (
+ bbRootName.getRawBuffer()
+ , fEmptyNamespaceId
+ , DTDElementDecl::Any
+ , fGrammarPoolMemoryManager
+ );
+ rootDecl->setCreateReason(DTDElementDecl::AsRootElem);
+ rootDecl->setExternalElemDeclaration(true);
+ ((DTDGrammar*)fGrammar)->setRootElemId(fGrammar->putElemDecl(rootDecl));
+ }
+ *********/
- return;
+ return;
+ }
}
}
@@ -1035,7 +1037,7 @@
, XMLReader::RefFrom_NonLiteral
, XMLReader::Type_General
, XMLReader::Source_External
- , fCalculateSrcOfs
+ , fCalculateSrcOfs
);
}
else {
@@ -1049,12 +1051,13 @@
, XMLReader::Source_External
, srcUsed
, fCalculateSrcOfs
+ , fDisableDefaultEntityResolution
);
janSrc.reset(srcUsed);
}
// If it failed then throw an exception
if (!reader)
- ThrowXMLwithMemMgr1(RuntimeException, XMLExcepts::Gen_CouldNotOpenDTD, srcUsed->getSystemId(), fMemoryManager);
+ ThrowXMLwithMemMgr1(RuntimeException, XMLExcepts::Gen_CouldNotOpenDTD, srcUsed ? srcUsed->getSystemId() : sysId, fMemoryManager);
if (fToCacheGrammar) {
@@ -2479,7 +2482,7 @@
fReaderMgr.getLastExtEntityInfo(lastInfo);
XMLResourceIdentifier resourceIdentifier(XMLResourceIdentifier::ExternalEntity,
expSysId.getRawBuffer(), 0, pubId, lastInfo.systemId);
- srcToFill = fEntityHandler->resolveEntity(&resourceIdentifier);
+ srcToFill = fEntityHandler->resolveEntity(&resourceIdentifier);
}
else
{
@@ -2490,6 +2493,9 @@
// have to create one on our own.
if (!srcToFill)
{
+ if (fDisableDefaultEntityResolution)
+ return srcToFill;
+
ReaderMgr::LastExtEntityInfo lastInfo;
fReaderMgr.getLastExtEntityInfo(lastInfo);
@@ -3222,6 +3228,7 @@
, XMLReader::Source_External
, srcUsed
, fCalculateSrcOfs
+ , fDisableDefaultEntityResolution
);
// Put a janitor on the source so it gets cleaned up on exit
@@ -3230,7 +3237,7 @@
// If the creation failed, and its not because the source was empty,
// then emit an error and return.
if (!reader)
- ThrowXMLwithMemMgr1(RuntimeException, XMLExcepts::Gen_CouldNotOpenExtEntity, srcUsed->getSystemId(), fMemoryManager);
+ ThrowXMLwithMemMgr1(RuntimeException, XMLExcepts::Gen_CouldNotOpenExtEntity, srcUsed ? srcUsed->getSystemId() : decl->getSystemId(), fMemoryManager);
// Push the reader. If its a recursive expansion, then emit an error
// and return an failure.
1.90 +39 -36 xml-xerces/c/src/xercesc/internal/IGXMLScanner.cpp
Index: IGXMLScanner.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/IGXMLScanner.cpp,v
retrieving revision 1.89
retrieving revision 1.90
diff -u -r1.89 -r1.90
--- IGXMLScanner.cpp 5 Apr 2005 14:05:04 -0000 1.89
+++ IGXMLScanner.cpp 5 Apr 2005 15:12:36 -0000 1.90
@@ -1432,44 +1432,46 @@
if (fUseCachedGrammar && !hasIntSubset)
{
srcUsed = resolveSystemId(sysId, pubId);
- janSrc.reset(srcUsed);
- Grammar* grammar = fGrammarResolver->getGrammar(srcUsed->getSystemId());
+ if (srcUsed) {
+ janSrc.reset(srcUsed);
+ Grammar* grammar = fGrammarResolver->getGrammar(srcUsed->getSystemId());
- if (grammar && grammar->getGrammarType() == Grammar::DTDGrammarType) {
+ if (grammar && grammar->getGrammarType() == Grammar::DTDGrammarType) {
- fDTDGrammar = (DTDGrammar*) grammar;
- fGrammar = fDTDGrammar;
- fValidator->setGrammar(fGrammar);
- // If we don't report at least the external subset boundaries,
- // an advanced document handler cannot know when the DTD end,
- // since we've already sent a doctype decl that indicates there's
- // there's an external subset.
- if (fDocTypeHandler)
- {
- fDocTypeHandler->startExtSubset();
- fDocTypeHandler->endExtSubset();
- }
- // should not be modifying cached grammars!
- /********
- rootDecl = (DTDElementDecl*) fGrammar->getElemDecl(fEmptyNamespaceId, 0, bbRootName.getRawBuffer(), Grammar::TOP_LEVEL_SCOPE);
+ fDTDGrammar = (DTDGrammar*) grammar;
+ fGrammar = fDTDGrammar;
+ fValidator->setGrammar(fGrammar);
+ // If we don't report at least the external subset boundaries,
+ // an advanced document handler cannot know when the DTD end,
+ // since we've already sent a doctype decl that indicates there's
+ // there's an external subset.
+ if (fDocTypeHandler)
+ {
+ fDocTypeHandler->startExtSubset();
+ fDocTypeHandler->endExtSubset();
+ }
+ // should not be modifying cached grammars!
+ /********
+ rootDecl = (DTDElementDecl*) fGrammar->getElemDecl(fEmptyNamespaceId, 0, bbRootName.getRawBuffer(), Grammar::TOP_LEVEL_SCOPE);
- if (rootDecl)
- ((DTDGrammar*)fGrammar)->setRootElemId(rootDecl->getId());
- else {
- rootDecl = new (fGrammarPoolMemoryManager) DTDElementDecl
- (
- bbRootName.getRawBuffer()
- , fEmptyNamespaceId
- , DTDElementDecl::Any
- , fGrammarPoolMemoryManager
- );
- rootDecl->setCreateReason(DTDElementDecl::AsRootElem);
- rootDecl->setExternalElemDeclaration(true);
- ((DTDGrammar*)fGrammar)->setRootElemId(fGrammar->putElemDecl(rootDecl));
- }
- ********/
+ if (rootDecl)
+ ((DTDGrammar*)fGrammar)->setRootElemId(rootDecl->getId());
+ else {
+ rootDecl = new (fGrammarPoolMemoryManager) DTDElementDecl
+ (
+ bbRootName.getRawBuffer()
+ , fEmptyNamespaceId
+ , DTDElementDecl::Any
+ , fGrammarPoolMemoryManager
+ );
+ rootDecl->setCreateReason(DTDElementDecl::AsRootElem);
+ rootDecl->setExternalElemDeclaration(true);
+ ((DTDGrammar*)fGrammar)->setRootElemId(fGrammar->putElemDecl(rootDecl));
+ }
+ ********/
- return;
+ return;
+ }
}
}
@@ -1499,12 +1501,13 @@
, XMLReader::Source_External
, srcUsed
, fCalculateSrcOfs
+ , fDisableDefaultEntityResolution
);
janSrc.reset(srcUsed);
}
// If it failed then throw an exception
if (!reader)
- ThrowXMLwithMemMgr1(RuntimeException, XMLExcepts::Gen_CouldNotOpenDTD, srcUsed->getSystemId(), fMemoryManager);
+ ThrowXMLwithMemMgr1(RuntimeException, XMLExcepts::Gen_CouldNotOpenDTD, srcUsed ? srcUsed->getSystemId() : sysId, fMemoryManager);
if (fToCacheGrammar) {
1.85 +9 -2 xml-xerces/c/src/xercesc/internal/IGXMLScanner2.cpp
Index: IGXMLScanner2.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/IGXMLScanner2.cpp,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -r1.84 -r1.85
--- IGXMLScanner2.cpp 5 Apr 2005 14:05:04 -0000 1.84
+++ IGXMLScanner2.cpp 5 Apr 2005 15:12:36 -0000 1.85
@@ -1708,6 +1708,9 @@
// have to create one on our own.
if (!srcToFill)
{
+ if (fDisableDefaultEntityResolution)
+ return;
+
ReaderMgr::LastExtEntityInfo lastInfo;
fReaderMgr.getLastExtEntityInfo(lastInfo);
@@ -1891,6 +1894,9 @@
// have to create one on our own.
if (!srcToFill)
{
+ if (fDisableDefaultEntityResolution)
+ return srcToFill;
+
ReaderMgr::LastExtEntityInfo lastInfo;
fReaderMgr.getLastExtEntityInfo(lastInfo);
@@ -2939,6 +2945,7 @@
, XMLReader::Source_External
, srcUsed
, fCalculateSrcOfs
+ , fDisableDefaultEntityResolution
);
// Put a janitor on the source so it gets cleaned up on exit
@@ -2947,7 +2954,7 @@
// If the creation failed, and its not because the source was empty,
// then emit an error and return.
if (!reader)
- ThrowXMLwithMemMgr1(RuntimeException, XMLExcepts::Gen_CouldNotOpenExtEntity, srcUsed->getSystemId(), fMemoryManager);
+ ThrowXMLwithMemMgr1(RuntimeException, XMLExcepts::Gen_CouldNotOpenExtEntity, srcUsed ? srcUsed->getSystemId() : decl->getSystemId(), fMemoryManager);
// Push the reader. If its a recursive expansion, then emit an error
// and return an failure.
1.29 +11 -3 xml-xerces/c/src/xercesc/internal/ReaderMgr.cpp
Index: ReaderMgr.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/ReaderMgr.cpp,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- ReaderMgr.cpp 8 Sep 2004 13:56:13 -0000 1.28
+++ ReaderMgr.cpp 5 Apr 2005 15:12:36 -0000 1.29
@@ -465,7 +465,8 @@
, const XMLReader::Types type
, const XMLReader::Sources source
, InputSource*& srcToFill
- , const bool calcSrcOfs)
+ , const bool calcSrcOfs
+ , const bool disableDefaultEntityResolution)
{
//Normalize sysId
XMLBuffer normalizedSysId(1023, fMemoryManager);
@@ -506,6 +507,9 @@
//
if (!srcToFill)
{
+ if (disableDefaultEntityResolution)
+ return 0;
+
LastExtEntityInfo lastInfo;
getLastExtEntityInfo(lastInfo);
@@ -612,7 +616,8 @@
, const XMLReader::Types type
, const XMLReader::Sources source
, InputSource*& srcToFill
- , const bool calcSrcOfs)
+ , const bool calcSrcOfs
+ , const bool disableDefaultEntityResolution)
{
//Normalize sysId
XMLBuffer normalizedSysId(1023, fMemoryManager);
@@ -651,6 +656,9 @@
//
if (!srcToFill)
{
+ if (disableDefaultEntityResolution)
+ return 0;
+
LastExtEntityInfo lastInfo;
const XMLCh* baseuri=baseURI;
1.18 +5 -0 xml-xerces/c/src/xercesc/internal/ReaderMgr.hpp
Index: ReaderMgr.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/ReaderMgr.hpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- ReaderMgr.hpp 4 Apr 2005 15:11:38 -0000 1.17
+++ ReaderMgr.hpp 5 Apr 2005 15:12:36 -0000 1.18
@@ -16,6 +16,9 @@
/*
* $Log$
+ * Revision 1.18 2005/04/05 15:12:36 cargilld
+ * Implement support for disabling default entity resolution.
+ *
* Revision 1.17 2005/04/04 15:11:38 cargilld
* Fix a problem where illegal qualified names were not reported as errors. Also store the colon position when searching for a qualified name to avoid looking it up again.
*
@@ -233,6 +236,7 @@
, const XMLReader::Sources source
, InputSource*& srcToFill
, const bool calcSrcOfs = true
+ , const bool disableDefaultEntityResolution = false
);
XMLReader* createReader
(
@@ -245,6 +249,7 @@
, const XMLReader::Sources source
, InputSource*& srcToFill
, const bool calcSrcOfs = true
+ , const bool disableDefaultEntityResolution = false
);
XMLReader* createIntEntReader
(
1.111 +7 -1 xml-xerces/c/src/xercesc/internal/SGXMLScanner.cpp
Index: SGXMLScanner.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/SGXMLScanner.cpp,v
retrieving revision 1.110
retrieving revision 1.111
diff -u -r1.110 -r1.111
--- SGXMLScanner.cpp 4 Apr 2005 15:11:38 -0000 1.110
+++ SGXMLScanner.cpp 5 Apr 2005 15:12:36 -0000 1.111
@@ -3553,6 +3553,9 @@
// have to create one on our own.
if (!srcToFill)
{
+ if (fDisableDefaultEntityResolution)
+ return;
+
ReaderMgr::LastExtEntityInfo lastInfo;
fReaderMgr.getLastExtEntityInfo(lastInfo);
@@ -3715,6 +3718,9 @@
// have to create one on our own.
if (!srcToFill)
{
+ if (fDisableDefaultEntityResolution)
+ return 0;
+
ReaderMgr::LastExtEntityInfo lastInfo;
fReaderMgr.getLastExtEntityInfo(lastInfo);
1.81 +10 -6 xml-xerces/c/src/xercesc/internal/XMLScanner.cpp
Index: XMLScanner.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/XMLScanner.cpp,v
retrieving revision 1.80
retrieving revision 1.81
diff -u -r1.80 -r1.81
--- XMLScanner.cpp 1 Apr 2005 09:23:31 -0000 1.80
+++ XMLScanner.cpp 5 Apr 2005 15:12:36 -0000 1.81
@@ -1630,6 +1630,8 @@
// First we try to parse it as a URL. If that fails, we assume its
// a file and try it that way.
if (!srcToUse) {
+ if (fDisableDefaultEntityResolution)
+ return 0;
try
{
@@ -1776,12 +1778,14 @@
if (fUseCachedGrammar && hasExtSubset && !fIgnoreCachedDTD)
{
InputSource* sysIdSrc = resolveSystemId(sysId, pubId);
- Janitor<InputSource> janSysIdSrc(sysIdSrc);
- Grammar* grammar = fGrammarResolver->getGrammar(sysIdSrc->getSystemId());
+ if (sysIdSrc) {
+ Janitor<InputSource> janSysIdSrc(sysIdSrc);
+ Grammar* grammar = fGrammarResolver->getGrammar(sysIdSrc->getSystemId());
- if (grammar && grammar->getGrammarType() == Grammar::DTDGrammarType)
- {
- ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Val_CantHaveIntSS, fMemoryManager);
+ if (grammar && grammar->getGrammarType() == Grammar::DTDGrammarType)
+ {
+ ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Val_CantHaveIntSS, fMemoryManager);
+ }
}
}
1.39 +9 -2 xml-xerces/c/src/xercesc/validators/DTD/DTDScanner.cpp
Index: DTDScanner.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/DTD/DTDScanner.cpp,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- DTDScanner.cpp 20 Mar 2005 19:02:45 -0000 1.38
+++ DTDScanner.cpp 5 Apr 2005 15:12:36 -0000 1.39
@@ -16,6 +16,9 @@
/*
* $Log$
+ * Revision 1.39 2005/04/05 15:12:36 cargilld
+ * Implement support for disabling default entity resolution.
+ *
* Revision 1.38 2005/03/20 19:02:45 cargilld
* Implement versions of uppercase and compareIstring that only check a to z, instead of all characters, and don't rely on functionality provided in the transcoders.
*
@@ -464,6 +467,8 @@
, XMLReader::Type_PE
, XMLReader::Source_External
, srcUsed
+ , fScanner->getCalculateSrcOfs()
+ , fScanner->getDisableDefaultEntityResolution()
);
// Put a janitor on the source so its cleaned up on exit
@@ -471,7 +476,7 @@
// If the creation failed then throw an exception
if (!reader)
- ThrowXMLwithMemMgr1(RuntimeException, XMLExcepts::Gen_CouldNotOpenExtEntity, srcUsed->getSystemId(), fMemoryManager);
+ ThrowXMLwithMemMgr1(RuntimeException, XMLExcepts::Gen_CouldNotOpenExtEntity, srcUsed ? srcUsed->getSystemId() : decl->getSystemId(), fMemoryManager);
// Set the 'throw at end' flag, to the one we were given
reader->setThrowAtEnd(throwEndOfExt);
@@ -2196,6 +2201,8 @@
, XMLReader::Type_General
, XMLReader::Source_External
, srcUsed
+ , fScanner->getCalculateSrcOfs()
+ , fScanner->getDisableDefaultEntityResolution()
);
// Put a janitor on the source so it gets cleaned up on exit
@@ -2205,7 +2212,7 @@
// If the creation failed then throw an exception
//
if (!reader)
- ThrowXMLwithMemMgr1(RuntimeException, XMLExcepts::Gen_CouldNotOpenExtEntity, srcUsed->getSystemId(), fMemoryManager);
+ ThrowXMLwithMemMgr1(RuntimeException, XMLExcepts::Gen_CouldNotOpenExtEntity, srcUsed ? srcUsed->getSystemId() : decl->getSystemId(), fMemoryManager);
//
// Push the reader. If its a recursive expansion, then emit an error
1.135 +4 -1 xml-xerces/c/src/xercesc/validators/schema/TraverseSchema.cpp
Index: TraverseSchema.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/schema/TraverseSchema.cpp,v
retrieving revision 1.134
retrieving revision 1.135
diff -u -r1.134 -r1.135
--- TraverseSchema.cpp 31 Mar 2005 10:45:58 -0000 1.134
+++ TraverseSchema.cpp 5 Apr 2005 15:12:36 -0000 1.135
@@ -6632,6 +6632,9 @@
// the update resolveEntity accepting nameSpace, a schemImport could
// pass a null schemaLocation)
if (!srcToFill && loc) {
+ if (fScanner->getDisableDefaultEntityResolution())
+ return 0;
+
XMLURL urlTmp(fMemoryManager);
if ((!urlTmp.setURL(fSchemaInfo->getCurrentSchemaURL(), normalizedURI, urlTmp)) ||
(urlTmp.isRelative()))
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org