coap_get_log_level:
  103|    399|coap_get_log_level(void) {
  104|    399|  return maxlog;
  105|    399|}
coap_log_level_desc:
  124|    399|coap_log_level_desc(coap_log_t level) {
  125|    399|  static char bad[8];
  126|    399|  if (level >= sizeof(loglevels)/sizeof(loglevels[0])) {
  ------------------
  |  Branch (126:7): [True: 0, False: 399]
  ------------------
  127|      0|    snprintf(bad, sizeof(bad), "%4d", level);
  128|      0|    return bad;
  129|    399|  } else {
  130|    399|    return loglevels[level];
  131|    399|  }
  132|    399|}
coap_log_impl:
 1378|    399|coap_log_impl(coap_log_t level, const char *format, ...) {
 1379|       |
 1380|       |#if COAP_THREAD_SAFE
 1381|       |  coap_mutex_lock(&m_log_impl);
 1382|       |#endif /* COAP_THREAD_SAFE */
 1383|       |
 1384|    399|  if (log_handler) {
  ------------------
  |  Branch (1384:7): [True: 0, False: 399]
  ------------------
 1385|       |#if COAP_CONSTRAINED_STACK
 1386|       |    /* message can be protected by m_log_impl if needed */
 1387|       |    static char message[COAP_DEBUG_BUF_SIZE];
 1388|       |#else /* ! COAP_CONSTRAINED_STACK */
 1389|      0|    char message[COAP_DEBUG_BUF_SIZE];
 1390|      0|#endif /* ! COAP_CONSTRAINED_STACK */
 1391|      0|    va_list ap;
 1392|      0|    va_start(ap, format);
 1393|       |
 1394|       |#ifdef RIOT_VERSION
 1395|       |    flash_vsnprintf(message, sizeof(message), format, ap);
 1396|       |#else /* !RIOT_VERSION */
 1397|      0|    vsnprintf(message, sizeof(message), format, ap);
 1398|      0|#endif /* !RIOT_VERSION */
 1399|      0|    va_end(ap);
 1400|      0|    log_handler(level, message);
 1401|    399|  } else {
 1402|    399|    va_list ap;
 1403|    399|    FILE *log_fd;
 1404|       |
 1405|    399|    log_fd = level <= COAP_LOG_CRIT ? COAP_ERR_FD : COAP_DEBUG_FD;
  ------------------
  |  |   44|    399|#define COAP_ERR_FD stderr
  ------------------
                  log_fd = level <= COAP_LOG_CRIT ? COAP_ERR_FD : COAP_DEBUG_FD;
  ------------------
  |  |   37|    399|#define COAP_DEBUG_FD stdout
  ------------------
  |  Branch (1405:14): [True: 0, False: 399]
  ------------------
 1406|       |
 1407|    399|#ifndef RIOT_VERSION
 1408|    399|    char timebuf[32];
 1409|    399|    coap_tick_t now;
 1410|    399|    size_t len;
 1411|       |
 1412|    399|    coap_ticks(&now);
 1413|    399|    len = print_timestamp(timebuf,sizeof(timebuf), now);
 1414|    399|    if (len) {
  ------------------
  |  Branch (1414:9): [True: 399, False: 0]
  ------------------
 1415|    399|      fprintf(log_fd, "%.*s ", (int)len, timebuf);
 1416|    399|    }
 1417|    399|#endif /* ! RIOT_VERSION */
 1418|       |
 1419|       |#if COAP_THREAD_SAFE && COAP_THREAD_NUM_LOGGING
 1420|       |    if (thread_no == 0) {
 1421|       |      /*
 1422|       |       * All other call to coap_mutex_lock(&m_io_threads) immediately
 1423|       |       * by setting thread_no if 0. So deadlock should never occur.
 1424|       |       */
 1425|       |      coap_mutex_lock(&m_io_threads);
 1426|       |      thread_no = ++max_thread_no;
 1427|       |      coap_mutex_unlock(&m_io_threads);
 1428|       |    }
 1429|       |    fprintf(log_fd, "%2d ", thread_no);
 1430|       |#endif /* COAP_THREAD_SAFE && COAP_THREAD_NUM_LOGGING */
 1431|       |
 1432|    399|    fprintf(log_fd, "%s ", coap_log_level_desc(level));
 1433|       |
 1434|    399|    va_start(ap, format);
 1435|       |#ifdef RIOT_VERSION
 1436|       |    flash_vfprintf(log_fd, format, ap);
 1437|       |#else /* !RIOT_VERSION */
 1438|    399|    vfprintf(log_fd, format, ap);
 1439|    399|#endif /* !RIOT_VERSION */
 1440|    399|    va_end(ap);
 1441|    399|    fflush(log_fd);
 1442|    399|  }
 1443|       |
 1444|       |#if COAP_THREAD_SAFE
 1445|       |  coap_mutex_unlock(&m_log_impl);
 1446|       |#endif /* COAP_THREAD_SAFE */
 1447|    399|}
