summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_conf_validation.c
diff options
context:
space:
mode:
authorAxel Duch <axel.duch@nginx.com>2020-11-17 15:03:30 +0000
committerAxel Duch <axel.duch@nginx.com>2020-11-17 15:03:30 +0000
commite3af18834d7cc32734cba7532d8864bb343b416b (patch)
tree578c68e31396926abff818cdaf6cb83116157511 /src/nxt_conf_validation.c
parent2a381a82a6e1bc2bd5d2f43a08fce50a1994f2e8 (diff)
downloadunit-e3af18834d7cc32734cba7532d8864bb343b416b.tar.gz
unit-e3af18834d7cc32734cba7532d8864bb343b416b.tar.bz2
Router: matching regular expressions support.
Diffstat (limited to 'src/nxt_conf_validation.c')
-rw-r--r--src/nxt_conf_validation.c35
1 files changed, 33 insertions, 2 deletions
diff --git a/src/nxt_conf_validation.c b/src/nxt_conf_validation.c
index f4e7c358..acb2e3de 100644
--- a/src/nxt_conf_validation.c
+++ b/src/nxt_conf_validation.c
@@ -11,6 +11,7 @@
#include <nxt_http.h>
#include <nxt_sockaddr.h>
#include <nxt_http_route_addr.h>
+#include <nxt_regex.h>
typedef enum {
@@ -1504,8 +1505,12 @@ static nxt_int_t
nxt_conf_vldt_match_pattern(nxt_conf_validation_t *vldt,
nxt_conf_value_t *value)
{
- nxt_str_t pattern;
- nxt_uint_t i, first, last;
+ nxt_str_t pattern;
+ nxt_uint_t i, first, last;
+#if (NXT_HAVE_REGEX)
+ nxt_regex_t *re;
+ nxt_regex_err_t err;
+#endif
if (nxt_conf_type(value) != NXT_CONF_STRING) {
return nxt_conf_vldt_error(vldt, "The \"match\" patterns for \"host\", "
@@ -1519,6 +1524,32 @@ nxt_conf_vldt_match_pattern(nxt_conf_validation_t *vldt,
}
first = (pattern.start[0] == '!');
+
+ if (first < pattern.length && pattern.start[first] == '~') {
+#if (NXT_HAVE_REGEX)
+ pattern.start += first + 1;
+ pattern.length -= first + 1;
+
+ re = nxt_regex_compile(vldt->pool, &pattern, &err);
+ if (nxt_slow_path(re == NULL)) {
+ if (err.offset < pattern.length) {
+ return nxt_conf_vldt_error(vldt, "Invalid regular expression: "
+ "%s at offset %d",
+ err.msg, err.offset);
+ }
+
+ return nxt_conf_vldt_error(vldt, "Invalid regular expression: %s",
+ err.msg);
+ }
+
+ return NXT_OK;
+#else
+ return nxt_conf_vldt_error(vldt, "Unit is built without support of "
+ "regular expressions: \"--no-regex\" "
+ "./configure option was set.");
+#endif
+ }
+
last = pattern.length - 1;
for (i = first; i < last; i++) {