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/. */
5 #ifndef DNSByTypeRecord_h__
6 #define DNSByTypeRecord_h__
8 #include "mozilla/net/HTTPSSVC.h"
9 #include "mozilla/ipc/IPDLParamTraits.h"
10 #include "ipc/IPCMessageUtils.h"
11 #include "mozilla/net/NeckoMessageUtils.h"
16 // The types of nsIDNSByTypeRecord: Nothing, TXT, HTTPSSVC
17 using TypeRecordEmpty
= Nothing
;
18 using TypeRecordTxt
= CopyableTArray
<nsCString
>;
19 using TypeRecordHTTPSSVC
= CopyableTArray
<SVCB
>;
21 // This variant reflects the multiple types of data a nsIDNSByTypeRecord
23 using TypeRecordResultType
=
24 Variant
<TypeRecordEmpty
, TypeRecordTxt
, TypeRecordHTTPSSVC
>;
26 // TypeRecordResultType is a variant, but since it doesn't have a default
27 // constructor it's not a type we can pass directly over IPC.
28 struct IPCTypeRecord
{
29 bool operator==(const IPCTypeRecord
& aOther
) const {
30 return mData
== aOther
.mData
;
32 explicit IPCTypeRecord() : mData(Nothing
{}) {}
33 TypeRecordResultType mData
;
38 } // namespace mozilla
44 struct IPDLParamTraits
<mozilla::net::IPCTypeRecord
> {
45 typedef mozilla::net::IPCTypeRecord paramType
;
46 static void Write(IPC::MessageWriter
* aWriter
, IProtocol
* aActor
,
47 const paramType
& aParam
) {
48 WriteIPDLParam(aWriter
, aActor
, aParam
.mData
);
49 WriteIPDLParam(aWriter
, aActor
, aParam
.mTTL
);
52 static bool Read(IPC::MessageReader
* aReader
, IProtocol
* aActor
,
54 if (!ReadIPDLParam(aReader
, aActor
, &aResult
->mData
)) {
57 if (!ReadIPDLParam(aReader
, aActor
, &aResult
->mTTL
)) {
65 struct IPDLParamTraits
<mozilla::Nothing
> {
66 typedef mozilla::Nothing paramType
;
67 static void Write(IPC::MessageWriter
* aWriter
, IProtocol
* aActor
,
68 const paramType
& aParam
) {
70 WriteIPDLParam(aWriter
, aActor
, isSome
);
73 static bool Read(IPC::MessageReader
* aReader
, IProtocol
* aActor
,
76 if (!ReadIPDLParam(aReader
, aActor
, &isSome
)) {
85 struct IPDLParamTraits
<mozilla::net::SVCB
> {
86 typedef mozilla::net::SVCB paramType
;
87 static void Write(IPC::MessageWriter
* aWriter
, IProtocol
* aActor
,
88 const paramType
& aParam
) {
89 WriteIPDLParam(aWriter
, aActor
, aParam
.mSvcFieldPriority
);
90 WriteIPDLParam(aWriter
, aActor
, aParam
.mSvcDomainName
);
91 WriteIPDLParam(aWriter
, aActor
, aParam
.mEchConfig
);
92 WriteIPDLParam(aWriter
, aActor
, aParam
.mODoHConfig
);
93 WriteIPDLParam(aWriter
, aActor
, aParam
.mHasIPHints
);
94 WriteIPDLParam(aWriter
, aActor
, aParam
.mHasEchConfig
);
95 WriteIPDLParam(aWriter
, aActor
, aParam
.mSvcFieldValue
);
98 static bool Read(IPC::MessageReader
* aReader
, IProtocol
* aActor
,
100 if (!ReadIPDLParam(aReader
, aActor
, &aResult
->mSvcFieldPriority
)) {
103 if (!ReadIPDLParam(aReader
, aActor
, &aResult
->mSvcDomainName
)) {
106 if (!ReadIPDLParam(aReader
, aActor
, &aResult
->mEchConfig
)) {
109 if (!ReadIPDLParam(aReader
, aActor
, &aResult
->mODoHConfig
)) {
112 if (!ReadIPDLParam(aReader
, aActor
, &aResult
->mHasIPHints
)) {
115 if (!ReadIPDLParam(aReader
, aActor
, &aResult
->mHasEchConfig
)) {
118 if (!ReadIPDLParam(aReader
, aActor
, &aResult
->mSvcFieldValue
)) {
126 struct IPDLParamTraits
<mozilla::net::SvcParamAlpn
> {
127 typedef mozilla::net::SvcParamAlpn paramType
;
128 static void Write(IPC::MessageWriter
* aWriter
, IProtocol
* aActor
,
129 const paramType
& aParam
) {
130 WriteIPDLParam(aWriter
, aActor
, aParam
.mValue
);
133 static bool Read(IPC::MessageReader
* aReader
, IProtocol
* aActor
,
134 paramType
* aResult
) {
135 if (!ReadIPDLParam(aReader
, aActor
, &aResult
->mValue
)) {
143 struct IPDLParamTraits
<mozilla::net::SvcParamNoDefaultAlpn
> {
144 typedef mozilla::net::SvcParamNoDefaultAlpn paramType
;
145 static void Write(IPC::MessageWriter
* aWriter
, IProtocol
* aActor
,
146 const paramType
& aParam
) {}
148 static bool Read(IPC::MessageReader
* aReader
, IProtocol
* aActor
,
149 paramType
* aResult
) {
155 struct IPDLParamTraits
<mozilla::net::SvcParamPort
> {
156 typedef mozilla::net::SvcParamPort paramType
;
157 static void Write(IPC::MessageWriter
* aWriter
, IProtocol
* aActor
,
158 const paramType
& aParam
) {
159 WriteIPDLParam(aWriter
, aActor
, aParam
.mValue
);
162 static bool Read(IPC::MessageReader
* aReader
, IProtocol
* aActor
,
163 paramType
* aResult
) {
164 if (!ReadIPDLParam(aReader
, aActor
, &aResult
->mValue
)) {
172 struct IPDLParamTraits
<mozilla::net::SvcParamIpv4Hint
> {
173 typedef mozilla::net::SvcParamIpv4Hint paramType
;
174 static void Write(IPC::MessageWriter
* aWriter
, IProtocol
* aActor
,
175 const paramType
& aParam
) {
176 WriteIPDLParam(aWriter
, aActor
, aParam
.mValue
);
179 static bool Read(IPC::MessageReader
* aReader
, IProtocol
* aActor
,
180 paramType
* aResult
) {
181 if (!ReadIPDLParam(aReader
, aActor
, &aResult
->mValue
)) {
189 struct IPDLParamTraits
<mozilla::net::SvcParamEchConfig
> {
190 typedef mozilla::net::SvcParamEchConfig paramType
;
191 static void Write(IPC::MessageWriter
* aWriter
, IProtocol
* aActor
,
192 const paramType
& aParam
) {
193 WriteIPDLParam(aWriter
, aActor
, aParam
.mValue
);
196 static bool Read(IPC::MessageReader
* aReader
, IProtocol
* aActor
,
197 paramType
* aResult
) {
198 if (!ReadIPDLParam(aReader
, aActor
, &aResult
->mValue
)) {
206 struct IPDLParamTraits
<mozilla::net::SvcParamIpv6Hint
> {
207 typedef mozilla::net::SvcParamIpv6Hint paramType
;
208 static void Write(IPC::MessageWriter
* aWriter
, IProtocol
* aActor
,
209 const paramType
& aParam
) {
210 WriteIPDLParam(aWriter
, aActor
, aParam
.mValue
);
213 static bool Read(IPC::MessageReader
* aReader
, IProtocol
* aActor
,
214 paramType
* aResult
) {
215 if (!ReadIPDLParam(aReader
, aActor
, &aResult
->mValue
)) {
223 struct IPDLParamTraits
<mozilla::net::SvcParamODoHConfig
> {
224 typedef mozilla::net::SvcParamODoHConfig paramType
;
225 static void Write(IPC::MessageWriter
* aWriter
, IProtocol
* aActor
,
226 const paramType
& aParam
) {
227 WriteIPDLParam(aWriter
, aActor
, aParam
.mValue
);
230 static bool Read(IPC::MessageReader
* aReader
, IProtocol
* aActor
,
231 paramType
* aResult
) {
232 if (!ReadIPDLParam(aReader
, aActor
, &aResult
->mValue
)) {
240 struct IPDLParamTraits
<mozilla::net::SvcFieldValue
> {
241 typedef mozilla::net::SvcFieldValue paramType
;
242 static void Write(IPC::MessageWriter
* aWriter
, IProtocol
* aActor
,
243 const paramType
& aParam
) {
244 WriteIPDLParam(aWriter
, aActor
, aParam
.mValue
);
247 static bool Read(IPC::MessageReader
* aReader
, IProtocol
* aActor
,
248 paramType
* aResult
) {
249 if (!ReadIPDLParam(aReader
, aActor
, &aResult
->mValue
)) {
257 } // namespace mozilla
259 #endif // DNSByTypeRecord_h__