fune/netwerk/base/ProxyAutoConfig.h
Valentin Gosu 1a1f42da37 Bug 1714307 - Run modernize-use-default-member-init --fix check on netwerk r=necko-reviewers,kershaw
This changeset is the result of adding modernize-use-default-member-init to
tools/clang-tidy/config.yaml then proceeding to run
`./mach static-analysis check netwerk/ --fix`
I then went through the resulting fix and manually updated all of the member
variables which were missed due to them having a non-trivial constructor.

Note that the tool was only run on Linux, so code that only runs on some
platforms may have been missed.

The member variables that are still initialized in the contructor definition
are:
  - bitfields (not all currently supported compilers allow default-member-init
  - variables that are initialized via a parameter
  - variables that use code not visible in the header file

There are a few advantages to landing this change:
- fewer lines of code - now declaration is in the same place as initialization
  this also makes it easier to see when looking at the header.
- it makes it harder to miss initializing a member when adding a new contructor
- variables that depend on an include guard look much nicer now

Additionally I removed some unnecessary reinitialization of NetAddr members
(it has a constructor that does that now), and changed nsWifiScannerDBus to
use the thread-safe strtok_r instead of strtok.

Differential Revision: https://phabricator.services.mozilla.com/D116980
2021-06-11 07:10:41 +00:00

107 lines
3.4 KiB
C++

/* -*- 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"
#include "nsCOMPtr.h"
class nsIEventTarget;
class nsITimer;
namespace JS {
class CallArgs;
} // namespace JS
namespace mozilla {
namespace net {
class JSContextWrapper;
union NetAddr;
// 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:
ProxyAutoConfig();
~ProxyAutoConfig();
nsresult Init(const nsCString& aPACURI, const nsCString& aPACScriptData,
bool aIncludePath, uint32_t aExtraHeapSize,
nsIEventTarget* aEventTarget);
void SetThreadLocalIndex(uint32_t index);
void Shutdown();
void GC();
bool MyIPAddress(const JS::CallArgs& aArgs);
bool ResolveAddress(const nsCString& aHostName, NetAddr* aNetAddr,
unsigned int aTimeout);
/**
* 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"
* proxy-type = "PROXY" | "HTTP" | "HTTPS" | "SOCKS" | "SOCKS4" | "SOCKS5"
* 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:
// allow 665ms for myipaddress dns queries. That's 95th percentile.
const static unsigned int kTimeout = 665;
// used to compile the PAC file and setup the execution context
nsresult SetupJS();
bool SrcAddress(const NetAddr* remoteAddress, nsCString& localAddress);
bool MyIPAddressTryHost(const nsCString& hostName, unsigned int timeout,
const JS::CallArgs& aArgs, bool* aResult);
JSContextWrapper* mJSContext{nullptr};
bool mJSNeedsSetup{false};
bool mShutdown{true};
nsCString mConcatenatedPACData;
nsCString mPACURI;
bool mIncludePath{false};
uint32_t mExtraHeapSize{0};
nsCString mRunningHost;
nsCOMPtr<nsITimer> mTimer;
nsCOMPtr<nsIEventTarget> mMainThreadEventTarget;
};
} // namespace net
} // namespace mozilla
#endif // ProxyAutoConfig_h__