1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2026-01-01 01:41:18 +01:00

net/gcoap: allow NULL path in gcoap_req_init()

This commit is contained in:
Ken Bannister 2018-11-28 13:20:22 -05:00
parent ad5d4ffc63
commit bec94b0b7a
2 changed files with 7 additions and 11 deletions

View File

@ -484,20 +484,14 @@ void gcoap_register_listener(gcoap_listener_t *listener);
/**
* @brief Initializes a CoAP request PDU on a buffer.
* @warning After you use this function, you may not add Options with option
* number less than COAP_OPT_URI_PATH. Otherwise, use the struct-based API
* described with @link net_nanocoap nanocoap @endlink to initialize the
* message. See the implementation of gcoap_req_init() itself as an example.
*
* @param[out] pdu Request metadata
* @param[out] buf Buffer containing the PDU
* @param[in] len Length of the buffer
* @param[in] code Request code: GCOAP_[GET|POST|PUT|DELETE]
* @param[in] path Resource path, *must* start with '/'
* @param[in] code Request code, one of COAP_METHOD_XXX
* @param[in] path Resource path, may be NULL
*
* @pre @p path not `NULL`
* @pre @p path must start with `/`
* @pre @p path must start with `/` if not NULL
*
* @return 0 on success
* @return < 0 on error

View File

@ -645,7 +645,7 @@ void gcoap_register_listener(gcoap_listener_t *listener)
int gcoap_req_init(coap_pkt_t *pdu, uint8_t *buf, size_t len,
unsigned code, const char *path)
{
assert((path != NULL) && (path[0] == '/'));
assert((path == NULL) || (path[0] == '/'));
pdu->hdr = (coap_hdr_t *)buf;
@ -669,7 +669,9 @@ int gcoap_req_init(coap_pkt_t *pdu, uint8_t *buf, size_t len,
if (hdrlen > 0) {
coap_pkt_init(pdu, buf, len - GCOAP_REQ_OPTIONS_BUF, hdrlen);
coap_opt_add_string(pdu, COAP_OPT_URI_PATH, path, '/');
if (path != NULL) {
coap_opt_add_string(pdu, COAP_OPT_URI_PATH, path, '/');
}
return 0;
}
else {