mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-02-02 09:20:39 +01:00
Cleanup and minor enhancement in database crypt example
This commit is contained in:
parent
95f6cc6211
commit
24ba968d34
@ -41,11 +41,6 @@ public:
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
IPluginModule* getModule()
|
||||
{
|
||||
return NULL; // OK for application, not for plugin
|
||||
}
|
||||
};
|
||||
|
||||
class App
|
||||
|
@ -29,47 +29,37 @@
|
||||
namespace
|
||||
{
|
||||
|
||||
IMaster* master = NULL;
|
||||
IPluginManager* pluginManager = NULL;
|
||||
|
||||
class PluginModule : public IPluginModuleImpl<PluginModule, CheckStatusWrapper>
|
||||
{
|
||||
public:
|
||||
PluginModule()
|
||||
: flag(false)
|
||||
: pluginManager(NULL)
|
||||
{ }
|
||||
|
||||
void registerMe()
|
||||
{
|
||||
pluginManager->registerModule(this);
|
||||
flag = true;
|
||||
}
|
||||
|
||||
~PluginModule()
|
||||
{
|
||||
if (flag)
|
||||
if (pluginManager)
|
||||
{
|
||||
pluginManager->unregisterModule(this);
|
||||
doClean();
|
||||
}
|
||||
}
|
||||
|
||||
IPluginModule* getModule()
|
||||
void registerMe(IPluginManager* m)
|
||||
{
|
||||
return this;
|
||||
pluginManager = m;
|
||||
pluginManager->registerModule(this);
|
||||
}
|
||||
|
||||
void doClean()
|
||||
{
|
||||
flag = false;
|
||||
pluginManager = NULL;
|
||||
}
|
||||
|
||||
private:
|
||||
bool flag;
|
||||
IPluginManager* pluginManager;
|
||||
};
|
||||
|
||||
PluginModule module;
|
||||
|
||||
class CryptKeyHolder : public IKeyHolderPluginImpl<CryptKeyHolder, CheckStatusWrapper>
|
||||
{
|
||||
public:
|
||||
@ -103,11 +93,6 @@ public:
|
||||
++refCounter;
|
||||
}
|
||||
|
||||
IPluginModule* getModule()
|
||||
{
|
||||
return &module;
|
||||
}
|
||||
|
||||
void setOwner(Firebird::IReferenceCounted* o)
|
||||
{
|
||||
owner = o;
|
||||
@ -265,38 +250,25 @@ ICryptKeyCallback* CryptKeyHolder::keyHandle(CheckStatusWrapper* status, const c
|
||||
class Factory : public IPluginFactoryImpl<Factory, CheckStatusWrapper>
|
||||
{
|
||||
public:
|
||||
IPluginModule* getModule()
|
||||
{
|
||||
return &module;
|
||||
}
|
||||
|
||||
IPluginBase* createPlugin(CheckStatusWrapper* status, IPluginConfig* factoryParameter)
|
||||
{
|
||||
try
|
||||
{
|
||||
CryptKeyHolder* p = new CryptKeyHolder(factoryParameter);
|
||||
p->addRef();
|
||||
return p;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
ISC_STATUS st[3] = {isc_arg_gds, isc_virmemexh, isc_arg_end};
|
||||
status->setErrors(st);
|
||||
}
|
||||
return NULL;
|
||||
CryptKeyHolder* p = new CryptKeyHolder(factoryParameter);
|
||||
p->addRef();
|
||||
return p;
|
||||
}
|
||||
};
|
||||
|
||||
PluginModule module;
|
||||
Factory factory;
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
extern "C" void FB_DLL_EXPORT FB_PLUGIN_ENTRY_POINT(IMaster* m)
|
||||
extern "C" void FB_DLL_EXPORT FB_PLUGIN_ENTRY_POINT(IMaster* master)
|
||||
{
|
||||
master = m;
|
||||
pluginManager = master->getPluginManager();
|
||||
IPluginManager* pluginManager = master->getPluginManager();
|
||||
|
||||
module.registerMe();
|
||||
module.registerMe(pluginManager);
|
||||
pluginManager->registerPluginFactory(IPluginManager::TYPE_KEY_HOLDER, "CryptKeyHolder_example",
|
||||
&factory);
|
||||
}
|
||||
|
||||
|
@ -31,52 +31,42 @@ using namespace Firebird;
|
||||
namespace
|
||||
{
|
||||
|
||||
IMaster* master = NULL;
|
||||
IPluginManager* pluginManager = NULL;
|
||||
|
||||
class PluginModule : public IPluginModuleImpl<PluginModule, CheckStatusWrapper>
|
||||
{
|
||||
public:
|
||||
PluginModule()
|
||||
: flag(false)
|
||||
: pluginManager(NULL)
|
||||
{ }
|
||||
|
||||
void registerMe()
|
||||
{
|
||||
pluginManager->registerModule(this);
|
||||
flag = true;
|
||||
}
|
||||
|
||||
~PluginModule()
|
||||
{
|
||||
if (flag)
|
||||
if (pluginManager)
|
||||
{
|
||||
pluginManager->unregisterModule(this);
|
||||
doClean();
|
||||
}
|
||||
}
|
||||
|
||||
IPluginModule* getModule()
|
||||
void registerMe(IPluginManager* m)
|
||||
{
|
||||
return this;
|
||||
pluginManager = m;
|
||||
pluginManager->registerModule(this);
|
||||
}
|
||||
|
||||
void doClean()
|
||||
{
|
||||
flag = false;
|
||||
pluginManager = NULL;
|
||||
}
|
||||
|
||||
private:
|
||||
bool flag;
|
||||
IPluginManager* pluginManager;
|
||||
};
|
||||
|
||||
PluginModule module;
|
||||
|
||||
class DbCrypt : public IDbCryptPluginImpl<DbCrypt, CheckStatusWrapper>
|
||||
{
|
||||
public:
|
||||
explicit DbCrypt(IPluginConfig* cnf) throw()
|
||||
: config(cnf), key(0), owner(NULL)
|
||||
: config(cnf), key(0), refCounter(0), owner(NULL)
|
||||
{
|
||||
config->addRef();
|
||||
}
|
||||
@ -107,11 +97,6 @@ public:
|
||||
++refCounter;
|
||||
}
|
||||
|
||||
IPluginModule* getModule()
|
||||
{
|
||||
return &module;
|
||||
}
|
||||
|
||||
void setOwner(IReferenceCounted* o)
|
||||
{
|
||||
owner = o;
|
||||
@ -254,37 +239,28 @@ void DbCrypt::setKey(CheckStatusWrapper* status, unsigned int length, IKeyHolder
|
||||
class Factory : public IPluginFactoryImpl<Factory, CheckStatusWrapper>
|
||||
{
|
||||
public:
|
||||
IPluginModule* getModule()
|
||||
{
|
||||
return &module;
|
||||
}
|
||||
|
||||
IPluginBase* createPlugin(CheckStatusWrapper* status, IPluginConfig* factoryParameter)
|
||||
{
|
||||
try
|
||||
{
|
||||
DbCrypt* p = new DbCrypt(factoryParameter);
|
||||
p->addRef();
|
||||
return p;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
ISC_STATUS st[3] = {isc_arg_gds, isc_virmemexh, isc_arg_end};
|
||||
status->setErrors(st);
|
||||
}
|
||||
return NULL;
|
||||
/*
|
||||
// *** Uncomment this 2 lines to see how plugin creation errors are handled
|
||||
const ISC_STATUS_ARRAY vector = {isc_arg_gds, isc_virmemexh, isc_arg_end};
|
||||
throw FbException(status, vector);
|
||||
*/
|
||||
DbCrypt* p = new DbCrypt(factoryParameter);
|
||||
p->addRef();
|
||||
return p;
|
||||
}
|
||||
};
|
||||
|
||||
PluginModule module;
|
||||
Factory factory;
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
extern "C" void FB_DLL_EXPORT FB_PLUGIN_ENTRY_POINT(IMaster* m)
|
||||
extern "C" void FB_DLL_EXPORT FB_PLUGIN_ENTRY_POINT(IMaster* master)
|
||||
{
|
||||
master = m;
|
||||
pluginManager = master->getPluginManager();
|
||||
IPluginManager* pluginManager = master->getPluginManager();
|
||||
|
||||
module.registerMe();
|
||||
module.registerMe(pluginManager);
|
||||
pluginManager->registerPluginFactory(IPluginManager::TYPE_DB_CRYPT, "DbCrypt_example", &factory);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user