MEDIUM: pattern: Change the prototype of the function pattern_register().

Each pattern parser take only one string. This change is reported to the
function prototype of the function "pattern_register()". Now, it is
called with just one string and no need to browse the array of args.
This commit is contained in:
Thierry FOURNIER 2014-01-23 17:53:31 +01:00 committed by Willy Tarreau
parent 580c32cb3a
commit 972028fa67
5 changed files with 103 additions and 140 deletions

View File

@ -40,7 +40,7 @@
* The function returns 1 if the processing is ok, return 0
* if the parser fails, with <err> message filled.
*/
int pattern_register(struct pattern_expr *expr, const char **args, struct sample_storage *smp, struct pattern **pattern, int patflags, char **err);
int pattern_register(struct pattern_expr *expr, const char *arg, struct sample_storage *smp, struct pattern **pattern, int patflags, char **err);
/* return the PAT_MATCH_* index for match name "name", or < 0 if not found */
static inline int pat_find_match_name(const char *name)

View File

@ -152,7 +152,6 @@ struct acl_expr *parse_acl_expr(const char **args, char **err, struct arg_list *
signed long long value, minor;
/* The following buffer contain two numbers, a ':' separator and the final \0. */
char buffer[NB_LLMAX_STR + 1 + NB_LLMAX_STR + 1];
const char *text[2];
/* First, we look for an ACL keyword. And if we don't find one, then
* we look for a sample fetch expression starting with a sample fetch
@ -570,9 +569,7 @@ struct acl_expr *parse_acl_expr(const char **args, char **err, struct arg_list *
}
}
text[0] = arg;
text[1] = "";
if (!pattern_register(&expr->pat, text, NULL, &pattern, patflags, err))
if (!pattern_register(&expr->pat, arg, NULL, &pattern, patflags, err))
goto out_free_pattern;
args++;
}

View File

@ -1919,7 +1919,6 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line)
}
else if (strcmp(args[0], "add") == 0) {
if (strcmp(args[1], "map") == 0) {
const char *params[2];
struct pattern *pat;
struct map_entry *ent;
struct sample_storage *smp;
@ -1931,9 +1930,6 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line)
return 1;
}
params[0] = args[3];
params[1] = "";
/* Lookup the reference in the maps. */
appctx->ctx.map.ref = map_get_reference(args[2]);
if (!appctx->ctx.map.ref) {
@ -2012,7 +2008,7 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line)
else
pat = NULL;
if (!pattern_register(appctx->ctx.map.desc->pat, params, smp, &pat, 0, NULL)) {
if (!pattern_register(appctx->ctx.map.desc->pat, args[3], smp, &pat, 0, NULL)) {
free(smp);
continue;
}

View File

@ -307,7 +307,6 @@ static int map_parse_and_index(struct map_descriptor *desc,
char **err)
{
struct sample_storage *smp;
const char *args[2];
/* use new smp for storing value */
smp = calloc(1, sizeof(*smp));
@ -322,9 +321,7 @@ static int map_parse_and_index(struct map_descriptor *desc,
}
/* register key */
args[0] = ent->key;
args[1] = "";
if (!pattern_register(desc->pat, args, smp, pattern, patflags, err))
if (!pattern_register(desc->pat, ent->key, smp, pattern, patflags, err))
return 0;
return 1;

View File

@ -790,7 +790,7 @@ void pattern_init_expr(struct pattern_expr *expr)
* return -1 if the parser fail. The err message is filled.
* return -2 if out of memory
*/
int pattern_register(struct pattern_expr *expr, const char **args,
int pattern_register(struct pattern_expr *expr, const char *arg,
struct sample_storage *smp,
struct pattern **pattern,
int patflags, char **err)
@ -800,9 +800,6 @@ int pattern_register(struct pattern_expr *expr, const char **args,
int len;
int ret;
/* eat args */
while (**args) {
/* we keep the previous pattern along iterations as long as it's not used */
if (!*pattern)
*pattern = (struct pattern *)malloc(sizeof(**pattern));
@ -814,25 +811,18 @@ int pattern_register(struct pattern_expr *expr, const char **args,
memset(*pattern, 0, sizeof(**pattern));
(*pattern)->flags = patflags;
ret = expr->parse(args[0], *pattern, PAT_U_COMPILE, err);
ret = expr->parse(arg, *pattern, PAT_U_COMPILE, err);
if (!ret)
return 0;
/* each parser return the number of args eated */
args += ret;
/*
*
* SMP_T_CSTR tree indexation
*
* The match "pat_match_str()" can use tree.
*
*/
if (expr->match == pat_match_str) {
/* SMP_T_CSTR tree indexation.
* The match "pat_match_str()" can use trees.
*/
if ((*pattern)->flags & PAT_F_IGNORE_CASE) {
/* If the flag PAT_F_IGNORE_CASE is set, we cannot use trees */
if ((*pattern)->flags & PAT_F_IGNORE_CASE)
goto just_chain_the_pattern;
}
/* Process the key len */
len = strlen((*pattern)->ptr.str) + 1;
@ -866,19 +856,14 @@ int pattern_register(struct pattern_expr *expr, const char **args,
if (ebst_insert((*pattern)->val.tree, &node->node) != &node->node)
free(node); /* was a duplicate */
}
/*
*
* SMP_T_IPV4 tree indexation
*
* The match "pat_match_ip()" can use tree.
*
*/
else if (expr->match == pat_match_ip) {
/* SMP_T_IPV4 tree indexation
* The match "pat_match_ip()" can use tree.
*/
if ((*pattern)->type != SMP_T_IPV4) {
/* Only IPv4 can be indexed */
if ((*pattern)->type != SMP_T_IPV4)
goto just_chain_the_pattern;
}
/* in IPv4 case, check if the mask is contiguous so that we can
* insert the network into the tree. A continuous mask has only
@ -918,16 +903,9 @@ int pattern_register(struct pattern_expr *expr, const char **args,
if (ebmb_insert_prefix((*pattern)->val.tree, &node->node, 4) != &node->node)
free(node); /* was a duplicate */
}
/*
*
* if the parser did not feed the tree, let's chain the pattern to the list
*
*/
else {
just_chain_the_pattern:
/* if the parser did not feed the tree, let's chain the pattern to the list */
LIST_ADDQ(&expr->patterns, &(*pattern)->list);
/* copy the pointer to sample associated to this node */
@ -936,7 +914,6 @@ just_chain_the_pattern:
/* get a new one */
*pattern = NULL;
}
}
return 1;
}
@ -955,7 +932,6 @@ int pattern_read_from_file(struct pattern_expr *expr,
int ret = 0;
int line = 0;
int code;
const char *args[2];
file = fopen(filename, "r");
if (!file) {
@ -990,10 +966,7 @@ int pattern_read_from_file(struct pattern_expr *expr,
if (c == arg)
continue;
args[0] = arg;
args[1] = "";
code = pattern_register(expr, args, NULL, &pattern, patflags, err);
code = pattern_register(expr, arg, NULL, &pattern, patflags, err);
if (code == -2) {
memprintf(err, "out of memory when loading patterns from file <%s>", filename);
goto out_close;