/src/pigeonhole/src/lib-sieve/plugins/editheader/ext-editheader-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 "rfc2822.h" |
10 | | #include "ext-editheader-limits.h" |
11 | | #include "ext-editheader-settings.h" |
12 | | |
13 | | static bool |
14 | | ext_editheader_header_settings_check(void *_set, pool_t pool, |
15 | | const char **error_r); |
16 | | static bool |
17 | | ext_editheader_settings_check(void *_set, pool_t pool, const char **error_r); |
18 | | |
19 | | #undef DEF |
20 | | #define DEF(type, name) \ |
21 | | SETTING_DEFINE_STRUCT_##type("sieve_editheader_header_"#name, name, \ |
22 | | struct ext_editheader_header_settings) |
23 | | |
24 | | static const struct setting_define ext_editheader_header_setting_defines[] = { |
25 | | DEF(STR, name), |
26 | | DEF(BOOL, forbid_add), |
27 | | DEF(BOOL, forbid_delete), |
28 | | |
29 | | SETTING_DEFINE_LIST_END, |
30 | | }; |
31 | | |
32 | | static const struct ext_editheader_header_settings |
33 | | ext_editheader_header_default_settings = { |
34 | | .name = "", |
35 | | .forbid_add = FALSE, |
36 | | .forbid_delete = FALSE, |
37 | | }; |
38 | | |
39 | | const struct setting_parser_info ext_editheader_header_setting_parser_info = { |
40 | | .name = "sieve_editheader_header", |
41 | | |
42 | | .defines = ext_editheader_header_setting_defines, |
43 | | .defaults = &ext_editheader_header_default_settings, |
44 | | |
45 | | .struct_size = sizeof(struct ext_editheader_header_settings), |
46 | | |
47 | | .check_func = ext_editheader_header_settings_check, |
48 | | |
49 | | .pool_offset1 = 1 + offsetof(struct ext_editheader_header_settings, pool), |
50 | | }; |
51 | | |
52 | | #undef DEF |
53 | | #define DEF(type, name) \ |
54 | | SETTING_DEFINE_STRUCT_##type("sieve_editheader_"#name, name, \ |
55 | | struct ext_editheader_settings) |
56 | | |
57 | | static const struct setting_define ext_editheader_setting_defines[] = { |
58 | | DEF(SIZE, max_header_size), |
59 | | |
60 | | { .type = SET_FILTER_ARRAY, |
61 | | .key = "sieve_editheader_header", |
62 | | .filter_array_field_name = "sieve_editheader_header_name", |
63 | | .offset = offsetof(struct ext_editheader_settings, headers), }, |
64 | | |
65 | | SETTING_DEFINE_LIST_END, |
66 | | }; |
67 | | |
68 | | static const struct ext_editheader_settings ext_editheader_default_settings = { |
69 | | .max_header_size = EXT_EDITHEADER_DEFAULT_MAX_HEADER_SIZE, |
70 | | .headers = ARRAY_INIT, |
71 | | }; |
72 | | |
73 | | const struct setting_parser_info ext_editheader_setting_parser_info = { |
74 | | .name = "sieve_editheader", |
75 | | |
76 | | .defines = ext_editheader_setting_defines, |
77 | | .defaults = &ext_editheader_default_settings, |
78 | | |
79 | | .struct_size = sizeof(struct ext_editheader_settings), |
80 | | |
81 | | .check_func = ext_editheader_settings_check, |
82 | | |
83 | | .pool_offset1 = 1 + offsetof(struct ext_editheader_settings, pool), |
84 | | }; |
85 | | |
86 | | /* <settings checks> */ |
87 | | static bool |
88 | | ext_editheader_header_settings_check(void *_set, pool_t pool ATTR_UNUSED, |
89 | | const char **error_r) |
90 | 0 | { |
91 | 0 | struct ext_editheader_header_settings *set = _set; |
92 | |
|
93 | 0 | if (!rfc2822_header_field_name_verify(set->name, strlen(set->name))) { |
94 | 0 | *error_r = t_strdup_printf( |
95 | 0 | "sieve_editheader_header_name: " |
96 | 0 | "Invalid header field name '%s'", set->name); |
97 | 0 | return FALSE; |
98 | 0 | } |
99 | | |
100 | 0 | return TRUE; |
101 | 0 | } |
102 | | |
103 | | static bool |
104 | | ext_editheader_settings_check(void *_set, pool_t pool ATTR_UNUSED, |
105 | | const char **error_r) |
106 | 0 | { |
107 | 0 | struct ext_editheader_settings *set = _set; |
108 | |
|
109 | 0 | if (set->max_header_size < EXT_EDITHEADER_MINIMUM_MAX_HEADER_SIZE) { |
110 | 0 | *error_r = t_strdup_printf( |
111 | 0 | "sieve_editheader_max_header_size: " |
112 | 0 | "Value (=%"PRIuUOFF_T") is less than the minimum " |
113 | 0 | "(=%"PRIuUOFF_T") ", |
114 | 0 | set->max_header_size, |
115 | 0 | (size_t)EXT_EDITHEADER_MINIMUM_MAX_HEADER_SIZE); |
116 | 0 | return FALSE; |
117 | 0 | } |
118 | | |
119 | 0 | return TRUE; |
120 | 0 | } |
121 | | /* </settings checks> */ |
122 | | |