Skip to content
Permalink
Browse files

Make JsSIP.URI and JsSIP.NameAddrHeader more robust.

  • Loading branch information
ibc committed Feb 13, 2013
1 parent b0603e3 commit e385840542da905bf4197c5adb61722f9fbba5a4
Showing with 14 additions and 20 deletions.
  1. +2 −2 src/NameAddrHeader.js
  2. +12 −18 src/URI.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;
@@ -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;

0 comments on commit e385840

Please sign in to comment.
You can’t perform that action at this time.