| 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 (!ParseIntegerBase10( |
| 323 base::StringPiece(raw.begin() + pos_colon + 1, raw.end()), &port) || | 323 base::StringPiece(raw.begin() + pos_colon + 1, raw.end()), |
| 324 ParseInteger::DISALLOW_NEGATIVE, &port) || |
| 324 port > 0xFFFF) { | 325 port > 0xFFFF) { |
| 325 return false; // Port was invalid. | 326 return false; // Port was invalid. |
| 326 } | 327 } |
| 327 raw = raw.substr(0, pos_colon); | 328 raw = raw.substr(0, pos_colon); |
| 328 } | 329 } |
| 329 | 330 |
| 330 // Special-case hostnames that begin with a period. | 331 // Special-case hostnames that begin with a period. |
| 331 // For example, we remap ".google.com" --> "*.google.com". | 332 // For example, we remap ".google.com" --> "*.google.com". |
| 332 if (base::StartsWith(raw, ".", base::CompareCase::SENSITIVE)) | 333 if (base::StartsWith(raw, ".", base::CompareCase::SENSITIVE)) |
| 333 raw = "*" + raw; | 334 raw = "*" + raw; |
| 334 | 335 |
| 335 // If suffix matching was asked for, make sure the pattern starts with a | 336 // If suffix matching was asked for, make sure the pattern starts with a |
| 336 // wildcard. | 337 // wildcard. |
| 337 if (use_hostname_suffix_matching && | 338 if (use_hostname_suffix_matching && |
| 338 !base::StartsWith(raw, "*", base::CompareCase::SENSITIVE)) | 339 !base::StartsWith(raw, "*", base::CompareCase::SENSITIVE)) |
| 339 raw = "*" + raw; | 340 raw = "*" + raw; |
| 340 | 341 |
| 341 return AddRuleForHostname(scheme, raw, port); | 342 return AddRuleForHostname(scheme, raw, port); |
| 342 } | 343 } |
| 343 | 344 |
| 344 bool ProxyBypassRules::AddRuleFromStringInternalWithLogging( | 345 bool ProxyBypassRules::AddRuleFromStringInternalWithLogging( |
| 345 const std::string& raw, | 346 const std::string& raw, |
| 346 bool use_hostname_suffix_matching) { | 347 bool use_hostname_suffix_matching) { |
| 347 return AddRuleFromStringInternal(raw, use_hostname_suffix_matching); | 348 return AddRuleFromStringInternal(raw, use_hostname_suffix_matching); |
| 348 } | 349 } |
| 349 | 350 |
| 350 } // namespace net | 351 } // namespace net |
| OLD | NEW |