Skip to content

Commit

Permalink
sys/net/CoRD: update use of deprecated nanocoap APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
maribu committed Nov 5, 2024
1 parent 925870b commit f31e223
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
15 changes: 6 additions & 9 deletions sys/net/application_layer/cord/ep/cord_ep.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @}
*/

#include <stdio.h>
#include <string.h>

#include "mutex.h"
Expand All @@ -28,15 +29,11 @@
#include "net/ipv6/addr.h"
#include "net/cord/ep.h"
#include "net/cord/common.h"
#include "net/cord/config.h"

#ifdef MODULE_CORD_EP_STANDALONE
#include "net/cord/ep_standalone.h"
#endif

#define ENABLE_DEBUG 0
#include "debug.h"

#define FLAG_SUCCESS (0x0001)
#define FLAG_TIMEOUT (0x0002)
#define FLAG_ERR (0x0004)
Expand Down Expand Up @@ -87,7 +84,7 @@ static void _on_register(const gcoap_request_memo_t *memo, coap_pkt_t* pdu,
thread_flags_t flag = FLAG_ERR;

if ((memo->state == GCOAP_MEMO_RESP) &&
(pdu->hdr->code == COAP_CODE_CREATED)) {
(coap_get_code_raw(pdu) == COAP_CODE_CREATED)) {
/* read the location header and save the RD details on success */
if (coap_get_location_path(pdu, (uint8_t *)_rd_loc,
sizeof(_rd_loc)) > 0) {
Expand All @@ -110,7 +107,7 @@ static void _on_update_remove(unsigned req_state, coap_pkt_t *pdu, uint8_t code)
{
thread_flags_t flag = FLAG_ERR;

if ((req_state == GCOAP_MEMO_RESP) && (pdu->hdr->code == code)) {
if ((req_state == GCOAP_MEMO_RESP) && (coap_get_code_raw(pdu) == code)) {
flag = FLAG_SUCCESS;
}
else if (req_state == GCOAP_MEMO_TIMEOUT) {
Expand Down Expand Up @@ -147,7 +144,7 @@ static int _update_remove(unsigned code, gcoap_resp_handler_t handle)
if (res < 0) {
return CORD_EP_ERR;
}
coap_hdr_set_type(pkt.hdr, COAP_TYPE_CON);
coap_pkt_set_type(&pkt, COAP_TYPE_CON);
ssize_t pkt_len = coap_opt_finish(&pkt, COAP_OPT_FINISH_NONE);

/* send request */
Expand Down Expand Up @@ -223,7 +220,7 @@ static int _discover_internal(const sock_udp_ep_t *remote,
if (res < 0) {
return CORD_EP_ERR;
}
coap_hdr_set_type(pkt.hdr, COAP_TYPE_CON);
coap_pkt_set_type(&pkt, COAP_TYPE_CON);
coap_opt_add_uri_query(&pkt, "rt", "core.rd");
size_t pkt_len = coap_opt_finish(&pkt, COAP_OPT_FINISH_NONE);
res = gcoap_req_send(buf, pkt_len, remote, NULL, _on_discover, NULL, GCOAP_SOCKET_TYPE_UNDEF);
Expand Down Expand Up @@ -277,7 +274,7 @@ int cord_ep_register(const sock_udp_ep_t *remote, const char *regif)
goto end;
}
/* set some packet options and write query string */
coap_hdr_set_type(pkt.hdr, COAP_TYPE_CON);
coap_pkt_set_type(&pkt, COAP_TYPE_CON);
coap_opt_add_uint(&pkt, COAP_OPT_CONTENT_FORMAT, COAP_FORMAT_LINK);
res = cord_common_add_qstring(&pkt);
if (res < 0) {
Expand Down
4 changes: 1 addition & 3 deletions sys/net/application_layer/cord/epsim/cord_epsim.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
#include "assert.h"
#include "net/gcoap.h"
#include "net/cord/epsim.h"
#include "net/cord/config.h"
#include "net/cord/common.h"
#include "net/ipv6/addr.h"

#define BUFSIZE (128U)

Expand Down Expand Up @@ -59,7 +57,7 @@ int cord_epsim_register(const sock_udp_ep_t *rd_ep)
return CORD_EPSIM_ERROR;
}
/* make packet confirmable */
coap_hdr_set_type(pkt.hdr, COAP_TYPE_CON);
coap_pkt_set_type(&pkt, COAP_TYPE_CON);
/* add Uri-Query options */
if (cord_common_add_qstring(&pkt) < 0) {
return CORD_EPSIM_ERROR;
Expand Down
4 changes: 2 additions & 2 deletions sys/net/application_layer/cord/lc/cord_lc.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ static ssize_t _lookup_raw(const cord_lc_rd_t *rd, unsigned content_format,
DEBUG("cord_lc: unsupported content format\n");
return CORD_LC_ERR;
}
coap_hdr_set_type(pkt.hdr, COAP_TYPE_CON);
coap_pkt_set_type(&pkt, COAP_TYPE_CON);
coap_opt_add_uint(&pkt, COAP_OPT_ACCEPT, content_format);

pkt_len = coap_opt_finish(&pkt, COAP_OPT_FINISH_NONE);
Expand Down Expand Up @@ -251,7 +251,7 @@ static int _send_rd_init_req(coap_pkt_t *pkt, const sock_udp_ep_t *remote,
return CORD_LC_ERR;
}

coap_hdr_set_type(pkt->hdr, COAP_TYPE_CON);
coap_pkt_set_type(pkt, COAP_TYPE_CON);
coap_opt_add_uri_query(pkt, "rt", "core.rd-lookup-*");

ssize_t pkt_len = coap_opt_finish(pkt, COAP_OPT_FINISH_NONE);
Expand Down

0 comments on commit f31e223

Please sign in to comment.