integer.
:param boolean ifexist: If this parameter is set to a truthy value the variable
will only be set if it was defined elsewhere (i.e. used
- within the configuration). It is highly recommended to
- always set this to true.
+ within the configuration). For global variables (using the
+ "proc" scope), they will only be updated and never created.
+ It is highly recommended to always set this to true.
.. js:function:: TXN.unset_var(TXN, var)
integer.
:param boolean ifexist: If this parameter is set to a truthy value the variable
will only be set if it was defined elsewhere (i.e. used
- within the configuration). It is highly recommended to
+ within the configuration). For global variables (using the
+ "proc" scope), they will only be updated and never created.
+ It is highly recommended to
always set this to true.
:see: :js:func:`AppletHTTP.unset_var`
:see: :js:func:`AppletHTTP.get_var`
integer.
:param boolean ifexist: If this parameter is set to a truthy value the variable
will only be set if it was defined elsewhere (i.e. used
- within the configuration). It is highly recommended to
+ within the configuration). For global variables (using the
+ "proc" scope), they will only be updated and never created.
+ It is highly recommended to
always set this to true.
:see: :js:func:`AppletTCP.unset_var`
:see: :js:func:`AppletTCP.get_var`
* and the stream may be NULL when scope is SCOPE_SESS. In case there wouldn't
* be enough memory to store the sample while the variable was already created,
* it would be changed to a bool (which is memory-less).
+ *
+ * Flags is a bitfield that may contain one of the following flags:
+ * - VF_UPDATEONLY: if the scope is SCOPE_PROC, the variable may only be
+ * updated but not created.
+ *
* It returns 0 on failure, non-zero on success.
*/
-static int var_set(const char *name, enum vars_scope scope, struct sample *smp)
+static int var_set(const char *name, enum vars_scope scope, struct sample *smp, uint flags)
{
struct vars *vars;
struct var *var;
-var->data.u.meth.str.data);
}
} else {
+ /* creation permitted for proc ? */
+ if (flags & VF_UPDATEONLY && scope == SCOPE_PROC)
+ goto unlock;
+
/* Check memory available. */
if (!var_accounting_add(vars, smp->sess, smp->strm, sizeof(struct var)))
goto unlock;
/* Returns 0 if fails, else returns 1. */
static int smp_conv_store(const struct arg *args, struct sample *smp, void *private)
{
- return var_set(args[0].data.var.name, args[0].data.var.scope, smp);
+ return var_set(args[0].data.var.name, args[0].data.var.scope, smp, 0);
}
/* Returns 0 if fails, else returns 1. */
if (!name)
return 0;
- return var_set(name, scope, smp);
+ return var_set(name, scope, smp, VF_UPDATEONLY);
}
if (!name)
return 0;
- return var_set(name, scope, smp);
+ return var_set(name, scope, smp, 0);
}
/* This function unset a variable if it was already defined.
smp_set_owner(&smp, px, sess, s, 0);
smp.data.type = SMP_T_STR;
smp.data.u.str = *fmtstr;
- var_set(rule->arg.vars.name, rule->arg.vars.scope, &smp);
+ var_set(rule->arg.vars.name, rule->arg.vars.scope, &smp, 0);
}
else {
/* an expression is used */
}
/* Store the sample, and ignore errors. */
- var_set(rule->arg.vars.name, rule->arg.vars.scope, &smp);
+ var_set(rule->arg.vars.name, rule->arg.vars.scope, &smp, 0);
free_trash_chunk(fmtstr);
return ACT_RET_CONT;
}