diff options
28 files changed, 1163 insertions, 1041 deletions
diff --git a/bin/bbackupd/BackupClientContext.cpp b/bin/bbackupd/BackupClientContext.cpp index 6b51b9e8..7602ed29 100644 --- a/bin/bbackupd/BackupClientContext.cpp +++ b/bin/bbackupd/BackupClientContext.cpp @@ -25,7 +25,7 @@ #include "BackupStoreConstants.h" #include "BackupStoreException.h" #include "BackupDaemon.h" -#include "autogen_BackupProtocolClient.h" +#include "autogen_BackupProtocol.h" #include "BackupStoreFile.h" #include "Logging.h" @@ -165,7 +165,7 @@ BackupProtocolClient &BackupClientContext::GetConnection() // Check the version of the server { - std::auto_ptr<BackupProtocolClientVersion> serverVersion(mpConnection->QueryVersion(BACKUP_STORE_SERVER_VERSION)); + std::auto_ptr<BackupProtocolVersion> serverVersion(mpConnection->QueryVersion(BACKUP_STORE_SERVER_VERSION)); if(serverVersion->GetVersion() != BACKUP_STORE_SERVER_VERSION) { THROW_EXCEPTION(BackupStoreException, WrongServerVersion) @@ -173,7 +173,7 @@ BackupProtocolClient &BackupClientContext::GetConnection() } // Login -- if this fails, the Protocol will exception - std::auto_ptr<BackupProtocolClientLoginConfirmed> loginConf(mpConnection->QueryLogin(mAccountNumber, 0 /* read/write */)); + std::auto_ptr<BackupProtocolLoginConfirmed> loginConf(mpConnection->QueryLogin(mAccountNumber, 0 /* read/write */)); // Check that the client store marker is the one we expect if(mClientStoreMarker != ClientStoreMarker_NotKnown) @@ -419,20 +419,20 @@ bool BackupClientContext::FindFilename(int64_t ObjectID, int64_t ContainingDirec // Request filenames from the server, in a "safe" manner to ignore errors properly { - BackupProtocolClientGetObjectName send(ObjectID, ContainingDirectory); + BackupProtocolGetObjectName send(ObjectID, ContainingDirectory); connection.Send(send); } - std::auto_ptr<BackupProtocolObjectCl> preply(connection.Receive()); + std::auto_ptr<BackupProtocolMessage> preply(connection.Receive()); // Is it of the right type? - if(preply->GetType() != BackupProtocolClientObjectName::TypeID) + if(preply->GetType() != BackupProtocolObjectName::TypeID) { // Was an error or something return false; } // Cast to expected type. - BackupProtocolClientObjectName *names = (BackupProtocolClientObjectName *)(preply.get()); + BackupProtocolObjectName *names = (BackupProtocolObjectName *)(preply.get()); // Anything found? int32_t numElements = names->GetNumNameElements(); @@ -482,10 +482,10 @@ bool BackupClientContext::FindFilename(int64_t ObjectID, int64_t ContainingDirec } // Is it a directory? - rIsDirectoryOut = ((names->GetFlags() & BackupProtocolClientListDirectory::Flags_Dir) == BackupProtocolClientListDirectory::Flags_Dir); + rIsDirectoryOut = ((names->GetFlags() & BackupProtocolListDirectory::Flags_Dir) == BackupProtocolListDirectory::Flags_Dir); // Is it the current version? - rIsCurrentVersionOut = ((names->GetFlags() & (BackupProtocolClientListDirectory::Flags_OldVersion | BackupProtocolClientListDirectory::Flags_Deleted)) == 0); + rIsCurrentVersionOut = ((names->GetFlags() & (BackupProtocolListDirectory::Flags_OldVersion | BackupProtocolListDirectory::Flags_Deleted)) == 0); // And other information which may be required if(pModTimeOnServer) *pModTimeOnServer = names->GetModificationTime(); diff --git a/bin/bbackupd/BackupClientDeleteList.cpp b/bin/bbackupd/BackupClientDeleteList.cpp index b9b5b53e..c0414b78 100644 --- a/bin/bbackupd/BackupClientDeleteList.cpp +++ b/bin/bbackupd/BackupClientDeleteList.cpp @@ -13,7 +13,7 @@ #include "BackupClientDeleteList.h" #include "BackupClientContext.h" -#include "autogen_BackupProtocolClient.h" +#include "autogen_BackupProtocol.h" #include "MemLeakFindOn.h" diff --git a/bin/bbackupd/BackupClientDirectoryRecord.cpp b/bin/bbackupd/BackupClientDirectoryRecord.cpp index b5c9fbcd..3f95be47 100644 --- a/bin/bbackupd/BackupClientDirectoryRecord.cpp +++ b/bin/bbackupd/BackupClientDirectoryRecord.cpp @@ -17,7 +17,7 @@ #include <errno.h> #include <string.h> -#include "autogen_BackupProtocolClient.h" +#include "autogen_BackupProtocol.h" #include "Archive.h" #include "BackupClientContext.h" #include "BackupClientDirectoryRecord.h" @@ -335,7 +335,7 @@ void BackupClientDirectoryRecord::SyncDirectory( filename << ", nlink=" << file_st.st_nlink); } - else if(file_st.st_nlink != 1) + else if(file_st.st_nlink > 1) { if(!mSuppressMultipleLinksWarning) { @@ -613,10 +613,11 @@ BackupStoreDirectory *BackupClientDirectoryRecord::FetchDirectoryListing(BackupC BackupProtocolClient &connection(rParams.mrContext.GetConnection()); // Query the directory - std::auto_ptr<BackupProtocolClientSuccess> dirreply(connection.QueryListDirectory( + std::auto_ptr<BackupProtocolSuccess> dirreply(connection.QueryListDirectory( mObjectID, - BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING, // both files and directories - BackupProtocolClientListDirectory::Flags_Deleted | BackupProtocolClientListDirectory::Flags_OldVersion, // exclude old/deleted stuff + BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING, // both files and directories + BackupProtocolListDirectory::Flags_Deleted | + BackupProtocolListDirectory::Flags_OldVersion, // exclude old/deleted stuff true /* want attributes */)); // Retrieve the directory from the stream following @@ -830,7 +831,8 @@ bool BackupClientDirectoryRecord::UpdateItems( { // Rename the existing files (ie include old versions) on the server connection.QueryMoveObject(renameObjectID, renameInDirectory, mObjectID /* move to this directory */, - BackupProtocolClientMoveObject::Flags_MoveAllWithSameName | BackupProtocolClientMoveObject::Flags_AllowMoveOverDeletedObject, + BackupProtocolMoveObject::Flags_MoveAllWithSameName | + BackupProtocolMoveObject::Flags_AllowMoveOverDeletedObject, storeFilename); // Stop the attempt to delete the file in the original location @@ -1364,7 +1366,8 @@ bool BackupClientDirectoryRecord::UpdateItems( { // Rename the existing directory on the server connection.QueryMoveObject(renameObjectID, renameInDirectory, mObjectID /* move to this directory */, - BackupProtocolClientMoveObject::Flags_MoveAllWithSameName | BackupProtocolClientMoveObject::Flags_AllowMoveOverDeletedObject, + BackupProtocolMoveObject::Flags_MoveAllWithSameName | + BackupProtocolMoveObject::Flags_AllowMoveOverDeletedObject, storeFilename); // Put the latest attributes on it @@ -1381,7 +1384,7 @@ bool BackupClientDirectoryRecord::UpdateItems( else { // Create a new directory - std::auto_ptr<BackupProtocolClientSuccess> dirCreate(connection.QueryCreateDirectory( + std::auto_ptr<BackupProtocolSuccess> dirCreate(connection.QueryCreateDirectory( mObjectID, attrModTime, storeFilename, attrStream)); subDirObjectID = dirCreate->GetObjectID(); @@ -1577,7 +1580,7 @@ int64_t BackupClientDirectoryRecord::UploadFile( { // YES -- try to do diff, if possible // First, query the server to see if there's an old version available - std::auto_ptr<BackupProtocolClientSuccess> getBlockIndex(connection.QueryGetBlockIndexByName(mObjectID, rStoreFilename)); + std::auto_ptr<BackupProtocolSuccess> getBlockIndex(connection.QueryGetBlockIndexByName(mObjectID, rStoreFilename)); int64_t diffFromID = getBlockIndex->GetObjectID(); if(diffFromID != 0) @@ -1625,7 +1628,7 @@ int64_t BackupClientDirectoryRecord::UploadFile( // // Upload the patch to the store // - std::auto_ptr<BackupProtocolClientSuccess> stored(connection.QueryStoreFile(mObjectID, ModificationTime, + std::auto_ptr<BackupProtocolSuccess> stored(connection.QueryStoreFile(mObjectID, ModificationTime, AttributesHash, isCompletelyDifferent?(0):(diffFromID), rStoreFilename, *pStreamToUpload)); // Get object ID from the result @@ -1666,7 +1669,7 @@ int64_t BackupClientDirectoryRecord::UploadFile( } // Send to store - std::auto_ptr<BackupProtocolClientSuccess> stored( + std::auto_ptr<BackupProtocolSuccess> stored( connection.QueryStoreFile( mObjectID, ModificationTime, AttributesHash, @@ -1692,8 +1695,8 @@ int64_t BackupClientDirectoryRecord::UploadFile( int type, subtype; if(connection.GetLastError(type, subtype)) { - if(type == BackupProtocolClientError::ErrorType - && subtype == BackupProtocolClientError::Err_StorageLimitExceeded) + if(type == BackupProtocolError::ErrorType + && subtype == BackupProtocolError::Err_StorageLimitExceeded) { // The hard limit was exceeded on the server, notify! rParams.mrSysadminNotifier.NotifySysadmin( diff --git a/bin/bbackupd/BackupDaemon.cpp b/bin/bbackupd/BackupDaemon.cpp index ccc52b8a..215c65a2 100644 --- a/bin/bbackupd/BackupDaemon.cpp +++ b/bin/bbackupd/BackupDaemon.cpp @@ -50,7 +50,7 @@ #include "SSLLib.h" -#include "autogen_BackupProtocolClient.h" +#include "autogen_BackupProtocol.h" #include "autogen_ClientException.h" #include "autogen_ConversionException.h" #include "Archive.h" @@ -696,6 +696,7 @@ void BackupDaemon::RunSyncNowWithExceptionHandling() // do not retry immediately without a good reason mDoSyncForcedByPreviousSyncError = false; + // Notify system administrator about the final state of the backup if(errorOccurred) { // Is it a berkely db failure? @@ -757,16 +758,19 @@ void BackupDaemon::RunSyncNowWithExceptionHandling() SYNC_PERIOD_RANDOM_EXTRA_TIME_SHIFT_BY); } } - // Notify system administrator about the final state of the backup - else if(mReadErrorsOnFilesystemObjects) + + if(mReadErrorsOnFilesystemObjects) { NotifySysadmin(SysadminNotifier::ReadError); } - else if(mStorageLimitExceeded) + + if(mStorageLimitExceeded) { NotifySysadmin(SysadminNotifier::StoreFull); } - else + + if (!errorOccurred && !mReadErrorsOnFilesystemObjects && + !mStorageLimitExceeded) { NotifySysadmin(SysadminNotifier::BackupOK); } @@ -1004,7 +1008,7 @@ void BackupDaemon::RunSyncNow() #endif (*i)->mpDirectoryRecord->SyncDirectory(params, - BackupProtocolClientListDirectory::RootDirectory, + BackupProtocolListDirectory::RootDirectory, locationPath, std::string("/") + (*i)->mName); // Unset exclude lists (just in case) @@ -2097,18 +2101,18 @@ void BackupDaemon::SetupLocations(BackupClientContext &rClientContext, const Con // Going to need a copy of the root directory. Get a connection, // and fetch it. - BackupProtocolClient &connection(rClientContext.GetConnection()); + BackupProtocolCallable& connection(rClientContext.GetConnection()); // Ask server for a list of everything in the root directory, // which is a directory itself - std::auto_ptr<BackupProtocolClientSuccess> dirreply( + std::auto_ptr<BackupProtocolSuccess> dirreply( connection.QueryListDirectory( - BackupProtocolClientListDirectory::RootDirectory, + BackupProtocolListDirectory::RootDirectory, // only directories - BackupProtocolClientListDirectory::Flags_Dir, + BackupProtocolListDirectory::Flags_Dir, // exclude old/deleted stuff - BackupProtocolClientListDirectory::Flags_Deleted | - BackupProtocolClientListDirectory::Flags_OldVersion, + BackupProtocolListDirectory::Flags_Deleted | + BackupProtocolListDirectory::Flags_OldVersion, false /* no attributes */)); // Retrieve the directory from the stream following @@ -2348,9 +2352,9 @@ void BackupDaemon::SetupLocations(BackupClientContext &rClientContext, const Con try { MemBlockStream attrStream(attr); - std::auto_ptr<BackupProtocolClientSuccess> + std::auto_ptr<BackupProtocolSuccess> dirCreate(connection.QueryCreateDirectory( - BackupProtocolClientListDirectory::RootDirectory, + BackupProtocolListDirectory::RootDirectory, attrModTime, dirname, attrStream)); // Object ID for later creation @@ -2894,7 +2898,7 @@ void BackupDaemon::DeleteUnusedRootDirEntries(BackupClientContext &rContext) // Entries to delete, and it's the right time to do so... BOX_NOTICE("Deleting unused locations from store root..."); - BackupProtocolClient &connection(rContext.GetConnection()); + BackupProtocolCallable &connection(rContext.GetConnection()); for(std::vector<std::pair<int64_t,std::string> >::iterator i(mUnusedRootDirEntries.begin()); i != mUnusedRootDirEntries.end(); ++i) diff --git a/bin/bbackupd/BackupDaemon.h b/bin/bbackupd/BackupDaemon.h index 23172f00..4a9097b9 100644 --- a/bin/bbackupd/BackupDaemon.h +++ b/bin/bbackupd/BackupDaemon.h @@ -24,7 +24,7 @@ #include "SocketStream.h" #include "TLSContext.h" -#include "autogen_BackupProtocolClient.h" +#include "autogen_BackupProtocol.h" #ifdef WIN32 #include "WinNamedPipeListener.h" @@ -382,7 +382,7 @@ public: int type, int subtype) { std::ostringstream msgs; - if (type != BackupProtocolClientError::ErrorType) + if (type != BackupProtocolError::ErrorType) { msgs << "unknown error type " << type; } @@ -390,46 +390,46 @@ public: { switch(subtype) { - case BackupProtocolClientError::Err_WrongVersion: + case BackupProtocolError::Err_WrongVersion: msgs << "WrongVersion"; break; - case BackupProtocolClientError::Err_NotInRightProtocolPhase: + case BackupProtocolError::Err_NotInRightProtocolPhase: msgs << "NotInRightProtocolPhase"; break; - case BackupProtocolClientError::Err_BadLogin: + case BackupProtocolError::Err_BadLogin: msgs << "BadLogin"; break; - case BackupProtocolClientError::Err_CannotLockStoreForWriting: + case BackupProtocolError::Err_CannotLockStoreForWriting: msgs << "CannotLockStoreForWriting"; break; - case BackupProtocolClientError::Err_SessionReadOnly: + case BackupProtocolError::Err_SessionReadOnly: msgs << "SessionReadOnly"; break; - case BackupProtocolClientError::Err_FileDoesNotVerify: + case BackupProtocolError::Err_FileDoesNotVerify: msgs << "FileDoesNotVerify"; break; - case BackupProtocolClientError::Err_DoesNotExist: + case BackupProtocolError::Err_DoesNotExist: msgs << "DoesNotExist"; break; - case BackupProtocolClientError::Err_DirectoryAlreadyExists: + case BackupProtocolError::Err_DirectoryAlreadyExists: msgs << "DirectoryAlreadyExists"; break; - case BackupProtocolClientError::Err_CannotDeleteRoot: + case BackupProtocolError::Err_CannotDeleteRoot: msgs << "CannotDeleteRoot"; break; - case BackupProtocolClientError::Err_TargetNameExists: + case BackupProtocolError::Err_TargetNameExists: msgs << "TargetNameExists"; break; - case BackupProtocolClientError::Err_StorageLimitExceeded: + case BackupProtocolError::Err_StorageLimitExceeded: msgs << "StorageLimitExceeded"; break; - case BackupProtocolClientError::Err_DiffFromFileDoesNotExist: + case BackupProtocolError::Err_DiffFromFileDoesNotExist: msgs << "DiffFromFileDoesNotExist"; break; - case BackupProtocolClientError::Err_DoesNotExistInDirectory: + case BackupProtocolError::Err_DoesNotExistInDirectory: msgs << "DoesNotExistInDirectory"; break; - case BackupProtocolClientError::Err_PatchConsistencyError: + case BackupProtocolError::Err_PatchConsistencyError: msgs << "PatchConsistencyError"; break; default: diff --git a/bin/bbackupquery/BackupQueries.cpp b/bin/bbackupquery/BackupQueries.cpp index edeeb034..3a63f8b5 100644 --- a/bin/bbackupquery/BackupQueries.cpp +++ b/bin/bbackupquery/BackupQueries.cpp @@ -49,7 +49,7 @@ #include "PathUtils.h" #include "SelfFlushingStream.h" #include "Utils.h" -#include "autogen_BackupProtocolClient.h" +#include "autogen_BackupProtocol.h" #include "MemLeakFindOn.h" @@ -358,16 +358,16 @@ static std::string GetTimeString(BackupStoreDirectory::Entry& en, void BackupQueries::List(int64_t DirID, const std::string &rListRoot, const bool *opts, bool FirstLevel) { // Generate exclude flags - int16_t excludeFlags = BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING; - if(!opts[LIST_OPTION_ALLOWOLD]) excludeFlags |= BackupProtocolClientListDirectory::Flags_OldVersion; - if(!opts[LIST_OPTION_ALLOWDELETED]) excludeFlags |= BackupProtocolClientListDirectory::Flags_Deleted; + int16_t excludeFlags = BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING; + if(!opts[LIST_OPTION_ALLOWOLD]) excludeFlags |= BackupProtocolListDirectory::Flags_OldVersion; + if(!opts[LIST_OPTION_ALLOWDELETED]) excludeFlags |= BackupProtocolListDirectory::Flags_Deleted; // Do communication try { mrConnection.QueryListDirectory( DirID, - BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING, + BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING, // both files and directories excludeFlags, true /* want attributes */); @@ -434,7 +434,7 @@ void BackupQueries::List(int64_t DirID, const std::string &rListRoot, const bool // terminate *(f++) = ' '; *(f++) = '\0'; - printf(displayflags); + printf("%s", displayflags); if(en_flags != 0) { @@ -544,7 +544,7 @@ int64_t BackupQueries::FindDirectoryObjectID(const std::string &rDirName, // Start from current stack, or root, whichever is required std::vector<std::pair<std::string, int64_t> > stack; - int64_t dirID = BackupProtocolClientListDirectory::RootDirectory; + int64_t dirID = BackupProtocolListDirectory::RootDirectory; if(rDirName.size() > 0 && rDirName[0] == '/') { // Root, do nothing @@ -560,9 +560,9 @@ int64_t BackupQueries::FindDirectoryObjectID(const std::string &rDirName, } // Generate exclude flags - int16_t excludeFlags = BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING; - if(!AllowOldVersion) excludeFlags |= BackupProtocolClientListDirectory::Flags_OldVersion; - if(!AllowDeletedDirs) excludeFlags |= BackupProtocolClientListDirectory::Flags_Deleted; + int16_t excludeFlags = BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING; + if(!AllowOldVersion) excludeFlags |= BackupProtocolListDirectory::Flags_OldVersion; + if(!AllowDeletedDirs) excludeFlags |= BackupProtocolListDirectory::Flags_Deleted; // Read directories for(unsigned int e = 0; e < dirElements.size(); ++e) @@ -582,20 +582,20 @@ int64_t BackupQueries::FindDirectoryObjectID(const std::string &rDirName, stack.pop_back(); // New dir ID - dirID = (stack.size() > 0)?(stack[stack.size() - 1].second):BackupProtocolClientListDirectory::RootDirectory; + dirID = (stack.size() > 0)?(stack[stack.size() - 1].second):BackupProtocolListDirectory::RootDirectory; } else { // At root anyway - dirID = BackupProtocolClientListDirectory::RootDirectory; + dirID = BackupProtocolListDirectory::RootDirectory; } } else { // Not blank element. Read current directory. - std::auto_ptr<BackupProtocolClientSuccess> dirreply(mrConnection.QueryListDirectory( + std::auto_ptr<BackupProtocolSuccess> dirreply(mrConnection.QueryListDirectory( dirID, - BackupProtocolClientListDirectory::Flags_Dir, // just directories + BackupProtocolListDirectory::Flags_Dir, // just directories excludeFlags, true /* want attributes */)); @@ -646,7 +646,7 @@ int64_t BackupQueries::GetCurrentDirectoryID() // Special case for root if(mDirStack.size() == 0) { - return BackupProtocolClientListDirectory::RootDirectory; + return BackupProtocolListDirectory::RootDirectory; } // Otherwise, get from the last entry on the stack @@ -837,8 +837,8 @@ void BackupQueries::CommandGetObject(const std::vector<std::string> &args, const try { // Request object - std::auto_ptr<BackupProtocolClientSuccess> getobj(mrConnection.QueryGetObject(id)); - if(getobj->GetObjectID() != BackupProtocolClientGetObject::NoObject) + std::auto_ptr<BackupProtocolSuccess> getobj(mrConnection.QueryGetObject(id)); + if(getobj->GetObjectID() != BackupProtocolGetObject::NoObject) { // Stream that object out to the file std::auto_ptr<IOStream> objectStream(mrConnection.ReceiveStream()); @@ -1017,19 +1017,19 @@ void BackupQueries::CommandGet(std::vector<std::string> args, const bool *opts) if(opts['i']) { // can retrieve anything by ID - flagsExclude = BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING; + flagsExclude = BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING; } else { // only current versions by name flagsExclude = - BackupProtocolClientListDirectory::Flags_OldVersion | - BackupProtocolClientListDirectory::Flags_Deleted; + BackupProtocolListDirectory::Flags_OldVersion | + BackupProtocolListDirectory::Flags_Deleted; } fileId = FindFileID(args[0], opts, &dirId, &localName, - BackupProtocolClientListDirectory::Flags_File, // just files + BackupProtocolListDirectory::Flags_File, // just files flagsExclude, NULL /* don't care about flags found */); if (fileId == 0) @@ -1519,10 +1519,10 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, // Get the directory listing from the store mrConnection.QueryListDirectory( DirID, - BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING, + BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING, // get everything - BackupProtocolClientListDirectory::Flags_OldVersion | - BackupProtocolClientListDirectory::Flags_Deleted, + BackupProtocolListDirectory::Flags_OldVersion | + BackupProtocolListDirectory::Flags_Deleted, // except for old versions and deleted files true /* want attributes */); @@ -1896,7 +1896,7 @@ void BackupQueries::CommandRestore(const std::vector<std::string> &args, const b return; } - if(dirID == BackupProtocolClientListDirectory::RootDirectory) + if(dirID == BackupProtocolListDirectory::RootDirectory) { BOX_ERROR("Cannot restore the root directory -- restore locations individually."); return; @@ -2053,7 +2053,7 @@ void BackupQueries::CommandUsage(const bool *opts) bool MachineReadable = opts['m']; // Request full details from the server - std::auto_ptr<BackupProtocolClientAccountUsage> usage(mrConnection.QueryGetAccountUsage()); + std::auto_ptr<BackupProtocolAccountUsage> usage(mrConnection.QueryGetAccountUsage()); // Display each entry in turn int64_t hardLimit = usage->GetBlocksHardLimit(); @@ -2129,9 +2129,9 @@ void BackupQueries::CommandUndelete(const std::vector<std::string> &args, const fileId = FindFileID(storeDirEncoded, opts, &parentId, &fileName, /* include files and directories */ - BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, + BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, /* include old and deleted files */ - BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, + BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, &flagsOut); if (fileId == 0) @@ -2144,7 +2144,7 @@ void BackupQueries::CommandUndelete(const std::vector<std::string> &args, const try { // Undelete object - if(flagsOut & BackupProtocolClientListDirectory::Flags_File) + if(flagsOut & BackupProtocolListDirectory::Flags_File) { mrConnection.QueryUndeleteFile(parentId, fileId); } @@ -2209,10 +2209,10 @@ void BackupQueries::CommandDelete(const std::vector<std::string> &args, fileId = FindFileID(storeDirEncoded, opts, &parentId, &fileName, /* include files and directories */ - BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, + BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, /* exclude old and deleted files */ - BackupProtocolClientListDirectory::Flags_OldVersion | - BackupProtocolClientListDirectory::Flags_Deleted, + BackupProtocolListDirectory::Flags_OldVersion | + BackupProtocolListDirectory::Flags_Deleted, &flagsOut); if (fileId == 0) @@ -2227,7 +2227,7 @@ void BackupQueries::CommandDelete(const std::vector<std::string> &args, try { // Delete object - if(flagsOut & BackupProtocolClientListDirectory::Flags_File) + if(flagsOut & BackupProtocolListDirectory::Flags_File) { mrConnection.QueryDeleteFile(parentId, fn); } diff --git a/bin/bbackupquery/CommandCompletion.cpp b/bin/bbackupquery/CommandCompletion.cpp index f7dab973..6d6189b3 100644 --- a/bin/bbackupquery/CommandCompletion.cpp +++ b/bin/bbackupquery/CommandCompletion.cpp @@ -32,7 +32,7 @@ #include "BackupQueries.h" #include "Configuration.h" -#include "autogen_BackupProtocolClient.h" +#include "autogen_BackupProtocol.h" #include "MemLeakFindOn.h" @@ -154,12 +154,12 @@ int16_t GetExcludeFlags(BackupQueries::ParsedCommand& rCommand) if (rCommand.mOptions.find(LIST_OPTION_ALLOWOLD) == std::string::npos) { - excludeFlags |= BackupProtocolClientListDirectory::Flags_OldVersion; + excludeFlags |= BackupProtocolListDirectory::Flags_OldVersion; } if (rCommand.mOptions.find(LIST_OPTION_ALLOWDELETED) == std::string::npos) { - excludeFlags |= BackupProtocolClientListDirectory::Flags_Deleted; + excludeFlags |= BackupProtocolListDirectory::Flags_Deleted; } return excludeFlags; @@ -225,18 +225,18 @@ std::vector<std::string> CompleteRemoteFileOrDirectory( // If we're looking for directories, then only list directories. bool completeFiles = includeFlags & - BackupProtocolClientListDirectory::Flags_File; + BackupProtocolListDirectory::Flags_File; bool completeDirs = includeFlags & - BackupProtocolClientListDirectory::Flags_Dir; + BackupProtocolListDirectory::Flags_Dir; int16_t listFlags = 0; if(completeFiles) { - listFlags = BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING; + listFlags = BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING; } else if(completeDirs) { - listFlags = BackupProtocolClientListDirectory::Flags_Dir; + listFlags = BackupProtocolListDirectory::Flags_Dir; } rProtocol.QueryListDirectory(listDirId, @@ -258,7 +258,7 @@ std::vector<std::string> CompleteRemoteFileOrDirectory( if(name.compare(0, searchPrefix.length(), searchPrefix) == 0) { if(en->IsDir() && - (includeFlags & BackupProtocolClientListDirectory::Flags_Dir) == 0) + (includeFlags & BackupProtocolListDirectory::Flags_Dir) == 0) { // Was looking for a file, but this is a // directory, so append a slash to the name @@ -282,13 +282,13 @@ std::vector<std::string> CompleteRemoteFileOrDirectory( COMPLETION_FUNCTION(RemoteDir, completions = CompleteRemoteFileOrDirectory(rCommand, prefix, rProtocol, rQueries, - BackupProtocolClientListDirectory::Flags_Dir); + BackupProtocolListDirectory::Flags_Dir); ) COMPLETION_FUNCTION(RemoteFile, completions = CompleteRemoteFileOrDirectory(rCommand, prefix, rProtocol, rQueries, - BackupProtocolClientListDirectory::Flags_File); + BackupProtocolListDirectory::Flags_File); ) COMPLETION_FUNCTION(LocalDir, @@ -324,7 +324,7 @@ COMPLETION_FUNCTION(RemoteFileIdInCurrentDir, rProtocol.QueryListDirectory( listDirId, - BackupProtocolClientListDirectory::Flags_File, + BackupProtocolListDirectory::Flags_File, excludeFlags, false /* no attributes */); // Retrieve the directory from the stream following diff --git a/bin/bbackupquery/bbackupquery.cpp b/bin/bbackupquery/bbackupquery.cpp index 788db51f..a89fba5f 100644 --- a/bin/bbackupquery/bbackupquery.cpp +++ b/bin/bbackupquery/bbackupquery.cpp @@ -50,7 +50,7 @@ #include "SSLLib.h" #include "BackupStoreConstants.h" #include "BackupStoreException.h" -#include "autogen_BackupProtocolClient.h" +#include "autogen_BackupProtocol.h" #include "BackupQueries.h" #include "FdGetLine.h" #include "BackupClientCryptoKeys.h" @@ -447,7 +447,7 @@ int main(int argc, const char *argv[]) if(!quiet) BOX_INFO("Login to store..."); // Check the version of the server { - std::auto_ptr<BackupProtocolClientVersion> serverVersion(connection.QueryVersion(BACKUP_STORE_SERVER_VERSION)); + std::auto_ptr<BackupProtocolVersion> serverVersion(connection.QueryVersion(BACKUP_STORE_SERVER_VERSION)); if(serverVersion->GetVersion() != BACKUP_STORE_SERVER_VERSION) { THROW_EXCEPTION(BackupStoreException, WrongServerVersion) @@ -455,7 +455,7 @@ int main(int argc, const char *argv[]) } // Login -- if this fails, the Protocol will exception connection.QueryLogin(conf.GetKeyValueUint32("AccountNumber"), - (readWrite)?0:(BackupProtocolClientLogin::Flags_ReadOnly)); + (readWrite)?0:(BackupProtocolLogin::Flags_ReadOnly)); // 5. Tell user. if(!quiet) printf("Login complete.\n\nType \"help\" for a list of commands.\n\n"); diff --git a/bin/bbstored/BackupStoreDaemon.cpp b/bin/bbstored/BackupStoreDaemon.cpp index 446dbfb7..2bf0073c 100644 --- a/bin/bbstored/BackupStoreDaemon.cpp +++ b/bin/bbstored/BackupStoreDaemon.cpp @@ -20,7 +20,7 @@ #include "BackupStoreContext.h" #include "BackupStoreDaemon.h" #include "BackupStoreConfigVerify.h" -#include "autogen_BackupProtocolServer.h" +#include "autogen_BackupProtocol.h" #include "RaidFileController.h" #include "BackupStoreAccountDatabase.h" #include "BackupStoreAccounts.h" diff --git a/lib/backupclient/BackupClientRestore.cpp b/lib/backupclient/BackupClientRestore.cpp index fa61bb59..4993f6ae 100644 --- a/lib/backupclient/BackupClientRestore.cpp +++ b/lib/backupclient/BackupClientRestore.cpp @@ -22,7 +22,7 @@ #include <errno.h> #include "BackupClientRestore.h" -#include "autogen_BackupProtocolClient.h" +#include "autogen_BackupProtocol.h" #include "CommonException.h" #include "BackupClientFileAttributes.h" #include "IOStream.h" @@ -443,8 +443,8 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, // list of files which is appropriate to the restore type rConnection.QueryListDirectory( DirectoryID, - Params.RestoreDeleted?(BackupProtocolClientListDirectory::Flags_Deleted):(BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING), - BackupProtocolClientListDirectory::Flags_OldVersion | (Params.RestoreDeleted?(0):(BackupProtocolClientListDirectory::Flags_Deleted)), + Params.RestoreDeleted?(BackupProtocolListDirectory::Flags_Deleted):(BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING), + BackupProtocolListDirectory::Flags_OldVersion | (Params.RestoreDeleted?(0):(BackupProtocolListDirectory::Flags_Deleted)), true /* want attributes */); // Retrieve the directory from the stream following diff --git a/lib/backupstore/BackupCommands.cpp b/lib/backupstore/BackupCommands.cpp index 34f813df..9552d831 100644 --- a/lib/backupstore/BackupCommands.cpp +++ b/lib/backupstore/BackupCommands.cpp @@ -12,7 +12,7 @@ #include <set> #include <sstream> -#include "autogen_BackupProtocolServer.h" +#include "autogen_BackupProtocol.h" #include "autogen_RaidFileException.h" #include "BackupConstants.h" #include "BackupStoreContext.h" @@ -31,9 +31,9 @@ #include "MemLeakFindOn.h" #define PROTOCOL_ERROR(code) \ - std::auto_ptr<ProtocolObject>(new BackupProtocolServerError( \ - BackupProtocolServerError::ErrorType, \ - BackupProtocolServerError::code)); + std::auto_ptr<BackupProtocolMessage>(new BackupProtocolError( \ + BackupProtocolError::ErrorType, \ + BackupProtocolError::code)); #define CHECK_PHASE(phase) \ if(rContext.GetPhase() != BackupStoreContext::phase) \ @@ -50,12 +50,12 @@ // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerVersion::DoCommand(Protocol &, BackupStoreContext &) +// Name: BackupProtocolVersion::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, BackupStoreContext &rContext) +std::auto_ptr<BackupProtocolMessage> BackupProtocolVersion::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const { CHECK_PHASE(Phase_Version) @@ -69,18 +69,18 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerVersion::DoCommand(BackupProto rContext.SetPhase(BackupStoreContext::Phase_Login); // Return our version - return std::auto_ptr<ProtocolObject>(new BackupProtocolServerVersion(BACKUP_STORE_SERVER_VERSION)); + return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolVersion(BACKUP_STORE_SERVER_VERSION)); } // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerLogin::DoCommand(Protocol &, BackupStoreContext &) +// Name: BackupProtocolLogin::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, BackupStoreContext &rContext) +std::auto_ptr<BackupProtocolMessage> BackupProtocolLogin::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const { CHECK_PHASE(Phase_Login) @@ -138,18 +138,18 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerLogin::DoCommand(BackupProtoco rContext.GetStoreDiscUsageInfo(blocksUsed, blocksSoftLimit, blocksHardLimit); // Return success - return std::auto_ptr<ProtocolObject>(new BackupProtocolServerLoginConfirmed(clientStoreMarker, blocksUsed, blocksSoftLimit, blocksHardLimit)); + return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolLoginConfirmed(clientStoreMarker, blocksUsed, blocksSoftLimit, blocksHardLimit)); } // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerFinished::DoCommand(Protocol &, BackupStoreContext &) +// Name: BackupProtocolFinished::DoCommand(Protocol &, BackupStoreContext &) // Purpose: Marks end of conversation (Protocol framework handles this) // Created: 2003/08/20 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerFinished::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) +std::auto_ptr<BackupProtocolMessage> BackupProtocolFinished::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const { BOX_NOTICE("Session finished for Client ID " << BOX_FORMAT_ACCOUNT(rContext.GetClientID())); @@ -158,19 +158,19 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerFinished::DoCommand(BackupProt rContext.ReceivedFinishCommand(); // can be called in any phase - return std::auto_ptr<ProtocolObject>(new BackupProtocolServerFinished); + return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolFinished); } // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerListDirectory::DoCommand(Protocol &, BackupStoreContext &) +// Name: BackupProtocolListDirectory::DoCommand(Protocol &, BackupStoreContext &) // Purpose: Command to list a directory // Created: 2003/09/02 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerListDirectory::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) +std::auto_ptr<BackupProtocolMessage> BackupProtocolListDirectory::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const { CHECK_PHASE(Phase_Commands) @@ -200,24 +200,24 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerListDirectory::DoCommand(Backu // Get the protocol to send the stream rProtocol.SendStreamAfterCommand(stream.release()); - return std::auto_ptr<ProtocolObject>( - new BackupProtocolServerSuccess(mObjectID)); + return std::auto_ptr<BackupProtocolMessage>( + new BackupProtocolSuccess(mObjectID)); } // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerStoreFile::DoCommand(Protocol &, BackupStoreContext &) +// Name: BackupProtocolStoreFile::DoCommand(Protocol &, BackupStoreContext &) // Purpose: Command to store a file on the server // Created: 2003/09/02 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerStoreFile::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) +std::auto_ptr<BackupProtocolMessage> BackupProtocolStoreFile::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const { CHECK_PHASE(Phase_Commands) CHECK_WRITEABLE_SESSION - std::auto_ptr<ProtocolObject> hookResult = + std::auto_ptr<BackupProtocolMessage> hookResult = rContext.StartCommandHook(*this); if(hookResult.get()) { @@ -263,7 +263,7 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerStoreFile::DoCommand(BackupPro } // Tell the caller what the file was - return std::auto_ptr<ProtocolObject>(new BackupProtocolServerSuccess(id)); + return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(id)); } @@ -272,19 +272,19 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerStoreFile::DoCommand(BackupPro // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerGetObject::DoCommand(Protocol &, BackupStoreContext &) +// Name: BackupProtocolGetObject::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, BackupStoreContext &rContext) +std::auto_ptr<BackupProtocolMessage> BackupProtocolGetObject::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const { CHECK_PHASE(Phase_Commands) // Check the object exists if(!rContext.ObjectExists(mObjectID)) { - return std::auto_ptr<ProtocolObject>(new BackupProtocolServerSuccess(NoObject)); + return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(NoObject)); } // Open the object @@ -294,19 +294,19 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerGetObject::DoCommand(BackupPro rProtocol.SendStreamAfterCommand(object.release()); // Tell the caller what the file was - return std::auto_ptr<ProtocolObject>(new BackupProtocolServerSuccess(mObjectID)); + return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(mObjectID)); } // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerGetFile::DoCommand(Protocol &, BackupStoreContext &) +// Name: BackupProtocolGetFile::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, BackupStoreContext &rContext) +std::auto_ptr<BackupProtocolMessage> BackupProtocolGetFile::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const { CHECK_PHASE(Phase_Commands) @@ -460,19 +460,19 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerGetFile::DoCommand(BackupProto stream.release(); // Tell the caller what the file was - return std::auto_ptr<ProtocolObject>(new BackupProtocolServerSuccess(mObjectID)); + return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(mObjectID)); } // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerCreateDirectory::DoCommand(Protocol &, BackupStoreContext &) +// Name: BackupProtocolCreateDirectory::DoCommand(Protocol &, BackupStoreContext &) // Purpose: Create directory command // Created: 2003/09/04 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerCreateDirectory::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) +std::auto_ptr<BackupProtocolMessage> BackupProtocolCreateDirectory::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const { CHECK_PHASE(Phase_Commands) CHECK_WRITEABLE_SESSION @@ -500,7 +500,7 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerCreateDirectory::DoCommand(Bac } // Tell the caller what the file was - return std::auto_ptr<ProtocolObject>(new BackupProtocolServerSuccess(id)); + return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(id)); } @@ -508,12 +508,12 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerCreateDirectory::DoCommand(Bac // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerChangeDirAttributes::DoCommand(Protocol &, BackupStoreContext &) +// Name: BackupProtocolChangeDirAttributes::DoCommand(Protocol &, BackupStoreContext &) // Purpose: Change attributes on directory // Created: 2003/09/06 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerChangeDirAttributes::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) +std::auto_ptr<BackupProtocolMessage> BackupProtocolChangeDirAttributes::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const { CHECK_PHASE(Phase_Commands) CHECK_WRITEABLE_SESSION @@ -529,19 +529,19 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerChangeDirAttributes::DoCommand rContext.ChangeDirAttributes(mObjectID, attr, mAttributesModTime); // Tell the caller what the file was - return std::auto_ptr<ProtocolObject>(new BackupProtocolServerSuccess(mObjectID)); + return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(mObjectID)); } // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerSetReplacementFileAttributes::DoCommand(Protocol &, BackupStoreContext &) +// Name: BackupProtocolSetReplacementFileAttributes::DoCommand(Protocol &, BackupStoreContext &) // Purpose: Change attributes on directory // Created: 2003/09/06 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerSetReplacementFileAttributes::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) +std::auto_ptr<BackupProtocolMessage> BackupProtocolSetReplacementFileAttributes::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const { CHECK_PHASE(Phase_Commands) CHECK_WRITEABLE_SESSION @@ -562,7 +562,7 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerSetReplacementFileAttributes:: } // Tell the caller what the file was - return std::auto_ptr<ProtocolObject>(new BackupProtocolServerSuccess(objectID)); + return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(objectID)); } @@ -570,12 +570,12 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerSetReplacementFileAttributes:: // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerDeleteFile::DoCommand(BackupProtocolServer &, BackupStoreContext &) +// Name: BackupProtocolDeleteFile::DoCommand(BackupProtocolReplyable &, BackupStoreContext &) // Purpose: Delete a file // Created: 2003/10/21 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerDeleteFile::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) +std::auto_ptr<BackupProtocolMessage> BackupProtocolDeleteFile::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const { CHECK_PHASE(Phase_Commands) CHECK_WRITEABLE_SESSION @@ -585,21 +585,21 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerDeleteFile::DoCommand(BackupPr rContext.DeleteFile(mFilename, mInDirectory, objectID); // return the object ID or zero for not found - return std::auto_ptr<ProtocolObject>(new BackupProtocolServerSuccess(objectID)); + return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(objectID)); } // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerUndeleteFile::DoCommand( -// BackupProtocolServer &, BackupStoreContext &) +// Name: BackupProtocolUndeleteFile::DoCommand( +// BackupProtocolBase &, BackupStoreContext &) // Purpose: Undelete a file // Created: 2008-09-12 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerUndeleteFile::DoCommand( - BackupProtocolServer &rProtocol, BackupStoreContext &rContext) +std::auto_ptr<BackupProtocolMessage> BackupProtocolUndeleteFile::DoCommand( + BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const { CHECK_PHASE(Phase_Commands) CHECK_WRITEABLE_SESSION @@ -608,20 +608,20 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerUndeleteFile::DoCommand( bool result = rContext.UndeleteFile(mObjectID, mInDirectory); // return the object ID or zero for not found - return std::auto_ptr<ProtocolObject>( - new BackupProtocolServerSuccess(result ? mObjectID : 0)); + return std::auto_ptr<BackupProtocolMessage>( + new BackupProtocolSuccess(result ? mObjectID : 0)); } // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerDeleteDirectory::DoCommand(BackupProtocolServer &, BackupStoreContext &) +// Name: BackupProtocolDeleteDirectory::DoCommand(BackupProtocolReplyable &, BackupStoreContext &) // Purpose: Delete a directory // Created: 2003/10/21 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerDeleteDirectory::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) +std::auto_ptr<BackupProtocolMessage> BackupProtocolDeleteDirectory::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const { CHECK_PHASE(Phase_Commands) CHECK_WRITEABLE_SESSION @@ -648,19 +648,19 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerDeleteDirectory::DoCommand(Bac } // return the object ID - return std::auto_ptr<ProtocolObject>(new BackupProtocolServerSuccess(mObjectID)); + return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(mObjectID)); } // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerUndeleteDirectory::DoCommand(BackupProtocolServer &, BackupStoreContext &) +// Name: BackupProtocolUndeleteDirectory::DoCommand(BackupProtocolReplyable &, BackupStoreContext &) // Purpose: Undelete a directory // Created: 23/11/03 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerUndeleteDirectory::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) +std::auto_ptr<BackupProtocolMessage> BackupProtocolUndeleteDirectory::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const { CHECK_PHASE(Phase_Commands) CHECK_WRITEABLE_SESSION @@ -675,18 +675,18 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerUndeleteDirectory::DoCommand(B rContext.DeleteDirectory(mObjectID, true /* undelete */); // return the object ID - return std::auto_ptr<ProtocolObject>(new BackupProtocolServerSuccess(mObjectID)); + return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(mObjectID)); } // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerSetClientStoreMarker::DoCommand(BackupProtocolServer &, BackupStoreContext &) +// Name: BackupProtocolSetClientStoreMarker::DoCommand(BackupProtocolReplyable &, BackupStoreContext &) // Purpose: Command to set the client's store marker // Created: 2003/10/29 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerSetClientStoreMarker::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) +std::auto_ptr<BackupProtocolMessage> BackupProtocolSetClientStoreMarker::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const { CHECK_PHASE(Phase_Commands) CHECK_WRITEABLE_SESSION @@ -695,19 +695,19 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerSetClientStoreMarker::DoComman rContext.SetClientStoreMarker(mClientStoreMarker); // return store marker set - return std::auto_ptr<ProtocolObject>(new BackupProtocolServerSuccess(mClientStoreMarker)); + return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(mClientStoreMarker)); } // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerMoveObject::DoCommand(BackupProtocolServer &, BackupStoreContext &) +// Name: BackupProtocolMoveObject::DoCommand(BackupProtocolReplyable &, BackupStoreContext &) // Purpose: Command to move an object from one directory to another // Created: 2003/11/12 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerMoveObject::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) +std::auto_ptr<BackupProtocolMessage> BackupProtocolMoveObject::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const { CHECK_PHASE(Phase_Commands) CHECK_WRITEABLE_SESSION @@ -736,19 +736,19 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerMoveObject::DoCommand(BackupPr } // Return the object ID - return std::auto_ptr<ProtocolObject>(new BackupProtocolServerSuccess(mObjectID)); + return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(mObjectID)); } // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerGetObjectName::DoCommand(BackupProtocolServer &, BackupStoreContext &) +// Name: BackupProtocolGetObjectName::DoCommand(BackupProtocolReplyable &, BackupStoreContext &) // Purpose: Command to find the name of an object // Created: 12/11/03 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerGetObjectName::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) +std::auto_ptr<BackupProtocolMessage> BackupProtocolGetObjectName::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const { CHECK_PHASE(Phase_Commands) @@ -771,7 +771,7 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerGetObjectName::DoCommand(Backu // Check the directory really exists if(!rContext.ObjectExists(dirID, BackupStoreContext::ObjectExists_Directory)) { - return std::auto_ptr<ProtocolObject>(new BackupProtocolServerObjectName(BackupProtocolServerObjectName::NumNameElements_ObjectDoesntExist, 0, 0, 0)); + return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolObjectName(BackupProtocolObjectName::NumNameElements_ObjectDoesntExist, 0, 0, 0)); } // Load up the directory @@ -786,7 +786,7 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerGetObjectName::DoCommand(Backu if(en == 0) { // Abort! - return std::auto_ptr<ProtocolObject>(new BackupProtocolServerObjectName(BackupProtocolServerObjectName::NumNameElements_ObjectDoesntExist, 0, 0, 0)); + return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolObjectName(BackupProtocolObjectName::NumNameElements_ObjectDoesntExist, 0, 0, 0)); } // Store flags? @@ -826,7 +826,7 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerGetObjectName::DoCommand(Backu } // Make reply - return std::auto_ptr<ProtocolObject>(new BackupProtocolServerObjectName(numNameElements, modTime, attrModHash, objectFlags)); + return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolObjectName(numNameElements, modTime, attrModHash, objectFlags)); } @@ -834,12 +834,12 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerGetObjectName::DoCommand(Backu // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerGetBlockIndexByID::DoCommand(BackupProtocolServer &, BackupStoreContext &) +// Name: BackupProtocolGetBlockIndexByID::DoCommand(BackupProtocolReplyable &, BackupStoreContext &) // Purpose: Get the block index from a file, by ID // Created: 19/1/04 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerGetBlockIndexByID::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) +std::auto_ptr<BackupProtocolMessage> BackupProtocolGetBlockIndexByID::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const { CHECK_PHASE(Phase_Commands) @@ -853,19 +853,19 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerGetBlockIndexByID::DoCommand(B rProtocol.SendStreamAfterCommand(stream.release()); // Return the object ID - return std::auto_ptr<ProtocolObject>(new BackupProtocolServerSuccess(mObjectID)); + return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(mObjectID)); } // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerGetBlockIndexByName::DoCommand(BackupProtocolServer &, BackupStoreContext &) +// Name: BackupProtocolGetBlockIndexByName::DoCommand(BackupProtocolReplyable &, 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, BackupStoreContext &rContext) +std::auto_ptr<BackupProtocolMessage> BackupProtocolGetBlockIndexByName::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const { CHECK_PHASE(Phase_Commands) @@ -892,7 +892,7 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerGetBlockIndexByName::DoCommand if(objectID == 0) { // No... return a zero object ID - return std::auto_ptr<ProtocolObject>(new BackupProtocolServerSuccess(0)); + return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(0)); } // Open the file @@ -905,19 +905,19 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerGetBlockIndexByName::DoCommand rProtocol.SendStreamAfterCommand(stream.release()); // Return the object ID - return std::auto_ptr<ProtocolObject>(new BackupProtocolServerSuccess(objectID)); + return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(objectID)); } // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerGetAccountUsage::DoCommand(BackupProtocolServer &, BackupStoreContext &) +// Name: BackupProtocolGetAccountUsage::DoCommand(BackupProtocolReplyable &, BackupStoreContext &) // Purpose: Return the amount of disc space used // Created: 19/4/04 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerGetAccountUsage::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) +std::auto_ptr<BackupProtocolMessage> BackupProtocolGetAccountUsage::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const { CHECK_PHASE(Phase_Commands) @@ -929,7 +929,7 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerGetAccountUsage::DoCommand(Bac RaidFileDiscSet &rdiscSet(rcontroller.GetDiscSet(rinfo.GetDiscSetNumber())); // Return info - return std::auto_ptr<ProtocolObject>(new BackupProtocolServerAccountUsage( + return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolAccountUsage( rinfo.GetBlocksUsed(), rinfo.GetBlocksInOldFiles(), rinfo.GetBlocksInDeletedFiles(), @@ -943,17 +943,17 @@ std::auto_ptr<ProtocolObject> BackupProtocolServerGetAccountUsage::DoCommand(Bac // -------------------------------------------------------------------------- // // Function -// Name: BackupProtocolServerGetIsAlive::DoCommand(BackupProtocolServer &, BackupStoreContext &) +// Name: BackupProtocolGetIsAlive::DoCommand(BackupProtocolReplyable &, BackupStoreContext &) // Purpose: Return the amount of disc space used // Created: 19/4/04 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> BackupProtocolServerGetIsAlive::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext) +std::auto_ptr<BackupProtocolMessage> BackupProtocolGetIsAlive::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const { CHECK_PHASE(Phase_Commands) // // NOOP // - return std::auto_ptr<ProtocolObject>(new BackupProtocolServerIsAlive()); + return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolIsAlive()); } diff --git a/lib/backupstore/BackupStoreContext.cpp b/lib/backupstore/BackupStoreContext.cpp index a62655d3..e44fa29d 100644 --- a/lib/backupstore/BackupStoreContext.cpp +++ b/lib/backupstore/BackupStoreContext.cpp @@ -27,10 +27,9 @@ #include "RaidFileWrite.h" #include "StoreStructure.h" -class BackupStoreDaemon; - #include "MemLeakFindOn.h" + // Maximum number of directories to keep in the cache // When the cache is bigger than this, everything gets // deleted. diff --git a/lib/backupstore/BackupStoreContext.h b/lib/backupstore/BackupStoreContext.h index 44a05dd8..d46ac295 100644 --- a/lib/backupstore/BackupStoreContext.h +++ b/lib/backupstore/BackupStoreContext.h @@ -16,15 +16,14 @@ #include "BackupStoreRefCountDatabase.h" #include "NamedLock.h" -#include "ProtocolObject.h" +#include "Message.h" #include "Utils.h" class BackupStoreDirectory; class BackupStoreFilename; -class BackupStoreDaemon; class BackupStoreInfo; class IOStream; -class BackupProtocolObject; +class BackupProtocolMessage; class StreamableMemBlock; class HousekeepingInterface @@ -161,21 +160,22 @@ public: class TestHook { public: - virtual std::auto_ptr<ProtocolObject> StartCommand(BackupProtocolObject& - rCommand) = 0; + virtual std::auto_ptr<BackupProtocolMessage> + StartCommand(const BackupProtocolMessage& rCommand) = 0; virtual ~TestHook() { } }; void SetTestHook(TestHook& rTestHook) { mpTestHook = &rTestHook; } - std::auto_ptr<ProtocolObject> StartCommandHook(BackupProtocolObject& rCommand) + std::auto_ptr<BackupProtocolMessage> + StartCommandHook(const BackupProtocolMessage& rCommand) { if(mpTestHook) { return mpTestHook->StartCommand(rCommand); } - return std::auto_ptr<ProtocolObject>(); + return std::auto_ptr<BackupProtocolMessage>(); } private: diff --git a/lib/backupstore/BackupStoreFile.h b/lib/backupstore/BackupStoreFile.h index f5bc1924..b390320e 100644 --- a/lib/backupstore/BackupStoreFile.h +++ b/lib/backupstore/BackupStoreFile.h @@ -18,7 +18,6 @@ #include "BackupStoreFilename.h" #include "IOStream.h" #include "ReadLoggingStream.h" -#include "RunStatusProvider.h" typedef struct { @@ -27,6 +26,8 @@ typedef struct int64_t mTotalFileStreamSize; } BackupStoreFileStats; +class RunStatusProvider; + // Uncomment to disable backwards compatibility //#define BOX_DISABLE_BACKWARDS_COMPATIBILITY_BACKUPSTOREFILE diff --git a/lib/backupstore/Makefile.extra b/lib/backupstore/Makefile.extra index bc807fb6..c55fd549 100644 --- a/lib/backupstore/Makefile.extra +++ b/lib/backupstore/Makefile.extra @@ -1,16 +1,11 @@ - MAKEPROTOCOL = ../../lib/server/makeprotocol.pl -GEN_CMD_CLI = $(MAKEPROTOCOL) Client backupprotocol.txt -GEN_CMD_SRV = $(MAKEPROTOCOL) Server backupprotocol.txt +GEN_CMD = $(MAKEPROTOCOL) backupprotocol.txt # AUTOGEN SEEDING -autogen_BackupProtocolClient.cpp autogen_BackupProtocolClient.h: $(MAKEPROTOCOL) backupprotocol.txt - $(_PERL) $(GEN_CMD_CLI) +autogen_BackupProtocol.cpp autogen_BackupProtocol.h: $(MAKEPROTOCOL) backupprotocol.txt + $(_PERL) $(GEN_CMD) -# AUTOGEN SEEDING -autogen_BackupProtocolServer.cpp autogen_BackupProtocolServer.h: $(MAKEPROTOCOL) backupprotocol.txt - $(_PERL) $(GEN_CMD_SRV) MAKEEXCEPTION = ../../lib/common/makeexception.pl diff --git a/lib/backupstore/backupprotocol.txt b/lib/backupstore/backupprotocol.txt index 011458e8..9df62459 100644 --- a/lib/backupstore/backupprotocol.txt +++ b/lib/backupstore/backupprotocol.txt @@ -6,14 +6,13 @@ Name Backup IdentString Box-Backup:v=C ServerContextClass BackupStoreContext BackupStoreContext.h -ClientType Filename BackupStoreFilenameClear BackupStoreFilenameClear.h -ServerType Filename BackupStoreFilename BackupStoreFilename.h +AddType Filename BackupStoreFilenameClear BackupStoreFilenameClear.h ImplementLog Server syslog ImplementLog Client syslog ImplementLog Client file -LogTypeToText Client Filename \"%s\" VAR.GetClearFilename().c_str() +LogTypeToText Filename "%s" VAR.GetClearFilenameIfPossible("OPAQUE").c_str() BEGIN_OBJECTS diff --git a/lib/server/ProtocolObject.cpp b/lib/server/Message.cpp index fb09f820..2ff9e6ae 100644 --- a/lib/server/ProtocolObject.cpp +++ b/lib/server/Message.cpp @@ -1,14 +1,14 @@ // -------------------------------------------------------------------------- // // File -// Name: ProtocolObject.h +// Name: Message.h // Purpose: Protocol object base class // Created: 2003/08/19 // // -------------------------------------------------------------------------- #include "Box.h" -#include "ProtocolObject.h" +#include "Message.h" #include "CommonException.h" #include "MemLeakFindOn.h" @@ -16,48 +16,48 @@ // -------------------------------------------------------------------------- // // Function -// Name: ProtocolObject::ProtocolObject() +// Name: Message::Message() // Purpose: Default constructor // Created: 2003/08/19 // // -------------------------------------------------------------------------- -ProtocolObject::ProtocolObject() +Message::Message() { } // -------------------------------------------------------------------------- // // Function -// Name: ProtocolObject::ProtocolObject() +// Name: Message::Message() // Purpose: Destructor // Created: 2003/08/19 // // -------------------------------------------------------------------------- -ProtocolObject::~ProtocolObject() +Message::~Message() { } // -------------------------------------------------------------------------- // // Function -// Name: ProtocolObject::ProtocolObject() +// Name: Message::Message() // Purpose: Copy constructor // Created: 2003/08/19 // // -------------------------------------------------------------------------- -ProtocolObject::ProtocolObject(const ProtocolObject &rToCopy) +Message::Message(const Message &rToCopy) { } // -------------------------------------------------------------------------- // // Function -// Name: ProtocolObject::IsError(int &, int &) +// Name: Message::IsError(int &, int &) // Purpose: Does this represent an error, and if so, what is the type and subtype? // Created: 2003/08/19 // // -------------------------------------------------------------------------- -bool ProtocolObject::IsError(int &rTypeOut, int &rSubTypeOut) const +bool Message::IsError(int &rTypeOut, int &rSubTypeOut) const { return false; } @@ -65,12 +65,12 @@ bool ProtocolObject::IsError(int &rTypeOut, int &rSubTypeOut) const // -------------------------------------------------------------------------- // // Function -// Name: ProtocolObject::IsConversationEnd() +// Name: Message::IsConversationEnd() // Purpose: Does this command end the conversation? // Created: 2003/08/19 // // -------------------------------------------------------------------------- -bool ProtocolObject::IsConversationEnd() const +bool Message::IsConversationEnd() const { return false; } @@ -79,12 +79,12 @@ bool ProtocolObject::IsConversationEnd() const // -------------------------------------------------------------------------- // // Function -// Name: ProtocolObject::GetType() +// Name: Message::GetType() // Purpose: Return type of the object // Created: 2003/08/19 // // -------------------------------------------------------------------------- -int ProtocolObject::GetType() const +int Message::GetType() const { // This isn't implemented in the base class! THROW_EXCEPTION(CommonException, Internal) @@ -94,12 +94,12 @@ int ProtocolObject::GetType() const // -------------------------------------------------------------------------- // // Function -// Name: ProtocolObject::SetPropertiesFromStreamData(Protocol &) +// Name: Message::SetPropertiesFromStreamData(Protocol &) // Purpose: Set the properties of the object from the stream data ready in the Protocol object // Created: 2003/08/19 // // -------------------------------------------------------------------------- -void ProtocolObject::SetPropertiesFromStreamData(Protocol &rProtocol) +void Message::SetPropertiesFromStreamData(Protocol &rProtocol) { // This isn't implemented in the base class! THROW_EXCEPTION(CommonException, Internal) @@ -110,12 +110,12 @@ void ProtocolObject::SetPropertiesFromStreamData(Protocol &rProtocol) // -------------------------------------------------------------------------- // // Function -// Name: ProtocolObject::WritePropertiesToStreamData(Protocol &) +// Name: Message::WritePropertiesToStreamData(Protocol &) // Purpose: Write the properties of the object into the stream data in the Protocol object // Created: 2003/08/19 // // -------------------------------------------------------------------------- -void ProtocolObject::WritePropertiesToStreamData(Protocol &rProtocol) const +void Message::WritePropertiesToStreamData(Protocol &rProtocol) const { // This isn't implemented in the base class! THROW_EXCEPTION(CommonException, Internal) diff --git a/lib/server/ProtocolObject.h b/lib/server/Message.h index 0a127ab5..0d073d49 100644 --- a/lib/server/ProtocolObject.h +++ b/lib/server/Message.h @@ -1,7 +1,7 @@ // -------------------------------------------------------------------------- // // File -// Name: ProtocolObject.h +// Name: Message.h // Purpose: Protocol object base class // Created: 2003/08/19 // @@ -10,22 +10,25 @@ #ifndef PROTOCOLOBJECT__H #define PROTOCOLOBJECT__H +#include <memory> + class Protocol; +class ProtocolContext; // -------------------------------------------------------------------------- // // Class -// Name: ProtocolObject +// Name: Message // Purpose: Basic object representation of objects to pass through a Protocol session // Created: 2003/08/19 // // -------------------------------------------------------------------------- -class ProtocolObject +class Message { public: - ProtocolObject(); - virtual ~ProtocolObject(); - ProtocolObject(const ProtocolObject &rToCopy); + Message(); + virtual ~Message(); + Message(const Message &rToCopy); // Info about this object virtual int GetType() const; @@ -35,7 +38,32 @@ public: // reading and writing with Protocol objects virtual void SetPropertiesFromStreamData(Protocol &rProtocol); virtual void WritePropertiesToStreamData(Protocol &rProtocol) const; + + virtual void LogSysLog(const char *Action) const { } + virtual void LogFile(const char *Action, FILE *file) const { } +}; + +/* +class Reply; + +class Request : public Message +{ +public: + Request() { } + virtual ~Request() { } + Request(const Request &rToCopy) { } + virtual std::auto_ptr<Reply> DoCommand(Protocol &rProtocol, + ProtocolContext &rContext) = 0; +}; + +class Reply : public Message +{ +public: + Reply() { } + virtual ~Reply() { } + Reply(const Reply &rToCopy) { } }; +*/ #endif // PROTOCOLOBJECT__H diff --git a/lib/server/Protocol.cpp b/lib/server/Protocol.cpp index 5dc5d0b1..82836007 100644 --- a/lib/server/Protocol.cpp +++ b/lib/server/Protocol.cpp @@ -11,8 +11,9 @@ #include <sys/types.h> -#include <stdlib.h> -#include <string.h> +#include <cstdlib> +#include <cstring> +#include <cstdio> #include <new> @@ -44,17 +45,17 @@ // // -------------------------------------------------------------------------- Protocol::Protocol(IOStream &rStream) - : mrStream(rStream), - mHandshakeDone(false), - mMaxObjectSize(PROTOCOL_DEFAULT_MAXOBJSIZE), - mTimeout(PROTOCOL_DEFAULT_TIMEOUT), - mpBuffer(0), - mBufferSize(0), - mReadOffset(-1), - mWriteOffset(-1), - mValidDataSize(-1), - mLastErrorType(NoError), - mLastErrorSubType(NoError) +: mrStream(rStream), + mHandshakeDone(false), + mMaxObjectSize(PROTOCOL_DEFAULT_MAXOBJSIZE), + mTimeout(PROTOCOL_DEFAULT_TIMEOUT), + mpBuffer(0), + mBufferSize(0), + mReadOffset(-1), + mWriteOffset(-1), + mValidDataSize(-1), + mLogToSysLog(false), + mLogToFile(NULL) { BOX_TRACE("Send block allocation size is " << PROTOCOL_ALLOCATE_SEND_BLOCK_CHUNK); @@ -82,34 +83,6 @@ Protocol::~Protocol() // -------------------------------------------------------------------------- // // Function -// Name: Protocol::GetLastError(int &, int &) -// Purpose: Returns true if there was an error, and type and subtype if there was. -// Created: 2003/08/19 -// -// -------------------------------------------------------------------------- -bool Protocol::GetLastError(int &rTypeOut, int &rSubTypeOut) -{ - if(mLastErrorType == NoError) - { - // no error. - return false; - } - - // Return type and subtype in args - rTypeOut = mLastErrorType; - rSubTypeOut = mLastErrorSubType; - - // and unset them - mLastErrorType = NoError; - mLastErrorSubType = NoError; - - return true; -} - - -// -------------------------------------------------------------------------- -// -// Function // Name: Protocol::Handshake() // Purpose: Handshake with peer (exchange ident strings) // Created: 2003/08/20 @@ -127,7 +100,7 @@ void Protocol::Handshake() PW_Handshake hsSend; ::memset(&hsSend, 0, sizeof(hsSend)); // Copy in ident string - ::strncpy(hsSend.mIdent, GetIdentString(), sizeof(hsSend.mIdent)); + ::strncpy(hsSend.mIdent, GetProtocolIdentString(), sizeof(hsSend.mIdent)); // Send it mrStream.Write(&hsSend, sizeof(hsSend)); @@ -200,7 +173,7 @@ void Protocol::CheckAndReadHdr(void *hdr) // Created: 2003/08/19 // // -------------------------------------------------------------------------- -std::auto_ptr<ProtocolObject> Protocol::Receive() +std::auto_ptr<Message> Protocol::ReceiveInternal() { // Get object header PW_ObjectHeader objHeader; @@ -220,7 +193,7 @@ std::auto_ptr<ProtocolObject> Protocol::Receive() } // Create a blank object - std::auto_ptr<ProtocolObject> obj(MakeProtocolObject(ntohl(objHeader.mObjType))); + std::auto_ptr<Message> obj(MakeMessage(ntohl(objHeader.mObjType))); // Make sure memory is allocated to read it into EnsureBufferAllocated(objSize); @@ -272,7 +245,7 @@ std::auto_ptr<ProtocolObject> Protocol::Receive() // Created: 2003/08/19 // // -------------------------------------------------------------------------- -void Protocol::Send(const ProtocolObject &rObject) +void Protocol::SendInternal(const Message &rObject) { // Check usage if(mValidDataSize != -1 || mWriteOffset != -1 || mReadOffset != -1) @@ -854,7 +827,26 @@ int Protocol::SendStreamSendBlock(uint8_t *Block, int BytesInBlock) // -------------------------------------------------------------------------- void Protocol::InformStreamReceiving(u_int32_t Size) { - // Do nothing + if(GetLogToSysLog()) + { + if(Size == Protocol::ProtocolStream_SizeUncertain) + { + BOX_TRACE("Receiving stream, size uncertain"); + } + else + { + BOX_TRACE("Receiving stream, size " << Size); + } + } + + if(GetLogToFile()) + { + ::fprintf(GetLogToFile(), + (Size == Protocol::ProtocolStream_SizeUncertain) + ? "Receiving stream, size uncertain\n" + : "Receiving stream, size %d\n", Size); + ::fflush(GetLogToFile()); + } } // -------------------------------------------------------------------------- @@ -867,7 +859,26 @@ void Protocol::InformStreamReceiving(u_int32_t Size) // -------------------------------------------------------------------------- void Protocol::InformStreamSending(u_int32_t Size) { - // Do nothing + if(GetLogToSysLog()) + { + if(Size == Protocol::ProtocolStream_SizeUncertain) + { + BOX_TRACE("Sending stream, size uncertain"); + } + else + { + BOX_TRACE("Sending stream, size " << Size); + } + } + + if(GetLogToFile()) + { + ::fprintf(GetLogToFile(), + (Size == Protocol::ProtocolStream_SizeUncertain) + ? "Sending stream, size uncertain\n" + : "Sending stream, size %d\n", Size); + ::fflush(GetLogToFile()); + } } diff --git a/lib/server/Protocol.h b/lib/server/Protocol.h index e037e33c..42cb0ff8 100644 --- a/lib/server/Protocol.h +++ b/lib/server/Protocol.h @@ -12,12 +12,14 @@ #include <sys/types.h> -class IOStream; -#include "ProtocolObject.h" #include <memory> #include <vector> #include <string> +#include "Message.h" + +class IOStream; + // default timeout is 15 minutes #define PROTOCOL_DEFAULT_TIMEOUT (15*60*1000) // 16 default maximum object size -- should be enough @@ -40,11 +42,14 @@ public: private: Protocol(const Protocol &rToCopy); +protected: + // Unsafe to make public, as they may allow sending objects + // from a different protocol. The derived class prevents this. + std::auto_ptr<Message> ReceiveInternal(); + void SendInternal(const Message &rObject); + public: void Handshake(); - std::auto_ptr<ProtocolObject> Receive(); - void Send(const ProtocolObject &rObject); - std::auto_ptr<IOStream> ReceiveStream(); void SendStream(IOStream &rStream); @@ -54,8 +59,6 @@ public: UnknownError = 0 }; - bool GetLastError(int &rTypeOut, int &rSubTypeOut); - // -------------------------------------------------------------------------- // // Function @@ -87,7 +90,7 @@ public: // -------------------------------------------------------------------------- void SetMaxObjectSize(unsigned int NewMaxObjSize) {mMaxObjectSize = NewMaxObjSize;} - // For ProtocolObject derived classes + // For Message derived classes void Read(void *Buffer, int Size); void Read(std::string &rOut, int Size); void Read(int64_t &rOut); @@ -168,11 +171,15 @@ public: { ProtocolStream_SizeUncertain = 0xffffffff }; + bool GetLogToSysLog() { return mLogToSysLog; } + FILE *GetLogToFile() { return mLogToFile; } + void SetLogToSysLog(bool Log = false) {mLogToSysLog = Log;} + void SetLogToFile(FILE *File = 0) {mLogToFile = File;} -protected: - virtual std::auto_ptr<ProtocolObject> MakeProtocolObject(int ObjType) = 0; - virtual const char *GetIdentString() = 0; - void SetError(int Type, int SubType) {mLastErrorType = Type; mLastErrorSubType = SubType;} +protected: + virtual std::auto_ptr<Message> MakeMessage(int ObjType) = 0; + virtual const char *GetProtocolIdentString() = 0; + void CheckAndReadHdr(void *hdr); // don't use type here to avoid dependency // Will be used for logging @@ -183,7 +190,6 @@ private: void EnsureBufferAllocated(int Size); int SendStreamSendBlock(uint8_t *Block, int BytesInBlock); -private: IOStream &mrStream; bool mHandshakeDone; unsigned int mMaxObjectSize; @@ -193,8 +199,12 @@ private: int mReadOffset; int mWriteOffset; int mValidDataSize; - int mLastErrorType; - int mLastErrorSubType; + bool mLogToSysLog; + FILE *mLogToFile; +}; + +class ProtocolContext +{ }; #endif // PROTOCOL__H diff --git a/lib/server/makeprotocol.pl.in b/lib/server/makeprotocol.pl.in index 91ba55b0..da4b9447 100755 --- a/lib/server/makeprotocol.pl.in +++ b/lib/server/makeprotocol.pl.in @@ -30,24 +30,19 @@ my %log_display_types = 'string' => ['%s', 'VAR.c_str()'] ); - - -my ($type, $file) = @ARGV; - -if($type ne 'Server' && $type ne 'Client') +if (@ARGV != 1) { - die "Neither Server or Client is specified on command line\n"; + die "Usage: $0 <protocol-txt-file>\n"; } +my ($file) = @ARGV; + open IN, $file or die "Can't open input file $file\n"; -print "Making $type protocol classes from $file...\n"; +print "Making protocol classes from $file...\n"; my @extra_header_files; -my $implement_syslog = 0; -my $implement_filelog = 0; - # read attributes my %attr; while(<IN>) @@ -59,41 +54,18 @@ while(<IN>) my ($k,$v) = split /\s+/,$l,2; - if($k eq 'ClientType') - { - add_type($v) if $type eq 'Client'; - } - elsif($k eq 'ServerType') + if($k eq 'AddType') { - add_type($v) if $type eq 'Server'; + add_type($v); } elsif($k eq 'ImplementLog') { - my ($log_if_type,$log_type) = split /\s+/,$v; - if($type eq $log_if_type) - { - if($log_type eq 'syslog') - { - $implement_syslog = 1; - } - elsif($log_type eq 'file') - { - $implement_filelog = 1; - } - else - { - printf("ERROR: Unknown log type for implementation: $log_type\n"); - exit(1); - } - } + # Always implement logging } elsif($k eq 'LogTypeToText') { - my ($log_if_type,$type_name,$printf_format,$arg_template) = split /\s+/,$v; - if($type eq $log_if_type) - { - $log_display_types{$type_name} = [$printf_format,$arg_template] - } + my ($type_name,$printf_format,$arg_template) = split /\s+/,$v; + $log_display_types{$type_name} = [$printf_format,$arg_template] } else { @@ -169,10 +141,12 @@ close IN; # open files -my $h_filename = 'autogen_'.$protocol_name.'Protocol'.$type.'.h'; -open CPP,'>autogen_'.$protocol_name.'Protocol'.$type.'.cpp'; +my $h_filename = 'autogen_'.$protocol_name.'Protocol.h'; +open CPP,'>autogen_'.$protocol_name.'Protocol.cpp'; open H,">$h_filename"; +my $guardname = uc 'AUTOGEN_'.$protocol_name.'Protocol_H'; + print CPP <<__E; // Auto-generated file -- do not edit @@ -183,149 +157,125 @@ print CPP <<__E; #include "$h_filename" #include "IOStream.h" - __E -if($implement_syslog) -{ - print H <<EOF; -#ifndef WIN32 -#include <syslog.h> -#endif -EOF -} - - -my $guardname = uc 'AUTOGEN_'.$protocol_name.'Protocol'.$type.'_H'; print H <<__E; - // Auto-generated file -- do not edit #ifndef $guardname #define $guardname +#include <cstdio> +#include <list> + +#ifndef WIN32 +#include <syslog.h> +#endif + #include "Protocol.h" -#include "ProtocolObject.h" +#include "Message.h" #include "ServerException.h" class IOStream; -__E -if($implement_filelog) -{ - print H qq~#include <stdio.h>\n~; -} +__E # extra headers for(@extra_header_files) { - print H qq~#include "$_"\n~ + print H qq@#include "$_"\n@; } -print H "\n"; -if($type eq 'Server') -{ - # need utils file for the server - print H '#include "Utils.h"',"\n\n" -} +print H <<__E; + +// need utils file for the server +#include "Utils.h" +__E -my $derive_objects_from = 'ProtocolObject'; +my $message_base_class = "${protocol_name}ProtocolMessage"; my $objects_extra_h = ''; my $objects_extra_cpp = ''; -if($type eq 'Server') -{ - # define the context - print H "class $context_class;\n\n"; - print CPP "#include \"$context_class_inc\"\n\n"; - - # change class we derive the objects from - $derive_objects_from = $protocol_name.'ProtocolObject'; - - $objects_extra_h = <<__E; - virtual std::auto_ptr<ProtocolObject> DoCommand(${protocol_name}ProtocolServer &rProtocol, $context_class &rContext); -__E - $objects_extra_cpp = <<__E; -std::auto_ptr<ProtocolObject> ${derive_objects_from}::DoCommand(${protocol_name}ProtocolServer &rProtocol, $context_class &rContext) -{ - THROW_EXCEPTION(ConnectionException, Conn_Protocol_TriedToExecuteReplyCommand) -} + +# define the context +print H "class $context_class;\n\n"; +print CPP <<__E; +#include "$context_class_inc" +#include "MemLeakFindOn.h" __E -} -print CPP qq~#include "MemLeakFindOn.h"\n~; +my $request_base_class = "${protocol_name}ProtocolRequest"; +my $reply_base_class = "${protocol_name}ProtocolReply"; +# the abstract protocol interface +my $protocol_base_class = $protocol_name."ProtocolBase"; +my $replyable_base_class = $protocol_name."ProtocolReplyable"; -if($type eq 'Client' && ($implement_syslog || $implement_filelog)) -{ - # change class we derive the objects from - $derive_objects_from = $protocol_name.'ProtocolObjectCl'; -} -if($implement_syslog) -{ - $objects_extra_h .= <<__E; - virtual void LogSysLog(const char *Action) const = 0; -__E -} -if($implement_filelog) -{ - $objects_extra_h .= <<__E; - virtual void LogFile(const char *Action, FILE *file) const = 0; -__E -} +print H <<__E; +class $protocol_base_class; +class $replyable_base_class; +class $reply_base_class; -if($derive_objects_from ne 'ProtocolObject') -{ - # output a definition for the protocol object derived class - print H <<__E; -class ${protocol_name}ProtocolServer; - -class $derive_objects_from : public ProtocolObject +class $message_base_class : public Message { public: - $derive_objects_from(); - virtual ~$derive_objects_from(); - $derive_objects_from(const $derive_objects_from &rToCopy); - -$objects_extra_h + virtual std::auto_ptr<$message_base_class> DoCommand($replyable_base_class &rProtocol, + $context_class &rContext) const; }; -__E - # and some cpp definitions - print CPP <<__E; -${derive_objects_from}::${derive_objects_from}() +class $reply_base_class { -} -${derive_objects_from}::~${derive_objects_from}() +}; + +class $request_base_class { -} -${derive_objects_from}::${derive_objects_from}(const $derive_objects_from &rToCopy) +}; + +__E + +print CPP <<__E; +std::auto_ptr<$message_base_class> $message_base_class\::DoCommand($replyable_base_class &rProtocol, + $context_class &rContext) const { + THROW_EXCEPTION(ConnectionException, Conn_Protocol_TriedToExecuteReplyCommand) } -$objects_extra_cpp __E -} - - -my $classname_base = $protocol_name.'Protocol'.$type; +my %cmd_class; # output the classes -for my $cmd (@cmd_list) +foreach my $cmd (@cmd_list) { + my @cmd_base_classes = ($message_base_class); + + if(obj_is_type($cmd, 'Command')) + { + push @cmd_base_classes, $request_base_class; + } + + if(obj_is_type($cmd, 'Reply')) + { + push @cmd_base_classes, $reply_base_class; + } + + my $cmd_base_class = join(", ", map {"public $_"} @cmd_base_classes); + my $cmd_class = $protocol_name."ProtocolClient".$cmd; + $cmd_class{$cmd} = $cmd_class; + print H <<__E; -class $classname_base$cmd : public $derive_objects_from +class $cmd_class : $cmd_base_class { public: - $classname_base$cmd(); - $classname_base$cmd(const $classname_base$cmd &rToCopy); - ~$classname_base$cmd(); + $cmd_class(); + $cmd_class(const $cmd_class &rToCopy); + ~$cmd_class(); int GetType() const; enum { TypeID = $cmd_id{$cmd} }; __E + # constants if(exists $cmd_constants{$cmd}) { @@ -333,72 +283,63 @@ __E print H join(",\n\t\t",@{$cmd_constants{$cmd}}); print H "\n\t};\n"; } + # flags if(obj_is_type($cmd,'EndsConversation')) { print H "\tbool IsConversationEnd() const;\n"; } + if(obj_is_type($cmd,'IsError')) { print H "\tbool IsError(int &rTypeOut, int &rSubTypeOut) const;\n"; print H "\tstd::string GetMessage() const;\n"; } - if($type eq 'Server' && obj_is_type($cmd, 'Command')) + + if(obj_is_type($cmd, 'Command')) { - print H "\tstd::auto_ptr<ProtocolObject> DoCommand(${protocol_name}ProtocolServer &rProtocol, $context_class &rContext); // IMPLEMENT THIS\n" + print H <<__E; + std::auto_ptr<$message_base_class> DoCommand($replyable_base_class &rProtocol, + $context_class &rContext) const; // IMPLEMENT THIS\n +__E } # want to be able to read from streams? - my $read_from_streams = (obj_is_type($cmd,'Command') && $type eq 'Server') || (obj_is_type($cmd,'Reply') && $type eq 'Client'); - my $write_to_streams = (obj_is_type($cmd,'Command') && $type eq 'Client') || (obj_is_type($cmd,'Reply') && $type eq 'Server'); + print H "\tvoid SetPropertiesFromStreamData(Protocol &rProtocol);\n"; - if($read_from_streams) + # write Get functions + for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) { - print H "\tvoid SetPropertiesFromStreamData(Protocol &rProtocol);\n"; + my ($ty,$nm) = (${$cmd_contents{$cmd}}[$x], ${$cmd_contents{$cmd}}[$x+1]); - # write Get functions - for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) - { - my ($ty,$nm) = (${$cmd_contents{$cmd}}[$x], ${$cmd_contents{$cmd}}[$x+1]); - - print H "\t".translate_type_to_arg_type($ty)." Get$nm() {return m$nm;}\n"; - } + print H "\t".translate_type_to_arg_type($ty)." Get$nm() {return m$nm;}\n"; } + my $param_con_args = ''; - if($write_to_streams) + # extra constructor? + if($#{$cmd_contents{$cmd}} >= 0) { - # extra constructor? - if($#{$cmd_contents{$cmd}} >= 0) - { - my @a; - for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) - { - my ($ty,$nm) = (${$cmd_contents{$cmd}}[$x], ${$cmd_contents{$cmd}}[$x+1]); - - push @a,translate_type_to_arg_type($ty)." $nm"; - } - $param_con_args = join(', ',@a); - print H "\t$classname_base$cmd(".$param_con_args.");\n"; - } - print H "\tvoid WritePropertiesToStreamData(Protocol &rProtocol) const;\n"; - # set functions + my @a; for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) { my ($ty,$nm) = (${$cmd_contents{$cmd}}[$x], ${$cmd_contents{$cmd}}[$x+1]); - - print H "\tvoid Set$nm(".translate_type_to_arg_type($ty)." $nm) {m$nm = $nm;}\n"; - } - } - - if($implement_syslog) - { - print H "\tvirtual void LogSysLog(const char *Action) const;\n"; + + push @a,translate_type_to_arg_type($ty)." $nm"; + } + $param_con_args = join(', ',@a); + print H "\t$cmd_class(".$param_con_args.");\n"; } - if($implement_filelog) + print H "\tvoid WritePropertiesToStreamData(Protocol &rProtocol) const;\n"; + # set functions + for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) { - print H "\tvirtual void LogFile(const char *Action, FILE *file) const;\n"; + my ($ty,$nm) = (${$cmd_contents{$cmd}}[$x], ${$cmd_contents{$cmd}}[$x+1]); + + print H "\tvoid Set$nm(".translate_type_to_arg_type($ty)." $nm) {m$nm = $nm;}\n"; } - + + print H "\tvirtual void LogSysLog(const char *Action) const;\n"; + print H "\tvirtual void LogFile(const char *Action, FILE *file) const;\n"; # write member variables and setup for cpp file my @def_constructor_list; @@ -432,77 +373,73 @@ __E my $param_con_vars = join(",\n\t ",@param_constructor_list); $param_con_vars = "\n\t: ".$param_con_vars if $param_con_vars ne ''; - my $class = "$classname_base$cmd".'::'; print CPP <<__E; -$class$classname_base$cmd()$def_con_vars +$cmd_class\::$cmd_class()$def_con_vars { } -$class$classname_base$cmd(const $classname_base$cmd &rToCopy)$copy_con_vars +$cmd_class\::$cmd_class(const $cmd_class &rToCopy)$copy_con_vars { } -$class~$classname_base$cmd() +$cmd_class\::~$cmd_class() { } -int ${class}GetType() const +int $cmd_class\::GetType() const { return $cmd_id{$cmd}; } __E - if($read_from_streams) + print CPP "void $cmd_class\::SetPropertiesFromStreamData(Protocol &rProtocol)\n{\n"; + for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) { - print CPP "void ${class}SetPropertiesFromStreamData(Protocol &rProtocol)\n{\n"; - for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) + my ($ty,$nm) = (${$cmd_contents{$cmd}}[$x], ${$cmd_contents{$cmd}}[$x+1]); + if($ty =~ m/\Avector/) { - my ($ty,$nm) = (${$cmd_contents{$cmd}}[$x], ${$cmd_contents{$cmd}}[$x+1]); - if($ty =~ m/\Avector/) - { - print CPP "\trProtocol.ReadVector(m$nm);\n"; - } - else - { - print CPP "\trProtocol.Read(m$nm);\n"; - } + print CPP "\trProtocol.ReadVector(m$nm);\n"; + } + else + { + print CPP "\trProtocol.Read(m$nm);\n"; } - print CPP "}\n"; } - if($write_to_streams) + print CPP "}\n"; + + # implement extra constructor? + if($param_con_vars ne '') + { + print CPP "$cmd_class\::$cmd_class($param_con_args)$param_con_vars\n{\n}\n"; + } + print CPP "void $cmd_class\::WritePropertiesToStreamData(Protocol &rProtocol) const\n{\n"; + for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) { - # implement extra constructor? - if($param_con_vars ne '') + my ($ty,$nm) = (${$cmd_contents{$cmd}}[$x], ${$cmd_contents{$cmd}}[$x+1]); + if($ty =~ m/\Avector/) { - print CPP "$class$classname_base$cmd($param_con_args)$param_con_vars\n{\n}\n"; + print CPP "\trProtocol.WriteVector(m$nm);\n"; } - print CPP "void ${class}WritePropertiesToStreamData(Protocol &rProtocol) const\n{\n"; - for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) + else { - my ($ty,$nm) = (${$cmd_contents{$cmd}}[$x], ${$cmd_contents{$cmd}}[$x+1]); - if($ty =~ m/\Avector/) - { - print CPP "\trProtocol.WriteVector(m$nm);\n"; - } - else - { - print CPP "\trProtocol.Write(m$nm);\n"; - } + print CPP "\trProtocol.Write(m$nm);\n"; } - print CPP "}\n"; } + print CPP "}\n"; + if(obj_is_type($cmd,'EndsConversation')) { - print CPP "bool ${class}IsConversationEnd() const\n{\n\treturn true;\n}\n"; + print CPP "bool $cmd_class\::IsConversationEnd() const\n{\n\treturn true;\n}\n"; } + if(obj_is_type($cmd,'IsError')) { # get parameters my ($mem_type,$mem_subtype) = split /,/,obj_get_type_params($cmd,'IsError'); print CPP <<__E; -bool ${class}IsError(int &rTypeOut, int &rSubTypeOut) const +bool $cmd_class\::IsError(int &rTypeOut, int &rSubTypeOut) const { rTypeOut = m$mem_type; rSubTypeOut = m$mem_subtype; return true; } -std::string ${class}GetMessage() const +std::string $cmd_class\::GetMessage() const { switch(m$mem_subtype) { @@ -526,21 +463,13 @@ __E __E } - if($implement_syslog) - { - my ($log) = make_log_strings_framework($cmd); - print CPP <<__E; -void ${class}LogSysLog(const char *Action) const + my ($log) = make_log_strings_framework($cmd); + print CPP <<__E; +void $cmd_class\::LogSysLog(const char *Action) const { BOX_TRACE($log); } -__E - } - if($implement_filelog) - { - my ($log) = make_log_strings_framework($cmd); - print CPP <<__E; -void ${class}LogFile(const char *Action, FILE *File) const +void $cmd_class\::LogFile(const char *Action, FILE *File) const { std::ostringstream oss; oss << $log; @@ -548,208 +477,476 @@ void ${class}LogFile(const char *Action, FILE *File) const ::fflush(File); } __E - } } -# finally, the protocol object itself +my $error_class = $protocol_name."ProtocolError"; + +# the abstract protocol interface print H <<__E; -class $classname_base : public Protocol +class $protocol_base_class { public: - $classname_base(IOStream &rStream); - virtual ~$classname_base(); + $protocol_base_class(); + virtual ~$protocol_base_class(); + virtual const char *GetIdentString(); + bool GetLastError(int &rTypeOut, int &rSubTypeOut); + +protected: + void CheckReply(const std::string& requestCommand, + const $message_base_class &rReply, int expectedType); + void SetLastError(int Type, int SubType) + { + mLastErrorType = Type; + mLastErrorSubType = SubType; + } + +private: + $protocol_base_class(const $protocol_base_class &rToCopy); /* do not call */ + int mLastErrorType; + int mLastErrorSubType; +}; + +class $replyable_base_class : public virtual $protocol_base_class +{ +public: + $replyable_base_class(); + virtual ~$replyable_base_class(); + + /* + virtual std::auto_ptr<$message_base_class> Receive() = 0; + virtual void Send(const ${message_base_class} &rObject) = 0; + */ + + virtual std::auto_ptr<IOStream> ReceiveStream() = 0; + virtual int GetTimeout() = 0; + void SendStreamAfterCommand(IOStream *pStream); + +protected: + std::list<IOStream*> mStreamsToSend; + void DeleteStreamsToSend(); + +private: + $replyable_base_class(const $replyable_base_class &rToCopy); /* do not call */ +}; - std::auto_ptr<$derive_objects_from> Receive(); - void Send(const ${derive_objects_from} &rObject); __E -if($implement_syslog) + +print CPP <<__E; +$protocol_base_class\::$protocol_base_class() +: mLastErrorType(Protocol::NoError), + mLastErrorSubType(Protocol::NoError) +{ } + +$protocol_base_class\::~$protocol_base_class() +{ } + +const char *$protocol_base_class\::GetIdentString() { - print H "\tvoid SetLogToSysLog(bool Log = false) {mLogToSysLog = Log;}\n"; + return "$ident_string"; } -if($implement_filelog) + +$replyable_base_class\::$replyable_base_class() +{ } + +$replyable_base_class\::~$replyable_base_class() +{ } + +void $replyable_base_class\::SendStreamAfterCommand(IOStream *pStream) { - print H "\tvoid SetLogToFile(FILE *File = 0) {mLogToFile = File;}\n"; + ASSERT(pStream != NULL); + mStreamsToSend.push_back(pStream); } -if($type eq 'Server') + +void $replyable_base_class\::DeleteStreamsToSend() { - # need to put in the conversation function - print H "\tvoid DoServer($context_class &rContext);\n\n"; - # and the send vector thing - print H "\tvoid SendStreamAfterCommand(IOStream *pStream);\n\n"; + for(std::list<IOStream*>::iterator i(mStreamsToSend.begin()); i != mStreamsToSend.end(); ++i) + { + delete (*i); + } + mStreamsToSend.clear(); } -if($type eq 'Client') + +void $protocol_base_class\::CheckReply(const std::string& requestCommand, + const $message_base_class &rReply, int expectedType) { - # add plain object taking query functions - my $with_params; - for my $cmd (@cmd_list) + if(rReply.GetType() == expectedType) + { + // Correct response, do nothing + } + else { - if(obj_is_type($cmd,'Command')) + // Set protocol error + int type, subType; + + if(rReply.IsError(type, subType)) { - my $has_stream = obj_is_type($cmd,'StreamWithCommand'); - my $argextra = $has_stream?', IOStream &rStream':''; - my $queryextra = $has_stream?', rStream':''; - my $reply = obj_get_type_params($cmd,'Command'); - print H "\tstd::auto_ptr<$classname_base$reply> Query(const $classname_base$cmd &rQuery$argextra);\n"; - my @a; - my @na; - for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) - { - my ($ty,$nm) = (${$cmd_contents{$cmd}}[$x], ${$cmd_contents{$cmd}}[$x+1]); - push @a,translate_type_to_arg_type($ty)." $nm"; - push @na,"$nm"; - } - my $ar = join(', ',@a); - my $nar = join(', ',@na); - $nar = "($nar)" if $nar ne ''; - - $with_params .= "\tinline std::auto_ptr<$classname_base$reply> Query$cmd($ar$argextra)\n\t{\n"; - $with_params .= "\t\t$classname_base$cmd send$nar;\n"; - $with_params .= "\t\treturn Query(send$queryextra);\n"; - $with_params .= "\t}\n"; + SetLastError(type, subType); + BOX_WARNING(requestCommand << " command failed: " + "received error " << + (($error_class&)rReply).GetMessage()); + } + else + { + SetLastError(Protocol::UnknownError, Protocol::UnknownError); + BOX_WARNING(requestCommand << " command failed: " + "received unexpected response type " << + rReply.GetType()); } + + // Throw an exception + THROW_EXCEPTION(ConnectionException, Conn_Protocol_UnexpectedReply) } - # quick hack to correct bad argument lists for commands with zero paramters but with streams - $with_params =~ s/\(, /(/g; - print H "\n",$with_params,"\n"; } -print H <<__E; -private: - $classname_base(const $classname_base &rToCopy); -__E -if($type eq 'Server') + +// -------------------------------------------------------------------------- +// +// Function +// Name: Protocol::GetLastError(int &, int &) +// Purpose: Returns true if there was an error, and type and subtype if there was. +// Created: 2003/08/19 +// +// -------------------------------------------------------------------------- +bool $protocol_base_class\::GetLastError(int &rTypeOut, int &rSubTypeOut) { - # need to put the streams to send vector - print H "\tstd::vector<IOStream*> mStreamsToSend;\n\tvoid DeleteStreamsToSend();\n"; + if(mLastErrorType == Protocol::NoError) + { + // no error. + return false; + } + + // Return type and subtype in args + rTypeOut = mLastErrorType; + rSubTypeOut = mLastErrorSubType; + + // and unset them + mLastErrorType = Protocol::NoError; + mLastErrorSubType = Protocol::NoError; + + return true; } -if($implement_filelog || $implement_syslog) -{ - print H <<__E; - virtual void InformStreamReceiving(u_int32_t Size); - virtual void InformStreamSending(u_int32_t Size); __E -} -if($implement_syslog) +# the callable protocol interface (implemented by Client and Local classes) +# with Query methods that don't take a context parameter +my $callable_base_class = $protocol_name."ProtocolCallable"; +print H <<__E; +class $callable_base_class : public virtual $protocol_base_class { - print H "private:\n\tbool mLogToSysLog;\n"; -} -if($implement_filelog) +public: + virtual std::auto_ptr<IOStream> ReceiveStream() = 0; + virtual int GetTimeout() = 0; +__E + +# add plain object taking query functions +my $with_params; +for my $cmd (@cmd_list) { - print H "private:\n\tFILE *mLogToFile;\n"; + if(obj_is_type($cmd,'Command')) + { + my $has_stream = obj_is_type($cmd,'StreamWithCommand'); + my $argextra = $has_stream?', IOStream &rStream':''; + my $queryextra = $has_stream?', rStream':''; + my $request_class = $cmd_class{$cmd}; + my $reply_class = $cmd_class{obj_get_type_params($cmd,'Command')}; + + print H "\tvirtual std::auto_ptr<$reply_class> Query(const $request_class &rQuery$argextra) = 0;\n"; + my @a; + my @na; + for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) + { + my ($ty,$nm) = (${$cmd_contents{$cmd}}[$x], ${$cmd_contents{$cmd}}[$x+1]); + push @a,translate_type_to_arg_type($ty)." $nm"; + push @na,"$nm"; + } + my $ar = join(', ',@a); + my $nar = join(', ',@na); + $nar = "($nar)" if $nar ne ''; + + $with_params .= <<__E; + inline std::auto_ptr<$reply_class> Query$cmd($ar$argextra) + { + $request_class send$nar; + return Query(send$queryextra); + } +__E + } } + +# quick hack to correct bad argument lists for commands with zero parameters but with streams +$with_params =~ s/\(, /(/g; + print H <<__E; -protected: - virtual std::auto_ptr<ProtocolObject> MakeProtocolObject(int ObjType); - virtual const char *GetIdentString(); +$with_params }; - __E -my $constructor_extra = ''; -$constructor_extra .= ', mLogToSysLog(false)' if $implement_syslog; -$constructor_extra .= ', mLogToFile(0)' if $implement_filelog; +# standard remote protocol objects +foreach my $type ('Client', 'Server', 'Local') +{ + my $writing_client = ($type eq 'Client'); + my $writing_server = ($type eq 'Server'); + my $writing_local = ($type eq 'Local'); + + my $server_or_client_class = $protocol_name."Protocol".$type; + my @base_classes; -my $destructor_extra = ($type eq 'Server')?"\n\tDeleteStreamsToSend();":''; + if (not $writing_client) + { + push @base_classes, $replyable_base_class; + } + if (not $writing_server) + { + push @base_classes, $callable_base_class; + } + if (not $writing_local) + { + push @base_classes, "Protocol"; + } -my $prefix = $classname_base.'::'; -print CPP <<__E; -$prefix$classname_base(IOStream &rStream) - : Protocol(rStream)$constructor_extra + my $base_classes_str = join(", ", map {"public $_"} @base_classes); + + print H <<__E; +class $server_or_client_class : $base_classes_str { -} -$prefix~$classname_base() +public: +__E + + if($writing_local) + { + print H <<__E; + $server_or_client_class($context_class &rContext); +__E + } + else + { + print H <<__E; + $server_or_client_class(IOStream &rStream); + std::auto_ptr<$message_base_class> Receive(); + void Send(const $message_base_class &rObject); +__E + } + + print H <<__E; + virtual ~$server_or_client_class(); +__E + + if($writing_server) + { + # need to put in the conversation function + print H <<__E; + void DoServer($context_class &rContext); + +__E + } + + if($writing_client or $writing_local) + { + # add plain object taking query functions + for my $cmd (@cmd_list) + { + if(obj_is_type($cmd,'Command')) + { + my $has_stream = obj_is_type($cmd,'StreamWithCommand'); + my $argextra = $has_stream?', IOStream &rStream':''; + my $queryextra = $has_stream?', rStream':''; + my $request_class = $cmd_class{$cmd}; + my $reply_class = $cmd_class{obj_get_type_params($cmd,'Command')}; + print H "\tstd::auto_ptr<$reply_class> Query(const $request_class &rQuery$argextra);\n"; + } + } + } + + if($writing_local) + { + print H <<__E; +private: + $context_class &mrContext; +__E + } + + print H <<__E; + +protected: + virtual std::auto_ptr<Message> MakeMessage(int ObjType); + +__E + + if($writing_local) + { + print H <<__E; + virtual void InformStreamReceiving(u_int32_t Size) { } + virtual void InformStreamSending(u_int32_t Size) { } + +public: + virtual std::auto_ptr<IOStream> ReceiveStream() + { + std::auto_ptr<IOStream> apStream(mStreamsToSend.front()); + mStreamsToSend.pop_front(); + return apStream; + } +__E + } + else + { + print H <<__E; + virtual void InformStreamReceiving(u_int32_t Size) + { + this->Protocol::InformStreamReceiving(Size); + } + virtual void InformStreamSending(u_int32_t Size) + { + this->Protocol::InformStreamSending(Size); + } + +public: + virtual std::auto_ptr<IOStream> ReceiveStream() + { + return this->Protocol::ReceiveStream(); + } +__E + } + + print H <<__E; + virtual const char *GetProtocolIdentString() + { + return GetIdentString(); + } +__E + + if($writing_local) + { + print H <<__E; + virtual int GetTimeout() + { + return IOStream::TimeOutInfinite; + } +__E + } + else + { + print H <<__E; + virtual int GetTimeout() + { + return this->Protocol::GetTimeout(); + } +__E + } + + print H <<__E; + /* + virtual void Handshake() + { + this->Protocol::Handshake(); + } + virtual bool GetLastError(int &rTypeOut, int &rSubTypeOut) + { + return this->Protocol::GetLastError(rTypeOut, rSubTypeOut); + } + */ + +private: + $server_or_client_class(const $server_or_client_class &rToCopy); /* no copies */ +}; + +__E + + my $destructor_extra = ($writing_server) ? "\n\tDeleteStreamsToSend();" + : ''; + + if($writing_local) + { + print CPP <<__E; +$server_or_client_class\::$server_or_client_class($context_class &rContext) +: mrContext(rContext) +{ } +__E + } + else + { + print CPP <<__E; +$server_or_client_class\::$server_or_client_class(IOStream &rStream) +: Protocol(rStream) +{ } +__E + } + + print CPP <<__E; +$server_or_client_class\::~$server_or_client_class() {$destructor_extra } -const char *${prefix}GetIdentString() -{ - return "$ident_string"; -} -std::auto_ptr<ProtocolObject> ${prefix}MakeProtocolObject(int ObjType) +__E + + # write receive and send functions + print CPP <<__E; +std::auto_ptr<Message> $server_or_client_class\::MakeMessage(int ObjType) { switch(ObjType) { __E -# do objects within this -for my $cmd (@cmd_list) -{ - print CPP <<__E; + # do objects within this + for my $cmd (@cmd_list) + { + print CPP <<__E; case $cmd_id{$cmd}: - return std::auto_ptr<ProtocolObject>(new $classname_base$cmd); + return std::auto_ptr<Message>(new $cmd_class{$cmd}()); break; __E -} + } -print CPP <<__E; + print CPP <<__E; default: THROW_EXCEPTION(ConnectionException, Conn_Protocol_UnknownCommandRecieved) } } __E -# write receive and send functions -print CPP <<__E; -std::auto_ptr<$derive_objects_from> ${prefix}Receive() -{ - std::auto_ptr<${derive_objects_from}> preply((${derive_objects_from}*)(Protocol::Receive().release())); -__E - if($implement_syslog) + if(not $writing_local) { print CPP <<__E; - if(mLogToSysLog) +std::auto_ptr<$message_base_class> $server_or_client_class\::Receive() +{ + std::auto_ptr<$message_base_class> preply(($message_base_class *) + Protocol::ReceiveInternal().release()); + + if(GetLogToSysLog()) { preply->LogSysLog("Receive"); } -__E - } - if($implement_filelog) - { - print CPP <<__E; - if(mLogToFile != 0) + + if(GetLogToFile() != 0) { - preply->LogFile("Receive", mLogToFile); + preply->LogFile("Receive", GetLogToFile()); } -__E - } -print CPP <<__E; return preply; } -void ${prefix}Send(const ${derive_objects_from} &rObject) +void $server_or_client_class\::Send(const $message_base_class &rObject) { -__E - if($implement_syslog) - { - print CPP <<__E; - if(mLogToSysLog) + if(GetLogToSysLog()) { rObject.LogSysLog("Send"); } -__E - } - if($implement_filelog) - { - print CPP <<__E; - if(mLogToFile != 0) + + if(GetLogToFile() != 0) { - rObject.LogFile("Send", mLogToFile); - } -__E + rObject.LogFile("Send", GetLogToFile()); } -print CPP <<__E; - Protocol::Send(rObject); + Protocol::SendInternal(rObject); } __E -# write server function? -if($type eq 'Server') -{ - print CPP <<__E; -void ${prefix}DoServer($context_class &rContext) + } + + # write server function? + if($writing_server) + { + print CPP <<__E; +void $server_or_client_class\::DoServer($context_class &rContext) { // Handshake with client Handshake(); @@ -759,20 +956,22 @@ void ${prefix}DoServer($context_class &rContext) while(inProgress) { // Get an object from the conversation - std::auto_ptr<${derive_objects_from}> pobj(Receive()); + std::auto_ptr<$message_base_class> pobj = Receive(); // Run the command - std::auto_ptr<${derive_objects_from}> preply((${derive_objects_from}*)(pobj->DoCommand(*this, rContext).release())); + std::auto_ptr<$message_base_class> preply = pobj->DoCommand(*this, rContext); // Send the reply - Send(*(preply.get())); + Send(*preply); // Send any streams - for(unsigned int s = 0; s < mStreamsToSend.size(); s++) + for(std::list<IOStream*>::iterator + i = mStreamsToSend.begin(); + i != mStreamsToSend.end(); ++i) { - // Send the streams - SendStream(*mStreamsToSend[s]); + SendStream(**i); } + // Delete these streams DeleteStreamsToSend(); @@ -784,161 +983,82 @@ void ${prefix}DoServer($context_class &rContext) } } -void ${prefix}SendStreamAfterCommand(IOStream *pStream) -{ - ASSERT(pStream != NULL); - mStreamsToSend.push_back(pStream); -} - -void ${prefix}DeleteStreamsToSend() -{ - for(std::vector<IOStream*>::iterator i(mStreamsToSend.begin()); i != mStreamsToSend.end(); ++i) - { - delete (*i); - } - mStreamsToSend.clear(); -} - -__E -} - -# write logging functions? -if($implement_filelog || $implement_syslog) -{ - my ($fR,$fS); - - if($implement_syslog) - { - $fR .= <<__E; - if(mLogToSysLog) - { - if(Size==Protocol::ProtocolStream_SizeUncertain) - { - BOX_TRACE("Receiving stream, size uncertain"); - } - else - { - BOX_TRACE("Receiving stream, size " << Size); - } - } -__E - - $fS .= <<__E; - if(mLogToSysLog) - { - if(Size==Protocol::ProtocolStream_SizeUncertain) - { - BOX_TRACE("Sending stream, size uncertain"); - } - else - { - BOX_TRACE("Sending stream, size " << Size); - } - } -__E - } - - if($implement_filelog) - { - $fR .= <<__E; - if(mLogToFile) - { - ::fprintf(mLogToFile, - (Size==Protocol::ProtocolStream_SizeUncertain) - ?"Receiving stream, size uncertain\\n" - :"Receiving stream, size %d\\n", Size); - ::fflush(mLogToFile); - } -__E - $fS .= <<__E; - if(mLogToFile) - { - ::fprintf(mLogToFile, - (Size==Protocol::ProtocolStream_SizeUncertain) - ?"Sending stream, size uncertain\\n" - :"Sending stream, size %d\\n", Size); - ::fflush(mLogToFile); - } __E } - print CPP <<__E; - -void ${prefix}InformStreamReceiving(u_int32_t Size) -{ -$fR} - -void ${prefix}InformStreamSending(u_int32_t Size) -{ -$fS} - -__E -} - - -# write client Query functions? -if($type eq 'Client') -{ - for my $cmd (@cmd_list) + # write client Query functions? + if($writing_client or $writing_local) { - if(obj_is_type($cmd,'Command')) + for my $cmd (@cmd_list) { - my $reply = obj_get_type_params($cmd,'Command'); - my $reply_id = $cmd_id{$reply}; - my $has_stream = obj_is_type($cmd,'StreamWithCommand'); - my $argextra = $has_stream?', IOStream &rStream':''; - my $send_stream_extra = ''; - if($has_stream) + if(obj_is_type($cmd,'Command')) { - $send_stream_extra = <<__E; - + my $request_class = $cmd_class{$cmd}; + my $reply_msg = obj_get_type_params($cmd,'Command'); + my $reply_class = $cmd_class{$reply_msg}; + my $reply_id = $cmd_id{$reply_msg}; + my $has_stream = obj_is_type($cmd,'StreamWithCommand'); + my $argextra = $has_stream?', IOStream &rStream':''; + my $send_stream_extra = ''; + my $send_stream_method = $writing_client ? "SendStream" + : "SendStreamAfterCommand"; + + if($writing_client) + { + if($has_stream) + { + $send_stream_extra = <<__E; // Send stream after the command SendStream(rStream); __E - } - print CPP <<__E; -std::auto_ptr<$classname_base$reply> ${classname_base}::Query(const $classname_base$cmd &rQuery$argextra) + } + + print CPP <<__E; +std::auto_ptr<$reply_class> $server_or_client_class\::Query(const $request_class &rQuery$argextra) { // Send query Send(rQuery); $send_stream_extra + // Wait for the reply - std::auto_ptr<${derive_objects_from}> preply(Receive().release()); + std::auto_ptr<$message_base_class> preply = Receive(); + + CheckReply("$cmd", *preply, $reply_id); - if(preply->GetType() == $reply_id) - { - // Correct response - return std::auto_ptr<$classname_base$reply>(($classname_base$reply*)preply.release()); - } - else - { - // Set protocol error - int type, subType; - if(preply->IsError(type, subType)) - { - SetError(type, subType); - BOX_WARNING("$cmd command failed: received error " << - ((${classname_base}Error&)*preply).GetMessage()); - } - else - { - SetError(Protocol::UnknownError, Protocol::UnknownError); - BOX_WARNING("$cmd command failed: received " - "unexpected response type " << - preply->GetType()); - } - - // Throw an exception - THROW_EXCEPTION(ConnectionException, Conn_Protocol_UnexpectedReply) - } + // Correct response, if no exception thrown by CheckReply + return std::auto_ptr<$reply_class>(($reply_class *)preply.release()); +} +__E + } + elsif($writing_local) + { + if($has_stream) + { + $send_stream_extra = <<__E; + // Send stream after the command + SendStreamAfterCommand(&rStream); +__E + } + + print CPP <<__E; +std::auto_ptr<$reply_class> $server_or_client_class\::Query(const $request_class &rQuery$argextra) +{ + // Send query + $send_stream_extra + std::auto_ptr<$message_base_class> preply = rQuery.DoCommand(*this, mrContext); + + CheckReply("$cmd", *preply, $reply_id); + + // Correct response, if no exception thrown by CheckReply + return std::auto_ptr<$reply_class>(($reply_class *)preply.release()); } __E + } + } } } } - - print H <<__E; #endif // $guardname @@ -948,8 +1068,7 @@ __E close H; close CPP; - -sub obj_is_type +sub obj_is_type ($$) { my ($c,$ty) = @_; for(@{$cmd_attributes{$c}}) @@ -1003,40 +1122,6 @@ sub translate_type_to_member_type return $typename } -sub make_log_strings -{ - my ($cmd) = @_; - - my @str; - my @arg; - for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) - { - my ($ty,$nm) = (${$cmd_contents{$cmd}}[$x], ${$cmd_contents{$cmd}}[$x+1]); - - if(exists $log_display_types{$ty}) - { - # need to translate it - my ($format,$arg) = @{$log_display_types{$ty}}; - $arg =~ s/VAR/m$nm/g; - - if ($format eq "0x%llx" and $target_windows) - { - $format = "0x%I64x"; - $arg = "(uint64_t)$arg"; - } - - push @str,$format; - push @arg,$arg; - } - else - { - # is opaque - push @str,'OPAQUE'; - } - } - return ($cmd.'('.join(',',@str).')', join(',','',@arg)); -} - sub make_log_strings_framework { my ($cmd) = @_; @@ -1053,7 +1138,7 @@ sub make_log_strings_framework my ($format,$arg) = @{$log_display_types{$ty}}; $arg =~ s/VAR/m$nm/g; - if ($format eq '\\"%s\\"') + if ($format eq '"%s"') { $arg = "\"\\\"\" << $arg << \"\\\"\""; } @@ -1090,4 +1175,3 @@ sub make_log_strings_framework return $log_cmd; } - diff --git a/test/backupstore/testbackupstore.cpp b/test/backupstore/testbackupstore.cpp index c98b37b4..65d068e9 100644 --- a/test/backupstore/testbackupstore.cpp +++ b/test/backupstore/testbackupstore.cpp @@ -13,7 +13,7 @@ #include <string.h> #include "Test.h" -#include "autogen_BackupProtocolClient.h" +#include "autogen_BackupProtocol.h" #include "SSLLib.h" #include "TLSContext.h" #include "SocketStreamTLS.h" @@ -440,10 +440,10 @@ void test_everything_deleted(BackupProtocolClient &protocol, int64_t DirID) printf("Test for del: %llx\n", DirID); // Command - std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocol.QueryListDirectory( + std::auto_ptr<BackupProtocolSuccess> dirreply(protocol.QueryListDirectory( DirID, - BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING, - BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); + BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING, + BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); // Stream BackupStoreDirectory dir; std::auto_ptr<IOStream> dirstream(protocol.ReceiveStream()); @@ -455,7 +455,7 @@ void test_everything_deleted(BackupProtocolClient &protocol, int64_t DirID) int dirs = 0; while((en = i.Next()) != 0) { - if(en->GetFlags() & BackupProtocolClientListDirectory::Flags_Dir) + if(en->GetFlags() & BackupProtocolListDirectory::Flags_Dir) { dirs++; // Recurse @@ -466,7 +466,7 @@ void test_everything_deleted(BackupProtocolClient &protocol, int64_t DirID) files++; } // Check it's deleted - TEST_THAT(en->GetFlags() & BackupProtocolClientListDirectory::Flags_Deleted); + TEST_THAT(en->GetFlags() & BackupProtocolListDirectory::Flags_Deleted); } // Check there were the right number of files and directories @@ -491,7 +491,7 @@ void create_file_in_dir(std::string name, std::string source, int64_t parentId, BackupStoreFilenameClear name_encoded("file_One"); std::auto_ptr<IOStream> upload(BackupStoreFile::EncodeFile( source.c_str(), parentId, name_encoded)); - std::auto_ptr<BackupProtocolClientSuccess> stored( + std::auto_ptr<BackupProtocolSuccess> stored( protocol.QueryStoreFile( parentId, 0x123456789abcdefLL, /* modification time */ @@ -515,7 +515,7 @@ int64_t create_test_data_subdirs(BackupProtocolClient &protocol, int64_t indir, // Create with dummy attributes int attrS = 0; MemBlockStream attr(&attrS, sizeof(attrS)); - std::auto_ptr<BackupProtocolClientSuccess> dirCreate(protocol.QueryCreateDirectory( + std::auto_ptr<BackupProtocolSuccess> dirCreate(protocol.QueryCreateDirectory( indir, 9837429842987984LL, dirname, attr)); subdirid = dirCreate->GetObjectID(); @@ -550,11 +550,11 @@ int64_t create_test_data_subdirs(BackupProtocolClient &protocol, int64_t indir, void check_dir_after_uploads(BackupProtocolClient &protocol, const StreamableMemBlock &Attributes) { // Command - std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocol.QueryListDirectory( - BackupProtocolClientListDirectory::RootDirectory, - BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING, - BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); - TEST_THAT(dirreply->GetObjectID() == BackupProtocolClientListDirectory::RootDirectory); + std::auto_ptr<BackupProtocolSuccess> dirreply(protocol.QueryListDirectory( + BackupProtocolListDirectory::RootDirectory, + BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING, + BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); + TEST_THAT(dirreply->GetObjectID() == BackupProtocolListDirectory::RootDirectory); // Stream BackupStoreDirectory dir; std::auto_ptr<IOStream> dirstream(protocol.ReceiveStream()); @@ -575,9 +575,9 @@ void check_dir_after_uploads(BackupProtocolClient &protocol, const StreamableMem TEST_THAT(en->GetName() == uploads[t].name); TEST_THAT(en->GetObjectID() == uploads[t].allocated_objid); TEST_THAT(en->GetModificationTime() == uploads[t].mod_time); - int correct_flags = BackupProtocolClientListDirectory::Flags_File; - if(uploads[t].should_be_old_version) correct_flags |= BackupProtocolClientListDirectory::Flags_OldVersion; - if(uploads[t].delete_file) correct_flags |= BackupProtocolClientListDirectory::Flags_Deleted; + int correct_flags = BackupProtocolListDirectory::Flags_File; + if(uploads[t].should_be_old_version) correct_flags |= BackupProtocolListDirectory::Flags_OldVersion; + if(uploads[t].delete_file) correct_flags |= BackupProtocolListDirectory::Flags_Deleted; TEST_THAT(en->GetFlags() == correct_flags); if(t == UPLOAD_ATTRS_EN) { @@ -606,10 +606,10 @@ typedef struct void recursive_count_objects_r(BackupProtocolClient &protocol, int64_t id, recursive_count_objects_results &results) { // Command - std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocol.QueryListDirectory( + std::auto_ptr<BackupProtocolSuccess> dirreply(protocol.QueryListDirectory( id, - BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING, - BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); + BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING, + BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); // Stream BackupStoreDirectory dir; std::auto_ptr<IOStream> dirstream(protocol.ReceiveStream()); @@ -649,9 +649,9 @@ void recursive_count_objects(const char *hostname, int64_t id, recursive_count_o BackupProtocolClient protocolReadOnly(connReadOnly); { - std::auto_ptr<BackupProtocolClientVersion> serverVersion(protocolReadOnly.QueryVersion(BACKUP_STORE_SERVER_VERSION)); + std::auto_ptr<BackupProtocolVersion> serverVersion(protocolReadOnly.QueryVersion(BACKUP_STORE_SERVER_VERSION)); TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION); - std::auto_ptr<BackupProtocolClientLoginConfirmed> loginConf(protocolReadOnly.QueryLogin(0x01234567, BackupProtocolClientLogin::Flags_ReadOnly)); + std::auto_ptr<BackupProtocolLoginConfirmed> loginConf(protocolReadOnly.QueryLogin(0x01234567, BackupProtocolLogin::Flags_ReadOnly)); } // Count objects @@ -758,10 +758,10 @@ void test_server_1(BackupProtocolClient &protocol, BackupProtocolClient &protoco for(int l = 0; l < 3; ++l) { // Command - std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocol.QueryListDirectory( - BackupProtocolClientListDirectory::RootDirectory, - BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING, - BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); + std::auto_ptr<BackupProtocolSuccess> dirreply(protocol.QueryListDirectory( + BackupProtocolListDirectory::RootDirectory, + BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING, + BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); // Stream BackupStoreDirectory dir; std::auto_ptr<IOStream> dirstream(protocol.ReceiveStream()); @@ -772,10 +772,10 @@ void test_server_1(BackupProtocolClient &protocol, BackupProtocolClient &protoco // Read the dir from the readonly connection (make sure it gets in the cache) { // Command - std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocolReadOnly.QueryListDirectory( - BackupProtocolClientListDirectory::RootDirectory, - BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING, - BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); + std::auto_ptr<BackupProtocolSuccess> dirreply(protocolReadOnly.QueryListDirectory( + BackupProtocolListDirectory::RootDirectory, + BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING, + BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); // Stream BackupStoreDirectory dir; std::auto_ptr<IOStream> dirstream(protocolReadOnly.ReceiveStream()); @@ -787,7 +787,7 @@ void test_server_1(BackupProtocolClient &protocol, BackupProtocolClient &protoco BackupStoreFilenameClear store1name("testfiles/file1"); { FileStream out("testfiles/file1_upload1", O_WRONLY | O_CREAT | O_EXCL); - std::auto_ptr<IOStream> encoded(BackupStoreFile::EncodeFile("testfiles/file1", BackupProtocolClientListDirectory::RootDirectory, store1name)); + std::auto_ptr<IOStream> encoded(BackupStoreFile::EncodeFile("testfiles/file1", BackupProtocolListDirectory::RootDirectory, store1name)); encoded->CopyStreamTo(out); } @@ -797,8 +797,8 @@ void test_server_1(BackupProtocolClient &protocol, BackupProtocolClient &protoco int64_t store1objid = 0; { FileStream upload("testfiles/file1_upload1"); - std::auto_ptr<BackupProtocolClientSuccess> stored(protocol.QueryStoreFile( - BackupProtocolClientListDirectory::RootDirectory, + std::auto_ptr<BackupProtocolSuccess> stored(protocol.QueryStoreFile( + BackupProtocolListDirectory::RootDirectory, 0x123456789abcdefLL, /* modification time */ 0x7362383249872dfLL, /* attr hash */ 0, /* diff from ID */ @@ -811,7 +811,7 @@ void test_server_1(BackupProtocolClient &protocol, BackupProtocolClient &protoco // And retrieve it { // Retrieve as object - std::auto_ptr<BackupProtocolClientSuccess> getfile(protocol.QueryGetObject(store1objid)); + std::auto_ptr<BackupProtocolSuccess> getfile(protocol.QueryGetObject(store1objid)); TEST_THAT(getfile->GetObjectID() == store1objid); // BLOCK { @@ -826,7 +826,7 @@ void test_server_1(BackupProtocolClient &protocol, BackupProtocolClient &protoco } // Retrieve as file - std::auto_ptr<BackupProtocolClientSuccess> getobj(protocol.QueryGetFile(BackupProtocolClientListDirectory::RootDirectory, store1objid)); + std::auto_ptr<BackupProtocolSuccess> getobj(protocol.QueryGetFile(BackupProtocolListDirectory::RootDirectory, store1objid)); TEST_THAT(getobj->GetObjectID() == store1objid); // BLOCK { @@ -852,7 +852,7 @@ void test_server_1(BackupProtocolClient &protocol, BackupProtocolClient &protoco // Retrieve the block index, by ID { - std::auto_ptr<BackupProtocolClientSuccess> getblockindex(protocol.QueryGetBlockIndexByID(store1objid)); + std::auto_ptr<BackupProtocolSuccess> getblockindex(protocol.QueryGetBlockIndexByID(store1objid)); TEST_THAT(getblockindex->GetObjectID() == store1objid); std::auto_ptr<IOStream> blockIndexStream(protocol.ReceiveStream()); // Check against uploaded file @@ -860,7 +860,7 @@ void test_server_1(BackupProtocolClient &protocol, BackupProtocolClient &protoco } // and again, by name { - std::auto_ptr<BackupProtocolClientSuccess> getblockindex(protocol.QueryGetBlockIndexByName(BackupProtocolClientListDirectory::RootDirectory, store1name)); + std::auto_ptr<BackupProtocolSuccess> getblockindex(protocol.QueryGetBlockIndexByName(BackupProtocolListDirectory::RootDirectory, store1name)); TEST_THAT(getblockindex->GetObjectID() == store1objid); std::auto_ptr<IOStream> blockIndexStream(protocol.ReceiveStream()); // Check against uploaded file @@ -870,10 +870,10 @@ void test_server_1(BackupProtocolClient &protocol, BackupProtocolClient &protoco // Get the directory again, and see if the entry is in it { // Command - std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocol.QueryListDirectory( - BackupProtocolClientListDirectory::RootDirectory, - BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING, - BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); + std::auto_ptr<BackupProtocolSuccess> dirreply(protocol.QueryListDirectory( + BackupProtocolListDirectory::RootDirectory, + BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING, + BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); // Stream BackupStoreDirectory dir; std::auto_ptr<IOStream> dirstream(protocol.ReceiveStream()); @@ -896,7 +896,7 @@ void test_server_1(BackupProtocolClient &protocol, BackupProtocolClient &protoco // Try using GetFile on a directory { - TEST_CHECK_THROWS(std::auto_ptr<BackupProtocolClientSuccess> getFile(protocol.QueryGetFile(BackupProtocolClientListDirectory::RootDirectory, BackupProtocolClientListDirectory::RootDirectory)), + TEST_CHECK_THROWS(std::auto_ptr<BackupProtocolSuccess> getFile(protocol.QueryGetFile(BackupProtocolListDirectory::RootDirectory, BackupProtocolListDirectory::RootDirectory)), ConnectionException, Conn_Protocol_UnexpectedReply); } } @@ -929,12 +929,12 @@ std::auto_ptr<BackupProtocolClient> test_server_login(const char *hostname, BackupProtocolClient(*rapConn)); // Check the version - std::auto_ptr<BackupProtocolClientVersion> serverVersion( + std::auto_ptr<BackupProtocolVersion> serverVersion( protocol->QueryVersion(BACKUP_STORE_SERVER_VERSION)); TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION); // Login - std::auto_ptr<BackupProtocolClientLoginConfirmed> loginConf( + std::auto_ptr<BackupProtocolLoginConfirmed> loginConf( protocol->QueryLogin(0x01234567, 0)); return protocol; @@ -1009,9 +1009,9 @@ int test_server(const char *hostname) conn.Open(context, Socket::TypeINET, hostname, BOX_PORT_BBSTORED_TEST); BackupProtocolClient protocol(conn); - std::auto_ptr<BackupProtocolClientVersion> serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION)); + std::auto_ptr<BackupProtocolVersion> serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION)); TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION); - TEST_CHECK_THROWS(std::auto_ptr<BackupProtocolClientLoginConfirmed> loginConf(protocol.QueryLogin(0x01234567, 0)), + TEST_CHECK_THROWS(std::auto_ptr<BackupProtocolLoginConfirmed> loginConf(protocol.QueryLogin(0x01234567, 0)), ConnectionException, Conn_Protocol_UnexpectedReply); protocol.QueryFinished(); } @@ -1033,9 +1033,9 @@ int test_server(const char *hostname) protocolReadOnly.SetLogToFile(protocolReadOnlyLog); { - std::auto_ptr<BackupProtocolClientVersion> serverVersion(protocolReadOnly.QueryVersion(BACKUP_STORE_SERVER_VERSION)); + std::auto_ptr<BackupProtocolVersion> serverVersion(protocolReadOnly.QueryVersion(BACKUP_STORE_SERVER_VERSION)); TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION); - std::auto_ptr<BackupProtocolClientLoginConfirmed> loginConf(protocolReadOnly.QueryLogin(0x01234567, BackupProtocolClientLogin::Flags_ReadOnly)); + std::auto_ptr<BackupProtocolLoginConfirmed> loginConf(protocolReadOnly.QueryLogin(0x01234567, BackupProtocolLogin::Flags_ReadOnly)); // Check client store marker TEST_THAT(loginConf->GetClientStoreMarker() == 0x8732523ab23aLL); @@ -1079,11 +1079,11 @@ int test_server(const char *hostname) filename += uploads[t].fnextra; int64_t modtime = 0; - std::auto_ptr<IOStream> upload(BackupStoreFile::EncodeFile(filename.c_str(), BackupProtocolClientListDirectory::RootDirectory, uploads[t].name, &modtime)); + std::auto_ptr<IOStream> upload(BackupStoreFile::EncodeFile(filename.c_str(), BackupProtocolListDirectory::RootDirectory, uploads[t].name, &modtime)); TEST_THAT(modtime != 0); - std::auto_ptr<BackupProtocolClientSuccess> stored(apProtocol->QueryStoreFile( - BackupProtocolClientListDirectory::RootDirectory, + std::auto_ptr<BackupProtocolSuccess> stored(apProtocol->QueryStoreFile( + BackupProtocolListDirectory::RootDirectory, modtime, modtime, /* use it for attr hash too */ 0, /* diff from ID */ @@ -1107,8 +1107,8 @@ int test_server(const char *hostname) { TEST_NUM_FILES(UPLOAD_NUM + 1, 0, 0, 1); MemBlockStream attrnew(attr3, sizeof(attr3)); - std::auto_ptr<BackupProtocolClientSuccess> set(apProtocol->QuerySetReplacementFileAttributes( - BackupProtocolClientListDirectory::RootDirectory, + std::auto_ptr<BackupProtocolSuccess> set(apProtocol->QuerySetReplacementFileAttributes( + BackupProtocolListDirectory::RootDirectory, 32498749832475LL, uploads[UPLOAD_ATTRS_EN].name, attrnew)); @@ -1118,8 +1118,8 @@ int test_server(const char *hostname) // Delete one of them (will implicitly delete an old version) { - std::auto_ptr<BackupProtocolClientSuccess> del(apProtocol->QueryDeleteFile( - BackupProtocolClientListDirectory::RootDirectory, + std::auto_ptr<BackupProtocolSuccess> del(apProtocol->QueryDeleteFile( + BackupProtocolListDirectory::RootDirectory, uploads[UPLOAD_DELETE_EN].name)); TEST_THAT(del->GetObjectID() == uploads[UPLOAD_DELETE_EN].allocated_objid); TEST_NUM_FILES(UPLOAD_NUM, 0, 1, 1); @@ -1130,13 +1130,13 @@ int test_server(const char *hostname) // Fetch the raw object { FileStream out("testfiles/downloaddelobj", O_WRONLY | O_CREAT); - std::auto_ptr<BackupProtocolClientSuccess> getobj(apProtocol->QueryGetObject(uploads[UPLOAD_DELETE_EN].allocated_objid)); + std::auto_ptr<BackupProtocolSuccess> getobj(apProtocol->QueryGetObject(uploads[UPLOAD_DELETE_EN].allocated_objid)); std::auto_ptr<IOStream> objstream(apProtocol->ReceiveStream()); objstream->CopyStreamTo(out); } // query index and test - std::auto_ptr<BackupProtocolClientSuccess> getblockindex(apProtocol->QueryGetBlockIndexByName( - BackupProtocolClientListDirectory::RootDirectory, uploads[UPLOAD_DELETE_EN].name)); + std::auto_ptr<BackupProtocolSuccess> getblockindex(apProtocol->QueryGetBlockIndexByName( + BackupProtocolListDirectory::RootDirectory, uploads[UPLOAD_DELETE_EN].name)); TEST_THAT(getblockindex->GetObjectID() == uploads[UPLOAD_DELETE_EN].allocated_objid); std::auto_ptr<IOStream> blockIndexStream(apProtocol->ReceiveStream()); TEST_THAT(check_block_index("testfiles/downloaddelobj", *blockIndexStream)); @@ -1146,7 +1146,7 @@ int test_server(const char *hostname) for(int t = 0; t < UPLOAD_NUM; ++t) { printf("%d\n", t); - std::auto_ptr<BackupProtocolClientSuccess> getFile(apProtocol->QueryGetFile(BackupProtocolClientListDirectory::RootDirectory, uploads[t].allocated_objid)); + std::auto_ptr<BackupProtocolSuccess> getFile(apProtocol->QueryGetFile(BackupProtocolListDirectory::RootDirectory, uploads[t].allocated_objid)); TEST_THAT(getFile->GetObjectID() == uploads[t].allocated_objid); std::auto_ptr<IOStream> filestream(apProtocol->ReceiveStream()); test_test_file(t, *filestream); @@ -1206,8 +1206,8 @@ int test_server(const char *hostname) { // Fetch the block index for this one - std::auto_ptr<BackupProtocolClientSuccess> getblockindex(apProtocol->QueryGetBlockIndexByName( - BackupProtocolClientListDirectory::RootDirectory, uploads[UPLOAD_PATCH_EN].name)); + std::auto_ptr<BackupProtocolSuccess> getblockindex(apProtocol->QueryGetBlockIndexByName( + BackupProtocolListDirectory::RootDirectory, uploads[UPLOAD_PATCH_EN].name)); TEST_THAT(getblockindex->GetObjectID() == uploads[UPLOAD_PATCH_EN].allocated_objid); std::auto_ptr<IOStream> blockIndexStream(apProtocol->ReceiveStream()); @@ -1217,7 +1217,7 @@ int test_server(const char *hostname) std::auto_ptr<IOStream> patchstream( BackupStoreFile::EncodeFileDiff( TEST_FILE_FOR_PATCHING ".mod", - BackupProtocolClientListDirectory::RootDirectory, + BackupProtocolListDirectory::RootDirectory, uploads[UPLOAD_PATCH_EN].name, uploads[UPLOAD_PATCH_EN].allocated_objid, *blockIndexStream, @@ -1236,8 +1236,8 @@ int test_server(const char *hostname) int64_t patchedID = 0; { FileStream uploadpatch(TEST_FILE_FOR_PATCHING ".patch"); - std::auto_ptr<BackupProtocolClientSuccess> stored(apProtocol->QueryStoreFile( - BackupProtocolClientListDirectory::RootDirectory, + std::auto_ptr<BackupProtocolSuccess> stored(apProtocol->QueryStoreFile( + BackupProtocolListDirectory::RootDirectory, modtime, modtime, /* use it for attr hash too */ uploads[UPLOAD_PATCH_EN].allocated_objid, /* diff from ID */ @@ -1251,7 +1251,7 @@ int test_server(const char *hostname) set_refcount(patchedID, 1); // Then download it to check it's OK - std::auto_ptr<BackupProtocolClientSuccess> getFile(apProtocol->QueryGetFile(BackupProtocolClientListDirectory::RootDirectory, patchedID)); + std::auto_ptr<BackupProtocolSuccess> getFile(apProtocol->QueryGetFile(BackupProtocolListDirectory::RootDirectory, patchedID)); TEST_THAT(getFile->GetObjectID() == patchedID); std::auto_ptr<IOStream> filestream(apProtocol->ReceiveStream()); BackupStoreFile::DecodeFile(*filestream, TEST_FILE_FOR_PATCHING ".downloaded", IOStream::TimeOutInfinite); @@ -1267,8 +1267,8 @@ int test_server(const char *hostname) { // Attributes MemBlockStream attr(attr1, sizeof(attr1)); - std::auto_ptr<BackupProtocolClientSuccess> dirCreate(apProtocol->QueryCreateDirectory( - BackupProtocolClientListDirectory::RootDirectory, + std::auto_ptr<BackupProtocolSuccess> dirCreate(apProtocol->QueryCreateDirectory( + BackupProtocolListDirectory::RootDirectory, 9837429842987984LL, dirname, attr)); subdirid = dirCreate->GetObjectID(); TEST_THAT(subdirid == maxID + 1); @@ -1285,7 +1285,7 @@ int test_server(const char *hostname) int64_t modtime; std::auto_ptr<IOStream> upload(BackupStoreFile::EncodeFile(filename.c_str(), subdirid, uploads[0].name, &modtime)); - std::auto_ptr<BackupProtocolClientSuccess> stored(apProtocol->QueryStoreFile( + std::auto_ptr<BackupProtocolSuccess> stored(apProtocol->QueryStoreFile( subdirid, modtime, modtime, /* use for attr hash too */ @@ -1303,10 +1303,10 @@ int test_server(const char *hostname) // Check the directories on the read only connection { // Command - std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocolReadOnly.QueryListDirectory( - BackupProtocolClientListDirectory::RootDirectory, - BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING, - BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes! */)); // Stream + std::auto_ptr<BackupProtocolSuccess> dirreply(protocolReadOnly.QueryListDirectory( + BackupProtocolListDirectory::RootDirectory, + BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING, + BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes! */)); // Stream BackupStoreDirectory dir; std::auto_ptr<IOStream> dirstream(protocolReadOnly.ReceiveStream()); dir.ReadFromStream(*dirstream, IOStream::TimeOutInfinite); @@ -1328,17 +1328,17 @@ int test_server(const char *hostname) } // Does it look right? TEST_THAT(en->GetName() == dirname); - TEST_THAT(en->GetFlags() == BackupProtocolClientListDirectory::Flags_Dir); + TEST_THAT(en->GetFlags() == BackupProtocolListDirectory::Flags_Dir); TEST_THAT(en->GetObjectID() == subdirid); TEST_THAT(en->GetModificationTime() == 0); // dirs don't have modification times. } { // Command - std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocolReadOnly.QueryListDirectory( + std::auto_ptr<BackupProtocolSuccess> dirreply(protocolReadOnly.QueryListDirectory( subdirid, - BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING, - BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, true /* get attributes */)); + BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING, + BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, true /* get attributes */)); TEST_THAT(dirreply->GetObjectID() == subdirid); // Stream BackupStoreDirectory dir; @@ -1353,7 +1353,7 @@ int test_server(const char *hostname) TEST_THAT(en != 0); // Does it look right? TEST_THAT(en->GetName() == uploads[0].name); - TEST_THAT(en->GetFlags() == BackupProtocolClientListDirectory::Flags_File); + TEST_THAT(en->GetFlags() == BackupProtocolListDirectory::Flags_File); TEST_THAT(en->GetObjectID() == subdirfileid); TEST_THAT(en->GetModificationTime() != 0); @@ -1368,10 +1368,10 @@ int test_server(const char *hostname) // Check that we don't get attributes if we don't ask for them { // Command - std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocolReadOnly.QueryListDirectory( + std::auto_ptr<BackupProtocolSuccess> dirreply(protocolReadOnly.QueryListDirectory( subdirid, - BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING, - BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes! */)); + BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING, + BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes! */)); // Stream BackupStoreDirectory dir; std::auto_ptr<IOStream> dirstream(protocolReadOnly.ReceiveStream()); @@ -1385,7 +1385,7 @@ int test_server(const char *hostname) // Change attributes on the directory { MemBlockStream attrnew(attr2, sizeof(attr2)); - std::auto_ptr<BackupProtocolClientSuccess> changereply(apProtocol->QueryChangeDirAttributes( + std::auto_ptr<BackupProtocolSuccess> changereply(apProtocol->QueryChangeDirAttributes( subdirid, 329483209443598LL, attrnew)); @@ -1394,10 +1394,10 @@ int test_server(const char *hostname) // Check the new attributes { // Command - std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocolReadOnly.QueryListDirectory( + std::auto_ptr<BackupProtocolSuccess> dirreply(protocolReadOnly.QueryListDirectory( subdirid, 0, // no flags - BackupProtocolClientListDirectory::Flags_EXCLUDE_EVERYTHING, true /* get attributes */)); + BackupProtocolListDirectory::Flags_EXCLUDE_EVERYTHING, true /* get attributes */)); // Stream BackupStoreDirectory dir; std::auto_ptr<IOStream> dirstream(protocolReadOnly.ReceiveStream()); @@ -1418,9 +1418,9 @@ int test_server(const char *hostname) { BackupStoreFilenameClear newName("moved-files"); - std::auto_ptr<BackupProtocolClientSuccess> rep(apProtocol->QueryMoveObject(uploads[UPLOAD_FILE_TO_MOVE].allocated_objid, - BackupProtocolClientListDirectory::RootDirectory, - subdirid, BackupProtocolClientMoveObject::Flags_MoveAllWithSameName, newName)); + std::auto_ptr<BackupProtocolSuccess> rep(apProtocol->QueryMoveObject(uploads[UPLOAD_FILE_TO_MOVE].allocated_objid, + BackupProtocolListDirectory::RootDirectory, + subdirid, BackupProtocolMoveObject::Flags_MoveAllWithSameName, newName)); TEST_THAT(rep->GetObjectID() == uploads[UPLOAD_FILE_TO_MOVE].allocated_objid); } @@ -1428,12 +1428,12 @@ int test_server(const char *hostname) { BackupStoreFilenameClear newName("moved-files"); TEST_CHECK_THROWS(apProtocol->QueryMoveObject(uploads[UPLOAD_FILE_TO_MOVE].allocated_objid, - BackupProtocolClientListDirectory::RootDirectory, - subdirid, BackupProtocolClientMoveObject::Flags_MoveAllWithSameName, newName), + BackupProtocolListDirectory::RootDirectory, + subdirid, BackupProtocolMoveObject::Flags_MoveAllWithSameName, newName), ConnectionException, Conn_Protocol_UnexpectedReply); TEST_CHECK_THROWS(apProtocol->QueryMoveObject(uploads[UPLOAD_FILE_TO_MOVE].allocated_objid, subdirid, - subdirid, BackupProtocolClientMoveObject::Flags_MoveAllWithSameName, newName), + subdirid, BackupProtocolMoveObject::Flags_MoveAllWithSameName, newName), ConnectionException, Conn_Protocol_UnexpectedReply); } @@ -1442,16 +1442,16 @@ int test_server(const char *hostname) BackupStoreFilenameClear newName("moved-files-x"); apProtocol->QueryMoveObject(uploads[UPLOAD_FILE_TO_MOVE].allocated_objid, subdirid, - subdirid, BackupProtocolClientMoveObject::Flags_MoveAllWithSameName, newName); + subdirid, BackupProtocolMoveObject::Flags_MoveAllWithSameName, newName); } // Check it's all gone from the root directory... { // Command - std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocolReadOnly.QueryListDirectory( - BackupProtocolClientListDirectory::RootDirectory, - BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING, - BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); + std::auto_ptr<BackupProtocolSuccess> dirreply(protocolReadOnly.QueryListDirectory( + BackupProtocolListDirectory::RootDirectory, + BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING, + BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); // Stream BackupStoreDirectory dir; std::auto_ptr<IOStream> dirstream(protocolReadOnly.ReceiveStream()); @@ -1470,10 +1470,10 @@ int test_server(const char *hostname) BackupStoreFilenameClear lookFor("moved-files-x"); // Command - std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocolReadOnly.QueryListDirectory( + std::auto_ptr<BackupProtocolSuccess> dirreply(protocolReadOnly.QueryListDirectory( subdirid, - BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING, - BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); + BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING, + BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); // Stream BackupStoreDirectory dir; std::auto_ptr<IOStream> dirstream(protocolReadOnly.ReceiveStream()); @@ -1505,14 +1505,14 @@ int test_server(const char *hostname) BackupStoreFilenameClear nd("sub2"); // Attributes MemBlockStream attr(attr1, sizeof(attr1)); - std::auto_ptr<BackupProtocolClientSuccess> dirCreate(apProtocol->QueryCreateDirectory( + std::auto_ptr<BackupProtocolSuccess> dirCreate(apProtocol->QueryCreateDirectory( subdirid, 9837429842987984LL, nd, attr)); subsubdirid = dirCreate->GetObjectID(); FileStream upload("testfiles/file1_upload1"); BackupStoreFilenameClear nf("file2"); - std::auto_ptr<BackupProtocolClientSuccess> stored(apProtocol->QueryStoreFile( + std::auto_ptr<BackupProtocolSuccess> stored(apProtocol->QueryStoreFile( subsubdirid, 0x123456789abcdefLL, /* modification time */ 0x7362383249872dfLL, /* attr hash */ @@ -1527,29 +1527,29 @@ int test_server(const char *hostname) // Query names -- test that invalid stuff returns not found OK { - std::auto_ptr<BackupProtocolClientObjectName> nameRep(apProtocol->QueryGetObjectName(3248972347823478927LL, subsubdirid)); + std::auto_ptr<BackupProtocolObjectName> nameRep(apProtocol->QueryGetObjectName(3248972347823478927LL, subsubdirid)); TEST_THAT(nameRep->GetNumNameElements() == 0); } { - std::auto_ptr<BackupProtocolClientObjectName> nameRep(apProtocol->QueryGetObjectName(subsubfileid, 2342378424LL)); + std::auto_ptr<BackupProtocolObjectName> nameRep(apProtocol->QueryGetObjectName(subsubfileid, 2342378424LL)); TEST_THAT(nameRep->GetNumNameElements() == 0); } { - std::auto_ptr<BackupProtocolClientObjectName> nameRep(apProtocol->QueryGetObjectName(38947234789LL, 2342378424LL)); + std::auto_ptr<BackupProtocolObjectName> nameRep(apProtocol->QueryGetObjectName(38947234789LL, 2342378424LL)); TEST_THAT(nameRep->GetNumNameElements() == 0); } { - std::auto_ptr<BackupProtocolClientObjectName> nameRep(apProtocol->QueryGetObjectName(BackupProtocolClientGetObjectName::ObjectID_DirectoryOnly, 2234342378424LL)); + std::auto_ptr<BackupProtocolObjectName> nameRep(apProtocol->QueryGetObjectName(BackupProtocolGetObjectName::ObjectID_DirectoryOnly, 2234342378424LL)); TEST_THAT(nameRep->GetNumNameElements() == 0); } // Query names... first, get info for the file { - std::auto_ptr<BackupProtocolClientObjectName> nameRep(apProtocol->QueryGetObjectName(subsubfileid, subsubdirid)); + std::auto_ptr<BackupProtocolObjectName> nameRep(apProtocol->QueryGetObjectName(subsubfileid, subsubdirid)); std::auto_ptr<IOStream> namestream(apProtocol->ReceiveStream()); TEST_THAT(nameRep->GetNumNameElements() == 3); - TEST_THAT(nameRep->GetFlags() == BackupProtocolClientListDirectory::Flags_File); + TEST_THAT(nameRep->GetFlags() == BackupProtocolListDirectory::Flags_File); TEST_THAT(nameRep->GetModificationTime() == 0x123456789abcdefLL); TEST_THAT(nameRep->GetAttributesHash() == 0x7362383249872dfLL); static const char *testnames[] = {"file2","sub2","lovely_directory"}; @@ -1563,11 +1563,11 @@ int test_server(const char *hostname) // Query names... secondly, for the directory { - std::auto_ptr<BackupProtocolClientObjectName> nameRep(apProtocol->QueryGetObjectName(BackupProtocolClientGetObjectName::ObjectID_DirectoryOnly, subsubdirid)); + std::auto_ptr<BackupProtocolObjectName> nameRep(apProtocol->QueryGetObjectName(BackupProtocolGetObjectName::ObjectID_DirectoryOnly, subsubdirid)); std::auto_ptr<IOStream> namestream(apProtocol->ReceiveStream()); TEST_THAT(nameRep->GetNumNameElements() == 2); - TEST_THAT(nameRep->GetFlags() == BackupProtocolClientListDirectory::Flags_Dir); + TEST_THAT(nameRep->GetFlags() == BackupProtocolListDirectory::Flags_Dir); static const char *testnames[] = {"sub2","lovely_directory"}; for(int l = 0; l < nameRep->GetNumNameElements(); ++l) { @@ -1585,12 +1585,12 @@ int test_server(const char *hostname) // Create some nice recursive directories int64_t dirtodelete = create_test_data_subdirs(*apProtocol, - BackupProtocolClientListDirectory::RootDirectory, + BackupProtocolListDirectory::RootDirectory, "test_delete", 6 /* depth */, *apRefCount); // And delete them { - std::auto_ptr<BackupProtocolClientSuccess> dirdel(apProtocol->QueryDeleteDirectory( + std::auto_ptr<BackupProtocolSuccess> dirdel(apProtocol->QueryDeleteDirectory( dirtodelete)); TEST_THAT(dirdel->GetObjectID() == dirtodelete); } @@ -1598,10 +1598,10 @@ int test_server(const char *hostname) // Get the root dir, checking for deleted items { // Command - std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocolReadOnly.QueryListDirectory( - BackupProtocolClientListDirectory::RootDirectory, - BackupProtocolClientListDirectory::Flags_Dir | BackupProtocolClientListDirectory::Flags_Deleted, - BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); + std::auto_ptr<BackupProtocolSuccess> dirreply(protocolReadOnly.QueryListDirectory( + BackupProtocolListDirectory::RootDirectory, + BackupProtocolListDirectory::Flags_Dir | BackupProtocolListDirectory::Flags_Deleted, + BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); // Stream BackupStoreDirectory dir; std::auto_ptr<IOStream> dirstream(protocolReadOnly.ReceiveStream()); @@ -1889,11 +1889,11 @@ int test3(int argc, const char *argv[]) BackupProtocolClient protocol(conn); // Check the version - std::auto_ptr<BackupProtocolClientVersion> serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION)); + std::auto_ptr<BackupProtocolVersion> serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION)); TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION); // Login - TEST_CHECK_THROWS(std::auto_ptr<BackupProtocolClientLoginConfirmed> loginConf(protocol.QueryLogin(0x01234567, 0)), + TEST_CHECK_THROWS(std::auto_ptr<BackupProtocolLoginConfirmed> loginConf(protocol.QueryLogin(0x01234567, 0)), ConnectionException, Conn_Protocol_UnexpectedReply); // Finish the connection @@ -1988,7 +1988,7 @@ int test3(int argc, const char *argv[]) // First, things as they are now. recursive_count_objects_results before = {0,0,0}; - recursive_count_objects("localhost", BackupProtocolClientListDirectory::RootDirectory, before); + recursive_count_objects("localhost", BackupProtocolListDirectory::RootDirectory, before); TEST_THAT(before.objectsNotDel != 0); TEST_THAT(before.deleted != 0); @@ -2033,7 +2033,7 @@ int test3(int argc, const char *argv[]) // Count the objects again recursive_count_objects_results after = {0,0,0}; recursive_count_objects("localhost", - BackupProtocolClientListDirectory::RootDirectory, + BackupProtocolListDirectory::RootDirectory, after); // If these tests fail then try increasing the timeout above @@ -2058,20 +2058,20 @@ int test3(int argc, const char *argv[]) BackupProtocolClient protocol(conn); // Check the version - std::auto_ptr<BackupProtocolClientVersion> serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION)); + std::auto_ptr<BackupProtocolVersion> serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION)); TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION); // Login - std::auto_ptr<BackupProtocolClientLoginConfirmed> loginConf(protocol.QueryLogin(0x01234567, 0)); + std::auto_ptr<BackupProtocolLoginConfirmed> loginConf(protocol.QueryLogin(0x01234567, 0)); int64_t modtime = 0; BackupStoreFilenameClear fnx("exceed-limit"); - std::auto_ptr<IOStream> upload(BackupStoreFile::EncodeFile("testfiles/test3", BackupProtocolClientListDirectory::RootDirectory, fnx, &modtime)); + std::auto_ptr<IOStream> upload(BackupStoreFile::EncodeFile("testfiles/test3", BackupProtocolListDirectory::RootDirectory, fnx, &modtime)); TEST_THAT(modtime != 0); - TEST_CHECK_THROWS(std::auto_ptr<BackupProtocolClientSuccess> stored(protocol.QueryStoreFile( - BackupProtocolClientListDirectory::RootDirectory, + TEST_CHECK_THROWS(std::auto_ptr<BackupProtocolSuccess> stored(protocol.QueryStoreFile( + BackupProtocolListDirectory::RootDirectory, modtime, modtime, /* use it for attr hash too */ 0, /* diff from ID */ @@ -2081,8 +2081,8 @@ int test3(int argc, const char *argv[]) MemBlockStream attr(&modtime, sizeof(modtime)); BackupStoreFilenameClear fnxd("exceed-limit-dir"); - TEST_CHECK_THROWS(std::auto_ptr<BackupProtocolClientSuccess> dirCreate(protocol.QueryCreateDirectory( - BackupProtocolClientListDirectory::RootDirectory, + TEST_CHECK_THROWS(std::auto_ptr<BackupProtocolSuccess> dirCreate(protocol.QueryCreateDirectory( + BackupProtocolListDirectory::RootDirectory, 9837429842987984LL, fnxd, attr)), ConnectionException, Conn_Protocol_UnexpectedReply); @@ -2240,7 +2240,7 @@ int test(int argc, const char *argv[]) /* { int64_t modtime = 0; std::auto_ptr<IOStream> upload(BackupStoreFile::EncodeFile("/Users/ben/temp/large.tar", - BackupProtocolClientListDirectory::RootDirectory, uploads[0].name, &modtime)); + BackupProtocolListDirectory::RootDirectory, uploads[0].name, &modtime)); TEST_THAT(modtime != 0); FileStream write("testfiles/large.enc", O_WRONLY | O_CREAT); upload->CopyStreamTo(write); diff --git a/test/backupstorepatch/testbackupstorepatch.cpp b/test/backupstorepatch/testbackupstorepatch.cpp index 2510da30..fab56523 100644 --- a/test/backupstorepatch/testbackupstorepatch.cpp +++ b/test/backupstorepatch/testbackupstorepatch.cpp @@ -13,7 +13,7 @@ #include <string.h> #include <signal.h> -#include "autogen_BackupProtocolClient.h" +#include "autogen_BackupProtocol.h" #include "BackupClientCryptoKeys.h" #include "BackupClientFileAttributes.h" #include "BackupStoreAccountDatabase.h" @@ -354,7 +354,7 @@ int test(int argc, const char *argv[]) // Login { // Check the version - std::auto_ptr<BackupProtocolClientVersion> serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION)); + std::auto_ptr<BackupProtocolVersion> serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION)); TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION); // Login @@ -367,9 +367,9 @@ int test(int argc, const char *argv[]) // Upload the first file { std::auto_ptr<IOStream> upload(BackupStoreFile::EncodeFile("testfiles/0.test", - BackupProtocolClientListDirectory::RootDirectory, storeFilename)); - std::auto_ptr<BackupProtocolClientSuccess> stored(protocol.QueryStoreFile( - BackupProtocolClientListDirectory::RootDirectory, ModificationTime, + BackupProtocolListDirectory::RootDirectory, storeFilename)); + std::auto_ptr<BackupProtocolSuccess> stored(protocol.QueryStoreFile( + BackupProtocolListDirectory::RootDirectory, ModificationTime, ModificationTime, 0 /* no diff from file ID */, storeFilename, *upload)); test_files[0].IDOnServer = stored->GetObjectID(); test_files[0].IsCompletelyDifferent = true; @@ -380,8 +380,8 @@ int test(int argc, const char *argv[]) for(unsigned int f = 1; f < NUMBER_FILES; ++f) { // Get an index for the previous version - std::auto_ptr<BackupProtocolClientSuccess> getBlockIndex(protocol.QueryGetBlockIndexByName( - BackupProtocolClientListDirectory::RootDirectory, storeFilename)); + std::auto_ptr<BackupProtocolSuccess> getBlockIndex(protocol.QueryGetBlockIndexByName( + BackupProtocolListDirectory::RootDirectory, storeFilename)); int64_t diffFromID = getBlockIndex->GetObjectID(); TEST_THAT(diffFromID != 0); @@ -397,7 +397,7 @@ int test(int argc, const char *argv[]) std::auto_ptr<IOStream> patchStream( BackupStoreFile::EncodeFileDiff( filename, - BackupProtocolClientListDirectory::RootDirectory, /* containing directory */ + BackupProtocolListDirectory::RootDirectory, /* containing directory */ storeFilename, diffFromID, *blockIndexStream, @@ -407,8 +407,8 @@ int test(int argc, const char *argv[]) &isCompletelyDifferent)); // Upload the patch to the store - std::auto_ptr<BackupProtocolClientSuccess> stored(protocol.QueryStoreFile( - BackupProtocolClientListDirectory::RootDirectory, ModificationTime, + std::auto_ptr<BackupProtocolSuccess> stored(protocol.QueryStoreFile( + BackupProtocolListDirectory::RootDirectory, ModificationTime, ModificationTime, isCompletelyDifferent?(0):(diffFromID), storeFilename, *patchStream)); ModificationTime += MODIFICATION_TIME_INC; @@ -432,10 +432,10 @@ int test(int argc, const char *argv[]) // List the directory from the server, and check that no dependency info is sent -- waste of bytes { - std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocol.QueryListDirectory( - BackupProtocolClientListDirectory::RootDirectory, - BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING, - BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); + std::auto_ptr<BackupProtocolSuccess> dirreply(protocol.QueryListDirectory( + BackupProtocolListDirectory::RootDirectory, + BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING, + BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); // Stream BackupStoreDirectory dir; std::auto_ptr<IOStream> dirstream(protocol.ReceiveStream()); @@ -531,7 +531,7 @@ int test(int argc, const char *argv[]) BOX_PORT_BBSTORED_TEST); BackupProtocolClient protocol(conn); { - std::auto_ptr<BackupProtocolClientVersion> serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION)); + std::auto_ptr<BackupProtocolVersion> serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION)); TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION); protocol.QueryLogin(0x01234567, 0); } @@ -555,8 +555,8 @@ int test(int argc, const char *argv[]) // Fetch the file { - std::auto_ptr<BackupProtocolClientSuccess> getobj(protocol.QueryGetFile( - BackupProtocolClientListDirectory::RootDirectory, + std::auto_ptr<BackupProtocolSuccess> getobj(protocol.QueryGetFile( + BackupProtocolListDirectory::RootDirectory, test_files[f].IDOnServer)); TEST_THAT(getobj->GetObjectID() == test_files[f].IDOnServer); // BLOCK @@ -572,7 +572,7 @@ int test(int argc, const char *argv[]) // Download the index, and check it looks OK { - std::auto_ptr<BackupProtocolClientSuccess> getblockindex(protocol.QueryGetBlockIndexByID(test_files[f].IDOnServer)); + std::auto_ptr<BackupProtocolSuccess> getblockindex(protocol.QueryGetBlockIndexByID(test_files[f].IDOnServer)); TEST_THAT(getblockindex->GetObjectID() == test_files[f].IDOnServer); std::auto_ptr<IOStream> blockIndexStream(protocol.ReceiveStream()); TEST_THAT(BackupStoreFile::CompareFileContentsAgainstBlockIndex(filename, *blockIndexStream, IOStream::TimeOutInfinite)); diff --git a/test/basicserver/Makefile.extra b/test/basicserver/Makefile.extra index 50120136..e6a4675e 100644 --- a/test/basicserver/Makefile.extra +++ b/test/basicserver/Makefile.extra @@ -1,21 +1,12 @@ MAKEPROTOCOL = ../../lib/server/makeprotocol.pl -GEN_CMD_SRV = $(MAKEPROTOCOL) Server testprotocol.txt -GEN_CMD_CLI = $(MAKEPROTOCOL) Client testprotocol.txt +GEN_CMD = $(MAKEPROTOCOL) testprotocol.txt # AUTOGEN SEEDING -autogen_TestProtocolServer.cpp: $(MAKEPROTOCOL) testprotocol.txt - $(_PERL) $(GEN_CMD_SRV) +autogen_TestProtocol.cpp: $(MAKEPROTOCOL) testprotocol.txt + $(_PERL) $(GEN_CMD) autogen_TestProtocolServer.h: $(MAKEPROTOCOL) testprotocol.txt - $(_PERL) $(GEN_CMD_SRV) - - -# AUTOGEN SEEDING -autogen_TestProtocolClient.cpp: $(MAKEPROTOCOL) testprotocol.txt - $(_PERL) $(GEN_CMD_CLI) - -autogen_TestProtocolClient.h: $(MAKEPROTOCOL) testprotocol.txt - $(_PERL) $(GEN_CMD_CLI) + $(_PERL) $(GEN_CMD) diff --git a/test/basicserver/TestCommands.cpp b/test/basicserver/TestCommands.cpp index 657e79ea..5238819f 100644 --- a/test/basicserver/TestCommands.cpp +++ b/test/basicserver/TestCommands.cpp @@ -5,34 +5,34 @@ #include <syslog.h> #endif -#include "autogen_TestProtocolServer.h" +#include "autogen_TestProtocol.h" #include "CollectInBufferStream.h" #include "MemLeakFindOn.h" -std::auto_ptr<ProtocolObject> TestProtocolServerHello::DoCommand(TestProtocolServer &rProtocol, TestContext &rContext) +std::auto_ptr<TestProtocolMessage> TestProtocolHello::DoCommand(TestProtocolReplyable &rProtocol, TestContext &rContext) const { if(mNumber32 != 41 || mNumber16 != 87 || mNumber8 != 11 || mText != "pingu") { - return std::auto_ptr<ProtocolObject>(new TestProtocolServerError(0, 0)); + return std::auto_ptr<TestProtocolMessage>(new TestProtocolError(0, 0)); } - return std::auto_ptr<ProtocolObject>(new TestProtocolServerHello(12,89,22,std::string("Hello world!"))); + return std::auto_ptr<TestProtocolMessage>(new TestProtocolHello(12,89,22,std::string("Hello world!"))); } -std::auto_ptr<ProtocolObject> TestProtocolServerLists::DoCommand(TestProtocolServer &rProtocol, TestContext &rContext) +std::auto_ptr<TestProtocolMessage> TestProtocolLists::DoCommand(TestProtocolReplyable &rProtocol, TestContext &rContext) const { - return std::auto_ptr<ProtocolObject>(new TestProtocolServerListsReply(mLotsOfText.size())); + return std::auto_ptr<TestProtocolMessage>(new TestProtocolListsReply(mLotsOfText.size())); } -std::auto_ptr<ProtocolObject> TestProtocolServerQuit::DoCommand(TestProtocolServer &rProtocol, TestContext &rContext) +std::auto_ptr<TestProtocolMessage> TestProtocolQuit::DoCommand(TestProtocolReplyable &rProtocol, TestContext &rContext) const { - return std::auto_ptr<ProtocolObject>(new TestProtocolServerQuit); + return std::auto_ptr<TestProtocolMessage>(new TestProtocolQuit); } -std::auto_ptr<ProtocolObject> TestProtocolServerSimple::DoCommand(TestProtocolServer &rProtocol, TestContext &rContext) +std::auto_ptr<TestProtocolMessage> TestProtocolSimple::DoCommand(TestProtocolReplyable &rProtocol, TestContext &rContext) const { - return std::auto_ptr<ProtocolObject>(new TestProtocolServerSimpleReply(mValue+1)); + return std::auto_ptr<TestProtocolMessage>(new TestProtocolSimpleReply(mValue+1)); } class UncertainBufferStream : public CollectInBufferStream @@ -45,7 +45,7 @@ public: } }; -std::auto_ptr<ProtocolObject> TestProtocolServerGetStream::DoCommand(TestProtocolServer &rProtocol, TestContext &rContext) +std::auto_ptr<TestProtocolMessage> TestProtocolGetStream::DoCommand(TestProtocolReplyable &rProtocol, TestContext &rContext) const { // make a new stream object CollectInBufferStream *pstream = mUncertainSize?(new UncertainBufferStream):(new CollectInBufferStream); @@ -68,14 +68,14 @@ std::auto_ptr<ProtocolObject> TestProtocolServerGetStream::DoCommand(TestProtoco // Get it to be sent rProtocol.SendStreamAfterCommand(pstream); - return std::auto_ptr<ProtocolObject>(new TestProtocolServerGetStream(mStartingValue, mUncertainSize)); + return std::auto_ptr<TestProtocolMessage>(new TestProtocolGetStream(mStartingValue, mUncertainSize)); } -std::auto_ptr<ProtocolObject> TestProtocolServerSendStream::DoCommand(TestProtocolServer &rProtocol, TestContext &rContext) +std::auto_ptr<TestProtocolMessage> TestProtocolSendStream::DoCommand(TestProtocolReplyable &rProtocol, TestContext &rContext) const { if(mValue != 0x73654353298ffLL) { - return std::auto_ptr<ProtocolObject>(new TestProtocolServerError(0, 0)); + return std::auto_ptr<TestProtocolMessage>(new TestProtocolError(0, 0)); } // Get a stream @@ -91,11 +91,11 @@ std::auto_ptr<ProtocolObject> TestProtocolServerSendStream::DoCommand(TestProtoc } // tell the caller how many bytes there were - return std::auto_ptr<ProtocolObject>(new TestProtocolServerGetStream(bytes, uncertain)); + return std::auto_ptr<TestProtocolMessage>(new TestProtocolGetStream(bytes, uncertain)); } -std::auto_ptr<ProtocolObject> TestProtocolServerString::DoCommand(TestProtocolServer &rProtocol, TestContext &rContext) +std::auto_ptr<TestProtocolMessage> TestProtocolString::DoCommand(TestProtocolReplyable &rProtocol, TestContext &rContext) const { - return std::auto_ptr<ProtocolObject>(new TestProtocolServerString(mTest)); + return std::auto_ptr<TestProtocolMessage>(new TestProtocolString(mTest)); } diff --git a/test/basicserver/testbasicserver.cpp b/test/basicserver/testbasicserver.cpp index 29bf8b6a..976bdd92 100644 --- a/test/basicserver/testbasicserver.cpp +++ b/test/basicserver/testbasicserver.cpp @@ -26,8 +26,7 @@ #include "CollectInBufferStream.h" #include "TestContext.h" -#include "autogen_TestProtocolClient.h" -#include "autogen_TestProtocolServer.h" +#include "autogen_TestProtocol.h" #include "ServerControl.h" #include "MemLeakFindOn.h" @@ -393,7 +392,7 @@ void Srv2TestConversations(const std::vector<IOStream *> &conns) void TestStreamReceive(TestProtocolClient &protocol, int value, bool uncertainstream) { - std::auto_ptr<TestProtocolClientGetStream> reply(protocol.QueryGetStream(value, uncertainstream)); + std::auto_ptr<TestProtocolGetStream> reply(protocol.QueryGetStream(value, uncertainstream)); TEST_THAT(reply->GetStartingValue() == value); // Get a stream @@ -704,11 +703,11 @@ int test(int argc, const char *argv[]) // Simple query { - std::auto_ptr<TestProtocolClientSimpleReply> reply(protocol.QuerySimple(41)); + std::auto_ptr<TestProtocolSimpleReply> reply(protocol.QuerySimple(41)); TEST_THAT(reply->GetValuePlusOne() == 42); } { - std::auto_ptr<TestProtocolClientSimpleReply> reply(protocol.QuerySimple(809)); + std::auto_ptr<TestProtocolSimpleReply> reply(protocol.QuerySimple(809)); TEST_THAT(reply->GetValuePlusOne() == 810); } @@ -724,14 +723,14 @@ int test(int argc, const char *argv[]) char buf[1663]; s.Write(buf, sizeof(buf)); s.SetForReading(); - std::auto_ptr<TestProtocolClientGetStream> reply(protocol.QuerySendStream(0x73654353298ffLL, s)); + std::auto_ptr<TestProtocolGetStream> reply(protocol.QuerySendStream(0x73654353298ffLL, s)); TEST_THAT(reply->GetStartingValue() == sizeof(buf)); } // Lots of simple queries for(int q = 0; q < 514; q++) { - std::auto_ptr<TestProtocolClientSimpleReply> reply(protocol.QuerySimple(q)); + std::auto_ptr<TestProtocolSimpleReply> reply(protocol.QuerySimple(q)); TEST_THAT(reply->GetValuePlusOne() == (q+1)); } // Send a list of strings to it @@ -740,13 +739,13 @@ int test(int argc, const char *argv[]) strings.push_back(std::string("test1")); strings.push_back(std::string("test2")); strings.push_back(std::string("test3")); - std::auto_ptr<TestProtocolClientListsReply> reply(protocol.QueryLists(strings)); + std::auto_ptr<TestProtocolListsReply> reply(protocol.QueryLists(strings)); TEST_THAT(reply->GetNumberOfStrings() == 3); } // And another { - std::auto_ptr<TestProtocolClientHello> reply(protocol.QueryHello(41,87,11,std::string("pingu"))); + std::auto_ptr<TestProtocolHello> reply(protocol.QueryHello(41,87,11,std::string("pingu"))); TEST_THAT(reply->GetNumber32() == 12); TEST_THAT(reply->GetNumber16() == 89); TEST_THAT(reply->GetNumber8() == 22); diff --git a/test/bbackupd/Makefile.extra b/test/bbackupd/Makefile.extra index 84152e95..b78886b6 100644 --- a/test/bbackupd/Makefile.extra +++ b/test/bbackupd/Makefile.extra @@ -8,7 +8,7 @@ link-extra: ../../bin/bbackupd/autogen_ClientException.o \ ../../bin/bbackupd/BackupDaemon.o \ ../../bin/bbstored/BBStoreDHousekeeping.o \ ../../bin/bbstored/HousekeepStoreAccount.o \ - ../../lib/backupstore/autogen_BackupProtocolServer.o \ + ../../lib/backupstore/autogen_BackupProtocol.o \ ../../lib/backupstore/BackupStoreContext.o \ ../../lib/backupstore/BackupCommands.o \ ../../bin/bbstored/BackupStoreDaemon.o diff --git a/test/bbackupd/testbbackupd.cpp b/test/bbackupd/testbbackupd.cpp index 5693d69b..1059d43e 100644 --- a/test/bbackupd/testbbackupd.cpp +++ b/test/bbackupd/testbbackupd.cpp @@ -42,7 +42,7 @@ #include <sys/syscall.h> #endif -#include "autogen_BackupProtocolServer.h" +#include "autogen_BackupProtocol.h" #include "BackupClientCryptoKeys.h" #include "BackupClientFileAttributes.h" #include "BackupClientRestore.h" @@ -73,7 +73,6 @@ #include "Timer.h" #include "Utils.h" -#include "autogen_BackupProtocolClient.h" #include "intercept.h" #include "ServerControl.h" @@ -475,8 +474,8 @@ int64_t GetDirID(BackupProtocolClient &protocol, const char *name, int64_t InDir { protocol.QueryListDirectory( InDirectory, - BackupProtocolClientListDirectory::Flags_Dir, - BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, + BackupProtocolListDirectory::Flags_Dir, + BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, true /* want attributes */); // Retrieve the directory from the stream following @@ -518,9 +517,9 @@ void do_interrupted_restore(const TLSContext &context, int64_t restoredirid) 22011); BackupProtocolClient protocol(conn); protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION); - std::auto_ptr<BackupProtocolClientLoginConfirmed> + std::auto_ptr<BackupProtocolLoginConfirmed> loginConf(protocol.QueryLogin(0x01234567, - BackupProtocolClientLogin::Flags_ReadOnly)); + BackupProtocolLogin::Flags_ReadOnly)); // Test the restoration TEST_THAT(BackupClientRestore(protocol, restoredirid, @@ -604,7 +603,7 @@ int64_t SearchDir(BackupStoreDirectory& rDir, if (en == 0) return 0; int64_t id = en->GetObjectID(); TEST_THAT(id > 0); - TEST_THAT(id != BackupProtocolClientListDirectory::RootDirectory); + TEST_THAT(id != BackupProtocolListDirectory::RootDirectory); return id; } @@ -617,7 +616,7 @@ std::auto_ptr<BackupProtocolClient> Connect(TLSContext& rContext) std::auto_ptr<BackupProtocolClient> connection; connection.reset(new BackupProtocolClient(sSocket)); connection->Handshake(); - std::auto_ptr<BackupProtocolClientVersion> + std::auto_ptr<BackupProtocolVersion> serverVersion(connection->QueryVersion( BACKUP_STORE_SERVER_VERSION)); if(serverVersion->GetVersion() != @@ -640,10 +639,10 @@ std::auto_ptr<BackupProtocolClient> ConnectAndLogin(TLSContext& rContext, std::auto_ptr<BackupStoreDirectory> ReadDirectory ( BackupProtocolClient& rClient, - int64_t id + int64_t id = BackupProtocolListDirectory::RootDirectory ) { - std::auto_ptr<BackupProtocolClientSuccess> dirreply( + std::auto_ptr<BackupProtocolSuccess> dirreply( rClient.QueryListDirectory(id, false, 0, false)); std::auto_ptr<IOStream> dirstream(rClient.ReceiveStream()); std::auto_ptr<BackupStoreDirectory> apDir(new BackupStoreDirectory()); @@ -766,7 +765,7 @@ extern "C" struct dirent *readdir_test_hook_2(DIR *dir) } else { - BOX_INFO("readdir hook still active at " << time_now << ", " + BOX_TRACE("readdir hook still active at " << time_now << ", " "waiting for " << readdir_stop_time); } @@ -780,7 +779,7 @@ extern "C" struct dirent *readdir_test_hook_2(DIR *dir) snprintf(readdir_test_dirent.d_name, sizeof(readdir_test_dirent.d_name), "test.%d", readdir_test_counter); - BOX_INFO("readdir hook returning " << readdir_test_dirent.d_name); + BOX_TRACE("readdir hook returning " << readdir_test_dirent.d_name); // ensure that when bbackupd stats the file, it gets the // right answer @@ -792,6 +791,9 @@ extern "C" struct dirent *readdir_test_hook_2(DIR *dir) intercept_setup_lstat_hook(stat_hook_filename, lstat_test_hook); #endif + // sleep a bit to reduce the number of dirents returned + ::safe_sleep(1); + return &readdir_test_dirent; } @@ -1131,6 +1133,9 @@ int test_bbackupd() TEST_LINE(comp2 != sub, line); } + // Check that no read error has been reported yet + TEST_THAT(!TestFileExists("testfiles/notifyran.read-error.1")); + if (failures > 0) { // stop early to make debugging easier @@ -1338,7 +1343,7 @@ int test_bbackupd() std::auto_ptr<BackupProtocolClient> client = ConnectAndLogin(context, 0 /* read-write */); - std::auto_ptr<BackupProtocolClientAccountUsage> usage( + std::auto_ptr<BackupProtocolAccountUsage> usage( client->QueryGetAccountUsage()); TEST_EQUAL_LINE(24, usage->GetBlocksUsed(), "blocks used"); @@ -1421,8 +1426,7 @@ int test_bbackupd() ConnectAndLogin(context, 0 /* read-write */); std::auto_ptr<BackupStoreDirectory> rootDir = - ReadDirectory(*client, - BackupProtocolClientListDirectory::RootDirectory); + ReadDirectory(*client); int64_t testDirId = SearchDir(*rootDir, "Test1"); TEST_THAT(testDirId != 0); @@ -1464,7 +1468,7 @@ int test_bbackupd() ReadDirectory(*client, d4_id); TEST_THAT(test_entry_deleted(*d4_dir, "f5")); - std::auto_ptr<BackupProtocolClientAccountUsage> usage( + std::auto_ptr<BackupProtocolAccountUsage> usage( client->QueryGetAccountUsage()); TEST_EQUAL_LINE(24, usage->GetBlocksUsed(), "blocks used"); @@ -1498,8 +1502,7 @@ int test_bbackupd() ConnectAndLogin(context, 0 /* read-write */); std::auto_ptr<BackupStoreDirectory> rootDir = - ReadDirectory(*client, - BackupProtocolClientListDirectory::RootDirectory); + ReadDirectory(*client); int64_t testDirId = SearchDir(*rootDir, "Test1"); TEST_THAT(testDirId != 0); @@ -1519,7 +1522,7 @@ int test_bbackupd() TEST_THAT(SearchDir(*spacetest_dir, "d3") == 0); TEST_THAT(SearchDir(*spacetest_dir, "d7") == 0); - std::auto_ptr<BackupProtocolClientAccountUsage> usage( + std::auto_ptr<BackupProtocolAccountUsage> usage( client->QueryGetAccountUsage()); TEST_EQUAL_LINE(16, usage->GetBlocksUsed(), "blocks used"); @@ -1574,7 +1577,7 @@ int test_bbackupd() std::auto_ptr<BackupProtocolClient> client = ConnectAndLogin(context, 0 /* read-write */); - std::auto_ptr<BackupProtocolClientAccountUsage> usage( + std::auto_ptr<BackupProtocolAccountUsage> usage( client->QueryGetAccountUsage()); TEST_EQUAL_LINE(22, usage->GetBlocksUsed(), "blocks used"); @@ -1685,17 +1688,17 @@ int test_bbackupd() class MyHook : public BackupStoreContext::TestHook { - virtual std::auto_ptr<ProtocolObject> StartCommand( - BackupProtocolObject& rCommand) + virtual std::auto_ptr<BackupProtocolMessage> StartCommand( + const BackupProtocolMessage& rCommand) { if (rCommand.GetType() == - BackupProtocolServerStoreFile::TypeID) + BackupProtocolStoreFile::TypeID) { // terminate badly THROW_EXCEPTION(CommonException, Internal); } - return std::auto_ptr<ProtocolObject>(); + return std::auto_ptr<BackupProtocolMessage>(); } }; MyHook hook; @@ -1959,11 +1962,10 @@ int test_bbackupd() { std::auto_ptr<BackupProtocolClient> client = ConnectAndLogin(context, - BackupProtocolClientLogin::Flags_ReadOnly); + BackupProtocolLogin::Flags_ReadOnly); std::auto_ptr<BackupStoreDirectory> dir = - ReadDirectory(*client, - BackupProtocolClientListDirectory::RootDirectory); + ReadDirectory(*client); int64_t testDirId = SearchDir(*dir, "Test2"); TEST_THAT(testDirId != 0); @@ -1998,11 +2000,10 @@ int test_bbackupd() { std::auto_ptr<BackupProtocolClient> client = ConnectAndLogin(context, - BackupProtocolClientLogin::Flags_ReadOnly); + BackupProtocolLogin::Flags_ReadOnly); std::auto_ptr<BackupStoreDirectory> dir = - ReadDirectory(*client, - BackupProtocolClientListDirectory::RootDirectory); + ReadDirectory(*client); int64_t testDirId = SearchDir(*dir, "Test2"); TEST_THAT(testDirId != 0); @@ -2017,11 +2018,10 @@ int test_bbackupd() { std::auto_ptr<BackupProtocolClient> client = ConnectAndLogin(context, - BackupProtocolClientLogin::Flags_ReadOnly); + BackupProtocolLogin::Flags_ReadOnly); std::auto_ptr<BackupStoreDirectory> root_dir = - ReadDirectory(*client, - BackupProtocolClientListDirectory::RootDirectory); + ReadDirectory(*client); TEST_THAT(test_entry_deleted(*root_dir, "Test2")); @@ -2263,8 +2263,7 @@ int test_bbackupd() ConnectAndLogin(context, 0); std::auto_ptr<BackupStoreDirectory> dir = ReadDirectory( - *client, - BackupProtocolClientListDirectory::RootDirectory); + *client); int64_t baseDirId = SearchDir(*dir, "Test1"); TEST_THAT(baseDirId != 0); @@ -3257,11 +3256,10 @@ int test_bbackupd() { std::auto_ptr<BackupProtocolClient> client = ConnectAndLogin(context, - BackupProtocolClientLogin::Flags_ReadOnly); + BackupProtocolLogin::Flags_ReadOnly); std::auto_ptr<BackupStoreDirectory> dir = ReadDirectory( - *client, - BackupProtocolClientListDirectory::RootDirectory); + *client); int64_t testDirId = SearchDir(*dir, "Test1"); TEST_THAT(testDirId != 0); @@ -3438,11 +3436,11 @@ int test_bbackupd() // connect and log in std::auto_ptr<BackupProtocolClient> client = ConnectAndLogin(context, - BackupProtocolClientLogin::Flags_ReadOnly); + BackupProtocolLogin::Flags_ReadOnly); // Find the ID of the Test1 directory restoredirid = GetDirID(*client, "Test1", - BackupProtocolClientListDirectory::RootDirectory); + BackupProtocolListDirectory::RootDirectory); TEST_THAT(restoredirid != 0); // Test the restoration @@ -3745,7 +3743,7 @@ int test_bbackupd() // Make sure the marker isn't zero, // because that's the default, and // it should have changed - std::auto_ptr<BackupProtocolClientLoginConfirmed> loginConf(protocol->QueryLogin(0x01234567, 0)); + std::auto_ptr<BackupProtocolLoginConfirmed> loginConf(protocol->QueryLogin(0x01234567, 0)); TEST_THAT(loginConf->GetClientStoreMarker() != 0); // Change it to something else @@ -3823,7 +3821,7 @@ int test_bbackupd() std::auto_ptr<BackupProtocolClient> client = ConnectAndLogin(context, - BackupProtocolClientLogin::Flags_ReadOnly); + BackupProtocolLogin::Flags_ReadOnly); // Check that the restore fn returns resume possible, // rather than doing anything |