Skip to content

Commit

Permalink
In case null, emptry string, undefined or NaN is passed as parameter …
Browse files Browse the repository at this point in the history
…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 8cb6963
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/UA.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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];
}

Expand Down

0 comments on commit 8cb6963

Please sign in to comment.