projects
/
project
/
uci.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
allow the user of the library to override the confdir/searchdir
[project/uci.git]
/
file.c
diff --git
a/file.c
b/file.c
index
803e912
..
4e3e828
100644
(file)
--- a/
file.c
+++ b/
file.c
@@
-210,6
+210,9
@@
static void parse_str(struct uci_context *ctx, char **str, char **target)
case '"':
parse_double_quote(ctx, str, target);
break;
case '"':
parse_double_quote(ctx, str, target);
break;
+ case '#':
+ **str = 0;
+ /* fall through */
case 0:
goto done;
case '\\':
case 0:
goto done;
case '\\':
@@
-268,7
+271,7
@@
static void assert_eol(struct uci_context *ctx, char **str)
char *tmp;
tmp = next_arg(ctx, str, false, false);
char *tmp;
tmp = next_arg(ctx, str, false, false);
- if (tmp && *tmp)
+ if (tmp && *tmp
&& (ctx->flags & UCI_FLAG_STRICT)
)
uci_parse_error(ctx, *str, "too many arguments");
}
uci_parse_error(ctx, *str, "too many arguments");
}
@@
-450,7
+453,12
@@
static void uci_parse_line(struct uci_context *ctx, bool single)
char *pbrk = NULL;
word = strtok_r(word, " \t", &pbrk);
char *pbrk = NULL;
word = strtok_r(word, " \t", &pbrk);
+ if (!word)
+ continue;
+
switch(word[0]) {
switch(word[0]) {
+ case '#':
+ return;
case 'p':
if ((word[1] == 0) || !strcmp(word + 1, "ackage"))
uci_parse_package(ctx, &word, single);
case 'p':
if ((word[1] == 0) || !strcmp(word + 1, "ackage"))
uci_parse_package(ctx, &word, single);
@@
-576,8
+584,10
@@
int uci_import(struct uci_context *ctx, FILE *stream, const char *name, struct u
* the appropriate 'package <name>' string to specify the config name
* NB: the config file can still override the package name
*/
* the appropriate 'package <name>' string to specify the config name
* NB: the config file can still override the package name
*/
- if (name)
+ if (name) {
+ UCI_ASSERT(ctx, uci_validate_name(name));
pctx->name = name;
pctx->name = name;
+ }
while (!feof(pctx->file)) {
uci_getln(ctx, 0);
while (!feof(pctx->file)) {
uci_getln(ctx, 0);
@@
-682,14
+692,14
@@
static void uci_parse_history_line(struct uci_context *ctx, struct uci_package *
}
UCI_INTERNAL(uci_parse_tuple, ctx, buf, &package, §ion, &option, &value);
}
UCI_INTERNAL(uci_parse_tuple, ctx, buf, &package, §ion, &option, &value);
- if (!package || !section || (!delete && !value))
- goto error;
- if (strcmp(package, p->e.name) != 0)
+ if (!package || (strcmp(package, p->e.name) != 0))
goto error;
if (!uci_validate_name(section))
goto error;
if (option && !uci_validate_name(option))
goto error;
goto error;
if (!uci_validate_name(section))
goto error;
if (option && !uci_validate_name(option))
goto error;
+ if ((rename || !delete) && !uci_validate_name(value))
+ goto error;
if (rename)
UCI_INTERNAL(uci_rename, ctx, p, section, option, value);
if (rename)
UCI_INTERNAL(uci_rename, ctx, p, section, option, value);
@@
-741,7
+751,8
@@
static void uci_load_history(struct uci_context *ctx, struct uci_package *p, boo
if (!p->confdir)
return;
if (!p->confdir)
return;
- 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);
UCI_TRAP_SAVE(ctx, done);
UCI_THROW(ctx, UCI_ERR_MEM);
UCI_TRAP_SAVE(ctx, done);
@@
-766,10
+777,9
@@
static char *uci_config_path(struct uci_context *ctx, const char *name)
{
char *filename;
{
char *filename;
- if (strchr(name, '/'))
- UCI_THROW(ctx, UCI_ERR_INVAL);
- filename = uci_malloc(ctx, strlen(name) + sizeof(UCI_CONFDIR) + 2);
- sprintf(filename, UCI_CONFDIR "/%s", name);
+ UCI_ASSERT(ctx, uci_validate_name(name));
+ filename = uci_malloc(ctx, strlen(name) + strlen(ctx->confdir) + 2);
+ sprintf(filename, "%s/%s", ctx->confdir, name);
return filename;
}
return filename;
}
@@
-781,7
+791,6
@@
int uci_load(struct uci_context *ctx, const char *name, struct uci_package **pac
FILE *file = NULL;
UCI_HANDLE_ERR(ctx);
FILE *file = NULL;
UCI_HANDLE_ERR(ctx);
- UCI_ASSERT(ctx, uci_validate_name(name));
switch (name[0]) {
case '.':
switch (name[0]) {
case '.':
@@
-840,7
+849,7
@@
int uci_save(struct uci_context *ctx, struct uci_package *p)
if (uci_list_empty(&p->history))
return 0;
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;
UCI_THROW(ctx, UCI_ERR_MEM);
ctx->errno = 0;
@@
-906,8
+915,14
@@
int uci_commit(struct uci_context *ctx, struct uci_package **package, bool overw
if (!overwrite) {
name = uci_strdup(ctx, p->e.name);
path = uci_strdup(ctx, p->path);
if (!overwrite) {
name = uci_strdup(ctx, p->e.name);
path = uci_strdup(ctx, p->path);
+ /* dump our own changes to the history file */
if (!uci_list_empty(&p->history))
UCI_INTERNAL(uci_save, ctx, p);
if (!uci_list_empty(&p->history))
UCI_INTERNAL(uci_save, ctx, p);
+
+ /*
+ * other processes might have modified the config
+ * as well. dump and reload
+ */
uci_free_package(&p);
uci_file_cleanup(ctx);
UCI_INTERNAL(uci_import, ctx, f, name, &p, true);
uci_free_package(&p);
uci_file_cleanup(ctx);
UCI_INTERNAL(uci_import, ctx, f, name, &p, true);
@@
-969,10
+984,13
@@
int uci_list_configs(struct uci_context *ctx, char ***list)
glob_t globbuf;
int size, i;
char *buf;
glob_t globbuf;
int size, i;
char *buf;
+ char *dir;
UCI_HANDLE_ERR(ctx);
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);
UCI_THROW(ctx, UCI_ERR_NOTFOUND);
size = sizeof(char *) * (globbuf.gl_pathc + 1);
@@
-1000,6
+1018,7
@@
int uci_list_configs(struct uci_context *ctx, char ***list)
buf += strlen(buf) + 1;
}
*list = configs;
buf += strlen(buf) + 1;
}
*list = configs;
+ free(dir);
return 0;
}
return 0;
}