From 8a11ca2f8715b6840e191eba815546f47be9b2fe Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Tue, 8 Nov 2022 19:27:45 +0100 Subject: [PATCH] nanocoap: don't hide coap_request_ctx_t content --- sys/include/net/nanocoap.h | 42 +++++++-------- sys/net/application_layer/gcoap/gcoap.c | 1 - sys/net/application_layer/nanocoap/nanocoap.c | 5 +- .../nanocoap/nanocoap_internal.h | 54 ------------------- sys/net/application_layer/nanocoap/sock.c | 1 - 5 files changed, 19 insertions(+), 84 deletions(-) delete mode 100644 sys/net/application_layer/nanocoap/nanocoap_internal.h diff --git a/sys/include/net/nanocoap.h b/sys/include/net/nanocoap.h index 8588d9249e..fc857ad05c 100644 --- a/sys/include/net/nanocoap.h +++ b/sys/include/net/nanocoap.h @@ -239,11 +239,6 @@ typedef struct { /** * @brief Forward declaration of internal CoAP resource request handler context */ -struct _coap_request_ctx; - -/** - * @brief CoAP resource request handler context - */ typedef struct _coap_request_ctx coap_request_ctx_t; /** @@ -322,33 +317,32 @@ typedef const struct { const size_t resources_numof; /**< number of entries in array */ } coap_resource_subtree_t; -/** - * @brief Size of the CoAP request context struct - */ -#define COAP_REQUEST_CTX_SIZE (2 * sizeof(void *) + \ - IS_USED(MODULE_GCOAP) * sizeof(uint32_t)) - -/** - * @brief Define and initialize CoAP request context struct - * - * @param[in] ctx Name of the request context variable - * @param[in] remote Remote endpoint that made the request - */ -#define COAP_REQUEST_CTX_INIT(ctx, remote) \ - uint8_t ctx ## _buffer[COAP_REQUEST_CTX_SIZE]; \ - coap_request_ctx_t *ctx = (void *)ctx ## _buffer; \ - coap_request_ctx_init(ctx, remote) - /** * @brief Initialize CoAP request context - * Called by @ref COAP_REQUEST_CTX_INIT - * @internal * * @param[in] ctx Pointer to the request context to initialize * @param[in] remote Remote endpoint that made the request */ void coap_request_ctx_init(coap_request_ctx_t *ctx, sock_udp_ep_t *remote); +/** + * @brief CoAP resource request handler context + * @internal + */ +struct _coap_request_ctx { + const coap_resource_t *resource; /**< resource of the request */ + sock_udp_ep_t *remote; /**< remote endpoint of the request */ +#if defined(MODULE_GCOAP) || DOXYGEN + /** + * @brief transport the packet was received over + * @see @ref gcoap_socket_type_t for values. + * @note @ref gcoap_socket_type_t can not be used, as this would + * cyclically include the @ref net_gcoap header. + */ + uint32_t tl_type; +#endif +}; + /** * @brief Get resource path associated with a CoAP request * diff --git a/sys/net/application_layer/gcoap/gcoap.c b/sys/net/application_layer/gcoap/gcoap.c index aaa0e1afba..aa7909de1e 100644 --- a/sys/net/application_layer/gcoap/gcoap.c +++ b/sys/net/application_layer/gcoap/gcoap.c @@ -29,7 +29,6 @@ #include "net/coap.h" #include "net/gcoap.h" #include "net/gcoap/forward_proxy.h" -#include "nanocoap_internal.h" #include "net/nanocoap/cache.h" #include "net/sock/async/event.h" #include "net/sock/util.h" diff --git a/sys/net/application_layer/nanocoap/nanocoap.c b/sys/net/application_layer/nanocoap/nanocoap.c index c9944dcf12..f768ffd8d4 100644 --- a/sys/net/application_layer/nanocoap/nanocoap.c +++ b/sys/net/application_layer/nanocoap/nanocoap.c @@ -27,7 +27,7 @@ #include #include "bitarithm.h" -#include "nanocoap_internal.h" +#include "net/nanocoap.h" #define ENABLE_DEBUG 0 #include "debug.h" @@ -1262,9 +1262,6 @@ unsigned coap_get_len(coap_pkt_t *pkt) void coap_request_ctx_init(coap_request_ctx_t *ctx, sock_udp_ep_t *remote) { - static_assert(COAP_REQUEST_CTX_SIZE == sizeof(coap_request_ctx_t), - "COAP_REQUEST_CTX_SIZE define does not match actual size"); - memset(ctx, 0, sizeof(*ctx)); ctx->remote = remote; } diff --git a/sys/net/application_layer/nanocoap/nanocoap_internal.h b/sys/net/application_layer/nanocoap/nanocoap_internal.h deleted file mode 100644 index a9819c24bb..0000000000 --- a/sys/net/application_layer/nanocoap/nanocoap_internal.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2022 ML!PA Consulting GmbH - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @ingroup net_nanocoap - * @{ - * - * @file - * @brief NanoCoAP internals - * - * @author Benjamin Valentin - */ - -#ifndef NANOCOAP_INTERNAL_H -#define NANOCOAP_INTERNAL_H - -#include "net/nanocoap.h" -#if defined(MODULE_SOCK_UDP) || defined(DOXYGEN) -#include "net/sock/udp.h" -#else -typedef void sock_udp_ep_t; -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Internal CoAP resource request handler context - */ -struct _coap_request_ctx { - const coap_resource_t *resource; /**< resource of the request */ - sock_udp_ep_t *remote; /**< remote endpoint of the request */ -#if defined(MODULE_GCOAP) || DOXYGEN - /** - * @brief transport the packet was received over - * @see @ref gcoap_socket_type_t for values. - * @note @ref gcoap_socket_type_t can not be used, as this would - * cyclically include the @ref net_gcoap header. - */ - uint32_t tl_type; -#endif -}; - -#ifdef __cplusplus -} -#endif -#endif /* NANOCOAP_INTERNAL_H */ -/** @} */ diff --git a/sys/net/application_layer/nanocoap/sock.c b/sys/net/application_layer/nanocoap/sock.c index 3261d16215..a0699215f5 100644 --- a/sys/net/application_layer/nanocoap/sock.c +++ b/sys/net/application_layer/nanocoap/sock.c @@ -26,7 +26,6 @@ #include #include "atomic_utils.h" -#include "nanocoap_internal.h" #include "net/nanocoap_sock.h" #include "net/sock/util.h" #include "net/sock/udp.h"