]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-smtp: client: Perform output stream error handling in one place.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Sat, 17 Feb 2018 00:46:15 +0000 (01:46 +0100)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Mon, 12 Mar 2018 08:42:26 +0000 (10:42 +0200)
src/lib-smtp/smtp-client-command.c
src/lib-smtp/smtp-client-connection.c
src/lib-smtp/smtp-client-private.h

index f67d01e328e581c004655cd6a15933a1bda7de5e..42477f9f4130da9f9ebd880d21f251c0a065394b 100644 (file)
@@ -352,8 +352,7 @@ smtp_client_command_sent(struct smtp_client_command *cmd)
 }
 
 static int
-smtp_client_command_send_stream(struct smtp_client_command *cmd,
-       const char **error_r)
+smtp_client_command_send_stream(struct smtp_client_command *cmd)
 {
        struct smtp_client_connection *conn = cmd->conn;
        struct istream *stream = cmd->stream;
@@ -382,11 +381,8 @@ smtp_client_command_send_stream(struct smtp_client_command *cmd,
                if (conn->dot_output != NULL) {
                        /* this concludes the dot stream with CRLF.CRLF */
                        if ((ret=o_stream_finish(conn->dot_output)) < 0) {
-                               *error_r = t_strdup_printf(
-                                       "flush(%s) failed: %s",
-                                       o_stream_get_name(output),
-                                       o_stream_get_error(output));
                                o_stream_unref(&conn->dot_output);
+                               smtp_client_connection_handle_output_error(conn);
                                return -1;
                        }
                        if (ret == 0)
@@ -403,32 +399,32 @@ smtp_client_command_send_stream(struct smtp_client_command *cmd,
                        stream->v_offset < cmd->stream_size);
                return 0;
        case OSTREAM_SEND_ISTREAM_RESULT_ERROR_INPUT:
+
                /* the provided payload stream is broken;
                   fail this command separately */
+               smtp_client_command_error(cmd, "read(%s) failed: %s",
+                                         i_stream_get_name(stream),
+                                         i_stream_get_error(stream));
                smtp_client_command_fail(&cmd,
                        SMTP_CLIENT_COMMAND_ERROR_BROKEN_PAYLOAD,
                        "Broken payload stream");
-
                /* we're in the middle of sending a command, so the connection
                   will also have to be aborted */
-               *error_r = t_strdup_printf("read(%s) failed: %s",
-                                          i_stream_get_name(stream),
-                                          i_stream_get_error(stream));
                o_stream_unref(&conn->dot_output);
+               smtp_client_connection_fail(conn,
+                       SMTP_CLIENT_COMMAND_ERROR_CONNECTION_LOST,
+                       "Broken payload stream");
                return -1;
        case OSTREAM_SEND_ISTREAM_RESULT_ERROR_OUTPUT:
                /* normal connection failure */
-               *error_r = t_strdup_printf("write(%s) failed: %s",
-                                          o_stream_get_name(output),
-                                          o_stream_get_error(output));
                o_stream_unref(&conn->dot_output);
+               smtp_client_connection_handle_output_error(conn);
                return -1;
        }
        i_unreached();
 }
 
-int smtp_client_command_send_more(struct smtp_client_connection *conn,
-       const char **error_r)
+int smtp_client_command_send_more(struct smtp_client_connection *conn)
 {
        struct smtp_client_command *cmd;
        const char *data;
@@ -486,10 +482,7 @@ int smtp_client_command_send_more(struct smtp_client_connection *conn,
                                size = cmd->data->used - cmd->send_pos;
                                if ((sent=o_stream_send(conn->conn.output, data, size)) <= 0) {
                                        if (sent < 0) {
-                                               *error_r = t_strdup_printf(
-                                                       "write(%s) failed: %s",
-                                                       o_stream_get_name(conn->conn.output),
-                                                       o_stream_get_error(conn->conn.output));
+                                               smtp_client_connection_handle_output_error(conn);
                                                return -1;
                                        }
                                        smtp_client_command_debug(cmd,
@@ -503,7 +496,7 @@ int smtp_client_command_send_more(struct smtp_client_connection *conn,
                }
 
                if (cmd->stream != NULL &&
-                       (ret=smtp_client_command_send_stream(cmd, error_r)) <= 0) {
+                       (ret=smtp_client_command_send_stream(cmd)) <= 0) {
                        if (ret < 0)
                                return -1;
                        smtp_client_command_debug(cmd,
index 347b8dad7a71bd0116a998555b9529e5609309eb..32e83dd9056e670a6028fcde4a849b08c9614c2f 100644 (file)
@@ -1094,7 +1094,6 @@ static void smtp_client_connection_input(struct connection *_conn)
 
 static int smtp_client_connection_output(struct smtp_client_connection *conn)
 {
-       const char *error;
        int ret;
 
        if (conn->to_connect != NULL)
@@ -1107,15 +1106,8 @@ static int smtp_client_connection_output(struct smtp_client_connection *conn)
        }
 
        smtp_client_connection_ref(conn);
-       if (smtp_client_command_send_more(conn, &error) < 0) {
-               smtp_client_connection_error(conn,
-                       "Connection lost: %s", error);
-               smtp_client_connection_fail(conn,
-                       SMTP_CLIENT_COMMAND_ERROR_CONNECTION_LOST,
-                       "Lost connection to remote server "
-                       "(failed to send command)");
+       if (smtp_client_command_send_more(conn) < 0)
                ret = -1;
-       }
        smtp_client_connection_unref(&conn);
        return ret;
 }
index 603d6148847da1b8abd70028e0f9a1a5c2f4f06c..3be73fea845971846ccef8e185161b13365f0b52 100644 (file)
@@ -186,8 +186,7 @@ struct smtp_client {
  */
 
 void smtp_client_command_free(struct smtp_client_command *cmd);
-int smtp_client_command_send_more(struct smtp_client_connection *conn,
-                                 const char **error_r);
+int smtp_client_command_send_more(struct smtp_client_connection *conn);
 int smtp_client_command_input_reply(struct smtp_client_command *cmd,
                                    const struct smtp_reply *reply);
 void smtp_client_command_fail(struct smtp_client_command **_cmd,