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

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

Issue 115029: Making command-line specified proxy settings more flexible - allowing for set... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 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_service_linux.h ('k') | net/proxy/proxy_config_unittest.cc » ('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) 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 <gdk/gdk.h> 8 #include <gdk/gdk.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 10
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 } 107 }
108 return false; 108 return false;
109 } 109 }
110 110
111 bool ProxyConfigServiceLinux::GetProxyFromEnvVar( 111 bool ProxyConfigServiceLinux::GetProxyFromEnvVar(
112 const char* variable, ProxyServer* result_server) { 112 const char* variable, ProxyServer* result_server) {
113 return GetProxyFromEnvVarForScheme(variable, ProxyServer::SCHEME_HTTP, 113 return GetProxyFromEnvVarForScheme(variable, ProxyServer::SCHEME_HTTP,
114 result_server); 114 result_server);
115 } 115 }
116 116
117 namespace {
118
119 // Returns true if the given string represents an IP address.
120 bool IsIPAddress(const std::string& domain) {
121 // From GURL::HostIsIPAddress()
122 url_canon::RawCanonOutputT<char, 128> ignored_output;
123 url_parse::Component ignored_component;
124 url_parse::Component domain_comp(0, domain.size());
125 return url_canon::CanonicalizeIPAddress(domain.c_str(), domain_comp,
126 &ignored_output,
127 &ignored_component);
128 }
129
130 } // namespace
131
132 void ProxyConfigServiceLinux::ParseNoProxyList(const std::string& no_proxy,
133 ProxyConfig* config) {
134 if (no_proxy.empty())
135 return;
136 // Traditional semantics:
137 // A single "*" is specifically allowed and unproxies anything.
138 // "*" wildcards other than a single "*" entry are not universally
139 // supported. We will support them, as we get * wildcards for free
140 // (see MatchPattern() called from ProxyService::ShouldBypassProxyForURL()).
141 // no_proxy is a comma-separated list of <trailing_domain>[:<port>].
142 // If no port is specified then any port matches.
143 // The historical definition has trailing_domain match using a simple
144 // string "endswith" test, so that the match need not correspond to a
145 // "." boundary. For example: "google.com" matches "igoogle.com" too.
146 // Seems like that could be confusing, but we'll obey tradition.
147 // IP CIDR patterns are supposed to be supported too. We intend
148 // to do this in proxy_service.cc, but it's currently a TODO.
149 // See: http://crbug.com/9835.
150 StringTokenizer no_proxy_list(no_proxy, ",");
151 while (no_proxy_list.GetNext()) {
152 std::string bypass_entry = no_proxy_list.token();
153 TrimWhitespaceASCII(bypass_entry, TRIM_ALL, &bypass_entry);
154 if (bypass_entry.empty())
155 continue;
156 if (bypass_entry.at(0) != '*') {
157 // Insert a wildcard * to obtain an endsWith match, unless the
158 // entry looks like it might be an IP or CIDR.
159 // First look for either a :<port> or CIDR mask length suffix.
160 std::string::const_iterator begin = bypass_entry.begin();
161 std::string::const_iterator scan = bypass_entry.end() - 1;
162 while (scan > begin && IsAsciiDigit(*scan))
163 --scan;
164 std::string potential_ip;
165 if (*scan == '/' || *scan == ':')
166 potential_ip = std::string(begin, scan - 1);
167 else
168 potential_ip = bypass_entry;
169 if (!IsIPAddress(potential_ip)) {
170 // Do insert a wildcard.
171 bypass_entry.insert(0, "*");
172 }
173 // TODO(sdoyon): When CIDR matching is implemented in
174 // proxy_service.cc, consider making config->proxy_bypass more
175 // sophisticated to avoid parsing out the string on every
176 // request.
177 }
178 config->proxy_bypass.push_back(bypass_entry);
179 }
180 }
181
182 bool ProxyConfigServiceLinux::GetConfigFromEnv(ProxyConfig* config) { 117 bool ProxyConfigServiceLinux::GetConfigFromEnv(ProxyConfig* config) {
183 // Check for automatic configuration first, in 118 // Check for automatic configuration first, in
184 // "auto_proxy". Possibly only the "environment_proxy" firefox 119 // "auto_proxy". Possibly only the "environment_proxy" firefox
185 // extension has ever used this, but it still sounds like a good 120 // extension has ever used this, but it still sounds like a good
186 // idea. 121 // idea.
187 std::string auto_proxy; 122 std::string auto_proxy;
188 if (env_var_getter_->Getenv("auto_proxy", &auto_proxy)) { 123 if (env_var_getter_->Getenv("auto_proxy", &auto_proxy)) {
189 if (auto_proxy.empty()) { 124 if (auto_proxy.empty()) {
190 // Defined and empty => autodetect 125 // Defined and empty => autodetect
191 config->auto_detect = true; 126 config->auto_detect = true;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 // Look for the proxy bypass list. 170 // Look for the proxy bypass list.
236 std::string no_proxy; 171 std::string no_proxy;
237 env_var_getter_->Getenv("no_proxy", &no_proxy); 172 env_var_getter_->Getenv("no_proxy", &no_proxy);
238 if (config->proxy_rules.empty()) { 173 if (config->proxy_rules.empty()) {
239 // Having only "no_proxy" set, presumably to "*", makes it 174 // Having only "no_proxy" set, presumably to "*", makes it
240 // explicit that env vars do specify a configuration: having no 175 // explicit that env vars do specify a configuration: having no
241 // rules specified only means the user explicitly asks for direct 176 // rules specified only means the user explicitly asks for direct
242 // connections. 177 // connections.
243 return !no_proxy.empty(); 178 return !no_proxy.empty();
244 } 179 }
245 ParseNoProxyList(no_proxy, config); 180 config->ParseNoProxyList(no_proxy);
246 return true; 181 return true;
247 } 182 }
248 183
249 namespace { 184 namespace {
250 185
251 class GConfSettingGetterImpl 186 class GConfSettingGetterImpl
252 : public ProxyConfigServiceLinux::GConfSettingGetter { 187 : public ProxyConfigServiceLinux::GConfSettingGetter {
253 public: 188 public:
254 GConfSettingGetterImpl() : client_(NULL) {} 189 GConfSettingGetterImpl() : client_(NULL) {}
255 virtual ~GConfSettingGetterImpl() { 190 virtual ~GConfSettingGetterImpl() {
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 if (!ok) { 485 if (!ok) {
551 ok = GetConfigFromEnv(config); 486 ok = GetConfigFromEnv(config);
552 if (ok) 487 if (ok)
553 LOG(INFO) << "ProxyConfigServiceLinux: obtained proxy setting " 488 LOG(INFO) << "ProxyConfigServiceLinux: obtained proxy setting "
554 "from environment variables"; 489 "from environment variables";
555 } 490 }
556 return ok ? OK : ERR_FAILED; 491 return ok ? OK : ERR_FAILED;
557 } 492 }
558 493
559 } // namespace net 494 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_config_service_linux.h ('k') | net/proxy/proxy_config_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698