Skip to content

Commit

Permalink
Add functions/properties for disallowing DOCTYPE (DTD) in SAX parsers
Browse files Browse the repository at this point in the history
We already have the equivalent functionality for DOM.
  • Loading branch information
boris-kolpackov committed Dec 13, 2023
1 parent b38ab79 commit 5fe4f4b
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/xercesc/parsers/AbstractDOMParser.cpp
Expand Up @@ -317,6 +317,11 @@ const XMLSize_t& AbstractDOMParser::getLowWaterMark() const
return fScanner->getLowWaterMark();
}

bool AbstractDOMParser::getDisallowDoctype() const
{
return fScanner->getDisallowDTD();
}

bool AbstractDOMParser::getLoadExternalDTD() const
{
return fScanner->getLoadExternalDTD();
Expand Down Expand Up @@ -455,6 +460,11 @@ void AbstractDOMParser::setLowWaterMark(XMLSize_t lwm)
fScanner->setLowWaterMark(lwm);
}

void AbstractDOMParser::setDisallowDoctype(const bool newState)
{
fScanner->setDisallowDTD(newState);
}

void AbstractDOMParser::setLoadExternalDTD(const bool newState)
{
fScanner->setLoadExternalDTD(newState);
Expand Down
33 changes: 33 additions & 0 deletions src/xercesc/parsers/AbstractDOMParser.hpp
Expand Up @@ -350,6 +350,20 @@ public :
*/
const XMLSize_t& getLowWaterMark() const;

/** Get the 'Disallow DOCTYPE (DTD)' flag
*
* This method returns the state of the parser's disallowed DOCTYPE
* flag.
*
* @return false, if the parser is currently configured to
* allow DOCTYPE, true otherwise.
*
* @see #setDisallowDoctype()
* @see #getLoadExternalDTD
* @see #getValidationScheme
*/
bool getDisallowDoctype() const;

/** Get the 'Loading External DTD' flag
*
* This method returns the state of the parser's loading external DTD
Expand All @@ -359,6 +373,7 @@ public :
* ignore external DTD completely, true otherwise.
*
* @see #setLoadExternalDTD
* @see #getDisallowDoctype
* @see #getValidationScheme
*/
bool getLoadExternalDTD() const;
Expand Down Expand Up @@ -793,6 +808,23 @@ public :
*/
void setLowWaterMark(XMLSize_t lwm);

/** Set the 'Disallow DOCTYPE (DTD)' flag
*
* This method allows users to disable the processing of DOCTYPE (DTD).
* When set to true, the parser will throw an exception if the document
* contains the DOCTYPE node.
*
* The parser's default state is: false.
*
* @param newState The value specifying whether to disallow DOCTYPE
* or not.
*
* @see #setDisallowDoctype()
* @see #getLoadExternalDTD
* @see #getValidationScheme
*/
void setDisallowDoctype(const bool newState);

/** Set the 'Loading External DTD' flag
*
* This method allows users to enable or disable the loading of external DTD.
Expand All @@ -807,6 +839,7 @@ public :
* be loaded or not.
*
* @see #getLoadExternalDTD
* @see #setDisallowDoctype
* @see #setValidationScheme
*/
void setLoadExternalDTD(const bool newState);
Expand Down
6 changes: 6 additions & 0 deletions src/xercesc/parsers/SAX2XMLReaderImpl.cpp
Expand Up @@ -1302,6 +1302,10 @@ void SAX2XMLReaderImpl::setFeature(const XMLCh* const name, const bool value)
{
fScanner->setIdentityConstraintChecking(value);
}
else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesDisallowDoctype) == 0)
{
fScanner->setDisallowDTD(value);
}
else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesLoadExternalDTD) == 0)
{
fScanner->setLoadExternalDTD(value);
Expand Down Expand Up @@ -1386,6 +1390,8 @@ bool SAX2XMLReaderImpl::getFeature(const XMLCh* const name) const
return fScanner->getValidationSchemaFullChecking();
else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesIdentityConstraintChecking) == 0)
return fScanner->getIdentityConstraintChecking();
else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesDisallowDoctype) == 0)
return fScanner->getDisallowDTD();
else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesLoadExternalDTD) == 0)
return fScanner->getLoadExternalDTD();
else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesLoadSchema) == 0)
Expand Down
10 changes: 10 additions & 0 deletions src/xercesc/parsers/SAXParser.cpp
Expand Up @@ -312,6 +312,11 @@ XMLSize_t SAXParser::getLowWaterMark() const
return fScanner->getLowWaterMark();
}

bool SAXParser::getDisallowDoctype() const
{
return fScanner->getDisallowDTD();
}

