From e45a3c20df2424ae8018c0e0734a7c7d2947f9a7 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 14 Jan 2025 11:03:21 -0400 Subject: [PATCH] MT#55283 modernise bencode_strdup_str Change-Id: I517728e007ddb6920c167eae018ab147a356c6cc --- daemon/janus.c | 10 +++++----- include/bencode.h | 15 ++++++++------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/daemon/janus.c b/daemon/janus.c index a028cd011..6b7a1869a 100644 --- a/daemon/janus.c +++ b/daemon/janus.c @@ -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); diff --git a/include/bencode.h b/include/bencode.h index 1d7816aa1..c77cf58bd 100644 --- a/include/bencode.h +++ b/include/bencode.h @@ -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) {