From fdcb97614cb5dfd2fa58d38fc352f0f37d6858fd Mon Sep 17 00:00:00 2001 From: William Lallemand Date: Thu, 20 Mar 2025 22:44:53 +0100 Subject: [PATCH] MINOR: ssl/ckch: add substring parser for ckch_conf 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 | 5 ++-- src/ssl_ckch.c | 47 ++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/include/haproxy/ssl_ckch-t.h b/include/haproxy/ssl_ckch-t.h index 83ac3a30c..8141ad3d5 100644 --- a/include/haproxy/ssl_ckch-t.h +++ b/include/haproxy/ssl_ckch-t.h @@ -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 { diff --git a/src/ssl_ckch.c b/src/ssl_ckch.c index 8e49fcb93..f5c893e57 100644 --- a/src/ssl_ckch.c +++ b/src/ssl_ckch.c @@ -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; -- 2.39.5