From 5234c6c6a8b8ee7cc33dde41c37dd3866c99405b Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Fri, 7 Feb 2020 15:00:55 +0100 Subject: Account for a reply that is finished before we can connect the signals In a case where a connection is refused, then it is possible for it to fail at the time that the QHttpNetworkReply is being created and therefore after the connections have been made it would have already emitted the signal to indicate it was finished with an error. To account for this, then it checks if there is an error code set on the reply and if there is then it will call the relevant slot right away. Fixes: QTBUG-57799 Change-Id: I4e73e5c82092c09f825343d18db40b47c3cdb9ac Reviewed-by: Timur Pocheptsov --- src/network/access/qhttpnetworkconnectionchannel.cpp | 1 + src/network/access/qhttpnetworkreply.cpp | 5 +++++ src/network/access/qhttpnetworkreply_p.h | 3 +++ src/network/access/qhttpthreaddelegate.cpp | 6 ++++++ 4 files changed, 15 insertions(+) (limited to 'src/network') diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp index 39f392a79b..e81f042bdc 100644 --- a/src/network/access/qhttpnetworkconnectionchannel.cpp +++ b/src/network/access/qhttpnetworkconnectionchannel.cpp @@ -1099,6 +1099,7 @@ void QHttpNetworkConnectionChannel::_q_error(QAbstractSocket::SocketError socket if (reply) { reply->d_func()->errorString = errorString; + reply->d_func()->httpErrorCode = errorCode; emit reply->finishedWithError(errorCode, errorString); reply = 0; if (protocolHandler) diff --git a/src/network/access/qhttpnetworkreply.cpp b/src/network/access/qhttpnetworkreply.cpp index a8b635c45a..7ccac88878 100644 --- a/src/network/access/qhttpnetworkreply.cpp +++ b/src/network/access/qhttpnetworkreply.cpp @@ -158,6 +158,11 @@ QString QHttpNetworkReply::errorString() const return d_func()->errorString; } +QNetworkReply::NetworkError QHttpNetworkReply::errorCode() const +{ + return d_func()->httpErrorCode; +} + QString QHttpNetworkReply::reasonPhrase() const { return d_func()->reasonPhrase; diff --git a/src/network/access/qhttpnetworkreply_p.h b/src/network/access/qhttpnetworkreply_p.h index 12cfe359aa..9c03a403e1 100644 --- a/src/network/access/qhttpnetworkreply_p.h +++ b/src/network/access/qhttpnetworkreply_p.h @@ -115,6 +115,8 @@ public: QString errorString() const; void setErrorString(const QString &error); + QNetworkReply::NetworkError errorCode() const; + QString reasonPhrase() const; qint64 bytesAvailable() const; @@ -259,6 +261,7 @@ public: qint64 removedContentLength; QPointer connection; QPointer connectionChannel; + QNetworkReply::NetworkError httpErrorCode = QNetworkReply::NoError; bool autoDecompress; diff --git a/src/network/access/qhttpthreaddelegate.cpp b/src/network/access/qhttpthreaddelegate.cpp index 63a3c4f204..de14260d69 100644 --- a/src/network/access/qhttpthreaddelegate.cpp +++ b/src/network/access/qhttpthreaddelegate.cpp @@ -428,6 +428,12 @@ void QHttpThreadDelegate::startRequest() connect(httpReply, SIGNAL(cacheCredentials(QHttpNetworkRequest,QAuthenticator*)), this, SLOT(cacheCredentialsSlot(QHttpNetworkRequest,QAuthenticator*))); + if (httpReply->errorCode() != QNetworkReply::NoError) { + if (synchronous) + synchronousFinishedWithErrorSlot(httpReply->errorCode(), httpReply->errorString()); + else + finishedWithErrorSlot(httpReply->errorCode(), httpReply->errorString()); + } } // This gets called from the user thread or by the synchronous HTTP timeout timer -- cgit v1.2.3 From 5ff37f13ee577c006f0b99307d0afa1cf991db08 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 7 Feb 2020 12:21:33 -0800 Subject: QTcpSocket::bind: fix issue found by BLACKLIST The comment in QNativeSocketEnginePrivate::fetchConnectionParameters() talked about IPv6 v4-mapped addresses. However, toIPv4Address also converts the unspecified address (::), which resulted in QAbstractSocket saying that it had bound to QHostAddress::Any instead of QHostAddress::AnyV6 Change-Id: I572733186b73423b89e5fffd15f138579c5c0c50 Reviewed-by: Timur Pocheptsov --- src/network/socket/qnativesocketengine_win.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/network') diff --git a/src/network/socket/qnativesocketengine_win.cpp b/src/network/socket/qnativesocketengine_win.cpp index 9edabd7822..78be0a7e0f 100644 --- a/src/network/socket/qnativesocketengine_win.cpp +++ b/src/network/socket/qnativesocketengine_win.cpp @@ -588,7 +588,8 @@ bool QNativeSocketEnginePrivate::fetchConnectionParameters() // local address of the socket which bound on both IPv4 and IPv6 interfaces. // This address does not match to any special address and should not be used // to send the data. So, replace it with QHostAddress::Any. - if (socketProtocol == QAbstractSocket::IPv6Protocol) { + const uchar ipv6MappedNet[] = {0,0,0,0, 0,0,0,0, 0,0,0xff,0xff, 0,0,0,0}; + if (localAddress.isInSubnet(QHostAddress(ipv6MappedNet), 128 - 32)) { bool ok = false; const quint32 localIPv4 = localAddress.toIPv4Address(&ok); if (ok && localIPv4 == INADDR_ANY) { -- cgit v1.2.3 From 6c3bca01d908bcef149e7339a1268ce79fe8eefa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Tue, 11 Feb 2020 16:48:19 +0100 Subject: QNetConMonitor(Win): Account for LOCALNETWORK reachability What I originally thought NLM_CONNECTIVITY_IPV*_SUBNET meant turns out to be what NLM_CONNECTIVITY_IPV*_LOCALNETWORK is, leaving me to wonder when *_SUBNET is actually used. Anyway we now also check *_LOCALNETWORK to make sure we're not unnecessarily denying certain connections to be made. At the same time check for link-local connections where both local and remote are link-local, in this case even NLM_CONNECTIVITY_IPV*_NOTRAFFIC is valid. Unfortunately this check cannot be done in QNetworkStatusMonitor, so QNAM will likely not allow these connections. Task-number: QTBUG-80947 Change-Id: Ieb96ce9f4a478eef0c3ea47f2471f701c102b4d4 Reviewed-by: Timur Pocheptsov --- src/network/kernel/qnetconmonitor_win.cpp | 38 +++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 7 deletions(-) (limited to 'src/network') diff --git a/src/network/kernel/qnetconmonitor_win.cpp b/src/network/kernel/qnetconmonitor_win.cpp index 1566e7f914..59b6cd5b66 100644 --- a/src/network/kernel/qnetconmonitor_win.cpp +++ b/src/network/kernel/qnetconmonitor_win.cpp @@ -163,11 +163,14 @@ private: ComPtr connectionEvents; // We can assume we have access to internet/subnet when this class is created because // connection has already been established to the peer: - NLM_CONNECTIVITY connectivity = - NLM_CONNECTIVITY(NLM_CONNECTIVITY_IPV4_INTERNET | NLM_CONNECTIVITY_IPV6_INTERNET - | NLM_CONNECTIVITY_IPV4_SUBNET | NLM_CONNECTIVITY_IPV6_SUBNET); + NLM_CONNECTIVITY connectivity = NLM_CONNECTIVITY( + NLM_CONNECTIVITY_IPV4_INTERNET | NLM_CONNECTIVITY_IPV6_INTERNET + | NLM_CONNECTIVITY_IPV4_SUBNET | NLM_CONNECTIVITY_IPV6_SUBNET + | NLM_CONNECTIVITY_IPV4_LOCALNETWORK | NLM_CONNECTIVITY_IPV6_LOCALNETWORK + | NLM_CONNECTIVITY_IPV4_NOTRAFFIC | NLM_CONNECTIVITY_IPV6_NOTRAFFIC); bool sameSubnet = false; + bool isLinkLocal = false; bool monitoring = false; bool comInitFailed = false; bool remoteIsIPv6 = false; @@ -370,6 +373,7 @@ bool QNetworkConnectionMonitorPrivate::setTargets(const QHostAddress &local, return false; } sameSubnet = remote.isInSubnet(local, it->prefixLength()); + isLinkLocal = remote.isLinkLocal() && local.isLinkLocal(); remoteIsIPv6 = remote.protocol() == QAbstractSocket::IPv6Protocol; return connectionEvents->setTarget(iface); @@ -461,9 +465,28 @@ void QNetworkConnectionMonitor::stopMonitoring() bool QNetworkConnectionMonitor::isReachable() { Q_D(QNetworkConnectionMonitor); - NLM_CONNECTIVITY required = d->sameSubnet - ? (d->remoteIsIPv6 ? NLM_CONNECTIVITY_IPV6_SUBNET : NLM_CONNECTIVITY_IPV4_SUBNET) - : (d->remoteIsIPv6 ? NLM_CONNECTIVITY_IPV6_INTERNET : NLM_CONNECTIVITY_IPV4_INTERNET); + + const NLM_CONNECTIVITY RequiredSameSubnetIPv6 = + NLM_CONNECTIVITY(NLM_CONNECTIVITY_IPV6_SUBNET | NLM_CONNECTIVITY_IPV6_LOCALNETWORK + | NLM_CONNECTIVITY_IPV6_INTERNET); + const NLM_CONNECTIVITY RequiredSameSubnetIPv4 = + NLM_CONNECTIVITY(NLM_CONNECTIVITY_IPV4_SUBNET | NLM_CONNECTIVITY_IPV4_LOCALNETWORK + | NLM_CONNECTIVITY_IPV4_INTERNET); + + NLM_CONNECTIVITY required; + if (d->isLinkLocal) { + required = NLM_CONNECTIVITY( + d->remoteIsIPv6 ? NLM_CONNECTIVITY_IPV6_NOTRAFFIC | RequiredSameSubnetIPv6 + : NLM_CONNECTIVITY_IPV4_NOTRAFFIC | RequiredSameSubnetIPv4); + } else if (d->sameSubnet) { + required = + NLM_CONNECTIVITY(d->remoteIsIPv6 ? RequiredSameSubnetIPv6 : RequiredSameSubnetIPv4); + + } else { + required = NLM_CONNECTIVITY(d->remoteIsIPv6 ? NLM_CONNECTIVITY_IPV6_INTERNET + : NLM_CONNECTIVITY_IPV4_INTERNET); + } + return d_func()->connectivity & required; } @@ -695,7 +718,8 @@ bool QNetworkStatusMonitor::isNetworkAccessible() { return d_func()->connectivity & (NLM_CONNECTIVITY_IPV4_INTERNET | NLM_CONNECTIVITY_IPV6_INTERNET - | NLM_CONNECTIVITY_IPV4_SUBNET | NLM_CONNECTIVITY_IPV6_SUBNET); + | NLM_CONNECTIVITY_IPV4_SUBNET | NLM_CONNECTIVITY_IPV6_SUBNET + | NLM_CONNECTIVITY_IPV4_LOCALNETWORK | NLM_CONNECTIVITY_IPV6_LOCALNETWORK); } bool QNetworkStatusMonitor::isEnabled() -- cgit v1.2.3 From c9eb9411cf901c6a9af5d470ebb5ba7ba7b7583a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Fri, 14 Feb 2020 12:26:23 +0100 Subject: QNAM: Correct logic of network monitor when bearer is disabled Change-Id: I0abe9034874a80423ad1e332404236dc5ff54365 Reviewed-by: Timur Pocheptsov --- src/network/access/qnetworkaccessmanager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/network') diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 76b95b5823..89664c154f 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -1462,7 +1462,7 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera // immediately set 'networkAccessible' even before we start // the monitor. #ifdef QT_NO_BEARERMANAGEMENT - if (d->networkAccessible + if (!d->networkAccessible #else if (d->networkAccessible == NotAccessible #endif // QT_NO_BEARERMANAGEMENT -- cgit v1.2.3 From ee73ec0c77dc040771d7f983df16e97ed5ac9cd3 Mon Sep 17 00:00:00 2001 From: Alexander Akulich Date: Fri, 7 Feb 2020 15:36:58 +0300 Subject: Fix a typo in QLocalSocket doc Change-Id: I3047cb24051c7f25d77d5b2b86ff145a52695107 Reviewed-by: Paul Wicking Reviewed-by: Timur Pocheptsov --- src/network/socket/qlocalsocket.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/network') diff --git a/src/network/socket/qlocalsocket.cpp b/src/network/socket/qlocalsocket.cpp index af7cdb76d2..a392a8c75a 100644 --- a/src/network/socket/qlocalsocket.cpp +++ b/src/network/socket/qlocalsocket.cpp @@ -51,7 +51,7 @@ QT_BEGIN_NAMESPACE On Windows this is a named pipe and on Unix this is a local domain socket. - If an error occurs, socketError() returns the type of error, and + If an error occurs, error() returns the type of error, and errorString() can be called to get a human readable description of what happened. -- cgit v1.2.3 From 3dc69d651b2795ef9c728528cf31b0269bf40805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Fri, 14 Feb 2020 16:43:07 +0100 Subject: QNAM Doc: Remove mention of bearer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🐻er management is going away Change-Id: I86067d593ece0d35a33f23130260ccb7c4b64881 Reviewed-by: Timur Pocheptsov --- src/network/access/qnetworkaccessmanager.cpp | 21 --------------------- src/network/doc/src/network-programming.qdoc | 25 ------------------------- src/network/doc/src/qtnetwork.qdoc | 1 - 3 files changed, 47 deletions(-) (limited to 'src/network') diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 7745f4b752..9cbf7b45c6 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -220,27 +220,6 @@ static void ensureInitialized() can be: \snippet code/src_network_access_qnetworkaccessmanager.cpp 1 - \section1 Network and Roaming Support - - With the addition of the \l {Bearer Management} API to Qt 4.7 - QNetworkAccessManager gained the ability to manage network connections. - QNetworkAccessManager can start the network interface if the device is - offline and terminates the interface if the current process is the last - one to use the uplink. Note that some platforms utilize grace periods from - when the last application stops using a uplink until the system actually - terminates the connectivity link. Roaming is equally transparent. Any - queued/pending network requests are automatically transferred to the new - access point. - - Clients wanting to utilize this feature should not require any changes. In fact - it is likely that existing platform specific connection code can simply be - removed from the application. - - \note The network and roaming support in QNetworkAccessManager is conditional - upon the platform supporting connection management. The - \l QNetworkConfigurationManager::NetworkSessionRequired can be used to - detect whether QNetworkAccessManager utilizes this feature. - \sa QNetworkRequest, QNetworkReply, QNetworkProxy */ diff --git a/src/network/doc/src/network-programming.qdoc b/src/network/doc/src/network-programming.qdoc index ce99af034b..654227f971 100644 --- a/src/network/doc/src/network-programming.qdoc +++ b/src/network/doc/src/network-programming.qdoc @@ -261,29 +261,4 @@ by passing a factory to QNetworkProxyFactory::setApplicationProxyFactory() and a custom proxying policy can be created by subclassing QNetworkProxyFactory; see the class documentation for details. - - \section1 Bearer Management Support - - Bearer Management controls the connectivity state of the device such that - the application can start or stop network interfaces and roam - transparently between access points. - - The QNetworkConfigurationManager class manages the list of network - configurations known to the device. A network configuration describes the - set of parameters used to start a network interface and is represented by - the QNetworkConfiguration class. - - A network interface is started by openning a QNetworkSession based on a - given network configuration. In most situations creating a network session - based on the platform specified default network configuration is - appropriate. The default network configuration is returned by the - QNetworkConfigurationManager::defaultConfiguration() function. - - On some platforms it is a platform requirement that the application open a - network session before any network operations can be performed. This can be - tested by the presents of the - QNetworkConfigurationManager::NetworkSessionRequired flag in the value - returned by the QNetworkConfigurationManager::capabilities() function. - - \sa {Bearer Management} */ diff --git a/src/network/doc/src/qtnetwork.qdoc b/src/network/doc/src/qtnetwork.qdoc index c931a1c19f..85a3c198a0 100644 --- a/src/network/doc/src/qtnetwork.qdoc +++ b/src/network/doc/src/qtnetwork.qdoc @@ -54,7 +54,6 @@ applications with networking capabilities. \list \li \l{Network Programming with Qt} - Programming applications with networking capabilities - \li \l{Bearer Management} - An API to control the system's connectivity state \li \l{Secure Sockets Layer (SSL) Classes} - Classes for secure communication over network sockets \endlist -- cgit v1.2.3 From 291b3cebb905c3924eefa1e5a7c6ac31ca89aacd Mon Sep 17 00:00:00 2001 From: Alexander Akulich Date: Mon, 10 Feb 2020 14:23:29 +0300 Subject: QAbstractSocket: Use constructor delegation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ib749ff46dd3c9d44c1a3c6273eadd78fdf0f837e Reviewed-by: Mårten Nordheim Reviewed-by: Timur Pocheptsov --- src/network/socket/qabstractsocket.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'src/network') diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp index 3d88c0337d..5f1ff2fcb8 100644 --- a/src/network/socket/qabstractsocket.cpp +++ b/src/network/socket/qabstractsocket.cpp @@ -1465,13 +1465,8 @@ QAbstractSocket::QAbstractSocket(SocketType socketType, \sa socketType(), QTcpSocket, QUdpSocket */ QAbstractSocket::QAbstractSocket(SocketType socketType, QObject *parent) - : QIODevice(*new QAbstractSocketPrivate, parent) + : QAbstractSocket(socketType, *new QAbstractSocketPrivate, parent) { - Q_D(QAbstractSocket); -#if defined(QABSTRACTSOCKET_DEBUG) - qDebug("QAbstractSocket::QAbstractSocket(%p)", parent); -#endif - d->socketType = socketType; } /*! -- cgit v1.2.3 From 0394961f953094ab3535b79329dace4ed9a0300d Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Tue, 25 Feb 2020 11:11:28 +0100 Subject: Rename TransferTimeoutPreset to DefaultTransferTimeoutConstant MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Found in API review. Replacing with the suggested name which is more Qt-ish. And also preventively fix the name to contain its enum's name to follow the conventions. Change-Id: I00b510e36ccc831f107ecc3c79943d617726b4fb Reviewed-by: Mårten Nordheim --- src/network/access/qnetworkaccessmanager.h | 2 +- src/network/access/qnetworkrequest.cpp | 6 +++--- src/network/access/qnetworkrequest.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/network') diff --git a/src/network/access/qnetworkaccessmanager.h b/src/network/access/qnetworkaccessmanager.h index 375d2e03f7..a75b16a6ca 100644 --- a/src/network/access/qnetworkaccessmanager.h +++ b/src/network/access/qnetworkaccessmanager.h @@ -171,7 +171,7 @@ public: void setAutoDeleteReplies(bool autoDelete); int transferTimeout() const; - void setTransferTimeout(int timeout = QNetworkRequest::TransferTimeoutPreset); + void setTransferTimeout(int timeout = QNetworkRequest::DefaultTransferTimeoutConstant); Q_SIGNALS: #ifndef QT_NO_NETWORKPROXY diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp index 70b09dba22..f1c8575c58 100644 --- a/src/network/access/qnetworkrequest.cpp +++ b/src/network/access/qnetworkrequest.cpp @@ -432,9 +432,9 @@ QT_BEGIN_NAMESPACE A constant that can be used for enabling transfer timeouts with a preset value. - \value TransferTimeoutPreset The transfer timeout in milliseconds. - Used if setTimeout() is called - without an argument. + \value DefaultTransferTimeoutConstant The transfer timeout in milliseconds. + Used if setTimeout() is called + without an argument. */ class QNetworkRequestPrivate: public QSharedData, public QNetworkHeadersPrivate diff --git a/src/network/access/qnetworkrequest.h b/src/network/access/qnetworkrequest.h index dcd2c6b61f..66b9a43e01 100644 --- a/src/network/access/qnetworkrequest.h +++ b/src/network/access/qnetworkrequest.h @@ -135,7 +135,7 @@ public: }; enum TransferTimeoutConstant { - TransferTimeoutPreset = 30000 + DefaultTransferTimeoutConstant = 30000 }; QNetworkRequest(); @@ -190,7 +190,7 @@ public: void setHttp2Configuration(const QHttp2Configuration &configuration); int transferTimeout() const; - void setTransferTimeout(int timeout = TransferTimeoutPreset); + void setTransferTimeout(int timeout = DefaultTransferTimeoutConstant); #endif // QT_CONFIG(http) || defined(Q_CLANG_QDOC) private: QSharedDataPointer d; -- cgit v1.2.3