1 /* edit.c - Key edit function.
2 Copyright (C) 2002, 2003 g10 Code GmbH
4 This file is part of GPGME.
6 GPGME is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 GPGME is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GPGME; if not, write to the Free Software Foundation,
18 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
32 /* The user callback function and its hook value. */
39 edit_status_handler (void *priv, gpgme_status_code_t status, char *args)
41 gpgme_ctx_t ctx = (gpgme_ctx_t) priv;
46 err = _gpgme_passphrase_status_handler (priv, status, args);
50 err = _gpgme_progress_status_handler (priv, status, args);
54 err = _gpgme_op_data_lookup (ctx, OPDATA_EDIT, &hook, -1, NULL);
59 return (*opd->fnc) (opd->fnc_value, status, args, -1);
64 command_handler (void *priv, gpgme_status_code_t status, const char *args,
67 gpgme_ctx_t ctx = (gpgme_ctx_t) priv;
71 if (ctx->passphrase_cb)
73 err = _gpgme_passphrase_command_handler_internal (ctx, status, args,
84 err = _gpgme_op_data_lookup (ctx, OPDATA_EDIT, &hook, -1, NULL);
89 return (*opd->fnc) (opd->fnc_value, status, args, fd);
96 edit_start (gpgme_ctx_t ctx, int synchronous, int type, gpgme_key_t key,
97 gpgme_edit_cb_t fnc, void *fnc_value, gpgme_data_t out)
103 err = _gpgme_op_reset (ctx, synchronous);
108 return gpg_error (GPG_ERR_INV_VALUE);
110 err = _gpgme_op_data_lookup (ctx, OPDATA_EDIT, &hook, sizeof (*opd), NULL);
116 opd->fnc_value = fnc_value;
118 err = _gpgme_engine_set_command_handler (ctx->engine, command_handler,
123 _gpgme_engine_set_status_handler (ctx->engine, edit_status_handler, ctx);
125 return _gpgme_engine_op_edit (ctx->engine, type, key, out, ctx);
130 gpgme_op_edit_start (gpgme_ctx_t ctx, gpgme_key_t key,
131 gpgme_edit_cb_t fnc, void *fnc_value, gpgme_data_t out)
133 return edit_start (ctx, 0, 0, key, fnc, fnc_value, out);
137 /* Edit the key KEY. Send status and command requests to FNC and
138 output of edit commands to OUT. */
140 gpgme_op_edit (gpgme_ctx_t ctx, gpgme_key_t key,
141 gpgme_edit_cb_t fnc, void *fnc_value, gpgme_data_t out)
143 gpgme_error_t err = edit_start (ctx, 1, 0, key, fnc, fnc_value, out);
145 err = _gpgme_wait_one (ctx);
151 gpgme_op_card_edit_start (gpgme_ctx_t ctx, gpgme_key_t key,
152 gpgme_edit_cb_t fnc, void *fnc_value,
155 return edit_start (ctx, 0, 1, key, fnc, fnc_value, out);
159 /* Edit the card for the key KEY. Send status and command requests to
160 FNC and output of edit commands to OUT. */
162 gpgme_op_card_edit (gpgme_ctx_t ctx, gpgme_key_t key,
163 gpgme_edit_cb_t fnc, void *fnc_value, gpgme_data_t out)
165 gpgme_error_t err = edit_start (ctx, 1, 1, key, fnc, fnc_value, out);
167 err = _gpgme_wait_one (ctx);