diff options
Diffstat (limited to 'net/proxy/proxy_config.cc')
-rw-r--r-- | net/proxy/proxy_config.cc | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/net/proxy/proxy_config.cc b/net/proxy/proxy_config.cc index fb30124..07c1d50 100644 --- a/net/proxy/proxy_config.cc +++ b/net/proxy/proxy_config.cc @@ -4,6 +4,9 @@ #include "net/proxy/proxy_config.h" +#include "base/string_tokenizer.h" +#include "base/string_util.h" + namespace net { // static @@ -25,4 +28,55 @@ bool ProxyConfig::Equals(const ProxyConfig& other) const { proxy_bypass_local_names == other.proxy_bypass_local_names; } +void ProxyConfig::ProxyRules::ParseFromString(const std::string& proxy_rules) { + // Reset. + type = TYPE_NO_RULES; + single_proxy = ProxyServer(); + proxy_for_http = ProxyServer(); + proxy_for_https = ProxyServer(); + proxy_for_ftp = ProxyServer(); + + StringTokenizer proxy_server_list(proxy_rules, ";"); + while (proxy_server_list.GetNext()) { + StringTokenizer proxy_server_for_scheme( + proxy_server_list.token_begin(), proxy_server_list.token_end(), "="); + + while (proxy_server_for_scheme.GetNext()) { + std::string url_scheme = proxy_server_for_scheme.token(); + + // If we fail to get the proxy server here, it means that + // this is a regular proxy server configuration, i.e. proxies + // are not configured per protocol. + if (!proxy_server_for_scheme.GetNext()) { + if (type == TYPE_PROXY_PER_SCHEME) + continue; // Unexpected. + single_proxy = ProxyServer::FromURI(url_scheme); + type = TYPE_SINGLE_PROXY; + return; + } + + // Trim whitespace off the url scheme. + TrimWhitespaceASCII(url_scheme, TRIM_ALL, &url_scheme); + + // Add it to the per-scheme mappings (if supported scheme). + type = TYPE_PROXY_PER_SCHEME; + if (const ProxyServer* entry = MapSchemeToProxy(url_scheme)) + *const_cast<ProxyServer*>(entry) = + ProxyServer::FromURI(proxy_server_for_scheme.token()); + } + } +} + +const ProxyServer* ProxyConfig::ProxyRules::MapSchemeToProxy( + const std::string& scheme) const { + DCHECK(type == TYPE_PROXY_PER_SCHEME); + if (scheme == "http") + return &proxy_for_http; + if (scheme == "https") + return &proxy_for_https; + if (scheme == "ftp") + return &proxy_for_ftp; + return NULL; // No mapping for this scheme. +} + } // namespace net |