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