Skip to content
Permalink
Browse files

Add JsSIP.URI and JsSIP.NameAddrHeader classes

  • Loading branch information
jmillan committed Jan 31, 2013
2 parents f4f9cf3 + 7b345bf commit 9fad09b653c951da855d99451ca21a6a8e0816ba
Showing with 608 additions and 263 deletions.
  1. +2 −0 grunt.js
  2. +4 −4 src/Message.js
  3. +86 −0 src/NameAddrHeader.js
  4. +3 −3 src/Parser.js
  5. +5 −5 src/Registrator.js
  6. +2 −2 src/SIPMessage.js
  7. +1 −1 src/SanityCheck.js
  8. +4 −4 src/Session.js
  9. +173 −0 src/URI.js
  10. +3 −0 src/constants.js
  11. +97 −58 src/grammar/dist/grammar.js
  12. +133 −131 src/grammar/dist/grammar.min.js
  13. +54 −31 src/grammar/src/grammar.pegjs
  14. +41 −24 src/utils.js
@@ -22,6 +22,8 @@ module.exports = function(grunt) {
"src/Transport.js",
"src/Parser.js",
"src/SIPMessage.js",
"src/URI.js",
"src/NameAddrHeader.js",
"src/Transactions.js",
"src/Dialogs.js",
"src/RequestSender.js",
@@ -41,14 +41,14 @@ JsSIP.Message.prototype.send = function(target, body, contentType, options) {
}

// Check target validity
target = JsSIP.utils.normalizeUri(target, this.ua.configuration.domain);
target = JsSIP.utils.normalizeURI(target, this.ua.configuration.domain);
if (!target) {
throw new JsSIP.exceptions.InvalidTargetError();
}

// Message parameter initialization
this.direction = 'outgoing';
this.local_identity = this.ua.configuration.user;
this.local_identity = this.ua.configuration.from_uri;
this.remote_identity = target;

this.closed = false;
@@ -164,8 +164,8 @@ JsSIP.Message.prototype.init_incoming = function(request) {

this.direction = 'incoming';
this.request = request;
this.local_identity = request.s('to').uri;
this.remote_identity = request.s('from').uri;
this.local_identity = request.s('to').uri.toAor();
this.remote_identity = request.s('from').uri.toAor();

if (contentType && (contentType.match(/^text\/plain(\s*;\s*.+)*$/i) || contentType.match(/^text\/html(\s*;\s*.+)*$/i))) {
this.ua.emit('newMessage', this.ua, {
@@ -0,0 +1,86 @@
/**
* @augments JsSIP
* @class Class creating a Name Address SIP header.
*
* @param {JsSIP.URI} uri
* @param {String} [display_name]
* @param {Object} [parameters]
*
*/
JsSIP.NameAddrHeader = function(uri, display_name, parameters) {
var param;

// Checks
if(!uri || !uri instanceof JsSIP.URI) {
console.warn('Missing or invalid "uri" in NameAddrHeader');
throw new JsSIP.exceptions.InvalidValueError();
}

// Initialize parameters
this.uri = uri;
this.parameters = {};

for (param in parameters) {
this.setParam(param, parameters[param]);
}

Object.defineProperties(this, {
display_name: {
get: function() { return display_name; },
set: function(value) {
display_name = value;
}
}
});
};
JsSIP.NameAddrHeader.prototype = {
setParam: function(key, value) {
if (key) {
this.parameters[key.toLowerCase()] = (typeof value === 'undefined' || value === null)? null : value.toString();
}
},

getParam: function(key) {
if(key) {
return this.parameters[key.toLowerCase()];
}
},

hasParam: function(key) {
if(key) {
return this.parameters.hasOwnProperty(key.toLowerCase()) && true || false;
}
},

deleteParam: function(parameter) {
parameter = parameter.toLowerCase();
if (this.parameters.hasOwnProperty(parameter)) {
delete this.parameters[parameter];
}
},

clearParams: function() {
this.parameters = {};
},

clone: function() {
return new JsSIP.NameAddrHeader(
this.uri.clone(),
this.display_name,
window.JSON.parse(window.JSON.stringify(this.parameters)));
},

toString: function() {
var body, parameter;

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


for (parameter in this.parameters) {
body += ';' + parameter;
body += (this.parameters[parameter] === null)? '' : '=' + this.parameters[parameter];
}
return body;
}
};
@@ -73,7 +73,7 @@ JsSIP.Parser = {
parsed = message.parseHeader('from');
if(parsed) {
message.from = parsed;
message.from_tag = parsed.tag;
message.from_tag = parsed.getParam('tag');
}
break;
case 'to':
@@ -82,7 +82,7 @@ JsSIP.Parser = {
parsed = message.parseHeader('to');
if(parsed) {
message.to = parsed;
message.to_tag = parsed.tag;
message.to_tag = parsed.getParam('tag');
}
break;
case 'record-route':
@@ -191,7 +191,7 @@ JsSIP.Parser = {
} else if(!parsed.status_code) {
message = new JsSIP.IncomingRequest();
message.method = parsed.method;
message.ruri = parsed;
message.ruri = parsed.uri;
} else {
message = new JsSIP.IncomingResponse();
message.status_code = parsed.status_code;
@@ -94,7 +94,7 @@ JsSIP.Registrator.prototype = {
while(contacts--) {
contact = response.parseHeader('contact', contacts);
if(contact.uri === this.ua.contact.uri) {
expires = contact.params.expires;
expires = contact.getParam('expires');
break;
}
}
@@ -115,11 +115,11 @@ JsSIP.Registrator.prototype = {
}, (expires * 1000) - 3000);

//Save gruu values
if (contact.params['temp-gruu']) {
this.ua.contact.temp_gruu = contact.params['temp-gruu'].replace(/"/g,'');
if (contact.hasParam('temp-gruu')) {
this.ua.contact.temp_gruu = contact.getParam('temp-gruu').replace(/"/g,'');
}
if (contact.params['pub-gruu']) {
this.ua.contact.pub_gruu = contact.params['pub-gruu'].replace(/"/g,'');
if (contact.hasParam('pub-gruu')) {
this.ua.contact.pub_gruu = contact.getParam('pub-gruu').replace(/"/g,'');
}

this.registered = true;
@@ -378,7 +378,7 @@ JsSIP.IncomingRequest.prototype.reply = function(code, reason, extraHeaders, bod

if(!this.to_tag) {
to += ';tag=' + JsSIP.utils.newTag();
} else if(this.to_tag && !this.s('to').tag) {
} else if(this.to_tag && !this.s('to').hasParam('tag')) {
to += ';tag=' + this.to_tag;
}

@@ -435,7 +435,7 @@ JsSIP.IncomingRequest.prototype.reply_sl = function(code, reason) {

if(!this.to_tag) {
to += ';tag=' + JsSIP.utils.newTag();
} else if(this.to_tag && !this.s('to').tag) {
} else if(this.to_tag && !this.s('to').hasParam('tag')) {
to += ';tag=' + this.to_tag;
}

@@ -36,7 +36,7 @@ JsSIP.sanityCheck = (function() {

// Sanity Check functions for requests
function rfc3261_8_2_2_1() {
if(message.s('to').scheme !== 'sip') {
if(message.s('to').uri.scheme !== 'sip') {
reply(416);
return false;
}
@@ -103,7 +103,7 @@ JsSIP.Session.prototype.connect = function(target, options) {
}

// Check target validity
target = JsSIP.utils.normalizeUri(target, this.ua.configuration.domain);
target = JsSIP.utils.normalizeURI(target, this.ua.configuration.domain);
if (!target) {
throw new JsSIP.exceptions.InvalidTargetError();
}
@@ -746,10 +746,10 @@ JsSIP.Session.prototype.newSession = function(originator, request, target) {
session.direction = (originator === 'local') ? 'outgoing' : 'incoming';

if (originator === 'remote') {
session.local_identity = request.s('to').uri;
session.remote_identity = request.s('from').uri;
session.local_identity = request.s('to').uri.toAor();
session.remote_identity = request.s('from').uri.toAor();
} else if (originator === 'local'){
session.local_identity = session.ua.configuration.user;
session.local_identity = session.ua.configuration.from_uri;
session.remote_identity = target;
}

0 comments on commit 9fad09b

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