summaryrefslogtreecommitdiff
path: root/src/kike.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/kike.c')
-rw-r--r--src/kike.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/kike.c b/src/kike.c
index 1ae4cee..7f7cdb8 100644
--- a/src/kike.c
+++ b/src/kike.c
@@ -38,6 +38,7 @@ static struct config_item g_config_table[] =
{ "ssl_key", NULL, "Server SSL private key (PEM)" },
{ "max_connections", NULL, "Maximum client connections" },
+ { "ping_interval", "180", "Interval between PING's (sec)" },
{ NULL, NULL, NULL }
};
@@ -360,13 +361,10 @@ channel_free (struct channel *self)
struct server_context
{
- struct str_map config; ///< Server configuration
-
int listen_fd; ///< Listening socket FD
struct client *clients; ///< Clients
SSL_CTX *ssl_ctx; ///< SSL context
- char *server_name; ///< Our server name
struct str_map users; ///< Maps nicknames to clients
struct str_map channels; ///< Maps channel names to data
struct str_map handlers; ///< Message handlers
@@ -375,6 +373,9 @@ struct server_context
bool quitting; ///< User requested quitting
bool polling; ///< The event loop is running
+ struct str_map config; ///< Server configuration
+ char *server_name; ///< Our server name
+ unsigned ping_interval; ///< Ping interval in seconds
struct str_vector motd; ///< MOTD (none if empty)
nl_catd catalog; ///< Message catalog for server msgs
};
@@ -1301,6 +1302,26 @@ irc_initialize_motd (struct server_context *ctx, struct error **e)
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;
+
+ const char *ping_interval = str_map_find (&ctx->config, "ping_interval");
+ hard_assert (ping_interval != NULL); // We have a default value for this
+ if (!xstrtoul (&ul, ping_interval, 10) || ul > UINT_MAX)
+ {
+ error_set (e, "invalid configuration value for `%s': %s",
+ "ping_interval", "the number is invalid or out of range");
+ return false;
+ }
+ ctx->ping_interval = ul;
+ return true;
+}
+
static bool
irc_initialize_server_name (struct server_context *ctx, struct error **e)
{
@@ -1549,6 +1570,7 @@ main (int argc, char *argv[])
|| !irc_initialize_server_name (&ctx, &e)
|| !irc_initialize_motd (&ctx, &e)
|| !irc_initialize_catalog (&ctx, &e)
+ || !irc_parse_config (&ctx, &e)
|| !irc_listen (&ctx, &e))
{
print_error ("%s", e->message);