| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 } | 113 } |
| 114 | 114 |
| 115 if (unknown_encoding) | 115 if (unknown_encoding) |
| 116 *unknown_encoding = true; | 116 *unknown_encoding = true; |
| 117 NET_LOG_DEBUG( | 117 NET_LOG_DEBUG( |
| 118 "GetSSIDFromProperties", | 118 "GetSSIDFromProperties", |
| 119 base::StringPrintf("Unrecognized Encoding=%s", encoding.c_str())); | 119 base::StringPrintf("Unrecognized Encoding=%s", encoding.c_str())); |
| 120 return ssid; | 120 return ssid; |
| 121 } | 121 } |
| 122 | 122 |
| 123 std::string GetNetworkIdFromProperties( |
| 124 const base::DictionaryValue& properties) { |
| 125 if (properties.empty()) |
| 126 return "EmptyProperties"; |
| 127 std::string result; |
| 128 if (properties.GetStringWithoutPathExpansion(shill::kGuidProperty, &result)) |
| 129 return result; |
| 130 if (properties.GetStringWithoutPathExpansion(shill::kSSIDProperty, &result)) |
| 131 return result; |
| 132 if (properties.GetStringWithoutPathExpansion(shill::kNameProperty, &result)) |
| 133 return result; |
| 134 std::string type = "UnknownType"; |
| 135 properties.GetStringWithoutPathExpansion(shill::kTypeProperty, &type); |
| 136 return "Unidentified " + type; |
| 137 } |
| 138 |
| 123 std::string GetNameFromProperties(const std::string& service_path, | 139 std::string GetNameFromProperties(const std::string& service_path, |
| 124 const base::DictionaryValue& properties) { | 140 const base::DictionaryValue& properties) { |
| 125 std::string name; | 141 std::string name; |
| 126 properties.GetStringWithoutPathExpansion(shill::kNameProperty, &name); | 142 properties.GetStringWithoutPathExpansion(shill::kNameProperty, &name); |
| 127 | 143 |
| 128 std::string validated_name = ValidateUTF8(name); | 144 std::string validated_name = ValidateUTF8(name); |
| 129 if (validated_name != name) { | 145 if (validated_name != name) { |
| 130 NET_LOG_DEBUG("GetNameFromProperties", | 146 NET_LOG_DEBUG("GetNameFromProperties", |
| 131 base::StringPrintf("Validated name %s: UTF8: %s", | 147 base::StringPrintf("Validated name %s: UTF8: %s", |
| 132 service_path.c_str(), | 148 service_path.c_str(), |
| 133 validated_name.c_str())); | 149 validated_name.c_str())); |
| 134 } | 150 } |
| 135 | 151 |
| 136 std::string type; | 152 std::string type; |
| 137 properties.GetStringWithoutPathExpansion(shill::kTypeProperty, &type); | 153 properties.GetStringWithoutPathExpansion(shill::kTypeProperty, &type); |
| 154 if (type.empty()) { |
| 155 NET_LOG_ERROR("GetNameFromProperties: No type", service_path); |
| 156 return validated_name; |
| 157 } |
| 138 if (!NetworkTypePattern::WiFi().MatchesType(type)) | 158 if (!NetworkTypePattern::WiFi().MatchesType(type)) |
| 139 return validated_name; | 159 return validated_name; |
| 140 | 160 |
| 141 bool unknown_ssid_encoding = false; | 161 bool unknown_ssid_encoding = false; |
| 142 std::string ssid = GetSSIDFromProperties(properties, &unknown_ssid_encoding); | 162 std::string ssid = GetSSIDFromProperties(properties, &unknown_ssid_encoding); |
| 143 if (ssid.empty()) | 163 if (ssid.empty()) |
| 144 NET_LOG_ERROR("GetNameFromProperties", "No SSID set: " + service_path); | 164 NET_LOG_ERROR("GetNameFromProperties", "No SSID set: " + service_path); |
| 145 | 165 |
| 146 // Use |validated_name| if |ssid| is empty. | 166 // Use |validated_name| if |ssid| is empty. |
| 147 // And if the encoding of the SSID is unknown, use |ssid|, which contains raw | 167 // And if the encoding of the SSID is unknown, use |ssid|, which contains raw |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 CopyStringFromDictionary(service_properties, shill::kWifiHexSsid, dest); | 235 CopyStringFromDictionary(service_properties, shill::kWifiHexSsid, dest); |
| 216 success &= CopyStringFromDictionary( | 236 success &= CopyStringFromDictionary( |
| 217 service_properties, shill::kModeProperty, dest); | 237 service_properties, shill::kModeProperty, dest); |
| 218 } else if (type == shill::kTypeVPN) { | 238 } else if (type == shill::kTypeVPN) { |
| 219 success &= CopyStringFromDictionary( | 239 success &= CopyStringFromDictionary( |
| 220 service_properties, shill::kNameProperty, dest); | 240 service_properties, shill::kNameProperty, dest); |
| 221 // VPN Provider values are read from the "Provider" dictionary, but written | 241 // VPN Provider values are read from the "Provider" dictionary, but written |
| 222 // with the keys "Provider.Type" and "Provider.Host". | 242 // with the keys "Provider.Type" and "Provider.Host". |
| 223 const base::DictionaryValue* provider_properties = NULL; | 243 const base::DictionaryValue* provider_properties = NULL; |
| 224 if (!service_properties.GetDictionaryWithoutPathExpansion( | 244 if (!service_properties.GetDictionaryWithoutPathExpansion( |
| 225 shill::kProviderProperty, &provider_properties)) { | 245 shill::kProviderProperty, &provider_properties)) { |
| 226 NET_LOG_ERROR("CopyIdentifyingProperties", "Missing VPN provider dict"); | 246 NET_LOG_ERROR("Missing VPN provider dict", |
| 247 GetNetworkIdFromProperties(service_properties)); |
| 227 return false; | 248 return false; |
| 228 } | 249 } |
| 229 std::string vpn_provider_type; | 250 std::string vpn_provider_type; |
| 230 provider_properties->GetStringWithoutPathExpansion(shill::kTypeProperty, | 251 provider_properties->GetStringWithoutPathExpansion(shill::kTypeProperty, |
| 231 &vpn_provider_type); | 252 &vpn_provider_type); |
| 232 success &= !vpn_provider_type.empty(); | 253 success &= !vpn_provider_type.empty(); |
| 233 dest->SetStringWithoutPathExpansion(shill::kProviderTypeProperty, | 254 dest->SetStringWithoutPathExpansion(shill::kProviderTypeProperty, |
| 234 vpn_provider_type); | 255 vpn_provider_type); |
| 235 | 256 |
| 236 std::string vpn_provider_host; | 257 std::string vpn_provider_host; |
| 237 provider_properties->GetStringWithoutPathExpansion(shill::kHostProperty, | 258 provider_properties->GetStringWithoutPathExpansion(shill::kHostProperty, |
| 238 &vpn_provider_host); | 259 &vpn_provider_host); |
| 239 success &= !vpn_provider_host.empty(); | 260 success &= !vpn_provider_host.empty(); |
| 240 dest->SetStringWithoutPathExpansion(shill::kProviderHostProperty, | 261 dest->SetStringWithoutPathExpansion(shill::kProviderHostProperty, |
| 241 vpn_provider_host); | 262 vpn_provider_host); |
| 242 } else if (type == shill::kTypeEthernet || type == shill::kTypeEthernetEap) { | 263 } else if (type == shill::kTypeEthernet || type == shill::kTypeEthernetEap) { |
| 243 // Ethernet and EthernetEAP don't have any additional identifying | 264 // Ethernet and EthernetEAP don't have any additional identifying |
| 244 // properties. | 265 // properties. |
| 245 } else { | 266 } else { |
| 246 NOTREACHED() << "Unsupported network type " << type; | 267 NOTREACHED() << "Unsupported network type " << type; |
| 247 success = false; | 268 success = false; |
| 248 } | 269 } |
| 249 if (!success) | 270 if (!success) { |
| 250 NET_LOG_ERROR("CopyIdentifyingProperties", "Missing required properties"); | 271 NET_LOG_ERROR("Missing required properties", |
| 272 GetNetworkIdFromProperties(service_properties)); |
| 273 } |
| 251 return success; | 274 return success; |
| 252 } | 275 } |
| 253 | 276 |
| 254 bool DoIdentifyingPropertiesMatch(const base::DictionaryValue& properties_a, | 277 bool DoIdentifyingPropertiesMatch(const base::DictionaryValue& properties_a, |
| 255 const base::DictionaryValue& properties_b) { | 278 const base::DictionaryValue& properties_b) { |
| 256 base::DictionaryValue identifying_a; | 279 base::DictionaryValue identifying_a; |
| 257 if (!CopyIdentifyingProperties(properties_a, &identifying_a)) | 280 if (!CopyIdentifyingProperties(properties_a, &identifying_a)) |
| 258 return false; | 281 return false; |
| 259 base::DictionaryValue identifying_b; | 282 base::DictionaryValue identifying_b; |
| 260 if (!CopyIdentifyingProperties(properties_b, &identifying_b)) | 283 if (!CopyIdentifyingProperties(properties_b, &identifying_b)) |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 if (!str.empty()) | 433 if (!str.empty()) |
| 411 str += "|"; | 434 str += "|"; |
| 412 str += shill_type_to_flag[i].shill_network_type; | 435 str += shill_type_to_flag[i].shill_network_type; |
| 413 } | 436 } |
| 414 return str; | 437 return str; |
| 415 } | 438 } |
| 416 | 439 |
| 417 NetworkTypePattern::NetworkTypePattern(int pattern) : pattern_(pattern) {} | 440 NetworkTypePattern::NetworkTypePattern(int pattern) : pattern_(pattern) {} |
| 418 | 441 |
| 419 } // namespace chromeos | 442 } // namespace chromeos |
| OLD | NEW |