NeoMutt  2022-04-29-178-g3b62e6
Teaching an old dog new tricks
DOXYGEN

Validate a config variable. More...

+ Collaboration diagram for validator():

Functions

int charset_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "charset" config variable - Implements ConfigDef::validator() -. More...
 
int charset_slist_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "charset" config variable - Implements ConfigDef::validator() - This is a version for charset options is Slist. More...
 
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() -. More...
 
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() -. More...
 
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() -. More...
 
static int imap_auth_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "imap_authenticators" config variable - Implements ConfigDef::validator() -. More...
 
int multipart_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "show_multipart_alternative" config variable - Implements ConfigDef::validator() -. More...
 
int reply_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "reply_regex" config variable - Implements ConfigDef::validator() -. More...
 
int level_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "debug_level" config variable - Implements ConfigDef::validator() -. More...
 
int sort_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate values of "sort" - Implements ConfigDef::validator() -. More...
 
static int nm_default_url_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Ensure nm_default_url is of the form notmuch://[absolute path] - Implements ConfigDef::validator() -. More...
 
static int nm_query_window_timebase_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Ensures nm_query_window_timebase matches allowed values - Implements ConfigDef::validator() -. More...
 
static int pop_auth_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "pop_authenticators" config variable - Implements ConfigDef::validator() -. More...
 
static int wrapheaders_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "wrap_headers" config variable - Implements ConfigDef::validator() -. More...
 
static int smtp_auth_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "smtp_authenticators" config variable - Implements ConfigDef::validator() -. More...
 
static int simple_command_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "sendmail" and "inews" config variables - Implements ConfigDef::validator() -. More...
 

Detailed Description

Validate a config variable.

Parameters
csConfig items
cdefConfig definition
valueNative value
errMessage for the user
Return values
CSR_SUCCESSSuccess
CSR_ERR_INVALIDFailure

Function Documentation

◆ charset_validator()

int charset_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)

Validate the "charset" config variable - Implements ConfigDef::validator() -.

Definition at line 40 of file charset.c.

42{
43 if (value == 0)
44 return CSR_SUCCESS;
45
46 const char *str = (const char *) value;
47
48 if ((cdef->type & DT_CHARSET_SINGLE) && strchr(str, ':'))
49 {
50 mutt_buffer_printf(err, _("'charset' must contain exactly one character set name"));
51 return CSR_ERR_INVALID;
52 }
53
54 int rc = CSR_SUCCESS;
55 bool strict = (cdef->type & DT_CHARSET_STRICT);
56 char *q = NULL;
57 char *s = mutt_str_dup(str);
58
59 for (char *p = strtok_r(s, ":", &q); p; p = strtok_r(NULL, ":", &q))
60 {
61 if (*p == '\0')
62 continue; // LCOV_EXCL_LINE
63 if (!mutt_ch_check_charset(p, strict))
64 {
65 rc = CSR_ERR_INVALID;
66 mutt_buffer_printf(err, _("Invalid value for option %s: %s"), cdef->name, p);
67 break;
68 }
69 }
70
71 FREE(&s);
72 return rc;
73}
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:158
#define DT_CHARSET_SINGLE
Flag for charset_validator to allow only one charset.
Definition: charset.h:28
#define DT_CHARSET_STRICT
Flag for charset_validator to use strict char check.
Definition: charset.h:29
#define FREE(x)
Definition: memory.h:43
bool mutt_ch_check_charset(const char *cs, bool strict)
Does iconv understand a character set?
Definition: charset.c:817
#define _(a)
Definition: message.h:28
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:250
#define CSR_ERR_INVALID
Value hasn't been set.
Definition: set.h:38
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
const char * name
User-visible name.
Definition: set.h:65
uint32_t type
Variable type, e.g. DT_STRING.
Definition: set.h:66
+ Here is the call graph for this function:

◆ charset_slist_validator()

int charset_slist_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)

Validate the "charset" config variable - Implements ConfigDef::validator() - This is a version for charset options is Slist.

Definition at line 79 of file charset.c.

