/** * reg_one_var - Register one config item * @param cs Config items * @param cdef Variable definition * @param err Buffer for error messages * @retval ptr New HashElem representing the config item */ static struct HashElem *reg_one_var(const struct ConfigSet *cs, struct ConfigDef *cdef, struct Buffer *err) { if (!cs || !cdef) return NULL; /* LCOV_EXCL_LINE */ if (cdef->type == DT_SYNONYM) return create_synonym(cs, cdef, err); const struct ConfigSetType *cst = cs_get_type_def(cs, cdef->type); if (!cst) { mutt_buffer_printf(err, "Variable '%s' has an invalid type %d", cdef->name, cdef->type); return NULL; } struct HashElem *he = mutt_hash_typed_insert(cs->hash, cdef->name, cdef->type, (void *) cdef); if (!he) return NULL; /* LCOV_EXCL_LINE */ if (cst && cst->reset) cst->reset(cs, cdef->var, cdef, err); return he; }
/** * cs_inherit_variable - Create in inherited config item * @param cs Config items * @param parent HashElem of parent config item * @param name Name of account-specific config item * @retval ptr New HashElem representing the inherited config item */ struct HashElem *cs_inherit_variable(const struct ConfigSet *cs, struct HashElem *parent, const char *name) { if (!cs || !parent) return NULL; /* LCOV_EXCL_LINE */ struct Buffer err; mutt_buffer_init(&err); err.dsize = 256; err.data = calloc(1, err.dsize); struct Inheritance *i = mutt_mem_calloc(1, sizeof(*i)); i->parent = parent; i->name = mutt_str_strdup(name); struct HashElem *he = mutt_hash_typed_insert(cs->hash, i->name, DT_INHERITED, i); if (!he) { FREE(&i->name); FREE(&i); } FREE(&err.data); return he; }
/** * cs_inherit_variable - Create in inherited config item * @param cs Config items * @param parent HashElem of parent config item * @param name Name of account-specific config item * @retval ptr New HashElem representing the inherited config item */ struct HashElem *cs_inherit_variable(const struct ConfigSet *cs, struct HashElem *parent, const char *name) { if (!cs || !parent) return NULL; struct Inheritance *i = mutt_mem_calloc(1, sizeof(*i)); i->parent = parent; i->name = mutt_str_strdup(name); struct HashElem *he = mutt_hash_typed_insert(cs->hash, i->name, DT_INHERITED, i); if (!he) { FREE(&i->name); FREE(&i); } return he; }
/** * create_synonym - Create an alternative name for a config item * @param cs Config items * @param cdef Variable definition * @param err Buffer for error messages * @retval ptr New HashElem representing the config item synonym */ static struct HashElem *create_synonym(const struct ConfigSet *cs, struct ConfigDef *cdef, struct Buffer *err) { if (!cs || !cdef) return NULL; /* LCOV_EXCL_LINE */ const char *name = (const char *) cdef->initial; struct HashElem *parent = cs_get_elem(cs, name); if (!parent) { mutt_buffer_printf(err, "No such variable: %s", name); return NULL; } struct HashElem *child = mutt_hash_typed_insert(cs->hash, cdef->name, cdef->type, (void *) cdef); if (!child) return NULL; /* LCOV_EXCL_LINE */ cdef->var = parent; return child; }