diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index 58fc65bb6..ed8217054 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -615,7 +615,7 @@ INLINE void ng_osrtp_option(sdp_ng_flags *out, str *s, helper_arg dummy) { static void call_ng_flags_str_pair_ht(sdp_ng_flags *out, str *s, helper_arg arg) { str *s_copy = str_dup_escape(s); str token; - if (str_token(&token, s_copy, '>')) { + if (!str_token(&token, s_copy, '>')) { ilog(LOG_WARN, "SDP manipulations: Ignoring invalid token '" STR_FORMAT "'", STR_FMT(s)); free(s_copy); return; @@ -799,7 +799,7 @@ static void call_ng_flags_list(sdp_ng_flags *out, bencode_item_t *list, if (list->type != BENCODE_LIST) { if (bencode_get_str(list, &s)) { str token; - while (str_token_sep(&token, &s, ',') == 0) + while (str_token_sep(&token, &s, ',')) str_callback(out, &token, arg); } else @@ -923,7 +923,7 @@ static void call_ng_flags_str_q_multi(sdp_ng_flags *out, str *s, helper_arg arg) if (s_copy->len == 0) ilog(LOG_DEBUG, "Hm, nothing to parse."); - while (str_token_sep(&token, s_copy, ';') == 0) + while (str_token_sep(&token, s_copy, ';')) { str * ret = str_dup(&token); t_queue_push_tail(q, ret); @@ -968,7 +968,7 @@ static const struct sdp_attr_helper sdp_attr_helper_substitute = { static void call_ng_flags_sdp_attr_helper(sdp_ng_flags *out, str *s, helper_arg arg) { // get media type str token; - if (str_token(&token, s, '-')) + if (!str_token(&token, s, '-')) return; struct sdp_manipulations *sm = sdp_manipulations_get_by_name(out, &token); if (!sm) { @@ -1428,7 +1428,7 @@ static void call_ng_flags_freqs(sdp_ng_flags *out, bencode_item_t *value) { case BENCODE_STRING:; str s, token; bencode_get_str(value, &s); - while (str_token_sep(&token, &s, ',') == 0) { + while (str_token_sep(&token, &s, ',')) { val = str_to_i(&token, 0); g_array_append_val(out->frequencies, val); } diff --git a/daemon/cli.c b/daemon/cli.c index 90bc3f20e..d9ec71fee 100644 --- a/daemon/cli.c +++ b/daemon/cli.c @@ -1148,7 +1148,7 @@ static void cli_incoming_debug(str *instr, struct cli_writer *cw) { } str callid; - if (str_token_sep(&callid, instr, ' ')) + if (!str_token_sep(&callid, instr, ' ')) callid = STR_NULL; if (!callid.len) { @@ -1285,7 +1285,7 @@ static void cli_incoming_set_loglevel(str *instr, struct cli_writer *cw) { str subsys = STR_NULL; if (instr->len && (instr->s[0] < '0' || instr->s[0] > '9')) - if (str_token_sep(&subsys, instr, ' ')) + if (!str_token_sep(&subsys, instr, ' ')) subsys = STR_NULL; if (!instr->len) { @@ -1440,7 +1440,7 @@ static void cli_incoming_call(str *instr, struct cli_writer *cw) { } str callid; - if (str_token_sep(&callid, instr, ' ')) + if (!str_token_sep(&callid, instr, ' ')) callid = STR_NULL; if (!callid.len) { @@ -1502,7 +1502,7 @@ static void cli_incoming_call_tag(str *instr, struct cli_writer *cw) { } str tag; - if (str_token_sep(&tag, instr, ' ')) + if (!str_token_sep(&tag, instr, ' ')) tag = STR_NULL; if (!tag.len) { diff --git a/daemon/codec.c b/daemon/codec.c index 21629e91c..e9d1f1c5c 100644 --- a/daemon/codec.c +++ b/daemon/codec.c @@ -2460,7 +2460,7 @@ rtp_payload_type *codec_make_payload_type(const str *codec_str, enum media_type str codec_fmt = *codec_str; str codec, parms, chans, opts, extra_opts, fmt_params, codec_opts; - if (str_token_sep(&codec, &codec_fmt, '/')) + if (!str_token_sep(&codec, &codec_fmt, '/')) return NULL; str_token_sep(&parms, &codec_fmt, '/'); str_token_sep(&chans, &codec_fmt, '/'); diff --git a/daemon/janus.c b/daemon/janus.c index f3e1c7ca2..76230b5a8 100644 --- a/daemon/janus.c +++ b/daemon/janus.c @@ -1944,14 +1944,14 @@ const char *websocket_janus_post(struct websocket_message *wm) { // parse out session ID and handle ID if given str s; - if (str_token_sep(&s, &uri, '/')) + if (!str_token_sep(&s, &uri, '/')) goto done; if (str_cmp(&s, "janus")) goto done; - if (str_token_sep(&s, &uri, '/')) + if (!str_token_sep(&s, &uri, '/')) goto done; session_id = str_to_ui(&s, 0); - if (str_token_sep(&s, &uri, '/')) + if (!str_token_sep(&s, &uri, '/')) goto done; handle_id = str_to_ui(&s, 0); diff --git a/daemon/redis.c b/daemon/redis.c index 9a1bfa6a5..d6fa503d6 100644 --- a/daemon/redis.c +++ b/daemon/redis.c @@ -1530,7 +1530,7 @@ static rtp_payload_type *rbl_cb_plts_g(str *s, struct redis_list *list, void *pt str ptype; struct call_media *med = ptr; - if (str_token(&ptype, s, '/')) + if (!str_token(&ptype, s, '/')) return NULL; rtp_payload_type *pt = codec_make_payload_type(s, med->type_id); @@ -1667,7 +1667,7 @@ static int redis_link_sfds(struct redis_list *sfds, struct redis_list *streams) static int rbl_subs_cb(str *s, callback_arg_t dummy, struct redis_list *list, void *ptr) { str token; - if (str_token_sep(&token, s, '/')) + if (!str_token_sep(&token, s, '/')) return -1; unsigned int media_unique_id = str_to_i(&token, 0); @@ -1676,11 +1676,11 @@ static int rbl_subs_cb(str *s, callback_arg_t dummy, struct redis_list *list, vo bool rtcp_only = false; bool egress = false; - if (!str_token_sep(&token, s, '/')) { + if (str_token_sep(&token, s, '/')) { offer_answer = str_to_i(&token, 0) ? true : false; - if (!str_token_sep(&token, s, '/')) { + if (str_token_sep(&token, s, '/')) { rtcp_only = str_to_i(&token, 0) ? true : false; - if (!str_token_sep(&token, s, '/')) + if (str_token_sep(&token, s, '/')) egress = str_to_i(&token, 0) ? true : false; } } diff --git a/daemon/sdp.c b/daemon/sdp.c index 09f2f2ce2..aa247d4eb 100644 --- a/daemon/sdp.c +++ b/daemon/sdp.c @@ -480,7 +480,7 @@ static int parse_address(struct network_address *address) { &address->address_type, &address->address); } -#define EXTRACT_TOKEN(field) do { if (str_token_sep(&output->field, value_str, ' ')) return -1; } while (0) +#define EXTRACT_TOKEN(field) do { if (!str_token_sep(&output->field, value_str, ' ')) return -1; } while (0) #define EXTRACT_NETWORK_ADDRESS_NP(field) \ do { EXTRACT_TOKEN(field.network_type); \ EXTRACT_TOKEN(field.address_type); \ @@ -552,7 +552,7 @@ static int parse_media(str *value_str, struct sdp_media *output) { /* to split the "formats" list into tokens, we abuse some vars */ str formats = output->formats; str format; - while (!str_token_sep(&format, &formats, ' ')) { + while (str_token_sep(&format, &formats, ' ')) { sp = g_slice_alloc(sizeof(*sp)); *sp = format; g_queue_push_tail(&output->format_list, sp); @@ -718,7 +718,7 @@ static int parse_attribute_crypto(struct sdp_attribute *output) { memcpy(c->mki + (c->mki_len - sizeof(u32)), &u32, sizeof(u32)); } - while (str_token_sep(&s, value_str, ' ') == 0) { + while (str_token_sep(&s, value_str, ' ')) { if (!str_cmp(&s, "UNENCRYPTED_SRTCP")) c->unencrypted_srtcp = 1; else if (!str_cmp(&s, "UNENCRYPTED_SRTP")) @@ -743,7 +743,7 @@ static int parse_attribute_rtcp(struct sdp_attribute *output) { PARSE_INIT; str portnum; - if (str_token_sep(&portnum, value_str, ' ')) + if (!str_token_sep(&portnum, value_str, ' ')) goto err; output->rtcp.port_num = str_to_i(&portnum, 0); if (output->rtcp.port_num <= 0 || output->rtcp.port_num > 0xffff) { @@ -828,9 +828,9 @@ static int parse_attribute_candidate(struct sdp_attribute *output, bool extended if (extended) { while (true) { str field, value; - if (str_token_sep(&field, value_str, ' ')) + if (!str_token_sep(&field, value_str, ' ')) break; - if (str_token_sep(&value, value_str, ' ')) + if (!str_token_sep(&value, value_str, ' ')) break; if (!str_cmp(&field, "ufrag")) c->cand_parsed.ufrag = value; diff --git a/lib/codeclib.c b/lib/codeclib.c index 1c3c0a2a5..5bd1860c4 100644 --- a/lib/codeclib.c +++ b/lib/codeclib.c @@ -2739,8 +2739,8 @@ static void codeclib_key_value_parse(const str *instr, bool need_value, // semicolon-separated key=value str s = *instr; str key, value; - while (str_token_sep(&value, &s, ';') == 0) { - if (str_token(&key, &value, '=')) { + while (str_token_sep(&value, &s, ';')) { + if (!str_token(&key, &value, '=')) { if (need_value) continue; value = STR_NULL; @@ -2858,7 +2858,7 @@ static void amr_parse_format_cb(str *key, str *token, void *data) { break; case CSH_LOOKUP("mode-set"):; str mode; - while (str_token_sep(&mode, token, ',') == 0) { + while (str_token_sep(&mode, token, ',')) { int m = str_to_i(&mode, -1); if (m < 0 || m >= AMR_FT_TYPES) continue; @@ -3745,7 +3745,7 @@ void frame_fill_dtmf_samples(enum AVSampleFormat fmt, void *samples, unsigned in static unsigned int str_to_i_k(str *s) { str intg; str frac = *s; - if (!str_token(&intg, &frac, '.')) { + if (str_token(&intg, &frac, '.')) { unsigned int ret = str_to_i(s, 0) * 1000; if (frac.len > 1) // at most one decimal digit frac.len = 1; @@ -3803,7 +3803,7 @@ static void evs_parse_bw(enum evs_bw *minp, enum evs_bw *maxp, const str *token) static void evs_parse_br(unsigned int *minp, unsigned int *maxp, str *token) { str min; str max = *token; - if (!str_token(&min, &max, '-')) { + if (str_token(&min, &max, '-')) { *minp = str_to_i_k(&min); *maxp = str_to_i_k(&max); } @@ -3950,7 +3950,7 @@ static void evs_parse_format_cb(str *key, str *token, void *data) { break; case CSH_LOOKUP("mode-set"):; str mode; - while (str_token_sep(&mode, token, ',') == 0) { + while (str_token_sep(&mode, token, ',')) { int m = str_to_i(&mode, -1); if (m < 0 || m > 8) continue; diff --git a/lib/str.h b/lib/str.h index a749ff2d3..5084100d3 100644 --- a/lib/str.h +++ b/lib/str.h @@ -156,12 +156,12 @@ INLINE unsigned long long str_to_ui(const str *s, unsigned long long def); __attribute__((nonnull(1, 2))) ACCESS(write_only, 1) ACCESS(read_write, 2) -INLINE int str_token(str *new_token, str *ori_and_remainder, int sep); +INLINE bool str_token(str *new_token, str *ori_and_remainder, int sep); /* same as str_token but allows for a trailing non-empty token (e.g. "foo,bar" -> "foo", "bar" ) */ __attribute__((nonnull(1, 2))) ACCESS(write_only, 1) ACCESS(read_write, 2) -INLINE int str_token_sep(str *new_token, str *ori_and_remainder, int sep); +INLINE bool str_token_sep(str *new_token, str *ori_and_remainder, int sep); /* copy a string to a regular C string buffer, limiting the max size */ __attribute__((nonnull(1, 3))) ACCESS(write_only, 1, 2) @@ -456,25 +456,25 @@ INLINE unsigned long long str_to_ui(const str *s, unsigned long long def) { return ret; } -INLINE int str_token(str *new_token, str *ori_and_remainder, int sep) { +INLINE bool str_token(str *new_token, str *ori_and_remainder, int sep) { *new_token = *ori_and_remainder; if (!str_chr_str(ori_and_remainder, ori_and_remainder, sep)) - return -1; + return false; new_token->len = ori_and_remainder->s - new_token->s; if (str_shift(ori_and_remainder, 1)) - return -1; - return 0; + return false; + return true; } -INLINE int str_token_sep(str *new_token, str *ori_and_remainder, int sep) { +INLINE bool str_token_sep(str *new_token, str *ori_and_remainder, int sep) { str ori = *ori_and_remainder; - if (!str_token(new_token, ori_and_remainder, sep)) - return 0; + if (str_token(new_token, ori_and_remainder, sep)) + return true; // separator not found, use remainder as final token if not empty if (!ori.len) - return -1; + return false; *new_token = ori; - return 0; + return true; } INLINE size_t str_uri_encode(char *out, const str *in) { diff --git a/perf-tester/main.c b/perf-tester/main.c index 50d4c8f50..4777659ba 100644 --- a/perf-tester/main.c +++ b/perf-tester/main.c @@ -656,7 +656,7 @@ static void show_popup(const char *fmt, ...) { str st = STR_INIT(s); str token; uint llen = 0; - while (str_token_sep(&token, &st, '\n') == 0) { + while (str_token_sep(&token, &st, '\n')) { g_queue_push_tail(&lines, str_dup(&token)); llen = MAX(token.len, llen); } diff --git a/recording-daemon/metafile.c b/recording-daemon/metafile.c index 0b4763b49..9ce7bd295 100644 --- a/recording-daemon/metafile.c +++ b/recording-daemon/metafile.c @@ -176,11 +176,11 @@ static void meta_metadata_parse(metafile_t *mf) { str all_meta = STR_INIT(mf->metadata); while (all_meta.len > 1) { str token; - if (str_token_sep(&token, &all_meta, '|')) + if (!str_token_sep(&token, &all_meta, '|')) break; str key; - if (str_token(&key, &token, ':')) { + if (!str_token(&key, &token, ':')) { // key:value separator not found, skip continue; }