summaryrefslogtreecommitdiffstats
path: root/src/network/ssl/qsslsocket.cpp
diff options
context:
space:
mode:
authorPeter Hartmann <peter.hartmann@nokia.com>2012-01-20 13:55:15 +0100
committerQt by Nokia <qt-info@nokia.com>2012-01-25 19:35:05 +0100
commit07662f93ac700d18bf2c7f5e3df1fa310327130d (patch)
tree8a1a81ab5d9e905b3e09f83673777fb8b4b1e978 /src/network/ssl/qsslsocket.cpp
parent0da4451b783b02d6df464fba9f0c34828df1ac06 (diff)
QAbstractSocket / QSslSocket: add API to pause and resume
pause and resume is currently only supported upon emitting the QSslSocket::sslErrors() signal. The API was added in QAbstractSocket to also support QAbstractSocket::proxyAuthenticationRequired() in the future. This is the first patch to support that feature on the socket level, another patch will follow to support sslErrors() and authenticationRequired() in QNetworkAccessManager / QNetworkReply. Task-number: QTBUG-19032 Change-Id: Ide2918268590ab9a01454ab26cb7fdca3dc840ab Reviewed-by: Shane Kearns <ext-shane.2.kearns@nokia.com>
Diffstat (limited to 'src/network/ssl/qsslsocket.cpp')
-rw-r--r--src/network/ssl/qsslsocket.cpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/network/ssl/qsslsocket.cpp b/src/network/ssl/qsslsocket.cpp
index 77eab192df..7240444572 100644
--- a/src/network/ssl/qsslsocket.cpp
+++ b/src/network/ssl/qsslsocket.cpp
@@ -356,6 +356,24 @@ QSslSocket::~QSslSocket()
}
/*!
+ \reimp
+
+ \since 5.0
+
+ Continues data transfer on the socket after it has been paused. If
+ "setPauseMode(QAbstractSocket::PauseOnNotify);" has been called on
+ this socket and a sslErrors() signal is received, calling this method
+ is necessary for the socket to continue.
+
+ \sa QAbstractSocket::pauseMode(), QAbstractSocket::setPauseMode()
+*/
+void QSslSocket::resume()
+{
+ // continuing might emit signals, rather do this through the event loop
+ QMetaObject::invokeMethod(this, "_q_resumeImplementation", Qt::QueuedConnection);
+}
+
+/*!
Starts an encrypted connection to the device \a hostName on \a
port, using \a mode as the \l OpenMode. This is equivalent to
calling connectToHost() to establish the connection, followed by a
@@ -1860,6 +1878,7 @@ QSslSocketPrivate::QSslSocketPrivate()
, readyReadEmittedPointer(0)
, allowRootCertOnDemandLoading(true)
, plainSocket(0)
+ , paused(false)
{
QSslConfigurationPrivate::deepCopyDefaultConfiguration(&configuration);
}
@@ -2114,6 +2133,11 @@ void QSslSocketPrivate::resumeSocketNotifiers(QSslSocket *socket)
QAbstractSocketPrivate::resumeSocketNotifiers(socket->d_func()->plainSocket);
}
+bool QSslSocketPrivate::isPaused() const
+{
+ return paused;
+}
+
/*!
\internal
*/
@@ -2260,6 +2284,55 @@ void QSslSocketPrivate::_q_flushReadBuffer()
/*!
\internal
*/
+void QSslSocketPrivate::_q_resumeImplementation()
+{
+ Q_Q(QSslSocket);
+ if (plainSocket)
+ plainSocket->resume();
+ paused = false;
+ if (!connectionEncrypted) {
+ if (verifyErrorsHaveBeenIgnored()) {
+ continueHandshake();
+ } else {
+ q->setErrorString(sslErrors.first().errorString());
+ q->setSocketError(QAbstractSocket::SslHandshakeFailedError);
+ emit q->error(QAbstractSocket::SslHandshakeFailedError);
+ plainSocket->disconnectFromHost();
+ return;
+ }
+ }
+ transmit();
+}
+
+/*!
+ \internal
+*/
+bool QSslSocketPrivate::verifyErrorsHaveBeenIgnored()
+{
+ bool doEmitSslError;
+ if (!ignoreErrorsList.empty()) {
+ // check whether the errors we got are all in the list of expected errors
+ // (applies only if the method QSslSocket::ignoreSslErrors(const QList<QSslError> &errors)
+ // was called)
+ doEmitSslError = false;
+ for (int a = 0; a < sslErrors.count(); a++) {
+ if (!ignoreErrorsList.contains(sslErrors.at(a))) {
+ doEmitSslError = true;
+ break;
+ }
+ }
+ } else {
+ // if QSslSocket::ignoreSslErrors(const QList<QSslError> &errors) was not called and
+ // we get an SSL error, emit a signal unless we ignored all errors (by calling
+ // QSslSocket::ignoreSslErrors() )
+ doEmitSslError = !ignoreAllSslErrors;
+ }
+ return !doEmitSslError;
+}
+
+/*!
+ \internal
+*/
QList<QByteArray> QSslSocketPrivate::unixRootCertDirectories()
{
return QList<QByteArray>() << "/etc/ssl/certs/" // (K)ubuntu, OpenSUSE, Mandriva, MeeGo ...