9 #include "coap_config.h" 11 #if defined(HAVE_ASSERT_H) && !defined(assert) 15 #if defined(HAVE_LIMITS_H) 43 while (len && *s++ != c)
46 return len ? s : NULL;
49 #define ISEQUAL_CI(a,b) \ 50 ((a) == (b) || (islower(b) && ((a) == ((b) - 0x20)))) 83 if (len && (*p ==
's')) {
92 if (len>=4 && p[0] ==
'+' && p[1] ==
't' && p[2] ==
'c' && p[3] ==
'p' ) {
101 while (len && *q && *p == *q) {
112 if (len && *p ==
'[') {
115 while (len && *q !=
']') {
119 if (!len || *q !=
']' || p == q) {
127 while (len && *q !=
':' && *q !=
'/' && *q !=
'?') {
141 if (len && *q ==
':') {
145 while (len && isdigit(*q)) {
154 uri_port = uri_port * 10 + (*p++ -
'0');
157 if (uri_port > 65535) {
162 uri->
port = (uint16_t)uri_port;
175 while (len && *q !=
'?') {
187 if (len && *p ==
'?') {
208 #define hexchar_to_dec(c) ((c) & 0x40 ? ((c) & 0x0F) + 9 : ((c) & 0x0F)) 230 seg += 2; length -= 2;
250 if (length < 2 || !(isxdigit(s[1]) && isxdigit(s[2])))
287 unsigned char *buf,
size_t buflen,
size_t* optionsize) {
304 assert(written <= buflen);
312 if (buflen < segmentlen) {
319 *optionsize = written + segmentlen;
326 #define min(a,b) ((a) < (b) ? (a) : (b)) 336 return len && *s ==
'.' && (len == 1 || (len == 2 && *(s+1) ==
'.'));
360 if (!
dots(p, q - p)) {
372 if (!
dots(p, q - p)) {
393 state->
buf.
s += optionsize;
401 unsigned char *
buf,
size_t *buflen) {
402 struct cnt_str tmp = { { *buflen, buf }, 0 };
413 unsigned char *
buf,
size_t *buflen) {
414 struct cnt_str tmp = { { *buflen, buf }, 0 };
418 while (length > 0 && *s !=
'#') {
435 #define URI_DATA(uriobj) ((unsigned char *)(uriobj) + sizeof(coap_uri_t)) 439 unsigned char *result;
446 memcpy(
URI_DATA(result), uri, length);
500 return ( c >=
'A' && c <=
'Z' ) || ( c >=
'a' && c <=
'z' )
501 || ( c >=
'0' && c <=
'9' ) || c ==
'-' || c ==
'.' || c ==
'_' 502 || c ==
'~' || c ==
'!' || c ==
'$' || c ==
'\'' || c ==
'(' 503 || c ==
')' || c ==
'*' || c ==
'+' || c ==
',' || c ==
';' || c==
'=' 504 || c==
':' || c==
'@' || c ==
'&';
518 static const uint8_t hex[] =
"0123456789ABCDEF";
526 for (i = 0; i < seg_len; i++) {
540 unsigned char *s = query->
s;
547 for (i = 0; i < seg_len; i++) {
552 *s++ = hex[seg[i]>>4];
553 *s++ = hex[seg[i]&0x0F];
568 static const uint8_t hex[] =
"0123456789ABCDEF";
576 for (i = 0; i < seg_len; i++) {
592 uri_path->
length = length;
593 unsigned char *s = uri_path->
s;
602 for (i = 0; i < seg_len; i++) {
607 *s++ = hex[seg[i]>>4];
608 *s++ = hex[seg[i]&0x0F];
Representation of parsed URI.
uint8_t coap_opt_t
Use byte-oriented access methods here because sliding a complex struct coap_opt_t over the data buffe...
int coap_split_query(const uint8_t *s, size_t length, unsigned char *buf, size_t *buflen)
Splits the given URI query into segments.
static void write_option(const uint8_t *s, size_t len, void *data)
coap_string_t * coap_get_query(const coap_pdu_t *request)
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.
int coap_option_filter_set(coap_opt_filter_t filter, uint16_t type)
Sets the corresponding entry for type in filter.
coap_str_const_t host
host part of the URI
coap_opt_t * coap_option_next(coap_opt_iterator_t *oi)
Updates the iterator oi to point to the next option.
Helpers for handling options in CoAP PDUs.
size_t length
length of string
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...
void(* segment_handler_t)(const uint8_t *, size_t, void *)
COAP_STATIC_INLINE void * coap_malloc(size_t size)
Wrapper function to coap_malloc_type() for backwards compatibility.
Coap string data definition.
int coap_split_path(const uint8_t *s, size_t length, unsigned char *buf, size_t *buflen)
Splits the given URI path into segments.
coap_string_t * coap_new_string(size_t size)
Returns a new string object with at least size+1 bytes storage allocated.
structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload mark...
uint16_t coap_opt_length(const coap_opt_t *opt)
Returns the length of the given option.
enum coap_uri_scheme_t scheme
The parsed scheme specifier.
coap_string_t * coap_get_uri_path(const coap_pdu_t *request)
#define COAPS_DEFAULT_PORT
Iterator to run through PDU options.
COAP_STATIC_INLINE void coap_free(void *object)
Wrapper function to coap_free_type() for backwards compatibility.
COAP_STATIC_INLINE int dots(const uint8_t *s, size_t len)
Checks if path segment s consists of one or two dots.
#define COAP_DEFAULT_SCHEME
COAP_STATIC_INLINE void coap_option_filter_clear(coap_opt_filter_t f)
Clears filter f.
uint16_t port
The port in host byte order.
#define COAP_STATIC_INLINE
#define COAP_DEFAULT_PORT
Pre-defined constants that reflect defaults for CoAP.
size_t length
length of string
COAP_STATIC_INLINE int is_unescaped_in_path(const uint8_t c)
uint16_t coap_opt_filter_t[COAP_OPT_FILTER_SIZE]
Fixed-size vector we use for option filtering.
coap_uri_t * coap_new_uri(const uint8_t *uri, unsigned int length)
Creates a new coap_uri_t object from the specified URI.
const uint8_t * s
string data
coap_uri_t * coap_clone_uri(const coap_uri_t *uri)
Clones the specified coap_uri_t object.
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.
const uint8_t * coap_opt_value(const coap_opt_t *opt)
Returns a pointer to the value of the given option.
coap_str_const_t query
The query part if present.
#define COAP_OPTION_URI_PATH
COAP_STATIC_INLINE int is_unescaped_in_query(const uint8_t c)
#define COAP_SET_STR(st, l, v)
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...
#define COAP_OPTION_URI_QUERY
#define coap_log(level,...)
Logging function.
int coap_split_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri)
Parses a given string into URI components.
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...
#define hexchar_to_dec(c)
Calculates decimal value from hexadecimal ASCII character given in c.
COAP_STATIC_INLINE const uint8_t * strnchr(const uint8_t *s, size_t len, unsigned char c)
A length-safe version of strchr().
coap_str_const_t path
Beginning of the first path segment.
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.