1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
23 * Malcolm Smith <malsmith@cs.rmit.edu.au>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef nsProtocolProxyService_h__
40 #define nsProtocolProxyService_h__
44 #include "nsAutoPtr.h"
45 #include "nsVoidArray.h"
46 #include "nsIPrefBranch.h"
47 #include "nsIProtocolProxyService2.h"
48 #include "nsIProtocolProxyFilter.h"
49 #include "nsIProxyAutoConfig.h"
50 #include "nsISystemProxySettings.h"
51 #include "nsIProxyInfo.h"
52 #include "nsIObserver.h"
53 #include "nsDataHashtable.h"
54 #include "nsHashKeys.h"
60 typedef nsDataHashtable
<nsCStringHashKey
, PRUint32
> nsFailedProxyTable
;
63 struct nsProtocolInfo
;
65 class nsProtocolProxyService
: public nsIProtocolProxyService2
70 NS_DECL_NSIPROTOCOLPROXYSERVICE2
71 NS_DECL_NSIPROTOCOLPROXYSERVICE
74 nsProtocolProxyService() NS_HIDDEN
;
76 NS_HIDDEN_(nsresult
) Init();
79 friend class nsAsyncResolveRequest
;
81 ~nsProtocolProxyService() NS_HIDDEN
;
84 * This method is called whenever a preference may have changed or
85 * to initialize all preferences.
88 * This must be a pointer to the root pref branch.
90 * This can be the name of a fully-qualified preference, or it can
91 * be null, in which case all preferences will be initialized.
93 NS_HIDDEN_(void) PrefsChanged(nsIPrefBranch
*prefs
, const char *name
);
96 * This method is called to create a nsProxyInfo instance from the given
97 * PAC-style proxy string. It parses up to the end of the string, or to
98 * the next ';' character.
101 * The PAC-style proxy string to parse. This must not be null.
103 * Upon return this points to a newly allocated nsProxyInfo or null
104 * if the proxy string was invalid.
106 * @return A pointer beyond the parsed proxy string (never null).
108 NS_HIDDEN_(const char *) ExtractProxyInfo(const char *proxy
,
109 nsProxyInfo
**result
);
112 * Load the specified PAC file.
115 * The URI spec of the PAC file to load.
117 NS_HIDDEN_(nsresult
) ConfigureFromPAC(const nsCString
&pacURI
, PRBool forceReload
);
120 * This method builds a list of nsProxyInfo objects from the given PAC-
124 * The PAC-style proxy string to parse. This may be empty.
126 * The resulting list of proxy info objects.
128 NS_HIDDEN_(void) ProcessPACString(const nsCString
&pacString
,
129 nsIProxyInfo
**result
);
132 * This method generates a string valued identifier for the given
133 * nsProxyInfo object.
136 * The nsProxyInfo object from which to generate the key.
138 * Upon return, this parameter holds the generated key.
140 NS_HIDDEN_(void) GetProxyKey(nsProxyInfo
*pi
, nsCString
&result
);
143 * @return Seconds since start of session.
145 NS_HIDDEN_(PRUint32
) SecondsSinceSessionStart();
148 * This method removes the specified proxy from the disabled list.
151 * The nsProxyInfo object identifying the proxy to enable.
153 NS_HIDDEN_(void) EnableProxy(nsProxyInfo
*pi
);
156 * This method adds the specified proxy to the disabled list.
159 * The nsProxyInfo object identifying the proxy to disable.
161 NS_HIDDEN_(void) DisableProxy(nsProxyInfo
*pi
);
164 * This method tests to see if the given proxy is disabled.
167 * The nsProxyInfo object identifying the proxy to test.
169 * @return True if the specified proxy is disabled.
171 NS_HIDDEN_(PRBool
) IsProxyDisabled(nsProxyInfo
*pi
);
174 * This method queries the protocol handler for the given scheme to check
175 * for the protocol flags and default port.
180 * Holds information about the protocol upon return. Pass address
181 * of structure when you call this method. This parameter must not
184 NS_HIDDEN_(nsresult
) GetProtocolInfo(nsIURI
*uri
, nsProtocolInfo
*result
);
187 * This method is an internal version nsIProtocolProxyService::newProxyInfo
188 * that expects a string literal for the type.
193 * The proxy host name (UTF-8 ok).
195 * The proxy port number.
197 * The proxy flags (nsIProxyInfo::flags).
199 * The failover timeout for this proxy.
201 * The next proxy to try if this one fails.
203 * The resulting nsIProxyInfo object.
205 NS_HIDDEN_(nsresult
) NewProxyInfo_Internal(const char *type
,
206 const nsACString
&host
,
211 nsIProxyInfo
**result
);
214 * This method is an internal version of Resolve that does not query PAC.
215 * It performs all of the built-in processing, and reports back to the
216 * caller with either the proxy info result or a flag to instruct the
217 * caller to use PAC instead.
222 * Information about the URI's protocol.
224 * If this flag is set upon return, then PAC should be queried to
225 * resolve the proxy info.
227 * The resulting proxy info or null.
229 NS_HIDDEN_(nsresult
) Resolve_Internal(nsIURI
*uri
,
230 const nsProtocolInfo
&info
,
232 nsIProxyInfo
**result
);
235 * This method applies the registered filters to the given proxy info
236 * list, and returns a possibly modified list.
239 * The URI corresponding to this proxy info list.
241 * Information about the URI's protocol.
243 * The proxy info list to be modified. This is an inout param.
245 NS_HIDDEN_(void) ApplyFilters(nsIURI
*uri
, const nsProtocolInfo
&info
,
246 nsIProxyInfo
**proxyInfo
);
249 * This method is a simple wrapper around ApplyFilters that takes the
250 * proxy info list inout param as a nsCOMPtr.
252 inline void ApplyFilters(nsIURI
*uri
, const nsProtocolInfo
&info
,
253 nsCOMPtr
<nsIProxyInfo
> &proxyInfo
)
255 nsIProxyInfo
*pi
= nsnull
;
257 ApplyFilters(uri
, info
, &pi
);
262 * This method prunes out disabled and disallowed proxies from a given
266 * Information about the URI's protocol.
268 * The proxy info list to be modified. This is an inout param.
270 NS_HIDDEN_(void) PruneProxyInfo(const nsProtocolInfo
&info
,
271 nsIProxyInfo
**proxyInfo
);
274 * This method populates mHostFiltersArray from the given string.
277 * A "no-proxy-for" exclusion list.
279 NS_HIDDEN_(void) LoadHostFilters(const char *hostFilters
);
282 * This method checks the given URI against mHostFiltersArray.
287 * The default port for the given URI.
289 * @return True if the URI can use the specified proxy.
291 NS_HIDDEN_(PRBool
) CanUseProxy(nsIURI
*uri
, PRInt32 defaultPort
);
293 static PRBool
CleanupFilterArray(void *aElement
, void *aData
);
296 // The Sun Forte compiler and others implement older versions of the
297 // C++ standard's rules on access and nested classes. These structs
298 // need to be public in order to deal with those compilers.
303 PRIPv6Addr addr
; // possibly IPv4-mapped address
306 struct HostInfoName
{
317 eProxyConfig_Direct4x
,
319 eProxyConfig_System
, // use system proxy settings if available, otherwise DIRECT
323 // simplified array of filters defined by this struct
333 : is_ipaddr(PR_FALSE
)
334 { /* other members intentionally uninitialized */ }
336 if (!is_ipaddr
&& name
.host
)
337 nsMemory::Free(name
.host
);
341 // This structure is allocated for each registered nsIProtocolProxyFilter.
343 struct FilterLink
*next
;
345 nsCOMPtr
<nsIProtocolProxyFilter
> filter
;
347 FilterLink(PRUint32 p
, nsIProtocolProxyFilter
*f
)
348 : next(nsnull
), position(p
), filter(f
) {}
350 // Chain deletion to simplify cleaning up the filter links
351 ~FilterLink() { if (next
) delete next
; }
354 // Holds an array of HostInfo objects
355 nsVoidArray mHostFiltersArray
;
357 // Points to the start of a sorted by position, singly linked list
358 // of FilterLink objects.
359 FilterLink
*mFilters
;
361 ProxyConfig mProxyConfig
;
363 nsCString mHTTPProxyHost
;
364 PRInt32 mHTTPProxyPort
;
366 nsCString mFTPProxyHost
;
367 PRInt32 mFTPProxyPort
;
369 nsCString mGopherProxyHost
;
370 PRInt32 mGopherProxyPort
;
372 nsCString mHTTPSProxyHost
;
373 PRInt32 mHTTPSProxyPort
;
375 nsCString mSOCKSProxyHost
;
376 PRInt32 mSOCKSProxyPort
;
377 PRInt32 mSOCKSProxyVersion
;
378 PRBool mSOCKSProxyRemoteDNS
;
380 nsRefPtr
<nsPACMan
> mPACMan
; // non-null if we are using PAC
381 nsCOMPtr
<nsISystemProxySettings
> mSystemProxySettings
;
383 PRTime mSessionStart
;
384 nsFailedProxyTable mFailedProxies
;
385 PRInt32 mFailedProxyTimeout
;
388 #endif // !nsProtocolProxyService_h__