summaryrefslogtreecommitdiffstats
path: root/netwerk/dns/DNSByTypeRecord.h
blob: 8b807876986cff7c2ac5e722459fbe48b8bcac2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef DNSByTypeRecord_h__
#define DNSByTypeRecord_h__

#include "mozilla/net/HTTPSSVC.h"
#include "mozilla/ipc/IPDLParamTraits.h"
#include "ipc/IPCMessageUtils.h"
#include "mozilla/net/NeckoMessageUtils.h"

namespace mozilla {
namespace net {

// The types of nsIDNSByTypeRecord: Nothing, TXT, HTTPSSVC
using TypeRecordEmpty = Nothing;
using TypeRecordTxt = CopyableTArray<nsCString>;
using TypeRecordHTTPSSVC = CopyableTArray<SVCB>;

// This variant reflects the multiple types of data a nsIDNSByTypeRecord
// can hold.
using TypeRecordResultType =
    Variant<TypeRecordEmpty, TypeRecordTxt, TypeRecordHTTPSSVC>;

// TypeRecordResultType is a variant, but since it doesn't have a default
// constructor it's not a type we can pass directly over IPC.
struct IPCTypeRecord {
  bool operator==(const IPCTypeRecord& aOther) const {
    return mData == aOther.mData;
  }
  explicit IPCTypeRecord() : mData(Nothing{}) {}
  TypeRecordResultType mData;
  uint32_t mTTL = 0;
};

}  // namespace net
}  // namespace mozilla

namespace mozilla {
namespace ipc {

template <>
struct IPDLParamTraits<mozilla::net::IPCTypeRecord> {
  typedef mozilla::net::IPCTypeRecord paramType;
  static void Write(IPC::MessageWriter* aWriter, IProtocol* aActor,
                    const paramType& aParam) {
    WriteIPDLParam(aWriter, aActor, aParam.mData);
    WriteIPDLParam(aWriter, aActor, aParam.mTTL);
  }

  static bool Read(IPC::MessageReader* aReader, IProtocol* aActor,
                   paramType* aResult) {
    if (!ReadIPDLParam(aReader, aActor, &aResult->mData)) {
      return false;
    }
    if (!ReadIPDLParam(aReader, aActor, &aResult->mTTL)) {
      return false;
    }
    return true;
  }
};

template <>
struct IPDLParamTraits<mozilla::Nothing> {
  typedef mozilla::Nothing paramType;
  static void Write(IPC::MessageWriter* aWriter, IProtocol* aActor,
                    const paramType& aParam) {
    bool isSome = false;
    WriteIPDLParam(aWriter, aActor, isSome);
  }

  static bool Read(IPC::MessageReader* aReader, IProtocol* aActor,
                   paramType* aResult) {
    bool isSome;
    if (!ReadIPDLParam(aReader, aActor, &isSome)) {
      return false;
    }
    *aResult = Nothing();
    return true;
  }
};

template <>
struct IPDLParamTraits<mozilla::net::SVCB> {
  typedef mozilla::net::SVCB paramType;
  static void Write(IPC::MessageWriter* aWriter, IProtocol* aActor,
                    const paramType& aParam) {
    WriteIPDLParam(aWriter, aActor, aParam.mSvcFieldPriority);
    WriteIPDLParam(aWriter, aActor, aParam.mSvcDomainName);
    WriteIPDLParam(aWriter, aActor, aParam.mEchConfig);
    WriteIPDLParam(aWriter, aActor, aParam.mODoHConfig);
    WriteIPDLParam(aWriter, aActor, aParam.mHasIPHints);
    WriteIPDLParam(aWriter, aActor, aParam.mHasEchConfig);
    WriteIPDLParam(aWriter, aActor, aParam.mSvcFieldValue);
  }

  static bool Read(IPC::MessageReader* aReader, IProtocol* aActor,
                   paramType* aResult) {
    if (!ReadIPDLParam(aReader, aActor, &aResult->mSvcFieldPriority)) {
      return false;
    }
    if (!ReadIPDLParam(aReader, aActor, &aResult->mSvcDomainName)) {
      return false;
    }
    if (!ReadIPDLParam(aReader, aActor, &aResult->mEchConfig)) {
      return false;
    }
    if (!ReadIPDLParam(aReader, aActor, &aResult->mODoHConfig)) {
      return false;
    }
    if (!ReadIPDLParam(aReader, aActor, &aResult->mHasIPHints)) {
      return false;
    }
    if (!ReadIPDLParam(aReader, aActor, &aResult->mHasEchConfig)) {
      return false;
    }
    if (!ReadIPDLParam(aReader, aActor, &aResult->mSvcFieldValue)) {
      return false;
    }
    return true;
  }
};

template <>
struct IPDLParamTraits<mozilla::net::SvcParamAlpn> {
  typedef mozilla::net::SvcParamAlpn paramType;
  static void Write(IPC::MessageWriter* aWriter, IProtocol* aActor,
                    const paramType& aParam) {
    WriteIPDLParam(aWriter, aActor, aParam.mValue);
  }

