Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qdnslookup_p.h
Go to the documentation of this file.
1// Copyright (C) 2012 Jeremy Lainé <jeremy.laine@m4x.org>
2// Copyright (C) 2023 Intel Corporation.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#ifndef QDNSLOOKUP_P_H
6#define QDNSLOOKUP_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists for the convenience
13// of the QDnsLookup class. This header file may change from
14// version to version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtNetwork/private/qtnetworkglobal_p.h>
20#include "QtCore/qmutex.h"
21#include "QtCore/qrunnable.h"
22#if QT_CONFIG(thread)
23#include "QtCore/qthreadpool.h"
24#endif
25#include "QtNetwork/qdnslookup.h"
26#include "QtNetwork/qhostaddress.h"
27#include "private/qobject_p.h"
28#include "private/qurl_p.h"
29
30#if QT_CONFIG(ssl)
31# include "qsslconfiguration.h"
32#endif
33
35
37
38//#define QDNSLOOKUP_DEBUG
39
41constexpr quint16 DnsPort = 53;
42constexpr quint16 DnsOverTlsPort = 853;
43
46
48{
49public:
51 bool authenticData = false;
53
54 QList<QDnsDomainNameRecord> canonicalNameRecords;
55 QList<QDnsHostAddressRecord> hostAddressRecords;
56 QList<QDnsMailExchangeRecord> mailExchangeRecords;
57 QList<QDnsDomainNameRecord> nameServerRecords;
58 QList<QDnsDomainNameRecord> pointerRecords;
59 QList<QDnsServiceRecord> serviceRecords;
60 QList<QDnsTlsAssociationRecord> tlsAssociationRecords;
61 QList<QDnsTextRecord> textRecords;
62
63#if QT_CONFIG(ssl)
64 std::optional<QSslConfiguration> sslConfiguration;
65#endif
66
67 // helper methods
69 {
70 error = err;
71 errorString = std::move(msg);
72 }
73
74 void makeResolverSystemError(int code = -1)
75 {
76 Q_ASSERT(allAreEmpty());
78 }
79
81 {
82 Q_ASSERT(allAreEmpty());
83 setError(QDnsLookup::TimeoutError, QDnsLookup::tr("Request timed out"));
84 }
85
87 {
88 Q_ASSERT(allAreEmpty());
89 switch (rcode) {
90 case 1: // FORMERR
92 errorString = QDnsLookup::tr("Server could not process query");
93 return;
94 case 2: // SERVFAIL
95 case 4: // NOTIMP
97 errorString = QDnsLookup::tr("Server failure");
98 return;
99 case 3: // NXDOMAIN
101 errorString = QDnsLookup::tr("Non existent domain");
102 return;
103 case 5: // REFUSED
105 errorString = QDnsLookup::tr("Server refused to answer");
106 return;
107 default:
109 errorString = QDnsLookup::tr("Invalid reply received (rcode %1)")
110 .arg(rcode);
111 return;
112 }
113 }
114
116 {
117 if (msg.isEmpty())
118 msg = QDnsLookup::tr("Invalid reply received");
119 else
120 msg = QDnsLookup::tr("Invalid reply received (%1)").arg(std::move(msg));
121 *this = QDnsLookupReply(); // empty our lists
123 }
124
125private:
126 bool allAreEmpty() const
127 {
135 && textRecords.isEmpty();
136 }
137};
138
140{
141public:
143 : type(QDnsLookup::A)
144 , port(0)
145 , protocol(QDnsLookup::Standard)
146 { }
147
149 {
150 emit q_func()->nameChanged(name);
151 }
154
156 {
157 emit q_func()->nameserverChanged(nameserver);
158 }
161
163 {
164 emit q_func()->typeChanged(type);
165 }
166
169
171 {
172 emit q_func()->nameserverPortChanged(port);
173 }
174
177
179 {
180 emit q_func()->nameserverProtocolChanged(protocol);
181 }
182
185
188 bool isFinished = false;
189
190#if QT_CONFIG(ssl)
191 std::optional<QSslConfiguration> sslConfiguration;
192#endif
193
194 Q_DECLARE_PUBLIC(QDnsLookup)
195};
196
198{
200
201public:
202#ifdef Q_OS_WIN
203 using EncodedLabel = QString;
204#else
206#endif
207 // minimum IPv6 MTU (1280) minus the IPv6 (40) and UDP headers (8)
208 static constexpr qsizetype ReplyBufferSize = 1280 - 40 - 8;
209 using ReplyBuffer = QVarLengthArray<unsigned char, ReplyBufferSize>;
210
212 void run() override;
213 bool sendDnsOverTls(QDnsLookupReply *reply, QSpan<unsigned char> query, ReplyBuffer &response);
214
215signals:
217
218private:
219 template <typename T> static QString decodeLabel(T encodedLabel)
220 {
221 return qt_ACE_do(encodedLabel.toString(), NormalizeAce, ForbidLeadingDot);
222 }
224
225 EncodedLabel requestName;
226 QHostAddress nameserver;
227 QDnsLookup::Type requestType;
229 QDnsLookup::Protocol protocol;
230
231#if QT_CONFIG(ssl)
232 std::optional<QSslConfiguration> sslConfiguration;
233#endif
235};
236
238{
239public:
241 : timeToLive(0)
242 { }
243
246};
247
256
265
276
291
293{
294public:
297
298 QList<QByteArray> values;
299};
300
309
311
312#endif // QDNSLOOKUP_P_H
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore
Q_OBJECT_BINDABLE_PROPERTY(QDnsLookupPrivate, QHostAddress, nameserver, &QDnsLookupPrivate::nameserverChanged)
Q_OBJECT_BINDABLE_PROPERTY(QDnsLookupPrivate, QString, name, &QDnsLookupPrivate::nameChanged)
Q_OBJECT_BINDABLE_PROPERTY(QDnsLookupPrivate, quint16, port, &QDnsLookupPrivate::nameserverPortChanged)
QDnsLookupRunnable * runnable
void nameserverProtocolChanged()
void nameserverPortChanged()
Q_OBJECT_BINDABLE_PROPERTY(QDnsLookupPrivate, QDnsLookup::Protocol, protocol, &QDnsLookupPrivate::nameserverProtocolChanged)
Q_OBJECT_BINDABLE_PROPERTY(QDnsLookupPrivate, QDnsLookup::Type, type, &QDnsLookupPrivate::typeChanged)
QDnsLookupReply reply
void setError(QDnsLookup::Error err, QString &&msg)
QList< QDnsMailExchangeRecord > mailExchangeRecords
void makeDnsRcodeError(quint8 rcode)
QList< QDnsServiceRecord > serviceRecords
void makeInvalidReplyError(QString &&msg=QString())
QDnsLookup::Error error
QList< QDnsDomainNameRecord > canonicalNameRecords
QList< QDnsDomainNameRecord > nameServerRecords
QList< QDnsDomainNameRecord > pointerRecords
QList< QDnsHostAddressRecord > hostAddressRecords
void makeResolverSystemError(int code=-1)
QList< QDnsTlsAssociationRecord > tlsAssociationRecords
QString errorString
void makeTimeoutError()
QList< QDnsTextRecord > textRecords
void finished(const QDnsLookupReply &reply)
QDnsLookupRunnable(const QDnsLookupPrivate *d)
void run() override
Implement this pure virtual function in your subclass.
static constexpr qsizetype ReplyBufferSize
QByteArray EncodedLabel
bool sendDnsOverTls(QDnsLookupReply *reply, QSpan< unsigned char > query, ReplyBuffer &response)
friend QDebug operator<<(QDebug &, QDnsLookupRunnable *)
The QDnsLookup class represents a DNS lookup.
Definition qdnslookup.h:217
Type
Indicates the type of DNS lookup that was performed.
Definition qdnslookup.h:247
Error
Indicates all possible error conditions found during the processing of the DNS lookup.
Definition qdnslookup.h:233
@ InvalidReplyError
Definition qdnslookup.h:238
@ ServerRefusedError
Definition qdnslookup.h:240
@ ServerFailureError
Definition qdnslookup.h:239
@ InvalidRequestError
Definition qdnslookup.h:237
Protocol
Indicates the type of DNS server that is being queried.
Definition qdnslookup.h:261
QList< QByteArray > values
QDnsTlsAssociationRecord::CertificateUsage usage
QDnsTlsAssociationRecord::MatchingType matchType
QDnsTlsAssociationRecord::Selector selector
CertificateUsage
This enumeration contains valid values for the certificate usage field of TLS Association queries.
Definition qdnslookup.h:148
Selector
This enumeration contains valid values for the selector field of TLS Association queries.
Definition qdnslookup.h:166
MatchingType
This enumeration contains valid values for the matching type field of TLS Association queries.
Definition qdnslookup.h:180
The QHostAddress class provides an IP address.
bool isEmpty() const noexcept
Definition qlist.h:401
\inmodule QtCore
Definition qobject.h:103
\inmodule QtCore
Definition qrunnable.h:18
\inmodule QtCore
Definition qshareddata.h:19
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QString arg(qlonglong a, int fieldwidth=0, int base=10, QChar fillChar=u' ') const
Definition qstring.cpp:8870
Combined button and popup list for selecting options.
constexpr quint16 DnsPort
constexpr quint16 DnsOverTlsPort
QT_BEGIN_NAMESPACE constexpr qsizetype MaxDomainNameLength
QDebug operator<<(QDebug &, QDnsLookupRunnable *)
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
EGLOutputPortEXT port
Q_DECL_COLD_FUNCTION Q_CORE_EXPORT QString qt_error_string(int errorCode=-1)
n varying highp vec2 A
GLuint GLuint GLfloat weight
GLenum type
GLuint name
GLenum query
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define QT_REQUIRE_CONFIG(feature)
#define Q_OBJECT
#define signals
#define emit
unsigned int quint32
Definition qtypes.h:50
unsigned short quint16
Definition qtypes.h:48
ptrdiff_t qsizetype
Definition qtypes.h:165
unsigned char quint8
Definition qtypes.h:46
@ ForbidLeadingDot
Definition qurl_p.h:30
QString Q_CORE_EXPORT qt_ACE_do(const QString &domain, AceOperation op, AceLeadingDot dot, QUrl::AceProcessingOptions options={})
Definition qurlidna.cpp:920
@ NormalizeAce
Definition qurl_p.h:31
QNetworkReply * reply