Qt 6.x
The Qt SDK
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
31
33
34//#define QDNSLOOKUP_DEBUG
35
37constexpr quint16 DnsPort = 53;
38
41
43{
44public:
47
55
56 // helper methods
58 {
59 error = err;
60 errorString = std::move(msg);
61 }
62
63 void makeResolverSystemError(int code = -1)
64 {
65 Q_ASSERT(allAreEmpty());
67 }
68
70 {
71 Q_ASSERT(allAreEmpty());
72 setError(QDnsLookup::TimeoutError, QDnsLookup::tr("Request timed out"));
73 }
74
76 {
77 Q_ASSERT(allAreEmpty());
78 switch (rcode) {
79 case 1: // FORMERR
81 errorString = QDnsLookup::tr("Server could not process query");
82 return;
83 case 2: // SERVFAIL
84 case 4: // NOTIMP
86 errorString = QDnsLookup::tr("Server failure");
87 return;
88 case 3: // NXDOMAIN
90 errorString = QDnsLookup::tr("Non existent domain");
91 return;
92 case 5: // REFUSED
94 errorString = QDnsLookup::tr("Server refused to answer");
95 return;
96 default:
98 errorString = QDnsLookup::tr("Invalid reply received (rcode %1)")
99 .arg(rcode);
100 return;
101 }
102 }
103
105 {
106 if (msg.isEmpty())
107 msg = QDnsLookup::tr("Invalid reply received");
108 else
109 msg = QDnsLookup::tr("Invalid reply received (%1)").arg(std::move(msg));
110 *this = QDnsLookupReply(); // empty our lists
112 }
113
114private:
115 bool allAreEmpty() const
116 {
123 && textRecords.isEmpty();
124 }
125};
126
128{
129public:
131 : type(QDnsLookup::A)
132 , port(DnsPort)
133 { }
134
136 {
137 emit q_func()->nameChanged(name);
138 }
141
143 {
144 emit q_func()->nameserverChanged(nameserver);
145 }
148
150 {
151 emit q_func()->typeChanged(type);
152 }
153
156
158 {
159 emit q_func()->nameserverPortChanged(port);
160 }
161
164
165
168 bool isFinished = false;
169
170 Q_DECLARE_PUBLIC(QDnsLookup)
171};
172
174{
176
177public:
178#ifdef Q_OS_WIN
179 using EncodedLabel = QString;
180#else
182#endif
183
185 void run() override;
186
187signals:
189
190private:
191 template <typename T> static QString decodeLabel(T encodedLabel)
192 {
193 return qt_ACE_do(encodedLabel.toString(), NormalizeAce, ForbidLeadingDot);
194 }
196
197 EncodedLabel requestName;
198 QHostAddress nameserver;
199 QDnsLookup::Type requestType;
202};
203
205{
206public:
208 : timeToLive(0)
209 { }
210
213};
214
216{
217public:
219 { }
220
222};
223
225{
226public:
228 { }
229
231};
232
234{
235public:
237 : preference(0)
238 { }
239
242};
243
245{
246public:
248 : port(0),
249 priority(0),
250 weight(0)
251 { }
252
257};
258
260{
261public:
263 { }
264
266};
267
269
270#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 nameserverPortChanged()
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)
QString errorString
void makeTimeoutError()
QList< QDnsTextRecord > textRecords
void finished(const QDnsLookupReply &reply)
void run() override
Implement this pure virtual function in your subclass.
QByteArray EncodedLabel
friend QDebug operator<<(QDebug &, QDnsLookupRunnable *)
The QDnsLookup class represents a DNS lookup.
Definition qdnslookup.h:141
Type
Indicates the type of DNS lookup that was performed.
Definition qdnslookup.h:168
Error
Indicates all possible error conditions found during the processing of the DNS lookup.
Definition qdnslookup.h:154
@ InvalidReplyError
Definition qdnslookup.h:159
@ ServerRefusedError
Definition qdnslookup.h:161
@ ServerFailureError
Definition qdnslookup.h:160
@ InvalidRequestError
Definition qdnslookup.h:158
QList< QByteArray > values
The QHostAddress class provides an IP address.
Definition qlist.h:74
bool isEmpty() const noexcept
Definition qlist.h:390
\inmodule QtCore
Definition qobject.h:90
\inmodule QtCore
Definition qrunnable.h:18
\inmodule QtCore
Definition qshareddata.h:19
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
QString arg(qlonglong a, int fieldwidth=0, int base=10, QChar fillChar=u' ') const
Definition qstring.cpp:8606
Combined button and popup list for selecting options.
constexpr quint16 DnsPort
QT_BEGIN_NAMESPACE constexpr qsizetype MaxDomainNameLength
QDebug operator<<(QDebug &, QDnsLookupRunnable *)
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:45
unsigned short quint16
Definition qtypes.h:43
ptrdiff_t qsizetype
Definition qtypes.h:70
unsigned char quint8
Definition qtypes.h:41
@ 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:889
@ NormalizeAce
Definition qurl_p.h:31
QNetworkReply * reply