aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2016-09-15 08:45:04 +0000
committerWerner Koch <[email protected]>2016-09-15 09:39:43 +0000
commited1f2700a73060e2615697491ea9e49ded4293e6 (patch)
tree63501434bf047297fdf770df8c5dac537fdc6be7 /src
parentcore: Minor change of the gpgme_op_edit semantics. (diff)
downloadgpgme-ed1f2700a73060e2615697491ea9e49ded4293e6.tar.gz
gpgme-ed1f2700a73060e2615697491ea9e49ded4293e6.zip
core: New function gpgme_op_interact, deprecate gpgme_op_edit.
* src/gpgme.h.in (gpgme_interact_cb_t): New. (GPGME_INTERACT_CARD): New. (gpgme_op_interact_start, gpgme_op_interact): New. * src/libgpgme.vers, src/gpgme.def: Add new functions. * src/edit.c (op_data_t): Rename fnc to fnc_old and change users. Add fnc. (edit_status_handler): Call old or new callback. (command_handler): Ditto. (interact_start): New. (gpgme_op_interact_start, gpgme_op_interact_start): New. * src/status-table.c (_gpgme_status_to_string): New. * tests/gpg/t-edit.c (edit_fnc): Rename to interact_fnc and change type of STATUS. Use gpgme_io_writen. (main): s/gpgme_op_edit/gpgme_op_interact/. -- This change will eventually allow us to remove all those status codes from gpgme.h. Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to '')
-rw-r--r--src/edit.c102
-rw-r--r--src/gpgme.def2
-rw-r--r--src/gpgme.h.in42
-rw-r--r--src/libgpgme.vers2
-rw-r--r--src/status-table.c12
-rw-r--r--src/util.h1
6 files changed, 146 insertions, 15 deletions
diff --git a/src/edit.c b/src/edit.c
index 1be60c46..887af730 100644
--- a/src/edit.c
+++ b/src/edit.c
@@ -27,12 +27,15 @@
#include "debug.h"
#include "context.h"
#include "ops.h"
+#include "util.h"
+
typedef struct
{
/* The user callback function and its hook value. */
- gpgme_edit_cb_t fnc;
+ gpgme_interact_cb_t fnc;
+ gpgme_edit_cb_t fnc_old;
void *fnc_value;
} *op_data_t;
@@ -58,7 +61,11 @@ edit_status_handler (void *priv, gpgme_status_code_t status, char *args)
if (err)
return err;
- return (*opd->fnc) (opd->fnc_value, status, args, -1);
+ if (opd->fnc_old)
+ return (*opd->fnc_old) (opd->fnc_value, status, args, -1);
+
+ return (*opd->fnc) (opd->fnc_value, _gpgme_status_to_string (status),
+ args, -1);
}
@@ -90,7 +97,12 @@ command_handler (void *priv, gpgme_status_code_t status, const char *args,
if (err)
return err;
- err = (*opd->fnc) (opd->fnc_value, status, args, fd);
+ if (opd->fnc_old)
+ err = (*opd->fnc_old) (opd->fnc_value, status, args, fd);
+ else
+ err = (*opd->fnc) (opd->fnc_value, _gpgme_status_to_string (status),
+ args, fd);
+
if (gpg_err_code (err) == GPG_ERR_FALSE)
err = 0;
else
@@ -103,6 +115,87 @@ command_handler (void *priv, gpgme_status_code_t status, const char *args,
static gpgme_error_t
+interact_start (gpgme_ctx_t ctx, int synchronous, gpgme_key_t key,
+ unsigned int flags,
+ gpgme_interact_cb_t fnc, void *fnc_value, gpgme_data_t out)
+{
+ gpgme_error_t err;
+ void *hook;
+ op_data_t opd;
+
+ err = _gpgme_op_reset (ctx, synchronous);
+ if (err)
+ return err;
+
+ if (!fnc || !out)
+ return gpg_error (GPG_ERR_INV_VALUE);
+
+ err = _gpgme_op_data_lookup (ctx, OPDATA_EDIT, &hook, sizeof (*opd), NULL);
+ opd = hook;
+ if (err)
+ return err;
+
+ opd->fnc = fnc;
+ opd->fnc_old = NULL;
+ opd->fnc_value = fnc_value;
+
+ err = _gpgme_engine_set_command_handler (ctx->engine, command_handler,
+ ctx, out);
+ if (err)
+ return err;
+
+ _gpgme_engine_set_status_handler (ctx->engine, edit_status_handler, ctx);
+
+ return _gpgme_engine_op_edit (ctx->engine,
+ (flags & GPGME_INTERACT_CARD)? 1: 0,
+ key, out, ctx);
+}
+
+
+gpgme_error_t
+gpgme_op_interact_start (gpgme_ctx_t ctx, gpgme_key_t key, unsigned int flags,
+ gpgme_interact_cb_t fnc, void *fnc_value,
+ gpgme_data_t out)
+{
+ gpgme_error_t err;
+
+ TRACE_BEG5 (DEBUG_CTX, "gpgme_op_interact_start", ctx,
+ "key=%p flags=0x%x fnc=%p fnc_value=%p, out=%p",
+ key, flags,fnc, fnc_value, out);
+
+ if (!ctx)
+ return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
+
+ err = interact_start (ctx, 0, key, flags, fnc, fnc_value, out);
+ return err;
+}
+
+
+gpgme_error_t
+gpgme_op_interact (gpgme_ctx_t ctx, gpgme_key_t key, unsigned int flags,
+ gpgme_interact_cb_t fnc, void *fnc_value,
+ gpgme_data_t out)
+{
+ gpgme_error_t err;
+
+ TRACE_BEG5 (DEBUG_CTX, "gpgme_op_interact", ctx,
+ "key=%p flags=0x%x fnc=%p fnc_value=%p, out=%p",
+ key, flags,fnc, fnc_value, out);
+
+ if (!ctx)
+ return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
+
+ err = interact_start (ctx, 1, key, flags, fnc, fnc_value, out);
+ if (!err)
+ err = _gpgme_wait_one (ctx);
+ return err;
+}
+
+
+
+
+/* The deprectated interface. */
+static gpgme_error_t
edit_start (gpgme_ctx_t ctx, int synchronous, int type, gpgme_key_t key,
gpgme_edit_cb_t fnc, void *fnc_value, gpgme_data_t out)
{
@@ -122,7 +215,8 @@ edit_start (gpgme_ctx_t ctx, int synchronous, int type, gpgme_key_t key,
if (err)
return err;
- opd->fnc = fnc;
+ opd->fnc = NULL;
+ opd->fnc_old = fnc;
opd->fnc_value = fnc_value;
err = _gpgme_engine_set_command_handler (ctx->engine, command_handler,
diff --git a/src/gpgme.def b/src/gpgme.def
index 7882af62..9815a834 100644
--- a/src/gpgme.def
+++ b/src/gpgme.def
@@ -241,6 +241,8 @@ EXPORTS
gpgme_op_keysign @181
gpgme_op_tofu_policy_start @182
gpgme_op_tofu_policy @183
+ gpgme_op_interact_start @184
+ gpgme_op_interact @185
; END
diff --git a/src/gpgme.h.in b/src/gpgme.h.in
index 5ed08903..9c87b7b4 100644
--- a/src/gpgme.h.in
+++ b/src/gpgme.h.in
@@ -444,7 +444,9 @@ typedef unsigned int gpgme_export_mode_t;
#define GPGME_AUDITLOG_HTML 1
#define GPGME_AUDITLOG_WITH_HELP 128
-/* The possible stati for the edit operation. */
+
+/* The possible stati for gpgme_op_edit. The use of that function and
+ * these status codes are deprecated in favor of gpgme_op_interact. */
typedef enum
{
GPGME_STATUS_EOF = 0,
@@ -967,8 +969,13 @@ typedef void (*gpgme_progress_cb_t) (void *opaque, const char *what,
typedef gpgme_error_t (*gpgme_status_cb_t) (void *opaque, const char *keyword,
const char *args);
-
/* Interact with the user about an edit operation. */
+typedef gpgme_error_t (*gpgme_interact_cb_t) (void *opaque,
+ const char *keyword,
+ const char *args, int fd);
+
+/* The callback type used by the deprecated functions gpgme_op_card
+ * and gpgme_of_card_edit. */
typedef gpgme_error_t (*gpgme_edit_cb_t) (void *opaque,
gpgme_status_code_t status,
const char *args, int fd);
@@ -1217,7 +1224,7 @@ void gpgme_set_io_cbs (gpgme_ctx_t ctx, gpgme_io_cbs_t io_cbs);
void gpgme_get_io_cbs (gpgme_ctx_t ctx, gpgme_io_cbs_t io_cbs);
/* Wrappers around the internal I/O functions for use with
- gpgme_passphrase_cb_t and gpgme_edit_cb_t. */
+ gpgme_passphrase_cb_t and gpgme_interact_cb_t. */
@API__SSIZE_T@ gpgme_io_read (int fd, void *buffer, size_t count);
@API__SSIZE_T@ gpgme_io_write (int fd, const void *buffer, size_t count);
int gpgme_io_writen (int fd, const void *buffer, size_t count);
@@ -1949,23 +1956,36 @@ gpgme_error_t gpgme_op_keysign (gpgme_ctx_t ctx,
* Key edit interface
*/
-/* Edit the key KEY. Send status and command requests to FNC and
+/* Flags to select the mode of the interact. */
+#define GPGME_INTERACT_CARD (1 << 0) /* Use --card-edit mode. */
+
+
+/* Edit the KEY. Send status and command requests to FNC and
output of edit commands to OUT. */
+gpgme_error_t gpgme_op_interact_start (gpgme_ctx_t ctx,
+ gpgme_key_t key,
+ unsigned int flags,
+ gpgme_interact_cb_t fnc,
+ void *fnc_value,
+ gpgme_data_t out);
+gpgme_error_t gpgme_op_interact (gpgme_ctx_t ctx, gpgme_key_t key,
+ unsigned int flags,
+ gpgme_interact_cb_t fnc,
+ void *fnc_value,
+ gpgme_data_t out);
+
gpgme_error_t gpgme_op_edit_start (gpgme_ctx_t ctx, gpgme_key_t key,
gpgme_edit_cb_t fnc, void *fnc_value,
- gpgme_data_t out);
+ gpgme_data_t out) _GPGME_DEPRECATED;
gpgme_error_t gpgme_op_edit (gpgme_ctx_t ctx, gpgme_key_t key,
gpgme_edit_cb_t fnc, void *fnc_value,
- gpgme_data_t out);
-
-/* Edit the card for the key KEY. Send status and command requests to
- FNC and output of edit commands to OUT. */
+ gpgme_data_t out) _GPGME_DEPRECATED;
gpgme_error_t gpgme_op_card_edit_start (gpgme_ctx_t ctx, gpgme_key_t key,
gpgme_edit_cb_t fnc, void *fnc_value,
- gpgme_data_t out);
+ gpgme_data_t out) _GPGME_DEPRECATED;
gpgme_error_t gpgme_op_card_edit (gpgme_ctx_t ctx, gpgme_key_t key,
gpgme_edit_cb_t fnc, void *fnc_value,
- gpgme_data_t out);
+ gpgme_data_t out) _GPGME_DEPRECATED;
/* Set the Tofu policy of KEY to POLCIY. */
diff --git a/src/libgpgme.vers b/src/libgpgme.vers
index d635b6ba..aec9090d 100644
--- a/src/libgpgme.vers
+++ b/src/libgpgme.vers
@@ -115,6 +115,8 @@ GPGME_1.1 {
gpgme_op_keysign;
gpgme_op_tofu_policy_start;
gpgme_op_tofu_policy;
+ gpgme_op_interact_start;
+ gpgme_op_interact;
};
diff --git a/src/status-table.c b/src/status-table.c
index 1318c8ed..f44a08fb 100644
--- a/src/status-table.c
+++ b/src/status-table.c
@@ -169,3 +169,15 @@ _gpgme_parse_status (const char *name)
sizeof t, status_cmp);
return r ? r->code : -1;
}
+
+
+const char *
+_gpgme_status_to_string (gpgme_status_code_t code)
+{
+ int i;
+
+ for (i=0; i < DIM(status_table); i++)
+ if (status_table[i].code == code)
+ return status_table[i].name;
+ return "status_code_lost";
+}
diff --git a/src/util.h b/src/util.h
index a59700f6..88e77508 100644
--- a/src/util.h
+++ b/src/util.h
@@ -185,6 +185,7 @@ gpgme_error_t _gpgme_getenv (const char *name, char **value);
/* Convert a status string to a status code. */
void _gpgme_status_init (void);
gpgme_status_code_t _gpgme_parse_status (const char *name);
+const char *_gpgme_status_to_string (gpgme_status_code_t code);
#ifdef HAVE_W32_SYSTEM