Improved regexroute by allowing multiple extra handlers with different priorities and target contexts.

A match parameter can be specified for such an extra handler.
Original patch (that changed config syntax) by Allan Sandfeld Jensen.


git-svn-id: http://voip.null.ro/svn/yate@3382 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2010-06-16 10:46:22 +00:00
parent 6b84c12e8c
commit 6404b73e70
2 changed files with 46 additions and 15 deletions

View File

@ -94,11 +94,14 @@
[extra]
; This section allows installing handlers for any message name.
; Each line must be of the form:
; message.name=priority
; You can only install one handler for any given message name.
; For each handler create a corresponding [message.name] section in which
; implement handling for that specific message. You will need to match
; parameters explicitely or set a new match string.
; message.name=priority[,[paramname][,context]]
; For each handler create a corresponding [context] or [message.name] section
; in which implement handling for that specific message. If paramname is not
; set you will need to match parameters explicitely or set a new match string.
; Examples:
; engine.command=90
; call.execute=120,callto
; call.route=200,called,reroute
[contexts]

View File

@ -504,7 +504,8 @@ static bool oneContext(Message &msg, String &str, const String &context, String
DDebug("RegexRoute",DebugAll,"Returning false at end of context '%s'", context.c_str());
return false;
}
bool RouteHandler::received(Message &msg)
{
u_int64_t tmr = Time::now();
@ -522,7 +523,8 @@ bool RouteHandler::received(Message &msg)
called.c_str(),context,Time::now()-tmr);
return false;
};
class PrerouteHandler : public MessageHandler
{
public:
@ -554,29 +556,42 @@ bool PrerouteHandler::received(Message &msg)
caller.c_str(),Time::now()-tmr);
return false;
};
class GenericHandler : public MessageHandler
{
public:
GenericHandler(const char* name, int prio)
: MessageHandler(name,prio)
GenericHandler(const char* name, int prio, const char* context, const char* match)
: MessageHandler(name,prio),
m_context(context), m_match(match)
{
Debug(DebugAll,"Installing generic handler for '%s' prio %d [%p]",c_str(),prio,this);
Debug(DebugAll,"Generic handler for '%s' prio %d to [%s] match '%s%s%s' [%p]",
c_str(),prio,context,
(match ? "${" : ""),(match ? match : c_str()),(match ? "}" : ""),
this);
s_extra.append(this);
}
~GenericHandler()
{ s_extra.remove(this,false); }
virtual bool received(Message &msg);
private:
String m_context;
String m_match;
};
bool GenericHandler::received(Message &msg)
{
DDebug(DebugAll,"Handling message '%s' [%p]",c_str(),this);
String what(*this);
String what(m_match);
if (what)
what = msg.getValue(what);
else
what = *this;
Lock lock(s_mutex);
return oneContext(msg,what,*this,msg.retValue());
return oneContext(msg,what,m_context,msg.retValue());
}
class RegexRoutePlugin : public Plugin
{
public:
@ -638,8 +653,21 @@ void RegexRoutePlugin::initialize()
unsigned int len = l->length();
for (unsigned int i=0; i<len; i++) {
NamedString* n = l->getParam(i);
if (n)
Engine::install(new GenericHandler(n->name(),n->toInteger()));
if (n) {
// message=prio[:[context][:[parameter]]]
ObjList* o = n->split(',');
const String* s = static_cast<const String*>(o->at(0));
int prio = s ? s->toInteger(100) : 100;
const char* match = TelEngine::c_str(static_cast<const String*>(o->at(1)));
const char* context = TelEngine::c_str(static_cast<const String*>(o->at(2)));
if (TelEngine::null(context))
context = n->name().c_str();
if (s_cfg.getSection(context))
Engine::install(new GenericHandler(n->name(),prio,context,match));
else
Debug(DebugWarn,"Missing context [%s] for handling %s",context,n->name().c_str());
TelEngine::destruct(o);
}
}
}
}