Soletta™ Framework
|
Buffer is a dynamic array, that can be resized if needed. More...
Data Structures | |
struct | sol_buffer |
A sol_buffer is a dynamic array, that can be resized if needed. More... | |
Macros | |
#define | SOL_BUFFER_CAN_RESIZE(buf) (!(buf->flags & (SOL_BUFFER_FLAGS_FIXED_CAPACITY | SOL_BUFFER_FLAGS_MEMORY_NOT_OWNED))) |
Convenience flag to check if the buffer is resizable. More... | |
#define | SOL_BUFFER_DECLARE_STATIC(name_, size_) |
A helper macro to create a static allocated buffer with a fixed capacity. More... | |
#define | SOL_BUFFER_INIT_CONST(data_, size_) SOL_BUFFER_C_CAST { .data = data_, .capacity = size_, .used = size_, .flags = SOL_BUFFER_FLAGS_MEMORY_NOT_OWNED } |
Helper macro to initialize an buffer with const data. More... | |
#define | SOL_BUFFER_INIT_DATA(data_, size_) SOL_BUFFER_C_CAST { .data = data_, .capacity = size_, .used = size_, .flags = SOL_BUFFER_FLAGS_DEFAULT } |
Helper macro to initialize an buffer with the given data. More... | |
#define | SOL_BUFFER_INIT_EMPTY SOL_BUFFER_C_CAST { .data = NULL, .capacity = 0, .used = 0, .flags = SOL_BUFFER_FLAGS_DEFAULT } |
Helper macro to initialize an empty buffer. More... | |
#define | SOL_BUFFER_INIT_FLAGS(data_, size_, flags_) SOL_BUFFER_C_CAST { .data = data_, .capacity = size_, .used = 0, .flags = (enum sol_buffer_flags)(flags_) } |
Helper macro to initialize an buffer with the given data and flags. More... | |
#define | SOL_BUFFER_NEEDS_NUL_BYTE(buf) (!((buf)->flags & SOL_BUFFER_FLAGS_NO_NUL_BYTE)) |
Convenience flag to check for flags not containing SOL_BUFFER_FLAGS_NO_NUL_BYTE, that is, buffers that needs the trailing nul byte terminator. More... | |
Typedefs | |
typedef struct sol_buffer | sol_buffer |
A sol_buffer is a dynamic array, that can be resized if needed. More... | |
Enumerations | |
enum | sol_buffer_flags { SOL_BUFFER_FLAGS_DEFAULT = 0, SOL_BUFFER_FLAGS_FIXED_CAPACITY = (1 << 0), SOL_BUFFER_FLAGS_NO_FREE = (1 << 1), SOL_BUFFER_FLAGS_MEMORY_NOT_OWNED = (SOL_BUFFER_FLAGS_FIXED_CAPACITY | SOL_BUFFER_FLAGS_NO_FREE), SOL_BUFFER_FLAGS_NO_NUL_BYTE = (1 << 2), SOL_BUFFER_FLAGS_CLEAR_MEMORY = (1 << 3) } |
Flags used to set sol_buffer capabilities. More... | |
enum | sol_decode_case { SOL_DECODE_UPPERCASE, SOL_DECODE_LOWERCASE, SOL_DECODE_BOTH } |
Case of a string to be decoded. More... | |
Functions | |
int | sol_buffer_append_as_base16 (struct sol_buffer *buf, const struct sol_str_slice slice, bool uppercase) |
Append the 'slice' at the end of 'buf' encoded as base16 (hexadecimal). More... | |
int | sol_buffer_append_as_base64 (struct sol_buffer *buf, const struct sol_str_slice slice, const char base64_map[SOL_STATIC_ARRAY_SIZE(65)]) |
Append the 'slice' at the end of 'buf' encoded as base64 using the given map. More... | |
int | sol_buffer_append_buffer (struct sol_buffer *dst, const struct sol_buffer *src) |
Appends the contents of the buffer from in the end of buf , reallocating if necessary. More... | |
int | sol_buffer_append_bytes (struct sol_buffer *buf, const uint8_t *bytes, size_t size) |
Appends the bytes array to the end of buf , reallocating if necessary. More... | |
int | sol_buffer_append_char (struct sol_buffer *buf, const char c) |
Appends character c into the end of buf , reallocating if necessary. More... | |
int | sol_buffer_append_from_base16 (struct sol_buffer *buf, const struct sol_str_slice slice, enum sol_decode_case decode_case) |
Append the 'slice' at the end of 'buf' decoded from base16 (hexadecimal). More... | |
int | sol_buffer_append_from_base64 (struct sol_buffer *buf, const struct sol_str_slice slice, const char base64_map[SOL_STATIC_ARRAY_SIZE(65)]) |
Append the 'slice' at the end of 'buf' decoded from base64 using the given map. More... | |
int static int | sol_buffer_append_printf (struct sol_buffer *buf, const char *fmt,...) SOL_ATTR_PRINTF(2 |
Append the formatted string in the end of the buffer (including trailing '\0'). More... | |
int | sol_buffer_append_slice (struct sol_buffer *buf, const struct sol_str_slice slice) |
Appends slice into the end of buf , reallocating if necessary. More... | |
int | sol_buffer_append_vprintf (struct sol_buffer *buf, const char *fmt, va_list args) SOL_ATTR_PRINTF(2 |
Append the formatted string in the end of the buffer (including trailing '\0'). More... | |
static void * | sol_buffer_at (const struct sol_buffer *buf, size_t pos) |
Returns a pointer to the data at position pos in the buffer buf . More... | |
static void * | sol_buffer_at_end (const struct sol_buffer *buf) |
Returns a pointer to the end of the used portion of the buffer. More... | |
struct sol_buffer * | sol_buffer_copy (const struct sol_buffer *buf) |
Allocate a new sol_buffer and a new data block and copy the contents of the provided sol_buffer. More... | |
int | sol_buffer_ensure (struct sol_buffer *buf, size_t min_size) |
Ensures that buf has at least min_size . More... | |
int | sol_buffer_ensure_nul_byte (struct sol_buffer *buf) |
Ensures that buffer has a terminating NULL byte. More... | |
int | sol_buffer_expand (struct sol_buffer *buf, size_t bytes) |
Increment the buffer capacity to fit the bytes . More... | |
void | sol_buffer_fini (struct sol_buffer *buf) |
Finalizes the buffer. More... | |
static void | sol_buffer_free (struct sol_buffer *buf) |
Delete the buffer. More... | |
static struct sol_str_slice | sol_buffer_get_slice (const struct sol_buffer *buf) |
Creates a string slice from the buffer's valid data. More... | |
static struct sol_str_slice | sol_buffer_get_slice_at (const struct sol_buffer *buf, size_t pos) |
Creates a string slice from the buffer's data starting at position pos . More... | |
static void | sol_buffer_init (struct sol_buffer *buf) |
Initializes a sol_buffer structure. More... | |
static void | sol_buffer_init_flags (struct sol_buffer *buf, void *data, size_t data_size, enum sol_buffer_flags flags) |
Initializes a sol_buffer structure with the given data and flags. More... | |
int | sol_buffer_insert_as_base16 (struct sol_buffer *buf, size_t pos, const struct sol_str_slice slice, bool uppercase) |
Insert the 'slice' into 'buf' at position 'pos' encoded as base16 (hexadecimal). More... | |
int | sol_buffer_insert_as_base64 (struct sol_buffer *buf, size_t pos, const struct sol_str_slice slice, const char base64_map[SOL_STATIC_ARRAY_SIZE(65)]) |
Insert the 'slice' into 'buf' at position 'pos' encoded as base64 using the given map. More... | |
static int | sol_buffer_insert_buffer (struct sol_buffer *dst, size_t pos, const struct sol_buffer *src) |
Insert the dst into src at position pos , reallocating if necessary. More... | |
int | sol_buffer_insert_bytes (struct sol_buffer *buf, size_t pos, const uint8_t *bytes, size_t size) |
Insert the bytes array into buf at position pos , reallocating if necessary. More... | |
int | sol_buffer_insert_char (struct sol_buffer *buf, size_t pos, const char c) |
Insert character c into buf at position pos , reallocating if necessary. More... | |
int | sol_buffer_insert_from_base16 (struct sol_buffer *buf, size_t pos, const struct sol_str_slice slice, enum sol_decode_case decode_case) |
Insert the 'slice' into 'buf' at position 'pos' decoded from base16 (hexadecimal). More... | |
int | sol_buffer_insert_from_base64 (struct sol_buffer *buf, size_t pos, const struct sol_str_slice slice, const char base64_map[SOL_STATIC_ARRAY_SIZE(65)]) |
Insert the 'slice' into 'buf' at position 'pos' decoded from base64 using the given map. More... | |
int static int | sol_buffer_insert_printf (struct sol_buffer *buf, size_t pos, const char *fmt,...) SOL_ATTR_PRINTF(3 |
Insert the formatted string in the given position in the buffer. More... | |
int | sol_buffer_insert_slice (struct sol_buffer *buf, size_t pos, const struct sol_str_slice slice) |
Insert the slice into buf at position pos , reallocating if necessary. More... | |
int | sol_buffer_insert_vprintf (struct sol_buffer *buf, size_t pos, const char *fmt, va_list args) SOL_ATTR_PRINTF(3 |
Insert the formatted string in the given position in the buffer. More... | |
static struct sol_buffer * | sol_buffer_new (void) |
Creates a new buffer. More... | |
int | sol_buffer_remove_data (struct sol_buffer *buf, size_t offset, size_t size) |
Removes part of data inside the buffer rearranging the memory properly. More... | |
static void | sol_buffer_reset (struct sol_buffer *buf) |
Reset the buffer content. More... | |
int | sol_buffer_resize (struct sol_buffer *buf, size_t new_size) |
Resize the buffer to the given size. More... | |
static int | sol_buffer_set_buffer (struct sol_buffer *dst, const struct sol_buffer *src) |
Copy src into dst , ensuring that will fit. More... | |
static int | sol_buffer_set_buffer_at (struct sol_buffer *dst, size_t pos, const struct sol_buffer *src) |
Copy src into dst at position pos , ensuring that will fit. More... | |
int | sol_buffer_set_char_at (struct sol_buffer *buf, size_t pos, char c) |
Set character c into buf at position pos , reallocating if necessary. More... | |
int | sol_buffer_set_slice (struct sol_buffer *buf, const struct sol_str_slice slice) |
Copy slice into buf , ensuring that will fit. More... | |
int | sol_buffer_set_slice_at (struct sol_buffer *buf, size_t pos, const struct sol_str_slice slice) |
Set the string slice slice into buf at position pos , reallocating if necessary. More... | |
void * | sol_buffer_steal (struct sol_buffer *buf, size_t *size) |
'Steals' sol_buffer internal buffer and resets sol_buffer. More... | |
void * | sol_buffer_steal_or_copy (struct sol_buffer *buf, size_t *size) |
'Steals' buf internal buffer and resets it. More... | |
struct sol_blob * | sol_buffer_to_blob (struct sol_buffer *buf) |
Convert a buffer to a struct sol_blob. More... | |
static int | sol_buffer_trim (struct sol_buffer *buf) |
Frees memory that is not in being used by the buffer. More... | |
Variables | |
const char | SOL_BASE64_MAP [66] |
The default base 64 map to use. More... | |
Buffer is a dynamic array, that can be resized if needed.
See also Arena if you are allocating multiple pieces of data that will be deallocated twice.
#define SOL_BUFFER_CAN_RESIZE | ( | buf | ) | (!(buf->flags & (SOL_BUFFER_FLAGS_FIXED_CAPACITY | SOL_BUFFER_FLAGS_MEMORY_NOT_OWNED))) |
Convenience flag to check if the buffer is resizable.
#define SOL_BUFFER_DECLARE_STATIC | ( | name_, | |
size_ | |||
) |
A helper macro to create a static allocated buffer with a fixed capacity.
This macro will expand into the following code:
name_ | The name of the struct sol_buffer variable |
size_ | The capacity of the buffer |
Referenced by _on_network_event(), create_location_obj(), create_security_obj(), create_server_obj(), found_device(), found_resource(), found_resource_print(), got_get_response(), light_resource_to_rep(), location_changed_cb(), on_connect(), on_disconnect(), print_response(), reply_cb(), request_cb(), resource_notify(), write_security_tlv(), and write_server_tlv().
#define SOL_BUFFER_INIT_CONST | ( | data_, | |
size_ | |||
) | SOL_BUFFER_C_CAST { .data = data_, .capacity = size_, .used = size_, .flags = SOL_BUFFER_FLAGS_MEMORY_NOT_OWNED } |
Helper macro to initialize an buffer with const
data.
Also set the appropriated flag.
data_ | Buffer initial data |
size_ | Initial data size |
Referenced by iio_gyroscope_reader_cb(), main(), on_can_write(), and request_cb().
#define SOL_BUFFER_INIT_DATA | ( | data_, | |
size_ | |||
) | SOL_BUFFER_C_CAST { .data = data_, .capacity = size_, .used = size_, .flags = SOL_BUFFER_FLAGS_DEFAULT } |
Helper macro to initialize an buffer with the given data.
data_ | Buffer initial data |
size_ | Initial data size |
#define SOL_BUFFER_INIT_EMPTY SOL_BUFFER_C_CAST { .data = NULL, .capacity = 0, .used = 0, .flags = SOL_BUFFER_FLAGS_DEFAULT } |
Helper macro to initialize an empty buffer.
Referenced by on_can_read(), on_stdin(), print_attr(), print_response(), producer_make_data(), request_events_cb(), sol_efivars_read_string(), sol_fs_read_string(), and sol_memmap_read_string().
#define SOL_BUFFER_INIT_FLAGS | ( | data_, | |
size_, | |||
flags_ | |||
) | SOL_BUFFER_C_CAST { .data = data_, .capacity = size_, .used = 0, .flags = (enum sol_buffer_flags)(flags_) } |
Helper macro to initialize an buffer with the given data and flags.
data_ | Buffer initial data |
size_ | Initial data size |
flags_ | Buffer flags |
#define SOL_BUFFER_NEEDS_NUL_BYTE | ( | buf | ) | (!((buf)->flags & SOL_BUFFER_FLAGS_NO_NUL_BYTE)) |
Convenience flag to check for flags not containing SOL_BUFFER_FLAGS_NO_NUL_BYTE, that is, buffers that needs the trailing nul byte terminator.
typedef struct sol_buffer sol_buffer |
A sol_buffer is a dynamic array, that can be resized if needed.
It grows exponentially but also supports setting a specific size.
Useful to reduce the noise of handling realloc/size-variable manually.
See also sol_arena if you are allocating multiple pieces of data that will be deallocated twice.
enum sol_buffer_flags |
Flags used to set sol_buffer capabilities.
Enumerator | |
---|---|
SOL_BUFFER_FLAGS_DEFAULT |
Default flags: buffer may be resized and memory will be free'd at the end. |
SOL_BUFFER_FLAGS_FIXED_CAPACITY |
Fixed capacity buffers won't be resized, sol_buffer_resize() will fail with -EPERM. |
SOL_BUFFER_FLAGS_NO_FREE |
No free buffers won't call |
SOL_BUFFER_FLAGS_MEMORY_NOT_OWNED |
Buffers where the |
SOL_BUFFER_FLAGS_NO_NUL_BYTE |
Do not reserve space for the NUL byte. |
SOL_BUFFER_FLAGS_CLEAR_MEMORY |
Securely clear buffer data before finishing. Prefer using this flag combined with SOL_BUFFER_FLAGS_FIXED_CAPACITY, because of resizing overhead: every time buffer is resized, new memory is allocated, old memory is copied to new destination and old memory is cleared. |
enum sol_decode_case |
Case of a string to be decoded.
Used by functions sol_buffer_append_from_base16 or sol_buffer_insert_from_base16.
Enumerator | |
---|---|
SOL_DECODE_UPPERCASE | |
SOL_DECODE_LOWERCASE | |
SOL_DECODE_BOTH |
int sol_buffer_append_as_base16 | ( | struct sol_buffer * | buf, |
const struct sol_str_slice | slice, | ||
bool | uppercase | ||
) |
Append the 'slice' at the end of 'buf' encoded as base16 (hexadecimal).
See https://en.wikipedia.org/wiki/Base16
buf | the already-initialized buffer to append the encoded slice. |
slice | the byte string to encode, may contain null bytes (\0), it will be encoded up the slice.len . |
uppercase | if true, uppercase letters ABCDEF are used, otherwise lowercase abcdef are used instead. |
Referenced by on_digest_ready(), and store_digest().
int sol_buffer_append_as_base64 | ( | struct sol_buffer * | buf, |
const struct sol_str_slice | slice, | ||
const char | base64_map[SOL_STATIC_ARRAY_SIZE(65)] | ||
) |
Append the 'slice' at the end of 'buf' encoded as base64 using the given map.
See https://en.wikipedia.org/wiki/Base64
buf | the already-initialized buffer to append the encoded slice. |
slice | the byte string to encode, may contain null bytes (\0), it will be encoded up the slice.len . |
base64_map | the map to use, the default is available as SOL_BASE64_MAP. Note that the last char in the map (position 64) is used as the padding char. |
int sol_buffer_append_buffer | ( | struct sol_buffer * | dst, |
const struct sol_buffer * | src | ||
) |
Appends the contents of the buffer from
in the end of buf
, reallocating if
necessary.
dst | Destination buffer |
src | The buffer from where the data will be copied |
0
on success, error code (always negative) otherwise int sol_buffer_append_bytes | ( | struct sol_buffer * | buf, |
const uint8_t * | bytes, | ||
size_t | size | ||
) |
Appends the bytes
array to the end of buf
, reallocating if necessary.
buf | Destination buffer |
bytes | Bytes to be inserted |
size | Number of bytes to insert |
0
on success, error code (always negative) otherwise int sol_buffer_append_char | ( | struct sol_buffer * | buf, |
const char | c | ||
) |
Appends character c
into the end of buf
, reallocating if necessary.
buf | Destination buffer |
c | Character to be appended |
0
on success, error code (always negative) otherwise int sol_buffer_append_from_base16 | ( | struct sol_buffer * | buf, |
const struct sol_str_slice | slice, | ||
enum sol_decode_case | decode_case | ||
) |
Append the 'slice' at the end of 'buf' decoded from base16 (hexadecimal).
See https://en.wikipedia.org/wiki/Base16
buf | the already-initialized buffer to append the decoded slice. |
slice | the slice to decode, it must be a set of 0-9 or letters A-F (if uppercase) or a-f, otherwise decode fails. |
decode_case | if SOL_DECODE_UPPERCASE, uppercase letters ABCDEF are used, if SOL_DECODE_LOWERCASE, lowercase abcdef are used instead. If SOL_DECODE_BOTH both, lowercase and uppercase, letters can be used. |
int sol_buffer_append_from_base64 | ( | struct sol_buffer * | buf, |
const struct sol_str_slice | slice, | ||
const char | base64_map[SOL_STATIC_ARRAY_SIZE(65)] | ||
) |
Append the 'slice' at the end of 'buf' decoded from base64 using the given map.
See https://en.wikipedia.org/wiki/Base64
buf | the already-initialized buffer to append the decoded slice. |
slice | the slice to decode, it must be composed solely of the base64_map characters or it will fail. |
base64_map | the map to use, the default is available as SOL_BASE64_MAP. Note that the last char in the map (position 64) is used as the padding char. |
|
inlinestatic |
Append the formatted string in the end of the buffer (including trailing '\0').
buf | The buffer |
fmt | A standard 'printf()' format string |
... | The arguments to 'printf()' |
0
on success, error code (always negative) otherwise References sol_buffer_append_vprintf().
Referenced by dump_byte_string(), light_resource_to_rep(), and request_cb().
int sol_buffer_append_slice | ( | struct sol_buffer * | buf, |
const struct sol_str_slice | slice | ||
) |
Appends slice
into the end of buf
, reallocating if necessary.
buf | Destination buffer |
slice | String slice to be appended |
0
on success, error code (always negative) otherwise Referenced by producer_make_data(), and sol_json_serialize_null().
int sol_buffer_append_vprintf | ( | struct sol_buffer * | buf, |
const char * | fmt, | ||
va_list | args | ||
) |
Append the formatted string in the end of the buffer (including trailing '\0').
Similar to sol_buffer_insert_printf, but receives va_list
instead.
buf | The buffer |
fmt | A standard 'printf()' format string |
args | va_list to 'vprintf()' |
0
on success, error code (always negative) otherwise Referenced by sol_buffer_append_printf().
|
inlinestatic |
Returns a pointer to the data at position pos
in the buffer buf
.
buf | The buffer |
pos | Position of the data |
References sol_buffer::data, and sol_buffer::used.
Referenced by light_method_put(), reply_cb(), and sol_buffer_get_slice_at().
|
inlinestatic |
Returns a pointer to the end of the used portion of the buffer.
buf | The buffer |
References sol_buffer::data, and sol_buffer::used.
Referenced by _can_read().
struct sol_buffer* sol_buffer_copy | ( | const struct sol_buffer * | buf | ) |
Allocate a new sol_buffer and a new data block and copy the contents of the provided sol_buffer.
After this call, user is responsible for calling fini on the buffer and freeing it afterwards. For it's memory to be freed properly, the flag SOL_BUFFER_FLAGS_NO_FREE will always be unset, despite the original buffer.
buf | Buffer to be copied |
buf
, NULL
on error. int sol_buffer_ensure | ( | struct sol_buffer * | buf, |
size_t | min_size | ||
) |
Ensures that buf
has at least min_size
.
If buffer has null-bytes (ie: null terminated strings), then the resized amount will include that null byte automatically. See SOL_BUFFER_FLAGS_NO_NUL_BYTE.
It may allocate more than requested to avoid subsequent reallocs, the internal heuristic rounds up to next power-of-2.
buf | The buffer |
min_size | Minimum size |
0
on success, error code (always negative) otherwise int sol_buffer_ensure_nul_byte | ( | struct sol_buffer * | buf | ) |
Ensures that buffer has a terminating NULL byte.
If flag SOL_BUFFER_FLAGS_NO_NUL_BYTE is not set.
int sol_buffer_expand | ( | struct sol_buffer * | buf, |
size_t | bytes | ||
) |
Increment the buffer capacity to fit the bytes
.
This function will increase the buffer capacity in order to be able to fit bytes
.
If buffer has null-bytes (ie: null terminated strings), then the resized amount will include that null byte automatically. See SOL_BUFFER_FLAGS_NO_NUL_BYTE.
buf | The buffer |
bytes | The number of bytes that the buffer must fit. |
0
on success, error code (always negative) otherwiseReferenced by _can_read().
void sol_buffer_fini | ( | struct sol_buffer * | buf | ) |
Finalizes the buffer.
Frees the data managed by the buffer but keeps the buffer handler intact for reuse.
buf | The buffer |
Referenced by api_close(), create_location_obj(), entry_del(), location_changed_cb(), on_can_read(), on_can_write(), on_digest_ready(), on_stdin(), print_attr(), print_response(), request_cb(), shutdown_server(), sol_buffer_free(), sol_efivars_read_string(), sol_fs_read_string(), sol_memmap_read_string(), and startup_server().
|
inlinestatic |
Delete the buffer.
Buffer is finalized and all memory is freed.
buf | Buffer to be deleted |
References sol_buffer_fini().
|
static |
Creates a string slice from the buffer's valid data.
buf | The buffer |
References SOL_STR_SLICE_STR.
Referenced by _on_network_event(), consumer_read_available(), found_resource(), found_resource_print(), got_get_response(), on_can_read(), on_data(), on_stdin(), print_response(), reply_cb(), request_cb(), resource_notify(), sol_buffer_insert_buffer(), sol_buffer_set_buffer(), sol_buffer_set_buffer_at(), startup_server(), write_access_control_tlv(), write_security_tlv(), and write_server_tlv().
|
static |
Creates a string slice from the buffer's data starting at position pos
.
buf | The buffer |
pos | Start position |
References sol_buffer_at(), and SOL_STR_SLICE_STR.
|
inlinestatic |
Initializes a sol_buffer
structure.
flags are set to SOL_BUFFER_FLAGS_DEFAULT
.
buf | Pointer to buffer |
References sol_buffer::capacity, sol_buffer::data, sol_buffer::flags, SOL_BUFFER_FLAGS_DEFAULT, and sol_buffer::used.
Referenced by entry_new(), on_can_read(), on_digest_ready(), request_cb(), sol_buffer_new(), and startup_server().
|
inlinestatic |
Initializes a sol_buffer
structure with the given data and flags.
buf | Pointer to buffer |
data | Pointer to buffer initial data |
data_size | Size of the initial data |
flags | Buffer flags |
References sol_buffer::capacity, sol_buffer::data, sol_buffer::flags, SOL_BUFFER_FLAGS_MEMORY_NOT_OWNED, and sol_buffer::used.
Referenced by hrs_measurement_read(), and my_stream_api_new().
int sol_buffer_insert_as_base16 | ( | struct sol_buffer * | buf, |
size_t | pos, | ||
const struct sol_str_slice | slice, | ||
bool | uppercase | ||
) |
Insert the 'slice' into 'buf' at position 'pos' encoded as base16 (hexadecimal).
buf | the already-initialized buffer to append the encoded slice. |
pos | the position in bytes from 0 up to buf->used . If pos == buf->end, then the behavior is the same as sol_buffer_append_as_base16(). |
slice | the byte string to encode, may contain null bytes (\0), it will be encoded up the slice.len . |
uppercase | if true, uppercase letters ABCDEF are used, otherwise lowercase abcdef are used instead. |
int sol_buffer_insert_as_base64 | ( | struct sol_buffer * | buf, |
size_t | pos, | ||
const struct sol_str_slice | slice, | ||
const char | base64_map[SOL_STATIC_ARRAY_SIZE(65)] | ||
) |
Insert the 'slice' into 'buf' at position 'pos' encoded as base64 using the given map.
buf | the already-initialized buffer to append the encoded slice. |
pos | the position in bytes from 0 up to buf->used . If pos == buf->end, then the behavior is the same as sol_buffer_append_as_base64(). |
slice | the byte string to encode, may contain null bytes (\0), it will be encoded up the slice.len . |
base64_map | the map to use, the default is available as SOL_BASE64_MAP. Note that the last char in the map (position 64) is used as the padding char. |
|
inlinestatic |
Insert the dst
into src
at position pos
, reallocating if necessary.
If pos == src->end, then the behavior is the same as sol_buffer_append_buffer
dst | Destination buffer |
pos | Start position |
src | Source buffer |
0
on success, error code (always negative) otherwise References sol_buffer_get_slice(), and sol_buffer_insert_slice().
int sol_buffer_insert_bytes | ( | struct sol_buffer * | buf, |
size_t | pos, | ||
const uint8_t * | bytes, | ||
size_t | size | ||
) |
Insert the bytes
array into buf
at position pos
, reallocating if necessary.
If pos == buf->end, then the behavior is the same as sol_buffer_append_bytes.
buf | Destination buffer |
pos | Start position |
bytes | Bytes to be inserted |
size | Number of bytes to insert |
0
on success, error code (always negative) otherwise int sol_buffer_insert_char | ( | struct sol_buffer * | buf, |
size_t | pos, | ||
const char | c | ||
) |
Insert character c
into buf
at position pos
, reallocating if necessary.
If pos == buf->end, then the behavior is the same as sol_buffer_append_char and a trailing '\0' is guaranteed.
buf | Destination buffer |
pos | Start position |
c | Character to be inserted |
0
on success, error code (always negative) otherwise int sol_buffer_insert_from_base16 | ( | struct sol_buffer * | buf, |
size_t | pos, | ||
const struct sol_str_slice | slice, | ||
enum sol_decode_case | decode_case | ||
) |
Insert the 'slice' into 'buf' at position 'pos' decoded from base16 (hexadecimal).
buf | the already-initialized buffer to append the decoded slice. |
pos | the position in bytes from 0 up to buf->used . If pos == buf->end, then the behavior is the same as sol_buffer_append_from_base16(). |
slice | the slice to decode, it must be a set of 0-9 or letters A-F (if uppercase) or a-f, otherwise decode fails. |
decode_case | if SOL_DECODE_UPPERCASE, uppercase letters ABCDEF are used, if SOL_DECODE_LOWERCASE, lowercase abcdef are used instead. If SOL_DECODE_BOTH both, lowercase and uppercase, letters can be used. |
int sol_buffer_insert_from_base64 | ( | struct sol_buffer * | buf, |
size_t | pos, | ||
const struct sol_str_slice | slice, | ||
const char | base64_map[SOL_STATIC_ARRAY_SIZE(65)] | ||
) |
Insert the 'slice' into 'buf' at position 'pos' decoded from base64 using the given map.
buf | the already-initialized buffer to append the decoded slice. |
pos | the position in bytes from 0 up to buf->used . If pos == buf->end, then the behavior is the same as sol_buffer_append_from_base64(). |
slice | the slice to decode, it must be composed solely of the base64_map characters or it will fail. |
base64_map | the map to use, the default is available as SOL_BASE64_MAP. Note that the last char in the map (position 64) is used as the padding char. |
|
inlinestatic |
Insert the formatted string in the given position in the buffer.
buf | The buffer |
pos | Position to start write the string |
fmt | A standard 'printf()' format string |
... | The arguments to 'printf()' |
0
on success, error code (always negative) otherwise References sol_buffer_insert_vprintf().
int sol_buffer_insert_slice | ( | struct sol_buffer * | buf, |
size_t | pos, | ||
const struct sol_str_slice | slice | ||
) |
Insert the slice
into buf
at position pos
, reallocating if necessary.
If pos == buf->end, then the behavior is the same as sol_buffer_append_slice
buf | Destination buffer |
pos | Start position |
slice | Source slice |
0
on success, error code (always negative) otherwise Referenced by sol_buffer_insert_buffer().
int sol_buffer_insert_vprintf | ( | struct sol_buffer * | buf, |
size_t | pos, | ||
const char * | fmt, | ||
va_list | args | ||
) |
Insert the formatted string in the given position in the buffer.
Similar to sol_buffer_insert_printf, but receives va_list
instead.
If position == buf->pos, then the behavior is the same as sol_buffer_append_vprintf.
buf | The buffer |
pos | Position to start write the string |
fmt | A standard 'printf()' format string |
args | va_list to 'vprintf()' |
0
on success, error code (always negative) otherwise Referenced by sol_buffer_insert_printf().
|
static |
int sol_buffer_remove_data | ( | struct sol_buffer * | buf, |
size_t | offset, | ||
size_t | size | ||
) |
Removes part of data inside the buffer rearranging the memory properly.
It's removed up to the buffer's size in case of size
greater than used data.
buf | The buffer (already-initialized) |
offset | Position (from begin of the buffer) where |
size | Amount of data (in bytes) that should be removed size bytes will be removed |
0
on success, error code (always negative) otherwiseReferenced by _inform_user().
|
inlinestatic |
Reset the buffer content.
All allocated memory is kept.
buf | The buffer |
References sol_buffer::used.
int sol_buffer_resize | ( | struct sol_buffer * | buf, |
size_t | new_size | ||
) |
Resize the buffer to the given size.
The new size will be exactly of the given new_size, no null-byte is automatically handled and if used
member is larger than the new size, then it's limited to that amount (clamp).
buf | The buffer |
new_size | New size |
0
on success, error code (always negative) otherwise Referenced by sol_buffer_trim().
|
inlinestatic |
Copy src
into dst
, ensuring that will fit.
If data exists, then it won't be moved/shiffted, instead it will be overriden.
dst | The buffer's destiny |
src | The source data |
0
on success, error code (always negative) otherwise References sol_buffer_get_slice(), and sol_buffer_set_slice().
|
inlinestatic |
Copy src
into dst
at position pos
, ensuring that will fit.
The memory regions of src and dst may overlap.
dst | The buffer's destiny |
pos | Start position |
src | The source data |
0
on success, error code (always negative) otherwise References sol_buffer_get_slice(), and sol_buffer_set_slice_at().
int sol_buffer_set_char_at | ( | struct sol_buffer * | buf, |
size_t | pos, | ||
char | c | ||
) |
Set character c
into buf
at position pos
, reallocating if necessary.
If pos == buf->end, then the behavior is the same as sol_buffer_insert_char
buf | Destination buffer |
pos | Start position |
c | Character to be set |
0
on success, error code (always negative) otherwise int sol_buffer_set_slice | ( | struct sol_buffer * | buf, |
const struct sol_str_slice | slice | ||
) |
Copy slice
into buf
, ensuring that will fit.
Also includes an extra NULL byte so the buffer data can be used as a C string.
If data exists, then it won't be moved/shiffted, instead it will be overriden. Example:
buf | The buffer |
slice | String slice |
0
on success, error code (always negative) otherwise Referenced by sol_buffer_set_buffer(), and startup_server().
int sol_buffer_set_slice_at | ( | struct sol_buffer * | buf, |
size_t | pos, | ||
const struct sol_str_slice | slice | ||
) |
Set the string slice slice
into buf
at position pos
, reallocating if necessary.
The memory regions of slice and buf may overlap.
If pos == buf->end, then the behavior is the same as sol_buffer_append_slice.
If data exists after pos, then it won't be moved/shiffted, instead it will be overriden. Example:
buf | Destination buffer |
pos | Start position |
slice | String slice to be set |
0
on success, error code (always negative) otherwise Referenced by sol_buffer_set_buffer_at().
void* sol_buffer_steal | ( | struct sol_buffer * | buf, |
size_t * | size | ||
) |
'Steals' sol_buffer internal buffer and resets sol_buffer.
After this call, user is responsible for the memory returned.
buf | buffer to have it's internal buffer stolen |
size | if not NULL, will store memory returned size |
sol_buffer_new()
, it still needs to be freed by calling sol_buffer_free()
;SOL_BUFFER_FLAGS_NO_FREE
, this function will return NULL. Referenced by light_resource_to_rep(), producer_make_data(), sol_efivars_read_string(), sol_fs_read_string(), and sol_memmap_read_string().
void* sol_buffer_steal_or_copy | ( | struct sol_buffer * | buf, |
size_t * | size | ||
) |
'Steals' buf
internal buffer and resets it.
If the SOL_BUFFER_FLAGS_NO_FREE
was set, it will return a copy of the buffer's data.
After this call, user is responsible for the memory returned.
buf | buffer to have it's internal buffer stolen or copied |
size | if not NULL, will store memory returned size |
sol_buffer_new()
, it still needs to be freed by calling sol_buffer_free()
; struct sol_blob* sol_buffer_to_blob | ( | struct sol_buffer * | buf | ) |
Convert a buffer to a struct sol_blob.
The buffer will be stolen by the created blob.
buf | The buf to be transformed in a blob |
Referenced by create_security_obj(), create_server_obj(), on_stdin(), write_security_tlv(), and write_server_tlv().
|
inlinestatic |
Frees memory that is not in being used by the buffer.
If buffer has null-bytes (ie: null terminated strings), then the resized amount will include that null byte automatically. See SOL_BUFFER_FLAGS_NO_NUL_BYTE.
buf | The buffer |
0
on success, error code (always negative) otherwise References sol_buffer::capacity, sol_buffer::flags, SOL_BUFFER_FLAGS_NO_NUL_BYTE, sol_buffer_resize(), and sol_buffer::used.
const char SOL_BASE64_MAP[66] |
The default base 64 map to use.
The last byte (position 64) is the padding character. This is a NUL terminated string.