libcoap 4.3.2rc2

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-2023 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
35 typedef void (*coap_method_handler_t)
36(coap_resource_t *,
37 coap_session_t *,
38 const coap_pdu_t * /* request */,
39 const coap_string_t * /* query string */,
40 coap_pdu_t * /* response */);
41
42#define COAP_ATTR_FLAGS_RELEASE_NAME 0x1
43#define COAP_ATTR_FLAGS_RELEASE_VALUE 0x2
44
46#define COAP_RESOURCE_FLAGS_RELEASE_URI 0x1
47
54#define COAP_RESOURCE_FLAGS_NOTIFY_NON 0x0
55
60#define COAP_RESOURCE_FLAGS_NOTIFY_CON 0x2
61
70#define COAP_RESOURCE_FLAGS_NOTIFY_NON_ALWAYS 0x4
71
80#define COAP_RESOURCE_FLAGS_HAS_MCAST_SUPPORT 0x8
81
91#define COAP_RESOURCE_FLAGS_LIB_DIS_MCAST_DELAYS 0x10
92
100#define COAP_RESOURCE_FLAGS_LIB_ENA_MCAST_SUPPRESS_2_05 0x20
101
109#define COAP_RESOURCE_FLAGS_LIB_ENA_MCAST_SUPPRESS_2_XX 0x40
110
118#define COAP_RESOURCE_FLAGS_LIB_DIS_MCAST_SUPPRESS_4_XX 0x80
119
127#define COAP_RESOURCE_FLAGS_LIB_DIS_MCAST_SUPPRESS_5_XX 0x100
128
129#define COAP_RESOURCE_FLAGS_MCAST_LIST \
130 (COAP_RESOURCE_FLAGS_HAS_MCAST_SUPPORT | \
131 COAP_RESOURCE_FLAGS_LIB_DIS_MCAST_DELAYS | \
132 COAP_RESOURCE_FLAGS_LIB_ENA_MCAST_SUPPRESS_2_05 | \
133 COAP_RESOURCE_FLAGS_LIB_ENA_MCAST_SUPPRESS_2_XX | \
134 COAP_RESOURCE_FLAGS_LIB_DIS_MCAST_SUPPRESS_4_XX | \
135 COAP_RESOURCE_FLAGS_LIB_DIS_MCAST_SUPPRESS_5_XX)
136
141#define COAP_RESOURCE_FLAGS_FORCE_SINGLE_BODY 0x200
142
146#define COAP_RESOURCE_FLAGS_OSCORE_ONLY 0x400
147
174 coap_resource_t *coap_resource_init(coap_str_const_t *uri_path,
175 int flags);
176
203 coap_resource_t *coap_resource_unknown_init(coap_method_handler_t put_handler);
204
233 coap_resource_t *coap_resource_unknown_init2(coap_method_handler_t put_handler,
234 int flags);
235
251 coap_resource_t *coap_resource_proxy_uri_init(coap_method_handler_t handler,
252 size_t host_name_count, const char *host_name_list[]);
253
272 coap_resource_t *coap_resource_proxy_uri_init2(coap_method_handler_t handler,
273 size_t host_name_count,
274 const char *host_name_list[],
275 int flags);
276
286 coap_resource_t *coap_get_resource_from_uri_path(coap_context_t *context,
287 coap_str_const_t *uri_path);
288
296 coap_str_const_t *coap_resource_get_uri_path(coap_resource_t *resource);
297
306 void coap_resource_set_mode(coap_resource_t *resource, int mode);
307
316 void coap_resource_set_userdata(coap_resource_t *resource, void *data);
317
326 void *coap_resource_get_userdata(coap_resource_t *resource);
327
331 typedef void (*coap_resource_release_userdata_handler_t)(void *user_data);
332
341 void coap_resource_release_userdata_handler(coap_context_t *context,
342 coap_resource_release_userdata_handler_t callback);
343
352 void coap_add_resource(coap_context_t *context, coap_resource_t *resource);
353
365 int coap_delete_resource(coap_context_t *context, coap_resource_t *resource);
366
377 void coap_register_handler(coap_resource_t *resource,
378 coap_request_t method,
379 coap_method_handler_t handler);
380
389 void coap_register_request_handler(coap_resource_t *resource,
390 coap_request_t method,
391 coap_method_handler_t handler);
392
423 coap_attr_t *coap_add_attr(coap_resource_t *resource,
424 coap_str_const_t *name,
425 coap_str_const_t *value,
426 int flags);
427
437 coap_attr_t *coap_find_attr(coap_resource_t *resource,
438 coap_str_const_t *name);
439
447 coap_str_const_t *coap_attr_get_value(coap_attr_t *attribute);
448
458 typedef unsigned int coap_print_status_t;
459
460#define COAP_PRINT_STATUS_MASK 0xF0000000u
461#define COAP_PRINT_OUTPUT_LENGTH(v) ((v) & ~COAP_PRINT_STATUS_MASK)
462#define COAP_PRINT_STATUS_ERROR 0x80000000u
463#define COAP_PRINT_STATUS_TRUNC 0x40000000u
464
486 coap_print_status_t coap_print_link(const coap_resource_t *resource,
487 unsigned char *buf,
488 size_t *len,
489 size_t *offset);
490
502 coap_resource_t *coap_get_resource_from_uri_path(coap_context_t *context,
503 coap_str_const_t *uri_path);
504
508 COAP_DEPRECATED int coap_resource_set_dirty(coap_resource_t *r,
509 const coap_string_t *query);
510
511#endif /* COAP_RESOURCE_H_ */
coap_resource_set_dirty
COAP_DEPRECATED int coap_resource_set_dirty(coap_resource_t *r, const coap_string_t *query)
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.
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.
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.
coap_resource_proxy_uri_init2
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...
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.
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.
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 ...
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.
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: coap_resource.h:458
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: coap_resource.h:36
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: coap_resource.h:331
coap_add_resource
void coap_add_resource(coap_context_t *context, coap_resource_t *resource)
Registers the given resource for context.
coap_register_request_handler
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_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.
coap_resource_set_userdata
void coap_resource_set_userdata(coap_resource_t *resource, void *data)
Sets the user_data.
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.
coap_resource_unknown_init2
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_attr_get_value
coap_str_const_t * coap_attr_get_value(coap_attr_t *attribute)
Returns attribute's value.
coap_delete_resource
int coap_delete_resource(coap_context_t *context, coap_resource_t *resource)
Deletes a resource identified by resource.
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.
coap_resource_get_userdata
void * coap_resource_get_userdata(coap_resource_t *resource)
Gets the user_data.
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.
coap_request_t
coap_request_t
CoAP PDU Request methods.
Definition: coap_pdu.h:74
COAP_DEPRECATED
#define COAP_DEPRECATED
Definition: libcoap.h:61
coap_attr_t
Limits the number of subscribers for each resource that this server support.
Definition: coap_resource_internal.h:42
coap_context_t
The CoAP stack's global state is stored in a coap_context_t object.
Definition: coap_net_internal.h:49
coap_pdu_t
structure for CoAP PDUs
Definition: coap_pdu_internal.h:119
coap_resource_t
Abstraction of resource that can be attached to coap_context_t.
Definition: coap_resource_internal.h:53
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:68
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