1COAP_STRING(3) libcoap Manual COAP_STRING(3)
2
3
4
6 coap_string, coap_new_string, coap_delete_string, coap_new_str_const,
7 coap_delete_str_const, coap_new_binary, coap_delete_binary,
8 coap_resize_binary, coap_new_bin_const, coap_delete_bin_const,
9 coap_make_str_const, coap_string_equal, coap_binary_equal - Work with
10 CoAP string functions
11
13 #include <coap3/coap.h>
14
15 coap_string_t *coap_new_string(size_t size);
16
17 void coap_delete_string(coap_string_t *string);
18
19 coap_str_const_t *coap_new_str_const(const uint8_t *data, size_t size);
20
21 void coap_delete_str_const(coap_str_const_t *string);
22
23 coap_str_const_t *coap_make_str_const(const char *string);
24
25 int coap_string_equal(coap_string_t *string1, coap_string_t *string2);
26
27 coap_binary_t *coap_new_binary(size_t size);
28
29 void coap_delete_binary(coap_binary_t *binary);
30
31 coap_binary_t *coap_resize_binary(coap_binary_t *binary, size_t
32 new_size);
33
34 coap_bin_const_t *coap_new_bin_const(const uint8_t *data, size_t size);
35
36 void coap_delete_bin_const(coap_bin_const_t *binary);
37
38 int coap_binary_equal(coap_binary_t *binary1, coap_binary_t *binary2);
39
40 For specific (D)TLS library support, link with -lcoap-3-notls,
41 -lcoap-3-gnutls, -lcoap-3-openssl, -lcoap-3-mbedtls or
42 -lcoap-3-tinydtls. Otherwise, link with -lcoap-3 to get the default
43 (D)TLS library support.
44
46 There is support for storing strings (usually readable data) and for
47 storing binary data. These are used by a number of functions and
48 provide the information in some of the callbacks.
49
50 There are 4 supported string/binary types as follows
51
52 /*
53 * Coap string data definition
54 */
55 typedef struct coap_string_t {
56 size_t length; /* length of string */
57 uint8_t *s; /* string data */
58 } coap_string_t;
59
60 /*
61 * Coap string data definition with const data
62 */
63 typedef struct coap_str_const_t {
64 size_t length; /* length of string */
65 const uint8_t *s; /* read-only string data */
66 } coap_str_const_t;
67
68 /*
69 * Coap binary data definition
70 */
71 typedef struct coap_binary_t {
72 size_t length; /* length of binary data */
73 uint8_t *s; /* binary data */
74 } coap_binary_t;
75
76 /*
77 * Coap binary data definition with const data
78 */
79 typedef struct coap_bin_const_t {
80 size_t length; /* length of binary data */
81 const uint8_t *s; /* read-only binary data */
82 } coap_bin_const_t;
83
84 The coap_new_string() function allocates a new coap_string_t of size
85 where s points to uninitialized data of length size with an extra
86 trailing NULL at size + 1. length is set to size.
87
88 The coap_delete_string() function is used to delete the coap_string_t
89 created by coap_new_string().
90
91 The coap_new_str_const() function allocates a coap_str_const_t of size
92 where s is filled in with data and has a trailing NULL added. length is
93 set to size. s is read-only.
94
95 The coap_delete_str_const() function is used to delete the
96 coap_str_const_t created by coap_new_str_const().
97
98 The coap_make_str_const() function is used to take some read-only text
99 and uses a static coap_str_const_t for use in different function calls.
100 There are two static entries that are cycled through so that a single
101 function call can call coap_make_str_const() twice.
102
103 The coap_string_equal() function is used to compare two different
104 string objects string1 and string2.
105
106 The coap_new_binary() function allocates a new coap_binary_t of size
107 where s points to uninitialized data of length size. length is set to
108 size.
109
110 The coap_resize_binary() function is used resize the size of s to the
111 new size of new_size. The data between the old length and the new_size
112 is unitialized. length is set to new_size.
113
114 The coap_delete_binary() function is used to delete the coap_binary_t
115 created by coap_new_binary().
116
117 The coap_new_bin_const() function allocates a coap_bin_const_t of size
118 where s is filled in with in with data and has a trailing NULL added.
119 length is set to size. s is read-only.
120
121 The coap_delete_bin_const() function is used to delete the
122 coap_bin_const_t created by coap_new_bin_const().
123
124 The coap_binary_equal() function is used to compare two different
125 binary objects binary1 and binary2.
126
128 The coap_new_string() function returns a pointer to an allocated
129 coap_string_t or NULL if there was a failure.
130
131 The coap_new_str_const() function returns a pointer to an allocated
132 coap_str_const_t or NULL if there was a failure.
133
134 The coap_new_binary() function returns a pointer to an allocated
135 coap_binary_t or NULL if there was a failure.
136
137 The coap_resize_binary() function returns a pointer to an re-allocated
138 coap_binary_t or NULL if there was a failure.
139
140 The coap_new_bin_const() function returns a pointer to an allocated
141 coap_bin_const_t or NULL if there was a failure.
142
144 coap_attribute(3), coap_context(3), coap_handler(3), coap_pdu_setup(3)
145 and coap_resource(3)
146
148 "RFC7252: The Constrained Application Protocol (CoAP)"
149
151 Please report bugs on the mailing list for libcoap:
152 libcoap-developers@lists.sourceforge.net or raise an issue on GitHub at
153 https://github.com/obgm/libcoap/issues
154
156 The libcoap project <libcoap-developers@lists.sourceforge.net>
157
158
159
160coap_string 4.3.1 01/19/2023 COAP_STRING(3)