libcoap 4.3.5-develop-f52fada
Loading...
Searching...
No Matches
coap_proxy_internal.h
Go to the documentation of this file.
1/*
2 * coap_proxy_internal.h -- Proxy functions for libcoap
3 *
4 * Copyright (C) 2024-2026 Jon Shallow <supjps-libcoap@jpshallow.com>
5 *
6 * SPDX-License-Identifier: BSD-2-Clause
7 *
8 * This file is part of the CoAP library libcoap. Please see README for terms
9 * of use.
10 */
11
16
17#ifndef COAP_PROXY_INTERNAL_H_
18#define COAP_PROXY_INTERNAL_H_
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24#if COAP_PROXY_SUPPORT
31
32/* Client <--> Proxy-Server | Proxy-Client <--> Server */
33
34typedef struct coap_proxy_cache_t {
35 UT_hash_handle hh;
36 coap_cache_key_t cache_req;
37 coap_pdu_t *req_pdu;
38 coap_pdu_t *rsp_pdu;
39 coap_tick_t expire;
40 uint64_t etag;
41 unsigned ref;
42} coap_proxy_cache_t;
43
44typedef struct coap_proxy_req_t {
45 struct coap_proxy_req_t *next;
46 coap_pdu_t *pdu;
47 coap_resource_t *resource;
48 coap_session_t *incoming;
49 coap_bin_const_t *token_used;
50 coap_cache_key_t *cache_key;
51 coap_proxy_cache_t *proxy_cache;
52 coap_mid_t mid;
53 unsigned doing_observe;
54} coap_proxy_req_t;
55
56struct coap_proxy_entry_t {
57 coap_session_t *ongoing;
58 coap_session_t *incoming;
59 coap_proxy_req_t *proxy_req;
60 coap_proxy_cache_t *rsp_cache; /* Response cache list */
61 uint8_t *uri_host_keep;
62 coap_uri_t uri;
63 int track_client_session;
66 coap_mid_t mid;
67 coap_tick_t req_start_ticks;
69 coap_tick_t idle_timeout_ticks;
72 coap_tick_t last_used;
73};
74
75typedef enum {
76 COAP_PROXY_SUBS_ALL,
77 COAP_PROXY_SUBS_TOKEN,
78 COAP_PROXY_SUBS_MID,
79} coap_proxy_subs_delete_t;
80
86void coap_proxy_cleanup(coap_context_t *context);
87
98int coap_proxy_check_timeouts(coap_context_t *context, coap_tick_t now,
99 coap_tick_t *tim_rem);
100
110int coap_proxy_remove_association(coap_session_t *session, coap_pdu_code_t failure_code);
111
137int coap_proxy_forward_request_lkd(coap_session_t *session,
138 const coap_pdu_t *request,
139 coap_pdu_t *response,
140 coap_resource_t *resource,
141 coap_cache_key_t *cache_key,
142 coap_proxy_server_list_t *server_list);
143
158coap_response_t coap_proxy_forward_response_lkd(coap_session_t *session,
159 const coap_pdu_t *received,
160 coap_cache_key_t **cache_key);
161
183coap_session_t *coap_new_client_session_proxy_lkd(coap_context_t *context,
184 coap_proxy_server_list_t *server_list);
185
186
209coap_proxy_entry_t *coap_proxy_fwd_add_client_session_lkd(coap_session_t *session,
210 const char *use_ip,
211 uint16_t use_port,
212 coap_proxy_server_list_t *server_list);
222coap_mid_t coap_proxy_local_write(coap_session_t *session, coap_pdu_t *pdu);
223
234struct coap_proxy_req_t *coap_proxy_map_outgoing_request(coap_session_t *ongoing,
235 const coap_pdu_t *received,
236 coap_proxy_entry_t **proxy_entry);
237
249void coap_proxy_process_incoming(coap_session_t *session,
250 coap_pdu_t *rcvd, void *body_free,
251 coap_proxy_req_t *proxy_req,
252 coap_proxy_entry_t *proxy_entry);
253
261void coap_proxy_del_req(coap_proxy_entry_t *proxy_entry, coap_proxy_req_t *proxy_req);
262
272void coap_delete_proxy_subscriber(coap_session_t *session, coap_bin_const_t *token,
273 coap_mid_t mid, coap_proxy_subs_delete_t type);
274
283void coap_proxy_log_entry(coap_session_t *incoming, const coap_pdu_t *pdu,
284 coap_bin_const_t *upstream_token, const char *type);
286
287#define PROXY_CACHE_ADD(e, obj) \
288 HASH_ADD(hh, (e), cache_req, sizeof((obj)->cache_req), (obj))
289
290#define PROXY_CACHE_DELETE(e, obj) \
291 HASH_DELETE(hh, (e), (obj))
292
293#define PROXY_CACHE_ITER(e, el, rtmp) \
294 HASH_ITER(hh, (e), el, rtmp)
295
296#define PROXY_CACHE_ITER_SAFE(e, el, rtmp) \
297 for ((el) = (e); (el) && ((rtmp) = (el)->hh.next, 1); (el) = (rtmp))
298
299#define PROXY_CACHE_FIND(e, k, res) { \
300 HASH_FIND(hh, (e), (k), sizeof(*k), (res)); \
301 }
302
303#endif /* COAP_PROXY_SUPPORT */
304
305#ifdef __cplusplus
306}
307#endif
308
309#endif /* COAP_PROXY_INTERNAL_H_ */
struct coap_cache_key_t coap_cache_key_t
struct coap_pdu_t coap_pdu_t
PDU information.
struct coap_proxy_entry_t coap_proxy_entry_t
Proxy information.
struct coap_resource_t coap_resource_t
struct coap_session_t coap_session_t
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
Definition coap_time.h:149
coap_response_t
Definition coap_net.h:51
int coap_mid_t
coap_mid_t is used to store the CoAP Message ID of a CoAP PDU.
Definition coap_pdu.h:184
coap_pdu_code_t
Set of codes available for a PDU.
Definition coap_pdu.h:248
struct coap_bin_const_t coap_bin_const_t
CoAP binary data definition with const data.
CoAP binary data definition with const data.
Definition coap_str.h:65
The CoAP stack's global state is stored in a coap_context_t object.
structure for CoAP PDUs
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...