diff options
author | Chris Wilson <chris+github@qwirx.com> | 2008-08-07 16:35:09 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2008-08-07 16:35:09 +0000 |
commit | f4ba64df969746a0dfa20a5a910fb120c82da981 (patch) | |
tree | fc72ebdd1e281a572b481343cc55e80183ecc042 | |
parent | a10f0006c29ae85375bd38960685d097e9726666 (diff) |
Rename BackupContext to BackupStoreContext.
Add a TestHook to help test weird server behaviour such as crashes.
-rw-r--r-- | bin/bbstored/BackupCommands.cpp | 99 | ||||
-rw-r--r-- | bin/bbstored/BackupStoreContext.cpp (renamed from bin/bbstored/BackupContext.cpp) | 115 | ||||
-rw-r--r-- | bin/bbstored/BackupStoreContext.h (renamed from bin/bbstored/BackupContext.h) | 40 | ||||
-rw-r--r-- | bin/bbstored/BackupStoreDaemon.cpp | 12 | ||||
-rw-r--r-- | bin/bbstored/BackupStoreDaemon.h | 12 | ||||
-rw-r--r-- | bin/bbstored/backupprotocol.txt | 2 |
6 files changed, 165 insertions, 115 deletions
diff --git a/bin/bbstored/BackupCommands.cpp b/bin/bbstored/BackupCommands.cpp index 90d1e5d9..b5ae365c 100644 --- a/bin/bbstored/BackupCommands.cpp +++ b/bin/bbstored/BackupCommands.cpp @@ -15,7 +15,7 @@ #include "autogen_BackupProtocolServer.h" #include "autogen_RaidFileException.h" #include "BackupConstants.h" -#include "BackupContext.h" +#include "BackupStoreContext.h" #include "BackupStoreConstants.h" #include "BackupStoreDirectory.h" #include "BackupStoreException.h" @@ -31,7 +31,7 @@ #include "MemLeakFindOn.h" #define CHECK_PHASE(phase) \ - if(rContext.GetPhase() != BackupContext::phase) \ + if(rContext.GetPhase() != BackupStoreContext::phase) \ { \ return std::auto_ptr<ProtocolObject>(new BackupProtocolServerError( \ BackupProtocolServerError::ErrorType, BackupProtocolServerError::Err_NotInRightProtocolPhase)); \ @@ -47,12 +47,12 @@ // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerVersion::DoCommand(Protocol &, BackupContext &) +// Name: BackupProtocolServerVersion::DoCommand(Protocol &, BackupStoreContext &) // Purpose: Return the current version, or an error if the requested version isn't allowed // Created: 2003/08/20 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerVersion::DoCommand(BackupProtocolServer &rProtocol, BackupContext &rContext) +std::auto_ptr<ProtocolObject> BackupProtocolServerVersion::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) { CHECK_PHASE(Phase_Version) @@ -64,7 +64,7 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerVersion::DoCommand(BackupProto } // Mark the next phase - rContext.SetPhase(BackupContext::Phase_Login); + rContext.SetPhase(BackupStoreContext::Phase_Login); // Return our version return std::auto_ptr<ProtocolObject>(new BackupProtocolServerVersion(BACKUP_STORE_SERVER_VERSION)); @@ -73,12 +73,12 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerVersion::DoCommand(BackupProto // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerLogin::DoCommand(Protocol &, BackupContext &) +// Name: BackupProtocolServerLogin::DoCommand(Protocol &, BackupStoreContext &) // Purpose: Return the current version, or an error if the requested version isn't allowed // Created: 2003/08/20 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerLogin::DoCommand(BackupProtocolServer &rProtocol, BackupContext &rContext) +std::auto_ptr<ProtocolObject> BackupProtocolServerLogin::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) { CHECK_PHASE(Phase_Login) @@ -131,7 +131,7 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerLogin::DoCommand(BackupProtoco int64_t clientStoreMarker = rContext.GetClientStoreMarker(); // Mark the next phase - rContext.SetPhase(BackupContext::Phase_Commands); + rContext.SetPhase(BackupStoreContext::Phase_Commands); // Log login BOX_NOTICE("Login from Client ID " << @@ -151,12 +151,12 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerLogin::DoCommand(BackupProtoco // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerFinished::DoCommand(Protocol &, BackupContext &) +// Name: BackupProtocolServerFinished::DoCommand(Protocol &, BackupStoreContext &) // Purpose: Marks end of conversation (Protocol framework handles this) // Created: 2003/08/20 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerFinished::DoCommand(BackupProtocolServer &rProtocol, BackupContext &rContext) +std::auto_ptr<ProtocolObject> BackupProtocolServerFinished::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) { BOX_NOTICE("Session finished for Client ID " << BOX_FORMAT_ACCOUNT(rContext.GetClientID())); @@ -172,12 +172,12 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerFinished::DoCommand(BackupProt // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerListDirectory::DoCommand(Protocol &, BackupContext &) +// Name: BackupProtocolServerListDirectory::DoCommand(Protocol &, BackupStoreContext &) // Purpose: Command to list a directory // Created: 2003/09/02 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerListDirectory::DoCommand(BackupProtocolServer &rProtocol, BackupContext &rContext) +std::auto_ptr<ProtocolObject> BackupProtocolServerListDirectory::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) { CHECK_PHASE(Phase_Commands) @@ -217,20 +217,27 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerListDirectory::DoCommand(Backu // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerStoreFile::DoCommand(Protocol &, BackupContext &) +// Name: BackupProtocolServerStoreFile::DoCommand(Protocol &, BackupStoreContext &) // Purpose: Command to store a file on the server // Created: 2003/09/02 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerStoreFile::DoCommand(BackupProtocolServer &rProtocol, BackupContext &rContext) +std::auto_ptr<ProtocolObject> BackupProtocolServerStoreFile::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) { CHECK_PHASE(Phase_Commands) CHECK_WRITEABLE_SESSION + + std::auto_ptr<ProtocolObject> hookResult = + rContext.StartCommandHook(*this); + if(hookResult.get()) + { + return hookResult; + } // Check that the diff from file actually exists, if it's specified if(mDiffFromFileID != 0) { - if(!rContext.ObjectExists(mDiffFromFileID, BackupContext::ObjectExists_File)) + if(!rContext.ObjectExists(mDiffFromFileID, BackupStoreContext::ObjectExists_File)) { return std::auto_ptr<ProtocolObject>(new BackupProtocolServerError( BackupProtocolServerError::ErrorType, BackupProtocolServerError::Err_DiffFromFileDoesNotExist)); @@ -275,12 +282,12 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerStoreFile::DoCommand(BackupPro // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerGetObject::DoCommand(Protocol &, BackupContext &) +// Name: BackupProtocolServerGetObject::DoCommand(Protocol &, BackupStoreContext &) // Purpose: Command to get an arbitary object from the server // Created: 2003/09/03 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerGetObject::DoCommand(BackupProtocolServer &rProtocol, BackupContext &rContext) +std::auto_ptr<ProtocolObject> BackupProtocolServerGetObject::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) { CHECK_PHASE(Phase_Commands) @@ -303,13 +310,13 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerGetObject::DoCommand(BackupPro // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerGetFile::DoCommand(Protocol &, BackupContext &) +// Name: BackupProtocolServerGetFile::DoCommand(Protocol &, BackupStoreContext &) // Purpose: Command to get an file object from the server -- may have to do a bit of // work to get the object. // Created: 2003/09/03 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerGetFile::DoCommand(BackupProtocolServer &rProtocol, BackupContext &rContext) +std::auto_ptr<ProtocolObject> BackupProtocolServerGetFile::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) { CHECK_PHASE(Phase_Commands) @@ -475,12 +482,12 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerGetFile::DoCommand(BackupProto // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerCreateDirectory::DoCommand(Protocol &, BackupContext &) +// Name: BackupProtocolServerCreateDirectory::DoCommand(Protocol &, BackupStoreContext &) // Purpose: Create directory command // Created: 2003/09/04 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerCreateDirectory::DoCommand(BackupProtocolServer &rProtocol, BackupContext &rContext) +std::auto_ptr<ProtocolObject> BackupProtocolServerCreateDirectory::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) { CHECK_PHASE(Phase_Commands) CHECK_WRITEABLE_SESSION @@ -518,12 +525,12 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerCreateDirectory::DoCommand(Bac // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerChangeDirAttributes::DoCommand(Protocol &, BackupContext &) +// Name: BackupProtocolServerChangeDirAttributes::DoCommand(Protocol &, BackupStoreContext &) // Purpose: Change attributes on directory // Created: 2003/09/06 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerChangeDirAttributes::DoCommand(BackupProtocolServer &rProtocol, BackupContext &rContext) +std::auto_ptr<ProtocolObject> BackupProtocolServerChangeDirAttributes::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) { CHECK_PHASE(Phase_Commands) CHECK_WRITEABLE_SESSION @@ -546,12 +553,12 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerChangeDirAttributes::DoCommand // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerSetReplacementFileAttributes::DoCommand(Protocol &, BackupContext &) +// Name: BackupProtocolServerSetReplacementFileAttributes::DoCommand(Protocol &, BackupStoreContext &) // Purpose: Change attributes on directory // Created: 2003/09/06 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerSetReplacementFileAttributes::DoCommand(BackupProtocolServer &rProtocol, BackupContext &rContext) +std::auto_ptr<ProtocolObject> BackupProtocolServerSetReplacementFileAttributes::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) { CHECK_PHASE(Phase_Commands) CHECK_WRITEABLE_SESSION @@ -581,12 +588,12 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerSetReplacementFileAttributes:: // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerDeleteFile::DoCommand(BackupProtocolServer &, BackupContext &) +// Name: BackupProtocolServerDeleteFile::DoCommand(BackupProtocolServer &, BackupStoreContext &) // Purpose: Delete a file // Created: 2003/10/21 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerDeleteFile::DoCommand(BackupProtocolServer &rProtocol, BackupContext &rContext) +std::auto_ptr<ProtocolObject> BackupProtocolServerDeleteFile::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) { CHECK_PHASE(Phase_Commands) CHECK_WRITEABLE_SESSION @@ -603,12 +610,12 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerDeleteFile::DoCommand(BackupPr // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerDeleteDirectory::DoCommand(BackupProtocolServer &, BackupContext &) +// Name: BackupProtocolServerDeleteDirectory::DoCommand(BackupProtocolServer &, BackupStoreContext &) // Purpose: Delete a directory // Created: 2003/10/21 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerDeleteDirectory::DoCommand(BackupProtocolServer &rProtocol, BackupContext &rContext) +std::auto_ptr<ProtocolObject> BackupProtocolServerDeleteDirectory::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) { CHECK_PHASE(Phase_Commands) CHECK_WRITEABLE_SESSION @@ -631,12 +638,12 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerDeleteDirectory::DoCommand(Bac // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerUndeleteDirectory::DoCommand(BackupProtocolServer &, BackupContext &) +// Name: BackupProtocolServerUndeleteDirectory::DoCommand(BackupProtocolServer &, BackupStoreContext &) // Purpose: Undelete a directory // Created: 23/11/03 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerUndeleteDirectory::DoCommand(BackupProtocolServer &rProtocol, BackupContext &rContext) +std::auto_ptr<ProtocolObject> BackupProtocolServerUndeleteDirectory::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) { CHECK_PHASE(Phase_Commands) CHECK_WRITEABLE_SESSION @@ -658,12 +665,12 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerUndeleteDirectory::DoCommand(B // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerSetClientStoreMarker::DoCommand(BackupProtocolServer &, BackupContext &) +// Name: BackupProtocolServerSetClientStoreMarker::DoCommand(BackupProtocolServer &, BackupStoreContext &) // Purpose: Command to set the client's store marker // Created: 2003/10/29 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerSetClientStoreMarker::DoCommand(BackupProtocolServer &rProtocol, BackupContext &rContext) +std::auto_ptr<ProtocolObject> BackupProtocolServerSetClientStoreMarker::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) { CHECK_PHASE(Phase_Commands) CHECK_WRITEABLE_SESSION @@ -679,12 +686,12 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerSetClientStoreMarker::DoComman // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerMoveObject::DoCommand(BackupProtocolServer &, BackupContext &) +// Name: BackupProtocolServerMoveObject::DoCommand(BackupProtocolServer &, BackupStoreContext &) // Purpose: Command to move an object from one directory to another // Created: 2003/11/12 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerMoveObject::DoCommand(BackupProtocolServer &rProtocol, BackupContext &rContext) +std::auto_ptr<ProtocolObject> BackupProtocolServerMoveObject::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) { CHECK_PHASE(Phase_Commands) CHECK_WRITEABLE_SESSION @@ -722,12 +729,12 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerMoveObject::DoCommand(BackupPr // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerGetObjectName::DoCommand(BackupProtocolServer &, BackupContext &) +// Name: BackupProtocolServerGetObjectName::DoCommand(BackupProtocolServer &, BackupStoreContext &) // Purpose: Command to find the name of an object // Created: 12/11/03 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerGetObjectName::DoCommand(BackupProtocolServer &rProtocol, BackupContext &rContext) +std::auto_ptr<ProtocolObject> BackupProtocolServerGetObjectName::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) { CHECK_PHASE(Phase_Commands) @@ -748,7 +755,7 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerGetObjectName::DoCommand(Backu do { // Check the directory really exists - if(!rContext.ObjectExists(dirID, BackupContext::ObjectExists_Directory)) + if(!rContext.ObjectExists(dirID, BackupStoreContext::ObjectExists_Directory)) { return std::auto_ptr<ProtocolObject>(new BackupProtocolServerObjectName(BackupProtocolServerObjectName::NumNameElements_ObjectDoesntExist, 0, 0, 0)); } @@ -813,12 +820,12 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerGetObjectName::DoCommand(Backu // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerGetBlockIndexByID::DoCommand(BackupProtocolServer &, BackupContext &) +// Name: BackupProtocolServerGetBlockIndexByID::DoCommand(BackupProtocolServer &, BackupStoreContext &) // Purpose: Get the block index from a file, by ID // Created: 19/1/04 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerGetBlockIndexByID::DoCommand(BackupProtocolServer &rProtocol, BackupContext &rContext) +std::auto_ptr<ProtocolObject> BackupProtocolServerGetBlockIndexByID::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) { CHECK_PHASE(Phase_Commands) @@ -839,12 +846,12 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerGetBlockIndexByID::DoCommand(B // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerGetBlockIndexByName::DoCommand(BackupProtocolServer &, BackupContext &) +// Name: BackupProtocolServerGetBlockIndexByName::DoCommand(BackupProtocolServer &, BackupStoreContext &) // Purpose: Get the block index from a file, by name within a directory // Created: 19/1/04 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerGetBlockIndexByName::DoCommand(BackupProtocolServer &rProtocol, BackupContext &rContext) +std::auto_ptr<ProtocolObject> BackupProtocolServerGetBlockIndexByName::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) { CHECK_PHASE(Phase_Commands) @@ -891,12 +898,12 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerGetBlockIndexByName::DoCommand // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerGetAccountUsage::DoCommand(BackupProtocolServer &, BackupContext &) +// Name: BackupProtocolServerGetAccountUsage::DoCommand(BackupProtocolServer &, BackupStoreContext &) // Purpose: Return the amount of disc space used // Created: 19/4/04 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerGetAccountUsage::DoCommand(BackupProtocolServer &rProtocol, BackupContext &rContext) +std::auto_ptr<ProtocolObject> BackupProtocolServerGetAccountUsage::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) { CHECK_PHASE(Phase_Commands) @@ -922,12 +929,12 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerGetAccountUsage::DoCommand(Bac // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerGetIsAlive::DoCommand(BackupProtocolServer &, BackupContext &) +// Name: BackupProtocolServerGetIsAlive::DoCommand(BackupProtocolServer &, BackupStoreContext &) // Purpose: Return the amount of disc space used // Created: 19/4/04 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerGetIsAlive::DoCommand(BackupProtocolServer &rProtocol, BackupContext &rContext) +std::auto_ptr<ProtocolObject> BackupProtocolServerGetIsAlive::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) { CHECK_PHASE(Phase_Commands) diff --git a/bin/bbstored/BackupContext.cpp b/bin/bbstored/BackupStoreContext.cpp index af1c9475..815f2aca 100644 --- a/bin/bbstored/BackupContext.cpp +++ b/bin/bbstored/BackupStoreContext.cpp @@ -1,7 +1,7 @@ // -------------------------------------------------------------------------- // // File -// Name: BackupContext.cpp +// Name: BackupStoreContext.cpp // Purpose: Context for backup store server // Created: 2003/08/20 // @@ -11,7 +11,7 @@ #include <stdio.h> -#include "BackupContext.h" +#include "BackupStoreContext.h" #include "RaidFileWrite.h" #include "RaidFileRead.h" #include "BackupStoreDirectory.h" @@ -48,31 +48,32 @@ // -------------------------------------------------------------------------- // // Function -// Name: BackupContext::BackupContext() +// Name: BackupStoreContext::BackupStoreContext() // Purpose: Constructor // Created: 2003/08/20 // // -------------------------------------------------------------------------- -BackupContext::BackupContext(int32_t ClientID, BackupStoreDaemon &rDaemon) +BackupStoreContext::BackupStoreContext(int32_t ClientID, BackupStoreDaemon &rDaemon) : mClientID(ClientID), mrDaemon(rDaemon), mProtocolPhase(Phase_START), mClientHasAccount(false), mStoreDiscSet(-1), mReadOnly(true), - mSaveStoreInfoDelay(STORE_INFO_SAVE_DELAY) + mSaveStoreInfoDelay(STORE_INFO_SAVE_DELAY), + mpTestHook(NULL) { } // -------------------------------------------------------------------------- // // Function -// Name: BackupContext::~BackupContext() +// Name: BackupStoreContext::~BackupStoreContext() // Purpose: Destructor // Created: 2003/08/20 // // -------------------------------------------------------------------------- -BackupContext::~BackupContext() +BackupStoreContext::~BackupStoreContext() { // Delete the objects in the cache for(std::map<int64_t, BackupStoreDirectory*>::iterator i(mDirectoryCache.begin()); i != mDirectoryCache.end(); ++i) @@ -85,12 +86,12 @@ BackupContext::~BackupContext() // -------------------------------------------------------------------------- // // Function -// Name: BackupContext::CleanUp() +// Name: BackupStoreContext::CleanUp() // Purpose: Clean up after a connection // Created: 16/12/03 // // -------------------------------------------------------------------------- -void BackupContext::CleanUp() +void BackupStoreContext::CleanUp() { // Make sure the store info is saved, if it has been loaded, isn't read only and has been modified if(mpStoreInfo.get() && !(mpStoreInfo->IsReadOnly()) && mpStoreInfo->IsModified()) @@ -102,12 +103,12 @@ void BackupContext::CleanUp() // -------------------------------------------------------------------------- // // Function -// Name: BackupContext::ReceivedFinishCommand() +// Name: BackupStoreContext::ReceivedFinishCommand() // Purpose: Called when the finish command is received by the protocol // Created: 16/12/03 // // -------------------------------------------------------------------------- -void BackupContext::ReceivedFinishCommand() +void BackupStoreContext::ReceivedFinishCommand() { if(!mReadOnly && mpStoreInfo.get()) { @@ -120,12 +121,12 @@ void BackupContext::ReceivedFinishCommand() // -------------------------------------------------------------------------- // // Function -// Name: BackupContext::AttemptToGetWriteLock() +// Name: BackupStoreContext::AttemptToGetWriteLock() // Purpose: Attempt to get a write lock for the store, and if so, unset the read only flags // Created: 2003/09/02 // // -------------------------------------------------------------------------- -bool BackupContext::AttemptToGetWriteLock() +bool BackupStoreContext::AttemptToGetWriteLock() { // Make the filename of the write lock file std::string writeLockFile; @@ -166,12 +167,12 @@ bool BackupContext::AttemptToGetWriteLock() // -------------------------------------------------------------------------- // // Function -// Name: BackupContext::LoadStoreInfo() +// Name: BackupStoreContext::LoadStoreInfo() // Purpose: Load the store info from disc // Created: 2003/09/03 // // -------------------------------------------------------------------------- -void BackupContext::LoadStoreInfo() +void BackupStoreContext::LoadStoreInfo() { if(mpStoreInfo.get() != 0) { @@ -195,12 +196,12 @@ void BackupContext::LoadStoreInfo() // -------------------------------------------------------------------------- // // Function -// Name: BackupContext::SaveStoreInfo(bool) +// Name: BackupStoreContext::SaveStoreInfo(bool) // Purpose: Potentially delayed saving of the store info // Created: 16/12/03 // // -------------------------------------------------------------------------- -void BackupContext::SaveStoreInfo(bool AllowDelay) +void BackupStoreContext::SaveStoreInfo(bool AllowDelay) { if(mpStoreInfo.get() == 0) { @@ -233,13 +234,13 @@ void BackupContext::SaveStoreInfo(bool AllowDelay) // -------------------------------------------------------------------------- // // Function -// Name: BackupContext::MakeObjectFilename(int64_t, std::string &, bool) +// Name: BackupStoreContext::MakeObjectFilename(int64_t, std::string &, bool) // Purpose: Create the filename of an object in the store, optionally creating the // containing directory if it doesn't already exist. // Created: 2003/09/02 // // -------------------------------------------------------------------------- -void BackupContext::MakeObjectFilename(int64_t ObjectID, std::string &rOutput, bool EnsureDirectoryExists) +void BackupStoreContext::MakeObjectFilename(int64_t ObjectID, std::string &rOutput, bool EnsureDirectoryExists) { // Delegate to utility function StoreStructure::MakeObjectFilename(ObjectID, mStoreRoot, mStoreDiscSet, rOutput, EnsureDirectoryExists); @@ -249,7 +250,7 @@ void BackupContext::MakeObjectFilename(int64_t ObjectID, std::string &rOutput, b // -------------------------------------------------------------------------- // // Function -// Name: BackupContext::GetDirectoryInternal(int64_t) +// Name: BackupStoreContext::GetDirectoryInternal(int64_t) // Purpose: Return a reference to a directory. Valid only until the // next time a function which affects directories is called. // Mainly this funciton, and creation of files. @@ -257,7 +258,7 @@ void BackupContext::MakeObjectFilename(int64_t ObjectID, std::string &rOutput, b // Created: 2003/09/02 // // -------------------------------------------------------------------------- -BackupStoreDirectory &BackupContext::GetDirectoryInternal(int64_t ObjectID) +BackupStoreDirectory &BackupStoreContext::GetDirectoryInternal(int64_t ObjectID) { // Get the filename std::string filename; @@ -343,12 +344,12 @@ BackupStoreDirectory &BackupContext::GetDirectoryInternal(int64_t ObjectID) // -------------------------------------------------------------------------- // // Function -// Name: BackupContext::AllocateObjectID() +// Name: BackupStoreContext::AllocateObjectID() // Purpose: Allocate a new object ID, tolerant of failures to save store info // Created: 16/12/03 // // -------------------------------------------------------------------------- -int64_t BackupContext::AllocateObjectID() +int64_t BackupStoreContext::AllocateObjectID() { if(mpStoreInfo.get() == 0) { @@ -393,13 +394,13 @@ int64_t BackupContext::AllocateObjectID() // -------------------------------------------------------------------------- // // Function -// Name: BackupContext::AddFile(IOStream &, int64_t, int64_t, int64_t, const BackupStoreFilename &, bool) +// Name: BackupStoreContext::AddFile(IOStream &, int64_t, int64_t, int64_t, const BackupStoreFilename &, bool) // Purpose: Add a file to the store, from a given stream, into a specified directory. // Returns object ID of the new file. // Created: 2003/09/03 // // -------------------------------------------------------------------------- -int64_t BackupContext::AddFile(IOStream &rFile, int64_t InDirectory, int64_t ModificationTime, +int64_t BackupStoreContext::AddFile(IOStream &rFile, int64_t InDirectory, int64_t ModificationTime, int64_t AttributesHash, int64_t DiffFromFileID, const BackupStoreFilename &rFilename, bool MarkFileWithSameNameAsOldVersions) { @@ -681,12 +682,12 @@ int64_t BackupContext::AddFile(IOStream &rFile, int64_t InDirectory, int64_t Mod // -------------------------------------------------------------------------- // // Function -// Name: BackupContext::DeleteFile(const BackupStoreFilename &, int64_t, int64_t &) +// Name: BackupStoreContext::DeleteFile(const BackupStoreFilename &, int64_t, int64_t &) // Purpose: Deletes a file, returning true if the file existed. Object ID returned too, set to zero if not found. // Created: 2003/10/21 // // -------------------------------------------------------------------------- -bool BackupContext::DeleteFile(const BackupStoreFilename &rFilename, int64_t InDirectory, int64_t &rObjectIDOut) +bool BackupStoreContext::DeleteFile(const BackupStoreFilename &rFilename, int64_t InDirectory, int64_t &rObjectIDOut) { // Essential checks! if(mpStoreInfo.get() == 0) @@ -768,12 +769,12 @@ bool BackupContext::DeleteFile(const BackupStoreFilename &rFilename, int64_t InD // -------------------------------------------------------------------------- // // Function -// Name: BackupContext::RemoveDirectoryFromCache(int64_t) +// Name: BackupStoreContext::RemoveDirectoryFromCache(int64_t) // Purpose: Remove directory from cache // Created: 2003/09/04 // // -------------------------------------------------------------------------- -void BackupContext::RemoveDirectoryFromCache(int64_t ObjectID) +void BackupStoreContext::RemoveDirectoryFromCache(int64_t ObjectID) { std::map<int64_t, BackupStoreDirectory*>::iterator item(mDirectoryCache.find(ObjectID)); if(item != mDirectoryCache.end()) @@ -789,12 +790,12 @@ void BackupContext::RemoveDirectoryFromCache(int64_t ObjectID) // -------------------------------------------------------------------------- // // Function -// Name: BackupContext::SaveDirectory(BackupStoreDirectory &, int64_t) +// Name: BackupStoreContext::SaveDirectory(BackupStoreDirectory &, int64_t) // Purpose: Save directory back to disc, update time in cache // Created: 2003/09/04 // // -------------------------------------------------------------------------- -void BackupContext::SaveDirectory(BackupStoreDirectory &rDir, int64_t ObjectID) +void BackupStoreContext::SaveDirectory(BackupStoreDirectory &rDir, int64_t ObjectID) { if(mpStoreInfo.get() == 0) { @@ -851,12 +852,12 @@ void BackupContext::SaveDirectory(BackupStoreDirectory &rDir, int64_t ObjectID) // -------------------------------------------------------------------------- // // Function -// Name: BackupContext::AddDirectory(int64_t, const BackupStoreFilename &, bool &) +// Name: BackupStoreContext::AddDirectory(int64_t, const BackupStoreFilename &, bool &) // Purpose: Creates a directory (or just returns the ID of an existing one). rAlreadyExists set appropraitely. // Created: 2003/09/04 // // -------------------------------------------------------------------------- -int64_t BackupContext::AddDirectory(int64_t InDirectory, const BackupStoreFilename &rFilename, const StreamableMemBlock &Attributes, int64_t AttributesModTime, bool &rAlreadyExists) +int64_t BackupStoreContext::AddDirectory(int64_t InDirectory, const BackupStoreFilename &rFilename, const StreamableMemBlock &Attributes, int64_t AttributesModTime, bool &rAlreadyExists) { if(mpStoreInfo.get() == 0) { @@ -945,12 +946,12 @@ int64_t BackupContext::AddDirectory(int64_t InDirectory, const BackupStoreFilena // -------------------------------------------------------------------------- // // Function -// Name: BackupContext::DeleteFile(const BackupStoreFilename &, int64_t, int64_t &, bool) +// Name: BackupStoreContext::DeleteFile(const BackupStoreFilename &, int64_t, int64_t &, bool) // Purpose: Recusively deletes a directory (or undeletes if Undelete = true) // Created: 2003/10/21 // // -------------------------------------------------------------------------- -void BackupContext::DeleteDirectory(int64_t ObjectID, bool Undelete) +void BackupStoreContext::DeleteDirectory(int64_t ObjectID, bool Undelete) { // Essential checks! if(mpStoreInfo.get() == 0) @@ -1027,12 +1028,12 @@ void BackupContext::DeleteDirectory(int64_t ObjectID, bool Undelete) // -------------------------------------------------------------------------- // // Function -// Name: BackupContext::DeleteDirectoryRecurse(BackupStoreDirectory &, int64_t) +// Name: BackupStoreContext::DeleteDirectoryRecurse(BackupStoreDirectory &, int64_t) // Purpose: Private. Deletes a directory depth-first recusively. // Created: 2003/10/21 // // -------------------------------------------------------------------------- -void BackupContext::DeleteDirectoryRecurse(int64_t ObjectID, int64_t &rBlocksDeletedOut, bool Undelete) +void BackupStoreContext::DeleteDirectoryRecurse(int64_t ObjectID, int64_t &rBlocksDeletedOut, bool Undelete) { try { @@ -1129,12 +1130,12 @@ void BackupContext::DeleteDirectoryRecurse(int64_t ObjectID, int64_t &rBlocksDel // -------------------------------------------------------------------------- // // Function -// Name: BackupContext::ChangeDirAttributes(int64_t, const StreamableMemBlock &, int64_t) +// Name: BackupStoreContext::ChangeDirAttributes(int64_t, const StreamableMemBlock &, int64_t) // Purpose: Change the attributes of a directory // Created: 2003/09/06 // // -------------------------------------------------------------------------- -void BackupContext::ChangeDirAttributes(int64_t Directory, const StreamableMemBlock &Attributes, int64_t AttributesModTime) +void BackupStoreContext::ChangeDirAttributes(int64_t Directory, const StreamableMemBlock &Attributes, int64_t AttributesModTime) { if(mpStoreInfo.get() == 0) { @@ -1166,12 +1167,12 @@ void BackupContext::ChangeDirAttributes(int64_t Directory, const StreamableMemBl // -------------------------------------------------------------------------- // // Function -// Name: BackupContext::ChangeFileAttributes(int64_t, int64_t, const StreamableMemBlock &, int64_t) +// Name: BackupStoreContext::ChangeFileAttributes(int64_t, int64_t, const StreamableMemBlock &, int64_t) // Purpose: Sets the attributes on a directory entry. Returns true if the object existed, false if it didn't. // Created: 2003/09/06 // // -------------------------------------------------------------------------- -bool BackupContext::ChangeFileAttributes(const BackupStoreFilename &rFilename, int64_t InDirectory, const StreamableMemBlock &Attributes, int64_t AttributesHash, int64_t &rObjectIDOut) +bool BackupStoreContext::ChangeFileAttributes(const BackupStoreFilename &rFilename, int64_t InDirectory, const StreamableMemBlock &Attributes, int64_t AttributesHash, int64_t &rObjectIDOut) { if(mpStoreInfo.get() == 0) { @@ -1231,12 +1232,12 @@ bool BackupContext::ChangeFileAttributes(const BackupStoreFilename &rFilename, i // -------------------------------------------------------------------------- // // Function -// Name: BackupContext::ObjectExists(int64_t) +// Name: BackupStoreContext::ObjectExists(int64_t) // Purpose: Test to see if an object of this ID exists in the store // Created: 2003/09/03 // // -------------------------------------------------------------------------- -bool BackupContext::ObjectExists(int64_t ObjectID, int MustBe) +bool BackupStoreContext::ObjectExists(int64_t ObjectID, int MustBe) { if(mpStoreInfo.get() == 0) { @@ -1302,12 +1303,12 @@ bool BackupContext::ObjectExists(int64_t ObjectID, int MustBe) // -------------------------------------------------------------------------- // // Function -// Name: BackupContext::OpenObject(int64_t) +// Name: BackupStoreContext::OpenObject(int64_t) // Purpose: Opens an object // Created: 2003/09/03 // // -------------------------------------------------------------------------- -std::auto_ptr<IOStream> BackupContext::OpenObject(int64_t ObjectID) +std::auto_ptr<IOStream> BackupStoreContext::OpenObject(int64_t ObjectID) { if(mpStoreInfo.get() == 0) { @@ -1324,12 +1325,12 @@ std::auto_ptr<IOStream> BackupContext::OpenObject(int64_t ObjectID) // -------------------------------------------------------------------------- // // Function -// Name: BackupContext::GetClientStoreMarker() +// Name: BackupStoreContext::GetClientStoreMarker() // Purpose: Retrieve the client store marker // Created: 2003/10/29 // // -------------------------------------------------------------------------- -int64_t BackupContext::GetClientStoreMarker() +int64_t BackupStoreContext::GetClientStoreMarker() { if(mpStoreInfo.get() == 0) { @@ -1343,12 +1344,12 @@ int64_t BackupContext::GetClientStoreMarker() // -------------------------------------------------------------------------- // // Function -// Name: BackupContext::GetStoreDiscUsageInfo(int64_t &, int64_t &, int64_t &) +// Name: BackupStoreContext::GetStoreDiscUsageInfo(int64_t &, int64_t &, int64_t &) // Purpose: Get disc usage info from store info // Created: 1/1/04 // // -------------------------------------------------------------------------- -void BackupContext::GetStoreDiscUsageInfo(int64_t &rBlocksUsed, int64_t &rBlocksSoftLimit, int64_t &rBlocksHardLimit) +void BackupStoreContext::GetStoreDiscUsageInfo(int64_t &rBlocksUsed, int64_t &rBlocksSoftLimit, int64_t &rBlocksHardLimit) { if(mpStoreInfo.get() == 0) { @@ -1364,12 +1365,12 @@ void BackupContext::GetStoreDiscUsageInfo(int64_t &rBlocksUsed, int64_t &rBlocks // -------------------------------------------------------------------------- // // Function -// Name: BackupContext::HardLimitExceeded() +// Name: BackupStoreContext::HardLimitExceeded() // Purpose: Returns true if the hard limit has been exceeded // Created: 1/1/04 // // -------------------------------------------------------------------------- -bool BackupContext::HardLimitExceeded() +bool BackupStoreContext::HardLimitExceeded() { if(mpStoreInfo.get() == 0) { @@ -1383,12 +1384,12 @@ bool BackupContext::HardLimitExceeded() // -------------------------------------------------------------------------- // // Function -// Name: BackupContext::SetClientStoreMarker(int64_t) +// Name: BackupStoreContext::SetClientStoreMarker(int64_t) // Purpose: Sets the client store marker, and commits it to disc // Created: 2003/10/29 // // -------------------------------------------------------------------------- -void BackupContext::SetClientStoreMarker(int64_t ClientStoreMarker) +void BackupStoreContext::SetClientStoreMarker(int64_t ClientStoreMarker) { if(mpStoreInfo.get() == 0) { @@ -1407,12 +1408,12 @@ void BackupContext::SetClientStoreMarker(int64_t ClientStoreMarker) // -------------------------------------------------------------------------- // // Function -// Name: BackupContext::MoveObject(int64_t, int64_t, int64_t, const BackupStoreFilename &, bool) +// Name: BackupStoreContext::MoveObject(int64_t, int64_t, int64_t, const BackupStoreFilename &, bool) // Purpose: Move an object (and all objects with the same name) from one directory to another // Created: 12/11/03 // // -------------------------------------------------------------------------- -void BackupContext::MoveObject(int64_t ObjectID, int64_t MoveFromDirectory, int64_t MoveToDirectory, const BackupStoreFilename &rNewFilename, bool MoveAllWithSameName, bool AllowMoveOverDeletedObject) +void BackupStoreContext::MoveObject(int64_t ObjectID, int64_t MoveFromDirectory, int64_t MoveToDirectory, const BackupStoreFilename &rNewFilename, bool MoveAllWithSameName, bool AllowMoveOverDeletedObject) { if(mReadOnly) { @@ -1652,12 +1653,12 @@ void BackupContext::MoveObject(int64_t ObjectID, int64_t MoveFromDirectory, int6 // -------------------------------------------------------------------------- // // Function -// Name: BackupContext::GetBackupStoreInfo() +// Name: BackupStoreContext::GetBackupStoreInfo() // Purpose: Return the backup store info object, exception if it isn't loaded // Created: 19/4/04 // // -------------------------------------------------------------------------- -const BackupStoreInfo &BackupContext::GetBackupStoreInfo() const +const BackupStoreInfo &BackupStoreContext::GetBackupStoreInfo() const { if(mpStoreInfo.get() == 0) { diff --git a/bin/bbstored/BackupContext.h b/bin/bbstored/BackupStoreContext.h index 18f2f25c..3f0ba55a 100644 --- a/bin/bbstored/BackupContext.h +++ b/bin/bbstored/BackupStoreContext.h @@ -1,7 +1,7 @@ // -------------------------------------------------------------------------- // // File -// Name: BackupContext.h +// Name: BackupStoreContext.h // Purpose: Context for backup store server // Created: 2003/08/20 // @@ -15,6 +15,7 @@ #include <memory> #include "NamedLock.h" +#include "ProtocolObject.h" #include "Utils.h" class BackupStoreDirectory; @@ -22,23 +23,24 @@ class BackupStoreFilename; class BackupStoreDaemon; class BackupStoreInfo; class IOStream; +class BackupProtocolObject; class StreamableMemBlock; // -------------------------------------------------------------------------- // // Class -// Name: BackupContext +// Name: BackupStoreContext // Purpose: Context for backup store server // Created: 2003/08/20 // // -------------------------------------------------------------------------- -class BackupContext +class BackupStoreContext { public: - BackupContext(int32_t ClientID, BackupStoreDaemon &rDaemon); - ~BackupContext(); + BackupStoreContext(int32_t ClientID, BackupStoreDaemon &rDaemon); + ~BackupStoreContext(); private: - BackupContext(const BackupContext &rToCopy); + BackupStoreContext(const BackupStoreContext &rToCopy); public: void ReceivedFinishCommand(); @@ -83,7 +85,7 @@ public: // -------------------------------------------------------------------------- // // Function - // Name: BackupContext::GetDirectory(int64_t) + // Name: BackupStoreContext::GetDirectory(int64_t) // Purpose: Return a reference to a directory. Valid only until the // next time a function which affects directories is called. // Mainly this funciton, and creation of files. @@ -143,6 +145,30 @@ private: // Directory cache std::map<int64_t, BackupStoreDirectory*> mDirectoryCache; + +public: + class TestHook + { + public: + virtual std::auto_ptr<ProtocolObject> StartCommand(BackupProtocolObject& + rCommand) = 0; + virtual ~TestHook() { } + }; + void SetTestHook(TestHook& rTestHook) + { + mpTestHook = &rTestHook; + } + std::auto_ptr<ProtocolObject> StartCommandHook(BackupProtocolObject& rCommand) + { + if(mpTestHook) + { + return mpTestHook->StartCommand(rCommand); + } + return std::auto_ptr<ProtocolObject>(); + } + +private: + TestHook* mpTestHook; }; #endif // BACKUPCONTEXT__H diff --git a/bin/bbstored/BackupStoreDaemon.cpp b/bin/bbstored/BackupStoreDaemon.cpp index 28e28176..ca620df2 100644 --- a/bin/bbstored/BackupStoreDaemon.cpp +++ b/bin/bbstored/BackupStoreDaemon.cpp @@ -17,7 +17,7 @@ #include <syslog.h> #endif -#include "BackupContext.h" +#include "BackupStoreContext.h" #include "BackupStoreDaemon.h" #include "BackupStoreConfigVerify.h" #include "autogen_BackupProtocolServer.h" @@ -43,7 +43,8 @@ BackupStoreDaemon::BackupStoreDaemon() mHaveForkedHousekeeping(false), mIsHousekeepingProcess(false), mHousekeepingInited(false), - mInterProcessComms(mInterProcessCommsSocket) + mInterProcessComms(mInterProcessCommsSocket), + mpTestHook(NULL) { } @@ -320,7 +321,12 @@ void BackupStoreDaemon::Connection2(SocketStreamTLS &rStream) SetProcessTitle("client %08x", id); // Create a context, using this ID - BackupContext context(id, *this); + BackupStoreContext context(id, *this); + + if (mpTestHook) + { + context.SetTestHook(*mpTestHook); + } // See if the client has an account? if(mpAccounts && mpAccounts->AccountExists(id)) diff --git a/bin/bbstored/BackupStoreDaemon.h b/bin/bbstored/BackupStoreDaemon.h index 387a1d5b..dff918a5 100644 --- a/bin/bbstored/BackupStoreDaemon.h +++ b/bin/bbstored/BackupStoreDaemon.h @@ -13,6 +13,7 @@ #include "ServerTLS.h" #include "BoxPortsAndFiles.h" #include "BackupConstants.h" +#include "BackupStoreContext.h" #include "IOStreamGetLine.h" class BackupStoreAccounts; @@ -38,7 +39,7 @@ private: BackupStoreDaemon(const BackupStoreDaemon &rToCopy); public: - // For BackupContext to communicate with housekeeping process + // For BackupStoreContext to communicate with housekeeping process void SendMessageToHousekeepingProcess(const void *Msg, int MsgLen) { #ifndef WIN32 @@ -81,6 +82,15 @@ private: void HousekeepingInit(); void RunHousekeepingIfNeeded(); int64_t mLastHousekeepingRun; + +public: + void SetTestHook(BackupStoreContext::TestHook& rTestHook) + { + mpTestHook = &rTestHook; + } + +private: + BackupStoreContext::TestHook* mpTestHook; }; diff --git a/bin/bbstored/backupprotocol.txt b/bin/bbstored/backupprotocol.txt index 62d837ff..d5406ae2 100644 --- a/bin/bbstored/backupprotocol.txt +++ b/bin/bbstored/backupprotocol.txt @@ -4,7 +4,7 @@ Name Backup IdentString Box-Backup:v=C -ServerContextClass BackupContext BackupContext.h +ServerContextClass BackupStoreContext BackupStoreContext.h ClientType Filename BackupStoreFilenameClear BackupStoreFilenameClear.h ServerType Filename BackupStoreFilename BackupStoreFilename.h |