aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2018-09-05 14:57:30 +0000
committerWerner Koch <[email protected]>2018-09-05 14:57:30 +0000
commitd4489be467e7229e17fb17a0489bf711d6ce66d6 (patch)
tree17ed779fc756f6d93b19dc5cbb7e02b5a7de3739
parentartwork: State license of the logo (diff)
downloadgnupg-d4489be467e7229e17fb17a0489bf711d6ce66d6.tar.gz
gnupg-d4489be467e7229e17fb17a0489bf711d6ce66d6.zip
common: New function status_printf.
* common/asshelp2.c (set_assuan_context_func): New. (status_printf): New. * po/Makevars (XGETTEXT_OPTIONS): Add status_printf -- This is a first patch to unify the status printing functions. Signed-off-by: Werner Koch <[email protected]>
-rw-r--r--common/asshelp.h6
-rw-r--r--common/asshelp2.c37
-rw-r--r--po/Makevars1
3 files changed, 44 insertions, 0 deletions
diff --git a/common/asshelp.h b/common/asshelp.h
index bf1bd1705..c2c87e3c4 100644
--- a/common/asshelp.h
+++ b/common/asshelp.h
@@ -82,8 +82,14 @@ gpg_error_t get_assuan_server_version (assuan_context_t ctx,
/*-- asshelp2.c --*/
+void set_assuan_context_func (assuan_context_t (*func)(ctrl_t ctrl));
+
/* Helper function to print an assuan status line using a printf
format string. */
+
+gpg_error_t status_printf (ctrl_t ctrl, int no, const char *format,
+ ...) GPGRT_ATTR_PRINTF(3,4);
+
gpg_error_t print_assuan_status (assuan_context_t ctx,
const char *keyword,
const char *format,
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;
+}
diff --git a/po/Makevars b/po/Makevars
index 90b0c5b83..60a6fb36e 100644
--- a/po/Makevars
+++ b/po/Makevars
@@ -53,6 +53,7 @@ XGETTEXT_OPTIONS = \
--flag=xasprintf:1:c-format \
--flag=xtryasprintf:1:c-format \
--flag=log_debug_with_string:2:c-format \
+ --flag=status_printf:3:c-format \
--flag=print_assuan_status:3:c-format \
--flag=vprint_assuan_status:3:c-format \
--flag=agent_print_status:3:c-format \