summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorLeander Beernaert <leander.beernaert@qt.io>2020-01-22 13:47:08 +0100
committerLeander Beernaert <leander.beernaert@qt.io>2020-01-24 13:17:33 +0100
commit502d3d6744913899da87acfda5ebdab42c40329e (patch)
tree16658a328503bfd5a62b4fd5d69ffb66e9854b18 /src/network
parentd1be8b9ceb2c7b20bbe53a07154c79699540ea3d (diff)
parent06bb315beb6c2c398223cfe52cbc7f66e14a8557 (diff)
Merge remote-tracking branch 'origin/dev' into merge-dev
Diffstat (limited to 'src/network')
-rw-r--r--src/network/access/qabstractprotocolhandler.cpp2
-rw-r--r--src/network/access/qftp.cpp20
-rw-r--r--src/network/access/qhttpmultipart.cpp2
-rw-r--r--src/network/access/qhttpnetworkconnection.cpp16
-rw-r--r--src/network/access/qhttpnetworkconnectionchannel.cpp20
-rw-r--r--src/network/access/qhttpnetworkreply.cpp10
-rw-r--r--src/network/access/qhttpnetworkrequest.cpp2
-rw-r--r--src/network/access/qhttpprotocolhandler.cpp6
-rw-r--r--src/network/access/qhttpthreaddelegate.cpp18
-rw-r--r--src/network/access/qnetworkaccessauthenticationmanager.cpp2
-rw-r--r--src/network/access/qnetworkaccessbackend.cpp10
-rw-r--r--src/network/access/qnetworkaccesscache.cpp22
-rw-r--r--src/network/access/qnetworkaccessdebugpipebackend.cpp10
-rw-r--r--src/network/access/qnetworkaccessfilebackend.cpp6
-rw-r--r--src/network/access/qnetworkaccessftpbackend.cpp12
-rw-r--r--src/network/access/qnetworkaccessmanager.cpp27
-rw-r--r--src/network/access/qnetworkaccessmanager.h4
-rw-r--r--src/network/access/qnetworkaccessmanager_p.h4
-rw-r--r--src/network/access/qnetworkcookie.cpp2
-rw-r--r--src/network/access/qnetworkdiskcache.cpp22
-rw-r--r--src/network/access/qnetworkreply.cpp28
-rw-r--r--src/network/access/qnetworkreply.h13
-rw-r--r--src/network/access/qnetworkreplyfileimpl.cpp2
-rw-r--r--src/network/access/qnetworkreplyhttpimpl.cpp4
-rw-r--r--src/network/access/qnetworkreplyimpl.cpp26
-rw-r--r--src/network/access/qnetworkrequest.cpp8
-rw-r--r--src/network/access/qnetworkrequest.h2
-rw-r--r--src/network/access/qspdyprotocolhandler.cpp1304
-rw-r--r--src/network/bearer/qnetworkconfigmanager.cpp4
-rw-r--r--src/network/bearer/qnetworkconfigmanager_p.cpp6
-rw-r--r--src/network/bearer/qnetworkconfiguration.cpp2
-rw-r--r--src/network/bearer/qnetworksession.cpp2
-rw-r--r--src/network/bearer/qnetworksession_impl.cpp6
-rw-r--r--src/network/configure.json12
-rw-r--r--src/network/doc/snippets/code/src_network_socket_qabstractsocket.cpp5
-rw-r--r--src/network/doc/snippets/code/src_network_socket_qlocalsocket_unix.cpp4
-rw-r--r--src/network/kernel/qauthenticator.cpp10
-rw-r--r--src/network/kernel/qdnslookup.cpp4
-rw-r--r--src/network/kernel/qdnslookup_unix.cpp8
-rw-r--r--src/network/kernel/qhostaddress.cpp2
-rw-r--r--src/network/kernel/qhostinfo.cpp27
-rw-r--r--src/network/kernel/qhostinfo_p.h7
-rw-r--r--src/network/kernel/qhostinfo_unix.cpp8
-rw-r--r--src/network/kernel/qnetworkinterface.cpp4
-rw-r--r--src/network/kernel/qnetworkinterface_p.h2
-rw-r--r--src/network/kernel/qnetworkinterface_unix_p.h2
-rw-r--r--src/network/kernel/qnetworkproxy.cpp12
-rw-r--r--src/network/kernel/qurlinfo.cpp10
-rw-r--r--src/network/socket/qabstractsocket.cpp75
-rw-r--r--src/network/socket/qabstractsocket.h7
-rw-r--r--src/network/socket/qabstractsocketengine.cpp6
-rw-r--r--src/network/socket/qhttpsocketengine.cpp29
-rw-r--r--src/network/socket/qlocalserver.cpp2
-rw-r--r--src/network/socket/qlocalserver_unix.cpp2
-rw-r--r--src/network/socket/qlocalsocket.cpp35
-rw-r--r--src/network/socket/qlocalsocket.h7
-rw-r--r--src/network/socket/qlocalsocket_tcp.cpp7
-rw-r--r--src/network/socket/qlocalsocket_unix.cpp22
-rw-r--r--src/network/socket/qlocalsocket_win.cpp7
-rw-r--r--src/network/socket/qnativesocketengine.cpp18
-rw-r--r--src/network/socket/qnativesocketengine_unix.cpp6
-rw-r--r--src/network/socket/qsocks5socketengine.cpp50
-rw-r--r--src/network/socket/qtcpserver.cpp6
-rw-r--r--src/network/ssl/qdtls_openssl.cpp2
-rw-r--r--src/network/ssl/qssl.cpp3
-rw-r--r--src/network/ssl/qssl.h12
-rw-r--r--src/network/ssl/qsslconfiguration.cpp91
-rw-r--r--src/network/ssl/qsslconfiguration.h6
-rw-r--r--src/network/ssl/qsslconfiguration_p.h8
-rw-r--r--src/network/ssl/qsslcontext_openssl.cpp78
-rw-r--r--src/network/ssl/qsslsocket.cpp192
-rw-r--r--src/network/ssl/qsslsocket.h52
-rw-r--r--src/network/ssl/qsslsocket_mac.cpp54
-rw-r--r--src/network/ssl/qsslsocket_openssl.cpp304
-rw-r--r--src/network/ssl/qsslsocket_openssl_p.h13
-rw-r--r--src/network/ssl/qsslsocket_openssl_symbols.cpp8
-rw-r--r--src/network/ssl/qsslsocket_openssl_symbols_p.h4
-rw-r--r--src/network/ssl/qsslsocket_p.h1
-rw-r--r--src/network/ssl/qsslsocket_schannel.cpp13
-rw-r--r--src/network/ssl/qsslsocket_winrt.cpp6
-rw-r--r--src/network/ssl/ssl.pri8
81 files changed, 2357 insertions, 518 deletions
diff --git a/src/network/access/qabstractprotocolhandler.cpp b/src/network/access/qabstractprotocolhandler.cpp
index f15dfe6899..6847816ba7 100644
--- a/src/network/access/qabstractprotocolhandler.cpp
+++ b/src/network/access/qabstractprotocolhandler.cpp
@@ -43,7 +43,7 @@
QT_BEGIN_NAMESPACE
QAbstractProtocolHandler::QAbstractProtocolHandler(QHttpNetworkConnectionChannel *channel)
- : m_channel(channel), m_reply(0), m_socket(m_channel->socket), m_connection(m_channel->connection)
+ : m_channel(channel), m_reply(nullptr), m_socket(m_channel->socket), m_connection(m_channel->connection)
{
Q_ASSERT(m_channel);
Q_ASSERT(m_socket);
diff --git a/src/network/access/qftp.cpp b/src/network/access/qftp.cpp
index cc230a5411..62ae1adbd9 100644
--- a/src/network/access/qftp.cpp
+++ b/src/network/access/qftp.cpp
@@ -74,7 +74,7 @@ public:
CsConnectionRefused
};
- QFtpDTP(QFtpPI *p, QObject *parent = 0);
+ QFtpDTP(QFtpPI *p, QObject *parent = nullptr);
void setData(QByteArray *);
void setDevice(QIODevice *);
@@ -149,7 +149,7 @@ class QFtpPI : public QObject
Q_OBJECT
public:
- QFtpPI(QObject *parent = 0);
+ QFtpPI(QObject *parent = nullptr);
void connectToHost(const QString &host, quint16 port);
@@ -229,7 +229,7 @@ class QFtpCommand
{
public:
QFtpCommand(QFtp::Command cmd, const QStringList &raw, const QByteArray &ba);
- QFtpCommand(QFtp::Command cmd, const QStringList &raw, QIODevice *dev = 0);
+ QFtpCommand(QFtp::Command cmd, const QStringList &raw, QIODevice *dev = nullptr);
~QFtpCommand();
int id;
@@ -279,7 +279,7 @@ QFtpCommand::~QFtpCommand()
*********************************************************************/
QFtpDTP::QFtpDTP(QFtpPI *p, QObject *parent) :
QObject(parent),
- socket(0),
+ socket(nullptr),
listener(this),
pi(p),
callWriteData(false)
@@ -314,7 +314,7 @@ void QFtpDTP::connectToHost(const QString & host, quint16 port)
if (socket) {
delete socket;
- socket = 0;
+ socket = nullptr;
}
socket = new QTcpSocket(this);
#ifndef QT_NO_BEARERMANAGEMENT
@@ -427,7 +427,7 @@ void QFtpDTP::writeData()
}
// do we continue uploading?
- callWriteData = data.dev != 0;
+ callWriteData = data.dev != nullptr;
}
}
@@ -779,7 +779,7 @@ void QFtpDTP::setupSocket()
void QFtpDTP::clearData()
{
is_ba = false;
- data.dev = 0;
+ data.dev = nullptr;
}
/**********************************************************************
@@ -792,7 +792,7 @@ QFtpPI::QFtpPI(QObject *parent) :
rawCommand(false),
transferConnectionExtended(true),
dtp(this),
- commandSocket(0),
+ commandSocket(nullptr),
state(Begin), abortState(None),
currentCmd(QString()),
waitForDtpToConnect(false),
@@ -2173,10 +2173,10 @@ QFtp::Command QFtp::currentCommand() const
QIODevice* QFtp::currentDevice() const
{
if (d_func()->pending.isEmpty())
- return 0;
+ return nullptr;
QFtpCommand *c = d_func()->pending.first();
if (c->is_ba)
- return 0;
+ return nullptr;
return c->data.dev;
}
diff --git a/src/network/access/qhttpmultipart.cpp b/src/network/access/qhttpmultipart.cpp
index c59df9d8b8..d6fefc4314 100644
--- a/src/network/access/qhttpmultipart.cpp
+++ b/src/network/access/qhttpmultipart.cpp
@@ -111,7 +111,7 @@ QHttpPart::QHttpPart(const QHttpPart &other) : d(other.d)
*/
QHttpPart::~QHttpPart()
{
- d = 0;
+ d = nullptr;
}
/*!
diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp
index 795efc91d7..04f63e8735 100644
--- a/src/network/access/qhttpnetworkconnection.cpp
+++ b/src/network/access/qhttpnetworkconnection.cpp
@@ -379,9 +379,9 @@ void QHttpNetworkConnectionPrivate::emitReplyError(QAbstractSocket *socket,
// Clean the channel
channels[i].close();
- channels[i].reply = 0;
+ channels[i].reply = nullptr;
if (channels[i].protocolHandler)
- channels[i].protocolHandler->setReply(0);
+ channels[i].protocolHandler->setReply(nullptr);
channels[i].request = QHttpNetworkRequest();
if (socket)
channels[i].requeueCurrentlyPipelinedRequests();
@@ -405,7 +405,7 @@ void QHttpNetworkConnectionPrivate::copyCredentials(int fromChannel, QAuthentica
}
// select another channel
- QAuthenticator* otherAuth = 0;
+ QAuthenticator* otherAuth = nullptr;
for (int i = 0; i < activeChannelCount; ++i) {
if (i == fromChannel)
continue;
@@ -438,7 +438,7 @@ bool QHttpNetworkConnectionPrivate::handleAuthenticateChallenge(QAbstractSocket
if (authMethod != QAuthenticatorPrivate::None) {
int i = indexOf(socket);
//Use a single authenticator for all domains. ### change later to use domain/realm
- QAuthenticator* auth = 0;
+ QAuthenticator* auth = nullptr;
if (isProxy) {
auth = &channels[i].proxyAuthenticator;
channels[i].proxyAuthMethod = authMethod;
@@ -493,7 +493,7 @@ bool QHttpNetworkConnectionPrivate::handleAuthenticateChallenge(QAbstractSocket
// we need to bail out if authentication is required.
if (priv->phase == QAuthenticatorPrivate::Done || !reply->request().withCredentials()) {
// Reset authenticator so the next request on that channel does not get messed up
- auth = 0;
+ auth = nullptr;
if (isProxy)
channels[i].proxyAuthenticator = QAuthenticator();
else
@@ -763,7 +763,7 @@ void QHttpNetworkConnectionPrivate::fillPipeline(QAbstractSocket *socket)
int i = indexOf(socket);
// return fast if there was no reply right now processed
- if (channels[i].reply == 0)
+ if (channels[i].reply == nullptr)
return;
if (! (defaultPipelineLength - channels[i].alreadyPipelinedRequests.length() >= defaultRePipelineLength)) {
@@ -934,9 +934,9 @@ void QHttpNetworkConnectionPrivate::removeReply(QHttpNetworkReply *reply)
for (int i = 0; i < activeChannelCount; ++i) {
// is the reply associated the currently processing of this channel?
if (channels[i].reply == reply) {
- channels[i].reply = 0;
+ channels[i].reply = nullptr;
if (channels[i].protocolHandler)
- channels[i].protocolHandler->setReply(0);
+ channels[i].protocolHandler->setReply(nullptr);
channels[i].request = QHttpNetworkRequest();
channels[i].resendCurrent = false;
diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp
index c6470622ab..98809e460b 100644
--- a/src/network/access/qhttpnetworkconnectionchannel.cpp
+++ b/src/network/access/qhttpnetworkconnectionchannel.cpp
@@ -86,11 +86,11 @@ private:
static const int reconnectAttemptsDefault = 3;
QHttpNetworkConnectionChannel::QHttpNetworkConnectionChannel()
- : socket(0)
+ : socket(nullptr)
, ssl(false)
, isInitialized(false)
, state(IdleState)
- , reply(0)
+ , reply(nullptr)
, written(0)
, bytesTotal(0)
, resendCurrent(false)
@@ -101,13 +101,13 @@ QHttpNetworkConnectionChannel::QHttpNetworkConnectionChannel()
, proxyAuthMethod(QAuthenticatorPrivate::None)
, authenticationCredentialsSent(false)
, proxyCredentialsSent(false)
- , protocolHandler(0)
+ , protocolHandler(nullptr)
#ifndef QT_NO_SSL
, ignoreAllSslErrors(false)
#endif
, pipeliningSupported(PipeliningSupportUnknown)
, networkLayerPreference(QAbstractSocket::AnyIPProtocol)
- , connection(0)
+ , connection(nullptr)
{
// Inlining this function in the header leads to compiler error on
// release-armv5, on at least timebox 9.2 and 10.1.
@@ -294,9 +294,9 @@ void QHttpNetworkConnectionChannel::handleUnexpectedEOF()
close();
reply->d_func()->errorString = connection->d_func()->errorDetail(QNetworkReply::RemoteHostClosedError, socket);
emit reply->finishedWithError(QNetworkReply::RemoteHostClosedError, reply->d_func()->errorString);
- reply = 0;
+ reply = nullptr;
if (protocolHandler)
- protocolHandler->setReply(0);
+ protocolHandler->setReply(nullptr);
request = QHttpNetworkRequest();
QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
} else {
@@ -525,8 +525,8 @@ void QHttpNetworkConnectionChannel::allDone()
// problem.
if (!resendCurrent) {
request = QHttpNetworkRequest();
- reply = 0;
- protocolHandler->setReply(0);
+ reply = nullptr;
+ protocolHandler->setReply(nullptr);
}
// move next from pipeline to current request
@@ -1099,9 +1099,9 @@ void QHttpNetworkConnectionChannel::_q_error(QAbstractSocket::SocketError socket
if (reply) {
reply->d_func()->errorString = errorString;
emit reply->finishedWithError(errorCode, errorString);
- reply = 0;
+ reply = nullptr;
if (protocolHandler)
- protocolHandler->setReply(0);
+ protocolHandler->setReply(nullptr);
}
} while (!connection->d_func()->highPriorityQueue.isEmpty()
|| !connection->d_func()->lowPriorityQueue.isEmpty());
diff --git a/src/network/access/qhttpnetworkreply.cpp b/src/network/access/qhttpnetworkreply.cpp
index 8982b7c745..1ba52ac6d6 100644
--- a/src/network/access/qhttpnetworkreply.cpp
+++ b/src/network/access/qhttpnetworkreply.cpp
@@ -326,12 +326,12 @@ QHttpNetworkReplyPrivate::QHttpNetworkReplyPrivate(const QUrl &newUrl)
currentChunkSize(0), currentChunkRead(0), readBufferMaxSize(0),
totallyUploadedData(0),
removedContentLength(-1),
- connection(0),
+ connection(nullptr),
autoDecompress(false), responseData(), requestIsPrepared(false)
,pipeliningUsed(false), h2Used(false), downstreamLimited(false)
- ,userProvidedDownloadBuffer(0)
+ ,userProvidedDownloadBuffer(nullptr)
#ifndef QT_NO_COMPRESS
- ,inflateStrm(0)
+ ,inflateStrm(nullptr)
#endif
{
@@ -371,8 +371,8 @@ void QHttpNetworkReplyPrivate::clearHttpLayerInformation()
// TODO: Isn't everything HTTP layer related? We don't need to set connection and connectionChannel to 0 at all
void QHttpNetworkReplyPrivate::clear()
{
- connection = 0;
- connectionChannel = 0;
+ connection = nullptr;
+ connectionChannel = nullptr;
autoDecompress = false;
clearHttpLayerInformation();
}
diff --git a/src/network/access/qhttpnetworkrequest.cpp b/src/network/access/qhttpnetworkrequest.cpp
index f81924d5d3..0b03e6e69e 100644
--- a/src/network/access/qhttpnetworkrequest.cpp
+++ b/src/network/access/qhttpnetworkrequest.cpp
@@ -44,7 +44,7 @@ QT_BEGIN_NAMESPACE
QHttpNetworkRequestPrivate::QHttpNetworkRequestPrivate(QHttpNetworkRequest::Operation op,
QHttpNetworkRequest::Priority pri, const QUrl &newUrl)
- : QHttpNetworkHeaderPrivate(newUrl), operation(op), priority(pri), uploadByteDevice(0),
+ : QHttpNetworkHeaderPrivate(newUrl), operation(op), priority(pri), uploadByteDevice(nullptr),
autoDecompress(false), pipeliningAllowed(false), http2Allowed(false),
http2Direct(false), withCredentials(true), preConnect(false), redirectCount(0),
redirectPolicy(QNetworkRequest::ManualRedirectPolicy)
diff --git a/src/network/access/qhttpprotocolhandler.cpp b/src/network/access/qhttpprotocolhandler.cpp
index edcbdcbe0e..981effb54f 100644
--- a/src/network/access/qhttpprotocolhandler.cpp
+++ b/src/network/access/qhttpprotocolhandler.cpp
@@ -233,7 +233,7 @@ void QHttpProtocolHandler::_q_readyRead()
char c;
qint64 ret = m_socket->peek(&c, 1);
if (ret < 0) {
- m_channel->_q_error(m_socket->error());
+ m_channel->_q_error(m_socket->socketError());
// We still need to handle the reply so it emits its signals etc.
if (m_reply)
_q_receiveReply();
@@ -278,7 +278,7 @@ bool QHttpProtocolHandler::sendRequest()
m_reply->d_func()->state = QHttpNetworkReplyPrivate::AllDoneState;
m_channel->allDone();
m_connection->preConnectFinished(); // will only decrease the counter
- m_reply = 0; // so we can reuse this channel
+ m_reply = nullptr; // so we can reuse this channel
return true; // we have a working connection and are done
}
@@ -373,7 +373,7 @@ bool QHttpProtocolHandler::sendRequest()
// premature eof happened
m_connection->d_func()->emitReplyError(m_socket, m_reply, QNetworkReply::UnknownNetworkError);
return false;
- } else if (readPointer == 0 || currentReadSize == 0) {
+ } else if (readPointer == nullptr || currentReadSize == 0) {
// nothing to read currently, break the loop
break;
} else {
diff --git a/src/network/access/qhttpthreaddelegate.cpp b/src/network/access/qhttpthreaddelegate.cpp
index 2933d75d2c..6322c773ac 100644
--- a/src/network/access/qhttpthreaddelegate.cpp
+++ b/src/network/access/qhttpthreaddelegate.cpp
@@ -189,7 +189,7 @@ public:
QNetworkAccessCachedHttpConnection(const QString &hostName, quint16 port, bool encrypt,
QHttpNetworkConnection::ConnectionType connectionType,
QSharedPointer<QNetworkSession> networkSession)
- : QHttpNetworkConnection(hostName, port, encrypt, connectionType, /*parent=*/0,
+ : QHttpNetworkConnection(hostName, port, encrypt, connectionType, /*parent=*/nullptr,
std::move(networkSession))
#endif
{
@@ -241,9 +241,9 @@ QHttpThreadDelegate::QHttpThreadDelegate(QObject *parent) :
, removedContentLength(-1)
, incomingErrorCode(QNetworkReply::NoError)
, downloadBuffer()
- , httpConnection(0)
- , httpReply(0)
- , synchronousRequestLoop(0)
+ , httpConnection(nullptr)
+ , httpReply(nullptr)
+ , synchronousRequestLoop(nullptr)
{
}
@@ -428,7 +428,7 @@ void QHttpThreadDelegate::abortRequest()
if (httpReply) {
httpReply->abort();
delete httpReply;
- httpReply = 0;
+ httpReply = nullptr;
}
// Got aborted by the timeout timer
@@ -534,7 +534,7 @@ void QHttpThreadDelegate::finishedSlot()
QMetaObject::invokeMethod(httpReply, "deleteLater", Qt::QueuedConnection);
QMetaObject::invokeMethod(this, "deleteLater", Qt::QueuedConnection);
- httpReply = 0;
+ httpReply = nullptr;
}
void QHttpThreadDelegate::synchronousFinishedSlot()
@@ -557,7 +557,7 @@ void QHttpThreadDelegate::synchronousFinishedSlot()
QMetaObject::invokeMethod(httpReply, "deleteLater", Qt::QueuedConnection);
QMetaObject::invokeMethod(synchronousRequestLoop, "quit", Qt::QueuedConnection);
- httpReply = 0;
+ httpReply = nullptr;
}
void QHttpThreadDelegate::finishedWithErrorSlot(QNetworkReply::NetworkError errorCode, const QString &detail)
@@ -579,7 +579,7 @@ void QHttpThreadDelegate::finishedWithErrorSlot(QNetworkReply::NetworkError erro
QMetaObject::invokeMethod(httpReply, "deleteLater", Qt::QueuedConnection);
QMetaObject::invokeMethod(this, "deleteLater", Qt::QueuedConnection);
- httpReply = 0;
+ httpReply = nullptr;
}
@@ -598,7 +598,7 @@ void QHttpThreadDelegate::synchronousFinishedWithErrorSlot(QNetworkReply::Networ
QMetaObject::invokeMethod(httpReply, "deleteLater", Qt::QueuedConnection);
QMetaObject::invokeMethod(synchronousRequestLoop, "quit", Qt::QueuedConnection);
- httpReply = 0;
+ httpReply = nullptr;
}
static void downloadBufferDeleter(char *ptr)
diff --git a/src/network/access/qnetworkaccessauthenticationmanager.cpp b/src/network/access/qnetworkaccessauthenticationmanager.cpp
index b661cc45b3..0df11684b1 100644
--- a/src/network/access/qnetworkaccessauthenticationmanager.cpp
+++ b/src/network/access/qnetworkaccessauthenticationmanager.cpp
@@ -71,7 +71,7 @@ public:
if (it == end() && !isEmpty())
--it;
if (it == end() || !domain.startsWith(it->domain))
- return 0;
+ return nullptr;
return &*it;
}
diff --git a/src/network/access/qnetworkaccessbackend.cpp b/src/network/access/qnetworkaccessbackend.cpp
index 566e410051..8f42f3690b 100644
--- a/src/network/access/qnetworkaccessbackend.cpp
+++ b/src/network/access/qnetworkaccessbackend.cpp
@@ -105,7 +105,7 @@ QNetworkAccessBackend *QNetworkAccessManagerPrivate::findBackend(QNetworkAccessM
++it;
}
}
- return 0;
+ return nullptr;
}
QStringList QNetworkAccessManagerPrivate::backendSupportedSchemes() const
@@ -131,7 +131,7 @@ QNonContiguousByteDevice* QNetworkAccessBackend::createUploadByteDevice()
else if (reply->outgoingData) {
uploadByteDevice = QNonContiguousByteDeviceFactory::createShared(reply->outgoingData);
} else {
- return 0;
+ return nullptr;
}
// We want signal emissions only for normal asynchronous uploads
@@ -151,8 +151,8 @@ void QNetworkAccessBackend::emitReplyUploadProgress(qint64 bytesSent, qint64 byt
}
QNetworkAccessBackend::QNetworkAccessBackend()
- : manager(0)
- , reply(0)
+ : manager(nullptr)
+ , reply(nullptr)
, synchronous(false)
{
}
@@ -223,7 +223,7 @@ QList<QNetworkProxy> QNetworkAccessBackend::proxyList() const
QAbstractNetworkCache *QNetworkAccessBackend::networkCache() const
{
if (!manager)
- return 0;
+ return nullptr;
return manager->networkCache;
}
diff --git a/src/network/access/qnetworkaccesscache.cpp b/src/network/access/qnetworkaccesscache.cpp
index b694a2c999..ba092f2618 100644
--- a/src/network/access/qnetworkaccesscache.cpp
+++ b/src/network/access/qnetworkaccesscache.cpp
@@ -73,7 +73,7 @@ struct QNetworkAccessCache::Node
int useCount;
Node()
- : older(0), newer(0), object(0), useCount(0)
+ : older(nullptr), newer(nullptr), object(nullptr), useCount(0)
{ }
};
@@ -103,7 +103,7 @@ void QNetworkAccessCache::CacheableObject::setShareable(bool enable)
}
QNetworkAccessCache::QNetworkAccessCache()
- : oldest(0), newest(0)
+ : oldest(nullptr), newest(nullptr)
{
}
@@ -130,7 +130,7 @@ void QNetworkAccessCache::clear()
timer.stop();
- oldest = newest = 0;
+ oldest = newest = nullptr;
}
/*!
@@ -145,11 +145,11 @@ void QNetworkAccessCache::linkEntry(const QByteArray &key)
Node *const node = &it.value();
Q_ASSERT(node != oldest && node != newest);
- Q_ASSERT(node->older == 0 && node->newer == 0);
+ Q_ASSERT(node->older == nullptr && node->newer == nullptr);
Q_ASSERT(node->useCount == 0);
if (newest) {
- Q_ASSERT(newest->newer == 0);
+ Q_ASSERT(newest->newer == nullptr);
newest->newer = node;
node->older = newest;
}
@@ -186,7 +186,7 @@ bool QNetworkAccessCache::unlinkEntry(const QByteArray &key)
if (node->newer)
node->newer->older = node->older;
- node->newer = node->older = 0;
+ node->newer = node->older = nullptr;
return wasOldest;
}
@@ -235,9 +235,9 @@ void QNetworkAccessCache::timerEvent(QTimerEvent *)
// fixup the list
if (oldest)
- oldest->older = 0;
+ oldest->older = nullptr;
else
- newest = 0;
+ newest = nullptr;
updateTimer();
}
@@ -277,7 +277,7 @@ bool QNetworkAccessCache::requestEntry(const QByteArray &key, QObject *target, c
if (node->useCount > 0 && !node->object->shareable) {
// object is not shareable and is in use
// queue for later use
- Q_ASSERT(node->older == 0 && node->newer == 0);
+ Q_ASSERT(node->older == nullptr && node->newer == nullptr);
node->receiverQueue.push_back({target, member});
// request queued
@@ -296,7 +296,7 @@ QNetworkAccessCache::CacheableObject *QNetworkAccessCache::requestEntryNow(const
{
NodeHash::Iterator it = hash.find(key);
if (it == hash.end())
- return 0;
+ return nullptr;
if (it->useCount > 0) {
if (it->object->shareable) {
++it->useCount;
@@ -304,7 +304,7 @@ QNetworkAccessCache::CacheableObject *QNetworkAccessCache::requestEntryNow(const
}
// object in use and not shareable
- return 0;
+ return nullptr;
}
// entry not in use, let the caller have it
diff --git a/src/network/access/qnetworkaccessdebugpipebackend.cpp b/src/network/access/qnetworkaccessdebugpipebackend.cpp
index 67a856506c..0406f2fac1 100644
--- a/src/network/access/qnetworkaccessdebugpipebackend.cpp
+++ b/src/network/access/qnetworkaccessdebugpipebackend.cpp
@@ -70,13 +70,13 @@ QNetworkAccessDebugPipeBackendFactory::create(QNetworkAccessManager::Operation o
default:
// no, we can't handle this operation
- return 0;
+ return nullptr;
}
QUrl url = request.url();
if (url.scheme() == QLatin1String("debugpipe"))
return new QNetworkAccessDebugPipeBackend;
- return 0;
+ return nullptr;
}
QNetworkAccessDebugPipeBackend::QNetworkAccessDebugPipeBackend()
@@ -188,7 +188,7 @@ void QNetworkAccessDebugPipeBackend::pushFromUpstreamToSocket()
emitReplyUploadProgress(bytesUploaded, bytesUploaded);
possiblyFinish();
break;
- } else if (haveRead == 0 || readPointer == 0) {
+ } else if (haveRead == 0 || readPointer == nullptr) {
// nothing to read right now, we will be called again later
break;
} else {
@@ -242,9 +242,9 @@ void QNetworkAccessDebugPipeBackend::closeDownstreamChannel()
void QNetworkAccessDebugPipeBackend::socketError()
{
- qWarning("QNetworkAccessDebugPipeBackend::socketError() %d",socket.error());
+ qWarning("QNetworkAccessDebugPipeBackend::socketError() %d",socket.socketError());
QNetworkReply::NetworkError code;
- switch (socket.error()) {
+ switch (socket.socketError()) {
case QAbstractSocket::RemoteHostClosedError:
return; // socketDisconnected will be called
diff --git a/src/network/access/qnetworkaccessfilebackend.cpp b/src/network/access/qnetworkaccessfilebackend.cpp
index 60353cb03e..507417f86c 100644
--- a/src/network/access/qnetworkaccessfilebackend.cpp
+++ b/src/network/access/qnetworkaccessfilebackend.cpp
@@ -73,7 +73,7 @@ QNetworkAccessFileBackendFactory::create(QNetworkAccessManager::Operation op,
default:
// no, we can't handle this operation
- return 0;
+ return nullptr;
}
QUrl url = request.url();
@@ -95,7 +95,7 @@ QNetworkAccessFileBackendFactory::create(QNetworkAccessManager::Operation op,
return new QNetworkAccessFileBackend;
}
- return 0;
+ return nullptr;
}
QNetworkAccessFileBackend::QNetworkAccessFileBackend()
@@ -198,7 +198,7 @@ void QNetworkAccessFileBackend::uploadReadyReadSlot()
file.close();
finished();
break;
- } else if (haveRead == 0 || readPointer == 0) {
+ } else if (haveRead == 0 || readPointer == nullptr) {
// nothing to read right now, we will be called again later
break;
} else {
diff --git a/src/network/access/qnetworkaccessftpbackend.cpp b/src/network/access/qnetworkaccessftpbackend.cpp
index 51ed2f5a55..fb8cd79c12 100644
--- a/src/network/access/qnetworkaccessftpbackend.cpp
+++ b/src/network/access/qnetworkaccessftpbackend.cpp
@@ -75,13 +75,13 @@ QNetworkAccessFtpBackendFactory::create(QNetworkAccessManager::Operation op,
default:
// no, we can't handle this operation
- return 0;
+ return nullptr;
}
QUrl url = request.url();
if (url.scheme().compare(QLatin1String("ftp"), Qt::CaseInsensitive) == 0)
return new QNetworkAccessFtpBackend;
- return 0;
+ return nullptr;
}
class QNetworkAccessCachedFtpConnection: public QFtp, public QNetworkAccessCache::CacheableObject
@@ -104,7 +104,7 @@ public:
};
QNetworkAccessFtpBackend::QNetworkAccessFtpBackend()
- : ftp(0), uploadDevice(0), totalBytes(0), helpId(-1), sizeId(-1), mdtmId(-1), pwdId(-1),
+ : ftp(nullptr), uploadDevice(nullptr), totalBytes(0), helpId(-1), sizeId(-1), mdtmId(-1), pwdId(-1),
supportsSize(false), supportsMdtm(false), supportsPwd(false), state(Idle)
{
}
@@ -215,7 +215,7 @@ void QNetworkAccessFtpBackend::disconnectFromFtp(CacheCleanupMode mode)
state = Disconnecting;
if (ftp) {
- disconnect(ftp, 0, this, 0);
+ disconnect(ftp, nullptr, this, nullptr);
QByteArray key = makeCacheKey(url());
if (mode == RemoveCachedConnection) {
@@ -225,7 +225,7 @@ void QNetworkAccessFtpBackend::disconnectFromFtp(CacheCleanupMode mode)
QNetworkAccessManagerPrivate::getObjectCache(this)->releaseEntry(key);
}
- ftp = 0;
+ ftp = nullptr;
}
}
@@ -362,7 +362,7 @@ void QNetworkAccessFtpBackend::ftpDone()
QFtp::TransferType type = QFtp::Binary;
if (operation() == QNetworkAccessManager::GetOperation) {
setCachingEnabled(true);
- ftp->get(url().path(), 0, type);
+ ftp->get(url().path(), nullptr, type);
} else {
ftp->put(uploadDevice, url().path(), type);
}
diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp
index f5d30069e8..3dea2e026a 100644
--- a/src/network/access/qnetworkaccessmanager.cpp
+++ b/src/network/access/qnetworkaccessmanager.cpp
@@ -1724,7 +1724,7 @@ void QNetworkAccessManager::setAutoDeleteReplies(bool shouldAutoDelete)
This timeout is zero if setTransferTimeout() hasn't been
called, which means that the timeout is not used.
*/
-int QNetworkAccessManager::transferTimeout()
+int QNetworkAccessManager::transferTimeout() const
{
return d_func()->transferTimeout;
}
@@ -1751,16 +1751,13 @@ void QNetworkAccessManager::setTransferTimeout(int timeout)
d_func()->transferTimeout = timeout;
}
-void QNetworkAccessManagerPrivate::_q_replyFinished()
+void QNetworkAccessManagerPrivate::_q_replyFinished(QNetworkReply *reply)
{
Q_Q(QNetworkAccessManager);
- QNetworkReply *reply = qobject_cast<QNetworkReply *>(q->sender());
- if (reply) {
- emit q->finished(reply);
- if (reply->request().attribute(QNetworkRequest::AutoDeleteReplyOnFinishAttribute, false).toBool())
- QMetaObject::invokeMethod(reply, [reply] { reply->deleteLater(); }, Qt::QueuedConnection);
- }
+ 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.
@@ -1772,13 +1769,11 @@ void QNetworkAccessManagerPrivate::_q_replyFinished()
#endif
}
-void QNetworkAccessManagerPrivate::_q_replyEncrypted()
+void QNetworkAccessManagerPrivate::_q_replyEncrypted(QNetworkReply *reply)
{
#ifndef QT_NO_SSL
Q_Q(QNetworkAccessManager);
- QNetworkReply *reply = qobject_cast<QNetworkReply *>(q->sender());
- if (reply)
- emit q->encrypted(reply);
+ emit q->encrypted(reply);
#endif
}
@@ -1810,11 +1805,13 @@ QNetworkReply *QNetworkAccessManagerPrivate::postProcess(QNetworkReply *reply)
{
Q_Q(QNetworkAccessManager);
QNetworkReplyPrivate::setManager(reply, q);
- q->connect(reply, SIGNAL(finished()), SLOT(_q_replyFinished()));
+ q->connect(reply, &QNetworkReply::finished, reply,
+ [this, reply]() { _q_replyFinished(reply); });
#ifndef QT_NO_SSL
/* In case we're compiled without SSL support, we don't have this signal and we need to
* avoid getting a connection error. */
- q->connect(reply, SIGNAL(encrypted()), SLOT(_q_replyEncrypted()));
+ q->connect(reply, &QNetworkReply::encrypted, reply,
+ [this, reply]() { _q_replyEncrypted(reply); });
q->connect(reply, SIGNAL(sslErrors(QList<QSslError>)), SLOT(_q_replySslErrors(QList<QSslError>)));
q->connect(reply, SIGNAL(preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator*)), SLOT(_q_replyPreSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator*)));
#endif
@@ -1979,7 +1976,7 @@ void QNetworkAccessManagerPrivate::destroyThread()
{
if (thread) {
thread->quit();
- thread->wait(5000);
+ thread->wait(QDeadlineTimer(5000));
if (thread->isFinished())
delete thread;
else
diff --git a/src/network/access/qnetworkaccessmanager.h b/src/network/access/qnetworkaccessmanager.h
index 8134abd6a2..c84116fd41 100644
--- a/src/network/access/qnetworkaccessmanager.h
+++ b/src/network/access/qnetworkaccessmanager.h
@@ -169,7 +169,7 @@ public:
bool autoDeleteReplies() const;
void setAutoDeleteReplies(bool autoDelete);
- int transferTimeout();
+ int transferTimeout() const;
void setTransferTimeout(int timeout = QNetworkRequest::TransferTimeoutPreset);
Q_SIGNALS:
@@ -207,8 +207,6 @@ private:
friend class QNetworkReplyWasmImpl;
#endif
Q_DECLARE_PRIVATE(QNetworkAccessManager)
- Q_PRIVATE_SLOT(d_func(), void _q_replyFinished())
- Q_PRIVATE_SLOT(d_func(), void _q_replyEncrypted())
Q_PRIVATE_SLOT(d_func(), void _q_replySslErrors(QList<QSslError>))
Q_PRIVATE_SLOT(d_func(), void _q_replyPreSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator*))
#ifndef QT_NO_BEARERMANAGEMENT
diff --git a/src/network/access/qnetworkaccessmanager_p.h b/src/network/access/qnetworkaccessmanager_p.h
index d558f61eed..da92cad704 100644
--- a/src/network/access/qnetworkaccessmanager_p.h
+++ b/src/network/access/qnetworkaccessmanager_p.h
@@ -120,8 +120,8 @@ public:
QThread * createThread();
void destroyThread();
- void _q_replyFinished();
- void _q_replyEncrypted();
+ void _q_replyFinished(QNetworkReply *reply);
+ void _q_replyEncrypted(QNetworkReply *reply);
void _q_replySslErrors(const QList<QSslError> &errors);
void _q_replyPreSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator *authenticator);
QNetworkReply *postProcess(QNetworkReply *reply);
diff --git a/src/network/access/qnetworkcookie.cpp b/src/network/access/qnetworkcookie.cpp
index 903de322ff..47f6112b22 100644
--- a/src/network/access/qnetworkcookie.cpp
+++ b/src/network/access/qnetworkcookie.cpp
@@ -131,7 +131,7 @@ QNetworkCookie::QNetworkCookie(const QNetworkCookie &other)
QNetworkCookie::~QNetworkCookie()
{
// QSharedDataPointer auto deletes
- d = 0;
+ d = nullptr;
}
/*!
diff --git a/src/network/access/qnetworkdiskcache.cpp b/src/network/access/qnetworkdiskcache.cpp
index df2e4902a4..b30d1c9664 100644
--- a/src/network/access/qnetworkdiskcache.cpp
+++ b/src/network/access/qnetworkdiskcache.cpp
@@ -180,11 +180,11 @@ QIODevice *QNetworkDiskCache::prepare(const QNetworkCacheMetaData &metaData)
#endif
Q_D(QNetworkDiskCache);
if (!metaData.isValid() || !metaData.url().isValid() || !metaData.saveToDisk())
- return 0;
+ return nullptr;
if (d->cacheDirectory.isEmpty()) {
qWarning("QNetworkDiskCache::prepare() The cache directory is not set");
- return 0;
+ return nullptr;
}
const auto headers = metaData.rawHeaders();
@@ -192,14 +192,14 @@ QIODevice *QNetworkDiskCache::prepare(const QNetworkCacheMetaData &metaData)
if (header.first.compare("content-length", Qt::CaseInsensitive) == 0) {
const qint64 size = header.second.toLongLong();
if (size > (maximumCacheSize() * 3)/4)
- return 0;
+ return nullptr;
break;
}
}
QScopedPointer<QCacheItem> cacheItem(new QCacheItem);
cacheItem->metaData = metaData;
- QIODevice *device = 0;
+ QIODevice *device = nullptr;
if (cacheItem->canCompress()) {
cacheItem->data.open(QBuffer::ReadWrite);
device = &(cacheItem->data);
@@ -208,12 +208,12 @@ QIODevice *QNetworkDiskCache::prepare(const QNetworkCacheMetaData &metaData)
QT_TRY {
cacheItem->file = new QTemporaryFile(templateName, &cacheItem->data);
} QT_CATCH(...) {
- cacheItem->file = 0;
+ cacheItem->file = nullptr;
}
if (!cacheItem->file || !cacheItem->file->open()) {
qWarning("QNetworkDiskCache::prepare() unable to open temporary file");
cacheItem.reset();
- return 0;
+ return nullptr;
}
cacheItem->writeHeader(cacheItem->file);
device = cacheItem->file;
@@ -397,19 +397,19 @@ QIODevice *QNetworkDiskCache::data(const QUrl &url)
Q_D(QNetworkDiskCache);
QScopedPointer<QBuffer> buffer;
if (!url.isValid())
- return 0;
+ return nullptr;
if (d->lastItem.metaData.url() == url && d->lastItem.data.isOpen()) {
buffer.reset(new QBuffer);
buffer->setData(d->lastItem.data.data());
} else {
QScopedPointer<QFile> file(new QFile(d->cacheFileName(url)));
if (!file->open(QFile::ReadOnly | QIODevice::Unbuffered))
- return 0;
+ return nullptr;
if (!d->lastItem.read(file.data(), true)) {
file->close();
remove(url);
- return 0;
+ return nullptr;
}
if (d->lastItem.data.isOpen()) {
// compressed
@@ -419,7 +419,7 @@ QIODevice *QNetworkDiskCache::data(const QUrl &url)
buffer.reset(new QBuffer);
// ### verify that QFile uses the fd size and not the file name
qint64 size = file->size() - file->pos();
- const uchar *p = 0;
+ const uchar *p = nullptr;
#if !defined(Q_OS_INTEGRITY)
p = file->map(file->pos(), size);
#endif
@@ -557,7 +557,7 @@ qint64 QNetworkDiskCache::expire()
for (QCacheItem *item : qAsConst(d->inserting)) {
if (item && item->file && item->file->fileName() == name) {
delete item->file;
- item->file = 0;
+ item->file = nullptr;
break;
}
}
diff --git a/src/network/access/qnetworkreply.cpp b/src/network/access/qnetworkreply.cpp
index aca9cb1c08..c22dce8f1c 100644
--- a/src/network/access/qnetworkreply.cpp
+++ b/src/network/access/qnetworkreply.cpp
@@ -554,14 +554,33 @@ QNetworkAccessManager::Operation QNetworkReply::operation() const
return d_func()->operation;
}
+#if QT_DEPRECATED_SINCE(5, 15)
/*!
+ \deprecated
+
+ Use networkError() instead.
+
Returns the error that was found during the processing of this
request. If no error was found, returns NoError.
- \sa setError()
+ \sa setError(), networkError()
*/
QNetworkReply::NetworkError QNetworkReply::error() const
{
+ return networkError();
+}
+#endif // QT_DEPRECATED_SINCE(5, 15)
+
+/*!
+ \since 5.15
+
+ Returns the error that was found during the processing of this
+ request. If no error was found, returns NoError.
+
+ \sa setError()
+*/
+QNetworkReply::NetworkError QNetworkReply::networkError() const
+{
return d_func()->errorCode;
}
@@ -687,7 +706,7 @@ QVariant QNetworkReply::attribute(QNetworkRequest::Attribute code) const
return d_func()->attributes.value(code);
}
-#ifndef QT_NO_SSL
+#if QT_CONFIG(ssl)
/*!
Returns the SSL configuration and state associated with this
reply, if SSL was used. It will contain the remote server's
@@ -742,7 +761,6 @@ void QNetworkReply::ignoreSslErrors(const QList<QSslError> &errors)
{
ignoreSslErrorsImplementation(errors);
}
-#endif
/*!
\fn void QNetworkReply::sslConfigurationImplementation(QSslConfiguration &configuration) const
@@ -786,6 +804,8 @@ void QNetworkReply::ignoreSslErrorsImplementation(const QList<QSslError> &)
{
}
+#endif // QT_CONFIG(ssl)
+
/*!
If this function is called, SSL errors related to network
connection will be ignored, including certificate validation
@@ -857,7 +877,7 @@ void QNetworkReply::setRequest(const QNetworkRequest &request)
Calling setError() does not emit the error(QNetworkReply::NetworkError)
signal.
- \sa error(), errorString()
+ \sa error(), errorString(), networkError()
*/
void QNetworkReply::setError(NetworkError errorCode, const QString &errorString)
{
diff --git a/src/network/access/qnetworkreply.h b/src/network/access/qnetworkreply.h
index 63c2752caf..139009a56a 100644
--- a/src/network/access/qnetworkreply.h
+++ b/src/network/access/qnetworkreply.h
@@ -124,7 +124,12 @@ public:
QNetworkAccessManager *manager() const;
QNetworkAccessManager::Operation operation() const;
QNetworkRequest request() const;
- NetworkError error() const;
+
+#if QT_DEPRECATED_SINCE(5, 15)
+ QT_DEPRECATED_X("Use networkError()") NetworkError error() const;
+#endif // QT_DEPRECATED_SINCE(5, 15)
+ NetworkError networkError() const;
+
bool isFinished() const;
bool isRunning() const;
QUrl url() const;
@@ -143,7 +148,7 @@ public:
// attributes
QVariant attribute(QNetworkRequest::Attribute code) const;
-#ifndef QT_NO_SSL
+#if QT_CONFIG(ssl)
QSslConfiguration sslConfiguration() const;
void setSslConfiguration(const QSslConfiguration &configuration);
void ignoreSslErrors(const QList<QSslError> &errors);
@@ -157,7 +162,7 @@ Q_SIGNALS:
void metaDataChanged();
void finished();
void error(QNetworkReply::NetworkError);
-#ifndef QT_NO_SSL
+#if QT_CONFIG(ssl)
void encrypted();
void sslErrors(const QList<QSslError> &errors);
void preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator *authenticator);
@@ -182,9 +187,11 @@ protected:
void setRawHeader(const QByteArray &headerName, const QByteArray &value);
void setAttribute(QNetworkRequest::Attribute code, const QVariant &value);
+#if QT_CONFIG(ssl)
virtual void sslConfigurationImplementation(QSslConfiguration &) const;
virtual void setSslConfigurationImplementation(const QSslConfiguration &);
virtual void ignoreSslErrorsImplementation(const QList<QSslError> &);
+#endif
private:
Q_DECLARE_PRIVATE(QNetworkReply)
diff --git a/src/network/access/qnetworkreplyfileimpl.cpp b/src/network/access/qnetworkreplyfileimpl.cpp
index ef319ebf0d..afab8ffd94 100644
--- a/src/network/access/qnetworkreplyfileimpl.cpp
+++ b/src/network/access/qnetworkreplyfileimpl.cpp
@@ -50,7 +50,7 @@
QT_BEGIN_NAMESPACE
QNetworkReplyFileImplPrivate::QNetworkReplyFileImplPrivate()
- : QNetworkReplyPrivate(), managerPrivate(0), realFile(0)
+ : QNetworkReplyPrivate(), managerPrivate(nullptr), realFile(nullptr)
{
qRegisterMetaType<QNetworkRequest::KnownHeaders>();
qRegisterMetaType<QNetworkReply::NetworkError>();
diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp
index f4b8661fe7..002d9ec5d1 100644
--- a/src/network/access/qnetworkreplyhttpimpl.cpp
+++ b/src/network/access/qnetworkreplyhttpimpl.cpp
@@ -693,7 +693,7 @@ void QNetworkReplyHttpImplPrivate::postRequest(const QNetworkRequest &newHttpReq
auto redirectPolicy = QNetworkRequest::ManualRedirectPolicy;
const QVariant value = newHttpRequest.attribute(QNetworkRequest::RedirectPolicyAttribute);
if (value.isValid())
- redirectPolicy = value.value<QNetworkRequest::RedirectPolicy>();
+ redirectPolicy = qvariant_cast<QNetworkRequest::RedirectPolicy>(value);
else if (newHttpRequest.attribute(QNetworkRequest::FollowRedirectsAttribute).toBool())
redirectPolicy = QNetworkRequest::NoLessSafeRedirectPolicy;
@@ -983,7 +983,7 @@ void QNetworkReplyHttpImplPrivate::postRequest(const QNetworkRequest &newHttpReq
}
thread->quit();
- thread->wait(5000);
+ thread->wait(QDeadlineTimer(5000));
if (thread->isFinished())
delete thread;
else
diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp
index 6eab500e8c..a43a29a239 100644
--- a/src/network/access/qnetworkreplyimpl.cpp
+++ b/src/network/access/qnetworkreplyimpl.cpp
@@ -53,9 +53,9 @@
QT_BEGIN_NAMESPACE
inline QNetworkReplyImplPrivate::QNetworkReplyImplPrivate()
- : backend(0), outgoingData(0),
- copyDevice(0),
- cacheEnabled(false), cacheSaveDevice(0),
+ : backend(nullptr), outgoingData(nullptr),
+ copyDevice(nullptr),
+ cacheEnabled(false), cacheSaveDevice(nullptr),
notificationHandlingPaused(false),
bytesDownloaded(0), lastBytesDownloaded(-1), bytesUploaded(-1), preMigrationDownloaded(-1),
httpStatusCode(0),
@@ -63,7 +63,7 @@ inline QNetworkReplyImplPrivate::QNetworkReplyImplPrivate()
, downloadBufferReadPosition(0)
, downloadBufferCurrentSize(0)
, downloadBufferMaximumSize(0)
- , downloadBuffer(0)
+ , downloadBuffer(nullptr)
{
if (request.attribute(QNetworkRequest::EmitAllUploadProgressSignalsAttribute).toBool() == true)
emitAllUploadProgressSignals = true;
@@ -489,7 +489,7 @@ void QNetworkReplyImplPrivate::resumeNotificationHandling()
QAbstractNetworkCache *QNetworkReplyImplPrivate::networkCache() const
{
if (!backend)
- return 0;
+ return nullptr;
return backend->networkCache();
}
@@ -504,7 +504,7 @@ void QNetworkReplyImplPrivate::createCache()
bool QNetworkReplyImplPrivate::isCachingEnabled() const
{
- return (cacheEnabled && networkCache() != 0);
+ return (cacheEnabled && networkCache() != nullptr);
}
void QNetworkReplyImplPrivate::setCachingEnabled(bool enable)
@@ -529,7 +529,7 @@ void QNetworkReplyImplPrivate::setCachingEnabled(bool enable)
"backend %s probably needs to be fixed",
backend->metaObject()->className());
networkCache()->remove(url);
- cacheSaveDevice = 0;
+ cacheSaveDevice = nullptr;
cacheEnabled = false;
}
}
@@ -541,7 +541,7 @@ void QNetworkReplyImplPrivate::completeCacheSave()
} else if (cacheEnabled && cacheSaveDevice) {
networkCache()->insert(cacheSaveDevice);
}
- cacheSaveDevice = 0;
+ cacheSaveDevice = nullptr;
cacheEnabled = false;
}
@@ -610,7 +610,7 @@ void QNetworkReplyImplPrivate::initCacheSaveDevice()
networkCache()->metaObject()->className());
networkCache()->remove(url);
- cacheSaveDevice = 0;
+ cacheSaveDevice = nullptr;
cacheEnabled = false;
}
}
@@ -927,9 +927,9 @@ void QNetworkReplyImpl::abort()
// stop both upload and download
if (d->outgoingData)
- disconnect(d->outgoingData, 0, this, 0);
+ disconnect(d->outgoingData, nullptr, this, nullptr);
if (d->copyDevice)
- disconnect(d->copyDevice, 0, this, 0);
+ disconnect(d->copyDevice, nullptr, this, nullptr);
QNetworkReply::close();
@@ -943,7 +943,7 @@ void QNetworkReplyImpl::abort()
// finished may access the backend
if (d->backend) {
d->backend->deleteLater();
- d->backend = 0;
+ d->backend = nullptr;
}
}
@@ -958,7 +958,7 @@ void QNetworkReplyImpl::close()
if (d->backend)
d->backend->closeDownstreamChannel();
if (d->copyDevice)
- disconnect(d->copyDevice, 0, this, 0);
+ disconnect(d->copyDevice, nullptr, this, nullptr);
QNetworkReply::close();
diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp
index 06ba3a96da..473aa42e1e 100644
--- a/src/network/access/qnetworkrequest.cpp
+++ b/src/network/access/qnetworkrequest.cpp
@@ -426,7 +426,7 @@ public:
inline QNetworkRequestPrivate()
: priority(QNetworkRequest::NormalPriority)
#ifndef QT_NO_SSL
- , sslConfiguration(0)
+ , sslConfiguration(nullptr)
#endif
, maxRedirectsAllowed(maxRedirectCount)
, transferTimeout(0)
@@ -446,7 +446,7 @@ public:
priority = other.priority;
maxRedirectsAllowed = other.maxRedirectsAllowed;
#ifndef QT_NO_SSL
- sslConfiguration = 0;
+ sslConfiguration = nullptr;
if (other.sslConfiguration)
sslConfiguration = new QSslConfiguration(*other.sslConfiguration);
#endif
@@ -532,7 +532,7 @@ QNetworkRequest::QNetworkRequest(const QNetworkRequest &other)
QNetworkRequest::~QNetworkRequest()
{
// QSharedDataPointer auto deletes
- d = 0;
+ d = nullptr;
}
/*!
@@ -918,7 +918,7 @@ void QNetworkRequest::setHttp2Configuration(const QHttp2Configuration &configura
\sa setTransferTimeout
*/
-int QNetworkRequest::transferTimeout()
+int QNetworkRequest::transferTimeout() const
{
return d->transferTimeout;
}
diff --git a/src/network/access/qnetworkrequest.h b/src/network/access/qnetworkrequest.h
index e9098accd9..cb15ca5aa5 100644
--- a/src/network/access/qnetworkrequest.h
+++ b/src/network/access/qnetworkrequest.h
@@ -181,7 +181,7 @@ public:
QHttp2Configuration http2Configuration() const;
void setHttp2Configuration(const QHttp2Configuration &configuration);
- int transferTimeout();
+ int transferTimeout() const;
void setTransferTimeout(int timeout = TransferTimeoutPreset);
#endif // QT_CONFIG(http) || defined(Q_CLANG_QDOC)
private:
diff --git a/src/network/access/qspdyprotocolhandler.cpp b/src/network/access/qspdyprotocolhandler.cpp
new file mode 100644
index 0000000000..eef8df288d
--- /dev/null
+++ b/src/network/access/qspdyprotocolhandler.cpp
@@ -0,0 +1,1304 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 BlackBerry Limited. All rights reserved.
+** Copyright (C) 2016 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/qspdyprotocolhandler_p.h>
+#include <private/qnoncontiguousbytedevice_p.h>
+#include <private/qhttpnetworkconnectionchannel_p.h>
+#include <QtCore/QtEndian>
+
+#if !defined(QT_NO_SSL)
+
+QT_BEGIN_NAMESPACE
+
+static const char spdyDictionary[] = {
+ 0x00, 0x00, 0x00, 0x07, 0x6f, 0x70, 0x74, 0x69, // ....opti
+ 0x6f, 0x6e, 0x73, 0x00, 0x00, 0x00, 0x04, 0x68, // ons....h
+ 0x65, 0x61, 0x64, 0x00, 0x00, 0x00, 0x04, 0x70, // ead....p
+ 0x6f, 0x73, 0x74, 0x00, 0x00, 0x00, 0x03, 0x70, // ost....p
+ 0x75, 0x74, 0x00, 0x00, 0x00, 0x06, 0x64, 0x65, // ut....de
+ 0x6c, 0x65, 0x74, 0x65, 0x00, 0x00, 0x00, 0x05, // lete....
+ 0x74, 0x72, 0x61, 0x63, 0x65, 0x00, 0x00, 0x00, // trace...
+ 0x06, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x00, // .accept.
+ 0x00, 0x00, 0x0e, 0x61, 0x63, 0x63, 0x65, 0x70, // ...accep
+ 0x74, 0x2d, 0x63, 0x68, 0x61, 0x72, 0x73, 0x65, // t-charse
+ 0x74, 0x00, 0x00, 0x00, 0x0f, 0x61, 0x63, 0x63, // t....acc
+ 0x65, 0x70, 0x74, 0x2d, 0x65, 0x6e, 0x63, 0x6f, // ept-enco
+ 0x64, 0x69, 0x6e, 0x67, 0x00, 0x00, 0x00, 0x0f, // ding....
+ 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x2d, 0x6c, // accept-l
+ 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x00, // anguage.
+ 0x00, 0x00, 0x0d, 0x61, 0x63, 0x63, 0x65, 0x70, // ...accep
+ 0x74, 0x2d, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x73, // t-ranges
+ 0x00, 0x00, 0x00, 0x03, 0x61, 0x67, 0x65, 0x00, // ....age.
+ 0x00, 0x00, 0x05, 0x61, 0x6c, 0x6c, 0x6f, 0x77, // ...allow
+ 0x00, 0x00, 0x00, 0x0d, 0x61, 0x75, 0x74, 0x68, // ....auth
+ 0x6f, 0x72, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, // orizatio
+ 0x6e, 0x00, 0x00, 0x00, 0x0d, 0x63, 0x61, 0x63, // n....cac
+ 0x68, 0x65, 0x2d, 0x63, 0x6f, 0x6e, 0x74, 0x72, // he-contr
+ 0x6f, 0x6c, 0x00, 0x00, 0x00, 0x0a, 0x63, 0x6f, // ol....co
+ 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, // nnection
+ 0x00, 0x00, 0x00, 0x0c, 0x63, 0x6f, 0x6e, 0x74, // ....cont
+ 0x65, 0x6e, 0x74, 0x2d, 0x62, 0x61, 0x73, 0x65, // ent-base
+ 0x00, 0x00, 0x00, 0x10, 0x63, 0x6f, 0x6e, 0x74, // ....cont
+ 0x65, 0x6e, 0x74, 0x2d, 0x65, 0x6e, 0x63, 0x6f, // ent-enco
+ 0x64, 0x69, 0x6e, 0x67, 0x00, 0x00, 0x00, 0x10, // ding....
+ 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, // content-
+ 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, // language
+ 0x00, 0x00, 0x00, 0x0e, 0x63, 0x6f, 0x6e, 0x74, // ....cont
+ 0x65, 0x6e, 0x74, 0x2d, 0x6c, 0x65, 0x6e, 0x67, // ent-leng
+ 0x74, 0x68, 0x00, 0x00, 0x00, 0x10, 0x63, 0x6f, // th....co
+ 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x6c, 0x6f, // ntent-lo
+ 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, // cation..
+ 0x00, 0x0b, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, // ..conten
+ 0x74, 0x2d, 0x6d, 0x64, 0x35, 0x00, 0x00, 0x00, // t-md5...
+ 0x0d, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, // .content
+ 0x2d, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x00, 0x00, // -range..
+ 0x00, 0x0c, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, // ..conten
+ 0x74, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x00, 0x00, // t-type..
+ 0x00, 0x04, 0x64, 0x61, 0x74, 0x65, 0x00, 0x00, // ..date..
+ 0x00, 0x04, 0x65, 0x74, 0x61, 0x67, 0x00, 0x00, // ..etag..
+ 0x00, 0x06, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, // ..expect
+ 0x00, 0x00, 0x00, 0x07, 0x65, 0x78, 0x70, 0x69, // ....expi
+ 0x72, 0x65, 0x73, 0x00, 0x00, 0x00, 0x04, 0x66, // res....f
+ 0x72, 0x6f, 0x6d, 0x00, 0x00, 0x00, 0x04, 0x68, // rom....h
+ 0x6f, 0x73, 0x74, 0x00, 0x00, 0x00, 0x08, 0x69, // ost....i
+ 0x66, 0x2d, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x00, // f-match.
+ 0x00, 0x00, 0x11, 0x69, 0x66, 0x2d, 0x6d, 0x6f, // ...if-mo
+ 0x64, 0x69, 0x66, 0x69, 0x65, 0x64, 0x2d, 0x73, // dified-s
+ 0x69, 0x6e, 0x63, 0x65, 0x00, 0x00, 0x00, 0x0d, // ince....
+ 0x69, 0x66, 0x2d, 0x6e, 0x6f, 0x6e, 0x65, 0x2d, // if-none-
+ 0x6d, 0x61, 0x74, 0x63, 0x68, 0x00, 0x00, 0x00, // match...
+ 0x08, 0x69, 0x66, 0x2d, 0x72, 0x61, 0x6e, 0x67, // .if-rang
+ 0x65, 0x00, 0x00, 0x00, 0x13, 0x69, 0x66, 0x2d, // e....if-
+ 0x75, 0x6e, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, // unmodifi
+ 0x65, 0x64, 0x2d, 0x73, 0x69, 0x6e, 0x63, 0x65, // ed-since
+ 0x00, 0x00, 0x00, 0x0d, 0x6c, 0x61, 0x73, 0x74, // ....last
+ 0x2d, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x65, // -modifie
+ 0x64, 0x00, 0x00, 0x00, 0x08, 0x6c, 0x6f, 0x63, // d....loc
+ 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x00, // ation...
+ 0x0c, 0x6d, 0x61, 0x78, 0x2d, 0x66, 0x6f, 0x72, // .max-for
+ 0x77, 0x61, 0x72, 0x64, 0x73, 0x00, 0x00, 0x00, // wards...
+ 0x06, 0x70, 0x72, 0x61, 0x67, 0x6d, 0x61, 0x00, // .pragma.
+ 0x00, 0x00, 0x12, 0x70, 0x72, 0x6f, 0x78, 0x79, // ...proxy
+ 0x2d, 0x61, 0x75, 0x74, 0x68, 0x65, 0x6e, 0x74, // -authent
+ 0x69, 0x63, 0x61, 0x74, 0x65, 0x00, 0x00, 0x00, // icate...
+ 0x13, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2d, 0x61, // .proxy-a
+ 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x61, // uthoriza
+ 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x00, 0x05, // tion....
+ 0x72, 0x61, 0x6e, 0x67, 0x65, 0x00, 0x00, 0x00, // range...
+ 0x07, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x72, // .referer
+ 0x00, 0x00, 0x00, 0x0b, 0x72, 0x65, 0x74, 0x72, // ....retr
+ 0x79, 0x2d, 0x61, 0x66, 0x74, 0x65, 0x72, 0x00, // y-after.
+ 0x00, 0x00, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, // ...serve
+ 0x72, 0x00, 0x00, 0x00, 0x02, 0x74, 0x65, 0x00, // r....te.
+ 0x00, 0x00, 0x07, 0x74, 0x72, 0x61, 0x69, 0x6c, // ...trail
+ 0x65, 0x72, 0x00, 0x00, 0x00, 0x11, 0x74, 0x72, // er....tr
+ 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x2d, 0x65, // ansfer-e
+ 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x00, // ncoding.
+ 0x00, 0x00, 0x07, 0x75, 0x70, 0x67, 0x72, 0x61, // ...upgra
+ 0x64, 0x65, 0x00, 0x00, 0x00, 0x0a, 0x75, 0x73, // de....us
+ 0x65, 0x72, 0x2d, 0x61, 0x67, 0x65, 0x6e, 0x74, // er-agent
+ 0x00, 0x00, 0x00, 0x04, 0x76, 0x61, 0x72, 0x79, // ....vary
+ 0x00, 0x00, 0x00, 0x03, 0x76, 0x69, 0x61, 0x00, // ....via.
+ 0x00, 0x00, 0x07, 0x77, 0x61, 0x72, 0x6e, 0x69, // ...warni
+ 0x6e, 0x67, 0x00, 0x00, 0x00, 0x10, 0x77, 0x77, // ng....ww
+ 0x77, 0x2d, 0x61, 0x75, 0x74, 0x68, 0x65, 0x6e, // w-authen
+ 0x74, 0x69, 0x63, 0x61, 0x74, 0x65, 0x00, 0x00, // ticate..
+ 0x00, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, // ..method
+ 0x00, 0x00, 0x00, 0x03, 0x67, 0x65, 0x74, 0x00, // ....get.
+ 0x00, 0x00, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, // ...statu
+ 0x73, 0x00, 0x00, 0x00, 0x06, 0x32, 0x30, 0x30, // s....200
+ 0x20, 0x4f, 0x4b, 0x00, 0x00, 0x00, 0x07, 0x76, // .OK....v
+ 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x00, 0x00, // ersion..
+ 0x00, 0x08, 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, // ..HTTP.1
+ 0x2e, 0x31, 0x00, 0x00, 0x00, 0x03, 0x75, 0x72, // .1....ur
+ 0x6c, 0x00, 0x00, 0x00, 0x06, 0x70, 0x75, 0x62, // l....pub
+ 0x6c, 0x69, 0x63, 0x00, 0x00, 0x00, 0x0a, 0x73, // lic....s
+ 0x65, 0x74, 0x2d, 0x63, 0x6f, 0x6f, 0x6b, 0x69, // et-cooki
+ 0x65, 0x00, 0x00, 0x00, 0x0a, 0x6b, 0x65, 0x65, // e....kee
+ 0x70, 0x2d, 0x61, 0x6c, 0x69, 0x76, 0x65, 0x00, // p-alive.
+ 0x00, 0x00, 0x06, 0x6f, 0x72, 0x69, 0x67, 0x69, // ...origi
+ 0x6e, 0x31, 0x30, 0x30, 0x31, 0x30, 0x31, 0x32, // n1001012
+ 0x30, 0x31, 0x32, 0x30, 0x32, 0x32, 0x30, 0x35, // 01202205
+ 0x32, 0x30, 0x36, 0x33, 0x30, 0x30, 0x33, 0x30, // 20630030
+ 0x32, 0x33, 0x30, 0x33, 0x33, 0x30, 0x34, 0x33, // 23033043
+ 0x30, 0x35, 0x33, 0x30, 0x36, 0x33, 0x30, 0x37, // 05306307
+ 0x34, 0x30, 0x32, 0x34, 0x30, 0x35, 0x34, 0x30, // 40240540
+ 0x36, 0x34, 0x30, 0x37, 0x34, 0x30, 0x38, 0x34, // 64074084
+ 0x30, 0x39, 0x34, 0x31, 0x30, 0x34, 0x31, 0x31, // 09410411
+ 0x34, 0x31, 0x32, 0x34, 0x31, 0x33, 0x34, 0x31, // 41241341
+ 0x34, 0x34, 0x31, 0x35, 0x34, 0x31, 0x36, 0x34, // 44154164
+ 0x31, 0x37, 0x35, 0x30, 0x32, 0x35, 0x30, 0x34, // 17502504
+ 0x35, 0x30, 0x35, 0x32, 0x30, 0x33, 0x20, 0x4e, // 505203.N
+ 0x6f, 0x6e, 0x2d, 0x41, 0x75, 0x74, 0x68, 0x6f, // on-Autho
+ 0x72, 0x69, 0x74, 0x61, 0x74, 0x69, 0x76, 0x65, // ritative
+ 0x20, 0x49, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, // .Informa
+ 0x74, 0x69, 0x6f, 0x6e, 0x32, 0x30, 0x34, 0x20, // tion204.
+ 0x4e, 0x6f, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x65, // No.Conte
+ 0x6e, 0x74, 0x33, 0x30, 0x31, 0x20, 0x4d, 0x6f, // nt301.Mo
+ 0x76, 0x65, 0x64, 0x20, 0x50, 0x65, 0x72, 0x6d, // ved.Perm
+ 0x61, 0x6e, 0x65, 0x6e, 0x74, 0x6c, 0x79, 0x34, // anently4
+ 0x30, 0x30, 0x20, 0x42, 0x61, 0x64, 0x20, 0x52, // 00.Bad.R
+ 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x34, 0x30, // equest40
+ 0x31, 0x20, 0x55, 0x6e, 0x61, 0x75, 0x74, 0x68, // 1.Unauth
+ 0x6f, 0x72, 0x69, 0x7a, 0x65, 0x64, 0x34, 0x30, // orized40
+ 0x33, 0x20, 0x46, 0x6f, 0x72, 0x62, 0x69, 0x64, // 3.Forbid
+ 0x64, 0x65, 0x6e, 0x34, 0x30, 0x34, 0x20, 0x4e, // den404.N
+ 0x6f, 0x74, 0x20, 0x46, 0x6f, 0x75, 0x6e, 0x64, // ot.Found
+ 0x35, 0x30, 0x30, 0x20, 0x49, 0x6e, 0x74, 0x65, // 500.Inte
+ 0x72, 0x6e, 0x61, 0x6c, 0x20, 0x53, 0x65, 0x72, // rnal.Ser
+ 0x76, 0x65, 0x72, 0x20, 0x45, 0x72, 0x72, 0x6f, // ver.Erro
+ 0x72, 0x35, 0x30, 0x31, 0x20, 0x4e, 0x6f, 0x74, // r501.Not
+ 0x20, 0x49, 0x6d, 0x70, 0x6c, 0x65, 0x6d, 0x65, // .Impleme
+ 0x6e, 0x74, 0x65, 0x64, 0x35, 0x30, 0x33, 0x20, // nted503.
+ 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x20, // Service.
+ 0x55, 0x6e, 0x61, 0x76, 0x61, 0x69, 0x6c, 0x61, // Unavaila
+ 0x62, 0x6c, 0x65, 0x4a, 0x61, 0x6e, 0x20, 0x46, // bleJan.F
+ 0x65, 0x62, 0x20, 0x4d, 0x61, 0x72, 0x20, 0x41, // eb.Mar.A
+ 0x70, 0x72, 0x20, 0x4d, 0x61, 0x79, 0x20, 0x4a, // pr.May.J
+ 0x75, 0x6e, 0x20, 0x4a, 0x75, 0x6c, 0x20, 0x41, // un.Jul.A
+ 0x75, 0x67, 0x20, 0x53, 0x65, 0x70, 0x74, 0x20, // ug.Sept.
+ 0x4f, 0x63, 0x74, 0x20, 0x4e, 0x6f, 0x76, 0x20, // Oct.Nov.
+ 0x44, 0x65, 0x63, 0x20, 0x30, 0x30, 0x3a, 0x30, // Dec.00.0
+ 0x30, 0x3a, 0x30, 0x30, 0x20, 0x4d, 0x6f, 0x6e, // 0.00.Mon
+ 0x2c, 0x20, 0x54, 0x75, 0x65, 0x2c, 0x20, 0x57, // ..Tue..W
+ 0x65, 0x64, 0x2c, 0x20, 0x54, 0x68, 0x75, 0x2c, // ed..Thu.
+ 0x20, 0x46, 0x72, 0x69, 0x2c, 0x20, 0x53, 0x61, // .Fri..Sa
+ 0x74, 0x2c, 0x20, 0x53, 0x75, 0x6e, 0x2c, 0x20, // t..Sun..
+ 0x47, 0x4d, 0x54, 0x63, 0x68, 0x75, 0x6e, 0x6b, // GMTchunk
+ 0x65, 0x64, 0x2c, 0x74, 0x65, 0x78, 0x74, 0x2f, // ed.text.
+ 0x68, 0x74, 0x6d, 0x6c, 0x2c, 0x69, 0x6d, 0x61, // html.ima
+ 0x67, 0x65, 0x2f, 0x70, 0x6e, 0x67, 0x2c, 0x69, // ge.png.i
+ 0x6d, 0x61, 0x67, 0x65, 0x2f, 0x6a, 0x70, 0x67, // mage.jpg
+ 0x2c, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2f, 0x67, // .image.g
+ 0x69, 0x66, 0x2c, 0x61, 0x70, 0x70, 0x6c, 0x69, // if.appli
+ 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x78, // cation.x
+ 0x6d, 0x6c, 0x2c, 0x61, 0x70, 0x70, 0x6c, 0x69, // ml.appli
+ 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x78, // cation.x
+ 0x68, 0x74, 0x6d, 0x6c, 0x2b, 0x78, 0x6d, 0x6c, // html.xml
+ 0x2c, 0x74, 0x65, 0x78, 0x74, 0x2f, 0x70, 0x6c, // .text.pl
+ 0x61, 0x69, 0x6e, 0x2c, 0x74, 0x65, 0x78, 0x74, // ain.text
+ 0x2f, 0x6a, 0x61, 0x76, 0x61, 0x73, 0x63, 0x72, // .javascr
+ 0x69, 0x70, 0x74, 0x2c, 0x70, 0x75, 0x62, 0x6c, // ipt.publ
+ 0x69, 0x63, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, // icprivat
+ 0x65, 0x6d, 0x61, 0x78, 0x2d, 0x61, 0x67, 0x65, // emax-age
+ 0x3d, 0x67, 0x7a, 0x69, 0x70, 0x2c, 0x64, 0x65, // .gzip.de
+ 0x66, 0x6c, 0x61, 0x74, 0x65, 0x2c, 0x73, 0x64, // flate.sd
+ 0x63, 0x68, 0x63, 0x68, 0x61, 0x72, 0x73, 0x65, // chcharse
+ 0x74, 0x3d, 0x75, 0x74, 0x66, 0x2d, 0x38, 0x63, // t.utf-8c
+ 0x68, 0x61, 0x72, 0x73, 0x65, 0x74, 0x3d, 0x69, // harset.i
+ 0x73, 0x6f, 0x2d, 0x38, 0x38, 0x35, 0x39, 0x2d, // so-8859-
+ 0x31, 0x2c, 0x75, 0x74, 0x66, 0x2d, 0x2c, 0x2a, // 1.utf-..
+ 0x2c, 0x65, 0x6e, 0x71, 0x3d, 0x30, 0x2e // .enq.0.
+};
+
+// uncomment to debug
+//static void printHex(const QByteArray &ba)
+//{
+// QByteArray hex;
+// QByteArray clearText;
+// for (int a = 0; a < ba.count(); ++a) {
+// QByteArray currentHexChar = QByteArray(1, ba.at(a)).toHex().rightJustified(2, ' ');
+// QByteArray currentChar;
+// if (ba.at(a) >= 32 && ba.at(a) < 126) { // if ASCII, print the letter
+// currentChar = QByteArray(1, ba.at(a));
+// } else {
+// currentChar = " ";
+// }
+// clearText.append(currentChar.rightJustified(2, ' '));
+// hex.append(currentHexChar);
+// hex.append(' ');
+// clearText.append(' ');
+// }
+// int chunkSize = 102; // 12 == 4 bytes per line
+// for (int a = 0; a < hex.count(); a += chunkSize) {
+// qDebug() << hex.mid(a, chunkSize);
+// qDebug() << clearText.mid(a, chunkSize);
+// }
+//}
+
+QSpdyProtocolHandler::QSpdyProtocolHandler(QHttpNetworkConnectionChannel *channel)
+ : QObject(nullptr), QAbstractProtocolHandler(channel),
+ m_nextStreamID(-1),
+ m_maxConcurrentStreams(100), // 100 is recommended in the SPDY RFC
+ m_initialWindowSize(0),
+ m_waitingForCompleteStream(false)
+{
+ m_inflateStream.zalloc = Z_NULL;
+ m_inflateStream.zfree = Z_NULL;
+ m_inflateStream.opaque = Z_NULL;
+ int zlibRet = inflateInit(&m_inflateStream);
+ Q_ASSERT(zlibRet == Z_OK);
+
+ m_deflateStream.zalloc = Z_NULL;
+ m_deflateStream.zfree = Z_NULL;
+ m_deflateStream.opaque = Z_NULL;
+
+ // Do actually not compress (i.e. compression level = 0)
+ // when sending the headers because of the CRIME attack
+ zlibRet = deflateInit(&m_deflateStream, /* compression level = */ 0);
+ Q_ASSERT(zlibRet == Z_OK);
+ Q_UNUSED(zlibRet); // silence -Wunused-variable
+}
+
+QSpdyProtocolHandler::~QSpdyProtocolHandler()
+{
+ deflateEnd(&m_deflateStream);
+ deflateEnd(&m_inflateStream);
+}
+
+bool QSpdyProtocolHandler::sendRequest()
+{
+ Q_ASSERT(!m_reply);
+
+ int maxPossibleRequests = m_maxConcurrentStreams - m_inFlightStreams.count();
+ Q_ASSERT(maxPossibleRequests >= 0);
+ if (maxPossibleRequests == 0)
+ return true; // return early if max concurrent requests are exceeded
+
+ m_channel->state = QHttpNetworkConnectionChannel::WritingState;
+
+ int requestsToSend = qMin(m_channel->spdyRequestsToSend.size(), maxPossibleRequests);
+
+ QMultiMap<int, HttpMessagePair>::iterator it = m_channel->spdyRequestsToSend.begin();
+ // requests will be ordered by priority (see QMultiMap doc)
+ for (int a = 0; a < requestsToSend; ++a) {
+ HttpMessagePair currentPair = *it;
+ QHttpNetworkRequest currentRequest = currentPair.first;
+ QHttpNetworkReply *currentReply = currentPair.second;
+
+ currentReply->setSpdyWasUsed(true);
+ qint32 streamID = generateNextStreamID();
+ m_streamIDs.insert(currentReply, streamID);
+
+ currentReply->setRequest(currentRequest);
+ currentReply->d_func()->connection = m_connection;
+ currentReply->d_func()->connectionChannel = m_channel;
+ m_inFlightStreams.insert(streamID, currentPair);
+ connect(currentReply, SIGNAL(destroyed(QObject*)), this, SLOT(_q_replyDestroyed(QObject*)));
+
+ sendSYN_STREAM(currentPair, streamID, /* associatedToStreamID = */ 0);
+ m_channel->spdyRequestsToSend.erase(it++);
+ }
+ m_channel->state = QHttpNetworkConnectionChannel::IdleState;
+ return true;
+}
+
+void QSpdyProtocolHandler::_q_replyDestroyed(QObject* reply)
+{
+ qint32 streamID = m_streamIDs.take(reply);
+ if (m_inFlightStreams.remove(streamID))
+ sendRST_STREAM(streamID, RST_STREAM_CANCEL);
+}
+
+void QSpdyProtocolHandler::_q_receiveReply()
+{
+ Q_ASSERT(m_socket);
+
+ // only run when the QHttpNetworkConnection is not currently being destructed, e.g.
+ // this function is called from _q_disconnected which is called because
+ // of ~QHttpNetworkConnectionPrivate
+ if (!qobject_cast<QHttpNetworkConnection*>(m_connection)) {
+ return;
+ }
+
+ if (bytesAvailable() < 8)
+ return; // cannot read frame headers, wait for more data
+
+ char frameHeadersRaw[8];
+ if (!readNextChunk(8, frameHeadersRaw))
+ return; // this should not happen, we just checked
+
+ const QByteArray frameHeaders(frameHeadersRaw, 8); // ### try without memcpy
+ if (frameHeadersRaw[0] & 0x80) {
+ handleControlFrame(frameHeaders);
+ } else {
+ handleDataFrame(frameHeaders);
+ }
+
+ // after handling the current frame, check whether there is more data waiting
+ if (m_socket->bytesAvailable() > 0)
+ QMetaObject::invokeMethod(m_channel, "_q_receiveReply", Qt::QueuedConnection);
+}
+
+void QSpdyProtocolHandler::_q_readyRead()
+{
+ _q_receiveReply();
+}
+
+static qint16 twoBytesToInt(const char *bytes)
+{
+ return qFromBigEndian<qint16>(bytes);
+}
+
+static qint32 threeBytesToInt(const char *bytes)
+{
+ return qFromBigEndian<qint32>(bytes) >> 8;
+}
+
+static qint32 fourBytesToInt(const char *bytes)
+{
+ return qFromBigEndian<qint32>(bytes);
+}
+
+static void appendIntToThreeBytes(char *output, qint32 number)
+{
+ qToBigEndian<qint16>(number, output + 1);
+ qToBigEndian<qint8>(number >> 16, output);
+}
+
+static void appendIntToFourBytes(char *output, qint32 number)
+{
+ qToBigEndian<qint32>(number, output);
+}
+
+static QByteArray intToFourBytes(qint32 number) // ### try to use appendIntToFourBytes where possible
+{
+ char data[4];
+ qToBigEndian<qint32>(number, data);
+ QByteArray ret(data, 4);
+ return ret;
+}
+
+static QByteArray intToThreeBytes(qint32 number)
+{
+ char data[4];
+ qToBigEndian<qint32>(number << 8, data);
+ QByteArray ret(data, 3);
+ return ret;
+}
+
+static qint32 getStreamID(const char *bytes)
+{
+ // eliminate most significant bit; it might be 0 or 1 depending on whether
+ // we are dealing with a control or data frame
+ return fourBytesToInt(bytes) & 0x3fffffff;
+}
+
+static QByteArray headerField(const QByteArray &name, const QByteArray &value)
+{
+ QByteArray ret;
+ ret.reserve(name.count() + value.count() + 8); // 4 byte for length each
+ ret.append(intToFourBytes(name.count()));
+ ret.append(name);
+ ret.append(intToFourBytes(value.count()));
+ ret.append(value);
+ return ret;
+}
+
+bool QSpdyProtocolHandler::uncompressHeader(const QByteArray &input, QByteArray *output)
+{
+ const size_t chunkSize = 1024;
+ char outputRaw[chunkSize];
+ // input bytes will not be changed by zlib, so it is safe to const_cast here
+ m_inflateStream.next_in = const_cast<Bytef *>(reinterpret_cast<const Bytef *>(input.constData()));
+ m_inflateStream.avail_in = input.count();
+ m_inflateStream.total_in = input.count();
+ int zlibRet;
+
+ do {
+ m_inflateStream.next_out = reinterpret_cast<Bytef *>(outputRaw);
+ m_inflateStream.avail_out = chunkSize;
+ zlibRet = inflate(&m_inflateStream, Z_SYNC_FLUSH);
+ if (zlibRet == Z_NEED_DICT) {
+ zlibRet = inflateSetDictionary(&m_inflateStream,
+ reinterpret_cast<const Bytef*>(spdyDictionary),
+ /* dictionaryLength = */ 1423);
+ Q_ASSERT(zlibRet == Z_OK);
+ continue;
+ }
+ switch (zlibRet) {
+ case Z_BUF_ERROR: {
+ if (m_inflateStream.avail_in == 0) {
+ int outputSize = chunkSize - m_inflateStream.avail_out;
+ output->append(outputRaw, outputSize);
+ m_inflateStream.avail_out = chunkSize;
+ }
+ break;
+ }
+ case Z_OK: {
+ int outputSize = chunkSize - m_inflateStream.avail_out;
+ output->append(outputRaw, outputSize);
+ break;
+ }
+ default: {
+ qWarning("got unexpected zlib return value: %d", zlibRet);
+ return false;
+ }
+ }
+ } while (m_inflateStream.avail_in > 0 && zlibRet != Z_STREAM_END);
+
+ Q_ASSERT(m_inflateStream.avail_in == 0);
+ return true;
+}
+
+QByteArray QSpdyProtocolHandler::composeHeader(const QHttpNetworkRequest &request)
+{
+ QByteArray uncompressedHeader;
+ uncompressedHeader.reserve(300); // rough estimate
+
+ // calculate additional headers first, because we need to know the size
+ // ### do not partially copy the list, but restrict the set header fields
+ // in QHttpNetworkConnection
+ QVector<QPair<QByteArray, QByteArray> > additionalHeaders;
+ for (int a = 0; a < request.header().count(); ++a) {
+ QByteArray key = request.header().at(a).first;
+ if (key == "Connection" || key == "Host" || key == "Keep-Alive"
+ || key == "Proxy-Connection" || key == "Transfer-Encoding")
+ continue; // those headers are not valid (section 3.2.1)
+ additionalHeaders.append(request.header().at(a));
+ }
+
+ qint32 numberOfHeaderPairs = 5 + additionalHeaders.count(); // 5 mandatory below + the additional ones
+ uncompressedHeader.append(intToFourBytes(numberOfHeaderPairs));
+
+ // mandatory header fields:
+
+ uncompressedHeader.append(headerField(":method", request.methodName()));
+#ifndef QT_NO_NETWORKPROXY
+ bool useProxy = m_connection->d_func()->networkProxy.type() != QNetworkProxy::NoProxy;
+ uncompressedHeader.append(headerField(":path", request.uri(useProxy)));
+#else
+ uncompressedHeader.append(headerField(":path", request.uri(false)));
+#endif
+ uncompressedHeader.append(headerField(":version", "HTTP/1.1"));
+
+ uncompressedHeader.append(headerField(":host", request.url().authority(QUrl::FullyEncoded | QUrl::RemoveUserInfo).toLatin1()));
+
+ uncompressedHeader.append(headerField(":scheme", request.url().scheme().toLatin1()));
+
+ // end of mandatory header fields
+
+ // now add the additional headers
+ for (int a = 0; a < additionalHeaders.count(); ++a) {
+ uncompressedHeader.append(headerField(additionalHeaders.at(a).first.toLower(),
+ additionalHeaders.at(a).second));
+ }
+
+ m_deflateStream.total_in = uncompressedHeader.count();
+ m_deflateStream.avail_in = uncompressedHeader.count();
+ m_deflateStream.next_in = reinterpret_cast<unsigned char *>(uncompressedHeader.data());
+ int outputBytes = uncompressedHeader.count() + 30; // 30 bytes of compression header overhead
+ m_deflateStream.avail_out = outputBytes;
+ unsigned char *out = new unsigned char[outputBytes];
+ m_deflateStream.next_out = out;
+ int availOutBefore = m_deflateStream.avail_out;
+ int zlibRet = deflate(&m_deflateStream, Z_SYNC_FLUSH); // do everything in one go since we use no compression
+ int compressedHeaderSize = availOutBefore - m_deflateStream.avail_out;
+ Q_ASSERT(zlibRet == Z_OK); // otherwise, we need to allocate more outputBytes
+ Q_UNUSED(zlibRet); // silence -Wunused-variable
+ Q_ASSERT(m_deflateStream.avail_in == 0);
+ QByteArray compressedHeader(reinterpret_cast<char *>(out), compressedHeaderSize);
+ delete[] out;
+
+ return compressedHeader;
+}
+
+quint64 QSpdyProtocolHandler::bytesAvailable() const
+{
+ Q_ASSERT(m_socket);
+ return m_spdyBuffer.byteAmount() + m_socket->bytesAvailable();
+}
+
+bool QSpdyProtocolHandler::readNextChunk(qint64 length, char *sink)
+{
+ qint64 expectedReadBytes = length;
+ qint64 requiredBytesFromBuffer = 0;
+
+ if (m_waitingForCompleteStream) {
+ requiredBytesFromBuffer = qMin(length, m_spdyBuffer.byteAmount());
+ // ### if next chunk from buffer bigger than what we want to read,
+ // we have to call read() (which memcpy's). Otherwise, we can just
+ // read the next chunk without memcpy'ing.
+ qint64 bytesReadFromBuffer = m_spdyBuffer.read(sink, requiredBytesFromBuffer);
+ Q_ASSERT(bytesReadFromBuffer == requiredBytesFromBuffer);
+ if (length <= bytesReadFromBuffer) {
+ return true; // buffer > required size -> no need to read from socket
+ }
+ expectedReadBytes -= requiredBytesFromBuffer;
+ }
+ qint64 readBytes = m_socket->read(sink + requiredBytesFromBuffer, expectedReadBytes);
+
+ if (readBytes < expectedReadBytes) {
+ m_waitingForCompleteStream = true;
+ // ### this is inefficient, we should not put back so much data into the buffer
+ QByteArray temp(sink, requiredBytesFromBuffer + readBytes);
+ m_spdyBuffer.append(temp);
+ return false;
+ } else {
+ return true; // buffer must be cleared by calling function
+ }
+}
+
+void QSpdyProtocolHandler::sendControlFrame(FrameType type,
+ ControlFrameFlags flags,
+ const char *data,
+ quint32 length)
+{
+ // frame type and stream ID
+ char header[8];
+ header[0] = 0x80u; // leftmost bit == 1 -> is a control frame
+ header[1] = 0x03; // 3 bit == version 3
+ header[2] = 0;
+ switch (type) {
+ case FrameType_CREDENTIAL: {
+ qWarning("sending SPDY CREDENTIAL frame is not yet implemented"); // QTBUG-36188
+ return;
+ }
+ default:
+ header[3] = type;
+ }
+
+ // flags
+ header[4] = 0;
+ if (flags & ControlFrame_FLAG_FIN || length == 0) {
+ Q_ASSERT(type == FrameType_SYN_STREAM || type == FrameType_SYN_REPLY
+ || type == FrameType_HEADERS || length == 0);
+ header[4] |= ControlFrame_FLAG_FIN;
+ }
+ if (flags & ControlFrame_FLAG_UNIDIRECTIONAL) {
+ Q_ASSERT(type == FrameType_SYN_STREAM);
+ header[4] |= ControlFrame_FLAG_UNIDIRECTIONAL;
+ }
+
+ // length
+ appendIntToThreeBytes(header + 5, length);
+
+ qint64 written = m_socket->write(header, 8);
+ Q_ASSERT(written == 8);
+ written = m_socket->write(data, length);
+ Q_ASSERT(written == length);
+ Q_UNUSED(written); // silence -Wunused-variable
+}
+
+void QSpdyProtocolHandler::sendSYN_STREAM(const HttpMessagePair &messagePair,
+ qint32 streamID, qint32 associatedToStreamID)
+{
+ QHttpNetworkRequest request = messagePair.first;
+ QHttpNetworkReply *reply = messagePair.second;
+
+ ControlFrameFlags flags;
+
+ if (!request.uploadByteDevice()) {
+ // no upload -> this is the last frame, send the FIN flag
+ flags |= ControlFrame_FLAG_FIN;
+ reply->d_func()->state = QHttpNetworkReplyPrivate::SPDYHalfClosed;
+ } else {
+ reply->d_func()->state = QHttpNetworkReplyPrivate::SPDYUploading;
+
+ // hack: set the stream ID on the device directly, so when we get
+ // the signal for uploading we know which stream we are sending on
+ m_streamIDs.insert(request.uploadByteDevice(), streamID);
+
+ QObject::connect(request.uploadByteDevice(), SIGNAL(readyRead()), this,
+ SLOT(_q_uploadDataReadyRead()), Qt::QueuedConnection);
+ QObject::connect(request.uploadByteDevice(), SIGNAL(destroyed(QObject*)), this,
+ SLOT(_q_uploadDataDestroyed(QObject *)));
+ }
+
+ QByteArray namesAndValues = composeHeader(request);
+ quint32 length = namesAndValues.count() + 10; // 10 == 4 for Stream-ID + 4 for Associated-To-Stream-ID
+ // + 2 for Priority, Unused and Slot
+
+ QByteArray wireData;
+ wireData.reserve(length);
+ wireData.append(intToFourBytes(streamID));
+ wireData.append(intToFourBytes(associatedToStreamID));
+
+ // priority (3 bits) / unused (5 bits) / slot (8 bits)
+ char prioAndSlot[2];
+ switch (request.priority()) {
+ case QHttpNetworkRequest::HighPriority:
+ prioAndSlot[0] = 0x00; // == prio 0 (highest)
+ break;
+ case QHttpNetworkRequest::NormalPriority:
+ prioAndSlot[0] = 0x80u; // == prio 4
+ break;
+ case QHttpNetworkRequest::LowPriority:
+ prioAndSlot[0] = 0xe0u; // == prio 7 (lowest)
+ break;
+ }
+ prioAndSlot[1] = 0x00; // slot in client certificates (not supported currently)
+ wireData.append(prioAndSlot, 2);
+
+ wireData.append(namesAndValues);
+
+ sendControlFrame(FrameType_SYN_STREAM, flags, wireData.constData(), length);
+
+ if (reply->d_func()->state == QHttpNetworkReplyPrivate::SPDYUploading)
+ uploadData(streamID);
+}
+
+void QSpdyProtocolHandler::_q_uploadDataDestroyed(QObject *uploadData)
+{
+ m_streamIDs.remove(uploadData);
+}
+
+void QSpdyProtocolHandler::sendRST_STREAM(qint32 streamID, RST_STREAM_STATUS_CODE statusCode)
+{
+ char wireData[8];
+ appendIntToFourBytes(wireData, streamID);
+ appendIntToFourBytes(wireData + 4, statusCode);
+ sendControlFrame(FrameType_RST_STREAM, /* flags = */ { }, wireData, /* length = */ 8);
+}
+
+void QSpdyProtocolHandler::sendPING(quint32 pingID)
+{
+ char rawData[4];
+ appendIntToFourBytes(rawData, pingID);
+ sendControlFrame(FrameType_PING, /* flags = */ { }, rawData, /* length = */ 4);
+}
+
+bool QSpdyProtocolHandler::uploadData(qint32 streamID)
+{
+ // we only rely on SPDY flow control here and don't care about TCP buffers
+ if (!m_inFlightStreams.contains(streamID)) {
+ sendRST_STREAM(streamID, RST_STREAM_INVALID_STREAM);
+ return false;
+ }
+
+ HttpMessagePair messagePair = m_inFlightStreams.value(streamID);
+ QHttpNetworkRequest request = messagePair.first;
+ QHttpNetworkReply *reply = messagePair.second;
+ Q_ASSERT(reply);
+ QHttpNetworkReplyPrivate *replyPrivate = reply->d_func();
+ Q_ASSERT(replyPrivate);
+
+ if (reply->d_func()->state == QHttpNetworkReplyPrivate::SPDYHalfClosed || reply->d_func()->state == QHttpNetworkReplyPrivate::SPDYClosed) {
+ qWarning("Trying to upload to closed stream");
+ return false;
+ }
+
+ qint32 dataLeftInWindow = replyPrivate->windowSizeUpload
+ - replyPrivate->currentlyUploadedDataInWindow;
+
+ while (dataLeftInWindow > 0 && !request.uploadByteDevice()->atEnd()) {
+
+ // get pointer to upload data
+ qint64 currentReadSize = 0;
+ const char *readPointer = request.uploadByteDevice()->readPointer(dataLeftInWindow,
+ currentReadSize);
+
+ if (currentReadSize == -1) {
+ // premature eof happened
+ m_connection->d_func()->emitReplyError(m_socket, reply,
+ QNetworkReply::UnknownNetworkError);
+ return false;
+ } else if (readPointer == nullptr || currentReadSize == 0) {
+ // nothing to read currently, break the loop
+ break;
+ } else {
+ DataFrameFlags flags;
+ // we will send the FIN flag later if appropriate
+ qint64 currentWriteSize = sendDataFrame(streamID, flags, currentReadSize, readPointer);
+ if (currentWriteSize == -1 || currentWriteSize != currentReadSize) {
+ // socket broke down
+ m_connection->d_func()->emitReplyError(m_socket, reply,
+ QNetworkReply::UnknownNetworkError);
+ return false;
+ } else {
+ replyPrivate->currentlyUploadedDataInWindow += currentWriteSize;
+ replyPrivate->totallyUploadedData += currentWriteSize;
+ dataLeftInWindow = replyPrivate->windowSizeUpload
+ - replyPrivate->currentlyUploadedDataInWindow;
+ request.uploadByteDevice()->advanceReadPointer(currentWriteSize);
+
+ emit reply->dataSendProgress(replyPrivate->totallyUploadedData,
+ request.contentLength());
+ }
+ }
+ }
+ if (replyPrivate->totallyUploadedData == request.contentLength()) {
+ DataFrameFlags finFlag = DataFrame_FLAG_FIN;
+ qint64 writeSize = sendDataFrame(streamID, finFlag, 0, nullptr);
+ Q_ASSERT(writeSize == 0);
+ Q_UNUSED(writeSize); // silence -Wunused-variable
+ replyPrivate->state = QHttpNetworkReplyPrivate::SPDYHalfClosed;
+ if (reply->request().uploadByteDevice())
+ reply->request().uploadByteDevice()->disconnect(this);
+ // ### this will not work if the content length is not known, but
+ // then again many servers will fail in this case anyhow according
+ // to the SPDY RFC
+ }
+ return true;
+}
+
+void QSpdyProtocolHandler::_q_uploadDataReadyRead()
+{
+ QNonContiguousByteDevice *device = qobject_cast<QNonContiguousByteDevice *>(sender());
+ Q_ASSERT(device);
+ qint32 streamID = m_streamIDs.value(device);
+ Q_ASSERT(streamID > 0);
+ uploadData(streamID);
+}
+
+void QSpdyProtocolHandler::sendWINDOW_UPDATE(qint32 streamID, quint32 deltaWindowSize)
+{
+ char windowUpdateData[8];
+ appendIntToFourBytes(windowUpdateData, streamID);
+ appendIntToFourBytes(windowUpdateData + 4, deltaWindowSize);
+
+ sendControlFrame(FrameType_WINDOW_UPDATE, /* flags = */ { }, windowUpdateData, /* length = */ 8);
+}
+
+qint64 QSpdyProtocolHandler::sendDataFrame(qint32 streamID, DataFrameFlags flags,
+ quint32 length, const char *data)
+{
+ QByteArray wireData;
+ wireData.reserve(8);
+
+ wireData.append(intToFourBytes(streamID));
+ wireData.append(flags);
+ wireData.append(intToThreeBytes(length));
+
+ Q_ASSERT(m_socket);
+ m_socket->write(wireData);
+
+ if (data) {
+ qint64 ret = m_socket->write(data, length);
+ return ret;
+ } else {
+ return 0; // nothing to write, e.g. FIN flag
+ }
+}
+
+void QSpdyProtocolHandler::handleControlFrame(const QByteArray &frameHeaders) // ### make it char *
+{
+ Q_ASSERT(frameHeaders.count() >= 8);
+ qint16 version = twoBytesToInt(frameHeaders.constData());
+ version &= 0x3fff; // eliminate most significant bit to determine version
+ Q_ASSERT(version == 3);
+
+ qint16 type = twoBytesToInt(frameHeaders.constData() + 2);
+
+ char flags = frameHeaders.at(4);
+ qint32 length = threeBytesToInt(frameHeaders.constData() + 5);
+ Q_ASSERT(length > 0);
+
+ QByteArray frameData;
+ frameData.resize(length);
+ if (!readNextChunk(length, frameData.data())) {
+ // put back the frame headers to the buffer
+ m_spdyBuffer.prepend(frameHeaders);
+ return; // we couldn't read the whole frame and need to wait
+ } else {
+ m_spdyBuffer.clear();
+ m_waitingForCompleteStream = false;
+ }
+
+ switch (type) {
+ case FrameType_SYN_STREAM: {
+ handleSYN_STREAM(flags, length, frameData);
+ break;
+ }
+ case FrameType_SYN_REPLY: {
+ handleSYN_REPLY(flags, length, frameData);
+ break;
+ }
+ case FrameType_RST_STREAM: {
+ handleRST_STREAM(flags, length, frameData);
+ break;
+ }
+ case FrameType_SETTINGS: {
+ handleSETTINGS(flags, length, frameData);
+ break;
+ }
+ case FrameType_PING: {
+ handlePING(flags, length, frameData);
+ break;
+ }
+ case FrameType_GOAWAY: {
+ handleGOAWAY(flags, length, frameData);
+ break;
+ }
+ case FrameType_HEADERS: {
+ handleHEADERS(flags, length, frameData);
+ break;
+ }
+ case FrameType_WINDOW_UPDATE: {
+ handleWINDOW_UPDATE(flags, length, frameData);
+ break;
+ }
+ default:
+ qWarning("cannot handle frame of type %d", int(type));
+ }
+}
+
+void QSpdyProtocolHandler::handleSYN_STREAM(char /*flags*/, quint32 /*length*/,
+ const QByteArray &frameData)
+{
+ // not implemented; will be implemented when servers start using it
+ // we just tell the server that we do not accept that
+
+ qint32 streamID = getStreamID(frameData.constData());
+
+ sendRST_STREAM(streamID, RST_STREAM_REFUSED_STREAM);
+}
+
+void QSpdyProtocolHandler::handleSYN_REPLY(char flags, quint32 /*length*/, const QByteArray &frameData)
+{
+ parseHttpHeaders(flags, frameData);
+}
+
+void QSpdyProtocolHandler::parseHttpHeaders(char flags, const QByteArray &frameData)
+{
+ qint32 streamID = getStreamID(frameData.constData());
+ const auto it = m_inFlightStreams.constFind(streamID);
+ if (it == m_inFlightStreams.cend()) {
+ sendRST_STREAM(streamID, RST_STREAM_INVALID_STREAM);
+ return;
+ }
+
+ flags &= 0x3f;
+ bool flag_fin = flags & 0x01;
+
+ QByteArray headerValuePairs = frameData.mid(4);
+
+ HttpMessagePair pair = it.value();
+ QHttpNetworkReply *httpReply = pair.second;
+ Q_ASSERT(httpReply != nullptr);
+
+ if (httpReply->d_func()->state == QHttpNetworkReplyPrivate::SPDYClosed) {
+ sendRST_STREAM(streamID, RST_STREAM_STREAM_ALREADY_CLOSED);
+ return;
+ }
+
+ QByteArray uncompressedHeader;
+ if (!uncompressHeader(headerValuePairs, &uncompressedHeader)) {
+ qWarning("error reading header from SYN_REPLY message");
+ return;
+ }
+
+ qint32 headerCount = fourBytesToInt(uncompressedHeader.constData());
+ if (headerCount * 8 > uncompressedHeader.size()) {
+ qWarning("error parsing header from SYN_REPLY message");
+ sendRST_STREAM(streamID, RST_STREAM_PROTOCOL_ERROR);
+ return;
+ }
+ qint32 readPointer = 4;
+ for (qint32 a = 0; a < headerCount; ++a) {
+ qint32 count = fourBytesToInt(uncompressedHeader.constData() + readPointer);
+ readPointer += 4;
+ QByteArray name = uncompressedHeader.mid(readPointer, count);
+ readPointer += count;
+ if (readPointer > uncompressedHeader.size()) {
+ qWarning("error parsing header from SYN_REPLY message");
+ sendRST_STREAM(streamID, RST_STREAM_PROTOCOL_ERROR);
+ return;
+ }
+ count = fourBytesToInt(uncompressedHeader.constData() + readPointer);
+ readPointer += 4;
+ QByteArray value = uncompressedHeader.mid(readPointer, count);
+ readPointer += count;
+ if (readPointer > uncompressedHeader.size()) {
+ qWarning("error parsing header from SYN_REPLY message");
+ sendRST_STREAM(streamID, RST_STREAM_PROTOCOL_ERROR);
+ return;
+ }
+ if (name == ":status") {
+ httpReply->setStatusCode(value.left(3).toInt());
+ httpReply->d_func()->reasonPhrase = QString::fromLatin1(value.mid(4));
+ } else if (name == ":version") {
+ int majorVersion = value.at(5) - 48;
+ int minorVersion = value.at(7) - 48;
+ httpReply->d_func()->majorVersion = majorVersion;
+ httpReply->d_func()->minorVersion = minorVersion;
+ } else if (name == "content-length") {
+ httpReply->setContentLength(value.toLongLong());
+ } else {
+ value.replace('\0', name == "set-cookie" ? "\n" : ", ");
+ httpReply->setHeaderField(name, value);
+ }
+ }
+ emit httpReply->headerChanged();
+
+ if (flag_fin) {
+ if (httpReply->d_func()->state != QHttpNetworkReplyPrivate::SPDYHalfClosed)
+ sendDataFrame(streamID, DataFrame_FLAG_FIN, 0, nullptr);
+ replyFinished(httpReply, streamID);
+ }
+}
+
+void QSpdyProtocolHandler::handleRST_STREAM(char /*flags*/, quint32 length,
+ const QByteArray &frameData)
+{
+ // flags are ignored
+
+ Q_ASSERT(length == 8);
+ Q_UNUSED(length); // silence -Wunused-parameter
+ qint32 streamID = getStreamID(frameData.constData());
+ QHttpNetworkReply *httpReply = m_inFlightStreams.value(streamID).second;
+
+ qint32 statusCodeInt = fourBytesToInt(frameData.constData() + 4);
+ RST_STREAM_STATUS_CODE statusCode = static_cast<RST_STREAM_STATUS_CODE>(statusCodeInt);
+ QNetworkReply::NetworkError errorCode;
+ QByteArray errorMessage;
+
+ switch (statusCode) {
+ case RST_STREAM_PROTOCOL_ERROR:
+ errorCode = QNetworkReply::ProtocolFailure;
+ errorMessage = "SPDY protocol error";
+ break;
+ case RST_STREAM_INVALID_STREAM:
+ errorCode = QNetworkReply::ProtocolFailure;
+ errorMessage = "SPDY stream is not active";
+ break;
+ case RST_STREAM_REFUSED_STREAM:
+ errorCode = QNetworkReply::ProtocolFailure;
+ errorMessage = "SPDY stream was refused";
+ break;
+ case RST_STREAM_UNSUPPORTED_VERSION:
+ errorCode = QNetworkReply::ProtocolUnknownError;
+ errorMessage = "SPDY version is unknown to the server";
+ break;
+ case RST_STREAM_CANCEL:
+ errorCode = QNetworkReply::ProtocolFailure;
+ errorMessage = "SPDY stream is no longer needed";
+ break;
+ case RST_STREAM_INTERNAL_ERROR:
+ errorCode = QNetworkReply::InternalServerError;
+ errorMessage = "Internal server error";
+ break;
+ case RST_STREAM_FLOW_CONTROL_ERROR:
+ errorCode = QNetworkReply::ProtocolFailure;
+ errorMessage = "peer violated the flow control protocol";
+ break;
+ case RST_STREAM_STREAM_IN_USE:
+ errorCode = QNetworkReply::ProtocolFailure;
+ errorMessage = "server received a SYN_REPLY for an already open stream";
+ break;
+ case RST_STREAM_STREAM_ALREADY_CLOSED:
+ errorCode = QNetworkReply::ProtocolFailure;
+ errorMessage = "server received data or a SYN_REPLY for an already half-closed stream";
+ break;
+ case RST_STREAM_INVALID_CREDENTIALS:
+ errorCode = QNetworkReply::ContentAccessDenied;
+ errorMessage = "server received invalid credentials";
+ break;
+ case RST_STREAM_FRAME_TOO_LARGE:
+ errorCode = QNetworkReply::ProtocolFailure;
+ errorMessage = "server cannot process the frame because it is too large";
+ break;
+ default:
+ qWarning("could not understand servers RST_STREAM status code");
+ errorCode = QNetworkReply::ProtocolFailure;
+ errorMessage = "got SPDY RST_STREAM message with unknown error code";
+ }
+ if (httpReply)
+ replyFinishedWithError(httpReply, streamID, errorCode, errorMessage.constData());
+}
+
+void QSpdyProtocolHandler::handleSETTINGS(char flags, quint32 /*length*/, const QByteArray &frameData)
+{
+ Q_ASSERT(frameData.count() > 0);
+
+ SETTINGS_Flags settingsFlags = static_cast<SETTINGS_Flags>(flags);
+ if (settingsFlags & FLAG_SETTINGS_CLEAR_SETTINGS) {
+ // ### clear all persistent settings; since we do not persist settings
+ // as of now, we don't need to clear anything either
+ }
+
+ qint32 numberOfEntries = fourBytesToInt(frameData.constData());
+ Q_ASSERT(numberOfEntries > 0);
+ for (int a = 0, frameDataIndex = 4; a < numberOfEntries; ++a, frameDataIndex += 8) {
+ SETTINGS_ID_Flag idFlag = static_cast<SETTINGS_ID_Flag>(frameData[frameDataIndex]);
+ if (idFlag & FLAG_SETTINGS_PERSIST_VALUE) {
+ // ### we SHOULD persist the settings here according to the RFC, but we don't have to,
+ // so implement that later
+ } // the other value is only sent by us, but not received
+
+ quint32 uniqueID = static_cast<SETTINGS_ID>(
+ threeBytesToInt(frameData.constData() + frameDataIndex + 1));
+ quint32 value = fourBytesToInt(frameData.constData() + frameDataIndex + 4);
+ switch (uniqueID) {
+ case SETTINGS_UPLOAD_BANDWIDTH: {
+ // ignored for now, just an estimated informative value
+ break;
+ }
+ case SETTINGS_DOWNLOAD_BANDWIDTH: {
+ // ignored for now, just an estimated informative value
+ break;
+ }
+ case SETTINGS_ROUND_TRIP_TIME: {
+ // ignored for now, just an estimated informative value
+ break;
+ }
+ case SETTINGS_MAX_CONCURRENT_STREAMS: {
+ m_maxConcurrentStreams = value;
+ break;
+ }
+ case SETTINGS_CURRENT_CWND: {
+ // ignored for now, just an informative value
+ break;
+ }
+ case SETTINGS_DOWNLOAD_RETRANS_RATE: {
+ // ignored for now, just an estimated informative value
+ break;
+ }
+ case SETTINGS_INITIAL_WINDOW_SIZE: {
+ m_initialWindowSize = value;
+ break;
+ }
+ case SETTINGS_CLIENT_CERTIFICATE_VECTOR_SIZE: {
+ // client certificates are not supported
+ break;
+ }
+ default:
+ qWarning("found unknown settings value %u", uint(value));
+ }
+ }
+}
+
+void QSpdyProtocolHandler::handlePING(char /*flags*/, quint32 length, const QByteArray &frameData)
+{
+ // flags are ignored
+
+ Q_ASSERT(length == 4);
+ Q_UNUSED(length); // silence -Wunused-parameter
+ quint32 pingID = fourBytesToInt(frameData.constData());
+
+ // odd numbered IDs must be ignored
+ if ((pingID & 1) == 0) // is even?
+ sendPING(pingID);
+}
+
+void QSpdyProtocolHandler::handleGOAWAY(char /*flags*/, quint32 /*length*/,
+ const QByteArray &frameData)
+{
+ // flags are ignored
+
+ qint32 statusCode = static_cast<GOAWAY_STATUS>(fourBytesToInt(frameData.constData() + 4));
+ QNetworkReply::NetworkError errorCode;
+ switch (statusCode) {
+ case GOAWAY_OK: {
+ errorCode = QNetworkReply::NoError;
+ break;
+ }
+ case GOAWAY_PROTOCOL_ERROR: {
+ errorCode = QNetworkReply::ProtocolFailure;
+ break;
+ }
+ case GOAWAY_INTERNAL_ERROR: {
+ errorCode = QNetworkReply::InternalServerError;
+ break;
+ }
+ default:
+ qWarning("unexpected status code %d", int(statusCode));
+ errorCode = QNetworkReply::ProtocolUnknownError;
+ }
+
+ qint32 lastGoodStreamID = getStreamID(frameData.constData());
+
+ // emit errors for all replies after the last good stream ID
+ Q_ASSERT(m_connection);
+ for (qint32 currentStreamID = lastGoodStreamID + 2; currentStreamID <= m_nextStreamID;
+ ++currentStreamID) {
+ QHttpNetworkReply *reply = m_inFlightStreams.value(currentStreamID).second;
+ Q_ASSERT(reply);
+ m_connection->d_func()->emitReplyError(m_socket, reply, errorCode);
+ }
+ // ### we could make sure a new session is initiated anyhow
+}
+
+void QSpdyProtocolHandler::handleHEADERS(char flags, quint32 /*length*/,
+ const QByteArray &frameData)
+{
+ parseHttpHeaders(flags, frameData);
+}
+
+void QSpdyProtocolHandler::handleWINDOW_UPDATE(char /*flags*/, quint32 /*length*/,
+ const QByteArray &frameData)
+{
+ qint32 streamID = getStreamID(frameData.constData());
+ qint32 deltaWindowSize = fourBytesToInt(frameData.constData() + 4);
+
+ const auto it = m_inFlightStreams.constFind(streamID);
+ if (it == m_inFlightStreams.cend()) {
+ sendRST_STREAM(streamID, RST_STREAM_INVALID_STREAM);
+ return;
+ }
+
+ QHttpNetworkReply *reply = it.value().second;
+ Q_ASSERT(reply);
+ QHttpNetworkReplyPrivate *replyPrivate = reply->d_func();
+ Q_ASSERT(replyPrivate);
+
+ // Ignore WINDOW_UPDATE if we are already done.
+ if (replyPrivate->state == QHttpNetworkReplyPrivate::SPDYHalfClosed || replyPrivate->state == QHttpNetworkReplyPrivate::SPDYClosed)
+ return;
+
+ replyPrivate->currentlyUploadedDataInWindow = replyPrivate->windowSizeUpload - deltaWindowSize;
+ uploadData(streamID); // we hopefully can continue to upload
+}
+
+
+void QSpdyProtocolHandler::handleDataFrame(const QByteArray &frameHeaders)
+{
+ Q_ASSERT(frameHeaders.count() >= 8);
+
+ qint32 streamID = getStreamID(frameHeaders.constData());
+ const auto it = m_inFlightStreams.constFind(streamID);
+ if (it == m_inFlightStreams.cend()) {
+ sendRST_STREAM(streamID, RST_STREAM_INVALID_STREAM);
+ return;
+ }
+
+ unsigned char flags = static_cast<unsigned char>(frameHeaders.at(4));
+ flags &= 0x3f;
+ bool flag_fin = flags & 0x01;
+ bool flag_compress = flags & 0x02;
+ qint32 length = threeBytesToInt(frameHeaders.constData() + 5);
+
+ QByteArray data;
+ data.resize(length);
+ if (!readNextChunk(length, data.data())) {
+ // put back the frame headers to the buffer
+ m_spdyBuffer.prepend(frameHeaders);
+ return; // we couldn't read the whole frame and need to wait
+ } else {
+ m_spdyBuffer.clear();
+ m_waitingForCompleteStream = false;
+ }
+
+ HttpMessagePair pair = it.value();
+ QHttpNetworkRequest httpRequest = pair.first;
+ QHttpNetworkReply *httpReply = pair.second;
+ Q_ASSERT(httpReply != nullptr);
+
+ QHttpNetworkReplyPrivate *replyPrivate = httpReply->d_func();
+
+ if (replyPrivate->state == QHttpNetworkReplyPrivate::SPDYClosed) {
+ sendRST_STREAM(streamID, RST_STREAM_STREAM_ALREADY_CLOSED);
+ return;
+ }
+
+ // check whether we need to send WINDOW_UPDATE (i.e. tell the sender it can send more)
+ replyPrivate->currentlyReceivedDataInWindow += length;
+ qint32 dataLeftInWindow = replyPrivate->windowSizeDownload - replyPrivate->currentlyReceivedDataInWindow;
+
+ if (replyPrivate->currentlyReceivedDataInWindow > 0
+ && dataLeftInWindow < replyPrivate->windowSizeDownload / 2) {
+
+ // socket read buffer size is 64K actually, hard coded in the channel
+ // We can read way more than 64K per socket, because the window size
+ // here is per stream.
+ if (replyPrivate->windowSizeDownload >= m_socket->readBufferSize()) {
+ replyPrivate->windowSizeDownload = m_socket->readBufferSize();
+ } else {
+ replyPrivate->windowSizeDownload *= 1.5;
+ }
+ QMetaObject::invokeMethod(this, "sendWINDOW_UPDATE", Qt::QueuedConnection,
+ Q_ARG(qint32, streamID),
+ Q_ARG(quint32, replyPrivate->windowSizeDownload));
+ // setting the current data count to 0 is a race condition,
+ // because we call sendWINDOW_UPDATE through the event loop.
+ // But then again, the whole situation is a race condition because
+ // we don't know when the packet will arrive at the server; so
+ // this is most likely good enough here.
+ replyPrivate->currentlyReceivedDataInWindow = 0;
+ }
+
+ httpReply->d_func()->compressedData.append(data);
+
+
+ replyPrivate->totalProgress += length;
+
+ if (httpRequest.d->autoDecompress && httpReply->d_func()->isCompressed()) {
+ QByteDataBuffer inDataBuffer; // ### should we introduce one in the http reply?
+ inDataBuffer.append(data);
+ qint64 compressedCount = httpReply->d_func()->uncompressBodyData(&inDataBuffer,
+ &replyPrivate->responseData);
+ Q_ASSERT(compressedCount >= 0);
+ Q_UNUSED(compressedCount); // silence -Wunused-variable
+ } else {
+ replyPrivate->responseData.append(data);
+ }
+
+ if (replyPrivate->shouldEmitSignals()) {
+ emit httpReply->readyRead();
+ emit httpReply->dataReadProgress(replyPrivate->totalProgress, replyPrivate->bodyLength);
+ }
+
+ if (flag_compress) {
+ qWarning("SPDY level compression is not supported");
+ }
+
+ if (flag_fin) {
+ if (httpReply->d_func()->state != QHttpNetworkReplyPrivate::SPDYHalfClosed)
+ sendDataFrame(streamID, DataFrame_FLAG_FIN, 0, nullptr);
+ replyFinished(httpReply, streamID);
+ }
+}
+
+void QSpdyProtocolHandler::replyFinished(QHttpNetworkReply *httpReply, qint32 streamID)
+{
+ httpReply->d_func()->state = QHttpNetworkReplyPrivate::SPDYClosed;
+ httpReply->disconnect(this);
+ if (httpReply->request().uploadByteDevice())
+ httpReply->request().uploadByteDevice()->disconnect(this);
+ int streamsRemoved = m_inFlightStreams.remove(streamID);
+ Q_ASSERT(streamsRemoved == 1);
+ Q_UNUSED(streamsRemoved); // silence -Wunused-variable
+ emit httpReply->finished();
+}
+
+void QSpdyProtocolHandler::replyFinishedWithError(QHttpNetworkReply *httpReply, qint32 streamID,
+ QNetworkReply::NetworkError errorCode, const char *errorMessage)
+{
+ Q_ASSERT(httpReply);
+ httpReply->d_func()->state = QHttpNetworkReplyPrivate::SPDYClosed;
+ httpReply->disconnect(this);
+ if (httpReply->request().uploadByteDevice())
+ httpReply->request().uploadByteDevice()->disconnect(this);
+ int streamsRemoved = m_inFlightStreams.remove(streamID);
+ Q_ASSERT(streamsRemoved == 1);
+ Q_UNUSED(streamsRemoved); // silence -Wunused-variable
+ emit httpReply->finishedWithError(errorCode, QSpdyProtocolHandler::tr(errorMessage));
+}
+
+qint32 QSpdyProtocolHandler::generateNextStreamID()
+{
+ // stream IDs initiated by the client must be odd
+ m_nextStreamID += 2;
+ return m_nextStreamID;
+}
+
+QT_END_NAMESPACE
+
+#endif // !defined(QT_NO_SSL)
diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp
index cd87c3669c..751735c8bd 100644
--- a/src/network/bearer/qnetworkconfigmanager.cpp
+++ b/src/network/bearer/qnetworkconfigmanager.cpp
@@ -68,7 +68,7 @@ static void connManager_cleanup()
int shutdown = appShutdown.fetchAndStoreAcquire(1);
Q_ASSERT(shutdown == 0);
Q_UNUSED(shutdown);
- QNetworkConfigurationManagerPrivate *cmp = connManager_ptr.fetchAndStoreAcquire(0);
+ QNetworkConfigurationManagerPrivate *cmp = connManager_ptr.fetchAndStoreAcquire(nullptr);
if (cmp)
cmp->cleanup();
}
@@ -355,7 +355,7 @@ QNetworkConfigurationManager::Capabilities QNetworkConfigurationManager::capabil
if (priv)
return priv->capabilities();
- return QNetworkConfigurationManager::Capabilities(0);
+ return {};
}
/*!
diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp
index b432444669..f0aa452dd3 100644
--- a/src/network/bearer/qnetworkconfigmanager_p.cpp
+++ b/src/network/bearer/qnetworkconfigmanager_p.cpp
@@ -59,7 +59,7 @@
QT_BEGIN_NAMESPACE
QNetworkConfigurationManagerPrivate::QNetworkConfigurationManagerPrivate()
- : QObject(), pollTimer(0),
+ : QObject(), pollTimer(nullptr),
loader(QBearerEngineFactoryInterface_iid, QLatin1String("/bearer")),
forcedPolling(0), firstUpdate(true)
{
@@ -93,7 +93,7 @@ void QNetworkConfigurationManagerPrivate::cleanup()
{
QThread* thread = bearerThread;
deleteLater();
- if (thread->wait(5000))
+ if (thread->wait(QDeadlineTimer(5000)))
delete thread;
}
@@ -367,7 +367,7 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations()
bool envOK = false;
const int skipGeneric = qEnvironmentVariableIntValue("QT_EXCLUDE_GENERIC_BEARER", &envOK);
- QBearerEngine *generic = 0;
+ QBearerEngine *generic = nullptr;
QFactoryLoader *l = &loader;
const PluginKeyMap keyMap = l->keyMap();
const PluginKeyMapConstIterator cend = keyMap.constEnd();
diff --git a/src/network/bearer/qnetworkconfiguration.cpp b/src/network/bearer/qnetworkconfiguration.cpp
index 19bc44e02a..25c4ab711e 100644
--- a/src/network/bearer/qnetworkconfiguration.cpp
+++ b/src/network/bearer/qnetworkconfiguration.cpp
@@ -209,7 +209,7 @@ QT_BEGIN_NAMESPACE
\sa isValid()
*/
QNetworkConfiguration::QNetworkConfiguration()
- : d(0)
+ : d(nullptr)
{
}
diff --git a/src/network/bearer/qnetworksession.cpp b/src/network/bearer/qnetworksession.cpp
index 1636bcee97..324016d72a 100644
--- a/src/network/bearer/qnetworksession.cpp
+++ b/src/network/bearer/qnetworksession.cpp
@@ -250,7 +250,7 @@ QT_BEGIN_NAMESPACE
\sa QNetworkConfiguration
*/
QNetworkSession::QNetworkSession(const QNetworkConfiguration &connectionConfig, QObject *parent)
- : QObject(parent), d(0)
+ : QObject(parent), d(nullptr)
{
qRegisterMetaType<QNetworkSession::State>();
qRegisterMetaType<QNetworkSession::SessionError>();
diff --git a/src/network/bearer/qnetworksession_impl.cpp b/src/network/bearer/qnetworksession_impl.cpp
index 4b8631d4db..45a00b45fd 100644
--- a/src/network/bearer/qnetworksession_impl.cpp
+++ b/src/network/bearer/qnetworksession_impl.cpp
@@ -67,7 +67,7 @@ static QBearerEngineImpl *getEngineFromId(const QString &id)
}
}
- return 0;
+ return nullptr;
}
class QNetworkSessionManagerPrivate : public QObject
@@ -75,7 +75,7 @@ class QNetworkSessionManagerPrivate : public QObject
Q_OBJECT
public:
- QNetworkSessionManagerPrivate(QObject *parent = 0) : QObject(parent) {}
+ QNetworkSessionManagerPrivate(QObject *parent = nullptr) : QObject(parent) {}
~QNetworkSessionManagerPrivate() {}
inline void forceSessionClose(const QNetworkConfiguration &config)
@@ -121,7 +121,7 @@ void QNetworkSessionPrivateImpl::syncStateWithInterface()
// Defer setting serviceConfig and activeConfig until open().
Q_FALLTHROUGH();
default:
- engine = 0;
+ engine = nullptr;
}
networkConfigurationsChanged();
diff --git a/src/network/configure.json b/src/network/configure.json
index 1fc09f67d6..1f1e6fafbf 100644
--- a/src/network/configure.json
+++ b/src/network/configure.json
@@ -94,6 +94,10 @@
"condition": "config.msvc"
},
{
+ "libs": "-lssl_arm64-v8a -lcrypto_arm64-v8a",
+ "condition": "config.android"
+ },
+ {
"libs": "-lssl -lcrypto",
"condition": "!config.msvc"
}
@@ -432,8 +436,12 @@
"report": [
{
"type": "note",
- "condition": "features.openssl-linked && libs.openssl.source != 0 && input.openssl.prefix == '' && input.openssl.libs == '' && input.openssl.libs.debug == ''",
- "message": "When linking against OpenSSL, you can override the default library names through OPENSSL_LIBS. For example: OPENSSL_LIBS='-L/opt/ssl/lib -lssl -lcrypto' ./configure -openssl-linked"
+ "condition": "!config.android && features.openssl-linked && libs.openssl.source != 0
+ && input.openssl.prefix == '' && input.openssl.libs == '' && input.openssl.libs.debug == ''",
+ "message": "When linking against OpenSSL, you can override the default
+library names through OPENSSL_LIBS.
+For example:
+ OPENSSL_LIBS='-L/opt/ssl/lib -lssl -lcrypto' ./configure -openssl-linked"
},
{
"type": "warning",
diff --git a/src/network/doc/snippets/code/src_network_socket_qabstractsocket.cpp b/src/network/doc/snippets/code/src_network_socket_qabstractsocket.cpp
index 3db16b50e6..e19cb40666 100644
--- a/src/network/doc/snippets/code/src_network_socket_qabstractsocket.cpp
+++ b/src/network/doc/snippets/code/src_network_socket_qabstractsocket.cpp
@@ -57,9 +57,10 @@ if (socket->waitForConnected(1000))
//! [1]
socket->disconnectFromHost();
- if (socket->state() == QAbstractSocket::UnconnectedState ||
- socket->waitForDisconnected(1000))
+if (socket->state() == QAbstractSocket::UnconnectedState
+ || socket->waitForDisconnected(1000)) {
qDebug("Disconnected!");
+}
//! [1]
diff --git a/src/network/doc/snippets/code/src_network_socket_qlocalsocket_unix.cpp b/src/network/doc/snippets/code/src_network_socket_qlocalsocket_unix.cpp
index 181f9c1686..deafca831d 100644
--- a/src/network/doc/snippets/code/src_network_socket_qlocalsocket_unix.cpp
+++ b/src/network/doc/snippets/code/src_network_socket_qlocalsocket_unix.cpp
@@ -57,6 +57,8 @@ if (socket->waitForConnected(1000))
//! [1]
socket->disconnectFromServer();
-if (socket->waitForDisconnected(1000))
+if (socket->state() == QLocalSocket::UnconnectedState
+ || socket->waitForDisconnected(1000)) {
qDebug("Disconnected!");
+}
//! [1]
diff --git a/src/network/kernel/qauthenticator.cpp b/src/network/kernel/qauthenticator.cpp
index 33a30eb1cd..e9a8e2a9e5 100644
--- a/src/network/kernel/qauthenticator.cpp
+++ b/src/network/kernel/qauthenticator.cpp
@@ -158,7 +158,7 @@ static QByteArray qGssapiContinue(QAuthenticatorPrivate *ctx,
Constructs an empty authentication object.
*/
QAuthenticator::QAuthenticator()
- : d(0)
+ : d(nullptr)
{
}
@@ -175,7 +175,7 @@ QAuthenticator::~QAuthenticator()
Constructs a copy of \a other.
*/
QAuthenticator::QAuthenticator(const QAuthenticator &other)
- : d(0)
+ : d(nullptr)
{
if (other.d)
*this = other;
@@ -1227,7 +1227,7 @@ QByteArray qEncodeHmacMd5(QByteArray &key, const QByteArray &message)
static QByteArray qCreatev2Hash(const QAuthenticatorPrivate *ctx,
QNtlmPhase3Block *phase3)
{
- Q_ASSERT(phase3 != 0);
+ Q_ASSERT(phase3 != nullptr);
// since v2 Hash is need for both NTLMv2 and LMv2 it is calculated
// only once and stored and reused
if(phase3->v2Hash.size() == 0) {
@@ -1284,7 +1284,7 @@ static QByteArray qEncodeNtlmv2Response(const QAuthenticatorPrivate *ctx,
const QNtlmPhase2Block& ch,
QNtlmPhase3Block *phase3)
{
- Q_ASSERT(phase3 != 0);
+ Q_ASSERT(phase3 != nullptr);
// return value stored in phase3
qCreatev2Hash(ctx, phase3);
@@ -1351,7 +1351,7 @@ static QByteArray qEncodeLmv2Response(const QAuthenticatorPrivate *ctx,
const QNtlmPhase2Block& ch,
QNtlmPhase3Block *phase3)
{
- Q_ASSERT(phase3 != 0);
+ Q_ASSERT(phase3 != nullptr);
// return value stored in phase3
qCreatev2Hash(ctx, phase3);
diff --git a/src/network/kernel/qdnslookup.cpp b/src/network/kernel/qdnslookup.cpp
index 1b66829070..ab1be02b6b 100644
--- a/src/network/kernel/qdnslookup.cpp
+++ b/src/network/kernel/qdnslookup.cpp
@@ -481,7 +481,7 @@ void QDnsLookup::abort()
{
Q_D(QDnsLookup);
if (d->runnable) {
- d->runnable = 0;
+ d->runnable = nullptr;
d->reply = QDnsLookupReply();
d->reply.error = QDnsLookup::OperationCancelledError;
d->reply.errorString = tr("Operation cancelled");
@@ -992,7 +992,7 @@ void QDnsLookupPrivate::_q_lookupFinished(const QDnsLookupReply &_reply)
qDebug("DNS reply for %s: %i (%s)", qPrintable(name), _reply.error, qPrintable(_reply.errorString));
#endif
reply = _reply;
- runnable = 0;
+ runnable = nullptr;
isFinished = true;
emit q->finished();
}
diff --git a/src/network/kernel/qdnslookup_unix.cpp b/src/network/kernel/qdnslookup_unix.cpp
index ee7484ab35..12b40fc35d 100644
--- a/src/network/kernel/qdnslookup_unix.cpp
+++ b/src/network/kernel/qdnslookup_unix.cpp
@@ -73,13 +73,13 @@ QT_BEGIN_NAMESPACE
typedef struct __res_state* res_state;
#endif
typedef int (*dn_expand_proto)(const unsigned char *, const unsigned char *, const unsigned char *, char *, int);
-static dn_expand_proto local_dn_expand = 0;
+static dn_expand_proto local_dn_expand = nullptr;
typedef void (*res_nclose_proto)(res_state);
-static res_nclose_proto local_res_nclose = 0;
+static res_nclose_proto local_res_nclose = nullptr;
typedef int (*res_ninit_proto)(res_state);
-static res_ninit_proto local_res_ninit = 0;
+static res_ninit_proto local_res_ninit = nullptr;
typedef int (*res_nquery_proto)(res_state, const char *, int, int, unsigned char *, int);
-static res_nquery_proto local_res_nquery = 0;
+static res_nquery_proto local_res_nquery = nullptr;
// Custom deleter to close resolver state.
diff --git a/src/network/kernel/qhostaddress.cpp b/src/network/kernel/qhostaddress.cpp
index b54fb349fb..ed1c23ed6e 100644
--- a/src/network/kernel/qhostaddress.cpp
+++ b/src/network/kernel/qhostaddress.cpp
@@ -144,7 +144,7 @@ static bool parseIp6(const QString &address, QIPAddressUtils::IPv6Address &addr,
} else {
scopeId->clear();
}
- return QIPAddressUtils::parseIp6(addr, tmp.constBegin(), tmp.constEnd()) == 0;
+ return QIPAddressUtils::parseIp6(addr, tmp.constBegin(), tmp.constEnd()) == nullptr;
}
bool QHostAddressPrivate::parse(const QString &ipString)
diff --git a/src/network/kernel/qhostinfo.cpp b/src/network/kernel/qhostinfo.cpp
index f9335c3bb9..93be053ef3 100644
--- a/src/network/kernel/qhostinfo.cpp
+++ b/src/network/kernel/qhostinfo.cpp
@@ -383,34 +383,13 @@ QHostInfo QHostInfo::fromName(const QString &name)
return hostInfo;
}
-#ifndef QT_NO_BEARERMANAGEMENT
-QHostInfo QHostInfoPrivate::fromName(const QString &name, QSharedPointer<QNetworkSession> session)
-{
-#if defined QHOSTINFO_DEBUG
- qDebug("QHostInfoPrivate::fromName(\"%s\") with session %p",name.toLatin1().constData(), session.data());
-#endif
-
- QHostInfo hostInfo = QHostInfoAgent::fromName(name, session);
- QHostInfoLookupManager* manager = theHostInfoLookupManager();
- manager->cache.put(name, hostInfo);
- return hostInfo;
-}
-#endif
-
-#ifndef QT_NO_BEARERMANAGEMENT
-QHostInfo QHostInfoAgent::fromName(const QString &hostName, QSharedPointer<QNetworkSession>)
-{
- return QHostInfoAgent::fromName(hostName);
-}
-#endif
-
QHostInfo QHostInfoAgent::reverseLookup(const QHostAddress &address)
{
QHostInfo results;
// Reverse lookup
sockaddr_in sa4;
sockaddr_in6 sa6;
- sockaddr *sa = 0;
+ sockaddr *sa = nullptr;
QT_SOCKLEN_T saSize;
if (address.protocol() == QAbstractSocket::IPv4Protocol) {
sa = reinterpret_cast<sockaddr *>(&sa4);
@@ -455,7 +434,7 @@ QHostInfo QHostInfoAgent::lookup(const QString &hostName)
return results;
}
- addrinfo *res = 0;
+ addrinfo *res = nullptr;
struct addrinfo hints;
memset(&hints, 0, sizeof(hints));
hints.ai_family = PF_UNSPEC;
@@ -595,7 +574,7 @@ QHostInfo::QHostInfo(const QHostInfo &other)
}
/*!
- \fn QHostInfo(QHostInfo &&other)
+ \fn QHostInfo::QHostInfo(QHostInfo &&other)
Move-constructs a new QHostInfo from \a other.
diff --git a/src/network/kernel/qhostinfo_p.h b/src/network/kernel/qhostinfo_p.h
index 1798ceab0a..d7875a0673 100644
--- a/src/network/kernel/qhostinfo_p.h
+++ b/src/network/kernel/qhostinfo_p.h
@@ -119,9 +119,6 @@ class QHostInfoAgent
{
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);
@@ -136,10 +133,6 @@ public:
lookupId(0)
{
}
-#ifndef QT_NO_BEARERMANAGEMENT
- //not a public API yet
- static QHostInfo fromName(const QString &hostName, QSharedPointer<QNetworkSession> networkSession);
-#endif
static int lookupHostImpl(const QString &name,
const QObject *receiver,
QtPrivate::QSlotObjectBase *slotObj,
diff --git a/src/network/kernel/qhostinfo_unix.cpp b/src/network/kernel/qhostinfo_unix.cpp
index 78a05f8407..625fbabf31 100644
--- a/src/network/kernel/qhostinfo_unix.cpp
+++ b/src/network/kernel/qhostinfo_unix.cpp
@@ -80,12 +80,12 @@ enum LibResolvFeature {
typedef struct __res_state *res_state_ptr;
typedef int (*res_init_proto)(void);
-static res_init_proto local_res_init = 0;
+static res_init_proto local_res_init = nullptr;
typedef int (*res_ninit_proto)(res_state_ptr);
-static res_ninit_proto local_res_ninit = 0;
+static res_ninit_proto local_res_ninit = nullptr;
typedef void (*res_nclose_proto)(res_state_ptr);
-static res_nclose_proto local_res_nclose = 0;
-static res_state_ptr local_res = 0;
+static res_nclose_proto local_res_nclose = nullptr;
+static res_state_ptr local_res = nullptr;
#if QT_CONFIG(library) && !defined(Q_OS_QNX)
namespace {
diff --git a/src/network/kernel/qnetworkinterface.cpp b/src/network/kernel/qnetworkinterface.cpp
index d43dba3e0c..eed57f8a32 100644
--- a/src/network/kernel/qnetworkinterface.cpp
+++ b/src/network/kernel/qnetworkinterface.cpp
@@ -627,7 +627,7 @@ bool QNetworkAddressEntry::isPermanent() const
Constructs an empty network interface object.
*/
QNetworkInterface::QNetworkInterface()
- : d(0)
+ : d(nullptr)
{
}
@@ -746,7 +746,7 @@ QString QNetworkInterface::humanReadableName() const
*/
QNetworkInterface::InterfaceFlags QNetworkInterface::flags() const
{
- return d ? d->flags : InterfaceFlags(0);
+ return d ? d->flags : InterfaceFlags{};
}
/*!
diff --git a/src/network/kernel/qnetworkinterface_p.h b/src/network/kernel/qnetworkinterface_p.h
index 44e27a7e34..b879a397f2 100644
--- a/src/network/kernel/qnetworkinterface_p.h
+++ b/src/network/kernel/qnetworkinterface_p.h
@@ -82,7 +82,7 @@ public:
class QNetworkInterfacePrivate: public QSharedData
{
public:
- QNetworkInterfacePrivate() : index(0), flags(nullptr)
+ QNetworkInterfacePrivate() : index(0)
{ }
~QNetworkInterfacePrivate()
{ }
diff --git a/src/network/kernel/qnetworkinterface_unix_p.h b/src/network/kernel/qnetworkinterface_unix_p.h
index 553af5a303..e5c8909eca 100644
--- a/src/network/kernel/qnetworkinterface_unix_p.h
+++ b/src/network/kernel/qnetworkinterface_unix_p.h
@@ -80,7 +80,7 @@ QT_BEGIN_NAMESPACE
static QNetworkInterface::InterfaceFlags convertFlags(uint rawFlags)
{
- QNetworkInterface::InterfaceFlags flags = nullptr;
+ QNetworkInterface::InterfaceFlags flags;
flags |= (rawFlags & IFF_UP) ? QNetworkInterface::IsUp : QNetworkInterface::InterfaceFlag(0);
flags |= (rawFlags & IFF_RUNNING) ? QNetworkInterface::IsRunning : QNetworkInterface::InterfaceFlag(0);
flags |= (rawFlags & IFF_BROADCAST) ? QNetworkInterface::CanBroadcast : QNetworkInterface::InterfaceFlag(0);
diff --git a/src/network/kernel/qnetworkproxy.cpp b/src/network/kernel/qnetworkproxy.cpp
index a2a89ed94b..90c8b75a86 100644
--- a/src/network/kernel/qnetworkproxy.cpp
+++ b/src/network/kernel/qnetworkproxy.cpp
@@ -254,13 +254,13 @@ class QGlobalNetworkProxy
{
public:
QGlobalNetworkProxy()
- : applicationLevelProxy(0)
- , applicationLevelProxyFactory(0)
+ : applicationLevelProxy(nullptr)
+ , applicationLevelProxyFactory(nullptr)
#if QT_CONFIG(socks5)
- , socks5SocketEngineHandler(0)
+ , socks5SocketEngineHandler(nullptr)
#endif
#if QT_CONFIG(http)
- , httpSocketEngineHandler(0)
+ , httpSocketEngineHandler(nullptr)
#endif
#ifdef QT_USE_SYSTEM_PROXIES
, useSystemProxies(true)
@@ -313,7 +313,7 @@ public:
applicationLevelProxy = new QNetworkProxy;
*applicationLevelProxy = proxy;
delete applicationLevelProxyFactory;
- applicationLevelProxyFactory = 0;
+ applicationLevelProxyFactory = nullptr;
useSystemProxies = false;
}
@@ -501,7 +501,7 @@ template<> void QSharedDataPointer<QNetworkProxyPrivate>::detach()
\sa setType(), setApplicationProxy()
*/
QNetworkProxy::QNetworkProxy()
- : d(0)
+ : d(nullptr)
{
// make sure we have QGlobalNetworkProxy singleton created, otherwise
// you don't have any socket engine handler created when directly setting
diff --git a/src/network/kernel/qurlinfo.cpp b/src/network/kernel/qurlinfo.cpp
index 7ae6822fb4..e6f2e70ff4 100644
--- a/src/network/kernel/qurlinfo.cpp
+++ b/src/network/kernel/qurlinfo.cpp
@@ -126,7 +126,7 @@ public:
QUrlInfo::QUrlInfo()
{
- d = 0;
+ d = nullptr;
}
/*!
@@ -139,7 +139,7 @@ QUrlInfo::QUrlInfo(const QUrlInfo &ui)
d = new QUrlInfoPrivate;
*d = *ui.d;
} else {
- d = 0;
+ d = nullptr;
}
}
@@ -443,7 +443,7 @@ QUrlInfo &QUrlInfo::operator=(const QUrlInfo &ui)
*d = *ui.d;
} else {
delete d;
- d = 0;
+ d = nullptr;
}
return *this;
}
@@ -683,7 +683,7 @@ bool QUrlInfo::equal(const QUrlInfo &i1, const QUrlInfo &i2,
bool QUrlInfo::operator==(const QUrlInfo &other) const
{
if (!d)
- return other.d == 0;
+ return other.d == nullptr;
if (!other.d)
return false;
@@ -721,7 +721,7 @@ bool QUrlInfo::operator==(const QUrlInfo &other) const
*/
bool QUrlInfo::isValid() const
{
- return d != 0;
+ return d != nullptr;
}
QT_END_NAMESPACE
diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp
index 9c8f29e18a..b8957ce818 100644
--- a/src/network/socket/qabstractsocket.cpp
+++ b/src/network/socket/qabstractsocket.cpp
@@ -215,7 +215,7 @@
connections, you will have to register it with Q_DECLARE_METATYPE() and
qRegisterMetaType().
- \sa error(), errorString(), {Creating Custom Qt Types}
+ \sa socketError(), errorString(), {Creating Custom Qt Types}
*/
/*!
@@ -329,7 +329,7 @@
is non-blocking).
\value UnknownSocketError An unidentified error occurred.
- \sa QAbstractSocket::error()
+ \sa QAbstractSocket::socketError()
*/
/*!
@@ -564,12 +564,12 @@ QAbstractSocketPrivate::QAbstractSocketPrivate()
port(0),
localPort(0),
peerPort(0),
- socketEngine(0),
+ socketEngine(nullptr),
cachedSocketDescriptor(-1),
readBufferMaxSize(0),
isBuffered(false),
hasPendingData(false),
- connectTimer(0),
+ connectTimer(nullptr),
hostLookupId(-1),
socketType(QAbstractSocket::UnknownSocketType),
state(QAbstractSocket::UnconnectedState),
@@ -603,7 +603,7 @@ void QAbstractSocketPrivate::resetSocketLayer()
socketEngine->close();
socketEngine->disconnect();
delete socketEngine;
- socketEngine = 0;
+ socketEngine = nullptr;
cachedSocketDescriptor = -1;
}
if (connectTimer)
@@ -659,7 +659,7 @@ bool QAbstractSocketPrivate::initSocketLayer(QAbstractSocket::NetworkLayerProtoc
configureCreatedSocket();
- if (threadData->hasEventDispatcher())
+ if (threadData.loadRelaxed()->hasEventDispatcher())
socketEngine->setReceiver(this);
#if defined (QABSTRACTSOCKET_DEBUG)
@@ -1138,7 +1138,7 @@ void QAbstractSocketPrivate::_q_connectToNextAddress()
}
// Start the connect timer.
- if (threadData->hasEventDispatcher()) {
+ if (threadData.loadRelaxed()->hasEventDispatcher()) {
if (!connectTimer) {
connectTimer = new QTimer(q);
QObject::connect(connectTimer, SIGNAL(timeout()),
@@ -1740,7 +1740,7 @@ void QAbstractSocket::connectToHost(const QString &hostName, quint16 port,
return;
#endif
} else {
- if (d->threadData->hasEventDispatcher()) {
+ if (d->threadData.loadRelaxed()->hasEventDispatcher()) {
// this internal API for QHostInfo either immediately gives us the desired
// QHostInfo from cache or later calls the _q_startConnecting slot.
bool immediateResultValid = false;
@@ -1953,7 +1953,7 @@ bool QAbstractSocket::setSocketDescriptor(qintptr socketDescriptor, SocketState
// Sync up with error string, which open() shall clear.
d->socketError = UnknownSocketError;
- if (d->threadData->hasEventDispatcher())
+ if (d->threadData.loadRelaxed()->hasEventDispatcher())
d->socketEngine->setReceiver(d);
QIODevice::open(openMode);
@@ -2094,7 +2094,7 @@ QVariant QAbstractSocket::socketOption(QAbstractSocket::SocketOption option)
Waits until the socket is connected, up to \a msecs
milliseconds. If the connection has been established, this
function returns \c true; otherwise it returns \c false. In the case
- where it returns \c false, you can call error() to determine
+ where it returns \c false, you can call socketError() to determine
the cause of the error.
The following example waits up to one second for a connection
@@ -2144,20 +2144,13 @@ bool QAbstractSocket::waitForConnected(int msecs)
#endif
QHostInfo::abortHostLookup(d->hostLookupId);
d->hostLookupId = -1;
-#ifndef QT_NO_BEARERMANAGEMENT
- if (networkSession) {
- d->_q_startConnecting(QHostInfoPrivate::fromName(d->hostName, networkSession));
- } else
-#endif
- {
- QHostAddress temp;
- if (temp.setAddress(d->hostName)) {
- QHostInfo info;
- info.setAddresses(QList<QHostAddress>() << temp);
- d->_q_startConnecting(info);
- } else {
- d->_q_startConnecting(QHostInfo::fromName(d->hostName));
- }
+ QHostAddress temp;
+ if (temp.setAddress(d->hostName)) {
+ QHostInfo info;
+ info.setAddresses(QList<QHostAddress>() << temp);
+ d->_q_startConnecting(info);
+ } else {
+ d->_q_startConnecting(QHostInfo::fromName(d->hostName));
}
}
if (state() == UnconnectedState)
@@ -2359,11 +2352,12 @@ bool QAbstractSocket::waitForBytesWritten(int msecs)
}
/*!
- Waits until the socket has disconnected, up to \a msecs
- milliseconds. If the connection has been disconnected, this
- function returns \c true; otherwise it returns \c false. In the case
- where it returns \c false, you can call error() to determine
- the cause of the error.
+ Waits until the socket has disconnected, up to \a msecs milliseconds. If the
+ connection was successfully disconnected, this function returns \c true;
+ otherwise it returns \c false (if the operation timed out, if an error
+ occurred, or if this QAbstractSocket is already disconnected). In the case
+ where it returns \c false, you can call error() to determine the cause of
+ the error.
The following example waits up to one second for a connection
to be closed:
@@ -2872,7 +2866,7 @@ void QAbstractSocket::setReadBufferSize(qint64 size)
/*!
Returns the state of the socket.
- \sa error()
+ \sa socketError()
*/
QAbstractSocket::SocketState QAbstractSocket::state() const
{
@@ -2899,16 +2893,35 @@ QAbstractSocket::SocketType QAbstractSocket::socketType() const
return d_func()->socketType;
}
+#if QT_DEPRECATED_SINCE(5, 15)
/*!
+ \deprecated
+
+ Use socketError() instead.
+
Returns the type of error that last occurred.
- \sa state(), errorString()
+ \sa state(), errorString(), socketError()
*/
QAbstractSocket::SocketError QAbstractSocket::error() const
{
+ return socketError();
+}
+#endif // QT_DEPRECATED_SINCE(5, 15)
+
+/*!
+ \since 5.15
+
+ Returns the type of error that last occurred.
+
+ \sa state(), errorString()
+*/
+QAbstractSocket::SocketError QAbstractSocket::socketError() const
+{
return d_func()->socketError;
}
+
/*!
Sets the type of error that last occurred to \a socketError.
diff --git a/src/network/socket/qabstractsocket.h b/src/network/socket/qabstractsocket.h
index de09195eeb..cbc79ea684 100644
--- a/src/network/socket/qabstractsocket.h
+++ b/src/network/socket/qabstractsocket.h
@@ -180,7 +180,12 @@ public:
SocketType socketType() const;
SocketState state() const;
- SocketError error() const;
+
+#if QT_DEPRECATED_SINCE(5, 15)
+ QT_DEPRECATED_X("Use socketError()") SocketError error() const;
+#endif // QT_DEPRECATED_SINCE(5, 15)
+
+ SocketError socketError() const;
// from QIODevice
void close() override;
diff --git a/src/network/socket/qabstractsocketengine.cpp b/src/network/socket/qabstractsocketengine.cpp
index db3a8280bd..44139ff81d 100644
--- a/src/network/socket/qabstractsocketengine.cpp
+++ b/src/network/socket/qabstractsocketengine.cpp
@@ -85,7 +85,7 @@ QAbstractSocketEnginePrivate::QAbstractSocketEnginePrivate()
, peerPort(0)
, inboundStreamCount(0)
, outboundStreamCount(0)
- , receiver(0)
+ , receiver(nullptr)
{
}
@@ -104,7 +104,7 @@ QAbstractSocketEngine *QAbstractSocketEngine::createSocketEngine(QAbstractSocket
#ifndef QT_NO_NETWORKPROXY
// proxy type must have been resolved by now
if (proxy.type() == QNetworkProxy::DefaultProxy)
- return 0;
+ return nullptr;
#endif
QMutexLocker locker(&socketHandlers()->mutex);
@@ -116,7 +116,7 @@ QAbstractSocketEngine *QAbstractSocketEngine::createSocketEngine(QAbstractSocket
#ifndef QT_NO_NETWORKPROXY
// only NoProxy can have reached here
if (proxy.type() != QNetworkProxy::NoProxy)
- return 0;
+ return nullptr;
#endif
return new QNativeSocketEngine(parent);
diff --git a/src/network/socket/qhttpsocketengine.cpp b/src/network/socket/qhttpsocketengine.cpp
index 2244955c55..98f850ba1b 100644
--- a/src/network/socket/qhttpsocketengine.cpp
+++ b/src/network/socket/qhttpsocketengine.cpp
@@ -216,7 +216,7 @@ void QHttpSocketEngine::close()
if (d->socket) {
d->socket->close();
delete d->socket;
- d->socket = 0;
+ d->socket = nullptr;
}
}
@@ -370,8 +370,8 @@ bool QHttpSocketEngine::waitForRead(int msecs, bool *timedOut)
if (!d->socket->waitForReadyRead(qt_subtract_from_timeout(msecs, stopWatch.elapsed()))) {
if (d->socket->state() == QAbstractSocket::UnconnectedState)
return true;
- setError(d->socket->error(), d->socket->errorString());
- if (timedOut && d->socket->error() == QAbstractSocket::SocketTimeoutError)
+ setError(d->socket->socketError(), d->socket->errorString());
+ if (timedOut && d->socket->socketError() == QAbstractSocket::SocketTimeoutError)
*timedOut = true;
return false;
}
@@ -385,8 +385,8 @@ bool QHttpSocketEngine::waitForRead(int msecs, bool *timedOut)
// Report any error that may occur.
if (d->state != Connected) {
- setError(d->socket->error(), d->socket->errorString());
- if (timedOut && d->socket->error() == QAbstractSocket::SocketTimeoutError)
+ setError(d->socket->socketError(), d->socket->errorString());
+ if (timedOut && d->socket->socketError() == QAbstractSocket::SocketTimeoutError)
*timedOut = true;
return false;
}
@@ -401,7 +401,7 @@ bool QHttpSocketEngine::waitForWrite(int msecs, bool *timedOut)
if (d->state == Connected) {
if (d->socket->bytesToWrite()) {
if (!d->socket->waitForBytesWritten(msecs)) {
- if (d->socket->error() == QAbstractSocket::SocketTimeoutError && timedOut)
+ if (d->socket->socketError() == QAbstractSocket::SocketTimeoutError && timedOut)
*timedOut = true;
return false;
}
@@ -421,8 +421,7 @@ bool QHttpSocketEngine::waitForWrite(int msecs, bool *timedOut)
// Report any error that may occur.
if (d->state != Connected) {
-// setError(d->socket->error(), d->socket->errorString());
- if (timedOut && d->socket->error() == QAbstractSocket::SocketTimeoutError)
+ if (timedOut && d->socket->socketError() == QAbstractSocket::SocketTimeoutError)
*timedOut = true;
}
@@ -586,7 +585,7 @@ void QHttpSocketEngine::slotSocketReadNotification()
}
int statusCode = d->reply->statusCode();
- QAuthenticatorPrivate *priv = 0;
+ QAuthenticatorPrivate *priv = nullptr;
if (statusCode == 200) {
d->state = Connected;
setLocalAddress(d->socket->localAddress());
@@ -829,8 +828,8 @@ QHttpSocketEnginePrivate::QHttpSocketEnginePrivate()
, credentialsSent(false)
, pendingResponseData(0)
{
- socket = 0;
- reply = 0;
+ socket = nullptr;
+ reply = nullptr;
state = QHttpSocketEngine::None;
}
@@ -843,15 +842,15 @@ QAbstractSocketEngine *QHttpSocketEngineHandler::createSocketEngine(QAbstractSoc
QObject *parent)
{
if (socketType != QAbstractSocket::TcpSocket)
- return 0;
+ return nullptr;
// proxy type must have been resolved by now
if (proxy.type() != QNetworkProxy::HttpProxy)
- return 0;
+ return nullptr;
// we only accept active sockets
if (!qobject_cast<QAbstractSocket *>(parent))
- return 0;
+ return nullptr;
QHttpSocketEngine *engine = new QHttpSocketEngine(parent);
engine->setProxy(proxy);
@@ -860,7 +859,7 @@ QAbstractSocketEngine *QHttpSocketEngineHandler::createSocketEngine(QAbstractSoc
QAbstractSocketEngine *QHttpSocketEngineHandler::createSocketEngine(qintptr, QObject *)
{
- return 0;
+ return nullptr;
}
QT_END_NAMESPACE
diff --git a/src/network/socket/qlocalserver.cpp b/src/network/socket/qlocalserver.cpp
index 3e36a7b229..5ca2db70b9 100644
--- a/src/network/socket/qlocalserver.cpp
+++ b/src/network/socket/qlocalserver.cpp
@@ -417,7 +417,7 @@ QLocalSocket *QLocalServer::nextPendingConnection()
{
Q_D(QLocalServer);
if (d->pendingConnections.isEmpty())
- return 0;
+ return nullptr;
QLocalSocket *nextSocket = d->pendingConnections.dequeue();
#ifndef QT_LOCALSOCKET_TCP
if (d->pendingConnections.size() <= d->maxPendingConnections)
diff --git a/src/network/socket/qlocalserver_unix.cpp b/src/network/socket/qlocalserver_unix.cpp
index 9547ec5b88..88367d680d 100644
--- a/src/network/socket/qlocalserver_unix.cpp
+++ b/src/network/socket/qlocalserver_unix.cpp
@@ -243,7 +243,7 @@ void QLocalServerPrivate::closeServer()
if (socketNotifier) {
socketNotifier->setEnabled(false); // Otherwise, closed socket is checked before deleter runs
socketNotifier->deleteLater();
- socketNotifier = 0;
+ socketNotifier = nullptr;
}
if (-1 != listenSocket)
diff --git a/src/network/socket/qlocalsocket.cpp b/src/network/socket/qlocalsocket.cpp
index 1c34cd13ee..d517f91aad 100644
--- a/src/network/socket/qlocalsocket.cpp
+++ b/src/network/socket/qlocalsocket.cpp
@@ -220,11 +220,25 @@ QT_BEGIN_NAMESPACE
/*!
\fn QLocalSocket::LocalSocketError QLocalSocket::error() const
+ \deprecated
+
+ Use socketError() instead.
+
+ Returns the type of error that last occurred.
+
+ \sa state(), errorString(), socketError()
+*/
+
+/*!
+ \fn QLocalSocket::LocalSocketError QLocalSocket::socketError() const
+ \since 5.15
+
Returns the type of error that last occurred.
\sa state(), errorString()
*/
+
/*!
\fn bool QLocalSocket::isValid() const
@@ -272,7 +286,7 @@ QT_BEGIN_NAMESPACE
Waits until the socket is connected, up to \a msecs milliseconds. If the
connection has been established, this function returns \c true; otherwise
it returns \c false. In the case where it returns \c false, you can call
- error() to determine the cause of the error.
+ socketError() to determine the cause of the error.
The following example waits up to one second for a connection
to be established:
@@ -287,11 +301,12 @@ QT_BEGIN_NAMESPACE
/*!
\fn bool QLocalSocket::waitForDisconnected(int msecs)
- Waits until the socket has disconnected, up to \a msecs
- milliseconds. If the connection has been disconnected, this
- function returns \c true; otherwise it returns \c false. In the case
- where it returns \c false, you can call error() to determine
- the cause of the error.
+ Waits until the socket has disconnected, up to \a msecs milliseconds. If the
+ connection was successfully disconnected, this function returns \c true;
+ otherwise it returns \c false (if the operation timed out, if an error
+ occurred, or if this QLocalSocket is already disconnected). In the case
+ where it returns \c false, you can call socketError() to determine the cause of
+ the error.
The following example waits up to one second for a connection
to be closed:
@@ -336,7 +351,7 @@ QT_BEGIN_NAMESPACE
connections, you will have to register it with Q_DECLARE_METATYPE() and
qRegisterMetaType().
- \sa error(), errorString(), {Creating Custom Qt Types}
+ \sa socketError(), errorString(), {Creating Custom Qt Types}
*/
/*!
@@ -371,7 +386,7 @@ QLocalSocket::~QLocalSocket()
QLocalSocket::close();
#if !defined(Q_OS_WIN) && !defined(QT_LOCALSOCKET_TCP)
Q_D(QLocalSocket);
- d->unixSocket.setParent(0);
+ d->unixSocket.setParent(nullptr);
#endif
}
@@ -445,7 +460,7 @@ QString QLocalSocket::fullServerName() const
/*!
Returns the state of the socket.
- \sa error()
+ \sa socketError()
*/
QLocalSocket::LocalSocketState QLocalSocket::state() const
{
@@ -465,7 +480,7 @@ bool QLocalSocket::isSequential() const
The LocalServerError enumeration represents the errors that can occur.
The most recent error can be retrieved through a call to
- \l QLocalSocket::error().
+ \l QLocalSocket::socketError().
\value ConnectionRefusedError The connection was refused by
the peer (or timed out).
diff --git a/src/network/socket/qlocalsocket.h b/src/network/socket/qlocalsocket.h
index 1876a6ac0d..9cf76d1022 100644
--- a/src/network/socket/qlocalsocket.h
+++ b/src/network/socket/qlocalsocket.h
@@ -97,7 +97,12 @@ public:
virtual bool canReadLine() const override;
virtual bool open(OpenMode openMode = ReadWrite) override;
virtual void close() override;
- LocalSocketError error() const;
+
+#if QT_DEPRECATED_SINCE(5, 15)
+ QT_DEPRECATED_X("Use socketError()") LocalSocketError error() const;
+#endif // QT_DEPRECATED_SINCE(5, 15)
+
+ LocalSocketError socketError() const;
bool flush();
bool isValid() const;
qint64 readBufferSize() const;
diff --git a/src/network/socket/qlocalsocket_tcp.cpp b/src/network/socket/qlocalsocket_tcp.cpp
index 41e5b47627..74d3d547b9 100644
--- a/src/network/socket/qlocalsocket_tcp.cpp
+++ b/src/network/socket/qlocalsocket_tcp.cpp
@@ -363,8 +363,15 @@ void QLocalSocket::disconnectFromServer()
d->tcpSocket->disconnectFromHost();
}
+#if QT_DEPRECATED_SINCE(5, 15)
QLocalSocket::LocalSocketError QLocalSocket::error() const
{
+ return socketError();
+}
+#endif // QT_DEPRECATED_SINCE(5, 15)
+
+QLocalSocket::LocalSocketError QLocalSocket::socketError() const
+{
Q_D(const QLocalSocket);
switch (d->tcpSocket->error()) {
case QAbstractSocket::ConnectionRefusedError:
diff --git a/src/network/socket/qlocalsocket_unix.cpp b/src/network/socket/qlocalsocket_unix.cpp
index d1df26d9f1..2e2eb7dee9 100644
--- a/src/network/socket/qlocalsocket_unix.cpp
+++ b/src/network/socket/qlocalsocket_unix.cpp
@@ -61,10 +61,9 @@
QT_BEGIN_NAMESPACE
QLocalSocketPrivate::QLocalSocketPrivate() : QIODevicePrivate(),
- delayConnect(0),
- connectTimer(0),
+ delayConnect(nullptr),
+ connectTimer(nullptr),
connectingSocket(-1),
- connectingOpenMode(0),
state(QLocalSocket::UnconnectedState)
{
}
@@ -341,7 +340,7 @@ void QLocalSocketPrivate::_q_connectToSocket()
}
connectingSocket = -1;
connectingName.clear();
- connectingOpenMode = 0;
+ connectingOpenMode = { };
}
bool QLocalSocket::setSocketDescriptor(qintptr socketDescriptor,
@@ -380,10 +379,10 @@ void QLocalSocketPrivate::cancelDelayedConnect()
if (delayConnect) {
delayConnect->setEnabled(false);
delete delayConnect;
- delayConnect = 0;
+ delayConnect = nullptr;
connectTimer->stop();
delete connectTimer;
- connectTimer = 0;
+ connectTimer = nullptr;
}
}
@@ -438,7 +437,7 @@ void QLocalSocket::close()
::close(d->connectingSocket);
d->connectingSocket = -1;
d->connectingName.clear();
- d->connectingOpenMode = 0;
+ d->connectingOpenMode = { };
d->serverName.clear();
d->fullServerName.clear();
QIODevice::close();
@@ -462,10 +461,17 @@ void QLocalSocket::disconnectFromServer()
d->unixSocket.disconnectFromHost();
}
+#if QT_DEPRECATED_SINCE(5, 15)
QLocalSocket::LocalSocketError QLocalSocket::error() const
{
+ return socketError();
+}
+#endif // QT_DEPRECATED_SINCE(5, 15)
+
+QLocalSocket::LocalSocketError QLocalSocket::socketError() const
+{
Q_D(const QLocalSocket);
- switch (d->unixSocket.error()) {
+ switch (d->unixSocket.socketError()) {
case QAbstractSocket::ConnectionRefusedError:
return QLocalSocket::ConnectionRefusedError;
case QAbstractSocket::RemoteHostClosedError:
diff --git a/src/network/socket/qlocalsocket_win.cpp b/src/network/socket/qlocalsocket_win.cpp
index 4decbd5ded..657790519b 100644
--- a/src/network/socket/qlocalsocket_win.cpp
+++ b/src/network/socket/qlocalsocket_win.cpp
@@ -330,8 +330,15 @@ void QLocalSocket::disconnectFromServer()
}
}
+#if QT_DEPRECATED_SINCE(5, 15)
QLocalSocket::LocalSocketError QLocalSocket::error() const
{
+ return socketError();
+}
+#endif // QT_DEPRECATED_SINCE(5, 15)
+
+QLocalSocket::LocalSocketError QLocalSocket::socketError() const
+{
Q_D(const QLocalSocket);
return d->error;
}
diff --git a/src/network/socket/qnativesocketengine.cpp b/src/network/socket/qnativesocketengine.cpp
index 7085fe3bbd..ad625b758e 100644
--- a/src/network/socket/qnativesocketengine.cpp
+++ b/src/network/socket/qnativesocketengine.cpp
@@ -191,9 +191,9 @@ QT_BEGIN_NAMESPACE
*/
QNativeSocketEnginePrivate::QNativeSocketEnginePrivate() :
socketDescriptor(-1),
- readNotifier(0),
- writeNotifier(0),
- exceptNotifier(0)
+ readNotifier(nullptr),
+ writeNotifier(nullptr),
+ exceptNotifier(nullptr)
{
#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
QSysInfo::machineHostName(); // this initializes ws2_32.dll
@@ -985,15 +985,15 @@ void QNativeSocketEngine::close()
d->inboundStreamCount = d->outboundStreamCount = 0;
if (d->readNotifier) {
qDeleteInEventHandler(d->readNotifier);
- d->readNotifier = 0;
+ d->readNotifier = nullptr;
}
if (d->writeNotifier) {
qDeleteInEventHandler(d->writeNotifier);
- d->writeNotifier = 0;
+ d->writeNotifier = nullptr;
}
if (d->exceptNotifier) {
qDeleteInEventHandler(d->exceptNotifier);
- d->exceptNotifier = 0;
+ d->exceptNotifier = nullptr;
}
}
@@ -1341,7 +1341,7 @@ void QNativeSocketEngine::setReadNotificationEnabled(bool enable)
Q_D(QNativeSocketEngine);
if (d->readNotifier) {
d->readNotifier->setEnabled(enable);
- } else if (enable && d->threadData->hasEventDispatcher()) {
+ } else if (enable && d->threadData.loadRelaxed()->hasEventDispatcher()) {
d->readNotifier = new QReadNotifier(d->socketDescriptor, this);
d->readNotifier->setEnabled(true);
}
@@ -1358,7 +1358,7 @@ void QNativeSocketEngine::setWriteNotificationEnabled(bool enable)
Q_D(QNativeSocketEngine);
if (d->writeNotifier) {
d->writeNotifier->setEnabled(enable);
- } else if (enable && d->threadData->hasEventDispatcher()) {
+ } else if (enable && d->threadData.loadRelaxed()->hasEventDispatcher()) {
d->writeNotifier = new QWriteNotifier(d->socketDescriptor, this);
d->writeNotifier->setEnabled(true);
}
@@ -1375,7 +1375,7 @@ void QNativeSocketEngine::setExceptionNotificationEnabled(bool enable)
Q_D(QNativeSocketEngine);
if (d->exceptNotifier) {
d->exceptNotifier->setEnabled(enable);
- } else if (enable && d->threadData->hasEventDispatcher()) {
+ } else if (enable && d->threadData.loadRelaxed()->hasEventDispatcher()) {
d->exceptNotifier = new QExceptionNotifier(d->socketDescriptor, this);
d->exceptNotifier->setEnabled(true);
}
diff --git a/src/network/socket/qnativesocketengine_unix.cpp b/src/network/socket/qnativesocketengine_unix.cpp
index 3ca586e247..e5b9fbbdb2 100644
--- a/src/network/socket/qnativesocketengine_unix.cpp
+++ b/src/network/socket/qnativesocketengine_unix.cpp
@@ -628,7 +628,7 @@ bool QNativeSocketEnginePrivate::nativeListen(int backlog)
int QNativeSocketEnginePrivate::nativeAccept()
{
- int acceptedDescriptor = qt_safe_accept(socketDescriptor, 0, 0);
+ int acceptedDescriptor = qt_safe_accept(socketDescriptor, nullptr, nullptr);
if (acceptedDescriptor == -1) {
switch (errno) {
case EBADF:
@@ -1002,7 +1002,7 @@ qint64 QNativeSocketEnginePrivate::nativeReceiveDatagram(char *data, qint64 maxS
struct cmsghdr *cmsgptr;
QT_WARNING_PUSH
QT_WARNING_DISABLE_CLANG("-Wsign-compare")
- for (cmsgptr = CMSG_FIRSTHDR(&msg); cmsgptr != NULL;
+ for (cmsgptr = CMSG_FIRSTHDR(&msg); cmsgptr != nullptr;
cmsgptr = CMSG_NXTHDR(&msg, cmsgptr)) {
QT_WARNING_POP
if (cmsgptr->cmsg_level == IPPROTO_IPV6 && cmsgptr->cmsg_type == IPV6_PKTINFO
@@ -1166,7 +1166,7 @@ qint64 QNativeSocketEnginePrivate::nativeSendDatagram(const char *data, qint64 l
#endif
if (msg.msg_controllen == 0)
- msg.msg_control = 0;
+ msg.msg_control = nullptr;
ssize_t sentBytes = qt_safe_sendmsg(socketDescriptor, &msg, 0);
if (sentBytes < 0) {
diff --git a/src/network/socket/qsocks5socketengine.cpp b/src/network/socket/qsocks5socketengine.cpp
index 4207832c4c..b2eefa352f 100644
--- a/src/network/socket/qsocks5socketengine.cpp
+++ b/src/network/socket/qsocks5socketengine.cpp
@@ -365,13 +365,13 @@ QSocks5BindData *QSocks5BindStore::retrieve(qintptr socketDescriptor)
QMutexLocker lock(&mutex);
const auto it = store.constFind(socketDescriptor);
if (it == store.cend())
- return 0;
+ return nullptr;
QSocks5BindData *bindData = it.value();
store.erase(it);
if (bindData) {
if (bindData->controlSocket->thread() != QThread::currentThread()) {
qWarning("Cannot access socks5 bind data from different thread");
- return 0;
+ return nullptr;
}
} else {
QSOCKS5_DEBUG << "__ERROR__ binddata == 0";
@@ -503,12 +503,12 @@ QSocks5SocketEnginePrivate::QSocks5SocketEnginePrivate()
, writeNotificationEnabled(false)
, exceptNotificationEnabled(false)
, socketDescriptor(-1)
- , data(0)
- , connectData(0)
+ , data(nullptr)
+ , connectData(nullptr)
#ifndef QT_NO_UDPSOCKET
- , udpData(0)
+ , udpData(nullptr)
#endif
- , bindData(0)
+ , bindData(nullptr)
, readNotificationActivated(false)
, writeNotificationActivated(false)
, readNotificationPending(false)
@@ -594,7 +594,7 @@ void QSocks5SocketEnginePrivate::setErrorState(Socks5State state, const QString
case ConnectError:
case ControlSocketError: {
- QAbstractSocket::SocketError controlSocketError = data->controlSocket->error();
+ QAbstractSocket::SocketError controlSocketError = data->controlSocket->socketError();
if (socks5State != Connected) {
switch (controlSocketError) {
case QAbstractSocket::ConnectionRefusedError:
@@ -918,7 +918,7 @@ void QSocks5SocketEnginePrivate::_q_emitPendingReadNotification()
return;
// check if there needs to be a new zero read notification
if (data && data->controlSocket->state() == QAbstractSocket::UnconnectedState
- && data->controlSocket->error() == QAbstractSocket::RemoteHostClosedError) {
+ && data->controlSocket->socketError() == QAbstractSocket::RemoteHostClosedError) {
connectData->readBuffer.clear();
emitReadNotification();
}
@@ -1038,11 +1038,11 @@ bool QSocks5SocketEngine::initialize(qintptr socketDescriptor, QAbstractSocket::
d->data = d->connectData;
d->mode = QSocks5SocketEnginePrivate::ConnectMode;
d->data->controlSocket = bindData->controlSocket;
- bindData->controlSocket = 0;
+ bindData->controlSocket = nullptr;
d->data->controlSocket->setParent(this);
d->socketProtocol = d->data->controlSocket->localAddress().protocol();
d->data->authenticator = bindData->authenticator;
- bindData->authenticator = 0;
+ bindData->authenticator = nullptr;
d->localPort = bindData->localPort;
d->localAddress = bindData->localAddress;
d->peerPort = bindData->peerPort;
@@ -1256,7 +1256,7 @@ void QSocks5SocketEnginePrivate::_q_controlSocketError(QAbstractSocket::SocketEr
data->controlSocket->close();
emitConnectionNotification();
} else {
- q_func()->setError(data->controlSocket->error(), data->controlSocket->errorString());
+ q_func()->setError(data->controlSocket->socketError(), data->controlSocket->errorString());
emitReadNotification();
emitWriteNotification();
}
@@ -1348,7 +1348,7 @@ bool QSocks5SocketEngine::bind(const QHostAddress &addr, quint16 port)
if (d->mode == QSocks5SocketEnginePrivate::UdpAssociateMode) {
if (!d->udpData->udpSocket->bind(address, port)) {
QSOCKS5_Q_DEBUG << "local udp bind failed";
- setError(d->udpData->udpSocket->error(), d->udpData->udpSocket->errorString());
+ setError(d->udpData->udpSocket->socketError(), d->udpData->udpSocket->errorString());
return false;
}
d->localAddress = d->udpData->udpSocket->localAddress();
@@ -1367,7 +1367,7 @@ bool QSocks5SocketEngine::bind(const QHostAddress &addr, quint16 port)
QElapsedTimer stopWatch;
stopWatch.start();
d->data->controlSocket->connectToHost(d->proxyInfo.hostName(), d->proxyInfo.port());
- if (!d->waitForConnected(msecs, 0) ||
+ if (!d->waitForConnected(msecs, nullptr) ||
d->data->controlSocket->state() == QAbstractSocket::UnconnectedState) {
// waitForConnected sets the error state and closes the socket
QSOCKS5_Q_DEBUG << "waitForConnected to proxy server" << d->data->controlSocket->errorString();
@@ -1428,13 +1428,13 @@ int QSocks5SocketEngine::accept()
case QSocks5SocketEnginePrivate::BindSuccess:
QSOCKS5_Q_DEBUG << "BindSuccess adding" << d->socketDescriptor << "to the bind store";
d->data->controlSocket->disconnect();
- d->data->controlSocket->setParent(0);
+ d->data->controlSocket->setParent(nullptr);
d->bindData->localAddress = d->localAddress;
d->bindData->localPort = d->localPort;
sd = d->socketDescriptor;
socks5BindStore()->add(sd, d->bindData);
- d->data = 0;
- d->bindData = 0;
+ d->data = nullptr;
+ d->bindData = nullptr;
d->socketDescriptor = 0;
//### do something about this socket layer ... set it closed and an error about why ...
// reset state and local port/address
@@ -1656,8 +1656,8 @@ qint64 QSocks5SocketEngine::writeDatagram(const char *data, qint64 len, const QI
}
if (d->udpData->udpSocket->writeDatagram(sealedBuf, d->udpData->associateAddress, d->udpData->associatePort) != sealedBuf.size()) {
//### try frgamenting
- if (d->udpData->udpSocket->error() == QAbstractSocket::DatagramTooLargeError)
- setError(d->udpData->udpSocket->error(), d->udpData->udpSocket->errorString());
+ if (d->udpData->udpSocket->socketError() == QAbstractSocket::DatagramTooLargeError)
+ setError(d->udpData->udpSocket->socketError(), d->udpData->udpSocket->errorString());
//### else maybe more serious error
return -1;
}
@@ -1727,7 +1727,7 @@ bool QSocks5SocketEnginePrivate::waitForConnected(int msecs, bool *timedOut)
return true;
setErrorState(QSocks5SocketEnginePrivate::ControlSocketError);
- if (timedOut && data->controlSocket->error() == QAbstractSocket::SocketTimeoutError)
+ if (timedOut && data->controlSocket->socketError() == QAbstractSocket::SocketTimeoutError)
*timedOut = true;
return false;
}
@@ -1765,8 +1765,8 @@ bool QSocks5SocketEngine::waitForRead(int msecs, bool *timedOut)
if (d->data->controlSocket->state() == QAbstractSocket::UnconnectedState)
return true;
- setError(d->data->controlSocket->error(), d->data->controlSocket->errorString());
- if (timedOut && d->data->controlSocket->error() == QAbstractSocket::SocketTimeoutError)
+ setError(d->data->controlSocket->socketError(), d->data->controlSocket->errorString());
+ if (timedOut && d->data->controlSocket->socketError() == QAbstractSocket::SocketTimeoutError)
*timedOut = true;
return false;
}
@@ -1775,8 +1775,8 @@ bool QSocks5SocketEngine::waitForRead(int msecs, bool *timedOut)
} else {
while (!d->readNotificationActivated) {
if (!d->udpData->udpSocket->waitForReadyRead(qt_subtract_from_timeout(msecs, stopWatch.elapsed()))) {
- setError(d->udpData->udpSocket->error(), d->udpData->udpSocket->errorString());
- if (timedOut && d->udpData->udpSocket->error() == QAbstractSocket::SocketTimeoutError)
+ setError(d->udpData->udpSocket->socketError(), d->udpData->udpSocket->errorString());
+ if (timedOut && d->udpData->udpSocket->socketError() == QAbstractSocket::SocketTimeoutError)
*timedOut = true;
return false;
}
@@ -1909,7 +1909,7 @@ QSocks5SocketEngineHandler::createSocketEngine(QAbstractSocket::SocketType socke
// proxy type must have been resolved by now
if (proxy.type() != QNetworkProxy::Socks5Proxy) {
QSOCKS5_DEBUG << "not proxying";
- return 0;
+ return nullptr;
}
QScopedPointer<QSocks5SocketEngine> engine(new QSocks5SocketEngine(parent));
engine->setProxy(proxy);
@@ -1923,7 +1923,7 @@ QAbstractSocketEngine *QSocks5SocketEngineHandler::createSocketEngine(qintptr so
QSOCKS5_DEBUG << "bind store contains" << socketDescriptor;
return new QSocks5SocketEngine(parent);
}
- return 0;
+ return nullptr;
}
QT_END_NAMESPACE
diff --git a/src/network/socket/qtcpserver.cpp b/src/network/socket/qtcpserver.cpp
index 98e58192a2..9916c75e65 100644
--- a/src/network/socket/qtcpserver.cpp
+++ b/src/network/socket/qtcpserver.cpp
@@ -121,7 +121,7 @@ QTcpServerPrivate::QTcpServerPrivate()
: port(0)
, socketType(QAbstractSocket::UnknownSocketType)
, state(QAbstractSocket::UnconnectedState)
- , socketEngine(0)
+ , socketEngine(nullptr)
, serverSocketError(QAbstractSocket::UnknownSocketError)
, maxConnections(30)
{
@@ -389,7 +389,7 @@ void QTcpServer::close()
// in out of memory situations, the socketEngine
// will be deleted in ~QTcpServer (it's a child-object of this)
}
- d->socketEngine = 0;
+ d->socketEngine = nullptr;
}
d->state = QAbstractSocket::UnconnectedState;
@@ -561,7 +561,7 @@ QTcpSocket *QTcpServer::nextPendingConnection()
{
Q_D(QTcpServer);
if (d->pendingConnections.isEmpty())
- return 0;
+ return nullptr;
if (!d->socketEngine) {
qWarning("QTcpServer::nextPendingConnection() called while not listening");
diff --git a/src/network/ssl/qdtls_openssl.cpp b/src/network/ssl/qdtls_openssl.cpp
index 25a6c5f49c..36b4d572fd 100644
--- a/src/network/ssl/qdtls_openssl.cpp
+++ b/src/network/ssl/qdtls_openssl.cpp
@@ -1125,7 +1125,7 @@ qint64 QDtlsPrivateOpenSSL::writeDatagramEncrypted(QUdpSocket *socket,
// some errors can be just ignored (it's UDP, not TCP after all).
// Unlike QSslSocket we do not abort though.
QString description(QSslSocketBackendPrivate::getErrorsFromOpenSsl());
- if (socket->error() != QAbstractSocket::UnknownSocketError && description.isEmpty()) {
+ if (socket->socketError() != QAbstractSocket::UnknownSocketError && description.isEmpty()) {
setDtlsError(QDtlsError::UnderlyingSocketError, socket->errorString());
} else {
setDtlsError(QDtlsError::TlsFatalError,
diff --git a/src/network/ssl/qssl.cpp b/src/network/ssl/qssl.cpp
index c9fa7f85d9..bfbe8eb90f 100644
--- a/src/network/ssl/qssl.cpp
+++ b/src/network/ssl/qssl.cpp
@@ -120,8 +120,6 @@ Q_LOGGING_CATEGORY(lcSsl, "qt.network.ssl");
Describes the protocol of the cipher.
- \value SslV3 SSLv3; not supported by QSslSocket.
- \value SslV2 SSLv2; not supported by QSslSocket.
\value TlsV1_0 TLSv1.0
\value TlsV1_0OrLater TLSv1.0 and later versions. This option is not available when using the WinRT backend due to platform limitations.
\value TlsV1 Obsolete, means the same as TlsV1_0
@@ -137,7 +135,6 @@ Q_LOGGING_CATEGORY(lcSsl, "qt.network.ssl");
\value TlsV1_3OrLater TLSv1.3 and later versions. (Since Qt 5.12)
\value UnknownProtocol The cipher's protocol cannot be determined.
\value AnyProtocol Any supported protocol. This value is used by QSslSocket only.
- \value TlsV1SslV3 Same as TlsV1_0.
\value SecureProtocols The default option, using protocols known to be secure.
*/
diff --git a/src/network/ssl/qssl.h b/src/network/ssl/qssl.h
index 42c7b5c56d..1fd2cf9c6d 100644
--- a/src/network/ssl/qssl.h
+++ b/src/network/ssl/qssl.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** 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.
@@ -77,17 +77,11 @@ namespace QSsl {
#endif
enum SslProtocol {
- SslV3,
- SslV2,
- TlsV1_0,
-#if QT_DEPRECATED_SINCE(5,0)
- TlsV1 = TlsV1_0,
-#endif
+ TlsV1_0 = 2,
TlsV1_1,
TlsV1_2,
AnyProtocol,
- TlsV1SslV3,
- SecureProtocols,
+ SecureProtocols = AnyProtocol + 2,
TlsV1_0OrLater,
TlsV1_1OrLater,
diff --git a/src/network/ssl/qsslconfiguration.cpp b/src/network/ssl/qsslconfiguration.cpp
index 738c8d4ac5..b6199a2b16 100644
--- a/src/network/ssl/qsslconfiguration.cpp
+++ b/src/network/ssl/qsslconfiguration.cpp
@@ -222,7 +222,9 @@ bool QSslConfiguration::operator==(const QSslConfiguration &other) const
d->nextNegotiatedProtocol == other.d->nextNegotiatedProtocol &&
d->nextProtocolNegotiationStatus == other.d->nextProtocolNegotiationStatus &&
d->dtlsCookieEnabled == other.d->dtlsCookieEnabled &&
- d->ocspStaplingEnabled == other.d->ocspStaplingEnabled;
+ d->ocspStaplingEnabled == other.d->ocspStaplingEnabled &&
+ d->reportFromCallback == other.d->reportFromCallback &&
+ d->missingCertIsFatal == other.d->missingCertIsFatal;
}
/*!
@@ -267,7 +269,9 @@ bool QSslConfiguration::isNull() const
d->nextAllowedProtocols.isEmpty() &&
d->nextNegotiatedProtocol.isNull() &&
d->nextProtocolNegotiationStatus == QSslConfiguration::NextProtocolNegotiationNone &&
- d->ocspStaplingEnabled == false);
+ d->ocspStaplingEnabled == false &&
+ d->reportFromCallback == false &&
+ d->missingCertIsFatal == false);
}
/*!
@@ -1190,6 +1194,89 @@ bool QSslConfiguration::ocspStaplingEnabled() const
return d->ocspStaplingEnabled;
}
+/*!
+ \since 6.0
+
+ Returns true if a verification callback will emit QSslSocket::handshakeInterruptedOnError()
+ early, before concluding the handshake.
+
+ \note This function always returns false for all backends but OpenSSL.
+
+ \sa setHandshakeMustInterruptOnError(), QSslSocket::handshakeInterruptedOnError(), QSslSocket::continueInterruptedHandshake()
+*/
+bool QSslConfiguration::handshakeMustInterruptOnError() const
+{
+ return d->reportFromCallback;
+}
+
+/*!
+ \since 6.0
+
+ If \a interrupt is true and the underlying backend supports this option,
+ errors found during certificate verification are reported immediately
+ by emitting QSslSocket::handshakeInterruptedOnError(). This allows
+ to stop the unfinished handshake and send a proper alert message to
+ a peer. No special action is required from the application in this case.
+ QSslSocket will close the connection after sending the alert message.
+ If the application after inspecting the error wants to continue the
+ handshake, it must call QSslSocket::continueInterruptedHandshake()
+ from its slot function. The signal-slot connection must be direct.
+
+ \note When interrupting handshake is enabled, errors that would otherwise
+ be reported by QSslSocket::peerVerifyError() are instead only reported by
+ QSslSocket::handshakeInterruptedOnError().
+ \note Even if the handshake was continued, these errors will be
+ reported when emitting QSslSocket::sslErrors() signal (and thus must
+ be ignored in the corresponding function slot).
+
+ \sa handshakeMustInterruptOnError(), QSslSocket::handshakeInterruptedOnError(), QSslSocket::continueInterruptedHandshake()
+*/
+void QSslConfiguration::setHandshakeMustInterruptOnError(bool interrupt)
+{
+#if QT_CONFIG(openssl)
+ d->reportFromCallback = interrupt;
+#else
+ qCWarning(lcSsl, "This operation requires OpenSSL as TLS backend");
+#endif
+}
+
+/*!
+ \since 6.0
+
+ Returns true if errors with code QSslError::NoPeerCertificate
+ cannot be ignored.
+
+ \note Always returns false for all TLS backends but OpenSSL.
+
+ \sa QSslSocket::ignoreSslErrors(), setMissingCertificateIsFatal()
+*/
+bool QSslConfiguration::missingCertificateIsFatal() const
+{
+ return d->missingCertIsFatal;
+}
+
+/*!
+ \since 6.0
+
+ If \a cannotRecover is true, and verification mode in use is
+ QSslSocket::VerifyPeer or QSslSocket::AutoVerifyPeer (for a
+ client-side socket), the missing peer's certificate would be
+ treated as an unrecoverable error that cannot be ignored. A proper
+ alert message will be sent to the peer before closing the connection.
+
+ \note Only available if Qt was configured and built with OpenSSL backend.
+
+ \sa QSslSocket::ignoreSslErrors(), QSslSocket::PeerVerifyMode, missingCertificateIsFatal()
+*/
+void QSslConfiguration::setMissingCertificateIsFatal(bool cannotRecover)
+{
+#if QT_CONFIG(openssl)
+ d->missingCertIsFatal = cannotRecover;
+#else
+ qCWarning(lcSsl, "Handling a missing certificate as a fatal error requires an OpenSSL backend");
+#endif // openssl
+}
+
/*! \internal
*/
bool QSslConfigurationPrivate::peerSessionWasShared(const QSslConfiguration &configuration) {
diff --git a/src/network/ssl/qsslconfiguration.h b/src/network/ssl/qsslconfiguration.h
index ad6e23638f..dc4587a835 100644
--- a/src/network/ssl/qsslconfiguration.h
+++ b/src/network/ssl/qsslconfiguration.h
@@ -172,6 +172,12 @@ public:
static void setDefaultDtlsConfiguration(const QSslConfiguration &configuration);
#endif // dtls
+ bool handshakeMustInterruptOnError() const;
+ void setHandshakeMustInterruptOnError(bool interrupt);
+
+ bool missingCertificateIsFatal() const;
+ void setMissingCertificateIsFatal(bool cannotRecover);
+
void setOcspStaplingEnabled(bool enable);
bool ocspStaplingEnabled() const;
diff --git a/src/network/ssl/qsslconfiguration_p.h b/src/network/ssl/qsslconfiguration_p.h
index 83126bb9a0..6ee3490df6 100644
--- a/src/network/ssl/qsslconfiguration_p.h
+++ b/src/network/ssl/qsslconfiguration_p.h
@@ -149,6 +149,14 @@ public:
const bool ocspStaplingEnabled = false;
#endif
+#if QT_CONFIG(openssl)
+ bool reportFromCallback = false;
+ bool missingCertIsFatal = false;
+#else
+ const bool reportFromCallback = false;
+ const bool missingCertIsFatal = false;
+#endif // openssl
+
// in qsslsocket.cpp:
static QSslConfiguration defaultConfiguration();
static void setDefaultConfiguration(const QSslConfiguration &configuration);
diff --git a/src/network/ssl/qsslcontext_openssl.cpp b/src/network/ssl/qsslcontext_openssl.cpp
index 562aa4f518..574f48a2b5 100644
--- a/src/network/ssl/qsslcontext_openssl.cpp
+++ b/src/network/ssl/qsslcontext_openssl.cpp
@@ -56,6 +56,7 @@ QT_BEGIN_NAMESPACE
// defined in qsslsocket_openssl.cpp:
extern int q_X509Callback(int ok, X509_STORE_CTX *ctx);
+extern "C" int q_X509CallbackDirect(int ok, X509_STORE_CTX *ctx);
extern QString getErrorsFromOpenSsl();
#if QT_CONFIG(dtls)
@@ -286,42 +287,31 @@ void QSslContext::initSslContext(QSslContext *sslContext, QSslSocket::SslMode mo
bool unsupportedProtocol = false;
bool isDtls = false;
init_context:
- if (sslContext->sslConfiguration.protocol() == QSsl::SslV2) {
- // SSL 2 is no longer supported, but chosen deliberately -> error
- sslContext->ctx = nullptr;
- unsupportedProtocol = true;
- } else if (sslContext->sslConfiguration.protocol() == QSsl::SslV3) {
- // SSL 3 is no longer supported, but chosen deliberately -> error
- sslContext->ctx = nullptr;
- unsupportedProtocol = true;
- } else {
- switch (sslContext->sslConfiguration.protocol()) {
- case QSsl::DtlsV1_0:
- case QSsl::DtlsV1_0OrLater:
- case QSsl::DtlsV1_2:
- case QSsl::DtlsV1_2OrLater:
+ switch (sslContext->sslConfiguration.protocol()) {
+ case QSsl::DtlsV1_0:
+ case QSsl::DtlsV1_0OrLater:
+ case QSsl::DtlsV1_2:
+ case QSsl::DtlsV1_2OrLater:
#if QT_CONFIG(dtls)
- isDtls = true;
- sslContext->ctx = q_SSL_CTX_new(client ? q_DTLS_client_method() : q_DTLS_server_method());
+ isDtls = true;
+ sslContext->ctx = q_SSL_CTX_new(client ? q_DTLS_client_method() : q_DTLS_server_method());
#else // dtls
- sslContext->ctx = nullptr;
- unsupportedProtocol = true;
- qCWarning(lcSsl, "DTLS protocol requested, but feature 'dtls' is disabled");
-
+ sslContext->ctx = nullptr;
+ unsupportedProtocol = true;
+ qCWarning(lcSsl, "DTLS protocol requested, but feature 'dtls' is disabled");
#endif // dtls
- break;
- case QSsl::TlsV1_3:
- case QSsl::TlsV1_3OrLater:
+ break;
+ case QSsl::TlsV1_3:
+ case QSsl::TlsV1_3OrLater:
#if !defined(TLS1_3_VERSION)
- qCWarning(lcSsl, "TLS 1.3 is not supported");
- sslContext->ctx = nullptr;
- unsupportedProtocol = true;
- break;
+ qCWarning(lcSsl, "TLS 1.3 is not supported");
+ sslContext->ctx = nullptr;
+ unsupportedProtocol = true;
+ break;
#endif // TLS1_3_VERSION
- default:
- // The ssl options will actually control the supported methods
- sslContext->ctx = q_SSL_CTX_new(client ? q_TLS_client_method() : q_TLS_server_method());
- }
+ default:
+ // The ssl options will actually control the supported methods
+ sslContext->ctx = q_SSL_CTX_new(client ? q_TLS_client_method() : q_TLS_server_method());
}
if (!sslContext->ctx) {
@@ -373,7 +363,6 @@ init_context:
#endif // TLS1_3_VERSION
break;
// Ranges:
- case QSsl::TlsV1SslV3:
case QSsl::AnyProtocol:
case QSsl::SecureProtocols:
case QSsl::TlsV1_0OrLater:
@@ -415,12 +404,6 @@ init_context:
Q_UNREACHABLE();
break;
#endif // TLS1_3_VERSION
- case QSsl::SslV2:
- case QSsl::SslV3:
- // These protocols are not supported, and we handle
- // them as an error (see the code above).
- Q_UNREACHABLE();
- break;
case QSsl::UnknownProtocol:
break;
}
@@ -589,11 +572,20 @@ init_context:
if (sslContext->sslConfiguration.peerVerifyMode() == QSslSocket::VerifyNone) {
q_SSL_CTX_set_verify(sslContext->ctx, SSL_VERIFY_NONE, nullptr);
} else {
- q_SSL_CTX_set_verify(sslContext->ctx, SSL_VERIFY_PEER,
-#if QT_CONFIG(dtls)
- isDtls ? dtlscallbacks::q_X509DtlsCallback :
-#endif // dtls
- q_X509Callback);
+ auto verificationCallback =
+ #if QT_CONFIG(dtls)
+ isDtls ? dtlscallbacks::q_X509DtlsCallback :
+ #endif // dtls
+ q_X509Callback;
+
+ if (!isDtls && configuration.handshakeMustInterruptOnError())
+ verificationCallback = q_X509CallbackDirect;
+
+ auto verificationMode = SSL_VERIFY_PEER;
+ if (!isDtls && sslContext->sslConfiguration.missingCertificateIsFatal())
+ verificationMode |= SSL_VERIFY_FAIL_IF_NO_PEER_CERT;
+
+ q_SSL_CTX_set_verify(sslContext->ctx, verificationMode, verificationCallback);
}
#if QT_CONFIG(dtls)
diff --git a/src/network/ssl/qsslsocket.cpp b/src/network/ssl/qsslsocket.cpp
index 690251727d..504e27a463 100644
--- a/src/network/ssl/qsslsocket.cpp
+++ b/src/network/ssl/qsslsocket.cpp
@@ -228,6 +228,74 @@
*/
/*!
+ \enum QAlertLevel
+ \brief Describes the level of an alert message
+ \relates QSslSocket
+ \since 6.0
+
+ \ingroup network
+ \ingroup ssl
+ \inmodule QtNetwork
+
+ This enum describes the level of an alert message that was sent
+ or received.
+
+ \value Warning Non-fatal alert message
+ \value Fatal Fatal alert message, the underlying backend will
+ handle such an alert properly and close the connection.
+ \value Unknown An alert of unknown level of severity.
+*/
+
+/*!
+ \enum QAlertType
+ \brief Enumerates possible codes that an alert message can have
+ \relates QSslSocket
+ \since 6.0
+
+ \ingroup network
+ \ingroup ssl
+ \inmodule QtNetwork
+
+ See \l{https://tools.ietf.org/html/rfc8446#page-85}{RFC 8446, section 6}
+ for the possible values and their meaning.
+
+ \value CloseNotify,
+ \value UnexpectedMessage
+ \value BadRecordMac
+ \value RecordOverflow
+ \value DecompressionFailure
+ \value HandshakeFailure
+ \value NoCertificate
+ \value BadCertificate
+ \value UnsupportedCertificate
+ \value CertificateRevoked
+ \value CertificateExpired
+ \value CertificateUnknown
+ \value IllegalParameter
+ \value UnknownCa
+ \value AccessDenied
+ \value DecodeError
+ \value DecryptError
+ \value ExportRestriction
+ \value ProtocolVersion
+ \value InsufficientSecurity
+ \value InternalError
+ \value InappropriateFallback
+ \value UserCancelled
+ \value NoRenegotiation
+ \value MissingExtension
+ \value UnsupportedExtension
+ \value CertificateUnobtainable
+ \value UnrecognizedName
+ \value BadCertificateStatusResponse
+ \value BadCertificateHashValue
+ \value UnknownPskIdentity
+ \value CertificateRequired
+ \value NoApplicationProtocol
+ \value UnknownAlertMessage
+*/
+
+/*!
\fn void QSslSocket::encrypted()
This signal is emitted when QSslSocket enters encrypted mode. After this
@@ -289,7 +357,7 @@
If you want to continue connecting despite the errors that have occurred,
you must call QSslSocket::ignoreSslErrors() from inside a slot connected to
this signal. If you need to access the error list at a later point, you
- can call sslErrors() (without arguments).
+ can call sslHandshakeErrors().
\a errors contains one or more errors that prevent QSslSocket from
verifying the identity of the peer.
@@ -322,6 +390,48 @@
\sa QSslPreSharedKeyAuthenticator
*/
+/*!
+ \fn void QSslSocket::alertSent(QAlertLevel level, QAlertType type, const QString &description)
+
+ QSslSocket emits this signal if an alert message was sent to a peer. \a level
+ describes if it was a warning or a fatal error. \a type gives the code
+ of the alert message. When a textual description of the alert message is
+ available, it is supplied in \a description.
+
+ \note This signal is mostly informational and can be used for debugging
+ purposes, normally it does not require any actions from the application.
+ \note Not all backends support this functionality.
+
+ \sa alertReceived(), QAlertLevel, QAlertType
+*/
+
+/*!
+ \fn void QSslSocket::alertReceived(QAlertLevel level, QAlertType type, const QString &description)
+
+ QSslSocket emits this signal if an alert message was received from a peer.
+ \a level tells if the alert was fatal or it was a warning. \a type is the
+ code explaining why the alert was sent. When a textual description of
+ the alert message is available, it is supplied in \a description.
+
+ \note The signal is mostly for informational and debugging purposes and does not
+ require any handling in the application. If the alert was fatal, underlying
+ backend will handle it and close the connection.
+ \note Not all backends support this functionality.
+
+ \sa alertSent(), QAlertLevel, QAlertType
+*/
+
+/*!
+ \fn void QSslSocket::handshakeInterruptedOnError(const QSslError &error)
+
+ QSslSocket emits this signal if a certificate verification error was
+ found and if early error reporting was enabled in QSslConfiguration.
+ An application is expected to inspect the \a error and decide if
+ it wants to continue the handshake, or abort it and send an alert message
+ to the peer. The signal-slot connection must be direct.
+
+ \sa continueInterruptedHandshake(), sslErrors(), QSslConfiguration::setHandshakeMustInterruptOnError()
+*/
#include "qssl_p.h"
#include "qsslsocket.h"
#include "qsslcipher.h"
@@ -549,7 +659,7 @@ bool QSslSocket::setSocketDescriptor(qintptr socketDescriptor, SocketState state
d->createPlainSocket(openMode);
bool retVal = d->plainSocket->setSocketDescriptor(socketDescriptor, state, openMode);
d->cachedSocketDescriptor = d->plainSocket->socketDescriptor();
- d->setError(d->plainSocket->error(), d->plainSocket->errorString());
+ d->setError(d->plainSocket->socketError(), d->plainSocket->errorString());
setSocketState(state);
setOpenMode(openMode);
setLocalPort(d->plainSocket->localPort());
@@ -977,7 +1087,10 @@ void QSslSocket::setSslConfiguration(const QSslConfiguration &configuration)
#if QT_CONFIG(ocsp)
d->configuration.ocspStaplingEnabled = configuration.ocspStaplingEnabled();
#endif
-
+#if QT_CONFIG(openssl)
+ d->configuration.reportFromCallback = configuration.handshakeMustInterruptOnError();
+ d->configuration.missingCertIsFatal = configuration.missingCertificateIsFatal();
+#endif // openssl
// if the CA certificates were set explicitly (either via
// QSslConfiguration::setCaCertificates() or QSslSocket::setCaCertificates(),
// we cannot load the certificates on demand
@@ -1526,7 +1639,7 @@ QList<QSslCertificate> QSslSocket::caCertificates() const
default CA certificate database.
\sa QSslConfiguration::caCertificates(), QSslConfiguration::addCaCertificates(),
- QSslConfiguration::addDefaultCaCertificate()
+ QSslConfiguration::addCaCertificate()
*/
bool QSslSocket::addDefaultCaCertificates(const QString &path, QSsl::EncodingFormat encoding,
QRegExp::PatternSyntax syntax)
@@ -1543,7 +1656,7 @@ bool QSslSocket::addDefaultCaCertificates(const QString &path, QSsl::EncodingFor
SSL socket's CA certificate database is initialized to the default
CA certificate database.
- \sa QSslConfiguration::caCertificates(), QSslConfiguration::addCaCertificates()
+ \sa QSslConfiguration::addCaCertificates()
*/
void QSslSocket::addDefaultCaCertificate(const QSslCertificate &certificate)
{
@@ -1651,7 +1764,7 @@ bool QSslSocket::waitForConnected(int msecs)
bool retVal = d->plainSocket->waitForConnected(msecs);
if (!retVal) {
setSocketState(d->plainSocket->state());
- d->setError(d->plainSocket->error(), d->plainSocket->errorString());
+ d->setError(d->plainSocket->socketError(), d->plainSocket->errorString());
}
return retVal;
}
@@ -1820,21 +1933,42 @@ bool QSslSocket::waitForDisconnected(int msecs)
bool retVal = d->plainSocket->waitForDisconnected(qt_subtract_from_timeout(msecs, stopWatch.elapsed()));
if (!retVal) {
setSocketState(d->plainSocket->state());
- d->setError(d->plainSocket->error(), d->plainSocket->errorString());
+ d->setError(d->plainSocket->socketError(), d->plainSocket->errorString());
}
return retVal;
}
+#if QT_DEPRECATED_SINCE(5, 15)
/*!
+ \deprecated
+
+ Use sslHandshakeErrors() instead.
+
Returns a list of the last SSL errors that occurred. This is the
same list as QSslSocket passes via the sslErrors() signal. If the
connection has been encrypted with no errors, this function will
return an empty list.
- \sa connectToHostEncrypted()
+ \sa connectToHostEncrypted(), sslHandshakeErrors()
*/
QList<QSslError> QSslSocket::sslErrors() const
{
+ return sslHandshakeErrors();
+}
+#endif // QT_DEPRECATED_SINCE(5, 15)
+
+/*!
+ \since 5.15
+
+ Returns a list of the last SSL errors that occurred. This is the
+ same list as QSslSocket passes via the sslErrors() signal. If the
+ connection has been encrypted with no errors, this function will
+ return an empty list.
+
+ \sa connectToHostEncrypted()
+*/
+QList<QSslError> QSslSocket::sslHandshakeErrors() const
+{
Q_D(const QSslSocket);
return d->sslErrors;
}
@@ -2035,7 +2169,7 @@ void QSslSocket::ignoreSslErrors()
You can clear the list of errors you want to ignore by calling this
function with an empty list.
- \sa sslErrors()
+ \sa sslErrors(), sslHandshakeErrors()
*/
void QSslSocket::ignoreSslErrors(const QList<QSslError> &errors)
{
@@ -2043,6 +2177,23 @@ void QSslSocket::ignoreSslErrors(const QList<QSslError> &errors)
d->ignoreErrorsList = errors;
}
+
+/*!
+ \since 6.0
+
+ If an application wants to conclude a handshake even after receiving
+ handshakeInterruptedOnError() signal, it must call this function.
+ This call must be done from a slot function attached to the signal.
+ The signal-slot connection must be direct.
+
+ \sa handshakeInterruptedOnError(), QSslConfiguration::setHandshakeMustInterruptOnError()
+*/
+void QSslSocket::continueInterruptedHandshake()
+{
+ Q_D(QSslSocket);
+ d->handshakeInterrupted = false;
+}
+
/*!
\internal
*/
@@ -2217,13 +2368,24 @@ void QSslSocketPrivate::init()
*/
bool QSslSocketPrivate::verifyProtocolSupported(const char *where)
{
- if (configuration.protocol == QSsl::SslV2 || configuration.protocol == QSsl::SslV3) {
- qCWarning(lcSsl) << where << "Attempted to use an unsupported protocol.";
+ QLatin1String protocolName("DTLS");
+ switch (configuration.protocol) {
+ case QSsl::UnknownProtocol:
+ // UnknownProtocol, according to our docs, is for cipher whose protocol is unknown.
+ // Should not be used when configuring QSslSocket.
+ protocolName = QLatin1String("UnknownProtocol");
+ Q_FALLTHROUGH();
+ case QSsl::DtlsV1_0:
+ case QSsl::DtlsV1_2:
+ case QSsl::DtlsV1_0OrLater:
+ case QSsl::DtlsV1_2OrLater:
+ qCWarning(lcSsl) << where << "QSslConfiguration with unexpected protocol" << protocolName;
setErrorAndEmit(QAbstractSocket::SslInvalidUserDataError,
QSslSocket::tr("Attempted to use an unsupported protocol."));
return false;
+ default:
+ return true;
}
- return true;
}
/*!
@@ -2434,6 +2596,10 @@ void QSslConfigurationPrivate::deepCopyDefaultConfiguration(QSslConfigurationPri
#if QT_CONFIG(ocsp)
ptr->ocspStaplingEnabled = global->ocspStaplingEnabled;
#endif
+#if QT_CONFIG(openssl)
+ ptr->reportFromCallback = global->reportFromCallback;
+ ptr->missingCertIsFatal = global->missingCertIsFatal;
+#endif
}
/*!
@@ -2668,7 +2834,7 @@ void QSslSocketPrivate::_q_errorSlot(QAbstractSocket::SocketError error)
readBufferMaxSize = tmpReadBufferMaxSize;
}
- setErrorAndEmit(plainSocket->error(), plainSocket->errorString());
+ setErrorAndEmit(plainSocket->socketError(), plainSocket->errorString());
}
/*!
diff --git a/src/network/ssl/qsslsocket.h b/src/network/ssl/qsslsocket.h
index 843e2d15f5..c12bb53334 100644
--- a/src/network/ssl/qsslsocket.h
+++ b/src/network/ssl/qsslsocket.h
@@ -63,6 +63,49 @@ class QSslEllipticCurve;
class QSslPreSharedKeyAuthenticator;
class QOcspResponse;
+enum class QAlertLevel {
+ Warning,
+ Fatal,
+ Unknown
+};
+
+enum class QAlertType {
+ CloseNotify,
+ UnexpectedMessage = 10,
+ BadRecordMac = 20,
+ RecordOverflow = 22,
+ DecompressionFailure = 30, // reserved
+ HandshakeFailure = 40,
+ NoCertificate = 41, // reserved
+ BadCertificate = 42,
+ UnsupportedCertificate = 43,
+ CertificateRevoked = 44,
+ CertificateExpired = 45,
+ CertificateUnknown = 46,
+ IllegalParameter = 47,
+ UnknownCa = 48,
+ AccessDenied = 49,
+ DecodeError = 50,
+ DecryptError = 51,
+ ExportRestriction = 60, // reserved
+ ProtocolVersion = 70,
+ InsufficientSecurity = 71,
+ InternalError = 80,
+ InappropriateFallback = 86,
+ UserCancelled = 90,
+ NoRenegotiation = 100,
+ MissingExtension = 109,
+ UnsupportedExtension = 110,
+ CertificateUnobtainable = 111, // reserved
+ UnrecognizedName = 112,
+ BadCertificateStatusResponse = 113,
+ BadCertificateHashValue = 114, // reserved
+ UnknownPskIdentity = 115,
+ CertificateRequired = 116,
+ NoApplicationProtocol = 120,
+ UnknownAlertMessage = 255
+};
+
class QSslSocketPrivate;
class Q_NETWORK_EXPORT QSslSocket : public QTcpSocket
{
@@ -192,7 +235,10 @@ public:
bool waitForBytesWritten(int msecs = 30000) override;
bool waitForDisconnected(int msecs = 30000) override;
- QList<QSslError> sslErrors() const;
+#if QT_DEPRECATED_SINCE(5, 15)
+ QT_DEPRECATED_X("Use sslHandshakeErrors()") QList<QSslError> sslErrors() const;
+#endif // QT_DEPRECATED_SINCE(5, 15)
+ QList<QSslError> sslHandshakeErrors() const;
static bool supportsSsl();
static long sslLibraryVersionNumber();
@@ -201,6 +247,7 @@ public:
static QString sslLibraryBuildVersionString();
void ignoreSslErrors(const QList<QSslError> &errors);
+ void continueInterruptedHandshake();
public Q_SLOTS:
void startClientEncryption();
@@ -214,6 +261,9 @@ Q_SIGNALS:
void modeChanged(QSslSocket::SslMode newMode);
void encryptedBytesWritten(qint64 totalBytes);
void preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator *authenticator);
+ void alertSent(QAlertLevel level, QAlertType type, const QString &description);
+ void alertReceived(QAlertLevel level, QAlertType type, const QString &description);
+ void handshakeInterruptedOnError(const QSslError &error);
protected:
qint64 readData(char *data, qint64 maxlen) override;
diff --git a/src/network/ssl/qsslsocket_mac.cpp b/src/network/ssl/qsslsocket_mac.cpp
index e0e065679d..fe1c43d992 100644
--- a/src/network/ssl/qsslsocket_mac.cpp
+++ b/src/network/ssl/qsslsocket_mac.cpp
@@ -496,10 +496,6 @@ QSsl::SslProtocol QSslSocketBackendPrivate::sessionProtocol() const
}
switch (protocol) {
- case kSSLProtocol2:
- return QSsl::SslV2;
- case kSSLProtocol3:
- return QSsl::SslV3;
case kTLSProtocol1:
return QSsl::TlsV1_0;
case kTLSProtocol11:
@@ -657,23 +653,6 @@ QSslCipher QSslSocketBackendPrivate::QSslCipher_from_SSLCipherSuite(SSLCipherSui
QSslCipher ciph;
switch (cipher) {
// Sorted as in CipherSuite.h (and groupped by their RFC)
- case SSL_RSA_WITH_NULL_MD5:
- ciph.d->name = QLatin1String("NULL-MD5");
- ciph.d->protocol = QSsl::SslV3;
- break;
- case SSL_RSA_WITH_NULL_SHA:
- ciph.d->name = QLatin1String("NULL-SHA");
- ciph.d->protocol = QSsl::SslV3;
- break;
- case SSL_RSA_WITH_RC4_128_MD5:
- ciph.d->name = QLatin1String("RC4-MD5");
- ciph.d->protocol = QSsl::SslV3;
- break;
- case SSL_RSA_WITH_RC4_128_SHA:
- ciph.d->name = QLatin1String("RC4-SHA");
- ciph.d->protocol = QSsl::SslV3;
- break;
-
// TLS addenda using AES, per RFC 3268
case TLS_RSA_WITH_AES_128_CBC_SHA:
ciph.d->name = QLatin1String("AES128-SHA");
@@ -822,12 +801,8 @@ QSslCipher QSslSocketBackendPrivate::QSslCipher_from_SSLCipherSuite(SSLCipherSui
ciph.d->isNull = false;
// protocol
- if (ciph.d->protocol == QSsl::SslV3) {
- ciph.d->protocolString = QLatin1String("SSLv3");
- } else {
- ciph.d->protocol = QSsl::TlsV1_2;
- ciph.d->protocolString = QLatin1String("TLSv1.2");
- }
+ ciph.d->protocol = QSsl::TlsV1_2;
+ ciph.d->protocolString = QLatin1String("TLSv1.2");
const auto bits = ciph.d->name.splitRef(QLatin1Char('-'));
if (bits.size() >= 2) {
@@ -1106,22 +1081,6 @@ bool QSslSocketBackendPrivate::setSessionProtocol()
{
Q_ASSERT_X(context, Q_FUNC_INFO, "invalid SSL context (null)");
- // QSsl::SslV2 == kSSLProtocol2 is disabled in Secure Transport and
- // always fails with errSSLIllegalParam:
- // if (version < MINIMUM_STREAM_VERSION || version > MAXIMUM_STREAM_VERSION)
- // return errSSLIllegalParam;
- // where MINIMUM_STREAM_VERSION is SSL_Version_3_0, MAXIMUM_STREAM_VERSION is TLS_Version_1_2.
- if (configuration.protocol == QSsl::SslV2) {
- qCDebug(lcSsl) << "protocol QSsl::SslV2 is disabled";
- return false;
- }
-
- // SslV3 is unsupported.
- if (configuration.protocol == QSsl::SslV3) {
- qCDebug(lcSsl) << "protocol QSsl::SslV3 is disabled";
- return false;
- }
-
// SecureTransport has kTLSProtocol13 constant and also, kTLSProtocolMaxSupported.
// Calling SSLSetProtocolVersionMax/Min with any of these two constants results
// in errInvalidParam and a failure to set the protocol version. This means
@@ -1162,13 +1121,6 @@ bool QSslSocketBackendPrivate::setSessionProtocol()
qCDebug(lcSsl) << plainSocket << "requesting : any";
#endif
err = SSLSetProtocolVersionMin(context, kTLSProtocol1);
- } else if (configuration.protocol == QSsl::TlsV1SslV3) {
- #ifdef QSSLSOCKET_DEBUG
- qCDebug(lcSsl) << plainSocket << "requesting : SSLv3 - TLSv1.2";
- #endif
- err = SSLSetProtocolVersionMin(context, kTLSProtocol1);
- if (err == errSecSuccess)
- err = SSLSetProtocolVersionMax(context, kTLSProtocol1);
} else if (configuration.protocol == QSsl::SecureProtocols) {
#ifdef QSSLSOCKET_DEBUG
qCDebug(lcSsl) << plainSocket << "requesting : TLSv1 - TLSv1.2";
@@ -1213,8 +1165,6 @@ bool QSslSocketBackendPrivate::verifySessionProtocol() const
bool protocolOk = false;
if (configuration.protocol == QSsl::AnyProtocol)
protocolOk = true;
- else if (configuration.protocol == QSsl::TlsV1SslV3)
- protocolOk = (sessionProtocol() == QSsl::TlsV1_0);
else if (configuration.protocol == QSsl::SecureProtocols)
protocolOk = (sessionProtocol() >= QSsl::TlsV1_0);
else if (configuration.protocol == QSsl::TlsV1_0OrLater)
diff --git a/src/network/ssl/qsslsocket_openssl.cpp b/src/network/ssl/qsslsocket_openssl.cpp
index 8cd0724d83..11989cd2ef 100644
--- a/src/network/ssl/qsslsocket_openssl.cpp
+++ b/src/network/ssl/qsslsocket_openssl.cpp
@@ -92,11 +92,129 @@
#endif
#include <algorithm>
+#include <memory>
#include <string.h>
QT_BEGIN_NAMESPACE
+namespace {
+
+QAlertLevel tlsAlertLevel(int value)
+{
+ if (const char *typeString = q_SSL_alert_type_string(value)) {
+ // Documented to return 'W' for warning, 'F' for fatal,
+ // 'U' for unknown.
+ switch (typeString[0]) {
+ case 'W':
+ return QAlertLevel::Warning;
+ case 'F':
+ return QAlertLevel::Fatal;
+ default:;
+ }
+ }
+
+ return QAlertLevel::Unknown;
+}
+
+QString tlsAlertDescription(int value)
+{
+ QString description = QLatin1String(q_SSL_alert_desc_string_long(value));
+ if (!description.size())
+ description = QLatin1String("no description provided");
+ return description;
+}
+
+QAlertType tlsAlertType(int value)
+{
+ // In case for some reason openssl gives us a value,
+ // which is not in our enum actually, we leave it to
+ // an application to handle (supposedly they have
+ // if or switch-statements).
+ return QAlertType(value & 0xff);
+}
+
+} // Unnamed namespace
+
+extern "C"
+{
+
+void qt_AlertInfoCallback(const SSL *connection, int from, int value)
+{
+ // Passed to SSL_set_info_callback()
+ // https://www.openssl.org/docs/man1.1.1/man3/SSL_set_info_callback.html
+
+ if (!connection) {
+#ifdef QSSLSOCKET_DEBUG
+ qCWarning(lcSsl, "Invalid 'connection' parameter (nullptr)");
+#endif // QSSLSOCKET_DEBUG
+ return;
+ }
+
+ const auto offset = QSslSocketBackendPrivate::s_indexForSSLExtraData
+ + QSslSocketBackendPrivate::socketOffsetInExData;
+ auto privateSocket =
+ static_cast<QSslSocketBackendPrivate *>(q_SSL_get_ex_data(connection, offset));
+ if (!privateSocket) {
+ // SSL_set_ex_data can fail:
+#ifdef QSSLSOCKET_DEBUG
+ qCWarning(lcSsl, "No external data (socket backend) found for parameter 'connection'");
+#endif // QSSLSOCKET_DEBUG
+ return;
+ }
+
+ if (!(from & SSL_CB_ALERT)) {
+ // We only want to know about alerts (at least for now).
+ return;
+ }
+
+ if (from & SSL_CB_WRITE)
+ privateSocket->alertMessageSent(value);
+ else
+ privateSocket->alertMessageReceived(value);
+}
+
+int q_X509CallbackDirect(int ok, X509_STORE_CTX *ctx)
+{
+ // Passed to SSL_CTX_set_verify()
+ // https://www.openssl.org/docs/man1.1.1/man3/SSL_CTX_set_verify.html
+ // Returns 0 to abort verification, 1 to continue.
+
+ // This is a new, experimental verification callback, reporting
+ // errors immediately and returning 0 or 1 depending on an application
+ // either ignoring or not ignoring verification errors as they come.
+ if (!ctx) {
+ qCWarning(lcSsl, "Invalid store context (nullptr)");
+ return 0;
+ }
+
+ if (!ok) {
+ // "Whenever a X509_STORE_CTX object is created for the verification of the
+ // peer's certificate during a handshake, a pointer to the SSL object is
+ // stored into the X509_STORE_CTX object to identify the connection affected.
+ // To retrieve this pointer the X509_STORE_CTX_get_ex_data() function can be
+ // used with the correct index."
+ SSL *ssl = static_cast<SSL *>(q_X509_STORE_CTX_get_ex_data(ctx, q_SSL_get_ex_data_X509_STORE_CTX_idx()));
+ if (!ssl) {
+ qCWarning(lcSsl, "No external data (SSL) found in X509 store object");
+ return 0;
+ }
+
+ const auto offset = QSslSocketBackendPrivate::s_indexForSSLExtraData
+ + QSslSocketBackendPrivate::socketOffsetInExData;
+ auto privateSocket = static_cast<QSslSocketBackendPrivate *>(q_SSL_get_ex_data(ssl, offset));
+ if (!privateSocket) {
+ qCWarning(lcSsl, "No external data (QSslSocketBackendPrivate) found in SSL object");
+ return 0;
+ }
+
+ return privateSocket->emitErrorFromCallback(ctx);
+ }
+ return 1;
+}
+
+} // extern "C"
+
Q_GLOBAL_STATIC(QRecursiveMutex, qt_opensslInitMutex)
bool QSslSocketPrivate::s_libraryLoaded = false;
@@ -249,11 +367,7 @@ QSslCipher QSslSocketBackendPrivate::QSslCipher_from_SSL_CIPHER(const SSL_CIPHER
QString protoString = descriptionList.at(1).toString();
ciph.d->protocolString = protoString;
ciph.d->protocol = QSsl::UnknownProtocol;
- if (protoString == QLatin1String("SSLv3"))
- ciph.d->protocol = QSsl::SslV3;
- else if (protoString == QLatin1String("SSLv2"))
- ciph.d->protocol = QSsl::SslV2;
- else if (protoString == QLatin1String("TLSv1"))
+ if (protoString == QLatin1String("TLSv1"))
ciph.d->protocol = QSsl::TlsV1_0;
else if (protoString == QLatin1String("TLSv1.1"))
ciph.d->protocol = QSsl::TlsV1_1;
@@ -408,12 +522,15 @@ int q_X509Callback(int ok, X509_STORE_CTX *ctx)
// Not found on store? Try SSL and its external data then. According to the OpenSSL's
// documentation:
//
- // "Whenever a X509_STORE_CTX object is created for the verification of the peers certificate
- // during a handshake, a pointer to the SSL object is stored into the X509_STORE_CTX object
- // to identify the connection affected. To retrieve this pointer the X509_STORE_CTX_get_ex_data()
- // function can be used with the correct index."
+ // "Whenever a X509_STORE_CTX object is created for the verification of the
+ // peer's certificate during a handshake, a pointer to the SSL object is
+ // stored into the X509_STORE_CTX object to identify the connection affected.
+ // To retrieve this pointer the X509_STORE_CTX_get_ex_data() function can be
+ // used with the correct index."
+ const auto offset = QSslSocketBackendPrivate::s_indexForSSLExtraData
+ + QSslSocketBackendPrivate::errorOffsetInExData;
if (SSL *ssl = static_cast<SSL *>(q_X509_STORE_CTX_get_ex_data(ctx, q_SSL_get_ex_data_X509_STORE_CTX_idx())))
- errors = ErrorListPtr(q_SSL_get_ex_data(ssl, QSslSocketBackendPrivate::s_indexForSSLExtraData + 1));
+ errors = ErrorListPtr(q_SSL_get_ex_data(ssl, offset));
}
if (!errors) {
@@ -459,20 +576,23 @@ void q_setDefaultDtlsCiphers(const QList<QSslCipher> &ciphers);
long QSslSocketBackendPrivate::setupOpenSslOptions(QSsl::SslProtocol protocol, QSsl::SslOptions sslOptions)
{
long options;
- if (protocol == QSsl::TlsV1SslV3)
- options = SSL_OP_ALL|SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3;
- else if (protocol == QSsl::SecureProtocols)
- options = SSL_OP_ALL|SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3;
- else if (protocol == QSsl::TlsV1_0OrLater)
- options = SSL_OP_ALL|SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3;
- else if (protocol == QSsl::TlsV1_1OrLater)
- options = SSL_OP_ALL|SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1;
- else if (protocol == QSsl::TlsV1_2OrLater)
- options = SSL_OP_ALL|SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1|SSL_OP_NO_TLSv1_1;
- else if (protocol == QSsl::TlsV1_3OrLater)
- options = SSL_OP_ALL|SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1|SSL_OP_NO_TLSv1_1|SSL_OP_NO_TLSv1_2;
- else
+ switch (protocol) {
+ case QSsl::SecureProtocols:
+ case QSsl::TlsV1_0OrLater:
+ options = SSL_OP_ALL | SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3;
+ break;
+ case QSsl::TlsV1_1OrLater:
+ options = SSL_OP_ALL | SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1;
+ break;
+ case QSsl::TlsV1_2OrLater:
+ options = SSL_OP_ALL | SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1;
+ break;
+ case QSsl::TlsV1_3OrLater:
+ options = SSL_OP_ALL | SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1 | SSL_OP_NO_TLSv1_2;
+ break;
+ default:
options = SSL_OP_ALL;
+ }
// This option is disabled by default, so we need to be able to clear it
if (sslOptions & QSsl::SslOptionDisableEmptyFragments)
@@ -530,10 +650,7 @@ bool QSslSocketBackendPrivate::initSslContext()
return false;
}
- if (configuration.protocol != QSsl::SslV2 &&
- configuration.protocol != QSsl::SslV3 &&
- configuration.protocol != QSsl::UnknownProtocol &&
- mode == QSslSocket::SslClientMode) {
+ if (configuration.protocol != QSsl::UnknownProtocol && mode == QSslSocket::SslClientMode) {
// Set server hostname on TLS extension. RFC4366 section 3.1 requires it in ACE format.
QString tlsHostName = verificationPeerName.isEmpty() ? q->peerName() : verificationPeerName;
if (tlsHostName.isEmpty())
@@ -992,7 +1109,7 @@ void QSslSocketBackendPrivate::transmit()
if (actualWritten < 0) {
//plain socket write fails if it was in the pending close state.
const ScopedBool bg(inSetAndEmitError, true);
- setErrorAndEmit(plainSocket->error(), plainSocket->errorString());
+ setErrorAndEmit(plainSocket->socketError(), plainSocket->errorString());
return;
}
transmitting = true;
@@ -1199,18 +1316,32 @@ bool QSslSocketBackendPrivate::startHandshake()
if (inSetAndEmitError)
return false;
+ pendingFatalAlert = false;
+ errorsReportedFromCallback = false;
QVector<QSslErrorEntry> lastErrors;
- q_SSL_set_ex_data(ssl, s_indexForSSLExtraData + 1, &lastErrors);
+ q_SSL_set_ex_data(ssl, s_indexForSSLExtraData + errorOffsetInExData, &lastErrors);
+
+ // SSL_set_ex_data can fail, but see the callback's code - we handle this there.
+ q_SSL_set_ex_data(ssl, s_indexForSSLExtraData + socketOffsetInExData, this);
+ q_SSL_set_info_callback(ssl, qt_AlertInfoCallback);
+
int result = (mode == QSslSocket::SslClientMode) ? q_SSL_connect(ssl) : q_SSL_accept(ssl);
- q_SSL_set_ex_data(ssl, s_indexForSSLExtraData + 1, nullptr);
+ q_SSL_set_ex_data(ssl, s_indexForSSLExtraData + errorOffsetInExData, nullptr);
+ // Note, unlike errors as external data on SSL object, we do not unset
+ // a callback/ex-data if alert notifications are enabled: an alert can
+ // arrive after the handshake, for example, this happens when the server
+ // does not find a ClientCert or does not like it.
- if (!lastErrors.isEmpty())
+ if (!lastErrors.isEmpty() || errorsReportedFromCallback)
storePeerCertificates();
- for (const auto &currentError : qAsConst(lastErrors)) {
- emit q->peerVerifyError(_q_OpenSSL_to_QSslError(currentError.code,
- configuration.peerCertificateChain.value(currentError.depth)));
- if (q->state() != QAbstractSocket::ConnectedState)
- break;
+
+ if (!errorsReportedFromCallback) {
+ for (const auto &currentError : qAsConst(lastErrors)) {
+ emit q->peerVerifyError(_q_OpenSSL_to_QSslError(currentError.code,
+ configuration.peerCertificateChain.value(currentError.depth)));
+ if (q->state() != QAbstractSocket::ConnectedState)
+ break;
+ }
}
errorList << lastErrors;
@@ -1234,6 +1365,10 @@ bool QSslSocketBackendPrivate::startHandshake()
{
const ScopedBool bg(inSetAndEmitError, true);
setErrorAndEmit(QAbstractSocket::SslHandshakeFailedError, errorString);
+ if (pendingFatalAlert) {
+ trySendFatalAlert();
+ pendingFatalAlert = false;
+ }
}
q->abort();
}
@@ -1703,6 +1838,88 @@ bool QSslSocketBackendPrivate::checkOcspStatus()
#endif // ocsp
+void QSslSocketBackendPrivate::alertMessageSent(int value)
+{
+ Q_Q(QSslSocket);
+
+ const auto level = tlsAlertLevel(value);
+ if (level == QAlertLevel::Fatal && !connectionEncrypted) {
+ // Note, this logic is handshake-time only:
+ pendingFatalAlert = true;
+ }
+
+ emit q->alertSent(level, tlsAlertType(value), tlsAlertDescription(value));
+}
+
+void QSslSocketBackendPrivate::alertMessageReceived(int value)
+{
+ Q_Q(QSslSocket);
+
+ emit q->alertReceived(tlsAlertLevel(value), tlsAlertType(value), tlsAlertDescription(value));
+}
+
+int QSslSocketBackendPrivate::emitErrorFromCallback(X509_STORE_CTX *ctx)
+{
+ // Returns 0 to abort verification, 1 to continue despite error (as
+ // OpenSSL expects from the verification callback).
+ Q_Q(QSslSocket);
+
+ Q_ASSERT(ctx);
+
+ using ScopedBool = QScopedValueRollback<bool>;
+ // While we are not setting, we are emitting and in general -
+ // we want to prevent accidental recursive startHandshake()
+ // calls:
+ const ScopedBool bg(inSetAndEmitError, true);
+
+ X509 *x509 = q_X509_STORE_CTX_get_current_cert(ctx);
+ if (!x509) {
+ qCWarning(lcSsl, "Could not obtain the certificate (that failed to verify)");
+ return 0;
+ }
+ const QSslCertificate certificate = QSslCertificatePrivate::QSslCertificate_from_X509(x509);
+
+ const auto errorAndDepth = QSslErrorEntry::fromStoreContext(ctx);
+ const QSslError tlsError = _q_OpenSSL_to_QSslError(errorAndDepth.code, certificate);
+
+ errorsReportedFromCallback = true;
+ handshakeInterrupted = true;
+ emit q->handshakeInterruptedOnError(tlsError);
+
+ // Conveniently so, we also can access 'lastErrors' external data set
+ // in startHandshake, we store it for the case an application later
+ // wants to check errors (ignored or not):
+ const auto offset = QSslSocketBackendPrivate::s_indexForSSLExtraData
+ + QSslSocketBackendPrivate::errorOffsetInExData;
+ if (auto errorList = static_cast<QVector<QSslErrorEntry>*>(q_SSL_get_ex_data(ssl, offset)))
+ errorList->append(errorAndDepth);
+
+ // An application is expected to ignore this error (by calling ignoreSslErrors)
+ // in its directly connected slot:
+ return !handshakeInterrupted;
+}
+
+void QSslSocketBackendPrivate::trySendFatalAlert()
+{
+ Q_ASSERT(pendingFatalAlert);
+
+ pendingFatalAlert = false;
+ QVarLengthArray<char, 4096> data;
+ int pendingBytes = 0;
+ while (plainSocket->isValid() && (pendingBytes = q_BIO_pending(writeBio)) > 0
+ && plainSocket->openMode() != QIODevice::NotOpen) {
+ // Read encrypted data from the write BIO into a buffer.
+ data.resize(pendingBytes);
+ const int bioReadBytes = q_BIO_read(writeBio, data.data(), pendingBytes);
+
+ // Write encrypted data from the buffer to the socket.
+ qint64 actualWritten = plainSocket->write(data.constData(), bioReadBytes);
+ if (actualWritten < 0)
+ return;
+ plainSocket->flush();
+ }
+}
+
void QSslSocketBackendPrivate::disconnectFromHost()
{
if (ssl) {
@@ -1746,10 +1963,6 @@ QSsl::SslProtocol QSslSocketBackendPrivate::sessionProtocol() const
int ver = q_SSL_version(ssl);
switch (ver) {
- case 0x2:
- return QSsl::SslV2;
- case 0x300:
- return QSsl::SslV3;
case 0x301:
return QSsl::TlsV1_0;
case 0x302:
@@ -1957,6 +2170,7 @@ QList<QSslError> QSslSocketBackendPrivate::verify(const QList<QSslCertificate> &
errors << QSslError(QSslError::UnspecifiedError);
return errors;
}
+ const std::unique_ptr<X509_STORE, decltype(&q_X509_STORE_free)> storeGuard(certStore, q_X509_STORE_free);
if (s_loadRootCertsOnDemand) {
setDefaultCaCertificates(defaultCaCertificates() + systemCaCertificates());
@@ -1997,7 +2211,6 @@ QList<QSslError> QSslSocketBackendPrivate::verify(const QList<QSslCertificate> &
intermediates = (STACK_OF(X509) *) q_OPENSSL_sk_new_null();
if (!intermediates) {
- q_X509_STORE_free(certStore);
errors << QSslError(QSslError::UnspecifiedError);
return errors;
}
@@ -2015,14 +2228,12 @@ QList<QSslError> QSslSocketBackendPrivate::verify(const QList<QSslCertificate> &
X509_STORE_CTX *storeContext = q_X509_STORE_CTX_new();
if (!storeContext) {
- q_X509_STORE_free(certStore);
errors << QSslError(QSslError::UnspecifiedError);
return errors;
}
+ std::unique_ptr<X509_STORE_CTX, decltype(&q_X509_STORE_CTX_free)> ctxGuard(storeContext, q_X509_STORE_CTX_free);
if (!q_X509_STORE_CTX_init(storeContext, certStore, reinterpret_cast<X509 *>(certificateChain[0].handle()), intermediates)) {
- q_X509_STORE_CTX_free(storeContext);
- q_X509_STORE_free(certStore);
errors << QSslError(QSslError::UnspecifiedError);
return errors;
}
@@ -2031,8 +2242,7 @@ QList<QSslError> QSslSocketBackendPrivate::verify(const QList<QSslCertificate> &
// We ignore the result of this function since we process errors via the
// callback.
(void) q_X509_verify_cert(storeContext);
-
- q_X509_STORE_CTX_free(storeContext);
+ ctxGuard.reset();
q_OPENSSL_sk_free((OPENSSL_STACK *)intermediates);
// Now process the errors
@@ -2054,8 +2264,6 @@ QList<QSslError> QSslSocketBackendPrivate::verify(const QList<QSslCertificate> &
for (const auto &error : qAsConst(lastErrors))
errors << _q_OpenSSL_to_QSslError(error.code, certificateChain.value(error.depth));
- q_X509_STORE_free(certStore);
-
return errors;
}
diff --git a/src/network/ssl/qsslsocket_openssl_p.h b/src/network/ssl/qsslsocket_openssl_p.h
index 0370a7d2ac..06af9f5974 100644
--- a/src/network/ssl/qsslsocket_openssl_p.h
+++ b/src/network/ssl/qsslsocket_openssl_p.h
@@ -131,6 +131,10 @@ public:
SSL_SESSION *session;
QVector<QSslErrorEntry> errorList;
static int s_indexForSSLExtraData; // index used in SSL_get_ex_data to get the matching QSslSocketBackendPrivate
+ enum ExDataOffset {
+ errorOffsetInExData = 1,
+ socketOffsetInExData = 2
+ };
bool inSetAndEmitError = false;
@@ -157,6 +161,15 @@ public:
bool checkOcspStatus();
#endif
+ void alertMessageSent(int encoded);
+ void alertMessageReceived(int encoded);
+
+ int emitErrorFromCallback(X509_STORE_CTX *ctx);
+ void trySendFatalAlert();
+
+ bool pendingFatalAlert = false;
+ bool errorsReportedFromCallback = false;
+
// This decription will go to setErrorAndEmit(SslHandshakeError, ocspErrorDescription)
QString ocspErrorDescription;
// These will go to sslErrors()
diff --git a/src/network/ssl/qsslsocket_openssl_symbols.cpp b/src/network/ssl/qsslsocket_openssl_symbols.cpp
index 3504924888..5b0a70d495 100644
--- a/src/network/ssl/qsslsocket_openssl_symbols.cpp
+++ b/src/network/ssl/qsslsocket_openssl_symbols.cpp
@@ -156,6 +156,10 @@ DEFINEFUNC(void, OPENSSL_sk_free, OPENSSL_STACK *a, a, return, DUMMYARG)
DEFINEFUNC2(void *, OPENSSL_sk_value, OPENSSL_STACK *a, a, int b, b, return nullptr, return)
DEFINEFUNC(int, SSL_session_reused, SSL *a, a, return 0, return)
DEFINEFUNC2(unsigned long, SSL_CTX_set_options, SSL_CTX *ctx, ctx, unsigned long op, op, return 0, return)
+using info_callback = void (*) (const SSL *ssl, int type, int val);
+DEFINEFUNC2(void, SSL_set_info_callback, SSL *ssl, ssl, info_callback cb, cb, return, return)
+DEFINEFUNC(const char *, SSL_alert_type_string, int value, value, return nullptr, return)
+DEFINEFUNC(const char *, SSL_alert_desc_string_long, int value, value, return nullptr, return)
#ifdef TLS1_3_VERSION
DEFINEFUNC2(int, SSL_CTX_set_ciphersuites, SSL_CTX *ctx, ctx, const char *str, str, return 0, return)
DEFINEFUNC2(void, SSL_set_psk_use_session_callback, SSL *ssl, ssl, q_SSL_psk_use_session_cb_func_t callback, callback, return, DUMMYARG)
@@ -839,7 +843,9 @@ bool q_resolveOpenSslSymbols()
RESOLVEFUNC(OPENSSL_sk_value)
RESOLVEFUNC(DH_get0_pqg)
RESOLVEFUNC(SSL_CTX_set_options)
-
+ RESOLVEFUNC(SSL_set_info_callback)
+ RESOLVEFUNC(SSL_alert_type_string)
+ RESOLVEFUNC(SSL_alert_desc_string_long)
#ifdef TLS1_3_VERSION
RESOLVEFUNC(SSL_CTX_set_ciphersuites)
RESOLVEFUNC(SSL_set_psk_use_session_callback)
diff --git a/src/network/ssl/qsslsocket_openssl_symbols_p.h b/src/network/ssl/qsslsocket_openssl_symbols_p.h
index baf1a43113..ac6aa1760f 100644
--- a/src/network/ssl/qsslsocket_openssl_symbols_p.h
+++ b/src/network/ssl/qsslsocket_openssl_symbols_p.h
@@ -719,6 +719,10 @@ int q_OCSP_id_cmp(OCSP_CERTID *a, OCSP_CERTID *b);
void *q_CRYPTO_malloc(size_t num, const char *file, int line);
#define q_OPENSSL_malloc(num) q_CRYPTO_malloc(num, "", 0)
+void q_SSL_set_info_callback(SSL *ssl, void (*cb) (const SSL *ssl, int type, int val));
+const char *q_SSL_alert_type_string(int value);
+const char *q_SSL_alert_desc_string_long(int value);
+
QT_END_NAMESPACE
#endif
diff --git a/src/network/ssl/qsslsocket_p.h b/src/network/ssl/qsslsocket_p.h
index 1abd18bb32..4b020b6a73 100644
--- a/src/network/ssl/qsslsocket_p.h
+++ b/src/network/ssl/qsslsocket_p.h
@@ -208,6 +208,7 @@ protected:
bool paused;
bool flushTriggered;
QVector<QOcspResponse> ocspResponses;
+ bool handshakeInterrupted = false;
};
#if QT_CONFIG(securetransport) || QT_CONFIG(schannel)
diff --git a/src/network/ssl/qsslsocket_schannel.cpp b/src/network/ssl/qsslsocket_schannel.cpp
index 78d807106b..ba15a0a65e 100644
--- a/src/network/ssl/qsslsocket_schannel.cpp
+++ b/src/network/ssl/qsslsocket_schannel.cpp
@@ -226,12 +226,6 @@ DWORD toSchannelProtocol(QSsl::SslProtocol protocol)
protocols = SP_PROT_TLS1_0 | SP_PROT_TLS1_1 | SP_PROT_TLS1_2;
// @future Add TLS 1.3 when supported by Windows!
break;
- case QSsl::SslV2:
- case QSsl::SslV3:
- return DWORD(-1); // Not supported
- case QSsl::TlsV1SslV3:
- protocols = SP_PROT_TLS1_0;
- break;
case QSsl::TlsV1_0:
protocols = SP_PROT_TLS1_0;
break;
@@ -582,7 +576,7 @@ bool QSslSocketBackendPrivate::sendToken(void *token, unsigned long tokenLength,
if (written != qint64(tokenLength)) {
// Failed to write/buffer everything or an error occurred
if (emitError)
- setErrorAndEmit(plainSocket->error(), plainSocket->errorString());
+ setErrorAndEmit(plainSocket->socketError(), plainSocket->errorString());
return false;
}
return true;
@@ -1030,6 +1024,7 @@ bool QSslSocketBackendPrivate::performHandshake()
bool QSslSocketBackendPrivate::verifyHandshake()
{
Q_Q(QSslSocket);
+ sslErrors.clear();
const bool isClient = mode == QSslSocket::SslClientMode;
#define CHECK_STATUS(status) \
@@ -1118,7 +1113,7 @@ bool QSslSocketBackendPrivate::verifyHandshake()
}
// verifyCertContext returns false if the user disconnected while it was checking errors.
- if (certificateContext && sslErrors.isEmpty() && !verifyCertContext(certificateContext))
+ if (certificateContext && !verifyCertContext(certificateContext))
return false;
if (!checkSslErrors() || state != QAbstractSocket::ConnectedState) {
@@ -1291,7 +1286,7 @@ void QSslSocketBackendPrivate::transmit()
if (bytesWritten >= 0) {
totalBytesWritten += bytesWritten;
} else {
- setErrorAndEmit(plainSocket->error(), plainSocket->errorString());
+ setErrorAndEmit(plainSocket->socketError(), plainSocket->errorString());
return;
}
}
diff --git a/src/network/ssl/qsslsocket_winrt.cpp b/src/network/ssl/qsslsocket_winrt.cpp
index 4286b5ea42..5f5201fc82 100644
--- a/src/network/ssl/qsslsocket_winrt.cpp
+++ b/src/network/ssl/qsslsocket_winrt.cpp
@@ -230,13 +230,7 @@ void QSslSocketBackendPrivate::startClientEncryption()
QSsl::SslProtocol protocol = q->protocol();
switch (q->protocol()) {
- case QSsl::SslV2:
- case QSsl::SslV3:
- setErrorAndEmit(QAbstractSocket::SslInvalidUserDataError,
- QStringLiteral("unsupported protocol"));
- return;
case QSsl::AnyProtocol:
- case QSsl::TlsV1SslV3:
protectionLevel = SocketProtectionLevel_Tls10;
break;
case QSsl::TlsV1_0:
diff --git a/src/network/ssl/ssl.pri b/src/network/ssl/ssl.pri
index 0c8b9ccd40..dfbf539303 100644
--- a/src/network/ssl/ssl.pri
+++ b/src/network/ssl/ssl.pri
@@ -115,9 +115,11 @@ qtConfig(ssl) {
# - libs in <OPENSSL_DIR>\lib\VC\static
# - configure: -openssl -openssl-linked -I <OPENSSL_DIR>\include -L <OPENSSL_DIR>\lib\VC\static OPENSSL_LIBS="-lUser32 -lAdvapi32 -lGdi32" OPENSSL_LIBS_DEBUG="-lssleay32MDd -llibeay32MDd" OPENSSL_LIBS_RELEASE="-lssleay32MD -llibeay32MD"
- qtConfig(openssl-linked): \
- QMAKE_USE_FOR_PRIVATE += openssl
- else: \
+ qtConfig(openssl-linked): {
+ android {
+ build_pass: LIBS_PRIVATE += -lssl_$${QT_ARCH} -lcrypto_$${QT_ARCH}
+ } else: QMAKE_USE_FOR_PRIVATE += openssl
+ } else: \
QMAKE_USE_FOR_PRIVATE += openssl/nolink
win32 {
LIBS_PRIVATE += -lcrypt32