summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2008-02-12 12:16:39 +0100
committerFelix Fietkau <nbd@openwrt.org>2008-02-12 12:16:39 +0100
commit53726f5dd57ab09a206c96108a71db25e7517caa (patch)
tree12eaab9a1578a2b15f5806e1dc47b4b9e3ab2764
parent4f629ff865b978a7ea399776ff6af83c6428bda0 (diff)
downloaduci-53726f5dd57ab09a206c96108a71db25e7517caa.tar.gz
add uci_set_backend()
-rw-r--r--file.c2
-rw-r--r--libuci.c11
-rw-r--r--list.c10
-rw-r--r--uci.h9
4 files changed, 26 insertions, 6 deletions
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,