forked from neomutt/neomutt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.c
202 lines (179 loc) · 5.91 KB
/
config.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/**
* @file
* Config used by libhcache
*
* @authors
* Copyright (C) 2020 Richard Russon <[email protected]>
*
* @copyright
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @page hc_config Config used by Header Cache
*
* Config used by libhcache
*/
#include "config.h"
#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "compress/lib.h"
#include "store/lib.h"
/**
* hcache_validator - Validate the "header_cache_backend" config variable - Implements ConfigDef::validator() - @ingroup cfg_def_validator
*/
static int hcache_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef,
intptr_t value, struct Buffer *err)
{
#ifdef USE_HCACHE
if (value == 0)
return CSR_SUCCESS;
const char *str = (const char *) value;
if (store_is_valid_backend(str))
return CSR_SUCCESS;
buf_printf(err, _("Invalid value for option %s: %s"), cdef->name, str);
return CSR_ERR_INVALID;
#else
return CSR_SUCCESS;
#endif
}
#if defined(USE_HCACHE_COMPRESSION)
/**
* compress_method_validator - Validate the "header_cache_compress_method" config variable - Implements ConfigDef::validator() - @ingroup cfg_def_validator
*/
static int compress_method_validator(const struct ConfigSet *cs,
const struct ConfigDef *cdef,
intptr_t value, struct Buffer *err)
{
#ifdef USE_HCACHE_COMPRESSION
if (value == 0)
return CSR_SUCCESS;
const char *str = (const char *) value;
if (compress_get_ops(str))
return CSR_SUCCESS;
buf_printf(err, _("Invalid value for option %s: %s"), cdef->name, str);
return CSR_ERR_INVALID;
#else
return CSR_SUCCESS;
#endif
}
/**
* compress_level_validator - Validate the "header_cache_compress_level" config variable - Implements ConfigDef::validator() - @ingroup cfg_def_validator
*/
static int compress_level_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef,
intptr_t value, struct Buffer *err)
{
#ifdef USE_HCACHE_COMPRESSION
const char *const c_header_cache_compress_method = cs_subset_string(NeoMutt->sub, "header_cache_compress_method");
if (!c_header_cache_compress_method)
{
buf_printf(err, _("Set option %s before setting %s"),
"header_cache_compress_method", cdef->name);
return CSR_ERR_INVALID;
}
const struct ComprOps *cops = compress_get_ops(c_header_cache_compress_method);
if (!cops)
{
buf_printf(err, _("Invalid value for option %s: %s"),
"header_cache_compress_method", c_header_cache_compress_method);
return CSR_ERR_INVALID;
}
if ((value < cops->min_level) || (value > cops->max_level))
{
// L10N: This applies to the "$header_cache_compress_level" config variable.
// It shows the minimum and maximum values, e.g. 'between 1 and 22'
buf_printf(err, _("Option %s must be between %d and %d inclusive"),
cdef->name, cops->min_level, cops->max_level);
return CSR_ERR_INVALID;
}
#endif
return CSR_SUCCESS;
}
#endif
/**
* HcacheVars - Config definitions for the Header Cache
*/
static struct ConfigDef HcacheVars[] = {
// clang-format off
{ "header_cache", DT_PATH, 0, 0, NULL,
"(hcache) Directory/file for the header cache database"
},
{ "header_cache_backend", DT_STRING, 0, 0, hcache_validator,
"(hcache) Header cache backend to use"
},
{ NULL },
// clang-format on
};
#if defined(USE_HCACHE_COMPRESSION)
/**
* HcacheVarsComp - Config definitions for the Header Cache Compression
*/
static struct ConfigDef HcacheVarsComp[] = {
// clang-format off
// These two are not in alphabetical order because `level`s validator depends on `method`
{ "header_cache_compress_method", DT_STRING, 0, 0, compress_method_validator,
"(hcache) Enable generic hcache database compression"
},
{ "header_cache_compress_level", DT_NUMBER|DT_NOT_NEGATIVE, 1, 0, compress_level_validator,
"(hcache) Level of compression for method"
},
{ NULL },
// clang-format on
};
#endif
#if defined(HAVE_QDBM) || defined(HAVE_TC) || defined(HAVE_KC)
/**
* HcacheVarsComp2 - Deprecated Config definitions for the Header Cache Compression
*/
static struct ConfigDef HcacheVarsComp2[] = {
// clang-format off
{ "header_cache_compress", DT_DEPRECATED|DT_BOOL, 0, IP "2020-03-25" },
{ NULL },
// clang-format on
};
#endif
#if defined(HAVE_GDBM) || defined(HAVE_BDB)
/**
* HcacheVarsPage - Deprecated Config definitions for the Header Cache
*/
static struct ConfigDef HcacheVarsPage[] = {
// clang-format off
{ "header_cache_pagesize", DT_DEPRECATED|DT_LONG, 0, IP "2020-03-25" },
{ NULL },
// clang-format on
};
#endif
/**
* config_init_hcache - Register hcache config variables - Implements ::module_init_config_t - @ingroup cfg_module_api
*/
bool config_init_hcache(struct ConfigSet *cs)
{
bool rc = false;
#if defined(USE_HCACHE)
rc |= cs_register_variables(cs, HcacheVars, DT_NO_FLAGS);
#endif
#if defined(USE_HCACHE_COMPRESSION)
rc |= cs_register_variables(cs, HcacheVarsComp, DT_NO_FLAGS);
#endif
#if defined(HAVE_QDBM) || defined(HAVE_TC) || defined(HAVE_KC)
rc |= cs_register_variables(cs, HcacheVarsComp2, DT_NO_FLAGS);
#endif
#if defined(HAVE_GDBM) || defined(HAVE_BDB)
rc |= cs_register_variables(cs, HcacheVarsPage, DT_NO_FLAGS);
#endif
return rc;
}