Skip to content

Commit

Permalink
Update CipherType/CipherMode to StringId.
Browse files Browse the repository at this point in the history
As in 6cc521b, this allows option values and enums to be easily mapped together.
  • Loading branch information
dwsteele committed Apr 28, 2021
1 parent c3b15fc commit 85fc3da
Show file tree
Hide file tree
Showing 36 changed files with 128 additions and 189 deletions.
5 changes: 4 additions & 1 deletion doc/xml/release.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,15 @@
<commit subject="Update storage module to use StringIds.">
<github-pull-request id="1379"/>
</commit>
<commit subject="Update CipherType/CipherMode to StringId.">
<github-pull-request id="1384"/>
</commit>

<release-item-contributor-list>
<release-item-reviewer id="cynthia.shang"/>
</release-item-contributor-list>

<p>Add StringId type.</p>
<p>Add <code>StringId</code> type.</p>
</release-item>

<release-item>
Expand Down
4 changes: 2 additions & 2 deletions src/command/archive/get/get.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ archiveGetCheck(const StringList *archiveRequestList)
ArchiveGetFindCacheRepo cacheRepo =
{
.repoIdx = repoIdx,
.cipherType = cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, repoIdx)),
.cipherType = cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx),
.archiveList = lstNewP(sizeof(ArchiveGetFindCacheArchive)),
.warnList = strLstNew(),
};
Expand Down Expand Up @@ -839,7 +839,7 @@ static ProtocolParallelJob *archiveGetAsyncCallback(void *data, unsigned int cli
protocolCommandParamAdd(command, VARSTR(actual->file));
protocolCommandParamAdd(command, VARUINT(actual->repoIdx));
protocolCommandParamAdd(command, VARSTR(actual->archiveId));
protocolCommandParamAdd(command, VARUINT(actual->cipherType));
protocolCommandParamAdd(command, VARUINT64(actual->cipherType));
protocolCommandParamAdd(command, VARSTR(actual->cipherPassArchive));
}

Expand Down
2 changes: 1 addition & 1 deletion src/command/archive/get/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ archiveGetFileProtocol(const VariantList *paramList, ProtocolServer *server)
.file = varStr(varLstGet(paramList, paramFixed + (actualIdx * paramActual))),
.repoIdx = varUIntForce(varLstGet(paramList, paramFixed + (actualIdx * paramActual) + 1)),
.archiveId = varStr(varLstGet(paramList, paramFixed + (actualIdx * paramActual) + 2)),
.cipherType = (CipherType)varUIntForce(varLstGet(paramList, paramFixed + (actualIdx * paramActual) + 3)),
.cipherType = varUInt64(varLstGet(paramList, paramFixed + (actualIdx * paramActual) + 3)),
.cipherPassArchive = varStr(varLstGet(paramList, paramFixed + (actualIdx * paramActual) + 4)),
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/command/archive/push/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ archivePushFileProtocol(const VariantList *paramList, ProtocolServer *server)
{
.repoIdx = varUIntForce(varLstGet(paramList, paramIdx)),
.archiveId = varStr(varLstGet(paramList, paramIdx + 1)),
.cipherType = (CipherType)varUIntForce(varLstGet(paramList, paramIdx + 2)),
.cipherType = varUInt64(varLstGet(paramList, paramIdx + 2)),
.cipherPass = varStr(varLstGet(paramList, paramIdx + 3)),
});

Expand Down
4 changes: 2 additions & 2 deletions src/command/archive/push/push.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ archivePushCheck(bool pgPathSet)
storageRepoIdx(repoIdx);

// Get cipher type
CipherType repoCipherType = cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, repoIdx));
CipherType repoCipherType = cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx);

