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

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

coap_memory_init:
  623|  3.06k|coap_memory_init(void) {
  624|  3.06k|}
coap_malloc_type:
  627|  7.60k|coap_malloc_type(coap_memory_tag_t type, size_t size) {
  628|  7.60k|  void *ptr;
  629|       |
  630|  7.60k|  (void)type;
  631|  7.60k|  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.60k|  return ptr;
  643|  7.60k|}
coap_realloc_type:
  646|    529|coap_realloc_type(coap_memory_tag_t type, void *p, size_t size) {
  647|    529|  void *ptr;
  648|       |
  649|    529|  (void)type;
  650|    529|  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|    529|  return ptr;
  663|    529|}
coap_free_type:
  666|  12.3k|coap_free_type(coap_memory_tag_t type, void *p) {
  667|  12.3k|  (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.3k|  free(p);
  674|  12.3k|}

coap_startup:
 5720|  3.06k|coap_startup(void) {
 5721|  3.06k|  coap_tick_t now;
 5722|  3.06k|#ifndef WITH_CONTIKI
 5723|  3.06k|  uint64_t us;
 5724|  3.06k|#endif /* !WITH_CONTIKI */
 5725|       |
 5726|  3.06k|  if (coap_started)
  ------------------
  |  Branch (5726:7): [True: 0, False: 3.06k]
  ------------------
 5727|      0|    return;
 5728|  3.06k|  coap_started = 1;
 5729|       |
 5730|       |#if COAP_THREAD_SAFE
 5731|       |  coap_lock_init(&global_lock);
 5732|       |  coap_mutex_init(&m_show_pdu);
 5733|       |  coap_mutex_init(&m_log_impl);
 5734|       |  coap_mutex_init(&m_io_threads);
 5735|       |#endif /* COAP_THREAD_SAFE */
 5736|       |
 5737|       |#if defined(HAVE_WINSOCK2_H)
 5738|       |  WORD wVersionRequested = MAKEWORD(2, 2);
 5739|       |  WSADATA wsaData;
 5740|       |  WSAStartup(wVersionRequested, &wsaData);
 5741|       |#endif
 5742|  3.06k|  coap_clock_init();
 5743|  3.06k|  coap_ticks(&now);
 5744|  3.06k|#ifndef WITH_CONTIKI
 5745|  3.06k|  us = coap_ticks_to_rt_us(now);
 5746|       |  /* Be accurate to the nearest (approx) us */
 5747|  3.06k|  coap_prng_init_lkd((unsigned int)us);
 5748|       |#else /* WITH_CONTIKI */
 5749|       |  coap_start_io_process();
 5750|       |#endif /* WITH_CONTIKI */
 5751|  3.06k|  coap_memory_init();
 5752|  3.06k|  coap_dtls_startup();
 5753|       |#ifdef WITH_LWIP
 5754|       |  coap_io_lwip_init();
 5755|       |#endif /* WITH_LWIP */
 5756|  3.06k|#if COAP_SERVER_SUPPORT
 5757|  3.06k|  static coap_str_const_t well_known = { sizeof(".well-known/core")-1,
 5758|  3.06k|                                         (const uint8_t *)".well-known/core"
 5759|  3.06k|                                       };
 5760|  3.06k|  memset(&resource_uri_wellknown, 0, sizeof(resource_uri_wellknown));
 5761|  3.06k|  resource_uri_wellknown.ref = 1;
 5762|  3.06k|  resource_uri_wellknown.handler[COAP_REQUEST_GET-1] = hnd_get_wellknown_lkd;
 5763|  3.06k|  resource_uri_wellknown.flags = COAP_RESOURCE_FLAGS_HAS_MCAST_SUPPORT;
  ------------------
  |  |   89|  3.06k|#define COAP_RESOURCE_FLAGS_HAS_MCAST_SUPPORT 0x8
  ------------------
 5764|  3.06k|  resource_uri_wellknown.uri_path = &well_known;
 5765|  3.06k|#endif /* COAP_SERVER_SUPPORT */
 5766|  3.06k|  send_recv_terminate = 0;
 5767|  3.06k|  coap_prng_lkd(&coap_unique_id, sizeof(coap_unique_id));
 5768|  3.06k|}
coap_cleanup:
 5771|  3.06k|coap_cleanup(void) {
 5772|  3.06k|  if (!coap_started)
  ------------------
  |  Branch (5772:7): [True: 0, False: 3.06k]
  ------------------
 5773|      0|    return;
 5774|  3.06k|  coap_started = 0;
 5775|       |#if defined(HAVE_WINSOCK2_H)
 5776|       |  WSACleanup();
 5777|       |#elif defined(WITH_CONTIKI)
 5778|       |  coap_stop_io_process();
 5779|       |#endif
 5780|       |#ifdef WITH_LWIP
 5781|       |  coap_io_lwip_cleanup();
 5782|       |#endif /* WITH_LWIP */
 5783|  3.06k|  coap_dtls_shutdown();
 5784|       |
 5785|  3.06k|  coap_delete_upa_chain(coap_upa_client_fallback_chain);
 5786|  3.06k|  coap_upa_client_fallback_chain = NULL;
 5787|  3.06k|  coap_delete_upa_chain(coap_upa_server_mapping_chain);
 5788|  3.06k|  coap_upa_server_mapping_chain = NULL;
 5789|       |#if COAP_THREAD_SAFE
 5790|       |  coap_mutex_destroy(&m_show_pdu);
 5791|       |  coap_mutex_destroy(&m_log_impl);
 5792|       |  coap_mutex_destroy(&m_io_threads);
 5793|       |#endif /* COAP_THREAD_SAFE */
 5794|       |
 5795|  3.06k|  coap_debug_reset();
 5796|  3.06k|}

coap_dtls_is_supported:
  191|      2|coap_dtls_is_supported(void) {
  192|      2|  if (SSLeay() < 0x10100000L) {
  ------------------
  |  Branch (192:7): [True: 0, False: 2]
  ------------------
  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|      2|#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|      2|  if (SSLeay() < 0x10101000L) {
  ------------------
  |  Branch (204:7): [True: 0, False: 2]
  ------------------
  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|      2|#endif /* OPENSSL_VERSION_NUMBER >= 0x10101000L */
  209|      2|  return 1;
  210|      2|}
coap_tls_is_supported:
  213|      2|coap_tls_is_supported(void) {
  214|      2|#if !COAP_DISABLE_TCP
  215|      2|  if (SSLeay() < 0x10100000L) {
  ------------------
  |  Branch (215:7): [True: 0, False: 2]
  ------------------
  216|      0|    coap_log_warn("OpenSSL version 1.1.0 or later is required\n");
  ------------------
  |  |  108|      0|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  217|      0|    return 0;
  218|      0|  }
  219|      2|#if OPENSSL_VERSION_NUMBER >= 0x10101000L
  220|      2|  if (SSLeay() < 0x10101000L) {
  ------------------
  |  Branch (220:7): [True: 0, False: 2]
  ------------------
  221|      0|    coap_log_warn("OpenSSL version 1.1.1 or later is required\n");
  ------------------
  |  |  108|      0|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  222|      0|    return 0;
  223|      0|  }
  224|      2|#endif /* OPENSSL_VERSION_NUMBER >= 0x10101000L */
  225|      2|  return 1;
  226|       |#else /* COAP_DISABLE_TCP */
  227|       |  return 0;
  228|       |#endif /* COAP_DISABLE_TCP */
  229|      2|}
coap_dtls_startup:
  304|  3.06k|coap_dtls_startup(void) {
  305|  3.06k|  SSL_load_error_strings();
  306|  3.06k|  SSL_library_init();
  307|  3.06k|#if OPENSSL_VERSION_NUMBER < 0x40000000L
  308|       |  ENGINE_load_dynamic();
  309|  3.06k|#endif /* OPENSSL_VERSION_NUMBER < 0x40000000L */
  310|  3.06k|}
coap_dtls_shutdown:
  313|  3.06k|coap_dtls_shutdown(void) {
  314|       |#if OPENSSL_VERSION_NUMBER < 0x30000000L
  315|       |  if (pkcs11_engine) {
  316|       |    /* Release the functional reference from ENGINE_init() */
  317|       |    ENGINE_finish(pkcs11_engine);
  318|       |    pkcs11_engine = NULL;
  319|       |  }
  320|       |  if (defined_engine) {
  321|       |    /* Release the functional reference from ENGINE_init() */
  322|       |    ENGINE_finish(defined_engine);
  323|       |    defined_engine = NULL;
  324|       |  }
  325|       |#elif OPENSSL_VERSION_NUMBER < 0x40000000L
  326|  3.06k|  pkcs11_engine = NULL;
  327|  3.06k|  defined_engine = NULL;
  328|  3.06k|#endif /* OPENSSL_VERSION_NUMBER >= 0x30000000L && < 0x40000000L */
  329|       |  ERR_free_strings();
  ------------------
  |  Branch (329:3): [Folded, False: 3.06k]
  ------------------
  330|  3.06k|  coap_dtls_set_log_level(COAP_LOG_EMERG);
  331|  3.06k|}
coap_dtls_set_log_level:
  590|  3.06k|coap_dtls_set_log_level(coap_log_t level) {
  591|  3.06k|  dtls_log_level = level;
  592|  3.06k|}

coap_opt_parse:
   41|  44.4M|coap_opt_parse(const coap_opt_t *opt, size_t length, coap_option_t *result) {
   42|       |
   43|  44.4M|  const coap_opt_t *opt_start = opt; /* store where parsing starts  */
   44|  44.4M|  uint32_t delta; /* wider than result->delta to detect overflow */
   45|       |
   46|  44.4M|  assert(opt);
  ------------------
  |  Branch (46:3): [True: 44.4M, False: 0]
  ------------------
   47|  44.4M|  assert(result);
  ------------------
  |  Branch (47:3): [True: 44.4M, False: 0]
  ------------------
   48|       |
   49|  44.4M|  if (length < 1)
  ------------------
  |  Branch (49:7): [True: 4.59k, False: 44.4M]
  ------------------
   50|  4.59k|    return 0;
   51|       |
   52|  44.4M|  result->delta = (*opt & 0xf0) >> 4;
   53|  44.4M|  result->length = *opt & 0x0f;
   54|  44.4M|  delta = result->delta;
   55|       |
   56|  44.4M|  switch (result->delta) {
   57|    499|  case 15:
  ------------------
  |  Branch (57:3): [True: 499, False: 44.4M]
  ------------------
   58|    499|    if (*opt != COAP_PAYLOAD_START) {
  ------------------
  |  |   96|    499|#define COAP_PAYLOAD_START 0xFF /* payload marker */
  ------------------
  |  Branch (58:9): [True: 180, False: 319]
  ------------------
   59|    180|      coap_log_debug("ignored reserved option delta 15\n");
  ------------------
  |  |  126|    180|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|    180|#define coap_log(level, ...) do { \
  |  |  |  |  291|    180|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 180]
  |  |  |  |  ------------------
  |  |  |  |  292|    180|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|    180|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 180]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   60|    180|    }
   61|    499|    return 0;
   62|  1.18k|  case 14:
  ------------------
  |  Branch (62:3): [True: 1.18k, False: 44.4M]
  ------------------
   63|       |    /* Handle two-byte value: First, the MSB + 269 is stored as delta value.
   64|       |     * After that, the option pointer is advanced to the LSB which is handled
   65|       |     * just like case delta == 13. */
   66|  1.18k|    ADVANCE_OPT_CHECK(opt,length,1);
  ------------------
  |  |   34|  1.18k|#define ADVANCE_OPT_CHECK(o,e,step) do { \
  |  |   35|  1.18k|    ADVANCE_OPT(o,e,step);               \
  |  |  ------------------
  |  |  |  |   22|  1.18k|#define ADVANCE_OPT(o,e,step) if ((e) < step) {           \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (22:35): [True: 0, False: 1.18k]
  |  |  |  |  ------------------
  |  |  |  |   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.18k|  } else {                                                \
  |  |  |  |   26|  1.18k|    (e) -= step;                                          \
  |  |  |  |   27|  1.18k|    (o) = ((o)) + step;                                   \
  |  |  |  |   28|  1.18k|  }
  |  |  ------------------
  |  |   36|  1.18k|    if ((e) < 1)                         \
  |  |  ------------------
  |  |  |  Branch (36:9): [True: 54, False: 1.12k]
  |  |  ------------------
  |  |   37|  1.18k|      return 0;                          \
  |  |   38|  1.18k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (38:12): [Folded, False: 1.12k]
  |  |  ------------------
  ------------------
   67|  1.12k|    delta = ((*opt & 0xff) << 8) + 269;
   68|       |  /* fall through */
   69|  6.14k|  case 13:
  ------------------
  |  Branch (69:3): [True: 5.01k, False: 44.4M]
  ------------------
   70|  6.14k|    ADVANCE_OPT_CHECK(opt,length,1);
  ------------------
  |  |   34|  6.14k|#define ADVANCE_OPT_CHECK(o,e,step) do { \
  |  |   35|  6.14k|    ADVANCE_OPT(o,e,step);               \
  |  |  ------------------
  |  |  |  |   22|  6.14k|#define ADVANCE_OPT(o,e,step) if ((e) < step) {           \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (22:35): [True: 0, False: 6.14k]
  |  |  |  |  ------------------
  |  |  |  |   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.14k|  } else {                                                \
  |  |  |  |   26|  6.14k|    (e) -= step;                                          \
  |  |  |  |   27|  6.14k|    (o) = ((o)) + step;                                   \
  |  |  |  |   28|  6.14k|  }
  |  |  ------------------
  |  |   36|  6.14k|    if ((e) < 1)                         \
  |  |  ------------------
  |  |  |  Branch (36:9): [True: 36, False: 6.10k]
  |  |  ------------------
  |  |   37|  6.14k|      return 0;                          \
  |  |   38|  6.14k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (38:12): [Folded, False: 6.10k]
  |  |  ------------------
  ------------------
   71|  6.10k|    delta += *opt & 0xff;
   72|  6.10k|    if (delta > 0xffff) {
  ------------------
  |  Branch (72:9): [True: 15, False: 6.09k]
  ------------------
   73|     15|      coap_log_debug("delta too large\n");
  ------------------
  |  |  126|     15|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     15|#define coap_log(level, ...) do { \
  |  |  |  |  291|     15|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 15]
  |  |  |  |  ------------------
  |  |  |  |  292|     15|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     15|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 15]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   74|     15|      return 0;
   75|     15|    }
   76|  6.09k|    result->delta = (uint16_t)delta;
   77|  6.09k|    break;
   78|       |
   79|  44.4M|  default:
  ------------------
  |  Branch (79:3): [True: 44.4M, False: 6.69k]
  ------------------
   80|  44.4M|    ;
   81|  44.4M|  }
   82|       |
   83|  44.4M|  switch (result->length) {
   84|    123|  case 15:
  ------------------
  |  Branch (84:3): [True: 123, False: 44.4M]
  ------------------
   85|    123|    coap_log_debug("found reserved option length 15\n");
  ------------------
  |  |  126|    123|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|    123|#define coap_log(level, ...) do { \
  |  |  |  |  291|    123|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 123]
  |  |  |  |  ------------------
  |  |  |  |  292|    123|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|    123|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 123]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   86|    123|    return 0;
   87|  5.64k|  case 14:
  ------------------
  |  Branch (87:3): [True: 5.64k, False: 44.4M]
  ------------------
   88|       |    /* Handle two-byte value: First, the MSB + 269 is stored as delta value.
   89|       |     * After that, the option pointer is advanced to the LSB which is handled
   90|       |     * just like case delta == 13. */
   91|  5.64k|    ADVANCE_OPT_CHECK(opt,length,1);
  ------------------
  |  |   34|  5.64k|#define ADVANCE_OPT_CHECK(o,e,step) do { \
  |  |   35|  5.64k|    ADVANCE_OPT(o,e,step);               \
  |  |  ------------------
  |  |  |  |   22|  5.64k|#define ADVANCE_OPT(o,e,step) if ((e) < step) {           \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (22:35): [True: 0, False: 5.64k]
  |  |  |  |  ------------------
  |  |  |  |   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|  5.64k|  } else {                                                \
  |  |  |  |   26|  5.64k|    (e) -= step;                                          \
  |  |  |  |   27|  5.64k|    (o) = ((o)) + step;                                   \
  |  |  |  |   28|  5.64k|  }
  |  |  ------------------
  |  |   36|  5.64k|    if ((e) < 1)                         \
  |  |  ------------------
  |  |  |  Branch (36:9): [True: 54, False: 5.58k]
  |  |  ------------------
  |  |   37|  5.64k|      return 0;                          \
  |  |   38|  5.64k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (38:12): [Folded, False: 5.58k]
  |  |  ------------------
  ------------------
   92|  5.58k|    result->length = ((*opt & 0xff) << 8) + 269;
   93|       |  /* fall through */
   94|  30.0k|  case 13:
  ------------------
  |  Branch (94:3): [True: 24.4k, False: 44.4M]
  ------------------
   95|  30.0k|    ADVANCE_OPT_CHECK(opt,length,1);
  ------------------
  |  |   34|  30.0k|#define ADVANCE_OPT_CHECK(o,e,step) do { \
  |  |   35|  30.0k|    ADVANCE_OPT(o,e,step);               \
  |  |  ------------------
  |  |  |  |   22|  30.0k|#define ADVANCE_OPT(o,e,step) if ((e) < step) {           \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (22:35): [True: 0, False: 30.0k]
  |  |  |  |  ------------------
  |  |  |  |   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|  30.0k|  } else {                                                \
  |  |  |  |   26|  30.0k|    (e) -= step;                                          \
  |  |  |  |   27|  30.0k|    (o) = ((o)) + step;                                   \
  |  |  |  |   28|  30.0k|  }
  |  |  ------------------
  |  |   36|  30.0k|    if ((e) < 1)                         \
  |  |  ------------------
  |  |  |  Branch (36:9): [True: 51, False: 29.9k]
  |  |  ------------------
  |  |   37|  30.0k|      return 0;                          \
  |  |   38|  30.0k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (38:12): [Folded, False: 29.9k]
  |  |  ------------------
  ------------------
   96|  29.9k|    result->length += *opt & 0xff;
   97|  29.9k|    break;
   98|       |
   99|  44.4M|  default:
  ------------------
  |  Branch (99:3): [True: 44.4M, False: 30.2k]
  ------------------
  100|  44.4M|    ;
  101|  44.4M|  }
  102|       |
  103|       |  /* ADVANCE_OPT() is correct here */
  104|  44.4M|  ADVANCE_OPT(opt,length,1);
  ------------------
  |  |   22|  44.4M|#define ADVANCE_OPT(o,e,step) if ((e) < step) {           \
  |  |  ------------------
  |  |  |  Branch (22:35): [True: 0, False: 44.4M]
  |  |  ------------------
  |  |   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|  44.4M|  } else {                                                \
  |  |   26|  44.4M|    (e) -= step;                                          \
  |  |   27|  44.4M|    (o) = ((o)) + step;                                   \
  |  |   28|  44.4M|  }
  ------------------
  105|       |  /* opt now points to value, if present */
  106|       |
  107|  44.4M|  result->value = opt;
  108|  44.4M|  if (length < result->length) {
  ------------------
  |  Branch (108:7): [True: 771, False: 44.4M]
  ------------------
  109|    771|    coap_log_debug("invalid option length\n");
  ------------------
  |  |  126|    771|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|    771|#define coap_log(level, ...) do { \
  |  |  |  |  291|    771|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 771]
  |  |  |  |  ------------------
  |  |  |  |  292|    771|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|    771|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 771]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  110|    771|    return 0;
  111|    771|  }
  112|       |
  113|  44.4M|#undef ADVANCE_OPT
  114|  44.4M|#undef ADVANCE_OPT_CHECK
  115|       |
  116|  44.4M|  return (opt + result->length) - opt_start;
  117|  44.4M|}
