From: Timo Sirainen Date: Fri, 9 Feb 2024 21:33:00 +0000 (+0200) Subject: lib-settings: Add settings_file_has_path() X-Git-Tag: 2.4.1~993 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=752187c9b4c2e0064dea0aca5de0b1f11522d9fc;p=thirdparty%2Fdovecot%2Fcore.git lib-settings: Add settings_file_has_path() --- diff --git a/src/lib-settings/settings-parser.c b/src/lib-settings/settings-parser.c index d18168f12e..b18e81523b 100644 --- a/src/lib-settings/settings-parser.c +++ b/src/lib-settings/settings-parser.c @@ -463,6 +463,15 @@ void settings_file_get(const char *value, pool_t path_pool, file_r->content = p + 1; } +bool settings_file_has_path(const char *value) +{ + /* value must be in format */ + const char *p = strchr(value, '\n'); + if (p == NULL) + i_panic("Settings file value is missing LF"); + return p != value; +} + const char *settings_file_get_value(pool_t pool, const struct settings_file *file) { diff --git a/src/lib-settings/settings-parser.h b/src/lib-settings/settings-parser.h index 10e87320e6..ac7730a3ae 100644 --- a/src/lib-settings/settings-parser.h +++ b/src/lib-settings/settings-parser.h @@ -256,6 +256,9 @@ const char *const *settings_boollist_get(const ARRAY_TYPE(const_string) *array); the path_pool, while content points directly to the value string. */ void settings_file_get(const char *value, pool_t path_pool, struct settings_file *file_r); +/* Returns TRUE if the settings value contains a non-empty path. The value + is expected to be in the SET_FILE format (path LF content). */ +bool settings_file_has_path(const char *value); /* Convert settings_file into a value (path LF content). The file path may be NULL, but the content must exist. */ const char *settings_file_get_value(pool_t pool,