* if an older config under the same name exists, unload it
* ignore errors here, e.g. if the config was not found
*/
- e = uci_lookup_list(ctx, &ctx->root, name);
+ e = uci_lookup_list(&ctx->root, name);
if (e)
UCI_THROW(ctx, UCI_ERR_DUPLICATE);
pctx->package = uci_alloc_package(ctx, name);
return 0;
}
+int uci_set_backend(struct uci_context *ctx, const char *name)
+{
+ struct uci_element *e;
+ UCI_HANDLE_ERR(ctx);
+ UCI_ASSERT(ctx, name != NULL);
+ e = uci_lookup_list(&ctx->backends, name);
+ if (!e)
+ UCI_THROW(ctx, UCI_ERR_NOTFOUND);
+ ctx->backend = uci_to_backend(e);
+ return 0;
+}
*package = NULL;
}
-static struct uci_element *uci_lookup_list(struct uci_context *ctx, struct uci_list *list, const char *name)
+static struct uci_element *uci_lookup_list(struct uci_list *list, const char *name)
{
struct uci_element *e;
if (option)
UCI_ASSERT(ctx, uci_validate_name(option));
- e = uci_lookup_list(ctx, &p->sections, section);
+ e = uci_lookup_list(&p->sections, section);
if (!e)
goto notfound;
if (option) {
s = uci_to_section(e);
- e = uci_lookup_list(ctx, &s->options, option);
+ e = uci_lookup_list(&s->options, option);
if (!e)
goto notfound;
}
* if the section/option is to be modified and it is not found
* create a new element in the appropriate list
*/
- e = uci_lookup_list(ctx, &p->sections, section);
+ e = uci_lookup_list(&p->sections, section);
if (!e)
goto notfound;
ctx->pctx->section = s;
if (option) {
- e = uci_lookup_list(ctx, &s->options, option);
+ e = uci_lookup_list(&s->options, option);
if (!e)
goto notfound;
o = uci_to_option(e);
*/
extern int uci_parse_argument(struct uci_context *ctx, FILE *stream, char **str, char **result);
+/**
+ * uci_set_backend: change the default backend
+ * @ctx: uci context
+ * @name: name of the backend
+ *
+ * The default backend is "file", which uses /etc/config for config storage
+ */
+extern int uci_set_backend(struct uci_context *ctx, const char *name);
+
/* UCI data structures */
enum uci_type {
UCI_TYPE_HISTORY = 0,