coap_option_iterator_init:
  121|  7.14k|                          const coap_opt_filter_t *filter) {
  122|  7.14k|  assert(pdu);
  ------------------
  |  Branch (122:3): [True: 7.14k, False: 0]
  ------------------
  123|  7.14k|  assert(pdu->token);
  ------------------
  |  Branch (123:3): [True: 7.14k, False: 0]
  ------------------
  124|  7.14k|  assert(oi);
  ------------------
  |  Branch (124:3): [True: 7.14k, False: 0]
  ------------------
  125|       |
  126|  7.14k|  memset(oi, 0, sizeof(coap_opt_iterator_t));
  127|       |
  128|  7.14k|  oi->next_option = pdu->token + pdu->e_token_length;
  129|  7.14k|  if (pdu->token + pdu->used_size <= oi->next_option) {
  ------------------
  |  Branch (129:7): [True: 220, False: 6.92k]
  ------------------
  130|    220|    oi->bad = 1;
  131|    220|    return NULL;
  132|    220|  }
  133|       |
  134|  6.92k|  oi->length = pdu->used_size - pdu->e_token_length;
  135|       |
  136|  6.92k|  if (filter) {
  ------------------
  |  Branch (136:7): [True: 6.92k, False: 0]
  ------------------
  137|  6.92k|    memcpy(&oi->filter, filter, sizeof(coap_opt_filter_t));
  138|  6.92k|    oi->filtered = 1;
  139|  6.92k|  }
  140|  6.92k|  return oi;
  141|  7.14k|}
coap_option_next:
  156|  9.28M|coap_option_next(coap_opt_iterator_t *oi) {
  157|  9.28M|  coap_option_t option;
  158|  9.28M|  coap_opt_t *current_opt = NULL;
  159|  9.28M|  size_t optsize;
  160|       |
  161|  9.28M|  assert(oi);
  ------------------
  |  Branch (161:3): [True: 9.28M, False: 0]
  ------------------
  162|       |
  163|  9.28M|  if (opt_finished(oi))
  ------------------
  |  Branch (163:7): [True: 1.65k, False: 9.28M]
  ------------------
  164|  1.65k|    return NULL;
  165|       |
  166|  26.0M|  while (1) {
  ------------------
  |  Branch (166:10): [True: 26.0M, Folded]
  ------------------
  167|       |    /* oi->next_option always points to the next option to deliver; as
  168|       |     * opt_finished() filters out any bad conditions, we can assume that
  169|       |     * oi->next_option is valid. */
  170|  26.0M|    current_opt = oi->next_option;
  171|       |
  172|       |    /*
  173|       |     * Advance internal pointer to next option.
  174|       |     * optsize will be 0 when no more options
  175|       |     */
  176|  26.0M|    optsize = coap_opt_parse(oi->next_option, oi->length, &option);
  177|  26.0M|    if (optsize) {
  ------------------
  |  Branch (177:9): [True: 26.0M, False: 4.91k]
  ------------------
  178|  26.0M|      assert(optsize <= oi->length);
  ------------------
  |  Branch (178:7): [True: 26.0M, False: 0]
  ------------------
  179|       |
  180|  26.0M|      oi->next_option += optsize;
  181|  26.0M|      oi->length -= optsize;
  182|       |
  183|  26.0M|      oi->number += option.delta;
  184|  26.0M|    } else {                        /* current option is malformed */
  185|  4.91k|      oi->bad = 1;
  186|  4.91k|      return NULL;
  187|  4.91k|    }
  188|       |
  189|       |    /* Exit the while loop when:
  190|       |     *   - no filtering is done at all
  191|       |     *   - the filter matches for the current option
  192|       |     */
  193|  26.0M|    if (!oi->filtered ||
  ------------------
  |  Branch (193:9): [True: 0, False: 26.0M]
  ------------------
  194|  26.0M|        coap_option_filter_get(&oi->filter, oi->number) > 0)
  ------------------
  |  Branch (194:9): [True: 9.27M, False: 16.7M]
  ------------------
  195|  9.27M|      break;
  196|  26.0M|  }
  197|       |
  198|  9.27M|  return current_opt;
  199|  9.28M|}
coap_check_option:
  203|  3.19k|                  coap_opt_iterator_t *oi) {
  204|  3.19k|  coap_opt_filter_t f;
  205|       |
  206|  3.19k|  coap_option_filter_clear(&f);
  207|  3.19k|  coap_option_filter_set(&f, number);
  208|       |
  209|  3.19k|  coap_option_iterator_init(pdu, oi, &f);
  210|       |
  211|  3.19k|  return coap_option_next(oi);
  212|  3.19k|}
coap_opt_length:
  215|  27.6M|coap_opt_length(const coap_opt_t *opt) {
  216|  27.6M|  uint32_t length;
  217|       |
  218|  27.6M|  length = *opt & 0x0f;
  219|  27.6M|  switch (*opt & 0xf0) {
  220|      0|  case 0xf0:
  ------------------
  |  Branch (220:3): [True: 0, False: 27.6M]
  ------------------
  221|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  222|      0|    return 0;
  223|    558|  case 0xe0:
  ------------------
  |  Branch (223:3): [True: 558, False: 27.6M]
  ------------------
  224|    558|    ++opt;
  225|       |  /* fall through */
  226|       |  /* to skip another byte */
  227|  3.25k|  case 0xd0:
  ------------------
  |  Branch (227:3): [True: 2.69k, False: 27.6M]
  ------------------
  228|  3.25k|    ++opt;
  229|       |  /* fall through */
  230|       |  /* to skip another byte */
  231|  27.6M|  default:
  ------------------
  |  Branch (231:3): [True: 27.6M, False: 3.25k]
  ------------------
  232|  27.6M|    ++opt;
  233|  27.6M|  }
  234|       |
  235|  27.6M|  switch (length) {
  236|      0|  case 0x0f:
  ------------------
  |  Branch (236:3): [True: 0, False: 27.6M]
  ------------------
  237|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  238|      0|    return 0;
  239|  4.75k|  case 0x0e:
  ------------------
  |  Branch (239:3): [True: 4.75k, False: 27.6M]
  ------------------
  240|  4.75k|    length = (*opt++ << 8) + 269;
  241|       |  /* fall through */
  242|  27.2k|  case 0x0d:
  ------------------
  |  Branch (242:3): [True: 22.5k, False: 27.6M]
  ------------------
  243|  27.2k|    length += *opt++;
  244|  27.2k|    break;
  245|  27.6M|  default:
  ------------------
  |  Branch (245:3): [True: 27.6M, False: 27.2k]
  ------------------
  246|  27.6M|    ;
  247|  27.6M|  }
  248|  27.6M|  return length;
  249|  27.6M|}
coap_opt_value:
  252|  27.6M|coap_opt_value(const coap_opt_t *opt) {
  253|  27.6M|  size_t ofs = 1;
  254|       |
  255|  27.6M|  switch (*opt & 0xf0) {
  256|      0|  case 0xf0:
  ------------------
  |  Branch (256:3): [True: 0, False: 27.6M]
  ------------------
  257|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  258|      0|    return 0;
  259|    558|  case 0xe0:
  ------------------
  |  Branch (259:3): [True: 558, False: 27.6M]
  ------------------
  260|    558|    ++ofs;
  261|       |  /* fall through */
  262|  3.25k|  case 0xd0:
  ------------------
  |  Branch (262:3): [True: 2.69k, False: 27.6M]
  ------------------
  263|  3.25k|    ++ofs;
  264|  3.25k|    break;
  265|  27.6M|  default:
  ------------------
  |  Branch (265:3): [True: 27.6M, False: 3.25k]
  ------------------
  266|  27.6M|    ;
  267|  27.6M|  }
  268|       |
  269|  27.6M|  switch (*opt & 0x0f) {
  270|      0|  case 0x0f:
  ------------------
  |  Branch (270:3): [True: 0, False: 27.6M]
  ------------------
  271|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  272|      0|    return 0;
  273|  4.75k|  case 0x0e:
  ------------------
  |  Branch (273:3): [True: 4.75k, False: 27.6M]
  ------------------
  274|  4.75k|    ++ofs;
  275|       |  /* fall through */
  276|  27.2k|  case 0x0d:
  ------------------
  |  Branch (276:3): [True: 22.5k, False: 27.6M]
  ------------------
  277|  27.2k|    ++ofs;
  278|  27.2k|    break;
  279|  27.6M|  default:
  ------------------
  |  Branch (279:3): [True: 27.6M, False: 27.2k]
  ------------------
  280|  27.6M|    ;
  281|  27.6M|  }
  282|       |
  283|  27.6M|  return (const uint8_t *)opt + ofs;
  284|  27.6M|}
coap_option_filter_clear:
  494|  8.83k|coap_option_filter_clear(coap_opt_filter_t *filter) {
  495|  8.83k|  memset(filter, 0, sizeof(coap_opt_filter_t));
  496|  8.83k|}
coap_option_filter_set:
  499|  3.44M|coap_option_filter_set(coap_opt_filter_t *filter, coap_option_num_t option) {
  500|  3.44M|  return coap_option_filter_op(filter, option, FILTER_SET);
  501|  3.44M|}
coap_option_filter_get:
  509|  26.0M|coap_option_filter_get(coap_opt_filter_t *filter, coap_option_num_t option) {
  510|  26.0M|  return coap_option_filter_op(filter, option, FILTER_GET);
  511|  26.0M|}
coap_option.c:opt_finished:
  144|  9.28M|opt_finished(coap_opt_iterator_t *oi) {
  145|  9.28M|  assert(oi);
  ------------------
  |  Branch (145:3): [True: 9.28M, False: 0]
  ------------------
  146|       |
  147|  9.28M|  if (oi->bad || oi->length == 0 ||
  ------------------
  |  Branch (147:7): [True: 220, False: 9.28M]
  |  Branch (147:18): [True: 1.16k, False: 9.28M]
  ------------------
  148|  9.28M|      !oi->next_option || *oi->next_option == COAP_PAYLOAD_START) {
  ------------------
  |  |   96|  9.28M|#define COAP_PAYLOAD_START 0xFF /* payload marker */
  ------------------
  |  Branch (148:7): [True: 0, False: 9.28M]
  |  Branch (148:27): [True: 271, False: 9.28M]
  ------------------
  149|  1.65k|    oi->bad = 1;
  150|  1.65k|  }
  151|       |
  152|  9.28M|  return oi->bad;
  153|  9.28M|}
