summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2008-03-28 22:59:28 +0000
committerChris Wilson <chris+github@qwirx.com>2008-03-28 22:59:28 +0000
commit732bdbdaacb429c94c4120070e531038e3d6f132 (patch)
treeecd16d380ae1d2dcd0d65e089177eb16cca6d47f
parent4fca88ed02c1f0b5208abf2420f73023de54c23e (diff)
Allow configuration of the server port that the client will connect to
(bbackupd and bbackupquery). Redesign ConfigurationVerify to use classes instead of structs. Use port 22011 instead of 2201 during tests, to reduce the chances of conflicting with a running bbstored or other process. Ignore autogen_* in svn:ignore everywhere instead of individual per-file ignores.
-rw-r--r--.hgignore37
-rw-r--r--bin/bbackupd/BackupClientContext.cpp5
-rw-r--r--bin/bbackupd/BackupClientContext.h2
-rw-r--r--bin/bbackupd/BackupDaemon.cpp1
-rw-r--r--bin/bbackupquery/bbackupquery.cpp4
-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
-rw-r--r--test/basicserver/testbasicserver.cpp4
-rw-r--r--test/bbackupd/testbbackupd.cpp21
-rw-r--r--test/bbackupd/testfiles/bbackupd-temploc.conf1
-rw-r--r--test/bbackupd/testfiles/bbackupd.conf.in1
-rw-r--r--test/bbackupd/testfiles/bbstored.conf2
-rw-r--r--test/common/testcommon.cpp37
19 files changed, 353 insertions, 158 deletions
diff --git a/.hgignore b/.hgignore
new file mode 100644
index 00000000..c21cefc6
--- /dev/null
+++ b/.hgignore
@@ -0,0 +1,37 @@
+.svn
+BoxConfig.h
+BoxConfig.h.in
+BoxPlatform.pm
+BoxPortsAndFiles.h
+ExceptionCodes.txt
+Makefile
+_main.cpp
+_t
+_t-gdb
+aclocal.m4
+autogen_*
+autom4te.cache
+bbackupd-config
+bbackupd.conf
+bbstored-certs
+bbstored-config
+config.log
+config.status
+configure
+debug
+extcheck1.pl
+extcheck2.pl
+local
+makebuildenv.pl
+makedistribution.pl
+makedocumentation.pl
+makeexception.pl
+makeparcels.pl
+makeprotocol.pl
+notifyscript.pl
+parcels
+raidfile-config
+release
+runtest.pl
+syncallowscript.pl
+testbackupstorefix.pl
diff --git a/bin/bbackupd/BackupClientContext.cpp b/bin/bbackupd/BackupClientContext.cpp
index fd9ff5df..146f7cb8 100644
--- a/bin/bbackupd/BackupClientContext.cpp
+++ b/bin/bbackupd/BackupClientContext.cpp
@@ -44,6 +44,7 @@ BackupClientContext::BackupClientContext
BackupDaemon &rDaemon,
TLSContext &rTLSContext,
const std::string &rHostname,
+ int Port,
int32_t AccountNumber,
bool ExtendedLogging,
bool ExtendedLogToFile,
@@ -52,6 +53,7 @@ BackupClientContext::BackupClientContext
: mrDaemon(rDaemon),
mrTLSContext(rTLSContext),
mHostname(rHostname),
+ mPort(Port),
mAccountNumber(AccountNumber),
mpSocket(0),
mpConnection(0),
@@ -129,7 +131,8 @@ BackupProtocolClient &BackupClientContext::GetConnection()
mHostname << "'...");
// Connect!
- mpSocket->Open(mrTLSContext, Socket::TypeINET, mHostname.c_str(), BOX_PORT_BBSTORED);
+ mpSocket->Open(mrTLSContext, Socket::TypeINET,
+ mHostname.c_str(), mPort);
// And create a procotol object
mpConnection = new BackupProtocolClient(*mpSocket);
diff --git a/bin/bbackupd/BackupClientContext.h b/bin/bbackupd/BackupClientContext.h
index 152d8556..1504cc72 100644
--- a/bin/bbackupd/BackupClientContext.h
+++ b/bin/bbackupd/BackupClientContext.h
@@ -41,6 +41,7 @@ public:
BackupDaemon &rDaemon,
TLSContext &rTLSContext,
const std::string &rHostname,
+ int32_t Port,
int32_t AccountNumber,
bool ExtendedLogging,
bool ExtendedLogToFile,
@@ -201,6 +202,7 @@ private:
BackupDaemon &mrDaemon;
TLSContext &mrTLSContext;
std::string mHostname;
+ int mPort;
int32_t mAccountNumber;
SocketStreamTLS *mpSocket;
BackupProtocolClient *mpConnection;
diff --git a/bin/bbackupd/BackupDaemon.cpp b/bin/bbackupd/BackupDaemon.cpp
index 1446c7a8..b1dc4832 100644
--- a/bin/bbackupd/BackupDaemon.cpp
+++ b/bin/bbackupd/BackupDaemon.cpp
@@ -958,6 +958,7 @@ void BackupDaemon::Run2()
*this,
tlsContext,
conf.GetKeyValue("StoreHostname"),
+ conf.GetKeyValueInt("StorePort"),
conf.GetKeyValueInt("AccountNumber"),
conf.GetKeyValueBool("ExtendedLogging"),
conf.KeyExists("ExtendedLogFile"),
diff --git a/bin/bbackupquery/bbackupquery.cpp b/bin/bbackupquery/bbackupquery.cpp
index 342969c2..b38821c1 100644
--- a/bin/bbackupquery/bbackupquery.cpp
+++ b/bin/bbackupquery/bbackupquery.cpp
@@ -260,7 +260,9 @@ int main(int argc, const char *argv[])
// 2. Connect to server
if(!quiet) BOX_INFO("Connecting to store...");
SocketStreamTLS socket;
- socket.Open(tlsContext, Socket::TypeINET, conf.GetKeyValue("StoreHostname").c_str(), BOX_PORT_BBSTORED);
+ socket.Open(tlsContext, Socket::TypeINET,
+ conf.GetKeyValue("StoreHostname").c_str(),
+ conf.GetKeyValueInt("StorePort"));
// 3. Make a protocol, and handshake
if(!quiet) BOX_INFO("Handshake with store...");
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
diff --git a/test/basicserver/testbasicserver.cpp b/test/basicserver/testbasicserver.cpp
index 18329441..18bc0aa8 100644
--- a/test/basicserver/testbasicserver.cpp
+++ b/test/basicserver/testbasicserver.cpp
@@ -185,7 +185,7 @@ const ConfigurationVerify *testserver::GetConfigVerify() const
{
static ConfigurationVerifyKey verifyserverkeys[] =
{
- SERVERSTREAM_VERIFY_SERVER_KEYS(0) // no default addresses
+ SERVERSTREAM_VERIFY_SERVER_KEYS(ConfigurationVerifyKey::NoDefaultValue) // no default listen addresses
};
static ConfigurationVerify verifyserver[] =
@@ -258,7 +258,7 @@ const ConfigurationVerify *testTLSserver::GetConfigVerify() const
{
static ConfigurationVerifyKey verifyserverkeys[] =
{
- SERVERTLS_VERIFY_SERVER_KEYS(0) // no default listen addresses
+ SERVERTLS_VERIFY_SERVER_KEYS(ConfigurationVerifyKey::NoDefaultValue) // no default listen addresses
};
static ConfigurationVerify verifyserver[] =
diff --git a/test/bbackupd/testbbackupd.cpp b/test/bbackupd/testbbackupd.cpp
index 3f165dc2..27ca4ecb 100644
--- a/test/bbackupd/testbbackupd.cpp
+++ b/test/bbackupd/testbbackupd.cpp
@@ -514,7 +514,8 @@ void do_interrupted_restore(const TLSContext &context, int64_t restoredirid)
{
// connect and log in
SocketStreamTLS conn;
- conn.Open(context, Socket::TypeINET, "localhost", BOX_PORT_BBSTORED);
+ conn.Open(context, Socket::TypeINET, "localhost",
+ 22011);
BackupProtocolClient protocol(conn);
protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION);
std::auto_ptr<BackupProtocolClientLoginConfirmed> loginConf(protocol.QueryLogin(0x01234567, BackupProtocolClientLogin::Flags_ReadOnly));
@@ -607,7 +608,7 @@ SocketStreamTLS sSocket;
std::auto_ptr<BackupProtocolClient> Connect(TLSContext& rContext)
{
sSocket.Open(rContext, Socket::TypeINET,
- "localhost", BOX_PORT_BBSTORED);
+ "localhost", 22011);
std::auto_ptr<BackupProtocolClient> connection;
connection.reset(new BackupProtocolClient(sSocket));
connection->Handshake();
@@ -2559,13 +2560,6 @@ int test_bbackupd()
true /* print progress dots */)
== Restore_TargetExists);
- // Make sure you can't restore to a nonexistant path
- printf("Try to restore to a path that doesn't exist\n");
- TEST_THAT(BackupClientRestore(*client, restoredirid,
- "testfiles/no-such-path/subdir",
- true /* print progress dots */)
- == Restore_TargetPathNotFound);
-
// Find ID of the deleted directory
deldirid = GetDirID(*client, "x1", restoredirid);
TEST_THAT(deldirid != 0);
@@ -2578,6 +2572,15 @@ int test_bbackupd()
true /* deleted files */)
== Restore_Complete);
+ // Make sure you can't restore to a nonexistant path
+ printf("\n\n==== Try to restore to a path "
+ "that doesn't exist\n");
+ fflush(stdout);
+ TEST_THAT(BackupClientRestore(*client, restoredirid,
+ "testfiles/no-such-path/subdir",
+ true /* print progress dots */)
+ == Restore_TargetPathNotFound);
+
// Log out
client->QueryFinished();
sSocket.Close();
diff --git a/test/bbackupd/testfiles/bbackupd-temploc.conf b/test/bbackupd/testfiles/bbackupd-temploc.conf
index 86901298..57d66bca 100644
--- a/test/bbackupd/testfiles/bbackupd-temploc.conf
+++ b/test/bbackupd/testfiles/bbackupd-temploc.conf
@@ -8,6 +8,7 @@ KeysFile = testfiles/bbackupd.keys
DataDirectory = testfiles/bbackupd-data
StoreHostname = localhost
+StorePort = 22011
AccountNumber = 0x01234567
UpdateStoreInterval = 3
diff --git a/test/bbackupd/testfiles/bbackupd.conf.in b/test/bbackupd/testfiles/bbackupd.conf.in
index aecb3884..712b58b2 100644
--- a/test/bbackupd/testfiles/bbackupd.conf.in
+++ b/test/bbackupd/testfiles/bbackupd.conf.in
@@ -8,6 +8,7 @@ KeysFile = testfiles/bbackupd.keys
DataDirectory = testfiles/bbackupd-data
StoreHostname = localhost
+StorePort = 22011
AccountNumber = 0x01234567
UpdateStoreInterval = 3
diff --git a/test/bbackupd/testfiles/bbstored.conf b/test/bbackupd/testfiles/bbstored.conf
index 18c73a40..87f4fe6b 100644
--- a/test/bbackupd/testfiles/bbstored.conf
+++ b/test/bbackupd/testfiles/bbstored.conf
@@ -9,7 +9,7 @@ TimeBetweenHousekeeping = 5
Server
{
PidFile = testfiles/bbstored.pid
- ListenAddresses = inet:localhost
+ ListenAddresses = inet:localhost:22011
CertificateFile = testfiles/serverCerts.pem
PrivateKeyFile = testfiles/serverPrivKey.pem
TrustedCAsFile = testfiles/serverTrustedCAs.pem
diff --git a/test/common/testcommon.cpp b/test/common/testcommon.cpp
index eb057228..46d36c73 100644
--- a/test/common/testcommon.cpp
+++ b/test/common/testcommon.cpp
@@ -57,15 +57,15 @@ void test_conversions()
ConfigurationVerifyKey verifykeys1_1_1[] =
{
- {"bing", 0, ConfigTest_Exists, 0},
- {"carrots", 0, ConfigTest_Exists | ConfigTest_IsInt, 0},
- {"terrible", 0, ConfigTest_Exists | ConfigTest_LastEntry, 0}
+ ConfigurationVerifyKey("bing", ConfigTest_Exists),
+ ConfigurationVerifyKey("carrots", ConfigTest_Exists | ConfigTest_IsInt),
+ ConfigurationVerifyKey("terrible", ConfigTest_Exists | ConfigTest_LastEntry)
};
ConfigurationVerifyKey verifykeys1_1_2[] =
{
- {"fish", 0, ConfigTest_Exists | ConfigTest_IsInt, 0},
- {"string", 0, ConfigTest_Exists | ConfigTest_LastEntry, 0}
+ ConfigurationVerifyKey("fish", ConfigTest_Exists | ConfigTest_IsInt),
+ ConfigurationVerifyKey("string", ConfigTest_Exists | ConfigTest_LastEntry)
};
@@ -89,15 +89,15 @@ ConfigurationVerify verifysub1_1[] =
ConfigurationVerifyKey verifykeys1_1[] =
{
- {"value", 0, ConfigTest_Exists | ConfigTest_IsInt, 0},
- {"string1", 0, ConfigTest_Exists, 0},
- {"string2", 0, ConfigTest_Exists | ConfigTest_LastEntry, 0}
+ ConfigurationVerifyKey("value", ConfigTest_Exists | ConfigTest_IsInt),
+ ConfigurationVerifyKey("string1", ConfigTest_Exists),
+ ConfigurationVerifyKey("string2", ConfigTest_Exists | ConfigTest_LastEntry)
};
ConfigurationVerifyKey verifykeys1_2[] =
{
- {"carrots", 0, ConfigTest_Exists | ConfigTest_IsInt, 0},
- {"string", 0, ConfigTest_Exists | ConfigTest_LastEntry, 0}
+ ConfigurationVerifyKey("carrots", ConfigTest_Exists | ConfigTest_IsInt),
+ ConfigurationVerifyKey("string", ConfigTest_Exists | ConfigTest_LastEntry)
};
ConfigurationVerify verifysub1[] =
@@ -120,14 +120,15 @@ ConfigurationVerify verifysub1[] =
ConfigurationVerifyKey verifykeys1[] =
{
- {"notExpected", 0, 0, 0},
- {"HasDefaultValue", "Lovely default value", 0, 0},
- {"MultiValue", 0, ConfigTest_MultiValueAllowed, 0},
- {"BoolTrue1", 0, ConfigTest_IsBool, 0},
- {"BoolTrue2", 0, ConfigTest_IsBool, 0},
- {"BoolFalse1", 0, ConfigTest_IsBool, 0},
- {"BoolFalse2", 0, ConfigTest_IsBool, 0},
- {"TOPlevel", 0, ConfigTest_LastEntry | ConfigTest_Exists, 0}
+ ConfigurationVerifyKey("notExpected", 0),
+ ConfigurationVerifyKey("HasDefaultValue", 0, "Lovely default value"),
+ ConfigurationVerifyKey("MultiValue", ConfigTest_MultiValueAllowed),
+ ConfigurationVerifyKey("BoolTrue1", ConfigTest_IsBool),
+ ConfigurationVerifyKey("BoolTrue2", ConfigTest_IsBool),
+ ConfigurationVerifyKey("BoolFalse1", ConfigTest_IsBool),
+ ConfigurationVerifyKey("BoolFalse2", ConfigTest_IsBool),
+ ConfigurationVerifyKey("TOPlevel",
+ ConfigTest_LastEntry | ConfigTest_Exists)
};
ConfigurationVerify verify =