|
libcoap
4.0.3
|
generic resource handling More...
#include "config.h"#include "t_list.h"#include <assert.h>#include "uthash.h"#include "hashkey.h"#include "async.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. | |
| #define | COAP_ATTR_FLAGS_RELEASE_NAME 0x1 |
| #define | COAP_ATTR_FLAGS_RELEASE_VALUE 0x2 |
| #define | COAP_RESOURCE_FLAGS_RELEASE_URI 0x1 |
Typedefs | |
| typedef void(* | coap_method_handler_t )(coap_context_t *, struct coap_resource_t *, coap_address_t *, coap_pdu_t *, str *, coap_pdu_t *) |
| Definition of message handler function (. | |
| typedef struct coap_attr_t | coap_attr_t |
| typedef struct coap_resource_t | coap_resource_t |
Functions | |
| 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. | |
| void | coap_add_resource (coap_context_t *context, coap_resource_t *resource) |
Registers the given resource for context. | |
| int | coap_delete_resource (coap_context_t *context, coap_key_t key) |
Deletes a resource identified by key. | |
| 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. | |
| 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. | |
| void | coap_delete_attr (coap_attr_t *attr) |
| Deletes an attribute. | |
| int | coap_print_link (const coap_resource_t *resource, unsigned char *buf, size_t *len) |
| Writes a description of this resource in link-format to given text buffer. | |
| 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_resource_t * | coap_get_resource_from_key (coap_context_t *context, coap_key_t key) |
Returns the resource identified by the unique string key. | |
| 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. | |
| coap_subscription_t * | coap_add_observer (coap_resource_t *resource, const coap_address_t *observer, const str *token) |
Adds the specified peer as observer for resource. | |
| 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. | |
| void | coap_touch_observer (coap_context_t *context, const coap_address_t *observer, const str *token) |
| Marks an observer as alive. | |
| void | 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. | |
| void | coap_check_notify (coap_context_t *context) |
| Checks for all known resources, if they are dirty and notifies subscribed observers. | |
generic resource handling
Definition in file resource.h.
| #define COAP_ATTR_FLAGS_RELEASE_NAME 0x1 |
Definition at line 45 of file resource.h.
| #define COAP_ATTR_FLAGS_RELEASE_VALUE 0x2 |
Definition at line 46 of file resource.h.
| #define COAP_RESOURCE_CHECK_TIME 2 |
The interval in seconds to check if resources have changed.
Definition at line 26 of file resource.h.
| #define COAP_RESOURCE_FLAGS_RELEASE_URI 0x1 |
Definition at line 55 of file resource.h.
| typedef struct coap_attr_t coap_attr_t |
| typedef void(* coap_method_handler_t)(coap_context_t *, struct coap_resource_t *, coap_address_t *, coap_pdu_t *, str *, coap_pdu_t *) |
Definition of message handler function (.
Definition at line 42 of file resource.h.
| typedef struct coap_resource_t coap_resource_t |
| 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.
As the attributes str fields will point to name and val the caller must ensure that these pointers are valid during the attribute's lifetime.
| resource | The resource to register the attribute with. |
| name | The attribute's name. |
| nlen | Length of name. |
| val | The attribute's value or NULL if none. |
| vlen | Length of val if specified. |
| flags | Flags for memory management (in particular release of memory) |
NULL on error. Definition at line 257 of file resource.c.
| coap_subscription_t* coap_add_observer | ( | coap_resource_t * | resource, |
| const coap_address_t * | observer, | ||
| const str * | token | ||
| ) |
Adds the specified peer as observer for resource.
The subscription is identified by the given token. This function returns the registered subscription information if the observer has been added, or NULL on error.
| resource | The observed resource. |
| observer | The remote peer that wants to received status updates. |
| token | The token that identifies this subscription. |
| token_length | The actual length of token. Must be 0 when token is NULL. |
NULL on error. Definition at line 486 of file resource.c.
| void coap_add_resource | ( | coap_context_t * | context, |
| coap_resource_t * | resource | ||
| ) |
Registers the given resource for context.
The resource must have been created by coap_resource_init(), the storage allocated for the resource will be released by coap_delete_resource().
| context | The context to use. |
| resource | The resource to store. |
Definition at line 344 of file resource.c.
| void coap_check_notify | ( | coap_context_t * | context | ) |
Checks for all known resources, if they are dirty and notifies subscribed observers.
Definition at line 620 of file resource.c.
| void coap_delete_attr | ( | coap_attr_t * | attr | ) |
Deletes an attribute.
| attr | Pointer to a previously created attribute |
Definition at line 317 of file resource.c.
| void 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.
| resource | The observed resource. |
| observer | The observer's address. |
| token | The token that identifies this subscription or NULL for any token. |
Definition at line 548 of file resource.c.
| int coap_delete_resource | ( | coap_context_t * | context, |
| coap_key_t | key | ||
| ) |
Deletes a resource identified by key.
The storage allocated for that resource is freed.
| context | The context where the resources are stored. |
| key | The unique key for the resource to delete. |
1 if the resource was found (and destroyed), 0 otherwise. Definition at line 351 of file resource.c.
| 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.
| resource | The resource to search for attribute name. |
| name | Name of the requested attribute. |
| nlen | Actual length of name. |
name or NULL if none was found. Definition at line 295 of file resource.c.
| 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.
| resource | The observed resource. |
| peer | The address to search for. |
| token | The token that identifies this subscription or NULL for any token. |
NULL otherwise. Definition at line 468 of file resource.c.
| 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.
If no resource was found, this function returns NULL.
| context | The context to look for this resource. |
| key | The unique key of the resource. |
NULL if not found. Definition at line 394 of file resource.c.
| 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.
This function calls coap_hash() for every path segment.
| request | The requesting pdu. |
| key | The resulting hash is stored in key |
Definition at line 328 of file resource.c.
| int coap_print_link | ( | const coap_resource_t * | resource, |
| unsigned char * | buf, | ||
| size_t * | len | ||
| ) |
Writes a description of this resource in link-format to given text buffer.
len must be initialized to the maximum length of buf and will be set to the number of characters actually written if successful. This function returns 1 on success or 0 on error.
| resource | The resource to describe. |
| buf | The output buffer to write the description to. |
| len | Must be initialized to the length of buf and will be set to the number of characters written on success. |
1 on success, or 0 on error. If 0, len is undefined. Definition at line 418 of file resource.c.
|
inlinestatic |
Registers the specified handler as message handler for the request type method.
| resource | The resource for which the handler shall be registered. |
| method | The CoAP request method to handle. |
| handler | The handler to register with resource. |
Definition at line 191 of file resource.h.
| 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.
This function returns the new coap_resource_t object.
| uri | The URI path of the new resource. |
| len | The length of uri. |
| flags | Flags for memory management (in particular release of memory) |
NULL on error. Definition at line 226 of file resource.c.
| void coap_touch_observer | ( | coap_context_t * | context, |
| const coap_address_t * | observer, | ||
| const str * | token | ||
| ) |
Marks an observer as alive.
| context | The CoAP context to use |
| observer | The transport address of the observer |
| token | The corresponding token that has been used for the subscription |
Definition at line 522 of file resource.c.
1.8.1.2