From 367e62c1c29e143267f40e3672d4869d79bfb58d Mon Sep 17 00:00:00 2001 From: Philip Prindeville Date: Wed, 22 Mar 2017 22:11:27 -0600 Subject: [PATCH] [core] allow overriding prior config values (fixes #2799) introduce ":=" config file syntax to replace previously set value github: closes #78 x-ref: "allow overriding configuration values" https://redmine.lighttpd.net/issues/2799 https://github.com/lighttpd/lighttpd1.4/pull/78 --- src/configfile.c | 8 ++++++++ src/configparser.y | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/configfile.c b/src/configfile.c index 179d9642..8399081e 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -967,6 +967,14 @@ static int config_tokenizer(server *srv, tokenizer_t *t, int *token_id, buffer * } break; + case ':': + if (t->input[t->offset+1] == '=') { + t->offset += 2; + tid = TK_FORCE_ASSIGN; + buffer_copy_string_len(token, CONST_STR_LEN(":=")); + } + break; + case '{': t->offset++; diff --git a/src/configparser.y b/src/configparser.y index 9def054f..66165d86 100644 --- a/src/configparser.y +++ b/src/configparser.y @@ -206,6 +206,23 @@ varline ::= key(A) ASSIGN expression(B). { A = NULL; } +varline ::= key(A) FORCE_ASSIGN expression(B). { + if (ctx->ok) { + if (strncmp(A->ptr, "env.", sizeof("env.") - 1) == 0) { + fprintf(stderr, "Setting env variable is not supported in conditional %d %s: %s\n", + ctx->current->context_ndx, + ctx->current->key->ptr, A->ptr); + ctx->ok = 0; + } else { + buffer_copy_buffer(B->key, A); + array_replace(ctx->current->value, B); + B = NULL; + } + } + buffer_free(A); + A = NULL; +} + varline ::= key(A) APPEND expression(B). { if (ctx->ok) { array *vars = ctx->current->value;