NeoMutt  2024-03-23-147-g885fbc
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 <stddef.h>
33#include <stdbool.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 ConfigSet *cs, const struct ConfigDef *cdef,
45 intptr_t value, struct Buffer *err)
46{
47#ifdef USE_HCACHE
48 if (value == 0)
49 return CSR_SUCCESS;
50
51 const char *str = (const char *) value;
52
54 return CSR_SUCCESS;
55
56 buf_printf(err, _("Invalid value for option %s: %s"), cdef->name, str);
57 return CSR_ERR_INVALID;
58#else
59 return CSR_SUCCESS;
60#endif
61}
62
63#if defined(USE_HCACHE_COMPRESSION)
67static int compress_method_validator(const struct ConfigSet *cs,
68 const struct ConfigDef *cdef,
69 intptr_t value, struct Buffer *err)
70{
71#ifdef USE_HCACHE_COMPRESSION
72 if (value == 0)
73 return CSR_SUCCESS;
74
75 const char *str = (const char *) value;
76
77 if (compress_get_ops(str))
78 return CSR_SUCCESS;
79
80 buf_printf(err, _("Invalid value for option %s: %s"), cdef->name, str);
81 return CSR_ERR_INVALID;
82#else
83 return CSR_SUCCESS;
84#endif
85}
86
90static int compress_level_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef,
91 intptr_t value, struct Buffer *err)
92{
93#ifdef USE_HCACHE_COMPRESSION
94 const char *const c_header_cache_compress_method = cs_subset_string(NeoMutt->sub, "header_cache_compress_method");
95 if (!c_header_cache_compress_method)
96 {
97 buf_printf(err, _("Set option %s before setting %s"),
98 "header_cache_compress_method", cdef->name);
99 return CSR_ERR_INVALID;
100 }
101
102 const struct ComprOps *cops = compress_get_ops(c_header_cache_compress_method);
103 if (!cops)
104 {
105 buf_printf(err, _("Invalid value for option %s: %s"),
106 "header_cache_compress_method", c_header_cache_compress_method);
107 return CSR_ERR_INVALID;
108 }
109
110 if ((value < cops->min_level) || (value > cops->max_level))
111 {
112 // L10N: This applies to the "$header_cache_compress_level" config variable.
113 // It shows the minimum and maximum values, e.g. 'between 1 and 22'
114 buf_printf(err, _("Option %s must be between %d and %d inclusive"),
115 cdef->name, cops->min_level, cops->max_level);
116 return CSR_ERR_INVALID;
117 }
118#endif
119 return CSR_SUCCESS;
120}
121#endif
122
126static struct ConfigDef HcacheVars[] = {
127 // clang-format off
128 { "header_cache", DT_PATH, 0, 0, NULL,
129 "(hcache) Directory/file for the header cache database"
130 },
131 { "header_cache_backend", DT_STRING, 0, 0, hcache_validator,
132 "(hcache) Header cache backend to use"
133 },
134 { NULL },
135 // clang-format on
136};
137
138#if defined(USE_HCACHE_COMPRESSION)
142static struct ConfigDef HcacheVarsComp[] = {
143 // clang-format off
144 // These two are not in alphabetical order because `level`s validator depends on `method`
145 { "header_cache_compress_method", DT_STRING, 0, 0, compress_method_validator,
146 "(hcache) Enable generic hcache database compression"
147 },
148 { "header_cache_compress_level", DT_NUMBER|D_INTEGER_NOT_NEGATIVE, 1, 0, compress_level_validator,
149 "(hcache) Level of compression for method"
150 },
151 { NULL },
152 // clang-format on
153};
154#endif
155
156#if defined(HAVE_QDBM) || defined(HAVE_TC) || defined(HAVE_KC)
160static struct ConfigDef HcacheVarsComp2[] = {
161 // clang-format off
162 { "header_cache_compress", D_INTERNAL_DEPRECATED|DT_BOOL, 0, IP "2020-03-25" },
163 { NULL },
164 // clang-format on
165};
166#endif
167
168#if defined(HAVE_GDBM) || defined(HAVE_BDB)
172static struct ConfigDef HcacheVarsPage[] = {
173 // clang-format off
174 { "header_cache_pagesize", D_INTERNAL_DEPRECATED|DT_LONG, 0, IP "2020-03-25" },
175 { NULL },
176 // clang-format on
177};
178#endif
179
184{
185 bool rc = false;
186
187#if defined(USE_HCACHE)
189#endif
190
191#if defined(USE_HCACHE_COMPRESSION)
193#endif
194
195#if defined(HAVE_QDBM) || defined(HAVE_TC) || defined(HAVE_KC)
197#endif
198
199#if defined(HAVE_GDBM) || defined(HAVE_BDB)
201#endif
202
203 return rc;
204}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
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:292
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:281
#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:90
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:44
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:67
bool config_init_hcache(struct ConfigSet *cs)
Register hcache config variables - Implements module_init_config_t -.
Definition: config.c:183
static struct ConfigDef HcacheVarsPage[]
Deprecated Config definitions for the Header Cache.
Definition: config.c:172
static struct ConfigDef HcacheVars[]
Config definitions for the Header Cache.
Definition: config.c:126
static struct ConfigDef HcacheVarsComp[]
Config definitions for the Header Cache Compression.
Definition: config.c:142
static struct ConfigDef HcacheVarsComp2[]
Deprecated Config definitions for the Header Cache Compression.
Definition: config.c:160
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:252
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
#define D_INTERNAL_DEPRECATED
Config item shouldn't be used any more.
Definition: types.h:88
@ DT_NUMBER
a number
Definition: types.h:39
@ DT_BOOL
boolean option
Definition: types.h:32
@ DT_STRING
a string
Definition: types.h:45
@ DT_LONG
a number (long)
Definition: types.h:36
@ DT_PATH
a path to a file/directory
Definition: types.h:40
#define D_INTEGER_NOT_NEGATIVE
Negative numbers are not allowed.
Definition: types.h:101