1 /* vfs-mount.c - vfs mount 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 struct _gpgme_op_vfs_mount_result result;
40 gpgme_vfs_mount_result_t
41 gpgme_op_vfs_mount_result (gpgme_ctx_t ctx)
47 err = _gpgme_op_data_lookup (ctx, OPDATA_VFS_MOUNT, &hook, -1, NULL);
49 /* Check in case this function is used without having run a command
59 _gpgme_vfs_mount_status_handler (void *priv, const char *code, const char *args)
61 gpgme_ctx_t ctx = (gpgme_ctx_t) priv;
66 err = _gpgme_op_data_lookup (ctx, OPDATA_VFS_MOUNT, &hook, -1, NULL);
71 if (! strcasecmp ("MOUNTPOINT", code))
73 if (opd->result.mount_dir)
74 free (opd->result.mount_dir);
75 opd->result.mount_dir = strdup (args);
83 vfs_start (gpgme_ctx_t ctx, int synchronous,
85 gpgme_assuan_data_cb_t data_cb,
87 gpgme_assuan_inquire_cb_t inq_cb,
89 gpgme_assuan_status_cb_t status_cb,
90 void *status_cb_value)
96 if (!command || !*command)
97 return gpg_error (GPG_ERR_INV_VALUE);
99 /* The flag value 256 is used to suppress an engine reset. This is
100 required to keep the connection running. */
101 err = _gpgme_op_reset (ctx, ((synchronous & 255) | 256));
105 err = _gpgme_op_data_lookup (ctx, OPDATA_VFS_MOUNT, &hook, sizeof (*opd),
111 return _gpgme_engine_op_assuan_transact (ctx->engine, command,
112 data_cb, data_cb_value,
113 inq_cb, inq_cb_value,
114 status_cb, status_cb_value);
120 /* XXXX. This is the asynchronous variant. */
122 gpgme_op_vfs_transact_start (gpgme_ctx_t ctx,
124 gpgme_assuan_data_cb_t data_cb,
126 gpgme_assuan_inquire_cb_t inq_cb,
128 gpgme_assuan_status_cb_t status_cb,
129 void *status_cb_value)
131 return vfs_start (ctx, 0, command, data_cb, data_cb_value,
132 inq_cb, inq_cb_value, status_cb, status_cb_value);
137 /* XXXX. This is the synchronous variant. */
139 gpgme_op_vfs_transact (gpgme_ctx_t ctx,
141 gpgme_assuan_data_cb_t data_cb,
143 gpgme_assuan_inquire_cb_t inq_cb,
145 gpgme_assuan_status_cb_t status_cb,
146 void *status_cb_value,
147 gpgme_error_t *op_err)
151 err = vfs_start (ctx, 1, command, data_cb, data_cb_value,
152 inq_cb, inq_cb_value, status_cb, status_cb_value);
154 err = _gpgme_wait_one_ext (ctx, op_err);
159 /* The actual exported interface follows. */
161 /* The container is automatically unmounted when the context is reset
162 or destroyed. This is a synchronous convenience interface, which
163 automatically returns an operation error if there is no
164 transmission error. */
166 _gpgme_op_vfs_mount (gpgme_ctx_t ctx, const char *container_file,
167 const char *mount_dir, int flags, gpgme_error_t *op_err)
171 char *container_file_esc = NULL;
173 /* We want to encourage people to check error values, so not getting
174 them is discouraged here. Also makes our code easier. */
176 return gpg_error (GPG_ERR_INV_VALUE);
178 err = _gpgme_encode_percent_string (container_file, &container_file_esc, 0);
182 if (asprintf (&cmd, "OPEN -- %s", container_file_esc) < 0)
184 err = gpg_error_from_syserror ();
185 free (container_file_esc);
188 free (container_file_esc);
190 err = gpgme_op_vfs_transact (ctx, cmd, NULL, NULL, NULL, NULL,
198 char *mount_dir_esc = NULL;
200 err = _gpgme_encode_percent_string (mount_dir, &mount_dir_esc, 0);
204 if (asprintf (&cmd, "MOUNT -- %s", mount_dir_esc) < 0)
206 err = gpg_error_from_syserror ();
207 free (mount_dir_esc);
210 free (mount_dir_esc);
214 if (asprintf (&cmd, "MOUNT") < 0)
215 return gpg_error_from_syserror ();
218 err = gpgme_op_vfs_transact (ctx, cmd, NULL, NULL, NULL, NULL,
219 _gpgme_vfs_mount_status_handler, ctx, op_err);
226 gpgme_op_vfs_mount (gpgme_ctx_t ctx, const char *container_file,
227 const char *mount_dir, unsigned int flags,
228 gpgme_error_t *op_err)
232 TRACE_BEG4 (DEBUG_CTX, "gpgme_op_vfs_mount", ctx,
233 "container=%s, mount_dir=%s, flags=0x%x, op_err=%p",
234 container_file, mount_dir, flags, op_err);
235 err = _gpgme_op_vfs_mount (ctx, container_file, mount_dir, flags, op_err);
236 return TRACE_ERR (err);