71 const char** _components;
77 "unicoap_pathspec_t is of unexpected size. Please file a bug report.");
90#define UNICOAP_PATH(...) \
91 ((unicoap_pathspec_t) { ._components = (const char*[]) { __VA_ARGS__, \
92 _UNICOAP_TRY_CHECK_PATH_COMPONENTS(__VA_ARGS__) ? NULL : NULL } })
95#define UNICOAP_PATH_ROOT \
96 ((unicoap_pathspec_t) { ._components = NULL })
99#define UNICOAP_PATH_RESOURCE_DISCOVERY UNICOAP_PATH(".well-known", "core")
108 return path->_components == NULL;
168 const char*
string,
size_t string_length,
bool match_subtree);
267#define UNICOAP_IGNORING_REQUEST (-2042)
638 const char* path,
size_t length) {
670#define UNICOAP_METHOD_FLAG(method) (1 << (method))
691#define UNICOAP_METHODS(first_method, ...) UNICOAP_BITFIELD(first_method, __VA_ARGS__)
696#define UNICOAP_METHODS_ALL (0xff)
713#define UNICOAP_PROTOCOL_FLAG(proto) (1 << (proto))
726#define UNICOAP_PROTOCOLS(first_proto, ...) UNICOAP_BITFIELD(first_proto, __VA_ARGS__)
731#define UNICOAP_PROTOCOLS_ALLOW_ALL (0)
736#define UNICOAP_PROTOCOLS_ALLOW_NONE (1)
772#if IS_USED(MODULE_UNICOAP_SERVER_RESOURCE_DECLARATIONS) || defined(DOXYGEN)
773# define UNICOAP_RESOURCE(name) \
774 XFA_CONST(unicoap_resource_t, unicoap_resources_xfa, 0) CONCAT(unicoap_resource_, name) =
776# define UNICOAP_RESOURCE(name) \
777 static_assert(false, \
778 "The unicoap_server_resource_declarations module is missing, resource cannot be registered"); \
779 unicoap_resource_t CONCAT(unicoap_resource_, name) =
#define assert(cond)
abort the program if assertion is false
Constants used in CoAP such as option numbers and message codes.
#define CONFIG_UNICOAP_PDU_SIZE_MAX
Capacity of internal buffers.
unicoap_status_t
CoAP response status codes.
unicoap_method_t
CoAP request method codes (0.xx range)
unicoap_content_format_t
Content-Format option values
bool unicoap_path_is_equal(const unicoap_pathspec_t *lhs, const unicoap_pathspec_t *rhs)
Compares two path objects.
void unicoap_listener_register(unicoap_listener_t *listener)
Makes unicoap listen for resources contained in listener.
bool unicoap_response_is_optional(unicoap_options_t *options, unicoap_status_t status)
Determines if the client is interested in a response.
static bool unicoap_resource_match_method(unicoap_method_set_t methods, unicoap_method_t method)
Returns whether the method is allowed according to the given methods.
void unicoap_print_path(const unicoap_pathspec_t *path)
Prints given path object as serialized path.
int(* unicoap_request_handler_t)(unicoap_message_t *request, const unicoap_aux_t *aux, unicoap_request_context_t *ctx, void *arg)
Resource request handler.
#define UNICOAP_METHOD_FLAG(method)
A bit set at the position dictated by method.
static bool unicoap_match_proto(unicoap_proto_set_t protocols, unicoap_proto_t proto)
Returns whether the given proto is allowed according to the protocols argument.
struct unicoap_listener unicoap_listener_t
Typealias for unicoap_listener.
unicoap_status_t unicoap_response_status_from_errno(int _errno)
Maps a given errno to a CoAP response status code.
ssize_t unicoap_resource_core_link_format_build(char *buffer, size_t capacity, unicoap_proto_t proto)
Builds a string in Constrained RESTful Environments (CoRE) Link Format.
unicoap_resource_flags_t
Flags for enabling advanced features in server exchanges.
bool unicoap_path_matches_string(const unicoap_pathspec_t *path, const char *string, size_t string_length, bool match_subtree)
Compares UTF-8 string path against path object.
int unicoap_send_response(unicoap_message_t *response, unicoap_request_context_t *context)
Sends a response to a request identifier by the given context.
uint8_t unicoap_method_set_t
Allowed methods bit field.
static bool unicoap_resource_match_path_options(const unicoap_resource_t *resource, const unicoap_options_t *options)
Determines whether the complete Uri-Path matches the resources path.
void unicoap_print_protocols(unicoap_proto_set_t protocols)
Prints protocols bitfield.
ssize_t unicoap_resource_encode_link(const unicoap_resource_t *resource, char *buffer, size_t capacity, unicoap_link_encoder_ctx_t *context)
Encodes given resource in Constrained RESTful Environments (CoRE) Link Format.
ssize_t unicoap_path_stringify(const unicoap_pathspec_t *path, char *buffer, size_t capacity)
Writes path into buffer, with path components separated by /
size_t unicoap_path_component_count(const unicoap_pathspec_t *path)
Counts path components in path.
ssize_t(* unicoap_link_encoder_t)(const unicoap_resource_t *resource, char *buffer, size_t capacity, unicoap_link_encoder_ctx_t *context)
Handler function to write a resource link.
void unicoap_print_methods(unicoap_method_set_t methods)
Prints methods bitfield.
static bool unicoap_path_is_root(const unicoap_pathspec_t *path)
Determines whether the given path is the root path.
uint8_t unicoap_proto_set_t
Allowed protocols bit field.
int(* unicoap_request_matcher_t)(const unicoap_listener_t *listener, const unicoap_resource_t **resource, const unicoap_message_t *request, const unicoap_endpoint_t *endpoint)
Handler function for the request matcher strategy.
void unicoap_print_resource_flags(unicoap_resource_flags_t flags)
Prints resource flags.
static bool unicoap_resource_match_path_string(const unicoap_resource_t *resource, const char *path, size_t length)
Determines whether the complete Uri-Path matches the resources path.
void unicoap_print_resource(const unicoap_resource_t *resource)
Prints CoAP resource definition properties.
bool unicoap_path_matches_options(const unicoap_pathspec_t *path, const unicoap_options_t *options, bool match_subtree)
Compares Uri-Path options against path object.
struct unicoap_resource unicoap_resource_t
CoAP resource.
#define UNICOAP_PROTOCOLS_ALLOW_ALL
unicoap_proto_set_t value indicating all protocols are allowed
int unicoap_listener_deregister(unicoap_listener_t *listener)
Removes listener from unicoap.
#define UNICOAP_PROTOCOL_FLAG(proto)
A bit set at the position dictated by proto.
@ UNICOAP_RESOURCE_FLAG_RELIABLE
Sets the type of the message to confirmable (CON), if an unreliable transport is used.
@ UNICOAP_RESOURCE_FLAG_MATCH_SUBTREE
Makes this resource match paths located in the subtree of the given path.
unicoap_proto_t
Transport protocol CoAP is used over.
Auxiliary exchange information.
Context information required to write a resource link.
unicoap_content_format_t content_format
Expected content format of resource.
bool uninitialized
Boolean value indicating whether to initialize result list for first resource.
size_t link_pos
Current byte offset of encoder.
A modular collection of resources for a server.
const unicoap_resource_t * resources
Reference to contiguous array of resource belonging to this listener.
unicoap_proto_set_t protocols
Allowed protocols for the resources grouped together by this resource.
unicoap_link_encoder_t link_encoder
Encoder for Constrained RESTful Environments (CoRE) Link Format.
size_t resource_count
The number of resources belonging in this listener.
unicoap_listener_t * next
Next listener in linked list.
unicoap_request_matcher_t request_matcher
Function that picks a suitable request handler from a request.
An immutable path object.
Request context used to send a response to a given request.
const unicoap_resource_t * resource
Resource this request was directed to.
A type representing a CoAP resource.
unicoap_method_set_t methods
Allowed request methods for this resource.
unicoap_proto_set_t protocols
Allowed transport protocols this resource can be reached over.
unicoap_request_handler_t handler
Request handler callback.
void * handler_arg
Opaque optional argument for the request handler (nullable)
const unicoap_pathspec_t path
Resource path.
unicoap_resource_flags_t flags
Flags for modifying resource behavior.
CoAP transport protocol abstraction layer.
Utility macros for unicoap