From fa5e760c826df739bf6f8c6c80957712ffc5ac8e Mon Sep 17 00:00:00 2001 From: "Zane U. Ji" Date: Thu, 24 Apr 2014 22:47:21 +0800 Subject: [PATCH] Resolve DTDs explicitly before loading them --- src/xmlpromptgenerator.cpp | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/xmlpromptgenerator.cpp b/src/xmlpromptgenerator.cpp index 3096291..fd9f65b 100644 --- a/src/xmlpromptgenerator.cpp +++ b/src/xmlpromptgenerator.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include "xmlpromptgenerator.h" #include "xmlencodinghandler.h" @@ -306,20 +307,42 @@ int XMLCALL XmlPromptGenerator::externalentityrefhandler ( parser.setDoSchema ( true ); parser.setValidationSchemaFullChecking ( true ); + MySAX2Handler handler; XercesCatalogResolver catalogResolver; + parser.setErrorHandler ( &handler ); parser.setEntityResolver ( &catalogResolver ); wxString wideSystemId ( systemId, wxConvUTF8 ); // TODO: Apply encoding wxString widePublicId ( publicId, wxConvUTF8 ); - URLInputSource source - ( ( const XMLCh * ) WrapXerces::toString ( d->basePath ).GetData() + std::auto_ptr source ( catalogResolver.resolveEntity + ( ( const XMLCh * ) WrapXerces::toString ( widePublicId ).GetData() + , ( const XMLCh * ) WrapXerces::toString ( wideSystemId ).GetData() + ) ); + if ( !source.get() ) + { + wxString fileURL = wxFileSystem::FileNameToURL ( d->basePath ); + source.reset ( new URLInputSource + ( ( const XMLCh * ) WrapXerces::toString ( fileURL ).GetData() , ( const XMLCh * ) WrapXerces::toString ( wideSystemId ).GetData() , ( const XMLCh * ) WrapXerces::toString ( widePublicId ).GetData() - ); - Grammar *rootGrammar = parser.loadGrammar ( source, Grammar::DTDGrammarType ); - if ( !rootGrammar ) + ) ); + } + + if ( pThis->TestDestroy() ) return XML_STATUS_ERROR; + Grammar *rootGrammar; + try { + rootGrammar = parser.loadGrammar ( *source, Grammar::DTDGrammarType ); + if ( !rootGrammar ) + return XML_STATUS_ERROR; + } + catch ( SAXParseException& e ) + { + wxLogError ( _T ( "%s" ), handler.getErrors().c_str() ); + return XML_STATUS_ERROR; + } + DTDGrammar* grammar = ( DTDGrammar* ) rootGrammar; NameIdPoolEnumerator elemEnum = grammar->getElemEnumerator();