coap_get_log_level:
  103|  4.52M|coap_get_log_level(void) {
  104|  4.52M|  return maxlog;
  105|  4.52M|}
coap_set_log_level:
  108|  3.10k|coap_set_log_level(coap_log_t level) {
  109|  3.10k|  if (level > COAP_MAX_LOGGING_LEVEL)
  ------------------
  |  |   48|  3.10k|#define COAP_MAX_LOGGING_LEVEL 8
  ------------------
  |  Branch (109:7): [True: 0, False: 3.10k]
  ------------------
  110|      0|    level = COAP_MAX_LOGGING_LEVEL;
  ------------------
  |  |   48|      0|#define COAP_MAX_LOGGING_LEVEL 8
  ------------------
  111|  3.10k|  maxlog = level;
  112|  3.10k|}
coap_show_pdu:
  813|  1.59k|coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu) {
  814|       |#if COAP_CONSTRAINED_STACK
  815|       |  /* Proxy-Uri: can be 1034 bytes long */
  816|       |  /* buf and outbuf can be protected by m_show_pdu if needed */
  817|       |  static unsigned char buf[USE_BUF_SIZE];
  818|       |  static char outbuf[COAP_DEBUG_BUF_SIZE];
  819|       |#else /* ! COAP_CONSTRAINED_STACK */
  820|       |  /* Proxy-Uri: can be 1034 bytes long */
  821|  1.59k|  unsigned char buf[USE_BUF_SIZE];
  822|  1.59k|  char outbuf[COAP_DEBUG_BUF_SIZE];
  823|  1.59k|#endif /* ! COAP_CONSTRAINED_STACK */
  824|  1.59k|  size_t buf_len = 0; /* takes the number of bytes written to buf */
  825|  1.59k|  int have_options = 0;
  826|  1.59k|  uint32_t i;
  827|  1.59k|  coap_opt_iterator_t opt_iter;
  828|  1.59k|  coap_opt_t *option;
  829|  1.59k|  int content_format = -1;
  830|  1.59k|  size_t data_len;
  831|  1.59k|  const uint8_t *data;
  832|  1.59k|  uint32_t opt_len;
  833|  1.59k|  const uint8_t *opt_val;
  834|  1.59k|  size_t outbuflen = 0;
  835|  1.59k|  int is_oscore_payload = 0;
  836|  1.59k|  const char *exp;
  837|  1.59k|  uint32_t value;
  838|       |
  839|       |  /* Save time if not needed */
  840|  1.59k|  if (level > coap_get_log_level())
  ------------------
  |  Branch (840:7): [True: 1.59k, False: 0]
  ------------------
  841|  1.59k|    return;
  842|       |
  843|       |#if COAP_THREAD_SAFE
  844|       |  coap_mutex_lock(&m_show_pdu);
  845|       |#endif /* COAP_THREAD_SAFE */
  846|      0|  if (!pdu->session || COAP_PROTO_NOT_RELIABLE(pdu->session->proto)) {
  ------------------
  |  |   41|      0|#define COAP_PROTO_NOT_RELIABLE(p) ((p)==COAP_PROTO_UDP || (p)==COAP_PROTO_DTLS)
  |  |  ------------------
  |  |  |  Branch (41:37): [True: 0, False: 0]
  |  |  |  Branch (41:60): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (846:7): [True: 0, False: 0]
  ------------------
  847|      0|    snprintf(outbuf, sizeof(outbuf), "v:%d t:%s c:%s i:%04x {",
  848|      0|             COAP_DEFAULT_VERSION, msg_type_string(pdu->type),
  ------------------
  |  |   35|      0|#define COAP_DEFAULT_VERSION      1 /* version of CoAP supported */
  ------------------
  849|      0|             msg_code_string(pdu->code), pdu->mid);
  850|      0|  } else if (pdu->session->proto == COAP_PROTO_WS ||
  ------------------
  |  Branch (850:14): [True: 0, False: 0]
  ------------------
  851|      0|             pdu->session->proto == COAP_PROTO_WSS) {
  ------------------
  |  Branch (851:14): [True: 0, False: 0]
  ------------------
  852|      0|    if (pdu->type != COAP_MESSAGE_CON)
  ------------------
  |  Branch (852:9): [True: 0, False: 0]
  ------------------
  853|      0|      coap_log_alert("WebSocket: type != CON\n");
  ------------------
  |  |   90|      0|#define coap_log_alert(...) coap_log(COAP_LOG_ALERT, __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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  854|      0|    snprintf(outbuf, sizeof(outbuf), "v:WebSocket c:%s {",
  855|      0|             msg_code_string(pdu->code));
  856|      0|  } else {
  857|      0|    if (pdu->type != COAP_MESSAGE_CON)
  ------------------
  |  Branch (857:9): [True: 0, False: 0]
  ------------------
  858|      0|      coap_log_alert("Reliable: type != CON\n");
  ------------------
  |  |   90|      0|#define coap_log_alert(...) coap_log(COAP_LOG_ALERT, __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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  859|      0|    snprintf(outbuf, sizeof(outbuf), "v:Reliable c:%s {",
  860|      0|             msg_code_string(pdu->code));
  861|      0|  }
  862|       |
  863|      0|  for (i = 0; i < pdu->actual_token.length; i++) {
  ------------------
  |  Branch (863:15): [True: 0, False: 0]
  ------------------
  864|      0|    outbuflen = strlen(outbuf);
  865|      0|    snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,
  866|      0|             "%02x", pdu->actual_token.s[i]);
  867|      0|  }
  868|      0|  outbuflen = strlen(outbuf);
  869|      0|  snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,  "}");
  870|       |
  871|       |  /* show options, if any */
  872|      0|  coap_option_iterator_init(pdu, &opt_iter, COAP_OPT_ALL);
  ------------------
  |  |  230|      0|#define COAP_OPT_ALL NULL
  ------------------
  873|       |
  874|      0|  outbuflen = strlen(outbuf);
  875|      0|  snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,  " [");
  876|      0|  while ((option = coap_option_next(&opt_iter))) {
  ------------------
  |  Branch (876:10): [True: 0, False: 0]
  ------------------
  877|      0|    buf[0] = '\000';
  878|      0|    if (!have_options) {
  ------------------
  |  Branch (878:9): [True: 0, False: 0]
  ------------------
  879|      0|      have_options = 1;
  880|      0|    } else {
  881|      0|      outbuflen = strlen(outbuf);
  882|      0|      snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,  ",");
  883|      0|    }
  884|       |
  885|      0|    if (pdu->code == COAP_SIGNALING_CODE_CSM) {
  ------------------
  |  Branch (885:9): [True: 0, False: 0]
  ------------------
  886|      0|      switch ((coap_sig_csm_opt_t)opt_iter.number) {
  887|      0|      case COAP_SIG_OPT_EXTENDED_TOKEN_LENGTH:
  ------------------
  |  Branch (887:7): [True: 0, False: 0]
  ------------------
  888|      0|      case COAP_SIG_OPT_MAX_MESSAGE_SIZE:
  ------------------
  |  Branch (888:7): [True: 0, False: 0]
  ------------------
  889|      0|        buf_len = snprintf((char *)buf, sizeof(buf), "%u",
  890|      0|                           coap_decode_var_bytes(coap_opt_value(option),
  891|      0|                                                 coap_opt_length(option)));
  892|      0|        break;
  893|      0|      case COAP_SIG_OPT_BLOCK_WISE_TRANSFER:
  ------------------
  |  Branch (893:7): [True: 0, False: 0]
  ------------------
  894|      0|      default:
  ------------------
  |  Branch (894:7): [True: 0, False: 0]
  ------------------
  895|      0|        buf_len = 0;
  896|      0|        break;
  897|      0|      }
  898|      0|    } else if (pdu->code == COAP_SIGNALING_CODE_PING ||
  ------------------
  |  Branch (898:16): [True: 0, False: 0]
  ------------------
  899|      0|               pdu->code == COAP_SIGNALING_CODE_PONG) {
  ------------------
  |  Branch (899:16): [True: 0, False: 0]
  ------------------
  900|      0|      switch ((coap_sig_ping_opt_t)opt_iter.number) {
  901|      0|      case COAP_SIG_OPT_CUSTODY:
  ------------------
  |  Branch (901:7): [True: 0, False: 0]
  ------------------
  902|      0|      default:
  ------------------
  |  Branch (902:7): [True: 0, False: 0]
  ------------------
  903|      0|        buf_len = 0;
  904|      0|      }
  905|      0|    } else if (pdu->code == COAP_SIGNALING_CODE_RELEASE) {
  ------------------
  |  Branch (905:16): [True: 0, False: 0]
  ------------------
  906|      0|      switch ((coap_sig_release_opt_t)opt_iter.number) {
  907|      0|      case COAP_SIG_OPT_ALTERNATIVE_ADDRESS:
  ------------------
  |  Branch (907:7): [True: 0, False: 0]
  ------------------
  908|      0|        buf_len = print_readable(coap_opt_value(option),
  909|      0|                                 coap_opt_length(option),
  910|      0|                                 buf, sizeof(buf), 0);
  911|      0|        break;
  912|      0|      case COAP_SIG_OPT_HOLD_OFF:
  ------------------
  |  Branch (912:7): [True: 0, False: 0]
  ------------------
  913|      0|        buf_len = snprintf((char *)buf, sizeof(buf), "%u",
  914|      0|                           coap_decode_var_bytes(coap_opt_value(option),
  915|      0|                                                 coap_opt_length(option)));
  916|      0|        break;
  917|      0|      default:
  ------------------
  |  Branch (917:7): [True: 0, False: 0]
  ------------------
  918|      0|        buf_len = 0;
  919|      0|        break;
  920|      0|      }
  921|      0|    } else if (pdu->code == COAP_SIGNALING_CODE_ABORT) {
  ------------------
  |  Branch (921:16): [True: 0, False: 0]
  ------------------
  922|      0|      switch ((coap_sig_abort_opt_t)opt_iter.number) {
  923|      0|      case COAP_SIG_OPT_BAD_CSM_OPTION:
  ------------------
  |  Branch (923:7): [True: 0, False: 0]
  ------------------
  924|      0|        buf_len = snprintf((char *)buf, sizeof(buf), "%u",
  925|      0|                           coap_decode_var_bytes(coap_opt_value(option),
  926|      0|                                                 coap_opt_length(option)));
  927|      0|        break;
  928|      0|      default:
  ------------------
  |  Branch (928:7): [True: 0, False: 0]
  ------------------
  929|      0|        buf_len = 0;
  930|      0|        break;
  931|      0|      }
  932|      0|    } else {
  933|      0|      switch ((coap_code_opt_num_t)opt_iter.number) {
  934|      0|      case COAP_OPTION_CONTENT_FORMAT:
  ------------------
  |  Branch (934:7): [True: 0, False: 0]
  ------------------
  935|      0|      case COAP_OPTION_ACCEPT:
  ------------------
  |  Branch (935:7): [True: 0, False: 0]
  ------------------
  936|      0|        content_format = (int)coap_decode_var_bytes(coap_opt_value(option),
  937|      0|                                                    coap_opt_length(option));
  938|       |
  939|      0|        buf_len = print_content_format(content_format, buf, sizeof(buf));
  940|      0|        break;
  941|       |
  942|      0|      case COAP_OPTION_BLOCK1:
  ------------------
  |  Branch (942:7): [True: 0, False: 0]
  ------------------
  943|      0|      case COAP_OPTION_BLOCK2:
  ------------------
  |  Branch (943:7): [True: 0, False: 0]
  ------------------
  944|      0|      case COAP_OPTION_Q_BLOCK1:
  ------------------
  |  Branch (944:7): [True: 0, False: 0]
  ------------------
  945|      0|      case COAP_OPTION_Q_BLOCK2:
  ------------------
  |  Branch (945:7): [True: 0, False: 0]
  ------------------
  946|       |        /* split block option into number/more/size where more is the
  947|       |         * letter M if set, the _ otherwise */
  948|      0|        if (COAP_OPT_BLOCK_SZX(option) == 7) {
  ------------------
  |  |   96|      0|  (coap_opt_length(opt) ? (COAP_OPT_BLOCK_END_BYTE(opt) & 0x07) : 0)
  |  |  ------------------
  |  |  |  |   87|      0|  ((coap_opt_length(opt) && coap_opt_value(opt)) ? \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (87:5): [True: 0, False: 0]
  |  |  |  |  |  Branch (87:29): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   88|      0|   *(coap_opt_value(opt) + (coap_opt_length(opt)-1)) : 0)
  |  |  ------------------
  |  |  |  Branch (96:4): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (948:13): [True: 0, False: 0]
  ------------------
  949|      0|          if (coap_get_data(pdu, &data_len, &data))
  ------------------
  |  Branch (949:15): [True: 0, False: 0]
  ------------------
  950|      0|            buf_len = snprintf((char *)buf, sizeof(buf), "%u/%c/BERT(%" PRIuS ")",
  951|      0|                               coap_opt_block_num(option), /* block number */
  952|      0|                               COAP_OPT_BLOCK_MORE(option) ? 'M' : '_', /* M bit */
  ------------------
  |  |   92|      0|  (coap_opt_length(opt) ? (COAP_OPT_BLOCK_END_BYTE(opt) & 0x08) : 0)
  |  |  ------------------
  |  |  |  |   87|      0|  ((coap_opt_length(opt) && coap_opt_value(opt)) ? \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (87:5): [True: 0, False: 0]
  |  |  |  |  |  Branch (87:29): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   88|      0|   *(coap_opt_value(opt) + (coap_opt_length(opt)-1)) : 0)
  |  |  ------------------
  |  |  |  Branch (92:3): [True: 0, False: 0]
  |  |  |  Branch (92:4): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  953|      0|                               data_len);
  954|      0|          else
  955|      0|            buf_len = snprintf((char *)buf, sizeof(buf), "%u/%c/BERT",
  956|      0|                               coap_opt_block_num(option), /* block number */
  957|      0|                               COAP_OPT_BLOCK_MORE(option) ? 'M' : '_'); /* M bit */
  ------------------
  |  |   92|      0|  (coap_opt_length(opt) ? (COAP_OPT_BLOCK_END_BYTE(opt) & 0x08) : 0)
  |  |  ------------------
  |  |  |  |   87|      0|  ((coap_opt_length(opt) && coap_opt_value(opt)) ? \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (87:5): [True: 0, False: 0]
  |  |  |  |  |  Branch (87:29): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   88|      0|   *(coap_opt_value(opt) + (coap_opt_length(opt)-1)) : 0)
  |  |  ------------------
  |  |  |  Branch (92:3): [True: 0, False: 0]
  |  |  |  Branch (92:4): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  958|      0|        } else {
  959|      0|          buf_len = snprintf((char *)buf, sizeof(buf), "%u/%c/%u",
  960|      0|                             coap_opt_block_num(option), /* block number */
  961|      0|                             COAP_OPT_BLOCK_MORE(option) ? 'M' : '_', /* M bit */
  ------------------
  |  |   92|      0|  (coap_opt_length(opt) ? (COAP_OPT_BLOCK_END_BYTE(opt) & 0x08) : 0)
  |  |  ------------------
  |  |  |  |   87|      0|  ((coap_opt_length(opt) && coap_opt_value(opt)) ? \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (87:5): [True: 0, False: 0]
  |  |  |  |  |  Branch (87:29): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   88|      0|   *(coap_opt_value(opt) + (coap_opt_length(opt)-1)) : 0)
  |  |  ------------------
  |  |  |  Branch (92:3): [True: 0, False: 0]
  |  |  |  Branch (92:4): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  962|      0|                             (unsigned)(1u << (COAP_OPT_BLOCK_SZX(option) + 4))); /* block size */
  ------------------
  |  |   96|      0|  (coap_opt_length(opt) ? (COAP_OPT_BLOCK_END_BYTE(opt) & 0x07) : 0)
  |  |  ------------------
  |  |  |  |   87|      0|  ((coap_opt_length(opt) && coap_opt_value(opt)) ? \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (87:5): [True: 0, False: 0]
  |  |  |  |  |  Branch (87:29): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   88|      0|   *(coap_opt_value(opt) + (coap_opt_length(opt)-1)) : 0)
  |  |  ------------------
  |  |  |  Branch (96:4): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  963|      0|        }
  964|       |
  965|      0|        break;
  966|       |
  967|      0|      case COAP_OPTION_OSCORE:
  ------------------
  |  Branch (967:7): [True: 0, False: 0]
  ------------------
  968|      0|        opt_len = coap_opt_length(option);
  969|      0|        buf[0] = '\000';
  970|      0|        if (opt_len) {
  ------------------
  |  Branch (970:13): [True: 0, False: 0]
  ------------------
  971|      0|          size_t ofs = 1;
  972|      0|          size_t cnt;
  973|       |
  974|      0|          opt_val = coap_opt_value(option);
  975|      0|          if (opt_val[0] & 0x20) {
  ------------------
  |  Branch (975:15): [True: 0, False: 0]
  ------------------
  976|       |            /* Group Flag */
  977|      0|            snprintf((char *)buf, sizeof(buf), "grp");
  978|      0|          }
  979|      0|          if (opt_val[0] & 0x07) {
  ------------------
  |  Branch (979:15): [True: 0, False: 0]
  ------------------
  980|       |            /* Partial IV */
  981|      0|            cnt = opt_val[0] & 0x07;
  982|      0|            if (cnt > opt_len - ofs)
  ------------------
  |  Branch (982:17): [True: 0, False: 0]
  ------------------
  983|      0|              goto no_more;
  984|      0|            buf_len = strlen((char *)buf);
  985|      0|            snprintf((char *)&buf[buf_len], sizeof(buf)-buf_len, "%spIV=0x",
  986|      0|                     buf_len ? "," : "");
  ------------------
  |  Branch (986:22): [True: 0, False: 0]
  ------------------
  987|      0|            for (i = 0; (uint32_t)i < cnt; i++) {
  ------------------
  |  Branch (987:25): [True: 0, False: 0]
  ------------------
  988|      0|              buf_len = strlen((char *)buf);
  989|      0|              snprintf((char *)&buf[buf_len], sizeof(buf)-buf_len,
  990|      0|                       "%02x", opt_val[ofs + i]);
  991|      0|            }
  992|      0|            ofs += cnt;
  993|      0|          }
  994|      0|          if (opt_val[0] & 0x10) {
  ------------------
  |  Branch (994:15): [True: 0, False: 0]
  ------------------
  995|       |            /* kid context */
  996|      0|            if (ofs >= opt_len)
  ------------------
  |  Branch (996:17): [True: 0, False: 0]
  ------------------
  997|      0|              goto no_more;
  998|      0|            cnt = opt_val[ofs];
  999|      0|            if (cnt > opt_len - ofs - 1)
  ------------------
  |  Branch (999:17): [True: 0, False: 0]
  ------------------
 1000|      0|              goto no_more;
 1001|      0|            ofs++;
 1002|      0|            buf_len = strlen((char *)buf);
 1003|      0|            snprintf((char *)&buf[buf_len], sizeof(buf)-buf_len, "%skc=0x",
 1004|      0|                     buf_len ? "," : "");
  ------------------
  |  Branch (1004:22): [True: 0, False: 0]
  ------------------
 1005|      0|            for (i = 0; (uint32_t)i < cnt; i++) {
  ------------------
  |  Branch (1005:25): [True: 0, False: 0]
  ------------------
 1006|      0|              buf_len = strlen((char *)buf);
 1007|      0|              snprintf((char *)&buf[buf_len], sizeof(buf)-buf_len,
 1008|      0|                       "%02x", opt_val[ofs + i]);
 1009|      0|            }
 1010|      0|            ofs += cnt;
 1011|      0|          }
 1012|      0|          if (opt_val[0] & 0x08) {
  ------------------
  |  Branch (1012:15): [True: 0, False: 0]
  ------------------
 1013|       |            /* kid */
 1014|      0|            if (ofs >= opt_len)
  ------------------
  |  Branch (1014:17): [True: 0, False: 0]
  ------------------
 1015|      0|              goto no_more;
 1016|      0|            cnt = opt_len - ofs;
 1017|      0|            buf_len = strlen((char *)buf);
 1018|      0|            snprintf((char *)&buf[buf_len], sizeof(buf)-buf_len, "%skid=0x",
 1019|      0|                     buf_len ? "," : "");
  ------------------
  |  Branch (1019:22): [True: 0, False: 0]
  ------------------
 1020|      0|            for (i = 0; (uint32_t)i < cnt; i++) {
  ------------------
  |  Branch (1020:25): [True: 0, False: 0]
  ------------------
 1021|      0|              buf_len = strlen((char *)buf);
 1022|      0|              snprintf((char *)&buf[buf_len], sizeof(buf)-buf_len,
 1023|      0|                       "%02x", opt_val[ofs + i]);
 1024|      0|            }
 1025|      0|          }
 1026|      0|        }
 1027|      0|no_more:
 1028|      0|        buf_len = strlen((char *)buf);
 1029|      0|        is_oscore_payload = 1;
 1030|      0|        break;
 1031|       |
 1032|      0|      case COAP_OPTION_URI_PORT:
  ------------------
  |  Branch (1032:7): [True: 0, False: 0]
  ------------------
 1033|      0|      case COAP_OPTION_MAXAGE:
  ------------------
  |  Branch (1033:7): [True: 0, False: 0]
  ------------------
 1034|      0|      case COAP_OPTION_OBSERVE:
  ------------------
  |  Branch (1034:7): [True: 0, False: 0]
  ------------------
 1035|      0|      case COAP_OPTION_SIZE1:
  ------------------
  |  Branch (1035:7): [True: 0, False: 0]
  ------------------
 1036|      0|      case COAP_OPTION_SIZE2:
  ------------------
  |  Branch (1036:7): [True: 0, False: 0]
  ------------------
 1037|      0|      case COAP_OPTION_HOP_LIMIT:
  ------------------
  |  Branch (1037:7): [True: 0, False: 0]
  ------------------
 1038|      0|        if (coap_opt_length(option)) {
  ------------------
  |  Branch (1038:13): [True: 0, False: 0]
  ------------------
 1039|       |          /* show values as unsigned decimal value */
 1040|      0|          buf_len = snprintf((char *)buf, sizeof(buf), "%u",
 1041|      0|                             coap_decode_var_bytes(coap_opt_value(option),
 1042|      0|                                                   coap_opt_length(option)));
 1043|      0|        }
 1044|      0|        break;
 1045|       |
 1046|      0|      case COAP_OPTION_IF_MATCH:
  ------------------
  |  Branch (1046:7): [True: 0, False: 0]
  ------------------
 1047|      0|      case COAP_OPTION_ETAG:
  ------------------
  |  Branch (1047:7): [True: 0, False: 0]
  ------------------
 1048|      0|      case COAP_OPTION_ECHO:
  ------------------
  |  Branch (1048:7): [True: 0, False: 0]
  ------------------
 1049|      0|      case COAP_OPTION_NORESPONSE:
  ------------------
  |  Branch (1049:7): [True: 0, False: 0]
  ------------------
 1050|      0|      case COAP_OPTION_RTAG:
  ------------------
  |  Branch (1050:7): [True: 0, False: 0]
  ------------------
 1051|      0|        opt_len = coap_opt_length(option);
 1052|      0|        opt_val = coap_opt_value(option);
 1053|      0|        snprintf((char *)buf, sizeof(buf), "0x");
 1054|      0|        for (i = 0; (uint32_t)i < opt_len; i++) {
  ------------------
  |  Branch (1054:21): [True: 0, False: 0]
  ------------------
 1055|      0|          buf_len = strlen((char *)buf);
 1056|      0|          snprintf((char *)&buf[buf_len], sizeof(buf)-buf_len,
 1057|      0|                   "%02x", opt_val[i]);
 1058|      0|        }
 1059|      0|        buf_len = strlen((char *)buf);
 1060|      0|        break;
 1061|      0|      case COAP_OPTION_URI_PATH_ABB:
  ------------------
  |  Branch (1061:7): [True: 0, False: 0]
  ------------------
 1062|      0|        value = coap_decode_var_bytes(coap_opt_value(option),
 1063|      0|                                      coap_opt_length(option));
 1064|      0|        exp = coap_map_abbrev_uri_path(coap_upa_server_mapping_chain, value);
 1065|      0|        if (!exp) {
  ------------------
  |  Branch (1065:13): [True: 0, False: 0]
  ------------------
 1066|      0|          exp = coap_map_abbrev_uri_path(coap_upa_client_fallback_chain, value);
 1067|      0|        }
 1068|      0|        if (exp) {
  ------------------
  |  Branch (1068:13): [True: 0, False: 0]
  ------------------
 1069|      0|          snprintf((char *)&buf, sizeof(buf), "%s", exp);
 1070|      0|        } else {
 1071|      0|          snprintf((char *)&buf, sizeof(buf), "(%" PRIu32 ")", value);
 1072|      0|        }
 1073|      0|        buf_len = strlen((char *)buf);
 1074|      0|        break;
 1075|      0|      case COAP_OPTION_URI_PATH:
  ------------------
  |  Branch (1075:7): [True: 0, False: 0]
  ------------------
 1076|      0|      case COAP_OPTION_PROXY_URI:
  ------------------
  |  Branch (1076:7): [True: 0, False: 0]
  ------------------
 1077|      0|      case COAP_OPTION_URI_HOST:
  ------------------
  |  Branch (1077:7): [True: 0, False: 0]
  ------------------
 1078|      0|      case COAP_OPTION_LOCATION_PATH:
  ------------------
  |  Branch (1078:7): [True: 0, False: 0]
  ------------------
 1079|      0|      case COAP_OPTION_LOCATION_QUERY:
  ------------------
  |  Branch (1079:7): [True: 0, False: 0]
  ------------------
 1080|      0|      case COAP_OPTION_PROXY_SCHEME:
  ------------------
  |  Branch (1080:7): [True: 0, False: 0]
  ------------------
 1081|      0|      case COAP_OPTION_URI_QUERY:
  ------------------
  |  Branch (1081:7): [True: 0, False: 0]
  ------------------
 1082|      0|        buf_len = print_readable(coap_opt_value(option),
 1083|      0|                                 coap_opt_length(option),
 1084|      0|                                 buf, sizeof(buf), 0);
 1085|      0|        break;
 1086|      0|      case COAP_OPTION_IF_NONE_MATCH:
  ------------------
  |  Branch (1086:7): [True: 0, False: 0]
  ------------------
 1087|      0|      case COAP_OPTION_EDHOC:
  ------------------
  |  Branch (1087:7): [True: 0, False: 0]
  ------------------
 1088|      0|      default:
  ------------------
  |  Branch (1088:7): [True: 0, False: 0]
  ------------------
 1089|      0|        buf_len = print_readable(coap_opt_value(option),
 1090|      0|                                 coap_opt_length(option),
 1091|      0|                                 buf, sizeof(buf), 1);
 1092|      0|      }
 1093|      0|    }
 1094|      0|    outbuflen = strlen(outbuf);
 1095|      0|    snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,
 1096|      0|             " %s:%.*s", coap_option_string(pdu->code, opt_iter.number),
 1097|      0|             (int)buf_len, buf);
 1098|      0|  }
 1099|       |
 1100|      0|  outbuflen = strlen(outbuf);
 1101|      0|  snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,  " ]");
 1102|       |
 1103|      0|  if (coap_get_data(pdu, &data_len, &data)) {
  ------------------
  |  Branch (1103:7): [True: 0, False: 0]
  ------------------
 1104|      0|    if (!enable_data_for_show_pdu) {
  ------------------
  |  Branch (1104:9): [True: 0, False: 0]
  ------------------
 1105|       |      /* Only output data if wanted */
 1106|      0|      outbuflen = strlen(outbuf);
 1107|      0|      snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,  " :: ");
 1108|      0|      outbuflen = strlen(outbuf);
 1109|      0|      snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,
 1110|      0|               "data length %"PRIuS " (data suppressed)\n", data_len);
 1111|      0|      COAP_DO_SHOW_OUTPUT_LINE;
  ------------------
  |  |  780|      0|  do {                                      \
  |  |  781|      0|    if (use_fprintf_for_show_pdu) {         \
  |  |  ------------------
  |  |  |  Branch (781:9): [True: 0, False: 0]
  |  |  ------------------
  |  |  782|      0|      fprintf(COAP_DEBUG_FD, "%s", outbuf); \
  |  |  ------------------
  |  |  |  |   37|      0|#define COAP_DEBUG_FD stdout
  |  |  ------------------
  |  |  783|      0|    }                                       \
  |  |  784|      0|    else {                                  \
  |  |  785|      0|      coap_log(level, "%s", outbuf);        \
  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  786|      0|    }                                       \
  |  |  787|      0|  } while (0)
  |  |  ------------------
  |  |  |  Branch (787:12): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1112|       |#if COAP_THREAD_SAFE
 1113|       |      coap_mutex_unlock(&m_show_pdu);
 1114|       |#endif /* COAP_THREAD_SAFE */
 1115|      0|      return;
 1116|      0|    }
 1117|       |
 1118|      0|    outbuflen = strlen(outbuf);
 1119|      0|    snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,  " :: ");
 1120|       |
 1121|      0|    if (is_binary(content_format) || !isprint(data[0]) || is_oscore_payload) {
  ------------------
  |  Branch (1121:9): [True: 0, False: 0]
  |  Branch (1121:38): [True: 0, False: 0]
  |  Branch (1121:59): [True: 0, False: 0]
  ------------------
 1122|      0|      size_t keep_data_len = data_len;
 1123|      0|      const uint8_t *keep_data = data;
 1124|       |
 1125|      0|      outbuflen = strlen(outbuf);
 1126|      0|      snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,
 1127|      0|               "binary data length %"PRIuS "\n", data_len);
 1128|      0|      COAP_DO_SHOW_OUTPUT_LINE;
  ------------------
  |  |  780|      0|  do {                                      \
  |  |  781|      0|    if (use_fprintf_for_show_pdu) {         \
  |  |  ------------------
  |  |  |  Branch (781:9): [True: 0, False: 0]
  |  |  ------------------
  |  |  782|      0|      fprintf(COAP_DEBUG_FD, "%s", outbuf); \
  |  |  ------------------
  |  |  |  |   37|      0|#define COAP_DEBUG_FD stdout
  |  |  ------------------
  |  |  783|      0|    }                                       \
  |  |  784|      0|    else {                                  \
  |  |  785|      0|      coap_log(level, "%s", outbuf);        \
  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  786|      0|    }                                       \
  |  |  787|      0|  } while (0)
  |  |  ------------------
  |  |  |  Branch (787:12): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1129|       |      /*
 1130|       |       * Output hex dump of binary data as a continuous entry
 1131|       |       */
 1132|      0|      outbuf[0] = '\000';
 1133|      0|      snprintf(outbuf, sizeof(outbuf),  "<<");
 1134|      0|      while (data_len--) {
  ------------------
  |  Branch (1134:14): [True: 0, False: 0]
  ------------------
 1135|      0|        outbuflen = strlen(outbuf);
 1136|      0|        snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,
 1137|      0|                 "%02x", *data++);
 1138|      0|      }
 1139|      0|      outbuflen = strlen(outbuf);
 1140|      0|      snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,  ">>");
 1141|      0|      data_len = keep_data_len;
 1142|      0|      data = keep_data;
 1143|      0|      outbuflen = strlen(outbuf);
 1144|      0|      if (outbuflen == sizeof(outbuf)-1)
  ------------------
  |  Branch (1144:11): [True: 0, False: 0]
  ------------------
 1145|      0|        outbuflen--;
 1146|      0|      snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,  "\n");
 1147|      0|      COAP_DO_SHOW_OUTPUT_LINE;
  ------------------
  |  |  780|      0|  do {                                      \
  |  |  781|      0|    if (use_fprintf_for_show_pdu) {         \
  |  |  ------------------
  |  |  |  Branch (781:9): [True: 0, False: 0]
  |  |  ------------------
  |  |  782|      0|      fprintf(COAP_DEBUG_FD, "%s", outbuf); \
  |  |  ------------------
  |  |  |  |   37|      0|#define COAP_DEBUG_FD stdout
  |  |  ------------------
  |  |  783|      0|    }                                       \
  |  |  784|      0|    else {                                  \
  |  |  785|      0|      coap_log(level, "%s", outbuf);        \
  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  786|      0|    }                                       \
  |  |  787|      0|  } while (0)
  |  |  ------------------
  |  |  |  Branch (787:12): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1148|       |      /*
 1149|       |       * Output ascii readable (if possible), immediately under the
 1150|       |       * hex value of the character output above to help binary debugging
 1151|       |       */
 1152|      0|      outbuf[0] = '\000';
 1153|      0|      snprintf(outbuf, sizeof(outbuf),  "<<");
 1154|      0|      while (data_len--) {
  ------------------
  |  Branch (1154:14): [True: 0, False: 0]
  ------------------
 1155|      0|        outbuflen = strlen(outbuf);
 1156|      0|        snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,
 1157|      0|                 "%c ", isprint(*data) ? *data : '.');
  ------------------
  |  Branch (1157:25): [True: 0, False: 0]
  ------------------
 1158|      0|        data++;
 1159|      0|      }
 1160|      0|      outbuflen = strlen(outbuf);
 1161|      0|      snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,  ">>");
 1162|      0|    } else {
 1163|      0|      size_t max_length;
 1164|       |
 1165|      0|      outbuflen = strlen(outbuf);
 1166|      0|      max_length = sizeof(outbuf)-outbuflen;
 1167|      0|      if (max_length > 1) {
  ------------------
  |  Branch (1167:11): [True: 0, False: 0]
  ------------------
 1168|      0|        outbuf[outbuflen++] = '\'';
 1169|      0|        outbuf[outbuflen] = '\000';
 1170|      0|        max_length--;
 1171|      0|      }
 1172|      0|      if (max_length > 1) {
  ------------------
  |  Branch (1172:11): [True: 0, False: 0]
  ------------------
 1173|      0|        outbuflen += print_readable(data, data_len,
 1174|      0|                                    (unsigned char *)&outbuf[outbuflen],
 1175|      0|                                    max_length, 0);
 1176|      0|      }
 1177|       |      /* print_readable may be handling unprintables - hence headroom of 4 */
 1178|      0|      if (outbuflen < sizeof(outbuf)-4-1) {
  ------------------
  |  Branch (1178:11): [True: 0, False: 0]
  ------------------
 1179|      0|        outbuf[outbuflen++] = '\'';
 1180|      0|        outbuf[outbuflen] = '\000';
 1181|      0|      }
 1182|      0|    }
 1183|      0|  }
 1184|       |
 1185|      0|  outbuflen = strlen(outbuf);
 1186|      0|  if (outbuflen == sizeof(outbuf)-1)
  ------------------
  |  Branch (1186:7): [True: 0, False: 0]
  ------------------
 1187|      0|    outbuflen--;
 1188|      0|  snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,  "\n");
 1189|      0|  COAP_DO_SHOW_OUTPUT_LINE;
  ------------------
  |  |  780|      0|  do {                                      \
  |  |  781|      0|    if (use_fprintf_for_show_pdu) {         \
  |  |  ------------------
  |  |  |  Branch (781:9): [True: 0, False: 0]
  |  |  ------------------
  |  |  782|      0|      fprintf(COAP_DEBUG_FD, "%s", outbuf); \
  |  |  ------------------
  |  |  |  |   37|      0|#define COAP_DEBUG_FD stdout
  |  |  ------------------
  |  |  783|      0|    }                                       \
  |  |  784|      0|    else {                                  \
  |  |  785|      0|      coap_log(level, "%s", outbuf);        \
  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  786|      0|    }                                       \
  |  |  787|      0|  } while (0)
  |  |  ------------------
  |  |  |  Branch (787:12): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1190|       |
 1191|       |#if COAP_THREAD_SAFE
 1192|       |  coap_mutex_unlock(&m_show_pdu);
 1193|       |#endif /* COAP_THREAD_SAFE */
 1194|      0|}
