Browse Source

make direct-hosts use glob characters correctly

David Rose 22 years ago
parent
commit
c88b65d0f6

+ 2 - 0
panda/src/downloader/config_downloader.cxx

@@ -82,6 +82,8 @@ config_downloader.GetBool("verify-ssl", true);
 // connections that don't specify otherwise.
 const string http_proxy =
 config_downloader.GetString("http-proxy", "");
+const string http_direct_hosts =
+config_downloader.GetString("http-direct-hosts", "");
 const string http_proxy_username =
 config_downloader.GetString("http-proxy-username", "");
 

+ 1 - 0
panda/src/downloader/config_downloader.h

@@ -43,6 +43,7 @@ extern const int patcher_buffer_size;
 extern const bool early_random_seed;
 extern const bool verify_ssl;
 extern const string http_proxy;
+extern const string http_direct_hosts;
 extern const string http_proxy_username;
 extern const double connect_timeout;
 extern const double http_timeout;

+ 27 - 17
panda/src/downloader/httpClient.cxx

@@ -25,6 +25,7 @@
 #include "executionEnvironment.h"
 #include "httpBasicAuthorization.h"
 #include "httpDigestAuthorization.h"
+#include "globPattern.h"
 
 #ifdef HAVE_SSL
 
@@ -102,6 +103,8 @@ HTTPClient() {
   _ssl_ctx = (SSL_CTX *)NULL;
 
   set_proxy_spec(http_proxy);
+  set_direct_host_spec(http_direct_hosts);
+
   if (!http_proxy_username.empty()) {
     set_username("*proxy", "", http_proxy_username);
   }
@@ -251,11 +254,6 @@ set_proxy_spec(const string &proxy_spec) {
       url = URLSpec(spec.substr(equals + 1), true);
     }
 
-    if (!url.has_scheme()) {
-      // The default scheme for talking to proxies is HTTP.
-      url.set_scheme("http");
-    }
-
     add_proxy(scheme, url);
   }
 }
@@ -301,8 +299,8 @@ get_proxy_spec() const {
 //       Access: Published
 //  Description: Specifies the set of hosts that should be connected
 //               to directly, without using a proxy.  This is a
-//               semicolon-separated list of hostnames or ip addresses,
-//               that may contain wildcard characters ("*").
+//               semicolon-separated list of hostnames that may
+//               contain wildcard characters ("*").
 ////////////////////////////////////////////////////////////////////
 void HTTPClient::
 set_direct_host_spec(const string &direct_host_spec) {
@@ -325,21 +323,21 @@ set_direct_host_spec(const string &direct_host_spec) {
 //       Access: Published
 //  Description: Returns the set of hosts that should be connected
 //               to directly, without using a proxy, as a
-//               semicolon-separated list of hostnames or ip addresses,
-//               that may contain wildcard characters ("*").
+//               semicolon-separated list of hostnames that may
+//               contain wildcard characters ("*").
 ////////////////////////////////////////////////////////////////////
 string HTTPClient::
 get_direct_host_spec() const {
   string result;
 
-  vector_string::const_iterator si;
+  DirectHosts::const_iterator si;
   for (si = _direct_hosts.begin(); si != _direct_hosts.end(); ++si) {
-    const string &host = (*si);
+    const GlobPattern &host = (*si);
 
     if (!result.empty()) {
       result += ";";
     }
-    result += host;
+    result += host.get_pattern();
   }
 
   return result;
@@ -367,6 +365,8 @@ clear_proxy() {
 ////////////////////////////////////////////////////////////////////
 void HTTPClient::
 add_proxy(const string &scheme, const URLSpec &proxy) {
+  URLSpec proxy_url(proxy);
+
   // The scheme is always converted to lowercase.
   string lc_scheme;
   lc_scheme.reserve(scheme.length());
@@ -379,7 +379,18 @@ add_proxy(const string &scheme, const URLSpec &proxy) {
     lc_scheme = lc_scheme.substr(0, lc_scheme.length() - 1);
   }
 
-  _proxies_by_scheme[lc_scheme].push_back(proxy);
+  if (lc_scheme == "socks") {
+    // Scheme "socks" implies we talk to the proxy via the "socks"
+    // scheme, no matter what scheme the user actually specified.
+    proxy_url.set_scheme("socks");
+
+  } else if (!proxy_url.has_scheme()) {
+    // Otherwise, if the user didn't specify a scheme to talk to the
+    // proxy, the default is "http".
+    proxy_url.set_scheme("http");
+  }
+
+  _proxies_by_scheme[lc_scheme].push_back(proxy_url);
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -414,7 +425,7 @@ add_direct_host(const string &hostname) {
     lc_hostname += tolower(*si);
   }
 
-  _direct_hosts.push_back(lc_hostname);
+  _direct_hosts.push_back(GlobPattern(lc_hostname));
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -435,10 +446,9 @@ get_proxies_for_url(const URLSpec &url, pvector<URLSpec> &proxies) const {
   // First, check if the hostname matches any listed in direct_hosts.
   string hostname = url.get_server();
 
-  // TODO: This should be a glob match, not a literal match.
-  vector_string::const_iterator si;
+  DirectHosts::const_iterator si;
   for (si = _direct_hosts.begin(); si != _direct_hosts.end(); ++si) {
-    if ((*si) == hostname) {
+    if ((*si).matches(hostname)) {
       // It matches, so don't use any proxies.
       return;
     }

+ 3 - 2
panda/src/downloader/httpClient.h

@@ -31,10 +31,10 @@
 #include "urlSpec.h"
 #include "httpAuthorization.h"
 #include "httpEnum.h"
+#include "globPattern.h"
 #include "pointerTo.h"
 #include "pvector.h"
 #include "pmap.h"
-#include "vector_string.h"
 
 #include <openssl/ssl.h>
 
@@ -136,7 +136,8 @@ private:
   typedef pvector<URLSpec> Proxies;
   typedef pmap<string, Proxies> ProxiesByScheme;
   ProxiesByScheme _proxies_by_scheme;
-  vector_string _direct_hosts;
+  typedef pvector<GlobPattern> DirectHosts;
+  DirectHosts _direct_hosts;
 
   HTTPEnum::HTTPVersion _http_version;
   VerifySSL _verify_ssl;