From: Marco Bettini Date: Fri, 14 Oct 2022 09:33:19 +0000 (+0000) Subject: pop3: struct client - Add event X-Git-Tag: 2.4.0~3498 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=de9c5f8b651b08bf08a6ac75a7fdceec5976b0ff;p=thirdparty%2Fdovecot%2Fcore.git pop3: struct client - Add event --- diff --git a/src/pop3/main.c b/src/pop3/main.c index 03ee550f79..cb17108be9 100644 --- a/src/pop3/main.c +++ b/src/pop3/main.c @@ -28,6 +28,10 @@ #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; } diff --git a/src/pop3/pop3-client.c b/src/pop3/pop3-client.c index 647ca5bd32..5af63ae712 100644 --- a/src/pop3/pop3-client.c +++ b/src/pop3/pop3-client.c @@ -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); diff --git a/src/pop3/pop3-client.h b/src/pop3/pop3-client.h index 98e574d93f..faa92e9d94 100644 --- a/src/pop3/pop3-client.h +++ b/src/pop3/pop3-client.h @@ -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);