shunt-manager: Remove first match if no namespace given during uninstall

Also makes namespace mandatory.
This commit is contained in:
Tobias Brunner 2017-11-03 10:47:48 +01:00
parent c1c63a400e
commit 57ea3f73bb
2 changed files with 16 additions and 7 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2015-2016 Tobias Brunner
* Copyright (C) 2015-2017 Tobias Brunner
* Copyright (C) 2011-2016 Andreas Steffen
* HSR Hochschule fuer Technik Rapperswil
*
@ -198,6 +198,13 @@ METHOD(shunt_manager_t, install, bool,
entry_t *entry;
bool found = FALSE, success;
if (!ns)
{
DBG1(DBG_CFG, "missing namespace for shunt policy '%s'",
cfg->get_name(cfg));
return FALSE;
}
/* check if not already installed */
this->lock->write_lock(this->lock);
if (this->installing == INSTALL_DISABLED)
@ -224,7 +231,7 @@ METHOD(shunt_manager_t, install, bool,
return TRUE;
}
INIT(entry,
.ns = strdupnull(ns),
.ns = strdup(ns),
.cfg = cfg->get_ref(cfg),
);
this->shunts->insert_last(this->shunts, entry);
@ -369,7 +376,7 @@ METHOD(shunt_manager_t, uninstall, bool,
enumerator = this->shunts->create_enumerator(this->shunts);
while (enumerator->enumerate(enumerator, &entry))
{
if (streq(ns, entry->ns) &&
if ((!ns || streq(ns, entry->ns)) &&
streq(name, entry->cfg->get_name(entry->cfg)))
{
this->shunts->remove_at(this->shunts, enumerator);

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2015-2016 Tobias Brunner
* Copyright (C) 2015-2017 Tobias Brunner
* Copyright (C) 2011 Andreas Steffen
* HSR Hochschule fuer Technik Rapperswil
*
@ -36,8 +36,7 @@ struct shunt_manager_t {
/**
* Install a policy as a shunt.
*
* @param ns optional namespace (e.g. name of a connection or
* plugin), cloned
* @param ns namespace (e.g. name of a connection or plugin), cloned
* @param child child configuration to install as a shunt
* @return TRUE if installed successfully
*/
@ -46,7 +45,10 @@ struct shunt_manager_t {
/**
* Uninstall a shunt policy.
*
* @param ns namespace (same as given during installation)
* If no namespace is given the first matching child configuration is
* removed.
*
* @param ns namespace (same as given during installation) or NULL
* @param name name of child configuration to uninstall as a shunt
* @return TRUE if uninstalled successfully
*/