diff --git a/src/xercesc/util/PlatformUtils.cpp b/src/xercesc/util/PlatformUtils.cpp index 19374260cde729b5adcffbc2d52517a4411346b2..c8e9e972df93af2389ad1a82e42066df536301bd 100644 --- a/src/xercesc/util/PlatformUtils.cpp +++ b/src/xercesc/util/PlatformUtils.cpp @@ -56,8 +56,11 @@ /* * $Log$ - * Revision 1.1 2002/02/01 22:22:11 peiyongz - * Initial revision + * Revision 1.2 2002/07/18 20:05:31 knoaman + * Add a new feature to control strict IANA encoding name. + * + * Revision 1.1.1.1 2002/02/01 22:22:11 peiyongz + * sane_include * * Revision 1.16 2001/10/25 21:52:28 peiyongz * XMLDeleterFor related functions and data are removed. @@ -358,3 +361,25 @@ bool XMLPlatformUtils::isNELRecognized() { return XMLReader::isNELRecognized(); } +// --------------------------------------------------------------------------- +// XMLPlatformUtils: IANA Encoding checking setting +// --------------------------------------------------------------------------- +void XMLPlatformUtils::strictIANAEncoding(const bool state) { + + //Make sure initialize has been called + if (gInitFlag == 0) { + return; + } + + fgTransService->strictIANAEncoding(state); +} + + +bool XMLPlatformUtils::isStrictIANAEncoding() { + + if (gInitFlag) + return fgTransService->isStrictIANAEncoding(); + + return false; +} + diff --git a/src/xercesc/util/PlatformUtils.hpp b/src/xercesc/util/PlatformUtils.hpp index f728786403c3f810277de44232d5ba3347530098..a089aea770c10fb09ad6a0857d48e63cfe25e008 100644 --- a/src/xercesc/util/PlatformUtils.hpp +++ b/src/xercesc/util/PlatformUtils.hpp @@ -578,6 +578,26 @@ public : static bool isNELRecognized(); //@} + /** @name Strict IANA Encoding Checking */ + //@{ + /** + * This function enables/disables strict IANA encoding names checking. + * + * The strict checking is disabled by default. + * + * @param state If true, a strict IANA encoding name check is performed, + * otherwise, no checking. + * + */ + static void strictIANAEncoding(const bool state); + + /** + * Returns whether a strict IANA encoding name check is enabled or + * disabled. + */ + static bool isStrictIANAEncoding(); + //@} + private : /** @name Private static methods */ diff --git a/src/xercesc/util/TransService.cpp b/src/xercesc/util/TransService.cpp index 46f9a446226f3c85c780534aa289b19c47e9d299..07e0862c265ff84ebbef91141be3706de106a3db 100644 --- a/src/xercesc/util/TransService.cpp +++ b/src/xercesc/util/TransService.cpp @@ -74,6 +74,7 @@ #include <xercesc/util/XMLUniDefs.hpp> #include <xercesc/util/XMLUni.hpp> #include <xercesc/util/TransENameMap.hpp> +#include <xercesc/util/EncodingValidator.hpp> @@ -137,7 +138,7 @@ static XMLCh gDisallowPre[] = { chLatin_I, chLatin_B, chLatin_M, chNull }; - +static bool gStrictIANAEncoding = false; // --------------------------------------------------------------------------- @@ -185,6 +186,18 @@ XMLTransService::makeNewTranscoderFor( const XMLCh* const encoding , XMLTransService::Codes& resValue , const unsigned int blockSize) { + // + // If strict IANA encoding flag is set, validate encoding name + // + if (gStrictIANAEncoding) + { + if (!EncodingValidator::instance()->isValidEncoding(encodingName)) + { + resValue = XMLTransService::UnsupportedEncoding; + return 0; + } + } + // // First try to find it in our list of mappings to intrinsically // supported encodings. We have to upper case the passed encoding @@ -522,3 +535,16 @@ void XMLTransService::initTransService() gMappings->put((void*)XMLUni::fgWin1252EncodingString, new ENameMapFor<XMLWin1252Transcoder>(XMLUni::fgWin1252EncodingString)); } + +// --------------------------------------------------------------------------- +// XLMTransService: IANA encoding setting +// --------------------------------------------------------------------------- +void XMLTransService::strictIANAEncoding(const bool newState) +{ + gStrictIANAEncoding = newState; +} + +bool XMLTransService::isStrictIANAEncoding() +{ + return gStrictIANAEncoding; +} diff --git a/src/xercesc/util/TransService.hpp b/src/xercesc/util/TransService.hpp index 5224f26c5041e3b14280388bb4b7f71573f1b8cf..cee2973cf07f3538b995429dd60f99835477647c 100644 --- a/src/xercesc/util/TransService.hpp +++ b/src/xercesc/util/TransService.hpp @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.3 2002/07/18 20:05:31 knoaman + * Add a new feature to control strict IANA encoding name. + * * Revision 1.2 2002/04/09 15:44:00 knoaman * Add lower case string support. * @@ -253,6 +256,12 @@ private : XMLTransService(const XMLTransService&); void operator=(const XMLTransService&); + // ----------------------------------------------------------------------- + // Hidden method to enable/disable strict IANA encoding check + // Caller: XMLPlatformUtils + // ----------------------------------------------------------------------- + void strictIANAEncoding(const bool newState); + bool isStrictIANAEncoding(); // ----------------------------------------------------------------------- // Hidden init method for platform utils to call diff --git a/src/xercesc/util/XMLUni.cpp b/src/xercesc/util/XMLUni.cpp index 711e208ca3860c5bafc9f307d88ecd20174bd28b..656745562326215073f9f45ae6fcc0e0b344eab1 100644 --- a/src/xercesc/util/XMLUni.cpp +++ b/src/xercesc/util/XMLUni.cpp @@ -1031,6 +1031,21 @@ const XMLCh XMLUni::fgXercesUseCachedGrammarInParse[] = , chLatin_s, chLatin_e, chNull }; +//Xerces: http://apache.org/xml/features/validation/strict-IANAEncoding +const XMLCh XMLUni::fgXercesStrictIANAEncoding[] = +{ + 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_v, chLatin_a, chLatin_l, chLatin_i, chLatin_d + , chLatin_a, chLatin_t, chLatin_i, chLatin_o, chLatin_n, chForwardSlash + , chLatin_s, chLatin_t, chLatin_r, chLatin_i, chLatin_c, chLatin_t, chDash + , chLatin_I, chLatin_A, chLatin_N, chLatin_A, chLatin_E, chLatin_n, chLatin_c + , chLatin_o, chLatin_d, chLatin_i, chLatin_n, chLatin_g, chNull +}; + //Introduced in DOM Level 3 const XMLCh XMLUni::fgDOMCanonicalForm[] = diff --git a/src/xercesc/util/XMLUni.hpp b/src/xercesc/util/XMLUni.hpp index b9bcf8e1479c37c8f682e4f4d33f35784109b7c4..558cd1c3bb9e3820b175563a4a2ef8b5eca8e5af 100644 --- a/src/xercesc/util/XMLUni.hpp +++ b/src/xercesc/util/XMLUni.hpp @@ -230,6 +230,7 @@ public : static const XMLCh fgXercesUserAdoptsDOMDocument[]; static const XMLCh fgXercesCacheGrammarFromParse[]; static const XMLCh fgXercesUseCachedGrammarInParse[]; + static const XMLCh fgXercesStrictIANAEncoding[]; // SAX2 features/properties names static const XMLCh fgSAX2CoreValidation[];