diff options
author | Valentin Bartenev <vbart@nginx.com> | 2018-06-06 16:53:35 +0300 |
---|---|---|
committer | Valentin Bartenev <vbart@nginx.com> | 2018-06-06 16:53:35 +0300 |
commit | ceeb30188152426d76eac1f40ca8ceb24ddb5d0a (patch) | |
tree | 910a973b915b7320746d87b9088fd29b37aafe79 /src/nxt_conf_validation.c | |
parent | 857bddeea613cdf7ce0f9228ec6601285bf3bde7 (diff) | |
download | unit-ceeb30188152426d76eac1f40ca8ceb24ddb5d0a.tar.gz unit-ceeb30188152426d76eac1f40ca8ceb24ddb5d0a.tar.bz2 |
Go: specifying command line arguments to the executable.
This closes #110 issue on GitHub.
Diffstat (limited to 'src/nxt_conf_validation.c')
-rw-r--r-- | src/nxt_conf_validation.c | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/src/nxt_conf_validation.c b/src/nxt_conf_validation.c index f31f3f15..cd5b576f 100644 --- a/src/nxt_conf_validation.c +++ b/src/nxt_conf_validation.c @@ -36,7 +36,8 @@ typedef struct { typedef nxt_int_t (*nxt_conf_vldt_member_t)(nxt_conf_validation_t *vldt, nxt_str_t *name, nxt_conf_value_t *value); - +typedef nxt_int_t (*nxt_conf_vldt_element_t)(nxt_conf_validation_t *vldt, + nxt_conf_value_t *value); typedef nxt_int_t (*nxt_conf_vldt_system_t)(nxt_conf_validation_t *vldt, char *name); @@ -58,12 +59,16 @@ static nxt_int_t nxt_conf_vldt_processes(nxt_conf_validation_t *vldt, nxt_conf_value_t *value, void *data); static nxt_int_t nxt_conf_vldt_object_iterator(nxt_conf_validation_t *vldt, nxt_conf_value_t *value, void *data); +static nxt_int_t nxt_conf_vldt_array_iterator(nxt_conf_validation_t *vldt, + nxt_conf_value_t *value, void *data); static nxt_int_t nxt_conf_vldt_system(nxt_conf_validation_t *vldt, nxt_conf_value_t *value, void *data); static nxt_int_t nxt_conf_vldt_user(nxt_conf_validation_t *vldt, char *name); static nxt_int_t nxt_conf_vldt_group(nxt_conf_validation_t *vldt, char *name); static nxt_int_t nxt_conf_vldt_environment(nxt_conf_validation_t *vldt, nxt_str_t *name, nxt_conf_value_t *value); +static nxt_int_t nxt_conf_vldt_argument(nxt_conf_validation_t *vldt, + nxt_conf_value_t *value); static nxt_conf_vldt_object_t nxt_conf_vldt_root_members[] = { @@ -222,6 +227,11 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_go_members[] = { NULL, NULL }, + { nxt_string("arguments"), + NXT_CONF_VLDT_ARRAY, + &nxt_conf_vldt_array_iterator, + (void *) &nxt_conf_vldt_argument }, + NXT_CONF_VLDT_NEXT(&nxt_conf_vldt_common_members) }; @@ -669,6 +679,33 @@ nxt_conf_vldt_object_iterator(nxt_conf_validation_t *vldt, static nxt_int_t +nxt_conf_vldt_array_iterator(nxt_conf_validation_t *vldt, + nxt_conf_value_t *value, void *data) +{ + uint32_t index; + nxt_int_t ret; + nxt_conf_value_t *element; + nxt_conf_vldt_element_t validator; + + validator = (nxt_conf_vldt_element_t) data; + + for (index = 0; /* void */ ; index++) { + element = nxt_conf_get_array_element(value, index); + + if (element == NULL) { + return NXT_OK; + } + + ret = validator(vldt, element); + + if (ret != NXT_OK) { + return ret; + } + } +} + + +static nxt_int_t nxt_conf_vldt_system(nxt_conf_validation_t *vldt, nxt_conf_value_t *value, void *data) { @@ -768,3 +805,24 @@ nxt_conf_vldt_environment(nxt_conf_validation_t *vldt, nxt_str_t *name, return NXT_OK; } + + +static nxt_int_t +nxt_conf_vldt_argument(nxt_conf_validation_t *vldt, nxt_conf_value_t *value) +{ + nxt_str_t str; + + if (nxt_conf_type(value) != NXT_CONF_STRING) { + return nxt_conf_vldt_error(vldt, "The \"arguments\" array " + "must contain only string values."); + } + + nxt_conf_get_string(value, &str); + + if (nxt_memchr(str.start, '\0', str.length) != NULL) { + return nxt_conf_vldt_error(vldt, "The \"arguments\" array must not " + "contain strings with null character."); + } + + return NXT_OK; +} |