18#if defined(HAVE_LIMITS_H) 
   28#define strcasecmp _stricmp 
   29#define strncasecmp _strnicmp 
   44strnchr(
const uint8_t *s, 
size_t len, 
unsigned char c) {
 
   45  while (len && *s++ != c)
 
   48  return len ? s : NULL;
 
 
   84  int is_unix_domain = 0;
 
   86  if (!str_var || !uri || len == 0)
 
  105  while (len >= 3 && !(p[0] == 
':' && p[1] == 
'/' && p[2] == 
'/')) {
 
  118        coap_log_err(
"%.*s URI scheme not enabled (not a proxy)\n",
 
  119                     (
int)(p - str_var), str_var);
 
  129    coap_log_err(
"%.*s URI scheme unknown\n", (
int)(p - str_var), str_var);
 
  138      coap_log_err(
"coaps URI scheme not supported in this version of libcoap\n");
 
  144      coap_log_err(
"coap+tcp URI scheme not supported in this version of libcoap\n");
 
  150      coap_log_err(
"coaps+tcp URI scheme not supported in this version of libcoap\n");
 
  156      coap_log_err(
"coap+ws URI scheme not supported in this version of libcoap\n");
 
  162      coap_log_err(
"coaps+ws URI scheme not supported in this version of libcoap\n");
 
  181  if (len && *p == 
'[') {
 
  187    while (len && *q != 
']') {
 
  192    if (!len || *q != 
']' || p == q) {
 
  202    if (len >= 3 && p[0] == 
'%' && p[1] == 
'2' &&
 
  203        (p[2] == 
'F' || p[2] == 
'f')) {
 
  208    while (len && *q != 
':' && *q != 
'/' && *q != 
'?') {
 
  218    if ((
int)(q - p) > 255) {
 
  219      coap_log_warn(
"Host name length too long (%d > 255)\n", (
int)(q - p));
 
  228  if (len && *q == 
':') {
 
  229    if (is_unix_domain) {
 
  236    while (len && isdigit(*q)) {
 
  244      while ((p < q) && (uri_port <= UINT16_MAX))
 
  245        uri_port = uri_port * 10 + (*p++ - 
'0');
 
  248      if (uri_port > UINT16_MAX) {
 
  249        coap_log_warn(
"Port number too big (%ld > 65535)\n", uri_port);
 
  254      uri->
port = (uint16_t)uri_port;
 
  267    while (len && *q != 
'?') {
 
  279  if (len && *p == 
'?') {
 
 
  307  for (i = 0; i < optlist->
length; i++) {
 
  308    if (optlist->
data[i] >= 
'A' && optlist->
data[i] <= 
'Z') {
 
  309      optlist->
data[i] += 
'a' - 
'A';
 
 
  328#if !defined(WITH_LWIP) && !defined(WITH_CONTIKI) 
  337      const uint8_t *cp = uri->
host.
s;
 
  340      for (
size_t i = 0; i < uri_host_len; i++) {
 
  349          (strlen(addr) != uri_host_len ||
 
  350           strncasecmp(addr, (
const char *)uri->
host.
s, uri_host_len) != 0)) {
 
  364    switch ((
int)uri->
scheme) {
 
  372      if (uri->
port != 443)
 
  387                                                                (uri->
port & 0xffff)),
 
 
  408  if (host->
length >= 3 && host->
s[0] == 
'%' &&
 
  410      (host->
s[2] == 
'F' || host->
s[2] == 
'f')) {
 
  413  if (host->
length >= 1 && host->
s[0] == 
'/')
 
 
  425#define hexchar_to_dec(c) ((c) & 0x40 ? ((c) & 0x0F) + 9 : ((c) & 0x0F)) 
  469      if (length < 2 || !(isxdigit(s[1]) && isxdigit(s[2])))
 
 
  508                    unsigned char *buf, 
size_t buflen, 
size_t *optionsize) {
 
  525  assert(written <= buflen);
 
  533  if (buflen < segmentlen) {
 
  540  *optionsize = written + segmentlen;
 
 
  547#define min(a,b) ((a) < (b) ? (a) : (b)) 
  558dots(
const uint8_t *s, 
size_t len) {
 
  567  if (p == 
'%' && len >=3) {
 
  568    if (s[1] == 
'2' && (s[2] == 
'E' || s[2] == 
'e')) {
 
  584  if (p == 
'%' && len >=3) {
 
  585    if (s[1] == 
'2' && (s[2] == 
'E' || s[2] == 
'e')) {
 
 
  615  for (i = 0; i < state->
n; i++) {
 
 
  636  const uint8_t *p, *q;
 
  641  while (length > 0 && !
strnchr((
const uint8_t *)
"?#", 2, *q)) {
 
  644      num_dots = 
dots(p, q - p);
 
  668  num_dots = 
dots(p, q - p);
 
 
  696    state->
buf.
s += optionsize;
 
 
  704                unsigned char *
buf, 
size_t *buflen) {
 
  705  struct cnt_str tmp = { { *buflen, 
buf }, { *buflen, 
buf }, 0 };
 
 
  719  for (i = 0; i < optlist->
length; i++) {
 
  720    if (optlist->
data[i] == 
'%' && optlist->
length - i >= 3) {
 
  725      optlist->
data[o] = optlist->
data[i];
 
 
  750    *optlist_begin = NULL;
 
 
  757  const uint8_t *p = s;
 
  762  if (*optlist_chain) {
 
  764    optlist_start = &((*optlist_chain)->next);
 
  766    optlist_start = optlist_chain;
 
  769  while (length > 0 && !
strnchr((
const uint8_t *)
"?#", 2, *s)) {
 
  772      num_dots = 
dots(p, s - p);
 
  798  num_dots = 
dots(p, s - p);
 
 
  822                 unsigned char *
buf, 
size_t *buflen) {
 
  823  struct cnt_str tmp = { { *buflen, 
buf }, { *buflen, 
buf }, 0 };
 
  827  while (length > 0 && *s != 
'#') {
 
 
  847  const uint8_t *p = s;
 
  850  while (length > 0 && *s != 
'#') {
 
 
  872#define URI_DATA(uriobj) ((unsigned char *)(uriobj) + sizeof(coap_uri_t)) 
  884  result = (uint8_t *)out_uri;
 
  885  memcpy(
URI_DATA(result), uri, length);
 
 
  944  return (c >= 
'A' && c <= 
'Z') || (c >= 
'a' && c <= 
'z') ||
 
  945         (c >= 
'0' && c <= 
'9') || c == 
'-' || c == 
'.' || c == 
'_' ||
 
  946         c == 
'~' || c == 
'!' || c == 
'$' || c == 
'\'' || c == 
'(' ||
 
  947         c == 
')' || c == 
'*' || c == 
'+' || c == 
',' || c == 
';' ||
 
  948         c==
'=' || c==
':' || c==
'@' || c == 
'&';
 
 
  963  static const uint8_t hex[] = 
"0123456789ABCDEF";
 
  971    for (i = 0; i < seg_len; i++) {
 
  985      unsigned char *s = query->
s;
 
  992        for (i = 0; i < seg_len; i++) {
 
  997            *s++ = hex[seg[i]>>4];
 
  998            *s++ = hex[seg[i]&0x0F];
 
 
 1014  static const uint8_t hex[] = 
"0123456789ABCDEF";
 
 1037    for (i = 0; i < seg_len; i++) {
 
 1053    uri_path->
length = length;
 
 1054    unsigned char *s = uri_path->
s;
 
 1063      for (i = 0; i < seg_len; i++) {
 
 1068          *s++ = hex[seg[i]>>4];
 
 1069          *s++ = hex[seg[i]&0x0F];
 
 
Library specific build wrapper for coap_internal.h.
 
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.
 
uint16_t coap_option_num_t
 
uint8_t coap_opt_t
Use byte-oriented access methods here because sliding a complex struct coap_opt_t over the data buffe...
 
static void coap_replace_upper_lower(coap_optlist_t *optlist)
 
static int dots(const uint8_t *s, size_t len)
Checks if path segment s consists of one or two dots.
 
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 COAP_UNUSED, size_t buflen COAP_UNUSED)
 
static void backup_optlist(coap_optlist_t **optlist_begin)
 
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.
 
static int is_unescaped_in_query(const uint8_t c)
 
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)
 
static void backup_segment(void *data)
 
void coap_delete_uri(coap_uri_t *uri)
Removes the specified coap_uri_t object.
 
static size_t coap_split_path_impl(const uint8_t *path, size_t len, segment_handler_t h, void *data)
Splits the given string into segments.
 
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.
 
static int is_unescaped_in_path(const uint8_t c)
 
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.
 
int coap_host_is_unix_domain(const coap_str_const_t *host)
Determines from the host whether this is a Unix Domain socket request.
 
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_WS
 
@ COAP_URI_SCHEME_COAPS_TCP
 
@ COAP_URI_SCHEME_COAP_TCP
 
@ COAP_URI_SCHEME_COAP_WS
 
unsigned int coap_encode_var_safe(uint8_t *buf, size_t length, unsigned int val)
Encodes multiple-length byte sequences.
 
#define coap_log_debug(...)
 
const char * coap_print_ip_addr(const coap_address_t *addr, char *buf, size_t len)
Print the IP address into the defined buffer.
 
#define coap_log_warn(...)
 
#define coap_log_err(...)
 
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_delete_optlist(coap_optlist_t *queue)
Removes all entries from the optlist_chain, freeing off their memory usage.
 
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
 
#define COAP_DEFAULT_PORT
 
#define COAP_OPTION_URI_QUERY
 
#define COAP_OPTION_URI_PATH
 
#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.
 
int coap_tcp_is_supported(void)
Check whether TCP is available.
 
int coap_tls_is_supported(void)
Check whether TLS is available.
 
int coap_ws_is_supported(void)
Check whether WebSockets is available.
 
int coap_dtls_is_supported(void)
Check whether DTLS is available.
 
int coap_wss_is_supported(void)
Check whether Secure WebSockets is available.
 
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_query_into_optlist(const uint8_t *s, size_t length, coap_option_num_t optnum, coap_optlist_t **optlist_chain)
Splits the given URI query into '&' separate segments, and then adds the Uri-Query / Location-Query o...
 
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_path_into_optlist(const uint8_t *s, size_t length, coap_option_num_t optnum, coap_optlist_t **optlist_chain)
Splits the given URI path into '/' separate segments, and then adds the Uri-Path / Location-Path opti...
 
int coap_split_proxy_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri)
Parses a given string into URI components.
 
int coap_uri_into_optlist(const coap_uri_t *uri, const coap_address_t *dst, coap_optlist_t **optlist_chain, int create_port_host_opt)
Takes a coap_uri_t and then adds CoAP options into the optlist_chain.
 
int coap_split_query(const uint8_t *s, size_t length, unsigned char *buf, size_t *buflen)
Splits the given URI query into segments.
 
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.
 
coap_uri_info_t coap_uri_scheme[COAP_URI_SCHEME_LAST]
 
void coap_replace_percents(coap_optlist_t *optlist)
replace any % hex definitions with the actual character.
 
#define COAP_STATIC_INLINE
 
Multi-purpose address abstraction.
 
Iterator to run through PDU options.
 
Representation of chained list of CoAP options to install.
 
size_t length
the option value length
 
uint8_t * data
the option data
 
struct coap_optlist_t * next
next entry in the optlist chain
 
CoAP string data definition with const data.
 
const uint8_t * s
read-only string data
 
size_t length
length of string
 
CoAP string data definition.
 
size_t length
length of string
 
coap_uri_scheme_t scheme
scheme
 
uint16_t port
default scheme port
 
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.