| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/proxy/proxy_bypass_rules.h" | 5 #include "net/proxy/proxy_bypass_rules.h" |
| 6 | 6 |
| 7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "base/strings/pattern.h" | 8 #include "base/strings/pattern.h" |
| 9 #include "base/strings/string_piece.h" | 9 #include "base/strings/string_piece.h" |
| 10 #include "base/strings/string_tokenizer.h" | 10 #include "base/strings/string_tokenizer.h" |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 // Canonicalize the IP literal before adding it as a string pattern. | 312 // Canonicalize the IP literal before adding it as a string pattern. |
| 313 GURL tmp_url("http://" + bracketed_host); | 313 GURL tmp_url("http://" + bracketed_host); |
| 314 return AddRuleForHostname(scheme, tmp_url.host(), port); | 314 return AddRuleForHostname(scheme, tmp_url.host(), port); |
| 315 } | 315 } |
| 316 } | 316 } |
| 317 | 317 |
| 318 // Otherwise assume we have <hostname-pattern>[:port]. | 318 // Otherwise assume we have <hostname-pattern>[:port]. |
| 319 std::string::size_type pos_colon = raw.rfind(':'); | 319 std::string::size_type pos_colon = raw.rfind(':'); |
| 320 port = -1; | 320 port = -1; |
| 321 if (pos_colon != std::string::npos) { | 321 if (pos_colon != std::string::npos) { |
| 322 if (!ParseNonNegativeDecimalInt( | 322 if (!ParseInt32(base::StringPiece(raw.begin() + pos_colon + 1, raw.end()), |
| 323 base::StringPiece(raw.begin() + pos_colon + 1, raw.end()), &port) || | 323 ParseIntFormat::NON_NEGATIVE, &port) || |
| 324 port > 0xFFFF) { | 324 port > 0xFFFF) { |
| 325 return false; // Port was invalid. | 325 return false; // Port was invalid. |
| 326 } | 326 } |
| 327 raw = raw.substr(0, pos_colon); | 327 raw = raw.substr(0, pos_colon); |
| 328 } | 328 } |
| 329 | 329 |
| 330 // Special-case hostnames that begin with a period. | 330 // Special-case hostnames that begin with a period. |
| 331 // For example, we remap ".google.com" --> "*.google.com". | 331 // For example, we remap ".google.com" --> "*.google.com". |
| 332 if (base::StartsWith(raw, ".", base::CompareCase::SENSITIVE)) | 332 if (base::StartsWith(raw, ".", base::CompareCase::SENSITIVE)) |
| 333 raw = "*" + raw; | 333 raw = "*" + raw; |
| 334 | 334 |
| 335 // If suffix matching was asked for, make sure the pattern starts with a | 335 // If suffix matching was asked for, make sure the pattern starts with a |
| 336 // wildcard. | 336 // wildcard. |
| 337 if (use_hostname_suffix_matching && | 337 if (use_hostname_suffix_matching && |
| 338 !base::StartsWith(raw, "*", base::CompareCase::SENSITIVE)) | 338 !base::StartsWith(raw, "*", base::CompareCase::SENSITIVE)) |
| 339 raw = "*" + raw; | 339 raw = "*" + raw; |
| 340 | 340 |
| 341 return AddRuleForHostname(scheme, raw, port); | 341 return AddRuleForHostname(scheme, raw, port); |
| 342 } | 342 } |
| 343 | 343 |
| 344 bool ProxyBypassRules::AddRuleFromStringInternalWithLogging( | 344 bool ProxyBypassRules::AddRuleFromStringInternalWithLogging( |
| 345 const std::string& raw, | 345 const std::string& raw, |
| 346 bool use_hostname_suffix_matching) { | 346 bool use_hostname_suffix_matching) { |
| 347 return AddRuleFromStringInternal(raw, use_hostname_suffix_matching); | 347 return AddRuleFromStringInternal(raw, use_hostname_suffix_matching); |
| 348 } | 348 } |
| 349 | 349 |
| 350 } // namespace net | 350 } // namespace net |
| OLD | NEW |