diff options
Diffstat (limited to 'common/asshelp2.c')
-rw-r--r-- | common/asshelp2.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/common/asshelp2.c b/common/asshelp2.c index 0a7c4549d..32e60dfb0 100644 --- a/common/asshelp2.c +++ b/common/asshelp2.c @@ -36,6 +36,24 @@ #include "util.h" #include "asshelp.h" +#include "status.h" + + +/* A variable with a function to be used to return the current assuan + * context for a CTRL variable. This needs to be set using the + * set_assuan_ctx_func function. */ +static assuan_context_t (*the_assuan_ctx_func)(ctrl_t ctrl); + + +/* Set FUNC to be used as a mapping fucntion from CTRL to an assuan + * context. Pass NULL for FUNC to disable the use of the assuan + * context in this module. */ +void +set_assuan_context_func (assuan_context_t (*func)(ctrl_t ctrl)) +{ + the_assuan_ctx_func = func; +} + /* Helper function to print an assuan status line using a printf format string. */ @@ -134,3 +152,22 @@ print_assuan_status_strings (assuan_context_t ctx, const char *keyword, ...) va_end (arg_ptr); return err; } + + +/* This function is similar to print_assuan_status but takes a CTRL + * arg instead of an assuan context as first argument. */ +gpg_error_t +status_printf (ctrl_t ctrl, int no, const char *format, ...) +{ + gpg_error_t err; + va_list arg_ptr; + assuan_context_t ctx; + + if (!ctrl || !the_assuan_ctx_func || !(ctx = the_assuan_ctx_func (ctrl))) + return 0; + + va_start (arg_ptr, format); + err = vprint_assuan_status (ctx, get_status_string (no), format, arg_ptr); + va_end (arg_ptr); + return err; +} |