]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap: Add client_command_context.event and use it as global event while running
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 21 Nov 2017 15:05:30 +0000 (16:05 +0100)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 13 Dec 2017 11:22:17 +0000 (13:22 +0200)
src/imap/imap-client.c
src/imap/imap-client.h
src/imap/imap-commands.c
src/imap/imap-notify.c
src/imap/imap-state.c

index 3a9c3c236d2c04c3044b1f22bfe2572a6066d83a..856628748b4daa02f901e20f4a25ad0a72248ee2 100644 (file)
@@ -833,6 +833,7 @@ struct client_command_context *client_command_alloc(struct client *client)
        cmd = p_new(client->command_pool, struct client_command_context, 1);
        cmd->client = client;
        cmd->pool = client->command_pool;
+       cmd->event = event_create(client->event);
        cmd->stats.start_time = ioloop_timeval;
        cmd->stats.last_run_timeval = ioloop_timeval;
        cmd->stats.start_ioloop_wait_usecs =
@@ -846,6 +847,16 @@ struct client_command_context *client_command_alloc(struct client *client)
        return cmd;
 }
 
+void client_command_init_finished(struct client_command_context *cmd)
+{
+       event_add_str(cmd->event, "tag", cmd->tag);
+       event_add_str(cmd->event, "name", cmd->name);
+       if (cmd->args != NULL)
+               event_add_str(cmd->event, "args", cmd->args);
+       if (cmd->human_args != NULL)
+               event_add_str(cmd->event, "human_args", cmd->human_args);
+}
+
 static struct client_command_context *
 client_command_new(struct client *client)
 {
@@ -903,6 +914,7 @@ void client_command_free(struct client_command_context **_cmd)
                client->input_lock = NULL;
        if (client->mailbox_change_lock == cmd)
                client->mailbox_change_lock = NULL;
+       event_unref(&cmd->event);
 
        if (cmd->parser != NULL) {
                if (client->free_parser == NULL) {
@@ -1125,6 +1137,7 @@ static bool client_command_input(struct client_command_context *cmd)
                }
                cmd->name = !cmd->uid ? p_strdup(cmd->pool, cmd->name) :
                        p_strconcat(cmd->pool, "UID ", cmd->name, NULL);
+               client_command_init_finished(cmd);
                imap_refresh_proctitle();
        }
 
index 3ccb83dfae13fa0f23692645ef4ac6f5b271db8a..fc5edb7ba166fa9ae77afb27b97a6617e9a2c4b2 100644 (file)
@@ -78,6 +78,7 @@ struct client_command_stats_start {
 struct client_command_context {
        struct client_command_context *prev, *next;
        struct client *client;
+       struct event *event;
 
        pool_t pool;
        /* IMAP command tag */
@@ -310,6 +311,7 @@ client_search_update_lookup(struct client *client, const char *tag,
 void client_search_updates_free(struct client *client);
 
 struct client_command_context *client_command_alloc(struct client *client);
+void client_command_init_finished(struct client_command_context *cmd);
 void client_command_cancel(struct client_command_context **cmd);
 void client_command_free(struct client_command_context **cmd);
 
index f11816b964c83cb83a3ebfc76ff44a113ff763e1..8fac8c74986b6c89e31658582e3d69a45a83b6ae 100644 (file)
@@ -194,6 +194,7 @@ bool command_exec(struct client_command_context *cmd)
        io_loop_time_refresh();
        command_stats_start(cmd);
 
+       event_push_global(cmd->event);
        cmd->executing = TRUE;
        array_foreach(&command_hooks, hook)
                hook->pre(cmd);
@@ -201,6 +202,7 @@ bool command_exec(struct client_command_context *cmd)
        array_foreach(&command_hooks, hook)
                hook->post(cmd);
        cmd->executing = FALSE;
+       event_pop_global(cmd->event);
        if (cmd->state == CLIENT_COMMAND_STATE_DONE)
                finished = TRUE;
 
index 7b964eec935a47813bdb6a1f5e104ab3a0abc787..4488bfc6a5d6fa02a175d3378888c81b50003b27 100644 (file)
@@ -397,6 +397,7 @@ static void imap_notify_callback(struct mailbox *box, struct client *client)
        cmd = client_command_alloc(client);
        cmd->tag = "*";
        cmd->name = "NOTIFY-CALLBACK";
+       client_command_init_finished(cmd);
 
        if (!client->notify_ctx->selected_immediate_expunges)
                sync_flags |= MAILBOX_SYNC_FLAG_NO_EXPUNGES;
index 488bde31cae8fd59077a878a498450e8bd70a32d..3e8fced88fc6706fc8afb3ea9451c65bc66645e4 100644 (file)
@@ -794,6 +794,8 @@ void imap_state_import_idle_cmd_tag(struct client *client, const char *tag)
                i_assert(command != NULL);
                cmd->func = command->func;
                cmd->cmd_flags = command->flags;
+               client_command_init_finished(cmd);
+
                if (command_exec(cmd)) {
                        /* IDLE terminated because of an external change, but
                           DONE was already buffered */