]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] pattern: make the converter more flexible by supporting void* and int args
authorWilly Tarreau <w@1wt.eu>
Tue, 26 Jan 2010 16:17:56 +0000 (17:17 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 26 Jan 2010 16:17:56 +0000 (17:17 +0100)
The pattern type converters currently support a string arg and a length.
Sometimes we'll prefer to pass them a list or a structure. So let's convert
the string and length into a generic void* and int that each converter may
use as it likes.

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

index c6f8ec8a59709a927d9f2872268d768aa6f87ac0..811625e79e702906baa21e8fc761d16c76d3ab3a 100644 (file)
@@ -54,8 +54,8 @@ struct pattern {
 /* pattern conversion */
 struct pattern_conv {
        const char *kw;                           /* configuration keyword  */
-       int (*process)(const char *arg,
-                      int arg_len,
+       int (*process)(const void *arg_p,
+                      int arg_i,
                       union pattern_data *data); /* process function */
        unsigned int in_type;                     /* input needed pattern type */
        unsigned int out_type;                    /* output pattern type */
@@ -65,8 +65,8 @@ struct pattern_conv {
 struct pattern_conv_expr {
        struct list list;                         /* member of a pattern expression */
        struct pattern_conv *conv;                /* pattern conversion */
-       char *arg;                                /* configured keyword argument */
-       int arg_len;                              /* configured keyword argument length */
+       void *arg_p;                              /* pointer arg, most often a string argument */
+       int arg_i;                                /* int arg, most often the argument's length */
 };
 
 /* pattern fetch */
index c593404107d5348314d799f3d31c41e9d1ecd58f..a5cb31f3a6019d7c2b59ec7dcf04ac60055910f6 100644 (file)
@@ -432,10 +432,9 @@ struct pattern_expr *pattern_parse_expr(char **str, int *idx)
                conv_expr->conv = conv;
 
                if (end != endw) {
-                       conv_expr->arg_len = end - endw - 2;
-                       conv_expr->arg = malloc(conv_expr->arg_len + 1);
-                       conv_expr->arg = memcpy(conv_expr->arg, endw + 1, conv_expr->arg_len);
-                       conv_expr->arg[expr->arg_len] = '\0';
+                       conv_expr->arg_i = end - endw - 2;
+                       conv_expr->arg_p = calloc(1, conv_expr->arg_i + 1);
+                       memcpy(conv_expr->arg_p, endw + 1, conv_expr->arg_i);
                }
        }
        return expr;
@@ -471,7 +470,7 @@ struct pattern *pattern_process(struct proxy *px, struct session *l4, void *l7,
                        return NULL;
 
                p->type = conv_expr->conv->in_type;
-               if (!conv_expr->conv->process(conv_expr->arg, conv_expr->arg_len, &p->data))
+               if (!conv_expr->conv->process(conv_expr->arg_p, conv_expr->arg_i, &p->data))
                        return NULL;
 
                p->type = conv_expr->conv->out_type;
@@ -532,7 +531,7 @@ int pattern_notusable_key(struct pattern_expr *expr, unsigned long table_type)
 /*    Pattern format convert functions                           */
 /*****************************************************************/
 
-static int pattern_conv_str2lower(const char *arg, int arg_len, union pattern_data *data)
+static int pattern_conv_str2lower(const void *arg_p, int arg_i, union pattern_data *data)
 {
        int i;
 
@@ -543,7 +542,7 @@ static int pattern_conv_str2lower(const char *arg, int arg_len, union pattern_da
        return 1;
 }
 
-static int pattern_conv_str2upper(const char *arg, int arg_len, union pattern_data *data)
+static int pattern_conv_str2upper(const void *arg_p, int arg_i, union pattern_data *data)
 {
        int i;