ipseckey: Allow en-/disabling at runtime using plugin reload feature

This commit is contained in:
Tobias Brunner
2013-06-11 11:18:18 +02:00
parent 82d3f5122b
commit 21d094f402
@@ -49,6 +49,28 @@ METHOD(plugin_t, get_name, char*,
return "ipseckey"; return "ipseckey";
} }
METHOD(plugin_t, reload, bool,
private_ipseckey_plugin_t *this)
{
bool enabled = lib->settings->get_bool(lib->settings,
"%s.plugins.ipseckey.enable", FALSE, charon->name);
if (enabled != this->enabled)
{
if (enabled)
{
lib->credmgr->add_set(lib->credmgr, &this->cred->set);
}
else
{
lib->credmgr->remove_set(lib->credmgr, &this->cred->set);
}
this->enabled = enabled;
}
DBG1(DBG_CFG, "ipseckey plugin is %sabled", this->enabled ? "en" : "dis");
return TRUE;
}
/** /**
* Create resolver and register credential set * Create resolver and register credential set
*/ */
@@ -66,23 +88,16 @@ static bool plugin_cb(private_ipseckey_plugin_t *this,
return FALSE; return FALSE;
} }
if (this->enabled) this->cred = ipseckey_cred_create(res);
{ reload(this);
this->cred = ipseckey_cred_create(res);
lib->credmgr->add_set(lib->credmgr, &this->cred->set);
}
else
{
res->destroy(res);
}
} }
else else
{ {
if (this->enabled) if (this->enabled)
{ {
lib->credmgr->remove_set(lib->credmgr, &this->cred->set); lib->credmgr->remove_set(lib->credmgr, &this->cred->set);
this->cred->destroy(this->cred);
} }
this->cred->destroy(this->cred);
} }
return TRUE; return TRUE;
} }
@@ -117,11 +132,10 @@ plugin_t *ipseckey_plugin_create()
.plugin = { .plugin = {
.get_name = _get_name, .get_name = _get_name,
.get_features = _get_features, .get_features = _get_features,
.reload = _reload,
.destroy = _destroy, .destroy = _destroy,
}, },
}, },
.enabled = lib->settings->get_bool(lib->settings,
"%s.plugins.ipseckey.enable", FALSE, charon->name),
); );
return &this->public.plugin; return &this->public.plugin;