coap_debug.c:print_timestamp:
  144|    399|print_timestamp(char *s, size_t len, coap_tick_t t) {
  145|    399|  struct tm *tmp;
  146|    399|  size_t lensofar;
  147|    399|  time_t now = coap_ticks_to_rt(t);
  148|    399|  tmp = localtime(&now);
  149|    399|  lensofar = strftime(s, len, "%b %d %H:%M:%S", tmp);
  150|    399|  if (len > lensofar + 4) {
  ------------------
  |  Branch (150:7): [True: 399, False: 0]
  ------------------
  151|    399|    lensofar += snprintf(&s[lensofar], len-lensofar, ".%03u",
  152|    399|                         (unsigned int)((coap_ticks_to_rt_us(t) % 1000000)/1000));
  153|    399|  }
  154|    399|  return lensofar;
  155|    399|}

coap_dtls_is_supported:
  191|      1|coap_dtls_is_supported(void) {
  192|      1|  if (SSLeay() < 0x10100000L) {
  ------------------
  |  Branch (192:7): [True: 0, False: 1]
  ------------------
  193|      0|    coap_log_warn("OpenSSL version 1.1.0 or later is required\n");
  ------------------
  |  |  108|      0|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  194|      0|    return 0;
  195|      0|  }
  196|      1|#if OPENSSL_VERSION_NUMBER >= 0x10101000L
  197|       |  /*
  198|       |   * For 1.1.1, we need to use SSL_CTX_set_client_hello_cb()
  199|       |   * which is not in 1.1.0 instead of SSL_CTX_set_tlsext_servername_callback()
  200|       |   *
  201|       |   * However, there could be a runtime undefined external reference error
  202|       |   * as SSL_CTX_set_client_hello_cb() is not there in 1.1.0.
  203|       |   */
  204|      1|  if (SSLeay() < 0x10101000L) {
  ------------------
  |  Branch (204:7): [True: 0, False: 1]
  ------------------
  205|      0|    coap_log_warn("OpenSSL version 1.1.1 or later is required\n");
  ------------------
  |  |  108|      0|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  206|      0|    return 0;
  207|      0|  }
  208|      1|#endif /* OPENSSL_VERSION_NUMBER >= 0x10101000L */
  209|      1|  return 1;
  210|      1|}
coap_tls_is_supported:
  213|      2|coap_tls_is_supported(void) {
  214|      2|#if !COAP_DISABLE_TCP
  215|      2|  if (SSLeay() < 0x10100000L) {
  ------------------
  |  Branch (215:7): [True: 0, False: 2]
  ------------------
  216|      0|    coap_log_warn("OpenSSL version 1.1.0 or later is required\n");
  ------------------
  |  |  108|      0|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  217|      0|    return 0;
  218|      0|  }
  219|      2|#if OPENSSL_VERSION_NUMBER >= 0x10101000L
  220|      2|  if (SSLeay() < 0x10101000L) {
  ------------------
  |  Branch (220:7): [True: 0, False: 2]
  ------------------
  221|      0|    coap_log_warn("OpenSSL version 1.1.1 or later is required\n");
  ------------------
  |  |  108|      0|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  222|      0|    return 0;
  223|      0|  }
  224|      2|#endif /* OPENSSL_VERSION_NUMBER >= 0x10101000L */
  225|      2|  return 1;
  226|       |#else /* COAP_DISABLE_TCP */
  227|       |  return 0;
  228|       |#endif /* COAP_DISABLE_TCP */
  229|      2|}

