summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/bbackupd/BackupClientContext.cpp16
-rw-r--r--bin/bbackupd/BackupClientContext.h4
-rw-r--r--bin/bbackupd/BackupClientDeleteList.cpp2
-rw-r--r--bin/bbackupd/BackupClientDirectoryRecord.cpp14
-rw-r--r--bin/bbackupquery/BackupQueries.cpp2
-rw-r--r--bin/bbackupquery/BackupQueries.h12
-rw-r--r--bin/bbackupquery/CommandCompletion.cpp4
-rwxr-xr-xlib/server/makeprotocol.pl.in34
-rw-r--r--test/bbackupd/testbbackupd.cpp44
9 files changed, 78 insertions, 54 deletions
diff --git a/bin/bbackupd/BackupClientContext.cpp b/bin/bbackupd/BackupClientContext.cpp
index 977f7ec1..0c229f94 100644
--- a/bin/bbackupd/BackupClientContext.cpp
+++ b/bin/bbackupd/BackupClientContext.cpp
@@ -107,7 +107,7 @@ BackupClientContext::~BackupClientContext()
// Created: 2003/10/08
//
// --------------------------------------------------------------------------
-BackupProtocolClient &BackupClientContext::GetConnection()
+BackupProtocolCallable &BackupClientContext::GetConnection()
{
// Already got it? Just return it.
if(mapConnection.get())
@@ -144,10 +144,14 @@ BackupProtocolClient &BackupClientContext::GetConnection()
apSocket.reset(mpNice);
}
- mapConnection.reset(new BackupProtocolClient(apSocket));
+ // We need to call some methods that aren't defined in
+ // BackupProtocolCallable, so we need to hang onto a more
+ // strongly typed pointer (to avoid far too many casts).
+ BackupProtocolClient *pClient = new BackupProtocolClient(apSocket);
+ mapConnection.reset(pClient);
// Set logging option
- mapConnection->SetLogToSysLog(mExtendedLogging);
+ pClient->SetLogToSysLog(mExtendedLogging);
if (mExtendedLogToFile)
{
@@ -163,12 +167,12 @@ BackupProtocolClient &BackupClientContext::GetConnection()
}
else
{
- mapConnection->SetLogToFile(mpExtendedLogFileHandle);
+ pClient->SetLogToFile(mpExtendedLogFileHandle);
}
}
// Handshake
- mapConnection->Handshake();
+ pClient->Handshake();
// Check the version of the server
{
@@ -405,7 +409,7 @@ bool BackupClientContext::FindFilename(int64_t ObjectID, int64_t ContainingDirec
bool &rIsCurrentVersionOut, box_time_t *pModTimeOnServer, box_time_t *pAttributesHashOnServer, BackupStoreFilenameClear *pLeafname)
{
// Make a connection to the server
- BackupProtocolClient &connection(GetConnection());
+ BackupProtocolCallable &connection(GetConnection());
// Request filenames from the server, in a "safe" manner to ignore errors properly
{
diff --git a/bin/bbackupd/BackupClientContext.h b/bin/bbackupd/BackupClientContext.h
index a1b5d824..04af1645 100644
--- a/bin/bbackupd/BackupClientContext.h
+++ b/bin/bbackupd/BackupClientContext.h
@@ -58,7 +58,7 @@ private:
BackupClientContext(const BackupClientContext &);
public:
- BackupProtocolClient &GetConnection();
+ virtual BackupProtocolCallable &GetConnection();
void CloseAnyOpenConnection();
int GetTimeout() const;
BackupClientDeleteList &GetDeleteList();
@@ -223,7 +223,7 @@ private:
std::string mHostname;
int mPort;
uint32_t mAccountNumber;
- std::auto_ptr<BackupProtocolClient> mapConnection;
+ std::auto_ptr<BackupProtocolCallable> mapConnection;
bool mExtendedLogging;
bool mExtendedLogToFile;
std::string mExtendedLogFile;
diff --git a/bin/bbackupd/BackupClientDeleteList.cpp b/bin/bbackupd/BackupClientDeleteList.cpp
index c0414b78..ce5e6264 100644
--- a/bin/bbackupd/BackupClientDeleteList.cpp
+++ b/bin/bbackupd/BackupClientDeleteList.cpp
@@ -132,7 +132,7 @@ void BackupClientDeleteList::PerformDeletions(BackupClientContext &rContext)
}
// Get a connection
- BackupProtocolClient &connection(rContext.GetConnection());
+ BackupProtocolCallable &connection(rContext.GetConnection());
// Do the deletes
for(std::vector<DirToDelete>::iterator i(mDirectoryList.begin());
diff --git a/bin/bbackupd/BackupClientDirectoryRecord.cpp b/bin/bbackupd/BackupClientDirectoryRecord.cpp
index 292330ab..58cf0ebb 100644
--- a/bin/bbackupd/BackupClientDirectoryRecord.cpp
+++ b/bin/bbackupd/BackupClientDirectoryRecord.cpp
@@ -711,7 +711,7 @@ void BackupClientDirectoryRecord::UpdateAttributes(BackupClientDirectoryRecord::
if(updateAttr)
{
// Get connection to store
- BackupProtocolClient &connection(rParams.mrContext.GetConnection());
+ BackupProtocolCallable &connection(rParams.mrContext.GetConnection());
// Exception thrown if this doesn't work
std::auto_ptr<IOStream> attrStream(new MemBlockStream(attr));
@@ -898,7 +898,7 @@ bool BackupClientDirectoryRecord::UpdateItems(
// Therefore we can safely rename it to this new file.
// Get the connection to the server
- BackupProtocolClient &connection(rContext.GetConnection());
+ BackupProtocolCallable &connection(rContext.GetConnection());
// Only do this step if there is room on the server.
// This step will be repeated later when there is space available
@@ -1169,7 +1169,7 @@ bool BackupClientDirectoryRecord::UpdateItems(
// been downloaded, and the entry will be available.
// Get connection
- BackupProtocolClient &connection(rContext.GetConnection());
+ BackupProtocolCallable &connection(rContext.GetConnection());
// Only do this step if there is room on the server.
// This step will be repeated later when there is
@@ -1327,7 +1327,7 @@ bool BackupClientDirectoryRecord::UpdateItems(
{
// Entry exists, but is not a directory. Bad.
// Get rid of it.
- BackupProtocolClient &connection(rContext.GetConnection());
+ BackupProtocolCallable &connection(rContext.GetConnection());
connection.QueryDeleteFile(mObjectID /* in directory */, storeFilename);
std::string filenameClear = DecryptFilename(en,
@@ -1577,7 +1577,7 @@ int64_t BackupClientDirectoryRecord::CreateRemoteDir(const std::string& localDir
}
// Get connection
- BackupProtocolClient &connection(rParams.mrContext.GetConnection());
+ BackupProtocolCallable &connection(rParams.mrContext.GetConnection());
// Don't do a check for storage limit exceeded here, because if we get to this
// stage, a connection will have been opened, and the status known, so the check
@@ -1668,7 +1668,7 @@ void BackupClientDirectoryRecord::RemoveDirectoryInPlaceOfFile(
const std::string &rFilename)
{
// First, delete the directory
- BackupProtocolClient &connection(rParams.mrContext.GetConnection());
+ BackupProtocolCallable &connection(rParams.mrContext.GetConnection());
connection.QueryDeleteDirectory(pEntry->GetObjectID());
BackupStoreFilenameClear clear(pEntry->GetName());
@@ -1720,7 +1720,7 @@ int64_t BackupClientDirectoryRecord::UploadFile(
ProgressNotifier& rNotifier(rContext.GetProgressNotifier());
// Get the connection
- BackupProtocolClient &connection(rContext.GetConnection());
+ BackupProtocolCallable &connection(rContext.GetConnection());
// Info
int64_t objID = 0;
diff --git a/bin/bbackupquery/BackupQueries.cpp b/bin/bbackupquery/BackupQueries.cpp
index 7bd2e367..bcb1827e 100644
--- a/bin/bbackupquery/BackupQueries.cpp
+++ b/bin/bbackupquery/BackupQueries.cpp
@@ -72,7 +72,7 @@
// Created: 2003/10/10
//
// --------------------------------------------------------------------------
-BackupQueries::BackupQueries(BackupProtocolClient &rConnection,
+BackupQueries::BackupQueries(BackupProtocolCallable &rConnection,
const Configuration &rConfiguration, bool readWrite)
: mReadWrite(readWrite),
mrConnection(rConnection),
diff --git a/bin/bbackupquery/BackupQueries.h b/bin/bbackupquery/BackupQueries.h
index bad1a39c..96df34f5 100644
--- a/bin/bbackupquery/BackupQueries.h
+++ b/bin/bbackupquery/BackupQueries.h
@@ -18,7 +18,7 @@
#include "BoxBackupCompareParams.h"
#include "BackupStoreDirectory.h"
-class BackupProtocolClient;
+class BackupProtocolCallable;
class Configuration;
class ExcludeList;
@@ -55,7 +55,7 @@ struct QueryCommandSpecification;
class BackupQueries
{
public:
- BackupQueries(BackupProtocolClient &rConnection,
+ BackupQueries(BackupProtocolCallable &rConnection,
const Configuration &rConfiguration,
bool readWrite);
~BackupQueries();
@@ -396,7 +396,7 @@ private:
private:
bool mReadWrite;
- BackupProtocolClient &mrConnection;
+ BackupProtocolCallable &mrConnection;
const Configuration &mrConfiguration;
bool mQuitNow;
std::vector<std::pair<std::string, int64_t> > mDirStack;
@@ -407,14 +407,14 @@ private:
typedef std::vector<std::string> (*CompletionHandler)
(BackupQueries::ParsedCommand& rCommand, const std::string& prefix,
- BackupProtocolClient& rProtocol, const Configuration& rConfig,
+ BackupProtocolCallable& rProtocol, const Configuration& rConfig,
BackupQueries& rQueries);
std::vector<std::string> CompleteCommand(BackupQueries::ParsedCommand& rCommand,
- const std::string& prefix, BackupProtocolClient& rProtocol,
+ const std::string& prefix, BackupProtocolCallable& rProtocol,
const Configuration& rConfig, BackupQueries& rQueries);
std::vector<std::string> CompleteOptions(BackupQueries::ParsedCommand& rCommand,
- const std::string& prefix, BackupProtocolClient& rProtocol,
+ const std::string& prefix, BackupProtocolCallable& rProtocol,
const Configuration& rConfig, BackupQueries& rQueries);
#define MAX_COMPLETION_HANDLERS 4
diff --git a/bin/bbackupquery/CommandCompletion.cpp b/bin/bbackupquery/CommandCompletion.cpp
index 2ca26991..5a547ea8 100644
--- a/bin/bbackupquery/CommandCompletion.cpp
+++ b/bin/bbackupquery/CommandCompletion.cpp
@@ -45,7 +45,7 @@
std::vector<std::string> Complete ## name( \
BackupQueries::ParsedCommand& rCommand, \
const std::string& prefix, \
- BackupProtocolClient& rProtocol, const Configuration& rConfig, \
+ BackupProtocolCallable& rProtocol, const Configuration& rConfig, \
BackupQueries& rQueries) \
{ \
std::vector<std::string> completions; \
@@ -170,7 +170,7 @@ int16_t GetExcludeFlags(BackupQueries::ParsedCommand& rCommand)
std::vector<std::string> CompleteRemoteFileOrDirectory(
BackupQueries::ParsedCommand& rCommand,
- const std::string& prefix, BackupProtocolClient& rProtocol,
+ const std::string& prefix, BackupProtocolCallable& rProtocol,
BackupQueries& rQueries, int16_t includeFlags)
{
std::vector<std::string> completions;
diff --git a/lib/server/makeprotocol.pl.in b/lib/server/makeprotocol.pl.in
index ed0f1ee6..348c85d3 100755
--- a/lib/server/makeprotocol.pl.in
+++ b/lib/server/makeprotocol.pl.in
@@ -216,6 +216,7 @@ my $custom_protocol_subclass = $protocol_name."Protocol";
my $client_server_base_class = $protocol_name."ProtocolClientServer";
my $replyable_base_class = $protocol_name."ProtocolReplyable";
my $callable_base_class = $protocol_name."ProtocolCallable";
+my $send_receive_class = $protocol_name."ProtocolSendReceive";
print H <<__E;
class $custom_protocol_subclass;
@@ -241,6 +242,12 @@ class $request_base_class
{
};
+class $send_receive_class {
+public:
+ virtual void Send(const $message_base_class &rObject) = 0;
+ virtual std::auto_ptr<$message_base_class> Receive() = 0;
+};
+
class $custom_protocol_subclass : public Protocol
{
public:
@@ -740,7 +747,8 @@ __E
# the callable protocol interface (implemented by Client and Local classes)
# with Query methods that don't take a context parameter
print H <<__E;
-class $callable_base_class : public virtual $client_server_base_class
+class $callable_base_class : public virtual $client_server_base_class,
+ public $send_receive_class
{
public:
virtual int GetTimeout() = 0;
@@ -837,15 +845,13 @@ __E
$server_or_client_class($context_class &rContext);
__E
}
- else
- {
- print H <<__E;
+
+ print H <<__E;
$server_or_client_class(std::auto_ptr<SocketStream> apConn);
std::auto_ptr<$message_base_class> Receive();
void Send(const $message_base_class &rObject);
__E
- }
-
+
if($writing_server)
{
# need to put in the conversation function
@@ -877,6 +883,7 @@ __E
print H <<__E;
private:
$context_class &mrContext;
+ std::auto_ptr<$message_base_class> mapLastReply;
public:
virtual std::auto_ptr<IOStream> ReceiveStream()
{
@@ -971,7 +978,20 @@ $server_or_client_class\::~$server_or_client_class()
__E
# write receive and send functions
- if(not $writing_local)
+ if($writing_local)
+ {
+ print CPP <<__E;
+std::auto_ptr<$message_base_class> $server_or_client_class\::Receive()
+{
+ return mapLastReply;
+}
+void $server_or_client_class\::Send(const $message_base_class &rObject)
+{
+ mapLastReply = rObject.DoCommand(*this, mrContext);
+}
+__E
+ }
+ else
{
print CPP <<__E;
std::auto_ptr<$message_base_class> $server_or_client_class\::Receive()
diff --git a/test/bbackupd/testbbackupd.cpp b/test/bbackupd/testbbackupd.cpp
index a6d0da75..12b22856 100644
--- a/test/bbackupd/testbbackupd.cpp
+++ b/test/bbackupd/testbbackupd.cpp
@@ -1096,7 +1096,7 @@ int test_bbackupd()
printf("\n==== Testing that ReadDirectory on nonexistent directory "
"does not crash\n");
{
- std::auto_ptr<BackupProtocolClient> client = ConnectAndLogin(
+ std::auto_ptr<BackupProtocolCallable> client = connect_and_login(
context, 0 /* read-write */);
{
@@ -1113,8 +1113,8 @@ int test_bbackupd()
printf("\n==== Testing that GetObject on nonexistent file outputs the "
"correct error message\n");
{
- std::auto_ptr<BackupProtocolClient> connection = ConnectAndLogin(
- context, 0 /* read-write */);
+ std::auto_ptr<BackupProtocolCallable> connection =
+ connect_and_login(context, 0 /* read-write */);
std::string errs;
std::auto_ptr<Configuration> config(
Configuration::LoadAndVerify
@@ -1520,8 +1520,8 @@ int test_bbackupd()
int expected_blocks_old = 6;
#endif
- std::auto_ptr<BackupProtocolClient> client =
- ConnectAndLogin(context, 0 /* read-write */);
+ std::auto_ptr<BackupProtocolCallable> client =
+ connect_and_login(context, 0 /* read-write */);
TEST_THAT(check_num_files(5, expected_num_old, 0, 9));
TEST_THAT(check_num_blocks(*client, 10, expected_blocks_old,
0, 18, 28 + expected_blocks_old));
@@ -2188,9 +2188,9 @@ int test_bbackupd()
TEST_THAT(!TestFileExists("testfiles/notifyran.backup-finish.2"));
// Did it actually get created? Should not have been!
- std::auto_ptr<BackupProtocolClient> client =
- ConnectAndLogin(context,
- BackupProtocolLogin::Flags_ReadOnly);
+ std::auto_ptr<BackupProtocolCallable> client =
+ connect_and_login(context,
+ BackupProtocolLogin::Flags_ReadOnly);
std::auto_ptr<BackupStoreDirectory> dir =
ReadDirectory(*client);
@@ -2218,9 +2218,9 @@ int test_bbackupd()
// BLOCK
{
- std::auto_ptr<BackupProtocolClient> client =
- ConnectAndLogin(context,
- BackupProtocolLogin::Flags_ReadOnly);
+ std::auto_ptr<BackupProtocolCallable> client =
+ connect_and_login(context,
+ BackupProtocolLogin::Flags_ReadOnly);
std::auto_ptr<BackupStoreDirectory> dir =
ReadDirectory(*client,
@@ -2260,10 +2260,10 @@ int test_bbackupd()
// not yet! should still be there
{
- std::auto_ptr<BackupProtocolClient> client =
- ConnectAndLogin(context,
- BackupProtocolLogin::Flags_ReadOnly);
-
+ std::auto_ptr<BackupProtocolCallable> client =
+ connect_and_login(context,
+ BackupProtocolLogin::Flags_ReadOnly);
+
std::auto_ptr<BackupStoreDirectory> dir =
ReadDirectory(*client);
int64_t testDirId = SearchDir(*dir, "Test2");
@@ -2277,10 +2277,10 @@ int test_bbackupd()
// NOW it should be gone
{
- std::auto_ptr<BackupProtocolClient> client =
- ConnectAndLogin(context,
- BackupProtocolLogin::Flags_ReadOnly);
-
+ std::auto_ptr<BackupProtocolCallable> client =
+ connect_and_login(context,
+ BackupProtocolLogin::Flags_ReadOnly);
+
std::auto_ptr<BackupStoreDirectory> root_dir =
ReadDirectory(*client);
@@ -3738,9 +3738,9 @@ int test_bbackupd()
printf("\n==== Resume restore\n");
- std::auto_ptr<BackupProtocolClient> client =
- ConnectAndLogin(context,
- BackupProtocolLogin::Flags_ReadOnly);
+ std::auto_ptr<BackupProtocolCallable> client =
+ connect_and_login(context,
+ BackupProtocolLogin::Flags_ReadOnly);
// Check that the restore fn returns resume possible,
// rather than doing anything