Decode base64 encoded source from the supplied chain iterator to the end of the source. This function is provided because bese64 encoded matter is often found partway into a chain (see email processing). By use of this function a separate step of copying the partial chain is avoided

Return TypeFunction nameArguments
hzEcodeBase64Decode(hzChain&,hzChain::Iter&,)

Declared in file: hzCodec.h
Defined in file : hzCodec.cpp

Function Logic:

0:START 1:items zi 2:unknown 3:unknown 4:items 5:unknown 6:items 7:a items b items c items d items 8:unknown 9:Return E_FORMAT 10:val 11:unknown 12:val 13:unknown 14:val 15:unknown 16:val 17:unknown 18:val 19:items items val c items 20:unknown 21:items 22:unknown 23:items 24:Return E_OK

Function body:

hzEcode Base64Decode (hzChain& Decoded)hzChain::Iter& ci, 
{
   //  Category: Codec
   //  
   //  Decode base64 encoded source from the supplied chain iterator to the end of the source.
   //  
   //  This function is provided because bese64 encoded matter is often found partway into a chain (see email processing). By use of
   //  this function a separate step of copying the partial chain is avoided
   //  
   //  Arguments: 1) Decoded  Chain to contain result of decode operation
   //     2) ci   Chain iterator into encoded data
   //  
   //  Returns: E_FORMAT If the input chain contains unexpected sequences
   //     E_OK  If the input was decoded
   _hzfunc("Base64Decode(chIter)") ;
   chIter      zi ;        //  Iterator
   int32_t     val ;       //  Holds 24 bit value to be written as 3 bytes
   int32_t     a ;         //  Input 1st value
   int32_t     b ;         //  Input 2nd value
   int32_t     c ;         //  Input 3rd value
   int32_t     d ;         //  Input 4th value
   Decoded.Clear() ;
   //  Loop through collecting sets of 4 chars and writing out sets of 3 chars
   zi = ci ;
   for (; !zi.eof() ;)
   {
       if (*zi == CHAR_CR) { zi++ ; continue ; }
       if (*zi == CHAR_NL) { zi++ ; continue ; }
       a = _get6bit(*zi) ; zi++ ;
       b = _get6bit(*zi) ; zi++ ;
       c = _get6bit(*zi) ; zi++ ;
       d = _get6bit(*zi) ; zi++ ;
       if (a == 101||b== 101||c== 101||d== 101)
           return E_FORMAT ;
       val = 0;
       if (a < 100)val += (a << 18);
       if (b < 100)val += (b << 12);
       if (c < 100)val += (c << 6);
       if (d < 100)val += d ;
       a = (val & 0xff0000)>>16;
       b = (val & 0xff00)>>8;
       c = val & 0xff;
       Decoded.AddByte(a) ;
       if (b)
           Decoded.AddByte(b) ;
       if (c)
           Decoded.AddByte(c) ;
   }
   return E_OK ;
}