mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #18519 from benpicco/coap_request_ctx_get_remote
gcoap: add remote sock_udp_ep_t to coap_request_ctx_t
This commit is contained in:
commit
b117171fcf
@ -53,7 +53,7 @@ void gcoap_forward_proxy_init(void);
|
||||
* @return -EINVAL if Proxy-Uri is malformed
|
||||
*/
|
||||
int gcoap_forward_proxy_request_process(coap_pkt_t *pkt,
|
||||
sock_udp_ep_t *client);
|
||||
const sock_udp_ep_t *client);
|
||||
|
||||
/**
|
||||
* @brief Finds the memo for an outstanding request within the
|
||||
|
@ -96,6 +96,12 @@
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#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
|
||||
@ -347,6 +353,18 @@ void *coap_request_ctx_get_context(const coap_request_ctx_t *ctx);
|
||||
*/
|
||||
uint32_t coap_request_ctx_get_tl_type(const coap_request_ctx_t *ctx);
|
||||
|
||||
/**
|
||||
* @brief Get the remote endpoint from which the request was received
|
||||
*
|
||||
* @note This is currently only implemented for GCoAP
|
||||
*
|
||||
* @param[in] ctx The request context
|
||||
*
|
||||
* @return Remote endpoint from which the request originated
|
||||
* @return NULL The request was not received via UDP
|
||||
*/
|
||||
const sock_udp_ep_t *coap_request_ctx_get_remote_udp(const coap_request_ctx_t *ctx);
|
||||
|
||||
/**
|
||||
* @brief Block1 helper struct
|
||||
*/
|
||||
|
@ -61,7 +61,7 @@ void gcoap_forward_proxy_init(void)
|
||||
gcoap_register_listener(&forward_proxy_listener);
|
||||
}
|
||||
|
||||
static client_ep_t *_allocate_client_ep(sock_udp_ep_t *ep)
|
||||
static client_ep_t *_allocate_client_ep(const sock_udp_ep_t *ep)
|
||||
{
|
||||
client_ep_t *cep;
|
||||
for (cep = _client_eps;
|
||||
@ -102,7 +102,7 @@ static ssize_t _forward_proxy_handler(coap_pkt_t *pdu, uint8_t *buf,
|
||||
size_t len, coap_request_ctx_t *ctx)
|
||||
{
|
||||
int pdu_len;
|
||||
sock_udp_ep_t *remote = coap_request_ctx_get_context(ctx);
|
||||
const sock_udp_ep_t *remote = coap_request_ctx_get_remote_udp(ctx);
|
||||
|
||||
pdu_len = gcoap_forward_proxy_request_process(pdu, remote);
|
||||
|
||||
@ -376,7 +376,7 @@ static int _gcoap_forward_proxy_via_coap(coap_pkt_t *client_pkt,
|
||||
}
|
||||
|
||||
int gcoap_forward_proxy_request_process(coap_pkt_t *pkt,
|
||||
sock_udp_ep_t *client) {
|
||||
const sock_udp_ep_t *client) {
|
||||
char *uri;
|
||||
uri_parser_result_t urip;
|
||||
ssize_t optlen = 0;
|
||||
|
@ -706,20 +706,13 @@ static size_t _handle_req(gcoap_socket_t *sock, coap_pkt_t *pdu, uint8_t *buf,
|
||||
}
|
||||
|
||||
ssize_t pdu_len;
|
||||
char *offset;
|
||||
|
||||
coap_request_ctx_t ctx = {
|
||||
.resource = resource,
|
||||
.tl_type = (uint32_t)sock->type,
|
||||
.remote = remote,
|
||||
};
|
||||
|
||||
if (coap_get_proxy_uri(pdu, &offset) > 0) {
|
||||
ctx.context = remote;
|
||||
}
|
||||
else {
|
||||
ctx.context = resource->context;
|
||||
}
|
||||
|
||||
pdu_len = resource->handler(pdu, buf, len, &ctx);
|
||||
if (pdu_len < 0) {
|
||||
pdu_len = gcoap_response(pdu, buf, len,
|
||||
|
@ -463,7 +463,6 @@ ssize_t coap_tree_handler(coap_pkt_t *pkt, uint8_t *resp_buf,
|
||||
else {
|
||||
coap_request_ctx_t ctx = {
|
||||
.resource = resource,
|
||||
.context = resource->context,
|
||||
};
|
||||
return resource->handler(pkt, resp_buf, resp_buf_len, &ctx);
|
||||
}
|
||||
@ -1244,7 +1243,7 @@ const char *coap_request_ctx_get_path(const coap_request_ctx_t *ctx)
|
||||
|
||||
void *coap_request_ctx_get_context(const coap_request_ctx_t *ctx)
|
||||
{
|
||||
return ctx->context;
|
||||
return ctx->resource->context;
|
||||
}
|
||||
|
||||
uint32_t coap_request_ctx_get_tl_type(const coap_request_ctx_t *ctx)
|
||||
@ -1256,3 +1255,13 @@ uint32_t coap_request_ctx_get_tl_type(const coap_request_ctx_t *ctx)
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
const sock_udp_ep_t *coap_request_ctx_get_remote_udp(const coap_request_ctx_t *ctx)
|
||||
{
|
||||
#ifdef MODULE_GCOAP
|
||||
return ctx->remote;
|
||||
#else
|
||||
(void)ctx;
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
@ -20,6 +20,11 @@
|
||||
#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" {
|
||||
@ -30,8 +35,6 @@ extern "C" {
|
||||
*/
|
||||
struct _coap_request_ctx {
|
||||
const coap_resource_t *resource; /**< resource of the request */
|
||||
void *context; /**< request context, needed to supply
|
||||
the remote for the forward proxy */
|
||||
#if defined(MODULE_GCOAP) || DOXYGEN
|
||||
/**
|
||||
* @brief transport the packet was received over
|
||||
@ -40,6 +43,7 @@ struct _coap_request_ctx {
|
||||
* cyclically include the @ref net_gcoap header.
|
||||
*/
|
||||
uint32_t tl_type;
|
||||
sock_udp_ep_t *remote; /**< remote endpoint of the request */
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -6,7 +6,7 @@ USEMODULE += embunit
|
||||
USEMODULE += sock_util
|
||||
|
||||
# make sure we have an implementation of sock_types.h
|
||||
USEMODULE += gnrc_sock_udp
|
||||
USEMODULE += sock_udp
|
||||
USEMODULE += gnrc_ipv6
|
||||
|
||||
USEMODULE += ipv4_addr
|
||||
|
@ -9,7 +9,7 @@ USEMODULE += fmt
|
||||
USEMODULE += gnrc_icmpv6_echo
|
||||
USEMODULE += gnrc_ipv6_default
|
||||
USEMODULE += netdev_default
|
||||
USEMODULE += gnrc_sock_udp
|
||||
USEMODULE += sock_udp
|
||||
USEMODULE += netstats_ipv6
|
||||
USEMODULE += netstats_l2
|
||||
USEMODULE += ps
|
||||
|
Loading…
Reference in New Issue
Block a user