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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 return false; | 54 return false; |
55 dest->SetStringWithoutPathExpansion(key, string_value); | 55 dest->SetStringWithoutPathExpansion(key, string_value); |
56 return true; | 56 return true; |
57 } | 57 } |
58 | 58 |
59 } // namespace | 59 } // namespace |
60 | 60 |
61 std::string GetNameFromProperties(const std::string& service_path, | 61 std::string GetNameFromProperties(const std::string& service_path, |
62 const base::DictionaryValue& properties) { | 62 const base::DictionaryValue& properties) { |
63 std::string name, hex_ssid; | 63 std::string name, hex_ssid; |
64 properties.GetStringWithoutPathExpansion(flimflam::kNameProperty, &name); | 64 properties.GetStringWithoutPathExpansion(shill::kNameProperty, &name); |
65 properties.GetStringWithoutPathExpansion(flimflam::kWifiHexSsid, &hex_ssid); | 65 properties.GetStringWithoutPathExpansion(shill::kWifiHexSsid, &hex_ssid); |
66 | 66 |
67 if (hex_ssid.empty()) { | 67 if (hex_ssid.empty()) { |
68 if (name.empty()) | 68 if (name.empty()) |
69 return name; | 69 return name; |
70 // Validate name for UTF8. | 70 // Validate name for UTF8. |
71 std::string valid_ssid = ValidateUTF8(name); | 71 std::string valid_ssid = ValidateUTF8(name); |
72 if (valid_ssid != name) { | 72 if (valid_ssid != name) { |
73 NET_LOG_DEBUG( | 73 NET_LOG_DEBUG( |
74 "GetNameFromProperties", | 74 "GetNameFromProperties", |
75 base::StringPrintf( | 75 base::StringPrintf( |
(...skipping 23 matching lines...) Expand all Loading... |
99 if (ssid != name) { | 99 if (ssid != name) { |
100 NET_LOG_DEBUG("GetNameFromProperties", | 100 NET_LOG_DEBUG("GetNameFromProperties", |
101 base::StringPrintf( | 101 base::StringPrintf( |
102 "%s: UTF8: %s", service_path.c_str(), ssid.c_str())); | 102 "%s: UTF8: %s", service_path.c_str(), ssid.c_str())); |
103 } | 103 } |
104 return ssid; | 104 return ssid; |
105 } | 105 } |
106 | 106 |
107 // Detect encoding and convert to UTF-8. | 107 // Detect encoding and convert to UTF-8. |
108 std::string country_code; | 108 std::string country_code; |
109 properties.GetStringWithoutPathExpansion(flimflam::kCountryProperty, | 109 properties.GetStringWithoutPathExpansion(shill::kCountryProperty, |
110 &country_code); | 110 &country_code); |
111 std::string encoding; | 111 std::string encoding; |
112 if (!base::DetectEncoding(ssid, &encoding)) { | 112 if (!base::DetectEncoding(ssid, &encoding)) { |
113 // TODO(stevenjb): This is currently experimental. If we find a case where | 113 // TODO(stevenjb): This is currently experimental. If we find a case where |
114 // base::DetectEncoding() fails, we need to figure out whether we can use | 114 // base::DetectEncoding() fails, we need to figure out whether we can use |
115 // country_code with ConvertToUtf8(). crbug.com/233267. | 115 // country_code with ConvertToUtf8(). crbug.com/233267. |
116 encoding = country_code; | 116 encoding = country_code; |
117 } | 117 } |
118 if (!encoding.empty()) { | 118 if (!encoding.empty()) { |
119 std::string utf8_ssid; | 119 std::string utf8_ssid; |
(...skipping 29 matching lines...) Expand all Loading... |
149 scoped_ptr<base::DictionaryValue> ui_data_dict( | 149 scoped_ptr<base::DictionaryValue> ui_data_dict( |
150 chromeos::onc::ReadDictionaryFromJson(ui_data_str)); | 150 chromeos::onc::ReadDictionaryFromJson(ui_data_str)); |
151 if (!ui_data_dict) | 151 if (!ui_data_dict) |
152 return scoped_ptr<NetworkUIData>(); | 152 return scoped_ptr<NetworkUIData>(); |
153 return make_scoped_ptr(new NetworkUIData(*ui_data_dict)); | 153 return make_scoped_ptr(new NetworkUIData(*ui_data_dict)); |
154 } | 154 } |
155 | 155 |
156 scoped_ptr<NetworkUIData> GetUIDataFromProperties( | 156 scoped_ptr<NetworkUIData> GetUIDataFromProperties( |
157 const base::DictionaryValue& shill_dictionary) { | 157 const base::DictionaryValue& shill_dictionary) { |
158 const base::Value* ui_data_value = NULL; | 158 const base::Value* ui_data_value = NULL; |
159 shill_dictionary.GetWithoutPathExpansion(flimflam::kUIDataProperty, | 159 shill_dictionary.GetWithoutPathExpansion(shill::kUIDataProperty, |
160 &ui_data_value); | 160 &ui_data_value); |
161 if (!ui_data_value) { | 161 if (!ui_data_value) { |
162 VLOG(2) << "Dictionary has no UIData entry."; | 162 VLOG(2) << "Dictionary has no UIData entry."; |
163 return scoped_ptr<NetworkUIData>(); | 163 return scoped_ptr<NetworkUIData>(); |
164 } | 164 } |
165 scoped_ptr<NetworkUIData> ui_data = GetUIDataFromValue(*ui_data_value); | 165 scoped_ptr<NetworkUIData> ui_data = GetUIDataFromValue(*ui_data_value); |
166 if (!ui_data) | 166 if (!ui_data) |
167 LOG(ERROR) << "UIData is not a valid JSON dictionary."; | 167 LOG(ERROR) << "UIData is not a valid JSON dictionary."; |
168 return ui_data.Pass(); | 168 return ui_data.Pass(); |
169 } | 169 } |
170 | 170 |
171 void SetUIData(const NetworkUIData& ui_data, | 171 void SetUIData(const NetworkUIData& ui_data, |
172 base::DictionaryValue* shill_dictionary) { | 172 base::DictionaryValue* shill_dictionary) { |
173 base::DictionaryValue ui_data_dict; | 173 base::DictionaryValue ui_data_dict; |
174 ui_data.FillDictionary(&ui_data_dict); | 174 ui_data.FillDictionary(&ui_data_dict); |
175 std::string ui_data_blob; | 175 std::string ui_data_blob; |
176 base::JSONWriter::Write(&ui_data_dict, &ui_data_blob); | 176 base::JSONWriter::Write(&ui_data_dict, &ui_data_blob); |
177 shill_dictionary->SetStringWithoutPathExpansion(flimflam::kUIDataProperty, | 177 shill_dictionary->SetStringWithoutPathExpansion(shill::kUIDataProperty, |
178 ui_data_blob); | 178 ui_data_blob); |
179 } | 179 } |
180 | 180 |
181 bool CopyIdentifyingProperties(const base::DictionaryValue& service_properties, | 181 bool CopyIdentifyingProperties(const base::DictionaryValue& service_properties, |
182 base::DictionaryValue* dest) { | 182 base::DictionaryValue* dest) { |
183 bool success = true; | 183 bool success = true; |
184 | 184 |
185 // GUID is optional. | 185 // GUID is optional. |
186 CopyStringFromDictionary(service_properties, flimflam::kGuidProperty, dest); | 186 CopyStringFromDictionary(service_properties, shill::kGuidProperty, dest); |
187 | 187 |
188 std::string type; | 188 std::string type; |
189 service_properties.GetStringWithoutPathExpansion(flimflam::kTypeProperty, | 189 service_properties.GetStringWithoutPathExpansion(shill::kTypeProperty, &type); |
190 &type); | |
191 success &= !type.empty(); | 190 success &= !type.empty(); |
192 dest->SetStringWithoutPathExpansion(flimflam::kTypeProperty, type); | 191 dest->SetStringWithoutPathExpansion(shill::kTypeProperty, type); |
193 if (type == flimflam::kTypeWifi) { | 192 if (type == shill::kTypeWifi) { |
194 success &= CopyStringFromDictionary( | 193 success &= CopyStringFromDictionary( |
195 service_properties, flimflam::kSecurityProperty, dest); | 194 service_properties, shill::kSecurityProperty, dest); |
196 success &= CopyStringFromDictionary( | 195 success &= CopyStringFromDictionary( |
197 service_properties, flimflam::kSSIDProperty, dest); | 196 service_properties, shill::kSSIDProperty, dest); |
198 success &= CopyStringFromDictionary( | 197 success &= CopyStringFromDictionary( |
199 service_properties, flimflam::kModeProperty, dest); | 198 service_properties, shill::kModeProperty, dest); |
200 } else if (type == flimflam::kTypeVPN) { | 199 } else if (type == shill::kTypeVPN) { |
201 success &= CopyStringFromDictionary( | 200 success &= CopyStringFromDictionary( |
202 service_properties, flimflam::kNameProperty, dest); | 201 service_properties, shill::kNameProperty, dest); |
203 // VPN Provider values are read from the "Provider" dictionary, but written | 202 // VPN Provider values are read from the "Provider" dictionary, but written |
204 // with the keys "Provider.Type" and "Provider.Host". | 203 // with the keys "Provider.Type" and "Provider.Host". |
205 const base::DictionaryValue* provider_properties = NULL; | 204 const base::DictionaryValue* provider_properties = NULL; |
206 if (!service_properties.GetDictionaryWithoutPathExpansion( | 205 if (!service_properties.GetDictionaryWithoutPathExpansion( |
207 flimflam::kProviderProperty, &provider_properties)) { | 206 shill::kProviderProperty, &provider_properties)) { |
208 NET_LOG_ERROR("CopyIdentifyingProperties", "Missing VPN provider dict"); | 207 NET_LOG_ERROR("CopyIdentifyingProperties", "Missing VPN provider dict"); |
209 return false; | 208 return false; |
210 } | 209 } |
211 std::string vpn_provider_type; | 210 std::string vpn_provider_type; |
212 provider_properties->GetStringWithoutPathExpansion(flimflam::kTypeProperty, | 211 provider_properties->GetStringWithoutPathExpansion(shill::kTypeProperty, |
213 &vpn_provider_type); | 212 &vpn_provider_type); |
214 success &= !vpn_provider_type.empty(); | 213 success &= !vpn_provider_type.empty(); |
215 dest->SetStringWithoutPathExpansion(flimflam::kProviderTypeProperty, | 214 dest->SetStringWithoutPathExpansion(shill::kProviderTypeProperty, |
216 vpn_provider_type); | 215 vpn_provider_type); |
217 | 216 |
218 std::string vpn_provider_host; | 217 std::string vpn_provider_host; |
219 provider_properties->GetStringWithoutPathExpansion(flimflam::kHostProperty, | 218 provider_properties->GetStringWithoutPathExpansion(shill::kHostProperty, |
220 &vpn_provider_host); | 219 &vpn_provider_host); |
221 success &= !vpn_provider_host.empty(); | 220 success &= !vpn_provider_host.empty(); |
222 dest->SetStringWithoutPathExpansion(flimflam::kProviderHostProperty, | 221 dest->SetStringWithoutPathExpansion(shill::kProviderHostProperty, |
223 vpn_provider_host); | 222 vpn_provider_host); |
224 } else if (type == flimflam::kTypeEthernet || | 223 } else if (type == shill::kTypeEthernet || type == shill::kTypeEthernetEap) { |
225 type == shill::kTypeEthernetEap) { | |
226 // Ethernet and EthernetEAP don't have any additional identifying | 224 // Ethernet and EthernetEAP don't have any additional identifying |
227 // properties. | 225 // properties. |
228 } else { | 226 } else { |
229 NOTREACHED() << "Unsupported network type " << type; | 227 NOTREACHED() << "Unsupported network type " << type; |
230 success = false; | 228 success = false; |
231 } | 229 } |
232 if (!success) | 230 if (!success) |
233 NET_LOG_ERROR("CopyIdentifyingProperties", "Missing required properties"); | 231 NET_LOG_ERROR("CopyIdentifyingProperties", "Missing required properties"); |
234 return success; | 232 return success; |
235 } | 233 } |
(...skipping 15 matching lines...) Expand all Loading... |
251 kNetworkTypeWimax = 1 << 2, | 249 kNetworkTypeWimax = 1 << 2, |
252 kNetworkTypeCellular = 1 << 3, | 250 kNetworkTypeCellular = 1 << 3, |
253 kNetworkTypeVPN = 1 << 4, | 251 kNetworkTypeVPN = 1 << 4, |
254 kNetworkTypeEthernetEap = 1 << 5 | 252 kNetworkTypeEthernetEap = 1 << 5 |
255 }; | 253 }; |
256 | 254 |
257 struct ShillToBitFlagEntry { | 255 struct ShillToBitFlagEntry { |
258 const char* shill_network_type; | 256 const char* shill_network_type; |
259 NetworkTypeBitFlag bit_flag; | 257 NetworkTypeBitFlag bit_flag; |
260 } shill_type_to_flag[] = { | 258 } shill_type_to_flag[] = { |
261 { flimflam::kTypeEthernet, kNetworkTypeEthernet }, | 259 { shill::kTypeEthernet, kNetworkTypeEthernet }, |
262 { shill::kTypeEthernetEap, kNetworkTypeEthernetEap }, | 260 { shill::kTypeEthernetEap, kNetworkTypeEthernetEap }, |
263 { flimflam::kTypeWifi, kNetworkTypeWifi }, | 261 { shill::kTypeWifi, kNetworkTypeWifi }, |
264 { flimflam::kTypeWimax, kNetworkTypeWimax }, | 262 { shill::kTypeWimax, kNetworkTypeWimax }, |
265 { flimflam::kTypeCellular, kNetworkTypeCellular }, | 263 { shill::kTypeCellular, kNetworkTypeCellular }, |
266 { flimflam::kTypeVPN, kNetworkTypeVPN } | 264 { shill::kTypeVPN, kNetworkTypeVPN } |
267 }; | 265 }; |
268 | 266 |
269 NetworkTypeBitFlag ShillNetworkTypeToFlag(const std::string& shill_type) { | 267 NetworkTypeBitFlag ShillNetworkTypeToFlag(const std::string& shill_type) { |
270 for (size_t i = 0; i < arraysize(shill_type_to_flag); ++i) { | 268 for (size_t i = 0; i < arraysize(shill_type_to_flag); ++i) { |
271 if (shill_type_to_flag[i].shill_network_type == shill_type) | 269 if (shill_type_to_flag[i].shill_network_type == shill_type) |
272 return shill_type_to_flag[i].bit_flag; | 270 return shill_type_to_flag[i].bit_flag; |
273 } | 271 } |
274 NET_LOG_ERROR("ShillNetworkTypeToFlag", "Unknown type: " + shill_type); | 272 NET_LOG_ERROR("ShillNetworkTypeToFlag", "Unknown type: " + shill_type); |
275 return kNetworkTypeNone; | 273 return kNetworkTypeNone; |
276 } | 274 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 if (!str.empty()) | 363 if (!str.empty()) |
366 str += "|"; | 364 str += "|"; |
367 str += shill_type_to_flag[i].shill_network_type; | 365 str += shill_type_to_flag[i].shill_network_type; |
368 } | 366 } |
369 return str; | 367 return str; |
370 } | 368 } |
371 | 369 |
372 NetworkTypePattern::NetworkTypePattern(int pattern) : pattern_(pattern) {} | 370 NetworkTypePattern::NetworkTypePattern(int pattern) : pattern_(pattern) {} |
373 | 371 |
374 } // namespace chromeos | 372 } // namespace chromeos |
OLD | NEW |