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