Add functions/properties for disallowing DOCTYPE (DTD) in SAX parsers
We already have the equivalent functionality for DOM.
diff --git a/src/xercesc/parsers/AbstractDOMParser.cpp b/src/xercesc/parsers/AbstractDOMParser.cpp
index 4526e87..44cb6ba 100644
--- a/src/xercesc/parsers/AbstractDOMParser.cpp
+++ b/src/xercesc/parsers/AbstractDOMParser.cpp
@@ -317,6 +317,11 @@
return fScanner->getLowWaterMark();
}
+bool AbstractDOMParser::getDisallowDoctype() const
+{
+ return fScanner->getDisallowDTD();
+}
+
bool AbstractDOMParser::getLoadExternalDTD() const
{
return fScanner->getLoadExternalDTD();
@@ -455,6 +460,11 @@
fScanner->setLowWaterMark(lwm);
}
+void AbstractDOMParser::setDisallowDoctype(const bool newState)
+{
+ fScanner->setDisallowDTD(newState);
+}
+
void AbstractDOMParser::setLoadExternalDTD(const bool newState)
{
fScanner->setLoadExternalDTD(newState);
diff --git a/src/xercesc/parsers/AbstractDOMParser.hpp b/src/xercesc/parsers/AbstractDOMParser.hpp
index 664a887..e179e59 100644
--- a/src/xercesc/parsers/AbstractDOMParser.hpp
+++ b/src/xercesc/parsers/AbstractDOMParser.hpp
@@ -350,6 +350,20 @@
*/
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
@@ -359,6 +373,7 @@
* ignore external DTD completely, true otherwise.
*
* @see #setLoadExternalDTD
+ * @see #getDisallowDoctype
* @see #getValidationScheme
*/
bool getLoadExternalDTD() const;
@@ -793,6 +808,23 @@
*/
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.
@@ -807,6 +839,7 @@
* be loaded or not.
*
* @see #getLoadExternalDTD
+ * @see #setDisallowDoctype
* @see #setValidationScheme
*/
void setLoadExternalDTD(const bool newState);
diff --git a/src/xercesc/parsers/SAX2XMLReaderImpl.cpp b/src/xercesc/parsers/SAX2XMLReaderImpl.cpp
index 473fb66..c9bb648 100644
--- a/src/xercesc/parsers/SAX2XMLReaderImpl.cpp
+++ b/src/xercesc/parsers/SAX2XMLReaderImpl.cpp
@@ -1302,6 +1302,10 @@
{
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);
@@ -1386,6 +1390,8 @@
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)
diff --git a/src/xercesc/parsers/SAXParser.cpp b/src/xercesc/parsers/SAXParser.cpp
index 8a46ad3..3a10eb9 100644
--- a/src/xercesc/parsers/SAXParser.cpp
+++ b/src/xercesc/parsers/SAXParser.cpp
@@ -312,6 +312,11 @@
return fScanner->getLowWaterMark();
}
+bool SAXParser::getDisallowDoctype() const
+{
+ return fScanner->getDisallowDTD();
+}
+
bool SAXParser::getLoadExternalDTD() const
{
return fScanner->getLoadExternalDTD();
@@ -475,6 +480,11 @@
fScanner->setLowWaterMark(lwm);
}
+void SAXParser::setDisallowDoctype(const bool newState)
+{
+ fScanner->setDisallowDTD(newState);
+}
+
void SAXParser::setLoadExternalDTD(const bool newState)
{
fScanner->setLoadExternalDTD(newState);
diff --git a/src/xercesc/parsers/SAXParser.hpp b/src/xercesc/parsers/SAXParser.hpp
index c0c903d..d42eee1 100644
--- a/src/xercesc/parsers/SAXParser.hpp
+++ b/src/xercesc/parsers/SAXParser.hpp
@@ -380,6 +380,20 @@
*/
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
@@ -389,6 +403,7 @@
* ignore external DTD completely, true otherwise.
*
* @see #setLoadExternalDTD
+ * @see #getDisallowDoctype
* @see #getValidationScheme
*/
bool getLoadExternalDTD() const;
@@ -791,6 +806,23 @@
*/
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.
@@ -805,6 +837,7 @@
* be loaded or not.
*
* @see #getLoadExternalDTD
+ * @see #setDisallowDoctype
* @see #setValidationScheme
*/
void setLoadExternalDTD(const bool newState);
diff --git a/src/xercesc/util/XMLUni.cpp b/src/xercesc/util/XMLUni.cpp
index c167238..184b34c 100644
--- a/src/xercesc/util/XMLUni.cpp
+++ b/src/xercesc/util/XMLUni.cpp
@@ -1070,6 +1070,22 @@
, 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[] =
{
diff --git a/src/xercesc/util/XMLUni.hpp b/src/xercesc/util/XMLUni.hpp
index 252dd0a..5fde8c8 100644
--- a/src/xercesc/util/XMLUni.hpp
+++ b/src/xercesc/util/XMLUni.hpp
@@ -224,6 +224,7 @@
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[];