11 #if defined(HAVE_ASSERT_H) && !defined(assert)
36 static inline unsigned char *
37 strnchr(
unsigned char *s,
size_t len,
unsigned char c) {
38 while (len && *s++ != c)
41 return len ? s : NULL;
47 int secure = 0, res = 0;
63 while (len && *q && tolower(*p) == *q) {
75 if (len && (secure = tolower(*p) ==
's')) {
79 q = (
unsigned char *)
"://";
80 while (len && *q && tolower(*p) == *q) {
91 if (len && *p ==
'[') {
94 while (len && *q !=
']') {
98 if (!len || *q !=
']' || p == q) {
106 while (len && *q !=
':' && *q !=
'/' && *q !=
'?') {
121 if (len && *q ==
':') {
125 while (len && isdigit(*q)) {
134 uri_port = uri_port * 10 + (*p++ -
'0');
136 uri->
port = uri_port;
149 while (len && *q !=
'?') {
161 if (len && *p ==
'?') {
182 #define hexchar_to_dec(c) ((c) & 0x40 ? ((c) & 0x0F) + 9 : ((c) & 0x0F))
204 seg += 2; length -= 2;
225 if (length < 2 || !(isxdigit(s[1]) && isxdigit(s[2])))
259 unsigned char *buf,
size_t buflen) {
264 debug(
"make_decoded_option(): buflen is 0!\n");
275 assert(written <= buflen);
283 if (buflen < (
size_t)res) {
284 debug(
"buffer too small for option\n");
290 return written + res;
295 #define min(a,b) ((a) < (b) ? (a) : (b))
319 length = parse_iter->
n;
342 if (memcmp(s,
"..",
min(len,2)) == 0)
355 unsigned char *
buf,
size_t *buflen) {
356 struct cnt_str tmp = { { *buflen, buf }, 0 };
360 '/', (
unsigned char *)
"?#", 2, &pi);
369 unsigned char *
buf,
size_t *buflen) {
370 struct cnt_str tmp = { { *buflen, buf }, 0 };
374 '&', (
unsigned char *)
"#", 1, &pi);
382 #define URI_DATA(uriobj) ((unsigned char *)(uriobj) + sizeof(coap_uri_t))
386 unsigned char *result;
393 memcpy(
URI_DATA(result), uri, length);
463 '/', (
unsigned char *)
"?#", 2, &pi);
473 unsigned char separator,
474 unsigned char *delim,
size_t dlen,
Representation of parsed URI.
int coap_split_uri(unsigned char *str_var, size_t len, coap_uri_t *uri)
Parses a given string into URI components.
str query
The query part if present.
unsigned char coap_key_t[4]
void(* segment_handler_t)(unsigned char *, size_t, void *)
str host
host part of the URI
size_t segment_length
length of current segment
size_t dlen
length of separator
str path
Beginning of the first path segment.
#define coap_malloc(size)
helpers for handling options in CoAP PDUs
unsigned short port
The port in host byte order.
Iterator to for tokenizing a URI path or query.
unsigned char * coap_parse_next(coap_parse_iterator_t *pi)
Updates the iterator pi to point to the next token.
#define COAP_SET_STR(st, l, v)
void write_option(unsigned char *s, size_t len, void *data)
static unsigned char * strnchr(unsigned char *s, size_t len, unsigned char c)
A length-safe version of strchr().
static void hash_segment(unsigned char *s, size_t len, void *data)
size_t n
number of remaining characters in buffer
coap_uri_t * coap_new_uri(const unsigned char *uri, unsigned int length)
Creates a new coap_uri_t object from the specified URI.
unsigned char separator
segment separators
int coap_split_path(const unsigned char *s, size_t length, unsigned char *buf, size_t *buflen)
Splits the given URI path into segments.
int make_decoded_option(const unsigned char *s, size_t length, unsigned char *buf, size_t buflen)
Writes a coap option from given string s to buf.
void decode_segment(const unsigned char *seg, size_t length, unsigned char *buf)
Decodes percent-encoded characters while copying the string seg of size length to buf...
#define coap_hash(String, Length, Result)
#define COAP_DEFAULT_SCHEME
coap_parse_iterator_t * coap_parse_iterator_init(unsigned char *s, size_t n, unsigned char separator, unsigned char *delim, size_t dlen, coap_parse_iterator_t *pi)
Initializes the given iterator pi.
#define COAP_DEFAULT_PORT
unsigned char * delim
delimiters where to split the string
int coap_hash_path(const unsigned char *path, size_t len, coap_key_t key)
Calculates a hash over the given path and stores the result in key.
coap_uri_t * coap_clone_uri(const coap_uri_t *uri)
Clones the specified coap_uri_t object.
int coap_split_query(const unsigned char *s, size_t length, unsigned char *buf, size_t *buflen)
Splits the given URI query into segments.
size_t coap_opt_setheader(coap_opt_t *opt, size_t maxlen, unsigned short delta, size_t length)
Encodes the given delta and length values into opt.
size_t coap_split_path_impl(coap_parse_iterator_t *parse_iter, segment_handler_t h, void *data)
Splits the given string into segments.
int check_segment(const unsigned char *s, size_t length)
Runs through the given path (or query) segment and checks if percent-encodings are correct...
#define hexchar_to_dec(c)
Calculates decimal value from hexadecimal ASCII character given in c.
unsigned char * pos
current position in buffer