Skip to content

Commit

Permalink
fixup! gcoap: addressed comments
Browse files Browse the repository at this point in the history
- s/pkt/pdu/
- fixed doc for gcoap_add_qstring
- removed deprecated comment in _write_options
  • Loading branch information
haukepetersen committed Aug 7, 2017
1 parent 90c2d68 commit 60916a1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
11 changes: 7 additions & 4 deletions sys/include/net/gcoap.h
Original file line number Diff line number Diff line change
Expand Up @@ -635,18 +635,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
}
Expand Down
15 changes: 7 additions & 8 deletions sys/net/application_layer/gcoap/gcoap.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,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;
}

Expand Down Expand Up @@ -828,9 +827,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;

Expand All @@ -839,15 +838,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;
}
Expand Down

0 comments on commit 60916a1

Please sign in to comment.