NeoMutt  2019-12-07-60-g0cfa53
Teaching an old dog new tricks
DOXYGEN
set.c File Reference

A collection of config items. More...

#include "config.h"
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include "mutt/mutt.h"
#include "set.h"
#include "inheritance.h"
#include "types.h"
+ Include dependency graph for set.c:

Go to the source code of this file.

Functions

static void destroy (int type, void *obj, intptr_t data)
 Callback function for the Hash Table - Implements hashelem_free_t. More...
 
static struct HashElemcreate_synonym (const struct ConfigSet *cs, struct ConfigDef *cdef, struct Buffer *err)
 Create an alternative name for a config item. More...
 
static struct HashElemreg_one_var (const struct ConfigSet *cs, struct ConfigDef *cdef, struct Buffer *err)
 Register one config item. More...
 
struct ConfigSetcs_new (size_t size)
 Create a new Config Set. More...
 
void cs_free (struct ConfigSet **ptr)
 Free a Config Set. More...
 
struct HashElemcs_get_base (struct HashElem *he)
 Find the root Config Item. More...
 
struct HashElemcs_get_elem (const struct ConfigSet *cs, const char *name)
 Get the HashElem representing a config item. More...
 
const struct ConfigSetTypecs_get_type_def (const struct ConfigSet *cs, unsigned int type)
 Get the definition for a type. More...
 
bool cs_register_type (struct ConfigSet *cs, unsigned int type, const struct ConfigSetType *cst)
 Register a type of config item. More...
 
bool cs_register_variables (const struct ConfigSet *cs, struct ConfigDef vars[], int flags)
 Register a set of config items. More...
 
struct HashElemcs_inherit_variable (const struct ConfigSet *cs, struct HashElem *parent, const char *name)
 Create in inherited config item. More...
 
void cs_uninherit_variable (const struct ConfigSet *cs, const char *name)
 Remove an inherited config item. More...
 
int cs_he_reset (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err)
 Reset a config item to its initial value. More...
 
int cs_str_reset (const struct ConfigSet *cs, const char *name, struct Buffer *err)
 Reset a config item to its initial value. More...
 
int cs_he_initial_set (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err)
 Set the initial value of a config item. More...
 
int cs_str_initial_set (const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err)
 Set the initial value of a config item. More...
 
int cs_he_initial_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result)
 Get the initial, or parent, value of a config item. More...
 
int cs_str_initial_get (const struct ConfigSet *cs, const char *name, struct Buffer *result)
 Get the initial, or parent, value of a config item. More...
 
int cs_he_string_set (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err)
 Set a config item by string. More...
 
int cs_str_string_set (const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err)
 Set a config item by string. More...
 
int cs_he_string_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result)
 Get a config item as a string. More...
 
int cs_str_string_get (const struct ConfigSet *cs, const char *name, struct Buffer *result)
 Get a config item as a string. More...
 
int cs_he_native_set (const struct ConfigSet *cs, struct HashElem *he, intptr_t value, struct Buffer *err)
 Natively set the value of a HashElem config item. More...
 
int cs_str_native_set (const struct ConfigSet *cs, const char *name, intptr_t value, struct Buffer *err)
 Natively set the value of a string config item. More...
 
intptr_t cs_he_native_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err)
 Natively get the value of a HashElem config item. More...
 
intptr_t cs_str_native_get (const struct ConfigSet *cs, const char *name, struct Buffer *err)
 Natively get the value of a string config item. More...
 

Variables

struct ConfigSetType RegisteredTypes [18]
 

Detailed Description

A collection of config items.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file set.c.

Function Documentation

◆ destroy()

static void destroy ( int  type,
void *  obj,
intptr_t  data 
)
static

Callback function for the Hash Table - Implements hashelem_free_t.

Parameters
typeObject type, e.g. DT_STRING
objObject to destroy
dataConfigSet associated with the object

Definition at line 48 of file set.c.

49 {
50  if (!obj || (data == 0))
51  return; /* LCOV_EXCL_LINE */
52 
53  struct ConfigSet *cs = (struct ConfigSet *) data;
54 
55  const struct ConfigSetType *cst = NULL;
56 
57  if (type & DT_INHERITED)
58  {
59  struct Inheritance *i = obj;
60 
61  struct HashElem *he_base = cs_get_base(i->parent);
62  struct ConfigDef *cdef = he_base->data;
63 
64  cst = cs_get_type_def(cs, he_base->type);
65  if (cst && cst->destroy)
66  cst->destroy(cs, (void **) &i->var, cdef);
67 
68  FREE(&i->name);
69  FREE(&i);
70  }
71  else
72  {
73  struct ConfigDef *cdef = obj;
74 
75  cst = cs_get_type_def(cs, type);
76  if (cst && cst->destroy)
77  cst->destroy(cs, cdef->var, cdef);
78 
79  /* If we allocated the initial value, clean it up */
80  if (cdef->type & DT_INITIAL_SET)
81  FREE(&cdef->initial);
82  }
83 }
Type definition for a config item.
Definition: set.h:149
Container for lots of config items.
Definition: set.h:168
intptr_t initial
Initial value.
Definition: set.h:139
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:187
#define DT_INITIAL_SET
Config item must have its initial value freed.
Definition: types.h:79
const char * name
Name of this config item.
Definition: inheritance.h:34
Config item definition.
Definition: set.h:134
An inherited config item.
Definition: inheritance.h:31
cst_destroy destroy
Free the resources for a variable.
Definition: set.h:157
void * data
Definition: hash.h:46
void * var
Pointer to the global variable.
Definition: set.h:138
unsigned int type
Variable type, e.g. DT_STRING.
Definition: set.h:137
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:225
int type
Definition: hash.h:44
#define FREE(x)
Definition: memory.h:40
The item stored in a Hash Table.
Definition: hash.h:42
struct HashElem * parent
HashElem of parent config item.
Definition: inheritance.h:33
#define DT_INHERITED
Config item is inherited.
Definition: types.h:78
intptr_t var
(Pointer to) value, of config item
Definition: inheritance.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ create_synonym()

