From b33182d9d479ee8687b806577bc1fb94d24de534 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 d2673bfe97..93b5be7524 100644 --- a/src/imap-login/imap-login-client.c +++ b/src/imap-login/imap-login-client.c @@ -768,6 +768,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 439ed89ded..5184559ac8 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 ab46563010..e62a8fef1f 100644 --- a/src/login-common/client-common.c +++ b/src/login-common/client-common.c @@ -337,6 +337,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) @@ -361,6 +364,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 c8142ab52d..09e1c37d9c 100644 --- a/src/login-common/client-common.h +++ b/src/login-common/client-common.h @@ -106,6 +106,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 { @@ -259,6 +260,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 = {