From: Stephan Bosch Date: Sun, 17 Sep 2017 17:03:06 +0000 (+0200) Subject: lmtp: client: Moved soon-to-be-obsolete input handling functions to end of the file. X-Git-Tag: 2.3.0.rc1~221 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eac03bb795495c3934022059989d3fe360e904bb;p=thirdparty%2Fdovecot%2Fcore.git lmtp: client: Moved soon-to-be-obsolete input handling functions to end of the file. --- diff --git a/src/lmtp/client.c b/src/lmtp/client.c index 25c7eb3f92..fae52309f8 100644 --- a/src/lmtp/client.c +++ b/src/lmtp/client.c @@ -86,97 +86,6 @@ static void client_idle_timeout(struct client *client) "Disconnected client for inactivity"); } -static int client_input_line(struct client *client, const char *line) -{ - const char *cmd, *args; - - args = strchr(line, ' '); - if (args == NULL) { - cmd = line; - args = ""; - } else { - cmd = t_strdup_until(line, args); - args++; - } - cmd = t_str_ucase(cmd); - - if (strcmp(cmd, "LHLO") == 0) - return cmd_lhlo(client, args); - if (strcmp(cmd, "STARTTLS") == 0 && - master_service_ssl_is_enabled(master_service)) - return cmd_starttls(client); - if (strcmp(cmd, "MAIL") == 0) - return cmd_mail(client, args); - if (strcmp(cmd, "RCPT") == 0) - return cmd_rcpt(client, args); - if (strcmp(cmd, "DATA") == 0) - return cmd_data(client, args); - if (strcmp(cmd, "QUIT") == 0) - return cmd_quit(client, args); - if (strcmp(cmd, "VRFY") == 0) - return cmd_vrfy(client, args); - if (strcmp(cmd, "RSET") == 0) - return cmd_rset(client, args); - if (strcmp(cmd, "NOOP") == 0) - return cmd_noop(client, args); - if (strcmp(cmd, "XCLIENT") == 0) - return cmd_xclient(client, args); - - client_send_line(client, "502 5.5.2 Unknown command"); - return 0; -} - -int client_input_read(struct client *client) -{ - client->last_input = ioloop_time; - timeout_reset(client->to_idle); - - switch (i_stream_read(client->input)) { - case -2: - /* buffer full */ - client_destroy(client, "502 5.5.2", - "Disconnected: Input buffer full"); - return -1; - case -1: - /* disconnected */ - client_destroy(client, NULL, NULL); - return -1; - case 0: - /* nothing new read */ - return 0; - default: - /* something was read */ - return 0; - } -} - -void client_input_handle(struct client *client) -{ - struct ostream *output; - const char *line; - int ret; - - output = client->output; - o_stream_ref(output); - while ((line = i_stream_next_line(client->input)) != NULL) { - T_BEGIN { - o_stream_cork(output); - ret = client_input_line(client, line); - o_stream_uncork(output); - } T_END; - if (ret < 0) - break; - } - o_stream_unref(&output); -} - -static void client_input(struct client *client) -{ - if (client_input_read(client) < 0) - return; - client_input_handle(client); -} - static void client_raw_user_create(struct client *client) { void **sets; @@ -229,16 +138,6 @@ static void client_generate_session_id(struct client *client) client->state.session_id = p_strdup(client->state_pool, str_c(id)); } -void client_io_reset(struct client *client) -{ - io_remove(&client->io); - timeout_remove(&client->to_idle); - client->io = io_add(client->fd_in, IO_READ, client_input, client); - client->last_input = ioloop_time; - client->to_idle = timeout_add(CLIENT_IDLE_TIMEOUT_MSECS, - client_idle_timeout, client); -} - struct client *client_create(int fd_in, int fd_out, const struct master_service_connection *conn) { @@ -433,3 +332,108 @@ void clients_destroy(void) "Shutting down"); } } + +/* + * Input handling + */ + +static int client_input_line(struct client *client, const char *line) +{ + const char *cmd, *args; + + args = strchr(line, ' '); + if (args == NULL) { + cmd = line; + args = ""; + } else { + cmd = t_strdup_until(line, args); + args++; + } + cmd = t_str_ucase(cmd); + + if (strcmp(cmd, "LHLO") == 0) + return cmd_lhlo(client, args); + if (strcmp(cmd, "STARTTLS") == 0 && + master_service_ssl_is_enabled(master_service)) + return cmd_starttls(client); + if (strcmp(cmd, "MAIL") == 0) + return cmd_mail(client, args); + if (strcmp(cmd, "RCPT") == 0) + return cmd_rcpt(client, args); + if (strcmp(cmd, "DATA") == 0) + return cmd_data(client, args); + if (strcmp(cmd, "QUIT") == 0) + return cmd_quit(client, args); + if (strcmp(cmd, "VRFY") == 0) + return cmd_vrfy(client, args); + if (strcmp(cmd, "RSET") == 0) + return cmd_rset(client, args); + if (strcmp(cmd, "NOOP") == 0) + return cmd_noop(client, args); + if (strcmp(cmd, "XCLIENT") == 0) + return cmd_xclient(client, args); + + client_send_line(client, "502 5.5.2 Unknown command"); + return 0; +} + +int client_input_read(struct client *client) +{ + client->last_input = ioloop_time; + timeout_reset(client->to_idle); + + switch (i_stream_read(client->input)) { + case -2: + /* buffer full */ + client_destroy(client, "502 5.5.2", + "Disconnected: Input buffer full"); + return -1; + case -1: + /* disconnected */ + client_destroy(client, NULL, NULL); + return -1; + case 0: + /* nothing new read */ + return 0; + default: + /* something was read */ + return 0; + } +} + +void client_input_handle(struct client *client) +{ + struct ostream *output; + const char *line; + int ret; + + output = client->output; + o_stream_ref(output); + while ((line = i_stream_next_line(client->input)) != NULL) { + T_BEGIN { + o_stream_cork(output); + ret = client_input_line(client, line); + o_stream_uncork(output); + } T_END; + if (ret < 0) + break; + } + o_stream_unref(&output); +} + +static void client_input(struct client *client) +{ + if (client_input_read(client) < 0) + return; + client_input_handle(client); +} + +void client_io_reset(struct client *client) +{ + io_remove(&client->io); + timeout_remove(&client->to_idle); + client->io = io_add(client->fd_in, IO_READ, client_input, client); + client->last_input = ioloop_time; + client->to_idle = timeout_add(CLIENT_IDLE_TIMEOUT_MSECS, + client_idle_timeout, client); +} diff --git a/src/lmtp/client.h b/src/lmtp/client.h index e41dcb83e9..84f9e04f73 100644 --- a/src/lmtp/client.h +++ b/src/lmtp/client.h @@ -86,18 +86,18 @@ void client_destroy(struct client *client, const char *prefix, const char *reason) ATTR_NULL(2, 3); void client_disconnect(struct client *client, const char *prefix, const char *reason); -void client_io_reset(struct client *client); void client_state_reset(struct client *client, const char *state_name); void client_state_set(struct client *client, const char *name, const char *args); const char *client_remote_id(struct client *client); -void client_input_handle(struct client *client); -int client_input_read(struct client *client); - void client_send_line(struct client *client, const char *fmt, ...) ATTR_FORMAT(2, 3); bool client_is_trusted(struct client *client); void clients_destroy(void); +void client_input_handle(struct client *client); +int client_input_read(struct client *client); +void client_io_reset(struct client *client); + #endif