  static bool Read(IPC::MessageReader* aReader, IProtocol* aActor,
                   paramType* aResult) {
    if (!ReadIPDLParam(aReader, aActor, &aResult->mValue)) {
      return false;
    }
    return true;
  }
};

template <>
struct IPDLParamTraits<mozilla::net::SvcParamNoDefaultAlpn> {
  typedef mozilla::net::SvcParamNoDefaultAlpn paramType;
  static void Write(IPC::MessageWriter* aWriter, IProtocol* aActor,
                    const paramType& aParam) {}

  static bool Read(IPC::MessageReader* aReader, IProtocol* aActor,
                   paramType* aResult) {
    return true;
  }
};

template <>
struct IPDLParamTraits<mozilla::net::SvcParamPort> {
  typedef mozilla::net::SvcParamPort paramType;
  static void Write(IPC::MessageWriter* aWriter, IProtocol* aActor,
                    const paramType& aParam) {
    WriteIPDLParam(aWriter, aActor, aParam.mValue);
  }

  static bool Read(IPC::MessageReader* aReader, IProtocol* aActor,
                   paramType* aResult) {
    if (!ReadIPDLParam(aReader, aActor, &aResult->mValue)) {
      return false;
    }
    return true;
  }
};

template <>
struct IPDLParamTraits<mozilla::net::SvcParamIpv4Hint> {
  typedef mozilla::net::SvcParamIpv4Hint paramType;
  static void Write(IPC::MessageWriter* aWriter, IProtocol* aActor,
                    const paramType& aParam) {
    WriteIPDLParam(aWriter, aActor, aParam.mValue);
  }

  static bool Read(IPC::MessageReader* aReader, IProtocol* aActor,
                   paramType* aResult) {
    if (!ReadIPDLParam(aReader, aActor, &aResult->mValue)) {
      return false;
    }
    return true;
  }
};

template <>
struct IPDLParamTraits<mozilla::net::SvcParamEchConfig> {
  typedef mozilla::net::SvcParamEchConfig paramType;
  static void Write(IPC::MessageWriter* aWriter, IProtocol* aActor,
                    const paramType& aParam) {
    WriteIPDLParam(aWriter, aActor, aParam.mValue);
  }

  static bool Read(IPC::MessageReader* aReader, IProtocol* aActor,
                   paramType* aResult) {
    if (!ReadIPDLParam(aReader, aActor, &aResult->mValue)) {
      return false;
    }
    return true;
  }
};

template <>
struct IPDLParamTraits<mozilla::net::SvcParamIpv6Hint> {
  typedef mozilla::net::SvcParamIpv6Hint paramType;
  static void Write(IPC::MessageWriter* aWriter, IProtocol* aActor,
                    const paramType& aParam) {
    WriteIPDLParam(aWriter, aActor, aParam.mValue);
  }

  static bool Read(IPC::MessageReader* aReader, IProtocol* aActor,
                   paramType* aResult) {
    if (!ReadIPDLParam(aReader, aActor, &aResult->mValue)) {
      return false;
    }
    return true;
  }
};

template <>
struct IPDLParamTraits<mozilla::net::SvcParamODoHConfig> {
  typedef mozilla::net::SvcParamODoHConfig paramType;
  static void Write(IPC::MessageWriter* aWriter, IProtocol* aActor,
                    const paramType& aParam) {
    WriteIPDLParam(aWriter, aActor, aParam.mValue);
  }

  static bool Read(IPC::MessageReader* aReader, IProtocol* aActor,
                   paramType* aResult) {
    if (!ReadIPDLParam(aReader, aActor, &aResult->mValue)) {
      return false;
    }
    return true;
  }
};

template <>
struct IPDLParamTraits<mozilla::net::SvcFieldValue> {
  typedef mozilla::net::SvcFieldValue paramType;
  static void Write(IPC::MessageWriter* aWriter, IProtocol* aActor,
                    const paramType& aParam) {
    WriteIPDLParam(aWriter, aActor, aParam.mValue);
  }

  static bool Read(IPC::MessageReader* aReader, IProtocol* aActor,
                   paramType* aResult) {
    if (!ReadIPDLParam(aReader, aActor, &aResult->mValue)) {
      return false;
    }
    return true;
  }
};

}  // namespace ipc
}  // namespace mozilla

#endif  // DNSByTypeRecord_h__