summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAlejandro Colomar <alx.manpages@gmail.com>2021-12-18 22:58:27 +0100
committerAlejandro Colomar <alx.manpages@gmail.com>2022-04-26 12:38:48 +0200
commitbce0f432c402ad18718aecab227b663160682ea4 (patch)
tree01f5091fc6bf12a2deb937b5ad434b65cbe8df62
parente525605d057fd923aa2728babe5b49e95d86d22b (diff)
downloadunit-bce0f432c402ad18718aecab227b663160682ea4.tar.gz
unit-bce0f432c402ad18718aecab227b663160682ea4.tar.bz2
Removed special cases for non-NXT_CONF_VALUE_ARRAY.
The previous commit added more generic APIs for handling NXT_CONF_VALUE_ARRAY and non-NXT_CONF_VALUE_ARRAY together. Modify calling code to remove special cases for arrays and non-arrays, taking special care that the path for non arrays is logically equivalent to the previous special cased code. Use the now-generic array code only.
-rw-r--r--src/nxt_http_route.c51
-rw-r--r--src/nxt_http_static.c28
-rw-r--r--src/nxt_openssl.c24
-rw-r--r--src/nxt_router.c24
-rw-r--r--src/python/nxt_python.c13
5 files changed, 27 insertions, 113 deletions
diff --git a/src/nxt_http_route.c b/src/nxt_http_route.c
index 606bf266..9add051b 100644
--- a/src/nxt_http_route.c
+++ b/src/nxt_http_route.c
@@ -718,13 +718,11 @@ nxt_http_route_table_create(nxt_task_t *task, nxt_mp_t *mp,
{
size_t size;
uint32_t i, n;
- nxt_bool_t array;
nxt_conf_value_t *ruleset_cv;
nxt_http_route_table_t *table;
nxt_http_route_ruleset_t *ruleset;
- array = (nxt_conf_type(table_cv) == NXT_CONF_ARRAY);
- n = array ? nxt_conf_array_elements_count(table_cv) : 1;
+ n = nxt_conf_array_elements_count_or_1(table_cv);
size = sizeof(nxt_http_route_table_t)
+ n * sizeof(nxt_http_route_ruleset_t *);
@@ -736,20 +734,8 @@ nxt_http_route_table_create(nxt_task_t *task, nxt_mp_t *mp,
table->items = n;
table->object = NXT_HTTP_ROUTE_TABLE;
- if (!array) {
- ruleset = nxt_http_route_ruleset_create(task, mp, table_cv, object,
- case_sensitive, encoding);
- if (nxt_slow_path(ruleset == NULL)) {
- return NULL;
- }
-
- table->ruleset[0] = ruleset;
-
- return table;
- }
-
for (i = 0; i < n; i++) {
- ruleset_cv = nxt_conf_get_array_element(table_cv, i);
+ ruleset_cv = nxt_conf_get_array_element_or_itself(table_cv, i);
ruleset = nxt_http_route_ruleset_create(task, mp, ruleset_cv, object,
case_sensitive, encoding);
@@ -911,13 +897,11 @@ nxt_http_route_rule_create(nxt_task_t *task, nxt_mp_t *mp,
size_t size;
uint32_t i, n;
nxt_int_t ret;
- nxt_bool_t string;
nxt_conf_value_t *value;
nxt_http_route_rule_t *rule;
nxt_http_route_pattern_t *pattern;
- string = (nxt_conf_type(cv) != NXT_CONF_ARRAY);
- n = string ? 1 : nxt_conf_array_elements_count(cv);
+ n = nxt_conf_array_elements_count_or_1(cv);
size = sizeof(nxt_http_route_rule_t) + n * sizeof(nxt_http_route_pattern_t);
rule = nxt_mp_alloc(mp, size);
@@ -929,22 +913,11 @@ nxt_http_route_rule_create(nxt_task_t *task, nxt_mp_t *mp,
pattern = &rule->pattern[0];
- if (string) {
- pattern[0].case_sensitive = case_sensitive;
- ret = nxt_http_route_pattern_create(task, mp, cv, &pattern[0],
- pattern_case, encoding);
- if (nxt_slow_path(ret != NXT_OK)) {
- return NULL;
- }
-
- return rule;
- }
-
nxt_conf_array_qsort(cv, nxt_http_pattern_compare);
for (i = 0; i < n; i++) {
pattern[i].case_sensitive = case_sensitive;
- value = nxt_conf_get_array_element(cv, i);
+ value = nxt_conf_get_array_element_or_itself(cv, i);
ret = nxt_http_route_pattern_create(task, mp, value, &pattern[i],
pattern_case, encoding);
@@ -963,13 +936,11 @@ nxt_http_route_addr_rule_create(nxt_task_t *task, nxt_mp_t *mp,
{
size_t size;
uint32_t i, n;
- nxt_bool_t array;
nxt_conf_value_t *value;
nxt_http_route_addr_rule_t *addr_rule;
nxt_http_route_addr_pattern_t *pattern;
- array = (nxt_conf_type(cv) == NXT_CONF_ARRAY);
- n = array ? nxt_conf_array_elements_count(cv) : 1;
+ n = nxt_conf_array_elements_count_or_1(cv);
size = sizeof(nxt_http_route_addr_rule_t)
+ n * sizeof(nxt_http_route_addr_pattern_t);
@@ -981,19 +952,9 @@ nxt_http_route_addr_rule_create(nxt_task_t *task, nxt_mp_t *mp,
addr_rule->items = n;
- if (!array) {
- pattern = &addr_rule->addr_pattern[0];
-
- if (nxt_http_route_addr_pattern_parse(mp, pattern, cv) != NXT_OK) {
- return NULL;
- }
-
- return addr_rule;
- }
-
for (i = 0; i < n; i++) {
pattern = &addr_rule->addr_pattern[i];
- value = nxt_conf_get_array_element(cv, i);
+ value = nxt_conf_get_array_element_or_itself(cv, i);
if (nxt_http_route_addr_pattern_parse(mp, pattern, value) != NXT_OK) {
return NULL;
diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c
index 36c1ebc9..5231f98e 100644
--- a/src/nxt_http_static.c
+++ b/src/nxt_http_static.c
@@ -77,7 +77,6 @@ nxt_http_static_init(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
nxt_mp_t *mp;
nxt_str_t str;
nxt_var_t *var;
- nxt_bool_t array;
nxt_conf_value_t *cv;
nxt_http_static_conf_t *conf;
@@ -91,39 +90,24 @@ nxt_http_static_init(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
action->handler = nxt_http_static;
action->u.conf = conf;
- array = (nxt_conf_type(acf->share) == NXT_CONF_ARRAY);
- conf->nshares = array ? nxt_conf_array_elements_count(acf->share) : 1;
-
+ conf->nshares = nxt_conf_array_elements_count_or_1(acf->share);
conf->shares = nxt_mp_zget(mp, sizeof(nxt_http_static_share_t)
* conf->nshares);
if (nxt_slow_path(conf->shares == NULL)) {
return NXT_ERROR;
}
- if (array) {
- for (i = 0; i < conf->nshares; i++) {
- cv = nxt_conf_get_array_element(acf->share, i);
- nxt_conf_get_string(cv, &str);
-
- var = nxt_var_compile(&str, mp, 1);
- if (nxt_slow_path(var == NULL)) {
- return NXT_ERROR;
- }
-
- conf->shares[i].var = var;
- conf->shares[i].is_const = nxt_var_is_const(var);
- }
-
- } else {
- nxt_conf_get_string(acf->share, &str);
+ for (i = 0; i < conf->nshares; i++) {
+ cv = nxt_conf_get_array_element_or_itself(acf->share, i);
+ nxt_conf_get_string(cv, &str);
var = nxt_var_compile(&str, mp, 1);
if (nxt_slow_path(var == NULL)) {
return NXT_ERROR;
}
- conf->shares[0].var = var;
- conf->shares[0].is_const = nxt_var_is_const(var);
+ conf->shares[i].var = var;
+ conf->shares[i].is_const = nxt_var_is_const(var);
}
#if (NXT_HAVE_OPENAT2)
diff --git a/src/nxt_openssl.c b/src/nxt_openssl.c
index 1e08015e..59c58b2b 100644
--- a/src/nxt_openssl.c
+++ b/src/nxt_openssl.c
@@ -644,16 +644,10 @@ nxt_tls_ticket_keys(nxt_task_t *task, SSL_CTX *ctx, nxt_tls_init_t *tls_init,
return NXT_OK;
}
- if (nxt_conf_type(tickets_conf) == NXT_CONF_ARRAY) {
- count = nxt_conf_array_elements_count(tickets_conf);
+ count = nxt_conf_array_elements_count_or_1(tickets_conf);
- if (count == 0) {
- goto no_ticket;
- }
-
- } else {
- /* nxt_conf_type(tickets_conf) == NXT_CONF_STRING */
- count = 1;
+ if (count == 0) {
+ goto no_ticket;
}
#ifdef SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB
@@ -673,15 +667,9 @@ nxt_tls_ticket_keys(nxt_task_t *task, SSL_CTX *ctx, nxt_tls_init_t *tls_init,
i++;
- if (nxt_conf_type(tickets_conf) == NXT_CONF_ARRAY) {
- member = nxt_conf_get_array_element(tickets_conf, count - i);
- if (member == NULL) {
- break;
- }
-
- } else {
- /* nxt_conf_type(tickets_conf) == NXT_CONF_STRING */
- member = tickets_conf;
+ member = nxt_conf_get_array_element_or_itself(tickets_conf, count - i);
+ if (member == NULL) {
+ break;
}
nxt_conf_get_string(member, &value);
diff --git a/src/nxt_router.c b/src/nxt_router.c
index 52ea0f37..3a32a363 100644
--- a/src/nxt_router.c
+++ b/src/nxt_router.c
@@ -1924,25 +1924,15 @@ nxt_router_conf_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
tls_init->tickets_conf = nxt_conf_get_path(listener,
&conf_tickets);
- if (nxt_conf_type(certificate) == NXT_CONF_ARRAY) {
- n = nxt_conf_array_elements_count(certificate);
+ n = nxt_conf_array_elements_count_or_1(certificate);
- for (i = 0; i < n; i++) {
- value = nxt_conf_get_array_element(certificate, i);
-
- nxt_assert(value != NULL);
-
- ret = nxt_router_conf_tls_insert(tmcf, value, skcf,
- tls_init, i == 0);
- if (nxt_slow_path(ret != NXT_OK)) {
- goto fail;
- }
- }
+ for (i = 0; i < n; i++) {
+ value = nxt_conf_get_array_element_or_itself(certificate,
+ i);
+ nxt_assert(value != NULL);
- } else {
- /* NXT_CONF_STRING */
- ret = nxt_router_conf_tls_insert(tmcf, certificate, skcf,
- tls_init, 1);
+ ret = nxt_router_conf_tls_insert(tmcf, value, skcf,
+ tls_init, i == 0);
if (nxt_slow_path(ret != NXT_OK)) {
goto fail;
}
diff --git a/src/python/nxt_python.c b/src/python/nxt_python.c
index 8687c869..188c4920 100644
--- a/src/python/nxt_python.c
+++ b/src/python/nxt_python.c
@@ -411,15 +411,8 @@ nxt_python_set_path(nxt_task_t *task, nxt_conf_value_t *value)
/* sys is a Borrowed reference. */
- if (nxt_conf_type(value) == NXT_CONF_STRING) {
- n = 0;
- goto value_is_string;
- }
-
- /* NXT_CONF_ARRAY */
array = value;
-
- n = nxt_conf_array_elements_count(array);
+ n = nxt_conf_array_elements_count_or_1(array);
while (n != 0) {
n--;
@@ -430,9 +423,7 @@ nxt_python_set_path(nxt_task_t *task, nxt_conf_value_t *value)
* specified in the "path" option.
*/
- value = nxt_conf_get_array_element(array, n);
-
- value_is_string:
+ value = nxt_conf_get_array_element_or_itself(array, n);
nxt_conf_get_string(value, &str);