Server APIs. More...
Server APIs.
Definition in file server.h.
#include <stdbool.h>#include <stdint.h>#include "xfa.h"#include "ztimer.h"#include "event.h"#include "net/unicoap/constants.h"#include "net/unicoap/message.h"#include "net/unicoap/transport.h"#include "net/unicoap/util_macros.h"
Include dependency graph for server.h:
This graph shows which files directly or indirectly include this file:Go to the source code of this file.
Data Structures | |
| struct | unicoap_pathspec_t |
| An immutable path object. More... | |
| struct | unicoap_request_context_t |
| Request context used to send a response to a given request. More... | |
| struct | unicoap_resource |
| A type representing a CoAP resource. More... | |
| struct | unicoap_link_encoder_ctx_t |
| Context information required to write a resource link. More... | |
| struct | unicoap_listener |
| A modular collection of resources for a server. More... | |
Typedefs | |
| typedef struct unicoap_resource | unicoap_resource_t |
| CoAP resource. | |
Specifying and inspecting resource paths | |
| #define | UNICOAP_PATH(...) |
| Constructs a path. | |
| #define | UNICOAP_PATH_ROOT ((unicoap_pathspec_t) { ._components = NULL }) |
The root path / | |
| #define | UNICOAP_PATH_RESOURCE_DISCOVERY UNICOAP_PATH(".well-known", "core") |
The path for resource discovery (/.well-known/core) | |
| static bool | unicoap_path_is_root (const unicoap_pathspec_t *path) |
| Determines whether the given path is the root path. | |
| size_t | unicoap_path_component_count (const unicoap_pathspec_t *path) |
| Counts path components in path. | |
| bool | unicoap_path_is_equal (const unicoap_pathspec_t *lhs, const unicoap_pathspec_t *rhs) |
| Compares two path objects. | |
| 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. | |
| 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. | |
| ssize_t | unicoap_path_stringify (const unicoap_pathspec_t *path, char *buffer, size_t capacity) |
Writes path into buffer, with path components separated by / | |
| void | unicoap_print_path (const unicoap_pathspec_t *path) |
| Prints given path object as serialized path. | |
Reacting to CoAP requests | |
| #define | UNICOAP_IGNORING_REQUEST (-2042) |
| Error number indicating the resource handler will not respond. | |
| typedef int(* | unicoap_request_handler_t) (unicoap_message_t *request, const unicoap_aux_t *aux, unicoap_request_context_t *ctx, void *arg) |
| Resource request handler. | |
| bool | unicoap_response_is_optional (unicoap_options_t *options, unicoap_status_t status) |
| Determines if the client is interested in a response. | |
| int | unicoap_send_response (unicoap_message_t *response, unicoap_request_context_t *context) |
Sends a response to a request identifier by the given context. | |
| unicoap_status_t | unicoap_response_status_from_errno (int _errno) |
Maps a given errno to a CoAP response status code. | |
Matching methods and protocols | |
| #define | UNICOAP_METHOD_FLAG(method) |
A bit set at the position dictated by method. | |
| #define | UNICOAP_METHODS(first_method, ...) |
Macro that builds a bit field where the i-th bit indicates the i-th request method 0.0i | |
| #define | UNICOAP_METHODS_ALL (0xff) |
| unicoap_method_set_t value indicating all methods are allowed | |
| #define | UNICOAP_PROTOCOL_FLAG(proto) |
A bit set at the position dictated by proto. | |
| #define | UNICOAP_PROTOCOLS(first_proto, ...) |
| Macro creating a bit field describing the specified protocols. | |
| #define | UNICOAP_PROTOCOLS_ALLOW_ALL (0) |
| unicoap_proto_set_t value indicating all protocols are allowed | |
| #define | UNICOAP_PROTOCOLS_ALLOW_NONE (1) |
| unicoap_proto_set_t value indicating no protocol is allowed | |
| 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. | |
| 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. | |
Declaring a CoAP resource at compile time | |
| #define | UNICOAP_RESOURCE(name) |
| Declares a static CoAP resource. | |
Registering CoAP resources | |
| enum | unicoap_resource_flags_t { UNICOAP_RESOURCE_FLAG_RELIABLE = 0x0001 , UNICOAP_RESOURCE_FLAG_MATCH_SUBTREE = 0x4000 } |
| Flags for enabling advanced features in server exchanges. More... | |
| typedef uint8_t | unicoap_proto_set_t |
| Allowed protocols bit field. | |
| typedef uint8_t | unicoap_method_set_t |
| Allowed methods bit field. | |
| void | unicoap_print_resource_flags (unicoap_resource_flags_t flags) |
| Prints resource flags. | |
| void | unicoap_print_protocols (unicoap_proto_set_t protocols) |
| Prints protocols bitfield. | |
| void | unicoap_print_methods (unicoap_method_set_t methods) |
| Prints methods bitfield. | |
| void | unicoap_print_resource (const unicoap_resource_t *resource) |
| Prints CoAP resource definition properties. | |
Resource discovery | |
| typedef 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. | |
| 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. | |
| 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. | |
Matching requests and resources | |
| typedef struct unicoap_listener | unicoap_listener_t |
| Typealias for unicoap_listener. | |
| typedef 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_listener_register (unicoap_listener_t *listener) |
| Makes unicoap listen for resources contained in listener. | |
| int | unicoap_listener_deregister (unicoap_listener_t *listener) |
| Removes listener from unicoap. | |
| 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. | |
| 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. | |