2002-10-09 12:26:00 +00:00
|
|
|
|
/* data-mem.c - A memory based data object.
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
Copyright (C) 2002, 2003, 2004, 2007 g10 Code GmbH
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2002-12-06 22:06:25 +00:00
|
|
|
|
This file is part of GPGME.
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2002-12-06 22:06:25 +00:00
|
|
|
|
GPGME is free software; you can redistribute it and/or modify it
|
2004-12-07 Marcus Brinkmann <marcus@g10code.de>
* README: Refer to COPYING.LESSER and "each file" instead of
COPYING.
* COPYING.LESSER: New file.
* gpgme.spec.in (%doc): Add COPYING.LESSER.
* acinclude.m4, configure.ac, Makefile.am: Change license to LGPL
2.1 or later.
* TODO: Add copyright notice.
* README.CVS: Likewise.
assuan/
2004-12-07 Marcus Brinkmann <marcus@g10code.de>
* README.1st: Add copyright notice.
doc/
2004-12-07 Marcus Brinkmann <marcus@g10code.de>
* Makefile.am: Change license to LGPL.
(gpgme_TEXINFOS): Replace gpl.texi with lesser.texi.
* gpgme.texi: Change license to LGPL (also for documentation of
GPGME's license).
* lesser.texi: New file.
* gpl.texi: File removed.
gpgme/
2004-12-07 Marcus Brinkmann <marcus@g10code.de>
* putc_unlocked.c, funopen.c: I just claim copyright on these
files and change their license to LGPL, because they are totally
trivial wrapper functions.
* isascii.c: Change copyright notice to the one from ctype/ctype.h
in the GNU C Library (CVS Head 2004-10-10), where isascii is
defined as a macro doing exactly the same as the function in this
file.
* memrchr.c: Update from the GNU C Library (CVS Head 2001-07-06).
* stpcpy.c: Update from the GNU C Library (CVS Head 2004-10-10).
* ath.c, ath-compat.c, ath.h, ath-pth.c, ath-pth-compat.c,
ath-pthread.c, ath-pthread-compat.c, context.h, conversion.c,
data.c, data-compat.c, data-fd.c, data.h, data-mem.c,
data-stream.c, data-user.c, debug.c, debug.h, decrypt.c,
decrypt-verify.c, delete.c, edit.c, encrypt.c, encrypt-sign.c,
engine-backend.h, engine.c, engine-gpgsm.c, engine.h, error.c,
export.c, genkey.c, get-env.c, gpgme.c, gpgme.h, import.c, io.h,
key.c, keylist.c, mkstatus, Makefile.am, ops.h, op-support.c,
passphrase.c, posix-io.c, posix-sema.c, posix-util.c, progress.c,
rungpg.c, sema.h, sign.c, signers.c, trust-item.c, trustlist.c,
util.h, verify.c, version.c, w32-io.c, w32-sema.c, w32-util.c,
wait.c, wait-global.c, wait.h, wait-private.c, wait-user.c: Change
license to LGPL.
tests/
2004-12-07 Marcus Brinkmann <marcus@g10code.de>
* gpg/mkdemodirs: Add copyright notice.
* gpgsm/Makefile.am, gpgsm/t-support.h, gpgsm/t-decrypt.c,
gpgsm/t-encrypt.c, gpgsm/t-export.c, gpgsm/t-genkey.c,
gpgsm/t-import.c, gpgsm/t-keylist.c, gpgsm/t-sign.c,
gpgsm/t-verify.c, gpg/Makefile.am, gpg/t-decrypt.c,
gpg/t-decrypt-verify.c, gpg/t-edit.c, gpg/t-encrypt.c,
gpg/t-encrypt-sign.c, gpg/t-encrypt-sym.c, gpg/t-eventloop.c,
gpg/t-export.c, gpg/t-genkey.c, gpg/t-import.c, gpg/t-keylist.c,
gpg/t-keylist-sig.c, gpg/t-sign.c, gpg/t-signers.c,
gpg/t-support.h, gpg/t-thread1.c, gpg/t-trustlist.c,
gpg/t-verify.c, Makefile.am, t-data.c, t-engine-info.c,
t-version.c: Change license to LGPL.
2004-12-07 21:13:39 +00:00
|
|
|
|
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.
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2002-12-06 22:06:25 +00:00
|
|
|
|
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
|
2004-12-07 Marcus Brinkmann <marcus@g10code.de>
* README: Refer to COPYING.LESSER and "each file" instead of
COPYING.
* COPYING.LESSER: New file.
* gpgme.spec.in (%doc): Add COPYING.LESSER.
* acinclude.m4, configure.ac, Makefile.am: Change license to LGPL
2.1 or later.
* TODO: Add copyright notice.
* README.CVS: Likewise.
assuan/
2004-12-07 Marcus Brinkmann <marcus@g10code.de>
* README.1st: Add copyright notice.
doc/
2004-12-07 Marcus Brinkmann <marcus@g10code.de>
* Makefile.am: Change license to LGPL.
(gpgme_TEXINFOS): Replace gpl.texi with lesser.texi.
* gpgme.texi: Change license to LGPL (also for documentation of
GPGME's license).
* lesser.texi: New file.
* gpl.texi: File removed.
gpgme/
2004-12-07 Marcus Brinkmann <marcus@g10code.de>
* putc_unlocked.c, funopen.c: I just claim copyright on these
files and change their license to LGPL, because they are totally
trivial wrapper functions.
* isascii.c: Change copyright notice to the one from ctype/ctype.h
in the GNU C Library (CVS Head 2004-10-10), where isascii is
defined as a macro doing exactly the same as the function in this
file.
* memrchr.c: Update from the GNU C Library (CVS Head 2001-07-06).
* stpcpy.c: Update from the GNU C Library (CVS Head 2004-10-10).
* ath.c, ath-compat.c, ath.h, ath-pth.c, ath-pth-compat.c,
ath-pthread.c, ath-pthread-compat.c, context.h, conversion.c,
data.c, data-compat.c, data-fd.c, data.h, data-mem.c,
data-stream.c, data-user.c, debug.c, debug.h, decrypt.c,
decrypt-verify.c, delete.c, edit.c, encrypt.c, encrypt-sign.c,
engine-backend.h, engine.c, engine-gpgsm.c, engine.h, error.c,
export.c, genkey.c, get-env.c, gpgme.c, gpgme.h, import.c, io.h,
key.c, keylist.c, mkstatus, Makefile.am, ops.h, op-support.c,
passphrase.c, posix-io.c, posix-sema.c, posix-util.c, progress.c,
rungpg.c, sema.h, sign.c, signers.c, trust-item.c, trustlist.c,
util.h, verify.c, version.c, w32-io.c, w32-sema.c, w32-util.c,
wait.c, wait-global.c, wait.h, wait-private.c, wait-user.c: Change
license to LGPL.
tests/
2004-12-07 Marcus Brinkmann <marcus@g10code.de>
* gpg/mkdemodirs: Add copyright notice.
* gpgsm/Makefile.am, gpgsm/t-support.h, gpgsm/t-decrypt.c,
gpgsm/t-encrypt.c, gpgsm/t-export.c, gpgsm/t-genkey.c,
gpgsm/t-import.c, gpgsm/t-keylist.c, gpgsm/t-sign.c,
gpgsm/t-verify.c, gpg/Makefile.am, gpg/t-decrypt.c,
gpg/t-decrypt-verify.c, gpg/t-edit.c, gpg/t-encrypt.c,
gpg/t-encrypt-sign.c, gpg/t-encrypt-sym.c, gpg/t-eventloop.c,
gpg/t-export.c, gpg/t-genkey.c, gpg/t-import.c, gpg/t-keylist.c,
gpg/t-keylist-sig.c, gpg/t-sign.c, gpg/t-signers.c,
gpg/t-support.h, gpg/t-thread1.c, gpg/t-trustlist.c,
gpg/t-verify.c, Makefile.am, t-data.c, t-engine-info.c,
t-version.c: Change license to LGPL.
2004-12-07 21:13:39 +00:00
|
|
|
|
Lesser General Public License for more details.
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2004-12-07 Marcus Brinkmann <marcus@g10code.de>
* README: Refer to COPYING.LESSER and "each file" instead of
COPYING.
* COPYING.LESSER: New file.
* gpgme.spec.in (%doc): Add COPYING.LESSER.
* acinclude.m4, configure.ac, Makefile.am: Change license to LGPL
2.1 or later.
* TODO: Add copyright notice.
* README.CVS: Likewise.
assuan/
2004-12-07 Marcus Brinkmann <marcus@g10code.de>
* README.1st: Add copyright notice.
doc/
2004-12-07 Marcus Brinkmann <marcus@g10code.de>
* Makefile.am: Change license to LGPL.
(gpgme_TEXINFOS): Replace gpl.texi with lesser.texi.
* gpgme.texi: Change license to LGPL (also for documentation of
GPGME's license).
* lesser.texi: New file.
* gpl.texi: File removed.
gpgme/
2004-12-07 Marcus Brinkmann <marcus@g10code.de>
* putc_unlocked.c, funopen.c: I just claim copyright on these
files and change their license to LGPL, because they are totally
trivial wrapper functions.
* isascii.c: Change copyright notice to the one from ctype/ctype.h
in the GNU C Library (CVS Head 2004-10-10), where isascii is
defined as a macro doing exactly the same as the function in this
file.
* memrchr.c: Update from the GNU C Library (CVS Head 2001-07-06).
* stpcpy.c: Update from the GNU C Library (CVS Head 2004-10-10).
* ath.c, ath-compat.c, ath.h, ath-pth.c, ath-pth-compat.c,
ath-pthread.c, ath-pthread-compat.c, context.h, conversion.c,
data.c, data-compat.c, data-fd.c, data.h, data-mem.c,
data-stream.c, data-user.c, debug.c, debug.h, decrypt.c,
decrypt-verify.c, delete.c, edit.c, encrypt.c, encrypt-sign.c,
engine-backend.h, engine.c, engine-gpgsm.c, engine.h, error.c,
export.c, genkey.c, get-env.c, gpgme.c, gpgme.h, import.c, io.h,
key.c, keylist.c, mkstatus, Makefile.am, ops.h, op-support.c,
passphrase.c, posix-io.c, posix-sema.c, posix-util.c, progress.c,
rungpg.c, sema.h, sign.c, signers.c, trust-item.c, trustlist.c,
util.h, verify.c, version.c, w32-io.c, w32-sema.c, w32-util.c,
wait.c, wait-global.c, wait.h, wait-private.c, wait-user.c: Change
license to LGPL.
tests/
2004-12-07 Marcus Brinkmann <marcus@g10code.de>
* gpg/mkdemodirs: Add copyright notice.
* gpgsm/Makefile.am, gpgsm/t-support.h, gpgsm/t-decrypt.c,
gpgsm/t-encrypt.c, gpgsm/t-export.c, gpgsm/t-genkey.c,
gpgsm/t-import.c, gpgsm/t-keylist.c, gpgsm/t-sign.c,
gpgsm/t-verify.c, gpg/Makefile.am, gpg/t-decrypt.c,
gpg/t-decrypt-verify.c, gpg/t-edit.c, gpg/t-encrypt.c,
gpg/t-encrypt-sign.c, gpg/t-encrypt-sym.c, gpg/t-eventloop.c,
gpg/t-export.c, gpg/t-genkey.c, gpg/t-import.c, gpg/t-keylist.c,
gpg/t-keylist-sig.c, gpg/t-sign.c, gpg/t-signers.c,
gpg/t-support.h, gpg/t-thread1.c, gpg/t-trustlist.c,
gpg/t-verify.c, Makefile.am, t-data.c, t-engine-info.c,
t-version.c: Change license to LGPL.
2004-12-07 21:13:39 +00:00
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
License along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
|
02111-1307, USA. */
|
2002-10-09 12:26:00 +00:00
|
|
|
|
|
|
|
|
|
#if HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <stdlib.h>
|
2010-11-02 16:27:46 +00:00
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
|
# include <unistd.h>
|
|
|
|
|
#endif
|
2002-10-09 12:26:00 +00:00
|
|
|
|
#include <assert.h>
|
2003-01-06 14:07:56 +00:00
|
|
|
|
#include <string.h>
|
2002-10-09 12:26:00 +00:00
|
|
|
|
|
|
|
|
|
#include "data.h"
|
|
|
|
|
#include "util.h"
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
#include "debug.h"
|
2002-10-09 12:26:00 +00:00
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
mem_read (gpgme_data_t dh, void *buffer, size_t size)
|
2002-10-09 12:26:00 +00:00
|
|
|
|
{
|
|
|
|
|
size_t amt = dh->data.mem.length - dh->data.mem.offset;
|
|
|
|
|
const char *src;
|
|
|
|
|
|
|
|
|
|
if (!amt)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (size < amt)
|
|
|
|
|
amt = size;
|
|
|
|
|
|
|
|
|
|
src = dh->data.mem.buffer ? dh->data.mem.buffer : dh->data.mem.orig_buffer;
|
|
|
|
|
memcpy (buffer, src + dh->data.mem.offset, amt);
|
|
|
|
|
dh->data.mem.offset += amt;
|
|
|
|
|
return amt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
mem_write (gpgme_data_t dh, const void *buffer, size_t size)
|
2002-10-09 12:26:00 +00:00
|
|
|
|
{
|
|
|
|
|
size_t unused;
|
|
|
|
|
|
|
|
|
|
if (!dh->data.mem.buffer && dh->data.mem.orig_buffer)
|
|
|
|
|
{
|
|
|
|
|
size_t new_size = dh->data.mem.size;
|
|
|
|
|
char *new_buffer;
|
|
|
|
|
|
|
|
|
|
if (new_size < dh->data.mem.offset + size)
|
|
|
|
|
new_size = dh->data.mem.offset + size;
|
|
|
|
|
|
|
|
|
|
new_buffer = malloc (new_size);
|
|
|
|
|
if (!new_buffer)
|
|
|
|
|
return -1;
|
2003-06-22 20:56:48 +00:00
|
|
|
|
memcpy (new_buffer, dh->data.mem.orig_buffer, dh->data.mem.length);
|
|
|
|
|
|
2012-09-25 13:29:49 +00:00
|
|
|
|
dh->data.mem.buffer = new_buffer;
|
2002-10-09 12:26:00 +00:00
|
|
|
|
dh->data.mem.size = new_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unused = dh->data.mem.size - dh->data.mem.offset;
|
|
|
|
|
if (unused < size)
|
|
|
|
|
{
|
|
|
|
|
/* Allocate a large enough buffer with exponential backoff. */
|
|
|
|
|
#define INITIAL_ALLOC 512
|
|
|
|
|
size_t new_size = dh->data.mem.size
|
|
|
|
|
? (2 * dh->data.mem.size) : INITIAL_ALLOC;
|
|
|
|
|
char *new_buffer;
|
|
|
|
|
|
|
|
|
|
if (new_size < dh->data.mem.offset + size)
|
|
|
|
|
new_size = dh->data.mem.offset + size;
|
|
|
|
|
|
|
|
|
|
new_buffer = realloc (dh->data.mem.buffer, new_size);
|
|
|
|
|
if (!new_buffer && new_size > dh->data.mem.offset + size)
|
|
|
|
|
{
|
|
|
|
|
/* Maybe we were too greedy, try again. */
|
|
|
|
|
new_size = dh->data.mem.offset + size;
|
|
|
|
|
new_buffer = realloc (dh->data.mem.buffer, new_size);
|
|
|
|
|
}
|
|
|
|
|
if (!new_buffer)
|
|
|
|
|
return -1;
|
|
|
|
|
dh->data.mem.buffer = new_buffer;
|
|
|
|
|
dh->data.mem.size = new_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memcpy (dh->data.mem.buffer + dh->data.mem.offset, buffer, size);
|
|
|
|
|
dh->data.mem.offset += size;
|
|
|
|
|
if (dh->data.mem.length < dh->data.mem.offset)
|
|
|
|
|
dh->data.mem.length = dh->data.mem.offset;
|
|
|
|
|
return 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
|
|
|
|
|
mem_seek (gpgme_data_t dh, gpgme_off_t offset, int whence)
|
2002-10-09 12:26:00 +00:00
|
|
|
|
{
|
|
|
|
|
switch (whence)
|
|
|
|
|
{
|
|
|
|
|
case SEEK_SET:
|
|
|
|
|
if (offset < 0 || offset > dh->data.mem.length)
|
|
|
|
|
{
|
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 (EINVAL);
|
2002-10-09 12:26:00 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
dh->data.mem.offset = offset;
|
|
|
|
|
break;
|
|
|
|
|
case SEEK_CUR:
|
|
|
|
|
if ((offset > 0 && dh->data.mem.length - dh->data.mem.offset < offset)
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|| (offset < 0 && dh->data.mem.offset < -offset))
|
2002-10-09 12:26:00 +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 (EINVAL);
|
2002-10-09 12:26:00 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
dh->data.mem.offset += offset;
|
|
|
|
|
break;
|
|
|
|
|
case SEEK_END:
|
|
|
|
|
if (offset > 0 || -offset > dh->data.mem.length)
|
|
|
|
|
{
|
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 (EINVAL);
|
2002-10-09 12:26:00 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
2012-07-28 20:06:09 +00:00
|
|
|
|
dh->data.mem.offset = dh->data.mem.length + offset;
|
2002-10-09 12:26:00 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
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 (EINVAL);
|
2002-10-09 12:26:00 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return dh->data.mem.offset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-12-06 22:06:25 +00:00
|
|
|
|
static void
|
2003-05-18 20:45:24 +00:00
|
|
|
|
mem_release (gpgme_data_t dh)
|
2002-10-09 12:26:00 +00:00
|
|
|
|
{
|
|
|
|
|
if (dh->data.mem.buffer)
|
|
|
|
|
free (dh->data.mem.buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-18 20:45:24 +00:00
|
|
|
|
static struct _gpgme_data_cbs mem_cbs =
|
2002-10-09 12:26:00 +00:00
|
|
|
|
{
|
|
|
|
|
mem_read,
|
|
|
|
|
mem_write,
|
|
|
|
|
mem_seek,
|
2007-01-18 17:59:26 +00:00
|
|
|
|
mem_release,
|
|
|
|
|
NULL
|
2002-10-09 12:26:00 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2005-10-06 10:44:26 +00:00
|
|
|
|
/* Create a new data buffer and return it in R_DH. */
|
2003-05-18 20:45:24 +00:00
|
|
|
|
gpgme_error_t
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
gpgme_data_new (gpgme_data_t *r_dh)
|
2002-10-09 12:26:00 +00:00
|
|
|
|
{
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
gpgme_error_t err;
|
|
|
|
|
TRACE_BEG (DEBUG_DATA, "gpgme_data_new", r_dh);
|
|
|
|
|
|
|
|
|
|
err = _gpgme_data_new (r_dh, &mem_cbs);
|
|
|
|
|
|
2002-10-09 12:26:00 +00:00
|
|
|
|
if (err)
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return TRACE_ERR (err);
|
2002-10-09 12:26:00 +00:00
|
|
|
|
|
2009-10-26 17:38:39 +00:00
|
|
|
|
return TRACE_SUC1 ("dh=%p", *r_dh);
|
2002-10-09 12:26:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Create a new data buffer filled with SIZE bytes starting from
|
|
|
|
|
BUFFER. If COPY is zero, copying is delayed until necessary, and
|
|
|
|
|
the data is taken from the original location when needed. */
|
2003-05-18 20:45:24 +00:00
|
|
|
|
gpgme_error_t
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
gpgme_data_new_from_mem (gpgme_data_t *r_dh, const char *buffer,
|
2002-10-09 12:26:00 +00:00
|
|
|
|
size_t size, int copy)
|
|
|
|
|
{
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
gpgme_error_t err;
|
|
|
|
|
TRACE_BEG4 (DEBUG_DATA, "gpgme_data_new_from_mem", r_dh,
|
|
|
|
|
"buffer=%p, size=%u, copy=%i (%s)", buffer, size,
|
|
|
|
|
copy, copy ? "yes" : "no");
|
|
|
|
|
|
|
|
|
|
err = _gpgme_data_new (r_dh, &mem_cbs);
|
2002-10-09 12:26:00 +00:00
|
|
|
|
if (err)
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return TRACE_ERR (err);
|
2002-10-09 12:26:00 +00:00
|
|
|
|
|
|
|
|
|
if (copy)
|
|
|
|
|
{
|
|
|
|
|
char *bufcpy = malloc (size);
|
|
|
|
|
if (!bufcpy)
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
{
|
2013-02-06 16:35:40 +00:00
|
|
|
|
int saved_err = gpg_error_from_syserror ();
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
_gpgme_data_release (*r_dh);
|
2013-02-06 16:35:40 +00:00
|
|
|
|
return TRACE_ERR (saved_err);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
}
|
2002-10-09 12:26:00 +00:00
|
|
|
|
memcpy (bufcpy, buffer, size);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
(*r_dh)->data.mem.buffer = bufcpy;
|
2002-10-09 12:26:00 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
(*r_dh)->data.mem.orig_buffer = buffer;
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
(*r_dh)->data.mem.size = size;
|
|
|
|
|
(*r_dh)->data.mem.length = size;
|
|
|
|
|
return TRACE_SUC1 ("dh=%p", *r_dh);
|
2002-10-09 12:26:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-10-06 10:44:26 +00:00
|
|
|
|
/* Destroy the data buffer DH and return a pointer to its content.
|
|
|
|
|
The memory has be to released with gpgme_free() by the user. It's
|
|
|
|
|
size is returned in R_LEN. */
|
2002-10-09 12:26:00 +00:00
|
|
|
|
char *
|
2003-05-18 20:45:24 +00:00
|
|
|
|
gpgme_data_release_and_get_mem (gpgme_data_t dh, size_t *r_len)
|
2002-10-09 12:26:00 +00:00
|
|
|
|
{
|
|
|
|
|
char *str = NULL;
|
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
TRACE_BEG1 (DEBUG_DATA, "gpgme_data_release_and_get_mem", dh,
|
|
|
|
|
"r_len=%p", r_len);
|
|
|
|
|
|
2002-10-09 12:26:00 +00:00
|
|
|
|
if (!dh || dh->cbs != &mem_cbs)
|
2006-09-25 14:57:00 +00:00
|
|
|
|
{
|
|
|
|
|
gpgme_data_release (dh);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
|
2006-09-25 14:57:00 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2002-10-09 12:26:00 +00:00
|
|
|
|
|
|
|
|
|
str = dh->data.mem.buffer;
|
|
|
|
|
if (!str && dh->data.mem.orig_buffer)
|
|
|
|
|
{
|
|
|
|
|
str = malloc (dh->data.mem.length);
|
|
|
|
|
if (!str)
|
2006-09-25 14:57:00 +00:00
|
|
|
|
{
|
2013-02-06 16:35:40 +00:00
|
|
|
|
int saved_err = gpg_error_from_syserror ();
|
2006-09-25 14:57:00 +00:00
|
|
|
|
gpgme_data_release (dh);
|
2013-02-06 16:35:40 +00:00
|
|
|
|
TRACE_ERR (saved_err);
|
2006-09-25 14:57:00 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2002-10-09 12:26:00 +00:00
|
|
|
|
memcpy (str, dh->data.mem.orig_buffer, dh->data.mem.length);
|
|
|
|
|
}
|
2006-09-25 14:57:00 +00:00
|
|
|
|
else
|
|
|
|
|
/* Prevent mem_release from releasing the buffer memory. We must
|
|
|
|
|
not fail from this point. */
|
|
|
|
|
dh->data.mem.buffer = NULL;
|
2002-10-09 12:26:00 +00:00
|
|
|
|
|
|
|
|
|
if (r_len)
|
|
|
|
|
*r_len = dh->data.mem.length;
|
|
|
|
|
|
2006-09-25 14:57:00 +00:00
|
|
|
|
gpgme_data_release (dh);
|
|
|
|
|
|
2007-09-14 12:27:54 +00:00
|
|
|
|
if (r_len)
|
|
|
|
|
{
|
|
|
|
|
TRACE_SUC2 ("buffer=%p, len=%u", str, *r_len);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
TRACE_SUC1 ("buffer=%p", str);
|
|
|
|
|
}
|
2002-10-09 12:26:00 +00:00
|
|
|
|
return str;
|
|
|
|
|
}
|
2005-10-06 10:44:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Release the memory returned by gpgme_data_release_and_get_mem(). */
|
|
|
|
|
void
|
|
|
|
|
gpgme_free (void *buffer)
|
|
|
|
|
{
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
TRACE (DEBUG_DATA, "gpgme_free", buffer);
|
|
|
|
|
|
2005-10-06 10:44:26 +00:00
|
|
|
|
if (buffer)
|
|
|
|
|
free (buffer);
|
|
|
|
|
}
|