NeoMutt  2025-12-11-694-ga89709
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 <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 if (value == 0)
47 return CSR_SUCCESS;
48
49 const char *const c_header_cache_backend = cs_subset_string(NeoMutt->sub, "header_cache_backend");
50 if (!c_header_cache_backend)
51 {
52 buf_printf(err, _("Set option %s before setting %s"), "header_cache_backend", cdef->name);
53 return CSR_ERR_INVALID;
54 }
55
56 return CSR_SUCCESS;
57}
58
62static int hcache_backend_validator(const struct ConfigDef *cdef,
63 intptr_t value, struct Buffer *err)
64{
65 if (value == 0)
66 return CSR_SUCCESS;
67
68 const char *str = (const char *) value;
69
71 return CSR_SUCCESS;
72
73 buf_printf(err, _("Invalid value for %s"), cdef->name);
74 buf_addch(err, '\n');
75 struct Slist *sl = store_backend_list();
76 struct Buffer *list = buf_pool_get();
77 struct ListNode *np = NULL;
78 bool first = true;
79 STAILQ_FOREACH(np, &sl->head, entries)
80 {
81 if (!first)
82 buf_addstr(list, ", ");
83 buf_addstr(list, np->data);
84 first = false;
85 }
86 buf_add_printf(err, _("Choose from: %s"), buf_string(list));
87 buf_pool_release(&list);
88 slist_free(&sl);
90}
91
92#if defined(USE_HCACHE_COMPRESSION)
96static int compress_method_validator(const struct ConfigDef *cdef,
97 intptr_t value, struct Buffer *err)
98{
99#ifdef USE_HCACHE_COMPRESSION
100 if (value == 0)
101 return CSR_SUCCESS;
102
103 const char *str = (const char *) value;
104
105 if (compress_get_ops(str))
106 return CSR_SUCCESS;
107
108 buf_printf(err, _("Invalid value for %s"), cdef->name);
109 buf_addch(err, '\n');
110 struct Slist *sl = compress_list();
111 struct Buffer *list = buf_pool_get();
112 struct ListNode *np = NULL;
113 bool first = true;
114 STAILQ_FOREACH(np, &sl->head, entries)
115 {
116 if (!first)
117 buf_addstr(list, ", ");
118 buf_addstr(list, np->data);
119 first = false;
120 }
121 buf_add_printf(err, _("Choose from: %s"), buf_string(list));
122 buf_pool_release(&list);
123 slist_free(&sl);
125#else
126 return CSR_SUCCESS;
127#endif
128}
129
133static int compress_level_validator(const struct ConfigDef *cdef,
134 intptr_t value, struct Buffer *err)
135{
136#ifdef USE_HCACHE_COMPRESSION
137 const char *const c_header_cache_compress_method = cs_subset_string(NeoMutt->sub, "header_cache_compress_method");
138 if (!c_header_cache_compress_method)
139 {
140 buf_printf(err, _("Set option %s before setting %s"),
141 "header_cache_compress_method", cdef->name);
142 return CSR_ERR_INVALID;
143 }
144
145 const struct ComprOps *cops = compress_get_ops(c_header_cache_compress_method);
146 if (!cops)
147 {
148 buf_printf(err, _("Invalid value for option %s: %s"),
149 "header_cache_compress_method", c_header_cache_compress_method);
150 return CSR_ERR_INVALID;
151 }
152
153 if ((value < cops->min_level) || (value > cops->max_level))
154 {
155 // L10N: This applies to the "$header_cache_compress_level" config variable.
156 // It shows the minimum and maximum values, e.g. 'between 1 and 22'
157 buf_printf(err, _("Option %s must be between %d and %d inclusive"),
158 cdef->name, cops->min_level, cops->max_level);
159 return CSR_ERR_INVALID;
160 }
161#endif
162 return CSR_SUCCESS;
163}
164#endif
165
170 // clang-format off
171 { "header_cache", DT_PATH, 0, 0, hcache_validator,
172 "(hcache) Directory/file for the header cache database"
173 },
174 { "header_cache_backend", DT_STRING, 0, 0, hcache_backend_validator,
175 "(hcache) Header cache backend to use"
176 },
177 { NULL },
178 // clang-format on
179};
180
181#if defined(USE_HCACHE_COMPRESSION)
186 // clang-format off
187 // These two are not in alphabetical order because `level`s validator depends on `method`
188 { "header_cache_compress_method", DT_STRING, 0, 0, compress_method_validator,
189 "(hcache) Enable generic hcache database compression"
190 },
191 { "header_cache_compress_level", DT_NUMBER|D_INTEGER_NOT_NEGATIVE, 1, 0, compress_level_validator,
192 "(hcache) Level of compression for method"
193 },
194 { NULL },
195 // clang-format on
196};
197#endif
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition buffer.c:161
int buf_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition buffer.c:204
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition buffer.c:241
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition buffer.c:226
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
const struct ComprOps * compress_get_ops(const char *compr)
Get the API functions for a compress backend.
Definition compress.c:78
struct Slist * compress_list(void)
Get a list of compression backend names.
Definition compress.c:59
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_INV_WARNING
Report as a warning, not an error.
Definition set.h:48
#define CSR_SUCCESS
Action completed successfully.
Definition set.h:33
Convenience wrapper for the core headers.
static int hcache_validator(const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Validate the "header_cache" 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:96
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:133
static int hcache_backend_validator(const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Validate the "header_cache_backend" config variable - Implements ConfigDef::validator() -.
Definition config.c:62
struct ConfigDef HcacheVars[]
Config definitions for the Header Cache.
Definition config.c:169
struct ConfigDef HcacheVarsComp[]
Config definitions for the Header Cache Compression.
Definition config.c:185
Convenience wrapper for the library headers.
#define _(a)
Definition message.h:28
void slist_free(struct Slist **ptr)
Free an Slist object.
Definition slist.c:124
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
#define STAILQ_FOREACH(var, head, field)
Definition queue.h:390
Key value store.
bool store_is_valid_backend(const char *str)
Is the string a valid Store backend.
Definition store.c:110
struct Slist * store_backend_list(void)
Get a list of backend names.
Definition store.c:69
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:66
A List node for strings.
Definition list.h:37
char * data
String.
Definition list.h:38
Container for Accounts, Notifications.
Definition neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
String list.
Definition slist.h:37
struct ListHead head
List containing values.
Definition slist.h:38
@ DT_NUMBER
a number
Definition types.h:38
@ DT_STRING
a string
Definition types.h:44
@ 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