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
85 Function: coap_new_string()
86
87 The coap_new_string() function allocates a new coap_string_t of size
88 where s points to uninitialized data of length size with an extra
89 trailing NULL at size + 1. length is set to size.
90
91 Function: coap_delete_string()
92
93 The coap_delete_string() function is used to delete the coap_string_t
94 created by coap_new_string().
95
96 Function: coap_new_str_const()
97
98 The coap_new_str_const() function allocates a coap_str_const_t of size
99 where s is filled in with data and has a trailing NULL added. length is
100 set to size. s is read-only.
101
102 Function: coap_delete_str_const()
103
104 The coap_delete_str_const() function is used to delete the
105 coap_str_const_t created by coap_new_str_const().
106
107 Function: coap_make_str_const()
108
109 The coap_make_str_const() function is used to take some read-only text
110 and uses a static coap_str_const_t for use in different function calls.
111 There are two static entries that are cycled through so that a single
112 function call can call coap_make_str_const() twice.
113
114 Function: coap_string_equal()
115
116 The coap_string_equal() function is used to compare two different
117 string objects string1 and string2.
118
119 Function: coap_new_binary()
120
121 The coap_new_binary() function allocates a new coap_binary_t of size
122 where s points to uninitialized data of length size. length is set to
123 size.
124
125 Function: coap_resize_binary()
126
127 The coap_resize_binary() function is used resize the size of s to the
128 new size of new_size. The data between the old length and the new_size
129 is unitialized. length is set to new_size.
130
131 Function: coap_delete_binary()
132
133 The coap_delete_binary() function is used to delete the coap_binary_t
134 created by coap_new_binary().
135
136 Function: coap_new_bin_const()
137
138 The coap_new_bin_const() function allocates a coap_bin_const_t of size
139 where s is filled in with in with data and has a trailing NULL added.
140 length is set to size. s is read-only.
141
142 Function: coap_delete_bin_const()
143
144 The coap_delete_bin_const() function is used to delete the
145 coap_bin_const_t created by coap_new_bin_const().
146
147 Function: coap_binary_equal()
148
149 The coap_binary_equal() function is used to compare two different
150 binary objects binary1 and binary2.
151
153 coap_new_string() returns a pointer to an allocated coap_string_t or
154 NULL if there was a failure.
155
156 coap_new_str_const() returns a pointer to an allocated coap_str_const_t
157 or NULL if there was a failure.
158
159 coap_make_str_const() returns a pointer to a structure in static memory
160 that has a pointer to the provided string.
161
162 coap_new_binary() returns a pointer to an allocated coap_binary_t or
163 NULL if there was a failure.
164
165 coap_resize_binary() returns a pointer to an re-allocated coap_binary_t
166 or NULL if there was a failure.
167
168 coap_new_bin_const() returns a pointer to an allocated coap_bin_const_t
169 or NULL if there was a failure.
170
171 coap_string_equal() and coap_binary_equal() return 1 on a precise
172 match, else 0.
173
175 coap_attribute(3), coap_context(3), coap_handler(3), coap_pdu_setup(3)
176 and coap_resource(3)
177
179 See
180
181 "RFC7252: The Constrained Application Protocol (CoAP)"
182
183 for further information.
184
186 Please report bugs on the mailing list for libcoap:
187 libcoap-developers@lists.sourceforge.net or raise an issue on GitHub at
188 https://github.com/obgm/libcoap/issues
189
191 The libcoap project <libcoap-developers@lists.sourceforge.net>
192
193
194
195coap_string 4.3.4 10/09/2023 COAP_STRING(3)