From 8ddc5801ade02297924447df5745c8877a96e5e3 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Tue, 25 Aug 2015 13:22:43 +0200 Subject: Improve error return by checking the FAILURE status. * src/gpgme.h.in (GPGME_STATUS_FAILURE): New. * src/status-table.c (FAILURE): New. * src/op-support.c (_gpgme_parse_failure): New. * src/passphrase.c (_gpgme_passphrase_status_handler): Forward FAILURE status line to the status callback. * src/decrypt.c (op_data_t): Add field failure_code. (_gpgme_decrypt_status_handler): Parse that code and act upon it on EOF. * src/encrypt.c (op_data_t): Add field failure_code. (_gpgme_encrypt_status_handler): Parse that code and act upon it on EOF. * src/genkey.c (op_data_t): Add field failure_code. (genkey_status_handler): Parse that code and act upon it on EOF. * src/passwd.c (op_data_t): Add field failure_code. (passwd_status_handler): Parse that code and act upon it on EOF. * src/sign.c (op_data_t): Add field failure_code. (_gpgme_sign_status_handler): Parse that code and act upon it on EOF. * src/verify.c (op_data_t): Add field failure_code. (_gpgme_verify_status_handler): Parse that code and act upon it on EOF. -- This requires GnuPG 2.1.8 to actually make a difference. Signed-off-by: Werner Koch --- src/op-support.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/op-support.c') diff --git a/src/op-support.c b/src/op-support.c index 2bcb3a35..02940efd 100644 --- a/src/op-support.c +++ b/src/op-support.c @@ -337,3 +337,27 @@ _gpgme_parse_plaintext (char *args, char **filenamep) } return 0; } + + +/* Parse a FAILURE status line and return the error code. ARGS is + modified to contain the location part. */ +gpgme_error_t +_gpgme_parse_failure (char *args) +{ + char *where, *which; + + where = strchr (args, ' '); + if (!where) + return trace_gpg_error (GPG_ERR_INV_ENGINE); + + *where = '\0'; + which = where + 1; + + where = strchr (which, ' '); + if (where) + *where = '\0'; + + where = args; + + return atoi (which); +} -- cgit v1.2.3