Add option to set a filter to extra installed handlers.

git-svn-id: http://voip.null.ro/svn/yate@6553 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
oana 2022-04-05 08:06:11 +00:00
parent 67ca493a9c
commit 987601dd20
1 changed files with 22 additions and 13 deletions

View File

@ -57,7 +57,7 @@ class GenericHandler : public MessageHandler
{ {
public: public:
GenericHandler(const char* name, int prio, const char* context, const char* match, GenericHandler(const char* name, int prio, const char* context, const char* match,
const char* trackName, bool addToExtra = true); const char* trackName, const char* filterKey, const char* filterVal, bool addToExtra = true);
~GenericHandler(); ~GenericHandler();
virtual bool received(Message &msg); virtual bool received(Message &msg);
inline bool sameHash(unsigned int hash) const inline bool sameHash(unsigned int hash) const
@ -67,8 +67,9 @@ public:
inline void updateSerial() inline void updateSerial()
{ m_serial = s_serial.count(); } { m_serial = s_serial.count(); }
static inline unsigned int getHash(const char* name, int prio, const char* context, static inline unsigned int getHash(const char* name, int prio, const char* context,
const char* match, const char* trackName) const char* match, const char* trackName,const char* filterKey, const char* filterVal)
{ return String::hash(String(name) << prio << context << match << trackName); } { return String::hash(String(name) << prio << context << match
<< trackName << filterKey << filterVal); }
private: private:
String m_context; String m_context;
@ -82,7 +83,7 @@ class RouteHandler : public GenericHandler
{ {
public: public:
RouteHandler(int prio, const char* trackName) RouteHandler(int prio, const char* trackName)
: GenericHandler("call.route",prio,0,0,trackName,false) : GenericHandler("call.route",prio,0,0,trackName,0,0,false)
{ } { }
virtual bool received(Message &msg); virtual bool received(Message &msg);
}; };
@ -91,7 +92,7 @@ class PrerouteHandler : public GenericHandler
{ {
public: public:
PrerouteHandler(int prio, const char* trackName) PrerouteHandler(int prio, const char* trackName)
: GenericHandler("call.preroute",prio,0,0,trackName,false) : GenericHandler("call.preroute",prio,0,0,trackName,0,0,false)
{ } { }
virtual bool received(Message &msg); virtual bool received(Message &msg);
}; };
@ -584,7 +585,7 @@ do { \
if (!handler) \ if (!handler) \
Engine::install(handler = new classType(priority,trackName)); \ Engine::install(handler = new classType(priority,trackName)); \
else { \ else { \
unsigned int hash = GenericHandler::getHash(name,priority,0,0,trackName); \ unsigned int hash = GenericHandler::getHash(name,priority,0,0,trackName,0,0); \
if (!handler->sameHash(hash)) { \ if (!handler->sameHash(hash)) { \
classType* tmp = handler; \ classType* tmp = handler; \
Engine::install(handler = new classType(priority,trackName)); \ Engine::install(handler = new classType(priority,trackName)); \
@ -651,7 +652,7 @@ void RegexConfig::initialize(bool first)
for (unsigned int i=0; i<len; i++) { for (unsigned int i=0; i<len; i++) {
NamedString* n = l->getParam(i); NamedString* n = l->getParam(i);
if (n) { if (n) {
// message=priority[,[parameter][,context]] // message=priority[,[parameter][,context],filter_param,filter_match]
ObjList* o = n->split(','); ObjList* o = n->split(',');
const String* s = static_cast<const String*>(o->at(0)); const String* s = static_cast<const String*>(o->at(0));
int prio = s ? s->toInteger(100) : 100; int prio = s ? s->toInteger(100) : 100;
@ -659,11 +660,13 @@ void RegexConfig::initialize(bool first)
const char* context = TelEngine::c_str(static_cast<const String*>(o->at(2))); const char* context = TelEngine::c_str(static_cast<const String*>(o->at(2)));
if (TelEngine::null(context)) if (TelEngine::null(context))
context = n->name().c_str(); context = n->name().c_str();
const char* key = TelEngine::c_str(static_cast<const String*>(o->at(3)));
const char* val = TelEngine::c_str(static_cast<const String*>(o->at(4)));
// check if we have the same handler already installed // check if we have the same handler already installed
GenericHandler* old = findHandler(GenericHandler::getHash(n->name(),prio,context,match,trackName)); GenericHandler* old = findHandler(GenericHandler::getHash(n->name(),prio,context,match,trackName,key,val));
if (m_cfg.getSection(context)) { if (m_cfg.getSection(context)) {
if (!old) if (!old)
Engine::install(new GenericHandler(n->name(),prio,context,match,trackName)); Engine::install(new GenericHandler(n->name(),prio,context,match,trackName,key,val));
else else
old->updateSerial(); old->updateSerial();
} }
@ -1144,16 +1147,22 @@ bool PrerouteHandler::received(Message &msg)
GenericHandler::GenericHandler(const char* name, int prio, const char* context, const char* match, GenericHandler::GenericHandler(const char* name, int prio, const char* context, const char* match,
const char* trackName, bool addToExtra) const char* trackName, const char* filterKey, const char* filterVal, bool addToExtra)
: MessageHandler(name,prio,trackName), : MessageHandler(name,prio,trackName),
m_context(context), m_match(match), m_serial(0), m_inExtra(addToExtra) m_context(context), m_match(match), m_serial(0), m_inExtra(addToExtra)
{ {
DDebug(&__plugin,DebugAll, DDebug(&__plugin,DebugAll,
"Creating generic handler for '%s' prio %d to [%s] match '%s%s%s', track name '%s' [%p]", "Creating generic handler for '%s' prio %d to [%s] match '%s%s%s', track name '%s', filter '%s=%s' [%p]",
toString().c_str(),prio,TelEngine::c_safe(context), toString().c_str(),prio,TelEngine::c_safe(context),
(match ? "${" : ""),(match ? match : toString().c_str()),(match ? "}" : ""), (match ? "${" : ""),(match ? match : toString().c_str()),(match ? "}" : ""),
TelEngine::c_safe(trackName),this); TelEngine::c_safe(trackName),TelEngine::c_safe(filterKey),TelEngine::c_safe(filterVal),this);
m_hash = getHash(name,prio,context,match,trackName); if (filterKey && filterVal) {
if (filterVal[0] == '^')
setFilter(new NamedPointer(filterKey,new Regexp(filterVal)));
else
setFilter(filterKey,filterVal);
}
m_hash = getHash(name,prio,context,match,trackName,filterKey,filterVal);
if (m_inExtra) { if (m_inExtra) {
Lock l(s_mutex); Lock l(s_mutex);
s_extra.append(this); s_extra.append(this);