summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
Diffstat (limited to 'src/network')
-rw-r--r--src/network/.prev_CMakeLists.txt13
-rw-r--r--src/network/CMakeLists.txt13
-rw-r--r--src/network/access/qabstractnetworkcache.h2
-rw-r--r--src/network/access/qftp.cpp11
-rw-r--r--src/network/access/qftp_p.h3
-rw-r--r--src/network/access/qhsts.cpp4
-rw-r--r--src/network/access/qhttp2protocolhandler.cpp9
-rw-r--r--src/network/access/qhttpmultipart.h2
-rw-r--r--src/network/access/qhttpnetworkconnection.cpp38
-rw-r--r--src/network/access/qhttpnetworkconnection_p.h13
-rw-r--r--src/network/access/qhttpnetworkconnectionchannel.cpp12
-rw-r--r--src/network/access/qnetworkaccessftpbackend.cpp7
-rw-r--r--src/network/access/qnetworkaccessmanager.cpp183
-rw-r--r--src/network/access/qnetworkaccessmanager.h5
-rw-r--r--src/network/access/qnetworkaccessmanager_p.h10
-rw-r--r--src/network/access/qnetworkcookie.cpp1
-rw-r--r--src/network/access/qnetworkcookie.h2
-rw-r--r--src/network/access/qnetworkreplyhttpimpl.cpp15
-rw-r--r--src/network/access/qnetworkreplyimpl.cpp24
-rw-r--r--src/network/access/qnetworkreplyimpl_p.h6
-rw-r--r--src/network/access/qnetworkreplywasmimpl.cpp32
-rw-r--r--src/network/access/qnetworkrequest.cpp6
-rw-r--r--src/network/access/qnetworkrequest.h3
-rw-r--r--src/network/bearer/qnetworkconfiguration.h2
-rw-r--r--src/network/kernel/kernel.pri12
-rw-r--r--src/network/kernel/qdnslookup.h10
-rw-r--r--src/network/kernel/qhostaddress.cpp4
-rw-r--r--src/network/kernel/qhostaddress.h3
-rw-r--r--src/network/kernel/qhostinfo.cpp179
-rw-r--r--src/network/kernel/qhostinfo_p.h7
-rw-r--r--src/network/kernel/qhostinfo_unix.cpp139
-rw-r--r--src/network/kernel/qhostinfo_win.cpp110
-rw-r--r--src/network/kernel/qnetconmonitor_darwin.mm419
-rw-r--r--src/network/kernel/qnetconmonitor_p.h126
-rw-r--r--src/network/kernel/qnetconmonitor_stub.cpp141
-rw-r--r--src/network/kernel/qnetworkinterface.h4
-rw-r--r--src/network/kernel/qnetworkproxy.h4
-rw-r--r--src/network/socket/qlocalserver.cpp2
-rw-r--r--src/network/socket/qnativesocketengine_winrt.cpp8
-rw-r--r--src/network/socket/qsctpserver.cpp7
-rw-r--r--src/network/socket/qtcpserver.cpp2
-rw-r--r--src/network/socket/socket.pri2
-rw-r--r--src/network/ssl/qsslcertificate.cpp2
-rw-r--r--src/network/ssl/qsslcertificate.h2
-rw-r--r--src/network/ssl/qsslcertificateextension.h2
-rw-r--r--src/network/ssl/qsslcipher.h2
-rw-r--r--src/network/ssl/qsslconfiguration.h2
-rw-r--r--src/network/ssl/qsslerror.cpp1
-rw-r--r--src/network/ssl/qsslerror.h2
-rw-r--r--src/network/ssl/qsslkey.h5
-rw-r--r--src/network/ssl/qsslkey_p.cpp22
-rw-r--r--src/network/ssl/qsslkey_qt.cpp5
-rw-r--r--src/network/ssl/qsslpresharedkeyauthenticator.h2
-rw-r--r--src/network/ssl/qsslsocket.cpp12
-rw-r--r--src/network/ssl/qsslsocket_openssl_symbols.cpp2
55 files changed, 1243 insertions, 413 deletions
diff --git a/src/network/.prev_CMakeLists.txt b/src/network/.prev_CMakeLists.txt
index d48c3920fc..1b901d3050 100644
--- a/src/network/.prev_CMakeLists.txt
+++ b/src/network/.prev_CMakeLists.txt
@@ -33,6 +33,7 @@ add_qt_module(Network
kernel/qauthenticator.cpp kernel/qauthenticator.h kernel/qauthenticator_p.h
kernel/qhostaddress.cpp kernel/qhostaddress.h kernel/qhostaddress_p.h
kernel/qhostinfo.cpp kernel/qhostinfo.h kernel/qhostinfo_p.h
+ kernel/qnetconmonitor_p.h
kernel/qnetworkdatagram.cpp kernel/qnetworkdatagram.h kernel/qnetworkdatagram_p.h
kernel/qnetworkinterface.cpp kernel/qnetworkinterface.h kernel/qnetworkinterface_p.h
kernel/qnetworkinterface_unix_p.h
@@ -213,6 +214,18 @@ extend_target(Network CONDITION APPLE_OSX AND NOT APPLE_UIKIT
${FWSystemConfiguration}
)
+extend_target(Network CONDITION APPLE_IOS OR APPLE_OSX
+ SOURCES
+ kernel/qnetconmonitor_darwin.mm
+ LIBRARIES
+ ${FWSystemConfiguration}
+)
+
+extend_target(Network CONDITION NOT APPLE_IOS AND NOT APPLE_OSX
+ SOURCES
+ kernel/qnetconmonitor_stub.cpp
+)
+
extend_target(Network CONDITION QT_FEATURE_gssapi
LIBRARIES
gssapi_krb5
diff --git a/src/network/CMakeLists.txt b/src/network/CMakeLists.txt
index 20add1192e..414a41581b 100644
--- a/src/network/CMakeLists.txt
+++ b/src/network/CMakeLists.txt
@@ -33,6 +33,7 @@ add_qt_module(Network
kernel/qauthenticator.cpp kernel/qauthenticator.h kernel/qauthenticator_p.h
kernel/qhostaddress.cpp kernel/qhostaddress.h kernel/qhostaddress_p.h
kernel/qhostinfo.cpp kernel/qhostinfo.h kernel/qhostinfo_p.h
+ kernel/qnetconmonitor_p.h
kernel/qnetworkdatagram.cpp kernel/qnetworkdatagram.h kernel/qnetworkdatagram_p.h
kernel/qnetworkinterface.cpp kernel/qnetworkinterface.h kernel/qnetworkinterface_p.h
kernel/qnetworkinterface_unix_p.h
@@ -222,6 +223,18 @@ extend_target(Network CONDITION APPLE_OSX AND NOT APPLE_UIKIT
${FWSystemConfiguration}
)
+extend_target(Network CONDITION APPLE_IOS OR APPLE_OSX
+ SOURCES
+ kernel/qnetconmonitor_darwin.mm
+ LIBRARIES
+ ${FWSystemConfiguration}
+)
+
+extend_target(Network CONDITION NOT APPLE_IOS AND NOT APPLE_OSX
+ SOURCES
+ kernel/qnetconmonitor_stub.cpp
+)
+
extend_target(Network CONDITION QT_FEATURE_gssapi
LIBRARIES
gssapi_krb5
diff --git a/src/network/access/qabstractnetworkcache.h b/src/network/access/qabstractnetworkcache.h
index b604323c41..e357dfe58f 100644
--- a/src/network/access/qabstractnetworkcache.h
+++ b/src/network/access/qabstractnetworkcache.h
@@ -67,9 +67,7 @@ public:
QNetworkCacheMetaData(const QNetworkCacheMetaData &other);
~QNetworkCacheMetaData();
-#ifdef Q_COMPILER_RVALUE_REFS
QNetworkCacheMetaData &operator=(QNetworkCacheMetaData &&other) noexcept { swap(other); return *this; }
-#endif
QNetworkCacheMetaData &operator=(const QNetworkCacheMetaData &other);
void swap(QNetworkCacheMetaData &other) noexcept
diff --git a/src/network/access/qftp.cpp b/src/network/access/qftp.cpp
index 4e399f018f..b6b721030b 100644
--- a/src/network/access/qftp.cpp
+++ b/src/network/access/qftp.cpp
@@ -2124,6 +2124,17 @@ void QFtp::abort()
/*!
\internal
+ Clears the last error.
+
+ \sa currentCommand()
+*/
+void QFtp::clearError()
+{
+ d_func()->error = NoError;
+}
+
+/*!
+ \internal
Returns the identifier of the FTP command that is being executed
or 0 if there is no command being executed.
diff --git a/src/network/access/qftp_p.h b/src/network/access/qftp_p.h
index 91d78d1351..a55429933b 100644
--- a/src/network/access/qftp_p.h
+++ b/src/network/access/qftp_p.h
@@ -157,6 +157,9 @@ Q_SIGNALS:
void commandFinished(int, bool);
void done(bool);
+protected:
+ void clearError();
+
private:
Q_DISABLE_COPY_MOVE(QFtp)
Q_DECLARE_PRIVATE(QFtp)
diff --git a/src/network/access/qhsts.cpp b/src/network/access/qhsts.cpp
index ce70b6af90..0cef0ad3dc 100644
--- a/src/network/access/qhsts.cpp
+++ b/src/network/access/qhsts.cpp
@@ -145,7 +145,7 @@ void QHstsCache::updateKnownHost(const QString &host, const QDateTime &expires,
return;
}
- knownHosts.insert(pos, {hostName, newPolicy});
+ knownHosts.insert({hostName, newPolicy});
#if QT_CONFIG(settings)
if (hstsStore)
hstsStore->addToObserved(newPolicy);
@@ -156,7 +156,7 @@ void QHstsCache::updateKnownHost(const QString &host, const QDateTime &expires,
if (newPolicy.isExpired())
knownHosts.erase(pos);
else if (pos->second != newPolicy)
- pos->second = std::move(newPolicy);
+ pos->second = newPolicy;
else
return;
diff --git a/src/network/access/qhttp2protocolhandler.cpp b/src/network/access/qhttp2protocolhandler.cpp
index 35aee6e3e1..87a70d8a55 100644
--- a/src/network/access/qhttp2protocolhandler.cpp
+++ b/src/network/access/qhttp2protocolhandler.cpp
@@ -818,7 +818,6 @@ void QHttp2ProtocolHandler::handleGOAWAY()
// and a NO_ERROR code."
if (lastStreamID != Http2::lastValidStreamID || errorCode != HTTP2_NO_ERROR)
return connectionError(PROTOCOL_ERROR, "GOAWAY invalid stream/error code");
- lastStreamID = 1;
} else {
lastStreamID += 2;
}
@@ -836,6 +835,14 @@ void QHttp2ProtocolHandler::handleGOAWAY()
QString message;
qt_error(errorCode, error, message);
+ // Even if the GOAWAY frame contains NO_ERROR we must send an error
+ // when terminating streams to ensure users can distinguish from a
+ // successful completion.
+ if (errorCode == HTTP2_NO_ERROR) {
+ error = QNetworkReply::ContentReSendError;
+ message = QLatin1String("Server stopped accepting new streams before this stream was established");
+ }
+
for (quint32 id = lastStreamID; id < nextID; id += 2) {
const auto it = activeStreams.find(id);
if (it != activeStreams.end()) {
diff --git a/src/network/access/qhttpmultipart.h b/src/network/access/qhttpmultipart.h
index f718d51d0c..56db83779a 100644
--- a/src/network/access/qhttpmultipart.h
+++ b/src/network/access/qhttpmultipart.h
@@ -60,9 +60,7 @@ public:
QHttpPart();
QHttpPart(const QHttpPart &other);
~QHttpPart();
-#ifdef Q_COMPILER_RVALUE_REFS
QHttpPart &operator=(QHttpPart &&other) noexcept { swap(other); return *this; }
-#endif
QHttpPart &operator=(const QHttpPart &other);
void swap(QHttpPart &other) noexcept { qSwap(d, other.d); }
diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp
index 0a37122fc6..cb4c722eb5 100644
--- a/src/network/access/qhttpnetworkconnection.cpp
+++ b/src/network/access/qhttpnetworkconnection.cpp
@@ -1320,6 +1320,10 @@ QHttpNetworkConnection::QHttpNetworkConnection(const QString &hostName, quint16
Q_D(QHttpNetworkConnection);
d->networkSession = std::move(networkSession);
d->init();
+ if (QNetworkStatusMonitor::isEnabled()) {
+ connect(&d->connectionMonitor, &QNetworkConnectionMonitor::reachabilityChanged,
+ this, &QHttpNetworkConnection::onlineStateChanged, Qt::QueuedConnection);
+ }
}
QHttpNetworkConnection::QHttpNetworkConnection(quint16 connectionCount, const QString &hostName,
@@ -1332,6 +1336,10 @@ QHttpNetworkConnection::QHttpNetworkConnection(quint16 connectionCount, const QS
Q_D(QHttpNetworkConnection);
d->networkSession = std::move(networkSession);
d->init();
+ if (QNetworkStatusMonitor::isEnabled()) {
+ connect(&d->connectionMonitor, &QNetworkConnectionMonitor::reachabilityChanged,
+ this, &QHttpNetworkConnection::onlineStateChanged, Qt::QueuedConnection);
+ }
}
#else
QHttpNetworkConnection::QHttpNetworkConnection(const QString &hostName, quint16 port, bool encrypt,
@@ -1340,6 +1348,10 @@ QHttpNetworkConnection::QHttpNetworkConnection(const QString &hostName, quint16
{
Q_D(QHttpNetworkConnection);
d->init();
+ if (QNetworkStatusMonitor::isEnabled()) {
+ connect(&d->connectionMonitor, &QNetworkConnectionMonitor::reachabilityChanged,
+ this, &QHttpNetworkConnection::onlineStateChanged, Qt::QueuedConnection);
+ }
}
QHttpNetworkConnection::QHttpNetworkConnection(quint16 connectionCount, const QString &hostName,
@@ -1350,8 +1362,12 @@ QHttpNetworkConnection::QHttpNetworkConnection(quint16 connectionCount, const QS
{
Q_D(QHttpNetworkConnection);
d->init();
+ if (QNetworkStatusMonitor::isEnabled()) {
+ connect(&d->connectionMonitor, &QNetworkConnectionMonitor::reachabilityChanged,
+ this, &QHttpNetworkConnection::onlineStateChanged, Qt::QueuedConnection);
+ }
}
-#endif
+#endif // QT_NO_BEARERMANAGEMENT
QHttpNetworkConnection::~QHttpNetworkConnection()
{
@@ -1531,6 +1547,26 @@ void QHttpNetworkConnection::setPeerVerifyName(const QString &peerName)
d->peerVerifyName = peerName;
}
+void QHttpNetworkConnection::onlineStateChanged(bool isOnline)
+{
+ Q_D(QHttpNetworkConnection);
+
+ if (isOnline) {
+ // If we did not have any 'isOffline' previously - well, good
+ // to know, we are 'online' apparently.
+ return;
+ }
+
+ for (int i = 0; i < d->activeChannelCount; i++) {
+ auto &channel = d->channels[i];
+ channel.emitFinishedWithError(QNetworkReply::TemporaryNetworkFailureError, "Temporary network failure.");
+ channel.close();
+ }
+
+ // We don't care, this connection is broken from our POV.
+ d->connectionMonitor.stopMonitoring();
+}
+
#ifndef QT_NO_NETWORKPROXY
// only called from QHttpNetworkConnectionChannel::_q_proxyAuthenticationRequired, not
// from QHttpNetworkConnectionChannel::handleAuthenticationChallenge
diff --git a/src/network/access/qhttpnetworkconnection_p.h b/src/network/access/qhttpnetworkconnection_p.h
index 2f3c334248..85d89f20c2 100644
--- a/src/network/access/qhttpnetworkconnection_p.h
+++ b/src/network/access/qhttpnetworkconnection_p.h
@@ -67,6 +67,7 @@
#include <private/qhttpnetworkheader_p.h>
#include <private/qhttpnetworkrequest_p.h>
#include <private/qhttpnetworkreply_p.h>
+#include <private/qnetconmonitor_p.h>
#include <private/http2protocol_p.h>
#include <private/qhttpnetworkconnectionchannel_p.h>
@@ -156,6 +157,10 @@ public:
QString peerVerifyName() const;
void setPeerVerifyName(const QString &peerName);
+
+public slots:
+ void onlineStateChanged(bool isOnline);
+
private:
Q_DECLARE_PRIVATE(QHttpNetworkConnection)
Q_DISABLE_COPY_MOVE(QHttpNetworkConnection)
@@ -292,6 +297,14 @@ public:
Http2::ProtocolParameters http2Parameters;
QString peerVerifyName;
+ // If network status monitoring is enabled, we activate connectionMonitor
+ // as soons as one of channels managed to connect to host (and we
+ // have a pair of addresses (us,peer).
+ // NETMONTODO: consider activating a monitor on a change from
+ // HostLookUp state to ConnectingState (means we have both
+ // local/remote addresses known and can start monitoring this
+ // early).
+ QNetworkConnectionMonitor connectionMonitor;
friend class QHttpNetworkConnectionChannel;
};
diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp
index f79a4d1dc6..9309d718e4 100644
--- a/src/network/access/qhttpnetworkconnectionchannel.cpp
+++ b/src/network/access/qhttpnetworkconnectionchannel.cpp
@@ -59,6 +59,8 @@
#include "private/qnetworksession_p.h"
#endif
+#include "private/qnetconmonitor_p.h"
+
QT_BEGIN_NAMESPACE
namespace
@@ -896,6 +898,16 @@ void QHttpNetworkConnectionChannel::_q_connected()
pipeliningSupported = QHttpNetworkConnectionChannel::PipeliningSupportUnknown;
+ if (QNetworkStatusMonitor::isEnabled()) {
+ auto connectionPrivate = connection->d_func();
+ if (!connectionPrivate->connectionMonitor.isMonitoring()) {
+ // Now that we have a pair of addresses, we can start monitoring the
+ // connection status to handle its loss properly.
+ if (connectionPrivate->connectionMonitor.setTargets(socket->localAddress(), socket->peerAddress()))
+ connectionPrivate->connectionMonitor.startMonitoring();
+ }
+ }
+
// ### FIXME: if the server closes the connection unexpectedly, we shouldn't send the same broken request again!
//channels[i].reconnectAttempts = 2;
if (ssl || pendingEncrypt) { // FIXME: Didn't work properly with pendingEncrypt only, we should refactor this into an EncrypingState
diff --git a/src/network/access/qnetworkaccessftpbackend.cpp b/src/network/access/qnetworkaccessftpbackend.cpp
index 5ad820eba0..51ed2f5a55 100644
--- a/src/network/access/qnetworkaccessftpbackend.cpp
+++ b/src/network/access/qnetworkaccessftpbackend.cpp
@@ -99,6 +99,8 @@ public:
connect(this, SIGNAL(done(bool)), this, SLOT(deleteLater()));
close();
}
+
+ using QFtp::clearError;
};
QNetworkAccessFtpBackend::QNetworkAccessFtpBackend()
@@ -282,7 +284,10 @@ void QNetworkAccessFtpBackend::ftpDone()
}
// check for errors:
- if (ftp->error() != QFtp::NoError) {
+ if (state == CheckingFeatures && ftp->error() == QFtp::UnknownError) {
+ qWarning("QNetworkAccessFtpBackend: HELP command failed, ignoring it");
+ ftp->clearError();
+ } else if (ftp->error() != QFtp::NoError) {
QString msg;
if (operation() == QNetworkAccessManager::GetOperation)
msg = tr("Error while downloading %1: %2");
diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp
index 50b9488594..a2996e3533 100644
--- a/src/network/access/qnetworkaccessmanager.cpp
+++ b/src/network/access/qnetworkaccessmanager.cpp
@@ -90,6 +90,8 @@
#include "qnetworkreplywasmimpl_p.h"
#endif
+#include "qnetconmonitor_p.h"
+
QT_BEGIN_NAMESPACE
Q_GLOBAL_STATIC(QNetworkAccessFileBackendFactory, fileBackend)
@@ -486,18 +488,25 @@ QNetworkAccessManager::QNetworkAccessManager(QObject *parent)
qRegisterMetaType<QNetworkReply::NetworkError>();
qRegisterMetaType<QSharedPointer<char> >();
-#ifndef QT_NO_BEARERMANAGEMENT
Q_D(QNetworkAccessManager);
- // if a session is required, we track online state through
- // the QNetworkSession's signals if a request is already made.
- // we need to track current accessibility state by default
- //
- connect(&d->networkConfigurationManager, SIGNAL(onlineStateChanged(bool)),
- SLOT(_q_onlineStateChanged(bool)));
- connect(&d->networkConfigurationManager, SIGNAL(configurationChanged(QNetworkConfiguration)),
- SLOT(_q_configurationChanged(QNetworkConfiguration)));
-
-#endif
+ if (QNetworkStatusMonitor::isEnabled()) {
+ connect(&d->statusMonitor, SIGNAL(onlineStateChanged(bool)),
+ SLOT(_q_onlineStateChanged(bool)));
+#ifdef QT_NO_BEARERMANAGEMENT
+ d->networkAccessible = d->statusMonitor.isNetworkAccesible();
+#else
+ d->networkAccessible = d->statusMonitor.isNetworkAccesible() ? Accessible : NotAccessible;
+ } else {
+ // if a session is required, we track online state through
+ // the QNetworkSession's signals if a request is already made.
+ // we need to track current accessibility state by default
+ //
+ connect(&d->networkConfigurationManager, SIGNAL(onlineStateChanged(bool)),
+ SLOT(_q_onlineStateChanged(bool)));
+ connect(&d->networkConfigurationManager, SIGNAL(configurationChanged(QNetworkConfiguration)),
+ SLOT(_q_configurationChanged(QNetworkConfiguration)));
+#endif // QT_NO_BEARERMANAGEMENT
+ }
}
/*!
@@ -1030,6 +1039,7 @@ QNetworkReply *QNetworkAccessManager::deleteResource(const QNetworkRequest &requ
void QNetworkAccessManager::setConfiguration(const QNetworkConfiguration &config)
{
Q_D(QNetworkAccessManager);
+
d->networkConfiguration = config;
d->customNetworkConfiguration = true;
d->createSession(config);
@@ -1048,7 +1058,7 @@ QNetworkConfiguration QNetworkAccessManager::configuration() const
Q_D(const QNetworkAccessManager);
QSharedPointer<QNetworkSession> session(d->getNetworkSession());
- if (session) {
+ if (session && !d->statusMonitor.isEnabled()) {
return session->configuration();
} else {
return d->networkConfigurationManager.defaultConfiguration();
@@ -1075,7 +1085,7 @@ QNetworkConfiguration QNetworkAccessManager::activeConfiguration() const
Q_D(const QNetworkAccessManager);
QSharedPointer<QNetworkSession> networkSession(d->getNetworkSession());
- if (networkSession) {
+ if (networkSession && !d->statusMonitor.isEnabled()) {
return d->networkConfigurationManager.configurationFromIdentifier(
networkSession->sessionProperty(QLatin1String("ActiveConfiguration")).toString());
} else {
@@ -1114,6 +1124,12 @@ QNetworkAccessManager::NetworkAccessibility QNetworkAccessManager::networkAccess
{
Q_D(const QNetworkAccessManager);
+ if (d->statusMonitor.isEnabled()) {
+ if (!d->statusMonitor.isMonitoring())
+ d->statusMonitor.start();
+ return d->networkAccessible;
+ }
+
if (d->customNetworkConfiguration && d->networkConfiguration.state().testFlag(QNetworkConfiguration::Undefined))
return UnknownAccessibility;
@@ -1386,6 +1402,11 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera
req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, redirectPolicy());
}
+ if (autoDeleteReplies()
+ && req.attribute(QNetworkRequest::AutoDeleteReplyOnFinishAttribute).isNull()) {
+ req.setAttribute(QNetworkRequest::AutoDeleteReplyOnFinishAttribute, true);
+ }
+
bool isLocalFile = req.url().isLocalFile();
QString scheme = req.url().scheme();
@@ -1434,35 +1455,57 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera
}
}
-#ifndef QT_NO_BEARERMANAGEMENT
+ if (d->statusMonitor.isEnabled()) {
+ // See the code in ctor - QNetworkStatusMonitor allows us to
+ // immediately set 'networkAccessible' even before we start
+ // the monitor.
+#ifdef QT_NO_BEARERMANAGEMENT
+ if (d->networkAccessible
+#else
+ if (d->networkAccessible == NotAccessible
+#endif // QT_NO_BEARERMANAGEMENT
+ && !isLocalFile) {
+ QHostAddress dest;
+ QString host = req.url().host().toLower();
+ if (!(dest.setAddress(host) && dest.isLoopback())
+ && host != QLatin1String("localhost")
+ && host != QHostInfo::localHostName().toLower()) {
+ return new QDisabledNetworkReply(this, req, op);
+ }
+ }
- // Return a disabled network reply if network access is disabled.
- // Except if the scheme is empty or file:// or if the host resolves to a loopback address.
- if (d->networkAccessible == NotAccessible && !isLocalFile) {
- QHostAddress dest;
- QString host = req.url().host().toLower();
- if (!(dest.setAddress(host) && dest.isLoopback()) && host != QLatin1String("localhost")
+ if (!d->statusMonitor.isMonitoring() && !d->statusMonitor.start())
+ qWarning(lcNetMon, "failed to start network status monitoring");
+ } else {
+#ifndef QT_NO_BEARERMANAGEMENT
+ // Return a disabled network reply if network access is disabled.
+ // Except if the scheme is empty or file:// or if the host resolves to a loopback address.
+ if (d->networkAccessible == NotAccessible && !isLocalFile) {
+ QHostAddress dest;
+ QString host = req.url().host().toLower();
+ if (!(dest.setAddress(host) && dest.isLoopback()) && host != QLatin1String("localhost")
&& host != QHostInfo::localHostName().toLower()) {
- return new QDisabledNetworkReply(this, req, op);
+ return new QDisabledNetworkReply(this, req, op);
+ }
}
- }
- if (!d->networkSessionStrongRef && (d->initializeSession || !d->networkConfiguration.identifier().isEmpty())) {
- if (!d->networkConfiguration.identifier().isEmpty()) {
- if ((d->networkConfiguration.state() & QNetworkConfiguration::Defined)
- && d->networkConfiguration != d->networkConfigurationManager.defaultConfiguration())
- d->createSession(d->networkConfigurationManager.defaultConfiguration());
- else
- d->createSession(d->networkConfiguration);
+ if (!d->networkSessionStrongRef && (d->initializeSession || !d->networkConfiguration.identifier().isEmpty())) {
+ if (!d->networkConfiguration.identifier().isEmpty()) {
+ if ((d->networkConfiguration.state() & QNetworkConfiguration::Defined)
+ && d->networkConfiguration != d->networkConfigurationManager.defaultConfiguration())
+ d->createSession(d->networkConfigurationManager.defaultConfiguration());
+ else
+ d->createSession(d->networkConfiguration);
- } else {
- if (d->networkSessionRequired)
- d->createSession(d->networkConfigurationManager.defaultConfiguration());
- else
- d->initializeSession = false;
+ } else {
+ if (d->networkSessionRequired)
+ d->createSession(d->networkConfigurationManager.defaultConfiguration());
+ else
+ d->initializeSession = false;
+ }
}
- }
#endif
+ }
QNetworkRequest request = req;
if (!request.header(QNetworkRequest::ContentLengthHeader).isValid() &&
@@ -1509,8 +1552,10 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera
#endif
QNetworkReplyHttpImpl *reply = new QNetworkReplyHttpImpl(this, request, op, outgoingData);
#ifndef QT_NO_BEARERMANAGEMENT
- connect(this, SIGNAL(networkSessionConnected()),
- reply, SLOT(_q_networkSessionConnected()));
+ if (!d->statusMonitor.isEnabled()) {
+ connect(this, SIGNAL(networkSessionConnected()),
+ reply, SLOT(_q_networkSessionConnected()));
+ }
#endif
return reply;
}
@@ -1519,7 +1564,9 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera
// first step: create the reply
QNetworkReplyImpl *reply = new QNetworkReplyImpl(this);
#ifndef QT_NO_BEARERMANAGEMENT
- if (!isLocalFile) {
+ // NETMONTODO: network reply impl must be augmented to use the same monitoring
+ // capabilities as http network reply impl does.
+ if (!isLocalFile && !d->statusMonitor.isEnabled()) {
connect(this, SIGNAL(networkSessionConnected()),
reply, SLOT(_q_networkSessionConnected()));
}
@@ -1630,13 +1677,50 @@ void QNetworkAccessManager::clearConnectionCache()
QNetworkAccessManagerPrivate::clearConnectionCache(this);
}
+
+/*!
+ \since 5.14
+
+ Returns the true if QNetworkAccessManager is currently configured
+ to automatically delete QNetworkReplies, false otherwise.
+
+ \sa setAutoDeleteReplies,
+ QNetworkRequest::AutoDeleteReplyOnFinishAttribute
+*/
+bool QNetworkAccessManager::autoDeleteReplies()
+{
+ return d_func()->autoDeleteReplies;
+}
+
+/*!
+ \since 5.14
+
+ Enables or disables automatic deletion of \l {QNetworkReply} {QNetworkReplies}.
+
+ Setting \a shouldAutoDelete to true is the same as setting the
+ QNetworkRequest::AutoDeleteReplyOnFinishAttribute attribute to
+ true on all \e{future} \l {QNetworkRequest} {QNetworkRequests}
+ passed to this instance of QNetworkAccessManager unless the
+ attribute was already explicitly set on the QNetworkRequest.
+
+ \sa autoDeleteReplies,
+ QNetworkRequest::AutoDeleteReplyOnFinishAttribute
+*/
+void QNetworkAccessManager::setAutoDeleteReplies(bool shouldAutoDelete)
+{
+ d_func()->autoDeleteReplies = shouldAutoDelete;
+}
+
void QNetworkAccessManagerPrivate::_q_replyFinished()
{
Q_Q(QNetworkAccessManager);
QNetworkReply *reply = qobject_cast<QNetworkReply *>(q->sender());
- if (reply)
+ if (reply) {
emit q->finished(reply);
+ if (reply->request().attribute(QNetworkRequest::AutoDeleteReplyOnFinishAttribute, false).toBool())
+ QMetaObject::invokeMethod(reply, [reply] { reply->deleteLater(); }, Qt::QueuedConnection);
+ }
#ifndef QT_NO_BEARERMANAGEMENT
// If there are no active requests, release our reference to the network session.
@@ -1988,7 +2072,13 @@ void QNetworkAccessManagerPrivate::_q_networkSessionStateChanged(QNetworkSession
void QNetworkAccessManagerPrivate::_q_onlineStateChanged(bool isOnline)
{
- Q_Q(QNetworkAccessManager);
+ Q_Q(QNetworkAccessManager);
+
+ if (statusMonitor.isEnabled()) {
+ networkAccessible = isOnline ? QNetworkAccessManager::Accessible : QNetworkAccessManager::NotAccessible;
+ return;
+ }
+
// if the user set a config, we only care whether this one is active.
// Otherwise, this QNAM is online if there is an online config.
@@ -2018,6 +2108,9 @@ void QNetworkAccessManagerPrivate::_q_onlineStateChanged(bool isOnline)
void QNetworkAccessManagerPrivate::_q_configurationChanged(const QNetworkConfiguration &configuration)
{
+ if (statusMonitor.isEnabled())
+ return;
+
const QString id = configuration.identifier();
if (configuration.state().testFlag(QNetworkConfiguration::Active)) {
if (!onlineConfigurations.contains(id)) {
@@ -2050,6 +2143,9 @@ void QNetworkAccessManagerPrivate::_q_configurationChanged(const QNetworkConfigu
void QNetworkAccessManagerPrivate::_q_networkSessionFailed(QNetworkSession::SessionError)
{
+ if (statusMonitor.isEnabled())
+ return;
+
const auto cfgs = networkConfigurationManager.allConfigurations();
for (const QNetworkConfiguration &cfg : cfgs) {
if (cfg.state().testFlag(QNetworkConfiguration::Active)) {
@@ -2061,6 +2157,13 @@ void QNetworkAccessManagerPrivate::_q_networkSessionFailed(QNetworkSession::Sess
}
}
+#else
+
+void QNetworkAccessManagerPrivate::_q_onlineStateChanged(bool isOnline)
+{
+ networkAccessible = isOnline;
+}
+
#endif // QT_NO_BEARERMANAGEMENT
#if QT_CONFIG(http)
diff --git a/src/network/access/qnetworkaccessmanager.h b/src/network/access/qnetworkaccessmanager.h
index 7e2f7683d0..601d0420ff 100644
--- a/src/network/access/qnetworkaccessmanager.h
+++ b/src/network/access/qnetworkaccessmanager.h
@@ -167,6 +167,9 @@ public:
void setRedirectPolicy(QNetworkRequest::RedirectPolicy policy);
QNetworkRequest::RedirectPolicy redirectPolicy() const;
+ bool autoDeleteReplies();
+ void setAutoDeleteReplies(bool autoDelete);
+
Q_SIGNALS:
#ifndef QT_NO_NETWORKPROXY
void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator);
@@ -209,10 +212,10 @@ private:
#ifndef QT_NO_BEARERMANAGEMENT
Q_PRIVATE_SLOT(d_func(), void _q_networkSessionClosed())
Q_PRIVATE_SLOT(d_func(), void _q_networkSessionStateChanged(QNetworkSession::State))
- Q_PRIVATE_SLOT(d_func(), void _q_onlineStateChanged(bool))
Q_PRIVATE_SLOT(d_func(), void _q_configurationChanged(const QNetworkConfiguration &))
Q_PRIVATE_SLOT(d_func(), void _q_networkSessionFailed(QNetworkSession::SessionError))
#endif
+ Q_PRIVATE_SLOT(d_func(), void _q_onlineStateChanged(bool))
};
QT_END_NAMESPACE
diff --git a/src/network/access/qnetworkaccessmanager_p.h b/src/network/access/qnetworkaccessmanager_p.h
index 5cab4928e4..67ea2094b3 100644
--- a/src/network/access/qnetworkaccessmanager_p.h
+++ b/src/network/access/qnetworkaccessmanager_p.h
@@ -55,6 +55,7 @@
#include "qnetworkaccessmanager.h"
#include "qnetworkaccesscache_p.h"
#include "qnetworkaccessbackend_p.h"
+#include "private/qnetconmonitor_p.h"
#include "qnetworkrequest.h"
#include "qhsts_p.h"
#include "private/qobject_p.h"
@@ -151,6 +152,7 @@ public:
QNetworkAccessBackend *findBackend(QNetworkAccessManager::Operation op, const QNetworkRequest &request);
QStringList backendSupportedSchemes() const;
+ void _q_onlineStateChanged(bool isOnline);
#ifndef QT_NO_BEARERMANAGEMENT
void createSession(const QNetworkConfiguration &config);
QSharedPointer<QNetworkSession> getNetworkSession() const;
@@ -160,12 +162,11 @@ public:
void _q_networkSessionPreferredConfigurationChanged(const QNetworkConfiguration &config,
bool isSeamless);
void _q_networkSessionStateChanged(QNetworkSession::State state);
- void _q_onlineStateChanged(bool isOnline);
+
void _q_configurationChanged(const QNetworkConfiguration &configuration);
void _q_networkSessionFailed(QNetworkSession::SessionError error);
QSet<QString> onlineConfigurations;
-
#endif
#if QT_CONFIG(http)
@@ -199,6 +200,8 @@ public:
int activeReplyCount;
bool online;
bool initializeSession;
+#else
+ bool networkAccessible = true;
#endif
bool cookieJarCreated;
@@ -222,6 +225,9 @@ public:
QScopedPointer<QHstsStore> stsStore;
#endif // QT_CONFIG(settings)
bool stsEnabled = false;
+ mutable QNetworkStatusMonitor statusMonitor;
+
+ bool autoDeleteReplies = false;
#ifndef QT_NO_BEARERMANAGEMENT
Q_AUTOTEST_EXPORT static const QWeakPointer<const QNetworkSession> getNetworkSession(const QNetworkAccessManager *manager);
diff --git a/src/network/access/qnetworkcookie.cpp b/src/network/access/qnetworkcookie.cpp
index b7cf989477..903de322ff 100644
--- a/src/network/access/qnetworkcookie.cpp
+++ b/src/network/access/qnetworkcookie.cpp
@@ -46,6 +46,7 @@
#include "QtCore/qdebug.h"
#include "QtCore/qlist.h"
#include "QtCore/qlocale.h"
+#include <QtCore/qregexp.h>
#include "QtCore/qstring.h"
#include "QtCore/qstringlist.h"
#include "QtCore/qurl.h"
diff --git a/src/network/access/qnetworkcookie.h b/src/network/access/qnetworkcookie.h
index 58c504f9ae..b712b63849 100644
--- a/src/network/access/qnetworkcookie.h
+++ b/src/network/access/qnetworkcookie.h
@@ -66,9 +66,7 @@ public:
explicit QNetworkCookie(const QByteArray &name = QByteArray(), const QByteArray &value = QByteArray());
QNetworkCookie(const QNetworkCookie &other);
~QNetworkCookie();
-#ifdef Q_COMPILER_RVALUE_REFS
QNetworkCookie &operator=(QNetworkCookie &&other) noexcept { swap(other); return *this; }
-#endif
QNetworkCookie &operator=(const QNetworkCookie &other);
void swap(QNetworkCookie &other) noexcept { qSwap(d, other.d); }
diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp
index f801ef0c88..b9651b35d2 100644
--- a/src/network/access/qnetworkreplyhttpimpl.cpp
+++ b/src/network/access/qnetworkreplyhttpimpl.cpp
@@ -59,6 +59,7 @@
#include <QtCore/private/qthread_p.h>
#include "qnetworkcookiejar.h"
+#include "qnetconmonitor_p.h"
#include <string.h> // for strchr
@@ -166,6 +167,11 @@ static QHash<QByteArray, QByteArray> parseHttpOptionHeader(const QByteArray &hea
#if QT_CONFIG(bearermanagement)
static bool isSessionNeeded(const QUrl &url)
{
+ if (QNetworkStatusMonitor::isEnabled()) {
+ // In case QNetworkStatus/QNetConManager are in business,
+ // no session, no bearer manager are involved.
+ return false;
+ }
// Connections to the local machine does not require a session
QString host = url.host().toLower();
return !QHostAddress(host).isLoopback() && host != QLatin1String("localhost")
@@ -796,7 +802,8 @@ void QNetworkReplyHttpImplPrivate::postRequest(const QNetworkRequest &newHttpReq
if (blob.isValid() && blob.canConvert<Http2::ProtocolParameters>())
delegate->http2Parameters = blob.value<Http2::ProtocolParameters>();
#ifndef QT_NO_BEARERMANAGEMENT
- delegate->networkSession = managerPrivate->getNetworkSession();
+ if (!QNetworkStatusMonitor::isEnabled())
+ delegate->networkSession = managerPrivate->getNetworkSession();
#endif
// For the synchronous HTTP, this is the normal way the delegate gets deleted
@@ -1807,7 +1814,7 @@ bool QNetworkReplyHttpImplPrivate::start(const QNetworkRequest &newHttpRequest)
{
#ifndef QT_NO_BEARERMANAGEMENT
QSharedPointer<QNetworkSession> networkSession(managerPrivate->getNetworkSession());
- if (!networkSession) {
+ if (!networkSession || QNetworkStatusMonitor::isEnabled()) {
#endif
postRequest(newHttpRequest);
return true;
@@ -1895,7 +1902,7 @@ void QNetworkReplyHttpImplPrivate::_q_startOperation()
// state changes.
if (!startWaitForSession(session))
return;
- } else if (session) {
+ } else if (session && !QNetworkStatusMonitor::isEnabled()) {
QObject::connect(session.data(), SIGNAL(stateChanged(QNetworkSession::State)),
q, SLOT(_q_networkSessionStateChanged(QNetworkSession::State)),
Qt::QueuedConnection);
@@ -2184,7 +2191,7 @@ void QNetworkReplyHttpImplPrivate::finished()
#ifndef QT_NO_BEARERMANAGEMENT
Q_ASSERT(managerPrivate);
QSharedPointer<QNetworkSession> session = managerPrivate->getNetworkSession();
- if (session && session->state() == QNetworkSession::Roaming &&
+ if (!QNetworkStatusMonitor::isEnabled() && session && session->state() == QNetworkSession::Roaming &&
state == Working && errorCode != QNetworkReply::OperationCanceledError) {
// only content with a known size will fail with a temporary network failure error
if (!totalSize.isNull()) {
diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp
index a794b492e7..6eab500e8c 100644
--- a/src/network/access/qnetworkreplyimpl.cpp
+++ b/src/network/access/qnetworkreplyimpl.cpp
@@ -158,7 +158,7 @@ void QNetworkReplyImplPrivate::_q_startOperation()
} else {
if (state != Finished) {
if (operation == QNetworkAccessManager::GetOperation)
- pendingNotifications.append(NotifyDownstreamReadyWrite);
+ pendingNotifications.push_back(NotifyDownstreamReadyWrite);
handleNotifications();
}
@@ -368,6 +368,7 @@ void QNetworkReplyImplPrivate::setup(QNetworkAccessManager::Operation op, const
outgoingData = data;
request = req;
+ originalRequest = req;
url = request.url();
operation = op;
@@ -432,8 +433,9 @@ void QNetworkReplyImplPrivate::setup(QNetworkAccessManager::Operation op, const
void QNetworkReplyImplPrivate::backendNotify(InternalNotifications notification)
{
Q_Q(QNetworkReplyImpl);
- if (!pendingNotifications.contains(notification))
- pendingNotifications.enqueue(notification);
+ const auto it = std::find(pendingNotifications.cbegin(), pendingNotifications.cend(), notification);
+ if (it == pendingNotifications.cend())
+ pendingNotifications.push_back(notification);
if (pendingNotifications.size() == 1)
QCoreApplication::postEvent(q, new QEvent(QEvent::NetworkReplyUpdated));
@@ -444,14 +446,9 @@ void QNetworkReplyImplPrivate::handleNotifications()
if (notificationHandlingPaused)
return;
- NotificationQueue current = pendingNotifications;
- pendingNotifications.clear();
-
- if (state != Working)
- return;
-
- while (state == Working && !current.isEmpty()) {
- InternalNotifications notification = current.dequeue();
+ for (InternalNotifications notification : qExchange(pendingNotifications, {})) {
+ if (state != Working)
+ return;
switch (notification) {
case NotifyDownstreamReadyWrite:
if (copyDevice)
@@ -465,8 +462,7 @@ void QNetworkReplyImplPrivate::handleNotifications()
break;
case NotifyCopyFinished: {
- QIODevice *dev = copyDevice;
- copyDevice = 0;
+ QIODevice *dev = qExchange(copyDevice, nullptr);
backend->copyFinished(dev);
break;
}
@@ -1116,7 +1112,6 @@ bool QNetworkReplyImplPrivate::migrateBackend()
return true;
}
-#ifndef QT_NO_BEARERMANAGEMENT
QDisabledNetworkReply::QDisabledNetworkReply(QObject *parent,
const QNetworkRequest &req,
QNetworkAccessManager::Operation op)
@@ -1141,7 +1136,6 @@ QDisabledNetworkReply::QDisabledNetworkReply(QObject *parent,
QDisabledNetworkReply::~QDisabledNetworkReply()
{
}
-#endif
QT_END_NAMESPACE
diff --git a/src/network/access/qnetworkreplyimpl_p.h b/src/network/access/qnetworkreplyimpl_p.h
index 4881e84e9c..8cec79541a 100644
--- a/src/network/access/qnetworkreplyimpl_p.h
+++ b/src/network/access/qnetworkreplyimpl_p.h
@@ -117,8 +117,6 @@ public:
NotifyCopyFinished
};
- typedef QQueue<InternalNotifications> NotificationQueue;
-
QNetworkReplyImplPrivate();
void _q_startOperation();
@@ -178,7 +176,7 @@ public:
bool cacheEnabled;
QIODevice *cacheSaveDevice;
- NotificationQueue pendingNotifications;
+ std::vector<InternalNotifications> pendingNotifications;
bool notificationHandlingPaused;
QUrl urlForLastAuthentication;
@@ -209,7 +207,6 @@ public:
};
Q_DECLARE_TYPEINFO(QNetworkReplyImplPrivate::InternalNotifications, Q_PRIMITIVE_TYPE);
-#ifndef QT_NO_BEARERMANAGEMENT
class QDisabledNetworkReply : public QNetworkReply
{
Q_OBJECT
@@ -223,7 +220,6 @@ public:
protected:
qint64 readData(char *, qint64) override { return -1; }
};
-#endif
QT_END_NAMESPACE
diff --git a/src/network/access/qnetworkreplywasmimpl.cpp b/src/network/access/qnetworkreplywasmimpl.cpp
index bb6ef07741..9f8a42ad89 100644
--- a/src/network/access/qnetworkreplywasmimpl.cpp
+++ b/src/network/access/qnetworkreplywasmimpl.cpp
@@ -235,7 +235,7 @@ void QNetworkReplyWasmImpl::close()
void QNetworkReplyWasmImpl::abort()
{
Q_D(const QNetworkReplyWasmImpl);
- setError( QNetworkReply::OperationCanceledError, "Operation canceled" );
+ setError( QNetworkReply::OperationCanceledError, QStringLiteral("Operation canceled"));
d->doAbort();
close();
@@ -328,8 +328,6 @@ void QNetworkReplyWasmImplPrivate::doSendRequest()
m_xhr = val::global("XMLHttpRequest").new_();
std::string verb = q->methodName().toStdString();
- QString extraDataString;
-
m_xhr.call<void>("open", verb, request.url().toString().toStdString());
m_xhr.set("onerror", val::module_property("qt_QNetworkReplyWasmImplPrivate_requestErrorCallback"));
@@ -348,30 +346,12 @@ void QNetworkReplyWasmImplPrivate::doSendRequest()
if (outgoingData) // data from post request
extraData = outgoingData->readAll();
- if (contentType.contains("text") ||
- contentType.contains("json") ||
- contentType.contains("form")) {
- if (extraData.size() > 0)
- extraDataString.fromUtf8(extraData);
- }
- if (contentType.contains("json")) {
- if (!extraDataString.isEmpty()) {
- m_xhr.set("responseType", val("json"));
- dataToSend = val(extraDataString.toStdString());
- }
- } else if (contentType.contains("form")) { //construct form data
- if (!extraDataString.isEmpty()) {
- val formData = val::global("FormData").new_();
- QStringList formList = extraDataString.split('&');
-
- for (auto formEntry : formList) {
- formData.call<void>("append", formEntry.split('=')[0].toStdString(), formEntry.split('=')[1].toStdString());
- }
- dataToSend = formData;
- }
- } else {
- m_xhr.set("responseType", val("blob"));
+ if (!extraData.isEmpty()) {
+ dataToSend = val(typed_memory_view(extraData.size(),
+ reinterpret_cast<const unsigned char *>
+ (extraData.constData())));
}
+ m_xhr.set("responseType", val("blob"));
// set request headers
for (auto header : request.rawHeaderList()) {
m_xhr.call<void>("setRequestHeader", header.toStdString(), request.rawHeader(header).toStdString());
diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp
index f15c43cdd8..deb0792938 100644
--- a/src/network/access/qnetworkrequest.cpp
+++ b/src/network/access/qnetworkrequest.cpp
@@ -331,6 +331,12 @@ QT_BEGIN_NAMESPACE
\omitvalue ResourceTypeAttribute
+ \value AutoDeleteReplyOnFinishAttribute
+ Requests only, type: QMetaType::Bool (default: false)
+ If set, this attribute will make QNetworkAccessManager delete
+ the QNetworkReply after having emitted "finished".
+ (This value was introduced in 5.14.)
+
\value User
Special type. Additional information can be passed in
QVariants with types ranging from User to UserMax. The default
diff --git a/src/network/access/qnetworkrequest.h b/src/network/access/qnetworkrequest.h
index 2515ff6ead..846ead1592 100644
--- a/src/network/access/qnetworkrequest.h
+++ b/src/network/access/qnetworkrequest.h
@@ -98,6 +98,7 @@ public:
RedirectPolicyAttribute,
Http2DirectAttribute,
ResourceTypeAttribute, // internal
+ AutoDeleteReplyOnFinishAttribute,
User = 1000,
UserMax = 32767
@@ -130,9 +131,7 @@ public:
explicit QNetworkRequest(const QUrl &url = QUrl());
QNetworkRequest(const QNetworkRequest &other);
~QNetworkRequest();
-#ifdef Q_COMPILER_RVALUE_REFS
QNetworkRequest &operator=(QNetworkRequest &&other) noexcept { swap(other); return *this; }
-#endif
QNetworkRequest &operator=(const QNetworkRequest &other);
void swap(QNetworkRequest &other) noexcept { qSwap(d, other.d); }
diff --git a/src/network/bearer/qnetworkconfiguration.h b/src/network/bearer/qnetworkconfiguration.h
index 41b6e6f020..048abc2fc8 100644
--- a/src/network/bearer/qnetworkconfiguration.h
+++ b/src/network/bearer/qnetworkconfiguration.h
@@ -55,9 +55,7 @@ class Q_NETWORK_EXPORT QNetworkConfiguration
public:
QNetworkConfiguration();
QNetworkConfiguration(const QNetworkConfiguration& other);
-#ifdef Q_COMPILER_RVALUE_REFS
QNetworkConfiguration &operator=(QNetworkConfiguration &&other) noexcept { swap(other); return *this; }
-#endif
QNetworkConfiguration &operator=(const QNetworkConfiguration &other);
~QNetworkConfiguration();
diff --git a/src/network/kernel/kernel.pri b/src/network/kernel/kernel.pri
index b86119b200..0e4cef5e74 100644
--- a/src/network/kernel/kernel.pri
+++ b/src/network/kernel/kernel.pri
@@ -16,7 +16,8 @@ HEADERS += kernel/qtnetworkglobal.h \
kernel/qnetworkinterface.h \
kernel/qnetworkinterface_p.h \
kernel/qnetworkinterface_unix_p.h \
- kernel/qnetworkproxy.h
+ kernel/qnetworkproxy.h \
+ kernel/qnetconmonitor_p.h
SOURCES += kernel/qauthenticator.cpp \
kernel/qhostaddress.cpp \
@@ -71,6 +72,15 @@ mac {
!uikit: LIBS_PRIVATE += -framework CoreServices -framework SystemConfiguration
}
+macos | ios {
+ OBJECTIVE_SOURCES += \
+ kernel/qnetconmonitor_darwin.mm
+
+ LIBS_PRIVATE += -framework SystemConfiguration
+} else {
+ SOURCES += kernel/qnetconmonitor_stub.cpp
+}
+
qtConfig(gssapi): LIBS_PRIVATE += -lgssapi_krb5
uikit:HEADERS += kernel/qnetworkinterface_uikit_p.h
diff --git a/src/network/kernel/qdnslookup.h b/src/network/kernel/qdnslookup.h
index 79a476b98f..110a74da44 100644
--- a/src/network/kernel/qdnslookup.h
+++ b/src/network/kernel/qdnslookup.h
@@ -64,9 +64,7 @@ class Q_NETWORK_EXPORT QDnsDomainNameRecord
public:
QDnsDomainNameRecord();
QDnsDomainNameRecord(const QDnsDomainNameRecord &other);
-#ifdef Q_COMPILER_RVALUE_REFS
QDnsDomainNameRecord &operator=(QDnsDomainNameRecord &&other) noexcept { swap(other); return *this; }
-#endif
QDnsDomainNameRecord &operator=(const QDnsDomainNameRecord &other);
~QDnsDomainNameRecord();
@@ -88,9 +86,7 @@ class Q_NETWORK_EXPORT QDnsHostAddressRecord
public:
QDnsHostAddressRecord();
QDnsHostAddressRecord(const QDnsHostAddressRecord &other);
-#ifdef Q_COMPILER_RVALUE_REFS
QDnsHostAddressRecord &operator=(QDnsHostAddressRecord &&other) noexcept { swap(other); return *this; }
-#endif
QDnsHostAddressRecord &operator=(const QDnsHostAddressRecord &other);
~QDnsHostAddressRecord();
@@ -112,9 +108,7 @@ class Q_NETWORK_EXPORT QDnsMailExchangeRecord
public:
QDnsMailExchangeRecord();
QDnsMailExchangeRecord(const QDnsMailExchangeRecord &other);
-#ifdef Q_COMPILER_RVALUE_REFS
QDnsMailExchangeRecord &operator=(QDnsMailExchangeRecord &&other) noexcept { swap(other); return *this; }
-#endif
QDnsMailExchangeRecord &operator=(const QDnsMailExchangeRecord &other);
~QDnsMailExchangeRecord();
@@ -137,9 +131,7 @@ class Q_NETWORK_EXPORT QDnsServiceRecord
public:
QDnsServiceRecord();
QDnsServiceRecord(const QDnsServiceRecord &other);
-#ifdef Q_COMPILER_RVALUE_REFS
QDnsServiceRecord &operator=(QDnsServiceRecord &&other) noexcept { swap(other); return *this; }
-#endif
QDnsServiceRecord &operator=(const QDnsServiceRecord &other);
~QDnsServiceRecord();
@@ -164,9 +156,7 @@ class Q_NETWORK_EXPORT QDnsTextRecord
public:
QDnsTextRecord();
QDnsTextRecord(const QDnsTextRecord &other);
-#ifdef Q_COMPILER_RVALUE_REFS
QDnsTextRecord &operator=(QDnsTextRecord &&other) noexcept { swap(other); return *this; }
-#endif
QDnsTextRecord &operator=(const QDnsTextRecord &other);
~QDnsTextRecord();
diff --git a/src/network/kernel/qhostaddress.cpp b/src/network/kernel/qhostaddress.cpp
index 644f4336ca..b54fb349fb 100644
--- a/src/network/kernel/qhostaddress.cpp
+++ b/src/network/kernel/qhostaddress.cpp
@@ -385,8 +385,8 @@ QHostAddress QNetmask::address(QAbstractSocket::NetworkLayerProtocol protocol) c
\value LocalHost The IPv4 localhost address. Equivalent to QHostAddress("127.0.0.1").
\value LocalHostIPv6 The IPv6 localhost address. Equivalent to QHostAddress("::1").
\value Broadcast The IPv4 broadcast address. Equivalent to QHostAddress("255.255.255.255").
- \value AnyIPv4 The IPv4 any-address. Equivalent to QHostAddress("0.0.0.0"). A socket bound with this address will listen only on IPv4 interaces.
- \value AnyIPv6 The IPv6 any-address. Equivalent to QHostAddress("::"). A socket bound with this address will listen only on IPv6 interaces.
+ \value AnyIPv4 The IPv4 any-address. Equivalent to QHostAddress("0.0.0.0"). A socket bound with this address will listen only on IPv4 interfaces.
+ \value AnyIPv6 The IPv6 any-address. Equivalent to QHostAddress("::"). A socket bound with this address will listen only on IPv6 interfaces.
\value Any The dual stack any-address. A socket bound with this address will listen on both IPv4 and IPv6 interfaces.
*/
diff --git a/src/network/kernel/qhostaddress.h b/src/network/kernel/qhostaddress.h
index f20da3304f..799247695e 100644
--- a/src/network/kernel/qhostaddress.h
+++ b/src/network/kernel/qhostaddress.h
@@ -102,11 +102,8 @@ public:
QHostAddress(SpecialAddress address);
~QHostAddress();
-#ifdef Q_COMPILER_RVALUE_REFS
QHostAddress &operator=(QHostAddress &&other) noexcept
{ swap(other); return *this; }
-#endif
-
QHostAddress &operator=(const QHostAddress &other);
#if QT_DEPRECATED_SINCE(5, 8)
QT_DEPRECATED_X("use = QHostAddress(string) instead")
diff --git a/src/network/kernel/qhostinfo.cpp b/src/network/kernel/qhostinfo.cpp
index 71d1aae35a..9374728244 100644
--- a/src/network/kernel/qhostinfo.cpp
+++ b/src/network/kernel/qhostinfo.cpp
@@ -37,8 +37,11 @@
**
****************************************************************************/
+//#define QHOSTINFO_DEBUG
+
#include "qhostinfo.h"
#include "qhostinfo_p.h"
+#include <qplatformdefs.h>
#include "QtCore/qscopedpointer.h"
#include <qabstracteventdispatcher.h>
@@ -53,6 +56,15 @@
#ifdef Q_OS_UNIX
# include <unistd.h>
+# include <netdb.h>
+# include <netinet/in.h>
+# if defined(AI_ADDRCONFIG)
+# define Q_ADDRCONFIG AI_ADDRCONFIG
+# endif
+#elif defined Q_OS_WIN
+# include <ws2tcpip.h>
+
+# define QT_SOCKLEN_T int
#endif
QT_BEGIN_NAMESPACE
@@ -137,8 +149,7 @@ void emit_results_ready(const QHostInfo &hostInfo, const QObject *receiver,
\inmodule QtNetwork
\ingroup network
- QHostInfo uses the lookup mechanisms provided by the operating
- system to find the IP address(es) associated with a host name,
+ QHostInfo finds the IP address(es) associated with a host name,
or the host name associated with an IP address.
The class provides two static convenience functions: one that
works asynchronously and emits a signal once the host is found,
@@ -173,6 +184,11 @@ void emit_results_ready(const QHostInfo &hostInfo, const QObject *receiver,
To retrieve the name of the local host, use the static
QHostInfo::localHostName() function.
+ QHostInfo uses the mechanisms provided by the operating system
+ to perform the lookup. As per {https://tools.ietf.org/html/rfc6724}{RFC 6724}
+ there is no guarantee that all IP addresses registered for a domain or
+ host will be returned.
+
\note Since Qt 4.6.1 QHostInfo is using multiple threads for DNS lookup
instead of one dedicated DNS thread. This improves performance,
but also changes the order of signal emissions when using lookupHost()
@@ -180,7 +196,8 @@ void emit_results_ready(const QHostInfo &hostInfo, const QObject *receiver,
\note Since Qt 4.6.3 QHostInfo is using a small internal 60 second DNS cache
for performance improvements.
- \sa QAbstractSocket, {http://www.rfc-editor.org/rfc/rfc3492.txt}{RFC 3492}
+ \sa QAbstractSocket, {http://www.rfc-editor.org/rfc/rfc3492.txt}{RFC 3492},
+ {https://tools.ietf.org/html/rfc6724}{RFC 6724}
*/
static int nextId()
@@ -407,6 +424,162 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName, QSharedPointer<QNetw
}
#endif
+QHostInfo QHostInfoAgent::reverseLookup(const QHostAddress &address)
+{
+ QHostInfo results;
+ // Reverse lookup
+ sockaddr_in sa4;
+ sockaddr_in6 sa6;
+ sockaddr *sa = 0;
+ QT_SOCKLEN_T saSize;
+ if (address.protocol() == QAbstractSocket::IPv4Protocol) {
+ sa = reinterpret_cast<sockaddr *>(&sa4);
+ saSize = sizeof(sa4);
+ memset(&sa4, 0, sizeof(sa4));
+ sa4.sin_family = AF_INET;
+ sa4.sin_addr.s_addr = htonl(address.toIPv4Address());
+ } else {
+ sa = reinterpret_cast<sockaddr *>(&sa6);
+ saSize = sizeof(sa6);
+ memset(&sa6, 0, sizeof(sa6));
+ sa6.sin6_family = AF_INET6;
+ memcpy(&sa6.sin6_addr, address.toIPv6Address().c, sizeof(sa6.sin6_addr));
+ }
+
+ char hbuf[NI_MAXHOST];
+ if (sa && getnameinfo(sa, saSize, hbuf, sizeof(hbuf), nullptr, 0, 0) == 0)
+ results.setHostName(QString::fromLatin1(hbuf));
+
+ if (results.hostName().isEmpty())
+ results.setHostName(address.toString());
+ results.setAddresses(QList<QHostAddress>() << address);
+
+ return results;
+}
+
+/*
+ Call getaddrinfo, and returns the results as QHostInfo::addresses
+*/
+QHostInfo QHostInfoAgent::lookup(const QString &hostName)
+{
+ QHostInfo results;
+
+ // IDN support
+ QByteArray aceHostname = QUrl::toAce(hostName);
+ results.setHostName(hostName);
+ if (aceHostname.isEmpty()) {
+ results.setError(QHostInfo::HostNotFound);
+ results.setErrorString(hostName.isEmpty() ?
+ QCoreApplication::translate("QHostInfoAgent", "No host name given") :
+ QCoreApplication::translate("QHostInfoAgent", "Invalid hostname"));
+ return results;
+ }
+
+ addrinfo *res = 0;
+ struct addrinfo hints;
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = PF_UNSPEC;
+#ifdef Q_ADDRCONFIG
+ hints.ai_flags = Q_ADDRCONFIG;
+#endif
+
+ int result = getaddrinfo(aceHostname.constData(), nullptr, &hints, &res);
+# ifdef Q_ADDRCONFIG
+ if (result == EAI_BADFLAGS) {
+ // if the lookup failed with AI_ADDRCONFIG set, try again without it
+ hints.ai_flags = 0;
+ result = getaddrinfo(aceHostname.constData(), nullptr, &hints, &res);
+ }
+# endif
+
+ if (result == 0) {
+ addrinfo *node = res;
+ QList<QHostAddress> addresses;
+ while (node) {
+#ifdef QHOSTINFO_DEBUG
+ qDebug() << "getaddrinfo node: flags:" << node->ai_flags << "family:" << node->ai_family
+ << "ai_socktype:" << node->ai_socktype << "ai_protocol:" << node->ai_protocol
+ << "ai_addrlen:" << node->ai_addrlen;
+#endif
+ switch (node->ai_family) {
+ case AF_INET: {
+ QHostAddress addr;
+ addr.setAddress(ntohl(((sockaddr_in *) node->ai_addr)->sin_addr.s_addr));
+ if (!addresses.contains(addr))
+ addresses.append(addr);
+ break;
+ }
+ case AF_INET6: {
+ QHostAddress addr;
+ sockaddr_in6 *sa6 = (sockaddr_in6 *) node->ai_addr;
+ addr.setAddress(sa6->sin6_addr.s6_addr);
+ if (sa6->sin6_scope_id)
+ addr.setScopeId(QString::number(sa6->sin6_scope_id));
+ if (!addresses.contains(addr))
+ addresses.append(addr);
+ break;
+ }
+ default:
+ results.setError(QHostInfo::UnknownError);
+ results.setErrorString(QCoreApplication::translate("QHostInfoAgent", "Unknown address type"));
+ }
+ node = node->ai_next;
+ }
+ if (addresses.isEmpty()) {
+ // Reached the end of the list, but no addresses were found; this
+ // means the list contains one or more unknown address types.
+ results.setError(QHostInfo::UnknownError);
+ results.setErrorString(QCoreApplication::translate("QHostInfoAgent", "Unknown address type"));
+ }
+
+ results.setAddresses(addresses);
+ freeaddrinfo(res);
+ } else {
+ switch (result) {
+#ifdef Q_OS_WIN
+ case WSAHOST_NOT_FOUND: //authoritative not found
+ case WSATRY_AGAIN: //non authoritative not found
+ case WSANO_DATA: //valid name, no associated address
+#else
+ case EAI_NONAME:
+ case EAI_FAIL:
+# ifdef EAI_NODATA // EAI_NODATA is deprecated in RFC 3493
+ case EAI_NODATA:
+# endif
+#endif
+ results.setError(QHostInfo::HostNotFound);
+ results.setErrorString(QCoreApplication::translate("QHostInfoAgent", "Host not found"));
+ break;
+ default:
+ results.setError(QHostInfo::UnknownError);
+#ifdef Q_OS_WIN
+ results.setErrorString(QString::fromWCharArray(gai_strerror(result)));
+#else
+ results.setErrorString(QString::fromLocal8Bit(gai_strerror(result)));
+#endif
+ break;
+ }
+ }
+
+#if defined(QHOSTINFO_DEBUG)
+ if (results.error() != QHostInfo::NoError) {
+ qDebug("QHostInfoAgent::fromName(): error #%d %s",
+ h_errno, results.errorString().toLatin1().constData());
+ } else {
+ QString tmp;
+ QList<QHostAddress> addresses = results.addresses();
+ for (int i = 0; i < addresses.count(); ++i) {
+ if (i != 0) tmp += QLatin1String(", ");
+ tmp += addresses.at(i).toString();
+ }
+ qDebug("QHostInfoAgent::fromName(): found %i entries for \"%s\": {%s}",
+ addresses.count(), aceHostname.constData(),
+ tmp.toLatin1().constData());
+ }
+#endif
+
+ return results;
+}
/*!
\enum QHostInfo::HostInfoError
diff --git a/src/network/kernel/qhostinfo_p.h b/src/network/kernel/qhostinfo_p.h
index da02163ddf..3c0ee2a0d8 100644
--- a/src/network/kernel/qhostinfo_p.h
+++ b/src/network/kernel/qhostinfo_p.h
@@ -127,15 +127,16 @@ Q_SIGNALS:
void resultsReady(const QHostInfo &info);
};
-// needs to be QObject because fromName calls tr()
-class QHostInfoAgent : public QObject
+class QHostInfoAgent
{
- Q_OBJECT
public:
static QHostInfo fromName(const QString &hostName);
#ifndef QT_NO_BEARERMANAGEMENT
static QHostInfo fromName(const QString &hostName, QSharedPointer<QNetworkSession> networkSession);
#endif
+private:
+ static QHostInfo lookup(const QString &hostName);
+ static QHostInfo reverseLookup(const QHostAddress &address);
};
class QHostInfoPrivate
diff --git a/src/network/kernel/qhostinfo_unix.cpp b/src/network/kernel/qhostinfo_unix.cpp
index e4810d68ee..78a05f8407 100644
--- a/src/network/kernel/qhostinfo_unix.cpp
+++ b/src/network/kernel/qhostinfo_unix.cpp
@@ -72,17 +72,6 @@
QT_BEGIN_NAMESPACE
-// Almost always the same. If not, specify in qplatformdefs.h.
-#if !defined(QT_SOCKOPTLEN_T)
-# define QT_SOCKOPTLEN_T QT_SOCKLEN_T
-#endif
-
-// HP-UXi has a bug in getaddrinfo(3) that makes it thread-unsafe
-// with this flag. So disable it in that platform.
-#if defined(AI_ADDRCONFIG) && !defined(Q_OS_HPUX)
-# define Q_ADDRCONFIG AI_ADDRCONFIG
-#endif
-
enum LibResolvFeature {
NeedResInit,
NeedResNInit
@@ -197,132 +186,10 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName)
local_res_init();
QHostAddress address;
- if (address.setAddress(hostName)) {
- // Reverse lookup
- sockaddr_in sa4;
- sockaddr_in6 sa6;
- sockaddr *sa = 0;
- QT_SOCKLEN_T saSize = 0;
- if (address.protocol() == QAbstractSocket::IPv4Protocol) {
- sa = (sockaddr *)&sa4;
- saSize = sizeof(sa4);
- memset(&sa4, 0, sizeof(sa4));
- sa4.sin_family = AF_INET;
- sa4.sin_addr.s_addr = htonl(address.toIPv4Address());
- }
- else {
- sa = (sockaddr *)&sa6;
- saSize = sizeof(sa6);
- memset(&sa6, 0, sizeof(sa6));
- sa6.sin6_family = AF_INET6;
- memcpy(sa6.sin6_addr.s6_addr, address.toIPv6Address().c, sizeof(sa6.sin6_addr.s6_addr));
- }
-
- char hbuf[NI_MAXHOST];
- if (sa && getnameinfo(sa, saSize, hbuf, sizeof(hbuf), 0, 0, 0) == 0)
- results.setHostName(QString::fromLatin1(hbuf));
-
- if (results.hostName().isEmpty())
- results.setHostName(address.toString());
- results.setAddresses(QList<QHostAddress>() << address);
- return results;
- }
-
- // IDN support
- QByteArray aceHostname = QUrl::toAce(hostName);
- results.setHostName(hostName);
- if (aceHostname.isEmpty()) {
- results.setError(QHostInfo::HostNotFound);
- results.setErrorString(hostName.isEmpty() ?
- QCoreApplication::translate("QHostInfoAgent", "No host name given") :
- QCoreApplication::translate("QHostInfoAgent", "Invalid hostname"));
- return results;
- }
-
- // Call getaddrinfo, and place all IPv4 addresses at the start and
- // the IPv6 addresses at the end of the address list in results.
- addrinfo *res = 0;
- struct addrinfo hints;
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = PF_UNSPEC;
-#ifdef Q_ADDRCONFIG
- hints.ai_flags = Q_ADDRCONFIG;
-#endif
+ if (address.setAddress(hostName))
+ return reverseLookup(address);
- int result = getaddrinfo(aceHostname.constData(), 0, &hints, &res);
-# ifdef Q_ADDRCONFIG
- if (result == EAI_BADFLAGS) {
- // if the lookup failed with AI_ADDRCONFIG set, try again without it
- hints.ai_flags = 0;
- result = getaddrinfo(aceHostname.constData(), 0, &hints, &res);
- }
-# endif
-
- if (result == 0) {
- addrinfo *node = res;
- QList<QHostAddress> addresses;
- while (node) {
-#ifdef QHOSTINFO_DEBUG
- qDebug() << "getaddrinfo node: flags:" << node->ai_flags << "family:" << node->ai_family << "ai_socktype:" << node->ai_socktype << "ai_protocol:" << node->ai_protocol << "ai_addrlen:" << node->ai_addrlen;
-#endif
- if (node->ai_family == AF_INET) {
- QHostAddress addr;
- addr.setAddress(ntohl(((sockaddr_in *) node->ai_addr)->sin_addr.s_addr));
- if (!addresses.contains(addr))
- addresses.append(addr);
- }
- else if (node->ai_family == AF_INET6) {
- QHostAddress addr;
- sockaddr_in6 *sa6 = (sockaddr_in6 *) node->ai_addr;
- addr.setAddress(sa6->sin6_addr.s6_addr);
- if (sa6->sin6_scope_id)
- addr.setScopeId(QString::number(sa6->sin6_scope_id));
- if (!addresses.contains(addr))
- addresses.append(addr);
- }
- node = node->ai_next;
- }
- if (addresses.isEmpty() && node == 0) {
- // Reached the end of the list, but no addresses were found; this
- // means the list contains one or more unknown address types.
- results.setError(QHostInfo::UnknownError);
- results.setErrorString(tr("Unknown address type"));
- }
-
- results.setAddresses(addresses);
- freeaddrinfo(res);
- } else if (result == EAI_NONAME
- || result == EAI_FAIL
-#ifdef EAI_NODATA
- // EAI_NODATA is deprecated in RFC 3493
- || result == EAI_NODATA
-#endif
- ) {
- results.setError(QHostInfo::HostNotFound);
- results.setErrorString(tr("Host not found"));
- } else {
- results.setError(QHostInfo::UnknownError);
- results.setErrorString(QString::fromLocal8Bit(gai_strerror(result)));
- }
-
-
-#if defined(QHOSTINFO_DEBUG)
- if (results.error() != QHostInfo::NoError) {
- qDebug("QHostInfoAgent::fromName(): error #%d %s",
- h_errno, results.errorString().toLatin1().constData());
- } else {
- QString tmp;
- QList<QHostAddress> addresses = results.addresses();
- for (int i = 0; i < addresses.count(); ++i) {
- if (i != 0) tmp += ", ";
- tmp += addresses.at(i).toString();
- }
- qDebug("QHostInfoAgent::fromName(): found %i entries for \"%s\": {%s}",
- addresses.count(), hostName.toLatin1().constData(),
- tmp.toLatin1().constData());
- }
-#endif
- return results;
+ return lookup(hostName);
}
QString QHostInfo::localDomainName()
diff --git a/src/network/kernel/qhostinfo_win.cpp b/src/network/kernel/qhostinfo_win.cpp
index c51e9968f8..0b5cc98970 100644
--- a/src/network/kernel/qhostinfo_win.cpp
+++ b/src/network/kernel/qhostinfo_win.cpp
@@ -51,27 +51,10 @@ QT_BEGIN_NAMESPACE
//#define QHOSTINFO_DEBUG
//###
-#define QT_SOCKLEN_T int
#ifndef NI_MAXHOST // already defined to 1025 in ws2tcpip.h?
#define NI_MAXHOST 1024
#endif
-static void translateWSAError(int error, QHostInfo *results)
-{
- switch (error) {
- case WSAHOST_NOT_FOUND: //authoritative not found
- case WSATRY_AGAIN: //non authoritative not found
- case WSANO_DATA: //valid name, no associated address
- results->setError(QHostInfo::HostNotFound);
- results->setErrorString(QHostInfoAgent::tr("Host not found"));
- return;
- default:
- results->setError(QHostInfo::UnknownError);
- results->setErrorString(QHostInfoAgent::tr("Unknown error (%1)").arg(error));
- return;
- }
-}
-
QHostInfo QHostInfoAgent::fromName(const QString &hostName)
{
QSysInfo::machineHostName(); // this initializes ws2_32.dll
@@ -79,98 +62,15 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName)
QHostInfo results;
#if defined(QHOSTINFO_DEBUG)
- qDebug("QHostInfoAgent::fromName(): looking up \"%s\" (IPv6 support is %s)",
- hostName.toLatin1().constData(),
- (getaddrinfo && freeaddrinfo) ? "enabled" : "disabled");
+ qDebug("QHostInfoAgent::fromName(%s) looking up...",
+ hostName.toLatin1().constData());
#endif
QHostAddress address;
- if (address.setAddress(hostName)) {
- // Reverse lookup
- sockaddr_in sa4;
- sockaddr_in6 sa6;
- sockaddr *sa;
- QT_SOCKLEN_T saSize;
- if (address.protocol() == QAbstractSocket::IPv4Protocol) {
- sa = reinterpret_cast<sockaddr *>(&sa4);
- saSize = sizeof(sa4);
- memset(&sa4, 0, sizeof(sa4));
- sa4.sin_family = AF_INET;
- sa4.sin_addr.s_addr = htonl(address.toIPv4Address());
- } else {
- sa = reinterpret_cast<sockaddr *>(&sa6);
- saSize = sizeof(sa6);
- memset(&sa6, 0, sizeof(sa6));
- sa6.sin6_family = AF_INET6;
- memcpy(&sa6.sin6_addr, address.toIPv6Address().c, sizeof(sa6.sin6_addr));
- }
-
- char hbuf[NI_MAXHOST];
- if (getnameinfo(sa, saSize, hbuf, sizeof(hbuf), 0, 0, 0) == 0)
- results.setHostName(QString::fromLatin1(hbuf));
-
- if (results.hostName().isEmpty())
- results.setHostName(address.toString());
- results.setAddresses(QList<QHostAddress>() << address);
- return results;
- }
+ if (address.setAddress(hostName))
+ return reverseLookup(address);
- // IDN support
- QByteArray aceHostname = QUrl::toAce(hostName);
- results.setHostName(hostName);
- if (aceHostname.isEmpty()) {
- results.setError(QHostInfo::HostNotFound);
- results.setErrorString(hostName.isEmpty() ? tr("No host name given") : tr("Invalid hostname"));
- return results;
- }
-
- addrinfo *res;
- int err = getaddrinfo(aceHostname.constData(), 0, 0, &res);
- if (err == 0) {
- QList<QHostAddress> addresses;
- for (addrinfo *p = res; p != 0; p = p->ai_next) {
- switch (p->ai_family) {
- case AF_INET: {
- QHostAddress addr;
- addr.setAddress(ntohl(reinterpret_cast<sockaddr_in *>(p->ai_addr)->sin_addr.s_addr));
- if (!addresses.contains(addr))
- addresses.append(addr);
- }
- break;
- case AF_INET6: {
- QHostAddress addr;
- addr.setAddress(reinterpret_cast<const sockaddr_in6 *>(p->ai_addr)->sin6_addr.s6_addr);
- if (!addresses.contains(addr))
- addresses.append(addr);
- }
- break;
- default:
- results.setError(QHostInfo::UnknownError);
- results.setErrorString(tr("Unknown address type"));
- }
- }
- results.setAddresses(addresses);
- freeaddrinfo(res);
- } else {
- translateWSAError(WSAGetLastError(), &results);
- }
-
-#if defined(QHOSTINFO_DEBUG)
- if (results.error() != QHostInfo::NoError) {
- qDebug("QHostInfoAgent::run(): error (%s)",
- results.errorString().toLatin1().constData());
- } else {
- QString tmp;
- QList<QHostAddress> addresses = results.addresses();
- for (int i = 0; i < addresses.count(); ++i) {
- if (i != 0) tmp += ", ";
- tmp += addresses.at(i).toString();
- }
- qDebug("QHostInfoAgent::run(): found %i entries: {%s}",
- addresses.count(), tmp.toLatin1().constData());
- }
-#endif
- return results;
+ return lookup(hostName);
}
// QString QHostInfo::localDomainName() defined in qnetworkinterface_win.cpp
diff --git a/src/network/kernel/qnetconmonitor_darwin.mm b/src/network/kernel/qnetconmonitor_darwin.mm
new file mode 100644
index 0000000000..a64cd6e530
--- /dev/null
+++ b/src/network/kernel/qnetconmonitor_darwin.mm
@@ -0,0 +1,419 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtNetwork module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "private/qnativesocketengine_p.h"
+#include "private/qnetconmonitor_p.h"
+
+#include "private/qobject_p.h"
+
+#include <SystemConfiguration/SystemConfiguration.h>
+#include <CoreFoundation/CoreFoundation.h>
+
+#include <netinet/in.h>
+
+#include <cstring>
+
+QT_BEGIN_NAMESPACE
+
+Q_LOGGING_CATEGORY(lcNetMon, "qt.network.monitor");
+
+namespace {
+
+class ReachabilityDispatchQueue
+{
+public:
+ ReachabilityDispatchQueue()
+ {
+ queue = dispatch_queue_create("qt-network-reachability-queue", nullptr);
+ if (!queue)
+ qCWarning(lcNetMon, "Failed to create a dispatch queue for reachability probes");
+ }
+
+ ~ReachabilityDispatchQueue()
+ {
+ if (queue)
+ dispatch_release(queue);
+ }
+
+ dispatch_queue_t data() const
+ {
+ return queue;
+ }
+
+private:
+ dispatch_queue_t queue = nullptr;
+
+ Q_DISABLE_COPY_MOVE(ReachabilityDispatchQueue)
+};
+
+dispatch_queue_t qt_reachability_queue()
+{
+ static const ReachabilityDispatchQueue reachabilityQueue;
+ return reachabilityQueue.data();
+}
+
+qt_sockaddr qt_hostaddress_to_sockaddr(const QHostAddress &src)
+{
+ if (src.isNull())
+ return {};
+
+ qt_sockaddr dst;
+ if (src.protocol() == QAbstractSocket::IPv4Protocol) {
+ dst.a4 = sockaddr_in{};
+ dst.a4.sin_family = AF_INET;
+ dst.a4.sin_addr.s_addr = htonl(src.toIPv4Address());
+ dst.a4.sin_len = sizeof(sockaddr_in);
+ } else if (src.protocol() == QAbstractSocket::IPv6Protocol) {
+ dst.a6 = sockaddr_in6{};
+ dst.a6.sin6_family = AF_INET6;
+ dst.a6.sin6_len = sizeof(sockaddr_in6);
+ const Q_IPV6ADDR ipv6 = src.toIPv6Address();
+ std::memcpy(&dst.a6.sin6_addr, &ipv6, sizeof ipv6);
+ } else {
+ Q_UNREACHABLE();
+ }
+
+ return dst;
+}
+
+} // unnamed namespace
+
+class QNetworkConnectionMonitorPrivate : public QObjectPrivate
+{
+public:
+ SCNetworkReachabilityRef probe = nullptr;
+ SCNetworkReachabilityFlags state = kSCNetworkReachabilityFlagsIsLocalAddress;
+ bool scheduled = false;
+
+ void updateState(SCNetworkReachabilityFlags newState);
+ void reset();
+ bool isReachable() const;
+
+ static void probeCallback(SCNetworkReachabilityRef probe, SCNetworkReachabilityFlags flags, void *info);
+
+ Q_DECLARE_PUBLIC(QNetworkConnectionMonitor)
+};
+
+void QNetworkConnectionMonitorPrivate::updateState(SCNetworkReachabilityFlags newState)
+{
+ // To be executed only on the reachability queue.
+ Q_Q(QNetworkConnectionMonitor);
+
+ // NETMONTODO: for now, 'online' for us means kSCNetworkReachabilityFlagsReachable
+ // is set. There are more possible flags that require more tests/some special
+ // setup. So in future this part and related can change/be extended.
+ const bool wasReachable = isReachable();
+ state = newState;
+ if (wasReachable != isReachable())
+ emit q->reachabilityChanged(isReachable());
+}
+
+void QNetworkConnectionMonitorPrivate::reset()
+{
+ if (probe) {
+ CFRelease(probe);
+ probe = nullptr;
+ }
+
+ state = kSCNetworkReachabilityFlagsIsLocalAddress;
+ scheduled = false;
+}
+
+bool QNetworkConnectionMonitorPrivate::isReachable() const
+{
+ return !!(state & kSCNetworkReachabilityFlagsReachable);
+}
+
+void QNetworkConnectionMonitorPrivate::probeCallback(SCNetworkReachabilityRef probe, SCNetworkReachabilityFlags flags, void *info)
+{
+ // To be executed only on the reachability queue.
+ Q_UNUSED(probe);
+
+ auto monitorPrivate = static_cast<QNetworkConnectionMonitorPrivate *>(info);
+ Q_ASSERT(monitorPrivate);
+ monitorPrivate->updateState(flags);
+}
+
+QNetworkConnectionMonitor::QNetworkConnectionMonitor()
+ : QObject(*new QNetworkConnectionMonitorPrivate)
+{
+}
+
+QNetworkConnectionMonitor::QNetworkConnectionMonitor(const QHostAddress &local, const QHostAddress &remote)
+ : QObject(*new QNetworkConnectionMonitorPrivate)
+{
+ setTargets(local, remote);
+}
+
+QNetworkConnectionMonitor::~QNetworkConnectionMonitor()
+{
+ Q_D(QNetworkConnectionMonitor);
+
+ stopMonitoring();
+ d->reset();
+}
+
+bool QNetworkConnectionMonitor::setTargets(const QHostAddress &local, const QHostAddress &remote)
+{
+ Q_D(QNetworkConnectionMonitor);
+
+ if (isMonitoring()) {
+ qCWarning(lcNetMon, "Monitor is already active, call stopMonitoring() first");
+ return false;
+ }
+
+ if (local.isNull()) {
+ qCWarning(lcNetMon, "Invalid (null) local address, cannot create a reachability target");
+ return false;
+ }
+
+ // Clear the old target if needed:
+ d->reset();
+
+ qt_sockaddr client = qt_hostaddress_to_sockaddr(local);
+ if (remote.isNull()) {
+ // That's a special case our QNetworkStatusMonitor is using (AnyIpv4/6 address to check an overall status).
+ d->probe = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, reinterpret_cast<sockaddr *>(&client));
+ } else {
+ qt_sockaddr target = qt_hostaddress_to_sockaddr(remote);
+ d->probe = SCNetworkReachabilityCreateWithAddressPair(kCFAllocatorDefault,
+ reinterpret_cast<sockaddr *>(&client),
+ reinterpret_cast<sockaddr *>(&target));
+ }
+
+ if (d->probe) {
+ // Let's read the initial state so that callback coming later can
+ // see a difference. Ignore errors though.
+ SCNetworkReachabilityGetFlags(d->probe, &d->state);
+ }else {
+ qCWarning(lcNetMon, "Failed to create network reachability probe");
+ return false;
+ }
+
+ return true;
+}
+
+bool QNetworkConnectionMonitor::startMonitoring()
+{
+ Q_D(QNetworkConnectionMonitor);
+
+ if (isMonitoring()) {
+ qCWarning(lcNetMon, "Monitor is already active, call stopMonitoring() first");
+ return false;
+ }
+
+ if (!d->probe) {
+ qCWarning(lcNetMon, "Can not start monitoring, set targets first");
+ return false;
+ }
+
+ auto queue = qt_reachability_queue();
+ if (!queue) {
+ qWarning(lcNetMon, "Failed to create a dispatch queue to schedule a probe on");
+ return false;
+ }
+
+ SCNetworkReachabilityContext context = {};
+ context.info = d;
+ if (!SCNetworkReachabilitySetCallback(d->probe, QNetworkConnectionMonitorPrivate::probeCallback, &context)) {
+ qWarning(lcNetMon, "Failed to set a reachability callback");
+ return false;
+ }
+
+
+ if (!SCNetworkReachabilitySetDispatchQueue(d->probe, queue)) {
+ qWarning(lcNetMon, "Failed to schedule a reachability callback on a queue");
+ return false;
+ }
+
+ return d->scheduled = true;
+}
+
+bool QNetworkConnectionMonitor::isMonitoring() const
+{
+ Q_D(const QNetworkConnectionMonitor);
+
+ return d->scheduled;
+}
+
+void QNetworkConnectionMonitor::stopMonitoring()
+{
+ Q_D(QNetworkConnectionMonitor);
+
+ if (d->scheduled) {
+ Q_ASSERT(d->probe);
+ SCNetworkReachabilitySetDispatchQueue(d->probe, nullptr);
+ SCNetworkReachabilitySetCallback(d->probe, nullptr, nullptr);
+ d->scheduled = false;
+ }
+}
+
+bool QNetworkConnectionMonitor::isReachable()
+{
+ Q_D(QNetworkConnectionMonitor);
+
+ if (isMonitoring()) {
+ qCWarning(lcNetMon, "Calling isReachable() is unsafe after the monitoring started");
+ return false;
+ }
+
+ if (!d->probe) {
+ qCWarning(lcNetMon, "Reachability is unknown, set the target first");
+ return false;
+ }
+
+ return d->isReachable();
+}
+
+class QNetworkStatusMonitorPrivate : public QObjectPrivate
+{
+public:
+ QNetworkConnectionMonitor ipv4Probe;
+ bool isOnlineIpv4 = false;
+ QNetworkConnectionMonitor ipv6Probe;
+ bool isOnlineIpv6 = false;
+};
+
+QNetworkStatusMonitor::QNetworkStatusMonitor()
+ : QObject(*new QNetworkStatusMonitorPrivate)
+{
+ Q_D(QNetworkStatusMonitor);
+
+ if (d->ipv4Probe.setTargets(QHostAddress::AnyIPv4, {})) {
+ // We manage to create SCNetworkReachabilityRef for IPv4, let's
+ // read the last known state then!
+ d->isOnlineIpv4 = d->ipv4Probe.isReachable();
+ }
+
+ if (d->ipv6Probe.setTargets(QHostAddress::AnyIPv6, {})) {
+ // We manage to create SCNetworkReachability ref for IPv6, let's
+ // read the last known state then!
+ d->isOnlineIpv6 = d->ipv6Probe.isReachable();
+ }
+
+
+ connect(&d->ipv4Probe, &QNetworkConnectionMonitor::reachabilityChanged, this,
+ &QNetworkStatusMonitor::reachabilityChanged, Qt::QueuedConnection);
+ connect(&d->ipv6Probe, &QNetworkConnectionMonitor::reachabilityChanged, this,
+ &QNetworkStatusMonitor::reachabilityChanged, Qt::QueuedConnection);
+}
+
+QNetworkStatusMonitor::~QNetworkStatusMonitor()
+{
+ Q_D(QNetworkStatusMonitor);
+
+ d->ipv4Probe.disconnect();
+ d->ipv4Probe.stopMonitoring();
+ d->ipv6Probe.disconnect();
+ d->ipv6Probe.stopMonitoring();
+}
+
+bool QNetworkStatusMonitor::start()
+{
+ Q_D(QNetworkStatusMonitor);
+
+ if (isMonitoring()) {
+ qCWarning(lcNetMon, "Network status monitor is already active");
+ return true;
+ }
+
+ d->ipv4Probe.startMonitoring();
+ d->ipv6Probe.startMonitoring();
+
+ return isMonitoring();
+}
+
+void QNetworkStatusMonitor::stop()
+{
+ Q_D(QNetworkStatusMonitor);
+
+ if (d->ipv4Probe.isMonitoring())
+ d->ipv4Probe.stopMonitoring();
+ if (d->ipv6Probe.isMonitoring())
+ d->ipv6Probe.stopMonitoring();
+}
+
+bool QNetworkStatusMonitor::isMonitoring() const
+{
+ Q_D(const QNetworkStatusMonitor);
+
+ return d->ipv4Probe.isMonitoring() || d->ipv6Probe.isMonitoring();
+}
+
+bool QNetworkStatusMonitor::isNetworkAccesible()
+{
+ // This function is to be executed on the thread that created
+ // and uses 'this'.
+ Q_D(QNetworkStatusMonitor);
+
+ return d->isOnlineIpv4 || d->isOnlineIpv6;
+}
+
+bool QNetworkStatusMonitor::isEnabled()
+{
+ return true;
+}
+
+void QNetworkStatusMonitor::reachabilityChanged(bool online)
+{
+ // This function is executed on the thread that created/uses 'this',
+ // not on the reachability queue.
+ Q_D(QNetworkStatusMonitor);
+
+ auto probe = qobject_cast<QNetworkConnectionMonitor *>(sender());
+ if (!probe)
+ return;
+
+ const bool isIpv4 = probe == &d->ipv4Probe;
+ bool &probeOnline = isIpv4 ? d->isOnlineIpv4 : d->isOnlineIpv6;
+ bool otherOnline = isIpv4 ? d->isOnlineIpv6 : d->isOnlineIpv4;
+
+ if (probeOnline == online) {
+ // We knew this already?
+ return;
+ }
+
+ probeOnline = online;
+ if (!otherOnline) {
+ // We either just lost or got a network access.
+ emit onlineStateChanged(probeOnline);
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/src/network/kernel/qnetconmonitor_p.h b/src/network/kernel/qnetconmonitor_p.h
new file mode 100644
index 0000000000..74ee56d422
--- /dev/null
+++ b/src/network/kernel/qnetconmonitor_p.h
@@ -0,0 +1,126 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtNetwork module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QNETCONMONITOR_P_H
+#define QNETCONMONITOR_P_H
+
+#include <private/qtnetworkglobal_p.h>
+
+#include <QtCore/qloggingcategory.h>
+#include <QtNetwork/qhostaddress.h>
+#include <QtCore/qglobal.h>
+#include <QtCore/qobject.h>
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+QT_BEGIN_NAMESPACE
+
+class QNetworkConnectionMonitorPrivate;
+class QNetworkConnectionMonitor : public QObject
+{
+ Q_OBJECT
+
+public:
+ QNetworkConnectionMonitor();
+ QNetworkConnectionMonitor(const QHostAddress &local, const QHostAddress &remote = {});
+ ~QNetworkConnectionMonitor();
+
+ bool setTargets(const QHostAddress &local, const QHostAddress &remote);
+ bool isReachable();
+
+ // Important: on Darwin you should not call isReachable() after
+ // startMonitoring(), you have to listen to reachabilityChanged()
+ // signal instead.
+ bool startMonitoring();
+ bool isMonitoring() const;
+ void stopMonitoring();
+
+Q_SIGNALS:
+ // Important: connect to this using QueuedConnection. On Darwin
+ // callback is coming on a special dispatch queue.
+ void reachabilityChanged(bool isOnline);
+
+private:
+ Q_DECLARE_PRIVATE(QNetworkConnectionMonitor)
+ Q_DISABLE_COPY_MOVE(QNetworkConnectionMonitor)
+};
+
+class QNetworkStatusMonitorPrivate;
+class QNetworkStatusMonitor : public QObject
+{
+ Q_OBJECT
+
+public:
+ QNetworkStatusMonitor();
+ ~QNetworkStatusMonitor();
+
+ bool isNetworkAccesible();
+
+ bool start();
+ void stop();
+ bool isMonitoring() const;
+
+ static bool isEnabled();
+
+Q_SIGNALS:
+ // Unlike QNetworkConnectionMonitor, this can be connected to directly.
+ void onlineStateChanged(bool isOnline);
+
+private slots:
+ void reachabilityChanged(bool isOnline);
+
+private:
+ Q_DECLARE_PRIVATE(QNetworkStatusMonitor)
+ Q_DISABLE_COPY_MOVE(QNetworkStatusMonitor)
+};
+
+Q_DECLARE_LOGGING_CATEGORY(lcNetMon)
+
+QT_END_NAMESPACE
+
+#endif // QNETCONMONITOR_P_H
diff --git a/src/network/kernel/qnetconmonitor_stub.cpp b/src/network/kernel/qnetconmonitor_stub.cpp
new file mode 100644
index 0000000000..7f3a0c44c6
--- /dev/null
+++ b/src/network/kernel/qnetconmonitor_stub.cpp
@@ -0,0 +1,141 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtNetwork module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qnetconmonitor_p.h"
+
+#include "private/qobject_p.h"
+
+QT_BEGIN_NAMESPACE
+
+Q_LOGGING_CATEGORY(lcNetMon, "qt.network.monitor");
+
+// Note: this 'stub' version is never enabled (see QNetworkStatusMonitor::isEnabled below)
+// and thus should never affect QNAM in any unusuall way. Having this 'stub' version is similar
+// to building Qt with bearer management configured out.
+
+class QNetworkConnectionMonitorPrivate : public QObjectPrivate
+{
+};
+
+QNetworkConnectionMonitor::QNetworkConnectionMonitor()
+ : QObject(*new QNetworkConnectionMonitorPrivate)
+{
+}
+
+QNetworkConnectionMonitor::QNetworkConnectionMonitor(const QHostAddress &local, const QHostAddress &remote)
+ : QObject(*new QNetworkConnectionMonitorPrivate)
+{
+ Q_UNUSED(local)
+ Q_UNUSED(remote)
+}
+
+QNetworkConnectionMonitor::~QNetworkConnectionMonitor()
+{
+}
+
+bool QNetworkConnectionMonitor::setTargets(const QHostAddress &local, const QHostAddress &remote)
+{
+ Q_UNUSED(local)
+ Q_UNUSED(remote)
+
+ return false;
+}
+
+bool QNetworkConnectionMonitor::startMonitoring()
+{
+ return false;
+}
+
+bool QNetworkConnectionMonitor::isMonitoring() const
+{
+ return false;
+}
+
+void QNetworkConnectionMonitor::stopMonitoring()
+{
+}
+
+bool QNetworkConnectionMonitor::isReachable()
+{
+ return false;
+}
+
+class QNetworkStatusMonitorPrivate : public QObjectPrivate
+{
+};
+
+QNetworkStatusMonitor::QNetworkStatusMonitor()
+ : QObject(*new QNetworkStatusMonitorPrivate)
+{
+}
+
+QNetworkStatusMonitor::~QNetworkStatusMonitor()
+{
+}
+
+bool QNetworkStatusMonitor::start()
+{
+ return false;
+}
+
+void QNetworkStatusMonitor::stop()
+{
+}
+
+bool QNetworkStatusMonitor::isMonitoring() const
+{
+ return false;
+}
+
+bool QNetworkStatusMonitor::isNetworkAccesible()
+{
+ return false;
+}
+
+bool QNetworkStatusMonitor::isEnabled()
+{
+ return false;
+}
+
+void QNetworkStatusMonitor::reachabilityChanged(bool online)
+{
+ Q_UNUSED(online)
+}
+
+QT_END_NAMESPACE
diff --git a/src/network/kernel/qnetworkinterface.h b/src/network/kernel/qnetworkinterface.h
index 1d3286118e..4caedaa38f 100644
--- a/src/network/kernel/qnetworkinterface.h
+++ b/src/network/kernel/qnetworkinterface.h
@@ -64,9 +64,7 @@ public:
QNetworkAddressEntry();
QNetworkAddressEntry(const QNetworkAddressEntry &other);
-#ifdef Q_COMPILER_RVALUE_REFS
QNetworkAddressEntry &operator=(QNetworkAddressEntry &&other) noexcept { swap(other); return *this; }
-#endif
QNetworkAddressEntry &operator=(const QNetworkAddressEntry &other);
~QNetworkAddressEntry();
@@ -142,9 +140,7 @@ public:
QNetworkInterface();
QNetworkInterface(const QNetworkInterface &other);
-#ifdef Q_COMPILER_RVALUE_REFS
QNetworkInterface &operator=(QNetworkInterface &&other) noexcept { swap(other); return *this; }
-#endif
QNetworkInterface &operator=(const QNetworkInterface &other);
~QNetworkInterface();
diff --git a/src/network/kernel/qnetworkproxy.h b/src/network/kernel/qnetworkproxy.h
index 0b1bc02695..302a2ce6ca 100644
--- a/src/network/kernel/qnetworkproxy.h
+++ b/src/network/kernel/qnetworkproxy.h
@@ -89,9 +89,7 @@ public:
QueryType queryType = TcpServer);
#endif
QNetworkProxyQuery(const QNetworkProxyQuery &other);
-#ifdef Q_COMPILER_RVALUE_REFS
QNetworkProxyQuery &operator=(QNetworkProxyQuery &&other) noexcept { swap(other); return *this; }
-#endif
QNetworkProxyQuery &operator=(const QNetworkProxyQuery &other);
~QNetworkProxyQuery();
@@ -161,9 +159,7 @@ public:
QNetworkProxy(ProxyType type, const QString &hostName = QString(), quint16 port = 0,
const QString &user = QString(), const QString &password = QString());
QNetworkProxy(const QNetworkProxy &other);
-#ifdef Q_COMPILER_RVALUE_REFS
QNetworkProxy &operator=(QNetworkProxy &&other) noexcept { swap(other); return *this; }
-#endif
QNetworkProxy &operator=(const QNetworkProxy &other);
~QNetworkProxy();
diff --git a/src/network/socket/qlocalserver.cpp b/src/network/socket/qlocalserver.cpp
index c5bd599a51..3e36a7b229 100644
--- a/src/network/socket/qlocalserver.cpp
+++ b/src/network/socket/qlocalserver.cpp
@@ -408,7 +408,7 @@ int QLocalServer::maxPendingConnections() const
still a good idea to delete the object explicitly when you are done with
it, to avoid wasting memory.
- 0 is returned if this function is called when there are no pending
+ \nullptr is returned if this function is called when there are no pending
connections.
\sa hasPendingConnections(), newConnection(), incomingConnection()
diff --git a/src/network/socket/qnativesocketengine_winrt.cpp b/src/network/socket/qnativesocketengine_winrt.cpp
index 7ac6297de6..2eb2141fee 100644
--- a/src/network/socket/qnativesocketengine_winrt.cpp
+++ b/src/network/socket/qnativesocketengine_winrt.cpp
@@ -875,8 +875,14 @@ void QNativeSocketEngine::close()
if (d->closingDown)
return;
- if (d->pendingReadNotification)
+ if (d->pendingReadNotification) {
+ // We use QPointer here to see if this QNativeSocketEngine was deleted as a result of
+ // finishing and cleaning up a network request when calling "processReadReady".
+ QPointer<QNativeSocketEngine> alive(this);
processReadReady();
+ if (alive.isNull())
+ return;
+ }
d->closingDown = true;
diff --git a/src/network/socket/qsctpserver.cpp b/src/network/socket/qsctpserver.cpp
index 77cb997192..2aa694b3fd 100644
--- a/src/network/socket/qsctpserver.cpp
+++ b/src/network/socket/qsctpserver.cpp
@@ -229,13 +229,12 @@ QSctpSocket *QSctpServer::nextPendingDatagramConnection()
{
Q_D(QSctpServer);
- QMutableListIterator<QTcpSocket *> i(d->pendingConnections);
- while (i.hasNext()) {
- QSctpSocket *socket = qobject_cast<QSctpSocket *>(i.next());
+ for (auto it = d->pendingConnections.begin(), end = d->pendingConnections.end(); it != end; ++it) {
+ QSctpSocket *socket = qobject_cast<QSctpSocket *>(*it);
Q_ASSERT(socket);
if (socket->isInDatagramMode()) {
- i.remove();
+ d->pendingConnections.erase(it);
Q_ASSERT(d->socketEngine);
d->socketEngine->setReadNotificationEnabled(true);
return socket;
diff --git a/src/network/socket/qtcpserver.cpp b/src/network/socket/qtcpserver.cpp
index 56c700ca8f..98e58192a2 100644
--- a/src/network/socket/qtcpserver.cpp
+++ b/src/network/socket/qtcpserver.cpp
@@ -548,7 +548,7 @@ bool QTcpServer::hasPendingConnections() const
destroyed. It is still a good idea to delete the object
explicitly when you are done with it, to avoid wasting memory.
- 0 is returned if this function is called when there are no pending
+ \nullptr is returned if this function is called when there are no pending
connections.
\note The returned QTcpSocket object cannot be used from another
diff --git a/src/network/socket/socket.pri b/src/network/socket/socket.pri
index 44ff5b7b39..c3a98ea31a 100644
--- a/src/network/socket/socket.pri
+++ b/src/network/socket/socket.pri
@@ -58,7 +58,7 @@ unix {
msvc: QMAKE_MOC_OPTIONS += -D_WINSOCK_DEPRECATED_NO_WARNINGS
win32:!winrt:SOURCES += socket/qnativesocketengine_win.cpp
-win32:!winrt:LIBS_PRIVATE += -ladvapi32
+win32:!winrt: QMAKE_USE_PRIVATE += advapi32
winrt {
SOURCES += socket/qnativesocketengine_winrt.cpp
diff --git a/src/network/ssl/qsslcertificate.cpp b/src/network/ssl/qsslcertificate.cpp
index 0156b5bf96..4820953468 100644
--- a/src/network/ssl/qsslcertificate.cpp
+++ b/src/network/ssl/qsslcertificate.cpp
@@ -417,7 +417,7 @@ QByteArray QSslCertificate::digest(QCryptographicHash::Algorithm algorithm) cons
/*!
\fn Qt::HANDLE QSslCertificate::handle() const
Returns a pointer to the native certificate handle, if there is
- one, or a null pointer otherwise.
+ one, else \nullptr.
You can use this handle, together with the native API, to access
extended information about the certificate.
diff --git a/src/network/ssl/qsslcertificate.h b/src/network/ssl/qsslcertificate.h
index a6acfa2cc3..69901b526c 100644
--- a/src/network/ssl/qsslcertificate.h
+++ b/src/network/ssl/qsslcertificate.h
@@ -88,9 +88,7 @@ public:
explicit QSslCertificate(const QByteArray &data = QByteArray(), QSsl::EncodingFormat format = QSsl::Pem);
QSslCertificate(const QSslCertificate &other);
~QSslCertificate();
-#ifdef Q_COMPILER_RVALUE_REFS
QSslCertificate &operator=(QSslCertificate &&other) noexcept { swap(other); return *this; }
-#endif
QSslCertificate &operator=(const QSslCertificate &other);
void swap(QSslCertificate &other) noexcept
diff --git a/src/network/ssl/qsslcertificateextension.h b/src/network/ssl/qsslcertificateextension.h
index f862015312..7cc8a888be 100644
--- a/src/network/ssl/qsslcertificateextension.h
+++ b/src/network/ssl/qsslcertificateextension.h
@@ -55,9 +55,7 @@ class Q_NETWORK_EXPORT QSslCertificateExtension
public:
QSslCertificateExtension();
QSslCertificateExtension(const QSslCertificateExtension &other);
-#ifdef Q_COMPILER_RVALUE_REFS
QSslCertificateExtension &operator=(QSslCertificateExtension &&other) noexcept { swap(other); return *this; }
-#endif
QSslCertificateExtension &operator=(const QSslCertificateExtension &other);
~QSslCertificateExtension();
diff --git a/src/network/ssl/qsslcipher.h b/src/network/ssl/qsslcipher.h
index 430fe9aa7c..6994f590ae 100644
--- a/src/network/ssl/qsslcipher.h
+++ b/src/network/ssl/qsslcipher.h
@@ -59,9 +59,7 @@ public:
explicit QSslCipher(const QString &name);
QSslCipher(const QString &name, QSsl::SslProtocol protocol);
QSslCipher(const QSslCipher &other);
-#ifdef Q_COMPILER_RVALUE_REFS
QSslCipher &operator=(QSslCipher &&other) noexcept { swap(other); return *this; }
-#endif
QSslCipher &operator=(const QSslCipher &other);
~QSslCipher();
diff --git a/src/network/ssl/qsslconfiguration.h b/src/network/ssl/qsslconfiguration.h
index 16704ba17b..c25c2686de 100644
--- a/src/network/ssl/qsslconfiguration.h
+++ b/src/network/ssl/qsslconfiguration.h
@@ -85,9 +85,7 @@ public:
QSslConfiguration();
QSslConfiguration(const QSslConfiguration &other);
~QSslConfiguration();
-#ifdef Q_COMPILER_RVALUE_REFS
QSslConfiguration &operator=(QSslConfiguration &&other) noexcept { swap(other); return *this; }
-#endif
QSslConfiguration &operator=(const QSslConfiguration &other);
void swap(QSslConfiguration &other) noexcept
diff --git a/src/network/ssl/qsslerror.cpp b/src/network/ssl/qsslerror.cpp
index ff54c2ad20..3e822fe852 100644
--- a/src/network/ssl/qsslerror.cpp
+++ b/src/network/ssl/qsslerror.cpp
@@ -86,6 +86,7 @@
\value UnspecifiedError
\value NoSslSupport
\value CertificateBlacklisted
+ \value CertificateStatusUnknown
\value OcspNoResponseFound
\value OcspMalformedRequest
\value OcspMalformedResponse
diff --git a/src/network/ssl/qsslerror.h b/src/network/ssl/qsslerror.h
index a9c46c8571..c4a0d52193 100644
--- a/src/network/ssl/qsslerror.h
+++ b/src/network/ssl/qsslerror.h
@@ -107,9 +107,7 @@ public:
{ qSwap(d, other.d); }
~QSslError();
-#ifdef Q_COMPILER_RVALUE_REFS
QSslError &operator=(QSslError &&other) noexcept { swap(other); return *this; }
-#endif
QSslError &operator=(const QSslError &other);
bool operator==(const QSslError &other) const;
inline bool operator!=(const QSslError &other) const
diff --git a/src/network/ssl/qsslkey.h b/src/network/ssl/qsslkey.h
index a865f20a51..74be406539 100644
--- a/src/network/ssl/qsslkey.h
+++ b/src/network/ssl/qsslkey.h
@@ -71,9 +71,8 @@ public:
const QByteArray &passPhrase = QByteArray());
explicit QSslKey(Qt::HANDLE handle, QSsl::KeyType type = QSsl::PrivateKey);
QSslKey(const QSslKey &other);
-#ifdef Q_COMPILER_RVALUE_REFS
- QSslKey &operator=(QSslKey &&other) noexcept { swap(other); return *this; }
-#endif
+ QSslKey(QSslKey &&other) noexcept;
+ QSslKey &operator=(QSslKey &&other) noexcept;
QSslKey &operator=(const QSslKey &other);
~QSslKey();
diff --git a/src/network/ssl/qsslkey_p.cpp b/src/network/ssl/qsslkey_p.cpp
index b29b38beab..b0d6c729f9 100644
--- a/src/network/ssl/qsslkey_p.cpp
+++ b/src/network/ssl/qsslkey_p.cpp
@@ -385,6 +385,24 @@ QSslKey::QSslKey(const QSslKey &other) : d(other.d)
{
}
+QSslKey::QSslKey(QSslKey &&other) noexcept
+ : d(nullptr)
+{
+ qSwap(d, other.d);
+}
+
+QSslKey &QSslKey::operator=(QSslKey &&other) noexcept
+{
+ if (this == &other)
+ return *this;
+
+ // If no one else is referencing the key data we want to make sure
+ // before we swap the d-ptr that it is not left in memory.
+ d.reset();
+ qSwap(d, other.d);
+ return *this;
+}
+
/*!
Destroys the QSslKey object.
*/
@@ -490,8 +508,8 @@ QByteArray QSslKey::toPem(const QByteArray &passPhrase) const
}
/*!
- Returns a pointer to the native key handle, if it is available;
- otherwise a null pointer is returned.
+ Returns a pointer to the native key handle, if there is
+ one, else \nullptr.
You can use this handle together with the native API to access
extended information about the key.
diff --git a/src/network/ssl/qsslkey_qt.cpp b/src/network/ssl/qsslkey_qt.cpp
index 2662418a05..43969c3d28 100644
--- a/src/network/ssl/qsslkey_qt.cpp
+++ b/src/network/ssl/qsslkey_qt.cpp
@@ -48,6 +48,8 @@
#include <QtNetwork/qpassworddigestor.h>
+#include <cstring>
+
QT_USE_NAMESPACE
static const quint8 bits_table[256] = {
@@ -186,8 +188,9 @@ static QByteArray deriveKey(QSslKeyPrivate::Cipher cipher, const QByteArray &pas
void QSslKeyPrivate::clear(bool deep)
{
- Q_UNUSED(deep);
isNull = true;
+ if (deep)
+ std::memset(derData.data(), 0, derData.size());
derData.clear();
keyLength = -1;
}
diff --git a/src/network/ssl/qsslpresharedkeyauthenticator.h b/src/network/ssl/qsslpresharedkeyauthenticator.h
index 29d647b121..5d714dc34e 100644
--- a/src/network/ssl/qsslpresharedkeyauthenticator.h
+++ b/src/network/ssl/qsslpresharedkeyauthenticator.h
@@ -59,9 +59,7 @@ public:
Q_NETWORK_EXPORT QSslPreSharedKeyAuthenticator(const QSslPreSharedKeyAuthenticator &authenticator);
Q_NETWORK_EXPORT QSslPreSharedKeyAuthenticator &operator=(const QSslPreSharedKeyAuthenticator &authenticator);
-#ifdef Q_COMPILER_RVALUE_REFS
QSslPreSharedKeyAuthenticator &operator=(QSslPreSharedKeyAuthenticator &&other) noexcept { swap(other); return *this; }
-#endif
void swap(QSslPreSharedKeyAuthenticator &other) noexcept { qSwap(d, other.d); }
diff --git a/src/network/ssl/qsslsocket.cpp b/src/network/ssl/qsslsocket.cpp
index 4e6caf3edd..fe81bd5fcf 100644
--- a/src/network/ssl/qsslsocket.cpp
+++ b/src/network/ssl/qsslsocket.cpp
@@ -761,8 +761,8 @@ qint64 QSslSocket::bytesAvailable() const
{
Q_D(const QSslSocket);
if (d->mode == UnencryptedMode)
- return QIODevice::bytesAvailable() + (d->plainSocket ? d->plainSocket->bytesAvailable() : 0);
- return QIODevice::bytesAvailable();
+ return QAbstractSocket::bytesAvailable() + (d->plainSocket ? d->plainSocket->bytesAvailable() : 0);
+ return QAbstractSocket::bytesAvailable();
}
/*!
@@ -818,8 +818,8 @@ bool QSslSocket::canReadLine() const
{
Q_D(const QSslSocket);
if (d->mode == UnencryptedMode)
- return QIODevice::canReadLine() || (d->plainSocket && d->plainSocket->canReadLine());
- return QIODevice::canReadLine();
+ return QAbstractSocket::canReadLine() || (d->plainSocket && d->plainSocket->canReadLine());
+ return QAbstractSocket::canReadLine();
}
/*!
@@ -849,8 +849,8 @@ bool QSslSocket::atEnd() const
{
Q_D(const QSslSocket);
if (d->mode == UnencryptedMode)
- return QIODevice::atEnd() && (!d->plainSocket || d->plainSocket->atEnd());
- return QIODevice::atEnd();
+ return QAbstractSocket::atEnd() && (!d->plainSocket || d->plainSocket->atEnd());
+ return QAbstractSocket::atEnd();
}
/*!
diff --git a/src/network/ssl/qsslsocket_openssl_symbols.cpp b/src/network/ssl/qsslsocket_openssl_symbols.cpp
index e04d45c10c..6f935a02e4 100644
--- a/src/network/ssl/qsslsocket_openssl_symbols.cpp
+++ b/src/network/ssl/qsslsocket_openssl_symbols.cpp
@@ -693,7 +693,7 @@ static QStringList libraryPathList()
// discover paths of already loaded libraries
QSet<QString> loadedPaths;
dl_iterate_phdr(dlIterateCallback, &loadedPaths);
- paths.append(loadedPaths.toList());
+ paths.append(loadedPaths.values());
#endif
return paths;