UCI_TRAP_SAVE(ctx, error);
ptr->o = uci_alloc_list(ptr->s, ptr->option, NULL);
UCI_TRAP_RESTORE(ctx);
- ptr->last = &ptr->o->e;
} else if (ptr->o->type == UCI_TYPE_STRING) {
/* create new list and add old string value as item to list */
struct uci_option *old = ptr->o;
if (ptr->option == old->e.name)
ptr->option = ptr->o->e.name;
uci_free_option(old);
- ptr->last = &ptr->o->e;
}
/* add new item to list */
return uci_delete(ctx, ptr);
} else if (!ptr->o && ptr->option) { /* new option */
ptr->o = uci_alloc_option(ptr->s, ptr->option, ptr->value, NULL);
- ptr->last = &ptr->o->e;
} else if (!ptr->s && ptr->section) { /* new section */
ptr->s = uci_alloc_section(ptr->p, ptr->value, ptr->section, NULL);
- ptr->last = &ptr->s->e;
} else if (ptr->o && ptr->option) { /* update option */
if (ptr->o->type == UCI_TYPE_STRING && !strcmp(ptr->o->v.string, ptr->value))
return 0;
if (ptr->option == old->e.name)
ptr->option = ptr->o->e.name;
uci_free_option(old);
- ptr->last = &ptr->o->e;
}
} else if (ptr->s && ptr->section) { /* update section */
- struct uci_section *old = ptr->s;
- ptr->s = uci_alloc_section(ptr->p, ptr->value, old->e.name, &old->e.list);
- uci_section_transfer_options(ptr->s, old);
- if (ptr->section == old->e.name)
- ptr->section = ptr->s->e.name;
- uci_free_section(old);
- ptr->s->package->n_section--;
- ptr->last = &ptr->s->e;
+ if (!strcmp(ptr->s->type, ptr->value))
+ return 0;
+
+ if (strlen(ptr->s->type) == strlen(ptr->value)) {
+ strcpy(ptr->s->type, ptr->value);
+ } else {
+ struct uci_section *old = ptr->s;
+ ptr->s = uci_alloc_section(ptr->p, ptr->value, old->e.name, &old->e.list);
+ uci_section_transfer_options(ptr->s, old);
+ if (ptr->section == old->e.name)
+ ptr->section = ptr->s->e.name;
+ uci_free_section(old);
+ ptr->s->package->n_section--;
+ }
} else {
UCI_THROW(ctx, UCI_ERR_INVAL);
}