You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by pe...@apache.org on 2004/06/24 17:00:37 UTC
cvs commit: xml-xerces/c/src/xercesc/util Base64.cpp Base64.hpp
peiyongz 2004/06/24 08:00:37
Modified: c/src/xercesc/util Base64.cpp Base64.hpp
Log:
Schema-Errata: E2-54 new specs for base64
Revision Changes Path
1.12 +90 -19 xml-xerces/c/src/xercesc/util/Base64.cpp
Index: Base64.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/Base64.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- Base64.cpp 17 Dec 2003 00:18:35 -0000 1.11
+++ Base64.cpp 24 Jun 2004 15:00:37 -0000 1.12
@@ -56,6 +56,9 @@
/*
* $Log$
+ * Revision 1.12 2004/06/24 15:00:37 peiyongz
+ * Schema-Errata: E2-54 new specs for base64
+ *
* Revision 1.11 2003/12/17 00:18:35 cargilld
* Update to memory management so that the static memory manager (one used to call Initialize) is only for static data.
*
@@ -321,11 +324,13 @@
// Since decode() has track of length of the decoded data, we
// will get this length from decode(), instead of strLen().
//
-int Base64::getDataLength(const XMLCh* const inputData
- , MemoryManager* const manager)
+int Base64::getDataLength(const XMLCh* const inputData
+ , MemoryManager* const manager
+ , Conformance conform )
+
{
unsigned int retLen = 0;
- XMLCh* decodedData = decode(inputData, &retLen, manager);
+ XMLCh* decodedData = decode(inputData, &retLen, manager, conform);
if ( !decodedData )
return -1;
@@ -358,11 +363,41 @@
* B04 ::= [AQgw]
* B16 ::= [AEIMQUYcgkosw048]
* B64 ::= [A-Za-z0-9+/]
+ *
+ *
+ * E2-54
+ *
+ * Base64Binary ::= ((B64S B64S B64S B64S)*
+ * ((B64S B64S B64S B64) |
+ * (B64S B64S B16S '=') |
+ * (B64S B04S '=' #x20? '=')))?
+ *
+ * B64S ::= B64 #x20?
+ * B16S ::= B16 #x20?
+ * B04S ::= B04 #x20?
+ *
+ *
+ * Note that this grammar requires the number of non-whitespace characters
+ * in the lexical form to be a multiple of four, and for equals signs to
+ * appear only at the end of the lexical form; strings which do not meet these
+ * constraints are not legal lexical forms of base64Binary because they
+ * cannot successfully be decoded by base64 decoders.
+ *
+ * Note:
+ * The above definition of the lexical space is more restrictive than that given
+ * in [RFC 2045] as regards whitespace -- this is not an issue in practice. Any
+ * string compatible with the RFC can occur in an element or attribute validated
+ * by this type, because the �whiteSpace� facet of this type is fixed to collapse,
+ * which means that all leading and trailing whitespace will be stripped, and all
+ * internal whitespace collapsed to single space characters, before the above grammar
+ * is enforced.
+ *
*/
-XMLByte* Base64::decode(const XMLByte* const inputData
- , unsigned int* decodedLength
- , MemoryManager* const memMgr)
+XMLByte* Base64::decode(const XMLByte* const inputData
+ , unsigned int* decodedLength
+ , MemoryManager* const memMgr
+ , Conformance conform )
{
if (!isInitialized)
init();
@@ -381,23 +416,58 @@
int rawInputLength = 0;
bool inWhiteSpace = false;
- while ( inputIndex < inputLength )
+ switch (conform)
{
- if (!XMLChar1_0::isWhitespace(inputData[inputIndex]))
+ case Conf_RFC2045:
+ while ( inputIndex < inputLength )
{
- rawInputData[ rawInputLength++ ] = inputData[ inputIndex ];
- inWhiteSpace = false;
+ if (!XMLChar1_0::isWhitespace(inputData[inputIndex]))
+ {
+ rawInputData[ rawInputLength++ ] = inputData[ inputIndex ];
+ }
+ // RFC2045 does not explicitly forbid more than ONE whitespace
+ // before, in between, or after base64 octects.
+ // Besides, S? allows more than ONE whitespace as specified in the production
+ // [3] S ::= (#x20 | #x9 | #xD | #xA)+
+ // therefore we do not detect multiple ws
+
+ inputIndex++;
}
- else
+
+ break;
+ case Conf_Schema:
+ // no leading #x20
+ if (chSpace == inputData[inputIndex])
+ return 0;
+
+ while ( inputIndex < inputLength )
{
- if (inWhiteSpace)
- return 0; // more than 1 whitespaces encountered
+ if (chSpace != inputData[inputIndex])
+ {
+ rawInputData[ rawInputLength++ ] = inputData[ inputIndex ];
+ inWhiteSpace = false;
+ }
else
- inWhiteSpace = true;
+ {
+ if (inWhiteSpace)
+ return 0; // more than 1 #x20 encountered
+ else
+ inWhiteSpace = true;
+ }
+
+ inputIndex++;
}
- inputIndex++;
+ // no trailing #x20
+ if (inWhiteSpace)
+ return 0;
+
+ break;
+
+ default:
+ break;
}
+
rawInputData[ rawInputLength ] = 0;
// the length of raw data should be divisible by four
@@ -516,9 +586,10 @@
return decodedData;
}
-XMLCh* Base64::decode(const XMLCh* const inputData
- , unsigned int* decodedLen
- , MemoryManager* const memMgr)
+XMLCh* Base64::decode(const XMLCh* const inputData
+ , unsigned int* decodedLen
+ , MemoryManager* const memMgr
+ , Conformance conform )
{
if (!inputData)
return 0;
@@ -539,7 +610,7 @@
* Forward to the actual decoding method to do the decoding
*/
*decodedLen = 0;
- XMLByte *DecodedBuf = decode(dataInByte, decodedLen, memMgr);
+ XMLByte *DecodedBuf = decode(dataInByte, decodedLen, memMgr, conform);
if (!DecodedBuf)
return 0;
1.9 +29 -10 xml-xerces/c/src/xercesc/util/Base64.hpp
Index: Base64.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/Base64.hpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Base64.hpp 17 Dec 2003 00:18:35 -0000 1.8
+++ Base64.hpp 24 Jun 2004 15:00:37 -0000 1.9
@@ -80,6 +80,12 @@
{
public :
+ enum Conformance
+ {
+ Conf_RFC2045
+ , Conf_Schema
+ };
+
//@{
/**
@@ -102,7 +108,7 @@
*/
static XMLByte* encode(const XMLByte* const inputData
, const unsigned int inputLength
- , unsigned int* outputLength
+ , unsigned int* outputLength
, MemoryManager* const memMgr = 0);
/**
@@ -118,13 +124,17 @@
* @param inputData Base64 data in XMLByte stream.
* @param outputLength Length of decoded XMLByte stream.
* @param memMgr client provided memory manager
+ * @param conform conformance specified
* @return Decoded binary data in XMLByte stream,
* or NULL if input data can not be decoded.
* @see XMLString::release(XMLByte**)
*/
- static XMLByte* decode(const XMLByte* const inputData
- , unsigned int* outputLength
- , MemoryManager* const memMgr = 0);
+ static XMLByte* decode(
+ const XMLByte* const inputData
+ , unsigned int* outputLength
+ , MemoryManager* const memMgr = 0
+ , Conformance conform = Conf_RFC2045
+ );
/**
* Decodes Base64 data into XMLCh
@@ -139,13 +149,17 @@
* @param inputData Base64 data in XMLCh stream.
* @param outputLength Length of decoded XMLCh stream
* @param memMgr client provided memory manager
+ * @param conform conformance specified
* @return Decoded binary data in XMLCh stream,
* or NULL if input data can not be decoded.
* @see XMLString::release(XMLCh**)
*/
- static XMLCh* decode(const XMLCh* const inputData
- , unsigned int* outputLength
- , MemoryManager* const memMgr = 0);
+ static XMLCh* decode(
+ const XMLCh* const inputData
+ , unsigned int* outputLength
+ , MemoryManager* const memMgr = 0
+ , Conformance conform = Conf_RFC2045
+ );
/**
* Get data length
@@ -154,11 +168,16 @@
* containing encoded data.
*
* @param inputData Base64 data in XMLCh stream.
+ * @param memMgr client provided memory manager
+ * @param conform conformance specified
* @return Length of decoded data,
* or -1 if input data can not be decoded.
*/
- static int getDataLength(const XMLCh* const inputData
- , MemoryManager* const memMgr = 0);
+ static int getDataLength(
+ const XMLCh* const inputData
+ , MemoryManager* const memMgr = 0
+ , Conformance conform = Conf_RFC2045
+ );
//@}
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org