Skip to content

Commit 5fe4f4b

Browse files
Add functions/properties for disallowing DOCTYPE (DTD) in SAX parsers
We already have the equivalent functionality for DOM.
1 parent b38ab79 commit 5fe4f4b

File tree

7 files changed

+109
-0
lines changed

7 files changed

+109
-0
lines changed

src/xercesc/parsers/AbstractDOMParser.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,11 @@ const XMLSize_t& AbstractDOMParser::getLowWaterMark() const
317317
return fScanner->getLowWaterMark();
318318
}
319319

320+
bool AbstractDOMParser::getDisallowDoctype() const
321+
{
322+
return fScanner->getDisallowDTD();
323+
}
324+
320325
bool AbstractDOMParser::getLoadExternalDTD() const
321326
{
322327
return fScanner->getLoadExternalDTD();
@@ -455,6 +460,11 @@ void AbstractDOMParser::setLowWaterMark(XMLSize_t lwm)
455460
fScanner->setLowWaterMark(lwm);
456461
}
457462

463+
void AbstractDOMParser::setDisallowDoctype(const bool newState)
464+
{
465+
fScanner->setDisallowDTD(newState);
466+
}
467+
458468
void AbstractDOMParser::setLoadExternalDTD(const bool newState)
459469
{
460470
fScanner->setLoadExternalDTD(newState);

src/xercesc/parsers/AbstractDOMParser.hpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,20 @@ public :
350350
*/
351351
const XMLSize_t& getLowWaterMark() const;
352352

353+
/** Get the 'Disallow DOCTYPE (DTD)' flag
354+
*
355+
* This method returns the state of the parser's disallowed DOCTYPE
356+
* flag.
357+
*
358+
* @return false, if the parser is currently configured to
359+
* allow DOCTYPE, true otherwise.
360+
*
361+
* @see #setDisallowDoctype()
362+
* @see #getLoadExternalDTD
363+
* @see #getValidationScheme
364+
*/
365+
bool getDisallowDoctype() const;
366+
353367
/** Get the 'Loading External DTD' flag
354368
*
355369
* This method returns the state of the parser's loading external DTD
@@ -359,6 +373,7 @@ public :
359373
* ignore external DTD completely, true otherwise.
360374
*
361375
* @see #setLoadExternalDTD
376+
* @see #getDisallowDoctype
362377
* @see #getValidationScheme
363378
*/
364379
bool getLoadExternalDTD() const;
@@ -793,6 +808,23 @@ public :
793808
*/
794809
void setLowWaterMark(XMLSize_t lwm);
795810

811+
/** Set the 'Disallow DOCTYPE (DTD)' flag
812+
*
813+
* This method allows users to disable the processing of DOCTYPE (DTD).
814+
* When set to true, the parser will throw an exception if the document
815+
* contains the DOCTYPE node.
816+
*
817+
* The parser's default state is: false.
818+
*
819+
* @param newState The value specifying whether to disallow DOCTYPE
820+
* or not.
821+
*
822+
* @see #setDisallowDoctype()
823+
* @see #getLoadExternalDTD
824+
* @see #getValidationScheme
825+
*/
826+
void setDisallowDoctype(const bool newState);
827+
796828
/** Set the 'Loading External DTD' flag
797829
*
798830
* This method allows users to enable or disable the loading of external DTD.
@@ -807,6 +839,7 @@ public :
807839
* be loaded or not.
808840
*
809841
* @see #getLoadExternalDTD
842+
* @see #setDisallowDoctype
810843
* @see #setValidationScheme
811844
*/
812845
void setLoadExternalDTD(const bool newState);

src/xercesc/parsers/SAX2XMLReaderImpl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,10 @@ void SAX2XMLReaderImpl::setFeature(const XMLCh* const name, const bool value)
13021302
{
13031303
fScanner->setIdentityConstraintChecking(value);
13041304
}
1305+
else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesDisallowDoctype) == 0)
1306+
{
1307+
fScanner->setDisallowDTD(value);
1308+
}
13051309
else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesLoadExternalDTD) == 0)
13061310
{
13071311
fScanner->setLoadExternalDTD(value);
@@ -1386,6 +1390,8 @@ bool SAX2XMLReaderImpl::getFeature(const XMLCh* const name) const
13861390
return fScanner->getValidationSchemaFullChecking();
13871391
else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesIdentityConstraintChecking) == 0)
13881392
return fScanner->getIdentityConstraintChecking();
1393+
else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesDisallowDoctype) == 0)
1394+
return fScanner->getDisallowDTD();
13891395
else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesLoadExternalDTD) == 0)
13901396
return fScanner->getLoadExternalDTD();
13911397
else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesLoadSchema) == 0)

src/xercesc/parsers/SAXParser.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,11 @@ XMLSize_t SAXParser::getLowWaterMark() const
312312
return fScanner->getLowWaterMark();
313313
}
314314

315+
bool SAXParser::getDisallowDoctype() const
316+
{
317+
return fScanner->getDisallowDTD();
318+
}
319+
315320
bool SAXParser::getLoadExternalDTD() const
316321
{
317322
return fScanner->getLoadExternalDTD();
@@ -475,6 +480,11 @@ void SAXParser::setLowWaterMark(XMLSize_t lwm)
475480
fScanner->setLowWaterMark(lwm);
476481
}
477482

