From: Timo Sirainen Date: Tue, 21 Nov 2017 14:33:59 +0000 (+0100) Subject: imap: Add client.event and use it as mail_*user's parent event X-Git-Tag: 2.3.0.rc1~89 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fcad7b5f8913030ef5bb6f23022fcdf15a089e14;p=thirdparty%2Fdovecot%2Fcore.git imap: Add client.event and use it as mail_*user's parent event --- diff --git a/src/imap/imap-client.c b/src/imap/imap-client.c index 536282ef21..3a9c3c236d 100644 --- a/src/imap/imap-client.c +++ b/src/imap/imap-client.c @@ -84,7 +84,7 @@ static bool user_has_special_use_mailboxes(struct mail_user *user) } struct client *client_create(int fd_in, int fd_out, const char *session_id, - struct mail_user *user, + struct event *event, struct mail_user *user, struct mail_storage_service_user *service_user, const struct imap_settings *set, const struct smtp_submit_settings *smtp_set) @@ -102,6 +102,8 @@ struct client *client_create(int fd_in, int fd_out, const char *session_id, client = p_new(pool, struct client, 1); client->pool = pool; client->v = imap_client_vfuncs; + client->event = event; + event_ref(client->event); client->set = set; client->smtp_set = smtp_set; client->service_user = service_user; @@ -477,6 +479,7 @@ static void client_default_destroy(struct client *client, const char *reason) imap_client_count--; DLLIST_REMOVE(&imap_clients, client); + event_unref(&client->event); i_free(client->last_cmd_name); pool_unref(&client->pool); diff --git a/src/imap/imap-client.h b/src/imap/imap-client.h index 3216af7f22..3ccb83dfae 100644 --- a/src/imap/imap-client.h +++ b/src/imap/imap-client.h @@ -143,6 +143,7 @@ struct client { struct client *prev, *next; struct imap_client_vfuncs v; + struct event *event; const char *session_id; const char *const *userdb_fields; /* for internal session saving/restoring */ @@ -251,7 +252,7 @@ extern unsigned int imap_client_count; /* Create new client with specified input/output handles. socket specifies if the handle is a socket. */ struct client *client_create(int fd_in, int fd_out, const char *session_id, - struct mail_user *user, + struct event *event, struct mail_user *user, struct mail_storage_service_user *service_user, const struct imap_settings *set, const struct smtp_submit_settings *smtp_set); diff --git a/src/imap/imap-common.h b/src/imap/imap-common.h index f103fb1ed0..1e214eb5c4 100644 --- a/src/imap/imap-common.h +++ b/src/imap/imap-common.h @@ -23,6 +23,7 @@ typedef void imap_client_created_func_t(struct client **client); extern imap_client_created_func_t *hook_client_created; extern bool imap_debug; +extern struct event_category event_category_imap; /* Sets the hook_client_created and returns the previous hook, which the new_hook should call if it's non-NULL. */ diff --git a/src/imap/main.c b/src/imap/main.c index b1dae18986..f5c15548f3 100644 --- a/src/imap/main.c +++ b/src/imap/main.c @@ -38,6 +38,10 @@ static struct master_login *master_login = NULL; imap_client_created_func_t *hook_client_created = NULL; bool imap_debug = FALSE; +struct event_category event_category_imap = { + .name = "imap", +}; + imap_client_created_func_t * imap_client_created_hook_set(imap_client_created_func_t *new_hook) { @@ -240,16 +244,30 @@ int client_create_from_input(const struct mail_storage_service_input *input, int fd_in, int fd_out, struct client **client_r, const char **error_r) { + struct mail_storage_service_input service_input; struct mail_storage_service_user *user; struct mail_user *mail_user; struct client *client; struct imap_settings *imap_set; struct smtp_submit_settings *smtp_set; + struct event *event; const char *errstr; - if (mail_storage_service_lookup_next(storage_service, input, - &user, &mail_user, error_r) <= 0) + event = event_create(NULL); + event_add_category(event, &event_category_imap); + event_add_fields(event, (const struct event_add_field []){ + { .key = "user", .value = input->username }, + { .key = "session", .value = input->session_id }, + { .key = NULL } + }); + + service_input = *input; + service_input.parent_event = event; + if (mail_storage_service_lookup_next(storage_service, &service_input, + &user, &mail_user, error_r) <= 0) { + event_unref(&event); return -1; + } restrict_access_allow_coredumps(TRUE); smtp_set = mail_storage_service_user_get_set(user)[1]; @@ -266,13 +284,15 @@ int client_create_from_input(const struct mail_storage_service_input *input, *error_r = t_strdup_printf("Failed to expand settings: %s", errstr); mail_user_unref(&mail_user); mail_storage_service_user_unref(&user); + event_unref(&event); return -1; } client = client_create(fd_in, fd_out, input->session_id, - mail_user, user, imap_set, smtp_set); + event, mail_user, user, imap_set, smtp_set); client->userdb_fields = input->userdb_fields == NULL ? NULL : p_strarray_dup(client->pool, input->userdb_fields); + event_unref(&event); *client_r = client; return 0; }