OLD | NEW |
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 <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 result->GetStringWithoutPathExpansion(::onc::ipconfig::kType, &type); | 601 result->GetStringWithoutPathExpansion(::onc::ipconfig::kType, &type); |
602 int lower_bound = 1; | 602 int lower_bound = 1; |
603 // In case of missing type, choose higher upper_bound. | 603 // In case of missing type, choose higher upper_bound. |
604 int upper_bound = (type == kIPv4) ? 32 : 128; | 604 int upper_bound = (type == kIPv4) ? 32 : 128; |
605 if (FieldExistsAndIsNotInRange( | 605 if (FieldExistsAndIsNotInRange( |
606 *result, kRoutingPrefix, lower_bound, upper_bound)) { | 606 *result, kRoutingPrefix, lower_bound, upper_bound)) { |
607 return false; | 607 return false; |
608 } | 608 } |
609 | 609 |
610 bool all_required_exist = RequireField(*result, kIPAddress) && | 610 bool all_required_exist = RequireField(*result, kIPAddress) && |
611 RequireField(*result, kRoutingPrefix) && | |
612 RequireField(*result, ::onc::ipconfig::kType); | 611 RequireField(*result, ::onc::ipconfig::kType); |
| 612 if (result->HasKey(kIPAddress)) |
| 613 all_required_exist &= RequireField(*result, kRoutingPrefix); |
| 614 |
613 | 615 |
614 return !error_on_missing_field_ || all_required_exist; | 616 return !error_on_missing_field_ || all_required_exist; |
615 } | 617 } |
616 | 618 |
617 bool Validator::ValidateWiFi(base::DictionaryValue* result) { | 619 bool Validator::ValidateWiFi(base::DictionaryValue* result) { |
618 using namespace ::onc::wifi; | 620 using namespace ::onc::wifi; |
619 | 621 |
620 const char* const kValidSecurities[] = {kSecurityNone, kWEP_PSK, kWEP_8021X, | 622 const char* const kValidSecurities[] = {kSecurityNone, kWEP_PSK, kWEP_8021X, |
621 kWPA_PSK, kWPA_EAP}; | 623 kWPA_PSK, kWPA_EAP}; |
622 const std::vector<const char*> valid_securities(toVector(kValidSecurities)); | 624 const std::vector<const char*> valid_securities(toVector(kValidSecurities)); |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 } | 906 } |
905 | 907 |
906 std::string Validator::MessageHeader() { | 908 std::string Validator::MessageHeader() { |
907 std::string path = path_.empty() ? "toplevel" : JoinString(path_, "."); | 909 std::string path = path_.empty() ? "toplevel" : JoinString(path_, "."); |
908 std::string message = "At " + path + ": "; | 910 std::string message = "At " + path + ": "; |
909 return message; | 911 return message; |
910 } | 912 } |
911 | 913 |
912 } // namespace onc | 914 } // namespace onc |
913 } // namespace chromeos | 915 } // namespace chromeos |
OLD | NEW |