diff options
-rw-r--r-- | src/kike.c | 27 |
1 files changed, 26 insertions, 1 deletions
@@ -22,6 +22,7 @@ #define PROGRAM_VERSION "alpha" #include "common.c" +#include <nl_types.h> // --- 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 ------------------------------------------------------------ @@ -795,6 +801,24 @@ error_ssl_1: } 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) { hard_assert (ctx->motd.len == 0); @@ -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); |