NeoMutt  2019-12-07-60-g0cfa53
Teaching an old dog new tricks
DOXYGEN
set.c
Go to the documentation of this file.
1 
29 #include "config.h"
30 #include <limits.h>
31 #include <stdio.h>
32 #include <string.h>
33 #include "mutt/mutt.h"
34 #include "set.h"
35 #include "inheritance.h"
36 #include "types.h"
37 
38 struct ConfigSetType RegisteredTypes[18] = {
39  { NULL, NULL, NULL, NULL, NULL, NULL, NULL },
40 };
41 
48 static void destroy(int type, void *obj, intptr_t data)
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 }
84 
92 static struct HashElem *create_synonym(const struct ConfigSet *cs,
93  struct ConfigDef *cdef, struct Buffer *err)
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 }
114 
122 static struct HashElem *reg_one_var(const struct ConfigSet *cs,
123  struct ConfigDef *cdef, struct Buffer *err)
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 }
148 
154 struct ConfigSet *cs_new(size_t size)
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 }
163 
168 void cs_free(struct ConfigSet **ptr)
169 {
170  if (!ptr || !*ptr)
171  return;
172 
173  struct ConfigSet *cs = *ptr;
174 
175  mutt_hash_free(&cs->hash);
176  FREE(ptr);
177 }
178 
187 struct HashElem *cs_get_base(struct HashElem *he)
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 }
195 
202 struct HashElem *cs_get_elem(const struct ConfigSet *cs, const char *name)
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 }
218 
225 const struct ConfigSetType *cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
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 }
239 
247 bool cs_register_type(struct ConfigSet *cs, unsigned int type, const struct ConfigSetType *cst)
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 }
267 
275 bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[], int flags)
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 }
296 
304 struct HashElem *cs_inherit_variable(const struct ConfigSet *cs,
305  struct HashElem *parent, const char *name)
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 }
323 
329 void cs_uninherit_variable(const struct ConfigSet *cs, const char *name)
330 {
331  if (!cs || !name)
332  return;
333 
334  mutt_hash_delete(cs->hash, name, NULL);
335 }
336 
344 int cs_he_reset(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err)
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 }
382 
390 int cs_str_reset(const struct ConfigSet *cs, const char *name, struct Buffer *err)
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 }
404 
413 int cs_he_initial_set(const struct ConfigSet *cs, struct HashElem *he,
414  const char *value, struct Buffer *err)
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 }
444 
453 int cs_str_initial_set(const struct ConfigSet *cs, const char *name,
454  const char *value, struct Buffer *err)
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 }
468 
479 int cs_he_initial_get(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result)
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 }
508 
519 int cs_str_initial_get(const struct ConfigSet *cs, const char *name, struct Buffer *result)
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 }
533 
542 int cs_he_string_set(const struct ConfigSet *cs, struct HashElem *he,
543  const char *value, struct Buffer *err)
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 }
582 
591 int cs_str_string_set(const struct ConfigSet *cs, const char *name,
592  const char *value, struct Buffer *err)
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 }
606 
614 int cs_he_string_get(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result)
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 }
654 
662 int cs_str_string_get(const struct ConfigSet *cs, const char *name, struct Buffer *result)
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 }
676 
685 int cs_he_native_set(const struct ConfigSet *cs, struct HashElem *he,
686  intptr_t value, struct Buffer *err)
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 }
725 
734 int cs_str_native_set(const struct ConfigSet *cs, const char *name,
735  intptr_t value, struct Buffer *err)
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 }
778 
787 intptr_t cs_he_native_get(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err)
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 }
826 
835 intptr_t cs_str_native_get(const struct ConfigSet *cs, const char *name, struct Buffer *err)
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 }
Type definition for a config item.
Definition: set.h:149
void mutt_hash_delete(struct Hash *table, const char *strkey, const void *data)
Remove an element from a Hash table.
Definition: hash.c:443
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
cst_reset reset
Reset the variable to its initial, or parent, value.
Definition: set.h:156
Constants for all the config types.
#define CSR_RESULT(x)
Definition: set.h:53
int cs_str_string_set(const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err)
Set a config item by string.
Definition: set.c:591
struct ConfigSetType types[18]
All the defined config types.
Definition: set.h:171
static void destroy(int type, void *obj, intptr_t data)
Callback function for the Hash Table - Implements hashelem_free_t.
Definition: set.c:48
intptr_t initial
Initial value.
Definition: set.h:139
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.
Definition: set.c:519
void cs_uninherit_variable(const struct ConfigSet *cs, const char *name)
Remove an inherited config item.
Definition: set.c:329
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:61
struct HashElem * cs_inherit_variable(const struct ConfigSet *cs, struct HashElem *parent, const char *name)
Create in inherited config item.
Definition: set.c:304
String manipulation buffer.
Definition: buffer.h:33
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
cst_string_get string_get
Initialise a variable from a string.
Definition: set.h:153
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.
Definition: set.c:835
const char * name
Name of this config item.
Definition: inheritance.h:34
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
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.
Definition: set.c:453
#define mutt_array_size(x)
Definition: memory.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
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
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
int cs_str_string_get(const struct ConfigSet *cs, const char *name, struct Buffer *result)
Get a config item as a string.
Definition: set.c:662
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:294
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.
Definition: set.c:685
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
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
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 mutt_b2s(buf)
Definition: buffer.h:41
#define CSR_ERR_UNKNOWN
Unrecognised config item.
Definition: set.h:39
A collection of config items.
cst_string_set string_set
Convert the variable to a string.
Definition: set.h:152
struct Hash * mutt_hash_new(size_t nelem, HashFlags flags)
Create a new Hash table (with string keys)
Definition: hash.c:275
cst_native_set native_set
Set the variable using a C-native type.
Definition: set.h:154
cst_destroy destroy
Free the resources for a variable.
Definition: set.h:157
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
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
void cs_free(struct ConfigSet **ptr)
Free a Config Set.
Definition: set.c:168
struct ConfigSet * cs_new(size_t size)
Create a new Config Set.
Definition: set.c:154
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
int cs_str_reset(const struct ConfigSet *cs, const char *name, struct Buffer *err)
Reset a config item to its initial value.
Definition: set.c:390
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
#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
Log at debug level 1.
Definition: logging.h:40
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
An inherited config item.
const char * name
Name of the type, e.g. "String".
Definition: set.h:151
int type
Definition: hash.h:44
#define FREE(x)
Definition: memory.h:40
The item stored in a Hash Table.
Definition: hash.h:42
bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[], int flags)
Register a set of config items.
Definition: set.c:275
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
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
struct HashElem * parent
HashElem of parent config item.
Definition: inheritance.h:33
void mutt_hash_free(struct Hash **ptr)
Free a hash table.
Definition: hash.c:471
bool cs_register_type(struct ConfigSet *cs, unsigned int type, const struct ConfigSetType *cst)
Register a type of config item.
Definition: set.c:247
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 MUTT_HASH_NO_FLAGS
No flags are set.
Definition: hash.h:74
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
#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
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.
Definition: set.c:734
intptr_t var
(Pointer to) value, of config item
Definition: inheritance.h:35