medcli: Use plugin features with dependency on database implementation
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
|
* Copyright (C) 2013 Tobias Brunner
|
||||||
* Copyright (C) 2008 Martin Willi
|
* Copyright (C) 2008 Martin Willi
|
||||||
* Hochschule fuer Technik Rapperswil
|
* Hochschule fuer Technik Rapperswil
|
||||||
*
|
*
|
||||||
@@ -60,16 +61,67 @@ METHOD(plugin_t, get_name, char*,
|
|||||||
return "medcli";
|
return "medcli";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connect to database
|
||||||
|
*/
|
||||||
|
static bool open_database(private_medcli_plugin_t *this,
|
||||||
|
plugin_feature_t *feature, bool reg, void *cb_data)
|
||||||
|
{
|
||||||
|
if (reg)
|
||||||
|
{
|
||||||
|
char *uri;
|
||||||
|
|
||||||
|
uri = lib->settings->get_str(lib->settings,
|
||||||
|
"medcli.database", NULL);
|
||||||
|
if (!uri)
|
||||||
|
{
|
||||||
|
DBG1(DBG_CFG, "mediation client database URI not defined, skipped");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->db = lib->db->create(lib->db, uri);
|
||||||
|
if (this->db == NULL)
|
||||||
|
{
|
||||||
|
DBG1(DBG_CFG, "opening mediation client database failed");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->creds = medcli_creds_create(this->db);
|
||||||
|
this->config = medcli_config_create(this->db);
|
||||||
|
this->listener = medcli_listener_create(this->db);
|
||||||
|
|
||||||
|
lib->credmgr->add_set(lib->credmgr, &this->creds->set);
|
||||||
|
charon->backends->add_backend(charon->backends, &this->config->backend);
|
||||||
|
charon->bus->add_listener(charon->bus, &this->listener->listener);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
charon->bus->remove_listener(charon->bus, &this->listener->listener);
|
||||||
|
charon->backends->remove_backend(charon->backends, &this->config->backend);
|
||||||
|
lib->credmgr->remove_set(lib->credmgr, &this->creds->set);
|
||||||
|
this->listener->destroy(this->listener);
|
||||||
|
this->config->destroy(this->config);
|
||||||
|
this->creds->destroy(this->creds);
|
||||||
|
this->db->destroy(this->db);
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
METHOD(plugin_t, get_features, int,
|
||||||
|
private_medcli_plugin_t *this, plugin_feature_t *features[])
|
||||||
|
{
|
||||||
|
static plugin_feature_t f[] = {
|
||||||
|
PLUGIN_CALLBACK((plugin_feature_callback_t)open_database, NULL),
|
||||||
|
PLUGIN_PROVIDE(CUSTOM, "medcli"),
|
||||||
|
PLUGIN_DEPENDS(DATABASE, DB_ANY),
|
||||||
|
};
|
||||||
|
*features = f;
|
||||||
|
return countof(f);
|
||||||
|
}
|
||||||
|
|
||||||
METHOD(plugin_t, destroy, void,
|
METHOD(plugin_t, destroy, void,
|
||||||
private_medcli_plugin_t *this)
|
private_medcli_plugin_t *this)
|
||||||
{
|
{
|
||||||
charon->bus->remove_listener(charon->bus, &this->listener->listener);
|
|
||||||
charon->backends->remove_backend(charon->backends, &this->config->backend);
|
|
||||||
lib->credmgr->remove_set(lib->credmgr, &this->creds->set);
|
|
||||||
this->listener->destroy(this->listener);
|
|
||||||
this->config->destroy(this->config);
|
|
||||||
this->creds->destroy(this->creds);
|
|
||||||
this->db->destroy(this->db);
|
|
||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,44 +130,17 @@ METHOD(plugin_t, destroy, void,
|
|||||||
*/
|
*/
|
||||||
plugin_t *medcli_plugin_create()
|
plugin_t *medcli_plugin_create()
|
||||||
{
|
{
|
||||||
char *uri;
|
|
||||||
private_medcli_plugin_t *this;
|
private_medcli_plugin_t *this;
|
||||||
|
|
||||||
INIT(this,
|
INIT(this,
|
||||||
.public = {
|
.public = {
|
||||||
.plugin = {
|
.plugin = {
|
||||||
.get_name = _get_name,
|
.get_name = _get_name,
|
||||||
.reload = (void*)return_false,
|
.get_features = _get_features,
|
||||||
.destroy = _destroy,
|
.destroy = _destroy,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
uri = lib->settings->get_str(lib->settings,
|
|
||||||
"medcli.database", NULL);
|
|
||||||
if (!uri)
|
|
||||||
{
|
|
||||||
DBG1(DBG_CFG, "mediation client database URI not defined, skipped");
|
|
||||||
free(this);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->db = lib->db->create(lib->db, uri);
|
|
||||||
if (this->db == NULL)
|
|
||||||
{
|
|
||||||
DBG1(DBG_CFG, "opening mediation client database failed");
|
|
||||||
free(this);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->creds = medcli_creds_create(this->db);
|
|
||||||
this->config = medcli_config_create(this->db);
|
|
||||||
this->listener = medcli_listener_create(this->db);
|
|
||||||
|
|
||||||
lib->credmgr->add_set(lib->credmgr, &this->creds->set);
|
|
||||||
charon->backends->add_backend(charon->backends, &this->config->backend);
|
|
||||||
charon->bus->add_listener(charon->bus, &this->listener->listener);
|
|
||||||
|
|
||||||
return &this->public.plugin;
|
return &this->public.plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user