You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ca...@apache.org on 2004/12/10 11:37:58 UTC

cvs commit: xml-xerces/c/src/xercesc/util Base64.cpp Base64.hpp HexBin.cpp HexBin.hpp

cargilld    2004/12/10 02:37:58

  Modified:    c/src/xercesc/framework/psvi XSValue.cpp XSValue.hpp
               c/src/xercesc/util Base64.cpp Base64.hpp HexBin.cpp
                        HexBin.hpp
  Log:
  Fix problem with hexbin::decode and use XMLByte instead of XMLCh for output of decoding.
  
  Revision  Changes    Path
  1.20      +9 -6      xml-xerces/c/src/xercesc/framework/psvi/XSValue.cpp
  
  Index: XSValue.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/framework/psvi/XSValue.cpp,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- XSValue.cpp	1 Dec 2004 16:18:47 -0000	1.19
  +++ XSValue.cpp	10 Dec 2004 10:37:55 -0000	1.20
  @@ -16,6 +16,9 @@
   
   /*
    * $Log$
  + * Revision 1.20  2004/12/10 10:37:55  cargilld
  + * Fix problem with hexbin::decode and use XMLByte instead of XMLCh for output of decoding.
  + *
    * Revision 1.19  2004/12/01 16:18:47  cargilld
    * Fix for bug xercesc-1304.
    *
  @@ -379,7 +382,7 @@
   XSValue::~XSValue()
   {
       if (fMemAllocated)
  -        fMemoryManager->deallocate(fData.fValue.f_strVal);
  +        fMemoryManager->deallocate(fData.fValue.f_byteVal);
   }
     
   // ---------------------------------------------------------------------------
  @@ -1523,7 +1526,7 @@
               break;
           case XSValue::dt_hexBinary:
               {
  -                XMLCh* decodedData = HexBin::decode(content, manager);
  +                XMLByte* decodedData = HexBin::decodeToXMLByte(content, manager);
   
                   if (!decodedData)
                   {
  @@ -1532,7 +1535,7 @@
                   }
   
                   XSValue* retVal = new (manager) XSValue(dt_hexBinary, manager);
  -                retVal->fData.fValue.f_strVal = decodedData;
  +                retVal->fData.fValue.f_byteVal = decodedData;
                   retVal->fMemAllocated = true;
                   return retVal;                
                   break;
  @@ -1540,7 +1543,7 @@
           case XSValue::dt_base64Binary:
               {
                   unsigned int    len = 0;
  -                XMLCh* decodedData = Base64::decode(content, &len, manager);
  +                XMLByte* decodedData = Base64::decodeToXMLByte(content, &len, manager);
   
                   if (!decodedData)
                   {
  @@ -1549,7 +1552,7 @@
                   }
   
                   XSValue* retVal = new (manager) XSValue(dt_base64Binary, manager);
  -                retVal->fData.fValue.f_strVal = decodedData;
  +                retVal->fData.fValue.f_byteVal = decodedData;
                   retVal->fMemAllocated = true;
                   return retVal;
                   break;
  
  
  
  1.18      +5 -1      xml-xerces/c/src/xercesc/framework/psvi/XSValue.hpp
  
  Index: XSValue.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/framework/psvi/XSValue.hpp,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- XSValue.hpp	24 Nov 2004 10:18:59 -0000	1.17
  +++ XSValue.hpp	10 Dec 2004 10:37:55 -0000	1.18
  @@ -16,6 +16,9 @@
   
   /*
    * $Log$
  + * Revision 1.18  2004/12/10 10:37:55  cargilld
  + * Fix problem with hexbin::decode and use XMLByte instead of XMLCh for output of decoding.
  + *
    * Revision 1.17  2004/11/24 10:18:59  cargilld
    * Fix compilation error on HP for yesterday's commit.
    *
  @@ -261,6 +264,7 @@
                            float     f_float;
                            double    f_double;
                            XMLCh*    f_strVal;
  +                         XMLByte*  f_byteVal;
   
                   struct decimal {
                                   double           f_dvalue;
  
  
  
  1.16      +31 -1     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.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- Base64.cpp	8 Sep 2004 13:56:21 -0000	1.15
  +++ Base64.cpp	10 Dec 2004 10:37:56 -0000	1.16
  @@ -16,6 +16,9 @@
   
   /*
    * $Log$
  + * Revision 1.16  2004/12/10 10:37:56  cargilld
  + * Fix problem with hexbin::decode and use XMLByte instead of XMLCh for output of decoding.
  + *
    * Revision 1.15  2004/09/08 13:56:21  peiyongz
    * Apache License Version 2.0
    *
  @@ -299,7 +302,7 @@
   
   {
       unsigned int    retLen = 0;
  -    XMLCh* decodedData = decode(inputData, &retLen, manager, conform);
  +    XMLByte* decodedData = decodeToXMLByte(inputData, &retLen, manager, conform);
   
       if ( !decodedData )
           return -1;
  @@ -377,6 +380,33 @@
       returnExternalMemory(memMgr, DecodedBuf);
   
       return toRet;
  +}
  +
  +XMLByte* Base64::decodeToXMLByte(const XMLCh*         const   inputData
  +                    ,       unsigned int*          decodedLen
  +                    ,       MemoryManager* const   memMgr
  +                    ,       Conformance            conform )
  +{
  +	if (!inputData)
  +		return 0;
  +
  +    /***
  +     *  Move input data to a XMLByte buffer
  +     */
  +	unsigned int srcLen = XMLString::stringLen(inputData);
  +    XMLByte *dataInByte = (XMLByte*) getExternalMemory(memMgr, (srcLen+1) * sizeof(XMLByte));
  +    ArrayJanitor<XMLByte> janFill(dataInByte, memMgr ? memMgr : XMLPlatformUtils::fgMemoryManager);
  +
  +    for (unsigned int i = 0; i < srcLen; i++)
  +		dataInByte[i] = (XMLByte)inputData[i];
  +
  +	dataInByte[srcLen] = 0;
  +
  +    /***
  +     * Forward to the actual decoding method to do the decoding
  +     */
  +	*decodedLen = 0;
  +	return decode(dataInByte, decodedLen, memMgr, conform);
   }
   
   /***
  
  
  
  1.14      +28 -2     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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Base64.hpp	8 Sep 2004 13:56:21 -0000	1.13
  +++ Base64.hpp	10 Dec 2004 10:37:56 -0000	1.14
  @@ -113,14 +113,40 @@
        * @return Decoded binary data in XMLCh stream,
        *      or NULL if input data can not be decoded.
        * @see   XMLString::release(XMLCh**)
  +     * @deprecated use decodeToXMLByte instead.
        */
  +
       static XMLCh* decode(
                            const XMLCh*          const    inputData
                          ,       unsigned int*            decodedLength
                          ,       MemoryManager*  const    memMgr = 0
                          ,       Conformance              conform = Conf_RFC2045
                           );
  -
  +   
  +   /**
  +     * Decodes Base64 data into octets
  +     *
  +     * NOTE: The returned buffer is dynamically allocated and is the
  +     * responsibility of the caller to delete it when not longer needed.
  +     * You can call XMLString::release to release this returned buffer.
  +     *
  +     * If a memory manager is provided, ask the memory manager to de-allocate
  +     * the returned buffer.
  +     *
  +     * @param inputData Base64 data in XMLCh stream.
  +     * @param decodedLength 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* decodeToXMLByte(
  +                           const XMLCh*          const   inputData
  +                         ,       unsigned int*           decodedLength
  +                         ,       MemoryManager*  const   memMgr = 0
  +                         ,       Conformance             conform = Conf_RFC2045
  +                          );
       /**
        * Get data length
   	 *
  
  
  
  1.6       +56 -22    xml-xerces/c/src/xercesc/util/HexBin.cpp
  
  Index: HexBin.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/HexBin.cpp,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- HexBin.cpp	8 Sep 2004 13:56:22 -0000	1.5
  +++ HexBin.cpp	10 Dec 2004 10:37:56 -0000	1.6
  @@ -16,6 +16,9 @@
   
   /*
    * $Log$
  + * Revision 1.6  2004/12/10 10:37:56  cargilld
  + * Fix problem with hexbin::decode and use XMLByte instead of XMLCh for output of decoding.
  + *
    * Revision 1.5  2004/09/08 13:56:22  peiyongz
    * Apache License Version 2.0
    *
  @@ -54,7 +57,7 @@
   // ---------------------------------------------------------------------------
   //  class data member
   // ---------------------------------------------------------------------------
  -bool HexBin::hexNumberTable[BASELENGTH];
  +XMLByte HexBin::hexNumberTable[BASELENGTH];
   bool HexBin::isInitialized = false;
   
   int HexBin::getDataLength(const XMLCh* const hexData)
  @@ -97,7 +100,6 @@
       return retStr;
   }
   
  -
   XMLCh* HexBin::decode(const XMLCh*          const   hexData
                       ,       MemoryManager*  const   manager)
   {
  @@ -112,29 +114,61 @@
           init();
   
       //prepare the return string
  -    XMLCh *retVal = (XMLCh*) manager->allocate( (strLen/2 + 1) * sizeof(XMLCh));
  +    int decodeLength = strLen/2;
  +    XMLCh *retVal = (XMLCh*) manager->allocate( (decodeLength + 1) * sizeof(XMLCh));
       ArrayJanitor<XMLCh> janFill(retVal, manager);
  +    
  +    XMLByte temp1, temp2;
  +    for( int i = 0; i<decodeLength; i++ ) {
  +        temp1 = hexNumberTable[hexData[i*2]];
  +        if (temp1 == (XMLByte) -1)
  +            return 0;
  +        temp2 = hexNumberTable[hexData[i*2+1]];
  +        if (temp2 == (XMLByte) -1)
  +            return 0;
  +        retVal[i] = (XMLCh)((temp1 << 4) | temp2);
  +    }
   
  -    for ( int i = 0; i < strLen; )
  -    {
  -        if( !isHex(hexData[i])  || 
  -            !isHex(hexData[i+1])  )
  +    janFill.release();
  +    retVal[decodeLength] = 0;
  +    return retVal;
  +}
  +
  +XMLByte* HexBin::decodeToXMLByte(const XMLCh*          const   hexData
  +                    ,       MemoryManager*  const   manager)
  +{
  +    if (( hexData == 0 ) || ( *hexData == 0 )) // zero length
  +        return 0;
  +
  +    int strLen = XMLString::stringLen(hexData);
  +    if ( strLen%2 != 0 )
  +        return 0;
  +
  +    if ( !isInitialized )
  +        init();
  +
  +    //prepare the return string
  +    int decodeLength = strLen/2;
  +    XMLByte *retVal = (XMLByte*) manager->allocate( (decodeLength + 1) * sizeof(XMLByte));
  +    ArrayJanitor<XMLByte> janFill(retVal, manager);
  +    
  +    XMLByte temp1, temp2;
  +    for( int i = 0; i<decodeLength; i++ ) {
  +        temp1 = hexNumberTable[hexData[i*2]];
  +        if (temp1 == (XMLByte) -1)
               return 0;
  -        else
  -        {
  -            retVal[i/2] = (XMLCh)(
  -                                   (((XMLByte) hexData[i]) << 4 ) | 
  -                                    ((XMLByte) hexData[i+1])
  -                                 );      
  -            i+=2;
  -        }
  +        temp2 = hexNumberTable[hexData[i*2+1]];
  +        if (temp2 == (XMLByte) -1)
  +            return 0;
  +        retVal[i] = ((temp1 << 4) | temp2);
       }
   
       janFill.release();
  -    retVal[strLen/2] = 0;
  +    retVal[decodeLength] = 0;
       return retVal;
   }
   
  +
   // -----------------------------------------------------------------------
   //  Helper methods
   // -----------------------------------------------------------------------
  @@ -144,7 +178,7 @@
       if ( octet >= BASELENGTH )
           return false;
   
  -    return (hexNumberTable[octet]);
  +    return (hexNumberTable[octet] != (XMLByte) -1);
   }
   
   void HexBin::init()
  @@ -154,16 +188,16 @@
   
       int i;
       for ( i = 0; i < BASELENGTH; i++ )
  -        hexNumberTable[i] = false;
  +        hexNumberTable[i] = -1;
   
       for ( i = chDigit_9; i >= chDigit_0; i-- )
  -        hexNumberTable[i] = true;
  +        hexNumberTable[i] = (XMLByte) (i - chDigit_0);
   
       for ( i = chLatin_F; i >= chLatin_A; i-- )
  -        hexNumberTable[i] = true;
  -
  +        hexNumberTable[i] = (XMLByte) (i - chLatin_A + 10);
  + 
       for ( i = chLatin_f; i >= chLatin_a; i-- )
  -        hexNumberTable[i] = true;
  +        hexNumberTable[i] = (XMLByte) (i - chLatin_a + 10);    
   
       isInitialized = true;
   }
  
  
  
  1.7       +25 -2     xml-xerces/c/src/xercesc/util/HexBin.hpp
  
  Index: HexBin.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/HexBin.hpp,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- HexBin.hpp	8 Sep 2004 13:56:22 -0000	1.6
  +++ HexBin.hpp	10 Dec 2004 10:37:56 -0000	1.7
  @@ -87,12 +87,35 @@
        * @return Decoded binary data in XMLCh stream,
        *      or NULL if input data can not be decoded.
        * @see   XMLString::release(XMLCh**)
  +     * @deprecated use decodeToXMLByte instead.
        */
  +
       static XMLCh* decode(
                            const XMLCh*          const    hexData
                          ,       MemoryManager*  const    manager = XMLPlatformUtils::fgMemoryManager
                           );
   
  +   /**
  +     * Decodes HexBinary data into XMLByte
  +     *
  +     * NOTE: The returned buffer is dynamically allocated and is the
  +     * responsibility of the caller to delete it when not longer needed.
  +     * You can call XMLString::release to release this returned buffer.
  +     *
  +     * If a memory manager is provided, ask the memory manager to de-allocate
  +     * the returned buffer.
  +     *
  +     * @param hexData HexBinary data in XMLCh stream.
  +     * @param manager client provided memory manager
  +     * @return Decoded binary data in XMLByte stream,
  +     *      or NULL if input data can not be decoded.
  +     * @see   XMLString::release(XMLByte**)
  +     */
  +    static XMLByte* decodeToXMLByte(
  +                         const XMLCh*          const    hexData
  +                       ,       MemoryManager*  const    manager = XMLPlatformUtils::fgMemoryManager
  +                        );
  +
   
       //@}
   
  @@ -126,7 +149,7 @@
       //
       // -----------------------------------------------------------------------
       static bool       isInitialized;
  -    static bool       hexNumberTable[];
  +    static XMLByte    hexNumberTable[];
   };
   
   XERCES_CPP_NAMESPACE_END
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org