Skip to content
Permalink
Browse files

Review comments

  • Loading branch information
nyalldawson committed Jan 28, 2019
1 parent 0f0ee9b commit 54d6a6cffe6b369120bb9eb3b42073803bfeb0e6
@@ -72,11 +72,8 @@ void QgsAppSslErrorHandler::handleSslErrors( QNetworkReply *reply, const QList<Q
dlg->resize( 580, 512 );
if ( dlg->exec() )
{
if ( reply )
{
QgsDebugMsg( QStringLiteral( "All SSL errors ignored for %1" ).arg( hostport ) );
reply->ignoreSslErrors();
}
QgsDebugMsg( QStringLiteral( "All SSL errors ignored for %1" ).arg( hostport ) );
reply->ignoreSslErrors();
}
dlg->deleteLater();
}
@@ -17,7 +17,7 @@

#include "qgsnetworkaccessmanager.h"

class CORE_EXPORT QgsAppSslErrorHandler : public QgsSslErrorHandler
class QgsAppSslErrorHandler : public QgsSslErrorHandler
{
Q_OBJECT

@@ -259,7 +259,7 @@ QNetworkReply *QgsNetworkAccessManager::createRequest( QNetworkAccessManager::Op
void QgsNetworkAccessManager::unlockAfterSslErrorHandled()
{
Q_ASSERT( QThread::currentThread() == QApplication::instance()->thread() );
mSslWaitCondition.wakeAll();
mSslErrorWaitCondition.wakeOne();
}

void QgsNetworkAccessManager::abortRequest()
@@ -312,14 +312,16 @@ void QgsNetworkAccessManager::onReplySslErrors( const QList<QSslError> &errors )
if ( ok )
emit requestEncounteredSslErrors( requestId, errors );

// in main thread this will trigger SSL error handler immediately and return once the errors are handled,
// while in worker thread the signal will be queued (and return immediately) -- hence the need to lock the thread in the next block
emit sslErrorsOccurred( reply, errors );
if ( this != sMainNAM )
{
// lock thread and wait till error is handled. If we return from this slot now, then the reply will resume
// without actually giving the main thread the chance to act on the ssl error and possibly ignore it.
mMutex.lock();
mSslWaitCondition.wait( &mMutex );
mMutex.unlock();
mSslErrorHandlerMutex.lock();
mSslErrorWaitCondition.wait( &mSslErrorHandlerMutex );
mSslErrorHandlerMutex.unlock();
afterSslErrorHandled( reply );
}
}
@@ -151,6 +151,9 @@ class QgsNetworkAccessManager;
* present prompts to users notifying them of the errors and asking them
* to choose the appropriate response.).
*
* If a reply is coming from background thread, that thread is blocked while handleSslErrors()
* is running.
*
* If the errors should be ignored and the request allowed to proceed, the subclasses'
* handleSslErrors() method MUST call QNetworkReply::ignoreSslErrors() on the specified
* QNetworkReply object.
@@ -427,9 +430,12 @@ class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager
bool mUseSystemProxy = false;
bool mInitialized = false;
static QgsNetworkAccessManager *sMainNAM;
// ssl error handler, will be set for main thread ONLY
std::unique_ptr< QgsSslErrorHandler > mSslErrorHandler;
QMutex mMutex;
QWaitCondition mSslWaitCondition;
// only in use by work threads, unused in main thread
QMutex mSslErrorHandlerMutex;
// only in use by work threads, unused in main thread
QWaitCondition mSslErrorWaitCondition;
};

#endif // QGSNETWORKACCESSMANAGER_H

0 comments on commit 54d6a6c

Please sign in to comment.
You can’t perform that action at this time.