coap_debug_reset:
 1585|  3.10k|coap_debug_reset(void) {
 1586|       |  log_handler = NULL;
 1587|  3.10k|  maxlog = COAP_LOG_WARN;
 1588|  3.10k|  use_fprintf_for_show_pdu = 1;
 1589|  3.10k|  num_packet_loss_intervals = 0;
 1590|  3.10k|  packet_loss_level = 0;
 1591|  3.10k|  num_packet_fail_intervals = 0;
 1592|  3.10k|  packet_fail_level = 0;
 1593|  3.10k|  send_packet_count = 0;
 1594|  3.10k|  num_packet_drop_intervals = 0;
 1595|  3.10k|  packet_drop_level = 0;
 1596|  3.10k|  recv_packet_count = 0;
 1597|  3.10k|}

coap_fls:
   21|  23.4k|coap_fls(unsigned int i) {
   22|  23.4k|  return coap_flsll(i);
   23|  23.4k|}
coap_flsll:
   28|  23.4k|coap_flsll(long long j) {
   29|  23.4k|  unsigned long long i = (unsigned long long)j;
   30|  23.4k|  int n;
   31|  84.6k|  for (n = 0; i; n++)
  ------------------
  |  Branch (31:15): [True: 61.1k, False: 23.4k]
  ------------------
   32|  61.1k|    i >>= 1;
   33|  23.4k|  return n;
   34|  23.4k|}
coap_decode_var_bytes:
   38|     15|coap_decode_var_bytes(const uint8_t *buf, size_t len) {
   39|     15|  unsigned int i, n = 0;
   40|     25|  for (i = 0; i < len; ++i)
  ------------------
  |  Branch (40:15): [True: 10, False: 15]
  ------------------
   41|     10|    n = (n << 8) + buf[i];
   42|       |
   43|     15|  return n;
   44|     15|}

coap_memory_init:
  623|  3.10k|coap_memory_init(void) {
  624|  3.10k|}
coap_malloc_type:
  627|  7.66k|coap_malloc_type(coap_memory_tag_t type, size_t size) {
  628|  7.66k|  void *ptr;
  629|       |
  630|  7.66k|  (void)type;
  631|  7.66k|  ptr = malloc(size);
  632|       |#if COAP_MEMORY_TYPE_TRACK
  633|       |  assert(type < COAP_MEM_TAG_LAST);
  634|       |  if (ptr) {
  635|       |    track_counts[type]++;
  636|       |    if (track_counts[type] > peak_counts[type])
  637|       |      peak_counts[type] = track_counts[type];
  638|       |  } else {
  639|       |    fail_counts[type]++;
  640|       |  }
  641|       |#endif /* COAP_MEMORY_TYPE_TRACK */
  642|  7.66k|  return ptr;
  643|  7.66k|}
coap_realloc_type:
  646|    559|coap_realloc_type(coap_memory_tag_t type, void *p, size_t size) {
  647|    559|  void *ptr;
  648|       |
  649|    559|  (void)type;
  650|    559|  ptr = realloc(p, size);
  651|       |#if COAP_MEMORY_TYPE_TRACK
  652|       |  if (ptr) {
  653|       |    assert(type < COAP_MEM_TAG_LAST);
  654|       |    if (!p)
  655|       |      track_counts[type]++;
  656|       |    if (track_counts[type] > peak_counts[type])
  657|       |      peak_counts[type] = track_counts[type];
  658|       |  } else {
  659|       |    fail_counts[type]++;
  660|       |  }
  661|       |#endif /* COAP_MEMORY_TYPE_TRACK */
  662|    559|  return ptr;
  663|    559|}
coap_free_type:
  666|  12.4k|coap_free_type(coap_memory_tag_t type, void *p) {
  667|  12.4k|  (void)type;
  668|       |#if COAP_MEMORY_TYPE_TRACK
  669|       |  assert(type < COAP_MEM_TAG_LAST);
  670|       |  if (p)
  671|       |    track_counts[type]--;
  672|       |#endif /* COAP_MEMORY_TYPE_TRACK */
  673|  12.4k|  free(p);
  674|  12.4k|}

coap_startup:
 5514|  3.10k|coap_startup(void) {
 5515|  3.10k|  coap_tick_t now;
 5516|  3.10k|#ifndef WITH_CONTIKI
 5517|  3.10k|  uint64_t us;
 5518|  3.10k|#endif /* !WITH_CONTIKI */
 5519|       |
 5520|  3.10k|  if (coap_started)
  ------------------
  |  Branch (5520:7): [True: 0, False: 3.10k]
  ------------------
 5521|      0|    return;
 5522|  3.10k|  coap_started = 1;
 5523|       |
 5524|       |#if COAP_THREAD_SAFE
 5525|       |  coap_lock_init(&global_lock);
 5526|       |  coap_mutex_init(&m_show_pdu);
 5527|       |  coap_mutex_init(&m_log_impl);
 5528|       |  coap_mutex_init(&m_io_threads);
 5529|       |#endif /* COAP_THREAD_SAFE */
 5530|       |
 5531|       |#if defined(HAVE_WINSOCK2_H)
 5532|       |  WORD wVersionRequested = MAKEWORD(2, 2);
 5533|       |  WSADATA wsaData;
 5534|       |  WSAStartup(wVersionRequested, &wsaData);
 5535|       |#endif
 5536|  3.10k|  coap_clock_init();
 5537|  3.10k|  coap_ticks(&now);
 5538|  3.10k|#ifndef WITH_CONTIKI
 5539|  3.10k|  us = coap_ticks_to_rt_us(now);
 5540|       |  /* Be accurate to the nearest (approx) us */
 5541|  3.10k|  coap_prng_init_lkd((unsigned int)us);
 5542|       |#else /* WITH_CONTIKI */
 5543|       |  coap_start_io_process();
 5544|       |#endif /* WITH_CONTIKI */
 5545|  3.10k|  coap_memory_init();
 5546|  3.10k|  coap_dtls_startup();
 5547|       |#ifdef WITH_LWIP
 5548|       |  coap_io_lwip_init();
 5549|       |#endif /* WITH_LWIP */
 5550|  3.10k|#if COAP_SERVER_SUPPORT
 5551|  3.10k|  static coap_str_const_t well_known = { sizeof(".well-known/core")-1,
 5552|  3.10k|                                         (const uint8_t *)".well-known/core"
 5553|  3.10k|                                       };
 5554|  3.10k|  memset(&resource_uri_wellknown, 0, sizeof(resource_uri_wellknown));
 5555|  3.10k|  resource_uri_wellknown.ref = 1;
 5556|  3.10k|  resource_uri_wellknown.handler[COAP_REQUEST_GET-1] = hnd_get_wellknown_lkd;
 5557|  3.10k|  resource_uri_wellknown.flags = COAP_RESOURCE_FLAGS_HAS_MCAST_SUPPORT;
  ------------------
  |  |   89|  3.10k|#define COAP_RESOURCE_FLAGS_HAS_MCAST_SUPPORT 0x8
  ------------------
 5558|  3.10k|  resource_uri_wellknown.uri_path = &well_known;
 5559|  3.10k|#endif /* COAP_SERVER_SUPPORT */
 5560|  3.10k|  send_recv_terminate = 0;
 5561|  3.10k|  coap_prng_lkd(&coap_unique_id, sizeof(coap_unique_id));
 5562|  3.10k|}
coap_cleanup:
 5565|  3.10k|coap_cleanup(void) {
 5566|  3.10k|  if (!coap_started)
  ------------------
  |  Branch (5566:7): [True: 0, False: 3.10k]
  ------------------
 5567|      0|    return;
 5568|  3.10k|  coap_started = 0;
 5569|       |#if defined(HAVE_WINSOCK2_H)
 5570|       |  WSACleanup();
 5571|       |#elif defined(WITH_CONTIKI)
 5572|       |  coap_stop_io_process();
 5573|       |#endif
 5574|       |#ifdef WITH_LWIP
 5575|       |  coap_io_lwip_cleanup();
 5576|       |#endif /* WITH_LWIP */
 5577|  3.10k|  coap_dtls_shutdown();
 5578|       |
 5579|  3.10k|  coap_delete_upa_chain(coap_upa_client_fallback_chain);
 5580|  3.10k|  coap_upa_client_fallback_chain = NULL;
 5581|  3.10k|  coap_delete_upa_chain(coap_upa_server_mapping_chain);
 5582|  3.10k|  coap_upa_server_mapping_chain = NULL;
 5583|       |#if COAP_THREAD_SAFE
 5584|       |  coap_mutex_destroy(&m_show_pdu);
 5585|       |  coap_mutex_destroy(&m_log_impl);
 5586|       |  coap_mutex_destroy(&m_io_threads);
 5587|       |#endif /* COAP_THREAD_SAFE */
 5588|       |
 5589|  3.10k|  coap_debug_reset();
 5590|  3.10k|}

