From 80bc6f4feafd94bfaf3bf77e7b4038c03b81de3a Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Thu, 23 Oct 2014 06:37:30 +0300 Subject: [PATCH] doveadm: Added doveadm_print_istream() for easily printing istreams. --- src/doveadm/doveadm-print.c | 21 +++++++++++++++++++++ src/doveadm/doveadm-print.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/src/doveadm/doveadm-print.c b/src/doveadm/doveadm-print.c index eb51e68c2a..c44848e6cd 100644 --- a/src/doveadm/doveadm-print.c +++ b/src/doveadm/doveadm-print.c @@ -2,6 +2,7 @@ #include "lib.h" #include "array.h" +#include "istream.h" #include "doveadm-print-private.h" #include @@ -101,6 +102,26 @@ void doveadm_print_stream(const void *value, size_t size) } } +int doveadm_print_istream(struct istream *input) +{ + const unsigned char *data; + size_t size; + ssize_t ret; + + while ((ret = i_stream_read_data(input, &data, &size, 0)) > 0) { + doveadm_print_stream(data, size); + i_stream_skip(input, size); + } + i_assert(ret == -1); + doveadm_print_stream("", 0); + if (input->stream_errno != 0) { + i_error("read(%s) failed: %s", i_stream_get_name(input), + i_stream_get_error(input)); + return -1; + } + return 0; +} + void doveadm_print_sticky(const char *key, const char *value) { struct doveadm_print_header_context *hdr; diff --git a/src/doveadm/doveadm-print.h b/src/doveadm/doveadm-print.h index dab95e7784..51b53149ec 100644 --- a/src/doveadm/doveadm-print.h +++ b/src/doveadm/doveadm-print.h @@ -23,6 +23,8 @@ void doveadm_print(const char *value); void doveadm_print_num(uintmax_t value); /* Stream for same field continues until len=0 */ void doveadm_print_stream(const void *value, size_t size); +/* Print the whole input stream. Returns 0 if ok, -1 if stream read() failed */ +int doveadm_print_istream(struct istream *input); void doveadm_print_sticky(const char *key, const char *value); void doveadm_print_flush(void); void doveadm_print_unstick_headers(void); -- 2.47.3