diff options
Diffstat (limited to 'src/config')
-rw-r--r-- | src/config/ConfigGlobal.cxx | 17 | ||||
-rw-r--r-- | src/config/ConfigGlobal.hxx | 11 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/config/ConfigGlobal.cxx b/src/config/ConfigGlobal.cxx index c7d16d3e7..dd76e3ca3 100644 --- a/src/config/ConfigGlobal.cxx +++ b/src/config/ConfigGlobal.cxx @@ -85,6 +85,23 @@ config_get_next_param(ConfigOption option, const struct config_param * last) return param; } +const config_param * +config_find_block(ConfigOption option, const char *key, const char *value) +{ + const config_param *param = nullptr; + while ((param = config_get_next_param(option, param)) != nullptr) { + const char *value2 = param->GetBlockValue(key); + if (value2 == nullptr) + FormatFatalError("block without '%s' name in line %d", + key, param->line); + + if (strcmp(value2, value) == 0) + return param; + } + + return nullptr; +} + const char * config_get_string(ConfigOption option, const char *default_value) { diff --git a/src/config/ConfigGlobal.hxx b/src/config/ConfigGlobal.hxx index abce424de..84ef7dd5f 100644 --- a/src/config/ConfigGlobal.hxx +++ b/src/config/ConfigGlobal.hxx @@ -53,6 +53,17 @@ config_get_param(enum ConfigOption option) return config_get_next_param(option, nullptr); } +/** + * Find a block with a matching attribute. + * + * @param option the blocks to search + * @param key the attribute name + * @param value the expected attribute value + */ +gcc_pure +const config_param * +config_find_block(ConfigOption option, const char *key, const char *value); + /* Note on gcc_pure: Some of the functions declared pure are not really pure in strict sense. They have side effect such that they validate parameter's value and signal an error if it's invalid. |