# HG changeset patch # User Timo Sirainen # Date 1497297176 -10800 # Node ID 5f3709d309b92779b8c055d5157ba0afb49318b7 # Parent 9e0fdc2a683e148d5b197d68cc58cbe5d36436d3 *-login: Add client_vfuncs.input_next_cmd() This allows plugins to hook into all the pre-login commands. For example with imap-login most of the commands could already be hooked into, except for ID and AUTHENTICATE because their parameters reading is handled specially. This allows hooking into them as well. This is actually internal to all the login binaries, so it wouldn't have to be in login-common. However, login-common already has all the code to handle overriding functions nicely and this is a rather useful feature for all the protocols anyway, so it's easier this way and not too ugly. diff -r 9e0fdc2a683e -r 5f3709d309b9 src/imap-login/imap-login-client.c --- a/src/imap-login/imap-login-client.c Mon Jun 12 22:51:12 2017 +0300 +++ b/src/imap-login/imap-login-client.c Mon Jun 12 22:52:56 2017 +0300 @@ -464,10 +464,6 @@ static bool client_handle_input(struct imap_client *client) { - const struct imap_arg *args; - bool parsed; - int ret; - i_assert(!client->common.authenticating); if (client->cmd_finished) { @@ -507,6 +503,15 @@ if (client->cmd_name == NULL) return FALSE; /* need more data */ } + return client->common.v.input_next_cmd(&client->common); +} + +static bool imap_client_input_next_cmd(struct client *_client) +{ + struct imap_client *client = (struct imap_client *)_client; + const struct imap_arg *args; + bool parsed; + int ret; if (strcasecmp(client->cmd_name, "AUTHENTICATE") == 0) { /* SASL-IR may need more space than input buffer's size, @@ -762,6 +767,7 @@ imap_proxy_error, imap_proxy_get_state, client_common_send_raw_data, + imap_client_input_next_cmd, }; static const struct login_binary imap_login_binary = { diff -r 9e0fdc2a683e -r 5f3709d309b9 src/imap-urlauth/imap-urlauth-login.c --- a/src/imap-urlauth/imap-urlauth-login.c Mon Jun 12 22:51:12 2017 +0300 +++ b/src/imap-urlauth/imap-urlauth-login.c Mon Jun 12 22:52:56 2017 +0300 @@ -175,6 +175,7 @@ NULL, NULL, client_common_send_raw_data, + NULL, }; static const struct login_binary imap_urlauth_login_binary = { diff -r 9e0fdc2a683e -r 5f3709d309b9 src/login-common/client-common.h --- a/src/login-common/client-common.h Mon Jun 12 22:51:12 2017 +0300 +++ b/src/login-common/client-common.h Mon Jun 12 22:52:56 2017 +0300 @@ -105,6 +105,7 @@ const char *(*proxy_get_state)(struct client *client); void (*send_raw_data)(struct client *client, const void *data, size_t size); + bool (*input_next_cmd)(struct client *client); }; struct client { diff -r 9e0fdc2a683e -r 5f3709d309b9 src/pop3-login/client.c --- a/src/pop3-login/client.c Mon Jun 12 22:51:12 2017 +0300 +++ b/src/pop3-login/client.c Mon Jun 12 22:52:56 2017 +0300 @@ -22,8 +22,6 @@ /* Disconnect client when it sends too many bad commands */ #define CLIENT_MAX_BAD_COMMANDS 3 -static bool pop3_client_input_next_cmd(struct client *client); - static bool cmd_stls(struct pop3_client *client) { client_cmd_starttls(&client->common); @@ -132,7 +130,7 @@ commands until the authentication is finished. */ while (!client->output->closed && !client->authenticating && auth_client_is_connected(auth_client)) { - if (!pop3_client_input_next_cmd(client)) + if (!client->v.input_next_cmd(client)) break; } @@ -335,6 +333,7 @@ pop3_proxy_error, pop3_proxy_get_state, client_common_send_raw_data, + pop3_client_input_next_cmd, }; static const struct login_binary pop3_login_binary = {