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

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

Issue 115029: Making command-line specified proxy settings more flexible - allowing for set... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 months 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 | Annotate | Revision Log
« no previous file with comments | « net/proxy/proxy_config.h ('k') | net/proxy/proxy_config_service_fixed.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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_config.h" 5 #include "net/proxy/proxy_config.h"
6 6
7 #include "base/string_tokenizer.h" 7 #include "base/string_tokenizer.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 9
10 namespace net { 10 namespace net {
11 11
12 ProxyConfig::ProxyConfig() 12 ProxyConfig::ProxyConfig()
13 : auto_detect(false), 13 : auto_detect(false),
14 proxy_bypass_local_names(false), 14 proxy_bypass_local_names(false),
15 id_(INVALID_ID) { 15 id_(INVALID_ID) {
16 } 16 }
17 17
18 bool ProxyConfig::Equals(const ProxyConfig& other) const { 18 bool ProxyConfig::Equals(const ProxyConfig& other) const {
19 // The two configs can have different IDs. We are just interested in if they 19 // The two configs can have different IDs. We are just interested in if they
20 // have the same settings. 20 // have the same settings.
21 return auto_detect == other.auto_detect && 21 return auto_detect == other.auto_detect &&
22 pac_url == other.pac_url && 22 pac_url == other.pac_url &&
23 proxy_rules == other.proxy_rules && 23 proxy_rules == other.proxy_rules &&
24 proxy_bypass == other.proxy_bypass && 24 proxy_bypass == other.proxy_bypass &&
25 proxy_bypass_local_names == other.proxy_bypass_local_names; 25 proxy_bypass_local_names == other.proxy_bypass_local_names;
26 } 26 }
27 27
28 bool ProxyConfig::MayRequirePACResolver() const {
29 return auto_detect || !pac_url.is_empty();
30 }
31
28 void ProxyConfig::ProxyRules::ParseFromString(const std::string& proxy_rules) { 32 void ProxyConfig::ProxyRules::ParseFromString(const std::string& proxy_rules) {
29 // Reset. 33 // Reset.
30 type = TYPE_NO_RULES; 34 type = TYPE_NO_RULES;
31 single_proxy = ProxyServer(); 35 single_proxy = ProxyServer();
32 proxy_for_http = ProxyServer(); 36 proxy_for_http = ProxyServer();
33 proxy_for_https = ProxyServer(); 37 proxy_for_https = ProxyServer();
34 proxy_for_ftp = ProxyServer(); 38 proxy_for_ftp = ProxyServer();
35 39
36 StringTokenizer proxy_server_list(proxy_rules, ";"); 40 StringTokenizer proxy_server_list(proxy_rules, ";");
37 while (proxy_server_list.GetNext()) { 41 while (proxy_server_list.GetNext()) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 DCHECK(type == TYPE_PROXY_PER_SCHEME); 73 DCHECK(type == TYPE_PROXY_PER_SCHEME);
70 if (scheme == "http") 74 if (scheme == "http")
71 return &proxy_for_http; 75 return &proxy_for_http;
72 if (scheme == "https") 76 if (scheme == "https")
73 return &proxy_for_https; 77 return &proxy_for_https;
74 if (scheme == "ftp") 78 if (scheme == "ftp")
75 return &proxy_for_ftp; 79 return &proxy_for_ftp;
76 return NULL; // No mapping for this scheme. 80 return NULL; // No mapping for this scheme.
77 } 81 }
78 82
83 namespace {
84
85 // Returns true if the given string represents an IP address.
86 bool IsIPAddress(const std::string& domain) {
87 // From GURL::HostIsIPAddress()
88 url_canon::RawCanonOutputT<char, 128> ignored_output;
89 url_parse::Component ignored_component;
90 url_parse::Component domain_comp(0, domain.size());
91 return url_canon::CanonicalizeIPAddress(domain.c_str(), domain_comp,
92 &ignored_output,
93 &ignored_component);
94 }
95
96 } // namespace
97
98 void ProxyConfig::ParseNoProxyList(const std::string& no_proxy) {
99 proxy_bypass.clear();
100 if (no_proxy.empty())
101 return;
102 // Traditional semantics:
103 // A single "*" is specifically allowed and unproxies anything.
104 // "*" wildcards other than a single "*" entry are not universally
105 // supported. We will support them, as we get * wildcards for free
106 // (see MatchPattern() called from ProxyService::ShouldBypassProxyForURL()).
107 // no_proxy is a comma-separated list of <trailing_domain>[:<port>].
108 // If no port is specified then any port matches.
109 // The historical definition has trailing_domain match using a simple
110 // string "endswith" test, so that the match need not correspond to a
111 // "." boundary. For example: "google.com" matches "igoogle.com" too.
112 // Seems like that could be confusing, but we'll obey tradition.
113 // IP CIDR patterns are supposed to be supported too. We intend
114 // to do this in proxy_service.cc, but it's currently a TODO.
115 // See: http://crbug.com/9835.
116 StringTokenizer no_proxy_list(no_proxy, ",");
117 while (no_proxy_list.GetNext()) {
118 std::string bypass_entry = no_proxy_list.token();
119 TrimWhitespaceASCII(bypass_entry, TRIM_ALL, &bypass_entry);
120 if (bypass_entry.empty())
121 continue;
122 if (bypass_entry.at(0) != '*') {
123 // Insert a wildcard * to obtain an endsWith match, unless the
124 // entry looks like it might be an IP or CIDR.
125 // First look for either a :<port> or CIDR mask length suffix.
126 std::string::const_iterator begin = bypass_entry.begin();
127 std::string::const_iterator scan = bypass_entry.end() - 1;
128 while (scan > begin && IsAsciiDigit(*scan))
129 --scan;
130 std::string potential_ip;
131 if (*scan == '/' || *scan == ':')
132 potential_ip = std::string(begin, scan - 1);
133 else
134 potential_ip = bypass_entry;
135 if (!IsIPAddress(potential_ip)) {
136 // Do insert a wildcard.
137 bypass_entry.insert(0, "*");
138 }
139 // TODO(sdoyon): When CIDR matching is implemented in
140 // proxy_service.cc, consider making proxy_bypass more
141 // sophisticated to avoid parsing out the string on every
142 // request.
143 }
144 proxy_bypass.push_back(bypass_entry);
145 }
146 }
147
79 } // namespace net 148 } // namespace net
80 149
81 namespace { 150 namespace {
82 151
83 // Helper to stringize a ProxyServer. 152 // Helper to stringize a ProxyServer.
84 std::ostream& operator<<(std::ostream& out, 153 std::ostream& operator<<(std::ostream& out,
85 const net::ProxyServer& proxy_server) { 154 const net::ProxyServer& proxy_server) {
86 if (proxy_server.is_valid()) 155 if (proxy_server.is_valid())
87 out << proxy_server.ToURI(); 156 out << proxy_server.ToURI();
88 return out; 157 return out;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 it != config.proxy_bypass.end(); ++it) { 203 it != config.proxy_bypass.end(); ++it) {
135 out << " " << *it << "\n"; 204 out << " " << *it << "\n";
136 } 205 }
137 out << " }\n"; 206 out << " }\n";
138 } 207 }
139 208
140 out << " id: " << config.id() << "\n" 209 out << " id: " << config.id() << "\n"
141 << "}"; 210 << "}";
142 return out; 211 return out;
143 } 212 }
OLDNEW
« no previous file with comments | « net/proxy/proxy_config.h ('k') | net/proxy/proxy_config_service_fixed.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698