provider versioning, also added qcaVersion for runtime version check

svn path=/trunk/kdesupport/qca/; revision=604475
This commit is contained in:
Justin Karneges 2006-11-12 23:01:27 +00:00
parent 3abc066bbc
commit 498fe8fff4
7 changed files with 71 additions and 0 deletions

View File

@ -195,6 +195,11 @@ protected:
class ClientSideProvider : public QCA::Provider class ClientSideProvider : public QCA::Provider
{ {
public: public:
int version() const
{
return QCA_VERSION;
}
QString name() const QString name() const
{ {
return "exampleClientSideProvider"; return "exampleClientSideProvider";

View File

@ -46,6 +46,8 @@
#include "qca_support.h" #include "qca_support.h"
#include "qca_tools.h" #include "qca_tools.h"
QCA_EXPORT int qcaVersion();
/** /**
* QCA - the Qt Cryptographic Architecture * QCA - the Qt Cryptographic Architecture
*/ */
@ -605,6 +607,19 @@ namespace QCA
*/ */
virtual void init(); virtual void init();
/**
* Target QCA version for the provider.
*
* This is used to verify compatibility between the
* provider and QCA. For a provider to be used, it
* must have major and minor version numbers that are
* less-than or equal to the QCA version (the patch
* version number is ignored). This means an older
* provider may be used with a newer QCA, but a newer
* provider cannot be used with an older QCA.
*/
virtual int version() const = 0;
/** /**
* The name of the provider. * The name of the provider.
* *

View File

@ -5882,6 +5882,11 @@ public:
// todo: any shutdown? // todo: any shutdown?
} }
int version() const
{
return QCA_VERSION;
}
QString name() const QString name() const
{ {
return "qca-openssl"; return "qca-openssl";

View File

@ -31,6 +31,11 @@
# include <unistd.h> # include <unistd.h>
#endif #endif
int qcaVersion()
{
return QCA_VERSION;
}
namespace QCA { namespace QCA {
// from qca_tools // from qca_tools

View File

@ -900,6 +900,11 @@ public:
srand(t); srand(t);
} }
int version() const
{
return QCA_VERSION;
}
QString name() const QString name() const
{ {
return "default"; return "default";

View File

@ -34,6 +34,14 @@ static void logDebug(const QString &str)
g_pluginman->appendDiagnosticText(str + '\n'); g_pluginman->appendDiagnosticText(str + '\n');
} }
static bool validVersion(int ver)
{
// make sure the provider isn't newer than qca
if((ver & 0xffff00) <= (QCA_VERSION & 0xffff00))
return true;
return false;
}
class PluginInstance class PluginInstance
{ {
private: private:
@ -263,6 +271,14 @@ void ProviderManager::scan()
continue; continue;
} }
int ver = i->p->version();
if(!validVersion(ver))
{
logDebug(QString().sprintf("plugin version 0x%06x is in the future", ver));
delete i;
continue;
}
addItem(i, -1); addItem(i, -1);
} }
scanned_static = true; scanned_static = true;
@ -322,6 +338,14 @@ void ProviderManager::scan()
continue; continue;
} }
int ver = i->p->version();
if(!validVersion(ver))
{
logDebug(QString().sprintf("plugin version 0x%06x is in the future", ver));
delete i;
continue;
}
addItem(i, -1); addItem(i, -1);
} }
} }
@ -336,6 +360,13 @@ bool ProviderManager::add(Provider *p, int priority)
return false; return false;
} }
int ver = p->version();
if(!validVersion(ver))
{
logDebug(QString().sprintf("plugin version 0x%06x is in the future", ver));
return false;
}
ProviderItem *i = ProviderItem::fromClass(p); ProviderItem *i = ProviderItem::fromClass(p);
addItem(i, priority); addItem(i, priority);
return true; return true;

View File

@ -54,6 +54,11 @@ void ClientPlugin::cleanupTestCase()
class TestClientProvider : public QCA::Provider class TestClientProvider : public QCA::Provider
{ {
public: public:
int version() const
{
return QCA_VERSION;
}
QString name() const QString name() const
{ {
return "testClientSideProvider"; return "testClientSideProvider";