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.
This commit is contained in:
parent
fa01c9d92b
commit
fdcb97614c
@ -183,8 +183,9 @@ struct cert_exts {
|
|||||||
enum parse_type_t {
|
enum parse_type_t {
|
||||||
PARSE_TYPE_NONE = 0,
|
PARSE_TYPE_NONE = 0,
|
||||||
PARSE_TYPE_INT,
|
PARSE_TYPE_INT,
|
||||||
PARSE_TYPE_STR, /* string which is strdup() */
|
PARSE_TYPE_STR, /* string which is strdup() */
|
||||||
PARSE_TYPE_ONOFF, /* "on" or "off" keyword */
|
PARSE_TYPE_ARRAY_SUBSTR, /* string splitted by colons into an array of substring */
|
||||||
|
PARSE_TYPE_ONOFF, /* "on" or "off" keyword */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ckch_conf_kws {
|
struct ckch_conf_kws {
|
||||||
|
@ -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;
|
err_code |= ERR_ALERT | ERR_ABORT;
|
||||||
goto out;
|
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) {
|
} else if (ckch_conf_kws[i].type == PARSE_TYPE_INT) {
|
||||||
int *t = target;
|
int *t = target;
|
||||||
char *stop;
|
char *stop;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user