REORG: use the name "sample" instead of "pattern" to designate extracted data

This is mainly a massive renaming in the code to get it in line with the
calling convention. Next patch will rename a few files to complete this
operation.
This commit is contained in:
Willy Tarreau 2012-04-27 21:37:17 +02:00
parent 7dcb6480db
commit 1278578487
11 changed files with 149 additions and 149 deletions

View File

@ -25,10 +25,10 @@
#include <types/pattern.h> #include <types/pattern.h>
#include <types/stick_table.h> #include <types/stick_table.h>
struct pattern_expr *pattern_parse_expr(char **str, int *idx, char *err, int err_size); struct sample_expr *sample_parse_expr(char **str, int *idx, char *err, int err_size);
struct sample *pattern_process(struct proxy *px, struct session *l4, struct sample *sample_process(struct proxy *px, struct session *l4,
void *l7, unsigned int dir, struct pattern_expr *expr, void *l7, unsigned int dir, struct sample_expr *expr,
struct sample *p); struct sample *p);
void pattern_register_fetches(struct pattern_fetch_kw_list *psl); void sample_register_fetches(struct sample_fetch_kw_list *psl);
void pattern_register_convs(struct pattern_conv_kw_list *psl); void sample_register_convs(struct sample_conv_kw_list *psl);
#endif #endif

View File

