]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: ssl/ckch: add substring parser for ckch_conf
authorWilliam Lallemand <wlallemand@haproxy.com>
Thu, 20 Mar 2025 21:44:53 +0000 (22:44 +0100)
committerWilliam Lallemand <wlallemand@haproxy.com>
Tue, 1 Apr 2025 13:38:32 +0000 (15:38 +0200)
Add a substring parser for the ckch_conf keyword parser, this will split
a string into multiple substring, and strdup them in a array.

include/haproxy/ssl_ckch-t.h
src/ssl_ckch.c

index 83ac3a30cf26766e6c396c51d0d642c7ccea4279..8141ad3d5eb3f332706ef74dcd5a79184f70baff 100644 (file)
@@ -183,8 +183,9 @@ struct cert_exts {
 enum parse_type_t {
        PARSE_TYPE_NONE = 0,
        PARSE_TYPE_INT,
-       PARSE_TYPE_STR,         /* string which is strdup() */
-       PARSE_TYPE_ONOFF,       /* "on" or "off" keyword */
+       PARSE_TYPE_STR,            /* string which is strdup() */
+       PARSE_TYPE_ARRAY_SUBSTR,   /* string splitted by colons into an array of substring */
+       PARSE_TYPE_ONOFF,          /* "on" or "off" keyword */
 };
 
 struct ckch_conf_kws {
index 8e49fcb939eca93d5b4f2040805a85674a885d8f..f5c893e573e9d3aadfe76eb8f6245fb370cbac64 100644 (file)
@@ -4801,6 +4801,53 @@ int ckch_conf_parse(char **args, int cur_arg, struct ckch_conf *f, int *found, c
                                        err_code |= ERR_ALERT | ERR_ABORT;
                                        goto out;
                                }
+                       } else if (ckch_conf_kws[i].type == PARSE_TYPE_ARRAY_SUBSTR) {
+                               char ***t = target;
+                               char **r = NULL;
+                               int n = 0;
+                               char *b, *e;
+
+                               /* split a string into substring splitted by colons */
+
+                               e = b = args[cur_arg + 1];
+                               do {
+                                       while (*e != ',' && *e != '\0')
+                                               e++;
+                                       r = realloc(r, sizeof(char *) * (n + 2));
+                                       if (!r) {
+                                               ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
+                                               err_code |= ERR_ALERT | ERR_ABORT;
+                                               goto out;
+                                       }
+                                       r[n] = strndup(b, e - b);
+                                       if (!r[n]) {
+                                               ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
+                                               err_code |= ERR_ALERT | ERR_ABORT;
+                                               goto out;
+                                       }
+
+                                       n++;
+
+                                       if (*e == '\0')
+                                               break;
+
+                                       e++; /* skip the separator */
+
+                                       /* skip trailing spaces */
+                                       while (*e == ' ')
+                                               e++;
+
+                                       b = e;
+
+                               } while (*b);
+
+                               r[n] = NULL; /* last element is NULL */
+                               *t = r;
+// debug
+//                             while (*r)
+//                                     fprintf(stderr, "sub: \"%s\"\n", *r++);
+
+
                        } else if (ckch_conf_kws[i].type == PARSE_TYPE_INT) {
                                int *t = target;
                                char *stop;