mirror of
https://github.com/jambonz/sbc-outbound.git
synced 2025-12-19 04:27:45 +00:00
if invite is sent with a domain name in request uri then assume the intention is for it to go out that way
This commit is contained in:
@@ -7,6 +7,9 @@ const {SipError, stringifyUri, parseUri} = require('drachtio-srf');
|
||||
const debug = require('debug')('jambonz:sbc-outbound');
|
||||
|
||||
const makeInviteInProgressKey = (callid) => `sbc-out-iip${callid}`;
|
||||
|
||||
const isDotDecimal = (host) => /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/.test(host);
|
||||
|
||||
/**
|
||||
* this is to make sure the outgoing From has the number in the incoming From
|
||||
* and not the incoming PAI
|
||||
@@ -25,9 +28,11 @@ const createBLegFromHeader = (req, teams) => {
|
||||
}
|
||||
return `sip:${user}@${host}`;
|
||||
};
|
||||
const createBLegToHeader = (req, teams) => {
|
||||
const createBLegToHeader = (req, teams, retainHostName) => {
|
||||
const to = req.getParsedHeader('To');
|
||||
const host = teams ? req.get('X-MS-Teams-Tenant-FQDN') : 'localhost';
|
||||
let host = 'localhost';
|
||||
if (teams) host = req.get('X-MS-Teams-Tenant-FQDN');
|
||||
else if (retainHostName) host = to.host;
|
||||
const uri = parseUri(to.uri);
|
||||
if (uri && uri.user) return `sip:${uri.user}@${host}`;
|
||||
return `sip:anonymous@${host}`;
|
||||
@@ -185,11 +190,18 @@ class CallSession extends Emitter {
|
||||
try {
|
||||
// determine where to send the call
|
||||
debug(`connecting call: ${JSON.stringify(this.req.locals)}`);
|
||||
|
||||
/**
|
||||
* if we receive an INVITE with a host part that is not a dot-decimal ipv4
|
||||
* default to retaining that in the INVITE we send
|
||||
* */
|
||||
const parsedIncomingUri = parseUri(this.req.uri);
|
||||
const retainHostName = !isDotDecimal(parsedIncomingUri.host);
|
||||
let headers = {
|
||||
'From': createBLegFromHeader(this.req, teams),
|
||||
'Contact': createBLegFromHeader(this.req, teams),
|
||||
'To': createBLegToHeader(this.req, teams),
|
||||
Allow: 'INVITE, ACK, OPTIONS, CANCEL, BYE, NOTIFY, UPDATE, PRACK',
|
||||
'To': createBLegToHeader(this.req, teams), retainHostName,
|
||||
Allow: 'INVITE, ACK, OPTIONS, CANCEL, BYE, NOTIFY, UPDATE, PRACK, REFER, INFO',
|
||||
'X-Account-Sid': this.account_sid
|
||||
};
|
||||
|
||||
@@ -262,21 +274,28 @@ class CallSession extends Emitter {
|
||||
if (gws.length) {
|
||||
uris = [];
|
||||
gws.forEach((o) => {
|
||||
let proxy;
|
||||
const calledNumber = this.req.calledNumber.startsWith('+') ?
|
||||
this.req.calledNumber.slice(1) :
|
||||
this.req.calledNumber;
|
||||
const prefix = vc.tech_prefix || '';
|
||||
const protocol = o.protocol?.startsWith('tls') ? 'tls' : (o.protocol || 'udp');
|
||||
const hostport = !o.port || 5060 === o.port ? o.ipv4 : `${o.ipv4}:${o.port}`;
|
||||
const host = retainHostName ? parsedIncomingUri.host : o.ipv4;
|
||||
const hostport = !o.port || 5060 === o.port ? host : `${host}:${o.port}`;
|
||||
const prependPlus = vc.e164_leading_plus && !this.req.calledNumber.startsWith('0') ? '+' : '';
|
||||
const transport = `transport=${protocol}`;
|
||||
const scheme = protocol === 'tls' ? 'sips' : 'sip';
|
||||
const u = `${scheme}:${prefix}${prependPlus}${calledNumber}@${hostport};${transport}`;
|
||||
if (retainHostName) {
|
||||
const hostport = !o.port || 5060 === o.port ? o.ipv4 : `${o.ipv4}:${o.port}`;
|
||||
proxy = `${scheme}:${hostport};transport=${transport}`;
|
||||
}
|
||||
const obj = {
|
||||
name: vc.name,
|
||||
diversion: vc.diversion,
|
||||
hostport,
|
||||
protocol: o.protocol
|
||||
protocol: o.protocol,
|
||||
...(proxy && {proxy})
|
||||
};
|
||||
if (vc.register_username && vc.register_password) {
|
||||
obj.auth = {
|
||||
@@ -355,7 +374,6 @@ class CallSession extends Emitter {
|
||||
// INVITE request line and To header should be the same.
|
||||
hdrs = {...hdrs, 'To': uri};
|
||||
if (gw) {
|
||||
this.logger.info({gw}, `sending INVITE to ${uri} via carrier ${gw.name}`);
|
||||
if (gw.diversion) {
|
||||
let div = gw.diversion;
|
||||
if (div.startsWith('+')) {
|
||||
@@ -367,6 +385,8 @@ class CallSession extends Emitter {
|
||||
'Diversion': div
|
||||
};
|
||||
}
|
||||
proxy = gw.proxy;
|
||||
this.logger.info({gw}, `sending INVITE to ${uri}`);
|
||||
}
|
||||
else this.logger.info(`sending INVITE to ${uri} via proxy ${proxy})`);
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user