From: Timo Sirainen Date: Fri, 27 Oct 2017 23:43:16 +0000 (+0300) Subject: lib-mail: ostream-dot - Require o_stream_finish() to write the trailer X-Git-Tag: 2.3.0.rc1~701 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a2583397219ebbb877fcf84107f0ca7f56362760;p=thirdparty%2Fdovecot%2Fcore.git lib-mail: ostream-dot - Require o_stream_finish() to write the trailer Similar to ostream-zlib. --- diff --git a/src/doveadm/server-connection.c b/src/doveadm/server-connection.c index fa12d629d5..96f475fae3 100644 --- a/src/doveadm/server-connection.c +++ b/src/doveadm/server-connection.c @@ -143,7 +143,7 @@ static int server_connection_send_cmd_input_more(struct server_connection *conn) break; } if (res == OSTREAM_SEND_ISTREAM_RESULT_FINISHED) { - if ((ret = o_stream_flush(conn->cmd_output)) == 0) + if ((ret = o_stream_finish(conn->cmd_output)) == 0) return 0; else if (ret < 0) { i_error("write(%s) failed: %s", diff --git a/src/lib-mail/ostream-dot.c b/src/lib-mail/ostream-dot.c index 04ca30c70a..d386380176 100644 --- a/src/lib-mail/ostream-dot.c +++ b/src/lib-mail/ostream-dot.c @@ -20,12 +20,14 @@ struct dot_ostream { bool force_extra_crlf; }; -static int -o_stream_dot_flush(struct ostream_private *stream) +static int o_stream_dot_finish(struct ostream_private *stream) { struct dot_ostream *dstream = (struct dot_ostream *)stream; int ret; + if (dstream->state == STREAM_STATE_DONE) + return 1; + if (o_stream_get_buffer_avail_size(stream->parent) < 5) { /* make space for the dot line */ if ((ret = o_stream_flush(stream->parent)) <= 0) { @@ -35,10 +37,8 @@ o_stream_dot_flush(struct ostream_private *stream) } } - if (dstream->state == STREAM_STATE_DONE) - ; - else if (dstream->state == STREAM_STATE_CRLF && - !dstream->force_extra_crlf) { + if (dstream->state == STREAM_STATE_CRLF && + !dstream->force_extra_crlf) { ret = o_stream_send(stream->parent, ".\r\n", 3); i_assert(ret == 3); } else { @@ -46,6 +46,18 @@ o_stream_dot_flush(struct ostream_private *stream) i_assert(ret == 5); } dstream->state = STREAM_STATE_DONE; + return 1; +} + +static int +o_stream_dot_flush(struct ostream_private *stream) +{ + int ret; + + if (stream->finished) { + if ((ret = o_stream_dot_finish(stream)) <= 0) + return ret; + } if ((ret = o_stream_flush(stream->parent)) < 0) o_stream_copy_error_from_parent(stream); diff --git a/src/lib-mail/test-ostream-dot.c b/src/lib-mail/test-ostream-dot.c index a56a2a4185..4740a62c57 100644 --- a/src/lib-mail/test-ostream-dot.c +++ b/src/lib-mail/test-ostream-dot.c @@ -39,7 +39,7 @@ static void test_ostream_dot_one(const struct dot_test *test) test_assert(test_input->eof); - test_assert(o_stream_flush(output) > 0); + test_assert(o_stream_finish(output) > 0); test_assert(output->offset == strlen(test->input)); test_assert(test_output->offset == strlen(test->output)); o_stream_unref(&output); diff --git a/src/lib-program-client/program-client.c b/src/lib-program-client/program-client.c index 1231178e8e..f2143c32f3 100644 --- a/src/lib-program-client/program-client.c +++ b/src/lib-program-client/program-client.c @@ -261,7 +261,7 @@ int program_client_program_output(struct program_client *pclient) if (input == NULL && output != NULL && pclient->dot_output != NULL) { - if ((ret = o_stream_flush(pclient->dot_output)) <= 0) { + if ((ret = o_stream_finish(pclient->dot_output)) <= 0) { if (ret < 0) { i_error("write(%s) failed: %s", o_stream_get_name(output), diff --git a/src/lib-program-client/test-program-client-net.c b/src/lib-program-client/test-program-client-net.c index 78897eb018..9194ed81e7 100644 --- a/src/lib-program-client/test-program-client-net.c +++ b/src/lib-program-client/test-program-client-net.c @@ -179,7 +179,7 @@ void test_program_run(struct test_client *client) } else if (strcmp(args[0], "test_program_io")==0) { os = o_stream_create_dot(client->out, FALSE); o_stream_send_istream(os, client->body); - test_assert(o_stream_flush(os) > 0); + test_assert(o_stream_finish(os) > 0); o_stream_unref(&os); o_stream_nsend_str(client->out, "+\n"); } else if (strcmp(args[0], "test_program_failure")==0) {