diff --git a/include/haproxy/vars.h b/include/haproxy/vars.h index f809c62d5..0647cf346 100644 --- a/include/haproxy/vars.h +++ b/include/haproxy/vars.h @@ -34,11 +34,11 @@ void var_accounting_diff(struct vars *vars, struct session *sess, struct stream unsigned int var_clear(struct var *var); void vars_prune(struct vars *vars, struct session *sess, struct stream *strm); void vars_prune_per_sess(struct vars *vars); -int vars_get_by_name(const char *name, size_t len, struct sample *smp); +int vars_get_by_name(const char *name, size_t len, struct sample *smp, const struct buffer *def); int vars_set_by_name_ifexist(const char *name, size_t len, struct sample *smp); int vars_set_by_name(const char *name, size_t len, struct sample *smp); int vars_unset_by_name_ifexist(const char *name, size_t len, struct sample *smp); -int vars_get_by_desc(const struct var_desc *var_desc, struct sample *smp); +int vars_get_by_desc(const struct var_desc *var_desc, struct sample *smp, const struct buffer *def); int vars_check_arg(struct arg *arg, char **err); #endif diff --git a/src/hlua.c b/src/hlua.c index 039ebeca7..72d232491 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -4382,7 +4382,7 @@ __LJMP static int hlua_applet_tcp_get_var(lua_State *L) s = luactx->htxn.s; smp_set_owner(&smp, s->be, s->sess, s, 0); - if (!vars_get_by_name(name, len, &smp)) { + if (!vars_get_by_name(name, len, &smp, NULL)) { lua_pushnil(L); return 1; } @@ -4869,7 +4869,7 @@ __LJMP static int hlua_applet_http_get_var(lua_State *L) s = luactx->htxn.s; smp_set_owner(&smp, s->be, s->sess, s, 0); - if (!vars_get_by_name(name, len, &smp)) { + if (!vars_get_by_name(name, len, &smp, NULL)) { lua_pushnil(L); return 1; } @@ -6966,7 +6966,7 @@ __LJMP static int hlua_get_var(lua_State *L) name = MAY_LJMP(luaL_checklstring(L, 2, &len)); smp_set_owner(&smp, htxn->p, htxn->s->sess, htxn->s, htxn->dir & SMP_OPT_DIR); - if (!vars_get_by_name(name, len, &smp)) { + if (!vars_get_by_name(name, len, &smp, NULL)) { lua_pushnil(L); return 1; } diff --git a/src/sample.c b/src/sample.c index a0727d236..e4bb3182a 100644 --- a/src/sample.c +++ b/src/sample.c @@ -1747,7 +1747,7 @@ static inline int sample_conv_var2smp_str(const struct arg *arg, struct sample * smp->flags = SMP_F_CONST; return 1; case ARGT_VAR: - if (!vars_get_by_desc(&arg->data.var, smp)) + if (!vars_get_by_desc(&arg->data.var, smp, NULL)) return 0; if (!sample_casts[smp->data.type][SMP_T_STR]) return 0; @@ -2990,7 +2990,7 @@ static inline int sample_conv_var2smp(const struct arg *arg, struct sample *smp) smp->data.u.sint = arg->data.sint; return 1; case ARGT_VAR: - if (!vars_get_by_desc(&arg->data.var, smp)) + if (!vars_get_by_desc(&arg->data.var, smp, NULL)) return 0; if (!sample_casts[smp->data.type][SMP_T_SINT]) return 0; @@ -3317,7 +3317,7 @@ static int sample_conv_concat(const struct arg *arg_p, struct sample *smp, void * into a string. */ smp_set_owner(&tmp, smp->px, smp->sess, smp->strm, smp->opt); - if (arg_p[1].type == ARGT_VAR && vars_get_by_desc(&arg_p[1].data.var, &tmp) && + if (arg_p[1].type == ARGT_VAR && vars_get_by_desc(&arg_p[1].data.var, &tmp, NULL) && (sample_casts[tmp.data.type][SMP_T_STR] == c_none || sample_casts[tmp.data.type][SMP_T_STR](&tmp))) { @@ -3377,7 +3377,7 @@ static int sample_conv_strcmp(const struct arg *arg_p, struct sample *smp, void smp_set_owner(&tmp, smp->px, smp->sess, smp->strm, smp->opt); if (arg_p[0].type != ARGT_VAR) return 0; - if (!vars_get_by_desc(&arg_p[0].data.var, &tmp)) + if (!vars_get_by_desc(&arg_p[0].data.var, &tmp, NULL)) return 0; if (!sample_casts[tmp.data.type][SMP_T_STR](&tmp)) return 0; @@ -3415,7 +3415,7 @@ static int sample_conv_secure_memcmp(const struct arg *arg_p, struct sample *smp smp_set_owner(&tmp, smp->px, smp->sess, smp->strm, smp->opt); if (arg_p[0].type != ARGT_VAR) return 0; - if (!vars_get_by_desc(&arg_p[0].data.var, &tmp)) + if (!vars_get_by_desc(&arg_p[0].data.var, &tmp, NULL)) return 0; if (!sample_casts[tmp.data.type][SMP_T_BIN](&tmp)) return 0; diff --git a/src/vars.c b/src/vars.c index 236466b21..df421f71e 100644 --- a/src/vars.c +++ b/src/vars.c @@ -340,7 +340,7 @@ static int smp_fetch_var(const struct arg *args, struct sample *smp, const char { const struct var_desc *var_desc = &args[0].data.var; - return vars_get_by_desc(var_desc, smp); + return vars_get_by_desc(var_desc, smp, NULL); } /* This function search in the
a variable with the same @@ -574,10 +574,11 @@ int vars_unset_by_name_ifexist(const char *name, size_t len, struct sample *smp) * release the variables lock ASAP (so a pre-allocated chunk is obtained * via get_trash_shunk()). The variables' lock is used for reads. * - * The function returns 0 if the variable was not found, otherwise 1 - * with the sample filled. + * The function returns 0 if the variable was not found and no default + * value was provided in