NeoMutt  2025-12-11-435-g4ac674
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
config.c
Go to the documentation of this file.
1
24
30
31#include "config.h"
32#include <stddef.h>
33#include <stdint.h>
34#include "mutt/lib.h"
35#include "config/lib.h"
36#include "core/lib.h"
37#include "compress/lib.h"
38#include "store/lib.h"
39
43static int hcache_validator(const struct ConfigDef *cdef, 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 ConfigDef *cdef,
66 intptr_t value, struct Buffer *err)
67{
68#ifdef USE_HCACHE_COMPRESSION
69 if (value == 0)
70 return CSR_SUCCESS;
71
72 const char *str = (const char *) value;
73
74 if (compress_get_ops(str))
75 return CSR_SUCCESS;
76
77 buf_printf(err, _("Invalid value for option %s: %s"), cdef->name, str);
78 return CSR_ERR_INVALID;
79#else
80 return CSR_SUCCESS;
81#endif
82}
83
87static int compress_level_validator(const struct ConfigDef *cdef,
88 intptr_t value, struct Buffer *err)
89{
90#ifdef USE_HCACHE_COMPRESSION
91 const char *const c_header_cache_compress_method = cs_subset_string(NeoMutt->sub, "header_cache_compress_method");
92 if (!c_header_cache_compress_method)
93 {
94 buf_printf(err, _("Set option %s before setting %s"),
95 "header_cache_compress_method", cdef->name);
96 return CSR_ERR_INVALID;
97 }
98
99 const struct ComprOps *cops = compress_get_ops(c_header_cache_compress_method);
100 if (!cops)
101 {
102 buf_printf(err, _("Invalid value for option %s: %s"),
103 "header_cache_compress_method", c_header_cache_compress_method);
104 return CSR_ERR_INVALID;
105 }
106
107 if ((value < cops->min_level) || (value > cops->max_level))
108 {
109 // L10N: This applies to the "$header_cache_compress_level" config variable.
110 // It shows the minimum and maximum values, e.g. 'between 1 and 22'
111 buf_printf(err, _("Option %s must be between %d and %d inclusive"),
112 cdef->name, cops->min_level, cops->max_level);
113 return CSR_ERR_INVALID;
114 }
115#endif
116 return CSR_SUCCESS;
117}
118#endif
119
124 // clang-format off
125 { "header_cache", DT_PATH, 0, 0, NULL,
126 "(hcache) Directory/file for the header cache database"
127 },
128 { "header_cache_backend", DT_STRING, 0, 0, hcache_validator,
129 "(hcache) Header cache backend to use"
130 },
131 { NULL },
132 // clang-format on
133};
134
135#if defined(USE_HCACHE_COMPRESSION)
140 // clang-format off
141 // These two are not in alphabetical order because `level`s validator depends on `method`
142 { "header_cache_compress_method", DT_STRING, 0, 0, compress_method_validator,
143 "(hcache) Enable generic hcache database compression"
144 },
145 { "header_cache_compress_level", DT_NUMBER|D_INTEGER_NOT_NEGATIVE, 1, 0, compress_level_validator,
146 "(hcache) Level of compression for method"
147 },
148 { NULL },
149 // clang-format on
150};
151#endif
152
153#if defined(HAVE_QDBM) || defined(HAVE_TC) || defined(HAVE_KC)
158 // clang-format off
159 { "header_cache_compress", D_INTERNAL_DEPRECATED|DT_BOOL, 0, IP "2020-03-25" },
160 { NULL },
161 // clang-format on
162};
163#endif
164
165#if defined(HAVE_GDBM) || defined(HAVE_BDB)
170 // clang-format off
171 { "header_cache_pagesize", D_INTERNAL_DEPRECATED|DT_LONG, 0, IP "2020-03-25" },
172 { NULL },
173 // clang-format on
174};
175#endif
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:78
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.
#define CSR_ERR_INVALID
Value hasn't been set.
Definition set.h:36
#define CSR_SUCCESS
Action completed successfully.
Definition set.h:33
#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:43
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:65
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:87
struct ConfigDef HcacheVarsPage[]
Deprecated Config definitions for the Header Cache.
Definition config.c:169
struct ConfigDef HcacheVars[]
Config definitions for the Header Cache.
Definition config.c:123
struct ConfigDef HcacheVarsComp[]
Config definitions for the Header Cache Compression.
Definition config.c:139
struct ConfigDef HcacheVarsComp2[]
Deprecated Config definitions for the Header Cache Compression.
Definition config.c:157
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:126
String manipulation buffer.
Definition buffer.h:36
Definition lib.h:65
short max_level
Maximum compression level.
Definition lib.h:68
short min_level
Minimum compression level.
Definition lib.h:67
const char * name
User-visible name.
Definition set.h:65
Container for Accounts, Notifications.
Definition neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
#define D_INTERNAL_DEPRECATED
Config item shouldn't be used any more.
Definition types.h:88
@ 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:101