From c203c2f9009a322e5e774ff8cd32bac2fa3b7961 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Thu, 10 Nov 2016 13:13:00 +0100 Subject: [PATCH] Revert "mandatory anonymous section identifier" This reverts commits: df72af474075 "mandatory anonymous section identifier" 2eb9c097e392 "cli: remove now-defunct UCI_FLAG_EXPORT_NAME support" fe45f97302cb "test: adjust for auto-naming anonymous sections" After some discussion we came to the conclusion that we need a different fix. Signed-off-by: Felix Fietkau --- cli.c | 12 ++++--- file.c | 31 +++---------------- list.c | 6 ++-- .../show_parsing_multiline_package.result | 4 +-- uci.h | 3 +- 5 files changed, 19 insertions(+), 37 deletions(-) diff --git a/cli.c b/cli.c index deb670b..f8b45db 100644 --- a/cli.c +++ b/cli.c @@ -156,6 +156,8 @@ static void uci_usage(void) "\t-d set the delimiter for list values in uci show\n" "\t-f use as input instead of stdin\n" "\t-m when importing, merge data into an existing package\n" + "\t-n name unnamed sections on export (default)\n" + "\t-N don't name unnamed sections\n" "\t-p add a search path for config change files\n" "\t-P add a search path for config change files and use as default\n" "\t-q quiet mode (don't print error messages)\n" @@ -727,6 +729,12 @@ int main(int argc, char **argv) ctx->flags &= ~UCI_FLAG_STRICT; ctx->flags |= UCI_FLAG_PERROR; break; + case 'n': + ctx->flags |= UCI_FLAG_EXPORT_NAME; + break; + case 'N': + ctx->flags &= ~UCI_FLAG_EXPORT_NAME; + break; case 'p': uci_add_delta_path(ctx, optarg); break; @@ -741,10 +749,6 @@ int main(int argc, char **argv) case 'X': flags &= ~CLI_FLAG_SHOW_EXT; break; - case 'n': - case 'N': - /* obsolete */ - break; default: uci_usage(); return 0; diff --git a/file.c b/file.c index 76f7f32..7e1e4e6 100644 --- a/file.c +++ b/file.c @@ -288,27 +288,6 @@ int uci_parse_argument(struct uci_context *ctx, FILE *stream, char **str, char * return 0; } -/* - * Fixup sections functions does the fixup of all sections for given package. - * It is used as a preprocessing step for fixing up existing anonymous sections - * from configurations. - * - * It uses uci_fixup_section() from list.c and then adds delta changes. - */ -static void -uci_fixup_sections(struct uci_context *ctx, struct uci_package *p) -{ - struct uci_element *e; - struct uci_section *s; - - uci_foreach_element(&p->sections, e) { - s = uci_to_section(e); - s->package->name_index++; - uci_fixup_section(ctx, s); - s->anonymous = false; - } -} - static int uci_fill_ptr(struct uci_context *ctx, struct uci_ptr *ptr, struct uci_element *e) { @@ -431,6 +410,7 @@ static void uci_parse_config(struct uci_context *ctx) char *name; char *type; + uci_fixup_section(ctx, ctx->pctx->section); if (!ctx->pctx->package) { if (!ctx->pctx->name) uci_parse_error(ctx, "attempting to import a file without a package name"); @@ -626,7 +606,8 @@ static void uci_export_package(struct uci_package *p, FILE *stream, bool header) uci_foreach_element(&p->sections, s) { struct uci_section *sec = uci_to_section(s); fprintf(stream, "\nconfig %s", uci_escape(ctx, sec->type)); - fprintf(stream, " '%s'", uci_escape(ctx, sec->e.name)); + if (!sec->anonymous || (ctx->flags & UCI_FLAG_EXPORT_NAME)) + fprintf(stream, " '%s'", uci_escape(ctx, sec->e.name)); fprintf(stream, "\n"); uci_foreach_element(&sec->options, o) { struct uci_option *opt = uci_to_option(o); @@ -710,6 +691,7 @@ error: UCI_THROW(ctx, ctx->err); } + uci_fixup_section(ctx, ctx->pctx->section); if (!pctx->package && name) uci_switch_config(ctx); if (package) @@ -717,7 +699,6 @@ error: if (pctx->merge) pctx->package = NULL; - uci_fixup_sections(ctx, *package); pctx->name = NULL; uci_switch_config(ctx); @@ -903,7 +884,6 @@ static struct uci_package *uci_file_load(struct uci_context *ctx, const char *na char *filename; bool confdir; FILE *file = NULL; - size_t n_change; switch (name[0]) { case '.': @@ -933,8 +913,7 @@ static struct uci_package *uci_file_load(struct uci_context *ctx, const char *na if (package) { package->path = filename; package->has_delta = confdir; - n_change = uci_load_delta(ctx, package, false); - package->name_index += n_change; + uci_load_delta(ctx, package, false); } done: diff --git a/list.c b/list.c index 2b859a6..321861c 100644 --- a/list.c +++ b/list.c @@ -150,7 +150,7 @@ __private void uci_fixup_section(struct uci_context *ctx, struct uci_section *s) struct uci_element *e; char buf[16]; - if (!s || !s->anonymous) + if (!s || s->e.name) return; /* @@ -175,7 +175,7 @@ __private void uci_fixup_section(struct uci_context *ctx, struct uci_section *s) break; } } - sprintf(buf, "cfg%02x%04x", s->package->name_index, hash % (1 << 16)); + sprintf(buf, "cfg%02x%04x", ++s->package->n_section, hash % (1 << 16)); s->e.name = uci_strdup(ctx, buf); } @@ -274,7 +274,7 @@ uci_lookup_list(struct uci_list *list, const char *name) struct uci_element *e; uci_foreach_element(list, e) { - if (e->name && !strcmp(e->name, name)) + if (!strcmp(e->name, name)) return e; } return NULL; diff --git a/test/references/show_parsing_multiline_package.result b/test/references/show_parsing_multiline_package.result index c199ca5..218082d 100644 --- a/test/references/show_parsing_multiline_package.result +++ b/test/references/show_parsing_multiline_package.result @@ -1,5 +1,5 @@ -sockd.cfg01ca82=main -sockd.cfg01ca82.version='1.4.1' +sockd.@main[0]=main +sockd.@main[0].version='1.4.1' sockd.instance0=sockd sockd.instance0.enabled='1' sockd.instance0.internal_network='vpn' diff --git a/uci.h b/uci.h index eea7303..c5583ed 100644 --- a/uci.h +++ b/uci.h @@ -370,7 +370,7 @@ enum uci_option_type { enum uci_flags { UCI_FLAG_STRICT = (1 << 0), /* strict mode for the parser */ UCI_FLAG_PERROR = (1 << 1), /* print parser error messages */ - UCI_FLAG_EXPORT_NAME = (1 << 2), /* when exporting, name unnamed sections [unused] */ + UCI_FLAG_EXPORT_NAME = (1 << 2), /* when exporting, name unnamed sections */ UCI_FLAG_SAVED_DELTA = (1 << 3), /* store the saved delta in memory as well */ }; @@ -435,7 +435,6 @@ struct uci_package struct uci_backend *backend; void *priv; int n_section; - int name_index; struct uci_list delta; struct uci_list saved_delta; }; -- 2.25.1