From: Felix Fietkau Date: Tue, 12 Feb 2008 11:16:39 +0000 (+0100) Subject: add uci_set_backend() X-Git-Url: http://pilppa.com/gitweb/?a=commitdiff_plain;h=53726f5dd57ab09a206c96108a71db25e7517caa;p=uci.git add uci_set_backend() --- diff --git a/file.c b/file.c index 883e360..29ff318 100644 --- a/file.c +++ b/file.c @@ -69,7 +69,7 @@ static void uci_switch_config(struct uci_context *ctx) * 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); diff --git a/libuci.c b/libuci.c index 6bbc874..50c17f9 100644 --- a/libuci.c +++ b/libuci.c @@ -194,4 +194,15 @@ int uci_load(struct uci_context *ctx, const char *name, struct uci_package **pac 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; +} diff --git a/list.c b/list.c index aabcab0..fb4d478 100644 --- a/list.c +++ b/list.c @@ -217,7 +217,7 @@ uci_free_package(struct uci_package **package) *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; @@ -240,13 +240,13 @@ int uci_lookup(struct uci_context *ctx, struct uci_element **res, struct uci_pac 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; } @@ -451,7 +451,7 @@ int uci_set(struct uci_context *ctx, struct uci_package *p, char *section, char * 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; @@ -460,7 +460,7 @@ int uci_set(struct uci_context *ctx, struct uci_package *p, char *section, char 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); diff --git a/uci.h b/uci.h index 4855170..29cd07d 100644 --- a/uci.h +++ b/uci.h @@ -275,6 +275,15 @@ extern int uci_revert(struct uci_context *ctx, struct uci_package **p, char *sec */ 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,