Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/network/kernel/qdnslookup.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||
2 | ** | - | ||||||||||||
3 | ** Copyright (C) 2012 Jeremy Lainé <jeremy.laine@m4x.org> | - | ||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||
5 | ** | - | ||||||||||||
6 | ** This file is part of the QtNetwork module of the Qt Toolkit. | - | ||||||||||||
7 | ** | - | ||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||
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 http://www.qt.io/terms-conditions. For further | - | ||||||||||||
15 | ** information use the contact form at http://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 2.1 or version 3 as published by the Free | - | ||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||
25 | ** | - | ||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||
29 | ** | - | ||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||
31 | ** | - | ||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||
33 | - | |||||||||||||
34 | #include "qdnslookup.h" | - | ||||||||||||
35 | #include "qdnslookup_p.h" | - | ||||||||||||
36 | - | |||||||||||||
37 | #include <qcoreapplication.h> | - | ||||||||||||
38 | #include <qdatetime.h> | - | ||||||||||||
39 | #include <qthreadstorage.h> | - | ||||||||||||
40 | #include <qurl.h> | - | ||||||||||||
41 | - | |||||||||||||
42 | #include <algorithm> | - | ||||||||||||
43 | - | |||||||||||||
44 | QT_BEGIN_NAMESPACE | - | ||||||||||||
45 | - | |||||||||||||
46 | Q_GLOBAL_STATIC(QDnsLookupThreadPool, theDnsLookupThreadPool); executed 2 times by 2 tests: end of block Executed by:
executed 2 times by 2 tests: guard.store(QtGlobalStatic::Destroyed); Executed by:
executed 101 times by 2 tests: return &holder.value; Executed by:
| 0-101 | ||||||||||||
47 | Q_GLOBAL_STATIC(QThreadStorage<bool *>, theDnsLookupSeedStorage); executed 2 times by 2 tests: end of block Executed by:
executed 2 times by 2 tests: guard.store(QtGlobalStatic::Destroyed); Executed by:
executed 107 times by 2 tests: return &holder.value; Executed by:
| 0-107 | ||||||||||||
48 | - | |||||||||||||
49 | static bool qt_qdnsmailexchangerecord_less_than(const QDnsMailExchangeRecord &r1, const QDnsMailExchangeRecord &r2) | - | ||||||||||||
50 | { | - | ||||||||||||
51 | // Lower numbers are more preferred than higher ones. | - | ||||||||||||
52 | return r1.preference() < r2.preference(); executed 7 times by 1 test: return r1.preference() < r2.preference(); Executed by:
| 7 | ||||||||||||
53 | } | - | ||||||||||||
54 | - | |||||||||||||
55 | /*! | - | ||||||||||||
56 | Sorts a list of QDnsMailExchangeRecord objects according to RFC 5321. | - | ||||||||||||
57 | */ | - | ||||||||||||
58 | - | |||||||||||||
59 | static void qt_qdnsmailexchangerecord_sort(QList<QDnsMailExchangeRecord> &records) | - | ||||||||||||
60 | { | - | ||||||||||||
61 | // If we have no more than one result, we are done. | - | ||||||||||||
62 | if (records.size() <= 1)
| 4-80 | ||||||||||||
63 | return; executed 80 times by 2 tests: return; Executed by:
| 80 | ||||||||||||
64 | - | |||||||||||||
65 | // Order the records by preference. | - | ||||||||||||
66 | std::sort(records.begin(), records.end(), qt_qdnsmailexchangerecord_less_than); | - | ||||||||||||
67 | - | |||||||||||||
68 | int i = 0; | - | ||||||||||||
69 | while (i < records.size()) {
| 4-6 | ||||||||||||
70 | - | |||||||||||||
71 | // Determine the slice of records with the current preference. | - | ||||||||||||
72 | QList<QDnsMailExchangeRecord> slice; | - | ||||||||||||
73 | const quint16 slicePreference = records[i].preference(); | - | ||||||||||||
74 | for (int j = i; j < records.size(); ++j) {
| 4-10 | ||||||||||||
75 | if (records[j].preference() != slicePreference)
| 2-8 | ||||||||||||
76 | break; executed 2 times by 1 test: break; Executed by:
| 2 | ||||||||||||
77 | slice << records[j]; | - | ||||||||||||
78 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||
79 | - | |||||||||||||
80 | // Randomize the slice of records. | - | ||||||||||||
81 | while (!slice.isEmpty()) {
| 6-8 | ||||||||||||
82 | const unsigned int pos = qrand() % slice.size(); | - | ||||||||||||
83 | records[i++] = slice.takeAt(pos); | - | ||||||||||||
84 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||
85 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||
86 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||
87 | - | |||||||||||||
88 | static bool qt_qdnsservicerecord_less_than(const QDnsServiceRecord &r1, const QDnsServiceRecord &r2) | - | ||||||||||||
89 | { | - | ||||||||||||
90 | // Order by priority, or if the priorities are equal, | - | ||||||||||||
91 | // put zero weight records first. | - | ||||||||||||
92 | return r1.priority() < r2.priority() executed 18 times by 1 test: return r1.priority() < r2.priority() || (r1.priority() == r2.priority() && r1.weight() == 0 && r2.weight() > 0); Executed by:
| 4-18 | ||||||||||||
93 | || (r1.priority() == r2.priority() executed 18 times by 1 test: return r1.priority() < r2.priority() || (r1.priority() == r2.priority() && r1.weight() == 0 && r2.weight() > 0); Executed by:
| 7-18 | ||||||||||||
94 | && r1.weight() == 0 && r2.weight() > 0); executed 18 times by 1 test: return r1.priority() < r2.priority() || (r1.priority() == r2.priority() && r1.weight() == 0 && r2.weight() > 0); Executed by:
| 0-18 | ||||||||||||
95 | } | - | ||||||||||||
96 | - | |||||||||||||
97 | /*! | - | ||||||||||||
98 | Sorts a list of QDnsServiceRecord objects according to RFC 2782. | - | ||||||||||||
99 | */ | - | ||||||||||||
100 | - | |||||||||||||
101 | static void qt_qdnsservicerecord_sort(QList<QDnsServiceRecord> &records) | - | ||||||||||||
102 | { | - | ||||||||||||
103 | // If we have no more than one result, we are done. | - | ||||||||||||
104 | if (records.size() <= 1)
| 6-78 | ||||||||||||
105 | return; executed 78 times by 2 tests: return; Executed by:
| 78 | ||||||||||||
106 | - | |||||||||||||
107 | // Order the records by priority, and for records with an equal | - | ||||||||||||
108 | // priority, put records with a zero weight first. | - | ||||||||||||
109 | std::sort(records.begin(), records.end(), qt_qdnsservicerecord_less_than); | - | ||||||||||||
110 | - | |||||||||||||
111 | int i = 0; | - | ||||||||||||
112 | while (i < records.size()) {
| 6-12 | ||||||||||||
113 | - | |||||||||||||
114 | // Determine the slice of records with the current priority. | - | ||||||||||||
115 | QList<QDnsServiceRecord> slice; | - | ||||||||||||
116 | const quint16 slicePriority = records[i].priority(); | - | ||||||||||||
117 | unsigned int sliceWeight = 0; | - | ||||||||||||
118 | for (int j = i; j < records.size(); ++j) {
| 6-22 | ||||||||||||
119 | if (records[j].priority() != slicePriority)
| 6-16 | ||||||||||||
120 | break; executed 6 times by 1 test: break; Executed by:
| 6 | ||||||||||||
121 | sliceWeight += records[j].weight(); | - | ||||||||||||
122 | slice << records[j]; | - | ||||||||||||
123 | } executed 16 times by 1 test: end of block Executed by:
| 16 | ||||||||||||
124 | #ifdef QDNSLOOKUP_DEBUG | - | ||||||||||||
125 | qDebug("qt_qdnsservicerecord_sort() : priority %i (size: %i, total weight: %i)", | - | ||||||||||||
126 | slicePriority, slice.size(), sliceWeight); | - | ||||||||||||
127 | #endif | - | ||||||||||||
128 | - | |||||||||||||
129 | // Order the slice of records. | - | ||||||||||||
130 | while (!slice.isEmpty()) {
| 12-16 | ||||||||||||
131 | const unsigned int weightThreshold = qrand() % (sliceWeight + 1); | - | ||||||||||||
132 | unsigned int summedWeight = 0; | - | ||||||||||||
133 | for (int j = 0; j < slice.size(); ++j) {
| 0-17 | ||||||||||||
134 | summedWeight += slice[j].weight(); | - | ||||||||||||
135 | if (summedWeight >= weightThreshold) {
| 1-16 | ||||||||||||
136 | #ifdef QDNSLOOKUP_DEBUG | - | ||||||||||||
137 | qDebug("qt_qdnsservicerecord_sort() : adding %s %i (weight: %i)", | - | ||||||||||||
138 | qPrintable(slice[j].target()), slice[j].port(), | - | ||||||||||||
139 | slice[j].weight()); | - | ||||||||||||
140 | #endif | - | ||||||||||||
141 | // Adjust the slice weight and take the current record. | - | ||||||||||||
142 | sliceWeight -= slice[j].weight(); | - | ||||||||||||
143 | records[i++] = slice.takeAt(j); | - | ||||||||||||
144 | break; executed 16 times by 1 test: break; Executed by:
| 16 | ||||||||||||
145 | } | - | ||||||||||||
146 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
147 | } executed 16 times by 1 test: end of block Executed by:
| 16 | ||||||||||||
148 | } executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||||||||
149 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||
150 | - | |||||||||||||
151 | const char *QDnsLookupPrivate::msgNoIpV6NameServerAdresses = | - | ||||||||||||
152 | QT_TRANSLATE_NOOP("QDnsLookupRunnable", "IPv6 addresses for nameservers are currently not supported"); | - | ||||||||||||
153 | - | |||||||||||||
154 | /*! | - | ||||||||||||
155 | \class QDnsLookup | - | ||||||||||||
156 | \brief The QDnsLookup class represents a DNS lookup. | - | ||||||||||||
157 | \since 5.0 | - | ||||||||||||
158 | - | |||||||||||||
159 | \inmodule QtNetwork | - | ||||||||||||
160 | \ingroup network | - | ||||||||||||
161 | - | |||||||||||||
162 | QDnsLookup uses the mechanisms provided by the operating system to perform | - | ||||||||||||
163 | DNS lookups. To perform a lookup you need to specify a \l name and \l type | - | ||||||||||||
164 | then invoke the \l{QDnsLookup::lookup()}{lookup()} slot. The | - | ||||||||||||
165 | \l{QDnsLookup::finished()}{finished()} signal will be emitted upon | - | ||||||||||||
166 | completion. | - | ||||||||||||
167 | - | |||||||||||||
168 | For example, you can determine which servers an XMPP chat client should | - | ||||||||||||
169 | connect to for a given domain with: | - | ||||||||||||
170 | - | |||||||||||||
171 | \snippet code/src_network_kernel_qdnslookup.cpp 0 | - | ||||||||||||
172 | - | |||||||||||||
173 | Once the request finishes you can handle the results with: | - | ||||||||||||
174 | - | |||||||||||||
175 | \snippet code/src_network_kernel_qdnslookup.cpp 1 | - | ||||||||||||
176 | - | |||||||||||||
177 | \note If you simply want to find the IP address(es) associated with a host | - | ||||||||||||
178 | name, or the host name associated with an IP address you should use | - | ||||||||||||
179 | QHostInfo instead. | - | ||||||||||||
180 | */ | - | ||||||||||||
181 | - | |||||||||||||
182 | /*! | - | ||||||||||||
183 | \enum QDnsLookup::Error | - | ||||||||||||
184 | - | |||||||||||||
185 | Indicates all possible error conditions found during the | - | ||||||||||||
186 | processing of the DNS lookup. | - | ||||||||||||
187 | - | |||||||||||||
188 | \value NoError no error condition. | - | ||||||||||||
189 | - | |||||||||||||
190 | \value ResolverError there was an error initializing the system's | - | ||||||||||||
191 | DNS resolver. | - | ||||||||||||
192 | - | |||||||||||||
193 | \value OperationCancelledError the lookup was aborted using the abort() | - | ||||||||||||
194 | method. | - | ||||||||||||
195 | - | |||||||||||||
196 | \value InvalidRequestError the requested DNS lookup was invalid. | - | ||||||||||||
197 | - | |||||||||||||
198 | \value InvalidReplyError the reply returned by the server was invalid. | - | ||||||||||||
199 | - | |||||||||||||
200 | \value ServerFailureError the server encountered an internal failure | - | ||||||||||||
201 | while processing the request (SERVFAIL). | - | ||||||||||||
202 | - | |||||||||||||
203 | \value ServerRefusedError the server refused to process the request for | - | ||||||||||||
204 | security or policy reasons (REFUSED). | - | ||||||||||||
205 | - | |||||||||||||
206 | \value NotFoundError the requested domain name does not exist | - | ||||||||||||
207 | (NXDOMAIN). | - | ||||||||||||
208 | */ | - | ||||||||||||
209 | - | |||||||||||||
210 | /*! | - | ||||||||||||
211 | \enum QDnsLookup::Type | - | ||||||||||||
212 | - | |||||||||||||
213 | Indicates the type of DNS lookup that was performed. | - | ||||||||||||
214 | - | |||||||||||||
215 | \value A IPv4 address records. | - | ||||||||||||
216 | - | |||||||||||||
217 | \value AAAA IPv6 address records. | - | ||||||||||||
218 | - | |||||||||||||
219 | \value ANY any records. | - | ||||||||||||
220 | - | |||||||||||||
221 | \value CNAME canonical name records. | - | ||||||||||||
222 | - | |||||||||||||
223 | \value MX mail exchange records. | - | ||||||||||||
224 | - | |||||||||||||
225 | \value NS name server records. | - | ||||||||||||
226 | - | |||||||||||||
227 | \value PTR pointer records. | - | ||||||||||||
228 | - | |||||||||||||
229 | \value SRV service records. | - | ||||||||||||
230 | - | |||||||||||||
231 | \value TXT text records. | - | ||||||||||||
232 | */ | - | ||||||||||||
233 | - | |||||||||||||
234 | /*! | - | ||||||||||||
235 | \fn void QDnsLookup::finished() | - | ||||||||||||
236 | - | |||||||||||||
237 | This signal is emitted when the reply has finished processing. | - | ||||||||||||
238 | */ | - | ||||||||||||
239 | - | |||||||||||||
240 | /*! | - | ||||||||||||
241 | \fn void QDnsLookup::nameChanged(const QString &name) | - | ||||||||||||
242 | - | |||||||||||||
243 | This signal is emitted when the lookup \l name changes. | - | ||||||||||||
244 | \a name is the new lookup name. | - | ||||||||||||
245 | */ | - | ||||||||||||
246 | - | |||||||||||||
247 | /*! | - | ||||||||||||
248 | \fn void QDnsLookup::typeChanged(Type type) | - | ||||||||||||
249 | - | |||||||||||||
250 | This signal is emitted when the lookup \l type changes. | - | ||||||||||||
251 | \a type is the new lookup type. | - | ||||||||||||
252 | */ | - | ||||||||||||
253 | - | |||||||||||||
254 | /*! | - | ||||||||||||
255 | Constructs a QDnsLookup object and sets \a parent as the parent object. | - | ||||||||||||
256 | - | |||||||||||||
257 | The \l type property will default to QDnsLookup::A. | - | ||||||||||||
258 | */ | - | ||||||||||||
259 | - | |||||||||||||
260 | QDnsLookup::QDnsLookup(QObject *parent) | - | ||||||||||||
261 | : QObject(*new QDnsLookupPrivate, parent) | - | ||||||||||||
262 | { | - | ||||||||||||
263 | qRegisterMetaType<QDnsLookupReply>(); | - | ||||||||||||
264 | } executed 76 times by 1 test: end of block Executed by:
| 76 | ||||||||||||
265 | /*! | - | ||||||||||||
266 | Constructs a QDnsLookup object for the given \a type and \a name and sets | - | ||||||||||||
267 | \a parent as the parent object. | - | ||||||||||||
268 | */ | - | ||||||||||||
269 | - | |||||||||||||
270 | QDnsLookup::QDnsLookup(Type type, const QString &name, QObject *parent) | - | ||||||||||||
271 | : QObject(*new QDnsLookupPrivate, parent) | - | ||||||||||||
272 | { | - | ||||||||||||
273 | Q_D(QDnsLookup); | - | ||||||||||||
274 | qRegisterMetaType<QDnsLookupReply>(); | - | ||||||||||||
275 | d->name = name; | - | ||||||||||||
276 | d->type = type; | - | ||||||||||||
277 | } executed 21 times by 1 test: end of block Executed by:
| 21 | ||||||||||||
278 | - | |||||||||||||
279 | /*! | - | ||||||||||||
280 | \fn QDnsLookup::QDnsLookup(Type type, const QString &name, const QHostAddress &nameserver, QObject *parent) | - | ||||||||||||
281 | \since 5.4 | - | ||||||||||||
282 | Constructs a QDnsLookup object for the given \a type, \a name and | - | ||||||||||||
283 | \a nameserver and sets \a parent as the parent object. | - | ||||||||||||
284 | */ | - | ||||||||||||
285 | - | |||||||||||||
286 | QDnsLookup::QDnsLookup(Type type, const QString &name, const QHostAddress &nameserver, QObject *parent) | - | ||||||||||||
287 | : QObject(*new QDnsLookupPrivate, parent) | - | ||||||||||||
288 | { | - | ||||||||||||
289 | Q_D(QDnsLookup); | - | ||||||||||||
290 | qRegisterMetaType<QDnsLookupReply>(); | - | ||||||||||||
291 | d->name = name; | - | ||||||||||||
292 | d->type = type; | - | ||||||||||||
293 | d->nameserver = nameserver; | - | ||||||||||||
294 | } never executed: end of block | 0 | ||||||||||||
295 | - | |||||||||||||
296 | /*! | - | ||||||||||||
297 | Destroys the QDnsLookup object. | - | ||||||||||||
298 | - | |||||||||||||
299 | It is safe to delete a QDnsLookup object even if it is not finished, you | - | ||||||||||||
300 | will simply never receive its results. | - | ||||||||||||
301 | */ | - | ||||||||||||
302 | - | |||||||||||||
303 | QDnsLookup::~QDnsLookup() | - | ||||||||||||
304 | { | - | ||||||||||||
305 | } | - | ||||||||||||
306 | - | |||||||||||||
307 | /*! | - | ||||||||||||
308 | \property QDnsLookup::error | - | ||||||||||||
309 | \brief the type of error that occurred if the DNS lookup failed, or NoError. | - | ||||||||||||
310 | */ | - | ||||||||||||
311 | - | |||||||||||||
312 | QDnsLookup::Error QDnsLookup::error() const | - | ||||||||||||
313 | { | - | ||||||||||||
314 | return d_func()->reply.error; executed 152 times by 1 test: return d_func()->reply.error; Executed by:
| 152 | ||||||||||||
315 | } | - | ||||||||||||
316 | - | |||||||||||||
317 | /*! | - | ||||||||||||
318 | \property QDnsLookup::errorString | - | ||||||||||||
319 | \brief a human-readable description of the error if the DNS lookup failed. | - | ||||||||||||
320 | */ | - | ||||||||||||
321 | - | |||||||||||||
322 | QString QDnsLookup::errorString() const | - | ||||||||||||
323 | { | - | ||||||||||||
324 | return d_func()->reply.errorString; executed 112 times by 1 test: return d_func()->reply.errorString; Executed by:
| 112 | ||||||||||||
325 | } | - | ||||||||||||
326 | - | |||||||||||||
327 | /*! | - | ||||||||||||
328 | Returns whether the reply has finished or was aborted. | - | ||||||||||||
329 | */ | - | ||||||||||||
330 | - | |||||||||||||
331 | bool QDnsLookup::isFinished() const | - | ||||||||||||
332 | { | - | ||||||||||||
333 | return d_func()->isFinished; executed 180 times by 2 tests: return d_func()->isFinished; Executed by:
| 180 | ||||||||||||
334 | } | - | ||||||||||||
335 | - | |||||||||||||
336 | /*! | - | ||||||||||||
337 | \property QDnsLookup::name | - | ||||||||||||
338 | \brief the name to lookup. | - | ||||||||||||
339 | - | |||||||||||||
340 | \note The name will be encoded using IDNA, which means it's unsuitable for | - | ||||||||||||
341 | querying SRV records compatible with the DNS-SD specification. | - | ||||||||||||
342 | */ | - | ||||||||||||
343 | - | |||||||||||||
344 | QString QDnsLookup::name() const | - | ||||||||||||
345 | { | - | ||||||||||||
346 | return d_func()->name; executed 72 times by 1 test: return d_func()->name; Executed by:
| 72 | ||||||||||||
347 | } | - | ||||||||||||
348 | - | |||||||||||||
349 | void QDnsLookup::setName(const QString &name) | - | ||||||||||||
350 | { | - | ||||||||||||
351 | Q_D(QDnsLookup); | - | ||||||||||||
352 | if (name != d->name) {
| 16-64 | ||||||||||||
353 | d->name = name; | - | ||||||||||||
354 | emit nameChanged(name); | - | ||||||||||||
355 | } executed 64 times by 1 test: end of block Executed by:
| 64 | ||||||||||||
356 | } executed 80 times by 1 test: end of block Executed by:
| 80 | ||||||||||||
357 | - | |||||||||||||
358 | /*! | - | ||||||||||||
359 | \property QDnsLookup::type | - | ||||||||||||
360 | \brief the type of DNS lookup. | - | ||||||||||||
361 | */ | - | ||||||||||||
362 | - | |||||||||||||
363 | QDnsLookup::Type QDnsLookup::type() const | - | ||||||||||||
364 | { | - | ||||||||||||
365 | return d_func()->type; executed 72 times by 1 test: return d_func()->type; Executed by:
| 72 | ||||||||||||
366 | } | - | ||||||||||||
367 | - | |||||||||||||
368 | void QDnsLookup::setType(Type type) | - | ||||||||||||
369 | { | - | ||||||||||||
370 | Q_D(QDnsLookup); | - | ||||||||||||
371 | if (type != d->type) {
| 12-68 | ||||||||||||
372 | d->type = type; | - | ||||||||||||
373 | emit typeChanged(type); | - | ||||||||||||
374 | } executed 68 times by 1 test: end of block Executed by:
| 68 | ||||||||||||
375 | } executed 80 times by 1 test: end of block Executed by:
| 80 | ||||||||||||
376 | - | |||||||||||||
377 | /*! | - | ||||||||||||
378 | \property QDnsLookup::nameserver | - | ||||||||||||
379 | \brief the nameserver to use for DNS lookup. | - | ||||||||||||
380 | */ | - | ||||||||||||
381 | - | |||||||||||||
382 | QHostAddress QDnsLookup::nameserver() const | - | ||||||||||||
383 | { | - | ||||||||||||
384 | return d_func()->nameserver; never executed: return d_func()->nameserver; | 0 | ||||||||||||
385 | } | - | ||||||||||||
386 | - | |||||||||||||
387 | void QDnsLookup::setNameserver(const QHostAddress &nameserver) | - | ||||||||||||
388 | { | - | ||||||||||||
389 | Q_D(QDnsLookup); | - | ||||||||||||
390 | if (nameserver != d->nameserver) {
| 0 | ||||||||||||
391 | d->nameserver = nameserver; | - | ||||||||||||
392 | emit nameserverChanged(nameserver); | - | ||||||||||||
393 | } never executed: end of block | 0 | ||||||||||||
394 | } never executed: end of block | 0 | ||||||||||||
395 | - | |||||||||||||
396 | /*! | - | ||||||||||||
397 | Returns the list of canonical name records associated with this lookup. | - | ||||||||||||
398 | */ | - | ||||||||||||
399 | - | |||||||||||||
400 | QList<QDnsDomainNameRecord> QDnsLookup::canonicalNameRecords() const | - | ||||||||||||
401 | { | - | ||||||||||||
402 | return d_func()->reply.canonicalNameRecords; executed 72 times by 1 test: return d_func()->reply.canonicalNameRecords; Executed by:
| 72 | ||||||||||||
403 | } | - | ||||||||||||
404 | - | |||||||||||||
405 | /*! | - | ||||||||||||
406 | Returns the list of host address records associated with this lookup. | - | ||||||||||||
407 | */ | - | ||||||||||||
408 | - | |||||||||||||
409 | QList<QDnsHostAddressRecord> QDnsLookup::hostAddressRecords() const | - | ||||||||||||
410 | { | - | ||||||||||||
411 | return d_func()->reply.hostAddressRecords; executed 92 times by 1 test: return d_func()->reply.hostAddressRecords; Executed by:
| 92 | ||||||||||||
412 | } | - | ||||||||||||
413 | - | |||||||||||||
414 | /*! | - | ||||||||||||
415 | Returns the list of mail exchange records associated with this lookup. | - | ||||||||||||
416 | - | |||||||||||||
417 | The records are sorted according to | - | ||||||||||||
418 | \l{http://www.rfc-editor.org/rfc/rfc5321.txt}{RFC 5321}, so if you use them | - | ||||||||||||
419 | to connect to servers, you should try them in the order they are listed. | - | ||||||||||||
420 | */ | - | ||||||||||||
421 | - | |||||||||||||
422 | QList<QDnsMailExchangeRecord> QDnsLookup::mailExchangeRecords() const | - | ||||||||||||
423 | { | - | ||||||||||||
424 | return d_func()->reply.mailExchangeRecords; executed 72 times by 1 test: return d_func()->reply.mailExchangeRecords; Executed by:
| 72 | ||||||||||||
425 | } | - | ||||||||||||
426 | - | |||||||||||||
427 | /*! | - | ||||||||||||
428 | Returns the list of name server records associated with this lookup. | - | ||||||||||||
429 | */ | - | ||||||||||||
430 | - | |||||||||||||
431 | QList<QDnsDomainNameRecord> QDnsLookup::nameServerRecords() const | - | ||||||||||||
432 | { | - | ||||||||||||
433 | return d_func()->reply.nameServerRecords; executed 72 times by 1 test: return d_func()->reply.nameServerRecords; Executed by:
| 72 | ||||||||||||
434 | } | - | ||||||||||||
435 | - | |||||||||||||
436 | /*! | - | ||||||||||||
437 | Returns the list of pointer records associated with this lookup. | - | ||||||||||||
438 | */ | - | ||||||||||||
439 | - | |||||||||||||
440 | QList<QDnsDomainNameRecord> QDnsLookup::pointerRecords() const | - | ||||||||||||
441 | { | - | ||||||||||||
442 | return d_func()->reply.pointerRecords; executed 72 times by 1 test: return d_func()->reply.pointerRecords; Executed by:
| 72 | ||||||||||||
443 | } | - | ||||||||||||
444 | - | |||||||||||||
445 | /*! | - | ||||||||||||
446 | Returns the list of service records associated with this lookup. | - | ||||||||||||
447 | - | |||||||||||||
448 | The records are sorted according to | - | ||||||||||||
449 | \l{http://www.rfc-editor.org/rfc/rfc2782.txt}{RFC 2782}, so if you use them | - | ||||||||||||
450 | to connect to servers, you should try them in the order they are listed. | - | ||||||||||||
451 | */ | - | ||||||||||||
452 | - | |||||||||||||
453 | QList<QDnsServiceRecord> QDnsLookup::serviceRecords() const | - | ||||||||||||
454 | { | - | ||||||||||||
455 | return d_func()->reply.serviceRecords; executed 72 times by 1 test: return d_func()->reply.serviceRecords; Executed by:
| 72 | ||||||||||||
456 | } | - | ||||||||||||
457 | - | |||||||||||||
458 | /*! | - | ||||||||||||
459 | Returns the list of text records associated with this lookup. | - | ||||||||||||
460 | */ | - | ||||||||||||
461 | - | |||||||||||||
462 | QList<QDnsTextRecord> QDnsLookup::textRecords() const | - | ||||||||||||
463 | { | - | ||||||||||||
464 | return d_func()->reply.textRecords; executed 72 times by 1 test: return d_func()->reply.textRecords; Executed by:
| 72 | ||||||||||||
465 | } | - | ||||||||||||
466 | - | |||||||||||||
467 | /*! | - | ||||||||||||
468 | Aborts the DNS lookup operation. | - | ||||||||||||
469 | - | |||||||||||||
470 | If the lookup is already finished, does nothing. | - | ||||||||||||
471 | */ | - | ||||||||||||
472 | - | |||||||||||||
473 | void QDnsLookup::abort() | - | ||||||||||||
474 | { | - | ||||||||||||
475 | Q_D(QDnsLookup); | - | ||||||||||||
476 | if (d->runnable) {
| 0-2 | ||||||||||||
477 | d->runnable = 0; | - | ||||||||||||
478 | d->reply = QDnsLookupReply(); | - | ||||||||||||
479 | d->reply.error = QDnsLookup::OperationCancelledError; | - | ||||||||||||
480 | d->reply.errorString = tr("Operation cancelled"); | - | ||||||||||||
481 | d->isFinished = true; | - | ||||||||||||
482 | emit finished(); | - | ||||||||||||
483 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
484 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
485 | - | |||||||||||||
486 | /*! | - | ||||||||||||
487 | Performs the DNS lookup. | - | ||||||||||||
488 | - | |||||||||||||
489 | The \l{QDnsLookup::finished()}{finished()} signal is emitted upon completion. | - | ||||||||||||
490 | */ | - | ||||||||||||
491 | - | |||||||||||||
492 | void QDnsLookup::lookup() | - | ||||||||||||
493 | { | - | ||||||||||||
494 | Q_D(QDnsLookup); | - | ||||||||||||
495 | d->isFinished = false; | - | ||||||||||||
496 | d->reply = QDnsLookupReply(); | - | ||||||||||||
497 | d->runnable = new QDnsLookupRunnable(d->type, QUrl::toAce(d->name), d->nameserver); | - | ||||||||||||
498 | connect(d->runnable, SIGNAL(finished(QDnsLookupReply)), | - | ||||||||||||
499 | this, SLOT(_q_lookupFinished(QDnsLookupReply)), | - | ||||||||||||
500 | Qt::BlockingQueuedConnection); | - | ||||||||||||
501 | theDnsLookupThreadPool()->start(d->runnable); | - | ||||||||||||
502 | } executed 101 times by 2 tests: end of block Executed by:
| 101 | ||||||||||||
503 | - | |||||||||||||
504 | /*! | - | ||||||||||||
505 | \class QDnsDomainNameRecord | - | ||||||||||||
506 | \brief The QDnsDomainNameRecord class stores information about a domain | - | ||||||||||||
507 | name record. | - | ||||||||||||
508 | - | |||||||||||||
509 | \inmodule QtNetwork | - | ||||||||||||
510 | \ingroup network | - | ||||||||||||
511 | \ingroup shared | - | ||||||||||||
512 | - | |||||||||||||
513 | When performing a name server lookup, zero or more records will be returned. | - | ||||||||||||
514 | Each record is represented by a QDnsDomainNameRecord instance. | - | ||||||||||||
515 | - | |||||||||||||
516 | \sa QDnsLookup | - | ||||||||||||
517 | */ | - | ||||||||||||
518 | - | |||||||||||||
519 | /*! | - | ||||||||||||
520 | Constructs an empty domain name record object. | - | ||||||||||||
521 | */ | - | ||||||||||||
522 | - | |||||||||||||
523 | QDnsDomainNameRecord::QDnsDomainNameRecord() | - | ||||||||||||
524 | : d(new QDnsDomainNameRecordPrivate) | - | ||||||||||||
525 | { | - | ||||||||||||
526 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||
527 | - | |||||||||||||
528 | /*! | - | ||||||||||||
529 | Constructs a copy of \a other. | - | ||||||||||||
530 | */ | - | ||||||||||||
531 | - | |||||||||||||
532 | QDnsDomainNameRecord::QDnsDomainNameRecord(const QDnsDomainNameRecord &other) | - | ||||||||||||
533 | : d(other.d) | - | ||||||||||||
534 | { | - | ||||||||||||
535 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||
536 | - | |||||||||||||
537 | /*! | - | ||||||||||||
538 | Destroys a domain name record. | - | ||||||||||||
539 | */ | - | ||||||||||||
540 | - | |||||||||||||
541 | QDnsDomainNameRecord::~QDnsDomainNameRecord() | - | ||||||||||||
542 | { | - | ||||||||||||
543 | } | - | ||||||||||||
544 | - | |||||||||||||
545 | /*! | - | ||||||||||||
546 | Returns the name for this record. | - | ||||||||||||
547 | */ | - | ||||||||||||
548 | - | |||||||||||||
549 | QString QDnsDomainNameRecord::name() const | - | ||||||||||||
550 | { | - | ||||||||||||
551 | return d->name; executed 6 times by 1 test: return d->name; Executed by:
| 6 | ||||||||||||
552 | } | - | ||||||||||||
553 | - | |||||||||||||
554 | /*! | - | ||||||||||||
555 | Returns the duration in seconds for which this record is valid. | - | ||||||||||||
556 | */ | - | ||||||||||||
557 | - | |||||||||||||
558 | quint32 QDnsDomainNameRecord::timeToLive() const | - | ||||||||||||
559 | { | - | ||||||||||||
560 | return d->timeToLive; never executed: return d->timeToLive; | 0 | ||||||||||||
561 | } | - | ||||||||||||
562 | - | |||||||||||||
563 | /*! | - | ||||||||||||
564 | Returns the value for this domain name record. | - | ||||||||||||
565 | */ | - | ||||||||||||
566 | - | |||||||||||||
567 | QString QDnsDomainNameRecord::value() const | - | ||||||||||||
568 | { | - | ||||||||||||
569 | return d->value; executed 6 times by 1 test: return d->value; Executed by:
| 6 | ||||||||||||
570 | } | - | ||||||||||||
571 | - | |||||||||||||
572 | /*! | - | ||||||||||||
573 | Assigns the data of the \a other object to this record object, | - | ||||||||||||
574 | and returns a reference to it. | - | ||||||||||||
575 | */ | - | ||||||||||||
576 | - | |||||||||||||
577 | QDnsDomainNameRecord &QDnsDomainNameRecord::operator=(const QDnsDomainNameRecord &other) | - | ||||||||||||
578 | { | - | ||||||||||||
579 | d = other.d; | - | ||||||||||||
580 | return *this; never executed: return *this; | 0 | ||||||||||||
581 | } | - | ||||||||||||
582 | /*! | - | ||||||||||||
583 | \fn void QDnsDomainNameRecord::swap(QDnsDomainNameRecord &other) | - | ||||||||||||
584 | - | |||||||||||||
585 | Swaps this domain-name record instance with \a other. This | - | ||||||||||||
586 | function is very fast and never fails. | - | ||||||||||||
587 | */ | - | ||||||||||||
588 | - | |||||||||||||
589 | /*! | - | ||||||||||||
590 | \class QDnsHostAddressRecord | - | ||||||||||||
591 | \brief The QDnsHostAddressRecord class stores information about a host | - | ||||||||||||
592 | address record. | - | ||||||||||||
593 | - | |||||||||||||
594 | \inmodule QtNetwork | - | ||||||||||||
595 | \ingroup network | - | ||||||||||||
596 | \ingroup shared | - | ||||||||||||
597 | - | |||||||||||||
598 | When performing an address lookup, zero or more records will be | - | ||||||||||||
599 | returned. Each record is represented by a QDnsHostAddressRecord instance. | - | ||||||||||||
600 | - | |||||||||||||
601 | \sa QDnsLookup | - | ||||||||||||
602 | */ | - | ||||||||||||
603 | - | |||||||||||||
604 | /*! | - | ||||||||||||
605 | Constructs an empty host address record object. | - | ||||||||||||
606 | */ | - | ||||||||||||
607 | - | |||||||||||||
608 | QDnsHostAddressRecord::QDnsHostAddressRecord() | - | ||||||||||||
609 | : d(new QDnsHostAddressRecordPrivate) | - | ||||||||||||
610 | { | - | ||||||||||||
611 | } executed 50 times by 2 tests: end of block Executed by:
| 50 | ||||||||||||
612 | - | |||||||||||||
613 | /*! | - | ||||||||||||
614 | Constructs a copy of \a other. | - | ||||||||||||
615 | */ | - | ||||||||||||
616 | - | |||||||||||||
617 | QDnsHostAddressRecord::QDnsHostAddressRecord(const QDnsHostAddressRecord &other) | - | ||||||||||||
618 | : d(other.d) | - | ||||||||||||
619 | { | - | ||||||||||||
620 | } executed 62 times by 2 tests: end of block Executed by:
| 62 | ||||||||||||
621 | - | |||||||||||||
622 | /*! | - | ||||||||||||
623 | Destroys a host address record. | - | ||||||||||||
624 | */ | - | ||||||||||||
625 | - | |||||||||||||
626 | QDnsHostAddressRecord::~QDnsHostAddressRecord() | - | ||||||||||||
627 | { | - | ||||||||||||
628 | } | - | ||||||||||||
629 | - | |||||||||||||
630 | /*! | - | ||||||||||||
631 | Returns the name for this record. | - | ||||||||||||
632 | */ | - | ||||||||||||
633 | - | |||||||||||||
634 | QString QDnsHostAddressRecord::name() const | - | ||||||||||||
635 | { | - | ||||||||||||
636 | return d->name; executed 38 times by 1 test: return d->name; Executed by:
| 38 | ||||||||||||
637 | } | - | ||||||||||||
638 | - | |||||||||||||
639 | /*! | - | ||||||||||||
640 | Returns the duration in seconds for which this record is valid. | - | ||||||||||||
641 | */ | - | ||||||||||||
642 | - | |||||||||||||
643 | quint32 QDnsHostAddressRecord::timeToLive() const | - | ||||||||||||
644 | { | - | ||||||||||||
645 | return d->timeToLive; never executed: return d->timeToLive; | 0 | ||||||||||||
646 | } | - | ||||||||||||
647 | - | |||||||||||||
648 | /*! | - | ||||||||||||
649 | Returns the value for this host address record. | - | ||||||||||||
650 | */ | - | ||||||||||||
651 | - | |||||||||||||
652 | QHostAddress QDnsHostAddressRecord::value() const | - | ||||||||||||
653 | { | - | ||||||||||||
654 | return d->value; executed 38 times by 1 test: return d->value; Executed by:
| 38 | ||||||||||||
655 | } | - | ||||||||||||
656 | - | |||||||||||||
657 | /*! | - | ||||||||||||
658 | Assigns the data of the \a other object to this record object, | - | ||||||||||||
659 | and returns a reference to it. | - | ||||||||||||
660 | */ | - | ||||||||||||
661 | - | |||||||||||||
662 | QDnsHostAddressRecord &QDnsHostAddressRecord::operator=(const QDnsHostAddressRecord &other) | - | ||||||||||||
663 | { | - | ||||||||||||
664 | d = other.d; | - | ||||||||||||
665 | return *this; never executed: return *this; | 0 | ||||||||||||
666 | } | - | ||||||||||||
667 | /*! | - | ||||||||||||
668 | \fn void QDnsHostAddressRecord::swap(QDnsHostAddressRecord &other) | - | ||||||||||||
669 | - | |||||||||||||
670 | Swaps this host address record instance with \a other. This | - | ||||||||||||
671 | function is very fast and never fails. | - | ||||||||||||
672 | */ | - | ||||||||||||
673 | - | |||||||||||||
674 | /*! | - | ||||||||||||
675 | \class QDnsMailExchangeRecord | - | ||||||||||||
676 | \brief The QDnsMailExchangeRecord class stores information about a DNS MX record. | - | ||||||||||||
677 | - | |||||||||||||
678 | \inmodule QtNetwork | - | ||||||||||||
679 | \ingroup network | - | ||||||||||||
680 | \ingroup shared | - | ||||||||||||
681 | - | |||||||||||||
682 | When performing a lookup on a service, zero or more records will be | - | ||||||||||||
683 | returned. Each record is represented by a QDnsMailExchangeRecord instance. | - | ||||||||||||
684 | - | |||||||||||||
685 | The meaning of the fields is defined in | - | ||||||||||||
686 | \l{http://www.rfc-editor.org/rfc/rfc1035.txt}{RFC 1035}. | - | ||||||||||||
687 | - | |||||||||||||
688 | \sa QDnsLookup | - | ||||||||||||
689 | */ | - | ||||||||||||
690 | - | |||||||||||||
691 | /*! | - | ||||||||||||
692 | Constructs an empty mail exchange record object. | - | ||||||||||||
693 | */ | - | ||||||||||||
694 | - | |||||||||||||
695 | QDnsMailExchangeRecord::QDnsMailExchangeRecord() | - | ||||||||||||
696 | : d(new QDnsMailExchangeRecordPrivate) | - | ||||||||||||
697 | { | - | ||||||||||||
698 | } executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||||||||
699 | - | |||||||||||||
700 | /*! | - | ||||||||||||
701 | Constructs a copy of \a other. | - | ||||||||||||
702 | */ | - | ||||||||||||
703 | - | |||||||||||||
704 | QDnsMailExchangeRecord::QDnsMailExchangeRecord(const QDnsMailExchangeRecord &other) | - | ||||||||||||
705 | : d(other.d) | - | ||||||||||||
706 | { | - | ||||||||||||
707 | } executed 32 times by 1 test: end of block Executed by:
| 32 | ||||||||||||
708 | - | |||||||||||||
709 | /*! | - | ||||||||||||
710 | Destroys a mail exchange record. | - | ||||||||||||
711 | */ | - | ||||||||||||
712 | - | |||||||||||||
713 | QDnsMailExchangeRecord::~QDnsMailExchangeRecord() | - | ||||||||||||
714 | { | - | ||||||||||||
715 | } | - | ||||||||||||
716 | - | |||||||||||||
717 | /*! | - | ||||||||||||
718 | Returns the domain name of the mail exchange for this record. | - | ||||||||||||
719 | */ | - | ||||||||||||
720 | - | |||||||||||||
721 | QString QDnsMailExchangeRecord::exchange() const | - | ||||||||||||
722 | { | - | ||||||||||||
723 | return d->exchange; executed 12 times by 1 test: return d->exchange; Executed by:
| 12 | ||||||||||||
724 | } | - | ||||||||||||
725 | - | |||||||||||||
726 | /*! | - | ||||||||||||
727 | Returns the name for this record. | - | ||||||||||||
728 | */ | - | ||||||||||||
729 | - | |||||||||||||
730 | QString QDnsMailExchangeRecord::name() const | - | ||||||||||||
731 | { | - | ||||||||||||
732 | return d->name; executed 12 times by 1 test: return d->name; Executed by:
| 12 | ||||||||||||
733 | } | - | ||||||||||||
734 | - | |||||||||||||
735 | /*! | - | ||||||||||||
736 | Returns the preference for this record. | - | ||||||||||||
737 | */ | - | ||||||||||||
738 | - | |||||||||||||
739 | quint16 QDnsMailExchangeRecord::preference() const | - | ||||||||||||
740 | { | - | ||||||||||||
741 | return d->preference; executed 42 times by 1 test: return d->preference; Executed by:
| 42 | ||||||||||||
742 | } | - | ||||||||||||
743 | - | |||||||||||||
744 | /*! | - | ||||||||||||
745 | Returns the duration in seconds for which this record is valid. | - | ||||||||||||
746 | */ | - | ||||||||||||
747 | - | |||||||||||||
748 | quint32 QDnsMailExchangeRecord::timeToLive() const | - | ||||||||||||
749 | { | - | ||||||||||||
750 | return d->timeToLive; never executed: return d->timeToLive; | 0 | ||||||||||||
751 | } | - | ||||||||||||
752 | - | |||||||||||||
753 | /*! | - | ||||||||||||
754 | Assigns the data of the \a other object to this record object, | - | ||||||||||||
755 | and returns a reference to it. | - | ||||||||||||
756 | */ | - | ||||||||||||
757 | - | |||||||||||||
758 | QDnsMailExchangeRecord &QDnsMailExchangeRecord::operator=(const QDnsMailExchangeRecord &other) | - | ||||||||||||
759 | { | - | ||||||||||||
760 | d = other.d; | - | ||||||||||||
761 | return *this; never executed: return *this; | 0 | ||||||||||||
762 | } | - | ||||||||||||
763 | /*! | - | ||||||||||||
764 | \fn void QDnsMailExchangeRecord::swap(QDnsMailExchangeRecord &other) | - | ||||||||||||
765 | - | |||||||||||||
766 | Swaps this mail exchange record with \a other. This function is | - | ||||||||||||
767 | very fast and never fails. | - | ||||||||||||
768 | */ | - | ||||||||||||
769 | - | |||||||||||||
770 | /*! | - | ||||||||||||
771 | \class QDnsServiceRecord | - | ||||||||||||
772 | \brief The QDnsServiceRecord class stores information about a DNS SRV record. | - | ||||||||||||
773 | - | |||||||||||||
774 | \inmodule QtNetwork | - | ||||||||||||
775 | \ingroup network | - | ||||||||||||
776 | \ingroup shared | - | ||||||||||||
777 | - | |||||||||||||
778 | When performing a lookup on a service, zero or more records will be | - | ||||||||||||
779 | returned. Each record is represented by a QDnsServiceRecord instance. | - | ||||||||||||
780 | - | |||||||||||||
781 | The meaning of the fields is defined in | - | ||||||||||||
782 | \l{http://www.rfc-editor.org/rfc/rfc2782.txt}{RFC 2782}. | - | ||||||||||||
783 | - | |||||||||||||
784 | \sa QDnsLookup | - | ||||||||||||
785 | */ | - | ||||||||||||
786 | - | |||||||||||||
787 | /*! | - | ||||||||||||
788 | Constructs an empty service record object. | - | ||||||||||||
789 | */ | - | ||||||||||||
790 | - | |||||||||||||
791 | QDnsServiceRecord::QDnsServiceRecord() | - | ||||||||||||
792 | : d(new QDnsServiceRecordPrivate) | - | ||||||||||||
793 | { | - | ||||||||||||
794 | } executed 18 times by 1 test: end of block Executed by:
| 18 | ||||||||||||
795 | - | |||||||||||||
796 | /*! | - | ||||||||||||
797 | Constructs a copy of \a other. | - | ||||||||||||
798 | */ | - | ||||||||||||
799 | - | |||||||||||||
800 | QDnsServiceRecord::QDnsServiceRecord(const QDnsServiceRecord &other) | - | ||||||||||||
801 | : d(other.d) | - | ||||||||||||
802 | { | - | ||||||||||||
803 | } executed 60 times by 1 test: end of block Executed by:
| 60 | ||||||||||||
804 | - | |||||||||||||
805 | /*! | - | ||||||||||||
806 | Destroys a service record. | - | ||||||||||||
807 | */ | - | ||||||||||||
808 | - | |||||||||||||
809 | QDnsServiceRecord::~QDnsServiceRecord() | - | ||||||||||||
810 | { | - | ||||||||||||
811 | } | - | ||||||||||||
812 | - | |||||||||||||
813 | /*! | - | ||||||||||||
814 | Returns the name for this record. | - | ||||||||||||
815 | */ | - | ||||||||||||
816 | - | |||||||||||||
817 | QString QDnsServiceRecord::name() const | - | ||||||||||||
818 | { | - | ||||||||||||
819 | return d->name; executed 18 times by 1 test: return d->name; Executed by:
| 18 | ||||||||||||
820 | } | - | ||||||||||||
821 | - | |||||||||||||
822 | /*! | - | ||||||||||||
823 | Returns the port on the target host for this service record. | - | ||||||||||||
824 | */ | - | ||||||||||||
825 | - | |||||||||||||
826 | quint16 QDnsServiceRecord::port() const | - | ||||||||||||
827 | { | - | ||||||||||||
828 | return d->port; executed 18 times by 1 test: return d->port; Executed by:
| 18 | ||||||||||||
829 | } | - | ||||||||||||
830 | - | |||||||||||||
831 | /*! | - | ||||||||||||
832 | Returns the priority for this service record. | - | ||||||||||||
833 | - | |||||||||||||
834 | A client must attempt to contact the target host with the lowest-numbered | - | ||||||||||||
835 | priority. | - | ||||||||||||
836 | */ | - | ||||||||||||
837 | - | |||||||||||||
838 | quint16 QDnsServiceRecord::priority() const | - | ||||||||||||
839 | { | - | ||||||||||||
840 | return d->priority; executed 116 times by 1 test: return d->priority; Executed by:
| 116 | ||||||||||||
841 | } | - | ||||||||||||
842 | - | |||||||||||||
843 | /*! | - | ||||||||||||
844 | Returns the domain name of the target host for this service record. | - | ||||||||||||
845 | */ | - | ||||||||||||
846 | - | |||||||||||||
847 | QString QDnsServiceRecord::target() const | - | ||||||||||||
848 | { | - | ||||||||||||
849 | return d->target; executed 18 times by 1 test: return d->target; Executed by:
| 18 | ||||||||||||
850 | } | - | ||||||||||||
851 | - | |||||||||||||
852 | /*! | - | ||||||||||||
853 | Returns the duration in seconds for which this record is valid. | - | ||||||||||||
854 | */ | - | ||||||||||||
855 | - | |||||||||||||
856 | quint32 QDnsServiceRecord::timeToLive() const | - | ||||||||||||
857 | { | - | ||||||||||||
858 | return d->timeToLive; never executed: return d->timeToLive; | 0 | ||||||||||||
859 | } | - | ||||||||||||
860 | - | |||||||||||||
861 | /*! | - | ||||||||||||
862 | Returns the weight for this service record. | - | ||||||||||||
863 | - | |||||||||||||
864 | The weight field specifies a relative weight for entries with the same | - | ||||||||||||
865 | priority. Entries with higher weights should be selected with a higher | - | ||||||||||||
866 | probability. | - | ||||||||||||
867 | */ | - | ||||||||||||
868 | - | |||||||||||||
869 | quint16 QDnsServiceRecord::weight() const | - | ||||||||||||
870 | { | - | ||||||||||||
871 | return d->weight; executed 74 times by 1 test: return d->weight; Executed by:
| 74 | ||||||||||||
872 | } | - | ||||||||||||
873 | - | |||||||||||||
874 | /*! | - | ||||||||||||
875 | Assigns the data of the \a other object to this record object, | - | ||||||||||||
876 | and returns a reference to it. | - | ||||||||||||
877 | */ | - | ||||||||||||
878 | - | |||||||||||||
879 | QDnsServiceRecord &QDnsServiceRecord::operator=(const QDnsServiceRecord &other) | - | ||||||||||||
880 | { | - | ||||||||||||
881 | d = other.d; | - | ||||||||||||
882 | return *this; never executed: return *this; | 0 | ||||||||||||
883 | } | - | ||||||||||||
884 | /*! | - | ||||||||||||
885 | \fn void QDnsServiceRecord::swap(QDnsServiceRecord &other) | - | ||||||||||||
886 | - | |||||||||||||
887 | Swaps this service record instance with \a other. This function is | - | ||||||||||||
888 | very fast and never fails. | - | ||||||||||||
889 | */ | - | ||||||||||||
890 | - | |||||||||||||
891 | /*! | - | ||||||||||||
892 | \class QDnsTextRecord | - | ||||||||||||
893 | \brief The QDnsTextRecord class stores information about a DNS TXT record. | - | ||||||||||||
894 | - | |||||||||||||
895 | \inmodule QtNetwork | - | ||||||||||||
896 | \ingroup network | - | ||||||||||||
897 | \ingroup shared | - | ||||||||||||
898 | - | |||||||||||||
899 | When performing a text lookup, zero or more records will be | - | ||||||||||||
900 | returned. Each record is represented by a QDnsTextRecord instance. | - | ||||||||||||
901 | - | |||||||||||||
902 | The meaning of the fields is defined in | - | ||||||||||||
903 | \l{http://www.rfc-editor.org/rfc/rfc1035.txt}{RFC 1035}. | - | ||||||||||||
904 | - | |||||||||||||
905 | \sa QDnsLookup | - | ||||||||||||
906 | */ | - | ||||||||||||
907 | - | |||||||||||||
908 | /*! | - | ||||||||||||
909 | Constructs an empty text record object. | - | ||||||||||||
910 | */ | - | ||||||||||||
911 | - | |||||||||||||
912 | QDnsTextRecord::QDnsTextRecord() | - | ||||||||||||
913 | : d(new QDnsTextRecordPrivate) | - | ||||||||||||
914 | { | - | ||||||||||||
915 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||
916 | - | |||||||||||||
917 | /*! | - | ||||||||||||
918 | Constructs a copy of \a other. | - | ||||||||||||
919 | */ | - | ||||||||||||
920 | - | |||||||||||||
921 | QDnsTextRecord::QDnsTextRecord(const QDnsTextRecord &other) | - | ||||||||||||
922 | : d(other.d) | - | ||||||||||||
923 | { | - | ||||||||||||
924 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||
925 | - | |||||||||||||
926 | /*! | - | ||||||||||||
927 | Destroys a text record. | - | ||||||||||||
928 | */ | - | ||||||||||||
929 | - | |||||||||||||
930 | QDnsTextRecord::~QDnsTextRecord() | - | ||||||||||||
931 | { | - | ||||||||||||
932 | } | - | ||||||||||||
933 | - | |||||||||||||
934 | /*! | - | ||||||||||||
935 | Returns the name for this text record. | - | ||||||||||||
936 | */ | - | ||||||||||||
937 | - | |||||||||||||
938 | QString QDnsTextRecord::name() const | - | ||||||||||||
939 | { | - | ||||||||||||
940 | return d->name; executed 8 times by 1 test: return d->name; Executed by:
| 8 | ||||||||||||
941 | } | - | ||||||||||||
942 | - | |||||||||||||
943 | /*! | - | ||||||||||||
944 | Returns the duration in seconds for which this record is valid. | - | ||||||||||||
945 | */ | - | ||||||||||||
946 | - | |||||||||||||
947 | quint32 QDnsTextRecord::timeToLive() const | - | ||||||||||||
948 | { | - | ||||||||||||
949 | return d->timeToLive; never executed: return d->timeToLive; | 0 | ||||||||||||
950 | } | - | ||||||||||||
951 | - | |||||||||||||
952 | /*! | - | ||||||||||||
953 | Returns the values for this text record. | - | ||||||||||||
954 | */ | - | ||||||||||||
955 | - | |||||||||||||
956 | QList<QByteArray> QDnsTextRecord::values() const | - | ||||||||||||
957 | { | - | ||||||||||||
958 | return d->values; executed 8 times by 1 test: return d->values; Executed by:
| 8 | ||||||||||||
959 | } | - | ||||||||||||
960 | - | |||||||||||||
961 | /*! | - | ||||||||||||
962 | Assigns the data of the \a other object to this record object, | - | ||||||||||||
963 | and returns a reference to it. | - | ||||||||||||
964 | */ | - | ||||||||||||
965 | - | |||||||||||||
966 | QDnsTextRecord &QDnsTextRecord::operator=(const QDnsTextRecord &other) | - | ||||||||||||
967 | { | - | ||||||||||||
968 | d = other.d; | - | ||||||||||||
969 | return *this; never executed: return *this; | 0 | ||||||||||||
970 | } | - | ||||||||||||
971 | /*! | - | ||||||||||||
972 | \fn void QDnsTextRecord::swap(QDnsTextRecord &other) | - | ||||||||||||
973 | - | |||||||||||||
974 | Swaps this text record instance with \a other. This function is | - | ||||||||||||
975 | very fast and never fails. | - | ||||||||||||
976 | */ | - | ||||||||||||
977 | - | |||||||||||||
978 | void QDnsLookupPrivate::_q_lookupFinished(const QDnsLookupReply &_reply) | - | ||||||||||||
979 | { | - | ||||||||||||
980 | Q_Q(QDnsLookup); | - | ||||||||||||
981 | if (runnable == q->sender()) {
| 2-88 | ||||||||||||
982 | #ifdef QDNSLOOKUP_DEBUG | - | ||||||||||||
983 | qDebug("DNS reply for %s: %i (%s)", qPrintable(name), _reply.error, qPrintable(_reply.errorString)); | - | ||||||||||||
984 | #endif | - | ||||||||||||
985 | reply = _reply; | - | ||||||||||||
986 | runnable = 0; | - | ||||||||||||
987 | isFinished = true; | - | ||||||||||||
988 | emit q->finished(); | - | ||||||||||||
989 | } executed 88 times by 2 tests: end of block Executed by:
| 88 | ||||||||||||
990 | } executed 90 times by 2 tests: end of block Executed by:
| 90 | ||||||||||||
991 | - | |||||||||||||
992 | void QDnsLookupRunnable::run() | - | ||||||||||||
993 | { | - | ||||||||||||
994 | QDnsLookupReply reply; | - | ||||||||||||
995 | - | |||||||||||||
996 | // Validate input. | - | ||||||||||||
997 | if (requestName.isEmpty()) {
| 16-84 | ||||||||||||
998 | reply.error = QDnsLookup::InvalidRequestError; | - | ||||||||||||
999 | reply.errorString = tr("Invalid domain name"); | - | ||||||||||||
1000 | emit finished(reply); | - | ||||||||||||
1001 | return; executed 16 times by 1 test: return; Executed by:
| 16 | ||||||||||||
1002 | } | - | ||||||||||||
1003 | - | |||||||||||||
1004 | // Perform request. | - | ||||||||||||
1005 | query(requestType, requestName, nameserver, &reply); | - | ||||||||||||
1006 | - | |||||||||||||
1007 | // Sort results. | - | ||||||||||||
1008 | if (!theDnsLookupSeedStorage()->hasLocalData()) {
| 23-61 | ||||||||||||
1009 | qsrand(QTime(0,0,0).msecsTo(QTime::currentTime()) ^ reinterpret_cast<quintptr>(this)); | - | ||||||||||||
1010 | theDnsLookupSeedStorage()->setLocalData(new bool(true)); | - | ||||||||||||
1011 | } executed 23 times by 2 tests: end of block Executed by:
| 23 | ||||||||||||
1012 | qt_qdnsmailexchangerecord_sort(reply.mailExchangeRecords); | - | ||||||||||||
1013 | qt_qdnsservicerecord_sort(reply.serviceRecords); | - | ||||||||||||
1014 | - | |||||||||||||
1015 | emit finished(reply); | - | ||||||||||||
1016 | } executed 84 times by 2 tests: end of block Executed by:
| 84 | ||||||||||||
1017 | - | |||||||||||||
1018 | QDnsLookupThreadPool::QDnsLookupThreadPool() | - | ||||||||||||
1019 | : signalsConnected(false) | - | ||||||||||||
1020 | { | - | ||||||||||||
1021 | // Run up to 5 lookups in parallel. | - | ||||||||||||
1022 | setMaxThreadCount(5); | - | ||||||||||||
1023 | } executed 2 times by 2 tests: end of block Executed by:
| 2 | ||||||||||||
1024 | - | |||||||||||||
1025 | void QDnsLookupThreadPool::start(QRunnable *runnable) | - | ||||||||||||
1026 | { | - | ||||||||||||
1027 | // Ensure threads complete at application destruction. | - | ||||||||||||
1028 | if (!signalsConnected) {
| 22-79 | ||||||||||||
1029 | QMutexLocker signalsLocker(&signalsMutex); | - | ||||||||||||
1030 | if (!signalsConnected) {
| 0-22 | ||||||||||||
1031 | QCoreApplication *app = QCoreApplication::instance(); | - | ||||||||||||
1032 | if (!app) {
| 1-21 | ||||||||||||
1033 | qWarning("QDnsLookup requires a QCoreApplication"); | - | ||||||||||||
1034 | delete runnable; | - | ||||||||||||
1035 | return; executed 1 time by 1 test: return; Executed by:
| 1 | ||||||||||||
1036 | } | - | ||||||||||||
1037 | - | |||||||||||||
1038 | moveToThread(app->thread()); | - | ||||||||||||
1039 | connect(app, SIGNAL(destroyed()), | - | ||||||||||||
1040 | SLOT(_q_applicationDestroyed()), Qt::DirectConnection); | - | ||||||||||||
1041 | signalsConnected = true; | - | ||||||||||||
1042 | } executed 21 times by 2 tests: end of block Executed by:
| 21 | ||||||||||||
1043 | } executed 21 times by 2 tests: end of block Executed by:
| 21 | ||||||||||||
1044 | - | |||||||||||||
1045 | QThreadPool::start(runnable); | - | ||||||||||||
1046 | } executed 100 times by 2 tests: end of block Executed by:
| 100 | ||||||||||||
1047 | - | |||||||||||||
1048 | void QDnsLookupThreadPool::_q_applicationDestroyed() | - | ||||||||||||
1049 | { | - | ||||||||||||
1050 | waitForDone(); | - | ||||||||||||
1051 | signalsConnected = false; | - | ||||||||||||
1052 | } executed 21 times by 2 tests: end of block Executed by:
| 21 | ||||||||||||
1053 | - | |||||||||||||
1054 | QT_END_NAMESPACE | - | ||||||||||||
1055 | - | |||||||||||||
1056 | #include "moc_qdnslookup.cpp" | - | ||||||||||||
Source code | Switch to Preprocessed file |