81{
82 if (value == 0)
83 return CSR_SUCCESS;
84
85 const struct Slist *list = (const struct Slist *) value;
86
87 int rc = CSR_SUCCESS;
88 bool strict = (cdef->type & DT_CHARSET_STRICT);
89
90 const struct ListNode *np = NULL;
91 STAILQ_FOREACH(np, &list->head, entries)
92 {
93 char const *charset = np->data;
94 if (!mutt_ch_check_charset(charset, strict))
95 {
96 rc = CSR_ERR_INVALID;
97 mutt_buffer_printf(err, _("Invalid value for option %s: %s"), cdef->name, charset);
98 break;
99 }
100 }
101
102 return rc;
103}
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
A List node for strings.
Definition: list.h:35
char * data
String.
Definition: list.h:36
String list.
Definition: slist.h:47
struct ListHead head
List containing values.
Definition: slist.h:48
+ Here is the call graph for this function:

◆ hcache_validator()

static int hcache_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Validate the "header_cache_backend" config variable - Implements ConfigDef::validator() -.

Definition at line 42 of file config.c.

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 mutt_buffer_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}
bool store_is_valid_backend(const char *str)
Is the string a valid Store backend.
Definition: store.c:129
+ Here is the call graph for this function:

◆ compress_method_validator()

static int compress_method_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Validate the "header_cache_compress_method" config variable - Implements ConfigDef::validator() -.

Definition at line 65 of file config.c.

68{
69#ifdef USE_HCACHE_COMPRESSION
70 if (value == 0)
71 return CSR_SUCCESS;
72
73 const char *str = (const char *) value;
74
75 if (compress_get_ops(str))
76 return CSR_SUCCESS;
77
78 mutt_buffer_printf(err, _("Invalid value for option %s: %s"), cdef->name, str);
79 return CSR_ERR_INVALID;
80#else
81 return CSR_SUCCESS;
82#endif
83}
const struct ComprOps * compress_get_ops(const char *compr)
Get the API functions for a compress backend.
Definition: compress.c:80
+ Here is the call graph for this function:

◆ compress_level_validator()

static int compress_level_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Validate the "header_cache_compress_level" config variable - Implements ConfigDef::validator() -.

Definition at line 88 of file config.c.

90{
91#ifdef USE_HCACHE_COMPRESSION
92 const char *const c_header_cache_compress_method = cs_subset_string(NeoMutt->sub, "header_cache_compress_method");
93 if (!c_header_cache_compress_method)
94 {
95 mutt_buffer_printf(err, _("Set option %s before setting %s"),
96 "header_cache_compress_method", cdef->name);
97 return CSR_ERR_INVALID;
98 }
99
100 const struct ComprOps *cops = compress_get_ops(c_header_cache_compress_method);
101 if (!cops)
102 {
103 mutt_buffer_printf(err, _("Invalid value for option %s: %s"),
104 "header_cache_compress_method", c_header_cache_compress_method);
105 return CSR_ERR_INVALID;
106 }
107
108 if ((value < cops->min_level) || (value > cops->max_level))
109 {
110 // L10N: This applies to the "$header_cache_compress_level" config variable.
111 // It shows the minimum and maximum values, e.g. 'between 1 and 22'
112 mutt_buffer_printf(err, _("Option %s must be between %d and %d inclusive"),
113 cdef->name, cops->min_level, cops->max_level);
114 return CSR_ERR_INVALID;
115 }
116#endif
117 return CSR_SUCCESS;
118}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
Definition: lib.h:60
short max_level
Maximum compression level.
Definition: lib.h:63
short min_level
Minimum compression level.
Definition: lib.h:62
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
+ Here is the call graph for this function:

◆ imap_auth_validator()

static int imap_auth_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Validate the "imap_authenticators" config variable - Implements ConfigDef::validator() -.

Definition at line 41 of file config.c.

