+ e = expand_ptr(ctx, ptr, true);
+ p = ptr->p;
+
+ UCI_ASSERT(ctx, ptr->s);
+ UCI_ASSERT(ctx, ptr->value);
+
+ if (!internal && p->has_history)
+ uci_add_history(ctx, &p->history, UCI_CMD_RENAME, ptr->section, ptr->option, ptr->value);
+
+ n = uci_strdup(ctx, ptr->value);
+ if (e->name)
+ free(e->name);
+ e->name = n;
+
+ return 0;
+}
+
+int uci_add_section(struct uci_context *ctx, struct uci_package *p, const char *type, struct uci_section **res)
+{
+ bool internal = ctx->internal;
+ struct uci_section *s;
+
+ UCI_HANDLE_ERR(ctx);
+ UCI_ASSERT(ctx, p != NULL);
+ s = uci_alloc_section(p, type, NULL);
+ uci_fixup_section(ctx, s);
+ *res = s;
+ if (!internal && p->has_history)
+ uci_add_history(ctx, &p->history, UCI_CMD_ADD, s->e.name, NULL, type);
+
+ return 0;
+}
+
+int uci_delete(struct uci_context *ctx, struct uci_ptr *ptr)
+{
+ /* NB: pass on internal flag to uci_del_element */
+ bool internal = ctx->internal;
+ struct uci_package *p;
+ struct uci_element *e;
+
+ UCI_HANDLE_ERR(ctx);
+
+ e = expand_ptr(ctx, ptr, true);
+ p = ptr->p;
+
+ UCI_ASSERT(ctx, ptr->s);
+
+ if (!internal && p->has_history)
+ uci_add_history(ctx, &p->history, UCI_CMD_REMOVE, ptr->section, ptr->option, NULL);
+
+ uci_free_any(&e);
+ return 0;
+}
+
+int uci_add_list(struct uci_context *ctx, struct uci_ptr *ptr)
+{
+ /* NB: UCI_INTERNAL use means without history tracking */
+ bool internal = ctx->internal;
+ struct uci_option *prev = NULL;
+ const char *value2 = NULL;
+
+ UCI_HANDLE_ERR(ctx);
+
+ expand_ptr(ctx, ptr, false);
+ UCI_ASSERT(ctx, ptr->s);
+ UCI_ASSERT(ctx, ptr->value);
+
+ if (ptr->o) {
+ switch (ptr->o->type) {
+ case UCI_TYPE_STRING:
+ /* we already have a string value, convert that to a list */
+ prev = ptr->o;
+ value2 = ptr->value;
+ ptr->value = ptr->o->v.string;
+ break;
+ case UCI_TYPE_LIST:
+ uci_add_element_list(ctx, ptr, internal);
+ return 0;
+ default:
+ UCI_THROW(ctx, UCI_ERR_INVAL);
+ break;
+ }