Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Review comments
  • Loading branch information
nyalldawson committed Jan 28, 2019
1 parent 0f0ee9b commit 54d6a6c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
7 changes: 2 additions & 5 deletions src/app/qgsappsslerrorhandler.cpp
Expand Up @@ -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();
}
2 changes: 1 addition & 1 deletion src/app/qgsappsslerrorhandler.h
Expand Up @@ -17,7 +17,7 @@

#include "qgsnetworkaccessmanager.h"

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

Expand Down
10 changes: 6 additions & 4 deletions src/core/qgsnetworkaccessmanager.cpp
Expand Up @@ -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()
Expand Down Expand Up @@ -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 );
}
}
Expand Down
10 changes: 8 additions & 2 deletions src/core/qgsnetworkaccessmanager.h
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 54d6a6c

Please sign in to comment.