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_service_linux.h" | 5 #include "net/proxy/proxy_config_service_linux.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <gconf/gconf-client.h> | 9 #include <gconf/gconf-client.h> |
10 #include <limits.h> | 10 #include <limits.h> |
(...skipping 25 matching lines...) Expand all Loading... |
36 | 36 |
37 namespace { | 37 namespace { |
38 | 38 |
39 // Given a proxy hostname from a setting, returns that hostname with | 39 // Given a proxy hostname from a setting, returns that hostname with |
40 // an appropriate proxy server scheme prefix. | 40 // an appropriate proxy server scheme prefix. |
41 // scheme indicates the desired proxy scheme: usually http, with | 41 // scheme indicates the desired proxy scheme: usually http, with |
42 // socks 4 or 5 as special cases. | 42 // socks 4 or 5 as special cases. |
43 // TODO(arindam): Remove URI string manipulation by using MapUrlSchemeToProxy. | 43 // TODO(arindam): Remove URI string manipulation by using MapUrlSchemeToProxy. |
44 std::string FixupProxyHostScheme(ProxyServer::Scheme scheme, | 44 std::string FixupProxyHostScheme(ProxyServer::Scheme scheme, |
45 std::string host) { | 45 std::string host) { |
46 if (scheme == ProxyServer::SCHEME_SOCKS4 && | 46 if (scheme == ProxyServer::SCHEME_SOCKS5 && |
47 StartsWithASCII(host, "socks5://", false)) { | 47 StartsWithASCII(host, "socks4://", false)) { |
48 // We default to socks 4, but if the user specifically set it to | 48 // We default to socks 5, but if the user specifically set it to |
49 // socks5://, then use that. | 49 // socks4://, then use that. |
50 scheme = ProxyServer::SCHEME_SOCKS5; | 50 scheme = ProxyServer::SCHEME_SOCKS4; |
51 } | 51 } |
52 // Strip the scheme if any. | 52 // Strip the scheme if any. |
53 std::string::size_type colon = host.find("://"); | 53 std::string::size_type colon = host.find("://"); |
54 if (colon != std::string::npos) | 54 if (colon != std::string::npos) |
55 host = host.substr(colon + 3); | 55 host = host.substr(colon + 3); |
56 // If a username and perhaps password are specified, give a warning. | 56 // If a username and perhaps password are specified, give a warning. |
57 std::string::size_type at_sign = host.find("@"); | 57 std::string::size_type at_sign = host.find("@"); |
58 // Should this be supported? | 58 // Should this be supported? |
59 if (at_sign != std::string::npos) { | 59 if (at_sign != std::string::npos) { |
60 // ProxyConfig does not support authentication parameters, but Chrome | 60 // ProxyConfig does not support authentication parameters, but Chrome |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 if (have_ftp) | 145 if (have_ftp) |
146 config->proxy_rules().proxy_for_ftp = proxy_server; | 146 config->proxy_rules().proxy_for_ftp = proxy_server; |
147 if (have_http || have_https || have_ftp) { | 147 if (have_http || have_https || have_ftp) { |
148 // mustn't change type unless some rules are actually set. | 148 // mustn't change type unless some rules are actually set. |
149 config->proxy_rules().type = | 149 config->proxy_rules().type = |
150 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME; | 150 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME; |
151 } | 151 } |
152 } | 152 } |
153 if (config->proxy_rules().empty()) { | 153 if (config->proxy_rules().empty()) { |
154 // If the above were not defined, try for socks. | 154 // If the above were not defined, try for socks. |
155 ProxyServer::Scheme scheme = ProxyServer::SCHEME_SOCKS4; | 155 // For environment variables, we default to version 5, per the gnome |
| 156 // documentation: http://library.gnome.org/devel/gnet/stable/gnet-socks.html |
| 157 ProxyServer::Scheme scheme = ProxyServer::SCHEME_SOCKS5; |
156 std::string env_version; | 158 std::string env_version; |
157 if (env_var_getter_->GetVar("SOCKS_VERSION", &env_version) | 159 if (env_var_getter_->GetVar("SOCKS_VERSION", &env_version) |
158 && env_version == "5") | 160 && env_version == "4") |
159 scheme = ProxyServer::SCHEME_SOCKS5; | 161 scheme = ProxyServer::SCHEME_SOCKS4; |
160 if (GetProxyFromEnvVarForScheme("SOCKS_SERVER", scheme, &proxy_server)) { | 162 if (GetProxyFromEnvVarForScheme("SOCKS_SERVER", scheme, &proxy_server)) { |
161 config->proxy_rules().type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY; | 163 config->proxy_rules().type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY; |
162 config->proxy_rules().single_proxy = proxy_server; | 164 config->proxy_rules().single_proxy = proxy_server; |
163 } | 165 } |
164 } | 166 } |
165 // Look for the proxy bypass list. | 167 // Look for the proxy bypass list. |
166 std::string no_proxy; | 168 std::string no_proxy; |
167 env_var_getter_->GetVar("no_proxy", &no_proxy); | 169 env_var_getter_->GetVar("no_proxy", &no_proxy); |
168 if (config->proxy_rules().empty()) { | 170 if (config->proxy_rules().empty()) { |
169 // Having only "no_proxy" set, presumably to "*", makes it | 171 // Having only "no_proxy" set, presumably to "*", makes it |
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 return false; | 910 return false; |
909 } | 911 } |
910 // Check for an optional port. | 912 // Check for an optional port. |
911 int port = 0; | 913 int port = 0; |
912 gconf_getter_->GetInt((key + "port").c_str(), &port); | 914 gconf_getter_->GetInt((key + "port").c_str(), &port); |
913 if (port != 0) { | 915 if (port != 0) { |
914 // If a port is set and non-zero: | 916 // If a port is set and non-zero: |
915 host += ":" + base::IntToString(port); | 917 host += ":" + base::IntToString(port); |
916 } | 918 } |
917 host = FixupProxyHostScheme( | 919 host = FixupProxyHostScheme( |
918 is_socks ? ProxyServer::SCHEME_SOCKS4 : ProxyServer::SCHEME_HTTP, | 920 is_socks ? ProxyServer::SCHEME_SOCKS5 : ProxyServer::SCHEME_HTTP, |
919 host); | 921 host); |
920 ProxyServer proxy_server = ProxyServer::FromURI(host, | 922 ProxyServer proxy_server = ProxyServer::FromURI(host, |
921 ProxyServer::SCHEME_HTTP); | 923 ProxyServer::SCHEME_HTTP); |
922 if (proxy_server.is_valid()) { | 924 if (proxy_server.is_valid()) { |
923 *result_server = proxy_server; | 925 *result_server = proxy_server; |
924 return true; | 926 return true; |
925 } | 927 } |
926 return false; | 928 return false; |
927 } | 929 } |
928 | 930 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 // not exist (presumably on older versions), assume false in that | 977 // not exist (presumably on older versions), assume false in that |
976 // case. | 978 // case. |
977 gconf_getter_->GetBoolean("/system/http_proxy/use_same_proxy", | 979 gconf_getter_->GetBoolean("/system/http_proxy/use_same_proxy", |
978 &same_proxy); | 980 &same_proxy); |
979 | 981 |
980 ProxyServer proxy_server; | 982 ProxyServer proxy_server; |
981 if (!same_proxy) { | 983 if (!same_proxy) { |
982 // Try socks. | 984 // Try socks. |
983 if (GetProxyFromGConf("/system/proxy/socks_", true, &proxy_server)) { | 985 if (GetProxyFromGConf("/system/proxy/socks_", true, &proxy_server)) { |
984 // gconf settings do not appear to distinguish between socks | 986 // gconf settings do not appear to distinguish between socks |
985 // version. We default to version 4. | 987 // version. We default to version 5. For more information on this policy |
| 988 // decisions, see: |
| 989 // http://code.google.com/p/chromium/issues/detail?id=55912#c2 |
986 config->proxy_rules().type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY; | 990 config->proxy_rules().type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY; |
987 config->proxy_rules().single_proxy = proxy_server; | 991 config->proxy_rules().single_proxy = proxy_server; |
988 } | 992 } |
989 } | 993 } |
990 if (config->proxy_rules().empty()) { | 994 if (config->proxy_rules().empty()) { |
991 bool have_http = GetProxyFromGConf("/system/http_proxy/", false, | 995 bool have_http = GetProxyFromGConf("/system/http_proxy/", false, |
992 &proxy_server); | 996 &proxy_server); |
993 if (same_proxy) { | 997 if (same_proxy) { |
994 if (have_http) { | 998 if (have_http) { |
995 config->proxy_rules().type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY; | 999 config->proxy_rules().type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY; |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1239 : delegate_(new Delegate(env_var_getter)) { | 1243 : delegate_(new Delegate(env_var_getter)) { |
1240 } | 1244 } |
1241 | 1245 |
1242 ProxyConfigServiceLinux::ProxyConfigServiceLinux( | 1246 ProxyConfigServiceLinux::ProxyConfigServiceLinux( |
1243 base::Environment* env_var_getter, | 1247 base::Environment* env_var_getter, |
1244 GConfSettingGetter* gconf_getter) | 1248 GConfSettingGetter* gconf_getter) |
1245 : delegate_(new Delegate(env_var_getter, gconf_getter)) { | 1249 : delegate_(new Delegate(env_var_getter, gconf_getter)) { |
1246 } | 1250 } |
1247 | 1251 |
1248 } // namespace net | 1252 } // namespace net |
OLD | NEW |