// Attempt to load the archive info file
InfoArchive *info = infoArchiveLoadFile(
Expand Down Expand Up @@ -478,7 +478,7 @@ archivePushAsyncCallback(void *data, unsigned int clientIdx)

protocolCommandParamAdd(command, VARUINT(data->repoIdx));
protocolCommandParamAdd(command, VARSTR(data->archiveId));
protocolCommandParamAdd(command, VARUINT(data->cipherType));
protocolCommandParamAdd(command, VARUINT64(data->cipherType));
protocolCommandParamAdd(command, VARSTR(data->cipherPass));
}

Expand Down
30 changes: 14 additions & 16 deletions src/command/backup/backup.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ backupBuildIncrPrior(const InfoBackup *infoBackup)
{
result = manifestLoadFile(
storageRepo(), strNewFmt(STORAGE_REPO_BACKUP "/%s/" BACKUP_MANIFEST_FILE, strZ(backupLabelPrior)),
cipherType(cfgOptionStr(cfgOptRepoCipherType)), infoPgCipherPass(infoBackupPg(infoBackup)));
cfgOptionStrId(cfgOptRepoCipherType), infoPgCipherPass(infoBackupPg(infoBackup)));
const ManifestData *manifestPriorData = manifestData(result);

LOG_INFO_FMT(
Expand Down Expand Up @@ -707,7 +707,7 @@ backupResumeFind(const Manifest *manifest, const String *cipherPassBackup)
TRY_BEGIN()
{
manifestResume = manifestLoadFile(
storageRepo(), manifestFile, cipherType(cfgOptionStr(cfgOptRepoCipherType)), cipherPassBackup);
storageRepo(), manifestFile, cfgOptionStrId(cfgOptRepoCipherType), cipherPassBackup);
const ManifestData *manifestResumeData = manifestData(manifestResume);

// Check pgBackRest version. This allows the resume implementation to be changed with each version of
Expand Down Expand Up @@ -961,7 +961,7 @@ backupFilePut(BackupData *backupData, Manifest *manifest, const String *name, ti

// Add encryption filter if required
cipherBlockFilterGroupAdd(
filterGroup, cipherType(cfgOptionStr(cfgOptRepoCipherType)), cipherModeEncrypt, manifestCipherSubPass(manifest));
filterGroup, cfgOptionStrId(cfgOptRepoCipherType), cipherModeEncrypt, manifestCipherSubPass(manifest));

// Add size filter last to calculate repo size
ioFilterGroupAdd(filterGroup, ioSizeNew());
Expand Down Expand Up @@ -1251,7 +1251,7 @@ backupManifestSaveCopy(Manifest *const manifest, const String *cipherPassBackup)

// Add encryption filter if required
cipherBlockFilterGroupAdd(
ioWriteFilterGroup(write), cipherType(cfgOptionStr(cfgOptRepoCipherType)), cipherModeEncrypt, cipherPassBackup);
ioWriteFilterGroup(write), cfgOptionStrId(cfgOptRepoCipherType), cipherModeEncrypt, cipherPassBackup);

