From: Timo Sirainen Date: Tue, 9 Mar 2021 14:37:18 +0000 (+0200) Subject: imap: Add and use client_command_context.global_event X-Git-Tag: 2.3.18~351 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ad5ef653eb1dd447bcc15b56694041c744cdf15e;p=thirdparty%2Fdovecot%2Fcore.git imap: Add and use client_command_context.global_event 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_ field. --- diff --git a/src/imap/cmd-append.c b/src/imap/cmd-append.c index 8fd7fa869a..72f078a495 100644 --- a/src/imap/cmd-append.c +++ b/src/imap/cmd-append.c @@ -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 | diff --git a/src/imap/cmd-create.c b/src/imap/cmd-create.c index e7805fb089..75f23b4159 100644 --- a/src/imap/cmd-create.c +++ b/src/imap/cmd-create.c @@ -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); diff --git a/src/imap/cmd-delete.c b/src/imap/cmd-delete.c index e6f37262d6..f8bb053b20 100644 --- a/src/imap/cmd-delete.c +++ b/src/imap/cmd-delete.c @@ -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 diff --git a/src/imap/cmd-getmetadata.c b/src/imap/cmd-getmetadata.c index ac014c4f1d..676d4e466f 100644 --- a/src/imap/cmd-getmetadata.c +++ b/src/imap/cmd-getmetadata.c @@ -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; diff --git a/src/imap/cmd-rename.c b/src/imap/cmd-rename.c index 776ed86d26..db706221b4 100644 --- a/src/imap/cmd-rename.c +++ b/src/imap/cmd-rename.c @@ -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 diff --git a/src/imap/cmd-resetkey.c b/src/imap/cmd-resetkey.c index 3a58ef4a22..230056d38e 100644 --- a/src/imap/cmd-resetkey.c +++ b/src/imap/cmd-resetkey.c @@ -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); diff --git a/src/imap/cmd-select.c b/src/imap/cmd-select.c index 619fa82b57..6a45b2de20 100644 --- a/src/imap/cmd-select.c +++ b/src/imap/cmd-select.c @@ -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); diff --git a/src/imap/cmd-setmetadata.c b/src/imap/cmd-setmetadata.c index c21d1e2ae2..614a166595 100644 --- a/src/imap/cmd-setmetadata.c +++ b/src/imap/cmd-setmetadata.c @@ -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); } diff --git a/src/imap/cmd-status.c b/src/imap/cmd-status.c index d90aef2a3e..69c0a51b02 100644 --- a/src/imap/cmd-status.c +++ b/src/imap/cmd-status.c @@ -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) { diff --git a/src/imap/cmd-subscribe.c b/src/imap/cmd-subscribe.c index ca7397beea..24741af497 100644 --- a/src/imap/cmd-subscribe.c +++ b/src/imap/cmd-subscribe.c @@ -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)) { diff --git a/src/imap/imap-client.c b/src/imap/imap-client.c index da56eb21eb..b5418f6179 100644 --- a/src/imap/imap-client.c +++ b/src/imap/imap-client.c @@ -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 */ diff --git a/src/imap/imap-client.h b/src/imap/imap-client.h index 24c22b23b3..a307955f7d 100644 --- a/src/imap/imap-client.h +++ b/src/imap/imap-client.h @@ -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 */ diff --git a/src/imap/imap-commands-util.c b/src/imap/imap-commands-util.c index fe08e4f40e..f6194811f1 100644 --- a/src/imap/imap-commands-util.c +++ b/src/imap/imap-commands-util.c @@ -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 { diff --git a/src/imap/imap-commands.c b/src/imap/imap-commands.c index 5ee2dec403..b78d0a17a7 100644 --- a/src/imap/imap-commands.c +++ b/src/imap/imap-commands.c @@ -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;