diff options
author | Felix Fietkau <nbd@openwrt.org> | 2008-09-05 21:51:46 +0200 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2008-09-05 21:51:46 +0200 |
commit | 1a388b01f8c85a8a8b987789096d1f9e86b29fdf (patch) | |
tree | 7966b5ccba1ab61a600395b07a5a8685eb07b6a2 | |
parent | c0d8661d7ec87bd2cf06a496a0c4e50e61106747 (diff) | |
download | uci-1a388b01f8c85a8a8b987789096d1f9e86b29fdf.tar.gz |
overhaul package and section type validation - makes it easier to read and fixes some bugs in uci changes and uci show without explicit package references
-rw-r--r-- | file.c | 8 | ||||
-rw-r--r-- | list.c | 4 | ||||
-rw-r--r-- | util.c | 12 |
3 files changed, 17 insertions, 7 deletions
@@ -119,7 +119,7 @@ static void uci_parse_config(struct uci_context *ctx, char **str) *str += strlen(*str) + 1; type = next_arg(ctx, str, true, false); - if (!uci_validate_str(type, false)) + if (!uci_validate_type(type)) uci_parse_error(ctx, type, "invalid character in field"); name = next_arg(ctx, str, false, true); assert_eol(ctx, str); @@ -353,7 +353,7 @@ int uci_import(struct uci_context *ctx, FILE *stream, const char *name, struct u * NB: the config file can still override the package name */ if (name) { - UCI_ASSERT(ctx, uci_validate_str(name, false)); + UCI_ASSERT(ctx, uci_validate_package(name)); pctx->name = name; } @@ -394,7 +394,7 @@ static char *uci_config_path(struct uci_context *ctx, const char *name) { char *filename; - UCI_ASSERT(ctx, uci_validate_str(name, false)); + UCI_ASSERT(ctx, uci_validate_package(name)); filename = uci_malloc(ctx, strlen(name) + strlen(ctx->confdir) + 2); sprintf(filename, "%s/%s", ctx->confdir, name); @@ -520,7 +520,7 @@ static char **uci_list_config_files(struct uci_context *ctx) if (!p) continue; - if (!uci_validate_name(p)) + if (!uci_validate_package(p)) continue; configs[i] = buf; @@ -322,7 +322,7 @@ uci_lookup_ext_section(struct uci_context *ctx, struct uci_ptr *ptr) if (!*name) name = NULL; - else if (!uci_validate_str(name, false)) + else if (!uci_validate_type(name)) goto error; /* if the given index is negative, it specifies the section number from @@ -618,7 +618,7 @@ int uci_set(struct uci_context *ctx, struct uci_ptr *ptr) UCI_ASSERT(ctx, ptr->value); UCI_ASSERT(ctx, ptr->s || (!ptr->option && ptr->section)); if (!ptr->option) { - UCI_ASSERT(ctx, uci_validate_str(ptr->value, false)); + UCI_ASSERT(ctx, uci_validate_type(ptr->value)); } if (!ptr->o && ptr->s && ptr->option) { @@ -96,6 +96,16 @@ __plugin bool uci_validate_str(const char *str, bool name) return true; } +static inline bool uci_validate_package(const char *str) +{ + return uci_validate_str(str, false); +} + +static inline bool uci_validate_type(const char *str) +{ + return uci_validate_str(str, false); +} + static inline bool uci_validate_name(const char *str) { return uci_validate_str(str, true); @@ -159,7 +169,7 @@ int uci_parse_ptr(struct uci_context *ctx, struct uci_ptr *ptr, char *str) goto error; lastval: - if (ptr->package && !uci_validate_str(ptr->package, false)) + if (ptr->package && !uci_validate_package(ptr->package)) goto error; if (ptr->section && !uci_validate_name(ptr->section)) ptr->flags |= UCI_LOOKUP_EXTENDED; |