From 3920dd8c20e508651ba5f8e574112a708c1eec51 Mon Sep 17 00:00:00 2001 From: Leandro Lanzieri Date: Fri, 17 Jul 2020 16:33:19 +0200 Subject: [PATCH] net/gcoap: Remove gcoap_finish --- sys/include/net/gcoap.h | 64 ----------------------- sys/net/application_layer/gcoap/Kconfig | 28 ---------- sys/net/application_layer/gcoap/gcoap.c | 45 ++-------------- tests/unittests/tests-gcoap/tests-gcoap.c | 2 +- 4 files changed, 4 insertions(+), 135 deletions(-) diff --git a/sys/include/net/gcoap.h b/sys/include/net/gcoap.h index 896cfe346b1f..c9f113965c20 100644 --- a/sys/include/net/gcoap.h +++ b/sys/include/net/gcoap.h @@ -411,45 +411,6 @@ extern "C" { #define CONFIG_GCOAP_PDU_BUF_SIZE (128) #endif -/** - * @brief Reduce payload length by this value for a request - * - * Accommodates writing Content-Format option in gcoap_finish(). May set to - * zero if function not used. - * - * @deprecated Will not be available after the 2020.07 release. Used only by - * gcoap_finish(), which also is deprecated. - */ -#ifndef CONFIG_GCOAP_REQ_OPTIONS_BUF -#define CONFIG_GCOAP_REQ_OPTIONS_BUF (4) -#endif - -/** - * @brief Reduce payload length by this value for a response - * - * Accommodates writing Content-Format option in gcoap_finish(). May set to - * zero if function not used. - * - * @deprecated Will not be available after the 2020.07 release. Used only by - * gcoap_finish(), which also is deprecated. - */ -#ifndef CONFIG_GCOAP_RESP_OPTIONS_BUF -#define CONFIG_GCOAP_RESP_OPTIONS_BUF (4) -#endif - -/** - * @brief Reduce payload length by this value for an observe notification - * - * Accommodates writing Content-Format option in gcoap_finish(). May set to - * zero if function not used. - * - * @deprecated Will not be available after the 2020.07 release. Used only by - * gcoap_finish(), which also is deprecated. - */ -#ifndef CONFIG_GCOAP_OBS_OPTIONS_BUF -#define CONFIG_GCOAP_OBS_OPTIONS_BUF (4) -#endif - /** * @brief Maximum number of requests awaiting a response */ @@ -752,31 +713,6 @@ 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); -/** - * @brief Finishes formatting a CoAP PDU after the payload has been written - * - * Assumes the PDU has been initialized with a gcoap_xxx_init() function, like - * gcoap_req_init(). - * - * @deprecated Will not be available after the 2020.07 release. Use - * coap_opt_finish() instead. - * - * @warning To use this function, you only may have added an Option with - * option number less than COAP_OPT_CONTENT_FORMAT. Otherwise, use the - * struct-based API described with @link net_nanocoap nanocoap. @endlink With - * this API, you specify the format with coap_opt_add_uint(), prepare for the - * payload with coap_opt_finish(), and then write the payload. - * - * @param[in,out] pdu Request metadata - * @param[in] payload_len Length of the payload, or 0 if none - * @param[in] format Format code for the payload; use COAP_FORMAT_NONE if - * not specified - * - * @return size of the PDU - * @return < 0 on error - */ -ssize_t gcoap_finish(coap_pkt_t *pdu, size_t payload_len, unsigned format); - /** * @brief Writes a complete CoAP request PDU when there is not a payload * diff --git a/sys/net/application_layer/gcoap/Kconfig b/sys/net/application_layer/gcoap/Kconfig index afe688f0d1b7..8599ae83c839 100644 --- a/sys/net/application_layer/gcoap/Kconfig +++ b/sys/net/application_layer/gcoap/Kconfig @@ -13,40 +13,12 @@ menuconfig KCONFIG_MODULE_GCOAP if KCONFIG_MODULE_GCOAP -menu "Buffer Sizes" - config GCOAP_PDU_BUF_SIZE int "Request or response buffer size" default 128 help Size of the buffer used to build a CoAP request or response. -config GCOAP_REQ_OPTIONS_BUF - int "Request options buffer size" - default 4 - help - Reduce payload length by this value for a request. - Accommodates writing Content-Format option in gcoap_finish(). May be - set to zero if the function is not used. - -config GCOAP_RESP_OPTIONS_BUF - int "Response options buffer size" - default 4 - help - Reduce payload length by this value for a response. - Accommodates writing Content-Format option in gcoap_finish(). May be - set to zero if the function is not used. - -config GCOAP_OBS_OPTIONS_BUF - int "Observe notification options buffer size" - default 4 - help - Reduce payload length by this value for an observe notification. - Accommodates writing Content-Format option in gcoap_finish(). May be - set to zero if the function is not used. - -endmenu # Buffer Sizes - menu "Observe options" config GCOAP_OBS_CLIENTS_MAX diff --git a/sys/net/application_layer/gcoap/gcoap.c b/sys/net/application_layer/gcoap/gcoap.c index 9511b5699575..7dcb442da8f6 100644 --- a/sys/net/application_layer/gcoap/gcoap.c +++ b/sys/net/application_layer/gcoap/gcoap.c @@ -680,52 +680,13 @@ int gcoap_req_init(coap_pkt_t *pdu, uint8_t *buf, size_t len, res = coap_build_hdr(pdu->hdr, COAP_TYPE_CON, NULL, 0, code, msgid); } - coap_pkt_init(pdu, buf, len - CONFIG_GCOAP_REQ_OPTIONS_BUF, res); + coap_pkt_init(pdu, buf, len, res); if (path != NULL) { res = coap_opt_add_uri_path(pdu, path); } return (res > 0) ? 0 : res; } -/* - * Assumes pdu.payload_len attribute was reduced in gcoap_xxx_init() to - * ensure enough space in PDU buffer to write Content-Format option and - * payload marker here. - */ -ssize_t gcoap_finish(coap_pkt_t *pdu, size_t payload_len, unsigned format) -{ - assert( !(pdu->options_len) || - !(payload_len) || - (format == COAP_FORMAT_NONE) || - (pdu->options[pdu->options_len-1].opt_num < COAP_OPT_CONTENT_FORMAT)); - - if (payload_len) { - /* determine Content-Format option length */ - unsigned format_optlen = 1; - if (format == COAP_FORMAT_NONE) { - format_optlen = 0; - } - else if (format > 255) { - format_optlen = 3; - } - else if (format > 0) { - format_optlen = 2; - } - - /* move payload to accommodate option and payload marker */ - memmove(pdu->payload+format_optlen+1, pdu->payload, payload_len); - - if (format_optlen) { - coap_opt_add_uint(pdu, COAP_OPT_CONTENT_FORMAT, format); - } - *pdu->payload++ = 0xFF; - } - /* must write option before updating PDU with actual length */ - pdu->payload_len = payload_len; - - return pdu->payload_len + (pdu->payload - (uint8_t *)pdu->hdr); -} - size_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) @@ -840,7 +801,7 @@ int gcoap_resp_init(coap_pkt_t *pdu, uint8_t *buf, size_t len, unsigned code) pdu->options_len = 0; pdu->payload = buf + header_len; - pdu->payload_len = len - header_len - CONFIG_GCOAP_RESP_OPTIONS_BUF; + pdu->payload_len = len - header_len; if (coap_get_observe(pdu) == COAP_OBS_REGISTER) { /* generate initial notification value */ @@ -869,7 +830,7 @@ int gcoap_obs_init(coap_pkt_t *pdu, uint8_t *buf, size_t len, memo->token_len, COAP_CODE_CONTENT, msgid); if (hdrlen > 0) { - coap_pkt_init(pdu, buf, len - CONFIG_GCOAP_OBS_OPTIONS_BUF, hdrlen); + coap_pkt_init(pdu, buf, len, hdrlen); uint32_t now = xtimer_now_usec(); pdu->observe_value = (now >> GCOAP_OBS_TICK_EXPONENT) & 0xFFFFFF; diff --git a/tests/unittests/tests-gcoap/tests-gcoap.c b/tests/unittests/tests-gcoap/tests-gcoap.c index 10047629dc50..7ba737868d0e 100644 --- a/tests/unittests/tests-gcoap/tests-gcoap.c +++ b/tests/unittests/tests-gcoap/tests-gcoap.c @@ -161,7 +161,7 @@ static void test_gcoap__client_put_req(void) static void test_gcoap__client_put_req_overfill(void) { /* header 4, token 2, path 11, format 1, marker 1 = 19 */ - uint8_t buf[18+CONFIG_GCOAP_REQ_OPTIONS_BUF]; + uint8_t buf[18]; coap_pkt_t pdu; ssize_t len; char path[] = "/riot/value";