From 20a3f25211c2e33f9f671f2179cd803cef8fa6c8 Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Mon, 15 Jun 2015 22:21:22 +0200
Subject: ZyklonB: factor out plugin_process_ipc()
---
zyklonb.c | 96 +++++++++++++++++++++++++++++++++------------------------------
1 file changed, 50 insertions(+), 46 deletions(-)
diff --git a/zyklonb.c b/zyklonb.c
index 7760ed1..06988d0 100644
--- a/zyklonb.c
+++ b/zyklonb.c
@@ -853,6 +853,55 @@ plugin_send (struct plugin *plugin, const char *format, ...)
plugin_queue_write (plugin);
}
+static void
+plugin_process_ipc (struct plugin *plugin, const struct irc_message *msg)
+{
+ // Replies are sent in the order in which they came in, so there's
+ // no need to attach a special identifier to them. It might be
+ // desirable in some cases, though.
+
+ if (msg->params.len < 1)
+ return;
+
+ const char *command = msg->params.vector[0];
+ if (!plugin->initialized && !strcasecmp (command, "register"))
+ {
+ // Register for relaying of IRC traffic
+ plugin->initialized = true;
+
+ // Flush any queued up traffic here. The point of queuing it in
+ // the first place is so that we don't have to wait for plugin
+ // initialization during startup.
+ //
+ // Note that if we start filtering data coming to the plugins e.g.
+ // based on what it tells us upon registration, we might need to
+ // filter `queued_output' as well.
+ str_append_str (&plugin->write_buffer, &plugin->queued_output);
+ str_free (&plugin->queued_output);
+
+ // NOTE: this may trigger the buffer length check
+ plugin_queue_write (plugin);
+ }
+ else if (!strcasecmp (command, "get_config"))
+ {
+ if (msg->params.len < 2)
+ return;
+
+ const char *value =
+ str_map_find (&plugin->ctx->config, msg->params.vector[1]);
+ // TODO: escape the value (although there's no need to ATM)
+ plugin_send (plugin, "%s :%s",
+ plugin_ipc_command, value ? value : "");
+ }
+ else if (!strcasecmp (command, "print"))
+ {
+ if (msg->params.len < 2)
+ return;
+
+ printf ("%s\n", msg->params.vector[1]);
+ }
+}
+
static void
plugin_process_message (const struct irc_message *msg,
const char *raw, void *user_data)
@@ -864,52 +913,7 @@ plugin_process_message (const struct irc_message *msg,
fprintf (stderr, "[%s] --> \"%s\"\n", plugin->name, raw);
if (!strcasecmp (msg->command, plugin_ipc_command))
- {
- // Replies are sent in the order in which they came in, so there's
- // no need to attach a special identifier to them. It might be
- // desirable in some cases, though.
-
- if (msg->params.len < 1)
- return;
-
- const char *command = msg->params.vector[0];
- if (!plugin->initialized && !strcasecmp (command, "register"))
- {
- // Register for relaying of IRC traffic
- plugin->initialized = true;
-
- // Flush any queued up traffic here. The point of queuing it in
- // the first place is so that we don't have to wait for plugin
- // initialization during startup.
- //
- // Note that if we start filtering data coming to the plugins e.g.
- // based on what it tells us upon registration, we might need to
- // filter `queued_output' as well.
- str_append_str (&plugin->write_buffer, &plugin->queued_output);
- str_free (&plugin->queued_output);
-
- // NOTE: this may trigger the buffer length check
- plugin_queue_write (plugin);
- }
- else if (!strcasecmp (command, "get_config"))
- {
- if (msg->params.len < 2)
- return;
-
- const char *value =
- str_map_find (&ctx->config, msg->params.vector[1]);
- // TODO: escape the value (although there's no need to ATM)
- plugin_send (plugin, "%s :%s",
- plugin_ipc_command, value ? value : "");
- }
- else if (!strcasecmp (command, "print"))
- {
- if (msg->params.len < 2)
- return;
-
- printf ("%s\n", msg->params.vector[1]);
- }
- }
+ plugin_process_ipc (plugin, msg);
else if (plugin->initialized && ctx->irc_registered)
{
// Pass everything else through to the IRC server
--
cgit v1.2.3-70-g09d2