diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index 39f2d54df..38bad52a5 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -147,9 +147,9 @@ static int addr_parse_udp(struct stream_params *sp, char **out) { for (cp =out[RE_UDP_UL_FLAGS]; *cp && i < 2; cp++) { c = chrtoupper(*cp); if (c == 'E') - str_init(&sp->direction[i++], "external"); + sp->direction[i++] = STR("external"); else if (c == 'I') - str_init(&sp->direction[i++], "internal"); + sp->direction[i++] = STR("internal"); } } @@ -188,9 +188,9 @@ static str *call_update_lookup_udp(char **out, enum call_opmode opmode, const ch g_auto(sdp_ng_flags) flags; call_ng_flags_init(&flags, opmode); - str callid = STR_INIT(out[RE_UDP_UL_CALLID]); - str fromtag = STR_INIT(out[RE_UDP_UL_FROMTAG]); - str totag = STR_INIT(out[RE_UDP_UL_TOTAG]); + str callid = STR(out[RE_UDP_UL_CALLID]); + str fromtag = STR(out[RE_UDP_UL_FROMTAG]); + str totag = STR(out[RE_UDP_UL_TOTAG]); if (opmode == OP_ANSWER) str_swap(&fromtag, &totag); @@ -342,7 +342,7 @@ static str *call_request_lookup_tcp(char **out, enum call_opmode opmode) { g_auto(sdp_ng_flags) flags; call_ng_flags_init(&flags, opmode); - str callid = STR_INIT(out[RE_TCP_RL_CALLID]); + str callid = STR(out[RE_TCP_RL_CALLID]); infohash = g_hash_table_new_full(g_str_hash, g_str_equal, free, free); c = call_get_opmode(&callid, opmode); if (!c) { @@ -352,12 +352,12 @@ static str *call_request_lookup_tcp(char **out, enum call_opmode opmode) { info_parse(out[RE_TCP_RL_INFO], infohash); streams_parse(out[RE_TCP_RL_STREAMS], &s); - str fromtag = STR_INIT(g_hash_table_lookup(infohash, "fromtag")); + str fromtag = STR(g_hash_table_lookup(infohash, "fromtag")); if (!fromtag.s) { ilog(LOG_WARNING, "No from-tag in message"); goto out2; } - str totag = STR_INIT(g_hash_table_lookup(infohash, "totag")); + str totag = STR(g_hash_table_lookup(infohash, "totag")); if (opmode == OP_ANSWER) { if (!totag.s) { ilog(LOG_WARNING, "No to-tag in message"); @@ -395,10 +395,10 @@ str *call_delete_udp(char **out) { __C_DBG("got delete for callid '%s' and viabranch '%s'", out[RE_UDP_DQ_CALLID], out[RE_UDP_DQ_VIABRANCH]); - str callid = STR_INIT(out[RE_UDP_DQ_CALLID]); - str branch = STR_INIT(out[RE_UDP_DQ_VIABRANCH]); - str fromtag = STR_INIT(out[RE_UDP_DQ_FROMTAG]); - str totag = STR_INIT(out[RE_UDP_DQ_TOTAG]); + str callid = STR(out[RE_UDP_DQ_CALLID]); + str branch = STR(out[RE_UDP_DQ_VIABRANCH]); + str fromtag = STR(out[RE_UDP_DQ_FROMTAG]); + str totag = STR(out[RE_UDP_DQ_TOTAG]); if (call_delete_branch_by_id(&callid, &branch, &fromtag, &totag, NULL, -1)) return str_sprintf("%s E8\n", out[RE_UDP_COOKIE]); @@ -412,9 +412,9 @@ str *call_query_udp(char **out) { __C_DBG("got query for callid '%s'", out[RE_UDP_DQ_CALLID]); - str callid = STR_INIT(out[RE_UDP_DQ_CALLID]); - str fromtag = STR_INIT(out[RE_UDP_DQ_FROMTAG]); - str totag = STR_INIT(out[RE_UDP_DQ_TOTAG]); + str callid = STR(out[RE_UDP_DQ_CALLID]); + str fromtag = STR(out[RE_UDP_DQ_FROMTAG]); + str totag = STR(out[RE_UDP_DQ_TOTAG]); c = call_get_opmode(&callid, OP_QUERY); if (!c) { @@ -439,7 +439,7 @@ out: } void call_delete_tcp(char **out) { - str callid = STR_INIT(out[RE_TCP_D_CALLID]); + str callid = STR(out[RE_TCP_D_CALLID]); call_delete_branch_by_id(&callid, NULL, NULL, NULL, NULL, -1); } diff --git a/daemon/cli.c b/daemon/cli.c index d9ec71fee..be1e7b80e 100644 --- a/daemon/cli.c +++ b/daemon/cli.c @@ -1210,7 +1210,7 @@ static void cli_stream_readable(struct streambuf_stream *s) { return; } - str_init(&instr, inbuf); + instr = STR(inbuf); struct cli_writer cw = { .cw_printf = cli_streambuf_printf, diff --git a/daemon/codec.c b/daemon/codec.c index 87abb2b20..302d0853f 100644 --- a/daemon/codec.c +++ b/daemon/codec.c @@ -776,9 +776,9 @@ static void __check_dtmf_injector(struct call_media *receiver, struct call_media .clock_rate = parent->source_pt.clock_rate, .channels = parent->source_pt.channels, }; - str_init(&src_pt.encoding, "DTMF injector"); - str_init(&src_pt.encoding_with_params, "DTMF injector"); - str_init(&src_pt.encoding_with_full_params, "DTMF injector"); + src_pt.encoding = STR("DTMF injector"); + src_pt.encoding_with_params = STR("DTMF injector"); + src_pt.encoding_with_full_params = STR("DTMF injector"); static const str tp_event = STR_CONST_INIT("telephone-event"); src_pt.codec_def = codec_find(&tp_event, MT_AUDIO); if (!src_pt.codec_def) { @@ -2517,7 +2517,7 @@ void codec_init_payload_type(rtp_payload_type *pt, enum media_type type) { if (pt->ptime <= 0) pt->ptime = def->default_ptime; if (!pt->format_parameters.s && def->default_fmtp) - str_init(&pt->format_parameters, (char *) def->default_fmtp); + pt->format_parameters = STR(def->default_fmtp); codec_parse_fmtp(def, &pt->format, &pt->format_parameters, NULL); @@ -4875,7 +4875,7 @@ void codec_tracker_update(struct codec_store *cs, struct codec_store *orig_cs) { g_autoptr(char) pt_s = g_strdup_printf(STR_FORMAT "/%u", STR_FMT(supp_codec), clockrate); - str pt_str = STR_INIT(pt_s); + str pt_str = STR(pt_s); // see if we have a matching PT from before rtp_payload_type *pt = NULL; diff --git a/daemon/control_ng_flags_parser.c b/daemon/control_ng_flags_parser.c index b09d74ffe..ae51bb143 100644 --- a/daemon/control_ng_flags_parser.c +++ b/daemon/control_ng_flags_parser.c @@ -158,7 +158,7 @@ static bool parse_codec_to_dict(str * key, str * val, const char *cmp1, const ch return false; } - call_ng_codec_flags(out, &STR_INIT(dictstr), bencode_str(buf, &s), opmode); + call_ng_codec_flags(out, &STR(dictstr), bencode_str(buf, &s), opmode); return true; } diff --git a/daemon/control_udp.c b/daemon/control_udp.c index 4c53cbcdc..d227c43e1 100644 --- a/daemon/control_udp.c +++ b/daemon/control_udp.c @@ -71,7 +71,7 @@ static void control_udp_incoming(struct obj *obj, struct udp_buffer *udp_buf) { pcre2_substring_list_get(md, (PCRE2_UCHAR ***) &out, NULL); - str_init(&cookie, (void *) out[RE_UDP_COOKIE]); + cookie = STR(out[RE_UDP_COOKIE]); ce = cookie_cache_lookup(&u->cookie_cache, &cookie); if (ce) { reply = ce->reply; diff --git a/daemon/crypto.c b/daemon/crypto.c index c90ebce0c..5f8ad32b0 100644 --- a/daemon/crypto.c +++ b/daemon/crypto.c @@ -997,7 +997,7 @@ void crypto_init_main(void) { for (unsigned int i = 0; i < num_crypto_suites; i++) { cs = &__crypto_suites[i]; cs->idx = i; - str_init(&cs->name_str, (char *) cs->name); + cs->name_str = STR(cs->name); switch(cs->master_key_len) { case 16: cs->aes_evp = EVP_aes_128_ecb(); diff --git a/daemon/janus.c b/daemon/janus.c index cc310c070..f202a78c7 100644 --- a/daemon/janus.c +++ b/daemon/janus.c @@ -121,7 +121,7 @@ static struct call_monologue *janus_get_monologue(uint64_t handle_id, call_t *ca { g_autoptr(char) handle_buf = NULL; handle_buf = g_strdup_printf("%" PRIu64, handle_id); - str handle_str = STR_INIT(handle_buf); + str handle_str = STR(handle_buf); return fn(call, &handle_str); } @@ -1083,7 +1083,7 @@ static const char *janus_videoroom(struct websocket_message *wm, struct janus_se const char *req = json_reader_get_string_value(reader); if (!req) goto err; - str req_str = STR_INIT(req); + str req_str = STR(req); json_reader_end_member(reader); switch (__csh_lookup(&req_str)) { @@ -1787,7 +1787,7 @@ static const char *websocket_janus_process_json(struct websocket_message *wm, ilog(LOG_DEBUG, "Processing '%s' type Janus message", janus_cmd); - str janus_cmd_str = STR_INIT(janus_cmd); + str janus_cmd_str = STR(janus_cmd); err = NULL; @@ -1902,7 +1902,7 @@ const char *websocket_janus_process(struct websocket_message *wm) { const char *websocket_janus_get(struct websocket_message *wm) { - str uri = STR_INIT(wm->uri); + str uri = STR(wm->uri); ilog(LOG_DEBUG, "Processing Janus GET: '%s'", wm->uri); @@ -1935,7 +1935,7 @@ const char *websocket_janus_get(struct websocket_message *wm) { const char *websocket_janus_post(struct websocket_message *wm) { - str uri = STR_INIT(wm->uri); + str uri = STR(wm->uri); ilog(LOG_DEBUG, "Processing Janus POST: '%s'", wm->uri); diff --git a/daemon/main.c b/daemon/main.c index 55f1ec24a..9a7d3a7d1 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -280,7 +280,7 @@ static int if_addr_parse(intf_config_q *q, char *s, struct ifaddrs *ifas) { if (c) { char cc = *c; *c++ = 0; - str_init(&name, s); + name = STR(s); s = c; if (cc == '=') { // foo=bar @@ -292,7 +292,7 @@ static int if_addr_parse(intf_config_q *q, char *s, struct ifaddrs *ifas) { } } else - str_init(&name, "default"); + name = STR("default"); /* advertised address */ c = strchr(s, '!'); diff --git a/daemon/recording.c b/daemon/recording.c index ea60ec894..5d6c7c3d2 100644 --- a/daemon/recording.c +++ b/daemon/recording.c @@ -369,7 +369,7 @@ 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, &call->recording_meta_prefix, &STR_INIT(meta_prefix)); + call_str_cpy(call, &call->recording_meta_prefix, &STR(meta_prefix)); call_str_cpy(call, &call->recording_random_tag, &STR_CONST_INIT(rand_str)); } diff --git a/daemon/redis.c b/daemon/redis.c index e52851e47..684cfdadb 100644 --- a/daemon/redis.c +++ b/daemon/redis.c @@ -72,14 +72,14 @@ static int redisCommandNR(redisContext *r, const char *fmt, ...) __attribute__((format(printf,2,3))); #define PB "%.*s" -#define STR(x) (int) (x)->len, (x)->s +#define PBSTR(x) (int) (x)->len, (x)->s #define STR_R(x) (int) (x)->len, (x)->str #define S_LEN(s,l) (int) (l), (s) #else #define PB "%b" -#define STR(x) (x)->s, (size_t) (x)->len +#define PBSTR(x) (x)->s, (size_t) (x)->len #define STR_R(x) (x)->str, (size_t) (x)->len #define S_LEN(s,l) (s), (size_t) (l) @@ -986,7 +986,7 @@ static int redis_check_conn(struct redis *r) { /* called with r->lock held and c->master_lock held */ static void redis_delete_call_json(call_t *c, struct redis *r) { - redis_pipe(r, "DEL "PB"", STR(&c->callid)); + redis_pipe(r, "DEL "PB"", PBSTR(&c->callid)); redis_consume(r); } @@ -2006,7 +2006,7 @@ static void json_restore_call(struct redis *r, const str *callid, bool foreign) JsonParser *parser =0; mutex_lock(&r->lock); - rr_jsonStr = redis_get(r, REDIS_REPLY_STRING, "GET " PB, STR(callid)); + rr_jsonStr = redis_get(r, REDIS_REPLY_STRING, "GET " PB, PBSTR(callid)); mutex_unlock(&r->lock); bool must_release_pop = true; @@ -2188,12 +2188,12 @@ err1: must_release_pop = false; mutex_lock(&rtpe_redis_write->lock); - redisCommandNR(rtpe_redis_write->ctx, "DEL " PB, STR(callid)); + redisCommandNR(rtpe_redis_write->ctx, "DEL " PB, PBSTR(callid)); mutex_unlock(&rtpe_redis_write->lock); if (rtpe_redis_notify) { mutex_lock(&rtpe_redis_notify->lock); - redisCommandNR(rtpe_redis_notify->ctx, "DEL " PB, STR(callid)); + redisCommandNR(rtpe_redis_notify->ctx, "DEL " PB, PBSTR(callid)); mutex_unlock(&rtpe_redis_notify->lock); } } @@ -2815,8 +2815,8 @@ void redis_update_onekey(call_t *c, struct redis *r) { if (!result) goto err; - redis_pipe(r, "SET "PB" %s", STR(&c->callid), result); - redis_pipe(r, "EXPIRE "PB" %i", STR(&c->callid), redis_expires_s); + redis_pipe(r, "SET "PB" %s", PBSTR(&c->callid), result); + redis_pipe(r, "EXPIRE "PB" %i", PBSTR(&c->callid), redis_expires_s); redis_consume(r); diff --git a/daemon/sdp.c b/daemon/sdp.c index e1338dc05..54cc8e2f8 100644 --- a/daemon/sdp.c +++ b/daemon/sdp.c @@ -331,7 +331,7 @@ static bool sdp_manipulate_remove(struct sdp_manipulations * sdp_manipulations, */ static bool sdp_manipulate_remove_c(const char *attr_name, const sdp_ng_flags *flags, enum media_type media_type) { struct sdp_manipulations *sdp_manipulations = sdp_manipulations_get_by_id(flags, media_type); - return sdp_manipulate_remove(sdp_manipulations, &STR_INIT(attr_name)); + return sdp_manipulate_remove(sdp_manipulations, &STR(attr_name)); } /** @@ -433,7 +433,7 @@ void sdp_append_str_attr(GString *s, const sdp_ng_flags *flags, enum media_type INLINE void append_attr_to_gstring(GString *s, const char * name, const str * value, const sdp_ng_flags *flags, enum media_type media_type) { - append_str_attr_to_gstring(s, &STR_INIT(name), value, flags, media_type); + append_str_attr_to_gstring(s, &STR(name), value, flags, media_type); } INLINE struct sdp_attribute *attr_get_by_id(struct sdp_attributes *a, enum attr_id id) { return t_hash_table_lookup(a->id_hash, &id); @@ -2785,13 +2785,13 @@ static void insert_dtls(GString *s, struct call_media *media, struct dtls_connec assert(hf->num_bytes > 0); if (MEDIA_ARESET2(media, SETUP_PASSIVE, SETUP_ACTIVE)) - str_init(&actpass_str, "actpass"); + actpass_str = STR("actpass"); else if (MEDIA_ISSET(media, SETUP_PASSIVE)) - str_init(&actpass_str, "passive"); + actpass_str = STR("passive"); else if (MEDIA_ISSET(media, SETUP_ACTIVE)) - str_init(&actpass_str, "active"); + actpass_str = STR("active"); else - str_init(&actpass_str, "holdconn"); + actpass_str = STR("holdconn"); append_attr_to_gstring(s, "setup", &actpass_str, flags, media->type_id); @@ -3462,7 +3462,6 @@ static void sdp_out_add_origin(GString *out, struct call_monologue *monologue, struct packet_stream *first_ps, sdp_ng_flags *flags) { struct call_monologue *ml = monologue; - str a, a_type; /* for the offer/answer model or subscribe don't use the given monologues SDP, * but try the one of the subscription, because the given monologue itself @@ -3486,17 +3485,15 @@ static void sdp_out_add_origin(GString *out, struct call_monologue *monologue, ml->session_last_sdp_orig->version_num : ml->session_sdp_orig->version_num; /* orig IP family and address */ - str * orig_address_type; - str * orig_address; + str orig_address_type; + str orig_address; if (!ms || flags->replace_origin || flags->replace_origin_full) { /* replacing flags or PUBLISH */ - str_init(&a_type, (char *)first_ps->selected_sfd->local_intf->advertised_address.addr.family->rfc_name); - str_init(&a, sockaddr_print_buf(&first_ps->selected_sfd->local_intf->advertised_address.addr)); - orig_address_type = &a_type; - orig_address = &a; + orig_address_type = STR(first_ps->selected_sfd->local_intf->advertised_address.addr.family->rfc_name); + orig_address = STR(sockaddr_print_buf(&first_ps->selected_sfd->local_intf->advertised_address.addr)); } else { - orig_address_type = &ml->session_sdp_orig->address.address_type; - orig_address = &ml->session_sdp_orig->address.address; + orig_address_type = ml->session_sdp_orig->address.address_type; + orig_address = ml->session_sdp_orig->address.address; } g_string_append_printf(out, @@ -3504,8 +3501,8 @@ static void sdp_out_add_origin(GString *out, struct call_monologue *monologue, STR_FMT(orig_username), STR_FMT(orig_session_id), orig_session_version, - STR_FMT(orig_address_type), - STR_FMT(orig_address)); + STR_FMT(&orig_address_type), + STR_FMT(&orig_address)); } static void sdp_out_add_session_name(GString *out, struct call_monologue *monologue, diff --git a/daemon/t38.c b/daemon/t38.c index f07c4232e..f723b19a0 100644 --- a/daemon/t38.c +++ b/daemon/t38.c @@ -392,7 +392,7 @@ int t38_gateway_pair(struct call_media *t38_media, struct call_media *pcm_media, tg->options = opts; tg->pcm_pt.payload_type = -1; - str_init(&tg->pcm_pt.encoding, "PCM-S16LE"); + tg->pcm_pt.encoding = STR("PCM-S16LE"); tg->pcm_pt.encoding_with_params = tg->pcm_pt.encoding; tg->pcm_pt.clock_rate = 8000; tg->pcm_pt.channels = 1; diff --git a/daemon/websocket.c b/daemon/websocket.c index 363054506..9d98c7de7 100644 --- a/daemon/websocket.c +++ b/daemon/websocket.c @@ -440,7 +440,7 @@ static const char *websocket_http_cli(struct websocket_message *wm) { ilogs(http, LOG_DEBUG, "Respoding to GET /cli/%s", uri); - str uri_cmd = STR_INIT(uri); + str uri_cmd = STR(uri); struct cli_writer cw = { .cw_printf = websocket_queue_printf, diff --git a/include/call.h b/include/call.h index 009a2b9af..766bff413 100644 --- a/include/call.h +++ b/include/call.h @@ -918,7 +918,7 @@ INLINE str *call_str_dup(call_t *c, const str *in) { } INLINE str *call_str_init_dup(call_t *c, char *s) { str t; - str_init(&t, s); + t = STR(s); return call_str_dup(c, &t); } INLINE void __call_unkernelize(call_t *call, const char *reason) { diff --git a/include/sdp.h b/include/sdp.h index 511e852c3..24e8e987d 100644 --- a/include/sdp.h +++ b/include/sdp.h @@ -54,7 +54,7 @@ sdp_attr_print_f sdp_insert_monologue_attributes; void sdp_append_str_attr(GString *s, const sdp_ng_flags *flags, enum media_type media_type, const str *name, const char *fmt, ...) __attribute__ ((format (printf, 5, 6))); -#define sdp_append_attr(s, g, t, n, f, ...) sdp_append_str_attr(s, g, t, &STR_INIT(n), f, ##__VA_ARGS__) +#define sdp_append_attr(s, g, t, n, f, ...) sdp_append_str_attr(s, g, t, &STR(n), f, ##__VA_ARGS__) void sdp_attr_free(struct sdp_attr *); sdp_origin *sdp_orig_dup(const sdp_origin *orig); diff --git a/lib/codeclib.c b/lib/codeclib.c index 726083cf4..f6c6ac27b 100644 --- a/lib/codeclib.c +++ b/lib/codeclib.c @@ -1589,7 +1589,7 @@ void codeclib_init(int print) { for (int i = 0; i < G_N_ELEMENTS(__codec_defs); i++) { // add to hash table struct codec_def_s *def = &__codec_defs[i]; - str_init(&def->rtpname_str, (char *) def->rtpname); + def->rtpname_str = STR(def->rtpname); assert(g_hash_table_lookup(codecs_ht, &def->rtpname_str) == NULL); g_hash_table_insert(codecs_ht, &def->rtpname_str, def); diff --git a/lib/str.h b/lib/str.h index d0cf3f61e..c563be8ea 100644 --- a/lib/str.h +++ b/lib/str.h @@ -37,7 +37,7 @@ TYPED_GQUEUE(str, str) #define STR_NULL ((str) { NULL, 0 }) #define STR_EMPTY ((str) { "", 0 }) #define STR_CONST_INIT(s) ((str) { s, sizeof(s)-1 }) -#define STR_INIT(s) ((str) { (char *) (s), (s) ? strlen(s) : 0 }) +#define STR(s) ((str) { (char *) (s), (s) ? strlen(s) : 0 }) #define STR_INIT_GS(s) ((str) { (s)->str, (s)->len }) #define STR_INIT_LEN(s, len) ((str) { (char *) (s), len }) #define STR_INIT_DUP(s) ((str) { g_strdup(s), strlen(s) }) @@ -81,10 +81,6 @@ 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. returns out */ -__attribute__((nonnull(1))) -ACCESS(write_only, 1) -INLINE str *str_init(str *out, char *s); /* inits a str object from any binary string. returns out */ __attribute__((nonnull(1, 2))) ACCESS(write_only, 1) @@ -305,11 +301,6 @@ INLINE int str_cmp_str0(const str *a, const str *b) { } return str_cmp_str(a, b); } -INLINE str *str_init(str *out, char *s) { - out->s = s; - out->len = s ? strlen(s) : 0; - return out; -} INLINE str *str_init_len(str *out, char *s, size_t len) { out->s = s; out->len = len; diff --git a/perf-tester/main.c b/perf-tester/main.c index 4777659ba..bc91300fd 100644 --- a/perf-tester/main.c +++ b/perf-tester/main.c @@ -653,7 +653,7 @@ static void show_popup(const char *fmt, ...) { // split into lines and get max line length GQueue lines = G_QUEUE_INIT; - str st = STR_INIT(s); + str st = STR(s); str token; uint llen = 0; while (str_token_sep(&token, &st, '\n')) { @@ -1929,10 +1929,10 @@ int main(int argc, char **argv) { if (!rtpe_poller) die("Failed to create poller"); - decoder_def = codec_find(&STR_INIT(source_codec), MT_AUDIO); + decoder_def = codec_find(&STR(source_codec), MT_AUDIO); if (!decoder_def) die("Codec definition for source codec not found"); - encoder_def = codec_find(&STR_INIT(dest_codec), MT_AUDIO); + encoder_def = codec_find(&STR(dest_codec), MT_AUDIO); if (!encoder_def) die("Codec definition for destination codec not found"); diff --git a/recording-daemon/decoder.c b/recording-daemon/decoder.c index 715796a6a..56e431567 100644 --- a/recording-daemon/decoder.c +++ b/recording-daemon/decoder.c @@ -82,7 +82,7 @@ decode_t *decoder_new(const char *payload_str, const char *format, int ptime, ou else out_format.format = AV_SAMPLE_FMT_S16; // needed for TLS-only scenarios - str fmtp = STR_INIT(format); + str fmtp = STR(format); decoder_t *dec = decoder_new_fmtp(def, rtp_clockrate, channels, ptime, &out_format, NULL, &fmtp, NULL); if (!dec) diff --git a/recording-daemon/metafile.c b/recording-daemon/metafile.c index 9ce7bd295..6c7d1ab62 100644 --- a/recording-daemon/metafile.c +++ b/recording-daemon/metafile.c @@ -173,7 +173,7 @@ static void meta_ptime(metafile_t *mf, unsigned long mnum, int ptime) static void meta_metadata_parse(metafile_t *mf) { // XXX offload this parsing to proxy module -> bencode list/dictionary t_hash_table_remove_all(mf->metadata_parsed); - str all_meta = STR_INIT(mf->metadata); + str all_meta = STR(mf->metadata); while (all_meta.len > 1) { str token; if (!str_token_sep(&token, &all_meta, '|')) diff --git a/recording-daemon/output.c b/recording-daemon/output.c index d0e10eab7..0c626bc44 100644 --- a/recording-daemon/output.c +++ b/recording-daemon/output.c @@ -426,11 +426,11 @@ void output_init(const char *format) { str codec; if (!strcmp(format, "wav")) { - str_init(&codec, "PCM-S16LE"); + codec = STR("PCM-S16LE"); output_file_format = "wav"; } else if (!strcmp(format, "mp3")) { - str_init(&codec, "MP3"); + codec = STR("MP3"); output_file_format = "mp3"; } else diff --git a/t/aead-aes-crypt.c b/t/aead-aes-crypt.c index 609be710c..5c41faa26 100644 --- a/t/aead-aes-crypt.c +++ b/t/aead-aes-crypt.c @@ -109,7 +109,7 @@ int main(void) crypto_init_main(); - str_init(&suite, "AEAD_AES_128_GCM"); + suite = STR("AEAD_AES_128_GCM"); c = crypto_find_suite(&suite); assert(c); @@ -168,7 +168,7 @@ int main(void) crypto_cleanup_session_key(&ctx); // AES 256 - str_init(&suite, "AEAD_AES_256_GCM"); + suite = STR("AEAD_AES_256_GCM"); c = crypto_find_suite(&suite); assert(c); diff --git a/t/aes-crypt.c b/t/aes-crypt.c index 290ae0faa..5a7e652b0 100644 --- a/t/aes-crypt.c +++ b/t/aes-crypt.c @@ -209,7 +209,7 @@ int main(int argc, char** argv) { crypto_init_main(); rtpe_ssl_init(); - str_init(&suite, "AES_CM_128_HMAC_SHA1_80"); + suite = STR("AES_CM_128_HMAC_SHA1_80"); c = crypto_find_suite(&suite); assert(c); @@ -232,7 +232,7 @@ int main(int argc, char** argv) { srtp_validate(&ctx, &ctx2, "SRTP AES-CM-128", rtp_plaintext_ref, srtp_ciphertext_128, rtcp_plaintext_ref, srtcp_ciphertext_128); - str_init(&suite, "AES_192_CM_HMAC_SHA1_80"); + suite = STR("AES_192_CM_HMAC_SHA1_80"); c = crypto_find_suite(&suite); assert(c); @@ -258,7 +258,7 @@ int main(int argc, char** argv) { srtp_validate(&ctx, &ctx2, "SRTP AES-CM-192", rtp_plaintext_ref, srtp_ciphertext_192, rtcp_plaintext_ref, srtcp_ciphertext_192); - str_init(&suite, "AES_256_CM_HMAC_SHA1_80"); + suite = STR("AES_256_CM_HMAC_SHA1_80"); c = crypto_find_suite(&suite); assert(c); diff --git a/t/test-amr-decode.c b/t/test-amr-decode.c index 9726c61e2..c9f77f9b5 100644 --- a/t/test-amr-decode.c +++ b/t/test-amr-decode.c @@ -53,7 +53,7 @@ static void do_test_amr_xx(const char *file, int line, char *codec, int clockrate) { printf("running test %s:%i\n", file, line); - str codec_name = STR_INIT(codec); + str codec_name = STR(codec); codec_def_t *def = codec_find(&codec_name, MT_AUDIO); assert(def); if (!def->support_encoding || !def->support_decoding) { @@ -61,12 +61,10 @@ static void do_test_amr_xx(const char *file, int line, exit(0); } const format_t fmt = { .clockrate = clockrate, .channels = 1, .format = AV_SAMPLE_FMT_S16}; - str fmtp_str, *fmtp = NULL; - if (fmtp_s) { - str_init(&fmtp_str, fmtp_s); - fmtp = &fmtp_str; - } - decoder_t *d = decoder_new_fmtp(def, clockrate, 1, 0, &fmt, NULL, NULL, fmtp); + str fmtp = STR_NULL; + if (fmtp_s) + fmtp = STR(fmtp_s); + decoder_t *d = decoder_new_fmtp(def, clockrate, 1, 0, &fmt, NULL, NULL, &fmtp); assert(d); const str data = { data_s, data_len }; int ret = decoder_input_data(d, &data, 1, frame_cb, &args, NULL); diff --git a/t/test-amr-encode.c b/t/test-amr-encode.c index 9fe539237..8702411b6 100644 --- a/t/test-amr-encode.c +++ b/t/test-amr-encode.c @@ -52,7 +52,7 @@ static void do_test_amr_xx(const char *file, int line, int bitrate, char *codec, int clockrate) { printf("running test %s:%i\n", file, line); - str codec_name = STR_INIT(codec); + str codec_name = STR(codec); codec_def_t *def = codec_find(&codec_name, MT_AUDIO); assert(def); if (!def->support_encoding || !def->support_decoding) { @@ -60,17 +60,13 @@ static void do_test_amr_xx(const char *file, int line, exit(0); } const format_t fmt = { .clockrate = clockrate, .channels = 1, .format = 0 }; - str fmtp_str, *fmtp = NULL; - char *fmtp_buf = NULL; - if (fmtp_s) { - fmtp_buf = strdup(fmtp_s); - str_init(&fmtp_str, fmtp_buf); - fmtp = &fmtp_str; - } + str fmtp = STR_NULL; + if (fmtp_s) + str_init_dup(&fmtp, fmtp_s); encoder_t *e = encoder_new(); assert(e); format_t actual_fmt; - int ret = encoder_config_fmtp(e, def, bitrate, 20, &fmt, &fmt, &actual_fmt, NULL, fmtp, NULL); + int ret = encoder_config_fmtp(e, def, bitrate, 20, &fmt, &fmt, &actual_fmt, NULL, &fmtp, NULL); assert(actual_fmt.clockrate == clockrate); assert(actual_fmt.channels == 1); assert(actual_fmt.format == AV_SAMPLE_FMT_S16); @@ -92,7 +88,7 @@ static void do_test_amr_xx(const char *file, int line, assert(expect_s == NULL); encoder_free(e); - free(fmtp_buf); + free(fmtp.s); av_frame_free(&frame); printf("test ok: %s:%i\n", file, line); diff --git a/t/test-const_str_hash.c b/t/test-const_str_hash.c index 044bf2c35..ddacc5e47 100644 --- a/t/test-const_str_hash.c +++ b/t/test-const_str_hash.c @@ -4,7 +4,7 @@ static int test_hash(char *p) { str s; - str_init(&s, p); + s = STR(p); switch (__csh_lookup(&s)) { case CSH_LOOKUP("one"): return 1; diff --git a/t/test-transcode.c b/t/test-transcode.c index a963abcb0..4e8bf7932 100644 --- a/t/test-transcode.c +++ b/t/test-transcode.c @@ -22,7 +22,7 @@ GQueue rtpe_control_ng = G_QUEUE_INIT; struct bufferpool *shm_bufferpool; static str *sdup(char *s) { - str r = STR_INIT(s); + str r = STR(s); return str_dup(&r); } static void queue_dump(GString *s, rtp_pt_q *q) { @@ -89,7 +89,7 @@ static void __start(const char *file, int line) { ZERO(call); obj_hold(&call); call.tags = tags_ht_new(); - str_init(&call.callid, "test-call"); + call.callid = STR("test-call"); bencode_buffer_init(&call.buffer); ml_A = __monologue_create(&call); ml_B = __monologue_create(&call); @@ -97,12 +97,12 @@ static void __start(const char *file, int line) { media_B = call_media_new(&call); // output destination t_queue_push_tail(&media_A->streams, ps_new(&call)); t_queue_push_tail(&media_B->streams, ps_new(&call)); - str_init(&ml_A->tag, "tag_A"); - str_init(&ml_A->label, "label_A"); + ml_A->tag = STR("tag_A"); + ml_A->label = STR("label_A"); media_A->monologue = ml_A; media_A->protocol = &transport_protocols[PROTO_RTP_AVP]; - str_init(&ml_B->tag, "tag_B"); - str_init(&ml_B->label, "label_B"); + ml_B->tag = STR("tag_B"); + ml_B->label = STR("label_B"); media_B->monologue = ml_B; media_B->protocol = &transport_protocols[PROTO_RTP_AVP]; __init(); @@ -117,7 +117,7 @@ static void __start(const char *file, int line) { static void codec_set(char *c) { // from call_ng_flags_str_ht_split c = strdup(c); - str s = STR_INIT(c); + str s = STR(c); str splitter = s; while (1) {