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

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|    383|coap_ticks(coap_tick_t *t) {
   91|    383|  coap_tick_t tmp;
   92|       |
   93|    383|#ifdef COAP_CLOCK
   94|    383|  struct timespec tv;
   95|    383|  clock_gettime(COAP_CLOCK, &tv);
  ------------------
  |  |   43|    383|#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|    383|  tmp = SHR_FP(tv.tv_nsec * Q(FRAC, (COAP_TICKS_PER_SECOND/1000000000.0)), FRAC);
  ------------------
  |  |   87|    383|#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|    383|  *t = tmp + (tv.tv_sec - coap_clock_offset) * COAP_TICKS_PER_SECOND;
  ------------------
  |  |  164|    383|#define COAP_TICKS_PER_SECOND ((coap_tick_t)(1000U))
  ------------------
  120|    383|}
coap_ticks_to_rt:
  123|    383|coap_ticks_to_rt(coap_tick_t t) {
  124|    383|  return coap_clock_offset + (t / COAP_TICKS_PER_SECOND);
  ------------------
  |  |  164|    383|#define COAP_TICKS_PER_SECOND ((coap_tick_t)(1000U))
  ------------------
  125|    383|}
coap_ticks_to_rt_us:
  128|    383|coap_ticks_to_rt_us(coap_tick_t t) {
  129|    383|  return (uint64_t)coap_clock_offset * 1000000 + (uint64_t)t * 1000000 / COAP_TICKS_PER_SECOND;
  ------------------
  |  |  164|    383|#define COAP_TICKS_PER_SECOND ((coap_tick_t)(1000U))
  ------------------
  130|    383|}

coap_split_uri:
  352|    830|coap_split_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri) {
  353|    830|  return coap_split_uri_sub(str_var, len, uri, COAP_URI_CHECK_URI);
  354|    830|}
coap_uri.c:coap_split_uri_sub:
   84|    830|                   coap_uri_check_t check_proxy) {
   85|    830|  const uint8_t *p, *q;
   86|    830|  int res = 0;
   87|    830|  size_t i;
   88|    830|  int is_unix_domain = 0;
   89|    830|  int is_llc = 0;
   90|       |
   91|    830|  if (!str_var || !uri || len == 0)
  ------------------
  |  Branch (91:7): [True: 0, False: 830]
  |  Branch (91:19): [True: 0, False: 830]
  |  Branch (91:27): [True: 0, False: 830]
  ------------------
   92|      0|    return -1;
   93|       |
   94|    830|  memset(uri, 0, sizeof(coap_uri_t));
   95|    830|  uri->port = COAP_DEFAULT_PORT;
  ------------------
  |  |   39|    830|#define COAP_DEFAULT_PORT      5683 /* CoAP default UDP/TCP port */
  ------------------
   96|       |
   97|       |  /* search for scheme */
   98|    830|  p = str_var;
   99|    830|  if (*p == '/') {
  ------------------
  |  Branch (99:7): [True: 75, False: 755]
  ------------------
  100|       |    /* no scheme, host or port */
  101|     75|    if (check_proxy == COAP_URI_CHECK_PROXY) {
  ------------------
  |  Branch (101:9): [True: 0, False: 75]
  ------------------
  102|       |      /* Must have ongoing host if proxy definition */
  103|      0|      return -1;
  104|      0|    }
  105|     75|    q = p;
  106|     75|    goto path;
  107|     75|  }
  108|       |
  109|       |  /* find scheme terminating :// */
  110|  11.7M|  while (len >= 3 && !(p[0] == ':' && p[1] == '/' && p[2] == '/')) {
  ------------------
  |  Branch (110:10): [True: 11.7M, False: 67]
  |  Branch (110:24): [True: 4.30k, False: 11.7M]
  |  Branch (110:39): [True: 1.23k, False: 3.06k]
  |  Branch (110:54): [True: 688, False: 547]
  ------------------
  111|  11.7M|    ++p;
  112|  11.7M|    --len;
  113|  11.7M|  }
  114|    755|  if (len < 3) {
  ------------------
  |  Branch (114:7): [True: 67, False: 688]
  ------------------
  115|       |    /* scheme not defined with a :// terminator */
  116|     67|    res = -2;
  117|     67|    goto error;
  118|     67|  }
  119|  1.76k|  for (i = 0; i < COAP_URI_SCHEME_LAST; i++) {
  ------------------
  |  Branch (119:15): [True: 1.63k, False: 132]
  ------------------
  120|  1.63k|    if ((p - str_var) == (int)strlen(coap_uri_scheme[i].name) &&
  ------------------
  |  Branch (120:9): [True: 682, False: 953]
  ------------------
  121|    682|        memcmp(str_var, coap_uri_scheme[i].name, p - str_var) == 0) {
  ------------------
  |  Branch (121:9): [True: 556, False: 126]
  ------------------
  122|    556|      if (check_proxy != COAP_URI_CHECK_PROXY && coap_uri_scheme[i].proxy_only) {
  ------------------
  |  Branch (122:11): [True: 556, False: 0]
  |  Branch (122:50): [True: 1, False: 555]
  ------------------
  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|    555|      uri->scheme = coap_uri_scheme[i].scheme;
  128|    555|      uri->port = coap_uri_scheme[i].port;
  129|    555|      break;
  130|    556|    }
  131|  1.63k|  }
  132|    687|  if (i == COAP_URI_SCHEME_LAST) {
  ------------------
  |  Branch (132:7): [True: 132, False: 555]
  ------------------
  133|       |    /* scheme unknown */
  134|    132|    coap_log_err("%.*s URI scheme unknown\n", (int)(p - str_var), str_var);
  ------------------
  |  |  102|    132|#define coap_log_err(...) coap_log(COAP_LOG_ERR, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|    132|#define coap_log(level, ...) do { \
  |  |  |  |  291|    132|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 132, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|    132|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|    132|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 132]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  135|    132|    res = -1;
  136|    132|    goto error;
  137|    132|  }
  138|    555|  switch (uri->scheme) {
  139|    550|  case COAP_URI_SCHEME_COAP:
  ------------------
  |  Branch (139:3): [True: 550, False: 5]
  ------------------
  140|    550|    break;
  141|      1|  case COAP_URI_SCHEME_COAPS:
  ------------------
  |  Branch (141:3): [True: 1, False: 554]
  ------------------
  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: 554]
  ------------------
  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: 554]
  ------------------
  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: 554]
  ------------------
  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: 554]
  ------------------
  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: 555]
  ------------------
  172|      0|  case COAP_URI_SCHEME_HTTPS:
  ------------------
  |  Branch (172:3): [True: 0, False: 555]
  ------------------
  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: 555]
  ------------------
  176|      0|  default:
  ------------------
  |  Branch (176:3): [True: 0, False: 555]
  ------------------
  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|    555|  }
  180|       |  /* skip :// */
  181|    555|  p += 3;
  182|    555|  len -= 3;
  183|       |
  184|       |  /* p points to beginning of Uri-Host */
  185|    555|  q = p;
  186|       |
  187|    555|  if (len && *p == '[') {
  ------------------
  |  Branch (187:7): [True: 549, False: 6]
  |  Branch (187:14): [True: 76, False: 473]
  ------------------
  188|       |    /* IPv6 address reference or Unix domain */
  189|     76|    ++p;
  190|     76|    ++q;
  191|     76|    --len;
  192|       |
  193|  5.43M|    while (len && *q != ']') {
  ------------------
  |  Branch (193:12): [True: 5.43M, False: 22]
  |  Branch (193:19): [True: 5.43M, False: 54]
  ------------------
  194|  5.43M|      ++q;
  195|  5.43M|      --len;
  196|  5.43M|    }
  197|       |
  198|     76|    if (!len || *q != ']' || p == q) {
  ------------------
  |  Branch (198:9): [True: 22, False: 54]
  |  Branch (198:17): [True: 0, False: 54]
  |  Branch (198:30): [True: 1, False: 53]
  ------------------
  199|     23|      res = -3;
  200|     23|      goto error;
  201|     23|    }
  202|       |
  203|     53|    if ((int)(q - p) > 255) {
  ------------------
  |  Branch (203:9): [True: 23, False: 30]
  ------------------
  204|     23|      coap_log_warn("Host name length too long (%d > 255)\n", (int)(q - p));
  ------------------
  |  |  108|     23|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     23|#define coap_log(level, ...) do { \
  |  |  |  |  291|     23|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 23, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|     23|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     23|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 23]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  205|     23|      res = -6;
  206|     23|      goto error;
  207|     23|    }
  208|       |
  209|     30|    COAP_SET_STR(&uri->host, q - p, p);
  ------------------
  |  |   52|     30|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  210|     30|    ++q;
  211|     30|    --len;
  212|     30|#if COAP_AF_LLC_SUPPORT
  213|    479|  } else if ((len >= LLC_HOST_LEN) && strncmp((const char *)p, "llc[", 4) == 0) {
  ------------------
  |  |  178|    479|#define LLC_HOST_LEN (4 + HW_ADDRSTRLEN + 4)
  |  |  ------------------
  |  |  |  |  176|    479|#define HW_ADDRSTRLEN 17
  |  |  ------------------
  ------------------
  |  Branch (213:14): [True: 323, False: 156]
  |  Branch (213:39): [True: 179, False: 144]
  ------------------
  214|    179|    unsigned long sap = 0;
  215|       |
  216|    179|    is_llc = 1;
  217|       |
  218|  1.99M|    while (len && *q != ']') {
  ------------------
  |  Branch (218:12): [True: 1.99M, False: 7]
  |  Branch (218:19): [True: 1.99M, False: 172]
  ------------------
  219|  1.99M|      ++q;
  220|  1.99M|      --len;
  221|  1.99M|    }
  222|       |
  223|    179|    if (!len || *q != ']' || p == q) {
  ------------------
  |  Branch (223:9): [True: 7, False: 172]
  |  Branch (223:17): [True: 0, False: 172]
  |  Branch (223:30): [True: 0, False: 172]
  ------------------
  224|      7|      res = -7;
  225|      7|      goto error;
  226|      7|    }
  227|       |
  228|    172|    ++q;
  229|    172|    --len;
  230|       |
  231|    172|    if (!len || *q != ':') {
  ------------------
  |  Branch (231:9): [True: 18, False: 154]
  |  Branch (231:17): [True: 14, False: 140]
  ------------------
  232|     32|      coap_log_warn("LLC SAP missing in URI\n");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  233|     32|      res = -7;
  234|     32|      goto error;
  235|     32|    }
  236|       |
  237|    140|    ++q;
  238|    140|    --len;
  239|       |
  240|  12.2k|    while (len && isxdigit(*q)) {
  ------------------
  |  Branch (240:12): [True: 12.2k, False: 34]
  |  Branch (240:19): [True: 12.1k, False: 106]
  ------------------
  241|  12.1k|      if (*q >= 'a' && *q <= 'f')
  ------------------
  |  Branch (241:11): [True: 1.57k, False: 10.5k]
  |  Branch (241:24): [True: 1.57k, False: 0]
  ------------------
  242|  1.57k|        sap = sap * 16 + (*q - 'a' + 10);
  243|  10.5k|      else if (*q >= 'A' && *q <= 'F')
  ------------------
  |  Branch (243:16): [True: 750, False: 9.78k]
  |  Branch (243:29): [True: 750, False: 0]
  ------------------
  244|    750|        sap = sap * 16 + (*q - 'A' + 10);
  245|       |
  246|  12.1k|      ++q;
  247|  12.1k|      --len;
  248|  12.1k|    }
  249|       |
  250|    140|    if (sap > UINT8_MAX) {
  ------------------
  |  Branch (250:9): [True: 102, False: 38]
  ------------------
  251|    102|      coap_log_warn("LLC SAP invalid (%lu > 255)\n", sap);
  ------------------
  |  |  108|    102|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|    102|#define coap_log(level, ...) do { \
  |  |  |  |  291|    102|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 102, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|    102|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|    102|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 102]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  252|    102|      res = -7;
  253|    102|      goto error;
  254|    102|    }
  255|       |
  256|     38|    COAP_SET_STR(&uri->host, q - p, p);
  ------------------
  |  |   52|     38|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  257|     38|#endif /* COAP_AF_LLC_SUPPORT */
  258|    300|  } else {
  259|       |    /* IPv4 address, FQDN or Unix domain socket */
  260|    300|    if (len >= 3 && p[0] == '%' && p[1] == '2' &&
  ------------------
  |  Branch (260:9): [True: 263, False: 37]
  |  Branch (260:21): [True: 44, False: 219]
  |  Branch (260:36): [True: 22, False: 22]
  ------------------
  261|     22|        (p[2] == 'F' || p[2] == 'f')) {
  ------------------
  |  Branch (261:10): [True: 2, False: 20]
  |  Branch (261:25): [True: 1, False: 19]
  ------------------
  262|       |      /* Unix domain definition */
  263|      3|      uri->port = 0;
  264|      3|      is_unix_domain = 1;
  265|      3|    }
  266|  5.48M|    while (len && *q != ':' && *q != '/' && *q != '?') {
  ------------------
  |  Branch (266:12): [True: 5.48M, False: 124]
  |  Branch (266:19): [True: 5.48M, False: 161]
  |  Branch (266:32): [True: 5.48M, False: 9]
  |  Branch (266:45): [True: 5.48M, False: 6]
  ------------------
  267|  5.48M|      ++q;
  268|  5.48M|      --len;
  269|  5.48M|    }
  270|       |
  271|    300|    if (p == q) {
  ------------------
  |  Branch (271:9): [True: 9, False: 291]
  ------------------
  272|      9|      res = -3;
  273|      9|      goto error;
  274|      9|    }
  275|       |
  276|    291|    if ((int)(q - p) > 255) {
  ------------------
  |  Branch (276:9): [True: 39, False: 252]
  ------------------
  277|     39|      coap_log_warn("Host name length too long (%d > 255)\n", (int)(q - p));
  ------------------
  |  |  108|     39|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     39|#define coap_log(level, ...) do { \
  |  |  |  |  291|     39|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 39, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|     39|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     39|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 39]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  278|     39|      res = -6;
  279|     39|      goto error;
  280|     39|    }
  281|       |
  282|    252|    COAP_SET_STR(&uri->host, q - p, p);
  ------------------
  |  |   52|    252|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  283|    252|  }
  284|       |
  285|       |  /* check for Uri-Port (invalid for Unix) */
  286|    320|  if (len && *q == ':') {
  ------------------
  |  Branch (286:7): [True: 209, False: 111]
  |  Branch (286:14): [True: 157, False: 52]
  ------------------
  287|    157|    if (is_unix_domain || is_llc) {
  ------------------
  |  Branch (287:9): [True: 1, False: 156]
  |  Branch (287:27): [True: 2, False: 154]
  ------------------
  288|      3|      res = -5;
  289|      3|      goto error;
  290|      3|    }
  291|    154|    p = ++q;
  292|    154|    --len;
  293|       |
  294|  1.79M|    while (len && isdigit(*q)) {
  ------------------
  |  Branch (294:12): [True: 1.79M, False: 83]
  |  Branch (294:19): [True: 1.79M, False: 71]
  ------------------
  295|  1.79M|      ++q;
  296|  1.79M|      --len;
  297|  1.79M|    }
  298|       |
  299|    154|    if (p < q) {                /* explicit port number given */
  ------------------
  |  Branch (299:9): [True: 112, False: 42]
  ------------------
  300|    112|      long uri_port = 0;
  301|       |
  302|   591k|      while ((p < q) && (uri_port <= UINT16_MAX))
  ------------------
  |  Branch (302:14): [True: 590k, False: 80]
  |  Branch (302:25): [True: 590k, False: 32]
  ------------------
  303|   590k|        uri_port = uri_port * 10 + (*p++ - '0');
  304|       |
  305|       |      /* check if port number is in allowed range */
  306|    112|      if (uri_port > UINT16_MAX) {
  ------------------
  |  Branch (306:11): [True: 54, False: 58]
  ------------------
  307|     54|        coap_log_warn("Port number too big (%ld > 65535)\n", uri_port);
  ------------------
  |  |  108|     54|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     54|#define coap_log(level, ...) do { \
  |  |  |  |  291|     54|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 54, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|     54|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     54|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 54]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  308|     54|        res = -4;
  309|     54|        goto error;
  310|     54|      }
  311|       |
  312|     58|      uri->port = (uint16_t)uri_port;
  313|     58|    }
  314|    154|  }
  315|       |
  316|    338|path:                 /* at this point, p must point to an absolute path */
  317|       |
  318|    338|  if (!len)
  ------------------
  |  Branch (318:7): [True: 153, False: 185]
  ------------------
  319|    153|    goto end;
  320|       |
  321|    185|  if (*q == '/') {
  ------------------
  |  Branch (321:7): [True: 88, False: 97]
  ------------------
  322|     88|    p = ++q;
  323|     88|    --len;
  324|       |
  325|  7.07M|    while (len && *q != '?') {
  ------------------
  |  Branch (325:12): [True: 7.07M, False: 65]
  |  Branch (325:19): [True: 7.07M, False: 23]
  ------------------
  326|  7.07M|      ++q;
  327|  7.07M|      --len;
  328|  7.07M|    }
  329|       |
  330|     88|    if (p < q) {
  ------------------
  |  Branch (330:9): [True: 65, False: 23]
  ------------------
  331|     65|      COAP_SET_STR(&uri->path, q - p, p);
  ------------------
  |  |   52|     65|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  332|     65|      p = q;
  333|     65|    }
  334|     88|  }
  335|       |
  336|       |  /* Uri_Query */
  337|    185|  if (len && *p == '?') {
  ------------------
  |  Branch (337:7): [True: 120, False: 65]
  |  Branch (337:14): [True: 23, False: 97]
  ------------------
  338|     23|    ++p;
  339|     23|    --len;
  340|     23|    COAP_SET_STR(&uri->query, len, p);
  ------------------
  |  |   52|     23|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  341|     23|    len = 0;
  342|     23|  }
  343|       |
  344|    338|end:
  345|    338|  return len ? -1 : 0;
  ------------------
  |  Branch (345:10): [True: 97, False: 241]
  ------------------
  346|       |
  347|    491|error:
  348|    491|  return res;
  349|    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|    830|LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
    5|    830|  coap_uri_t uri;
    6|    830|  coap_split_uri(data, size, &uri);
    7|    830|  return 0;
    8|    830|}

