michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et cindent: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef ProxyAutoConfig_h__ michael@0: #define ProxyAutoConfig_h__ michael@0: michael@0: #include "nsString.h" michael@0: #include "nsCOMPtr.h" michael@0: michael@0: class nsITimer; michael@0: namespace JS { michael@0: class CallArgs; michael@0: } michael@0: michael@0: namespace mozilla { namespace net { michael@0: michael@0: class JSRuntimeWrapper; michael@0: union NetAddr; michael@0: michael@0: // The ProxyAutoConfig class is meant to be created and run on a michael@0: // non main thread. It synchronously resolves PAC files by blocking that michael@0: // thread and running nested event loops. GetProxyForURI is not re-entrant. michael@0: michael@0: class ProxyAutoConfig { michael@0: public: michael@0: ProxyAutoConfig(); michael@0: ~ProxyAutoConfig(); michael@0: michael@0: nsresult Init(const nsCString &aPACURI, michael@0: const nsCString &aPACScript); michael@0: void Shutdown(); michael@0: void GC(); michael@0: bool MyIPAddress(const JS::CallArgs &aArgs); michael@0: bool ResolveAddress(const nsCString &aHostName, michael@0: NetAddr *aNetAddr, unsigned int aTimeout); michael@0: michael@0: /** michael@0: * Get the proxy string for the specified URI. The proxy string is michael@0: * given by the following: michael@0: * michael@0: * result = proxy-spec *( proxy-sep proxy-spec ) michael@0: * proxy-spec = direct-type | proxy-type LWS proxy-host [":" proxy-port] michael@0: * direct-type = "DIRECT" michael@0: * proxy-type = "PROXY" | "SOCKS" | "SOCKS4" | "SOCKS5" michael@0: * proxy-sep = ";" LWS michael@0: * proxy-host = hostname | ipv4-address-literal michael@0: * proxy-port = michael@0: * LWS = *( SP | HT ) michael@0: * SP = michael@0: * HT = michael@0: * michael@0: * NOTE: direct-type and proxy-type are case insensitive michael@0: * NOTE: SOCKS implies SOCKS4 michael@0: * michael@0: * Examples: michael@0: * "PROXY proxy1.foo.com:8080; PROXY proxy2.foo.com:8080; DIRECT" michael@0: * "SOCKS socksproxy" michael@0: * "DIRECT" michael@0: * michael@0: * XXX add support for IPv6 address literals. michael@0: * XXX quote whatever the official standard is for PAC. michael@0: * michael@0: * @param aTestURI michael@0: * The URI as an ASCII string to test. michael@0: * @param aTestHost michael@0: * The ASCII hostname to test. michael@0: * michael@0: * @param result michael@0: * result string as defined above. michael@0: */ michael@0: nsresult GetProxyForURI(const nsCString &aTestURI, michael@0: const nsCString &aTestHost, michael@0: nsACString &result); michael@0: michael@0: private: michael@0: const static unsigned int kTimeout = 1000; // ms to allow for myipaddress dns queries michael@0: michael@0: // used to compile the PAC file and setup the execution context michael@0: nsresult SetupJS(); michael@0: michael@0: bool SrcAddress(const NetAddr *remoteAddress, nsCString &localAddress); michael@0: bool MyIPAddressTryHost(const nsCString &hostName, unsigned int timeout, michael@0: const JS::CallArgs &aArgs, bool* aResult); michael@0: michael@0: JSRuntimeWrapper *mJSRuntime; michael@0: bool mJSNeedsSetup; michael@0: bool mShutdown; michael@0: nsCString mPACScript; michael@0: nsCString mPACURI; michael@0: nsCString mRunningHost; michael@0: nsCOMPtr mTimer; michael@0: }; michael@0: michael@0: }} // namespace mozilla::net michael@0: michael@0: #endif // ProxyAutoConfig_h__