diff --git a/.gitignore b/.gitignore index 492fe2a4..2b30a469 100644 --- a/.gitignore +++ b/.gitignore @@ -155,6 +155,7 @@ tests/mcast_recv_test tests/metadata_wildcard_test tests/meterstrip_test tests/notification_test +tests/provisioning_test tests/rdwavefile_test tests/rdxml_parse_test tests/readcd_test diff --git a/ChangeLog b/ChangeLog index 22f217c8..c66c54ac 100644 --- a/ChangeLog +++ b/ChangeLog @@ -25058,3 +25058,8 @@ 2025-04-28 Fred Gleason * Added a '--dump-config' switch to the set of common options in 'RDCoreApplications'. +2025-04-29 Fred Gleason + * Modified regex code in ' RDConfig::provisioningHostShortName()' and + 'RDConfig::provisioningServiceName()' to use the QRegularExpression + class rather than QRegExp. + * Added a 'test_provisioning' test harness in 'tests/'. diff --git a/conf/rd.conf-sample b/conf/rd.conf-sample index 9f8d0125..1902fdec 100644 --- a/conf/rd.conf-sample +++ b/conf/rd.conf-sample @@ -117,7 +117,7 @@ XportHostname= CreateHost=No NewHostTemplate=some_host_entry NewHostIpAddress=lo -NewHostShortNameRegex=[^*]* +NewHostShortNameRegex=(\w+)-(\w+) NewHostShortNameGroup=0 ; If CreateService=Yes, a Service entry will be automatically created in the DB @@ -128,7 +128,7 @@ NewHostShortNameGroup=0 ; captured group from the regex specified in 'NewServiceNameGroup='. CreateService=No NewServiceTemplate=some_service_entry -NewServiceNameRegex=[^*]* +NewServiceNameRegex=(\w+)-(\w+) NewServiceNameGroup=0 [Logs] diff --git a/configure.ac b/configure.ac index 6db9fd75..1fa8712c 100644 --- a/configure.ac +++ b/configure.ac @@ -89,21 +89,6 @@ AC_ARG_ENABLE(rdxport-debug,[ --enable-rdxport-debug enable DEBUG support for AC_ARG_ENABLE(i18n-updates,[ --enable-i18n-updates enable I18N metadata updates], [I18N_ENABLED=yes],[]) - -# -# Check for Qt5 (Mandatory) -# -#PKG_CHECK_MODULES(QT5,Qt5Core Qt5Widgets Qt5Gui Qt5Network Qt5Sql Qt5Xml Qt5WebKitWidgets,,[AC_MSG_ERROR([*** Qt5 not found ***])]) -#PKG_CHECK_MODULES(QT5_CLI,Qt5Core Qt5Network Qt5Sql Qt5Xml,,[AC_MSG_ERROR([*** Qt5 not found ***])]) -#AC_CHECK_PROG(MOC_NAME,moc-qt5,[moc-qt5],[moc]) -#AC_SUBST(QT_MOC,$MOC_NAME) - -#AC_CHECK_PROG(LUPDATE_NAME,lupdate-qt5,[lupdate-qt5],[lupdate]) -#AC_SUBST(QT_LUPDATE,$LUPDATE_NAME) - -#AC_CHECK_PROG(LRELEASE_NAME,lrelease-qt5,[lrelease-qt5],[lrelease]) -#AC_SUBST(QT_LRELEASE,$LRELEASE_NAME) - # # Check for Qt6 (Mandatory) # @@ -115,7 +100,6 @@ AC_SUBST(QT_LUPDATE,$LUPDATE_NAME) AC_CHECK_PROG(LRELEASE_NAME,lrelease-qt6,[lrelease-qt6],[lrelease]) AC_SUBST(QT_LRELEASE,$LRELEASE_NAME) - # # Determine the target architecture # diff --git a/docs/manpages/rd.conf.xml b/docs/manpages/rd.conf.xml index 56af1d01..499b2041 100644 --- a/docs/manpages/rd.conf.xml +++ b/docs/manpages/rd.conf.xml @@ -536,7 +536,8 @@ The name of an existing network interface from which to - extract the IP address of a newly provisioned Host. + extract the IP address to be assigned to a newly provisioned + Host entry. @@ -546,7 +547,7 @@ - A regular express to use when setting the Short Name of a + A regular expression to use when setting the Short Name of a newly provisioned Host from the system host name. diff --git a/lib/rdconfig.cpp b/lib/rdconfig.cpp index c70160da..59aeecc7 100644 --- a/lib/rdconfig.cpp +++ b/lib/rdconfig.cpp @@ -30,7 +30,7 @@ #include #include -#include +#include #include #include @@ -255,17 +255,10 @@ QHostAddress RDConfig::provisioningHostIpAddress() const QString RDConfig::provisioningHostShortName(const QString &hostname) const { - /* - * FIXME: Reimplement using QRegularExpression - */ - QRegExp exp(conf_provisioning_host_short_name_regex); + QRegularExpression regex(conf_provisioning_host_short_name_regex); + QRegularExpressionMatch match=regex.match(hostname); - exp.indexIn(hostname); - QStringList texts=exp.capturedTexts(); - if((unsigned)texts.size() +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// + +#include +#include + +#include + +#include +#include +#include + +#include "provisioning_test.h" + +MainObject::MainObject(QObject *parent) + :QObject(parent) +{ + QString config_filename=RD_CONF_FILE; + QString test_host_name; + + // + // Read Command Line + // + RDCmdSwitch *cmd=new RDCmdSwitch("provisioning_test",PROVISIONING_TEST_USAGE); + for(unsigned i=0;ikeys();i++) { + if(cmd->key(i)=="--config-file") { + config_filename=cmd->value(i); + cmd->setProcessed(i,true); + } + if(cmd->key(i)=="--test-host-name") { + test_host_name=cmd->value(i); + cmd->setProcessed(i,true); + } + if(!cmd->processed(i)) { + fprintf(stderr,"provisioning_test: unknown option\n"); + exit(1); + } + } + if(test_host_name.isEmpty()) { + char name[HOST_NAME_MAX]; + if(gethostname(name,HOST_NAME_MAX)<0) { + fprintf(stderr,"provisioning_test: %s\n",strerror(errno)); + exit(1); + } + test_host_name=QString::fromUtf8(name); + } + + // + // Run Test + // + RDConfig *config=new RDConfig(config_filename); + if(!config->load()) { + fprintf(stderr,"provisioning_test: failed to load config file\n"); + exit(1); + } + printf(" Config File: %s\n",config_filename.toUtf8().constData()); + printf("Test Hostname: %s\n",test_host_name.toUtf8().constData()); + printf("\n"); + printf("provisiongHostShortName: %s\n", + config->provisioningHostShortName(test_host_name).toUtf8().constData()); + printf("provisioningServiceName: %s\n", + config->provisioningServiceName(test_host_name).toUtf8().constData()); + printf("provisioningHostIpAddress: %s\n", + config->provisioningHostIpAddress().toString().toUtf8().constData()); + + exit(0); +} + + +int main(int argc,char *argv[]) +{ + QCoreApplication a(argc,argv,false); + new MainObject(); + return a.exec(); +} diff --git a/tests/provisioning_test.h b/tests/provisioning_test.h new file mode 100644 index 00000000..850ffb2f --- /dev/null +++ b/tests/provisioning_test.h @@ -0,0 +1,36 @@ +// provisioning_test.h +// +// Test Rivendell provisioning methods in RDConfig. +// +// (C) Copyright 2025 Fred Gleason +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// + +#ifndef PROVISIONING_TEST_H +#define PROVISIONING_TEST_H + +#include + +#define PROVISIONING_TEST_USAGE "--config-file= --test-host-name=" + +class MainObject : public QObject +{ + Q_OBJECT + public: + MainObject(QObject *parent=0); +}; + + +#endif // PROVISIONING_TEST_H