Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: chromeos/network/onc/onc_validator.cc

Issue 2818593003: [CrOS Tether] Add tether network properties (battery percentage, carrier, and signal strength) to t… (Closed)
Patch Set: stevenjb@ comments. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/onc/onc_validator.h" 5 #include "chromeos/network/onc/onc_validator.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 } else if (&signature == &kGlobalNetworkConfigurationSignature) { 122 } else if (&signature == &kGlobalNetworkConfigurationSignature) {
123 valid = ValidateGlobalNetworkConfiguration(repaired.get()); 123 valid = ValidateGlobalNetworkConfiguration(repaired.get());
124 } else if (&signature == &kProxySettingsSignature) { 124 } else if (&signature == &kProxySettingsSignature) {
125 valid = ValidateProxySettings(repaired.get()); 125 valid = ValidateProxySettings(repaired.get());
126 } else if (&signature == &kProxyLocationSignature) { 126 } else if (&signature == &kProxyLocationSignature) {
127 valid = ValidateProxyLocation(repaired.get()); 127 valid = ValidateProxyLocation(repaired.get());
128 } else if (&signature == &kEAPSignature) { 128 } else if (&signature == &kEAPSignature) {
129 valid = ValidateEAP(repaired.get()); 129 valid = ValidateEAP(repaired.get());
130 } else if (&signature == &kCertificateSignature) { 130 } else if (&signature == &kCertificateSignature) {
131 valid = ValidateCertificate(repaired.get()); 131 valid = ValidateCertificate(repaired.get());
132 } else if (&signature == &kTetherSignature) {
133 valid = ValidateTether(repaired.get());
132 } 134 }
133 } 135 }
134 136
135 if (valid) 137 if (valid)
136 return repaired; 138 return repaired;
137 139
138 DCHECK(error_or_warning_found_); 140 DCHECK(error_or_warning_found_);
139 error_or_warning_found_ = *error = true; 141 error_or_warning_found_ = *error = true;
140 return std::unique_ptr<base::DictionaryValue>(); 142 return std::unique_ptr<base::DictionaryValue>();
141 } 143 }
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 542
541 if (IsGlobalNetworkConfigInUserImport(*result)) 543 if (IsGlobalNetworkConfigInUserImport(*result))
542 return false; 544 return false;
543 545
544 return true; 546 return true;
545 } 547 }
546 548
547 bool Validator::ValidateNetworkConfiguration(base::DictionaryValue* result) { 549 bool Validator::ValidateNetworkConfiguration(base::DictionaryValue* result) {
548 using namespace ::onc::network_config; 550 using namespace ::onc::network_config;
549 551
550 const char* const kValidTypes[] = {::onc::network_type::kEthernet, 552 const char* const kValidTypes[] = {
551 ::onc::network_type::kVPN, 553 ::onc::network_type::kEthernet, ::onc::network_type::kVPN,
552 ::onc::network_type::kWiFi, 554 ::onc::network_type::kWiFi, ::onc::network_type::kCellular,
553 ::onc::network_type::kCellular, 555 ::onc::network_type::kWimax, ::onc::network_type::kTether};
554 ::onc::network_type::kWimax};
555 const std::vector<const char*> valid_types(toVector(kValidTypes)); 556 const std::vector<const char*> valid_types(toVector(kValidTypes));
556 const char* const kValidIPConfigTypes[] = {kIPConfigTypeDHCP, 557 const char* const kValidIPConfigTypes[] = {kIPConfigTypeDHCP,
557 kIPConfigTypeStatic}; 558 kIPConfigTypeStatic};
558 const std::vector<const char*> valid_ipconfig_types( 559 const std::vector<const char*> valid_ipconfig_types(
559 toVector(kValidIPConfigTypes)); 560 toVector(kValidIPConfigTypes));
560 if (FieldExistsAndHasNoValidValue(*result, kType, valid_types) || 561 if (FieldExistsAndHasNoValidValue(*result, kType, valid_types) ||
561 FieldExistsAndHasNoValidValue(*result, kIPAddressConfigType, 562 FieldExistsAndHasNoValidValue(*result, kIPAddressConfigType,
562 valid_ipconfig_types) || 563 valid_ipconfig_types) ||
563 FieldExistsAndHasNoValidValue(*result, kNameServersConfigType, 564 FieldExistsAndHasNoValidValue(*result, kNameServersConfigType,
564 valid_ipconfig_types) || 565 valid_ipconfig_types) ||
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 all_required_exist &= 610 all_required_exist &=
610 RequireField(*result, ::onc::network_config::kEthernet); 611 RequireField(*result, ::onc::network_config::kEthernet);
611 } else if (type == ::onc::network_type::kCellular) { 612 } else if (type == ::onc::network_type::kCellular) {
612 all_required_exist &= 613 all_required_exist &=
613 RequireField(*result, ::onc::network_config::kCellular); 614 RequireField(*result, ::onc::network_config::kCellular);
614 } else if (type == ::onc::network_type::kWimax) { 615 } else if (type == ::onc::network_type::kWimax) {
615 all_required_exist &= 616 all_required_exist &=
616 RequireField(*result, ::onc::network_config::kWimax); 617 RequireField(*result, ::onc::network_config::kWimax);
617 } else if (type == ::onc::network_type::kVPN) { 618 } else if (type == ::onc::network_type::kVPN) {
618 all_required_exist &= RequireField(*result, ::onc::network_config::kVPN); 619 all_required_exist &= RequireField(*result, ::onc::network_config::kVPN);
620 } else if (type == ::onc::network_type::kTether) {
621 all_required_exist &=
622 RequireField(*result, ::onc::network_config::kTether);
619 } 623 }
620 } 624 }
621 625
622 return !error_on_missing_field_ || all_required_exist; 626 return !error_on_missing_field_ || all_required_exist;
623 } 627 }
624 628
625 bool Validator::ValidateEthernet(base::DictionaryValue* result) { 629 bool Validator::ValidateEthernet(base::DictionaryValue* result) {
626 using namespace ::onc::ethernet; 630 using namespace ::onc::ethernet;
627 631
628 const char* const kValidAuthentications[] = {kAuthenticationNone, k8021X}; 632 const char* const kValidAuthentications[] = {kAuthenticationNone, k8021X};
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 if (onc_source_ != ::onc::ONC_SOURCE_DEVICE_POLICY) { 895 if (onc_source_ != ::onc::ONC_SOURCE_DEVICE_POLICY) {
892 error_or_warning_found_ = true; 896 error_or_warning_found_ = true;
893 LOG(ERROR) 897 LOG(ERROR)
894 << "AllowOnlyPolicyNetworksToConnect only allowed in device policy."; 898 << "AllowOnlyPolicyNetworksToConnect only allowed in device policy.";
895 return false; 899 return false;
896 } 900 }
897 } 901 }
898 902
899 // Ensure the list contains only legitimate network type identifiers. 903 // Ensure the list contains only legitimate network type identifiers.
900 const char* const kValidNetworkTypeValues[] = {kCellular, kEthernet, kWiFi, 904 const char* const kValidNetworkTypeValues[] = {kCellular, kEthernet, kWiFi,
901 kWimax}; 905 kWimax, kTether};
902 const std::vector<const char*> valid_network_type_values( 906 const std::vector<const char*> valid_network_type_values(
903 toVector(kValidNetworkTypeValues)); 907 toVector(kValidNetworkTypeValues));
904 if (!ListFieldContainsValidValues(*result, kDisableNetworkTypes, 908 if (!ListFieldContainsValidValues(*result, kDisableNetworkTypes,
905 valid_network_type_values)) { 909 valid_network_type_values)) {
906 return false; 910 return false;
907 } 911 }
908 return true; 912 return true;
909 } 913 }
910 914
911 bool Validator::ValidateProxySettings(base::DictionaryValue* result) { 915 bool Validator::ValidateProxySettings(base::DictionaryValue* result) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 all_required_exist &= RequireField(*result, kType); 1012 all_required_exist &= RequireField(*result, kType);
1009 1013
1010 if (type == kClient) 1014 if (type == kClient)
1011 all_required_exist &= RequireField(*result, kPKCS12); 1015 all_required_exist &= RequireField(*result, kPKCS12);
1012 else if (type == kServer || type == kAuthority) 1016 else if (type == kServer || type == kAuthority)
1013 all_required_exist &= RequireField(*result, kX509); 1017 all_required_exist &= RequireField(*result, kX509);
1014 1018
1015 return !error_on_missing_field_ || all_required_exist; 1019 return !error_on_missing_field_ || all_required_exist;
1016 } 1020 }
1017 1021
1022 bool Validator::ValidateTether(base::DictionaryValue* result) {
1023 using namespace ::onc::tether;
1024
1025 int batteryPercentage;
1026 if (!result->GetIntegerWithoutPathExpansion(kBatteryPercentage,
1027 &batteryPercentage) ||
1028 batteryPercentage < 0 || batteryPercentage > 100) {
1029 // Battery percentage must be present and within [0, 100].
1030 error_or_warning_found_ = true;
1031 return false;
1032 }
1033
1034 int signalStrength;
1035 if (!result->GetIntegerWithoutPathExpansion(kSignalStrength,
1036 &signalStrength) ||
1037 signalStrength < 0 || signalStrength > 100) {
1038 // Signal strength must be present and within [0, 100].
1039 error_or_warning_found_ = true;
1040 return false;
1041 }
1042
1043 std::string carrier;
1044 if (!result->GetStringWithoutPathExpansion(kCarrier,
1045 &carrier) || carrier.empty()) {
1046 LOG(ERROR) << "here";
stevenjb 2017/04/18 23:34:14 ?
Kyle Horimoto 2017/04/18 23:41:13 Sorry - debug log. Removed it.
1047 // Carrier must be a non-empty string.
1048 error_or_warning_found_ = true;
1049 return false;
1050 }
1051
1052 // No required fields.
1053 return true;
1054 }
1055
1018 std::string Validator::MessageHeader() { 1056 std::string Validator::MessageHeader() {
1019 std::string path = path_.empty() ? "toplevel" : base::JoinString(path_, "."); 1057 std::string path = path_.empty() ? "toplevel" : base::JoinString(path_, ".");
1020 std::string message = "At " + path + ": "; 1058 std::string message = "At " + path + ": ";
1021 return message; 1059 return message;
1022 } 1060 }
1023 1061
1024 } // namespace onc 1062 } // namespace onc
1025 } // namespace chromeos 1063 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698