From 02a008da35964da9812e5ed2c9d09abb04a04bce Mon Sep 17 00:00:00 2001 From: Dirk Mueller Date: Thu, 17 Jul 2008 01:11:25 +0000 Subject: [PATCH] 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 --- applet.cpp | 5 +++++ applet.h | 4 +++- version.cpp | 16 ++++++++++++++++ version.h | 6 ++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/applet.cpp b/applet.cpp index 59961b59d..2bb9f4c80 100644 --- a/applet.cpp +++ b/applet.cpp @@ -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; diff --git a/applet.h b/applet.h index 295073b38..833024a45 100644 --- a/applet.h +++ b/applet.h @@ -35,6 +35,7 @@ #include #include #include +#include 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();) \ -K_EXPORT_PLUGIN(factory("plasma_applet_" #libname)) +K_EXPORT_PLUGIN(factory("plasma_applet_" #libname)) \ +K_EXPORT_PLUGIN_VERSION(PLASMA_VERSION) #endif // multiple inclusion guard diff --git a/version.cpp b/version.cpp index a948651bc..3017705ff 100644 --- a/version.cpp +++ b/version.cpp @@ -18,6 +18,7 @@ */ #include +#include 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 diff --git a/version.h b/version.h index d0acb4acd..6643942c2 100644 --- a/version.h +++ b/version.h @@ -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