coap_dtls_is_supported:
  191|      4|coap_dtls_is_supported(void) {
  192|      4|  if (SSLeay() < 0x10100000L) {
  ------------------
  |  Branch (192:7): [True: 0, False: 4]
  ------------------
  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|      4|#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|      4|  if (SSLeay() < 0x10101000L) {
  ------------------
  |  Branch (204:7): [True: 0, False: 4]
  ------------------
  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|      4|#endif /* OPENSSL_VERSION_NUMBER >= 0x10101000L */
  209|      4|  return 1;
  210|      4|}
coap_tls_is_supported:
  213|      3|coap_tls_is_supported(void) {
  214|      3|#if !COAP_DISABLE_TCP
  215|      3|  if (SSLeay() < 0x10100000L) {
  ------------------
  |  Branch (215:7): [True: 0, False: 3]
  ------------------
  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|      3|#if OPENSSL_VERSION_NUMBER >= 0x10101000L
  220|      3|  if (SSLeay() < 0x10101000L) {
  ------------------
  |  Branch (220:7): [True: 0, False: 3]
  ------------------
  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|      3|#endif /* OPENSSL_VERSION_NUMBER >= 0x10101000L */
  225|      3|  return 1;
  226|       |#else /* COAP_DISABLE_TCP */
  227|       |  return 0;
  228|       |#endif /* COAP_DISABLE_TCP */
  229|      3|}
coap_dtls_startup:
  304|  3.10k|coap_dtls_startup(void) {
  305|  3.10k|  SSL_load_error_strings();
  306|  3.10k|  SSL_library_init();
  307|  3.10k|#if OPENSSL_VERSION_NUMBER < 0x40000000L
  308|       |  ENGINE_load_dynamic();
  309|  3.10k|#endif /* OPENSSL_VERSION_NUMBER < 0x40000000L */
  310|  3.10k|}
coap_dtls_shutdown:
  313|  3.10k|coap_dtls_shutdown(void) {
  314|  3.10k|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  315|  3.10k|  if (pkcs11_engine) {
  ------------------
  |  Branch (315:7): [True: 0, False: 3.10k]
  ------------------
  316|       |    /* Release the functional reference from ENGINE_init() */
  317|      0|    ENGINE_finish(pkcs11_engine);
  318|      0|    pkcs11_engine = NULL;
  319|      0|  }
  320|  3.10k|  if (defined_engine) {
  ------------------
  |  Branch (320:7): [True: 0, False: 3.10k]
  ------------------
  321|       |    /* Release the functional reference from ENGINE_init() */
  322|      0|    ENGINE_finish(defined_engine);
  323|      0|    defined_engine = NULL;
  324|      0|  }
  325|       |#elif OPENSSL_VERSION_NUMBER < 0x40000000L
  326|       |  pkcs11_engine = NULL;
  327|       |  defined_engine = NULL;
  328|       |#endif /* OPENSSL_VERSION_NUMBER >= 0x30000000L && < 0x40000000L */
  329|       |  ERR_free_strings();
  ------------------
  |  Branch (329:3): [Folded, False: 3.10k]
  ------------------
  330|  3.10k|  coap_dtls_set_log_level(COAP_LOG_EMERG);
  331|  3.10k|}
coap_dtls_set_log_level:
  590|  3.10k|coap_dtls_set_log_level(coap_log_t level) {
  591|  3.10k|  dtls_log_level = level;
  592|  3.10k|}

coap_opt_parse:
   41|  51.1M|coap_opt_parse(const coap_opt_t *opt, size_t length, coap_option_t *result) {
   42|       |
   43|  51.1M|  const coap_opt_t *opt_start = opt; /* store where parsing starts  */
   44|       |
   45|  51.1M|  assert(opt);
  ------------------
  |  Branch (45:3): [True: 51.1M, False: 0]
  ------------------
   46|  51.1M|  assert(result);
  ------------------
  |  Branch (46:3): [True: 51.1M, False: 0]
  ------------------
   47|       |
   48|  51.1M|  if (length < 1)
  ------------------
  |  Branch (48:7): [True: 4.59k, False: 51.1M]
  ------------------
   49|  4.59k|    return 0;
   50|       |
   51|  51.1M|  result->delta = (*opt & 0xf0) >> 4;
   52|  51.1M|  result->length = *opt & 0x0f;
   53|       |
   54|  51.1M|  switch (result->delta) {
   55|    534|  case 15:
  ------------------
  |  Branch (55:3): [True: 534, False: 51.1M]
  ------------------
   56|    534|    if (*opt != COAP_PAYLOAD_START) {
  ------------------
  |  |   96|    534|#define COAP_PAYLOAD_START 0xFF /* payload marker */
  ------------------
  |  Branch (56:9): [True: 177, False: 357]
  ------------------
   57|    177|      coap_log_debug("ignored reserved option delta 15\n");
  ------------------
  |  |  126|    177|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|    177|#define coap_log(level, ...) do { \
  |  |  |  |  291|    177|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 177]
  |  |  |  |  ------------------
  |  |  |  |  292|    177|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|    177|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 177]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   58|    177|    }
   59|    534|    return 0;
   60|  1.33k|  case 14:
  ------------------
  |  Branch (60:3): [True: 1.33k, False: 51.1M]
  ------------------
   61|       |    /* Handle two-byte value: First, the MSB + 269 is stored as delta value.
   62|       |     * After that, the option pointer is advanced to the LSB which is handled
   63|       |     * just like case delta == 13. */
   64|  1.33k|    ADVANCE_OPT_CHECK(opt,length,1);
  ------------------
  |  |   34|  1.33k|#define ADVANCE_OPT_CHECK(o,e,step) do { \
  |  |   35|  1.33k|    ADVANCE_OPT(o,e,step);               \
  |  |  ------------------
  |  |  |  |   22|  1.33k|#define ADVANCE_OPT(o,e,step) if ((e) < step) {           \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (22:35): [True: 0, False: 1.33k]
  |  |  |  |  ------------------
  |  |  |  |   23|      0|    coap_log_debug("cannot advance opt past end\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |  126|      0|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __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]
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |   24|      0|    return 0;                                             \
  |  |  |  |   25|  1.33k|  } else {                                                \
  |  |  |  |   26|  1.33k|    (e) -= step;                                          \
  |  |  |  |   27|  1.33k|    (o) = ((o)) + step;                                   \
  |  |  |  |   28|  1.33k|  }
  |  |  ------------------
  |  |   36|  1.33k|    if ((e) < 1)                         \
  |  |  ------------------
  |  |  |  Branch (36:9): [True: 63, False: 1.27k]
  |  |  ------------------
  |  |   37|  1.33k|      return 0;                          \
  |  |   38|  1.33k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (38:12): [Folded, False: 1.27k]
  |  |  ------------------
  ------------------
   65|  1.27k|    result->delta = ((*opt & 0xff) << 8) + 269;
   66|  1.27k|    if (result->delta < 269) {
  ------------------
  |  Branch (66:9): [True: 12, False: 1.26k]
  ------------------
   67|     12|      coap_log_debug("delta too large\n");
  ------------------
  |  |  126|     12|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     12|#define coap_log(level, ...) do { \
  |  |  |  |  291|     12|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 12]
  |  |  |  |  ------------------
  |  |  |  |  292|     12|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     12|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 12]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   68|     12|      return 0;
   69|     12|    }
   70|       |  /* fall through */
   71|  6.20k|  case 13:
  ------------------
  |  Branch (71:3): [True: 4.94k, False: 51.1M]
  ------------------
   72|  6.20k|    ADVANCE_OPT_CHECK(opt,length,1);
  ------------------
  |  |   34|  6.20k|#define ADVANCE_OPT_CHECK(o,e,step) do { \
  |  |   35|  6.20k|    ADVANCE_OPT(o,e,step);               \
  |  |  ------------------
  |  |  |  |   22|  6.20k|#define ADVANCE_OPT(o,e,step) if ((e) < step) {           \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (22:35): [True: 0, False: 6.20k]
  |  |  |  |  ------------------
  |  |  |  |   23|      0|    coap_log_debug("cannot advance opt past end\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |  126|      0|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __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]
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |   24|      0|    return 0;                                             \
  |  |  |  |   25|  6.20k|  } else {                                                \
  |  |  |  |   26|  6.20k|    (e) -= step;                                          \
  |  |  |  |   27|  6.20k|    (o) = ((o)) + step;                                   \
  |  |  |  |   28|  6.20k|  }
  |  |  ------------------
  |  |   36|  6.20k|    if ((e) < 1)                         \
  |  |  ------------------
  |  |  |  Branch (36:9): [True: 75, False: 6.13k]
  |  |  ------------------
  |  |   37|  6.20k|      return 0;                          \
  |  |   38|  6.20k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (38:12): [Folded, False: 6.13k]
  |  |  ------------------
  ------------------
   73|  6.13k|    result->delta += *opt & 0xff;
   74|  6.13k|    break;
   75|       |
   76|  51.1M|  default:
  ------------------
  |  Branch (76:3): [True: 51.1M, False: 6.81k]
  ------------------
   77|  51.1M|    ;
   78|  51.1M|  }
   79|       |
   80|  51.1M|  switch (result->length) {
   81|    111|  case 15:
  ------------------
  |  Branch (81:3): [True: 111, False: 51.1M]
  ------------------
   82|    111|    coap_log_debug("found reserved option length 15\n");
  ------------------
  |  |  126|    111|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|    111|#define coap_log(level, ...) do { \
  |  |  |  |  291|    111|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 111]
  |  |  |  |  ------------------
  |  |  |  |  292|    111|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|    111|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 111]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   83|    111|    return 0;
   84|  4.85k|  case 14:
  ------------------
  |  Branch (84:3): [True: 4.85k, False: 51.1M]
  ------------------
   85|       |    /* Handle two-byte value: First, the MSB + 269 is stored as delta value.
   86|       |     * After that, the option pointer is advanced to the LSB which is handled
   87|       |     * just like case delta == 13. */
   88|  4.85k|    ADVANCE_OPT_CHECK(opt,length,1);
  ------------------
  |  |   34|  4.85k|#define ADVANCE_OPT_CHECK(o,e,step) do { \
  |  |   35|  4.85k|    ADVANCE_OPT(o,e,step);               \
  |  |  ------------------
  |  |  |  |   22|  4.85k|#define ADVANCE_OPT(o,e,step) if ((e) < step) {           \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (22:35): [True: 0, False: 4.85k]
  |  |  |  |  ------------------
  |  |  |  |   23|      0|    coap_log_debug("cannot advance opt past end\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |  126|      0|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __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]
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |   24|      0|    return 0;                                             \
  |  |  |  |   25|  4.85k|  } else {                                                \
  |  |  |  |   26|  4.85k|    (e) -= step;                                          \
  |  |  |  |   27|  4.85k|    (o) = ((o)) + step;                                   \
  |  |  |  |   28|  4.85k|  }
  |  |  ------------------
  |  |   36|  4.85k|    if ((e) < 1)                         \
  |  |  ------------------
  |  |  |  Branch (36:9): [True: 36, False: 4.82k]
  |  |  ------------------
  |  |   37|  4.85k|      return 0;                          \
  |  |   38|  4.85k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (38:12): [Folded, False: 4.82k]
  |  |  ------------------
  ------------------
   89|  4.82k|    result->length = ((*opt & 0xff) << 8) + 269;
   90|       |  /* fall through */
   91|  42.9k|  case 13:
  ------------------
  |  Branch (91:3): [True: 38.1k, False: 51.1M]
  ------------------
   92|  42.9k|    ADVANCE_OPT_CHECK(opt,length,1);
  ------------------
  |  |   34|  42.9k|#define ADVANCE_OPT_CHECK(o,e,step) do { \
  |  |   35|  42.9k|    ADVANCE_OPT(o,e,step);               \
  |  |  ------------------
  |  |  |  |   22|  42.9k|#define ADVANCE_OPT(o,e,step) if ((e) < step) {           \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (22:35): [True: 0, False: 42.9k]
  |  |  |  |  ------------------
  |  |  |  |   23|      0|    coap_log_debug("cannot advance opt past end\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |  126|      0|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __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]
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |   24|      0|    return 0;                                             \
  |  |  |  |   25|  42.9k|  } else {                                                \
  |  |  |  |   26|  42.9k|    (e) -= step;                                          \
  |  |  |  |   27|  42.9k|    (o) = ((o)) + step;                                   \
  |  |  |  |   28|  42.9k|  }
  |  |  ------------------
  |  |   36|  42.9k|    if ((e) < 1)                         \
  |  |  ------------------
  |  |  |  Branch (36:9): [True: 57, False: 42.9k]
  |  |  ------------------
  |  |   37|  42.9k|      return 0;                          \
  |  |   38|  42.9k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (38:12): [Folded, False: 42.9k]
  |  |  ------------------
  ------------------
   93|  42.9k|    result->length += *opt & 0xff;
   94|  42.9k|    break;
   95|       |
   96|  51.1M|  default:
  ------------------
  |  Branch (96:3): [True: 51.1M, False: 43.1k]
  ------------------
   97|  51.1M|    ;
   98|  51.1M|  }
   99|       |
  100|       |  /* ADVANCE_OPT() is correct here */
  101|  51.1M|  ADVANCE_OPT(opt,length,1);
  ------------------
  |  |   22|  51.1M|#define ADVANCE_OPT(o,e,step) if ((e) < step) {           \
  |  |  ------------------
  |  |  |  Branch (22:35): [True: 0, False: 51.1M]
  |  |  ------------------
  |  |   23|      0|    coap_log_debug("cannot advance opt past end\n"); \
  |  |  ------------------
  |  |  |  |  126|      0|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __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]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   24|      0|    return 0;                                             \
  |  |   25|  51.1M|  } else {                                                \
  |  |   26|  51.1M|    (e) -= step;                                          \
  |  |   27|  51.1M|    (o) = ((o)) + step;                                   \
  |  |   28|  51.1M|  }
  ------------------
  102|       |  /* opt now points to value, if present */
  103|       |
  104|  51.1M|  result->value = opt;
  105|  51.1M|  if (length < result->length) {
  ------------------
  |  Branch (105:7): [True: 774, False: 51.1M]
  ------------------
  106|    774|    coap_log_debug("invalid option length\n");
  ------------------
  |  |  126|    774|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|    774|#define coap_log(level, ...) do { \
  |  |  |  |  291|    774|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 774]
  |  |  |  |  ------------------
  |  |  |  |  292|    774|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|    774|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 774]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  107|    774|    return 0;
  108|    774|  }
  109|       |
  110|  51.1M|#undef ADVANCE_OPT
  111|  51.1M|#undef ADVANCE_OPT_CHECK
  112|       |
  113|  51.1M|  return (opt + result->length) - opt_start;
  114|  51.1M|}
coap_option_iterator_init:
  118|  7.14k|                          const coap_opt_filter_t *filter) {
  119|  7.14k|  assert(pdu);
  ------------------
  |  Branch (119:3): [True: 7.14k, False: 0]
  ------------------
  120|  7.14k|  assert(pdu->token);
  ------------------
  |  Branch (120:3): [True: 7.14k, False: 0]
  ------------------
  121|  7.14k|  assert(oi);
  ------------------
  |  Branch (121:3): [True: 7.14k, False: 0]
  ------------------
  122|       |
  123|  7.14k|  memset(oi, 0, sizeof(coap_opt_iterator_t));
  124|       |
  125|  7.14k|  oi->next_option = pdu->token + pdu->e_token_length;
  126|  7.14k|  if (pdu->token + pdu->used_size <= oi->next_option) {
  ------------------
  |  Branch (126:7): [True: 215, False: 6.93k]
  ------------------
  127|    215|    oi->bad = 1;
  128|    215|    return NULL;
  129|    215|  }
  130|       |
  131|  6.93k|  oi->length = pdu->used_size - pdu->e_token_length;
  132|       |
  133|  6.93k|  if (filter) {
  ------------------
  |  Branch (133:7): [True: 6.93k, False: 0]
  ------------------
  134|  6.93k|    memcpy(&oi->filter, filter, sizeof(coap_opt_filter_t));
  135|  6.93k|    oi->filtered = 1;
  136|  6.93k|  }
  137|  6.93k|  return oi;
  138|  7.14k|}
coap_option_next:
  153|  8.31M|coap_option_next(coap_opt_iterator_t *oi) {
  154|  8.31M|  coap_option_t option;
  155|  8.31M|  coap_opt_t *current_opt = NULL;
  156|  8.31M|  size_t optsize;
  157|       |
  158|  8.31M|  assert(oi);
  ------------------
  |  Branch (158:3): [True: 8.31M, False: 0]
  ------------------
  159|       |
  160|  8.31M|  if (opt_finished(oi))
  ------------------
  |  Branch (160:7): [True: 1.63k, False: 8.31M]
  ------------------
  161|  1.63k|    return NULL;
  162|       |
  163|  28.9M|  while (1) {
  ------------------
  |  Branch (163:10): [True: 28.9M, Folded]
  ------------------
  164|       |    /* oi->next_option always points to the next option to deliver; as
  165|       |     * opt_finished() filters out any bad conditions, we can assume that
  166|       |     * oi->next_option is valid. */
  167|  28.9M|    current_opt = oi->next_option;
  168|       |
  169|       |    /*
  170|       |     * Advance internal pointer to next option.
  171|       |     * optsize will be 0 when no more options
  172|       |     */
  173|  28.9M|    optsize = coap_opt_parse(oi->next_option, oi->length, &option);
  174|  28.9M|    if (optsize) {
  ------------------
  |  Branch (174:9): [True: 28.9M, False: 4.94k]
  ------------------
  175|  28.9M|      assert(optsize <= oi->length);
  ------------------
  |  Branch (175:7): [True: 28.9M, False: 0]
  ------------------
  176|       |
  177|  28.9M|      oi->next_option += optsize;
  178|  28.9M|      oi->length -= optsize;
  179|       |
  180|  28.9M|      oi->number += option.delta;
  181|  28.9M|    } else {                        /* current option is malformed */
  182|  4.94k|      oi->bad = 1;
  183|  4.94k|      return NULL;
  184|  4.94k|    }
  185|       |
  186|       |    /* Exit the while loop when:
  187|       |     *   - no filtering is done at all
  188|       |     *   - the filter matches for the current option
  189|       |     */
  190|  28.9M|    if (!oi->filtered ||
  ------------------
  |  Branch (190:9): [True: 0, False: 28.9M]
  ------------------
  191|  28.9M|        coap_option_filter_get(&oi->filter, oi->number) > 0)
  ------------------
  |  Branch (191:9): [True: 8.30M, False: 20.6M]
  ------------------
  192|  8.30M|      break;
  193|  28.9M|  }
  194|       |
  195|  8.30M|  return current_opt;
  196|  8.31M|}
coap_check_option:
  200|  3.20k|                  coap_opt_iterator_t *oi) {
  201|  3.20k|  coap_opt_filter_t f;
  202|       |
  203|  3.20k|  coap_option_filter_clear(&f);
  204|  3.20k|  coap_option_filter_set(&f, number);
  205|       |
  206|  3.20k|  coap_option_iterator_init(pdu, oi, &f);
  207|       |
  208|  3.20k|  return coap_option_next(oi);
  209|  3.20k|}
coap_opt_length:
  212|  30.5M|coap_opt_length(const coap_opt_t *opt) {
  213|  30.5M|  uint32_t length;
  214|       |
  215|  30.5M|  length = *opt & 0x0f;
  216|  30.5M|  switch (*opt & 0xf0) {
  217|      0|  case 0xf0:
  ------------------
  |  Branch (217:3): [True: 0, False: 30.5M]
  ------------------
  218|      0|    coap_log_debug("illegal option delta\n");
  ------------------
  |  |  126|      0|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __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|    570|  case 0xe0:
  ------------------
  |  Branch (220:3): [True: 570, False: 30.5M]
  ------------------
  221|    570|    ++opt;
  222|       |  /* fall through */
  223|       |  /* to skip another byte */
  224|  3.19k|  case 0xd0:
  ------------------
  |  Branch (224:3): [True: 2.62k, False: 30.5M]
  ------------------
  225|  3.19k|    ++opt;
  226|       |  /* fall through */
  227|       |  /* to skip another byte */
  228|  30.5M|  default:
  ------------------
  |  Branch (228:3): [True: 30.5M, False: 3.19k]
  ------------------
  229|  30.5M|    ++opt;
  230|  30.5M|  }
  231|       |
  232|  30.5M|  switch (length) {
  233|      0|  case 0x0f:
  ------------------
  |  Branch (233:3): [True: 0, False: 30.5M]
  ------------------
  234|      0|    coap_log_debug("illegal option length\n");
  ------------------
  |  |  126|      0|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  235|      0|    return 0;
  236|  3.83k|  case 0x0e:
  ------------------
  |  Branch (236:3): [True: 3.83k, False: 30.5M]
  ------------------
  237|  3.83k|    length = (*opt++ << 8) + 269;
  238|       |  /* fall through */
  239|  39.9k|  case 0x0d:
  ------------------
  |  Branch (239:3): [True: 36.1k, False: 30.5M]
  ------------------
  240|  39.9k|    length += *opt++;
  241|  39.9k|    break;
  242|  30.5M|  default:
  ------------------
  |  Branch (242:3): [True: 30.5M, False: 39.9k]
  ------------------
  243|  30.5M|    ;
  244|  30.5M|  }
  245|  30.5M|  return length;
  246|  30.5M|}
coap_opt_value:
  249|  30.5M|coap_opt_value(const coap_opt_t *opt) {
  250|  30.5M|  size_t ofs = 1;
  251|       |
  252|  30.5M|  switch (*opt & 0xf0) {
  253|      0|  case 0xf0:
  ------------------
  |  Branch (253:3): [True: 0, False: 30.5M]
  ------------------
  254|      0|    coap_log_debug("illegal option delta\n");
  ------------------
  |  |  126|      0|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  255|      0|    return 0;
  256|    570|  case 0xe0:
  ------------------
  |  Branch (256:3): [True: 570, False: 30.5M]
  ------------------
  257|    570|    ++ofs;
  258|       |  /* fall through */
  259|  3.19k|  case 0xd0:
  ------------------
  |  Branch (259:3): [True: 2.62k, False: 30.5M]
  ------------------
  260|  3.19k|    ++ofs;
  261|  3.19k|    break;
  262|  30.5M|  default:
  ------------------
  |  Branch (262:3): [True: 30.5M, False: 3.19k]
  ------------------
  263|  30.5M|    ;
  264|  30.5M|  }
  265|       |
  266|  30.5M|  switch (*opt & 0x0f) {
  267|      0|  case 0x0f:
  ------------------
  |  Branch (267:3): [True: 0, False: 30.5M]
  ------------------
  268|      0|    coap_log_debug("illegal option length\n");
  ------------------
  |  |  126|      0|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  269|      0|    return 0;
  270|  3.83k|  case 0x0e:
  ------------------
  |  Branch (270:3): [True: 3.83k, False: 30.5M]
  ------------------
  271|  3.83k|    ++ofs;
  272|       |  /* fall through */
  273|  39.9k|  case 0x0d:
  ------------------
  |  Branch (273:3): [True: 36.1k, False: 30.5M]
  ------------------
  274|  39.9k|    ++ofs;
  275|  39.9k|    break;
  276|  30.5M|  default:
  ------------------
  |  Branch (276:3): [True: 30.5M, False: 39.9k]
  ------------------
  277|  30.5M|    ;
  278|  30.5M|  }
  279|       |
  280|  30.5M|  return (const uint8_t *)opt + ofs;
  281|  30.5M|}
coap_option_filter_clear:
  491|  8.90k|coap_option_filter_clear(coap_opt_filter_t *filter) {
  492|  8.90k|  memset(filter, 0, sizeof(coap_opt_filter_t));
  493|  8.90k|}
coap_option_filter_set:
  496|  4.52M|coap_option_filter_set(coap_opt_filter_t *filter, coap_option_num_t option) {
  497|  4.52M|  return coap_option_filter_op(filter, option, FILTER_SET);
  498|  4.52M|}
coap_option_filter_get:
  506|  28.9M|coap_option_filter_get(coap_opt_filter_t *filter, coap_option_num_t option) {
  507|  28.9M|  return coap_option_filter_op(filter, option, FILTER_GET);
  508|  28.9M|}
coap_option.c:opt_finished:
  141|  8.31M|opt_finished(coap_opt_iterator_t *oi) {
  142|  8.31M|  assert(oi);
  ------------------
  |  Branch (142:3): [True: 8.31M, False: 0]
  ------------------
  143|       |
  144|  8.31M|  if (oi->bad || oi->length == 0 ||
  ------------------
  |  Branch (144:7): [True: 215, False: 8.31M]
  |  Branch (144:18): [True: 1.15k, False: 8.31M]
  ------------------
  145|  8.31M|      !oi->next_option || *oi->next_option == COAP_PAYLOAD_START) {
  ------------------
  |  |   96|  8.31M|#define COAP_PAYLOAD_START 0xFF /* payload marker */
  ------------------
  |  Branch (145:7): [True: 0, False: 8.31M]
  |  Branch (145:27): [True: 265, False: 8.31M]
  ------------------
  146|  1.63k|    oi->bad = 1;
  147|  1.63k|  }
  148|       |
  149|  8.31M|  return oi->bad;
  150|  8.31M|}
