netwerk/base/src/nsProtocolProxyService.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef nsProtocolProxyService_h__
michael@0 7 #define nsProtocolProxyService_h__
michael@0 8
michael@0 9 #include "nsString.h"
michael@0 10 #include "nsCOMPtr.h"
michael@0 11 #include "nsAutoPtr.h"
michael@0 12 #include "nsTArray.h"
michael@0 13 #include "nsIProtocolProxyService2.h"
michael@0 14 #include "nsIProtocolProxyFilter.h"
michael@0 15 #include "nsIProxyInfo.h"
michael@0 16 #include "nsIObserver.h"
michael@0 17 #include "nsDataHashtable.h"
michael@0 18 #include "nsHashKeys.h"
michael@0 19 #include "prio.h"
michael@0 20 #include "mozilla/Attributes.h"
michael@0 21
michael@0 22 typedef nsDataHashtable<nsCStringHashKey, uint32_t> nsFailedProxyTable;
michael@0 23
michael@0 24 class nsProxyInfo;
michael@0 25 struct nsProtocolInfo;
michael@0 26 class nsIPrefBranch;
michael@0 27 class nsISystemProxySettings;
michael@0 28 class nsPACMan;
michael@0 29
michael@0 30 // CID for the nsProtocolProxyService class
michael@0 31 // 091eedd8-8bae-4fe3-ad62-0c87351e640d
michael@0 32 #define NS_PROTOCOL_PROXY_SERVICE_IMPL_CID \
michael@0 33 { 0x091eedd8, 0x8bae, 0x4fe3, \
michael@0 34 { 0xad, 0x62, 0x0c, 0x87, 0x35, 0x1e, 0x64, 0x0d } }
michael@0 35
michael@0 36 class nsProtocolProxyService MOZ_FINAL : public nsIProtocolProxyService2
michael@0 37 , public nsIObserver
michael@0 38 {
michael@0 39 public:
michael@0 40 NS_DECL_ISUPPORTS
michael@0 41 NS_DECL_NSIPROTOCOLPROXYSERVICE2
michael@0 42 NS_DECL_NSIPROTOCOLPROXYSERVICE
michael@0 43 NS_DECL_NSIOBSERVER
michael@0 44
michael@0 45 NS_DECLARE_STATIC_IID_ACCESSOR(NS_PROTOCOL_PROXY_SERVICE_IMPL_CID)
michael@0 46
michael@0 47 nsProtocolProxyService() NS_HIDDEN;
michael@0 48
michael@0 49 NS_HIDDEN_(nsresult) Init();
michael@0 50 nsresult DeprecatedBlockingResolve(nsIChannel *aChannel,
michael@0 51 uint32_t aFlags,
michael@0 52 nsIProxyInfo **retval);
michael@0 53
michael@0 54 protected:
michael@0 55 friend class nsAsyncResolveRequest;
michael@0 56
michael@0 57 ~nsProtocolProxyService() NS_HIDDEN;
michael@0 58
michael@0 59 /**
michael@0 60 * This method is called whenever a preference may have changed or
michael@0 61 * to initialize all preferences.
michael@0 62 *
michael@0 63 * @param prefs
michael@0 64 * This must be a pointer to the root pref branch.
michael@0 65 * @param name
michael@0 66 * This can be the name of a fully-qualified preference, or it can
michael@0 67 * be null, in which case all preferences will be initialized.
michael@0 68 */
michael@0 69 NS_HIDDEN_(void) PrefsChanged(nsIPrefBranch *prefs, const char *name);
michael@0 70
michael@0 71 /**
michael@0 72 * This method is called to create a nsProxyInfo instance from the given
michael@0 73 * PAC-style proxy string. It parses up to the end of the string, or to
michael@0 74 * the next ';' character.
michael@0 75 *
michael@0 76 * @param proxy
michael@0 77 * The PAC-style proxy string to parse. This must not be null.
michael@0 78 * @param aResolveFlags
michael@0 79 * The flags passed to Resolve or AsyncResolve that are stored in
michael@0 80 * proxyInfo.
michael@0 81 * @param result
michael@0 82 * Upon return this points to a newly allocated nsProxyInfo or null
michael@0 83 * if the proxy string was invalid.
michael@0 84 *
michael@0 85 * @return A pointer beyond the parsed proxy string (never null).
michael@0 86 */
michael@0 87 NS_HIDDEN_(const char *) ExtractProxyInfo(const char *proxy,
michael@0 88 uint32_t aResolveFlags,
michael@0 89 nsProxyInfo **result);
michael@0 90
michael@0 91 /**
michael@0 92 * Load the specified PAC file.
michael@0 93 *
michael@0 94 * @param pacURI
michael@0 95 * The URI spec of the PAC file to load.
michael@0 96 */
michael@0 97 NS_HIDDEN_(nsresult) ConfigureFromPAC(const nsCString &pacURI, bool forceReload);
michael@0 98
michael@0 99 /**
michael@0 100 * This method builds a list of nsProxyInfo objects from the given PAC-
michael@0 101 * style string.
michael@0 102 *
michael@0 103 * @param pacString
michael@0 104 * The PAC-style proxy string to parse. This may be empty.
michael@0 105 * @param aResolveFlags
michael@0 106 * The flags passed to Resolve or AsyncResolve that are stored in
michael@0 107 * proxyInfo.
michael@0 108 * @param result
michael@0 109 * The resulting list of proxy info objects.
michael@0 110 */
michael@0 111 NS_HIDDEN_(void) ProcessPACString(const nsCString &pacString,
michael@0 112 uint32_t aResolveFlags,
michael@0 113 nsIProxyInfo **result);
michael@0 114
michael@0 115 /**
michael@0 116 * This method generates a string valued identifier for the given
michael@0 117 * nsProxyInfo object.
michael@0 118 *
michael@0 119 * @param pi
michael@0 120 * The nsProxyInfo object from which to generate the key.
michael@0 121 * @param result
michael@0 122 * Upon return, this parameter holds the generated key.
michael@0 123 */
michael@0 124 NS_HIDDEN_(void) GetProxyKey(nsProxyInfo *pi, nsCString &result);
michael@0 125
michael@0 126 /**
michael@0 127 * @return Seconds since start of session.
michael@0 128 */
michael@0 129 NS_HIDDEN_(uint32_t) SecondsSinceSessionStart();
michael@0 130
michael@0 131 /**
michael@0 132 * This method removes the specified proxy from the disabled list.
michael@0 133 *
michael@0 134 * @param pi
michael@0 135 * The nsProxyInfo object identifying the proxy to enable.
michael@0 136 */
michael@0 137 NS_HIDDEN_(void) EnableProxy(nsProxyInfo *pi);
michael@0 138
michael@0 139 /**
michael@0 140 * This method adds the specified proxy to the disabled list.
michael@0 141 *
michael@0 142 * @param pi
michael@0 143 * The nsProxyInfo object identifying the proxy to disable.
michael@0 144 */
michael@0 145 NS_HIDDEN_(void) DisableProxy(nsProxyInfo *pi);
michael@0 146
michael@0 147 /**
michael@0 148 * This method tests to see if the given proxy is disabled.
michael@0 149 *
michael@0 150 * @param pi
michael@0 151 * The nsProxyInfo object identifying the proxy to test.
michael@0 152 *
michael@0 153 * @return True if the specified proxy is disabled.
michael@0 154 */
michael@0 155 NS_HIDDEN_(bool) IsProxyDisabled(nsProxyInfo *pi);
michael@0 156
michael@0 157 /**
michael@0 158 * This method queries the protocol handler for the given scheme to check
michael@0 159 * for the protocol flags and default port.
michael@0 160 *
michael@0 161 * @param uri
michael@0 162 * The URI to query.
michael@0 163 * @param info
michael@0 164 * Holds information about the protocol upon return. Pass address
michael@0 165 * of structure when you call this method. This parameter must not
michael@0 166 * be null.
michael@0 167 */
michael@0 168 NS_HIDDEN_(nsresult) GetProtocolInfo(nsIURI *uri, nsProtocolInfo *result);
michael@0 169
michael@0 170 /**
michael@0 171 * This method is an internal version nsIProtocolProxyService::newProxyInfo
michael@0 172 * that expects a string literal for the type.
michael@0 173 *
michael@0 174 * @param type
michael@0 175 * The proxy type.
michael@0 176 * @param host
michael@0 177 * The proxy host name (UTF-8 ok).
michael@0 178 * @param port
michael@0 179 * The proxy port number.
michael@0 180 * @param username
michael@0 181 * The username for the proxy (ASCII). May be "", but not null.
michael@0 182 * @param password
michael@0 183 * The password for the proxy (ASCII). May be "", but not null.
michael@0 184 * @param flags
michael@0 185 * The proxy flags (nsIProxyInfo::flags).
michael@0 186 * @param timeout
michael@0 187 * The failover timeout for this proxy.
michael@0 188 * @param next
michael@0 189 * The next proxy to try if this one fails.
michael@0 190 * @param aResolveFlags
michael@0 191 * The flags passed to resolve (from nsIProtocolProxyService).
michael@0 192 * @param result
michael@0 193 * The resulting nsIProxyInfo object.
michael@0 194 */
michael@0 195 NS_HIDDEN_(nsresult) NewProxyInfo_Internal(const char *type,
michael@0 196 const nsACString &host,
michael@0 197 int32_t port,
michael@0 198 const nsACString &username,
michael@0 199 const nsACString &password,
michael@0 200 uint32_t flags,
michael@0 201 uint32_t timeout,
michael@0 202 nsIProxyInfo *next,
michael@0 203 uint32_t aResolveFlags,
michael@0 204 nsIProxyInfo **result);
michael@0 205
michael@0 206 /**
michael@0 207 * This method is an internal version of Resolve that does not query PAC.
michael@0 208 * It performs all of the built-in processing, and reports back to the
michael@0 209 * caller with either the proxy info result or a flag to instruct the
michael@0 210 * caller to use PAC instead.
michael@0 211 *
michael@0 212 * @param channel
michael@0 213 * The channel to test.
michael@0 214 * @param info
michael@0 215 * Information about the URI's protocol.
michael@0 216 * @param flags
michael@0 217 * The flags passed to either the resolve or the asyncResolve method.
michael@0 218 * @param usePAC
michael@0 219 * If this flag is set upon return, then PAC should be queried to
michael@0 220 * resolve the proxy info.
michael@0 221 * @param result
michael@0 222 * The resulting proxy info or null.
michael@0 223 */
michael@0 224 NS_HIDDEN_(nsresult) Resolve_Internal(nsIChannel *channel,
michael@0 225 const nsProtocolInfo &info,
michael@0 226 uint32_t flags,
michael@0 227 bool *usePAC,
michael@0 228 nsIProxyInfo **result);
michael@0 229
michael@0 230 /**
michael@0 231 * This method applies the registered filters to the given proxy info
michael@0 232 * list, and returns a possibly modified list.
michael@0 233 *
michael@0 234 * @param channel
michael@0 235 * The channel corresponding to this proxy info list.
michael@0 236 * @param info
michael@0 237 * Information about the URI's protocol.
michael@0 238 * @param proxyInfo
michael@0 239 * The proxy info list to be modified. This is an inout param.
michael@0 240 */
michael@0 241 NS_HIDDEN_(void) ApplyFilters(nsIChannel *channel, const nsProtocolInfo &info,
michael@0 242 nsIProxyInfo **proxyInfo);
michael@0 243
michael@0 244 /**
michael@0 245 * This method is a simple wrapper around ApplyFilters that takes the
michael@0 246 * proxy info list inout param as a nsCOMPtr.
michael@0 247 */
michael@0 248 inline void ApplyFilters(nsIChannel *channel, const nsProtocolInfo &info,
michael@0 249 nsCOMPtr<nsIProxyInfo> &proxyInfo)
michael@0 250 {
michael@0 251 nsIProxyInfo *pi = nullptr;
michael@0 252 proxyInfo.swap(pi);
michael@0 253 ApplyFilters(channel, info, &pi);
michael@0 254 proxyInfo.swap(pi);
michael@0 255 }
michael@0 256
michael@0 257 /**
michael@0 258 * This method prunes out disabled and disallowed proxies from a given
michael@0 259 * proxy info list.
michael@0 260 *
michael@0 261 * @param info
michael@0 262 * Information about the URI's protocol.
michael@0 263 * @param proxyInfo
michael@0 264 * The proxy info list to be modified. This is an inout param.
michael@0 265 */
michael@0 266 NS_HIDDEN_(void) PruneProxyInfo(const nsProtocolInfo &info,
michael@0 267 nsIProxyInfo **proxyInfo);
michael@0 268
michael@0 269 /**
michael@0 270 * This method populates mHostFiltersArray from the given string.
michael@0 271 *
michael@0 272 * @param hostFilters
michael@0 273 * A "no-proxy-for" exclusion list.
michael@0 274 */
michael@0 275 NS_HIDDEN_(void) LoadHostFilters(const char *hostFilters);
michael@0 276
michael@0 277 /**
michael@0 278 * This method checks the given URI against mHostFiltersArray.
michael@0 279 *
michael@0 280 * @param uri
michael@0 281 * The URI to test.
michael@0 282 * @param defaultPort
michael@0 283 * The default port for the given URI.
michael@0 284 *
michael@0 285 * @return True if the URI can use the specified proxy.
michael@0 286 */
michael@0 287 NS_HIDDEN_(bool) CanUseProxy(nsIURI *uri, int32_t defaultPort);
michael@0 288
michael@0 289 /**
michael@0 290 * Disable Prefetch in the DNS service if a proxy is in use.
michael@0 291 *
michael@0 292 * @param aProxy
michael@0 293 * The proxy information
michael@0 294 */
michael@0 295 NS_HIDDEN_(void) MaybeDisableDNSPrefetch(nsIProxyInfo *aProxy);
michael@0 296
michael@0 297 private:
michael@0 298 nsresult SetupPACThread();
michael@0 299 nsresult ResetPACThread();
michael@0 300
michael@0 301 public:
michael@0 302 // The Sun Forte compiler and others implement older versions of the
michael@0 303 // C++ standard's rules on access and nested classes. These structs
michael@0 304 // need to be public in order to deal with those compilers.
michael@0 305
michael@0 306 struct HostInfoIP {
michael@0 307 uint16_t family;
michael@0 308 uint16_t mask_len;
michael@0 309 PRIPv6Addr addr; // possibly IPv4-mapped address
michael@0 310 };
michael@0 311
michael@0 312 struct HostInfoName {
michael@0 313 char *host;
michael@0 314 uint32_t host_len;
michael@0 315 };
michael@0 316
michael@0 317 protected:
michael@0 318
michael@0 319 // simplified array of filters defined by this struct
michael@0 320 struct HostInfo {
michael@0 321 bool is_ipaddr;
michael@0 322 int32_t port;
michael@0 323 union {
michael@0 324 HostInfoIP ip;
michael@0 325 HostInfoName name;
michael@0 326 };
michael@0 327
michael@0 328 HostInfo()
michael@0 329 : is_ipaddr(false)
michael@0 330 { /* other members intentionally uninitialized */ }
michael@0 331 ~HostInfo() {
michael@0 332 if (!is_ipaddr && name.host)
michael@0 333 nsMemory::Free(name.host);
michael@0 334 }
michael@0 335 };
michael@0 336
michael@0 337 // An instance of this struct is allocated for each registered
michael@0 338 // nsIProtocolProxyFilter and each nsIProtocolProxyChannelFilter.
michael@0 339 struct FilterLink {
michael@0 340 struct FilterLink *next;
michael@0 341 uint32_t position;
michael@0 342 nsCOMPtr<nsIProtocolProxyFilter> filter;
michael@0 343 nsCOMPtr<nsIProtocolProxyChannelFilter> channelFilter;
michael@0 344 FilterLink(uint32_t p, nsIProtocolProxyFilter *f)
michael@0 345 : next(nullptr), position(p), filter(f), channelFilter(nullptr) {}
michael@0 346 FilterLink(uint32_t p, nsIProtocolProxyChannelFilter *cf)
michael@0 347 : next(nullptr), position(p), filter(nullptr), channelFilter(cf) {}
michael@0 348 // Chain deletion to simplify cleaning up the filter links
michael@0 349 ~FilterLink() { if (next) delete next; }
michael@0 350 };
michael@0 351
michael@0 352 private:
michael@0 353 // Private methods to insert and remove FilterLinks from the FilterLink chain.
michael@0 354 nsresult InsertFilterLink(FilterLink *link, uint32_t position);
michael@0 355 nsresult RemoveFilterLink(nsISupports *givenObject);
michael@0 356
michael@0 357 protected:
michael@0 358 // Indicates if local hosts (plain hostnames, no dots) should use the proxy
michael@0 359 bool mFilterLocalHosts;
michael@0 360
michael@0 361 // Holds an array of HostInfo objects
michael@0 362 nsTArray<nsAutoPtr<HostInfo> > mHostFiltersArray;
michael@0 363
michael@0 364 // Points to the start of a sorted by position, singly linked list
michael@0 365 // of FilterLink objects.
michael@0 366 FilterLink *mFilters;
michael@0 367
michael@0 368 uint32_t mProxyConfig;
michael@0 369
michael@0 370 nsCString mHTTPProxyHost;
michael@0 371 int32_t mHTTPProxyPort;
michael@0 372
michael@0 373 nsCString mFTPProxyHost;
michael@0 374 int32_t mFTPProxyPort;
michael@0 375
michael@0 376 nsCString mHTTPSProxyHost;
michael@0 377 int32_t mHTTPSProxyPort;
michael@0 378
michael@0 379 nsCString mSOCKSProxyHost;
michael@0 380 int32_t mSOCKSProxyPort;
michael@0 381 int32_t mSOCKSProxyVersion;
michael@0 382 bool mSOCKSProxyRemoteDNS;
michael@0 383 nsCString mSOCKSProxyUsername;
michael@0 384 nsCString mSOCKSProxyPassword;
michael@0 385
michael@0 386 nsRefPtr<nsPACMan> mPACMan; // non-null if we are using PAC
michael@0 387 nsCOMPtr<nsISystemProxySettings> mSystemProxySettings;
michael@0 388
michael@0 389 PRTime mSessionStart;
michael@0 390 nsFailedProxyTable mFailedProxies;
michael@0 391 int32_t mFailedProxyTimeout;
michael@0 392
michael@0 393 private:
michael@0 394 nsresult AsyncResolveInternal(nsIChannel *channel, uint32_t flags,
michael@0 395 nsIProtocolProxyCallback *callback,
michael@0 396 nsICancelable **result,
michael@0 397 bool isSyncOK);
michael@0 398
michael@0 399 };
michael@0 400
michael@0 401 NS_DEFINE_STATIC_IID_ACCESSOR(nsProtocolProxyService, NS_PROTOCOL_PROXY_SERVICE_IMPL_CID)
michael@0 402
michael@0 403 #endif // !nsProtocolProxyService_h__

mercurial