diff --git a/sys/include/net/gcoap.h b/sys/include/net/gcoap.h index 9fc90f0f93a0..98e8289a9674 100644 --- a/sys/include/net/gcoap.h +++ b/sys/include/net/gcoap.h @@ -634,18 +634,21 @@ size_t gcoap_obs_send(const uint8_t *buf, size_t len, uint8_t gcoap_op_state(void); /** - * @brief Add Uri-Query options to a CoAP request + * @brief Adds a single Uri-Query option to a CoAP request * - * @param[out] pkt The package that is being build + * To add multiple Uri-Query options, simply call this function multiple times. + * The Uri-Query options will be added in the order those calls. + * + * @param[out] pdu The package that is being build * @param[in] key Key to add to the query string * @param[in] val Value to assign to @p key (may be NULL) * - * @pre ((pkt != NULL) && (key != NULL)) + * @pre ((pdu != NULL) && (key != NULL)) * * @return overall length of new query string * @return -1 on error */ -int gcoap_add_qstring(coap_pkt_t *pkt, const char *key, const char *val); +int gcoap_add_qstring(coap_pkt_t *pdu, const char *key, const char *val); #ifdef __cplusplus } diff --git a/sys/net/application_layer/coap/gcoap.c b/sys/net/application_layer/coap/gcoap.c index be21c160a648..150da94aa8ef 100644 --- a/sys/net/application_layer/coap/gcoap.c +++ b/sys/net/application_layer/coap/gcoap.c @@ -473,7 +473,6 @@ static ssize_t _write_options(coap_pkt_t *pdu, uint8_t *buf, size_t len) /* Content-Format */ if (pdu->content_type != COAP_FORMAT_NONE) { bufpos += coap_put_option_ct(bufpos, last_optnum, pdu->content_type); - /* uncomment when add an option after Content-Format */ last_optnum = COAP_OPT_CONTENT_FORMAT; } @@ -827,9 +826,9 @@ uint8_t gcoap_op_state(void) return count; } -int gcoap_add_qstring(coap_pkt_t *pkt, const char *key, const char *val) +int gcoap_add_qstring(coap_pkt_t *pdu, const char *key, const char *val) { - size_t qs_len = strlen((char *)pkt->qs); + size_t qs_len = strlen((char *)pdu->qs); size_t key_len = strlen(key); size_t val_len = (val) ? (strlen(val) + 1) : 0; @@ -838,15 +837,15 @@ int gcoap_add_qstring(coap_pkt_t *pkt, const char *key, const char *val) return -1; } - pkt->qs[qs_len++] = '&'; - memcpy(&pkt->qs[qs_len], key, key_len); + pdu->qs[qs_len++] = '&'; + memcpy(&pdu->qs[qs_len], key, key_len); qs_len += key_len; if (val) { - pkt->qs[qs_len++] = '='; - memcpy(&pkt->qs[qs_len], val, val_len); + pdu->qs[qs_len++] = '='; + memcpy(&pdu->qs[qs_len], val, val_len); qs_len += val_len; } - pkt->qs[qs_len] = '\0'; + pdu->qs[qs_len] = '\0'; return (int)qs_len; }