20#ifndef INET6_ADDRSTRLEN
21#define INET6_ADDRSTRLEN 46
24#if COAP_CLIENT_SUPPORT == 0
25#error For Proxy support, COAP_CLIENT_SUPPORT must be set
27#if COAP_SERVER_SUPPORT == 0
28#error For Proxy support, COAP_SERVER_SUPPORT must be set
32#define strcasecmp _stricmp
33#define strncasecmp _strnicmp
56 scratch_d[0] =
'\000';
58 size = strlen(scratch_d);
59 snprintf(&scratch_d[size],
sizeof(scratch_d)-size,
62 scratch_u[0] =
'\000';
64 for (i = 0; i < upstream_token->
length; i++) {
65 size = strlen(scratch_u);
66 snprintf(&scratch_u[size],
sizeof(scratch_u)-size,
67 "%02x", upstream_token->
s[i]);
71 coap_log_debug(
" proxy %-4s %s {%s}-{%s} \"%s\"%s\n", type, addr, scratch_u, scratch_d,
80 coap_proxy_log_entry(proxy_req->incoming, proxy_req->pdu, proxy_req->token_used,
"del");
85 if (proxy_req->proxy_cache) {
92 url ? (
char *)url->
s :
"???",
93 proxy_req->proxy_cache->ref);
96 assert(proxy_req->proxy_cache->ref);
97 proxy_req->proxy_cache->ref--;
98 if (proxy_req->proxy_cache->ref == 0) {
99 PROXY_CACHE_DELETE(proxy_entry->rsp_cache, proxy_req->proxy_cache);
103 proxy_req->proxy_cache = NULL;
105 if (proxy_req->doing_observe) {
106 assert(proxy_req->incoming->ref_proxy_subs);
107 proxy_req->incoming->ref_proxy_subs--;
108 proxy_req->doing_observe = 0;
112 proxy_req->incoming = NULL;
114 LL_DELETE(proxy_entry->proxy_req, proxy_req);
120 coap_proxy_req_t *proxy_req, *treq;
122 LL_FOREACH_SAFE(proxy_entry->proxy_req, proxy_req, treq) {
140 coap_log_debug(
"Cannot add token to incoming proxy response PDU\n");
144 coap_log_info(
"Failed to send PDU with 5.02 gateway issue\n");
148 coap_proxy_del_req(proxy_entry, proxy_req);
157 for (i = 0; i < context->proxy_list_count; i++) {
160 (
void *)&context->proxy_list[i]);
161 coap_proxy_cleanup_entry(&context->proxy_list[i], 0);
168 if (proxy_entry && proxy_entry->ongoing) {
172 LL_FOREACH(proxy_entry->ongoing->lg_crcv, lg_crcv) {
192 for (i = 0; i < context->proxy_list_count; i++) {
195 if (coap_proxy_check_observe(proxy_entry))
198 if (proxy_entry->ongoing && proxy_entry->idle_timeout_ticks) {
199 if (proxy_entry->last_used + proxy_entry->idle_timeout_ticks <= now) {
201 if (coap_proxy_remove_association(proxy_entry->ongoing, 0))
204 if (*tim_rem > proxy_entry->last_used + proxy_entry->idle_timeout_ticks - now) {
205 *tim_rem = proxy_entry->last_used + proxy_entry->idle_timeout_ticks - now;
215coap_get_uri_proxy_scheme_info(
const coap_pdu_t *request,
223 strncasecmp(opt_val,
"coaps+tcp", 9) == 0) {
226 }
else if (opt_len == 8 &&
227 strncasecmp(opt_val,
"coap+tcp", 8) == 0) {
230 }
else if (opt_len == 5 &&
231 strncasecmp(opt_val,
"coaps", 5) == 0) {
234 }
else if (opt_len == 4 &&
235 strncasecmp(opt_val,
"coap", 4) == 0) {
238 }
else if (opt_len == 7 &&
239 strncasecmp(opt_val,
"coap+ws", 7) == 0) {
242 }
else if (opt_len == 8 &&
243 strncasecmp(opt_val,
"coaps+ws", 8) == 0) {
248 opt_len, opt_len, opt_val);
290 coap_log_warn(
"coap+tcp URI scheme not supported for proxy\n");
296 coap_log_warn(
"coaps+tcp URI scheme not supported for proxy\n");
302 coap_log_warn(
"coap+ws URI scheme not supported for proxy\n");
308 coap_log_warn(
"coaps+ws URI scheme not supported for proxy\n");
324 switch ((
int)proxy_type) {
346 coap_log_warn(
"Proxy old proxy_type 0x%u unknow\n", proxy_type);
362 size_t proxy_list_count = session->
context->proxy_list_count;
368 *proxy_entry_created = 0;
374 if (session->proxy_entry) {
375 for (i = 0; i < proxy_list_count; i++) {
376 if (&proxy_list[i] == session->proxy_entry) {
377 if (session->proxy_entry->ongoing) {
378 memset(server_use, 0,
sizeof(*server_use));
379 return session->proxy_entry;
391 memcpy(server_use, &server_list->
entry[server_list->
next_entry],
sizeof(*server_use));
393 memset(server_use, 0,
sizeof(*server_use));
396 proxy_type = coap_proxy_map_type(server_list->
type);
405 if (!coap_get_uri_proxy_scheme_info(request, proxy_scheme, &server_use->
uri)) {
420 &server_use->
uri) < 0) {
428 if (!(proxy_scheme || proxy_uri)) {
446 for (i = 0; i < proxy_list_count; i++) {
448 proxy_list[i].uri.port == server_use->
uri.
port &&
449 proxy_list[i].uri.scheme == server_use->
uri.
scheme) {
452 return &proxy_list[i];
454 if (proxy_list[i].incoming == session) {
456 return &proxy_list[i];
465 if (new_proxy_list == NULL) {
469 session->
context->proxy_list = proxy_list = new_proxy_list;
470 memset(&proxy_list[i], 0,
sizeof(proxy_list[i]));
473 proxy_list[i].uri = server_use->
uri;
476 if (!proxy_list[i].uri_host_keep) {
480 memcpy(proxy_list[i].uri_host_keep, server_use->
uri.
host.
s,
482 proxy_list[i].uri.host.s = proxy_list[i].uri_host_keep;
484 proxy_list[i].uri.path.s = NULL;
485 proxy_list[i].uri.path.length = 0;
486 proxy_list[i].uri.query.s = NULL;
487 proxy_list[i].uri.query.length = 0;
490 proxy_list[i].incoming = session;
492 *proxy_entry_created = 1;
493 session->
context->proxy_list_count++;
496 session->proxy_entry = &proxy_list[i];
497 return &proxy_list[i];
501coap_proxy_remove_association(
coap_session_t *session,
int send_failure) {
505 size_t proxy_list_count = session->
context->proxy_list_count;
507 for (i = 0; i < proxy_list_count; i++) {
509 coap_proxy_req_t *proxy_req;
513 LL_FOREACH(proxy_entry->proxy_req, proxy_req) {
514 if (proxy_req->incoming == session) {
515 coap_proxy_del_req(proxy_entry, proxy_req);
519 if (proxy_entry->incoming == session) {
523 proxy_entry->ongoing = NULL;
529 if (proxy_entry->ongoing == session) {
532 coap_proxy_cleanup_entry(proxy_entry, send_failure);
533 ongoing = proxy_entry->ongoing;
534 coap_log_debug(
"* %s: proxy_entry %p released (rem count = %zd)\n",
537 session->
context->proxy_list_count - 1);
538 if (proxy_list_count-i > 1) {
539 memmove(&proxy_list[i],
541 (proxy_list_count-i-1) *
sizeof(proxy_list[0]));
543 session->
context->proxy_list_count--;
562 static char client_sni[256];
564 int proxy_entry_created;
566 proxy_entry = coap_proxy_get_session(session, request, response, server_list,
567 &server_use, &proxy_entry_created);
573 if (!proxy_entry->ongoing) {
587 if (info_list == NULL) {
589 coap_proxy_remove_association(session, 0);
592 proto = info_list->
proto;
593 memcpy(&dst, &info_list->
addr,
sizeof(dst));
601 coap_proxy_remove_association(session, 0);
608 coap_proxy_remove_association(session, 0);
609 coap_log_debug(
"* %s: mcast proxy forwarding only supported for 'coap'\n",
615#if COAP_AF_UNIX_SUPPORT
624 "/tmp/coap-pr-cl-%" PRIu64, (uint64_t)now);
627 fprintf(stderr,
"coap_address_set_unix_domain: %s: failed\n",
633 local_addr = &bind_addr;
637 snprintf(client_sni,
sizeof(client_sni),
"%*.*s", (
int)server_use.
uri.
host.
length,
644#if COAP_OSCORE_SUPPORT
646 proxy_entry->ongoing =
651 proxy_entry->ongoing =
653#if COAP_OSCORE_SUPPORT
660#if COAP_OSCORE_SUPPORT
664 proxy_entry->ongoing =
669 proxy_entry->ongoing =
673 coap_log_warn(
"Proxy: (D)TLS not configured for secure session\n");
680 proxy_entry->ongoing =
685 proxy_entry->ongoing =
690 proxy_entry->ongoing =
693#if COAP_OSCORE_SUPPORT
704 if (proxy_entry->ongoing == NULL) {
706 coap_proxy_remove_association(session, 0);
709 if (proxy_entry_created) {
710 coap_log_debug(
"* %s: proxy_entry %p created (tot count = %zd)\n",
713 session->
context->proxy_list_count);
715 }
else if (proxy_entry->ongoing->session_failed) {
731static coap_proxy_req_t *
732coap_proxy_get_req(
coap_proxy_list_t *proxy_entry, coap_proxy_cache_t *proxy_cache,
734 coap_proxy_req_t *proxy_req;
736 LL_FOREACH(proxy_entry->proxy_req, proxy_req) {
737 if (proxy_req->incoming == session && proxy_req->proxy_cache == proxy_cache) {
752 coap_proxy_req_t *proxy_req,
int replace_mid,
753 int remove_observe) {
763 if (remove_observe) {
780 if (proxy_req && proxy_req->pdu)
781 resp_pdu->
type = proxy_req->pdu->type;
787 resp_pdu->
mid = sent->
mid;
789 proxy_req->mid = resp_pdu->
mid;
798 uint16_t media_type = 0;
806 assert(size == total);
810 coap_log_debug(
"coap_proxy_call_response_handler: copy data error\n");
833 media_type, maxage, etag, body->
length,
835 coap_proxy_free_response_data,
837 coap_log_debug(
"coap_proxy_call_response_handler: add data error\n");
842 session->
context->proxy_response_handler(session,
845 proxy_req->cache_key),
853 if (fwd_pdu != resp_pdu) {
876 ret = coap_proxy_forward_request_lkd(session,
911 coap_proxy_req_t *proxy_req = NULL;
919 coap_proxy_cache_t *proxy_cache = NULL;
923 proxy_entry = coap_proxy_get_ongoing_session(session, request, response,
929 coap_proxy_log_entry(session, request, NULL,
"req");
932 if (obs_opt && session->
context->proxy_response_handler) {
937 coap_proxy_ignore_options,
938 sizeof(coap_proxy_ignore_options)/
sizeof(coap_proxy_ignore_options[0]));
943 PROXY_CACHE_FIND(proxy_entry->rsp_cache, cache_key_l, proxy_cache);
948 proxy_req = coap_proxy_get_req(proxy_entry, proxy_cache, session);
959 if (proxy_req->doing_observe) {
960 assert(proxy_req->incoming->ref_proxy_subs);
961 proxy_req->incoming->ref_proxy_subs--;
962 proxy_req->doing_observe = 0;
964 if (proxy_entry->proxy_req && !proxy_entry->proxy_req->next &&
965 proxy_req->token_used) {
968 coap_log_debug(
"coap_proxy_forward_request: Using coap_cancel_observe() to do Proxy OBSERVE cancellation\n");
970 memcpy(&tmp.
s, &proxy_req->token_used->s,
sizeof(tmp.
s));
971 tmp.
length = proxy_req->token_used->length;
977 goto return_cached_info;
984 coap_proxy_del_req(proxy_entry, proxy_req);
988 goto return_cached_info;
995 coap_proxy_del_req(proxy_entry, proxy_req);
999 goto return_cached_info;
1007 if (proxy_req == NULL) {
1010 memset(proxy_req, 0,
sizeof(coap_proxy_req_t));
1011 LL_PREPEND(proxy_entry->proxy_req, proxy_req);
1014 proxy_req->resource = resource;
1015 proxy_req->incoming = session;
1016 proxy_req->cache_key = cache_key;
1017 proxy_req->proxy_cache = proxy_cache;
1019 coap_proxy_log_entry(proxy_req->incoming, proxy_req->pdu, proxy_req->token_used,
"add");
1030 if (proxy_req->token_used == NULL) {
1033 goto return_cached_info;
1040 if (proxy_req->token_used == NULL) {
1047 proxy_type = coap_proxy_map_type(server_list->
type);
1064 if (
coap_is_mcast(&proxy_entry->ongoing->addr_info.remote)) {
1075 switch (opt_iter.
number) {
1128 assert(size == total);
1138 memcpy(body_data->
s, data, size);
1140 coap_proxy_release_body_data, body_data)) {
1146 coap_proxy_log_entry(proxy_req->incoming, proxy_req->pdu, proxy_req->token_used,
"fwd");
1166 if (obs_opt && !proxy_req->doing_observe) {
1173 proxy_req->doing_observe = 1;
1174 proxy_req->incoming->ref_proxy_subs++;
1180 coap_proxy_log_entry(session, request, &proxy_cache->rsp_pdu->actual_token,
"rspc");
1181 coap_proxy_call_response_handler(session, request, proxy_cache->rsp_pdu,
1182 &r_token, proxy_req, 1, obs_opt ? 0 : 1);
1184 coap_proxy_del_req(proxy_entry, proxy_req);
1193 size_t proxy_list_count = ongoing->
context->proxy_list_count;
1197 coap_proxy_req_t *proxy_req;
1199 for (i = 0; i < proxy_list_count; i++) {
1200 proxy_entry = &proxy_list[i];
1201 if (proxy_entry->ongoing == ongoing) {
1202 LL_FOREACH(proxy_entry->proxy_req, proxy_req) {
1206 *u_proxy_entry = proxy_entry;
1216 scratch[0] =
'\000';
1217 for (i = 0; i < rcv_token.
length; i++) {
1218 size = strlen(scratch);
1219 snprintf(&scratch[size],
sizeof(scratch)-size,
1220 "%02x", rcv_token.
s[i]);
1223 for (i = 0; i < proxy_list_count; i++) {
1224 proxy_entry = &proxy_list[i];
1225 LL_FOREACH(proxy_entry->proxy_req, proxy_req) {
1226 coap_proxy_log_entry(proxy_req->incoming, proxy_req->pdu, proxy_req->token_used,
"miss");
1240 ret = coap_proxy_forward_response_lkd(session,
1254 const uint8_t *data;
1269 coap_proxy_req_t *proxy_req = NULL;
1271 proxy_req = coap_proxy_map_outgoing_request(session, received, &proxy_entry);
1272 if (!proxy_req || proxy_req->incoming->server_list) {
1273 coap_log_warn(
"Unknown proxy ongoing session response received - ignored\n");
1277 req_pdu = proxy_req->pdu;
1279 resource = proxy_req->resource;
1280 incoming = proxy_req->incoming;
1282 coap_log_debug(
"** process upstream incoming %d.%02d response:\n",
1287 assert(size == total);
1293 memcpy(body_data->
s, data, size);
1294 data = body_data->
s;
1310 coap_log_debug(
"cannot add token to ongoing proxy response PDU\n");
1319 switch (opt_iter.
number) {
1352 media_type, maxage, etag, size, data,
1353 coap_proxy_release_body_data,
1360 *cache_key = proxy_req->cache_key;
1367 if (option == NULL) {
1368 if (proxy_entry->proxy_req) {
1370 proxy_req->cache_key = NULL;
1371 coap_proxy_del_req(proxy_entry, proxy_req);
1373 }
else if (!proxy_req->doing_observe) {
1378 proxy_req->doing_observe = 1;
1379 proxy_req->incoming->ref_proxy_subs++;
1389 void *body_data, coap_proxy_req_t *proxy_req,
1401 coap_proxy_cache_t *proxy_cache;
1407 if (proxy_req->proxy_cache) {
1409 proxy_cache = proxy_req->proxy_cache;
1412 if (proxy_cache == NULL) {
1415 memset(proxy_cache, 0,
sizeof(coap_proxy_cache_t));
1418 coap_proxy_ignore_options,
1419 sizeof(coap_proxy_ignore_options)/
sizeof(coap_proxy_ignore_options[0]));
1424 memcpy(&proxy_cache->cache_req, cache_key_l,
1425 sizeof(proxy_cache->cache_req));
1429 proxy_req->proxy_cache = proxy_cache;
1431 PROXY_CACHE_ADD(proxy_entry->rsp_cache, proxy_cache);
1436 const uint8_t *data;
1444 if (proxy_cache->rsp_pdu) {
1450 memcpy(copy->
s, data, data_len);
1451 proxy_cache->rsp_pdu->data_free = copy;
1452 proxy_cache->rsp_pdu->body_data = copy->
s;
1453 proxy_cache->rsp_pdu->body_length = copy->
length;
1454 proxy_cache->rsp_pdu->body_total = copy->
length;
1456 proxy_cache->rsp_pdu->body_data = NULL;
1457 proxy_cache->rsp_pdu->body_length = 0;
1458 proxy_cache->rsp_pdu->body_total = 0;
1471 proxy_cache->etag = 0;
1485 LL_FOREACH(proxy_entry->proxy_req, proxy_req) {
1486 if (proxy_req->proxy_cache == proxy_cache) {
1487 if (!proxy_req->doing_observe) {
1494 proxy_req->doing_observe = 1;
1495 proxy_req->incoming->ref_proxy_subs++;
1498 coap_proxy_log_entry(proxy_req->incoming, proxy_req->pdu, proxy_req->token_used,
"rsp");
1500 if (coap_proxy_call_response_handler(proxy_req->incoming, proxy_req->pdu,
1511 coap_proxy_log_entry(proxy_req->incoming, proxy_req->pdu, proxy_req->token_used,
"rspn");
1513 ret = coap_proxy_call_response_handler(proxy_req->incoming, proxy_req->pdu,
1514 rcvd, &token, proxy_req, 0, 0);
1516 coap_proxy_del_req(proxy_entry, proxy_req);
1541 coap_log_err(
"coap_proxy_local_write: Unknown or Proxy resource not defined\n");
1549 coap_log_err(
"coap_proxy_local_write: Could not create response PDU\n");
1565 if (!coap_proxy_forward_request_lkd(session, pdu, response, resource,
1566 NULL, session->server_list)) {
1567 coap_log_debug(
"coap_proxy_local_write: Failed to forward PDU\n");
1582 session = coap_new_client_session_proxy_lkd(ctx, server_list);
1596#if COAP_IPV6_SUPPORT
1597 remote.
s = (
const uint8_t *)
"::1";
1598#elif COAP_IPV4_SUPPORT
1599 remote.
s = (
const uint8_t *)
"127.0.0.1";
1601 coap_log_warn(
"coap_new_client_session_proxy: No IPv4 or IPv6 support\n");
1604 remote.
length = strlen((
const char *)remote.
s);
1611 coap_log_warn(
"coap_new_client_session_proxy: Unable to resolve IP address\n");
1618 session->server_list = server_list;
1626 coap_mid_t mid, coap_proxy_subs_delete_t type) {
1631 for (i = 0; i < context->proxy_list_count; i++) {
1633 coap_proxy_req_t *proxy_req, *treq;
1635 LL_FOREACH_SAFE(proxy_entry->proxy_req, proxy_req, treq) {
1636 if (proxy_req->incoming == session) {
1642 case COAP_PROXY_SUBS_ALL:
1645 case COAP_PROXY_SUBS_TOKEN:
1649 case COAP_PROXY_SUBS_MID:
1650 if (proxy_req->mid == mid)
1657 if (match && proxy_entry->proxy_req && ! proxy_entry->proxy_req->next &&
1658 proxy_req->token_used) {
1661 coap_log_debug(
"coap_delete_proxy_subscriber: Using coap_cancel_observe() to do Proxy OBSERVE cancellation\n");
1663 memcpy(&tmp.
s, &proxy_req->token_used->s,
sizeof(tmp.
s));
1664 tmp.
length = proxy_req->token_used->length;
1667 coap_proxy_del_req(proxy_entry, proxy_req);
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.
int coap_is_mcast(const coap_address_t *a)
Checks if given address a denotes a multicast 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.
#define COAP_BLOCK_CACHE_RESPONSE
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 *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, func, failed)
Dummy for no thread-safe code.
#define coap_lock_unlock()
Dummy for no thread-safe code.
#define coap_lock_check_locked()
Dummy for no thread-safe code.
#define coap_lock_lock(failed)
Dummy for no thread-safe code.
#define coap_log_debug(...)
coap_log_t coap_get_log_level(void)
Get the current logging level.
void coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu)
Display the contents of the specified pdu.
size_t coap_print_addr(const coap_address_t *addr, unsigned char *buf, size_t len)
Print the address into the defined buffer.
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.
int coap_option_filter_set(coap_opt_filter_t *filter, coap_option_num_t option)
Sets the corresponding entry for number in filter.
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_...
COAP_STATIC_INLINE void coap_pdu_release_lkd(coap_pdu_t *pdu)
#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 Note: coap_layers_coap[] needs updating if extended.
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
int coap_get_data(const coap_pdu_t *pdu, size_t *len, const uint8_t **data)
Retrieves the length and data pointer of specified PDU.
#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_proxy_t
coap_proxy_t Proxy definitions.
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.
#define COAP_PROXY_NEW_MASK
Space used in coap_proxy_t for new types.
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_DIRECT_STRIP
Old - do not use - Act as a forward-dynamic proxy, strip out proxy options.
@ COAP_PROXY_BIT_STRIP
If COAP_PROXY_BIT_STRIP set, then remove any Proxy-Uri or Proxy-Scheme, else leave them.
@ COAP_PROXY_REVERSE_STRIP
Old - do not use - Act as a reverse proxy, strip out proxy options.
@ COAP_PROXY_FWD_STATIC
forward-static proxy.
@ COAP_PROXY_REV
reverse proxy.
@ COAP_PROXY_REVERSE
Old - do not use - Act as a reverse proxy.
@ COAP_PROXY_DIRECT
Old - do not use - Act as a forward-dynamic proxy.
@ COAP_PROXY_FORWARD_STRIP
Old - do not use - Act as a forward-static proxy, strip out proxy options.
@ COAP_PROXY_FWD_DYNAMIC
forward-dynamic proxy.
@ COAP_PROXY_FORWARD
Old - do not use - Act as a forward-static proxy.
@ COAP_PROXY_BIT_MCAST
If COAP_PROXY_BIT_MCAST set, then upstream servers can be multicast, else only unicast.
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.
#define COAP_PROTO_NOT_RELIABLE(p)
void coap_session_new_token(coap_session_t *session, size_t *len, uint8_t *data)
Creates a new token for use.
const coap_address_t * coap_session_get_addr_remote(const coap_session_t *session)
Get the remote IP address and port from the session.
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_cancel_observe_lkd(coap_session_t *session, coap_binary_t *token, coap_pdu_type_t message_type)
Cancel an observe that is being tracked by the client large receive logic.
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.
coap_string_t * coap_get_uri_path(const coap_pdu_t *request)
Extract uri_path string from request PDU.
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.
size_t length
length of binary data
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.
size_t max_size
maximum size for token, options and payload, or zero for variable size pdu
const uint8_t * body_data
Holds ptr to re-assembled data or NULL.
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 and option controlling bits (if old type used, will get mapped into new + bits.
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...
uint32_t block_mode
Zero or more COAP_BLOCK_ or'd options.
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.