1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/base/src/ProxyAutoConfig.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,99 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:set ts=2 sw=2 sts=2 et cindent: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef ProxyAutoConfig_h__ 1.11 +#define ProxyAutoConfig_h__ 1.12 + 1.13 +#include "nsString.h" 1.14 +#include "nsCOMPtr.h" 1.15 + 1.16 +class nsITimer; 1.17 +namespace JS { 1.18 +class CallArgs; 1.19 +} 1.20 + 1.21 +namespace mozilla { namespace net { 1.22 + 1.23 +class JSRuntimeWrapper; 1.24 +union NetAddr; 1.25 + 1.26 +// The ProxyAutoConfig class is meant to be created and run on a 1.27 +// non main thread. It synchronously resolves PAC files by blocking that 1.28 +// thread and running nested event loops. GetProxyForURI is not re-entrant. 1.29 + 1.30 +class ProxyAutoConfig { 1.31 +public: 1.32 + ProxyAutoConfig(); 1.33 + ~ProxyAutoConfig(); 1.34 + 1.35 + nsresult Init(const nsCString &aPACURI, 1.36 + const nsCString &aPACScript); 1.37 + void Shutdown(); 1.38 + void GC(); 1.39 + bool MyIPAddress(const JS::CallArgs &aArgs); 1.40 + bool ResolveAddress(const nsCString &aHostName, 1.41 + NetAddr *aNetAddr, unsigned int aTimeout); 1.42 + 1.43 + /** 1.44 + * Get the proxy string for the specified URI. The proxy string is 1.45 + * given by the following: 1.46 + * 1.47 + * result = proxy-spec *( proxy-sep proxy-spec ) 1.48 + * proxy-spec = direct-type | proxy-type LWS proxy-host [":" proxy-port] 1.49 + * direct-type = "DIRECT" 1.50 + * proxy-type = "PROXY" | "SOCKS" | "SOCKS4" | "SOCKS5" 1.51 + * proxy-sep = ";" LWS 1.52 + * proxy-host = hostname | ipv4-address-literal 1.53 + * proxy-port = <any 16-bit unsigned integer> 1.54 + * LWS = *( SP | HT ) 1.55 + * SP = <US-ASCII SP, space (32)> 1.56 + * HT = <US-ASCII HT, horizontal-tab (9)> 1.57 + * 1.58 + * NOTE: direct-type and proxy-type are case insensitive 1.59 + * NOTE: SOCKS implies SOCKS4 1.60 + * 1.61 + * Examples: 1.62 + * "PROXY proxy1.foo.com:8080; PROXY proxy2.foo.com:8080; DIRECT" 1.63 + * "SOCKS socksproxy" 1.64 + * "DIRECT" 1.65 + * 1.66 + * XXX add support for IPv6 address literals. 1.67 + * XXX quote whatever the official standard is for PAC. 1.68 + * 1.69 + * @param aTestURI 1.70 + * The URI as an ASCII string to test. 1.71 + * @param aTestHost 1.72 + * The ASCII hostname to test. 1.73 + * 1.74 + * @param result 1.75 + * result string as defined above. 1.76 + */ 1.77 + nsresult GetProxyForURI(const nsCString &aTestURI, 1.78 + const nsCString &aTestHost, 1.79 + nsACString &result); 1.80 + 1.81 +private: 1.82 + const static unsigned int kTimeout = 1000; // ms to allow for myipaddress dns queries 1.83 + 1.84 + // used to compile the PAC file and setup the execution context 1.85 + nsresult SetupJS(); 1.86 + 1.87 + bool SrcAddress(const NetAddr *remoteAddress, nsCString &localAddress); 1.88 + bool MyIPAddressTryHost(const nsCString &hostName, unsigned int timeout, 1.89 + const JS::CallArgs &aArgs, bool* aResult); 1.90 + 1.91 + JSRuntimeWrapper *mJSRuntime; 1.92 + bool mJSNeedsSetup; 1.93 + bool mShutdown; 1.94 + nsCString mPACScript; 1.95 + nsCString mPACURI; 1.96 + nsCString mRunningHost; 1.97 + nsCOMPtr<nsITimer> mTimer; 1.98 +}; 1.99 + 1.100 +}} // namespace mozilla::net 1.101 + 1.102 +#endif // ProxyAutoConfig_h__