coap_option.c:coap_option_filter_op:
  436|  29.4M|                      enum filter_op_t op) {
  437|  29.4M|  size_t lindex = 0;
  438|  29.4M|  coap_opt_filter_t *of = filter;
  439|  29.4M|  uint16_t nr, mask = 0;
  440|       |
  441|  29.4M|  if (is_long_option(number)) {
  ------------------
  |  Branch (441:7): [True: 537k, False: 28.9M]
  ------------------
  442|   537k|    mask = LONG_MASK;
  ------------------
  |  |  401|   537k|#define LONG_MASK ((1 << COAP_OPT_FILTER_LONG) - 1)
  |  |  ------------------
  |  |  |  |  208|   537k|#define COAP_OPT_FILTER_LONG  2
  |  |  ------------------
  ------------------
  443|       |
  444|   646k|    for (nr = 1; lindex < COAP_OPT_FILTER_LONG; nr <<= 1, lindex++) {
  ------------------
  |  |  208|   646k|#define COAP_OPT_FILTER_LONG  2
  ------------------
  |  Branch (444:18): [True: 602k, False: 44.2k]
  ------------------
  445|       |
  446|   602k|      if (((of->mask & nr) > 0) && (of->long_opts[lindex] == number)) {
  ------------------
  |  Branch (446:11): [True: 502k, False: 100k]
  |  Branch (446:36): [True: 493k, False: 8.82k]
  ------------------
  447|   493k|        if (op == FILTER_CLEAR) {
  ------------------
  |  Branch (447:13): [True: 0, False: 493k]
  ------------------
  448|      0|          of->mask &= ~nr;
  449|      0|        }
  450|       |
  451|   493k|        return 1;
  452|   493k|      }
  453|   602k|    }
  454|  28.9M|  } else {
  455|  28.9M|    mask = SHORT_MASK;
  ------------------
  |  |  403|  28.9M|  (~LONG_MASK & ((1 << (COAP_OPT_FILTER_LONG + COAP_OPT_FILTER_SHORT)) - 1))
  |  |  ------------------
  |  |  |  |  401|  28.9M|#define LONG_MASK ((1 << COAP_OPT_FILTER_LONG) - 1)
  |  |  |  |  ------------------
  |  |  |  |  |  |  208|  28.9M|#define COAP_OPT_FILTER_LONG  2
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                 (~LONG_MASK & ((1 << (COAP_OPT_FILTER_LONG + COAP_OPT_FILTER_SHORT)) - 1))
  |  |  ------------------
  |  |  |  |  208|  28.9M|#define COAP_OPT_FILTER_LONG  2
  |  |  ------------------
  |  |                 (~LONG_MASK & ((1 << (COAP_OPT_FILTER_LONG + COAP_OPT_FILTER_SHORT)) - 1))
  |  |  ------------------
  |  |  |  |  200|  28.9M|#define COAP_OPT_FILTER_SHORT 6
  |  |  ------------------
  ------------------
  456|       |
  457|   190M|    for (nr = 1 << COAP_OPT_FILTER_LONG; lindex < COAP_OPT_FILTER_SHORT;
  ------------------
  |  |  208|  28.9M|#define COAP_OPT_FILTER_LONG  2
  ------------------
                  for (nr = 1 << COAP_OPT_FILTER_LONG; lindex < COAP_OPT_FILTER_SHORT;
  ------------------
  |  |  200|   190M|#define COAP_OPT_FILTER_SHORT 6
  ------------------
  |  Branch (457:42): [True: 173M, False: 16.7M]
  ------------------
  458|   173M|         nr <<= 1, lindex++) {
  459|       |
  460|   173M|      if (((of->mask & nr) > 0) && (of->short_opts[lindex] == (number & 0xff))) {
  ------------------
  |  Branch (460:11): [True: 28.9M, False: 144M]
  |  Branch (460:36): [True: 12.2M, False: 16.7M]
  ------------------
  461|  12.2M|        if (op == FILTER_CLEAR) {
  ------------------
  |  Branch (461:13): [True: 0, False: 12.2M]
  ------------------
  462|      0|          of->mask &= ~nr;
  463|      0|        }
  464|       |
  465|  12.2M|        return 1;
  466|  12.2M|      }
  467|   173M|    }
  468|  28.9M|  }
  469|       |
  470|       |  /* number was not found, so there is nothing to do if op is CLEAR or GET */
  471|  16.7M|  if ((op == FILTER_CLEAR) || (op == FILTER_GET)) {
  ------------------
  |  Branch (471:7): [True: 0, False: 16.7M]
  |  Branch (471:31): [True: 16.7M, False: 17.7k]
  ------------------
  472|  16.7M|    return 0;
  473|  16.7M|  }
  474|       |
  475|       |  /* handle FILTER_SET: */
  476|       |
  477|  17.7k|  lindex = coap_fls(~of->mask & mask);
  478|  17.7k|  if (!lindex) {
  ------------------
  |  Branch (478:7): [True: 9.84k, False: 7.90k]
  ------------------
  479|  9.84k|    return 0;
  480|  9.84k|  }
  481|       |
  482|  7.90k|  if (is_long_option(number)) {
  ------------------
  |  Branch (482:7): [True: 226, False: 7.68k]
  ------------------
  483|    226|    of->long_opts[lindex - 1] = number;
  484|  7.68k|  } else {
  485|  7.68k|    of->short_opts[lindex - COAP_OPT_FILTER_LONG - 1] = (uint8_t)number;
  ------------------
  |  |  208|  7.68k|#define COAP_OPT_FILTER_LONG  2
  ------------------
  486|  7.68k|  }
  487|       |
  488|  7.90k|  of->mask |= 1 << (lindex - 1);
  489|       |
  490|  7.90k|  return 1;
  491|  17.7k|}
coap_option.c:is_long_option:
  407|  29.4M|is_long_option(coap_option_num_t number) {
  408|  29.4M|  return number > 255;
  409|  29.4M|}

coap_pdu_clear:
   47|  3.06k|coap_pdu_clear(coap_pdu_t *pdu, size_t size) {
   48|  3.06k|  assert(pdu);
  ------------------
  |  Branch (48:3): [True: 3.06k, False: 0]
  ------------------
   49|  3.06k|  assert(pdu->token);
  ------------------
  |  Branch (49:3): [True: 3.06k, False: 0]
  ------------------
   50|  3.06k|  assert(pdu->max_hdr_size >= COAP_PDU_MAX_UDP_HEADER_SIZE);
  ------------------
  |  Branch (50:3): [True: 3.06k, False: 0]
  ------------------
   51|  3.06k|  if (pdu->alloc_size > size)
  ------------------
  |  Branch (51:7): [True: 0, False: 3.06k]
  ------------------
   52|      0|    pdu->alloc_size = size;
   53|  3.06k|  pdu->type = 0;
   54|  3.06k|  pdu->code = 0;
   55|  3.06k|  pdu->ref = 0;
   56|  3.06k|  pdu->hdr_size = 0;
   57|  3.06k|  pdu->actual_token.length = 0;
   58|  3.06k|  pdu->e_token_length = 0;
   59|  3.06k|  pdu->crit_opt = 0;
   60|  3.06k|  pdu->mid = 0;
   61|  3.06k|  pdu->max_opt = 0;
   62|  3.06k|  pdu->max_size = size;
   63|  3.06k|  pdu->used_size = 0;
   64|  3.06k|  pdu->data = NULL;
   65|  3.06k|  pdu->body_data = NULL;
   66|  3.06k|  pdu->body_length = 0;
   67|  3.06k|  pdu->body_offset = 0;
   68|  3.06k|  pdu->body_total = 0;
   69|  3.06k|  pdu->lg_xmit = NULL;
   70|  3.06k|  pdu->session = NULL;
   71|       |  pdu->data_free = NULL;
   72|  3.06k|}
coap_pdu_init:
  105|  3.06k|              size_t size) {
  106|  3.06k|  coap_pdu_t *pdu;
  107|       |
  108|  3.06k|#ifndef RIOT_VERSION
  109|  3.06k|  assert(type <= 0x3);
  ------------------
  |  Branch (109:3): [True: 3.06k, False: 0]
  ------------------
  110|  3.06k|  assert(code <= 0xff);
  ------------------
  |  Branch (110:3): [True: 3.06k, False: 0]
  ------------------
  111|  3.06k|  assert(mid >= 0 && mid <= 0xffff);
  ------------------
  |  Branch (111:3): [True: 3.06k, False: 0]
  |  Branch (111:3): [True: 3.06k, False: 0]
  ------------------
  112|  3.06k|#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.06k|  pdu = coap_malloc_type(COAP_PDU, sizeof(coap_pdu_t));
  125|  3.06k|  if (!pdu)
  ------------------
  |  Branch (125:7): [True: 0, False: 3.06k]
  ------------------
  126|      0|    return NULL;
  127|       |
  128|  3.06k|  pdu->max_hdr_size = COAP_PDU_MAX_HEADER_SIZE;
  ------------------
  |  |  115|  3.06k|#define COAP_PDU_MAX_HEADER_SIZE COAP_PDU_MAX_TCP_HEADER_SIZE
  |  |  ------------------
  |  |  |  |  108|  3.06k|#define COAP_PDU_MAX_TCP_HEADER_SIZE 6
  |  |  ------------------
  ------------------
  129|  3.06k|  if (size > ((size_t)COAP_DEFAULT_MAX_PDU_RX_SIZE - pdu->max_hdr_size)) {
  ------------------
  |  |   84|  3.06k|#define COAP_DEFAULT_MAX_PDU_RX_SIZE (8UL*1024*1024+256)
  ------------------
  |  Branch (129:7): [True: 0, False: 3.06k]
  ------------------
  130|      0|    coap_free_type(COAP_PDU, pdu);
  131|      0|    return NULL;
  132|      0|  }
  133|       |
  134|  3.06k|  pdu->alloc_size = min(size, COAP_DEFAULT_MTU);
  ------------------
  |  |   37|  3.06k|#define min(a,b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (37:19): [True: 2.53k, False: 531]
  |  |  ------------------
  ------------------
  135|       |#ifdef WITH_LWIP
  136|       |  pdu->pbuf = pbuf_alloc(PBUF_TRANSPORT, pdu->alloc_size + pdu->max_hdr_size,
  137|       |                         PBUF_RAM);
  138|       |  if (pdu->pbuf == NULL) {
  139|       |    coap_free_type(COAP_PDU, pdu);
  140|       |    return NULL;
  141|       |  }
  142|       |  pdu->token = (uint8_t *)pdu->pbuf->payload + pdu->max_hdr_size;
  143|       |#else /* ! WITH_LWIP */
  144|  3.06k|  uint8_t *buf;
  145|  3.06k|  buf = coap_malloc_type(COAP_PDU_BUF, pdu->alloc_size + pdu->max_hdr_size);
  146|  3.06k|  if (buf == NULL) {
  ------------------
  |  Branch (146:7): [True: 0, False: 3.06k]
  ------------------
  147|      0|    coap_free_type(COAP_PDU, pdu);
  148|      0|    return NULL;
  149|      0|  }
  150|  3.06k|  pdu->token = buf + pdu->max_hdr_size;
  151|  3.06k|#endif /* ! WITH_LWIP */
  152|  3.06k|  coap_pdu_clear(pdu, size);
  153|  3.06k|  pdu->mid = mid;
  154|  3.06k|  pdu->type = type;
  155|  3.06k|  pdu->code = code;
  156|  3.06k|  return pdu;
  157|  3.06k|}
coap_delete_pdu:
  185|  3.06k|coap_delete_pdu(coap_pdu_t *pdu) {
  186|  3.06k|  coap_lock_lock(return);
  187|  3.06k|  coap_delete_pdu_lkd(pdu);
  188|  3.06k|  coap_lock_unlock();
  189|  3.06k|}
coap_delete_pdu_lkd:
  192|  3.06k|coap_delete_pdu_lkd(coap_pdu_t *pdu) {
  193|  3.06k|  if (pdu != NULL) {
  ------------------
  |  Branch (193:7): [True: 3.06k, False: 0]
  ------------------
  194|  3.06k|    if (pdu->ref) {
  ------------------
  |  Branch (194:9): [True: 0, False: 3.06k]
  ------------------
  195|      0|      pdu->ref--;
  196|      0|      return;
  197|      0|    }
  198|       |#ifdef WITH_LWIP
  199|       |    pbuf_free(pdu->pbuf);
  200|       |#else
  201|  3.06k|    if (pdu->token != NULL)
  ------------------
  |  Branch (201:9): [True: 3.06k, False: 0]
  ------------------
  202|  3.06k|      coap_free_type(COAP_PDU_BUF, pdu->token - pdu->max_hdr_size);
  203|  3.06k|#endif
  204|  3.06k|    coap_delete_binary(pdu->data_free);
  205|  3.06k|    coap_free_type(COAP_PDU, pdu);
  206|  3.06k|  }
  207|  3.06k|}
coap_pdu_resize:
  335|  3.06k|coap_pdu_resize(coap_pdu_t *pdu, size_t new_size) {
  336|  3.06k|  if (new_size > pdu->alloc_size) {
  ------------------
  |  Branch (336:7): [True: 529, False: 2.53k]
  ------------------
  337|       |    /* Expanding the PDU usage */
  338|    529|#if !defined(WITH_LWIP)
  339|    529|    uint8_t *new_hdr;
  340|       |#else /* WITH_LWIP */
  341|       |    struct pbuf *new_hdr;
  342|       |#endif /* WITH_LWIP */
  343|    529|    size_t offset;
  344|       |
  345|    529|    if (pdu->max_size && new_size > pdu->max_size) {
  ------------------
  |  Branch (345:9): [True: 529, False: 0]
  |  Branch (345:26): [True: 0, False: 529]
  ------------------
  346|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  347|      0|      return 0;
  348|      0|    }
  349|    529|    if (pdu->data != NULL) {
  ------------------
  |  Branch (349:9): [True: 0, False: 529]
  ------------------
  350|      0|      assert(pdu->data > pdu->token);
  ------------------
  |  Branch (350:7): [True: 0, False: 0]
  ------------------
  351|      0|      offset = pdu->data - pdu->token;
  352|    529|    } else {
  353|    529|      offset = 0;
  354|    529|    }
  355|    529|#if !defined(WITH_LWIP)
  356|    529|    new_hdr = (uint8_t *)coap_realloc_type(COAP_PDU_BUF,
  357|    529|                                           pdu->token - pdu->max_hdr_size,
  358|    529|                                           new_size + pdu->max_hdr_size);
  359|       |#else /* WITH_LWIP */
  360|       |    new_hdr = pbuf_alloc(PBUF_TRANSPORT, new_size + pdu->max_hdr_size, PBUF_RAM);
  361|       |#endif /* WITH_LWIP */
  362|    529|    if (new_hdr == NULL) {
  ------------------
  |  Branch (362:9): [True: 0, False: 529]
  ------------------
  363|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  364|      0|      return 0;
  365|      0|    }
  366|    529|#if !defined(WITH_LWIP)
  367|    529|    pdu->token = new_hdr + pdu->max_hdr_size;
  368|       |#else /* WITH_LWIP */
  369|       |    memcpy(new_hdr->payload, pdu->pbuf->payload, pdu->pbuf->len);
  370|       |    pbuf_free(pdu->pbuf);
  371|       |    pdu->pbuf = new_hdr;
  372|       |    pdu->token = (uint8_t *)pdu->pbuf->payload + pdu->max_hdr_size;
  373|       |#endif /* WITH_LWIP */
  374|    529|    if (offset > 0)
  ------------------
  |  Branch (374:9): [True: 0, False: 529]
  ------------------
  375|      0|      pdu->data = pdu->token + offset;
  376|    529|    else
  377|    529|      pdu->data = NULL;
  378|    529|    if (pdu->actual_token.length < COAP_TOKEN_EXT_1B_BIAS)
  ------------------
  |  |   56|    529|#define COAP_TOKEN_EXT_1B_BIAS 13
  ------------------
  |  Branch (378:9): [True: 529, False: 0]
  ------------------
  379|    529|      pdu->actual_token.s = &pdu->token[0];
  380|      0|    else if (pdu->actual_token.length < COAP_TOKEN_EXT_2B_BIAS)
  ------------------
  |  |   57|      0|#define COAP_TOKEN_EXT_2B_BIAS 269 /* 13 + 256 */
  ------------------
  |  Branch (380:14): [True: 0, False: 0]
  ------------------
  381|      0|      pdu->actual_token.s = &pdu->token[1];
  382|      0|    else
  383|      0|      pdu->actual_token.s = &pdu->token[2];
  384|    529|    pdu->alloc_size = new_size;
  385|    529|  }
  386|  3.06k|  return 1;
  387|  3.06k|}
coap_pdu_parse_header_size:
 1077|  3.06k|                           const uint8_t *data) {
 1078|  3.06k|  assert(data);
  ------------------
  |  Branch (1078:3): [True: 3.06k, False: 0]
  ------------------
 1079|  3.06k|  size_t header_size = 0;
 1080|       |
 1081|  3.06k|  if (proto == COAP_PROTO_TCP || proto==COAP_PROTO_TLS) {
  ------------------
  |  Branch (1081:7): [True: 0, False: 3.06k]
  |  Branch (1081:34): [True: 0, False: 3.06k]
  ------------------
 1082|      0|    uint8_t len = *data >> 4;
 1083|      0|    if (len < 13)
  ------------------
  |  Branch (1083:9): [True: 0, False: 0]
  ------------------
 1084|      0|      header_size = 2;
 1085|      0|    else if (len==13)
  ------------------
  |  Branch (1085:14): [True: 0, False: 0]
  ------------------
 1086|      0|      header_size = 3;
 1087|      0|    else if (len==14)
  ------------------
  |  Branch (1087:14): [True: 0, False: 0]
  ------------------
 1088|      0|      header_size = 4;
 1089|      0|    else
 1090|      0|      header_size = 6;
 1091|  3.06k|  } else if (proto == COAP_PROTO_WS || proto==COAP_PROTO_WSS) {
  ------------------
  |  Branch (1091:14): [True: 3.06k, False: 0]
  |  Branch (1091:40): [True: 0, False: 0]
  ------------------
 1092|  3.06k|    header_size = COAP_PDU_WS_HEADER_SIZE;
  ------------------
  |  |  109|  3.06k|#define COAP_PDU_WS_HEADER_SIZE 2
  ------------------
 1093|  3.06k|  } else if (proto == COAP_PROTO_UDP || proto==COAP_PROTO_DTLS) {
  ------------------
  |  Branch (1093:14): [True: 0, False: 0]
  |  Branch (1093:41): [True: 0, False: 0]
  ------------------
 1094|      0|    header_size = 4;
 1095|      0|  }
 1096|       |
 1097|  3.06k|  return header_size;
 1098|  3.06k|}
coap_pdu_parse_header:
 1173|  3.06k|coap_pdu_parse_header(coap_pdu_t *pdu, coap_proto_t proto) {
 1174|  3.06k|  uint8_t *hdr = pdu->token - pdu->hdr_size;
 1175|  3.06k|  uint8_t e_token_length;
 1176|       |
 1177|  3.06k|  if (proto == COAP_PROTO_UDP || proto == COAP_PROTO_DTLS) {
  ------------------
  |  Branch (1177:7): [True: 0, False: 3.06k]
  |  Branch (1177:34): [True: 0, False: 3.06k]
  ------------------
 1178|      0|    assert(pdu->hdr_size == 4);
  ------------------
  |  Branch (1178:5): [True: 0, False: 0]
  ------------------
 1179|      0|    if ((hdr[0] >> 6) != COAP_DEFAULT_VERSION) {
  ------------------
  |  |   35|      0|#define COAP_DEFAULT_VERSION      1 /* version of CoAP supported */
  ------------------
  |  Branch (1179:9): [True: 0, False: 0]
  ------------------
 1180|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1181|      0|      return 0;
 1182|      0|    }
 1183|      0|    pdu->type = (hdr[0] >> 4) & 0x03;
 1184|      0|    pdu->code = hdr[1];
 1185|      0|    pdu->mid = (uint16_t)hdr[2] << 8 | hdr[3];
 1186|  3.06k|  } else if (proto == COAP_PROTO_TCP || proto == COAP_PROTO_TLS) {
  ------------------
  |  Branch (1186:14): [True: 0, False: 3.06k]
  |  Branch (1186:41): [True: 0, False: 3.06k]
  ------------------
 1187|      0|    assert(pdu->hdr_size >= 2 && pdu->hdr_size <= 6);
  ------------------
  |  Branch (1187:5): [True: 0, False: 0]
  |  Branch (1187:5): [True: 0, False: 0]
  ------------------
 1188|      0|    pdu->type = COAP_MESSAGE_CON;
 1189|      0|    pdu->code = hdr[pdu->hdr_size-1];
 1190|      0|    pdu->mid = 0;
 1191|  3.06k|  } else if (proto == COAP_PROTO_WS || proto == COAP_PROTO_WSS) {
  ------------------
  |  Branch (1191:14): [True: 3.06k, False: 0]
  |  Branch (1191:40): [True: 0, False: 0]
  ------------------
 1192|  3.06k|    assert(pdu->hdr_size == 2);
  ------------------
  |  Branch (1192:5): [True: 3.06k, False: 0]
  ------------------
 1193|  3.06k|    pdu->type = COAP_MESSAGE_CON;
 1194|  3.06k|    pdu->code = hdr[pdu->hdr_size-1];
 1195|  3.06k|    pdu->mid = 0;
 1196|  3.06k|  } else {
 1197|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1198|      0|    return 0;
 1199|      0|  }
 1200|       |
 1201|  3.06k|  e_token_length = hdr[0] & 0x0f;
 1202|  3.06k|  if (e_token_length < COAP_TOKEN_EXT_1B_TKL) {
  ------------------
  |  |   54|  3.06k|#define COAP_TOKEN_EXT_1B_TKL 13
  ------------------
  |  Branch (1202:7): [True: 2.93k, False: 122]
  ------------------
 1203|  2.93k|    pdu->e_token_length = e_token_length;
 1204|  2.93k|    pdu->actual_token.length = pdu->e_token_length;
 1205|  2.93k|    pdu->actual_token.s = &pdu->token[0];
 1206|  2.93k|  } else if (e_token_length == COAP_TOKEN_EXT_1B_TKL) {
  ------------------
  |  |   54|    122|#define COAP_TOKEN_EXT_1B_TKL 13
  ------------------
  |  Branch (1206:14): [True: 54, False: 68]
  ------------------
 1207|     54|    if (pdu->used_size < 1)
  ------------------
  |  Branch (1207:9): [True: 1, False: 53]
  ------------------
 1208|      1|      goto bad_ext_token;
 1209|     53|    pdu->e_token_length = pdu->token[0] + COAP_TOKEN_EXT_1B_BIAS + 1;
  ------------------
  |  |   56|     53|#define COAP_TOKEN_EXT_1B_BIAS 13
  ------------------
 1210|     53|    pdu->actual_token.length = pdu->e_token_length - 1;
 1211|     53|    pdu->actual_token.s = &pdu->token[1];
 1212|     68|  } else if (e_token_length == COAP_TOKEN_EXT_2B_TKL) {
  ------------------
  |  |   55|     68|#define COAP_TOKEN_EXT_2B_TKL 14
  ------------------
  |  Branch (1212:14): [True: 65, False: 3]
  ------------------
 1213|     65|    if (pdu->used_size < 2)
  ------------------
  |  Branch (1213:9): [True: 2, False: 63]
  ------------------
 1214|      2|      goto bad_ext_token;
 1215|     63|    pdu->e_token_length = ((uint16_t)pdu->token[0] << 8) + pdu->token[1] +
 1216|     63|                          COAP_TOKEN_EXT_2B_BIAS + 2;
  ------------------
  |  |   57|     63|#define COAP_TOKEN_EXT_2B_BIAS 269 /* 13 + 256 */
  ------------------
 1217|     63|    pdu->actual_token.length = pdu->e_token_length - 2;
 1218|     63|    pdu->actual_token.s = &pdu->token[2];
 1219|     63|  }
 1220|  3.05k|  if (pdu->e_token_length > pdu->alloc_size || e_token_length == 15) {
  ------------------
  |  Branch (1220:7): [True: 25, False: 3.03k]
  |  Branch (1220:48): [True: 3, False: 3.02k]
  ------------------
 1221|     28|    goto bad_ext_token;
 1222|     28|  }
 1223|  3.02k|  return 1;
 1224|       |
 1225|     31|bad_ext_token:
 1226|       |  /* Invalid PDU provided - not wise to assert here though */
 1227|     31|  coap_log_warn("coap_pdu_parse: PDU header extended token size broken\n");
  ------------------
  |  |  108|     31|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     31|#define coap_log(level, ...) do { \
  |  |  |  |  291|     31|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 31]
  |  |  |  |  ------------------
  |  |  |  |  292|     31|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     31|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 31]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1228|     31|  pdu->e_token_length = 0;
 1229|     31|  pdu->actual_token.length = 0;
 1230|     31|  return 0;
 1231|  3.05k|}
coap_pdu_parse_opt_base:
 1302|  6.04M|coap_pdu_parse_opt_base(coap_option_num_t number, size_t len, const uint8_t *opt_val) {
 1303|  6.04M|  int res = 1;
 1304|       |
 1305|  6.04M|  switch ((coap_code_opt_num_t)number) {
 1306|  2.00k|  case COAP_OPTION_IF_MATCH:
  ------------------
  |  Branch (1306:3): [True: 2.00k, False: 6.04M]
  ------------------
 1307|  2.00k|    if (len > 8)
  ------------------
  |  Branch (1307:9): [True: 1.10k, False: 900]
  ------------------
 1308|  1.10k|      res = 0;
 1309|  2.00k|    break;
 1310|  7.06k|  case COAP_OPTION_URI_HOST:
  ------------------
  |  Branch (1310:3): [True: 7.06k, False: 6.03M]
  ------------------
 1311|  7.06k|    if (len < 1 || len > 255)
  ------------------
  |  Branch (1311:9): [True: 4.70k, False: 2.36k]
  |  Branch (1311:20): [True: 1.02k, False: 1.34k]
  ------------------
 1312|  5.72k|      res = 0;
 1313|  7.06k|    break;
 1314|  3.32k|  case COAP_OPTION_ETAG:
  ------------------
  |  Branch (1314:3): [True: 3.32k, False: 6.03M]
  ------------------
 1315|  3.32k|    if (len < 1 || len > 8)
  ------------------
  |  Branch (1315:9): [True: 1.82k, False: 1.50k]
  |  Branch (1315:20): [True: 1.10k, False: 399]
  ------------------
 1316|  2.92k|      res = 0;
 1317|  3.32k|    break;
 1318|  2.10k|  case COAP_OPTION_IF_NONE_MATCH:
  ------------------
  |  Branch (1318:3): [True: 2.10k, False: 6.04M]
  ------------------
 1319|  2.10k|    if (len != 0)
  ------------------
  |  Branch (1319:9): [True: 1.52k, False: 579]
  ------------------
 1320|  1.52k|      res = 0;
 1321|  2.10k|    break;
 1322|  11.8k|  case COAP_OPTION_OBSERVE:
  ------------------
  |  Branch (1322:3): [True: 11.8k, False: 6.03M]
  ------------------
 1323|  11.8k|    if (len > 3)
  ------------------
  |  Branch (1323:9): [True: 9.54k, False: 2.27k]
  ------------------
 1324|  9.54k|      res = 0;
 1325|  11.8k|    break;
 1326|  5.55k|  case COAP_OPTION_URI_PORT:
  ------------------
  |  Branch (1326:3): [True: 5.55k, False: 6.03M]
  ------------------
 1327|  5.55k|    if (len > 2)
  ------------------
  |  Branch (1327:9): [True: 4.23k, False: 1.32k]
  ------------------
 1328|  4.23k|      res = 0;
 1329|  5.55k|    break;
 1330|  15.5k|  case COAP_OPTION_LOCATION_PATH:
  ------------------
  |  Branch (1330:3): [True: 15.5k, False: 6.02M]
  ------------------
 1331|  4.56M|  case COAP_OPTION_URI_PATH:
  ------------------
  |  Branch (1331:3): [True: 4.54M, False: 1.49M]
  ------------------
 1332|  4.56M|    if (len > 255)
  ------------------
  |  Branch (1332:9): [True: 1.06k, False: 4.56M]
  ------------------
 1333|  1.06k|      res = 0;
 1334|  4.56M|    if (coap_check_dots(opt_val, len)) {
  ------------------
  |  Branch (1334:9): [True: 2.66k, False: 4.56M]
  ------------------
 1335|  2.66k|      res = 0;
 1336|  2.66k|    }
 1337|  4.56M|    break;
 1338|  18.7k|  case COAP_OPTION_OSCORE:
  ------------------
  |  Branch (1338:3): [True: 18.7k, False: 6.02M]
  ------------------
 1339|  18.7k|    if (len > 255)
  ------------------
  |  Branch (1339:9): [True: 996, False: 17.7k]
  ------------------
 1340|    996|      res = 0;
 1341|  18.7k|    break;
 1342|  4.27k|  case COAP_OPTION_CONTENT_FORMAT:
  ------------------
  |  Branch (1342:3): [True: 4.27k, False: 6.03M]
  ------------------
 1343|  4.27k|    if (len > 2)
  ------------------
  |  Branch (1343:9): [True: 2.74k, False: 1.53k]
  ------------------
 1344|  2.74k|      res = 0;
 1345|  4.27k|    break;
 1346|  6.63k|  case COAP_OPTION_URI_PATH_ABB:
  ------------------
  |  Branch (1346:3): [True: 6.63k, False: 6.03M]
  ------------------
 1347|  6.63k|    if (len > 4)
  ------------------
  |  Branch (1347:9): [True: 5.01k, False: 1.61k]
  ------------------
 1348|  5.01k|      res = 0;
 1349|  6.63k|    break;
 1350|  5.69k|  case COAP_OPTION_MAXAGE:
  ------------------
  |  Branch (1350:3): [True: 5.69k, False: 6.03M]
  ------------------
 1351|  5.69k|    if (len > 4)
  ------------------
  |  Branch (1351:9): [True: 4.60k, False: 1.09k]
  ------------------
 1352|  4.60k|      res = 0;
 1353|  5.69k|    break;
 1354|   116k|  case COAP_OPTION_URI_QUERY:
  ------------------
  |  Branch (1354:3): [True: 116k, False: 5.92M]
  ------------------
 1355|   116k|    if (len > 255)
  ------------------
  |  Branch (1355:9): [True: 978, False: 115k]
  ------------------
 1356|    978|      res = 0;
 1357|   116k|    break;
 1358|  2.06k|  case COAP_OPTION_HOP_LIMIT:
  ------------------
  |  Branch (1358:3): [True: 2.06k, False: 6.04M]
  ------------------
 1359|  2.06k|    if (len != 1)
  ------------------
  |  Branch (1359:9): [True: 1.84k, False: 225]
  ------------------
 1360|  1.84k|      res = 0;
 1361|  2.06k|    break;
 1362|  19.3k|  case COAP_OPTION_ACCEPT:
  ------------------
  |  Branch (1362:3): [True: 19.3k, False: 6.02M]
  ------------------
 1363|  19.3k|    if (len > 2)
  ------------------
  |  Branch (1363:9): [True: 17.1k, False: 2.18k]
  ------------------
 1364|  17.1k|      res = 0;
 1365|  19.3k|    break;
 1366|   526k|  case COAP_OPTION_Q_BLOCK1:
  ------------------
  |  Branch (1366:3): [True: 526k, False: 5.51M]
  ------------------
 1367|   526k|    if (len > 3)
  ------------------
  |  Branch (1367:9): [True: 1.22k, False: 525k]
  ------------------
 1368|  1.22k|      res = 0;
 1369|   526k|    break;
 1370|  1.94k|  case COAP_OPTION_LOCATION_QUERY:
  ------------------
  |  Branch (1370:3): [True: 1.94k, False: 6.04M]
  ------------------
 1371|  1.94k|    if (len > 255)
  ------------------
  |  Branch (1371:9): [True: 987, False: 954]
  ------------------
 1372|    987|      res = 0;
 1373|  1.94k|    break;
 1374|  1.59k|  case COAP_OPTION_EDHOC:
  ------------------
  |  Branch (1374:3): [True: 1.59k, False: 6.04M]
  ------------------
 1375|  1.59k|    if (len != 0)
  ------------------
  |  Branch (1375:9): [True: 1.14k, False: 449]
  ------------------
 1376|  1.14k|      res = 0;
 1377|  1.59k|    break;
 1378|  1.49k|  case COAP_OPTION_BLOCK2:
  ------------------
  |  Branch (1378:3): [True: 1.49k, False: 6.04M]
  ------------------
 1379|  1.49k|    if (len > 3)
  ------------------
  |  Branch (1379:9): [True: 1.11k, False: 375]
  ------------------
 1380|  1.11k|      res = 0;
 1381|  1.49k|    break;
 1382|  2.00k|  case COAP_OPTION_BLOCK1:
  ------------------
  |  Branch (1382:3): [True: 2.00k, False: 6.04M]
  ------------------
 1383|  2.00k|    if (len > 3)
  ------------------
  |  Branch (1383:9): [True: 1.16k, False: 837]
  ------------------
 1384|  1.16k|      res = 0;
 1385|  2.00k|    break;
 1386|  1.40k|  case COAP_OPTION_SIZE2:
  ------------------
  |  Branch (1386:3): [True: 1.40k, False: 6.04M]
  ------------------
 1387|  1.40k|    if (len > 4)
  ------------------
  |  Branch (1387:9): [True: 1.03k, False: 376]
  ------------------
 1388|  1.03k|      res = 0;
 1389|  1.40k|    break;
 1390|  9.94k|  case COAP_OPTION_Q_BLOCK2:
  ------------------
  |  Branch (1390:3): [True: 9.94k, False: 6.03M]
  ------------------
 1391|  9.94k|    if (len > 3)
  ------------------
  |  Branch (1391:9): [True: 8.77k, False: 1.16k]
  ------------------
 1392|  8.77k|      res = 0;
 1393|  9.94k|    break;
 1394|  9.70k|  case COAP_OPTION_PROXY_URI:
  ------------------
  |  Branch (1394:3): [True: 9.70k, False: 6.03M]
  ------------------
 1395|  9.70k|    if (len < 1 || len > 1034)
  ------------------
  |  Branch (1395:9): [True: 3.63k, False: 6.07k]
  |  Branch (1395:20): [True: 1.02k, False: 5.05k]
  ------------------
 1396|  4.65k|      res = 0;
 1397|  9.70k|    break;
 1398|  3.04k|  case COAP_OPTION_PROXY_SCHEME:
  ------------------
  |  Branch (1398:3): [True: 3.04k, False: 6.03M]
  ------------------
 1399|  3.04k|    if (len < 1 || len > 255)
  ------------------
  |  Branch (1399:9): [True: 1.58k, False: 1.45k]
  |  Branch (1399:20): [True: 1.02k, False: 430]
  ------------------
 1400|  2.61k|      res = 0;
 1401|  3.04k|    break;
 1402|  2.97k|  case COAP_OPTION_SIZE1:
  ------------------
  |  Branch (1402:3): [True: 2.97k, False: 6.03M]
  ------------------
 1403|  2.97k|    if (len > 4)
  ------------------
  |  Branch (1403:9): [True: 1.07k, False: 1.89k]
  ------------------
 1404|  1.07k|      res = 0;
 1405|  2.97k|    break;
 1406|  1.99k|  case COAP_OPTION_ECHO:
  ------------------
  |  Branch (1406:3): [True: 1.99k, False: 6.04M]
  ------------------
 1407|  1.99k|    if (len > 40)
  ------------------
  |  Branch (1407:9): [True: 1.16k, False: 824]
  ------------------
 1408|  1.16k|      res = 0;
 1409|  1.99k|    break;
 1410|  1.44k|  case COAP_OPTION_NORESPONSE:
  ------------------
  |  Branch (1410:3): [True: 1.44k, False: 6.04M]
  ------------------
 1411|  1.44k|    if (len > 1)
  ------------------
  |  Branch (1411:9): [True: 1.02k, False: 424]
  ------------------
 1412|  1.02k|      res = 0;
 1413|  1.44k|    break;
 1414|  2.05k|  case COAP_OPTION_RTAG:
  ------------------
  |  Branch (1414:3): [True: 2.05k, False: 6.04M]
  ------------------
 1415|  2.05k|    if (len > 8)
  ------------------
  |  Branch (1415:9): [True: 1.28k, False: 767]
  ------------------
 1416|  1.28k|      res = 0;
 1417|  2.05k|    break;
 1418|   706k|  default:
  ------------------
  |  Branch (1418:3): [True: 706k, False: 5.33M]
  ------------------
 1419|   706k|    ;
 1420|  6.04M|  }
 1421|  6.04M|  return res;
 1422|  6.04M|}
