a-oRTP  5.2.0
b64.h
1 /* /////////////////////////////////////////////////////////////////////////////
2  * File: b64/b64.h
3  *
4  * Purpose: Header file for the b64 library
5  *
6  * Created: 18th October 2004
7  * Updated: 24th August 2008
8  *
9  * Thanks: To Adam McLaurin, for ideas regarding the b64_decode2() and
10  * b64_encode2().
11  *
12  * Home: http://synesis.com.au/software/
13  *
14  * Copyright (c) 2004-2008, Matthew Wilson and Synesis Software
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are met:
19  *
20  * - Redistributions of source code must retain the above copyright notice, this
21  * list of conditions and the following disclaimer.
22  * - Redistributions in binary form must reproduce the above copyright notice,
23  * this list of conditions and the following disclaimer in the documentation
24  * and/or other materials provided with the distribution.
25  * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
26  * any contributors may be used to endorse or promote products derived from
27  * this software without specific prior written permission.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
30  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
33  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39  * POSSIBILITY OF SUCH DAMAGE.
40  *
41  * ////////////////////////////////////////////////////////////////////////// */
42 
48 #ifndef B64_INCL_B64_H_B64
49 #define B64_INCL_B64_H_B64
50 
51 /* /////////////////////////////////////////////////////////////////////////////
52  * Version information
53  */
54 
55 #ifndef B64_DOCUMENTATION_SKIP_SECTION
56 #define B64_VER_B64_H_B64_MAJOR 1
57 #define B64_VER_B64_H_B64_MINOR 5
58 #define B64_VER_B64_H_B64_REVISION 4
59 #define B64_VER_B64_H_B64_EDIT 28
60 #endif /* !B64_DOCUMENTATION_SKIP_SECTION */
61 
78 #ifndef B64_DOCUMENTATION_SKIP_SECTION
79 #define B64_VER_1_0_1 0x01000100
80 #define B64_VER_1_0_2 0x01000200
81 #define B64_VER_1_0_3 0x01000300
82 #define B64_VER_1_1_1 0x01010100
83 #define B64_VER_1_1_2 0x01010200
84 #define B64_VER_1_1_3 0x01010300
85 #define B64_VER_1_2_1 0x01020100
86 #define B64_VER_1_2_2 0x01020200
87 #define B64_VER_1_2_3 0x01020300
88 #define B64_VER_1_2_4 0x01020400
89 #define B64_VER_1_2_5 0x01020500
90 #define B64_VER_1_2_6 0x01020600
91 #define B64_VER_1_2_7 0x01020700
92 #define B64_VER_1_3_1 0x010301ff
93 #define B64_VER_1_3_2 0x010302ff
94 #define B64_VER_1_3_3 0x010303ff
95 #define B64_VER_1_3_4 0x010304ff
96 
97 #define B64_VER B64_VER_1_3_4
98 #else /* ? B64_DOCUMENTATION_SKIP_SECTION */
99 #define B64_VER 0x010304ff
100 #endif /* !B64_DOCUMENTATION_SKIP_SECTION */
101 
102 #define B64_VER_MAJOR 1
103 #define B64_VER_MINOR 3
104 #define B64_VER_REVISION 4
105 
106 /* /////////////////////////////////////////////////////////////////////////////
107  * Includes
108  */
109 
110 #include <stddef.h>
111 
112 /* /////////////////////////////////////////////////////////////////////////////
113  * Namespace
114  */
115 
116 #if !defined(B64_NO_NAMESPACE) && !defined(__cplusplus)
117 #define B64_NO_NAMESPACE
118 #endif /* !B64_NO_NAMESPACE && !__cplusplus */
119 
120 #ifdef B64_NAMESPACE
121 #undef B64_NAMESPACE
122 #endif /* B64_NAMESPACE */
123 
124 #ifdef B64_NAMESPACE_QUALIFIER
125 #undef B64_NAMESPACE_QUALIFIER
126 #endif /* B64_NAMESPACE_QUALIFIER */
127 
128 #ifndef B64_NO_NAMESPACE
129 
130 #ifdef B64_CUSTOM_NAMESPACE
131 #define B64_NAMESPACE B64_CUSTOM_NAMESPACE
132 #else /* ? B64_CUSTOM_NAMESPACE */
133 #define B64_NAMESPACE b64
134 #endif /* B64_CUSTOM_NAMESPACE */
135 
136 #if defined(B64_CUSTOM_NAMESPACE) && defined(B64_CUSTOM_NAMESPACE_QUALIFIER)
137 #define B64_NAMESPACE_QUALIFIER B64_CUSTOM_NAMESPACE_QUALIFIER
138 #else /* B64_CUSTOM_NAMESPACE && B64_CUSTOM_NAMESPACE_QUALIFIER */
139 #define B64_NAMESPACE_QUALIFIER ::B64_NAMESPACE
140 #endif /* B64_CUSTOM_NAMESPACE && B64_CUSTOM_NAMESPACE_QUALIFIER */
141 
150 namespace B64_NAMESPACE {
151 #endif /* !B64_NO_NAMESPACE */
152 
153 /* /////////////////////////////////////////////////////////////////////////////
154  * Enumerations
155  */
156 
159 enum B64_RC {
160  B64_RC_OK = 0
161  ,
162  B64_RC_INSUFFICIENT_BUFFER = 1
163  ,
164  B64_RC_TRUNCATED_INPUT = 2
165  ,
166  B64_RC_DATA_ERROR = 3
167 #ifndef B64_DOCUMENTATION_SKIP_SECTION
168  ,
169  B64_max_RC_value
170 #endif /* !B64_DOCUMENTATION_SKIP_SECTION */
171 };
172 
173 #ifndef __cplusplus
174 typedef enum B64_RC B64_RC;
175 #endif /* !__cplusplus */
176 
179 enum B64_FLAGS {
180  B64_F_LINE_LEN_USE_PARAM = 0x0000
181  ,
182  B64_F_LINE_LEN_INFINITE = 0x0001
183  ,
184  B64_F_LINE_LEN_64 = 0x0002
185  ,
186  B64_F_LINE_LEN_76 = 0x0003
187  ,
188  B64_F_LINE_LEN_MASK = 0x000f
189  ,
190  B64_F_STOP_ON_NOTHING = 0x0000
191  ,
192  B64_F_STOP_ON_UNKNOWN_CHAR = 0x0100
193  ,
194  B64_F_STOP_ON_UNEXPECTED_WS = 0x0200
195  ,
196  B64_F_STOP_ON_BAD_CHAR = 0x0300
197 };
198 
199 #ifndef __cplusplus
200 typedef enum B64_FLAGS B64_FLAGS;
201 #endif /* !__cplusplus */
202 
203 /* /////////////////////////////////////////////////////////////////////////////
204  * Functions
205  */
206 
207 #ifdef __cplusplus
208 extern "C" {
209 #endif /* __cplusplus */
210 
234 size_t b64_encode(void const *src, size_t srcSize, char *dest, size_t destLen);
235 
264 size_t b64_encode2(void const *src, size_t srcSize, char *dest, size_t destLen, unsigned flags, int lineLen /* = 0 */
265  ,
266  B64_RC *rc /* = NULL */);
267 
301 size_t b64_decode(char const *src, size_t srcLen, void *dest, size_t destSize);
302 
343 size_t b64_decode2(char const *src, size_t srcLen, void *dest, size_t destSize, unsigned flags, char const **badChar /* = NULL */
344  ,
345  B64_RC *rc /* = NULL */);
346 
351 char const *b64_getErrorString(B64_RC code);
352 
359 size_t b64_getErrorStringLength(B64_RC code);
360 
361 #ifdef __cplusplus
362 } /* extern "C" */
363 #endif /* __cplusplus */
364 
365 /* /////////////////////////////////////////////////////////////////////////////
366  * Namespace
367  */
368 
369 #ifndef B64_NO_NAMESPACE
370 } /* namespace B64_NAMESPACE */
371 
372 #ifndef B64_DOCUMENTATION_SKIP_SECTION
373 
374 namespace stlsoft {
375 
376 inline char const *c_str_data_a(B64_NAMESPACE_QUALIFIER::B64_RC code) {
377  return B64_NAMESPACE_QUALIFIER::b64_getErrorString(code);
378 }
379 inline char const *c_str_data(B64_NAMESPACE_QUALIFIER::B64_RC code) {
380  return B64_NAMESPACE_QUALIFIER::b64_getErrorString(code);
381 }
382 
383 inline size_t c_str_len_a(B64_NAMESPACE_QUALIFIER::B64_RC code) {
384  return B64_NAMESPACE_QUALIFIER::b64_getErrorStringLength(code);
385 }
386 inline size_t c_str_len(B64_NAMESPACE_QUALIFIER::B64_RC code) {
387  return B64_NAMESPACE_QUALIFIER::b64_getErrorStringLength(code);
388 }
389 
390 inline char const *c_str_ptr_a(B64_NAMESPACE_QUALIFIER::B64_RC code) {
391  return B64_NAMESPACE_QUALIFIER::b64_getErrorString(code);
392 }
393 inline char const *c_str_ptr(B64_NAMESPACE_QUALIFIER::B64_RC code) {
394  return B64_NAMESPACE_QUALIFIER::b64_getErrorString(code);
395 }
396 
397 } /* namespace stlsoft */
398 
399 #endif /* !B64_DOCUMENTATION_SKIP_SECTION */
400 
401 #endif /* !B64_NO_NAMESPACE */
402 
403 /* ////////////////////////////////////////////////////////////////////////// */
404 
405 #endif /* B64_INCL_B64_H_B64 */
406 
407 /* ////////////////////////////////////////////////////////////////////////// */