]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail: ostream-dot - Require o_stream_finish() to write the trailer
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 27 Oct 2017 23:43:16 +0000 (02:43 +0300)
committerTimo Sirainen <tss@dovecot.fi>
Mon, 30 Oct 2017 11:04:53 +0000 (13:04 +0200)
Similar to ostream-zlib.

src/doveadm/server-connection.c
src/lib-mail/ostream-dot.c
src/lib-mail/test-ostream-dot.c
src/lib-program-client/program-client.c
src/lib-program-client/test-program-client-net.c

index fa12d629d5037bac06b3a4fe122b788b98040f6d..96f475fae37a44687802b97720ef5a8c48d492dc 100644 (file)
@@ -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",
index 04ca30c70a954ddcee62c4b27a25841a12950e6a..d386380176240b3661a616d1bc5e728eca08cb0a 100644 (file)
@@ -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);
index a56a2a4185c8497a874574ffe9580c04c0e74ad0..4740a62c57e644e58eaf44efa608a37ae8119566 100644 (file)
@@ -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);
index 1231178e8e1740cf02f6938aaab354bc636ff1f0..f2143c32f311d254212bcd8211cca90475653cbb 100644 (file)
@@ -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),
index 78897eb0185063785bb786f49ed5685c47a958fb..9194ed81e7ac67d9a7924bdc3793109e1d9285ab 100644 (file)
@@ -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) {