32 QDnsLookupThreadPool()
45 return r1.preference() <
r2.preference();
55 if (records.size() <= 1)
62 while (
i < records.size()) {
65 QList<QDnsMailExchangeRecord> slice;
66 const quint16 slicePreference = records.at(
i).preference();
67 for (
int j =
i;
j < records.size(); ++
j) {
68 if (records.at(
j).preference() != slicePreference)
70 slice << records.at(
j);
74 while (!slice.isEmpty()) {
76 records[
i++] = slice.takeAt(
pos);
85 return r1.priority() <
r2.priority()
86 || (
r1.priority() ==
r2.priority()
87 &&
r1.weight() == 0 &&
r2.weight() > 0);
97 if (records.size() <= 1)
105 while (
i < records.size()) {
108 QList<QDnsServiceRecord> slice;
109 const quint16 slicePriority = records.at(
i).priority();
110 unsigned int sliceWeight = 0;
111 for (
int j =
i;
j < records.size(); ++
j) {
112 if (records.at(
j).priority() != slicePriority)
114 sliceWeight += records.at(
j).weight();
115 slice << records.at(
j);
117#ifdef QDNSLOOKUP_DEBUG
118 qDebug(
"qt_qdnsservicerecord_sort() : priority %i (size: %i, total weight: %i)",
119 slicePriority, slice.size(), sliceWeight);
123 while (!slice.isEmpty()) {
125 unsigned int summedWeight = 0;
126 for (
int j = 0;
j < slice.size(); ++
j) {
127 summedWeight += slice.at(
j).weight();
128 if (summedWeight >= weightThreshold) {
129#ifdef QDNSLOOKUP_DEBUG
130 qDebug(
"qt_qdnsservicerecord_sort() : adding %s %i (weight: %i)",
132 slice.at(
j).weight());
135 sliceWeight -= slice.at(
j).weight();
136 records[
i++] = slice.takeAt(
j);
290#if QT_CONFIG(libresolv) || defined(Q_OS_WIN)
463 return d_func()->reply.authenticData;
473 return d_func()->reply.error;
483 return d_func()->reply.errorString;
492 return d_func()->isFinished;
509 return d_func()->name;
531 return d_func()->type;
553 return d_func()->nameserver;
565 return &
d->nameserver;
581 return d_func()->port;
605 return d_func()->protocol;
610 d_func()->protocol = protocol;
615 return &d_func()->protocol;
644 return d_func()->reply.canonicalNameRecords;
653 return d_func()->reply.hostAddressRecords;
666 return d_func()->reply.mailExchangeRecords;
675 return d_func()->reply.nameServerRecords;
684 return d_func()->reply.pointerRecords;
697 return d_func()->reply.serviceRecords;
706 return d_func()->reply.textRecords;
721 return d_func()->reply.tlsAssociationRecords;
734 d->sslConfiguration.emplace(sslConfiguration);
759 d->runnable =
nullptr;
762 d->reply.errorString =
tr(
"Operation cancelled");
763 d->isFinished =
true;
777 d->isFinished =
false;
781 qWarning(
"QDnsLookup requires a QCoreApplication");
788#ifdef QDNSLOOKUP_DEBUG
792 d->sslConfiguration = std::move(
reply.sslConfiguration);
795 d->runnable =
nullptr;
804 theDnsLookupThreadPool->start(
d->runnable);
1501 if (
label.isEmpty())
1506 return encodedLabel;
1508 return std::move(encodedLabel).toLatin1();
1514 nameserver(
d->nameserver),
1515 requestType(
d->
type),
1517 protocol(
d->protocol)
1522 sslConfiguration =
d->sslConfiguration;
1559 <<
"DNS lookup failed (" <<
reply.
error <<
"): "
1561 <<
"; request was " <<
this;
1570 d <<
"... (truncated)";
1571 d <<
" type " <<
r->requestType;
1572 if (!
r->nameserver.isNull()) {
1575 switch (
r->protocol) {
1586static constexpr std::chrono::milliseconds DnsOverTlsConnectTimeout(15'000);
1587static constexpr std::chrono::milliseconds DnsOverTlsTimeout(120'000);
1588static constexpr quint8 DnsAuthenticDataBit = 0x20;
1611# if QT_CONFIG(networkproxy)
1616 query[3] |= DnsAuthenticDataBit;
1625 if (!
socket.waitForEncrypted(DnsOverTlsConnectTimeout.count()))
1628 reply->sslConfiguration =
socket.sslConfiguration();
1631 auto waitForBytes = [&](
void *
buffer,
int count) {
1632 int remaining =
timeout.remainingTime();
1639 if (!waitForBytes(&
size,
sizeof(
size)))
1647 if (waitForBytes(response.
data(),
size)) {
1650 reply->authenticData = response[3] & DnsAuthenticDataBit;
1671#include "moc_qdnslookup.cpp"
1672#include "moc_qdnslookup_p.cpp"
The QAbstractSocket class provides the base functionality common to all socket types.
bool waitForReadyRead(int msecs=30000) override
This function blocks until new data is available for reading and the \l{QIODevice::}{readyRead()} sig...
qint64 bytesAvailable() const override
Returns the number of incoming bytes that are waiting to be read.
void setProtocolTag(const QString &tag)
@ ProxyConnectionTimeoutError
SocketError error() const
Returns the type of error that last occurred.
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
static QCoreApplication * instance() noexcept
Returns a pointer to the application's QCoreApplication (or QGuiApplication/QApplication) instance.
The QDnsDomainNameRecord class stores information about a domain name record.
QString name() const
Returns the name for this record.
QString value() const
Returns the value for this domain name record.
QDnsDomainNameRecord & operator=(QDnsDomainNameRecord &&other) noexcept
QDnsDomainNameRecord()
Constructs an empty domain name record object.
quint32 timeToLive() const
Returns the duration in seconds for which this record is valid.
~QDnsDomainNameRecord()
Destroys a domain name record.
The QDnsHostAddressRecord class stores information about a host address record.
QHostAddress value() const
Returns the value for this host address record.
~QDnsHostAddressRecord()
Destroys a host address record.
QDnsHostAddressRecord()
Constructs an empty host address record object.
quint32 timeToLive() const
Returns the duration in seconds for which this record is valid.
QDnsHostAddressRecord & operator=(QDnsHostAddressRecord &&other) noexcept
QString name() const
Returns the name for this record.
void finished(const QDnsLookupReply &reply)
QDnsLookupRunnable(const QDnsLookupPrivate *d)
void run() override
Implement this pure virtual function in your subclass.
bool sendDnsOverTls(QDnsLookupReply *reply, QSpan< unsigned char > query, ReplyBuffer &response)
The QDnsLookup class represents a DNS lookup.
quint16 nameserverPort
the port number of nameserver to use for DNS lookup.
Protocol nameserverProtocol
the protocol to use when sending the DNS query
Type
Indicates the type of DNS lookup that was performed.
QBindable< QString > bindableName()
QString errorString
a human-readable description of the error if the DNS lookup failed.
static quint16 defaultPortForProtocol(Protocol protocol) noexcept Q_DECL_CONST_FUNCTION
QHostAddress nameserver
the nameserver to use for DNS lookup.
QList< QDnsServiceRecord > serviceRecords() const
Returns the list of service records associated with this lookup.
bool isFinished() const
Returns whether the reply has finished or was aborted.
QList< QDnsMailExchangeRecord > mailExchangeRecords() const
Returns the list of mail exchange records associated with this lookup.
QBindable< Protocol > bindableNameserverProtocol()
void setName(const QString &name)
QList< QDnsDomainNameRecord > nameServerRecords() const
Returns the list of name server records associated with this lookup.
QList< QDnsTlsAssociationRecord > tlsAssociationRecords() const
void setNameserverProtocol(Protocol protocol)
Error
Indicates all possible error conditions found during the processing of the DNS lookup.
@ OperationCancelledError
void abort()
Aborts the DNS lookup operation.
bool isAuthenticData() const
QBindable< quint16 > bindableNameserverPort()
void finished()
This signal is emitted when the reply has finished processing.
Error error
the type of error that occurred if the DNS lookup failed, or NoError.
void setType(QDnsLookup::Type)
static bool isProtocolSupported(Protocol protocol)
Protocol
Indicates the type of DNS server that is being queried.
QDnsLookup(QObject *parent=nullptr)
Constructs a QDnsLookup object and sets parent as the parent object.
QList< QDnsDomainNameRecord > canonicalNameRecords() const
Returns the list of canonical name records associated with this lookup.
void lookup()
Performs the DNS lookup.
void setNameserver(const QHostAddress &nameserver)
~QDnsLookup()
Destroys the QDnsLookup object.
QBindable< QHostAddress > bindableNameserver()
QList< QDnsDomainNameRecord > pointerRecords() const
Returns the list of pointer records associated with this lookup.
QBindable< Type > bindableType()
void setNameserverPort(quint16 port)
QList< QDnsHostAddressRecord > hostAddressRecords() const
Returns the list of host address records associated with this lookup.
Type type
the type of DNS lookup.
QString name
the name to lookup.
QList< QDnsTextRecord > textRecords() const
Returns the list of text records associated with this lookup.
The QDnsMailExchangeRecord class stores information about a DNS MX record.
~QDnsMailExchangeRecord()
Destroys a mail exchange record.
quint16 preference() const
Returns the preference for this record.
quint32 timeToLive() const
Returns the duration in seconds for which this record is valid.
QString name() const
Returns the name for this record.
QDnsMailExchangeRecord()
Constructs an empty mail exchange record object.
QDnsMailExchangeRecord & operator=(QDnsMailExchangeRecord &&other) noexcept
QString exchange() const
Returns the domain name of the mail exchange for this record.
The QDnsServiceRecord class stores information about a DNS SRV record.
QString target() const
Returns the domain name of the target host for this service record.
QDnsServiceRecord & operator=(QDnsServiceRecord &&other) noexcept
quint16 weight() const
Returns the weight for this service record.
quint32 timeToLive() const
Returns the duration in seconds for which this record is valid.
~QDnsServiceRecord()
Destroys a service record.
quint16 priority() const
Returns the priority for this service record.
QString name() const
Returns the name for this record.
quint16 port() const
Returns the port on the target host for this service record.
QDnsServiceRecord()
Constructs an empty service record object.
QList< QByteArray > values
The QDnsTextRecord class stores information about a DNS TXT record.
quint32 timeToLive() const
Returns the duration in seconds for which this record is valid.
QDnsTextRecord & operator=(QDnsTextRecord &&other) noexcept
QDnsTextRecord()
Constructs an empty text record object.
~QDnsTextRecord()
Destroys a text record.
QList< QByteArray > values() const
Returns the values for this text record.
QString name() const
Returns the name for this text record.
QDnsTlsAssociationRecord::CertificateUsage usage
QDnsTlsAssociationRecord::MatchingType matchType
QDnsTlsAssociationRecord::Selector selector
The QDnsTlsAssociationRecord class stores information about a DNS TLSA record.
QDnsTlsAssociationRecord & operator=(QDnsTlsAssociationRecord &&other) noexcept
QDnsTlsAssociationRecord()
Constructs an empty TLS Association record.
Selector selector() const
Returns the selector field for this record.
CertificateUsage
This enumeration contains valid values for the certificate usage field of TLS Association queries.
Selector
This enumeration contains valid values for the selector field of TLS Association queries.
quint32 timeToLive() const
Returns the duration in seconds for which this record is valid.
MatchingType matchType() const
Returns the match type field for this record.
QByteArray value() const
Returns the binary data field for this record.
QString name() const
Returns the name of this record.
~QDnsTlsAssociationRecord()
Destroys this TLS Association record object.
MatchingType
This enumeration contains valid values for the matching type field of TLS Association queries.
CertificateUsage usage() const
Returns the certificate usage field for this record.
The QHostAddress class provides an IP address.
QString toString() const
Returns the address as a string.
NetworkLayerProtocol protocol() const
Returns the network layer protocol of the host address.
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
QString errorString() const
Returns a human-readable description of the last device error that occurred.
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read.
void setError(NetworkError errorCode, const QString &errorString)
Sets the error condition to be errorCode.
NetworkError error() const
Returns the error that was found during the processing of this request.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
QObject * sender() const
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; othe...
static Q_DECL_CONST_FUNCTION QRandomGenerator * global()
\threadsafe
The QSslConfiguration class holds the configuration and state of an SSL connection.
static QSslConfiguration defaultConfiguration()
Returns the default SSL configuration to be used in new SSL connections.
The QSslSocket class provides an SSL encrypted socket for both clients and servers.
static bool supportsSsl()
Returns true if this platform supports SSL; otherwise, returns false.
\macro QT_RESTRICTED_CAST_FROM_ASCII
void resize(qsizetype sz)
Combined button and popup list for selecting options.
Q_CORE_EXPORT void beginPropertyUpdateGroup()
@ BlockingQueuedConnection
Q_CORE_EXPORT void endPropertyUpdateGroup()
#define Q_APPLICATION_STATIC(TYPE, NAME,...)
DBusConnection const char DBusError * error
static void qt_qdnsmailexchangerecord_sort(QList< QDnsMailExchangeRecord > &records)
static void qt_qdnsservicerecord_sort(QList< QDnsServiceRecord > &records)
QDebug operator<<(QDebug &d, QDnsLookupRunnable *r)
static bool qt_qdnsmailexchangerecord_less_than(const QDnsMailExchangeRecord &r1, const QDnsMailExchangeRecord &r2)
static bool qt_qdnsservicerecord_less_than(const QDnsServiceRecord &r1, const QDnsServiceRecord &r2)
static QDnsLookupRunnable::EncodedLabel encodeLabel(const QString &label)
constexpr quint16 DnsPort
constexpr quint16 DnsOverTlsPort
QT_BEGIN_NAMESPACE constexpr qsizetype MaxDomainNameLength
constexpr T qFromBigEndian(T source)
#define Q_LOGGING_CATEGORY(name,...)
#define qCWarning(category,...)
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLenum GLsizei count
GLbitfield GLuint64 timeout
[4]
GLuint GLsizei const GLchar * label
[43]
#define QT_DEFINE_QSDP_SPECIALIZATION_DTOR(Class)
#define qPrintable(string)
#define qUtf16Printable(string)
QString Q_CORE_EXPORT qt_ACE_do(const QString &domain, AceOperation op, AceLeadingDot dot, QUrl::AceProcessingOptions options={})