coap_option.c:coap_option_filter_op:
  433|  33.4M|                      enum filter_op_t op) {
  434|  33.4M|  size_t lindex = 0;
  435|  33.4M|  coap_opt_filter_t *of = filter;
  436|  33.4M|  uint16_t nr, mask = 0;
  437|       |
  438|  33.4M|  if (is_long_option(number)) {
  ------------------
  |  Branch (438:7): [True: 819k, False: 32.6M]
  ------------------
  439|   819k|    mask = LONG_MASK;
  ------------------
  |  |  398|   819k|#define LONG_MASK ((1 << COAP_OPT_FILTER_LONG) - 1)
  |  |  ------------------
  |  |  |  |  208|   819k|#define COAP_OPT_FILTER_LONG  2
  |  |  ------------------
  ------------------
  440|       |
  441|  1.01M|    for (nr = 1; lindex < COAP_OPT_FILTER_LONG; nr <<= 1, lindex++) {
  ------------------
  |  |  208|  1.01M|#define COAP_OPT_FILTER_LONG  2
  ------------------
  |  Branch (441:18): [True: 930k, False: 80.1k]
  ------------------
  442|       |
  443|   930k|      if (((of->mask & nr) > 0) && (of->long_opts[lindex] == number)) {
  ------------------
  |  Branch (443:11): [True: 758k, False: 171k]
  |  Branch (443:36): [True: 739k, False: 18.5k]
  ------------------
  444|   739k|        if (op == FILTER_CLEAR) {
  ------------------
  |  Branch (444:13): [True: 0, False: 739k]
  ------------------
  445|      0|          of->mask &= ~nr;
  446|      0|        }
  447|       |
  448|   739k|        return 1;
  449|   739k|      }
  450|   930k|    }
  451|  32.6M|  } else {
  452|  32.6M|    mask = SHORT_MASK;
  ------------------
  |  |  400|  32.6M|  (~LONG_MASK & ((1 << (COAP_OPT_FILTER_LONG + COAP_OPT_FILTER_SHORT)) - 1))
  |  |  ------------------
  |  |  |  |  398|  32.6M|#define LONG_MASK ((1 << COAP_OPT_FILTER_LONG) - 1)
  |  |  |  |  ------------------
  |  |  |  |  |  |  208|  32.6M|#define COAP_OPT_FILTER_LONG  2
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                 (~LONG_MASK & ((1 << (COAP_OPT_FILTER_LONG + COAP_OPT_FILTER_SHORT)) - 1))
  |  |  ------------------
  |  |  |  |  208|  32.6M|#define COAP_OPT_FILTER_LONG  2
  |  |  ------------------
  |  |                 (~LONG_MASK & ((1 << (COAP_OPT_FILTER_LONG + COAP_OPT_FILTER_SHORT)) - 1))
  |  |  ------------------
  |  |  |  |  200|  32.6M|#define COAP_OPT_FILTER_SHORT 6
  |  |  ------------------
  ------------------
  453|       |
  454|   215M|    for (nr = 1 << COAP_OPT_FILTER_LONG; lindex < COAP_OPT_FILTER_SHORT;
  ------------------
  |  |  208|  32.6M|#define COAP_OPT_FILTER_LONG  2
  ------------------
                  for (nr = 1 << COAP_OPT_FILTER_LONG; lindex < COAP_OPT_FILTER_SHORT;
  ------------------
  |  |  200|   215M|#define COAP_OPT_FILTER_SHORT 6
  ------------------
  |  Branch (454:42): [True: 194M, False: 20.5M]
  ------------------
  455|   194M|         nr <<= 1, lindex++) {
  456|       |
  457|   194M|      if (((of->mask & nr) > 0) && (of->short_opts[lindex] == (number & 0xff))) {
  ------------------
  |  Branch (457:11): [True: 32.6M, False: 161M]
  |  Branch (457:36): [True: 12.0M, False: 20.5M]
  ------------------
  458|  12.0M|        if (op == FILTER_CLEAR) {
  ------------------
  |  Branch (458:13): [True: 0, False: 12.0M]
  ------------------
  459|      0|          of->mask &= ~nr;
  460|      0|        }
  461|       |
  462|  12.0M|        return 1;
  463|  12.0M|      }
  464|   194M|    }
  465|  32.6M|  }
  466|       |
  467|       |  /* number was not found, so there is nothing to do if op is CLEAR or GET */
  468|  20.6M|  if ((op == FILTER_CLEAR) || (op == FILTER_GET)) {
  ------------------
  |  Branch (468:7): [True: 0, False: 20.6M]
  |  Branch (468:31): [True: 20.6M, False: 23.4k]
  ------------------
  469|  20.6M|    return 0;
  470|  20.6M|  }
  471|       |
  472|       |  /* handle FILTER_SET: */
  473|       |
  474|  23.4k|  lindex = coap_fls(~of->mask & mask);
  475|  23.4k|  if (!lindex) {
  ------------------
  |  Branch (475:7): [True: 15.4k, False: 7.98k]
  ------------------
  476|  15.4k|    return 0;
  477|  15.4k|  }
  478|       |
  479|  7.98k|  if (is_long_option(number)) {
  ------------------
  |  Branch (479:7): [True: 242, False: 7.73k]
  ------------------
  480|    242|    of->long_opts[lindex - 1] = number;
  481|  7.73k|  } else {
  482|  7.73k|    of->short_opts[lindex - COAP_OPT_FILTER_LONG - 1] = (uint8_t)number;
  ------------------
  |  |  208|  7.73k|#define COAP_OPT_FILTER_LONG  2
  ------------------
  483|  7.73k|  }
  484|       |
  485|  7.98k|  of->mask |= 1 << (lindex - 1);
  486|       |
  487|  7.98k|  return 1;
  488|  23.4k|}
coap_option.c:is_long_option:
  404|  33.4M|is_long_option(coap_option_num_t number) {
  405|  33.4M|  return number > 255;
  406|  33.4M|}

coap_pdu_clear:
   47|  3.10k|coap_pdu_clear(coap_pdu_t *pdu, size_t size) {
   48|  3.10k|  assert(pdu);
  ------------------
  |  Branch (48:3): [True: 3.10k, False: 0]
  ------------------
   49|  3.10k|  assert(pdu->token);
  ------------------
  |  Branch (49:3): [True: 3.10k, False: 0]
  ------------------
   50|  3.10k|  assert(pdu->max_hdr_size >= COAP_PDU_MAX_UDP_HEADER_SIZE);
  ------------------
  |  Branch (50:3): [True: 3.10k, False: 0]
  ------------------
   51|  3.10k|  if (pdu->alloc_size > size)
  ------------------
  |  Branch (51:7): [True: 0, False: 3.10k]
  ------------------
   52|      0|    pdu->alloc_size = size;
   53|  3.10k|  pdu->type = 0;
   54|  3.10k|  pdu->code = 0;
   55|  3.10k|  pdu->ref = 0;
   56|  3.10k|  pdu->hdr_size = 0;
   57|  3.10k|  pdu->actual_token.length = 0;
   58|  3.10k|  pdu->e_token_length = 0;
   59|  3.10k|  pdu->crit_opt = 0;
   60|  3.10k|  pdu->mid = 0;
   61|  3.10k|  pdu->max_opt = 0;
   62|  3.10k|  pdu->max_size = size;
   63|  3.10k|  pdu->used_size = 0;
   64|  3.10k|  pdu->data = NULL;
   65|  3.10k|  pdu->body_data = NULL;
   66|  3.10k|  pdu->body_length = 0;
   67|  3.10k|  pdu->body_offset = 0;
   68|  3.10k|  pdu->body_total = 0;
   69|  3.10k|  pdu->lg_xmit = NULL;
   70|  3.10k|  pdu->session = NULL;
   71|       |  pdu->data_free = NULL;
   72|  3.10k|}
coap_pdu_init:
  105|  3.10k|              size_t size) {
  106|  3.10k|  coap_pdu_t *pdu;
  107|       |
  108|  3.10k|#ifndef RIOT_VERSION
  109|  3.10k|  assert(type <= 0x3);
  ------------------
  |  Branch (109:3): [True: 3.10k, False: 0]
  ------------------
  110|  3.10k|  assert(code <= 0xff);
  ------------------
  |  Branch (110:3): [True: 3.10k, False: 0]
  ------------------
  111|  3.10k|  assert(mid >= 0 && mid <= 0xffff);
  ------------------
  |  Branch (111:3): [True: 3.10k, False: 0]
  |  Branch (111:3): [True: 3.10k, False: 0]
  ------------------
  112|  3.10k|#endif /* RIOT_VERSION */
  113|       |
  114|       |#if defined(WITH_LWIP) && MEMP_USE_CUSTOM_POOLS
  115|       |#if MEMP_STATS
  116|       |  /* Reserve 1 PDU for a response packet */
  117|       |  if (memp_pools[MEMP_COAP_PDU]->stats->used + 1 >=
  118|       |      memp_pools[MEMP_COAP_PDU]->stats->avail) {
  119|       |    memp_pools[MEMP_COAP_PDU]->stats->err++;
  120|       |    return NULL;
  121|       |  }
  122|       |#endif /* MEMP_STATS */
  123|       |#endif /* LWIP && MEMP_USE_CUSTOM_POOLS */
  124|  3.10k|  pdu = coap_malloc_type(COAP_PDU, sizeof(coap_pdu_t));
  125|  3.10k|  if (!pdu)
  ------------------
  |  Branch (125:7): [True: 0, False: 3.10k]
  ------------------
  126|      0|    return NULL;
  127|       |
  128|       |#if COAP_DEFAULT_MAX_PDU_RX_SIZE <= COAP_MAX_MESSAGE_SIZE_TCP16
  129|       |  /* on TCP, the CoAP header will also have a maximum length of 4 bytes */
  130|       |  pdu->max_hdr_size = COAP_PDU_MAX_UDP_HEADER_SIZE;
  131|       |#else
  132|  3.10k|  pdu->max_hdr_size = COAP_PDU_MAX_TCP_HEADER_SIZE;
  ------------------
  |  |  108|  3.10k|#define COAP_PDU_MAX_TCP_HEADER_SIZE 6
  ------------------
  133|  3.10k|#endif
  134|  3.10k|  if (size > ((size_t)COAP_DEFAULT_MAX_PDU_RX_SIZE - pdu->max_hdr_size)) {
  ------------------
  |  |   84|  3.10k|#define COAP_DEFAULT_MAX_PDU_RX_SIZE (8UL*1024*1024+256)
  ------------------
  |  Branch (134:7): [True: 0, False: 3.10k]
  ------------------
  135|      0|    coap_free_type(COAP_PDU, pdu);
  136|      0|    return NULL;
  137|      0|  }
  138|       |
  139|  3.10k|  pdu->alloc_size = min(size, COAP_DEFAULT_MTU);
  ------------------
  |  |   37|  3.10k|#define min(a,b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (37:19): [True: 2.54k, False: 562]
  |  |  ------------------
  ------------------
  140|       |#ifdef WITH_LWIP
  141|       |  pdu->pbuf = pbuf_alloc(PBUF_TRANSPORT, pdu->alloc_size + pdu->max_hdr_size,
  142|       |                         PBUF_RAM);
  143|       |  if (pdu->pbuf == NULL) {
  144|       |    coap_free_type(COAP_PDU, pdu);
  145|       |    return NULL;
  146|       |  }
  147|       |  pdu->token = (uint8_t *)pdu->pbuf->payload + pdu->max_hdr_size;
  148|       |#else /* ! WITH_LWIP */
  149|  3.10k|  uint8_t *buf;
  150|  3.10k|  buf = coap_malloc_type(COAP_PDU_BUF, pdu->alloc_size + pdu->max_hdr_size);
  151|  3.10k|  if (buf == NULL) {
  ------------------
  |  Branch (151:7): [True: 0, False: 3.10k]
  ------------------
  152|      0|    coap_free_type(COAP_PDU, pdu);
  153|      0|    return NULL;
  154|      0|  }
  155|  3.10k|  pdu->token = buf + pdu->max_hdr_size;
  156|  3.10k|#endif /* ! WITH_LWIP */
  157|  3.10k|  coap_pdu_clear(pdu, size);
  158|  3.10k|  pdu->mid = mid;
  159|  3.10k|  pdu->type = type;
  160|  3.10k|  pdu->code = code;
  161|  3.10k|  return pdu;
  162|  3.10k|}
coap_delete_pdu:
  190|  3.10k|coap_delete_pdu(coap_pdu_t *pdu) {
  191|  3.10k|  coap_lock_lock(return);
  192|  3.10k|  coap_delete_pdu_lkd(pdu);
  193|  3.10k|  coap_lock_unlock();
  194|  3.10k|}
coap_delete_pdu_lkd:
  197|  3.10k|coap_delete_pdu_lkd(coap_pdu_t *pdu) {
  198|  3.10k|  if (pdu != NULL) {
  ------------------
  |  Branch (198:7): [True: 3.10k, False: 0]
  ------------------
  199|  3.10k|    if (pdu->ref) {
  ------------------
  |  Branch (199:9): [True: 0, False: 3.10k]
  ------------------
  200|      0|      pdu->ref--;
  201|      0|      return;
  202|      0|    }
  203|       |#ifdef WITH_LWIP
  204|       |    pbuf_free(pdu->pbuf);
  205|       |#else
  206|  3.10k|    if (pdu->token != NULL)
  ------------------
  |  Branch (206:9): [True: 3.10k, False: 0]
  ------------------
  207|  3.10k|      coap_free_type(COAP_PDU_BUF, pdu->token - pdu->max_hdr_size);
  208|  3.10k|#endif
  209|  3.10k|    coap_delete_binary(pdu->data_free);
  210|  3.10k|    coap_free_type(COAP_PDU, pdu);
  211|  3.10k|  }
  212|  3.10k|}
coap_pdu_resize:
  340|  3.10k|coap_pdu_resize(coap_pdu_t *pdu, size_t new_size) {
  341|  3.10k|  if (new_size > pdu->alloc_size) {
  ------------------
  |  Branch (341:7): [True: 559, False: 2.54k]
  ------------------
  342|       |    /* Expanding the PDU usage */
  343|    559|#if !defined(WITH_LWIP)
  344|    559|    uint8_t *new_hdr;
  345|       |#else /* WITH_LWIP */
  346|       |    struct pbuf *new_hdr;
  347|       |#endif /* WITH_LWIP */
  348|    559|    size_t offset;
  349|       |
  350|    559|    if (pdu->max_size && new_size > pdu->max_size) {
  ------------------
  |  Branch (350:9): [True: 559, False: 0]
  |  Branch (350:26): [True: 0, False: 559]
  ------------------
  351|      0|      coap_log_warn("coap_pdu_resize: pdu too big\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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  352|      0|      return 0;
  353|      0|    }
  354|    559|    if (pdu->data != NULL) {
  ------------------
  |  Branch (354:9): [True: 0, False: 559]
  ------------------
  355|      0|      assert(pdu->data > pdu->token);
  ------------------
  |  Branch (355:7): [True: 0, False: 0]
  ------------------
  356|      0|      offset = pdu->data - pdu->token;
  357|    559|    } else {
  358|    559|      offset = 0;
  359|    559|    }
  360|    559|#if !defined(WITH_LWIP)
  361|    559|    new_hdr = (uint8_t *)coap_realloc_type(COAP_PDU_BUF,
  362|    559|                                           pdu->token - pdu->max_hdr_size,
  363|    559|                                           new_size + pdu->max_hdr_size);
  364|       |#else /* WITH_LWIP */
  365|       |    new_hdr = pbuf_alloc(PBUF_TRANSPORT, new_size + pdu->max_hdr_size, PBUF_RAM);
  366|       |#endif /* WITH_LWIP */
  367|    559|    if (new_hdr == NULL) {
  ------------------
  |  Branch (367:9): [True: 0, False: 559]
  ------------------
  368|      0|      coap_log_warn("coap_pdu_resize: realloc failed\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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  369|      0|      return 0;
  370|      0|    }
  371|    559|#if !defined(WITH_LWIP)
  372|    559|    pdu->token = new_hdr + pdu->max_hdr_size;
  373|       |#else /* WITH_LWIP */
  374|       |    memcpy(new_hdr->payload, pdu->pbuf->payload, pdu->pbuf->len);
  375|       |    pbuf_free(pdu->pbuf);
  376|       |    pdu->pbuf = new_hdr;
  377|       |    pdu->token = (uint8_t *)pdu->pbuf->payload + pdu->max_hdr_size;
  378|       |#endif /* WITH_LWIP */
  379|    559|    if (offset > 0)
  ------------------
  |  Branch (379:9): [True: 0, False: 559]
  ------------------
  380|      0|      pdu->data = pdu->token + offset;
  381|    559|    else
  382|    559|      pdu->data = NULL;
  383|    559|    if (pdu->actual_token.length < COAP_TOKEN_EXT_1B_BIAS)
  ------------------
  |  |   56|    559|#define COAP_TOKEN_EXT_1B_BIAS 13
  ------------------
  |  Branch (383:9): [True: 559, False: 0]
  ------------------
  384|    559|      pdu->actual_token.s = &pdu->token[0];
  385|      0|    else if (pdu->actual_token.length < COAP_TOKEN_EXT_2B_BIAS)
  ------------------
  |  |   57|      0|#define COAP_TOKEN_EXT_2B_BIAS 269 /* 13 + 256 */
  ------------------
  |  Branch (385:14): [True: 0, False: 0]
  ------------------
  386|      0|      pdu->actual_token.s = &pdu->token[1];
  387|      0|    else
  388|      0|      pdu->actual_token.s = &pdu->token[2];
  389|    559|    pdu->alloc_size = new_size;
  390|    559|  }
  391|  3.10k|  return 1;
  392|  3.10k|}
coap_pdu_parse_header_size:
 1082|  3.10k|                           const uint8_t *data) {
 1083|  3.10k|  assert(data);
  ------------------
  |  Branch (1083:3): [True: 3.10k, False: 0]
  ------------------
 1084|  3.10k|  size_t header_size = 0;
 1085|       |
 1086|  3.10k|  if (proto == COAP_PROTO_TCP || proto==COAP_PROTO_TLS) {
  ------------------
  |  Branch (1086:7): [True: 0, False: 3.10k]
  |  Branch (1086:34): [True: 0, False: 3.10k]
  ------------------
 1087|      0|    uint8_t len = *data >> 4;
 1088|      0|    if (len < 13)
  ------------------
  |  Branch (1088:9): [True: 0, False: 0]
  ------------------
 1089|      0|      header_size = 2;
 1090|      0|    else if (len==13)
  ------------------
  |  Branch (1090:14): [True: 0, False: 0]
  ------------------
 1091|      0|      header_size = 3;
 1092|      0|    else if (len==14)
  ------------------
  |  Branch (1092:14): [True: 0, False: 0]
  ------------------
 1093|      0|      header_size = 4;
 1094|      0|    else
 1095|      0|      header_size = 6;
 1096|  3.10k|  } else if (proto == COAP_PROTO_WS || proto==COAP_PROTO_WSS) {
  ------------------
  |  Branch (1096:14): [True: 3.10k, False: 0]
  |  Branch (1096:40): [True: 0, False: 0]
  ------------------
 1097|  3.10k|    header_size = 2;
 1098|  3.10k|  } else if (proto == COAP_PROTO_UDP || proto==COAP_PROTO_DTLS) {
  ------------------
  |  Branch (1098:14): [True: 0, False: 0]
  |  Branch (1098:41): [True: 0, False: 0]
  ------------------
 1099|      0|    header_size = 4;
 1100|      0|  }
 1101|       |
 1102|  3.10k|  return header_size;
 1103|  3.10k|}
coap_pdu_parse_header:
 1165|  3.10k|coap_pdu_parse_header(coap_pdu_t *pdu, coap_proto_t proto) {
 1166|  3.10k|  uint8_t *hdr = pdu->token - pdu->hdr_size;
 1167|  3.10k|  uint8_t e_token_length;
 1168|       |
 1169|  3.10k|  if (proto == COAP_PROTO_UDP || proto == COAP_PROTO_DTLS) {
  ------------------
  |  Branch (1169:7): [True: 0, False: 3.10k]
  |  Branch (1169:34): [True: 0, False: 3.10k]
  ------------------
 1170|      0|    assert(pdu->hdr_size == 4);
  ------------------
  |  Branch (1170:5): [True: 0, False: 0]
  ------------------
 1171|      0|    if ((hdr[0] >> 6) != COAP_DEFAULT_VERSION) {
  ------------------
  |  |   35|      0|#define COAP_DEFAULT_VERSION      1 /* version of CoAP supported */
  ------------------
  |  Branch (1171:9): [True: 0, False: 0]
  ------------------
 1172|      0|      coap_log_debug("coap_pdu_parse: UDP version not supported\n");
  ------------------
  |  |  126|      0|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1173|      0|      return 0;
 1174|      0|    }
 1175|      0|    pdu->type = (hdr[0] >> 4) & 0x03;
 1176|      0|    pdu->code = hdr[1];
 1177|      0|    pdu->mid = (uint16_t)hdr[2] << 8 | hdr[3];
 1178|  3.10k|  } else if (proto == COAP_PROTO_TCP || proto == COAP_PROTO_TLS) {
  ------------------
  |  Branch (1178:14): [True: 0, False: 3.10k]
  |  Branch (1178:41): [True: 0, False: 3.10k]
  ------------------
 1179|      0|    assert(pdu->hdr_size >= 2 && pdu->hdr_size <= 6);
  ------------------
  |  Branch (1179:5): [True: 0, False: 0]
  |  Branch (1179:5): [True: 0, False: 0]
  ------------------
 1180|      0|    pdu->type = COAP_MESSAGE_CON;
 1181|      0|    pdu->code = hdr[pdu->hdr_size-1];
 1182|      0|    pdu->mid = 0;
 1183|  3.10k|  } else if (proto == COAP_PROTO_WS || proto == COAP_PROTO_WSS) {
  ------------------
  |  Branch (1183:14): [True: 3.10k, False: 0]
  |  Branch (1183:40): [True: 0, False: 0]
  ------------------
 1184|  3.10k|    assert(pdu->hdr_size == 2);
  ------------------
  |  Branch (1184:5): [True: 3.10k, False: 0]
  ------------------
 1185|  3.10k|    pdu->type = COAP_MESSAGE_CON;
 1186|  3.10k|    pdu->code = hdr[pdu->hdr_size-1];
 1187|  3.10k|    pdu->mid = 0;
 1188|  3.10k|  } else {
 1189|      0|    coap_log_debug("coap_pdu_parse: unsupported protocol\n");
  ------------------
  |  |  126|      0|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1190|      0|    return 0;
 1191|      0|  }
 1192|       |
 1193|  3.10k|  e_token_length = hdr[0] & 0x0f;
 1194|  3.10k|  if (e_token_length < COAP_TOKEN_EXT_1B_TKL) {
  ------------------
  |  |   54|  3.10k|#define COAP_TOKEN_EXT_1B_TKL 13
  ------------------
  |  Branch (1194:7): [True: 2.97k, False: 128]
  ------------------
 1195|  2.97k|    pdu->e_token_length = e_token_length;
 1196|  2.97k|    pdu->actual_token.length = pdu->e_token_length;
 1197|  2.97k|    pdu->actual_token.s = &pdu->token[0];
 1198|  2.97k|  } else if (e_token_length == COAP_TOKEN_EXT_1B_TKL) {
  ------------------
  |  |   54|    128|#define COAP_TOKEN_EXT_1B_TKL 13
  ------------------
  |  Branch (1198:14): [True: 63, False: 65]
  ------------------
 1199|     63|    if (pdu->used_size < 1)
  ------------------
  |  Branch (1199:9): [True: 1, False: 62]
  ------------------
 1200|      1|      goto bad_ext_token;
 1201|     62|    pdu->e_token_length = pdu->token[0] + COAP_TOKEN_EXT_1B_BIAS + 1;
  ------------------
  |  |   56|     62|#define COAP_TOKEN_EXT_1B_BIAS 13
  ------------------
 1202|     62|    pdu->actual_token.length = pdu->e_token_length - 1;
 1203|     62|    pdu->actual_token.s = &pdu->token[1];
 1204|     65|  } else if (e_token_length == COAP_TOKEN_EXT_2B_TKL) {
  ------------------
  |  |   55|     65|#define COAP_TOKEN_EXT_2B_TKL 14
  ------------------
  |  Branch (1204:14): [True: 62, False: 3]
  ------------------
 1205|     62|    if (pdu->used_size < 2)
  ------------------
  |  Branch (1205:9): [True: 2, False: 60]
  ------------------
 1206|      2|      goto bad_ext_token;
 1207|     60|    pdu->e_token_length = ((uint16_t)pdu->token[0] << 8) + pdu->token[1] +
 1208|     60|                          COAP_TOKEN_EXT_2B_BIAS + 2;
  ------------------
  |  |   57|     60|#define COAP_TOKEN_EXT_2B_BIAS 269 /* 13 + 256 */
  ------------------
 1209|     60|    pdu->actual_token.length = pdu->e_token_length - 2;
 1210|     60|    pdu->actual_token.s = &pdu->token[2];
 1211|     60|  }
 1212|  3.10k|  if (pdu->e_token_length > pdu->alloc_size || e_token_length == 15) {
  ------------------
  |  Branch (1212:7): [True: 22, False: 3.07k]
  |  Branch (1212:48): [True: 3, False: 3.07k]
  ------------------
 1213|     25|    goto bad_ext_token;
 1214|     25|  }
 1215|  3.07k|  return 1;
 1216|       |
 1217|     28|bad_ext_token:
 1218|       |  /* Invalid PDU provided - not wise to assert here though */
 1219|     28|  coap_log_debug("coap_pdu_parse: PDU header extended token size broken\n");
  ------------------
  |  |  126|     28|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     28|#define coap_log(level, ...) do { \
  |  |  |  |  291|     28|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 28]
  |  |  |  |  ------------------
  |  |  |  |  292|     28|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     28|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 28]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1220|     28|  pdu->e_token_length = 0;
 1221|     28|  pdu->actual_token.length = 0;
 1222|     28|  return 0;
 1223|  3.10k|}
coap_pdu_parse_opt_base:
 1294|  5.52M|coap_pdu_parse_opt_base(coap_option_num_t number, size_t len, const uint8_t *opt_val) {
 1295|  5.52M|  int res = 1;
 1296|       |
 1297|  5.52M|  switch ((coap_code_opt_num_t)number) {
 1298|  2.17k|  case COAP_OPTION_IF_MATCH:
  ------------------
  |  Branch (1298:3): [True: 2.17k, False: 5.52M]
  ------------------
 1299|  2.17k|    if (len > 8)
  ------------------
  |  Branch (1299:9): [True: 1.02k, False: 1.15k]
  ------------------
 1300|  1.02k|      res = 0;
 1301|  2.17k|    break;
 1302|  5.41k|  case COAP_OPTION_URI_HOST:
  ------------------
  |  Branch (1302:3): [True: 5.41k, False: 5.52M]
  ------------------
 1303|  5.41k|    if (len < 1 || len > 255)
  ------------------
  |  Branch (1303:9): [True: 3.82k, False: 1.59k]
  |  Branch (1303:20): [True: 1.02k, False: 570]
  ------------------
 1304|  4.84k|      res = 0;
 1305|  5.41k|    break;
 1306|  5.05k|  case COAP_OPTION_ETAG:
  ------------------
  |  Branch (1306:3): [True: 5.05k, False: 5.52M]
  ------------------
 1307|  5.05k|    if (len < 1 || len > 8)
  ------------------
  |  Branch (1307:9): [True: 2.91k, False: 2.13k]
  |  Branch (1307:20): [True: 1.40k, False: 733]
  ------------------
 1308|  4.32k|      res = 0;
 1309|  5.05k|    break;
 1310|  1.93k|  case COAP_OPTION_IF_NONE_MATCH:
  ------------------
  |  Branch (1310:3): [True: 1.93k, False: 5.52M]
  ------------------
 1311|  1.93k|    if (len != 0)
  ------------------
  |  Branch (1311:9): [True: 1.44k, False: 493]
  ------------------
 1312|  1.44k|      res = 0;
 1313|  1.93k|    break;
 1314|  2.89k|  case COAP_OPTION_OBSERVE:
  ------------------
  |  Branch (1314:3): [True: 2.89k, False: 5.52M]
  ------------------
 1315|  2.89k|    if (len > 3)
  ------------------
  |  Branch (1315:9): [True: 2.13k, False: 755]
  ------------------
 1316|  2.13k|      res = 0;
 1317|  2.89k|    break;
 1318|  2.12k|  case COAP_OPTION_URI_PORT:
  ------------------
  |  Branch (1318:3): [True: 2.12k, False: 5.52M]
  ------------------
 1319|  2.12k|    if (len > 2)
  ------------------
  |  Branch (1319:9): [True: 1.15k, False: 968]
  ------------------
 1320|  1.15k|      res = 0;
 1321|  2.12k|    break;
 1322|  3.62k|  case COAP_OPTION_LOCATION_PATH:
  ------------------
  |  Branch (1322:3): [True: 3.62k, False: 5.52M]
  ------------------
 1323|  4.02M|  case COAP_OPTION_URI_PATH:
  ------------------
  |  Branch (1323:3): [True: 4.01M, False: 1.51M]
  ------------------
 1324|  4.02M|    if (len > 255)
  ------------------
  |  Branch (1324:9): [True: 1.06k, False: 4.02M]
  ------------------
 1325|  1.06k|      res = 0;
 1326|  4.02M|    if (coap_check_dots(opt_val, len)) {
  ------------------
  |  Branch (1326:9): [True: 2.75k, False: 4.01M]
  ------------------
 1327|  2.75k|      res = 0;
 1328|  2.75k|    }
 1329|  4.02M|    break;
 1330|  1.95k|  case COAP_OPTION_OSCORE:
  ------------------
  |  Branch (1330:3): [True: 1.95k, False: 5.52M]
  ------------------
 1331|  1.95k|    if (len > 255)
  ------------------
  |  Branch (1331:9): [True: 993, False: 957]
  ------------------
 1332|    993|      res = 0;
 1333|  1.95k|    break;
 1334|  2.08k|  case COAP_OPTION_CONTENT_FORMAT:
  ------------------
  |  Branch (1334:3): [True: 2.08k, False: 5.52M]
  ------------------
 1335|  2.08k|    if (len > 2)
  ------------------
  |  Branch (1335:9): [True: 1.17k, False: 908]
  ------------------
 1336|  1.17k|      res = 0;
 1337|  2.08k|    break;
 1338|  1.65k|  case COAP_OPTION_URI_PATH_ABB:
  ------------------
  |  Branch (1338:3): [True: 1.65k, False: 5.52M]
  ------------------
 1339|  1.65k|    if (len > 4)
  ------------------
  |  Branch (1339:9): [True: 1.14k, False: 514]
  ------------------
 1340|  1.14k|      res = 0;
 1341|  1.65k|    break;
 1342|  1.78k|  case COAP_OPTION_MAXAGE:
  ------------------
  |  Branch (1342:3): [True: 1.78k, False: 5.52M]
  ------------------
 1343|  1.78k|    if (len > 4)
  ------------------
  |  Branch (1343:9): [True: 1.28k, False: 504]
  ------------------
 1344|  1.28k|      res = 0;
 1345|  1.78k|    break;
 1346|   146k|  case COAP_OPTION_URI_QUERY:
  ------------------
  |  Branch (1346:3): [True: 146k, False: 5.38M]
  ------------------
 1347|   146k|    if (len < 1 || len > 255)
  ------------------
  |  Branch (1347:9): [True: 1.83k, False: 144k]
  |  Branch (1347:20): [True: 1.00k, False: 143k]
  ------------------
 1348|  2.83k|      res = 0;
 1349|   146k|    break;
 1350|  1.76k|  case COAP_OPTION_HOP_LIMIT:
  ------------------
  |  Branch (1350:3): [True: 1.76k, False: 5.52M]
  ------------------
 1351|  1.76k|    if (len != 1)
  ------------------
  |  Branch (1351:9): [True: 1.54k, False: 219]
  ------------------
 1352|  1.54k|      res = 0;
 1353|  1.76k|    break;
 1354|  2.01k|  case COAP_OPTION_ACCEPT:
  ------------------
  |  Branch (1354:3): [True: 2.01k, False: 5.52M]
  ------------------
 1355|  2.01k|    if (len > 2)
  ------------------
  |  Branch (1355:9): [True: 1.16k, False: 847]
  ------------------
 1356|  1.16k|      res = 0;
 1357|  2.01k|    break;
 1358|   526k|  case COAP_OPTION_Q_BLOCK1:
  ------------------
  |  Branch (1358:3): [True: 526k, False: 5.00M]
  ------------------
 1359|   526k|    if (len > 3)
  ------------------
  |  Branch (1359:9): [True: 1.19k, False: 525k]
  ------------------
 1360|  1.19k|      res = 0;
 1361|   526k|    break;
 1362|  2.23k|  case COAP_OPTION_LOCATION_QUERY:
  ------------------
  |  Branch (1362:3): [True: 2.23k, False: 5.52M]
  ------------------
 1363|  2.23k|    if (len > 255)
  ------------------
  |  Branch (1363:9): [True: 1.06k, False: 1.17k]
  ------------------
 1364|  1.06k|      res = 0;
 1365|  2.23k|    break;
 1366|  2.16k|  case COAP_OPTION_EDHOC:
  ------------------
  |  Branch (1366:3): [True: 2.16k, False: 5.52M]
  ------------------
 1367|  2.16k|    if (len != 0)
  ------------------
  |  Branch (1367:9): [True: 1.27k, False: 886]
  ------------------
 1368|  1.27k|      res = 0;
 1369|  2.16k|    break;
 1370|  1.63k|  case COAP_OPTION_BLOCK2:
  ------------------
  |  Branch (1370:3): [True: 1.63k, False: 5.52M]
  ------------------
 1371|  1.63k|    if (len > 3)
  ------------------
  |  Branch (1371:9): [True: 1.20k, False: 425]
  ------------------
 1372|  1.20k|      res = 0;
 1373|  1.63k|    break;
 1374|  1.85k|  case COAP_OPTION_BLOCK1:
  ------------------
  |  Branch (1374:3): [True: 1.85k, False: 5.52M]
  ------------------
 1375|  1.85k|    if (len > 3)
  ------------------
  |  Branch (1375:9): [True: 1.06k, False: 789]
  ------------------
 1376|  1.06k|      res = 0;
 1377|  1.85k|    break;
 1378|  1.37k|  case COAP_OPTION_SIZE2:
  ------------------
  |  Branch (1378:3): [True: 1.37k, False: 5.52M]
  ------------------
 1379|  1.37k|    if (len > 4)
  ------------------
  |  Branch (1379:9): [True: 1.02k, False: 349]
  ------------------
 1380|  1.02k|      res = 0;
 1381|  1.37k|    break;
 1382|  1.34k|  case COAP_OPTION_Q_BLOCK2:
  ------------------
  |  Branch (1382:3): [True: 1.34k, False: 5.52M]
  ------------------
 1383|  1.34k|    if (len > 3)
  ------------------
  |  Branch (1383:9): [True: 1.03k, False: 302]
  ------------------
 1384|  1.03k|      res = 0;
 1385|  1.34k|    break;
 1386|  11.8k|  case COAP_OPTION_PROXY_URI:
  ------------------
  |  Branch (1386:3): [True: 11.8k, False: 5.51M]
  ------------------
 1387|  11.8k|    if (len < 1 || len > 1034)
  ------------------
  |  Branch (1387:9): [True: 4.89k, False: 6.91k]
  |  Branch (1387:20): [True: 999, False: 5.91k]
  ------------------
 1388|  5.88k|      res = 0;
 1389|  11.8k|    break;
 1390|  3.24k|  case COAP_OPTION_PROXY_SCHEME:
  ------------------
  |  Branch (1390:3): [True: 3.24k, False: 5.52M]
  ------------------
 1391|  3.24k|    if (len < 1 || len > 255)
  ------------------
  |  Branch (1391:9): [True: 1.86k, False: 1.38k]
  |  Branch (1391:20): [True: 1.02k, False: 353]
  ------------------
 1392|  2.89k|      res = 0;
 1393|  3.24k|    break;
 1394|  2.87k|  case COAP_OPTION_SIZE1:
  ------------------
  |  Branch (1394:3): [True: 2.87k, False: 5.52M]
  ------------------
 1395|  2.87k|    if (len > 4)
  ------------------
  |  Branch (1395:9): [True: 999, False: 1.87k]
  ------------------
 1396|    999|      res = 0;
 1397|  2.87k|    break;
 1398|  1.74k|  case COAP_OPTION_ECHO:
  ------------------
  |  Branch (1398:3): [True: 1.74k, False: 5.52M]
  ------------------
 1399|  1.74k|    if (len > 40)
  ------------------
  |  Branch (1399:9): [True: 1.13k, False: 610]
  ------------------
 1400|  1.13k|      res = 0;
 1401|  1.74k|    break;
 1402|  1.26k|  case COAP_OPTION_NORESPONSE:
  ------------------
  |  Branch (1402:3): [True: 1.26k, False: 5.52M]
  ------------------
 1403|  1.26k|    if (len > 1)
  ------------------
  |  Branch (1403:9): [True: 984, False: 277]
  ------------------
 1404|    984|      res = 0;
 1405|  1.26k|    break;
 1406|  2.02k|  case COAP_OPTION_RTAG:
  ------------------
  |  Branch (1406:3): [True: 2.02k, False: 5.52M]
  ------------------
 1407|  2.02k|    if (len > 8)
  ------------------
  |  Branch (1407:9): [True: 1.21k, False: 809]
  ------------------
 1408|  1.21k|      res = 0;
 1409|  2.02k|    break;
 1410|   768k|  default:
  ------------------
  |  Branch (1410:3): [True: 768k, False: 4.76M]
  ------------------
 1411|   768k|    ;
 1412|  5.52M|  }
 1413|  5.52M|  return res;
 1414|  5.52M|}
coap_pdu_parse_opt:
 1450|  3.07k|coap_pdu_parse_opt(coap_pdu_t *pdu, coap_opt_filter_t *error_opts) {
 1451|  3.07k|  int good = 1;
 1452|       |
 1453|  3.07k|  coap_option_filter_clear(error_opts);
 1454|       |
 1455|       |  /* sanity checks */
 1456|  3.07k|  if (pdu->code == 0) {
  ------------------
  |  Branch (1456:7): [True: 20, False: 3.05k]
  ------------------
 1457|     20|    if (pdu->used_size != 0 || pdu->e_token_length) {
  ------------------
  |  Branch (1457:9): [True: 18, False: 2]
  |  Branch (1457:32): [True: 1, False: 1]
  ------------------
 1458|     19|      coap_log_debug("coap_pdu_parse: empty message is not empty\n");
  ------------------
  |  |  126|     19|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     19|#define coap_log(level, ...) do { \
  |  |  |  |  291|     19|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 19]
  |  |  |  |  ------------------
  |  |  |  |  292|     19|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     19|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 19]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1459|     19|      return 0;
 1460|     19|    }
 1461|     20|  }
 1462|       |
 1463|  3.05k|  if (pdu->e_token_length > pdu->used_size) {
  ------------------
  |  Branch (1463:7): [True: 5, False: 3.05k]
  ------------------
 1464|      5|    coap_log_debug("coap_pdu_parse: invalid Token\n");
  ------------------
  |  |  126|      5|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      5|#define coap_log(level, ...) do { \
  |  |  |  |  291|      5|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  292|      5|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      5|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 5]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1465|      5|    return 0;
 1466|      5|  }
 1467|       |
 1468|  3.05k|  pdu->max_opt = 0;
 1469|  3.05k|  if (pdu->code == 0) {
  ------------------
  |  Branch (1469:7): [True: 1, False: 3.05k]
  ------------------
 1470|       |    /* empty packet */
 1471|      1|    pdu->used_size = 0;
 1472|      1|    pdu->data = NULL;
 1473|  3.05k|  } else {
 1474|       |    /* skip header + token */
 1475|  3.05k|    coap_opt_t *opt = pdu->token + pdu->e_token_length;
 1476|  3.05k|    size_t length = pdu->used_size - pdu->e_token_length;
 1477|       |
 1478|  11.2M|    while (length > 0 && *opt != COAP_PAYLOAD_START) {
  ------------------
  |  |   96|  11.2M|#define COAP_PAYLOAD_START 0xFF /* payload marker */
  ------------------
  |  Branch (1478:12): [True: 11.2M, False: 2.40k]
  |  Branch (1478:26): [True: 11.2M, False: 201]
  ------------------
 1479|  11.2M|#if (COAP_MAX_LOGGING_LEVEL >= _COAP_LOG_WARN)
 1480|  11.2M|      coap_opt_t *opt_last = opt;
 1481|  11.2M|#endif
 1482|  11.2M|      size_t optsize = next_option_safe(&opt, &length, &pdu->max_opt);
 1483|  11.2M|      uint32_t len;
 1484|  11.2M|      const uint8_t *opt_val;
 1485|       |
 1486|  11.2M|      if (optsize == 0) {
  ------------------
  |  Branch (1486:11): [True: 443, False: 11.2M]
  ------------------
 1487|    443|        coap_log_debug("coap_pdu_parse: %d.%02d: offset %u malformed option\n",
  ------------------
  |  |  126|    443|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|    443|#define coap_log(level, ...) do { \
  |  |  |  |  291|    443|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 443]
  |  |  |  |  ------------------
  |  |  |  |  292|    443|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|    443|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 443]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1488|    443|                       pdu->code >> 5, pdu->code & 0x1F,
 1489|    443|                       (int)(opt_last - pdu->token - pdu->e_token_length));
 1490|    443|        coap_option_filter_set(error_opts, pdu->max_opt);
 1491|    443|        good = 0;
 1492|    443|        break;
 1493|    443|      }
 1494|  11.2M|      len = coap_opt_length((const uint8_t *)opt - optsize);
 1495|  11.2M|      opt_val = coap_opt_value((const uint8_t *)opt - optsize);
 1496|  11.2M|      if (COAP_PDU_IS_SIGNALING(pdu) ?
  ------------------
  |  |  102|  11.2M|#define COAP_PDU_IS_SIGNALING(pdu) ((pdu)->code >= 224)
  |  |  ------------------
  |  |  |  Branch (102:36): [True: 6.27M, False: 4.97M]
  |  |  ------------------
  ------------------
  |  Branch (1496:11): [True: 4.52M, False: 6.72M]
  ------------------
 1497|  6.27M|          !coap_pdu_parse_opt_csm(pdu->code, pdu->max_opt, len) :
 1498|  11.2M|          !coap_pdu_parse_opt_base(pdu->max_opt, len, opt_val)) {
 1499|  4.52M|        coap_log_warn("coap_pdu_parse: %d.%02d: offset %u option %u has bad length %" PRIu32 " or value\n",
  ------------------
  |  |  108|  4.52M|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|  4.52M|#define coap_log(level, ...) do { \
  |  |  |  |  291|  4.52M|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 4.52M]
  |  |  |  |  ------------------
  |  |  |  |  292|  4.52M|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|  4.52M|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 4.52M]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1500|  4.52M|                      pdu->code >> 5, pdu->code & 0x1F,
 1501|  4.52M|                      (int)(opt_last - pdu->token - pdu->e_token_length), pdu->max_opt,
 1502|  4.52M|                      len);
 1503|  4.52M|        coap_option_filter_set(error_opts, pdu->max_opt);
 1504|  4.52M|        good = 0;
 1505|  4.52M|      }
 1506|  11.2M|    }
 1507|       |
 1508|  3.05k|    if (!good) {
  ------------------
  |  Branch (1508:9): [True: 1.45k, False: 1.59k]
  ------------------
 1509|       |      /*
 1510|       |       * Dump the options in the PDU for analysis, space separated except
 1511|       |       * error options which are prefixed by *
 1512|       |       * Two rows - hex and ascii (if printable)
 1513|       |       */
 1514|  1.45k|      static char outbuf[COAP_DEBUG_BUF_SIZE];
 1515|  1.45k|      char *obp;
 1516|  1.45k|      size_t tlen;
 1517|  1.45k|      size_t outbuflen;
 1518|  1.45k|      int i;
 1519|  1.45k|      int ok;
 1520|       |
 1521|  4.35k|      for (i = 0; i < 2; i++) {
  ------------------
  |  Branch (1521:19): [True: 2.90k, False: 1.45k]
  ------------------
 1522|  2.90k|        opt = pdu->token + pdu->e_token_length;
 1523|  2.90k|        length = pdu->used_size - pdu->e_token_length;
 1524|  2.90k|        pdu->max_opt = 0;
 1525|       |
 1526|  2.90k|        outbuflen = sizeof(outbuf);
 1527|  2.90k|        obp = outbuf;
 1528|  2.90k|        ok = write_prefix(&obp, &outbuflen, "O: ", 3);
 1529|       |        /*
 1530|       |         * Not safe to check for 'ok' here as a lot of variables may get
 1531|       |         * partially changed due to lack of outbuflen */
 1532|  10.9M|        while (length > 0 && *opt != COAP_PAYLOAD_START) {
  ------------------
  |  |   96|  10.9M|#define COAP_PAYLOAD_START 0xFF /* payload marker */
  ------------------
  |  Branch (1532:16): [True: 10.9M, False: 2.78k]
  |  Branch (1532:30): [True: 10.9M, False: 116]
  ------------------
 1533|  10.9M|          coap_opt_t *opt_last = opt;
 1534|  10.9M|          size_t optsize = next_option_safe(&opt, &length, &pdu->max_opt);
 1535|  10.9M|          const uint32_t len =
 1536|  10.9M|              optsize ? coap_opt_length((const uint8_t *)opt - optsize) : 0;
  ------------------
  |  Branch (1536:15): [True: 10.9M, False: 886]
  ------------------
 1537|  10.9M|          const uint8_t *opt_val =
 1538|  10.9M|              optsize ?  coap_opt_value((const uint8_t *)opt - optsize) : 0;
  ------------------
  |  Branch (1538:15): [True: 10.9M, False: 886]
  ------------------
 1539|       |
 1540|  10.9M|          if (!optsize || (COAP_PDU_IS_SIGNALING(pdu) ?
  ------------------
  |  |  102|  10.9M|#define COAP_PDU_IS_SIGNALING(pdu) ((pdu)->code >= 224)
  |  |  ------------------
  |  |  |  Branch (102:36): [True: 10.4M, False: 549k]
  |  |  ------------------
  ------------------
  |  Branch (1540:15): [True: 886, False: 10.9M]
  |  Branch (1540:27): [True: 9.04M, False: 1.95M]
  ------------------
 1541|  10.4M|                           !coap_pdu_parse_opt_csm(pdu->code, pdu->max_opt, len) :
 1542|  10.9M|                           !coap_pdu_parse_opt_base(pdu->max_opt, len, opt_val))) {
 1543|  9.04M|            ok = ok && write_prefix(&obp, &outbuflen, "*", 1);
  ------------------
  |  Branch (1543:18): [True: 58.3k, False: 8.98M]
  |  Branch (1543:24): [True: 58.3k, False: 20]
  ------------------
 1544|  9.04M|            if (!optsize) {
  ------------------
  |  Branch (1544:17): [True: 886, False: 9.04M]
  ------------------
 1545|       |              /* Skip to end of options to output all data */
 1546|    886|              opt = pdu->token + pdu->used_size;
 1547|    886|              length = 0;
 1548|    886|            }
 1549|  9.04M|          } else {
 1550|  1.95M|            ok = ok && write_prefix(&obp, &outbuflen, " ", 1);
  ------------------
  |  Branch (1550:18): [True: 40.6k, False: 1.91M]
  |  Branch (1550:24): [True: 40.6k, False: 16]
  ------------------
 1551|  1.95M|          }
 1552|  10.9M|          tlen = opt - opt_last;
 1553|  90.8M|          while (tlen) {
  ------------------
  |  Branch (1553:18): [True: 79.8M, False: 10.9M]
  ------------------
 1554|  79.8M|            tlen--;
 1555|  79.8M|            ok = ok && write_char(&obp, &outbuflen, *opt_last, i);
  ------------------
  |  Branch (1555:18): [True: 1.07M, False: 78.7M]
  |  Branch (1555:24): [True: 1.07M, False: 822]
  ------------------
 1556|  79.8M|            opt_last++;
 1557|  79.8M|          }
 1558|  10.9M|        }
 1559|  2.90k|        if (length && *opt == COAP_PAYLOAD_START) {
  ------------------
  |  |   96|    116|#define COAP_PAYLOAD_START 0xFF /* payload marker */
  ------------------
  |  Branch (1559:13): [True: 116, False: 2.78k]
  |  Branch (1559:23): [True: 116, False: 0]
  ------------------
 1560|    116|          write_char(&obp, &outbuflen, *opt, i);
 1561|    116|        }
 1562|       |        /* write_*() always leaves a spare byte to null terminate */
 1563|  2.90k|        *obp = '\000';
 1564|  2.90k|        coap_log_debug("%s\n", outbuf);
  ------------------
  |  |  126|  2.90k|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|  2.90k|#define coap_log(level, ...) do { \
  |  |  |  |  291|  2.90k|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 2.90k]
  |  |  |  |  ------------------
  |  |  |  |  292|  2.90k|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|  2.90k|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 2.90k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1565|  2.90k|      }
 1566|  1.45k|    }
 1567|       |
 1568|  3.05k|    if (length > 0) {
  ------------------
  |  Branch (1568:9): [True: 201, False: 2.84k]
  ------------------
 1569|    201|      assert(*opt == COAP_PAYLOAD_START);
  ------------------
  |  Branch (1569:7): [True: 201, False: 0]
  ------------------
 1570|    201|      opt++;
 1571|    201|      length--;
 1572|       |
 1573|    201|      if (length == 0) {
  ------------------
  |  Branch (1573:11): [True: 26, False: 175]
  ------------------
 1574|     26|        coap_log_debug("coap_pdu_parse: message ending in payload start marker\n");
  ------------------
  |  |  126|     26|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     26|#define coap_log(level, ...) do { \
  |  |  |  |  291|     26|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 26]
  |  |  |  |  ------------------
  |  |  |  |  292|     26|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     26|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 26]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1575|     26|        return 0;
 1576|     26|      }
 1577|    201|    }
 1578|  3.02k|    if (length > 0)
  ------------------
  |  Branch (1578:9): [True: 175, False: 2.84k]
  ------------------
 1579|    175|      pdu->data = (uint8_t *)opt;
 1580|  2.84k|    else
 1581|  2.84k|      pdu->data = NULL;
 1582|  3.02k|  }
 1583|       |
 1584|  3.02k|  return good;
 1585|  3.05k|}
coap_pdu_parse:
 1591|  3.10k|               coap_pdu_t *pdu) {
 1592|  3.10k|  coap_opt_filter_t error_opts;
 1593|       |
 1594|  3.10k|  return coap_pdu_parse2(proto, data, length, pdu, &error_opts);
 1595|  3.10k|}
coap_pdu_parse2:
 1602|  3.10k|                coap_opt_filter_t *error_opts) {
 1603|  3.10k|  size_t hdr_size;
 1604|       |
 1605|  3.10k|  if (length == 0)
  ------------------
  |  Branch (1605:7): [True: 0, False: 3.10k]
  ------------------
 1606|      0|    return 0;
 1607|  3.10k|  hdr_size = coap_pdu_parse_header_size(proto, data);
 1608|  3.10k|  if (!hdr_size || hdr_size > length)
  ------------------
  |  Branch (1608:7): [True: 0, False: 3.10k]
  |  Branch (1608:20): [True: 1, False: 3.10k]
  ------------------
 1609|      1|    return 0;
 1610|  3.10k|  if (hdr_size > pdu->max_hdr_size)
  ------------------
  |  Branch (1610:7): [True: 0, False: 3.10k]
  ------------------
 1611|      0|    return 0;
 1612|  3.10k|  if (!coap_pdu_resize(pdu, length - hdr_size))
  ------------------
  |  Branch (1612:7): [True: 0, False: 3.10k]
  ------------------
 1613|      0|    return 0;
 1614|  3.10k|  if (pdu->token - hdr_size != data)
  ------------------
  |  Branch (1614:7): [True: 3.10k, False: 0]
  ------------------
 1615|  3.10k|    memcpy(pdu->token - hdr_size, data, length);
 1616|  3.10k|  pdu->hdr_size = (uint8_t)hdr_size;
 1617|  3.10k|  pdu->used_size = length - hdr_size;
 1618|  3.10k|  return coap_pdu_parse_header(pdu, proto) && coap_pdu_parse_opt(pdu, error_opts);
  ------------------
  |  Branch (1618:10): [True: 3.07k, False: 28]
  |  Branch (1618:47): [True: 1.59k, False: 1.48k]
  ------------------
 1619|  3.10k|}
