* libuci - Library for the Unified Configuration Interface
* Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
*
- * this program is free software; you can redistribute it and/or modify
- * it under the terms of the gnu lesser general public license version 2.1
- * as published by the free software foundation
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1
+ * as published by the Free Software Foundation
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
case '"':
parse_double_quote(ctx, str, target);
break;
+ case '#':
+ **str = 0;
+ /* fall through */
case 0:
goto done;
case '\\':
char *pbrk = NULL;
word = strtok_r(word, " \t", &pbrk);
+ if (!word)
+ continue;
+
switch(word[0]) {
+ case '#':
+ return;
case 'p':
if ((word[1] == 0) || !strcmp(word + 1, "ackage"))
uci_parse_package(ctx, &word, single);
uci_file_cleanup(ctx);
}
+static void uci_load_history_file(struct uci_context *ctx, struct uci_package *p, char *filename, FILE **f, bool flush)
+{
+ FILE *stream = NULL;
+
+ UCI_TRAP_SAVE(ctx, done);
+ stream = uci_open_stream(ctx, filename, SEEK_SET, flush, false);
+ if (p)
+ uci_parse_history(ctx, stream, p);
+ UCI_TRAP_RESTORE(ctx);
+done:
+ if (f)
+ *f = stream;
+ else if (stream)
+ uci_close_stream(stream);
+}
+
static void uci_load_history(struct uci_context *ctx, struct uci_package *p, bool flush)
{
+ struct uci_element *e;
char *filename = NULL;
FILE *f = NULL;
if (!p->confdir)
return;
- if ((asprintf(&filename, "%s/%s", UCI_SAVEDIR, p->e.name) < 0) || !filename)
- UCI_THROW(ctx, UCI_ERR_MEM);
+ uci_foreach_element(&ctx->history_path, e) {
+ if ((asprintf(&filename, "%s/%s", e->name, p->e.name) < 0) || !filename)
+ UCI_THROW(ctx, UCI_ERR_MEM);
- UCI_TRAP_SAVE(ctx, done);
- f = uci_open_stream(ctx, filename, SEEK_SET, flush, false);
- if (p)
- uci_parse_history(ctx, f, p);
- UCI_TRAP_RESTORE(ctx);
+ uci_load_history_file(ctx, p, filename, NULL, false);
+ free(filename);
+ }
-done:
+ if ((asprintf(&filename, "%s/%s", ctx->savedir, p->e.name) < 0) || !filename)
+ UCI_THROW(ctx, UCI_ERR_MEM);
+
+ uci_load_history_file(ctx, p, filename, &f, flush);
if (flush && f) {
rewind(f);
ftruncate(fileno(f), 0);
char *filename;
UCI_ASSERT(ctx, uci_validate_name(name));
- filename = uci_malloc(ctx, strlen(name) + sizeof(UCI_CONFDIR) + 2);
- sprintf(filename, UCI_CONFDIR "/%s", name);
+ filename = uci_malloc(ctx, strlen(name) + strlen(ctx->confdir) + 2);
+ sprintf(filename, "%s/%s", ctx->confdir, name);
return filename;
}
if (uci_list_empty(&p->history))
return 0;
- if ((asprintf(&filename, "%s/%s", UCI_SAVEDIR, p->e.name) < 0) || !filename)
+ if ((asprintf(&filename, "%s/%s", ctx->savedir, p->e.name) < 0) || !filename)
UCI_THROW(ctx, UCI_ERR_MEM);
ctx->errno = 0;
glob_t globbuf;
int size, i;
char *buf;
+ char *dir;
UCI_HANDLE_ERR(ctx);
- if (glob(UCI_CONFDIR "/*", GLOB_MARK, NULL, &globbuf) != 0)
+ dir = uci_malloc(ctx, strlen(ctx->confdir) + 1 + sizeof("/*"));
+ sprintf(dir, "%s/*", ctx->confdir);
+ if (glob(dir, GLOB_MARK, NULL, &globbuf) != 0)
UCI_THROW(ctx, UCI_ERR_NOTFOUND);
size = sizeof(char *) * (globbuf.gl_pathc + 1);
buf += strlen(buf) + 1;
}
*list = configs;
+ free(dir);
return 0;
}