]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: map/pattern: The sample parser is stored in the pattern
authorThierry FOURNIER <tfournier@exceliance.fr>
Wed, 15 Jan 2014 14:17:23 +0000 (15:17 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 17 Mar 2014 17:06:07 +0000 (18:06 +0100)
We cannot separe the pattern and the value. Now, the patern known the
value and the pattern is able to parsehis associated sample staroage.

include/types/map.h
include/types/pattern.h
src/dumpstats.c
src/map.c

index 4463541bdd850e81395dba0246042f188039e85d..59c1a226a38cd29737f3f154eb01526505fdc888 100644 (file)
@@ -57,8 +57,6 @@ struct map_descriptor {
        struct list list;              /* used for listing */
        struct map_reference *ref;     /* the reference used for unindexed entries */
        struct sample_conv *conv;      /* original converter descriptor */
-       int (*parse)(const char *text, /* The function that can parse the output value */
-                    struct sample_storage *smp);
        struct pattern_expr *pat;      /* the pattern matching associated to the map */
        int do_free;                   /* set if <pat> is the orignal pat and must be freed */
        char *default_value;           /* a copy of default value. This copy is
index 7b9f8fd433831e1747334deba73975db00083ec8..72022e36de1787331bfb46a3da50fbe72e6f3232 100644 (file)
@@ -155,6 +155,7 @@ struct pattern_list {
  */
 struct pattern_expr {
        int (*parse)(const char *text, struct pattern *pattern, char **err);
+       int (*parse_smp)(const char *text, struct sample_storage *smp);
        int (*index)(struct pattern_expr *, struct pattern *, char **);
        void (*delete)(struct pattern_expr *, struct pattern *);
        struct sample_storage **(*find_smp)(struct pattern_expr *, struct pattern *);
index aecce5fba756a837131ce8d332f52009ebc6a00d..8b7782e0af845925935d235d09c83fab13a9861a 100644 (file)
@@ -1613,7 +1613,7 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line)
                             stats_map_lookup_next(si)) {
                                smp = pattern_find_smp(args[3], appctx->ctx.map.desc->pat, NULL);
                                if (smp)
-                                       appctx->ctx.map.desc->parse(value, *smp);
+                                       appctx->ctx.map.desc->pat->parse_smp(value, *smp);
                        }
 
                        /* The set is done, send message. */
@@ -1974,7 +1974,7 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line)
                                 * is canceled for this 'descriptor', but continue, for
                                 * the other descriptors.
                                 */
-                               if (!appctx->ctx.map.desc->parse(ent->value, smp)) {
+                               if (!appctx->ctx.map.desc->pat->parse_smp(ent->value, smp)) {
                                        free(smp);
                                        continue;
                                }
index b595b02fb1d8c61a4456bc91c853723a82555ba3..b266614a57b46cd91bd9a93a485ffcac445d57c1 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -314,7 +314,7 @@ static int map_parse_and_index(struct map_descriptor *desc,
                return 0;
 
        /* first read and convert value */
-       if (!desc->parse(ent->value, smp)) {
+       if (!desc->pat->parse_smp(ent->value, smp)) {
                memprintf(err, "parse value failed at line %d of file <%s>",
                          ent->line, desc->ref->reference);
                return 0;
@@ -384,10 +384,10 @@ static int sample_load_map(struct arg *arg, struct sample_conv *conv, char **err
 
        /* check the output parse method */
        switch (desc->conv->out_type) {
-       case SMP_T_STR:  desc->parse = map_parse_str;  break;
-       case SMP_T_UINT: desc->parse = map_parse_int;  break;
-       case SMP_T_IPV4: desc->parse = map_parse_ip;   break;
-       case SMP_T_IPV6: desc->parse = map_parse_ip6;  break;
+       case SMP_T_STR:  desc->pat->parse_smp = map_parse_str;  break;
+       case SMP_T_UINT: desc->pat->parse_smp = map_parse_int;  break;
+       case SMP_T_IPV4: desc->pat->parse_smp = map_parse_ip;   break;
+       case SMP_T_IPV6: desc->pat->parse_smp = map_parse_ip6;  break;
        default:
                memprintf(err, "map: internal haproxy error: no default parse case for the input type <%d>.",
                          conv->out_type);
@@ -442,7 +442,7 @@ static int sample_load_map(struct arg *arg, struct sample_conv *conv, char **err
                        memprintf(err, "out of memory");
                        return 0;
                }
-               if (!desc->parse(desc->default_value, desc->def)) {
+               if (!desc->pat->parse_smp(desc->default_value, desc->def)) {
                        memprintf(err, "Cannot parse default value");
                        return 0;
                }