mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-04-08 02:01:33 +00:00
MINOR: sample: provide a generic var-to-sample conversion function
We're using variable-to-sample conversion at least 4 times in the code, two of which are bogus. Let's introduce a generic conversion function that performs the required checks.
This commit is contained in:
parent
4034e2cb58
commit
168e8de1d0
@ -40,6 +40,7 @@ struct sample *sample_process(struct proxy *px, struct session *sess,
|
|||||||
struct sample *sample_fetch_as_type(struct proxy *px, struct session *sess,
|
struct sample *sample_fetch_as_type(struct proxy *px, struct session *sess,
|
||||||
struct stream *strm, unsigned int opt,
|
struct stream *strm, unsigned int opt,
|
||||||
struct sample_expr *expr, int smp_type);
|
struct sample_expr *expr, int smp_type);
|
||||||
|
int sample_conv_var2smp(const struct var_desc *var, struct sample *smp, int type);
|
||||||
int sample_conv_var2smp_sint(const struct arg *arg, struct sample *smp);
|
int sample_conv_var2smp_sint(const struct arg *arg, struct sample *smp);
|
||||||
int sample_conv_var2smp_str(const struct arg *arg, struct sample *smp);
|
int sample_conv_var2smp_str(const struct arg *arg, struct sample *smp);
|
||||||
void release_sample_expr(struct sample_expr *expr);
|
void release_sample_expr(struct sample_expr *expr);
|
||||||
|
18
src/sample.c
18
src/sample.c
@ -1630,6 +1630,24 @@ static int sample_conv_bin2base64url(const struct arg *arg_p, struct sample *smp
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This function returns a sample struct filled with the conversion of variable
|
||||||
|
* <var> to sample type <type> (SMP_T_*), via a cast to the target type. If the
|
||||||
|
* variable cannot be retrieved or casted, 0 is returned, otherwise 1.
|
||||||
|
*
|
||||||
|
* Keep in mind that the sample content may be written to a pre-allocated
|
||||||
|
* trash chunk as returned by get_trash_chunk().
|
||||||
|
*/
|
||||||
|
int sample_conv_var2smp(const struct var_desc *var, struct sample *smp, int type)
|
||||||
|
{
|
||||||
|
if (!vars_get_by_desc(var, smp, NULL))
|
||||||
|
return 0;
|
||||||
|
if (!sample_casts[smp->data.type][type])
|
||||||
|
return 0;
|
||||||
|
if (!sample_casts[smp->data.type][type](smp))
|
||||||
|
return 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int sample_conv_sha1(const struct arg *arg_p, struct sample *smp, void *private)
|
static int sample_conv_sha1(const struct arg *arg_p, struct sample *smp, void *private)
|
||||||
{
|
{
|
||||||
blk_SHA_CTX ctx;
|
blk_SHA_CTX ctx;
|
||||||
|
Loading…
Reference in New Issue
Block a user