static struct HashElem* create_synonym ( const struct ConfigSet cs,
struct ConfigDef cdef,
struct Buffer err 
)
static

Create an alternative name for a config item.

Parameters
csConfig items
cdefVariable definition
errBuffer for error messages
Return values
ptrNew HashElem representing the config item synonym

Definition at line 92 of file set.c.

94 {
95  if (!cs || !cdef)
96  return NULL; /* LCOV_EXCL_LINE */
97 
98  const char *name = (const char *) cdef->initial;
99  struct HashElem *parent = cs_get_elem(cs, name);
100  if (!parent)
101  {
102  mutt_buffer_printf(err, "No such variable: %s", name);
103  return NULL;
104  }
105 
106  struct HashElem *child =
107  mutt_hash_typed_insert(cs->hash, cdef->name, cdef->type, (void *) cdef);
108  if (!child)
109  return NULL; /* LCOV_EXCL_LINE */
110 
111  cdef->var = parent;
112  return child;
113 }
struct Hash * hash
HashTable storing the config items.
Definition: set.h:170
intptr_t initial
Initial value.
Definition: set.h:139
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
const char * name
Definition: pgpmicalg.c:46
const char * name
User-visible name.
Definition: set.h:136
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:202
void * var
Pointer to the global variable.
Definition: set.h:138
unsigned int type
Variable type, e.g. DT_STRING.
Definition: set.h:137
The item stored in a Hash Table.
Definition: hash.h:42
struct HashElem * mutt_hash_typed_insert(struct Hash *table, const char *strkey, int type, void *data)
Insert a string with type info into a Hash Table.
Definition: hash.c:333
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reg_one_var()

static struct HashElem* reg_one_var ( const struct ConfigSet cs,
struct ConfigDef cdef,
struct Buffer err 
)
static

Register one config item.

Parameters
csConfig items
cdefVariable definition
errBuffer for error messages
Return values
ptrNew HashElem representing the config item

Definition at line 122 of file set.c.

124 {
125  if (!cs || !cdef)
126  return NULL; /* LCOV_EXCL_LINE */
127 
128  if (cdef->type == DT_SYNONYM)
129  return create_synonym(cs, cdef, err);
130 
131  const struct ConfigSetType *cst = cs_get_type_def(cs, cdef->type);
132  if (!cst)
133  {
134  mutt_buffer_printf(err, "Variable '%s' has an invalid type %d", cdef->name, cdef->type);
135  return NULL;
136  }
137 
138  struct HashElem *he =
139  mutt_hash_typed_insert(cs->hash, cdef->name, cdef->type, (void *) cdef);
140  if (!he)
141  return NULL; /* LCOV_EXCL_LINE */
142 
143  if (cst && cst->reset)
144  cst->reset(cs, cdef->var, cdef, err);
145 
146  return he;
147 }
Type definition for a config item.
Definition: set.h:149
struct Hash * hash
HashTable storing the config items.
Definition: set.h:170
cst_reset reset
Reset the variable to its initial, or parent, value.
Definition: set.h:156
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
static struct HashElem * create_synonym(const struct ConfigSet *cs, struct ConfigDef *cdef, struct Buffer *err)
Create an alternative name for a config item.
Definition: set.c:92
const char * name
User-visible name.
Definition: set.h:136
void * var
Pointer to the global variable.
Definition: set.h:138
unsigned int type
Variable type, e.g. DT_STRING.
Definition: set.h:137
#define DT_SYNONYM
synonym for another variable
Definition: types.h:41
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:225
The item stored in a Hash Table.
Definition: hash.h:42
struct HashElem * mutt_hash_typed_insert(struct Hash *table, const char *strkey, int type, void *data)
Insert a string with type info into a Hash Table.
Definition: hash.c:333
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_new()

struct ConfigSet* cs_new ( size_t  size)

Create a new Config Set.

Parameters
sizeNumber of expected config items
Return values
ptrNew ConfigSet object

Definition at line 154 of file set.c.

155 {
156  struct ConfigSet *cs = mutt_mem_calloc(1, sizeof(*cs));
157 
159  mutt_hash_set_destructor(cs->hash, destroy, (intptr_t) cs);
160 
161  return cs;
162 }
Container for lots of config items.
Definition: set.h:168
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
struct Hash * hash
HashTable storing the config items.
Definition: set.h:170
static void destroy(int type, void *obj, intptr_t data)
Callback function for the Hash Table - Implements hashelem_free_t.
Definition: set.c:48
struct Hash * mutt_hash_new(size_t nelem, HashFlags flags)
Create a new Hash table (with string keys)
Definition: hash.c:275
void mutt_hash_set_destructor(struct Hash *table, hashelem_free_t fn, intptr_t fn_data)
Set the destructor for a Hash Table.
Definition: hash.c:317
#define MUTT_HASH_NO_FLAGS
No flags are set.
Definition: hash.h:74
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_free()

