18#if defined(HAVE_LIMITS_H)
39strnchr(
const uint8_t *s,
size_t len,
unsigned char c) {
40 while (len && *s++ != c)
43 return len ? s : NULL;
46#define ISEQUAL_CI(a,b) \
47 ((a) == (b) || (islower(b) && ((a) == ((b) - 0x20))))
61 int is_http_proxy_scheme = 0;
62 size_t keep_len = len;
64 if (!str_var || !uri || len == 0)
87 q = (
const uint8_t *)
"http";
109 is_http_proxy_scheme = 1;
119 if (is_http_proxy_scheme == 0) {
121 if (len && (*p ==
's')) {
130 if (len>=4 && p[0] ==
'+' && p[1] ==
't' && p[2] ==
'c' && p[3] ==
'p' ) {
139 q = (
const uint8_t *)
"://";
140 while (len && *q && *p == *q) {
151 if (len && *p ==
'[') {
154 while (len && *q !=
']') {
158 if (!len || *q !=
']' || p == q) {
166 while (len && *q !=
':' && *q !=
'/' && *q !=
'?') {
180 if (len && *q ==
':') {
184 while (len && isdigit(*q)) {
192 while ((p < q) && (uri_port <= UINT16_MAX))
193 uri_port = uri_port * 10 + (*p++ -
'0');
196 if (uri_port > UINT16_MAX) {
201 uri->
port = (uint16_t)uri_port;
214 while (len && *q !=
'?') {
226 if (len && *p ==
'?') {
253 uint8_t *_buf,
size_t _buflen) {
255 unsigned char *buf = _buf;
256 size_t buflen = _buflen;
263 (uri->
port & 0xffff)),
269 coap_log_warn(
"URI path will be truncated (max buffer %zu)\n",
289 coap_log_warn(
"URI query will be truncated (max buffer %zu)\n",
314#define hexchar_to_dec(c) ((c) & 0x40 ? ((c) & 0x0F) + 9 : ((c) & 0x0F))
336 seg += 2; length -= 2;
356 if (length < 2 || !(isxdigit(s[1]) && isxdigit(s[2])))
393 unsigned char *buf,
size_t buflen,
size_t* optionsize) {
410 assert(written <= buflen);
418 if (buflen < segmentlen) {
425 *optionsize = written + segmentlen;
432#define min(a,b) ((a) < (b) ? (a) : (b))
441dots(
const uint8_t *s,
size_t len) {
442 return len && *s ==
'.' && (len == 1 || (len == 2 && *(s+1) ==
'.'));
460 const uint8_t *p, *q;
463 while (length > 0 && !
strnchr((
const uint8_t *)
"?#", 2, *q)) {
466 if (!
dots(p, q - p)) {
478 if (!
dots(p, q - p)) {
499 state->
buf.
s += optionsize;
507 unsigned char *
buf,
size_t *buflen) {
519 unsigned char *
buf,
size_t *buflen) {
524 while (length > 0 && *s !=
'#') {
541#define URI_DATA(uriobj) ((unsigned char *)(uriobj) + sizeof(coap_uri_t))
545 unsigned char *result;
552 memcpy(
URI_DATA(result), uri, length);
611 return ( c >=
'A' && c <=
'Z' ) || ( c >=
'a' && c <=
'z' )
612 || ( c >=
'0' && c <=
'9' ) || c ==
'-' || c ==
'.' || c ==
'_'
613 || c ==
'~' || c ==
'!' || c ==
'$' || c ==
'\'' || c ==
'('
614 || c ==
')' || c ==
'*' || c ==
'+' || c ==
',' || c ==
';' || c==
'='
615 || c==
':' || c==
'@' || c ==
'&';
629 static const uint8_t hex[] =
"0123456789ABCDEF";
637 for (i = 0; i < seg_len; i++) {
651 unsigned char *s = query->
s;
658 for (i = 0; i < seg_len; i++) {
663 *s++ = hex[seg[i]>>4];
664 *s++ = hex[seg[i]&0x0F];
679 static const uint8_t hex[] =
"0123456789ABCDEF";
702 for (i = 0; i < seg_len; i++) {
718 uri_path->
length = length;
719 unsigned char *s = uri_path->
s;
728 for (i = 0; i < seg_len; i++) {
733 *s++ = hex[seg[i]>>4];
734 *s++ = hex[seg[i]&0x0F];
Pulls together all the internal only header files.
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...
unsigned int coap_encode_var_safe(uint8_t *buf, size_t length, unsigned int val)
Encodes multiple-length byte sequences.
#define coap_log_debug(...)
#define coap_log_warn(...)
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_DEFAULT_PORT
#define COAP_OPTION_URI_QUERY
#define COAP_OPTION_URI_PATH
#define COAP_DEFAULT_SCHEME
#define COAPS_DEFAULT_PORT
#define COAP_OPTION_URI_PORT
#define COAP_OPTION_PROXY_URI
#define COAP_SET_STR(st, l, v)
coap_string_t * coap_new_string(size_t size)
Returns a new string object with at least size+1 bytes storage allocated.
coap_string_t * coap_get_uri_path(const coap_pdu_t *request)
Extract uri_path string from request PDU.
int coap_split_path(const uint8_t *s, size_t length, unsigned char *buf, size_t *buflen)
Splits the given URI path into segments.
int coap_split_query(const uint8_t *s, size_t length, unsigned char *buf, size_t *buflen)
Splits the given URI query into segments.
int coap_uri_into_options(coap_uri_t *uri, coap_optlist_t **optlist_chain, int create_port_opt, uint8_t *_buf, size_t _buflen)
Takes a coap_uri_t and then adds CoAP options into the optlist_chain.
int coap_split_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri)
Parses a given string into URI components.
int coap_split_proxy_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri)
Parses a given string into URI components.
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.
#define COAP_STATIC_INLINE
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().
Iterator to run through PDU options.
Representation of chained list of CoAP options to install.
const uint8_t * s
read-only string data
size_t length
length of string
CoAP string data definition.
size_t length
length of string
Representation of parsed URI.
enum coap_uri_scheme_t scheme
The parsed scheme specifier.
coap_str_const_t path
The complete path if present or {0, NULL}.
uint16_t port
The port in host byte order.
coap_str_const_t query
The complete query if present or {0, NULL}.
coap_str_const_t host
The host part of the URI.
COAP_STATIC_INLINE int is_unescaped_in_path(const uint8_t c)
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.
COAP_STATIC_INLINE int is_unescaped_in_query(const uint8_t c)
COAP_STATIC_INLINE int dots(const uint8_t *s, size_t len)
Checks if path segment s consists of one or two dots.
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.
COAP_STATIC_INLINE const uint8_t * strnchr(const uint8_t *s, size_t len, unsigned char c)
A length-safe version of strchr().
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.
static void write_option(const uint8_t *s, size_t len, void *data)
void coap_delete_uri(coap_uri_t *uri)
Removes the specified coap_uri_t object.
static int coap_split_uri_sub(const uint8_t *str_var, size_t len, coap_uri_t *uri, coap_uri_check_t check_proxy)
#define hexchar_to_dec(c)
Calculates decimal value from hexadecimal ASCII character given in c.
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.
coap_uri_t * coap_clone_uri(const coap_uri_t *uri)
Clones the specified coap_uri_t object.
coap_uri_t * coap_new_uri(const uint8_t *uri, unsigned int length)
Creates a new coap_uri_t object from the specified URI.
void(* segment_handler_t)(const uint8_t *, size_t, void *)
static int coap_uri_scheme_is_secure(const coap_uri_t *uri)
@ COAP_URI_SCHEME_COAPS_TCP
@ COAP_URI_SCHEME_COAP_TCP