Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(312)

Side by Side Diff: net/proxy/proxy_bypass_rules.cc

Issue 8921006: Standardize StringToInt{,64} interface. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix namespace issues. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
15 using base::StringPiece;
cbentzel 2011/12/14 18:15:03 Remove this using declaration.
16
14 namespace net { 17 namespace net {
15 18
16 namespace { 19 namespace {
17 20
18 class HostnamePatternRule : public ProxyBypassRules::Rule { 21 class HostnamePatternRule : public ProxyBypassRules::Rule {
19 public: 22 public:
20 HostnamePatternRule(const std::string& optional_scheme, 23 HostnamePatternRule(const std::string& optional_scheme,
21 const std::string& hostname_pattern, 24 const std::string& hostname_pattern,
22 int optional_port) 25 int optional_port)
23 : optional_scheme_(StringToLowerASCII(optional_scheme)), 26 : optional_scheme_(StringToLowerASCII(optional_scheme)),
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 GURL tmp_url("http://" + host); 311 GURL tmp_url("http://" + host);
309 return AddRuleForHostname(scheme, tmp_url.host(), port); 312 return AddRuleForHostname(scheme, tmp_url.host(), port);
310 } 313 }
311 } 314 }
312 315
313 // Otherwise assume we have <hostname-pattern>[:port]. 316 // Otherwise assume we have <hostname-pattern>[:port].
314 std::string::size_type pos_colon = raw.rfind(':'); 317 std::string::size_type pos_colon = raw.rfind(':');
315 host = raw; 318 host = raw;
316 port = -1; 319 port = -1;
317 if (pos_colon != std::string::npos) { 320 if (pos_colon != std::string::npos) {
318 if (!base::StringToInt(raw.begin() + pos_colon + 1, raw.end(), &port) || 321 if (!base::StringToInt(StringPiece(raw.begin() + pos_colon + 1,
322 raw.end()),
323 &port) ||
319 (port < 0 || port > 0xFFFF)) { 324 (port < 0 || port > 0xFFFF)) {
320 return false; // Port was invalid. 325 return false; // Port was invalid.
321 } 326 }
322 raw = raw.substr(0, pos_colon); 327 raw = raw.substr(0, pos_colon);
323 } 328 }
324 329
325 // Special-case hostnames that begin with a period. 330 // Special-case hostnames that begin with a period.
326 // For example, we remap ".google.com" --> "*.google.com". 331 // For example, we remap ".google.com" --> "*.google.com".
327 if (StartsWithASCII(raw, ".", false)) 332 if (StartsWithASCII(raw, ".", false))
328 raw = "*" + raw; 333 raw = "*" + raw;
329 334
330 // 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
331 // wildcard. 336 // wildcard.
332 if (use_hostname_suffix_matching && !StartsWithASCII(raw, "*", false)) 337 if (use_hostname_suffix_matching && !StartsWithASCII(raw, "*", false))
333 raw = "*" + raw; 338 raw = "*" + raw;
334 339
335 return AddRuleForHostname(scheme, raw, port); 340 return AddRuleForHostname(scheme, raw, port);
336 } 341 }
337 342
338 bool ProxyBypassRules::AddRuleFromStringInternalWithLogging( 343 bool ProxyBypassRules::AddRuleFromStringInternalWithLogging(
339 const std::string& raw, 344 const std::string& raw,
340 bool use_hostname_suffix_matching) { 345 bool use_hostname_suffix_matching) {
341 return AddRuleFromStringInternal(raw, use_hostname_suffix_matching); 346 return AddRuleFromStringInternal(raw, use_hostname_suffix_matching);
342 } 347 }
343 348
344 } // namespace net 349 } // namespace net
OLDNEW
« net/base/x509_cert_types.cc ('K') | « net/http/http_response_headers.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698