2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 22:01:16 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2000-02-14 10:04:56 +00:00
|
|
|
*
|
2004-04-18 22:01:16 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
2000-02-14 10:04:56 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
2000-02-14 10:04:56 +00:00
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 22:01:16 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-28 20:14:13 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2000-02-14 10:04:56 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Contributor(s):
|
2004-12-16 02:46:12 +00:00
|
|
|
* Malcolm Smith <malsmith@cs.rmit.edu.au>
|
2001-09-28 20:14:13 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 22:01:16 +00:00
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
2001-09-28 20:14:13 +00:00
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 22:01:16 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-28 20:14:13 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 22:01:16 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-28 20:14:13 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2001-07-25 00:28:28 +00:00
|
|
|
|
2003-04-11 18:24:55 +00:00
|
|
|
#ifndef nsProtocolProxyService_h__
|
|
|
|
#define nsProtocolProxyService_h__
|
2000-02-14 10:04:56 +00:00
|
|
|
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2004-07-01 23:31:47 +00:00
|
|
|
#include "nsAutoPtr.h"
|
2009-02-23 01:05:28 +00:00
|
|
|
#include "nsTArray.h"
|
2003-07-14 21:36:24 +00:00
|
|
|
#include "nsIPrefBranch.h"
|
2006-03-30 17:31:15 +00:00
|
|
|
#include "nsIProtocolProxyService2.h"
|
2005-03-25 03:41:33 +00:00
|
|
|
#include "nsIProtocolProxyFilter.h"
|
2001-04-17 02:34:47 +00:00
|
|
|
#include "nsIProxyAutoConfig.h"
|
2008-01-29 18:38:15 +00:00
|
|
|
#include "nsISystemProxySettings.h"
|
2001-09-13 02:21:05 +00:00
|
|
|
#include "nsIProxyInfo.h"
|
2003-07-14 21:36:24 +00:00
|
|
|
#include "nsIObserver.h"
|
2004-07-01 23:31:47 +00:00
|
|
|
#include "nsDataHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
2005-03-25 03:41:33 +00:00
|
|
|
#include "nsPACMan.h"
|
2004-07-01 23:31:47 +00:00
|
|
|
#include "prtime.h"
|
2001-09-13 02:21:05 +00:00
|
|
|
#include "prmem.h"
|
2003-04-11 18:24:55 +00:00
|
|
|
#include "prio.h"
|
2000-02-14 10:04:56 +00:00
|
|
|
|
2004-07-01 23:31:47 +00:00
|
|
|
typedef nsDataHashtable<nsCStringHashKey, PRUint32> nsFailedProxyTable;
|
|
|
|
|
|
|
|
class nsProxyInfo;
|
2005-07-06 17:42:06 +00:00
|
|
|
struct nsProtocolInfo;
|
2004-07-01 23:31:47 +00:00
|
|
|
|
2006-03-30 17:31:15 +00:00
|
|
|
class nsProtocolProxyService : public nsIProtocolProxyService2
|
2003-07-14 21:36:24 +00:00
|
|
|
, public nsIObserver
|
2002-09-23 01:31:17 +00:00
|
|
|
{
|
2000-02-14 10:04:56 +00:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
2006-03-30 17:31:15 +00:00
|
|
|
NS_DECL_NSIPROTOCOLPROXYSERVICE2
|
2000-02-14 10:04:56 +00:00
|
|
|
NS_DECL_NSIPROTOCOLPROXYSERVICE
|
2003-07-14 21:36:24 +00:00
|
|
|
NS_DECL_NSIOBSERVER
|
2000-02-14 10:04:56 +00:00
|
|
|
|
2004-07-01 23:31:47 +00:00
|
|
|
nsProtocolProxyService() NS_HIDDEN;
|
2000-02-23 21:17:17 +00:00
|
|
|
|
2004-07-01 23:31:47 +00:00
|
|
|
NS_HIDDEN_(nsresult) Init();
|
2000-02-14 10:04:56 +00:00
|
|
|
|
|
|
|
protected:
|
2005-04-01 23:31:04 +00:00
|
|
|
friend class nsAsyncResolveRequest;
|
2005-03-25 03:41:33 +00:00
|
|
|
|
|
|
|
~nsProtocolProxyService() NS_HIDDEN;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is called whenever a preference may have changed or
|
|
|
|
* to initialize all preferences.
|
|
|
|
*
|
|
|
|
* @param prefs
|
|
|
|
* This must be a pointer to the root pref branch.
|
|
|
|
* @param name
|
|
|
|
* This can be the name of a fully-qualified preference, or it can
|
|
|
|
* be null, in which case all preferences will be initialized.
|
|
|
|
*/
|
|
|
|
NS_HIDDEN_(void) PrefsChanged(nsIPrefBranch *prefs, const char *name);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is called to create a nsProxyInfo instance from the given
|
|
|
|
* PAC-style proxy string. It parses up to the end of the string, or to
|
|
|
|
* the next ';' character.
|
|
|
|
*
|
|
|
|
* @param proxy
|
|
|
|
* The PAC-style proxy string to parse. This must not be null.
|
|
|
|
* @param result
|
|
|
|
* Upon return this points to a newly allocated nsProxyInfo or null
|
|
|
|
* if the proxy string was invalid.
|
|
|
|
*
|
|
|
|
* @return A pointer beyond the parsed proxy string (never null).
|
|
|
|
*/
|
|
|
|
NS_HIDDEN_(const char *) ExtractProxyInfo(const char *proxy,
|
|
|
|
nsProxyInfo **result);
|
|
|
|
|
2006-03-30 17:31:15 +00:00
|
|
|
/**
|
|
|
|
* Load the specified PAC file.
|
|
|
|
*
|
|
|
|
* @param pacURI
|
|
|
|
* The URI spec of the PAC file to load.
|
|
|
|
*/
|
2008-05-08 09:05:11 +00:00
|
|
|
NS_HIDDEN_(nsresult) ConfigureFromPAC(const nsCString &pacURI, PRBool forceReload);
|
2006-03-30 17:31:15 +00:00
|
|
|
|
2005-03-25 03:41:33 +00:00
|
|
|
/**
|
|
|
|
* This method builds a list of nsProxyInfo objects from the given PAC-
|
|
|
|
* style string.
|
|
|
|
*
|
|
|
|
* @param pacString
|
|
|
|
* The PAC-style proxy string to parse. This may be empty.
|
|
|
|
* @param result
|
|
|
|
* The resulting list of proxy info objects.
|
|
|
|
*/
|
|
|
|
NS_HIDDEN_(void) ProcessPACString(const nsCString &pacString,
|
|
|
|
nsIProxyInfo **result);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method generates a string valued identifier for the given
|
|
|
|
* nsProxyInfo object.
|
|
|
|
*
|
|
|
|
* @param pi
|
|
|
|
* The nsProxyInfo object from which to generate the key.
|
|
|
|
* @param result
|
|
|
|
* Upon return, this parameter holds the generated key.
|
|
|
|
*/
|
|
|
|
NS_HIDDEN_(void) GetProxyKey(nsProxyInfo *pi, nsCString &result);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Seconds since start of session.
|
|
|
|
*/
|
|
|
|
NS_HIDDEN_(PRUint32) SecondsSinceSessionStart();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method removes the specified proxy from the disabled list.
|
|
|
|
*
|
|
|
|
* @param pi
|
|
|
|
* The nsProxyInfo object identifying the proxy to enable.
|
|
|
|
*/
|
|
|
|
NS_HIDDEN_(void) EnableProxy(nsProxyInfo *pi);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method adds the specified proxy to the disabled list.
|
|
|
|
*
|
|
|
|
* @param pi
|
|
|
|
* The nsProxyInfo object identifying the proxy to disable.
|
|
|
|
*/
|
|
|
|
NS_HIDDEN_(void) DisableProxy(nsProxyInfo *pi);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method tests to see if the given proxy is disabled.
|
|
|
|
*
|
|
|
|
* @param pi
|
|
|
|
* The nsProxyInfo object identifying the proxy to test.
|
|
|
|
*
|
|
|
|
* @return True if the specified proxy is disabled.
|
|
|
|
*/
|
|
|
|
NS_HIDDEN_(PRBool) IsProxyDisabled(nsProxyInfo *pi);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method queries the protocol handler for the given scheme to check
|
|
|
|
* for the protocol flags and default port.
|
|
|
|
*
|
|
|
|
* @param uri
|
|
|
|
* The URI to query.
|
|
|
|
* @param info
|
|
|
|
* Holds information about the protocol upon return. Pass address
|
|
|
|
* of structure when you call this method. This parameter must not
|
|
|
|
* be null.
|
|
|
|
*/
|
|
|
|
NS_HIDDEN_(nsresult) GetProtocolInfo(nsIURI *uri, nsProtocolInfo *result);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is an internal version nsIProtocolProxyService::newProxyInfo
|
|
|
|
* that expects a string literal for the type.
|
|
|
|
*
|
|
|
|
* @param type
|
|
|
|
* The proxy type.
|
|
|
|
* @param host
|
|
|
|
* The proxy host name (UTF-8 ok).
|
|
|
|
* @param port
|
|
|
|
* The proxy port number.
|
|
|
|
* @param flags
|
|
|
|
* The proxy flags (nsIProxyInfo::flags).
|
|
|
|
* @param timeout
|
|
|
|
* The failover timeout for this proxy.
|
|
|
|
* @param next
|
|
|
|
* The next proxy to try if this one fails.
|
|
|
|
* @param result
|
|
|
|
* The resulting nsIProxyInfo object.
|
|
|
|
*/
|
|
|
|
NS_HIDDEN_(nsresult) NewProxyInfo_Internal(const char *type,
|
|
|
|
const nsACString &host,
|
|
|
|
PRInt32 port,
|
|
|
|
PRUint32 flags,
|
|
|
|
PRUint32 timeout,
|
|
|
|
nsIProxyInfo *next,
|
|
|
|
nsIProxyInfo **result);
|
2000-04-22 00:35:05 +00:00
|
|
|
|
2005-03-25 03:41:33 +00:00
|
|
|
/**
|
|
|
|
* This method is an internal version of Resolve that does not query PAC.
|
|
|
|
* It performs all of the built-in processing, and reports back to the
|
|
|
|
* caller with either the proxy info result or a flag to instruct the
|
|
|
|
* caller to use PAC instead.
|
|
|
|
*
|
|
|
|
* @param uri
|
|
|
|
* The URI to test.
|
|
|
|
* @param info
|
|
|
|
* Information about the URI's protocol.
|
|
|
|
* @param usePAC
|
|
|
|
* If this flag is set upon return, then PAC should be queried to
|
|
|
|
* resolve the proxy info.
|
|
|
|
* @param result
|
|
|
|
* The resulting proxy info or null.
|
|
|
|
*/
|
|
|
|
NS_HIDDEN_(nsresult) Resolve_Internal(nsIURI *uri,
|
|
|
|
const nsProtocolInfo &info,
|
|
|
|
PRBool *usePAC,
|
|
|
|
nsIProxyInfo **result);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method applies the registered filters to the given proxy info
|
|
|
|
* list, and returns a possibly modified list.
|
|
|
|
*
|
|
|
|
* @param uri
|
|
|
|
* The URI corresponding to this proxy info list.
|
|
|
|
* @param info
|
|
|
|
* Information about the URI's protocol.
|
|
|
|
* @param proxyInfo
|
|
|
|
* The proxy info list to be modified. This is an inout param.
|
|
|
|
*/
|
|
|
|
NS_HIDDEN_(void) ApplyFilters(nsIURI *uri, const nsProtocolInfo &info,
|
|
|
|
nsIProxyInfo **proxyInfo);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is a simple wrapper around ApplyFilters that takes the
|
|
|
|
* proxy info list inout param as a nsCOMPtr.
|
|
|
|
*/
|
|
|
|
inline void ApplyFilters(nsIURI *uri, const nsProtocolInfo &info,
|
|
|
|
nsCOMPtr<nsIProxyInfo> &proxyInfo)
|
|
|
|
{
|
|
|
|
nsIProxyInfo *pi = nsnull;
|
|
|
|
proxyInfo.swap(pi);
|
|
|
|
ApplyFilters(uri, info, &pi);
|
|
|
|
proxyInfo.swap(pi);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method prunes out disabled and disallowed proxies from a given
|
|
|
|
* proxy info list.
|
|
|
|
*
|
|
|
|
* @param info
|
|
|
|
* Information about the URI's protocol.
|
|
|
|
* @param proxyInfo
|
|
|
|
* The proxy info list to be modified. This is an inout param.
|
|
|
|
*/
|
|
|
|
NS_HIDDEN_(void) PruneProxyInfo(const nsProtocolInfo &info,
|
|
|
|
nsIProxyInfo **proxyInfo);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method populates mHostFiltersArray from the given string.
|
|
|
|
*
|
|
|
|
* @param hostFilters
|
|
|
|
* A "no-proxy-for" exclusion list.
|
|
|
|
*/
|
|
|
|
NS_HIDDEN_(void) LoadHostFilters(const char *hostFilters);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method checks the given URI against mHostFiltersArray.
|
|
|
|
*
|
|
|
|
* @param uri
|
|
|
|
* The URI to test.
|
|
|
|
* @param defaultPort
|
|
|
|
* The default port for the given URI.
|
|
|
|
*
|
|
|
|
* @return True if the URI can use the specified proxy.
|
|
|
|
*/
|
|
|
|
NS_HIDDEN_(PRBool) CanUseProxy(nsIURI *uri, PRInt32 defaultPort);
|
2003-04-11 18:24:55 +00:00
|
|
|
|
2004-04-19 21:59:26 +00:00
|
|
|
public:
|
|
|
|
// The Sun Forte compiler and others implement older versions of the
|
|
|
|
// C++ standard's rules on access and nested classes. These structs
|
|
|
|
// need to be public in order to deal with those compilers.
|
|
|
|
|
2004-04-16 05:46:27 +00:00
|
|
|
struct HostInfoIP {
|
|
|
|
PRUint16 family;
|
|
|
|
PRUint16 mask_len;
|
|
|
|
PRIPv6Addr addr; // possibly IPv4-mapped address
|
|
|
|
};
|
|
|
|
|
|
|
|
struct HostInfoName {
|
|
|
|
char *host;
|
|
|
|
PRUint32 host_len;
|
|
|
|
};
|
|
|
|
|
2009-05-06 21:26:33 +00:00
|
|
|
// These values correspond to the integer network.proxy.type preference
|
2005-03-25 03:41:33 +00:00
|
|
|
enum ProxyConfig {
|
|
|
|
eProxyConfig_Direct,
|
|
|
|
eProxyConfig_Manual,
|
|
|
|
eProxyConfig_PAC,
|
|
|
|
eProxyConfig_Direct4x,
|
|
|
|
eProxyConfig_WPAD,
|
2008-01-29 18:38:15 +00:00
|
|
|
eProxyConfig_System, // use system proxy settings if available, otherwise DIRECT
|
2005-03-25 03:41:33 +00:00
|
|
|
eProxyConfig_Last
|
|
|
|
};
|
|
|
|
|
2009-05-06 21:26:33 +00:00
|
|
|
protected:
|
|
|
|
|
2000-04-22 00:35:05 +00:00
|
|
|
// simplified array of filters defined by this struct
|
2003-04-11 18:24:55 +00:00
|
|
|
struct HostInfo {
|
|
|
|
PRBool is_ipaddr;
|
|
|
|
PRInt32 port;
|
|
|
|
union {
|
2004-04-16 05:46:27 +00:00
|
|
|
HostInfoIP ip;
|
|
|
|
HostInfoName name;
|
2003-04-11 18:24:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
HostInfo()
|
|
|
|
: is_ipaddr(PR_FALSE)
|
|
|
|
{ /* other members intentionally uninitialized */ }
|
|
|
|
~HostInfo() {
|
|
|
|
if (!is_ipaddr && name.host)
|
|
|
|
nsMemory::Free(name.host);
|
|
|
|
}
|
2000-04-22 00:35:05 +00:00
|
|
|
};
|
|
|
|
|
2005-03-25 03:41:33 +00:00
|
|
|
// This structure is allocated for each registered nsIProtocolProxyFilter.
|
|
|
|
struct FilterLink {
|
|
|
|
struct FilterLink *next;
|
|
|
|
PRUint32 position;
|
|
|
|
nsCOMPtr<nsIProtocolProxyFilter> filter;
|
|
|
|
|
|
|
|
FilterLink(PRUint32 p, nsIProtocolProxyFilter *f)
|
|
|
|
: next(nsnull), position(p), filter(f) {}
|
|
|
|
|
|
|
|
// Chain deletion to simplify cleaning up the filter links
|
|
|
|
~FilterLink() { if (next) delete next; }
|
|
|
|
};
|
|
|
|
|
|
|
|
// Holds an array of HostInfo objects
|
2009-02-23 01:05:28 +00:00
|
|
|
nsTArray<nsAutoPtr<HostInfo> > mHostFiltersArray;
|
2005-03-25 03:41:33 +00:00
|
|
|
|
|
|
|
// Points to the start of a sorted by position, singly linked list
|
|
|
|
// of FilterLink objects.
|
|
|
|
FilterLink *mFilters;
|
|
|
|
|
|
|
|
ProxyConfig mProxyConfig;
|
2000-02-14 10:04:56 +00:00
|
|
|
|
2004-07-01 23:31:47 +00:00
|
|
|
nsCString mHTTPProxyHost;
|
|
|
|
PRInt32 mHTTPProxyPort;
|
2000-02-14 10:04:56 +00:00
|
|
|
|
2004-07-01 23:31:47 +00:00
|
|
|
nsCString mFTPProxyHost;
|
|
|
|
PRInt32 mFTPProxyPort;
|
2000-04-22 00:35:05 +00:00
|
|
|
|
2004-07-01 23:31:47 +00:00
|
|
|
nsCString mHTTPSProxyHost;
|
|
|
|
PRInt32 mHTTPSProxyPort;
|
2000-07-01 10:25:25 +00:00
|
|
|
|
2004-07-01 23:31:47 +00:00
|
|
|
nsCString mSOCKSProxyHost;
|
|
|
|
PRInt32 mSOCKSProxyPort;
|
|
|
|
PRInt32 mSOCKSProxyVersion;
|
2004-12-16 02:46:12 +00:00
|
|
|
PRBool mSOCKSProxyRemoteDNS;
|
2001-04-17 02:34:47 +00:00
|
|
|
|
2005-03-25 03:41:33 +00:00
|
|
|
nsRefPtr<nsPACMan> mPACMan; // non-null if we are using PAC
|
2008-01-29 18:38:15 +00:00
|
|
|
nsCOMPtr<nsISystemProxySettings> mSystemProxySettings;
|
2004-07-01 23:31:47 +00:00
|
|
|
|
|
|
|
PRTime mSessionStart;
|
|
|
|
nsFailedProxyTable mFailedProxies;
|
|
|
|
PRInt32 mFailedProxyTimeout;
|
2000-02-14 10:04:56 +00:00
|
|
|
};
|
|
|
|
|
2003-04-11 18:24:55 +00:00
|
|
|
#endif // !nsProtocolProxyService_h__
|