Feature #166 Network access cannot be disabled

This commit is contained in:
Zane U. Ji 2013-12-23 22:12:10 +08:00
parent 27b5ba800c
commit 437e139f4c
5 changed files with 49 additions and 27 deletions

View File

@ -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" ) );

View File

@ -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 )
{

View File

@ -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;

View File

@ -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();
}

View File

@ -34,7 +34,6 @@ XmlSchemaGenerator::XmlSchemaGenerator ( bool inlineSimpleType /*= true*/)
: mInlineSimpleType ( inlineSimpleType )
, mGrammarType ( Grammar::SchemaGrammarType )
{
WrapXerces::Init();
}
XmlSchemaGenerator::~XmlSchemaGenerator()