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 * The function returns 1 if the processing is ok, return 0
* if the parser fails, with <err> message filled. * 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 */ /* return the PAT_MATCH_* index for match name "name", or < 0 if not found */
static inline int pat_find_match_name(const char *name) 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; signed long long value, minor;
/* The following buffer contain two numbers, a ':' separator and the final \0. */ /* The following buffer contain two numbers, a ':' separator and the final \0. */
char buffer[NB_LLMAX_STR + 1 + NB_LLMAX_STR + 1]; 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 /* 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 * 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; if (!pattern_register(&expr->pat, arg, NULL, &pattern, patflags, err))
text[1] = "";
if (!pattern_register(&expr->pat, text, NULL, &pattern, patflags, err))
goto out_free_pattern; goto out_free_pattern;
args++; 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) { else if (strcmp(args[0], "add") == 0) {
if (strcmp(args[1], "map") == 0) { if (strcmp(args[1], "map") == 0) {
const char *params[2];
struct pattern *pat; struct pattern *pat;
struct map_entry *ent; struct map_entry *ent;
struct sample_storage *smp; struct sample_storage *smp;
@ -1931,9 +1930,6 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line)
return 1; return 1;
} }
params[0] = args[3];
params[1] = "";
/* Lookup the reference in the maps. */ /* Lookup the reference in the maps. */
appctx->ctx.map.ref = map_get_reference(args[2]); appctx->ctx.map.ref = map_get_reference(args[2]);
if (!appctx->ctx.map.ref) { if (!appctx->ctx.map.ref) {
@ -2012,7 +2008,7 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line)
else else
pat = NULL; 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); free(smp);
continue; continue;
} }

View File

@ -307,7 +307,6 @@ static int map_parse_and_index(struct map_descriptor *desc,
char **err) char **err)
{ {
struct sample_storage *smp; struct sample_storage *smp;
const char *args[2];
/* use new smp for storing value */ /* use new smp for storing value */
smp = calloc(1, sizeof(*smp)); smp = calloc(1, sizeof(*smp));
@ -322,9 +321,7 @@ static int map_parse_and_index(struct map_descriptor *desc,
} }
/* register key */ /* register key */
args[0] = ent->key; if (!pattern_register(desc->pat, ent->key, smp, pattern, patflags, err))
args[1] = "";
if (!pattern_register(desc->pat, args, smp, pattern, patflags, err))
return 0; return 0;
return 1; 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 -1 if the parser fail. The err message is filled.
* return -2 if out of memory * 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 sample_storage *smp,
struct pattern **pattern, struct pattern **pattern,
int patflags, char **err) int patflags, char **err)
@ -800,9 +800,6 @@ int pattern_register(struct pattern_expr *expr, const char **args,
int len; int len;
int ret; int ret;
/* eat args */
while (**args) {
/* we keep the previous pattern along iterations as long as it's not used */ /* we keep the previous pattern along iterations as long as it's not used */
if (!*pattern) if (!*pattern)
*pattern = (struct pattern *)malloc(sizeof(**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)); memset(*pattern, 0, sizeof(**pattern));
(*pattern)->flags = patflags; (*pattern)->flags = patflags;
ret = expr->parse(args[0], *pattern, PAT_U_COMPILE, err); ret = expr->parse(arg, *pattern, PAT_U_COMPILE, err);
if (!ret) if (!ret)
return 0; 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) { 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 the flag PAT_F_IGNORE_CASE is set, we cannot use trees */
if ((*pattern)->flags & PAT_F_IGNORE_CASE)
goto just_chain_the_pattern; goto just_chain_the_pattern;
}
/* Process the key len */ /* Process the key len */
len = strlen((*pattern)->ptr.str) + 1; 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) if (ebst_insert((*pattern)->val.tree, &node->node) != &node->node)
free(node); /* was a duplicate */ 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) { 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 */ /* Only IPv4 can be indexed */
if ((*pattern)->type != SMP_T_IPV4)
goto just_chain_the_pattern; goto just_chain_the_pattern;
}
/* in IPv4 case, check if the mask is contiguous so that we can /* in IPv4 case, check if the mask is contiguous so that we can
* insert the network into the tree. A continuous mask has only * 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) if (ebmb_insert_prefix((*pattern)->val.tree, &node->node, 4) != &node->node)
free(node); /* was a duplicate */ free(node); /* was a duplicate */
} }
/*
*
* if the parser did not feed the tree, let's chain the pattern to the list
*
*/
else { else {
just_chain_the_pattern: 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); LIST_ADDQ(&expr->patterns, &(*pattern)->list);
/* copy the pointer to sample associated to this node */ /* copy the pointer to sample associated to this node */
@ -936,7 +914,6 @@ just_chain_the_pattern:
/* get a new one */ /* get a new one */
*pattern = NULL; *pattern = NULL;
} }
}
return 1; return 1;
} }
@ -955,7 +932,6 @@ int pattern_read_from_file(struct pattern_expr *expr,
int ret = 0; int ret = 0;
int line = 0; int line = 0;
int code; int code;
const char *args[2];
file = fopen(filename, "r"); file = fopen(filename, "r");
if (!file) { if (!file) {
@ -990,10 +966,7 @@ int pattern_read_from_file(struct pattern_expr *expr,
if (c == arg) if (c == arg)
continue; continue;
args[0] = arg; code = pattern_register(expr, arg, NULL, &pattern, patflags, err);
args[1] = "";
code = pattern_register(expr, args, NULL, &pattern, patflags, err);
if (code == -2) { if (code == -2) {
memprintf(err, "out of memory when loading patterns from file <%s>", filename); memprintf(err, "out of memory when loading patterns from file <%s>", filename);
goto out_close; goto out_close;