15 #ifndef COAP_RESOURCE_H_
16 #define COAP_RESOURCE_H_
18 #ifndef COAP_RESOURCE_CHECK_TIME
20 #define COAP_RESOURCE_CHECK_TIME 2
49 #define COAP_ATTR_FLAGS_RELEASE_NAME 0x1
50 #define COAP_ATTR_FLAGS_RELEASE_VALUE 0x2
60 #define COAP_RESOURCE_FLAGS_RELEASE_URI 0x1
67 #define COAP_RESOURCE_FLAGS_NOTIFY_NON 0x0
73 #define COAP_RESOURCE_FLAGS_NOTIFY_CON 0x2
83 #define COAP_RESOURCE_FLAGS_NOTIFY_NON_ALWAYS 0x4
224 size_t host_name_count,
const char *host_name_list[]);
365 #define COAP_PRINT_STATUS_MASK 0xF0000000u
366 #define COAP_PRINT_OUTPUT_LENGTH(v) ((v) & ~COAP_PRINT_STATUS_MASK)
367 #define COAP_PRINT_STATUS_ERROR 0x80000000u
368 #define COAP_PRINT_STATUS_TRUNC 0x40000000u
422 #define RESOURCES_ADD(r, obj) \
423 HASH_ADD(hh, (r), uri_path->s[0], (obj)->uri_path->length, (obj))
425 #define RESOURCES_DELETE(r, obj) \
426 HASH_DELETE(hh, (r), (obj))
428 #define RESOURCES_ITER(r,tmp) \
429 coap_resource_t *tmp, *rtmp; \
430 HASH_ITER(hh, (r), tmp, rtmp)
432 #define RESOURCES_FIND(r, k, res) { \
433 HASH_FIND(hh, (r), (k)->s, (k)->length, (res)); \
State management for asynchronous messages.
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.
void(* coap_method_handler_t)(coap_context_t *, struct coap_resource_t *, coap_session_t *, coap_pdu_t *, coap_binary_t *, coap_string_t *, coap_pdu_t *)
Definition of message handler function.
#define COAP_RESOURCE_FLAGS_NOTIFY_NON
Notifications will be sent non-confirmable by default.
COAP_STATIC_INLINE void coap_resource_set_userdata(coap_resource_t *resource, void *data)
Sets the user_data.
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.
void coap_delete_all_resources(coap_context_t *context)
Deletes all resources from given context and frees their storage.
COAP_STATIC_INLINE void coap_resource_set_mode(coap_resource_t *resource, int mode)
Sets the notification message type of resource resource to given mode.
void coap_delete_attr(coap_attr_t *attr)
Deletes an attribute.
COAP_STATIC_INLINE void * coap_resource_get_userdata(coap_resource_t *resource)
Gets the user_data.
#define COAP_RESOURCE_FLAGS_NOTIFY_CON
Notifications will be sent confirmable.
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.
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.
struct coap_attr_t coap_attr_t
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.
unsigned int coap_print_status_t
Status word to encode the result of conditional print or copy operations such as coap_print_link().
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_add_resource(coap_context_t *context, coap_resource_t *resource)
Registers the given resource for context.
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.
int coap_delete_resource(coap_context_t *context, coap_resource_t *resource)
Deletes a resource identified by resource.
struct coap_resource_t coap_resource_t
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...
int coap_delete_observer(coap_resource_t *resource, coap_session_t *session, const coap_binary_t *token)
Removes any subscription for observer from resource and releases the allocated storage.
coap_subscription_t * coap_add_observer(coap_resource_t *resource, coap_session_t *session, const coap_binary_t *token, coap_string_t *query, int has_block2, coap_block_t block2, uint8_t code)
Adds the specified peer as observer for resource.
coap_subscription_t * coap_find_observer(coap_resource_t *resource, coap_session_t *session, const coap_binary_t *token)
Returns a subscription object for given peer.
void coap_delete_observers(coap_context_t *context, coap_session_t *session)
Removes any subscription for session and releases the allocated storage.
COAP_STATIC_INLINE void coap_resource_set_get_observable(coap_resource_t *resource, int mode)
Set whether a resource is observable.
void coap_touch_observer(coap_context_t *context, coap_session_t *session, const coap_binary_t *token)
Flags that data is ready to be sent to observers.
COAP_STATIC_INLINE coap_str_const_t * coap_resource_get_uri_path(coap_resource_t *resource)
Get the UriPath from a resource.
#define COAP_STATIC_INLINE
uint8_t coap_opt_t
Use byte-oriented access methods here because sliding a complex struct coap_opt_t over the data buffe...
Pre-defined constants that reflect defaults for CoAP.
COAP_DEPRECATED int coap_resource_set_dirty(coap_resource_t *r, const coap_string_t *query)
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.
void coap_handle_failed_notify(coap_context_t *, coap_session_t *, const coap_binary_t *)
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.
void coap_check_notify(coap_context_t *context)
Checks for all known resources, if they are dirty and notifies subscribed observers.
struct coap_attr_t * next
CoAP binary data definition.
Structure of Block options.
The CoAP stack's global state is stored in a coap_context_t object.
structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload mark...
unsigned int dirty
set to 1 if resource has changed
unsigned int partiallydirty
set to 1 if some subscribers have not yet been notified of the last change
coap_subscription_t * subscribers
list of observers for this resource
void * user_data
This pointer is under user control.
coap_str_const_t ** proxy_name_list
Array valid names this host is known by (proxy support)
coap_str_const_t * uri_path
Request URI Path for this resource.
unsigned int observe
The next value for the Observe option.
unsigned int cacheable
can be cached
coap_context_t * context
Pointer back to the context that 'owns' this resource.
coap_method_handler_t handler[7]
Used to store handlers for the seven coap methods GET, POST, PUT, DELETE, FETCH, PATCH and IPATCH.
unsigned int is_proxy_uri
resource created for proxy URI handler
unsigned int is_unknown
resource created for unknown handler
coap_attr_t * link_attr
attributes to be included with the link format
unsigned int observable
can be observed
size_t proxy_name_count
Count of valid names this host is known by (proxy support)
CoAP string data definition with const data.
CoAP string data definition.
Defines the application visible subscribe information.