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_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
36QT_BEGIN_NAMESPACE
37
38//#define QDNSLOOKUP_DEBUG
39
40constexpr qsizetype MaxDomainNameLength = 255;
41constexpr quint16 DnsPort = 53;
42constexpr quint16 DnsOverTlsPort = 853;
43
46
48{
49public:
51 bool authenticData = false;
53
62
63#if QT_CONFIG(ssl)
65#endif
66
67 // helper methods
68 void setError(QDnsLookup::Error err, QString &&msg)
69 {
70 error = err;
71 errorString = std::move(msg);
72 }
73
74 void makeResolverSystemError(int code = -1)
75 {
76 Q_ASSERT(allAreEmpty());
77 setError(QDnsLookup::ResolverError, qt_error_string(code));
78 }
79
81 {
82 Q_ASSERT(allAreEmpty());
83 setError(QDnsLookup::TimeoutError, QDnsLookup::tr("Request timed out"));
84 }
85
86 void makeDnsRcodeError(quint8 rcode)
87 {
88 Q_ASSERT(allAreEmpty());
89 switch (rcode) {
90 case 1: // FORMERR
91 error = QDnsLookup::InvalidRequestError;
92 errorString = QDnsLookup::tr("Server could not process query");
93 return;
94 case 2: // SERVFAIL
95 case 4: // NOTIMP
96 error = QDnsLookup::ServerFailureError;
97 errorString = QDnsLookup::tr("Server failure");
98 return;
99 case 3: // NXDOMAIN
100 error = QDnsLookup::NotFoundError;
101 errorString = QDnsLookup::tr("Non existent domain");
102 return;
103 case 5: // REFUSED
104 error = QDnsLookup::ServerRefusedError;
105 errorString = QDnsLookup::tr("Server refused to answer");
106 return;
107 default:
108 error = QDnsLookup::InvalidReplyError;
109 errorString = QDnsLookup::tr("Invalid reply received (rcode %1)")
110 .arg(rcode);
111 return;
112 }
113 }
114
115 void makeInvalidReplyError(QString &&msg = QString())
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
122 setError(QDnsLookup::InvalidReplyError, std::move(msg));
123 }
124
125private:
126 bool allAreEmpty() const
127 {
128 return canonicalNameRecords.isEmpty()
129 && hostAddressRecords.isEmpty()
130 && mailExchangeRecords.isEmpty()
131 && nameServerRecords.isEmpty()
132 && pointerRecords.isEmpty()
133 && serviceRecords.isEmpty()
134 && tlsAssociationRecords.isEmpty()
135 && textRecords.isEmpty();
136 }
137};
138
140{
141public:
143 : type(QDnsLookup::A)
144 , port(0)
146 { }
147
149 {
150 emit q_func()->nameChanged(name);
151 }
153 &QDnsLookupPrivate::nameChanged);
154
156 {
157 emit q_func()->nameserverChanged(nameserver);
158 }
159 Q_OBJECT_BINDABLE_PROPERTY(QDnsLookupPrivate, QHostAddress, nameserver,
160 &QDnsLookupPrivate::nameserverChanged);
161
163 {
164 emit q_func()->typeChanged(type);
165 }
166
168 type, &QDnsLookupPrivate::typeChanged);
169
171 {
172 emit q_func()->nameserverPortChanged(port);
173 }
174
176 port, &QDnsLookupPrivate::nameserverPortChanged);
177
179 {
180 emit q_func()->nameserverProtocolChanged(protocol);
181 }
182
184 protocol, &QDnsLookupPrivate::nameserverProtocolChanged);
185
188 bool isFinished = false;
189
190#if QT_CONFIG(ssl)
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;
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 }
223 void query(QDnsLookupReply *reply);
224
225 EncodedLabel requestName;
226 QHostAddress nameserver;
228 quint16 port;
230
231#if QT_CONFIG(ssl)
233#endif
234 friend QDebug operator<<(QDebug &, QDnsLookupRunnable *);
235};
236
238{
239public:
241 : timeToLive(0)
242 { }
243
246};
247
256
258{
259public:
262
263 QHostAddress value;
264};
265
276
291
300
309
310QT_END_NAMESPACE
311
312#endif // QDNSLOOKUP_P_H
The QDnsDomainNameRecord class stores information about a domain name record.
Definition qdnslookup.h:31
The QDnsHostAddressRecord class stores information about a host address record.
Definition qdnslookup.h:53
Q_OBJECT_BINDABLE_PROPERTY(QDnsLookupPrivate, QString, name, &QDnsLookupPrivate::nameChanged)
QDnsLookupRunnable * runnable
void nameserverProtocolChanged()
void nameserverPortChanged()
QDnsLookupReply reply
void setError(QDnsLookup::Error err, QString &&msg)
QList< QDnsMailExchangeRecord > mailExchangeRecords
void makeDnsRcodeError(quint8 rcode)
QList< QDnsServiceRecord > serviceRecords
void makeInvalidReplyError(QString &&msg=QString())
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
QDnsLookupRunnable(const QDnsLookupPrivate *d)
void run() override
Implement this pure virtual function in your subclass.
static constexpr qsizetype ReplyBufferSize
bool sendDnsOverTls(QDnsLookupReply *reply, QSpan< unsigned char > query, ReplyBuffer &response)
The QDnsLookup class represents a DNS lookup.
Definition qdnslookup.h:216
The QDnsMailExchangeRecord class stores information about a DNS MX record.
Definition qdnslookup.h:75
The QDnsServiceRecord class stores information about a DNS SRV record.
Definition qdnslookup.h:98
QList< QByteArray > values
The QDnsTextRecord class stores information about a DNS TXT record.
Definition qdnslookup.h:123
QDnsTlsAssociationRecord::CertificateUsage usage
QDnsTlsAssociationRecord::MatchingType matchType
QDnsTlsAssociationRecord::Selector selector
The QDnsTlsAssociationRecord class stores information about a DNS TLSA record.
Definition qdnslookup.h:145
void swap(QDnsTlsAssociationRecord &other) noexcept
Definition qdnslookup.h:199
QDnsTlsAssociationRecord(QDnsTlsAssociationRecord &&other) noexcept=default
Q_NETWORK_EXPORT ~QDnsTlsAssociationRecord()
Destroys this TLS Association record object.
Combined button and popup list for selecting options.
QT_REQUIRE_CONFIG(animation)
#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)
constexpr quint16 DnsPort
constexpr quint16 DnsOverTlsPort
QDebug operator<<(QDebug &, QDnsLookupRunnable *)
#define qCWarning(category,...)
#define Q_STATIC_LOGGING_CATEGORY(name,...)