qdnslookup_unix.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/network/kernel/qdnslookup_unix.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2012 Jeremy Lainé <jeremy.laine@m4x.org>-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtNetwork module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qdnslookup_p.h"-
41-
42#include <qlibrary.h>-
43#include <qscopedpointer.h>-
44#include <qurl.h>-
45#include <private/qnativesocketengine_p.h>-
46-
47#include <sys/types.h>-
48#include <netinet/in.h>-
49#include <arpa/nameser.h>-
50#if !defined(Q_OS_OPENBSD)-
51# include <arpa/nameser_compat.h>-
52#endif-
53#include <resolv.h>-
54-
55#if defined(__GNU_LIBRARY__) && !defined(__UCLIBC__)-
56# include <gnu/lib-names.h>-
57#endif-
58-
59QT_BEGIN_NAMESPACE-
60-
61#ifndef QT_NO_LIBRARY-
62-
63#if defined(Q_OS_OPENBSD)-
64typedef struct __res_state* res_state;-
65#endif-
66typedef int (*dn_expand_proto)(const unsigned char *, const unsigned char *, const unsigned char *, char *, int);-
67static dn_expand_proto local_dn_expand = 0;-
68typedef void (*res_nclose_proto)(res_state);-
69static res_nclose_proto local_res_nclose = 0;-
70typedef int (*res_ninit_proto)(res_state);-
71static res_ninit_proto local_res_ninit = 0;-
72typedef int (*res_nquery_proto)(res_state, const char *, int, int, unsigned char *, int);-
73static res_nquery_proto local_res_nquery = 0;-
74-
75// Custom deleter to close resolver state.-
76-
77struct QDnsLookupStateDeleter-
78{-
79 static inline void cleanup(struct __res_state *pointer)-
80 {-
81 local_res_nclose(pointer);-
82 }
executed 84 times by 2 tests: end of block
Executed by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
84
83};-
84-
85static bool resolveLibraryInternal()-
86{-
87 QLibrary lib;-
88#ifdef LIBRESOLV_SO-
89 lib.setFileName(QStringLiteral(LIBRESOLV_SO));
executed 2 times by 2 tests: return qstring_literal_temp;
Executed by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
2
90 if (!lib.load())
!lib.load()Description
TRUEnever evaluated
FALSEevaluated 2 times by 2 tests
Evaluated by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
0-2
91#endif-
92 {-
93 lib.setFileName(QLatin1String("resolv"));-
94 if (!lib.load())
!lib.load()Description
TRUEnever evaluated
FALSEnever evaluated
0
95 return false;
never executed: return false;
0
96 }
never executed: end of block
0
97-
98 local_dn_expand = dn_expand_proto(lib.resolve("__dn_expand"));-
99 if (!local_dn_expand)
!local_dn_expandDescription
TRUEnever evaluated
FALSEevaluated 2 times by 2 tests
Evaluated by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
0-2
100 local_dn_expand = dn_expand_proto(lib.resolve("dn_expand"));
never executed: local_dn_expand = dn_expand_proto(lib.resolve("dn_expand"));
0
101-
102 local_res_nclose = res_nclose_proto(lib.resolve("__res_nclose"));-
103 if (!local_res_nclose)
!local_res_ncloseDescription
TRUEnever evaluated
FALSEevaluated 2 times by 2 tests
Evaluated by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
0-2
104 local_res_nclose = res_nclose_proto(lib.resolve("res_9_nclose"));
never executed: local_res_nclose = res_nclose_proto(lib.resolve("res_9_nclose"));
0
105 if (!local_res_nclose)
!local_res_ncloseDescription
TRUEnever evaluated
FALSEevaluated 2 times by 2 tests
Evaluated by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
0-2
106 local_res_nclose = res_nclose_proto(lib.resolve("res_nclose"));
never executed: local_res_nclose = res_nclose_proto(lib.resolve("res_nclose"));
0
107-
108 local_res_ninit = res_ninit_proto(lib.resolve("__res_ninit"));-
109 if (!local_res_ninit)
!local_res_ninitDescription
TRUEnever evaluated
FALSEevaluated 2 times by 2 tests
Evaluated by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
0-2
110 local_res_ninit = res_ninit_proto(lib.resolve("res_9_ninit"));
never executed: local_res_ninit = res_ninit_proto(lib.resolve("res_9_ninit"));
0
111 if (!local_res_ninit)
!local_res_ninitDescription
TRUEnever evaluated
FALSEevaluated 2 times by 2 tests
Evaluated by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
0-2
112 local_res_ninit = res_ninit_proto(lib.resolve("res_ninit"));
never executed: local_res_ninit = res_ninit_proto(lib.resolve("res_ninit"));
0
113-
114 local_res_nquery = res_nquery_proto(lib.resolve("__res_nquery"));-
115 if (!local_res_nquery)
!local_res_nqueryDescription
TRUEnever evaluated
FALSEevaluated 2 times by 2 tests
Evaluated by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
0-2
116 local_res_nquery = res_nquery_proto(lib.resolve("res_9_nquery"));
never executed: local_res_nquery = res_nquery_proto(lib.resolve("res_9_nquery"));
0
117 if (!local_res_nquery)
!local_res_nqueryDescription
TRUEnever evaluated
FALSEevaluated 2 times by 2 tests
Evaluated by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
0-2
118 local_res_nquery = res_nquery_proto(lib.resolve("res_nquery"));
never executed: local_res_nquery = res_nquery_proto(lib.resolve("res_nquery"));
0
119-
120 return true;
executed 2 times by 2 tests: return true;
Executed by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
2
121}-
122Q_GLOBAL_STATIC_WITH_ARGS(bool, resolveLibrary, (resolveLibraryInternal()))
executed 2 times by 2 tests: end of block
Executed by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
executed 2 times by 2 tests: guard.store(QtGlobalStatic::Destroyed);
Executed by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
executed 84 times by 2 tests: return &holder.value;
Executed by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
guard.load() =...c::InitializedDescription
TRUEevaluated 2 times by 2 tests
Evaluated by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
FALSEnever evaluated
0-84
123-
124void QDnsLookupRunnable::query(const int requestType, const QByteArray &requestName, const QHostAddress &nameserver, QDnsLookupReply *reply)-
125{-
126 // Load dn_expand, res_ninit and res_nquery on demand.-
127 resolveLibrary();-
128-
129 // If dn_expand, res_ninit or res_nquery is missing, fail.-
130 if (!local_dn_expand || !local_res_nclose || !local_res_ninit || !local_res_nquery) {
!local_dn_expandDescription
TRUEnever evaluated
FALSEevaluated 84 times by 2 tests
Evaluated by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
!local_res_ncloseDescription
TRUEnever evaluated
FALSEevaluated 84 times by 2 tests
Evaluated by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
!local_res_ninitDescription
TRUEnever evaluated
FALSEevaluated 84 times by 2 tests
Evaluated by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
!local_res_nqueryDescription
TRUEnever evaluated
FALSEevaluated 84 times by 2 tests
Evaluated by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
0-84
131 reply->error = QDnsLookup::ResolverError;-
132 reply->errorString = tr("Resolver functions not found");-
133 return;
never executed: return;
0
134 }-
135-
136 // Initialize state.-
137 struct __res_state state;-
138 memset(&state, 0, sizeof(state));-
139 if (local_res_ninit(&state) < 0) {
local_res_ninit(&state) < 0Description
TRUEnever evaluated
FALSEevaluated 84 times by 2 tests
Evaluated by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
0-84
140 reply->error = QDnsLookup::ResolverError;-
141 reply->errorString = tr("Resolver initialization failed");-
142 return;
never executed: return;
0
143 }-
144-
145 //Check if a nameserver was set. If so, use it-
146 if (!nameserver.isNull()) {
!nameserver.isNull()Description
TRUEnever evaluated
FALSEevaluated 84 times by 2 tests
Evaluated by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
0-84
147 if (nameserver.protocol() == QAbstractSocket::IPv4Protocol) {
nameserver.pro...::IPv4ProtocolDescription
TRUEnever evaluated
FALSEnever evaluated
0
148 state.nsaddr_list[0].sin_addr.s_addr = htonl(nameserver.toIPv4Address());-
149 state.nscount = 1;-
150 } else if (nameserver.protocol() == QAbstractSocket::IPv6Protocol) {
never executed: end of block
nameserver.pro...::IPv6ProtocolDescription
TRUEnever evaluated
FALSEnever evaluated
0
151#if defined(Q_OS_LINUX)-
152 struct sockaddr_in6 *ns;-
153 ns = state._u._ext.nsaddrs[0];-
154 // nsaddrs will be NULL if no nameserver is set in /etc/resolv.conf-
155 if (!ns) {
!nsDescription
TRUEnever evaluated
FALSEnever evaluated
0
156 // Memory allocated here will be free'd in res_close() as we-
157 // have done res_init() above.-
158 ns = (struct sockaddr_in6*) calloc(1, sizeof(struct sockaddr_in6));-
159 Q_CHECK_PTR(ns);
never executed: qt_check_pointer(__FILE__,159);
!(ns)Description
TRUEnever evaluated
FALSEnever evaluated
0
160 state._u._ext.nsaddrs[0] = ns;-
161 }
never executed: end of block
0
162#ifndef __UCLIBC__-
163 // Set nsmap[] to indicate that nsaddrs[0] is an IPv6 address-
164 // See: https://sourceware.org/ml/libc-hacker/2002-05/msg00035.html-
165 state._u._ext.nsmap[0] = MAXNS + 1;-
166#endif-
167 state._u._ext.nscount6 = 1;-
168 ns->sin6_family = AF_INET6;-
169 ns->sin6_port = htons(53);-
170 SetSALen::set(ns, sizeof(*ns));-
171-
172 Q_IPV6ADDR ipv6Address = nameserver.toIPv6Address();-
173 for (int i=0; i<16; i++) {
i<16Description
TRUEnever evaluated
FALSEnever evaluated
0
174 ns->sin6_addr.s6_addr[i] = ipv6Address[i];-
175 }
never executed: end of block
0
176#else-
177 qWarning("%s", QDnsLookupPrivate::msgNoIpV6NameServerAdresses);-
178 reply->error = QDnsLookup::ResolverError;-
179 reply->errorString = tr(QDnsLookupPrivate::msgNoIpV6NameServerAdresses);-
180 return;-
181#endif-
182 }
never executed: end of block
0
183 }
never executed: end of block
0
184#ifdef QDNSLOOKUP_DEBUG-
185 state.options |= RES_DEBUG;-
186#endif-
187 QScopedPointer<struct __res_state, QDnsLookupStateDeleter> state_ptr(&state);-
188-
189 // Perform DNS query.-
190 unsigned char response[PACKETSZ];-
191 memset(response, 0, sizeof(response));-
192 const int responseLength = local_res_nquery(&state, requestName, C_IN, requestType, response, sizeof(response));-
193-
194 // Check the response header.-
195 HEADER *header = (HEADER*)response;-
196 const int answerCount = ntohs(header->ancount);-
197 switch (header->rcode) {-
198 case NOERROR:
executed 58 times by 2 tests: case ns_r_noerror:
Executed by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
58
199 break;
executed 58 times by 2 tests: break;
Executed by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
58
200 case FORMERR:
never executed: case ns_r_formerr:
0
201 reply->error = QDnsLookup::InvalidRequestError;-
202 reply->errorString = tr("Server could not process query");-
203 return;
never executed: return;
0
204 case SERVFAIL:
never executed: case ns_r_servfail:
0
205 reply->error = QDnsLookup::ServerFailureError;-
206 reply->errorString = tr("Server failure");-
207 return;
never executed: return;
0
208 case NXDOMAIN:
executed 26 times by 2 tests: case ns_r_nxdomain:
Executed by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
26
209 reply->error = QDnsLookup::NotFoundError;-
210 reply->errorString = tr("Non existent domain");-
211 return;
executed 26 times by 2 tests: return;
Executed by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
26
212 case REFUSED:
never executed: case ns_r_refused:
0
213 reply->error = QDnsLookup::ServerRefusedError;-
214 reply->errorString = tr("Server refused to answer");-
215 return;
never executed: return;
0
216 default:
never executed: default:
0
217 reply->error = QDnsLookup::InvalidReplyError;-
218 reply->errorString = tr("Invalid reply received");-
219 return;
never executed: return;
0
220 }-
221-
222 // Check the reply is valid.-
223 if (responseLength < int(sizeof(HEADER))) {
responseLength...izeof(HEADER))Description
TRUEnever evaluated
FALSEevaluated 58 times by 2 tests
Evaluated by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
0-58
224 reply->error = QDnsLookup::InvalidReplyError;-
225 reply->errorString = tr("Invalid reply received");-
226 return;
never executed: return;
0
227 }-
228-
229 // Skip the query host, type (2 bytes) and class (2 bytes).-
230 char host[PACKETSZ], answer[PACKETSZ];-
231 unsigned char *p = response + sizeof(HEADER);-
232 int status = local_dn_expand(response, response + responseLength, p, host, sizeof(host));-
233 if (status < 0) {
status < 0Description
TRUEnever evaluated
FALSEevaluated 58 times by 2 tests
Evaluated by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
0-58
234 reply->error = QDnsLookup::InvalidReplyError;-
235 reply->errorString = tr("Could not expand domain name");-
236 return;
never executed: return;
0
237 }-
238 p += status + 4;-
239-
240 // Extract results.-
241 int answerIndex = 0;-
242 while ((p < response + responseLength) && (answerIndex < answerCount)) {
(p < response ...esponseLength)Description
TRUEevaluated 100 times by 2 tests
Evaluated by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
FALSEevaluated 52 times by 2 tests
Evaluated by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
(answerIndex < answerCount)Description
TRUEevaluated 94 times by 2 tests
Evaluated by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
FALSEevaluated 6 times by 1 test
Evaluated by:
  • tst_qdnslookup - unknown status
6-100
243 status = local_dn_expand(response, response + responseLength, p, host, sizeof(host));-
244 if (status < 0) {
status < 0Description
TRUEnever evaluated
FALSEevaluated 94 times by 2 tests
Evaluated by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
0-94
245 reply->error = QDnsLookup::InvalidReplyError;-
246 reply->errorString = tr("Could not expand domain name");-
247 return;
never executed: return;
0
248 }-
249 const QString name = QUrl::fromAce(host);-
250-
251 p += status;-
252 const quint16 type = (p[0] << 8) | p[1];-
253 p += 2; // RR type-
254 p += 2; // RR class-
255 const quint32 ttl = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];-
256 p += 4;-
257 const quint16 size = (p[0] << 8) | p[1];-
258 p += 2;-
259-
260 if (type == QDnsLookup::A) {
type == QDnsLookup::ADescription
TRUEevaluated 32 times by 2 tests
Evaluated by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
FALSEevaluated 62 times by 1 test
Evaluated by:
  • tst_qdnslookup - unknown status
32-62
261 if (size != 4) {
size != 4Description
TRUEnever evaluated
FALSEevaluated 32 times by 2 tests
Evaluated by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
0-32
262 reply->error = QDnsLookup::InvalidReplyError;-
263 reply->errorString = tr("Invalid IPv4 address record");-
264 return;
never executed: return;
0
265 }-
266 const quint32 addr = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];-
267 QDnsHostAddressRecord record;-
268 record.d->name = name;-
269 record.d->timeToLive = ttl;-
270 record.d->value = QHostAddress(addr);-
271 reply->hostAddressRecords.append(record);-
272 } else if (type == QDnsLookup::AAAA) {
executed 32 times by 2 tests: end of block
Executed by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
type == QDnsLookup::AAAADescription
TRUEevaluated 18 times by 1 test
Evaluated by:
  • tst_qdnslookup - unknown status
FALSEevaluated 44 times by 1 test
Evaluated by:
  • tst_qdnslookup - unknown status
18-44
273 if (size != 16) {
size != 16Description
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • tst_qdnslookup - unknown status
0-18
274 reply->error = QDnsLookup::InvalidReplyError;-
275 reply->errorString = tr("Invalid IPv6 address record");-
276 return;
never executed: return;
0
277 }-
278 QDnsHostAddressRecord record;-
279 record.d->name = name;-
280 record.d->timeToLive = ttl;-
281 record.d->value = QHostAddress(p);-
282 reply->hostAddressRecords.append(record);-
283 } else if (type == QDnsLookup::CNAME) {
executed 18 times by 1 test: end of block
Executed by:
  • tst_qdnslookup - unknown status
type == QDnsLookup::CNAMEDescription
TRUEnever evaluated
FALSEevaluated 44 times by 1 test
Evaluated by:
  • tst_qdnslookup - unknown status
0-44
284 status = local_dn_expand(response, response + responseLength, p, answer, sizeof(answer));-
285 if (status < 0) {
status < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
286 reply->error = QDnsLookup::InvalidReplyError;-
287 reply->errorString = tr("Invalid canonical name record");-
288 return;
never executed: return;
0
289 }-
290 QDnsDomainNameRecord record;-
291 record.d->name = name;-
292 record.d->timeToLive = ttl;-
293 record.d->value = QUrl::fromAce(answer);-
294 reply->canonicalNameRecords.append(record);-
295 } else if (type == QDnsLookup::NS) {
never executed: end of block
type == QDnsLookup::NSDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • tst_qdnslookup - unknown status
FALSEevaluated 38 times by 1 test
Evaluated by:
  • tst_qdnslookup - unknown status
0-38
296 status = local_dn_expand(response, response + responseLength, p, answer, sizeof(answer));-
297 if (status < 0) {
status < 0Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • tst_qdnslookup - unknown status
0-6
298 reply->error = QDnsLookup::InvalidReplyError;-
299 reply->errorString = tr("Invalid name server record");-
300 return;
never executed: return;
0
301 }-
302 QDnsDomainNameRecord record;-
303 record.d->name = name;-
304 record.d->timeToLive = ttl;-
305 record.d->value = QUrl::fromAce(answer);-
306 reply->nameServerRecords.append(record);-
307 } else if (type == QDnsLookup::PTR) {
executed 6 times by 1 test: end of block
Executed by:
  • tst_qdnslookup - unknown status
type == QDnsLookup::PTRDescription
TRUEnever evaluated
FALSEevaluated 38 times by 1 test
Evaluated by:
  • tst_qdnslookup - unknown status
0-38
308 status = local_dn_expand(response, response + responseLength, p, answer, sizeof(answer));-
309 if (status < 0) {
status < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
310 reply->error = QDnsLookup::InvalidReplyError;-
311 reply->errorString = tr("Invalid pointer record");-
312 return;
never executed: return;
0
313 }-
314 QDnsDomainNameRecord record;-
315 record.d->name = name;-
316 record.d->timeToLive = ttl;-
317 record.d->value = QUrl::fromAce(answer);-
318 reply->pointerRecords.append(record);-
319 } else if (type == QDnsLookup::MX) {
never executed: end of block
type == QDnsLookup::MXDescription
TRUEevaluated 12 times by 1 test
Evaluated by:
  • tst_qdnslookup - unknown status
FALSEevaluated 26 times by 1 test
Evaluated by:
  • tst_qdnslookup - unknown status
0-26
320 const quint16 preference = (p[0] << 8) | p[1];-
321 status = local_dn_expand(response, response + responseLength, p + 2, answer, sizeof(answer));-
322 if (status < 0) {
status < 0Description
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • tst_qdnslookup - unknown status
0-12
323 reply->error = QDnsLookup::InvalidReplyError;-
324 reply->errorString = tr("Invalid mail exchange record");-
325 return;
never executed: return;
0
326 }-
327 QDnsMailExchangeRecord record;-
328 record.d->exchange = QUrl::fromAce(answer);-
329 record.d->name = name;-
330 record.d->preference = preference;-
331 record.d->timeToLive = ttl;-
332 reply->mailExchangeRecords.append(record);-
333 } else if (type == QDnsLookup::SRV) {
executed 12 times by 1 test: end of block
Executed by:
  • tst_qdnslookup - unknown status
type == QDnsLookup::SRVDescription
TRUEevaluated 18 times by 1 test
Evaluated by:
  • tst_qdnslookup - unknown status
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_qdnslookup - unknown status
8-18
334 const quint16 priority = (p[0] << 8) | p[1];-
335 const quint16 weight = (p[2] << 8) | p[3];-
336 const quint16 port = (p[4] << 8) | p[5];-
337 status = local_dn_expand(response, response + responseLength, p + 6, answer, sizeof(answer));-
338 if (status < 0) {
status < 0Description
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • tst_qdnslookup - unknown status
0-18
339 reply->error = QDnsLookup::InvalidReplyError;-
340 reply->errorString = tr("Invalid service record");-
341 return;
never executed: return;
0
342 }-
343 QDnsServiceRecord record;-
344 record.d->name = name;-
345 record.d->target = QUrl::fromAce(answer);-
346 record.d->port = port;-
347 record.d->priority = priority;-
348 record.d->timeToLive = ttl;-
349 record.d->weight = weight;-
350 reply->serviceRecords.append(record);-
351 } else if (type == QDnsLookup::TXT) {
executed 18 times by 1 test: end of block
Executed by:
  • tst_qdnslookup - unknown status
type == QDnsLookup::TXTDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • tst_qdnslookup - unknown status
FALSEnever evaluated
0-18
352 unsigned char *txt = p;-
353 QDnsTextRecord record;-
354 record.d->name = name;-
355 record.d->timeToLive = ttl;-
356 while (txt < p + size) {
txt < p + sizeDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • tst_qdnslookup - unknown status
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_qdnslookup - unknown status
8-10
357 const unsigned char length = *txt;-
358 txt++;-
359 if (txt + length > p + size) {
txt + length > p + sizeDescription
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • tst_qdnslookup - unknown status
0-10
360 reply->error = QDnsLookup::InvalidReplyError;-
361 reply->errorString = tr("Invalid text record");-
362 return;
never executed: return;
0
363 }-
364 record.d->values << QByteArray((char*)txt, length);-
365 txt += length;-
366 }
executed 10 times by 1 test: end of block
Executed by:
  • tst_qdnslookup - unknown status
10
367 reply->textRecords.append(record);-
368 }
executed 8 times by 1 test: end of block
Executed by:
  • tst_qdnslookup - unknown status
8
369 p += size;-
370 answerIndex++;-
371 }
executed 94 times by 2 tests: end of block
Executed by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
94
372}
executed 58 times by 2 tests: end of block
Executed by:
  • tst_qdnslookup - unknown status
  • tst_qdnslookup_appless - unknown status
58
373-
374#else-
375void QDnsLookupRunnable::query(const int requestType, const QByteArray &requestName, const QHostAddress &nameserver, QDnsLookupReply *reply)-
376{-
377 Q_UNUSED(requestType)-
378 Q_UNUSED(requestName)-
379 Q_UNUSED(nameserver)-
380 reply->error = QDnsLookup::ResolverError;-
381 reply->errorString = tr("Resolver library can't be loaded: No runtime library loading support");-
382 return;-
383}-
384-
385#endif /* ifndef QT_NO_LIBRARY */-
386-
387QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9