Add sorting of optlist

This commit is contained in:
Magdalena Szumny authored and Jon Shallow committed 2026-02-16 10:34:48 +00:00
1 parent d2b61c2e49
commit f79eaba9b9
6 files changed
+39 -2

No files matched your search

+10
View File
@@ -376,6 +376,16 @@ coap_optlist_t *coap_new_optlist(uint16_t number,
*/
int coap_add_optlist_pdu(coap_pdu_t *pdu, coap_optlist_t **optlist_chain);
/**
* @brief Sorts the optlist chain
*
* @param options The optlist chain to sort
*
* @return @c 1 if sorted successfully, @c 0 otherwise.
*/
int coap_sort_optlist(coap_optlist_t **options);
/**
* Adds @p optlist to the given @p optlist_chain. The optlist_chain variable
* be set to NULL before the initial call to coap_insert_optlist().
+1
View File
@@ -333,6 +333,7 @@ global:
coap_socket_get_flags;
coap_socket_set_flags;
coap_socket_strerror;
coap_sort_optlist;
coap_split_path;
coap_split_proxy_uri;
coap_split_query;
+1
View File
@@ -331,6 +331,7 @@ coap_socket_get_fd
coap_socket_get_flags
coap_socket_set_flags
coap_socket_strerror
coap_sort_optlist
coap_split_path
coap_split_proxy_uri
coap_split_query
+1
View File
@@ -192,6 +192,7 @@ install-man: install-man3 install-man5 install-man7
@echo ".so man3/coap_pdu_access.3" > coap_get_uri_path.3
@echo ".so man3/coap_pdu_setup.3" > coap_insert_optlist.3
@echo ".so man3/coap_pdu_setup.3" > coap_delete_optlist.3
@echo ".so man3/coap_pdu_setup.3" > coap_sort_optlist.3
@echo ".so man3/coap_pdu_setup.3" > coap_encode_var_safe.3
@echo ".so man3/coap_pdu_setup.3" > coap_encode_var_safe8.3
@echo ".so man3/coap_pdu_setup.3" > coap_add_optlist_pdu.3
+16 -2
View File
@@ -20,6 +20,7 @@ coap_add_token,
coap_new_optlist,
coap_insert_optlist,
coap_delete_optlist,
coap_sort_optlist,
coap_encode_var_safe,
coap_encode_var_safe8,
coap_add_optlist_pdu,
@@ -64,6 +65,8 @@ coap_optlist_t *_optlist_);*
*void coap_delete_optlist(coap_optlist_t *_optlist_chain_);*
*int coap_sort_optlist(coap_optlist_t **_options_);*
*unsigned int coap_encode_var_safe(uint8_t *_buffer_, size_t _size_,
unsigned int _value_);*
@@ -383,6 +386,17 @@ off all the _optlist_chain_ entries.
The *coap_delete_optlist*() function deletes and frees off all the optlist
entries in the _optlist_chain_.
*Function: coap_sort_optlist()*
The *coap_sort_optlist*() function sorts the optlist chain pointed to by
_options_ into ascending option number order (RFC 7252 ordering for delta
encoding). The chain is reordered in place. Use this when the list was
built with *coap_insert_optlist*() and you need it ordered before use (for
example, before adding options to a PDU manually or for inspection).
*coap_add_optlist_pdu*() sorts internally, so calling *coap_sort_optlist*()
is not required when using that function. Returns 1 if sorted successfully,
0 if _options_ is NULL or the chain is empty.
*Function: coap_add_optlist_pdu()*
The *coap_add_optlist_pdu*() function sorts all of the entries in
@@ -570,8 +584,8 @@ _PDU_ or NULL if there is a malloc or parameter failure.
*coap_new_optlist*() returns a newly created _optlist_ or NULL
if there is a malloc failure.
*coap_add_token*(), *coap_insert_optlist*(), *coap_add_optlist_pdu*()
and *coap_add_data*() return 0 on failure, 1 on success.
*coap_add_token*(), *coap_insert_optlist*(), *coap_sort_optlist*(),
*coap_add_optlist_pdu*() and *coap_add_data*() return 0 on failure, 1 on success.
*coap_encode_var_safe*() returns either the length of bytes
encoded (which can be 0 when encoding 0) or 0 on failure.
+10
View File
@@ -567,6 +567,16 @@ coap_add_optlist_pdu(coap_pdu_t *pdu, coap_optlist_t **options) {
return 1;
}
int
coap_sort_optlist(coap_optlist_t **options) {
if (options && *options) {
/* sort options for delta encoding */
LL_SORT((*options), order_opts);
return 1;
}
return 0;
}
int
coap_insert_optlist(coap_optlist_t **head, coap_optlist_t *node) {
if (!node) {