table of contents
COAP_STRING(3) | libcoap Manual | COAP_STRING(3) |
NAME¶
coap_string, coap_new_string, coap_delete_string, coap_new_str_const, coap_delete_str_const, coap_new_binary, coap_delete_binary, coap_resize_binary, coap_new_bin_const, coap_delete_bin_const, coap_make_str_const, coap_string_equal, coap_binary_equal - Work with CoAP string functions
SYNOPSIS¶
#include <coap3/coap.h>
coap_string_t *coap_new_string(size_t size);
void coap_delete_string(coap_string_t *string);
coap_str_const_t *coap_new_str_const(const uint8_t *data, size_t size);
void coap_delete_str_const(coap_str_const_t *string);
coap_str_const_t *coap_make_str_const(const char *string);
int coap_string_equal(coap_string_t *string1, coap_string_t *string2);
coap_binary_t *coap_new_binary(size_t size);
void coap_delete_binary(coap_binary_t *binary);
coap_binary_t *coap_resize_binary(coap_binary_t *binary, size_t new_size);
coap_bin_const_t *coap_new_bin_const(const uint8_t *data, size_t size);
void coap_delete_bin_const(coap_bin_const_t *binary);
int coap_binary_equal(coap_binary_t *binary1, coap_binary_t *binary2);
For specific (D)TLS library support, link with -lcoap-3-notls, -lcoap-3-gnutls, -lcoap-3-openssl, -lcoap-3-mbedtls or -lcoap-3-tinydtls. Otherwise, link with -lcoap-3 to get the default (D)TLS library support.
DESCRIPTION¶
There is support for storing strings (usually readable data) and for storing binary data. These are used by a number of functions and provide the information in some of the callbacks.
There are 4 supported string/binary types as follows
/*
* Coap string data definition
*/ typedef struct coap_string_t {
size_t length; /* length of string */
uint8_t *s; /* string data */ } coap_string_t; /*
* Coap string data definition with const data
*/ typedef struct coap_str_const_t {
size_t length; /* length of string */
const uint8_t *s; /* read-only string data */ } coap_str_const_t; /*
* Coap binary data definition
*/ typedef struct coap_binary_t {
size_t length; /* length of binary data */
uint8_t *s; /* binary data */ } coap_binary_t; /*
* Coap binary data definition with const data
*/ typedef struct coap_bin_const_t {
size_t length; /* length of binary data */
const uint8_t *s; /* read-only binary data */ } coap_bin_const_t;
FUNCTIONS¶
Function: coap_new_string()
The coap_new_string() function allocates a new coap_string_t of size where s points to uninitialized data of length size with an extra trailing NULL at size + 1. length is set to size.
Function: coap_delete_string()
The coap_delete_string() function is used to delete the coap_string_t created by coap_new_string().
Function: coap_new_str_const()
The coap_new_str_const() function allocates a coap_str_const_t of size where s is filled in with data and has a trailing NULL added. length is set to size. s is read-only.
Function: coap_delete_str_const()
The coap_delete_str_const() function is used to delete the coap_str_const_t created by coap_new_str_const().
Function: coap_make_str_const()
The coap_make_str_const() function is used to take some read-only text and uses a static coap_str_const_t for use in different function calls. There are two static entries that are cycled through so that a single function call can call coap_make_str_const() twice.
Function: coap_string_equal()
The coap_string_equal() function is used to compare two different string objects string1 and string2.
Function: coap_new_binary()
The coap_new_binary() function allocates a new coap_binary_t of size where s points to uninitialized data of length size. length is set to size.
Function: coap_resize_binary()
The coap_resize_binary() function is used resize the size of s to the new size of new_size. The data between the old length and the new_size is unitialized. length is set to new_size.
Function: coap_delete_binary()
The coap_delete_binary() function is used to delete the coap_binary_t created by coap_new_binary().
Function: coap_new_bin_const()
The coap_new_bin_const() function allocates a coap_bin_const_t of size where s is filled in with in with data and has a trailing NULL added. length is set to size. s is read-only.
Function: coap_delete_bin_const()
The coap_delete_bin_const() function is used to delete the coap_bin_const_t created by coap_new_bin_const().
Function: coap_binary_equal()
The coap_binary_equal() function is used to compare two different binary objects binary1 and binary2.
RETURN VALUES¶
coap_new_string() returns a pointer to an allocated coap_string_t or NULL if there was a failure.
coap_new_str_const() returns a pointer to an allocated coap_str_const_t or NULL if there was a failure.
coap_make_str_const() returns a pointer to a structure in static memory that has a pointer to the provided string.
coap_new_binary() returns a pointer to an allocated coap_binary_t or NULL if there was a failure.
coap_resize_binary() returns a pointer to an re-allocated coap_binary_t or NULL if there was a failure.
coap_new_bin_const() returns a pointer to an allocated coap_bin_const_t or NULL if there was a failure.
coap_string_equal() and coap_binary_equal() return 1 on a precise match, else 0.
SEE ALSO¶
coap_attribute(3), coap_context(3), coap_handler(3), coap_pdu_setup(3) and coap_resource(3)
FURTHER INFORMATION¶
See
"RFC7252: The Constrained Application Protocol (CoAP)"
for further information.
BUGS¶
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
AUTHORS¶
The libcoap project <libcoap-developers@lists.sourceforge.net>
04/07/2024 | coap_string 4.3.4 |