mirror of
https://github.com/jambonz/sbc-inbound.git
synced 2025-12-19 04:37:43 +00:00
phone number's application should override voice carrier default application (#128)
* phone number's application should override voice carrier default application * fix review comments * fix review comments
This commit is contained in:
@@ -142,7 +142,7 @@ module.exports = (srf, logger) => {
|
||||
const failure = {fromCarrier: false};
|
||||
const uri = parseUri(req.uri);
|
||||
const isDotDecimal = /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/.test(uri.host);
|
||||
|
||||
const did = normalizeDID(req.calledNumber) || 'anonymous';
|
||||
if (!isDotDecimal) {
|
||||
/**
|
||||
* The host part of the SIP URI is not a dot-decimal IP address,
|
||||
@@ -175,12 +175,19 @@ module.exports = (srf, logger) => {
|
||||
.sort((a, b) => b.netmask - a.netmask);
|
||||
const selected = gw.find(gatewayMatchesSourceAddress.bind(null, logger, req.source_address));
|
||||
if (selected) {
|
||||
const sql =
|
||||
`SELECT application_sid FROM phone_numbers WHERE number = '${did}'
|
||||
AND voip_carrier_sid = '${selected.voip_carrier_sid}'
|
||||
AND account_sid = '${a[0].account_sid}'`;
|
||||
logger.debug({selected, sql, did}, 'looking up DID');
|
||||
const [r] = await pp.query(sql);
|
||||
|
||||
return {
|
||||
fromCarrier: true,
|
||||
gateway: selected,
|
||||
service_provider_sid: a[0].service_provider_sid,
|
||||
account_sid: a[0].account_sid,
|
||||
application_sid: selected.application_sid,
|
||||
application_sid: r[0]?.application_sid || selected.application_sid,
|
||||
account: a[0]
|
||||
};
|
||||
}
|
||||
@@ -207,12 +214,19 @@ module.exports = (srf, logger) => {
|
||||
const [a] = await pp.query(sqlAccountBySid, [[matches[0].account_sid]]);
|
||||
if (0 === a.length) return failure;
|
||||
logger.debug({matches}, `found registration carrier using ${uri.host} and ${uri.user}`);
|
||||
const sql =
|
||||
`SELECT application_sid FROM phone_numbers WHERE number = '${did}'
|
||||
AND voip_carrier_sid = '${matches[0].voip_carrier_sid}'
|
||||
AND account_sid = '${matches[0].account_sid}'`;
|
||||
logger.debug({matches: matches[0], sql, did}, 'looking up DID');
|
||||
|
||||
const [r] = await pp.query(sql);
|
||||
return {
|
||||
fromCarrier: true,
|
||||
gateway: matches[0],
|
||||
service_provider_sid: a[0].service_provider_sid,
|
||||
account_sid: a[0].account_sid,
|
||||
application_sid: matches[0].application_sid,
|
||||
application_sid: r[0]?.application_sid || matches[0].application_sid,
|
||||
account: a[0]
|
||||
};
|
||||
}
|
||||
@@ -264,7 +278,6 @@ module.exports = (srf, logger) => {
|
||||
if (matches.length) {
|
||||
/* we have one or more matches. Now check for one with a provisioned phone number matching the DID */
|
||||
const vc_sids = matches.map((m) => `'${m.voip_carrier_sid}'`).join(',');
|
||||
const did = normalizeDID(req.calledNumber) || 'anonymous';
|
||||
const sql = `SELECT * FROM phone_numbers WHERE number = '${did}' AND voip_carrier_sid IN (${vc_sids})`;
|
||||
logger.debug({matches, sql, did, vc_sids}, 'looking up DID');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user