From 1fd0dc1670fd6664ac6f4f063c6da92398998d67 Mon Sep 17 00:00:00 2001 From: paulc Date: Wed, 16 Mar 2011 23:31:07 +0000 Subject: [PATCH] Added support for delivering Caller ID over analog FXS MGCP gateways. git-svn-id: http://voip.null.ro/svn/yate@4188 acf43c95-373e-0410-b603-e72c3f656dc1 --- conf.d/mgcpca.conf.sample | 6 ++++++ modules/server/analog.cpp | 14 +++++++++++--- modules/server/mgcpca.cpp | 25 ++++++++++++++++++++++++- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/conf.d/mgcpca.conf.sample b/conf.d/mgcpca.conf.sample index be56f12d..2e05df4e 100644 --- a/conf.d/mgcpca.conf.sample +++ b/conf.d/mgcpca.conf.sample @@ -4,6 +4,12 @@ ; priority: int: Priority of the chan.rtp message handler ;priority=80 +; tzoffset: int: Timezone offset from GMT in seconds for sending Caller ID +; Positive to go East, negative to go West +; Examples: CET=3600, EST=-18000 +; This parameter is reloadable +;tzoffset=0 + [engine] ; These parameters are used to initialize the MGCP Engine diff --git a/modules/server/analog.cpp b/modules/server/analog.cpp index 81b9b195..b7d56397 100644 --- a/modules/server/analog.cpp +++ b/modules/server/analog.cpp @@ -71,7 +71,7 @@ public: const char* called = 0) { m_caller = caller; m_callerName = callername; m_called = called; } // Set the caller, callername and called parameters - void copyCall(Message& dest, bool privacy = false); + void copyCall(NamedList& dest, bool privacy = false); // Fill a string with line status parameters void statusParams(String& str); // Fill a string with line status detail parameters @@ -680,7 +680,7 @@ void ModuleLine::processNotify(Message& msg) } // Set the caller, callername and called parameters -void ModuleLine::copyCall(Message& dest, bool privacy) +void ModuleLine::copyCall(NamedList& dest, bool privacy) { if (privacy) dest.addParam("callerpres","restricted"); @@ -1409,7 +1409,15 @@ AnalogChannel::AnalogChannel(ModuleLine* line, Message* msg, RecordTrigger recor m_privacy = getPrivacy(*msg); if (m_callsetup == AnalogLine::Before) m_line->sendCallSetup(m_privacy); - m_line->sendEvent(SignallingCircuitEvent::RingBegin,AnalogLine::Dialing); + { + NamedList* params = 0; + NamedList callerId(""); + if (m_callsetup != AnalogLine::NoCallSetup) { + params = &callerId; + m_line->copyCall(callerId,m_privacy); + } + m_line->sendEvent(SignallingCircuitEvent::RingBegin,AnalogLine::Dialing,params); + } if (m_callsetup == AnalogLine::After) m_dialTimer.interval(500); break; diff --git a/modules/server/mgcpca.cpp b/modules/server/mgcpca.cpp index ebf25cfb..48708c70 100644 --- a/modules/server/mgcpca.cpp +++ b/modules/server/mgcpca.cpp @@ -31,6 +31,7 @@ #include #include +#include using namespace TelEngine; namespace { // anonymous @@ -300,6 +301,7 @@ YSIGFACTORY2(MGCPSpan); static YMGCPEngine* s_engine = 0; static MGCPEndpoint* s_endpoint = 0; static String s_defaultEp; +static int s_tzOffset = 0; static MGCPPlugin splugin; static ObjList s_wrappers; @@ -1696,7 +1698,27 @@ bool MGCPCircuit::sendEvent(SignallingCircuitEvent::Type type, NamedList* params setParams(*params); return status(Connected,!params || params->getBoolValue("sync",true)); case SignallingCircuitEvent::RingBegin: - return fxs() && sendPending("L/rg"); + if (fxs()) { + String s("L/rg"); + if (params) { + String number = params->getValue("caller"); + String name = params->getValue("callername"); + if (number || name) { + MimeHeaderLine::addQuotes(number); + MimeHeaderLine::addQuotes(name); + int year; + unsigned int month,day,hour,minutes,seconds; + int tzo = params->getIntValue("tzoffset",s_tzOffset); + Time::toDateTime(Time::secNow()+tzo,year,month,day,hour,minutes,seconds); + char buf[16]; + ::snprintf(buf,sizeof(buf),"%02u/%02u/%02u/%02u",month,day,hour,minutes); + buf[sizeof(buf)-1] = '\0'; + s << ",L/ci(" << buf << "," << number << "," << name << ")"; + } + } + return sendPending(s); + } + return false; case SignallingCircuitEvent::RingEnd: return sendPending(); case SignallingCircuitEvent::Polarity: @@ -1956,6 +1978,7 @@ void MGCPPlugin::initialize() Output("Initializing module MGCP Call Agent"); Configuration cfg(Engine::configFile("mgcpca")); setup(); + s_tzOffset = cfg.getIntValue("general","tzoffset",0); NamedList* engSect = cfg.getSection("engine"); if (s_engine && engSect) s_engine->initialize(*engSect);