libcoap  4.3.0rc1
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 "coap2/uthash.h"
24 #include "coap2/async.h"
25 #include "coap2/block.h"
26 #include "coap2/str.h"
27 #include "coap2/pdu.h"
28 #include "coap2/net.h"
29 #include "coap2/subscribe.h"
30 
40 typedef void (*coap_method_handler_t)
41  (coap_context_t *,
44  coap_pdu_t *,
45  coap_binary_t * /* token */,
46  coap_string_t * /* query string */,
47  coap_pdu_t * /* response */);
48 
49 #define COAP_ATTR_FLAGS_RELEASE_NAME 0x1
50 #define COAP_ATTR_FLAGS_RELEASE_VALUE 0x2
51 
53 #define COAP_RESOURCE_FLAGS_RELEASE_URI 0x1
54 
60 #define COAP_RESOURCE_FLAGS_NOTIFY_NON 0x0
61 
66 #define COAP_RESOURCE_FLAGS_NOTIFY_CON 0x2
67 
76 #define COAP_RESOURCE_FLAGS_NOTIFY_NON_ALWAYS 0x4
77 
110  int flags);
111 
112 
140 
157  size_t host_name_count, const char *host_name_list[]);
158 
169  coap_str_const_t *uri_path);
170 
179 
188 void coap_resource_set_mode(coap_resource_t *resource, int mode);
189 
198 void coap_resource_set_userdata(coap_resource_t *resource, void *data);
199 
209 
213 typedef void (*coap_resource_release_userdata_handler_t)(void *user_data);
214 
225 
234 void coap_add_resource(coap_context_t *context, coap_resource_t *resource);
235 
246 int coap_delete_resource(coap_context_t *context, coap_resource_t *resource);
247 
257  coap_request_t method,
258  coap_method_handler_t handler);
259 
291  coap_str_const_t *name,
292  coap_str_const_t *value,
293  int flags);
294 
305  coap_str_const_t *name);
306 
315 
325 typedef unsigned int coap_print_status_t;
326 
327 #define COAP_PRINT_STATUS_MASK 0xF0000000u
328 #define COAP_PRINT_OUTPUT_LENGTH(v) ((v) & ~COAP_PRINT_STATUS_MASK)
329 #define COAP_PRINT_STATUS_ERROR 0x80000000u
330 #define COAP_PRINT_STATUS_TRUNC 0x40000000u
331 
354  unsigned char *buf,
355  size_t *len,
356  size_t *offset);
357 
367  coap_request_t method,
368  coap_method_handler_t handler);
369 
382  coap_str_const_t *uri_path);
383 
384 #define RESOURCES_ADD(r, obj) \
385  HASH_ADD(hh, (r), uri_path->s[0], (obj)->uri_path->length, (obj))
386 
387 #define RESOURCES_DELETE(r, obj) \
388  HASH_DELETE(hh, (r), (obj))
389 
390 #define RESOURCES_ITER(r,tmp) \
391  coap_resource_t *tmp, *rtmp; \
392  HASH_ITER(hh, (r), tmp, rtmp)
393 
394 #define RESOURCES_FIND(r, k, res) { \
395  HASH_FIND(hh, (r), (k)->s, (k)->length, (res)); \
396  }
397 
401 COAP_DEPRECATED int
403  const coap_string_t *query);
404 
405 #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:1011
coap_str_const_t * coap_resource_get_uri_path(coap_resource_t *resource)
Get the uri_path from a resource.
Definition: resource.c:1039
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:1028
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_method_handler_t)(coap_context_t *, coap_resource_t *, coap_session_t *, coap_pdu_t *, coap_binary_t *, coap_string_t *, coap_pdu_t *)
Definition of message handler function.
Definition: resource.h:41
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:325
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:213
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:1018
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:1023
#define COAP_DEPRECATED
Definition: libcoap.h:46
Pre-defined constants that reflect defaults for CoAP.
coap_request_t
Definition: pdu.h:82
COAP_DEPRECATED int coap_resource_set_dirty(coap_resource_t *r, const coap_string_t *query)
Definition: resource.c:955
Abstraction of attribute associated with a resource.
CoAP binary data definition.
Definition: str.h:48
The CoAP stack's global state is stored in a coap_context_t object.
Definition: net.h:150
structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload mark...
Definition: pdu.h:287
Abstraction of resource that can be attached to coap_context_t.
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.