Skip to content

Commit

Permalink
Bug 1055380 - Cast network configs into correct data type. r=hchang
Browse files Browse the repository at this point in the history
  • Loading branch information
chuck-lee committed Aug 29, 2014
1 parent 460b0a7 commit b285bf0
Showing 1 changed file with 40 additions and 9 deletions.
49 changes: 40 additions & 9 deletions dom/wifi/WifiWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -1163,20 +1163,45 @@ var WifiManager = (function() {
manager.reassociate = wifiCommand.reassociate;

var networkConfigurationFields = [
"ssid", "bssid", "psk", "wep_key0", "wep_key1", "wep_key2", "wep_key3",
"wep_tx_keyidx", "priority", "key_mgmt", "scan_ssid", "disabled",
"identity", "password", "auth_alg", "phase1", "phase2", "eap", "pin",
"pcsc", "ca_cert", "subject_match"
{name: "ssid", type: "string"},
{name: "bssid", type: "string"},
{name: "psk", type: "string"},
{name: "wep_key0", type: "string"},
{name: "wep_key1", type: "string"},
{name: "wep_key2", type: "string"},
{name: "wep_key3", type: "string"},
{name: "wep_tx_keyidx", type: "integer"},
{name: "priority", type: "integer"},
{name: "key_mgmt", type: "string"},
{name: "scan_ssid", type: "string"},
{name: "disabled", type: "integer"},
{name: "identity", type: "string"},
{name: "password", type: "string"},
{name: "auth_alg", type: "string"},
{name: "phase1", type: "string"},
{name: "phase2", type: "string"},
{name: "eap", type: "string"},
{name: "pin", type: "string"},
{name: "pcsc", type: "string"},
{name: "ca_cert", type: "string"},
{name: "subject_match", type: "string"}
];

manager.getNetworkConfiguration = function(config, callback) {
var netId = config.netId;
var done = 0;
for (var n = 0; n < networkConfigurationFields.length; ++n) {
let fieldName = networkConfigurationFields[n];
let fieldName = networkConfigurationFields[n].name;
let fieldType = networkConfigurationFields[n].type;
wifiCommand.getNetworkVariable(netId, fieldName, function(value) {
if (value !== null)
config[fieldName] = value;
if (value !== null) {
if (fieldType === "integer") {
config[fieldName] = parseInt(value, 10);
} else {
// value is string type by default.
config[fieldName] = value;
}
}
if (++done == networkConfigurationFields.length)
callback(config);
});
Expand All @@ -1195,7 +1220,7 @@ var WifiManager = (function() {
}

for (var n = 0; n < networkConfigurationFields.length; ++n) {
let fieldName = networkConfigurationFields[n];
let fieldName = networkConfigurationFields[n].name;
if (!hasValidProperty(fieldName)) {
++done;
} else {
Expand Down Expand Up @@ -2518,8 +2543,10 @@ WifiWorker.prototype = {
continue;
}

if (network.priority && network.priority > this._highestPriority)
if (network.hasOwnProperty("priority") &&
network.priority > this._highestPriority) {
this._highestPriority = network.priority;
}

let networkKey = getNetworkKey(network);
// Accept latest config of same network(same SSID and same security).
Expand Down Expand Up @@ -3148,6 +3175,10 @@ WifiWorker.prototype = {
privnet.priority = ++this._highestPriority;
if (configured) {
privnet.netId = configured.netId;
// Sync priority back to configured so if priority reaches MAX_PRIORITY,
// it can be sorted correctly in _reprioritizeNetworks() because the
// function sort network based on priority in configure list.
configured.priority = privnet.priority;
WifiManager.updateNetwork(privnet, (function(ok) {
if (!ok) {
this._sendMessage(message, false, "Network is misconfigured", msg);
Expand Down

0 comments on commit b285bf0

Please sign in to comment.