From c441020f105249458c389cc167d70f36b39ea28e Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Wed, 17 Jun 2009 09:03:57 +0200 Subject: QNAM: Use QTcpSocket for HTTP if no encryption was requested This stops QNetworkAccessManager from loading the OpenSSL libs, certificates etc. when they are not needed for the non-HTTPS case. Reviewed-by: mariusSO --- src/network/access/qhttpnetworkconnection.cpp | 35 ++++++++++++++++++++------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index c7a3d71..cfce735 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -113,12 +113,15 @@ void QHttpNetworkConnectionPrivate::connectSignals(QAbstractSocket *socket) #ifndef QT_NO_OPENSSL QSslSocket *sslSocket = qobject_cast(socket); - QObject::connect(sslSocket, SIGNAL(encrypted()), - q, SLOT(_q_encrypted()), - Qt::DirectConnection); - QObject::connect(sslSocket, SIGNAL(sslErrors(const QList&)), - q, SLOT(_q_sslErrors(const QList&)), - Qt::DirectConnection); + if (sslSocket) { + // won't be a sslSocket if encrypt is false + QObject::connect(sslSocket, SIGNAL(encrypted()), + q, SLOT(_q_encrypted()), + Qt::DirectConnection); + QObject::connect(sslSocket, SIGNAL(sslErrors(const QList&)), + q, SLOT(_q_sslErrors(const QList&)), + Qt::DirectConnection); + } #endif } @@ -126,10 +129,14 @@ void QHttpNetworkConnectionPrivate::init() { for (int i = 0; i < channelCount; ++i) { #ifndef QT_NO_OPENSSL - channels[i].socket = new QSslSocket; + if (encrypt) + channels[i].socket = new QSslSocket; + else + channels[i].socket = new QTcpSocket; #else channels[i].socket = new QTcpSocket; #endif + connectSignals(channels[i].socket); } } @@ -404,8 +411,9 @@ bool QHttpNetworkConnectionPrivate::sendRequest(QAbstractSocket *socket) #ifndef QT_NO_OPENSSL QSslSocket *sslSocket = qobject_cast(socket); - while ((sslSocket->encryptedBytesToWrite() + sslSocket->bytesToWrite()) <= socketBufferFill - && channels[i].bytesTotal != channels[i].written) + // if it is really an ssl socket, check more than just bytesToWrite() + while ((socket->bytesToWrite() + (sslSocket ? sslSocket->encryptedBytesToWrite() : 0)) + <= socketBufferFill && channels[i].bytesTotal != channels[i].written) #else while (socket->bytesToWrite() <= socketBufferFill && channels[i].bytesTotal != channels[i].written) @@ -1355,6 +1363,9 @@ void QHttpNetworkConnectionPrivate::_q_sslErrors(const QList &errors) QSslConfiguration QHttpNetworkConnectionPrivate::sslConfiguration(const QHttpNetworkReply &reply) const { + if (!encrypt) + return QSslConfiguration(); + for (int i = 0; i < channelCount; ++i) if (channels[i].reply == &reply) return static_cast(channels[0].socket)->sslConfiguration(); @@ -1364,6 +1375,9 @@ QSslConfiguration QHttpNetworkConnectionPrivate::sslConfiguration(const QHttpNet void QHttpNetworkConnection::setSslConfiguration(const QSslConfiguration &config) { Q_D(QHttpNetworkConnection); + if (!d->encrypt) + return; + // set the config on all channels for (int i = 0; i < d->channelCount; ++i) static_cast(d->channels[i].socket)->setSslConfiguration(config); @@ -1372,6 +1386,9 @@ void QHttpNetworkConnection::setSslConfiguration(const QSslConfiguration &config void QHttpNetworkConnection::ignoreSslErrors(int channel) { Q_D(QHttpNetworkConnection); + if (!d->encrypt) + return; + if (channel == -1) { // ignore for all channels for (int i = 0; i < d->channelCount; ++i) { static_cast(d->channels[i].socket)->ignoreSslErrors(); -- cgit v0.12