20 impl_base64_digits[] =
21 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
31 impl_base64_value[256] =
34 65,65,65,65, 65,65,65,65, 65,65,65,65, 65,65,65,65,
35 65,65,65,65, 65,65,65,65, 65,65,65,65, 65,65,65,65,
36 65,65,65,65, 65,65,65,65, 65,65,65,62, 65,65,65,63,
37 52,53,54,55, 56,57,58,59, 60,61,65,65, 65,64,65,65,
38 65, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11,12,13,14,
39 15,16,17,18, 19,20,21,22, 23,24,25,65, 65,65,65,65,
40 65,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40,
41 41,42,43,44, 45,46,47,48, 49,50,51,65, 65,65,65,65,
42 65,65,65,65, 65,65,65,65, 65,65,65,65, 65,65,65,65,
43 65,65,65,65, 65,65,65,65, 65,65,65,65, 65,65,65,65,
44 65,65,65,65, 65,65,65,65, 65,65,65,65, 65,65,65,65,
45 65,65,65,65, 65,65,65,65, 65,65,65,65, 65,65,65,65,
46 65,65,65,65, 65,65,65,65, 65,65,65,65, 65,65,65,65,
47 65,65,65,65, 65,65,65,65, 65,65,65,65, 65,65,65,65,
48 65,65,65,65, 65,65,65,65, 65,65,65,65, 65,65,65,65,
49 65,65,65,65, 65,65,65,65, 65,65,65,65, 65,65,65,65
56 {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F' };
61 impl_hex_lookup[256] = {
62 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
63 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
64 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
65 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 255, 255, 255, 255, 255, 255,
66 255, 10, 11, 12, 13, 14, 15, 255, 255, 255, 255, 255, 255, 255, 255, 255,
67 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
68 255, 10, 11, 12, 13, 14, 15, 255, 255, 255, 255, 255, 255, 255, 255, 255,
69 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
70 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
71 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
72 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
73 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
74 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
75 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
76 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
77 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255
82 #define IMPL_BINARY_BUF_SEGMENT_SIZE 1000
103 static afw_size_t impl_callback(
void *context,
114 for (s = (
const afw_octet_t *)buffer, count = size;
118 if (self->last->used == IMPL_BINARY_BUF_SEGMENT_SIZE) {
122 segment->next = NULL;
124 self->last->next = segment;
125 self->last = segment;
127 self->last->s[
self->last->used++] = *s;
146 (
void *)&new_object, &
object, p, xctx);
170 &property_name, xctx);
192 encoded->len = ((memory->size + 2) / 3) * 4;
193 if (encoded->len == 0) {
201 for (i = 0; i < memory->size; i += 3) {
202 d1 = memory->ptr[i] >> 2;
203 d2 = (memory->ptr[i] & 0x03) << 4;
205 if ((i + 1) < memory->size) {
206 d2 |= memory->ptr[i + 1] >> 4;
207 d3 = (memory->ptr[i + 1] & 0x0f) << 2;
208 if ((i + 2) < memory->size) {
209 d3 |= memory->ptr[i + 2] >> 6;
210 d4 = memory->ptr[i + 2] & 0x3f;
213 *s++ = impl_base64_digits[d1];
214 *s++ = impl_base64_digits[d2];
215 *s++ = impl_base64_digits[d3];
216 *s++ = impl_base64_digits[d4];
234 for (non_ws_len = equals = 0, c = (
const afw_octet_t *)encoded->s, end = c + encoded->len; ; c++)
238 if (non_ws_len % 4 == 0)
break;
247 if (impl_base64_value[*c] <= 63) {
253 if (non_ws_len % 4 == 3) {
260 else if (non_ws_len % 4 == 2) {
261 if (c + 2 == end && *(c + 1) ==
'=') {
275 memory->size = (non_ws_len / 4) * 3 - equals;
276 if (memory->size == 0) {
284 for (c = (
const afw_octet_t *)encoded->s; c < end;)
291 *b++ = (impl_base64_value[c1] << 2) |
292 (impl_base64_value[c2] >> 4);
294 if (c3 ==
'=')
break;
296 *b++ = ((impl_base64_value[c2] << 4) & 0xF0) |
297 (impl_base64_value[c3] >> 2);
299 if (c4 ==
'=')
break;
301 *b++ = ((impl_base64_value[c3] << 6) & 0xC0) |
302 (impl_base64_value[c4]);
313 const unsigned char *in;
317 if (memory->size == 0) {
322 encoded->len = memory->size * 2;
325 for (count = memory->size, in = memory->ptr; count > 0; count--, in++) {
326 *out = impl_hex_digits[(*in) >> 4];
328 *out = impl_hex_digits[(*in) & 0x0f];
346 if (encoded->len & 1)
goto error;
348 if (encoded->len == 0) {
353 count = encoded->len / 2;
355 memory->size = count;
357 for (in = (
const afw_octet_t *)encoded->s; count > 0; in += 2, out++, count--)
359 if (*in != 0x20 && *in != 0x09 && *in != 0x0a && *in != 0x0d) {
360 if (impl_hex_lookup[*in] == 255 || impl_hex_lookup[*(in + 1)] == 255)
362 *out = (impl_hex_lookup[*in] << 4) + impl_hex_lookup[*(in + 1)];
387 writer->callback = impl_callback;
388 writer->context =
self;
389 self->pub.p = self_p;
393 self->first->next = NULL;
394 self->first->used = 0;
408 for (size = 0, segment = self->first; segment; segment = segment->next) {
409 size += segment->used;
428 for (size = 0, segment = self->first; segment; segment = segment->next)
430 callback(context, &segment->s[0], segment->used, self->result_p, xctx);
431 size += segment->used;
451 for (segment = self->first; segment; segment = segment->next) {
452 result->size += segment->used;
455 if (result->size > 0) {
458 for (segment = self->first; segment; segment = segment->next) {
459 memcpy(ptr, &segment->s[0], segment->used);
460 ptr += segment->used;
AFW_DEFINE(const afw_object_t *)
Adaptive Framework Core Internal.
#define afw_ascii_is_whitespace(v)
Determine if octet is white space.
afw_data_type_object
Data type struct for object.
#define AFW_UTF8_FMT_ARG(A_STRING)
Convenience Macro for use with AFW_UTF8_FMT to specify arg.
struct afw_iterator_s afw_iterator_t
#define AFW_UTF8_FMT
Format string specifier used for afw_utf8_t.
char afw_utf8_octet_t
8 bits of utf-8 codepoint.
apr_size_t afw_size_t
size_t.
unsigned char afw_octet_t
8 bits (unsigned).
afw_size_t(* afw_write_cb_t)(void *context, const void *buffer, afw_size_t size, const afw_pool_t *p, afw_xctx_t *xctx)
Typedef for write callback function.
#define afw_data_type_clone_internal(instance, to_internal, from_internal, p, xctx)
Call method clone_internal of interface afw_data_type.
#define AFW_THROW_ERROR_FZ(code, xctx, format_z,...)
Macro used to set error and 0 rv in xctx and throw it.
#define AFW_THROW_ERROR_Z(code, message_z, xctx)
Macro used to set error and 0 rv in xctx and throw it.
afw_memory_decode_base64(afw_memory_t *memory, const afw_utf8_t *encoded, const afw_pool_t *p, afw_xctx_t *xctx)
Decode memory to a base64 string.
afw_memory_writer_retrieve_using_callback_and_release(const afw_memory_writer_t *writer, void *context, afw_write_cb_t callback, afw_xctx_t *xctx)
Retrieve memory as using callback.
afw_memory_encode_printable_hex(afw_utf8_t *encoded, const afw_memory_t *memory, const afw_pool_t *p, afw_xctx_t *xctx)
Encode memory to a printable hex string.
afw_memory_writer_get_current_size(const afw_memory_writer_t *writer, afw_xctx_t *xctx)
Retrieve memory as one chunk from memory writer and release writer.
afw_memory_writer_retrieve_and_release(const afw_memory_writer_t *writer, afw_xctx_t *xctx)
Retrieve memory as one chunk from memory writer and release writer.
afw_memory_encode_base64(afw_utf8_t *encoded, const afw_memory_t *memory, const afw_pool_t *p, afw_xctx_t *xctx)
Encode memory to as base64 string.
afw_memory_create_writer(const afw_pool_t *p, afw_xctx_t *xctx)
Create a memory writer.
afw_memory_decode_printable_hex(afw_memory_t *memory, const afw_utf8_t *encoded, const afw_pool_t *p, afw_xctx_t *xctx)
Decode memory to a printable hex string.
#define afw_object_get_next_property(instance, iterator, property_name, xctx)
Call method get_next_property of interface afw_object.
#define afw_object_has_property(instance, property_name, xctx)
Call method has_property of interface afw_object.
afw_object_create_clone(const afw_object_t *object, const afw_pool_t *p, afw_xctx_t *xctx)
Clone an object to a specified pool.
const afw_object_t * afw_object_create_merged(const afw_object_t *primary, const afw_object_t *secondary, const afw_pool_t *p, afw_xctx_t *xctx)
Create a memory object with properties from two other objects.
afw_object_set_property(const afw_object_t *instance, const afw_utf8_t *property_name, const afw_value_t *value, afw_xctx_t *xctx)
Set the value of an object's property.
#define afw_pool_malloc(instance, size, xctx)
Call method malloc of interface afw_pool.
#define afw_pool_release(instance, xctx)
Call method release of interface afw_pool.
#define afw_pool_calloc_type(instance, type, xctx)
Macro to allocate cleared memory to hold type in pool.
const afw_pool_t * afw_pool_create(const afw_pool_t *parent, afw_xctx_t *xctx)
Create a new pool.
#define afw_pool_malloc_type(instance, type, xctx)
Macro to allocate uncleared memory to hold type in pool.
afw_value_clone(const afw_value_t *value, const afw_pool_t *p, afw_xctx_t *xctx)
Clone a value to specified pool.
Struct for memory pointer and size.
Return value from afw_memory_create_writer().
Interface afw_object public struct.
Interface afw_pool public struct.
NFC normalized UTF-8 string.
Interface afw_value public struct.
Interface afw_xctx public struct.