add abstraction for listing config files as well
authorFelix Fietkau <nbd@openwrt.org>
Tue, 12 Feb 2008 10:36:24 +0000 (11:36 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Tue, 12 Feb 2008 10:36:24 +0000 (11:36 +0100)
file.c
libuci.c
uci.h

diff --git a/file.c b/file.c
index 62ab1a8..9f59637 100644 (file)
--- a/file.c
+++ b/file.c
@@ -442,7 +442,7 @@ static inline char *get_filename(char *path)
        return p;
 }
 
-int uci_list_configs(struct uci_context *ctx, char ***list)
+static char **uci_list_config_files(struct uci_context *ctx)
 {
        char **configs;
        glob_t globbuf;
@@ -450,8 +450,6 @@ int uci_list_configs(struct uci_context *ctx, char ***list)
        char *buf;
        char *dir;
 
-       UCI_HANDLE_ERR(ctx);
-
        dir = uci_malloc(ctx, strlen(ctx->confdir) + 1 + sizeof("/*"));
        sprintf(dir, "%s/*", ctx->confdir);
        if (glob(dir, GLOB_MARK, NULL, &globbuf) != 0)
@@ -481,10 +479,8 @@ int uci_list_configs(struct uci_context *ctx, char ***list)
                strcpy(buf, p);
                buf += strlen(buf) + 1;
        }
-       *list = configs;
        free(dir);
-
-       return 0;
+       return configs;
 }
 
 static struct uci_package *uci_file_load(struct uci_context *ctx, const char *name)
@@ -536,4 +532,5 @@ static struct uci_backend uci_file_backend = {
        .name = "file",
        .load = uci_file_load,
        .commit = uci_file_commit,
+       .list_configs = uci_list_config_files,
 };
index 4985a33..a220199 100644 (file)
--- a/libuci.c
+++ b/libuci.c
@@ -158,6 +158,15 @@ void uci_perror(struct uci_context *ctx, const char *prefix)
        }
 }
 
+int uci_list_configs(struct uci_context *ctx, char ***list)
+{
+       UCI_HANDLE_ERR(ctx);
+       UCI_ASSERT(ctx, list != NULL);
+       UCI_ASSERT(ctx, ctx->backend && ctx->backend->list_configs);
+       *list = ctx->backend->list_configs(ctx);
+       return 0;
+}
+
 int uci_commit(struct uci_context *ctx, struct uci_package **package, bool overwrite)
 {
        UCI_HANDLE_ERR(ctx);
diff --git a/uci.h b/uci.h
index 2fbcb80..382e745 100644 (file)
--- a/uci.h
+++ b/uci.h
@@ -299,6 +299,7 @@ struct uci_element
 struct uci_backend
 {
        const char *name;
+       char **(*list_configs)(struct uci_context *ctx);
        struct uci_package *(*load)(struct uci_context *ctx, const char *name);
        void (*commit)(struct uci_context *ctx, struct uci_package **p, bool overwrite);
 };