Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qdnslookup.h
Go to the documentation of this file.
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// Qt-Security score:significant reason:default
4
5#ifndef QDNSLOOKUP_H
6#define QDNSLOOKUP_H
7
8#include <QtNetwork/qtnetworkglobal.h>
9#include <QtCore/qlist.h>
10#include <QtCore/qobject.h>
11#include <QtCore/qshareddata.h>
12#include <QtCore/qstring.h>
13#include <QtCore/qproperty.h>
14
16
17QT_BEGIN_NAMESPACE
18
19class QHostAddress;
27class QSslConfiguration;
28
29QT_DECLARE_QESDP_SPECIALIZATION_DTOR(QDnsTlsAssociationRecordPrivate)
30
31class Q_NETWORK_EXPORT QDnsDomainNameRecord
32{
33public:
34 QDnsDomainNameRecord();
35 QDnsDomainNameRecord(const QDnsDomainNameRecord &other);
36 QDnsDomainNameRecord &operator=(QDnsDomainNameRecord &&other) noexcept { swap(other); return *this; }
37 QDnsDomainNameRecord &operator=(const QDnsDomainNameRecord &other);
38 ~QDnsDomainNameRecord();
39
40 void swap(QDnsDomainNameRecord &other) noexcept { d.swap(other.d); }
41
42 QString name() const;
43 quint32 timeToLive() const;
44 QString value() const;
45
46private:
47 QSharedDataPointer<QDnsDomainNameRecordPrivate> d;
48 friend class QDnsLookupRunnable;
49};
50
52
53class Q_NETWORK_EXPORT QDnsHostAddressRecord
54{
55public:
56 QDnsHostAddressRecord();
57 QDnsHostAddressRecord(const QDnsHostAddressRecord &other);
58 QDnsHostAddressRecord &operator=(QDnsHostAddressRecord &&other) noexcept { swap(other); return *this; }
59 QDnsHostAddressRecord &operator=(const QDnsHostAddressRecord &other);
60 ~QDnsHostAddressRecord();
61
62 void swap(QDnsHostAddressRecord &other) noexcept { d.swap(other.d); }
63
64 QString name() const;
65 quint32 timeToLive() const;
66 QHostAddress value() const;
67
68private:
69 QSharedDataPointer<QDnsHostAddressRecordPrivate> d;
70 friend class QDnsLookupRunnable;
71};
72
74
75class Q_NETWORK_EXPORT QDnsMailExchangeRecord
76{
77public:
78 QDnsMailExchangeRecord();
79 QDnsMailExchangeRecord(const QDnsMailExchangeRecord &other);
80 QDnsMailExchangeRecord &operator=(QDnsMailExchangeRecord &&other) noexcept { swap(other); return *this; }
81 QDnsMailExchangeRecord &operator=(const QDnsMailExchangeRecord &other);
82 ~QDnsMailExchangeRecord();
83
84 void swap(QDnsMailExchangeRecord &other) noexcept { d.swap(other.d); }
85
86 QString exchange() const;
87 QString name() const;
88 quint16 preference() const;
89 quint32 timeToLive() const;
90
91private:
92 QSharedDataPointer<QDnsMailExchangeRecordPrivate> d;
93 friend class QDnsLookupRunnable;
94};
95
97
98class Q_NETWORK_EXPORT QDnsServiceRecord
99{
100public:
101 QDnsServiceRecord();
102 QDnsServiceRecord(const QDnsServiceRecord &other);
103 QDnsServiceRecord &operator=(QDnsServiceRecord &&other) noexcept { swap(other); return *this; }
104 QDnsServiceRecord &operator=(const QDnsServiceRecord &other);
105 ~QDnsServiceRecord();
106
107 void swap(QDnsServiceRecord &other) noexcept { d.swap(other.d); }
108
109 QString name() const;
110 quint16 port() const;
111 quint16 priority() const;
112 QString target() const;
113 quint32 timeToLive() const;
114 quint16 weight() const;
115
116private:
117 QSharedDataPointer<QDnsServiceRecordPrivate> d;
118 friend class QDnsLookupRunnable;
119};
120
122
123class Q_NETWORK_EXPORT QDnsTextRecord
124{
125public:
126 QDnsTextRecord();
127 QDnsTextRecord(const QDnsTextRecord &other);
128 QDnsTextRecord &operator=(QDnsTextRecord &&other) noexcept { swap(other); return *this; }
129 QDnsTextRecord &operator=(const QDnsTextRecord &other);
130 ~QDnsTextRecord();
131
132 void swap(QDnsTextRecord &other) noexcept { d.swap(other.d); }
133
134 QString name() const;
135 quint32 timeToLive() const;
136 QList<QByteArray> values() const;
137
138private:
139 QSharedDataPointer<QDnsTextRecordPrivate> d;
140 friend class QDnsLookupRunnable;
141};
142
144
146{
147 Q_GADGET_EXPORT(Q_NETWORK_EXPORT)
148 Q_CLASSINFO("RegisterEnumClassesUnscoped", "false")
149public:
151 // https://www.iana.org/assignments/dane-parameters/dane-parameters.xhtml#certificate-usages
152 // RFC 6698
158
159 // Aliases by RFC 7218
164 PrivCert = 255,
165 };
166 Q_ENUM(CertificateUsage)
167
168 enum class Selector : quint8 {
169 // https://www.iana.org/assignments/dane-parameters/dane-parameters.xhtml#selectors
170 // RFC 6698
174
175 // Aliases by RFC 7218
179 };
180 Q_ENUM(Selector)
181
182 enum class MatchingType : quint8 {
183 // https://www.iana.org/assignments/dane-parameters/dane-parameters.xhtml#matching-types
184 // RFC 6698
185 Exact = 0,
190 };
191 Q_ENUM(MatchingType)
192
199
200 void swap(QDnsTlsAssociationRecord &other) noexcept { d.swap(other.d); }
201
202 Q_NETWORK_EXPORT QString name() const;
203 Q_NETWORK_EXPORT quint32 timeToLive() const;
207 Q_NETWORK_EXPORT QByteArray value() const;
208
209private:
210 QExplicitlySharedDataPointer<QDnsTlsAssociationRecordPrivate> d;
211 friend class QDnsLookupRunnable;
212};
213
214Q_DECLARE_SHARED(QDnsTlsAssociationRecord)
215
216class Q_NETWORK_EXPORT QDnsLookup : public QObject
217{
218 Q_OBJECT
219 Q_PROPERTY(Error error READ error NOTIFY finished)
220 Q_PROPERTY(bool authenticData READ isAuthenticData NOTIFY finished)
221 Q_PROPERTY(QString errorString READ errorString NOTIFY finished)
222 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged BINDABLE bindableName)
223 Q_PROPERTY(Type type READ type WRITE setType NOTIFY typeChanged BINDABLE bindableType)
224 Q_PROPERTY(QHostAddress nameserver READ nameserver WRITE setNameserver NOTIFY nameserverChanged
225 BINDABLE bindableNameserver)
226 Q_PROPERTY(quint16 nameserverPort READ nameserverPort WRITE setNameserverPort
227 NOTIFY nameserverPortChanged BINDABLE bindableNameserverPort)
228 Q_PROPERTY(Protocol nameserverProtocol READ nameserverProtocol WRITE setNameserverProtocol
229 NOTIFY nameserverProtocolChanged BINDABLE bindableNameserverProtocol)
230
231public:
232 enum Error
233 {
234 NoError = 0,
235 ResolverError,
236 OperationCancelledError,
237 InvalidRequestError,
238 InvalidReplyError,
239 ServerFailureError,
240 ServerRefusedError,
241 NotFoundError,
242 TimeoutError,
243 };
244 Q_ENUM(Error)
245
246 enum Type
247 {
248 A = 1,
249 AAAA = 28,
250 ANY = 255,
251 CNAME = 5,
252 MX = 15,
253 NS = 2,
254 PTR = 12,
255 SRV = 33,
256 TLSA = 52,
257 TXT = 16
258 };
259 Q_ENUM(Type)
260
261 enum Protocol : quint8 {
262 Standard = 0,
263 DnsOverTls,
264 };
265 Q_ENUM(Protocol)
266
267 explicit QDnsLookup(QObject *parent = nullptr);
268 QDnsLookup(Type type, const QString &name, QObject *parent = nullptr);
269 QDnsLookup(Type type, const QString &name, const QHostAddress &nameserver, QObject *parent = nullptr);
270 QDnsLookup(Type type, const QString &name, const QHostAddress &nameserver, quint16 port,
271 QObject *parent = nullptr);
272 QDnsLookup(Type type, const QString &name, Protocol protocol, const QHostAddress &nameserver,
273 quint16 port = 0, QObject *parent = nullptr);
274 ~QDnsLookup();
275
276 bool isAuthenticData() const;
277 Error error() const;
278 QString errorString() const;
279 bool isFinished() const;
280
281 QString name() const;
282 void setName(const QString &name);
283 QBindable<QString> bindableName();
284
285 Type type() const;
286 void setType(QDnsLookup::Type);
287 QBindable<Type> bindableType();
288
289 QHostAddress nameserver() const;
290 void setNameserver(const QHostAddress &nameserver);
291 QBindable<QHostAddress> bindableNameserver();
292 quint16 nameserverPort() const;
293 void setNameserverPort(quint16 port);
294 QBindable<quint16> bindableNameserverPort();
295 Protocol nameserverProtocol() const;
296 void setNameserverProtocol(Protocol protocol);
297 QBindable<Protocol> bindableNameserverProtocol();
298 void setNameserver(Protocol protocol, const QHostAddress &nameserver, quint16 port = 0);
299 QT_NETWORK_INLINE_SINCE(6, 8)
300 void setNameserver(const QHostAddress &nameserver, quint16 port);
301
302 QList<QDnsDomainNameRecord> canonicalNameRecords() const;
303 QList<QDnsHostAddressRecord> hostAddressRecords() const;
304 QList<QDnsMailExchangeRecord> mailExchangeRecords() const;
305 QList<QDnsDomainNameRecord> nameServerRecords() const;
306 QList<QDnsDomainNameRecord> pointerRecords() const;
307 QList<QDnsServiceRecord> serviceRecords() const;
308 QList<QDnsTextRecord> textRecords() const;
309 QList<QDnsTlsAssociationRecord> tlsAssociationRecords() const;
310
311#if QT_CONFIG(ssl)
312 void setSslConfiguration(const QSslConfiguration &sslConfiguration);
313 QSslConfiguration sslConfiguration() const;
314#endif
315
316 static bool isProtocolSupported(Protocol protocol);
317 Q_DECL_CONST_FUNCTION static quint16 defaultPortForProtocol(Protocol protocol) noexcept;
318
319public Q_SLOTS:
320 void abort();
321 void lookup();
322
323Q_SIGNALS:
324 void finished();
325 void nameChanged(const QString &name);
326 void typeChanged(QDnsLookup::Type type);
327 void nameserverChanged(const QHostAddress &nameserver);
328 void nameserverPortChanged(quint16 port);
329 void nameserverProtocolChanged(QDnsLookup::Protocol protocol);
330
331private:
332 Q_DECLARE_PRIVATE(QDnsLookup)
333};
334
335#if QT_NETWORK_INLINE_IMPL_SINCE(6, 8)
336void QDnsLookup::setNameserver(const QHostAddress &nameserver, quint16 port)
337{
338 setNameserver(Standard, nameserver, port);
339}
340#endif
341
342QT_END_NAMESPACE
343
344#endif // QDNSLOOKUP_H
The QDnsDomainNameRecord class stores information about a domain name record.
Definition qdnslookup.h:32
The QDnsHostAddressRecord class stores information about a host address record.
Definition qdnslookup.h:54
QDnsLookupRunnable(const QDnsLookupPrivate *d)
void run() override
Implement this pure virtual function in your subclass.
bool sendDnsOverTls(QDnsLookupReply *reply, QSpan< unsigned char > query, ReplyBuffer &response)
The QDnsLookup class represents a DNS lookup.
Definition qdnslookup.h:217
The QDnsMailExchangeRecord class stores information about a DNS MX record.
Definition qdnslookup.h:76
The QDnsServiceRecord class stores information about a DNS SRV record.
Definition qdnslookup.h:99
The QDnsTextRecord class stores information about a DNS TXT record.
Definition qdnslookup.h:124
The QDnsTlsAssociationRecord class stores information about a DNS TLSA record.
Definition qdnslookup.h:146
void swap(QDnsTlsAssociationRecord &other) noexcept
Definition qdnslookup.h:200
QDnsTlsAssociationRecord(QDnsTlsAssociationRecord &&other) noexcept=default
Q_NETWORK_EXPORT ~QDnsTlsAssociationRecord()
Destroys this TLS Association record object.
#define Q_APPLICATION_STATIC(TYPE, NAME,...)
static void qt_qdnsmailexchangerecord_sort(QList< QDnsMailExchangeRecord > &records)
static void qt_qdnsservicerecord_sort(QList< QDnsServiceRecord > &records)
static bool qt_qdnsmailexchangerecord_less_than(const QDnsMailExchangeRecord &r1, const QDnsMailExchangeRecord &r2)
static bool qt_qdnsservicerecord_less_than(const QDnsServiceRecord &r1, const QDnsServiceRecord &r2)
static QDnsLookupRunnable::EncodedLabel encodeLabel(const QString &label)
QT_REQUIRE_CONFIG(dnslookup)
#define qCWarning(category,...)
#define Q_STATIC_LOGGING_CATEGORY(name,...)