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/string_tokenizer.h" | 8 #include "base/string_tokenizer.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "net/base/host_port_pair.h" | 10 #include "net/base/host_port_pair.h" |
11 #include "net/base/net_util.h" | 11 #include "net/base/net_util.h" |
12 | 12 |
13 namespace net { | 13 namespace net { |
14 | 14 |
| 15 struct HostMappingRules::MapRule { |
| 16 MapRule() : replacement_port(-1) {} |
| 17 |
| 18 std::string hostname_pattern; |
| 19 std::string replacement_hostname; |
| 20 int replacement_port; |
| 21 }; |
| 22 |
| 23 struct HostMappingRules::ExclusionRule { |
| 24 std::string hostname_pattern; |
| 25 }; |
| 26 |
15 HostMappingRules::HostMappingRules() {} | 27 HostMappingRules::HostMappingRules() {} |
16 | 28 |
| 29 HostMappingRules::~HostMappingRules() {} |
| 30 |
17 bool HostMappingRules::RewriteHost(HostPortPair* host_port) const { | 31 bool HostMappingRules::RewriteHost(HostPortPair* host_port) const { |
18 // Check if the hostname was excluded. | 32 // Check if the hostname was excluded. |
19 for (ExclusionRuleList::const_iterator it = exclusion_rules_.begin(); | 33 for (ExclusionRuleList::const_iterator it = exclusion_rules_.begin(); |
20 it != exclusion_rules_.end(); ++it) { | 34 it != exclusion_rules_.end(); ++it) { |
21 const ExclusionRule& rule = *it; | 35 const ExclusionRule& rule = *it; |
22 if (MatchPattern(host_port->host(), rule.hostname_pattern)) | 36 if (MatchPattern(host_port->host(), rule.hostname_pattern)) |
23 return false; | 37 return false; |
24 } | 38 } |
25 | 39 |
26 // Check if the hostname was remapped. | 40 // Check if the hostname was remapped. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 map_rules_.clear(); | 100 map_rules_.clear(); |
87 | 101 |
88 StringTokenizer rules(rules_string, ","); | 102 StringTokenizer rules(rules_string, ","); |
89 while (rules.GetNext()) { | 103 while (rules.GetNext()) { |
90 bool ok = AddRuleFromString(rules.token()); | 104 bool ok = AddRuleFromString(rules.token()); |
91 LOG_IF(ERROR, !ok) << "Failed parsing rule: " << rules.token(); | 105 LOG_IF(ERROR, !ok) << "Failed parsing rule: " << rules.token(); |
92 } | 106 } |
93 } | 107 } |
94 | 108 |
95 } // namespace net | 109 } // namespace net |
OLD | NEW |