summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/configfile-glue.c16
-rw-r--r--src/configfile.c15
-rw-r--r--src/mod_cgi.c6
-rw-r--r--src/mod_dirlisting.c6
-rw-r--r--src/mod_nss.c5
-rw-r--r--src/mod_openssl.c5
-rw-r--r--src/mod_proxy.c5
-rw-r--r--src/mod_redirect.c6
-rw-r--r--src/mod_rewrite.c6
-rw-r--r--src/mod_trigger_b4_dl.c6
-rw-r--r--src/mod_wolfssl.c5
-rw-r--r--src/plugin_config.h8
-rw-r--r--src/server.c38
13 files changed, 48 insertions, 79 deletions
diff --git a/src/configfile-glue.c b/src/configfile-glue.c
index 7b63a233..feadf2ba 100644
--- a/src/configfile-glue.c
+++ b/src/configfile-glue.c
@@ -39,6 +39,22 @@ void config_get_config_cond_info(config_cond_info * const cfginfo, uint32_t idx)
cfginfo->comp_key = dc->comp_key;
}
+int config_feature_bool (const server *srv, const char *feature, int default_value) {
+ return srv->srvconf.feature_flags
+ ? config_plugin_value_tobool(
+ array_get_element_klen(srv->srvconf.feature_flags,
+ feature, strlen(feature)), default_value)
+ : default_value;
+}
+
+int32_t config_feature_int (const server *srv, const char *feature, int32_t default_value) {
+ return srv->srvconf.feature_flags
+ ? config_plugin_value_to_int32(
+ array_get_element_klen(srv->srvconf.feature_flags,
+ feature, strlen(feature)), default_value)
+ : default_value;
+}
+
int config_plugin_value_tobool (const data_unset *du, int default_value)
{
if (NULL == du) return default_value;
diff --git a/src/configfile.c b/src/configfile.c
index 84138845..63dd3982 100644
--- a/src/configfile.c
+++ b/src/configfile.c
@@ -246,11 +246,7 @@ static void config_burl_normalize_cond (server * const srv) {
}
static int config_pcre_keyvalue (server * const srv) {
- const int pcre_jit =
- !srv->srvconf.feature_flags
- || config_plugin_value_tobool(
- array_get_element_klen(srv->srvconf.feature_flags,
- CONST_STR_LEN("server.pcre_jit")), 1);
+ const int pcre_jit = config_feature_bool(srv, "server.pcre_jit", 1);
for (uint32_t i = 0; i < srv->config_context->used; ++i) {
data_config * const dc = (data_config *)srv->config_context->data[i];
if (dc->cond != CONFIG_COND_NOMATCH && dc->cond != CONFIG_COND_MATCH)
@@ -1570,13 +1566,8 @@ int config_log_error_open(server *srv) {
}
}
- if (NULL != srv->srvconf.feature_flags) {
- data_unset * const du =
- array_get_data_unset(srv->srvconf.feature_flags,
- CONST_STR_LEN("server.errorlog-high-precision"));
- if (config_plugin_value_tobool(du, 0))
- log_set_global_errh(srv->errh, 1);
- }
+ if (config_feature_bool(srv, "server.errorlog-high-precision", 0))
+ log_set_global_errh(srv->errh, 1);
if (srv->srvconf.errorlog_use_syslog) /*(restricted to global scope)*/
config_log_error_open_syslog(srv, srv->errh,
diff --git a/src/mod_cgi.c b/src/mod_cgi.c
index f7aa53bc..36887370 100644
--- a/src/mod_cgi.c
+++ b/src/mod_cgi.c
@@ -374,11 +374,7 @@ SETDEFAULTS_FUNC(mod_cgi_set_defaults) {
mod_cgi_merge_config(&p->defaults, cpv);
}
- p->tempfile_accum =
- !srv->srvconf.feature_flags
- || config_plugin_value_tobool(
- array_get_element_klen(srv->srvconf.feature_flags,
- CONST_STR_LEN("cgi.tempfile-accum")), 1);
+ p->tempfile_accum = config_feature_bool(srv, "cgi.tempfile-accum", 1);
return HANDLER_GO_ON;
}
diff --git a/src/mod_dirlisting.c b/src/mod_dirlisting.c
index f727db59..6d312a17 100644
--- a/src/mod_dirlisting.c
+++ b/src/mod_dirlisting.c
@@ -203,11 +203,7 @@ static struct dirlist_cache * mod_dirlisting_parse_cache(server *srv, const arra
static pcre_keyvalue_buffer * mod_dirlisting_parse_excludes(server *srv, const array *a) {
- const int pcre_jit =
- !srv->srvconf.feature_flags
- || config_plugin_value_tobool(
- array_get_element_klen(srv->srvconf.feature_flags,
- CONST_STR_LEN("server.pcre_jit")), 1);
+ const int pcre_jit = config_feature_bool(srv, "server.pcre_jit", 1);
pcre_keyvalue_buffer * const kvb = pcre_keyvalue_buffer_init();
buffer empty = { NULL, 0, 0 };
for (uint32_t j = 0; j < a->used; ++j) {
diff --git a/src/mod_nss.c b/src/mod_nss.c
index 650bc329..3f3e5db5 100644
--- a/src/mod_nss.c
+++ b/src/mod_nss.c
@@ -1600,10 +1600,7 @@ network_init_ssl (server *srv, plugin_config_socket *s, plugin_data *p)
UNUSED(p);
const int disable_sess_cache =
- srv->srvconf.feature_flags
- && !config_plugin_value_tobool(
- array_get_element_klen(srv->srvconf.feature_flags,
- CONST_STR_LEN("ssl.session-cache")), 0);
+ !config_feature_bool(srv, "ssl.session-cache", 0);
if (!disable_sess_cache) /* undo disable from mod_nss_init_once_nss() */
SSL_OptionSetDefault(SSL_NO_CACHE, PR_FALSE);
diff --git a/src/mod_openssl.c b/src/mod_openssl.c
index da2d0665..e3f15d55 100644
--- a/src/mod_openssl.c
+++ b/src/mod_openssl.c
@@ -2151,10 +2151,7 @@ network_init_ssl (server *srv, plugin_config_socket *s, plugin_data *p)
}
const int disable_sess_cache =
- srv->srvconf.feature_flags
- && !config_plugin_value_tobool(
- array_get_element_klen(srv->srvconf.feature_flags,
- CONST_STR_LEN("ssl.session-cache")), 0);
+ !config_feature_bool(srv, "ssl.session-cache", 0);
if (disable_sess_cache)
/* disable session cache; session tickets are preferred */
SSL_CTX_set_session_cache_mode(s->ssl_ctx,
diff --git a/src/mod_proxy.c b/src/mod_proxy.c
index 9b824660..92cb26a0 100644
--- a/src/mod_proxy.c
+++ b/src/mod_proxy.c
@@ -366,10 +366,7 @@ SETDEFAULTS_FUNC(mod_proxy_set_defaults)
/*p->defaults.balance = (unsigned int)gw_get_defaults_balance(srv, NULL);*/
p->defaults.header.force_http10 =
- srv->srvconf.feature_flags
- && config_plugin_value_tobool(
- array_get_element_klen(srv->srvconf.feature_flags,
- CONST_STR_LEN("proxy.force-http10")), 0);
+ config_feature_bool(srv, "proxy.force-http10", 0);
/* initialize p->defaults from global config context */
if (p->nconfig > 0 && p->cvlist->v.u2[1]) {
diff --git a/src/mod_redirect.c b/src/mod_redirect.c
index 998b343a..638b60af 100644
--- a/src/mod_redirect.c
+++ b/src/mod_redirect.c
@@ -76,11 +76,7 @@ static void mod_redirect_patch_config(request_st * const r, plugin_data * const
}
static pcre_keyvalue_buffer * mod_redirect_parse_list(server *srv, const array *a, const int condidx) {
- const int pcre_jit =
- !srv->srvconf.feature_flags
- || config_plugin_value_tobool(
- array_get_element_klen(srv->srvconf.feature_flags,
- CONST_STR_LEN("server.pcre_jit")), 1);
+ const int pcre_jit = config_feature_bool(srv, "server.pcre_jit", 1);
pcre_keyvalue_buffer * const kvb = pcre_keyvalue_buffer_init();
kvb->x0 = (unsigned short)condidx;
buffer * const tb = srv->tmp_buf;
diff --git a/src/mod_rewrite.c b/src/mod_rewrite.c
index 60a62feb..79c44683 100644
--- a/src/mod_rewrite.c
+++ b/src/mod_rewrite.c
@@ -94,11 +94,7 @@ static void mod_rewrite_patch_config(request_st * const r, plugin_data * const p
}
static pcre_keyvalue_buffer * mod_rewrite_parse_list(server *srv, const array *a, pcre_keyvalue_buffer *kvb, const int condidx) {
- const int pcre_jit =
- !srv->srvconf.feature_flags
- || config_plugin_value_tobool(
- array_get_element_klen(srv->srvconf.feature_flags,
- CONST_STR_LEN("server.pcre_jit")), 1);
+ const int pcre_jit = config_feature_bool(srv, "server.pcre_jit", 1);
int allocated = 0;
if (NULL == kvb) {
allocated = 1;
diff --git a/src/mod_trigger_b4_dl.c b/src/mod_trigger_b4_dl.c
index dd8fe974..940a9978 100644
--- a/src/mod_trigger_b4_dl.c
+++ b/src/mod_trigger_b4_dl.c
@@ -164,11 +164,7 @@ static int mod_trigger_b4_dl_init_regex(server * const srv, config_plugin_value_
return 1;
}
- const int pcre_jit =
- !srv->srvconf.feature_flags
- || config_plugin_value_tobool(
- array_get_element_klen(srv->srvconf.feature_flags,
- CONST_STR_LEN("server.pcre_jit")), 1);
+ const int pcre_jit = config_feature_bool(srv, "server.pcre_jit", 1);
pcre_keyvalue_buffer * const kvb = pcre_keyvalue_buffer_init();
buffer empty = { NULL, 0, 0 };
if (!pcre_keyvalue_buffer_append(srv->errh, kvb, b, &empty, pcre_jit)) {
diff --git a/src/mod_wolfssl.c b/src/mod_wolfssl.c
index 4daca8e3..565b3a45 100644
--- a/src/mod_wolfssl.c
+++ b/src/mod_wolfssl.c
@@ -1974,10 +1974,7 @@ network_init_ssl (server *srv, plugin_config_socket *s, plugin_data *p)
#if !defined(NO_SESSION_CACHE)
const int disable_sess_cache =
- srv->srvconf.feature_flags
- && !config_plugin_value_tobool(
- array_get_element_klen(srv->srvconf.feature_flags,
- CONST_STR_LEN("ssl.session-cache")), 0);
+ !config_feature_bool(srv, "ssl.session-cache", 0);
if (disable_sess_cache)
/* disable session cache; session tickets are preferred */
SSL_CTX_set_session_cache_mode(s->ssl_ctx,
diff --git a/src/plugin_config.h b/src/plugin_config.h
index e6a12f2f..4b96f679 100644
--- a/src/plugin_config.h
+++ b/src/plugin_config.h
@@ -173,4 +173,12 @@ typedef struct cond_match_t {
int config_check_cond(request_st *r, int context_ndx);
+__attribute_cold__
+__attribute_pure__
+int config_feature_bool (const server *srv, const char *feature, int default_value);
+
+__attribute_cold__
+__attribute_pure__
+int32_t config_feature_int (const server *srv, const char *feature, int32_t default_value);
+
#endif
diff --git a/src/server.c b/src/server.c
index 0007e246..ff40106e 100644
--- a/src/server.c
+++ b/src/server.c
@@ -256,11 +256,8 @@ server_epoch_secs (server * const srv)
log_error(srv->errh, __FILE__, __LINE__,
"warning: clock jumped %lld secs",
(long long)((int64_t)new_ts - (int64_t)cur_ts));
- data_unset * const du = (NULL != srv->srvconf.feature_flags)
- ? array_get_data_unset(srv->srvconf.feature_flags,
- CONST_STR_LEN("server.clock-jump-restart"))
- : NULL;
- int delta = config_plugin_value_to_int32(du, 1800);/*(30 mins default)*/
+ int delta = /*(30 mins default)*/
+ config_feature_int(srv, "server.clock-jump-restart", 1800);
if (delta && (new_ts > cur_ts ? new_ts-cur_ts : cur_ts-new_ts) > delta){
log_error(srv->errh, __FILE__, __LINE__,
"attempting graceful restart in < ~5 seconds, else hard restart");
@@ -856,16 +853,15 @@ static int server_graceful_state_bg (server *srv) {
/*assert(graceful_restart);*/
/*(SIGUSR1 set to SIG_IGN in workers, so should not reach here if worker)*/
if (srv_shutdown) return 0;
- if (NULL == srv->srvconf.feature_flags) return 0;
/* check if server should fork and background (bg) itself
* to continue processing requests already in progress */
+ if (!config_feature_bool(srv, "server.graceful-restart-bg", 0)) return 0;
+
+ /*(set flag to false to avoid repeating)*/
data_unset * const du =
array_get_data_unset(srv->srvconf.feature_flags,
CONST_STR_LEN("server.graceful-restart-bg"));
- if (!config_plugin_value_tobool(du, 0)) return 0;
-
- /*(set flag to false to avoid repeating)*/
if (du->type == TYPE_STRING)
buffer_copy_string_len(&((data_string *)du)->value,
CONST_STR_LEN("false"));
@@ -999,11 +995,9 @@ __attribute_noinline__
static void server_graceful_state (server *srv) {
if (!srv_shutdown) {
- if (0 == srv->graceful_expire_ts && srv->srvconf.feature_flags) {
- const data_unset * const du =
- array_get_element_klen(srv->srvconf.feature_flags,
- CONST_STR_LEN("server.graceful-shutdown-timeout"));
- srv->graceful_expire_ts = config_plugin_value_to_int32(du, 0);
+ if (0 == srv->graceful_expire_ts) {
+ srv->graceful_expire_ts =
+ config_feature_int(srv, "server.graceful-shutdown-timeout", 0);
if (srv->graceful_expire_ts)
srv->graceful_expire_ts += log_monotonic_secs;
}
@@ -1265,20 +1259,12 @@ static int server_main_setup (server * const srv, int argc, char **argv) {
}
http_response_send_1xx_cb_set(NULL, HTTP_VERSION_2);
- if (srv->srvconf.feature_flags
- && !config_plugin_value_tobool(
- array_get_element_klen(srv->srvconf.feature_flags,
- CONST_STR_LEN("server.h2-discard-backend-1xx")), 0))
- http_response_send_1xx_cb_set(h2_send_1xx,
- HTTP_VERSION_2);
+ if (!config_feature_bool(srv, "server.h2-discard-backend-1xx", 0))
+ http_response_send_1xx_cb_set(h2_send_1xx, HTTP_VERSION_2);
http_response_send_1xx_cb_set(NULL, HTTP_VERSION_1_1);
- if (srv->srvconf.feature_flags
- && !config_plugin_value_tobool(
- array_get_element_klen(srv->srvconf.feature_flags,
- CONST_STR_LEN("server.h1-discard-backend-1xx")), 0))
- http_response_send_1xx_cb_set(connection_send_1xx,
- HTTP_VERSION_1_1);
+ if (!config_feature_bool(srv, "server.h1-discard-backend-1xx", 0))
+ http_response_send_1xx_cb_set(connection_send_1xx, HTTP_VERSION_1_1);
if (0 != config_set_defaults(srv)) {
log_error(srv->errh, __FILE__, __LINE__,