Apache Portable Runtime
|
Data Structures | |
struct | apr_buffer_t |
Macros | |
#define | APR_BUFFER_STRING (-1) |
#define | APR_BUFFER_PLAIN 0 |
#define | APR_BUFFER_BASE64 1 |
Typedefs | |
typedef void *(* | apr_buffer_alloc) (void *ctx, apr_size_t size) |
An APR buffer is a structure that can contain a zero terminated string, or a non zero terminated block of memory, and allow such structures to be passed around and handled in a memory efficient way.
We allow two buffers to be compared without duplicating strings. Memory buffers can be converted to string buffers safely. The contents of buffers can be copied into and out of other systems like caches using memory allocation callbacks.
#define APR_BUFFER_BASE64 1 |
Perform base64 encoding on memory buffers during apr_buffer_pstrcat().
#define APR_BUFFER_PLAIN 0 |
Perform no encoding on memory buffers during apr_buffer_pstrcat().
#define APR_BUFFER_STRING (-1) |
When passing a string to apr_buffer_str_create or apr_buffer_str_set, this value can be passed to indicate a string with unknown length, and have apr_buffer_str_create and apr_buffer_str_set compute the length automatically.
typedef void *(* apr_buffer_alloc) (void *ctx, apr_size_t size) |
Function called to allocate memory in the buffer functions.
This allows buffers to be copied into and out of shared memory, or memory from other systems.
apr_size_t apr_buffer_allocated | ( | const apr_buffer_t * | buf | ) |
Return the allocated length.
The size of the underlying buffer is returned, including the terminating zero if present.
Use this function when you need to know how much memory the buffer is taking up.
buf | The string/memory buffer. |
apr_status_t apr_buffer_arraydup | ( | apr_buffer_t ** | out, |
const apr_buffer_t * | in, | ||
apr_buffer_alloc | alloc, | ||
void * | ctx, | ||
int | nelts | ||
) |
Return a copy of an array of memory buffers.
This function allows you to make a copy of one or more buffers, controlling the memory allocation yourself.
Use this function to copy buffers, and the contents of the buffers, into and out of a cache.
out | The duplicated buffer array. If APR_ENOMEM is returned the array may be partially duplicated, it is up to the caller to free any memory allocated, and to pass zeroed buffers if needed. |
in | The string/memory buffer. |
alloc | The function callback to allocate memory for the buffer |
ctx | Context to pass to the callback function |
nelts | Number of buffers to duplicate |
int apr_buffer_cmp | ( | const apr_buffer_t * | dst, |
const apr_buffer_t * | src | ||
) |
Compare two possibly NULL buffers for equality.
Each buffer can be either a string or memory buffer, or NULL.
Two NULL buffers are considered equal.
A string buffer and a memory buffer are considered equal if the length excluding any trailing zero is equal, and the contents without the trailing zero are the same.
dst | The first buffer |
src | The second buffer |
apr_buffer_t * apr_buffer_cpy | ( | apr_buffer_t * | dst, |
const apr_buffer_t * | src, | ||
apr_buffer_alloc | alloc, | ||
void * | ctx | ||
) |
Copy the contents a buffer into another buffer.
This function allows you to make a copy of the contents of a buffer, into and out of a cache.
If the source buffer is NULL, the destination buffer will be assigned NULL as content.
If the memory allocator callback is NULL, the contents of the source buffer will be assigned to the destination buffer as is.
dst | The first buffer |
src | The second buffer |
alloc | The function callback to allocate memory for the buffer |
ctx | The context for the callback |
apr_status_t apr_buffer_dup | ( | apr_buffer_t ** | out, |
const apr_buffer_t * | in, | ||
apr_buffer_alloc | alloc, | ||
void * | ctx | ||
) |
Return a copy of a string/memory buffer.
This function allows you to make a copy of a buffer, controlling the memory allocation yourself.
Use this function to copy a buffer, and the content of the buffer, into and out of a cache.
out | The duplicated buffer. If APR_ENOMEM is returned the buffer may be partially duplicated, it is up to the caller to free any memory allocated, and to pass zeroed buffers if needed. |
in | The string/memory buffer. |
alloc | The function callback to allocate memory for the buffer |
ctx | Context to pass to the callback function |
int apr_buffer_is_null | ( | const apr_buffer_t * | buf | ) |
Does the buffer contain a NULL buffer.
If the internal buffer is NULL, 1 is returned, otherwise 0.
buf | The buffer. |
int apr_buffer_is_str | ( | const apr_buffer_t * | buf | ) |
Does the buffer contain a zero terminated string.
If the buffer is already zero terminated, 1 is returned, otherwise 0.
buf | The buffer. |
apr_size_t apr_buffer_len | ( | const apr_buffer_t * | buf | ) |
Return the buffer length.
The size of the underlying buffer is returned, excluding the terminating zero if present.
Use this function to know the length of the data in the buffer.
buf | The string/memory buffer. |
void * apr_buffer_mem | ( | const apr_buffer_t * | buf, |
apr_size_t * | size | ||
) |
Return the non zero terminated string/memory buffer.
If a size is provided, the size of the buffer without the terminating zero will be returned.
Use this function when you need to pass the content of the buffer to an API requiring an area of memory and a length.
buf | The string/memory buffer. |
size | Location to write the size to. |
apr_status_t apr_buffer_mem_create | ( | apr_buffer_t ** | mb, |
apr_pool_t * | pool, | ||
void * | mem, | ||
apr_size_t | len | ||
) |
Create a apr_buffer_t containing non zero terminated memory.
The buffer structure is allocated from the pool, while the contents are stored as is. It is the responsibility of the caller to ensure the contents have a lifetime as long as the pool.
mb | The memory buffer returned |
pool | The pool to allocate from |
mem | The memory to assign to the buffer |
len | The length of the memory |
apr_status_t apr_buffer_mem_set | ( | apr_buffer_t * | buf, |
void * | mem, | ||
apr_size_t | len | ||
) |
Set a apr_buffer_t with non zero terminated memory.
buf | The buffer to allocate to |
mem | The memory buffer to assign to the buffer |
len | The length of the memory buffer |
apr_status_t apr_buffer_null_create | ( | apr_buffer_t ** | nb, |
apr_pool_t * | pool | ||
) |
Create a apr_buffer_t containing a NULL payload.
The buffer structure is allocated from the pool.
nb | The null buffer returned |
pool | The pool to allocate from. |
void * apr_buffer_pmemdup | ( | apr_pool_t * | pool, |
const apr_buffer_t * | buf, | ||
apr_size_t * | size | ||
) |
Return a copy of the content of a buffer as non zero terminated memory allocated from a pool.
If a size is provided, the size of the buffer will be returned.
pool | The pool to allocate from. |
buf | The string/memory buffer. |
size | Location to write the size to. |
char * apr_buffer_pstrdup | ( | apr_pool_t * | pool, |
const apr_buffer_t * | buf | ||
) |
Return a copy of the buffer as a zero terminated string allocated from a pool.
The memory or string buffer will be copied, as appropriate.
Use this function when you need the buffer to become a string with the lifetime of the pool provided.
pool | The pool to allocate from. |
buf | The buffer. |
char * apr_buffer_pstrncat | ( | apr_pool_t * | p, |
const apr_buffer_t * | buf, | ||
int | nelts, | ||
const char * | sep, | ||
int | flags, | ||
apr_size_t * | nbytes | ||
) |
Concatenate multiple buffers and return a string.
If the buffer contains a string, it will be copied across as is, memory buffers will be transformed by the flags specified before concatenation.
This function can be used with an apr_array_header_t.
p | The pool from which to allocate |
buf | The buffers to concatenate |
nelts | The number of buffers to concatenate |
sep | The optional separator between strings |
flags | Allow memory buffers to be transformed before concatenation. APR_BUFFER_NONE copies memory buffer as is. APR_BUFFER_BASE64 applies base64 encoding to the memory buffer. |
nbytes | (output) strlen of new string (pass in NULL to omit) |
char * apr_buffer_str | ( | const apr_buffer_t * | buf | ) |
Return the zero terminated string from a buffer containing a string.
If the buffer contains a string, the original string is returned.
If the buffer contains non zero terminated memory, NULL will be returned.
Use this function when we want to be sure you're dealing with a string, and want to avoid duplication.
buf | The string/memory buffer. |
apr_status_t apr_buffer_str_create | ( | apr_buffer_t ** | sb, |
apr_pool_t * | pool, | ||
char * | str, | ||
apr_ssize_t | len | ||
) |
Create a apr_buffer_t containing a zero terminated string.
The buffer structure is allocated from the pool, while the contents are stored as is. It is the responsibility of the caller to ensure the contents have a lifetime as long as the pool.
sb | The string buffer returned |
pool | The pool to allocate from. |
str | The string to assign to the buffer. |
len | The length of the string, or APR_BUFFER_STRING to have the length calculated. |
apr_status_t apr_buffer_str_set | ( | apr_buffer_t * | buf, |
char * | str, | ||
apr_ssize_t | len | ||
) |
Set a apr_buffer_t with a zero terminated string.
buf | The buffer to assign the data to. |
str | The zero terminated string to assign to the buffer. |
len | The length of the string without terminating zero, or APR_BUFFER_STRING to have the length calculated. |