MT#55283 modernise STR_INIT and str_init

Obsolete str_init(), rename STR_INIT() to just STR(), and replace all
instances of str_init() with STR().

no-op

Change-Id: I981529063ad2ea26089add467f7a84b638dbf423
rfuchs/gh1842
Richard Fuchs 10 months ago
parent 5f6739b9fa
commit a6b28af6f8

@ -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++) { for (cp =out[RE_UDP_UL_FLAGS]; *cp && i < 2; cp++) {
c = chrtoupper(*cp); c = chrtoupper(*cp);
if (c == 'E') if (c == 'E')
str_init(&sp->direction[i++], "external"); sp->direction[i++] = STR("external");
else if (c == 'I') 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; g_auto(sdp_ng_flags) flags;
call_ng_flags_init(&flags, opmode); call_ng_flags_init(&flags, opmode);
str callid = STR_INIT(out[RE_UDP_UL_CALLID]); str callid = STR(out[RE_UDP_UL_CALLID]);
str fromtag = STR_INIT(out[RE_UDP_UL_FROMTAG]); str fromtag = STR(out[RE_UDP_UL_FROMTAG]);
str totag = STR_INIT(out[RE_UDP_UL_TOTAG]); str totag = STR(out[RE_UDP_UL_TOTAG]);
if (opmode == OP_ANSWER) if (opmode == OP_ANSWER)
str_swap(&fromtag, &totag); 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; g_auto(sdp_ng_flags) flags;
call_ng_flags_init(&flags, opmode); 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); infohash = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
c = call_get_opmode(&callid, opmode); c = call_get_opmode(&callid, opmode);
if (!c) { 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); info_parse(out[RE_TCP_RL_INFO], infohash);
streams_parse(out[RE_TCP_RL_STREAMS], &s); 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) { if (!fromtag.s) {
ilog(LOG_WARNING, "No from-tag in message"); ilog(LOG_WARNING, "No from-tag in message");
goto out2; 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 (opmode == OP_ANSWER) {
if (!totag.s) { if (!totag.s) {
ilog(LOG_WARNING, "No to-tag in message"); 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'", __C_DBG("got delete for callid '%s' and viabranch '%s'",
out[RE_UDP_DQ_CALLID], out[RE_UDP_DQ_VIABRANCH]); out[RE_UDP_DQ_CALLID], out[RE_UDP_DQ_VIABRANCH]);
str callid = STR_INIT(out[RE_UDP_DQ_CALLID]); str callid = STR(out[RE_UDP_DQ_CALLID]);
str branch = STR_INIT(out[RE_UDP_DQ_VIABRANCH]); str branch = STR(out[RE_UDP_DQ_VIABRANCH]);
str fromtag = STR_INIT(out[RE_UDP_DQ_FROMTAG]); str fromtag = STR(out[RE_UDP_DQ_FROMTAG]);
str totag = STR_INIT(out[RE_UDP_DQ_TOTAG]); str totag = STR(out[RE_UDP_DQ_TOTAG]);
if (call_delete_branch_by_id(&callid, &branch, &fromtag, &totag, NULL, -1)) if (call_delete_branch_by_id(&callid, &branch, &fromtag, &totag, NULL, -1))
return str_sprintf("%s E8\n", out[RE_UDP_COOKIE]); 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]); __C_DBG("got query for callid '%s'", out[RE_UDP_DQ_CALLID]);
str callid = STR_INIT(out[RE_UDP_DQ_CALLID]); str callid = STR(out[RE_UDP_DQ_CALLID]);
str fromtag = STR_INIT(out[RE_UDP_DQ_FROMTAG]); str fromtag = STR(out[RE_UDP_DQ_FROMTAG]);
str totag = STR_INIT(out[RE_UDP_DQ_TOTAG]); str totag = STR(out[RE_UDP_DQ_TOTAG]);
c = call_get_opmode(&callid, OP_QUERY); c = call_get_opmode(&callid, OP_QUERY);
if (!c) { if (!c) {
@ -439,7 +439,7 @@ out:
} }
void call_delete_tcp(char **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); call_delete_branch_by_id(&callid, NULL, NULL, NULL, NULL, -1);
} }

@ -1210,7 +1210,7 @@ static void cli_stream_readable(struct streambuf_stream *s) {
return; return;
} }
str_init(&instr, inbuf); instr = STR(inbuf);
struct cli_writer cw = { struct cli_writer cw = {
.cw_printf = cli_streambuf_printf, .cw_printf = cli_streambuf_printf,

@ -776,9 +776,9 @@ static void __check_dtmf_injector(struct call_media *receiver, struct call_media
.clock_rate = parent->source_pt.clock_rate, .clock_rate = parent->source_pt.clock_rate,
.channels = parent->source_pt.channels, .channels = parent->source_pt.channels,
}; };
str_init(&src_pt.encoding, "DTMF injector"); src_pt.encoding = STR("DTMF injector");
str_init(&src_pt.encoding_with_params, "DTMF injector"); src_pt.encoding_with_params = STR("DTMF injector");
str_init(&src_pt.encoding_with_full_params, "DTMF injector"); src_pt.encoding_with_full_params = STR("DTMF injector");
static const str tp_event = STR_CONST_INIT("telephone-event"); static const str tp_event = STR_CONST_INIT("telephone-event");
src_pt.codec_def = codec_find(&tp_event, MT_AUDIO); src_pt.codec_def = codec_find(&tp_event, MT_AUDIO);
if (!src_pt.codec_def) { 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) if (pt->ptime <= 0)
pt->ptime = def->default_ptime; pt->ptime = def->default_ptime;
if (!pt->format_parameters.s && def->default_fmtp) 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); 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_autoptr(char) pt_s
= g_strdup_printf(STR_FORMAT "/%u", STR_FMT(supp_codec), clockrate); = 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 // see if we have a matching PT from before
rtp_payload_type *pt = NULL; rtp_payload_type *pt = NULL;

@ -158,7 +158,7 @@ static bool parse_codec_to_dict(str * key, str * val, const char *cmp1, const ch
return false; 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; return true;
} }

