44 QgsAuthMethodRegistry::QgsAuthMethodRegistry(
const QString &pluginPath )
50 char **argv = qApp->argv();
51 QString appDir = argv[0];
52 int bin = appDir.findRev(
"/bin", -1,
false );
53 QString baseDir = appDir.left( bin );
54 QString mLibraryDirectory = baseDir +
"/lib";
56 mLibraryDirectory.setPath( pluginPath );
57 mLibraryDirectory.setSorting( QDir::Name | QDir::IgnoreCase );
58 mLibraryDirectory.setFilter( QDir::Files | QDir::NoSymLinks );
60 #if defined(Q_OS_WIN) || defined(__CYGWIN__)
61 mLibraryDirectory.setNameFilters( QStringList(
"*authmethod.dll" ) );
63 mLibraryDirectory.setNameFilters( QStringList( QStringLiteral(
"*authmethod.so" ) ) );
66 QgsDebugMsgLevel( QStringLiteral(
"Checking for auth method plugins in: %1" ).arg( mLibraryDirectory.path() ), 2 );
68 if ( mLibraryDirectory.count() == 0 )
70 QString msg = QObject::tr(
"No QGIS auth method plugins found in:\n%1\n" ).arg( mLibraryDirectory.path() );
71 msg += QObject::tr(
"No authentication methods can be used. Check your QGIS installation" );
74 output->
setTitle( QObject::tr(
"No Authentication Methods" ) );
81 QString filePattern = getenv(
"QGIS_AUTHMETHOD_FILE" );
83 if ( !filePattern.isEmpty() )
85 fileRegexp.setPattern( filePattern );
88 QListIterator<QFileInfo> it( mLibraryDirectory.entryInfoList() );
89 while ( it.hasNext() )
91 QFileInfo fi( it.next() );
93 if ( !fileRegexp.isEmpty() )
95 if ( fileRegexp.indexIn( fi.fileName() ) == -1 )
97 QgsDebugMsg(
"auth method " + fi.fileName() +
" skipped because doesn't match pattern " + filePattern );
102 QLibrary myLib( fi.filePath() );
105 QgsDebugMsg( QStringLiteral(
"Checking %1: ...invalid (lib not loadable): %2" ).arg( myLib.fileName(), myLib.errorString() ) );
113 QgsDebugMsg( QStringLiteral(
"Checking %1: ...invalid (no isAuthMethod method)" ).arg( myLib.fileName() ) );
118 if ( !isAuthMethod() )
120 QgsDebugMsg( QStringLiteral(
"Checking %1: ...invalid (not an auth method)" ).arg( myLib.fileName() ) );
128 QgsDebugMsg( QStringLiteral(
"Checking %1: ...invalid (no description method)" ).arg( myLib.fileName() ) );
135 QgsDebugMsg( QStringLiteral(
"Checking %1: ...invalid (no authMethodKey method)" ).arg( myLib.fileName() ) );
150 AuthMethods::const_iterator it = mAuthMethods.begin();
152 while ( it != mAuthMethods.end() )
155 QString lib = it->second->library();
156 QLibrary myLib( lib );
157 if ( myLib.isLoaded() )
179 QString
const &authMethodKey )
181 QgsAuthMethodRegistry::AuthMethods::const_iterator i =
182 metaData.find( authMethodKey );
184 if ( i != metaData.end() )
207 AuthMethods::const_iterator it = mAuthMethods.begin();
209 if ( mAuthMethods.empty() )
211 return QObject::tr(
"No authentication method plugins are available." );
218 list += QLatin1String(
"<ol>" );
221 while ( it != mAuthMethods.end() )
225 list += QLatin1String(
"<li>" );
228 list += it->second->description();
232 list += QLatin1String(
"<br></li>" );
244 list += QLatin1String(
"</ol>" );
252 return mLibraryDirectory;
257 mLibraryDirectory = path;
267 QString lib =
library( authMethodKey );
269 #ifdef TESTAUTHMETHODLIB
270 const char *cLib = lib.toUtf8();
274 void *handle = dlopen( cOgrLib, RTLD_LAZY | RTLD_GLOBAL );
281 QgsDebugMsg( QStringLiteral(
"dlopen succeeded" ) );
287 QLibrary myLib( lib );
299 QgsDebugMsg( QStringLiteral(
"Failed to load %1: no classFactory method" ).arg( lib ) );
303 std::unique_ptr< QgsAuthMethod >
authMethod( classFactory() );
325 return editFactory( parent );
329 QString
const &functionName )
331 QLibrary myLib(
library( authMethodKey ) );
333 QgsDebugMsg(
"Library name is " + myLib.fileName() );
337 return myLib.resolve( functionName.toLatin1().data() );
341 QgsDebugMsg(
"Cannot load library: " + myLib.errorString() );
348 std::unique_ptr< QLibrary > myLib(
new QLibrary(
library( authMethodKey ) ) );
350 QgsDebugMsg(
"Library name is " + myLib->fileName() );
355 QgsDebugMsg(
"Cannot load library: " + myLib->errorString() );
362 for ( AuthMethods::const_iterator it = mAuthMethods.begin(); it != mAuthMethods.end(); ++it )
364 lst.append( it->first );
371 return findMetadata_( mAuthMethods, authMethodKey );