Skip to content

Commit

Permalink
*-login: Add client_vfuncs.free() that is called when client refcount=0
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sirainen committed Jun 16, 2017
1 parent 8ed2646 commit b84eff6
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/imap-login/imap-login-client.c
Expand Up @@ -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 = {
Expand Down
1 change: 1 addition & 0 deletions src/imap-urlauth/imap-urlauth-login.c
Expand Up @@ -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 = {
Expand Down
7 changes: 7 additions & 0 deletions src/login-common/client-common.c
Expand Up @@ -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)
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/login-common/client-common.h
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/pop3-login/client.c
Expand Up @@ -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 = {
Expand Down

0 comments on commit b84eff6

Please sign in to comment.