[PATCH v6 03/15] Remove special cases for non-NXT_CONF_VALUE_ARRAY
Alejandro Colomar
alx.manpages at gmail.com
Tue Feb 15 14:57:43 UTC 2022
The previous commit made the functions accepting
NXT_CONF_VALUE_ARRAY more generic, so that now they can handle
non-arrays correctly. 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.
Signed-off-by: Alejandro Colomar <alx.manpages at gmail.com>
Cc: Nginx Unit <unit at nginx.org>
Cc: "Valentin V. Bartenev" <vbart at nginx.com>
Cc: Zhidao HONG <z.hong at f5.com>
Cc: Igor Sysoev <igor at sysoev.ru>
Cc: Oisin Canty <o.canty at f5.com>
Cc: Andrei Zeliankou <zelenkov at nginx.com>
Cc: Maxim Romanov <m.romanov at f5.com>
---
src/nxt_http_route.c | 45 +++--------------------------------------
src/nxt_http_static.c | 28 ++++++-------------------
src/nxt_openssl.c | 24 ++++++----------------
src/nxt_router.c | 23 ++++++---------------
src/python/nxt_python.c | 9 ---------
5 files changed, 21 insertions(+), 108 deletions(-)
diff --git a/src/nxt_http_route.c b/src/nxt_http_route.c
index 606bf26..71ebf3f 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(table_cv);
size = sizeof(nxt_http_route_table_t)
+ n * sizeof(nxt_http_route_ruleset_t *);
@@ -736,18 +734,6 @@ 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);
@@ -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(cv);
size = sizeof(nxt_http_route_rule_t) + n * sizeof(nxt_http_route_pattern_t);
rule = nxt_mp_alloc(mp, size);
@@ -929,17 +913,6 @@ 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++) {
@@ -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(cv);
size = sizeof(nxt_http_route_addr_rule_t)
+ n * sizeof(nxt_http_route_addr_pattern_t);
@@ -981,16 +952,6 @@ 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);
diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c
index 36c1ebc..6b7cee7 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(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(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 1e08015..a4564f1 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(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(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 52ea0f3..b8ee0c7 100644
--- a/src/nxt_router.c
+++ b/src/nxt_router.c
@@ -1924,25 +1924,14 @@ 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);
-
- for (i = 0; i < n; i++) {
- value = nxt_conf_get_array_element(certificate, i);
-
- nxt_assert(value != NULL);
+ n = nxt_conf_array_elements_count(certificate);
+ for (i = 0; i < n; i++) {
+ value = nxt_conf_get_array_element(certificate, i);
- ret = nxt_router_conf_tls_insert(tmcf, value, skcf,
- tls_init, i == 0);
- if (nxt_slow_path(ret != NXT_OK)) {
- goto fail;
- }
- }
+ 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 8687c86..3edaa08 100644
--- a/src/python/nxt_python.c
+++ b/src/python/nxt_python.c
@@ -411,14 +411,7 @@ 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);
while (n != 0) {
@@ -432,8 +425,6 @@ nxt_python_set_path(nxt_task_t *task, nxt_conf_value_t *value)
value = nxt_conf_get_array_element(array, n);
- value_is_string:
-
nxt_conf_get_string(value, &str);
path = PyString_FromStringAndSize((char *) str.start, str.length);
--
2.34.1
More information about the unit
mailing list