NeoMutt  2021-02-05-666-ge300cd
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 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...
 
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...
 
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() -Allowed values: 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...
 

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 39 of file charset.c.

41 {
42  if (value == 0)
43  return CSR_SUCCESS;
44 
45  const char *str = (const char *) value;
46 
47  if ((cdef->type & DT_CHARSET_SINGLE) && strchr(str, ':'))
48  {
50  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;
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 }
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
#define CSR_ERR_INVALID
Value hasn't been set.
Definition: set.h:38
#define DT_CHARSET_SINGLE
Flag for charset_validator to allow only one charset.
Definition: charset.h:28
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
#define _(a)
Definition: message.h:28
#define DT_CHARSET_STRICT
Flag for charset_validator to use strict char check.
Definition: charset.h:29
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
bool mutt_ch_check_charset(const char *cs, bool strict)
Does iconv understand a character set?
Definition: charset.c:822
const char * name
User-visible name.
Definition: set.h:65
uint32_t type
Variable type, e.g. DT_STRING.
Definition: set.h:66
#define FREE(x)
Definition: memory.h:40
+ Here is the call graph for this function:

◆ hcache_validator()

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 at line 42 of file config.c.

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 }
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
#define CSR_ERR_INVALID
Value hasn't been set.
Definition: set.h:38
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
const char * name
User-visible name.
Definition: set.h:65
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()

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 at line 61 of file config.c.

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 }
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
#define CSR_ERR_INVALID
Value hasn't been set.
Definition: set.h:38
const struct ComprOps * compress_get_ops(const char *compr)
Get the API functions for a compress backend.
Definition: compress.c:80
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
const char * name
User-visible name.
Definition: set.h:65
+ Here is the call graph for this function:

◆ compress_level_validator()

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 at line 79 of file config.c.

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 }
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
#define CSR_ERR_INVALID
Value hasn&#39;t been set.
Definition: set.h:38
const struct ComprOps * compress_get_ops(const char *compr)
Get the API functions for a compress backend.
Definition: compress.c:80
short max_level
Maximum compression level.
Definition: lib.h:63
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
Container for Accounts, Notifications.
Definition: neomutt.h:36
const char * name
User-visible name.
Definition: set.h:65
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:59
short min_level
Minimum compression level.
Definition: lib.h:62
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
54  if (sasl_auth_validator(np->data))
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 }
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
#define CSR_ERR_INVALID
Value hasn&#39;t been set.
Definition: set.h:38
#define _(a)
Definition: message.h:28
String list.
Definition: slist.h:46
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
struct ListHead head
Definition: slist.h:48
const char * name
User-visible name.
Definition: set.h:65
size_t count
Definition: slist.h:49
bool imap_auth_is_valid(const char *authenticator)
Check if string is a valid imap authentication method.
Definition: auth.c:87
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
char * data
String.
Definition: list.h:36
A List node for strings.
Definition: list.h:34
bool sasl_auth_validator(const char *authenticator)
Validate an auth method against Cyrus SASL methods.
Definition: sasl.c:127
+ 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 116 of file mutt_config.c.

118 {
119  if (value == 0)
120  return CSR_SUCCESS;
121 
122  const char *str = (const char *) value;
123 
124  if (mutt_str_equal(str, "inline") || mutt_str_equal(str, "info"))
125  return CSR_SUCCESS;
126 
127  mutt_buffer_printf(err, _("Invalid value for option %s: %s"), cdef->name, str);
128  return CSR_ERR_INVALID;
129 }
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
#define CSR_ERR_INVALID
Value hasn&#39;t been set.
Definition: set.h:38
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
const char * name
User-visible name.
Definition: set.h:65
+ 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 134 of file mutt_config.c.

136 {
137  if (!OptAttachMsg)
138  return CSR_SUCCESS;
139 
140  mutt_buffer_printf(err, _("Option %s may not be set when in attach-message mode"),
141  cdef->name);
142  return CSR_ERR_INVALID;
143 }
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
#define CSR_ERR_INVALID
Value hasn&#39;t been set.
Definition: set.h:38
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
const char * name
User-visible name.
Definition: set.h:65
WHERE bool OptAttachMsg
(pseudo) used by attach-message
Definition: options.h:31
+ 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 306 of file mutt_logging.c.

