NeoMutt  2023-05-17-16-g61469c
Teaching an old dog new tricks
DOXYGEN
config.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <stddef.h>
31#include <stdbool.h>
32#include <stdint.h>
33#include "mutt/lib.h"
34#include "config/lib.h"
35#include "core/lib.h"
36#include "compress/lib.h"
37#include "store/lib.h"
38
42static int hcache_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef,
43 intptr_t value, struct Buffer *err)
44{
45#ifdef USE_HCACHE
46 if (value == 0)
47 return CSR_SUCCESS;
48
49 const char *str = (const char *) value;
50
52 return CSR_SUCCESS;
53
54 buf_printf(err, _("Invalid value for option %s: %s"), cdef->name, str);
55 return CSR_ERR_INVALID;
56#else
57 return CSR_SUCCESS;
58#endif
59}
60
61#if defined(USE_HCACHE_COMPRESSION)
65static int compress_method_validator(const struct ConfigSet *cs,
66 const struct ConfigDef *cdef,
67 intptr_t value, struct Buffer *err)
68{
69#ifdef USE_HCACHE_COMPRESSION
70 if (value == 0)
71 return CSR_SUCCESS;
72
73 const char *str = (const char *) value;
74
75 if (compress_get_ops(str))
76 return CSR_SUCCESS;
77
78 buf_printf(err, _("Invalid value for option %s: %s"), cdef->name, str);
79 return CSR_ERR_INVALID;
80#else
81 return CSR_SUCCESS;
82#endif
83}
84
88static int compress_level_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef,
89 intptr_t value, struct Buffer *err)
90{
91#ifdef USE_HCACHE_COMPRESSION
92 const char *const c_header_cache_compress_method = cs_subset_string(NeoMutt->sub, "header_cache_compress_method");
93 if (!c_header_cache_compress_method)
94 {
95 buf_printf(err, _("Set option %s before setting %s"),
96 "header_cache_compress_method", cdef->name);
97 return CSR_ERR_INVALID;
98 }
99
100 const struct ComprOps *cops = compress_get_ops(c_header_cache_compress_method);
101 if (!cops)
102 {
103 buf_printf(err, _("Invalid value for option %s: %s"),
104 "header_cache_compress_method", c_header_cache_compress_method);
105 return CSR_ERR_INVALID;
106 }
107
108 if ((value < cops->min_level) || (value > cops->max_level))
109 {
110 // L10N: This applies to the "$header_cache_compress_level" config variable.
111 // It shows the minimum and maximum values, e.g. 'between 1 and 22'
112 buf_printf(err, _("Option %s must be between %d and %d inclusive"),
113 cdef->name, cops->min_level, cops->max_level);
114 return CSR_ERR_INVALID;
115 }
116#endif
117 return CSR_SUCCESS;
118}
119#endif
120
124static struct ConfigDef HcacheVars[] = {
125 // clang-format off
126 { "header_cache", DT_PATH, 0, 0, NULL,
127 "(hcache) Directory/file for the header cache database"
128 },
129 { "header_cache_backend", DT_STRING, 0, 0, hcache_validator,
130 "(hcache) Header cache backend to use"
131 },
132 { NULL },
133 // clang-format on
134};
135
136#if defined(USE_HCACHE_COMPRESSION)
140static struct ConfigDef HcacheVarsComp[] = {
141 // clang-format off
142 // These two are not in alphabetical order because `level`s validator depends on `method`
143 { "header_cache_compress_method", DT_STRING, 0, 0, compress_method_validator,
144 "(hcache) Enable generic hcache database compression"
145 },
146 { "header_cache_compress_level", DT_NUMBER|DT_NOT_NEGATIVE, 1, 0, compress_level_validator,
147 "(hcache) Level of compression for method"
148 },
149 { NULL },
150 // clang-format on
151};
152#endif
153
154#if defined(HAVE_QDBM) || defined(HAVE_TC) || defined(HAVE_KC)
158static struct ConfigDef HcacheVarsComp2[] = {
159 // clang-format off
160 { "header_cache_compress", DT_DEPRECATED|DT_BOOL, 0, IP "2020-03-25" },
161 { NULL },
162 // clang-format on
163};
164#endif
165
166#if defined(HAVE_GDBM) || defined(HAVE_BDB)
170static struct ConfigDef HcacheVarsPage[] = {
171 // clang-format off
172 { "header_cache_pagesize", DT_DEPRECATED|DT_LONG, 0, IP "2020-03-25" },
173 { NULL },
174 // clang-format on
175};
176#endif
177
182{
183 bool rc = false;
184
185#if defined(USE_HCACHE)
187#endif
188
189#if defined(USE_HCACHE_COMPRESSION)
191#endif
192
193#if defined(HAVE_QDBM) || defined(HAVE_TC) || defined(HAVE_KC)
195#endif
196
197#if defined(HAVE_GDBM) || defined(HAVE_BDB)
199#endif
200
201 return rc;
202}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:171
const struct ComprOps * compress_get_ops(const char *compr)
Get the API functions for a compress backend.
Definition: compress.c:79
API for the header cache compression.
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
Convenience wrapper for the config headers.
bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[], uint32_t flags)
Register a set of config items.
Definition: set.c:279
#define CSR_ERR_INVALID
Value hasn't been set.
Definition: set.h:38
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
#define IP
Definition: set.h:54
Convenience wrapper for the core headers.
static int compress_level_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Validate the "header_cache_compress_level" config variable - Implements ConfigDef::validator() -.
Definition: config.c:88
static int hcache_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Validate the "header_cache_backend" config variable - Implements ConfigDef::validator() -.
Definition: config.c:42
static int compress_method_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Validate the "header_cache_compress_method" config variable - Implements ConfigDef::validator() -.
Definition: config.c:65
bool config_init_hcache(struct ConfigSet *cs)
Register hcache config variables - Implements module_init_config_t -.
Definition: config.c:181
static struct ConfigDef HcacheVarsPage[]
Deprecated Config definitions for the Header Cache.
Definition: config.c:170
static struct ConfigDef HcacheVars[]
Config definitions for the Header Cache.
Definition: config.c:124
static struct ConfigDef HcacheVarsComp[]
Config definitions for the Header Cache Compression.
Definition: config.c:140
static struct ConfigDef HcacheVarsComp2[]
Deprecated Config definitions for the Header Cache Compression.
Definition: config.c:158
Convenience wrapper for the library headers.
#define _(a)
Definition: message.h:28
Key value store.
bool store_is_valid_backend(const char *str)
Is the string a valid Store backend.
Definition: store.c:128
String manipulation buffer.
Definition: buffer.h:34
Definition: lib.h:60
short max_level
Maximum compression level.
Definition: lib.h:63
short min_level
Minimum compression level.
Definition: lib.h:62
Definition: set.h:64
const char * name
User-visible name.
Definition: set.h:65
Container for lots of config items.
Definition: set.h:252
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
#define DT_LONG
a number (long)
Definition: types.h:33
#define DT_BOOL
boolean option
Definition: types.h:30
#define DT_DEPRECATED
Config item shouldn't be used any more.
Definition: types.h:77
#define DT_PATH
a path to a file/directory
Definition: types.h:36
#define DT_STRING
a string
Definition: types.h:41
#define DT_NO_FLAGS
No flags are set.
Definition: types.h:47
#define DT_NOT_NEGATIVE
Negative numbers are not allowed.
Definition: types.h:50
#define DT_NUMBER
a number
Definition: types.h:35