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_P_H
41#define QDNSLOOKUP_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists for the convenience
48// of the QDnsLookup class. This header file may change from
49// version to version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <QtNetwork/private/qtnetworkglobal_p.h>
55#include "QtCore/qmutex.h"
56#include "QtCore/qrunnable.h"
57#include "QtCore/qsharedpointer.h"
58#if QT_CONFIG(thread)
59#include "QtCore/qthreadpool.h"
60#endif
61#include "QtNetwork/qdnslookup.h"
62#include "QtNetwork/qhostaddress.h"
63#include "private/qobject_p.h"
64
65QT_REQUIRE_CONFIG(dnslookup);
66
67QT_BEGIN_NAMESPACE
68
69//#define QDNSLOOKUP_DEBUG
70
71class QDnsLookupRunnable;
72
73class QDnsLookupReply
74{
75public:
76 QDnsLookupReply()
77 : error(QDnsLookup::NoError)
78 { }
79
80 QDnsLookup::Error error;
81 QString errorString;
82
83 QList<QDnsDomainNameRecord> canonicalNameRecords;
84 QList<QDnsHostAddressRecord> hostAddressRecords;
85 QList<QDnsMailExchangeRecord> mailExchangeRecords;
86 QList<QDnsDomainNameRecord> nameServerRecords;
87 QList<QDnsDomainNameRecord> pointerRecords;
88 QList<QDnsServiceRecord> serviceRecords;
89 QList<QDnsTextRecord> textRecords;
90};
91
92class QDnsLookupPrivate : public QObjectPrivate
93{
94public:
95 QDnsLookupPrivate()
96 : isFinished(false)
97 , type(QDnsLookup::A)
98 , runnable(nullptr)
99 { }
100
101 void _q_lookupFinished(const QDnsLookupReply &reply);
102
103 static const char *msgNoIpV6NameServerAdresses;
104
105 bool isFinished;
106 QString name;
107 QDnsLookup::Type type;
108 QHostAddress nameserver;
109 QDnsLookupReply reply;
110 QDnsLookupRunnable *runnable;
111
112 Q_DECLARE_PUBLIC(QDnsLookup)
113};
114
115class QDnsLookupRunnable : public QObject, public QRunnable
116{
117 Q_OBJECT
118
119public:
120 QDnsLookupRunnable(QDnsLookup::Type type, const QByteArray &name, const QHostAddress &nameserver)
121 : requestType(type)
122 , requestName(name)
123 , nameserver(nameserver)
124 { }
125 void run() override;
126
127signals:
128 void finished(const QDnsLookupReply &reply);
129
130private:
131 static void query(const int requestType, const QByteArray &requestName, const QHostAddress &nameserver, QDnsLookupReply *reply);
132 QDnsLookup::Type requestType;
133 QByteArray requestName;
134 QHostAddress nameserver;
135};
136
137#if QT_CONFIG(thread)
138class QDnsLookupThreadPool : public QThreadPool
139{
140 Q_OBJECT
141
142public:
143 QDnsLookupThreadPool();
144 void start(QRunnable *runnable);
145
146private slots:
147 void _q_applicationDestroyed();
148
149private:
150 QMutex signalsMutex;
151 bool signalsConnected;
152};
153#endif // QT_CONFIG(thread)
154
155class QDnsRecordPrivate : public QSharedData
156{
157public:
158 QDnsRecordPrivate()
159 : timeToLive(0)
160 { }
161
162 QString name;
163 quint32 timeToLive;
164};
165
166class QDnsDomainNameRecordPrivate : public QDnsRecordPrivate
167{
168public:
169 QDnsDomainNameRecordPrivate()
170 { }
171
172 QString value;
173};
174
175class QDnsHostAddressRecordPrivate : public QDnsRecordPrivate
176{
177public:
178 QDnsHostAddressRecordPrivate()
179 { }
180
181 QHostAddress value;
182};
183
184class QDnsMailExchangeRecordPrivate : public QDnsRecordPrivate
185{
186public:
187 QDnsMailExchangeRecordPrivate()
188 : preference(0)
189 { }
190
191 QString exchange;
192 quint16 preference;
193};
194
195class QDnsServiceRecordPrivate : public QDnsRecordPrivate
196{
197public:
198 QDnsServiceRecordPrivate()
199 : port(0),
200 priority(0),
201 weight(0)
202 { }
203
204 QString target;
205 quint16 port;
206 quint16 priority;
207 quint16 weight;
208};
209
210class QDnsTextRecordPrivate : public QDnsRecordPrivate
211{
212public:
213 QDnsTextRecordPrivate()
214 { }
215
216 QList<QByteArray> values;
217};
218
219QT_END_NAMESPACE
220
221Q_DECLARE_METATYPE(QDnsLookupReply)
222
223#endif // QDNSLOOKUP_P_H
224

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