libcoap 4.3.5-develop-daa4e05
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-2025 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
17#ifndef COAP_PROXY_INTERNAL_H_
18#define COAP_PROXY_INTERNAL_H_
19
20#include "coap_internal.h"
21
22#if COAP_PROXY_SUPPORT
30/* Client <--> Proxy-Server | Proxy-Client <--> Server */
31
32typedef struct coap_proxy_cache_t {
33 UT_hash_handle hh;
34 coap_cache_key_t cache_req;
35 coap_pdu_t *req_pdu;
36 coap_pdu_t *rsp_pdu;
37 coap_tick_t expire;
38 uint64_t etag;
39 unsigned ref;
40} coap_proxy_cache_t;
41
42typedef struct coap_proxy_req_t {
43 coap_pdu_t *pdu;
44 coap_resource_t *resource;
45 coap_session_t *incoming;
46 coap_bin_const_t *token_used;
47 coap_cache_key_t *cache_key;
48 coap_proxy_cache_t *proxy_cache;
49} coap_proxy_req_t;
50
51struct coap_proxy_list_t {
52 coap_session_t *ongoing;
53 coap_session_t *incoming;
54 coap_proxy_req_t *req_list;
55 size_t req_count;
56 coap_proxy_cache_t *rsp_cache; /* Response cache list */
57 coap_uri_t uri;
58 uint8_t *uri_host_keep;
59 coap_tick_t idle_timeout_ticks;
62 coap_tick_t last_used;
63};
64
70void coap_proxy_cleanup(coap_context_t *context);
71
82int coap_proxy_check_timeouts(coap_context_t *context, coap_tick_t now,
83 coap_tick_t *tim_rem);
84
93int coap_proxy_remove_association(coap_session_t *session, int send_failure);
94
120int coap_proxy_forward_request_lkd(coap_session_t *session,
121 const coap_pdu_t *request,
122 coap_pdu_t *response,
123 coap_resource_t *resource,
124 coap_cache_key_t *cache_key,
125 coap_proxy_server_list_t *server_list);
126
141coap_response_t coap_proxy_forward_response_lkd(coap_session_t *session,
142 const coap_pdu_t *received,
143 coap_cache_key_t **cache_key);
144
166coap_session_t *coap_new_client_session_proxy_lkd(coap_context_t *context,
167 coap_proxy_server_list_t *server_list);
168
169/*
170 * coap_proxy_local_write() is used to send the PDU for a session created by
171 * coap_new_client_session_proxy() into the proxy logic for onward transmittion.
172 *
173 * @param session The coap_new_client_session_proxy() generated session.
174 * @param pdu The PDU presented to libcoap by coap_send().
175 *
176 * @return The MID used for the transmission, else COAP_INVALID_MID on failure.
177 */
178coap_mid_t coap_proxy_local_write(coap_session_t *session, coap_pdu_t *pdu);
179
180/*
181 * coap_proxy_map_outgoing_request() takes the upstream proxy client session and
182 * maps it back to the incoming request.
183 *
184 * @param ongoing The upstream proxy client session.
185 * @param received The received PDU from the upstream server.
186 * @param proxy_entry Updated with the proxy server entry definition if not NULL.
187 *
188 * @return The proxy request information, or NULL on mapping failure.
189 */
190struct coap_proxy_req_t *coap_proxy_map_outgoing_request(coap_session_t *ongoing,
191 const coap_pdu_t *received,
192 coap_proxy_list_t **proxy_entry);
193
194/*
195 * coap_proxy_process_incoming() handles the Server response back to P-Client.
196 *
197 * @param session The upstream proxy client session.
198 * @param rcvd The received PDU from the upstream server.
199 * @param body_data The data to be freed off once all responses sent for rcvd,
200 * @param proxy_req The current proxy request object
201 * @param proxy_entry The current proxy entry object
202 *
203 * @return The proxy request information, or NULL on mapping failure.
204 */
205void coap_proxy_process_incoming(coap_session_t *session,
206 coap_pdu_t *rcvd, void *body_free,
207 coap_proxy_req_t *proxy_req,
208 coap_proxy_list_t *proxy_entry);
211#define PROXY_CACHE_ADD(e, obj) \
212 HASH_ADD(hh, (e), cache_req, sizeof((obj)->cache_req), (obj))
213
214#define PROXY_CACHE_DELETE(e, obj) \
215 HASH_DELETE(hh, (e), (obj))
216
217#define PROXY_CACHE_ITER(e, el, rtmp) \
218 HASH_ITER(hh, (e), el, rtmp)
219
220#define PROXY_CACHE_ITER_SAFE(e, el, rtmp) \
221 for ((el) = (e); (el) && ((rtmp) = (el)->hh.next, 1); (el) = (rtmp))
222
223#define PROXY_CACHE_FIND(e, k, res) { \
224 HASH_FIND(hh, (e), (k), sizeof(*k), (res)); \
225 }
226
227#endif /* COAP_PROXY_SUPPORT */
228#endif /* COAP_PROXY_INTERNAL_H_ */
struct coap_proxy_list_t coap_proxy_list_t
Proxy information.
Pulls together all the internal only header files.
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
Definition coap_time.h:143
coap_response_t
Definition coap_net.h:48
int coap_mid_t
coap_mid_t is used to store the CoAP Message ID of a CoAP PDU.
Definition coap_pdu.h:263
CoAP binary data definition with const data.
Definition coap_str.h:64
The CoAP stack's global state is stored in a coap_context_t object.
structure for CoAP PDUs
Abstraction of resource that can be attached to coap_context_t.
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
Representation of parsed URI.
Definition coap_uri.h:68