NeoMutt  2021-02-05-666-ge300cd
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 
42 int hcache_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef,
43  intptr_t value, struct Buffer *err)
44 {
45  if (value == 0)
46  return CSR_SUCCESS;
47 
48  const char *str = (const char *) value;
49 
50  if (store_is_valid_backend(str))
51  return CSR_SUCCESS;
52 
53  mutt_buffer_printf(err, _("Invalid value for option %s: %s"), cdef->name, str);
54  return CSR_ERR_INVALID;
55 }
56 
57 #ifdef USE_HCACHE_COMPRESSION
58 
61 int compress_method_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef,
62  intptr_t value, struct Buffer *err)
63 {
64  if (value == 0)
65  return CSR_SUCCESS;
66 
67  const char *str = (const char *) value;
68 
69  if (compress_get_ops(str))
70  return CSR_SUCCESS;
71 
72  mutt_buffer_printf(err, _("Invalid value for option %s: %s"), cdef->name, str);
73  return CSR_ERR_INVALID;
74 }
75 
79 int compress_level_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef,
80  intptr_t value, struct Buffer *err)
81 {
82  const char *const c_header_cache_compress_method =
83  cs_subset_string(NeoMutt->sub, "header_cache_compress_method");
84  if (!c_header_cache_compress_method)
85  {
86  mutt_buffer_printf(err, _("Set option %s before setting %s"),
87  "header_cache_compress_method", cdef->name);
88  return CSR_ERR_INVALID;
89  }
90 
91  const struct ComprOps *cops = compress_get_ops(c_header_cache_compress_method);
92  if (!cops)
93  {
94  mutt_buffer_printf(err, _("Invalid value for option %s: %s"),
95  "header_cache_compress_method", c_header_cache_compress_method);
96  return CSR_ERR_INVALID;
97  }
98 
99  if ((value < cops->min_level) || (value > cops->max_level))
100  {
101  // L10N: This applies to the "$header_cache_compress_level" config variable.
102  // It shows the minimum and maximum values, e.g. 'between 1 and 22'
103  mutt_buffer_printf(err, _("Option %s must be between %d and %d inclusive"),
104  cdef->name, cops->min_level, cops->max_level);
105  return CSR_ERR_INVALID;
106  }
107 
108  return CSR_SUCCESS;
109 }
110 #endif /* USE_HCACHE_COMPRESSION */
111 
112 static struct ConfigDef HcacheVars[] = {
113  // clang-format off
114  { "header_cache", DT_PATH, 0, 0, NULL,
115  "(hcache) Directory/file for the header cache database"
116  },
117  { "header_cache_backend", DT_STRING, 0, 0, hcache_validator,
118  "(hcache) Header cache backend to use"
119  },
120 #if defined(USE_HCACHE_COMPRESSION)
121  // These two are not in alphabetical order because `level`s validator depends on `method`
122  { "header_cache_compress_method", DT_STRING, 0, 0, compress_method_validator,
123  "(hcache) Enable generic hcache database compression"
124  },
125  { "header_cache_compress_level", DT_NUMBER|DT_NOT_NEGATIVE, 1, 0, compress_level_validator,
126  "(hcache) Level of compression for method"
127  },
128 #endif
129 #if defined(HAVE_QDBM) || defined(HAVE_TC) || defined(HAVE_KC)
130  { "header_cache_compress", DT_DEPRECATED|DT_BOOL, false, 0, NULL, NULL },
131 #endif
132 #if defined(HAVE_GDBM) || defined(HAVE_BDB)
133  { "header_cache_pagesize", DT_DEPRECATED|DT_LONG, 0, 0, NULL, NULL },
134 #endif
135 
136  { NULL },
137  // clang-format on
138 };
139 
144 {
145  return cs_register_variables(cs, HcacheVars, 0);
146 }
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
Container for lots of config items.
Definition: set.h:259
#define CSR_ERR_INVALID
Value hasn&#39;t been set.
Definition: set.h:38
#define DT_LONG
a number (long)
Definition: types.h:33
const struct ComprOps * compress_get_ops(const char *compr)
Get the API functions for a compress backend.
Definition: compress.c:80
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
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:79
String manipulation buffer.
Definition: buffer.h:33
short max_level
Maximum compression level.
Definition: lib.h:63
#define _(a)
Definition: message.h:28
#define DT_NOT_NEGATIVE
Negative numbers are not allowed.
Definition: types.h:47
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
Definition: set.h:63
Container for Accounts, Notifications.
Definition: neomutt.h:36
Convenience wrapper for the config headers.
API for the header cache compression.
Convenience wrapper for the core headers.
bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[], uint32_t flags)
Register a set of config items.
Definition: set.c:276
const char * name
User-visible name.
Definition: set.h:65
#define DT_STRING
a string
Definition: types.h:41
#define DT_PATH
a path to a file/directory
Definition: types.h:36
#define DT_DEPRECATED
Config item shouldn&#39;t be used any more.
Definition: types.h:77
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
Key value store.
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:61
Definition: lib.h:59
bool store_is_valid_backend(const char *str)
Is the string a valid Store backend.
Definition: store.c:129
short min_level
Minimum compression level.
Definition: lib.h:62
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
Convenience wrapper for the library headers.
#define DT_NUMBER
a number
Definition: types.h:35
#define DT_BOOL
boolean option
Definition: types.h:30
bool config_init_hcache(struct ConfigSet *cs)
Register hcache config variables - Implements module_init_config_t -.
Definition: config.c:143