HA_RWLOCK_INIT(&vars->rwlock);
}
-/* This function returns a hash value and a scope for a variable name of a
- * specified length. It makes sure that the scope is valid. It returns non-zero
- * on success, 0 on failure. Neither hash nor scope may be NULL.
+/* This function returns the description (a var_desc structure) of a variable
+ * name of a specified length. It makes sure that the scope is valid. It fills
+ * <desc> passed as parameter and returns non-zero on success, 0 on
+ * failure. Neither hash nor scope may be NULL.
*/
-static int vars_hash_name(const char *name, int len, enum vars_scope *scope,
- uint64_t *hash, char **err)
+static int vars_fill_desc(const char *name, int len, struct var_desc *desc, char **err)
{
const char *tmp;
- /* Check length. */
- if (len == 0) {
+ /* Check name and length. */
+ if (name == NULL || len == 0) {
memprintf(err, "Empty variable name cannot be accepted");
return 0;
}
+ /* Check desc */
+ if (desc == NULL) {
+ memprintf(err, "Invalid variable description");
+ return 0;
+ }
/* Check scope. */
if (len > 5 && strncmp(name, "proc.", 5) == 0) {
}
}
- *hash = XXH3(name, len, var_name_hash_seed);
+ desc->name_hash = XXH3(name, len, var_name_hash_seed);
return 1;
}
*/
int vars_check_arg(struct arg *arg, char **err)
{
- enum vars_scope scope;
struct sample empty_smp = { };
- uint64_t hash;
+ struct var_desc desc;
/* Check arg type. */
if (arg->type != ARGT_STR) {
}
/* Register new variable name. */
- if (!vars_hash_name(arg->data.str.area, arg->data.str.data, &scope, &hash, err))
+ if (!vars_fill_desc(arg->data.str.area, arg->data.str.data, &desc, err))
return 0;
- if (scope == SCOPE_PROC && !var_set(hash, scope, &empty_smp, VF_CREATEONLY|VF_PERMANENT))
+ if (desc.scope == SCOPE_PROC && !var_set(desc.name_hash, desc.scope, &empty_smp, VF_CREATEONLY|VF_PERMANENT))
return 0;
/* properly destroy the chunk */
/* Use the global variable name pointer. */
arg->type = ARGT_VAR;
- arg->data.var.name_hash = hash;
- arg->data.var.scope = scope;
+ arg->data.var = desc;
return 1;
}
*/
int vars_set_by_name_ifexist(const char *name, size_t len, struct sample *smp)
{
- enum vars_scope scope;
- uint64_t hash;
+ struct var_desc desc;
/* Resolve name and scope. */
- if (!vars_hash_name(name, len, &scope, &hash, NULL))
+ if (!vars_fill_desc(name, len, &desc, NULL))
return 0;
/* Variable creation is allowed for all scopes apart from the PROC one. */
- return var_set(hash, scope, smp, (scope == SCOPE_PROC) ? VF_COND_IFEXISTS : 0);
+ return var_set(desc.name_hash, desc.scope, smp, (desc.scope == SCOPE_PROC) ? VF_COND_IFEXISTS : 0);
}
*/
int vars_set_by_name(const char *name, size_t len, struct sample *smp)
{
- enum vars_scope scope;
- uint64_t hash;
+ struct var_desc desc;
/* Resolve name and scope. */
- if (!vars_hash_name(name, len, &scope, &hash, NULL))
+ if (!vars_fill_desc(name, len, &desc, NULL))
return 0;
- return var_set(hash, scope, smp, 0);
+ return var_set(desc.name_hash, desc.scope, smp, 0);
}
/* This function unsets a variable if it was already defined.
*/
int vars_unset_by_name_ifexist(const char *name, size_t len, struct sample *smp)
{
- enum vars_scope scope;
- uint64_t hash;
+ struct var_desc desc;
/* Resolve name and scope. */
- if (!vars_hash_name(name, len, &scope, &hash, NULL))
+ if (!vars_fill_desc(name, len, &desc, NULL))
return 0;
- return var_unset(hash, scope, smp);
+ return var_unset(desc.name_hash, desc.scope, smp);
}
int vars_get_by_name(const char *name, size_t len, struct sample *smp, const struct buffer *def)
{
struct vars *vars;
- enum vars_scope scope;
- uint64_t hash;
+ struct var_desc desc;
/* Resolve name and scope. */
- if (!vars_hash_name(name, len, &scope, &hash, NULL))
+ if (!vars_fill_desc(name, len, &desc, NULL))
return 0;
/* Select "vars" pool according with the scope. */
- vars = get_vars(smp->sess, smp->strm, scope);
- if (!vars || vars->scope != scope)
+ vars = get_vars(smp->sess, smp->strm, desc.scope);
+ if (!vars || vars->scope != desc.scope)
return 0;
- return var_to_smp(vars, hash, smp, def);
+ return var_to_smp(vars, desc.name_hash, smp, def);
}
/* This function fills a sample with the content of the variable described
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_hash, rule->arg.vars.scope, &smp, rule->arg.vars.conditions);
+ var_set(rule->arg.vars.desc.name_hash, rule->arg.vars.desc.scope, &smp, rule->arg.vars.conditions);
}
else {
/* an expression is used */
}
/* Store the sample, and ignore errors. */
- var_set(rule->arg.vars.name_hash, rule->arg.vars.scope, &smp, rule->arg.vars.conditions);
+ var_set(rule->arg.vars.desc.name_hash, rule->arg.vars.desc.scope, &smp, rule->arg.vars.conditions);
free_trash_chunk(fmtstr);
return ACT_RET_CONT;
}
smp_set_owner(&smp, px, sess, s, SMP_OPT_FINAL);
/* Clear the variable using the sample context, and ignore errors. */
- var_unset(rule->arg.vars.name_hash, rule->arg.vars.scope, &smp);
+ var_unset(rule->arg.vars.desc.name_hash, rule->arg.vars.desc.scope, &smp);
return ACT_RET_CONT;
}
}
lf_expr_init(&rule->arg.vars.fmt);
- if (!vars_hash_name(var_name, var_len, &rule->arg.vars.scope, &rule->arg.vars.name_hash, err))
+ if (!vars_fill_desc(var_name, var_len, &rule->arg.vars.desc, err))
return ACT_RET_PRS_ERR;
- if (rule->arg.vars.scope == SCOPE_PROC &&
- !var_set(rule->arg.vars.name_hash, rule->arg.vars.scope, &empty_smp, VF_CREATEONLY|VF_PERMANENT))
+ if (rule->arg.vars.desc.scope == SCOPE_PROC &&
+ !var_set(rule->arg.vars.desc.name_hash, rule->arg.vars.desc.scope, &empty_smp, VF_CREATEONLY|VF_PERMANENT))
return 0;
/* There is no fetch method when variable is unset. Just set the right
.flags = PR_FL_CHECKED,
};
struct act_rule rule = {
- .arg.vars.scope = SCOPE_PROC,
+ .arg.vars.desc.scope = SCOPE_PROC,
.from = ACT_F_CFG_PARSER,
.conf = { .file = (char *)file, .line = line, },
};
if (p_ret != ACT_RET_PRS_OK)
goto end;
- if (rule.arg.vars.scope != SCOPE_PROC) {
+ if (rule.arg.vars.desc.scope != SCOPE_PROC) {
memprintf(err, "'%s': cannot set variable '%s', only scope 'proc' is permitted in the global section.", args[0], args[1]);
goto end;
}
.flags = PR_FL_CHECKED,
};
struct act_rule rule = {
- .arg.vars.scope = SCOPE_PROC,
+ .arg.vars.desc.scope = SCOPE_PROC,
.from = ACT_F_CLI_PARSER,
.conf = { .file = "CLI", .line = 0, },
};
if (p_ret != ACT_RET_PRS_OK)
goto fail;
- if (rule.arg.vars.scope != SCOPE_PROC) {
+ if (rule.arg.vars.desc.scope != SCOPE_PROC) {
memprintf(&err, "'%s %s': cannot set variable '%s', only scope 'proc' is permitted here.", args[0], args[1], args[2]);
goto fail;
}