Synesis Software STLSoft - ... Robust, Lightweight, Cross-platform, Template Software ...

b64/b64.h

Go to the documentation of this file.
00001 /* /////////////////////////////////////////////////////////////////////////////
00002  * File:        b64/b64.h
00003  *
00004  * Purpose:     Header file for the b64 library
00005  *
00006  * Created:     18th October 2004
00007  * Updated:     15th March 2008
00008  *
00009  * Thanks:      To Adam McLaurin, for ideas regarding the b64_decode2() and
00010  *              b64_encode2().
00011  *
00012  * Home:        http://synesis.com.au/software/
00013  *
00014  * Copyright (c) 2004-2008, Matthew Wilson and Synesis Software
00015  * All rights reserved.
00016  *
00017  * Redistribution and use in source and binary forms, with or without
00018  * modification, are permitted provided that the following conditions are met:
00019  *
00020  * - Redistributions of source code must retain the above copyright notice, this
00021  *   list of conditions and the following disclaimer.
00022  * - Redistributions in binary form must reproduce the above copyright notice,
00023  *   this list of conditions and the following disclaimer in the documentation
00024  *   and/or other materials provided with the distribution.
00025  * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
00026  *   any contributors may be used to endorse or promote products derived from
00027  *   this software without specific prior written permission.
00028  *
00029  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00030  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00031  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00032  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00033  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00034  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00035  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00036  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00037  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00038  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00039  * POSSIBILITY OF SUCH DAMAGE.
00040  *
00041  * ////////////////////////////////////////////////////////////////////////// */
00042 
00043 
00049 #ifndef B64_INCL_B64_H_B64
00050 #define B64_INCL_B64_H_B64
00051 
00052 /* /////////////////////////////////////////////////////////////////////////////
00053  * Version information
00054  */
00055 
00056 #ifndef B64_DOCUMENTATION_SKIP_SECTION
00057 # define B64_VER_B64_H_B64_MAJOR    1
00058 # define B64_VER_B64_H_B64_MINOR    5
00059 # define B64_VER_B64_H_B64_REVISION 1
00060 # define B64_VER_B64_H_B64_EDIT     25
00061 #endif /* !B64_DOCUMENTATION_SKIP_SECTION */
00062 
00079 #ifndef B64_DOCUMENTATION_SKIP_SECTION
00080 # define B64_VER_1_0_1      0x01000100
00081 # define B64_VER_1_0_2      0x01000200
00082 # define B64_VER_1_0_3      0x01000300
00083 # define B64_VER_1_1_1      0x01010100
00084 # define B64_VER_1_1_2      0x01010200
00085 # define B64_VER_1_1_3      0x01010300
00086 # define B64_VER_1_2_1      0x01020100
00087 # define B64_VER_1_2_2      0x01020200
00088 # define B64_VER_1_2_3      0x01020300
00089 # define B64_VER_1_2_4      0x01020400
00090 # define B64_VER_1_2_5      0x01020500
00091 # define B64_VER_1_2_6      0x01020600
00092 # define B64_VER_1_2_7      0x01020700
00093 # define B64_VER_1_3_1      0x010301ff
00094 
00095 # define B64_VER            B64_VER_1_3_1
00096 #else /* ? B64_DOCUMENTATION_SKIP_SECTION */
00097 # define B64_VER            0x010301ff
00098 #endif /* !B64_DOCUMENTATION_SKIP_SECTION */
00099 
00100 #define B64_VER_MAJOR       1
00101 #define B64_VER_MINOR       3
00102 #define B64_VER_REVISION    1
00103 
00104 /* /////////////////////////////////////////////////////////////////////////////
00105  * Includes
00106  */
00107 
00108 #include <stddef.h>
00109 
00110 /* /////////////////////////////////////////////////////////////////////////////
00111  * Namespace
00112  */
00113 
00114 #if !defined(B64_NO_NAMESPACE) && \
00115     !defined(__cplusplus)
00116 # define B64_NO_NAMESPACE
00117 #endif /* !B64_NO_NAMESPACE && !__cplusplus */
00118 
00119 #ifdef B64_NAMESPACE
00120 # undef B64_NAMESPACE
00121 #endif /* B64_NAMESPACE */
00122 
00123 #ifdef B64_NAMESPACE_QUALIFIER
00124 # undef B64_NAMESPACE_QUALIFIER
00125 #endif /* B64_NAMESPACE_QUALIFIER */
00126 
00127 
00128 #ifndef B64_NO_NAMESPACE
00129 
00130 # ifdef B64_CUSTOM_NAMESPACE
00131 #  define B64_NAMESPACE     B64_CUSTOM_NAMESPACE
00132 # else /* ? B64_CUSTOM_NAMESPACE */
00133 #  define B64_NAMESPACE     b64
00134 # endif /* B64_CUSTOM_NAMESPACE */
00135 
00136 # if defined(B64_CUSTOM_NAMESPACE) && \
00137      defined(B64_CUSTOM_NAMESPACE_QUALIFIER)
00138 #  define B64_NAMESPACE_QUALIFIER       B64_CUSTOM_NAMESPACE_QUALIFIER
00139 # else /* B64_CUSTOM_NAMESPACE && B64_CUSTOM_NAMESPACE_QUALIFIER */
00140 #  define B64_NAMESPACE_QUALIFIER       ::B64_NAMESPACE
00141 # endif /* B64_CUSTOM_NAMESPACE && B64_CUSTOM_NAMESPACE_QUALIFIER */
00142 
00143 
00152 namespace B64_NAMESPACE
00153 {
00154 #endif /* !B64_NO_NAMESPACE */
00155 
00156 /* /////////////////////////////////////////////////////////////////////////////
00157  * Enumerations
00158  */
00159 
00162 enum B64_RC
00163 {
00164         B64_RC_OK                   =   0   
00165     ,   B64_RC_INSUFFICIENT_BUFFER  =   1   
00166     ,   B64_RC_TRUNCATED_INPUT      =   2   
00167     ,   B64_RC_DATA_ERROR           =   3   
00168 #ifndef B64_DOCUMENTATION_SKIP_SECTION
00169     ,   B64_max_RC_value
00170 #endif /* !B64_DOCUMENTATION_SKIP_SECTION */
00171 };
00172 
00173 #ifndef __cplusplus
00174 typedef enum B64_RC B64_RC;
00175 #endif /* !__cplusplus */
00176 
00179 enum B64_FLAGS
00180 {
00181         B64_F_LINE_LEN_USE_PARAM    =   0x0000  
00182     ,   B64_F_LINE_LEN_INFINITE     =   0x0001  
00183     ,   B64_F_LINE_LEN_64           =   0x0002  
00184     ,   B64_F_LINE_LEN_76           =   0x0003  
00185     ,   B64_F_LINE_LEN_MASK         =   0x000f  
00186     ,   B64_F_STOP_ON_NOTHING       =   0x0000  
00187     ,   B64_F_STOP_ON_UNKNOWN_CHAR  =   0x0100  
00188     ,   B64_F_STOP_ON_UNEXPECTED_WS =   0x0200  
00189     ,   B64_F_STOP_ON_BAD_CHAR      =   0x0300  
00190 };
00191 
00192 #ifndef __cplusplus
00193 typedef enum B64_FLAGS  B64_FLAGS;
00194 #endif /* !__cplusplus */
00195 
00196 /* /////////////////////////////////////////////////////////////////////////////
00197  * Functions
00198  */
00199 
00200 #ifdef __cplusplus
00201 extern "C" {
00202 #endif /* __cplusplus */
00203 
00227 size_t b64_encode(void const *src, size_t srcSize, char *dest, size_t destLen);
00228 
00257 size_t b64_encode2( void const  *src
00258                 ,   size_t      srcSize
00259                 ,   char        *dest
00260                 ,   size_t      destLen
00261                 ,   unsigned    flags
00262                 ,   int         lineLen /* = 0 */
00263                 ,   B64_RC      *rc     /* = NULL */);
00264 
00298 size_t b64_decode(char const *src, size_t srcLen, void *dest, size_t destSize);
00299 
00340 size_t b64_decode2( char const  *src
00341                 ,   size_t      srcLen
00342                 ,   void        *dest
00343                 ,   size_t      destSize
00344                 ,   unsigned    flags
00345                 ,   char const  **badChar   /* = NULL */
00346                 ,   B64_RC      *rc         /* = NULL */);
00347 
00348 
00353 char const *b64_getErrorString(B64_RC code);
00354 
00361 size_t b64_getErrorStringLength(B64_RC code);
00362 
00363 
00364 #ifdef __cplusplus
00365 } /* extern "C" */
00366 #endif /* __cplusplus */
00367 
00368 /* /////////////////////////////////////////////////////////////////////////////
00369  * Namespace
00370  */
00371 
00372 #ifndef B64_NO_NAMESPACE
00373 } /* namespace B64_NAMESPACE */
00374 
00375 # ifndef B64_DOCUMENTATION_SKIP_SECTION
00376 
00377 namespace stlsoft
00378 {
00379 
00380     inline char const *c_str_data_a( B64_NAMESPACE_QUALIFIER::B64_RC code)
00381     {
00382         return B64_NAMESPACE_QUALIFIER::b64_getErrorString(code);
00383     }
00384     inline char const *c_str_data( B64_NAMESPACE_QUALIFIER::B64_RC code)
00385     {
00386         return B64_NAMESPACE_QUALIFIER::b64_getErrorString(code);
00387     }
00388 
00389     inline size_t c_str_len_a( B64_NAMESPACE_QUALIFIER::B64_RC code)
00390     {
00391         return B64_NAMESPACE_QUALIFIER::b64_getErrorStringLength(code);
00392     }
00393     inline size_t c_str_len( B64_NAMESPACE_QUALIFIER::B64_RC code)
00394     {
00395         return B64_NAMESPACE_QUALIFIER::b64_getErrorStringLength(code);
00396     }
00397 
00398     inline char const *c_str_ptr_a( B64_NAMESPACE_QUALIFIER::B64_RC code)
00399     {
00400         return B64_NAMESPACE_QUALIFIER::b64_getErrorString(code);
00401     }
00402     inline char const *c_str_ptr( B64_NAMESPACE_QUALIFIER::B64_RC code)
00403     {
00404         return B64_NAMESPACE_QUALIFIER::b64_getErrorString(code);
00405     }
00406 
00407 } /* namespace stlsoft */
00408 
00409 # endif /* !B64_DOCUMENTATION_SKIP_SECTION */
00410 
00411 #endif /* !B64_NO_NAMESPACE */
00412 
00413 /* ////////////////////////////////////////////////////////////////////////// */
00414 
00415 #endif /* B64_INCL_B64_H_B64 */
00416 
00417 /* ////////////////////////////////////////////////////////////////////////// */

b64 Library documentation © Synesis Software Pty Ltd, 2004-2007