Browse Source

change str_chr_str() semantics

Change-Id: I0fb541215a1bb1a248693a6258e953827258b7ec
changes/14/17914/3
Richard Fuchs 8 years ago
parent
commit
61d828a48f
4 changed files with 13 additions and 22 deletions
  1. +1
    -2
      daemon/call_interfaces.c
  2. +7
    -14
      daemon/sdp.c
  3. +1
    -2
      daemon/stun.c
  4. +4
    -4
      lib/str.h

+ 1
- 2
daemon/call_interfaces.c View File

@ -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);


+ 7
- 14
daemon/sdp.c View File

@ -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);


+ 1
- 2
daemon/stun.c View File

@ -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);


+ 4
- 4
lib/str.h View File

@ -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)


Loading…
Cancel
Save