From 71b55c945542e695161ddbd783f87c5f534012a5 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Tue, 11 Mar 2014 14:27:58 +0100 Subject: dirmngr: Make Assuan output of keyblocks easier readable * dirmngr/server.c (data_line_cookie_write): Print shorter data lines in verbose mode. --- dirmngr/server.c | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'dirmngr') diff --git a/dirmngr/server.c b/dirmngr/server.c index 9a0244195..d2682eaaa 100644 --- a/dirmngr/server.c +++ b/dirmngr/server.c @@ -141,14 +141,44 @@ leave_cmd (assuan_context_t ctx, gpg_error_t err) /* A write handler used by es_fopencookie to write assuan data lines. */ static ssize_t -data_line_cookie_write (void *cookie, const void *buffer, size_t size) +data_line_cookie_write (void *cookie, const void *buffer_arg, size_t size) { assuan_context_t ctx = cookie; + const char *buffer = buffer_arg; - if (assuan_send_data (ctx, buffer, size)) + if (opt.verbose && buffer && size) { - gpg_err_set_errno (EIO); - return -1; + /* Ease reading of output by sending a physical line at each LF. */ + const char *p; + size_t n, nbytes; + + nbytes = size; + do + { + p = memchr (buffer, '\n', nbytes); + n = p ? (p - buffer) + 1 : nbytes; + if (assuan_send_data (ctx, buffer, n)) + { + gpg_err_set_errno (EIO); + return -1; + } + buffer += n; + nbytes -= n; + if (nbytes && assuan_send_data (ctx, NULL, 0)) /* Flush line. */ + { + gpg_err_set_errno (EIO); + return -1; + } + } + while (nbytes); + } + else + { + if (assuan_send_data (ctx, buffer, size)) + { + gpg_err_set_errno (EIO); + return -1; + } } return size; -- cgit v1.2.3