@ -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); 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); ce = cookie_cache_lookup(&u->cookie_cache, &cookie);
if (ce) { if (ce) {
reply = ce->reply; reply = ce->reply;

@ -997,7 +997,7 @@ void crypto_init_main(void) {
for (unsigned int i = 0; i < num_crypto_suites; i++) { for (unsigned int i = 0; i < num_crypto_suites; i++) {
cs = &__crypto_suites[i]; cs = &__crypto_suites[i];
cs->idx = i; cs->idx = i;
str_init(&cs->name_str, (char *) cs->name); cs->name_str = STR(cs->name);
switch(cs->master_key_len) { switch(cs->master_key_len) {
case 16: case 16:
cs->aes_evp = EVP_aes_128_ecb(); cs->aes_evp = EVP_aes_128_ecb();

@ -121,7 +121,7 @@ static struct call_monologue *janus_get_monologue(uint64_t handle_id, call_t *ca
{ {
g_autoptr(char) handle_buf = NULL; g_autoptr(char) handle_buf = NULL;
handle_buf = g_strdup_printf("%" PRIu64, handle_id); 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); 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); const char *req = json_reader_get_string_value(reader);
if (!req) if (!req)
goto err; goto err;
str req_str = STR_INIT(req); str req_str = STR(req);
json_reader_end_member(reader); json_reader_end_member(reader);
switch (__csh_lookup(&req_str)) { 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); 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; err = NULL;
@ -1902,7 +1902,7 @@ const char *websocket_janus_process(struct websocket_message *wm) {
const char *websocket_janus_get(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); 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) { 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); ilog(LOG_DEBUG, "Processing Janus POST: '%s'", wm->uri);

@ -280,7 +280,7 @@ static int if_addr_parse(intf_config_q *q, char *s, struct ifaddrs *ifas) {
if (c) { if (c) {
char cc = *c; char cc = *c;
*c++ = 0; *c++ = 0;
str_init(&name, s); name = STR(s);
s = c; s = c;
if (cc == '=') { if (cc == '=') {
// foo=bar // foo=bar
@ -292,7 +292,7 @@ static int if_addr_parse(intf_config_q *q, char *s, struct ifaddrs *ifas) {
} }
} }
else else
str_init(&name, "default"); name = STR("default");
/* advertised address */ /* advertised address */
c = strchr(s, '!'); c = strchr(s, '!');

@ -369,7 +369,7 @@ 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_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)); call_str_cpy(call, &call->recording_random_tag, &STR_CONST_INIT(rand_str));
} }

@ -72,14 +72,14 @@ static int redisCommandNR(redisContext *r, const char *fmt, ...)
__attribute__((format(printf,2,3))); __attribute__((format(printf,2,3)));
#define PB "%.*s" #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 STR_R(x) (int) (x)->len, (x)->str
#define S_LEN(s,l) (int) (l), (s) #define S_LEN(s,l) (int) (l), (s)
#else #else
#define PB "%b" #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 STR_R(x) (x)->str, (size_t) (x)->len
#define S_LEN(s,l) (s), (size_t) (l) #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 */ /* called with r->lock held and c->master_lock held */
static void redis_delete_call_json(call_t *c, struct redis *r) { 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); redis_consume(r);
} }
@ -2006,7 +2006,7 @@ static void json_restore_call(struct redis *r, const str *callid, bool foreign)
JsonParser *parser =0; JsonParser *parser =0;
mutex_lock(&r->lock); 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); mutex_unlock(&r->lock);
bool must_release_pop = true; bool must_release_pop = true;
@ -2188,12 +2188,12 @@ err1:
must_release_pop = false; must_release_pop = false;
mutex_lock(&rtpe_redis_write->lock); 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); mutex_unlock(&rtpe_redis_write->lock);
if (rtpe_redis_notify) { if (rtpe_redis_notify) {
mutex_lock(&rtpe_redis_notify->lock); 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); mutex_unlock(&rtpe_redis_notify->lock);
} }
} }
@ -2815,8 +2815,8 @@ void redis_update_onekey(call_t *c, struct redis *r) {
if (!result) if (!result)
goto err; goto err;
redis_pipe(r, "SET "PB" %s", STR(&c->callid), result); redis_pipe(r, "SET "PB" %s", PBSTR(&c->callid), result);
redis_pipe(r, "EXPIRE "PB" %i", STR(&c->callid), redis_expires_s); redis_pipe(r, "EXPIRE "PB" %i", PBSTR(&c->callid), redis_expires_s);
redis_consume(r); redis_consume(r);

@ -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) { 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); 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, INLINE void append_attr_to_gstring(GString *s, const char * name, const str * value,
const sdp_ng_flags *flags, enum media_type media_type) 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) { 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); 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); assert(hf->num_bytes > 0);
if (MEDIA_ARESET2(media, SETUP_PASSIVE, SETUP_ACTIVE)) if (MEDIA_ARESET2(media, SETUP_PASSIVE, SETUP_ACTIVE))
str_init(&actpass_str, "actpass"); actpass_str = STR("actpass");
else if (MEDIA_ISSET(media, SETUP_PASSIVE)) else if (MEDIA_ISSET(media, SETUP_PASSIVE))
str_init(&actpass_str, "passive"); actpass_str = STR("passive");
else if (MEDIA_ISSET(media, SETUP_ACTIVE)) else if (MEDIA_ISSET(media, SETUP_ACTIVE))
str_init(&actpass_str, "active"); actpass_str = STR("active");
else else
str_init(&actpass_str, "holdconn"); actpass_str = STR("holdconn");
append_attr_to_gstring(s, "setup", &actpass_str, flags, media->type_id); 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 packet_stream *first_ps, sdp_ng_flags *flags)
{ {
struct call_monologue *ml = monologue; struct call_monologue *ml = monologue;
str a, a_type;
/* for the offer/answer model or subscribe don't use the given monologues SDP, /* 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 * 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; ml->session_last_sdp_orig->version_num : ml->session_sdp_orig->version_num;
/* orig IP family and address */ /* orig IP family and address */
str * orig_address_type; str orig_address_type;
str * orig_address; str orig_address;
if (!ms || flags->replace_origin || flags->replace_origin_full) { if (!ms || flags->replace_origin || flags->replace_origin_full) {
/* replacing flags or PUBLISH */ /* replacing flags or PUBLISH */
str_init(&a_type, (char *)first_ps->selected_sfd->local_intf->advertised_address.addr.family->rfc_name); orig_address_type = STR(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 = STR(sockaddr_print_buf(&first_ps->selected_sfd->local_intf->advertised_address.addr));
orig_address_type = &a_type;
orig_address = &a;
} else { } else {
orig_address_type = &ml->session_sdp_orig->address.address_type; orig_address_type = ml->session_sdp_orig->address.address_type;
orig_address = &ml->session_sdp_orig->address.address; orig_address = ml->session_sdp_orig->address.address;
} }
g_string_append_printf(out, 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_username),
STR_FMT(orig_session_id), STR_FMT(orig_session_id),
orig_session_version, orig_session_version,
STR_FMT(orig_address_type), STR_FMT(&orig_address_type),
STR_FMT(orig_address)); STR_FMT(&orig_address));
} }
static void sdp_out_add_session_name(GString *out, struct call_monologue *monologue, static void sdp_out_add_session_name(GString *out, struct call_monologue *monologue,

@ -392,7 +392,7 @@ int t38_gateway_pair(struct call_media *t38_media, struct call_media *pcm_media,
tg->options = opts; tg->options = opts;
tg->pcm_pt.payload_type = -1; 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.encoding_with_params = tg->pcm_pt.encoding;
tg->pcm_pt.clock_rate = 8000; tg->pcm_pt.clock_rate = 8000;
tg->pcm_pt.channels = 1; tg->pcm_pt.channels = 1;

@ -440,7 +440,7 @@ static const char *websocket_http_cli(struct websocket_message *wm) {
ilogs(http, LOG_DEBUG, "Respoding to GET /cli/%s", uri); 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 = { struct cli_writer cw = {
.cw_printf = websocket_queue_printf, .cw_printf = websocket_queue_printf,

@ -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) { INLINE str *call_str_init_dup(call_t *c, char *s) {
str t; str t;
str_init(&t, s); t = STR(s);
return call_str_dup(c, &t); return call_str_dup(c, &t);
} }
INLINE void __call_unkernelize(call_t *call, const char *reason) { INLINE void __call_unkernelize(call_t *call, const char *reason) {

@ -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, void sdp_append_str_attr(GString *s, const sdp_ng_flags *flags, enum media_type media_type,
const str *name, const char *fmt, ...) const str *name, const char *fmt, ...)
__attribute__ ((format (printf, 5, 6))); __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 *); void sdp_attr_free(struct sdp_attr *);
sdp_origin *sdp_orig_dup(const sdp_origin *orig); sdp_origin *sdp_orig_dup(const sdp_origin *orig);

@ -1589,7 +1589,7 @@ void codeclib_init(int print) {
for (int i = 0; i < G_N_ELEMENTS(__codec_defs); i++) { for (int i = 0; i < G_N_ELEMENTS(__codec_defs); i++) {
// add to hash table // add to hash table
struct codec_def_s *def = &__codec_defs[i]; 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); assert(g_hash_table_lookup(codecs_ht, &def->rtpname_str) == NULL);
g_hash_table_insert(codecs_ht, &def->rtpname_str, def); g_hash_table_insert(codecs_ht, &def->rtpname_str, def);

@ -37,7 +37,7 @@ TYPED_GQUEUE(str, str)
#define STR_NULL ((str) { NULL, 0 }) #define STR_NULL ((str) { NULL, 0 })
#define STR_EMPTY ((str) { "", 0 }) #define STR_EMPTY ((str) { "", 0 })
#define STR_CONST_INIT(s) ((str) { s, sizeof(s)-1 }) #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_GS(s) ((str) { (s)->str, (s)->len })
#define STR_INIT_LEN(s, len) ((str) { (char *) (s), len }) #define STR_INIT_LEN(s, len) ((str) { (char *) (s), len })
#define STR_INIT_DUP(s) ((str) { g_strdup(s), strlen(s) }) #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, 1)
ACCESS(read_only, 2) ACCESS(read_only, 2)
INLINE int str_cmp_str0(const str *a, const str *b); 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 */ /* inits a str object from any binary string. returns out */
__attribute__((nonnull(1, 2))) __attribute__((nonnull(1, 2)))
ACCESS(write_only, 1) 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); 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) { INLINE str *str_init_len(str *out, char *s, size_t len) {
out->s = s; out->s = s;
out->len = len; out->len = len;

@ -653,7 +653,7 @@ static void show_popup(const char *fmt, ...) {
// split into lines and get max line length // split into lines and get max line length
GQueue lines = G_QUEUE_INIT; GQueue lines = G_QUEUE_INIT;
str st = STR_INIT(s); str st = STR(s);
str token; str token;
uint llen = 0; uint llen = 0;
while (str_token_sep(&token, &st, '\n')) { while (str_token_sep(&token, &st, '\n')) {
@ -1929,10 +1929,10 @@ int main(int argc, char **argv) {
if (!rtpe_poller) if (!rtpe_poller)
die("Failed to create 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) if (!decoder_def)
die("Codec definition for source codec not found"); 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) if (!encoder_def)
die("Codec definition for destination codec not found"); die("Codec definition for destination codec not found");

@ -82,7 +82,7 @@ decode_t *decoder_new(const char *payload_str, const char *format, int ptime, ou
else else
out_format.format = AV_SAMPLE_FMT_S16; // needed for TLS-only scenarios 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); decoder_t *dec = decoder_new_fmtp(def, rtp_clockrate, channels, ptime, &out_format, NULL, &fmtp, NULL);
if (!dec) if (!dec)

@ -173,7 +173,7 @@ static void meta_ptime(metafile_t *mf, unsigned long mnum, int ptime)
static void meta_metadata_parse(metafile_t *mf) { static void meta_metadata_parse(metafile_t *mf) {
// XXX offload this parsing to proxy module -> bencode list/dictionary // XXX offload this parsing to proxy module -> bencode list/dictionary
t_hash_table_remove_all(mf->metadata_parsed); 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) { while (all_meta.len > 1) {
str token; str token;
if (!str_token_sep(&token, &all_meta, '|')) if (!str_token_sep(&token, &all_meta, '|'))

@ -426,11 +426,11 @@ void output_init(const char *format) {
str codec; str codec;
if (!strcmp(format, "wav")) { if (!strcmp(format, "wav")) {
str_init(&codec, "PCM-S16LE"); codec = STR("PCM-S16LE");
output_file_format = "wav"; output_file_format = "wav";
} }
else if (!strcmp(format, "mp3")) { else if (!strcmp(format, "mp3")) {
str_init(&codec, "MP3"); codec = STR("MP3");
output_file_format = "mp3"; output_file_format = "mp3";
} }
else else

@ -109,7 +109,7 @@ int main(void)
crypto_init_main(); crypto_init_main();
str_init(&suite, "AEAD_AES_128_GCM"); suite = STR("AEAD_AES_128_GCM");
c = crypto_find_suite(&suite); c = crypto_find_suite(&suite);
assert(c); assert(c);
@ -168,7 +168,7 @@ int main(void)
crypto_cleanup_session_key(&ctx); crypto_cleanup_session_key(&ctx);
// AES 256 // AES 256
str_init(&suite, "AEAD_AES_256_GCM"); suite = STR("AEAD_AES_256_GCM");
c = crypto_find_suite(&suite); c = crypto_find_suite(&suite);
assert(c); assert(c);

@ -209,7 +209,7 @@ int main(int argc, char** argv) {
crypto_init_main(); crypto_init_main();
rtpe_ssl_init(); 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); c = crypto_find_suite(&suite);
assert(c); 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, srtp_validate(&ctx, &ctx2, "SRTP AES-CM-128", rtp_plaintext_ref, srtp_ciphertext_128,
rtcp_plaintext_ref, srtcp_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); c = crypto_find_suite(&suite);
assert(c); 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, srtp_validate(&ctx, &ctx2, "SRTP AES-CM-192", rtp_plaintext_ref, srtp_ciphertext_192,
rtcp_plaintext_ref, srtcp_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); c = crypto_find_suite(&suite);
assert(c); assert(c);

@ -53,7 +53,7 @@ static void do_test_amr_xx(const char *file, int line,
char *codec, int clockrate) char *codec, int clockrate)
{ {
printf("running test %s:%i\n", file, line); 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); codec_def_t *def = codec_find(&codec_name, MT_AUDIO);
assert(def); assert(def);
if (!def->support_encoding || !def->support_decoding) { if (!def->support_encoding || !def->support_decoding) {
@ -61,12 +61,10 @@ static void do_test_amr_xx(const char *file, int line,
exit(0); exit(0);
} }
const format_t fmt = { .clockrate = clockrate, .channels = 1, .format = AV_SAMPLE_FMT_S16}; const format_t fmt = { .clockrate = clockrate, .channels = 1, .format = AV_SAMPLE_FMT_S16};
str fmtp_str, *fmtp = NULL; str fmtp = STR_NULL;
if (fmtp_s) { if (fmtp_s)
str_init(&fmtp_str, fmtp_s); fmtp = STR(fmtp_s);
fmtp = &fmtp_str; decoder_t *d = decoder_new_fmtp(def, clockrate, 1, 0, &fmt, NULL, NULL, &fmtp);
}
decoder_t *d = decoder_new_fmtp(def, clockrate, 1, 0, &fmt, NULL, NULL, fmtp);
assert(d); assert(d);
const str data = { data_s, data_len }; const str data = { data_s, data_len };
int ret = decoder_input_data(d, &data, 1, frame_cb, &args, NULL); int ret = decoder_input_data(d, &data, 1, frame_cb, &args, NULL);

@ -52,7 +52,7 @@ static void do_test_amr_xx(const char *file, int line,
int bitrate, char *codec, int clockrate) int bitrate, char *codec, int clockrate)
{ {
printf("running test %s:%i\n", file, line); 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); codec_def_t *def = codec_find(&codec_name, MT_AUDIO);
assert(def); assert(def);
if (!def->support_encoding || !def->support_decoding) { if (!def->support_encoding || !def->support_decoding) {
@ -60,17 +60,13 @@ static void do_test_amr_xx(const char *file, int line,
exit(0); exit(0);
} }
const format_t fmt = { .clockrate = clockrate, .channels = 1, .format = 0 }; const format_t fmt = { .clockrate = clockrate, .channels = 1, .format = 0 };
str fmtp_str, *fmtp = NULL; str fmtp = STR_NULL;
char *fmtp_buf = NULL; if (fmtp_s)
if (fmtp_s) { str_init_dup(&fmtp, fmtp_s);
fmtp_buf = strdup(fmtp_s);
str_init(&fmtp_str, fmtp_buf);
fmtp = &fmtp_str;
}
encoder_t *e = encoder_new(); encoder_t *e = encoder_new();
assert(e); assert(e);
format_t actual_fmt; 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.clockrate == clockrate);
assert(actual_fmt.channels == 1); assert(actual_fmt.channels == 1);
assert(actual_fmt.format == AV_SAMPLE_FMT_S16); 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); assert(expect_s == NULL);
encoder_free(e); encoder_free(e);
free(fmtp_buf); free(fmtp.s);
av_frame_free(&frame); av_frame_free(&frame);
printf("test ok: %s:%i\n", file, line); printf("test ok: %s:%i\n", file, line);

@ -4,7 +4,7 @@
static int test_hash(char *p) { static int test_hash(char *p) {
str s; str s;
str_init(&s, p); s = STR(p);
switch (__csh_lookup(&s)) { switch (__csh_lookup(&s)) {
case CSH_LOOKUP("one"): case CSH_LOOKUP("one"):
return 1; return 1;

@ -22,7 +22,7 @@ GQueue rtpe_control_ng = G_QUEUE_INIT;
struct bufferpool *shm_bufferpool; struct bufferpool *shm_bufferpool;
static str *sdup(char *s) { static str *sdup(char *s) {
str r = STR_INIT(s); str r = STR(s);
return str_dup(&r); return str_dup(&r);
} }
static void queue_dump(GString *s, rtp_pt_q *q) { static void queue_dump(GString *s, rtp_pt_q *q) {
@ -89,7 +89,7 @@ static void __start(const char *file, int line) {
ZERO(call); ZERO(call);
obj_hold(&call); obj_hold(&call);
call.tags = tags_ht_new(); call.tags = tags_ht_new();
str_init(&call.callid, "test-call"); call.callid = STR("test-call");
bencode_buffer_init(&call.buffer); bencode_buffer_init(&call.buffer);
ml_A = __monologue_create(&call); ml_A = __monologue_create(&call);
ml_B = __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 media_B = call_media_new(&call); // output destination
t_queue_push_tail(&media_A->streams, ps_new(&call)); t_queue_push_tail(&media_A->streams, ps_new(&call));
t_queue_push_tail(&media_B->streams, ps_new(&call)); t_queue_push_tail(&media_B->streams, ps_new(&call));
str_init(&ml_A->tag, "tag_A"); ml_A->tag = STR("tag_A");
str_init(&ml_A->label, "label_A"); ml_A->label = STR("label_A");
media_A->monologue = ml_A; media_A->monologue = ml_A;
media_A->protocol = &transport_protocols[PROTO_RTP_AVP]; media_A->protocol = &transport_protocols[PROTO_RTP_AVP];
str_init(&ml_B->tag, "tag_B"); ml_B->tag = STR("tag_B");
str_init(&ml_B->label, "label_B"); ml_B->label = STR("label_B");
media_B->monologue = ml_B; media_B->monologue = ml_B;
media_B->protocol = &transport_protocols[PROTO_RTP_AVP]; media_B->protocol = &transport_protocols[PROTO_RTP_AVP];
__init(); __init();
@ -117,7 +117,7 @@ static void __start(const char *file, int line) {
static void codec_set(char *c) { static void codec_set(char *c) {
// from call_ng_flags_str_ht_split // from call_ng_flags_str_ht_split
c = strdup(c); c = strdup(c);
str s = STR_INIT(c); str s = STR(c);
str splitter = s; str splitter = s;
while (1) { while (1) {

Loading…
Cancel
Save