From 86b778167a554bd4add3b9282893df1fc22c2366 Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Thu, 16 Apr 2026 15:42:51 +0100 Subject: [PATCH] RIOT: Implement RIOT's coding standards --- examples/riot/examples_libcoap_client/Kconfig | 6 +-- .../examples_libcoap_client/client_coap.c | 47 ++++++++-------- .../examples_libcoap_client/client_coap.h | 14 +++-- examples/riot/examples_libcoap_client/main.c | 12 ++--- examples/riot/examples_libcoap_server/Kconfig | 6 +-- examples/riot/examples_libcoap_server/main.c | 12 ++--- .../examples_libcoap_server/server_coap.c | 48 ++++++----------- .../examples_libcoap_server/server_coap.h | 14 +++-- examples/riot/pkg_libcoap/Kconfig | 6 +-- examples/riot/pkg_libcoap/Makefile | 3 +- examples/riot/pkg_libcoap/Makefile.libcoap | 2 +- examples/riot/tests_pkg_libcoap/Kconfig | 6 +-- .../riot/tests_pkg_libcoap/libcoap-test.c | 53 ++++++++----------- .../riot/tests_pkg_libcoap/libcoap-test.h | 15 +++--- examples/riot/tests_pkg_libcoap/main.c | 12 ++--- src/coap_asn1.c | 2 +- 16 files changed, 107 insertions(+), 151 deletions(-) diff --git a/examples/riot/examples_libcoap_client/Kconfig b/examples/riot/examples_libcoap_client/Kconfig index 1f873507..e9123a1a 100644 --- a/examples/riot/examples_libcoap_client/Kconfig +++ b/examples/riot/examples_libcoap_client/Kconfig @@ -1,6 +1,6 @@ -# 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. +# +# SPDX-FileCopyrightText: 2023-2026 Jon Shallow +# SPDX-License-Identifier: BSD-2-Clause # menu "libcoap_client" depends on USEPKG_LIBCOAP diff --git a/examples/riot/examples_libcoap_client/client_coap.c b/examples/riot/examples_libcoap_client/client_coap.c index 329b3594..d29bc8cc 100644 --- a/examples/riot/examples_libcoap_client/client_coap.c +++ b/examples/riot/examples_libcoap_client/client_coap.c @@ -1,10 +1,11 @@ +/* + * SPDX-FileCopyrightText: 2023-2026 Jon Shallow + * SPDX-License-Identifier: BSD-2-Clause + */ + /* * client_coap.c -- RIOT client example * - * Copyright (C) 2023-2026 Jon Shallow - * - * SPDX-License-Identifier: BSD-2-Clause - * * This file is part of the CoAP library libcoap. Please see README for terms * of use. */ @@ -17,21 +18,21 @@ #include "macros/utils.h" #ifdef CONFIG_LIBCOAP_CLIENT_URI -#define COAP_CLIENT_URI CONFIG_LIBCOAP_CLIENT_URI +# define COAP_CLIENT_URI CONFIG_LIBCOAP_CLIENT_URI #else /* ! CONFIG_LIBCOAP_CLIENT_URI */ -#define COAP_CLIENT_URI "coap://[fe80::405:5aff:fe15:9b7f]/.well-known/core" +# define COAP_CLIENT_URI "coap://[fe80::405:5aff:fe15:9b7f]/.well-known/core" #endif /* ! CONFIG_LIBCOAP_CLIENT_URI */ #ifdef CONFIG_LIBCOAP_USE_PSK -#define COAP_USE_PSK CONFIG_LIBCOAP_USE_PSK +# define COAP_USE_PSK CONFIG_LIBCOAP_USE_PSK #else /* ! CONFIG_LIBCOAP_USE_PSK */ -#define COAP_USE_PSK NULL +# define COAP_USE_PSK NULL #endif /* ! CONFIG_LIBCOAP_USE_PSK */ #ifdef CONFIG_LIBCOAP_USE_PSK_ID -#define COAP_USE_PSK_ID CONFIG_LIBCOAP_USE_PSK_ID +# define COAP_USE_PSK_ID CONFIG_LIBCOAP_USE_PSK_ID #else /* ! CONFIG_LIBCOAP_USE_PSK_ID */ -#define COAP_USE_PSK_ID NULL +# define COAP_USE_PSK_ID NULL #endif /* ! CONFIG_LIBCOAP_USE_PSK_ID */ static coap_context_t *main_coap_context = NULL; @@ -44,11 +45,10 @@ static int is_mcast = 0; unsigned int wait_seconds = DEFAULT_WAIT_TIME; /* default timeout in seconds */ -static coap_response_t -message_handler(coap_session_t *session, - const coap_pdu_t *sent, - const coap_pdu_t *received, - const coap_mid_t id) +static coap_response_t message_handler(coap_session_t *session, + const coap_pdu_t *sent, + const coap_pdu_t *received, + const coap_mid_t id) { const uint8_t *data; size_t len; @@ -68,11 +68,10 @@ message_handler(coap_session_t *session, return COAP_RESPONSE_OK; } -static void -nack_handler(coap_session_t *session COAP_UNUSED, - const coap_pdu_t *sent COAP_UNUSED, - const coap_nack_reason_t reason, - const coap_mid_t id COAP_UNUSED) +static void nack_handler(coap_session_t *session COAP_UNUSED, + const coap_pdu_t *sent COAP_UNUSED, + const coap_nack_reason_t reason, + const coap_mid_t id COAP_UNUSED) { switch (reason) { @@ -94,9 +93,8 @@ nack_handler(coap_session_t *session COAP_UNUSED, return; } -static int -resolve_address(const char *host, const char *service, coap_address_t *dst, - int scheme_hint_bits) +static int resolve_address(const char *host, const char *service, + coap_address_t *dst, int scheme_hint_bits) { uint16_t port = service ? atoi(service) : 0; int ret = 0; @@ -118,8 +116,7 @@ resolve_address(const char *host, const char *service, coap_address_t *dst, return ret; } -void -client_coap_init(int argc, char **argv) +void client_coap_init(int argc, char **argv) { coap_session_t *session = NULL; coap_pdu_t *pdu; diff --git a/examples/riot/examples_libcoap_client/client_coap.h b/examples/riot/examples_libcoap_client/client_coap.h index 4e4bcfd6..ced7ac9b 100644 --- a/examples/riot/examples_libcoap_client/client_coap.h +++ b/examples/riot/examples_libcoap_client/client_coap.h @@ -1,16 +1,16 @@ +/* + * SPDX-FileCopyrightText: 2023-2026 Jon Shallow + * SPDX-License-Identifier: BSD-2-Clause + */ + /* * client-coap.h -- RIOT client example * - * Copyright (C) 2023-2026 Jon Shallow - * - * SPDX-License-Identifier: BSD-2-Clause - * * This file is part of the CoAP library libcoap. Please see README for terms * of use. */ -#ifndef CLIENT_COAP_H -#define CLIENT_COAP_H +#pragma once #ifdef __cplusplus extern "C" { @@ -22,5 +22,3 @@ void client_coap_init(int argc, char **argv); #ifdef __cplusplus } #endif - -#endif /* CLIENT_COAP_H */ diff --git a/examples/riot/examples_libcoap_client/main.c b/examples/riot/examples_libcoap_client/main.c index 23dacae5..d7a11777 100644 --- a/examples/riot/examples_libcoap_client/main.c +++ b/examples/riot/examples_libcoap_client/main.c @@ -1,10 +1,7 @@ /* - * Copyright (C) 2015 Freie Universität Berlin - * Copyright (C) 2018 Inria - * - * 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. + * SPDX-FileCopyrightText: 2015 Freie Universität Berlin + * SPDX-FileCopyrightText: 2018 Inria + * SPDX-License-Identifier: LGPL-2.1-only */ /** @@ -36,8 +33,7 @@ static const shell_command_t shell_commands[] = { { NULL, NULL, NULL } }; -int -main(void) +int main(void) { /* we need a message queue for the thread running the shell in order to * receive potentially fast incoming networking packets */ diff --git a/examples/riot/examples_libcoap_server/Kconfig b/examples/riot/examples_libcoap_server/Kconfig index dd7969e9..6d8dc4f9 100644 --- a/examples/riot/examples_libcoap_server/Kconfig +++ b/examples/riot/examples_libcoap_server/Kconfig @@ -1,6 +1,6 @@ -# 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. +# +# SPDX-FileCopyrightText: 2023-2026 Jon Shallow +# SPDX-License-Identifier: BSD-2-Clause # menu "libcoap_server" depends on USEPKG_LIBCOAP diff --git a/examples/riot/examples_libcoap_server/main.c b/examples/riot/examples_libcoap_server/main.c index a9db1ffc..7cd42a36 100644 --- a/examples/riot/examples_libcoap_server/main.c +++ b/examples/riot/examples_libcoap_server/main.c @@ -1,10 +1,7 @@ /* - * Copyright (C) 2015 Freie Universität Berlin - * Copyright (C) 2018 Inria - * - * 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. + * SPDX-FileCopyrightText: 2015 Freie Universität Berlin + * SPDX-FileCopyrightText: 2018 Inria + * SPDX-License-Identifier: LGPL-2.1-only */ /** @@ -36,8 +33,7 @@ static const shell_command_t shell_commands[] = { { NULL, NULL, NULL } }; -int -main(void) +int main(void) { /* we need a message queue for the thread running the shell in order to * receive potentially fast incoming networking packets */ diff --git a/examples/riot/examples_libcoap_server/server_coap.c b/examples/riot/examples_libcoap_server/server_coap.c index b45fd0dc..6015445a 100644 --- a/examples/riot/examples_libcoap_server/server_coap.c +++ b/examples/riot/examples_libcoap_server/server_coap.c @@ -1,10 +1,11 @@ +/* + * SPDX-FileCopyrightText: 2023-2026 Jon Shallow + * SPDX-License-Identifier: BSD-2-Clause + */ + /* * server_coap.c -- RIOT example * - * Copyright (C) 2023-2026 Jon Shallow - * - * SPDX-License-Identifier: BSD-2-Clause - * * This file is part of the CoAP library libcoap. Please see README for terms * of use. */ @@ -16,9 +17,9 @@ #include "macros/utils.h" #ifdef CONFIG_LIBCOAP_USE_PSK -#define COAP_USE_PSK CONFIG_LIBCOAP_USE_PSK +# define COAP_USE_PSK CONFIG_LIBCOAP_USE_PSK #else /* CONFIG_LIBCOAP_USE_PSK */ -#define COAP_USE_PSK NULL +# define COAP_USE_PSK NULL #endif /* CONFIG_LIBCOAP_USE_PSK */ static volatile int running = 0; @@ -31,10 +32,9 @@ static coap_time_t clock_offset; static coap_time_t my_clock_base = 0; static coap_resource_t *time_resource = NULL; /* just for testing */ -static void -hnd_get_time(coap_resource_t *resource, coap_session_t *session, - const coap_pdu_t *request, const coap_string_t *query, - coap_pdu_t *response) +static void hnd_get_time(coap_resource_t *resource, coap_session_t *session, + const coap_pdu_t *request, const coap_string_t *query, + coap_pdu_t *response) { unsigned char buf[40]; size_t len; @@ -75,19 +75,10 @@ hnd_get_time(coap_resource_t *resource, coap_session_t *session, } } -static void -init_coap_resources(coap_context_t *ctx) +static void init_coap_resources(coap_context_t *ctx) { coap_resource_t *r; -#if 0 - r = coap_resource_init(NULL, 0, 0); - coap_register_handler(r, COAP_REQUEST_GET, hnd_get_index); - - coap_add_attr(r, coap_make_str_const("ct"), coap_make_str_const("0"), 0); - coap_add_attr(r, coap_make_str_const("title"), coap_make_str_const("\"General Info\""), 0); - coap_add_resource(ctx, r); -#endif /* store clock base to use in /time */ my_clock_base = clock_offset; @@ -125,8 +116,7 @@ error: coap_log_crit("cannot create resource\n"); } -static int -init_coap_context_endpoints(const char *use_psk) +static int init_coap_context_endpoints(const char *use_psk) { coap_address_t listenaddress; gnrc_netif_t *netif = gnrc_netif_iter(NULL); @@ -196,8 +186,7 @@ init_coap_context_endpoints(const char *use_psk) return 1; } -void * -server_coap_run(void *arg) +void *server_coap_run(void *arg) { (void)arg; @@ -234,9 +223,7 @@ fail: static char server_stack[THREAD_STACKSIZE_MAIN + THREAD_EXTRA_STACKSIZE_PRINTF]; -static -void -start_server(void) +static void start_server(void) { kernel_pid_t server_pid; @@ -268,9 +255,7 @@ start_server(void) return; } -static -void -stop_server(void) +static void stop_server(void) { /* check if server is running at all */ if (running == 0) { @@ -283,8 +268,7 @@ stop_server(void) puts("Stopping server..."); } -void -server_coap_init(int argc, char **argv) +void server_coap_init(int argc, char **argv) { if (argc < 2) { printf("usage: %s start|stop\n", argv[0]); diff --git a/examples/riot/examples_libcoap_server/server_coap.h b/examples/riot/examples_libcoap_server/server_coap.h index 52711d88..f0f75005 100644 --- a/examples/riot/examples_libcoap_server/server_coap.h +++ b/examples/riot/examples_libcoap_server/server_coap.h @@ -1,16 +1,16 @@ +/* + * SPDX-FileCopyrightText: 2023-2026 Jon Shallow + * SPDX-License-Identifier: BSD-2-Clause + */ + /* * server_coap.h -- RIOT client example * - * Copyright (C) 2023-2026 Jon Shallow - * - * SPDX-License-Identifier: BSD-2-Clause - * * This file is part of the CoAP library libcoap. Please see README for terms * of use. */ -#ifndef SERVER_COAP_H -#define SERVER_COAP_H +#pragma once #ifdef __cplusplus extern "C" { @@ -22,5 +22,3 @@ void server_coap_init(int argc, char **argv); #ifdef __cplusplus } #endif - -#endif /* SERVER_COAP_H */ diff --git a/examples/riot/pkg_libcoap/Kconfig b/examples/riot/pkg_libcoap/Kconfig index a033b7fa..eac27072 100644 --- a/examples/riot/pkg_libcoap/Kconfig +++ b/examples/riot/pkg_libcoap/Kconfig @@ -1,8 +1,6 @@ -# Copyright (c) 2019 HAW Hamburg # -# 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. +# SPDX-FileCopyrightText: 2019 HAW Hamburg +# SPDX-License-Identifier: BSD-2-Clause # menu "libcoap" depends on USEPKG_LIBCOAP diff --git a/examples/riot/pkg_libcoap/Makefile b/examples/riot/pkg_libcoap/Makefile index 0dcb607a..59126c4d 100644 --- a/examples/riot/pkg_libcoap/Makefile +++ b/examples/riot/pkg_libcoap/Makefile @@ -1,6 +1,7 @@ PKG_NAME=libcoap PKG_URL=https://github.com/obgm/libcoap -PKG_VERSION=24d146d55327507b2107941a134795c9a7be13ef +# develop branch as of 20th April 2026 +PKG_VERSION=783b5317caf30397df392228d67969af579fa03b PKG_LICENSE=BSD-2-Clause LIBCOAP_BUILD_DIR=$(BINDIR)/pkg/$(PKG_NAME) diff --git a/examples/riot/pkg_libcoap/Makefile.libcoap b/examples/riot/pkg_libcoap/Makefile.libcoap index 08af89dd..734f8959 100644 --- a/examples/riot/pkg_libcoap/Makefile.libcoap +++ b/examples/riot/pkg_libcoap/Makefile.libcoap @@ -38,7 +38,7 @@ SRC := coap_address.c \ coap_ws.c ifneq (,$(filter libcoap_tinydtls,$(USEMODULE))) -CFLAGS += -DCOAP_WITH_LIBTINYDTLS + CFLAGS += -DCOAP_WITH_LIBTINYDTLS endif include $(RIOTBASE)/Makefile.base diff --git a/examples/riot/tests_pkg_libcoap/Kconfig b/examples/riot/tests_pkg_libcoap/Kconfig index 522df4cd..2cca767e 100644 --- a/examples/riot/tests_pkg_libcoap/Kconfig +++ b/examples/riot/tests_pkg_libcoap/Kconfig @@ -1,6 +1,6 @@ -# 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. +# +# SPDX-FileCopyrightText: 2023-2026 Jon Shallow +# SPDX-License-Identifier: BSD-2-Clause # menu "tests_libcoap" depends on USEPKG_LIBCOAP diff --git a/examples/riot/tests_pkg_libcoap/libcoap-test.c b/examples/riot/tests_pkg_libcoap/libcoap-test.c index 65f530ad..d5aafc6d 100644 --- a/examples/riot/tests_pkg_libcoap/libcoap-test.c +++ b/examples/riot/tests_pkg_libcoap/libcoap-test.c @@ -1,10 +1,11 @@ +/* + * SPDX-FileCopyrightText: 2023-2026 Jon Shallow + * SPDX-License-Identifier: BSD-2-Clause + */ + /* * libcoap-test.c -- RIOT example * - * Copyright (C) 2023-2026 Jon Shallow - * - * SPDX-License-Identifier: BSD-2-Clause - * * This file is part of the CoAP library libcoap. Please see README for terms * of use. */ @@ -16,25 +17,24 @@ #include "macros/utils.h" #ifdef CONFIG_LIBCOAP_USE_PSK -#define COAP_USE_PSK CONFIG_LIBCOAP_USE_PSK +# define COAP_USE_PSK CONFIG_LIBCOAP_USE_PSK #else /* CONFIG_LIBCOAP_USE_PSK */ -#define COAP_USE_PSK NULL +# define COAP_USE_PSK NULL #endif /* CONFIG_LIBCOAP_USE_PSK */ #ifdef CONFIG_LIBCOAP_USE_PSK_ID -#define COAP_USE_PSK_ID CONFIG_LIBCOAP_USE_PSK_ID +# define COAP_USE_PSK_ID CONFIG_LIBCOAP_USE_PSK_ID #else /* CONFIG_LIBCOAP_USE_PSK_ID */ -#define COAP_USE_PSK_ID NULL +# define COAP_USE_PSK_ID NULL #endif /* CONFIG_LIBCOAP_USE_PSK_ID */ static int quit; #define INDEX "This is a DTLS loopback test client/server made with libcoap\n" -static void -hnd_get_index(coap_resource_t *resource, coap_session_t *session, - const coap_pdu_t *request, const coap_string_t *query, - coap_pdu_t *response) +static void hnd_get_index(coap_resource_t *resource, coap_session_t *session, + const coap_pdu_t *request, const coap_string_t *query, + coap_pdu_t *response) { coap_pdu_set_code(response, COAP_RESPONSE_CODE_CONTENT); coap_add_data_large_response(resource, session, request, response, @@ -43,8 +43,7 @@ hnd_get_index(coap_resource_t *resource, coap_session_t *session, (const uint8_t *)INDEX, NULL, NULL); } -static void -init_coap_resources(coap_context_t *ctx) +static void init_coap_resources(coap_context_t *ctx) { coap_resource_t *r; @@ -61,8 +60,7 @@ error: coap_log_crit("cannot create resource\n"); } -static int -init_coap_endpoints(coap_context_t *ctx, const char *use_psk) +static int init_coap_endpoints(coap_context_t *ctx, const char *use_psk) { char addr_str[INET6_ADDRSTRLEN + 8]; int scheme_hint_bits = 1 << COAP_URI_SCHEME_COAP; @@ -111,8 +109,7 @@ init_coap_endpoints(coap_context_t *ctx, const char *use_psk) return 1; } -static int -coap_server_init(coap_context_t *ctx) +static int coap_server_init(coap_context_t *ctx) { if (!init_coap_endpoints(ctx, COAP_USE_PSK)) { return 0; @@ -122,9 +119,8 @@ coap_server_init(coap_context_t *ctx) return 1; } -static int -resolve_address(const char *host, const char *service, coap_address_t *dst, - int scheme_hint_bits) +static int resolve_address(const char *host, const char *service, + coap_address_t *dst, int scheme_hint_bits) { uint16_t port = service ? atoi(service) : 0; int ret = 0; @@ -145,11 +141,10 @@ resolve_address(const char *host, const char *service, coap_address_t *dst, return ret; } -static coap_response_t -message_handler(coap_session_t *session, - const coap_pdu_t *sent, - const coap_pdu_t *received, - const coap_mid_t id) +static coap_response_t message_handler(coap_session_t *session, + const coap_pdu_t *sent, + const coap_pdu_t *received, + const coap_mid_t id) { const uint8_t *data; size_t len; @@ -169,8 +164,7 @@ message_handler(coap_session_t *session, return COAP_RESPONSE_OK; } -static int -coap_client_init(coap_context_t *ctx) +static int coap_client_init(coap_context_t *ctx) { coap_session_t *session = NULL; coap_pdu_t *pdu; @@ -289,8 +283,7 @@ fail: return 0; } -void -libcoap_test_run(void) +void libcoap_test_run(void) { coap_context_t *coap_context; diff --git a/examples/riot/tests_pkg_libcoap/libcoap-test.h b/examples/riot/tests_pkg_libcoap/libcoap-test.h index 1be0878f..af53a0b9 100644 --- a/examples/riot/tests_pkg_libcoap/libcoap-test.h +++ b/examples/riot/tests_pkg_libcoap/libcoap-test.h @@ -1,16 +1,17 @@ +/* + * SPDX-FileCopyrightText: 2023-2026 Jon Shallow + * SPDX-License-Identifier: BSD-2-Clause + */ + /* * libcoap-test.h -- RIOT client example * - * Copyright (C) 2023-2026 Jon Shallow - * - * SPDX-License-Identifier: BSD-2-Clause - * * This file is part of the CoAP library libcoap. Please see README for terms * of use. */ -#ifndef LIBCOAP_TEST_H -#define LIBCOAP_TEST_H + +#pragma once #ifdef __cplusplus extern "C" { @@ -22,5 +23,3 @@ void libcoap_test_run(void); #ifdef __cplusplus } #endif - -#endif /* LIBCOAP_TEST_H */ diff --git a/examples/riot/tests_pkg_libcoap/main.c b/examples/riot/tests_pkg_libcoap/main.c index 48b8254c..e1608714 100644 --- a/examples/riot/tests_pkg_libcoap/main.c +++ b/examples/riot/tests_pkg_libcoap/main.c @@ -1,10 +1,7 @@ /* - * Copyright (C) 2015 Freie Universität Berlin - * Copyright (C) 2018 Inria - * - * 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. + * SPDX-FileCopyrightText: 2015 Freie Universität Berlin + * SPDX-FileCopyrightText: 2018 Inria + * SPDX-License-Identifier: LGPL-2.1-only */ /** @@ -30,8 +27,7 @@ #define MAIN_QUEUE_SIZE (8) static msg_t _main_msg_queue[MAIN_QUEUE_SIZE]; -int -main(void) +int main(void) { /* we need a message queue for the thread running the shell in order to * receive potentially fast incoming networking packets */ diff --git a/src/coap_asn1.c b/src/coap_asn1.c index 788387b5..8ef55912 100644 --- a/src/coap_asn1.c +++ b/src/coap_asn1.c @@ -72,7 +72,7 @@ asn1_tag_c(const uint8_t **ptr, size_t *plen, int *constructed, int *cls) { tag = (tag << 7) + (byte & 0x7F); (*plen)--; (*ptr)++; - if (*plen == 0 || tag > (INT_MAX >> 7)) + if (*plen == 0 || (uint32_t)tag > (INT_MAX >> 7)) return COAP_ASN1_FAIL; byte = (**ptr); }