Added extra parameter to config clearKey() method used to clear key(s) matching a given value.

git-svn-id: http://voip.null.ro/svn/yate@6563 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
marian 2022-06-27 08:25:05 +00:00
parent 21d6241621
commit d43863899a
1 changed files with 26 additions and 7 deletions

View File

@ -3908,7 +3908,7 @@ void* JsConfigFile::getObject(const String& name) const
return obj;
}
static void handleCfgSetValues(bool set, Configuration& cfg, const String& sName,
static inline void handleCfgSetValues(bool set, Configuration& cfg, const String& sName,
GenObject* params, const String* prefix)
{
const NamedList* pList = sName ? getReplaceParams(params) : 0;
@ -3935,6 +3935,20 @@ static void handleCfgSetValues(bool set, Configuration& cfg, const String& sName
}
}
static inline void handleCfgClearKey(Configuration& cfg, const String& sName, const String& kName,
const String* kVal = 0)
{
NamedList* sect = cfg.getSection(sName);
if (!sect)
return;
if (kVal) {
JsRegExp* r = YOBJECT(JsRegExp,kVal);
if (r)
kVal = static_cast<const String*>(&r->regexp());
}
sect->clearParam(kName,0,kVal);
}
bool JsConfigFile::runNative(ObjList& stack, const ExpOperation& oper, GenObject* context)
{
XDebug(&__plugin,DebugAll,"JsConfigFile::runNative '%s'(" FMT64 ")",oper.name().c_str(),oper.number());
@ -4101,9 +4115,13 @@ bool JsConfigFile::runNative(ObjList& stack, const ExpOperation& oper, GenObject
m_config.clearSection(op ? (const char*)*op : 0);
}
else if (oper.name() == YSTRING("clearKey")) {
if (extractArgs(stack,oper,context,args) != 2)
// clearKey(sect,key[,matchValue])
ExpOperation* sect = 0;
ExpOperation* key = 0;
ExpOperation* matchValue = 0;
if (!extractStackArgs(2,this,stack,oper,context,args,&sect,&key,&matchValue))
return false;
m_config.clearKey(*static_cast<ExpOperation*>(args[0]),*static_cast<ExpOperation*>(args[1]));
handleCfgClearKey(m_config,*sect,*key,matchValue);
}
else if (oper.name() == YSTRING("keys")) {
if (extractArgs(stack,oper,context,args) != 1)
@ -4271,11 +4289,12 @@ bool JsConfigSection::runNative(ObjList& stack, const ExpOperation& oper, GenObj
handleCfgSetValues(oper.name() == YSTRING("setValues"),m_owner->config(),toString(),params,prefix);
}
else if (oper.name() == YSTRING("clearKey")) {
if (extractArgs(stack,oper,context,args) != 1)
// clearKey(key[,matchValue])
ExpOperation* key = 0;
ExpOperation* matchValue = 0;
if (!extractStackArgs(1,this,stack,oper,context,args,&key,&matchValue))
return false;
NamedList* sect = m_owner->config().getSection(toString());
if (sect)
sect->clearParam(*static_cast<ExpOperation*>(args[0]));
handleCfgClearKey(m_owner->config(),toString(),*key,matchValue);
}
else if (oper.name() == YSTRING("keys")) {
if (extractArgs(stack,oper,context,args) != 0)