]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: arg: add an argument type for identifier
authorDragan Dosen <ddosen@haproxy.com>
Thu, 17 Oct 2024 08:59:01 +0000 (10:59 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 18 Oct 2024 12:30:24 +0000 (14:30 +0200)
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.

include/haproxy/arg-t.h
src/arg.c
src/sample.c

index d90d326ef3540fce36c87c75bd15b867b16a0fd5..708a90ede3ed1ab535d49216ff39e640afd61ce5 100644 (file)
@@ -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 <str> 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
index 2810050b0fa66dec17295570864e18b4e5905092..38b4e9460364265944ebc7d5ff526fb9b58e0d10 100644 (file)
--- 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:
index 67531392ac959925af2817edacc9d9841e666005..844b273d6d0b39b159b9b1bf7290d7ab01bbf868 100644 (file)
@@ -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",