| 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: 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 | - | |||||||||||||||||||||||||
| 59 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
| 60 | - | |||||||||||||||||||||||||
| 61 | #ifndef QT_NO_LIBRARY | - | ||||||||||||||||||||||||
| 62 | - | |||||||||||||||||||||||||
| 63 | #if defined(Q_OS_OPENBSD) | - | ||||||||||||||||||||||||
| 64 | typedef struct __res_state* res_state; | - | ||||||||||||||||||||||||
| 65 | #endif | - | ||||||||||||||||||||||||
| 66 | typedef int (*dn_expand_proto)(const unsigned char *, const unsigned char *, const unsigned char *, char *, int); | - | ||||||||||||||||||||||||
| 67 | static dn_expand_proto local_dn_expand = 0; | - | ||||||||||||||||||||||||
| 68 | typedef void (*res_nclose_proto)(res_state); | - | ||||||||||||||||||||||||
| 69 | static res_nclose_proto local_res_nclose = 0; | - | ||||||||||||||||||||||||
| 70 | typedef int (*res_ninit_proto)(res_state); | - | ||||||||||||||||||||||||
| 71 | static res_ninit_proto local_res_ninit = 0; | - | ||||||||||||||||||||||||
| 72 | typedef int (*res_nquery_proto)(res_state, const char *, int, int, unsigned char *, int); | - | ||||||||||||||||||||||||
| 73 | static res_nquery_proto local_res_nquery = 0; | - | ||||||||||||||||||||||||
| 74 | - | |||||||||||||||||||||||||
| 75 | // Custom deleter to close resolver state. | - | ||||||||||||||||||||||||
| 76 | - | |||||||||||||||||||||||||
| 77 | struct QDnsLookupStateDeleter | - | ||||||||||||||||||||||||
| 78 | { | - | ||||||||||||||||||||||||
| 79 | static inline void cleanup(struct __res_state *pointer) | - | ||||||||||||||||||||||||
| 80 | { | - | ||||||||||||||||||||||||
| 81 | local_res_nclose(pointer); | - | ||||||||||||||||||||||||
| 82 | } | - | ||||||||||||||||||||||||
| 83 | }; | - | ||||||||||||||||||||||||
| 84 | - | |||||||||||||||||||||||||
| 85 | static bool resolveLibraryInternal() | - | ||||||||||||||||||||||||
| 86 | { | - | ||||||||||||||||||||||||
| 87 | QLibrary lib; | - | ||||||||||||||||||||||||
| 88 | #ifdef LIBRESOLV_SO | - | ||||||||||||||||||||||||
| 89 | lib.setFileName(QStringLiteral(LIBRESOLV_SO)); | - | ||||||||||||||||||||||||
| 90 | if (!lib.load()) | - | ||||||||||||||||||||||||
| 91 | #endif | - | ||||||||||||||||||||||||
| 92 | { | - | ||||||||||||||||||||||||
| 93 | lib.setFileName(QLatin1String("resolv")); | - | ||||||||||||||||||||||||
| 94 | if (!lib.load()) | - | ||||||||||||||||||||||||
| 95 | return false; | - | ||||||||||||||||||||||||
| 96 | } | - | ||||||||||||||||||||||||
| 97 | - | |||||||||||||||||||||||||
| 98 | local_dn_expand = dn_expand_proto(lib.resolve("__dn_expand")); | - | ||||||||||||||||||||||||
| 99 | if (!local_dn_expand) | - | ||||||||||||||||||||||||
| 100 | local_dn_expand = dn_expand_proto(lib.resolve("dn_expand")); | - | ||||||||||||||||||||||||
| 101 | - | |||||||||||||||||||||||||
| 102 | local_res_nclose = res_nclose_proto(lib.resolve("__res_nclose")); | - | ||||||||||||||||||||||||
| 103 | if (!local_res_nclose) | - | ||||||||||||||||||||||||
| 104 | local_res_nclose = res_nclose_proto(lib.resolve("res_9_nclose")); | - | ||||||||||||||||||||||||
| 105 | if (!local_res_nclose) | - | ||||||||||||||||||||||||
| 106 | local_res_nclose = res_nclose_proto(lib.resolve("res_nclose")); | - | ||||||||||||||||||||||||
| 107 | - | |||||||||||||||||||||||||
| 108 | local_res_ninit = res_ninit_proto(lib.resolve("__res_ninit")); | - | ||||||||||||||||||||||||
| 109 | if (!local_res_ninit) | - | ||||||||||||||||||||||||
| 110 | local_res_ninit = res_ninit_proto(lib.resolve("res_9_ninit")); | - | ||||||||||||||||||||||||
| 111 | if (!local_res_ninit) | - | ||||||||||||||||||||||||
| 112 | local_res_ninit = res_ninit_proto(lib.resolve("res_ninit")); | - | ||||||||||||||||||||||||
| 113 | - | |||||||||||||||||||||||||
| 114 | local_res_nquery = res_nquery_proto(lib.resolve("__res_nquery")); | - | ||||||||||||||||||||||||
| 115 | if (!local_res_nquery) | - | ||||||||||||||||||||||||
| 116 | local_res_nquery = res_nquery_proto(lib.resolve("res_9_nquery")); | - | ||||||||||||||||||||||||
| 117 | if (!local_res_nquery) | - | ||||||||||||||||||||||||
| 118 | local_res_nquery = res_nquery_proto(lib.resolve("res_nquery")); | - | ||||||||||||||||||||||||
| 119 | - | |||||||||||||||||||||||||
| 120 | return true; | - | ||||||||||||||||||||||||
| 121 | } | - | ||||||||||||||||||||||||
| 122 | Q_GLOBAL_STATIC_WITH_ARGS(bool, resolveLibrary, (resolveLibraryInternal())) | - | ||||||||||||||||||||||||
| 123 | - | |||||||||||||||||||||||||
| 124 | void 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) {
| 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) {
| 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()) {
| 0-84 | ||||||||||||||||||||||||
| 147 | if (nameserver.protocol() == QAbstractSocket::IPv4Protocol) {
| 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
| 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) {
| 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);
| 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++) {
| 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:
| 58 | ||||||||||||||||||||||||
| 199 | break; executed 58 times by 2 tests: break;Executed by:
| 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:
| 26 | ||||||||||||||||||||||||
| 209 | reply->error = QDnsLookup::NotFoundError; | - | ||||||||||||||||||||||||
| 210 | reply->errorString = tr("Non existent domain"); | - | ||||||||||||||||||||||||
| 211 | return; executed 26 times by 2 tests: return;Executed by:
| 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))) {
| 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) {
| 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)) {
| 6-100 | ||||||||||||||||||||||||
| 243 | status = local_dn_expand(response, response + responseLength, p, host, sizeof(host)); | - | ||||||||||||||||||||||||
| 244 | if (status < 0) {
| 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) {
| 32-62 | ||||||||||||||||||||||||
| 261 | if (size != 4) {
| 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 blockExecuted by:
| 18-44 | ||||||||||||||||||||||||
| 273 | if (size != 16) {
| 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 blockExecuted by:
| 0-44 | ||||||||||||||||||||||||
| 284 | status = local_dn_expand(response, response + responseLength, p, answer, sizeof(answer)); | - | ||||||||||||||||||||||||
| 285 | if (status < 0) {
| 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
| 0-38 | ||||||||||||||||||||||||
| 296 | status = local_dn_expand(response, response + responseLength, p, answer, sizeof(answer)); | - | ||||||||||||||||||||||||
| 297 | if (status < 0) {
| 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 blockExecuted by:
| 0-38 | ||||||||||||||||||||||||
| 308 | status = local_dn_expand(response, response + responseLength, p, answer, sizeof(answer)); | - | ||||||||||||||||||||||||
| 309 | if (status < 0) {
| 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
| 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) {
| 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 blockExecuted by:
| 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) {
| 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 blockExecuted by:
| 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) {
| 8-10 | ||||||||||||||||||||||||
| 357 | const unsigned char length = *txt; | - | ||||||||||||||||||||||||
| 358 | txt++; | - | ||||||||||||||||||||||||
| 359 | if (txt + length > p + size) {
| 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 blockExecuted by:
| 10 | ||||||||||||||||||||||||
| 367 | reply->textRecords.append(record); | - | ||||||||||||||||||||||||
| 368 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||||||||
| 369 | p += size; | - | ||||||||||||||||||||||||
| 370 | answerIndex++; | - | ||||||||||||||||||||||||
| 371 | } executed 94 times by 2 tests: end of blockExecuted by:
| 94 | ||||||||||||||||||||||||
| 372 | } executed 58 times by 2 tests: end of blockExecuted by:
| 58 | ||||||||||||||||||||||||
| 373 | - | |||||||||||||||||||||||||
| 374 | #else | - | ||||||||||||||||||||||||
| 375 | void 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 | - | |||||||||||||||||||||||||
| 387 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |