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);
99 return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
101 err = opassuan_start (ctx, 0, command, data_cb, data_cb_value,
102 inq_cb, inq_cb_value, status_cb, status_cb_value);
103 return TRACE_ERR (err);
107 /* XXXX. This is the synchronous variant. */
109 gpgme_op_assuan_transact_ext (gpgme_ctx_t ctx,
111 gpgme_assuan_data_cb_t data_cb,
113 gpgme_assuan_inquire_cb_t inq_cb,
115 gpgme_assuan_status_cb_t status_cb,
116 void *status_cb_value,
117 gpgme_error_t *op_err_p)
120 gpgme_error_t op_err;
122 TRACE_BEG8 (DEBUG_CTX, "gpgme_op_assuan_transact", ctx,
123 "command=%s, data_cb=%p/%p, inq_cb=%p/%p, status_cb=%p/%p, "
125 command, data_cb, data_cb_value, inq_cb, inq_cb_value,
126 status_cb, status_cb_value, op_err_p);
129 return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
131 err = opassuan_start (ctx, 1, command,
132 data_cb, data_cb_value,
133 inq_cb, inq_cb_value,
134 status_cb, status_cb_value);
138 err = _gpgme_wait_one_ext (ctx, &op_err);
141 TRACE_LOG2 ("op_err = %s <%s>", gpgme_strerror (op_err),
142 gpgme_strsource (op_err));
145 TRACE_LOG ("warning: operational error ignored by user");
152 return TRACE_ERR (err);
158 /* Compatibility code for old interface. */
160 /* Evil hack breaking abstractions for the purpose of localizing our
161 other hack. This is copied from engine.c. */
164 struct engine_ops *ops;
168 gpg_error_t _gpgme_engine_assuan_last_op_err (void *engine);
170 gpgme_assuan_result_t
171 gpgme_op_assuan_result (gpgme_ctx_t ctx)
177 TRACE_BEG (DEBUG_CTX, "gpgme_op_assuan_result", ctx);
179 err = _gpgme_op_data_lookup (ctx, OPDATA_ASSUAN, &hook, -1, NULL);
181 /* Check in case this function is used without having run a command
185 TRACE_SUC0 ("result=(null)");
189 /* All of this is a hack for the old style interface. The new style
190 interface returns op errors directly. */
191 opd->result.err = _gpgme_engine_assuan_last_op_err (ctx->engine->engine);
194 TRACE_LOG1 ("err = %s", gpg_strerror (0));
198 TRACE_LOG2 ("err = %s <%s>", gpg_strerror (opd->result.err),
199 gpg_strsource (opd->result.err));
202 TRACE_SUC1 ("result=%p", &opd->result);
208 gpgme_op_assuan_transact (gpgme_ctx_t ctx,
210 gpgme_assuan_data_cb_t data_cb,
212 gpgme_assuan_inquire_cb_t inq_cb,
214 gpgme_assuan_status_cb_t status_cb,
215 void *status_cb_value)
219 TRACE (DEBUG_CTX, "gpgme_op_assuan_transact", ctx);
222 return gpg_error (GPG_ERR_INV_VALUE);
224 /* Users of the old-style session based interfaces need to look at
225 the result structure. */
226 err = gpgme_op_assuan_transact_ext (ctx, command, data_cb, data_cb_value,
227 inq_cb, inq_cb_value,
228 status_cb, status_cb_value, NULL);