1 /* vfs-create.c - vfs create support in GPGME
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, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
35 vfs_start (gpgme_ctx_t ctx, int synchronous,
37 gpgme_assuan_data_cb_t data_cb,
39 gpgme_assuan_inquire_cb_t inq_cb,
41 gpgme_assuan_status_cb_t status_cb,
42 void *status_cb_value)
46 if (!command || !*command)
47 return gpg_error (GPG_ERR_INV_VALUE);
49 /* The flag value 256 is used to suppress an engine reset. This is
50 required to keep the connection running. */
51 err = _gpgme_op_reset (ctx, ((synchronous & 255) | 256));
55 return _gpgme_engine_op_assuan_transact (ctx->engine, command,
56 data_cb, data_cb_value,
58 status_cb, status_cb_value);
63 /* XXXX. This is the asynchronous variant. */
65 gpgme_op_vfs_transact_start (gpgme_ctx_t ctx,
67 gpgme_assuan_data_cb_t data_cb,
69 gpgme_assuan_inquire_cb_t inq_cb,
71 gpgme_assuan_status_cb_t status_cb,
72 void *status_cb_value)
74 return vfs_start (ctx, 0, command, data_cb, data_cb_value,
75 inq_cb, inq_cb_value, status_cb, status_cb_value);
80 /* XXXX. This is the synchronous variant. */
82 gpgme_op_vfs_transact (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,
90 gpgme_error_t *op_err)
94 err = vfs_start (ctx, 1, command, data_cb, data_cb_value,
95 inq_cb, inq_cb_value, status_cb, status_cb_value);
97 err = _gpgme_wait_one_ext (ctx, op_err);
102 /* The actual exported interface follows. */
104 /* The container is automatically uncreateed when the context is reset
105 or destroyed. This is a synchronous convenience interface, which
106 automatically returns an operation error if there is no
107 transmission error. */
109 _gpgme_op_vfs_create (gpgme_ctx_t ctx, gpgme_key_t recp[],
110 const char *container_file, unsigned int flags,
111 gpgme_error_t *op_err)
115 char *container_file_esc = NULL;
118 /* We want to encourage people to check error values, so not getting
119 them is discouraged here. Also makes our code easier. */
121 return gpg_error (GPG_ERR_INV_VALUE);
123 err = _gpgme_encode_percent_string (container_file, &container_file_esc, 0);
128 while (!err && recp[i])
130 if (!recp[i]->subkeys || !recp[i]->subkeys->fpr)
132 free (container_file_esc);
133 return gpg_error (GPG_ERR_UNUSABLE_PUBKEY);
136 if (asprintf (&cmd, "RECIPIENT %s", recp[i]->subkeys->fpr) < 0)
138 err = gpg_error_from_syserror ();
139 free (container_file_esc);
143 err = gpgme_op_vfs_transact (ctx, cmd, NULL, NULL, NULL, NULL,
148 free (container_file_esc);
154 if (asprintf (&cmd, "CREATE -- %s", container_file_esc) < 0)
156 err = gpg_error_from_syserror ();
157 free (container_file_esc);
160 free (container_file_esc);
162 err = gpgme_op_vfs_transact (ctx, cmd, NULL, NULL, NULL, NULL,
171 gpgme_op_vfs_create (gpgme_ctx_t ctx, gpgme_key_t recp[],
172 const char *container_file, unsigned int flags,
173 gpgme_error_t *op_err)
177 TRACE_BEG3 (DEBUG_CTX, "gpgme_op_vfs_create", ctx,
178 "container_file=%s, flags=0x%x, op_err=%p",
179 container_file, flags, op_err);
181 if (_gpgme_debug_trace () && recp)
187 TRACE_LOG3 ("recipient[%i] = %p (%s)", i, recp[i],
188 (recp[i]->subkeys && recp[i]->subkeys->fpr) ?
189 recp[i]->subkeys->fpr : "invalid");
194 err = _gpgme_op_vfs_create (ctx, recp, container_file, flags, op_err);
195 return TRACE_ERR (err);