1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-30 05:39:12 +02:00

Update config module to recent coding standards.

Add const as appropriate and avoid initializing variables if the variable will definitely be set later on or is immediately returned.
This commit is contained in:
David Steele 2024-04-21 12:06:39 +10:00
parent 0e36e1a2fc
commit 19411f39d2
6 changed files with 106 additions and 107 deletions

View File

@ -62,14 +62,14 @@ cfgParseSize(const String *const value)
ASSERT(value != NULL);
// Lowercase the value
String *valueLower = strLower(strDup(value));
String *const valueLower = strLower(strDup(value));
// Match the value against possible values
if (regExpMatchOne(STRDEF("^[0-9]+(kib|kb|k|mib|mb|m|gib|gb|g|tib|tb|t|pib|pb|p|b)*$"), valueLower))
{
// Get the character array and size
const char *strArray = strZ(valueLower);
size_t size = strSize(valueLower);
const char *const strArray = strZ(valueLower);
const size_t size = strSize(valueLower);
int chrPos = -1;
// If there is a 'b' on the end, then see if the previous character is a number

View File

@ -18,7 +18,7 @@ static Config *configLocal = NULL;
/**********************************************************************************************************************************/
FN_EXTERN void
cfgInit(Config *config)
cfgInit(Config *const config)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM_P(VOID, config);
@ -88,13 +88,13 @@ cfgCommandJobRetry(void)
ASSERT(configLocal != NULL);
// Return NULL if no retries
unsigned int retryTotal = cfgOptionUInt(cfgOptJobRetry);
const unsigned int retryTotal = cfgOptionUInt(cfgOptJobRetry);
if (retryTotal == 0)
FUNCTION_TEST_RETURN(VARIANT_LIST, NULL);
// Build retry list
VariantList *result = varLstNew();
VariantList *const result = varLstNew();
MEM_CONTEXT_BEGIN(lstMemContext((List *)result))
{
@ -229,7 +229,7 @@ cfgLogLevelDefault(void)
/**********************************************************************************************************************************/
FN_EXTERN bool
cfgOptionGroup(ConfigOption optionId)
cfgOptionGroup(const ConfigOption optionId)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, optionId);
@ -274,7 +274,7 @@ cfgOptionGroupName(const ConfigOptionGroup groupId, const unsigned int groupIdx)
/**********************************************************************************************************************************/
FN_EXTERN unsigned int
cfgOptionGroupId(ConfigOption optionId)
cfgOptionGroupId(const ConfigOption optionId)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, optionId);
@ -289,7 +289,7 @@ cfgOptionGroupId(ConfigOption optionId)
/**********************************************************************************************************************************/
FN_EXTERN unsigned int
cfgOptionGroupIdxDefault(ConfigOptionGroup groupId)
cfgOptionGroupIdxDefault(const ConfigOptionGroup groupId)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, groupId);
@ -304,7 +304,7 @@ cfgOptionGroupIdxDefault(ConfigOptionGroup groupId)
/**********************************************************************************************************************************/
FN_EXTERN unsigned int
cfgOptionGroupIdxToKey(ConfigOptionGroup groupId, unsigned int groupIdx)
cfgOptionGroupIdxToKey(const ConfigOptionGroup groupId, const unsigned int groupIdx)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, groupId);
@ -320,7 +320,7 @@ cfgOptionGroupIdxToKey(ConfigOptionGroup groupId, unsigned int groupIdx)
/**********************************************************************************************************************************/
FN_EXTERN unsigned int
cfgOptionKeyToIdx(ConfigOption optionId, unsigned int key)
cfgOptionKeyToIdx(const ConfigOption optionId, const unsigned int key)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, optionId);
@ -335,7 +335,7 @@ cfgOptionKeyToIdx(ConfigOption optionId, unsigned int key)
// If then option is in a group then search for the key, else the index is 0
if (cfgOptionGroup(optionId))
{
unsigned int groupId = cfgOptionGroupId(optionId);
const unsigned int groupId = cfgOptionGroupId(optionId);
// Seach the group for the key
for (; result < cfgOptionGroupIdxTotal(groupId); result++)
@ -354,7 +354,7 @@ cfgOptionKeyToIdx(ConfigOption optionId, unsigned int key)
/**********************************************************************************************************************************/
FN_EXTERN unsigned int
cfgOptionGroupIdxTotal(ConfigOptionGroup groupId)
cfgOptionGroupIdxTotal(const ConfigOptionGroup groupId)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, groupId);
@ -368,7 +368,7 @@ cfgOptionGroupIdxTotal(ConfigOptionGroup groupId)
/**********************************************************************************************************************************/
FN_EXTERN unsigned int
cfgOptionIdxDefault(ConfigOption optionId)
cfgOptionIdxDefault(const ConfigOption optionId)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, optionId);
@ -386,7 +386,7 @@ cfgOptionIdxDefault(ConfigOption optionId)
/**********************************************************************************************************************************/
FN_EXTERN unsigned int
cfgOptionIdxTotal(ConfigOption optionId)
cfgOptionIdxTotal(const ConfigOption optionId)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, optionId);
@ -402,7 +402,7 @@ cfgOptionIdxTotal(ConfigOption optionId)
/**********************************************************************************************************************************/
FN_EXTERN const String *
cfgOptionDefault(ConfigOption optionId)
cfgOptionDefault(const ConfigOption optionId)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, optionId);
@ -420,7 +420,7 @@ cfgOptionDefault(ConfigOption optionId)
}
FN_EXTERN void
cfgOptionDefaultSet(ConfigOption optionId, const Variant *defaultValue)
cfgOptionDefaultSet(const ConfigOption optionId, const Variant *defaultValue)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, optionId);
@ -539,7 +539,7 @@ cfgOptionDisplay(const ConfigOption optionId)
Get option name by id
***********************************************************************************************************************************/
FN_EXTERN const char *
cfgOptionName(ConfigOption optionId)
cfgOptionName(const ConfigOption optionId)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, optionId);
@ -551,7 +551,7 @@ cfgOptionName(ConfigOption optionId)
}
FN_EXTERN const char *
cfgOptionIdxName(ConfigOption optionId, unsigned int optionIdx)
cfgOptionIdxName(const ConfigOption optionId, const unsigned int optionIdx)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, optionId);
@ -596,7 +596,7 @@ cfgOptionIdxName(ConfigOption optionId, unsigned int optionIdx)
/**********************************************************************************************************************************/
FN_EXTERN bool
cfgOptionIdxNegate(ConfigOption optionId, unsigned int optionIdx)
cfgOptionIdxNegate(const ConfigOption optionId, const unsigned int optionIdx)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, optionId);
@ -614,7 +614,7 @@ cfgOptionIdxNegate(ConfigOption optionId, unsigned int optionIdx)
/**********************************************************************************************************************************/
FN_EXTERN bool
cfgOptionIdxReset(ConfigOption optionId, unsigned int optionIdx)
cfgOptionIdxReset(const ConfigOption optionId, const unsigned int optionIdx)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, optionId);
@ -654,8 +654,8 @@ cfgOptionIdxInternal(
THROW_FMT(AssertError, "option '%s' is not valid for the current command", cfgOptionIdxName(optionId, optionIdx));
// If the option is not NULL then check it is the requested type
ConfigOptionData *const option = &configLocal->option[optionId];
ConfigOptionValue *const result = &option->index[optionIdx];
const ConfigOptionData *const option = &configLocal->option[optionId];
const ConfigOptionValue *const result = &option->index[optionIdx];
if (result->set)
{
@ -670,7 +670,7 @@ cfgOptionIdxInternal(
else if (!nullAllowed)
THROW_FMT(AssertError, "option '%s' is null but non-null was requested", cfgOptionIdxName(optionId, optionIdx));
FUNCTION_TEST_RETURN_TYPE_P(ConfigOptionValue, result);
FUNCTION_TEST_RETURN_TYPE_CONST_P(ConfigOptionValue, result);
}
FN_EXTERN Variant *
@ -721,7 +721,7 @@ cfgOptionIdxVar(const ConfigOption optionId, const unsigned int optionIdx)
}
FN_EXTERN bool
cfgOptionIdxBool(const ConfigOption optionId, unsigned int optionIdx)
cfgOptionIdxBool(const ConfigOption optionId, const unsigned int optionIdx)
{
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(ENUM, optionId);
@ -784,7 +784,7 @@ cfgOptionIdxUInt64(const ConfigOption optionId, const unsigned int optionIdx)
}
FN_EXTERN const KeyValue *
cfgOptionIdxKv(ConfigOption optionId, unsigned int optionIdx)
cfgOptionIdxKv(const ConfigOption optionId, const unsigned int optionIdx)
{
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(ENUM, optionId);
@ -795,7 +795,7 @@ cfgOptionIdxKv(ConfigOption optionId, unsigned int optionIdx)
}
FN_EXTERN const KeyValue *
cfgOptionIdxKvNull(ConfigOption optionId, unsigned int optionIdx)
cfgOptionIdxKvNull(const ConfigOption optionId, const unsigned int optionIdx)
{
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(ENUM, optionId);
@ -806,7 +806,7 @@ cfgOptionIdxKvNull(ConfigOption optionId, unsigned int optionIdx)
}
FN_EXTERN const VariantList *
cfgOptionIdxLst(ConfigOption optionId, unsigned int optionIdx)
cfgOptionIdxLst(const ConfigOption optionId, const unsigned int optionIdx)
{
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(ENUM, optionId);
@ -831,7 +831,7 @@ cfgOptionIdxLst(ConfigOption optionId, unsigned int optionIdx)
}
FN_EXTERN const String *
cfgOptionIdxStr(ConfigOption optionId, unsigned int optionIdx)
cfgOptionIdxStr(const ConfigOption optionId, const unsigned int optionIdx)
{
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(ENUM, optionId);
@ -842,7 +842,7 @@ cfgOptionIdxStr(ConfigOption optionId, unsigned int optionIdx)
}
FN_EXTERN const String *
cfgOptionIdxStrNull(ConfigOption optionId, unsigned int optionIdx)
cfgOptionIdxStrNull(const ConfigOption optionId, const unsigned int optionIdx)
{
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(ENUM, optionId);
@ -853,7 +853,7 @@ cfgOptionIdxStrNull(ConfigOption optionId, unsigned int optionIdx)
}
FN_EXTERN StringId
cfgOptionIdxStrId(ConfigOption optionId, unsigned int optionIdx)
cfgOptionIdxStrId(const ConfigOption optionId, const unsigned int optionIdx)
{
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(ENUM, optionId);
@ -865,7 +865,7 @@ cfgOptionIdxStrId(ConfigOption optionId, unsigned int optionIdx)
/**********************************************************************************************************************************/
FN_EXTERN void
cfgOptionSet(ConfigOption optionId, ConfigSource source, const Variant *value)
cfgOptionSet(const ConfigOption optionId, const ConfigSource source, const Variant *const value)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, optionId);
@ -879,7 +879,8 @@ cfgOptionSet(ConfigOption optionId, ConfigSource source, const Variant *value)
}
FN_EXTERN void
cfgOptionIdxSet(ConfigOption optionId, unsigned int optionIdx, ConfigSource source, const Variant *value)
cfgOptionIdxSet(
const ConfigOption optionId, const unsigned int optionIdx, const ConfigSource source, const Variant *const value)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, optionId);
@ -895,7 +896,7 @@ cfgOptionIdxSet(ConfigOption optionId, unsigned int optionIdx, ConfigSource sour
ASSERT((!group && optionIdx == 0) || (group && optionIdx < indexTotal));
// Set the source
ConfigOptionData *const option = &configLocal->option[optionId];
const ConfigOptionData *const option = &configLocal->option[optionId];
ConfigOptionValue *const optionValue = &option->index[optionIdx];
optionValue->source = source;
@ -966,7 +967,7 @@ cfgOptionIdxSet(ConfigOption optionId, unsigned int optionIdx, ConfigSource sour
/**********************************************************************************************************************************/
FN_EXTERN ConfigSource
cfgOptionSource(ConfigOption optionId)
cfgOptionSource(const ConfigOption optionId)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, optionId);
@ -976,7 +977,7 @@ cfgOptionSource(ConfigOption optionId)
}
FN_EXTERN ConfigSource
cfgOptionIdxSource(ConfigOption optionId, unsigned int optionIdx)
cfgOptionIdxSource(const ConfigOption optionId, const unsigned int optionIdx)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, optionId);
@ -994,7 +995,7 @@ cfgOptionIdxSource(ConfigOption optionId, unsigned int optionIdx)
/**********************************************************************************************************************************/
FN_EXTERN bool
cfgOptionTest(ConfigOption optionId)
cfgOptionTest(const ConfigOption optionId)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, optionId);
@ -1004,7 +1005,7 @@ cfgOptionTest(ConfigOption optionId)
}
FN_EXTERN bool
cfgOptionIdxTest(ConfigOption optionId, unsigned int optionIdx)
cfgOptionIdxTest(const ConfigOption optionId, const unsigned int optionIdx)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, optionId);
@ -1022,7 +1023,7 @@ cfgOptionIdxTest(ConfigOption optionId, unsigned int optionIdx)
/**********************************************************************************************************************************/
FN_EXTERN bool
cfgOptionValid(ConfigOption optionId)
cfgOptionValid(const ConfigOption optionId)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, optionId);
@ -1035,7 +1036,7 @@ cfgOptionValid(ConfigOption optionId)
}
FN_EXTERN void
cfgOptionInvalidate(ConfigOption optionId)
cfgOptionInvalidate(const ConfigOption optionId)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, optionId);

