changeset 22241:5f3709d309b9

*-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.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Mon, 12 Jun 2017 22:52:56 +0300
parents 9e0fdc2a683e
children 589993f80eda
files src/imap-login/imap-login-client.c src/imap-urlauth/imap-urlauth-login.c src/login-common/client-common.h src/pop3-login/client.c
diffstat 4 files changed, 14 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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 = {
--- 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 = {
--- 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 {
--- 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 = {