// Save file
manifestSave(manifest, write);
Expand Down Expand Up @@ -1492,7 +1492,7 @@ static ProtocolParallelJob *backupJobCallback(void *data, unsigned int clientIdx
protocolCommandParamAdd(command, VARINT(jobData->compressLevel));
protocolCommandParamAdd(command, VARSTR(jobData->backupLabel));
protocolCommandParamAdd(command, VARBOOL(jobData->delta));
protocolCommandParamAdd(command, VARUINT(jobData->cipherType));
protocolCommandParamAdd(command, VARUINT64(jobData->cipherType));
protocolCommandParamAdd(command, VARSTR(jobData->cipherSubPass));

// Remove job from the queue
Expand Down Expand Up @@ -1583,7 +1583,7 @@ backupProcess(BackupData *backupData, Manifest *manifest, const String *lsnStart
.backupStandby = backupStandby,
.compressType = compressTypeEnum(cfgOptionStr(cfgOptCompressType)),
.compressLevel = cfgOptionInt(cfgOptCompressLevel),
.cipherType = cipherType(cfgOptionStr(cfgOptRepoCipherType)),
.cipherType = cfgOptionStrId(cfgOptRepoCipherType),
.cipherSubPass = manifestCipherSubPass(manifest),
.delta = cfgOptionBool(cfgOptDelta),
.lsnStart = cfgOptionBool(cfgOptOnline) ? pgLsnFromStr(lsnStart) : 0xFFFFFFFFFFFFFFFF,
Expand Down Expand Up @@ -1755,7 +1755,7 @@ backupArchiveCheckCopy(Manifest *manifest, unsigned int walSegmentSize, const St

// Loop through all the segments in the lsn range
InfoArchive *infoArchive = infoArchiveLoadFile(
storageRepo(), INFO_ARCHIVE_PATH_FILE_STR, cipherType(cfgOptionStr(cfgOptRepoCipherType)),
storageRepo(), INFO_ARCHIVE_PATH_FILE_STR, cfgOptionStrId(cfgOptRepoCipherType),
cfgOptionStrNull(cfgOptRepoCipherPass));
const String *archiveId = infoArchiveId(infoArchive);

Expand Down Expand Up @@ -1788,7 +1788,7 @@ backupArchiveCheckCopy(Manifest *manifest, unsigned int walSegmentSize, const St

// Decrypt with archive key if encrypted
cipherBlockFilterGroupAdd(
filterGroup, cipherType(cfgOptionStr(cfgOptRepoCipherType)), cipherModeDecrypt,
filterGroup, cfgOptionStrId(cfgOptRepoCipherType), cipherModeDecrypt,
infoArchiveCipherPass(infoArchive));

// Compress/decompress if archive and backup do not have the same compression settings
Expand All @@ -1806,8 +1806,7 @@ backupArchiveCheckCopy(Manifest *manifest, unsigned int walSegmentSize, const St

// Encrypt with backup key if encrypted
cipherBlockFilterGroupAdd(
filterGroup, cipherType(cfgOptionStr(cfgOptRepoCipherType)), cipherModeEncrypt,
manifestCipherSubPass(manifest));
filterGroup, cfgOptionStrId(cfgOptRepoCipherType), cipherModeEncrypt, manifestCipherSubPass(manifest));

// Add size filter last to calculate repo size
ioFilterGroupAdd(filterGroup, ioSizeNew());
Expand Down Expand Up @@ -1891,7 +1890,7 @@ backupComplete(InfoBackup *const infoBackup, Manifest *const manifest)
storageRepo(), strNewFmt(STORAGE_REPO_BACKUP "/%s/" BACKUP_MANIFEST_FILE, strZ(backupLabel)));

cipherBlockFilterGroupAdd(
ioReadFilterGroup(storageReadIo(manifestRead)), cipherType(cfgOptionStr(cfgOptRepoCipherType)), cipherModeDecrypt,
ioReadFilterGroup(storageReadIo(manifestRead)), cfgOptionStrId(cfgOptRepoCipherType), cipherModeDecrypt,
infoPgCipherPass(infoBackupPg(infoBackup)));

StorageWrite *manifestWrite = storageNewWriteP(
Expand All @@ -1903,7 +1902,7 @@ backupComplete(InfoBackup *const infoBackup, Manifest *const manifest)
ioFilterGroupAdd(ioWriteFilterGroup(storageWriteIo(manifestWrite)), compressFilter(compressTypeGz, 9));

cipherBlockFilterGroupAdd(
ioWriteFilterGroup(storageWriteIo(manifestWrite)), cipherType(cfgOptionStr(cfgOptRepoCipherType)), cipherModeEncrypt,
ioWriteFilterGroup(storageWriteIo(manifestWrite)), cfgOptionStrId(cfgOptRepoCipherType), cipherModeEncrypt,
infoPgCipherPass(infoBackupPg(infoBackup)));

storageCopyP(manifestRead, manifestWrite);
Expand All @@ -1922,7 +1921,7 @@ backupComplete(InfoBackup *const infoBackup, Manifest *const manifest)
infoBackupDataAdd(infoBackup, manifest);

infoBackupSaveFile(
infoBackup, storageRepoWrite(), INFO_BACKUP_PATH_FILE_STR, cipherType(cfgOptionStr(cfgOptRepoCipherType)),
infoBackup, storageRepoWrite(), INFO_BACKUP_PATH_FILE_STR, cfgOptionStrId(cfgOptRepoCipherType),
cfgOptionStrNull(cfgOptRepoCipherPass));
}
MEM_CONTEXT_TEMP_END();
Expand Down Expand Up @@ -1954,8 +1953,7 @@ cmdBackup(void)

// Load backup.info
InfoBackup *infoBackup = infoBackupLoadFileReconstruct(
storageRepo(), INFO_BACKUP_PATH_FILE_STR, cipherType(cfgOptionStr(cfgOptRepoCipherType)),
cfgOptionStrNull(cfgOptRepoCipherPass));
storageRepo(), INFO_BACKUP_PATH_FILE_STR, cfgOptionStrId(cfgOptRepoCipherType), cfgOptionStrNull(cfgOptRepoCipherPass));
InfoPgData infoPg = infoPgDataCurrent(infoBackupPg(infoBackup));
const String *cipherPassBackup = infoPgCipherPass(infoBackupPg(infoBackup));

Expand All @@ -1982,7 +1980,7 @@ cmdBackup(void)

// Build an incremental backup if type is not full (manifestPrior will be freed in this call)
if (!backupBuildIncr(infoBackup, manifest, manifestPrior, backupStartResult.walSegmentName))
manifestCipherSubPassSet(manifest, cipherPassGen(cipherType(cfgOptionStr(cfgOptRepoCipherType))));
manifestCipherSubPassSet(manifest, cipherPassGen(cfgOptionStrId(cfgOptRepoCipherType)));

// Set delta if it is not already set and the manifest requires it
if (!cfgOptionBool(cfgOptDelta) && varBool(manifestData(manifest)->backupOptionDelta))
Expand Down
2 changes: 1 addition & 1 deletion src/command/backup/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ backupFile(
FUNCTION_LOG_PARAM(INT, repoFileCompressLevel); // Compression level for repo file
FUNCTION_LOG_PARAM(STRING, backupLabel); // Label of current backup
FUNCTION_LOG_PARAM(BOOL, delta); // Is the delta option on?
FUNCTION_LOG_PARAM(ENUM, cipherType); // Encryption type
FUNCTION_LOG_PARAM(STRING_ID, cipherType); // Encryption type
FUNCTION_TEST_PARAM(STRING, cipherPass); // Password to access the repo file if encrypted
FUNCTION_LOG_END();

Expand Down
4 changes: 2 additions & 2 deletions src/command/backup/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ backupFileProtocol(const VariantList *paramList, ProtocolServer *server)
varBool(varLstGet(paramList, 3)), varStr(varLstGet(paramList, 4)), varBool(varLstGet(paramList, 5)),
varUInt64(varLstGet(paramList, 6)), varStr(varLstGet(paramList, 7)), varBool(varLstGet(paramList, 8)),
(CompressType)varUIntForce(varLstGet(paramList, 9)), varIntForce(varLstGet(paramList, 10)),
varStr(varLstGet(paramList, 11)), varBool(varLstGet(paramList, 12)),
(CipherType)varUIntForce(varLstGet(paramList, 13)), varStr(varLstGet(paramList, 14)));
varStr(varLstGet(paramList, 11)), varBool(varLstGet(paramList, 12)), varUInt64(varLstGet(paramList, 13)),
varStr(varLstGet(paramList, 14)));

// Return backup result
VariantList *resultList = varLstNew();
Expand Down
6 changes: 3 additions & 3 deletions src/command/check/check.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ checkStandby(const DbGetResult dbGroup, unsigned int pgPathDefinedTotal)

// Check that the backup and archive info files exist and are valid for the current database of the stanza
checkStanzaInfoPg(
storageRepo, pgControl.version, pgControl.systemId, cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, repoIdx)),
storageRepo, pgControl.version, pgControl.systemId, cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx),
cfgOptionIdxStrNull(cfgOptRepoCipherPass, repoIdx));
}

