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