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

coap_dtls_is_supported:
  188|      1|coap_dtls_is_supported(void) {
  189|      1|  if (SSLeay() < 0x10100000L) {
  ------------------
  |  Branch (189:7): [True: 0, False: 1]
  ------------------
  190|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  191|      0|    return 0;
  192|      0|  }
  193|      1|#if OPENSSL_VERSION_NUMBER >= 0x10101000L
  194|       |  /*
  195|       |   * For 1.1.1, we need to use SSL_CTX_set_client_hello_cb()
  196|       |   * which is not in 1.1.0 instead of SSL_CTX_set_tlsext_servername_callback()
  197|       |   *
  198|       |   * However, there could be a runtime undefined external reference error
  199|       |   * as SSL_CTX_set_client_hello_cb() is not there in 1.1.0.
  200|       |   */
  201|      1|  if (SSLeay() < 0x10101000L) {
  ------------------
  |  Branch (201:7): [True: 0, False: 1]
  ------------------
  202|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  203|      0|    return 0;
  204|      0|  }
  205|      1|#endif /* OPENSSL_VERSION_NUMBER >= 0x10101000L */
  206|      1|  return 1;
  207|      1|}
coap_tls_is_supported:
  210|      2|coap_tls_is_supported(void) {
  211|      2|#if !COAP_DISABLE_TCP
  212|      2|  if (SSLeay() < 0x10100000L) {
  ------------------
  |  Branch (212:7): [True: 0, False: 2]
  ------------------
  213|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  214|      0|    return 0;
  215|      0|  }
  216|      2|#if OPENSSL_VERSION_NUMBER >= 0x10101000L
  217|      2|  if (SSLeay() < 0x10101000L) {
  ------------------
  |  Branch (217:7): [True: 0, False: 2]
  ------------------
  218|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  219|      0|    return 0;
  220|      0|  }
  221|      2|#endif /* OPENSSL_VERSION_NUMBER >= 0x10101000L */
  222|      2|  return 1;
  223|       |#else /* COAP_DISABLE_TCP */
  224|       |  return 0;
  225|       |#endif /* COAP_DISABLE_TCP */
  226|      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|    370|coap_ticks(coap_tick_t *t) {
   91|    370|  coap_tick_t tmp;
   92|       |
   93|    370|#ifdef COAP_CLOCK
   94|    370|  struct timespec tv;
   95|    370|  clock_gettime(COAP_CLOCK, &tv);
  ------------------
  |  |   43|    370|#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|    370|  tmp = SHR_FP(tv.tv_nsec * Q(FRAC, (COAP_TICKS_PER_SECOND/1000000000.0)), FRAC);
  ------------------
  |  |   87|    370|#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|    370|  *t = tmp + (tv.tv_sec - coap_clock_offset) * COAP_TICKS_PER_SECOND;
  ------------------
  |  |  164|    370|#define COAP_TICKS_PER_SECOND ((coap_tick_t)(1000U))
  ------------------
  120|    370|}
coap_ticks_to_rt:
  123|    370|coap_ticks_to_rt(coap_tick_t t) {
  124|    370|  return coap_clock_offset + (t / COAP_TICKS_PER_SECOND);
  ------------------
  |  |  164|    370|#define COAP_TICKS_PER_SECOND ((coap_tick_t)(1000U))
  ------------------
  125|    370|}
coap_ticks_to_rt_us:
  128|    370|coap_ticks_to_rt_us(coap_tick_t t) {
  129|    370|  return (uint64_t)coap_clock_offset * 1000000 + (uint64_t)t * 1000000 / COAP_TICKS_PER_SECOND;
  ------------------
  |  |  164|    370|#define COAP_TICKS_PER_SECOND ((coap_tick_t)(1000U))
  ------------------
  130|    370|}

coap_split_uri:
  346|    855|coap_split_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri) {
  347|    855|  return coap_split_uri_sub(str_var, len, uri, COAP_URI_CHECK_URI);
  348|    855|}
coap_uri.c:coap_split_uri_sub:
   84|    855|                   coap_uri_check_t check_proxy) {
   85|    855|  const uint8_t *p, *q;
   86|    855|  int res = 0;
   87|    855|  size_t i;
   88|    855|  int is_unix_domain = 0;
   89|    855|  int is_llc = 0;
   90|       |
   91|    855|  if (!str_var || !uri || len == 0)
  ------------------
  |  Branch (91:7): [True: 0, False: 855]
  |  Branch (91:19): [True: 0, False: 855]
  |  Branch (91:27): [True: 0, False: 855]
  ------------------
   92|      0|    return -1;
   93|       |
   94|    855|  memset(uri, 0, sizeof(coap_uri_t));
   95|    855|  uri->port = COAP_DEFAULT_PORT;
  ------------------
  |  |   39|    855|#define COAP_DEFAULT_PORT      5683 /* CoAP default UDP/TCP port */
  ------------------
   96|       |
   97|       |  /* search for scheme */
   98|    855|  p = str_var;
   99|    855|  if (*p == '/') {
  ------------------
  |  Branch (99:7): [True: 78, False: 777]
  ------------------
  100|       |    /* no scheme, host or port */
  101|     78|    if (check_proxy == COAP_URI_CHECK_PROXY) {
  ------------------
  |  Branch (101:9): [True: 0, False: 78]
  ------------------
  102|       |      /* Must have ongoing host if proxy definition */
  103|      0|      return -1;
  104|      0|    }
  105|     78|    q = p;
  106|     78|    goto path;
  107|     78|  }
  108|       |
  109|       |  /* find scheme terminating :// */
  110|  11.9M|  while (len >= 3 && !(p[0] == ':' && p[1] == '/' && p[2] == '/')) {
  ------------------
  |  Branch (110:10): [True: 11.9M, False: 71]
  |  Branch (110:24): [True: 4.14k, False: 11.9M]
  |  Branch (110:39): [True: 1.04k, False: 3.09k]
  |  Branch (110:54): [True: 706, False: 340]
  ------------------
  111|  11.9M|    ++p;
  112|  11.9M|    --len;
  113|  11.9M|  }
  114|    777|  if (len < 3) {
  ------------------
  |  Branch (114:7): [True: 71, False: 706]
  ------------------
  115|       |    /* scheme not defined with a :// terminator */
  116|     71|    res = -2;
  117|     71|    goto error;
  118|     71|  }
  119|  1.84k|  for (i = 0; i < COAP_URI_SCHEME_LAST; i++) {
  ------------------
  |  Branch (119:15): [True: 1.70k, False: 140]
  ------------------
  120|  1.70k|    if ((p - str_var) == (int)strlen(coap_uri_scheme[i].name) &&
  ------------------
  |  Branch (120:9): [True: 701, False: 1.00k]
  ------------------
  121|    701|        memcmp(str_var, coap_uri_scheme[i].name, p - str_var) == 0) {
  ------------------
  |  Branch (121:9): [True: 566, False: 135]
  ------------------
  122|    566|      if (check_proxy != COAP_URI_CHECK_PROXY && coap_uri_scheme[i].proxy_only) {
  ------------------
  |  Branch (122:11): [True: 566, False: 0]
  |  Branch (122:50): [True: 1, False: 565]
  ------------------
  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|    565|      uri->scheme = coap_uri_scheme[i].scheme;
  128|    565|      uri->port = coap_uri_scheme[i].port;
  129|    565|      break;
  130|    566|    }
  131|  1.70k|  }
  132|    705|  if (i == COAP_URI_SCHEME_LAST) {
  ------------------
  |  Branch (132:7): [True: 140, False: 565]
  ------------------
  133|       |    /* scheme unknown */
  134|    140|    coap_log_err("%.*s URI scheme unknown\n", (int)(p - str_var), str_var);
  ------------------
  |  |  102|    140|#define coap_log_err(...) coap_log(COAP_LOG_ERR, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|    140|#define coap_log(level, ...) do { \
  |  |  |  |  291|    140|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 140, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|    140|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|    140|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 140]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  135|    140|    res = -1;
  136|    140|    goto error;
  137|    140|  }
  138|    565|  switch (uri->scheme) {
  139|    560|  case COAP_URI_SCHEME_COAP:
  ------------------
  |  Branch (139:3): [True: 560, False: 5]
  ------------------
  140|    560|    break;
  141|      1|  case COAP_URI_SCHEME_COAPS:
  ------------------
  |  Branch (141:3): [True: 1, False: 564]
  ------------------
  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: 564]
  ------------------
  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: 564]
  ------------------
  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: 564]
  ------------------
  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: 564]
  ------------------
  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: 565]
  ------------------
  172|      0|  case COAP_URI_SCHEME_HTTPS:
  ------------------
  |  Branch (172:3): [True: 0, False: 565]
  ------------------
  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: 565]
  ------------------
  176|      0|  default:
  ------------------
  |  Branch (176:3): [True: 0, False: 565]
  ------------------
  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|    565|  }
  180|       |  /* skip :// */
  181|    565|  p += 3;
  182|    565|  len -= 3;
  183|       |
  184|       |  /* p points to beginning of Uri-Host */
  185|    565|  q = p;
  186|       |
  187|    565|  if (len && *p == '[') {
  ------------------
  |  Branch (187:7): [True: 559, False: 6]
  |  Branch (187:14): [True: 65, False: 494]
  ------------------
  188|       |    /* IPv6 address reference or Unix domain */
  189|     65|    ++p;
  190|     65|    ++q;
  191|     65|    --len;
  192|       |
  193|  3.04M|    while (len && *q != ']') {
  ------------------
  |  Branch (193:12): [True: 3.04M, False: 27]
  |  Branch (193:19): [True: 3.04M, False: 38]
  ------------------
  194|  3.04M|      ++q;
  195|  3.04M|      --len;
  196|  3.04M|    }
  197|       |
  198|     65|    if (!len || *q != ']' || p == q) {
  ------------------
  |  Branch (198:9): [True: 27, False: 38]
  |  Branch (198:17): [True: 0, False: 38]
  |  Branch (198:30): [True: 2, False: 36]
  ------------------
  199|     29|      res = -3;
  200|     29|      goto error;
  201|     29|    }
  202|       |
  203|     36|    COAP_SET_STR(&uri->host, q - p, p);
  ------------------
  |  |   52|     36|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  204|     36|    ++q;
  205|     36|    --len;
  206|     36|#if COAP_AF_LLC_SUPPORT
  207|    500|  } else if ((len >= LLC_HOST_LEN) && strncmp((const char *)p, "llc[", 4) == 0) {
  ------------------
  |  |  169|    500|#define LLC_HOST_LEN (4 + HW_ADDRSTRLEN + 4)
  |  |  ------------------
  |  |  |  |  167|    500|#define HW_ADDRSTRLEN 17
  |  |  ------------------
  ------------------
  |  Branch (207:14): [True: 336, False: 164]
  |  Branch (207:39): [True: 181, False: 155]
  ------------------
  208|    181|    unsigned long sap = 0;
  209|       |
  210|    181|    is_llc = 1;
  211|       |
  212|  2.01M|    while (len && *q != ']') {
  ------------------
  |  Branch (212:12): [True: 2.01M, False: 8]
  |  Branch (212:19): [True: 2.01M, False: 173]
  ------------------
  213|  2.01M|      ++q;
  214|  2.01M|      --len;
  215|  2.01M|    }
  216|       |
  217|    181|    if (!len || *q != ']' || p == q) {
  ------------------
  |  Branch (217:9): [True: 8, False: 173]
  |  Branch (217:17): [True: 0, False: 173]
  |  Branch (217:30): [True: 0, False: 173]
  ------------------
  218|      8|      res = -7;
  219|      8|      goto error;
  220|      8|    }
  221|       |
  222|    173|    ++q;
  223|    173|    --len;
  224|       |
  225|    173|    if (!len || *q != ':') {
  ------------------
  |  Branch (225:9): [True: 9, False: 164]
  |  Branch (225:17): [True: 24, False: 140]
  ------------------
  226|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  227|     33|      res = -7;
  228|     33|      goto error;
  229|     33|    }
  230|       |
  231|    140|    ++q;
  232|    140|    --len;
  233|       |
  234|  13.8k|    while (len && isxdigit(*q)) {
  ------------------
  |  Branch (234:12): [True: 13.7k, False: 43]
  |  Branch (234:19): [True: 13.6k, False: 97]
  ------------------
  235|  13.6k|      if (*q >= 'a' && *q <= 'f')
  ------------------
  |  Branch (235:11): [True: 987, False: 12.6k]
  |  Branch (235:24): [True: 987, False: 0]
  ------------------
  236|    987|        sap = sap * 16 + (*q - 'a' + 10);
  237|  12.6k|      else if (*q >= 'A' && *q <= 'F')
  ------------------
  |  Branch (237:16): [True: 1.18k, False: 11.4k]
  |  Branch (237:29): [True: 1.18k, False: 0]
  ------------------
  238|  1.18k|        sap = sap * 16 + (*q - 'A' + 10);
  239|       |
  240|  13.6k|      ++q;
  241|  13.6k|      --len;
  242|  13.6k|    }
  243|       |
  244|    140|    if (sap > UINT8_MAX) {
  ------------------
  |  Branch (244:9): [True: 115, False: 25]
  ------------------
  245|    115|      coap_log_warn("LLC SAP invalid (%lu > 255)\n", sap);
  ------------------
  |  |  108|    115|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|    115|#define coap_log(level, ...) do { \
  |  |  |  |  291|    115|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 115, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|    115|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|    115|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 115]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  246|    115|      res = -7;
  247|    115|      goto error;
  248|    115|    }
  249|       |
  250|     25|    COAP_SET_STR(&uri->host, q - p, p);
  ------------------
  |  |   52|     25|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  251|     25|#endif /* COAP_AF_LLC_SUPPORT */
  252|    319|  } else {
  253|       |    /* IPv4 address, FQDN or Unix domain socket */
  254|    319|    if (len >= 3 && p[0] == '%' && p[1] == '2' &&
  ------------------
  |  Branch (254:9): [True: 282, False: 37]
  |  Branch (254:21): [True: 48, False: 234]
  |  Branch (254:36): [True: 24, False: 24]
  ------------------
  255|     24|        (p[2] == 'F' || p[2] == 'f')) {
  ------------------
  |  Branch (255:10): [True: 2, False: 22]
  |  Branch (255:25): [True: 2, False: 20]
  ------------------
  256|       |      /* Unix domain definition */
  257|      4|      uri->port = 0;
  258|      4|      is_unix_domain = 1;
  259|      4|    }
  260|  5.23M|    while (len && *q != ':' && *q != '/' && *q != '?') {
  ------------------
  |  Branch (260:12): [True: 5.23M, False: 126]
  |  Branch (260:19): [True: 5.23M, False: 183]
  |  Branch (260:32): [True: 5.23M, False: 8]
  |  Branch (260:45): [True: 5.23M, False: 2]
  ------------------
  261|  5.23M|      ++q;
  262|  5.23M|      --len;
  263|  5.23M|    }
  264|       |
  265|    319|    if (p == q) {
  ------------------
  |  Branch (265:9): [True: 11, False: 308]
  ------------------
  266|     11|      res = -3;
  267|     11|      goto error;
  268|     11|    }
  269|       |
  270|    308|    if ((int)(q - p) > 255) {
  ------------------
  |  Branch (270:9): [True: 33, False: 275]
  ------------------
  271|     33|      coap_log_warn("Host name length too long (%d > 255)\n", (int)(q - p));
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  272|     33|      res = -6;
  273|     33|      goto error;
  274|     33|    }
  275|       |
  276|    275|    COAP_SET_STR(&uri->host, q - p, p);
  ------------------
  |  |   52|    275|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  277|    275|  }
  278|       |
  279|       |  /* check for Uri-Port (invalid for Unix) */
  280|    336|  if (len && *q == ':') {
  ------------------
  |  Branch (280:7): [True: 220, False: 116]
  |  Branch (280:14): [True: 182, False: 38]
  ------------------
  281|    182|    if (is_unix_domain || is_llc) {
  ------------------
  |  Branch (281:9): [True: 2, False: 180]
  |  Branch (281:27): [True: 1, False: 179]
  ------------------
  282|      3|      res = -5;
  283|      3|      goto error;
  284|      3|    }
  285|    179|    p = ++q;
  286|    179|    --len;
  287|       |
  288|  1.87M|    while (len && isdigit(*q)) {
  ------------------
  |  Branch (288:12): [True: 1.87M, False: 87]
  |  Branch (288:19): [True: 1.87M, False: 92]
  ------------------
  289|  1.87M|      ++q;
  290|  1.87M|      --len;
  291|  1.87M|    }
  292|       |
  293|    179|    if (p < q) {                /* explicit port number given */
  ------------------
  |  Branch (293:9): [True: 130, False: 49]
  ------------------
  294|    130|      long uri_port = 0;
  295|       |
  296|   228k|      while ((p < q) && (uri_port <= UINT16_MAX))
  ------------------
  |  Branch (296:14): [True: 228k, False: 104]
  |  Branch (296:25): [True: 228k, False: 26]
  ------------------
  297|   228k|        uri_port = uri_port * 10 + (*p++ - '0');
  298|       |
  299|       |      /* check if port number is in allowed range */
  300|    130|      if (uri_port > UINT16_MAX) {
  ------------------
  |  Branch (300:11): [True: 48, False: 82]
  ------------------
  301|     48|        coap_log_warn("Port number too big (%ld > 65535)\n", uri_port);
  ------------------
  |  |  108|     48|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     48|#define coap_log(level, ...) do { \
  |  |  |  |  291|     48|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 48, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|     48|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     48|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 48]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  302|     48|        res = -4;
  303|     48|        goto error;
  304|     48|      }
  305|       |
  306|     82|      uri->port = (uint16_t)uri_port;
  307|     82|    }
  308|    179|  }
  309|       |
  310|    363|path:                 /* at this point, p must point to an absolute path */
  311|       |
  312|    363|  if (!len)
  ------------------
  |  Branch (312:7): [True: 163, False: 200]
  ------------------
  313|    163|    goto end;
  314|       |
  315|    200|  if (*q == '/') {
  ------------------
  |  Branch (315:7): [True: 101, False: 99]
  ------------------
  316|    101|    p = ++q;
  317|    101|    --len;
  318|       |
  319|  7.57M|    while (len && *q != '?') {
  ------------------
  |  Branch (319:12): [True: 7.57M, False: 73]
  |  Branch (319:19): [True: 7.57M, False: 28]
  ------------------
  320|  7.57M|      ++q;
  321|  7.57M|      --len;
  322|  7.57M|    }
  323|       |
  324|    101|    if (p < q) {
  ------------------
  |  Branch (324:9): [True: 72, False: 29]
  ------------------
  325|     72|      COAP_SET_STR(&uri->path, q - p, p);
  ------------------
  |  |   52|     72|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  326|     72|      p = q;
  327|     72|    }
  328|    101|  }
  329|       |
  330|       |  /* Uri_Query */
  331|    200|  if (len && *p == '?') {
  ------------------
  |  Branch (331:7): [True: 127, False: 73]
  |  Branch (331:14): [True: 28, False: 99]
  ------------------
  332|     28|    ++p;
  333|     28|    --len;
  334|     28|    COAP_SET_STR(&uri->query, len, p);
  ------------------
  |  |   52|     28|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  335|     28|    len = 0;
  336|     28|  }
  337|       |
  338|    363|end:
  339|    363|  return len ? -1 : 0;
  ------------------
  |  Branch (339:10): [True: 99, False: 264]
  ------------------
  340|       |
  341|    491|error:
  342|    491|  return res;
  343|    200|}

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|    855|LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
    5|    855|  coap_uri_t uri;
    6|    855|  coap_split_uri(data, size, &uri);
    7|    855|  return 0;
    8|    855|}

