libcoap  4.3.0
resource.c File Reference
#include "coap3/coap_internal.h"
#include <stdio.h>
#include <errno.h>
+ Include dependency graph for resource.c:

Go to the source code of this file.

Macros

#define COAP_MALLOC_TYPE(Type)    ((coap_##Type##_t *)coap_malloc(sizeof(coap_##Type##_t)))
 
#define COAP_FREE_TYPE(Type, Object)   coap_free(Object)
 
#define COAP_PRINT_STATUS_MAX   (~COAP_PRINT_STATUS_MASK)
 
#define min(a, b)   ((a) < (b) ? (a) : (b))
 
#define PRINT_WITH_OFFSET(Buf, Offset, Char)
 Adds Char to Buf if Offset is zero. More...
 
#define PRINT_COND_WITH_OFFSET(Buf, Bufend, Offset, Char, Result)
 Adds Char to Buf if Offset is zero and Buf is less than Bufend. More...
 
#define COPY_COND_WITH_OFFSET(Buf, Bufend, Offset, Str, Length, Result)
 Copies at most Length characters of Str to Buf. More...
 
#define MATCH_URI   0x01
 
#define MATCH_PREFIX   0x02
 
#define MATCH_SUBSTRING   0x04
 
#define INET6_ADDRSTRLEN   40
 

Typedefs

typedef enum coap_deleting_resource_t coap_deleting_resource_t
 

Enumerations

enum  coap_deleting_resource_t { COAP_DELETING_RESOURCE , COAP_NOT_DELETING_RESOURCE }
 

Functions

static int match (const coap_str_const_t *text, const coap_str_const_t *pattern, int match_prefix, int match_substring)
 
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. More...
 
coap_resource_tcoap_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_tcoap_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_tcoap_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_attr_tcoap_add_attr (coap_resource_t *resource, coap_str_const_t *name, coap_str_const_t *val, int flags)
 Registers a new attribute with the given resource. More...
 
coap_attr_tcoap_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...
 
coap_str_const_tcoap_attr_get_value (coap_attr_t *attr)
 Returns attribute's value. More...
 
void coap_delete_attr (coap_attr_t *attr)
 Deletes an attribute. More...
 
static void coap_notify_observers (coap_context_t *context, coap_resource_t *r, coap_deleting_resource_t deleting)
 
static void coap_free_resource (coap_resource_t *resource)
 
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_resource_tcoap_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_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_subscription_tcoap_find_observer (coap_resource_t *resource, coap_session_t *session, const coap_binary_t *token)
 Returns a subscription object for given peer. More...
 
static coap_subscription_tcoap_find_observer_cache_key (coap_resource_t *resource, coap_session_t *session, const coap_cache_key_t *cache_key)
 
coap_subscription_tcoap_add_observer (coap_resource_t *resource, coap_session_t *session, const coap_binary_t *token, const coap_pdu_t *request)
 Adds the specified peer as observer for resource. 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...
 
int coap_resource_set_dirty (coap_resource_t *r, const coap_string_t *query)
 
int coap_resource_notify_observers (coap_resource_t *r, const coap_string_t *query COAP_UNUSED)
 
void coap_resource_set_mode (coap_resource_t *resource, int mode)
 Sets the notification message type of resource resource to given mode. More...
 
void coap_resource_set_userdata (coap_resource_t *resource, void *data)
 Sets the user_data. More...
 
void * coap_resource_get_userdata (coap_resource_t *resource)
 Gets the user_data. More...
 
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 the resource's user_data. More...
 
void coap_resource_set_get_observable (coap_resource_t *resource, int mode)
 Set whether a resource is observable. More...
 
coap_str_const_tcoap_resource_get_uri_path (coap_resource_t *resource)
 Get the uri_path from a resource. More...
 
void coap_check_notify (coap_context_t *context)
 Checks all known resources to see if they are dirty and then notifies subscribed observers. More...
 
static void coap_remove_failed_observers (coap_context_t *context, coap_resource_t *resource, coap_session_t *session, const coap_binary_t *token)
 Checks the failure counter for (peer, token) and removes peer from the list of observers for the given resource when COAP_OBS_MAX_FAIL is reached. More...
 
void coap_handle_failed_notify (coap_context_t *context, coap_session_t *session, const coap_binary_t *token)
 Handles a failed observe notify. More...
 

Variables

static coap_str_const_t null_path_value = {0, (const uint8_t*)""}
 
static coap_str_const_tnull_path = &null_path_value
 
static const uint8_t coap_unknown_resource_uri []
 
static const uint8_t coap_proxy_resource_uri []
 

Macro Definition Documentation

◆ COAP_FREE_TYPE

#define COAP_FREE_TYPE (   Type,
  Object 
)    coap_free(Object)

Definition at line 60 of file resource.c.

◆ COAP_MALLOC_TYPE

