From db7696e550695219f00b24b19020f0c163e8c171 Mon Sep 17 00:00:00 2001 From: Thomas Hochstein Date: Mon, 2 Sep 2013 10:40:17 +0200 Subject: [PATCH] Add some basic validation to config parser. We check for empty mandatory options for starters. Fixes #13 ... so we can release RSN :) Signed-off-by: Thomas Hochstein --- NewsStats.pm | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/NewsStats.pm b/NewsStats.pm index bfcb37b..91a1396 100644 --- a/NewsStats.pm +++ b/NewsStats.pm @@ -99,7 +99,19 @@ sub ReadConfig { ### IN : $ConfFile: config filename ### OUT: reference to a hash containing the configuration my ($ConfFile) = @_; - return Config::Auto::parse($ConfFile, format => 'equal'); + # mandatory configuration options + my @Mandatory = ('DBDriver','DBHost','DBUser','DBPw','DBDatabase', + 'DBTableRaw','DBTableGrps'); + # read config via Config::Auto + my $ConfR = Config::Auto::parse($ConfFile, format => 'equal'); + my %Conf = %{$ConfR}; + # check for mandatory options + foreach (@Mandatory) { + &Bleat(2,sprintf("Mandatory configuration option %s is not set!",$_)) + if (!defined($Conf{$_})); + } + # $Conf{'TLH'} is checked in gatherstats.pl + return $ConfR; }; ################################################################################ -- 2.20.1