NeoMutt  2023-11-03-107-g582dc1
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
native_set()

Set a config item by string. More...

+ Collaboration diagram for native_set():

Functions

static int address_native_set (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Set an Address config item by Address object - Implements ConfigSetType::native_set() -.
 
static int bool_native_set (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Set a Bool config item by bool - Implements ConfigSetType::native_set() -.
 
static int enum_native_set (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Set an Enumeration config item by int - Implements ConfigSetType::native_set() -.
 
static int long_native_set (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Set a Long config item by long - Implements ConfigSetType::native_set() -.
 
static int mbtable_native_set (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Set an MbTable config item by MbTable object - Implements ConfigSetType::native_set() -.
 
static int myvar_native_set (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Set a MyVar config item by string - Implements ConfigSetType::native_set() -.
 
static int number_native_set (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Set a Number config item by int - Implements ConfigSetType::native_set() -.
 
static int path_native_set (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Set a Path config item by string - Implements ConfigSetType::native_set() -.
 
static int quad_native_set (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Set a Quad-option config item by int - Implements ConfigSetType::native_set() -.
 
static int regex_native_set (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Set a Regex config item by Regex object - Implements ConfigSetType::native_set() -.
 
static int slist_native_set (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Set a Slist config item by Slist - Implements ConfigSetType::native_set() -.
 
static int sort_native_set (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Set a Sort config item by int - Implements ConfigSetType::native_set() -.
 
static int string_native_set (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Set a String config item by string - Implements ConfigSetType::native_set() -.
 

Detailed Description

Set a config item by string.

Parameters
csConfig items
varVariable to set
cdefVariable definition
valueNative pointer/value to set
errBuffer for error messages (may be NULL)
Return values
numResult, e.g. CSR_SUCCESS
Precondition
cs is not NULL
var is not NULL
cdef is not NULL

Function Documentation

◆ address_native_set()

static int address_native_set ( const struct ConfigSet cs,
void *  var,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Set an Address config item by Address object - Implements ConfigSetType::native_set() -.

Definition at line 169 of file config_type.c.

172{
173 int rc;
174
175 if (cdef->validator)
176 {
177 rc = cdef->validator(cs, cdef, value, err);
178
179 if (CSR_RESULT(rc) != CSR_SUCCESS)
180 return rc | CSR_INV_VALIDATOR;
181 }
182
183 mutt_addr_free(var);
184
185 struct Address *addr = address_dup((struct Address *) value);
186
187 rc = CSR_SUCCESS;
188 if (!addr)
189 rc |= CSR_SUC_EMPTY;
190
191 *(struct Address **) var = addr;
192 return rc;
193}
void mutt_addr_free(struct Address **ptr)
Free a single Address.
Definition: address.c:460
#define CSR_INV_VALIDATOR
Value was rejected by the validator.
Definition: set.h:48
#define CSR_RESULT(x)
Definition: set.h:52
#define CSR_SUC_EMPTY
Value is empty/unset.
Definition: set.h:42
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
static struct Address * address_dup(struct Address *addr)
Create a copy of an Address object.
Definition: config_type.c:155
An email address.
Definition: address.h:36
int(* validator)(const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Definition: set.h:82
+ Here is the call graph for this function:

◆ bool_native_set()

static int bool_native_set ( const struct ConfigSet cs,
void *  var,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Set a Bool config item by bool - Implements ConfigSetType::native_set() -.

Definition at line 128 of file bool.c.

130{
131 if ((value < 0) || (value > 1))
132 {
133 buf_printf(err, _("Invalid boolean value: %ld"), (long) value);
135 }
136
137 if (value == (*(bool *) var))
139
140 if (startup_only(cdef, err))
142
143 if (cdef->validator)
144 {
145 int rc = cdef->validator(cs, cdef, value, err);
146
147 if (CSR_RESULT(rc) != CSR_SUCCESS)
148 return rc | CSR_INV_VALIDATOR;
149 }
150
151 *(bool *) var = value;
152 return CSR_SUCCESS;
153}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:173
static bool startup_only(const struct ConfigDef *cdef, struct Buffer *err)
Validator function for DT_ON_STARTUP.
Definition: set.h:301
#define CSR_ERR_INVALID
Value hasn't been set.
Definition: set.h:38
#define CSR_INV_TYPE
Value is not valid for the type.
Definition: set.h:47
#define CSR_SUC_NO_CHANGE
The value hasn't changed.
Definition: set.h:44
#define _(a)
Definition: message.h:28
+ Here is the call graph for this function:

◆ enum_native_set()

static int enum_native_set ( const struct ConfigSet cs,
void *  var,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Set an Enumeration config item by int - Implements ConfigSetType::native_set() -.

Definition at line 122 of file enum.c.

124{
125 if (!cs || !var || !cdef)
126 return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
127
128 struct EnumDef *ed = (struct EnumDef *) cdef->data;
129 if (!ed || !ed->lookup)
130 return CSR_ERR_CODE;
131
132 const char *name = mutt_map_get_name(value, ed->lookup);
133 if (!name)
134 {
135 buf_printf(err, _("Invalid enum value: %ld"), (long) value);
137 }
138
139 if (value == (*(unsigned char *) var))
141
142 if (startup_only(cdef, err))
144
145 if (cdef->validator)
146 {
147 int rc = cdef->validator(cs, cdef, value, err);
148
149 if (CSR_RESULT(rc) != CSR_SUCCESS)
150 return rc | CSR_INV_VALIDATOR;
151 }
152
153 *(unsigned char *) var = value;
154 return CSR_SUCCESS;
155}
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition: mapping.c:42
intptr_t data
Extra variable data.
Definition: set.h:68
An enumeration.
Definition: enum.h:30
const char * name
Config variable.
Definition: enum.h:31
struct Mapping * lookup
Lookup table.
Definition: enum.h:33
+ Here is the call graph for this function:

◆ long_native_set()

static int long_native_set ( const struct ConfigSet cs,
void *  var,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Set a Long config item by long - Implements ConfigSetType::native_set() -.

Definition at line 111 of file long.c.

113{
114 if ((value < 0) && (cdef->type & DT_NOT_NEGATIVE))
115 {
116 buf_printf(err, _("Option %s may not be negative"), cdef->name);
118 }
119
120 if (value == (*(long *) var))
122
123 if (startup_only(cdef, err))
125
126 if (cdef->validator)
127 {
128 int rc = cdef->validator(cs, cdef, value, err);
129
130 if (CSR_RESULT(rc) != CSR_SUCCESS)
131 return rc | CSR_INV_VALIDATOR;
132 }
133
134 *(long *) var = value;
135 return CSR_SUCCESS;
136}
const char * name
User-visible name.
Definition: set.h:65
uint32_t type
Variable type, e.g. DT_STRING.
Definition: set.h:66
#define DT_NOT_NEGATIVE
Negative numbers are not allowed.
Definition: types.h:51
+ Here is the call graph for this function:

◆ mbtable_native_set()

static int mbtable_native_set ( const struct ConfigSet cs,
void *  var,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Set an MbTable config item by MbTable object - Implements ConfigSetType::native_set() -.

Definition at line 215 of file mbtable.c.

218{
219 int rc;
220
221 if (mbtable_equal(*(struct MbTable **) var, (struct MbTable *) value))
223
224 if (startup_only(cdef, err))
226
227 if (cdef->validator)
228 {
229 rc = cdef->validator(cs, cdef, value, err);
230
231 if (CSR_RESULT(rc) != CSR_SUCCESS)
232 return rc | CSR_INV_VALIDATOR;
233 }
234
235 mbtable_free(var);
236
237 struct MbTable *table = mbtable_dup((struct MbTable *) value);
238
239 rc = CSR_SUCCESS;
240 if (!table)
241 rc |= CSR_SUC_EMPTY;
242
243 *(struct MbTable **) var = table;
244 return rc;
245}
bool mbtable_equal(const struct MbTable *a, const struct MbTable *b)
Compare two MbTables.
Definition: mbtable.c:50
static struct MbTable * mbtable_dup(struct MbTable *table)
Create a copy of an MbTable object.
Definition: mbtable.c:202
void mbtable_free(struct MbTable **ptr)
Free an MbTable object.
Definition: mbtable.c:307
Multibyte character table.
Definition: mbtable.h:36
+ Here is the call graph for this function:

◆ myvar_native_set()

static int myvar_native_set ( const struct ConfigSet cs,
void *  var,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Set a MyVar config item by string - Implements ConfigSetType::native_set() -.

Definition at line 110 of file myvar.c.

112{
113 const char *str = (const char *) value;
114
115 /* Store empty myvars as NULL */
116 if (str && (str[0] == '\0'))
117 value = 0;
118
119 if (mutt_str_equal((const char *) value, (*(char **) var)))
121
122 int rc;
123
124 myvar_destroy(cs, var, cdef);
125
126 str = mutt_str_dup(str);
127 rc = CSR_SUCCESS;
128 if (!str)
129 rc |= CSR_SUC_EMPTY;
130
131 *(const char **) var = str;
132 return rc;
133}
static void myvar_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy a MyVar - Implements ConfigSetType::destroy() -.
Definition: myvar.c:41
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:251
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:763
+ Here is the call graph for this function:

◆ number_native_set()

static int number_native_set ( const struct ConfigSet cs,
void *  var,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Set a Number config item by int - Implements ConfigSetType::native_set() -.

Definition at line 118 of file number.c.

121{
122 if ((value < SHRT_MIN) || (value > SHRT_MAX))
123 {
124 buf_printf(err, _("Invalid number: %ld"), (long) value);
126 }
127
128 if ((value < 0) && (cdef->type & DT_NOT_NEGATIVE))
129 {
130 buf_printf(err, _("Option %s may not be negative"), cdef->name);
132 }
133
134 if (value == (*(short *) var))
136
137 if (cdef->validator)
138 {
139 int rc = cdef->validator(cs, cdef, value, err);
140
141 if (CSR_RESULT(rc) != CSR_SUCCESS)
142 return rc | CSR_INV_VALIDATOR;
143 }
144
145 if (startup_only(cdef, err))
147
148 *(short *) var = value;
149 return CSR_SUCCESS;
150}
+ Here is the call graph for this function:

◆ path_native_set()

static int path_native_set ( const struct ConfigSet cs,
void *  var,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Set a Path config item by string - Implements ConfigSetType::native_set() -.

Definition at line 161 of file path.c.

163{
164 const char *str = (const char *) value;
165
166 /* Store empty paths as NULL */
167 if (str && (str[0] == '\0'))
168 value = 0;
169
170 if ((value == 0) && (cdef->type & DT_NOT_EMPTY))
171 {
172 buf_printf(err, _("Option %s may not be empty"), cdef->name);
174 }
175
176 if (mutt_str_equal((const char *) value, (*(char **) var)))
178
179 int rc;
180
181 if (startup_only(cdef, err))
183
184 if (cdef->validator)
185 {
186 rc = cdef->validator(cs, cdef, value, err);
187
188 if (CSR_RESULT(rc) != CSR_SUCCESS)
189 return rc | CSR_INV_VALIDATOR;
190 }
191
192 path_destroy(cs, var, cdef);
193
194 str = path_tidy(str, cdef->type & DT_PATH_DIR);
195 rc = CSR_SUCCESS;
196 if (!str)
197 rc |= CSR_SUC_EMPTY;
198
199 *(const char **) var = str;
200 return rc;
201}
static char * path_tidy(const char *path, bool is_dir)
Tidy a path for storage.
Definition: path.c:55
static void path_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy a Path - Implements ConfigSetType::destroy() -.
Definition: path.c:75
#define DT_PATH_DIR
Path is a directory.
Definition: types.h:57
#define DT_NOT_EMPTY
Empty strings are not allowed.
Definition: types.h:50
+ Here is the call graph for this function:

◆ quad_native_set()

static int quad_native_set ( const struct ConfigSet cs,
void *  var,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Set a Quad-option config item by int - Implements ConfigSetType::native_set() -.

Definition at line 130 of file quad.c.

132{
133 if ((value < 0) || (value >= (mutt_array_size(QuadValues) - 1)))
134 {
135 buf_printf(err, _("Invalid quad value: %ld"), (long) value);
137 }
138
139 if (value == (*(char *) var))
141
142 if (startup_only(cdef, err))
144
145 if (cdef->validator)
146 {
147 int rc = cdef->validator(cs, cdef, value, err);
148
149 if (CSR_RESULT(rc) != CSR_SUCCESS)
150 return rc | CSR_INV_VALIDATOR;
151 }
152
153 *(char *) var = value;
154 return CSR_SUCCESS;
155}
#define mutt_array_size(x)
Definition: memory.h:38
const char * QuadValues[]
Valid strings for creating a QuadValue.
Definition: quad.c:49
+ Here is the call graph for this function:

◆ regex_native_set()

static int regex_native_set ( const struct ConfigSet cs,
void *  var,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Set a Regex config item by Regex object - Implements ConfigSetType::native_set() -.

Definition at line 226 of file regex.c.

228{
229 int rc;
230
231 if (regex_equal(*(struct Regex **) var, (struct Regex *) value))
233
234 if (startup_only(cdef, err))
236
237 if (cdef->validator)
238 {
239 rc = cdef->validator(cs, cdef, value, err);
240
241 if (CSR_RESULT(rc) != CSR_SUCCESS)
242 return rc | CSR_INV_VALIDATOR;
243 }
244
245 rc = CSR_SUCCESS;
246 struct Regex *orig = (struct Regex *) value;
247 struct Regex *r = NULL;
248
249 if (orig && orig->pattern)
250 {
251 const uint32_t flags = orig->pat_not ? DT_REGEX_ALLOW_NOT : 0;
252 r = regex_new(orig->pattern, flags, err);
253 if (!r)
254 rc = CSR_ERR_INVALID;
255 }
256 else
257 {
258 rc |= CSR_SUC_EMPTY;
259 }
260
261 if (CSR_RESULT(rc) == CSR_SUCCESS)
262 {
263 regex_free(var);
264 *(struct Regex **) var = r;
265 }
266
267 return rc;
268}
struct Regex * regex_new(const char *str, uint32_t flags, struct Buffer *err)
Create an Regex from a string.
Definition: regex.c:100
bool regex_equal(const struct Regex *a, const struct Regex *b)
Compare two regexes.
Definition: regex.c:50
void regex_free(struct Regex **ptr)
Free a Regex object.
Definition: regex.c:66
#define DT_REGEX_ALLOW_NOT
Regex can begin with '!'.
Definition: regex3.h:36
Cached regular expression.
Definition: regex3.h:89
char * pattern
printable version
Definition: regex3.h:90
bool pat_not
do not match
Definition: regex3.h:92
+ Here is the call graph for this function:

◆ slist_native_set()

static int slist_native_set ( const struct ConfigSet cs,
void *  var,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Set a Slist config item by Slist - Implements ConfigSetType::native_set() -.

Definition at line 153 of file slist.c.

155{
156 if (!cs || !var || !cdef)
157 return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
158
159 int rc;
160
161 if (slist_equal((struct Slist *) value, *(struct Slist **) var))
163
164 if (startup_only(cdef, err))
166
167 if (cdef->validator)
168 {
169 rc = cdef->validator(cs, cdef, value, err);
170
171 if (CSR_RESULT(rc) != CSR_SUCCESS)
172 return rc | CSR_INV_VALIDATOR;
173 }
174
175 slist_free(var);
176
177 struct Slist *list = slist_dup((struct Slist *) value);
178
179 rc = CSR_SUCCESS;
180 if (!list)
181 rc |= CSR_SUC_EMPTY;
182
183 *(struct Slist **) var = list;
184 return rc;
185}
void slist_free(struct Slist **ptr)
Free an Slist object.
Definition: slist.c:162
bool slist_equal(const struct Slist *a, const struct Slist *b)
Compare two string lists.
Definition: slist.c:103
struct Slist * slist_dup(const struct Slist *list)
Create a copy of an Slist object.
Definition: slist.c:120
String list.
Definition: slist.h:47
+ Here is the call graph for this function:

◆ sort_native_set()

static int sort_native_set ( const struct ConfigSet cs,
void *  var,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Set a Sort config item by int - Implements ConfigSetType::native_set() -.

Definition at line 155 of file sort.c.

157{
158 const char *str = NULL;
159
160 str = mutt_map_get_name((value & SORT_MASK), (struct Mapping *) cdef->data);
161
162 if (!str)
163 {
164 buf_printf(err, _("Invalid sort type: %ld"), (long) value);
166 }
167
168 if (value == (*(short *) var))
170
171 if (startup_only(cdef, err))
173
174 if (cdef->validator)
175 {
176 int rc = cdef->validator(cs, cdef, value, err);
177
178 if (CSR_RESULT(rc) != CSR_SUCCESS)
179 return rc | CSR_INV_VALIDATOR;
180 }
181
182 *(short *) var = value;
183 return CSR_SUCCESS;
184}
#define SORT_MASK
Mask for the sort id.
Definition: sort2.h:74
Mapping between user-readable string and a constant.
Definition: mapping.h:32
+ Here is the call graph for this function:

◆ string_native_set()

static int string_native_set ( const struct ConfigSet cs,
void *  var,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Set a String config item by string - Implements ConfigSetType::native_set() -.

Definition at line 131 of file string.c.

134{
135 const char *str = (const char *) value;
136
137 /* Store empty strings as NULL */
138 if (str && (str[0] == '\0'))
139 value = 0;
140
141 if ((value == 0) && (cdef->type & DT_NOT_EMPTY))
142 {
143 buf_printf(err, _("Option %s may not be empty"), cdef->name);
145 }
146
147 if (mutt_str_equal((const char *) value, (*(char **) var)))
149
150 int rc;
151
152 if (startup_only(cdef, err))
154
155 if (cdef->validator)
156 {
157 rc = cdef->validator(cs, cdef, value, err);
158
159 if (CSR_RESULT(rc) != CSR_SUCCESS)
160 return rc | CSR_INV_VALIDATOR;
161 }
162
163 string_destroy(cs, var, cdef);
164
165 str = mutt_str_dup(str);
166 rc = CSR_SUCCESS;
167 if (!str)
168 rc |= CSR_SUC_EMPTY;
169
170 *(const char **) var = str;
171 return rc;
172}
static void string_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy a String - Implements ConfigSetType::destroy() -.
Definition: string.c:45
+ Here is the call graph for this function: