1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-23 21:43:51 +01:00

nanocoap: allow lastonum=NULL in coap_opt_put_uri_pathquery()

This commit is contained in:
Benjamin Valentin 2024-01-11 16:25:37 +01:00
parent a470c1cb44
commit eb76b8ea62
2 changed files with 9 additions and 3 deletions

View File

@ -1763,6 +1763,7 @@ static inline size_t coap_opt_put_uri_query(uint8_t *buf, uint16_t lastonum,
* @param[out] buf buffer to write to
* @param[in,out] lastonum number of previous option (for delta calculation),
* or 0 if first option
* May be NULL, then previous option is assumed to be 0.
* @param[in] uri ptr into a source URI, to the first character after
* the authority component
*

View File

@ -904,6 +904,7 @@ size_t coap_opt_put_uri_pathquery(uint8_t *buf, uint16_t *lastonum, const char *
{
size_t len;
const char *query = strchr(uri, '?');
uint16_t _lastonum = lastonum ? *lastonum : 0;
if (query) {
len = (query == uri) ? 0 : (query - uri - 1);
@ -911,16 +912,20 @@ size_t coap_opt_put_uri_pathquery(uint8_t *buf, uint16_t *lastonum, const char *
len = strlen(uri);
}
size_t bytes_out = coap_opt_put_string_with_len(buf, *lastonum,
size_t bytes_out = coap_opt_put_string_with_len(buf, _lastonum,
COAP_OPT_URI_PATH,
uri, len, '/');
if (query) {
buf += bytes_out;
bytes_out += coap_opt_put_uri_query(buf, COAP_OPT_URI_PATH, query + 1);
*lastonum = COAP_OPT_URI_QUERY;
_lastonum = COAP_OPT_URI_QUERY;
}
else if (bytes_out) {
*lastonum = COAP_OPT_URI_PATH;
_lastonum = COAP_OPT_URI_PATH;
}
if (lastonum) {
*lastonum = _lastonum;
}
return bytes_out;