From: Willy Tarreau Date: Tue, 26 Jan 2010 16:17:56 +0000 (+0100) Subject: [MINOR] pattern: make the converter more flexible by supporting void* and int args X-Git-Tag: v1.4-rc1~43 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1a51b6342e268de8d6ff961c61008c536676b3cd;p=thirdparty%2Fhaproxy.git [MINOR] pattern: make the converter more flexible by supporting void* and int args 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. --- diff --git a/include/types/pattern.h b/include/types/pattern.h index c6f8ec8a59..811625e79e 100644 --- a/include/types/pattern.h +++ b/include/types/pattern.h @@ -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 */ diff --git a/src/pattern.c b/src/pattern.c index c593404107..a5cb31f3a6 100644 --- a/src/pattern.c +++ b/src/pattern.c @@ -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;