diff --git a/ChangeLog b/ChangeLog index b08b2d32..8d77c6f9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 + * Added 'NewHostShortNameRegex=', 'NewHostShortNameGroup=', + 'NewServiceNameRegex=' and 'NewServiceNameGroup=' parameters + to rd.conf(5). diff --git a/cae/cae.cpp b/cae/cae.cpp index 040fd743..ceb0bc12 100644 --- a/cae/cae.cpp +++ b/cae/cae.cpp @@ -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", diff --git a/conf/rd.conf-sample b/conf/rd.conf-sample index 746a1d73..ba162c71 100644 --- a/conf/rd.conf-sample +++ b/conf/rd.conf-sample @@ -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: diff --git a/lib/rdconfig.cpp b/lib/rdconfig.cpp index c2ecc6cd..dd43720e 100644 --- a/lib/rdconfig.cpp +++ b/lib/rdconfig.cpp @@ -30,6 +30,7 @@ #endif // WIN32 #include +#include #include #include @@ -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()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; diff --git a/lib/rdconfig.h b/lib/rdconfig.h index 01db62c6..f6a5e8c1 100644 --- a/lib/rdconfig.h +++ b/lib/rdconfig.h @@ -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;