diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2014-08-01 20:50:56 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2014-08-02 20:36:40 +0200 |
commit | 9720e30c8bca98cc20730cdb9650ac2f4dc02472 (patch) | |
tree | 4adbbbd31e63ed875c46a35d740b013c1a9d0b8c | |
parent | 16852048ed0f781761c79e8f0d46c8331d5fcd25 (diff) | |
download | xK-9720e30c8bca98cc20730cdb9650ac2f4dc02472.tar.gz xK-9720e30c8bca98cc20730cdb9650ac2f4dc02472.tar.xz xK-9720e30c8bca98cc20730cdb9650ac2f4dc02472.zip |
kike: add a `ping_interval' config. value
-rw-r--r-- | src/kike.c | 28 |
1 files changed, 25 insertions, 3 deletions
@@ -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); |