Bug 1866777 - Disable test_race_cache_with_network.js on windows opt for frequent...
[gecko.git] / netwerk / dns / GetAddrInfo.h
blobe8dc09541574cb773c0530abb2f46bda6f5c90c8
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"
22 #if defined(XP_WIN)
23 # define DNSQUERY_AVAILABLE 1
24 #else
25 # undef DNSQUERY_AVAILABLE
26 #endif
28 namespace mozilla {
29 namespace net {
31 extern LazyLogModule gGetAddrInfoLog;
32 class AddrInfo;
33 class DNSPacket;
35 /**
36 * Look up a host by name. Mostly equivalent to getaddrinfo(host, NULL, ...) of
37 * RFC 3493.
39 * @param aHost[in] Character string defining the host name of interest
40 * @param aAddressFamily[in] May be AF_INET, AF_INET6, or AF_UNSPEC.
41 * @param aFlags[in] May be either PR_AI_ADDRCONFIG or
42 * PR_AI_ADDRCONFIG | PR_AI_NOCANONNAME. Include PR_AI_NOCANONNAME to
43 * suppress the determination of the canonical name corresponding to
44 * hostname (PR_AI_NOCANONNAME will be ignored if the TTL is retrieved).
45 * @param aAddrInfo[out] Will point to the results of the host lookup, or be
46 * null if the lookup failed.
47 * @param aGetTtl[in] If true, the TTL will be retrieved if DNS provides the
48 * answers..
50 nsresult GetAddrInfo(const nsACString& aHost, uint16_t aAddressFamily,
51 uint16_t aFlags, AddrInfo** aAddrInfo, bool aGetTtl);
53 /**
54 * Initialize the GetAddrInfo module.
56 * GetAddrInfoShutdown() should be called for every time this function is
57 * called.
59 nsresult GetAddrInfoInit();
61 /**
62 * Shutdown the GetAddrInfo module.
64 * This function should be called for every time GetAddrInfoInit() is called.
65 * An assertion may throw (but is not guarenteed) if this function is called
66 * too many times.
68 nsresult GetAddrInfoShutdown();
70 /**
71 * Resolves a HTTPS record. Will check overrides before calling the
72 * native OS implementation.
74 nsresult ResolveHTTPSRecord(const nsACString& aHost, uint16_t aFlags,
75 TypeRecordResultType& aResult, uint32_t& aTTL);
77 /**
78 * The platform specific implementation of HTTPS resolution.
80 nsresult ResolveHTTPSRecordImpl(const nsACString& aHost, uint16_t aFlags,
81 TypeRecordResultType& aResult, uint32_t& aTTL);
83 nsresult ParseHTTPSRecord(nsCString& aHost, DNSPacket& aDNSPacket,
84 TypeRecordResultType& aResult, uint32_t& aTTL);
86 class NativeDNSResolverOverride : public nsINativeDNSResolverOverride {
87 NS_DECL_THREADSAFE_ISUPPORTS
88 NS_DECL_NSINATIVEDNSRESOLVEROVERRIDE
89 public:
90 NativeDNSResolverOverride() = default;
92 static already_AddRefed<nsINativeDNSResolverOverride> GetSingleton();
94 private:
95 virtual ~NativeDNSResolverOverride() = default;
96 mozilla::RWLock mLock MOZ_UNANNOTATED{"NativeDNSResolverOverride"};
98 nsTHashMap<nsCStringHashKey, nsTArray<NetAddr>> mOverrides;
99 nsTHashMap<nsCStringHashKey, nsCString> mCnames;
100 nsTHashMap<nsCStringHashKey, nsTArray<uint8_t>> mHTTPSRecordOverrides;
102 friend bool FindAddrOverride(const nsACString& aHost, uint16_t aAddressFamily,
103 uint16_t aFlags, AddrInfo** aAddrInfo);
104 friend bool FindHTTPSRecordOverride(const nsACString& aHost,
105 TypeRecordResultType& aResult);
108 } // namespace net
109 } // namespace mozilla
111 #endif // netwerk_dns_GetAddrInfo_h