mirror of
https://github.com/haproxy/haproxy.git
synced 2026-02-20 00:10:41 -05:00
[MINOR] pattern: add support for argument parsers for converters
Some converters will need one or several arguments. It's not possible to write a simple generic parser for that, so let's add the ability for each converter to support its own argument parser, and call it to get the arguments when it's specified. If unspecified, the arguments are passed unmodified as string+len.
This commit is contained in:
parent
2937c0dd20
commit
9e92d327f7
2 changed files with 15 additions and 3 deletions
|
|
@ -59,6 +59,9 @@ struct pattern_conv {
|
|||
union pattern_data *data); /* process function */
|
||||
unsigned int in_type; /* input needed pattern type */
|
||||
unsigned int out_type; /* output pattern type */
|
||||
int (*parse_args)(const char *arg_str,
|
||||
void **arg_p,
|
||||
int *arg_i); /* argument parser. Can be NULL. */
|
||||
};
|
||||
|
||||
/* pattern conversion expression */
|
||||
|
|
|
|||
|
|
@ -432,9 +432,18 @@ struct pattern_expr *pattern_parse_expr(char **str, int *idx)
|
|||
conv_expr->conv = conv;
|
||||
|
||||
if (end != endw) {
|
||||
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);
|
||||
int i = end - endw - 2;
|
||||
char *p = my_strndup(endw + 1, i);
|
||||
|
||||
if (conv->parse_args) {
|
||||
i = conv->parse_args(p, &conv_expr->arg_p, &conv_expr->arg_i);
|
||||
free(p);
|
||||
if (!i)
|
||||
goto out_error;
|
||||
} else {
|
||||
conv_expr->arg_i = i;
|
||||
conv_expr->arg_p = p;
|
||||
}
|
||||
}
|
||||
}
|
||||
return expr;
|
||||
|
|
|
|||
Loading…
Reference in a new issue