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:
parent
a470c1cb44
commit
eb76b8ea62
@ -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
|
||||
*
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user