| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #if defined(USE_GCONF) | 9 #if defined(USE_GCONF) |
| 10 #include <gconf/gconf-client.h> | 10 #include <gconf/gconf-client.h> |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 } else { | 130 } else { |
| 131 // specified autoconfig URL | 131 // specified autoconfig URL |
| 132 config->set_pac_url(GURL(auto_proxy)); | 132 config->set_pac_url(GURL(auto_proxy)); |
| 133 } | 133 } |
| 134 return true; | 134 return true; |
| 135 } | 135 } |
| 136 // "all_proxy" is a shortcut to avoid defining {http,https,ftp}_proxy. | 136 // "all_proxy" is a shortcut to avoid defining {http,https,ftp}_proxy. |
| 137 ProxyServer proxy_server; | 137 ProxyServer proxy_server; |
| 138 if (GetProxyFromEnvVar("all_proxy", &proxy_server)) { | 138 if (GetProxyFromEnvVar("all_proxy", &proxy_server)) { |
| 139 config->proxy_rules().type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY; | 139 config->proxy_rules().type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY; |
| 140 config->proxy_rules().single_proxy = proxy_server; | 140 config->proxy_rules().single_proxies.SetSingleProxyServer(proxy_server); |
| 141 } else { | 141 } else { |
| 142 bool have_http = GetProxyFromEnvVar("http_proxy", &proxy_server); | 142 bool have_http = GetProxyFromEnvVar("http_proxy", &proxy_server); |
| 143 if (have_http) | 143 if (have_http) |
| 144 config->proxy_rules().proxy_for_http = proxy_server; | 144 config->proxy_rules().proxies_for_http.SetSingleProxyServer(proxy_server); |
| 145 // It would be tempting to let http_proxy apply for all protocols | 145 // It would be tempting to let http_proxy apply for all protocols |
| 146 // if https_proxy and ftp_proxy are not defined. Googling turns up | 146 // if https_proxy and ftp_proxy are not defined. Googling turns up |
| 147 // several documents that mention only http_proxy. But then the | 147 // several documents that mention only http_proxy. But then the |
| 148 // user really might not want to proxy https. And it doesn't seem | 148 // user really might not want to proxy https. And it doesn't seem |
| 149 // like other apps do this. So we will refrain. | 149 // like other apps do this. So we will refrain. |
| 150 bool have_https = GetProxyFromEnvVar("https_proxy", &proxy_server); | 150 bool have_https = GetProxyFromEnvVar("https_proxy", &proxy_server); |
| 151 if (have_https) | 151 if (have_https) |
| 152 config->proxy_rules().proxy_for_https = proxy_server; | 152 config->proxy_rules().proxies_for_https. |
| 153 SetSingleProxyServer(proxy_server); |
| 153 bool have_ftp = GetProxyFromEnvVar("ftp_proxy", &proxy_server); | 154 bool have_ftp = GetProxyFromEnvVar("ftp_proxy", &proxy_server); |
| 154 if (have_ftp) | 155 if (have_ftp) |
| 155 config->proxy_rules().proxy_for_ftp = proxy_server; | 156 config->proxy_rules().proxies_for_ftp.SetSingleProxyServer(proxy_server); |
| 156 if (have_http || have_https || have_ftp) { | 157 if (have_http || have_https || have_ftp) { |
| 157 // mustn't change type unless some rules are actually set. | 158 // mustn't change type unless some rules are actually set. |
| 158 config->proxy_rules().type = | 159 config->proxy_rules().type = |
| 159 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME; | 160 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME; |
| 160 } | 161 } |
| 161 } | 162 } |
| 162 if (config->proxy_rules().empty()) { | 163 if (config->proxy_rules().empty()) { |
| 163 // If the above were not defined, try for socks. | 164 // If the above were not defined, try for socks. |
| 164 // For environment variables, we default to version 5, per the gnome | 165 // For environment variables, we default to version 5, per the gnome |
| 165 // documentation: http://library.gnome.org/devel/gnet/stable/gnet-socks.html | 166 // documentation: http://library.gnome.org/devel/gnet/stable/gnet-socks.html |
| 166 ProxyServer::Scheme scheme = ProxyServer::SCHEME_SOCKS5; | 167 ProxyServer::Scheme scheme = ProxyServer::SCHEME_SOCKS5; |
| 167 std::string env_version; | 168 std::string env_version; |
| 168 if (env_var_getter_->GetVar("SOCKS_VERSION", &env_version) | 169 if (env_var_getter_->GetVar("SOCKS_VERSION", &env_version) |
| 169 && env_version == "4") | 170 && env_version == "4") |
| 170 scheme = ProxyServer::SCHEME_SOCKS4; | 171 scheme = ProxyServer::SCHEME_SOCKS4; |
| 171 if (GetProxyFromEnvVarForScheme("SOCKS_SERVER", scheme, &proxy_server)) { | 172 if (GetProxyFromEnvVarForScheme("SOCKS_SERVER", scheme, &proxy_server)) { |
| 172 config->proxy_rules().type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY; | 173 config->proxy_rules().type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY; |
| 173 config->proxy_rules().single_proxy = proxy_server; | 174 config->proxy_rules().single_proxies.SetSingleProxyServer(proxy_server); |
| 174 } | 175 } |
| 175 } | 176 } |
| 176 // Look for the proxy bypass list. | 177 // Look for the proxy bypass list. |
| 177 std::string no_proxy; | 178 std::string no_proxy; |
| 178 env_var_getter_->GetVar("no_proxy", &no_proxy); | 179 env_var_getter_->GetVar("no_proxy", &no_proxy); |
| 179 if (config->proxy_rules().empty()) { | 180 if (config->proxy_rules().empty()) { |
| 180 // Having only "no_proxy" set, presumably to "*", makes it | 181 // Having only "no_proxy" set, presumably to "*", makes it |
| 181 // explicit that env vars do specify a configuration: having no | 182 // explicit that env vars do specify a configuration: having no |
| 182 // rules specified only means the user explicitly asks for direct | 183 // rules specified only means the user explicitly asks for direct |
| 183 // connections. | 184 // connections. |
| (...skipping 1254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1438 num_proxies_specified++; | 1439 num_proxies_specified++; |
| 1439 if (GetProxyFromSettings(SettingGetter::PROXY_FTP_HOST, &proxy_for_ftp)) | 1440 if (GetProxyFromSettings(SettingGetter::PROXY_FTP_HOST, &proxy_for_ftp)) |
| 1440 num_proxies_specified++; | 1441 num_proxies_specified++; |
| 1441 if (GetProxyFromSettings(SettingGetter::PROXY_SOCKS_HOST, &socks_proxy)) | 1442 if (GetProxyFromSettings(SettingGetter::PROXY_SOCKS_HOST, &socks_proxy)) |
| 1442 num_proxies_specified++; | 1443 num_proxies_specified++; |
| 1443 | 1444 |
| 1444 if (same_proxy) { | 1445 if (same_proxy) { |
| 1445 if (proxy_for_http.is_valid()) { | 1446 if (proxy_for_http.is_valid()) { |
| 1446 // Use the http proxy for all schemes. | 1447 // Use the http proxy for all schemes. |
| 1447 config->proxy_rules().type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY; | 1448 config->proxy_rules().type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY; |
| 1448 config->proxy_rules().single_proxy = proxy_for_http; | 1449 config->proxy_rules().single_proxies.SetSingleProxyServer(proxy_for_http); |
| 1449 } | 1450 } |
| 1450 } else if (num_proxies_specified > 0) { | 1451 } else if (num_proxies_specified > 0) { |
| 1451 if (socks_proxy.is_valid() && num_proxies_specified == 1) { | 1452 if (socks_proxy.is_valid() && num_proxies_specified == 1) { |
| 1452 // If the only proxy specified was for SOCKS, use it for all schemes. | 1453 // If the only proxy specified was for SOCKS, use it for all schemes. |
| 1453 config->proxy_rules().type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY; | 1454 config->proxy_rules().type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY; |
| 1454 config->proxy_rules().single_proxy = socks_proxy; | 1455 config->proxy_rules().single_proxies.SetSingleProxyServer(socks_proxy); |
| 1455 } else { | 1456 } else { |
| 1456 // Otherwise use the indicate proxies per-scheme. | 1457 // Otherwise use the indicated proxies per-scheme. |
| 1457 config->proxy_rules().type = | 1458 config->proxy_rules().type = |
| 1458 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME; | 1459 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME; |
| 1459 config->proxy_rules().proxy_for_http = proxy_for_http; | 1460 config->proxy_rules().proxies_for_http. |
| 1460 config->proxy_rules().proxy_for_https = proxy_for_https; | 1461 SetSingleProxyServer(proxy_for_http); |
| 1461 config->proxy_rules().proxy_for_ftp = proxy_for_ftp; | 1462 config->proxy_rules().proxies_for_https. |
| 1462 config->proxy_rules().fallback_proxy = socks_proxy; | 1463 SetSingleProxyServer(proxy_for_https); |
| 1464 config->proxy_rules().proxies_for_ftp.SetSingleProxyServer(proxy_for_ftp); |
| 1465 config->proxy_rules().fallback_proxies.SetSingleProxyServer(socks_proxy); |
| 1463 } | 1466 } |
| 1464 } | 1467 } |
| 1465 | 1468 |
| 1466 if (config->proxy_rules().empty()) { | 1469 if (config->proxy_rules().empty()) { |
| 1467 // Manual mode but we couldn't parse any rules. | 1470 // Manual mode but we couldn't parse any rules. |
| 1468 return false; | 1471 return false; |
| 1469 } | 1472 } |
| 1470 | 1473 |
| 1471 // Check for authentication, just so we can warn. | 1474 // Check for authentication, just so we can warn. |
| 1472 bool use_auth = false; | 1475 bool use_auth = false; |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1751 void ProxyConfigServiceLinux::RemoveObserver(Observer* observer) { | 1754 void ProxyConfigServiceLinux::RemoveObserver(Observer* observer) { |
| 1752 delegate_->RemoveObserver(observer); | 1755 delegate_->RemoveObserver(observer); |
| 1753 } | 1756 } |
| 1754 | 1757 |
| 1755 ProxyConfigService::ConfigAvailability | 1758 ProxyConfigService::ConfigAvailability |
| 1756 ProxyConfigServiceLinux::GetLatestProxyConfig(ProxyConfig* config) { | 1759 ProxyConfigServiceLinux::GetLatestProxyConfig(ProxyConfig* config) { |
| 1757 return delegate_->GetLatestProxyConfig(config); | 1760 return delegate_->GetLatestProxyConfig(config); |
| 1758 } | 1761 } |
| 1759 | 1762 |
| 1760 } // namespace net | 1763 } // namespace net |
| OLD | NEW |