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/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/string_piece.h" |
10 #include "base/string_tokenizer.h" | 11 #include "base/string_tokenizer.h" |
11 #include "base/string_util.h" | 12 #include "base/string_util.h" |
12 #include "net/base/net_util.h" | 13 #include "net/base/net_util.h" |
13 | 14 |
14 namespace net { | 15 namespace net { |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 class HostnamePatternRule : public ProxyBypassRules::Rule { | 19 class HostnamePatternRule : public ProxyBypassRules::Rule { |
19 public: | 20 public: |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 GURL tmp_url("http://" + host); | 309 GURL tmp_url("http://" + host); |
309 return AddRuleForHostname(scheme, tmp_url.host(), port); | 310 return AddRuleForHostname(scheme, tmp_url.host(), port); |
310 } | 311 } |
311 } | 312 } |
312 | 313 |
313 // Otherwise assume we have <hostname-pattern>[:port]. | 314 // Otherwise assume we have <hostname-pattern>[:port]. |
314 std::string::size_type pos_colon = raw.rfind(':'); | 315 std::string::size_type pos_colon = raw.rfind(':'); |
315 host = raw; | 316 host = raw; |
316 port = -1; | 317 port = -1; |
317 if (pos_colon != std::string::npos) { | 318 if (pos_colon != std::string::npos) { |
318 if (!base::StringToInt(raw.begin() + pos_colon + 1, raw.end(), &port) || | 319 if (!base::StringToInt(base::StringPiece(raw.begin() + pos_colon + 1, |
| 320 raw.end()), |
| 321 &port) || |
319 (port < 0 || port > 0xFFFF)) { | 322 (port < 0 || port > 0xFFFF)) { |
320 return false; // Port was invalid. | 323 return false; // Port was invalid. |
321 } | 324 } |
322 raw = raw.substr(0, pos_colon); | 325 raw = raw.substr(0, pos_colon); |
323 } | 326 } |
324 | 327 |
325 // Special-case hostnames that begin with a period. | 328 // Special-case hostnames that begin with a period. |
326 // For example, we remap ".google.com" --> "*.google.com". | 329 // For example, we remap ".google.com" --> "*.google.com". |
327 if (StartsWithASCII(raw, ".", false)) | 330 if (StartsWithASCII(raw, ".", false)) |
328 raw = "*" + raw; | 331 raw = "*" + raw; |
329 | 332 |
330 // If suffix matching was asked for, make sure the pattern starts with a | 333 // If suffix matching was asked for, make sure the pattern starts with a |
331 // wildcard. | 334 // wildcard. |
332 if (use_hostname_suffix_matching && !StartsWithASCII(raw, "*", false)) | 335 if (use_hostname_suffix_matching && !StartsWithASCII(raw, "*", false)) |
333 raw = "*" + raw; | 336 raw = "*" + raw; |
334 | 337 |
335 return AddRuleForHostname(scheme, raw, port); | 338 return AddRuleForHostname(scheme, raw, port); |
336 } | 339 } |
337 | 340 |
338 bool ProxyBypassRules::AddRuleFromStringInternalWithLogging( | 341 bool ProxyBypassRules::AddRuleFromStringInternalWithLogging( |
339 const std::string& raw, | 342 const std::string& raw, |
340 bool use_hostname_suffix_matching) { | 343 bool use_hostname_suffix_matching) { |
341 return AddRuleFromStringInternal(raw, use_hostname_suffix_matching); | 344 return AddRuleFromStringInternal(raw, use_hostname_suffix_matching); |
342 } | 345 } |
343 | 346 |
344 } // namespace net | 347 } // namespace net |
OLD | NEW |