tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsProxyInfo.h (3423B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef nsProxyInfo_h__
      8 #define nsProxyInfo_h__
      9 
     10 #include "nsIProxyInfo.h"
     11 #include "nsString.h"
     12 #include "mozilla/Atomics.h"
     13 
     14 // Use to support QI nsIProxyInfo to nsProxyInfo
     15 #define NS_PROXYINFO_IID                      \
     16  {/* ed42f751-825e-4cc2-abeb-3670711a8b85 */ \
     17   0xed42f751,                                \
     18   0x825e,                                    \
     19   0x4cc2,                                    \
     20   {0xab, 0xeb, 0x36, 0x70, 0x71, 0x1a, 0x8b, 0x85}}
     21 
     22 namespace mozilla {
     23 namespace net {
     24 
     25 class ProxyInfoCloneArgs;
     26 
     27 // This class is exposed to other classes inside Necko for fast access
     28 // to the nsIProxyInfo attributes.
     29 class nsProxyInfo final : public nsIProxyInfo {
     30 public:
     31  NS_INLINE_DECL_STATIC_IID(NS_PROXYINFO_IID)
     32 
     33  NS_DECL_THREADSAFE_ISUPPORTS
     34  NS_DECL_NSIPROXYINFO
     35 
     36  // Cheap accessors for use within Necko
     37  const nsCString& Host() const { return mHost; }
     38  int32_t Port() const { return mPort; }
     39  const nsCString& MasqueTemplate() const { return mMasqueTemplate; }
     40  const char* Type() const { return mType; }
     41  uint32_t Flags() const { return mFlags; }
     42  const nsCString& Username() const { return mUsername; }
     43  const nsCString& Password() const { return mPassword; }
     44  uint32_t Timeout() { return mTimeout; }
     45  uint32_t ResolveFlags() { return mResolveFlags; }
     46  const nsCString& ProxyAuthorizationHeader() const {
     47    return mProxyAuthorizationHeader;
     48  }
     49  const nsCString& ConnectionIsolationKey() const {
     50    return mConnectionIsolationKey;
     51  }
     52 
     53  bool IsDirect();
     54  bool IsHTTP();
     55  bool IsHTTPS();
     56  bool IsSOCKS();
     57  bool IsHttp3Proxy();
     58 
     59  static void SerializeProxyInfo(nsProxyInfo* aProxyInfo,
     60                                 nsTArray<ProxyInfoCloneArgs>& aResult);
     61  static nsProxyInfo* DeserializeProxyInfo(
     62      const nsTArray<ProxyInfoCloneArgs>& aArgs);
     63 
     64  already_AddRefed<nsProxyInfo> CloneProxyInfoWithNewResolveFlags(
     65      uint32_t aResolveFlags);
     66 
     67  already_AddRefed<nsProxyInfo> CreateFallbackProxyInfo();
     68 
     69 private:
     70  friend class nsProtocolProxyService;
     71 
     72  explicit nsProxyInfo(const char* type = nullptr) : mType(type) {}
     73 
     74  nsProxyInfo(const nsACString& aType, const nsACString& aHost, int32_t aPort,
     75              const nsACString& aUsername, const nsACString& aPassword,
     76              uint32_t aFlags, uint32_t aTimeout, uint32_t aResolveFlags,
     77              const nsACString& aProxyAuthorizationHeader,
     78              const nsACString& aConnectionIsolationKey,
     79              const nsACString& aUriTemplate);
     80 
     81  ~nsProxyInfo() { NS_IF_RELEASE(mNext); }
     82 
     83  const char* mType;  // pointer to statically allocated value
     84  nsCString mHost;
     85  nsCString mUsername;
     86  nsCString mPassword;
     87  nsCString mProxyAuthorizationHeader;
     88  nsCString mConnectionIsolationKey;
     89  nsCString mSourceId;
     90  nsCString mMasqueTemplate;
     91  int32_t mPort{-1};
     92  uint32_t mFlags{0};
     93  // We need to read on multiple threads, but don't need to sync on anything
     94  // else
     95  Atomic<uint32_t, Relaxed> mResolveFlags{0};
     96  uint32_t mTimeout{UINT32_MAX};
     97  nsProxyInfo* mNext{nullptr};
     98 };
     99 
    100 }  // namespace net
    101 }  // namespace mozilla
    102 
    103 #endif  // nsProxyInfo_h__