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/string_split.h" | 8 #include "base/strings/string_split.h" |
9 #include "base/strings/string_tokenizer.h" | 9 #include "base/strings/string_tokenizer.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 // First, we'll check for a match just on hostname. | 51 // First, we'll check for a match just on hostname. |
52 // If that fails, we'll check for a match with both hostname and port. | 52 // If that fails, we'll check for a match with both hostname and port. |
53 if (!MatchPattern(host_port->host(), rule.hostname_pattern)) { | 53 if (!MatchPattern(host_port->host(), rule.hostname_pattern)) { |
54 std::string host_port_string = host_port->ToString(); | 54 std::string host_port_string = host_port->ToString(); |
55 if (!MatchPattern(host_port_string, rule.hostname_pattern)) | 55 if (!MatchPattern(host_port_string, rule.hostname_pattern)) |
56 continue; // This rule doesn't apply. | 56 continue; // This rule doesn't apply. |
57 } | 57 } |
58 | 58 |
59 host_port->set_host(rule.replacement_hostname); | 59 host_port->set_host(rule.replacement_hostname); |
60 if (rule.replacement_port != -1) | 60 if (rule.replacement_port != -1) |
61 host_port->set_port(rule.replacement_port); | 61 host_port->set_port(static_cast<uint16>(rule.replacement_port)); |
62 return true; | 62 return true; |
63 } | 63 } |
64 | 64 |
65 return false; | 65 return false; |
66 } | 66 } |
67 | 67 |
68 bool HostMappingRules::AddRuleFromString(const std::string& rule_string) { | 68 bool HostMappingRules::AddRuleFromString(const std::string& rule_string) { |
69 std::string trimmed; | 69 std::string trimmed; |
70 base::TrimWhitespaceASCII(rule_string, base::TRIM_ALL, &trimmed); | 70 base::TrimWhitespaceASCII(rule_string, base::TRIM_ALL, &trimmed); |
71 std::vector<std::string> parts; | 71 std::vector<std::string> parts; |
(...skipping 29 matching lines...) Expand all Loading... |
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 |