From: sergey.kitov Date: Fri, 11 Oct 2024 12:21:24 +0000 (+0300) Subject: lib-settings: Introduce settings_boollist_is_stopped() function. X-Git-Tag: 2.4.1~621 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=108f50544c9b03b979043ee90a1b9bc105b0182f;p=thirdparty%2Fdovecot%2Fcore.git lib-settings: Introduce settings_boollist_is_stopped() function. The function is to be used to identify if boollist setting is set explicitly or updating existing (default) settings. --- diff --git a/src/lib-settings/settings-parser.c b/src/lib-settings/settings-parser.c index b59f69b4eb..244730d4e4 100644 --- a/src/lib-settings/settings-parser.c +++ b/src/lib-settings/settings-parser.c @@ -514,6 +514,19 @@ void settings_boollist_finish(ARRAY_TYPE(const_string) *array, bool stop) array_pop_back(array); } +bool settings_boollist_is_stopped(const ARRAY_TYPE(const_string) *array) +{ + /* The first element after the visible array is NULL. If the next element + after the NULL is set_array_stop, then the boollist is stopped. */ + unsigned int count; + const char *const *values = + array_get(array, &count); + i_assert(values[count] == NULL); + if (values[count + 1] == set_array_stop) + return TRUE; + return FALSE; +} + static int settings_parse_boollist(struct setting_parser_context *ctx, ARRAY_TYPE(const_string) *array, @@ -524,14 +537,9 @@ settings_parse_boollist(struct setting_parser_context *ctx, if (!array_is_created(array)) p_array_init(array, ctx->set_pool, 5); else { - /* The first element after the visible array is NULL. If the - next element after the NULL is set_array_stop, then the - boollist should not be modified any further. */ - unsigned int old_count; - const char *const *old_values = - array_get(array, &old_count); - i_assert(old_values[old_count] == NULL); - if (old_values[old_count + 1] == set_array_stop) + /* If the array is stopped, then the boollist should not + be modified any further. */ + if (settings_boollist_is_stopped(array)) return 0; } diff --git a/src/lib-settings/settings-parser.h b/src/lib-settings/settings-parser.h index 176ff24279..25f37e9fd7 100644 --- a/src/lib-settings/settings-parser.h +++ b/src/lib-settings/settings-parser.h @@ -275,6 +275,8 @@ const char *const *settings_boollist_get(const ARRAY_TYPE(const_string) *array); as long as this function is called again after modifications. */ void settings_boollist_finish(ARRAY_TYPE(const_string) *array, bool stop); +/* Checks if boollist is marked as replacing the full list */ +bool settings_boollist_is_stopped(const ARRAY_TYPE(const_string) *array); /* Split the settings value into path and content. The path is allocated from the path_pool, while content points directly to the value string. */ void settings_file_get(const char *value, pool_t path_pool,