kernel/qdnslookup.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7static QDnsLookupThreadPool *theDnsLookupThreadPool() { static QGlobalStatic<QDnsLookupThreadPool > thisGlobalStatic = { { (0) }, false }; if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) { QDnsLookupThreadPool *x = new QDnsLookupThreadPool; if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x)) delete x; else static QGlobalStaticDeleter<QDnsLookupThreadPool > cleanup(thisGlobalStatic); } return thisGlobalStatic.pointer.load(); };
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
8static QThreadStorage<bool *> *theDnsLookupSeedStorage() { static QGlobalStatic<QThreadStorage<bool *> > thisGlobalStatic = { { (0) }, false }; if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) { QThreadStorage<bool *> *x = new QThreadStorage<bool *>; if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x)) delete x; else static QGlobalStaticDeleter<QThreadStorage<bool *> > cleanup(thisGlobalStatic); } return thisGlobalStatic.pointer.load(); };
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
never executed: delete x;
executed: return thisGlobalStatic.pointer.load();
Execution Count:63
0-63
9 -
10static bool qt_qdnsmailexchangerecord_less_than(const QDnsMailExchangeRecord &r1, const QDnsMailExchangeRecord &r2) -
11{ -
12 -
13 return r1.preference() < r2.preference();
never executed: return r1.preference() < r2.preference();
0
14} -
15 -
16 -
17 -
18 -
19 -
20static void qt_qdnsmailexchangerecord_sort(QList<QDnsMailExchangeRecord> &records) -
21{ -
22 -
23 if (records.size() <= 1)
partially evaluated: records.size() <= 1
TRUEFALSE
yes
Evaluation Count:41
no
Evaluation Count:0
0-41
24 return;
executed: return;
Execution Count:41
41
25 -
26 -
27 std::sort(records.begin(), records.end(), qt_qdnsmailexchangerecord_less_than); -
28 -
29 int i = 0; -
30 while (i < records.size()) {
never evaluated: i < records.size()
0
31 -
32 -
33 QList<QDnsMailExchangeRecord> slice; -
34 const quint16 slicePreference = records[i].preference(); -
35 for (int j = i; j < records.size(); ++j) {
never evaluated: j < records.size()
0
36 if (records[j].preference() != slicePreference)
never evaluated: records[j].preference() != slicePreference
0
37 break;
never executed: break;
0
38 slice << records[j]; -
39 }
never executed: }
0
40 -
41 -
42 while (!slice.isEmpty()) {
never evaluated: !slice.isEmpty()
0
43 const unsigned int pos = qrand() % slice.size(); -
44 records[i++] = slice.takeAt(pos); -
45 }
never executed: }
0
46 }
never executed: }
0
47}
never executed: }
0
48 -
49static bool qt_qdnsservicerecord_less_than(const QDnsServiceRecord &r1, const QDnsServiceRecord &r2) -
50{ -
51 -
52 -
53 return r1.priority() < r2.priority() 0
54 || (r1.priority() == r2.priority() 0
55 && r1.weight() == 0 && r2.weight() > 0);
never executed: return r1.priority() < r2.priority() || (r1.priority() == r2.priority() && r1.weight() == 0 && r2.weight() > 0);
0
56} -
57 -
58 -
59 -
60 -
61 -
62static void qt_qdnsservicerecord_sort(QList<QDnsServiceRecord> &records) -
63{ -
64 -
65 if (records.size() <= 1)
partially evaluated: records.size() <= 1
TRUEFALSE
yes
Evaluation Count:41
no
Evaluation Count:0
0-41
66 return;
executed: return;
Execution Count:41
41
67 -
68 -
69 -
70 std::sort(records.begin(), records.end(), qt_qdnsservicerecord_less_than); -
71 -
72 int i = 0; -
73 while (i < records.size()) {
never evaluated: i < records.size()
0
74 -
75 -
76 QList<QDnsServiceRecord> slice; -
77 const quint16 slicePriority = records[i].priority(); -
78 unsigned int sliceWeight = 0; -
79 for (int j = i; j < records.size(); ++j) {
never evaluated: j < records.size()
0
80 if (records[j].priority() != slicePriority)
never evaluated: records[j].priority() != slicePriority
0
81 break;
never executed: break;
0
82 sliceWeight += records[j].weight(); -
83 slice << records[j]; -
84 }
never executed: }
0
85 -
86 -
87 -
88 -
89 -
90 -
91 while (!slice.isEmpty()) {
never evaluated: !slice.isEmpty()
0
92 const unsigned int weightThreshold = qrand() % (sliceWeight + 1); -
93 unsigned int summedWeight = 0; -
94 for (int j = 0; j < slice.size(); ++j) {
never evaluated: j < slice.size()
0
95 summedWeight += slice[j].weight(); -
96 if (summedWeight >= weightThreshold) {
never evaluated: summedWeight >= weightThreshold
0
97 -
98 -
99 -
100 -
101 -
102 -
103 sliceWeight -= slice[j].weight(); -
104 records[i++] = slice.takeAt(j); -
105 break;
never executed: break;
0
106 } -
107 }
never executed: }
0
108 }
never executed: }
0
109 }
never executed: }
0
110}
never executed: }
0
111QDnsLookup::QDnsLookup(QObject *parent) -
112 : QObject(*new QDnsLookupPrivate, parent) -
113{ -
114 qRegisterMetaType<QDnsLookupReply>(); -
115}
executed: }
Execution Count:28
28
116 -
117 -
118 -
119 -
120 -
121QDnsLookup::QDnsLookup(Type type, const QString &name, QObject *parent) -
122 : QObject(*new QDnsLookupPrivate, parent) -
123{ -
124 QDnsLookupPrivate * const d = d_func(); -
125 qRegisterMetaType<QDnsLookupReply>(); -
126 d->name = name; -
127 d->type = type; -
128}
executed: }
Execution Count:21
21
129QDnsLookup::~QDnsLookup() -
130{ -
131} -
132 -
133 -
134 -
135 -
136 -
137 -
138QDnsLookup::Error QDnsLookup::error() const -
139{ -
140 return d_func()->reply.error;
executed: return d_func()->reply.error;
Execution Count:29
29
141} -
142 -
143 -
144 -
145 -
146 -
147 -
148QString QDnsLookup::errorString() const -
149{ -
150 return d_func()->reply.errorString;
executed: return d_func()->reply.errorString;
Execution Count:30
30
151} -
152 -
153 -
154 -
155 -
156 -
157bool QDnsLookup::isFinished() const -
158{ -
159 return d_func()->isFinished;
executed: return d_func()->isFinished;
Execution Count:78
78
160} -
161QString QDnsLookup::name() const -
162{ -
163 return d_func()->name;
executed: return d_func()->name;
Execution Count:20
20
164} -
165 -
166void QDnsLookup::setName(const QString &name) -
167{ -
168 QDnsLookupPrivate * const d = d_func(); -
169 if (name != d->name) {
evaluated: name != d->name
TRUEFALSE
yes
Evaluation Count:21
yes
Evaluation Count:8
8-21
170 d->name = name; -
171 nameChanged(name); -
172 }
executed: }
Execution Count:21
21
173}
executed: }
Execution Count:29
29
174 -
175 -
176 -
177 -
178 -
179 -
180QDnsLookup::Type QDnsLookup::type() const -
181{ -
182 return d_func()->type;
executed: return d_func()->type;
Execution Count:20
20
183} -
184 -
185void QDnsLookup::setType(Type type) -
186{ -
187 QDnsLookupPrivate * const d = d_func(); -
188 if (type != d->type) {
evaluated: type != d->type
TRUEFALSE
yes
Evaluation Count:22
yes
Evaluation Count:7
7-22
189 d->type = type; -
190 typeChanged(type); -
191 }
executed: }
Execution Count:22
22
192}
executed: }
Execution Count:29
29
193 -
194 -
195 -
196 -
197 -
198QList<QDnsDomainNameRecord> QDnsLookup::canonicalNameRecords() const -
199{ -
200 return d_func()->reply.canonicalNameRecords;
executed: return d_func()->reply.canonicalNameRecords;
Execution Count:20
20
201} -
202 -
203 -
204 -
205 -
206 -
207QList<QDnsHostAddressRecord> QDnsLookup::hostAddressRecords() const -
208{ -
209 return d_func()->reply.hostAddressRecords;
executed: return d_func()->reply.hostAddressRecords;
Execution Count:21
21
210} -
211QList<QDnsMailExchangeRecord> QDnsLookup::mailExchangeRecords() const -
212{ -
213 return d_func()->reply.mailExchangeRecords;
executed: return d_func()->reply.mailExchangeRecords;
Execution Count:20
20
214} -
215 -
216 -
217 -
218 -
219 -
220QList<QDnsDomainNameRecord> QDnsLookup::nameServerRecords() const -
221{ -
222 return d_func()->reply.nameServerRecords;
executed: return d_func()->reply.nameServerRecords;
Execution Count:19
19
223} -
224 -
225 -
226 -
227 -
228 -
229QList<QDnsDomainNameRecord> QDnsLookup::pointerRecords() const -
230{ -
231 return d_func()->reply.pointerRecords;
executed: return d_func()->reply.pointerRecords;
Execution Count:19
19
232} -
233QList<QDnsServiceRecord> QDnsLookup::serviceRecords() const -
234{ -
235 return d_func()->reply.serviceRecords;
executed: return d_func()->reply.serviceRecords;
Execution Count:18
18
236} -
237 -
238 -
239 -
240 -
241 -
242QList<QDnsTextRecord> QDnsLookup::textRecords() const -
243{ -
244 return d_func()->reply.textRecords;
executed: return d_func()->reply.textRecords;
Execution Count:19
19
245} -
246 -
247 -
248 -
249 -
250 -
251 -
252 -
253void QDnsLookup::abort() -
254{ -
255 QDnsLookupPrivate * const d = d_func(); -
256 if (d->runnable) {
partially evaluated: d->runnable
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
257 d->runnable = 0; -
258 d->reply = QDnsLookupReply(); -
259 d->reply.error = QDnsLookup::OperationCancelledError; -
260 d->reply.errorString = tr("Operation cancelled"); -
261 d->isFinished = true; -
262 finished(); -
263 }
executed: }
Execution Count:1
1
264}
executed: }
Execution Count:1
1
265 -
266 -
267 -
268 -
269 -
270 -
271 -
272void QDnsLookup::lookup() -
273{ -
274 QDnsLookupPrivate * const d = d_func(); -
275 d->isFinished = false; -
276 d->reply = QDnsLookupReply(); -
277 d->runnable = new QDnsLookupRunnable(d->type, QUrl::toAce(d->name)); -
278 connect(d->runnable, "2""finished(QDnsLookupReply)", -
279 this, "1""_q_lookupFinished(QDnsLookupReply)", -
280 Qt::BlockingQueuedConnection); -
281 theDnsLookupThreadPool()->start(d->runnable); -
282}
executed: }
Execution Count:50
50
283QDnsDomainNameRecord::QDnsDomainNameRecord() -
284 : d(new QDnsDomainNameRecordPrivate) -
285{ -
286}
executed: }
Execution Count:3
3
287 -
288 -
289 -
290 -
291 -
292QDnsDomainNameRecord::QDnsDomainNameRecord(const QDnsDomainNameRecord &other) -
293 : d(other.d) -
294{ -
295}
executed: }
Execution Count:5
5
296 -
297 -
298 -
299 -
300 -
301QDnsDomainNameRecord::~QDnsDomainNameRecord() -
302{ -
303} -
304 -
305 -
306 -
307 -
308 -
309QString QDnsDomainNameRecord::name() const -
310{ -
311 return d->name;
executed: return d->name;
Execution Count:3
3
312} -
313 -
314 -
315 -
316 -
317 -
318quint32 QDnsDomainNameRecord::timeToLive() const -
319{ -
320 return d->timeToLive;
never executed: return d->timeToLive;
0
321} -
322 -
323 -
324 -
325 -
326 -
327QString QDnsDomainNameRecord::value() const -
328{ -
329 return d->value;
executed: return d->value;
Execution Count:3
3
330} -
331 -
332 -
333 -
334 -
335 -
336 -
337QDnsDomainNameRecord &QDnsDomainNameRecord::operator=(const QDnsDomainNameRecord &other) -
338{ -
339 d = other.d; -
340 return *this;
never executed: return *this;
0
341} -
342QDnsHostAddressRecord::QDnsHostAddressRecord() -
343 : d(new QDnsHostAddressRecordPrivate) -
344{ -
345}
never executed: }
0
346 -
347 -
348 -
349 -
350 -
351QDnsHostAddressRecord::QDnsHostAddressRecord(const QDnsHostAddressRecord &other) -
352 : d(other.d) -
353{ -
354}
never executed: }
0
355 -
356 -
357 -
358 -
359 -
360QDnsHostAddressRecord::~QDnsHostAddressRecord() -
361{ -
362} -
363 -
364 -
365 -
366 -
367 -
368QString QDnsHostAddressRecord::name() const -
369{ -
370 return d->name;
never executed: return d->name;
0
371} -
372 -
373 -
374 -
375 -
376 -
377quint32 QDnsHostAddressRecord::timeToLive() const -
378{ -
379 return d->timeToLive;
never executed: return d->timeToLive;
0
380} -
381 -
382 -
383 -
384 -
385 -
386QHostAddress QDnsHostAddressRecord::value() const -
387{ -
388 return d->value;
never executed: return d->value;
0
389} -
390 -
391 -
392 -
393 -
394 -
395 -
396QDnsHostAddressRecord &QDnsHostAddressRecord::operator=(const QDnsHostAddressRecord &other) -
397{ -
398 d = other.d; -
399 return *this;
never executed: return *this;
0
400} -
401QDnsMailExchangeRecord::QDnsMailExchangeRecord() -
402 : d(new QDnsMailExchangeRecordPrivate) -
403{ -
404}
executed: }
Execution Count:1
1
405 -
406 -
407 -
408 -
409 -
410QDnsMailExchangeRecord::QDnsMailExchangeRecord(const QDnsMailExchangeRecord &other) -
411 : d(other.d) -
412{ -
413}
executed: }
Execution Count:1
1
414 -
415 -
416 -
417 -
418 -
419QDnsMailExchangeRecord::~QDnsMailExchangeRecord() -
420{ -
421} -
422 -
423 -
424 -
425 -
426 -
427QString QDnsMailExchangeRecord::exchange() const -
428{ -
429 return d->exchange;
executed: return d->exchange;
Execution Count:1
1
430} -
431 -
432 -
433 -
434 -
435 -
436QString QDnsMailExchangeRecord::name() const -
437{ -
438 return d->name;
executed: return d->name;
Execution Count:1
1
439} -
440 -
441 -
442 -
443 -
444 -
445quint16 QDnsMailExchangeRecord::preference() const -
446{ -
447 return d->preference;
executed: return d->preference;
Execution Count:1
1
448} -
449 -
450 -
451 -
452 -
453 -
454quint32 QDnsMailExchangeRecord::timeToLive() const -
455{ -
456 return d->timeToLive;
never executed: return d->timeToLive;
0
457} -
458 -
459 -
460 -
461 -
462 -
463 -
464QDnsMailExchangeRecord &QDnsMailExchangeRecord::operator=(const QDnsMailExchangeRecord &other) -
465{ -
466 d = other.d; -
467 return *this;
never executed: return *this;
0
468} -
469QDnsServiceRecord::QDnsServiceRecord() -
470 : d(new QDnsServiceRecordPrivate) -
471{ -
472}
never executed: }
0
473 -
474 -
475 -
476 -
477 -
478QDnsServiceRecord::QDnsServiceRecord(const QDnsServiceRecord &other) -
479 : d(other.d) -
480{ -
481}
never executed: }
0
482 -
483 -
484 -
485 -
486 -
487QDnsServiceRecord::~QDnsServiceRecord() -
488{ -
489} -
490 -
491 -
492 -
493 -
494 -
495QString QDnsServiceRecord::name() const -
496{ -
497 return d->name;
never executed: return d->name;
0
498} -
499 -
500 -
501 -
502 -
503 -
504quint16 QDnsServiceRecord::port() const -
505{ -
506 return d->port;
never executed: return d->port;
0
507} -
508quint16 QDnsServiceRecord::priority() const -
509{ -
510 return d->priority;
never executed: return d->priority;
0
511} -
512 -
513 -
514 -
515 -
516 -
517QString QDnsServiceRecord::target() const -
518{ -
519 return d->target;
never executed: return d->target;
0
520} -
521 -
522 -
523 -
524 -
525 -
526quint32 QDnsServiceRecord::timeToLive() const -
527{ -
528 return d->timeToLive;
never executed: return d->timeToLive;
0
529} -
530quint16 QDnsServiceRecord::weight() const -
531{ -
532 return d->weight;
never executed: return d->weight;
0
533} -
534 -
535 -
536 -
537 -
538 -
539 -
540QDnsServiceRecord &QDnsServiceRecord::operator=(const QDnsServiceRecord &other) -
541{ -
542 d = other.d; -
543 return *this;
never executed: return *this;
0
544} -
545QDnsTextRecord::QDnsTextRecord() -
546 : d(new QDnsTextRecordPrivate) -
547{ -
548}
executed: }
Execution Count:1
1
549 -
550 -
551 -
552 -
553 -
554QDnsTextRecord::QDnsTextRecord(const QDnsTextRecord &other) -
555 : d(other.d) -
556{ -
557}
executed: }
Execution Count:3
3
558 -
559 -
560 -
561 -
562 -
563QDnsTextRecord::~QDnsTextRecord() -
564{ -
565} -
566 -
567 -
568 -
569 -
570 -
571QString QDnsTextRecord::name() const -
572{ -
573 return d->name;
executed: return d->name;
Execution Count:1
1
574} -
575 -
576 -
577 -
578 -
579 -
580quint32 QDnsTextRecord::timeToLive() const -
581{ -
582 return d->timeToLive;
never executed: return d->timeToLive;
0
583} -
584 -
585 -
586 -
587 -
588 -
589QList<QByteArray> QDnsTextRecord::values() const -
590{ -
591 return d->values;
executed: return d->values;
Execution Count:2
2
592} -
593 -
594 -
595 -
596 -
597 -
598 -
599QDnsTextRecord &QDnsTextRecord::operator=(const QDnsTextRecord &other) -
600{ -
601 d = other.d; -
602 return *this;
never executed: return *this;
0
603} -
604 -
605 -
606 -
607 -
608 -
609 -
610 -
611void QDnsLookupPrivate::_q_lookupFinished(const QDnsLookupReply &_reply) -
612{ -
613 QDnsLookup * const q = q_func(); -
614 if (runnable == q->sender()) {
evaluated: runnable == q->sender()
TRUEFALSE
yes
Evaluation Count:38
yes
Evaluation Count:1
1-38
615 -
616 -
617 -
618 reply = _reply; -
619 runnable = 0; -
620 isFinished = true; -
621 q->finished(); -
622 }
executed: }
Execution Count:38
38
623}
executed: }
Execution Count:39
39
624 -
625void QDnsLookupRunnable::run() -
626{ -
627 QDnsLookupReply reply; -
628 -
629 -
630 if (requestName.isEmpty()) {
evaluated: requestName.isEmpty()
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:41
8-41
631 reply.error = QDnsLookup::InvalidRequestError; -
632 reply.errorString = tr("Invalid domain name"); -
633 finished(reply); -
634 return;
executed: return;
Execution Count:8
8
635 } -
636 -
637 -
638 query(requestType, requestName, &reply); -
639 -
640 -
641 if (!theDnsLookupSeedStorage()->hasLocalData()) {
evaluated: !theDnsLookupSeedStorage()->hasLocalData()
TRUEFALSE
yes
Evaluation Count:22
yes
Evaluation Count:19
19-22
642 qsrand(QTime(0,0,0).msecsTo(QTime::currentTime()) ^ reinterpret_cast<quintptr>(this)); -
643 theDnsLookupSeedStorage()->setLocalData(new bool(true)); -
644 }
executed: }
Execution Count:22
22
645 qt_qdnsmailexchangerecord_sort(reply.mailExchangeRecords); -
646 qt_qdnsservicerecord_sort(reply.serviceRecords); -
647 -
648 finished(reply); -
649}
executed: }
Execution Count:41
41
650 -
651QDnsLookupThreadPool::QDnsLookupThreadPool() -
652 : signalsConnected(false) -
653{ -
654 -
655 setMaxThreadCount(5); -
656}
executed: }
Execution Count:2
2
657 -
658void QDnsLookupThreadPool::start(QRunnable *runnable) -
659{ -
660 -
661 if (!signalsConnected) {
evaluated: !signalsConnected
TRUEFALSE
yes
Evaluation Count:22
yes
Evaluation Count:28
22-28
662 QMutexLocker signalsLocker(&signalsMutex); -
663 if (!signalsConnected) {
partially evaluated: !signalsConnected
TRUEFALSE
yes
Evaluation Count:22
no
Evaluation Count:0
0-22
664 QCoreApplication *app = QCoreApplication::instance(); -
665 if (!app) {
evaluated: !app
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:21
1-21
666 QMessageLogger("kernel/qdnslookup.cpp", 1002, __PRETTY_FUNCTION__).warning("QDnsLookup requires a QCoreApplication"); -
667 delete runnable; -
668 return;
executed: return;
Execution Count:1
1
669 } -
670 -
671 moveToThread(app->thread()); -
672 connect(app, "2""destroyed()", -
673 "1""_q_applicationDestroyed()", Qt::DirectConnection); -
674 signalsConnected = true; -
675 }
executed: }
Execution Count:21
21
676 }
executed: }
Execution Count:21
21
677 -
678 QThreadPool::start(runnable); -
679}
executed: }
Execution Count:49
49
680 -
681void QDnsLookupThreadPool::_q_applicationDestroyed() -
682{ -
683 waitForDone(); -
684 signalsConnected = false; -
685}
executed: }
Execution Count:21
21
686 -
687 -
688 -
689 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial