'\" t .\" Title: coap_attribute .\" Author: [see the "AUTHORS" section] .\" Generator: DocBook XSL Stylesheets vsnapshot .\" Date: 05/14/2022 .\" Manual: libcoap Manual .\" Source: coap_attribute 4.2.1 .\" Language: English .\" .TH "COAP_ATTRIBUTE" "3" "05/14/2022" "coap_attribute 4\&.2\&.1" "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_attribute, coap_add_attr, coap_find_attr \- Work with CoAP attributes .SH "SYNOPSIS" .sp \fB#include \fR .sp \fBcoap_attr_t *coap_add_attr(coap_resource_t *\fR\fB\fIresource\fR\fR\fB, coap_str_const_t *\fR\fB\fIname\fR\fR\fB, coap_str_const_t *\fR\fB\fIvalue\fR\fR\fB, int \fR\fB\fIflags\fR\fR\fB);\fR .sp \fBcoap_attr_t *coap_find_attr(coap_resource_t *\fR\fB\fIresource\fR\fR\fB, coap_str_const_t *\fR\fB\fIname\fR\fR\fB);\fR .sp Link with \fB\-lcoap\-2\fR, \fB\-lcoap\-2\-gnutls\fR, \fB\-lcoap\-2\-openssl\fR or \fB\-lcoap\-2\-tinydtls\fR depending on your (D)TLS library type\&. .SH "DESCRIPTION" .sp CoAP Resources on a CoAP Server need to be created, updated etc\&. The URI in the request packet defines the resource to work with, with possibly the Query referring to a sub\-resource\&. When resources are configured on the CoAP server, the URI to match against is specified\&. Callback Handlers are then added to the resource to handle the different request methods\&. 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\&. .sp Attributes are automatically freed when a Resource is deleted\&. .sp The \fBcoap_add_attr\fR() function registers a new attribute called \fIname\fR for the \fIresource\fR\&. The value of the attribute is \fIvalue\fR\&. .sp \fIflags\fR can be one or more of the following, which, if set, defines what is to be internally freed off when the attribute is deleted with \fBcoap_delete_resource\fR()\&. .TS tab(:); lt lt lt lt. T{ .sp \fBCOAP_ATTR_FLAGS_RELEASE_NAME\fR T}:T{ .sp Free off \fIname\fR when attribute is deleted with \fBcoap_delete_resource\fR()\&. T} T{ .sp \fBCOAP_ATTR_FLAGS_RELEASE_VALUE\fR T}:T{ .sp Free off \fIvalue\fR when attribute is deleted with \fBcoap_delete_resource\fR()\&. T} .TE .sp 1 .sp The \fBcoap_find_attr\fR() function returns the attribute with the \fIname\fR, if found, associated with \fIresource\fR\&. .SH "RETURN VALUES" .sp \fBcoap_add_attr\fR() function return a pointer to the attribute that was created or NULL if there is a malloc failure\&. .sp \fBcoap_find_attr\fR() function returns a pointer to the first matching attribute or NULL if the \fIname\fR was not found\&. .SH "EXAMPLE" .sp \fBInitialize Resources\fR .sp .if n \{\ .RS 4 .\} .nf #include 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_handler(r, COAP_REQUEST_GET, hnd_get_index); /* Document resource for \&.well\-known/core 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_handler(r, COAP_REQUEST_GET, hnd_get_time); coap_register_handler(r, COAP_REQUEST_PUT, hnd_put_time); coap_register_handler(r, COAP_REQUEST_DELETE, hnd_delete_time); /* Document resource for \&.well\-known/core 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 .\} .SH "SEE ALSO" .sp \fBcoap_resource\fR(3) and \fBcoap_handler\fR(3) .SH "FURTHER INFORMATION" .sp See RFC7252 \(oqThe Constrained Application Protocol (CoAP)\(cq for further information\&. .SH "BUGS" .sp Please report bugs on the mailing list for libcoap: libcoap\-developers@lists\&.sourceforge\&.net .SH "AUTHORS" .sp The libcoap project