coap_pdu_encode_header:
 1622|  1.59k|coap_pdu_encode_header(coap_pdu_t *pdu, coap_proto_t proto) {
 1623|  1.59k|  uint8_t e_token_length;
 1624|       |
 1625|  1.59k|  if (pdu->actual_token.length < COAP_TOKEN_EXT_1B_BIAS) {
  ------------------
  |  |   56|  1.59k|#define COAP_TOKEN_EXT_1B_BIAS 13
  ------------------
  |  Branch (1625:7): [True: 1.52k, False: 67]
  ------------------
 1626|  1.52k|    e_token_length = (uint8_t)pdu->actual_token.length;
 1627|  1.52k|  } else if (pdu->actual_token.length < COAP_TOKEN_EXT_2B_BIAS) {
  ------------------
  |  |   57|     67|#define COAP_TOKEN_EXT_2B_BIAS 269 /* 13 + 256 */
  ------------------
  |  Branch (1627:14): [True: 25, False: 42]
  ------------------
 1628|     25|    e_token_length = COAP_TOKEN_EXT_1B_TKL;
  ------------------
  |  |   54|     25|#define COAP_TOKEN_EXT_1B_TKL 13
  ------------------
 1629|     42|  } else if (pdu->actual_token.length <= COAP_TOKEN_EXT_MAX) {
  ------------------
  |  |   60|     42|#define COAP_TOKEN_EXT_MAX 65804UL /* 13 + 256 + 65535 */
  ------------------
  |  Branch (1629:14): [True: 42, False: 0]
  ------------------
 1630|     42|    e_token_length = COAP_TOKEN_EXT_2B_TKL;
  ------------------
  |  |   55|     42|#define COAP_TOKEN_EXT_2B_TKL 14
  ------------------
 1631|     42|  } else {
 1632|      0|    coap_log_warn("coap_pdu_encode_header: Token size too large. PDU ignored\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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1633|      0|    return 0;
 1634|      0|  }
 1635|  1.59k|  if (COAP_PROTO_NOT_RELIABLE(proto)) {
  ------------------
  |  |   41|  1.59k|#define COAP_PROTO_NOT_RELIABLE(p) ((p)==COAP_PROTO_UDP || (p)==COAP_PROTO_DTLS)
  |  |  ------------------
  |  |  |  Branch (41:37): [True: 0, False: 1.59k]
  |  |  |  Branch (41:60): [True: 0, False: 1.59k]
  |  |  ------------------
  ------------------
 1636|      0|    assert(pdu->max_hdr_size >= 4);
  ------------------
  |  Branch (1636:5): [True: 0, False: 0]
  ------------------
 1637|      0|    if (pdu->max_hdr_size < 4) {
  ------------------
  |  Branch (1637:9): [True: 0, False: 0]
  ------------------
 1638|      0|      coap_log_warn("coap_pdu_encode_header: not enough space for UDP-style header\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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1639|      0|      return 0;
 1640|      0|    }
 1641|      0|    pdu->token[-4] = COAP_DEFAULT_VERSION << 6
  ------------------
  |  |   35|      0|#define COAP_DEFAULT_VERSION      1 /* version of CoAP supported */
  ------------------
 1642|      0|                     | pdu->type << 4
 1643|      0|                     | e_token_length;
 1644|      0|    pdu->token[-3] = pdu->code;
 1645|      0|    pdu->token[-2] = (uint8_t)(pdu->mid >> 8);
 1646|      0|    pdu->token[-1] = (uint8_t)(pdu->mid);
 1647|      0|    pdu->hdr_size = 4;
 1648|      0|#if !COAP_DISABLE_TCP
 1649|  1.59k|  } else if (COAP_PROTO_RELIABLE(proto)) {
  ------------------
  |  |   42|  1.59k|#define COAP_PROTO_RELIABLE(p) ((p)==COAP_PROTO_TCP || (p)==COAP_PROTO_TLS || \
  |  |  ------------------
  |  |  |  Branch (42:33): [True: 0, False: 1.59k]
  |  |  |  Branch (42:56): [True: 0, False: 1.59k]
  |  |  ------------------
  |  |   43|  1.59k|                                (p)==COAP_PROTO_WS || (p)==COAP_PROTO_WSS)
  |  |  ------------------
  |  |  |  Branch (43:33): [True: 1.59k, False: 0]
  |  |  |  Branch (43:55): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1650|  1.59k|    size_t len;
 1651|  1.59k|    assert(pdu->used_size >= pdu->e_token_length);
  ------------------
  |  Branch (1651:5): [True: 1.59k, False: 0]
  ------------------
 1652|  1.59k|    if (pdu->used_size < pdu->e_token_length) {
  ------------------
  |  Branch (1652:9): [True: 0, False: 1.59k]
  ------------------
 1653|      0|      coap_log_warn("coap_pdu_encode_header: corrupted PDU\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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1654|      0|      return 0;
 1655|      0|    }
 1656|       |
 1657|       |    /* A lot of the reliable code assumes type is CON */
 1658|  1.59k|    if (pdu->type != COAP_MESSAGE_CON)
  ------------------
  |  Branch (1658:9): [True: 0, False: 1.59k]
  ------------------
 1659|      0|      pdu->type = COAP_MESSAGE_CON;
 1660|       |
 1661|  1.59k|    if (proto == COAP_PROTO_WS || proto == COAP_PROTO_WSS)
  ------------------
  |  Branch (1661:9): [True: 1.59k, False: 0]
  |  Branch (1661:35): [True: 0, False: 0]
  ------------------
 1662|  1.59k|      len = 0;
 1663|      0|    else
 1664|      0|      len = pdu->used_size - pdu->e_token_length;
 1665|  1.59k|    if (len <= COAP_MAX_MESSAGE_SIZE_TCP0) {
  ------------------
  |  |   43|  1.59k|#define COAP_MAX_MESSAGE_SIZE_TCP0 (COAP_MESSAGE_SIZE_OFFSET_TCP8-1) /* 12 */
  |  |  ------------------
  |  |  |  |   38|  1.59k|#define COAP_MESSAGE_SIZE_OFFSET_TCP8 13
  |  |  ------------------
  ------------------
  |  Branch (1665:9): [True: 1.59k, False: 0]
  ------------------
 1666|  1.59k|      assert(pdu->max_hdr_size >= 2);
  ------------------
  |  Branch (1666:7): [True: 1.59k, False: 0]
  ------------------
 1667|  1.59k|      if (pdu->max_hdr_size < 2) {
  ------------------
  |  Branch (1667:11): [True: 0, False: 1.59k]
  ------------------
 1668|      0|        coap_log_warn("coap_pdu_encode_header: not enough space for TCP0 header\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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1669|      0|        return 0;
 1670|      0|      }
 1671|  1.59k|      pdu->token[-2] = (uint8_t)len << 4
 1672|  1.59k|                       | e_token_length;
 1673|  1.59k|      pdu->token[-1] = pdu->code;
 1674|  1.59k|      pdu->hdr_size = 2;
 1675|  1.59k|    } else if (len <= COAP_MAX_MESSAGE_SIZE_TCP8) {
  ------------------
  |  |   44|      0|#define COAP_MAX_MESSAGE_SIZE_TCP8 (COAP_MESSAGE_SIZE_OFFSET_TCP16-1) /* 268 */
  |  |  ------------------
  |  |  |  |   39|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP16 269 /* 13 + 256 */
  |  |  ------------------
  ------------------
  |  Branch (1675:16): [True: 0, False: 0]
  ------------------
 1676|      0|      assert(pdu->max_hdr_size >= 3);
  ------------------
  |  Branch (1676:7): [True: 0, False: 0]
  ------------------
 1677|      0|      if (pdu->max_hdr_size < 3) {
  ------------------
  |  Branch (1677:11): [True: 0, False: 0]
  ------------------
 1678|      0|        coap_log_warn("coap_pdu_encode_header: not enough space for TCP8 header\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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1679|      0|        return 0;
 1680|      0|      }
 1681|      0|      pdu->token[-3] = 13 << 4 | e_token_length;
 1682|      0|      pdu->token[-2] = (uint8_t)(len - COAP_MESSAGE_SIZE_OFFSET_TCP8);
  ------------------
  |  |   38|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP8 13
  ------------------
 1683|      0|      pdu->token[-1] = pdu->code;
 1684|      0|      pdu->hdr_size = 3;
 1685|      0|    } else if (len <= COAP_MAX_MESSAGE_SIZE_TCP16) {
  ------------------
  |  |   45|      0|#define COAP_MAX_MESSAGE_SIZE_TCP16 (COAP_MESSAGE_SIZE_OFFSET_TCP32-1) /* 65804 */
  |  |  ------------------
  |  |  |  |   40|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */
  |  |  ------------------
  ------------------
  |  Branch (1685:16): [True: 0, False: 0]
  ------------------
 1686|      0|      assert(pdu->max_hdr_size >= 4);
  ------------------
  |  Branch (1686:7): [True: 0, False: 0]
  ------------------
 1687|      0|      if (pdu->max_hdr_size < 4) {
  ------------------
  |  Branch (1687:11): [True: 0, False: 0]
  ------------------
 1688|      0|        coap_log_warn("coap_pdu_encode_header: not enough space for TCP16 header\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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1689|      0|        return 0;
 1690|      0|      }
 1691|      0|      pdu->token[-4] = 14 << 4 | e_token_length;
 1692|      0|      pdu->token[-3] = (uint8_t)((len - COAP_MESSAGE_SIZE_OFFSET_TCP16) >> 8);
  ------------------
  |  |   39|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP16 269 /* 13 + 256 */
  ------------------
 1693|      0|      pdu->token[-2] = (uint8_t)(len - COAP_MESSAGE_SIZE_OFFSET_TCP16);
  ------------------
  |  |   39|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP16 269 /* 13 + 256 */
  ------------------
 1694|      0|      pdu->token[-1] = pdu->code;
 1695|      0|      pdu->hdr_size = 4;
 1696|      0|    } else {
 1697|      0|      assert(pdu->max_hdr_size >= 6);
  ------------------
  |  Branch (1697:7): [True: 0, False: 0]
  ------------------
 1698|      0|      if (pdu->max_hdr_size < 6) {
  ------------------
  |  Branch (1698:11): [True: 0, False: 0]
  ------------------
 1699|      0|        coap_log_warn("coap_pdu_encode_header: not enough space for TCP32 header\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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1700|      0|        return 0;
 1701|      0|      }
 1702|      0|      pdu->token[-6] = 15 << 4 | e_token_length;
 1703|      0|      pdu->token[-5] = (uint8_t)((len - COAP_MESSAGE_SIZE_OFFSET_TCP32) >> 24);
  ------------------
  |  |   40|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */
  ------------------
 1704|      0|      pdu->token[-4] = (uint8_t)((len - COAP_MESSAGE_SIZE_OFFSET_TCP32) >> 16);
  ------------------
  |  |   40|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */
  ------------------
 1705|      0|      pdu->token[-3] = (uint8_t)((len - COAP_MESSAGE_SIZE_OFFSET_TCP32) >> 8);
  ------------------
  |  |   40|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */
  ------------------
 1706|      0|      pdu->token[-2] = (uint8_t)(len - COAP_MESSAGE_SIZE_OFFSET_TCP32);
  ------------------
  |  |   40|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */
  ------------------
 1707|      0|      pdu->token[-1] = pdu->code;
 1708|      0|      pdu->hdr_size = 6;
 1709|      0|    }
 1710|  1.59k|#endif /* ! COAP_DISABLE_TCP */
 1711|  1.59k|  } else {
 1712|      0|    coap_log_warn("coap_pdu_encode_header: unsupported protocol\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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1713|      0|  }
 1714|  1.59k|  return pdu->hdr_size;
 1715|  1.59k|}
coap_pdu.c:coap_pdu_parse_opt_csm:
 1226|  16.7M|coap_pdu_parse_opt_csm(coap_pdu_code_t code, coap_option_num_t option, size_t len) {
 1227|  16.7M|  switch ((coap_pdu_signaling_proto_t)code) {
 1228|  26.5k|  case COAP_SIGNALING_CSM:
  ------------------
  |  Branch (1228:3): [True: 26.5k, False: 16.6M]
  ------------------
 1229|  26.5k|    switch ((coap_sig_csm_opt_t)option) {
 1230|  2.41k|    case COAP_SIG_OPT_MAX_MESSAGE_SIZE:
  ------------------
  |  Branch (1230:5): [True: 2.41k, False: 24.1k]
  ------------------
 1231|  2.41k|      if (len > 4)
  ------------------
  |  Branch (1231:11): [True: 1.54k, False: 870]
  ------------------
 1232|  1.54k|        goto bad;
 1233|    870|      break;
 1234|  2.02k|    case COAP_SIG_OPT_BLOCK_WISE_TRANSFER:
  ------------------
  |  Branch (1234:5): [True: 2.02k, False: 24.5k]
  ------------------
 1235|  2.02k|      if (len > 0)
  ------------------
  |  Branch (1235:11): [True: 1.12k, False: 903]
  ------------------
 1236|  1.12k|        goto bad;
 1237|    903|      break;
 1238|  2.46k|    case COAP_SIG_OPT_EXTENDED_TOKEN_LENGTH:
  ------------------
  |  Branch (1238:5): [True: 2.46k, False: 24.1k]
  ------------------
 1239|  2.46k|      if (len > 3)
  ------------------
  |  Branch (1239:11): [True: 1.02k, False: 1.43k]
  ------------------
 1240|  1.02k|        goto bad;
 1241|  1.43k|      break;
 1242|  19.6k|    default:
  ------------------
  |  Branch (1242:5): [True: 19.6k, False: 6.90k]
  ------------------
 1243|  19.6k|      if (option & 0x01)
  ------------------
  |  Branch (1243:11): [True: 9.97k, False: 9.70k]
  ------------------
 1244|  9.97k|        goto bad; /* Critical */
 1245|  26.5k|    }
 1246|  12.9k|    break;
 1247|  12.9k|  case COAP_SIGNALING_PING:
  ------------------
  |  Branch (1247:3): [True: 2.44k, False: 16.7M]
  ------------------
 1248|  3.15M|  case COAP_SIGNALING_PONG:
  ------------------
  |  Branch (1248:3): [True: 3.15M, False: 13.5M]
  ------------------
 1249|  3.15M|    switch ((coap_sig_ping_opt_t)option) {
 1250|  2.12M|    case COAP_SIG_OPT_CUSTODY:
  ------------------
  |  Branch (1250:5): [True: 2.12M, False: 1.02M]
  ------------------
 1251|  2.12M|      if (len > 0)
  ------------------
  |  Branch (1251:11): [True: 1.05k, False: 2.12M]
  ------------------
 1252|  1.05k|        goto bad;
 1253|  2.12M|      break;
 1254|  2.12M|    default:
  ------------------
  |  Branch (1254:5): [True: 1.02M, False: 2.12M]
  ------------------
 1255|  1.02M|      if (option & 0x01)
  ------------------
  |  Branch (1255:11): [True: 1.02M, False: 3.58k]
  ------------------
 1256|  1.02M|        goto bad; /* Critical */
 1257|  3.15M|    }
 1258|  2.13M|    break;
 1259|  2.13M|  case COAP_SIGNALING_RELEASE:
  ------------------
  |  Branch (1259:3): [True: 23.8k, False: 16.6M]
  ------------------
 1260|  23.8k|    switch ((coap_sig_release_opt_t)option) {
 1261|  11.0k|    case COAP_SIG_OPT_ALTERNATIVE_ADDRESS:
  ------------------
  |  Branch (1261:5): [True: 11.0k, False: 12.7k]
  ------------------
 1262|  11.0k|      if (len < 1 || len > 255)
  ------------------
  |  Branch (1262:11): [True: 9.53k, False: 1.54k]
  |  Branch (1262:22): [True: 1.16k, False: 387]
  ------------------
 1263|  10.6k|        goto bad;
 1264|    387|      break;
 1265|  3.60k|    case COAP_SIG_OPT_HOLD_OFF:
  ------------------
  |  Branch (1265:5): [True: 3.60k, False: 20.2k]
  ------------------
 1266|  3.60k|      if (len > 3)
  ------------------
  |  Branch (1266:11): [True: 1.24k, False: 2.35k]
  ------------------
 1267|  1.24k|        goto bad;
 1268|  2.35k|      break;
 1269|  9.13k|    default:
  ------------------
  |  Branch (1269:5): [True: 9.13k, False: 14.6k]
  ------------------
 1270|  9.13k|      if (option & 0x01)
  ------------------
  |  Branch (1270:11): [True: 6.52k, False: 2.60k]
  ------------------
 1271|  6.52k|        goto bad; /* Critical */
 1272|  23.8k|    }
 1273|  5.35k|    break;
 1274|  1.05M|  case COAP_SIGNALING_ABORT:
  ------------------
  |  Branch (1274:3): [True: 1.05M, False: 15.6M]
  ------------------
 1275|  1.05M|    switch ((coap_sig_abort_opt_t)option) {
 1276|  1.05M|    case COAP_SIG_OPT_BAD_CSM_OPTION:
  ------------------
  |  Branch (1276:5): [True: 1.05M, False: 9.12k]
  ------------------
 1277|  1.05M|      if (len > 2)
  ------------------
  |  Branch (1277:11): [True: 1.11k, False: 1.04M]
  ------------------
 1278|  1.11k|        goto bad;
 1279|  1.04M|      break;
 1280|  1.04M|    default:
  ------------------
  |  Branch (1280:5): [True: 9.12k, False: 1.05M]
  ------------------
 1281|  9.12k|      if (option & 0x01)
  ------------------
  |  Branch (1281:11): [True: 6.72k, False: 2.40k]
  ------------------
 1282|  6.72k|        goto bad; /* Critical */
 1283|  1.05M|    }
 1284|  1.05M|    break;
 1285|  12.4M|  default:
  ------------------
  |  Branch (1285:3): [True: 12.4M, False: 4.26M]
  ------------------
 1286|  12.4M|    goto bad;
 1287|  16.7M|  }
 1288|  3.20M|  return 1;
 1289|  13.5M|bad:
 1290|  13.5M|  return 0;
 1291|  16.7M|}
coap_pdu.c:next_option_safe:
 1057|  22.2M|next_option_safe(coap_opt_t **optp, size_t *length, uint16_t *max_opt) {
 1058|  22.2M|  coap_option_t option;
 1059|  22.2M|  size_t optsize;
 1060|       |
 1061|  22.2M|  assert(optp);
  ------------------
  |  Branch (1061:3): [True: 22.2M, False: 0]
  ------------------
 1062|  22.2M|  assert(*optp);
  ------------------
  |  Branch (1062:3): [True: 22.2M, False: 0]
  ------------------
 1063|  22.2M|  assert(length);
  ------------------
  |  Branch (1063:3): [True: 22.2M, False: 0]
  ------------------
 1064|       |
 1065|  22.2M|  optsize = coap_opt_parse(*optp, *length, &option);
 1066|  22.2M|  assert(optsize <= *length);
  ------------------
  |  Branch (1066:3): [True: 22.2M, False: 0]
  ------------------
 1067|       |
 1068|       |  /* signal an error if this option would exceed the
 1069|       |   * allowed number space */
 1070|  22.2M|  if ((uint32_t)(*max_opt) + option.delta > COAP_MAX_OPT) {
  ------------------
  |  |  105|  22.2M|#define COAP_MAX_OPT 65535 /**< the highest option number we know */
  ------------------
  |  Branch (1070:7): [True: 24, False: 22.2M]
  ------------------
 1071|     24|    return 0;
 1072|     24|  }
 1073|  22.2M|  *max_opt += option.delta;
 1074|  22.2M|  *optp += optsize;
 1075|  22.2M|  *length -= optsize;
 1076|       |
 1077|  22.2M|  return optsize;
 1078|  22.2M|}
coap_pdu.c:write_prefix:
 1417|   101k|write_prefix(char **obp, size_t *len, const char *prf, size_t prflen) {
 1418|       |  /* Make sure space for null terminating byte */
 1419|   101k|  if (*len < prflen +1) {
  ------------------
  |  Branch (1419:7): [True: 36, False: 101k]
  ------------------
 1420|     36|    return 0;
 1421|     36|  }
 1422|       |
 1423|   101k|  memcpy(*obp, prf, prflen);
 1424|   101k|  *obp += prflen;
 1425|   101k|  *len -= prflen;
 1426|   101k|  return 1;
 1427|   101k|}
coap_pdu.c:write_char:
 1430|  1.07M|write_char(char **obp, size_t *len, int c, int printable) {
 1431|       |  /* Make sure space for null terminating byte */
 1432|  1.07M|  if (*len < 2 +1) {
  ------------------
  |  Branch (1432:7): [True: 892, False: 1.07M]
  ------------------
 1433|    892|    return 0;
 1434|    892|  }
 1435|       |
 1436|  1.07M|  if (!printable) {
  ------------------
  |  Branch (1436:7): [True: 536k, False: 536k]
  ------------------
 1437|   536k|    const uint8_t hex[] = "0123456789abcdef";
 1438|   536k|    (*obp)[0] = hex[(c & 0xf0) >> 4];
 1439|   536k|    (*obp)[1] = hex[c & 0x0f];
 1440|   536k|  } else {
 1441|   536k|    (*obp)[0] = isprint(c) ? c : '.';
  ------------------
  |  Branch (1441:17): [True: 85.8k, False: 451k]
  ------------------
 1442|   536k|    (*obp)[1] = ' ';
 1443|   536k|  }
 1444|  1.07M|  *obp += 2;
 1445|  1.07M|  *len -= 2;
 1446|  1.07M|  return 1;
 1447|  1.07M|}

coap_prng_init_lkd:
  180|  3.10k|coap_prng_init_lkd(unsigned int seed) {
  181|  3.10k|#ifdef HAVE_GETRANDOM
  182|       |  /* No seed to seed the random source if getrandom() is used */
  183|  3.10k|  (void)seed;
  184|       |#elif defined(HAVE_RANDOM)
  185|       |  srandom(seed);
  186|       |#else /* !HAVE_GETRANDOM  && !HAVE_RANDOM */
  187|       |  srand(seed);
  188|       |#endif /* !HAVE_GETRANDOM */
  189|  3.10k|}
coap_prng_lkd:
  192|  3.10k|coap_prng_lkd(void *buf, size_t len) {
  193|  3.10k|  if (!rand_func) {
  ------------------
  |  Branch (193:7): [True: 0, False: 3.10k]
  ------------------
  194|      0|    return 0;
  195|      0|  }
  196|       |
  197|  3.10k|  return rand_func(buf, len);
  198|  3.10k|}
coap_prng.c:coap_prng_default:
  110|  3.10k|coap_prng_default(void *buf, size_t len) {
  111|       |#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
  112|       |  /* mbedtls_hardware_poll() returns 0 on success */
  113|       |  return (mbedtls_hardware_poll(NULL, buf, len, NULL) ? 0 : 1);
  114|       |
  115|       |#elif defined(__ZEPHYR__)
  116|       |  /* Use Zephyr's cryptographically secure random number generator */
  117|       |  if (!buf || len == 0) {
  118|       |    return 0;
  119|       |  }
  120|       |
  121|       |  /* sys_csrand_get() returns 0 on success */
  122|       |  return (sys_csrand_get(buf, len) ? 0 : 1);
  123|       |
  124|       |#elif defined(HAVE_GETRANDOM)
  125|  3.10k|  return (getrandom(buf, len, 0) > 0) ? 1 : 0;
  ------------------
  |  Branch (125:10): [True: 3.10k, False: 0]
  ------------------
  126|       |
  127|       |#elif defined(HAVE_RANDOM)
  128|       |#define RAND_BYTES (RAND_MAX >= 0xffffff ? 3 : (RAND_MAX >= 0xffff ? 2 : 1))
  129|       |  unsigned char *dst = (unsigned char *)buf;
  130|       |
  131|       |  if (len) {
  132|       |    uint8_t byte_counter = RAND_BYTES;
  133|       |    uint32_t r_v = random();
  134|       |
  135|       |    while (1) {
  136|       |      *dst++ = r_v & 0xFF;
  137|       |      if (!--len) {
  138|       |        break;
  139|       |      }
  140|       |      if (--byte_counter) {
  141|       |        r_v >>= 8;
  142|       |      } else {
  143|       |        r_v = random();
  144|       |        byte_counter = RAND_BYTES;
  145|       |      }
  146|       |    }
  147|       |  }
  148|       |  return 1;
  149|       |#elif defined(RIOT_VERSION)
  150|       |#include <random.h>
  151|       |  random_bytes(buf, len);
  152|       |  return 1;
  153|       |
  154|       |#elif defined(WITH_CONTIKI)
  155|       |  return csprng_rand(buf, len);
  156|       |
  157|       |#elif defined(_WIN32)
  158|       |  return coap_prng_impl(buf,len);
  159|       |
  160|       |#else /* !MBEDTLS_ENTROPY_HARDWARE_ALT && !HAVE_GETRANDOM &&
  161|       |         !HAVE_RANDOM && !_WIN32 */
  162|       |#error "CVE-2021-34430: using rand() for crypto randoms is not secure!"
  163|       |#error "Please update you C-library and rerun the auto-configuration."
  164|       |  unsigned char *dst = (unsigned char *)buf;
  165|       |  while (len--)
  166|       |    *dst++ = rand() & 0xFF;
  167|       |  return 1;
  168|       |#endif /* !MBEDTLS_ENTROPY_HARDWARE_ALT && !HAVE_GETRANDOM &&
  169|       |          !HAVE_RANDOM && !_WIN32 */
  170|  3.10k|}

coap_new_string:
   21|  1.45k|coap_new_string(size_t size) {
   22|  1.45k|  coap_string_t *s;
   23|       |#if defined(WITH_LWIP) && MEMP_USE_CUSTOM_POOLS && ! MEM_USE_POOLS
   24|       |  if (size >= MEMP_LEN_COAPSTRING) {
   25|       |    coap_log_crit("coap_new_string: size too large (%" PRIuS " +1 > MEMP_LEN_COAPSTRING)\n",
   26|       |                  size);
   27|       |    return NULL;
   28|       |  }
   29|       |#endif /* WITH_LWIP && MEMP_USE_CUSTOM_POOLS */
   30|       |  /* Check no overflow (including a 8 byte small headroom) */
   31|  1.45k|  if (size > SIZE_MAX - sizeof(coap_str_bin_union_t) - 1 - 8) {
  ------------------
  |  Branch (31:7): [True: 0, False: 1.45k]
  ------------------
   32|      0|    return NULL;
   33|      0|  }
   34|       |
   35|  1.45k|  s = (coap_string_t *)coap_malloc_type(COAP_STRING,
   36|  1.45k|                                        sizeof(coap_str_bin_union_t) + size + 1);
   37|  1.45k|  if (!s) {
  ------------------
  |  Branch (37:7): [True: 0, False: 1.45k]
  ------------------
   38|      0|    coap_log_crit("coap_new_string: malloc: failed\n");
  ------------------
  |  |   96|      0|#define coap_log_crit(...) coap_log(COAP_LOG_CRIT, __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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   39|      0|    return NULL;
   40|      0|  }
   41|       |
   42|  1.45k|  memset(s, 0, sizeof(coap_str_bin_union_t));
   43|  1.45k|  s->s = ((unsigned char *)s) + sizeof(coap_str_bin_union_t);
   44|  1.45k|  s->s[size] = '\000';
   45|  1.45k|  s->length = size;
   46|  1.45k|  return s;
   47|  1.45k|}
coap_delete_string:
   50|  3.18k|coap_delete_string(coap_string_t *s) {
   51|  3.18k|  coap_free_type(COAP_STRING, s);
   52|  3.18k|}
coap_delete_binary:
  114|  3.10k|coap_delete_binary(coap_binary_t *s) {
  115|  3.10k|  coap_free_type(COAP_STRING, s);
  116|  3.10k|}

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

coap_clock_init:
   68|  3.10k|coap_clock_init(void) {
   69|  3.10k|#ifdef COAP_CLOCK
   70|  3.10k|  struct timespec tv;
   71|  3.10k|  clock_gettime(COAP_CLOCK, &tv);
  ------------------
  |  |   43|  3.10k|#define COAP_CLOCK CLOCK_REALTIME
  ------------------
   72|       |#else /* _POSIX_TIMERS */
   73|       |  struct timeval tv;
   74|       |  gettimeofday(&tv, NULL);
   75|       |#endif /* not _POSIX_TIMERS */
   76|       |
   77|  3.10k|  coap_clock_offset = tv.tv_sec;
   78|  3.10k|}
coap_ticks:
   90|  3.10k|coap_ticks(coap_tick_t *t) {
   91|  3.10k|  coap_tick_t tmp;
   92|       |
   93|  3.10k|#ifdef COAP_CLOCK
   94|  3.10k|  struct timespec tv;
   95|  3.10k|  clock_gettime(COAP_CLOCK, &tv);
  ------------------
  |  |   43|  3.10k|#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|  3.10k|  tmp = SHR_FP(tv.tv_nsec * Q(FRAC, (COAP_TICKS_PER_SECOND/1000000000.0)), FRAC);
  ------------------
  |  |   87|  3.10k|#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|  3.10k|  *t = tmp + (tv.tv_sec - coap_clock_offset) * COAP_TICKS_PER_SECOND;
  ------------------
  |  |  164|  3.10k|#define COAP_TICKS_PER_SECOND ((coap_tick_t)(1000U))
  ------------------
  120|  3.10k|}
coap_ticks_to_rt_us:
  128|  3.10k|coap_ticks_to_rt_us(coap_tick_t t) {
  129|  3.10k|  return (uint64_t)coap_clock_offset * 1000000 + (uint64_t)t * 1000000 / COAP_TICKS_PER_SECOND;
  ------------------
  |  |  164|  3.10k|#define COAP_TICKS_PER_SECOND ((coap_tick_t)(1000U))
  ------------------
  130|  3.10k|}

coap_split_proxy_uri:
  351|    529|coap_split_proxy_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri) {
  352|    529|  return coap_split_uri_sub(str_var, len, uri, COAP_URI_CHECK_PROXY);
  353|    529|}
coap_check_dots:
  668|  4.02M|coap_check_dots(const uint8_t *s, size_t len) {
  669|  4.02M|  uint8_t p;
  670|       |
  671|  4.02M|  if (!len)
  ------------------
  |  Branch (671:7): [True: 3.87M, False: 150k]
  ------------------
  672|  3.87M|    return 0;
  673|       |
  674|   150k|  p = *s;
  675|       |
  676|       |  /* Check 'first' char */
  677|   150k|  if (p == '%' && len >=3) {
  ------------------
  |  Branch (677:7): [True: 3.22k, False: 147k]
  |  Branch (677:19): [True: 3.00k, False: 220]
  ------------------
  678|  3.00k|    if (s[1] == '2' && (s[2] == 'E' || s[2] == 'e')) {
  ------------------
  |  Branch (678:9): [True: 872, False: 2.12k]
  |  Branch (678:25): [True: 396, False: 476]
  |  Branch (678:40): [True: 201, False: 275]
  ------------------
  679|    597|      s += 2;
  680|    597|      len -= 2;
  681|    597|    }
  682|  3.00k|    p = '.';
  683|  3.00k|  }
  684|   150k|  if (p != '.')
  ------------------
  |  Branch (684:7): [True: 145k, False: 5.02k]
  ------------------
  685|   145k|    return 0;
  686|  5.02k|  if (len == 1)
  ------------------
  |  Branch (686:7): [True: 1.30k, False: 3.71k]
  ------------------
  687|  1.30k|    return 1;
  688|       |
  689|       |  /* Check 'second' char, first is '.' */
  690|  3.71k|  s++;
  691|  3.71k|  len--;
  692|  3.71k|  assert(len);
  ------------------
  |  Branch (692:3): [True: 3.71k, False: 0]
  ------------------
  693|  3.71k|  p = *s;
  694|  3.71k|  if (p == '%' && len >=3) {
  ------------------
  |  Branch (694:7): [True: 2.04k, False: 1.67k]
  |  Branch (694:19): [True: 1.67k, False: 367]
  ------------------
  695|  1.67k|    if (s[1] == '2' && (s[2] == 'E' || s[2] == 'e')) {
  ------------------
  |  Branch (695:9): [True: 1.29k, False: 379]
  |  Branch (695:25): [True: 267, False: 1.03k]
  |  Branch (695:40): [True: 729, False: 303]
  ------------------
  696|    996|      len -= 2;
  697|    996|    }
  698|  1.67k|    p = '.';
  699|  1.67k|  }
  700|  3.71k|  if (p != '.')
  ------------------
  |  Branch (700:7): [True: 1.49k, False: 2.22k]
  ------------------
  701|  1.49k|    return 0;
  702|  2.22k|  if (len == 1)
  ------------------
  |  Branch (702:7): [True: 1.44k, False: 783]
  ------------------
  703|  1.44k|    return 2;
  704|       |
  705|    783|  return 0;
  706|  2.22k|}
coap_get_query:
 1103|  1.59k|coap_get_query(const coap_pdu_t *request) {
 1104|  1.59k|  coap_opt_iterator_t opt_iter;
 1105|  1.59k|  coap_opt_filter_t f;
 1106|  1.59k|  coap_opt_t *q;
 1107|  1.59k|  coap_string_t *query = NULL;
 1108|  1.59k|  size_t length = 0;
 1109|  1.59k|  static const uint8_t hex[] = "0123456789ABCDEF";
 1110|       |
 1111|  1.59k|  coap_option_filter_clear(&f);
 1112|  1.59k|  coap_option_filter_set(&f, COAP_OPTION_URI_QUERY);
 1113|  1.59k|  coap_option_iterator_init(request, &opt_iter, &f);
 1114|   144k|  while ((q = coap_option_next(&opt_iter))) {
  ------------------
  |  Branch (1114:10): [True: 142k, False: 1.59k]
  ------------------
 1115|   142k|    uint16_t seg_len = coap_opt_length(q), i;
 1116|   142k|    const uint8_t *seg= coap_opt_value(q);
 1117|  1.45M|    for (i = 0; i < seg_len; i++) {
  ------------------
  |  Branch (1117:17): [True: 1.31M, False: 142k]
  ------------------
 1118|  1.31M|      if (is_unescaped_in_query(seg[i]))
  ------------------
  |  Branch (1118:11): [True: 14.7k, False: 1.30M]
  ------------------
 1119|  14.7k|        length += 1;
 1120|  1.30M|      else
 1121|  1.30M|        length += 3;
 1122|  1.31M|    }
 1123|   142k|    length += 1;
 1124|   142k|  }
 1125|  1.59k|  if (length > 0)
  ------------------
  |  Branch (1125:7): [True: 286, False: 1.30k]
  ------------------
 1126|    286|    length -= 1;
 1127|  1.59k|  if (length > 0) {
  ------------------
  |  Branch (1127:7): [True: 286, False: 1.30k]
  ------------------
 1128|    286|    query = coap_new_string(length);
 1129|    286|    if (query) {
  ------------------
  |  Branch (1129:9): [True: 286, False: 0]
  ------------------
 1130|    286|      query->length = length;
 1131|    286|      unsigned char *s = query->s;
 1132|    286|      coap_option_iterator_init(request, &opt_iter, &f);
 1133|   143k|      while ((q = coap_option_next(&opt_iter))) {
  ------------------
  |  Branch (1133:14): [True: 142k, False: 286]
  ------------------
 1134|   142k|        if (s != query->s)
  ------------------
  |  Branch (1134:13): [True: 142k, False: 286]
  ------------------
 1135|   142k|          *s++ = '&';
 1136|   142k|        uint16_t seg_len = coap_opt_length(q), i;
 1137|   142k|        const uint8_t *seg= coap_opt_value(q);
 1138|  1.45M|        for (i = 0; i < seg_len; i++) {
  ------------------
  |  Branch (1138:21): [True: 1.31M, False: 142k]
  ------------------
 1139|  1.31M|          if (is_unescaped_in_query(seg[i])) {
  ------------------
  |  Branch (1139:15): [True: 14.7k, False: 1.30M]
  ------------------
 1140|  14.7k|            *s++ = seg[i];
 1141|  1.30M|          } else {
 1142|  1.30M|            *s++ = '%';
 1143|  1.30M|            *s++ = hex[seg[i]>>4];
 1144|  1.30M|            *s++ = hex[seg[i]&0x0F];
 1145|  1.30M|          }
 1146|  1.31M|        }
 1147|   142k|      }
 1148|    286|    }
 1149|    286|  }
 1150|  1.59k|  return query;
 1151|  1.59k|}
coap_map_abbrev_uri_path:
 1154|     15|coap_map_abbrev_uri_path(coap_upa_chain_t *chain, uint32_t value) {
 1155|     15|  while (chain) {
  ------------------
  |  Branch (1155:10): [True: 0, False: 15]
  ------------------
 1156|      0|    coap_upa_chain_t *next = chain->next;
 1157|       |
 1158|      0|    if (chain->upa_value == value) {
  ------------------
  |  Branch (1158:9): [True: 0, False: 0]
  ------------------
 1159|      0|      return chain->upa_path;
 1160|      0|    }
 1161|      0|    chain = next;
 1162|      0|  }
 1163|     15|  return NULL;
 1164|     15|}
coap_get_uri_path:
 1182|  1.59k|coap_get_uri_path(const coap_pdu_t *request) {
 1183|  1.59k|  coap_opt_iterator_t opt_iter;
 1184|  1.59k|  coap_opt_filter_t f;
 1185|  1.59k|  coap_opt_t *q;
 1186|  1.59k|  coap_string_t *uri_path = NULL;
 1187|  1.59k|  size_t length = 0;
 1188|  1.59k|  static const uint8_t hex[] = "0123456789ABCDEF";
 1189|       |
 1190|  1.59k|  q = coap_check_option(request, COAP_OPTION_URI_PATH_ABB, &opt_iter);
 1191|  1.59k|  if (q) {
  ------------------
  |  Branch (1191:7): [True: 25, False: 1.56k]
  ------------------
 1192|     25|    uint32_t value;
 1193|     25|    const char *exp;
 1194|     25|    if (coap_check_option(request, COAP_OPTION_PROXY_URI, &opt_iter) ||
  ------------------
  |  Branch (1194:9): [True: 5, False: 20]
  ------------------
 1195|     20|        coap_check_option(request, COAP_OPTION_URI_PATH, &opt_iter)) {
  ------------------
  |  Branch (1195:9): [True: 5, False: 15]
  ------------------
 1196|     10|      return NULL;
 1197|     10|    }
 1198|     15|    value = coap_decode_var_bytes(coap_opt_value(q), coap_opt_length(q));
 1199|     15|    exp = coap_map_abbrev_uri_path(coap_upa_server_mapping_chain, value);
 1200|     15|    if (exp) {
  ------------------
  |  Branch (1200:9): [True: 0, False: 15]
  ------------------
 1201|      0|      uri_path = coap_new_string(strlen(exp));
 1202|      0|      if (uri_path) {
  ------------------
  |  Branch (1202:11): [True: 0, False: 0]
  ------------------
 1203|      0|        memcpy(uri_path->s, exp, strlen(exp));
 1204|      0|      }
 1205|      0|      return uri_path;
 1206|      0|    }
 1207|     15|    return NULL;
 1208|     15|  }
 1209|  1.56k|  q = coap_check_option(request, COAP_OPTION_PROXY_URI, &opt_iter);
 1210|  1.56k|  if (q) {
  ------------------
  |  Branch (1210:7): [True: 529, False: 1.03k]
  ------------------
 1211|    529|    coap_uri_t uri;
 1212|       |
 1213|    529|    if (coap_split_proxy_uri(coap_opt_value(q),
  ------------------
  |  Branch (1213:9): [True: 396, False: 133]
  ------------------
 1214|    529|                             coap_opt_length(q), &uri) < 0) {
 1215|    396|      return NULL;
 1216|    396|    }
 1217|    133|    uri_path = coap_new_string(uri.path.length);
 1218|    133|    if (uri_path && uri.path.length) {
  ------------------
  |  Branch (1218:9): [True: 133, False: 0]
  |  Branch (1218:21): [True: 34, False: 99]
  ------------------
 1219|     34|      memcpy(uri_path->s, uri.path.s, uri.path.length);
 1220|     34|    }
 1221|    133|    return uri_path;
 1222|    529|  }
 1223|       |
 1224|  1.03k|  coap_option_filter_clear(&f);
 1225|  1.03k|  coap_option_filter_set(&f, COAP_OPTION_URI_PATH);
 1226|  1.03k|  coap_option_iterator_init(request, &opt_iter, &f);
 1227|  4.01M|  while ((q = coap_option_next(&opt_iter))) {
  ------------------
  |  Branch (1227:10): [True: 4.00M, False: 1.03k]
  ------------------
 1228|  4.00M|    uint16_t seg_len = coap_opt_length(q), i;
 1229|  4.00M|    const uint8_t *seg = coap_opt_value(q);
 1230|  5.17M|    for (i = 0; i < seg_len; i++) {
  ------------------
  |  Branch (1230:17): [True: 1.16M, False: 4.00M]
  ------------------
 1231|  1.16M|      if (is_unescaped_in_path(seg[i]))
  ------------------
  |  Branch (1231:11): [True: 19.5k, False: 1.14M]
  ------------------
 1232|  19.5k|        length += 1;
 1233|  1.14M|      else
 1234|  1.14M|        length += 3;
 1235|  1.16M|    }
 1236|       |    /* bump for the leading "/" */
 1237|  4.00M|    length += 1;
 1238|  4.00M|  }
 1239|       |  /* The first entry does not have a leading "/" */
 1240|  1.03k|  if (length > 0)
  ------------------
  |  Branch (1240:7): [True: 419, False: 617]
  ------------------
 1241|    419|    length -= 1;
 1242|       |
 1243|       |  /* if 0, either no URI_PATH Option, or the first one was empty */
 1244|  1.03k|  uri_path = coap_new_string(length);
 1245|  1.03k|  if (uri_path) {
  ------------------
  |  Branch (1245:7): [True: 1.03k, False: 0]
  ------------------
 1246|  1.03k|    uri_path->length = length;
 1247|  1.03k|    unsigned char *s = uri_path->s;
 1248|  1.03k|    int n = 0;
 1249|  1.03k|    coap_option_iterator_init(request, &opt_iter, &f);
 1250|  4.01M|    while ((q = coap_option_next(&opt_iter))) {
  ------------------
  |  Branch (1250:12): [True: 4.00M, False: 1.03k]
  ------------------
 1251|  4.00M|      if (n++) {
  ------------------
  |  Branch (1251:11): [True: 4.00M, False: 419]
  ------------------
 1252|  4.00M|        *s++ = '/';
 1253|  4.00M|      }
 1254|  4.00M|      uint16_t seg_len = coap_opt_length(q), i;
 1255|  4.00M|      const uint8_t *seg= coap_opt_value(q);
 1256|  5.17M|      for (i = 0; i < seg_len; i++) {
  ------------------
  |  Branch (1256:19): [True: 1.16M, False: 4.00M]
  ------------------
 1257|  1.16M|        if (is_unescaped_in_path(seg[i])) {
  ------------------
  |  Branch (1257:13): [True: 19.5k, False: 1.14M]
  ------------------
 1258|  19.5k|          *s++ = seg[i];
 1259|  1.14M|        } else {
 1260|  1.14M|          *s++ = '%';
 1261|  1.14M|          *s++ = hex[seg[i]>>4];
 1262|  1.14M|          *s++ = hex[seg[i]&0x0F];
 1263|  1.14M|        }
 1264|  1.16M|      }
 1265|  4.00M|    }
 1266|  1.03k|  }
 1267|  1.03k|  return uri_path;
 1268|  1.56k|}
coap_delete_upa_chain:
 1271|  6.20k|coap_delete_upa_chain(coap_upa_chain_t *chain) {
 1272|  6.20k|  while (chain) {
  ------------------
  |  Branch (1272:10): [True: 0, False: 6.20k]
  ------------------
 1273|      0|    coap_upa_chain_t *next = chain->next;
 1274|       |
 1275|      0|    coap_free_type(COAP_STRING, chain);
 1276|      0|    chain = next;
 1277|      0|  }
 1278|  6.20k|}
coap_uri.c:coap_split_uri_sub:
   84|    529|                   coap_uri_check_t check_proxy) {
   85|    529|  const uint8_t *p, *q;
   86|    529|  int res = 0;
   87|    529|  size_t i;
   88|    529|  int is_unix_domain = 0;
   89|    529|  int is_llc = 0;
   90|       |
   91|    529|  if (!str_var || !uri || len == 0)
  ------------------
  |  Branch (91:7): [True: 0, False: 529]
  |  Branch (91:19): [True: 0, False: 529]
  |  Branch (91:27): [True: 0, False: 529]
  ------------------
   92|      0|    return -1;
   93|       |
   94|    529|  memset(uri, 0, sizeof(coap_uri_t));
   95|    529|  uri->port = COAP_DEFAULT_PORT;
  ------------------
  |  |   39|    529|#define COAP_DEFAULT_PORT      5683 /* CoAP default UDP/TCP port */
  ------------------
   96|       |
   97|       |  /* search for scheme */
   98|    529|  p = str_var;
   99|    529|  if (*p == '/') {
  ------------------
  |  Branch (99:7): [True: 2, False: 527]
  ------------------
  100|       |    /* no scheme, host or port */
  101|      2|    if (check_proxy == COAP_URI_CHECK_PROXY) {
  ------------------
  |  Branch (101:9): [True: 2, False: 0]
  ------------------
  102|       |      /* Must have ongoing host if proxy definition */
  103|      2|      return -1;
  104|      2|    }
  105|      0|    q = p;
  106|      0|    goto path;
  107|      2|  }
  108|       |
  109|       |  /* find scheme terminating :// */
  110|  10.0k|  while (len >= 3 && !(p[0] == ':' && p[1] == '/' && p[2] == '/')) {
  ------------------
  |  Branch (110:10): [True: 9.96k, False: 56]
  |  Branch (110:24): [True: 1.12k, False: 8.83k]
  |  Branch (110:39): [True: 686, False: 443]
  |  Branch (110:54): [True: 471, False: 215]
  ------------------
  111|  9.49k|    ++p;
  112|  9.49k|    --len;
  113|  9.49k|  }
  114|    527|  if (len < 3) {
  ------------------
  |  Branch (114:7): [True: 56, False: 471]
  ------------------
  115|       |    /* scheme not defined with a :// terminator */
  116|     56|    res = -2;
  117|     56|    goto error;
  118|     56|  }
  119|  1.98k|  for (i = 0; i < COAP_URI_SCHEME_LAST; i++) {
  ------------------
  |  Branch (119:15): [True: 1.88k, False: 97]
  ------------------
  120|  1.88k|    if ((p - str_var) == (int)strlen(coap_uri_scheme[i].name) &&
  ------------------
  |  Branch (120:9): [True: 678, False: 1.20k]
  ------------------
  121|    678|        memcmp(str_var, coap_uri_scheme[i].name, p - str_var) == 0) {
  ------------------
  |  Branch (121:9): [True: 374, False: 304]
  ------------------
  122|    374|      if (check_proxy != COAP_URI_CHECK_PROXY && coap_uri_scheme[i].proxy_only) {
  ------------------
  |  Branch (122:11): [True: 0, False: 374]
  |  Branch (122:50): [True: 0, False: 0]
  ------------------
  123|      0|        coap_log_err("%.*s URI scheme not enabled (not a proxy)\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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  124|      0|                     (int)(p - str_var), str_var);
  125|      0|        return -1;
  126|      0|      }
  127|    374|      uri->scheme = coap_uri_scheme[i].scheme;
  128|    374|      uri->port = coap_uri_scheme[i].port;
  129|    374|      break;
  130|    374|    }
  131|  1.88k|  }
  132|    471|  if (i == COAP_URI_SCHEME_LAST) {
  ------------------
  |  Branch (132:7): [True: 97, False: 374]
  ------------------
  133|       |    /* scheme unknown */
  134|     97|    coap_log_err("%.*s URI scheme unknown\n", (int)(p - str_var), str_var);
  ------------------
  |  |  102|     97|#define coap_log_err(...) coap_log(COAP_LOG_ERR, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     97|#define coap_log(level, ...) do { \
  |  |  |  |  291|     97|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 97]
  |  |  |  |  ------------------
  |  |  |  |  292|     97|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     97|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 97]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  135|     97|    res = -1;
  136|     97|    goto error;
  137|     97|  }
  138|    374|  switch (uri->scheme) {
  139|    190|  case COAP_URI_SCHEME_COAP:
  ------------------
  |  Branch (139:3): [True: 190, False: 184]
  ------------------
  140|    190|    break;
  141|      4|  case COAP_URI_SCHEME_COAPS:
  ------------------
  |  Branch (141:3): [True: 4, False: 370]
  ------------------
  142|      4|    if (!coap_dtls_is_supported()) {
  ------------------
  |  Branch (142:9): [True: 0, False: 4]
  ------------------
  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|      4|    break;
  147|      4|  case COAP_URI_SCHEME_COAP_TCP:
  ------------------
  |  Branch (147:3): [True: 1, False: 373]
  ------------------
  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|      2|  case COAP_URI_SCHEME_COAPS_TCP:
  ------------------
  |  Branch (153:3): [True: 2, False: 372]
  ------------------
  154|      2|    if (!coap_tls_is_supported()) {
  ------------------
  |  Branch (154:9): [True: 0, False: 2]
  ------------------
  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|      2|    break;
  159|      2|  case COAP_URI_SCHEME_COAP_WS:
  ------------------
  |  Branch (159:3): [True: 2, False: 372]
  ------------------
  160|      2|    if (!coap_ws_is_supported()) {
  ------------------
  |  Branch (160:9): [True: 0, False: 2]
  ------------------
  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|      2|    break;
  165|      2|  case COAP_URI_SCHEME_COAPS_WS:
  ------------------
  |  Branch (165:3): [True: 1, False: 373]
  ------------------
  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|    166|  case COAP_URI_SCHEME_HTTP:
  ------------------
  |  Branch (171:3): [True: 166, False: 208]
  ------------------
  172|    174|  case COAP_URI_SCHEME_HTTPS:
  ------------------
  |  Branch (172:3): [True: 8, False: 366]
  ------------------
  173|       |    /* Not proxy, caught above.  For proxy, assume app is doing CoAP <> HTTP mapping. */
  174|    174|    break;
  175|      0|  case COAP_URI_SCHEME_LAST:
  ------------------
  |  Branch (175:3): [True: 0, False: 374]
  ------------------
  176|      0|  default:
  ------------------
  |  Branch (176:3): [True: 0, False: 374]
  ------------------
  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|    374|  }
  180|       |  /* skip :// */
  181|    374|  p += 3;
  182|    374|  len -= 3;
  183|       |
  184|       |  /* p points to beginning of Uri-Host */
  185|    374|  q = p;
  186|       |
  187|    374|  if (len && *p == '[') {
  ------------------
  |  Branch (187:7): [True: 366, False: 8]
  |  Branch (187:14): [True: 32, False: 334]
  ------------------
  188|       |    /* IPv6 address reference or Unix domain */
  189|     32|    ++p;
  190|     32|    ++q;
  191|     32|    --len;
  192|       |
  193|  1.50k|    while (len && *q != ']') {
  ------------------
  |  Branch (193:12): [True: 1.49k, False: 16]
  |  Branch (193:19): [True: 1.47k, False: 16]
  ------------------
  194|  1.47k|      ++q;
  195|  1.47k|      --len;
  196|  1.47k|    }
  197|       |
  198|     32|    if (!len || *q != ']' || p == q) {
  ------------------
  |  Branch (198:9): [True: 16, False: 16]
  |  Branch (198:17): [True: 0, False: 16]
  |  Branch (198:30): [True: 1, False: 15]
  ------------------
  199|     17|      res = -3;
  200|     17|      goto error;
  201|     17|    }
  202|       |
  203|     15|    COAP_SET_STR(&uri->host, q - p, p);
  ------------------
  |  |   52|     15|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  204|     15|    ++q;
  205|     15|    --len;
  206|     15|#if COAP_AF_LLC_SUPPORT
  207|    342|  } else if ((len >= LLC_HOST_LEN) && strncmp((const char *)p, "llc[", 4) == 0) {
  ------------------
  |  |  178|    342|#define LLC_HOST_LEN (4 + HW_ADDRSTRLEN + 4)
  |  |  ------------------
  |  |  |  |  176|    342|#define HW_ADDRSTRLEN 17
  |  |  ------------------
  ------------------
  |  Branch (207:14): [True: 222, False: 120]
  |  Branch (207:39): [True: 132, False: 90]
  ------------------
  208|    132|    unsigned long sap = 0;
  209|       |
  210|    132|    is_llc = 1;
  211|       |
  212|  5.65k|    while (len && *q != ']') {
  ------------------
  |  Branch (212:12): [True: 5.64k, False: 10]
  |  Branch (212:19): [True: 5.52k, False: 122]
  ------------------
  213|  5.52k|      ++q;
  214|  5.52k|      --len;
  215|  5.52k|    }
  216|       |
  217|    132|    if (!len || *q != ']' || p == q) {
  ------------------
  |  Branch (217:9): [True: 10, False: 122]
  |  Branch (217:17): [True: 0, False: 122]
  |  Branch (217:30): [True: 0, False: 122]
  ------------------
  218|     10|      res = -7;
  219|     10|      goto error;
  220|     10|    }
  221|       |
  222|    122|    ++q;
  223|    122|    --len;
  224|       |
  225|    122|    if (!len || *q != ':') {
  ------------------
  |  Branch (225:9): [True: 2, False: 120]
  |  Branch (225:17): [True: 18, False: 102]
  ------------------
  226|     20|      coap_log_warn("LLC SAP missing in URI\n");
  ------------------
  |  |  108|     20|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     20|#define coap_log(level, ...) do { \
  |  |  |  |  291|     20|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 20]
  |  |  |  |  ------------------
  |  |  |  |  292|     20|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     20|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 20]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  227|     20|      res = -7;
  228|     20|      goto error;
  229|     20|    }
  230|       |
  231|    102|    ++q;
  232|    102|    --len;
  233|       |
  234|  1.81k|    while (len && isxdigit(*q)) {
  ------------------
  |  Branch (234:12): [True: 1.79k, False: 22]
  |  Branch (234:19): [True: 1.71k, False: 80]
  ------------------
  235|  1.71k|      if (*q >= 'a' && *q <= 'f')
  ------------------
  |  Branch (235:11): [True: 865, False: 845]
  |  Branch (235:24): [True: 865, False: 0]
  ------------------
  236|    865|        sap = sap * 16 + (*q - 'a' + 10);
  237|    845|      else if (*q >= 'A' && *q <= 'F')
  ------------------
  |  Branch (237:16): [True: 562, False: 283]
  |  Branch (237:29): [True: 562, False: 0]
  ------------------
  238|    562|        sap = sap * 16 + (*q - 'A' + 10);
  239|       |
  240|  1.71k|      ++q;
  241|  1.71k|      --len;
  242|  1.71k|    }
  243|       |
  244|    102|    if (sap > UINT8_MAX) {
  ------------------
  |  Branch (244:9): [True: 84, False: 18]
  ------------------
  245|     84|      coap_log_warn("LLC SAP invalid (%lu > 255)\n", sap);
  ------------------
  |  |  108|     84|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     84|#define coap_log(level, ...) do { \
  |  |  |  |  291|     84|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 84]
  |  |  |  |  ------------------
  |  |  |  |  292|     84|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     84|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 84]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  246|     84|      res = -7;
  247|     84|      goto error;
  248|     84|    }
  249|       |
  250|     18|    COAP_SET_STR(&uri->host, q - p, p);
  ------------------
  |  |   52|     18|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  251|     18|#endif /* COAP_AF_LLC_SUPPORT */
  252|    210|  } else {
  253|       |    /* IPv4 address, FQDN or Unix domain socket */
  254|    210|    if (len >= 3 && p[0] == '%' && p[1] == '2' &&
  ------------------
  |  Branch (254:9): [True: 183, False: 27]
  |  Branch (254:21): [True: 31, False: 152]
  |  Branch (254:36): [True: 17, False: 14]
  ------------------
  255|     17|        (p[2] == 'F' || p[2] == 'f')) {
  ------------------
  |  Branch (255:10): [True: 1, False: 16]
  |  Branch (255:25): [True: 2, False: 14]
  ------------------
  256|       |      /* Unix domain definition */
  257|      3|      uri->port = 0;
  258|      3|      is_unix_domain = 1;
  259|      3|    }
  260|  8.71k|    while (len && *q != ':' && *q != '/' && *q != '?') {
  ------------------
  |  Branch (260:12): [True: 8.64k, False: 71]
  |  Branch (260:19): [True: 8.55k, False: 96]
  |  Branch (260:32): [True: 8.51k, False: 36]
  |  Branch (260:45): [True: 8.50k, False: 7]
  ------------------
  261|  8.50k|      ++q;
  262|  8.50k|      --len;
  263|  8.50k|    }
  264|       |
  265|    210|    if (p == q) {
  ------------------
  |  Branch (265:9): [True: 11, False: 199]
  ------------------
  266|     11|      res = -3;
  267|     11|      goto error;
  268|     11|    }
  269|       |
  270|    199|    if ((int)(q - p) > 255) {
  ------------------
  |  Branch (270:9): [True: 8, False: 191]
  ------------------
  271|      8|      coap_log_warn("Host name length too long (%d > 255)\n", (int)(q - p));
  ------------------
  |  |  108|      8|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      8|#define coap_log(level, ...) do { \
  |  |  |  |  291|      8|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 8]
  |  |  |  |  ------------------
  |  |  |  |  292|      8|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      8|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 8]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  272|      8|      res = -6;
  273|      8|      goto error;
  274|      8|    }
  275|       |
  276|    191|    COAP_SET_STR(&uri->host, q - p, p);
  ------------------
  |  |   52|    191|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  277|    191|  }
  278|       |
  279|       |  /* check for Uri-Port (invalid for Unix) */
  280|    224|  if (len && *q == ':') {
  ------------------
  |  Branch (280:7): [True: 161, False: 63]
  |  Branch (280:14): [True: 98, False: 63]
  ------------------
  281|     98|    if (is_unix_domain || is_llc) {
  ------------------
  |  Branch (281:9): [True: 1, False: 97]
  |  Branch (281:27): [True: 3, False: 94]
  ------------------
  282|      4|      res = -5;
  283|      4|      goto error;
  284|      4|    }
  285|     94|    p = ++q;
  286|     94|    --len;
  287|       |
  288|    661|    while (len && isdigit(*q)) {
  ------------------
  |  Branch (288:12): [True: 614, False: 47]
  |  Branch (288:19): [True: 567, False: 47]
  ------------------
  289|    567|      ++q;
  290|    567|      --len;
  291|    567|    }
  292|       |
  293|     94|    if (p < q) {                /* explicit port number given */
  ------------------
  |  Branch (293:9): [True: 56, False: 38]
  ------------------
  294|     56|      long uri_port = 0;
  295|       |
  296|    607|      while ((p < q) && (uri_port <= UINT16_MAX))
  ------------------
  |  Branch (296:14): [True: 557, False: 50]
  |  Branch (296:25): [True: 551, False: 6]
  ------------------
  297|    551|        uri_port = uri_port * 10 + (*p++ - '0');
  298|       |
  299|       |      /* check if port number is in allowed range */
  300|     56|      if (uri_port > UINT16_MAX) {
  ------------------
  |  Branch (300:11): [True: 22, False: 34]
  ------------------
  301|     22|        coap_log_warn("Port number too big (%ld > 65535)\n", uri_port);
  ------------------
  |  |  108|     22|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     22|#define coap_log(level, ...) do { \
  |  |  |  |  291|     22|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 22]
  |  |  |  |  ------------------
  |  |  |  |  292|     22|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     22|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 22]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  302|     22|        res = -4;
  303|     22|        goto error;
  304|     22|      }
  305|       |
  306|     34|      uri->port = (uint16_t)uri_port;
  307|     34|    }
  308|     94|  }
  309|       |
  310|    198|path:                 /* at this point, p must point to an absolute path */
  311|       |
  312|    198|  if (!len)
  ------------------
  |  Branch (312:7): [True: 92, False: 106]
  ------------------
  313|     92|    goto end;
  314|       |
  315|    106|  if (*q == '/') {
  ------------------
  |  Branch (315:7): [True: 41, False: 65]
  ------------------
  316|     41|    p = ++q;
  317|     41|    --len;
  318|       |
  319|  6.68k|    while (len && *q != '?') {
  ------------------
  |  Branch (319:12): [True: 6.64k, False: 36]
  |  Branch (319:19): [True: 6.64k, False: 5]
  ------------------
  320|  6.64k|      ++q;
  321|  6.64k|      --len;
  322|  6.64k|    }
  323|       |
  324|     41|    if (p < q) {
  ------------------
  |  Branch (324:9): [True: 34, False: 7]
  ------------------
  325|     34|      COAP_SET_STR(&uri->path, q - p, p);
  ------------------
  |  |   52|     34|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  326|     34|      p = q;
  327|     34|    }
  328|     41|  }
  329|       |
  330|       |  /* Uri_Query */
  331|    106|  if (len && *p == '?') {
  ------------------
  |  Branch (331:7): [True: 70, False: 36]
  |  Branch (331:14): [True: 5, False: 65]
  ------------------
  332|      5|    ++p;
  333|      5|    --len;
  334|      5|    COAP_SET_STR(&uri->query, len, p);
  ------------------
  |  |   52|      5|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  335|      5|    len = 0;
  336|      5|  }
  337|       |
  338|    198|end:
  339|    198|  return len ? -1 : 0;
  ------------------
  |  Branch (339:10): [True: 65, False: 133]
  ------------------
  340|       |
  341|    329|error:
  342|    329|  return res;
  343|    106|}
