1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "nsIDNSByTypeRecord.h"
9 #include "mozilla/net/DNS.h"
10 #include "mozilla/Variant.h"
11 #include "mozilla/Maybe.h"
17 class DNSHTTPSSVCRecordBase
;
19 enum SvcParamKey
: uint16_t {
20 SvcParamKeyMandatory
= 0,
22 SvcParamKeyNoDefaultAlpn
= 2,
24 SvcParamKeyIpv4Hint
= 4,
25 SvcParamKeyEchConfig
= 5,
26 SvcParamKeyIpv6Hint
= 6,
27 SvcParamKeyODoHConfig
= 32769,
30 inline bool IsValidSvcParamKey(uint16_t aKey
) {
31 return aKey
<= SvcParamKeyIpv6Hint
|| aKey
== SvcParamKeyODoHConfig
;
35 bool operator==(const SvcParamAlpn
& aOther
) const {
36 return mValue
== aOther
.mValue
;
38 CopyableTArray
<nsCString
> mValue
;
41 struct SvcParamNoDefaultAlpn
{
42 bool operator==(const SvcParamNoDefaultAlpn
& aOther
) const { return true; }
46 bool operator==(const SvcParamPort
& aOther
) const {
47 return mValue
== aOther
.mValue
;
52 struct SvcParamIpv4Hint
{
53 bool operator==(const SvcParamIpv4Hint
& aOther
) const {
54 return mValue
== aOther
.mValue
;
56 CopyableTArray
<mozilla::net::NetAddr
> mValue
;
59 struct SvcParamEchConfig
{
60 bool operator==(const SvcParamEchConfig
& aOther
) const {
61 return mValue
== aOther
.mValue
;
66 struct SvcParamIpv6Hint
{
67 bool operator==(const SvcParamIpv6Hint
& aOther
) const {
68 return mValue
== aOther
.mValue
;
70 CopyableTArray
<mozilla::net::NetAddr
> mValue
;
73 struct SvcParamODoHConfig
{
74 bool operator==(const SvcParamODoHConfig
& aOther
) const {
75 return mValue
== aOther
.mValue
;
81 mozilla::Variant
<Nothing
, SvcParamAlpn
, SvcParamNoDefaultAlpn
, SvcParamPort
,
82 SvcParamIpv4Hint
, SvcParamEchConfig
, SvcParamIpv6Hint
,
85 struct SvcFieldValue
{
86 bool operator==(const SvcFieldValue
& aOther
) const {
87 return mValue
== aOther
.mValue
;
89 SvcFieldValue() : mValue(AsVariant(Nothing
{})) {}
94 bool operator==(const SVCB
& aOther
) const {
95 return mSvcFieldPriority
== aOther
.mSvcFieldPriority
&&
96 mSvcDomainName
== aOther
.mSvcDomainName
&&
97 mSvcFieldValue
== aOther
.mSvcFieldValue
;
99 bool operator<(const SVCB
& aOther
) const;
100 Maybe
<uint16_t> GetPort() const;
101 bool NoDefaultAlpn() const;
102 void GetIPHints(CopyableTArray
<mozilla::net::NetAddr
>& aAddresses
) const;
103 nsTArray
<std::tuple
<nsCString
, SupportedAlpnRank
>> GetAllAlpn() const;
104 uint16_t mSvcFieldPriority
= 0;
105 nsCString mSvcDomainName
;
106 nsCString mEchConfig
;
107 nsCString mODoHConfig
;
108 bool mHasIPHints
= false;
109 bool mHasEchConfig
= false;
110 CopyableTArray
<SvcFieldValue
> mSvcFieldValue
;
114 explicit SVCBWrapper(const SVCB
& aRecord
) : mRecord(aRecord
) {}
115 Maybe
<std::tuple
<nsCString
, SupportedAlpnRank
>> mAlpn
;
119 class SVCBRecord
: public nsISVCBRecord
{
120 NS_DECL_THREADSAFE_ISUPPORTS
121 NS_DECL_NSISVCBRECORD
123 explicit SVCBRecord(const SVCB
& data
)
124 : mData(data
), mPort(Nothing()), mAlpn(Nothing()) {}
125 explicit SVCBRecord(const SVCB
& data
,
126 Maybe
<std::tuple
<nsCString
, SupportedAlpnRank
>> aAlpn
);
129 friend class DNSHTTPSSVCRecordBase
;
131 virtual ~SVCBRecord() = default;
134 Maybe
<uint16_t> mPort
;
135 Maybe
<std::tuple
<nsCString
, SupportedAlpnRank
>> mAlpn
;
138 class DNSHTTPSSVCRecordBase
{
140 explicit DNSHTTPSSVCRecordBase(const nsACString
& aHost
) : mHost(aHost
) {}
143 virtual ~DNSHTTPSSVCRecordBase() = default;
145 already_AddRefed
<nsISVCBRecord
> GetServiceModeRecordInternal(
146 bool aNoHttp2
, bool aNoHttp3
, const nsTArray
<SVCB
>& aRecords
,
147 bool& aRecordsAllExcluded
, bool aCheckHttp3ExcludedList
= true);
149 bool HasIPAddressesInternal(const nsTArray
<SVCB
>& aRecords
);
151 void GetAllRecordsWithEchConfigInternal(
152 bool aNoHttp2
, bool aNoHttp3
, const nsTArray
<SVCB
>& aRecords
,
153 bool* aAllRecordsHaveEchConfig
, bool* aAllRecordsInH3ExcludedList
,
154 nsTArray
<RefPtr
<nsISVCBRecord
>>& aResult
,
155 bool aCheckHttp3ExcludedList
= true);
157 // The owner name of this HTTPS RR.
162 } // namespace mozilla
164 #endif // HTTPSSVC_h__