From: Dragan Dosen Date: Thu, 17 Oct 2024 08:59:01 +0000 (+0200) Subject: MINOR: arg: add an argument type for identifier X-Git-Tag: v3.1-dev11~107 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f33e9079a93ce0a22954b9423657524e81d852e8;p=thirdparty%2Fhaproxy.git MINOR: arg: add an argument type for identifier The ARGT_ID argument type may now be used to set a custom resolve function in order to help resolve the argument string value. If the custom resolve function is not set, the behavior is the same as of type ARGT_STR. --- diff --git a/include/haproxy/arg-t.h b/include/haproxy/arg-t.h index d90d326ef3..708a90ede3 100644 --- a/include/haproxy/arg-t.h +++ b/include/haproxy/arg-t.h @@ -46,6 +46,7 @@ enum { ARGT_STOP = 0, /* end of the arg list */ ARGT_SINT, /* signed 64 bit integer. */ ARGT_STR, /* string */ + ARGT_ID, /* identifier */ ARGT_IPV4, /* an IPv4 address */ ARGT_MSK4, /* an IPv4 address mask (integer or dotted), stored as ARGT_IPV4 */ ARGT_IPV6, /* an IPv6 address */ @@ -124,6 +125,12 @@ struct arg { unsigned char unresolved; /* argument contains a string in that must be resolved and freed */ unsigned char type_flags; /* type-specific extra flags (eg: case sensitivity for regex), ARGF_* */ union arg_data data; /* argument data */ + + int (*resolve_ptr)(struct arg *arg, char **err); /* ptr to custom resolve function that can be used + * for the arg of type ARGT_ID; the err must always + * be compatible with free() (i.e. either null or + * the result of a malloc/strdup/memprintf call) + */ }; /* arg lists are used to store information about arguments that could not be diff --git a/src/arg.c b/src/arg.c index 2810050b0f..38b4e94603 100644 --- a/src/arg.c +++ b/src/arg.c @@ -24,6 +24,7 @@ const char *arg_type_names[ARGT_NBTYPES] = { [ARGT_STOP] = "end of arguments", [ARGT_SINT] = "integer", [ARGT_STR] = "string", + [ARGT_ID] = "identifier", [ARGT_IPV4] = "IPv4 address", [ARGT_MSK4] = "IPv4 mask", [ARGT_IPV6] = "IPv6 address", @@ -237,6 +238,7 @@ int make_arg_list(const char *in, int len, uint64_t mask, struct arg **argp, arg->type = ARGT_SINT; break; + case ARGT_ID: case ARGT_FE: case ARGT_BE: case ARGT_TAB: diff --git a/src/sample.c b/src/sample.c index 67531392ac..844b273d6d 100644 --- a/src/sample.c +++ b/src/sample.c @@ -1444,6 +1444,20 @@ int smp_resolve_args(struct proxy *p, char **err) pname = p->id; switch (arg->type) { + case ARGT_ID: + err2 = NULL; + + if (arg->resolve_ptr && !arg->resolve_ptr(arg, &err2)) { + memprintf(err, "%sparsing [%s:%d]: error in identifier '%s' in arg %d of %s%s%s%s '%s' %s proxy '%s' : %s.\n", + *err ? *err : "", cur->file, cur->line, + arg->data.str.area, + cur->arg_pos + 1, conv_pre, conv_ctx, conv_pos, ctx, cur->kw, where, p->id, err2); + ha_free(&err2); + cfgerr++; + continue; + } + break; + case ARGT_SRV: if (!arg->data.str.data) { memprintf(err, "%sparsing [%s:%d]: missing server name in arg %d of %s%s%s%s '%s' %s proxy '%s'.\n",