1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2012 Jeremy Lainé <jeremy.laine@m4x.org> |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtNetwork module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #ifndef QDNSLOOKUP_H |
41 | #define QDNSLOOKUP_H |
42 | |
43 | #include <QtNetwork/qtnetworkglobal.h> |
44 | #include <QtCore/qlist.h> |
45 | #include <QtCore/qobject.h> |
46 | #include <QtCore/qshareddata.h> |
47 | #include <QtCore/qsharedpointer.h> |
48 | #include <QtCore/qstring.h> |
49 | |
50 | QT_REQUIRE_CONFIG(dnslookup); |
51 | |
52 | QT_BEGIN_NAMESPACE |
53 | |
54 | class QHostAddress; |
55 | class QDnsLookupPrivate; |
56 | class QDnsDomainNameRecordPrivate; |
57 | class QDnsHostAddressRecordPrivate; |
58 | class QDnsMailExchangeRecordPrivate; |
59 | class QDnsServiceRecordPrivate; |
60 | class QDnsTextRecordPrivate; |
61 | |
62 | class Q_NETWORK_EXPORT QDnsDomainNameRecord |
63 | { |
64 | public: |
65 | QDnsDomainNameRecord(); |
66 | QDnsDomainNameRecord(const QDnsDomainNameRecord &other); |
67 | QDnsDomainNameRecord &operator=(QDnsDomainNameRecord &&other) noexcept { swap(other); return *this; } |
68 | QDnsDomainNameRecord &operator=(const QDnsDomainNameRecord &other); |
69 | ~QDnsDomainNameRecord(); |
70 | |
71 | void swap(QDnsDomainNameRecord &other) noexcept { qSwap(d, other.d); } |
72 | |
73 | QString name() const; |
74 | quint32 timeToLive() const; |
75 | QString value() const; |
76 | |
77 | private: |
78 | QSharedDataPointer<QDnsDomainNameRecordPrivate> d; |
79 | friend class QDnsLookupRunnable; |
80 | }; |
81 | |
82 | Q_DECLARE_SHARED(QDnsDomainNameRecord) |
83 | |
84 | class Q_NETWORK_EXPORT QDnsHostAddressRecord |
85 | { |
86 | public: |
87 | QDnsHostAddressRecord(); |
88 | QDnsHostAddressRecord(const QDnsHostAddressRecord &other); |
89 | QDnsHostAddressRecord &operator=(QDnsHostAddressRecord &&other) noexcept { swap(other); return *this; } |
90 | QDnsHostAddressRecord &operator=(const QDnsHostAddressRecord &other); |
91 | ~QDnsHostAddressRecord(); |
92 | |
93 | void swap(QDnsHostAddressRecord &other) noexcept { qSwap(d, other.d); } |
94 | |
95 | QString name() const; |
96 | quint32 timeToLive() const; |
97 | QHostAddress value() const; |
98 | |
99 | private: |
100 | QSharedDataPointer<QDnsHostAddressRecordPrivate> d; |
101 | friend class QDnsLookupRunnable; |
102 | }; |
103 | |
104 | Q_DECLARE_SHARED(QDnsHostAddressRecord) |
105 | |
106 | class Q_NETWORK_EXPORT QDnsMailExchangeRecord |
107 | { |
108 | public: |
109 | QDnsMailExchangeRecord(); |
110 | QDnsMailExchangeRecord(const QDnsMailExchangeRecord &other); |
111 | QDnsMailExchangeRecord &operator=(QDnsMailExchangeRecord &&other) noexcept { swap(other); return *this; } |
112 | QDnsMailExchangeRecord &operator=(const QDnsMailExchangeRecord &other); |
113 | ~QDnsMailExchangeRecord(); |
114 | |
115 | void swap(QDnsMailExchangeRecord &other) noexcept { qSwap(d, other.d); } |
116 | |
117 | QString exchange() const; |
118 | QString name() const; |
119 | quint16 preference() const; |
120 | quint32 timeToLive() const; |
121 | |
122 | private: |
123 | QSharedDataPointer<QDnsMailExchangeRecordPrivate> d; |
124 | friend class QDnsLookupRunnable; |
125 | }; |
126 | |
127 | Q_DECLARE_SHARED(QDnsMailExchangeRecord) |
128 | |
129 | class Q_NETWORK_EXPORT QDnsServiceRecord |
130 | { |
131 | public: |
132 | QDnsServiceRecord(); |
133 | QDnsServiceRecord(const QDnsServiceRecord &other); |
134 | QDnsServiceRecord &operator=(QDnsServiceRecord &&other) noexcept { swap(other); return *this; } |
135 | QDnsServiceRecord &operator=(const QDnsServiceRecord &other); |
136 | ~QDnsServiceRecord(); |
137 | |
138 | void swap(QDnsServiceRecord &other) noexcept { qSwap(d, other.d); } |
139 | |
140 | QString name() const; |
141 | quint16 port() const; |
142 | quint16 priority() const; |
143 | QString target() const; |
144 | quint32 timeToLive() const; |
145 | quint16 weight() const; |
146 | |
147 | private: |
148 | QSharedDataPointer<QDnsServiceRecordPrivate> d; |
149 | friend class QDnsLookupRunnable; |
150 | }; |
151 | |
152 | Q_DECLARE_SHARED(QDnsServiceRecord) |
153 | |
154 | class Q_NETWORK_EXPORT QDnsTextRecord |
155 | { |
156 | public: |
157 | QDnsTextRecord(); |
158 | QDnsTextRecord(const QDnsTextRecord &other); |
159 | QDnsTextRecord &operator=(QDnsTextRecord &&other) noexcept { swap(other); return *this; } |
160 | QDnsTextRecord &operator=(const QDnsTextRecord &other); |
161 | ~QDnsTextRecord(); |
162 | |
163 | void swap(QDnsTextRecord &other) noexcept { qSwap(d, other.d); } |
164 | |
165 | QString name() const; |
166 | quint32 timeToLive() const; |
167 | QList<QByteArray> values() const; |
168 | |
169 | private: |
170 | QSharedDataPointer<QDnsTextRecordPrivate> d; |
171 | friend class QDnsLookupRunnable; |
172 | }; |
173 | |
174 | Q_DECLARE_SHARED(QDnsTextRecord) |
175 | |
176 | class Q_NETWORK_EXPORT QDnsLookup : public QObject |
177 | { |
178 | Q_OBJECT |
179 | Q_PROPERTY(Error error READ error NOTIFY finished) |
180 | Q_PROPERTY(QString errorString READ errorString NOTIFY finished) |
181 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) |
182 | Q_PROPERTY(Type type READ type WRITE setType NOTIFY typeChanged) |
183 | Q_PROPERTY(QHostAddress nameserver READ nameserver WRITE setNameserver NOTIFY nameserverChanged) |
184 | |
185 | public: |
186 | enum Error |
187 | { |
188 | NoError = 0, |
189 | ResolverError, |
190 | OperationCancelledError, |
191 | InvalidRequestError, |
192 | InvalidReplyError, |
193 | ServerFailureError, |
194 | ServerRefusedError, |
195 | NotFoundError |
196 | }; |
197 | Q_ENUM(Error) |
198 | |
199 | enum Type |
200 | { |
201 | A = 1, |
202 | AAAA = 28, |
203 | ANY = 255, |
204 | CNAME = 5, |
205 | MX = 15, |
206 | NS = 2, |
207 | PTR = 12, |
208 | SRV = 33, |
209 | TXT = 16 |
210 | }; |
211 | Q_ENUM(Type) |
212 | |
213 | explicit QDnsLookup(QObject *parent = nullptr); |
214 | QDnsLookup(Type type, const QString &name, QObject *parent = nullptr); |
215 | QDnsLookup(Type type, const QString &name, const QHostAddress &nameserver, QObject *parent = nullptr); |
216 | ~QDnsLookup(); |
217 | |
218 | Error error() const; |
219 | QString errorString() const; |
220 | bool isFinished() const; |
221 | |
222 | QString name() const; |
223 | void setName(const QString &name); |
224 | |
225 | Type type() const; |
226 | void setType(QDnsLookup::Type); |
227 | |
228 | QHostAddress nameserver() const; |
229 | void setNameserver(const QHostAddress &nameserver); |
230 | |
231 | QList<QDnsDomainNameRecord> canonicalNameRecords() const; |
232 | QList<QDnsHostAddressRecord> hostAddressRecords() const; |
233 | QList<QDnsMailExchangeRecord> mailExchangeRecords() const; |
234 | QList<QDnsDomainNameRecord> nameServerRecords() const; |
235 | QList<QDnsDomainNameRecord> pointerRecords() const; |
236 | QList<QDnsServiceRecord> serviceRecords() const; |
237 | QList<QDnsTextRecord> textRecords() const; |
238 | |
239 | |
240 | public Q_SLOTS: |
241 | void abort(); |
242 | void lookup(); |
243 | |
244 | Q_SIGNALS: |
245 | void finished(); |
246 | void nameChanged(const QString &name); |
247 | void typeChanged(Type type); |
248 | void nameserverChanged(const QHostAddress &nameserver); |
249 | |
250 | private: |
251 | Q_DECLARE_PRIVATE(QDnsLookup) |
252 | Q_PRIVATE_SLOT(d_func(), void _q_lookupFinished(const QDnsLookupReply &reply)) |
253 | }; |
254 | |
255 | QT_END_NAMESPACE |
256 | |
257 | #endif // QDNSLOOKUP_H |
258 | |