netwerk/base/src/ProxyAutoConfig.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef ProxyAutoConfig_h__
michael@0 8 #define ProxyAutoConfig_h__
michael@0 9
michael@0 10 #include "nsString.h"
michael@0 11 #include "nsCOMPtr.h"
michael@0 12
michael@0 13 class nsITimer;
michael@0 14 namespace JS {
michael@0 15 class CallArgs;
michael@0 16 }
michael@0 17
michael@0 18 namespace mozilla { namespace net {
michael@0 19
michael@0 20 class JSRuntimeWrapper;
michael@0 21 union NetAddr;
michael@0 22
michael@0 23 // The ProxyAutoConfig class is meant to be created and run on a
michael@0 24 // non main thread. It synchronously resolves PAC files by blocking that
michael@0 25 // thread and running nested event loops. GetProxyForURI is not re-entrant.
michael@0 26
michael@0 27 class ProxyAutoConfig {
michael@0 28 public:
michael@0 29 ProxyAutoConfig();
michael@0 30 ~ProxyAutoConfig();
michael@0 31
michael@0 32 nsresult Init(const nsCString &aPACURI,
michael@0 33 const nsCString &aPACScript);
michael@0 34 void Shutdown();
michael@0 35 void GC();
michael@0 36 bool MyIPAddress(const JS::CallArgs &aArgs);
michael@0 37 bool ResolveAddress(const nsCString &aHostName,
michael@0 38 NetAddr *aNetAddr, unsigned int aTimeout);
michael@0 39
michael@0 40 /**
michael@0 41 * Get the proxy string for the specified URI. The proxy string is
michael@0 42 * given by the following:
michael@0 43 *
michael@0 44 * result = proxy-spec *( proxy-sep proxy-spec )
michael@0 45 * proxy-spec = direct-type | proxy-type LWS proxy-host [":" proxy-port]
michael@0 46 * direct-type = "DIRECT"
michael@0 47 * proxy-type = "PROXY" | "SOCKS" | "SOCKS4" | "SOCKS5"
michael@0 48 * proxy-sep = ";" LWS
michael@0 49 * proxy-host = hostname | ipv4-address-literal
michael@0 50 * proxy-port = <any 16-bit unsigned integer>
michael@0 51 * LWS = *( SP | HT )
michael@0 52 * SP = <US-ASCII SP, space (32)>
michael@0 53 * HT = <US-ASCII HT, horizontal-tab (9)>
michael@0 54 *
michael@0 55 * NOTE: direct-type and proxy-type are case insensitive
michael@0 56 * NOTE: SOCKS implies SOCKS4
michael@0 57 *
michael@0 58 * Examples:
michael@0 59 * "PROXY proxy1.foo.com:8080; PROXY proxy2.foo.com:8080; DIRECT"
michael@0 60 * "SOCKS socksproxy"
michael@0 61 * "DIRECT"
michael@0 62 *
michael@0 63 * XXX add support for IPv6 address literals.
michael@0 64 * XXX quote whatever the official standard is for PAC.
michael@0 65 *
michael@0 66 * @param aTestURI
michael@0 67 * The URI as an ASCII string to test.
michael@0 68 * @param aTestHost
michael@0 69 * The ASCII hostname to test.
michael@0 70 *
michael@0 71 * @param result
michael@0 72 * result string as defined above.
michael@0 73 */
michael@0 74 nsresult GetProxyForURI(const nsCString &aTestURI,
michael@0 75 const nsCString &aTestHost,
michael@0 76 nsACString &result);
michael@0 77
michael@0 78 private:
michael@0 79 const static unsigned int kTimeout = 1000; // ms to allow for myipaddress dns queries
michael@0 80
michael@0 81 // used to compile the PAC file and setup the execution context
michael@0 82 nsresult SetupJS();
michael@0 83
michael@0 84 bool SrcAddress(const NetAddr *remoteAddress, nsCString &localAddress);
michael@0 85 bool MyIPAddressTryHost(const nsCString &hostName, unsigned int timeout,
michael@0 86 const JS::CallArgs &aArgs, bool* aResult);
michael@0 87
michael@0 88 JSRuntimeWrapper *mJSRuntime;
michael@0 89 bool mJSNeedsSetup;
michael@0 90 bool mShutdown;
michael@0 91 nsCString mPACScript;
michael@0 92 nsCString mPACURI;
michael@0 93 nsCString mRunningHost;
michael@0 94 nsCOMPtr<nsITimer> mTimer;
michael@0 95 };
michael@0 96
michael@0 97 }} // namespace mozilla::net
michael@0 98
michael@0 99 #endif // ProxyAutoConfig_h__

mercurial