libcoap  4.3.0rc3
resource.h
Go to the documentation of this file.
1 /*
2  * resource.h -- generic resource handling
3  *
4  * Copyright (C) 2010,2011,2014-2021 Olaf Bergmann <bergmann@tzi.org>
5  *
6  * This file is part of the CoAP library libcoap. Please see README for terms
7  * of use.
8  */
9 
15 #ifndef COAP_RESOURCE_H_
16 #define COAP_RESOURCE_H_
17 
18 #ifndef COAP_RESOURCE_CHECK_TIME
20 #define COAP_RESOURCE_CHECK_TIME 2
21 #endif /* COAP_RESOURCE_CHECK_TIME */
22 
23 #include "async.h"
24 #include "block.h"
25 #include "str.h"
26 #include "pdu.h"
27 #include "net.h"
28 #include "subscribe.h"
29 
39 typedef void (*coap_method_handler_t)
40  (coap_resource_t *,
42  const coap_pdu_t * /* request */,
43  const coap_string_t * /* query string */,
44  coap_pdu_t * /* response */);
45 
46 #define COAP_ATTR_FLAGS_RELEASE_NAME 0x1
47 #define COAP_ATTR_FLAGS_RELEASE_VALUE 0x2
48 
50 #define COAP_RESOURCE_FLAGS_RELEASE_URI 0x1
51 
57 #define COAP_RESOURCE_FLAGS_NOTIFY_NON 0x0
58 
63 #define COAP_RESOURCE_FLAGS_NOTIFY_CON 0x2
64 
73 #define COAP_RESOURCE_FLAGS_NOTIFY_NON_ALWAYS 0x4
74 
107  int flags);
108 
109 
137 
154  size_t host_name_count, const char *host_name_list[]);
155 
166  coap_str_const_t *uri_path);
167 
176 
185 void coap_resource_set_mode(coap_resource_t *resource, int mode);
186 
195 void coap_resource_set_userdata(coap_resource_t *resource, void *data);
196 
206 
210 typedef void (*coap_resource_release_userdata_handler_t)(void *user_data);
211 
222 
231 void coap_add_resource(coap_context_t *context, coap_resource_t *resource);
232 
243 int coap_delete_resource(coap_context_t *context, coap_resource_t *resource);
244 
254  coap_request_t method,
255  coap_method_handler_t handler);
256 
288  coap_str_const_t *name,
289  coap_str_const_t *value,
290  int flags);
291 
302  coap_str_const_t *name);
303 
312 
322 typedef unsigned int coap_print_status_t;
323 
324 #define COAP_PRINT_STATUS_MASK 0xF0000000u
325 #define COAP_PRINT_OUTPUT_LENGTH(v) ((v) & ~COAP_PRINT_STATUS_MASK)
326 #define COAP_PRINT_STATUS_ERROR 0x80000000u
327 #define COAP_PRINT_STATUS_TRUNC 0x40000000u
328 
351  unsigned char *buf,
352  size_t *len,
353  size_t *offset);
354 
367  coap_str_const_t *uri_path);
368 
372 COAP_DEPRECATED int
374  const coap_string_t *query);
375 
376 #endif /* COAP_RESOURCE_H_ */
State management for asynchronous messages.
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:356
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:622
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:1028
coap_str_const_t * coap_resource_get_uri_path(coap_resource_t *resource)
Get the uri_path from a resource.
Definition: resource.c:1056
coap_str_const_t * coap_attr_get_value(coap_attr_t *attribute)
Returns attribute's value.
Definition: resource.c:459
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:1045
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:613
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:675
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:335
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:442
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:322
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:40
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:301
void(* coap_resource_release_userdata_handler_t)(void *user_data)
Definition of release resource user_data callback function.
Definition: resource.h:210
void coap_add_resource(coap_context_t *context, coap_resource_t *resource)
Registers the given resource for context.
Definition: resource.c:534
void coap_resource_set_userdata(coap_resource_t *resource, void *data)
Sets the user_data.
Definition: resource.c:1035
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:405
int coap_delete_resource(coap_context_t *context, coap_resource_t *resource)
Deletes a resource identified by resource.
Definition: resource.c:563
void * coap_resource_get_userdata(coap_resource_t *resource)
Gets the user_data.
Definition: resource.c:1040
coap_request_t
CoAP PDU Request methods.
Definition: pdu.h:64
#define COAP_DEPRECATED
Definition: libcoap.h:46
Pre-defined constants that reflect defaults for CoAP.
COAP_DEPRECATED int coap_resource_set_dirty(coap_resource_t *r, const coap_string_t *query)
Definition: resource.c:972
Abstraction of attribute associated with a resource.
The CoAP stack's global state is stored in a coap_context_t object.
structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload mark...
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: str.h:38
CoAP string data definition.
Definition: str.h:30
Defines the application visible subscribe information.