]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lmtp: client: Moved soon-to-be-obsolete input handling functions to end of the file.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Sun, 17 Sep 2017 17:03:06 +0000 (19:03 +0200)
committerStephan Bosch <stephan.bosch@dovecot.fi>
Thu, 7 Dec 2017 23:08:15 +0000 (00:08 +0100)
src/lmtp/client.c
src/lmtp/client.h

index 25c7eb3f92c60b969423c0ba99a50a5f0d3faed2..fae52309f878a505b8245ebd01e2cf3974dca161 100644 (file)
@@ -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);
+}
index e41dcb83e9159e91cd4a3ec90d55207e135b1257..84f9e04f737ac80c3c5a1bd0d451432a5dc41b9b 100644 (file)
@@ -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