'\" t
.\" Title: coap_resource
.\" Author: [see the "AUTHORS" section]
.\" Generator: DocBook XSL Stylesheets vsnapshot
.\" Date: 04/07/2024
.\" Manual: libcoap Manual
.\" Source: coap_resource 4.3.4
.\" Language: English
.\"
.TH "COAP_RESOURCE" "3" "04/07/2024" "coap_resource 4\&.3\&.4" "libcoap Manual"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
coap_resource, coap_resource_init, coap_resource_unknown_init, coap_resource_unknown_init2, coap_resource_proxy_uri_init, coap_resource_proxy_uri_init2, coap_add_resource, coap_delete_resource, coap_resource_set_mode, coap_resource_set_userdata, coap_resource_get_userdata, coap_resource_release_userdata_handler, coap_resource_get_uri_path \- Work with CoAP resources
.SH "SYNOPSIS"
.sp
\fB#include \fR
.sp
\fBcoap_resource_t *coap_resource_init(coap_str_const_t *\fR\fB\fIuri_path\fR\fR\fB, int \fR\fB\fIflags\fR\fR\fB);\fR
.sp
\fBcoap_resource_t *coap_resource_unknown_init(coap_method_handler_t \fR\fB\fIput_handler\fR\fR\fB);\fR
.sp
\fBcoap_resource_t *coap_resource_unknown_init2(coap_method_handler_t \fR\fB\fIput_handler\fR\fR\fB, int \fR\fB\fIflags\fR\fR\fB);\fR
.sp
\fBcoap_resource_t *coap_resource_proxy_uri_init(coap_method_handler_t \fR\fB\fIproxy_handler\fR\fR\fB, size_t \fR\fB\fIhost_name_count\fR\fR\fB, const char *\fR\fB\fIhost_name_list\fR\fR\fB[]);\fR
.sp
\fBcoap_resource_t *coap_resource_proxy_uri_init2(coap_method_handler_t \fR\fB\fIproxy_handler\fR\fR\fB, size_t \fR\fB\fIhost_name_count\fR\fR\fB, const char *\fR\fB\fIhost_name_list\fR\fR\fB[], int \fR\fB\fIflags\fR\fR\fB);\fR
.sp
\fBvoid coap_add_resource(coap_context_t *\fR\fB\fIcontext\fR\fR\fB, coap_resource_t *\fR\fB\fIresource\fR\fR\fB);\fR
.sp
\fBint coap_delete_resource(coap_context_t *\fR\fB\fIcontext\fR\fR\fB, coap_resource_t *\fR\fB\fIresource\fR\fR\fB);\fR
.sp
\fBvoid coap_resource_set_mode(coap_resource_t *\fR\fB\fIresource\fR\fR\fB, int \fR\fB\fImode\fR\fR\fB);\fR
.sp
\fBvoid coap_resource_set_userdata(coap_resource_t *\fR\fB\fIresource\fR\fR\fB, void *\fR\fB\fIdata\fR\fR\fB);\fR
.sp
\fBvoid *coap_resource_get_userdata(coap_resource_t *\fR\fB\fIresource\fR\fR\fB);\fR
.sp
\fBvoid coap_resource_release_userdata_handler(coap_context_t *\fR\fB\fIcontext\fR\fR\fB, coap_resource_release_userdata_handler_t \fR\fB\fIcallback\fR\fR\fB);\fR
.sp
\fBcoap_str_const_t *coap_resource_get_uri_path(coap_resource_t *\fR\fB\fIresource\fR\fR\fB);\fR
.sp
For specific (D)TLS library support, link with \fB\-lcoap\-3\-notls\fR, \fB\-lcoap\-3\-gnutls\fR, \fB\-lcoap\-3\-openssl\fR, \fB\-lcoap\-3\-mbedtls\fR or \fB\-lcoap\-3\-tinydtls\fR\&. Otherwise, link with \fB\-lcoap\-3\fR to get the default (D)TLS library support\&.
.SH "DESCRIPTION"
.sp
CoAP Resources on a CoAP Server need to be created, updated and deleted as appropriate\&. The URI in the request packet defines the resource to work with, with possibly the Query or data in the request referring to a sub\-resource\&.
.sp
When resources are configured on the CoAP server, the URI to match against in the request packet is specified\&.
.sp
Callback Handlers are then added to the resource to handle the different request methods\&. See \fBcoap_register_request_handler\fR(3) for further information\&.
.sp
Adding Attributes allows textual information to be added to the resource which can then be reported back to any client doing a "GET \&.well\-known/core" request\&. See \fBcoap_add_attr\fR(3) for further information\&.
.sp
If an incoming packet request matches a resource\(cqs URI and Method, then the appropriate callback resource handler is invoked to process the packet which should then update a suitable response packet for returning back to the requester\&.
.sp
There is support for handling incoming packets where the URI is unknown (no specific resource has been created)\&. This could, for example, happen when a PUT request is trying to create a new resource\&. It is the responsibility of the unknown resource callback handler to either create a new resource for the URI or just manage things separately\&.
.sp
CoAP Observe (RFC7641) is not supported for unknown resources, so a new resource with GET handler must be created by the unknown resource callback handle matching the URI which then can be Observable\&.
.sp
There is support for handling incoming proxy based requests using the Proxy\-Uri or Proxy\-Scheme options\&.
.SH "FUNCTIONS"
.sp
\fBFunction: coap_resource_init()\fR
.sp
The \fBcoap_resource_init\fR() function returns a newly created \fIresource\fR of type \fIcoap_resource_t\fR * \&. \fIuri_path\fR specifies the uri string path to match against\&. Normally there is no need for the leading \fI/\fR \- e\&.g\&. just "full/path/for/resource"\&. \fIflags\fR can be zero or more of the following definitions or\(cqed together\&.
.TS
tab(:);
lt lt
lt lt
lt lt
lt lt
lt lt
lt lt.
T{
.sp
\fBCOAP_RESOURCE_FLAGS_NOTIFY_NON\fR
T}:T{
.sp
Set the notification message type to non\-confirmable for any trigggered "observe" responses with type set to confirmable every 5 packets as required by "RFC7641 4\&.5\&. Transmission"\&. See \fBcoap_observe\fR(3)\&. \fBNOTE:\fR This flag is ignored if COAP_RESOURCE_FLAGS_NOTIFY_CON is set\&.
T}
T{
.sp
\fBCOAP_RESOURCE_FLAGS_NOTIFY_NON_ALWAYS\fR
T}:T{
.sp
Set the notification message type to always non\-confirmable for any trigggered "observe" responses\&. This should only be used if a upper layer protocol requires it\&. See \fBcoap_observe\fR(3)\&. \fBNOTE:\fR This flag is ignored if COAP_RESOURCE_FLAGS_NOTIFY_CON is set\&.
T}
T{
.sp
\fBCOAP_RESOURCE_FLAGS_NOTIFY_CON\fR
T}:T{
.sp
Set the notification message type to confirmable for any trigggered "observe" responses\&. See \fBcoap_observe\fR(3)\&. \fBNOTE:\fR COAP_RESOURCE_FLAGS_NOTIFY_NON is assumed if COAP_RESOURCE_FLAGS_NOTIFY_CON is not set\&.
T}
T{
.sp
\fBCOAP_RESOURCE_FLAGS_RELEASE_URI\fR
T}:T{
.sp
Free off the coap_str_const_t for \fIuri_path\fR when the \fIresource\fR is deleted\&.
T}
T{
.sp
\fBCOAP_RESOURCE_FLAGS_FORCE_SINGLE_BODY\fR
T}:T{
.sp
Force all large traffic to this resource to be presented as a single body to the request handler\&.
T}
T{
.sp
\fBCOAP_RESOURCE_FLAGS_OSCORE_ONLY\fR
T}:T{
.sp
Define this resource as an OSCORE enabled access only\&.
T}
.TE
.sp 1
.sp
\fBNOTE:\fR The following flags are only tested against if \fBcoap_mcast_per_resource\fR() has been called\&. If \fBcoap_mcast_per_resource\fR() has not been called, then all resources have multicast support, libcoap adds in random delays to the responses, and 4\&.xx / 5\&.xx responses are dropped\&.
.sp
\fBNOTE:\fR The pseudo resource for "\&.well\-known/core" always has multicast support enabled and is not configurable\&.
.TS
tab(:);
lt lt
lt lt
lt lt
lt lt
lt lt
lt lt.
T{
.sp
\fBCOAP_RESOURCE_FLAGS_HAS_MCAST_SUPPORT\fR
T}:T{
.sp
This resource has support for multicast requests\&.
T}
T{
.sp
\fBCOAP_RESOURCE_FLAGS_LIB_DIS_MCAST_DELAYS\fR
T}:T{
.sp
Disable libcoap library from adding in delays to multicast requests before sending the response back to the client\&. It is then the responsibility of the app to delay the responses for multicast requests\&. See "RFC7252 8\&.2\&. Request/Response Layer"\&. However, the pseudo resource for "\&.well\-known/core" always has multicast support enabled\&.
T}
T{
.sp
\fBCOAP_RESOURCE_FLAGS_LIB_ENA_MCAST_SUPPRESS_2_05\fR
T}:T{
.sp
Enable libcoap library suppression of 205 multicast responses that are empty (overridden by RFC7967 No\-Response option) for multicast requests\&.
T}
T{
.sp
\fBCOAP_RESOURCE_FLAGS_LIB_ENA_MCAST_SUPPRESS_2_XX\fR
T}:T{
.sp
Enable libcoap library suppressing 2\&.xx multicast responses (overridden by RFC7967 No\-Response option) for multicast requests\&.
T}
T{
.sp
\fBCOAP_RESOURCE_FLAGS_LIB_DIS_MCAST_SUPPRESS_4_XX\fR
T}:T{
.sp
Disable libcoap library suppressing 4\&.xx multicast responses (overridden by RFC7967 No\-Response option) for multicast requests\&.
T}
T{
.sp
\fBCOAP_RESOURCE_FLAGS_LIB_DIS_MCAST_SUPPRESS_5_XX\fR
T}:T{
.sp
Disable libcoap library suppressing 5\&.xx multicast responses (overridden by RFC7967 No\-Response option) for multicast requests\&.
T}
.TE
.sp 1
.sp
\fBNOTE:\fR \fIuri_path\fR, if not 7 bit readable ASCII, binary bytes must be hex encoded according to the rules defined in "RFC3986 2\&.1\&. Percent\-Encoding"\&.
.sp
\fBFunction: coap_resource_unknown_init()\fR
.sp
The \fBcoap_resource_unknown_init\fR() function returns a newly created \fIresource\fR of type \fIcoap_resource_t\fR *\&. \fIput_handler\fR is automatically added to the \fIresource\fR to handle PUT requests to resources that are unknown\&. Additional handlers can be added to this resource if required\&.
.sp
\fBFunction: coap_resource_unknown_init2()\fR
.sp
The \fBcoap_resource_unknown_init2\fR() function returns a newly created \fIresource\fR of type \fIcoap_resource_t\fR *\&. \fIput_handler\fR is automatically added to the \fIresource\fR to handle PUT requests to resources that are unknown\&. Additional handlers can be added to this resource if required\&. \fIflags\fR can be zero or more of the COAP_RESOURCE_FLAGS MCAST definitions\&.
.sp
\fBFunction: coap_resource_proxy_uri_init()\fR
.sp
The \fBcoap_resource_proxy_uri_init\fR() function returns a newly created \fIresource\fR of type \fIcoap_resource_t\fR *\&. \fIproxy_handler\fR is automatically added to the \fIresource\fR to handle PUT/POST/GET etc\&. requests that use the Proxy\-Uri option\&. There is no need to add explicit request type handlers\&. One or more names by which the proxy is known by (IP address, DNS name etc\&.) must be supplied in the array defined by \fIhost_name_list\fR[] which has a count of \fIhost_name_count\fR\&. This is used to check whether the current endpoint is the proxy target address, or the request has to be passed on to an upstream server\&.
.sp
\fBFunction: coap_resource_proxy_uri_init2()\fR
.sp
The \fBcoap_resource_proxy_uri_init2\fR() function returns a newly created \fIresource\fR of type \fIcoap_resource_t\fR *\&. \fIproxy_handler\fR is automatically added to the \fIresource\fR to handle PUT/POST/GET etc\&. requests that use the Proxy\-Uri option\&. There is no need to add explicit request type handlers\&. One or more names by which the proxy is known by (IP address, DNS name etc\&.) must be supplied in the array defined by \fIhost_name_list\fR[] which has a count of \fIhost_name_count\fR\&. This is used to check whether the current endpoint is the proxy target address, or the request has to be passed on to an upstream server\&. \fIflags\fR can be zero or more COAP_RESOURCE_FLAGS MCAST definitions\&.
.sp
\fBFunction: coap_add_resource()\fR
.sp
The \fBcoap_add_resource\fR() function registers the given \fIresource\fR with the \fIcontext\fR\&. The \fIresource\fR must have been created by \fBcoap_resource_init\fR(), \fBcoap_resource_unknown_init\fR(), \fBcoap_resource_unknown_init2\fR(), \fBcoap_resource_proxy_uri_init\fR() or \fBcoap_resource_proxy_uri_init2\fR()\&. The storage allocated for the \fIresource\fR will be released by \fBcoap_delete_resource\fR()\&.
.sp
As the \fIuri_path\fR of the resource has to be unique across all of the resources associated with a \fIcontext\fR, \fBcoap_add_resource\fR() will delete any previous \fIresource\fR with the same \fIuri_path\fR before adding in the new \fIresource\fR\&.
.sp
\fBFunction: coap_delete_resource()\fR
.sp
The \fBcoap_delete_resource\fR() function deletes the resource identified by \fIresource\fR\&. The \fIcontext\fR parameter is ignored\&. The storage allocated for that \fIresource\fR is freed, along with any attributes associated with the \fIresource\fR\&.
.sp
\fBFunction: coap_resource_set_mode()\fR
.sp
The \fBcoap_resource_set_mode\fR() changes the unsolicited notification message type of \fIresource\fR to the given \fImode\fR which must be one of COAP_RESOURCE_FLAGS_NOTIFY_NON, COAP_RESOURCE_FLAGS_NOTIFY_NON_ALWAYS or COAP_RESOURCE_FLAGS_NOTIFY_CON\&.
.sp
\fBFunction: coap_resource_set_userdata()\fR
.sp
The \fBcoap_resource_set_userdata\fR() function allows a pointer to user \fIdata\fR to be associated with a \fIresource\fR that can accessed in any callback that includes \fIresource\fR as a parameter\&.
.sp
\fBNOTE:\fR \fIdata\fR must point to a static, or allocated, block of memory\&.
.sp
\fBFunction: coap_resource_get_userdata()\fR
.sp
The \fBcoap_resource_get_userdata\fR() function obtains the user data pointer from the \fIresource\fR that had previously been set up by \fBcoap_resource_set_userdata\fR()\&.
.sp
\fBFunction: coap_resource_release_userdata_handler()\fR
.sp
The \fBcoap_resource_release_userdata_handler\fR() function defines the \fIcontext\fR wide \fIcallback\fR handler to call to release the allocated user data that has been added to the resource using \fBcoap_resource_set_userdata\fR() when the resource is deleted\&. \fIcallback\fR can be NULL (which is the default) if nothing needs to be freed off\&.
.sp
\fBFunction: coap_resource_get_uri_path()\fR
.sp
The \fBcoap_resource_get_uri_path\fR() function is used to obtain the UriPath of the \fIresource\fR definion\&.
.SH "RETURN VALUES"
.sp
\fBcoap_resource_init\fR(), \fBcoap_resource_unknown_init\fR(), \fBcoap_resource_unknown_init2\fR(), \fBcoap_resource_proxy_uri_init\fR() and \fBcoap_resource_proxy_uri_init2\fR() return a newly created resource or NULL if there is a malloc failure\&.
.sp
\fBcoap_delete_resource\fR() returns 0 on failure (\fIresource\fR not found), 1 on success\&.
.sp
\fBcoap_resource_get_userdata\fR() returns the value previously set by the \fBcoap_resource_set_userdata\fR() function or NULL\&.
.sp
\fBcoap_resource_get_uri_path\fR() returns the uri_path or NULL if there was a failure\&.
.SH "EXAMPLES"
.sp
\fBFixed Resources Set Up\fR
.sp
.if n \{\
.RS 4
.\}
.nf
#include
#define INDEX "This is an example server using libcoap\en"
static void
hnd_get_index(coap_resource_t *resource, coap_session_t *session,
const coap_pdu_t *request, const coap_string_t *query, coap_pdu_t *response) {
unsigned char buf[3];
/* Remove (void) definition if variable is used */
(void)resource;
(void)session;
(void)request;
(void)query;
coap_pdu_set_code(response, COAP_RESPONSE_CODE_CONTENT);
coap_add_option(response,
COAP_OPTION_CONTENT_TYPE,
coap_encode_var_safe(buf, sizeof(buf),
COAP_MEDIATYPE_TEXT_PLAIN),
buf);
coap_add_option(response,
COAP_OPTION_MAXAGE,
coap_encode_var_safe(buf, sizeof(buf), 0x2ffff), buf);
coap_add_data(response, strlen(INDEX), (const uint8_t *)INDEX);
coap_pdu_set_code(response, COAP_RESPONSE_CODE_CONTENT);
}
static void
hnd_delete_time(coap_resource_t *resource, coap_session_t *session,
const coap_pdu_t *request, const coap_string_t *query, coap_pdu_t *response) {
/* Remove (void) definition if variable is used */
(void)resource;
(void)session;
(void)request;
(void)query;
/* \&.\&. code \&.\&. */
coap_pdu_set_code(response, COAP_RESPONSE_CODE_DELETED);
}
static void
hnd_get_time(coap_resource_t *resource, coap_session_t *session,
const coap_pdu_t *request, const coap_string_t *query, coap_pdu_t *response) {
/* Remove (void) definition if variable is used */
(void)resource;
(void)session;
(void)request;
(void)query;
(void)response;
/* \&.\&. code \&.\&. */
coap_pdu_set_code(response, COAP_RESPONSE_CODE_CONTENT);
}
static void
hnd_put_time(coap_resource_t *resource, coap_session_t *session,
const coap_pdu_t *request, const coap_string_t *query, coap_pdu_t *response) {
/* Remove (void) definition if variable is used */
(void)resource;
(void)session;
(void)request;
(void)query;
(void)response;
/* \&.\&. code \&.\&. */
coap_pdu_set_code(response, COAP_RESPONSE_CODE_CHANGED);
}
static void
init_resources(coap_context_t *ctx) {
coap_resource_t *r;
/* Create a resource to return general information */
r = coap_resource_init(NULL, 0);
coap_register_request_handler(r, COAP_REQUEST_GET, hnd_get_index);
/* Document resource for \*(Aq\&.well\-known/core\*(Aq request */
coap_add_attr(r, coap_make_str_const("ct"), coap_make_str_const("0"), 0);
coap_add_attr(r, coap_make_str_const("title"),
coap_make_str_const("\e"General Info\e""), 0);
coap_add_resource(ctx, r);
/* Create a resource to return return or update time */
r = coap_resource_init(coap_make_str_const("time"),
COAP_RESOURCE_FLAGS_NOTIFY_CON);
coap_resource_set_get_observable(r, 1);
coap_register_request_handler(r, COAP_REQUEST_GET, hnd_get_time);
coap_register_request_handler(r, COAP_REQUEST_PUT, hnd_put_time);
coap_register_request_handler(r, COAP_REQUEST_DELETE, hnd_delete_time);
/* Document resource for \*(Aqtime\*(Aq request */
coap_add_attr(r, coap_make_str_const("ct"), coap_make_str_const("0"), 0);
coap_add_attr(r, coap_make_str_const("title"),
coap_make_str_const("\e"Internal Clock\e""), 0);
coap_add_attr(r, coap_make_str_const("rt"), coap_make_str_const("\e"secs\e""),
0);
coap_add_attr(r, coap_make_str_const("if"), coap_make_str_const("\e"clock\e""),
0);
coap_add_resource(ctx, r);
}
.fi
.if n \{\
.RE
.\}
.sp
\fBDynamic Resources Set Up\fR
.sp
.if n \{\
.RS 4
.\}
.nf
#include
/* Regular DELETE handler \- used by resources created by the
* Unknown Resource PUT handler */
static void
hnd_delete(coap_resource_t *resource, coap_session_t *session,
const coap_pdu_t *request, const coap_string_t *query, coap_pdu_t *response) {
/* Remove (void) definition if variable is used */
(void)session;
(void)request;
(void)query;
(void)response;
/* \&.\&. code \&.\&. */
/* Dynamic resource no longer required \- delete it */
coap_delete_resource(NULL, resource);
coap_pdu_set_code(response, COAP_RESPONSE_CODE_DELETED);
}
/* Regular GET handler \- used by resources created by the
* Unknown Resource PUT handler */
static void
hnd_get(coap_resource_t *resource, coap_session_t *session,
const coap_pdu_t *request, const coap_string_t *query, coap_pdu_t *response) {
coap_str_const_t *get_uri_path;
/* Remove (void) definition if variable is used */
(void)resource;
(void)session;
(void)request;
(void)query;
/*
* Get the specific resource being requested to determine what the response is
* The uri_path string is a const pointer
*/
get_uri_path = coap_resource_get_uri_path(resource);
/* \&.\&. code \&.\&. */
coap_pdu_set_code(response, COAP_RESPONSE_CODE_CONTENT);
}
/* Regular PUT handler \- used by resources created by the
* Unknown Resource PUT handler */
static void
hnd_put(coap_resource_t *resource, coap_session_t *session,
const coap_pdu_t *request, const coap_string_t *query, coap_pdu_t *response) {
/* Remove (void) definition if variable is used */
(void)resource;
(void)session;
(void)query;
coap_string_t *put_uri_path;
size_t length;
const uint8_t *data;
size_t offset;
size_t total;
int new_resource = 0;
/* get the uri_path */
put_uri_path = coap_get_uri_path(request);
if (!put_uri_path) {
coap_pdu_set_code(response, COAP_RESPONSE_CODE_NOT_FOUND);
return;
}
coap_get_data_large(request, &length, &data, &offset, &total);
/* \&.\&. code \&.\&. */
/* Need to do this as coap_get_uri_path() created it */
coap_delete_string(put_uri_path);
if (length + offset < total)
coap_pdu_set_code(response, COAP_RESPONSE_CODE_CONTINUE);
else if (new_resource)
coap_pdu_set_code(response, COAP_RESPONSE_CODE_CREATED);
else
coap_pdu_set_code(response, COAP_RESPONSE_CODE_CHANGED);
}
static int
check_url_fn(coap_string_t *uri_path, uint8_t code) {
/* Remove (void) definition if variable is used */
(void)uri_path;
(void)code;
/* Code to determine whether the uri is valid or not */
return 1;
}
/* Unknown Resource PUT handler */
static void
hnd_put_unknown(coap_resource_t *resource, coap_session_t *session,
const coap_pdu_t *request, const coap_string_t *query, coap_pdu_t *response) {
/* Remove (void) definition if variable is used */
(void)resource;
coap_pdu_code_t req_code = coap_pdu_get_code(request);
coap_resource_t *r;
coap_string_t *uri_path;
/* get the uri_path \- which will get used by coap_resource_init() */
uri_path = coap_get_uri_path(request);
if (!uri_path) {
coap_pdu_set_code(response, COAP_RESPONSE_CODE_NOT_FOUND);
return;
}
/* Check if new URI Path is valid */
if (!check_url_fn (uri_path, req_code)) {
coap_pdu_set_code(response, COAP_RESPONSE_CODE_NOT_FOUND);
coap_delete_string(uri_path);
return;
}
/*
* Create a resource to handle the new URI
* uri_path will get deleted when the resource is removed
*/
r = coap_resource_init((coap_str_const_t*)uri_path,
COAP_RESOURCE_FLAGS_RELEASE_URI | COAP_RESOURCE_FLAGS_NOTIFY_NON);
coap_register_request_handler(r, COAP_REQUEST_PUT, hnd_put);
coap_register_request_handler(r, COAP_REQUEST_DELETE, hnd_delete);
/* We possibly want to Observe the GETs */
coap_resource_set_get_observable(r, 1);
coap_register_request_handler(r, COAP_REQUEST_GET, hnd_get);
coap_add_resource(coap_session_get_context(session), r);
/* Do the PUT for this first call */
hnd_put(r, session, request, query, response);
return;
}
/* Initialize single Unknown Resource PUT handler */
static void
init_resources(coap_context_t *ctx) {
coap_resource_t *r;
/* Create a resource to handle PUTs to unknown URIs */
r = coap_resource_unknown_init2(hnd_put_unknown, 0);
/*
* Additional handlers can be added \- for example
* coap_register_request_handler(r, COAP_REQUEST_POST, hnd_post_unknown);
* coap_register_request_handler(r, COAP_REQUEST_GET, hnd_get_unknown);
* coap_register_request_handler(r, COAP_REQUEST_DELETE, hnd_delete_unknown);
*/
coap_add_resource(ctx, r);
}
.fi
.if n \{\
.RE
.\}
.SH "SEE ALSO"
.sp
\fBcoap_attribute\fR(3), \fBcoap_context\fR(3), \fBcoap_handler\fR(3) and \fBcoap_observe\fR(3)
.SH "FURTHER INFORMATION"
.sp
See
.sp
"RFC7252: The Constrained Application Protocol (CoAP)"
.sp
"RFC3986: Uniform Resource Identifier (URI): Generic Syntax"
.sp
for further information\&.
.SH "BUGS"
.sp
Please report bugs on the mailing list for libcoap: libcoap\-developers@lists\&.sourceforge\&.net or raise an issue on GitHub at https://github\&.com/obgm/libcoap/issues
.SH "AUTHORS"
.sp
The libcoap project