Skip to content

Commit

Permalink
Improvements and some bug fixes in URI and NameAddrHeader classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ibc committed Feb 13, 2013
1 parent fda507a commit 826ce12
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/NameAddrHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ JsSIP.NameAddrHeader = function(uri, display_name, parameters) {
JsSIP.NameAddrHeader.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 Down Expand Up @@ -76,7 +76,7 @@ JsSIP.NameAddrHeader.prototype = {
toString: function() {
var body, parameter;

body = (this.display_name) ? '"' + this.display_name + '" ' : '';
body = (this.display_name || this.display_name === 0) ? '"' + this.display_name + '" ' : '';
body += '<' + this.uri.toString() + '>';

for (parameter in this.parameters) {
Expand Down
19 changes: 12 additions & 7 deletions src/URI.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ JsSIP.URI = function(scheme, user, host, port, parameters, headers) {
throw new TypeError('missing or invalid "host" parameter');
}

scheme = scheme || JsSIP.C.SIP;

// Initialize parameters
scheme = scheme || JsSIP.C.SIP;
this.parameters = {};
this.headers = {};

Expand Down Expand Up @@ -56,7 +55,7 @@ JsSIP.URI = function(scheme, user, host, port, parameters, headers) {
port: {
get: function(){ return port; },
set: function(value){
port = parseInt(value,10);
port = value === 0 ? value : (parseInt(value,10) || null);
}
}
});
Expand Down Expand Up @@ -106,7 +105,7 @@ JsSIP.URI.prototype = {

hasHeader: function(name) {
if(name) {
return (this.headers.hasOwnProperty(name.toLowerCase()) && true) || false;
return (this.headers.hasOwnProperty(JsSIP.Utils.headerize(name)) && true) || false;
}
},

Expand Down Expand Up @@ -139,9 +138,13 @@ JsSIP.URI.prototype = {
headers = [];

uri = this.scheme + ':';
uri += this.user ? JsSIP.Utils.escapeUser(this.user) + '@' : '';
if (this.user) {
uri += JsSIP.Utils.escapeUser(this.user) + '@';
}
uri += this.host;
uri += this.port ? ':' + this.port : '';
if (this.port || this.port === 0) {
uri += ':' + this.port;
}

for (parameter in this.parameters) {
uri += ';'+ parameter;
Expand All @@ -164,7 +167,9 @@ JsSIP.URI.prototype = {
var aor;

aor = this.scheme + ':';
aor += this.user ? JsSIP.Utils.escapeUser(this.user) + '@' : '';
if (this.user) {
aor += JsSIP.Utils.escapeUser(this.user) + '@';
}
aor += this.host;

return aor;
Expand Down

0 comments on commit 826ce12

Please sign in to comment.