Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

confg,uag: rework on sip_transports setting #1525

Merged
merged 1 commit into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 35 additions & 15 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,18 +251,38 @@ static void decode_sip_transports(struct config_sip *cfg,
const struct pl *pl)
{
uint8_t i;
const char *tr[] = {
"udp",
"tcp",
"tls",
"ws",
"wss"
};

for (i = 0; i < ARRAY_SIZE(tr); ++i) {
bool en = 0 == re_regex(pl->p, pl->l, tr[i]);
u32mask_enable(&cfg->transports, i, en);
for (i = 0; i < SIP_TRANSPC; ++i) {
bool en;
char buf[9];
struct pl e=PL_INIT;

strcpy(buf, sip_transp_name(i));
strcat(buf, "[^,]+");
en = 0 == re_regex(pl->p, pl->l, sip_transp_name(i)) &&
0 != re_regex(pl->p, pl->l, buf, &e);
u32mask_enable(&cfg->transports, i, en);
}
}


static int sip_transports_print(struct re_printf *pf, uint32_t *mask)
{
uint8_t i;
int err = 0;
bool first = true;

for (i = 0; i < SIP_TRANSPC; ++i) {
if (*mask==0 || u32mask_enabled(*mask, i)) {
if (!first)
err = re_hprintf(pf, ",");

err |= re_hprintf(pf, "%s", sip_transp_name(i));
first = false;
}
}

return err;
}


Expand Down Expand Up @@ -463,6 +483,7 @@ int config_print(struct re_printf *pf, const struct config *cfg)
"sip_certificate\t%s\n"
"sip_cafile\t\t%s\n"
"sip_capath\t\t%s\n"
"sip_transports\t\t%H\n"
"sip_trans_def\t%s\n"
"sip_verify_server\t\t\t%s\n"
"sip_tos\t%u\n"
Expand Down Expand Up @@ -519,6 +540,7 @@ int config_print(struct re_printf *pf, const struct config *cfg)

cfg->sip.local, cfg->sip.cert, cfg->sip.cafile,
cfg->sip.capath,
sip_transports_print, &cfg->sip.transports,
sip_transp_name(cfg->sip.transp),
cfg->sip.verify_server ? "yes" : "no",
cfg->sip.tos,
Expand Down Expand Up @@ -679,6 +701,7 @@ static int core_config_template(struct re_printf *pf, const struct config *cfg)
#else
"#sip_cafile\t\t%s\n"
#endif
"#sip_transports\t\tudp,tcp,tls,ws,wss\n"
"#sip_trans_def\t\tudp\n"
"#sip_verify_server\tyes\n"
"sip_tos\t\t\t160\n"
Expand Down Expand Up @@ -845,12 +868,9 @@ void u32mask_enable(uint32_t *mask, uint8_t bit, bool enable)
}


bool u32mask_enabled(uint32_t *mask, uint8_t bit)
bool u32mask_enabled(uint32_t mask, uint8_t bit)
{
if (!mask)
return false;

return 0 != (*mask & (1u << bit));
return 0 != (mask & (1u << bit));
}


Expand Down
2 changes: 1 addition & 1 deletion src/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ bool uag_delayed_close(void);
int uag_raise(struct ua *ua, struct le *le);

void u32mask_enable(uint32_t *mask, uint8_t bit, bool enable);
bool u32mask_enabled(uint32_t *mask, uint8_t bit);
bool u32mask_enabled(uint32_t mask, uint8_t bit);


/*
Expand Down
10 changes: 5 additions & 5 deletions src/uag.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,17 +330,17 @@ static int add_transp_af(const struct sa *laddr)
sa_set_port(&local, 0);
}

if (u32mask_enabled(&uag.transports, SIP_TRANSP_UDP))
if (u32mask_enabled(uag.transports, SIP_TRANSP_UDP))
err |= sip_transp_add(uag.sip, SIP_TRANSP_UDP, &local);
if (u32mask_enabled(&uag.transports, SIP_TRANSP_TCP))
if (u32mask_enabled(uag.transports, SIP_TRANSP_TCP))
err |= sip_transp_add(uag.sip, SIP_TRANSP_TCP, &local);
if (err) {
warning("ua: SIP Transport failed: %m\n", err);
return err;
}

#ifdef USE_TLS
if (u32mask_enabled(&uag.transports, SIP_TRANSP_TLS)) {
if (u32mask_enabled(uag.transports, SIP_TRANSP_TLS)) {
/* Build our SSL context*/
if (!uag.tls) {
if (str_isset(uag.cfg->cert)) {
Expand Down Expand Up @@ -391,7 +391,7 @@ static int add_transp_af(const struct sa *laddr)
}
#endif

if (u32mask_enabled(&uag.transports, SIP_TRANSP_WS)) {
if (u32mask_enabled(uag.transports, SIP_TRANSP_WS)) {
err = sip_transp_add_websock(uag.sip, SIP_TRANSP_WS, &local,
false, NULL, NULL);
if (err) {
Expand All @@ -402,7 +402,7 @@ static int add_transp_af(const struct sa *laddr)
}

#ifdef USE_TLS
if (u32mask_enabled(&uag.transports, SIP_TRANSP_WSS)) {
if (u32mask_enabled(uag.transports, SIP_TRANSP_WSS)) {
if (!uag.wss_tls) {
err = tls_alloc(&uag.wss_tls, TLS_METHOD_SSLV23,
NULL, NULL);
Expand Down