aboutsummaryrefslogtreecommitdiffstats
path: root/src/engine-gpg.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2016-05-19 15:01:07 +0000
committerWerner Koch <[email protected]>2016-05-19 15:04:54 +0000
commit88f2c1c0d16eee6bb36a901623ea65ac69499f03 (patch)
tree4ac0d8ab84bee699987f61e277e8c4d80e857850 /src/engine-gpg.c
parentapi: Remove arbitrary restriction from gpgme_op_verify. (diff)
downloadgpgme-88f2c1c0d16eee6bb36a901623ea65ac69499f03.tar.gz
gpgme-88f2c1c0d16eee6bb36a901623ea65ac69499f03.zip
api: Add new function gpgme_set_ctx_flag.
* src/gpgme.h.in (gpgme_set_ctx_flag): New prototype. * src/gpgme.c (gpgme_set_ctx_flag): New. * src/gpgme.def, src/libgpgme.vers: Add new function. * src/context.h (struct gpgme_context): Add FULL_STATUS. * src/decrypt.c (_gpgme_decrypt_status_handler): Do not call the status callback if FULL_STATUS is set. * src/genkey.c (genkey_status_handler): Ditto. * src/passphrase.c (_gpgme_passphrase_status_handler): Ditto. * src/sign.c (_gpgme_sign_status_handler): Ditto. * src/engine-backend.h (struct engine_ops): Add SET_STATUS_CB and add adjust all definitions of that variable. * src/engine.c (_gpgme_engine_set_status_cb): New. * src/op-support.c (_gpgme_op_reset): Call this function. * src/engine-gpg.c (struct engine_gpg): Add fields MON_CB and MON_CB_VALUE. (gpg_set_status_cb): New. (_gpgme_engine_ops_gpg): Register that function. (read_status): Call the monitor callback. * src/engine-gpgsm.c (struct engine_gpgsm): Add fields MON_CB and MON_CB_VALUE. (_gpgme_engine_ops_gpgsm): Register that function. (gpgsm_assuan_simple_command): Change first arg to be an engine context and adjust call callers. Call the monitor callback. * src/engine-uiserver.c (struct engine_uiserver): Add fields MON_CB and MON_CB_VALUE. (_gpgme_engine_ops_uiserver): Register that function. (uiserver_assuan_simple_command): Change first arg to be an engine context and adjust call callers. Call the monitor callback. * tests/run-verify.c (status_cb): New. (print_result): Print algo names. (main): Add option --status. -- This new feature is mainly intended for bug tracking. Having access to the raw status lines might also be useful for applications, though. Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'src/engine-gpg.c')
-rw-r--r--src/engine-gpg.c39
1 files changed, 31 insertions, 8 deletions
diff --git a/src/engine-gpg.c b/src/engine-gpg.c
index 9efced25..e507c683 100644
--- a/src/engine-gpg.c
+++ b/src/engine-gpg.c
@@ -95,6 +95,8 @@ struct engine_gpg
int eof;
engine_status_handler_t fnc;
void *fnc_value;
+ gpgme_status_cb_t mon_cb;
+ void *mon_cb_value;
void *tag;
} status;
@@ -609,6 +611,17 @@ gpg_set_locale (void *engine, int category, const char *value)
return 0;
}
+/* This sets a status callback for monitoring status lines before they
+ * are passed to a caller set handler. */
+static void
+gpg_set_status_cb (void *engine, gpgme_status_cb_t cb, void *cb_value)
+{
+ engine_gpg_t gpg = engine;
+
+ gpg->status.mon_cb = cb;
+ gpg->status.mon_cb_value = cb_value;
+}
+
/* Note, that the status_handler is allowed to modifiy the args
value. */
@@ -1019,6 +1032,7 @@ read_status (engine_gpg_t gpg)
size_t bufsize = gpg->status.bufsize;
char *buffer = gpg->status.buffer;
size_t readpos = gpg->status.readpos;
+ gpgme_error_t err;
assert (buffer);
if (bufsize - readpos < 256)
@@ -1037,15 +1051,15 @@ read_status (engine_gpg_t gpg)
if (!nread)
{
+ err = 0;
gpg->status.eof = 1;
+ if (gpg->status.mon_cb)
+ err = gpg->status.mon_cb (gpg->status.mon_cb_value,
+ GPGME_STATUS_EOF, "");
if (gpg->status.fnc)
- {
- gpgme_error_t err;
- err = gpg->status.fnc (gpg->status.fnc_value, GPGME_STATUS_EOF, "");
- if (err)
- return err;
- }
- return 0;
+ err = gpg->status.fnc (gpg->status.fnc_value, GPGME_STATUS_EOF, "");
+
+ return err;
}
while (nread > 0)
@@ -1071,6 +1085,15 @@ read_status (engine_gpg_t gpg)
*rest++ = 0;
r = _gpgme_parse_status (buffer + 9);
+ if (gpg->status.mon_cb && r != GPGME_STATUS_PROGRESS)
+ {
+ /* Note that we call the monitor even if we do
+ * not know the status code (r < 0). */
+ err = gpg->status.mon_cb (gpg->status.mon_cb_value,
+ buffer + 9, rest);
+ if (err)
+ return err;
+ }
if (r >= 0)
{
if (gpg->cmd.used
@@ -1099,7 +1122,6 @@ read_status (engine_gpg_t gpg)
}
else if (gpg->status.fnc)
{
- gpgme_error_t err;
err = gpg->status.fnc (gpg->status.fnc_value,
r, rest);
if (err)
@@ -2470,6 +2492,7 @@ struct engine_ops _gpgme_engine_ops_gpg =
/* Member functions. */
gpg_release,
NULL, /* reset */
+ gpg_set_status_cb,
gpg_set_status_handler,
gpg_set_command_handler,
gpg_set_colon_line_handler,