From 230c1570ac43989b8851142dceb0a3ffed1458cc Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Wed, 17 Jul 2024 16:54:45 +0200 Subject: [PATCH] MEDIUM: vars: Be able to retrieve variable of the parent stream, if any It is now possible to retrieved the value of a variable using the parent stream or the parent session instead of the current one. It remains forbidden to set or unset this value. The sample fetch used to store the result is a local copy. So it may be safely altered by a converter without changing the value of the original variable. Note that for now, the parent of a stream is never set. So this part is not really used. This will change with the SPOE. --- src/vars.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/vars.c b/src/vars.c index 4206e71fb7..0e2029de77 100644 --- a/src/vars.c +++ b/src/vars.c @@ -64,6 +64,13 @@ static inline struct vars *get_vars(struct session *sess, struct stream *strm, c if (!desc) return NULL; + if (desc->flags & VDF_PARENT_CTX) { + if (!strm || !strm->parent) + return NULL; + strm = strm->parent; + sess = strm_sess(strm); + } + switch (desc->scope) { case SCOPE_PROC: return &proc_vars; @@ -758,9 +765,6 @@ int vars_get_by_name(const char *name, size_t len, struct sample *smp, const str if (!vars_fill_desc(name, len, &desc, NULL)) return 0; - if (desc.flags & VDF_PARENT_CTX) - return 0; - /* Select "vars" pool according with the scope. */ vars = get_vars(smp->sess, smp->strm, &desc); if (!vars || vars->scope != desc.scope) @@ -786,9 +790,6 @@ int vars_get_by_desc(const struct var_desc *var_desc, struct sample *smp, const { struct vars *vars; - if (var_desc->flags & VDF_PARENT_CTX) - return 0; - /* Select "vars" pool according with the scope. */ vars = get_vars(smp->sess, smp->strm, var_desc);