summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
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.cpp4
-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.cpp6
-rw-r--r--src/network/access/qnetworkaccessfilebackend.cpp6
-rw-r--r--src/network/access/qnetworkaccessftpbackend.cpp12
-rw-r--r--src/network/access/qnetworkcookie.cpp2
-rw-r--r--src/network/access/qnetworkdiskcache.cpp22
-rw-r--r--src/network/access/qnetworkreplyfileimpl.cpp2
-rw-r--r--src/network/access/qnetworkreplyimpl.cpp26
-rw-r--r--src/network/access/qnetworkrequest.cpp6
-rw-r--r--src/network/access/qspdyprotocolhandler.cpp1304
-rw-r--r--src/network/bearer/qnetworkconfigmanager.cpp2
-rw-r--r--src/network/bearer/qnetworkconfigmanager_p.cpp4
-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/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.cpp4
-rw-r--r--src/network/kernel/qhostinfo_unix.cpp8
-rw-r--r--src/network/kernel/qnetworkinterface.cpp2
-rw-r--r--src/network/kernel/qnetworkproxy.cpp12
-rw-r--r--src/network/kernel/qurlinfo.cpp10
-rw-r--r--src/network/socket/qabstractsocket.cpp6
-rw-r--r--src/network/socket/qabstractsocketengine.cpp6
-rw-r--r--src/network/socket/qhttpsocketengine.cpp16
-rw-r--r--src/network/socket/qlocalserver.cpp2
-rw-r--r--src/network/socket/qlocalserver_unix.cpp2
-rw-r--r--src/network/socket/qlocalsocket.cpp2
-rw-r--r--src/network/socket/qlocalsocket_unix.cpp8
-rw-r--r--src/network/socket/qnativesocketengine.cpp12
-rw-r--r--src/network/socket/qnativesocketengine_unix.cpp6
-rw-r--r--src/network/socket/qsocks5socketengine.cpp28
-rw-r--r--src/network/socket/qtcpserver.cpp6
46 files changed, 1494 insertions, 190 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..d39589fb96 100644
--- a/src/network/access/qhttpprotocolhandler.cpp
+++ b/src/network/access/qhttpprotocolhandler.cpp
@@ -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..03ffc69628 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 {
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/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/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/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 c5bbba8216..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;
}
/*!
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 c2d30d52e2..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();
}
diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp
index 252b88d36a..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)
{
@@ -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/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..31671feece 100644
--- a/src/network/kernel/qhostinfo.cpp
+++ b/src/network/kernel/qhostinfo.cpp
@@ -410,7 +410,7 @@ QHostInfo QHostInfoAgent::reverseLookup(const QHostAddress &address)
// 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 +455,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;
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 b7a6d9adf9..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)
{
}
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 e48fbea3b6..cbc4114904 100644
--- a/src/network/socket/qabstractsocket.cpp
+++ b/src/network/socket/qabstractsocket.cpp
@@ -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)
diff --git a/src/network/socket/qabstractsocketengine.cpp b/src/network/socket/qabstractsocketengine.cpp
index 3fffff6d5a..54c7452c66 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 c67b273937..76b3053224 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;
}
}
@@ -586,7 +586,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 +829,8 @@ QHttpSocketEnginePrivate::QHttpSocketEnginePrivate()
, credentialsSent(false)
, pendingResponseData(0)
{
- socket = 0;
- reply = 0;
+ socket = nullptr;
+ reply = nullptr;
state = QHttpSocketEngine::None;
}
@@ -843,15 +843,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 +860,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 af7cdb76d2..d35f838af5 100644
--- a/src/network/socket/qlocalsocket.cpp
+++ b/src/network/socket/qlocalsocket.cpp
@@ -372,7 +372,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
}
diff --git a/src/network/socket/qlocalsocket_unix.cpp b/src/network/socket/qlocalsocket_unix.cpp
index 3a571edc3a..7de9a7d4c7 100644
--- a/src/network/socket/qlocalsocket_unix.cpp
+++ b/src/network/socket/qlocalsocket_unix.cpp
@@ -61,8 +61,8 @@
QT_BEGIN_NAMESPACE
QLocalSocketPrivate::QLocalSocketPrivate() : QIODevicePrivate(),
- delayConnect(0),
- connectTimer(0),
+ delayConnect(nullptr),
+ connectTimer(nullptr),
connectingSocket(-1),
state(QLocalSocket::UnconnectedState)
{
@@ -379,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;
}
}
diff --git a/src/network/socket/qnativesocketengine.cpp b/src/network/socket/qnativesocketengine.cpp
index f3ca2afdc8..31628846dc 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;
}
}
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 8a030601dc..622d5df131 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)
@@ -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;
@@ -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
@@ -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");