From 07b04627c5d7495bc6ebe3afae6cff485d3a037b Mon Sep 17 00:00:00 2001 From: marian Date: Thu, 3 Oct 2013 12:42:20 +0000 Subject: [PATCH] Added extra parameter to NamedList::copySubParams() used when wanting to replace existing parameters instead of adding a new one. git-svn-id: http://yate.null.ro/svn/yate/trunk@5658 acf43c95-373e-0410-b603-e72c3f656dc1 --- engine/NamedList.cpp | 16 ++++++++++++---- yateclass.h | 4 +++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/engine/NamedList.cpp b/engine/NamedList.cpp index 7b349424..208e4f8f 100644 --- a/engine/NamedList.cpp +++ b/engine/NamedList.cpp @@ -194,10 +194,12 @@ NamedList& NamedList::copyParams(const NamedList& original, const String& list, return *this; } -NamedList& NamedList::copySubParams(const NamedList& original, const String& prefix, bool skipPrefix) +NamedList& NamedList::copySubParams(const NamedList& original, const String& prefix, + bool skipPrefix, bool replace) { - XDebug(DebugInfo,"NamedList::copySubParams(%p,\"%s\",%s) [%p]", - &original,prefix.c_str(),String::boolText(skipPrefix),this); + XDebug(DebugInfo,"NamedList::copySubParams(%p,\"%s\",%s,%s) [%p]", + &original,prefix.c_str(),String::boolText(skipPrefix), + String::boolText(replace),this); if (prefix) { unsigned int offs = skipPrefix ? prefix.length() : 0; ObjList* dest = &m_params; @@ -205,8 +207,14 @@ NamedList& NamedList::copySubParams(const NamedList& original, const String& pre const NamedString* s = static_cast(l->get()); if (s->name().startsWith(prefix)) { const char* name = s->name().c_str() + offs; - if (*name) + if (!*name) + continue; + if (!replace) dest = dest->append(new NamedString(name,*s)); + else if (offs) + setParam(name,*s); + else + setParam(s->name(),*s); } } } diff --git a/yateclass.h b/yateclass.h index f02f25da..fbdd081c 100644 --- a/yateclass.h +++ b/yateclass.h @@ -4397,9 +4397,11 @@ public: * @param original Named list to copy parameters from * @param prefix Prefix to match in parameter names, must not be NULL * @param skipPrefix Skip over the prefix when building new parameter name + * @param replace Set to true to replace list parameter instead of adding a new one * @return Reference to this NamedList */ - NamedList& copySubParams(const NamedList& original, const String& prefix, bool skipPrefix = true); + NamedList& copySubParams(const NamedList& original, const String& prefix, + bool skipPrefix = true, bool replace = false); /** * Check if we have a parameter that starts with prefix