summaryrefslogtreecommitdiffstats
path: root/cmd-confirm-before.c
diff options
context:
space:
mode:
authornicm <nicm>2016-10-16 17:55:14 +0000
committernicm <nicm>2016-10-16 17:55:14 +0000
commitddc4512d2e0eda6c705e002cb5dbf80719d709e1 (patch)
treecd9ff99f4b1ccb3e76ab99633d59772ae07c3092 /cmd-confirm-before.c
parentbfe14b531267f3762a518f98b72a3148a134396a (diff)
Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues being dispatched on demand from wherever the command happens to be added, they are now all dispatched from the top level server loop. Command queues may now also include callbacks as well as commands, and items may be inserted after the current command as well as at the end. This all makes command queues significantly more predictable and easier to use, and avoids the complex multiple nested command queues used by source-file, if-shell and friends. A mass rename of struct cmdq to a better name (cmdq_item probably) is coming.
Diffstat (limited to 'cmd-confirm-before.c')
-rw-r--r--cmd-confirm-before.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/cmd-confirm-before.c b/cmd-confirm-before.c
index 4241aefb..2dd52c81 100644
--- a/cmd-confirm-before.c
+++ b/cmd-confirm-before.c
@@ -83,12 +83,24 @@ cmd_confirm_before_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_NORMAL);
}
+static enum cmd_retval
+cmd_confirm_before_error(struct cmd_q *cmdq, void *data)
+{
+ char *error = data;
+
+ cmdq_error(cmdq, "%s", error);
+ free(error);
+
+ return (CMD_RETURN_NORMAL);
+}
+
static int
cmd_confirm_before_callback(void *data, const char *s)
{
struct cmd_confirm_before_data *cdata = data;
struct client *c = cdata->client;
struct cmd_list *cmdlist;
+ struct cmd_q *new_cmdq;
char *cause;
if (c->flags & CLIENT_DEAD)
@@ -101,14 +113,17 @@ cmd_confirm_before_callback(void *data, const char *s)
if (cmd_string_parse(cdata->cmd, &cmdlist, NULL, 0, &cause) != 0) {
if (cause != NULL) {
- cmdq_error(c->cmdq, "%s", cause);
- free(cause);
- }
- return (0);
+ new_cmdq = cmdq_get_callback(cmd_confirm_before_error,
+ cause);
+ } else
+ new_cmdq = NULL;
+ } else {
+ new_cmdq = cmdq_get_command(cmdlist, NULL, NULL, 0);
+ cmd_list_free(cmdlist);
}
- cmdq_run(c->cmdq, cmdlist, NULL);
- cmd_list_free(cmdlist);
+ if (new_cmdq != NULL)
+ cmdq_append(c, new_cmdq);
return (0);
}