]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-settings: Introduce settings_boollist_is_stopped() function.
authorsergey.kitov <sergey.kitov@open-xchange.com>
Fri, 11 Oct 2024 12:21:24 +0000 (15:21 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Fri, 17 Jan 2025 08:40:00 +0000 (10:40 +0200)
The function is to be used to identify if boollist setting is set
explicitly or updating existing (default) settings.

src/lib-settings/settings-parser.c
src/lib-settings/settings-parser.h

index b59f69b4eb062cc8505569b48ec063ebad828cb4..244730d4e4b0218e2ec6f04c21fb3f467192f236 100644 (file)
@@ -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;
        }
 
index 176ff242797f85c951da9e800173923d42c253dd..25f37e9fd7d08cd876cfbd39617811cf37929bca 100644 (file)
@@ -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,