libcoap 4.3.2rc1
Loading...
Searching...
No Matches
coap_uri.c
Go to the documentation of this file.
1/* coap_uri.c -- helper functions for URI treatment
2 *
3 * Copyright (C) 2010--2012,2015-2016,2022-2023 Olaf Bergmann <bergmann@tzi.org>
4 *
5 * SPDX-License-Identifier: BSD-2-Clause
6 *
7 * This file is part of the CoAP library libcoap. Please see
8 * README for terms of use.
9 */
10
16#include "coap3/coap_internal.h"
17
18#if defined(HAVE_LIMITS_H)
19#include <limits.h>
20#endif
21
22#include <stdint.h>
23#include <stdio.h>
24#include <string.h>
25#include <ctype.h>
26
38COAP_STATIC_INLINE const uint8_t *
39strnchr(const uint8_t *s, size_t len, unsigned char c) {
40 while (len && *s++ != c)
41 --len;
42
43 return len ? s : NULL;
44}
45
50
56 { "http", 80, 1, COAP_URI_SCHEME_HTTP },
57 { "https", 443, 1, COAP_URI_SCHEME_HTTPS },
58 { "coap+ws", 80, 0, COAP_URI_SCHEME_COAP_WS },
59 { "coaps+ws", 443, 0, COAP_URI_SCHEME_COAPS_WS }
60};
61
62static int
63coap_split_uri_sub(const uint8_t *str_var,
64 size_t len,
65 coap_uri_t *uri,
66 coap_uri_check_t check_proxy) {
67 const uint8_t *p, *q;
68 int res = 0;
69 size_t i;
70 int is_unix_domain = 0;
71
72 if (!str_var || !uri || len == 0)
73 return -1;
74
75 memset(uri, 0, sizeof(coap_uri_t));
77
78 /* search for scheme */
79 p = str_var;
80 if (*p == '/') {
81 /* no scheme, host or port */
82 if (check_proxy == COAP_URI_CHECK_PROXY) {
83 /* Must have ongoing host if proxy definition */
84 return -1;
85 }
86 q = p;
87 goto path;
88 }
89
90 /* find scheme terminating :// */
91 while (len >= 3 && !(p[0] == ':' && p[1] == '/' && p[2] == '/')) {
92 ++p;
93 --len;
94 }
95 if (len < 3) {
96 /* scheme not defined with a :// terminator */
97 res = -2;
98 goto error;
99 }
100 for (i = 0; i < COAP_URI_SCHEME_LAST; i++) {
101 if ((p - str_var) == (int)strlen(coap_uri_scheme[i].name) &&
102 memcmp(str_var, coap_uri_scheme[i].name, p - str_var) == 0) {
103 if (check_proxy != COAP_URI_CHECK_PROXY && coap_uri_scheme[i].proxy_only) {
104 coap_log_err("%.*s URI scheme not enabled (not a proxy)\n",
105 (int)(p - str_var), str_var);
106 return -1;
107 }
108 uri->scheme = coap_uri_scheme[i].scheme;
109 uri->port = coap_uri_scheme[i].port;
110 break;
111 }
112 }
113 if (i == COAP_URI_SCHEME_LAST) {
114 /* scheme unknown */
115 coap_log_err("%.*s URI scheme unknown\n", (int)(p - str_var), str_var);
116 res = -1;
117 goto error;
118 }
119 switch (uri->scheme) {
121 break;
123 if (!coap_dtls_is_supported()) {
124 coap_log_err("coaps URI scheme not supported in this version of libcoap\n");
125 return -1;
126 }
127 break;
129 if (!coap_tcp_is_supported()) {
130 coap_log_err("coap+tcp URI scheme not supported in this version of libcoap\n");
131 return -1;
132 }
133 break;
135 if (!coap_tcp_is_supported()) {
136 coap_log_err("coaps+tcp URI scheme not supported in this version of libcoap\n");
137 return -1;
138 }
139 break;
141 if (!coap_ws_is_supported()) {
142 coap_log_err("coap+ws URI scheme not supported in this version of libcoap\n");
143 return -1;
144 }
145 break;
147 if (!coap_wss_is_supported()) {
148 coap_log_err("coaps+ws URI scheme not supported in this version of libcoap\n");
149 return -1;
150 }
151 break;
155 default:
156 coap_log_warn("Unsupported URI type %d\n", uri->scheme);
157 return -1;
158 }
159 /* skip :// */
160 p += 3;
161 len -= 3;
162
163 /* p points to beginning of Uri-Host */
164 q = p;
165 if (len && *p == '[') {
166 /* IPv6 address reference */
167 ++p;
168
169 while (len && *q != ']') {
170 ++q;
171 --len;
172 }
173
174 if (!len || *q != ']' || p == q) {
175 res = -3;
176 goto error;
177 }
178
179 COAP_SET_STR(&uri->host, q - p, p);
180 ++q;
181 --len;
182 } else {
183 /* IPv4 address, FQDN or Unix domain socket */
184 if (len >= 3 && p[0] == '%' && p[1] == '2' &&
185 (p[2] == 'F' || p[2] == 'f')) {
186 /* Unix domain definition */
187 uri->port = 0;
188 is_unix_domain = 1;
189 }
190 while (len && *q != ':' && *q != '/' && *q != '?') {
191 ++q;
192 --len;
193 }
194
195 if (p == q) {
196 res = -3;
197 goto error;
198 }
199
200 COAP_SET_STR(&uri->host, q - p, p);
201 }
202
203 /* check for Uri-Port (invalid for Unix) */
204 if (len && *q == ':') {
205 if (is_unix_domain) {
206 res = -5;
207 goto error;
208 }
209 p = ++q;
210 --len;
211
212 while (len && isdigit(*q)) {
213 ++q;
214 --len;
215 }
216
217 if (p < q) { /* explicit port number given */
218 int uri_port = 0;
219
220 while ((p < q) && (uri_port <= UINT16_MAX))
221 uri_port = uri_port * 10 + (*p++ - '0');
222
223 /* check if port number is in allowed range */
224 if (uri_port > UINT16_MAX) {
225 res = -4;
226 goto error;
227 }
228
229 uri->port = (uint16_t)uri_port;
230 }
231 }
232
233path: /* at this point, p must point to an absolute path */
234
235 if (!len)
236 goto end;
237
238 if (*q == '/') {
239 p = ++q;
240 --len;
241
242 while (len && *q != '?') {
243 ++q;
244 --len;
245 }
246
247 if (p < q) {
248 COAP_SET_STR(&uri->path, q - p, p);
249 p = q;
250 }
251 }
252
253 /* Uri_Query */
254 if (len && *p == '?') {
255 ++p;
256 --len;
257 COAP_SET_STR(&uri->query, len, p);
258 len = 0;
259 }
260
261end:
262 return len ? -1 : 0;
263
264error:
265 return res;
266}
267
268int
269coap_split_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri) {
270 return coap_split_uri_sub(str_var, len, uri, COAP_URI_CHECK_URI);
271}
272
273int
274coap_split_proxy_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri) {
275 return coap_split_uri_sub(str_var, len, uri, COAP_URI_CHECK_PROXY);
276}
277
278int
280 coap_optlist_t **optlist_chain, int create_port_host_opt,
281 uint8_t *_buf, size_t _buflen) {
282 int res;
283 unsigned char *buf = _buf;
284 size_t buflen = _buflen;
285
286 if (create_port_host_opt && !coap_host_is_unix_domain(&uri->host)) {
287 int add_option = 0;
288
289 if (dst && uri->host.length) {
290#if !defined(WITH_LWIP) && !defined(WITH_CONTIKI)
291 char addr[INET6_ADDRSTRLEN];
292#else /* WITH_LWIP || WITH_CONTIKI */
293 char addr[40];
294#endif /* WITH_LWIP || WITH_CONTIKI */
295
296 /* Add in UriHost if not match (need to strip off &iface) */
297 size_t uri_host_len = uri->host.length;
298 uint8_t *cp = (uint8_t *)strchr((const char *)uri->host.s, '%');
299
300 if (cp && (size_t)(cp - uri->host.s) < uri_host_len)
301 /* %iface specified in host name */
302 uri_host_len = cp - uri->host.s;
303
304 if (coap_print_ip_addr(dst, addr, sizeof(addr)) &&
305 (strlen(addr) != uri_host_len ||
306 memcmp(addr, uri->host.s, uri_host_len) != 0)) {
307 /* add Uri-Host */
308 coap_insert_optlist(optlist_chain,
310 uri->host.length,
311 uri->host.s));
312 }
313 }
314 /* Add in UriPort if not default */
315 switch ((int)uri->scheme) {
318 if (uri->port != 80)
319 add_option = 1;
320 break;
323 if (uri->port != 443)
324 add_option = 1;
325 break;
326 default:
329 add_option = 1;
330 break;
331 }
332 if (add_option)
333 coap_insert_optlist(optlist_chain,
336 (uri->port & 0xffff)),
337 buf));
338 }
339
340 if (uri->path.length) {
341 if (uri->path.length > buflen)
342 coap_log_warn("URI path will be truncated (max buffer %zu)\n",
343 buflen);
344 res = coap_split_path(uri->path.s, uri->path.length, buf, &buflen);
345 if (res < 0)
346 return -1;
347
348 while (res--) {
349 coap_insert_optlist(optlist_chain,
351 coap_opt_length(buf),
352 coap_opt_value(buf)));
353
354 buf += coap_opt_size(buf);
355 }
356 }
357
358 if (uri->query.length) {
359 buflen = _buflen;
360 buf = _buf;
361 if (uri->query.length > buflen)
362 coap_log_warn("URI query will be truncated (max buffer %zu)\n",
363 buflen);
364 res = coap_split_query(uri->query.s, uri->query.length, buf, &buflen);
365 if (res < 0)
366 return -1;
367
368 while (res--) {
369 coap_insert_optlist(optlist_chain,
371 coap_opt_length(buf),
372 coap_opt_value(buf)));
373
374 buf += coap_opt_size(buf);
375 }
376 }
377 return 0;
378}
379
380int
382 if (host->length >= 3 && host->s[0] == '%' &&
383 host->s[1] == '2' &&
384 (host->s[2] == 'F' || host->s[2] == 'f')) {
385 return 1;
386 }
387 if (host->length >= 1 && host->s[0] == '/')
388 return 1;
389 return 0;
390}
391
399#define hexchar_to_dec(c) ((c) & 0x40 ? ((c) & 0x0F) + 9 : ((c) & 0x0F))
400
413static void
414decode_segment(const uint8_t *seg, size_t length, unsigned char *buf) {
415
416 while (length--) {
417
418 if (*seg == '%') {
419 *buf = (hexchar_to_dec(seg[1]) << 4) + hexchar_to_dec(seg[2]);
420
421 seg += 2;
422 length -= 2;
423 } else {
424 *buf = *seg;
425 }
426
427 ++buf;
428 ++seg;
429 }
430}
431
437static int
438check_segment(const uint8_t *s, size_t length, size_t *segment_size) {
439 size_t n = 0;
440
441 while (length) {
442 if (*s == '%') {
443 if (length < 2 || !(isxdigit(s[1]) && isxdigit(s[2])))
444 return -1;
445
446 s += 2;
447 length -= 2;
448 }
449
450 ++s;
451 ++n;
452 --length;
453 }
454
455 *segment_size = n;
456
457 return 0;
458}
459
480static int
481make_decoded_option(const uint8_t *s, size_t length,
482 unsigned char *buf, size_t buflen, size_t *optionsize) {
483 int res;
484 size_t segmentlen;
485 size_t written;
486
487 if (!buflen) {
488 coap_log_debug("make_decoded_option(): buflen is 0!\n");
489 return -1;
490 }
491
492 res = check_segment(s, length, &segmentlen);
493 if (res < 0)
494 return -1;
495
496 /* write option header using delta 0 and length res */
497 written = coap_opt_setheader(buf, buflen, 0, segmentlen);
498
499 assert(written <= buflen);
500
501 if (!written) /* encoding error */
502 return -1;
503
504 buf += written; /* advance past option type/length */
505 buflen -= written;
506
507 if (buflen < segmentlen) {
508 coap_log_debug("buffer too small for option\n");
509 return -1;
510 }
511
512 decode_segment(s, length, buf);
513
514 *optionsize = written + segmentlen;
515
516 return 0;
517}
518
519
520#ifndef min
521#define min(a,b) ((a) < (b) ? (a) : (b))
522#endif
523
524typedef void (*segment_handler_t)(const uint8_t *, size_t, void *);
525
530dots(const uint8_t *s, size_t len) {
531 return len && *s == '.' && (len == 1 || (len == 2 && *(s+1) == '.'));
532}
533
545static size_t
546coap_split_path_impl(const uint8_t *s, size_t length,
547 segment_handler_t h, void *data) {
548
549 const uint8_t *p, *q;
550
551 p = q = s;
552 while (length > 0 && !strnchr((const uint8_t *)"?#", 2, *q)) {
553 if (*q == '/') { /* start new segment */
554
555 if (!dots(p, q - p)) {
556 h(p, q - p, data);
557 }
558
559 p = q + 1;
560 }
561
562 q++;
563 length--;
564 }
565
566 /* write last segment */
567 if (!dots(p, q - p)) {
568 h(p, q - p, data);
569 }
570
571 return q - s;
572}
573
574struct cnt_str {
576 int n;
577};
578
579static void
580write_option(const uint8_t *s, size_t len, void *data) {
581 struct cnt_str *state = (struct cnt_str *)data;
582 int res;
583 size_t optionsize;
584 assert(state);
585
586 res = make_decoded_option(s, len, state->buf.s, state->buf.length, &optionsize);
587 if (res == 0) {
588 state->buf.s += optionsize;
589 state->buf.length -= optionsize;
590 state->n++;
591 }
592}
593
594int
595coap_split_path(const uint8_t *s, size_t length,
596 unsigned char *buf, size_t *buflen) {
597 struct cnt_str tmp = { { *buflen, buf }, 0 };
598
599 coap_split_path_impl(s, length, write_option, &tmp);
600
601 *buflen = *buflen - tmp.buf.length;
602
603 return tmp.n;
604}
605
606int
607coap_split_query(const uint8_t *s, size_t length,
608 unsigned char *buf, size_t *buflen) {
609 struct cnt_str tmp = { { *buflen, buf }, 0 };
610 const uint8_t *p;
611
612 p = s;
613 while (length > 0 && *s != '#') {
614 if (*s == '&') { /* start new query element */
615 write_option(p, s - p, &tmp);
616 p = s + 1;
617 }
618
619 s++;
620 length--;
621 }
622
623 /* write last query element */
624 write_option(p, s - p, &tmp);
625
626 *buflen = *buflen - tmp.buf.length;
627 return tmp.n;
628}
629
630#define URI_DATA(uriobj) ((unsigned char *)(uriobj) + sizeof(coap_uri_t))
631
633coap_new_uri(const uint8_t *uri, unsigned int length) {
634 unsigned char *result;
635
636 result = (unsigned char *)coap_malloc_type(COAP_STRING, length + 1 + sizeof(coap_uri_t));
637
638 if (!result)
639 return NULL;
640
641 memcpy(URI_DATA(result), uri, length);
642 URI_DATA(result)[length] = '\0'; /* make it zero-terminated */
643
644 if (coap_split_uri(URI_DATA(result), length, (coap_uri_t *)result) < 0) {
646 return NULL;
647 }
648 return (coap_uri_t *)result;
649}
650
653 coap_uri_t *result;
654 uint8_t *p;
655
656 if (!uri)
657 return NULL;
658
660 uri->path.length + sizeof(coap_uri_t) + 1);
661
662 if (!result)
663 return NULL;
664
665 memset(result, 0, sizeof(coap_uri_t));
666
667 result->port = uri->port;
668
669 if (uri->host.length) {
670 result->host.s = p = URI_DATA(result);
671 result->host.length = uri->host.length;
672
673 memcpy(p, uri->host.s, uri->host.length);
674 }
675
676 if (uri->path.length) {
677 result->path.s = p = URI_DATA(result) + uri->host.length;
678 result->path.length = uri->path.length;
679
680 memcpy(p, uri->path.s, uri->path.length);
681 }
682
683 if (uri->query.length) {
684 result->query.s = p = URI_DATA(result) + uri->host.length + uri->path.length;
685 result->query.length = uri->query.length;
686
687 memcpy(p, uri->query.s, uri->query.length);
688 }
689
690 return result;
691}
692
693void
697
699is_unescaped_in_path(const uint8_t c) {
700 return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') ||
701 (c >= '0' && c <= '9') || c == '-' || c == '.' || c == '_' ||
702 c == '~' || c == '!' || c == '$' || c == '\'' || c == '(' ||
703 c == ')' || c == '*' || c == '+' || c == ',' || c == ';' ||
704 c=='=' || c==':' || c=='@' || c == '&';
705}
706
708is_unescaped_in_query(const uint8_t c) {
709 return is_unescaped_in_path(c) || c=='/' || c=='?';
710}
711
713coap_get_query(const coap_pdu_t *request) {
714 coap_opt_iterator_t opt_iter;
716 coap_opt_t *q;
717 coap_string_t *query = NULL;
718 size_t length = 0;
719 static const uint8_t hex[] = "0123456789ABCDEF";
720
723 coap_option_iterator_init(request, &opt_iter, &f);
724 while ((q = coap_option_next(&opt_iter))) {
725 uint16_t seg_len = coap_opt_length(q), i;
726 const uint8_t *seg= coap_opt_value(q);
727 for (i = 0; i < seg_len; i++) {
728 if (is_unescaped_in_query(seg[i]))
729 length += 1;
730 else
731 length += 3;
732 }
733 length += 1;
734 }
735 if (length > 0)
736 length -= 1;
737 if (length > 0) {
738 query = coap_new_string(length);
739 if (query) {
740 query->length = length;
741 unsigned char *s = query->s;
742 coap_option_iterator_init(request, &opt_iter, &f);
743 while ((q = coap_option_next(&opt_iter))) {
744 if (s != query->s)
745 *s++ = '&';
746 uint16_t seg_len = coap_opt_length(q), i;
747 const uint8_t *seg= coap_opt_value(q);
748 for (i = 0; i < seg_len; i++) {
749 if (is_unescaped_in_query(seg[i])) {
750 *s++ = seg[i];
751 } else {
752 *s++ = '%';
753 *s++ = hex[seg[i]>>4];
754 *s++ = hex[seg[i]&0x0F];
755 }
756 }
757 }
758 }
759 }
760 return query;
761}
762
765 coap_opt_iterator_t opt_iter;
767 coap_opt_t *q;
768 coap_string_t *uri_path = NULL;
769 size_t length = 0;
770 static const uint8_t hex[] = "0123456789ABCDEF";
771
772 q = coap_check_option(request, COAP_OPTION_PROXY_URI, &opt_iter);
773 if (q) {
774 coap_uri_t uri;
775
777 coap_opt_length(q), &uri) < 0) {
778 return NULL;
779 }
780 uri_path = coap_new_string(uri.path.length);
781 if (uri_path) {
782 memcpy(uri_path->s, uri.path.s, uri.path.length);
783 }
784 return uri_path;
785 }
786
789 coap_option_iterator_init(request, &opt_iter, &f);
790 while ((q = coap_option_next(&opt_iter))) {
791 uint16_t seg_len = coap_opt_length(q), i;
792 const uint8_t *seg= coap_opt_value(q);
793 for (i = 0; i < seg_len; i++) {
794 if (is_unescaped_in_path(seg[i]))
795 length += 1;
796 else
797 length += 3;
798 }
799 /* bump for the leading "/" */
800 length += 1;
801 }
802 /* The first entry does not have a leading "/" */
803 if (length > 0)
804 length -= 1;
805
806 /* if 0, either no URI_PATH Option, or the first one was empty */
807 uri_path = coap_new_string(length);
808 if (uri_path) {
809 uri_path->length = length;
810 unsigned char *s = uri_path->s;
811 int n = 0;
812 coap_option_iterator_init(request, &opt_iter, &f);
813 while ((q = coap_option_next(&opt_iter))) {
814 if (n++) {
815 *s++ = '/';
816 }
817 uint16_t seg_len = coap_opt_length(q), i;
818 const uint8_t *seg= coap_opt_value(q);
819 for (i = 0; i < seg_len; i++) {
820 if (is_unescaped_in_path(seg[i])) {
821 *s++ = seg[i];
822 } else {
823 *s++ = '%';
824 *s++ = hex[seg[i]>>4];
825 *s++ = hex[seg[i]&0x0F];
826 }
827 }
828 }
829 }
830 return uri_path;
831}
#define INET6_ADDRSTRLEN
Definition coap_debug.c:211
Pulls together all the internal only header files.
@ COAP_STRING
Definition coap_mem.h:38
void * coap_malloc_type(coap_memory_tag_t type, size_t size)
Allocates a chunk of size bytes and returns a pointer to the newly allocated memory.
void coap_free_type(coap_memory_tag_t type, void *p)
Releases the memory that was allocated by coap_malloc_type().
size_t coap_opt_size(const coap_opt_t *opt)
Returns the size of the given option, taking into account a possible option jump.
uint8_t coap_opt_t
Use byte-oriented access methods here because sliding a complex struct coap_opt_t over the data buffe...
Definition coap_option.h:26
int coap_tcp_is_supported(void)
Check whether TCP is available.
Definition coap_tcp.c:37
COAP_STATIC_INLINE int is_unescaped_in_path(const uint8_t c)
Definition coap_uri.c:699
static void decode_segment(const uint8_t *seg, size_t length, unsigned char *buf)
Decodes percent-encoded characters while copying the string seg of size length to buf.
Definition coap_uri.c:414
COAP_STATIC_INLINE int is_unescaped_in_query(const uint8_t c)
Definition coap_uri.c:708
COAP_STATIC_INLINE int dots(const uint8_t *s, size_t len)
Checks if path segment s consists of one or two dots.
Definition coap_uri.c:530
static size_t coap_split_path_impl(const uint8_t *s, size_t length, segment_handler_t h, void *data)
Splits the given string into segments.
Definition coap_uri.c:546
COAP_STATIC_INLINE const uint8_t * strnchr(const uint8_t *s, size_t len, unsigned char c)
A length-safe version of strchr().
Definition coap_uri.c:39
static int check_segment(const uint8_t *s, size_t length, size_t *segment_size)
Runs through the given path (or query) segment and checks if percent-encodings are correct.
Definition coap_uri.c:438
static void write_option(const uint8_t *s, size_t len, void *data)
Definition coap_uri.c:580
void coap_delete_uri(coap_uri_t *uri)
Removes the specified coap_uri_t object.
Definition coap_uri.c:694
static int coap_split_uri_sub(const uint8_t *str_var, size_t len, coap_uri_t *uri, coap_uri_check_t check_proxy)
Definition coap_uri.c:63
#define hexchar_to_dec(c)
Calculates decimal value from hexadecimal ASCII character given in c.
Definition coap_uri.c:399
static int make_decoded_option(const uint8_t *s, size_t length, unsigned char *buf, size_t buflen, size_t *optionsize)
Writes a coap option from given string s to buf.
Definition coap_uri.c:481
coap_uri_check_t
Definition coap_uri.c:46
@ COAP_URI_CHECK_URI
Definition coap_uri.c:47
@ COAP_URI_CHECK_PROXY
Definition coap_uri.c:48
coap_uri_t * coap_clone_uri(const coap_uri_t *uri)
Clones the specified coap_uri_t object.
Definition coap_uri.c:652
#define URI_DATA(uriobj)
Definition coap_uri.c:630
coap_uri_t * coap_new_uri(const uint8_t *uri, unsigned int length)
Creates a new coap_uri_t object from the specified URI.
Definition coap_uri.c:633
int coap_host_is_unix_domain(const coap_str_const_t *host)
Determines from the host whether this is a Unix Domain socket request.
Definition coap_uri.c:381
void(* segment_handler_t)(const uint8_t *, size_t, void *)
Definition coap_uri.c:524
static int coap_uri_scheme_is_secure(const coap_uri_t *uri)
Definition coap_uri.h:79
@ COAP_URI_SCHEME_COAPS_WS
Definition coap_uri.h:36
@ COAP_URI_SCHEME_COAPS_TCP
Definition coap_uri.h:32
@ COAP_URI_SCHEME_COAPS
Definition coap_uri.h:30
@ COAP_URI_SCHEME_COAP_TCP
Definition coap_uri.h:31
@ COAP_URI_SCHEME_COAP_WS
Definition coap_uri.h:35
@ COAP_URI_SCHEME_HTTPS
Definition coap_uri.h:34
@ COAP_URI_SCHEME_COAP
Definition coap_uri.h:29
@ COAP_URI_SCHEME_LAST
Definition coap_uri.h:37
@ COAP_URI_SCHEME_HTTP
Definition coap_uri.h:33
int coap_dtls_is_supported(void)
Check whether DTLS is available.
Definition coap_notls.c:23
unsigned int coap_encode_var_safe(uint8_t *buf, size_t length, unsigned int val)
Encodes multiple-length byte sequences.
Definition coap_encode.c:47
#define coap_log_debug(...)
Definition coap_debug.h:120
const char * coap_print_ip_addr(const coap_address_t *addr, char *buf, size_t len)
Print the IP address into the defined buffer.
Definition coap_debug.c:364
#define coap_log_warn(...)
Definition coap_debug.h:102
#define coap_log_err(...)
Definition coap_debug.h:96
coap_opt_t * coap_option_next(coap_opt_iterator_t *oi)
Updates the iterator oi to point to the next option.
coap_optlist_t * coap_new_optlist(uint16_t number, size_t length, const uint8_t *data)
Create a new optlist entry.
uint32_t coap_opt_length(const coap_opt_t *opt)
Returns the length of the given option.
coap_opt_iterator_t * coap_option_iterator_init(const coap_pdu_t *pdu, coap_opt_iterator_t *oi, const coap_opt_filter_t *filter)
Initializes the given option iterator oi to point to the beginning of the pdu's option list.
void coap_option_filter_clear(coap_opt_filter_t *filter)
Clears filter filter.
coap_opt_t * coap_check_option(const coap_pdu_t *pdu, coap_option_num_t number, coap_opt_iterator_t *oi)
Retrieves the first option of number number from pdu.
int coap_insert_optlist(coap_optlist_t **head, coap_optlist_t *node)
Adds optlist to the given optlist_chain.
const uint8_t * coap_opt_value(const coap_opt_t *opt)
Returns a pointer to the value of the given option.
int coap_option_filter_set(coap_opt_filter_t *filter, coap_option_num_t option)
Sets the corresponding entry for number in filter.
size_t coap_opt_setheader(coap_opt_t *opt, size_t maxlen, uint16_t delta, size_t length)
Encodes the given delta and length values into opt.
#define COAP_OPTION_URI_HOST
Definition coap_pdu.h:116
#define COAP_DEFAULT_PORT
Definition coap_pdu.h:37
#define COAP_OPTION_URI_QUERY
Definition coap_pdu.h:128
#define COAP_OPTION_URI_PATH
Definition coap_pdu.h:123
#define COAPS_DEFAULT_PORT
Definition coap_pdu.h:38
#define COAP_OPTION_URI_PORT
Definition coap_pdu.h:120
#define COAP_OPTION_PROXY_URI
Definition coap_pdu.h:137
#define COAP_SET_STR(st, l, v)
Definition coap_str.h:51
coap_string_t * coap_new_string(size_t size)
Returns a new string object with at least size+1 bytes storage allocated.
Definition coap_str.c:21
coap_string_t * coap_get_uri_path(const coap_pdu_t *request)
Extract uri_path string from request PDU.
Definition coap_uri.c:764
int coap_split_path(const uint8_t *s, size_t length, unsigned char *buf, size_t *buflen)
Splits the given URI path into segments.
Definition coap_uri.c:595
int coap_split_query(const uint8_t *s, size_t length, unsigned char *buf, size_t *buflen)
Splits the given URI query into segments.
Definition coap_uri.c:607
int coap_split_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri)
Parses a given string into URI components.
Definition coap_uri.c:269
int coap_split_proxy_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri)
Parses a given string into URI components.
Definition coap_uri.c:274
int coap_uri_into_options(const coap_uri_t *uri, const coap_address_t *dst, coap_optlist_t **optlist_chain, int create_port_host_opt, uint8_t *_buf, size_t _buflen)
Takes a coap_uri_t and then adds CoAP options into the optlist_chain.
Definition coap_uri.c:279
coap_string_t * coap_get_query(const coap_pdu_t *request)
Extract query string from request PDU according to escape rules in 6.5.8.
Definition coap_uri.c:713
coap_uri_info_t coap_uri_scheme[COAP_URI_SCHEME_LAST]
Definition coap_uri.c:51
int coap_ws_is_supported(void)
Check whether WebSockets is available.
Definition coap_ws.c:929
int coap_wss_is_supported(void)
Check whether Secure WebSockets is available.
Definition coap_ws.c:934
#define COAP_STATIC_INLINE
Definition libcoap.h:53
int n
Definition coap_uri.c:576
coap_string_t buf
Definition coap_uri.c:575
Multi-purpose address abstraction.
Iterator to run through PDU options.
Representation of chained list of CoAP options to install.
structure for CoAP PDUs
CoAP string data definition with const data.
Definition coap_str.h:46
const uint8_t * s
read-only string data
Definition coap_str.h:48
size_t length
length of string
Definition coap_str.h:47
CoAP string data definition.
Definition coap_str.h:38
uint8_t * s
string data
Definition coap_str.h:40
size_t length
length of string
Definition coap_str.h:39
coap_uri_scheme_t scheme
scheme
uint16_t port
default scheme port
Representation of parsed URI.
Definition coap_uri.h:65
enum coap_uri_scheme_t scheme
The parsed scheme specifier.
Definition coap_uri.h:75
coap_str_const_t path
The complete path if present or {0, NULL}.
Definition coap_uri.h:68
uint16_t port
The port in host byte order.
Definition coap_uri.h:67
coap_str_const_t query
The complete query if present or {0, NULL}.
Definition coap_uri.h:71
coap_str_const_t host
The host part of the URI.
Definition coap_uri.h:66