summaryrefslogtreecommitdiff
path: root/zyklonb.c
diff options
context:
space:
mode:
Diffstat (limited to 'zyklonb.c')
-rw-r--r--zyklonb.c56
1 files changed, 23 insertions, 33 deletions
diff --git a/zyklonb.c b/zyklonb.c
index d3de92d..b1a9282 100644
--- a/zyklonb.c
+++ b/zyklonb.c
@@ -89,12 +89,12 @@ plugin_init (struct plugin *self)
memset (self, 0, sizeof *self);
self->pid = -1;
- str_init (&self->queued_output);
+ self->queued_output = str_make ();
self->read_fd = -1;
- str_init (&self->read_buffer);
+ self->read_buffer = str_make ();
self->write_fd = -1;
- str_init (&self->write_buffer);
+ self->write_buffer = str_make ();
}
static void
@@ -152,34 +152,33 @@ static void on_irc_reconnect_timeout (void *user_data);
static void
bot_context_init (struct bot_context *self)
{
- str_map_init (&self->config);
- self->config.free = free;
+ self->config = str_map_make (free);
simple_config_load_defaults (&self->config, g_config_table);
self->admin_re = NULL;
self->irc_fd = -1;
- str_init (&self->read_buffer);
+ self->read_buffer = str_make ();
self->irc_registered = false;
self->ssl = NULL;
self->ssl_ctx = NULL;
self->plugins = NULL;
- str_map_init (&self->plugins_by_name);
+ self->plugins_by_name = str_map_make (NULL);
poller_init (&self->poller);
self->quitting = false;
self->polling = false;
- poller_timer_init (&self->timeout_tmr, &self->poller);
+ self->timeout_tmr = poller_timer_make (&self->poller);
self->timeout_tmr.dispatcher = on_irc_timeout;
self->timeout_tmr.user_data = self;
- poller_timer_init (&self->ping_tmr, &self->poller);
+ self->ping_tmr = poller_timer_make (&self->poller);
self->ping_tmr.dispatcher = on_irc_ping_timeout;
self->ping_tmr.user_data = self;
- poller_timer_init (&self->reconnect_tmr, &self->poller);
+ self->reconnect_tmr = poller_timer_make (&self->poller);
self->reconnect_tmr.dispatcher = on_irc_reconnect_timeout;
self->reconnect_tmr.user_data = self;
}
@@ -272,8 +271,7 @@ irc_send (struct bot_context *ctx, const char *format, ...)
return false;
va_start (ap, format);
- struct str str;
- str_init (&str);
+ struct str str = str_make ();
str_append_vprintf (&str, format, ap);
str_append (&str, "\r\n");
va_end (ap);
@@ -684,7 +682,7 @@ recovery_handler (int signum, siginfo_t *info, void *context)
static void
prepare_recovery_environment (void)
{
- strv_init (&g_recovery_env);
+ g_recovery_env = strv_make ();
strv_append_vector (&g_recovery_env, environ);
// Prepare a location within the environment where we will put the startup
@@ -1047,8 +1045,7 @@ plugin_launch (struct bot_context *ctx, const char *name, struct error **e)
goto fail_1;
}
- struct str work_dir;
- str_init (&work_dir);
+ struct str work_dir = str_make ();
get_xdg_home_dir (&work_dir, "XDG_DATA_HOME", ".local/share");
str_append_printf (&work_dir, "/%s", PROGRAM_NAME);
@@ -1136,11 +1133,11 @@ plugin_load (struct bot_context *ctx, const char *name, struct error **e)
set_blocking (plugin->read_fd, false);
set_blocking (plugin->write_fd, false);
- poller_fd_init (&plugin->read_event, &ctx->poller, plugin->read_fd);
+ plugin->read_event = poller_fd_make (&ctx->poller, plugin->read_fd);
plugin->read_event.dispatcher = (poller_fd_fn) on_plugin_readable;
plugin->read_event.user_data = plugin;
- poller_fd_init (&plugin->write_event, &ctx->poller, plugin->write_fd);
+ plugin->write_event = poller_fd_make (&ctx->poller, plugin->write_fd);
plugin->write_event.dispatcher = (poller_fd_fn) on_plugin_writable;
plugin->write_event.user_data = plugin;
@@ -1173,9 +1170,7 @@ plugin_load_all_from_config (struct bot_context *ctx)
if (!plugin_list)
return;
- struct strv plugins;
- strv_init (&plugins);
-
+ struct strv plugins = strv_make ();
cstr_split (plugin_list, ",", true, &plugins);
for (size_t i = 0; i < plugins.len; i++)
{
@@ -1256,10 +1251,8 @@ respond_to_user (struct bot_context *ctx, const struct irc_message *msg,
strncpy (nick, msg->prefix, sizeof nick - 1);
nick[sizeof nick - 1] = '\0';
- struct str text;
va_list ap;
-
- str_init (&text);
+ struct str text = str_make ();
va_start (ap, format);
str_append_vprintf (&text, format, ap);
va_end (ap);
@@ -1320,9 +1313,7 @@ process_plugin_reload (struct bot_context *ctx,
static char *
make_status_report (struct bot_context *ctx)
{
- struct str report;
- str_init (&report);
-
+ struct str report = str_make ();
const char *reason = getenv (g_startup_reason_str);
if (!reason)
reason = "launched normally";
@@ -1367,8 +1358,7 @@ process_privmsg (struct bot_context *ctx, const struct irc_message *msg)
return;
const char *following;
- struct strv list;
- strv_init (&list);
+ struct strv list = strv_make ();
if (parse_bot_command (text, "quote", &following))
// This seems to replace tons of random stupid commands
@@ -1805,7 +1795,7 @@ irc_connect (struct bot_context *ctx, struct error **e)
}
print_status ("connection established");
- poller_fd_init (&ctx->irc_event, &ctx->poller, ctx->irc_fd);
+ ctx->irc_event = poller_fd_make (&ctx->poller, ctx->irc_fd);
ctx->irc_event.dispatcher = (poller_fd_fn) on_irc_readable;
ctx->irc_event.user_data = ctx;
@@ -1965,7 +1955,7 @@ on_signal_pipe_readable (const struct pollfd *fd, struct bot_context *ctx)
int
main (int argc, char *argv[])
{
- strv_init (&g_original_argv);
+ g_original_argv = strv_make ();
strv_append_vector (&g_original_argv, argv);
static const struct opt opts[] =
@@ -1979,8 +1969,8 @@ main (int argc, char *argv[])
{ 0, NULL, NULL, 0, NULL }
};
- struct opt_handler oh;
- opt_handler_init (&oh, argc, argv, opts, NULL, "Experimental IRC bot.");
+ struct opt_handler oh =
+ opt_handler_make (argc, argv, opts, NULL, "Experimental IRC bot.");
int c;
while ((c = opt_handler_get (&oh)) != -1)
@@ -2022,7 +2012,7 @@ main (int argc, char *argv[])
exit (EXIT_FAILURE);
}
- poller_fd_init (&ctx.signal_event, &ctx.poller, g_signal_pipe[0]);
+ ctx.signal_event = poller_fd_make (&ctx.poller, g_signal_pipe[0]);
ctx.signal_event.dispatcher = (poller_fd_fn) on_signal_pipe_readable;
ctx.signal_event.user_data = &ctx;
poller_fd_set (&ctx.signal_event, POLLIN);