/src/pigeonhole/src/lib-sieve/plugins/variables/ext-variables-settings.c
Line | Count | Source |
1 | | /* Copyright (c) 2024 Pigeonhole authors, see the included COPYING file |
2 | | */ |
3 | | |
4 | | #include "lib.h" |
5 | | #include "array.h" |
6 | | #include "settings.h" |
7 | | #include "settings-parser.h" |
8 | | |
9 | | #include "ext-variables-limits.h" |
10 | | #include "ext-variables-settings.h" |
11 | | |
12 | | static bool |
13 | | ext_variables_settings_check(void *_set, pool_t pool ATTR_UNUSED, |
14 | | const char **error_r); |
15 | | |
16 | | #undef DEF |
17 | | #define DEF(type, name) \ |
18 | | SETTING_DEFINE_STRUCT_##type("sieve_variables_"#name, name, \ |
19 | | struct ext_variables_settings) |
20 | | |
21 | | static const struct setting_define ext_variables_setting_defines[] = { |
22 | | DEF(UINT, max_scope_count), |
23 | | DEF(SIZE, max_value_size), |
24 | | |
25 | | SETTING_DEFINE_LIST_END, |
26 | | }; |
27 | | |
28 | | static const struct ext_variables_settings ext_variables_default_settings = { |
29 | | .max_scope_count = 255, |
30 | | .max_value_size = (4 * 1024), |
31 | | }; |
32 | | |
33 | | const struct setting_parser_info ext_variables_setting_parser_info = { |
34 | | .name = "sieve_variables", |
35 | | |
36 | | .defines = ext_variables_setting_defines, |
37 | | .defaults = &ext_variables_default_settings, |
38 | | |
39 | | .struct_size = sizeof(struct ext_variables_settings), |
40 | | |
41 | | .check_func = ext_variables_settings_check, |
42 | | |
43 | | .pool_offset1 = 1 + offsetof(struct ext_variables_settings, pool), |
44 | | }; |
45 | | |
46 | | /* <settings checks> */ |
47 | | static bool |
48 | | ext_variables_settings_check(void *_set, pool_t pool ATTR_UNUSED, |
49 | | const char **error_r) |
50 | 0 | { |
51 | 0 | struct ext_variables_settings *set = _set; |
52 | |
|
53 | 0 | if (set->max_scope_count < EXT_VARIABLES_REQUIRED_MAX_SCOPE_COUNT) { |
54 | 0 | *error_r = t_strdup_printf( |
55 | 0 | "Setting sieve_variables_max_scope_count " |
56 | 0 | "is lower than required by standards " |
57 | 0 | "(>= %u items)", |
58 | 0 | EXT_VARIABLES_REQUIRED_MAX_SCOPE_COUNT); |
59 | 0 | return FALSE; |
60 | 0 | } |
61 | 0 | if (set->max_value_size < EXT_VARIABLES_REQUIRED_MAX_VALUE_SIZE) { |
62 | 0 | *error_r = t_strdup_printf( |
63 | 0 | "Setting sieve_variables_max_variable_size " |
64 | 0 | "is lower than required by standards " |
65 | 0 | "(>= %zu bytes)", |
66 | 0 | (size_t)EXT_VARIABLES_REQUIRED_MAX_VALUE_SIZE); |
67 | 0 | return FALSE; |
68 | 0 | } |
69 | | |
70 | 0 | return TRUE; |
71 | 0 | } |
72 | | /* </settings checks> */ |
73 | | |