coap_get_log_level:
  103|    352|coap_get_log_level(void) {
  104|    352|  return maxlog;
  105|    352|}
coap_log_level_desc:
  124|    352|coap_log_level_desc(coap_log_t level) {
  125|    352|  static char bad[8];
  126|    352|  if (level >= sizeof(loglevels)/sizeof(loglevels[0])) {
  ------------------
  |  Branch (126:7): [True: 0, False: 352]
  ------------------
  127|      0|    snprintf(bad, sizeof(bad), "%4d", level);
  128|      0|    return bad;
  129|    352|  } else {
  130|    352|    return loglevels[level];
  131|    352|  }
  132|    352|}
coap_log_impl:
 1362|    352|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|    352|  if (log_handler) {
  ------------------
  |  Branch (1368:7): [True: 0, False: 352]
  ------------------
 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|    352|  } else {
 1386|    352|    va_list ap;
 1387|    352|    FILE *log_fd;
 1388|       |
 1389|    352|    log_fd = level <= COAP_LOG_CRIT ? COAP_ERR_FD : COAP_DEBUG_FD;
  ------------------
  |  |   44|    352|#define COAP_ERR_FD stderr
  ------------------
                  log_fd = level <= COAP_LOG_CRIT ? COAP_ERR_FD : COAP_DEBUG_FD;
  ------------------
  |  |   37|    352|#define COAP_DEBUG_FD stdout
  ------------------
  |  Branch (1389:14): [True: 0, False: 352]
  ------------------
 1390|       |
 1391|    352|#ifndef RIOT_VERSION
 1392|    352|    char timebuf[32];
 1393|    352|    coap_tick_t now;
 1394|    352|    size_t len;
 1395|       |
 1396|    352|    coap_ticks(&now);
 1397|    352|    len = print_timestamp(timebuf,sizeof(timebuf), now);
 1398|    352|    if (len)
  ------------------
  |  Branch (1398:9): [True: 352, False: 0]
  ------------------
 1399|    352|      fprintf(log_fd, "%.*s ", (int)len, timebuf);
 1400|    352|#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|    352|    fprintf(log_fd, "%s ", coap_log_level_desc(level));
 1416|       |
 1417|    352|    va_start(ap, format);
 1418|       |#ifdef RIOT_VERSION
 1419|       |    flash_vfprintf(log_fd, format, ap);
 1420|       |#else /* !RIOT_VERSION */
 1421|    352|    vfprintf(log_fd, format, ap);
 1422|    352|#endif /* !RIOT_VERSION */
 1423|    352|    va_end(ap);
 1424|    352|    fflush(log_fd);
 1425|    352|  }
 1426|       |
 1427|       |#if COAP_THREAD_SAFE
 1428|       |  coap_mutex_unlock(&m_log_impl);
 1429|       |#endif /* COAP_THREAD_SAFE */
 1430|    352|}
coap_debug.c:print_timestamp:
  144|    352|print_timestamp(char *s, size_t len, coap_tick_t t) {
  145|    352|  struct tm *tmp;
  146|    352|  size_t lensofar;
  147|    352|  time_t now = coap_ticks_to_rt(t);
  148|    352|  tmp = localtime(&now);
  149|    352|  lensofar = strftime(s, len, "%b %d %H:%M:%S", tmp);
  150|    352|  if (len > lensofar + 4) {
  ------------------
  |  Branch (150:7): [True: 352, False: 0]
  ------------------
  151|    352|    lensofar += snprintf(&s[lensofar], len-lensofar, ".%03u",
  152|    352|                         (unsigned int)((coap_ticks_to_rt_us(t) % 1000000)/1000));
  153|    352|  }
  154|    352|  return lensofar;
  155|    352|}

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

coap_split_uri:
  346|    795|coap_split_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri) {
  347|    795|  return coap_split_uri_sub(str_var, len, uri, COAP_URI_CHECK_URI);
  348|    795|}
