summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_conf_validation.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nxt_conf_validation.c')
-rw-r--r--src/nxt_conf_validation.c57
1 files changed, 41 insertions, 16 deletions
diff --git a/src/nxt_conf_validation.c b/src/nxt_conf_validation.c
index 5a1f7839..4282f46b 100644
--- a/src/nxt_conf_validation.c
+++ b/src/nxt_conf_validation.c
@@ -323,17 +323,27 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_match_members[] = {
};
-static nxt_conf_vldt_object_t nxt_conf_vldt_action_members[] = {
+static nxt_conf_vldt_object_t nxt_conf_vldt_pass_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_share_action_members[] = {
{ nxt_string("share"),
NXT_CONF_VLDT_STRING,
NULL,
NULL },
+ NXT_CONF_VLDT_END
+};
+
+
+static nxt_conf_vldt_object_t nxt_conf_vldt_proxy_action_members[] = {
{ nxt_string("proxy"),
NXT_CONF_VLDT_STRING,
&nxt_conf_vldt_proxy,
@@ -912,30 +922,45 @@ static nxt_int_t
nxt_conf_vldt_action(nxt_conf_validation_t *vldt, nxt_conf_value_t *value,
void *data)
{
- nxt_int_t ret;
- nxt_conf_value_t *pass_value, *share_value, *proxy_value;
+ nxt_uint_t i;
+ nxt_conf_value_t *action;
+ nxt_conf_vldt_object_t *members;
+
+ static struct {
+ nxt_str_t name;
+ nxt_conf_vldt_object_t *members;
+
+ } actions[] = {
+ { nxt_string("pass"), nxt_conf_vldt_pass_action_members },
+ { nxt_string("share"), nxt_conf_vldt_share_action_members },
+ { nxt_string("proxy"), nxt_conf_vldt_proxy_action_members },
+ };
- static nxt_str_t pass_str = nxt_string("pass");
- static nxt_str_t share_str = nxt_string("share");
- static nxt_str_t proxy_str = nxt_string("proxy");
+ members = NULL;
- ret = nxt_conf_vldt_object(vldt, value, nxt_conf_vldt_action_members);
+ for (i = 0; i < nxt_nitems(actions); i++) {
+ action = nxt_conf_get_object_member(value, &actions[i].name, NULL);
- if (ret != NXT_OK) {
- return ret;
- }
+ if (action == NULL) {
+ continue;
+ }
- pass_value = nxt_conf_get_object_member(value, &pass_str, NULL);
- share_value = nxt_conf_get_object_member(value, &share_str, NULL);
- proxy_value = nxt_conf_get_object_member(value, &proxy_str, NULL);
+ if (members != NULL) {
+ return nxt_conf_vldt_error(vldt, "The \"action\" object must have "
+ "just one of \"pass\", \"share\" or "
+ "\"proxy\" options set.");
+ }
+
+ members = actions[i].members;
+ }
- if (pass_value == NULL && share_value == NULL && proxy_value == NULL) {
+ if (members == NULL) {
return nxt_conf_vldt_error(vldt, "The \"action\" object must have "
- "either \"pass\" or \"share\" or "
+ "either \"pass\", \"share\", or "
"\"proxy\" option set.");
}
- return NXT_OK;
+ return nxt_conf_vldt_object(vldt, value, members);
}