- UCI_ASSERT(ctx, (element != NULL) && (*element != NULL));
-
- /* what the 'value' of an element means depends on the type
- * for a section, the 'value' means its type
- * for an option, the 'value' means its value string
- * when changing the value, shrink the element to its actual size
- * (it may have been allocated with a bigger size, to include
- * its buffer)
- * then duplicate the string passed on the command line and
- * insert it into the structure.
- */
- e = *element;
- list = e->list.prev;
- switch(e->type) {
- case UCI_TYPE_SECTION:
- UCI_ASSERT(ctx, uci_validate_str(value, false));
- size = sizeof(struct uci_section);
- s = uci_to_section(e);
- section = e->name;
- option = NULL;
- /* matches the currently set value */
- if (!strcmp(value, s->type))
- return 0;
- break;
- case UCI_TYPE_OPTION:
- UCI_ASSERT(ctx, value != NULL);
- size = sizeof(struct uci_option);
- s = uci_to_option(e)->section;
- section = s->e.name;
- option = e->name;
- /* matches the currently set value */
- if (!strcmp(value, e->name))
- return 0;
- break;
- default:
- UCI_THROW(ctx, UCI_ERR_INVAL);
- return 0;
- }
- p = s->package;
- if (!internal && p->has_history)
- uci_add_history(ctx, &p->history, UCI_CMD_CHANGE, section, option, value);