coap_uri.c:coap_split_uri_sub:
   84|    795|                   coap_uri_check_t check_proxy) {
   85|    795|  const uint8_t *p, *q;
   86|    795|  int res = 0;
   87|    795|  size_t i;
   88|    795|  int is_unix_domain = 0;
   89|    795|  int is_llc = 0;
   90|       |
   91|    795|  if (!str_var || !uri || len == 0)
  ------------------
  |  Branch (91:7): [True: 0, False: 795]
  |  Branch (91:19): [True: 0, False: 795]
  |  Branch (91:27): [True: 0, False: 795]
  ------------------
   92|      0|    return -1;
   93|       |
   94|    795|  memset(uri, 0, sizeof(coap_uri_t));
   95|    795|  uri->port = COAP_DEFAULT_PORT;
  ------------------
  |  |   39|    795|#define COAP_DEFAULT_PORT      5683 /* CoAP default UDP/TCP port */
  ------------------
   96|       |
   97|       |  /* search for scheme */
   98|    795|  p = str_var;
   99|    795|  if (*p == '/') {
  ------------------
  |  Branch (99:7): [True: 76, False: 719]
  ------------------
  100|       |    /* no scheme, host or port */
  101|     76|    if (check_proxy == COAP_URI_CHECK_PROXY) {
  ------------------
  |  Branch (101:9): [True: 0, False: 76]
  ------------------
  102|       |      /* Must have ongoing host if proxy definition */
  103|      0|      return -1;
  104|      0|    }
  105|     76|    q = p;
  106|     76|    goto path;
  107|     76|  }
  108|       |
  109|       |  /* find scheme terminating :// */
  110|  10.7M|  while (len >= 3 && !(p[0] == ':' && p[1] == '/' && p[2] == '/')) {
  ------------------
  |  Branch (110:10): [True: 10.7M, False: 66]
  |  Branch (110:24): [True: 4.03k, False: 10.7M]
  |  Branch (110:39): [True: 1.05k, False: 2.98k]
  |  Branch (110:54): [True: 653, False: 400]
  ------------------
  111|  10.7M|    ++p;
  112|  10.7M|    --len;
  113|  10.7M|  }
  114|    719|  if (len < 3) {
  ------------------
  |  Branch (114:7): [True: 66, False: 653]
  ------------------
  115|       |    /* scheme not defined with a :// terminator */
  116|     66|    res = -2;
  117|     66|    goto error;
  118|     66|  }
  119|  1.76k|  for (i = 0; i < COAP_URI_SCHEME_LAST; i++) {
  ------------------
  |  Branch (119:15): [True: 1.62k, False: 136]
  ------------------
  120|  1.62k|    if ((p - str_var) == (int)strlen(coap_uri_scheme[i].name) &&
  ------------------
  |  Branch (120:9): [True: 651, False: 977]
  ------------------
  121|    651|        memcmp(str_var, coap_uri_scheme[i].name, p - str_var) == 0) {
  ------------------
  |  Branch (121:9): [True: 517, False: 134]
  ------------------
  122|    517|      if (check_proxy != COAP_URI_CHECK_PROXY && coap_uri_scheme[i].proxy_only) {
  ------------------
  |  Branch (122:11): [True: 517, False: 0]
  |  Branch (122:50): [True: 1, False: 516]
  ------------------
  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|    516|      uri->scheme = coap_uri_scheme[i].scheme;
  128|    516|      uri->port = coap_uri_scheme[i].port;
  129|    516|      break;
  130|    517|    }
  131|  1.62k|  }
  132|    652|  if (i == COAP_URI_SCHEME_LAST) {
  ------------------
  |  Branch (132:7): [True: 136, False: 516]
  ------------------
  133|       |    /* scheme unknown */
  134|    136|    coap_log_err("%.*s URI scheme unknown\n", (int)(p - str_var), str_var);
  ------------------
  |  |  102|    136|#define coap_log_err(...) coap_log(COAP_LOG_ERR, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|    136|#define coap_log(level, ...) do { \
  |  |  |  |  291|    136|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 136, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|    136|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|    136|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 136]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  135|    136|    res = -1;
  136|    136|    goto error;
  137|    136|  }
  138|    516|  switch (uri->scheme) {
  139|    511|  case COAP_URI_SCHEME_COAP:
  ------------------
  |  Branch (139:3): [True: 511, False: 5]
  ------------------
  140|    511|    break;
  141|      1|  case COAP_URI_SCHEME_COAPS:
  ------------------
  |  Branch (141:3): [True: 1, False: 515]
  ------------------
  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: 515]
  ------------------
  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: 515]
  ------------------
  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: 515]
  ------------------
  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: 515]
  ------------------
  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: 516]
  ------------------
  172|      0|  case COAP_URI_SCHEME_HTTPS:
  ------------------
  |  Branch (172:3): [True: 0, False: 516]
  ------------------
  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: 516]
  ------------------
  176|      0|  default:
  ------------------
  |  Branch (176:3): [True: 0, False: 516]
  ------------------
  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|    516|  }
  180|       |  /* skip :// */
  181|    516|  p += 3;
  182|    516|  len -= 3;
  183|       |
  184|       |  /* p points to beginning of Uri-Host */
  185|    516|  q = p;
  186|       |
  187|    516|  if (len && *p == '[') {
  ------------------
  |  Branch (187:7): [True: 510, False: 6]
  |  Branch (187:14): [True: 60, False: 450]
  ------------------
  188|       |    /* IPv6 address reference or Unix domain */
  189|     60|    ++p;
  190|     60|    ++q;
  191|     60|    --len;
  192|       |
  193|  3.03M|    while (len && *q != ']') {
  ------------------
  |  Branch (193:12): [True: 3.03M, False: 22]
  |  Branch (193:19): [True: 3.03M, False: 38]
  ------------------
  194|  3.03M|      ++q;
  195|  3.03M|      --len;
  196|  3.03M|    }
  197|       |
  198|     60|    if (!len || *q != ']' || p == q) {
  ------------------
  |  Branch (198:9): [True: 22, False: 38]
  |  Branch (198:17): [True: 0, False: 38]
  |  Branch (198:30): [True: 2, False: 36]
  ------------------
  199|     24|      res = -3;
  200|     24|      goto error;
  201|     24|    }
  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|    456|  } else if ((len >= LLC_HOST_LEN) && strncmp((const char *)p, "llc[", 4) == 0) {
  ------------------
  |  |  178|    456|#define LLC_HOST_LEN (4 + HW_ADDRSTRLEN + 4)
  |  |  ------------------
  |  |  |  |  176|    456|#define HW_ADDRSTRLEN 17
  |  |  ------------------
  ------------------
  |  Branch (207:14): [True: 308, False: 148]
  |  Branch (207:39): [True: 169, False: 139]
  ------------------
  208|    169|    unsigned long sap = 0;
  209|       |
  210|    169|    is_llc = 1;
  211|       |
  212|  3.09M|    while (len && *q != ']') {
  ------------------
  |  Branch (212:12): [True: 3.09M, False: 9]
  |  Branch (212:19): [True: 3.09M, False: 160]
  ------------------
  213|  3.09M|      ++q;
  214|  3.09M|      --len;
  215|  3.09M|    }
  216|       |
  217|    169|    if (!len || *q != ']' || p == q) {
  ------------------
  |  Branch (217:9): [True: 9, False: 160]
  |  Branch (217:17): [True: 0, False: 160]
  |  Branch (217:30): [True: 0, False: 160]
  ------------------
  218|      9|      res = -7;
  219|      9|      goto error;
  220|      9|    }
  221|       |
  222|    160|    ++q;
  223|    160|    --len;
  224|       |
  225|    160|    if (!len || *q != ':') {
  ------------------
  |  Branch (225:9): [True: 22, False: 138]
  |  Branch (225:17): [True: 14, False: 124]
  ------------------
  226|     36|      coap_log_warn("LLC SAP missing in URI\n");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  227|     36|      res = -7;
  228|     36|      goto error;
  229|     36|    }
  230|       |
  231|    124|    ++q;
  232|    124|    --len;
  233|       |
  234|  2.57k|    while (len && isxdigit(*q)) {
  ------------------
  |  Branch (234:12): [True: 2.54k, False: 31]
  |  Branch (234:19): [True: 2.45k, False: 93]
  ------------------
  235|  2.45k|      if (*q >= 'a' && *q <= 'f')
  ------------------
  |  Branch (235:11): [True: 1.13k, False: 1.32k]
  |  Branch (235:24): [True: 1.13k, False: 0]
  ------------------
  236|  1.13k|        sap = sap * 16 + (*q - 'a' + 10);
  237|  1.32k|      else if (*q >= 'A' && *q <= 'F')
  ------------------
  |  Branch (237:16): [True: 940, False: 380]
  |  Branch (237:29): [True: 940, False: 0]
  ------------------
  238|    940|        sap = sap * 16 + (*q - 'A' + 10);
  239|       |
  240|  2.45k|      ++q;
  241|  2.45k|      --len;
  242|  2.45k|    }
  243|       |
  244|    124|    if (sap > UINT8_MAX) {
  ------------------
  |  Branch (244:9): [True: 94, False: 30]
  ------------------
  245|     94|      coap_log_warn("LLC SAP invalid (%lu > 255)\n", sap);
  ------------------
  |  |  108|     94|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     94|#define coap_log(level, ...) do { \
  |  |  |  |  291|     94|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 94, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|     94|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     94|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 94]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  246|     94|      res = -7;
  247|     94|      goto error;
  248|     94|    }
  249|       |
  250|     30|    COAP_SET_STR(&uri->host, q - p, p);
  ------------------
  |  |   52|     30|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  251|     30|#endif /* COAP_AF_LLC_SUPPORT */
  252|    287|  } else {
  253|       |    /* IPv4 address, FQDN or Unix domain socket */
  254|    287|    if (len >= 3 && p[0] == '%' && p[1] == '2' &&
  ------------------
  |  Branch (254:9): [True: 252, False: 35]
  |  Branch (254:21): [True: 35, False: 217]
  |  Branch (254:36): [True: 21, False: 14]
  ------------------
  255|     21|        (p[2] == 'F' || p[2] == 'f')) {
  ------------------
  |  Branch (255:10): [True: 2, False: 19]
  |  Branch (255:25): [True: 3, False: 16]
  ------------------
  256|       |      /* Unix domain definition */
  257|      5|      uri->port = 0;
  258|      5|      is_unix_domain = 1;
  259|      5|    }
  260|  4.57M|    while (len && *q != ':' && *q != '/' && *q != '?') {
  ------------------
  |  Branch (260:12): [True: 4.57M, False: 119]
  |  Branch (260:19): [True: 4.57M, False: 158]
  |  Branch (260:32): [True: 4.57M, False: 5]
  |  Branch (260:45): [True: 4.57M, False: 5]
  ------------------
  261|  4.57M|      ++q;
  262|  4.57M|      --len;
  263|  4.57M|    }
  264|       |
  265|    287|    if (p == q) {
  ------------------
  |  Branch (265:9): [True: 9, False: 278]
  ------------------
  266|      9|      res = -3;
  267|      9|      goto error;
  268|      9|    }
  269|       |
  270|    278|    if ((int)(q - p) > 255) {
  ------------------
  |  Branch (270:9): [True: 34, False: 244]
  ------------------
  271|     34|      coap_log_warn("Host name length too long (%d > 255)\n", (int)(q - p));
  ------------------
  |  |  108|     34|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     34|#define coap_log(level, ...) do { \
  |  |  |  |  291|     34|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 34, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|     34|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     34|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 34]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  272|     34|      res = -6;
  273|     34|      goto error;
  274|     34|    }
  275|       |
  276|    244|    COAP_SET_STR(&uri->host, q - p, p);
  ------------------
  |  |   52|    244|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  277|    244|  }
  278|       |
  279|       |  /* check for Uri-Port (invalid for Unix) */
  280|    310|  if (len && *q == ':') {
  ------------------
  |  Branch (280:7): [True: 201, False: 109]
  |  Branch (280:14): [True: 155, False: 46]
  ------------------
  281|    155|    if (is_unix_domain || is_llc) {
  ------------------
  |  Branch (281:9): [True: 2, False: 153]
  |  Branch (281:27): [True: 1, False: 152]
  ------------------
  282|      3|      res = -5;
  283|      3|      goto error;
  284|      3|    }
  285|    152|    p = ++q;
  286|    152|    --len;
  287|       |
  288|  1.56M|    while (len && isdigit(*q)) {
  ------------------
  |  Branch (288:12): [True: 1.56M, False: 83]
  |  Branch (288:19): [True: 1.56M, False: 69]
  ------------------
  289|  1.56M|      ++q;
  290|  1.56M|      --len;
  291|  1.56M|    }
  292|       |
  293|    152|    if (p < q) {                /* explicit port number given */
  ------------------
  |  Branch (293:9): [True: 115, False: 37]
  ------------------
  294|    115|      long uri_port = 0;
  295|       |
  296|   457k|      while ((p < q) && (uri_port <= UINT16_MAX))
  ------------------
  |  Branch (296:14): [True: 457k, False: 85]
  |  Branch (296:25): [True: 457k, False: 30]
  ------------------
  297|   457k|        uri_port = uri_port * 10 + (*p++ - '0');
  298|       |
  299|       |      /* check if port number is in allowed range */
  300|    115|      if (uri_port > UINT16_MAX) {
  ------------------
  |  Branch (300:11): [True: 51, False: 64]
  ------------------
  301|     51|        coap_log_warn("Port number too big (%ld > 65535)\n", uri_port);
  ------------------
  |  |  108|     51|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     51|#define coap_log(level, ...) do { \
  |  |  |  |  291|     51|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 51, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|     51|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     51|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 51]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  302|     51|        res = -4;
  303|     51|        goto error;
  304|     51|      }
  305|       |
  306|     64|      uri->port = (uint16_t)uri_port;
  307|     64|    }
  308|    152|  }
  309|       |
  310|    332|path:                 /* at this point, p must point to an absolute path */
  311|       |
  312|    332|  if (!len)
  ------------------
  |  Branch (312:7): [True: 152, False: 180]
  ------------------
  313|    152|    goto end;
  314|       |
  315|    180|  if (*q == '/') {
  ------------------
  |  Branch (315:7): [True: 91, False: 89]
  ------------------
  316|     91|    p = ++q;
  317|     91|    --len;
  318|       |
  319|  7.58M|    while (len && *q != '?') {
  ------------------
  |  Branch (319:12): [True: 7.58M, False: 63]
  |  Branch (319:19): [True: 7.58M, False: 28]
  ------------------
  320|  7.58M|      ++q;
  321|  7.58M|      --len;
  322|  7.58M|    }
  323|       |
  324|     91|    if (p < q) {
  ------------------
  |  Branch (324:9): [True: 64, False: 27]
  ------------------
  325|     64|      COAP_SET_STR(&uri->path, q - p, p);
  ------------------
  |  |   52|     64|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  326|     64|      p = q;
  327|     64|    }
  328|     91|  }
  329|       |
  330|       |  /* Uri_Query */
  331|    180|  if (len && *p == '?') {
  ------------------
  |  Branch (331:7): [True: 117, False: 63]
  |  Branch (331:14): [True: 28, False: 89]
  ------------------
  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|    332|end:
  339|    332|  return len ? -1 : 0;
  ------------------
  |  Branch (339:10): [True: 89, False: 243]
  ------------------
  340|       |
  341|    462|error:
  342|    462|  return res;
  343|    180|}

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

