You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-07 00:35:37 +02:00
Improve protocol handlers.
Make protocol handlers have one function per command. This allows the logic of finding the handler to be in ProtocolServer, isolates each command to a function, and removes the need to test the "not found" condition for each handler.
This commit is contained in:
@ -129,6 +129,14 @@
|
||||
</release-improvement-list>
|
||||
|
||||
<release-development-list>
|
||||
<release-item>
|
||||
<release-item-contributor-list>
|
||||
<release-item-reviewer id="cynthia.shang"/>
|
||||
</release-item-contributor-list>
|
||||
|
||||
<p>Improve protocol handlers.</p>
|
||||
</release-item>
|
||||
|
||||
<release-item>
|
||||
<release-item-contributor-list>
|
||||
<release-item-reviewer id="cynthia.shang"/>
|
||||
|
@ -828,7 +828,7 @@ static ProtocolParallelJob *archiveGetAsyncCallback(void *data, unsigned int cli
|
||||
const ArchiveFileMap *archiveFileMap = lstGet(jobData->archiveFileMapList, jobData->archiveFileIdx);
|
||||
jobData->archiveFileIdx++;
|
||||
|
||||
ProtocolCommand *command = protocolCommandNew(PROTOCOL_COMMAND_ARCHIVE_GET_STR);
|
||||
ProtocolCommand *command = protocolCommandNew(PROTOCOL_COMMAND_ARCHIVE_GET_FILE_STR);
|
||||
protocolCommandParamAdd(command, VARSTR(archiveFileMap->request));
|
||||
|
||||
// Add actual files to get
|
||||
|
@ -16,26 +16,21 @@ Archive Get Protocol Handler
|
||||
/***********************************************************************************************************************************
|
||||
Constants
|
||||
***********************************************************************************************************************************/
|
||||
STRING_EXTERN(PROTOCOL_COMMAND_ARCHIVE_GET_STR, PROTOCOL_COMMAND_ARCHIVE_GET);
|
||||
STRING_EXTERN(PROTOCOL_COMMAND_ARCHIVE_GET_FILE_STR, PROTOCOL_COMMAND_ARCHIVE_GET_FILE);
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
bool
|
||||
archiveGetProtocol(const String *command, const VariantList *paramList, ProtocolServer *server)
|
||||
void
|
||||
archiveGetFileProtocol(const VariantList *paramList, ProtocolServer *server)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STRING, command);
|
||||
FUNCTION_LOG_PARAM(VARIANT_LIST, paramList);
|
||||
FUNCTION_LOG_PARAM(PROTOCOL_SERVER, server);
|
||||
FUNCTION_LOG_END();
|
||||
|
||||
ASSERT(command != NULL);
|
||||
|
||||
// Attempt to satisfy the request -- we may get requests that are meant for other handlers
|
||||
bool found = true;
|
||||
ASSERT(paramList != NULL);
|
||||
ASSERT(server != NULL);
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
if (strEq(command, PROTOCOL_COMMAND_ARCHIVE_GET_STR))
|
||||
{
|
||||
const String *request = varStr(varLstGet(paramList, 0));
|
||||
|
||||
@ -74,10 +69,7 @@ archiveGetProtocol(const String *command, const VariantList *paramList, Protocol
|
||||
|
||||
protocolServerResponse(server, varNewVarLst(result));
|
||||
}
|
||||
else
|
||||
found = false;
|
||||
}
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
FUNCTION_LOG_RETURN(BOOL, found);
|
||||
FUNCTION_LOG_RETURN_VOID();
|
||||
}
|
||||
|
@ -11,13 +11,19 @@ Archive Get Protocol Handler
|
||||
/***********************************************************************************************************************************
|
||||
Constants
|
||||
***********************************************************************************************************************************/
|
||||
#define PROTOCOL_COMMAND_ARCHIVE_GET "archiveGet"
|
||||
STRING_DECLARE(PROTOCOL_COMMAND_ARCHIVE_GET_STR);
|
||||
#define PROTOCOL_COMMAND_ARCHIVE_GET_FILE "archiveGetFile"
|
||||
STRING_DECLARE(PROTOCOL_COMMAND_ARCHIVE_GET_FILE_STR);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Functions
|
||||
***********************************************************************************************************************************/
|
||||
// Process protocol requests
|
||||
bool archiveGetProtocol(const String *command, const VariantList *paramList, ProtocolServer *server);
|
||||
void archiveGetFileProtocol(const VariantList *paramList, ProtocolServer *server);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Protocol commands for ProtocolServerHandler arrays passed to protocolServerProcess()
|
||||
***********************************************************************************************************************************/
|
||||
#define PROTOCOL_SERVER_HANDLER_ARCHIVE_GET_LIST \
|
||||
{.command = PROTOCOL_COMMAND_ARCHIVE_GET_FILE, .handler = archiveGetFileProtocol},
|
||||
|
||||
#endif
|
||||
|
@ -15,26 +15,21 @@ Archive Push Protocol Handler
|
||||
/***********************************************************************************************************************************
|
||||
Constants
|
||||
***********************************************************************************************************************************/
|
||||
STRING_EXTERN(PROTOCOL_COMMAND_ARCHIVE_PUSH_STR, PROTOCOL_COMMAND_ARCHIVE_PUSH);
|
||||
STRING_EXTERN(PROTOCOL_COMMAND_ARCHIVE_PUSH_FILE_STR, PROTOCOL_COMMAND_ARCHIVE_PUSH_FILE);
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
bool
|
||||
archivePushProtocol(const String *command, const VariantList *paramList, ProtocolServer *server)
|
||||
void
|
||||
archivePushFileProtocol(const VariantList *paramList, ProtocolServer *server)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STRING, command);
|
||||
FUNCTION_LOG_PARAM(VARIANT_LIST, paramList);
|
||||
FUNCTION_LOG_PARAM(PROTOCOL_SERVER, server);
|
||||
FUNCTION_LOG_END();
|
||||
|
||||
ASSERT(command != NULL);
|
||||
|
||||
// Attempt to satisfy the request -- we may get requests that are meant for other handlers
|
||||
bool found = true;
|
||||
ASSERT(paramList != NULL);
|
||||
ASSERT(server != NULL);
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
if (strEq(command, PROTOCOL_COMMAND_ARCHIVE_PUSH_STR))
|
||||
{
|
||||
const unsigned int paramFixed = 6; // Fixed params before the repo param array
|
||||
const unsigned int paramRepo = 3; // Parameters in each index of the repo array
|
||||
@ -65,10 +60,7 @@ archivePushProtocol(const String *command, const VariantList *paramList, Protoco
|
||||
|
||||
protocolServerResponse(server, varNewVarLst(result));
|
||||
}
|
||||
else
|
||||
found = false;
|
||||
}
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
FUNCTION_LOG_RETURN(BOOL, found);
|
||||
FUNCTION_LOG_RETURN_VOID();
|
||||
}
|
||||
|
@ -11,13 +11,19 @@ Archive Push Protocol Handler
|
||||
/***********************************************************************************************************************************
|
||||
Constants
|
||||
***********************************************************************************************************************************/
|
||||
#define PROTOCOL_COMMAND_ARCHIVE_PUSH "archivePush"
|
||||
STRING_DECLARE(PROTOCOL_COMMAND_ARCHIVE_PUSH_STR);
|
||||
#define PROTOCOL_COMMAND_ARCHIVE_PUSH_FILE "archivePushFile"
|
||||
STRING_DECLARE(PROTOCOL_COMMAND_ARCHIVE_PUSH_FILE_STR);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Functions
|
||||
***********************************************************************************************************************************/
|
||||
// Process protocol requests
|
||||
bool archivePushProtocol(const String *command, const VariantList *paramList, ProtocolServer *server);
|
||||
void archivePushFileProtocol(const VariantList *paramList, ProtocolServer *server);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Protocol commands for ProtocolServerHandler arrays passed to protocolServerProcess()
|
||||
***********************************************************************************************************************************/
|
||||
#define PROTOCOL_SERVER_HANDLER_ARCHIVE_PUSH_LIST \
|
||||
{.command = PROTOCOL_COMMAND_ARCHIVE_PUSH_FILE, .handler = archivePushFileProtocol},
|
||||
|
||||
#endif
|
||||
|
@ -425,7 +425,7 @@ archivePushAsyncCallback(void *data, unsigned int clientIdx)
|
||||
const String *walFile = strLstGet(jobData->walFileList, jobData->walFileIdx);
|
||||
jobData->walFileIdx++;
|
||||
|
||||
ProtocolCommand *command = protocolCommandNew(PROTOCOL_COMMAND_ARCHIVE_PUSH_STR);
|
||||
ProtocolCommand *command = protocolCommandNew(PROTOCOL_COMMAND_ARCHIVE_PUSH_FILE_STR);
|
||||
protocolCommandParamAdd(command, VARSTR(strNewFmt("%s/%s", strZ(jobData->walPath), strZ(walFile))));
|
||||
protocolCommandParamAdd(command, VARUINT(jobData->archiveInfo.pgVersion));
|
||||
protocolCommandParamAdd(command, VARUINT64(jobData->archiveInfo.pgSystemId));
|
||||
|
@ -18,23 +18,18 @@ Constants
|
||||
STRING_EXTERN(PROTOCOL_COMMAND_BACKUP_FILE_STR, PROTOCOL_COMMAND_BACKUP_FILE);
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
bool
|
||||
backupProtocol(const String *command, const VariantList *paramList, ProtocolServer *server)
|
||||
void
|
||||
backupFileProtocol(const VariantList *paramList, ProtocolServer *server)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STRING, command);
|
||||
FUNCTION_LOG_PARAM(VARIANT_LIST, paramList);
|
||||
FUNCTION_LOG_PARAM(PROTOCOL_SERVER, server);
|
||||
FUNCTION_LOG_END();
|
||||
|
||||
ASSERT(command != NULL);
|
||||
|
||||
// Attempt to satisfy the request -- we may get requests that are meant for other handlers
|
||||
bool found = true;
|
||||
ASSERT(paramList != NULL);
|
||||
ASSERT(server != NULL);
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
if (strEq(command, PROTOCOL_COMMAND_BACKUP_FILE_STR))
|
||||
{
|
||||
// Backup the file
|
||||
BackupFileResult result = backupFile(
|
||||
@ -55,10 +50,7 @@ backupProtocol(const String *command, const VariantList *paramList, ProtocolServ
|
||||
|
||||
protocolServerResponse(server, varNewVarLst(resultList));
|
||||
}
|
||||
else
|
||||
found = false;
|
||||
}
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
FUNCTION_LOG_RETURN(BOOL, found);
|
||||
FUNCTION_LOG_RETURN_VOID();
|
||||
}
|
||||
|
@ -18,6 +18,12 @@ Constants
|
||||
Functions
|
||||
***********************************************************************************************************************************/
|
||||
// Process protocol requests
|
||||
bool backupProtocol(const String *command, const VariantList *paramList, ProtocolServer *server);
|
||||
void backupFileProtocol(const VariantList *paramList, ProtocolServer *server);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Protocol commands for ProtocolServerHandler arrays passed to protocolServerProcess()
|
||||
***********************************************************************************************************************************/
|
||||
#define PROTOCOL_SERVER_HANDLER_BACKUP_LIST \
|
||||
{.command = PROTOCOL_COMMAND_BACKUP_FILE, .handler = backupFileProtocol},
|
||||
|
||||
#endif
|
||||
|
@ -17,6 +17,18 @@ Local Command
|
||||
#include "protocol/helper.h"
|
||||
#include "protocol/server.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Command handlers
|
||||
***********************************************************************************************************************************/
|
||||
static const ProtocolServerHandler commandLocalHandlerList[] =
|
||||
{
|
||||
PROTOCOL_SERVER_HANDLER_ARCHIVE_GET_LIST
|
||||
PROTOCOL_SERVER_HANDLER_ARCHIVE_PUSH_LIST
|
||||
PROTOCOL_SERVER_HANDLER_BACKUP_LIST
|
||||
PROTOCOL_SERVER_HANDLER_RESTORE_LIST
|
||||
PROTOCOL_SERVER_HANDLER_VERIFY_LIST
|
||||
};
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
void
|
||||
cmdLocal(int fdRead, int fdWrite)
|
||||
@ -32,12 +44,8 @@ cmdLocal(int fdRead, int fdWrite)
|
||||
ioWriteOpen(write);
|
||||
|
||||
ProtocolServer *server = protocolServerNew(name, PROTOCOL_SERVICE_LOCAL_STR, read, write);
|
||||
protocolServerHandlerAdd(server, archiveGetProtocol);
|
||||
protocolServerHandlerAdd(server, archivePushProtocol);
|
||||
protocolServerHandlerAdd(server, backupProtocol);
|
||||
protocolServerHandlerAdd(server, restoreProtocol);
|
||||
protocolServerHandlerAdd(server, verifyProtocol);
|
||||
protocolServerProcess(server, cfgCommandJobRetry());
|
||||
protocolServerProcess(
|
||||
server, cfgCommandJobRetry(), commandLocalHandlerList, PROTOCOL_SERVER_HANDLER_LIST_SIZE(commandLocalHandlerList));
|
||||
}
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
|
@ -17,6 +17,16 @@ Remote Command
|
||||
#include "protocol/server.h"
|
||||
#include "storage/remote/protocol.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Command handlers
|
||||
***********************************************************************************************************************************/
|
||||
static const ProtocolServerHandler commandRemoteHandlerList[] =
|
||||
{
|
||||
PROTOCOL_SERVER_HANDLER_DB_LIST
|
||||
PROTOCOL_SERVER_HANDLER_OPTION_LIST
|
||||
PROTOCOL_SERVER_HANDLER_STORAGE_REMOTE_LIST
|
||||
};
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
void
|
||||
cmdRemote(int fdRead, int fdWrite)
|
||||
@ -32,9 +42,6 @@ cmdRemote(int fdRead, int fdWrite)
|
||||
ioWriteOpen(write);
|
||||
|
||||
ProtocolServer *server = protocolServerNew(name, PROTOCOL_SERVICE_REMOTE_STR, read, write);
|
||||
protocolServerHandlerAdd(server, storageRemoteProtocol);
|
||||
protocolServerHandlerAdd(server, dbProtocol);
|
||||
protocolServerHandlerAdd(server, configProtocol);
|
||||
|
||||
// Acquire a lock if this command needs one. We'll use the noop that is always sent from the client right after the
|
||||
// handshake to return an error. We can't take a lock earlier than this because we want the error to go back through the
|
||||
@ -74,7 +81,10 @@ cmdRemote(int fdRead, int fdWrite)
|
||||
|
||||
// If not successful we'll just exit
|
||||
if (success)
|
||||
protocolServerProcess(server, NULL);
|
||||
{
|
||||
protocolServerProcess(
|
||||
server, NULL, commandRemoteHandlerList, PROTOCOL_SERVER_HANDLER_LIST_SIZE(commandRemoteHandlerList));
|
||||
}
|
||||
}
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
|
@ -18,23 +18,18 @@ Constants
|
||||
STRING_EXTERN(PROTOCOL_COMMAND_RESTORE_FILE_STR, PROTOCOL_COMMAND_RESTORE_FILE);
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
bool
|
||||
restoreProtocol(const String *command, const VariantList *paramList, ProtocolServer *server)
|
||||
void
|
||||
restoreFileProtocol(const VariantList *paramList, ProtocolServer *server)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STRING, command);
|
||||
FUNCTION_LOG_PARAM(VARIANT_LIST, paramList);
|
||||
FUNCTION_LOG_PARAM(PROTOCOL_SERVER, server);
|
||||
FUNCTION_LOG_END();
|
||||
|
||||
ASSERT(command != NULL);
|
||||
|
||||
// Attempt to satisfy the request -- we may get requests that are meant for other handlers
|
||||
bool found = true;
|
||||
ASSERT(paramList != NULL);
|
||||
ASSERT(server != NULL);
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
if (strEq(command, PROTOCOL_COMMAND_RESTORE_FILE_STR))
|
||||
{
|
||||
protocolServerResponse(
|
||||
server,
|
||||
@ -49,10 +44,7 @@ restoreProtocol(const String *command, const VariantList *paramList, ProtocolSer
|
||||
(time_t)varInt64Force(varLstGet(paramList, 12)), varBoolForce(varLstGet(paramList, 13)),
|
||||
varBoolForce(varLstGet(paramList, 14)), varStr(varLstGet(paramList, 15)))));
|
||||
}
|
||||
else
|
||||
found = false;
|
||||
}
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
FUNCTION_LOG_RETURN(BOOL, found);
|
||||
FUNCTION_LOG_RETURN_VOID();
|
||||
}
|
||||
|
@ -18,6 +18,12 @@ Constants
|
||||
Functions
|
||||
***********************************************************************************************************************************/
|
||||
// Process protocol requests
|
||||
bool restoreProtocol(const String *command, const VariantList *paramList, ProtocolServer *server);
|
||||
void restoreFileProtocol(const VariantList *paramList, ProtocolServer *server);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Protocol commands for ProtocolServerHandler arrays passed to protocolServerProcess()
|
||||
***********************************************************************************************************************************/
|
||||
#define PROTOCOL_SERVER_HANDLER_RESTORE_LIST \
|
||||
{.command = PROTOCOL_COMMAND_RESTORE_FILE, .handler = restoreFileProtocol},
|
||||
|
||||
#endif
|
||||
|
@ -18,24 +18,18 @@ Constants
|
||||
STRING_EXTERN(PROTOCOL_COMMAND_VERIFY_FILE_STR, PROTOCOL_COMMAND_VERIFY_FILE);
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
bool
|
||||
verifyProtocol(const String *command, const VariantList *paramList, ProtocolServer *server)
|
||||
void
|
||||
verifyFileProtocol(const VariantList *paramList, ProtocolServer *server)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STRING, command);
|
||||
FUNCTION_LOG_PARAM(VARIANT_LIST, paramList);
|
||||
FUNCTION_LOG_PARAM(PROTOCOL_SERVER, server);
|
||||
FUNCTION_LOG_END();
|
||||
|
||||
ASSERT(command != NULL);
|
||||
|
||||
// Attempt to satisfy the request -- we may get requests that are meant for other handlers
|
||||
bool found = true;
|
||||
ASSERT(paramList != NULL);
|
||||
ASSERT(server != NULL);
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
// Process any commands received that are for this handler
|
||||
if (strEq(command, PROTOCOL_COMMAND_VERIFY_FILE_STR))
|
||||
{
|
||||
VerifyResult result = verifyFile(
|
||||
varStr(varLstGet(paramList, 0)), // Full filename
|
||||
@ -45,10 +39,7 @@ verifyProtocol(const String *command, const VariantList *paramList, ProtocolServ
|
||||
|
||||
protocolServerResponse(server, VARUINT(result));
|
||||
}
|
||||
else
|
||||
found = false;
|
||||
}
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
FUNCTION_LOG_RETURN(BOOL, found);
|
||||
FUNCTION_LOG_RETURN_VOID();
|
||||
}
|
||||
|
@ -18,6 +18,12 @@ Constants
|
||||
Functions
|
||||
***********************************************************************************************************************************/
|
||||
// Process protocol requests
|
||||
bool verifyProtocol(const String *command, const VariantList *paramList, ProtocolServer *server);
|
||||
void verifyFileProtocol(const VariantList *paramList, ProtocolServer *server);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Protocol commands for ProtocolServerHandler arrays passed to protocolServerProcess()
|
||||
***********************************************************************************************************************************/
|
||||
#define PROTOCOL_SERVER_HANDLER_VERIFY_LIST \
|
||||
{.command = PROTOCOL_COMMAND_VERIFY_FILE, .handler = verifyFileProtocol},
|
||||
|
||||
#endif
|
||||
|
@ -17,23 +17,18 @@ Constants
|
||||
STRING_EXTERN(PROTOCOL_COMMAND_CONFIG_OPTION_STR, PROTOCOL_COMMAND_CONFIG_OPTION);
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
bool
|
||||
configProtocol(const String *command, const VariantList *paramList, ProtocolServer *server)
|
||||
void
|
||||
configOptionProtocol(const VariantList *paramList, ProtocolServer *server)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STRING, command);
|
||||
FUNCTION_LOG_PARAM(VARIANT_LIST, paramList);
|
||||
FUNCTION_LOG_PARAM(PROTOCOL_SERVER, server);
|
||||
FUNCTION_LOG_END();
|
||||
|
||||
ASSERT(command != NULL);
|
||||
|
||||
// Attempt to satisfy the request -- we may get requests that are meant for other handlers
|
||||
bool found = true;
|
||||
ASSERT(paramList != NULL);
|
||||
ASSERT(server != NULL);
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
if (strEq(command, PROTOCOL_COMMAND_CONFIG_OPTION_STR))
|
||||
{
|
||||
VariantList *optionList = varLstNew();
|
||||
|
||||
@ -47,17 +42,14 @@ configProtocol(const String *command, const VariantList *paramList, ProtocolServ
|
||||
|
||||
protocolServerResponse(server, varNewVarLst(optionList));
|
||||
}
|
||||
else
|
||||
found = false;
|
||||
}
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
FUNCTION_LOG_RETURN(BOOL, found);
|
||||
FUNCTION_LOG_RETURN_VOID();
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
VariantList *
|
||||
configProtocolOption(ProtocolClient *client, const VariantList *paramList)
|
||||
configOptionRemote(ProtocolClient *client, const VariantList *paramList)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelTrace);
|
||||
FUNCTION_LOG_PARAM(PROTOCOL_CLIENT, client);
|
||||
|
@ -19,9 +19,15 @@ Constants
|
||||
Functions
|
||||
***********************************************************************************************************************************/
|
||||
// Process config protocol requests
|
||||
bool configProtocol(const String *command, const VariantList *paramList, ProtocolServer *server);
|
||||
void configOptionProtocol(const VariantList *paramList, ProtocolServer *server);
|
||||
|
||||
// Get option values from another process
|
||||
VariantList *configProtocolOption(ProtocolClient *client, const VariantList *paramList);
|
||||
// Get option values from a remote process
|
||||
VariantList *configOptionRemote(ProtocolClient *client, const VariantList *paramList);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Protocol commands for ProtocolServerHandler arrays passed to protocolServerProcess()
|
||||
***********************************************************************************************************************************/
|
||||
#define PROTOCOL_SERVER_HANDLER_OPTION_LIST \
|
||||
{.command = PROTOCOL_COMMAND_CONFIG_OPTION, .handler = configOptionProtocol},
|
||||
|
||||
#endif
|
||||
|
@ -29,23 +29,18 @@ static struct
|
||||
} dbProtocolLocal;
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
bool
|
||||
dbProtocol(const String *command, const VariantList *paramList, ProtocolServer *server)
|
||||
void
|
||||
dbOpenProtocol(const VariantList *paramList, ProtocolServer *server)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STRING, command);
|
||||
FUNCTION_LOG_PARAM(VARIANT_LIST, paramList);
|
||||
FUNCTION_LOG_PARAM(PROTOCOL_SERVER, server);
|
||||
FUNCTION_LOG_END();
|
||||
|
||||
ASSERT(command != NULL);
|
||||
|
||||
// Attempt to satisfy the request -- we may get requests that are meant for other handlers
|
||||
bool found = true;
|
||||
ASSERT(paramList == NULL);
|
||||
ASSERT(server != NULL);
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
if (strEq(command, PROTOCOL_COMMAND_DB_OPEN_STR))
|
||||
{
|
||||
// If the db list does not exist then create it in the prior context (which should be persistent)
|
||||
if (dbProtocolLocal.pgClientList == NULL)
|
||||
@ -75,22 +70,55 @@ dbProtocol(const String *command, const VariantList *paramList, ProtocolServer *
|
||||
// Return db index which should be included in subsequent calls
|
||||
protocolServerResponse(server, VARUINT(dbIdx));
|
||||
}
|
||||
else if (strEq(command, PROTOCOL_COMMAND_DB_QUERY_STR) || strEq(command, PROTOCOL_COMMAND_DB_CLOSE_STR))
|
||||
{
|
||||
PgClient *pgClient = *(PgClient **)lstGet(dbProtocolLocal.pgClientList, varUIntForce(varLstGet(paramList, 0)));
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
if (strEq(command, PROTOCOL_COMMAND_DB_QUERY_STR))
|
||||
protocolServerResponse(server, varNewVarLst(pgClientQuery(pgClient, varStr(varLstGet(paramList, 1)))));
|
||||
else
|
||||
FUNCTION_LOG_RETURN_VOID();
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
void
|
||||
dbQueryProtocol(const VariantList *paramList, ProtocolServer *server)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(VARIANT_LIST, paramList);
|
||||
FUNCTION_LOG_PARAM(PROTOCOL_SERVER, server);
|
||||
FUNCTION_LOG_END();
|
||||
|
||||
ASSERT(paramList != NULL);
|
||||
ASSERT(server != NULL);
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
pgClientClose(pgClient);
|
||||
protocolServerResponse(server, NULL);
|
||||
}
|
||||
}
|
||||
else
|
||||
found = false;
|
||||
protocolServerResponse(
|
||||
server,
|
||||
varNewVarLst(
|
||||
pgClientQuery(
|
||||
*(PgClient **)lstGet(dbProtocolLocal.pgClientList, varUIntForce(varLstGet(paramList, 0))),
|
||||
varStr(varLstGet(paramList, 1)))));
|
||||
}
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
FUNCTION_LOG_RETURN(BOOL, found);
|
||||
FUNCTION_LOG_RETURN_VOID();
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
void
|
||||
dbCloseProtocol(const VariantList *paramList, ProtocolServer *server)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(VARIANT_LIST, paramList);
|
||||
FUNCTION_LOG_PARAM(PROTOCOL_SERVER, server);
|
||||
FUNCTION_LOG_END();
|
||||
|
||||
ASSERT(paramList != NULL);
|
||||
ASSERT(server != NULL);
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
pgClientClose(*(PgClient **)lstGet(dbProtocolLocal.pgClientList, varUIntForce(varLstGet(paramList, 0))));
|
||||
protocolServerResponse(server, NULL);
|
||||
}
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
FUNCTION_LOG_RETURN_VOID();
|
||||
}
|
||||
|
@ -23,6 +23,16 @@ Constants
|
||||
Functions
|
||||
***********************************************************************************************************************************/
|
||||
// Process db protocol requests
|
||||
bool dbProtocol(const String *command, const VariantList *paramList, ProtocolServer *server);
|
||||
void dbOpenProtocol(const VariantList *paramList, ProtocolServer *server);
|
||||
void dbQueryProtocol(const VariantList *paramList, ProtocolServer *server);
|
||||
void dbCloseProtocol(const VariantList *paramList, ProtocolServer *server);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Protocol commands for ProtocolServerHandler arrays passed to protocolServerProcess()
|
||||
***********************************************************************************************************************************/
|
||||
#define PROTOCOL_SERVER_HANDLER_DB_LIST \
|
||||
{.command = PROTOCOL_COMMAND_DB_OPEN, .handler = dbOpenProtocol}, \
|
||||
{.command = PROTOCOL_COMMAND_DB_QUERY, .handler = dbQueryProtocol}, \
|
||||
{.command = PROTOCOL_COMMAND_DB_CLOSE, .handler = dbCloseProtocol},
|
||||
|
||||
#endif
|
||||
|
@ -502,7 +502,7 @@ protocolRemoteGet(ProtocolStorageType protocolStorageType, unsigned int hostIdx)
|
||||
varLstAdd(param, varNewStrZ(cfgOptionIdxName(cfgOptRepoCipherType, hostIdx)));
|
||||
varLstAdd(param, varNewStrZ(cfgOptionIdxName(cfgOptRepoCipherPass, hostIdx)));
|
||||
|
||||
VariantList *optionList = configProtocolOption(protocolHelperClient->client, param);
|
||||
VariantList *optionList = configOptionRemote(protocolHelperClient->client, param);
|
||||
|
||||
if (!strEq(varStr(varLstGet(optionList, 0)), CIPHER_TYPE_NONE_STR))
|
||||
{
|
||||
|
@ -27,8 +27,6 @@ struct ProtocolServer
|
||||
const String *name;
|
||||
IoRead *read;
|
||||
IoWrite *write;
|
||||
|
||||
List *handlerList;
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_MOVE(PROTOCOL_SERVER);
|
||||
@ -61,7 +59,6 @@ protocolServerNew(const String *name, const String *service, IoRead *read, IoWri
|
||||
.name = strDup(name),
|
||||
.read = read,
|
||||
.write = write,
|
||||
.handlerList = lstNewP(sizeof(ProtocolServerProcessHandler)),
|
||||
};
|
||||
|
||||
// Send the protocol greeting
|
||||
@ -82,20 +79,6 @@ protocolServerNew(const String *name, const String *service, IoRead *read, IoWri
|
||||
FUNCTION_LOG_RETURN(PROTOCOL_SERVER, this);
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
void
|
||||
protocolServerHandlerAdd(ProtocolServer *this, ProtocolServerProcessHandler handler)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelTrace);
|
||||
FUNCTION_LOG_PARAM(PROTOCOL_SERVER, this);
|
||||
FUNCTION_LOG_PARAM(FUNCTIONP, handler);
|
||||
FUNCTION_LOG_END();
|
||||
|
||||
lstAdd(this->handlerList, &handler);
|
||||
|
||||
FUNCTION_LOG_RETURN_VOID();
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
void
|
||||
protocolServerError(ProtocolServer *this, int code, const String *message, const String *stack)
|
||||
@ -125,13 +108,21 @@ protocolServerError(ProtocolServer *this, int code, const String *message, const
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
void
|
||||
protocolServerProcess(ProtocolServer *this, const VariantList *retryInterval)
|
||||
protocolServerProcess(
|
||||
ProtocolServer *this, const VariantList *retryInterval, const ProtocolServerHandler *const handlerList,
|
||||
const unsigned int handlerListSize)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(PROTOCOL_SERVER, this);
|
||||
FUNCTION_LOG_PARAM(VARIANT_LIST, retryInterval);
|
||||
FUNCTION_LOG_PARAM_P(VOID, handlerList);
|
||||
FUNCTION_LOG_PARAM(UINT, handlerListSize);
|
||||
FUNCTION_LOG_END();
|
||||
|
||||
ASSERT(this != NULL);
|
||||
ASSERT(handlerList != NULL);
|
||||
ASSERT(handlerListSize > 0);
|
||||
|
||||
// Loop until exit command is received
|
||||
bool exit = false;
|
||||
|
||||
@ -146,14 +137,21 @@ protocolServerProcess(ProtocolServer *this, const VariantList *retryInterval)
|
||||
const String *command = varStr(kvGet(commandKv, VARSTR(PROTOCOL_KEY_COMMAND_STR)));
|
||||
VariantList *paramList = varVarLst(kvGet(commandKv, VARSTR(PROTOCOL_KEY_PARAMETER_STR)));
|
||||
|
||||
// Process command
|
||||
bool found = false;
|
||||
// Find the handler
|
||||
ProtocolServerCommandHandler handler = NULL;
|
||||
|
||||
for (unsigned int handlerIdx = 0; handlerIdx < lstSize(this->handlerList); handlerIdx++)
|
||||
for (unsigned int handlerIdx = 0; handlerIdx < handlerListSize; handlerIdx++)
|
||||
{
|
||||
// Get the next handler
|
||||
ProtocolServerProcessHandler handler = *(ProtocolServerProcessHandler *)lstGet(this->handlerList, handlerIdx);
|
||||
if (strEqZ(command, handlerList[handlerIdx].command))
|
||||
{
|
||||
handler = handlerList[handlerIdx].handler;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If handler was found then process
|
||||
if (handler != NULL)
|
||||
{
|
||||
// Send the command to the handler. Run the handler in the server's memory context in case any persistent data
|
||||
// needs to be stored by the handler.
|
||||
MEM_CONTEXT_BEGIN(this->memContext)
|
||||
@ -162,13 +160,14 @@ protocolServerProcess(ProtocolServer *this, const VariantList *retryInterval)
|
||||
bool retry = false;
|
||||
unsigned int retryRemaining = retryInterval != NULL ? varLstSize(retryInterval) : 0;
|
||||
|
||||
// Handler retry loop
|
||||
do
|
||||
{
|
||||
retry = false;
|
||||
|
||||
TRY_BEGIN()
|
||||
{
|
||||
found = handler(command, paramList, this);
|
||||
handler(paramList, this);
|
||||
}
|
||||
CATCH_ANY()
|
||||
{
|
||||
@ -204,13 +203,9 @@ protocolServerProcess(ProtocolServer *this, const VariantList *retryInterval)
|
||||
while (retry);
|
||||
}
|
||||
MEM_CONTEXT_END();
|
||||
|
||||
// If the handler processed the command then exit the handler loop
|
||||
if (found)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!found)
|
||||
// Else check built-in commands
|
||||
else
|
||||
{
|
||||
if (strEq(command, PROTOCOL_COMMAND_NOOP_STR))
|
||||
protocolServerResponse(this, NULL);
|
||||
|
@ -16,9 +16,20 @@ typedef struct ProtocolServer ProtocolServer;
|
||||
#include "common/io/write.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Protocol process handler type
|
||||
Protocol command handler type and structure
|
||||
|
||||
An array of this struct must be passed to protocolServerProcess() for the server to process commands. Each command handler should
|
||||
implement a single command, as defined by the command string.
|
||||
***********************************************************************************************************************************/
|
||||
typedef bool (*ProtocolServerProcessHandler)(const String *command, const VariantList *paramList, ProtocolServer *server);
|
||||
typedef void (*ProtocolServerCommandHandler)(const VariantList *paramList, ProtocolServer *server);
|
||||
|
||||
typedef struct ProtocolServerHandler
|
||||
{
|
||||
const char *const command;
|
||||
ProtocolServerCommandHandler handler;
|
||||
} ProtocolServerHandler;
|
||||
|
||||
#define PROTOCOL_SERVER_HANDLER_LIST_SIZE(list) (sizeof(list) / sizeof(ProtocolServerHandler))
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Constructors
|
||||
@ -32,14 +43,13 @@ Functions
|
||||
void protocolServerError(ProtocolServer *this, int code, const String *message, const String *stack);
|
||||
|
||||
// Process requests
|
||||
void protocolServerProcess(ProtocolServer *this, const VariantList *retryInterval);
|
||||
void protocolServerProcess(
|
||||
ProtocolServer *this, const VariantList *retryInterval, const ProtocolServerHandler *const handlerList,
|
||||
const unsigned int handlerListSize);
|
||||
|
||||
// Respond to request with output if provided
|
||||
void protocolServerResponse(ProtocolServer *this, const Variant *output);
|
||||
|
||||
// Add a new handler
|
||||
void protocolServerHandlerAdd(ProtocolServer *this, ProtocolServerProcessHandler handler);
|
||||
|
||||
// Move to a new parent mem context
|
||||
ProtocolServer *protocolServerMove(ProtocolServer *this, MemContext *parentNew);
|
||||
|
||||
|
@ -45,7 +45,7 @@ Local variables
|
||||
static struct
|
||||
{
|
||||
MemContext *memContext; // Mem context
|
||||
RegExp *blockRegExp; // Regular expression to check block messages
|
||||
void *driver; // Storage driver used for requests
|
||||
} storageRemoteProtocolLocal;
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -138,40 +138,68 @@ storageRemoteProtocolInfoListCallback(void *server, const StorageInfo *info)
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
bool
|
||||
storageRemoteProtocol(const String *command, const VariantList *paramList, ProtocolServer *server)
|
||||
void
|
||||
storageRemoteFeatureProtocol(const VariantList *paramList, ProtocolServer *server)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STRING, command);
|
||||
FUNCTION_LOG_PARAM(VARIANT_LIST, paramList);
|
||||
FUNCTION_LOG_PARAM(PROTOCOL_SERVER, server);
|
||||
FUNCTION_LOG_END();
|
||||
|
||||
ASSERT(command != NULL);
|
||||
|
||||
// Determine which storage should be used
|
||||
const Storage *storage = protocolStorageTypeEnum(
|
||||
cfgOptionStr(cfgOptRemoteType)) == protocolStorageTypeRepo ? storageRepoWrite() : storagePgWrite();
|
||||
StorageInterface interface = storageInterface(storage);
|
||||
void *driver = storageDriver(storage);
|
||||
|
||||
// Attempt to satisfy the request -- we may get requests that are meant for other handlers
|
||||
bool found = true;
|
||||
ASSERT(paramList == NULL);
|
||||
ASSERT(server != NULL);
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
if (strEq(command, PROTOCOL_COMMAND_STORAGE_FEATURE_STR))
|
||||
// Get storage based on remote type
|
||||
const Storage *storage =
|
||||
protocolStorageTypeEnum(cfgOptionStr(cfgOptRemoteType)) == protocolStorageTypeRepo ?
|
||||
storageRepoWrite() : storagePgWrite();
|
||||
|
||||
// Store local variables in the server context
|
||||
if (storageRemoteProtocolLocal.memContext == NULL)
|
||||
{
|
||||
MEM_CONTEXT_PRIOR_BEGIN()
|
||||
{
|
||||
MEM_CONTEXT_NEW_BEGIN("StorageRemoteProtocol")
|
||||
{
|
||||
storageRemoteProtocolLocal.memContext = memContextCurrent();
|
||||
storageRemoteProtocolLocal.driver = storageDriver(storage);
|
||||
}
|
||||
MEM_CONTEXT_NEW_END();
|
||||
}
|
||||
MEM_CONTEXT_PRIOR_END();
|
||||
}
|
||||
|
||||
// Return storage features
|
||||
protocolServerWriteLine(server, jsonFromStr(storagePathP(storage, NULL)));
|
||||
protocolServerWriteLine(server, jsonFromUInt64(interface.feature));
|
||||
protocolServerWriteLine(server, jsonFromUInt64(storageInterface(storage).feature));
|
||||
|
||||
protocolServerResponse(server, NULL);
|
||||
}
|
||||
else if (strEq(command, PROTOCOL_COMMAND_STORAGE_INFO_STR))
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
FUNCTION_TEST_RETURN_VOID();
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
void
|
||||
storageRemoteInfoProtocol(const VariantList *paramList, ProtocolServer *server)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(VARIANT_LIST, paramList);
|
||||
FUNCTION_LOG_PARAM(PROTOCOL_SERVER, server);
|
||||
FUNCTION_LOG_END();
|
||||
|
||||
ASSERT(paramList != NULL);
|
||||
ASSERT(server != NULL);
|
||||
ASSERT(storageRemoteProtocolLocal.driver != NULL);
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
StorageInfo info = storageInterfaceInfoP(
|
||||
driver, varStr(varLstGet(paramList, 0)), (StorageInfoLevel)varUIntForce(varLstGet(paramList, 1)),
|
||||
.followLink = varBool(varLstGet(paramList, 2)));
|
||||
storageRemoteProtocolLocal.driver, varStr(varLstGet(paramList, 0)),
|
||||
(StorageInfoLevel)varUIntForce(varLstGet(paramList, 1)), .followLink = varBool(varLstGet(paramList, 2)));
|
||||
|
||||
protocolServerResponse(server, VARBOOL(info.exists));
|
||||
|
||||
@ -181,21 +209,58 @@ storageRemoteProtocol(const String *command, const VariantList *paramList, Proto
|
||||
protocolServerResponse(server, NULL);
|
||||
}
|
||||
}
|
||||
else if (strEq(command, PROTOCOL_COMMAND_STORAGE_INFO_LIST_STR))
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
FUNCTION_TEST_RETURN_VOID();
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
void
|
||||
storageRemoteInfoListProtocol(const VariantList *paramList, ProtocolServer *server)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(VARIANT_LIST, paramList);
|
||||
FUNCTION_LOG_PARAM(PROTOCOL_SERVER, server);
|
||||
FUNCTION_LOG_END();
|
||||
|
||||
ASSERT(paramList != NULL);
|
||||
ASSERT(server != NULL);
|
||||
ASSERT(storageRemoteProtocolLocal.driver != NULL);
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
bool result = storageInterfaceInfoListP(
|
||||
driver, varStr(varLstGet(paramList, 0)), (StorageInfoLevel)varUIntForce(varLstGet(paramList, 1)),
|
||||
storageRemoteProtocolInfoListCallback, server);
|
||||
storageRemoteProtocolLocal.driver, varStr(varLstGet(paramList, 0)),
|
||||
(StorageInfoLevel)varUIntForce(varLstGet(paramList, 1)), storageRemoteProtocolInfoListCallback, server);
|
||||
|
||||
protocolServerWriteLine(server, NULL);
|
||||
protocolServerResponse(server, VARBOOL(result));
|
||||
}
|
||||
else if (strEq(command, PROTOCOL_COMMAND_STORAGE_OPEN_READ_STR))
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
FUNCTION_TEST_RETURN_VOID();
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
void
|
||||
storageRemoteOpenReadProtocol(const VariantList *paramList, ProtocolServer *server)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(VARIANT_LIST, paramList);
|
||||
FUNCTION_LOG_PARAM(PROTOCOL_SERVER, server);
|
||||
FUNCTION_LOG_END();
|
||||
|
||||
ASSERT(paramList != NULL);
|
||||
ASSERT(server != NULL);
|
||||
ASSERT(storageRemoteProtocolLocal.driver != NULL);
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
// Create the read object
|
||||
IoRead *fileRead = storageReadIo(
|
||||
storageInterfaceNewReadP(
|
||||
driver, varStr(varLstGet(paramList, 0)), varBool(varLstGet(paramList, 1)), .limit = varLstGet(paramList, 2)));
|
||||
storageRemoteProtocolLocal.driver, varStr(varLstGet(paramList, 0)), varBool(varLstGet(paramList, 1)),
|
||||
.limit = varLstGet(paramList, 2)));
|
||||
|
||||
// Set filter group based on passed filters
|
||||
storageRemoteFilterGroup(ioReadFilterGroup(fileRead), varLstGet(paramList, 3));
|
||||
@ -235,12 +300,31 @@ storageRemoteProtocol(const String *command, const VariantList *paramList, Proto
|
||||
protocolServerResponse(server, ioFilterGroupResultAll(ioReadFilterGroup(fileRead)));
|
||||
}
|
||||
}
|
||||
else if (strEq(command, PROTOCOL_COMMAND_STORAGE_OPEN_WRITE_STR))
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
FUNCTION_TEST_RETURN_VOID();
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
void
|
||||
storageRemoteOpenWriteProtocol(const VariantList *paramList, ProtocolServer *server)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(VARIANT_LIST, paramList);
|
||||
FUNCTION_LOG_PARAM(PROTOCOL_SERVER, server);
|
||||
FUNCTION_LOG_END();
|
||||
|
||||
ASSERT(paramList != NULL);
|
||||
ASSERT(server != NULL);
|
||||
ASSERT(storageRemoteProtocolLocal.driver != NULL);
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
// Create the write object
|
||||
IoWrite *fileWrite = storageWriteIo(
|
||||
storageInterfaceNewWriteP(
|
||||
driver, varStr(varLstGet(paramList, 0)), .modeFile = (mode_t)varUIntForce(varLstGet(paramList, 1)),
|
||||
storageRemoteProtocolLocal.driver, varStr(varLstGet(paramList, 0)),
|
||||
.modeFile = (mode_t)varUIntForce(varLstGet(paramList, 1)),
|
||||
.modePath = (mode_t)varUIntForce(varLstGet(paramList, 2)), .user = varStr(varLstGet(paramList, 3)),
|
||||
.group = varStr(varLstGet(paramList, 4)), .timeModified = (time_t)varUInt64Force(varLstGet(paramList, 5)),
|
||||
.createPath = varBool(varLstGet(paramList, 6)), .syncFile = varBool(varLstGet(paramList, 7)),
|
||||
@ -296,39 +380,109 @@ storageRemoteProtocol(const String *command, const VariantList *paramList, Proto
|
||||
}
|
||||
}
|
||||
while (remaining > 0);
|
||||
|
||||
}
|
||||
else if (strEq(command, PROTOCOL_COMMAND_STORAGE_PATH_CREATE_STR))
|
||||
{
|
||||
storageInterfacePathCreateP(
|
||||
driver, varStr(varLstGet(paramList, 0)), varBool(varLstGet(paramList, 1)), varBool(varLstGet(paramList, 2)),
|
||||
(mode_t)varUIntForce(varLstGet(paramList, 3)));
|
||||
|
||||
protocolServerResponse(server, NULL);
|
||||
}
|
||||
else if (strEq(command, PROTOCOL_COMMAND_STORAGE_PATH_REMOVE_STR))
|
||||
{
|
||||
protocolServerResponse(server,
|
||||
VARBOOL(storageInterfacePathRemoveP(driver, varStr(varLstGet(paramList, 0)), varBool(varLstGet(paramList, 1)))));
|
||||
}
|
||||
else if (strEq(command, PROTOCOL_COMMAND_STORAGE_PATH_SYNC_STR))
|
||||
{
|
||||
storageInterfacePathSyncP(driver, varStr(varLstGet(paramList, 0)));
|
||||
|
||||
protocolServerResponse(server, NULL);
|
||||
}
|
||||
else if (strEq(command, PROTOCOL_COMMAND_STORAGE_REMOVE_STR))
|
||||
{
|
||||
storageInterfaceRemoveP(driver, varStr(varLstGet(paramList, 0)), .errorOnMissing = varBool(varLstGet(paramList, 1)));
|
||||
|
||||
protocolServerResponse(server, NULL);
|
||||
}
|
||||
else
|
||||
found = false;
|
||||
}
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
FUNCTION_LOG_RETURN(BOOL, found);
|
||||
FUNCTION_TEST_RETURN_VOID();
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
void
|
||||
storageRemotePathCreateProtocol(const VariantList *paramList, ProtocolServer *server)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(VARIANT_LIST, paramList);
|
||||
FUNCTION_LOG_PARAM(PROTOCOL_SERVER, server);
|
||||
FUNCTION_LOG_END();
|
||||
|
||||
ASSERT(paramList != NULL);
|
||||
ASSERT(server != NULL);
|
||||
ASSERT(storageRemoteProtocolLocal.driver != NULL);
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
storageInterfacePathCreateP(
|
||||
storageRemoteProtocolLocal.driver, varStr(varLstGet(paramList, 0)), varBool(varLstGet(paramList, 1)),
|
||||
varBool(varLstGet(paramList, 2)), (mode_t)varUIntForce(varLstGet(paramList, 3)));
|
||||
|
||||
protocolServerResponse(server, NULL);
|
||||
}
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
FUNCTION_TEST_RETURN_VOID();
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
void
|
||||
storageRemotePathRemoveProtocol(const VariantList *paramList, ProtocolServer *server)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(VARIANT_LIST, paramList);
|
||||
FUNCTION_LOG_PARAM(PROTOCOL_SERVER, server);
|
||||
FUNCTION_LOG_END();
|
||||
|
||||
ASSERT(paramList != NULL);
|
||||
ASSERT(server != NULL);
|
||||
ASSERT(storageRemoteProtocolLocal.driver != NULL);
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
protocolServerResponse(
|
||||
server,
|
||||
VARBOOL(
|
||||
storageInterfacePathRemoveP(
|
||||
storageRemoteProtocolLocal.driver, varStr(varLstGet(paramList, 0)), varBool(varLstGet(paramList, 1)))));
|
||||
}
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
FUNCTION_TEST_RETURN_VOID();
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
void
|
||||
storageRemotePathSyncProtocol(const VariantList *paramList, ProtocolServer *server)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(VARIANT_LIST, paramList);
|
||||
FUNCTION_LOG_PARAM(PROTOCOL_SERVER, server);
|
||||
FUNCTION_LOG_END();
|
||||
|
||||
ASSERT(paramList != NULL);
|
||||
ASSERT(server != NULL);
|
||||
ASSERT(storageRemoteProtocolLocal.driver != NULL);
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
storageInterfacePathSyncP(storageRemoteProtocolLocal.driver, varStr(varLstGet(paramList, 0)));
|
||||
protocolServerResponse(server, NULL);
|
||||
}
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
FUNCTION_TEST_RETURN_VOID();
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
void
|
||||
storageRemoteRemoveProtocol(const VariantList *paramList, ProtocolServer *server)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(VARIANT_LIST, paramList);
|
||||
FUNCTION_LOG_PARAM(PROTOCOL_SERVER, server);
|
||||
FUNCTION_LOG_END();
|
||||
|
||||
ASSERT(paramList != NULL);
|
||||
ASSERT(server != NULL);
|
||||
ASSERT(storageRemoteProtocolLocal.driver != NULL);
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
storageInterfaceRemoveP(
|
||||
storageRemoteProtocolLocal.driver, varStr(varLstGet(paramList, 0)), .errorOnMissing = varBool(varLstGet(paramList, 1)));
|
||||
protocolServerResponse(server, NULL);
|
||||
}
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
FUNCTION_LOG_RETURN_VOID();
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
@ -341,23 +495,21 @@ storageRemoteProtocolBlockSize(const String *message)
|
||||
|
||||
ASSERT(message != NULL);
|
||||
|
||||
// Regular expression to check block messages
|
||||
static RegExp *blockRegExp = NULL;
|
||||
|
||||
// Create block regular expression if it has not been created yet
|
||||
if (storageRemoteProtocolLocal.memContext == NULL)
|
||||
if (blockRegExp == NULL)
|
||||
{
|
||||
MEM_CONTEXT_BEGIN(memContextTop())
|
||||
{
|
||||
MEM_CONTEXT_NEW_BEGIN("StorageRemoteFileReadLocal")
|
||||
{
|
||||
storageRemoteProtocolLocal.memContext = memContextCurrent();
|
||||
storageRemoteProtocolLocal.blockRegExp = regExpNew(BLOCK_REG_EXP_STR);
|
||||
}
|
||||
MEM_CONTEXT_NEW_END();
|
||||
blockRegExp = regExpNew(BLOCK_REG_EXP_STR);
|
||||
}
|
||||
MEM_CONTEXT_END();
|
||||
}
|
||||
|
||||
// Validate the header block size message
|
||||
if (!regExpMatch(storageRemoteProtocolLocal.blockRegExp, message))
|
||||
if (!regExpMatch(blockRegExp, message))
|
||||
THROW_FMT(ProtocolError, "'%s' is not a valid block size message", strZ(message));
|
||||
|
||||
FUNCTION_LOG_RETURN(SSIZE, (ssize_t)cvtZToInt(strZ(message) + sizeof(PROTOCOL_BLOCK_HEADER) - 1));
|
||||
|
@ -39,6 +39,28 @@ Functions
|
||||
ssize_t storageRemoteProtocolBlockSize(const String *message);
|
||||
|
||||
// Process storage protocol requests
|
||||
bool storageRemoteProtocol(const String *command, const VariantList *paramList, ProtocolServer *server);
|
||||
void storageRemoteFeatureProtocol(const VariantList *paramList, ProtocolServer *server);
|
||||
void storageRemoteInfoProtocol(const VariantList *paramList, ProtocolServer *server);
|
||||
void storageRemoteInfoListProtocol(const VariantList *paramList, ProtocolServer *server);
|
||||
void storageRemoteOpenReadProtocol(const VariantList *paramList, ProtocolServer *server);
|
||||
void storageRemoteOpenWriteProtocol(const VariantList *paramList, ProtocolServer *server);
|
||||
void storageRemotePathCreateProtocol(const VariantList *paramList, ProtocolServer *server);
|
||||
void storageRemotePathRemoveProtocol(const VariantList *paramList, ProtocolServer *server);
|
||||
void storageRemotePathSyncProtocol(const VariantList *paramList, ProtocolServer *server);
|
||||
void storageRemoteRemoveProtocol(const VariantList *paramList, ProtocolServer *server);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Protocol commands for ProtocolServerHandler arrays passed to protocolServerProcess()
|
||||
***********************************************************************************************************************************/
|
||||
#define PROTOCOL_SERVER_HANDLER_STORAGE_REMOTE_LIST \
|
||||
{.command = PROTOCOL_COMMAND_STORAGE_FEATURE, .handler = storageRemoteFeatureProtocol}, \
|
||||
{.command = PROTOCOL_COMMAND_STORAGE_INFO, .handler = storageRemoteInfoProtocol}, \
|
||||
{.command = PROTOCOL_COMMAND_STORAGE_INFO_LIST, .handler = storageRemoteInfoListProtocol}, \
|
||||
{.command = PROTOCOL_COMMAND_STORAGE_OPEN_READ, .handler = storageRemoteOpenReadProtocol}, \
|
||||
{.command = PROTOCOL_COMMAND_STORAGE_OPEN_WRITE, .handler = storageRemoteOpenWriteProtocol}, \
|
||||
{.command = PROTOCOL_COMMAND_STORAGE_PATH_CREATE, .handler = storageRemotePathCreateProtocol}, \
|
||||
{.command = PROTOCOL_COMMAND_STORAGE_PATH_REMOVE, .handler = storageRemotePathRemoveProtocol}, \
|
||||
{.command = PROTOCOL_COMMAND_STORAGE_PATH_SYNC, .handler = storageRemotePathSyncProtocol}, \
|
||||
{.command = PROTOCOL_COMMAND_STORAGE_REMOVE, .handler = storageRemoteRemoveProtocol},
|
||||
|
||||
#endif
|
||||
|
@ -1043,9 +1043,7 @@ testRun(void)
|
||||
IoWrite *serverWriteIo = ioBufferWriteNew(serverWrite);
|
||||
ioWriteOpen(serverWriteIo);
|
||||
|
||||
ProtocolServer *server = protocolServerNew(
|
||||
strNew("test"), strNew("test"), ioBufferReadNew(bufNew(0)), serverWriteIo);
|
||||
|
||||
ProtocolServer *server = protocolServerNew(strNew("test"), strNew("test"), ioBufferReadNew(bufNew(0)), serverWriteIo);
|
||||
bufUsedSet(serverWrite, 0);
|
||||
|
||||
// Add archive-async and spool path
|
||||
@ -1065,19 +1063,13 @@ testRun(void)
|
||||
varLstAdd(paramList, varNewUInt(cipherTypeAes256Cbc));
|
||||
varLstAdd(paramList, varNewStrZ(TEST_CIPHER_PASS_ARCHIVE));
|
||||
|
||||
TEST_RESULT_BOOL(
|
||||
archiveGetProtocol(PROTOCOL_COMMAND_ARCHIVE_GET_STR, paramList, server), true, "protocol archive get");
|
||||
TEST_RESULT_VOID(archiveGetFileProtocol(paramList, server), "protocol archive get");
|
||||
|
||||
TEST_RESULT_STR_Z(strNewBuf(serverWrite), "{\"out\":[0,[]]}\n", "check result");
|
||||
TEST_STORAGE_LIST(
|
||||
storageSpool(), STORAGE_SPOOL_ARCHIVE_IN, "000000010000000100000002\n01ABCDEF01ABCDEF01ABCDEF.pgbackrest.tmp\n");
|
||||
|
||||
bufUsedSet(serverWrite, 0);
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("invalid protocol command");
|
||||
|
||||
TEST_RESULT_BOOL(archiveGetProtocol(strNew(BOGUS_STR), paramList, server), false, "invalid function");
|
||||
}
|
||||
|
||||
FUNCTION_HARNESS_RETURN_VOID();
|
||||
|
@ -235,7 +235,7 @@ testRun(void)
|
||||
}
|
||||
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("Synchronous cmdArchivePush(), archivePushFile() and archivePushProtocol()"))
|
||||
if (testBegin("Synchronous cmdArchivePush(), archivePushFile() and archivePushFileProtocol()"))
|
||||
{
|
||||
TEST_TITLE("command must be run on the pg host");
|
||||
|
||||
@ -445,8 +445,7 @@ testRun(void)
|
||||
varLstAdd(paramList, varNewUInt64(cipherTypeNone));
|
||||
varLstAdd(paramList, NULL);
|
||||
|
||||
TEST_RESULT_BOOL(
|
||||
archivePushProtocol(PROTOCOL_COMMAND_ARCHIVE_PUSH_STR, paramList, server), true, "protocol archive put");
|
||||
TEST_RESULT_VOID(archivePushFileProtocol(paramList, server), "protocol archive put");
|
||||
TEST_RESULT_STR_Z(
|
||||
strNewBuf(serverWrite),
|
||||
"{\"out\":[[\"WAL file '000000010000000100000002' already exists in the repo1 archive with the same checksum"
|
||||
@ -455,10 +454,6 @@ testRun(void)
|
||||
|
||||
bufUsedSet(serverWrite, 0);
|
||||
|
||||
// Check invalid protocol function
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_RESULT_BOOL(archivePushProtocol(strNew(BOGUS_STR), paramList, server), false, "invalid function");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("multiple repos, one encrypted");
|
||||
|
||||
|
@ -470,7 +470,7 @@ testRun(void)
|
||||
}
|
||||
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("backupFile(), backupProtocol"))
|
||||
if (testBegin("backupFile() and backupFileProtocol()"))
|
||||
{
|
||||
// Load Parameters
|
||||
StringList *argList = strLstNew();
|
||||
@ -513,8 +513,7 @@ testRun(void)
|
||||
varLstAdd(paramList, varNewUInt(cipherTypeNone)); // cipherType
|
||||
varLstAdd(paramList, NULL); // cipherSubPass
|
||||
|
||||
TEST_RESULT_BOOL(
|
||||
backupProtocol(PROTOCOL_COMMAND_BACKUP_FILE_STR, paramList, server), true, "protocol backup file - skip");
|
||||
TEST_RESULT_VOID(backupFileProtocol(paramList, server), "protocol backup file - skip");
|
||||
TEST_RESULT_STR_Z(strNewBuf(serverWrite), "{\"out\":[3,0,0,null,null]}\n", " check result");
|
||||
bufUsedSet(serverWrite, 0);
|
||||
|
||||
@ -606,8 +605,7 @@ testRun(void)
|
||||
varLstAdd(paramList, varNewUInt(cipherTypeNone)); // cipherType
|
||||
varLstAdd(paramList, NULL); // cipherSubPass
|
||||
|
||||
TEST_RESULT_BOOL(
|
||||
backupProtocol(PROTOCOL_COMMAND_BACKUP_FILE_STR, paramList, server), true, "protocol backup file - pageChecksum");
|
||||
TEST_RESULT_VOID(backupFileProtocol(paramList, server), "protocol backup file - pageChecksum");
|
||||
TEST_RESULT_STR_Z(
|
||||
strNewBuf(serverWrite),
|
||||
"{\"out\":[1,12,12,\"c3ae4687ea8ccd47bfdb190dbe7fd3b37545fdb9\",{\"align\":false,\"valid\":false}]}\n",
|
||||
@ -650,8 +648,7 @@ testRun(void)
|
||||
varLstAdd(paramList, varNewUInt(cipherTypeNone)); // cipherType
|
||||
varLstAdd(paramList, NULL); // cipherSubPass
|
||||
|
||||
TEST_RESULT_BOOL(
|
||||
backupProtocol(PROTOCOL_COMMAND_BACKUP_FILE_STR, paramList, server), true, "protocol backup file - noop");
|
||||
TEST_RESULT_VOID(backupFileProtocol(paramList, server), "protocol backup file - noop");
|
||||
TEST_RESULT_STR_Z(
|
||||
strNewBuf(serverWrite), "{\"out\":[4,12,0,\"c3ae4687ea8ccd47bfdb190dbe7fd3b37545fdb9\",null]}\n", " check result");
|
||||
bufUsedSet(serverWrite, 0);
|
||||
@ -793,8 +790,7 @@ testRun(void)
|
||||
varLstAdd(paramList, varNewUInt(cipherTypeNone)); // cipherType
|
||||
varLstAdd(paramList, NULL); // cipherSubPass
|
||||
|
||||
TEST_RESULT_BOOL(
|
||||
backupProtocol(PROTOCOL_COMMAND_BACKUP_FILE_STR, paramList, server), true, "protocol backup file - copy, compress");
|
||||
TEST_RESULT_VOID(backupFileProtocol(paramList, server), "protocol backup file - copy, compress");
|
||||
TEST_RESULT_STR_Z(
|
||||
strNewBuf(serverWrite), "{\"out\":[0,9,29,\"9bc8ab2dda60ef4beed07d1e19ce0676d5edde67\",null]}\n", " check result");
|
||||
bufUsedSet(serverWrite, 0);
|
||||
@ -817,10 +813,6 @@ testRun(void)
|
||||
(storageExistsP(storageRepo(), strNewFmt(STORAGE_REPO_BACKUP "/%s/zerofile", strZ(backupLabel))) &&
|
||||
result.pageChecksumResult == NULL),
|
||||
true, " copy zero file to repo success");
|
||||
|
||||
// Check invalid protocol function
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_RESULT_BOOL(backupProtocol(strNew(BOGUS_STR), paramList, server), false, "invalid function");
|
||||
}
|
||||
|
||||
// *****************************************************************************************************************************
|
||||
@ -913,8 +905,7 @@ testRun(void)
|
||||
varLstAdd(paramList, varNewUInt(cipherTypeAes256Cbc)); // cipherType
|
||||
varLstAdd(paramList, varNewStrZ("12345678")); // cipherPass
|
||||
|
||||
TEST_RESULT_BOOL(
|
||||
backupProtocol(PROTOCOL_COMMAND_BACKUP_FILE_STR, paramList, server), true, "protocol backup file - recopy, encrypt");
|
||||
TEST_RESULT_VOID(backupFileProtocol(paramList, server), "protocol backup file - recopy, encrypt");
|
||||
TEST_RESULT_STR_Z(
|
||||
strNewBuf(serverWrite), "{\"out\":[2,9,32,\"9bc8ab2dda60ef4beed07d1e19ce0676d5edde67\",null]}\n", " check result");
|
||||
bufUsedSet(serverWrite, 0);
|
||||
|
@ -350,7 +350,7 @@ testRun(void)
|
||||
varLstAdd(paramList, varNewBool(false));
|
||||
varLstAdd(paramList, NULL);
|
||||
|
||||
TEST_RESULT_BOOL(restoreProtocol(PROTOCOL_COMMAND_RESTORE_FILE_STR, paramList, server), true, "protocol restore file");
|
||||
TEST_RESULT_VOID(restoreFileProtocol(paramList, server), "protocol restore file");
|
||||
TEST_RESULT_STR_Z(strNewBuf(serverWrite), "{\"out\":true}\n", " check result");
|
||||
bufUsedSet(serverWrite, 0);
|
||||
|
||||
@ -382,13 +382,9 @@ testRun(void)
|
||||
varLstAdd(paramList, varNewBool(false));
|
||||
varLstAdd(paramList, NULL);
|
||||
|
||||
TEST_RESULT_BOOL(restoreProtocol(PROTOCOL_COMMAND_RESTORE_FILE_STR, paramList, server), true, "protocol restore file");
|
||||
TEST_RESULT_VOID(restoreFileProtocol(paramList, server), "protocol restore file");
|
||||
TEST_RESULT_STR_Z(strNewBuf(serverWrite), "{\"out\":false}\n", " check result");
|
||||
bufUsedSet(serverWrite, 0);
|
||||
|
||||
// Check invalid protocol function
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_RESULT_BOOL(restoreProtocol(strNew(BOGUS_STR), paramList, server), false, "invalid function");
|
||||
}
|
||||
|
||||
// *****************************************************************************************************************************
|
||||
|
@ -876,7 +876,7 @@ testRun(void)
|
||||
}
|
||||
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("verifyFile(), verifyProtocol()"))
|
||||
if (testBegin("verifyFile() and verifyFileProtocol()"))
|
||||
{
|
||||
// Load Parameters
|
||||
StringList *argList = strLstDup(argListBase);
|
||||
@ -912,7 +912,7 @@ testRun(void)
|
||||
"file encrypted compressed checksum mismatch");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("verifyProtocol()");
|
||||
TEST_TITLE("verifyFileProtocol()");
|
||||
|
||||
// Start a protocol server to test the protocol directly
|
||||
Buffer *serverWrite = bufNew(8192);
|
||||
@ -927,11 +927,9 @@ testRun(void)
|
||||
varLstAdd(paramList, varNewUInt64(fileSize));
|
||||
varLstAdd(paramList, varNewStrZ("pass"));
|
||||
|
||||
TEST_RESULT_BOOL(verifyProtocol(PROTOCOL_COMMAND_VERIFY_FILE_STR, paramList, server), true, "protocol verify file");
|
||||
TEST_RESULT_VOID(verifyFileProtocol(paramList, server), "protocol verify file");
|
||||
TEST_RESULT_STR_Z(strNewBuf(serverWrite), "{\"out\":0}\n", "check result");
|
||||
bufUsedSet(serverWrite, 0);
|
||||
|
||||
TEST_RESULT_BOOL(verifyProtocol(strNew(BOGUS_STR), paramList, server), false, "invalid protocol function");
|
||||
}
|
||||
|
||||
// *****************************************************************************************************************************
|
||||
|
@ -18,7 +18,7 @@ testRun(void)
|
||||
FUNCTION_HARNESS_VOID();
|
||||
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("configProtocol() and configProtocolOption()"))
|
||||
if (testBegin("configOptionProtocol() and configOptionRemote()"))
|
||||
{
|
||||
HARNESS_FORK_BEGIN()
|
||||
{
|
||||
@ -37,8 +37,9 @@ testRun(void)
|
||||
harnessCfgLoad(cfgCmdArchiveGet, argList);
|
||||
|
||||
ProtocolServer *server = protocolServerNew(strNew("test"), strNew("config"), read, write);
|
||||
protocolServerHandlerAdd(server, configProtocol);
|
||||
protocolServerProcess(server, NULL);
|
||||
|
||||
static const ProtocolServerHandler commandHandler[] = {PROTOCOL_SERVER_HANDLER_OPTION_LIST};
|
||||
protocolServerProcess(server, NULL, commandHandler, PROTOCOL_SERVER_HANDLER_LIST_SIZE(commandHandler));
|
||||
}
|
||||
HARNESS_FORK_CHILD_END();
|
||||
|
||||
@ -56,8 +57,7 @@ testRun(void)
|
||||
varLstAdd(list, varNewStr(strNew("repo1-host-user")));
|
||||
|
||||
TEST_RESULT_STRLST_Z(
|
||||
strLstNewVarLst(configProtocolOption(client, list)), "repo-host\nrepo-host-user\n",
|
||||
"get options");
|
||||
strLstNewVarLst(configOptionRemote(client, list)), "repo-host\nrepo-host-user\n", "get options");
|
||||
|
||||
protocolClientFree(client);
|
||||
}
|
||||
|
@ -100,8 +100,12 @@ testRun(void)
|
||||
ProtocolServer *server = NULL;
|
||||
|
||||
TEST_ASSIGN(server, protocolServerNew(strNew("db test server"), strNew("test"), read, write), "create server");
|
||||
TEST_RESULT_VOID(protocolServerHandlerAdd(server, dbProtocol), "add handler");
|
||||
TEST_RESULT_VOID(protocolServerProcess(server, NULL), "run process loop");
|
||||
|
||||
static const ProtocolServerHandler commandHandler[] = {PROTOCOL_SERVER_HANDLER_DB_LIST};
|
||||
|
||||
TEST_RESULT_VOID(
|
||||
protocolServerProcess(server, NULL, commandHandler, PROTOCOL_SERVER_HANDLER_LIST_SIZE(commandHandler)),
|
||||
"run process loop");
|
||||
TEST_RESULT_VOID(protocolServerFree(server), "free server");
|
||||
}
|
||||
HARNESS_FORK_CHILD_END();
|
||||
|
@ -178,8 +178,9 @@ testRun(void)
|
||||
ioWriteOpen(write);
|
||||
|
||||
ProtocolServer *server = protocolServerNew(strNew("storage test server"), strNew("test"), read, write);
|
||||
protocolServerHandlerAdd(server, storageRemoteProtocol);
|
||||
protocolServerProcess(server, NULL);
|
||||
|
||||
static const ProtocolServerHandler commandHandler[] = {PROTOCOL_SERVER_HANDLER_STORAGE_REMOTE_LIST};
|
||||
protocolServerProcess(server, NULL, commandHandler, PROTOCOL_SERVER_HANDLER_LIST_SIZE(commandHandler));
|
||||
|
||||
}
|
||||
HARNESS_FORK_CHILD_END();
|
||||
|
@ -18,38 +18,81 @@ Test protocol request handler
|
||||
***********************************************************************************************************************************/
|
||||
static unsigned int testServerProtocolErrorTotal = 0;
|
||||
|
||||
static bool
|
||||
testServerProtocol(const String *command, const VariantList *paramList, ProtocolServer *server)
|
||||
static void
|
||||
testServerAssertProtocol(const VariantList *paramList, ProtocolServer *server)
|
||||
{
|
||||
FUNCTION_HARNESS_BEGIN();
|
||||
FUNCTION_HARNESS_PARAM(STRING, command);
|
||||
FUNCTION_HARNESS_PARAM(VARIANT_LIST, paramList);
|
||||
FUNCTION_HARNESS_PARAM(PROTOCOL_SERVER, server);
|
||||
FUNCTION_HARNESS_END();
|
||||
|
||||
ASSERT(command != NULL);
|
||||
|
||||
// Attempt to satisfy the request -- we may get requests that are meant for other handlers
|
||||
bool found = true;
|
||||
ASSERT(paramList == NULL);
|
||||
ASSERT(server != NULL);
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
if (strEq(command, strNew("assert")))
|
||||
{
|
||||
THROW(AssertError, "test assert");
|
||||
}
|
||||
else if (strEq(command, strNew("request-simple")))
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
FUNCTION_HARNESS_RETURN_VOID();
|
||||
}
|
||||
|
||||
static void
|
||||
testServerRequestSimpleProtocol(const VariantList *paramList, ProtocolServer *server)
|
||||
{
|
||||
FUNCTION_HARNESS_BEGIN();
|
||||
FUNCTION_HARNESS_PARAM(VARIANT_LIST, paramList);
|
||||
FUNCTION_HARNESS_PARAM(PROTOCOL_SERVER, server);
|
||||
FUNCTION_HARNESS_END();
|
||||
|
||||
ASSERT(paramList == NULL);
|
||||
ASSERT(server != NULL);
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
protocolServerResponse(server, varNewBool(true));
|
||||
}
|
||||
else if (strEq(command, strNew("request-complex")))
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
FUNCTION_HARNESS_RETURN_VOID();
|
||||
}
|
||||
|
||||
static void
|
||||
testServerRequestComplexProtocol(const VariantList *paramList, ProtocolServer *server)
|
||||
{
|
||||
FUNCTION_HARNESS_BEGIN();
|
||||
FUNCTION_HARNESS_PARAM(VARIANT_LIST, paramList);
|
||||
FUNCTION_HARNESS_PARAM(PROTOCOL_SERVER, server);
|
||||
FUNCTION_HARNESS_END();
|
||||
|
||||
ASSERT(paramList == NULL);
|
||||
ASSERT(server != NULL);
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
protocolServerResponse(server, varNewBool(false));
|
||||
protocolServerWriteLine(server, strNew("LINEOFTEXT"));
|
||||
protocolServerWriteLine(server, NULL);
|
||||
ioWriteFlush(protocolServerIoWrite(server));
|
||||
}
|
||||
else if (strEq(command, STRDEF("error-until-0")))
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
FUNCTION_HARNESS_RETURN_VOID();
|
||||
}
|
||||
|
||||
static void
|
||||
testServerErrorUntil0Protocol(const VariantList *paramList, ProtocolServer *server)
|
||||
{
|
||||
FUNCTION_HARNESS_BEGIN();
|
||||
FUNCTION_HARNESS_PARAM(VARIANT_LIST, paramList);
|
||||
FUNCTION_HARNESS_PARAM(PROTOCOL_SERVER, server);
|
||||
FUNCTION_HARNESS_END();
|
||||
|
||||
ASSERT(paramList == NULL);
|
||||
ASSERT(server != NULL);
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
if (testServerProtocolErrorTotal > 0)
|
||||
{
|
||||
@ -59,12 +102,9 @@ testServerProtocol(const String *command, const VariantList *paramList, Protocol
|
||||
|
||||
protocolServerResponse(server, varNewBool(true));
|
||||
}
|
||||
else
|
||||
found = false;
|
||||
}
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
FUNCTION_HARNESS_RETURN(BOOL, found);
|
||||
FUNCTION_HARNESS_RETURN_VOID();
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -689,9 +729,17 @@ testRun(void)
|
||||
TEST_RESULT_PTR(protocolServerIoRead(server), server->read, "get read io");
|
||||
TEST_RESULT_PTR(protocolServerIoWrite(server), server->write, "get write io");
|
||||
|
||||
TEST_RESULT_VOID(protocolServerHandlerAdd(server, testServerProtocol), "add handler");
|
||||
static const ProtocolServerHandler commandHandler[] =
|
||||
{
|
||||
{.command = "assert", .handler = testServerAssertProtocol},
|
||||
{.command = "request-simple", .handler = testServerRequestSimpleProtocol},
|
||||
{.command = "request-complex", .handler = testServerRequestComplexProtocol},
|
||||
{.command = "error-until-0", .handler = testServerErrorUntil0Protocol},
|
||||
};
|
||||
|
||||
TEST_RESULT_VOID(protocolServerProcess(server, NULL), "run process loop");
|
||||
TEST_RESULT_VOID(
|
||||
protocolServerProcess(server, NULL, commandHandler, PROTOCOL_SERVER_HANDLER_LIST_SIZE(commandHandler)),
|
||||
"run process loop");
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("run process loop with retries");
|
||||
@ -702,7 +750,9 @@ testRun(void)
|
||||
|
||||
testServerProtocolErrorTotal = 2;
|
||||
|
||||
TEST_RESULT_VOID(protocolServerProcess(server, retryInterval), "run process loop");
|
||||
TEST_RESULT_VOID(
|
||||
protocolServerProcess(server, retryInterval, commandHandler, PROTOCOL_SERVER_HANDLER_LIST_SIZE(commandHandler)),
|
||||
"run process loop");
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("free server");
|
||||
|
@ -62,20 +62,37 @@ testRun(void)
|
||||
TEST_RESULT_BOOL(storageFeature(storageRemote, storageFeatureCompress), true, " check compress feature");
|
||||
TEST_RESULT_STR(storagePathP(storageRemote, NULL), strNewFmt("%s/repo", testPath()), " check path");
|
||||
|
||||
// Check protocol function directly
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_RESULT_BOOL(
|
||||
storageRemoteProtocol(PROTOCOL_COMMAND_STORAGE_FEATURE_STR, varLstNew(), server), true, "protocol feature");
|
||||
TEST_TITLE("check protocol function directly (pg)");
|
||||
|
||||
cfgOptionSet(cfgOptRemoteType, cfgSourceParam, VARSTRDEF("pg"));
|
||||
|
||||
TEST_RESULT_VOID(storageRemoteFeatureProtocol(NULL, server), "protocol feature");
|
||||
TEST_RESULT_STR(
|
||||
strNewBuf(serverWrite),
|
||||
strNewFmt(".\"%s/repo\"\n.%" PRIu64 "\n{}\n", testPath(), storageInterface(storageTest).feature),
|
||||
"check result");
|
||||
|
||||
bufUsedSet(serverWrite, 0);
|
||||
|
||||
// Check invalid protocol function
|
||||
TEST_RESULT_VOID(storageRemoteFeatureProtocol(NULL, server), "protocol feature");
|
||||
TEST_RESULT_STR(
|
||||
strNewBuf(serverWrite),
|
||||
strNewFmt(".\"%s/repo\"\n.%" PRIu64 "\n{}\n", testPath(), storageInterface(storageTest).feature),
|
||||
"check result cache");
|
||||
bufUsedSet(serverWrite, 0);
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_RESULT_BOOL(storageRemoteProtocol(strNew(BOGUS_STR), varLstNew(), server), false, "invalid function");
|
||||
TEST_TITLE("check protocol function directly (repo)");
|
||||
|
||||
storageRemoteProtocolLocal.memContext = NULL;
|
||||
cfgOptionSet(cfgOptRemoteType, cfgSourceParam, VARSTRDEF("repo"));
|
||||
|
||||
TEST_RESULT_VOID(storageRemoteFeatureProtocol(NULL, server), "protocol feature");
|
||||
TEST_RESULT_STR(
|
||||
strNewBuf(serverWrite),
|
||||
strNewFmt(".\"%s/repo\"\n.%" PRIu64 "\n{}\n", testPath(), storageInterface(storageTest).feature),
|
||||
"check result");
|
||||
bufUsedSet(serverWrite, 0);
|
||||
}
|
||||
|
||||
// *****************************************************************************************************************************
|
||||
@ -198,7 +215,7 @@ testRun(void)
|
||||
varLstAdd(paramList, varNewUInt(storageInfoLevelBasic));
|
||||
varLstAdd(paramList, varNewBool(false));
|
||||
|
||||
TEST_RESULT_BOOL(storageRemoteProtocol(PROTOCOL_COMMAND_STORAGE_INFO_STR, paramList, server), true, "protocol list");
|
||||
TEST_RESULT_VOID(storageRemoteInfoProtocol(paramList, server), "protocol list");
|
||||
TEST_RESULT_STR_Z(strNewBuf(serverWrite), "{\"out\":false}\n", "check result");
|
||||
|
||||
bufUsedSet(serverWrite, 0);
|
||||
@ -215,7 +232,7 @@ testRun(void)
|
||||
varLstAdd(paramList, varNewUInt(storageInfoLevelBasic));
|
||||
varLstAdd(paramList, varNewBool(false));
|
||||
|
||||
TEST_RESULT_BOOL(storageRemoteProtocol(PROTOCOL_COMMAND_STORAGE_INFO_STR, paramList, server), true, "protocol list");
|
||||
TEST_RESULT_VOID(storageRemoteInfoProtocol(paramList, server), "protocol list");
|
||||
TEST_RESULT_STR_Z(
|
||||
strNewBuf(serverWrite),
|
||||
hrnReplaceKey(
|
||||
@ -234,7 +251,7 @@ testRun(void)
|
||||
varLstAdd(paramList, varNewUInt(storageInfoLevelDetail));
|
||||
varLstAdd(paramList, varNewBool(false));
|
||||
|
||||
TEST_RESULT_BOOL(storageRemoteProtocol(PROTOCOL_COMMAND_STORAGE_INFO_STR, paramList, server), true, "protocol list");
|
||||
TEST_RESULT_VOID(storageRemoteInfoProtocol(paramList, server), "protocol list");
|
||||
TEST_RESULT_STR_Z(
|
||||
strNewBuf(serverWrite),
|
||||
hrnReplaceKey(
|
||||
@ -299,7 +316,7 @@ testRun(void)
|
||||
varLstAdd(paramList, varNewStrZ(hrnReplaceKey("{[path]}/repo")));
|
||||
varLstAdd(paramList, varNewUInt(storageInfoLevelDetail));
|
||||
|
||||
TEST_RESULT_BOOL(storageRemoteProtocol(PROTOCOL_COMMAND_STORAGE_INFO_LIST_STR, paramList, server), true, "call protocol");
|
||||
TEST_RESULT_VOID(storageRemoteInfoListProtocol(paramList, server), "call protocol");
|
||||
TEST_RESULT_STR_Z(
|
||||
strNewBuf(serverWrite),
|
||||
hrnReplaceKey(
|
||||
@ -374,9 +391,7 @@ testRun(void)
|
||||
varLstAdd(paramList, NULL);
|
||||
varLstAdd(paramList, varNewVarLst(varLstNew()));
|
||||
|
||||
TEST_RESULT_BOOL(
|
||||
storageRemoteProtocol(PROTOCOL_COMMAND_STORAGE_OPEN_READ_STR, paramList, server), true,
|
||||
"protocol open read (missing)");
|
||||
TEST_RESULT_VOID(storageRemoteOpenReadProtocol(paramList, server), "protocol open read (missing)");
|
||||
TEST_RESULT_STR_Z(strNewBuf(serverWrite), "{\"out\":false}\n", "check result");
|
||||
|
||||
bufUsedSet(serverWrite, 0);
|
||||
@ -402,8 +417,7 @@ testRun(void)
|
||||
ioFilterGroupAdd(filterGroup, decompressFilter(compressTypeGz));
|
||||
varLstAdd(paramList, ioFilterGroupParamAll(filterGroup));
|
||||
|
||||
TEST_RESULT_BOOL(
|
||||
storageRemoteProtocol(PROTOCOL_COMMAND_STORAGE_OPEN_READ_STR, paramList, server), true, "protocol open read");
|
||||
TEST_RESULT_VOID(storageRemoteOpenReadProtocol(paramList, server), "protocol open read");
|
||||
TEST_RESULT_STR_Z(
|
||||
strNewBuf(serverWrite),
|
||||
"{\"out\":true}\n"
|
||||
@ -434,8 +448,7 @@ testRun(void)
|
||||
ioFilterGroupAdd(filterGroup, ioSinkNew());
|
||||
varLstAdd(paramList, ioFilterGroupParamAll(filterGroup));
|
||||
|
||||
TEST_RESULT_BOOL(
|
||||
storageRemoteProtocol(PROTOCOL_COMMAND_STORAGE_OPEN_READ_STR, paramList, server), true, "protocol open read (sink)");
|
||||
TEST_RESULT_VOID(storageRemoteOpenReadProtocol(paramList, server), "protocol open read (sink)");
|
||||
TEST_RESULT_STR_Z(
|
||||
strNewBuf(serverWrite),
|
||||
"{\"out\":true}\n"
|
||||
@ -453,9 +466,7 @@ testRun(void)
|
||||
varLstAdd(paramList, NULL);
|
||||
varLstAdd(paramList, varNewVarLst(varLstAdd(varLstNew(), varNewKv(kvAdd(kvNew(), varNewStrZ("bogus"), NULL)))));
|
||||
|
||||
TEST_ERROR(
|
||||
storageRemoteProtocol(
|
||||
PROTOCOL_COMMAND_STORAGE_OPEN_READ_STR, paramList, server), AssertError, "unable to add filter 'bogus'");
|
||||
TEST_ERROR(storageRemoteOpenReadProtocol(paramList, server), AssertError, "unable to add filter 'bogus'");
|
||||
}
|
||||
|
||||
// *****************************************************************************************************************************
|
||||
@ -551,8 +562,7 @@ testRun(void)
|
||||
"BRBLOCK3\n"
|
||||
"ABCBRBLOCK-1\n"));
|
||||
|
||||
TEST_RESULT_BOOL(
|
||||
storageRemoteProtocol(PROTOCOL_COMMAND_STORAGE_OPEN_WRITE_STR, paramList, server), true, "protocol open write");
|
||||
TEST_RESULT_VOID(storageRemoteOpenWriteProtocol(paramList, server), "protocol open write");
|
||||
TEST_RESULT_STR_Z(
|
||||
strNewBuf(serverWrite),
|
||||
"{}\n"
|
||||
@ -582,8 +592,7 @@ testRun(void)
|
||||
varLstAdd(paramList, varNewBool(true));
|
||||
varLstAdd(paramList, varNewVarLst(varLstNew()));
|
||||
|
||||
TEST_RESULT_BOOL(
|
||||
storageRemoteProtocol(PROTOCOL_COMMAND_STORAGE_OPEN_WRITE_STR, paramList, server), true, "protocol open write");
|
||||
TEST_RESULT_VOID(storageRemoteOpenWriteProtocol(paramList, server), "protocol open write");
|
||||
TEST_RESULT_STR_Z(
|
||||
strNewBuf(serverWrite),
|
||||
"{}\n"
|
||||
@ -622,7 +631,7 @@ testRun(void)
|
||||
varLstAdd(paramList, varNewUInt64(0)); // path mode
|
||||
|
||||
TEST_ERROR_FMT(
|
||||
storageRemoteProtocol(PROTOCOL_COMMAND_STORAGE_PATH_CREATE_STR, paramList, server), PathCreateError,
|
||||
storageRemotePathCreateProtocol(paramList, server), PathCreateError,
|
||||
"raised from remote-0 protocol on 'localhost': unable to create path '%s/repo/testpath': [17] File exists",
|
||||
testPath());
|
||||
|
||||
@ -635,7 +644,7 @@ testRun(void)
|
||||
varLstAdd(paramList, varNewUInt64(0)); // path mode
|
||||
|
||||
TEST_ERROR_FMT(
|
||||
storageRemoteProtocol(PROTOCOL_COMMAND_STORAGE_PATH_CREATE_STR, paramList, server), PathCreateError,
|
||||
storageRemotePathCreateProtocol(paramList, server), PathCreateError,
|
||||
"raised from remote-0 protocol on 'localhost': unable to create path '%s/repo/parent/testpath': "
|
||||
"[2] No such file or directory", testPath());
|
||||
|
||||
@ -646,8 +655,7 @@ testRun(void)
|
||||
varLstAdd(paramList, varNewBool(false)); // noParentCreate (true=error if it does not have a parent, false=create parent)
|
||||
varLstAdd(paramList, varNewUInt64(0777)); // path mode
|
||||
|
||||
TEST_RESULT_VOID(
|
||||
storageRemoteProtocol(PROTOCOL_COMMAND_STORAGE_PATH_CREATE_STR, paramList, server), "create parent and path");
|
||||
TEST_RESULT_VOID(storageRemotePathCreateProtocol(paramList, server), "create parent and path");
|
||||
TEST_ASSIGN(info, storageInfoP(storageTest, strNewFmt("repo/%s", strZ(path))), " get path info");
|
||||
TEST_RESULT_BOOL(info.exists, true, " path exists");
|
||||
TEST_RESULT_INT(info.mode, 0777, " mode is set");
|
||||
@ -676,9 +684,7 @@ testRun(void)
|
||||
varLstAdd(paramList, varNewStr(strNewFmt("%s/repo/%s", testPath(), strZ(path))));
|
||||
varLstAdd(paramList, varNewBool(true)); // recurse
|
||||
|
||||
TEST_RESULT_BOOL(
|
||||
storageRemoteProtocol(PROTOCOL_COMMAND_STORAGE_PATH_REMOVE_STR, paramList, server), true,
|
||||
" protocol path remove missing");
|
||||
TEST_RESULT_VOID(storageRemotePathRemoveProtocol(paramList, server), " protocol path remove missing");
|
||||
TEST_RESULT_STR_Z(strNewBuf(serverWrite), "{\"out\":false}\n", " check result");
|
||||
|
||||
bufUsedSet(serverWrite, 0);
|
||||
@ -687,9 +693,7 @@ testRun(void)
|
||||
TEST_RESULT_VOID(
|
||||
storagePutP(storageNewWriteP(storageRemote, strNewFmt("%s/file.txt", strZ(path))), BUFSTRDEF("TEST")),
|
||||
"new path and file");
|
||||
TEST_RESULT_BOOL(
|
||||
storageRemoteProtocol(PROTOCOL_COMMAND_STORAGE_PATH_REMOVE_STR, paramList, server), true,
|
||||
" protocol path recurse remove");
|
||||
TEST_RESULT_VOID(storageRemotePathRemoveProtocol(paramList, server), " protocol path recurse remove");
|
||||
TEST_RESULT_BOOL(storagePathExistsP(storageTest, strNewFmt("repo/%s", strZ(path))), false, " recurse path removed");
|
||||
TEST_RESULT_STR_Z(strNewBuf(serverWrite), "{\"out\":true}\n", " check result");
|
||||
|
||||
@ -720,7 +724,7 @@ testRun(void)
|
||||
varLstAdd(paramList, varNewBool(true));
|
||||
|
||||
TEST_ERROR_FMT(
|
||||
storageRemoteProtocol(PROTOCOL_COMMAND_STORAGE_REMOVE_STR, paramList, server), FileRemoveError,
|
||||
storageRemoteRemoveProtocol(paramList, server), FileRemoveError,
|
||||
"raised from remote-0 protocol on 'localhost': unable to remove '%s/repo/file.txt': "
|
||||
"[2] No such file or directory", testPath());
|
||||
|
||||
@ -728,17 +732,13 @@ testRun(void)
|
||||
varLstAdd(paramList, varNewStr(strNewFmt("%s/repo/%s", testPath(), strZ(file))));
|
||||
varLstAdd(paramList, varNewBool(false));
|
||||
|
||||
TEST_RESULT_BOOL(
|
||||
storageRemoteProtocol(PROTOCOL_COMMAND_STORAGE_REMOVE_STR, paramList, server), true,
|
||||
"protocol file remove - no error on missing");
|
||||
TEST_RESULT_VOID(storageRemoteRemoveProtocol(paramList, server), "protocol file remove - no error on missing");
|
||||
TEST_RESULT_STR_Z(strNewBuf(serverWrite), "{}\n", " check result");
|
||||
bufUsedSet(serverWrite, 0);
|
||||
|
||||
// Write the file to the repo via the remote and test the protocol
|
||||
TEST_RESULT_VOID(storagePutP(storageNewWriteP(storageRemote, file), BUFSTRDEF("TEST")), "new file");
|
||||
TEST_RESULT_BOOL(
|
||||
storageRemoteProtocol(PROTOCOL_COMMAND_STORAGE_REMOVE_STR, paramList, server), true,
|
||||
"protocol file remove");
|
||||
TEST_RESULT_VOID(storageRemoteRemoveProtocol(paramList, server), "protocol file remove");
|
||||
TEST_RESULT_BOOL(storageExistsP(storageTest, strNewFmt("repo/%s", strZ(file))), false, " confirm file removed");
|
||||
TEST_RESULT_STR_Z(strNewBuf(serverWrite), "{}\n", " check result");
|
||||
bufUsedSet(serverWrite, 0);
|
||||
@ -761,16 +761,14 @@ testRun(void)
|
||||
VariantList *paramList = varLstNew();
|
||||
varLstAdd(paramList, varNewStr(strNewFmt("%s/repo/%s", testPath(), strZ(path))));
|
||||
|
||||
TEST_RESULT_BOOL(
|
||||
storageRemoteProtocol(PROTOCOL_COMMAND_STORAGE_PATH_SYNC_STR, paramList, server), true,
|
||||
"protocol path sync");
|
||||
TEST_RESULT_VOID(storageRemotePathSyncProtocol(paramList, server), "protocol path sync");
|
||||
TEST_RESULT_STR_Z(strNewBuf(serverWrite), "{}\n", " check result");
|
||||
bufUsedSet(serverWrite, 0);
|
||||
|
||||
paramList = varLstNew();
|
||||
varLstAdd(paramList, varNewStr(strNewFmt("%s/repo/anewpath", testPath())));
|
||||
TEST_ERROR_FMT(
|
||||
storageRemoteProtocol(PROTOCOL_COMMAND_STORAGE_PATH_SYNC_STR, paramList, server), PathMissingError,
|
||||
storageRemotePathSyncProtocol(paramList, server), PathMissingError,
|
||||
"raised from remote-0 protocol on 'localhost': " STORAGE_ERROR_PATH_SYNC_MISSING,
|
||||
strZ(strNewFmt("%s/repo/anewpath", testPath())));
|
||||
}
|
||||
|
Reference in New Issue
Block a user