kike: add a `ping_interval' config. value

This commit is contained in:
Přemysl Eric Janouch 2014-08-01 20:50:56 +02:00
parent 16852048ed
commit 9720e30c8b
1 changed files with 25 additions and 3 deletions

View File

@ -38,6 +38,7 @@ static struct config_item g_config_table[] =
{ "ssl_key", NULL, "Server SSL private key (PEM)" }, { "ssl_key", NULL, "Server SSL private key (PEM)" },
{ "max_connections", NULL, "Maximum client connections" }, { "max_connections", NULL, "Maximum client connections" },
{ "ping_interval", "180", "Interval between PING's (sec)" },
{ NULL, NULL, NULL } { NULL, NULL, NULL }
}; };
@ -360,13 +361,10 @@ channel_free (struct channel *self)
struct server_context struct server_context
{ {
struct str_map config; ///< Server configuration
int listen_fd; ///< Listening socket FD int listen_fd; ///< Listening socket FD
struct client *clients; ///< Clients struct client *clients; ///< Clients
SSL_CTX *ssl_ctx; ///< SSL context SSL_CTX *ssl_ctx; ///< SSL context
char *server_name; ///< Our server name
struct str_map users; ///< Maps nicknames to clients struct str_map users; ///< Maps nicknames to clients
struct str_map channels; ///< Maps channel names to data struct str_map channels; ///< Maps channel names to data
struct str_map handlers; ///< Message handlers struct str_map handlers; ///< Message handlers
@ -375,6 +373,9 @@ struct server_context
bool quitting; ///< User requested quitting bool quitting; ///< User requested quitting
bool polling; ///< The event loop is running 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) struct str_vector motd; ///< MOTD (none if empty)
nl_catd catalog; ///< Message catalog for server msgs nl_catd catalog; ///< Message catalog for server msgs
}; };
@ -1301,6 +1302,26 @@ irc_initialize_motd (struct server_context *ctx, struct error **e)
return true; 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 static bool
irc_initialize_server_name (struct server_context *ctx, struct error **e) 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_server_name (&ctx, &e)
|| !irc_initialize_motd (&ctx, &e) || !irc_initialize_motd (&ctx, &e)
|| !irc_initialize_catalog (&ctx, &e) || !irc_initialize_catalog (&ctx, &e)
|| !irc_parse_config (&ctx, &e)
|| !irc_listen (&ctx, &e)) || !irc_listen (&ctx, &e))
{ {
print_error ("%s", e->message); print_error ("%s", e->message);