Commit 291e8e7c authored by Dennis Nienhüser's avatar Dennis Nienhüser
Browse files

Allow plugins to be blacklisted and whitelisted

If you want to avoid that the plugin libFoo.so (Foo.dll on Windows) is
loaded at all, call Marble::PluginManager::blacklistPlugin("Foo").

If you want to avoid that any plugin other than libBar.so (Bar.dll
on Windows) is loaded at all, call
Marble::PluginManager::whitelistPlugin("Bar").

Each can be called multiple times with different plugins to blacklist
or whitelist several plugins. Plugins that are both blacklisted and
whitelisted are considered blacklisted.

Make sure to call the methods early enough before anything else
already used the PluginManager to load plugins. Take care to pass the
filename (without library prefix and file suffix) of the plugin, not
its nameId(). They can be identical, but often that is not the case.
parent cfbd82bc
#define MARBLE_PLUGIN_PATH "${MARBLE_PLUGIN_PATH}"
#define MARBLE_DATA_PATH "${MARBLE_DATA_PATH}"
#define MARBLE_SHARED_LIBRARY_PREFIX "${CMAKE_SHARED_LIBRARY_PREFIX}"
......@@ -28,6 +28,7 @@
#include "ReverseGeocodingRunnerPlugin.h"
#include "RoutingRunnerPlugin.h"
#include "SearchRunnerPlugin.h"
#include "config-marble.h"
namespace Marble
{
......@@ -51,12 +52,17 @@ class PluginManagerPrivate
QList<const ReverseGeocodingRunnerPlugin *> m_reverseGeocodingRunnerPlugins;
QList<RoutingRunnerPlugin *> m_routingRunnerPlugins;
QList<const ParseRunnerPlugin *> m_parsingRunnerPlugins;
static QStringList m_blacklist;
static QStringList m_whitelist;
#ifdef Q_OS_ANDROID
QStringList m_pluginPaths;
#endif
};
QStringList PluginManagerPrivate::m_blacklist;
QStringList PluginManagerPrivate::m_whitelist;
PluginManagerPrivate::~PluginManagerPrivate()
{
// nothing to do
......@@ -154,6 +160,16 @@ void PluginManager::addParseRunnerPlugin( const ParseRunnerPlugin *plugin )
emit parseRunnerPluginsChanged();
}
void PluginManager::blacklistPlugin(const QString &filename)
{
PluginManagerPrivate::m_blacklist << MARBLE_SHARED_LIBRARY_PREFIX + filename;
}
void PluginManager::whitelistPlugin(const QString &filename)
{
PluginManagerPrivate::m_whitelist << MARBLE_SHARED_LIBRARY_PREFIX + filename;
}
/** Append obj to the given plugins list if it inherits both T and U */
template<class T, class U>
bool appendPlugin( QObject * obj, QPluginLoader* &loader, QList<T*> &plugins )
......@@ -211,6 +227,16 @@ void PluginManagerPrivate::loadPlugins()
Q_ASSERT( m_parsingRunnerPlugins.isEmpty() );
foreach( const QString &fileName, pluginFileNameList ) {
QString const baseName = QFileInfo(fileName).baseName();
if (!m_whitelist.isEmpty() && !m_whitelist.contains(baseName)) {
mDebug() << "Ignoring non-whitelisted plugin " << fileName;
continue;
}
if (m_blacklist.contains(baseName)) {
mDebug() << "Ignoring blacklisted plugin " << fileName;
continue;
}
// mDebug() << fileName << " - " << MarbleDirs::pluginPath( fileName );
QString const path = MarbleDirs::pluginPath( fileName );
#ifdef Q_OS_ANDROID
......
......@@ -135,6 +135,22 @@ class MARBLE_EXPORT PluginManager : public QObject
*/
void addParseRunnerPlugin( const ParseRunnerPlugin *plugin );
/**
* @brief blacklistPlugin Prevent that a plugin is loaded from the given filename
* @param filename The name of the file (excluding prefix and file extension) to blacklist. E.g.
* to ignore "libWikipedia.so" on Linux and "Wikipedia.dll" on Windows, pass "Wikipedia"
*/
static void blacklistPlugin(const QString &filename);
/**
* @brief whitelistPlugin Add a plugin to the whitelist of plugins. If the whitelist is not
* empty, only whitelisted plugins are loaded. If a plugin is both whitelisted and blacklisted,
* it will not be loaded
* @param filename The name of the file (excluding prefix and file extension) to whitelist. E.g.
* to ignore "libWikipedia.so" on Linux and "Wikipedia.dll" on Windows, pass "Wikipedia"
*/
static void whitelistPlugin(const QString &filename);
Q_SIGNALS:
void renderPluginsChanged();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment