NeoMutt  2025-01-09-81-g753ae0
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
config.c
Go to the documentation of this file.
1
31#include "config.h"
32#include <stdbool.h>
33#include <stddef.h>
34#include <stdint.h>
35#include "mutt/lib.h"
36#include "config/lib.h"
37#include "core/lib.h"
38#include "compress/lib.h"
39#include "store/lib.h"
40
44static int hcache_validator(const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
45{
46#ifdef USE_HCACHE
47 if (value == 0)
48 return CSR_SUCCESS;
49
50 const char *str = (const char *) value;
51
53 return CSR_SUCCESS;
54
55 buf_printf(err, _("Invalid value for option %s: %s"), cdef->name, str);
56 return CSR_ERR_INVALID;
57#else
58 return CSR_SUCCESS;
59#endif
60}
61
62#if defined(USE_HCACHE_COMPRESSION)
66static int compress_method_validator(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 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|D_INTEGER_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", D_INTERNAL_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", D_INTERNAL_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:161
const struct ComprOps * compress_get_ops(const char *compr)
Get the API functions for a compress backend.
Definition: compress.c:81
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:291
Convenience wrapper for the config headers.
bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[])
Register a set of config items.
Definition: set.c:289
#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 hcache_validator(const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Validate the "header_cache_backend" config variable - Implements ConfigDef::validator() -.
Definition: config.c:44
static int compress_method_validator(const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Validate the "header_cache_compress_method" config variable - Implements ConfigDef::validator() -.
Definition: config.c:66
static int compress_level_validator(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
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:129
String manipulation buffer.
Definition: buffer.h:36
Definition: lib.h:64
short max_level
Maximum compression level.
Definition: lib.h:67
short min_level
Minimum compression level.
Definition: lib.h:66
Definition: set.h:64
const char * name
User-visible name.
Definition: set.h:65
Container for lots of config items.
Definition: set.h:250
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
#define D_INTERNAL_DEPRECATED
Config item shouldn't be used any more.
Definition: types.h:87
@ DT_NUMBER
a number
Definition: types.h:38
@ DT_BOOL
boolean option
Definition: types.h:32
@ DT_STRING
a string
Definition: types.h:44
@ DT_LONG
a number (long)
Definition: types.h:35
@ DT_PATH
a path to a file/directory
Definition: types.h:39
#define D_INTEGER_NOT_NEGATIVE
Negative numbers are not allowed.
Definition: types.h:100