Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[auth] Morph the mutex from a pointer to a member var
  • Loading branch information
elpaso committed Nov 16, 2017
1 parent 674467b commit 6f06597
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 39 deletions.
5 changes: 0 additions & 5 deletions python/core/auth/qgsauthmethod.sip
Expand Up @@ -34,11 +34,6 @@ class QgsAuthMethod : QObject
typedef QFlags<QgsAuthMethod::Expansion> Expansions;


~QgsAuthMethod();
%Docstring
Destructor: delete the mutex
%End

virtual QString key() const = 0;
%Docstring
A non-translated short name representing the auth method
Expand Down
14 changes: 7 additions & 7 deletions src/auth/basic/qgsauthbasicmethod.cpp
Expand Up @@ -66,7 +66,7 @@ bool QgsAuthBasicMethod::updateNetworkRequest( QNetworkRequest &request, const Q
const QString &dataprovider )
{
Q_UNUSED( dataprovider )
QMutexLocker locker( mMutex );
QMutexLocker locker( &mMutex );
QgsAuthMethodConfig mconfig = getMethodConfig( authcfg );
if ( !mconfig.isValid() )
{
Expand All @@ -88,7 +88,7 @@ bool QgsAuthBasicMethod::updateDataSourceUriItems( QStringList &connectionItems,
const QString &dataprovider )
{
Q_UNUSED( dataprovider )
QMutexLocker locker( mMutex );
QMutexLocker locker( &mMutex );
QgsAuthMethodConfig mconfig = getMethodConfig( authcfg );
if ( !mconfig.isValid() )
{
Expand Down Expand Up @@ -280,7 +280,7 @@ bool QgsAuthBasicMethod::updateDataSourceUriItems( QStringList &connectionItems,
bool QgsAuthBasicMethod::updateNetworkProxy( QNetworkProxy &proxy, const QString &authcfg, const QString &dataprovider )
{
Q_UNUSED( dataprovider )
QMutexLocker locker( mMutex );
QMutexLocker locker( &mMutex );

QgsAuthMethodConfig mconfig = getMethodConfig( authcfg );
if ( !mconfig.isValid() )
Expand All @@ -302,7 +302,7 @@ bool QgsAuthBasicMethod::updateNetworkProxy( QNetworkProxy &proxy, const QString

void QgsAuthBasicMethod::updateMethodConfig( QgsAuthMethodConfig &mconfig )
{
QMutexLocker locker( mMutex );
QMutexLocker locker( &mMutex );
if ( mconfig.hasConfig( QStringLiteral( "oldconfigstyle" ) ) )
{
QgsDebugMsg( "Updating old style auth method config" );
Expand All @@ -324,7 +324,7 @@ void QgsAuthBasicMethod::clearCachedConfig( const QString &authcfg )

QgsAuthMethodConfig QgsAuthBasicMethod::getMethodConfig( const QString &authcfg, bool fullconfig )
{
QMutexLocker locker( mMutex );
QMutexLocker locker( &mMutex );
QgsAuthMethodConfig mconfig;

// check if it is cached
Expand All @@ -350,14 +350,14 @@ QgsAuthMethodConfig QgsAuthBasicMethod::getMethodConfig( const QString &authcfg,

void QgsAuthBasicMethod::putMethodConfig( const QString &authcfg, const QgsAuthMethodConfig &mconfig )
{
QMutexLocker locker( mMutex );
QMutexLocker locker( &mMutex );
QgsDebugMsg( QString( "Putting basic config for authcfg: %1" ).arg( authcfg ) );
sAuthConfigCache.insert( authcfg, mconfig );
}

void QgsAuthBasicMethod::removeMethodConfig( const QString &authcfg )
{
QMutexLocker locker( mMutex );
QMutexLocker locker( &mMutex );
if ( sAuthConfigCache.contains( authcfg ) )
{
sAuthConfigCache.remove( authcfg );
Expand Down
14 changes: 7 additions & 7 deletions src/auth/identcert/qgsauthidentcertmethod.cpp
Expand Up @@ -52,7 +52,7 @@ QgsAuthIdentCertMethod::QgsAuthIdentCertMethod()

QgsAuthIdentCertMethod::~QgsAuthIdentCertMethod()
{
QMutexLocker locker( mMutex );
QMutexLocker locker( &mMutex );
qDeleteAll( sPkiConfigBundleCache );
sPkiConfigBundleCache.clear();
}
Expand All @@ -76,7 +76,7 @@ bool QgsAuthIdentCertMethod::updateNetworkRequest( QNetworkRequest &request, con
const QString &dataprovider )
{
Q_UNUSED( dataprovider )
QMutexLocker locker( mMutex );
QMutexLocker locker( &mMutex );

// TODO: is this too restrictive, to intercept only HTTPS connections?
if ( request.url().scheme().toLower() != QLatin1String( "https" ) )
Expand Down Expand Up @@ -111,7 +111,7 @@ bool QgsAuthIdentCertMethod::updateDataSourceUriItems( QStringList &connectionIt
const QString &dataprovider )
{
Q_UNUSED( dataprovider )
QMutexLocker locker( mMutex );
QMutexLocker locker( &mMutex );

QgsDebugMsg( QString( "Update URI items for authcfg: %1" ).arg( authcfg ) );

Expand Down Expand Up @@ -210,7 +210,7 @@ void QgsAuthIdentCertMethod::clearCachedConfig( const QString &authcfg )

void QgsAuthIdentCertMethod::updateMethodConfig( QgsAuthMethodConfig &mconfig )
{
QMutexLocker locker( mMutex );
QMutexLocker locker( &mMutex );
if ( mconfig.hasConfig( QStringLiteral( "oldconfigstyle" ) ) )
{
QgsDebugMsg( "Updating old style auth method config" );
Expand All @@ -225,7 +225,7 @@ void QgsAuthIdentCertMethod::updateMethodConfig( QgsAuthMethodConfig &mconfig )

QgsPkiConfigBundle *QgsAuthIdentCertMethod::getPkiConfigBundle( const QString &authcfg )
{
QMutexLocker locker( mMutex );
QMutexLocker locker( &mMutex );
QgsPkiConfigBundle *bundle = nullptr;

// check if it is cached
Expand Down Expand Up @@ -278,14 +278,14 @@ QgsPkiConfigBundle *QgsAuthIdentCertMethod::getPkiConfigBundle( const QString &a

void QgsAuthIdentCertMethod::putPkiConfigBundle( const QString &authcfg, QgsPkiConfigBundle *pkibundle )
{
QMutexLocker locker( mMutex );
QMutexLocker locker( &mMutex );
QgsDebugMsg( QString( "Putting PKI bundle for authcfg %1" ).arg( authcfg ) );
sPkiConfigBundleCache.insert( authcfg, pkibundle );
}

void QgsAuthIdentCertMethod::removePkiConfigBundle( const QString &authcfg )
{
QMutexLocker locker( mMutex );
QMutexLocker locker( &mMutex );
if ( sPkiConfigBundleCache.contains( authcfg ) )
{
QgsPkiConfigBundle *pkibundle = sPkiConfigBundleCache.take( authcfg );
Expand Down
16 changes: 8 additions & 8 deletions src/auth/pkipaths/qgsauthpkipathsmethod.cpp
Expand Up @@ -53,7 +53,7 @@ QgsAuthPkiPathsMethod::QgsAuthPkiPathsMethod()

QgsAuthPkiPathsMethod::~QgsAuthPkiPathsMethod()
{
QMutexLocker locker( mMutex );
QMutexLocker locker( &mMutex );
qDeleteAll( sPkiConfigBundleCache );
sPkiConfigBundleCache.clear();
}
Expand All @@ -77,7 +77,7 @@ bool QgsAuthPkiPathsMethod::updateNetworkRequest( QNetworkRequest &request, cons
const QString &dataprovider )
{
Q_UNUSED( dataprovider )
QMutexLocker locker( mMutex );
QMutexLocker locker( &mMutex );

// TODO: is this too restrictive, to intercept only HTTPS connections?
if ( request.url().scheme().toLower() != QLatin1String( "https" ) )
Expand Down Expand Up @@ -125,7 +125,7 @@ bool QgsAuthPkiPathsMethod::updateDataSourceUriItems( QStringList &connectionIte
const QString &dataprovider )
{
Q_UNUSED( dataprovider )
QMutexLocker locker( mMutex );
QMutexLocker locker( &mMutex );

QgsDebugMsg( QString( "Update URI items for authcfg: %1" ).arg( authcfg ) );

Expand Down Expand Up @@ -239,13 +239,13 @@ bool QgsAuthPkiPathsMethod::updateDataSourceUriItems( QStringList &connectionIte

void QgsAuthPkiPathsMethod::clearCachedConfig( const QString &authcfg )
{
QMutexLocker locker( mMutex );
QMutexLocker locker( &mMutex );
removePkiConfigBundle( authcfg );
}

void QgsAuthPkiPathsMethod::updateMethodConfig( QgsAuthMethodConfig &mconfig )
{
QMutexLocker locker( mMutex );
QMutexLocker locker( &mMutex );
if ( mconfig.hasConfig( QStringLiteral( "oldconfigstyle" ) ) )
{
QgsDebugMsg( "Updating old style auth method config" );
Expand All @@ -262,7 +262,7 @@ void QgsAuthPkiPathsMethod::updateMethodConfig( QgsAuthMethodConfig &mconfig )

QgsPkiConfigBundle *QgsAuthPkiPathsMethod::getPkiConfigBundle( const QString &authcfg )
{
QMutexLocker locker( mMutex );
QMutexLocker locker( &mMutex );
QgsPkiConfigBundle *bundle = nullptr;

// check if it is cached
Expand Down Expand Up @@ -313,14 +313,14 @@ QgsPkiConfigBundle *QgsAuthPkiPathsMethod::getPkiConfigBundle( const QString &au

void QgsAuthPkiPathsMethod::putPkiConfigBundle( const QString &authcfg, QgsPkiConfigBundle *pkibundle )
{
QMutexLocker locker( mMutex );
QMutexLocker locker( &mMutex );
QgsDebugMsg( QString( "Putting PKI bundle for authcfg %1" ).arg( authcfg ) );
sPkiConfigBundleCache.insert( authcfg, pkibundle );
}

void QgsAuthPkiPathsMethod::removePkiConfigBundle( const QString &authcfg )
{
QMutexLocker locker( mMutex );
QMutexLocker locker( &mMutex );
if ( sPkiConfigBundleCache.contains( authcfg ) )
{
QgsPkiConfigBundle *pkibundle = sPkiConfigBundleCache.take( authcfg );
Expand Down
14 changes: 7 additions & 7 deletions src/auth/pkipkcs12/qgsauthpkcs12method.cpp
Expand Up @@ -76,7 +76,7 @@ bool QgsAuthPkcs12Method::updateNetworkRequest( QNetworkRequest &request, const
const QString &dataprovider )
{
Q_UNUSED( dataprovider )
QMutexLocker locker( mMutex );
QMutexLocker locker( &mMutex );

// TODO: is this too restrictive, to intercept only HTTPS connections?
if ( request.url().scheme().toLower() != QLatin1String( "https" ) )
Expand Down Expand Up @@ -124,7 +124,7 @@ bool QgsAuthPkcs12Method::updateDataSourceUriItems( QStringList &connectionItems
const QString &dataprovider )
{
Q_UNUSED( dataprovider )
QMutexLocker locker( mMutex );
QMutexLocker locker( &mMutex );

QgsDebugMsg( QString( "Update URI items for authcfg: %1" ).arg( authcfg ) );

Expand Down Expand Up @@ -238,13 +238,13 @@ bool QgsAuthPkcs12Method::updateDataSourceUriItems( QStringList &connectionItems

void QgsAuthPkcs12Method::clearCachedConfig( const QString &authcfg )
{
QMutexLocker locker( mMutex );
QMutexLocker locker( &mMutex );
removePkiConfigBundle( authcfg );
}

void QgsAuthPkcs12Method::updateMethodConfig( QgsAuthMethodConfig &mconfig )
{
QMutexLocker locker( mMutex );
QMutexLocker locker( &mMutex );
if ( mconfig.hasConfig( QStringLiteral( "oldconfigstyle" ) ) )
{
QgsDebugMsg( "Updating old style auth method config" );
Expand All @@ -260,7 +260,7 @@ void QgsAuthPkcs12Method::updateMethodConfig( QgsAuthMethodConfig &mconfig )

QgsPkiConfigBundle *QgsAuthPkcs12Method::getPkiConfigBundle( const QString &authcfg )
{
QMutexLocker locker( mMutex );
QMutexLocker locker( &mMutex );
QgsPkiConfigBundle *bundle = nullptr;

// check if it is cached
Expand Down Expand Up @@ -334,14 +334,14 @@ QgsPkiConfigBundle *QgsAuthPkcs12Method::getPkiConfigBundle( const QString &auth

void QgsAuthPkcs12Method::putPkiConfigBundle( const QString &authcfg, QgsPkiConfigBundle *pkibundle )
{
QMutexLocker locker( mMutex );
QMutexLocker locker( &mMutex );
QgsDebugMsg( QString( "Putting PKI bundle for authcfg %1" ).arg( authcfg ) );
sPkiConfigBundleCache.insert( authcfg, pkibundle );
}

void QgsAuthPkcs12Method::removePkiConfigBundle( const QString &authcfg )
{
QMutexLocker locker( mMutex );
QMutexLocker locker( &mMutex );
if ( sPkiConfigBundleCache.contains( authcfg ) )
{
QgsPkiConfigBundle *pkibundle = sPkiConfigBundleCache.take( authcfg );
Expand Down
7 changes: 2 additions & 5 deletions src/core/auth/qgsauthmethod.h
Expand Up @@ -59,9 +59,6 @@ class CORE_EXPORT QgsAuthMethod : public QObject
};
Q_DECLARE_FLAGS( Expansions, Expansion )

//! Destructor: delete the mutex
~QgsAuthMethod() { delete mMutex; }

//! A non-translated short name representing the auth method
virtual QString key() const = 0;

Expand Down Expand Up @@ -178,7 +175,7 @@ class CORE_EXPORT QgsAuthMethod : public QObject
explicit QgsAuthMethod()
: mExpansions( QgsAuthMethod::Expansions( nullptr ) )
, mDataProviders( QStringList() )
, mMutex( new QMutex( QMutex::RecursionMode::Recursive ) )
, mMutex( QMutex::RecursionMode::Recursive )
{}


Expand All @@ -196,7 +193,7 @@ class CORE_EXPORT QgsAuthMethod : public QObject
QgsAuthMethod::Expansions mExpansions;
QStringList mDataProviders;
int mVersion = 0;
QMutex *mMutex;
QMutex mMutex;

};
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsAuthMethod::Expansions )
Expand Down

0 comments on commit 6f06597

Please sign in to comment.