Expand Down Expand Up @@ -134,12 +134,12 @@ checkPrimary(const DbGetResult dbGroup)

// Check that the backup and archive info files exist and are valid for the current database of the stanza
checkStanzaInfoPg(
storageRepo, pgControl.version, pgControl.systemId, cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, repoIdx)),
storageRepo, pgControl.version, pgControl.systemId, cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx),
cfgOptionIdxStrNull(cfgOptRepoCipherPass, repoIdx));

// Attempt to load the archive info file and retrieve the archiveId
InfoArchive *archiveInfo = infoArchiveLoadFile(
storageRepo, INFO_ARCHIVE_PATH_FILE_STR, cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, repoIdx)),
storageRepo, INFO_ARCHIVE_PATH_FILE_STR, cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx),
cfgOptionIdxStrNull(cfgOptRepoCipherPass, repoIdx));

repoArchiveId[repoIdx] = infoArchiveId(archiveInfo);
Expand Down
2 changes: 1 addition & 1 deletion src/command/check/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ checkStanzaInfoPg(
FUNCTION_LOG_PARAM(STORAGE, storage);
FUNCTION_LOG_PARAM(UINT, pgVersion);
FUNCTION_LOG_PARAM(UINT64, pgSystemId);
FUNCTION_LOG_PARAM(ENUM, cipherType);
FUNCTION_LOG_PARAM(STRING_ID, cipherType);
FUNCTION_TEST_PARAM(STRING, cipherPass);
FUNCTION_TEST_END();

Expand Down
9 changes: 4 additions & 5 deletions src/command/expire/expire.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ removeExpiredArchive(InfoBackup *infoBackup, bool timeBasedFullRetention, unsign
{
// Attempt to load the archive info file
InfoArchive *infoArchive = infoArchiveLoadFile(
storageRepoIdx(repoIdx), INFO_ARCHIVE_PATH_FILE_STR, cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, repoIdx)),
storageRepoIdx(repoIdx), INFO_ARCHIVE_PATH_FILE_STR, cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx),
cfgOptionIdxStrNull(cfgOptRepoCipherPass, repoIdx));

