1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

nanocoap: define coap_request_ctx_t for request handlers

This commit is contained in:
Benjamin Valentin 2022-04-15 21:16:41 +02:00
parent 6ba048f80c
commit 0898e499fc

View File

@ -240,6 +240,11 @@ typedef struct {
#endif
} coap_pkt_t;
/**
* @brief CoAP resource request handler context
*/
typedef struct _coap_request_ctx coap_request_ctx_t;
/**
* @brief Resource handler type
*
@ -254,7 +259,8 @@ typedef struct {
* For POST, PATCH and other non-idempotent methods, this is an additional
* requirement introduced by the contract of this type.
*/
typedef ssize_t (*coap_handler_t)(coap_pkt_t *pkt, uint8_t *buf, size_t len, void *context);
typedef ssize_t (*coap_handler_t)(coap_pkt_t *pkt, uint8_t *buf, size_t len,
coap_request_ctx_t *context);
/**
* @brief Coap blockwise request callback descriptor
@ -307,6 +313,38 @@ typedef const struct {
const size_t resources_numof; /**< number of entries in array */
} coap_resource_subtree_t;
/**
* @brief CoAP resource request handler context
*/
struct _coap_request_ctx {
const coap_resource_t *resource; /**< resource of the request */
void *context; /**< request context */
};
/**
* @brief Get resource path associated with a CoAP request
*
* @param[in] ctx The request context
*
* @return Resource path of the request
*/
static inline const char *coap_request_get_path(const coap_request_ctx_t *ctx)
{
return ctx->resource->path;
}
/**
* @brief Get resource context associated with a CoAP request
*
* @param[in] ctx The request context
*
* @return Resource context of the request
*/
static inline void *coap_request_get_context(const coap_request_ctx_t *ctx)
{
return ctx->context;
}
/**
* @brief Block1 helper struct
*/
@ -1953,7 +1991,7 @@ ssize_t coap_reply_simple(coap_pkt_t *pkt,
*/
extern ssize_t coap_well_known_core_default_handler(coap_pkt_t *pkt, \
uint8_t *buf, size_t len,
void *context);
coap_request_ctx_t *context);
/**@}*/
/**