diff --git a/conf.d/register.conf.sample b/conf.d/register.conf.sample index 569e1493..a276361b 100644 --- a/conf.d/register.conf.sample +++ b/conf.d/register.conf.sample @@ -20,6 +20,9 @@ ; engine.timer: bool: Activate handler on the "engine.timer" message ;engine.timer=no +; call.preroute: bool: Activate handler on the "call.preroute" message +;call.preroute=no + ; call.route: bool: Activate handler on the "call.route" message ;call.route=no @@ -74,6 +77,13 @@ query=UPDATE users SET location=NULL,expires=NULL WHERE expires IS NOT NULL AND query=UPDATE users SET location=NULL,expires=NULL WHERE expires IS NOT NULL AND expires<=CURRENT_TIMESTAMP +[call.preroute] +; Query and result name for the prerouting message + +query= +priority=120 + + [call.route] ; Query and result name for the routing message diff --git a/engine/Channel.cpp b/engine/Channel.cpp index a0a20a4e..fb25c2f5 100644 --- a/engine/Channel.cpp +++ b/engine/Channel.cpp @@ -980,8 +980,13 @@ bool Router::route() bool ok = !tmp.null(); if (ok) m_msg->retValue() = tmp; - else + else { + if (*m_msg == "call.preroute") { + Engine::dispatch(m_msg); + *m_msg = "call.route"; + } ok = Engine::dispatch(m_msg); + } m_driver->lock(); Channel* chan = m_driver->find(m_id); diff --git a/modules/h323chan.cpp b/modules/h323chan.cpp index 4abf8b99..82e40ec5 100644 --- a/modules/h323chan.cpp +++ b/modules/h323chan.cpp @@ -962,7 +962,7 @@ H323Connection::AnswerCallResponse YateH323Connection::OnAnswerCall(const PStrin } const YateH323EndPoint& ep = static_cast(GetEndPoint()); - Message *m = m_chan->message("call.route",false,true); + Message *m = m_chan->message("call.preroute",false,true); if (ep.c_str()) m->setParam("in_line",ep.c_str()); const char *s = s_cfg.getValue("incoming","context"); diff --git a/modules/iaxchan.cpp b/modules/iaxchan.cpp index 5a544e2b..6e4a1c7d 100644 --- a/modules/iaxchan.cpp +++ b/modules/iaxchan.cpp @@ -527,7 +527,7 @@ IAXConnection::~IAXConnection() bool IAXConnection::startRouting(iax_event *e) { - Message *m = message("call.route"); + Message *m = message("call.preroute"); if (e->ies.calling_name) m->addParam("callername",e->ies.calling_name); else diff --git a/modules/libypri.cpp b/modules/libypri.cpp index 48280f33..ab3aeb8e 100644 --- a/modules/libypri.cpp +++ b/modules/libypri.cpp @@ -869,7 +869,7 @@ void PriChan::ring(pri_event_ring &ev) m_inband = m_span->inband(); openData(lookup(ev.layer1,dict_str2law),0); - m = message("call.route"); + m = message("call.preroute"); if (m_span->overlapped() && !ev.complete && (::strlen(ev.callednum) < m_span->overlapped())) { ::pri_need_more_info(m_span->pri(),m_call,m_chan,!isISDN()); m->addParam("overlapped","yes"); diff --git a/modules/register.cpp b/modules/register.cpp index e88f0d3f..d73c9cfc 100644 --- a/modules/register.cpp +++ b/modules/register.cpp @@ -40,6 +40,7 @@ public: Regist, UnRegist, Auth, + PreRoute, Route, Cdr, Timer @@ -109,7 +110,7 @@ static void replaceParams(String& str, const Message &msg) } // copy parameters from SQL result to a Message -static void copyParams(Message& msg, Array *a, const char* resultName = 0, int row = 0) +static void copyParams(Message& msg, Array* a, const char* resultName = 0, int row = 0) { if (!a) return; @@ -214,6 +215,22 @@ bool AAAHandler::received(Message& msg) return false; } break; + case PreRoute: + { + if (s_critical) + return failure(&msg); + Message m("database"); + m.addParam("account",m_account); + m.addParam("query",query); + if (Engine::dispatch(m)) + if (m.getIntValue("rows") >=1) + { + Array* a = static_cast(m.userObject("Array")); + copyParams(msg,a,m_result); + } + return false; + } + break; case Route: { if (s_critical) @@ -224,7 +241,7 @@ bool AAAHandler::received(Message& msg) if (Engine::dispatch(m)) if (m.getIntValue("rows") >=1) { - Array *a = (Array *)m.userData(); + Array* a = static_cast(m.userObject("Array")); copyParams(msg,a,m_result); if (msg.retValue().null()) { @@ -398,6 +415,7 @@ void RegistModule::initialize() addHandler("engine.timer",AAAHandler::Timer); addHandler("user.unregister",AAAHandler::UnRegist); addHandler("user.register",AAAHandler::Regist); + addHandler("call.preroute",AAAHandler::PreRoute); addHandler("call.route",AAAHandler::Route); } diff --git a/modules/ysipchan.cpp b/modules/ysipchan.cpp index f8ea4784..3639f8df 100644 --- a/modules/ysipchan.cpp +++ b/modules/ysipchan.cpp @@ -1281,7 +1281,7 @@ YateSIPConnection::YateSIPConnection(SIPEvent* ev, SIPTransaction* tr) URI uri(m_tr->getURI()); YateSIPLine* line = plugin.findLine(m_host,m_port,m_uri.getUser()); - Message *m = message("call.route"); + Message *m = message("call.preroute"); if (line) { // call comes from line we have registered to - trust it...