summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/backupclient/BackupDaemonConfigVerify.cpp89
-rw-r--r--lib/backupstore/BackupStoreConfigVerify.cpp17
-rw-r--r--lib/common/Configuration.cpp204
-rw-r--r--lib/common/Configuration.h55
-rw-r--r--lib/raidfile/RaidFileController.cpp13
-rw-r--r--lib/server/Daemon.h5
-rw-r--r--lib/server/ServerStream.h4
-rw-r--r--lib/server/ServerTLS.h9
8 files changed, 270 insertions, 126 deletions
diff --git a/lib/backupclient/BackupDaemonConfigVerify.cpp b/lib/backupclient/BackupDaemonConfigVerify.cpp
index 61033b5b..db1de4fa 100644
--- a/lib/backupclient/BackupDaemonConfigVerify.cpp
+++ b/lib/backupclient/BackupDaemonConfigVerify.cpp
@@ -17,15 +17,15 @@
static const ConfigurationVerifyKey backuplocationkeys[] =
{
- {"ExcludeFile", 0, ConfigTest_MultiValueAllowed, 0},
- {"ExcludeFilesRegex", 0, ConfigTest_MultiValueAllowed, 0},
- {"ExcludeDir", 0, ConfigTest_MultiValueAllowed, 0},
- {"ExcludeDirsRegex", 0, ConfigTest_MultiValueAllowed, 0},
- {"AlwaysIncludeFile", 0, ConfigTest_MultiValueAllowed, 0},
- {"AlwaysIncludeFilesRegex", 0, ConfigTest_MultiValueAllowed, 0},
- {"AlwaysIncludeDir", 0, ConfigTest_MultiValueAllowed, 0},
- {"AlwaysIncludeDirsRegex", 0, ConfigTest_MultiValueAllowed, 0},
- {"Path", 0, ConfigTest_Exists | ConfigTest_LastEntry, 0}
+ ConfigurationVerifyKey("ExcludeFile", ConfigTest_MultiValueAllowed),
+ ConfigurationVerifyKey("ExcludeFilesRegex", ConfigTest_MultiValueAllowed),
+ ConfigurationVerifyKey("ExcludeDir", ConfigTest_MultiValueAllowed),
+ ConfigurationVerifyKey("ExcludeDirsRegex", ConfigTest_MultiValueAllowed),
+ ConfigurationVerifyKey("AlwaysIncludeFile", ConfigTest_MultiValueAllowed),
+ ConfigurationVerifyKey("AlwaysIncludeFilesRegex", ConfigTest_MultiValueAllowed),
+ ConfigurationVerifyKey("AlwaysIncludeDir", ConfigTest_MultiValueAllowed),
+ ConfigurationVerifyKey("AlwaysIncludeDirsRegex", ConfigTest_MultiValueAllowed),
+ ConfigurationVerifyKey("Path", ConfigTest_Exists | ConfigTest_LastEntry)
};
static const ConfigurationVerify backuplocations[] =
@@ -64,39 +64,54 @@ static const ConfigurationVerify verifyserver[] =
static const ConfigurationVerifyKey verifyrootkeys[] =
{
- {"AccountNumber", 0, ConfigTest_Exists | ConfigTest_IsInt, 0},
-
- {"UpdateStoreInterval", 0, ConfigTest_Exists | ConfigTest_IsInt, 0},
- {"MinimumFileAge", 0, ConfigTest_Exists | ConfigTest_IsInt, 0},
- {"MaxUploadWait", 0, ConfigTest_Exists | ConfigTest_IsInt, 0},
- {"MaxFileTimeInFuture", "172800", ConfigTest_IsInt, 0}, // file is uploaded if the file is this much in the future (2 days default)
-
- {"AutomaticBackup", "yes", ConfigTest_IsBool, 0},
+ ConfigurationVerifyKey("AccountNumber",
+ ConfigTest_Exists | ConfigTest_IsInt),
+ ConfigurationVerifyKey("UpdateStoreInterval",
+ ConfigTest_Exists | ConfigTest_IsInt),
+ ConfigurationVerifyKey("MinimumFileAge",
+ ConfigTest_Exists | ConfigTest_IsInt),
+ ConfigurationVerifyKey("MaxUploadWait",
+ ConfigTest_Exists | ConfigTest_IsInt),
+ ConfigurationVerifyKey("MaxFileTimeInFuture", ConfigTest_IsInt, 172800),
+ // file is uploaded if the file is this much in the future
+ // (2 days default)
+ ConfigurationVerifyKey("AutomaticBackup", ConfigTest_IsBool, true),
- {"SyncAllowScript", 0, 0, 0}, // optional script to run to see if the sync should be started now
- // return "now" if it's allowed, or a number of seconds if it's not
-
- {"MaximumDiffingTime", 0, ConfigTest_IsInt, 0},
- {"DeleteRedundantLocationsAfter", "172800", ConfigTest_IsInt, 0},
+ ConfigurationVerifyKey("SyncAllowScript", 0),
+ // script that returns "now" if backup is allowed now, or a number
+ // of seconds to wait before trying again if not
- {"FileTrackingSizeThreshold", 0, ConfigTest_Exists | ConfigTest_IsInt, 0},
- {"DiffingUploadSizeThreshold", 0, ConfigTest_Exists | ConfigTest_IsInt, 0},
- {"StoreHostname", 0, ConfigTest_Exists, 0},
- {"ExtendedLogging", "no", ConfigTest_IsBool, 0}, // extended log to syslog
- {"ExtendedLogFile", NULL, 0, 0}, // extended log to a file
- {"LogAllFileAccess", "no", ConfigTest_IsBool, 0},
+ ConfigurationVerifyKey("MaximumDiffingTime", ConfigTest_IsInt),
+ ConfigurationVerifyKey("DeleteRedundantLocationsAfter",
+ ConfigTest_IsInt, 172800),
- {"CommandSocket", 0, 0, 0}, // not compulsory to have this
- {"KeepAliveTime", 0, ConfigTest_IsInt, 0}, // optional
- {"StoreObjectInfoFile", 0, 0, 0}, // optional
+ ConfigurationVerifyKey("FileTrackingSizeThreshold",
+ ConfigTest_Exists | ConfigTest_IsInt),
+ ConfigurationVerifyKey("DiffingUploadSizeThreshold",
+ ConfigTest_Exists | ConfigTest_IsInt),
+ ConfigurationVerifyKey("StoreHostname", ConfigTest_Exists),
+ ConfigurationVerifyKey("StorePort", ConfigTest_IsInt,
+ BOX_PORT_BBSTORED),
+ ConfigurationVerifyKey("ExtendedLogging", ConfigTest_IsBool, false),
+ // extended log to syslog
+ ConfigurationVerifyKey("ExtendedLogFile", 0),
+ // extended log to a file
+ ConfigurationVerifyKey("LogAllFileAccess", ConfigTest_IsBool, false),
+ ConfigurationVerifyKey("CommandSocket", 0),
+ // not compulsory to have this
+ ConfigurationVerifyKey("KeepAliveTime", ConfigTest_IsInt),
+ ConfigurationVerifyKey("StoreObjectInfoFile", 0),
+ // optional
- {"NotifyScript", 0, 0, 0}, // optional script to run when backup needs attention, eg store full
+ ConfigurationVerifyKey("NotifyScript", 0),
+ // optional script to run when backup needs attention, eg store full
- {"CertificateFile", 0, ConfigTest_Exists, 0},
- {"PrivateKeyFile", 0, ConfigTest_Exists, 0},
- {"TrustedCAsFile", 0, ConfigTest_Exists, 0},
- {"KeysFile", 0, ConfigTest_Exists, 0},
- {"DataDirectory", 0, ConfigTest_Exists | ConfigTest_LastEntry, 0}
+ ConfigurationVerifyKey("CertificateFile", ConfigTest_Exists),
+ ConfigurationVerifyKey("PrivateKeyFile", ConfigTest_Exists),
+ ConfigurationVerifyKey("TrustedCAsFile", ConfigTest_Exists),
+ ConfigurationVerifyKey("KeysFile", ConfigTest_Exists),
+ ConfigurationVerifyKey("DataDirectory",
+ ConfigTest_Exists | ConfigTest_LastEntry),
};
const ConfigurationVerify BackupDaemonConfigVerify =
diff --git a/lib/backupstore/BackupStoreConfigVerify.cpp b/lib/backupstore/BackupStoreConfigVerify.cpp
index 784adfb8..cc6efcf5 100644
--- a/lib/backupstore/BackupStoreConfigVerify.cpp
+++ b/lib/backupstore/BackupStoreConfigVerify.cpp
@@ -16,7 +16,8 @@
static const ConfigurationVerifyKey verifyserverkeys[] =
{
- SERVERTLS_VERIFY_SERVER_KEYS(0) // no default listen addresses
+ SERVERTLS_VERIFY_SERVER_KEYS(ConfigurationVerifyKey::NoDefaultValue)
+ // no default listen addresses
};
static const ConfigurationVerify verifyserver[] =
@@ -32,16 +33,18 @@ static const ConfigurationVerify verifyserver[] =
static const ConfigurationVerifyKey verifyrootkeys[] =
{
- {"AccountDatabase", 0, ConfigTest_Exists, 0},
- {"TimeBetweenHousekeeping", 0, ConfigTest_Exists | ConfigTest_IsInt, 0},
- {"ExtendedLogging", "no", ConfigTest_IsBool, 0}, // make value "yes" to enable in config file
+ ConfigurationVerifyKey("AccountDatabase", ConfigTest_Exists),
+ ConfigurationVerifyKey("TimeBetweenHousekeeping",
+ ConfigTest_Exists | ConfigTest_IsInt),
+ ConfigurationVerifyKey("ExtendedLogging", ConfigTest_IsBool, false),
+ // make value "yes" to enable in config file
#ifdef WIN32
- {"RaidFileConf", "", ConfigTest_LastEntry, 0}
+ ConfigurationVerifyKey("RaidFileConf", ConfigTest_LastEntry)
#else
- {"RaidFileConf", BOX_FILE_RAIDFILE_DEFAULT_CONFIG, ConfigTest_LastEntry, 0}
+ ConfigurationVerifyKey("RaidFileConf", ConfigTest_LastEntry,
+ BOX_FILE_RAIDFILE_DEFAULT_CONFIG)
#endif
-
};
const ConfigurationVerify BackupConfigFileVerify =
diff --git a/lib/common/Configuration.cpp b/lib/common/Configuration.cpp
index 4d76e0e0..f797f454 100644
--- a/lib/common/Configuration.cpp
+++ b/lib/common/Configuration.cpp
@@ -12,6 +12,8 @@
#include <stdlib.h>
#include <limits.h>
+#include <sstream>
+
#include "Configuration.h"
#include "CommonException.h"
#include "Guards.h"
@@ -29,7 +31,105 @@ inline bool iw(int c)
static const char *sValueBooleanStrings[] = {"yes", "true", "no", "false", 0};
static const bool sValueBooleanValue[] = {true, true, false, false};
+ConfigurationVerifyKey::ConfigurationVerifyKey
+(
+ std::string name,
+ int flags,
+ void *testFunction
+)
+: mName(name),
+ mHasDefaultValue(false),
+ mFlags(flags),
+ mTestFunction(testFunction)
+{ }
+
+// to allow passing NULL for default ListenAddresses
+
+ConfigurationVerifyKey::ConfigurationVerifyKey
+(
+ std::string name,
+ int flags,
+ NoDefaultValue_t t,
+ void *testFunction
+)
+: mName(name),
+ mHasDefaultValue(false),
+ mFlags(flags),
+ mTestFunction(testFunction)
+{ }
+
+ConfigurationVerifyKey::ConfigurationVerifyKey
+(
+ std::string name,
+ int flags,
+ std::string defaultValue,
+ void *testFunction
+)
+: mName(name),
+ mDefaultValue(defaultValue),
+ mHasDefaultValue(true),
+ mFlags(flags),
+ mTestFunction(testFunction)
+{ }
+
+ConfigurationVerifyKey::ConfigurationVerifyKey
+(
+ std::string name,
+ int flags,
+ const char *defaultValue,
+ void *testFunction
+)
+: mName(name),
+ mDefaultValue(defaultValue),
+ mHasDefaultValue(true),
+ mFlags(flags),
+ mTestFunction(testFunction)
+{ }
+
+ConfigurationVerifyKey::ConfigurationVerifyKey
+(
+ std::string name,
+ int flags,
+ int defaultValue,
+ void *testFunction
+)
+: mName(name),
+ mHasDefaultValue(true),
+ mFlags(flags),
+ mTestFunction(testFunction)
+{
+ ASSERT(flags & ConfigTest_IsInt);
+ std::ostringstream val;
+ val << defaultValue;
+ mDefaultValue = val.str();
+}
+ConfigurationVerifyKey::ConfigurationVerifyKey
+(
+ std::string name,
+ int flags,
+ bool defaultValue,
+ void *testFunction
+)
+: mName(name),
+ mHasDefaultValue(true),
+ mFlags(flags),
+ mTestFunction(testFunction)
+{
+ ASSERT(flags & ConfigTest_IsBool);
+ mDefaultValue = defaultValue ? "yes" : "no";
+}
+
+ConfigurationVerifyKey::ConfigurationVerifyKey
+(
+ const ConfigurationVerifyKey& rToCopy
+)
+: mName(rToCopy.mName),
+ mDefaultValue(rToCopy.mDefaultValue),
+ mHasDefaultValue(rToCopy.mHasDefaultValue),
+ mFlags(rToCopy.mFlags),
+ mTestFunction(rToCopy.mTestFunction)
+{ }
// --------------------------------------------------------------------------
//
@@ -120,8 +220,8 @@ std::auto_ptr<Configuration> Configuration::LoadAndVerify(
{
if(!Verify(*pconfig, *pVerify, std::string(), rErrorMsg))
{
- //TRACE1("Error message from Verify: %s", rErrorMsg.c_str());
- TRACE0("Error at Configuration::Verify\n");
+ BOX_ERROR("Error verifying configuration: " <<
+ rErrorMsg);
delete pconfig;
pconfig = 0;
return std::auto_ptr<Configuration>(0);
@@ -189,7 +289,8 @@ bool Configuration::LoadInto(Configuration &rConfig, FdGetLine &rGetLine, std::s
}
else
{
- rErrorMsg += "Unexpected start block in " + rConfig.mName + "\n";
+ rErrorMsg += "Unexpected start block in " +
+ rConfig.mName + "\n";
}
}
else
@@ -290,36 +391,32 @@ bool Configuration::LoadInto(Configuration &rConfig, FdGetLine &rGetLine, std::s
// --------------------------------------------------------------------------
//
// Function
-// Name: Configuration::KeyExists(const char *)
+// Name: Configuration::KeyExists(const std::string&)
// Purpose: Checks to see if a key exists
// Created: 2003/07/23
//
// --------------------------------------------------------------------------
-bool Configuration::KeyExists(const char *pKeyName) const
+bool Configuration::KeyExists(const std::string& rKeyName) const
{
- if(pKeyName == 0) {THROW_EXCEPTION(CommonException, BadArguments)}
-
- return mKeys.find(pKeyName) != mKeys.end();
+ return mKeys.find(rKeyName) != mKeys.end();
}
// --------------------------------------------------------------------------
//
// Function
-// Name: Configuration::GetKeyValue(const char *)
+// Name: Configuration::GetKeyValue(const std::string&)
// Purpose: Returns the value of a configuration variable
// Created: 2003/07/23
//
// --------------------------------------------------------------------------
-const std::string &Configuration::GetKeyValue(const char *pKeyName) const
+const std::string &Configuration::GetKeyValue(const std::string& rKeyName) const
{
- if(pKeyName == 0) {THROW_EXCEPTION(CommonException, BadArguments)}
-
- std::map<std::string, std::string>::const_iterator i(mKeys.find(pKeyName));
+ std::map<std::string, std::string>::const_iterator i(mKeys.find(rKeyName));
if(i == mKeys.end())
{
- BOX_ERROR("Missing configuration key: " << pKeyName);
+ BOX_ERROR("Missing configuration key: " << rKeyName);
THROW_EXCEPTION(CommonException, ConfigNoKey)
}
else
@@ -332,16 +429,14 @@ const std::string &Configuration::GetKeyValue(const char *pKeyName) const
// --------------------------------------------------------------------------
//
// Function
-// Name: Configuration::GetKeyValueInt(const char *)
+// Name: Configuration::GetKeyValueInt(const std::string& rKeyName)
// Purpose: Gets a key value as an integer
// Created: 2003/07/23
//
// --------------------------------------------------------------------------
-int Configuration::GetKeyValueInt(const char *pKeyName) const
+int Configuration::GetKeyValueInt(const std::string& rKeyName) const
{
- if(pKeyName == 0) {THROW_EXCEPTION(CommonException, BadArguments)}
-
- std::map<std::string, std::string>::const_iterator i(mKeys.find(pKeyName));
+ std::map<std::string, std::string>::const_iterator i(mKeys.find(rKeyName));
if(i == mKeys.end())
{
@@ -362,16 +457,14 @@ int Configuration::GetKeyValueInt(const char *pKeyName) const
// --------------------------------------------------------------------------
//
// Function
-// Name: Configuration::GetKeyValueBool(const char *) const
+// Name: Configuration::GetKeyValueBool(const std::string&)
// Purpose: Gets a key value as a boolean
// Created: 17/2/04
//
// --------------------------------------------------------------------------
-bool Configuration::GetKeyValueBool(const char *pKeyName) const
+bool Configuration::GetKeyValueBool(const std::string& rKeyName) const
{
- if(pKeyName == 0) {THROW_EXCEPTION(CommonException, BadArguments)}
-
- std::map<std::string, std::string>::const_iterator i(mKeys.find(pKeyName));
+ std::map<std::string, std::string>::const_iterator i(mKeys.find(rKeyName));
if(i == mKeys.end())
{
@@ -428,22 +521,21 @@ std::vector<std::string> Configuration::GetKeyNames() const
// --------------------------------------------------------------------------
//
// Function
-// Name: Configuration::SubConfigurationExists(const char *)
+// Name: Configuration::SubConfigurationExists(const
+// std::string&)
// Purpose: Checks to see if a sub configuration exists
// Created: 2003/07/23
//
// --------------------------------------------------------------------------
-bool Configuration::SubConfigurationExists(const char *pSubName) const
+bool Configuration::SubConfigurationExists(const std::string& rSubName) const
{
- if(pSubName == 0) {THROW_EXCEPTION(CommonException, BadArguments)}
-
// Attempt to find it...
std::list<std::pair<std::string, Configuration> >::const_iterator i(mSubConfigurations.begin());
for(; i != mSubConfigurations.end(); ++i)
{
// This the one?
- if(i->first == pSubName)
+ if(i->first == rSubName)
{
// Yes.
return true;
@@ -458,22 +550,22 @@ bool Configuration::SubConfigurationExists(const char *pSubName) const
// --------------------------------------------------------------------------
//
// Function
-// Name: Configuration::GetSubConfiguration(const char *)
+// Name: Configuration::GetSubConfiguration(const
+// std::string&)
// Purpose: Gets a sub configuration
// Created: 2003/07/23
//
// --------------------------------------------------------------------------
-const Configuration &Configuration::GetSubConfiguration(const char *pSubName) const
+const Configuration &Configuration::GetSubConfiguration(const std::string&
+ rSubName) const
{
- if(pSubName == 0) {THROW_EXCEPTION(CommonException, BadArguments)}
-
// Attempt to find it...
std::list<std::pair<std::string, Configuration> >::const_iterator i(mSubConfigurations.begin());
for(; i != mSubConfigurations.end(); ++i)
{
// This the one?
- if(i->first == pSubName)
+ if(i->first == rSubName)
{
// Yes.
return i->second;
@@ -528,15 +620,14 @@ bool Configuration::Verify(Configuration &rConfig, const ConfigurationVerify &rV
do
{
// Can the key be found?
- ASSERT(pvkey->mpName);
- if(rConfig.KeyExists(pvkey->mpName))
+ if(rConfig.KeyExists(pvkey->Name()))
{
// Get value
- const std::string &rval = rConfig.GetKeyValue(pvkey->mpName);
+ const std::string &rval = rConfig.GetKeyValue(pvkey->Name());
const char *val = rval.c_str();
// Check it's a number?
- if((pvkey->Tests & ConfigTest_IsInt) == ConfigTest_IsInt)
+ if((pvkey->Flags() & ConfigTest_IsInt) == ConfigTest_IsInt)
{
// Test it...
char *end;
@@ -545,12 +636,12 @@ bool Configuration::Verify(Configuration &rConfig, const ConfigurationVerify &rV
{
// not a good value
ok = false;
- rErrorMsg += rLevel + rConfig.mName +"." + pvkey->mpName + " (key) is not a valid integer.\n";
+ rErrorMsg += rLevel + rConfig.mName + "." + pvkey->Name() + " (key) is not a valid integer.\n";
}
}
// Check it's a bool?
- if((pvkey->Tests & ConfigTest_IsBool) == ConfigTest_IsBool)
+ if((pvkey->Flags() & ConfigTest_IsBool) == ConfigTest_IsBool)
{
// See if it's one of the allowed strings.
bool found = false;
@@ -568,37 +659,38 @@ bool Configuration::Verify(Configuration &rConfig, const ConfigurationVerify &rV
if(!found)
{
ok = false;
- rErrorMsg += rLevel + rConfig.mName +"." + pvkey->mpName + " (key) is not a valid boolean value.\n";
+ rErrorMsg += rLevel + rConfig.mName + "." + pvkey->Name() + " (key) is not a valid boolean value.\n";
}
}
// Check for multi valued statments where they're not allowed
- if((pvkey->Tests & ConfigTest_MultiValueAllowed) == 0)
+ if((pvkey->Flags() & ConfigTest_MultiValueAllowed) == 0)
{
// Check to see if this key is a multi-value -- it shouldn't be
if(rval.find(MultiValueSeparator) != rval.npos)
{
ok = false;
- rErrorMsg += rLevel + rConfig.mName +"." + pvkey->mpName + " (key) multi value not allowed (duplicated key?).\n";
+ rErrorMsg += rLevel + rConfig.mName +"." + pvkey->Name() + " (key) multi value not allowed (duplicated key?).\n";
}
}
}
else
{
// Is it required to exist?
- if((pvkey->Tests & ConfigTest_Exists) == ConfigTest_Exists)
+ if((pvkey->Flags() & ConfigTest_Exists) == ConfigTest_Exists)
{
// Should exist, but doesn't.
ok = false;
- rErrorMsg += rLevel + rConfig.mName + "." + pvkey->mpName + " (key) is missing.\n";
+ rErrorMsg += rLevel + rConfig.mName + "." + pvkey->Name() + " (key) is missing.\n";
}
- else if(pvkey->mpDefaultValue)
+ else if(pvkey->HasDefaultValue())
{
- rConfig.mKeys[std::string(pvkey->mpName)] = std::string(pvkey->mpDefaultValue);
+ rConfig.mKeys[pvkey->Name()] =
+ pvkey->DefaultValue();
}
}
- if((pvkey->Tests & ConfigTest_LastEntry) == ConfigTest_LastEntry)
+ if((pvkey->Flags() & ConfigTest_LastEntry) == ConfigTest_LastEntry)
{
// No more!
todo = false;
@@ -618,14 +710,14 @@ bool Configuration::Verify(Configuration &rConfig, const ConfigurationVerify &rV
bool found = false;
while(scan)
{
- if(scan->mpName == i->first)
+ if(scan->Name() == i->first)
{
found = true;
break;
}
// Next?
- if((scan->Tests & ConfigTest_LastEntry) == ConfigTest_LastEntry)
+ if((scan->Flags() & ConfigTest_LastEntry) == ConfigTest_LastEntry)
{
break;
}
@@ -650,8 +742,7 @@ bool Configuration::Verify(Configuration &rConfig, const ConfigurationVerify &rV
const ConfigurationVerify *scan = rVerify.mpSubConfigurations;
while(scan)
{
- ASSERT(scan->mpName);
- if(scan->mpName[0] == '*')
+ if(scan->mName.length() > 0 && scan->mName[0] == '*')
{
wildcardverify = scan;
}
@@ -659,7 +750,8 @@ bool Configuration::Verify(Configuration &rConfig, const ConfigurationVerify &rV
// Required?
if((scan->Tests & ConfigTest_Exists) == ConfigTest_Exists)
{
- if(scan->mpName[0] == '*')
+ if(scan->mName.length() > 0 &&
+ scan->mName[0] == '*')
{
// Check something exists
if(rConfig.mSubConfigurations.size() < 1)
@@ -672,11 +764,11 @@ bool Configuration::Verify(Configuration &rConfig, const ConfigurationVerify &rV
else
{
// Check real thing exists
- if(!rConfig.SubConfigurationExists(scan->mpName))
+ if(!rConfig.SubConfigurationExists(scan->mName))
{
// Should exist, but doesn't.
ok = false;
- rErrorMsg += rLevel + rConfig.mName + "." + scan->mpName + " (block) is missing.\n";
+ rErrorMsg += rLevel + rConfig.mName + "." + scan->mName + " (block) is missing.\n";
}
}
}
@@ -701,7 +793,7 @@ bool Configuration::Verify(Configuration &rConfig, const ConfigurationVerify &rV
ASSERT(name);
while(scan)
{
- if(strcmp(scan->mpName, name) == 0)
+ if(scan->mName == name)
{
// found it!
subverify = scan;
diff --git a/lib/common/Configuration.h b/lib/common/Configuration.h
index 64e7568e..80b3614b 100644
--- a/lib/common/Configuration.h
+++ b/lib/common/Configuration.h
@@ -29,20 +29,51 @@ enum
class ConfigurationVerifyKey
{
public:
- const char *mpName; // "*" for all other keys (not implemented yet)
- const char *mpDefaultValue; // default for when it's not present
- int Tests;
- void *TestFunction; // set to zero for now, will implement later
+ typedef enum
+ {
+ NoDefaultValue = 1
+ } NoDefaultValue_t;
+
+ ConfigurationVerifyKey(std::string name, int flags,
+ void *testFunction = NULL);
+ // to allow passing ConfigurationVerifyKey::NoDefaultValue
+ // for default ListenAddresses
+ ConfigurationVerifyKey(std::string name, int flags,
+ NoDefaultValue_t t, void *testFunction = NULL);
+ ConfigurationVerifyKey(std::string name, int flags,
+ std::string defaultValue, void *testFunction = NULL);
+ ConfigurationVerifyKey(std::string name, int flags,
+ const char* defaultValue, void *testFunction = NULL);
+ ConfigurationVerifyKey(std::string name, int flags,
+ int defaultValue, void *testFunction = NULL);
+ ConfigurationVerifyKey(std::string name, int flags,
+ bool defaultValue, void *testFunction = NULL);
+ const std::string& Name() const { return mName; }
+ const std::string& DefaultValue() const { return mDefaultValue; }
+ const bool HasDefaultValue() const { return mHasDefaultValue; }
+ const int Flags() const { return mFlags; }
+ const void* TestFunction() const { return mTestFunction; }
+ ConfigurationVerifyKey(const ConfigurationVerifyKey& rToCopy);
+
+private:
+ ConfigurationVerifyKey& operator=(const ConfigurationVerifyKey&
+ noAssign);
+
+ std::string mName; // "*" for all other keys (not implemented yet)
+ std::string mDefaultValue; // default for when it's not present
+ bool mHasDefaultValue;
+ int mFlags;
+ void *mTestFunction; // set to zero for now, will implement later
};
class ConfigurationVerify
{
public:
- const char *mpName; // "*" for all other sub config names
+ std::string mName; // "*" for all other sub config names
const ConfigurationVerify *mpSubConfigurations;
const ConfigurationVerifyKey *mpKeys;
int Tests;
- void *TestFunction; // set to zero for now, will implement later
+ void *TestFunction; // set to zero for now, will implement later
};
class FdGetLine;
@@ -79,14 +110,14 @@ public:
std::string &rErrorMsg)
{ return LoadAndVerify(rFilename, 0, rErrorMsg); }
- bool KeyExists(const char *pKeyName) const;
- const std::string &GetKeyValue(const char *pKeyName) const;
- int GetKeyValueInt(const char *pKeyName) const;
- bool GetKeyValueBool(const char *pKeyName) const;
+ bool KeyExists(const std::string& rKeyName) const;
+ const std::string &GetKeyValue(const std::string& rKeyName) const;
+ int GetKeyValueInt(const std::string& rKeyName) const;
+ bool GetKeyValueBool(const std::string& rKeyName) const;
std::vector<std::string> GetKeyNames() const;
- bool SubConfigurationExists(const char *pSubName) const;
- const Configuration &GetSubConfiguration(const char *pSubName) const;
+ bool SubConfigurationExists(const std::string& rSubName) const;
+ const Configuration &GetSubConfiguration(const std::string& rSubName) const;
std::vector<std::string> GetSubConfigurationNames() const;
std::string mName;
diff --git a/lib/raidfile/RaidFileController.cpp b/lib/raidfile/RaidFileController.cpp
index 0cc2ede7..86fa9df1 100644
--- a/lib/raidfile/RaidFileController.cpp
+++ b/lib/raidfile/RaidFileController.cpp
@@ -70,11 +70,14 @@ void RaidFileController::Initialise(const std::string& rConfigFilename)
static const ConfigurationVerifyKey verifykeys[] =
{
- {"SetNumber", 0, ConfigTest_Exists | ConfigTest_IsInt, 0},
- {"BlockSize", 0, ConfigTest_Exists | ConfigTest_IsInt, 0},
- {"Dir0", 0, ConfigTest_Exists, 0},
- {"Dir1", 0, ConfigTest_Exists, 0},
- {"Dir2", 0, ConfigTest_Exists | ConfigTest_LastEntry, 0}
+ ConfigurationVerifyKey("SetNumber",
+ ConfigTest_Exists | ConfigTest_IsInt),
+ ConfigurationVerifyKey("BlockSize",
+ ConfigTest_Exists | ConfigTest_IsInt),
+ ConfigurationVerifyKey("Dir0", ConfigTest_Exists),
+ ConfigurationVerifyKey("Dir1", ConfigTest_Exists),
+ ConfigurationVerifyKey("Dir2",
+ ConfigTest_Exists | ConfigTest_LastEntry)
};
static const ConfigurationVerify subverify =
diff --git a/lib/server/Daemon.h b/lib/server/Daemon.h
index 60444ab9..ef5728ec 100644
--- a/lib/server/Daemon.h
+++ b/lib/server/Daemon.h
@@ -92,8 +92,9 @@ private:
std::string mAppName;
};
-#define DAEMON_VERIFY_SERVER_KEYS {"PidFile", 0, ConfigTest_Exists, 0}, \
- {"User", 0, ConfigTest_LastEntry, 0}
+#define DAEMON_VERIFY_SERVER_KEYS \
+ ConfigurationVerifyKey("PidFile", ConfigTest_Exists), \
+ ConfigurationVerifyKey("User", ConfigTest_LastEntry)
#endif // DAEMON__H
diff --git a/lib/server/ServerStream.h b/lib/server/ServerStream.h
index 0ec5ef49..41899e78 100644
--- a/lib/server/ServerStream.h
+++ b/lib/server/ServerStream.h
@@ -365,8 +365,8 @@ private:
};
#define SERVERSTREAM_VERIFY_SERVER_KEYS(DEFAULT_ADDRESSES) \
- {"ListenAddresses", DEFAULT_ADDRESSES, 0, 0}, \
- DAEMON_VERIFY_SERVER_KEYS
+ ConfigurationVerifyKey("ListenAddresses", 0, DEFAULT_ADDRESSES), \
+ DAEMON_VERIFY_SERVER_KEYS
#include "MemLeakFindOff.h"
diff --git a/lib/server/ServerTLS.h b/lib/server/ServerTLS.h
index 71d35380..1bfcb547 100644
--- a/lib/server/ServerTLS.h
+++ b/lib/server/ServerTLS.h
@@ -70,11 +70,10 @@ private:
};
#define SERVERTLS_VERIFY_SERVER_KEYS(DEFAULT_ADDRESSES) \
- {"CertificateFile", 0, ConfigTest_Exists, 0}, \
- {"PrivateKeyFile", 0, ConfigTest_Exists, 0}, \
- {"TrustedCAsFile", 0, ConfigTest_Exists, 0}, \
- SERVERSTREAM_VERIFY_SERVER_KEYS(DEFAULT_ADDRESSES)
-
+ ConfigurationVerifyKey("CertificateFile", ConfigTest_Exists), \
+ ConfigurationVerifyKey("PrivateKeyFile", ConfigTest_Exists), \
+ ConfigurationVerifyKey("TrustedCAsFile", ConfigTest_Exists), \
+ SERVERSTREAM_VERIFY_SERVER_KEYS(DEFAULT_ADDRESSES)
#endif // SERVERTLS__H