Browse Source

MT#55283 modernise str_dup_str()

no-op

Change-Id: I6090ba2fe63d2f5a096bbc8adf734ba6aead1430
rfuchs/gh1842
Richard Fuchs 1 year ago
parent
commit
ec964c3958
9 changed files with 43 additions and 49 deletions
  1. +2
    -2
      daemon/call_interfaces.c
  2. +4
    -4
      daemon/codec.c
  3. +2
    -2
      daemon/ice.c
  4. +4
    -4
      daemon/main.c
  5. +3
    -3
      daemon/media_player.c
  6. +12
    -12
      daemon/redis.c
  7. +8
    -8
      daemon/sdp.c
  8. +1
    -1
      lib/codeclib.c
  9. +7
    -13
      lib/str.h

+ 2
- 2
daemon/call_interfaces.c View File

@ -2162,7 +2162,7 @@ static const char *call_offer_answer_ng(ng_buffer *ngbuf, bencode_item_t *input,
if (opmode == OP_ANSWER)
str_swap(&flags.to_tag, &flags.from_tag);
str_init_dup_str(&sdp, &flags.sdp);
sdp = str_dup_str(&flags.sdp);
errstr = "Failed to parse SDP";
if (sdp_parse(&sdp, &parsed, &flags))
@ -3667,7 +3667,7 @@ const char *call_publish_ng(ng_buffer *ngbuf, bencode_item_t *input, bencode_ite
if ((ret = call_ng_basic_checks(&flags, OP_PUBLISH)) > 0)
return _ng_basic_errors[ret];
str_init_dup_str(&sdp_in, &flags.sdp);
sdp_in = str_dup_str(&flags.sdp);
if (sdp_parse(&sdp_in, &parsed, &flags))
return "Failed to parse SDP";


+ 4
- 4
daemon/codec.c View File

@ -1445,7 +1445,7 @@ transcode:
sink_pt->bitrate = reverse_pt->bitrate;
if (!sink_pt->codec_opts.len) {
str_free_dup(&sink_pt->codec_opts);
str_init_dup_str(&sink_pt->codec_opts, &reverse_pt->codec_opts);
sink_pt->codec_opts = str_dup_str(&reverse_pt->codec_opts);
}
}
is_transcoding = true;
@ -2559,12 +2559,12 @@ void codec_init_payload_type(rtp_payload_type *pt, enum media_type type) {
pt->clock_rate);
// allocate strings
str_init_dup_str(&pt->encoding, &pt->encoding);
pt->encoding = str_dup_str(&pt->encoding);
pt->encoding_with_params = STR_DUP(full_encoding);
pt->encoding_with_full_params = STR_DUP(full_full_encoding);
pt->encoding_parameters = STR_DUP(params);
str_init_dup_str(&pt->format_parameters, &pt->format_parameters);
str_init_dup_str(&pt->codec_opts, &pt->codec_opts);
pt->format_parameters = str_dup_str(&pt->format_parameters);
pt->codec_opts = str_dup_str(&pt->codec_opts);
// allocate everything from the rtcp-fb list
for (GList *l = pt->rtcp_fb.head; l; l = l->next) {


+ 2
- 2
daemon/ice.c View File

@ -157,8 +157,8 @@ static void queue_sdp_fragment(ng_buffer *ngbuf, sdp_streams_q *streams, sdp_ng_
STR_FMT_M(&flags->call_id), STR_FMT_M(&flags->from_tag));
struct fragment_key *k = g_slice_alloc0(sizeof(*k));
str_init_dup_str(&k->call_id, &flags->call_id);
str_init_dup_str(&k->from_tag, &flags->from_tag);
k->call_id = str_dup_str(&flags->call_id);
k->from_tag = str_dup_str(&flags->from_tag);
struct sdp_fragment *frag = g_slice_alloc0(sizeof(*frag));
frag->received = rtpe_now;


+ 4
- 4
daemon/main.c View File

@ -285,7 +285,7 @@ static int if_addr_parse(intf_config_q *q, char *s, struct ifaddrs *ifas) {
if (cc == '=') {
// foo=bar
ifa = g_slice_alloc0(sizeof(*ifa));
str_init_dup_str(&ifa->name, &name);
ifa->name = str_dup_str(&name);
ifa->alias = STR_DUP(s);
t_queue_push_tail(q, ifa);
return 0;
@ -337,7 +337,7 @@ static int if_addr_parse(intf_config_q *q, char *s, struct ifaddrs *ifas) {
while ((addr = g_queue_pop_head(&addrs))) {
ifa = g_slice_alloc0(sizeof(*ifa));
str_init_dup_str(&ifa->name, &name);
ifa->name = str_dup_str(&name);
ifa->local_address.addr = *addr;
ifa->local_address.type = socktype_udp;
ifa->advertised_address.addr = adv;
@ -1081,8 +1081,8 @@ static void fill_initial_rtpe_cfg(struct rtpengine_config* ini_rtpe_cfg) {
for (__auto_type l = rtpe_config.interfaces.head; l ; l=l->next) {
gptr_data = g_slice_alloc0(sizeof(*gptr_data));
memcpy(gptr_data, l->data, sizeof(*gptr_data));
str_init_dup_str(&gptr_data->name, &l->data->name);
str_init_dup_str(&gptr_data->alias, &l->data->alias);
gptr_data->name = str_dup_str(&l->data->name);
gptr_data->alias = str_dup_str(&l->data->alias);
t_queue_push_tail(&ini_rtpe_cfg->interfaces, gptr_data);
}


+ 3
- 3
daemon/media_player.c View File

@ -640,7 +640,7 @@ static bool media_player_cache_get_entry(struct media_player *mp,
struct media_player_cache_index *ins_key = g_slice_alloc(sizeof(*ins_key));
*ins_key = lookup;
str_init_dup_str(&ins_key->index.file, &lookup.index.file);
ins_key->index.file = str_dup_str(&lookup.index.file);
codec_init_payload_type(&ins_key->dst_pt, MT_UNKNOWN); // duplicate contents
entry = mp->cache_entry = g_slice_alloc0(sizeof(*entry));
@ -1110,7 +1110,7 @@ static mp_cached_code __media_player_init_file(struct media_player *mp, const st
{
#ifdef WITH_TRANSCODING
mp->cache_index.type = MP_FILE;
str_init_dup_str(&mp->cache_index.file, file);
mp->cache_index.file = str_dup_str(file);
mp->opts = opts;
@ -1224,7 +1224,7 @@ static mp_cached_code __media_player_init_blob_id(struct media_player *mp, const
}
else {
mp->cache_index.type = MP_BLOB;
str_init_dup_str(&mp->cache_index.file, blob);
mp->cache_index.file = str_dup_str(blob);
if (media_player_cache_get_entry(mp, dst_pt))
return MPC_CACHED;


+ 12
- 12
daemon/redis.c View File

@ -1519,17 +1519,17 @@ static int redis_tags(call_t *c, struct redis_list *tags, JsonReader *root_reade
ml->session_sdp_orig->parsed = 1;
redis_hash_get_llu(&ml->session_sdp_orig->version_num, rh, "sdp_orig_version_num");
if (!redis_hash_get_str(&s, rh, "sdp_orig_username"))
str_init_dup_str(&ml->session_sdp_orig->username, &s);
ml->session_sdp_orig->username = str_dup_str(&s);
if (!redis_hash_get_str(&s, rh, "sdp_orig_session_id"))
str_init_dup_str(&ml->session_sdp_orig->session_id, &s);
ml->session_sdp_orig->session_id = str_dup_str(&s);
if (!redis_hash_get_str(&s, rh, "sdp_orig_version_str"))
str_init_dup_str(&ml->session_sdp_orig->version_str, &s);
ml->session_sdp_orig->version_str = str_dup_str(&s);
if (!redis_hash_get_str(&s, rh, "sdp_orig_address_network_type"))
str_init_dup_str(&ml->session_sdp_orig->address.network_type, &s);
ml->session_sdp_orig->address.network_type = str_dup_str(&s);
if (!redis_hash_get_str(&s, rh, "sdp_orig_address_address_type"))
str_init_dup_str(&ml->session_sdp_orig->address.address_type, &s);
ml->session_sdp_orig->address.address_type = str_dup_str(&s);
if (!redis_hash_get_str(&s, rh, "sdp_orig_address_address"))
str_init_dup_str(&ml->session_sdp_orig->address.address, &s);
ml->session_sdp_orig->address.address = str_dup_str(&s);
}
/* o= last used of the other side*/
if (!redis_hash_get_str(&s, rh, "last_sdp_orig_parsed")) {
@ -1537,17 +1537,17 @@ static int redis_tags(call_t *c, struct redis_list *tags, JsonReader *root_reade
ml->session_last_sdp_orig->parsed = 1;
redis_hash_get_llu(&ml->session_last_sdp_orig->version_num, rh, "last_sdp_orig_version_num");
if (!redis_hash_get_str(&s, rh, "last_sdp_orig_username"))
str_init_dup_str(&ml->session_last_sdp_orig->username, &s);
ml->session_last_sdp_orig->username = str_dup_str(&s);
if (!redis_hash_get_str(&s, rh, "last_sdp_orig_session_id"))
str_init_dup_str(&ml->session_last_sdp_orig->session_id, &s);
ml->session_last_sdp_orig->session_id = str_dup_str(&s);
if (!redis_hash_get_str(&s, rh, "last_sdp_orig_version_str"))
str_init_dup_str(&ml->session_last_sdp_orig->version_str, &s);
ml->session_last_sdp_orig->version_str = str_dup_str(&s);
if (!redis_hash_get_str(&s, rh, "last_sdp_orig_address_network_type"))
str_init_dup_str(&ml->session_last_sdp_orig->address.network_type, &s);
ml->session_last_sdp_orig->address.network_type = str_dup_str(&s);
if (!redis_hash_get_str(&s, rh, "last_sdp_orig_address_address_type"))
str_init_dup_str(&ml->session_last_sdp_orig->address.address_type, &s);
ml->session_last_sdp_orig->address.address_type = str_dup_str(&s);
if (!redis_hash_get_str(&s, rh, "last_sdp_orig_address_address"))
str_init_dup_str(&ml->session_last_sdp_orig->address.address, &s);
ml->session_last_sdp_orig->address.address = str_dup_str(&s);
}
ml->sdp_session_rr = (!redis_hash_get_int(&ii, rh, "sdp_session_rr")) ? ii : -1;


+ 8
- 8
daemon/sdp.c View File

@ -1770,8 +1770,8 @@ static bool legacy_osrtp_accept(struct stream_params *sp, sdp_streams_q *streams
static struct sdp_attr *sdp_attr_dup(const struct sdp_attribute *c) {
struct sdp_attr *ac = g_new0(__typeof(*ac), 1);
str_init_dup_str(&ac->strs.name, &c->strs.name);
str_init_dup_str(&ac->strs.value, &c->strs.value);
ac->strs.name = str_dup_str(&c->strs.name);
ac->strs.value = str_dup_str(&c->strs.value);
ac->type = c->other;
return ac;
@ -1785,16 +1785,16 @@ void sdp_attr_free(struct sdp_attr *c) {
sdp_origin *sdp_orig_dup(const sdp_origin *orig) {
sdp_origin *copy = g_slice_alloc0(sizeof(*copy));
str_init_dup_str(&copy->username, &orig->username);
str_init_dup_str(&copy->session_id, &orig->session_id);
str_init_dup_str(&copy->version_str, &orig->version_str);
copy->username = str_dup_str(&orig->username);
copy->session_id = str_dup_str(&orig->session_id);
copy->version_str = str_dup_str(&orig->version_str);
copy->version_num = orig->version_num;
copy->version_output_pos = orig->version_output_pos;
copy->parsed = orig->parsed;
/* struct network_address */
str_init_dup_str(&copy->address.network_type, &orig->address.network_type);
str_init_dup_str(&copy->address.address_type, &orig->address.address_type);
str_init_dup_str(&copy->address.address, &orig->address.address);
copy->address.network_type = str_dup_str(&orig->address.network_type);
copy->address.address_type = str_dup_str(&orig->address.address_type);
copy->address.address = str_dup_str(&orig->address.address);
copy->address.parsed = orig->address.parsed;
return copy;


+ 1
- 1
lib/codeclib.c View File

@ -4993,7 +4993,7 @@ static void __codec_cc_free(codec_cc_t *c) {
// append job to queue
static void __cc_async_do_add_queue(codec_cc_t *c, const str *data, unsigned long ts, void *async_cb_obj) {
struct async_job *j = g_new0(__typeof__(*j), 1);
str_init_dup_str(&j->data, data);
j->data = str_dup_str(data);
j->async_cb_obj = async_cb_obj;
j->ts = ts;
t_queue_push_tail(&c->async_jobs, j);


+ 7
- 13
lib/str.h View File

@ -86,11 +86,9 @@ INLINE int str_casecmp_str(const str *a, const str *b);
ACCESS(read_only, 1)
ACCESS(read_only, 2)
INLINE int str_cmp_str0(const str *a, const str *b);
/* inits a str object from a regular string and duplicates the contents. returns out */
__attribute__((nonnull(1)))
ACCESS(write_only, 1)
ACCESS(read_only, 2)
INLINE str *str_init_dup_str(str *out, const str *s);
/* inits a str object from a regular string and duplicates the contents */
ACCESS(read_only, 1)
INLINE str str_dup_str(const str *s);
INLINE void str_free_dup(str *out);
/* returns new str object with uninitialized buffer large enough to hold `len` characters (+1 for null byte) */
INLINE str *str_alloc(size_t len);
@ -295,18 +293,14 @@ INLINE int str_cmp_str0(const str *a, const str *b) {
}
return str_cmp_str(a, b);
}
INLINE str *str_init_dup_str(str *out, const str *s) {
if (!s) {
*out = STR_NULL;
return out;
}
INLINE str str_dup_str(const str *s) {
if (!s)
return STR_NULL;
char *buf = g_malloc(s->len + 1);
if (s->s && s->len)
memcpy(buf, s->s, s->len);
buf[s->len] = '\0';
out->len = s->len;
out->s = buf;
return out;
return STR_LEN(buf, s->len);
}
INLINE void str_free_dup(str *out) {
if (!out)


Loading…
Cancel
Save