summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/configfile-glue.c17
-rw-r--r--src/mod_auth.c11
-rw-r--r--src/mod_vhostdb.c11
-rw-r--r--src/plugin_config.h3
-rw-r--r--src/server.c12
5 files changed, 31 insertions, 23 deletions
diff --git a/src/configfile-glue.c b/src/configfile-glue.c
index a8e7b42b..c4cd3bf7 100644
--- a/src/configfile-glue.c
+++ b/src/configfile-glue.c
@@ -63,6 +63,23 @@ int config_plugin_value_tobool (data_unset *du, int default_value)
return default_value;
}
+int32_t config_plugin_value_to_int32 (data_unset *du, int32_t default_value)
+{
+ if (NULL == du) return default_value;
+ if (du->type == TYPE_STRING) {
+ const buffer * const b = &((const data_string *)du)->value;
+ char *err;
+ long v = strtol(b->ptr, &err, 10);
+ return (*err=='\0' && err != b->ptr && INT32_MIN <= v && v <= INT32_MAX)
+ ? (int32_t)v
+ : default_value;
+ }
+ else if (du->type == TYPE_INTEGER)
+ return ((const data_integer *)du)->value;
+ else
+ return default_value;
+}
+
int config_plugin_values_init_block(server * const srv, const array * const ca, const config_plugin_keys_t * const cpk, const char * const mname, config_plugin_value_t *cpv) {
/*(cpv must be list with sufficient elements to store all matches + 1)*/
diff --git a/src/mod_auth.c b/src/mod_auth.c
index 731f7a82..6733e967 100644
--- a/src/mod_auth.c
+++ b/src/mod_auth.c
@@ -7,6 +7,7 @@
#include "base.h"
#include "plugin.h"
+#include "plugin_config.h"
#include "http_auth.h"
#include "http_header.h"
#include "log.h"
@@ -96,13 +97,9 @@ http_auth_cache_init (const array *opts)
ac->sptree = NULL;
ac->max_age = 600; /* 10 mins */
for (uint32_t i = 0, used = opts->used; i < used; ++i) {
- data_string *ds = (data_string *)opts->data[i];
- if (buffer_is_equal_string(&ds->key, CONST_STR_LEN("max-age"))) {
- if (ds->type == TYPE_STRING)
- ac->max_age = (time_t)strtol(ds->value.ptr, NULL, 10);
- else if (ds->type == TYPE_INTEGER)
- ac->max_age = (time_t)((data_integer *)ds)->value;
- }
+ data_unset *du = opts->data[i];
+ if (buffer_is_equal_string(&du->key, CONST_STR_LEN("max-age")))
+ ac->max_age = (time_t)config_plugin_value_to_int32(du, ac->max_age);
}
return ac;
}
diff --git a/src/mod_vhostdb.c b/src/mod_vhostdb.c
index e6c7e275..5fdee864 100644
--- a/src/mod_vhostdb.c
+++ b/src/mod_vhostdb.c
@@ -8,6 +8,7 @@
#include "base.h"
#include "plugin.h"
+#include "plugin_config.h"
#include "http_vhostdb.h"
#include "log.h"
#include "stat_cache.h"
@@ -88,13 +89,9 @@ vhostdb_cache_init (const array *opts)
vc->sptree = NULL;
vc->max_age = 600; /* 10 mins */
for (uint32_t i = 0, used = opts->used; i < used; ++i) {
- data_string *ds = (data_string *)opts->data[i];
- if (buffer_is_equal_string(&ds->key, CONST_STR_LEN("max-age"))) {
- if (ds->type == TYPE_STRING)
- vc->max_age = (time_t)strtol(ds->value.ptr, NULL, 10);
- else if (ds->type == TYPE_INTEGER)
- vc->max_age = (time_t)((data_integer *)ds)->value;
- }
+ data_unset *du = opts->data[i];
+ if (buffer_is_equal_string(&du->key, CONST_STR_LEN("max-age")))
+ vc->max_age = (time_t)config_plugin_value_to_int32(du, vc->max_age);
}
return vc;
}
diff --git a/src/plugin_config.h b/src/plugin_config.h
index 9b52568f..a63e2bba 100644
--- a/src/plugin_config.h
+++ b/src/plugin_config.h
@@ -134,6 +134,9 @@ __attribute_cold__
int config_plugin_value_tobool(data_unset *du, int default_value);
__attribute_cold__
+int32_t config_plugin_value_to_int32 (data_unset *du, int32_t default_value);
+
+__attribute_cold__
int config_plugin_values_init_block(server * const srv, const array * const ca, const config_plugin_keys_t * const cpk, const char * const mname, config_plugin_value_t *cpv);
__attribute_cold__
diff --git a/src/server.c b/src/server.c
index 139853d7..8b2aa660 100644
--- a/src/server.c
+++ b/src/server.c
@@ -874,15 +874,9 @@ static void server_graceful_state (server *srv) {
data_unset * const du =
array_get_element_klen(srv->srvconf.feature_flags,
CONST_STR_LEN("server.graceful-shutdown-timeout"));
- if (NULL != du) {
- if (du->type == TYPE_STRING)
- srv->graceful_expire_ts =
- strtol(((data_string *)du)->value.ptr, NULL, 10);
- else if (du->type == TYPE_INTEGER)
- srv->graceful_expire_ts = ((data_integer *)du)->value;
- if (srv->graceful_expire_ts)
- srv->graceful_expire_ts += log_epoch_secs;
- }
+ srv->graceful_expire_ts = config_plugin_value_to_int32(du, 0);
+ if (srv->graceful_expire_ts)
+ srv->graceful_expire_ts += log_epoch_secs;
}
connection_graceful_shutdown_maint(srv);
}