coap_pdu_parse_opt:
 1458|  3.02k|coap_pdu_parse_opt(coap_pdu_t *pdu, coap_opt_filter_t *error_opts) {
 1459|  3.02k|  int good = 1;
 1460|       |
 1461|  3.02k|  coap_option_filter_clear(error_opts);
 1462|       |
 1463|       |  /* sanity checks */
 1464|  3.02k|  if (pdu->code == 0) {
  ------------------
  |  Branch (1464:7): [True: 26, False: 3.00k]
  ------------------
 1465|     26|    if (pdu->used_size != 0 || pdu->e_token_length) {
  ------------------
  |  Branch (1465:9): [True: 24, False: 2]
  |  Branch (1465:32): [True: 1, False: 1]
  ------------------
 1466|     25|      coap_log_debug("coap_pdu_parse: empty message is not empty\n");
  ------------------
  |  |  126|     25|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     25|#define coap_log(level, ...) do { \
  |  |  |  |  291|     25|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 25]
  |  |  |  |  ------------------
  |  |  |  |  292|     25|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     25|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 25]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1467|     25|      return 0;
 1468|     25|    }
 1469|     26|  }
 1470|       |
 1471|  3.00k|  if (pdu->e_token_length > pdu->used_size) {
  ------------------
  |  Branch (1471:7): [True: 4, False: 3.00k]
  ------------------
 1472|      4|    coap_log_debug("coap_pdu_parse: invalid Token\n");
  ------------------
  |  |  126|      4|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      4|#define coap_log(level, ...) do { \
  |  |  |  |  291|      4|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  292|      4|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      4|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 4]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1473|      4|    return 0;
 1474|      4|  }
 1475|       |
 1476|  3.00k|  pdu->max_opt = 0;
 1477|  3.00k|  if (pdu->code == 0) {
  ------------------
  |  Branch (1477:7): [True: 1, False: 2.99k]
  ------------------
 1478|       |    /* empty packet */
 1479|      1|    pdu->used_size = 0;
 1480|      1|    pdu->data = NULL;
 1481|  2.99k|  } else {
 1482|       |    /* skip header + token */
 1483|  2.99k|    coap_opt_t *opt = pdu->token + pdu->e_token_length;
 1484|  2.99k|    size_t length = pdu->used_size - pdu->e_token_length;
 1485|       |
 1486|  9.59M|    while (length > 0 && *opt != COAP_PAYLOAD_START) {
  ------------------
  |  |   96|  9.59M|#define COAP_PAYLOAD_START 0xFF /* payload marker */
  ------------------
  |  Branch (1486:12): [True: 9.59M, False: 2.37k]
  |  Branch (1486:26): [True: 9.59M, False: 193]
  ------------------
 1487|  9.59M|#if (COAP_MAX_LOGGING_LEVEL >= _COAP_LOG_WARN)
 1488|  9.59M|      coap_opt_t *opt_last = opt;
 1489|  9.59M|#endif
 1490|  9.59M|      size_t optsize = next_option_safe(&opt, &length, &pdu->max_opt);
 1491|  9.59M|      uint32_t len;
 1492|  9.59M|      const uint8_t *opt_val;
 1493|       |
 1494|  9.59M|      if (optsize == 0) {
  ------------------
  |  Branch (1494:11): [True: 435, False: 9.59M]
  ------------------
 1495|    435|        coap_log_debug("coap_pdu_parse: %d.%02d: offset %u malformed option\n",
  ------------------
  |  |  126|    435|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|    435|#define coap_log(level, ...) do { \
  |  |  |  |  291|    435|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 435]
  |  |  |  |  ------------------
  |  |  |  |  292|    435|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|    435|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 435]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1496|    435|                       pdu->code >> 5, pdu->code & 0x1F,
 1497|    435|                       (int)(opt_last - pdu->token - pdu->e_token_length));
 1498|    435|        coap_option_filter_set(error_opts, pdu->max_opt);
 1499|    435|        good = 0;
 1500|    435|        break;
 1501|    435|      }
 1502|  9.59M|      len = coap_opt_length((const uint8_t *)opt - optsize);
 1503|  9.59M|      opt_val = coap_opt_value((const uint8_t *)opt - optsize);
 1504|  9.59M|      if (COAP_PDU_IS_SIGNALING(pdu) ?
  ------------------
  |  |  102|  9.59M|#define COAP_PDU_IS_SIGNALING(pdu) ((pdu)->code >= 224)
  |  |  ------------------
  |  |  |  Branch (102:36): [True: 4.12M, False: 5.47M]
  |  |  ------------------
  ------------------
  |  Branch (1504:11): [True: 3.43M, False: 6.15M]
  ------------------
 1505|  4.12M|          !coap_pdu_parse_opt_csm(pdu->code, pdu->max_opt, len) :
 1506|  9.59M|          !coap_pdu_parse_opt_base(pdu->max_opt, len, opt_val)) {
 1507|  3.43M|        coap_log_warn("coap_pdu_parse: %d.%02d: offset %u option %u has bad length %" PRIu32 " or value\n",
  ------------------
  |  |  108|  3.43M|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|  3.43M|#define coap_log(level, ...) do { \
  |  |  |  |  291|  3.43M|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 3.43M]
  |  |  |  |  ------------------
  |  |  |  |  292|  3.43M|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|  3.43M|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 3.43M]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1508|  3.43M|                      pdu->code >> 5, pdu->code & 0x1F,
 1509|  3.43M|                      (int)(opt_last - pdu->token - pdu->e_token_length), pdu->max_opt,
 1510|  3.43M|                      len);
 1511|  3.43M|        coap_option_filter_set(error_opts, pdu->max_opt);
 1512|  3.43M|        good = 0;
 1513|  3.43M|      }
 1514|  9.59M|    }
 1515|       |
 1516|  2.99k|    if (!good) {
  ------------------
  |  Branch (1516:9): [True: 1.40k, False: 1.59k]
  ------------------
 1517|       |      /*
 1518|       |       * Dump the options in the PDU for analysis, space separated except
 1519|       |       * error options which are prefixed by *
 1520|       |       * Two rows - hex and ascii (if printable)
 1521|       |       */
 1522|  1.40k|      static char outbuf[COAP_DEBUG_BUF_SIZE];
 1523|  1.40k|      char *obp;
 1524|  1.40k|      size_t tlen;
 1525|  1.40k|      size_t outbuflen;
 1526|  1.40k|      int i;
 1527|  1.40k|      int ok;
 1528|       |
 1529|  4.21k|      for (i = 0; i < 2; i++) {
  ------------------
  |  Branch (1529:19): [True: 2.81k, False: 1.40k]
  ------------------
 1530|  2.81k|        opt = pdu->token + pdu->e_token_length;
 1531|  2.81k|        length = pdu->used_size - pdu->e_token_length;
 1532|  2.81k|        pdu->max_opt = 0;
 1533|       |
 1534|  2.81k|        outbuflen = sizeof(outbuf);
 1535|  2.81k|        obp = outbuf;
 1536|  2.81k|        ok = write_prefix(&obp, &outbuflen, "O: ", 3);
 1537|       |        /*
 1538|       |         * Not safe to check for 'ok' here as a lot of variables may get
 1539|       |         * partially changed due to lack of outbuflen */
 1540|  8.82M|        while (length > 0 && *opt != COAP_PAYLOAD_START) {
  ------------------
  |  |   96|  8.82M|#define COAP_PAYLOAD_START 0xFF /* payload marker */
  ------------------
  |  Branch (1540:16): [True: 8.82M, False: 2.69k]
  |  Branch (1540:30): [True: 8.82M, False: 120]
  ------------------
 1541|  8.82M|          coap_opt_t *opt_last = opt;
 1542|  8.82M|          size_t optsize = next_option_safe(&opt, &length, &pdu->max_opt);
 1543|  8.82M|          const uint32_t len =
 1544|  8.82M|              optsize ? coap_opt_length((const uint8_t *)opt - optsize) : 0;
  ------------------
  |  Branch (1544:15): [True: 8.82M, False: 870]
  ------------------
 1545|  8.82M|          const uint8_t *opt_val =
 1546|  8.82M|              optsize ?  coap_opt_value((const uint8_t *)opt - optsize) : 0;
  ------------------
  |  Branch (1546:15): [True: 8.82M, False: 870]
  ------------------
 1547|       |
 1548|  8.82M|          if (!optsize || (COAP_PDU_IS_SIGNALING(pdu) ?
  ------------------
  |  |  102|  8.82M|#define COAP_PDU_IS_SIGNALING(pdu) ((pdu)->code >= 224)
  |  |  ------------------
  |  |  |  Branch (102:36): [True: 8.24M, False: 571k]
  |  |  ------------------
  ------------------
  |  Branch (1548:15): [True: 870, False: 8.82M]
  |  Branch (1548:27): [True: 6.87M, False: 1.94M]
  ------------------
 1549|  8.24M|                           !coap_pdu_parse_opt_csm(pdu->code, pdu->max_opt, len) :
 1550|  8.82M|                           !coap_pdu_parse_opt_base(pdu->max_opt, len, opt_val))) {
 1551|  6.87M|            ok = ok && write_prefix(&obp, &outbuflen, "*", 1);
  ------------------
  |  Branch (1551:18): [True: 55.1k, False: 6.82M]
  |  Branch (1551:24): [True: 55.1k, False: 22]
  ------------------
 1552|  6.87M|            if (!optsize) {
  ------------------
  |  Branch (1552:17): [True: 870, False: 6.87M]
  ------------------
 1553|       |              /* Skip to end of options to output all data */
 1554|    870|              opt = pdu->token + pdu->used_size;
 1555|    870|              length = 0;
 1556|    870|            }
 1557|  6.87M|          } else {
 1558|  1.94M|            ok = ok && write_prefix(&obp, &outbuflen, " ", 1);
  ------------------
  |  Branch (1558:18): [True: 40.1k, False: 1.90M]
  |  Branch (1558:24): [True: 40.1k, False: 18]
  ------------------
 1559|  1.94M|          }
 1560|  8.82M|          tlen = opt - opt_last;
 1561|  86.9M|          while (tlen) {
  ------------------
  |  Branch (1561:18): [True: 78.1M, False: 8.82M]
  ------------------
 1562|  78.1M|            tlen--;
 1563|  78.1M|            ok = ok && write_char(&obp, &outbuflen, *opt_last, i);
  ------------------
  |  Branch (1563:18): [True: 1.05M, False: 77.0M]
  |  Branch (1563:24): [True: 1.05M, False: 800]
  ------------------
 1564|  78.1M|            opt_last++;
 1565|  78.1M|          }
 1566|  8.82M|        }
 1567|  2.81k|        if (length && *opt == COAP_PAYLOAD_START) {
  ------------------
  |  |   96|    120|#define COAP_PAYLOAD_START 0xFF /* payload marker */
  ------------------
  |  Branch (1567:13): [True: 120, False: 2.69k]
  |  Branch (1567:23): [True: 120, False: 0]
  ------------------
 1568|    120|          write_char(&obp, &outbuflen, *opt, i);
 1569|    120|        }
 1570|       |        /* write_*() always leaves a spare byte to null terminate */
 1571|  2.81k|        *obp = '\000';
 1572|  2.81k|        coap_log_debug("%s\n", outbuf);
  ------------------
  |  |  126|  2.81k|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|  2.81k|#define coap_log(level, ...) do { \
  |  |  |  |  291|  2.81k|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 2.81k]
  |  |  |  |  ------------------
  |  |  |  |  292|  2.81k|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|  2.81k|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 2.81k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1573|  2.81k|      }
 1574|  1.40k|    }
 1575|       |
 1576|  2.99k|    if (length > 0) {
  ------------------
  |  Branch (1576:9): [True: 193, False: 2.80k]
  ------------------
 1577|    193|      assert(*opt == COAP_PAYLOAD_START);
  ------------------
  |  Branch (1577:7): [True: 193, False: 0]
  ------------------
 1578|    193|      opt++;
 1579|    193|      length--;
 1580|       |
 1581|    193|      if (length == 0) {
  ------------------
  |  Branch (1581:11): [True: 18, False: 175]
  ------------------
 1582|     18|        coap_log_debug("coap_pdu_parse: message ending in payload start marker\n");
  ------------------
  |  |  126|     18|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     18|#define coap_log(level, ...) do { \
  |  |  |  |  291|     18|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 18]
  |  |  |  |  ------------------
  |  |  |  |  292|     18|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     18|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 18]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1583|     18|        return 0;
 1584|     18|      }
 1585|    193|    }
 1586|  2.98k|    if (length > 0)
  ------------------
  |  Branch (1586:9): [True: 175, False: 2.80k]
  ------------------
 1587|    175|      pdu->data = (uint8_t *)opt;
 1588|  2.80k|    else
 1589|  2.80k|      pdu->data = NULL;
 1590|  2.98k|  }
 1591|       |
 1592|  2.98k|  return good;
 1593|  3.00k|}
coap_pdu_parse:
 1599|  3.06k|               coap_pdu_t *pdu) {
 1600|  3.06k|  coap_opt_filter_t error_opts;
 1601|       |
 1602|  3.06k|  return coap_pdu_parse2(proto, data, length, pdu, &error_opts);
 1603|  3.06k|}
coap_pdu_parse2:
 1610|  3.06k|                coap_opt_filter_t *error_opts) {
 1611|  3.06k|  size_t hdr_size;
 1612|       |
 1613|  3.06k|  if (length == 0)
  ------------------
  |  Branch (1613:7): [True: 0, False: 3.06k]
  ------------------
 1614|      0|    return 0;
 1615|  3.06k|  hdr_size = coap_pdu_parse_header_size(proto, data);
 1616|  3.06k|  if (!hdr_size || hdr_size > length)
  ------------------
  |  Branch (1616:7): [True: 0, False: 3.06k]
  |  Branch (1616:20): [True: 1, False: 3.06k]
  ------------------
 1617|      1|    return 0;
 1618|  3.06k|  if (hdr_size > pdu->max_hdr_size)
  ------------------
  |  Branch (1618:7): [True: 0, False: 3.06k]
  ------------------
 1619|      0|    return 0;
 1620|  3.06k|  if (!coap_pdu_resize(pdu, length - hdr_size))
  ------------------
  |  Branch (1620:7): [True: 0, False: 3.06k]
  ------------------
 1621|      0|    return 0;
 1622|  3.06k|  if (pdu->token - hdr_size != data)
  ------------------
  |  Branch (1622:7): [True: 3.06k, False: 0]
  ------------------
 1623|  3.06k|    memcpy(pdu->token - hdr_size, data, length);
 1624|  3.06k|  pdu->hdr_size = (uint8_t)hdr_size;
 1625|  3.06k|  pdu->used_size = length - hdr_size;
 1626|  3.06k|  return coap_pdu_parse_header(pdu, proto) && coap_pdu_parse_opt(pdu, error_opts);
  ------------------
  |  Branch (1626:10): [True: 3.02k, False: 31]
  |  Branch (1626:47): [True: 1.58k, False: 1.44k]
  ------------------
 1627|  3.06k|}
coap_pdu_encode_header:
 1630|  1.58k|coap_pdu_encode_header(coap_pdu_t *pdu, coap_proto_t proto) {
 1631|  1.58k|  uint8_t e_token_length;
 1632|       |
 1633|  1.58k|  if (pdu->actual_token.length < COAP_TOKEN_EXT_1B_BIAS) {
  ------------------
  |  |   56|  1.58k|#define COAP_TOKEN_EXT_1B_BIAS 13
  ------------------
  |  Branch (1633:7): [True: 1.52k, False: 61]
  ------------------
 1634|  1.52k|    e_token_length = (uint8_t)pdu->actual_token.length;
 1635|  1.52k|  } else if (pdu->actual_token.length < COAP_TOKEN_EXT_2B_BIAS) {
  ------------------
  |  |   57|     61|#define COAP_TOKEN_EXT_2B_BIAS 269 /* 13 + 256 */
  ------------------
  |  Branch (1635:14): [True: 26, False: 35]
  ------------------
 1636|     26|    e_token_length = COAP_TOKEN_EXT_1B_TKL;
  ------------------
  |  |   54|     26|#define COAP_TOKEN_EXT_1B_TKL 13
  ------------------
 1637|     35|  } else if (pdu->actual_token.length <= COAP_TOKEN_EXT_MAX) {
  ------------------
  |  |   60|     35|#define COAP_TOKEN_EXT_MAX 65804UL /* 13 + 256 + 65535 */
  ------------------
  |  Branch (1637:14): [True: 35, False: 0]
  ------------------
 1638|     35|    e_token_length = COAP_TOKEN_EXT_2B_TKL;
  ------------------
  |  |   55|     35|#define COAP_TOKEN_EXT_2B_TKL 14
  ------------------
 1639|     35|  } else {
 1640|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1641|      0|    return 0;
 1642|      0|  }
 1643|  1.58k|  if (COAP_PROTO_NOT_RELIABLE(proto)) {
  ------------------
  |  |   41|  1.58k|#define COAP_PROTO_NOT_RELIABLE(p) ((p)==COAP_PROTO_UDP || (p)==COAP_PROTO_DTLS)
  |  |  ------------------
  |  |  |  Branch (41:37): [True: 0, False: 1.58k]
  |  |  |  Branch (41:60): [True: 0, False: 1.58k]
  |  |  ------------------
  ------------------
 1644|      0|    assert(pdu->max_hdr_size >= 4);
  ------------------
  |  Branch (1644:5): [True: 0, False: 0]
  ------------------
 1645|      0|    if (pdu->max_hdr_size < 4) {
  ------------------
  |  Branch (1645:9): [True: 0, False: 0]
  ------------------
 1646|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1647|      0|      return 0;
 1648|      0|    }
 1649|      0|    pdu->token[-4] = COAP_DEFAULT_VERSION << 6
  ------------------
  |  |   35|      0|#define COAP_DEFAULT_VERSION      1 /* version of CoAP supported */
  ------------------
 1650|      0|                     | pdu->type << 4
 1651|      0|                     | e_token_length;
 1652|      0|    pdu->token[-3] = pdu->code;
 1653|      0|    pdu->token[-2] = (uint8_t)(pdu->mid >> 8);
 1654|      0|    pdu->token[-1] = (uint8_t)(pdu->mid);
 1655|      0|    pdu->hdr_size = 4;
 1656|      0|#if !COAP_DISABLE_TCP
 1657|  1.58k|  } else if (COAP_PROTO_RELIABLE(proto)) {
  ------------------
  |  |   42|  1.58k|#define COAP_PROTO_RELIABLE(p) ((p)==COAP_PROTO_TCP || (p)==COAP_PROTO_TLS || \
  |  |  ------------------
  |  |  |  Branch (42:33): [True: 0, False: 1.58k]
  |  |  |  Branch (42:56): [True: 0, False: 1.58k]
  |  |  ------------------
  |  |   43|  1.58k|                                (p)==COAP_PROTO_WS || (p)==COAP_PROTO_WSS)
  |  |  ------------------
  |  |  |  Branch (43:33): [True: 1.58k, False: 0]
  |  |  |  Branch (43:55): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1658|  1.58k|    size_t len;
 1659|  1.58k|    assert(pdu->used_size >= pdu->e_token_length);
  ------------------
  |  Branch (1659:5): [True: 1.58k, False: 0]
  ------------------
 1660|  1.58k|    if (pdu->used_size < pdu->e_token_length) {
  ------------------
  |  Branch (1660:9): [True: 0, False: 1.58k]
  ------------------
 1661|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1662|      0|      return 0;
 1663|      0|    }
 1664|       |
 1665|       |    /* A lot of the reliable code assumes type is CON */
 1666|  1.58k|    if (pdu->type != COAP_MESSAGE_CON)
  ------------------
  |  Branch (1666:9): [True: 0, False: 1.58k]
  ------------------
 1667|      0|      pdu->type = COAP_MESSAGE_CON;
 1668|       |
 1669|  1.58k|    if (proto == COAP_PROTO_WS || proto == COAP_PROTO_WSS)
  ------------------
  |  Branch (1669:9): [True: 1.58k, False: 0]
  |  Branch (1669:35): [True: 0, False: 0]
  ------------------
 1670|  1.58k|      len = 0;
 1671|      0|    else
 1672|      0|      len = pdu->used_size - pdu->e_token_length;
 1673|  1.58k|    if (len <= COAP_MAX_MESSAGE_SIZE_TCP0) {
  ------------------
  |  |   43|  1.58k|#define COAP_MAX_MESSAGE_SIZE_TCP0 (COAP_MESSAGE_SIZE_OFFSET_TCP8-1) /* 12 */
  |  |  ------------------
  |  |  |  |   38|  1.58k|#define COAP_MESSAGE_SIZE_OFFSET_TCP8 13
  |  |  ------------------
  ------------------
  |  Branch (1673:9): [True: 1.58k, False: 0]
  ------------------
 1674|  1.58k|      assert(pdu->max_hdr_size >= 2);
  ------------------
  |  Branch (1674:7): [True: 1.58k, False: 0]
  ------------------
 1675|  1.58k|      if (pdu->max_hdr_size < 2) {
  ------------------
  |  Branch (1675:11): [True: 0, False: 1.58k]
  ------------------
 1676|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1677|      0|        return 0;
 1678|      0|      }
 1679|  1.58k|      pdu->token[-2] = (uint8_t)len << 4
 1680|  1.58k|                       | e_token_length;
 1681|  1.58k|      pdu->token[-1] = pdu->code;
 1682|  1.58k|      pdu->hdr_size = 2;
 1683|  1.58k|    } 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 (1683:16): [True: 0, False: 0]
  ------------------
 1684|      0|      assert(pdu->max_hdr_size >= 3);
  ------------------
  |  Branch (1684:7): [True: 0, False: 0]
  ------------------
 1685|      0|      if (pdu->max_hdr_size < 3) {
  ------------------
  |  Branch (1685:11): [True: 0, False: 0]
  ------------------
 1686|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1687|      0|        return 0;
 1688|      0|      }
 1689|      0|      pdu->token[-3] = 13 << 4 | e_token_length;
 1690|      0|      pdu->token[-2] = (uint8_t)(len - COAP_MESSAGE_SIZE_OFFSET_TCP8);
  ------------------
  |  |   38|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP8 13
  ------------------
 1691|      0|      pdu->token[-1] = pdu->code;
 1692|      0|      pdu->hdr_size = 3;
 1693|      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 (1693:16): [True: 0, False: 0]
  ------------------
 1694|      0|      assert(pdu->max_hdr_size >= 4);
  ------------------
  |  Branch (1694:7): [True: 0, False: 0]
  ------------------
 1695|      0|      if (pdu->max_hdr_size < 4) {
  ------------------
  |  Branch (1695:11): [True: 0, False: 0]
  ------------------
 1696|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1697|      0|        return 0;
 1698|      0|      }
 1699|      0|      pdu->token[-4] = 14 << 4 | e_token_length;
 1700|      0|      pdu->token[-3] = (uint8_t)((len - COAP_MESSAGE_SIZE_OFFSET_TCP16) >> 8);
  ------------------
  |  |   39|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP16 269 /* 13 + 256 */
  ------------------
 1701|      0|      pdu->token[-2] = (uint8_t)(len - COAP_MESSAGE_SIZE_OFFSET_TCP16);
  ------------------
  |  |   39|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP16 269 /* 13 + 256 */
  ------------------
 1702|      0|      pdu->token[-1] = pdu->code;
 1703|      0|      pdu->hdr_size = 4;
 1704|      0|    } else {
 1705|      0|      assert(pdu->max_hdr_size >= 6);
  ------------------
  |  Branch (1705:7): [True: 0, False: 0]
  ------------------
 1706|      0|      if (pdu->max_hdr_size < 6) {
  ------------------
  |  Branch (1706:11): [True: 0, False: 0]
  ------------------
 1707|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1708|      0|        return 0;
 1709|      0|      }
 1710|      0|      pdu->token[-6] = 15 << 4 | e_token_length;
 1711|      0|      pdu->token[-5] = (uint8_t)((len - COAP_MESSAGE_SIZE_OFFSET_TCP32) >> 24);
  ------------------
  |  |   40|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */
  ------------------
 1712|      0|      pdu->token[-4] = (uint8_t)((len - COAP_MESSAGE_SIZE_OFFSET_TCP32) >> 16);
  ------------------
  |  |   40|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */
  ------------------
 1713|      0|      pdu->token[-3] = (uint8_t)((len - COAP_MESSAGE_SIZE_OFFSET_TCP32) >> 8);
  ------------------
  |  |   40|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */
  ------------------
 1714|      0|      pdu->token[-2] = (uint8_t)(len - COAP_MESSAGE_SIZE_OFFSET_TCP32);
  ------------------
  |  |   40|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */
  ------------------
 1715|      0|      pdu->token[-1] = pdu->code;
 1716|      0|      pdu->hdr_size = 6;
 1717|      0|    }
 1718|  1.58k|#endif /* ! COAP_DISABLE_TCP */
 1719|  1.58k|  } else {
 1720|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1721|      0|  }
 1722|  1.58k|  return pdu->hdr_size;
 1723|  1.58k|}
