1 /* edit.c - Key edit function.
2 Copyright (C) 2002, 2003, 2004 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 Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of
9 the License, or (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 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
34 /* The user callback function and its hook value. */
41 edit_status_handler (void *priv, gpgme_status_code_t status, char *args)
43 gpgme_ctx_t ctx = (gpgme_ctx_t) priv;
48 err = _gpgme_passphrase_status_handler (priv, status, args);
52 err = _gpgme_progress_status_handler (priv, status, args);
56 err = _gpgme_op_data_lookup (ctx, OPDATA_EDIT, &hook, -1, NULL);
61 return (*opd->fnc) (opd->fnc_value, status, args, -1);
66 command_handler (void *priv, gpgme_status_code_t status, const char *args,
67 int fd, int *processed_r)
69 gpgme_ctx_t ctx = (gpgme_ctx_t) priv;
73 if (ctx->passphrase_cb)
75 err = _gpgme_passphrase_command_handler (ctx, status, args,
86 err = _gpgme_op_data_lookup (ctx, OPDATA_EDIT, &hook, -1, NULL);
91 /* FIXME: We expect the user to handle _all_ status codes.
92 Later, we may fix the callback interface to allow the user
93 indicate if it processed the status code or not. */
96 return (*opd->fnc) (opd->fnc_value, status, args, fd);
99 *processed_r = processed;
105 edit_start (gpgme_ctx_t ctx, int synchronous, int type, gpgme_key_t key,
106 gpgme_edit_cb_t fnc, void *fnc_value, gpgme_data_t out)
112 err = _gpgme_op_reset (ctx, synchronous);
117 return gpg_error (GPG_ERR_INV_VALUE);
119 err = _gpgme_op_data_lookup (ctx, OPDATA_EDIT, &hook, sizeof (*opd), NULL);
125 opd->fnc_value = fnc_value;
127 err = _gpgme_engine_set_command_handler (ctx->engine, command_handler,
132 _gpgme_engine_set_status_handler (ctx->engine, edit_status_handler, ctx);
134 return _gpgme_engine_op_edit (ctx->engine, type, key, out, ctx);
139 gpgme_op_edit_start (gpgme_ctx_t ctx, gpgme_key_t key,
140 gpgme_edit_cb_t fnc, void *fnc_value, gpgme_data_t out)
144 TRACE_BEG5 (DEBUG_CTX, "gpgme_op_edit_start", ctx,
145 "key=%p (%s), fnc=%p fnc_value=%p, out=%p", key,
146 (key->subkeys && key->subkeys->fpr) ?
147 key->subkeys->fpr : "invalid", fnc, fnc_value, out);
150 return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
152 err = edit_start (ctx, 0, 0, key, fnc, fnc_value, out);
157 /* Edit the key KEY. Send status and command requests to FNC and
158 output of edit commands to OUT. */
160 gpgme_op_edit (gpgme_ctx_t ctx, gpgme_key_t key,
161 gpgme_edit_cb_t fnc, void *fnc_value, gpgme_data_t out)
165 TRACE_BEG5 (DEBUG_CTX, "gpgme_op_edit", ctx,
166 "key=%p (%s), fnc=%p fnc_value=%p, out=%p", key,
167 (key->subkeys && key->subkeys->fpr) ?
168 key->subkeys->fpr : "invalid", fnc, fnc_value, out);
171 return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
173 err = edit_start (ctx, 1, 0, key, fnc, fnc_value, out);
176 err = _gpgme_wait_one (ctx);
177 return TRACE_ERR (err);
182 gpgme_op_card_edit_start (gpgme_ctx_t ctx, gpgme_key_t key,
183 gpgme_edit_cb_t fnc, void *fnc_value,
188 TRACE_BEG5 (DEBUG_CTX, "gpgme_op_card_edit_start", ctx,
189 "key=%p (%s), fnc=%p fnc_value=%p, out=%p", key,
190 (key->subkeys && key->subkeys->fpr) ?
191 key->subkeys->fpr : "invalid", fnc, fnc_value, out);
194 return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
196 err = edit_start (ctx, 0, 1, key, fnc, fnc_value, out);
201 /* Edit the card for the key KEY. Send status and command requests to
202 FNC and output of edit commands to OUT. */
204 gpgme_op_card_edit (gpgme_ctx_t ctx, gpgme_key_t key,
205 gpgme_edit_cb_t fnc, void *fnc_value, gpgme_data_t out)
209 TRACE_BEG5 (DEBUG_CTX, "gpgme_op_card_edit", ctx,
210 "key=%p (%s), fnc=%p fnc_value=%p, out=%p", key,
211 (key->subkeys && key->subkeys->fpr) ?
212 key->subkeys->fpr : "invalid", fnc, fnc_value, out);
215 return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
217 err = edit_start (ctx, 1, 1, key, fnc, fnc_value, out);
219 err = _gpgme_wait_one (ctx);
220 return TRACE_ERR (err);