Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / netwerk / dns / GetAddrInfo.h
blob21435e361d194f4016b6d4ab338e117c0f992549
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
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/. */
7 #ifndef netwerk_dns_GetAddrInfo_h
8 #define netwerk_dns_GetAddrInfo_h
10 #include "nsError.h"
11 #include "nscore.h"
12 #include "nsINativeDNSResolverOverride.h"
13 #include "nsHashKeys.h"
14 #include "nsTHashMap.h"
15 #include "mozilla/RWLock.h"
16 #include "nsTArray.h"
17 #include "prio.h"
18 #include "mozilla/net/DNS.h"
19 #include "nsIDNSByTypeRecord.h"
20 #include "mozilla/Logging.h"
21 #include "nsIDNSService.h"
23 #if defined(XP_WIN)
24 # define DNSQUERY_AVAILABLE 1
25 #else
26 # undef DNSQUERY_AVAILABLE
27 #endif
29 namespace mozilla {
30 namespace net {
32 extern LazyLogModule gGetAddrInfoLog;
33 class AddrInfo;
34 class DNSPacket;
36 /**
37 * Look up a host by name. Mostly equivalent to getaddrinfo(host, NULL, ...) of
38 * RFC 3493.
40 * @param aHost[in] Character string defining the host name of interest
41 * @param aAddressFamily[in] May be AF_INET, AF_INET6, or AF_UNSPEC.
42 * @param aFlags[in] See nsIDNSService::DNSFlags
43 * @param aAddrInfo[out] Will point to the results of the host lookup, or be
44 * null if the lookup failed.
45 * @param aGetTtl[in] If true, the TTL will be retrieved if DNS provides the
46 * answers..
48 nsresult GetAddrInfo(const nsACString& aHost, uint16_t aAddressFamily,
49 nsIDNSService::DNSFlags aFlags, AddrInfo** aAddrInfo,
50 bool aGetTtl);
52 /**
53 * Initialize the GetAddrInfo module.
55 * GetAddrInfoShutdown() should be called for every time this function is
56 * called.
58 nsresult GetAddrInfoInit();
60 /**
61 * Shutdown the GetAddrInfo module.
63 * This function should be called for every time GetAddrInfoInit() is called.
64 * An assertion may throw (but is not guarenteed) if this function is called
65 * too many times.
67 nsresult GetAddrInfoShutdown();
69 void DNSThreadShutdown();
71 /**
72 * Resolves a HTTPS record. Will check overrides before calling the
73 * native OS implementation.
75 nsresult ResolveHTTPSRecord(const nsACString& aHost,
76 nsIDNSService::DNSFlags aFlags,
77 TypeRecordResultType& aResult, uint32_t& aTTL);
79 /**
80 * The platform specific implementation of HTTPS resolution.
82 nsresult ResolveHTTPSRecordImpl(const nsACString& aHost,
83 nsIDNSService::DNSFlags aFlags,
84 TypeRecordResultType& aResult, uint32_t& aTTL);
86 nsresult ParseHTTPSRecord(nsCString& aHost, DNSPacket& aDNSPacket,
87 TypeRecordResultType& aResult, uint32_t& aTTL);
89 // Use the provided aHost to create a mock HTTPS record.
90 nsresult CreateAndResolveMockHTTPSRecord(const nsACString& aHost,
91 nsIDNSService::DNSFlags aFlags,
92 TypeRecordResultType& aResult,
93 uint32_t& aTTL);
95 class NativeDNSResolverOverride : public nsINativeDNSResolverOverride {
96 NS_DECL_THREADSAFE_ISUPPORTS
97 NS_DECL_NSINATIVEDNSRESOLVEROVERRIDE
98 public:
99 NativeDNSResolverOverride() = default;
101 static already_AddRefed<nsINativeDNSResolverOverride> GetSingleton();
103 private:
104 virtual ~NativeDNSResolverOverride() = default;
105 mozilla::RWLock mLock{"NativeDNSResolverOverride"};
107 nsTHashMap<nsCStringHashKey, nsTArray<NetAddr>> mOverrides
108 MOZ_GUARDED_BY(mLock);
109 nsTHashMap<nsCStringHashKey, nsCString> mCnames MOZ_GUARDED_BY(mLock);
110 nsTHashMap<nsCStringHashKey, nsTArray<uint8_t>> mHTTPSRecordOverrides
111 MOZ_GUARDED_BY(mLock);
113 friend bool FindAddrOverride(const nsACString& aHost, uint16_t aAddressFamily,
114 nsIDNSService::DNSFlags aFlags,
115 AddrInfo** aAddrInfo);
116 friend bool FindHTTPSRecordOverride(const nsACString& aHost,
117 TypeRecordResultType& aResult);
120 } // namespace net
121 } // namespace mozilla
123 #endif // netwerk_dns_GetAddrInfo_h