void cs_free ( struct ConfigSet **  ptr)

Free a Config Set.

Parameters
[out]ptrConfig items

Definition at line 168 of file set.c.

169 {
170  if (!ptr || !*ptr)
171  return;
172 
173  struct ConfigSet *cs = *ptr;
174 
175  mutt_hash_free(&cs->hash);
176  FREE(ptr);
177 }
Container for lots of config items.
Definition: set.h:168
struct Hash * hash
HashTable storing the config items.
Definition: set.h:170
#define FREE(x)
Definition: memory.h:40
void mutt_hash_free(struct Hash **ptr)
Free a hash table.
Definition: hash.c:471
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_get_base()

struct HashElem* cs_get_base ( struct HashElem he)

Find the root Config Item.

Parameters
heConfig Item to examine
Return values
ptrRoot Config Item

Given an inherited HashElem, find the HashElem representing the original Config Item.

Definition at line 187 of file set.c.

188 {
189  if (!(he->type & DT_INHERITED))
190  return he;
191 
192  struct Inheritance *i = he->data;
193  return cs_get_base(i->parent);
194 }
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:187
An inherited config item.
Definition: inheritance.h:31
void * data
Definition: hash.h:46
int type
Definition: hash.h:44
struct HashElem * parent
HashElem of parent config item.
Definition: inheritance.h:33
#define DT_INHERITED
Config item is inherited.
Definition: types.h:78
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_get_elem()

struct HashElem* cs_get_elem ( const struct ConfigSet cs,
const char *  name 
)

Get the HashElem representing a config item.

Parameters
csConfig items
nameName of config item
Return values
ptrHashElem representing the config item

Definition at line 202 of file set.c.

203 {
204  if (!cs || !name)
205  return NULL;
206 
207  struct HashElem *he = mutt_hash_find_elem(cs->hash, name);
208  if (!he)
209  return NULL;
210 
211  if (he->type != DT_SYNONYM)
212  return he;
213 
214  const struct ConfigDef *cdef = he->data;
215 
216  return cdef->var;
217 }
struct Hash * hash
HashTable storing the config items.
Definition: set.h:170
Config item definition.
Definition: set.h:134
const char * name
Definition: pgpmicalg.c:46
struct HashElem * mutt_hash_find_elem(const struct Hash *table, const char *strkey)
Find the HashElem in a Hash table element using a key.
Definition: hash.c:393
void * data
Definition: hash.h:46
void * var
Pointer to the global variable.
Definition: set.h:138
#define DT_SYNONYM
synonym for another variable
Definition: types.h:41
int type
Definition: hash.h:44
The item stored in a Hash Table.
Definition: hash.h:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_get_type_def()

const struct ConfigSetType* cs_get_type_def ( const struct ConfigSet cs,
unsigned int  type 
)

Get the definition for a type.

Parameters
csConfig items
typeType to lookup, e.g. DT_NUMBER
Return values
ptrConfigSetType representing the type

Definition at line 225 of file set.c.

226 {
227  if (!cs)
228  return NULL;
229 
230  type = DTYPE(type);
231  if ((type < 1) || (type >= mutt_array_size(cs->types)))
232  return NULL;
233 
234  if (!cs->types[type].name)
235  return NULL;
236 
237  return &cs->types[type];
238 }
struct ConfigSetType types[18]
All the defined config types.
Definition: set.h:171
#define DTYPE(x)
Mask for the Data Type.
Definition: types.h:43
#define mutt_array_size(x)
Definition: memory.h:33
unsigned int type
Variable type, e.g. DT_STRING.
Definition: set.h:137
const char * name
Name of the type, e.g. "String".
Definition: set.h:151
+ Here is the caller graph for this function:

◆ cs_register_type()

bool cs_register_type ( struct ConfigSet cs,
unsigned int  type,
const struct ConfigSetType cst 
)

Register a type of config item.

Parameters
csConfig items
typeObject type, e.g. DT_BOOL
cstStructure defining the type
Return values
boolTrue, if type was registered successfully

Definition at line 247 of file set.c.

248 {
249  if (!cs || !cst)
250  return false;
251 
252  if (!cst->name || !cst->string_set || !cst->string_get || !cst->reset ||
253  !cst->native_set || !cst->native_get)
254  {
255  return false;
256  }
257 
258  if (type >= mutt_array_size(cs->types))
259  return false;
260 
261  if (cs->types[type].name)
262  return false; /* already registered */
263 
264  cs->types[type] = *cst;
265  return true;
266 }
cst_reset reset
Reset the variable to its initial, or parent, value.
Definition: set.h:156
struct ConfigSetType types[18]
All the defined config types.
Definition: set.h:171
cst_string_get string_get
Initialise a variable from a string.
Definition: set.h:153
#define mutt_array_size(x)
Definition: memory.h:33
cst_native_get native_get
Get the variable&#39;s value as a C-native type.
Definition: set.h:155
cst_string_set string_set
Convert the variable to a string.
Definition: set.h:152
cst_native_set native_set
Set the variable using a C-native type.
Definition: set.h:154
unsigned int type
Variable type, e.g. DT_STRING.
Definition: set.h:137
const char * name
Name of the type, e.g. "String".
Definition: set.h:151
+ Here is the caller graph for this function:

◆ cs_register_variables()

bool cs_register_variables ( const struct ConfigSet cs,
struct ConfigDef  vars[],
int  flags 
)

Register a set of config items.

Parameters
csConfig items
varsVariable definition
flagsFlags, e.g. CS_REG_DISABLED
Return values
boolTrue, if all variables were registered successfully

Definition at line 275 of file set.c.

276 {
277  if (!cs || !vars)
278  return false;
279 
280  struct Buffer err = mutt_buffer_make(0);
281 
282  bool rc = true;
283 
284  for (size_t i = 0; vars[i].name; i++)
285  {
286  if (!reg_one_var(cs, &vars[i], &err))
287  {
288  mutt_debug(LL_DEBUG1, "%s\n", mutt_b2s(&err));
289  rc = false;
290  }
291  }
292 
293  mutt_buffer_dealloc(&err);
294  return rc;
295 }
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:61
String manipulation buffer.
Definition: buffer.h:33
static struct HashElem * reg_one_var(const struct ConfigSet *cs, struct ConfigDef *cdef, struct Buffer *err)
Register one config item.
Definition: set.c:122
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:294
const char * name
User-visible name.
Definition: set.h:136
#define mutt_b2s(buf)
Definition: buffer.h:41
Log at debug level 1.
Definition: logging.h:40
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_inherit_variable()

struct HashElem* cs_inherit_variable ( const struct ConfigSet cs,
struct HashElem parent,
const char *  name 
)

Create in inherited config item.

Parameters
csConfig items
parentHashElem of parent config item
nameName of account-specific config item
Return values
ptrNew HashElem representing the inherited config item

Definition at line 304 of file set.c.

306 {
307  if (!cs || !parent)
308  return NULL;
309 
310  struct Inheritance *i = mutt_mem_calloc(1, sizeof(*i));
311  i->parent = parent;
312  i->name = mutt_str_strdup(name);
313 
314  struct HashElem *he = mutt_hash_typed_insert(cs->hash, i->name, DT_INHERITED, i);
315  if (!he)
316  {
317  FREE(&i->name);
318  FREE(&i);
319  }
320 
321  return he;
322 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
struct Hash * hash
HashTable storing the config items.
Definition: set.h:170
const char * name
Name of this config item.
Definition: inheritance.h:34
An inherited config item.
Definition: inheritance.h:31
const char * name
Definition: pgpmicalg.c:46
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
#define FREE(x)
Definition: memory.h:40
The item stored in a Hash Table.
Definition: hash.h:42
struct HashElem * parent
HashElem of parent config item.
Definition: inheritance.h:33
#define DT_INHERITED
Config item is inherited.
Definition: types.h:78
struct HashElem * mutt_hash_typed_insert(struct Hash *table, const char *strkey, int type, void *data)
Insert a string with type info into a Hash Table.
Definition: hash.c:333
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_uninherit_variable()

void cs_uninherit_variable ( const struct ConfigSet cs,
const char *  name 
)

Remove an inherited config item.

Parameters
csConfig items
nameName of config item to remove

Definition at line 329 of file set.c.

330 {
331  if (!cs || !name)
332  return;
333 
334  mutt_hash_delete(cs->hash, name, NULL);
335 }
void mutt_hash_delete(struct Hash *table, const char *strkey, const void *data)
Remove an element from a Hash table.
Definition: hash.c:443
struct Hash * hash
HashTable storing the config items.
Definition: set.h:170
const char * name
Definition: pgpmicalg.c:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_he_reset()

int cs_he_reset ( const struct ConfigSet cs,
struct HashElem he,
struct Buffer err 
)

Reset a config item to its initial value.

Parameters
csConfig items
heHashElem representing config item
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 344 of file set.c.

345 {
346  if (!cs || !he)
347  return CSR_ERR_CODE;
348 
349  /* An inherited var that's already pointing to its parent.
350  * Return 'success', but don't send a notification. */
351  if ((he->type & DT_INHERITED) && (DTYPE(he->type) == 0))
352  return CSR_SUCCESS;
353 
354  const struct ConfigDef *cdef = NULL;
355  const struct ConfigSetType *cst = NULL;
356 
357  int rc = CSR_SUCCESS;
358 
359  if (he->type & DT_INHERITED)
360  {
361  struct Inheritance *i = he->data;
362  struct HashElem *he_base = cs_get_base(he);
363  cdef = he_base->data;
364  cst = cs_get_type_def(cs, he_base->type);
365 
366  if (cst && cst->destroy)
367  cst->destroy(cs, (void **) &i->var, cdef);
368 
369  he->type = DT_INHERITED;
370  }
371  else
372  {
373  cdef = he->data;
374  cst = cs_get_type_def(cs, he->type);
375 
376  if (cst)
377  rc = cst->reset(cs, cdef->var, cdef, err);
378  }
379 
380  return rc;
381 }
Type definition for a config item.
Definition: set.h:149
cst_reset reset
Reset the variable to its initial, or parent, value.
Definition: set.h:156
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:187
Config item definition.
Definition: set.h:134
#define DTYPE(x)
Mask for the Data Type.
Definition: types.h:43
An inherited config item.
Definition: inheritance.h:31
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:37
cst_destroy destroy
Free the resources for a variable.
Definition: set.h:157
void * data
Definition: hash.h:46
void * var
Pointer to the global variable.
Definition: set.h:138
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:38
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:225
int type
Definition: hash.h:44
The item stored in a Hash Table.
Definition: hash.h:42
#define DT_INHERITED
Config item is inherited.
Definition: types.h:78
intptr_t var
(Pointer to) value, of config item
Definition: inheritance.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_str_reset()

int cs_str_reset ( const struct ConfigSet cs,
const char *  name,
struct Buffer err 
)

Reset a config item to its initial value.

Parameters
csConfig items
nameName of config item
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 390 of file set.c.

391 {
392  if (!cs || !name)
393  return CSR_ERR_CODE;
394 
395  struct HashElem *he = cs_get_elem(cs, name);
396  if (!he)
397  {
398  mutt_buffer_printf(err, "Unknown var '%s'", name);
399  return CSR_ERR_UNKNOWN;
400  }
401 
402  return cs_he_reset(cs, he, err);
403 }
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
const char * name
Definition: pgpmicalg.c:46
int cs_he_reset(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err)
Reset a config item to its initial value.
Definition: set.c:344
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:202
#define CSR_ERR_UNKNOWN
Unrecognised config item.
Definition: set.h:39
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:38
The item stored in a Hash Table.
Definition: hash.h:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_he_initial_set()

int cs_he_initial_set ( const struct ConfigSet cs,
struct HashElem he,
const char *  value,
struct Buffer err 
)

Set the initial value of a config item.

Parameters
csConfig items
heHashElem representing config item
valueValue to set
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 413 of file set.c.

415 {
416  if (!cs || !he)
417  return CSR_ERR_CODE;
418 
419  struct ConfigDef *cdef = NULL;
420  const struct ConfigSetType *cst = NULL;
421 
422  if (he->type & DT_INHERITED)
423  {
424  struct HashElem *he_base = cs_get_base(he);
425  cdef = he_base->data;
426  mutt_debug(LL_DEBUG1, "Variable '%s' is inherited type\n", cdef->name);
427  return CSR_ERR_CODE;
428  }
429 
430  cdef = he->data;
431  cst = cs_get_type_def(cs, he->type);
432  if (!cst)
433  {
434  mutt_debug(LL_DEBUG1, "Variable '%s' has an invalid type %d\n", cdef->name, he->type);
435  return CSR_ERR_CODE;
436  }
437 
438  int rc = cst->string_set(cs, NULL, cdef, value, err);
439  if (CSR_RESULT(rc) != CSR_SUCCESS)
440  return rc;
441 
442  return CSR_SUCCESS;
443 }
Type definition for a config item.
Definition: set.h:149
#define CSR_RESULT(x)
Definition: set.h:53
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:187
Config item definition.
Definition: set.h:134
const char * name
User-visible name.
Definition: set.h:136
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:37
cst_string_set string_set
Convert the variable to a string.
Definition: set.h:152
void * data
Definition: hash.h:46
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:38
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:225
Log at debug level 1.
Definition: logging.h:40
int type
Definition: hash.h:44
The item stored in a Hash Table.
Definition: hash.h:42
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
#define DT_INHERITED
Config item is inherited.
Definition: types.h:78
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_str_initial_set()

int cs_str_initial_set ( const struct ConfigSet cs,
const char *  name,
const char *  value,
struct Buffer err 
)

Set the initial value of a config item.

Parameters
csConfig items
nameName of config item
valueValue to set
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 453 of file set.c.

455 {
456  if (!cs || !name)
457  return CSR_ERR_CODE;
458 
459  struct HashElem *he = cs_get_elem(cs, name);
460  if (!he)
461  {
462  mutt_buffer_printf(err, "Unknown var '%s'", name);
463  return CSR_ERR_UNKNOWN;
464  }
465 
466  return cs_he_initial_set(cs, he, value, err);
467 }
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
const char * name
Definition: pgpmicalg.c:46
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:202
#define CSR_ERR_UNKNOWN
Unrecognised config item.
Definition: set.h:39
int cs_he_initial_set(const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err)
Set the initial value of a config item.
Definition: set.c:413
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:38
The item stored in a Hash Table.
Definition: hash.h:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_he_initial_get()

int cs_he_initial_get ( const struct ConfigSet cs,
struct HashElem he,
struct Buffer result 
)

Get the initial, or parent, value of a config item.

Parameters
csConfig items
heHashElem representing config item
resultBuffer for results or error messages
Return values
numResult, e.g. CSR_SUCCESS

If a config item is inherited from another, then this will get the parent's value. Otherwise, it will get the config item's initial value.

Definition at line 479 of file set.c.

480 {
481  if (!cs || !he)
482  return CSR_ERR_CODE;
483 
484  const struct ConfigDef *cdef = NULL;
485  const struct ConfigSetType *cst = NULL;
486 
487  if (he->type & DT_INHERITED)
488  {
489  struct HashElem *he_base = cs_get_base(he);
490  cdef = he_base->data;
491  cst = cs_get_type_def(cs, he_base->type);
492  }
493  else
494  {
495  cdef = he->data;
496  cst = cs_get_type_def(cs, he->type);
497  }
498 
499  if (!cst)
500  {
501  mutt_debug(LL_DEBUG1, "Variable '%s' has an invalid type %d\n", cdef->name,
502  DTYPE(he->type));
503  return CSR_ERR_CODE;
504  }
505 
506  return cst->string_get(cs, NULL, cdef, result);
507 }
Type definition for a config item.
Definition: set.h:149
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:187
cst_string_get string_get
Initialise a variable from a string.
Definition: set.h:153
Config item definition.
Definition: set.h:134
#define DTYPE(x)
Mask for the Data Type.
Definition: types.h:43
const char * name
User-visible name.
Definition: set.h:136
void * data
Definition: hash.h:46
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:38
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:225
Log at debug level 1.
Definition: logging.h:40
int type
Definition: hash.h:44
The item stored in a Hash Table.
Definition: hash.h:42
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
#define DT_INHERITED
Config item is inherited.
Definition: types.h:78
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_str_initial_get()

int cs_str_initial_get ( const struct ConfigSet cs,
const char *  name,
struct Buffer result 
)

Get the initial, or parent, value of a config item.

Parameters
csConfig items
nameName of config item
resultBuffer for results or error messages
Return values
numResult, e.g. CSR_SUCCESS

If a config item is inherited from another, then this will get the parent's value. Otherwise, it will get the config item's initial value.

Definition at line 519 of file set.c.

520 {
521  if (!cs || !name)
522  return CSR_ERR_CODE;
523 
524  struct HashElem *he = cs_get_elem(cs, name);
525  if (!he)
526  {
527  mutt_buffer_printf(result, "Unknown var '%s'", name);
528  return CSR_ERR_UNKNOWN;
529  }
530 
531  return cs_he_initial_get(cs, he, result);
532 }
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
const char * name
Definition: pgpmicalg.c:46
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:202
#define CSR_ERR_UNKNOWN
Unrecognised config item.
Definition: set.h:39
int cs_he_initial_get(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result)
Get the initial, or parent, value of a config item.
Definition: set.c:479
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:38
The item stored in a Hash Table.
Definition: hash.h:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_he_string_set()

int cs_he_string_set ( const struct ConfigSet cs,
struct HashElem he,
const char *  value,
struct Buffer err 
)

Set a config item by string.

Parameters
csConfig items
heHashElem representing config item
valueValue to set
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 542 of file set.c.

544 {
545  if (!cs || !he)
546  return CSR_ERR_CODE;
547 
548  struct ConfigDef *cdef = NULL;
549  const struct ConfigSetType *cst = NULL;
550  void *var = NULL;
551 
552  if (he->type & DT_INHERITED)
553  {
554  struct Inheritance *i = he->data;
555  struct HashElem *he_base = cs_get_base(he);
556  cdef = he_base->data;
557  cst = cs_get_type_def(cs, he_base->type);
558  var = &i->var;
559  }
560  else
561  {
562  cdef = he->data;
563  cst = cs_get_type_def(cs, he->type);
564  var = cdef->var;
565  }
566 
567  if (!cst)
568  {
569  mutt_debug(LL_DEBUG1, "Variable '%s' has an invalid type %d\n", cdef->name, he->type);
570  return CSR_ERR_CODE;
571  }
572 
573  int rc = cst->string_set(cs, var, cdef, value, err);
574  if (CSR_RESULT(rc) != CSR_SUCCESS)
575  return rc;
576 
577  if (he->type & DT_INHERITED)
578  he->type = cdef->type | DT_INHERITED;
579 
580  return rc;
581 }
Type definition for a config item.
Definition: set.h:149
#define CSR_RESULT(x)
Definition: set.h:53
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:187
Config item definition.
Definition: set.h:134
An inherited config item.
Definition: inheritance.h:31
const char * name
User-visible name.
Definition: set.h:136
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:37
cst_string_set string_set
Convert the variable to a string.
Definition: set.h:152
void * data
Definition: hash.h:46
void * var
Pointer to the global variable.
Definition: set.h:138
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:38
unsigned int type
Variable type, e.g. DT_STRING.
Definition: set.h:137
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:225
Log at debug level 1.
Definition: logging.h:40
int type
Definition: hash.h:44
The item stored in a Hash Table.
Definition: hash.h:42
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
#define DT_INHERITED
Config item is inherited.
Definition: types.h:78
intptr_t var
(Pointer to) value, of config item
Definition: inheritance.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_str_string_set()

int cs_str_string_set ( const struct ConfigSet cs,
const char *  name,
const char *  value,
struct Buffer err 
)

Set a config item by string.

Parameters
csConfig items
nameName of config item
valueValue to set
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 591 of file set.c.

593 {
594  if (!cs || !name)
595  return CSR_ERR_CODE;
596 
597  struct HashElem *he = cs_get_elem(cs, name);
598  if (!he)
599  {
600  mutt_buffer_printf(err, "Unknown var '%s'", name);
601  return CSR_ERR_UNKNOWN;
602  }
603 
604  return cs_he_string_set(cs, he, value, err);
605 }
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
const char * name
Definition: pgpmicalg.c:46
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:202
#define CSR_ERR_UNKNOWN
Unrecognised config item.
Definition: set.h:39
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:38
The item stored in a Hash Table.
Definition: hash.h:42
int cs_he_string_set(const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err)
Set a config item by string.
Definition: set.c:542
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_he_string_get()

int cs_he_string_get ( const struct ConfigSet cs,
struct HashElem he,
struct Buffer result 
)

Get a config item as a string.

Parameters
csConfig items
heHashElem representing config item
resultBuffer for results or error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 614 of file set.c.

615 {
616  if (!cs || !he)
617  return CSR_ERR_CODE;
618 
619  const struct ConfigDef *cdef = NULL;
620  const struct ConfigSetType *cst = NULL;
621  void *var = NULL;
622 
623  if (he->type & DT_INHERITED)
624  {
625  struct Inheritance *i = he->data;
626 
627  // inherited, value not set
628  if (DTYPE(he->type) == 0)
629  return cs_he_string_get(cs, i->parent, result);
630 
631  // inherited, value set
632  struct HashElem *he_base = cs_get_base(he);
633  cdef = he_base->data;
634  cst = cs_get_type_def(cs, he_base->type);
635  var = &i->var;
636  }
637  else
638  {
639  // not inherited
640  cdef = he->data;
641  cst = cs_get_type_def(cs, he->type);
642  var = cdef->var;
643  }
644 
645  if (!cst)
646  {
647  mutt_debug(LL_DEBUG1, "Variable '%s' has an invalid type %d\n", cdef->name,
648  DTYPE(he->type));
649  return CSR_ERR_CODE;
650  }
651 
652  return cst->string_get(cs, var, cdef, result);
653 }
Type definition for a config item.
Definition: set.h:149
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:187
cst_string_get string_get
Initialise a variable from a string.
Definition: set.h:153
Config item definition.
Definition: set.h:134
#define DTYPE(x)
Mask for the Data Type.
Definition: types.h:43
An inherited config item.
Definition: inheritance.h:31
const char * name
User-visible name.
Definition: set.h:136
int cs_he_string_get(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result)
Get a config item as a string.
Definition: set.c:614
void * data
Definition: hash.h:46
void * var
Pointer to the global variable.
Definition: set.h:138
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:38
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:225
Log at debug level 1.
Definition: logging.h:40
int type
Definition: hash.h:44
The item stored in a Hash Table.
Definition: hash.h:42
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
struct HashElem * parent
HashElem of parent config item.
Definition: inheritance.h:33
#define DT_INHERITED
Config item is inherited.
Definition: types.h:78
intptr_t var
(Pointer to) value, of config item
Definition: inheritance.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_str_string_get()

int cs_str_string_get ( const struct ConfigSet cs,
const char *  name,
struct Buffer result 
)

Get a config item as a string.

Parameters
csConfig items
nameName of config item
resultBuffer for results or error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 662 of file set.c.

663 {
664  if (!cs || !name)
665  return CSR_ERR_CODE;
666 
667  struct HashElem *he = cs_get_elem(cs, name);
668  if (!he)
669  {
670  mutt_buffer_printf(result, "Unknown var '%s'", name);
671  return CSR_ERR_UNKNOWN;
672  }
673 
674  return cs_he_string_get(cs, he, result);
675 }
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
const char * name
Definition: pgpmicalg.c:46
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:202
#define CSR_ERR_UNKNOWN
Unrecognised config item.
Definition: set.h:39
int cs_he_string_get(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result)
Get a config item as a string.
Definition: set.c:614
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:38
The item stored in a Hash Table.
Definition: hash.h:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_he_native_set()

int cs_he_native_set ( const struct ConfigSet cs,
struct HashElem he,
intptr_t  value,
struct Buffer err 
)

Natively set the value of a HashElem config item.

Parameters
csConfig items
heHashElem representing config item
valueNative pointer/value to set
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 685 of file set.c.

687 {
688  if (!cs || !he)
689  return CSR_ERR_CODE;
690 
691  const struct ConfigDef *cdef = NULL;
692  const struct ConfigSetType *cst = NULL;
693  void *var = NULL;
694 
695  if (he->type & DT_INHERITED)
696  {
697  struct Inheritance *i = he->data;
698  struct HashElem *he_base = cs_get_base(he);
699  cdef = he_base->data;
700  cst = cs_get_type_def(cs, he_base->type);
701  var = &i->var;
702  }
703  else
704  {
705  cdef = he->data;
706  cst = cs_get_type_def(cs, he->type);
707  var = cdef->var;
708  }
709 
710  if (!cst)
711  {
712  mutt_debug(LL_DEBUG1, "Variable '%s' has an invalid type %d\n", cdef->name, he->type);
713  return CSR_ERR_CODE;
714  }
715 
716  int rc = cst->native_set(cs, var, cdef, value, err);
717  if (CSR_RESULT(rc) != CSR_SUCCESS)
718  return rc;
719 
720  if (he->type & DT_INHERITED)
721  he->type = cdef->type | DT_INHERITED;
722 
723  return rc;
724 }
Type definition for a config item.
Definition: set.h:149
#define CSR_RESULT(x)
Definition: set.h:53
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:187
Config item definition.
Definition: set.h:134
An inherited config item.
Definition: inheritance.h:31
const char * name
User-visible name.
Definition: set.h:136
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:37
cst_native_set native_set
Set the variable using a C-native type.
Definition: set.h:154
void * data
Definition: hash.h:46
void * var
Pointer to the global variable.
Definition: set.h:138
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:38
unsigned int type
Variable type, e.g. DT_STRING.
Definition: set.h:137
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:225
Log at debug level 1.
Definition: logging.h:40
int type
Definition: hash.h:44
The item stored in a Hash Table.
Definition: hash.h:42
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
#define DT_INHERITED
Config item is inherited.
Definition: types.h:78
intptr_t var
(Pointer to) value, of config item
Definition: inheritance.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_str_native_set()

int cs_str_native_set ( const struct ConfigSet cs,
const char *  name,
intptr_t  value,
struct Buffer err 
)

Natively set the value of a string config item.

Parameters
csConfig items
nameName of config item
valueNative pointer/value to set
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 734 of file set.c.

736 {
737  if (!cs || !name)
738  return CSR_ERR_CODE;
739 
740  struct HashElem *he = cs_get_elem(cs, name);
741  if (!he)
742  {
743  mutt_buffer_printf(err, "Unknown var '%s'", name);
744  return CSR_ERR_UNKNOWN;
745  }
746 
747  const struct ConfigDef *cdef = NULL;
748  const struct ConfigSetType *cst = NULL;
749  void *var = NULL;
750 
751  if (he->type & DT_INHERITED)
752  {
753  struct Inheritance *i = he->data;
754  struct HashElem *he_base = cs_get_base(he);
755  cdef = he_base->data;
756  cst = cs_get_type_def(cs, he_base->type);
757  var = &i->var;
758  }
759  else
760  {
761  cdef = he->data;
762  cst = cs_get_type_def(cs, he->type);
763  var = cdef->var;
764  }
765 
766  if (!cst)
767  return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
768 
769  int rc = cst->native_set(cs, var, cdef, value, err);
770  if (CSR_RESULT(rc) != CSR_SUCCESS)
771  return rc;
772 
773  if (he->type & DT_INHERITED)
774  he->type = cdef->type | DT_INHERITED;
775 
776  return rc;
777 }
Type definition for a config item.
Definition: set.h:149
#define CSR_RESULT(x)
Definition: set.h:53
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:187
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:134
An inherited config item.
Definition: inheritance.h:31
const char * name
Definition: pgpmicalg.c:46
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:202
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:37
#define CSR_ERR_UNKNOWN
Unrecognised config item.
Definition: set.h:39
cst_native_set native_set
Set the variable using a C-native type.
Definition: set.h:154
void * data
Definition: hash.h:46
void * var
Pointer to the global variable.
Definition: set.h:138
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:38
unsigned int type
Variable type, e.g. DT_STRING.
Definition: set.h:137
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:225
int type
Definition: hash.h:44
The item stored in a Hash Table.
Definition: hash.h:42
#define DT_INHERITED
Config item is inherited.
Definition: types.h:78
intptr_t var
(Pointer to) value, of config item
Definition: inheritance.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_he_native_get()

intptr_t cs_he_native_get ( const struct ConfigSet cs,
struct HashElem he,
struct Buffer err 
)

Natively get the value of a HashElem config item.

Parameters
csConfig items
heHashElem representing config item
errBuffer for results or error messages
Return values
intptr_tNative pointer/value
INT_MINError

Definition at line 787 of file set.c.

788 {
789  if (!cs || !he)
790  return INT_MIN;
791 
792  const struct ConfigDef *cdef = NULL;
793  const struct ConfigSetType *cst = NULL;
794  void *var = NULL;
795 
796  if (he->type & DT_INHERITED)
797  {
798  struct Inheritance *i = he->data;
799 
800  // inherited, value not set
801  if (DTYPE(he->type) == 0)
802  return cs_he_native_get(cs, i->parent, err);
803 
804  // inherited, value set
805  struct HashElem *he_base = cs_get_base(he);
806  cdef = he_base->data;
807  cst = cs_get_type_def(cs, he_base->type);
808  var = &i->var;
809  }
810  else
811  {
812  // not inherited
813  cdef = he->data;
814  cst = cs_get_type_def(cs, he->type);
815  var = cdef->var;
816  }
817 
818  if (!cst)
819  {
820  mutt_buffer_printf(err, "Variable '%s' has an invalid type %d", cdef->name, he->type);
821  return INT_MIN;
822  }
823 
824  return cst->native_get(cs, var, cdef, err);
825 }
Type definition for a config item.
Definition: set.h:149
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:187
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:134
#define DTYPE(x)
Mask for the Data Type.
Definition: types.h:43
An inherited config item.
Definition: inheritance.h:31
const char * name
User-visible name.
Definition: set.h:136
cst_native_get native_get
Get the variable&#39;s value as a C-native type.
Definition: set.h:155
void * data
Definition: hash.h:46
void * var
Pointer to the global variable.
Definition: set.h:138
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:225
int type
Definition: hash.h:44
The item stored in a Hash Table.
Definition: hash.h:42
struct HashElem * parent
HashElem of parent config item.
Definition: inheritance.h:33
intptr_t cs_he_native_get(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err)
Natively get the value of a HashElem config item.
Definition: set.c:787
#define DT_INHERITED
Config item is inherited.
Definition: types.h:78
intptr_t var
(Pointer to) value, of config item
Definition: inheritance.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_str_native_get()

intptr_t cs_str_native_get ( const struct ConfigSet cs,
const char *  name,
struct Buffer err 
)

Natively get the value of a string config item.

Parameters
csConfig items
nameName of config item
errBuffer for error messages
Return values
intptr_tNative pointer/value
INT_MINError

Definition at line 835 of file set.c.

836 {
837  if (!cs || !name)
838  return INT_MIN;
839 
840  struct HashElem *he = cs_get_elem(cs, name);
841  return cs_he_native_get(cs, he, err);
842 }
const char * name
Definition: pgpmicalg.c:46
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:202
The item stored in a Hash Table.
Definition: hash.h:42
intptr_t cs_he_native_get(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err)
Natively get the value of a HashElem config item.
Definition: set.c:787
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ RegisteredTypes

struct ConfigSetType RegisteredTypes[18]
Initial value:
= {
{ NULL, NULL, NULL, NULL, NULL, NULL, NULL },
}

Definition at line 38 of file set.c.