/** * cs_he_initial_set - Set the initial value of a config item * @param cs Config items * @param he HashElem representing config item * @param value Value to set * @param err Buffer for error messages * @retval int Result, e.g. #CSR_SUCCESS */ int cs_he_initial_set(const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err) { if (!cs || !he) return CSR_ERR_CODE; struct ConfigDef *cdef = NULL; const struct ConfigSetType *cst = NULL; if (he->type & DT_INHERITED) { struct Inheritance *i = he->data; cdef = i->parent->data; mutt_debug(LL_DEBUG1, "Variable '%s' is inherited type\n", cdef->name); return CSR_ERR_CODE; } cdef = he->data; cst = cs_get_type_def(cs, he->type); if (!cst) { mutt_debug(LL_DEBUG1, "Variable '%s' has an invalid type %d\n", cdef->name, he->type); return CSR_ERR_CODE; } int rc = cst->string_set(cs, NULL, cdef, value, err); if (CSR_RESULT(rc) != CSR_SUCCESS) return rc; cs_notify_listeners(cs, he, he->key.strkey, CE_INITIAL_SET); return CSR_SUCCESS; }
/** * cs_str_native_set - Natively set the value of a string config item * @param cs Config items * @param name Name of config item * @param value Native pointer/value to set * @param err Buffer for error messages * @retval int Result, e.g. #CSR_SUCCESS */ int cs_str_native_set(const struct ConfigSet *cs, const char *name, intptr_t value, struct Buffer *err) { if (!cs || !name) return CSR_ERR_CODE; /* LCOV_EXCL_LINE */ struct HashElem *he = cs_get_elem(cs, name); if (!he) { mutt_buffer_printf(err, "Unknown var '%s'", name); return CSR_ERR_UNKNOWN; } const struct ConfigDef *cdef = NULL; const struct ConfigSetType *cst = NULL; void *var = NULL; if (he->type & DT_INHERITED) { struct Inheritance *i = he->data; cdef = i->parent->data; var = &i->var; cst = cs_get_type_def(cs, i->parent->type); } else { cdef = he->data; var = cdef->var; cst = cs_get_type_def(cs, he->type); } if (!cst) { mutt_debug(LL_DEBUG1, "Variable '%s' has an invalid type %d\n", cdef->name, he->type); return CSR_ERR_CODE; } int rc = cst->native_set(cs, var, cdef, value, err); if (CSR_RESULT(rc) == CSR_SUCCESS) { if (he->type & DT_INHERITED) he->type = cdef->type | DT_INHERITED; if (!(rc & CSR_SUC_NO_CHANGE)) cs_notify_listeners(cs, he, cdef->name, CE_SET); } return rc; }
/** * cs_he_string_set - Set a config item by string * @param cs Config items * @param he HashElem representing config item * @param value Value to set * @param err Buffer for error messages * @retval int Result, e.g. #CSR_SUCCESS */ int cs_he_string_set(const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err) { if (!cs || !he) return CSR_ERR_CODE; struct ConfigDef *cdef = NULL; const struct ConfigSetType *cst = NULL; void *var = NULL; if (he->type & DT_INHERITED) { struct Inheritance *i = he->data; cdef = i->parent->data; var = &i->var; cst = cs_get_type_def(cs, i->parent->type); } else { cdef = he->data; var = cdef->var; cst = cs_get_type_def(cs, he->type); } if (!cst) { mutt_debug(LL_DEBUG1, "Variable '%s' has an invalid type %d\n", cdef->name, he->type); return CSR_ERR_CODE; } if (!var) return CSR_ERR_CODE; /* LCOV_EXCL_LINE */ int rc = cst->string_set(cs, var, cdef, value, err); if (CSR_RESULT(rc) != CSR_SUCCESS) return rc; if (he->type & DT_INHERITED) { struct Inheritance *i = he->data; he->type = i->parent->type | DT_INHERITED; } if (!(rc & CSR_SUC_NO_CHANGE)) cs_notify_listeners(cs, he, he->key.strkey, CE_SET); return rc; }
/** * cs_he_reset - Reset a config item to its initial value * @param cs Config items * @param he HashElem representing config item * @param err Buffer for error messages * @retval int Result, e.g. #CSR_SUCCESS */ int cs_he_reset(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err) { if (!cs || !he) return CSR_ERR_CODE; /* An inherited var that's already pointing to its parent. * Return 'success', but don't send a notification. */ if ((he->type & DT_INHERITED) && (DTYPE(he->type) == 0)) return CSR_SUCCESS; const struct ConfigSetType *cst = NULL; const struct ConfigDef *cdef = NULL; int rc = CSR_SUCCESS; if (he->type & DT_INHERITED) { struct Inheritance *i = he->data; cst = cs_get_type_def(cs, i->parent->type); cdef = i->parent->data; if (cst && cst->destroy) cst->destroy(cs, (void **) &i->var, cdef); he->type = DT_INHERITED; } else { cst = cs_get_type_def(cs, he->type); cdef = he->data; if (cst) rc = cst->reset(cs, cdef->var, cdef, err); } if ((CSR_RESULT(rc) == CSR_SUCCESS) && !(rc & CSR_SUC_NO_CHANGE)) cs_notify_listeners(cs, he, he->key.strkey, CE_RESET); return rc; }