diff options
| author | Werner Koch <[email protected]> | 2018-02-22 15:19:56 +0000 |
|---|---|---|
| committer | Werner Koch <[email protected]> | 2018-02-22 15:19:56 +0000 |
| commit | 20539ea5cad1903352e01ef95aecdda4d5cd999b (patch) | |
| tree | 609042662948bcd256dd4400b64bdb5e656173e4 /common/asshelp2.c | |
| parent | build: Update autogen.sh to set a git PATCH prefix. (diff) | |
| parent | Post release updates. (diff) | |
| download | gnupg-20539ea5cad1903352e01ef95aecdda4d5cd999b.tar.gz gnupg-20539ea5cad1903352e01ef95aecdda4d5cd999b.zip | |
Merge branch 'STABLE-BRANCH-2-2'
Diffstat (limited to 'common/asshelp2.c')
| -rw-r--r-- | common/asshelp2.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/common/asshelp2.c b/common/asshelp2.c index f85c1e67e..0a7c4549d 100644 --- a/common/asshelp2.c +++ b/common/asshelp2.c @@ -71,3 +71,66 @@ print_assuan_status (assuan_context_t ctx, va_end (arg_ptr); return err; } + + +/* Helper function to print a list of strings as an assuan status + * line. KEYWORD is the first item on the status line. ARG_PTR is a + * list of strings which are all separated by a space in the output. + * The last argument must be a NULL. Linefeeds and carriage returns + * characters (which are not allowed in an Assuan status line) are + * silently quoted in C-style. */ +gpg_error_t +vprint_assuan_status_strings (assuan_context_t ctx, + const char *keyword, va_list arg_ptr) +{ + gpg_error_t err = 0; + const char *text; + char buf[950], *p; + size_t n; + + p = buf; + n = 0; + while ((text = va_arg (arg_ptr, const char *)) && n < DIM (buf)-3 ) + { + if (n) + { + *p++ = ' '; + n++; + } + for ( ; *text && n < DIM (buf)-3; n++, text++) + { + if (*text == '\n') + { + *p++ = '\\'; + *p++ = 'n'; + n++; + } + else if (*text == '\r') + { + *p++ = '\\'; + *p++ = 'r'; + n++; + } + else + *p++ = *text; + } + } + *p = 0; + err = assuan_write_status (ctx, keyword, buf); + + return err; +} + + +/* See vprint_assuan_status_strings. */ +gpg_error_t +print_assuan_status_strings (assuan_context_t ctx, const char *keyword, ...) +{ + va_list arg_ptr; + gpg_error_t err; + + va_start (arg_ptr, keyword); + err = vprint_assuan_status_strings (ctx, keyword, arg_ptr); + va_end (arg_ptr); + return err; +} |
