OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <sstream> | 7 #include <sstream> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 default: | 46 default: |
47 type = base::IntToString(rules.type); | 47 type = base::IntToString(rules.type); |
48 break; | 48 break; |
49 } | 49 } |
50 return out << " {\n" | 50 return out << " {\n" |
51 << " type: " << type << "\n" | 51 << " type: " << type << "\n" |
52 << " single_proxy: " << rules.single_proxy << "\n" | 52 << " single_proxy: " << rules.single_proxy << "\n" |
53 << " proxy_for_http: " << rules.proxy_for_http << "\n" | 53 << " proxy_for_http: " << rules.proxy_for_http << "\n" |
54 << " proxy_for_https: " << rules.proxy_for_https << "\n" | 54 << " proxy_for_https: " << rules.proxy_for_https << "\n" |
55 << " proxy_for_ftp: " << rules.proxy_for_ftp << "\n" | 55 << " proxy_for_ftp: " << rules.proxy_for_ftp << "\n" |
56 << " socks_proxy: " << rules.socks_proxy << "\n" | 56 << " fallback_proxy: " << rules.fallback_proxy << "\n" |
57 << " }"; | 57 << " }"; |
58 } | 58 } |
59 | 59 |
60 std::ostream& operator<<(std::ostream& out, const ProxyConfig& config) { | 60 std::ostream& operator<<(std::ostream& out, const ProxyConfig& config) { |
61 // "Automatic" settings. | 61 // "Automatic" settings. |
62 out << "Automatic settings:\n"; | 62 out << "Automatic settings:\n"; |
63 out << " Auto-detect: " << BoolToYesNoString(config.auto_detect()) << "\n"; | 63 out << " Auto-detect: " << BoolToYesNoString(config.auto_detect()) << "\n"; |
64 out << " Custom PAC script: "; | 64 out << " Custom PAC script: "; |
65 if (config.has_pac_url()) | 65 if (config.has_pac_url()) |
66 out << config.pac_url(); | 66 out << config.pac_url(); |
(...skipping 14 matching lines...) Expand all Loading... |
81 out << "\n"; | 81 out << "\n"; |
82 break; | 82 break; |
83 case net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME: | 83 case net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME: |
84 out << "\n"; | 84 out << "\n"; |
85 if (config.proxy_rules().proxy_for_http.is_valid()) | 85 if (config.proxy_rules().proxy_for_http.is_valid()) |
86 out << " HTTP: " << config.proxy_rules().proxy_for_http << "\n"; | 86 out << " HTTP: " << config.proxy_rules().proxy_for_http << "\n"; |
87 if (config.proxy_rules().proxy_for_https.is_valid()) | 87 if (config.proxy_rules().proxy_for_https.is_valid()) |
88 out << " HTTPS: " << config.proxy_rules().proxy_for_https << "\n"; | 88 out << " HTTPS: " << config.proxy_rules().proxy_for_https << "\n"; |
89 if (config.proxy_rules().proxy_for_ftp.is_valid()) | 89 if (config.proxy_rules().proxy_for_ftp.is_valid()) |
90 out << " FTP: " << config.proxy_rules().proxy_for_ftp << "\n"; | 90 out << " FTP: " << config.proxy_rules().proxy_for_ftp << "\n"; |
91 if (config.proxy_rules().socks_proxy.is_valid()) | 91 if (config.proxy_rules().fallback_proxy.is_valid()) { |
92 out << " SOCKS: " << config.proxy_rules().socks_proxy << "\n"; | 92 out << " (fallback): " |
| 93 << config.proxy_rules().fallback_proxy << "\n"; |
| 94 } |
93 break; | 95 break; |
94 } | 96 } |
95 | 97 |
96 if (config.proxy_rules().reverse_bypass) | 98 if (config.proxy_rules().reverse_bypass) |
97 out << " Only use proxy for: "; | 99 out << " Only use proxy for: "; |
98 else | 100 else |
99 out << " Bypass list: "; | 101 out << " Bypass list: "; |
100 if (config.proxy_rules().bypass_rules.rules().empty()) { | 102 if (config.proxy_rules().bypass_rules.rules().empty()) { |
101 out << "[None]"; | 103 out << "[None]"; |
102 } else { | 104 } else { |
(...skipping 16 matching lines...) Expand all Loading... |
119 } | 121 } |
120 | 122 |
121 } // namespace | 123 } // namespace |
122 | 124 |
123 bool ProxyConfig::ProxyRules::Equals(const ProxyRules& other) const { | 125 bool ProxyConfig::ProxyRules::Equals(const ProxyRules& other) const { |
124 return type == other.type && | 126 return type == other.type && |
125 single_proxy == other.single_proxy && | 127 single_proxy == other.single_proxy && |
126 proxy_for_http == other.proxy_for_http && | 128 proxy_for_http == other.proxy_for_http && |
127 proxy_for_https == other.proxy_for_https && | 129 proxy_for_https == other.proxy_for_https && |
128 proxy_for_ftp == other.proxy_for_ftp && | 130 proxy_for_ftp == other.proxy_for_ftp && |
129 socks_proxy == other.socks_proxy && | 131 fallback_proxy == other.fallback_proxy && |
130 bypass_rules.Equals(other.bypass_rules) && | 132 bypass_rules.Equals(other.bypass_rules) && |
131 reverse_bypass == other.reverse_bypass; | 133 reverse_bypass == other.reverse_bypass; |
132 } | 134 } |
133 | 135 |
134 void ProxyConfig::ProxyRules::Apply(const GURL& url, ProxyInfo* result) { | 136 void ProxyConfig::ProxyRules::Apply(const GURL& url, ProxyInfo* result) { |
135 if (empty()) { | 137 if (empty()) { |
136 result->UseDirect(); | 138 result->UseDirect(); |
137 return; | 139 return; |
138 } | 140 } |
139 | 141 |
(...skipping 29 matching lines...) Expand all Loading... |
169 } | 171 } |
170 } | 172 } |
171 | 173 |
172 void ProxyConfig::ProxyRules::ParseFromString(const std::string& proxy_rules) { | 174 void ProxyConfig::ProxyRules::ParseFromString(const std::string& proxy_rules) { |
173 // Reset. | 175 // Reset. |
174 type = TYPE_NO_RULES; | 176 type = TYPE_NO_RULES; |
175 single_proxy = ProxyServer(); | 177 single_proxy = ProxyServer(); |
176 proxy_for_http = ProxyServer(); | 178 proxy_for_http = ProxyServer(); |
177 proxy_for_https = ProxyServer(); | 179 proxy_for_https = ProxyServer(); |
178 proxy_for_ftp = ProxyServer(); | 180 proxy_for_ftp = ProxyServer(); |
179 socks_proxy = ProxyServer(); | 181 fallback_proxy = ProxyServer(); |
180 | 182 |
181 StringTokenizer proxy_server_list(proxy_rules, ";"); | 183 StringTokenizer proxy_server_list(proxy_rules, ";"); |
182 while (proxy_server_list.GetNext()) { | 184 while (proxy_server_list.GetNext()) { |
183 StringTokenizer proxy_server_for_scheme( | 185 StringTokenizer proxy_server_for_scheme( |
184 proxy_server_list.token_begin(), proxy_server_list.token_end(), "="); | 186 proxy_server_list.token_begin(), proxy_server_list.token_end(), "="); |
185 | 187 |
186 while (proxy_server_for_scheme.GetNext()) { | 188 while (proxy_server_for_scheme.GetNext()) { |
187 std::string url_scheme = proxy_server_for_scheme.token(); | 189 std::string url_scheme = proxy_server_for_scheme.token(); |
188 | 190 |
189 // If we fail to get the proxy server here, it means that | 191 // If we fail to get the proxy server here, it means that |
190 // this is a regular proxy server configuration, i.e. proxies | 192 // this is a regular proxy server configuration, i.e. proxies |
191 // are not configured per protocol. | 193 // are not configured per protocol. |
192 if (!proxy_server_for_scheme.GetNext()) { | 194 if (!proxy_server_for_scheme.GetNext()) { |
193 if (type == TYPE_PROXY_PER_SCHEME) | 195 if (type == TYPE_PROXY_PER_SCHEME) |
194 continue; // Unexpected. | 196 continue; // Unexpected. |
195 single_proxy = ProxyServer::FromURI(url_scheme, | 197 single_proxy = ProxyServer::FromURI(url_scheme, |
196 ProxyServer::SCHEME_HTTP); | 198 ProxyServer::SCHEME_HTTP); |
197 type = TYPE_SINGLE_PROXY; | 199 type = TYPE_SINGLE_PROXY; |
198 return; | 200 return; |
199 } | 201 } |
200 | 202 |
201 // Trim whitespace off the url scheme. | 203 // Trim whitespace off the url scheme. |
202 TrimWhitespaceASCII(url_scheme, TRIM_ALL, &url_scheme); | 204 TrimWhitespaceASCII(url_scheme, TRIM_ALL, &url_scheme); |
203 | 205 |
204 // Add it to the per-scheme mappings (if supported scheme). | 206 // Add it to the per-scheme mappings (if supported scheme). |
205 type = TYPE_PROXY_PER_SCHEME; | 207 type = TYPE_PROXY_PER_SCHEME; |
206 if (ProxyServer* entry = MapSchemeToProxy(url_scheme)) { | 208 ProxyServer* entry = MapUrlSchemeToProxyNoFallback(url_scheme); |
207 std::string proxy_server_token = proxy_server_for_scheme.token(); | 209 ProxyServer::Scheme default_scheme = ProxyServer::SCHEME_HTTP; |
208 ProxyServer::Scheme scheme = (entry == &socks_proxy) ? | 210 |
209 ProxyServer::SCHEME_SOCKS4 : ProxyServer::SCHEME_HTTP; | 211 // socks=XXX is inconsistent with the other formats, since "socks" |
210 *entry = ProxyServer::FromURI(proxy_server_token, scheme); | 212 // is not a URL scheme. Rather this means "for everything else, send |
| 213 // it to the SOCKS proxy server XXX". |
| 214 if (url_scheme == "socks") { |
| 215 DCHECK(!entry); |
| 216 entry = &fallback_proxy; |
| 217 default_scheme = ProxyServer::SCHEME_SOCKS4; |
| 218 } |
| 219 |
| 220 if (entry) { |
| 221 *entry = ProxyServer::FromURI(proxy_server_for_scheme.token(), |
| 222 default_scheme); |
211 } | 223 } |
212 } | 224 } |
213 } | 225 } |
214 } | 226 } |
215 | 227 |
216 const ProxyServer* ProxyConfig::ProxyRules::MapUrlSchemeToProxy( | 228 const ProxyServer* ProxyConfig::ProxyRules::MapUrlSchemeToProxy( |
217 const std::string& url_scheme) const { | 229 const std::string& url_scheme) const { |
218 const ProxyServer* proxy_server = | 230 const ProxyServer* proxy_server = |
219 const_cast<ProxyRules*>(this)->MapSchemeToProxy(url_scheme); | 231 const_cast<ProxyRules*>(this)->MapUrlSchemeToProxyNoFallback(url_scheme); |
220 if (proxy_server && proxy_server->is_valid()) | 232 if (proxy_server && proxy_server->is_valid()) |
221 return proxy_server; | 233 return proxy_server; |
222 if (socks_proxy.is_valid()) | 234 if (fallback_proxy.is_valid()) |
223 return &socks_proxy; | 235 return &fallback_proxy; |
224 return NULL; // No mapping for this scheme. Use direct. | 236 return NULL; // No mapping for this scheme. Use direct. |
225 } | 237 } |
226 | 238 |
227 ProxyServer* ProxyConfig::ProxyRules::MapSchemeToProxy( | 239 ProxyServer* ProxyConfig::ProxyRules::MapUrlSchemeToProxyNoFallback( |
228 const std::string& scheme) { | 240 const std::string& scheme) { |
229 DCHECK(type == TYPE_PROXY_PER_SCHEME); | 241 DCHECK_EQ(TYPE_PROXY_PER_SCHEME, type); |
230 if (scheme == "http") | 242 if (scheme == "http") |
231 return &proxy_for_http; | 243 return &proxy_for_http; |
232 if (scheme == "https") | 244 if (scheme == "https") |
233 return &proxy_for_https; | 245 return &proxy_for_https; |
234 if (scheme == "ftp") | 246 if (scheme == "ftp") |
235 return &proxy_for_ftp; | 247 return &proxy_for_ftp; |
236 if (scheme == "socks") | |
237 return &socks_proxy; | |
238 return NULL; // No mapping for this scheme. | 248 return NULL; // No mapping for this scheme. |
239 } | 249 } |
240 | 250 |
241 ProxyConfig::ProxyConfig() : auto_detect_(false), id_(INVALID_ID) { | 251 ProxyConfig::ProxyConfig() : auto_detect_(false), id_(INVALID_ID) { |
242 } | 252 } |
243 | 253 |
244 bool ProxyConfig::Equals(const ProxyConfig& other) const { | 254 bool ProxyConfig::Equals(const ProxyConfig& other) const { |
245 // The two configs can have different IDs. We are just interested in if they | 255 // The two configs can have different IDs. We are just interested in if they |
246 // have the same settings. | 256 // have the same settings. |
247 return auto_detect_ == other.auto_detect_ && | 257 return auto_detect_ == other.auto_detect_ && |
(...skipping 11 matching lines...) Expand all Loading... |
259 | 269 |
260 Value* ProxyConfig::ToValue() const { | 270 Value* ProxyConfig::ToValue() const { |
261 // TODO(eroman): send a dictionary rather than a flat string, so the | 271 // TODO(eroman): send a dictionary rather than a flat string, so the |
262 // javascript client can do prettier formatting. | 272 // javascript client can do prettier formatting. |
263 // crbug.com/52011 | 273 // crbug.com/52011 |
264 return Value::CreateStringValue(ToString()); | 274 return Value::CreateStringValue(ToString()); |
265 } | 275 } |
266 | 276 |
267 } // namespace net | 277 } // namespace net |
268 | 278 |
OLD | NEW |