From 1e854ec1873e8954c57b78e9b9cc2e0d6fc832fb Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Fri, 20 Oct 2023 13:47:20 +0200 Subject: [PATCH 1/2] coap: create typedef for CoAP methods --- sys/include/net/coap.h | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/sys/include/net/coap.h b/sys/include/net/coap.h index dca1f4bae0fd..7da367af581f 100644 --- a/sys/include/net/coap.h +++ b/sys/include/net/coap.h @@ -163,14 +163,20 @@ extern "C" { * @name CoAP method codes used in header * @{ */ -#define COAP_CLASS_REQ (0) -#define COAP_METHOD_GET (1) -#define COAP_METHOD_POST (2) -#define COAP_METHOD_PUT (3) -#define COAP_METHOD_DELETE (4) -#define COAP_METHOD_FETCH (5) -#define COAP_METHOD_PATCH (6) -#define COAP_METHOD_IPATCH (7) +#define COAP_CLASS_REQ (0) /**< Code Class for Request */ + +/** + * @brief CoAP method codes used in request + */ +typedef enum { + COAP_METHOD_GET = 1, /**< GET request (no paylod) */ + COAP_METHOD_POST = 2, /**< POST request (resource processes payload) */ + COAP_METHOD_PUT = 3, /**< PUT request (update resource with payload) */ + COAP_METHOD_DELETE = 4, /**< DELETE request (no payload, remove resource)*/ + COAP_METHOD_FETCH = 5, /**< FETCH request (RFC 8132) */ + COAP_METHOD_PATCH = 6, /**< PATCH request (RFC 8132) */ + COAP_METHOD_IPATCH = 7, /**< iPATCH request (RFC 8132) */ +} coap_method_t; /** @} */ /** From db3294a48125a54779606a4f8eb6a284839e3894 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Fri, 20 Oct 2023 13:51:35 +0200 Subject: [PATCH 2/2] nanocoap_sock: make use of coap_method_t --- sys/include/net/nanocoap_sock.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/include/net/nanocoap_sock.h b/sys/include/net/nanocoap_sock.h index aee225d2c472..9917996df885 100644 --- a/sys/include/net/nanocoap_sock.h +++ b/sys/include/net/nanocoap_sock.h @@ -205,7 +205,7 @@ typedef struct { nanocoap_sock_t *sock; /**< socket used for the request */ const char *path; /**< path on the server */ uint32_t blknum; /**< current block number */ - uint8_t method; /**< request method (GET, POST, PUT) */ + coap_method_t method; /**< request method (GET, POST, PUT) */ uint8_t blksize; /**< CoAP blocksize exponent */ } coap_block_request_t; @@ -580,7 +580,7 @@ ssize_t nanocoap_request(coap_pkt_t *pkt, const sock_udp_ep_t *local, static inline int nanocoap_block_request_connect_url(coap_block_request_t *ctx, nanocoap_sock_t *sock, const char *url, - uint8_t method, + coap_method_t method, coap_blksize_t blksize) { ctx->sock = sock;