15 #ifndef _COAP_RESOURCE_H_ 16 #define _COAP_RESOURCE_H_ 20 #ifndef COAP_RESOURCE_CHECK_TIME 22 #define COAP_RESOURCE_CHECK_TIME 2 25 #ifdef COAP_RESOURCES_NOHASH 50 #define COAP_ATTR_FLAGS_RELEASE_NAME 0x1 51 #define COAP_ATTR_FLAGS_RELEASE_VALUE 0x2 61 #define COAP_RESOURCE_FLAGS_RELEASE_URI 0x1 67 #define COAP_RESOURCE_FLAGS_NOTIFY_NON 0x0 73 #define COAP_RESOURCE_FLAGS_NOTIFY_CON 0x2 77 unsigned int partiallydirty:1;
79 unsigned int observable:1;
80 unsigned int cacheable:1;
92 #ifdef COAP_RESOURCES_NOHASH 121 size_t len,
int flags);
180 const unsigned char *
name,
182 const unsigned char *val,
197 const unsigned char *
name,
219 #define COAP_PRINT_STATUS_MASK 0xF0000000u 220 #define COAP_PRINT_OUTPUT_LENGTH(v) ((v) & ~COAP_PRINT_STATUS_MASK) 221 #define COAP_PRINT_STATUS_ERROR 0x80000000u 222 #define COAP_PRINT_STATUS_TRUNC 0x40000000u 260 unsigned char method,
307 const coap_endpoint_t *local_interface,
308 const coap_address_t *observer,
321 const coap_address_t *peer,
333 const coap_address_t *observer,
348 const coap_address_t *observer,
357 #ifdef COAP_RESOURCES_NOHASH 359 #define RESOURCES_ADD(r, obj) \ 360 LL_PREPEND((r), (obj)) 362 #define RESOURCES_DELETE(r, obj) \ 363 LL_DELETE((r), (obj)) 365 #define RESOURCES_ITER(r,tmp) \ 366 coap_resource_t *tmp; \ 369 #define RESOURCES_FIND(r, k, res) { \ 370 coap_resource_t *tmp; \ 371 (res) = tmp = NULL; \ 372 LL_FOREACH((r), tmp) { \ 373 if (memcmp((k), tmp->key, sizeof(coap_key_t)) == 0) { \ 381 #define RESOURCES_ADD(r, obj) \ 382 HASH_ADD(hh, (r), key, sizeof(coap_key_t), (obj)) 384 #define RESOURCES_DELETE(r, obj) \ 385 HASH_DELETE(hh, (r), (obj)) 387 #define RESOURCES_ITER(r,tmp) \ 388 coap_resource_t *tmp, *rtmp; \ 389 HASH_ITER(hh, (r), tmp, rtmp) 391 #define RESOURCES_FIND(r, k, res) { \ 392 HASH_FIND(hh, (r), (k), sizeof(coap_key_t), (res)); \ 405 const coap_address_t *,
unsigned char coap_key_t[4]
multi-purpose address abstraction
State management for asynchronous messages.
static void coap_resource_set_mode(coap_resource_t *r, int mode)
Sets the notification message type of resource r to given mode which must be one of COAP_RESOURCE_FLA...
int coap_delete_observer(coap_resource_t *resource, const coap_address_t *observer, const str *token)
Removes any subscription for observer from resource and releases the allocated storage.
coap_attr_t * link_attr
attributes to be included with the link format
coap_resource_t * coap_get_resource_from_key(coap_context_t *context, coap_key_t key)
Returns the resource identified by the unique string key.
int coap_delete_resource(coap_context_t *context, coap_key_t key)
Deletes a resource identified by key.
void coap_check_notify(coap_context_t *context)
Checks for all known resources, if they are dirty and notifies subscribed observers.
Abstraction of virtual endpoint that can be attached to coap_context_t.
void coap_delete_all_resources(coap_context_t *context)
Deletes all resources from given context and frees their storage.
void coap_hash_request_uri(const coap_pdu_t *request, coap_key_t key)
Calculates the hash key for the resource requested by the Uri-Options of request. ...
str uri
Request URI for this resource.
Header structure for CoAP PDUs.
coap_subscription_t * coap_find_observer(coap_resource_t *resource, const coap_address_t *peer, const str *token)
Returns a subscription object for given peer.
coap_key_t key
the actual key bytes for this resource
static void coap_register_handler(coap_resource_t *resource, unsigned char method, coap_method_handler_t handler)
Registers the specified handler as message handler for the request type method.
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_attr_t * coap_find_attr(coap_resource_t *resource, const unsigned char *name, size_t nlen)
Returns resource's coap_attr_t object with given name if found, NULL otherwise.
struct coap_resource_t coap_resource_t
coap_subscription_t * coap_add_observer(coap_resource_t *resource, const coap_endpoint_t *local_interface, const coap_address_t *observer, const str *token)
Adds the specified peer as observer for resource.
struct coap_attr_t coap_attr_t
coap_subscription_t * subscribers
list of observers for this resource
coap_attr_t * coap_add_attr(coap_resource_t *resource, const unsigned char *name, size_t nlen, const unsigned char *val, size_t vlen, int flags)
Registers a new attribute with the given resource.
Pre-defined constants that reflect defaults for CoAP.
coap_print_status_t coap_print_wellknown(coap_context_t *, unsigned char *, size_t *, size_t, coap_opt_t *)
Prints the names of all known resources to buf.
#define COAP_RESOURCE_FLAGS_NOTIFY_CON
Notifications will be sent confirmable by default.
void coap_add_resource(coap_context_t *context, coap_resource_t *resource)
Registers the given resource for context.
definition of hash key type and helper functions
struct coap_attr_t * next
coap_resource_t * coap_resource_init(const unsigned char *uri, size_t len, int flags)
Creates a new resource object and initializes the link field to the string of length len...
unsigned int coap_print_status_t
Status word to encode the result of conditional print or copy operations such as coap_print_link().
unsigned char coap_opt_t
Use byte-oriented access methods here because sliding a complex struct coap_opt_t over the data buffe...
void coap_handle_failed_notify(coap_context_t *, const coap_address_t *, const str *)
void(* coap_method_handler_t)(coap_context_t *, struct coap_resource_t *, const coap_endpoint_t *, coap_address_t *, coap_pdu_t *, str *, coap_pdu_t *)
Definition of message handler function (.
The CoAP stack's global state is stored in a coap_context_t object.
void coap_touch_observer(coap_context_t *context, const coap_address_t *observer, const str *token)
Marks an observer as alive.
void coap_delete_attr(coap_attr_t *attr)
Deletes an attribute.
coap_method_handler_t handler[4]
Used to store handlers for the four coap methods GET, POST, PUT, and DELETE.