coap_tcp_is_supported:
   35|      2|coap_tcp_is_supported(void) {
   36|      2|  return !COAP_DISABLE_TCP;
  ------------------
  |  |   23|      2|#define COAP_DISABLE_TCP 0
  ------------------
   37|      2|}

coap_ticks:
   90|    399|coap_ticks(coap_tick_t *t) {
   91|    399|  coap_tick_t tmp;
   92|       |
   93|    399|#ifdef COAP_CLOCK
   94|    399|  struct timespec tv;
   95|    399|  clock_gettime(COAP_CLOCK, &tv);
  ------------------
  |  |   43|    399|#define COAP_CLOCK CLOCK_REALTIME
  ------------------
   96|       |  /* Possible errors are (see clock_gettime(2)):
   97|       |   *  EFAULT tp points outside the accessible address space.
   98|       |   *  EINVAL The clk_id specified is not supported on this system.
   99|       |   * Both cases should not be possible here.
  100|       |   */
  101|       |
  102|    399|  tmp = SHR_FP(tv.tv_nsec * Q(FRAC, (COAP_TICKS_PER_SECOND/1000000000.0)), FRAC);
  ------------------
  |  |   87|    399|#define SHR_FP(val,frac) (((coap_tick_t)((val) + (1 << ((frac) - 1)))) >> (frac))
  ------------------
  103|       |#else /* _POSIX_TIMERS */
  104|       |  /* Fall back to gettimeofday() */
  105|       |
  106|       |  struct timeval tv;
  107|       |  gettimeofday(&tv, NULL);
  108|       |  /* Possible errors are (see gettimeofday(2)):
  109|       |   *  EFAULT One of tv or tz pointed outside the accessible address space.
  110|       |   *  EINVAL Timezone (or something else) is invalid.
  111|       |   * Both cases should not be possible here.
  112|       |   */
  113|       |
  114|       |  tmp = SHR_FP(tv.tv_usec * Q(FRAC, (COAP_TICKS_PER_SECOND/1000000.0)), FRAC);
  115|       |#endif /* not _POSIX_TIMERS */
  116|       |
  117|       |  /* Finally, convert temporary FP representation to multiple of
  118|       |   * COAP_TICKS_PER_SECOND */
  119|    399|  *t = tmp + (tv.tv_sec - coap_clock_offset) * COAP_TICKS_PER_SECOND;
  ------------------
  |  |  164|    399|#define COAP_TICKS_PER_SECOND ((coap_tick_t)(1000U))
  ------------------
  120|    399|}
coap_ticks_to_rt:
  123|    399|coap_ticks_to_rt(coap_tick_t t) {
  124|    399|  return coap_clock_offset + (t / COAP_TICKS_PER_SECOND);
  ------------------
  |  |  164|    399|#define COAP_TICKS_PER_SECOND ((coap_tick_t)(1000U))
  ------------------
  125|    399|}
coap_ticks_to_rt_us:
  128|    399|coap_ticks_to_rt_us(coap_tick_t t) {
  129|    399|  return (uint64_t)coap_clock_offset * 1000000 + (uint64_t)t * 1000000 / COAP_TICKS_PER_SECOND;
  ------------------
  |  |  164|    399|#define COAP_TICKS_PER_SECOND ((coap_tick_t)(1000U))
  ------------------
  130|    399|}

coap_split_uri:
  351|    861|coap_split_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri) {
  352|    861|  return coap_split_uri_sub(str_var, len, uri, COAP_URI_CHECK_URI);
  353|    861|}
