From e385840542da905bf4197c5adb61722f9fbba5a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Wed, 13 Feb 2013 15:42:04 +0100 Subject: [PATCH] Make JsSIP.URI and JsSIP.NameAddrHeader more robust. --- src/NameAddrHeader.js | 4 ++-- src/URI.js | 30 ++++++++++++------------------ 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/NameAddrHeader.js b/src/NameAddrHeader.js index dd088b880..7a0961400 100644 --- a/src/NameAddrHeader.js +++ b/src/NameAddrHeader.js @@ -48,7 +48,7 @@ JsSIP.NameAddrHeader.prototype = { hasParam: function(key) { if(key) { - return this.parameters.hasOwnProperty(key.toLowerCase()) && true || false; + return (this.parameters.hasOwnProperty(key.toLowerCase()) && true) || false; } }, @@ -81,7 +81,7 @@ JsSIP.NameAddrHeader.prototype = { for (parameter in this.parameters) { body += ';' + parameter; - body += (this.parameters[parameter] === null)? '' : '=' + this.parameters[parameter]; + body += (this.parameters[parameter] === null) ? '' : '=' + this.parameters[parameter]; } return body; diff --git a/src/URI.js b/src/URI.js index cb801946b..76c612be0 100644 --- a/src/URI.js +++ b/src/URI.js @@ -18,6 +18,8 @@ JsSIP.URI = function(scheme, user, host, port, parameters, headers) { throw new TypeError('missing or invalid "host" parameter'); } + this.scheme = scheme || JsSIP.C.SIP; + // Initialize parameters this.parameters = {}; this.headers = {}; @@ -62,7 +64,7 @@ JsSIP.URI = function(scheme, user, host, port, parameters, headers) { JsSIP.URI.prototype = { setParam: function(key, value) { if(key) { - this.parameters[key.toLowerCase()] = (typeof value === 'undefined' || value === null)? null : value.toString().toLowerCase(); + this.parameters[key.toLowerCase()] = (typeof value === 'undefined' || value === null) ? null : value.toString().toLowerCase(); } }, @@ -74,7 +76,7 @@ JsSIP.URI.prototype = { hasParam: function(key) { if(key) { - return this.parameters.hasOwnProperty(key.toLowerCase()) && true || false; + return (this.parameters.hasOwnProperty(key.toLowerCase()) && true) || false; } }, @@ -104,7 +106,7 @@ JsSIP.URI.prototype = { hasHeader: function(name) { if(name) { - return this.headers.hasOwnProperty(name.toLowerCase()) && true || false; + return (this.headers.hasOwnProperty(name.toLowerCase()) && true) || false; } }, @@ -133,24 +135,17 @@ JsSIP.URI.prototype = { }, toString: function(){ - var header, parameter, idx, - headers = [], - uri = ''; - - if(!this.host) { - console.error(JsSIP.C.LOG_URI +'cannot print a SIP URI without host'); - throw new TypeError('cannot print a SIP URI without host'); - } + var header, parameter, idx, uri, + headers = []; - uri = this.scheme || JsSIP.C.SIP; - uri += ':'; + uri = this.scheme + ':'; uri += this.user ? JsSIP.Utils.escapeUser(this.user) + '@' : ''; uri += this.host; uri += this.port ? ':' + this.port : ''; for (parameter in this.parameters) { - uri += ';'+ parameter.toLowerCase(); - uri += (this.parameters[parameter] === null )? '' : '=' + this.parameters[parameter]; + uri += ';'+ parameter; + uri += (this.parameters[parameter] === null) ? '' : '=' + this.parameters[parameter]; } for(header in this.headers) { @@ -166,10 +161,9 @@ JsSIP.URI.prototype = { return uri; }, toAor: function(){ - var aor = ''; + var aor; - aor += this.scheme || JsSIP.C.SIP; - aor += ':'; + aor = this.scheme + ':'; aor += this.user ? JsSIP.Utils.escapeUser(this.user) + '@' : ''; aor += this.host;