@ -48,8 +48,8 @@ struct stksess *stktable_lookup_key(struct stktable *t, struct stktable_key *key
struct stksess *stktable_update_key(struct stktable *table, struct stktable_key *key); struct stksess *stktable_update_key(struct stktable *table, struct stktable_key *key);
struct stktable_key *stktable_fetch_key(struct stktable *t, struct proxy *px, struct stktable_key *stktable_fetch_key(struct stktable *t, struct proxy *px,
struct session *l4, void *l7, unsigned int opt, struct session *l4, void *l7, unsigned int opt,
struct pattern_expr *expr); struct sample_expr *expr);
int stktable_compatible_pattern(struct pattern_expr *expr, unsigned long table_type); int stktable_compatible_sample(struct sample_expr *expr, unsigned long table_type);
int stktable_get_data_type(char *name); int stktable_get_data_type(char *name);
struct proxy *find_stktable(const char *name); struct proxy *find_stktable(const char *name);

View File

@ -106,27 +106,27 @@ struct sample {
union smp_ctx ctx; union smp_ctx ctx;
}; };
/* pattern conversion */ /* Descriptor for a sample conversion */
struct pattern_conv { struct sample_conv {
const char *kw; /* configuration keyword */ const char *kw; /* configuration keyword */
int (*process)(const struct arg *arg_p, int (*process)(const struct arg *arg_p,
struct sample *smp); /* process function */ struct sample *smp); /* process function */
unsigned int arg_mask; /* arguments (ARG*()) */ unsigned int arg_mask; /* arguments (ARG*()) */
int (*val_args)(struct arg *arg_p, int (*val_args)(struct arg *arg_p,
char **err_msg); /* argument validation function */ char **err_msg); /* argument validation function */
unsigned int in_type; /* input needed pattern type */ unsigned int in_type; /* expected input sample type */
unsigned int out_type; /* output pattern type */ unsigned int out_type; /* output sample type */
}; };
/* pattern conversion expression */ /* sample conversion expression */
struct pattern_conv_expr { struct sample_conv_expr {
struct list list; /* member of a pattern expression */ struct list list; /* member of a sample_expr */
struct pattern_conv *conv; /* pattern conversion */ struct sample_conv *conv; /* sample conversion used */
struct arg *arg_p; /* pointer on args */ struct arg *arg_p; /* optional arguments */
}; };
/* pattern fetch */ /* Descriptor for a sample fetch method */
struct pattern_fetch { struct sample_fetch {
const char *kw; /* configuration keyword */ const char *kw; /* configuration keyword */
int (*process)(struct proxy *px, int (*process)(struct proxy *px,
struct session *l4, struct session *l4,
@ -137,28 +137,28 @@ struct pattern_fetch {
unsigned int arg_mask; /* arguments (ARG*()) */ unsigned int arg_mask; /* arguments (ARG*()) */
int (*val_args)(struct arg *arg_p, int (*val_args)(struct arg *arg_p,
char **err_msg); /* argument validation function */ char **err_msg); /* argument validation function */
unsigned long out_type; /* output pattern type */ unsigned long out_type; /* output sample type */
unsigned int cap; /* fetch capabilities (SMP_CAP_*) */ unsigned int cap; /* fetch capabilities (SMP_CAP_*) */
}; };
/* pattern expression */ /* sample expression */
struct pattern_expr { struct sample_expr {
struct list list; /* member of list of pattern, currently not used */ struct list list; /* member of list of sample, currently not used */
struct pattern_fetch *fetch; /* pattern fetch */ struct sample_fetch *fetch; /* sample fetch method */
struct arg *arg_p; /* pointer on args */ struct arg *arg_p; /* optional pointer to arguments to fetch function */
struct list conv_exprs; /* list of conversion expression to apply */ struct list conv_exprs; /* list of conversion expression to apply */
}; };
/* pattern fetch keywords list */ /* sample fetch keywords list */
struct pattern_fetch_kw_list { struct sample_fetch_kw_list {
struct list list; /* head of pattern fetch keyword list */ struct list list; /* head of sample fetch keyword list */
struct pattern_fetch kw[VAR_ARRAY]; /* array of pattern fetches */ struct sample_fetch kw[VAR_ARRAY]; /* array of sample fetch descriptors */
}; };
/* pattern conversion keywords list */ /* sample conversion keywords list */
struct pattern_conv_kw_list { struct sample_conv_kw_list {
struct list list; /* head of pattern conversion keyword list */ struct list list; /* head of sample conversion keyword list */
struct pattern_conv kw[VAR_ARRAY]; /* array of pattern ions */ struct sample_conv kw[VAR_ARRAY]; /* array of sample conversion descriptors */
}; };
#endif /* _TYPES_PATTERN_H */ #endif /* _TYPES_PATTERN_H */

View File

@ -371,7 +371,7 @@ struct persist_rule {
struct sticking_rule { struct sticking_rule {
struct list list; /* list linked to from the proxy */ struct list list; /* list linked to from the proxy */
struct acl_cond *cond; /* acl condition to meet */ struct acl_cond *cond; /* acl condition to meet */
struct pattern_expr *expr; /* fetch expr to fetch key */ struct sample_expr *expr; /* fetch expr to fetch key */
int flags; /* STK_* */ int flags; /* STK_* */
union { union {
struct stktable *t; /* target table */ struct stktable *t; /* target table */

View File

@ -2968,7 +2968,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
} }
else if (!strcmp(args[0], "stick")) { else if (!strcmp(args[0], "stick")) {
struct sticking_rule *rule; struct sticking_rule *rule;
struct pattern_expr *expr; struct sample_expr *expr;
int myidx = 0; int myidx = 0;
char *errmsg = NULL; char *errmsg = NULL;
const char *name = NULL; const char *name = NULL;
@ -3015,7 +3015,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
goto out; goto out;
} }
expr = pattern_parse_expr(args, &myidx, trash, sizeof(trash)); expr = sample_parse_expr(args, &myidx, trash, sizeof(trash));
if (!expr) { if (!expr) {
Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], trash); Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], trash);
err_code |= ERR_ALERT | ERR_FATAL; err_code |= ERR_ALERT | ERR_FATAL;
@ -5930,8 +5930,8 @@ int check_config_validity()
curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
cfgerr++; cfgerr++;
} }
else if (!stktable_compatible_pattern(mrule->expr, target->table.type)) { else if (!stktable_compatible_sample(mrule->expr, target->table.type)) {
Alert("Proxy '%s': type of pattern not usable with type of stick-table '%s'.\n", Alert("Proxy '%s': type of fetch not usable with type of stick-table '%s'.\n",
curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
cfgerr++; cfgerr++;
} }
@ -5963,8 +5963,8 @@ int check_config_validity()
curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
cfgerr++; cfgerr++;
} }
else if (!stktable_compatible_pattern(mrule->expr, target->table.type)) { else if (!stktable_compatible_sample(mrule->expr, target->table.type)) {
Alert("Proxy '%s': type of pattern not usable with type of stick-table '%s'.\n", Alert("Proxy '%s': type of fetch not usable with type of stick-table '%s'.\n",
curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
cfgerr++; cfgerr++;
} }

View File

@ -758,7 +758,7 @@ static void deinit_tcp_rules(struct list *rules)
} }
} }
static void deinit_pattern_arg(struct arg *p) static void deinit_sample_arg(struct arg *p)
{ {
struct arg *p_back = p; struct arg *p_back = p;
@ -786,10 +786,10 @@ static void deinit_stick_rules(struct list *rules)
LIST_DEL(&rule->list); LIST_DEL(&rule->list);
deinit_acl_cond(rule->cond); deinit_acl_cond(rule->cond);
if (rule->expr) { if (rule->expr) {
struct pattern_conv_expr *conv_expr, *conv_exprb; struct sample_conv_expr *conv_expr, *conv_exprb;
list_for_each_entry_safe(conv_expr, conv_exprb, &rule->expr->conv_exprs, list) list_for_each_entry_safe(conv_expr, conv_exprb, &rule->expr->conv_exprs, list)
deinit_pattern_arg(conv_expr->arg_p); deinit_sample_arg(conv_expr->arg_p);
deinit_pattern_arg(rule->expr->arg_p); deinit_sample_arg(rule->expr->arg_p);
free(rule->expr); free(rule->expr);
} }
free(rule); free(rule);

View File

@ -18,58 +18,58 @@
#include <proto/buffers.h> #include <proto/buffers.h>
#include <common/standard.h> #include <common/standard.h>
/* static sample used in pattern_process() when <p> is NULL */ /* static sample used in sample_process() when <p> is NULL */
static struct sample temp_smp; static struct sample temp_smp;
/* trash chunk used for pattern conversions */ /* trash chunk used for sample conversions */
static struct chunk trash_chunk; static struct chunk trash_chunk;
/* trash buffers used or pattern conversions */ /* trash buffers used or sample conversions */
static char pattern_trash_buf1[BUFSIZE]; static char sample_trash_buf1[BUFSIZE];
static char pattern_trash_buf2[BUFSIZE]; static char sample_trash_buf2[BUFSIZE];
/* pattern_trash_buf point on used buffer*/ /* sample_trash_buf point on used buffer*/
static char *pattern_trash_buf = pattern_trash_buf1; static char *sample_trash_buf = sample_trash_buf1;
/* list head of all known pattern fetch keywords */ /* list head of all known sample fetch keywords */
static struct pattern_fetch_kw_list pattern_fetches = { static struct sample_fetch_kw_list sample_fetches = {
.list = LIST_HEAD_INIT(pattern_fetches.list) .list = LIST_HEAD_INIT(sample_fetches.list)
}; };
/* list head of all known pattern format conversion keywords */ /* list head of all known sample format conversion keywords */
static struct pattern_conv_kw_list pattern_convs = { static struct sample_conv_kw_list sample_convs = {
.list = LIST_HEAD_INIT(pattern_convs.list) .list = LIST_HEAD_INIT(sample_convs.list)
}; };
/* /*
* Registers the pattern fetch keyword list <kwl> as a list of valid keywords for next * Registers the sample fetch keyword list <kwl> as a list of valid keywords for next
* parsing sessions. * parsing sessions.
*/ */
void pattern_register_fetches(struct pattern_fetch_kw_list *pfkl) void sample_register_fetches(struct sample_fetch_kw_list *pfkl)
{ {
LIST_ADDQ(&pattern_fetches.list, &pfkl->list); LIST_ADDQ(&sample_fetches.list, &pfkl->list);
} }
/* /*
* Registers the pattern format coverstion keyword list <pckl> as a list of valid keywords for next * Registers the sample format coverstion keyword list <pckl> as a list of valid keywords for next
* parsing sessions. * parsing sessions.
*/ */
void pattern_register_convs(struct pattern_conv_kw_list *pckl) void sample_register_convs(struct sample_conv_kw_list *pckl)
{ {
LIST_ADDQ(&pattern_convs.list, &pckl->list); LIST_ADDQ(&sample_convs.list, &pckl->list);
} }
/* /*
* Returns the pointer on pattern fetch keyword structure identified by * Returns the pointer on sample fetch keyword structure identified by
* string of <len> in buffer <kw>. * string of <len> in buffer <kw>.
* *
*/ */
struct pattern_fetch *find_pattern_fetch(const char *kw, int len) struct sample_fetch *find_sample_fetch(const char *kw, int len)
{ {
int index; int index;
struct pattern_fetch_kw_list *kwl; struct sample_fetch_kw_list *kwl;
list_for_each_entry(kwl, &pattern_fetches.list, list) { list_for_each_entry(kwl, &sample_fetches.list, list) {
for (index = 0; kwl->kw[index].kw != NULL; index++) { for (index = 0; kwl->kw[index].kw != NULL; index++) {
if (strncmp(kwl->kw[index].kw, kw, len) == 0 && if (strncmp(kwl->kw[index].kw, kw, len) == 0 &&
kwl->kw[index].kw[len] == '\0') kwl->kw[index].kw[len] == '\0')
@ -80,16 +80,16 @@ struct pattern_fetch *find_pattern_fetch(const char *kw, int len)
} }
/* /*
* Returns the pointer on pattern format conversion keyword structure identified by * Returns the pointer on sample format conversion keyword structure identified by
* string of <len> in buffer <kw>. * string of <len> in buffer <kw>.
* *
*/ */
struct pattern_conv *find_pattern_conv(const char *kw, int len) struct sample_conv *find_sample_conv(const char *kw, int len)
{ {
int index; int index;
struct pattern_conv_kw_list *kwl; struct sample_conv_kw_list *kwl;
list_for_each_entry(kwl, &pattern_convs.list, list) { list_for_each_entry(kwl, &sample_convs.list, list) {
for (index = 0; kwl->kw[index].kw != NULL; index++) { for (index = 0; kwl->kw[index].kw != NULL; index++) {
if (strncmp(kwl->kw[index].kw, kw, len) == 0 && if (strncmp(kwl->kw[index].kw, kw, len) == 0 &&
kwl->kw[index].kw[len] == '\0') kwl->kw[index].kw[len] == '\0')
@ -101,23 +101,23 @@ struct pattern_conv *find_pattern_conv(const char *kw, int len)
/* /*
* Returns a static trash struct chunk to use in pattern casts or format conversions * Returns a static trash struct chunk to use in sample casts or format conversions
* Swiths the 2 available trash buffers to protect data during convert * Swiths the 2 available trash buffers to protect data during convert
*/ */
static struct chunk *get_trash_chunk(void) static struct chunk *get_trash_chunk(void)
{ {
if (pattern_trash_buf == pattern_trash_buf1) if (sample_trash_buf == sample_trash_buf1)
pattern_trash_buf = pattern_trash_buf2; sample_trash_buf = sample_trash_buf2;
else else
pattern_trash_buf = pattern_trash_buf1; sample_trash_buf = sample_trash_buf1;
chunk_init(&trash_chunk, pattern_trash_buf, BUFSIZE); chunk_init(&trash_chunk, sample_trash_buf, BUFSIZE);
return &trash_chunk; return &trash_chunk;
} }
/******************************************************************/ /******************************************************************/
/* Pattern casts functions */ /* Sample casts functions */
/* Note: these functions do *NOT* set the output type on the */ /* Note: these functions do *NOT* set the output type on the */
/* sample, the caller is responsible for doing this on return. */ /* sample, the caller is responsible for doing this on return. */
/******************************************************************/ /******************************************************************/
@ -236,13 +236,13 @@ static int c_str2int(struct sample *smp)
} }
/*****************************************************************/ /*****************************************************************/
/* Pattern casts matrix: */ /* Sample casts matrix: */
/* pattern_casts[from type][to type] */ /* sample_casts[from type][to type] */
/* NULL pointer used for impossible pattern casts */ /* NULL pointer used for impossible sample casts */
/*****************************************************************/ /*****************************************************************/
typedef int (*pattern_cast_fct)(struct sample *smp); typedef int (*sample_cast_fct)(struct sample *smp);
static pattern_cast_fct pattern_casts[SMP_TYPES][SMP_TYPES] = { static sample_cast_fct sample_casts[SMP_TYPES][SMP_TYPES] = {
/* to: BOOL UINT SINT IPV4 IPV6 STR BIN CSTR CBIN */ /* to: BOOL UINT SINT IPV4 IPV6 STR BIN CSTR CBIN */
/* from: BOOL */ { c_none, c_none, c_none, NULL, NULL, NULL, NULL, NULL, NULL }, /* from: BOOL */ { c_none, c_none, c_none, NULL, NULL, NULL, NULL, NULL, NULL },
/* UINT */ { c_none, c_none, c_none, c_int2ip, NULL, c_int2str, NULL, c_int2str, NULL }, /* UINT */ { c_none, c_none, c_none, c_int2ip, NULL, c_int2str, NULL, c_int2str, NULL },
@ -256,17 +256,17 @@ static pattern_cast_fct pattern_casts[SMP_TYPES][SMP_TYPES] = {
}; };
/* /*
* Parse a pattern expression configuration: * Parse a sample expression configuration:
* fetch keyword followed by format conversion keywords. * fetch keyword followed by format conversion keywords.
* Returns a pointer on allocated pattern expression structure. * Returns a pointer on allocated sample expression structure.
*/ */
struct pattern_expr *pattern_parse_expr(char **str, int *idx, char *err, int err_size) struct sample_expr *sample_parse_expr(char **str, int *idx, char *err, int err_size)
{ {
const char *endw; const char *endw;
const char *end; const char *end;
struct pattern_expr *expr; struct sample_expr *expr;
struct pattern_fetch *fetch; struct sample_fetch *fetch;
struct pattern_conv *conv; struct sample_conv *conv;
unsigned long prev_type; unsigned long prev_type;
char *p; char *p;
@ -291,7 +291,7 @@ struct pattern_expr *pattern_parse_expr(char **str, int *idx, char *err, int err
goto out_error; goto out_error;
} }
fetch = find_pattern_fetch(str[*idx], endw - str[*idx]); fetch = find_sample_fetch(str[*idx], endw - str[*idx]);
if (!fetch) { if (!fetch) {
p = my_strndup(str[*idx], endw - str[*idx]); p = my_strndup(str[*idx], endw - str[*idx]);
if (p) { if (p) {
@ -311,7 +311,7 @@ struct pattern_expr *pattern_parse_expr(char **str, int *idx, char *err, int err
} }
prev_type = fetch->out_type; prev_type = fetch->out_type;
expr = calloc(1, sizeof(struct pattern_expr)); expr = calloc(1, sizeof(struct sample_expr));
if (!expr) if (!expr)
goto out_error; goto out_error;
@ -361,7 +361,7 @@ struct pattern_expr *pattern_parse_expr(char **str, int *idx, char *err, int err
} }
for (*idx += 1; *(str[*idx]); (*idx)++) { for (*idx += 1; *(str[*idx]); (*idx)++) {
struct pattern_conv_expr *conv_expr; struct sample_conv_expr *conv_expr;
end = str[*idx] + strlen(str[*idx]); end = str[*idx] + strlen(str[*idx]);
endw = strchr(str[*idx], '('); endw = strchr(str[*idx], '(');
@ -377,7 +377,7 @@ struct pattern_expr *pattern_parse_expr(char **str, int *idx, char *err, int err
goto out_error; goto out_error;
} }
conv = find_pattern_conv(str[*idx], endw - str[*idx]); conv = find_sample_conv(str[*idx], endw - str[*idx]);
if (!conv) if (!conv)
break; break;
@ -392,7 +392,7 @@ struct pattern_expr *pattern_parse_expr(char **str, int *idx, char *err, int err
} }
/* If impossible type conversion */ /* If impossible type conversion */
if (!pattern_casts[prev_type][conv->in_type]) { if (!sample_casts[prev_type][conv->in_type]) {
p = my_strndup(str[*idx], endw - str[*idx]); p = my_strndup(str[*idx], endw - str[*idx]);
if (p) { if (p) {
snprintf(err, err_size, "conv method '%s' cannot be applied.", p); snprintf(err, err_size, "conv method '%s' cannot be applied.", p);
@ -402,7 +402,7 @@ struct pattern_expr *pattern_parse_expr(char **str, int *idx, char *err, int err
} }
prev_type = conv->out_type; prev_type = conv->out_type;
conv_expr = calloc(1, sizeof(struct pattern_conv_expr)); conv_expr = calloc(1, sizeof(struct sample_conv_expr));
if (!conv_expr) if (!conv_expr)
goto out_error; goto out_error;
@ -457,27 +457,27 @@ struct pattern_expr *pattern_parse_expr(char **str, int *idx, char *err, int err
return expr; return expr;
out_error: out_error:
/* TODO: prune_pattern_expr(expr); */ /* TODO: prune_sample_expr(expr); */
return NULL; return NULL;
} }
/* /*
* Process a fetch + format conversion of defined by the pattern expression <expr> * Process a fetch + format conversion of defined by the sample expression <expr>
* on request or response considering the <opt> parameter. * on request or response considering the <opt> parameter.
* Returns a pointer on a typed pattern structure containing the result or NULL if * Returns a pointer on a typed sample structure containing the result or NULL if
* pattern is not found or when format conversion failed. * sample is not found or when format conversion failed.
* If <p> is not null, function returns results in structure pointed by <p>. * If <p> is not null, function returns results in structure pointed by <p>.
* If <p> is null, functions returns a pointer on a static pattern structure. * If <p> is null, functions returns a pointer on a static sample structure.
* *
* Note: the fetch functions are required to properly set the return type. The * Note: the fetch functions are required to properly set the return type. The
* conversion functions must do so too. However the cast functions do not need * conversion functions must do so too. However the cast functions do not need
* to since they're made to cast mutiple types according to what is required. * to since they're made to cast mutiple types according to what is required.
*/ */
struct sample *pattern_process(struct proxy *px, struct session *l4, void *l7, struct sample *sample_process(struct proxy *px, struct session *l4, void *l7,
unsigned int opt, unsigned int opt,
struct pattern_expr *expr, struct sample *p) struct sample_expr *expr, struct sample *p)
{ {
struct pattern_conv_expr *conv_expr; struct sample_conv_expr *conv_expr;
if (p == NULL) if (p == NULL)
p = &temp_smp; p = &temp_smp;
@ -487,7 +487,7 @@ struct sample *pattern_process(struct proxy *px, struct session *l4, void *l7,
return NULL; return NULL;
if (p->flags & SMP_F_MAY_CHANGE) if (p->flags & SMP_F_MAY_CHANGE)
return NULL; /* we can only use stable patterns */ return NULL; /* we can only use stable samples */
list_for_each_entry(conv_expr, &expr->conv_exprs, list) { list_for_each_entry(conv_expr, &expr->conv_exprs, list) {
/* we want to ensure that p->type can be casted into /* we want to ensure that p->type can be casted into
@ -496,11 +496,11 @@ struct sample *pattern_process(struct proxy *px, struct session *l4, void *l7,
* - c_none => nothing to do (let's optimize it) * - c_none => nothing to do (let's optimize it)
* - other => apply cast and prepare to fail * - other => apply cast and prepare to fail
*/ */
if (!pattern_casts[p->type][conv_expr->conv->in_type]) if (!sample_casts[p->type][conv_expr->conv->in_type])
return NULL; return NULL;
if (pattern_casts[p->type][conv_expr->conv->in_type] != c_none && if (sample_casts[p->type][conv_expr->conv->in_type] != c_none &&
!pattern_casts[p->type][conv_expr->conv->in_type](p)) !sample_casts[p->type][conv_expr->conv->in_type](p))
return NULL; return NULL;
/* OK cast succeeded */ /* OK cast succeeded */
@ -514,11 +514,11 @@ struct sample *pattern_process(struct proxy *px, struct session *l4, void *l7,
} }
/*****************************************************************/ /*****************************************************************/
/* Pattern format convert functions */ /* Sample format convert functions */
/* These functions set the data type on return. */ /* These functions set the data type on return. */
/*****************************************************************/ /*****************************************************************/
static int pattern_conv_str2lower(const struct arg *arg_p, struct sample *smp) static int sample_conv_str2lower(const struct arg *arg_p, struct sample *smp)
{ {
int i; int i;
@ -533,7 +533,7 @@ static int pattern_conv_str2lower(const struct arg *arg_p, struct sample *smp)
return 1; return 1;
} }
static int pattern_conv_str2upper(const struct arg *arg_p, struct sample *smp) static int sample_conv_str2upper(const struct arg *arg_p, struct sample *smp)
{ {
int i; int i;
@ -549,7 +549,7 @@ static int pattern_conv_str2upper(const struct arg *arg_p, struct sample *smp)
} }
/* takes the netmask in arg_p */ /* takes the netmask in arg_p */
static int pattern_conv_ipmask(const struct arg *arg_p, struct sample *smp) static int sample_conv_ipmask(const struct arg *arg_p, struct sample *smp)
{ {
smp->data.ipv4.s_addr &= arg_p->data.ipv4.s_addr; smp->data.ipv4.s_addr &= arg_p->data.ipv4.s_addr;
smp->type = SMP_T_IPV4; smp->type = SMP_T_IPV4;
@ -557,16 +557,16 @@ static int pattern_conv_ipmask(const struct arg *arg_p, struct sample *smp)
} }
/* Note: must not be declared <const> as its list will be overwritten */ /* Note: must not be declared <const> as its list will be overwritten */
static struct pattern_conv_kw_list pattern_conv_kws = {{ },{ static struct sample_conv_kw_list sample_conv_kws = {{ },{
{ "upper", pattern_conv_str2upper, 0, NULL, SMP_T_STR, SMP_T_STR }, { "upper", sample_conv_str2upper, 0, NULL, SMP_T_STR, SMP_T_STR },
{ "lower", pattern_conv_str2lower, 0, NULL, SMP_T_STR, SMP_T_STR }, { "lower", sample_conv_str2lower, 0, NULL, SMP_T_STR, SMP_T_STR },
{ "ipmask", pattern_conv_ipmask, ARG1(1,MSK4), NULL, SMP_T_IPV4, SMP_T_IPV4 }, { "ipmask", sample_conv_ipmask, ARG1(1,MSK4), NULL, SMP_T_IPV4, SMP_T_IPV4 },
{ NULL, NULL, 0, 0, 0 }, { NULL, NULL, 0, 0, 0 },
}}; }};
__attribute__((constructor)) __attribute__((constructor))
static void __pattern_init(void) static void __sample_init(void)
{ {
/* register pattern format convert keywords */ /* register sample format convert keywords */
pattern_register_convs(&pattern_conv_kws); sample_register_convs(&sample_conv_kws);
} }

View File

@ -8304,7 +8304,7 @@ acl_fetch_cookie_cnt(struct proxy *px, struct session *l4, void *l7, unsigned in
} }
/************************************************************************/ /************************************************************************/
/* The code below is dedicated to pattern fetching and matching */ /* The code below is dedicated to sample fetches */
/************************************************************************/ /************************************************************************/
/* /*
@ -8533,7 +8533,7 @@ static struct acl_kw_list acl_kws = {{ },{
/* All supported pattern keywords must be declared here. */ /* All supported pattern keywords must be declared here. */
/************************************************************************/ /************************************************************************/
/* Note: must not be declared <const> as its list will be overwritten */ /* Note: must not be declared <const> as its list will be overwritten */
static struct pattern_fetch_kw_list pattern_fetch_keywords = {{ },{ static struct sample_fetch_kw_list sample_fetch_keywords = {{ },{
{ "hdr", smp_fetch_hdr, ARG2(1,STR,SINT), val_hdr, SMP_T_CSTR, SMP_CAP_REQ }, { "hdr", smp_fetch_hdr, ARG2(1,STR,SINT), val_hdr, SMP_T_CSTR, SMP_CAP_REQ },
{ "url_param", smp_fetch_url_param, ARG1(1,STR), NULL, SMP_T_CSTR, SMP_CAP_REQ }, { "url_param", smp_fetch_url_param, ARG1(1,STR), NULL, SMP_T_CSTR, SMP_CAP_REQ },
{ "cookie", smp_fetch_cookie_value, ARG1(1,STR), NULL, SMP_T_CSTR, SMP_CAP_REQ|SMP_CAP_RES }, { "cookie", smp_fetch_cookie_value, ARG1(1,STR), NULL, SMP_T_CSTR, SMP_CAP_REQ|SMP_CAP_RES },
@ -8546,7 +8546,7 @@ __attribute__((constructor))
static void __http_protocol_init(void) static void __http_protocol_init(void)
{ {
acl_register_keywords(&acl_kws); acl_register_keywords(&acl_kws);
pattern_register_fetches(&pattern_fetch_keywords); sample_register_fetches(&sample_fetch_keywords);
} }

View File

@ -1258,7 +1258,7 @@ static int tcp_parse_tcp_req(char **args, int section_type, struct proxy *curpx,
/************************************************************************/ /************************************************************************/
/* Fetch the request RDP cookie identified in the args, or any cookie if no arg /* Fetch the request RDP cookie identified in the args, or any cookie if no arg
* is passed. It is usable both for ACL and for patterns. Note: this decoder * is passed. It is usable both for ACL and for samples. Note: this decoder
* only works with non-wrapping data. Accepts either 0 or 1 argument. Argument * only works with non-wrapping data. Accepts either 0 or 1 argument. Argument
* is a string (cookie name), other types will lead to undefined behaviour. * is a string (cookie name), other types will lead to undefined behaviour.
*/ */
@ -1397,8 +1397,8 @@ smp_fetch_src(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
/* extract the connection's source ipv6 address */ /* extract the connection's source ipv6 address */
static int static int
pattern_fetch_src6(struct proxy *px, struct session *l4, void *l7, unsigned int opt, smp_fetch_src6(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *arg_p, struct sample *smp) const struct arg *arg_p, struct sample *smp)
{ {
if (l4->si[0].addr.from.ss_family != AF_INET6) if (l4->si[0].addr.from.ss_family != AF_INET6)
return 0; return 0;
@ -1447,8 +1447,8 @@ smp_fetch_dst(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
/* extract the connection's destination ipv6 address */ /* extract the connection's destination ipv6 address */
static int static int
pattern_fetch_dst6(struct proxy *px, struct session *l4, void *l7, unsigned int opt, smp_fetch_dst6(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *arg_p, struct sample *smp) const struct arg *arg_p, struct sample *smp)
{ {
stream_sock_get_to_addr(&l4->si[0]); stream_sock_get_to_addr(&l4->si[0]);
@ -1638,11 +1638,11 @@ static struct acl_kw_list acl_kws = {{ },{
* common denominator, the type that can be casted into all other ones. For * common denominator, the type that can be casted into all other ones. For
* instance v4/v6 must be declared v4. * instance v4/v6 must be declared v4.
*/ */
static struct pattern_fetch_kw_list pattern_fetch_keywords = {{ },{ static struct sample_fetch_kw_list sample_fetch_keywords = {{ },{
{ "src", smp_fetch_src, 0, NULL, SMP_T_IPV4, SMP_CAP_REQ|SMP_CAP_RES }, { "src", smp_fetch_src, 0, NULL, SMP_T_IPV4, SMP_CAP_REQ|SMP_CAP_RES },
{ "src6", pattern_fetch_src6, 0, NULL, SMP_T_IPV6, SMP_CAP_REQ|SMP_CAP_RES }, { "src6", smp_fetch_src6, 0, NULL, SMP_T_IPV6, SMP_CAP_REQ|SMP_CAP_RES },
{ "dst", smp_fetch_dst, 0, NULL, SMP_T_IPV4, SMP_CAP_REQ|SMP_CAP_RES }, { "dst", smp_fetch_dst, 0, NULL, SMP_T_IPV4, SMP_CAP_REQ|SMP_CAP_RES },
{ "dst6", pattern_fetch_dst6, 0, NULL, SMP_T_IPV6, SMP_CAP_REQ|SMP_CAP_RES }, { "dst6", smp_fetch_dst6, 0, NULL, SMP_T_IPV6, SMP_CAP_REQ|SMP_CAP_RES },
{ "dst_port", smp_fetch_dport, 0, NULL, SMP_T_UINT, SMP_CAP_REQ|SMP_CAP_RES }, { "dst_port", smp_fetch_dport, 0, NULL, SMP_T_UINT, SMP_CAP_REQ|SMP_CAP_RES },
{ "payload", smp_fetch_payload, ARG2(2,UINT,UINT), val_payload, SMP_T_CBIN, SMP_CAP_REQ|SMP_CAP_RES }, { "payload", smp_fetch_payload, ARG2(2,UINT,UINT), val_payload, SMP_T_CBIN, SMP_CAP_REQ|SMP_CAP_RES },
{ "payload_lv", smp_fetch_payload_lv, ARG3(2,UINT,UINT,SINT), val_payload_lv, SMP_T_CBIN, SMP_CAP_REQ|SMP_CAP_RES }, { "payload_lv", smp_fetch_payload_lv, ARG3(2,UINT,UINT,SINT), val_payload_lv, SMP_T_CBIN, SMP_CAP_REQ|SMP_CAP_RES },
@ -1656,7 +1656,7 @@ static void __tcp_protocol_init(void)
{ {
protocol_register(&proto_tcpv4); protocol_register(&proto_tcpv4);
protocol_register(&proto_tcpv6); protocol_register(&proto_tcpv6);
pattern_register_fetches(&pattern_fetch_keywords); sample_register_fetches(&sample_fetch_keywords);
cfg_register_keywords(&cfg_kws); cfg_register_keywords(&cfg_kws);
acl_register_keywords(&acl_kws); acl_register_keywords(&acl_kws);
} }

View File

@ -3386,7 +3386,7 @@ int parse_track_counters(char **args, int *arg,
struct track_ctr_prm *prm, struct track_ctr_prm *prm,
struct proxy *defpx, char *err, int errlen) struct proxy *defpx, char *err, int errlen)
{ {
int pattern_type = 0; int sample_type = 0;
char *kw = args[*arg - 1]; char *kw = args[*arg - 1];
/* parse the arguments of "track-sc[12]" before the condition in the /* parse the arguments of "track-sc[12]" before the condition in the
@ -3396,7 +3396,7 @@ int parse_track_counters(char **args, int *arg,
while (args[*arg]) { while (args[*arg]) {
if (strcmp(args[*arg], "src") == 0) { if (strcmp(args[*arg], "src") == 0) {
prm->type = STKTABLE_TYPE_IP; prm->type = STKTABLE_TYPE_IP;
pattern_type = 1; sample_type = 1;
} }
else if (strcmp(args[*arg], "table") == 0) { else if (strcmp(args[*arg], "table") == 0) {
if (!args[*arg + 1]) { if (!args[*arg + 1]) {
@ -3416,7 +3416,7 @@ int parse_track_counters(char **args, int *arg,
(*arg)++; (*arg)++;
} }
if (!pattern_type) { if (!sample_type) {
snprintf(err, errlen, snprintf(err, errlen,
"%s key not specified in %s '%s' (found %s, only 'src' is supported).", "%s key not specified in %s '%s' (found %s, only 'src' is supported).",
kw, proxy_type_str(curpx), curpx->id, quote_arg(args[*arg])); kw, proxy_type_str(curpx), curpx->id, quote_arg(args[*arg]));

View File

@ -30,7 +30,7 @@
#include <proto/peers.h> #include <proto/peers.h>
#include <types/global.h> #include <types/global.h>
/* structure used to return a table key built from a pattern */ /* structure used to return a table key built from a sample */
struct stktable_key static_table_key; struct stktable_key static_table_key;
/* /*
@ -445,7 +445,7 @@ int stktable_parse_type(char **args, int *myidx, unsigned long *type, size_t *ke
} }
/*****************************************************************/ /*****************************************************************/
/* typed pattern to typed table key functions */ /* typed sample to typed table key functions */
/*****************************************************************/ /*****************************************************************/
static void *k_int2int(struct sample *smp, union stktable_key_data *kdata, size_t *len) static void *k_int2int(struct sample *smp, union stktable_key_data *kdata, size_t *len)
@ -558,9 +558,9 @@ static void *k_str2int(struct sample *smp, union stktable_key_data *kdata, size_
} }
/*****************************************************************/ /*****************************************************************/
/* typed pattern to typed table key matrix: */ /* typed sample to typed table key matrix: */
/* pattern_to_key[from pattern type][to table key type] */ /* sample_to_key[from sample type][to table key type] */
/* NULL pointer used for impossible pattern casts */ /* NULL pointer used for impossible sample casts */
/*****************************************************************/ /*****************************************************************/
/* /*
@ -569,8 +569,8 @@ static void *k_str2int(struct sample *smp, union stktable_key_data *kdata, size_
* relevant and could cause confusion in configuration. * relevant and could cause confusion in configuration.
*/ */
typedef void *(*pattern_to_key_fct)(struct sample *smp, union stktable_key_data *kdata, size_t *len); typedef void *(*sample_to_key_fct)(struct sample *smp, union stktable_key_data *kdata, size_t *len);
static pattern_to_key_fct pattern_to_key[SMP_TYPES][STKTABLE_TYPES] = { static sample_to_key_fct sample_to_key[SMP_TYPES][STKTABLE_TYPES] = {
/* table type: IP IPV6 INTEGER STRING BINARY */ /* table type: IP IPV6 INTEGER STRING BINARY */
/* patt. type: BOOL */ { NULL, NULL, k_int2int, k_int2str, NULL }, /* patt. type: BOOL */ { NULL, NULL, k_int2int, k_int2str, NULL },
/* UINT */ { k_int2ip, NULL, k_int2int, k_int2str, NULL }, /* UINT */ { k_int2ip, NULL, k_int2int, k_int2str, NULL },
@ -585,26 +585,26 @@ static pattern_to_key_fct pattern_to_key[SMP_TYPES][STKTABLE_TYPES] = {
/* /*
* Process a fetch + format conversion as defined by the pattern expression <expr> * Process a fetch + format conversion as defined by the sample expression <expr>
* on request or response considering the <opt> parameter. Returns either NULL if * on request or response considering the <opt> parameter. Returns either NULL if
* no key could be extracted, or a pointer to the converted result stored in * no key could be extracted, or a pointer to the converted result stored in
* static_table_key in format <table_type>. * static_table_key in format <table_type>.
*/ */
struct stktable_key *stktable_fetch_key(struct stktable *t, struct proxy *px, struct session *l4, void *l7, struct stktable_key *stktable_fetch_key(struct stktable *t, struct proxy *px, struct session *l4, void *l7,
unsigned int opt, unsigned int opt,
struct pattern_expr *expr) struct sample_expr *expr)
{ {
struct sample *smp; struct sample *smp;
smp = pattern_process(px, l4, l7, opt, expr, NULL); smp = sample_process(px, l4, l7, opt, expr, NULL);
if (!smp) if (!smp)
return NULL; return NULL;
if (!pattern_to_key[smp->type][t->type]) if (!sample_to_key[smp->type][t->type])
return NULL; return NULL;
static_table_key.key_len = t->key_size; static_table_key.key_len = t->key_size;
static_table_key.key = pattern_to_key[smp->type][t->type](smp, &static_table_key.data, &static_table_key.key_len); static_table_key.key = sample_to_key[smp->type][t->type](smp, &static_table_key.data, &static_table_key.key_len);
if (!static_table_key.key) if (!static_table_key.key)
return NULL; return NULL;
@ -642,22 +642,22 @@ struct stktable_key *stktable_fetch_key(struct stktable *t, struct proxy *px, st
} }
/* /*
* Returns 1 if pattern expression <expr> result can be converted to table key of * Returns 1 if sample expression <expr> result can be converted to table key of
* type <table_type>, otherwise zero. Used in configuration check. * type <table_type>, otherwise zero. Used in configuration check.
*/ */
int stktable_compatible_pattern(struct pattern_expr *expr, unsigned long table_type) int stktable_compatible_sample(struct sample_expr *expr, unsigned long table_type)
{ {
if (table_type >= STKTABLE_TYPES) if (table_type >= STKTABLE_TYPES)
return 0; return 0;
if (LIST_ISEMPTY(&expr->conv_exprs)) { if (LIST_ISEMPTY(&expr->conv_exprs)) {
if (!pattern_to_key[expr->fetch->out_type][table_type]) if (!sample_to_key[expr->fetch->out_type][table_type])
return 0; return 0;
} else { } else {
struct pattern_conv_expr *conv_expr; struct sample_conv_expr *conv_expr;
conv_expr = LIST_PREV(&expr->conv_exprs, typeof(conv_expr), list); conv_expr = LIST_PREV(&expr->conv_exprs, typeof(conv_expr), list);
if (!pattern_to_key[conv_expr->conv->out_type][table_type]) if (!sample_to_key[conv_expr->conv->out_type][table_type])
return 0; return 0;
} }
return 1; return 1;