OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromeos/network/shill_property_util.h" | 5 #include "chromeos/network/shill_property_util.h" |
6 | 6 |
7 #include "base/i18n/icu_encoding_detection.h" | 7 #include "base/i18n/icu_encoding_detection.h" |
8 #include "base/i18n/icu_string_conversions.h" | 8 #include "base/i18n/icu_string_conversions.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 } else { | 36 } else { |
37 const uint32 kReplacementChar = 0xFFFD; | 37 const uint32 kReplacementChar = 0xFFFD; |
38 // Puts kReplacementChar if character is a control character [0,0x20) | 38 // Puts kReplacementChar if character is a control character [0,0x20) |
39 // or is not readable UTF8. | 39 // or is not readable UTF8. |
40 base::WriteUnicodeCharacter(kReplacementChar, &result); | 40 base::WriteUnicodeCharacter(kReplacementChar, &result); |
41 } | 41 } |
42 } | 42 } |
43 return result; | 43 return result; |
44 } | 44 } |
45 | 45 |
46 void CopyStringFromDictionary(const base::DictionaryValue& source, | 46 // If existent and non-empty, copies the string at |key| from |source| to |
| 47 // |dest|. Returns true if the string was copied. |
| 48 bool CopyStringFromDictionary(const base::DictionaryValue& source, |
47 const std::string& key, | 49 const std::string& key, |
48 base::DictionaryValue* dest) { | 50 base::DictionaryValue* dest) { |
49 std::string string_value; | 51 std::string string_value; |
50 if (source.GetStringWithoutPathExpansion(key, &string_value)) | 52 if (!source.GetStringWithoutPathExpansion(key, &string_value) || |
51 dest->SetStringWithoutPathExpansion(key, string_value); | 53 string_value.empty()) |
| 54 return false; |
| 55 dest->SetStringWithoutPathExpansion(key, string_value); |
| 56 return true; |
52 } | 57 } |
53 | 58 |
54 } // namespace | 59 } // namespace |
55 | 60 |
56 std::string GetNameFromProperties(const std::string& service_path, | 61 std::string GetNameFromProperties(const std::string& service_path, |
57 const base::DictionaryValue& properties) { | 62 const base::DictionaryValue& properties) { |
58 std::string name, hex_ssid; | 63 std::string name, hex_ssid; |
59 properties.GetStringWithoutPathExpansion(flimflam::kNameProperty, &name); | 64 properties.GetStringWithoutPathExpansion(flimflam::kNameProperty, &name); |
60 properties.GetStringWithoutPathExpansion(flimflam::kWifiHexSsid, &hex_ssid); | 65 properties.GetStringWithoutPathExpansion(flimflam::kWifiHexSsid, &hex_ssid); |
61 | 66 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 base::DictionaryValue ui_data_dict; | 173 base::DictionaryValue ui_data_dict; |
169 ui_data.FillDictionary(&ui_data_dict); | 174 ui_data.FillDictionary(&ui_data_dict); |
170 std::string ui_data_blob; | 175 std::string ui_data_blob; |
171 base::JSONWriter::Write(&ui_data_dict, &ui_data_blob); | 176 base::JSONWriter::Write(&ui_data_dict, &ui_data_blob); |
172 shill_dictionary->SetStringWithoutPathExpansion(flimflam::kUIDataProperty, | 177 shill_dictionary->SetStringWithoutPathExpansion(flimflam::kUIDataProperty, |
173 ui_data_blob); | 178 ui_data_blob); |
174 } | 179 } |
175 | 180 |
176 bool CopyIdentifyingProperties(const base::DictionaryValue& service_properties, | 181 bool CopyIdentifyingProperties(const base::DictionaryValue& service_properties, |
177 base::DictionaryValue* dest) { | 182 base::DictionaryValue* dest) { |
| 183 bool success = true; |
| 184 |
| 185 // GUID is optional. |
178 CopyStringFromDictionary(service_properties, flimflam::kGuidProperty, dest); | 186 CopyStringFromDictionary(service_properties, flimflam::kGuidProperty, dest); |
179 | 187 |
180 std::string type; | 188 std::string type; |
181 service_properties.GetStringWithoutPathExpansion(flimflam::kTypeProperty, | 189 service_properties.GetStringWithoutPathExpansion(flimflam::kTypeProperty, |
182 &type); | 190 &type); |
| 191 success &= !type.empty(); |
183 dest->SetStringWithoutPathExpansion(flimflam::kTypeProperty, type); | 192 dest->SetStringWithoutPathExpansion(flimflam::kTypeProperty, type); |
184 if (type == flimflam::kTypeWifi) { | 193 if (type == flimflam::kTypeWifi) { |
185 CopyStringFromDictionary( | 194 success &= CopyStringFromDictionary( |
186 service_properties, flimflam::kSecurityProperty, dest); | 195 service_properties, flimflam::kSecurityProperty, dest); |
187 CopyStringFromDictionary(service_properties, flimflam::kSSIDProperty, dest); | 196 success &= CopyStringFromDictionary( |
188 CopyStringFromDictionary(service_properties, flimflam::kModeProperty, dest); | 197 service_properties, flimflam::kSSIDProperty, dest); |
| 198 success &= CopyStringFromDictionary( |
| 199 service_properties, flimflam::kModeProperty, dest); |
189 } else if (type == flimflam::kTypeVPN) { | 200 } else if (type == flimflam::kTypeVPN) { |
190 CopyStringFromDictionary(service_properties, flimflam::kNameProperty, dest); | 201 success &= CopyStringFromDictionary( |
| 202 service_properties, flimflam::kNameProperty, dest); |
191 // VPN Provider values are read from the "Provider" dictionary, but written | 203 // VPN Provider values are read from the "Provider" dictionary, but written |
192 // with the keys "Provider.Type" and "Provider.Host". | 204 // with the keys "Provider.Type" and "Provider.Host". |
193 const base::DictionaryValue* provider_properties; | 205 const base::DictionaryValue* provider_properties = NULL; |
194 if (!service_properties.GetDictionaryWithoutPathExpansion( | 206 if (!service_properties.GetDictionaryWithoutPathExpansion( |
195 flimflam::kProviderProperty, &provider_properties)) { | 207 flimflam::kProviderProperty, &provider_properties)) { |
196 LOG(ERROR) << "Incomplete Shill dictionary missing VPN provider dict."; | 208 NET_LOG_ERROR("CopyIdentifyingProperties", "Missing VPN provider dict"); |
197 return false; | 209 return false; |
198 } | 210 } |
199 std::string vpn_provider_type; | 211 std::string vpn_provider_type; |
200 provider_properties->GetStringWithoutPathExpansion(flimflam::kTypeProperty, | 212 provider_properties->GetStringWithoutPathExpansion(flimflam::kTypeProperty, |
201 &vpn_provider_type); | 213 &vpn_provider_type); |
| 214 success &= !vpn_provider_type.empty(); |
202 dest->SetStringWithoutPathExpansion(flimflam::kProviderTypeProperty, | 215 dest->SetStringWithoutPathExpansion(flimflam::kProviderTypeProperty, |
203 vpn_provider_type); | 216 vpn_provider_type); |
204 | 217 |
205 std::string vpn_provider_host; | 218 std::string vpn_provider_host; |
206 provider_properties->GetStringWithoutPathExpansion(flimflam::kHostProperty, | 219 provider_properties->GetStringWithoutPathExpansion(flimflam::kHostProperty, |
207 &vpn_provider_host); | 220 &vpn_provider_host); |
| 221 success &= !vpn_provider_host.empty(); |
208 dest->SetStringWithoutPathExpansion(flimflam::kProviderHostProperty, | 222 dest->SetStringWithoutPathExpansion(flimflam::kProviderHostProperty, |
209 vpn_provider_host); | 223 vpn_provider_host); |
210 } else if (type == flimflam::kTypeEthernet || | 224 } else if (type == flimflam::kTypeEthernet || |
211 type == shill::kTypeEthernetEap) { | 225 type == shill::kTypeEthernetEap) { |
212 // Ethernet and EthernetEAP don't have any additional identifying | 226 // Ethernet and EthernetEAP don't have any additional identifying |
213 // properties. | 227 // properties. |
214 } else { | 228 } else { |
215 NOTREACHED() << "Unsupported network type " << type; | 229 NOTREACHED() << "Unsupported network type " << type; |
| 230 success = false; |
216 } | 231 } |
217 return true; | 232 if (!success) |
| 233 NET_LOG_ERROR("CopyIdentifyingProperties", "Missing required properties"); |
| 234 return success; |
218 } | 235 } |
219 | 236 |
220 } // namespace shill_property_util | 237 } // namespace shill_property_util |
221 | 238 |
222 } // namespace chromeos | 239 } // namespace chromeos |
OLD | NEW |