]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
pop3: struct client - Add event
authorMarco Bettini <marco.bettini@open-xchange.com>
Fri, 14 Oct 2022 09:33:19 +0000 (09:33 +0000)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Wed, 26 Oct 2022 16:35:08 +0000 (16:35 +0000)
src/pop3/main.c
src/pop3/pop3-client.c
src/pop3/pop3-client.h

index 03ee550f79d69813b80d5888669a8c8d7422403c..cb17108be915bee23d503169dcab29e112328660 100644 (file)
 #define IS_STANDALONE() \
         (getenv(MASTER_IS_PARENT_ENV) == NULL)
 
+struct event_category event_category_pop3 = {
+       .name = "pop3",
+};
+
 static bool verbose_proctitle = FALSE;
 static struct mail_storage_service_ctx *storage_service;
 static struct login_server *login_server = NULL;
@@ -117,7 +121,25 @@ client_create_from_input(const struct mail_storage_service_input *input,
        struct pop3_settings *set;
        const char *errstr;
 
-       if (mail_storage_service_lookup_next(storage_service, input,
+       struct event *event = event_create(NULL);
+       event_add_category(event, &event_category_pop3);
+       event_add_fields(event, (const struct event_add_field []){
+               { .key = "user", .value = input->username },
+               { .key = NULL }
+       });
+       if (input->local_ip.family != 0)
+               event_add_str(event, "local_ip", net_ip2addr(&input->local_ip));
+       if (input->local_port != 0)
+               event_add_int(event, "local_port", input->local_port);
+       if (input->remote_ip.family != 0)
+               event_add_str(event, "remote_ip", net_ip2addr(&input->remote_ip));
+       if (input->remote_port != 0)
+               event_add_int(event, "remote_port", input->remote_port);
+
+       struct mail_storage_service_input service_input = *input;
+       service_input.event_parent = event;
+
+       if (mail_storage_service_lookup_next(storage_service, &service_input,
                                             &user, &mail_user, error_r) <= 0) {
                if (write(fd_out, lookup_error_str, strlen(lookup_error_str)) < 0) {
                        /* ignored */
@@ -139,7 +161,8 @@ client_create_from_input(const struct mail_storage_service_input *input,
                return -1;
        }
 
-       *client_r = client_create(fd_in, fd_out, mail_user, user, set);
+       *client_r = client_create(fd_in, fd_out, event, mail_user, user, set);
+       event_unref(&event);
        return 0;
 }
 
index 647ca5bd329f8e2d9db38be45b9125f297373941..5af63ae712cbfc13cad3c3c102cade4889e48bd6 100644 (file)
@@ -379,7 +379,7 @@ int pop3_lock_session(struct client *client)
 }
 
 struct client *client_create(int fd_in, int fd_out,
-                            struct mail_user *user,
+                            struct event *event, struct mail_user *user,
                             struct mail_storage_service_user *service_user,
                             const struct pop3_settings *set)
 {
@@ -393,6 +393,8 @@ struct client *client_create(int fd_in, int fd_out,
        pool = pool_alloconly_create("pop3 client", 256);
        client = p_new(pool, struct client, 1);
        client->pool = pool;
+       client->event = event;
+       event_ref(client->event);
        client->service_user = service_user;
        client->v = pop3_client_vfuncs;
        client->set = set;
@@ -562,7 +564,9 @@ static const char *client_stats(struct client *client)
 
 void client_destroy(struct client *client, const char *reason)
 {
+       struct event *event = client->event;
        client->v.destroy(client, reason);
+       event_unref(&event);
 }
 
 static void client_default_destroy(struct client *client, const char *reason)
@@ -657,7 +661,7 @@ void client_disconnect(struct client *client, const char *reason)
                return;
 
        client->disconnected = TRUE;
-       i_info("Disconnected: %s %s", reason, client_stats(client));
+       e_info(client->event, "Disconnected: %s %s", reason, client_stats(client));
 
        (void)o_stream_flush(client->output);
 
index 98e574d93f852a058918ed762196d1cc7b349b79..faa92e9d94ce2bd043e14b3ca0f844957c0e8e5b 100644 (file)
@@ -34,6 +34,7 @@ struct pop3_client_vfuncs {
 struct client {
        struct client *prev, *next;
 
+       struct event *event;
        struct pop3_client_vfuncs v;
 
        int fd_in, fd_out;
@@ -123,7 +124,7 @@ extern unsigned int pop3_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,
-                            struct mail_user *user,
+                            struct event *event, struct mail_user *user,
                             struct mail_storage_service_user *service_user,
                             const struct pop3_settings *set);
 void client_create_finish(struct client *client);