From 437e139f4c5851d72f03774952f149539dabcd09 Mon Sep 17 00:00:00 2001 From: "Zane U. Ji" Date: Mon, 23 Dec 2013 22:12:10 +0800 Subject: [PATCH] Feature #166 Network access cannot be disabled --- src/mypropertysheet.cpp | 2 +- src/wrapxerces.cpp | 26 ++++++++++++++++++++---- src/wrapxerces.h | 6 +++++- src/xmlcopyeditor.cpp | 41 +++++++++++++++++++------------------- src/xmlschemagenerator.cpp | 1 - 5 files changed, 49 insertions(+), 27 deletions(-) diff --git a/src/mypropertysheet.cpp b/src/mypropertysheet.cpp index 78a32d3..265291b 100644 --- a/src/mypropertysheet.cpp +++ b/src/mypropertysheet.cpp @@ -190,7 +190,7 @@ MyPropertySheet::MyPropertySheet ( } libxmlNetAccessBox = new wxCheckBox ( - generalPanel, wxID_ANY, _ ( "&Enable network access for DTD validation" ) ); + generalPanel, wxID_ANY, _ ( "&Enable network access for XML validation" ) ); libxmlNetAccessBox->SetValue ( libxmlNetAccessParameter ); expandInternalEntitiesBox = new wxCheckBox ( generalPanel, wxID_ANY, _ ( "E&xpand internal entities on open" ) ); diff --git a/src/wrapxerces.cpp b/src/wrapxerces.cpp index 78f65cb..dcd8d45 100644 --- a/src/wrapxerces.cpp +++ b/src/wrapxerces.cpp @@ -33,26 +33,29 @@ using namespace xercesc; -void WrapXerces::Init() throw() +XMLNetAccessor *WrapXerces::mOriginalNetAccessor = NULL; + +void WrapXerces::Init ( bool enableNetAccess ) throw() { static class Initializer { public: - Initializer() + Initializer () { XMLPlatformUtils::Initialize(); + mOriginalNetAccessor = XMLPlatformUtils::fgNetAccessor; } ~Initializer() { XMLPlatformUtils::Terminate(); } } dummy; + + enableNetwork ( enableNetAccess ); } WrapXerces::WrapXerces() { - WrapXerces::Init(); - catalogResolver = new XercesCatalogResolver(); } @@ -206,6 +209,21 @@ wxMemoryBuffer WrapXerces::toString ( const wxString &str ) return buffer; } +bool WrapXerces::enableNetwork ( bool enable /*= true*/ ) +{ + bool ret = XMLPlatformUtils::fgNetAccessor != NULL; + if ( enable ) + { + wxASSERT ( mOriginalNetAccessor != NULL ); + XMLPlatformUtils::fgNetAccessor = mOriginalNetAccessor; + } + else + { + XMLPlatformUtils::fgNetAccessor = NULL; + } + return ret; +} + void MySAX2Handler::logError ( const wxString &type, wxLogLevel level, const SAXParseException& e ) { diff --git a/src/wrapxerces.h b/src/wrapxerces.h index db324fd..7038816 100644 --- a/src/wrapxerces.h +++ b/src/wrapxerces.h @@ -94,7 +94,8 @@ class MySAX2Handler : public DefaultHandler class WrapXerces : private boost::noncopyable { public: - static void Init() throw (); + static void Init ( bool enableNetAccess ) throw (); + WrapXerces(); virtual ~WrapXerces(); bool validate ( const wxString &fileName ); @@ -118,9 +119,12 @@ class WrapXerces : private boost::noncopyable //#else static wxMemoryBuffer toString ( const wxString &str ); //#endif + // Returns original value + static bool enableNetwork ( bool enable = true ); private: static const wxMBConv &getMBConv(); + static XMLNetAccessor *mOriginalNetAccessor; XercesCatalogResolver *catalogResolver; MySAX2Handler mySAX2Handler; diff --git a/src/xmlcopyeditor.cpp b/src/xmlcopyeditor.cpp index 9a97bdf..2aff0dc 100644 --- a/src/xmlcopyeditor.cpp +++ b/src/xmlcopyeditor.cpp @@ -375,9 +375,6 @@ bool MyApp::OnInit() wxImage::AddHandler ( new wxPNGHandler ); wxSystemOptions::SetOption ( _T ( "msw.remap" ), 0 ); - // Initialize Xerces-C++ - WrapXerces::Init(); - frame = new MyFrame ( _ ( "XML Copy Editor" ), config.get(), @@ -841,23 +838,6 @@ MyFrame::MyFrame ( xercescSSE2Warning = true; } - if ( XMLPlatformUtils::fgSSE2ok - && xercescSSE2Warning - && wxTheApp->argc == 1 ) - { - xercescSSE2Warning = wxMessageBox ( - _ ("SSE2 is enabled in Xerces-C++ library. Xerces-C++ didn't "\ - "use them in a thread-safe way. It may cause program crashes "\ - "(segmentation faults).\n\n"\ - "If it happens, please try compiling Xerces-C++ with SSE2 "\ - "disabled.\n\n"\ - "OK:\tShow this warning next time\n"\ - "Cancel:\tDisable the warning\n"), - _ ("SSE2 problem in Xerces-C++"), - wxOK | wxCANCEL | wxICON_WARNING - ) == wxOK; - } - largeFileProperties.completion = false; largeFileProperties.fold = false; largeFileProperties.whitespaceVisible = false; @@ -881,6 +861,26 @@ MyFrame::MyFrame ( // Initialize libxml WrapLibxml::Init ( catalogPath ); + // Initialize Xerces-C++ + WrapXerces::Init ( libxmlNetAccess ); + + if ( XMLPlatformUtils::fgSSE2ok + && xercescSSE2Warning + && wxTheApp->argc == 1 ) + { + xercescSSE2Warning = wxMessageBox ( + _ ("SSE2 is enabled in Xerces-C++ library. Xerces-C++ didn't "\ + "use them in a thread-safe way. It may cause program crashes "\ + "(segmentation faults).\n\n"\ + "If it happens, please try compiling Xerces-C++ with SSE2 "\ + "disabled.\n\n"\ + "OK:\tShow this warning next time\n"\ + "Cancel:\tDisable the warning\n"), + _ ("SSE2 problem in Xerces-C++"), + wxOK | wxCANCEL | wxICON_WARNING + ) == wxOK; + } + size_t findFlags = 0; findFlags |= wxFR_DOWN; @@ -2597,6 +2597,7 @@ void MyFrame::OnOptions ( wxCommandEvent& WXUNUSED ( event ) ) title ) ); if ( mpsd->ShowModal() == wxID_OK ) { + WrapXerces::enableNetwork ( libxmlNetAccess ); applyEditorProperties(); updatePaths(); } diff --git a/src/xmlschemagenerator.cpp b/src/xmlschemagenerator.cpp index 63135eb..a090821 100644 --- a/src/xmlschemagenerator.cpp +++ b/src/xmlschemagenerator.cpp @@ -34,7 +34,6 @@ XmlSchemaGenerator::XmlSchemaGenerator ( bool inlineSimpleType /*= true*/) : mInlineSimpleType ( inlineSimpleType ) , mGrammarType ( Grammar::SchemaGrammarType ) { - WrapXerces::Init(); } XmlSchemaGenerator::~XmlSchemaGenerator()