]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm: Added doveadm_print_istream() for easily printing istreams.
authorTimo Sirainen <tss@iki.fi>
Thu, 23 Oct 2014 03:37:30 +0000 (06:37 +0300)
committerTimo Sirainen <tss@iki.fi>
Thu, 23 Oct 2014 03:37:30 +0000 (06:37 +0300)
src/doveadm/doveadm-print.c
src/doveadm/doveadm-print.h

index eb51e68c2adca4f031157f4db8c78a7f025f7b2b..c44848e6cd3d6696082860f67da8c481b5372859 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "lib.h"
 #include "array.h"
+#include "istream.h"
 #include "doveadm-print-private.h"
 
 #include <stdio.h>
@@ -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;
index dab95e778498ff649e5010f5393e0aa5cdd82411..51b53149ec71212a7a8eff1d33af34142d75c243 100644 (file)
@@ -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);