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;
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)
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)
.name = "file",
.load = uci_file_load,
.commit = uci_file_commit,
+ .list_configs = uci_list_config_files,
};
}
}
+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);
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);
};