21#if COAP_CLIENT_SUPPORT == 0
22#error For Proxy support, COAP_CLIENT_SUPPORT must be set
24#if COAP_SERVER_SUPPORT == 0
25#error For Proxy support, COAP_SERVER_SUPPORT must be set
29#define strcasecmp _stricmp
30#define strncasecmp _strnicmp
45 if (proxy_req->proxy_cache) {
46 assert(proxy_req->proxy_cache->ref);
47 proxy_req->proxy_cache->ref--;
48 if (proxy_req->proxy_cache->ref == 0) {
49 PROXY_CACHE_DELETE(proxy_entry->rsp_cache, proxy_req->proxy_cache);
53 proxy_req->proxy_cache = NULL;
57 for (i = 0; i < proxy_entry->req_count; i++) {
58 if (&proxy_entry->req_list[i] == proxy_req) {
59 if (proxy_entry->req_count > 1) {
60 memmove(&proxy_entry->req_list[i], &proxy_entry->req_list[i+1],
61 (proxy_entry->req_count-i-1) *
sizeof(proxy_entry->req_list[0]));
63 proxy_entry->req_count--;
73 for (i = 0; i < proxy_entry->req_count; i++) {
74 coap_proxy_req_t *proxy_req = &proxy_entry->req_list[i];
93 coap_log_debug(
"Cannot add token to incoming proxy response PDU\n");
97 coap_log_info(
"Failed to send PDU with 5.02 gateway issue\n");
101 coap_proxy_del_req(proxy_entry, proxy_req);
111 for (i = 0; i < context->proxy_list_count; i++) {
114 (
void *)&context->proxy_list[i]);
115 coap_proxy_cleanup_entry(&context->proxy_list[i], 0);
122 if (proxy_entry && proxy_entry->ongoing) {
126 LL_FOREACH(proxy_entry->ongoing->lg_crcv, lg_crcv) {
146 for (i = 0; i < context->proxy_list_count; i++) {
149 if (coap_proxy_check_observe(proxy_entry))
152 if (proxy_entry->ongoing && proxy_entry->idle_timeout_ticks) {
153 if (proxy_entry->last_used + proxy_entry->idle_timeout_ticks <= now) {
155 if (coap_proxy_remove_association(proxy_entry->ongoing, 0))
158 if (*tim_rem > proxy_entry->last_used + proxy_entry->idle_timeout_ticks - now) {
159 *tim_rem = proxy_entry->last_used + proxy_entry->idle_timeout_ticks - now;
169coap_get_uri_proxy_scheme_info(
const coap_pdu_t *request,
177 strncasecmp(opt_val,
"coaps+tcp", 9) == 0) {
180 }
else if (opt_len == 8 &&
181 strncasecmp(opt_val,
"coap+tcp", 8) == 0) {
184 }
else if (opt_len == 5 &&
185 strncasecmp(opt_val,
"coaps", 5) == 0) {
188 }
else if (opt_len == 4 &&
189 strncasecmp(opt_val,
"coap", 4) == 0) {
192 }
else if (opt_len == 7 &&
193 strncasecmp(opt_val,
"coap+ws", 7) == 0) {
196 }
else if (opt_len == 8 &&
197 strncasecmp(opt_val,
"coaps+ws", 8) == 0) {
202 opt_len, opt_len, opt_val);
244 coap_log_warn(
"coap+tcp URI scheme not supported for proxy\n");
250 coap_log_warn(
"coaps+tcp URI scheme not supported for proxy\n");
256 coap_log_warn(
"coap+ws URI scheme not supported for proxy\n");
262 coap_log_warn(
"coaps+ws URI scheme not supported for proxy\n");
282 size_t proxy_list_count = session->
context->proxy_list_count;
287 *proxy_entry_created = 0;
293 if (session->proxy_entry) {
294 for (i = 0; i < proxy_list_count; i++) {
295 if (&proxy_list[i] == session->proxy_entry) {
296 if (session->proxy_entry->ongoing) {
297 memset(server_use, 0,
sizeof(*server_use));
298 return session->proxy_entry;
310 memcpy(server_use, &server_list->
entry[server_list->
next_entry],
sizeof(*server_use));
312 memset(server_use, 0,
sizeof(*server_use));
315 switch (server_list->
type) {
330 if (!coap_get_uri_proxy_scheme_info(request, proxy_scheme, &server_use->
uri)) {
345 &server_use->
uri) < 0) {
353 if (!(proxy_scheme || proxy_uri)) {
375 for (i = 0; i < proxy_list_count; i++) {
377 proxy_list[i].uri.port == server_use->
uri.
port &&
378 proxy_list[i].uri.scheme == server_use->
uri.
scheme) {
381 return &proxy_list[i];
383 if (proxy_list[i].incoming == session) {
385 return &proxy_list[i];
394 if (new_proxy_list == NULL) {
398 session->
context->proxy_list = proxy_list = new_proxy_list;
399 memset(&proxy_list[i], 0,
sizeof(proxy_list[i]));
402 proxy_list[i].uri = server_use->
uri;
405 if (!proxy_list[i].uri_host_keep) {
409 memcpy(proxy_list[i].uri_host_keep, server_use->
uri.
host.
s,
411 proxy_list[i].uri.host.s = proxy_list[i].uri_host_keep;
413 proxy_list[i].uri.path.s = NULL;
414 proxy_list[i].uri.path.length = 0;
415 proxy_list[i].uri.query.s = NULL;
416 proxy_list[i].uri.query.length = 0;
419 proxy_list[i].incoming = session;
421 *proxy_entry_created = 1;
422 session->
context->proxy_list_count++;
425 session->proxy_entry = &proxy_list[i];
426 return &proxy_list[i];
430coap_proxy_remove_association(
coap_session_t *session,
int send_failure) {
435 size_t proxy_list_count = session->
context->proxy_list_count;
437 for (i = 0; i < proxy_list_count; i++) {
441 for (j = 0; j < proxy_entry->req_count; j++) {
442 coap_proxy_req_t *proxy_req = &proxy_entry->req_list[j];
444 if (proxy_req->incoming == session) {
445 coap_proxy_del_req(proxy_entry, proxy_req);
449 if (proxy_entry->incoming == session) {
453 proxy_entry->ongoing = NULL;
459 if (proxy_entry->ongoing == session) {
462 coap_proxy_cleanup_entry(proxy_entry, send_failure);
463 ongoing = proxy_entry->ongoing;
464 coap_log_debug(
"* %s: proxy_entry %p released (rem count = %zd)\n",
467 session->
context->proxy_list_count - 1);
468 if (proxy_list_count-i > 1) {
469 memmove(&proxy_list[i],
471 (proxy_list_count-i-1) *
sizeof(proxy_list[0]));
473 session->
context->proxy_list_count--;
492 static char client_sni[256];
494 int proxy_entry_created;
496 proxy_entry = coap_proxy_get_session(session, request, response, server_list,
497 &server_use, &proxy_entry_created);
503 if (!proxy_entry->ongoing) {
517 if (info_list == NULL) {
519 coap_proxy_remove_association(session, 0);
522 proto = info_list->
proto;
523 memcpy(&dst, &info_list->
addr,
sizeof(dst));
526#if COAP_AF_UNIX_SUPPORT
535 "/tmp/coap-pr-cl-%" PRIu64, (uint64_t)now);
538 fprintf(stderr,
"coap_address_set_unix_domain: %s: failed\n",
544 local_addr = &bind_addr;
548 snprintf(client_sni,
sizeof(client_sni),
"%*.*s", (
int)server_use.
uri.
host.
length,
555#if COAP_OSCORE_SUPPORT
557 proxy_entry->ongoing =
562 proxy_entry->ongoing =
564#if COAP_OSCORE_SUPPORT
571#if COAP_OSCORE_SUPPORT
575 proxy_entry->ongoing =
580 proxy_entry->ongoing =
584 coap_log_warn(
"Proxy: (D)TLS not configured for secure session\n");
591 proxy_entry->ongoing =
596 proxy_entry->ongoing =
601 proxy_entry->ongoing =
604#if COAP_OSCORE_SUPPORT
615 if (proxy_entry->ongoing == NULL) {
617 coap_proxy_remove_association(session, 0);
620 if (proxy_entry_created) {
621 coap_log_debug(
"* %s: proxy_entry %p created (tot count = %zd)\n",
624 session->
context->proxy_list_count);
626 }
else if (proxy_entry->ongoing->session_failed) {
642static coap_proxy_req_t *
646 for (i = 0; i < proxy_entry->req_count; i++) {
647 if (proxy_entry->req_list[i].incoming == session) {
648 return &proxy_entry->req_list[i];
662 coap_proxy_req_t *proxy_req,
int replace_mid) {
678 resp_pdu->
mid = rcvd->
mid;
680 uint16_t media_type = 0;
688 assert(size == total);
692 coap_log_debug(
"coap_proxy_call_response_handler: copy data error\n");
715 media_type, maxage, etag, body->
length,
717 coap_proxy_free_response_data,
719 coap_log_debug(
"coap_proxy_call_response_handler: add data error\n");
724 session->
context->proxy_response_handler(session,
727 proxy_req->cache_key),
735 if (fwd_pdu != resp_pdu) {
758 ret = coap_proxy_forward_request_lkd(session,
793 coap_proxy_req_t *proxy_req = NULL;
801 coap_proxy_cache_t *proxy_cache = NULL;
804 proxy_entry = coap_proxy_get_ongoing_session(session, request, response,
812 if (obs_opt && session->
context->proxy_response_handler) {
818 coap_proxy_ignore_options,
819 sizeof(coap_proxy_ignore_options)/
sizeof(coap_proxy_ignore_options[0]));
824 PROXY_CACHE_FIND(proxy_entry->rsp_cache, cache_key_l, proxy_cache);
834 proxy_req = coap_proxy_get_req(proxy_entry, session);
843 assert(proxy_cache->ref);
845 if (proxy_cache->ref > 0) {
846 goto return_cached_info;
849 if (proxy_req->proxy_cache->ref == 0) {
850 PROXY_CACHE_DELETE(proxy_entry->rsp_cache, proxy_req->proxy_cache);
854 proxy_req->proxy_cache = NULL;
859 goto return_cached_info;
862 goto return_cached_info;
868 coap_proxy_req_t *new_req_list;
871 (proxy_entry->req_count + 1)*
sizeof(coap_proxy_req_t));
873 if (new_req_list == NULL) {
876 proxy_entry->req_list = new_req_list;
877 proxy_req = &new_req_list[proxy_entry->req_count];
878 memset(proxy_req, 0,
sizeof(coap_proxy_req_t));
883 if (proxy_req->token_used == NULL) {
887 proxy_req->resource = resource;
888 proxy_req->incoming = session;
889 proxy_req->cache_key = cache_key;
890 proxy_req->proxy_cache = proxy_cache;
891 proxy_entry->req_count++;
892 }
else if (obs_opt) {
894 memcpy(token, proxy_req->token_used->s, proxy_req->token_used->length);
895 token_len = proxy_req->token_used->length;
901 if (proxy_req->token_used == NULL) {
909 goto return_cached_info;
913 switch (server_list->
type) {
939 switch (opt_iter.
number) {
995 assert(size == total);
1005 memcpy(body_data->
s, data, size);
1007 coap_proxy_release_body_data, body_data)) {
1032 coap_proxy_call_response_handler(session, request, proxy_cache->rsp_pdu,
1033 &r_token, proxy_req, 1);
1035 coap_proxy_del_req(proxy_entry, proxy_req);
1039struct coap_proxy_req_t *
1044 size_t proxy_list_count = ongoing->
context->proxy_list_count;
1050 for (i = 0; i < proxy_list_count; i++) {
1051 l_proxy_entry = &proxy_list[i];
1052 if (l_proxy_entry->ongoing == ongoing) {
1053 for (j = 0; j < l_proxy_entry->req_count; j++) {
1057 *proxy_entry = l_proxy_entry;
1058 return &l_proxy_entry->req_list[j];
1073 ret = coap_proxy_forward_response_lkd(session,
1087 const uint8_t *data;
1102 struct coap_proxy_req_t *proxy_req = NULL;
1104 proxy_req = coap_proxy_map_outgoing_request(session, received, &proxy_entry);
1105 if (!proxy_req || proxy_req->incoming->server_list) {
1106 coap_log_warn(
"Unknown proxy ongoing session response received - ignored\n");
1110 req_pdu = proxy_req->pdu;
1112 resource = proxy_req->resource;
1113 incoming = proxy_req->incoming;
1115 coap_log_debug(
"** process upstream incoming %d.%02d response:\n",
1120 assert(size == total);
1126 memcpy(body_data->
s, data, size);
1127 data = body_data->
s;
1143 coap_log_debug(
"cannot add token to ongoing proxy response PDU\n");
1152 switch (opt_iter.
number) {
1185 media_type, maxage, etag, size, data,
1186 coap_proxy_release_body_data,
1193 *cache_key = proxy_req->cache_key;
1200 if (option == NULL && proxy_entry->req_count) {
1202 proxy_req->cache_key = NULL;
1203 coap_proxy_del_req(proxy_entry, proxy_req);
1212 void *body_data, coap_proxy_req_t *proxy_req,
1224 coap_proxy_cache_t *proxy_cache;
1231 if (proxy_req->proxy_cache) {
1233 proxy_cache = proxy_req->proxy_cache;
1236 if (proxy_cache == NULL) {
1239 memset(proxy_cache, 0,
sizeof(coap_proxy_cache_t));
1242 coap_proxy_ignore_options,
1243 sizeof(coap_proxy_ignore_options)/
sizeof(coap_proxy_ignore_options[0]));
1248 memcpy(&proxy_cache->cache_req, cache_key_l,
1249 sizeof(proxy_cache->cache_req));
1253 proxy_req->proxy_cache = proxy_cache;
1255 PROXY_CACHE_ADD(proxy_entry->rsp_cache, proxy_cache);
1264 proxy_cache->etag = 0;
1278 for (i = 0; i < proxy_entry->req_count; i++) {
1279 if (proxy_entry->req_list[i].proxy_cache == proxy_cache) {
1280 proxy_req = &proxy_entry->req_list[i];
1282 if (coap_proxy_call_response_handler(proxy_req->incoming, proxy_req->pdu,
1294 ret = coap_proxy_call_response_handler(proxy_req->incoming, proxy_req->pdu,
1295 rcvd, &token, proxy_req, 0);
1320 coap_log_err(
"coap_proxy_local_write: Unknown or Proxy resource not defined\n");
1328 coap_log_err(
"coap_proxy_local_write: Could not create response PDU\n");
1344 if (!coap_proxy_forward_request_lkd(session, pdu, response, resource,
1345 NULL, session->server_list)) {
1346 coap_log_debug(
"coap_proxy_local_write: Failed to forward PDU\n");
1361 session = coap_new_client_session_proxy_lkd(ctx, server_list);
1375#if COAP_IPV6_SUPPORT
1376 remote.
s = (
const uint8_t *)
"::1";
1377#elif COAP_IPV4_SUPPORT
1378 remote.
s = (
const uint8_t *)
"127.0.0.1";
1380 coap_log_warn(
"coap_new_client_session_proxy: No IPv4 or IPv6 support\n");
1383 remote.
length = strlen((
const char *)remote.
s);
1390 coap_log_warn(
"coap_new_client_session_proxy: Unable to resolve IP address\n");
1397 session->server_list = server_list;
int coap_address_set_unix_domain(coap_address_t *addr, const uint8_t *host, size_t host_len)
Copy the parsed unix domain host into coap_address_t structure translating %2F into / on the way.
void coap_free_address_info(coap_addr_info_t *info)
Free off the one or more linked sets of coap_addr_info_t returned from coap_resolve_address_info().
int coap_is_af_unix(const coap_address_t *a)
Checks if given address a denotes a AF_UNIX address.
coap_addr_info_t * coap_resolve_address_info(const coap_str_const_t *address, uint16_t port, uint16_t secure_port, uint16_t ws_port, uint16_t ws_secure_port, int ai_hints_flags, int scheme_hint_bits, coap_resolve_type_t type)
Resolve the specified address into a set of coap_address_t that can be used to bind() (local) or conn...
@ COAP_RESOLVE_TYPE_REMOTE
remote side of session
#define COAP_UNIX_PATH_MAX
struct coap_proxy_list_t coap_proxy_list_t
Proxy information.
Library specific build wrapper for coap_internal.h.
void * coap_realloc_type(coap_memory_tag_t type, void *p, size_t size)
Reallocates a chunk p of bytes created by coap_malloc_type() or coap_realloc_type() and returns a poi...
void * coap_malloc_type(coap_memory_tag_t type, size_t size)
Allocates a chunk of size bytes and returns a pointer to the newly allocated memory.
void coap_free_type(coap_memory_tag_t type, void *p)
Releases the memory that was allocated by coap_malloc_type().
uint8_t coap_opt_t
Use byte-oriented access methods here because sliding a complex struct coap_opt_t over the data buffe...
coap_uri_scheme_t
The scheme specifiers.
@ COAP_URI_SCHEME_COAPS_WS
@ COAP_URI_SCHEME_COAPS_TCP
@ COAP_URI_SCHEME_COAP_TCP
@ COAP_URI_SCHEME_COAP_WS
coap_mid_t coap_send_rst_lkd(coap_session_t *session, const coap_pdu_t *request)
Sends an RST message with code 0 for the specified request to dst.
coap_mid_t coap_send_lkd(coap_session_t *session, coap_pdu_t *pdu)
Sends a CoAP message to given peer.
coap_mid_t coap_send_ack_lkd(coap_session_t *session, const coap_pdu_t *request)
Sends an ACK message with code 0 for the specified request to dst.
int coap_add_data_large_response_lkd(coap_resource_t *resource, coap_session_t *session, const coap_pdu_t *request, coap_pdu_t *response, const coap_string_t *query, uint16_t media_type, int maxage, uint64_t etag, size_t length, const uint8_t *data, coap_release_large_data_t release_func, void *app_ptr)
Associates given data with the response pdu that is passed as fourth parameter.
int coap_add_data_large_request_lkd(coap_session_t *session, coap_pdu_t *pdu, size_t length, const uint8_t *data, coap_release_large_data_t release_func, void *app_ptr)
Associates given data with the pdu that is passed as second parameter.
void coap_delete_cache_key(coap_cache_key_t *cache_key)
Delete the cache-key.
coap_cache_key_t * coap_cache_derive_key_w_ignore(const coap_session_t *session, const coap_pdu_t *pdu, coap_cache_session_based_t session_based, const uint16_t *ignore_options, size_t ignore_count)
Calculates a cache-key for the given CoAP PDU.
@ COAP_CACHE_NOT_SESSION_BASED
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
#define COAP_TICKS_PER_SECOND
Use ms resolution on POSIX systems.
#define COAP_MAX_DELAY_TICKS
uint16_t coap_new_message_id_lkd(coap_session_t *session)
Returns a new message id and updates session->tx_mid accordingly.
void coap_ticks(coap_tick_t *)
Returns the current value of an internal tick counter.
@ COAP_RESPONSE_FAIL
Response not liked - send CoAP RST packet.
@ COAP_RESPONSE_OK
Response is fine.
unsigned int coap_decode_var_bytes(const uint8_t *buf, size_t len)
Decodes multiple-length byte sequences.
uint64_t coap_decode_var_bytes8(const uint8_t *buf, size_t len)
Decodes multiple-length byte sequences.
#define coap_lock_callback_ret_release(r, c, func, failed)
Dummy for no thread-safe code.
#define coap_lock_unlock(c)
Dummy for no thread-safe code.
#define coap_lock_lock(c, failed)
Dummy for no thread-safe code.
#define coap_lock_check_locked(c)
Dummy for no thread-safe code.
#define coap_log_debug(...)
void coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu)
Display the contents of the specified pdu.
const char * coap_session_str(const coap_session_t *session)
Get session description.
#define coap_log_info(...)
#define coap_log_warn(...)
#define coap_log_err(...)
#define COAP_OBSERVE_CANCEL
The value COAP_OBSERVE_CANCEL in a GET/FETCH request option COAP_OPTION_OBSERVE indicates that the ob...
#define COAP_OBSERVE_ESTABLISH
The value COAP_OBSERVE_ESTABLISH in a GET/FETCH request option COAP_OPTION_OBSERVE indicates a new ob...
coap_opt_t * coap_option_next(coap_opt_iterator_t *oi)
Updates the iterator oi to point to the next option.
coap_optlist_t * coap_new_optlist(uint16_t number, size_t length, const uint8_t *data)
Create a new optlist entry.
uint32_t coap_opt_length(const coap_opt_t *opt)
Returns the length of the given option.
coap_opt_iterator_t * coap_option_iterator_init(const coap_pdu_t *pdu, coap_opt_iterator_t *oi, const coap_opt_filter_t *filter)
Initializes the given option iterator oi to point to the beginning of the pdu's option list.
void coap_delete_optlist(coap_optlist_t *queue)
Removes all entries from the optlist_chain, freeing off their memory usage.
#define COAP_OPT_ALL
Pre-defined filter that includes all options.
int coap_add_optlist_pdu(coap_pdu_t *pdu, coap_optlist_t **options)
The current optlist of optlist_chain is first sorted (as per RFC7272 ordering requirements) and then ...
coap_opt_t * coap_check_option(const coap_pdu_t *pdu, coap_option_num_t number, coap_opt_iterator_t *oi)
Retrieves the first option of number number from pdu.
int coap_insert_optlist(coap_optlist_t **head, coap_optlist_t *node)
Adds optlist to the given optlist_chain.
const uint8_t * coap_opt_value(const coap_opt_t *opt)
Returns a pointer to the value of the given option.
coap_session_t * coap_new_client_session_oscore_psk_lkd(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto, coap_dtls_cpsk_t *psk_data, coap_oscore_conf_t *oscore_conf)
Creates a new client session to the designated server with PSK credentials as well as protecting the ...
coap_session_t * coap_new_client_session_oscore_lkd(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto, coap_oscore_conf_t *oscore_conf)
Creates a new client session to the designated server, protecting the data using OSCORE.
coap_session_t * coap_new_client_session_oscore_pki_lkd(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto, coap_dtls_pki_t *pki_data, coap_oscore_conf_t *oscore_conf)
Creates a new client session to the designated server with PKI credentials as well as protecting the ...
coap_pdu_t * coap_pdu_reference_lkd(coap_pdu_t *pdu)
Increment reference counter on a pdu to stop it prematurely getting freed off when coap_delete_pdu() ...
void coap_delete_pdu_lkd(coap_pdu_t *pdu)
Dispose of an CoAP PDU and free off associated storage.
size_t coap_pdu_encode_header(coap_pdu_t *pdu, coap_proto_t proto)
Compose the protocol specific header for the specified PDU.
coap_pdu_t * coap_pdu_duplicate_lkd(const coap_pdu_t *old_pdu, coap_session_t *session, size_t token_length, const uint8_t *token, coap_opt_filter_t *drop_options)
Duplicate an existing PDU.
coap_pdu_t * coap_const_pdu_reference_lkd(const coap_pdu_t *pdu)
Increment reference counter on a const pdu to stop it prematurely getting freed off when coap_delete_...
#define COAP_OPTION_URI_HOST
coap_pdu_code_t coap_pdu_get_code(const coap_pdu_t *pdu)
Gets the PDU code associated with pdu.
#define COAP_OPTION_BLOCK2
#define COAP_OPTION_CONTENT_FORMAT
#define COAP_OPTION_SIZE2
#define COAP_OPTION_BLOCK1
#define COAP_OPTION_Q_BLOCK1
#define COAP_OPTION_PROXY_SCHEME
#define COAP_DEFAULT_PORT
int coap_mid_t
coap_mid_t is used to store the CoAP Message ID of a CoAP PDU.
#define COAP_RESPONSE_CODE(N)
#define COAP_RESPONSE_CLASS(C)
coap_proto_t
CoAP protocol types.
coap_pdu_code_t
Set of codes available for a PDU.
#define COAP_OPTION_OSCORE
#define COAP_MEDIATYPE_TEXT_PLAIN
int coap_add_token(coap_pdu_t *pdu, size_t len, const uint8_t *data)
Adds token of length len to pdu.
#define COAP_OPTION_Q_BLOCK2
#define COAPS_DEFAULT_PORT
#define COAP_OPTION_URI_PORT
coap_pdu_t * coap_pdu_init(coap_pdu_type_t type, coap_pdu_code_t code, coap_mid_t mid, size_t size)
Creates a new CoAP PDU with at least enough storage space for the given size maximum message size.
int coap_get_data_large(const coap_pdu_t *pdu, size_t *len, const uint8_t **data, size_t *offset, size_t *total)
Retrieves the data from a PDU, with support for large bodies of data that spans multiple PDUs.
#define COAP_INVALID_MID
Indicates an invalid message id.
#define COAP_OPTION_MAXAGE
#define COAP_OPTION_PROXY_URI
#define COAP_OPTION_OBSERVE
coap_bin_const_t coap_pdu_get_token(const coap_pdu_t *pdu)
Gets the token associated with pdu.
COAP_API coap_session_t * coap_new_client_session_proxy(coap_context_t *context, coap_proxy_server_list_t *server_list)
Creates a new client session to use the proxy logic going to the defined upstream server.
COAP_API int coap_proxy_forward_request(coap_session_t *session, const coap_pdu_t *request, coap_pdu_t *response, coap_resource_t *resource, coap_cache_key_t *cache_key, coap_proxy_server_list_t *server_list)
Forward incoming request upstream to the next proxy/server.
int coap_verify_proxy_scheme_supported(coap_uri_scheme_t scheme)
Verify that the CoAP Scheme is supported for an ongoing proxy connection.
COAP_API coap_response_t coap_proxy_forward_response(coap_session_t *session, const coap_pdu_t *received, coap_cache_key_t **cache_key)
Forward the returning response back to the appropriate client.
@ COAP_PROXY_REVERSE_STRIP
Act as a reverse proxy, strip out proxy options.
@ COAP_PROXY_FORWARD_DYNAMIC
Act as a forward-dynamic proxy using the request's Proxy-Uri or Proxy-Scheme options to determine ser...
@ COAP_PROXY_REVERSE
Act as a reverse proxy.
@ COAP_PROXY_FORWARD_STATIC
Act as a forward-static proxy.
@ COAP_PROXY_FORWARD_DYNAMIC_STRIP
Act as a forward-dynamic proxy, strip out proxy options.
@ COAP_PROXY_FORWARD_STATIC_STRIP
Act as a forward-static proxy, strip out proxy options.
coap_session_t * coap_new_client_session_psk2_lkd(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto, coap_dtls_cpsk_t *setup_data)
Creates a new client session to the designated server with PSK credentials.
int coap_session_reconnect(coap_session_t *session)
Close the current session (if not already closed) and reconnect to server (client session only).
coap_session_t * coap_new_client_session_pki_lkd(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto, coap_dtls_pki_t *setup_data)
Creates a new client session to the designated server with PKI credentials.
coap_session_t * coap_new_client_session_lkd(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto)
Creates a new client session to the designated server.
size_t coap_session_max_pdu_size_lkd(const coap_session_t *session)
Get maximum acceptable PDU size.
void coap_session_release_lkd(coap_session_t *session)
Decrement reference counter on a session.
void coap_session_new_token(coap_session_t *session, size_t *len, uint8_t *data)
Creates a new token for use.
void coap_delete_bin_const(coap_bin_const_t *s)
Deletes the given const binary data and releases any memory allocated.
coap_binary_t * coap_new_binary(size_t size)
Returns a new binary object with at least size bytes storage allocated.
coap_bin_const_t * coap_new_bin_const(const uint8_t *data, size_t size)
Take the specified byte array (text) and create a coap_bin_const_t * Returns a new const binary objec...
void coap_delete_binary(coap_binary_t *s)
Deletes the given coap_binary_t object and releases any memory allocated.
#define coap_binary_equal(binary1, binary2)
Compares the two binary data for equality.
#define coap_string_equal(string1, string2)
Compares the two strings for equality.
void coap_delete_string(coap_string_t *s)
Deletes the given string and releases any memory allocated.
int coap_tcp_is_supported(void)
Check whether TCP is available.
int coap_tls_is_supported(void)
Check whether TLS is available.
int coap_ws_is_supported(void)
Check whether WebSockets is available.
int coap_dtls_is_supported(void)
Check whether DTLS is available.
int coap_proxy_is_supported(void)
Check whether Proxy code is available.
int coap_wss_is_supported(void)
Check whether Secure WebSockets is available.
int coap_split_proxy_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri)
Parses a given string into URI components.
int coap_uri_into_optlist(const coap_uri_t *uri, const coap_address_t *dst, coap_optlist_t **optlist_chain, int create_port_host_opt)
Takes a coap_uri_t and then adds CoAP options into the optlist_chain.
coap_string_t * coap_get_query(const coap_pdu_t *request)
Extract query string from request PDU according to escape rules in 6.5.8.
Resolved addresses information.
coap_proto_t proto
CoAP protocol to use.
coap_address_t addr
The address to connect / bind to.
Multi-purpose address abstraction.
CoAP binary data definition with const data.
size_t length
length of binary data
const uint8_t * s
read-only binary data
CoAP binary data definition.
The CoAP stack's global state is stored in a coap_context_t object.
coap_resource_t * proxy_uri_resource
can be used for handling proxy URI resources
coap_resource_t * unknown_resource
can be used for handling unknown resources
char * client_sni
If not NULL, SNI to use in client TLS setup.
char * client_sni
If not NULL, SNI to use in client TLS setup.
Structure to hold large body (many blocks) client receive information.
uint8_t observe_set
Set if this is an observe receive PDU.
Iterator to run through PDU options.
coap_option_num_t number
decoded option number
Representation of chained list of CoAP options to install.
coap_pdu_code_t code
request method (value 1–31) or response code (value 64-255)
coap_bin_const_t actual_token
Actual token in pdu.
coap_mid_t mid
message id, if any, in regular host byte order
size_t used_size
used bytes of storage for token, options and payload
coap_session_t * session
Session responsible for PDU or NULL.
coap_pdu_type_t type
message type
int track_client_session
If 1, track individual connections to upstream server, else 0 for all clients to be multiplexed over ...
coap_proxy_server_t * entry
Set of servers to connect to.
coap_proxy_t type
The proxy type.
unsigned int idle_timeout_secs
Proxy upstream session idle timeout (0 is no timeout).
size_t next_entry
Next server to use (% entry_count)
size_t entry_count
The number of servers in entry list.
coap_dtls_pki_t * dtls_pki
PKI configuration to use if not NULL.
coap_oscore_conf_t * oscore_conf
OSCORE configuration if not NULL.
coap_uri_t uri
host and port define the server, scheme method
coap_dtls_cpsk_t * dtls_cpsk
PSK configuration to use if not NULL.
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...
coap_proto_t proto
protocol used
coap_response_t last_con_handler_res
The result of calling the response handler of the last CON.
coap_context_t * context
session's context
CoAP string data definition with const data.
const uint8_t * s
read-only string data
size_t length
length of string
CoAP string data definition.
Representation of parsed URI.
enum coap_uri_scheme_t scheme
The parsed scheme specifier.
uint16_t port
The port in host byte order.
coap_str_const_t host
The host part of the URI.