Browse Source

MT#55283 modernise bencode_strdup_str

Change-Id: I517728e007ddb6920c167eae018ab147a356c6cc
pull/1897/head
Richard Fuchs 11 months ago
parent
commit
e45a3c20df
2 changed files with 13 additions and 12 deletions
  1. +5
    -5
      daemon/janus.c
  2. +8
    -7
      include/bencode.h

+ 5
- 5
daemon/janus.c View File

@ -1647,7 +1647,7 @@ static const char *janus_trickle(JsonReader *reader, struct janus_session *sessi
// allocate and parse candidate
str cand_str;
bencode_strdup_str(&ngbuf->buffer, &cand_str, candidate);
cand_str = bencode_strdup_str(&ngbuf->buffer, candidate);
str_shift_cmp(&cand_str, "candidate:"); // skip prefix
if (!cand_str.len) // end of candidates
return NULL;
@ -1664,12 +1664,12 @@ static const char *janus_trickle(JsonReader *reader, struct janus_session *sessi
g_autoptr(char) handle_buf = NULL;
handle_buf = g_strdup_printf("%" PRIu64, handle_id);
bencode_strdup_str(&ngbuf->buffer, &flags.from_tag, handle_buf);
bencode_strdup_str(&ngbuf->buffer, &flags.call_id, call_id);
flags.from_tag = bencode_strdup_str(&ngbuf->buffer, handle_buf);
flags.call_id = bencode_strdup_str(&ngbuf->buffer, call_id);
// populate and allocate a=mid
if (sdp_mid)
bencode_strdup_str(&ngbuf->buffer, &sp->media_id, sdp_mid);
sp->media_id = bencode_strdup_str(&ngbuf->buffer, sdp_mid);
// check m= line index
if (sdp_m_line >= 0)
@ -1678,7 +1678,7 @@ static const char *janus_trickle(JsonReader *reader, struct janus_session *sessi
// ufrag can be given in-line or separately
sp->ice_ufrag = cand->ufrag;
if (!sp->ice_ufrag.len && ufrag)
bencode_strdup_str(&ngbuf->buffer, &sp->ice_ufrag, ufrag);
sp->ice_ufrag = bencode_strdup_str(&ngbuf->buffer, ufrag);
// finally do the update
trickle_ice_update(ngbuf, call, &flags, &streams);


+ 8
- 7
include/bencode.h View File

@ -86,8 +86,8 @@ INLINE bencode_buffer_t *bencode_item_buffer(bencode_item_t *);
/* like strdup() but uses the bencode buffer to store the string */
INLINE char *bencode_strdup(bencode_buffer_t *, const char *);
/* ditto but inits a str object */
INLINE void bencode_strdup_str(bencode_buffer_t *, str *, const char *);
/* ditto but returns a str object */
INLINE str bencode_strdup_str(bencode_buffer_t *, const char *);
@ -369,11 +369,12 @@ INLINE char *bencode_strdup(bencode_buffer_t *buf, const char *s) {
return ret;
}
INLINE void bencode_strdup_str(bencode_buffer_t *buf, str *o, const char *s) {
*o = STR_NULL;
o->len = strlen(s);
o->s = bencode_buffer_alloc(buf, o->len);
memcpy(o->s, s, o->len);
INLINE str bencode_strdup_str(bencode_buffer_t *buf, const char *s) {
str o = STR_NULL;
o.len = strlen(s);
o.s = bencode_buffer_alloc(buf, o.len);
memcpy(o.s, s, o.len);
return o;
}
INLINE bencode_item_t *bencode_dictionary_add(bencode_item_t *dict, const char *key, bencode_item_t *val) {


Loading…
Cancel
Save