coap_pdu.c:coap_pdu_parse_opt_csm:
 1234|  12.3M|coap_pdu_parse_opt_csm(coap_pdu_code_t code, coap_option_num_t option, size_t len) {
 1235|  12.3M|  switch ((coap_pdu_signaling_proto_t)code) {
 1236|  21.3k|  case COAP_SIGNALING_CSM:
  ------------------
  |  Branch (1236:3): [True: 21.3k, False: 12.3M]
  ------------------
 1237|  21.3k|    switch ((coap_sig_csm_opt_t)option) {
 1238|  1.71k|    case COAP_SIG_OPT_MAX_MESSAGE_SIZE:
  ------------------
  |  Branch (1238:5): [True: 1.71k, False: 19.6k]
  ------------------
 1239|  1.71k|      if (len > 4)
  ------------------
  |  Branch (1239:11): [True: 1.13k, False: 580]
  ------------------
 1240|  1.13k|        goto bad;
 1241|    580|      break;
 1242|  1.83k|    case COAP_SIG_OPT_BLOCK_WISE_TRANSFER:
  ------------------
  |  Branch (1242:5): [True: 1.83k, False: 19.5k]
  ------------------
 1243|  1.83k|      if (len > 0)
  ------------------
  |  Branch (1243:11): [True: 1.12k, False: 703]
  ------------------
 1244|  1.12k|        goto bad;
 1245|    703|      break;
 1246|  2.49k|    case COAP_SIG_OPT_EXTENDED_TOKEN_LENGTH:
  ------------------
  |  Branch (1246:5): [True: 2.49k, False: 18.8k]
  ------------------
 1247|  2.49k|      if (len > 3)
  ------------------
  |  Branch (1247:11): [True: 1.40k, False: 1.09k]
  ------------------
 1248|  1.40k|        goto bad;
 1249|  1.09k|      break;
 1250|  15.3k|    default:
  ------------------
  |  Branch (1250:5): [True: 15.3k, False: 6.04k]
  ------------------
 1251|  15.3k|      if (option & 0x01)
  ------------------
  |  Branch (1251:11): [True: 7.35k, False: 7.96k]
  ------------------
 1252|  7.35k|        goto bad; /* Critical */
 1253|  21.3k|    }
 1254|  10.3k|    break;
 1255|  10.3k|  case COAP_SIGNALING_PING:
  ------------------
  |  Branch (1255:3): [True: 1.89k, False: 12.3M]
  ------------------
 1256|  3.15M|  case COAP_SIGNALING_PONG:
  ------------------
  |  Branch (1256:3): [True: 3.15M, False: 9.22M]
  ------------------
 1257|  3.15M|    switch ((coap_sig_ping_opt_t)option) {
 1258|  2.13M|    case COAP_SIG_OPT_CUSTODY:
  ------------------
  |  Branch (1258:5): [True: 2.13M, False: 1.02M]
  ------------------
 1259|  2.13M|      if (len > 0)
  ------------------
  |  Branch (1259:11): [True: 1.65k, False: 2.12M]
  ------------------
 1260|  1.65k|        goto bad;
 1261|  2.12M|      break;
 1262|  2.12M|    default:
  ------------------
  |  Branch (1262:5): [True: 1.02M, False: 2.13M]
  ------------------
 1263|  1.02M|      if (option & 0x01)
  ------------------
  |  Branch (1263:11): [True: 1.02M, False: 926]
  ------------------
 1264|  1.02M|        goto bad; /* Critical */
 1265|  3.15M|    }
 1266|  2.12M|    break;
 1267|  2.12M|  case COAP_SIGNALING_RELEASE:
  ------------------
  |  Branch (1267:3): [True: 28.8k, False: 12.3M]
  ------------------
 1268|  28.8k|    switch ((coap_sig_release_opt_t)option) {
 1269|  13.3k|    case COAP_SIG_OPT_ALTERNATIVE_ADDRESS:
  ------------------
  |  Branch (1269:5): [True: 13.3k, False: 15.4k]
  ------------------
 1270|  13.3k|      if (len < 1 || len > 255)
  ------------------
  |  Branch (1270:11): [True: 11.8k, False: 1.56k]
  |  Branch (1270:22): [True: 1.14k, False: 414]
  ------------------
 1271|  12.9k|        goto bad;
 1272|    414|      break;
 1273|  3.44k|    case COAP_SIG_OPT_HOLD_OFF:
  ------------------
  |  Branch (1273:5): [True: 3.44k, False: 25.4k]
  ------------------
 1274|  3.44k|      if (len > 3)
  ------------------
  |  Branch (1274:11): [True: 1.26k, False: 2.17k]
  ------------------
 1275|  1.26k|        goto bad;
 1276|  2.17k|      break;
 1277|  12.0k|    default:
  ------------------
  |  Branch (1277:5): [True: 12.0k, False: 16.8k]
  ------------------
 1278|  12.0k|      if (option & 0x01)
  ------------------
  |  Branch (1278:11): [True: 7.19k, False: 4.86k]
  ------------------
 1279|  7.19k|        goto bad; /* Critical */
 1280|  28.8k|    }
 1281|  7.45k|    break;
 1282|  15.3k|  case COAP_SIGNALING_ABORT:
  ------------------
  |  Branch (1282:3): [True: 15.3k, False: 12.3M]
  ------------------
 1283|  15.3k|    switch ((coap_sig_abort_opt_t)option) {
 1284|  1.48k|    case COAP_SIG_OPT_BAD_CSM_OPTION:
  ------------------
  |  Branch (1284:5): [True: 1.48k, False: 13.8k]
  ------------------
 1285|  1.48k|      if (len > 2)
  ------------------
  |  Branch (1285:11): [True: 1.05k, False: 425]
  ------------------
 1286|  1.05k|        goto bad;
 1287|    425|      break;
 1288|  13.8k|    default:
  ------------------
  |  Branch (1288:5): [True: 13.8k, False: 1.48k]
  ------------------
 1289|  13.8k|      if (option & 0x01)
  ------------------
  |  Branch (1289:11): [True: 9.53k, False: 4.28k]
  ------------------
 1290|  9.53k|        goto bad; /* Critical */
 1291|  15.3k|    }
 1292|  4.71k|    break;
 1293|  9.15M|  default:
  ------------------
  |  Branch (1293:3): [True: 9.15M, False: 3.21M]
  ------------------
 1294|  9.15M|    goto bad;
 1295|  12.3M|  }
 1296|  2.15M|  return 1;
 1297|  10.2M|bad:
 1298|  10.2M|  return 0;
 1299|  12.3M|}
coap_pdu.c:next_option_safe:
 1052|  18.4M|next_option_safe(coap_opt_t **optp, size_t *length, uint16_t *max_opt) {
 1053|  18.4M|  coap_option_t option;
 1054|  18.4M|  size_t optsize;
 1055|       |
 1056|  18.4M|  assert(optp);
  ------------------
  |  Branch (1056:3): [True: 18.4M, False: 0]
  ------------------
 1057|  18.4M|  assert(*optp);
  ------------------
  |  Branch (1057:3): [True: 18.4M, False: 0]
  ------------------
 1058|  18.4M|  assert(length);
  ------------------
  |  Branch (1058:3): [True: 18.4M, False: 0]
  ------------------
 1059|       |
 1060|  18.4M|  optsize = coap_opt_parse(*optp, *length, &option);
 1061|  18.4M|  assert(optsize <= *length);
  ------------------
  |  Branch (1061:3): [True: 18.4M, False: 0]
  ------------------
 1062|       |
 1063|       |  /* signal an error if this option would exceed the
 1064|       |   * allowed number space */
 1065|  18.4M|  if ((uint32_t)(*max_opt) + option.delta > COAP_MAX_OPT) {
  ------------------
  |  |  105|  18.4M|#define COAP_MAX_OPT 65535 /**< the highest option number we know */
  ------------------
  |  Branch (1065:7): [True: 21, False: 18.4M]
  ------------------
 1066|     21|    return 0;
 1067|     21|  }
 1068|  18.4M|  *max_opt += option.delta;
 1069|  18.4M|  *optp += optsize;
 1070|  18.4M|  *length -= optsize;
 1071|       |
 1072|  18.4M|  return optsize;
 1073|  18.4M|}
coap_pdu.c:write_prefix:
 1425|  98.1k|write_prefix(char **obp, size_t *len, const char *prf, size_t prflen) {
 1426|       |  /* Make sure space for null terminating byte */
 1427|  98.1k|  if (*len < prflen +1) {
  ------------------
  |  Branch (1427:7): [True: 40, False: 98.1k]
  ------------------
 1428|     40|    return 0;
 1429|     40|  }
 1430|       |
 1431|  98.1k|  memcpy(*obp, prf, prflen);
 1432|  98.1k|  *obp += prflen;
 1433|  98.1k|  *len -= prflen;
 1434|  98.1k|  return 1;
 1435|  98.1k|}
coap_pdu.c:write_char:
 1438|  1.05M|write_char(char **obp, size_t *len, int c, int printable) {
 1439|       |  /* Make sure space for null terminating byte */
 1440|  1.05M|  if (*len < 2 +1) {
  ------------------
  |  Branch (1440:7): [True: 884, False: 1.05M]
  ------------------
 1441|    884|    return 0;
 1442|    884|  }
 1443|       |
 1444|  1.05M|  if (!printable) {
  ------------------
  |  Branch (1444:7): [True: 527k, False: 527k]
  ------------------
 1445|   527k|    const uint8_t hex[] = "0123456789abcdef";
 1446|   527k|    (*obp)[0] = hex[(c & 0xf0) >> 4];
 1447|   527k|    (*obp)[1] = hex[c & 0x0f];
 1448|   527k|  } else {
 1449|   527k|    (*obp)[0] = isprint(c) ? c : '.';
  ------------------
  |  Branch (1449:17): [True: 84.3k, False: 442k]
  ------------------
 1450|   527k|    (*obp)[1] = ' ';
 1451|   527k|  }
 1452|  1.05M|  *obp += 2;
 1453|  1.05M|  *len -= 2;
 1454|  1.05M|  return 1;
 1455|  1.05M|}

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

coap_new_string:
   21|  1.48k|coap_new_string(size_t size) {
   22|  1.48k|  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.48k|  if (size > SIZE_MAX - sizeof(coap_str_bin_union_t) - 1 - 8) {
  ------------------
  |  Branch (31:7): [True: 0, False: 1.48k]
  ------------------
   32|      0|    return NULL;
   33|      0|  }
   34|       |
   35|  1.48k|  s = (coap_string_t *)coap_malloc_type(COAP_STRING,
   36|  1.48k|                                        sizeof(coap_str_bin_union_t) + size + 1);
   37|  1.48k|  if (!s) {
  ------------------
  |  Branch (37:7): [True: 0, False: 1.48k]
  ------------------
   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.48k|  memset(s, 0, sizeof(coap_str_bin_union_t));
   43|  1.48k|  s->s = ((unsigned char *)s) + sizeof(coap_str_bin_union_t);
   44|  1.48k|  s->s[size] = '\000';
   45|  1.48k|  s->length = size;
   46|  1.48k|  return s;
   47|  1.48k|}
coap_delete_string:
   50|  3.17k|coap_delete_string(coap_string_t *s) {
   51|  3.17k|  coap_free_type(COAP_STRING, s);
   52|  3.17k|}
coap_delete_binary:
  114|  3.06k|coap_delete_binary(coap_binary_t *s) {
  115|  3.06k|  coap_free_type(COAP_STRING, s);
  116|  3.06k|}

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

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

coap_split_proxy_uri:
  356|    532|coap_split_proxy_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri) {
  357|    532|  return coap_split_uri_sub(str_var, len, uri, COAP_URI_CHECK_PROXY);
  358|    532|}
coap_check_dots:
  675|  4.56M|coap_check_dots(const uint8_t *s, size_t len) {
  676|  4.56M|  uint8_t p;
  677|       |
  678|  4.56M|  if (!len)
  ------------------
  |  Branch (678:7): [True: 4.42M, False: 141k]
  ------------------
  679|  4.42M|    return 0;
  680|       |
  681|   141k|  p = *s;
  682|       |
  683|       |  /* Check 'first' char */
  684|   141k|  if (p == '%' && len >=3) {
  ------------------
  |  Branch (684:7): [True: 2.03k, False: 139k]
  |  Branch (684:19): [True: 1.83k, False: 202]
  ------------------
  685|  1.83k|    if (s[1] == '2' && (s[2] == 'E' || s[2] == 'e')) {
  ------------------
  |  Branch (685:9): [True: 672, False: 1.15k]
  |  Branch (685:25): [True: 207, False: 465]
  |  Branch (685:40): [True: 243, False: 222]
  ------------------
  686|    450|      s += 2;
  687|    450|      len -= 2;
  688|    450|    }
  689|  1.83k|    p = '.';
  690|  1.83k|  }
  691|   141k|  if (p != '.')
  ------------------
  |  Branch (691:7): [True: 137k, False: 4.35k]
  ------------------
  692|   137k|    return 0;
  693|  4.35k|  if (len == 1)
  ------------------
  |  Branch (693:7): [True: 1.29k, False: 3.06k]
  ------------------
  694|  1.29k|    return 1;
  695|       |
  696|       |  /* Check 'second' char, first is '.' */
  697|  3.06k|  s++;
  698|  3.06k|  len--;
  699|  3.06k|  assert(len);
  ------------------
  |  Branch (699:3): [True: 3.06k, False: 0]
  ------------------
  700|  3.06k|  p = *s;
  701|  3.06k|  if (p == '%' && len >=3) {
  ------------------
  |  Branch (701:7): [True: 1.21k, False: 1.84k]
  |  Branch (701:19): [True: 932, False: 286]
  ------------------
  702|    932|    if (s[1] == '2' && (s[2] == 'E' || s[2] == 'e')) {
  ------------------
  |  Branch (702:9): [True: 651, False: 281]
  |  Branch (702:25): [True: 204, False: 447]
  |  Branch (702:40): [True: 213, False: 234]
  ------------------
  703|    417|      len -= 2;
  704|    417|    }
  705|    932|    p = '.';
  706|    932|  }
  707|  3.06k|  if (p != '.')
  ------------------
  |  Branch (707:7): [True: 1.06k, False: 2.00k]
  ------------------
  708|  1.06k|    return 0;
  709|  2.00k|  if (len == 1)
  ------------------
  |  Branch (709:7): [True: 1.37k, False: 626]
  ------------------
  710|  1.37k|    return 2;
  711|       |
  712|    626|  return 0;
  713|  2.00k|}
