Loading...
Searching...
No Matches
coap_resource_internal.h
Go to the documentation of this file.
/*
* coap_resource_internal.h -- generic resource handling
*
* Copyright (C) 2010,2011,2014-2024 Olaf Bergmann <bergmann@tzi.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*
* This file is part of the CoAP library libcoap. Please see README for terms
* of use.
*/
#ifndef COAP_RESOURCE_INTERNAL_H_
#define COAP_RESOURCE_INTERNAL_H_
#include "coap_internal.h"
#include "coap_uthash_internal.h"
#if COAP_SERVER_SUPPORT
#ifndef COAP_RESOURCE_MAX_SUBSCRIBER
#define COAP_RESOURCE_MAX_SUBSCRIBER 0
#endif /* COAP_RESOURCE_MAX_SUBSCRIBER */
struct coap_attr_t {
struct coap_attr_t *next;
coap_str_const_t *name;
coap_str_const_t *value;
int flags;
};
struct coap_resource_t {
unsigned int dirty:1;
unsigned int partiallydirty:1;
unsigned int observable:1;
unsigned int cacheable:1;
unsigned int is_unknown:1;
unsigned int is_proxy_uri:1;
coap_method_handler_t handler[7];
UT_hash_handle hh;
coap_attr_t *link_attr;
coap_subscription_t *subscribers;
coap_str_const_t *uri_path;
int flags;
unsigned int observe;
coap_context_t *context;
size_t proxy_name_count;
coap_str_const_t **proxy_name_list;
void *user_data;
};
void coap_add_resource_lkd(coap_context_t *context, coap_resource_t *resource);
int coap_delete_resource_lkd(coap_context_t *context, coap_resource_t *resource);
void coap_delete_all_resources(coap_context_t *context);
#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) \
coap_resource_t *tmp, *rtmp; \
HASH_ITER(hh, (r), tmp, rtmp)
#define RESOURCES_FIND(r, k, res) { \
HASH_FIND(hh, (r), (k)->s, (k)->length, (res)); \
}
coap_resource_t *coap_get_resource_from_uri_path_lkd(coap_context_t *context,
coap_str_const_t *uri_path);
void coap_delete_attr(coap_attr_t *attr);
coap_print_status_t coap_print_wellknown_lkd(coap_context_t *context,
unsigned char *buf,
size_t *buflen,
size_t offset,
const coap_string_t *query_filter);
#endif /* COAP_SERVER_SUPPORT */
#endif /* COAP_RESOURCE_INTERNAL_H_ */
coap_internal.h
Pulls together all the internal only header files.
coap_delete_all_resources
void coap_delete_all_resources(coap_context_t *context)
Deletes all resources from given context and frees their storage.
coap_print_wellknown_lkd
coap_print_status_t coap_print_wellknown_lkd(coap_context_t *context, unsigned char *buf, size_t *buflen, size_t offset, const coap_string_t *query_filter)
Prints the names of all known resources for context to buf.
coap_delete_attr
void coap_delete_attr(coap_attr_t *attr)
Deletes an attribute.
coap_get_resource_from_uri_path_lkd
coap_resource_t * coap_get_resource_from_uri_path_lkd(coap_context_t *context, coap_str_const_t *uri_path)
Returns the resource identified by the unique string uri_path.
coap_add_resource_lkd
void coap_add_resource_lkd(coap_context_t *context, coap_resource_t *resource)
Registers the given resource for context.
coap_delete_resource_lkd
int coap_delete_resource_lkd(coap_context_t *context, coap_resource_t *resource)
Deletes a resource identified by resource.
coap_method_handler_t
void(* coap_method_handler_t)(coap_resource_t *resource, coap_session_t *session, const coap_pdu_t *request, const coap_string_t *query, coap_pdu_t *response)
Definition of message handler function.
Definition coap_resource.h:41
coap_print_status_t
uint32_t coap_print_status_t
Status word to encode the result of conditional print or copy operations such as coap_print_link().
Definition coap_resource.h:489
coap_attr_t
Limits the number of subscribers for each resource that this server support.
Definition coap_resource_internal.h:42
coap_attr_t::value
coap_str_const_t * value
Value of the attribute (can be NULL).
Definition coap_resource_internal.h:45
coap_attr_t::next
struct coap_attr_t * next
Pointer to next in chain or NULL.
Definition coap_resource_internal.h:43
coap_attr_t::name
coap_str_const_t * name
Name of the attribute.
Definition coap_resource_internal.h:44
coap_attr_t::flags
int flags
Definition coap_resource_internal.h:46
coap_context_t
The CoAP stack's global state is stored in a coap_context_t object.
Definition coap_net_internal.h:50
coap_resource_t
Abstraction of resource that can be attached to coap_context_t.
Definition coap_resource_internal.h:53
coap_resource_t::dirty
unsigned int dirty
set to 1 if resource has changed
Definition coap_resource_internal.h:54
coap_resource_t::partiallydirty
unsigned int partiallydirty
set to 1 if some subscribers have not yet been notified of the last change
Definition coap_resource_internal.h:55
coap_resource_t::subscribers
coap_subscription_t * subscribers
list of observers for this resource
Definition coap_resource_internal.h:74
coap_resource_t::user_data
void * user_data
This pointer is under user control.
Definition coap_resource_internal.h:110
coap_resource_t::proxy_name_list
coap_str_const_t ** proxy_name_list
Array valid names this host is known by (proxy support).
Definition coap_resource_internal.h:104
coap_resource_t::uri_path
coap_str_const_t * uri_path
Request URI Path for this resource.
Definition coap_resource_internal.h:81
coap_resource_t::observe
unsigned int observe
The next value for the Observe option.
Definition coap_resource_internal.h:89
coap_resource_t::cacheable
unsigned int cacheable
can be cached
Definition coap_resource_internal.h:58
coap_resource_t::context
coap_context_t * context
Pointer back to the context that 'owns' this resource.
Definition coap_resource_internal.h:94
coap_resource_t::handler
coap_method_handler_t handler[7]
Used to store handlers for the seven coap methods GET, POST, PUT, DELETE, FETCH, PATCH and IPATCH.
Definition coap_resource_internal.h:69
coap_resource_t::is_proxy_uri
unsigned int is_proxy_uri
resource created for proxy URI handler
Definition coap_resource_internal.h:60
coap_resource_t::is_unknown
unsigned int is_unknown
resource created for unknown handler
Definition coap_resource_internal.h:59
coap_resource_t::link_attr
coap_attr_t * link_attr
attributes to be included with the link format
Definition coap_resource_internal.h:73
coap_resource_t::observable
unsigned int observable
can be observed
Definition coap_resource_internal.h:57
coap_resource_t::proxy_name_count
size_t proxy_name_count
Count of valid names this host is known by (proxy support).
Definition coap_resource_internal.h:99
coap_resource_t::flags
int flags
zero or more COAP_RESOURCE_FLAGS_* or'd together
Definition coap_resource_internal.h:83
coap_resource_t::hh
UT_hash_handle hh
Definition coap_resource_internal.h:71
coap_str_const_t
CoAP string data definition with const data.
Definition coap_str.h:46
coap_string_t
CoAP string data definition.
Definition coap_str.h:38
coap_subscription_t
Number of notifications that may be sent non-confirmable before a confirmable message is sent to dete...
Definition coap_subscribe_internal.h:57