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 <stdint.h> |
| 8 |
7 #include <set> | 9 #include <set> |
8 | 10 |
9 #include "base/i18n/icu_encoding_detection.h" | 11 #include "base/i18n/icu_encoding_detection.h" |
10 #include "base/i18n/icu_string_conversions.h" | 12 #include "base/i18n/icu_string_conversions.h" |
11 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
12 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
14 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
15 #include "base/strings/utf_string_conversion_utils.h" | 17 #include "base/strings/utf_string_conversion_utils.h" |
16 #include "base/values.h" | 18 #include "base/values.h" |
17 #include "chromeos/network/network_ui_data.h" | 19 #include "chromeos/network/network_ui_data.h" |
18 #include "chromeos/network/onc/onc_utils.h" | 20 #include "chromeos/network/onc/onc_utils.h" |
19 #include "components/device_event_log/device_event_log.h" | 21 #include "components/device_event_log/device_event_log.h" |
20 #include "third_party/cros_system_api/dbus/service_constants.h" | 22 #include "third_party/cros_system_api/dbus/service_constants.h" |
21 | 23 |
22 namespace chromeos { | 24 namespace chromeos { |
23 | 25 |
24 namespace shill_property_util { | 26 namespace shill_property_util { |
25 | 27 |
26 namespace { | 28 namespace { |
27 | 29 |
28 // Replace non UTF8 characters in |str| with a replacement character. | 30 // Replace non UTF8 characters in |str| with a replacement character. |
29 std::string ValidateUTF8(const std::string& str) { | 31 std::string ValidateUTF8(const std::string& str) { |
30 std::string result; | 32 std::string result; |
31 for (int32 index = 0; index < static_cast<int32>(str.size()); ++index) { | 33 for (int32_t index = 0; index < static_cast<int32_t>(str.size()); ++index) { |
32 uint32 code_point_out; | 34 uint32_t code_point_out; |
33 bool is_unicode_char = base::ReadUnicodeCharacter( | 35 bool is_unicode_char = base::ReadUnicodeCharacter( |
34 str.c_str(), str.size(), &index, &code_point_out); | 36 str.c_str(), str.size(), &index, &code_point_out); |
35 const uint32 kFirstNonControlChar = 0x20; | 37 const uint32_t kFirstNonControlChar = 0x20; |
36 if (is_unicode_char && (code_point_out >= kFirstNonControlChar)) { | 38 if (is_unicode_char && (code_point_out >= kFirstNonControlChar)) { |
37 base::WriteUnicodeCharacter(code_point_out, &result); | 39 base::WriteUnicodeCharacter(code_point_out, &result); |
38 } else { | 40 } else { |
39 const uint32 kReplacementChar = 0xFFFD; | 41 const uint32_t kReplacementChar = 0xFFFD; |
40 // Puts kReplacementChar if character is a control character [0,0x20) | 42 // Puts kReplacementChar if character is a control character [0,0x20) |
41 // or is not readable UTF8. | 43 // or is not readable UTF8. |
42 base::WriteUnicodeCharacter(kReplacementChar, &result); | 44 base::WriteUnicodeCharacter(kReplacementChar, &result); |
43 } | 45 } |
44 } | 46 } |
45 return result; | 47 return result; |
46 } | 48 } |
47 | 49 |
48 // If existent and non-empty, copies the string at |key| from |source| to | 50 // If existent and non-empty, copies the string at |key| from |source| to |
49 // |dest|. Returns true if the string was copied. | 51 // |dest|. Returns true if the string was copied. |
(...skipping 29 matching lines...) Expand all Loading... |
79 std::string hex_ssid; | 81 std::string hex_ssid; |
80 properties.GetStringWithoutPathExpansion(shill::kWifiHexSsid, &hex_ssid); | 82 properties.GetStringWithoutPathExpansion(shill::kWifiHexSsid, &hex_ssid); |
81 | 83 |
82 if (hex_ssid.empty()) { | 84 if (hex_ssid.empty()) { |
83 if (verbose_logging) | 85 if (verbose_logging) |
84 NET_LOG(DEBUG) << "GetSSIDFromProperties: No HexSSID set: " << name; | 86 NET_LOG(DEBUG) << "GetSSIDFromProperties: No HexSSID set: " << name; |
85 return std::string(); | 87 return std::string(); |
86 } | 88 } |
87 | 89 |
88 std::string ssid; | 90 std::string ssid; |
89 std::vector<uint8> raw_ssid_bytes; | 91 std::vector<uint8_t> raw_ssid_bytes; |
90 if (base::HexStringToBytes(hex_ssid, &raw_ssid_bytes)) { | 92 if (base::HexStringToBytes(hex_ssid, &raw_ssid_bytes)) { |
91 ssid = std::string(raw_ssid_bytes.begin(), raw_ssid_bytes.end()); | 93 ssid = std::string(raw_ssid_bytes.begin(), raw_ssid_bytes.end()); |
92 VLOG(2) << "GetSSIDFromProperties: " << name << " HexSsid=" << hex_ssid | 94 VLOG(2) << "GetSSIDFromProperties: " << name << " HexSsid=" << hex_ssid |
93 << " SSID=" << ssid; | 95 << " SSID=" << ssid; |
94 } else { | 96 } else { |
95 NET_LOG(ERROR) << "GetSSIDFromProperties: " << name | 97 NET_LOG(ERROR) << "GetSSIDFromProperties: " << name |
96 << " Error processing HexSsid: " << hex_ssid; | 98 << " Error processing HexSsid: " << hex_ssid; |
97 return std::string(); | 99 return std::string(); |
98 } | 100 } |
99 | 101 |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 LOG(WARNING) | 374 LOG(WARNING) |
373 << "Provider name and country not defined, using code instead: " | 375 << "Provider name and country not defined, using code instead: " |
374 << *home_provider_id; | 376 << *home_provider_id; |
375 } | 377 } |
376 return true; | 378 return true; |
377 } | 379 } |
378 | 380 |
379 } // namespace shill_property_util | 381 } // namespace shill_property_util |
380 | 382 |
381 } // namespace chromeos | 383 } // namespace chromeos |
OLD | NEW |