]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap: Add client.event and use it as mail_*user's parent event
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 21 Nov 2017 14:33:59 +0000 (15:33 +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-common.h
src/imap/main.c

index 536282ef217c590facca7fae74dd4ae89989740e..3a9c3c236d2c04c3044b1f22bfe2572a6066d83a 100644 (file)
@@ -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);
 
index 3216af7f22a2b4e0e5a26d39100f189340d699b5..3ccb83dfae13fa0f23692645ef4ac6f5b271db8a 100644 (file)
@@ -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);
index f103fb1ed0504d998658a2485c919d08e0313dc8..1e214eb5c495cbf1af914a93873e7b9ddced4e21 100644 (file)
@@ -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. */
index b1dae189865950aa30bc4e4b2dd97fc2f7f61edf..f5c15548f3913f1396070140c67cbc95984252f7 100644 (file)
@@ -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;
 }