introduce plugin versioning for plasma and ensure

that only applets with a matching major.minor version
are loaded. needs porting to plugins other than applets.

CCMAIL: aseigo@kde.org

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=833550
This commit is contained in:
Dirk Mueller 2008-07-17 01:11:25 +00:00
parent 19b3401af9
commit 02a008da35
4 changed files with 30 additions and 1 deletions

View File

@ -1320,6 +1320,11 @@ Applet* Applet::load(const QString& appletName, uint appletId, const QVariantLis
return new Applet(0, offer->storageId(), appletId);
}
KPluginLoader plugin(*offer);
if (!Plasma::isPluginVersionCompatible(plugin.pluginVersion()))
return 0;
QVariantList allArgs;
allArgs << offer->storageId() << appletId << args;
QString error;

View File

@ -35,6 +35,7 @@
#include <plasma/packagestructure.h>
#include <plasma/plasma.h>
#include <plasma/animator.h>
#include <plasma/version.h>
class KConfigDialog;
class QGraphicsView;
@ -776,6 +777,7 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(Plasma::Applet::BackgroundHints)
*/
#define K_EXPORT_PLASMA_APPLET(libname, classname) \
K_PLUGIN_FACTORY(factory, registerPlugin<classname>();) \
K_EXPORT_PLUGIN(factory("plasma_applet_" #libname))
K_EXPORT_PLUGIN(factory("plasma_applet_" #libname)) \
K_EXPORT_PLUGIN_VERSION(PLASMA_VERSION)
#endif // multiple inclusion guard

View File

@ -18,6 +18,7 @@
*/
#include <plasma/version.h>
#include <kdebug.h>
namespace Plasma
{
@ -47,5 +48,20 @@ const char *versionString()
return PLASMA_VERSION_STRING;
}
bool isPluginVersionCompatible(unsigned int version)
{
// we require PLASMA_VERSION_MAJOR and PLASMA_VERSION_MINOR
const quint32 minVersion = PLASMA_MAKE_VERSION(PLASMA_VERSION_MAJOR, PLASMA_VERSION_MINOR, 0);
const quint32 maxVersion = PLASMA_MAKE_VERSION(PLASMA_VERSION_MAJOR, PLASMA_VERSION_MINOR, 60);
if (version < minVersion || version > maxVersion)
{
kDebug() << "plugin is compiled against incompatible Plasma version " << version;
return false;
}
return true;
}
} // Plasma namespace

View File

@ -80,6 +80,12 @@ PLASMA_EXPORT unsigned int versionRelease();
*/
PLASMA_EXPORT const char *versionString();
/**
* Verifies that a plugin is compatible with plasma
*/
PLASMA_EXPORT bool isPluginVersionCompatible(unsigned int version);
} // Plasma namespace
#endif // multiple inclusion guard