libcoap
4.3.0beta
|
Generic resource handling. More...
#include "uthash.h"
#include "async.h"
#include "block.h"
#include "str.h"
#include "pdu.h"
#include "net.h"
#include "subscribe.h"
Go to the source code of this file.
Data Structures | |
struct | coap_attr_t |
struct | coap_resource_t |
Macros | |
#define | COAP_RESOURCE_CHECK_TIME 2 |
The interval in seconds to check if resources have changed. More... | |
#define | COAP_ATTR_FLAGS_RELEASE_NAME 0x1 |
#define | COAP_ATTR_FLAGS_RELEASE_VALUE 0x2 |
#define | COAP_RESOURCE_FLAGS_RELEASE_URI 0x1 |
The URI passed to coap_resource_init() is free'd by coap_delete_resource(). More... | |
#define | COAP_RESOURCE_FLAGS_NOTIFY_NON 0x0 |
Notifications will be sent non-confirmable by default. More... | |
#define | COAP_RESOURCE_FLAGS_NOTIFY_CON 0x2 |
Notifications will be sent confirmable. More... | |
#define | COAP_RESOURCE_FLAGS_NOTIFY_NON_ALWAYS 0x4 |
Notifications will always be sent non-confirmable. More... | |
#define | COAP_PRINT_STATUS_MASK 0xF0000000u |
#define | COAP_PRINT_OUTPUT_LENGTH(v) ((v) & ~COAP_PRINT_STATUS_MASK) |
#define | COAP_PRINT_STATUS_ERROR 0x80000000u |
#define | COAP_PRINT_STATUS_TRUNC 0x40000000u |
#define | RESOURCES_ADD(r, obj) HASH_ADD(hh, (r), uri_path->s[0], (obj)->uri_path->length, (obj)) |
#define | RESOURCES_DELETE(r, obj) HASH_DELETE(hh, (r), (obj)) |
#define | RESOURCES_ITER(r, tmp) |
#define | RESOURCES_FIND(r, k, res) |
Typedefs | |
typedef 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. More... | |
typedef struct coap_attr_t | coap_attr_t |
typedef struct coap_resource_t | coap_resource_t |
typedef unsigned int | coap_print_status_t |
Status word to encode the result of conditional print or copy operations such as coap_print_link(). More... | |
Functions | |
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 . More... | |
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. More... | |
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. More... | |
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 . More... | |
COAP_STATIC_INLINE void | coap_resource_set_userdata (coap_resource_t *resource, void *data) |
Sets the user_data. More... | |
COAP_STATIC_INLINE void * | coap_resource_get_userdata (coap_resource_t *resource) |
Gets the user_data. More... | |
void | coap_add_resource (coap_context_t *context, coap_resource_t *resource) |
Registers the given resource for context . More... | |
int | coap_delete_resource (coap_context_t *context, coap_resource_t *resource) |
Deletes a resource identified by resource . More... | |
void | coap_delete_all_resources (coap_context_t *context) |
Deletes all resources from given context and frees their storage. More... | |
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 . More... | |
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. More... | |
void | coap_delete_attr (coap_attr_t *attr) |
Deletes an attribute. More... | |
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. More... | |
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 . More... | |
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 . More... | |
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 . More... | |
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 . More... | |
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. More... | |
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. More... | |
void | coap_delete_observers (coap_context_t *context, coap_session_t *session) |
Removes any subscription for session and releases the allocated storage. More... | |
COAP_STATIC_INLINE void | coap_resource_set_get_observable (coap_resource_t *resource, int mode) |
Set whether a resource is observable. More... | |
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 not NULL. More... | |
COAP_STATIC_INLINE coap_str_const_t * | coap_resource_get_uri_path (coap_resource_t *resource) |
Get the UriPath from a resource . More... | |
void | coap_check_notify (coap_context_t *context) |
Checks for all known resources, if they are dirty and notifies subscribed observers. More... | |
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 . More... | |
void | coap_handle_failed_notify (coap_context_t *, coap_session_t *, const coap_binary_t *) |
COAP_DEPRECATED int | coap_resource_set_dirty (coap_resource_t *r, const coap_string_t *query) |
Generic resource handling.
Definition in file resource.h.
#define COAP_RESOURCE_CHECK_TIME 2 |
The interval in seconds to check if resources have changed.
Definition at line 20 of file resource.h.
#define RESOURCES_ADD | ( | r, | |
obj | |||
) | HASH_ADD(hh, (r), uri_path->s[0], (obj)->uri_path->length, (obj)) |
Definition at line 422 of file resource.h.
#define RESOURCES_DELETE | ( | r, | |
obj | |||
) | HASH_DELETE(hh, (r), (obj)) |
Definition at line 425 of file resource.h.
#define RESOURCES_FIND | ( | r, | |
k, | |||
res | |||
) |
Definition at line 432 of file resource.h.
#define RESOURCES_ITER | ( | r, | |
tmp | |||
) |
Definition at line 428 of file resource.h.
void coap_check_notify | ( | coap_context_t * | context | ) |
Checks for all known resources, if they are dirty and notifies subscribed observers.
Definition at line 999 of file resource.c.
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
.
If no resource was found, this function returns NULL
.
context | The context to look for this resource. |
uri_path | The unique string uri of the resource. |
NULL
if not found. Definition at line 603 of file resource.c.
void coap_handle_failed_notify | ( | coap_context_t * | context, |
coap_session_t * | session, | ||
const coap_binary_t * | token | ||
) |
Definition at line 1062 of file resource.c.
coap_print_status_t coap_print_wellknown | ( | coap_context_t * | context, |
unsigned char * | buf, | ||
size_t * | buflen, | ||
size_t | offset, | ||
coap_opt_t * | query_filter | ||
) |
Prints the names of all known resources to buf
.
This function sets buflen
to the number of bytes actually written and returns 1
on succes. On error, the value in buflen
is undefined and the return value will be 0
.
context | The context with the resource map. |
buf | The buffer to write the result. |
buflen | Must be initialized to the maximum length of buf and will be set to the length of the well-known response on return. |
offset | The offset in bytes where the output shall start and is shifted accordingly with the characters that have been processed. This parameter is used to support the block option. |
query_filter | A filter query according to Link Format |
buf
. COAP_PRINT_STATUS_TRUNC is set when the output has been truncated. Definition at line 169 of file resource.c.
COAP_DEPRECATED int coap_resource_set_dirty | ( | coap_resource_t * | r, |
const coap_string_t * | query | ||
) |
Definition at line 943 of file resource.c.