1 /* opassuan.c - Low-level Assuan operations.
2 Copyright (C) 2009 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, see <http://www.gnu.org/licenses/>.
24 /* Suppress warning for accessing deprecated member "err". */
25 #define _GPGME_IN_GPGME 1
32 /* LEGACY: Remove this when removing the deprecated result
36 struct _gpgme_op_assuan_result result;
41 opassuan_start (gpgme_ctx_t ctx, int synchronous,
43 gpgme_assuan_data_cb_t data_cb,
45 gpgme_assuan_inquire_cb_t inq_cb,
47 gpgme_assuan_status_cb_t status_cb,
48 void *status_cb_value)
52 if (!command || !*command)
53 return gpg_error (GPG_ERR_INV_VALUE);
55 /* The flag value 256 is used to suppress an engine reset. This is
56 required to keep the connection running. */
57 err = _gpgme_op_reset (ctx, ((synchronous&255) | 256));
62 /* LEGACY: Remove this when removing the deprecated result
66 err = _gpgme_op_data_lookup (ctx, OPDATA_ASSUAN, &hook,
72 return _gpgme_engine_op_assuan_transact (ctx->engine, command,
73 data_cb, data_cb_value,
75 status_cb, status_cb_value);
80 /* XXXX. This is the asynchronous variant. */
82 gpgme_op_assuan_transact_start (gpgme_ctx_t ctx,
84 gpgme_assuan_data_cb_t data_cb,
86 gpgme_assuan_inquire_cb_t inq_cb,
88 gpgme_assuan_status_cb_t status_cb,
89 void *status_cb_value)
93 TRACE_BEG7 (DEBUG_CTX, "gpgme_op_assuan_transact_start", ctx,
94 "command=%s, data_cb=%p/%p, inq_cb=%p/%p, status_cb=%p/%p",
95 command, data_cb, data_cb_value, inq_cb, inq_cb_value,
96 status_cb, status_cb_value);
98 err = opassuan_start (ctx, 0, command, data_cb, data_cb_value,
99 inq_cb, inq_cb_value, status_cb, status_cb_value);
100 return TRACE_ERR (err);
104 /* XXXX. This is the synchronous variant. */
106 gpgme_op_assuan_transact_ext (gpgme_ctx_t ctx,
108 gpgme_assuan_data_cb_t data_cb,
110 gpgme_assuan_inquire_cb_t inq_cb,
112 gpgme_assuan_status_cb_t status_cb,
113 void *status_cb_value,
114 gpgme_error_t *op_err_p)
117 gpgme_error_t op_err;
119 TRACE_BEG8 (DEBUG_CTX, "gpgme_op_assuan_transact", ctx,
120 "command=%s, data_cb=%p/%p, inq_cb=%p/%p, status_cb=%p/%p, "
122 command, data_cb, data_cb_value, inq_cb, inq_cb_value,
123 status_cb, status_cb_value, op_err_p);
125 err = opassuan_start (ctx, 1, command,
126 data_cb, data_cb_value,
127 inq_cb, inq_cb_value,
128 status_cb, status_cb_value);
132 err = _gpgme_wait_one_ext (ctx, &op_err);
135 TRACE_LOG2 ("op_err = %s <%s>", gpgme_strerror (op_err),
136 gpgme_strsource (op_err));
139 TRACE_LOG ("warning: operational error ignored by user");
146 return TRACE_ERR (err);
152 /* Compatibility code for old interface. */
154 /* Evil hack breaking abstractions for the purpose of localizing our
155 other hack. This is copied from engine.c. */
158 struct engine_ops *ops;
162 gpg_error_t _gpgme_engine_assuan_last_op_err (void *engine);
164 gpgme_assuan_result_t
165 gpgme_op_assuan_result (gpgme_ctx_t ctx)
171 TRACE_BEG (DEBUG_CTX, "gpgme_op_assuan_result", ctx);
173 err = _gpgme_op_data_lookup (ctx, OPDATA_ASSUAN, &hook, -1, NULL);
175 /* Check in case this function is used without having run a command
179 TRACE_SUC0 ("result=(null)");
183 /* All of this is a hack for the old style interface. The new style
184 interface returns op errors directly. */
185 opd->result.err = _gpgme_engine_assuan_last_op_err (ctx->engine->engine);
188 TRACE_LOG1 ("err = %s", gpg_strerror (0));
192 TRACE_LOG2 ("err = %s <%s>", gpg_strerror (opd->result.err),
193 gpg_strsource (opd->result.err));
196 TRACE_SUC1 ("result=%p", &opd->result);
202 gpgme_op_assuan_transact (gpgme_ctx_t ctx,
204 gpgme_assuan_data_cb_t data_cb,
206 gpgme_assuan_inquire_cb_t inq_cb,
208 gpgme_assuan_status_cb_t status_cb,
209 void *status_cb_value)
213 TRACE (DEBUG_CTX, "gpgme_op_assuan_transact", ctx);
215 /* Users of the old-style session based interfaces need to look at
216 the result structure. */
217 err = gpgme_op_assuan_transact_ext (ctx, command, data_cb, data_cb_value,
218 inq_cb, inq_cb_value,
219 status_cb, status_cb_value, NULL);