resource.h
Go to the documentation of this file.
/*
* resource.h -- generic resource handling
*
* Copyright (C) 2010,2011,2014-2021 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_H_
#define COAP_RESOURCE_H_
#ifndef COAP_RESOURCE_CHECK_TIME
#define COAP_RESOURCE_CHECK_TIME 2
#endif /* COAP_RESOURCE_CHECK_TIME */
#include "async.h"
#include "block.h"
#include "str.h"
#include "pdu.h"
#include "net.h"
#include "subscribe.h"
typedef void (*coap_method_handler_t)
(coap_resource_t *,
coap_session_t *,
const coap_pdu_t * /* request */,
const coap_string_t * /* query string */,
coap_pdu_t * /* response */);
#define COAP_ATTR_FLAGS_RELEASE_NAME 0x1
#define COAP_ATTR_FLAGS_RELEASE_VALUE 0x2
#define COAP_RESOURCE_FLAGS_RELEASE_URI 0x1
#define COAP_RESOURCE_FLAGS_NOTIFY_NON 0x0
#define COAP_RESOURCE_FLAGS_NOTIFY_CON 0x2
#define COAP_RESOURCE_FLAGS_NOTIFY_NON_ALWAYS 0x4
coap_resource_t *coap_resource_init(coap_str_const_t *uri_path,
int flags);
coap_resource_t *coap_resource_unknown_init(coap_method_handler_t put_handler);
coap_resource_t *coap_resource_proxy_uri_init(coap_method_handler_t handler,
size_t host_name_count, const char *host_name_list[]);
coap_resource_t *coap_get_resource_from_uri_path(coap_context_t *context,
coap_str_const_t *uri_path);
coap_str_const_t* coap_resource_get_uri_path(coap_resource_t *resource);
void coap_resource_set_mode(coap_resource_t *resource, int mode);
void coap_resource_set_userdata(coap_resource_t *resource, void *data);
void *coap_resource_get_userdata(coap_resource_t *resource);
typedef void (*coap_resource_release_userdata_handler_t)(void *user_data);
void coap_resource_release_userdata_handler(coap_context_t *context,
coap_resource_release_userdata_handler_t callback);
void coap_add_resource(coap_context_t *context, coap_resource_t *resource);
int coap_delete_resource(coap_context_t *context, coap_resource_t *resource);
void coap_register_handler(coap_resource_t *resource,
coap_request_t method,
coap_method_handler_t handler);
coap_attr_t *coap_add_attr(coap_resource_t *resource,
coap_str_const_t *name,
coap_str_const_t *value,
int flags);
coap_attr_t *coap_find_attr(coap_resource_t *resource,
coap_str_const_t *name);
coap_str_const_t *coap_attr_get_value(coap_attr_t *attribute);
typedef unsigned int coap_print_status_t;
#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
coap_print_status_t coap_print_link(const coap_resource_t *resource,
unsigned char *buf,
size_t *len,
size_t *offset);
coap_resource_t *coap_get_resource_from_uri_path(coap_context_t *context,
coap_str_const_t *uri_path);
COAP_DEPRECATED int
coap_resource_set_dirty(coap_resource_t *r,
const coap_string_t *query);
#endif /* COAP_RESOURCE_H_ */
async.h
State management for asynchronous messages.
block.h
coap_resource_proxy_uri_init
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.
Definition: resource.c:358
coap_print_link
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.
Definition: resource.c:624
coap_resource_set_mode
void coap_resource_set_mode(coap_resource_t *resource, int mode)
Sets the notification message type of resource resource to given mode.
Definition: resource.c:1027
coap_resource_get_uri_path
coap_str_const_t * coap_resource_get_uri_path(coap_resource_t *resource)
Get the uri_path from a resource.
Definition: resource.c:1055
coap_attr_get_value
coap_str_const_t * coap_attr_get_value(coap_attr_t *attribute)
Returns attribute's value.
Definition: resource.c:461
coap_resource_release_userdata_handler
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 ...
Definition: resource.c:1044
coap_get_resource_from_uri_path
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.
Definition: resource.c:615
coap_register_handler
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.
Definition: resource.c:677
coap_resource_unknown_init
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.
Definition: resource.c:337
coap_find_attr
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.
Definition: resource.c:444
coap_print_status_t
unsigned int coap_print_status_t
Status word to encode the result of conditional print or copy operations such as coap_print_link().
Definition: resource.h:324
coap_method_handler_t
void(* coap_method_handler_t)(coap_resource_t *, coap_session_t *, const coap_pdu_t *, const coap_string_t *, coap_pdu_t *)
Definition of message handler function.
Definition: resource.h:42
coap_resource_init
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.
Definition: resource.c:303
coap_resource_release_userdata_handler_t
void(* coap_resource_release_userdata_handler_t)(void *user_data)
Definition of release resource user_data callback function.
Definition: resource.h:212
coap_add_resource
void coap_add_resource(coap_context_t *context, coap_resource_t *resource)
Registers the given resource for context.
Definition: resource.c:536
coap_resource_set_userdata
void coap_resource_set_userdata(coap_resource_t *resource, void *data)
Sets the user_data.
Definition: resource.c:1034
coap_add_attr
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.
Definition: resource.c:407
coap_delete_resource
int coap_delete_resource(coap_context_t *context, coap_resource_t *resource)
Deletes a resource identified by resource.
Definition: resource.c:565
coap_resource_get_userdata
void * coap_resource_get_userdata(coap_resource_t *resource)
Gets the user_data.
Definition: resource.c:1039
coap_request_t
coap_request_t
CoAP PDU Request methods.
Definition: pdu.h:66
COAP_DEPRECATED
#define COAP_DEPRECATED
Definition: libcoap.h:48
net.h
pdu.h
Pre-defined constants that reflect defaults for CoAP.
coap_resource_set_dirty
COAP_DEPRECATED int coap_resource_set_dirty(coap_resource_t *r, const coap_string_t *query)
Definition: resource.c:988
str.h
coap_attr_t
Abstraction of attribute associated with a resource.
Definition: coap_resource_internal.h:31
coap_context_t
The CoAP stack's global state is stored in a coap_context_t object.
Definition: coap_net_internal.h:45
coap_pdu_t
structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload mark...
Definition: coap_pdu_internal.h:94
coap_resource_t
Abstraction of resource that can be attached to coap_context_t.
Definition: coap_resource_internal.h:42
coap_session_t
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
Definition: coap_session_internal.h:48
coap_str_const_t
CoAP string data definition with const data.
Definition: str.h:40
coap_string_t
CoAP string data definition.
Definition: str.h:32
subscribe.h
Defines the application visible subscribe information.