MT#55283 simplify call_str_dup family

Instead of having to explicitly pass the call object to each invocation,
keep one thread-local reference to a call, implicitly set by setting the
logging context.

Add helper functions to set and release the respective reference.

Change-Id: Ic0d82eeaa403467d50dae867e33fdf9b9dd7cec5
rfuchs/test
Richard Fuchs 1 year ago
parent 57044d7563
commit 67e1b9979a

@ -58,6 +58,7 @@ struct xmlrpc_helper {
rwlock_t rtpe_callhash_lock; rwlock_t rtpe_callhash_lock;
rtpe_calls_ht rtpe_callhash; rtpe_calls_ht rtpe_callhash;
struct call_iterator_list rtpe_call_iterators[NUM_CALL_ITERATORS]; struct call_iterator_list rtpe_call_iterators[NUM_CALL_ITERATORS];
__thread call_t *call_memory_arena;
static struct mqtt_timer *global_mqtt_timer; static struct mqtt_timer *global_mqtt_timer;
unsigned int call_socket_cpu_affinity = 0; unsigned int call_socket_cpu_affinity = 0;
@ -709,7 +710,7 @@ static struct call_media *__get_media(struct call_monologue *ml, const struct st
med = call_media_new(call); med = call_media_new(call);
med->monologue = ml; med->monologue = ml;
med->index = want_index; med->index = want_index;
call_str_cpy(ml->call, &med->type, &sp->type); call_str_cpy(&med->type, &sp->type);
med->type_id = sp->type_id; med->type_id = sp->type_id;
ml->medias->pdata[arr_index] = med; ml->medias->pdata[arr_index] = med;
@ -2137,7 +2138,6 @@ static void __dtls_logic(const sdp_ng_flags *flags,
struct call_media *other_media, struct stream_params *sp) struct call_media *other_media, struct stream_params *sp)
{ {
uint64_t tmp; uint64_t tmp;
call_t *call = other_media->call;
/* active and passive are from our POV */ /* active and passive are from our POV */
tmp = atomic64_get_na(&other_media->media_flags); tmp = atomic64_get_na(&other_media->media_flags);
@ -2183,7 +2183,7 @@ static void __dtls_logic(const sdp_ng_flags *flags,
__dtls_restart(other_media); __dtls_restart(other_media);
} }
call_str_cpy(call, &other_media->tls_id, &sp->tls_id); call_str_cpy(&other_media->tls_id, &sp->tls_id);
MEDIA_CLEAR(other_media, DTLS); MEDIA_CLEAR(other_media, DTLS);
if (MEDIA_ISSET2(other_media, SETUP_PASSIVE, SETUP_ACTIVE) if (MEDIA_ISSET2(other_media, SETUP_PASSIVE, SETUP_ACTIVE)
@ -2233,7 +2233,6 @@ __attribute__((nonnull(2, 3, 4)))
static void __update_media_id(struct call_media *media, struct call_media *other_media, static void __update_media_id(struct call_media *media, struct call_media *other_media,
struct stream_params *sp, const sdp_ng_flags *flags) struct stream_params *sp, const sdp_ng_flags *flags)
{ {
call_t *call = other_media->call;
struct call_monologue *ml = media ? media->monologue : NULL; struct call_monologue *ml = media ? media->monologue : NULL;
struct call_monologue *other_ml = other_media->monologue; struct call_monologue *other_ml = other_media->monologue;
@ -2245,7 +2244,7 @@ static void __update_media_id(struct call_media *media, struct call_media *other
if (!other_media->media_id.s) { if (!other_media->media_id.s) {
// incoming side: we copy what we received // incoming side: we copy what we received
if (sp->media_id.s) if (sp->media_id.s)
call_str_cpy(call, &other_media->media_id, &sp->media_id); call_str_cpy(&other_media->media_id, &sp->media_id);
if (other_media->media_id.s) if (other_media->media_id.s)
g_hash_table_insert(other_ml->media_ids, &other_media->media_id, g_hash_table_insert(other_ml->media_ids, &other_media->media_id,
other_media); other_media);
@ -2257,7 +2256,7 @@ static void __update_media_id(struct call_media *media, struct call_media *other
if (str_cmp_str(&other_media->media_id, &sp->media_id)) { if (str_cmp_str(&other_media->media_id, &sp->media_id)) {
// mismatch - update // mismatch - update
g_hash_table_remove(other_ml->media_ids, &other_media->media_id); g_hash_table_remove(other_ml->media_ids, &other_media->media_id);
call_str_cpy(call, &other_media->media_id, &sp->media_id); call_str_cpy(&other_media->media_id, &sp->media_id);
g_hash_table_insert(other_ml->media_ids, &other_media->media_id, g_hash_table_insert(other_ml->media_ids, &other_media->media_id,
other_media); other_media);
} }
@ -2271,12 +2270,12 @@ static void __update_media_id(struct call_media *media, struct call_media *other
if (media && !media->media_id.s) { if (media && !media->media_id.s) {
// outgoing side: we copy from the other side // outgoing side: we copy from the other side
if (other_media->media_id.s) if (other_media->media_id.s)
call_str_cpy(call, &media->media_id, &other_media->media_id); call_str_cpy(&media->media_id, &other_media->media_id);
else if (flags->generate_mid) { else if (flags->generate_mid) {
// or generate one // or generate one
char buf[64]; char buf[64];
snprintf(buf, sizeof(buf), "%u", other_media->index); snprintf(buf, sizeof(buf), "%u", other_media->index);
call_str_cpy_c(call, &media->media_id, buf); call_str_cpy_c(&media->media_id, buf);
} }
if (media->media_id.s) if (media->media_id.s)
g_hash_table_insert(ml->media_ids, &media->media_id, media); g_hash_table_insert(ml->media_ids, &media->media_id, media);
@ -2314,8 +2313,8 @@ static void __t38_reset(struct call_media *media, struct call_media *other_media
media->protocol = other_media->protocol; media->protocol = other_media->protocol;
media->type_id = other_media->type_id; media->type_id = other_media->type_id;
call_str_cpy(media->call, &media->type, &other_media->type); call_str_cpy(&media->type, &other_media->type);
call_str_cpy(media->call, &media->format_str, &other_media->format_str); call_str_cpy(&media->format_str, &other_media->format_str);
} }
__attribute__((nonnull(2, 3, 4))) __attribute__((nonnull(2, 3, 4)))
@ -2326,16 +2325,16 @@ static void __update_media_protocol(struct call_media *media, struct call_media
if (str_cmp_str(&other_media->type, &sp->type)) { if (str_cmp_str(&other_media->type, &sp->type)) {
ilog(LOG_DEBUG, "Updating media type from '" STR_FORMAT "' to '" STR_FORMAT "'", ilog(LOG_DEBUG, "Updating media type from '" STR_FORMAT "' to '" STR_FORMAT "'",
STR_FMT(&other_media->type), STR_FMT(&sp->type)); STR_FMT(&other_media->type), STR_FMT(&sp->type));
call_str_cpy(other_media->call, &other_media->type, &sp->type); call_str_cpy(&other_media->type, &sp->type);
other_media->type_id = codec_get_type(&other_media->type); other_media->type_id = codec_get_type(&other_media->type);
if (media) { if (media) {
call_str_cpy(media->call, &media->type, &sp->type); call_str_cpy(&media->type, &sp->type);
media->type_id = other_media->type_id; media->type_id = other_media->type_id;
} }
} }
/* deduct protocol from stream parameters received */ /* deduct protocol from stream parameters received */
call_str_cpy(other_media->call, &other_media->protocol_str, &sp->protocol_str); call_str_cpy(&other_media->protocol_str, &sp->protocol_str);
if (other_media->protocol != sp->protocol) { if (other_media->protocol != sp->protocol) {
other_media->protocol = sp->protocol; other_media->protocol = sp->protocol;
@ -2377,7 +2376,7 @@ static void __update_media_protocol(struct call_media *media, struct call_media
media->protocol = other_media->protocol; media->protocol = other_media->protocol;
if (media && !media->protocol_str.s) if (media && !media->protocol_str.s)
call_str_cpy(other_media->call, &media->protocol_str, &other_media->protocol_str); call_str_cpy(&media->protocol_str, &other_media->protocol_str);
// handler overrides requested by the user // handler overrides requested by the user
@ -2402,7 +2401,7 @@ static void __update_media_protocol(struct call_media *media, struct call_media
if (!media->protocol) if (!media->protocol)
media->protocol = &transport_protocols[PROTO_RTP_AVP]; media->protocol = &transport_protocols[PROTO_RTP_AVP];
media->type_id = MT_AUDIO; media->type_id = MT_AUDIO;
call_str_cpy_c(media->call, &media->type, "audio"); call_str_cpy_c(&media->type, "audio");
return; return;
} }
@ -2412,8 +2411,8 @@ static void __update_media_protocol(struct call_media *media, struct call_media
{ {
media->protocol = &transport_protocols[PROTO_UDPTL]; media->protocol = &transport_protocols[PROTO_UDPTL];
media->type_id = MT_IMAGE; media->type_id = MT_IMAGE;
call_str_cpy_c(media->call, &media->type, "image"); call_str_cpy_c(&media->type, "image");
call_str_cpy_c(media->call, &media->format_str, "t38"); call_str_cpy_c(&media->format_str, "t38");
return; return;
} }
@ -2663,12 +2662,12 @@ static void __call_monologue_init_from_flags(struct call_monologue *ml, struct c
(!ml->sdp_session_name || /* if not set yet */ (!ml->sdp_session_name || /* if not set yet */
(ml->sdp_session_name && !flags->replace_sess_name))) /* replace_sess_name = do not replace if possible*/ (ml->sdp_session_name && !flags->replace_sess_name))) /* replace_sess_name = do not replace if possible*/
{ {
ml->sdp_session_name = call_strdup_len(call, flags->session_sdp_name.s, ml->sdp_session_name = call_strdup_len(flags->session_sdp_name.s,
flags->session_sdp_name.len); flags->session_sdp_name.len);
} }
/* sdp session timing */ /* sdp session timing */
if (flags->session_timing.len) if (flags->session_timing.len)
ml->sdp_session_timing = call_strdup_len(call, flags->session_timing.s, ml->sdp_session_timing = call_strdup_len(flags->session_timing.s,
flags->session_timing.len); flags->session_timing.len);
/* sdp bandwidth per session level /* sdp bandwidth per session level
* 0 value is supported (e.g. b=RR:0 and b=RS:0), to be able to disable rtcp */ * 0 value is supported (e.g. b=RR:0 and b=RS:0), to be able to disable rtcp */
@ -2684,7 +2683,7 @@ static void __call_monologue_init_from_flags(struct call_monologue *ml, struct c
ml->sdp_session_bandwidth.tias = flags->session_bandwidth.tias; ml->sdp_session_bandwidth.tias = flags->session_bandwidth.tias;
/* sdp session group */ /* sdp session group */
if (flags->session_group.len) if (flags->session_group.len)
ml->sdp_session_group = call_strdup_len(call, flags->session_group.s, ml->sdp_session_group = call_strdup_len(flags->session_group.s,
flags->session_group.len); flags->session_group.len);
} }
@ -2704,7 +2703,7 @@ static void __call_monologue_init_from_flags(struct call_monologue *ml, struct c
__tos_change(call, flags); __tos_change(call, flags);
if (flags->label.s) { if (flags->label.s) {
call_str_cpy(call, &ml->label, &flags->label); call_str_cpy(&ml->label, &flags->label);
t_hash_table_replace(call->labels, &ml->label, ml); t_hash_table_replace(call->labels, &ml->label, ml);
} }
@ -2752,13 +2751,11 @@ static void __update_media_label(struct call_media *media, struct call_media *ot
if (!media) if (!media)
return; return;
call_t *call = media->call;
if (flags->siprec && flags->opmode == OP_REQUEST) { if (flags->siprec && flags->opmode == OP_REQUEST) {
if (!media->label.len) { if (!media->label.len) {
char buf[64]; char buf[64];
snprintf(buf, sizeof(buf), "%u", other_media->unique_id); snprintf(buf, sizeof(buf), "%u", other_media->unique_id);
call_str_cpy_c(call, &media->label, buf); call_str_cpy_c(&media->label, buf);
} }
// put same label on both sides // put same label on both sides
if (!other_media->label.len) if (!other_media->label.len)
@ -2771,8 +2768,6 @@ __attribute__((nonnull(1, 3, 4)))
static void __media_init_from_flags(struct call_media *other_media, struct call_media *media, static void __media_init_from_flags(struct call_media *other_media, struct call_media *media,
struct stream_params *sp, sdp_ng_flags *flags) struct stream_params *sp, sdp_ng_flags *flags)
{ {
call_t *call = other_media->call;
if (flags->opmode == OP_OFFER && flags->reset) { if (flags->opmode == OP_OFFER && flags->reset) {
if (media) if (media)
MEDIA_CLEAR(media, INITIALIZED); MEDIA_CLEAR(media, INITIALIZED);
@ -2887,11 +2882,11 @@ static void __media_init_from_flags(struct call_media *other_media, struct call_
MEDIA_SET(other_media, PTIME_OVERRIDE); MEDIA_SET(other_media, PTIME_OVERRIDE);
} }
if (str_cmp_str(&other_media->format_str, &sp->format_str)) if (str_cmp_str(&other_media->format_str, &sp->format_str))
call_str_cpy(call, &other_media->format_str, &sp->format_str); call_str_cpy(&other_media->format_str, &sp->format_str);
if (media && str_cmp_str(&media->format_str, &sp->format_str)) { if (media && str_cmp_str(&media->format_str, &sp->format_str)) {
// update opposite side format string only if protocols match // update opposite side format string only if protocols match
if (media->protocol == other_media->protocol) if (media->protocol == other_media->protocol)
call_str_cpy(call, &media->format_str, &sp->format_str); call_str_cpy(&media->format_str, &sp->format_str);
} }
/* deduct address family from stream parameters received */ /* deduct address family from stream parameters received */
@ -4117,7 +4112,8 @@ static call_t *call_create(const str *callid) {
c->tags = tags_ht_new(); c->tags = tags_ht_new();
c->viabranches = tags_ht_new(); c->viabranches = tags_ht_new();
c->labels = labels_ht_new(); c->labels = labels_ht_new();
call_str_cpy(c, &c->callid, callid); call_memory_arena_set(c);
call_str_cpy(&c->callid, callid);
c->created = rtpe_now; c->created = rtpe_now;
c->dtls_cert = dtls_cert(); c->dtls_cert = dtls_cert();
c->tos = rtpe_config.default_tos; c->tos = rtpe_config.default_tos;
@ -4280,7 +4276,7 @@ void __monologue_tag(struct call_monologue *ml, const str *tag) {
__C_DBG("tagging monologue with '"STR_FORMAT"'", STR_FMT(tag)); __C_DBG("tagging monologue with '"STR_FORMAT"'", STR_FMT(tag));
if (ml->tag.s) if (ml->tag.s)
t_hash_table_remove(call->tags, &ml->tag); /* remove tag from tags of the call object */ t_hash_table_remove(call->tags, &ml->tag); /* remove tag from tags of the call object */
call_str_cpy(call, &ml->tag, tag); call_str_cpy(&ml->tag, tag);
t_hash_table_insert(call->tags, &ml->tag, ml); /* and insert a new one */ t_hash_table_insert(call->tags, &ml->tag, ml); /* and insert a new one */
} }
@ -4293,7 +4289,7 @@ void __monologue_viabranch(struct call_monologue *ml, const str *viabranch) {
__C_DBG("tagging monologue with viabranch '"STR_FORMAT"'", STR_FMT(viabranch)); __C_DBG("tagging monologue with viabranch '"STR_FORMAT"'", STR_FMT(viabranch));
if (ml->viabranch.s) if (ml->viabranch.s)
t_hash_table_remove(call->viabranches, &ml->viabranch); t_hash_table_remove(call->viabranches, &ml->viabranch);
call_str_cpy(call, &ml->viabranch, viabranch); call_str_cpy(&ml->viabranch, viabranch);
t_hash_table_insert(call->viabranches, &ml->viabranch, ml); t_hash_table_insert(call->viabranches, &ml->viabranch, ml);
} }

@ -168,7 +168,7 @@ fail:
static void updated_created_from(call_t *c, const char *addr, const endpoint_t *sin) { static void updated_created_from(call_t *c, const char *addr, const endpoint_t *sin) {
if (!c->created_from && addr) { if (!c->created_from && addr) {
c->created_from = call_strdup(c, addr); c->created_from = call_strdup(addr);
if (sin) if (sin)
c->created_from_addr = sin->address; c->created_from_addr = sin->address;
} }
@ -2988,7 +2988,7 @@ static const char *media_block_match(call_t **call, struct call_monologue **mono
// for generic ops, handle set-label here if given // for generic ops, handle set-label here if given
if (IS_OP_OTHER(opmode) && flags->set_label.len && *monologue) { if (IS_OP_OTHER(opmode) && flags->set_label.len && *monologue) {
call_str_cpy(*call, &(*monologue)->label, &flags->set_label); call_str_cpy(&(*monologue)->label, &flags->set_label);
t_hash_table_replace((*call)->labels, &(*monologue)->label, *monologue); t_hash_table_replace((*call)->labels, &(*monologue)->label, *monologue);
} }

@ -311,7 +311,7 @@ void dtmf_trigger_set(struct call_monologue *ml, enum dtmf_trigger_type trigger_
dtmf_trigger_types[trigger_type], dtmf_trigger_types[trigger_type],
(unsigned int) (state - ml->dtmf_trigger_state), STR_FMT(s)); (unsigned int) (state - ml->dtmf_trigger_state), STR_FMT(s));
call_str_cpy(ml->call, &state->trigger, s); call_str_cpy(&state->trigger, s);
state->matched = 0; state->matched = 0;
state->inactive = inactive; state->inactive = inactive;
} }

@ -451,7 +451,7 @@ void ice_agent_init(struct ice_agent **agp, struct call_media *media) {
static int __copy_cand(call_t *call, struct ice_candidate *dst, const struct ice_candidate *src) { static int __copy_cand(call_t *call, struct ice_candidate *dst, const struct ice_candidate *src) {
int eq = (dst->priority == src->priority); int eq = (dst->priority == src->priority);
*dst = *src; *dst = *src;
call_str_cpy(call, &dst->foundation, &src->foundation); call_str_cpy(&dst->foundation, &src->foundation);
return eq ? 0 : 1; return eq ? 0 : 1;
} }
@ -517,9 +517,9 @@ void ice_update(struct ice_agent *ag, struct stream_params *sp, bool allow_reset
/* update remote info */ /* update remote info */
if (sp->ice_ufrag.s) if (sp->ice_ufrag.s)
call_str_cpy(call, &ag->ufrag[0], &sp->ice_ufrag); call_str_cpy(&ag->ufrag[0], &sp->ice_ufrag);
if (sp->ice_pwd.s) if (sp->ice_pwd.s)
call_str_cpy(call, &ag->pwd[0], &sp->ice_pwd); call_str_cpy(&ag->pwd[0], &sp->ice_pwd);
candidates = &sp->ice_candidates; candidates = &sp->ice_candidates;
} }
@ -1026,7 +1026,7 @@ static void __cand_ice_foundation(call_t *call, struct ice_candidate *cand) {
len = sprintf(buf, "%x%x%x", endpoint_hash(&cand->endpoint), len = sprintf(buf, "%x%x%x", endpoint_hash(&cand->endpoint),
cand->type, g_direct_hash(cand->transport)); cand->type, g_direct_hash(cand->transport));
call_str_cpy_len(call, &cand->foundation, buf, len); call_str_cpy_len(&cand->foundation, buf, len);
} }
/* agent must be locked */ /* agent must be locked */
@ -1551,7 +1551,7 @@ static void create_random_ice_string(call_t *call, str *s, int len) {
return; return;
random_ice_string(buf, len); random_ice_string(buf, len);
call_str_cpy_len(call, s, buf, len); call_str_cpy_len(s, buf, len);
} }
void ice_foundation(str *s) { void ice_foundation(str *s) {

@ -42,6 +42,7 @@ INLINE void log_info_pop(void) {
if (!log_info_stack) { if (!log_info_stack) {
ZERO(log_info); ZERO(log_info);
call_memory_arena_release();
return; return;
} }
@ -64,6 +65,7 @@ INLINE void log_info_pop_until(void *p) {
INLINE void log_info_reset(void) { INLINE void log_info_reset(void) {
__log_info_release(&log_info); __log_info_release(&log_info);
ZERO(log_info); ZERO(log_info);
call_memory_arena_release();
while (log_info_stack) { while (log_info_stack) {
struct log_info *element = log_info_stack->data; struct log_info *element = log_info_stack->data;
@ -79,6 +81,7 @@ INLINE void log_info_call(call_t *c) {
__log_info_push(); __log_info_push();
log_info.e = LOG_INFO_CALL; log_info.e = LOG_INFO_CALL;
log_info.call = obj_get(c); log_info.call = obj_get(c);
call_memory_arena_set(c);
} }
INLINE void log_info_stream_fd(stream_fd *sfd) { INLINE void log_info_stream_fd(stream_fd *sfd) {
if (!sfd) if (!sfd)
@ -86,6 +89,7 @@ INLINE void log_info_stream_fd(stream_fd *sfd) {
__log_info_push(); __log_info_push();
log_info.e = LOG_INFO_STREAM_FD; log_info.e = LOG_INFO_STREAM_FD;
log_info.stream_fd = obj_get(sfd); log_info.stream_fd = obj_get(sfd);
call_memory_arena_set(sfd->call);
} }
INLINE void log_info_str(const str *s) { INLINE void log_info_str(const str *s) {
if (!s || !s->s) if (!s || !s->s)
@ -107,6 +111,7 @@ INLINE void log_info_ice_agent(struct ice_agent *ag) {
__log_info_push(); __log_info_push();
log_info.e = LOG_INFO_ICE_AGENT; log_info.e = LOG_INFO_ICE_AGENT;
log_info.ice_agent = obj_get(&ag->tt_obj); log_info.ice_agent = obj_get(&ag->tt_obj);
call_memory_arena_set(ag->call);
} }
INLINE void log_info_media(struct call_media *m) { INLINE void log_info_media(struct call_media *m) {
if (!m) if (!m)
@ -117,6 +122,7 @@ INLINE void log_info_media(struct call_media *m) {
log_info.e = LOG_INFO_MEDIA; log_info.e = LOG_INFO_MEDIA;
log_info.call = obj_get(m->call); log_info.call = obj_get(m->call);
log_info.media = m; log_info.media = m;
call_memory_arena_set(m->call);
} }

@ -276,7 +276,7 @@ static void update_call_field(call_t *call, str *dst_field, const str *src_field
return; return;
if (src_field && src_field->len && str_cmp_str(src_field, dst_field)) if (src_field && src_field->len && str_cmp_str(src_field, dst_field))
call_str_cpy(call, dst_field, src_field); call_str_cpy(dst_field, src_field);
if (call->recording && dst_field->len) { if (call->recording && dst_field->len) {
va_list ap; va_list ap;
@ -368,8 +368,8 @@ void recording_start_daemon(call_t *call) {
char rand_str[rand_bytes * 2 + 1]; char rand_str[rand_bytes * 2 + 1];
rand_hex_str(rand_str, rand_bytes); rand_hex_str(rand_str, rand_bytes);
g_autoptr(char) meta_prefix = g_strdup_printf("%s-%s", escaped_callid, rand_str); g_autoptr(char) meta_prefix = g_strdup_printf("%s-%s", escaped_callid, rand_str);
call_str_cpy(call, &call->recording_meta_prefix, &STR(meta_prefix)); call_str_cpy(&call->recording_meta_prefix, &STR(meta_prefix));
call_str_cpy(call, &call->recording_random_tag, &STR_CONST(rand_str)); call_str_cpy(&call->recording_random_tag, &STR_CONST(rand_str));
} }
_rm(init_struct, call); _rm(init_struct, call);

@ -1479,9 +1479,9 @@ static int redis_tags(call_t *c, struct redis_list *tags, parser_arg arg) {
if (!redis_hash_get_str(&s, rh, "via-branch")) if (!redis_hash_get_str(&s, rh, "via-branch"))
__monologue_viabranch(ml, &s); __monologue_viabranch(ml, &s);
if (!redis_hash_get_str(&s, rh, "label")) if (!redis_hash_get_str(&s, rh, "label"))
call_str_cpy(c, &ml->label, &s); call_str_cpy(&ml->label, &s);
if (!redis_hash_get_str(&s, rh, "metadata")) if (!redis_hash_get_str(&s, rh, "metadata"))
call_str_cpy(c, &c->metadata, &s); call_str_cpy(&c->metadata, &s);
redis_hash_get_time_t(&ml->deleted, rh, "deleted"); redis_hash_get_time_t(&ml->deleted, rh, "deleted");
if (!redis_hash_get_int(&ii, rh, "block_dtmf")) if (!redis_hash_get_int(&ii, rh, "block_dtmf"))
ml->block_dtmf = ii; ml->block_dtmf = ii;
@ -1490,10 +1490,10 @@ static int redis_tags(call_t *c, struct redis_list *tags, parser_arg arg) {
/* s= */ /* s= */
if (!redis_hash_get_str(&s, rh, "sdp_session_name")) if (!redis_hash_get_str(&s, rh, "sdp_session_name"))
ml->sdp_session_name = call_strdup_len(c, s.s, s.len); ml->sdp_session_name = call_strdup_len(s.s, s.len);
/* t= */ /* t= */
if (!redis_hash_get_str(&s, rh, "sdp_session_timing")) if (!redis_hash_get_str(&s, rh, "sdp_session_timing"))
ml->sdp_session_timing = call_strdup_len(c, s.s, s.len); ml->sdp_session_timing = call_strdup_len(s.s, s.len);
/* o= */ /* o= */
if (!redis_hash_get_str(&s, rh, "sdp_orig_parsed")) { if (!redis_hash_get_str(&s, rh, "sdp_orig_parsed")) {
ml->session_sdp_orig = g_slice_alloc0(sizeof(*ml->session_sdp_orig)); ml->session_sdp_orig = g_slice_alloc0(sizeof(*ml->session_sdp_orig));
@ -1595,12 +1595,12 @@ static int json_medias(call_t *c, struct redis_list *medias, struct redis_list *
return -1; return -1;
if (redis_hash_get_str(&s, rh, "type")) if (redis_hash_get_str(&s, rh, "type"))
return -1; return -1;
call_str_cpy(c, &med->type, &s); call_str_cpy(&med->type, &s);
med->type_id = codec_get_type(&med->type); med->type_id = codec_get_type(&med->type);
if (!redis_hash_get_str(&s, rh, "format_str")) if (!redis_hash_get_str(&s, rh, "format_str"))
call_str_cpy(c, &med->format_str, &s); call_str_cpy(&med->format_str, &s);
if (!redis_hash_get_str(&s, rh, "media_id")) if (!redis_hash_get_str(&s, rh, "media_id"))
call_str_cpy(c, &med->media_id, &s); call_str_cpy(&med->media_id, &s);
if (redis_hash_get_int(&med->ptime, rh, "ptime")) if (redis_hash_get_int(&med->ptime, rh, "ptime"))
return -1; return -1;
@ -2081,7 +2081,7 @@ static void json_restore_call(struct redis *r, const str *callid, bool foreign)
redis_hash_get_time_t(&c->deleted, &call, "deleted"); redis_hash_get_time_t(&c->deleted, &call, "deleted");
redis_hash_get_time_t(&c->ml_deleted, &call, "ml_deleted"); redis_hash_get_time_t(&c->ml_deleted, &call, "ml_deleted");
if (!redis_hash_get_str(&id, &call, "created_from")) if (!redis_hash_get_str(&id, &call, "created_from"))
c->created_from = call_strdup(c, id.s); c->created_from = call_strdup(id.s);
if (!redis_hash_get_str(&id, &call, "created_from_addr")) if (!redis_hash_get_str(&id, &call, "created_from_addr"))
sockaddr_parse_any_str(&c->created_from_addr, &id); sockaddr_parse_any_str(&c->created_from_addr, &id);
if (!redis_hash_get_int(&i, &call, "block_dtmf")) if (!redis_hash_get_int(&i, &call, "block_dtmf"))
@ -2127,18 +2127,18 @@ static void json_restore_call(struct redis *r, const str *callid, bool foreign)
// presence of this key determines whether we were recording at all // presence of this key determines whether we were recording at all
if (!redis_hash_get_str(&s, &call, "recording_meta_prefix")) { if (!redis_hash_get_str(&s, &call, "recording_meta_prefix")) {
call_str_cpy(c, &c->recording_meta_prefix, &s); call_str_cpy(&c->recording_meta_prefix, &s);
// coverity[check_return : FALSE] // coverity[check_return : FALSE]
redis_hash_get_str(&s, &call, "recording_metadata"); redis_hash_get_str(&s, &call, "recording_metadata");
call_str_cpy(c, &c->metadata, &s); call_str_cpy(&c->metadata, &s);
redis_hash_get_str(&s, &call, "recording_file"); redis_hash_get_str(&s, &call, "recording_file");
call_str_cpy(c, &c->recording_file, &s); call_str_cpy(&c->recording_file, &s);
redis_hash_get_str(&s, &call, "recording_path"); redis_hash_get_str(&s, &call, "recording_path");
call_str_cpy(c, &c->recording_path, &s); call_str_cpy(&c->recording_path, &s);
redis_hash_get_str(&s, &call, "recording_pattern"); redis_hash_get_str(&s, &call, "recording_pattern");
call_str_cpy(c, &c->recording_pattern, &s); call_str_cpy(&c->recording_pattern, &s);
redis_hash_get_str(&s, &call, "recording_random_tag"); redis_hash_get_str(&s, &call, "recording_random_tag");
call_str_cpy(c, &c->recording_random_tag, &s); call_str_cpy(&c->recording_random_tag, &s);
recording_start_daemon(c); recording_start_daemon(c);
} }

@ -3420,7 +3420,7 @@ int sdp_replace(struct sdp_chopper *chop, sdp_sessions_q *sessions,
err = "error while processing s= line"; err = "error while processing s= line";
if (!monologue->sdp_session_name) if (!monologue->sdp_session_name)
monologue->sdp_session_name = call_strdup_len(monologue->call, session->session_name.s, monologue->sdp_session_name = call_strdup_len(session->session_name.s,
session->session_name.len); session->session_name.len);
else if (flags->replace_sess_name) { else if (flags->replace_sess_name) {
if (copy_up_to(chop, &session->session_name)) if (copy_up_to(chop, &session->session_name))

@ -783,6 +783,7 @@ TYPED_GHASHTABLE(rtpe_calls_ht, str, struct call, str_hash, str_equal, NULL, NUL
extern rwlock_t rtpe_callhash_lock; extern rwlock_t rtpe_callhash_lock;
extern rtpe_calls_ht rtpe_callhash; extern rtpe_calls_ht rtpe_callhash;
extern struct call_iterator_list rtpe_call_iterators[NUM_CALL_ITERATORS]; extern struct call_iterator_list rtpe_call_iterators[NUM_CALL_ITERATORS];
extern __thread call_t *call_memory_arena;
@ -858,54 +859,54 @@ const rtp_payload_type *__rtp_stats_codec(struct call_media *m);
#include "str.h" #include "str.h"
#include "rtp.h" #include "rtp.h"
INLINE void *call_malloc(call_t *c, size_t l) { INLINE void *call_malloc(size_t l) {
void *ret; void *ret;
mutex_lock(&c->buffer_lock); mutex_lock(&call_memory_arena->buffer_lock);
ret = call_buffer_alloc(&c->buffer, l); ret = call_buffer_alloc(&call_memory_arena->buffer, l);
mutex_unlock(&c->buffer_lock); mutex_unlock(&call_memory_arena->buffer_lock);
return ret; return ret;
} }
INLINE char *call_strdup_len(call_t *c, const char *s, unsigned int len) { INLINE char *call_strdup_len(const char *s, unsigned int len) {
char *r; char *r;
if (!s) if (!s)
return NULL; return NULL;
r = call_malloc(c, len + 1); r = call_malloc(len + 1);
memcpy(r, s, len); memcpy(r, s, len);
r[len] = 0; r[len] = 0;
return r; return r;
} }
INLINE char *call_strdup(call_t *c, const char *s) { INLINE char *call_strdup(const char *s) {
if (!s) if (!s)
return NULL; return NULL;
return call_strdup_len(c, s, strlen(s)); return call_strdup_len(s, strlen(s));
} }
INLINE str *call_str_cpy_len(call_t *c, str *out, const char *in, int len) { INLINE str *call_str_cpy_len(str *out, const char *in, int len) {
if (!in) { if (!in) {
*out = STR_NULL; *out = STR_NULL;
return out; return out;
} }
out->s = call_strdup_len(c, in, len); out->s = call_strdup_len(in, len);
out->len = len; out->len = len;
return out; return out;
} }
INLINE str *call_str_cpy(call_t *c, str *out, const str *in) { INLINE str *call_str_cpy(str *out, const str *in) {
return call_str_cpy_len(c, out, in ? in->s : NULL, in ? in->len : 0); return call_str_cpy_len(out, in ? in->s : NULL, in ? in->len : 0);
} }
INLINE str *call_str_cpy_c(call_t *c, str *out, const char *in) { INLINE str *call_str_cpy_c(str *out, const char *in) {
return call_str_cpy_len(c, out, in, in ? strlen(in) : 0); return call_str_cpy_len(out, in, in ? strlen(in) : 0);
} }
INLINE str *call_str_dup(call_t *c, const str *in) { INLINE str *call_str_dup(const str *in) {
str *out; str *out;
out = call_malloc(c, sizeof(*out)); out = call_malloc(sizeof(*out));
call_str_cpy_len(c, out, in->s, in->len); call_str_cpy_len(out, in->s, in->len);
return out; return out;
} }
INLINE str *call_str_init_dup(call_t *c, char *s) { INLINE str *call_str_init_dup(char *s) {
str t; str t;
t = STR(s); t = STR(s);
return call_str_dup(c, &t); return call_str_dup(&t);
} }
INLINE void __call_unkernelize(call_t *call, const char *reason) { INLINE void __call_unkernelize(call_t *call, const char *reason) {
for (__auto_type l = call->monologues.head; l; l = l->next) { for (__auto_type l = call->monologues.head; l; l = l->next) {
@ -930,4 +931,15 @@ INLINE endpoint_t *packet_stream_local_addr(struct packet_stream *ps) {
return &dummy; return &dummy;
} }
INLINE void call_memory_arena_release(void) {
if (!call_memory_arena)
return;
obj_put(call_memory_arena);
call_memory_arena = NULL;
}
INLINE void call_memory_arena_set(call_t *c) {
call_memory_arena_release();
call_memory_arena = obj_get(c);
}
#endif #endif

@ -8,6 +8,7 @@
#include "ssllib.h" #include "ssllib.h"
#include "ice.h" #include "ice.h"
#include "bufferpool.h" #include "bufferpool.h"
#include "log_funcs.h"
int _log_facility_rtcp; int _log_facility_rtcp;
int _log_facility_cdr; int _log_facility_cdr;
@ -7482,6 +7483,7 @@ int main(void) {
dtls_cert_free(); dtls_cert_free();
ice_free(); ice_free();
bufferpool_destroy(shm_bufferpool); bufferpool_destroy(shm_bufferpool);
call_memory_arena_release();
bufferpool_cleanup(); bufferpool_cleanup();
return 0; return 0;

Loading…
Cancel
Save