From a1fdad784bc734c2a01ca5980e1a662d418a2a0b Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Mon, 20 Feb 2023 17:55:58 +0100 Subject: [PATCH] MINOR: cfgcond: Implement strstr condition expression Implement a way to match a substring in a string. The strstr expresionn can now be used to do so. --- doc/configuration.txt | 1 + include/haproxy/cfgcond-t.h | 1 + src/cfgcond.c | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/doc/configuration.txt b/doc/configuration.txt index 3c60634..8aea55e 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -865,6 +865,7 @@ The list of currently supported predicates is the following: - streq(,) : returns true only if the two strings are equal - strneq(,) : returns true only if the two strings differ + - strstr(,) : returns true only if the second string is found in the first one - version_atleast(): returns true if the current haproxy version is at least as recent as otherwise false. The diff --git a/include/haproxy/cfgcond-t.h b/include/haproxy/cfgcond-t.h index 1e09293..206ae06 100644 --- a/include/haproxy/cfgcond-t.h +++ b/include/haproxy/cfgcond-t.h @@ -48,6 +48,7 @@ enum cond_predicate { CFG_PRED_FEATURE, // "feature" CFG_PRED_STREQ, // "streq" CFG_PRED_STRNEQ, // "strneq" + CFG_PRED_STRSTR, // "strstr" CFG_PRED_VERSION_ATLEAST, // "version_atleast" CFG_PRED_VERSION_BEFORE, // "version_before" CFG_PRED_OSSL_VERSION_ATLEAST, // "openssl_version_atleast" diff --git a/src/cfgcond.c b/src/cfgcond.c index 5fb7069..b29fcbf 100644 --- a/src/cfgcond.c +++ b/src/cfgcond.c @@ -22,6 +22,7 @@ const struct cond_pred_kw cond_predicates[] = { { "feature", CFG_PRED_FEATURE, ARG1(1, STR) }, { "streq", CFG_PRED_STREQ, ARG2(2, STR, STR) }, { "strneq", CFG_PRED_STRNEQ, ARG2(2, STR, STR) }, + { "strstr", CFG_PRED_STRSTR, ARG2(2, STR, STR) }, { "version_atleast", CFG_PRED_VERSION_ATLEAST, ARG1(1, STR) }, { "version_before", CFG_PRED_VERSION_BEFORE, ARG1(1, STR) }, { "openssl_version_atleast", CFG_PRED_OSSL_VERSION_ATLEAST, ARG1(1, STR) }, @@ -225,6 +226,10 @@ int cfg_eval_cond_term(const struct cfg_cond_term *term, char **err) ret = strcmp(term->args[0].data.str.area, term->args[1].data.str.area) != 0; break; + case CFG_PRED_STRSTR: // checks if the 2nd arg is found in the first one + ret = strstr(term->args[0].data.str.area, term->args[1].data.str.area) != NULL; + break; + case CFG_PRED_VERSION_ATLEAST: // checks if the current version is at least this one ret = compare_current_version(term->args[0].data.str.area) <= 0; break; -- 1.7.10.4