43{
44 const struct Slist *imap_auth_methods = (const struct Slist *) value;
45 if (!imap_auth_methods || (imap_auth_methods->count == 0))
46 return CSR_SUCCESS;
47
48 struct ListNode *np = NULL;
49 STAILQ_FOREACH(np, &imap_auth_methods->head, entries)
50 {
51 if (imap_auth_is_valid(np->data))
52 continue;
53#ifdef USE_SASL
55 continue;
56#endif
57 mutt_buffer_printf(err, _("Option %s: %s is not a valid authenticator"),
58 cdef->name, np->data);
59 return CSR_ERR_INVALID;
60 }
61
62 return CSR_SUCCESS;
63}
bool imap_auth_is_valid(const char *authenticator)
Check if string is a valid imap authentication method.
Definition: auth.c:88
bool sasl_auth_validator(const char *authenticator)
Validate an auth method against Cyrus SASL methods.
Definition: sasl.c:131
size_t count
Number of values in list.
Definition: slist.h:49
+ Here is the call graph for this function:

◆ multipart_validator()

int multipart_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)

Validate the "show_multipart_alternative" config variable - Implements ConfigDef::validator() -.

Definition at line 115 of file mutt_config.c.

117{
118 if (value == 0)
119 return CSR_SUCCESS;
120
121 const char *str = (const char *) value;
122
123 if (mutt_str_equal(str, "inline") || mutt_str_equal(str, "info"))
124 return CSR_SUCCESS;
125
126 mutt_buffer_printf(err, _("Invalid value for option %s: %s"), cdef->name, str);
127 return CSR_ERR_INVALID;
128}
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:784
+ Here is the call graph for this function:

◆ reply_validator()

int reply_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)

Validate the "reply_regex" config variable - Implements ConfigDef::validator() -.

Definition at line 133 of file mutt_config.c.

135{
136 if (!OptAttachMsg)
137 return CSR_SUCCESS;
138
139 mutt_buffer_printf(err, _("Option %s may not be set when in attach-message mode"),
140 cdef->name);
141 return CSR_ERR_INVALID;
142}
bool OptAttachMsg
(pseudo) used by attach-message
Definition: options.h:37
+ Here is the call graph for this function:

◆ level_validator()

int level_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)

Validate the "debug_level" config variable - Implements ConfigDef::validator() -.

Definition at line 273 of file mutt_logging.c.

275{
276 if ((value < 0) || (value >= LL_MAX))
277 {
278 mutt_buffer_printf(err, _("Invalid value for option %s: %ld"), cdef->name, value);
279 return CSR_ERR_INVALID;
280 }
281
282 return CSR_SUCCESS;
283}
@ LL_MAX
Definition: logging.h:47
+ Here is the call graph for this function:

◆ sort_validator()

int sort_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)

Validate values of "sort" - Implements ConfigDef::validator() -.

Definition at line 115 of file mutt_thread.c.

117{
118 if (((value & SORT_MASK) == SORT_THREADS) && (value & SORT_LAST))
119 {
120 mutt_buffer_printf(err, _("Cannot use 'last-' prefix with 'threads' for %s"), cdef->name);
121 return CSR_ERR_INVALID;
122 }
123 return CSR_SUCCESS;
124}
#define SORT_MASK
Mask for the sort id.
Definition: sort2.h:78
#define SORT_LAST
Sort thread by last-X, e.g. received date.
Definition: sort2.h:80
@ SORT_THREADS
Sort by email threads.
Definition: sort2.h:49
+ Here is the call graph for this function:

◆ nm_default_url_validator()

static int nm_default_url_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Ensure nm_default_url is of the form notmuch://[absolute path] - Implements ConfigDef::validator() -.

Definition at line 53 of file config.c.

55{
56#ifdef USE_NOTMUCH
57 const char *url = (const char *) value;
58 if (!is_valid_notmuch_url(url))
59 {
60 mutt_buffer_printf(err, _("nm_default_url must be: notmuch://<absolute path> . Current: %s"),
61 url);
62 return CSR_ERR_INVALID;
63 }
64#endif
65 return CSR_SUCCESS;
66}
static bool is_valid_notmuch_url(const char *url)
Checks that a URL is in required form.
Definition: config.c:44
+ Here is the call graph for this function:

◆ nm_query_window_timebase_validator()

static int nm_query_window_timebase_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Ensures nm_query_window_timebase matches allowed values - Implements ConfigDef::validator() -.

Allowed values:

  • hour
  • day
  • week
  • month
  • year

Definition at line 78 of file config.c.