bool SAXParser::getLoadExternalDTD() const
{
return fScanner->getLoadExternalDTD();
Expand Down Expand Up @@ -475,6 +480,11 @@ void SAXParser::setLowWaterMark(XMLSize_t lwm)
fScanner->setLowWaterMark(lwm);
}

void SAXParser::setDisallowDoctype(const bool newState)
{
fScanner->setDisallowDTD(newState);
}

void SAXParser::setLoadExternalDTD(const bool newState)
{
fScanner->setLoadExternalDTD(newState);
Expand Down
33 changes: 33 additions & 0 deletions src/xercesc/parsers/SAXParser.hpp
Expand Up @@ -380,6 +380,20 @@ public :
*/
XMLSize_t getLowWaterMark() const;

/** Get the 'Disallow DOCTYPE (DTD)' flag
*
* This method returns the state of the parser's disallowed DOCTYPE
* flag.
*
* @return false, if the parser is currently configured to
* allow DOCTYPE, true otherwise.
*
* @see #setDisallowDoctype()
* @see #getLoadExternalDTD
* @see #getValidationScheme
*/
bool getDisallowDoctype() const;

/** Get the 'Loading External DTD' flag
*
* This method returns the state of the parser's loading external DTD
Expand All @@ -389,6 +403,7 @@ public :
* ignore external DTD completely, true otherwise.
*
* @see #setLoadExternalDTD
* @see #getDisallowDoctype
* @see #getValidationScheme
*/
bool getLoadExternalDTD() const;
Expand Down Expand Up @@ -791,6 +806,23 @@ public :
*/
void setLowWaterMark(XMLSize_t lwm);

/** Set the 'Disallow DOCTYPE (DTD)' flag
*
* This method allows users to disable the processing of DOCTYPE (DTD).
* When set to true, the parser will throw an exception if the document
* contains the DOCTYPE node.
*
* The parser's default state is: false.
*
* @param newState The value specifying whether to disallow DOCTYPE
* or not.
*
* @see #setDisallowDoctype()
* @see #getLoadExternalDTD
* @see #getValidationScheme
*/
void setDisallowDoctype(const bool newState);

/** Set the 'Loading External DTD' flag
*
* This method allows users to enable or disable the loading of external DTD.
Expand All @@ -805,6 +837,7 @@ public :
* be loaded or not.
*
* @see #getLoadExternalDTD
* @see #setDisallowDoctype
* @see #setValidationScheme
*/
void setLoadExternalDTD(const bool newState);
Expand Down
16 changes: 16 additions & 0 deletions src/xercesc/util/XMLUni.cpp
Expand Up @@ -1070,6 +1070,22 @@ const XMLCh XMLUni::fgXercesIdentityConstraintChecking[] =
, chLatin_n, chLatin_g, chNull
};

//Xerces: http://apache.org/xml/features/nonvalidating/disallow-doctype
const XMLCh XMLUni::fgXercesDisallowDoctype[] =
{
chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColon, chForwardSlash
, chForwardSlash, chLatin_a, chLatin_p, chLatin_a, chLatin_c, chLatin_h
, chLatin_e, chPeriod, chLatin_o, chLatin_r, chLatin_g, chForwardSlash
, chLatin_x, chLatin_m, chLatin_l, chForwardSlash, chLatin_f, chLatin_e
, chLatin_a, chLatin_t, chLatin_u, chLatin_r, chLatin_e, chLatin_s
, chForwardSlash, chLatin_n, chLatin_o, chLatin_n
, chLatin_v, chLatin_a, chLatin_l, chLatin_i, chLatin_d
, chLatin_a, chLatin_t, chLatin_i, chLatin_n, chLatin_g, chForwardSlash
, chLatin_d, chLatin_i, chLatin_s, chLatin_a, chLatin_l, chLatin_l, chLatin_o
, chLatin_w, chDash, chLatin_d, chLatin_o, chLatin_c, chLatin_t, chLatin_y
, chLatin_p, chLatin_e, chNull
};

//Xerces: http://apache.org/xml/features/nonvalidating/load-external-dtd
const XMLCh XMLUni::fgXercesLoadExternalDTD[] =
{
Expand Down
1 change: 1 addition & 0 deletions src/xercesc/util/XMLUni.hpp
Expand Up @@ -224,6 +224,7 @@ public :
static const XMLCh fgXercesSchemaExternalSchemaLocation[];
static const XMLCh fgXercesSchemaExternalNoNameSpaceSchemaLocation[];
static const XMLCh fgXercesSecurityManager[];
static const XMLCh fgXercesDisallowDoctype[]; // DOMDisallowDoctype equivalent for SAX.
static const XMLCh fgXercesLoadExternalDTD[];
static const XMLCh fgXercesContinueAfterFatalError[];
static const XMLCh fgXercesValidationErrorAsFatal[];
Expand Down

0 comments on commit 5fe4f4b

Please sign in to comment.