From 27308585c36288bfc7a2ef76d5a8551d91ca8a20 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Wed, 27 Mar 2024 12:21:57 +0100 Subject: [PATCH] gcoap: make gcoap_req_send_tl() an alias of gcoap_req_send() As per the deprecation notice from July 2021 ;-). --- examples/gcoap/client.c | 6 ++- sys/include/net/gcoap.h | 38 ++++++++++--------- sys/net/application_layer/cord/ep/cord_ep.c | 6 +-- .../application_layer/cord/epsim/cord_epsim.c | 2 +- sys/net/application_layer/cord/lc/cord_lc.c | 4 +- sys/net/application_layer/gcoap/dns.c | 2 +- .../application_layer/gcoap/forward_proxy.c | 9 +++-- sys/net/application_layer/gcoap/gcoap.c | 8 ++-- 8 files changed, 41 insertions(+), 34 deletions(-) diff --git a/examples/gcoap/client.c b/examples/gcoap/client.c index 8f4039baefa8..9af427f24159 100644 --- a/examples/gcoap/client.c +++ b/examples/gcoap/client.c @@ -146,7 +146,8 @@ static void _resp_handler(const gcoap_request_memo_t *memo, coap_pkt_t* pdu, int len = coap_opt_finish(pdu, COAP_OPT_FINISH_NONE); gcoap_req_send((uint8_t *)pdu->hdr, len, remote, - _resp_handler, memo->context); + _resp_handler, memo->context, + GCOAP_SOCKET_TYPE_UNDEF); } else { puts("--- blockwise complete ---"); @@ -158,7 +159,8 @@ static size_t _send(uint8_t *buf, size_t len, sock_udp_ep_t *remote) { size_t bytes_sent; - bytes_sent = gcoap_req_send(buf, len, remote, _resp_handler, NULL); + bytes_sent = gcoap_req_send(buf, len, remote, _resp_handler, NULL, + GCOAP_SOCKET_TYPE_UNDEF); if (bytes_sent > 0) { req_count++; } diff --git a/sys/include/net/gcoap.h b/sys/include/net/gcoap.h index 8c6370949178..7e364f46aea1 100644 --- a/sys/include/net/gcoap.h +++ b/sys/include/net/gcoap.h @@ -330,7 +330,8 @@ * coap_opt_add_proxy_uri(&pdu, uri); * unsigned len = coap_opt_finish(&pdu, COAP_OPT_FINISH_NONE); * - * gcoap_req_send((uint8_t *) pdu->hdr, len, proxy_remote, _resp_handler, NULL); + * gcoap_req_send((uint8_t *) pdu->hdr, len, proxy_remote, _resp_handler, NULL, + * GCOAP_SOCKET_TYPE_UNDEF); * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * See the gcoap example for a sample implementation. @@ -960,9 +961,6 @@ static inline ssize_t gcoap_request(coap_pkt_t *pdu, uint8_t *buf, size_t len, /** * @brief Sends a buffer containing a CoAP request to the provided endpoint * - * @deprecated Will be an alias for @ref gcoap_req_send after the 2022.01 - * release. Will be removed after the 2022.04 release. - * * @param[in] buf Buffer containing the PDU * @param[in] len Length of the buffer * @param[in] remote Destination for the packet @@ -973,39 +971,45 @@ static inline ssize_t gcoap_request(coap_pkt_t *pdu, uint8_t *buf, size_t len, * available (by value) will be selected. Only single * types are allowed, not a combination of them. * + * @note The highest supported (by value) gcoap_socket_type_t will be selected + * as transport type. + * * @return length of the packet * @return -ENOTCONN, if DTLS was used and session establishment failed * @return -EINVAL, if @p tl_type is is not supported * @return 0 if cannot send */ -ssize_t gcoap_req_send_tl(const uint8_t *buf, size_t len, - const sock_udp_ep_t *remote, - gcoap_resp_handler_t resp_handler, void *context, - gcoap_socket_type_t tl_type); +ssize_t gcoap_req_send(const uint8_t *buf, size_t len, + const sock_udp_ep_t *remote, + gcoap_resp_handler_t resp_handler, void *context, + gcoap_socket_type_t tl_type); /** * @brief Sends a buffer containing a CoAP request to the provided endpoint * + * @deprecated Will be removed after the 2023.10 release. Use alias @ref gcoap_req_send() instead. + * * @param[in] buf Buffer containing the PDU * @param[in] len Length of the buffer * @param[in] remote Destination for the packet * @param[in] resp_handler Callback when response received, may be NULL * @param[in] context User defined context passed to the response handler - * - * @note The highest supported (by value) gcoap_socket_type_t will be selected - * as transport type. + * @param[in] tl_type The transport type to use for send. When + * @ref GCOAP_SOCKET_TYPE_UNDEF is selected, the highest + * available (by value) will be selected. Only single + * types are allowed, not a combination of them. * * @return length of the packet * @return -ENOTCONN, if DTLS was used and session establishment failed + * @return -EINVAL, if @p tl_type is is not supported * @return 0 if cannot send */ -static inline ssize_t gcoap_req_send(const uint8_t *buf, size_t len, - const sock_udp_ep_t *remote, - gcoap_resp_handler_t resp_handler, - void *context) +static inline ssize_t gcoap_req_send_tl(const uint8_t *buf, size_t len, + const sock_udp_ep_t *remote, + gcoap_resp_handler_t resp_handler, void *context, + gcoap_socket_type_t tl_type) { - return gcoap_req_send_tl(buf, len, remote, resp_handler, context, - GCOAP_SOCKET_TYPE_UNDEF); + return gcoap_req_send(buf, len, remote, resp_handler, context, tl_type); } /** diff --git a/sys/net/application_layer/cord/ep/cord_ep.c b/sys/net/application_layer/cord/ep/cord_ep.c index 4bc13538fad9..b9148d9b2b3a 100644 --- a/sys/net/application_layer/cord/ep/cord_ep.c +++ b/sys/net/application_layer/cord/ep/cord_ep.c @@ -151,7 +151,7 @@ static int _update_remove(unsigned code, gcoap_resp_handler_t handle) ssize_t pkt_len = coap_opt_finish(&pkt, COAP_OPT_FINISH_NONE); /* send request */ - ssize_t send_len = gcoap_req_send(buf, pkt_len, &_rd_remote, handle, NULL); + ssize_t send_len = gcoap_req_send(buf, pkt_len, &_rd_remote, handle, NULL, GCOAP_SOCKET_TYPE_UNDEF); if (send_len <= 0) { return CORD_EP_ERR; } @@ -225,7 +225,7 @@ static int _discover_internal(const sock_udp_ep_t *remote, coap_hdr_set_type(pkt.hdr, 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, _on_discover, NULL); + res = gcoap_req_send(buf, pkt_len, remote, _on_discover, NULL, GCOAP_SOCKET_TYPE_UNDEF); if (res <= 0) { return CORD_EP_ERR; } @@ -296,7 +296,7 @@ int cord_ep_register(const sock_udp_ep_t *remote, const char *regif) pkt_len += res; /* send out the request */ - res = gcoap_req_send(buf, pkt_len, remote, _on_register, NULL); + res = gcoap_req_send(buf, pkt_len, remote, _on_register, NULL, GCOAP_SOCKET_TYPE_UNDEF); if (res <= 0) { retval = CORD_EP_ERR; goto end; diff --git a/sys/net/application_layer/cord/epsim/cord_epsim.c b/sys/net/application_layer/cord/epsim/cord_epsim.c index 4bcefce27edb..9c739c106f69 100644 --- a/sys/net/application_layer/cord/epsim/cord_epsim.c +++ b/sys/net/application_layer/cord/epsim/cord_epsim.c @@ -67,7 +67,7 @@ int cord_epsim_register(const sock_udp_ep_t *rd_ep) /* finish, we don't have any payload */ ssize_t len = coap_opt_finish(&pkt, COAP_OPT_FINISH_NONE); _state = CORD_EPSIM_BUSY; - if (gcoap_req_send(buf, len, rd_ep, _req_handler, NULL) == 0) { + if (gcoap_req_send(buf, len, rd_ep, _req_handler, NULL, GCOAP_SOCKET_TYPE_UNDEF) == 0) { return CORD_EPSIM_ERROR; } diff --git a/sys/net/application_layer/cord/lc/cord_lc.c b/sys/net/application_layer/cord/lc/cord_lc.c index b77e00a3f117..68fb2032b832 100644 --- a/sys/net/application_layer/cord/lc/cord_lc.c +++ b/sys/net/application_layer/cord/lc/cord_lc.c @@ -190,7 +190,7 @@ static ssize_t _lookup_raw(const cord_lc_rd_t *rd, unsigned content_format, if (pkt_len < 0) { return CORD_LC_ERR; } - res = gcoap_req_send(reqbuf, pkt_len, rd->remote, _on_lookup, NULL); + res = gcoap_req_send(reqbuf, pkt_len, rd->remote, _on_lookup, NULL, GCOAP_SOCKET_TYPE_UNDEF); if (res < 0) { return CORD_LC_ERR; } @@ -250,7 +250,7 @@ static int _send_rd_init_req(coap_pkt_t *pkt, const sock_udp_ep_t *remote, return CORD_LC_ERR; } - if (!gcoap_req_send(buf, pkt_len, remote, _on_rd_init, NULL)) { + if (!gcoap_req_send(buf, pkt_len, remote, _on_rd_init, NULL, GCOAP_SOCKET_TYPE_UNDEF)) { DEBUG("cord_lc: error gcoap_req_send()\n"); return CORD_LC_ERR; } diff --git a/sys/net/application_layer/gcoap/dns.c b/sys/net/application_layer/gcoap/dns.c index 9d78dd53c9f8..1b0ce80d2c80 100644 --- a/sys/net/application_layer/gcoap/dns.c +++ b/sys/net/application_layer/gcoap/dns.c @@ -765,6 +765,6 @@ static ssize_t _send(const void *buf, size_t len, const sock_udp_ep_t *remote, if (lock_resp_wait) { mutex_lock(&context->resp_wait); } - return gcoap_req_send_tl(buf, len, remote, _resp_handler, context, tl_type); + return gcoap_req_send(buf, len, remote, _resp_handler, context, tl_type); } /** @} */ diff --git a/sys/net/application_layer/gcoap/forward_proxy.c b/sys/net/application_layer/gcoap/forward_proxy.c index a5d74c967997..808180aeb277 100644 --- a/sys/net/application_layer/gcoap/forward_proxy.c +++ b/sys/net/application_layer/gcoap/forward_proxy.c @@ -208,10 +208,10 @@ static bool _parse_endpoint(sock_udp_ep_t *remote, static ssize_t _dispatch_msg(const void *buf, size_t len, sock_udp_ep_t *remote) { /* Yes it's not a request -- but turns out there is nothing in - * gcoap_req_send_tl that is actually request specific, especially if we + * gcoap_req_send that is actually request specific, especially if we * don't assign a callback. */ - ssize_t res = gcoap_req_send_tl(buf, len, remote, NULL, NULL, - GCOAP_SOCKET_TYPE_UDP); + ssize_t res = gcoap_req_send(buf, len, remote, NULL, NULL, + GCOAP_SOCKET_TYPE_UDP); if (res <= 0) { DEBUG("gcoap_forward_proxy: unable to dispatch message: %d\n", -res); } @@ -440,7 +440,8 @@ static int _gcoap_forward_proxy_via_coap(coap_pkt_t *client_pkt, len = gcoap_req_send((uint8_t *)pkt.hdr, len, &origin_server_ep, - _forward_resp_handler, (void *)client_ep); + _forward_resp_handler, (void *)client_ep, + GCOAP_SOCKET_TYPE_UNDEF); return len; } diff --git a/sys/net/application_layer/gcoap/gcoap.c b/sys/net/application_layer/gcoap/gcoap.c index adf8829b237b..e6fc5d91ff8b 100644 --- a/sys/net/application_layer/gcoap/gcoap.c +++ b/sys/net/application_layer/gcoap/gcoap.c @@ -1612,10 +1612,10 @@ int gcoap_obs_req_forget(const sock_udp_ep_t *remote, const uint8_t *token, return res; } -ssize_t gcoap_req_send_tl(const uint8_t *buf, size_t len, - const sock_udp_ep_t *remote, - gcoap_resp_handler_t resp_handler, void *context, - gcoap_socket_type_t tl_type) +ssize_t gcoap_req_send(const uint8_t *buf, size_t len, + const sock_udp_ep_t *remote, + gcoap_resp_handler_t resp_handler, void *context, + gcoap_socket_type_t tl_type) { gcoap_socket_t socket = { 0 }; gcoap_request_memo_t *memo = NULL;