81{
82#ifdef USE_NOTMUCH
83 const char *timebase = (const char *) value;
84 if (!nm_query_window_check_timebase(timebase))
85 {
87 // L10N: The values 'hour', 'day', 'week', 'month', 'year' are literal.
88 // They should not be translated.
89 err, _("Invalid nm_query_window_timebase value (valid values are: "
90 "hour, day, week, month, year)"));
91 return CSR_ERR_INVALID;
92 }
93#endif
94 return CSR_SUCCESS;
95}
bool nm_query_window_check_timebase(const char *timebase)
Checks if a given timebase string is valid.
Definition: query.c:150
+ Here is the call graph for this function:

◆ pop_auth_validator()

static int pop_auth_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Validate the "pop_authenticators" config variable - Implements ConfigDef::validator() -.

Definition at line 41 of file config.c.

43{
44 const struct Slist *pop_auth_methods = (const struct Slist *) value;
45 if (!pop_auth_methods || (pop_auth_methods->count == 0))
46 return CSR_SUCCESS;
47
48 struct ListNode *np = NULL;
49 STAILQ_FOREACH(np, &pop_auth_methods->head, entries)
50 {
51 if (pop_auth_is_valid(np->data))
52 continue;
53#ifdef USE_SASL
55 continue;
56#endif
57 mutt_buffer_printf(err, _("Option %s: %s is not a valid authenticator"),
58 cdef->name, np->data);
59 return CSR_ERR_INVALID;
60 }
61
62 return CSR_SUCCESS;
63}
bool pop_auth_is_valid(const char *authenticator)
Check if string is a valid pop authentication method.
Definition: auth.c:403
+ Here is the call graph for this function:

◆ wrapheaders_validator()

static int wrapheaders_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Validate the "wrap_headers" config variable - Implements ConfigDef::validator() -.

Definition at line 41 of file config.c.

43{
44 const int min_length = 78; // Recommendations from RFC5233
45 const int max_length = 998;
46
47 if ((value >= min_length) && (value <= max_length))
48 return CSR_SUCCESS;
49
50 // L10N: This applies to the "$wrap_headers" config variable.
51 mutt_buffer_printf(err, _("Option %s must be between %d and %d inclusive"),
52 cdef->name, min_length, max_length);
53 return CSR_ERR_INVALID;
54}
+ Here is the call graph for this function:

◆ smtp_auth_validator()

static int smtp_auth_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Validate the "smtp_authenticators" config variable - Implements ConfigDef::validator() -.

Definition at line 59 of file config.c.

61{
62 const struct Slist *smtp_auth_methods = (const struct Slist *) value;
63 if (!smtp_auth_methods || (smtp_auth_methods->count == 0))
64 return CSR_SUCCESS;
65
66 struct ListNode *np = NULL;
67 STAILQ_FOREACH(np, &smtp_auth_methods->head, entries)
68 {
69 if (smtp_auth_is_valid(np->data))
70 continue;
71#ifdef USE_SASL
73 continue;
74#endif
75 mutt_buffer_printf(err, _("Option %s: %s is not a valid authenticator"),
76 cdef->name, np->data);
77 return CSR_ERR_INVALID;
78 }
79
80 return CSR_SUCCESS;
81}
bool smtp_auth_is_valid(const char *authenticator)
Check if string is a valid smtp authentication method.
Definition: smtp.c:738
+ Here is the call graph for this function:

◆ simple_command_validator()

static int simple_command_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Validate the "sendmail" and "inews" config variables - Implements ConfigDef::validator() -.

Definition at line 86 of file config.c.

88{
89 // Check for shell metacharacters that won't do what the user expects
90 const char *valstr = (const char *) value;
91 if (!valstr)
92 return CSR_SUCCESS;
93
94 const char c = valstr[strcspn(valstr, "|&;()<>[]{}$`'~\"\\*?")];
95 if (c == '\0')
96 return CSR_SUCCESS;
97
98 // L10N: This applies to the "$sendmail" and "$inews" config variables.
99 mutt_buffer_printf(err, _("Option %s must not contain shell metacharacters: %c"),
100 cdef->name, c);
101 return CSR_ERR_INVALID;
102}
+ Here is the call graph for this function: