ZyklonB: struct plugin_data -> plugin

This commit is contained in:
Přemysl Eric Janouch 2015-06-15 00:38:34 +02:00
parent 241acd1ac7
commit 634841ea18
1 changed files with 27 additions and 25 deletions

View File

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