Re: [PATCH] MINOR : converter: add param converter

2022-12-13 Thread Willy Tarreau
On Wed, Dec 14, 2022 at 12:19:59AM -0700, Thayne McCombs wrote:
> Add a converter that extracts a parameter from string of delimited
> key/value pairs.

Great, now merged. Thank you!
Willy



Re: [PATCH] MINOR : converter: add param converter

2022-12-13 Thread Tim Düsterhus

Thayne,

On 12/9/22 07:22, Thayne McCombs wrote:

Ok. I think this patch addresses all of your feedback. Thanks for
looking at it.


It appears that your mailer mangled the patch. It looks incorrectly 
formatted in my MUA and git fails to apply it. I recommend either using 
'git send-email' or just attaching the patch as a regular attachment. 
Both should be equally simple for Willy to apply.


Best regards
Tim Düsterhus



Re: [PATCH] MINOR : converter: add param converter

2022-12-07 Thread Willy Tarreau
On Wed, Jun 08, 2022 at 01:56:20AM -0600, astrotha...@gmail.com wrote:
> +param(,[])
> +  This extracts the first occurrence of the parameter  in the input 
> string
> +  where parameters are delimited by , which defaults to "&", and the 
> name
> +  and value of the parameter are separated by a "=". If there is no "=" and 
> value
> +  before the end of the parameter segment, it is treated as equivalent to a 
> value
> +  of an empty string.
> +
> +  This can be useful for extracting parameters from a query string, or 
> possibly a
> +  x-www-form-urlencoded body. In particular, `query,param()` can be 
> used as
> +  an alternative to `urlp()` which only uses "&" as a delimiter, 
> whereas "urlp"
> +  also uses "?" and ";".
> +
> +  Note that this converter doesn't do anything special with url encoded 
> characters. If
> +  you want to decode the value, you can use the url_dec converter on the 
> output. If
> +  the name of the parameter in the input might contain encoded characters, 
> you'll probably

Be careful to trim your long lines in the doc so that they don't overflow 80
characters.

> +static int sample_conv_param(const struct arg *arg_p, struct sample *smp, 
> void *private)
> +{
> + char *pos, *end, *pend, *equal;
> + char delim = '&';
> + const char *name = arg_p[0].data.str.area;
> + size_t name_l = arg_p[0].data.str.data;
> +
> + if (arg_p[1].type == ARGT_STR)
> + delim = *arg_p[1].data.str.area;
> +
> + pos = smp->data.u.str.area;
> + end = pos + smp->data.u.str.data;
> + while (pos < end) {
> + equal = pos + name_l;
> + /* Parameter not found */
> + if (equal > end)
> + break;
> +
> + if (equal == end || *equal == '&') {
  ^^^
here it should be "delim", I guess it's a leftover from a previous version

> + if (memcmp(pos, name, name_l) == 0) {
> + /* input contains parameter, but no value is 
> suplied */
 
^^^
supplied :-)

> + smp->data.u.str.data = 0;
> + return 1;
> + }
> + pos = equal + 1;
> + continue;
> + }
> +
> + if (*equal == '=' && memcmp(pos, name, name_l) == 0) {
> + pos = equal + 1;
> + pend = memchr(pos, delim, end - pos);
> + if (pend == NULL)
> + pend = end;
> + b_set_area_sub(&(smp->data.u.str), pos, pend - pos);

Ah, I didn't notice that b_set_area_sub() comes in a previous patch.
I'm not fond of this function, because it standardizes something that
should never work except in this exceptional case, and will inevitably
result in someone using it for the wrong thing. The point is that the
 part of a buffer is allocated from pools normally and must not
be changed at all, since for regular use, there are start offset and
length that do the job. However here in samples we're still using buffers
to store strings because they're easy to allocate and are convenient
enough to use, but I would say it's just a convenience that's almost an
abuse. Most likely that the string part of samples could be turned to IST
instead. Thus I'd rather see both the ->area and ->data parts here being
manually assigned, it's more readable and doesn't standardize an exception.
I suspect it would simply become:

smp->data.u.str.area = pos;
smp->data.u.str.data = pend - pos;

And that's way more readable for those trying to rule out the possibility of
a bug here.

>  /* Note: must not be declared  as its list will be overwritten */
>  static struct sample_conv_kw_list sample_conv_kws = {ILH, {
> - { "add_item",sample_conv_add_item, ARG3(2,STR,STR,STR),   
> smp_check_add_item,   SMP_T_STR,  SMP_T_STR  },
> - { "debug",   sample_conv_debug,ARG2(0,STR,STR),   
> smp_check_debug,  SMP_T_ANY,  SMP_T_ANY  },
> - { "b64dec",  sample_conv_base642bin,   0, NULL, 
> SMP_T_STR,  SMP_T_BIN  },
> + { "add_item",sample_conv_add_item, ARG3(2,STR,STR,STR),   
> smp_check_add_item,   SMP_T_STR,  SMP_T_STR  }, { "debug",   
> sample_conv_debug,ARG2(0,STR,STR),   smp_check_debug,  
> SMP_T_ANY,  SMP_T_ANY  }, { "b64dec",  sample_conv_base642bin,   0,   
>   NULL, SMP_T_STR,  SMP_T_BIN  },

There's a mistake here, you accidently folded 3 lines. Probably "J" being
pressed there by accident in vim :-)

Otherwise it looks good. Please recheck, but I'm overall fine with merging
this.

Thank you!
Willy



Re: [PATCH] MINOR : converter: add param converter

2022-12-07 Thread Willy Tarreau
On Tue, Dec 06, 2022 at 03:44:00PM -0700, Thayne wrote:
> Any update on this?

Hmm indeed it left forgotten in the dust, we must get back to it to verify
that it's OK then merge it.

Thanks for the reminder, Thayne!
Willy



Re: [PATCH] MINOR : converter: add param converter

2022-12-06 Thread Thayne
Any update on this?