Added a default regexp to apply where it is missing in a rule.
Greatly simplifies checking for booleans or non-empty strings. git-svn-id: http://yate.null.ro/svn/yate/trunk@4626 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
parent
3a9e1c4e6a
commit
dde4ed9ed0
|
@ -76,6 +76,11 @@
|
|||
; insensitive: bool: Make the regular expressions case insensitive
|
||||
;insensitive=no
|
||||
|
||||
; defaultrule: regexp: Default expression to use in matches if not specified
|
||||
; Works only for ${param} or $(expression) matches
|
||||
; Default matches any string that is not empty or explicitely false or zero
|
||||
;defaultrule=^\(false\|no\|off\|disable\|f\|0*\)$^
|
||||
|
||||
; prerouteall: bool: Preroute even calls having a context or with empty caller
|
||||
;prerouteall=no
|
||||
|
||||
|
|
|
@ -30,11 +30,14 @@
|
|||
using namespace TelEngine;
|
||||
namespace { // anonymous
|
||||
|
||||
#define DEFAULT_RULE "^\\(false\\|no\\|off\\|disable\\|f\\|0*\\)$^"
|
||||
|
||||
static Configuration s_cfg;
|
||||
static bool s_extended;
|
||||
static bool s_insensitive;
|
||||
static bool s_prerouteall;
|
||||
static int s_maxDepth = 5;
|
||||
static String s_defRule;
|
||||
static Mutex s_mutex(true,"RegexRoute");
|
||||
static ObjList s_extra;
|
||||
static NamedList s_vars("");
|
||||
|
@ -381,6 +384,22 @@ static void setMessage(const String& match, Message& msg, String& line, Message*
|
|||
strs->destruct();
|
||||
}
|
||||
|
||||
// helper function to set the default regexp
|
||||
static void setDefault(Regexp& reg)
|
||||
{
|
||||
if (s_defRule.null())
|
||||
return;
|
||||
if (reg.null())
|
||||
reg = s_defRule;
|
||||
else if (reg == "^") {
|
||||
// deal with double '^' at end
|
||||
if (s_defRule.endsWith("^"))
|
||||
reg.assign(s_defRule,s_defRule.length()-1);
|
||||
else
|
||||
reg = s_defRule + reg;
|
||||
}
|
||||
}
|
||||
|
||||
// helper function to process one match attempt
|
||||
static bool oneMatch(const NamedList& msg, Regexp& reg, String& match, const String& context, unsigned int rule)
|
||||
{
|
||||
|
@ -404,6 +423,7 @@ static bool oneMatch(const NamedList& msg, Regexp& reg, String& match, const Str
|
|||
match = match.substr(0,p);
|
||||
match.trimBlanks();
|
||||
}
|
||||
setDefault(reg);
|
||||
if (match.null() || reg.null()) {
|
||||
Debug("RegexRoute",DebugWarn,"Missing parameter or rule in rule #%u in context '%s'",
|
||||
rule,context.c_str());
|
||||
|
@ -424,6 +444,7 @@ static bool oneMatch(const NamedList& msg, Regexp& reg, String& match, const Str
|
|||
match = reg.substr(0,p+1);
|
||||
reg = reg.substr(p+1);
|
||||
reg.trimBlanks();
|
||||
setDefault(reg);
|
||||
if (reg.null()) {
|
||||
Debug("RegexRoute",DebugWarn,"Missing rule in rule #%u in context '%s'",
|
||||
rule,context.c_str());
|
||||
|
@ -726,6 +747,7 @@ void RegexRoutePlugin::initialize()
|
|||
else if (depth > 100)
|
||||
depth = 100;
|
||||
s_maxDepth = depth;
|
||||
s_defRule = s_cfg.getValue("priorities","defaultrule",DEFAULT_RULE);
|
||||
NamedList* l = s_cfg.getSection("extra");
|
||||
if (l) {
|
||||
unsigned int len = l->length();
|
||||
|
|
Loading…
Reference in New Issue