]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: sample: add len converter
authorEtienne Carriere <etienne.carriere@datadome.co>
Wed, 13 Dec 2017 12:41:34 +0000 (13:41 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 14 Dec 2017 13:36:10 +0000 (14:36 +0100)
Add len converter that returns the length of a string

doc/configuration.txt
src/sample.c

index 208c11e51f5f8999bface7cae7f40a7979d5eec0..a9587129bc30262f88677f4dbe2f4253c0ebe0e3 100644 (file)
@@ -12941,6 +12941,11 @@ language(<value>[,<default>])
     use_backend english if en
     default_backend choose_your_language
 
+len
+  Get the length of the string. This can only be placed after a string
+  sample fetch function or after a transformation keyword returning a string
+  type. The result is of type integer.
+
 lower
   Convert a string sample to lower case. This can only be placed after a string
   sample fetch function or after a transformation keyword returning a string
index f9c1ff4e47d3e19769b43875f681ae74da09b1c1..213dd317bc08fa1f00e9f49e73785299806f9e75 100644 (file)
@@ -1568,6 +1568,15 @@ static int sample_conv_djb2(const struct arg *arg_p, struct sample *smp, void *p
        return 1;
 }
 
+static int sample_conv_strlen(const struct arg *arg_p, struct sample *smp, void *private)
+{
+       int i = smp->data.u.str.len;
+       smp->data.u.sint = i;
+       smp->data.type = SMP_T_SINT;
+       return 1;
+}
+
+
 static int sample_conv_str2lower(const struct arg *arg_p, struct sample *smp, void *private)
 {
        int i;
@@ -2787,6 +2796,7 @@ static struct sample_conv_kw_list sample_conv_kws = {ILH, {
        { "base64", sample_conv_bin2base64,0,            NULL, SMP_T_BIN,  SMP_T_STR  },
        { "upper",  sample_conv_str2upper, 0,            NULL, SMP_T_STR,  SMP_T_STR  },
        { "lower",  sample_conv_str2lower, 0,            NULL, SMP_T_STR,  SMP_T_STR  },
+       { "len",    sample_conv_strlen,    0,            NULL, SMP_T_STR,  SMP_T_SINT },
        { "hex",    sample_conv_bin2hex,   0,            NULL, SMP_T_BIN,  SMP_T_STR  },
        { "hex2i",  sample_conv_hex2int,   0,            NULL, SMP_T_STR,  SMP_T_SINT },
        { "ipmask", sample_conv_ipmask,    ARG1(1,MSK4), NULL, SMP_T_IPV4, SMP_T_IPV4 },