]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: vars: Be able to retrieve variable of the parent stream, if any
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 17 Jul 2024 14:54:45 +0000 (16:54 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 18 Jul 2024 15:06:12 +0000 (17:06 +0200)
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

index 4206e71fb7c53a988d772c1f90178353eb213e0f..0e2029de77e4a7f5a527d72fb98ca0e6c6628859 100644 (file)
@@ -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);