]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/base64.h
Make storing non-trivial data in wxThreadSpecificInfo possible.
[wxWidgets.git] / interface / wx / base64.h
CommitLineData
23324ae1 1/////////////////////////////////////////////////////////////////////////////
7c913512 2// Name: base64.h
e54c96f1 3// Purpose: interface of global functions
7c913512 4// Author: wxWidgets team
526954c5 5// Licence: wxWindows licence
7c913512
FM
6/////////////////////////////////////////////////////////////////////////////
7
698d17c3
FM
8
9// ============================================================================
10// Global functions/macros
11// ============================================================================
12
b21126db 13/** @addtogroup group_funcmacro_misc */
7c913512 14//@{
698d17c3 15
7aa3b31d
VZ
16/**
17 Elements of this enum specify the possible behaviours of wxBase64Decode
18 when an invalid character is encountered.
19*/
20enum wxBase64DecodeMode
21{
22 wxBase64DecodeMode_Strict, ///< Normal behaviour: stop at any invalid characters.
23 wxBase64DecodeMode_SkipWS, ///< Skip whitespace characters.
24 wxBase64DecodeMode_Relaxed ///< The most lenient behaviour: simply ignore all invalid characters.
25};
26
23324ae1 27/**
698d17c3
FM
28 This function encodes the given data using base64.
29
7fa7088e
BP
30 To allocate the buffer of the correct size, use wxBase64EncodedSize() or
31 call this function with @a dst set to @NULL -- it will then return the
32 necessary buffer size.
698d17c3
FM
33
34 This raw encoding function overload writes the output string into the
35 provided buffer; the other overloads return it as a wxString.
7c913512
FM
36
37 @param dst
698d17c3 38 The output buffer, may be @NULL to retrieve the needed buffer size.
7c913512 39 @param dstLen
4cc4bfaf 40 The output buffer size, ignored if dst is @NULL.
7c913512 41 @param src
4cc4bfaf 42 The input buffer, must not be @NULL.
7c913512 43 @param srcLen
4cc4bfaf 44 The length of the input data.
698d17c3 45
d29a9a8a 46 @return @c wxCONV_FAILED if the output buffer is too small.
7fa7088e
BP
47
48 @header{wx/base64.h}
23324ae1 49*/
4cc4bfaf
FM
50size_t wxBase64Encode(char* dst, size_t dstLen,
51 const void* src,
23324ae1 52 size_t srcLen);
698d17c3
FM
53
54/**
7fa7088e
BP
55 This function encodes the given data using base64 and returns the output as
56 a wxString.
698d17c3
FM
57
58 There is no error return.
59
7fa7088e
BP
60 To allocate the buffer of the correct size, use wxBase64EncodedSize() or
61 call this function with @a dst set to @NULL -- it will then return the
62 necessary buffer size.
698d17c3
FM
63
64 @param src
65 The input buffer, must not be @NULL.
66 @param srcLen
67 The length of the input data.
7fa7088e
BP
68
69 @header{wx/base64.h}
698d17c3 70*/
4cc4bfaf 71wxString wxBase64Encode(const void* src, size_t srcLen);
698d17c3
FM
72
73/**
7fa7088e
BP
74 This function encodes the given data using base64 and returns the output as
75 a wxString.
698d17c3
FM
76
77 There is no error return.
7fa7088e
BP
78
79 @header{wx/base64.h}
698d17c3 80*/
7c913512 81wxString wxBase64Encode(const wxMemoryBuffer& buf);
23324ae1
FM
82
83
7c913512 84/**
698d17c3
FM
85 Returns the size of the buffer necessary to contain the data encoded in a
86 base64 string of length @e srcLen. This can be useful for allocating a
87 buffer to be passed to wxBase64Decode().
7fa7088e
BP
88
89 @header{wx/base64.h}
23324ae1
FM
90*/
91size_t wxBase64DecodedSize(size_t srcLen);
92
93/**
94 Returns the length of the string with base64 representation of a buffer of
95 specified size @e len. This can be useful for allocating the buffer passed
e54c96f1 96 to wxBase64Encode().
7fa7088e
BP
97
98 @header{wx/base64.h}
23324ae1
FM
99*/
100size_t wxBase64EncodedSize(size_t len);
101
23324ae1 102/**
698d17c3
FM
103 This function decodes a Base64-encoded string.
104
7fa7088e
BP
105 This overload is a raw decoding function and decodes the data into the
106 provided buffer @a dst of the given size @e dstLen. An error is returned if
107 the buffer is not large enough -- that is not at least
07890fbe
VZ
108 wxBase64DecodedSize(srcLen) bytes. Notice that the buffer will @e not be
109 @NULL-terminated.
698d17c3
FM
110
111 This overload returns the number of bytes written to the buffer or the
7fa7088e
BP
112 necessary buffer size if @a dst was @NULL or @c wxCONV_FAILED on error,
113 e.g. if the output buffer is too small or invalid characters were
698d17c3 114 encountered in the input string.
7c913512
FM
115
116 @param dst
7fa7088e
BP
117 Pointer to output buffer, may be @NULL to just compute the necessary
118 buffer size.
7c913512 119 @param dstLen
698d17c3 120 The size of the output buffer, ignored if dst is @NULL.
7c913512 121 @param src
7fa7088e
BP
122 The input string, must not be @NULL. For the version using wxString,
123 the input string should contain only ASCII characters.
7c913512 124 @param srcLen
7fa7088e
BP
125 The length of the input string or special value wxNO_LEN if the string
126 is @NULL-terminated and the length should be computed by this function
127 itself.
7c913512 128 @param mode
3c4f71cc 129 This parameter specifies the function behaviour when invalid characters
698d17c3 130 are encountered in input. By default, any such character stops the
4cc4bfaf 131 decoding with error. If the mode is wxBase64DecodeMode_SkipWS, then the
698d17c3 132 white space characters are silently skipped instead. And if it is
4cc4bfaf 133 wxBase64DecodeMode_Relaxed, then all invalid characters are skipped.
7c913512 134 @param posErr
7fa7088e
BP
135 If this pointer is non-@NULL and an error occurs during decoding, it is
136 filled with the index of the invalid character.
137
138 @header{wx/base64.h}
23324ae1 139*/
4cc4bfaf
FM
140size_t wxBase64Decode(void* dst, size_t dstLen,
141 const char* src,
23324ae1
FM
142 size_t srcLen = wxNO_LEN,
143 wxBase64DecodeMode mode = wxBase64DecodeMode_Strict,
77782a5c 144 size_t *posErr = NULL);
698d17c3
FM
145
146/**
869bc90d
VZ
147 Decode a Base64-encoded wxString.
148
7aa3b31d 149 See the wxBase64Decode(void*,size_t,const char*,size_t,wxBase64DecodeMode,size_t*)
869bc90d
VZ
150 overload for more information about the parameters of this function, the
151 only difference between it and this one is that a wxString is used instead
152 of a @c char* pointer and its length.
153
154 @since 2.9.1
155
156 @header{wx/base64.h}
157 */
158size_t wxBase64Decode(void* dst, size_t dstLen,
159 const wxString& str,
160 wxBase64DecodeMode mode = wxBase64DecodeMode_Strict,
161 size_t *posErr = NULL);
698d17c3 162
869bc90d
VZ
163/**
164 Decode a Base64-encoded string and return decoded contents in a buffer.
698d17c3 165
869bc90d
VZ
166 See the wxBase64Decode(void*,size_t,const char*,size_t,wxBase64DecodeMode,size_t*)
167 overload for more information about the parameters of this function. The
168 difference of this overload is that it allocates a buffer of necessary size
169 on its own and returns it, freeing you from the need to do it manually.
170 Because of this, it is simpler to use and is recommended for normal use.
7fa7088e
BP
171
172 @header{wx/base64.h}
698d17c3 173*/
4cc4bfaf 174wxMemoryBuffer wxBase64Decode(const char* src,
7c913512
FM
175 size_t srcLen = wxNO_LEN,
176 wxBase64DecodeMode mode = wxBase64DecodeMode_Strict,
77782a5c 177 size_t *posErr = NULL);
698d17c3
FM
178
179/**
869bc90d
VZ
180 Decode a Base64-encoded wxString and return decoded contents in a buffer.
181
7aa3b31d 182 See the wxBase64Decode(void*,size_t,const char*,size_t,wxBase64DecodeMode,size_t*)
869bc90d 183 overload for more information about the parameters of this function.
698d17c3
FM
184
185 This overload takes as input a wxString and returns the internally-allocated
869bc90d 186 memory as a wxMemoryBuffer, containing the Base64-decoded data.
7fa7088e
BP
187
188 @header{wx/base64.h}
698d17c3 189*/
7c913512
FM
190wxMemoryBuffer wxBase64Decode(const wxString& src,
191 wxBase64DecodeMode mode = wxBase64DecodeMode_Strict,
77782a5c 192 size_t *posErr = NULL);
698d17c3 193
23324ae1
FM
194//@}
195