diff --git a/daemon/call.c b/daemon/call.c index 3333d6304..09060b182 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -710,7 +710,7 @@ static struct call_media *__get_media(struct call_monologue *ml, const struct st med = call_media_new(call); med->monologue = ml; med->index = want_index; - call_str_cpy(&med->type, &sp->type); + med->type = call_str_cpy(&sp->type); med->type_id = sp->type_id; ml->medias->pdata[arr_index] = med; @@ -2183,7 +2183,7 @@ static void __dtls_logic(const sdp_ng_flags *flags, __dtls_restart(other_media); } - call_str_cpy(&other_media->tls_id, &sp->tls_id); + other_media->tls_id = call_str_cpy(&sp->tls_id); MEDIA_CLEAR(other_media, DTLS); if (MEDIA_ISSET2(other_media, SETUP_PASSIVE, SETUP_ACTIVE) @@ -2244,7 +2244,7 @@ static void __update_media_id(struct call_media *media, struct call_media *other if (!other_media->media_id.s) { // incoming side: we copy what we received if (sp->media_id.s) - call_str_cpy(&other_media->media_id, &sp->media_id); + other_media->media_id = call_str_cpy(&sp->media_id); if (other_media->media_id.s) g_hash_table_insert(other_ml->media_ids, &other_media->media_id, other_media); @@ -2256,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)) { // mismatch - update g_hash_table_remove(other_ml->media_ids, &other_media->media_id); - call_str_cpy(&other_media->media_id, &sp->media_id); + other_media->media_id = call_str_cpy(&sp->media_id); g_hash_table_insert(other_ml->media_ids, &other_media->media_id, other_media); } @@ -2270,12 +2270,12 @@ static void __update_media_id(struct call_media *media, struct call_media *other if (media && !media->media_id.s) { // outgoing side: we copy from the other side if (other_media->media_id.s) - call_str_cpy(&media->media_id, &other_media->media_id); + media->media_id = call_str_cpy(&other_media->media_id); else if (flags->generate_mid) { // or generate one char buf[64]; snprintf(buf, sizeof(buf), "%u", other_media->index); - call_str_cpy_c(&media->media_id, buf); + media->media_id = call_str_cpy_c(buf); } if (media->media_id.s) g_hash_table_insert(ml->media_ids, &media->media_id, media); @@ -2313,8 +2313,8 @@ static void __t38_reset(struct call_media *media, struct call_media *other_media media->protocol = other_media->protocol; media->type_id = other_media->type_id; - call_str_cpy(&media->type, &other_media->type); - call_str_cpy(&media->format_str, &other_media->format_str); + media->type = call_str_cpy(&other_media->type); + media->format_str = call_str_cpy(&other_media->format_str); } __attribute__((nonnull(2, 3, 4))) @@ -2325,16 +2325,16 @@ static void __update_media_protocol(struct call_media *media, struct call_media if (str_cmp_str(&other_media->type, &sp->type)) { ilog(LOG_DEBUG, "Updating media type from '" STR_FORMAT "' to '" STR_FORMAT "'", STR_FMT(&other_media->type), STR_FMT(&sp->type)); - call_str_cpy(&other_media->type, &sp->type); + other_media->type = call_str_cpy(&sp->type); other_media->type_id = codec_get_type(&other_media->type); if (media) { - call_str_cpy(&media->type, &sp->type); + media->type = call_str_cpy(&sp->type); media->type_id = other_media->type_id; } } /* deduct protocol from stream parameters received */ - call_str_cpy(&other_media->protocol_str, &sp->protocol_str); + other_media->protocol_str = call_str_cpy(&sp->protocol_str); if (other_media->protocol != sp->protocol) { other_media->protocol = sp->protocol; @@ -2376,7 +2376,7 @@ static void __update_media_protocol(struct call_media *media, struct call_media media->protocol = other_media->protocol; if (media && !media->protocol_str.s) - call_str_cpy(&media->protocol_str, &other_media->protocol_str); + media->protocol_str = call_str_cpy(&other_media->protocol_str); // handler overrides requested by the user @@ -2401,7 +2401,7 @@ static void __update_media_protocol(struct call_media *media, struct call_media if (!media->protocol) media->protocol = &transport_protocols[PROTO_RTP_AVP]; media->type_id = MT_AUDIO; - call_str_cpy_c(&media->type, "audio"); + media->type = call_str_cpy_c("audio"); return; } @@ -2411,8 +2411,8 @@ static void __update_media_protocol(struct call_media *media, struct call_media { media->protocol = &transport_protocols[PROTO_UDPTL]; media->type_id = MT_IMAGE; - call_str_cpy_c(&media->type, "image"); - call_str_cpy_c(&media->format_str, "t38"); + media->type = call_str_cpy_c("image"); + media->format_str = call_str_cpy_c("t38"); return; } @@ -2703,7 +2703,7 @@ static void __call_monologue_init_from_flags(struct call_monologue *ml, struct c __tos_change(call, flags); if (flags->label.s) { - call_str_cpy(&ml->label, &flags->label); + ml->label = call_str_cpy(&flags->label); t_hash_table_replace(call->labels, &ml->label, ml); } @@ -2755,7 +2755,7 @@ static void __update_media_label(struct call_media *media, struct call_media *ot if (!media->label.len) { char buf[64]; snprintf(buf, sizeof(buf), "%u", other_media->unique_id); - call_str_cpy_c(&media->label, buf); + media->label = call_str_cpy_c(buf); } // put same label on both sides if (!other_media->label.len) @@ -2882,11 +2882,11 @@ static void __media_init_from_flags(struct call_media *other_media, struct call_ MEDIA_SET(other_media, PTIME_OVERRIDE); } if (str_cmp_str(&other_media->format_str, &sp->format_str)) - call_str_cpy(&other_media->format_str, &sp->format_str); + other_media->format_str = call_str_cpy(&sp->format_str); if (media && str_cmp_str(&media->format_str, &sp->format_str)) { // update opposite side format string only if protocols match if (media->protocol == other_media->protocol) - call_str_cpy(&media->format_str, &sp->format_str); + media->format_str = call_str_cpy(&sp->format_str); } /* deduct address family from stream parameters received */ @@ -4113,7 +4113,7 @@ static call_t *call_create(const str *callid) { c->viabranches = tags_ht_new(); c->labels = labels_ht_new(); call_memory_arena_set(c); - call_str_cpy(&c->callid, callid); + c->callid = call_str_cpy(callid); c->created = rtpe_now; c->dtls_cert = dtls_cert(); c->tos = rtpe_config.default_tos; @@ -4276,7 +4276,7 @@ void __monologue_tag(struct call_monologue *ml, const str *tag) { __C_DBG("tagging monologue with '"STR_FORMAT"'", STR_FMT(tag)); if (ml->tag.s) t_hash_table_remove(call->tags, &ml->tag); /* remove tag from tags of the call object */ - call_str_cpy(&ml->tag, tag); + ml->tag = call_str_cpy(tag); t_hash_table_insert(call->tags, &ml->tag, ml); /* and insert a new one */ } @@ -4289,7 +4289,7 @@ void __monologue_viabranch(struct call_monologue *ml, const str *viabranch) { __C_DBG("tagging monologue with viabranch '"STR_FORMAT"'", STR_FMT(viabranch)); if (ml->viabranch.s) t_hash_table_remove(call->viabranches, &ml->viabranch); - call_str_cpy(&ml->viabranch, viabranch); + ml->viabranch = call_str_cpy(viabranch); t_hash_table_insert(call->viabranches, &ml->viabranch, ml); } diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index aa9ff6dfd..6d0bc83ef 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -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 if (IS_OP_OTHER(opmode) && flags->set_label.len && *monologue) { - call_str_cpy(&(*monologue)->label, &flags->set_label); + (*monologue)->label = call_str_cpy(&flags->set_label); t_hash_table_replace((*call)->labels, &(*monologue)->label, *monologue); } diff --git a/daemon/dtmf.c b/daemon/dtmf.c index e7adcaa33..1b1b06a2a 100644 --- a/daemon/dtmf.c +++ b/daemon/dtmf.c @@ -311,7 +311,7 @@ void dtmf_trigger_set(struct call_monologue *ml, enum dtmf_trigger_type trigger_ dtmf_trigger_types[trigger_type], (unsigned int) (state - ml->dtmf_trigger_state), STR_FMT(s)); - call_str_cpy(&state->trigger, s); + state->trigger = call_str_cpy(s); state->matched = 0; state->inactive = inactive; } diff --git a/daemon/ice.c b/daemon/ice.c index e3341e8c3..56a7d4c0c 100644 --- a/daemon/ice.c +++ b/daemon/ice.c @@ -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) { int eq = (dst->priority == src->priority); *dst = *src; - call_str_cpy(&dst->foundation, &src->foundation); + dst->foundation = call_str_cpy(&src->foundation); 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 */ if (sp->ice_ufrag.s) - call_str_cpy(&ag->ufrag[0], &sp->ice_ufrag); + ag->ufrag[0] = call_str_cpy(&sp->ice_ufrag); if (sp->ice_pwd.s) - call_str_cpy(&ag->pwd[0], &sp->ice_pwd); + ag->pwd[0] = call_str_cpy(&sp->ice_pwd); 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), cand->type, g_direct_hash(cand->transport)); - call_str_cpy_len(&cand->foundation, buf, len); + cand->foundation = call_str_cpy_len(buf, len); } /* agent must be locked */ @@ -1551,7 +1551,7 @@ static void create_random_ice_string(call_t *call, str *s, int len) { return; random_ice_string(buf, len); - call_str_cpy_len(s, buf, len); + *s = call_str_cpy_len(buf, len); } void ice_foundation(str *s) { diff --git a/daemon/recording.c b/daemon/recording.c index 170df1f38..e9a46818a 100644 --- a/daemon/recording.c +++ b/daemon/recording.c @@ -276,7 +276,7 @@ static void update_call_field(call_t *call, str *dst_field, const str *src_field return; if (src_field && src_field->len && str_cmp_str(src_field, dst_field)) - call_str_cpy(dst_field, src_field); + *dst_field = call_str_cpy(src_field); if (call->recording && dst_field->len) { va_list ap; @@ -368,8 +368,8 @@ void recording_start_daemon(call_t *call) { char rand_str[rand_bytes * 2 + 1]; rand_hex_str(rand_str, rand_bytes); g_autoptr(char) meta_prefix = g_strdup_printf("%s-%s", escaped_callid, rand_str); - call_str_cpy(&call->recording_meta_prefix, &STR(meta_prefix)); - call_str_cpy(&call->recording_random_tag, &STR_CONST(rand_str)); + call->recording_meta_prefix = call_str_cpy(&STR(meta_prefix)); + call->recording_random_tag = call_str_cpy(&STR_CONST(rand_str)); } _rm(init_struct, call); diff --git a/daemon/redis.c b/daemon/redis.c index 0bd1f69a5..47a25a2a4 100644 --- a/daemon/redis.c +++ b/daemon/redis.c @@ -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")) __monologue_viabranch(ml, &s); if (!redis_hash_get_str(&s, rh, "label")) - call_str_cpy(&ml->label, &s); + ml->label = call_str_cpy(&s); if (!redis_hash_get_str(&s, rh, "metadata")) - call_str_cpy(&c->metadata, &s); + c->metadata = call_str_cpy(&s); redis_hash_get_time_t(&ml->deleted, rh, "deleted"); if (!redis_hash_get_int(&ii, rh, "block_dtmf")) ml->block_dtmf = ii; @@ -1595,12 +1595,12 @@ static int json_medias(call_t *c, struct redis_list *medias, struct redis_list * return -1; if (redis_hash_get_str(&s, rh, "type")) return -1; - call_str_cpy(&med->type, &s); + med->type = call_str_cpy(&s); med->type_id = codec_get_type(&med->type); if (!redis_hash_get_str(&s, rh, "format_str")) - call_str_cpy(&med->format_str, &s); + med->format_str = call_str_cpy(&s); if (!redis_hash_get_str(&s, rh, "media_id")) - call_str_cpy(&med->media_id, &s); + med->media_id = call_str_cpy(&s); if (redis_hash_get_int(&med->ptime, rh, "ptime")) return -1; @@ -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 if (!redis_hash_get_str(&s, &call, "recording_meta_prefix")) { - call_str_cpy(&c->recording_meta_prefix, &s); + c->recording_meta_prefix = call_str_cpy(&s); // coverity[check_return : FALSE] redis_hash_get_str(&s, &call, "recording_metadata"); - call_str_cpy(&c->metadata, &s); + c->metadata = call_str_cpy(&s); redis_hash_get_str(&s, &call, "recording_file"); - call_str_cpy(&c->recording_file, &s); + c->recording_file = call_str_cpy(&s); redis_hash_get_str(&s, &call, "recording_path"); - call_str_cpy(&c->recording_path, &s); + c->recording_path = call_str_cpy(&s); redis_hash_get_str(&s, &call, "recording_pattern"); - call_str_cpy(&c->recording_pattern, &s); + c->recording_pattern = call_str_cpy(&s); redis_hash_get_str(&s, &call, "recording_random_tag"); - call_str_cpy(&c->recording_random_tag, &s); + c->recording_random_tag = call_str_cpy(&s); recording_start_daemon(c); } diff --git a/include/call.h b/include/call.h index 022477a9e..11538787a 100644 --- a/include/call.h +++ b/include/call.h @@ -882,25 +882,26 @@ INLINE char *call_strdup(const char *s) { return NULL; return call_strdup_len(s, strlen(s)); } -INLINE str *call_str_cpy_len(str *out, const char *in, int len) { +INLINE str call_str_cpy_len(const char *in, int len) { + str out; if (!in) { - *out = STR_NULL; + out = STR_NULL; return out; } - out->s = call_strdup_len(in, len); - out->len = len; + out.s = call_strdup_len(in, len); + out.len = len; return out; } -INLINE str *call_str_cpy(str *out, const str *in) { - return call_str_cpy_len(out, in ? in->s : NULL, in ? in->len : 0); +INLINE str call_str_cpy(const str *in) { + return call_str_cpy_len(in ? in->s : NULL, in ? in->len : 0); } -INLINE str *call_str_cpy_c(str *out, const char *in) { - return call_str_cpy_len(out, in, in ? strlen(in) : 0); +INLINE str call_str_cpy_c(const char *in) { + return call_str_cpy_len(in, in ? strlen(in) : 0); } INLINE str *call_str_dup(const str *in) { str *out; out = call_malloc(sizeof(*out)); - call_str_cpy_len(out, in->s, in->len); + *out = call_str_cpy_len(in->s, in->len); return out; } INLINE str *call_str_init_dup(char *s) {