summaryrefslogtreecommitdiff
path: root/src/kike.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/kike.c')
-rw-r--r--src/kike.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/kike.c b/src/kike.c
index 9734f2b..60774cf 100644
--- a/src/kike.c
+++ b/src/kike.c
@@ -28,6 +28,8 @@
static struct config_item g_config_table[] =
{
{ "server_name", NULL, "Server name" },
+ { "motd", NULL, "MOTD filename" },
+
{ "bind_host", NULL, "Address of the IRC server" },
{ "bind_port", "6667", "Port of the IRC server" },
{ "ssl_cert", NULL, "Server SSL certificate (PEM)" },
@@ -321,6 +323,8 @@ struct server_context
struct poller poller; ///< Manages polled description
bool quitting; ///< User requested quitting
bool polling; ///< The event loop is running
+
+ struct str_vector motd; ///< MOTD (none if empty)
};
static void
@@ -341,6 +345,8 @@ server_context_init (struct server_context *self)
poller_init (&self->poller);
self->quitting = false;
self->polling = false;
+
+ str_vector_init (&self->motd);
}
static void
@@ -366,6 +372,8 @@ server_context_free (struct server_context *self)
str_map_free (&self->users);
str_map_free (&self->channels);
poller_free (&self->poller);
+
+ str_vector_free (&self->motd);
}
// --- Main program ------------------------------------------------------------
@@ -787,6 +795,32 @@ error_ssl_1:
}
static bool
+irc_initialize_motd (struct server_context *ctx, struct error **e)
+{
+ hard_assert (ctx->motd.len == 0);
+ const char *motd = str_map_find (&ctx->config, "motd");
+ if (!motd)
+ return true;
+
+ FILE *fp = fopen (motd, "r");
+ if (!fp)
+ {
+ error_set (e, IO_ERROR, IO_ERROR_FAILED,
+ "%s: %s", "failed reading the MOTD file", strerror (errno));
+ return false;
+ }
+
+ struct str line;
+ str_init (&line);
+ while (read_line (fp, &line))
+ str_vector_add_owned (&ctx->motd, str_steal (&line));
+ str_free (&line);
+
+ fclose (fp);
+ return true;
+}
+
+static bool
irc_initialize_server_name (struct server_context *ctx, struct error **e)
{
enum validation_result res;
@@ -834,6 +868,8 @@ irc_listen (struct server_context *ctx, struct error **e)
if (!irc_initialize_server_name (ctx, e))
return false;
+ if (!irc_initialize_motd (ctx, e))
+ return false;
struct addrinfo gai_hints, *gai_result, *gai_iter;
memset (&gai_hints, 0, sizeof gai_hints);