blautenb 2004/01/25 16:15:38
Modified: c/src/utils XSECDOMUtils.hpp XSECDOMUtils.cpp
Log:
Functions to remove hex escapes in a URI (taken from Xerces)
Revision Changes Path
1.14 +6 -1 xml-security/c/src/utils/XSECDOMUtils.hpp
Index: XSECDOMUtils.hpp
===================================================================
RCS file: /home/cvs/xml-security/c/src/utils/XSECDOMUtils.hpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- XSECDOMUtils.hpp 20 Nov 2003 09:11:25 -0000 1.13
+++ XSECDOMUtils.hpp 26 Jan 2004 00:15:38 -0000 1.14
@@ -169,6 +169,11 @@
// String Functions
//
--------------------------------------------------------------------------------
+// Remove escape (%XX) characters from URIs and return a new buffer
containing the
+// "cleaned" string
+
+XMLCh * cleanURIEscapes(const XMLCh * str);
+
inline
bool strEquals (const XMLCh * str1, const XMLCh *str2) {
1.16 +66 -0 xml-security/c/src/utils/XSECDOMUtils.cpp
Index: XSECDOMUtils.cpp
===================================================================
RCS file: /home/cvs/xml-security/c/src/utils/XSECDOMUtils.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- XSECDOMUtils.cpp 20 Nov 2003 09:11:25 -0000 1.15
+++ XSECDOMUtils.cpp 26 Jan 2004 00:15:38 -0000 1.16
@@ -646,3 +646,69 @@
}
+//
--------------------------------------------------------------------------------
+// Misc string functions
+//
--------------------------------------------------------------------------------
+
+// These three functions are pretty much lifted from XMLURL.cpp in Xerces
+
+static bool isHexDigit(const XMLCh toCheck)
+{
+ if ((toCheck >= chDigit_0) && (toCheck <= chDigit_9)
+ || (toCheck >= chLatin_A) && (toCheck <= chLatin_Z)
+ || (toCheck >= chLatin_a) && (toCheck <= chLatin_z))
+ {
+ return true;
+ }
+ return false;
+}
+
+static unsigned int xlatHexDigit(const XMLCh toXlat)
+{
+ if ((toXlat >= chDigit_0) && (toXlat <= chDigit_9))
+ return (unsigned int)(toXlat - chDigit_0);
+
+ if ((toXlat >= chLatin_A) && (toXlat <= chLatin_Z))
+ return (unsigned int)(toXlat - chLatin_A) + 10;
+
+ return (unsigned int)(toXlat - chLatin_a) + 10;
+}
+
+XMLCh * cleanURIEscapes(const XMLCh * str) {
+
+ // Taken from Xerces XMLURI.cpp
+
+ XMLCh * retPath = XMLString::replicate(str);
+ ArrayJanitor<XMLCh> j_retPath(retPath);
+
+ int len = XMLString::stringLen(retPath);
+ int percentIndex = XMLString::indexOf(retPath, chPercent, 0);
+
+ while (percentIndex != -1) {
+
+ if (percentIndex+2 >= len ||
+ !isHexDigit(retPath[percentIndex+1]) ||
+ !isHexDigit(retPath[percentIndex+2]))
+
+ throw XSECException(XSECException::ErrorOpeningURI,
+ "Bad escape sequence in URI");
+
+ unsigned int value = (xlatHexDigit(retPath[percentIndex+1]) *
16) +
+
(xlatHexDigit(retPath[percentIndex+2]));
+
+ retPath[percentIndex] = XMLCh(value);
+ int i = 0;
+ for (i = percentIndex+1 ; i < len - 2; ++i)
+ retPath[i] = retPath[i+2];
+ retPath[i] = chNull;
+ len = i;
+
+ percentIndex = XMLString::indexOf(retPath, chPercent,
percentIndex);
+
+ }
+
+ j_retPath.release();
+ return retPath;
+
+}
+