libcoap 4.3.5-develop-19cef11
coap_resource.h
Go to the documentation of this file.
1/*
2 * coap_resource.h -- generic resource handling
3 *
4 * Copyright (C) 2010,2011,2014-2024 Olaf Bergmann <bergmann@tzi.org>
5 *
6 * SPDX-License-Identifier: BSD-2-Clause
7 *
8 * This file is part of the CoAP library libcoap. Please see README for terms
9 * of use.
10 */
11
17#ifndef COAP_RESOURCE_H_
18#define COAP_RESOURCE_H_
19
20#ifndef COAP_RESOURCE_CHECK_TIME
22#define COAP_RESOURCE_CHECK_TIME 2
23#endif /* COAP_RESOURCE_CHECK_TIME */
24
41typedef void (*coap_method_handler_t)(coap_resource_t *resource,
42 coap_session_t *session,
43 const coap_pdu_t *request,
44 const coap_string_t *query,
45 coap_pdu_t *response);
46
47#define COAP_ATTR_FLAGS_RELEASE_NAME 0x1
48#define COAP_ATTR_FLAGS_RELEASE_VALUE 0x2
49
51#define COAP_RESOURCE_FLAGS_RELEASE_URI 0x1
52
59#define COAP_RESOURCE_FLAGS_NOTIFY_NON 0x0
60
65#define COAP_RESOURCE_FLAGS_NOTIFY_CON 0x2
66
75#define COAP_RESOURCE_FLAGS_NOTIFY_NON_ALWAYS 0x4
76
85#define COAP_RESOURCE_FLAGS_HAS_MCAST_SUPPORT 0x8
86
96#define COAP_RESOURCE_FLAGS_LIB_DIS_MCAST_DELAYS 0x10
97
105#define COAP_RESOURCE_FLAGS_LIB_ENA_MCAST_SUPPRESS_2_05 0x20
106
114#define COAP_RESOURCE_FLAGS_LIB_ENA_MCAST_SUPPRESS_2_XX 0x40
115
123#define COAP_RESOURCE_FLAGS_LIB_DIS_MCAST_SUPPRESS_4_XX 0x80
124
132#define COAP_RESOURCE_FLAGS_LIB_DIS_MCAST_SUPPRESS_5_XX 0x100
133
134#define COAP_RESOURCE_FLAGS_MCAST_LIST \
135 (COAP_RESOURCE_FLAGS_HAS_MCAST_SUPPORT | \
136 COAP_RESOURCE_FLAGS_LIB_DIS_MCAST_DELAYS | \
137 COAP_RESOURCE_FLAGS_LIB_ENA_MCAST_SUPPRESS_2_05 | \
138 COAP_RESOURCE_FLAGS_LIB_ENA_MCAST_SUPPRESS_2_XX | \
139 COAP_RESOURCE_FLAGS_LIB_DIS_MCAST_SUPPRESS_4_XX | \
140 COAP_RESOURCE_FLAGS_LIB_DIS_MCAST_SUPPRESS_5_XX)
141
146#define COAP_RESOURCE_FLAGS_FORCE_SINGLE_BODY 0x200
147
151#define COAP_RESOURCE_FLAGS_OSCORE_ONLY 0x400
152
158#define COAP_RESOURCE_HANDLE_WELLKNOWN_CORE 0x800
159
187 int flags);
188
216
246 int flags);
247
264 size_t host_name_count, const char *host_name_list[]);
265
285 size_t host_name_count,
286 const char *host_name_list[],
287 int flags);
288
306 int flags);
307
318 coap_str_const_t *uri_path);
319
328
337void coap_resource_set_mode(coap_resource_t *resource, int mode);
338
347void coap_resource_set_userdata(coap_resource_t *resource, void *data);
348
358
362typedef void (*coap_resource_release_userdata_handler_t)(void *user_data);
363
374
384
397
409 coap_request_t method,
410 coap_method_handler_t handler);
411
421 coap_request_t method,
422 coap_method_handler_t handler);
423
455 coap_str_const_t *name,
456 coap_str_const_t *value,
457 int flags);
458
469 coap_str_const_t *name);
470
479
489typedef uint32_t coap_print_status_t;
490
491#define COAP_PRINT_STATUS_MASK 0xF0000000UL
492#define COAP_PRINT_STATUS_MAX 0x0FFFFFFFUL
493#define COAP_PRINT_OUTPUT_LENGTH(v) ((v) & COAP_PRINT_STATUS_MAX)
494#define COAP_PRINT_STATUS_ERROR 0x80000000UL
495#define COAP_PRINT_STATUS_TRUNC 0x40000000UL
496
519 unsigned char *buf,
520 size_t *len,
521 size_t *offset);
522
546 unsigned char *buf,
547 size_t *buflen,
548 size_t offset,
549 const coap_string_t *query_filter);
550
557 const coap_string_t *query);
558
559#endif /* COAP_RESOURCE_H_ */
#define COAP_API
COAP_DEPRECATED COAP_API int coap_resource_set_dirty(coap_resource_t *r, const coap_string_t *query)
COAP_API 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.
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.
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.
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.
coap_resource_t * coap_resource_proxy_uri_init2(coap_method_handler_t handler, size_t host_name_count, const char *host_name_list[], int flags)
Creates a new resource object for handling proxy URIs with configurable control over multicast reques...
void coap_resource_set_mode(coap_resource_t *resource, int mode)
Sets the notification message type of resource resource to given mode.
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
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 ...
COAP_API coap_print_status_t coap_print_wellknown(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_resource_t * coap_resource_reverse_proxy_init(coap_method_handler_t handler, int flags)
Creates a new resource object for the reverse-proxy resource handler with control over multicast requ...
COAP_API int coap_delete_resource(coap_context_t *context, coap_resource_t *resource)
Deletes a resource identified by resource.
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.
void(* coap_resource_release_userdata_handler_t)(void *user_data)
Definition of release resource user_data callback function.
void coap_register_request_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.
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.
void coap_resource_set_userdata(coap_resource_t *resource, void *data)
Sets the user_data.
uint32_t coap_print_status_t
Status word to encode the result of conditional print or copy operations such as coap_print_link().
coap_str_const_t * coap_resource_get_uri_path(coap_resource_t *resource)
Get the uri_path from a resource.
coap_resource_t * coap_resource_unknown_init2(coap_method_handler_t put_handler, int flags)
Creates a new resource object for the unknown resource handler with support for PUT and configurable ...
coap_str_const_t * coap_attr_get_value(coap_attr_t *attribute)
Returns attribute's value.
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.
void * coap_resource_get_userdata(coap_resource_t *resource)
Gets the user_data.
COAP_API void coap_add_resource(coap_context_t *context, coap_resource_t *resource)
Registers the given resource for context.
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.
coap_request_t
CoAP PDU Request methods.
Definition: coap_pdu.h:78
#define COAP_DEPRECATED
Definition: libcoap.h:62
Limits the number of subscribers for each resource that this server support.
The CoAP stack's global state is stored in a coap_context_t object.
structure for CoAP PDUs
Abstraction of resource that can be attached to coap_context_t.
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
CoAP string data definition with const data.
Definition: coap_str.h:46
CoAP string data definition.
Definition: coap_str.h:38