summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_conf_validation.c
diff options
context:
space:
mode:
authorValentin Bartenev <vbart@nginx.com>2019-02-27 16:50:37 +0300
committerValentin Bartenev <vbart@nginx.com>2019-02-27 16:50:37 +0300
commita881c31abdb9fda2ba0d2e05c45c2ce890a6cfab (patch)
treeec477b5d6c011b9468f13cf0224735cf380028ad /src/nxt_conf_validation.c
parentc24c0deb19034726b6450efcd5bce17632177f1b (diff)
downloadunit-a881c31abdb9fda2ba0d2e05c45c2ce890a6cfab.tar.gz
unit-a881c31abdb9fda2ba0d2e05c45c2ce890a6cfab.tar.bz2
Controller: added "routes" configuration.
Diffstat (limited to 'src/nxt_conf_validation.c')
-rw-r--r--src/nxt_conf_validation.c186
1 files changed, 186 insertions, 0 deletions
diff --git a/src/nxt_conf_validation.c b/src/nxt_conf_validation.c
index 3485b4e3..655097fd 100644
--- a/src/nxt_conf_validation.c
+++ b/src/nxt_conf_validation.c
@@ -56,6 +56,16 @@ static nxt_int_t nxt_conf_vldt_certificate(nxt_conf_validation_t *vldt,
#endif
static nxt_int_t nxt_conf_vldt_pass(nxt_conf_validation_t *vldt,
nxt_conf_value_t *value, void *data);
+static nxt_int_t nxt_conf_vldt_routes(nxt_conf_validation_t *vldt,
+ nxt_conf_value_t *value, void *data);
+static nxt_int_t nxt_conf_vldt_routes_member(nxt_conf_validation_t *vldt,
+ nxt_str_t *name, nxt_conf_value_t *value);
+static nxt_int_t nxt_conf_vldt_route(nxt_conf_validation_t *vldt,
+ nxt_conf_value_t *value);
+static nxt_int_t nxt_conf_vldt_match_patterns(nxt_conf_validation_t *vldt,
+ nxt_conf_value_t *value, void *data);
+static nxt_int_t nxt_conf_vldt_match_pattern(nxt_conf_validation_t *vldt,
+ nxt_conf_value_t *value);
static nxt_int_t nxt_conf_vldt_app_name(nxt_conf_validation_t *vldt,
nxt_conf_value_t *value, void *data);
static nxt_int_t nxt_conf_vldt_app(nxt_conf_validation_t *vldt,
@@ -131,6 +141,11 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_root_members[] = {
&nxt_conf_vldt_object_iterator,
(void *) &nxt_conf_vldt_listener },
+ { nxt_string("routes"),
+ NXT_CONF_VLDT_ARRAY | NXT_CONF_VLDT_OBJECT,
+ &nxt_conf_vldt_routes,
+ NULL },
+
{ nxt_string("applications"),
NXT_CONF_VLDT_OBJECT,
&nxt_conf_vldt_object_iterator,
@@ -183,6 +198,51 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_listener_members[] = {
};
+static nxt_conf_vldt_object_t nxt_conf_vldt_match_members[] = {
+ { nxt_string("method"),
+ NXT_CONF_VLDT_STRING | NXT_CONF_VLDT_ARRAY,
+ &nxt_conf_vldt_match_patterns,
+ NULL },
+
+ { nxt_string("host"),
+ NXT_CONF_VLDT_STRING | NXT_CONF_VLDT_ARRAY,
+ &nxt_conf_vldt_match_patterns,
+ NULL },
+
+ { nxt_string("uri"),
+ NXT_CONF_VLDT_STRING | NXT_CONF_VLDT_ARRAY,
+ &nxt_conf_vldt_match_patterns,
+ NULL },
+
+ NXT_CONF_VLDT_END
+};
+
+
+static nxt_conf_vldt_object_t nxt_conf_vldt_action_members[] = {
+ { nxt_string("pass"),
+ NXT_CONF_VLDT_STRING,
+ &nxt_conf_vldt_pass,
+ NULL },
+
+ NXT_CONF_VLDT_END
+};
+
+
+static nxt_conf_vldt_object_t nxt_conf_vldt_route_members[] = {
+ { nxt_string("match"),
+ NXT_CONF_VLDT_OBJECT,
+ &nxt_conf_vldt_object,
+ (void *) &nxt_conf_vldt_match_members },
+
+ { nxt_string("action"),
+ NXT_CONF_VLDT_OBJECT,
+ &nxt_conf_vldt_object,
+ (void *) &nxt_conf_vldt_action_members },
+
+ NXT_CONF_VLDT_END
+};
+
+
static nxt_conf_vldt_object_t nxt_conf_vldt_app_limits_members[] = {
{ nxt_string("timeout"),
NXT_CONF_VLDT_INTEGER,
@@ -550,6 +610,34 @@ nxt_conf_vldt_pass(nxt_conf_validation_t *vldt, nxt_conf_value_t *value,
return NXT_OK;
}
+ if (nxt_str_eq(&first, "routes", 6)) {
+ value = nxt_conf_get_object_member(vldt->conf, &first, NULL);
+
+ if (nxt_slow_path(value == NULL)) {
+ goto error;
+ }
+
+ if (second.length == 0) {
+ if (nxt_conf_type(value) != NXT_CONF_ARRAY) {
+ goto error;
+ }
+
+ return NXT_OK;
+ }
+
+ if (nxt_conf_type(value) != NXT_CONF_OBJECT) {
+ goto error;
+ }
+
+ value = nxt_conf_get_object_member(value, &second, NULL);
+
+ if (nxt_slow_path(value == NULL)) {
+ goto error;
+ }
+
+ return NXT_OK;
+ }
+
error:
return nxt_conf_vldt_error(vldt, "Request \"pass\" points to invalid "
@@ -557,6 +645,104 @@ error:
}
+static nxt_int_t
+nxt_conf_vldt_routes(nxt_conf_validation_t *vldt, nxt_conf_value_t *value,
+ void *data)
+{
+ if (nxt_conf_type(value) == NXT_CONF_ARRAY) {
+ return nxt_conf_vldt_array_iterator(vldt, value,
+ &nxt_conf_vldt_route);
+ }
+
+ /* NXT_CONF_OBJECT */
+
+ return nxt_conf_vldt_object_iterator(vldt, value,
+ &nxt_conf_vldt_routes_member);
+}
+
+
+static nxt_int_t
+nxt_conf_vldt_routes_member(nxt_conf_validation_t *vldt, nxt_str_t *name,
+ nxt_conf_value_t *value)
+{
+ nxt_int_t ret;
+
+ ret = nxt_conf_vldt_type(vldt, name, value, NXT_CONF_VLDT_ARRAY);
+
+ if (ret != NXT_OK) {
+ return ret;
+ }
+
+ return nxt_conf_vldt_array_iterator(vldt, value, &nxt_conf_vldt_route);
+}
+
+
+static nxt_int_t
+nxt_conf_vldt_route(nxt_conf_validation_t *vldt, nxt_conf_value_t *value)
+{
+ if (nxt_conf_type(value) != NXT_CONF_OBJECT) {
+ return nxt_conf_vldt_error(vldt, "The \"routes\" array must contain "
+ "only object values.");
+ }
+
+ return nxt_conf_vldt_object(vldt, value, nxt_conf_vldt_route_members);
+}
+
+
+static nxt_int_t
+nxt_conf_vldt_match_patterns(nxt_conf_validation_t *vldt,
+ nxt_conf_value_t *value, void *data)
+{
+ if (nxt_conf_type(value) == NXT_CONF_ARRAY) {
+ return nxt_conf_vldt_array_iterator(vldt, value,
+ &nxt_conf_vldt_match_pattern);
+ }
+
+ /* NXT_CONF_STRING */
+
+ return nxt_conf_vldt_match_pattern(vldt, value);
+}
+
+
+static nxt_int_t
+nxt_conf_vldt_match_pattern(nxt_conf_validation_t *vldt,
+ nxt_conf_value_t *value)
+{
+ u_char ch;
+ nxt_str_t pattern;
+ nxt_uint_t i, first, last;
+
+ if (nxt_conf_type(value) != NXT_CONF_STRING) {
+ return nxt_conf_vldt_error(vldt,
+ "The \"match\" patterns must be strings.");
+ }
+
+ nxt_conf_get_string(value, &pattern);
+
+ if (pattern.length == 0) {
+ return NXT_OK;
+ }
+
+ first = (pattern.start[0] == '!');
+ last = pattern.length - 1;
+
+ for (i = first; i != pattern.length; i++) {
+ ch = pattern.start[i];
+
+ if (ch != '*') {
+ continue;
+ }
+
+ if (i != first && i != last) {
+ return nxt_conf_vldt_error(vldt, "The \"match\" patterns can only "
+ "contain \"*\" markers at the sides.");
+ }
+ }
+
+ return NXT_OK;
+}
+
+
#if (NXT_TLS)
static nxt_int_t