View File

@ -13,7 +13,9 @@ Exec Configuration
/**********************************************************************************************************************************/
FN_EXTERN StringList *
cfgExecParam(ConfigCommand commandId, ConfigCommandRole commandRoleId, const KeyValue *optionReplace, bool local, bool quote)
cfgExecParam(
const ConfigCommand commandId, const ConfigCommandRole commandRoleId, const KeyValue *const optionReplace, const bool local,
const bool quote)
{
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(ENUM, commandId);
@ -23,13 +25,11 @@ cfgExecParam(ConfigCommand commandId, ConfigCommandRole commandRoleId, const Key
FUNCTION_LOG_PARAM(BOOL, quote); // Do parameters with spaces need to be quoted?
FUNCTION_LOG_END();
StringList *result = NULL;
StringList *const result = strLstNew();
MEM_CONTEXT_TEMP_BEGIN()
{
// Loop though options and add the ones that apply to the specified command
result = strLstNew();
for (ConfigOption optionId = 0; optionId < CFG_OPTION_TOTAL; optionId++)
{
// Skip the option if it is not valid for the original/specified command or if is secure. Also skip repo1-cipher-type
@ -42,12 +42,12 @@ cfgExecParam(ConfigCommand commandId, ConfigCommandRole commandRoleId, const Key
}
// Loop through option indexes
unsigned int optionIdxTotal = cfgOptionGroup(optionId) ? cfgOptionGroupIdxTotal(cfgOptionGroupId(optionId)) : 1;
const unsigned int optionIdxTotal = cfgOptionGroup(optionId) ? cfgOptionGroupIdxTotal(cfgOptionGroupId(optionId)) : 1;
for (unsigned int optionIdx = 0; optionIdx < optionIdxTotal; optionIdx++)
{
// First check for a replacement
const Variant *key = VARSTRZ(cfgOptionIdxName(optionId, optionIdx));
const Variant *const key = VARSTRZ(cfgOptionIdxName(optionId, optionIdx));
const Variant *value = NULL;
bool exists = false;
@ -92,8 +92,8 @@ cfgExecParam(ConfigCommand commandId, ConfigCommandRole commandRoleId, const Key
{
valueList = strLstNew();
const KeyValue *optionKv = varKv(value);
const VariantList *keyList = kvKeyList(optionKv);
const KeyValue *const optionKv = varKv(value);
const VariantList *const keyList = kvKeyList(optionKv);
for (unsigned int keyIdx = 0; keyIdx < varLstSize(keyList); keyIdx++)
{
@ -134,9 +134,6 @@ cfgExecParam(ConfigCommand commandId, ConfigCommandRole commandRoleId, const Key
// Add the command
strLstAdd(result, cfgParseCommandRoleName(commandId, commandRoleId));
// Move list to the prior context
strLstMove(result, memContextPrior());
}
MEM_CONTEXT_TEMP_END();

View File

@ -144,7 +144,7 @@ cfgLoadUpdateOption(void)
}
else if (cfgOptionSource(cfgOptDbTimeout) == cfgSourceDefault)
{
int64_t dbTimeout = cfgOptionInt64(cfgOptProtocolTimeout) - (int64_t)(30 * MSEC_PER_SEC);
const int64_t dbTimeout = cfgOptionInt64(cfgOptProtocolTimeout) - (int64_t)(30 * MSEC_PER_SEC);
// Normally the protocol time will be greater than 45 seconds so db timeout can be at least 15 seconds
if (dbTimeout >= (int64_t)(15 * MSEC_PER_SEC))
@ -216,16 +216,16 @@ cfgLoadUpdateOption(void)
{
const BackupType archiveRetentionType = (BackupType)cfgOptionIdxStrId(cfgOptRepoRetentionArchiveType, optionIdx);
const String *msgArchiveOff = strNewFmt(
"WAL segments will not be expired: option '%s=%s' but", cfgOptionIdxName(cfgOptRepoRetentionArchiveType, optionIdx),
strZ(strIdToStr(archiveRetentionType)));
// If the archive retention is not explicitly set then determine what it should be defaulted to
if (!cfgOptionIdxTest(cfgOptRepoRetentionArchive, optionIdx))
{
// If repo-retention-archive-type is default (full), then if repo-retention-full is set, set the
// repo-retention-archive to this value when retention-full-type is 'count', else ignore archiving. If
// retention-full-type is 'time' then the expire command will default the archive retention accordingly.
const String *const msgArchiveOff = strNewFmt(
"WAL segments will not be expired: option '%s=%s' but",
cfgOptionIdxName(cfgOptRepoRetentionArchiveType, optionIdx), strZ(strIdToStr(archiveRetentionType)));
switch (archiveRetentionType)
{
case backupTypeFull:

View File

@ -295,7 +295,7 @@ typedef struct ParseOption
Get the indexed value, creating the array to contain it if needed
***********************************************************************************************************************************/
static ParseOptionValue *
parseOptionIdxValue(ParseOption *optionList, unsigned int optionId, unsigned int optionKeyIdx)
parseOptionIdxValue(ParseOption *const optionList, const unsigned int optionId, const unsigned int optionKeyIdx)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM_P(PARSE_OPTION, optionList); // Structure containing all options being parsed
@ -833,7 +833,7 @@ typedef struct CfgParseOptionalRuleState
static bool
cfgParseOptionalRule(
CfgParseOptionalRuleState *optionalRules, ParseRuleOptionalType optionalRuleType, ConfigCommand commandId,
CfgParseOptionalRuleState *const optionalRules, const ParseRuleOptionalType optionalRuleType, const ConfigCommand commandId,
const ConfigOption optionId)
{
FUNCTION_TEST_BEGIN();
@ -1129,7 +1129,7 @@ cfgParseOptionalFilterDepend(PackRead *const filter, const Config *const config,
/**********************************************************************************************************************************/
FN_EXTERN const String *
cfgParseOptionDefault(ConfigCommand commandId, ConfigOption optionId)
cfgParseOptionDefault(const ConfigCommand commandId, const ConfigOption optionId)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, commandId);
@ -1155,7 +1155,7 @@ cfgParseOptionDefault(ConfigCommand commandId, ConfigOption optionId)
/**********************************************************************************************************************************/
FN_EXTERN const char *
cfgParseOptionName(ConfigOption optionId)
cfgParseOptionName(const ConfigOption optionId)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, optionId);
@ -1168,7 +1168,7 @@ cfgParseOptionName(ConfigOption optionId)
/**********************************************************************************************************************************/
FN_EXTERN const char *
cfgParseOptionKeyIdxName(ConfigOption optionId, unsigned int keyIdx)
cfgParseOptionKeyIdxName(const ConfigOption optionId, const unsigned int keyIdx)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, optionId);
@ -1194,7 +1194,7 @@ cfgParseOptionKeyIdxName(ConfigOption optionId, unsigned int keyIdx)
/**********************************************************************************************************************************/
FN_EXTERN bool
cfgParseOptionRequired(ConfigCommand commandId, ConfigOption optionId)
cfgParseOptionRequired(const ConfigCommand commandId, const ConfigOption optionId)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, commandId);
@ -1227,7 +1227,7 @@ cfgParseOptionRequired(ConfigCommand commandId, ConfigOption optionId)
/**********************************************************************************************************************************/
FN_EXTERN bool
cfgParseOptionSecure(ConfigOption optionId)
cfgParseOptionSecure(const ConfigOption optionId)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, optionId);
@ -1240,7 +1240,7 @@ cfgParseOptionSecure(ConfigOption optionId)
/**********************************************************************************************************************************/
FN_EXTERN ConfigOptionType
cfgParseOptionType(ConfigOption optionId)
cfgParseOptionType(const ConfigOption optionId)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, optionId);
@ -1253,7 +1253,7 @@ cfgParseOptionType(ConfigOption optionId)
/**********************************************************************************************************************************/
FN_EXTERN bool
cfgParseOptionValid(ConfigCommand commandId, ConfigCommandRole commandRoleId, ConfigOption optionId)
cfgParseOptionValid(const ConfigCommand commandId, const ConfigCommandRole commandRoleId, const ConfigOption optionId)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, commandId);
@ -1296,7 +1296,7 @@ Rules:
will not be required to exist since this is a default override.
***********************************************************************************************************************************/
static void
cfgFileLoadPart(String **config, const Buffer *configPart)
cfgFileLoadPart(String **const config, const Buffer *const configPart)
{
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM_P(STRING, config);
@ -1331,12 +1331,12 @@ cfgFileLoadPart(String **config, const Buffer *configPart)
static String *
cfgFileLoad(
const Storage *storage, // Storage to load configs
const ParseOption *optionList, // All options and their current settings
const Storage *const storage, // Storage to load configs
const ParseOption *const optionList, // All options and their current settings
// NOTE: Passing defaults to enable more complete test coverage
const String *optConfigDefault, // Current default for --config option
const String *optConfigIncludePathDefault, // Current default for --config-include-path option
const String *origConfigDefault) // Original --config option default (/etc/pgbackrest.conf)
const String *const origConfigDefault) // Original --config option default (/etc/pgbackrest.conf)
{
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(STORAGE, storage);
@ -1358,14 +1358,15 @@ cfgFileLoad(
// If the option is specified on the command line, then found will be true meaning the file is required to exist,
// else it is optional
bool configFound = optionList[cfgOptConfig].indexList != NULL && optionList[cfgOptConfig].indexList[0].found;
const bool configFound = optionList[cfgOptConfig].indexList != NULL && optionList[cfgOptConfig].indexList[0].found;
bool configRequired = configFound;
bool configPathRequired = optionList[cfgOptConfigPath].indexList != NULL && optionList[cfgOptConfigPath].indexList[0].found;
const bool configPathRequired =
optionList[cfgOptConfigPath].indexList != NULL && optionList[cfgOptConfigPath].indexList[0].found;
bool configIncludeRequired =
optionList[cfgOptConfigIncludePath].indexList != NULL && optionList[cfgOptConfigIncludePath].indexList[0].found;
// Save default for later determining if must check old original default config path
const String *optConfigDefaultCurrent = optConfigDefault;
const String *const optConfigDefaultCurrent = optConfigDefault;
// If the config-path option is found on the command line, then its value will override the base path defaults for config and
// config-include-path
@ -1406,7 +1407,7 @@ cfgFileLoad(
configFileName = optConfigDefault;
// Load the config file
Buffer *buffer = storageGetP(storageNewReadP(storage, configFileName, .ignoreMissing = !configRequired));
const Buffer *buffer = storageGetP(storageNewReadP(storage, configFileName, .ignoreMissing = !configRequired));
// Convert the contents of the file buffer to the config string object
if (buffer != NULL)
@ -1437,7 +1438,7 @@ cfgFileLoad(
configIncludePath = optConfigIncludePathDefault;
// Get a list of conf files from the specified path -error on missing directory if the option was passed on the command line
StringList *list = storageListP(
StringList *const list = storageListP(
storage, configIncludePath, .expression = STRDEF(".+\\.conf$"), .errorOnMissing = configIncludeRequired,
.nullOnMissing = !configIncludeRequired);
@ -1575,7 +1576,7 @@ cfgParse(const Storage *const storage, const unsigned int argListSize, const cha
arg += 2;
// Get the option name and the value when separated by =
const String *optionName = NULL;
const String *optionName;
const String *optionArg = NULL;
const char *const equalPtr = strchr(arg, '=');
@ -1656,7 +1657,7 @@ cfgParse(const Storage *const storage, const unsigned int argListSize, const cha
}
// If the option has not been found yet then set it
ParseOptionValue *optionValue = parseOptionIdxValue(parseOptionList, option.id, option.keyIdx);
ParseOptionValue *const optionValue = parseOptionIdxValue(parseOptionList, option.id, option.keyIdx);
if (!optionValue->found)
{
@ -1847,14 +1848,14 @@ cfgParse(const Storage *const storage, const unsigned int argListSize, const cha
if (strstr(keyValue, PGBACKREST_ENV) == keyValue)
{
// Find the first = char
const char *equalPtr = strchr(keyValue, '=');
const char *const equalPtr = strchr(keyValue, '=');
ASSERT(equalPtr != NULL);
// Get key and value
const String *key = strReplaceChr(
const String *const key = strReplaceChr(
strLower(strNewZN(keyValue + PGBACKREST_ENV_SIZE, (size_t)(equalPtr - (keyValue + PGBACKREST_ENV_SIZE)))),
'_', '-');
const String *value = STR(equalPtr + 1);
const String *const value = STR(equalPtr + 1);
// Find the option
CfgParseOptionResult option = cfgParseOptionP(key);
@ -1950,7 +1951,7 @@ cfgParse(const Storage *const storage, const unsigned int argListSize, const cha
stanza = strLstGet(parseOptionList[cfgOptStanza].indexList[0].valueList, 0);
// Build list of sections to search for options
StringList *sectionList = strLstNew();
StringList *const sectionList = strLstNew();
if (stanza != NULL)
{
@ -1964,17 +1965,17 @@ cfgParse(const Storage *const storage, const unsigned int argListSize, const cha
// Loop through sections to search for options
for (unsigned int sectionIdx = 0; sectionIdx < strLstSize(sectionList); sectionIdx++)
{
String *section = strLstGet(sectionList, sectionIdx);
const String *const section = strLstGet(sectionList, sectionIdx);
const StringList *const keyList = iniSectionKeyList(configParseLocal.ini, section);
KeyValue *optionFound = kvNew();
KeyValue *const optionFound = kvNew();
// Loop through keys to search for options
for (unsigned int keyIdx = 0; keyIdx < strLstSize(keyList); keyIdx++)
{
String *key = strLstGet(keyList, keyIdx);
String *const key = strLstGet(keyList, keyIdx);
// Find the optionName in the main list
CfgParseOptionResult option = cfgParseOptionP(key);
const CfgParseOptionResult option = cfgParseOptionP(key);
// Warn if the option not found
if (!option.found)
@ -2003,8 +2004,8 @@ cfgParse(const Storage *const storage, const unsigned int argListSize, const cha
}
// Make sure this option does not appear in the same section with an alternate name
const Variant *optionFoundKey = VARUINT64(option.id * CFG_OPTION_KEY_MAX + option.keyIdx);
const Variant *optionFoundName = kvGet(optionFound, optionFoundKey);
const Variant *const optionFoundKey = VARUINT64(option.id * CFG_OPTION_KEY_MAX + option.keyIdx);
const Variant *const optionFoundName = kvGet(optionFound, optionFoundKey);
if (optionFoundName != NULL)
{
@ -2041,7 +2042,7 @@ cfgParse(const Storage *const storage, const unsigned int argListSize, const cha
}
// Continue if this option has already been found in another section or command-line/environment
ParseOptionValue *optionValue = parseOptionIdxValue(parseOptionList, option.id, option.keyIdx);
ParseOptionValue *const optionValue = parseOptionIdxValue(parseOptionList, option.id, option.keyIdx);
if (optionValue->found)
continue;
@ -2065,7 +2066,7 @@ cfgParse(const Storage *const storage, const unsigned int argListSize, const cha
else
{
// Get the option value
const String *value = iniGet(configParseLocal.ini, section, key);
const String *const value = iniGet(configParseLocal.ini, section, key);
if (strSize(value) == 0)
{
@ -2127,7 +2128,7 @@ cfgParse(const Storage *const storage, const unsigned int argListSize, const cha
// If the option is in a group
if (parseRuleOption[optionId].group)
{
unsigned int groupId = parseRuleOption[optionId].groupId;
const unsigned int groupId = parseRuleOption[optionId].groupId;
config->optionGroup[groupId].valid = true;
@ -2210,16 +2211,16 @@ cfgParse(const Storage *const storage, const unsigned int argListSize, const cha
for (unsigned int optionOrderIdx = 0; optionOrderIdx < CFG_OPTION_TOTAL; optionOrderIdx++)
{
// Validate options based on the option resolve order. This allows resolving all options in a single pass.
ConfigOption optionId = optionResolveOrder[optionOrderIdx];
const ConfigOption optionId = optionResolveOrder[optionOrderIdx];
// Skip this option if it is not valid
if (!config->option[optionId].valid)
continue;
// Determine the option index total. For options that are not indexed the index total is 1.
bool optionGroup = parseRuleOption[optionId].group;
unsigned int optionGroupId = optionGroup ? parseRuleOption[optionId].groupId : UINT_MAX;
unsigned int optionListIndexTotal = optionGroup ? config->optionGroup[optionGroupId].indexTotal : 1;
const bool optionGroup = parseRuleOption[optionId].group;
const unsigned int optionGroupId = optionGroup ? parseRuleOption[optionId].groupId : UINT_MAX;
const unsigned int optionListIndexTotal = optionGroup ? config->optionGroup[optionGroupId].indexTotal : 1;
MEM_CONTEXT_BEGIN(config->memContext)
{
@ -2228,12 +2229,12 @@ cfgParse(const Storage *const storage, const unsigned int argListSize, const cha
MEM_CONTEXT_END();
// Loop through the option indexes
ConfigOptionType optionType = cfgParseOptionType(optionId);
const ConfigOptionType optionType = cfgParseOptionType(optionId);
for (unsigned int optionListIdx = 0; optionListIdx < optionListIndexTotal; optionListIdx++)
{
// Get the key index by looking it up in the group or by defaulting to 0 for ungrouped options
unsigned optionKeyIdx = optionGroup ? config->optionGroup[optionGroupId].indexMap[optionListIdx] : 0;
const unsigned optionKeyIdx = optionGroup ? config->optionGroup[optionGroupId].indexMap[optionListIdx] : 0;
// Get the parsed value using the key index. Provide a default structure when the value was not found.
ParseOptionValue *parseOptionValue =
@ -2244,7 +2245,7 @@ cfgParse(const Storage *const storage, const unsigned int argListSize, const cha
ConfigOptionValue *configOptionValue = &config->option[optionId].index[optionListIdx];
// Is the value set for this option?
bool optionSet =
const bool optionSet =
parseOptionValue->found && (optionType == cfgOptTypeBoolean || !parseOptionValue->negate) &&
!parseOptionValue->reset;
@ -2257,7 +2258,7 @@ cfgParse(const Storage *const storage, const unsigned int argListSize, const cha
if (cfgParseOptionalRule(&optionalRules, parseRuleOptionalTypeValid, config->command, optionId))
{
PackRead *filter = pckReadNewC(optionalRules.valid, optionalRules.validSize);
PackRead *const filter = pckReadNewC(optionalRules.valid, optionalRules.validSize);
dependResult = cfgParseOptionalFilterDepend(filter, config, optionListIdx);
// If depend not resolved and option value is set on the command-line then error. It is OK to have
@ -2266,7 +2267,7 @@ cfgParse(const Storage *const storage, const unsigned int argListSize, const cha
// spool-path in the config file should not cause an error here, it will just end up null.
if (!dependResult.valid && optionSet && parseOptionValue->source == cfgSourceParam)
{
PackRead *filter = pckReadNewC(optionalRules.valid, optionalRules.validSize);
PackRead *const filter = pckReadNewC(optionalRules.valid, optionalRules.validSize);
// If there is a boolean default value just consume it since it is not needed here
pckReadNext(filter);
@ -2362,8 +2363,8 @@ cfgParse(const Storage *const storage, const unsigned int argListSize, const cha
for (unsigned int listIdx = 0; listIdx < strLstSize(parseOptionValue->valueList); listIdx++)
{
const char *pair = strZ(strLstGet(parseOptionValue->valueList, listIdx));
const char *equal = strchr(pair, '=');
const char *const pair = strZ(strLstGet(parseOptionValue->valueList, listIdx));
const char *const equal = strchr(pair, '=');
if (equal == NULL)
{
@ -2388,8 +2389,8 @@ cfgParse(const Storage *const storage, const unsigned int argListSize, const cha
}
else
{
String *value = strLstGet(parseOptionValue->valueList, 0);
const String *valueAllow = value;
String *const value = strLstGet(parseOptionValue->valueList, 0);
const String *const valueAllow = value;
// Preserve original value to display
MEM_CONTEXT_BEGIN(config->memContext)
@ -2668,7 +2669,7 @@ cfgParse(const Storage *const storage, const unsigned int argListSize, const cha
ASSERT(groupId == cfgOptGrpPg || groupId == cfgOptGrpRepo);
// Get the group default option
unsigned int defaultOptionId = groupId == cfgOptGrpPg ? cfgOptPg : cfgOptRepo;
const unsigned int defaultOptionId = groupId == cfgOptGrpPg ? cfgOptPg : cfgOptRepo;
// Does a default always exist?
config->optionGroup[groupId].indexDefaultExists =
@ -2682,7 +2683,7 @@ cfgParse(const Storage *const storage, const unsigned int argListSize, const cha
if (cfgOptionTest(defaultOptionId))
{
// Search for the key
unsigned int optionKeyIdx = cfgOptionUInt(defaultOptionId) - 1;
const unsigned int optionKeyIdx = cfgOptionUInt(defaultOptionId) - 1;
unsigned int index = 0;
for (; index < cfgOptionGroupIdxTotal(groupId); index++)

View File

@ -26,7 +26,7 @@ configOptionProtocol(PackRead *const param, ProtocolServer *const server)
MEM_CONTEXT_TEMP_BEGIN()
{
VariantList *optionList = varLstNew();
VariantList *const optionList = varLstNew();
while (pckReadNext(param))
{
@ -46,7 +46,7 @@ configOptionProtocol(PackRead *const param, ProtocolServer *const server)
/**********************************************************************************************************************************/
FN_EXTERN VariantList *
configOptionRemote(ProtocolClient *client, const VariantList *paramList)
configOptionRemote(ProtocolClient *const client, const VariantList *const paramList)
{
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(PROTOCOL_CLIENT, client);
@ -57,7 +57,7 @@ configOptionRemote(ProtocolClient *client, const VariantList *paramList)
MEM_CONTEXT_TEMP_BEGIN()
{
ProtocolCommand *command = protocolCommandNew(PROTOCOL_COMMAND_CONFIG_OPTION);
ProtocolCommand *const command = protocolCommandNew(PROTOCOL_COMMAND_CONFIG_OPTION);
PackWrite *const param = protocolCommandParam(command);
for (unsigned int paramIdx = 0; paramIdx < varLstSize(paramList); paramIdx++)