2002-10-09 12:26:00 +00:00
|
|
|
|
/* data-user.c - A user callback based data object.
|
2018-11-16 12:27:33 +00:00
|
|
|
|
* Copyright (C) 2002, 2004 g10 Code GmbH
|
|
|
|
|
*
|
|
|
|
|
* This file is part of GPGME.
|
|
|
|
|
*
|
|
|
|
|
* GPGME is free software; you can redistribute it and/or modify it
|
|
|
|
|
* under the terms of the GNU Lesser General Public License as
|
|
|
|
|
* published by the Free Software Foundation; either version 2.1 of
|
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* GPGME is distributed in the hope that it will be useful, but
|
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this program; if not, see <https://gnu.org/licenses/>.
|
|
|
|
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
|
*/
|
2002-10-09 12:26:00 +00:00
|
|
|
|
|
|
|
|
|
#if HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2010-11-03 09:56:27 +00:00
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
|
# include <sys/types.h>
|
|
|
|
|
#endif
|
2005-05-28 20:03:24 +00:00
|
|
|
|
#include <errno.h>
|
2002-10-09 12:26:00 +00:00
|
|
|
|
|
2009-10-26 17:38:39 +00:00
|
|
|
|
#include "debug.h"
|
2002-10-09 12:26:00 +00:00
|
|
|
|
#include "data.h"
|
|
|
|
|
|
|
|
|
|
|
Make definition of off_t robust against misbehaving w32 toolchains.
* configure.ac (NEED__FILE_OFFSET_BITS): Change to define gpgme_off_t
and gpgme_ssize_t.
(API__OFF_T, API__SSIZE_T): New ac_subst.
* src/gpgme.h.in: Replace all ssize_t and off_t by ac_subst macros.
* src/assuan-support.c, src/ath-pthread.c, src/ath.c, src/ath.h
* src/data-compat.c, src/data-fd.c, src/data-mem.c, src/data-stream.c
* src/data-user.c, src/data.c, src/data.h, src/engine-gpgsm.c
* src/engine-uiserver.c, src/gpgme-tool.c, src/gpgme.c: Replace off_t
by gpgme_off_t and sszie_t by gpgme_ssize_t.
* src/ath-pthread.c, src/ath.h: Include gpgme.h.
--
For a detailed description, see the gpgme.texi diff.
2013-04-25 11:00:16 +00:00
|
|
|
|
static gpgme_ssize_t
|
2003-05-18 20:45:24 +00:00
|
|
|
|
user_read (gpgme_data_t dh, void *buffer, size_t size)
|
2002-10-09 12:26:00 +00:00
|
|
|
|
{
|
2005-05-05 12:00:11 +00:00
|
|
|
|
if (!dh->data.user.cbs->read)
|
2007-07-13 14:47:07 +00:00
|
|
|
|
{
|
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Require libgpg-error 1.8.
src/
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* sign.c, data-user.c, conversion.c, debug.c, verify.c, data.c,
decrypt.c, delete.c, assuan-support.c, import.c, engine-gpgsm.c,
data-mem.c, op-support.c, w32-io.c, w32-util.c, data-compat.c: Use
gpg_error_from_syserror instead gpg_error_from_errno, and use
gpg_err_set_errno to set error number.
* setenv.c: Include <gpg-error.h> and define __set_errno to use
gpg_err_set_errno.
* gpgme-tool.c (ARGP_ERR_UNKNOWN): Define to EDEADLOCK (which is
mapped in Windows CE) instead of E2BIG (which is not).
(gt_import_keys): Initialize err.
2010-05-06 13:39:55 +00:00
|
|
|
|
gpg_err_set_errno (EBADF);
|
2007-07-13 14:47:07 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
2005-05-05 12:00:11 +00:00
|
|
|
|
|
2002-10-09 12:26:00 +00:00
|
|
|
|
return (*dh->data.user.cbs->read) (dh->data.user.handle, buffer, size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
Make definition of off_t robust against misbehaving w32 toolchains.
* configure.ac (NEED__FILE_OFFSET_BITS): Change to define gpgme_off_t
and gpgme_ssize_t.
(API__OFF_T, API__SSIZE_T): New ac_subst.
* src/gpgme.h.in: Replace all ssize_t and off_t by ac_subst macros.
* src/assuan-support.c, src/ath-pthread.c, src/ath.c, src/ath.h
* src/data-compat.c, src/data-fd.c, src/data-mem.c, src/data-stream.c
* src/data-user.c, src/data.c, src/data.h, src/engine-gpgsm.c
* src/engine-uiserver.c, src/gpgme-tool.c, src/gpgme.c: Replace off_t
by gpgme_off_t and sszie_t by gpgme_ssize_t.
* src/ath-pthread.c, src/ath.h: Include gpgme.h.
--
For a detailed description, see the gpgme.texi diff.
2013-04-25 11:00:16 +00:00
|
|
|
|
static gpgme_ssize_t
|
2003-05-18 20:45:24 +00:00
|
|
|
|
user_write (gpgme_data_t dh, const void *buffer, size_t size)
|
2002-10-09 12:26:00 +00:00
|
|
|
|
{
|
2005-05-05 12:00:11 +00:00
|
|
|
|
if (!dh->data.user.cbs->write)
|
2007-07-13 14:47:07 +00:00
|
|
|
|
{
|
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Require libgpg-error 1.8.
src/
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* sign.c, data-user.c, conversion.c, debug.c, verify.c, data.c,
decrypt.c, delete.c, assuan-support.c, import.c, engine-gpgsm.c,
data-mem.c, op-support.c, w32-io.c, w32-util.c, data-compat.c: Use
gpg_error_from_syserror instead gpg_error_from_errno, and use
gpg_err_set_errno to set error number.
* setenv.c: Include <gpg-error.h> and define __set_errno to use
gpg_err_set_errno.
* gpgme-tool.c (ARGP_ERR_UNKNOWN): Define to EDEADLOCK (which is
mapped in Windows CE) instead of E2BIG (which is not).
(gt_import_keys): Initialize err.
2010-05-06 13:39:55 +00:00
|
|
|
|
gpg_err_set_errno (EBADF);
|
2007-07-13 14:47:07 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
2005-05-05 12:00:11 +00:00
|
|
|
|
|
2002-10-09 12:26:00 +00:00
|
|
|
|
return (*dh->data.user.cbs->write) (dh->data.user.handle, buffer, size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
Make definition of off_t robust against misbehaving w32 toolchains.
* configure.ac (NEED__FILE_OFFSET_BITS): Change to define gpgme_off_t
and gpgme_ssize_t.
(API__OFF_T, API__SSIZE_T): New ac_subst.
* src/gpgme.h.in: Replace all ssize_t and off_t by ac_subst macros.
* src/assuan-support.c, src/ath-pthread.c, src/ath.c, src/ath.h
* src/data-compat.c, src/data-fd.c, src/data-mem.c, src/data-stream.c
* src/data-user.c, src/data.c, src/data.h, src/engine-gpgsm.c
* src/engine-uiserver.c, src/gpgme-tool.c, src/gpgme.c: Replace off_t
by gpgme_off_t and sszie_t by gpgme_ssize_t.
* src/ath-pthread.c, src/ath.h: Include gpgme.h.
--
For a detailed description, see the gpgme.texi diff.
2013-04-25 11:00:16 +00:00
|
|
|
|
static gpgme_off_t
|
|
|
|
|
user_seek (gpgme_data_t dh, gpgme_off_t offset, int whence)
|
2002-10-09 12:26:00 +00:00
|
|
|
|
{
|
2005-05-05 12:00:11 +00:00
|
|
|
|
if (!dh->data.user.cbs->seek)
|
2007-07-13 14:47:07 +00:00
|
|
|
|
{
|
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Require libgpg-error 1.8.
src/
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* sign.c, data-user.c, conversion.c, debug.c, verify.c, data.c,
decrypt.c, delete.c, assuan-support.c, import.c, engine-gpgsm.c,
data-mem.c, op-support.c, w32-io.c, w32-util.c, data-compat.c: Use
gpg_error_from_syserror instead gpg_error_from_errno, and use
gpg_err_set_errno to set error number.
* setenv.c: Include <gpg-error.h> and define __set_errno to use
gpg_err_set_errno.
* gpgme-tool.c (ARGP_ERR_UNKNOWN): Define to EDEADLOCK (which is
mapped in Windows CE) instead of E2BIG (which is not).
(gt_import_keys): Initialize err.
2010-05-06 13:39:55 +00:00
|
|
|
|
gpg_err_set_errno (EBADF);
|
2007-07-13 14:47:07 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
2005-05-05 12:00:11 +00:00
|
|
|
|
|
2002-10-09 12:26:00 +00:00
|
|
|
|
return (*dh->data.user.cbs->seek) (dh->data.user.handle, offset, whence);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-12-06 22:06:25 +00:00
|
|
|
|
static void
|
2003-05-18 20:45:24 +00:00
|
|
|
|
user_release (gpgme_data_t dh)
|
2002-10-09 12:26:00 +00:00
|
|
|
|
{
|
2005-05-05 12:00:11 +00:00
|
|
|
|
if (dh->data.user.cbs->release)
|
|
|
|
|
(*dh->data.user.cbs->release) (dh->data.user.handle);
|
2002-10-09 12:26:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-18 20:45:24 +00:00
|
|
|
|
static struct _gpgme_data_cbs user_cbs =
|
2002-10-09 12:26:00 +00:00
|
|
|
|
{
|
|
|
|
|
user_read,
|
|
|
|
|
user_write,
|
|
|
|
|
user_seek,
|
2007-01-18 17:59:26 +00:00
|
|
|
|
user_release,
|
|
|
|
|
NULL
|
2002-10-09 12:26:00 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2003-05-18 20:45:24 +00:00
|
|
|
|
gpgme_error_t
|
2009-10-26 17:38:39 +00:00
|
|
|
|
gpgme_data_new_from_cbs (gpgme_data_t *r_dh, gpgme_data_cbs_t cbs, void *handle)
|
2002-10-09 12:26:00 +00:00
|
|
|
|
{
|
2009-10-26 17:38:39 +00:00
|
|
|
|
gpgme_error_t err;
|
2018-11-16 15:25:49 +00:00
|
|
|
|
TRACE_BEG (DEBUG_DATA, "gpgme_data_new_from_cbs", r_dh, "handle=%p", handle);
|
2009-10-26 17:38:39 +00:00
|
|
|
|
|
|
|
|
|
err = _gpgme_data_new (r_dh, &user_cbs);
|
2002-10-09 12:26:00 +00:00
|
|
|
|
if (err)
|
2009-10-26 17:38:39 +00:00
|
|
|
|
return TRACE_ERR (err);
|
2002-10-09 12:26:00 +00:00
|
|
|
|
|
2009-10-26 17:38:39 +00:00
|
|
|
|
(*r_dh)->data.user.cbs = cbs;
|
|
|
|
|
(*r_dh)->data.user.handle = handle;
|
2018-11-16 17:17:22 +00:00
|
|
|
|
TRACE_SUC ("dh=%p", *r_dh);
|
|
|
|
|
return 0;
|
2002-10-09 12:26:00 +00:00
|
|
|
|
}
|