2017-10-16 Fred Gleason <fredg@paravelsystems.com>

* Added 'NewHostShortNameRegex=', 'NewHostShortNameGroup=',
	'NewServiceNameRegex=' and 'NewServiceNameGroup=' parameters
	to rd.conf(5).
This commit is contained in:
Fred Gleason 2017-10-16 08:45:04 -04:00
parent 52d1d8be52
commit 0607e00cd9
5 changed files with 72 additions and 6 deletions

View File

@ -16141,3 +16141,7 @@
Host' dialog.
* Added a 'Short Name' control to the 'Edit Host' dialog.
* Implemented a '%R' wildcard for Rivendell Host Short Name.
2017-10-16 Fred Gleason <fredg@paravelsystems.com>
* Added 'NewHostShortNameRegex=', 'NewHostShortNameGroup=',
'NewServiceNameRegex=' and 'NewServiceNameGroup=' parameters
to rd.conf(5).

View File

@ -594,6 +594,13 @@ void MainObject::InitProvisioning() const
if(RDStation::create(rd_config->stationName(),&err_msg,rd_config->provisioningHostTemplate(),rd_config->provisioningHostIpAddress())) {
syslog(LOG_INFO,"created new host entry \"%s\"",
(const char *)rd_config->stationName());
if(!rd_config->provisioningHostShortName(rd_config->stationName()).
isEmpty()) {
RDStation *station=new RDStation(rd_config->stationName());
station->setShortName(rd_config->
provisioningHostShortName(rd_config->stationName()));
delete station;
}
}
else {
fprintf(stderr,"caed: unable to provision host [%s]\n",
@ -610,13 +617,16 @@ void MainObject::InitProvisioning() const
//
if(rd_config->provisioningCreateService()) {
if(!rd_config->provisioningServiceTemplate().isEmpty()) {
QString svcname=
rd_config->provisioningServiceName(rd_config->stationName());
sql=QString("select NAME from SERVICES where ")+
"NAME=\""+RDEscapeString(rd_config->stationName())+"\"";
"NAME=\""+RDEscapeString(svcname)+"\"";
q=new RDSqlQuery(sql);
if(!q->first()) {
if(RDSvc::create(rd_config->stationName(),&err_msg,rd_config->provisioningServiceTemplate())) {
if(RDSvc::create(svcname,&err_msg,
rd_config->provisioningServiceTemplate())) {
syslog(LOG_INFO,"created new service entry \"%s\"",
(const char *)rd_config->stationName());
(const char *)svcname);
}
else {
fprintf(stderr,"caed: unable to provision service [%s]\n",

View File

@ -38,17 +38,26 @@ XportHostname=
; when the 'rivendell' system service is started, using the Host definition
; specified in NewHostTemplate= as the template. The new host entry will be
; assigned the IP address bound to the network interface specified by
; NewHostIpAddress= ('lo' by default).
; NewHostIpAddress= ('lo' by default). The new host's Short Name can be
; populated using the NewHostShortName= parameter, which takes a Perl-style
; regex to capture the required text from the full host name, using the
; captured group from the regex specified in 'NewHostShortNameGroup='.
CreateHost=No
NewHostTemplate=some_host_entry
NewHostIpAddress=lo
NewHostShortNameRegex=[^*]*
NewHostShortNameGroup=0
; If CreateService=Yes, a Service entry will be automatically created in the DB
; when the 'rivendell' system service is started, using the Service definition
; specified in NewServiceTemplate= as the template. The new service entry will
; have the same name as the hostname.
; specified in NewServiceTemplate= as the template. The new service's name
; is determined by the NewServiceNameRegex= parameter, which takes a Perl-style
; regex to capture the required text from the full host name, using the
; captured group from the regex specified in 'NewServiceNameGroup='.
CreateService=No
NewServiceTemplate=some_service_entry
NewServiceNameRegex=[^*]*
NewServiceNameGroup=0
[Logs]
; Set the method to be used for logging. Possible values are:

View File

@ -30,6 +30,7 @@
#endif // WIN32
#include <qmessagebox.h>
#include <qregexp.h>
#include <qsettings.h>
#include <qstringlist.h>
@ -271,6 +272,19 @@ QHostAddress RDConfig::provisioningHostIpAddress() const
}
QString RDConfig::provisioningHostShortName(const QString &hostname) const
{
QRegExp exp(conf_provisioning_host_short_name_regex);
exp.search(hostname);
QStringList texts=exp.capturedTexts();
if(texts.size()<conf_provisioning_host_short_name_group) {
return QString();
}
return texts[conf_provisioning_host_short_name_group];
}
bool RDConfig::provisioningCreateService() const
{
return conf_provisioning_create_service;
@ -283,6 +297,19 @@ QString RDConfig::provisioningServiceTemplate() const
}
QString RDConfig::provisioningServiceName(const QString &hostname) const
{
QRegExp exp(conf_provisioning_service_name_regex);
exp.search(hostname);
QStringList texts=exp.capturedTexts();
if(texts.size()<conf_provisioning_service_name_group) {
return QString();
}
return texts[conf_provisioning_service_name_group];
}
int RDConfig::alsaPeriodQuantity() const
{
return conf_alsa_period_quantity;
@ -501,10 +528,18 @@ void RDConfig::load()
conf_provisioning_host_template=
profile->stringValue("Provisioning","NewHostTemplate");
iface=profile->stringValue("Provisioning","NewHostIpAddress","lo");
conf_provisioning_host_short_name_regex=
profile->stringValue("Provisioning","NewHostShortNameRegex","[^*]*");
conf_provisioning_host_short_name_group=
profile->intValue("Provisioning","NewHostShortNameGroup");
conf_provisioning_create_service=
profile->boolValue("Provisioning","CreateService");
conf_provisioning_service_template=
profile->stringValue("Provisioning","NewServiceTemplate");
conf_provisioning_service_name_regex=
profile->stringValue("Provisioning","NewServiceNameRegex","[^*]*");
conf_provisioning_service_name_group=
profile->intValue("Provisioning","NewServiceNameGroup");
conf_audio_root=
profile->stringValue("Cae","AudioRoot",RD_AUDIO_ROOT);
@ -635,6 +670,8 @@ void RDConfig::clear()
conf_provisioning_create_host=false;
conf_provisioning_host_template="";
conf_provisioning_host_ip_address.setAddress("127.0.0.2");
conf_provisioning_host_short_name_regex="[^%]*";
conf_provisioning_host_short_name_group=0;
conf_provisioning_create_service=false;
conf_provisioning_service_template="";
conf_alsa_period_quantity=RD_ALSA_DEFAULT_PERIOD_QUANTITY;

View File

@ -69,8 +69,10 @@ class RDConfig
bool provisioningCreateHost() const;
QString provisioningHostTemplate() const;
QHostAddress provisioningHostIpAddress() const;
QString provisioningHostShortName(const QString &hostname) const;
bool provisioningCreateService() const;
QString provisioningServiceTemplate() const;
QString provisioningServiceName(const QString &hostname) const;
int alsaPeriodQuantity() const;
int alsaPeriodSize() const;
int alsaChannelsPerPcm() const;
@ -130,8 +132,12 @@ class RDConfig
bool conf_provisioning_create_host;
QString conf_provisioning_host_template;
QHostAddress conf_provisioning_host_ip_address;
QString conf_provisioning_host_short_name_regex;
unsigned conf_provisioning_host_short_name_group;
bool conf_provisioning_create_service;
QString conf_provisioning_service_template;
QString conf_provisioning_service_name_regex;
unsigned conf_provisioning_service_name_group;
bool conf_log_xload_debug_data;
int conf_alsa_period_quantity;
int conf_alsa_period_size;