coap_uri.c:is_unescaped_in_query:
 1098|  2.63M|is_unescaped_in_query(const uint8_t c) {
 1099|  2.63M|  return is_unescaped_in_path(c) || c=='/' || c=='?';
  ------------------
  |  Branch (1099:10): [True: 28.9k, False: 2.60M]
  |  Branch (1099:37): [True: 432, False: 2.60M]
  |  Branch (1099:47): [True: 34, False: 2.60M]
  ------------------
 1100|  2.63M|}
coap_uri.c:is_unescaped_in_path:
 1089|  4.97M|is_unescaped_in_path(const uint8_t c) {
 1090|  4.97M|  return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') ||
  ------------------
  |  Branch (1090:11): [True: 72.4k, False: 4.89M]
  |  Branch (1090:23): [True: 8.79k, False: 63.7k]
  |  Branch (1090:37): [True: 62.6k, False: 4.89M]
  |  Branch (1090:49): [True: 4.81k, False: 57.8k]
  ------------------
 1091|  4.95M|         (c >= '0' && c <= '9') || c == '-' || c == '.' || c == '_' ||
  ------------------
  |  Branch (1091:11): [True: 74.9k, False: 4.88M]
  |  Branch (1091:23): [True: 4.43k, False: 70.4k]
  |  Branch (1091:36): [True: 1.03k, False: 4.95M]
  |  Branch (1091:48): [True: 7.01k, False: 4.94M]
  |  Branch (1091:60): [True: 800, False: 4.94M]
  ------------------
 1092|  4.94M|         c == '~' || c == '!' || c == '$' || c == '\'' || c == '(' ||
  ------------------
  |  Branch (1092:10): [True: 3.01k, False: 4.94M]
  |  Branch (1092:22): [True: 6.29k, False: 4.93M]
  |  Branch (1092:34): [True: 3.42k, False: 4.93M]
  |  Branch (1092:46): [True: 1.24k, False: 4.92M]
  |  Branch (1092:59): [True: 902, False: 4.92M]
  ------------------
 1093|  4.92M|         c == ')' || c == '*' || c == '+' || c == ',' || c == ';' ||
  ------------------
  |  Branch (1093:10): [True: 890, False: 4.92M]
  |  Branch (1093:22): [True: 8.20k, False: 4.91M]
  |  Branch (1093:34): [True: 4.20k, False: 4.91M]
  |  Branch (1093:46): [True: 852, False: 4.91M]
  |  Branch (1093:58): [True: 3.58k, False: 4.91M]
  ------------------
 1094|  4.91M|         c=='=' || c==':' || c=='@' || c == '&';
  ------------------
  |  Branch (1094:10): [True: 1.11k, False: 4.90M]
  |  Branch (1094:20): [True: 4.40k, False: 4.90M]
  |  Branch (1094:30): [True: 2.43k, False: 4.90M]
  |  Branch (1094:40): [True: 604, False: 4.90M]
  ------------------
 1095|  4.97M|}

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

LLVMFuzzerTestOneInput:
    4|  3.10k|LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
    5|  3.10k|  coap_pdu_t *pdu;
    6|       |
    7|  3.10k|  coap_startup();
    8|  3.10k|  pdu = coap_pdu_init(0, 0, 0, size);
    9|  3.10k|  if (pdu) {
  ------------------
  |  Branch (9:7): [True: 3.10k, False: 0]
  ------------------
   10|  3.10k|    coap_set_log_level(COAP_LOG_EMERG);
   11|  3.10k|    if (coap_pdu_parse(COAP_PROTO_WS, data, size, pdu)) {
  ------------------
  |  Branch (11:9): [True: 1.59k, False: 1.51k]
  ------------------
   12|  1.59k|      coap_string_t *query = coap_get_query(pdu);
   13|  1.59k|      coap_string_t *uri_path = coap_get_uri_path(pdu);
   14|  1.59k|      coap_show_pdu(COAP_LOG_ERR, pdu);
   15|  1.59k|      coap_pdu_encode_header(pdu, COAP_PROTO_WS);
   16|       |
   17|  1.59k|      coap_delete_string(query);
   18|  1.59k|      coap_delete_string(uri_path);
   19|  1.59k|    }
   20|  3.10k|    coap_delete_pdu(pdu);
   21|  3.10k|  }
   22|  3.10k|  coap_cleanup();
   23|  3.10k|  return 0;
   24|  3.10k|}

