OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "net/base/host_mapping_rules.h" | 5 #include "net/base/host_mapping_rules.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/pattern.h" | 8 #include "base/strings/pattern.h" |
9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
10 #include "base/strings/string_tokenizer.h" | 10 #include "base/strings/string_tokenizer.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 } | 67 } |
68 | 68 |
69 bool HostMappingRules::AddRuleFromString(const std::string& rule_string) { | 69 bool HostMappingRules::AddRuleFromString(const std::string& rule_string) { |
70 std::vector<std::string> parts = | 70 std::vector<std::string> parts = |
71 base::SplitString(base::TrimWhitespaceASCII(rule_string, base::TRIM_ALL), | 71 base::SplitString(base::TrimWhitespaceASCII(rule_string, base::TRIM_ALL), |
72 " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 72 " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
73 | 73 |
74 // Test for EXCLUSION rule. | 74 // Test for EXCLUSION rule. |
75 if (parts.size() == 2 && base::LowerCaseEqualsASCII(parts[0], "exclude")) { | 75 if (parts.size() == 2 && base::LowerCaseEqualsASCII(parts[0], "exclude")) { |
76 ExclusionRule rule; | 76 ExclusionRule rule; |
77 rule.hostname_pattern = base::StringToLowerASCII(parts[1]); | 77 rule.hostname_pattern = base::ToLowerASCII(parts[1]); |
78 exclusion_rules_.push_back(rule); | 78 exclusion_rules_.push_back(rule); |
79 return true; | 79 return true; |
80 } | 80 } |
81 | 81 |
82 // Test for MAP rule. | 82 // Test for MAP rule. |
83 if (parts.size() == 3 && base::LowerCaseEqualsASCII(parts[0], "map")) { | 83 if (parts.size() == 3 && base::LowerCaseEqualsASCII(parts[0], "map")) { |
84 MapRule rule; | 84 MapRule rule; |
85 rule.hostname_pattern = base::StringToLowerASCII(parts[1]); | 85 rule.hostname_pattern = base::ToLowerASCII(parts[1]); |
86 | 86 |
87 if (!ParseHostAndPort(parts[2], &rule.replacement_hostname, | 87 if (!ParseHostAndPort(parts[2], &rule.replacement_hostname, |
88 &rule.replacement_port)) { | 88 &rule.replacement_port)) { |
89 return false; // Failed parsing the hostname/port. | 89 return false; // Failed parsing the hostname/port. |
90 } | 90 } |
91 | 91 |
92 map_rules_.push_back(rule); | 92 map_rules_.push_back(rule); |
93 return true; | 93 return true; |
94 } | 94 } |
95 | 95 |
96 return false; | 96 return false; |
97 } | 97 } |
98 | 98 |
99 void HostMappingRules::SetRulesFromString(const std::string& rules_string) { | 99 void HostMappingRules::SetRulesFromString(const std::string& rules_string) { |
100 exclusion_rules_.clear(); | 100 exclusion_rules_.clear(); |
101 map_rules_.clear(); | 101 map_rules_.clear(); |
102 | 102 |
103 base::StringTokenizer rules(rules_string, ","); | 103 base::StringTokenizer rules(rules_string, ","); |
104 while (rules.GetNext()) { | 104 while (rules.GetNext()) { |
105 bool ok = AddRuleFromString(rules.token()); | 105 bool ok = AddRuleFromString(rules.token()); |
106 LOG_IF(ERROR, !ok) << "Failed parsing rule: " << rules.token(); | 106 LOG_IF(ERROR, !ok) << "Failed parsing rule: " << rules.token(); |
107 } | 107 } |
108 } | 108 } |
109 | 109 |
110 } // namespace net | 110 } // namespace net |
OLD | NEW |