2012-09-15 00:27:46 +04: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 07:04:57 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
|
|
|
class nsITimer;
|
|
|
|
namespace JS {
|
2014-03-25 22:42:33 +04:00
|
|
|
class CallArgs;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace JS
|
2013-08-18 02:50:18 +04:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
namespace mozilla { namespace net {
|
|
|
|
|
|
|
|
class JSRuntimeWrapper;
|
2013-09-22 07:04:57 +04:00
|
|
|
union NetAddr;
|
2012-09-15 00:27:46 +04: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 07:04:57 +04:00
|
|
|
ProxyAutoConfig();
|
2012-09-15 00:27:46 +04:00
|
|
|
~ProxyAutoConfig();
|
|
|
|
|
|
|
|
nsresult Init(const nsCString &aPACURI,
|
|
|
|
const nsCString &aPACScript);
|
2014-08-07 19:38:41 +04:00
|
|
|
void SetThreadLocalIndex(uint32_t index);
|
2012-09-15 00:27:46 +04:00
|
|
|
void Shutdown();
|
|
|
|
void GC();
|
2014-03-25 22:42:33 +04:00
|
|
|
bool MyIPAddress(const JS::CallArgs &aArgs);
|
2015-03-26 10:11:05 +03:00
|
|
|
bool MyAppId(const JS::CallArgs &aArgs);
|
|
|
|
bool MyAppOrigin(const JS::CallArgs &aArgs);
|
|
|
|
bool IsInBrowser(const JS::CallArgs &aArgs);
|
2012-09-15 00:27:46 +04:00
|
|
|
bool ResolveAddress(const nsCString &aHostName,
|
2012-12-24 01:08:43 +04:00
|
|
|
NetAddr *aNetAddr, unsigned int aTimeout);
|
2012-09-15 00:27:46 +04: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-16 02:16:41 +04:00
|
|
|
* proxy-type = "PROXY" | "HTTP" | "HTTPS" | "SOCKS" | "SOCKS4" | "SOCKS5"
|
2012-09-15 00:27:46 +04: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.
|
2015-03-26 10:11:05 +03:00
|
|
|
* @param aAppId
|
|
|
|
* The id of the app requesting connection.
|
|
|
|
* @param aAppOrigin
|
|
|
|
* The origin of the app requesting connection.
|
|
|
|
* @param aIsInBrowser
|
|
|
|
* True if the iframe has mozbrowser but has no mozapp attribute.
|
2012-09-15 00:27:46 +04:00
|
|
|
*
|
|
|
|
* @param result
|
|
|
|
* result string as defined above.
|
|
|
|
*/
|
|
|
|
nsresult GetProxyForURI(const nsCString &aTestURI,
|
|
|
|
const nsCString &aTestHost,
|
2015-03-26 10:11:05 +03:00
|
|
|
uint32_t aAppId,
|
|
|
|
const nsString &aAppOrigin,
|
|
|
|
bool aIsInBrowser,
|
2012-09-15 00:27:46 +04:00
|
|
|
nsACString &result);
|
|
|
|
|
|
|
|
private:
|
2014-09-18 19:53:30 +04:00
|
|
|
// allow 665ms for myipaddress dns queries. That's 95th percentile.
|
|
|
|
const static unsigned int kTimeout = 665;
|
2012-09-15 00:27:46 +04:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
// used to compile the PAC file and setup the execution context
|
|
|
|
nsresult SetupJS();
|
|
|
|
|
2012-12-24 01:08:43 +04:00
|
|
|
bool SrcAddress(const NetAddr *remoteAddress, nsCString &localAddress);
|
2012-09-15 00:27:46 +04:00
|
|
|
bool MyIPAddressTryHost(const nsCString &hostName, unsigned int timeout,
|
2014-03-26 21:38:29 +04:00
|
|
|
const JS::CallArgs &aArgs, bool* aResult);
|
2012-09-15 00:27:46 +04:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
JSRuntimeWrapper *mJSRuntime;
|
|
|
|
bool mJSNeedsSetup;
|
|
|
|
bool mShutdown;
|
|
|
|
nsCString mPACScript;
|
|
|
|
nsCString mPACURI;
|
2012-09-15 00:27:46 +04:00
|
|
|
nsCString mRunningHost;
|
2015-03-26 10:11:05 +03:00
|
|
|
uint32_t mRunningAppId;
|
|
|
|
nsString mRunningAppOrigin;
|
|
|
|
bool mRunningIsInBrowser;
|
2012-09-15 00:27:46 +04:00
|
|
|
nsCOMPtr<nsITimer> mTimer;
|
2012-09-15 00:27:46 +04:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|
2012-09-15 00:27:46 +04:00
|
|
|
|
|
|
|
#endif // ProxyAutoConfig_h__
|