diff --git a/include/haproxy/sample.h b/include/haproxy/sample.h index 7e05e7840..e8694c656 100644 --- a/include/haproxy/sample.h +++ b/include/haproxy/sample.h @@ -31,6 +31,7 @@ extern sample_cast_fct sample_casts[SMP_TYPES][SMP_TYPES]; extern const unsigned int fetch_cap[SMP_SRC_ENTRIES]; extern const char *smp_to_type[SMP_TYPES]; +int type_to_smp(const char *type); struct sample_expr *sample_parse_expr(char **str, int *idx, const char *file, int line, char **err, struct arg_list *al, char **endptr); int sample_parse_expr_cnv(char **str, int *idx, char **endptr, char **err_msg, struct arg_list *al, const char *file, int line, diff --git a/src/sample.c b/src/sample.c index a7b8a23a7..cbb959161 100644 --- a/src/sample.c +++ b/src/sample.c @@ -61,6 +61,21 @@ const char *smp_to_type[SMP_TYPES] = { [SMP_T_METH] = "meth", }; +/* Returns SMP_T_* smp matching with name or SMP_TYPES if + * not found. + */ +int type_to_smp(const char *type) +{ + int it = 0; + + while (it < SMP_TYPES) { + if (!strcmp(type, smp_to_type[it])) + break; // found + it += 1; + } + return it; +} + /* static sample used in sample_process() when

is NULL */ static THREAD_LOCAL struct sample temp_smp;