1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-24 14:03:55 +01:00

Merge pull request #13805 from benpicco/nanocoap_path

nanocoap: add convenience function for adding path elements
This commit is contained in:
Ken Bannister 2020-04-04 12:50:16 -04:00 committed by GitHub
commit 127f8ca407
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -1046,6 +1046,25 @@ ssize_t coap_opt_add_proxy_uri(coap_pkt_t *pkt, const char *uri);
*/
ssize_t coap_opt_add_string(coap_pkt_t *pkt, uint16_t optnum, const char *string, char separator);
/**
* @brief Adds one or multiple Uri-Path options in the form '/path' into pkt
*
* @note Use this only for null-terminated strings.
*
* @param[in,out] pkt Packet being built
* @param[in] path Resource (sub)path
*
* @pre ((pkt != NULL) && (path != NULL))
*
* @return number of bytes written to pkt buffer
* @return <0 on error
* @return -ENOSPC if no available options or pkt full
*/
static inline ssize_t coap_opt_add_uri_path(coap_pkt_t *pkt, const char *path)
{
return coap_opt_add_string(pkt, COAP_OPT_URI_PATH, path, '/');
}
/**
* @brief Finalizes options as required and prepares for payload
*

View File

@ -659,7 +659,7 @@ int gcoap_req_init(coap_pkt_t *pdu, uint8_t *buf, size_t len,
coap_pkt_init(pdu, buf, len - CONFIG_GCOAP_REQ_OPTIONS_BUF, res);
if (path != NULL) {
res = coap_opt_add_string(pdu, COAP_OPT_URI_PATH, path, '/');
res = coap_opt_add_uri_path(pdu, path);
}
return (res > 0) ? 0 : res;
}