2012-09-14 20:27:46 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef ProxyAutoConfig_h__
|
|
|
|
#define ProxyAutoConfig_h__
|
|
|
|
|
|
|
|
#include "nsString.h"
|
2013-09-22 03:04:57 +00:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
2017-07-04 22:48:00 +00:00
|
|
|
class nsIEventTarget;
|
2013-09-22 03:04:57 +00:00
|
|
|
class nsITimer;
|
|
|
|
namespace JS {
|
2014-03-25 18:42:33 +00:00
|
|
|
class CallArgs;
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace JS
|
2013-08-17 22:50:18 +00:00
|
|
|
|
2012-09-14 20:27:46 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
2016-07-23 17:54:19 +00:00
|
|
|
class JSContextWrapper;
|
2013-09-22 03:04:57 +00:00
|
|
|
union NetAddr;
|
2012-09-14 20:27:46 +00:00
|
|
|
|
|
|
|
// The ProxyAutoConfig class is meant to be created and run on a
|
|
|
|
// non main thread. It synchronously resolves PAC files by blocking that
|
|
|
|
// thread and running nested event loops. GetProxyForURI is not re-entrant.
|
|
|
|
|
|
|
|
class ProxyAutoConfig {
|
|
|
|
public:
|
2013-09-22 03:04:57 +00:00
|
|
|
ProxyAutoConfig();
|
2012-09-14 20:27:46 +00:00
|
|
|
~ProxyAutoConfig();
|
|
|
|
|
2018-12-04 19:40:45 +00:00
|
|
|
nsresult Init(const nsCString& aPACURI, const nsCString& aPACScriptData,
|
2017-07-04 22:48:00 +00:00
|
|
|
bool aIncludePath, uint32_t aExtraHeapSize,
|
|
|
|
nsIEventTarget* aEventTarget);
|
2014-08-07 15:38:41 +00:00
|
|
|
void SetThreadLocalIndex(uint32_t index);
|
2012-09-14 20:27:46 +00:00
|
|
|
void Shutdown();
|
|
|
|
void GC();
|
2014-03-25 18:42:33 +00:00
|
|
|
bool MyIPAddress(const JS::CallArgs& aArgs);
|
2012-09-14 20:27:46 +00:00
|
|
|
bool ResolveAddress(const nsCString& aHostName, NetAddr* aNetAddr,
|
2012-12-23 21:08:43 +00:00
|
|
|
unsigned int aTimeout);
|
2012-09-14 20:27:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the proxy string for the specified URI. The proxy string is
|
|
|
|
* given by the following:
|
|
|
|
*
|
|
|
|
* result = proxy-spec *( proxy-sep proxy-spec )
|
|
|
|
* proxy-spec = direct-type | proxy-type LWS proxy-host [":" proxy-port]
|
|
|
|
* direct-type = "DIRECT"
|
2014-04-15 22:16:41 +00:00
|
|
|
* proxy-type = "PROXY" | "HTTP" | "HTTPS" | "SOCKS" | "SOCKS4" | "SOCKS5"
|
2012-09-14 20:27:46 +00:00
|
|
|
* proxy-sep = ";" LWS
|
|
|
|
* proxy-host = hostname | ipv4-address-literal
|
|
|
|
* proxy-port = <any 16-bit unsigned integer>
|
|
|
|
* LWS = *( SP | HT )
|
|
|
|
* SP = <US-ASCII SP, space (32)>
|
|
|
|
* HT = <US-ASCII HT, horizontal-tab (9)>
|
|
|
|
*
|
|
|
|
* NOTE: direct-type and proxy-type are case insensitive
|
|
|
|
* NOTE: SOCKS implies SOCKS4
|
|
|
|
*
|
|
|
|
* Examples:
|
|
|
|
* "PROXY proxy1.foo.com:8080; PROXY proxy2.foo.com:8080; DIRECT"
|
|
|
|
* "SOCKS socksproxy"
|
|
|
|
* "DIRECT"
|
|
|
|
*
|
|
|
|
* XXX add support for IPv6 address literals.
|
|
|
|
* XXX quote whatever the official standard is for PAC.
|
|
|
|
*
|
|
|
|
* @param aTestURI
|
|
|
|
* The URI as an ASCII string to test.
|
|
|
|
* @param aTestHost
|
|
|
|
* The ASCII hostname to test.
|
|
|
|
*
|
|
|
|
* @param result
|
|
|
|
* result string as defined above.
|
|
|
|
*/
|
|
|
|
nsresult GetProxyForURI(const nsCString& aTestURI, const nsCString& aTestHost,
|
|
|
|
nsACString& result);
|
|
|
|
|
|
|
|
private:
|
2014-09-18 15:53:30 +00:00
|
|
|
// allow 665ms for myipaddress dns queries. That's 95th percentile.
|
|
|
|
const static unsigned int kTimeout = 665;
|
2012-09-14 20:27:46 +00:00
|
|
|
|
2012-09-14 20:27:46 +00:00
|
|
|
// used to compile the PAC file and setup the execution context
|
|
|
|
nsresult SetupJS();
|
|
|
|
|
2012-12-23 21:08:43 +00:00
|
|
|
bool SrcAddress(const NetAddr* remoteAddress, nsCString& localAddress);
|
2012-09-14 20:27:46 +00:00
|
|
|
bool MyIPAddressTryHost(const nsCString& hostName, unsigned int timeout,
|
2014-03-26 17:38:29 +00:00
|
|
|
const JS::CallArgs& aArgs, bool* aResult);
|
2012-09-14 20:27:46 +00:00
|
|
|
|
2016-07-23 17:54:19 +00:00
|
|
|
JSContextWrapper* mJSContext;
|
2012-09-14 20:27:46 +00:00
|
|
|
bool mJSNeedsSetup;
|
|
|
|
bool mShutdown;
|
2018-12-04 19:40:45 +00:00
|
|
|
nsCString mConcatenatedPACData;
|
2012-09-14 20:27:46 +00:00
|
|
|
nsCString mPACURI;
|
2016-09-21 01:42:52 +00:00
|
|
|
bool mIncludePath;
|
2017-05-24 06:24:55 +00:00
|
|
|
uint32_t mExtraHeapSize;
|
2012-09-14 20:27:46 +00:00
|
|
|
nsCString mRunningHost;
|
|
|
|
nsCOMPtr<nsITimer> mTimer;
|
2017-07-04 22:48:00 +00:00
|
|
|
nsCOMPtr<nsIEventTarget> mMainThreadEventTarget;
|
2012-09-14 20:27:46 +00:00
|
|
|
};
|
|
|
|
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|
2012-09-14 20:27:46 +00:00
|
|
|
|
|
|
|
#endif // ProxyAutoConfig_h__
|