Loading...
Searching...
No Matches
coap_proxy.c
Go to the documentation of this file.
/* coap_proxy.c -- helper functions for proxy handling
*
* Copyright (C) 2024 Jon Shallow <supjps-libcoap@jpshallow.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*
* This file is part of the CoAP library libcoap. Please see
* README for terms of use.
*/
#include "coap3/coap_libcoap_build.h"
#if COAP_PROXY_SUPPORT
#include <stdio.h>
#ifdef _WIN32
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#endif
int
coap_proxy_is_supported(void) {
return 1;
}
void
coap_proxy_cleanup(coap_context_t *context) {
size_t i;
size_t j;
for (i = 0; i < context->proxy_list_count; i++) {
for (j = 0; j < context->proxy_list[i].req_count; j++) {
coap_delete_pdu(context->proxy_list[i].req_list[j].pdu);
coap_delete_cache_key(context->proxy_list[i].req_list[j].cache_key);
}
coap_free_type(COAP_STRING, context->proxy_list[i].req_list);
}
coap_free_type(COAP_STRING, context->proxy_list);
}
/*
* return 1 if there is a future expire time, else 0.
* update tim_rem with remaining value if return is 1.
*/
int
coap_proxy_check_timeouts(coap_context_t *context, coap_tick_t now,
coap_tick_t *tim_rem) {
size_t i;
int ret = 0;
*tim_rem = -1;
for (i = 0; i < context->proxy_list_count; i++) {
coap_proxy_list_t *proxy_list = &context->proxy_list[i];
if (proxy_list->ongoing && proxy_list->idle_timeout_ticks) {
if (proxy_list->last_used + proxy_list->idle_timeout_ticks <= now) {
/* Drop session to upstream server */
coap_session_release_lkd(proxy_list->ongoing);
proxy_list->ongoing = NULL;
} else {
if (*tim_rem > proxy_list->last_used + proxy_list->idle_timeout_ticks - now) {
*tim_rem = proxy_list->last_used + proxy_list->idle_timeout_ticks - now;
}
ret = 1;
}
}
}
return ret;
}
static int
coap_get_uri_proxy_scheme_info(const coap_pdu_t *request,
coap_opt_t *opt,
coap_uri_t *uri,
coap_string_t **uri_path,
coap_string_t **uri_query) {
const char *opt_val = (const char *)coap_opt_value(opt);
int opt_len = coap_opt_length(opt);
coap_opt_iterator_t opt_iter;
if (opt_len == 9 &&
strncasecmp(opt_val, "coaps+tcp", 9) == 0) {
uri->scheme = COAP_URI_SCHEME_COAPS_TCP;
uri->port = COAPS_DEFAULT_PORT;
} else if (opt_len == 8 &&
strncasecmp(opt_val, "coap+tcp", 8) == 0) {
uri->scheme = COAP_URI_SCHEME_COAP_TCP;
uri->port = COAP_DEFAULT_PORT;
} else if (opt_len == 5 &&
strncasecmp(opt_val, "coaps", 5) == 0) {
uri->scheme = COAP_URI_SCHEME_COAPS;
uri->port = COAPS_DEFAULT_PORT;
} else if (opt_len == 4 &&
strncasecmp(opt_val, "coap", 4) == 0) {
uri->scheme = COAP_URI_SCHEME_COAP;
uri->port = COAP_DEFAULT_PORT;
} else if (opt_len == 7 &&
strncasecmp(opt_val, "coap+ws", 7) == 0) {
uri->scheme = COAP_URI_SCHEME_COAP_WS;
uri->port = 80;
} else if (opt_len == 8 &&
strncasecmp(opt_val, "coaps+ws", 8) == 0) {
uri->scheme = COAP_URI_SCHEME_COAPS_WS;
uri->port = 443;
} else {
coap_log_warn("Unsupported Proxy Scheme '%*.*s'\n",
opt_len, opt_len, opt_val);
return 0;
}
opt = coap_check_option(request, COAP_OPTION_URI_HOST, &opt_iter);
if (opt) {
uri->host.length = coap_opt_length(opt);
uri->host.s = coap_opt_value(opt);
} else {
coap_log_warn("Proxy Scheme requires Uri-Host\n");
return 0;
}
opt = coap_check_option(request, COAP_OPTION_URI_PORT, &opt_iter);
if (opt) {
uri->port =
coap_decode_var_bytes(coap_opt_value(opt),
coap_opt_length(opt));
}
*uri_path = coap_get_uri_path(request);
if (*uri_path) {
uri->path.s = (*uri_path)->s;
uri->path.length = (*uri_path)->length;
} else {
uri->path.s = NULL;
uri->path.length = 0;
}
*uri_query = coap_get_query(request);
if (*uri_query) {
uri->query.s = (*uri_query)->s;
uri->query.length = (*uri_query)->length;
} else {
uri->query.s = NULL;
uri->query.length = 0;
}
return 1;
}
int
coap_verify_proxy_scheme_supported(coap_uri_scheme_t scheme) {
/* Sanity check that the connection can be forwarded on */
switch (scheme) {
case COAP_URI_SCHEME_HTTP:
case COAP_URI_SCHEME_HTTPS:
coap_log_warn("Proxy URI http or https not supported\n");
return 0;
case COAP_URI_SCHEME_COAP:
break;
case COAP_URI_SCHEME_COAPS:
if (!coap_dtls_is_supported()) {
coap_log_warn("coaps URI scheme not supported for proxy\n");
return 0;
}
break;
case COAP_URI_SCHEME_COAP_TCP:
if (!coap_tcp_is_supported()) {
coap_log_warn("coap+tcp URI scheme not supported for proxy\n");
return 0;
}
break;
case COAP_URI_SCHEME_COAPS_TCP:
if (!coap_tls_is_supported()) {
coap_log_warn("coaps+tcp URI scheme not supported for proxy\n");
return 0;
}
break;
case COAP_URI_SCHEME_COAP_WS:
if (!coap_ws_is_supported()) {
coap_log_warn("coap+ws URI scheme not supported for proxy\n");
return 0;
}
break;
case COAP_URI_SCHEME_COAPS_WS:
if (!coap_wss_is_supported()) {
coap_log_warn("coaps+ws URI scheme not supported for proxy\n");
return 0;
}
break;
case COAP_URI_SCHEME_LAST:
default:
coap_log_warn("%d URI scheme not supported\n", scheme);
return 0;
}
return 1;
}
static coap_proxy_list_t *
coap_proxy_get_session(coap_session_t *session, const coap_pdu_t *request,
coap_pdu_t *response,
coap_proxy_server_list_t *server_list,
coap_proxy_server_t *server_use) {
size_t i;
coap_proxy_list_t *new_proxy_list;
coap_proxy_list_t *proxy_list = session->context->proxy_list;
size_t proxy_list_count = session->context->proxy_list_count;
coap_opt_iterator_t opt_iter;
coap_opt_t *proxy_scheme;
coap_opt_t *proxy_uri;
coap_string_t *uri_path = NULL;
coap_string_t *uri_query = NULL;
/* Round robin the defined next server list (which usually is just one */
server_list->next_entry++;
if (server_list->next_entry >= server_list->entry_count)
server_list->next_entry = 0;
memcpy(server_use, &server_list->entry[server_list->next_entry], sizeof(*server_use));
switch (server_list->type) {
case COAP_PROXY_REVERSE:
case COAP_PROXY_FORWARD:
case COAP_PROXY_DIRECT:
/* Nothing else needs to be done */
break;
case COAP_PROXY_REVERSE_STRIP:
case COAP_PROXY_FORWARD_STRIP:
case COAP_PROXY_DIRECT_STRIP:
/* Need to get actual server from CoAP options */
/*
* See if Proxy-Scheme
*/
proxy_scheme = coap_check_option(request, COAP_OPTION_PROXY_SCHEME, &opt_iter);
if (proxy_scheme) {
if (!coap_get_uri_proxy_scheme_info(request, proxy_scheme, &server_use->uri, &uri_path,
&uri_query)) {
response->code = COAP_RESPONSE_CODE(505);
return NULL;
}
}
/*
* See if Proxy-Uri
*/
proxy_uri = coap_check_option(request, COAP_OPTION_PROXY_URI, &opt_iter);
if (proxy_uri) {
coap_log_info("Proxy URI '%.*s'\n",
(int)coap_opt_length(proxy_uri),
(const char *)coap_opt_value(proxy_uri));
if (coap_split_proxy_uri(coap_opt_value(proxy_uri),
coap_opt_length(proxy_uri),
&server_use->uri) < 0) {
/* Need to return a 5.05 RFC7252 Section 5.7.2 */
coap_log_warn("Proxy URI not decodable\n");
response->code = COAP_RESPONSE_CODE(505);
return NULL;
}
}
if (!(proxy_scheme || proxy_uri)) {
response->code = COAP_RESPONSE_CODE(404);
return NULL;
}
if (server_use->uri.host.length == 0) {
/* Ongoing connection not well formed */
response->code = COAP_RESPONSE_CODE(505);
return NULL;
}
if (!coap_verify_proxy_scheme_supported(server_use->uri.scheme)) {
response->code = COAP_RESPONSE_CODE(505);
return NULL;
}
break;
default:
assert(0);
return NULL;
}
/* See if we are already connected to the Server */
for (i = 0; i < proxy_list_count; i++) {
if (coap_string_equal(&proxy_list[i].uri.host, &server_use->uri.host) &&
proxy_list[i].uri.port == server_use->uri.port &&
proxy_list[i].uri.scheme == server_use->uri.scheme) {
if (!server_list->track_client_session) {
coap_ticks(&proxy_list[i].last_used);
return &proxy_list[i];
} else {
if (proxy_list[i].incoming == session) {
coap_ticks(&proxy_list[i].last_used);
return &proxy_list[i];
}
}
}
}
/* Need to create a new forwarding mapping */
new_proxy_list = coap_realloc_type(COAP_STRING, proxy_list, (i+1)*sizeof(proxy_list[0]));
if (new_proxy_list == NULL) {
response->code = COAP_RESPONSE_CODE(500);
return NULL;
}
session->context->proxy_list = proxy_list = new_proxy_list;
memset(&proxy_list[i], 0, sizeof(proxy_list[i]));
proxy_list[i].uri = server_use->uri;
if (server_list->track_client_session) {
proxy_list[i].incoming = session;
}
session->context->proxy_list_count++;
proxy_list[i].idle_timeout_ticks = server_list->idle_timeout_secs * COAP_TICKS_PER_SECOND;
coap_ticks(&proxy_list[i].last_used);
return &proxy_list[i];
}
void
coap_proxy_remove_association(coap_session_t *session, int send_failure) {
size_t i;
size_t j;
coap_proxy_list_t *proxy_list = session->context->proxy_list;
size_t proxy_list_count = session->context->proxy_list_count;
for (i = 0; i < proxy_list_count; i++) {
/* Check for incoming match */
for (j = 0; j < proxy_list[i].req_count; j++) {
if (proxy_list[i].req_list[j].incoming == session) {
coap_delete_pdu(proxy_list[i].req_list[j].pdu);
coap_delete_bin_const(proxy_list[i].req_list[j].token_used);
coap_delete_cache_key(proxy_list[i].req_list[j].cache_key);
if (proxy_list[i].req_count-j > 1) {
memmove(&proxy_list[i].req_list[j], &proxy_list[i].req_list[j+1],
(proxy_list[i].req_count-j-1) * sizeof(proxy_list[i].req_list[0]));
}
proxy_list[i].req_count--;
break;
}
}
if (proxy_list[i].incoming == session) {
/* Only if there is a one-to-one tracking */
coap_session_release_lkd(proxy_list[i].ongoing);
break;
}
/* Check for outgoing match */
if (proxy_list[i].ongoing == session) {
coap_session_t *ongoing;
for (j = 0; j < proxy_list[i].req_count; j++) {
if (send_failure) {
coap_pdu_t *response;
coap_bin_const_t l_token;
/* Need to send back a gateway failure */
response = coap_pdu_init(proxy_list[i].req_list[j].pdu->type,
COAP_RESPONSE_CODE(502),
coap_new_message_id_lkd(proxy_list[i].incoming),
coap_session_max_pdu_size_lkd(proxy_list[i].incoming));
if (!response) {
coap_log_info("PDU creation issue\n");
goto cleanup;
}
l_token = coap_pdu_get_token(proxy_list[i].req_list[j].pdu);
if (!coap_add_token(response, l_token.length,
l_token.s)) {
coap_log_debug("Cannot add token to incoming proxy response PDU\n");
}
if (coap_send_lkd(proxy_list[i].incoming, response) == COAP_INVALID_MID) {
coap_log_info("Failed to send PDU with 5.02 gateway issue\n");
}
cleanup:
coap_delete_pdu(proxy_list[i].req_list[j].pdu);
coap_delete_bin_const(proxy_list[i].req_list[j].token_used);
coap_delete_cache_key(proxy_list[i].req_list[j].cache_key);
}
}
ongoing = proxy_list[i].ongoing;
coap_free_type(COAP_STRING, proxy_list[i].req_list);
if (proxy_list_count-i > 1) {
memmove(&proxy_list[i],
&proxy_list[i+1],
(proxy_list_count-i-1) * sizeof(proxy_list[0]));
}
session->context->proxy_list_count--;
coap_session_release_lkd(ongoing);
break;
}
}
}
static coap_proxy_list_t *
coap_proxy_get_ongoing_session(coap_session_t *session,
const coap_pdu_t *request,
coap_pdu_t *response,
coap_proxy_server_list_t *server_list,
coap_proxy_server_t *server_use) {
coap_address_t dst;
coap_proto_t proto;
coap_addr_info_t *info_list = NULL;
coap_proxy_list_t *proxy_entry;
coap_context_t *context = session->context;
static char client_sni[256];
proxy_entry = coap_proxy_get_session(session, request, response, server_list, server_use);
if (!proxy_entry) {
/* Response code should be set */
return NULL;
}
if (!proxy_entry->ongoing) {
/* Need to create a new session */
/* resolve destination address where data should be sent */
info_list = coap_resolve_address_info(&server_use->uri.host,
server_use->uri.port,
server_use->uri.port,
server_use->uri.port,
server_use->uri.port,
0,
1 << server_use->uri.scheme,
COAP_RESOLVE_TYPE_REMOTE);
if (info_list == NULL) {
response->code = COAP_RESPONSE_CODE(502);
coap_proxy_remove_association(session, 0);
return NULL;
}
proto = info_list->proto;
memcpy(&dst, &info_list->addr, sizeof(dst));
coap_free_address_info(info_list);
snprintf(client_sni, sizeof(client_sni), "%*.*s", (int)server_use->uri.host.length,
(int)server_use->uri.host.length, server_use->uri.host.s);
switch (server_use->uri.scheme) {
case COAP_URI_SCHEME_COAP:
case COAP_URI_SCHEME_COAP_TCP:
case COAP_URI_SCHEME_COAP_WS:
#if COAP_OSCORE_SUPPORT
if (server_use->oscore_conf) {
proxy_entry->ongoing =
coap_new_client_session_oscore_lkd(context, NULL, &dst,
proto, server_use->oscore_conf);
} else {
#endif /* COAP_OSCORE_SUPPORT */
proxy_entry->ongoing =
coap_new_client_session_lkd(context, NULL, &dst, proto);
#if COAP_OSCORE_SUPPORT
}
#endif /* COAP_OSCORE_SUPPORT */
break;
case COAP_URI_SCHEME_COAPS:
case COAP_URI_SCHEME_COAPS_TCP:
case COAP_URI_SCHEME_COAPS_WS:
#if COAP_OSCORE_SUPPORT
if (server_use->oscore_conf) {
if (server_use->dtls_pki) {
server_use->dtls_pki->client_sni = client_sni;
proxy_entry->ongoing =
coap_new_client_session_oscore_pki_lkd(context, NULL, &dst,
proto, server_use->dtls_pki, server_use->oscore_conf);
} else if (server_use->dtls_cpsk) {
server_use->dtls_cpsk->client_sni = client_sni;
proxy_entry->ongoing =
coap_new_client_session_oscore_psk_lkd(context, NULL, &dst,
proto, server_use->dtls_cpsk, server_use->oscore_conf);
} else {
coap_log_warn("Proxy: (D)TLS not configured for secure session\n");
}
} else {
#endif /* COAP_OSCORE_SUPPORT */
/* Not doing OSCORE */
if (server_use->dtls_pki) {
server_use->dtls_pki->client_sni = client_sni;
proxy_entry->ongoing =
coap_new_client_session_pki_lkd(context, NULL, &dst,
proto, server_use->dtls_pki);
} else if (server_use->dtls_cpsk) {
server_use->dtls_cpsk->client_sni = client_sni;
proxy_entry->ongoing =
coap_new_client_session_psk2_lkd(context, NULL, &dst,
proto, server_use->dtls_cpsk);
} else {
coap_log_warn("Proxy: (D)TLS not configured for secure session\n");
}
#if COAP_OSCORE_SUPPORT
}
#endif /* COAP_OSCORE_SUPPORT */
break;
case COAP_URI_SCHEME_HTTP:
case COAP_URI_SCHEME_HTTPS:
case COAP_URI_SCHEME_LAST:
default:
assert(0);
break;
}
if (proxy_entry->ongoing == NULL) {
response->code = COAP_RESPONSE_CODE(505);
coap_proxy_remove_association(session, 0);
return NULL;
}
}
return proxy_entry;
}
static void
coap_proxy_release_body_data(coap_session_t *session COAP_UNUSED,
void *app_ptr) {
coap_delete_binary(app_ptr);
}
int COAP_API
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) {
int ret;
coap_lock_lock(session->context, return 0);
ret = coap_proxy_forward_request_lkd(session,
request,
response,
resource,
cache_key,
server_list);
coap_lock_unlock(session->context);
return ret;
}
int
coap_proxy_forward_request_lkd(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) {
coap_proxy_list_t *proxy_entry;
size_t size;
size_t offset;
size_t total;
coap_binary_t *body_data = NULL;
const uint8_t *data;
coap_pdu_t *pdu = NULL;
coap_bin_const_t r_token = coap_pdu_get_token(request);
uint8_t token[8];
size_t token_len;
coap_proxy_req_t *new_req_list;
coap_optlist_t *optlist = NULL;
coap_opt_t *option;
coap_opt_iterator_t opt_iter;
coap_proxy_server_t server_use;
/* Set up ongoing session (if not already done) */
proxy_entry = coap_proxy_get_ongoing_session(session, request, response,
server_list, &server_use);
if (!proxy_entry)
/* response code already set */
return 0;
/* Need to save the request pdu entry */
new_req_list = coap_realloc_type(COAP_STRING, proxy_entry->req_list,
(proxy_entry->req_count + 1)*sizeof(coap_proxy_req_t));
if (new_req_list == NULL) {
goto failed;
}
proxy_entry->req_list = new_req_list;
/* Get a new token for ongoing session */
coap_session_new_token(proxy_entry->ongoing, &token_len, token);
new_req_list[proxy_entry->req_count].token_used = coap_new_bin_const(token, token_len);
if (new_req_list[proxy_entry->req_count].token_used == NULL) {
goto failed;
}
new_req_list[proxy_entry->req_count].pdu = coap_pdu_duplicate_lkd(request, session,
r_token.length, r_token.s, NULL);
if (new_req_list[proxy_entry->req_count].pdu == NULL) {
coap_delete_bin_const(new_req_list[proxy_entry->req_count].token_used);
new_req_list[proxy_entry->req_count].token_used = NULL;
goto failed;
}
new_req_list[proxy_entry->req_count].resource = resource;
new_req_list[proxy_entry->req_count].incoming = session;
new_req_list[proxy_entry->req_count].cache_key = cache_key;
proxy_entry->req_count++;
switch (server_list->type) {
case COAP_PROXY_REVERSE_STRIP:
case COAP_PROXY_FORWARD_STRIP:
case COAP_PROXY_DIRECT_STRIP:
/*
* Need to replace Proxy-Uri with Uri-Host (and Uri-Port)
* or strip out Proxy-Scheme.
*/
/*
* Build up the ongoing PDU that we are going to send
*/
pdu = coap_pdu_init(request->type, request->code,
coap_new_message_id_lkd(proxy_entry->ongoing),
coap_session_max_pdu_size_lkd(proxy_entry->ongoing));
if (!pdu) {
goto failed;
}
if (!coap_add_token(pdu, token_len, token)) {
goto failed;
}
if (!coap_uri_into_optlist(&server_use.uri,
&proxy_entry->ongoing->addr_info.remote,
&optlist, 1)) {
coap_log_err("Failed to create options for URI\n");
goto failed;
}
/* Copy the remaining options across */
coap_option_iterator_init(request, &opt_iter, COAP_OPT_ALL);
while ((option = coap_option_next(&opt_iter))) {
switch (opt_iter.number) {
case COAP_OPTION_PROXY_URI:
break;
case COAP_OPTION_PROXY_SCHEME:
break;
case COAP_OPTION_BLOCK1:
case COAP_OPTION_BLOCK2:
case COAP_OPTION_Q_BLOCK1:
case COAP_OPTION_Q_BLOCK2:
/* These are not passed on */
break;
default:
coap_insert_optlist(&optlist,
coap_new_optlist(opt_iter.number,
coap_opt_length(option),
coap_opt_value(option)));
break;
}
}
/* Update pdu with options */
coap_add_optlist_pdu(pdu, &optlist);
coap_delete_optlist(optlist);
break;
case COAP_PROXY_REVERSE:
case COAP_PROXY_FORWARD:
case COAP_PROXY_DIRECT:
default:
/*
* Duplicate request PDU for onward transmission (with new token).
*/
pdu = coap_pdu_duplicate_lkd(request, proxy_entry->ongoing, token_len, token, NULL);
if (!pdu) {
coap_log_debug("proxy: PDU generation error\n");
goto failed;
}
break;
}
if (coap_get_data_large(request, &size, &data, &offset, &total)) {
/* COAP_BLOCK_SINGLE_BODY is set, so single body should be given */
assert(size == total);
/*
* Need to take a copy of the data as request PDU may go away before
* all data is transmitted.
*/
body_data = coap_new_binary(total);
if (!body_data) {
coap_log_debug("proxy: body build memory error\n");
goto failed;
}
memcpy(body_data->s, data, size);
if (!coap_add_data_large_request_lkd(proxy_entry->ongoing, pdu, total, data,
coap_proxy_release_body_data, body_data)) {
coap_log_debug("proxy: add data error\n");
goto failed;
}
}
if (coap_send_lkd(proxy_entry->ongoing, pdu) == COAP_INVALID_MID) {
pdu = NULL;
coap_log_debug("proxy: upstream PDU send error\n");
goto failed;
}
/*
* Do not update the response code (hence empty ACK) as will be sending
* separate response when response comes back from upstream server
*/
return 1;
failed:
response->code = COAP_RESPONSE_CODE(500);
coap_delete_pdu(pdu);
return 0;
}
coap_response_t COAP_API
coap_proxy_forward_response(coap_session_t *session,
const coap_pdu_t *received,
coap_cache_key_t **cache_key) {
int ret;
coap_lock_lock(session->context, return 0);
ret = coap_proxy_forward_response_lkd(session,
received,
cache_key);
coap_lock_unlock(session->context);
return ret;
}
coap_response_t
coap_proxy_forward_response_lkd(coap_session_t *session,
const coap_pdu_t *received,
coap_cache_key_t **cache_key) {
coap_pdu_t *pdu = NULL;
coap_session_t *incoming = NULL;
size_t i;
size_t j = 0;
size_t size;
const uint8_t *data;
coap_optlist_t *optlist = NULL;
coap_opt_t *option;
coap_opt_iterator_t opt_iter;
size_t offset;
size_t total;
coap_proxy_list_t *proxy_entry = NULL;
uint16_t media_type = COAP_MEDIATYPE_TEXT_PLAIN;
int maxage = -1;
uint64_t etag = 0;
coap_pdu_code_t rcv_code = coap_pdu_get_code(received);
coap_bin_const_t rcv_token = coap_pdu_get_token(received);
coap_bin_const_t req_token;
coap_binary_t *body_data = NULL;
coap_pdu_t *req_pdu;
coap_proxy_list_t *proxy_list = session->context->proxy_list;
size_t proxy_list_count = session->context->proxy_list_count;
coap_resource_t *resource;
struct coap_proxy_req_t *proxy_req = NULL;
for (i = 0; i < proxy_list_count; i++) {
proxy_entry = &proxy_list[i];
for (j = 0; j < proxy_entry->req_count; j++) {
if (coap_binary_equal(&rcv_token, proxy_entry->req_list[j].token_used)) {
proxy_req = &proxy_entry->req_list[j];
break;
}
}
if (j != proxy_entry->req_count) {
break;
}
}
if (i == proxy_list_count) {
coap_log_warn("Unknown proxy ongoing session response received\n");
return COAP_RESPONSE_OK;
}
req_pdu = proxy_req->pdu;
req_token = coap_pdu_get_token(req_pdu);
resource = proxy_req->resource;
incoming = proxy_req->incoming;
coap_log_debug("** process upstream incoming %d.%02d response:\n",
COAP_RESPONSE_CLASS(rcv_code), rcv_code & 0x1F);
if (coap_get_data_large(received, &size, &data, &offset, &total)) {
/* COAP_BLOCK_SINGLE_BODY is set, so single body should be given */
assert(size == total);
body_data = coap_new_binary(total);
if (!body_data) {
coap_log_debug("body build memory error\n");
goto remove_match;
}
memcpy(body_data->s, data, size);
data = body_data->s;
}
/*
* Build up the ongoing PDU that we are going to send to proxy originator
* as separate response
*/
pdu = coap_pdu_init(req_pdu->type, rcv_code,
coap_new_message_id_lkd(incoming),
coap_session_max_pdu_size_lkd(incoming));
if (!pdu) {
coap_log_debug("Failed to create ongoing proxy response PDU\n");
goto remove_match;
}
if (!coap_add_token(pdu, req_token.length, req_token.s)) {
coap_log_debug("cannot add token to ongoing proxy response PDU\n");
}
/*
* Copy the options across, skipping those needed for
* coap_add_data_response_large()
*/
coap_option_iterator_init(received, &opt_iter, COAP_OPT_ALL);
while ((option = coap_option_next(&opt_iter))) {
switch (opt_iter.number) {
case COAP_OPTION_CONTENT_FORMAT:
media_type = coap_decode_var_bytes(coap_opt_value(option),
coap_opt_length(option));
break;
case COAP_OPTION_MAXAGE:
maxage = coap_decode_var_bytes(coap_opt_value(option),
coap_opt_length(option));
break;
case COAP_OPTION_ETAG:
etag = coap_decode_var_bytes8(coap_opt_value(option),
coap_opt_length(option));
break;
case COAP_OPTION_BLOCK2:
case COAP_OPTION_Q_BLOCK2:
case COAP_OPTION_SIZE2:
break;
default:
coap_insert_optlist(&optlist,
coap_new_optlist(opt_iter.number,
coap_opt_length(option),
coap_opt_value(option)));
break;
}
}
coap_add_optlist_pdu(pdu, &optlist);
coap_delete_optlist(optlist);
if (size > 0) {
coap_string_t *l_query = coap_get_query(req_pdu);
coap_add_data_large_response_lkd(resource, incoming, req_pdu, pdu,
l_query,
media_type, maxage, etag, size, data,
coap_proxy_release_body_data,
body_data);
body_data = NULL;
coap_delete_string(l_query);
}
if (cache_key)
*cache_key = proxy_req->cache_key;
coap_send_lkd(incoming, pdu);
remove_match:
option = coap_check_option(received, COAP_OPTION_OBSERVE, &opt_iter);
/* Need to remove matching token entry (apart from on Observe response) */
if (option == NULL && proxy_entry->req_count) {
coap_delete_pdu(proxy_entry->req_list[j].pdu);
coap_delete_bin_const(proxy_entry->req_list[j].token_used);
/* Do not delete cache key here - caller's responsibility */
proxy_entry->req_count--;
if (proxy_entry->req_count-j > 0) {
memmove(&proxy_entry->req_list[j], &proxy_entry->req_list[j+1],
(proxy_entry->req_count-j) * sizeof(proxy_entry->req_list[0]));
}
}
coap_delete_binary(body_data);
return COAP_RESPONSE_OK;
}
#else /* ! COAP_PROXY_SUPPORT */
int
coap_proxy_is_supported(void) {
return 0;
}
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) {
(void)session;
(void)request;
(void)resource;
(void)cache_key;
(void)server_list;
response->code = COAP_RESPONSE_CODE(500);
return 0;
}
COAP_API coap_response_t
coap_proxy_forward_response(coap_session_t *session,
const coap_pdu_t *received,
coap_cache_key_t **cache_key) {
(void)session;
(void)received;
(void)cache_key;
return COAP_RESPONSE_OK;
}
int
coap_verify_proxy_scheme_supported(coap_uri_scheme_t scheme) {
(void)scheme;
return 0;
}
#endif /* ! COAP_PROXY_SUPPORT */
coap_free_address_info
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().
Definition coap_address.c:790
coap_resolve_address_info
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...
Definition coap_address.c:486
COAP_RESOLVE_TYPE_REMOTE
@ COAP_RESOLVE_TYPE_REMOTE
remote side of session
Definition coap_address.h:207
coap_libcoap_build.h
Library specific build wrapper for coap_internal.h.
COAP_API
#define COAP_API
Definition coap_libcoap_build.h:41
COAP_STRING
@ COAP_STRING
Definition coap_mem.h:39
coap_realloc_type
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...
coap_free_type
void coap_free_type(coap_memory_tag_t type, void *p)
Releases the memory that was allocated by coap_malloc_type().
coap_opt_t
uint8_t coap_opt_t
Use byte-oriented access methods here because sliding a complex struct coap_opt_t over the data buffe...
Definition coap_option.h:26
coap_uri_scheme_t
coap_uri_scheme_t
The scheme specifiers.
Definition coap_uri.h:28
COAP_URI_SCHEME_COAPS_WS
@ COAP_URI_SCHEME_COAPS_WS
Definition coap_uri.h:36
COAP_URI_SCHEME_COAPS_TCP
@ COAP_URI_SCHEME_COAPS_TCP
Definition coap_uri.h:32
COAP_URI_SCHEME_COAPS
@ COAP_URI_SCHEME_COAPS
Definition coap_uri.h:30
COAP_URI_SCHEME_COAP_TCP
@ COAP_URI_SCHEME_COAP_TCP
Definition coap_uri.h:31
COAP_URI_SCHEME_COAP_WS
@ COAP_URI_SCHEME_COAP_WS
Definition coap_uri.h:35
COAP_URI_SCHEME_HTTPS
@ COAP_URI_SCHEME_HTTPS
Definition coap_uri.h:34
COAP_URI_SCHEME_COAP
@ COAP_URI_SCHEME_COAP
Definition coap_uri.h:29
COAP_URI_SCHEME_LAST
@ COAP_URI_SCHEME_LAST
Definition coap_uri.h:37
COAP_URI_SCHEME_HTTP
@ COAP_URI_SCHEME_HTTP
Definition coap_uri.h:33
coap_proxy_check_timeouts
int coap_proxy_check_timeouts(coap_context_t *context, coap_tick_t now, coap_tick_t *tim_rem)
Idle timeout inactive proxy sessions as well as return in tim_rem the time to remaining to timeout th...
coap_proxy_forward_response_lkd
coap_response_t coap_proxy_forward_response_lkd(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_cleanup
void coap_proxy_cleanup(coap_context_t *context)
Close down proxy tracking, releasing any memory used.
coap_proxy_remove_association
void coap_proxy_remove_association(coap_session_t *session, int send_failure)
coap_proxy_forward_request_lkd
int coap_proxy_forward_request_lkd(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.
coap_send_lkd
coap_mid_t coap_send_lkd(coap_session_t *session, coap_pdu_t *pdu)
Sends a CoAP message to given peer.
Definition coap_net.c:1356
coap_add_data_large_response_lkd
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.
coap_add_data_large_request_lkd
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.
coap_delete_cache_key
void coap_delete_cache_key(coap_cache_key_t *cache_key)
Delete the cache-key.
coap_tick_t
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
Definition coap_time.h:143
COAP_TICKS_PER_SECOND
#define COAP_TICKS_PER_SECOND
Use ms resolution on POSIX systems.
Definition coap_time.h:158
coap_new_message_id_lkd
uint16_t coap_new_message_id_lkd(coap_session_t *session)
Returns a new message id and updates session->tx_mid accordingly.
Definition coap_session.c:1909
coap_response_t
coap_response_t
Definition coap_net.h:48
coap_ticks
void coap_ticks(coap_tick_t *)
Returns the current value of an internal tick counter.
COAP_RESPONSE_OK
@ COAP_RESPONSE_OK
Response is fine.
Definition coap_net.h:50
coap_decode_var_bytes
unsigned int coap_decode_var_bytes(const uint8_t *buf, size_t len)
Decodes multiple-length byte sequences.
Definition coap_encode.c:38
coap_decode_var_bytes8
uint64_t coap_decode_var_bytes8(const uint8_t *buf, size_t len)
Decodes multiple-length byte sequences.
Definition coap_encode.c:67
coap_lock_unlock
#define coap_lock_unlock(c)
Dummy for no thread-safe code.
Definition coap_threadsafe_internal.h:477
coap_lock_lock
#define coap_lock_lock(c, failed)
Dummy for no thread-safe code.
Definition coap_threadsafe_internal.h:465
coap_log_debug
#define coap_log_debug(...)
Definition coap_debug.h:120
coap_log_info
#define coap_log_info(...)
Definition coap_debug.h:108
coap_log_warn
#define coap_log_warn(...)
Definition coap_debug.h:102
coap_log_err
#define coap_log_err(...)
Definition coap_debug.h:96
coap_option_next
coap_opt_t * coap_option_next(coap_opt_iterator_t *oi)
Updates the iterator oi to point to the next option.
Definition coap_option.c:153
coap_new_optlist
coap_optlist_t * coap_new_optlist(uint16_t number, size_t length, const uint8_t *data)
Create a new optlist entry.
Definition coap_option.c:511
coap_opt_length
uint32_t coap_opt_length(const coap_opt_t *opt)
Returns the length of the given option.
Definition coap_option.c:212
coap_option_iterator_init
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.
Definition coap_option.c:117
coap_delete_optlist
void coap_delete_optlist(coap_optlist_t *queue)
Removes all entries from the optlist_chain, freeing off their memory usage.
Definition coap_option.c:592
COAP_OPT_ALL
#define COAP_OPT_ALL
Pre-defined filter that includes all options.
Definition coap_option.h:108
coap_add_optlist_pdu
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 ...
Definition coap_option.c:551
coap_check_option
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.
Definition coap_option.c:199
coap_insert_optlist
int coap_insert_optlist(coap_optlist_t **head, coap_optlist_t *node)
Adds optlist to the given optlist_chain.
Definition coap_option.c:571
coap_opt_value
const uint8_t * coap_opt_value(const coap_opt_t *opt)
Returns a pointer to the value of the given option.
Definition coap_option.c:249
coap_new_client_session_oscore_psk_lkd
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_new_client_session_oscore_lkd
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_new_client_session_oscore_pki_lkd
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_duplicate_lkd
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.
Definition coap_pdu.c:214
COAP_OPTION_URI_HOST
#define COAP_OPTION_URI_HOST
Definition coap_pdu.h:120
coap_pdu_get_code
coap_pdu_code_t coap_pdu_get_code(const coap_pdu_t *pdu)
Gets the PDU code associated with pdu.
Definition coap_pdu.c:1565
COAP_OPTION_BLOCK2
#define COAP_OPTION_BLOCK2
Definition coap_pdu.h:137
COAP_OPTION_CONTENT_FORMAT
#define COAP_OPTION_CONTENT_FORMAT
Definition coap_pdu.h:128
COAP_OPTION_SIZE2
#define COAP_OPTION_SIZE2
Definition coap_pdu.h:139
COAP_OPTION_BLOCK1
#define COAP_OPTION_BLOCK1
Definition coap_pdu.h:138
COAP_OPTION_Q_BLOCK1
#define COAP_OPTION_Q_BLOCK1
Definition coap_pdu.h:135
COAP_OPTION_PROXY_SCHEME
#define COAP_OPTION_PROXY_SCHEME
Definition coap_pdu.h:142
COAP_DEFAULT_PORT
#define COAP_DEFAULT_PORT
Definition coap_pdu.h:37
coap_delete_pdu
void coap_delete_pdu(coap_pdu_t *pdu)
Dispose of an CoAP PDU and frees associated storage.
Definition coap_pdu.c:179
COAP_RESPONSE_CODE
#define COAP_RESPONSE_CODE(N)
Definition coap_pdu.h:160
COAP_RESPONSE_CLASS
#define COAP_RESPONSE_CLASS(C)
Definition coap_pdu.h:163
coap_proto_t
coap_proto_t
CoAP protocol types.
Definition coap_pdu.h:312
coap_pdu_code_t
coap_pdu_code_t
Set of codes available for a PDU.
Definition coap_pdu.h:326
COAP_MEDIATYPE_TEXT_PLAIN
#define COAP_MEDIATYPE_TEXT_PLAIN
Definition coap_pdu.h:213
coap_add_token
int coap_add_token(coap_pdu_t *pdu, size_t len, const uint8_t *data)
Adds token of length len to pdu.
Definition coap_pdu.c:340
COAP_OPTION_Q_BLOCK2
#define COAP_OPTION_Q_BLOCK2
Definition coap_pdu.h:140
COAPS_DEFAULT_PORT
#define COAPS_DEFAULT_PORT
Definition coap_pdu.h:38
COAP_OPTION_URI_PORT
#define COAP_OPTION_URI_PORT
Definition coap_pdu.h:124
coap_pdu_init
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.
Definition coap_pdu.c:97
coap_get_data_large
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.
Definition coap_pdu.c:864
COAP_INVALID_MID
#define COAP_INVALID_MID
Indicates an invalid message id.
Definition coap_pdu.h:266
COAP_OPTION_MAXAGE
#define COAP_OPTION_MAXAGE
Definition coap_pdu.h:131
COAP_OPTION_ETAG
#define COAP_OPTION_ETAG
Definition coap_pdu.h:121
COAP_OPTION_PROXY_URI
#define COAP_OPTION_PROXY_URI
Definition coap_pdu.h:141
COAP_OPTION_OBSERVE
#define COAP_OPTION_OBSERVE
Definition coap_pdu.h:123
coap_pdu_get_token
coap_bin_const_t coap_pdu_get_token(const coap_pdu_t *pdu)
Gets the token associated with pdu.
Definition coap_pdu.c:1589
coap_proxy_forward_response
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.
Definition coap_proxy.c:895
coap_verify_proxy_scheme_supported
int coap_verify_proxy_scheme_supported(coap_uri_scheme_t scheme)
Verify that the CoAP Scheme is supported for an ongoing proxy connection.
Definition coap_proxy.c:905
coap_proxy_forward_request
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.
Definition coap_proxy.c:879
COAP_PROXY_DIRECT_STRIP
@ COAP_PROXY_DIRECT_STRIP
Act as a direct proxy, strip out proxy options.
Definition coap_proxy.h:33
COAP_PROXY_REVERSE_STRIP
@ COAP_PROXY_REVERSE_STRIP
Act as a reverse proxy, strip out proxy options.
Definition coap_proxy.h:29
COAP_PROXY_REVERSE
@ COAP_PROXY_REVERSE
Act as a reverse proxy.
Definition coap_proxy.h:28
COAP_PROXY_DIRECT
@ COAP_PROXY_DIRECT
Act as a direct proxy.
Definition coap_proxy.h:32
COAP_PROXY_FORWARD_STRIP
@ COAP_PROXY_FORWARD_STRIP
Act as a forward proxy, strip out proxy options.
Definition coap_proxy.h:31
COAP_PROXY_FORWARD
@ COAP_PROXY_FORWARD
Act as a forward proxy.
Definition coap_proxy.h:30
coap_new_client_session_psk2_lkd
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.
coap_new_client_session_pki_lkd
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_new_client_session_lkd
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.
coap_session_max_pdu_size_lkd
size_t coap_session_max_pdu_size_lkd(const coap_session_t *session)
Get maximum acceptable PDU size.
Definition coap_session.c:652
coap_session_release_lkd
void coap_session_release_lkd(coap_session_t *session)
Decrement reference counter on a session.
Definition coap_session.c:376
coap_session_new_token
void coap_session_new_token(coap_session_t *session, size_t *len, uint8_t *data)
Creates a new token for use.
Definition coap_session.c:1892
coap_delete_bin_const
void coap_delete_bin_const(coap_bin_const_t *s)
Deletes the given const binary data and releases any memory allocated.
Definition coap_str.c:120
coap_new_binary
coap_binary_t * coap_new_binary(size_t size)
Returns a new binary object with at least size bytes storage allocated.
Definition coap_str.c:77
coap_new_bin_const
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...
Definition coap_str.c:110
coap_delete_binary
void coap_delete_binary(coap_binary_t *s)
Deletes the given coap_binary_t object and releases any memory allocated.
Definition coap_str.c:105
coap_binary_equal
#define coap_binary_equal(binary1, binary2)
Compares the two binary data for equality.
Definition coap_str.h:211
coap_string_equal
#define coap_string_equal(string1, string2)
Compares the two strings for equality.
Definition coap_str.h:197
coap_delete_string
void coap_delete_string(coap_string_t *s)
Deletes the given string and releases any memory allocated.
Definition coap_str.c:46
coap_tcp_is_supported
int coap_tcp_is_supported(void)
Check whether TCP is available.
Definition coap_tcp.c:20
coap_tls_is_supported
int coap_tls_is_supported(void)
Check whether TLS is available.
Definition coap_notls.c:41
coap_ws_is_supported
int coap_ws_is_supported(void)
Check whether WebSockets is available.
Definition coap_ws.c:933
coap_dtls_is_supported
int coap_dtls_is_supported(void)
Check whether DTLS is available.
Definition coap_notls.c:36
coap_proxy_is_supported
int coap_proxy_is_supported(void)
Check whether Proxy code is available.
Definition coap_proxy.c:874
coap_wss_is_supported
int coap_wss_is_supported(void)
Check whether Secure WebSockets is available.
Definition coap_ws.c:938
coap_get_uri_path
coap_string_t * coap_get_uri_path(const coap_pdu_t *request)
Extract uri_path string from request PDU.
Definition coap_uri.c:985
coap_split_proxy_uri
int coap_split_proxy_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri)
Parses a given string into URI components.
Definition coap_uri.c:276
coap_uri_into_optlist
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.
Definition coap_uri.c:299
coap_get_query
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.
Definition coap_uri.c:934
COAP_UNUSED
#define COAP_UNUSED
Definition libcoap.h:70
coap_addr_info_t
Resolved addresses information.
Definition coap_address.h:179
coap_addr_info_t::proto
coap_proto_t proto
CoAP protocol to use.
Definition coap_address.h:182
coap_addr_info_t::addr
coap_address_t addr
The address to connect / bind to.
Definition coap_address.h:183
coap_addr_tuple_t::remote
coap_address_t remote
remote address and port
Definition coap_io.h:56
coap_address_t
Multi-purpose address abstraction.
Definition coap_address.h:148
coap_bin_const_t
CoAP binary data definition with const data.
Definition coap_str.h:64
coap_bin_const_t::length
size_t length
length of binary data
Definition coap_str.h:65
coap_bin_const_t::s
const uint8_t * s
read-only binary data
Definition coap_str.h:66
coap_binary_t
CoAP binary data definition.
Definition coap_str.h:56
coap_binary_t::s
uint8_t * s
binary data
Definition coap_str.h:58
coap_cache_key_t
Definition coap_cache_internal.h:37
coap_context_t
The CoAP stack's global state is stored in a coap_context_t object.
Definition coap_net_internal.h:50
coap_dtls_cpsk_t::client_sni
char * client_sni
If not NULL, SNI to use in client TLS setup.
Definition coap_dtls.h:437
coap_dtls_pki_t::client_sni
char * client_sni
If not NULL, SNI to use in client TLS setup.
Definition coap_dtls.h:368
coap_opt_iterator_t
Iterator to run through PDU options.
Definition coap_option.h:168
coap_opt_iterator_t::number
coap_option_num_t number
decoded option number
Definition coap_option.h:170
coap_optlist_t
Representation of chained list of CoAP options to install.
Definition coap_option.h:325
coap_pdu_t
structure for CoAP PDUs
Definition coap_pdu_internal.h:135
coap_pdu_t::code
coap_pdu_code_t code
request method (value 1–31) or response code (value 64-255)
Definition coap_pdu_internal.h:137
coap_pdu_t::type
coap_pdu_type_t type
message type
Definition coap_pdu_internal.h:136
coap_proxy_list_t
Definition coap_proxy_internal.h:37
coap_proxy_list_t::idle_timeout_ticks
coap_tick_t idle_timeout_ticks
Idle timeout (0 == no timeout).
Definition coap_proxy_internal.h:43
coap_proxy_list_t::incoming
coap_session_t * incoming
Incoming session (used if client tracking(.
Definition coap_proxy_internal.h:39
coap_proxy_list_t::req_list
coap_proxy_req_t * req_list
Incoming list of request info.
Definition coap_proxy_internal.h:40
coap_proxy_list_t::last_used
coap_tick_t last_used
Last time entry was used.
Definition coap_proxy_internal.h:44
coap_proxy_list_t::uri
coap_uri_t uri
URI info for connection.
Definition coap_proxy_internal.h:42
coap_proxy_list_t::ongoing
coap_session_t * ongoing
Ongoing session.
Definition coap_proxy_internal.h:38
coap_proxy_list_t::req_count
size_t req_count
Count of incoming request info.
Definition coap_proxy_internal.h:41
coap_proxy_req_t
Definition coap_proxy_internal.h:29
coap_proxy_req_t::pdu
coap_pdu_t * pdu
Definition coap_proxy_internal.h:30
coap_proxy_req_t::token_used
coap_bin_const_t * token_used
Definition coap_proxy_internal.h:33
coap_proxy_req_t::cache_key
coap_cache_key_t * cache_key
Definition coap_proxy_internal.h:34
coap_proxy_req_t::incoming
coap_session_t * incoming
Definition coap_proxy_internal.h:32
coap_proxy_req_t::resource
coap_resource_t * resource
Definition coap_proxy_internal.h:31
coap_proxy_server_list_t
Definition coap_proxy.h:43
coap_proxy_server_list_t::track_client_session
int track_client_session
If 1, track individual connections to upstream server, else 0.
Definition coap_proxy.h:48
coap_proxy_server_list_t::entry
coap_proxy_server_t * entry
Set of servers to connect to.
Definition coap_proxy.h:44
coap_proxy_server_list_t::type
coap_proxy_t type
The proxy type.
Definition coap_proxy.h:47
coap_proxy_server_list_t::idle_timeout_secs
unsigned int idle_timeout_secs
Proxy session idle timeout (0 is no timeout).
Definition coap_proxy.h:50
coap_proxy_server_list_t::next_entry
size_t next_entry
Next server to us (% entry_count).
Definition coap_proxy.h:46
coap_proxy_server_list_t::entry_count
size_t entry_count
The number of servers.
Definition coap_proxy.h:45
coap_proxy_server_t
Definition coap_proxy.h:36
coap_proxy_server_t::dtls_pki
coap_dtls_pki_t * dtls_pki
PKI configuration to use if not NULL.
Definition coap_proxy.h:38
coap_proxy_server_t::oscore_conf
coap_oscore_conf_t * oscore_conf
OSCORE configuration if not NULL.
Definition coap_proxy.h:40
coap_proxy_server_t::uri
coap_uri_t uri
host and port define the server, scheme method
Definition coap_proxy.h:37
coap_proxy_server_t::dtls_cpsk
coap_dtls_cpsk_t * dtls_cpsk
PSK configuration to use if not NULL.
Definition coap_proxy.h:39
coap_resource_t
Abstraction of resource that can be attached to coap_context_t.
Definition coap_resource_internal.h:53
coap_session_t
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
Definition coap_session_internal.h:68
coap_session_t::addr_info
coap_addr_tuple_t addr_info
remote/local address info
Definition coap_session_internal.h:79
coap_session_t::context
coap_context_t * context
session's context
Definition coap_session_internal.h:86
coap_str_const_t::s
const uint8_t * s
read-only string data
Definition coap_str.h:48
coap_str_const_t::length
size_t length
length of string
Definition coap_str.h:47
coap_string_t
CoAP string data definition.
Definition coap_str.h:38
coap_uri_t
Representation of parsed URI.
Definition coap_uri.h:65
coap_uri_t::scheme
enum coap_uri_scheme_t scheme
The parsed scheme specifier.
Definition coap_uri.h:77
coap_uri_t::path
coap_str_const_t path
The complete path if present or {0, NULL}.
Definition coap_uri.h:68
coap_uri_t::port
uint16_t port
The port in host byte order.
Definition coap_uri.h:67
coap_uri_t::query
coap_str_const_t query
The complete query if present or {0, NULL}.
Definition coap_uri.h:72
coap_uri_t::host
coap_str_const_t host
The host part of the URI.
Definition coap_uri.h:66