From b84eff65e25ae86dfd6f798386577209b94838c6 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Fri, 16 Jun 2017 14:34:24 +0300 Subject: [PATCH] *-login: Add client_vfuncs.free() that is called when client refcount=0 This can be useful for plugins that want to run something after proxying ends. Use an empty default function so plugins can call super.free() without having to check if it's NULL. --- src/imap-login/imap-login-client.c | 1 + src/imap-urlauth/imap-urlauth-login.c | 1 + src/login-common/client-common.c | 7 +++++++ src/login-common/client-common.h | 2 ++ src/pop3-login/client.c | 1 + 5 files changed, 12 insertions(+) diff --git a/src/imap-login/imap-login-client.c b/src/imap-login/imap-login-client.c index 15e0539e7f..f6e1d01feb 100644 --- a/src/imap-login/imap-login-client.c +++ b/src/imap-login/imap-login-client.c @@ -786,6 +786,7 @@ static struct client_vfuncs imap_client_vfuncs = { imap_proxy_get_state, client_common_send_raw_data, imap_client_input_next_cmd, + client_common_default_free, }; static const struct login_binary imap_login_binary = { diff --git a/src/imap-urlauth/imap-urlauth-login.c b/src/imap-urlauth/imap-urlauth-login.c index 004ac95b4a..fe0d455882 100644 --- a/src/imap-urlauth/imap-urlauth-login.c +++ b/src/imap-urlauth/imap-urlauth-login.c @@ -176,6 +176,7 @@ static struct client_vfuncs imap_urlauth_vfuncs = { NULL, client_common_send_raw_data, NULL, + client_common_default_free, }; static const struct login_binary imap_urlauth_login_binary = { diff --git a/src/login-common/client-common.c b/src/login-common/client-common.c index 5648be3188..2f5f696c2e 100644 --- a/src/login-common/client-common.c +++ b/src/login-common/client-common.c @@ -335,6 +335,9 @@ bool client_unref(struct client **_client) i_assert(client->destroyed); i_assert(client->login_proxy == NULL); + if (client->v.free != NULL) + client->v.free(client); + if (client->ssl_proxy != NULL) ssl_proxy_free(&client->ssl_proxy); if (client->input != NULL) @@ -359,6 +362,10 @@ bool client_unref(struct client **_client) return FALSE; } +void client_common_default_free(struct client *client ATTR_UNUSED) +{ +} + void client_destroy_oldest(void) { struct client *client; diff --git a/src/login-common/client-common.h b/src/login-common/client-common.h index ff5ba0a1df..90b57c8666 100644 --- a/src/login-common/client-common.h +++ b/src/login-common/client-common.h @@ -123,6 +123,7 @@ struct client_vfuncs { void (*send_raw_data)(struct client *client, const void *data, size_t size); bool (*input_next_cmd)(struct client *client); + void (*free)(struct client *client); }; struct client { @@ -273,6 +274,7 @@ void client_send_raw_data(struct client *client, const void *data, size_t size); void client_send_raw(struct client *client, const char *data); void client_common_send_raw_data(struct client *client, const void *data, size_t size); +void client_common_default_free(struct client *client); void client_set_auth_waiting(struct client *client); void client_auth_send_challenge(struct client *client, const char *data); diff --git a/src/pop3-login/client.c b/src/pop3-login/client.c index ae9c2ddb7c..6b67507ff2 100644 --- a/src/pop3-login/client.c +++ b/src/pop3-login/client.c @@ -334,6 +334,7 @@ static struct client_vfuncs pop3_client_vfuncs = { pop3_proxy_get_state, client_common_send_raw_data, pop3_client_input_next_cmd, + client_common_default_free, }; static const struct login_binary pop3_login_binary = {