Added functions used to set/add a list of parameters in configuration and section.

git-svn-id: http://voip.null.ro/svn/yate@6532 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
marian 2021-12-22 07:03:35 +00:00
parent 8862918e65
commit f74685918c
1 changed files with 50 additions and 0 deletions

View File

@ -752,6 +752,8 @@ public:
params().addParam(new ExpFunction("getBoolValue"));
params().addParam(new ExpFunction("setValue"));
params().addParam(new ExpFunction("addValue"));
params().addParam(new ExpFunction("setValues"));
params().addParam(new ExpFunction("addValues"));
params().addParam(new ExpFunction("clearSection"));
params().addParam(new ExpFunction("clearKey"));
params().addParam(new ExpFunction("keys"));
@ -791,6 +793,8 @@ protected:
params().addParam(new ExpFunction("getBoolValue"));
params().addParam(new ExpFunction("setValue"));
params().addParam(new ExpFunction("addValue"));
params().addParam(new ExpFunction("setValues"));
params().addParam(new ExpFunction("addValues"));
params().addParam(new ExpFunction("clearKey"));
params().addParam(new ExpFunction("keys"));
}
@ -3689,6 +3693,33 @@ void* JsConfigFile::getObject(const String& name) const
return obj;
}
static void handleCfgSetValues(bool set, Configuration& cfg, const String& sName,
GenObject* params, const String* prefix)
{
const NamedList* pList = sName ? getReplaceParams(params) : 0;
if (!pList)
return;
NamedList* sect = cfg.createSection(sName);
if (TelEngine::null(prefix))
prefix = 0;
for (ObjList* o = pList->paramList()->skipNull(); o; o = o->skipNext()) {
NamedString* ns = static_cast<NamedString*>(o->get());
JsObject* jso = YOBJECT(JsObject,ns);
if (jso || ns->name() == JsObject::protoName())
continue;
if (set) {
if (prefix)
sect->setParam(*prefix + ns->name(),*ns);
else
sect->setParam(ns->name(),*ns);
}
else if (prefix)
sect->addParam(*prefix + ns->name(),*ns);
else
sect->addParam(ns->name(),*ns);
}
}
bool JsConfigFile::runNative(ObjList& stack, const ExpOperation& oper, GenObject* context)
{
XDebug(&__plugin,DebugAll,"JsConfigFile::runNative '%s'(" FMT64 ")",oper.name().c_str(),oper.number());
@ -3829,6 +3860,16 @@ bool JsConfigFile::runNative(ObjList& stack, const ExpOperation& oper, GenObject
m_config.addValue(*static_cast<ExpOperation*>(args[0]),*static_cast<ExpOperation*>(args[1]),
*static_cast<ExpOperation*>(args[2]));
}
else if (oper.name() == YSTRING("setValues") || oper.name() == YSTRING("addValues")) {
// setValues(sect,params[,prefix])
// addValues(sect,params[,prefix])
ExpOperation* sName = 0;
ExpOperation* params = 0;
ExpOperation* prefix = 0;
if (!extractStackArgs(2,this,stack,oper,context,args,&sName,&params,&prefix))
return false;
handleCfgSetValues(oper.name() == YSTRING("setValues"),m_config,*sName,params,prefix);
}
else if (oper.name() == YSTRING("clearSection")) {
ExpOperation* op = 0;
switch (extractArgs(stack,oper,context,args)) {
@ -4005,6 +4046,15 @@ bool JsConfigSection::runNative(ObjList& stack, const ExpOperation& oper, GenObj
if (sect)
sect->addParam(*static_cast<ExpOperation*>(args[0]),*static_cast<ExpOperation*>(args[1]));
}
else if (oper.name() == YSTRING("setValues") || oper.name() == YSTRING("addValues")) {
// setValues(params[,prefix])
// addValues(params[,prefix])
ExpOperation* params = 0;
ExpOperation* prefix = 0;
if (!extractStackArgs(1,this,stack,oper,context,args,&params,&prefix))
return false;
handleCfgSetValues(oper.name() == YSTRING("setValues"),m_owner->config(),toString(),params,prefix);
}
else if (oper.name() == YSTRING("clearKey")) {
if (extractArgs(stack,oper,context,args) != 1)
return false;