aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kike.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/kike.c b/kike.c
index b886427..1708d2c 100644
--- a/kike.c
+++ b/kike.c
@@ -3680,26 +3680,35 @@ irc_initialize_motd (struct server_context *ctx, struct error **e)
return true;
}
+static bool
+irc_parse_config_unsigned (const char *name, const char *value, unsigned *out,
+ unsigned long min, unsigned long max, struct error **e)
+{
+ unsigned long ul;
+ hard_assert (value != NULL);
+ if (!xstrtoul (&ul, value, 10) || ul > max || ul < min)
+ {
+ error_set (e, "invalid configuration value for `%s': %s",
+ name, "the number is invalid or out of range");
+ return false;
+ }
+ *out = ul;
+ return true;
+}
+
/// This function handles values that require validation before their first use,
/// or some kind of a transformation (such as conversion to an integer) needs
/// to be done before they can be used directly.
static bool
irc_parse_config (struct server_context *ctx, struct error **e)
{
- unsigned long ul;
#define PARSE_UNSIGNED(name, min, max) \
- const char *name = str_map_find (&ctx->config, #name); \
- hard_assert (name != NULL); \
- if (!xstrtoul (&ul, name, 10) || ul > max || ul < min) \
- { \
- error_set (e, "invalid configuration value for `%s': %s", \
- #name, "the number is invalid or out of range"); \
- return false; \
- } \
- ctx->name = ul
-
- PARSE_UNSIGNED (ping_interval, 1, UINT_MAX);
- PARSE_UNSIGNED (max_connections, 0, UINT_MAX);
+ irc_parse_config_unsigned (#name, str_map_find (&ctx->config, #name), \
+ &ctx->name, min, max, e)
+
+ if (!PARSE_UNSIGNED (ping_interval, 1, UINT_MAX)
+ || !PARSE_UNSIGNED (max_connections, 0, UINT_MAX))
+ return false;
bool result = true;
struct strv fingerprints = strv_make ();