diff --git a/src/kike.c b/src/kike.c index 60774cf..faea7b9 100644 --- a/src/kike.c +++ b/src/kike.c @@ -22,6 +22,7 @@ #define PROGRAM_VERSION "alpha" #include "common.c" +#include // --- Configuration (application-specific) ------------------------------------ @@ -29,6 +30,7 @@ static struct config_item g_config_table[] = { { "server_name", NULL, "Server name" }, { "motd", NULL, "MOTD filename" }, + { "catalog", NULL, "catgets localization catalog" }, { "bind_host", NULL, "Address of the IRC server" }, { "bind_port", "6667", "Port of the IRC server" }, @@ -325,6 +327,7 @@ struct server_context bool polling; ///< The event loop is running struct str_vector motd; ///< MOTD (none if empty) + nl_catd catalog; ///< Message catalog for server msgs }; static void @@ -347,6 +350,7 @@ server_context_init (struct server_context *self) self->polling = false; str_vector_init (&self->motd); + self->catalog = (nl_catd) -1; } static void @@ -374,6 +378,8 @@ server_context_free (struct server_context *self) poller_free (&self->poller); str_vector_free (&self->motd); + if (self->catalog != (nl_catd) -1) + catclose (self->catalog); } // --- Main program ------------------------------------------------------------ @@ -794,6 +800,24 @@ error_ssl_1: return false; } +static bool +irc_initialize_catalog (struct server_context *ctx, struct error **e) +{ + hard_assert (ctx->catalog == (nl_catd) -1); + const char *catalog = str_map_find (&ctx->config, "catalog"); + if (!catalog) + return true; + + ctx->catalog = catopen (catalog, NL_CAT_LOCALE); + if (ctx->catalog == (nl_catd) -1) + { + error_set (e, IO_ERROR, IO_ERROR_FAILED, "%s: %s", + "failed reading the message catalog file", strerror (errno)); + return false; + } + return true; +} + static bool irc_initialize_motd (struct server_context *ctx, struct error **e) { @@ -1046,7 +1070,8 @@ main (int argc, char *argv[]) if (!irc_initialize_ssl (&ctx)) exit (EXIT_FAILURE); - if (!irc_listen (&ctx, &e)) + if (!irc_initialize_catalog (&ctx, &e) + || !irc_listen (&ctx, &e)) { print_error ("%s", e->message); error_free (e);