Skip to content
Permalink
Browse files
core part to add gui modules for auth methods
  • Loading branch information
3nids committed May 19, 2021
1 parent 016e5e7 commit de11305b1661a22654e8753d98144c2119096957
@@ -18,26 +18,30 @@
#include "qgsauthmethodmetadata.h"


QgsAuthMethodMetadata::QgsAuthMethodMetadata( QString const &_key,
QString const &_description,
QString const &_library )
: key_( _key )
, description_( _description )
, library_( _library )
QgsAuthMethodMetadata::QgsAuthMethodMetadata(QString const &key, QString const &description, QString const &library , const QString &guiLibrary)
: mKey( key )
, mDescription( description )
, mLibrary( library )
, mGuiLibrary( guiLibrary )
{}

QString QgsAuthMethodMetadata::key() const
{
return key_;
return mKey;
}

QString QgsAuthMethodMetadata::description() const
{
return description_;
return mDescription;
}

QString QgsAuthMethodMetadata::library() const
{
return library_;
return mLibrary;
}

QString QgsAuthMethodMetadata::guiLibrary() const
{
return mGuiLibrary;
}

@@ -43,11 +43,12 @@ class CORE_EXPORT QgsAuthMethodMetadata

/**
* Construct an authentication method metadata container
* \param _key Textual key of the library plugin
* \param _description Description of the library plugin
* \param _library File name of library plugin
* \param key Textual key of the library plugin
* \param description Description of the library plugin
* \param library File name of the core library plugin
* \param guiLibrary File name of the gui library plugin
*/
QgsAuthMethodMetadata( const QString &_key, const QString &_description, const QString &_library );
QgsAuthMethodMetadata(const QString &_key, const QString &description, const QString &library, const QString &guiLibrary = QString() );

/**
* Returns the unique key associated with the method
@@ -70,16 +71,26 @@ class CORE_EXPORT QgsAuthMethodMetadata
*/
QString library() const;

/**
* Returns the gui library file name.
*
* This is used to QLibrary calls to load the method.
*/
QString guiLibrary() const;

private:

/// unique key for method
QString key_;
QString mKey;

/// associated terse description
QString description_;
QString mDescription;

/// file path of the core library
QString mLibrary;

/// file path
QString library_;
/// file path of the gui library, might be an empty string
QString mGuiLibrary;
};

#endif // QGSAUTHMETHODMETADATA_H
@@ -41,7 +41,7 @@ QgsAuthMethodRegistry *QgsAuthMethodRegistry::instance( const QString &pluginPat
return sInstance;
}

QgsAuthMethodRegistry::QgsAuthMethodRegistry( const QString &pluginPath )
QgsAuthMethodRegistry::QgsAuthMethodRegistry( const QString &pluginPath, bool loadGuiModules )
{
// At startup, examine the libs in the qgis/lib dir and store those that
// are an auth method shared lib
@@ -58,10 +58,11 @@ QgsAuthMethodRegistry::QgsAuthMethodRegistry( const QString &pluginPath )
mLibraryDirectory.setFilter( QDir::Files | QDir::NoSymLinks );

#if defined(Q_OS_WIN) || defined(__CYGWIN__)
mLibraryDirectory.setNameFilters( QStringList( "*authmethod.dll" ) );
const QString libExtension = QStringLiteral( "dll" );
#else
mLibraryDirectory.setNameFilters( QStringList( QStringLiteral( "*authmethod.so" ) ) );
const QString libExtension = QStringLiteral( "so" );
#endif
mLibraryDirectory.setNameFilters( QStringList( QStringLiteral( "*authmethod.%1" ).arg(libExtension) ) );

QgsDebugMsgLevel( QStringLiteral( "Checking for auth method plugins in: %1" ).arg( mLibraryDirectory.path() ), 2 );

@@ -136,9 +137,58 @@ QgsAuthMethodRegistry::QgsAuthMethodRegistry( const QString &pluginPath )
continue;
}

