Skip to content

Commit

Permalink
Intelligent 'Allow' header field value.
Browse files Browse the repository at this point in the history
Do not set a method in the 'Allow' header field if its corresponding event is not defined or has zero listeners.
  • Loading branch information
jmillan committed Nov 20, 2012
1 parent 4e70a25 commit 1ab3423
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Registrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ JsSIP.Registrator.prototype = {
'cseq': (this.cseq += 1)
}, [
'Contact: '+ this.contact + ';expires=' + this.expires,
'Allow: '+ JsSIP.c.ALLOWED_METHODS
'Allow: '+ JsSIP.utils.getAllowedMethods(this.ua)
]);

request_sender = new JsSIP.RequestSender(this, this.ua);
Expand Down
2 changes: 1 addition & 1 deletion src/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ JsSIP.Session.prototype.connect = function(target, options) {
}

extraHeaders.push('Contact: <'+ this.contact + ';ob>');
extraHeaders.push('Allow: '+ JsSIP.c.ALLOWED_METHODS);
extraHeaders.push('Allow: '+ JsSIP.utils.getAllowedMethods(this.ua));
extraHeaders.push('Content-Type: application/sdp');

request = new JsSIP.OutgoingRequest(JsSIP.c.INVITE, target, this.ua, requestParams, extraHeaders);
Expand Down
2 changes: 1 addition & 1 deletion src/UA.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ JsSIP.UA.prototype.receiveRequest = function(request) {
*/
if(method === JsSIP.c.OPTIONS) {
request.reply(200, JsSIP.c.REASON_200, [
'Allow: '+ JsSIP.c.ALLOWED_METHODS,
'Allow: '+ JsSIP.utils.getAllowedMethods(this),
'Accept: '+ JsSIP.c.ACCEPTED_BODY_TYPES
]);
}
Expand Down
8 changes: 7 additions & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,5 +198,11 @@ JsSIP.c = {
ALLOWED_METHODS: 'INVITE, ACK, CANCEL, BYE, OPTIONS, MESSAGE, SUBSCRIBE',
SUPPORTED: 'path, outbound, gruu',
ACCEPTED_BODY_TYPES: 'application/sdp',
TAG_LENGTH: 10
TAG_LENGTH: 10,

// User Agent EVENT METHODS
UA_EVENT_METHODS: {
'newSession': 'INVITE',
'newMessage': 'MESSAGE'
}
};
13 changes: 13 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,19 @@ JsSIP.utils = {
}
},

getAllowedMethods: function(ua) {
var event,
allowed = JsSIP.c.ALLOWED_METHODS.split(', ');

for (event in JsSIP.c.UA_EVENT_METHODS) {
if (!ua.checkEvent(event) || ua.listeners(event).length === 0) {
allowed.splice(allowed.indexOf(JsSIP.c.UA_EVENT_METHODS[event]), 1);
}
}

return allowed.join(', ');
},

// MD5 (Message-Digest Algorithm) http://www.webtoolkit.info
MD5: function(string) {
function RotateLeft(lValue, iShiftBits) {
Expand Down

0 comments on commit 1ab3423

Please sign in to comment.