Skip to content

Commit

Permalink
xml: Hide expat and ParserEngine from user
Browse files Browse the repository at this point in the history
Hide expat completly from user. This way we do not need to publish
expat.h or expat_external.h.

I move also headers to orignal locations so diff is smaller compared to
original.
  • Loading branch information
Kari Argillander committed Jun 7, 2024
1 parent 618c51f commit adf16f1
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 70 deletions.
1 change: 0 additions & 1 deletion PocoDoc/cfg/mkdoc-poco.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
</include>
<exclude>
*_*.h,
expat*.h,
</exclude>
</files>
<pages>
Expand Down
1 change: 0 additions & 1 deletion PocoDoc/cfg/mkdocumentation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
</include>
<exclude>
*_*.h,
expat*.h,
${PocoBuild}/Util/include/Poco/Util/Units.h
</exclude>
</files>
Expand Down
16 changes: 6 additions & 10 deletions XML/XML_vs90.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -1168,30 +1168,26 @@
Name="Expat"
>
<Filter
Name="Header Files"
Name="Source Files"
>
<File
RelativePath=".\include\Poco\Xml\expat.h"
RelativePath=".\src\ascii.h"
>
</File>
<File
RelativePath=".\include\Poco\Xml\expat_external.h"
RelativePath=".\src\asciitab.h"
>
</File>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\ascii.h"
RelativePath=".\src\expat.h"
>
</File>
<File
RelativePath=".\src\asciitab.h"
RelativePath=".\src\expat_config.h"
>
</File>
<File
RelativePath=".\src\expat_config.h"
RelativePath=".\src\expat_external.h"
>
</File>
<File
Expand Down
7 changes: 5 additions & 2 deletions XML/include/Poco/SAX/SAXParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@

#include "Poco/XML/XML.h"
#include "Poco/SAX/XMLReader.h"
#include "Poco/XML/ParserEngine.h"
#include "Poco/TextEncoding.h"


