Browse Source

[multiple] check feature flags funcs; code reuse

config_feature_bool()
config_feature_int()
Glenn Strauss 4 weeks ago
parent
commit
7432841dbf
  1. 16
      src/configfile-glue.c
  2. 15
      src/configfile.c
  3. 6
      src/mod_cgi.c
  4. 6
      src/mod_dirlisting.c
  5. 5
      src/mod_nss.c
  6. 5
      src/mod_openssl.c
  7. 5
      src/mod_proxy.c
  8. 6
      src/mod_redirect.c
  9. 6
      src/mod_rewrite.c
  10. 6
      src/mod_trigger_b4_dl.c
  11. 5
      src/mod_wolfssl.c
  12. 8
      src/plugin_config.h
  13. 38
      src/server.c

16
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;

15
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,

6
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;
}

6
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) {

5
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);

5
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,

5
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]) {

6
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;

6
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;

6
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)) {

5
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,

8
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

38
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__,

Loading…
Cancel
Save