diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/network/kernel/qdnslookup.cpp | 70 | ||||
| -rw-r--r-- | src/network/kernel/qdnslookup.h | 9 | ||||
| -rw-r--r-- | src/network/kernel/qdnslookup_p.h | 28 | ||||
| -rw-r--r-- | src/network/kernel/qdnslookup_unix.cpp | 2 | ||||
| -rw-r--r-- | src/network/kernel/qdnslookup_win.cpp | 2 |
5 files changed, 96 insertions, 15 deletions
diff --git a/src/network/kernel/qdnslookup.cpp b/src/network/kernel/qdnslookup.cpp index 06f6f83a49b..645ed31b023 100644 --- a/src/network/kernel/qdnslookup.cpp +++ b/src/network/kernel/qdnslookup.cpp @@ -244,16 +244,39 @@ QDnsLookup::QDnsLookup(Type type, const QString &name, QObject *parent) /*! \fn QDnsLookup::QDnsLookup(Type type, const QString &name, const QHostAddress &nameserver, QObject *parent) \since 5.4 - Constructs a QDnsLookup object for the given \a type, \a name and - \a nameserver and sets \a parent as the parent object. + + Constructs a QDnsLookup object to issue a query for \a name of record type + \a type, using the DNS server \a nameserver running on the default DNS port, + and sets \a parent as the parent object. */ QDnsLookup::QDnsLookup(Type type, const QString &name, const QHostAddress &nameserver, QObject *parent) + : QDnsLookup(type, name, nameserver, DnsPort, parent) +{ +} + +/*! + \fn QDnsLookup::QDnsLookup(Type type, const QString &name, const QHostAddress &nameserver, quint16 port, QObject *parent) + \since 6.6 + + Constructs a QDnsLookup object to issue a query for \a name of record type + \a type, using the DNS server \a nameserver running on port \a port, and + sets \a parent as the parent object. + +//! [nameserver-port] + \note Setting the port number to any value other than the default (53) can + cause the name resolution to fail, depending on the operating system + limitations and firewalls. Notably, the Windows API used by QDnsLookup is + unable to handle alternate port numbers. +//! [nameserver-port] +*/ +QDnsLookup::QDnsLookup(Type type, const QString &name, const QHostAddress &nameserver, quint16 port, QObject *parent) : QObject(*new QDnsLookupPrivate, parent) { Q_D(QDnsLookup); d->name = name; d->type = type; + d->port = port; d->nameserver = nameserver; } @@ -367,6 +390,46 @@ QBindable<QHostAddress> QDnsLookup::bindableNameserver() } /*! + \property QDnsLookup::nameserverPort + \since 6.6 + \brief the port number of nameserver to use for DNS lookup. + \include qdnslookup.cpp nameserver-port +*/ + +quint16 QDnsLookup::nameserverPort() const +{ + return d_func()->port; +} + +void QDnsLookup::setNameserverPort(quint16 nameserverPort) +{ + Q_D(QDnsLookup); + d->port = nameserverPort; +} + +QBindable<quint16> QDnsLookup::bindableNameserverPort() +{ + Q_D(QDnsLookup); + return &d->port; +} + +/*! + \since 6.6 + Sets the nameserver to \a nameserver and the port to \a port. + + \include qdnslookup.cpp nameserver-port + + \sa QDnsLookup::nameserver, QDnsLookup::nameserverPort +*/ +void QDnsLookup::setNameserver(const QHostAddress &nameserver, quint16 port) +{ + Qt::beginPropertyUpdateGroup(); + setNameserver(nameserver); + setNameserverPort(port); + Qt::endPropertyUpdateGroup(); +} + +/*! Returns the list of canonical name records associated with this lookup. */ @@ -965,7 +1028,8 @@ void QDnsLookupPrivate::_q_lookupFinished(const QDnsLookupReply &_reply) inline QDnsLookupRunnable::QDnsLookupRunnable(const QDnsLookupPrivate *d) : requestName(QUrl::toAce(d->name)), nameserver(d->nameserver), - requestType(d->type) + requestType(d->type), + port(d->port) { } diff --git a/src/network/kernel/qdnslookup.h b/src/network/kernel/qdnslookup.h index bf31b81da1a..ca7cb617ccb 100644 --- a/src/network/kernel/qdnslookup.h +++ b/src/network/kernel/qdnslookup.h @@ -146,6 +146,8 @@ class Q_NETWORK_EXPORT QDnsLookup : public QObject Q_PROPERTY(Type type READ type WRITE setType NOTIFY typeChanged BINDABLE bindableType) Q_PROPERTY(QHostAddress nameserver READ nameserver WRITE setNameserver NOTIFY nameserverChanged BINDABLE bindableNameserver) + Q_PROPERTY(quint16 nameserverPort READ nameserverPort WRITE setNameserverPort + NOTIFY nameserverPortChanged BINDABLE bindableNameserverPort) public: enum Error @@ -178,6 +180,8 @@ public: explicit QDnsLookup(QObject *parent = nullptr); QDnsLookup(Type type, const QString &name, QObject *parent = nullptr); QDnsLookup(Type type, const QString &name, const QHostAddress &nameserver, QObject *parent = nullptr); + QDnsLookup(Type type, const QString &name, const QHostAddress &nameserver, quint16 port, + QObject *parent = nullptr); ~QDnsLookup(); Error error() const; @@ -195,6 +199,10 @@ public: QHostAddress nameserver() const; void setNameserver(const QHostAddress &nameserver); QBindable<QHostAddress> bindableNameserver(); + quint16 nameserverPort() const; + void setNameserverPort(quint16 port); + QBindable<quint16> bindableNameserverPort(); + void setNameserver(const QHostAddress &nameserver, quint16 port); QList<QDnsDomainNameRecord> canonicalNameRecords() const; QList<QDnsHostAddressRecord> hostAddressRecords() const; @@ -214,6 +222,7 @@ Q_SIGNALS: void nameChanged(const QString &name); void typeChanged(Type type); void nameserverChanged(const QHostAddress &nameserver); + void nameserverPortChanged(quint16 port); private: Q_DECLARE_PRIVATE(QDnsLookup) diff --git a/src/network/kernel/qdnslookup_p.h b/src/network/kernel/qdnslookup_p.h index 45403050edd..a1ffb5f20b0 100644 --- a/src/network/kernel/qdnslookup_p.h +++ b/src/network/kernel/qdnslookup_p.h @@ -120,15 +120,12 @@ class QDnsLookupPrivate : public QObjectPrivate { public: QDnsLookupPrivate() - : isFinished(false) - , type(QDnsLookup::A) - , runnable(nullptr) + : type(QDnsLookup::A) + , port(DnsPort) { } void _q_lookupFinished(const QDnsLookupReply &reply); - bool isFinished; - void nameChanged() { emit q_func()->nameChanged(name); @@ -136,6 +133,13 @@ public: Q_OBJECT_BINDABLE_PROPERTY(QDnsLookupPrivate, QString, name, &QDnsLookupPrivate::nameChanged); + void nameserverChanged() + { + emit q_func()->nameserverChanged(nameserver); + } + Q_OBJECT_BINDABLE_PROPERTY(QDnsLookupPrivate, QHostAddress, nameserver, + &QDnsLookupPrivate::nameserverChanged); + void typeChanged() { emit q_func()->typeChanged(type); @@ -144,15 +148,18 @@ public: Q_OBJECT_BINDABLE_PROPERTY(QDnsLookupPrivate, QDnsLookup::Type, type, &QDnsLookupPrivate::typeChanged); - void nameserverChanged() + void nameserverPortChanged() { - emit q_func()->nameserverChanged(nameserver); + emit q_func()->nameserverPortChanged(port); } - Q_OBJECT_BINDABLE_PROPERTY(QDnsLookupPrivate, QHostAddress, nameserver, - &QDnsLookupPrivate::nameserverChanged); + + Q_OBJECT_BINDABLE_PROPERTY(QDnsLookupPrivate, quint16, + port, &QDnsLookupPrivate::nameserverPortChanged); + QDnsLookupReply reply; - QDnsLookupRunnable *runnable; + QDnsLookupRunnable *runnable = nullptr; + bool isFinished = false; Q_DECLARE_PUBLIC(QDnsLookup) }; @@ -173,6 +180,7 @@ private: QByteArray requestName; QHostAddress nameserver; QDnsLookup::Type requestType; + quint16 port; }; class QDnsLookupThreadPool : public QThreadPool diff --git a/src/network/kernel/qdnslookup_unix.cpp b/src/network/kernel/qdnslookup_unix.cpp index af2ef73a22b..9d12b75b31b 100644 --- a/src/network/kernel/qdnslookup_unix.cpp +++ b/src/network/kernel/qdnslookup_unix.cpp @@ -109,7 +109,7 @@ void QDnsLookupRunnable::query(QDnsLookupReply *reply) auto guard = qScopeGuard([&] { res_nclose(&state); }); //Check if a nameserver was set. If so, use it - if (!applyNameServer(&state, nameserver, DnsPort)) { + if (!applyNameServer(&state, nameserver, port)) { qWarning("QDnsLookup: %s", "IPv6 nameservers are currently not supported on this OS"); return reply->setError(QDnsLookup::ResolverError, QDnsLookup::tr("IPv6 nameservers are currently not supported on this OS")); diff --git a/src/network/kernel/qdnslookup_win.cpp b/src/network/kernel/qdnslookup_win.cpp index ac0252f2cc1..24169545919 100644 --- a/src/network/kernel/qdnslookup_win.cpp +++ b/src/network/kernel/qdnslookup_win.cpp @@ -82,7 +82,7 @@ void QDnsLookupRunnable::query(QDnsLookupReply *reply) request.pDnsServerList->MaxCount = sizeof(dnsAddresses); request.pDnsServerList->AddrCount = 1; // ### setting port 53 seems to cause some systems to fail - setSockaddr(sa, nameserver, 0); + setSockaddr(sa, nameserver, port == DnsPort ? 0 : port); request.pDnsServerList->Family = sa->sa_family; } |
