mirror of
https://github.com/jambonz/sbc-sip-sidecar.git
synced 2025-12-19 04:27:46 +00:00
prevent crash when no Contact header in 200 OK response to REGISTER (#60)
* prevent crash when no Contact header in 200 OK response to REGISTER request * fixed jslint --------- Co-authored-by: Andre Heber <a.heber@cognigy.com>
This commit is contained in:
@@ -109,17 +109,29 @@ class Regbot {
|
|||||||
this.timer = setTimeout(this.register.bind(this, srf), 30 * 1000);
|
this.timer = setTimeout(this.register.bind(this, srf), 30 * 1000);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
|
// the code parses the SIP headers to get the expires value
|
||||||
|
// if there is a Contact header, it will use the expires value from there
|
||||||
|
// otherwise, it will use the Expires header, acording to the SIP RFC 3261, section 10.2.4 Refreshing Bindings
|
||||||
this.status = 'registered';
|
this.status = 'registered';
|
||||||
let expires = DEFAULT_EXPIRES;
|
let expires = DEFAULT_EXPIRES;
|
||||||
const contact = res.getParsedHeader('Contact');
|
|
||||||
if (contact.length > 0 && contact[0].params && contact[0].params.expires) {
|
if (res.has('Expires')) {
|
||||||
if (contact[0].params.expires) expires = parseInt(contact[0].params.expires);
|
|
||||||
}
|
|
||||||
else if (res.has('Expires')) {
|
|
||||||
expires = parseInt(res.get('Expires'));
|
expires = parseInt(res.get('Expires'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (res.has('Contact')) {
|
||||||
|
const contact = res.getParsedHeader('Contact');
|
||||||
|
if (contact.length > 0 && contact[0].params && contact[0].params.expires) {
|
||||||
|
expires = parseInt(contact[0].params.expires);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.logger.info({ aor: this.aor, ipv4: this.ipv4, port: this.port },
|
||||||
|
'no Contact header in 200 OK');
|
||||||
|
}
|
||||||
|
|
||||||
if (isNaN(expires) || expires < MIN_EXPIRES) {
|
if (isNaN(expires) || expires < MIN_EXPIRES) {
|
||||||
this.logger.info({aor: this.aor, ipv4: this.ipv4, port: this.port},
|
this.logger.info({ aor: this.aor, ipv4: this.ipv4, port: this.port },
|
||||||
`got expires of ${expires} in 200 OK, too small so setting to ${MIN_EXPIRES}`);
|
`got expires of ${expires} in 200 OK, too small so setting to ${MIN_EXPIRES}`);
|
||||||
expires = MIN_EXPIRES;
|
expires = MIN_EXPIRES;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user