mirror of
https://github.com/jambonz/sbc-inbound.git
synced 2026-07-04 19:11:47 +00:00
bugfix: allow users to fully specify a Refer-To uri without us overiding it
This commit is contained in:
+26
-18
@@ -774,30 +774,38 @@ Duration=${payload.duration} `
|
||||
const referredBy = req.getParsedHeader('Referred-By');
|
||||
if (!referredBy) return res.send(400);
|
||||
const u = parseUri(referredBy.uri);
|
||||
const isDotDecimal = /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/.test(uri.host);
|
||||
let selectedGateway = false;
|
||||
let e164 = false;
|
||||
if (gateway && isDotDecimal) {
|
||||
/* host of Refer-to to an outbound gateway */
|
||||
const gw = await this.srf.locals.getOutboundGatewayForRefer(gateway.voip_carrier_sid);
|
||||
if (gw) {
|
||||
selectedGateway = true;
|
||||
e164 = gw.e164_leading_plus;
|
||||
uri.host = gw.ipv4;
|
||||
uri.port = gw.port;
|
||||
const leaveReferToAlone = req.has('X-Refer-To-Leave-Untouched');
|
||||
if (leaveReferToAlone) {
|
||||
this.logger.debug(`passing Refer-To header through untouched: ${referTo}`);
|
||||
}
|
||||
else {
|
||||
const isDotDecimal = /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/.test(uri.host);
|
||||
let selectedGateway = false;
|
||||
let e164 = false;
|
||||
if (gateway && isDotDecimal) {
|
||||
/* host of Refer-to to an outbound gateway */
|
||||
const gw = await this.srf.locals.getOutboundGatewayForRefer(gateway.voip_carrier_sid);
|
||||
if (gw) {
|
||||
selectedGateway = true;
|
||||
e164 = gw.e164_leading_plus;
|
||||
uri.host = gw.ipv4;
|
||||
uri.port = gw.port;
|
||||
}
|
||||
}
|
||||
if (!selectedGateway && isDotDecimal) {
|
||||
uri.host = this.req.source_address;
|
||||
uri.port = this.req.source_port;
|
||||
}
|
||||
if (e164 && !uri.user.startsWith('+')) {
|
||||
uri.user = `+${uri.user}`;
|
||||
}
|
||||
}
|
||||
if (!selectedGateway && isDotDecimal) {
|
||||
uri.host = this.req.source_address;
|
||||
uri.port = this.req.source_port;
|
||||
}
|
||||
if (e164 && !uri.user.startsWith('+')) {
|
||||
uri.user = `+${uri.user}`;
|
||||
}
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const {via, from, to, 'call-id':callid, cseq, 'max-forwards':maxforwards,
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
'content-length':contentlength, 'refer-to':_referto, 'referred-by':_referredby,
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
'x-refer-to-leave-untouched': _leave,
|
||||
...customHeaders
|
||||
} = req.headers;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user