namespace Poco {
namespace XML {


class ParserEngine;


class XML_API SAXParser: public XMLReader
/// This class provides a SAX2 (Simple API for XML) interface to expat,
/// the XML parser toolkit.
Expand Down Expand Up @@ -101,7 +104,7 @@ class XML_API SAXParser: public XMLReader
void setupParse();

private:
ParserEngine _engine;
ParserEngine* _engine;
bool _namespaces;
bool _namespacePrefixes;
};
Expand Down
21 changes: 10 additions & 11 deletions XML/include/Poco/XML/XMLStreamParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,17 @@
#include "Poco/XML/QName.h"
#include "Poco/XML/ValueTraits.h"
#include "Poco/XML/Content.h"
#if defined(POCO_UNBUNDLED)
#include <expat.h>
#else
#include "Poco/XML/expat.h"
#endif
#include "Poco/XML/XMLString.h"
#include <map>
#include <vector>
#include <string>
#include <iosfwd>
#include <cstddef>


struct XML_ParserStruct;


namespace Poco {
namespace XML {

Expand Down Expand Up @@ -269,11 +268,11 @@ class XML_API XMLStreamParser
XMLStreamParser(const XMLStreamParser&);
XMLStreamParser& operator = (const XMLStreamParser&);

static void XMLCALL handleStartElement(void*, const XML_Char*, const XML_Char**);
static void XMLCALL handleEndElement(void*, const XML_Char*);
static void XMLCALL handleCharacters(void*, const XML_Char*, int);
static void XMLCALL handleStartNamespaceDecl(void*, const XML_Char*, const XML_Char*);
static void XMLCALL handleEndNamespaceDecl(void*, const XML_Char*);
static void handleStartElement(void*, const XMLChar*, const XMLChar**);
static void handleEndElement(void*, const XMLChar*);
static void handleCharacters(void*, const XMLChar*, int);
static void handleStartNamespaceDecl(void*, const XMLChar*, const XMLChar*);
static void handleEndNamespaceDecl(void*, const XMLChar*);

void init();
EventType nextImpl(bool peek);
Expand All @@ -299,7 +298,7 @@ class XML_API XMLStreamParser
std::size_t _size;
const std::string _inputName;
FeatureType _feature;
XML_Parser _parser;
XML_ParserStruct* _parser;
std::size_t _depth;
bool _accumulateContent; // Whether we are accumulating character content.
ParserState _parserState;
Expand Down
2 changes: 1 addition & 1 deletion XML/src/ParserEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//


#include "Poco/XML/ParserEngine.h"
#include "ParserEngine.h"
#include "Poco/XML/NamespaceStrategy.h"
#include "Poco/XML/XMLException.h"
#include "Poco/SAX/EntityResolver.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#if defined(POCO_UNBUNDLED)
#include <expat.h>
#else
#include "Poco/XML/expat.h"
#include "expat.h"
#endif
#include "Poco/XML/XMLString.h"
#include "Poco/XML/XMLStream.h"
Expand Down
63 changes: 33 additions & 30 deletions XML/src/SAXParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "Poco/SAX/InputSource.h"
#include "Poco/XML/NamespaceStrategy.h"
#include "Poco/NumberParser.h"
#include "ParserEngine.h"
#include <sstream>


Expand All @@ -34,85 +35,87 @@ SAXParser::SAXParser():
_namespaces(true),
_namespacePrefixes(false)
{
_engine = new ParserEngine;
}


SAXParser::SAXParser(const XMLString& encoding):
_engine(encoding),
_namespaces(true),
_namespacePrefixes(false)
{
_engine = new ParserEngine(encoding);
}


SAXParser::~SAXParser()
{
delete _engine;
}


void SAXParser::setEncoding(const XMLString& encoding)
{
_engine.setEncoding(encoding);
_engine->setEncoding(encoding);
}


const XMLString& SAXParser::getEncoding() const
{
return _engine.getEncoding();
return _engine->getEncoding();
}


void SAXParser::addEncoding(const XMLString& name, Poco::TextEncoding* pEncoding)
{
_engine.addEncoding(name, pEncoding);
_engine->addEncoding(name, pEncoding);
}


void SAXParser::setEntityResolver(EntityResolver* pResolver)
{
_engine.setEntityResolver(pResolver);
_engine->setEntityResolver(pResolver);
}


EntityResolver* SAXParser::getEntityResolver() const
{
return _engine.getEntityResolver();
return _engine->getEntityResolver();
}


void SAXParser::setDTDHandler(DTDHandler* pDTDHandler)
{
_engine.setDTDHandler(pDTDHandler);
_engine->setDTDHandler(pDTDHandler);
}


DTDHandler* SAXParser::getDTDHandler() const
{
return _engine.getDTDHandler();
return _engine->getDTDHandler();
}


void SAXParser::setContentHandler(ContentHandler* pContentHandler)
{
_engine.setContentHandler(pContentHandler);
_engine->setContentHandler(pContentHandler);
}


ContentHandler* SAXParser::getContentHandler() const
{
return _engine.getContentHandler();
return _engine->getContentHandler();
}


void SAXParser::setErrorHandler(ErrorHandler* pErrorHandler)
{
_engine.setErrorHandler(pErrorHandler);
_engine->setErrorHandler(pErrorHandler);
}


ErrorHandler* SAXParser::getErrorHandler() const
{
return _engine.getErrorHandler();
return _engine->getErrorHandler();
}


Expand All @@ -121,15 +124,15 @@ void SAXParser::setFeature(const XMLString& featureId, bool state)
if (featureId == XMLReader::FEATURE_VALIDATION || featureId == XMLReader::FEATURE_STRING_INTERNING)
throw SAXNotSupportedException(fromXMLString(XMLReader::FEATURE_VALIDATION));
else if (featureId == XMLReader::FEATURE_EXTERNAL_GENERAL_ENTITIES)
_engine.setExternalGeneralEntities(state);
_engine->setExternalGeneralEntities(state);
else if (featureId == XMLReader::FEATURE_EXTERNAL_PARAMETER_ENTITIES)
_engine.setExternalParameterEntities(state);
_engine->setExternalParameterEntities(state);
else if (featureId == XMLReader::FEATURE_NAMESPACES)
_namespaces = state;
else if (featureId == XMLReader::FEATURE_NAMESPACE_PREFIXES)
_namespacePrefixes = state;
else if (featureId == FEATURE_PARTIAL_READS)
_engine.setEnablePartialReads(state);
_engine->setEnablePartialReads(state);
else throw SAXNotRecognizedException(fromXMLString(featureId));
}

Expand All @@ -139,15 +142,15 @@ bool SAXParser::getFeature(const XMLString& featureId) const
if (featureId == XMLReader::FEATURE_VALIDATION || featureId == XMLReader::FEATURE_STRING_INTERNING)
throw SAXNotSupportedException(fromXMLString(XMLReader::FEATURE_VALIDATION));
else if (featureId == XMLReader::FEATURE_EXTERNAL_GENERAL_ENTITIES)
return _engine.getExternalGeneralEntities();
return _engine->getExternalGeneralEntities();
else if (featureId == XMLReader::FEATURE_EXTERNAL_PARAMETER_ENTITIES)
return _engine.getExternalParameterEntities();
return _engine->getExternalParameterEntities();
else if (featureId == XMLReader::FEATURE_NAMESPACES)
return _namespaces;
else if (featureId == XMLReader::FEATURE_NAMESPACE_PREFIXES)
return _namespacePrefixes;
else if (featureId == FEATURE_PARTIAL_READS)
return _engine.getEnablePartialReads();
return _engine->getEnablePartialReads();
else throw SAXNotRecognizedException(fromXMLString(featureId));
}

Expand All @@ -157,9 +160,9 @@ void SAXParser::setProperty(const XMLString& propertyId, const XMLString& value)
if (propertyId == XMLReader::PROPERTY_DECLARATION_HANDLER || propertyId == XMLReader::PROPERTY_LEXICAL_HANDLER)
throw SAXNotSupportedException(std::string("property does not take a string value: ") + fromXMLString(propertyId));
else if (propertyId == PROPERTY_BLA_MAXIMUM_AMPLIFICATION)
_engine.setBillionLaughsAttackProtectionMaximumAmplification(static_cast<float>(Poco::NumberParser::parseFloat(value)));
_engine->setBillionLaughsAttackProtectionMaximumAmplification(static_cast<float>(Poco::NumberParser::parseFloat(value)));
else if (propertyId == PROPERTY_BLA_ACTIVATION_THRESHOLD)
_engine.setBillionLaughsAttackProtectionActivationThreshold(Poco::NumberParser::parseUnsigned64(value));
_engine->setBillionLaughsAttackProtectionActivationThreshold(Poco::NumberParser::parseUnsigned64(value));
else
throw SAXNotRecognizedException(fromXMLString(propertyId));
}
Expand All @@ -168,19 +171,19 @@ void SAXParser::setProperty(const XMLString& propertyId, const XMLString& value)
void SAXParser::setProperty(const XMLString& propertyId, void* value)
{
if (propertyId == XMLReader::PROPERTY_DECLARATION_HANDLER)
_engine.setDeclHandler(reinterpret_cast<DeclHandler*>(value));
_engine->setDeclHandler(reinterpret_cast<DeclHandler*>(value));
else if (propertyId == XMLReader::PROPERTY_LEXICAL_HANDLER)
_engine.setLexicalHandler(reinterpret_cast<LexicalHandler*>(value));
_engine->setLexicalHandler(reinterpret_cast<LexicalHandler*>(value));
else throw SAXNotRecognizedException(fromXMLString(propertyId));
}


