From 61d828a48f4a56b0a8cde1a92330a226d9fcb8d2 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Fri, 22 Dec 2017 11:25:23 -0500 Subject: [PATCH] change str_chr_str() semantics Change-Id: I0fb541215a1bb1a248693a6258e953827258b7ec --- daemon/call_interfaces.c | 3 +-- daemon/sdp.c | 21 +++++++-------------- daemon/stun.c | 3 +-- lib/str.h | 8 ++++---- 4 files changed, 13 insertions(+), 22 deletions(-) diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index 13492005f..277e9b969 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -483,8 +483,7 @@ INLINE void str_hyphenate(bencode_item_t *it) { if (!bencode_get_str(it, &s)) return; while (s.len) { - str_chr_str(&s, &s, ' '); - if (!s.s || !s.len) + if (!str_chr_str(&s, &s, ' ')) break; *s.s = '-'; str_shift(&s, 1); diff --git a/daemon/sdp.c b/daemon/sdp.c index ef8fa61ff..54e6ac9ee 100644 --- a/daemon/sdp.c +++ b/daemon/sdp.c @@ -391,8 +391,7 @@ static int parse_attribute_ssrc(struct sdp_attribute *output) { return -1; s->attr = s->attr_str; - str_chr_str(&s->value, &s->attr, ':'); - if (s->value.s) { + if (str_chr_str(&s->value, &s->attr, ':')) { s->attr.len = s->value.s - s->attr.s; str_shift(&s->value, 1); } @@ -471,8 +470,7 @@ static int parse_attribute_crypto(struct sdp_attribute *output) { if (c->lifetime_str.s[0] != '|') goto error; str_shift(&c->lifetime_str, 1); - str_chr_str(&c->mki_str, &c->lifetime_str, '|'); - if (!c->mki_str.s) { + if (!str_chr_str(&c->mki_str, &c->lifetime_str, '|')) { if (str_chr(&c->lifetime_str, ':')) { c->mki_str = c->lifetime_str; c->lifetime_str = STR_NULL; @@ -507,9 +505,8 @@ static int parse_attribute_crypto(struct sdp_attribute *output) { } if (c->mki_str.s) { - str_chr_str(&s, &c->mki_str, ':'); err = "invalid MKI specification"; - if (!s.s) + if (!str_chr_str(&s, &c->mki_str, ':')) goto error; u32 = htonl(strtoul(c->mki_str.s, NULL, 10)); c->mki_len = strtoul(s.s + 1, NULL, 10); @@ -723,16 +720,14 @@ static int parse_attribute_rtpmap(struct sdp_attribute *output) { if (ep == a->payload_type_str.s) return -1; - str_chr_str(&a->clock_rate_str, &a->encoding_str, '/'); - if (!a->clock_rate_str.s) + if (!str_chr_str(&a->clock_rate_str, &a->encoding_str, '/')) return -1; pt->encoding = a->encoding_str; pt->encoding.len -= a->clock_rate_str.len; str_shift(&a->clock_rate_str, 1); - str_chr_str(&pt->encoding_parameters, &a->clock_rate_str, '/'); - if (pt->encoding_parameters.s) { + if (str_chr_str(&pt->encoding_parameters, &a->clock_rate_str, '/')) { a->clock_rate_str.len -= pt->encoding_parameters.len; str_shift(&pt->encoding_parameters, 1); } @@ -751,15 +746,13 @@ static int parse_attribute(struct sdp_attribute *a) { int ret; a->name = a->line_value; - str_chr_str(&a->value, &a->name, ':'); - if (a->value.s) { + if (str_chr_str(&a->value, &a->name, ':')) { a->name.len -= a->value.len; a->value.s++; a->value.len--; a->key = a->name; - str_chr_str(&a->param, &a->value, ' '); - if (a->param.s) { + if (str_chr_str(&a->param, &a->value, ' ')) { a->key.len += 1 + (a->value.len - a->param.len); diff --git a/daemon/stun.c b/daemon/stun.c index a236f0e98..ce4823870 100644 --- a/daemon/stun.c +++ b/daemon/stun.c @@ -437,8 +437,7 @@ static int check_auth(str *msg, struct stun_attrs *attrs, struct call_media *med if (attrs->username.s) { /* request */ ufrag[dst] = attrs->username; - str_chr_str(&ufrag[src], &ufrag[dst], ':'); - if (!ufrag[src].s) + if (!str_chr_str(&ufrag[src], &ufrag[dst], ':')) return -1; ufrag[dst].len -= ufrag[src].len; str_shift(&ufrag[src], 1); diff --git a/lib/str.h b/lib/str.h index 1a02b26bc..ee3318ea7 100644 --- a/lib/str.h +++ b/lib/str.h @@ -35,7 +35,7 @@ INLINE char *str_end(const str *s); /* returns pointer to first occurrence of "c" in s */ INLINE char *str_chr(const str *s, int c); /* sets "out" to point to first occurrence of c in s. adjusts len also */ -INLINE str *str_chr_str(str *out, const str *s, int c); +INLINE char *str_chr_str(str *out, const str *s, int c); /* compares a str to a regular string */ INLINE int str_cmp(const str *a, const char *b); /* compares a str to a non-null-terminated string */ @@ -132,16 +132,16 @@ INLINE int str_shift_cmp(str *s, const char *t) { INLINE char *str_chr(const str *s, int c) { return memchr(s->s, c, s->len); } -INLINE str *str_chr_str(str *out, const str *s, int c) { +INLINE char *str_chr_str(str *out, const str *s, int c) { char *p; p = str_chr(s, c); if (!p) { *out = STR_NULL; - return out; + return NULL; } *out = *s; str_shift(out, p - out->s); - return out; + return out->s; } INLINE int str_cmp_len(const str *a, const char *b, int l) { if (a->len < l)