InfoPg *infoArchivePgData = infoArchivePg(infoArchive);
Expand Down Expand Up @@ -828,7 +828,7 @@ removeExpiredBackup(InfoBackup *infoBackup, const String *adhocBackupLabel, unsi
else
{
Manifest *manifestResume = manifestLoadFile(
storageRepoIdx(repoIdx), manifestFileName, cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, repoIdx)),
storageRepoIdx(repoIdx), manifestFileName, cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx),
infoPgCipherPass(infoBackupPg(infoBackup)));

// If the ancestor of the resumable backup still exists in backup.info then do not remove the resumable backup
Expand Down Expand Up @@ -915,7 +915,7 @@ cmdExpire(void)
{
// Load the backup.info
infoBackup = infoBackupLoadFileReconstruct(
storageRepo, INFO_BACKUP_PATH_FILE_STR, cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, repoIdx)),
storageRepo, INFO_BACKUP_PATH_FILE_STR, cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx),
cfgOptionIdxStrNull(cfgOptRepoCipherPass, repoIdx));

// If a backupLabel was set, then attempt to expire the requested backup
Expand Down Expand Up @@ -960,8 +960,7 @@ cmdExpire(void)
{
infoBackupSaveFile(
infoBackup, storageRepoIdxWrite(repoIdx), INFO_BACKUP_PATH_FILE_STR,
cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, repoIdx)),
cfgOptionIdxStrNull(cfgOptRepoCipherPass, repoIdx));
cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx), cfgOptionIdxStrNull(cfgOptRepoCipherPass, repoIdx));
}

// Remove all files on disk that are now expired
Expand Down
Loading

0 comments on commit 85fc3da

Please sign in to comment.