void* SAXParser::getProperty(const XMLString& propertyId) const
{
if (propertyId == XMLReader::PROPERTY_DECLARATION_HANDLER)
return _engine.getDeclHandler();
return _engine->getDeclHandler();
else if (propertyId == XMLReader::PROPERTY_LEXICAL_HANDLER)
return _engine.getLexicalHandler();
return _engine->getLexicalHandler();
else throw SAXNotSupportedException(fromXMLString(propertyId));
}

Expand All @@ -190,7 +193,7 @@ void SAXParser::parse(InputSource* pInputSource)
if (pInputSource->getByteStream() || pInputSource->getCharacterStream())
{
setupParse();
_engine.parse(pInputSource);
_engine->parse(pInputSource);
}
else parse(pInputSource->getSystemId());
}
Expand All @@ -205,7 +208,7 @@ void SAXParser::parse(const XMLString& systemId)
{
try
{
_engine.parse(pInputSource);
_engine->parse(pInputSource);
}
catch (...)
{
Expand All @@ -227,18 +230,18 @@ void SAXParser::parseString(const std::string& xml)
void SAXParser::parseMemoryNP(const char* xml, std::size_t size)
{
setupParse();
_engine.parse(xml, size);
_engine->parse(xml, size);
}


void SAXParser::setupParse()
{
if (_namespaces && !_namespacePrefixes)
_engine.setNamespaceStrategy(new NoNamespacePrefixesStrategy);
_engine->setNamespaceStrategy(new NoNamespacePrefixesStrategy);
else if (_namespaces && _namespacePrefixes)
_engine.setNamespaceStrategy(new NamespacePrefixesStrategy);
_engine->setNamespaceStrategy(new NamespacePrefixesStrategy);
else
_engine.setNamespaceStrategy(new NoNamespacesStrategy);
_engine->setNamespaceStrategy(new NoNamespacesStrategy);
}


Expand Down
Loading

0 comments on commit adf16f1

Please sign in to comment.