From: Timo Sirainen Date: Sat, 8 Dec 2012 08:48:23 +0000 (+0200) Subject: doveadm: table formatter supports now writing by streaming. X-Git-Tag: 2.1.13~27 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=69b728ce94379c297dc0d9247db25648871e5a34;p=thirdparty%2Fdovecot%2Fcore.git doveadm: table formatter supports now writing by streaming. This fixes it to work with doveadm server, which sometimes may use streaming. --- diff --git a/src/doveadm/doveadm-print-table.c b/src/doveadm/doveadm-print-table.c index 06e8258ee7..75c9660295 100644 --- a/src/doveadm/doveadm-print-table.c +++ b/src/doveadm/doveadm-print-table.c @@ -2,6 +2,7 @@ #include "lib.h" #include "array.h" +#include "str.h" #include "doveadm-print-private.h" #include @@ -24,6 +25,7 @@ struct doveadm_print_table_context { pool_t pool; ARRAY_DEFINE(headers, struct doveadm_print_table_header); ARRAY_TYPE(const_string) buffered_values; + string_t *stream; unsigned int hdr_idx; unsigned int columns; @@ -179,10 +181,17 @@ static void doveadm_print_table_print(const char *value) } static void -doveadm_print_table_print_stream(const unsigned char *value ATTR_UNUSED, - size_t size ATTR_UNUSED) +doveadm_print_table_print_stream(const unsigned char *value, size_t size) { - i_fatal("table formatter doesn't support multi-line values"); + if (memchr(value, '\n', size) != NULL) + i_fatal("table formatter doesn't support multi-line values"); + + if (size != 0) + str_append_n(ctx->stream, value, size); + else { + doveadm_print_table_print(str_c(ctx->stream)); + str_truncate(ctx->stream, 0); + } } static void doveadm_print_table_flush(void) @@ -199,6 +208,7 @@ static void doveadm_print_table_init(void) pool = pool_alloconly_create("doveadm print table", 2048); ctx = p_new(pool, struct doveadm_print_table_context, 1); ctx->pool = pool; + ctx->stream = str_new(default_pool, 128); p_array_init(&ctx->headers, pool, 16); i_array_init(&ctx->buffered_values, 64); ctx->columns = DEFAULT_COLUMNS; @@ -211,6 +221,7 @@ static void doveadm_print_table_init(void) static void doveadm_print_table_deinit(void) { + str_free(&ctx->stream); array_free(&ctx->buffered_values); pool_unref(&ctx->pool); ctx = NULL;