Browse Source

[core] config_plugin_value_to_int32()

master
Glenn Strauss 3 months ago
parent
commit
d6f692f1c2
5 changed files with 31 additions and 23 deletions
  1. +17
    -0
      src/configfile-glue.c
  2. +4
    -7
      src/mod_auth.c
  3. +4
    -7
      src/mod_vhostdb.c
  4. +3
    -0
      src/plugin_config.h
  5. +3
    -9
      src/server.c

+ 17
- 0
src/configfile-glue.c View File

@ -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)*/


+ 4
- 7
src/mod_auth.c View File

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


+ 4
- 7
src/mod_vhostdb.c View File

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


+ 3
- 0
src/plugin_config.h View File

@ -133,6 +133,9 @@ typedef struct {
__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);


+ 3
- 9
src/server.c View File

@ -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);
}


Loading…
Cancel
Save