177# define _UNICOAP_OPTIONS_ALLOC(_buf, _name, capacity, _static) \
178 _static uint8_t _buf[capacity]; \
179 _static unicoap_options_t _name = { \
180 .entries = { { .data = _buf } }, \
181 .storage_capacity = capacity, \
197#define UNICOAP_OPTIONS_ALLOC(name, capacity) \
198 _UNICOAP_OPTIONS_ALLOC(_CONCAT3(name, _storage, __LINE__), name, capacity,)
212#define UNICOAP_OPTIONS_ALLOC_STATIC(name, capacity) \
213 _UNICOAP_OPTIONS_ALLOC(_CONCAT3(name, _storage, __LINE__), name, capacity, static)
226#define UNICOAP_OPTIONS_ALLOC_DEFAULT(name) \
227 UNICOAP_OPTIONS_ALLOC(name, CONFIG_UNICOAP_OPTIONS_BUFFER_DEFAULT_CAPACITY)
240#define UNICOAP_OPTIONS_ALLOC_STATIC_DEFAULT(name) \
241 UNICOAP_OPTIONS_ALLOC_STATIC(name, CONFIG_UNICOAP_OPTIONS_BUFFER_DEFAULT_CAPACITY)
261 return option_number & 1;
274 return (option_number & 2) == 0;
289 return ((option_number & 0x1e) == 0x1c);
304 return ((option_number & 0x1e) != 0x1c);
366#if !defined(EBADOPT) || defined(DOXYGEN)
371#if !defined(EPAYLD) || defined(DOXYGEN)
376#define UNICOAP_UINT24_MAX (0xffffff)
379#define UNICOAP_UINT24_SIZE (3)
387#define UNICOAP_UINT_MAX (14 + 255 + 0xffff)
420 const uint8_t* value,
size_t value_size);
443 const uint8_t* buffer,
size_t size, uint8_t separator);
466 size_t capacity, uint8_t separator);
504 const uint8_t** value);
521 uint8_t* dest,
size_t capacity);
536 const uint8_t* value,
size_t value_size);
671 const char* name,
size_t length,
750 ((count > 0) &&
string) ? count : strlen(
string));
776 ((count > 0) &&
string) ? count : strlen(
string));
827 return _unicoap_options_get_variable_uint(options, number, uint,
sizeof(uint32_t));
874 int res = _unicoap_options_get_variable_uint(options, number, &_uint,
sizeof(uint16_t));
875 *uint = (uint16_t)_uint;
POSIX.1-2008 compliant version of the assert macro.
#define assert(cond)
abort the program if assertion is false
Functions to work with different byte orders.
Constants used in CoAP such as option numbers and message codes.
#define CONFIG_UNICOAP_OPTIONS_MAX
Maximum number of options that can be present in a request or response.
void unicoap_options_print_uri_path(const unicoap_options_t *options)
Iterates over all Uri-Path options and prints the resulting path using printf.
static ssize_t unicoap_options_get_uint8(const unicoap_options_t *options, unicoap_option_number_t number, uint8_t *uint)
Retrieves an unsigned option value that takes up at most one bytes.
static ssize_t unicoap_options_get_uint16(const unicoap_options_t *options, unicoap_option_number_t number, uint16_t *uint)
Retrieves an unsigned option value that takes up at most 2 bytes.
ssize_t unicoap_options_copy_values_joined(const unicoap_options_t *options, unicoap_option_number_t number, uint8_t *buffer, size_t capacity, uint8_t separator)
Copies the values of all options with the given number joined by the given separator.
ssize_t unicoap_options_get(const unicoap_options_t *options, unicoap_option_number_t number, const uint8_t **value)
Retrieves the value of the option with given value, if present.
static ssize_t unicoap_options_get_next_query_by_name_string(unicoap_options_iterator_t *iterator, unicoap_option_number_t number, const char *name, const char **value)
Gets the next query option matching a given null-terminated name string, potentially skipping any opt...
void unicoap_options_dump_all(const unicoap_options_t *options)
Iterates and dumps all options using printf
int unicoap_options_remove_all(unicoap_options_t *options, unicoap_option_number_t number)
Removes all options with the given number, if any.
static void unicoap_options_iterator_init(unicoap_options_iterator_t *iterator, unicoap_options_t *options)
Initializes the given iterator structure.
static ssize_t unicoap_options_get_uint24(const unicoap_options_t *options, unicoap_option_number_t number, uint32_t *uint)
Retrieves an unsigned option value that takes up at most 3 bytes.
ssize_t unicoap_options_copy_value(const unicoap_options_t *options, unicoap_option_number_t number, uint8_t *dest, size_t capacity)
Copies the value of the option with given value, if present, into a buffer.
int unicoap_options_add(unicoap_options_t *options, unicoap_option_number_t number, const uint8_t *value, size_t value_size)
Adds a repeatable option with the given value.
ssize_t unicoap_options_get_next(unicoap_options_iterator_t *iterator, unicoap_option_number_t *number, const uint8_t **value)
Gets the next option provided by the given iterator.
int unicoap_options_set(unicoap_options_t *options, unicoap_option_number_t number, const uint8_t *value, size_t value_size)
Sets the option with the given number.
int unicoap_options_set_uint(unicoap_options_t *options, unicoap_option_number_t number, uint32_t value)
Sets the option with the given number to the unsigned integer value passed.
ssize_t unicoap_options_get_next_by_number(unicoap_options_iterator_t *iterator, unicoap_option_number_t number, const uint8_t **value)
Gets the next option with the given number, potentially skipping any options in between.
static int unicoap_options_remove(unicoap_options_t *options, unicoap_option_number_t number)
Removes option with the given number, if present.
static int unicoap_options_add_string(unicoap_options_t *options, unicoap_option_number_t number, const char *string, size_t count)
Adds a repeatable option with the given string value.
int unicoap_options_add_uint(unicoap_options_t *options, unicoap_option_number_t number, uint32_t value)
Adds a repeatable option with the given unsigned integer value.
static int unicoap_options_set_string(unicoap_options_t *options, unicoap_option_number_t number, const char *string, size_t count)
Sets a non-repeatable option to the given string value.
static ssize_t unicoap_options_get_uint32(const unicoap_options_t *options, unicoap_option_number_t number, uint32_t *uint)
Retrieves an unsigned option value that takes up at most 4 bytes.
int unicoap_options_add_values_joined(unicoap_options_t *options, unicoap_option_number_t number, const uint8_t *buffer, size_t size, uint8_t separator)
Splits the given value into separate values and adds them as option values.
ssize_t unicoap_options_get_next_query_by_name(unicoap_options_iterator_t *iterator, unicoap_option_number_t number, const char *name, size_t length, const char **value)
Gets the next query option matching the given name, potentially skipping any options in between.
unicoap_option_number_t
CoAP option number.
#define UNICOAP_UINT24_SIZE
Size in bytes of number representable with 24 bits (3 bytes)
static uint8_t * unicoap_options_data(const unicoap_options_t *options)
Retrieves storage buffer.
static void unicoap_options_clear(unicoap_options_t *options)
Removes all options.
static size_t unicoap_options_size(const unicoap_options_t *options)
Retrieves total size of options in buffer.
static bool unicoap_option_is_no_cache_key(unicoap_option_number_t option_number)
Determines whether the given option is not intended to be part of the cache key.
static bool unicoap_option_is_critical(unicoap_option_number_t option_number)
Determines whether the given option is considered critical.
static void unicoap_options_init(unicoap_options_t *options, uint8_t *storage, size_t capacity)
Initializes the given options structure.
ssize_t unicoap_options_swap_storage(unicoap_options_t *options, uint8_t *destination, size_t capacity)
Copies storage and adjusts options struct.
static bool unicoap_option_is_safe_to_forward(unicoap_option_number_t option_number)
Determines whether the given option is safe to forward.
bool unicoap_options_contains(const unicoap_options_t *options, unicoap_option_number_t number)
Determines whether the given options container has one or more options with the given number.
static bool unicoap_option_is_cache_key(unicoap_option_number_t option_number)
Determines whether the given option is intended to be part of the cache key.
const char * unicoap_string_from_option_number(unicoap_option_number_t number)
Returns label of option corresponding to the given number.
Helper struct for options parser.
uint16_t size
Number of bytes this option is comprised of.
uint8_t * data
Pointer into options storage where this option starts.
unicoap_option_number_t number
Option number.
The iterator you use to retrieve option values in-order.
size_t index
Current option's index.
unicoap_options_t * options
Options.
size_t storage_size
Current size of encoded options.
size_t option_count
Number of options present.
unicoap_option_entry_t entries[CONFIG_UNICOAP_OPTIONS_MAX]
Helper array used to encode and decode options into options storage.
size_t storage_capacity
Available capacity in options storage buffer.
Utility macros for unicoap