From 8e468b1fb42910e2c138426286eb0a68b07cf433 Mon Sep 17 00:00:00 2001 From: Khaled Noaman <knoaman@apache.org> Date: Thu, 18 Jul 2002 20:05:31 +0000 Subject: [PATCH] Add a new feature to control strict IANA encoding name. git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@174026 13f79535-47bb-0310-9956-ffa450edef68 --- src/xercesc/util/PlatformUtils.cpp | 29 +++++++++++++++++++++++++++-- src/xercesc/util/PlatformUtils.hpp | 20 ++++++++++++++++++++ src/xercesc/util/TransService.cpp | 28 +++++++++++++++++++++++++++- src/xercesc/util/TransService.hpp | 9 +++++++++ src/xercesc/util/XMLUni.cpp | 15 +++++++++++++++ src/xercesc/util/XMLUni.hpp | 1 + 6 files changed, 99 insertions(+), 3 deletions(-) diff --git a/src/xercesc/util/PlatformUtils.cpp b/src/xercesc/util/PlatformUtils.cpp index 19374260c..c8e9e972d 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 f72878640..a089aea77 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 46f9a4462..07e0862c2 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 5224f26c5..cee2973cf 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 711e208ca..656745562 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 b9bcf8e14..558cd1c3b 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[]; -- GitLab