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:     4th February 2012
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-2012, 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    6
00059 # define B64_VER_B64_H_B64_REVISION 3
00060 # define B64_VER_B64_H_B64_EDIT     35
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 # define B64_VER_1_3_2          0x010302ff
00095 # define B64_VER_1_3_3          0x010303ff
00096 # define B64_VER_1_3_4          0x010304ff
00097 # define B64_VER_1_4_1_ALPHA_1  0x01040101
00098 # define B64_VER_1_4_2          0x010402ff
00099 #endif /* !B64_DOCUMENTATION_SKIP_SECTION */
00100 
00101 #define B64_VER_MAJOR       1
00102 #define B64_VER_MINOR       4
00103 #define B64_VER_REVISION    2
00104 #define B64_VER             0x010402ff
00105 
00106 /* /////////////////////////////////////////////////////////////////////////
00107  * Includes
00108  */
00109 
00110 #include <stddef.h>
00111 
00112 /* /////////////////////////////////////////////////////////////////////////
00113  * Features
00114  */
00115 
00116 /* If the Synesis preprocessor symbol SYNESIS_VARIANT_TEST is defined, then we
00117  * automatically define B64_VARIANT_TEST, which requests a test build: i.e.
00118  * debug information off, optimisations on, contract enforcements on
00119  */
00120 #if defined(SYNESIS_VARIANT_TEST)
00121 # if !defined(B64_VARIANT_TEST)
00122 #  define B64_VARIANT_TEST
00123 # endif /* !B64_VARIANT_TEST */
00124 #endif /* SYNESIS_VARIANT_TEST */
00125 
00126 /* /////////////////////////////////////////////////////////////////////////
00127  * Namespace
00128  */
00129 
00130 #if !defined(B64_NO_NAMESPACE) && \
00131     !defined(__cplusplus)
00132 # define B64_NO_NAMESPACE
00133 #endif /* !B64_NO_NAMESPACE && !__cplusplus */
00134 
00135 #ifdef B64_NAMESPACE
00136 # undef B64_NAMESPACE
00137 #endif /* B64_NAMESPACE */
00138 
00139 #ifdef B64_NAMESPACE_QUALIFIER
00140 # undef B64_NAMESPACE_QUALIFIER
00141 #endif /* B64_NAMESPACE_QUALIFIER */
00142 
00143 
00144 #ifndef B64_NO_NAMESPACE
00145 
00146 # ifdef B64_CUSTOM_NAMESPACE
00147 #  define B64_NAMESPACE     B64_CUSTOM_NAMESPACE
00148 # else /* ? B64_CUSTOM_NAMESPACE */
00149 #  define B64_NAMESPACE     b64
00150 # endif /* B64_CUSTOM_NAMESPACE */
00151 
00152 # if defined(B64_CUSTOM_NAMESPACE) && \
00153      defined(B64_CUSTOM_NAMESPACE_QUALIFIER)
00154 #  define B64_NAMESPACE_QUALIFIER       B64_CUSTOM_NAMESPACE_QUALIFIER
00155 # else /* B64_CUSTOM_NAMESPACE && B64_CUSTOM_NAMESPACE_QUALIFIER */
00156 #  define B64_NAMESPACE_QUALIFIER       ::B64_NAMESPACE
00157 # endif /* B64_CUSTOM_NAMESPACE && B64_CUSTOM_NAMESPACE_QUALIFIER */
00158 
00159 
00168 namespace B64_NAMESPACE
00169 {
00170 #endif /* !B64_NO_NAMESPACE */
00171 
00172 /* /////////////////////////////////////////////////////////////////////////
00173  * Typedefs
00174  */
00175 
00180 typedef char    b64_char_t;
00181 
00184 enum B64_RC
00185 {
00186         B64_RC_OK                   =   0   
00187     ,   B64_RC_INSUFFICIENT_BUFFER  =   1   
00188     ,   B64_RC_TRUNCATED_INPUT      =   2   
00189     ,   B64_RC_DATA_ERROR           =   3   
00190 #ifndef B64_DOCUMENTATION_SKIP_SECTION
00191     ,   B64_max_RC_value
00192 #endif /* !B64_DOCUMENTATION_SKIP_SECTION */
00193 };
00194 
00195 #ifndef __cplusplus
00196 typedef enum B64_RC B64_RC;
00197 #endif /* !__cplusplus */
00198 
00201 enum B64_FLAGS
00202 {
00203         B64_F_LINE_LEN_USE_PARAM    =   0x0000  
00204     ,   B64_F_LINE_LEN_INFINITE     =   0x0001  
00205     ,   B64_F_LINE_LEN_64           =   0x0002  
00206     ,   B64_F_LINE_LEN_76           =   0x0003  
00207     ,   B64_F_LINE_LEN_MASK         =   0x000f  
00208     ,   B64_F_STOP_ON_NOTHING       =   0x0000  
00209     ,   B64_F_STOP_ON_UNKNOWN_CHAR  =   0x0100  
00210     ,   B64_F_STOP_ON_UNEXPECTED_WS =   0x0200  
00211     ,   B64_F_STOP_ON_BAD_CHAR      =   0x0300  
00212 };
00213 
00214 #ifndef __cplusplus
00215 typedef enum B64_FLAGS  B64_FLAGS;
00216 #endif /* !__cplusplus */
00217 
00218 /* /////////////////////////////////////////////////////////////////////////
00219  * Functions
00220  */
00221 
00222 #ifdef __cplusplus
00223 extern "C" {
00224 #endif /* __cplusplus */
00225 
00249 size_t b64_encode(
00250     void const* src
00251 ,   size_t      srcSize
00252 ,   b64_char_t* dest
00253 ,   size_t      destLen
00254 );
00255 
00284 size_t b64_encode2(
00285     void const* src
00286 ,   size_t      srcSize
00287 ,   b64_char_t* dest
00288 ,   size_t      destLen
00289 ,   unsigned    flags
00290 ,   int         lineLen /* = 0 */
00291 ,   B64_RC*     rc     /* = NULL */
00292 );
00293 
00327 size_t b64_decode(
00328     b64_char_t const*   src
00329 ,   size_t              srcLen
00330 ,   void*               dest
00331 ,   size_t              destSize
00332 );
00333 
00374 size_t b64_decode2(
00375     b64_char_t const*   src
00376 ,   size_t              srcLen
00377 ,   void*               dest
00378 ,   size_t              destSize
00379 ,   unsigned            flags
00380 ,   b64_char_t const**  badChar /* = NULL */
00381 ,   B64_RC*             rc      /* = NULL */
00382 );
00383 
00391 char const* b64_getErrorString(B64_RC code);
00392 
00402 size_t b64_getErrorStringLength(B64_RC code);
00403 
00404 
00413 #define b64_getStatusCodeString         b64_getErrorString
00414 
00423 #define b64_getStatusCodeStringLength   b64_getErrorStringLength
00424 
00425 
00426 #ifdef __cplusplus
00427 } /* extern "C" */
00428 #endif /* __cplusplus */
00429 
00430 /* /////////////////////////////////////////////////////////////////////////
00431  * Namespace
00432  */
00433 
00434 #ifndef B64_NO_NAMESPACE
00435 } /* namespace B64_NAMESPACE */
00436 
00437 # ifndef B64_DOCUMENTATION_SKIP_SECTION
00438 
00439 namespace stlsoft
00440 {
00441 
00442     inline char const *c_str_data_a( B64_NAMESPACE_QUALIFIER::B64_RC code)
00443     {
00444         return B64_NAMESPACE_QUALIFIER::b64_getStatusCodeString(code);
00445     }
00446     inline char const *c_str_data( B64_NAMESPACE_QUALIFIER::B64_RC code)
00447     {
00448         return B64_NAMESPACE_QUALIFIER::b64_getStatusCodeString(code);
00449     }
00450 
00451     inline size_t c_str_len_a( B64_NAMESPACE_QUALIFIER::B64_RC code)
00452     {
00453         return B64_NAMESPACE_QUALIFIER::b64_getStatusCodeStringLength(code);
00454     }
00455     inline size_t c_str_len( B64_NAMESPACE_QUALIFIER::B64_RC code)
00456     {
00457         return B64_NAMESPACE_QUALIFIER::b64_getStatusCodeStringLength(code);
00458     }
00459 
00460     inline char const *c_str_ptr_a( B64_NAMESPACE_QUALIFIER::B64_RC code)
00461     {
00462         return B64_NAMESPACE_QUALIFIER::b64_getStatusCodeString(code);
00463     }
00464     inline char const *c_str_ptr( B64_NAMESPACE_QUALIFIER::B64_RC code)
00465     {
00466         return B64_NAMESPACE_QUALIFIER::b64_getStatusCodeString(code);
00467     }
00468 
00469 } /* namespace stlsoft */
00470 
00471 # endif /* !B64_DOCUMENTATION_SKIP_SECTION */
00472 
00473 #endif /* !B64_NO_NAMESPACE */
00474 
00475 /* ////////////////////////////////////////////////////////////////////// */
00476 
00477 #endif /* B64_INCL_B64_H_B64 */
00478 
00479 /* ///////////////////////////// end of file //////////////////////////// */

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