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