kernel/qdnslookup.cpp

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

Generated by Squish Coco Non-Commercial