]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: acl: move the 3 remaining sample fetches to samples.c
authorWilly Tarreau <w@1wt.eu>
Thu, 25 Jul 2013 10:17:57 +0000 (12:17 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 25 Jul 2013 13:00:37 +0000 (15:00 +0200)
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.

src/acl.c
src/sample.c

index 845e1de1e981a408bcfaff9dc541439829c08f45..b069d39c855aab513eabc5e795f441e5fdfdf11e 100644 (file)
--- 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 <const> 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 <const> 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);
 }
 
index fdf5400917900afb4d4f8b0b85ad8d733afa9bdc..607239269ba1dd5e7bbeb3b8963dcb33aece8a0b 100644 (file)
@@ -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 <const> 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 <const> 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);
 }