308 {
309  if ((value < 0) || (value >= LL_MAX))
310  {
311  mutt_buffer_printf(err, _("Invalid value for option %s: %ld"), cdef->name, value);
312  return CSR_ERR_INVALID;
313  }
314 
315  return CSR_SUCCESS;
316 }
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
#define CSR_ERR_INVALID
Value hasn&#39;t been set.
Definition: set.h:38
#define _(a)
Definition: message.h:28
Definition: logging.h:47
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
const char * name
User-visible name.
Definition: set.h:65
+ 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 116 of file mutt_thread.c.

118 {
119  if (((value & SORT_MASK) == SORT_THREADS) && (value & SORT_LAST))
120  {
121  mutt_buffer_printf(err, _("Cannot use 'last-' prefix with 'threads' for %s"), cdef->name);
122  return CSR_ERR_INVALID;
123  }
124  return CSR_SUCCESS;
125 }
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
#define CSR_ERR_INVALID
Value hasn&#39;t been set.
Definition: set.h:38
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
const char * name
User-visible name.
Definition: set.h:65
Sort by email threads.
Definition: sort2.h:49
#define SORT_LAST
Sort thread by last-X, e.g. received date.
Definition: sort2.h:80
#define SORT_MASK
Mask for the sort id.
Definition: sort2.h:78
+ 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 51 of file config.c.

53 {
54  const char *url = (const char *) value;
55  if (!is_valid_notmuch_url(url))
56  {
58  err, _("nm_default_url must be: notmuch://<absolute path> . Current: %s"), url);
59  return CSR_ERR_INVALID;
60  }
61 
62  return CSR_SUCCESS;
63 }
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
#define CSR_ERR_INVALID
Value hasn&#39;t been set.
Definition: set.h:38
#define _(a)
Definition: message.h:28
static bool is_valid_notmuch_url(const char *url)
Checks that a URL is in required form.
Definition: config.c:43
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
+ 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 75 of file config.c.

78 {
79  const char *timebase = (const char *) value;
80  if (!nm_query_window_check_timebase(timebase))
81  {
83  // L10N: The values 'hour', 'day', 'week', 'month', 'year' are literal.
84  // They should not be translated.
85  err, _("Invalid nm_query_window_timebase value (valid values are: "
86  "hour, day, week, month, year)"));
87  return CSR_ERR_INVALID;
88  }
89 
90  return CSR_SUCCESS;
91 }
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
#define CSR_ERR_INVALID
Value hasn&#39;t been set.
Definition: set.h:38
bool nm_query_window_check_timebase(const char *timebase)
Checks if a given timebase string is valid.
Definition: query.c:149
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
+ 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
54  if (sasl_auth_validator(np->data))
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 }
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
#define CSR_ERR_INVALID
Value hasn&#39;t been set.
Definition: set.h:38
#define _(a)
Definition: message.h:28
String list.
Definition: slist.h:46
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
bool pop_auth_is_valid(const char *authenticator)
Check if string is a valid pop authentication method.
Definition: auth.c:407
struct ListHead head
Definition: slist.h:48
const char * name
User-visible name.
Definition: set.h:65
size_t count
Definition: slist.h:49
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
char * data
String.
Definition: list.h:36
A List node for strings.
Definition: list.h:34
bool sasl_auth_validator(const char *authenticator)
Validate an auth method against Cyrus SASL methods.
Definition: sasl.c:127
+ 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 }
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
#define CSR_ERR_INVALID
Value hasn&#39;t been set.
Definition: set.h:38
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
const char * name
User-visible name.
Definition: set.h:65
+ 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
72  if (sasl_auth_validator(np->data))
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 }
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
#define CSR_ERR_INVALID
Value hasn&#39;t been set.
Definition: set.h:38
#define _(a)
Definition: message.h:28
String list.
Definition: slist.h:46
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
struct ListHead head
Definition: slist.h:48
const char * name
User-visible name.
Definition: set.h:65
size_t count
Definition: slist.h:49
bool smtp_auth_is_valid(const char *authenticator)
Check if string is a valid smtp authentication method.
Definition: smtp.c:719
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
char * data
String.
Definition: list.h:36
A List node for strings.
Definition: list.h:34
bool sasl_auth_validator(const char *authenticator)
Validate an auth method against Cyrus SASL methods.
Definition: sasl.c:127
+ Here is the call graph for this function: