Skip to content
Permalink
Browse files

In case null, emptry string, undefined or NaN is passed as parameter …

…value then its default value is applied.

Also print to console the processed value of all the parameters after validating them.
  • Loading branch information
ibc committed Feb 4, 2013
1 parent f306d3c commit 8cb6963bee5881668a680d352fbfbfd363ef33f4
Showing with 15 additions and 4 deletions.
  1. +15 −4 src/UA.js
@@ -599,7 +599,7 @@ JsSIP.UA.prototype.recoverTransport = function(ua) {
*/
JsSIP.UA.prototype.loadConfig = function(configuration) {
// Settings and default values
var parameter, attribute, idx, uri, ws_uri, contact,
var parameter, attribute, idx, uri, ws_uri, contact, value,
settings = {
/* Host address
* Value to be set in Via sent_by and host part of Contact FQDN
@@ -677,10 +677,18 @@ JsSIP.UA.prototype.loadConfig = function(configuration) {
// Check Optional parameters
for(parameter in JsSIP.UA.configuration_check.optional) {
if(configuration.hasOwnProperty(parameter)) {
if(JsSIP.UA.configuration_check.optional[parameter](configuration[parameter])) {
settings[parameter] = configuration[parameter];
value = configuration[parameter];

// If the parameter value is null, empty string or undefined then apply its default value.
if(value === null || value === "" || value === undefined) { continue; }
// If it's a number with NaN value then also apply its default value.
// NOTE: JS does not allow "value === NaN", the following does the work:
else if(typeof(value) === 'number' && window.isNaN(value)) { continue; }

if(JsSIP.UA.configuration_check.optional[parameter](value)) {
settings[parameter] = value;
} else {
console.error('Bad configuration parameter: ' + parameter);
console.error('Bad configuration parameter ' + parameter + ' with value ' + window.String(value));
return false;
}
}
@@ -751,7 +759,10 @@ JsSIP.UA.prototype.loadConfig = function(configuration) {
}

// Fill the value of the configuration_skeleton
console.log('configuration parameters after validation:');
for(attribute in settings) {
value = settings[attribute];
console.log('· ' + attribute + ': ' + window.String(settings[attribute]));
JsSIP.UA.configuration_skeleton[attribute].value = settings[attribute];
}

0 comments on commit 8cb6963

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