1// Copyright (C) 2012 Jeremy Lainé <jeremy.laine@m4x.org>
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QDNSLOOKUP_H
5#define QDNSLOOKUP_H
6
7#include <QtNetwork/qtnetworkglobal.h>
8#include <QtCore/qlist.h>
9#include <QtCore/qobject.h>
10#include <QtCore/qshareddata.h>
11#include <QtCore/qstring.h>
12#include <QtCore/qproperty.h>
13
14QT_REQUIRE_CONFIG(dnslookup);
15
16QT_BEGIN_NAMESPACE
17
18class QHostAddress;
19class QDnsLookupPrivate;
20class QDnsDomainNameRecordPrivate;
21class QDnsHostAddressRecordPrivate;
22class QDnsMailExchangeRecordPrivate;
23class QDnsServiceRecordPrivate;
24class QDnsTextRecordPrivate;
25class QDnsTlsAssociationRecordPrivate;
26class QSslConfiguration;
27
28QT_DECLARE_QESDP_SPECIALIZATION_DTOR(QDnsTlsAssociationRecordPrivate)
29
30class Q_NETWORK_EXPORT QDnsDomainNameRecord
31{
32public:
33 QDnsDomainNameRecord();
34 QDnsDomainNameRecord(const QDnsDomainNameRecord &other);
35 QDnsDomainNameRecord &operator=(QDnsDomainNameRecord &&other) noexcept { swap(other); return *this; }
36 QDnsDomainNameRecord &operator=(const QDnsDomainNameRecord &other);
37 ~QDnsDomainNameRecord();
38
39 void swap(QDnsDomainNameRecord &other) noexcept { d.swap(other&: other.d); }
40
41 QString name() const;
42 quint32 timeToLive() const;
43 QString value() const;
44
45private:
46 QSharedDataPointer<QDnsDomainNameRecordPrivate> d;
47 friend class QDnsLookupRunnable;
48};
49
50Q_DECLARE_SHARED(QDnsDomainNameRecord)
51
52class Q_NETWORK_EXPORT QDnsHostAddressRecord
53{
54public:
55 QDnsHostAddressRecord();
56 QDnsHostAddressRecord(const QDnsHostAddressRecord &other);
57 QDnsHostAddressRecord &operator=(QDnsHostAddressRecord &&other) noexcept { swap(other); return *this; }
58 QDnsHostAddressRecord &operator=(const QDnsHostAddressRecord &other);
59 ~QDnsHostAddressRecord();
60
61 void swap(QDnsHostAddressRecord &other) noexcept { d.swap(other&: other.d); }
62
63 QString name() const;
64 quint32 timeToLive() const;
65 QHostAddress value() const;
66
67private:
68 QSharedDataPointer<QDnsHostAddressRecordPrivate> d;
69 friend class QDnsLookupRunnable;
70};
71
72Q_DECLARE_SHARED(QDnsHostAddressRecord)
73
74class Q_NETWORK_EXPORT QDnsMailExchangeRecord
75{
76public:
77 QDnsMailExchangeRecord();
78 QDnsMailExchangeRecord(const QDnsMailExchangeRecord &other);
79 QDnsMailExchangeRecord &operator=(QDnsMailExchangeRecord &&other) noexcept { swap(other); return *this; }
80 QDnsMailExchangeRecord &operator=(const QDnsMailExchangeRecord &other);
81 ~QDnsMailExchangeRecord();
82
83 void swap(QDnsMailExchangeRecord &other) noexcept { d.swap(other&: other.d); }
84
85 QString exchange() const;
86 QString name() const;
87 quint16 preference() const;
88 quint32 timeToLive() const;
89
90private:
91 QSharedDataPointer<QDnsMailExchangeRecordPrivate> d;
92 friend class QDnsLookupRunnable;
93};
94
95Q_DECLARE_SHARED(QDnsMailExchangeRecord)
96
97class Q_NETWORK_EXPORT QDnsServiceRecord
98{
99public:
100 QDnsServiceRecord();
101 QDnsServiceRecord(const QDnsServiceRecord &other);
102 QDnsServiceRecord &operator=(QDnsServiceRecord &&other) noexcept { swap(other); return *this; }
103 QDnsServiceRecord &operator=(const QDnsServiceRecord &other);
104 ~QDnsServiceRecord();
105
106 void swap(QDnsServiceRecord &other) noexcept { d.swap(other&: other.d); }
107
108 QString name() const;
109 quint16 port() const;
110 quint16 priority() const;
111 QString target() const;
112 quint32 timeToLive() const;
113 quint16 weight() const;
114
115private:
116 QSharedDataPointer<QDnsServiceRecordPrivate> d;
117 friend class QDnsLookupRunnable;
118};
119
120Q_DECLARE_SHARED(QDnsServiceRecord)
121
122class Q_NETWORK_EXPORT QDnsTextRecord
123{
124public:
125 QDnsTextRecord();
126 QDnsTextRecord(const QDnsTextRecord &other);
127 QDnsTextRecord &operator=(QDnsTextRecord &&other) noexcept { swap(other); return *this; }
128 QDnsTextRecord &operator=(const QDnsTextRecord &other);
129 ~QDnsTextRecord();
130
131 void swap(QDnsTextRecord &other) noexcept { d.swap(other&: other.d); }
132
133 QString name() const;
134 quint32 timeToLive() const;
135 QList<QByteArray> values() const;
136
137private:
138 QSharedDataPointer<QDnsTextRecordPrivate> d;
139 friend class QDnsLookupRunnable;
140};
141
142Q_DECLARE_SHARED(QDnsTextRecord)
143
144class QDnsTlsAssociationRecord
145{
146 Q_GADGET_EXPORT(Q_NETWORK_EXPORT)
147 Q_CLASSINFO("RegisterEnumClassesUnscoped", "false")
148public:
149 enum class CertificateUsage : quint8 {
150 // https://www.iana.org/assignments/dane-parameters/dane-parameters.xhtml#certificate-usages
151 // RFC 6698
152 CertificateAuthorityConstrait = 0,
153 ServiceCertificateConstraint = 1,
154 TrustAnchorAssertion = 2,
155 DomainIssuedCertificate = 3,
156 PrivateUse = 255,
157
158 // Aliases by RFC 7218
159 PKIX_TA = 0,
160 PKIX_EE = 1,
161 DANE_TA = 2,
162 DANE_EE = 3,
163 PrivCert = 255,
164 };
165 Q_ENUM(CertificateUsage)
166
167 enum class Selector : quint8 {
168 // https://www.iana.org/assignments/dane-parameters/dane-parameters.xhtml#selectors
169 // RFC 6698
170 FullCertificate = 0,
171 SubjectPublicKeyInfo = 1,
172 PrivateUse = 255,
173
174 // Aliases by RFC 7218
175 Cert = FullCertificate,
176 SPKI = SubjectPublicKeyInfo,
177 PrivSel = PrivateUse,
178 };
179 Q_ENUM(Selector)
180
181 enum class MatchingType : quint8 {
182 // https://www.iana.org/assignments/dane-parameters/dane-parameters.xhtml#matching-types
183 // RFC 6698
184 Exact = 0,
185 Sha256 = 1,
186 Sha512 = 2,
187 PrivateUse = 255,
188 PrivMatch = PrivateUse,
189 };
190 Q_ENUM(MatchingType)
191
192 Q_NETWORK_EXPORT QDnsTlsAssociationRecord();
193 Q_NETWORK_EXPORT QDnsTlsAssociationRecord(const QDnsTlsAssociationRecord &other);
194 QDnsTlsAssociationRecord(QDnsTlsAssociationRecord &&other) noexcept = default;
195 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QDnsTlsAssociationRecord)
196 Q_NETWORK_EXPORT QDnsTlsAssociationRecord &operator=(const QDnsTlsAssociationRecord &other);
197 Q_NETWORK_EXPORT ~QDnsTlsAssociationRecord();
198
199 void swap(QDnsTlsAssociationRecord &other) noexcept { d.swap(other&: other.d); }
200
201 Q_NETWORK_EXPORT QString name() const;
202 Q_NETWORK_EXPORT quint32 timeToLive() const;
203 Q_NETWORK_EXPORT CertificateUsage usage() const;
204 Q_NETWORK_EXPORT Selector selector() const;
205 Q_NETWORK_EXPORT MatchingType matchType() const;
206 Q_NETWORK_EXPORT QByteArray value() const;
207
208private:
209 QExplicitlySharedDataPointer<QDnsTlsAssociationRecordPrivate> d;
210 friend class QDnsLookupRunnable;
211};
212
213Q_DECLARE_SHARED(QDnsTlsAssociationRecord)
214
215class Q_NETWORK_EXPORT QDnsLookup : public QObject
216{
217 Q_OBJECT
218 Q_PROPERTY(Error error READ error NOTIFY finished)
219 Q_PROPERTY(bool authenticData READ isAuthenticData NOTIFY finished)
220 Q_PROPERTY(QString errorString READ errorString NOTIFY finished)
221 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged BINDABLE bindableName)
222 Q_PROPERTY(Type type READ type WRITE setType NOTIFY typeChanged BINDABLE bindableType)
223 Q_PROPERTY(QHostAddress nameserver READ nameserver WRITE setNameserver NOTIFY nameserverChanged
224 BINDABLE bindableNameserver)
225 Q_PROPERTY(quint16 nameserverPort READ nameserverPort WRITE setNameserverPort
226 NOTIFY nameserverPortChanged BINDABLE bindableNameserverPort)
227 Q_PROPERTY(Protocol nameserverProtocol READ nameserverProtocol WRITE setNameserverProtocol
228 NOTIFY nameserverProtocolChanged BINDABLE bindableNameserverProtocol)
229
230public:
231 enum Error
232 {
233 NoError = 0,
234 ResolverError,
235 OperationCancelledError,
236 InvalidRequestError,
237 InvalidReplyError,
238 ServerFailureError,
239 ServerRefusedError,
240 NotFoundError,
241 TimeoutError,
242 };
243 Q_ENUM(Error)
244
245 enum Type
246 {
247 A = 1,
248 AAAA = 28,
249 ANY = 255,
250 CNAME = 5,
251 MX = 15,
252 NS = 2,
253 PTR = 12,
254 SRV = 33,
255 TLSA = 52,
256 TXT = 16
257 };
258 Q_ENUM(Type)
259
260 enum Protocol : quint8 {
261 Standard = 0,
262 DnsOverTls,
263 };
264 Q_ENUM(Protocol)
265
266 explicit QDnsLookup(QObject *parent = nullptr);
267 QDnsLookup(Type type, const QString &name, QObject *parent = nullptr);
268 QDnsLookup(Type type, const QString &name, const QHostAddress &nameserver, QObject *parent = nullptr);
269 QDnsLookup(Type type, const QString &name, const QHostAddress &nameserver, quint16 port,
270 QObject *parent = nullptr);
271 QDnsLookup(Type type, const QString &name, Protocol protocol, const QHostAddress &nameserver,
272 quint16 port = 0, QObject *parent = nullptr);
273 ~QDnsLookup();
274
275 bool isAuthenticData() const;
276 Error error() const;
277 QString errorString() const;
278 bool isFinished() const;
279
280 QString name() const;
281 void setName(const QString &name);
282 QBindable<QString> bindableName();
283
284 Type type() const;
285 void setType(QDnsLookup::Type);
286 QBindable<Type> bindableType();
287
288 QHostAddress nameserver() const;
289 void setNameserver(const QHostAddress &nameserver);
290 QBindable<QHostAddress> bindableNameserver();
291 quint16 nameserverPort() const;
292 void setNameserverPort(quint16 port);
293 QBindable<quint16> bindableNameserverPort();
294 Protocol nameserverProtocol() const;
295 void setNameserverProtocol(Protocol protocol);
296 QBindable<Protocol> bindableNameserverProtocol();
297 void setNameserver(Protocol protocol, const QHostAddress &nameserver, quint16 port = 0);
298 QT_NETWORK_INLINE_SINCE(6, 8)
299 void setNameserver(const QHostAddress &nameserver, quint16 port);
300
301 QList<QDnsDomainNameRecord> canonicalNameRecords() const;
302 QList<QDnsHostAddressRecord> hostAddressRecords() const;
303 QList<QDnsMailExchangeRecord> mailExchangeRecords() const;
304 QList<QDnsDomainNameRecord> nameServerRecords() const;
305 QList<QDnsDomainNameRecord> pointerRecords() const;
306 QList<QDnsServiceRecord> serviceRecords() const;
307 QList<QDnsTextRecord> textRecords() const;
308 QList<QDnsTlsAssociationRecord> tlsAssociationRecords() const;
309
310#if QT_CONFIG(ssl)
311 void setSslConfiguration(const QSslConfiguration &sslConfiguration);
312 QSslConfiguration sslConfiguration() const;
313#endif
314
315 static bool isProtocolSupported(Protocol protocol);
316 static quint16 defaultPortForProtocol(Protocol protocol) noexcept Q_DECL_CONST_FUNCTION;
317
318public Q_SLOTS:
319 void abort();
320 void lookup();
321
322Q_SIGNALS:
323 void finished();
324 void nameChanged(const QString &name);
325 void typeChanged(QDnsLookup::Type type);
326 void nameserverChanged(const QHostAddress &nameserver);
327 void nameserverPortChanged(quint16 port);
328 void nameserverProtocolChanged(QDnsLookup::Protocol protocol);
329
330private:
331 Q_DECLARE_PRIVATE(QDnsLookup)
332};
333
334#if QT_NETWORK_INLINE_IMPL_SINCE(6, 8)
335void QDnsLookup::setNameserver(const QHostAddress &nameserver, quint16 port)
336{
337 setNameserver(protocol: Standard, nameserver, port);
338}
339#endif
340
341QT_END_NAMESPACE
342
343#endif // QDNSLOOKUP_H
344

Provided by KDAB

Privacy Policy
Start learning QML with our Intro Training
Find out more

source code of qtbase/src/network/kernel/qdnslookup.h