Skip to content

Commit

Permalink
Make JsSIP.URI and JsSIP.NameAddrHeader more robust.
Browse files Browse the repository at this point in the history
  • Loading branch information
ibc committed Feb 13, 2013
1 parent b0603e3 commit e385840
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/NameAddrHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
},

Expand Down Expand Up @@ -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;
Expand Down
30 changes: 12 additions & 18 deletions src/URI.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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();
}
},

Expand All @@ -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;
}
},

Expand Down Expand Up @@ -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;
}
},

Expand Down Expand Up @@ -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) {
Expand All @@ -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;

Expand Down

0 comments on commit e385840

Please sign in to comment.