coap_get_query:
 1108|  1.58k|coap_get_query(const coap_pdu_t *request) {
 1109|  1.58k|  coap_opt_iterator_t opt_iter;
 1110|  1.58k|  coap_opt_filter_t f;
 1111|  1.58k|  coap_opt_t *q;
 1112|  1.58k|  coap_string_t *query = NULL;
 1113|  1.58k|  size_t length = 0;
 1114|  1.58k|  int have_query = 0;
 1115|  1.58k|  static const uint8_t hex[] = "0123456789ABCDEF";
 1116|       |
 1117|  1.58k|  coap_option_filter_clear(&f);
 1118|  1.58k|  coap_option_filter_set(&f, COAP_OPTION_URI_QUERY);
 1119|  1.58k|  coap_option_iterator_init(request, &opt_iter, &f);
 1120|  97.9k|  while ((q = coap_option_next(&opt_iter))) {
  ------------------
  |  Branch (1120:10): [True: 96.3k, False: 1.58k]
  ------------------
 1121|  96.3k|    uint16_t seg_len = coap_opt_length(q), i;
 1122|  96.3k|    const uint8_t *seg= coap_opt_value(q);
 1123|  96.3k|    have_query = 1;
 1124|   970k|    for (i = 0; i < seg_len; i++) {
  ------------------
  |  Branch (1124:17): [True: 874k, False: 96.3k]
  ------------------
 1125|   874k|      if (is_unescaped_in_query(seg[i]))
  ------------------
  |  Branch (1125:11): [True: 12.7k, False: 861k]
  ------------------
 1126|  12.7k|        length += 1;
 1127|   861k|      else
 1128|   861k|        length += 3;
 1129|   874k|    }
 1130|  96.3k|    length += 1;
 1131|  96.3k|  }
 1132|  1.58k|  if (length > 0)
  ------------------
  |  Branch (1132:7): [True: 312, False: 1.27k]
  ------------------
 1133|    312|    length -= 1;
 1134|       |  /* Allocate and return a string whenever at least one Uri-Query option is
 1135|       |     present, even when every option is empty and the encoded length is zero.
 1136|       |     A single empty Uri-Query then yields an empty string rather than NULL,
 1137|       |     which is reserved for "no Uri-Query option at all". */
 1138|  1.58k|  if (have_query) {
  ------------------
  |  Branch (1138:7): [True: 312, False: 1.27k]
  ------------------
 1139|    312|    query = coap_new_string(length);
 1140|    312|    if (query) {
  ------------------
  |  Branch (1140:9): [True: 312, False: 0]
  ------------------
 1141|    312|      unsigned char *s = query->s;
 1142|    312|      int first = 1;
 1143|    312|      query->length = length;
 1144|    312|      coap_option_iterator_init(request, &opt_iter, &f);
 1145|  96.6k|      while ((q = coap_option_next(&opt_iter))) {
  ------------------
  |  Branch (1145:14): [True: 96.3k, False: 312]
  ------------------
 1146|       |        /* Write the '&' separator before every Uri-Query option except the
 1147|       |           first. An empty Uri-Query option is a distinct zero-length segment
 1148|       |           (just as "&&" is not "&"), so the separators around it must still
 1149|       |           be emitted. Keying this off the option index rather than off
 1150|       |           whether any byte has been written yet is what keeps leading empty
 1151|       |           options from being dropped, and keeps the buffer fully written so
 1152|       |           no uninitialised tail is exposed to callers. */
 1153|  96.3k|        if (!first)
  ------------------
  |  Branch (1153:13): [True: 96.0k, False: 312]
  ------------------
 1154|  96.0k|          *s++ = '&';
 1155|  96.3k|        first = 0;
 1156|  96.3k|        uint16_t seg_len = coap_opt_length(q), i;
 1157|  96.3k|        const uint8_t *seg= coap_opt_value(q);
 1158|   970k|        for (i = 0; i < seg_len; i++) {
  ------------------
  |  Branch (1158:21): [True: 874k, False: 96.3k]
  ------------------
 1159|   874k|          if (is_unescaped_in_query(seg[i])) {
  ------------------
  |  Branch (1159:15): [True: 12.7k, False: 861k]
  ------------------
 1160|  12.7k|            *s++ = seg[i];
 1161|   861k|          } else {
 1162|   861k|            *s++ = '%';
 1163|   861k|            *s++ = hex[seg[i]>>4];
 1164|   861k|            *s++ = hex[seg[i]&0x0F];
 1165|   861k|          }
 1166|   874k|        }
 1167|  96.3k|      }
 1168|    312|    }
 1169|    312|  }
 1170|  1.58k|  return query;
 1171|  1.58k|}
coap_map_abbrev_uri_path:
 1174|     16|coap_map_abbrev_uri_path(coap_upa_chain_t *chain, uint32_t value) {
 1175|     16|  while (chain) {
  ------------------
  |  Branch (1175:10): [True: 0, False: 16]
  ------------------
 1176|      0|    coap_upa_chain_t *next = chain->next;
 1177|       |
 1178|      0|    if (chain->upa_value == value) {
  ------------------
  |  Branch (1178:9): [True: 0, False: 0]
  ------------------
 1179|      0|      return chain->upa_path;
 1180|      0|    }
 1181|      0|    chain = next;
 1182|      0|  }
 1183|     16|  return NULL;
 1184|     16|}
coap_get_uri_path:
 1202|  1.58k|coap_get_uri_path(const coap_pdu_t *request) {
 1203|  1.58k|  coap_opt_iterator_t opt_iter;
 1204|  1.58k|  coap_opt_filter_t f;
 1205|  1.58k|  coap_opt_t *q;
 1206|  1.58k|  coap_string_t *uri_path = NULL;
 1207|  1.58k|  size_t length = 0;
 1208|  1.58k|  static const uint8_t hex[] = "0123456789ABCDEF";
 1209|       |
 1210|  1.58k|  q = coap_check_option(request, COAP_OPTION_URI_PATH_ABB, &opt_iter);
 1211|  1.58k|  if (q) {
  ------------------
  |  Branch (1211:7): [True: 27, False: 1.55k]
  ------------------
 1212|     27|    uint32_t value;
 1213|     27|    const char *exp;
 1214|     27|    if (coap_check_option(request, COAP_OPTION_PROXY_URI, &opt_iter) ||
  ------------------
  |  Branch (1214:9): [True: 5, False: 22]
  ------------------
 1215|     22|        coap_check_option(request, COAP_OPTION_URI_PATH, &opt_iter)) {
  ------------------
  |  Branch (1215:9): [True: 6, False: 16]
  ------------------
 1216|     11|      return NULL;
 1217|     11|    }
 1218|     16|    value = coap_decode_var_bytes(coap_opt_value(q), coap_opt_length(q));
 1219|     16|    exp = coap_map_abbrev_uri_path(coap_upa_server_mapping_chain, value);
 1220|     16|    if (exp) {
  ------------------
  |  Branch (1220:9): [True: 0, False: 16]
  ------------------
 1221|      0|      uri_path = coap_new_string(strlen(exp));
 1222|      0|      if (uri_path) {
  ------------------
  |  Branch (1222:11): [True: 0, False: 0]
  ------------------
 1223|      0|        memcpy(uri_path->s, exp, strlen(exp));
 1224|      0|      }
 1225|      0|      return uri_path;
 1226|      0|    }
 1227|     16|    return NULL;
 1228|     16|  }
 1229|  1.55k|  q = coap_check_option(request, COAP_OPTION_PROXY_URI, &opt_iter);
 1230|  1.55k|  if (q) {
  ------------------
  |  Branch (1230:7): [True: 532, False: 1.02k]
  ------------------
 1231|    532|    coap_uri_t uri;
 1232|       |
 1233|    532|    if (coap_split_proxy_uri(coap_opt_value(q),
  ------------------
  |  Branch (1233:9): [True: 385, False: 147]
  ------------------
 1234|    532|                             coap_opt_length(q), &uri) < 0) {
 1235|    385|      return NULL;
 1236|    385|    }
 1237|    147|    uri_path = coap_new_string(uri.path.length);
 1238|    147|    if (uri_path && uri.path.length) {
  ------------------
  |  Branch (1238:9): [True: 147, False: 0]
  |  Branch (1238:21): [True: 35, False: 112]
  ------------------
 1239|     35|      memcpy(uri_path->s, uri.path.s, uri.path.length);
 1240|     35|    }
 1241|    147|    return uri_path;
 1242|    532|  }
 1243|       |
 1244|  1.02k|  coap_option_filter_clear(&f);
 1245|  1.02k|  coap_option_filter_set(&f, COAP_OPTION_URI_PATH);
 1246|  1.02k|  coap_option_iterator_init(request, &opt_iter, &f);
 1247|  4.54M|  while ((q = coap_option_next(&opt_iter))) {
  ------------------
  |  Branch (1247:10): [True: 4.54M, False: 1.02k]
  ------------------
 1248|  4.54M|    uint16_t seg_len = coap_opt_length(q), i;
 1249|  4.54M|    const uint8_t *seg = coap_opt_value(q);
 1250|  5.71M|    for (i = 0; i < seg_len; i++) {
  ------------------
  |  Branch (1250:17): [True: 1.17M, False: 4.54M]
  ------------------
 1251|  1.17M|      if (is_unescaped_in_path(seg[i]))
  ------------------
  |  Branch (1251:11): [True: 19.0k, False: 1.15M]
  ------------------
 1252|  19.0k|        length += 1;
 1253|  1.15M|      else
 1254|  1.15M|        length += 3;
 1255|  1.17M|    }
 1256|       |    /* bump for the leading "/" */
 1257|  4.54M|    length += 1;
 1258|  4.54M|  }
 1259|       |  /* The first entry does not have a leading "/" */
 1260|  1.02k|  if (length > 0)
  ------------------
  |  Branch (1260:7): [True: 422, False: 605]
  ------------------
 1261|    422|    length -= 1;
 1262|       |
 1263|       |  /* if 0, either no URI_PATH Option, or the first one was empty */
 1264|  1.02k|  uri_path = coap_new_string(length);
 1265|  1.02k|  if (uri_path) {
  ------------------
  |  Branch (1265:7): [True: 1.02k, False: 0]
  ------------------
 1266|  1.02k|    uri_path->length = length;
 1267|  1.02k|    unsigned char *s = uri_path->s;
 1268|  1.02k|    int n = 0;
 1269|  1.02k|    coap_option_iterator_init(request, &opt_iter, &f);
 1270|  4.54M|    while ((q = coap_option_next(&opt_iter))) {
  ------------------
  |  Branch (1270:12): [True: 4.54M, False: 1.02k]
  ------------------
 1271|  4.54M|      if (n++) {
  ------------------
  |  Branch (1271:11): [True: 4.54M, False: 422]
  ------------------
 1272|  4.54M|        *s++ = '/';
 1273|  4.54M|      }
 1274|  4.54M|      uint16_t seg_len = coap_opt_length(q), i;
 1275|  4.54M|      const uint8_t *seg= coap_opt_value(q);
 1276|  5.71M|      for (i = 0; i < seg_len; i++) {
  ------------------
  |  Branch (1276:19): [True: 1.17M, False: 4.54M]
  ------------------
 1277|  1.17M|        if (is_unescaped_in_path(seg[i])) {
  ------------------
  |  Branch (1277:13): [True: 19.0k, False: 1.15M]
  ------------------
 1278|  19.0k|          *s++ = seg[i];
 1279|  1.15M|        } else {
 1280|  1.15M|          *s++ = '%';
 1281|  1.15M|          *s++ = hex[seg[i]>>4];
 1282|  1.15M|          *s++ = hex[seg[i]&0x0F];
 1283|  1.15M|        }
 1284|  1.17M|      }
 1285|  4.54M|    }
 1286|  1.02k|  }
 1287|  1.02k|  return uri_path;
 1288|  1.55k|}
coap_delete_upa_chain:
 1291|  6.12k|coap_delete_upa_chain(coap_upa_chain_t *chain) {
 1292|  6.12k|  while (chain) {
  ------------------
  |  Branch (1292:10): [True: 0, False: 6.12k]
  ------------------
 1293|      0|    coap_upa_chain_t *next = chain->next;
 1294|       |
 1295|      0|    coap_free_type(COAP_STRING, chain);
 1296|      0|    chain = next;
 1297|      0|  }
 1298|  6.12k|}
