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;
25
26class Q_NETWORK_EXPORT QDnsDomainNameRecord
27{
28public:
29 QDnsDomainNameRecord();
30 QDnsDomainNameRecord(const QDnsDomainNameRecord &other);
31 QDnsDomainNameRecord &operator=(QDnsDomainNameRecord &&other) noexcept { swap(other); return *this; }
32 QDnsDomainNameRecord &operator=(const QDnsDomainNameRecord &other);
33 ~QDnsDomainNameRecord();
34
35 void swap(QDnsDomainNameRecord &other) noexcept { d.swap(other&: other.d); }
36
37 QString name() const;
38 quint32 timeToLive() const;
39 QString value() const;
40
41private:
42 QSharedDataPointer<QDnsDomainNameRecordPrivate> d;
43 friend class QDnsLookupRunnable;
44};
45
46Q_DECLARE_SHARED(QDnsDomainNameRecord)
47
48class Q_NETWORK_EXPORT QDnsHostAddressRecord
49{
50public:
51 QDnsHostAddressRecord();
52 QDnsHostAddressRecord(const QDnsHostAddressRecord &other);
53 QDnsHostAddressRecord &operator=(QDnsHostAddressRecord &&other) noexcept { swap(other); return *this; }
54 QDnsHostAddressRecord &operator=(const QDnsHostAddressRecord &other);
55 ~QDnsHostAddressRecord();
56
57 void swap(QDnsHostAddressRecord &other) noexcept { d.swap(other&: other.d); }
58
59 QString name() const;
60 quint32 timeToLive() const;
61 QHostAddress value() const;
62
63private:
64 QSharedDataPointer<QDnsHostAddressRecordPrivate> d;
65 friend class QDnsLookupRunnable;
66};
67
68Q_DECLARE_SHARED(QDnsHostAddressRecord)
69
70class Q_NETWORK_EXPORT QDnsMailExchangeRecord
71{
72public:
73 QDnsMailExchangeRecord();
74 QDnsMailExchangeRecord(const QDnsMailExchangeRecord &other);
75 QDnsMailExchangeRecord &operator=(QDnsMailExchangeRecord &&other) noexcept { swap(other); return *this; }
76 QDnsMailExchangeRecord &operator=(const QDnsMailExchangeRecord &other);
77 ~QDnsMailExchangeRecord();
78
79 void swap(QDnsMailExchangeRecord &other) noexcept { d.swap(other&: other.d); }
80
81 QString exchange() const;
82 QString name() const;
83 quint16 preference() const;
84 quint32 timeToLive() const;
85
86private:
87 QSharedDataPointer<QDnsMailExchangeRecordPrivate> d;
88 friend class QDnsLookupRunnable;
89};
90
91Q_DECLARE_SHARED(QDnsMailExchangeRecord)
92
93class Q_NETWORK_EXPORT QDnsServiceRecord
94{
95public:
96 QDnsServiceRecord();
97 QDnsServiceRecord(const QDnsServiceRecord &other);
98 QDnsServiceRecord &operator=(QDnsServiceRecord &&other) noexcept { swap(other); return *this; }
99 QDnsServiceRecord &operator=(const QDnsServiceRecord &other);
100 ~QDnsServiceRecord();
101
102 void swap(QDnsServiceRecord &other) noexcept { d.swap(other&: other.d); }
103
104 QString name() const;
105 quint16 port() const;
106 quint16 priority() const;
107 QString target() const;
108 quint32 timeToLive() const;
109 quint16 weight() const;
110
111private:
112 QSharedDataPointer<QDnsServiceRecordPrivate> d;
113 friend class QDnsLookupRunnable;
114};
115
116Q_DECLARE_SHARED(QDnsServiceRecord)
117
118class Q_NETWORK_EXPORT QDnsTextRecord
119{
120public:
121 QDnsTextRecord();
122 QDnsTextRecord(const QDnsTextRecord &other);
123 QDnsTextRecord &operator=(QDnsTextRecord &&other) noexcept { swap(other); return *this; }
124 QDnsTextRecord &operator=(const QDnsTextRecord &other);
125 ~QDnsTextRecord();
126
127 void swap(QDnsTextRecord &other) noexcept { d.swap(other&: other.d); }
128
129 QString name() const;
130 quint32 timeToLive() const;
131 QList<QByteArray> values() const;
132
133private:
134 QSharedDataPointer<QDnsTextRecordPrivate> d;
135 friend class QDnsLookupRunnable;
136};
137
138Q_DECLARE_SHARED(QDnsTextRecord)
139
140class Q_NETWORK_EXPORT QDnsLookup : public QObject
141{
142 Q_OBJECT
143 Q_PROPERTY(Error error READ error NOTIFY finished)
144 Q_PROPERTY(QString errorString READ errorString NOTIFY finished)
145 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged BINDABLE bindableName)
146 Q_PROPERTY(Type type READ type WRITE setType NOTIFY typeChanged BINDABLE bindableType)
147 Q_PROPERTY(QHostAddress nameserver READ nameserver WRITE setNameserver NOTIFY nameserverChanged
148 BINDABLE bindableNameserver)
149 Q_PROPERTY(quint16 nameserverPort READ nameserverPort WRITE setNameserverPort
150 NOTIFY nameserverPortChanged BINDABLE bindableNameserverPort)
151
152public:
153 enum Error
154 {
155 NoError = 0,
156 ResolverError,
157 OperationCancelledError,
158 InvalidRequestError,
159 InvalidReplyError,
160 ServerFailureError,
161 ServerRefusedError,
162 NotFoundError,
163 TimeoutError,
164 };
165 Q_ENUM(Error)
166
167 enum Type
168 {
169 A = 1,
170 AAAA = 28,
171 ANY = 255,
172 CNAME = 5,
173 MX = 15,
174 NS = 2,
175 PTR = 12,
176 SRV = 33,
177 TXT = 16
178 };
179 Q_ENUM(Type)
180
181 explicit QDnsLookup(QObject *parent = nullptr);
182 QDnsLookup(Type type, const QString &name, QObject *parent = nullptr);
183 QDnsLookup(Type type, const QString &name, const QHostAddress &nameserver, QObject *parent = nullptr);
184 QDnsLookup(Type type, const QString &name, const QHostAddress &nameserver, quint16 port,
185 QObject *parent = nullptr);
186 ~QDnsLookup();
187
188 Error error() const;
189 QString errorString() const;
190 bool isFinished() const;
191
192 QString name() const;
193 void setName(const QString &name);
194 QBindable<QString> bindableName();
195
196 Type type() const;
197 void setType(QDnsLookup::Type);
198 QBindable<Type> bindableType();
199
200 QHostAddress nameserver() const;
201 void setNameserver(const QHostAddress &nameserver);
202 QBindable<QHostAddress> bindableNameserver();
203 quint16 nameserverPort() const;
204 void setNameserverPort(quint16 port);
205 QBindable<quint16> bindableNameserverPort();
206 void setNameserver(const QHostAddress &nameserver, quint16 port);
207
208 QList<QDnsDomainNameRecord> canonicalNameRecords() const;
209 QList<QDnsHostAddressRecord> hostAddressRecords() const;
210 QList<QDnsMailExchangeRecord> mailExchangeRecords() const;
211 QList<QDnsDomainNameRecord> nameServerRecords() const;
212 QList<QDnsDomainNameRecord> pointerRecords() const;
213 QList<QDnsServiceRecord> serviceRecords() const;
214 QList<QDnsTextRecord> textRecords() const;
215
216
217public Q_SLOTS:
218 void abort();
219 void lookup();
220
221Q_SIGNALS:
222 void finished();
223 void nameChanged(const QString &name);
224 void typeChanged(Type type);
225 void nameserverChanged(const QHostAddress &nameserver);
226 void nameserverPortChanged(quint16 port);
227
228private:
229 Q_DECLARE_PRIVATE(QDnsLookup)
230};
231
232QT_END_NAMESPACE
233
234#endif // QDNSLOOKUP_H
235

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