Allow creating many gateway trunks using one section as template.

Keeps the config file small and readable for high density gateways.


git-svn-id: http://voip.null.ro/svn/yate@3316 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2010-05-12 17:36:52 +00:00
parent 8e07c5fd49
commit 32ea971f33
2 changed files with 41 additions and 7 deletions

View File

@ -127,6 +127,14 @@
; or TGCP protocols too.
;version=
; range: string: Range of gateways to create using this section as a template
; If range is not empty the "user" setting must contain an asterisk
; Example for creating aaln1/[1-10], aaln2/[1-10], aaln3/[1-10] and aaln6/[1-10]:
; user=aaln*/1
; chans=10
; range=1-3,6
;range=
; cluster: bool: This is the gateway to send remote RTP commands to
; Do not activate this functionality unless you know very well what it does
; as it disrupts other based RTP protocols

View File

@ -864,7 +864,14 @@ bool MGCPSpan::init(const NamedList& params)
if ((cicStart < 0) || !sect)
return false;
Configuration cfg(Engine::configFile("mgcpca"));
const NamedList* config = cfg.getSection("gw " + *sect);
String sn = "gw " + *sect;
const NamedList* config = cfg.getSection(sn);
if (!config) {
// Try to find a template section for gateway:number
int sep = sn.rfind(':');
if (sep > 0)
config = cfg.getSection(sn.substr(0,sep));
}
if (!config) {
Debug(m_group,DebugWarn,"MGCPSpan('%s'). Failed to find config section [%p]",
id().safe(),this);
@ -1851,13 +1858,32 @@ void MGCPPlugin::initialize()
cfg.getIntValue("endpoint","port")
);
}
MGCPEpInfo* ep = s_endpoint->append(
sect->getValue("user",name),
host,
sect->getIntValue("port",0)
);
int port = sect->getIntValue("port",0);
String user = sect->getValue("user",name);
name = sect->getValue("name",name);
SignallingCircuitRange range(sect->getValue("range"));
if (range.count() && user.find('*') >= 0) {
// This section is a template
for (unsigned int idx = 0; idx < range.count(); idx++) {
String num(range[idx]);
String tmpN = name + ":" + num;
String tmpU(user);
// Replace * with number
int sep;
while ((sep = tmpU.find('*')) >= 0)
tmpU = tmpU.substr(0,sep) + num + tmpU.substr(sep+1);
MGCPEpInfo* ep = s_endpoint->append(tmpU,host,port);
if (ep)
ep->alias = tmpN;
else
Debug(this,DebugWarn,"Could not set user '%s' for gateway '%s'",
tmpU.c_str(),tmpN.c_str());
}
continue;
}
MGCPEpInfo* ep = s_endpoint->append(user,host,port);
if (ep) {
ep->alias = sect->getValue("name",name);
ep->alias = name;
if (sect->getBoolValue("cluster",false))
s_defaultEp = ep->toString();
}