483+
void SAXParser::setDisallowDoctype(const bool newState)
484+
{
485+
fScanner->setDisallowDTD(newState);
486+
}
487+
478488
void SAXParser::setLoadExternalDTD(const bool newState)
479489
{
480490
fScanner->setLoadExternalDTD(newState);

src/xercesc/parsers/SAXParser.hpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,20 @@ public :
380380
*/
381381
XMLSize_t getLowWaterMark() const;
382382

383+
/** Get the 'Disallow DOCTYPE (DTD)' flag
384+
*
385+
* This method returns the state of the parser's disallowed DOCTYPE
386+
* flag.
387+
*
388+
* @return false, if the parser is currently configured to
389+
* allow DOCTYPE, true otherwise.
390+
*
391+
* @see #setDisallowDoctype()
392+
* @see #getLoadExternalDTD
393+
* @see #getValidationScheme
394+
*/
395+
bool getDisallowDoctype() const;
396+
383397
/** Get the 'Loading External DTD' flag
384398
*
385399
* This method returns the state of the parser's loading external DTD
@@ -389,6 +403,7 @@ public :
389403
* ignore external DTD completely, true otherwise.
390404
*
391405
* @see #setLoadExternalDTD
406+
* @see #getDisallowDoctype
392407
* @see #getValidationScheme
393408
*/
394409
bool getLoadExternalDTD() const;
@@ -791,6 +806,23 @@ public :
791806
*/
792807
void setLowWaterMark(XMLSize_t lwm);
793808

809+
/** Set the 'Disallow DOCTYPE (DTD)' flag
810+
*
811+
* This method allows users to disable the processing of DOCTYPE (DTD).
812+
* When set to true, the parser will throw an exception if the document
813+
* contains the DOCTYPE node.
814+
*
815+
* The parser's default state is: false.
816+
*
817+
* @param newState The value specifying whether to disallow DOCTYPE
818+
* or not.
819+
*
820+
* @see #setDisallowDoctype()
821+
* @see #getLoadExternalDTD
822+
* @see #getValidationScheme
823+
*/
824+
void setDisallowDoctype(const bool newState);
825+
794826
/** Set the 'Loading External DTD' flag
795827
*
796828
* This method allows users to enable or disable the loading of external DTD.
@@ -805,6 +837,7 @@ public :
805837
* be loaded or not.
806838
*
807839
* @see #getLoadExternalDTD
840+
* @see #setDisallowDoctype
808841
* @see #setValidationScheme
809842
*/
810843
void setLoadExternalDTD(const bool newState);

src/xercesc/util/XMLUni.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,22 @@ const XMLCh XMLUni::fgXercesIdentityConstraintChecking[] =
10701070
, chLatin_n, chLatin_g, chNull
10711071
};
10721072

1073+
//Xerces: http://apache.org/xml/features/nonvalidating/disallow-doctype
1074+
const XMLCh XMLUni::fgXercesDisallowDoctype[] =
1075+
{
1076+
chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColon, chForwardSlash
1077+
, chForwardSlash, chLatin_a, chLatin_p, chLatin_a, chLatin_c, chLatin_h
1078+
, chLatin_e, chPeriod, chLatin_o, chLatin_r, chLatin_g, chForwardSlash
1079+
, chLatin_x, chLatin_m, chLatin_l, chForwardSlash, chLatin_f, chLatin_e
1080+
, chLatin_a, chLatin_t, chLatin_u, chLatin_r, chLatin_e, chLatin_s
1081+
, chForwardSlash, chLatin_n, chLatin_o, chLatin_n
1082+
, chLatin_v, chLatin_a, chLatin_l, chLatin_i, chLatin_d
1083+
, chLatin_a, chLatin_t, chLatin_i, chLatin_n, chLatin_g, chForwardSlash
1084+
, chLatin_d, chLatin_i, chLatin_s, chLatin_a, chLatin_l, chLatin_l, chLatin_o
1085+
, chLatin_w, chDash, chLatin_d, chLatin_o, chLatin_c, chLatin_t, chLatin_y
1086+
, chLatin_p, chLatin_e, chNull
1087+
};
1088+
10731089
//Xerces: http://apache.org/xml/features/nonvalidating/load-external-dtd
10741090
const XMLCh XMLUni::fgXercesLoadExternalDTD[] =
10751091
{

src/xercesc/util/XMLUni.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ public :
224224
static const XMLCh fgXercesSchemaExternalSchemaLocation[];
225225
static const XMLCh fgXercesSchemaExternalNoNameSpaceSchemaLocation[];
226226
static const XMLCh fgXercesSecurityManager[];
227+
static const XMLCh fgXercesDisallowDoctype[]; // DOMDisallowDoctype equivalent for SAX.
227228
static const XMLCh fgXercesLoadExternalDTD[];
228229
static const XMLCh fgXercesContinueAfterFatalError[];
229230
static const XMLCh fgXercesValidationErrorAsFatal[];

0 commit comments

Comments
 (0)