18#if COAP_SERVER_SUPPORT
21#ifdef COAP_EPOLL_SUPPORT
23#include <sys/timerfd.h>
27#define min(a,b) ((a) < (b) ? (a) : (b))
38#define PRINT_WITH_OFFSET(Buf,Offset,Char) \
39 if ((Offset) == 0) { \
40 (*(Buf)++) = (Char); \
48#define PRINT_COND_WITH_OFFSET(Buf,Bufend,Offset,Char,Result) { \
49 if ((Buf) < (Bufend)) { \
50 PRINT_WITH_OFFSET(Buf,Offset,Char); \
60#define COPY_COND_WITH_OFFSET(Buf,Bufend,Offset,Str,Length,Result) { \
62 for (i = 0; i < (Length); i++) { \
63 PRINT_COND_WITH_OFFSET((Buf), (Bufend), (Offset), (Str)[i], (Result)); \
67#ifndef WITHOUT_QUERY_FILTER
71 const uint8_t *next_token = text->
s;
72 size_t remaining_length = text->
length;
79 while (remaining_length) {
81 const uint8_t *token = next_token;
82 next_token = (
const unsigned char *)memchr(token,
' ', remaining_length);
85 token_length = next_token - token;
86 remaining_length -= (token_length + 1);
89 token_length = remaining_length;
93 if (token_length >= pattern->
length &&
94 (match_prefix || pattern->
length == token_length) &&
95 memcmp(token, pattern->
s, pattern->
length) == 0)
104 size_t *buflen,
size_t offset,
108 result = coap_print_wellknown_lkd(context, buf, buflen, offset, query_filter);
119coap_print_wellknown_lkd(
coap_context_t *context,
unsigned char *buf,
120 size_t *buflen,
size_t offset,
123 unsigned char *p = buf;
124 const uint8_t *bufend = buf + *buflen;
125 size_t left, written = 0;
127 const size_t old_offset = offset;
128 int subsequent_resource = 0;
129#ifdef WITHOUT_QUERY_FILTER
134#ifndef WITHOUT_QUERY_FILTER
137 unsigned char *next_query = (
unsigned char *)memchr(query_filterm->
s,
'&', query_filterm->
length);
138 size_t query_filterm_rem;
142 query_filter.
s = query_filterm->
s;
144 query_filter.
length = next_query - query_filter.
s;
146 query_filterm_rem = query_filterm->
length - query_filter.
length - 1;
149 query_filterm_rem = 0;
152 while (query_filter.
length) {
160#define MATCH_URI 0x01
161#define MATCH_PREFIX 0x02
163 resource_param.
s = query_filter.
s;
165 resource_param.
s[resource_param.
length] !=
'=')
169 if (resource_param.
length == 4 &&
170 memcmp(resource_param.
s,
"href", 4) == 0)
175 query_filter.
s + resource_param.
length + 1;
177 assert((resource_param.
length + 1) <= query_filter.
length);
178 query_pattern.length =
181 if (query_pattern.length &&
182 (query_pattern.s[0] ==
'/') && ((flags & MATCH_URI) == MATCH_URI)) {
184 query_pattern.length--;
187 if (query_pattern.length &&
188 query_pattern.s[query_pattern.length-1] ==
'*') {
189 query_pattern.length--;
190 flags |= MATCH_PREFIX;
194 RESOURCES_ITER(context->resources, r) {
203 if (resource_param.
length) {
205 if ((flags & MATCH_PREFIX) && query_pattern.length == 0) {
206 int present = (flags & MATCH_URI) ||
207 (r->observable && resource_param.
length == 3 &&
208 memcmp(resource_param.
s,
"obs", 3) == 0) ||
209#if COAP_OSCORE_SUPPORT
211 resource_param.
length == 3 && memcmp(resource_param.
s,
"osc", 3) == 0) ||
212#
if COAP_OSCORE_GROUP_SUPPORT
214 resource_param.
length == 4 && memcmp(resource_param.
s,
"gosc", 4) == 0) ||
220 }
else if (flags & MATCH_URI) {
221 if (!match(r->uri_path, &query_pattern, (flags & MATCH_PREFIX) != 0))
227 if (!attr || !attr->value)
229 unquoted_val = *attr->value;
231 if (attr->value->length >= 2 && attr->value->s[0] ==
'"') {
235 if (!match(&unquoted_val, &query_pattern, (flags & MATCH_PREFIX) != 0))
240 if (!subsequent_resource) {
241 subsequent_resource = 1;
243 PRINT_COND_WITH_OFFSET(p, bufend, offset,
',', written);
258 query_filter.
s = next_query;
260 next_query = (
unsigned char *)memchr(next_query,
'&', query_filterm_rem);
262 query_filter.
length = next_query - query_filter.
s;
264 query_filterm_rem = query_filterm_rem - query_filter.
length - 1;
266 query_filter.
length = query_filterm_rem;
267 query_filterm_rem = 0;
270 query_filter.
length = query_filterm_rem;
271 query_filterm_rem = 0;
276 RESOURCES_ITER(context->resources, r) {
286 if (!subsequent_resource) {
287 subsequent_resource = 1;
289 PRINT_COND_WITH_OFFSET(p, bufend, offset,
',', written);
304#ifndef WITHOUT_QUERY_FILTER
317 if (result + old_offset - offset < *buflen) {
343 }
else if (!uri_path) {
349 r->uri_path = uri_path;
360static const uint8_t coap_unknown_resource_uri[] =
375 r->uri_path =
coap_new_str_const(coap_unknown_resource_uri,
sizeof(coap_unknown_resource_uri)-1);
390static const uint8_t coap_proxy_resource_uri[] =
395 size_t host_name_count,
396 const char *host_name_list[],
int flags) {
408 r->uri_path =
coap_new_str_const(coap_proxy_resource_uri,
sizeof(coap_proxy_resource_uri)-1);
410 for (i = 0; i < (
sizeof(r->handler) /
sizeof(r->handler[0])); i++) {
411 r->handler[i] = handler;
413 if (host_name_count) {
416 if (r->proxy_name_list) {
417 for (i = 0; i < host_name_count; i++) {
418 r->proxy_name_list[i] =
420 strlen(host_name_list[i]));
421 if (!r->proxy_name_list[i]) {
422 coap_log_err(
"coap_resource_proxy_uri_init: unable to add host name\n");
425 r->proxy_name_list =
NULL;
430 r->proxy_name_count = i;
436 coap_log_debug(
"coap_resource_proxy_uri_init2: no memory left\n");
444 size_t host_name_count,
const char *host_name_list[]) {
449static const uint8_t coap_rev_proxy_resource_uri[] =
463 r->is_reverse_proxy = 1;
466 sizeof(coap_rev_proxy_resource_uri)-1);
490 if (!resource || !name)
511 LL_PREPEND(resource->link_attr, attr);
524 if (!resource || !name)
527 LL_FOREACH(resource->link_attr, attr) {
528 if (attr->name->length == name->
length &&
529 memcmp(attr->name->s, name->
s, name->
length) == 0)
556 coap_deleting_resource_t deleting);
559coap_free_resource(
coap_resource_t *resource, coap_deleting_resource_t deleting) {
566 context = resource->context;
568 if (!context->observe_no_clear) {
569 coap_resource_notify_observers_lkd(resource, deleting);
570 coap_notify_observers(context, resource, deleting);
573 if (context->resource_deleted_cb)
576 context->observe_user_data));
578 if (context->release_userdata_cb && resource->user_data) {
584 LL_FOREACH_SAFE(resource->link_attr, attr, tmp) coap_delete_attr(attr);
590 LL_FOREACH_SAFE(resource->subscribers, obs, otmp) {
591 coap_delete_observer_internal(resource, obs->session, obs);
593 if (resource->proxy_name_count && resource->proxy_name_list) {
596 for (i = 0; i < resource->proxy_name_count; i++) {
608 coap_add_resource_lkd(context, resource);
615 if (resource->is_unknown) {
616 if (context->unknown_resource)
617 coap_free_resource(context->unknown_resource, COAP_DELETING_RESOURCE);
618 context->unknown_resource = resource;
619 }
else if (resource->is_proxy_uri) {
620 if (context->proxy_uri_resource)
621 coap_free_resource(context->proxy_uri_resource, COAP_DELETING_RESOURCE);
622 context->proxy_uri_resource = resource;
628 coap_log_warn(
"coap_add_resource: Duplicate uri_path '%*.*s', old resource deleted\n",
629 (
int)resource->uri_path->length, (
int)resource->uri_path->length,
630 resource->uri_path->s);
631 coap_delete_resource_lkd(r);
633 RESOURCES_ADD(context->resources, resource);
634#if COAP_WITH_OBSERVE_PERSIST
635 if (context->unknown_pdu && context->dyn_resource_save_file &&
636 context->dyn_resource_added_cb && resource->observable) {
639 raw_packet.
s = context->unknown_pdu->token -
640 context->unknown_pdu->hdr_size;
641 raw_packet.
length = context->unknown_pdu->used_size +
642 context->unknown_pdu->hdr_size;
646 context->observe_user_data));
650 assert(resource->context ==
NULL);
651 resource->context = context;
663 ret = coap_delete_resource_lkd(resource);
674 coap_deleting_resource_t deleting;
679 context = resource->context;
686 if (context && context->context_going_away) {
687 deleting = COAP_DELETING_RESOURCE_ON_EXIT;
689 deleting = COAP_DELETING_RESOURCE;
691 if (resource->is_unknown) {
692 if (context && context->unknown_resource == resource) {
693 context->unknown_resource =
NULL;
695 }
else if (resource->is_proxy_uri) {
696 if (context && context->proxy_uri_resource == resource) {
697 context->proxy_uri_resource =
NULL;
699 }
else if (context) {
701 RESOURCES_DELETE(context->resources, resource);
703 if (resource->is_dynamic) {
711 coap_free_resource(resource, deleting);
718 return coap_delete_resource_lkd(resource);
726 RESOURCE_ITER_SAFE(context->resources, r, tmp) {
727 coap_delete_resource_lkd(r);
730 context->resources =
NULL;
732 if (context->unknown_resource) {
733 coap_delete_resource_lkd(context->unknown_resource);
734 context->unknown_resource =
NULL;
736 if (context->proxy_uri_resource) {
737 coap_delete_resource_lkd(context->proxy_uri_resource);
738 context->proxy_uri_resource =
NULL;
747 result = coap_get_resource_from_uri_path_lkd(context, uri_path);
760 RESOURCES_FIND(context->resources, uri_path, result);
767 unsigned char *buf,
size_t *len,
size_t *offset) {
768 unsigned char *p = buf;
769 const uint8_t *bufend = buf + *len;
773 const size_t old_offset = *offset;
776 PRINT_COND_WITH_OFFSET(p, bufend, *offset,
'<', *len);
777 PRINT_COND_WITH_OFFSET(p, bufend, *offset,
'/', *len);
779 COPY_COND_WITH_OFFSET(p, bufend, *offset,
780 resource->uri_path->s, resource->uri_path->length, *len);
782 PRINT_COND_WITH_OFFSET(p, bufend, *offset,
'>', *len);
784 LL_FOREACH(resource->link_attr, attr) {
786 PRINT_COND_WITH_OFFSET(p, bufend, *offset,
';', *len);
788 COPY_COND_WITH_OFFSET(p, bufend, *offset,
789 attr->name->s, attr->name->length, *len);
791 if (attr->value && attr->value->s) {
792 PRINT_COND_WITH_OFFSET(p, bufend, *offset,
'=', *len);
794 COPY_COND_WITH_OFFSET(p, bufend, *offset,
795 attr->value->s, attr->value->length, *len);
800 if (resource->observable) {
801 COPY_COND_WITH_OFFSET(p, bufend, *offset,
";obs", 4, *len);
804#if COAP_OSCORE_SUPPORT
806#if COAP_OSCORE_GROUP_SUPPORT
807 COPY_COND_WITH_OFFSET(p, bufend, *offset,
";gosc;osc", 9, *len);
809 COPY_COND_WITH_OFFSET(p, bufend, *offset,
";osc", 4, *len);
822 if (result + old_offset - *offset < *len) {
841 assert(method > 0 && (
size_t)(method-1) <
843 resource->handler[method-1] = handler;
854 LL_FOREACH(resource->subscribers, s) {
855 if (s->session == session &&
871 LL_FOREACH(resource->subscribers, s) {
872 if (s->session == session
897 s = coap_find_observer(resource, session, token);
906 cache_ignore_options,
907 sizeof(cache_ignore_options)/
sizeof(cache_ignore_options[0]));
909 s = coap_find_observer_cache_key(resource, session, cache_key);
912 coap_delete_observer(resource, session, &s->pdu->actual_token);
925#if (COAP_RESOURCE_MAX_SUBSCRIBER > 0)
926 uint32_t subscriber_count = 0;
927 LL_COUNT(resource->subscribers, s, subscriber_count);
928 if (subscriber_count >= COAP_RESOURCE_MAX_SUBSCRIBER) {
941 coap_subscription_init(s);
944 if (s->pdu ==
NULL) {
951 s->pdu->max_size = 0;
954 if (cache_key ==
NULL) {
957 cache_ignore_options,
958 sizeof(cache_ignore_options)/
sizeof(cache_ignore_options[0]));
959 if (cache_key ==
NULL) {
966 s->cache_key = cache_key;
969 session->ref_subscriptions++;
972 LL_PREPEND(resource->subscribers, s);
974 coap_log_debug(
"create new subscription %p key 0x%02x%02x%02x%02x\n",
975 (
void *)s, s->cache_key->key[0], s->cache_key->key[1],
976 s->cache_key->key[2], s->cache_key->key[3]);
982#if COAP_OSCORE_SUPPORT
985 if (session->recipient_ctx && session->recipient_ctx->recipient_id) {
999 uint8_t info_buffer[60];
1000 uint8_t *info_buf = info_buffer;
1001 size_t info_len =
sizeof(info_buffer);
1008 session->recipient_ctx->recipient_id->s,
1009 session->recipient_ctx->recipient_id->length);
1010 if (session->recipient_ctx->osc_ctx &&
1011 session->recipient_ctx->osc_ctx->id_context) {
1014 session->recipient_ctx->osc_ctx->id_context->s,
1015 session->recipient_ctx->osc_ctx->id_context->length);
1021 if (association->
aad) {
1024 association->
aad->
s,
1037 if (association->
nonce) {
1049 if (ret >
sizeof(info_buffer)) {
1052 ret =
sizeof(info_buffer);
1059 memcpy(s->pdu->token - request->
hdr_size,
1061 raw_packet.
s = s->pdu->token - request->
hdr_size;
1064 &session->endpoint->bind_addr,
1068 session->
context->observe_user_data));
1069#if COAP_OSCORE_SUPPORT
1073 if (resource->context->track_observe_value_cb) {
1075 coap_lock_callback(resource->context->track_observe_value_cb(resource->context,resource->uri_path,
1077 resource->context->observe_user_data));
1088 RESOURCES_ITER(context->resources, r) {
1089 s = coap_find_observer(r, session, token);
1103 char outbuf[2 * 8 + 1] =
"";
1108 for (i = 0; i < s->pdu->actual_token.length; i++) {
1109 size_t size = strlen(outbuf);
1111 snprintf(&outbuf[size],
sizeof(outbuf)-size,
"%02x",
1112 s->pdu->actual_token.s[i]);
1116 coap_log_debug(
"removed subscription '/%*.*s%s%*.*s' (%p) with token '%s' key 0x%02x%02x%02x%02x\n",
1117 uri_path ? (
int)uri_path->
length : 0, uri_path ? (
int)uri_path->
length : 0,
1118 uri_path ? (
char *)uri_path->
s :
"",
1119 uri_query ?
"?" :
"",
1120 uri_query ? (
int)uri_query->
length : 0, uri_query ? (
int)uri_query->
length : 0,
1121 uri_query ? (
char *)uri_query->
s :
"",
1122 (
void *)s, outbuf, s->cache_key->key[0], s->cache_key->key[1],
1123 s->cache_key->key[2], s-> cache_key->key[3]);
1127 if (session->
context->observe_deleted_cb)
1129 session->
context->observe_user_data));
1131 if (resource->subscribers) {
1132 LL_DELETE(resource->subscribers, s);
1133 assert(session->ref_subscriptions > 0);
1134 session->ref_subscriptions--;
1149 s = coap_find_observer(resource, session, token);
1151 coap_delete_observer_internal(resource, session, s);
1162 s = coap_find_observer(resource, session, token);
1163 if (!s && large_fetch) {
1172 cache_ignore_options,
1173 sizeof(cache_ignore_options)/
sizeof(cache_ignore_options[0]));
1175 s = coap_find_observer_cache_key(resource, session, cache_key);
1178 ret = coap_delete_observer(resource, session, &s->pdu->actual_token);
1183 coap_delete_observer_internal(resource, session, s);
1191 RESOURCES_ITER(context->resources, resource) {
1193 LL_FOREACH_SAFE(resource->subscribers, s, tmp) {
1194 if (s->session == session) {
1195 if (context->observe_deleted_cb)
1196 coap_lock_callback(context->observe_deleted_cb(session, s, context->observe_user_data));
1197 assert(resource->subscribers);
1198 LL_DELETE(resource->subscribers, s);
1210 coap_deleting_resource_t deleting) {
1221 if (r->observable && (r->dirty || r->partiallydirty)) {
1222 if (r->list_being_traversed)
1224 r->list_being_traversed = 1;
1226 coap_resource_reference_lkd(r);
1228 r->partiallydirty = 0;
1238 LL_FOREACH(r->subscribers, obs) {
1246 LL_FOREACH(r->subscribers, obs) {
1254 if ((r->dirty == 0 && obs->dirty == 0) || obs->session->is_rate_limiting) {
1259 context->observe_pending = 1;
1267 obs_session = obs->session;
1272 if (obs->session->con_active >=
COAP_NSTART(obs->session) &&
1274 (obs->non_cnt >= COAP_OBS_MAX_NON))) {
1279 if (obs->session->lg_xmit && obs->session->lg_xmit->last_all_sent == 0 &&
1280 obs->session->lg_xmit->last_obs &&
1296 coap_log_debug(
"coap_check_notify: pdu init failed, resource stays "
1297 "partially dirty\n");
1298 goto next_one_fail_no_pending;
1302 obs->pdu->actual_token.s)) {
1303 coap_log_debug(
"coap_check_notify: cannot add token, resource stays "
1304 "partially dirty\n");
1306 goto next_one_fail_no_pending;
1314 obs->non_cnt < COAP_OBS_MAX_NON)) {
1320 case COAP_NOT_DELETING_RESOURCE:
1336#if COAP_Q_BLOCK_SUPPORT
1349 h = r->handler[obs->pdu->code - 1];
1356 (
int)r->uri_path->length, (
int)r->uri_path->length,
1367 r->list_being_traversed = 0;
1368 coap_resource_release_lkd(r);
1372 h(r, obs_session, obs_pdu, query, response),
1378 r->list_being_traversed = 0;
1379 coap_resource_release_lkd(r);
1385 coap_log_warn(
"handle_request: Invalid PDU response code (%d.%02d)\n",
1387 response->
code & 0x1f);
1392 r->list_being_traversed = 0;
1393 coap_resource_release_lkd(r);
1404 coap_delete_observer(r, obs_session, &obs_pdu->
actual_token);
1408 case COAP_DELETING_RESOURCE_ON_EXIT:
1417 case COAP_DELETING_RESOURCE:
1431 LL_FOREACH(r->subscribers, s) {
1447#if COAP_Q_BLOCK_SUPPORT
1453 mid = coap_send_q_block2(obs_session, r, query, obs_pdu->
code,
1454 block, response, 1);
1476#if COAP_Q_BLOCK_SUPPORT
1480 coap_log_debug(
"* %s: coap_check_notify: sending failed, resource stays "
1488 LL_FOREACH(r->subscribers, s) {
1498 r->partiallydirty = 1;
1503 context->observe_pending = 1;
1504next_one_fail_no_pending:
1505 r->partiallydirty = 1;
1512 r->list_being_traversed = 0;
1514 coap_resource_release_lkd(r);
1527 ret = coap_resource_notify_observers_lkd(r, COAP_NOT_DELETING_RESOURCE);
1539 ret = coap_resource_notify_observers_lkd(r, COAP_NOT_DELETING_RESOURCE);
1546 coap_deleting_resource_t deleting) {
1550 if (!r->subscribers)
1555 r->observe = (r->observe + 1) & 0xFFFFFF;
1559 if (r->context->track_observe_value_cb) {
1561 if ((r->observe % r->context->observe_save_freq) == 0)
1564 r->context->observe_user_data));
1567 coap_notify_observers(r->context, r, deleting);
1573 resource->flags = (resource->flags &
1580 resource->user_data = data;
1585 return resource->user_data;
1591 context->release_userdata_cb = callback;
1596 if (resource->is_unknown || resource->is_proxy_uri) {
1598 coap_log_debug(
"coap_resource_set_get_observable: Not supported for Unknown or Proxy URIs\n");
1599 resource->observable = 0;
1601 resource->observable = mode ? 1 : 0;
1608 return resource->uri_path;
1615 coap_check_notify_lkd(context);
1623 if (context->observe_pending) {
1624 context->observe_pending = 0;
1625 RESOURCES_ITER(context->resources, r) {
1626 coap_notify_observers(context, r, COAP_NOT_DELETING_RESOURCE);
1633 uint32_t start_observe_no) {
1637 resource->observe = start_observe_no & 0xffffff;
1657 LL_FOREACH_SAFE(resource->subscribers, obs, otmp) {
1658 if (obs->session == session &&
1663 if (obs->fail_cnt >= COAP_OBS_MAX_FAIL) {
1665 &obs->pdu->actual_token);
1666 coap_delete_observer(resource, session, token);
1678 RESOURCES_ITER(context->resources, r) {
1679 coap_remove_failed_observers(context, r, session, token);
1697#if COAP_WITH_OBSERVE_PERSIST
1699 context->unknown_pdu = pdu;
1700 context->unknown_session = session;
1703#if COAP_WITH_OBSERVE_PERSIST
1705 context->unknown_pdu =
NULL;
1706 context->unknown_session =
NULL;
1710 resource->is_dynamic = 1;
int coap_is_af_unix(const coap_address_t *a)
Checks if given address a denotes a AF_UNIX address.
void coap_address_copy(coap_address_t *dst, const coap_address_t *src)
struct coap_cache_key_t coap_cache_key_t
struct coap_attr_t coap_attr_t
struct coap_subscription_t coap_subscription_t
struct coap_resource_t coap_resource_t
Library specific build wrapper for coap_internal.h.
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().
COAP_DEPRECATED COAP_API int coap_resource_set_dirty(coap_resource_t *r, const coap_string_t *query)
void coap_check_code_lg_xmit(const coap_session_t *session, const coap_pdu_t *request, coap_pdu_t *response, const coap_resource_t *resource, const coap_string_t *query)
The function checks that the code in a newly formed lg_xmit created by coap_add_data_large_response_l...
int coap_get_block_b(const coap_session_t *session, const coap_pdu_t *pdu, coap_option_num_t number, coap_block_b_t *block)
Initializes block from pdu.
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_IS_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.
COAP_API coap_resource_t * coap_get_resource_from_uri_path(coap_context_t *context, coap_str_const_t *uri_path)
Returns the resource identified by the unique string uri_path.
#define COAP_RESOURCE_FLAGS_NOTIFY_NON
Observe Notifications will be sent non-confirmable by default.
coap_resource_t * coap_resource_proxy_uri_init(coap_method_handler_t handler, size_t host_name_count, const char *host_name_list[])
Creates a new resource object for handling proxy URIs.
coap_attr_t * coap_add_attr(coap_resource_t *resource, coap_str_const_t *name, coap_str_const_t *value, int flags)
Registers a new attribute with the given resource.
#define COAP_ATTR_FLAGS_RELEASE_VALUE
coap_print_status_t coap_print_link(const coap_resource_t *resource, unsigned char *buf, size_t *len, size_t *offset)
Writes a description of this resource in link-format to given text buffer.
coap_resource_t * coap_resource_proxy_uri_init2(coap_method_handler_t handler, size_t host_name_count, const char *host_name_list[], int flags)
Creates a new resource object for handling proxy URIs with configurable control over multicast reques...
#define COAP_RESOURCE_FLAGS_NOTIFY_NON_ALWAYS
Observe Notifications will always be sent non-confirmable.
#define COAP_RESOURCE_HANDLE_WELLKNOWN_CORE
Define this when invoking coap_resource_unknown_init2() if .well-known/core is to be passed to the un...
#define COAP_ATTR_FLAGS_RELEASE_NAME
void coap_resource_set_mode(coap_resource_t *resource, int mode)
Sets the notification message type of resource resource to given mode.
#define COAP_RESOURCE_SAFE_REQUEST_HANDLER
Don't lock this resource when calling app call-back handler for requests as handler will not be manip...
#define COAP_PRINT_STATUS_TRUNC
void(* coap_method_handler_t)(coap_resource_t *resource, coap_session_t *session, const coap_pdu_t *request, const coap_string_t *query, coap_pdu_t *response)
Definition of message handler function.
void coap_resource_release_userdata_handler(coap_context_t *context, coap_resource_release_userdata_handler_t callback)
Defines the context wide callback to use to when the resource is deleted to release the data held in ...
#define COAP_RESOURCE_FLAGS_OSCORE_ONLY
Define this resource as an OSCORE enabled access only.
COAP_API coap_print_status_t coap_print_wellknown(coap_context_t *context, unsigned char *buf, size_t *buflen, size_t offset, const coap_string_t *query_filter)
Prints the names of all known resources for context to buf.
#define COAP_RESOURCE_FLAGS_NOTIFY_CON
Observe Notifications will be sent confirmable.
coap_resource_t * coap_resource_reverse_proxy_init(coap_method_handler_t handler, int flags)
Creates a new resource object for the reverse-proxy resource handler with control over multicast requ...
COAP_API int coap_delete_resource(coap_context_t *context, coap_resource_t *resource)
Deletes a resource identified by resource.
void coap_register_handler(coap_resource_t *resource, coap_request_t method, coap_method_handler_t handler)
Registers the specified handler as message handler for the request type method.
#define COAP_PRINT_STATUS_MAX
void(* coap_resource_release_userdata_handler_t)(void *user_data)
Definition of release resource user_data callback function.
void coap_register_request_handler(coap_resource_t *resource, coap_request_t method, coap_method_handler_t handler)
Registers the specified handler as message handler for the request type method.
coap_resource_t * coap_resource_init(coap_str_const_t *uri_path, int flags)
Creates a new resource object and initializes the link field to the string uri_path.
void coap_resource_set_userdata(coap_resource_t *resource, void *data)
Sets the user_data.
uint32_t coap_print_status_t
Status word to encode the result of conditional print or copy operations such as coap_print_link().
#define COAP_PRINT_STATUS_ERROR
coap_str_const_t * coap_resource_get_uri_path(coap_resource_t *resource)
Get the uri_path from a resource.
coap_resource_t * coap_resource_unknown_init2(coap_method_handler_t put_handler, int flags)
Creates a new resource object for the unknown resource handler with support for PUT and configurable ...
#define COAP_RESOURCE_FLAGS_FORCE_SINGLE_BODY
Force all large traffic to this resource to be presented as a single body to the request handler.
coap_str_const_t * coap_attr_get_value(coap_attr_t *attribute)
Returns attribute's value.
#define COAP_PRINT_OUTPUT_LENGTH(v)
coap_attr_t * coap_find_attr(coap_resource_t *resource, coap_str_const_t *name)
Returns resource's coap_attr_t object with given name if found, NULL otherwise.
void * coap_resource_get_userdata(coap_resource_t *resource)
Gets the user_data.
COAP_API void coap_add_resource(coap_context_t *context, coap_resource_t *resource)
Registers the given resource for context.
#define COAP_RESOURCE_FLAGS_RELEASE_URI
The URI passed to coap_resource_init() is free'd by coap_delete_resource().
coap_resource_t * coap_resource_unknown_init(coap_method_handler_t put_handler)
Creates a new resource object for the unknown resource handler with support for PUT.
#define COAP_RESOURCE_HIDE_WELLKNOWN_CORE
Hide this resource from .well-known/core.
uint16_t coap_new_message_id_lkd(coap_session_t *session)
Returns a new message id and updates session->tx_mid accordingly.
coap_mid_t coap_send_internal(coap_session_t *session, coap_pdu_t *pdu, coap_pdu_t *request_pdu)
Sends a CoAP message to given peer.
int coap_check_code_class(coap_session_t *session, coap_pdu_t *pdu)
Check whether the pdu contains a valid code class.
void coap_cancel_all_messages(coap_context_t *context, coap_session_t *session, coap_bin_const_t *token)
Cancels all outstanding messages for session session that have the specified token.
void coap_ticks(coap_tick_t *t)
Returns the current value of an internal tick counter.
unsigned int coap_encode_var_safe(uint8_t *buf, size_t length, unsigned int val)
Encodes multiple-length byte sequences.
#define coap_lock_specific_callback_release(lock, func, failed)
Dummy for no thread-safe code.
#define coap_lock_callback(func)
Dummy for no thread-safe code.
#define coap_lock_init(lock)
Dummy for no thread-safe code.
#define coap_lock_callback_ret(r, func)
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_callback_release(func, failed)
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.
const char * coap_session_str(const coap_session_t *session)
Get session description.
#define coap_log_warn(...)
#define coap_log_err(...)
void coap_persist_set_observe_num(coap_resource_t *resource, uint32_t observe_num)
Sets the current observe number value.
void coap_resource_set_get_observable(coap_resource_t *resource, int mode)
Set whether a resource is observable.
COAP_API void coap_check_notify(coap_context_t *context)
Checks all known resources to see if they are dirty and then notifies subscribed observers.
COAP_API int coap_resource_notify_observers(coap_resource_t *resource, const coap_string_t *query)
Initiate the sending of an Observe packet for all observers of resource, optionally matching query if...
size_t oscore_cbor_put_nil(uint8_t **buffer, size_t *buf_size)
size_t oscore_cbor_put_bytes(uint8_t **buffer, size_t *buf_size, const uint8_t *bytes, size_t bytes_len)
size_t oscore_cbor_put_array(uint8_t **buffer, size_t *buf_size, size_t elements)
oscore_association_t * oscore_find_association(coap_session_t *session, coap_bin_const_t *token)
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.
int coap_remove_option(coap_pdu_t *pdu, coap_option_num_t number)
Removes (first) option of given number from the pdu.
#define COAP_DROPPED_RESPONSE
Indicates that a response is suppressed.
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, coap_bool_t expand_opt_abb)
Duplicate an existing PDU.
COAP_STATIC_INLINE void coap_pdu_release_lkd(coap_pdu_t *pdu)
size_t coap_add_option_internal(coap_pdu_t *pdu, coap_option_num_t number, size_t len, const uint8_t *data)
Adds option of given number to pdu that is passed as first parameter.
int coap_mid_t
coap_mid_t is used to store the CoAP Message ID of a CoAP PDU.
coap_request_t
CoAP PDU Request methods.
#define COAP_RESPONSE_CODE(N)
#define COAP_RESPONSE_CLASS(C)
int coap_add_token(coap_pdu_t *pdu, size_t len, const uint8_t *data)
Adds token of length len to pdu.
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.
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.
#define COAP_INVALID_MID
Indicates an invalid message id.
#define COAP_DEFAULT_URI_WELLKNOWN
well-known resources URI
int coap_add_data(coap_pdu_t *pdu, size_t len, const uint8_t *data)
Adds given data to the pdu that is passed as first parameter.
void coap_session_hold_lkd(coap_session_t *session)
Mark the session as in use for a unit of work (reading and dispatching received data,...
void coap_session_unhold_lkd(coap_session_t *session)
End a unit of work started by coap_session_hold_lkd().
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.
coap_session_t * coap_session_reference_lkd(coap_session_t *session)
Increment reference counter on a session.
#define COAP_PROTO_NOT_RELIABLE(p)
void coap_delete_bin_const(coap_bin_const_t *s)
Deletes the given const binary data and releases any memory allocated.
void coap_delete_str_const(coap_str_const_t *s)
Deletes the given const string and releases any memory 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...
#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.
coap_str_const_t * coap_new_str_const(const uint8_t *data, size_t size)
Returns a new const string object with at least size+1 bytes storage allocated, and the provided data...
void coap_delete_string(coap_string_t *s)
Deletes the given string and releases any memory allocated.
coap_string_t * coap_get_uri_path(const coap_pdu_t *request)
Extract uri_path string from request PDU.
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.
coap_address_t local
local address and port
CoAP binary data definition with const data.
size_t length
length of binary data
const uint8_t * s
read-only binary data
Structure of Block options with BERT support.
unsigned int aszx
block size (0-7 including BERT
unsigned int m
1 if more blocks follow, 0 otherwise
unsigned int szx
block size (0-6)
The CoAP stack's global state is stored in a coap_context_t object.
uint32_t dynamic_cur
Current number of dynamic resources.
coap_resource_dynamic_create_t dyn_create_handler
Dynamic resource create handler.
uint32_t dynamic_max
Max number of dynamic resources or 0 is unlimited.
uint8_t * token
first byte of token (or extended length bytes prefix), if any, or options
coap_pdu_code_t code
request method (value 1–31) or response code (value 64-255)
uint8_t hdr_size
actual size used for protocol-specific header (0 until header is encoded)
coap_bin_const_t actual_token
Actual token in pdu.
coap_mid_t mid
message id, if any, in regular host byte order
coap_pdu_type_t type
message type
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
coap_addr_tuple_t addr_info
remote/local address info
coap_proto_t proto
protocol used
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.
size_t length
length of string
coap_bin_const_t * partial_iv