Browse Source

MT#55283 update str_token*() to bool return type

Requires updating/reversing the conditional wherever it is used

Change-Id: I1d34a4a3a835662d0f5bb868756ddd21211d9738
rfuchs/dataport
Richard Fuchs 2 years ago
parent
commit
560ec9af27
10 changed files with 44 additions and 44 deletions
  1. +5
    -5
      daemon/call_interfaces.c
  2. +4
    -4
      daemon/cli.c
  3. +1
    -1
      daemon/codec.c
  4. +3
    -3
      daemon/janus.c
  5. +5
    -5
      daemon/redis.c
  6. +6
    -6
      daemon/sdp.c
  7. +6
    -6
      lib/codeclib.c
  8. +11
    -11
      lib/str.h
  9. +1
    -1
      perf-tester/main.c
  10. +2
    -2
      recording-daemon/metafile.c

+ 5
- 5
daemon/call_interfaces.c View File

@ -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) { 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 *s_copy = str_dup_escape(s);
str token; 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)); ilog(LOG_WARN, "SDP manipulations: Ignoring invalid token '" STR_FORMAT "'", STR_FMT(s));
free(s_copy); free(s_copy);
return; 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 (list->type != BENCODE_LIST) {
if (bencode_get_str(list, &s)) { if (bencode_get_str(list, &s)) {
str token; str token;
while (str_token_sep(&token, &s, ',') == 0)
while (str_token_sep(&token, &s, ','))
str_callback(out, &token, arg); str_callback(out, &token, arg);
} }
else 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) if (s_copy->len == 0)
ilog(LOG_DEBUG, "Hm, nothing to parse."); 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); str * ret = str_dup(&token);
t_queue_push_tail(q, ret); 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) { static void call_ng_flags_sdp_attr_helper(sdp_ng_flags *out, str *s, helper_arg arg) {
// get media type // get media type
str token; str token;
if (str_token(&token, s, '-'))
if (!str_token(&token, s, '-'))
return; return;
struct sdp_manipulations *sm = sdp_manipulations_get_by_name(out, &token); struct sdp_manipulations *sm = sdp_manipulations_get_by_name(out, &token);
if (!sm) { if (!sm) {
@ -1428,7 +1428,7 @@ static void call_ng_flags_freqs(sdp_ng_flags *out, bencode_item_t *value) {
case BENCODE_STRING:; case BENCODE_STRING:;
str s, token; str s, token;
bencode_get_str(value, &s); bencode_get_str(value, &s);
while (str_token_sep(&token, &s, ',') == 0) {
while (str_token_sep(&token, &s, ',')) {
val = str_to_i(&token, 0); val = str_to_i(&token, 0);
g_array_append_val(out->frequencies, val); g_array_append_val(out->frequencies, val);
} }


+ 4
- 4
daemon/cli.c View File

@ -1148,7 +1148,7 @@ static void cli_incoming_debug(str *instr, struct cli_writer *cw) {
} }
str callid; str callid;
if (str_token_sep(&callid, instr, ' '))
if (!str_token_sep(&callid, instr, ' '))
callid = STR_NULL; callid = STR_NULL;
if (!callid.len) { if (!callid.len) {
@ -1285,7 +1285,7 @@ static void cli_incoming_set_loglevel(str *instr, struct cli_writer *cw) {
str subsys = STR_NULL; str subsys = STR_NULL;
if (instr->len && (instr->s[0] < '0' || instr->s[0] > '9')) 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; subsys = STR_NULL;
if (!instr->len) { if (!instr->len) {
@ -1440,7 +1440,7 @@ static void cli_incoming_call(str *instr, struct cli_writer *cw) {
} }
str callid; str callid;
if (str_token_sep(&callid, instr, ' '))
if (!str_token_sep(&callid, instr, ' '))
callid = STR_NULL; callid = STR_NULL;
if (!callid.len) { if (!callid.len) {
@ -1502,7 +1502,7 @@ static void cli_incoming_call_tag(str *instr, struct cli_writer *cw) {
} }
str tag; str tag;
if (str_token_sep(&tag, instr, ' '))
if (!str_token_sep(&tag, instr, ' '))
tag = STR_NULL; tag = STR_NULL;
if (!tag.len) { if (!tag.len) {


+ 1
- 1
daemon/codec.c View File

@ -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_fmt = *codec_str;
str codec, parms, chans, opts, extra_opts, fmt_params, codec_opts; 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; return NULL;
str_token_sep(&parms, &codec_fmt, '/'); str_token_sep(&parms, &codec_fmt, '/');
str_token_sep(&chans, &codec_fmt, '/'); str_token_sep(&chans, &codec_fmt, '/');


+ 3
- 3
daemon/janus.c View File

@ -1944,14 +1944,14 @@ const char *websocket_janus_post(struct websocket_message *wm) {
// parse out session ID and handle ID if given // parse out session ID and handle ID if given
str s; str s;
if (str_token_sep(&s, &uri, '/'))
if (!str_token_sep(&s, &uri, '/'))
goto done; goto done;
if (str_cmp(&s, "janus")) if (str_cmp(&s, "janus"))
goto done; goto done;
if (str_token_sep(&s, &uri, '/'))
if (!str_token_sep(&s, &uri, '/'))
goto done; goto done;
session_id = str_to_ui(&s, 0); session_id = str_to_ui(&s, 0);
if (str_token_sep(&s, &uri, '/'))
if (!str_token_sep(&s, &uri, '/'))
goto done; goto done;
handle_id = str_to_ui(&s, 0); handle_id = str_to_ui(&s, 0);


+ 5
- 5
daemon/redis.c View File

@ -1530,7 +1530,7 @@ static rtp_payload_type *rbl_cb_plts_g(str *s, struct redis_list *list, void *pt
str ptype; str ptype;
struct call_media *med = ptr; struct call_media *med = ptr;
if (str_token(&ptype, s, '/'))
if (!str_token(&ptype, s, '/'))
return NULL; return NULL;
rtp_payload_type *pt = codec_make_payload_type(s, med->type_id); 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) { static int rbl_subs_cb(str *s, callback_arg_t dummy, struct redis_list *list, void *ptr) {
str token; str token;
if (str_token_sep(&token, s, '/'))
if (!str_token_sep(&token, s, '/'))
return -1; return -1;
unsigned int media_unique_id = str_to_i(&token, 0); 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 rtcp_only = false;
bool egress = 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; 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; 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; egress = str_to_i(&token, 0) ? true : false;
} }
} }


+ 6
- 6
daemon/sdp.c View File

@ -480,7 +480,7 @@ static int parse_address(struct network_address *address) {
&address->address_type, &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) \ #define EXTRACT_NETWORK_ADDRESS_NP(field) \
do { EXTRACT_TOKEN(field.network_type); \ do { EXTRACT_TOKEN(field.network_type); \
EXTRACT_TOKEN(field.address_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 */ /* to split the "formats" list into tokens, we abuse some vars */
str formats = output->formats; str formats = output->formats;
str format; str format;
while (!str_token_sep(&format, &formats, ' ')) {
while (str_token_sep(&format, &formats, ' ')) {
sp = g_slice_alloc(sizeof(*sp)); sp = g_slice_alloc(sizeof(*sp));
*sp = format; *sp = format;
g_queue_push_tail(&output->format_list, sp); 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)); 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")) if (!str_cmp(&s, "UNENCRYPTED_SRTCP"))
c->unencrypted_srtcp = 1; c->unencrypted_srtcp = 1;
else if (!str_cmp(&s, "UNENCRYPTED_SRTP")) else if (!str_cmp(&s, "UNENCRYPTED_SRTP"))
@ -743,7 +743,7 @@ static int parse_attribute_rtcp(struct sdp_attribute *output) {
PARSE_INIT; PARSE_INIT;
str portnum; str portnum;
if (str_token_sep(&portnum, value_str, ' '))
if (!str_token_sep(&portnum, value_str, ' '))
goto err; goto err;
output->rtcp.port_num = str_to_i(&portnum, 0); output->rtcp.port_num = str_to_i(&portnum, 0);
if (output->rtcp.port_num <= 0 || output->rtcp.port_num > 0xffff) { 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) { if (extended) {
while (true) { while (true) {
str field, value; str field, value;
if (str_token_sep(&field, value_str, ' '))
if (!str_token_sep(&field, value_str, ' '))
break; break;
if (str_token_sep(&value, value_str, ' '))
if (!str_token_sep(&value, value_str, ' '))
break; break;
if (!str_cmp(&field, "ufrag")) if (!str_cmp(&field, "ufrag"))
c->cand_parsed.ufrag = value; c->cand_parsed.ufrag = value;


+ 6
- 6
lib/codeclib.c View File

@ -2739,8 +2739,8 @@ static void codeclib_key_value_parse(const str *instr, bool need_value,
// semicolon-separated key=value // semicolon-separated key=value
str s = *instr; str s = *instr;
str key, value; 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) if (need_value)
continue; continue;
value = STR_NULL; value = STR_NULL;
@ -2858,7 +2858,7 @@ static void amr_parse_format_cb(str *key, str *token, void *data) {
break; break;
case CSH_LOOKUP("mode-set"):; case CSH_LOOKUP("mode-set"):;
str mode; str mode;
while (str_token_sep(&mode, token, ',') == 0) {
while (str_token_sep(&mode, token, ',')) {
int m = str_to_i(&mode, -1); int m = str_to_i(&mode, -1);
if (m < 0 || m >= AMR_FT_TYPES) if (m < 0 || m >= AMR_FT_TYPES)
continue; 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) { static unsigned int str_to_i_k(str *s) {
str intg; str intg;
str frac = *s; str frac = *s;
if (!str_token(&intg, &frac, '.')) {
if (str_token(&intg, &frac, '.')) {
unsigned int ret = str_to_i(s, 0) * 1000; unsigned int ret = str_to_i(s, 0) * 1000;
if (frac.len > 1) // at most one decimal digit if (frac.len > 1) // at most one decimal digit
frac.len = 1; 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) { static void evs_parse_br(unsigned int *minp, unsigned int *maxp, str *token) {
str min; str min;
str max = *token; str max = *token;
if (!str_token(&min, &max, '-')) {
if (str_token(&min, &max, '-')) {
*minp = str_to_i_k(&min); *minp = str_to_i_k(&min);
*maxp = str_to_i_k(&max); *maxp = str_to_i_k(&max);
} }
@ -3950,7 +3950,7 @@ static void evs_parse_format_cb(str *key, str *token, void *data) {
break; break;
case CSH_LOOKUP("mode-set"):; case CSH_LOOKUP("mode-set"):;
str mode; str mode;
while (str_token_sep(&mode, token, ',') == 0) {
while (str_token_sep(&mode, token, ',')) {
int m = str_to_i(&mode, -1); int m = str_to_i(&mode, -1);
if (m < 0 || m > 8) if (m < 0 || m > 8)
continue; continue;


+ 11
- 11
lib/str.h View File

@ -156,12 +156,12 @@ INLINE unsigned long long str_to_ui(const str *s, unsigned long long def);
__attribute__((nonnull(1, 2))) __attribute__((nonnull(1, 2)))
ACCESS(write_only, 1) ACCESS(write_only, 1)
ACCESS(read_write, 2) 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" ) */ /* same as str_token but allows for a trailing non-empty token (e.g. "foo,bar" -> "foo", "bar" ) */
__attribute__((nonnull(1, 2))) __attribute__((nonnull(1, 2)))
ACCESS(write_only, 1) ACCESS(write_only, 1)
ACCESS(read_write, 2) 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 */ /* copy a string to a regular C string buffer, limiting the max size */
__attribute__((nonnull(1, 3))) __attribute__((nonnull(1, 3)))
ACCESS(write_only, 1, 2) 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; 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; *new_token = *ori_and_remainder;
if (!str_chr_str(ori_and_remainder, ori_and_remainder, sep)) 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; new_token->len = ori_and_remainder->s - new_token->s;
if (str_shift(ori_and_remainder, 1)) 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; 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 // separator not found, use remainder as final token if not empty
if (!ori.len) if (!ori.len)
return -1;
return false;
*new_token = ori; *new_token = ori;
return 0;
return true;
} }
INLINE size_t str_uri_encode(char *out, const str *in) { INLINE size_t str_uri_encode(char *out, const str *in) {


+ 1
- 1
perf-tester/main.c View File

@ -656,7 +656,7 @@ static void show_popup(const char *fmt, ...) {
str st = STR_INIT(s); str st = STR_INIT(s);
str token; str token;
uint llen = 0; 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)); g_queue_push_tail(&lines, str_dup(&token));
llen = MAX(token.len, llen); llen = MAX(token.len, llen);
} }


+ 2
- 2
recording-daemon/metafile.c View File

@ -176,11 +176,11 @@ static void meta_metadata_parse(metafile_t *mf) {
str all_meta = STR_INIT(mf->metadata); str all_meta = STR_INIT(mf->metadata);
while (all_meta.len > 1) { while (all_meta.len > 1) {
str token; str token;
if (str_token_sep(&token, &all_meta, '|'))
if (!str_token_sep(&token, &all_meta, '|'))
break; break;
str key; str key;
if (str_token(&key, &token, ':')) {
if (!str_token(&key, &token, ':')) {
// key:value separator not found, skip // key:value separator not found, skip
continue; continue;
} }


Loading…
Cancel
Save