#define COAP_MALLOC_TYPE (   Type)     ((coap_##Type##_t *)coap_malloc(sizeof(coap_##Type##_t)))

Definition at line 58 of file resource.c.

◆ COAP_PRINT_STATUS_MAX

#define COAP_PRINT_STATUS_MAX   (~COAP_PRINT_STATUS_MASK)

Definition at line 63 of file resource.c.

◆ COPY_COND_WITH_OFFSET

#define COPY_COND_WITH_OFFSET (   Buf,
  Bufend,
  Offset,
  Str,
  Length,
  Result 
)
Value:
{ \
size_t i; \
for (i = 0; i < (Length); i++) { \
PRINT_COND_WITH_OFFSET((Buf), (Bufend), (Offset), (Str)[i], (Result)); \
} \
}

Copies at most Length characters of Str to Buf.

The first Offset characters are skipped. Output may be truncated to Bufend - Buf characters.

Definition at line 99 of file resource.c.

◆ INET6_ADDRSTRLEN

#define INET6_ADDRSTRLEN   40

◆ MATCH_PREFIX

#define MATCH_PREFIX   0x02

◆ MATCH_SUBSTRING

#define MATCH_SUBSTRING   0x04

◆ MATCH_URI

#define MATCH_URI   0x01

◆ min

#define min (   a,
 
)    ((a) < (b) ? (a) : (b))

Definition at line 66 of file resource.c.

◆ PRINT_COND_WITH_OFFSET

#define PRINT_COND_WITH_OFFSET (   Buf,
  Bufend,
  Offset,
  Char,
  Result 
)
Value:
{ \
if ((Buf) < (Bufend)) { \
PRINT_WITH_OFFSET(Buf,Offset,Char); \
} \
(Result)++; \
}

Adds Char to Buf if Offset is zero and Buf is less than Bufend.

Definition at line 87 of file resource.c.

◆ PRINT_WITH_OFFSET

#define PRINT_WITH_OFFSET (   Buf,
  Offset,
  Char 
)
Value:
if ((Offset) == 0) { \
(*(Buf)++) = (Char); \
} else { \
(Offset)--; \
} \

Adds Char to Buf if Offset is zero.

Otherwise, Char is not written and Offset is decremented.

Definition at line 77 of file resource.c.

Typedef Documentation

◆ coap_deleting_resource_t

Enumeration Type Documentation

◆ coap_deleting_resource_t

Enumerator
COAP_DELETING_RESOURCE 
COAP_NOT_DELETING_RESOURCE 

Definition at line 484 of file resource.c.

Function Documentation

◆ coap_find_observer_cache_key()

static coap_subscription_t* coap_find_observer_cache_key ( coap_resource_t resource,
coap_session_t session,
const coap_cache_key_t cache_key 
)
static

Definition at line 704 of file resource.c.

+ Here is the caller graph for this function:

◆ coap_free_resource()

static void coap_free_resource ( coap_resource_t resource)
static

Definition at line 493 of file resource.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_notify_observers()

static void coap_notify_observers ( coap_context_t context,
coap_resource_t r,
coap_deleting_resource_t  deleting 
)
static

Definition at line 858 of file resource.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_remove_failed_observers()

static void coap_remove_failed_observers ( coap_context_t context,
coap_resource_t resource,
coap_session_t session,
const coap_binary_t token 
)
static

Checks the failure counter for (peer, token) and removes peer from the list of observers for the given resource when COAP_OBS_MAX_FAIL is reached.

Parameters
contextThe CoAP context to use
resourceThe resource to check for (peer, token)
sessionThe observer's session
tokenThe token that has been used for subscription.

Definition at line 1083 of file resource.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_resource_notify_observers()

int coap_resource_notify_observers ( coap_resource_t r,
const coap_string_t *query  COAP_UNUSED 
)

Definition at line 993 of file resource.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_resource_set_dirty()

int coap_resource_set_dirty ( coap_resource_t r,
const coap_string_t query 
)
Deprecated:
use coap_resource_notify_observers() instead.

Definition at line 988 of file resource.c.

+ Here is the call graph for this function:

◆ match()

static int match ( const coap_str_const_t text,
const coap_str_const_t pattern,
int  match_prefix,
int  match_substring 
)
static

Definition at line 107 of file resource.c.

+ Here is the caller graph for this function:

Variable Documentation

◆ coap_proxy_resource_uri

const uint8_t coap_proxy_resource_uri[]
static
Initial value:
=
"- Proxy URI -"

Definition at line 354 of file resource.c.

◆ coap_unknown_resource_uri

const uint8_t coap_unknown_resource_uri[]
static
Initial value:
=
"- Unknown -"

Definition at line 333 of file resource.c.

◆ null_path

coap_str_const_t* null_path = &null_path_value
static

Definition at line 300 of file resource.c.

◆ null_path_value

coap_str_const_t null_path_value = {0, (const uint8_t*)""}
static

Definition at line 299 of file resource.c.