coap_uri.c:coap_split_uri_sub:
   84|    532|                   coap_uri_check_t check_proxy) {
   85|    532|  const uint8_t *p, *q;
   86|    532|  int res = 0;
   87|    532|  size_t i;
   88|    532|  int is_unix_domain = 0;
   89|    532|  int is_llc = 0;
   90|       |
   91|    532|  if (!str_var || !uri || len == 0)
  ------------------
  |  Branch (91:7): [True: 0, False: 532]
  |  Branch (91:19): [True: 0, False: 532]
  |  Branch (91:27): [True: 0, False: 532]
  ------------------
   92|      0|    return -1;
   93|       |
   94|    532|  memset(uri, 0, sizeof(coap_uri_t));
   95|    532|  uri->port = COAP_DEFAULT_PORT;
  ------------------
  |  |   39|    532|#define COAP_DEFAULT_PORT      5683 /* CoAP default UDP/TCP port */
  ------------------
   96|       |
   97|       |  /* search for scheme */
   98|    532|  p = str_var;
   99|    532|  if (*p == '/') {
  ------------------
  |  Branch (99:7): [True: 1, False: 531]
  ------------------
  100|       |    /* no scheme, host or port */
  101|      1|    if (check_proxy == COAP_URI_CHECK_PROXY) {
  ------------------
  |  Branch (101:9): [True: 1, False: 0]
  ------------------
  102|       |      /* Must have ongoing host if proxy definition */
  103|      1|      return -1;
  104|      1|    }
  105|      0|    q = p;
  106|      0|    goto path;
  107|      1|  }
  108|       |
  109|       |  /* find scheme terminating :// */
  110|  9.16k|  while (len >= 3 && !(p[0] == ':' && p[1] == '/' && p[2] == '/')) {
  ------------------
  |  Branch (110:10): [True: 9.11k, False: 46]
  |  Branch (110:24): [True: 1.01k, False: 8.09k]
  |  Branch (110:39): [True: 695, False: 322]
  |  Branch (110:54): [True: 485, False: 210]
  ------------------
  111|  8.63k|    ++p;
  112|  8.63k|    --len;
  113|  8.63k|  }
  114|    531|  if (len < 3) {
  ------------------
  |  Branch (114:7): [True: 46, False: 485]
  ------------------
  115|       |    /* scheme not defined with a :// terminator */
  116|     46|    res = -2;
  117|     46|    goto error;
  118|     46|  }
  119|  1.78k|  for (i = 0; i < COAP_URI_SCHEME_LAST; i++) {
  ------------------
  |  Branch (119:15): [True: 1.68k, False: 100]
  ------------------
  120|  1.68k|    if ((p - str_var) == (int)strlen(coap_uri_scheme[i].name) &&
  ------------------
  |  Branch (120:9): [True: 639, False: 1.05k]
  ------------------
  121|    639|        strncasecmp((const char *)str_var, coap_uri_scheme[i].name, p - str_var) == 0) {
  ------------------
  |  Branch (121:9): [True: 385, False: 254]
  ------------------
  122|    385|      if (check_proxy != COAP_URI_CHECK_PROXY && coap_uri_scheme[i].proxy_only) {
  ------------------
  |  Branch (122:11): [True: 0, False: 385]
  |  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|    385|      uri->scheme = coap_uri_scheme[i].scheme;
  128|    385|      uri->port = coap_uri_scheme[i].port;
  129|    385|      break;
  130|    385|    }
  131|  1.68k|  }
  132|    485|  if (i == COAP_URI_SCHEME_LAST) {
  ------------------
  |  Branch (132:7): [True: 100, False: 385]
  ------------------
  133|       |    /* scheme unknown */
  134|    100|    coap_log_err("%.*s URI scheme unknown\n", (int)(p - str_var), str_var);
  ------------------
  |  |  102|    100|#define coap_log_err(...) coap_log(COAP_LOG_ERR, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|    100|#define coap_log(level, ...) do { \
  |  |  |  |  291|    100|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 100]
  |  |  |  |  ------------------
  |  |  |  |  292|    100|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|    100|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 100]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  135|    100|    res = -1;
  136|    100|    goto error;
  137|    100|  }
  138|    385|  switch (uri->scheme) {
  139|    259|  case COAP_URI_SCHEME_COAP:
  ------------------
  |  Branch (139:3): [True: 259, False: 126]
  ------------------
  140|    259|    break;
  141|      2|  case COAP_URI_SCHEME_COAPS:
  ------------------
  |  Branch (141:3): [True: 2, False: 383]
  ------------------
  142|      2|    if (!coap_dtls_is_supported()) {
  ------------------
  |  Branch (142:9): [True: 0, False: 2]
  ------------------
  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|      2|    break;
  147|      2|  case COAP_URI_SCHEME_COAP_TCP:
  ------------------
  |  Branch (147:3): [True: 1, False: 384]
  ------------------
  148|      1|    if (!coap_tcp_is_supported()) {
  ------------------
  |  Branch (148:9): [True: 0, False: 1]
  ------------------
  149|      0|      coap_log_err("coap+tcp URI scheme not supported in this version of libcoap\n");
  ------------------
  |  |  102|      0|#define coap_log_err(...) coap_log(COAP_LOG_ERR, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  150|      0|      return -1;
  151|      0|    }
  152|      1|    break;
  153|      1|  case COAP_URI_SCHEME_COAPS_TCP:
  ------------------
  |  Branch (153:3): [True: 1, False: 384]
  ------------------
  154|      1|    if (!coap_tls_is_supported()) {
  ------------------
  |  Branch (154:9): [True: 0, False: 1]
  ------------------
  155|      0|      coap_log_err("coaps+tcp URI scheme not supported in this version of libcoap\n");
  ------------------
  |  |  102|      0|#define coap_log_err(...) coap_log(COAP_LOG_ERR, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  156|      0|      return -1;
  157|      0|    }
  158|      1|    break;
  159|      1|  case COAP_URI_SCHEME_COAP_WS:
  ------------------
  |  Branch (159:3): [True: 1, False: 384]
  ------------------
  160|      1|    if (!coap_ws_is_supported()) {
  ------------------
  |  Branch (160:9): [True: 0, False: 1]
  ------------------
  161|      0|      coap_log_err("coap+ws URI scheme not supported in this version of libcoap\n");
  ------------------
  |  |  102|      0|#define coap_log_err(...) coap_log(COAP_LOG_ERR, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  162|      0|      return -1;
  163|      0|    }
  164|      1|    break;
  165|      1|  case COAP_URI_SCHEME_COAPS_WS:
  ------------------
  |  Branch (165:3): [True: 1, False: 384]
  ------------------
  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|    116|  case COAP_URI_SCHEME_HTTP:
  ------------------
  |  Branch (171:3): [True: 116, False: 269]
  ------------------
  172|    120|  case COAP_URI_SCHEME_HTTPS:
  ------------------
  |  Branch (172:3): [True: 4, False: 381]
  ------------------
  173|       |    /* Not proxy, caught above.  For proxy, assume app is doing CoAP <> HTTP mapping. */
  174|    120|    break;
  175|      0|  case COAP_URI_SCHEME_LAST:
  ------------------
  |  Branch (175:3): [True: 0, False: 385]
  ------------------
  176|      0|  default:
  ------------------
  |  Branch (176:3): [True: 0, False: 385]
  ------------------
  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|    385|  }
  180|       |  /* skip :// */
  181|    385|  p += 3;
  182|    385|  len -= 3;
  183|       |
  184|       |  /* p points to beginning of Uri-Host */
  185|    385|  q = p;
  186|       |
  187|    385|  if (len && *p == '[') {
  ------------------
  |  Branch (187:7): [True: 377, False: 8]
  |  Branch (187:14): [True: 46, False: 331]
  ------------------
  188|       |    /* IPv6 address reference or Unix domain */
  189|     46|    ++p;
  190|     46|    ++q;
  191|     46|    --len;
  192|       |
  193|  6.17k|    while (len && *q != ']') {
  ------------------
  |  Branch (193:12): [True: 6.16k, False: 15]
  |  Branch (193:19): [True: 6.13k, False: 31]
  ------------------
  194|  6.13k|      ++q;
  195|  6.13k|      --len;
  196|  6.13k|    }
  197|       |
  198|     46|    if (!len || *q != ']' || p == q) {
  ------------------
  |  Branch (198:9): [True: 15, False: 31]
  |  Branch (198:17): [True: 0, False: 31]
  |  Branch (198:30): [True: 1, False: 30]
  ------------------
  199|     16|      res = -3;
  200|     16|      goto error;
  201|     16|    }
  202|       |
  203|     30|    if ((int)(q - p) > 255) {
  ------------------
  |  Branch (203:9): [True: 6, False: 24]
  ------------------
  204|      6|      coap_log_warn("Host name length too long (%d > 255)\n", (int)(q - p));
  ------------------
  |  |  108|      6|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      6|#define coap_log(level, ...) do { \
  |  |  |  |  291|      6|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  292|      6|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      6|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 6]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  205|      6|      res = -6;
  206|      6|      goto error;
  207|      6|    }
  208|       |
  209|     24|    COAP_SET_STR(&uri->host, q - p, p);
  ------------------
  |  |   52|     24|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  210|     24|    ++q;
  211|     24|    --len;
  212|     24|#if COAP_AF_LLC_SUPPORT
  213|    339|  } else if ((len >= LLC_HOST_LEN) && strncmp((const char *)p, "llc[", 4) == 0) {
  ------------------
  |  |  178|    339|#define LLC_HOST_LEN (4 + HW_ADDRSTRLEN + 4)
  |  |  ------------------
  |  |  |  |  176|    339|#define HW_ADDRSTRLEN 17
  |  |  ------------------
  ------------------
  |  Branch (213:14): [True: 215, False: 124]
  |  Branch (213:39): [True: 126, False: 89]
  ------------------
  214|    126|    unsigned long sap = 0;
  215|       |
  216|    126|    is_llc = 1;
  217|       |
  218|  6.07k|    while (len && *q != ']') {
  ------------------
  |  Branch (218:12): [True: 6.06k, False: 11]
  |  Branch (218:19): [True: 5.95k, False: 115]
  ------------------
  219|  5.95k|      ++q;
  220|  5.95k|      --len;
  221|  5.95k|    }
  222|       |
  223|    126|    if (!len || *q != ']' || p == q) {
  ------------------
  |  Branch (223:9): [True: 11, False: 115]
  |  Branch (223:17): [True: 0, False: 115]
  |  Branch (223:30): [True: 0, False: 115]
  ------------------
  224|     11|      res = -7;
  225|     11|      goto error;
  226|     11|    }
  227|       |
  228|    115|    ++q;
  229|    115|    --len;
  230|       |
  231|    115|    if (!len || *q != ':') {
  ------------------
  |  Branch (231:9): [True: 1, False: 114]
  |  Branch (231:17): [True: 4, False: 110]
  ------------------
  232|      5|      coap_log_warn("LLC SAP missing in URI\n");
  ------------------
  |  |  108|      5|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  233|      5|      res = -7;
  234|      5|      goto error;
  235|      5|    }
  236|       |
  237|    110|    ++q;
  238|    110|    --len;
  239|       |
  240|  2.14k|    while (len && isxdigit(*q)) {
  ------------------
  |  Branch (240:12): [True: 2.11k, False: 31]
  |  Branch (240:19): [True: 2.03k, False: 79]
  ------------------
  241|  2.03k|      if (*q >= 'a' && *q <= 'f')
  ------------------
  |  Branch (241:11): [True: 927, False: 1.11k]
  |  Branch (241:24): [True: 927, False: 0]
  ------------------
  242|    927|        sap = sap * 16 + (*q - 'a' + 10);
  243|  1.11k|      else if (*q >= 'A' && *q <= 'F')
  ------------------
  |  Branch (243:16): [True: 716, False: 396]
  |  Branch (243:29): [True: 716, False: 0]
  ------------------
  244|    716|        sap = sap * 16 + (*q - 'A' + 10);
  245|       |
  246|  2.03k|      ++q;
  247|  2.03k|      --len;
  248|  2.03k|    }
  249|       |
  250|    110|    if (sap > UINT8_MAX) {
  ------------------
  |  Branch (250:9): [True: 90, False: 20]
  ------------------
  251|     90|      coap_log_warn("LLC SAP invalid (%lu > 255)\n", sap);
  ------------------
  |  |  108|     90|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     90|#define coap_log(level, ...) do { \
  |  |  |  |  291|     90|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 90]
  |  |  |  |  ------------------
  |  |  |  |  292|     90|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     90|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 90]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  252|     90|      res = -7;
  253|     90|      goto error;
  254|     90|    }
  255|       |
  256|     20|    COAP_SET_STR(&uri->host, q - p, p);
  ------------------
  |  |   52|     20|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  257|     20|#endif /* COAP_AF_LLC_SUPPORT */
  258|    213|  } else {
  259|       |    /* IPv4 address, FQDN or Unix domain socket */
  260|    213|    if (len >= 3 && p[0] == '%' && p[1] == '2' &&
  ------------------
  |  Branch (260:9): [True: 183, False: 30]
  |  Branch (260:21): [True: 29, False: 154]
  |  Branch (260:36): [True: 16, False: 13]
  ------------------
  261|     16|        (p[2] == 'F' || p[2] == 'f')) {
  ------------------
  |  Branch (261:10): [True: 1, False: 15]
  |  Branch (261:25): [True: 2, False: 13]
  ------------------
  262|       |      /* Unix domain definition */
  263|      3|      uri->port = 0;
  264|      3|      is_unix_domain = 1;
  265|      3|    }
  266|  8.27k|    while (len && *q != ':' && *q != '/' && *q != '?') {
  ------------------
  |  Branch (266:12): [True: 8.20k, False: 76]
  |  Branch (266:19): [True: 8.10k, False: 99]
  |  Branch (266:32): [True: 8.07k, False: 30]
  |  Branch (266:45): [True: 8.06k, False: 8]
  ------------------
  267|  8.06k|      ++q;
  268|  8.06k|      --len;
  269|  8.06k|    }
  270|       |
  271|    213|    if (p == q) {
  ------------------
  |  Branch (271:9): [True: 12, False: 201]
  ------------------
  272|     12|      res = -3;
  273|     12|      goto error;
  274|     12|    }
  275|       |
  276|    201|    if ((int)(q - p) > 255) {
  ------------------
  |  Branch (276:9): [True: 7, False: 194]
  ------------------
  277|      7|      coap_log_warn("Host name length too long (%d > 255)\n", (int)(q - p));
  ------------------
  |  |  108|      7|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      7|#define coap_log(level, ...) do { \
  |  |  |  |  291|      7|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  292|      7|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      7|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 7]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  278|      7|      res = -6;
  279|      7|      goto error;
  280|      7|    }
  281|       |
  282|    194|    COAP_SET_STR(&uri->host, q - p, p);
  ------------------
  |  |   52|    194|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  283|    194|  }
  284|       |
  285|       |  /* check for Uri-Port (invalid for Unix) */
  286|    238|  if (len && *q == ':') {
  ------------------
  |  Branch (286:7): [True: 168, False: 70]
  |  Branch (286:14): [True: 100, False: 68]
  ------------------
  287|    100|    if (is_unix_domain || is_llc) {
  ------------------
  |  Branch (287:9): [True: 1, False: 99]
  |  Branch (287:27): [True: 2, False: 97]
  ------------------
  288|      3|      res = -5;
  289|      3|      goto error;
  290|      3|    }
  291|     97|    p = ++q;
  292|     97|    --len;
  293|       |
  294|    817|    while (len && isdigit(*q)) {
  ------------------
  |  Branch (294:12): [True: 768, False: 49]
  |  Branch (294:19): [True: 720, False: 48]
  ------------------
  295|    720|      ++q;
  296|    720|      --len;
  297|    720|    }
  298|       |
  299|     97|    if (p < q) {                /* explicit port number given */
  ------------------
  |  Branch (299:9): [True: 60, False: 37]
  ------------------
  300|     60|      long uri_port = 0;
  301|       |
  302|    731|      while ((p < q) && (uri_port <= UINT16_MAX))
  ------------------
  |  Branch (302:14): [True: 677, False: 54]
  |  Branch (302:25): [True: 671, False: 6]
  ------------------
  303|    671|        uri_port = uri_port * 10 + (*p++ - '0');
  304|       |
  305|       |      /* check if port number is in allowed range */
  306|     60|      if (uri_port > UINT16_MAX) {
  ------------------
  |  Branch (306:11): [True: 24, False: 36]
  ------------------
  307|     24|        coap_log_warn("Port number too big (%ld > 65535)\n", uri_port);
  ------------------
  |  |  108|     24|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     24|#define coap_log(level, ...) do { \
  |  |  |  |  291|     24|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 24]
  |  |  |  |  ------------------
  |  |  |  |  292|     24|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     24|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 24]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  308|     24|        res = -4;
  309|     24|        goto error;
  310|     24|      }
  311|       |
  312|     36|      uri->port = (uint16_t)uri_port;
  313|     36|    }
  314|     97|  }
  315|       |
  316|    211|path:                 /* q points just past the authority, or to a relative URI's leading '/' */
  317|       |
  318|    211|  if (!len)
  ------------------
  |  Branch (318:7): [True: 101, False: 110]
  ------------------
  319|    101|    goto end;
  320|       |
  321|    110|  if (*q == '/') {
  ------------------
  |  Branch (321:7): [True: 39, False: 71]
  ------------------
  322|     39|    p = ++q;
  323|     39|    --len;
  324|       |
  325|  6.82k|    while (len && *q != '?') {
  ------------------
  |  Branch (325:12): [True: 6.78k, False: 36]
  |  Branch (325:19): [True: 6.78k, False: 3]
  ------------------
  326|  6.78k|      ++q;
  327|  6.78k|      --len;
  328|  6.78k|    }
  329|       |
  330|     39|    if (p < q) {
  ------------------
  |  Branch (330:9): [True: 35, False: 4]
  ------------------
  331|     35|      COAP_SET_STR(&uri->path, q - p, p);
  ------------------
  |  |   52|     35|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  332|     35|    }
  333|     39|  }
  334|       |
  335|       |  /* Uri_Query */
  336|    110|  if (len && *q == '?') {
  ------------------
  |  Branch (336:7): [True: 74, False: 36]
  |  Branch (336:14): [True: 10, False: 64]
  ------------------
  337|     10|    ++q;
  338|     10|    --len;
  339|     10|    COAP_SET_STR(&uri->query, len, q);
  ------------------
  |  |   52|     10|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  340|     10|    len = 0;
  341|     10|  }
  342|       |
  343|    211|end:
  344|    211|  return len ? -1 : 0;
  ------------------
  |  Branch (344:10): [True: 64, False: 147]
  ------------------
  345|       |
  346|    320|error:
  347|    320|  return res;
  348|    110|}
coap_uri.c:is_unescaped_in_query:
 1103|  1.74M|is_unescaped_in_query(const uint8_t c) {
 1104|  1.74M|  return c != '&' && (is_unescaped_in_path(c) || c == '/' || c == '?');
  ------------------
  |  Branch (1104:10): [True: 1.74M, False: 410]
  |  Branch (1104:23): [True: 24.7k, False: 1.72M]
  |  Branch (1104:50): [True: 444, False: 1.72M]
  |  Branch (1104:62): [True: 380, False: 1.72M]
  ------------------
 1105|  1.74M|}
coap_uri.c:is_unescaped_in_path:
 1094|  4.08M|is_unescaped_in_path(const uint8_t c) {
 1095|  4.08M|  return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') ||
  ------------------
  |  Branch (1095:11): [True: 67.6k, False: 4.02M]
  |  Branch (1095:23): [True: 8.99k, False: 58.6k]
  |  Branch (1095:37): [True: 57.6k, False: 4.02M]
  |  Branch (1095:49): [True: 4.29k, False: 53.3k]
  ------------------
 1096|  4.07M|         (c >= '0' && c <= '9') || c == '-' || c == '.' || c == '_' ||
  ------------------
  |  Branch (1096:11): [True: 71.0k, False: 4.00M]
  |  Branch (1096:23): [True: 4.77k, False: 66.3k]
  |  Branch (1096:36): [True: 1.08k, False: 4.07M]
  |  Branch (1096:48): [True: 5.90k, False: 4.06M]
  |  Branch (1096:60): [True: 810, False: 4.06M]
  ------------------
 1097|  4.06M|         c == '~' || c == '!' || c == '$' || c == '\'' || c == '(' ||
  ------------------
  |  Branch (1097:10): [True: 2.96k, False: 4.06M]
  |  Branch (1097:22): [True: 4.53k, False: 4.05M]
  |  Branch (1097:34): [True: 2.37k, False: 4.05M]
  |  Branch (1097:46): [True: 1.08k, False: 4.05M]
  |  Branch (1097:59): [True: 1.35k, False: 4.05M]
  ------------------
 1098|  4.05M|         c == ')' || c == '*' || c == '+' || c == ',' || c == ';' ||
  ------------------
  |  Branch (1098:10): [True: 1.56k, False: 4.04M]
  |  Branch (1098:22): [True: 6.19k, False: 4.04M]
  |  Branch (1098:34): [True: 4.02k, False: 4.03M]
  |  Branch (1098:46): [True: 982, False: 4.03M]
  |  Branch (1098:58): [True: 3.76k, False: 4.03M]
  ------------------
 1099|  4.03M|         c=='=' || c==':' || c=='@' || c == '&';
  ------------------
  |  Branch (1099:10): [True: 1.00k, False: 4.03M]
  |  Branch (1099:20): [True: 4.33k, False: 4.02M]
  |  Branch (1099:30): [True: 2.47k, False: 4.02M]
  |  Branch (1099:40): [True: 294, False: 4.02M]
  ------------------
 1100|  4.08M|}

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

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