// add this auth method to the method map
mAuthMethods[pKey()] = new QgsAuthMethodMetadata( pKey(), pDesc(), myLib.fileName() );
QString guiLibPath = fi.filePath().replace(QStringLiteral("authmethod.%1").arg(libExtension), QStringLiteral("authmethodgui.%1").arg(libExtension));
bool loadGui = false;
if (loadGuiModules)
{
QLibrary myGuiLib( guiLibPath );
if ( !myGuiLib.load() )
{
QgsDebugMsg( QStringLiteral( "Checking %1: ...invalid gui module (lib not loadable): %2" ).arg( myGuiLib.fileName(), myGuiLib.errorString() ) );
}
else
{
// get the description and the key for the auth method plugin
isauthmethod_t *isAuthMethodGui = reinterpret_cast< isauthmethod_t * >( cast_to_fptr( myGuiLib.resolve( "isAuthMethodGui" ) ) );
if ( !isAuthMethodGui )
{
QgsDebugMsg( QStringLiteral( "Checking %1: ...invalid gui module (no isAuthMethod method)" ).arg( myGuiLib.fileName() ) );
}
// check to see if this is an auth method plugin
else if ( !isAuthMethodGui() )
{
QgsDebugMsg( QStringLiteral( "Checking %1: ...invalid gui module (not a gui auth method)" ).arg( myGuiLib.fileName() ) );
}
else
{
methodkey_t *pKeyGui = reinterpret_cast< methodkey_t * >( cast_to_fptr( myGuiLib.resolve( "authMethodKey" ) ) );
if ( !pKeyGui )
{
QgsDebugMsg( QStringLiteral( "Checking %1: ...invalid gui module (no authMethodKey method)" ).arg( myGuiLib.fileName() ) );
}
else
{
if (pKeyGui() != pKey() )
{
Q_ASSERT(pKeyGui() == pKey());
QgsDebugMsg( QStringLiteral( "Checking %1: ...invalid gui module (key does not match core one: %2 / %3)" ).arg( myGuiLib.fileName(), pKeyGui(), pKey() ) );
}
else
{
guiLibPath = myGuiLib.fileName();
loadGui = true;
}
}
}
}
}
if (!loadGui)
guiLibPath = QString();

QgsDebugMsg( QStringLiteral( "Authentication method loaded: %1 (gui: %2)" ).arg( myLib.fileName(), loadGui ? guiLibPath : "not available" ) );

// add this auth method to the method map
mAuthMethods[pKey()] = new QgsAuthMethodMetadata( pKey(), pDesc(), myLib.fileName(), guiLibPath );
}
}

@@ -190,12 +240,15 @@ static QgsAuthMethodMetadata *findMetadata_( QgsAuthMethodRegistry::AuthMethods
} // findMetadata_


QString QgsAuthMethodRegistry::library( const QString &authMethodKey ) const
QString QgsAuthMethodRegistry::library( const QString &authMethodKey, bool gui ) const
{
QgsAuthMethodMetadata *md = findMetadata_( mAuthMethods, authMethodKey );

if ( md )
{
if (gui)
return md->guiLibrary();
else
return md->library();
}

@@ -317,7 +370,7 @@ typedef QWidget *editFactoryFunction_t( QWidget *parent );
QWidget *QgsAuthMethodRegistry::editWidget( const QString &authMethodKey, QWidget *parent )
{
editFactoryFunction_t *editFactory =
reinterpret_cast< editFactoryFunction_t * >( cast_to_fptr( function( authMethodKey, QStringLiteral( "editWidget" ) ) ) );
reinterpret_cast< editFactoryFunction_t * >( cast_to_fptr( function( authMethodKey, QStringLiteral( "editWidget" ), true ) ) );

if ( !editFactory )
return nullptr;
@@ -326,9 +379,9 @@ QWidget *QgsAuthMethodRegistry::editWidget( const QString &authMethodKey, QWidge
}

QFunctionPointer QgsAuthMethodRegistry::function( QString const &authMethodKey,
QString const &functionName )
QString const &functionName, bool gui )
{
QLibrary myLib( library( authMethodKey ) );
QLibrary myLib( library( authMethodKey, gui ) );

QgsDebugMsgLevel( "Library name is " + myLib.fileName(), 2 );

@@ -54,7 +54,8 @@ class CORE_EXPORT QgsAuthMethodRegistry
virtual ~QgsAuthMethodRegistry();

//! Returns path for the library of the auth method
QString library( const QString &authMethodKey ) const;
//! if gui is TRUE, it will return the gui module if it exists and is loaded
QString library(const QString &authMethodKey , bool gui = false) const;

//! Returns list of auth method plugins found
QString pluginList( bool asHtml = false ) const;
@@ -92,10 +93,11 @@ class CORE_EXPORT QgsAuthMethodRegistry
* Gets pointer to auth method function
* \param authMethodKey identificator of the auth method
* \param functionName name of function
* \param gui determines if the function is in the gui module (core by default).
* \returns pointer to function or nullptr on error
*/
QFunctionPointer function( const QString &authMethodKey,
const QString &functionName );
QFunctionPointer function(const QString &authMethodKey,
const QString &functionName , bool gui = false);

//! Returns the library object associated with an auth method key
std::unique_ptr< QLibrary > authMethodLibrary( const QString &authMethodKey ) const;
@@ -113,7 +115,8 @@ class CORE_EXPORT QgsAuthMethodRegistry

private:
//! Ctor private since instance() creates it
QgsAuthMethodRegistry( const QString &pluginPath );
//! If loadGuiModules is TRUE, the registry will also register the gui module matching the core part
QgsAuthMethodRegistry(const QString &pluginPath , bool loadGuiModules = true);

//! Associative container of auth method metadata handles
AuthMethods mAuthMethods;

0 comments on commit de11305

Please sign in to comment.