]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: sample: add cut_crlf converter
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 1 Apr 2020 14:21:44 +0000 (16:21 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 27 Apr 2020 07:39:37 +0000 (09:39 +0200)
This converter cuts a string on the first \r or \n found.

doc/configuration.txt
src/sample.c

index 7c2d838066d18155c2bb5fca7ae62d2f7b4b9a52..df4465cafe012209033b844fa0cde8c954953196 100644 (file)
@@ -14036,6 +14036,11 @@ crc32c([<avalanche>])
   not be used for security purposes as a 32-bit hash is trivial to break. See
   also "djb2", "sdbm", "wt6", "crc32" and the "hash-type" directive.
 
+cut_crlf
+  Cuts the string representation of the input sample on the first carriage
+  return ('\r') or newline ('\n') character found. Only the string length is
+  updated.
+
 da-csv-conv(<prop>[,<prop>*])
   Asks the DeviceAtlas converter to identify the User Agent string passed on
   input, and to emit a string made of the concatenation of the properties
index c28b5449e2ffdd25b3dea0d40e95b158f4c06721..43d932d84961516c317e6090c19a04d17ed344cb 100644 (file)
@@ -2979,6 +2979,21 @@ static int sample_conv_htonl(const struct arg *arg_p, struct sample *smp, void *
        return 1;
 }
 
+/**/
+static int sample_conv_cut_crlf(const struct arg *arg_p, struct sample *smp, void *private)
+{
+       char *p;
+       size_t l;
+
+       p = smp->data.u.str.area;
+       for (l = 0; l < smp->data.u.str.data; l++) {
+               if (*(p+l) == '\r' || *(p+l) == '\n')
+                       break;
+       }
+       smp->data.u.str.data = l;
+       return 1;
+}
+
 /************************************************************************/
 /*       All supported sample fetch functions must be declared here     */
 /************************************************************************/
@@ -3447,7 +3462,8 @@ static struct sample_conv_kw_list sample_conv_kws = {ILH, {
        { "mod",    sample_conv_arith_mod,  ARG1(1,STR), check_operator, SMP_T_SINT, SMP_T_SINT  },
        { "neg",    sample_conv_arith_neg,            0, NULL, SMP_T_SINT, SMP_T_SINT  },
 
-       { "htonl",  sample_conv_htonl,                0, NULL, SMP_T_SINT, SMP_T_BIN  },
+       { "htonl",    sample_conv_htonl,              0, NULL, SMP_T_SINT, SMP_T_BIN  },
+       { "cut_crlf", sample_conv_cut_crlf,           0, NULL, SMP_T_STR,  SMP_T_STR  },
        { NULL, NULL, 0, 0, 0 },
 }};