NeoMutt  2021-02-05
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 "mutt/lib.h"
33 #include "config/lib.h"
34 #include "lib.h"
35 #include "compress/lib.h"
36 #include "store/lib.h"
37 #include "init.h"
38 
39 // clang-format off
42 #ifdef USE_HCACHE_COMPRESSION
45 #endif
46 // clang-format on
47 
48 bool C_HeaderCacheCompress = false;
49 #if defined(HAVE_GDBM) || defined(HAVE_BDB)
51 #endif
52 
56 int hcache_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef,
57  intptr_t value, struct Buffer *err)
58 {
59  if (value == 0)
60  return CSR_SUCCESS;
61 
62  const char *str = (const char *) value;
63 
64  if (store_is_valid_backend(str))
65  return CSR_SUCCESS;
66 
67  mutt_buffer_printf(err, _("Invalid value for option %s: %s"), cdef->name, str);
68  return CSR_ERR_INVALID;
69 }
70 
71 #ifdef USE_HCACHE_COMPRESSION
72 
75 int compress_method_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef,
76  intptr_t value, struct Buffer *err)
77 {
78  if (value == 0)
79  return CSR_SUCCESS;
80 
81  const char *str = (const char *) value;
82 
83  if (compress_get_ops(str))
84  return CSR_SUCCESS;
85 
86  mutt_buffer_printf(err, _("Invalid value for option %s: %s"), cdef->name, str);
87  return CSR_ERR_INVALID;
88 }
89 
93 int compress_level_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef,
94  intptr_t value, struct Buffer *err)
95 {
97  {
98  mutt_buffer_printf(err, _("Set option %s before setting %s"),
99  "header_cache_compress_method", cdef->name);
100  return CSR_ERR_INVALID;
101  }
102 
104  if (!cops)
105  {
106  mutt_buffer_printf(err, _("Invalid value for option %s: %s"),
107  "header_cache_compress_method", C_HeaderCacheCompressMethod);
108  return CSR_ERR_INVALID;
109  }
110 
111  if ((value < cops->min_level) || (value > cops->max_level))
112  {
113  // L10N: This applies to the "$header_cache_compress_level" config variable.
114  // It shows the minimum and maximum values, e.g. 'between 1 and 22'
115  mutt_buffer_printf(err, _("Option %s must be between %d and %d inclusive"),
116  cdef->name, cops->min_level, cops->max_level);
117  return CSR_ERR_INVALID;
118  }
119 
120  return CSR_SUCCESS;
121 }
122 #endif /* USE_HCACHE_COMPRESSION */
123 
124 struct ConfigDef HcacheVars[] = {
125  // clang-format off
126  { "header_cache", DT_PATH, &C_HeaderCache, 0, 0, NULL,
127  "(hcache) Directory/file for the header cache database"
128  },
129  { "header_cache_backend", DT_STRING, &C_HeaderCacheBackend, 0, 0, hcache_validator,
130  "(hcache) Header cache backend to use"
131  },
132 #if defined(USE_HCACHE_COMPRESSION)
133  { "header_cache_compress_level", DT_NUMBER|DT_NOT_NEGATIVE, &C_HeaderCacheCompressLevel, 1, 0, compress_level_validator,
134  "(hcache) Level of compression for method"
135  },
136  { "header_cache_compress_method", DT_STRING, &C_HeaderCacheCompressMethod, 0, 0, compress_method_validator,
137  "(hcache) Enable generic hcache database compression"
138  },
139 #endif
140 #if defined(HAVE_QDBM) || defined(HAVE_TC) || defined(HAVE_KC)
141  { "header_cache_compress", DT_DEPRECATED|DT_BOOL, &C_HeaderCacheCompress, false, 0, NULL, NULL },
142 #endif
143 #if defined(HAVE_GDBM) || defined(HAVE_BDB)
144  { "header_cache_pagesize", DT_DEPRECATED|DT_LONG, &C_HeaderCachePagesize, 0, 0, NULL, NULL },
145 #endif
146  { NULL, 0, NULL, 0, 0, NULL, NULL },
147  // clang-format on
148 };
149 
154 {
155  return cs_register_variables(cs, HcacheVars, 0);
156 }
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
char * C_HeaderCacheCompressMethod
Config: (hcache) Enable generic hcache database compression.
Definition: config.c:44
Container for lots of config items.
Definition: set.h:228
#define CSR_ERR_INVALID
Value hasn&#39;t been set.
Definition: set.h:38
#define DT_LONG
a number (long)
Definition: types.h:33
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:93
Config/command parsing.
const struct ComprOps * compress_get_ops(const char *compr)
Get the API functions for a compress backend.
Definition: compress.c:81
char * C_HeaderCache
Config: (hcache) Directory/file for the header cache database.
Definition: config.c:40
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:75
long C_HeaderCachePagesize
Definition: config.c:50
bool C_HeaderCacheCompress
Definition: config.c:48
String manipulation buffer.
Definition: buffer.h:33
short max_level
Maximum compression level.
Definition: lib.h:59
#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
Config item definition.
Definition: set.h:61
Convenience wrapper for the config headers.
API for the header cache compression.
bool config_init_hcache(struct ConfigSet *cs)
Register hcache config variables - Implements module_init_config_t.
Definition: config.c:153
short C_HeaderCacheCompressLevel
Config: (hcache) Level of compression for method.
Definition: config.c:43
bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[], uint32_t flags)
Register a set of config items.
Definition: set.c:286
const char * name
User-visible name.
Definition: set.h:63
#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:79
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:56
Key value store.
Header Cache Compression API.
Definition: lib.h:55
char * C_HeaderCacheBackend
Config: (hcache) Header cache backend to use.
Definition: config.c:41
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:58
Convenience wrapper for the library headers.
#define DT_NUMBER
a number
Definition: types.h:35
#define DT_BOOL
boolean option
Definition: types.h:30