]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap: Add and use client_command_context.global_event
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 9 Mar 2021 14:37:18 +0000 (16:37 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Wed, 29 Sep 2021 10:09:58 +0000 (10:09 +0000)
This way all the (potentially large) IMAP command parameters won't be
included in all the events. This change might be reverted in the future
if the performance worries go away.

The global event also contains reason_code=imap:cmd_<command name> field.

14 files changed:
src/imap/cmd-append.c
src/imap/cmd-create.c
src/imap/cmd-delete.c
src/imap/cmd-getmetadata.c
src/imap/cmd-rename.c
src/imap/cmd-resetkey.c
src/imap/cmd-select.c
src/imap/cmd-setmetadata.c
src/imap/cmd-status.c
src/imap/cmd-subscribe.c
src/imap/imap-client.c
src/imap/imap-client.h
src/imap/imap-commands-util.c
src/imap/imap-commands.c

index 8fd7fa869a589843a963fa207491f5fc46b54b59..72f078a4959474a892d1e381acb973958356c63e 100644 (file)
@@ -931,7 +931,7 @@ bool cmd_append(struct client_command_context *cmd)
        if (client_open_save_dest_box(cmd, mailbox, &ctx->box) < 0)
                ctx->failed = TRUE;
        else {
-               event_add_str(cmd->event, "mailbox",
+               event_add_str(cmd->global_event, "mailbox",
                              mailbox_get_vname(ctx->box));
                ctx->t = mailbox_transaction_begin(ctx->box,
                                        MAILBOX_TRANSACTION_FLAG_EXTERNAL |
index e7805fb089d0ad05ffe5f8fc68b2e986b50bbaf6..75f23b41598d94b3c0f5df6e2329fbc36d650f3e 100644 (file)
@@ -38,7 +38,7 @@ bool cmd_create(struct client_command_context *cmd)
        }
 
        box = mailbox_alloc(ns->list, mailbox, 0);
-       event_add_str(cmd->event, "mailbox", mailbox_get_vname(box));
+       event_add_str(cmd->global_event, "mailbox", mailbox_get_vname(box));
        mailbox_set_reason(box, "CREATE");
        if (mailbox_create(box, NULL, directory) < 0)
                client_send_box_error(cmd, box);
index e6f37262d6d653055a8e46833b7c3d860ac29e34..f8bb053b20cc0010606fc8ebb48d8a04743e62c0 100644 (file)
@@ -21,7 +21,7 @@ bool cmd_delete(struct client_command_context *cmd)
                return TRUE;
 
        box = mailbox_alloc(ns->list, name, 0);
-       event_add_str(cmd->event, "mailbox", mailbox_get_vname(box));
+       event_add_str(cmd->global_event, "mailbox", mailbox_get_vname(box));
        mailbox_set_reason(box, "DELETE");
        if (mailbox_is_any_inbox(box)) {
                /* IMAP protocol allows this, but I think it's safer to
index ac014c4f1df7cd3a27323772783cd7b80d141a88..676d4e466ff212dabf158330e700a7dda252d0f2 100644 (file)
@@ -435,7 +435,8 @@ cmd_getmetadata_try_mailbox(struct imap_getmetadata_context *ctx,
                            struct mail_namespace *ns, const char *mailbox)
 {
        ctx->box = mailbox_alloc(ns->list, mailbox, MAILBOX_FLAG_READONLY);
-       event_add_str(ctx->cmd->event, "mailbox", mailbox_get_vname(ctx->box));
+       event_add_str(ctx->cmd->global_event, "mailbox",
+                     mailbox_get_vname(ctx->box));
        mailbox_set_reason(ctx->box, "GETMETADATA");
 
        enum mailbox_existence existence;
index 776ed86d260174fcab73e13a09b01a265fa751f7..db706221b46e9ee98282121ff7c3f0e8bc8ecb7c 100644 (file)
@@ -39,8 +39,10 @@ bool cmd_rename(struct client_command_context *cmd)
        new_box = mailbox_alloc(new_ns->list, newname, 0);
        mailbox_set_reason(old_box, "RENAME from");
        mailbox_set_reason(new_box, "RENAME to");
-       event_add_str(cmd->event, "old_mailbox", mailbox_get_vname(old_box));
-       event_add_str(cmd->event, "new_mailbox", mailbox_get_vname(new_box));
+       event_add_str(cmd->global_event, "old_mailbox",
+                     mailbox_get_vname(old_box));
+       event_add_str(cmd->global_event, "new_mailbox",
+                     mailbox_get_vname(new_box));
        if (mailbox_rename(old_box, new_box) < 0)
                client_send_box_error(cmd, old_box);
        else
index 3a58ef4a229e749c166c420295876c3dd82528b5..230056d38e4e313d65bb50f4fd7930b0264418a7 100644 (file)
@@ -49,7 +49,7 @@ cmd_resetkey_mailbox(struct client_command_context *cmd,
 
        /* open mailbox */
        box = mailbox_alloc(ns->list, mailbox, flags);
-       event_add_str(cmd->event, "mailbox", mailbox_get_vname(box));
+       event_add_str(cmd->global_event, "mailbox", mailbox_get_vname(box));
        mailbox_set_reason(box, "RESETKEY");
        if (mailbox_open(box) < 0) {
                client_send_box_error(cmd, box);
index 619fa82b57c271155291f7c4dc2454770573882b..6a45b2de2019249d361061eeaeace66e5d7acfc8 100644 (file)
@@ -283,7 +283,8 @@ select_open(struct imap_select_context *ctx, const char *mailbox, bool readonly)
        else
                flags |= MAILBOX_FLAG_DROP_RECENT;
        ctx->box = mailbox_alloc(ctx->ns->list, mailbox, flags);
-       event_add_str(ctx->cmd->event, "mailbox", mailbox_get_vname(ctx->box));
+       event_add_str(ctx->cmd->global_event, "mailbox",
+                     mailbox_get_vname(ctx->box));
        mailbox_set_reason(ctx->box, readonly ? "EXAMINE" : "SELECT");
        if (mailbox_open(ctx->box) < 0) {
                client_send_box_error(ctx->cmd, ctx->box);
index c21d1e2ae261522dcc3455b562eae8b372167d7d..614a166595ee6133ba706f3285e60d74592cf64a 100644 (file)
@@ -339,7 +339,8 @@ cmd_setmetadata_mailbox(struct imap_setmetadata_context *ctx,
                        return TRUE;
                }
        }
-       event_add_str(ctx->cmd->event, "mailbox", mailbox_get_vname(ctx->box));
+       event_add_str(ctx->cmd->global_event, "mailbox",
+                     mailbox_get_vname(ctx->box));
        ctx->trans = imap_metadata_transaction_begin(ctx->box);
        return cmd_setmetadata_start(ctx);
 }
index d90aef2a3e7923e29fa88cc27a2fbee861e183c5..69c0a51b02d247572453898f20db5aa688f4f087 100644 (file)
@@ -35,7 +35,7 @@ bool cmd_status(struct client_command_context *cmd)
        if (ns == NULL)
                return TRUE;
 
-       event_add_str(cmd->event, "mailbox", mailbox);
+       event_add_str(cmd->global_event, "mailbox", mailbox);
        selected_mailbox = client->mailbox != NULL &&
                mailbox_equals(client->mailbox, ns, mailbox);
        if (imap_status_get(cmd, ns, mailbox, &items, &result) < 0) {
index ca7397beea428a5849e964f1d3ee7add24526e6c..24741af49786780df9ee7e328e6f8604026650d6 100644 (file)
@@ -48,7 +48,7 @@ bool cmd_subscribe_full(struct client_command_context *cmd, bool subscribe)
                return TRUE;
 
        box = mailbox_alloc(ns->list, mailbox, 0);
-       event_add_str(cmd->event, "mailbox", mailbox_get_vname(box));
+       event_add_str(cmd->global_event, "mailbox", mailbox_get_vname(box));
        mailbox_set_reason(box, subscribe ? "SUBSCRIBE" : "UNSUBSCRIBE");
        if (subscribe) {
                if (!subscribe_is_valid_name(cmd, box)) {
index da56eb21eb3eeb50ded40edd8d276ab0c3260adf..b5418f617965858cda530ed8559bf55466cb8fde 100644 (file)
@@ -917,7 +917,8 @@ 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->global_event = event_create(client->event);
+       cmd->event = event_create(cmd->global_event);
        cmd->stats.start_time = ioloop_timeval;
        cmd->stats.last_run_timeval = ioloop_timeval;
        cmd->stats.start_ioloop_wait_usecs =
@@ -1014,6 +1015,7 @@ void client_command_free(struct client_command_context **_cmd)
        e_debug(cmd->event, "Command finished: %s %s", cmd->name,
                cmd->human_args != NULL ? cmd->human_args : "");
        event_unref(&cmd->event);
+       event_unref(&cmd->global_event);
 
        if (cmd->parser != NULL) {
                if (client->free_parser == NULL) {
@@ -1277,6 +1279,9 @@ static bool client_command_input(struct client_command_context *cmd)
                cmd->func = command->func;
                cmd->cmd_flags = command->flags;
                /* valid command - overwrite the "unknown" string set earlier */
+               event_add_str(cmd->global_event, "cmd_name", command->name);
+               event_strlist_append(cmd->global_event, "reason_code",
+                       event_reason_code_prefix("imap", "cmd_", command->name));
                event_add_str(cmd->event, "cmd_name", command->name);
                if (client_command_is_ambiguous(cmd)) {
                        /* do nothing until existing commands are finished */
index 24c22b23b35bd3f58ff974e8e31165f68f8d4353..a307955f7de20714af2afedba254cc513be99a6c 100644 (file)
@@ -79,6 +79,10 @@ struct client_command_context {
        struct client_command_context *prev, *next;
        struct client *client;
        struct event *event;
+       /* global_event is pushed to the global event stack while the command
+          is running. It has only the minimal fields that are actually wanted
+          to be in all the events while it's being run. */
+       struct event *global_event;
 
        pool_t pool;
        /* IMAP command tag */
index fe08e4f40ef996c957867c8c5d70d3e37049361d..f6194811f1ed00d66d4ad698079641af2698cf4d 100644 (file)
@@ -67,7 +67,7 @@ client_find_namespace(struct client_command_context *cmd, const char **mailbox)
 bool client_verify_open_mailbox(struct client_command_context *cmd)
 {
        if (cmd->client->mailbox != NULL) {
-               event_add_str(cmd->event, "mailbox",
+               event_add_str(cmd->global_event, "mailbox",
                              mailbox_get_vname(cmd->client->mailbox));
                return TRUE;
        } else {
index 5ee2dec403b811ed5ec464ac2b6afdfa39faeca5..b78d0a17a753c4f68534f6f852f8cc55e4dd056c 100644 (file)
@@ -194,7 +194,7 @@ bool command_exec(struct client_command_context *cmd)
        io_loop_time_refresh();
        command_stats_start(cmd);
 
-       event_push_global(cmd->event);
+       event_push_global(cmd->global_event);
        cmd->executing = TRUE;
        array_foreach(&command_hooks, hook)
                hook->pre(cmd);
@@ -202,7 +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);
+       event_pop_global(cmd->global_event);
        if (cmd->state == CLIENT_COMMAND_STATE_DONE)
                finished = TRUE;