summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--zyklonb.c52
1 files changed, 27 insertions, 25 deletions
diff --git a/zyklonb.c b/zyklonb.c
index 549ae21..01c7089 100644
--- a/zyklonb.c
+++ b/zyklonb.c
@@ -57,9 +57,9 @@ static struct config_item g_config_table[] =
// --- Application data --------------------------------------------------------
-struct plugin_data
+struct plugin
{
- LIST_HEADER (struct plugin_data)
+ LIST_HEADER (struct plugin)
struct bot_context *ctx; ///< Parent context
char *name; ///< Plugin identifier
@@ -83,7 +83,7 @@ struct plugin_data
};
static void
-plugin_data_init (struct plugin_data *self)
+plugin_init (struct plugin *self)
{
memset (self, 0, sizeof *self);
@@ -97,7 +97,7 @@ plugin_data_init (struct plugin_data *self)
}
static void
-plugin_data_free (struct plugin_data *self)
+plugin_free (struct plugin *self)
{
soft_assert (self->pid == -1);
free (self->name);
@@ -114,6 +114,8 @@ plugin_data_free (struct plugin_data *self)
str_free (&self->queued_output);
}
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
struct bot_context
{
struct str_map config; ///< User configuration
@@ -134,7 +136,7 @@ struct bot_context
SSL_CTX *ssl_ctx; ///< SSL context
SSL *ssl; ///< SSL connection
- struct plugin_data *plugins; ///< Linked list of plugins
+ struct plugin *plugins; ///< Linked list of plugins
struct str_map plugins_by_name; ///< Indexes @em plugins by their name
struct poller poller; ///< Manages polled descriptors
@@ -190,11 +192,11 @@ bot_context_free (struct bot_context *self)
str_free (&self->read_buffer);
// TODO: terminate the plugins properly before this is called
- struct plugin_data *link, *tmp;
+ struct plugin *link, *tmp;
for (link = self->plugins; link; link = tmp)
{
tmp = link->next;
- plugin_data_free (link);
+ plugin_free (link);
free (link);
}
@@ -230,7 +232,7 @@ try_finish_quit (struct bot_context *ctx)
ctx->polling = false;
}
-static bool plugin_zombify (struct plugin_data *);
+static bool plugin_zombify (struct plugin *);
static void
initiate_quit (struct bot_context *ctx)
@@ -238,7 +240,7 @@ initiate_quit (struct bot_context *ctx)
// Initiate bringing down of the two things that block our shutdown:
// a/ the IRC socket, b/ our child processes:
- for (struct plugin_data *plugin = ctx->plugins;
+ for (struct plugin *plugin = ctx->plugins;
plugin; plugin = plugin->next)
plugin_zombify (plugin);
if (ctx->irc_fd != -1)
@@ -721,10 +723,10 @@ setup_recovery_handler (struct bot_context *ctx, struct error **e)
/// The name of the special IRC command for interprocess communication
static const char *plugin_ipc_command = "ZYKLONB";
-static struct plugin_data *
+static struct plugin *
plugin_find_by_pid (struct bot_context *ctx, pid_t pid)
{
- struct plugin_data *iter;
+ struct plugin *iter;
for (iter = ctx->plugins; iter; iter = iter->next)
if (iter->pid == pid)
return iter;
@@ -732,7 +734,7 @@ plugin_find_by_pid (struct bot_context *ctx, pid_t pid)
}
static bool
-plugin_zombify (struct plugin_data *plugin)
+plugin_zombify (struct plugin *plugin)
{
if (plugin->is_zombie)
return false;
@@ -760,7 +762,7 @@ plugin_zombify (struct plugin_data *plugin)
}
static void
-on_plugin_writable (const struct pollfd *fd, struct plugin_data *plugin)
+on_plugin_writable (const struct pollfd *fd, struct plugin *plugin)
{
struct str *buf = &plugin->write_buffer;
size_t written_total = 0;
@@ -807,7 +809,7 @@ on_plugin_writable (const struct pollfd *fd, struct plugin_data *plugin)
}
static void
-plugin_queue_write (struct plugin_data *plugin)
+plugin_queue_write (struct plugin *plugin)
{
if (plugin->is_zombie)
return;
@@ -826,11 +828,11 @@ plugin_queue_write (struct plugin_data *plugin)
}
static void
-plugin_send (struct plugin_data *plugin, const char *format, ...)
+plugin_send (struct plugin *plugin, const char *format, ...)
ATTRIBUTE_PRINTF (2, 3);
static void
-plugin_send (struct plugin_data *plugin, const char *format, ...)
+plugin_send (struct plugin *plugin, const char *format, ...)
{
va_list ap;
@@ -855,7 +857,7 @@ static void
plugin_process_message (const struct irc_message *msg,
const char *raw, void *user_data)
{
- struct plugin_data *plugin = user_data;
+ struct plugin *plugin = user_data;
struct bot_context *ctx = plugin->ctx;
if (g_debug_mode)
@@ -926,7 +928,7 @@ plugin_process_message (const struct irc_message *msg,
}
static void
-on_plugin_readable (const struct pollfd *fd, struct plugin_data *plugin)
+on_plugin_readable (const struct pollfd *fd, struct plugin *plugin)
{
if (fd->revents & ~(POLLIN | POLLHUP | POLLERR))
print_debug ("fd %d: unexpected revents: %d", fd->fd, fd->revents);
@@ -1076,8 +1078,8 @@ plugin_load (struct bot_context *ctx, const char *name, struct error **e)
set_blocking (stdout_pipe[0], false);
set_blocking (stdin_pipe[1], false);
- struct plugin_data *plugin = xmalloc (sizeof *plugin);
- plugin_data_init (plugin);
+ struct plugin *plugin = xmalloc (sizeof *plugin);
+ plugin_init (plugin);
plugin->ctx = ctx;
plugin->pid = pid;
plugin->name = xstrdup (name);
@@ -1111,7 +1113,7 @@ fail_1:
static bool
plugin_unload (struct bot_context *ctx, const char *name, struct error **e)
{
- struct plugin_data *plugin = str_map_find (&ctx->plugins_by_name, name);
+ struct plugin *plugin = str_map_find (&ctx->plugins_by_name, name);
if (!plugin)
{
@@ -1325,7 +1327,7 @@ process_privmsg (struct bot_context *ctx, const struct irc_message *msg)
"\x02startup reason:\x0f %s; \x02plugins:\x0f ", reason);
size_t zombies = 0;
const char *prepend = "";
- for (struct plugin_data *plugin = ctx->plugins;
+ for (struct plugin *plugin = ctx->plugins;
plugin; plugin = plugin->next)
{
if (plugin->is_zombie)
@@ -1372,7 +1374,7 @@ irc_forward_message_to_plugins (struct bot_context *ctx, const char *raw)
if (!ctx->irc_ready)
return;
- for (struct plugin_data *plugin = ctx->plugins;
+ for (struct plugin *plugin = ctx->plugins;
plugin; plugin = plugin->next)
{
if (plugin->is_zombie)
@@ -1778,7 +1780,7 @@ on_signal_pipe_readable (const struct pollfd *fd, struct bot_context *ctx)
if (zombie == 0)
break;
- struct plugin_data *plugin = plugin_find_by_pid (ctx, zombie);
+ struct plugin *plugin = plugin_find_by_pid (ctx, zombie);
// Something has died but we don't recognize it (re-exec?)
if (!soft_assert (plugin != NULL))
continue;
@@ -1814,7 +1816,7 @@ on_signal_pipe_readable (const struct pollfd *fd, struct bot_context *ctx)
plugin->read_fd = -1;
LIST_UNLINK (ctx->plugins, plugin);
- plugin_data_free (plugin);
+ plugin_free (plugin);
free (plugin);
// Living child processes block us from quitting