coap_uri.c:coap_split_uri_sub:
   84|    861|                   coap_uri_check_t check_proxy) {
   85|    861|  const uint8_t *p, *q;
   86|    861|  int res = 0;
   87|    861|  size_t i;
   88|    861|  int is_unix_domain = 0;
   89|    861|  int is_llc = 0;
   90|       |
   91|    861|  if (!str_var || !uri || len == 0)
  ------------------
  |  Branch (91:7): [True: 0, False: 861]
  |  Branch (91:19): [True: 0, False: 861]
  |  Branch (91:27): [True: 0, False: 861]
  ------------------
   92|      0|    return -1;
   93|       |
   94|    861|  memset(uri, 0, sizeof(coap_uri_t));
   95|    861|  uri->port = COAP_DEFAULT_PORT;
  ------------------
  |  |   39|    861|#define COAP_DEFAULT_PORT      5683 /* CoAP default UDP/TCP port */
  ------------------
   96|       |
   97|       |  /* search for scheme */
   98|    861|  p = str_var;
   99|    861|  if (*p == '/') {
  ------------------
  |  Branch (99:7): [True: 77, False: 784]
  ------------------
  100|       |    /* no scheme, host or port */
  101|     77|    if (check_proxy == COAP_URI_CHECK_PROXY) {
  ------------------
  |  Branch (101:9): [True: 0, False: 77]
  ------------------
  102|       |      /* Must have ongoing host if proxy definition */
  103|      0|      return -1;
  104|      0|    }
  105|     77|    q = p;
  106|     77|    goto path;
  107|     77|  }
  108|       |
  109|       |  /* find scheme terminating :// */
  110|  11.7M|  while (len >= 3 && !(p[0] == ':' && p[1] == '/' && p[2] == '/')) {
  ------------------
  |  Branch (110:10): [True: 11.7M, False: 69]
  |  Branch (110:24): [True: 4.06k, False: 11.7M]
  |  Branch (110:39): [True: 1.05k, False: 3.01k]
  |  Branch (110:54): [True: 715, False: 335]
  ------------------
  111|  11.7M|    ++p;
  112|  11.7M|    --len;
  113|  11.7M|  }
  114|    784|  if (len < 3) {
  ------------------
  |  Branch (114:7): [True: 69, False: 715]
  ------------------
  115|       |    /* scheme not defined with a :// terminator */
  116|     69|    res = -2;
  117|     69|    goto error;
  118|     69|  }
  119|  1.85k|  for (i = 0; i < COAP_URI_SCHEME_LAST; i++) {
  ------------------
  |  Branch (119:15): [True: 1.71k, False: 139]
  ------------------
  120|  1.71k|    if ((p - str_var) == (int)strlen(coap_uri_scheme[i].name) &&
  ------------------
  |  Branch (120:9): [True: 713, False: 998]
  ------------------
  121|    713|        strncasecmp((const char *)str_var, coap_uri_scheme[i].name, p - str_var) == 0) {
  ------------------
  |  Branch (121:9): [True: 576, False: 137]
  ------------------
  122|    576|      if (check_proxy != COAP_URI_CHECK_PROXY && coap_uri_scheme[i].proxy_only) {
  ------------------
  |  Branch (122:11): [True: 576, False: 0]
  |  Branch (122:50): [True: 1, False: 575]
  ------------------
  123|      1|        coap_log_err("%.*s URI scheme not enabled (not a proxy)\n",
  ------------------
  |  |  102|      1|#define coap_log_err(...) coap_log(COAP_LOG_ERR, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      1|#define coap_log(level, ...) do { \
  |  |  |  |  291|      1|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      1|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      1|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  124|      1|                     (int)(p - str_var), str_var);
  125|      1|        return -1;
  126|      1|      }
  127|    575|      uri->scheme = coap_uri_scheme[i].scheme;
  128|    575|      uri->port = coap_uri_scheme[i].port;
  129|    575|      break;
  130|    576|    }
  131|  1.71k|  }
  132|    714|  if (i == COAP_URI_SCHEME_LAST) {
  ------------------
  |  Branch (132:7): [True: 139, False: 575]
  ------------------
  133|       |    /* scheme unknown */
  134|    139|    coap_log_err("%.*s URI scheme unknown\n", (int)(p - str_var), str_var);
  ------------------
  |  |  102|    139|#define coap_log_err(...) coap_log(COAP_LOG_ERR, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|    139|#define coap_log(level, ...) do { \
  |  |  |  |  291|    139|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 139, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|    139|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|    139|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 139]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  135|    139|    res = -1;
  136|    139|    goto error;
  137|    139|  }
  138|    575|  switch (uri->scheme) {
  139|    570|  case COAP_URI_SCHEME_COAP:
  ------------------
  |  Branch (139:3): [True: 570, False: 5]
  ------------------
  140|    570|    break;
  141|      1|  case COAP_URI_SCHEME_COAPS:
  ------------------
  |  Branch (141:3): [True: 1, False: 574]
  ------------------
  142|      1|    if (!coap_dtls_is_supported()) {
  ------------------
  |  Branch (142:9): [True: 0, False: 1]
  ------------------
  143|      0|      coap_log_err("coaps URI scheme not supported in this version of libcoap\n");
  ------------------
  |  |  102|      0|#define coap_log_err(...) coap_log(COAP_LOG_ERR, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  144|      0|      return -1;
  145|      0|    }
  146|      1|    break;
  147|      1|  case COAP_URI_SCHEME_COAP_TCP:
  ------------------
  |  Branch (147:3): [True: 1, False: 574]
  ------------------
  148|      1|    if (!coap_tcp_is_supported()) {
  ------------------
  |  Branch (148:9): [True: 0, False: 1]
  ------------------
  149|      0|      coap_log_err("coap+tcp URI scheme not supported in this version of libcoap\n");
  ------------------
  |  |  102|      0|#define coap_log_err(...) coap_log(COAP_LOG_ERR, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  150|      0|      return -1;
  151|      0|    }
  152|      1|    break;
  153|      1|  case COAP_URI_SCHEME_COAPS_TCP:
  ------------------
  |  Branch (153:3): [True: 1, False: 574]
  ------------------
  154|      1|    if (!coap_tls_is_supported()) {
  ------------------
  |  Branch (154:9): [True: 0, False: 1]
  ------------------
  155|      0|      coap_log_err("coaps+tcp URI scheme not supported in this version of libcoap\n");
  ------------------
  |  |  102|      0|#define coap_log_err(...) coap_log(COAP_LOG_ERR, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  156|      0|      return -1;
  157|      0|    }
  158|      1|    break;
  159|      1|  case COAP_URI_SCHEME_COAP_WS:
  ------------------
  |  Branch (159:3): [True: 1, False: 574]
  ------------------
  160|      1|    if (!coap_ws_is_supported()) {
  ------------------
  |  Branch (160:9): [True: 0, False: 1]
  ------------------
  161|      0|      coap_log_err("coap+ws URI scheme not supported in this version of libcoap\n");
  ------------------
  |  |  102|      0|#define coap_log_err(...) coap_log(COAP_LOG_ERR, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  162|      0|      return -1;
  163|      0|    }
  164|      1|    break;
  165|      1|  case COAP_URI_SCHEME_COAPS_WS:
  ------------------
  |  Branch (165:3): [True: 1, False: 574]
  ------------------
  166|      1|    if (!coap_wss_is_supported()) {
  ------------------
  |  Branch (166:9): [True: 0, False: 1]
  ------------------
  167|      0|      coap_log_err("coaps+ws URI scheme not supported in this version of libcoap\n");
  ------------------
  |  |  102|      0|#define coap_log_err(...) coap_log(COAP_LOG_ERR, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  168|      0|      return -1;
  169|      0|    }
  170|      1|    break;
  171|      1|  case COAP_URI_SCHEME_HTTP:
  ------------------
  |  Branch (171:3): [True: 0, False: 575]
  ------------------
  172|      0|  case COAP_URI_SCHEME_HTTPS:
  ------------------
  |  Branch (172:3): [True: 0, False: 575]
  ------------------
  173|       |    /* Not proxy, caught above.  For proxy, assume app is doing CoAP <> HTTP mapping. */
  174|      0|    break;
  175|      0|  case COAP_URI_SCHEME_LAST:
  ------------------
  |  Branch (175:3): [True: 0, False: 575]
  ------------------
  176|      0|  default:
  ------------------
  |  Branch (176:3): [True: 0, False: 575]
  ------------------
  177|      0|    coap_log_warn("Unsupported URI type %d\n", uri->scheme);
  ------------------
  |  |  108|      0|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  178|      0|    return -1;
  179|    575|  }
  180|       |  /* skip :// */
  181|    575|  p += 3;
  182|    575|  len -= 3;
  183|       |
  184|       |  /* p points to beginning of Uri-Host */
  185|    575|  q = p;
  186|       |
  187|    575|  if (len && *p == '[') {
  ------------------
  |  Branch (187:7): [True: 569, False: 6]
  |  Branch (187:14): [True: 84, False: 485]
  ------------------
  188|       |    /* IPv6 address reference or Unix domain */
  189|     84|    ++p;
  190|     84|    ++q;
  191|     84|    --len;
  192|       |
  193|  6.33M|    while (len && *q != ']') {
  ------------------
  |  Branch (193:12): [True: 6.33M, False: 25]
  |  Branch (193:19): [True: 6.33M, False: 59]
  ------------------
  194|  6.33M|      ++q;
  195|  6.33M|      --len;
  196|  6.33M|    }
  197|       |
  198|     84|    if (!len || *q != ']' || p == q) {
  ------------------
  |  Branch (198:9): [True: 25, False: 59]
  |  Branch (198:17): [True: 0, False: 59]
  |  Branch (198:30): [True: 1, False: 58]
  ------------------
  199|     26|      res = -3;
  200|     26|      goto error;
  201|     26|    }
  202|       |
  203|     58|    if ((int)(q - p) > 255) {
  ------------------
  |  Branch (203:9): [True: 32, False: 26]
  ------------------
  204|     32|      coap_log_warn("Host name length too long (%d > 255)\n", (int)(q - p));
  ------------------
  |  |  108|     32|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     32|#define coap_log(level, ...) do { \
  |  |  |  |  291|     32|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 32, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|     32|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     32|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 32]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  205|     32|      res = -6;
  206|     32|      goto error;
  207|     32|    }
  208|       |
  209|     26|    COAP_SET_STR(&uri->host, q - p, p);
  ------------------
  |  |   52|     26|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  210|     26|    ++q;
  211|     26|    --len;
  212|     26|#if COAP_AF_LLC_SUPPORT
  213|    491|  } else if ((len >= LLC_HOST_LEN) && strncmp((const char *)p, "llc[", 4) == 0) {
  ------------------
  |  |  178|    491|#define LLC_HOST_LEN (4 + HW_ADDRSTRLEN + 4)
  |  |  ------------------
  |  |  |  |  176|    491|#define HW_ADDRSTRLEN 17
  |  |  ------------------
  ------------------
  |  Branch (213:14): [True: 334, False: 157]
  |  Branch (213:39): [True: 184, False: 150]
  ------------------
  214|    184|    unsigned long sap = 0;
  215|       |
  216|    184|    is_llc = 1;
  217|       |
  218|  1.50M|    while (len && *q != ']') {
  ------------------
  |  Branch (218:12): [True: 1.50M, False: 8]
  |  Branch (218:19): [True: 1.50M, False: 176]
  ------------------
  219|  1.50M|      ++q;
  220|  1.50M|      --len;
  221|  1.50M|    }
  222|       |
  223|    184|    if (!len || *q != ']' || p == q) {
  ------------------
  |  Branch (223:9): [True: 8, False: 176]
  |  Branch (223:17): [True: 0, False: 176]
  |  Branch (223:30): [True: 0, False: 176]
  ------------------
  224|      8|      res = -7;
  225|      8|      goto error;
  226|      8|    }
  227|       |
  228|    176|    ++q;
  229|    176|    --len;
  230|       |
  231|    176|    if (!len || *q != ':') {
  ------------------
  |  Branch (231:9): [True: 19, False: 157]
  |  Branch (231:17): [True: 14, False: 143]
  ------------------
  232|     33|      coap_log_warn("LLC SAP missing in URI\n");
  ------------------
  |  |  108|     33|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     33|#define coap_log(level, ...) do { \
  |  |  |  |  291|     33|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 33, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|     33|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     33|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 33]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  233|     33|      res = -7;
  234|     33|      goto error;
  235|     33|    }
  236|       |
  237|    143|    ++q;
  238|    143|    --len;
  239|       |
  240|  4.84k|    while (len && isxdigit(*q)) {
  ------------------
  |  Branch (240:12): [True: 4.81k, False: 28]
  |  Branch (240:19): [True: 4.69k, False: 115]
  ------------------
  241|  4.69k|      if (*q >= 'a' && *q <= 'f')
  ------------------
  |  Branch (241:11): [True: 1.75k, False: 2.94k]
  |  Branch (241:24): [True: 1.75k, False: 0]
  ------------------
  242|  1.75k|        sap = sap * 16 + (*q - 'a' + 10);
  243|  2.94k|      else if (*q >= 'A' && *q <= 'F')
  ------------------
  |  Branch (243:16): [True: 757, False: 2.19k]
  |  Branch (243:29): [True: 757, False: 0]
  ------------------
  244|    757|        sap = sap * 16 + (*q - 'A' + 10);
  245|       |
  246|  4.69k|      ++q;
  247|  4.69k|      --len;
  248|  4.69k|    }
  249|       |
  250|    143|    if (sap > UINT8_MAX) {
  ------------------
  |  Branch (250:9): [True: 108, False: 35]
  ------------------
  251|    108|      coap_log_warn("LLC SAP invalid (%lu > 255)\n", sap);
  ------------------
  |  |  108|    108|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|    108|#define coap_log(level, ...) do { \
  |  |  |  |  291|    108|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 108, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|    108|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|    108|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 108]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  252|    108|      res = -7;
  253|    108|      goto error;
  254|    108|    }
  255|       |
  256|     35|    COAP_SET_STR(&uri->host, q - p, p);
  ------------------
  |  |   52|     35|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  257|     35|#endif /* COAP_AF_LLC_SUPPORT */
  258|    307|  } else {
  259|       |    /* IPv4 address, FQDN or Unix domain socket */
  260|    307|    if (len >= 3 && p[0] == '%' && p[1] == '2' &&
  ------------------
  |  Branch (260:9): [True: 272, False: 35]
  |  Branch (260:21): [True: 45, False: 227]
  |  Branch (260:36): [True: 25, False: 20]
  ------------------
  261|     25|        (p[2] == 'F' || p[2] == 'f')) {
  ------------------
  |  Branch (261:10): [True: 2, False: 23]
  |  Branch (261:25): [True: 3, False: 20]
  ------------------
  262|       |      /* Unix domain definition */
  263|      5|      uri->port = 0;
  264|      5|      is_unix_domain = 1;
  265|      5|    }
  266|  5.43M|    while (len && *q != ':' && *q != '/' && *q != '?') {
  ------------------
  |  Branch (266:12): [True: 5.43M, False: 128]
  |  Branch (266:19): [True: 5.43M, False: 164]
  |  Branch (266:32): [True: 5.43M, False: 11]
  |  Branch (266:45): [True: 5.43M, False: 4]
  ------------------
  267|  5.43M|      ++q;
  268|  5.43M|      --len;
  269|  5.43M|    }
  270|       |
  271|    307|    if (p == q) {
  ------------------
  |  Branch (271:9): [True: 10, False: 297]
  ------------------
  272|     10|      res = -3;
  273|     10|      goto error;
  274|     10|    }
  275|       |
  276|    297|    if ((int)(q - p) > 255) {
  ------------------
  |  Branch (276:9): [True: 36, False: 261]
  ------------------
  277|     36|      coap_log_warn("Host name length too long (%d > 255)\n", (int)(q - p));
  ------------------
  |  |  108|     36|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     36|#define coap_log(level, ...) do { \
  |  |  |  |  291|     36|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 36, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|     36|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     36|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 36]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  278|     36|      res = -6;
  279|     36|      goto error;
  280|     36|    }
  281|       |
  282|    261|    COAP_SET_STR(&uri->host, q - p, p);
  ------------------
  |  |   52|    261|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  283|    261|  }
  284|       |
  285|       |  /* check for Uri-Port (invalid for Unix) */
  286|    322|  if (len && *q == ':') {
  ------------------
  |  Branch (286:7): [True: 204, False: 118]
  |  Branch (286:14): [True: 161, False: 43]
  ------------------
  287|    161|    if (is_unix_domain || is_llc) {
  ------------------
  |  Branch (287:9): [True: 1, False: 160]
  |  Branch (287:27): [True: 2, False: 158]
  ------------------
  288|      3|      res = -5;
  289|      3|      goto error;
  290|      3|    }
  291|    158|    p = ++q;
  292|    158|    --len;
  293|       |
  294|  1.55M|    while (len && isdigit(*q)) {
  ------------------
  |  Branch (294:12): [True: 1.55M, False: 83]
  |  Branch (294:19): [True: 1.55M, False: 75]
  ------------------
  295|  1.55M|      ++q;
  296|  1.55M|      --len;
  297|  1.55M|    }
  298|       |
  299|    158|    if (p < q) {                /* explicit port number given */
  ------------------
  |  Branch (299:9): [True: 109, False: 49]
  ------------------
  300|    109|      long uri_port = 0;
  301|       |
  302|   447k|      while ((p < q) && (uri_port <= UINT16_MAX))
  ------------------
  |  Branch (302:14): [True: 447k, False: 80]
  |  Branch (302:25): [True: 447k, False: 29]
  ------------------
  303|   447k|        uri_port = uri_port * 10 + (*p++ - '0');
  304|       |
  305|       |      /* check if port number is in allowed range */
  306|    109|      if (uri_port > UINT16_MAX) {
  ------------------
  |  Branch (306:11): [True: 50, False: 59]
  ------------------
  307|     50|        coap_log_warn("Port number too big (%ld > 65535)\n", uri_port);
  ------------------
  |  |  108|     50|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     50|#define coap_log(level, ...) do { \
  |  |  |  |  291|     50|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 50, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|     50|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     50|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 50]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  308|     50|        res = -4;
  309|     50|        goto error;
  310|     50|      }
  311|       |
  312|     59|      uri->port = (uint16_t)uri_port;
  313|     59|    }
  314|    158|  }
  315|       |
  316|    346|path:                 /* q points just past the authority, or to a relative URI's leading '/' */
  317|       |
  318|    346|  if (!len)
  ------------------
  |  Branch (318:7): [True: 161, False: 185]
  ------------------
  319|    161|    goto end;
  320|       |
  321|    185|  if (*q == '/') {
  ------------------
  |  Branch (321:7): [True: 95, False: 90]
  ------------------
  322|     95|    p = ++q;
  323|     95|    --len;
  324|       |
  325|  7.89M|    while (len && *q != '?') {
  ------------------
  |  Branch (325:12): [True: 7.89M, False: 68]
  |  Branch (325:19): [True: 7.89M, False: 27]
  ------------------
  326|  7.89M|      ++q;
  327|  7.89M|      --len;
  328|  7.89M|    }
  329|       |
  330|     95|    if (p < q) {
  ------------------
  |  Branch (330:9): [True: 72, False: 23]
  ------------------
  331|     72|      COAP_SET_STR(&uri->path, q - p, p);
  ------------------
  |  |   52|     72|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  332|     72|    }
  333|     95|  }
  334|       |
  335|       |  /* Uri_Query */
  336|    185|  if (len && *q == '?') {
  ------------------
  |  Branch (336:7): [True: 117, False: 68]
  |  Branch (336:14): [True: 30, False: 87]
  ------------------
  337|     30|    ++q;
  338|     30|    --len;
  339|     30|    COAP_SET_STR(&uri->query, len, q);
  ------------------
  |  |   52|     30|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  340|     30|    len = 0;
  341|     30|  }
  342|       |
  343|    346|end:
  344|    346|  return len ? -1 : 0;
  ------------------
  |  Branch (344:10): [True: 87, False: 259]
  ------------------
  345|       |
  346|    514|error:
  347|    514|  return res;
  348|    185|}

coap_ws_is_supported:
   38|      1|coap_ws_is_supported(void) {
   39|      1|  return coap_tcp_is_supported();
   40|      1|}
coap_wss_is_supported:
   43|      1|coap_wss_is_supported(void) {
   44|      1|  return coap_tls_is_supported();
   45|      1|}

LLVMFuzzerTestOneInput:
    4|    861|LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
    5|    861|  coap_uri_t uri;
    6|    861|  coap_split_uri(data, size, &uri);
    7|    861|  return 0;
    8|    861|}

