]> 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)
committerStephan Bosch <stephan.bosch@dovecot.fi>
Sat, 17 Feb 2018 14:49:41 +0000 (15:49 +0100)
src/lib-smtp/smtp-client-command.c
src/lib-smtp/smtp-client-connection.c
src/lib-smtp/smtp-client-private.h

index 04ec32ea0598f7886c519aef439a24bce20f602a..4d023ed5a76334abf6c09a96d4e7cdee9a3aadee 100644 (file)
@@ -420,8 +420,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;
@@ -450,11 +449,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)
@@ -471,32 +467,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;
@@ -554,10 +550,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,
@@ -571,7 +564,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 3994d13c69cf5f6f8cc2e62b0edbf6840dcf253e..33e3919cfd70db312b516feee77e7fe1d1bb4f41 100644 (file)
@@ -1068,7 +1068,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)
@@ -1081,15 +1080,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 8480093a0e99b6c0d47434aac07414bd4a2b3714..3775f0f138901843ff96d008c66a884b8b7a96bf 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);