summaryrefslogtreecommitdiff
path: root/src/configfile-glue.c
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2020-10-17 10:25:11 -0400
committerGlenn Strauss <gstrauss@gluelogic.com>2020-10-19 21:40:14 -0400
commitd6f692f1c21c79f4dbf68071c7a48a4b2316311a (patch)
tree22e6eea10dfa305f785c0ad7c686d74e1756cc7d /src/configfile-glue.c
parent3d8dcbdd4327c884f1d46fad690a6c01fc441fbd (diff)
downloadlighttpd-git-d6f692f1c21c79f4dbf68071c7a48a4b2316311a.tar.gz
[core] config_plugin_value_to_int32()
Diffstat (limited to 'src/configfile-glue.c')
-rw-r--r--src/configfile-glue.c17
1 files changed, 17 insertions, 0 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)*/