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

Side by Side Diff: net/proxy/proxy_config_service_linux.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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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_service_linux.h" 5 #include "net/proxy/proxy_config_service_linux.h"
6 6
7 #include <gconf/gconf-client.h> 7 #include <gconf/gconf-client.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 return true; 48 return true;
49 } 49 }
50 return false; 50 return false;
51 } 51 }
52 }; 52 };
53 53
54 // Given a proxy hostname from a setting, returns that hostname with 54 // Given a proxy hostname from a setting, returns that hostname with
55 // an appropriate proxy server scheme prefix. 55 // an appropriate proxy server scheme prefix.
56 // scheme indicates the desired proxy scheme: usually http, with 56 // scheme indicates the desired proxy scheme: usually http, with
57 // socks 4 or 5 as special cases. 57 // socks 4 or 5 as special cases.
58 // TODO(arindam): Remove URI string manipulation by using MapUrlSchemeToProxy.
58 std::string FixupProxyHostScheme(ProxyServer::Scheme scheme, 59 std::string FixupProxyHostScheme(ProxyServer::Scheme scheme,
59 std::string host) { 60 std::string host) {
60 if (scheme == ProxyServer::SCHEME_SOCKS4 && 61 if (scheme == ProxyServer::SCHEME_SOCKS4 &&
61 StartsWithASCII(host, "socks5://", false)) { 62 StartsWithASCII(host, "socks5://", false)) {
62 // We default to socks 4, but if the user specifically set it to 63 // We default to socks 4, but if the user specifically set it to
63 // socks5://, then use that. 64 // socks5://, then use that.
64 scheme = ProxyServer::SCHEME_SOCKS5; 65 scheme = ProxyServer::SCHEME_SOCKS5;
65 } 66 }
66 // Strip the scheme if any. 67 // Strip the scheme if any.
67 std::string::size_type colon = host.find("://"); 68 std::string::size_type colon = host.find("://");
(...skipping 19 matching lines...) Expand all
87 88
88 } // namespace 89 } // namespace
89 90
90 bool ProxyConfigServiceLinux::Delegate::GetProxyFromEnvVarForScheme( 91 bool ProxyConfigServiceLinux::Delegate::GetProxyFromEnvVarForScheme(
91 const char* variable, ProxyServer::Scheme scheme, 92 const char* variable, ProxyServer::Scheme scheme,
92 ProxyServer* result_server) { 93 ProxyServer* result_server) {
93 std::string env_value; 94 std::string env_value;
94 if (env_var_getter_->Getenv(variable, &env_value)) { 95 if (env_var_getter_->Getenv(variable, &env_value)) {
95 if (!env_value.empty()) { 96 if (!env_value.empty()) {
96 env_value = FixupProxyHostScheme(scheme, env_value); 97 env_value = FixupProxyHostScheme(scheme, env_value);
97 ProxyServer proxy_server = ProxyServer::FromURI(env_value); 98 ProxyServer proxy_server =
99 ProxyServer::FromURI(env_value, ProxyServer::SCHEME_HTTP);
98 if (proxy_server.is_valid() && !proxy_server.is_direct()) { 100 if (proxy_server.is_valid() && !proxy_server.is_direct()) {
99 *result_server = proxy_server; 101 *result_server = proxy_server;
100 return true; 102 return true;
101 } else { 103 } else {
102 LOG(ERROR) << "Failed to parse environment variable " << variable; 104 LOG(ERROR) << "Failed to parse environment variable " << variable;
103 } 105 }
104 } 106 }
105 } 107 }
106 return false; 108 return false;
107 } 109 }
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 // Check for an optional port. 381 // Check for an optional port.
380 int port; 382 int port;
381 gconf_getter_->GetInt((key + "port").c_str(), &port); 383 gconf_getter_->GetInt((key + "port").c_str(), &port);
382 if (port != 0) { 384 if (port != 0) {
383 // If a port is set and non-zero: 385 // If a port is set and non-zero:
384 host += ":" + IntToString(port); 386 host += ":" + IntToString(port);
385 } 387 }
386 host = FixupProxyHostScheme( 388 host = FixupProxyHostScheme(
387 is_socks ? ProxyServer::SCHEME_SOCKS4 : ProxyServer::SCHEME_HTTP, 389 is_socks ? ProxyServer::SCHEME_SOCKS4 : ProxyServer::SCHEME_HTTP,
388 host); 390 host);
389 ProxyServer proxy_server = ProxyServer::FromURI(host); 391 ProxyServer proxy_server = ProxyServer::FromURI(host,
392 ProxyServer::SCHEME_HTTP);
390 if (proxy_server.is_valid()) { 393 if (proxy_server.is_valid()) {
391 *result_server = proxy_server; 394 *result_server = proxy_server;
392 return true; 395 return true;
393 } 396 }
394 return false; 397 return false;
395 } 398 }
396 399
397 bool ProxyConfigServiceLinux::Delegate::GetConfigFromGConf( 400 bool ProxyConfigServiceLinux::Delegate::GetConfigFromGConf(
398 ProxyConfig* config) { 401 ProxyConfig* config) {
399 std::string mode; 402 std::string mode;
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 new GConfSettingGetterImpl())) { 655 new GConfSettingGetterImpl())) {
653 } 656 }
654 657
655 ProxyConfigServiceLinux::ProxyConfigServiceLinux( 658 ProxyConfigServiceLinux::ProxyConfigServiceLinux(
656 EnvironmentVariableGetter* env_var_getter, 659 EnvironmentVariableGetter* env_var_getter,
657 GConfSettingGetter* gconf_getter) 660 GConfSettingGetter* gconf_getter)
658 : delegate_(new Delegate(env_var_getter, gconf_getter)) { 661 : delegate_(new Delegate(env_var_getter, gconf_getter)) {
659 } 662 }
660 663
661 } // namespace net 664 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_config_service_common_unittest.cc ('k') | net/proxy/proxy_config_service_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698