From: Willy Tarreau Date: Thu, 25 Jul 2013 10:17:57 +0000 (+0200) Subject: CLEANUP: acl: move the 3 remaining sample fetches to samples.c X-Git-Tag: v1.5-dev20~327 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5b8ad22228d95adf8aaf3bdb79fa07f447adff1b;p=thirdparty%2Fhaproxy.git CLEANUP: acl: move the 3 remaining sample fetches to samples.c There is no more reason for having "always_true", "always_false" and "env" in acl.c while they're the most basic sample fetch keywords, so let's move them to sample.c where it's easier to find them. --- diff --git a/src/acl.c b/src/acl.c index 845e1de1e9..b069d39c85 100644 --- a/src/acl.c +++ b/src/acl.c @@ -1956,68 +1956,10 @@ int init_acl() return err; } -/************************************************************************/ -/* All supported sample fetch functions must be declared here */ -/************************************************************************/ - -/* force TRUE to be returned at the fetch level */ -static int -smp_fetch_true(struct proxy *px, struct session *s, void *l7, unsigned int opt, - const struct arg *args, struct sample *smp) -{ - smp->type = SMP_T_BOOL; - smp->data.uint = 1; - return 1; -} - -/* force FALSE to be returned at the fetch level */ -static int -smp_fetch_false(struct proxy *px, struct session *s, void *l7, unsigned int opt, - const struct arg *args, struct sample *smp) -{ - smp->type = SMP_T_BOOL; - smp->data.uint = 0; - return 1; -} - -/* retrieve environment variable $1 as a string */ -static int -smp_fetch_env(struct proxy *px, struct session *s, void *l7, unsigned int opt, - const struct arg *args, struct sample *smp) -{ - char *env; - - if (!args || args[0].type != ARGT_STR) - return 0; - - env = getenv(args[0].data.str.str); - if (!env) - return 0; - - smp->type = SMP_T_CSTR; - smp->data.str.str = env; - smp->data.str.len = strlen(env); - return 1; -} - - /************************************************************************/ /* All supported sample and ACL keywords must be declared here. */ /************************************************************************/ -/* Note: must not be declared as its list will be overwritten. - * Note: fetches that may return multiple types must be declared as the lowest - * common denominator, the type that can be casted into all other ones. For - * instance IPv4/IPv6 must be declared IPv4. - */ -static struct sample_fetch_kw_list smp_kws = {ILH, { - { "always_false", smp_fetch_false, 0, NULL, SMP_T_BOOL, SMP_USE_INTRN }, - { "always_true", smp_fetch_true, 0, NULL, SMP_T_BOOL, SMP_USE_INTRN }, - { "env", smp_fetch_env, ARG1(1,STR), NULL, SMP_T_CSTR, SMP_USE_INTRN }, - { /* END */ }, -}}; - - /* Note: must not be declared as its list will be overwritten. * Please take care of keeping this list alphabetically sorted. */ @@ -2025,11 +1967,9 @@ static struct acl_kw_list acl_kws = {ILH, { { /* END */ }, }}; - __attribute__((constructor)) static void __acl_init(void) { - sample_register_fetches(&smp_kws); acl_register_keywords(&acl_kws); } diff --git a/src/sample.c b/src/sample.c index fdf5400917..607239269b 100644 --- a/src/sample.c +++ b/src/sample.c @@ -1081,6 +1081,62 @@ static int sample_conv_ipmask(const struct arg *arg_p, struct sample *smp) return 1; } +/************************************************************************/ +/* All supported sample fetch functions must be declared here */ +/************************************************************************/ + +/* force TRUE to be returned at the fetch level */ +static int +smp_fetch_true(struct proxy *px, struct session *s, void *l7, unsigned int opt, + const struct arg *args, struct sample *smp) +{ + smp->type = SMP_T_BOOL; + smp->data.uint = 1; + return 1; +} + +/* force FALSE to be returned at the fetch level */ +static int +smp_fetch_false(struct proxy *px, struct session *s, void *l7, unsigned int opt, + const struct arg *args, struct sample *smp) +{ + smp->type = SMP_T_BOOL; + smp->data.uint = 0; + return 1; +} + +/* retrieve environment variable $1 as a string */ +static int +smp_fetch_env(struct proxy *px, struct session *s, void *l7, unsigned int opt, + const struct arg *args, struct sample *smp) +{ + char *env; + + if (!args || args[0].type != ARGT_STR) + return 0; + + env = getenv(args[0].data.str.str); + if (!env) + return 0; + + smp->type = SMP_T_CSTR; + smp->data.str.str = env; + smp->data.str.len = strlen(env); + return 1; +} + +/* Note: must not be declared as its list will be overwritten. + * Note: fetches that may return multiple types must be declared as the lowest + * common denominator, the type that can be casted into all other ones. For + * instance IPv4/IPv6 must be declared IPv4. + */ +static struct sample_fetch_kw_list smp_kws = {ILH, { + { "always_false", smp_fetch_false, 0, NULL, SMP_T_BOOL, SMP_USE_INTRN }, + { "always_true", smp_fetch_true, 0, NULL, SMP_T_BOOL, SMP_USE_INTRN }, + { "env", smp_fetch_env, ARG1(1,STR), NULL, SMP_T_CSTR, SMP_USE_INTRN }, + { /* END */ }, +}}; + /* Note: must not be declared as its list will be overwritten */ static struct sample_conv_kw_list sample_conv_kws = {ILH, { { "upper", sample_conv_str2upper, 0, NULL, SMP_T_STR, SMP_T_STR }, @@ -1092,6 +1148,7 @@ static struct sample_conv_kw_list sample_conv_kws = {ILH, { __attribute__((constructor)) static void __sample_init(void) { - /* register sample format convert keywords */ + /* register sample fetch and format conversion keywords */ + sample_register_fetches(&smp_kws); sample_register_convs(&sample_conv_kws); }