From b0d3e6bbac291aa76ae870c5bab2d5c46bd4a074 Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Wed, 29 Jul 2020 08:13:10 -0400 Subject: [PATCH] fixes for sending calls to sip endpoint that challenges --- lib/call-session.js | 5 +++-- lib/middleware.js | 2 +- test/db/jambones-sql.sql | 4 +++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/call-session.js b/lib/call-session.js index cff4aa7..db5fb72 100644 --- a/lib/call-session.js +++ b/lib/call-session.js @@ -126,12 +126,13 @@ class CallSession extends Emitter { let earlyMedia = false; while (uris.length) { const uri = uris.shift(); + const passFailure = 0 === uris.length; // only a single target debug(`sending INVITE to ${uri} via ${proxy})`); this.logger.info(`sending INVITE to ${uri}`); try { const {uas, uac} = await this.srf.createB2BUA(this.req, this.res, uri, { proxy, - passFailure: false, + passFailure, proxyRequestHeaders: ['all', '-X-MS-Teams-FQDN', '-X-MS-Teams-Tenant-FQDN', '-Allow', '-Session-Expires', 'Min-SE'], proxyResponseHeaders: ['all', '-Allow'], @@ -172,7 +173,7 @@ class CallSession extends Emitter { if (err instanceof SipError) this.logger.info(`final call failure ${err.status}`); else this.logger.error(err, 'unexpected call failure'); debug(`got final outdial error: ${err}`); - this.res.send(err.status || 500); + if (!passFailure) this.res.send(err.status || 500); this.emit('failed'); this.rtpEngineResource.destroy(); const tags = ['accepted:no', `sipStatus:${err.status || 500}`]; diff --git a/lib/middleware.js b/lib/middleware.js index 6050b22..1db1441 100644 --- a/lib/middleware.js +++ b/lib/middleware.js @@ -69,7 +69,7 @@ function route(opts) { return next(); } } - else if (!isLocalUri(uri.host, req) /*|| !dotDecimalHost */) { + if (!dotDecimalHost || !isLocalUri(uri.host, req)) { // TODO: need to try to forward calls to a DNS host name // so long as that domain name is not associated with an account or SP in our DB logger.info(`forwarding call to sip endpoint ${req.uri}`); diff --git a/test/db/jambones-sql.sql b/test/db/jambones-sql.sql index 22254b8..950467b 100644 --- a/test/db/jambones-sql.sql +++ b/test/db/jambones-sql.sql @@ -55,7 +55,9 @@ api_key_sid CHAR(36) NOT NULL UNIQUE , token CHAR(36) NOT NULL UNIQUE , account_sid CHAR(36), service_provider_sid CHAR(36), -expires_at TIMESTAMP, +expires_at TIMESTAMP NULL, +last_used TIMESTAMP NULL, +created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (api_key_sid) ) ENGINE=InnoDB COMMENT='An authorization token that is used to access the REST api';