exit(255);
}
+static void uci_show_file(const char *name)
+{
+ uci_load(ctx, name);
+ uci_unload(ctx, name);
+}
+
static int uci_show(int argc, char **argv)
{
char **configs = uci_list_configs(ctx);
for (p = configs; *p; p++) {
fprintf(stderr, "# config: %s\n", *p);
+ uci_show_file(*p);
}
return 0;
uci_cleanup(ctx);
uci_foreach_entry(config, &ctx->root, cfg) {
- uci_drop_file(cfg);
+ uci_drop_config(cfg);
}
free(ctx);
return;
return NULL;
}
-static void uci_drop_file(struct uci_config *cfg)
+static void uci_drop_config(struct uci_config *cfg)
{
struct uci_section *s;
}
-static struct uci_config *uci_alloc_file(struct uci_context *ctx, const char *name)
+static struct uci_config *uci_alloc_config(struct uci_context *ctx, const char *name)
{
struct uci_config *cfg = NULL;
return cfg;
error:
- uci_drop_file(cfg);
+ uci_drop_config(cfg);
UCI_THROW(ctx, ctx->errno);
return NULL;
}
+int uci_unload(struct uci_context *ctx, const char *name)
+{
+ struct uci_config *cfg;
+
+ UCI_HANDLE_ERR(ctx);
+ UCI_ASSERT(ctx, name != NULL);
+
+ uci_foreach_entry(config, &ctx->root, cfg) {
+ if (!strcmp(cfg->name, name))
+ goto found;
+ }
+ UCI_THROW(ctx, UCI_ERR_NOTFOUND);
+
+found:
+ uci_list_del(&cfg->list);
+ uci_drop_config(cfg);
+
+ return 0;
+}
+
char **uci_list_configs(struct uci_context *ctx)
{
char **configs;
ctx->pctx = NULL;
if (pctx->cfg) {
uci_list_del(&pctx->cfg->list);
- uci_drop_file(pctx->cfg);
+ uci_drop_config(pctx->cfg);
}
if (pctx->buf)
free(pctx->buf);
UCI_HANDLE_ERR(ctx);
UCI_ASSERT(ctx, name != NULL);
+ UCI_TRAP_SAVE(ctx, ignore);
+ uci_unload(ctx, name);
+ UCI_TRAP_RESTORE(ctx);
+
+ignore:
/* make sure no memory from previous parse attempts is leaked */
uci_parse_cleanup(ctx);
if (!pctx->file)
UCI_THROW(ctx, UCI_ERR_IO);
- pctx->cfg = uci_alloc_file(ctx, name);
+ pctx->cfg = uci_alloc_config(ctx, name);
while (!feof(pctx->file)) {
uci_getln(ctx);
*/
extern int uci_load(struct uci_context *ctx, const char *name);
+/**
+ * uci_unload: Unload a config file from the uci context
+ *
+ * @ctx: uci context
+ * @name: name of the config file
+ */
+extern int uci_unload(struct uci_context *ctx, const char *name);
+
/**
* uci_cleanup: Clean up after an error
*