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

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

Issue 149191: Whenever proxy configurations contain socks and http/https/ftp proxies, socks... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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_common_unittest.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 {
(...skipping 18 matching lines...) Expand all
29 return auto_detect || !pac_url.is_empty(); 29 return auto_detect || !pac_url.is_empty();
30 } 30 }
31 31
32 void ProxyConfig::ProxyRules::ParseFromString(const std::string& proxy_rules) { 32 void ProxyConfig::ProxyRules::ParseFromString(const std::string& proxy_rules) {
33 // Reset. 33 // Reset.
34 type = TYPE_NO_RULES; 34 type = TYPE_NO_RULES;
35 single_proxy = ProxyServer(); 35 single_proxy = ProxyServer();
36 proxy_for_http = ProxyServer(); 36 proxy_for_http = ProxyServer();
37 proxy_for_https = ProxyServer(); 37 proxy_for_https = ProxyServer();
38 proxy_for_ftp = ProxyServer(); 38 proxy_for_ftp = ProxyServer();
39 socks_proxy = ProxyServer();
39 40
40 StringTokenizer proxy_server_list(proxy_rules, ";"); 41 StringTokenizer proxy_server_list(proxy_rules, ";");
41 while (proxy_server_list.GetNext()) { 42 while (proxy_server_list.GetNext()) {
42 StringTokenizer proxy_server_for_scheme( 43 StringTokenizer proxy_server_for_scheme(
43 proxy_server_list.token_begin(), proxy_server_list.token_end(), "="); 44 proxy_server_list.token_begin(), proxy_server_list.token_end(), "=");
44 45
45 while (proxy_server_for_scheme.GetNext()) { 46 while (proxy_server_for_scheme.GetNext()) {
46 std::string url_scheme = proxy_server_for_scheme.token(); 47 std::string url_scheme = proxy_server_for_scheme.token();
47 48
48 // If we fail to get the proxy server here, it means that 49 // If we fail to get the proxy server here, it means that
49 // this is a regular proxy server configuration, i.e. proxies 50 // this is a regular proxy server configuration, i.e. proxies
50 // are not configured per protocol. 51 // are not configured per protocol.
51 if (!proxy_server_for_scheme.GetNext()) { 52 if (!proxy_server_for_scheme.GetNext()) {
52 if (type == TYPE_PROXY_PER_SCHEME) 53 if (type == TYPE_PROXY_PER_SCHEME)
53 continue; // Unexpected. 54 continue; // Unexpected.
54 single_proxy = ProxyServer::FromURI(url_scheme); 55 single_proxy = ProxyServer::FromURI(url_scheme,
55 type = TYPE_SINGLE_PROXY; 56 ProxyServer::SCHEME_HTTP);
56 return;
57 }
58
59 // If the proxy settings has only socks and others blank,
60 // make that the default for all the proxies
61 // This gets hit only on windows when using IE settings.
62 if (url_scheme == "socks") {
63 std::string proxy_server_string = "socks://";
64 proxy_server_string.append(proxy_server_for_scheme.token());
65 single_proxy = ProxyServer::FromURI(proxy_server_string);
66 type = TYPE_SINGLE_PROXY; 57 type = TYPE_SINGLE_PROXY;
67 return; 58 return;
68 } 59 }
69 60
70 // Trim whitespace off the url scheme. 61 // Trim whitespace off the url scheme.
71 TrimWhitespaceASCII(url_scheme, TRIM_ALL, &url_scheme); 62 TrimWhitespaceASCII(url_scheme, TRIM_ALL, &url_scheme);
72 63
73 // Add it to the per-scheme mappings (if supported scheme). 64 // Add it to the per-scheme mappings (if supported scheme).
74 type = TYPE_PROXY_PER_SCHEME; 65 type = TYPE_PROXY_PER_SCHEME;
75 if (const ProxyServer* entry = MapSchemeToProxy(url_scheme)) 66 if (ProxyServer* entry = MapSchemeToProxy(url_scheme)) {
76 *const_cast<ProxyServer*>(entry) = 67 std::string proxy_server_token = proxy_server_for_scheme.token();
77 ProxyServer::FromURI(proxy_server_for_scheme.token()); 68 ProxyServer::Scheme scheme = (entry == &socks_proxy) ?
69 ProxyServer::SCHEME_SOCKS4 : ProxyServer::SCHEME_HTTP;
70 *entry = ProxyServer::FromURI(proxy_server_token, scheme);
71 }
78 } 72 }
79 } 73 }
80 } 74 }
81 75
82 const ProxyServer* ProxyConfig::ProxyRules::MapSchemeToProxy( 76 const ProxyServer* ProxyConfig::ProxyRules::MapUrlSchemeToProxy(
83 const std::string& scheme) const { 77 const std::string& url_scheme) const {
78 const ProxyServer* proxy_server =
79 const_cast<ProxyRules*>(this)->MapSchemeToProxy(url_scheme);
80 if (proxy_server && proxy_server->is_valid())
81 return proxy_server;
82 if (socks_proxy.is_valid())
83 return &socks_proxy;
84 return NULL; // No mapping for this scheme. Use direct.
85 }
86
87 ProxyServer* ProxyConfig::ProxyRules::MapSchemeToProxy(
88 const std::string& scheme) {
84 DCHECK(type == TYPE_PROXY_PER_SCHEME); 89 DCHECK(type == TYPE_PROXY_PER_SCHEME);
85 if (scheme == "http") 90 if (scheme == "http")
86 return &proxy_for_http; 91 return &proxy_for_http;
87 if (scheme == "https") 92 if (scheme == "https")
88 return &proxy_for_https; 93 return &proxy_for_https;
89 if (scheme == "ftp") 94 if (scheme == "ftp")
90 return &proxy_for_ftp; 95 return &proxy_for_ftp;
96 if (scheme == "socks")
97 return &socks_proxy;
91 return NULL; // No mapping for this scheme. 98 return NULL; // No mapping for this scheme.
92 } 99 }
93 100
94 namespace { 101 namespace {
95 102
96 // Returns true if the given string represents an IP address. 103 // Returns true if the given string represents an IP address.
97 bool IsIPAddress(const std::string& domain) { 104 bool IsIPAddress(const std::string& domain) {
98 // From GURL::HostIsIPAddress() 105 // From GURL::HostIsIPAddress()
99 url_canon::RawCanonOutputT<char, 128> ignored_output; 106 url_canon::RawCanonOutputT<char, 128> ignored_output;
100 url_canon::CanonHostInfo host_info; 107 url_canon::CanonHostInfo host_info;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 default: 194 default:
188 type = IntToString(rules.type); 195 type = IntToString(rules.type);
189 break; 196 break;
190 } 197 }
191 return out << " {\n" 198 return out << " {\n"
192 << " type: " << type << "\n" 199 << " type: " << type << "\n"
193 << " single_proxy: " << rules.single_proxy << "\n" 200 << " single_proxy: " << rules.single_proxy << "\n"
194 << " proxy_for_http: " << rules.proxy_for_http << "\n" 201 << " proxy_for_http: " << rules.proxy_for_http << "\n"
195 << " proxy_for_https: " << rules.proxy_for_https << "\n" 202 << " proxy_for_https: " << rules.proxy_for_https << "\n"
196 << " proxy_for_ftp: " << rules.proxy_for_ftp << "\n" 203 << " proxy_for_ftp: " << rules.proxy_for_ftp << "\n"
204 << " socks_proxy: " << rules.socks_proxy << "\n"
197 << " }"; 205 << " }";
198 } 206 }
199 207
200 std::ostream& operator<<(std::ostream& out, const net::ProxyConfig& config) { 208 std::ostream& operator<<(std::ostream& out, const net::ProxyConfig& config) {
201 out << "{\n" 209 out << "{\n"
202 << " auto_detect: " << config.auto_detect << "\n" 210 << " auto_detect: " << config.auto_detect << "\n"
203 << " pac_url: " << config.pac_url << "\n" 211 << " pac_url: " << config.pac_url << "\n"
204 << " proxy_rules:\n" << config.proxy_rules << "\n" 212 << " proxy_rules:\n" << config.proxy_rules << "\n"
205 << " proxy_bypass_local_names: " << config.proxy_bypass_local_names 213 << " proxy_bypass_local_names: " << config.proxy_bypass_local_names
206 << "\n" 214 << "\n"
207 << " proxy_bypass_list:\n"; 215 << " proxy_bypass_list:\n";
208 216
209 // Print out the proxy bypass list. 217 // Print out the proxy bypass list.
210 if (!config.proxy_bypass.empty()) { 218 if (!config.proxy_bypass.empty()) {
211 out << " {\n"; 219 out << " {\n";
212 std::vector<std::string>::const_iterator it; 220 std::vector<std::string>::const_iterator it;
213 for (it = config.proxy_bypass.begin(); 221 for (it = config.proxy_bypass.begin();
214 it != config.proxy_bypass.end(); ++it) { 222 it != config.proxy_bypass.end(); ++it) {
215 out << " " << *it << "\n"; 223 out << " " << *it << "\n";
216 } 224 }
217 out << " }\n"; 225 out << " }\n";
218 } 226 }
219 227
220 out << " id: " << config.id() << "\n" 228 out << " id: " << config.id() << "\n"
221 << "}"; 229 << "}";
222 return out; 230 return out;
223 } 231 }
OLDNEW
« no previous file with comments | « net/proxy/proxy_config.h ('k') | net/proxy/proxy_config_service_common_unittest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698