diff options
| author | Přemysl Janouch <p.janouch@gmail.com> | 2015-06-15 22:21:22 +0200 | 
|---|---|---|
| committer | Přemysl Janouch <p.janouch@gmail.com> | 2015-06-15 22:21:22 +0200 | 
| commit | 20a3f25211c2e33f9f671f2179cd803cef8fa6c8 (patch) | |
| tree | be9f98bfcbd60ee8a2c3599899c5b78c59b1de67 /zyklonb.c | |
| parent | ac466d5ac94003a78c1fef5fd4a93269b0a0c957 (diff) | |
| download | xK-20a3f25211c2e33f9f671f2179cd803cef8fa6c8.tar.gz xK-20a3f25211c2e33f9f671f2179cd803cef8fa6c8.tar.xz xK-20a3f25211c2e33f9f671f2179cd803cef8fa6c8.zip | |
ZyklonB: factor out plugin_process_ipc()
Diffstat (limited to 'zyklonb.c')
| -rw-r--r-- | zyklonb.c | 94 | 
1 files changed, 49 insertions, 45 deletions
| @@ -854,62 +854,66 @@ plugin_send (struct plugin *plugin, const char *format, ...)  }  static void -plugin_process_message (const struct irc_message *msg, -	const char *raw, void *user_data) +plugin_process_ipc (struct plugin *plugin, const struct irc_message *msg)  { -	struct plugin *plugin = user_data; -	struct bot_context *ctx = plugin->ctx; +	// 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 (g_debug_mode) -		fprintf (stderr, "[%s] --> \"%s\"\n", plugin->name, raw); +	if (msg->params.len < 1) +		return; -	if (!strcasecmp (msg->command, plugin_ipc_command)) +	const char *command = msg->params.vector[0]; +	if (!plugin->initialized && !strcasecmp (command, "register"))  	{ -		// 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. +		// Register for relaying of IRC traffic +		plugin->initialized = true; -		if (msg->params.len < 1) +		// 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 *command = msg->params.vector[0]; -		if (!plugin->initialized && !strcasecmp (command, "register")) -		{ -			// Register for relaying of IRC traffic -			plugin->initialized = true; +		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; -			// 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); +		printf ("%s\n", msg->params.vector[1]); +	} +} -			// NOTE: this may trigger the buffer length check -			plugin_queue_write (plugin); -		} -		else if (!strcasecmp (command, "get_config")) -		{ -			if (msg->params.len < 2) -				return; +static void +plugin_process_message (const struct irc_message *msg, +	const char *raw, void *user_data) +{ +	struct plugin *plugin = user_data; +	struct bot_context *ctx = plugin->ctx; -			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; +	if (g_debug_mode) +		fprintf (stderr, "[%s] --> \"%s\"\n", plugin->name, raw); -			printf ("%s\n", msg->params.vector[1]); -		} -	} +	if (!strcasecmp (msg->command, plugin_ipc_command)) +		plugin_process_ipc (plugin, msg);  	else if (plugin->initialized && ctx->irc_registered)  	{  		// Pass everything else through to the IRC server | 
