2003-01-29 20:03:24 +00:00
|
|
|
|
/* w32-io.c - W32 API I/O functions.
|
|
|
|
|
Copyright (C) 2000 Werner Koch (dd9jn)
|
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
|
|
|
|
Copyright (C) 2001, 2002, 2003, 2004 g10 Code GmbH
|
2003-01-29 20:03:24 +00:00
|
|
|
|
|
|
|
|
|
This file is part of GPGME.
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
2003-01-29 20:03:24 +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.
|
|
|
|
|
|
|
|
|
|
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. */
|
2000-11-22 17:10:48 +00:00
|
|
|
|
|
2002-03-18 00:04:06 +00:00
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2000-11-22 17:10:48 +00:00
|
|
|
|
#include <config.h>
|
2002-03-18 00:04:06 +00:00
|
|
|
|
#endif
|
2000-11-22 17:10:48 +00:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
#include <fcntl.h>
|
2002-03-18 00:04:06 +00:00
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
#include <sys/types.h>
|
2000-11-22 17:10:48 +00:00
|
|
|
|
#include <windows.h>
|
2002-03-18 00:04:06 +00:00
|
|
|
|
#include <io.h>
|
2000-11-22 17:10:48 +00:00
|
|
|
|
|
2000-11-23 15:28:15 +00:00
|
|
|
|
#include "util.h"
|
2001-01-30 11:01:41 +00:00
|
|
|
|
#include "sema.h"
|
2005-03-24 13:05:12 +00:00
|
|
|
|
#include "priv-io.h"
|
2005-03-09 11:47:21 +00:00
|
|
|
|
#include "debug.h"
|
2000-11-23 15:28:15 +00:00
|
|
|
|
|
2003-05-18 21:08:43 +00:00
|
|
|
|
/* We assume that a HANDLE can be represented by an int which should
|
|
|
|
|
be true for all i386 systems (HANDLE is defined as void *) and
|
|
|
|
|
these are the only systems for which Windows is available. Further
|
|
|
|
|
we assume that -1 denotes an invalid handle. */
|
2000-11-22 17:10:48 +00:00
|
|
|
|
|
|
|
|
|
#define fd_to_handle(a) ((HANDLE)(a))
|
|
|
|
|
#define handle_to_fd(a) ((int)(a))
|
|
|
|
|
#define pid_to_handle(a) ((HANDLE)(a))
|
2000-11-23 15:28:15 +00:00
|
|
|
|
#define handle_to_pid(a) ((int)(a))
|
2000-11-22 17:10:48 +00:00
|
|
|
|
|
2001-01-30 11:01:41 +00:00
|
|
|
|
#define READBUF_SIZE 4096
|
2001-02-28 10:18:38 +00:00
|
|
|
|
#define WRITEBUF_SIZE 4096
|
2005-09-23 13:29:04 +00:00
|
|
|
|
#define PIPEBUF_SIZE 4096
|
2001-02-28 10:18:38 +00:00
|
|
|
|
#define MAX_READERS 20
|
|
|
|
|
#define MAX_WRITERS 20
|
2001-01-30 11:01:41 +00:00
|
|
|
|
|
2001-02-20 13:31:56 +00:00
|
|
|
|
static struct {
|
|
|
|
|
int inuse;
|
|
|
|
|
int fd;
|
|
|
|
|
void (*handler)(int,void*);
|
|
|
|
|
void *value;
|
|
|
|
|
} notify_table[256];
|
|
|
|
|
DEFINE_STATIC_LOCK (notify_table_lock);
|
|
|
|
|
|
|
|
|
|
|
2001-01-30 11:01:41 +00:00
|
|
|
|
struct reader_context_s {
|
|
|
|
|
HANDLE file_hd;
|
|
|
|
|
HANDLE thread_hd;
|
|
|
|
|
DECLARE_LOCK (mutex);
|
2001-02-20 13:31:56 +00:00
|
|
|
|
|
|
|
|
|
int stop_me;
|
2001-01-30 11:01:41 +00:00
|
|
|
|
int eof;
|
2001-01-31 12:39:53 +00:00
|
|
|
|
int eof_shortcut;
|
2001-01-30 11:01:41 +00:00
|
|
|
|
int error;
|
|
|
|
|
int error_code;
|
|
|
|
|
|
|
|
|
|
HANDLE have_data_ev; /* manually reset */
|
|
|
|
|
HANDLE have_space_ev; /* auto reset */
|
2001-02-20 13:31:56 +00:00
|
|
|
|
HANDLE stopped;
|
2001-01-30 11:01:41 +00:00
|
|
|
|
size_t readpos, writepos;
|
|
|
|
|
char buffer[READBUF_SIZE];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
|
volatile int used;
|
|
|
|
|
int fd;
|
|
|
|
|
struct reader_context_s *context;
|
|
|
|
|
} reader_table[MAX_READERS];
|
|
|
|
|
static int reader_table_size= MAX_READERS;
|
|
|
|
|
DEFINE_STATIC_LOCK (reader_table_lock);
|
|
|
|
|
|
2001-02-28 10:18:38 +00:00
|
|
|
|
|
|
|
|
|
struct writer_context_s {
|
|
|
|
|
HANDLE file_hd;
|
|
|
|
|
HANDLE thread_hd;
|
|
|
|
|
DECLARE_LOCK (mutex);
|
|
|
|
|
|
|
|
|
|
int stop_me;
|
|
|
|
|
int error;
|
|
|
|
|
int error_code;
|
|
|
|
|
|
|
|
|
|
HANDLE have_data; /* manually reset */
|
|
|
|
|
HANDLE is_empty;
|
|
|
|
|
HANDLE stopped;
|
|
|
|
|
size_t nbytes;
|
|
|
|
|
char buffer[WRITEBUF_SIZE];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
|
volatile int used;
|
|
|
|
|
int fd;
|
|
|
|
|
struct writer_context_s *context;
|
|
|
|
|
} writer_table[MAX_WRITERS];
|
|
|
|
|
static int writer_table_size= MAX_WRITERS;
|
|
|
|
|
DEFINE_STATIC_LOCK (writer_table_lock);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-01-26 10:23:15 +00:00
|
|
|
|
static int
|
|
|
|
|
get_desired_thread_priority (void)
|
|
|
|
|
{
|
|
|
|
|
int value;
|
|
|
|
|
|
|
|
|
|
if (!_gpgme_get_conf_int ("IOThreadPriority", &value))
|
|
|
|
|
{
|
|
|
|
|
value = THREAD_PRIORITY_HIGHEST;
|
|
|
|
|
DEBUG1 ("** Using standard IOThreadPriority of %d\n", value);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
DEBUG1 ("** Configured IOThreadPriority is %d\n", value);
|
|
|
|
|
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-01-30 11:01:41 +00:00
|
|
|
|
static HANDLE
|
|
|
|
|
set_synchronize (HANDLE h)
|
|
|
|
|
{
|
|
|
|
|
HANDLE tmp;
|
|
|
|
|
|
|
|
|
|
/* For NT we have to set the sync flag. It seems that the only
|
|
|
|
|
* way to do it is by duplicating the handle. Tsss.. */
|
|
|
|
|
if (!DuplicateHandle( GetCurrentProcess(), h,
|
|
|
|
|
GetCurrentProcess(), &tmp,
|
2001-02-01 09:25:56 +00:00
|
|
|
|
EVENT_MODIFY_STATE|SYNCHRONIZE, FALSE, 0 ) ) {
|
2001-01-30 11:01:41 +00:00
|
|
|
|
DEBUG1 ("** Set SYNCRONIZE failed: ec=%d\n", (int)GetLastError());
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
CloseHandle (h);
|
|
|
|
|
h = tmp;
|
|
|
|
|
}
|
|
|
|
|
return h;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static DWORD CALLBACK
|
|
|
|
|
reader (void *arg)
|
|
|
|
|
{
|
|
|
|
|
struct reader_context_s *c = arg;
|
|
|
|
|
int nbytes;
|
|
|
|
|
DWORD nread;
|
|
|
|
|
|
|
|
|
|
DEBUG2 ("reader thread %p for file %p started", c->thread_hd, c->file_hd );
|
|
|
|
|
for (;;) {
|
|
|
|
|
LOCK (c->mutex);
|
2001-02-20 13:31:56 +00:00
|
|
|
|
/* leave a 1 byte gap so that we can see whether it is empty or full*/
|
2001-01-30 11:01:41 +00:00
|
|
|
|
if ((c->writepos + 1) % READBUF_SIZE == c->readpos) {
|
|
|
|
|
/* wait for space */
|
2001-02-01 09:25:56 +00:00
|
|
|
|
if (!ResetEvent (c->have_space_ev) )
|
|
|
|
|
DEBUG1 ("ResetEvent failed: ec=%d", (int)GetLastError ());
|
2001-01-30 11:01:41 +00:00
|
|
|
|
UNLOCK (c->mutex);
|
|
|
|
|
DEBUG1 ("reader thread %p: waiting for space ...", c->thread_hd );
|
|
|
|
|
WaitForSingleObject (c->have_space_ev, INFINITE);
|
|
|
|
|
DEBUG1 ("reader thread %p: got space", c->thread_hd );
|
|
|
|
|
LOCK (c->mutex);
|
|
|
|
|
}
|
2001-02-20 13:31:56 +00:00
|
|
|
|
if ( c->stop_me ) {
|
|
|
|
|
UNLOCK (c->mutex);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2001-01-30 11:01:41 +00:00
|
|
|
|
nbytes = (c->readpos + READBUF_SIZE - c->writepos-1) % READBUF_SIZE;
|
|
|
|
|
if ( nbytes > READBUF_SIZE - c->writepos )
|
|
|
|
|
nbytes = READBUF_SIZE - c->writepos;
|
|
|
|
|
UNLOCK (c->mutex);
|
|
|
|
|
|
|
|
|
|
DEBUG2 ("reader thread %p: reading %d bytes", c->thread_hd, nbytes );
|
|
|
|
|
if ( !ReadFile ( c->file_hd,
|
|
|
|
|
c->buffer+c->writepos, nbytes, &nread, NULL) ) {
|
|
|
|
|
c->error_code = (int)GetLastError ();
|
2001-01-31 12:39:53 +00:00
|
|
|
|
if (c->error_code == ERROR_BROKEN_PIPE ) {
|
|
|
|
|
c->eof=1;
|
|
|
|
|
DEBUG1 ("reader thread %p: got eof (broken pipe)",
|
|
|
|
|
c->thread_hd );
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
c->error = 1;
|
|
|
|
|
DEBUG2 ("reader thread %p: read error: ec=%d",
|
|
|
|
|
c->thread_hd, c->error_code );
|
|
|
|
|
}
|
2001-01-30 11:01:41 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if ( !nread ) {
|
|
|
|
|
c->eof = 1;
|
|
|
|
|
DEBUG1 ("reader thread %p: got eof", c->thread_hd );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
DEBUG2 ("reader thread %p: got %d bytes", c->thread_hd, (int)nread );
|
|
|
|
|
|
|
|
|
|
LOCK (c->mutex);
|
2001-02-20 13:31:56 +00:00
|
|
|
|
if (c->stop_me) {
|
|
|
|
|
UNLOCK (c->mutex);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2001-01-30 11:01:41 +00:00
|
|
|
|
c->writepos = (c->writepos + nread) % READBUF_SIZE;
|
2001-02-01 09:25:56 +00:00
|
|
|
|
if ( !SetEvent (c->have_data_ev) )
|
|
|
|
|
DEBUG1 ("SetEvent failed: ec=%d", (int)GetLastError ());
|
2001-01-30 11:01:41 +00:00
|
|
|
|
UNLOCK (c->mutex);
|
|
|
|
|
}
|
2001-01-31 12:39:53 +00:00
|
|
|
|
/* indicate that we have an error or eof */
|
2001-02-01 09:25:56 +00:00
|
|
|
|
if ( !SetEvent (c->have_data_ev) )
|
|
|
|
|
DEBUG1 ("SetEvent failed: ec=%d", (int)GetLastError ());
|
2001-01-30 11:01:41 +00:00
|
|
|
|
DEBUG1 ("reader thread %p ended", c->thread_hd );
|
2001-02-20 13:31:56 +00:00
|
|
|
|
SetEvent (c->stopped);
|
2001-01-30 11:01:41 +00:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static struct reader_context_s *
|
|
|
|
|
create_reader (HANDLE fd)
|
|
|
|
|
{
|
|
|
|
|
struct reader_context_s *c;
|
|
|
|
|
SECURITY_ATTRIBUTES sec_attr;
|
|
|
|
|
DWORD tid;
|
|
|
|
|
|
|
|
|
|
DEBUG1 ("creating new read thread for file handle %p", fd );
|
|
|
|
|
memset (&sec_attr, 0, sizeof sec_attr );
|
|
|
|
|
sec_attr.nLength = sizeof sec_attr;
|
|
|
|
|
sec_attr.bInheritHandle = FALSE;
|
|
|
|
|
|
2002-10-08 Marcus Brinkmann <marcus@g10code.de>
* util.h (_gpgme_malloc, _gpgme_realloc, _gpgme_calloc,
_gpgme_strdup, _gpgme_free): Remove prototypes.
(xtrymalloc, xtrycalloc, xtryrealloc, xtrystrdup, xfree): Remove
macros.
* util.c: File removed.
* Makefile.am (libgpgme_la_SOURCES): Remove util.h.
* conversion.c (_gpgme_decode_c_string): Use malloc instead of
xtrymalloc, realloc instead of xtryrealloc, calloc instead of
xtrycalloc, free instead of xfree.
(_gpgme_data_append_percentstring_for_xml): Likewise.
* data.c (_gpgme_data_new, _gpgme_data_release): Likewise.
* data-compat.c (gpgme_data_new_from_filepart): Likewise.
* data-mem.c (mem_write, mem_release, gpgme_data_new_from_mem,
_gpgme_data_get_as_string): Likewise.
* debug.c (debug_init): Likewise.
* decrypt.c (_gpgme_release_decrypt_result): Likewise.
* delete.c (_gpgme_release_delete_result): Likewise.
* edit.c (_gpgme_release_edit_result, _gpgme_op_edit_start):
Likewise.
* encrypt.c (_gpgme_release_encrypt_result): Likewise.
* engine.c (_gpgme_engine_get_info, _gpgme_engine_new,
_gpgme_engine_release): Likewise.
* engine-gpgsm.c (_gpgme_gpgsm_new, _gpgme_gpgsm_release,
_gpgme_gpgsm_op_decrypt, _gpgme_gpgsm_op_delete,
gpgsm_set_recipients, _gpgme_gpgsm_op_encrypt,
_gpgme_gpgsm_op_export, _gpgme_gpgsm_op_genkey,
_gpgme_gpgsm_op_import, _gpgme_gpgsm_op_keylist,
_gpgme_gpgsm_op_keylist_ext, _gpgme_gpgsm_op_sign,
_gpgme_gpgsm_op_verify, gpgsm_status_handler): Likewise.
* genkey.c (_gpgme_release_genkey_result): Likewise.
* gpgme.c (gpgme_new, gpgme_release): Likewise.
* import.c (_gpgme_release_import_result): Likewise.
* key.c (_gpgme_key_cache_init, _gpgme_key_cache_add, key_new,
add_subkey, gpgme_key_release, _gpgme_key_append_name): Likewise.
* keylist.c (_gpgme_release_keylist_result, keylist_colon_handler,
_gpgme_op_keylist_event_cb, gpgme_op_keylist_next): Likewise.
* ops.h (test_and_allocate_result): Likewise.
* passphrase.c (_gpgme_release_passphrase_result,
_gpgme_passphrase_status_handler,
_gpgme_passphrase_command_handler): Likewise.
* progress.c (_gpgme_progress_status_handler): Likewise.
* recipient.c (gpgme_recipients_new, gpgme_recipients_release,
gpgme_recipients_add_name_with_validity): Likewise.
* rungpg.c (_gpgme_gpg_new, _gpgme_gpg_release,
_gpgme_gpg_add_arg, _gpgme_gpg_add_data,
_gpgme_gpg_set_colon_line_handler, free_argv, free_fd_data_map,
build_argv, _gpgme_gpg_spawn, read_status, read_colon_line):
Likewise.
* sign.c (_gpgme_release_sign_result): Likewise.
* signers.c (_gpgme_signers_add): Likewise.
* trustlist.c (trust_item_new, trustlist_colon_handler,
_gpgme_op_trustlist_event_cb, gpgme_op_trustlist_next,
gpgme_trustitem_release): Likewise.
* verify.c (_gpgme_release_verify_result, finish_sig): Likewise.
* version.c (gpgme_get_engine_info, _gpgme_get_program_version):
Likewise.
* w32-io.c (create_reader, create_writer, destroy_reader,
destroy_writer, build_commandline, _gpgme_io_spawn): Likewise.
* w32-sema.c (critsect_init, _gpgme_sema_cs_destroy): Likewise.
* w32-util.c (read_w32_registry_string): Likewise.
* wait.c (_gpgme_fd_table_deinit, _gpgme_fd_table_put,
_gpgme_wait_event_cb, _gpgme_add_io_cb, _gpgme_remove_io_cb)
* data-compat.c: Include <stdlib.h>.
2002-10-09 01:08:21 +00:00
|
|
|
|
c = calloc (1, sizeof *c );
|
2001-01-30 11:01:41 +00:00
|
|
|
|
if (!c)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
c->file_hd = fd;
|
|
|
|
|
c->have_data_ev = CreateEvent (&sec_attr, TRUE, FALSE, NULL);
|
|
|
|
|
c->have_space_ev = CreateEvent (&sec_attr, FALSE, TRUE, NULL);
|
2001-02-20 13:31:56 +00:00
|
|
|
|
c->stopped = CreateEvent (&sec_attr, TRUE, FALSE, NULL);
|
|
|
|
|
if (!c->have_data_ev || !c->have_space_ev || !c->stopped ) {
|
2001-01-30 11:01:41 +00:00
|
|
|
|
DEBUG1 ("** CreateEvent failed: ec=%d\n", (int)GetLastError ());
|
|
|
|
|
if (c->have_data_ev)
|
|
|
|
|
CloseHandle (c->have_data_ev);
|
|
|
|
|
if (c->have_space_ev)
|
|
|
|
|
CloseHandle (c->have_space_ev);
|
2001-02-20 13:31:56 +00:00
|
|
|
|
if (c->stopped)
|
|
|
|
|
CloseHandle (c->stopped);
|
2002-10-08 Marcus Brinkmann <marcus@g10code.de>
* util.h (_gpgme_malloc, _gpgme_realloc, _gpgme_calloc,
_gpgme_strdup, _gpgme_free): Remove prototypes.
(xtrymalloc, xtrycalloc, xtryrealloc, xtrystrdup, xfree): Remove
macros.
* util.c: File removed.
* Makefile.am (libgpgme_la_SOURCES): Remove util.h.
* conversion.c (_gpgme_decode_c_string): Use malloc instead of
xtrymalloc, realloc instead of xtryrealloc, calloc instead of
xtrycalloc, free instead of xfree.
(_gpgme_data_append_percentstring_for_xml): Likewise.
* data.c (_gpgme_data_new, _gpgme_data_release): Likewise.
* data-compat.c (gpgme_data_new_from_filepart): Likewise.
* data-mem.c (mem_write, mem_release, gpgme_data_new_from_mem,
_gpgme_data_get_as_string): Likewise.
* debug.c (debug_init): Likewise.
* decrypt.c (_gpgme_release_decrypt_result): Likewise.
* delete.c (_gpgme_release_delete_result): Likewise.
* edit.c (_gpgme_release_edit_result, _gpgme_op_edit_start):
Likewise.
* encrypt.c (_gpgme_release_encrypt_result): Likewise.
* engine.c (_gpgme_engine_get_info, _gpgme_engine_new,
_gpgme_engine_release): Likewise.
* engine-gpgsm.c (_gpgme_gpgsm_new, _gpgme_gpgsm_release,
_gpgme_gpgsm_op_decrypt, _gpgme_gpgsm_op_delete,
gpgsm_set_recipients, _gpgme_gpgsm_op_encrypt,
_gpgme_gpgsm_op_export, _gpgme_gpgsm_op_genkey,
_gpgme_gpgsm_op_import, _gpgme_gpgsm_op_keylist,
_gpgme_gpgsm_op_keylist_ext, _gpgme_gpgsm_op_sign,
_gpgme_gpgsm_op_verify, gpgsm_status_handler): Likewise.
* genkey.c (_gpgme_release_genkey_result): Likewise.
* gpgme.c (gpgme_new, gpgme_release): Likewise.
* import.c (_gpgme_release_import_result): Likewise.
* key.c (_gpgme_key_cache_init, _gpgme_key_cache_add, key_new,
add_subkey, gpgme_key_release, _gpgme_key_append_name): Likewise.
* keylist.c (_gpgme_release_keylist_result, keylist_colon_handler,
_gpgme_op_keylist_event_cb, gpgme_op_keylist_next): Likewise.
* ops.h (test_and_allocate_result): Likewise.
* passphrase.c (_gpgme_release_passphrase_result,
_gpgme_passphrase_status_handler,
_gpgme_passphrase_command_handler): Likewise.
* progress.c (_gpgme_progress_status_handler): Likewise.
* recipient.c (gpgme_recipients_new, gpgme_recipients_release,
gpgme_recipients_add_name_with_validity): Likewise.
* rungpg.c (_gpgme_gpg_new, _gpgme_gpg_release,
_gpgme_gpg_add_arg, _gpgme_gpg_add_data,
_gpgme_gpg_set_colon_line_handler, free_argv, free_fd_data_map,
build_argv, _gpgme_gpg_spawn, read_status, read_colon_line):
Likewise.
* sign.c (_gpgme_release_sign_result): Likewise.
* signers.c (_gpgme_signers_add): Likewise.
* trustlist.c (trust_item_new, trustlist_colon_handler,
_gpgme_op_trustlist_event_cb, gpgme_op_trustlist_next,
gpgme_trustitem_release): Likewise.
* verify.c (_gpgme_release_verify_result, finish_sig): Likewise.
* version.c (gpgme_get_engine_info, _gpgme_get_program_version):
Likewise.
* w32-io.c (create_reader, create_writer, destroy_reader,
destroy_writer, build_commandline, _gpgme_io_spawn): Likewise.
* w32-sema.c (critsect_init, _gpgme_sema_cs_destroy): Likewise.
* w32-util.c (read_w32_registry_string): Likewise.
* wait.c (_gpgme_fd_table_deinit, _gpgme_fd_table_put,
_gpgme_wait_event_cb, _gpgme_add_io_cb, _gpgme_remove_io_cb)
* data-compat.c: Include <stdlib.h>.
2002-10-09 01:08:21 +00:00
|
|
|
|
free (c);
|
2001-01-30 11:01:41 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c->have_data_ev = set_synchronize (c->have_data_ev);
|
|
|
|
|
INIT_LOCK (c->mutex);
|
|
|
|
|
|
|
|
|
|
c->thread_hd = CreateThread (&sec_attr, 0, reader, c, 0, &tid );
|
|
|
|
|
if (!c->thread_hd) {
|
|
|
|
|
DEBUG1 ("** failed to create reader thread: ec=%d\n",
|
|
|
|
|
(int)GetLastError ());
|
|
|
|
|
DESTROY_LOCK (c->mutex);
|
|
|
|
|
if (c->have_data_ev)
|
|
|
|
|
CloseHandle (c->have_data_ev);
|
|
|
|
|
if (c->have_space_ev)
|
|
|
|
|
CloseHandle (c->have_space_ev);
|
2001-02-20 13:31:56 +00:00
|
|
|
|
if (c->stopped)
|
|
|
|
|
CloseHandle (c->stopped);
|
2002-10-08 Marcus Brinkmann <marcus@g10code.de>
* util.h (_gpgme_malloc, _gpgme_realloc, _gpgme_calloc,
_gpgme_strdup, _gpgme_free): Remove prototypes.
(xtrymalloc, xtrycalloc, xtryrealloc, xtrystrdup, xfree): Remove
macros.
* util.c: File removed.
* Makefile.am (libgpgme_la_SOURCES): Remove util.h.
* conversion.c (_gpgme_decode_c_string): Use malloc instead of
xtrymalloc, realloc instead of xtryrealloc, calloc instead of
xtrycalloc, free instead of xfree.
(_gpgme_data_append_percentstring_for_xml): Likewise.
* data.c (_gpgme_data_new, _gpgme_data_release): Likewise.
* data-compat.c (gpgme_data_new_from_filepart): Likewise.
* data-mem.c (mem_write, mem_release, gpgme_data_new_from_mem,
_gpgme_data_get_as_string): Likewise.
* debug.c (debug_init): Likewise.
* decrypt.c (_gpgme_release_decrypt_result): Likewise.
* delete.c (_gpgme_release_delete_result): Likewise.
* edit.c (_gpgme_release_edit_result, _gpgme_op_edit_start):
Likewise.
* encrypt.c (_gpgme_release_encrypt_result): Likewise.
* engine.c (_gpgme_engine_get_info, _gpgme_engine_new,
_gpgme_engine_release): Likewise.
* engine-gpgsm.c (_gpgme_gpgsm_new, _gpgme_gpgsm_release,
_gpgme_gpgsm_op_decrypt, _gpgme_gpgsm_op_delete,
gpgsm_set_recipients, _gpgme_gpgsm_op_encrypt,
_gpgme_gpgsm_op_export, _gpgme_gpgsm_op_genkey,
_gpgme_gpgsm_op_import, _gpgme_gpgsm_op_keylist,
_gpgme_gpgsm_op_keylist_ext, _gpgme_gpgsm_op_sign,
_gpgme_gpgsm_op_verify, gpgsm_status_handler): Likewise.
* genkey.c (_gpgme_release_genkey_result): Likewise.
* gpgme.c (gpgme_new, gpgme_release): Likewise.
* import.c (_gpgme_release_import_result): Likewise.
* key.c (_gpgme_key_cache_init, _gpgme_key_cache_add, key_new,
add_subkey, gpgme_key_release, _gpgme_key_append_name): Likewise.
* keylist.c (_gpgme_release_keylist_result, keylist_colon_handler,
_gpgme_op_keylist_event_cb, gpgme_op_keylist_next): Likewise.
* ops.h (test_and_allocate_result): Likewise.
* passphrase.c (_gpgme_release_passphrase_result,
_gpgme_passphrase_status_handler,
_gpgme_passphrase_command_handler): Likewise.
* progress.c (_gpgme_progress_status_handler): Likewise.
* recipient.c (gpgme_recipients_new, gpgme_recipients_release,
gpgme_recipients_add_name_with_validity): Likewise.
* rungpg.c (_gpgme_gpg_new, _gpgme_gpg_release,
_gpgme_gpg_add_arg, _gpgme_gpg_add_data,
_gpgme_gpg_set_colon_line_handler, free_argv, free_fd_data_map,
build_argv, _gpgme_gpg_spawn, read_status, read_colon_line):
Likewise.
* sign.c (_gpgme_release_sign_result): Likewise.
* signers.c (_gpgme_signers_add): Likewise.
* trustlist.c (trust_item_new, trustlist_colon_handler,
_gpgme_op_trustlist_event_cb, gpgme_op_trustlist_next,
gpgme_trustitem_release): Likewise.
* verify.c (_gpgme_release_verify_result, finish_sig): Likewise.
* version.c (gpgme_get_engine_info, _gpgme_get_program_version):
Likewise.
* w32-io.c (create_reader, create_writer, destroy_reader,
destroy_writer, build_commandline, _gpgme_io_spawn): Likewise.
* w32-sema.c (critsect_init, _gpgme_sema_cs_destroy): Likewise.
* w32-util.c (read_w32_registry_string): Likewise.
* wait.c (_gpgme_fd_table_deinit, _gpgme_fd_table_put,
_gpgme_wait_event_cb, _gpgme_add_io_cb, _gpgme_remove_io_cb)
* data-compat.c: Include <stdlib.h>.
2002-10-09 01:08:21 +00:00
|
|
|
|
free (c);
|
2001-01-30 11:01:41 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2005-09-23 13:29:04 +00:00
|
|
|
|
else {
|
|
|
|
|
/* We set the priority of the thread higher because we know that
|
|
|
|
|
it only runs for a short time. This greatly helps to increase
|
|
|
|
|
the performance of the I/O. */
|
2006-01-26 10:23:15 +00:00
|
|
|
|
SetThreadPriority (c->thread_hd, get_desired_thread_priority ());
|
2005-09-23 13:29:04 +00:00
|
|
|
|
}
|
2001-01-30 11:01:41 +00:00
|
|
|
|
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
2001-02-20 13:31:56 +00:00
|
|
|
|
static void
|
|
|
|
|
destroy_reader (struct reader_context_s *c)
|
|
|
|
|
{
|
2001-03-14 13:51:30 +00:00
|
|
|
|
LOCK (c->mutex);
|
2001-02-28 10:18:38 +00:00
|
|
|
|
c->stop_me = 1;
|
2001-02-20 13:31:56 +00:00
|
|
|
|
if (c->have_space_ev)
|
|
|
|
|
SetEvent (c->have_space_ev);
|
2001-03-14 13:51:30 +00:00
|
|
|
|
UNLOCK (c->mutex);
|
2001-02-20 13:31:56 +00:00
|
|
|
|
|
|
|
|
|
DEBUG1 ("waiting for thread %p termination ...", c->thread_hd );
|
|
|
|
|
WaitForSingleObject (c->stopped, INFINITE);
|
|
|
|
|
DEBUG1 ("thread %p has terminated", c->thread_hd );
|
|
|
|
|
|
|
|
|
|
if (c->stopped)
|
|
|
|
|
CloseHandle (c->stopped);
|
|
|
|
|
if (c->have_data_ev)
|
|
|
|
|
CloseHandle (c->have_data_ev);
|
|
|
|
|
if (c->have_space_ev)
|
|
|
|
|
CloseHandle (c->have_space_ev);
|
|
|
|
|
CloseHandle (c->thread_hd);
|
|
|
|
|
DESTROY_LOCK (c->mutex);
|
2002-10-08 Marcus Brinkmann <marcus@g10code.de>
* util.h (_gpgme_malloc, _gpgme_realloc, _gpgme_calloc,
_gpgme_strdup, _gpgme_free): Remove prototypes.
(xtrymalloc, xtrycalloc, xtryrealloc, xtrystrdup, xfree): Remove
macros.
* util.c: File removed.
* Makefile.am (libgpgme_la_SOURCES): Remove util.h.
* conversion.c (_gpgme_decode_c_string): Use malloc instead of
xtrymalloc, realloc instead of xtryrealloc, calloc instead of
xtrycalloc, free instead of xfree.
(_gpgme_data_append_percentstring_for_xml): Likewise.
* data.c (_gpgme_data_new, _gpgme_data_release): Likewise.
* data-compat.c (gpgme_data_new_from_filepart): Likewise.
* data-mem.c (mem_write, mem_release, gpgme_data_new_from_mem,
_gpgme_data_get_as_string): Likewise.
* debug.c (debug_init): Likewise.
* decrypt.c (_gpgme_release_decrypt_result): Likewise.
* delete.c (_gpgme_release_delete_result): Likewise.
* edit.c (_gpgme_release_edit_result, _gpgme_op_edit_start):
Likewise.
* encrypt.c (_gpgme_release_encrypt_result): Likewise.
* engine.c (_gpgme_engine_get_info, _gpgme_engine_new,
_gpgme_engine_release): Likewise.
* engine-gpgsm.c (_gpgme_gpgsm_new, _gpgme_gpgsm_release,
_gpgme_gpgsm_op_decrypt, _gpgme_gpgsm_op_delete,
gpgsm_set_recipients, _gpgme_gpgsm_op_encrypt,
_gpgme_gpgsm_op_export, _gpgme_gpgsm_op_genkey,
_gpgme_gpgsm_op_import, _gpgme_gpgsm_op_keylist,
_gpgme_gpgsm_op_keylist_ext, _gpgme_gpgsm_op_sign,
_gpgme_gpgsm_op_verify, gpgsm_status_handler): Likewise.
* genkey.c (_gpgme_release_genkey_result): Likewise.
* gpgme.c (gpgme_new, gpgme_release): Likewise.
* import.c (_gpgme_release_import_result): Likewise.
* key.c (_gpgme_key_cache_init, _gpgme_key_cache_add, key_new,
add_subkey, gpgme_key_release, _gpgme_key_append_name): Likewise.
* keylist.c (_gpgme_release_keylist_result, keylist_colon_handler,
_gpgme_op_keylist_event_cb, gpgme_op_keylist_next): Likewise.
* ops.h (test_and_allocate_result): Likewise.
* passphrase.c (_gpgme_release_passphrase_result,
_gpgme_passphrase_status_handler,
_gpgme_passphrase_command_handler): Likewise.
* progress.c (_gpgme_progress_status_handler): Likewise.
* recipient.c (gpgme_recipients_new, gpgme_recipients_release,
gpgme_recipients_add_name_with_validity): Likewise.
* rungpg.c (_gpgme_gpg_new, _gpgme_gpg_release,
_gpgme_gpg_add_arg, _gpgme_gpg_add_data,
_gpgme_gpg_set_colon_line_handler, free_argv, free_fd_data_map,
build_argv, _gpgme_gpg_spawn, read_status, read_colon_line):
Likewise.
* sign.c (_gpgme_release_sign_result): Likewise.
* signers.c (_gpgme_signers_add): Likewise.
* trustlist.c (trust_item_new, trustlist_colon_handler,
_gpgme_op_trustlist_event_cb, gpgme_op_trustlist_next,
gpgme_trustitem_release): Likewise.
* verify.c (_gpgme_release_verify_result, finish_sig): Likewise.
* version.c (gpgme_get_engine_info, _gpgme_get_program_version):
Likewise.
* w32-io.c (create_reader, create_writer, destroy_reader,
destroy_writer, build_commandline, _gpgme_io_spawn): Likewise.
* w32-sema.c (critsect_init, _gpgme_sema_cs_destroy): Likewise.
* w32-util.c (read_w32_registry_string): Likewise.
* wait.c (_gpgme_fd_table_deinit, _gpgme_fd_table_put,
_gpgme_wait_event_cb, _gpgme_add_io_cb, _gpgme_remove_io_cb)
* data-compat.c: Include <stdlib.h>.
2002-10-09 01:08:21 +00:00
|
|
|
|
free (c);
|
2001-02-20 13:31:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-01-30 11:01:41 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Find a reader context or create a new one
|
|
|
|
|
* Note that the reader context will last until a io_close.
|
|
|
|
|
*/
|
|
|
|
|
static struct reader_context_s *
|
|
|
|
|
find_reader (int fd, int start_it)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i=0; i < reader_table_size ; i++ ) {
|
|
|
|
|
if ( reader_table[i].used && reader_table[i].fd == fd )
|
|
|
|
|
return reader_table[i].context;
|
|
|
|
|
}
|
|
|
|
|
if (!start_it)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
LOCK (reader_table_lock);
|
|
|
|
|
for (i=0; i < reader_table_size; i++ ) {
|
|
|
|
|
if (!reader_table[i].used) {
|
|
|
|
|
reader_table[i].fd = fd;
|
|
|
|
|
reader_table[i].context = create_reader (fd_to_handle (fd));
|
|
|
|
|
reader_table[i].used = 1;
|
|
|
|
|
UNLOCK (reader_table_lock);
|
|
|
|
|
return reader_table[i].context;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
UNLOCK (reader_table_lock);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-02-20 13:31:56 +00:00
|
|
|
|
static void
|
|
|
|
|
kill_reader (int fd)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
LOCK (reader_table_lock);
|
|
|
|
|
for (i=0; i < reader_table_size; i++ ) {
|
|
|
|
|
if (reader_table[i].used && reader_table[i].fd == fd ) {
|
|
|
|
|
destroy_reader (reader_table[i].context);
|
|
|
|
|
reader_table[i].context = NULL;
|
|
|
|
|
reader_table[i].used = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
UNLOCK (reader_table_lock);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-11-22 17:10:48 +00:00
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
_gpgme_io_read ( int fd, void *buffer, size_t count )
|
|
|
|
|
{
|
2001-01-30 11:01:41 +00:00
|
|
|
|
int nread;
|
|
|
|
|
struct reader_context_s *c = find_reader (fd,1);
|
2000-11-22 17:10:48 +00:00
|
|
|
|
|
2001-01-30 11:01:41 +00:00
|
|
|
|
DEBUG2 ("fd %d: about to read %d bytes\n", fd, (int)count );
|
|
|
|
|
if ( !c ) {
|
|
|
|
|
DEBUG0 ( "no reader thread\n");
|
2000-11-22 17:10:48 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
2001-01-31 12:39:53 +00:00
|
|
|
|
if (c->eof_shortcut) {
|
|
|
|
|
DEBUG1 ("fd %d: EOF (again)", fd );
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2001-01-30 11:01:41 +00:00
|
|
|
|
|
|
|
|
|
LOCK (c->mutex);
|
2001-01-31 12:39:53 +00:00
|
|
|
|
if (c->readpos == c->writepos && !c->error) { /*no data avail*/
|
2001-01-30 11:01:41 +00:00
|
|
|
|
UNLOCK (c->mutex);
|
|
|
|
|
DEBUG2 ("fd %d: waiting for data from thread %p", fd, c->thread_hd);
|
|
|
|
|
WaitForSingleObject (c->have_data_ev, INFINITE);
|
|
|
|
|
DEBUG2 ("fd %d: data from thread %p available", fd, c->thread_hd);
|
|
|
|
|
LOCK (c->mutex);
|
|
|
|
|
}
|
2001-01-31 12:39:53 +00:00
|
|
|
|
|
|
|
|
|
if (c->readpos == c->writepos || c->error) {
|
|
|
|
|
UNLOCK (c->mutex);
|
|
|
|
|
c->eof_shortcut = 1;
|
|
|
|
|
if (c->eof) {
|
|
|
|
|
DEBUG1 ("fd %d: EOF", fd );
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (!c->error) {
|
|
|
|
|
DEBUG1 ("fd %d: EOF but eof flag not set", fd );
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
DEBUG1 ("fd %d: read error", fd );
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-30 11:01:41 +00:00
|
|
|
|
nread = c->readpos < c->writepos? c->writepos - c->readpos
|
|
|
|
|
: READBUF_SIZE - c->readpos;
|
|
|
|
|
if (nread > count)
|
|
|
|
|
nread = count;
|
|
|
|
|
memcpy (buffer, c->buffer+c->readpos, nread);
|
|
|
|
|
c->readpos = (c->readpos + nread) % READBUF_SIZE;
|
2001-01-31 12:39:53 +00:00
|
|
|
|
if (c->readpos == c->writepos && !c->eof) {
|
2001-02-01 09:25:56 +00:00
|
|
|
|
if ( !ResetEvent (c->have_data_ev) )
|
|
|
|
|
DEBUG1 ("ResetEvent failed: ec=%d", (int)GetLastError ());
|
2001-01-30 11:01:41 +00:00
|
|
|
|
}
|
2001-02-01 09:25:56 +00:00
|
|
|
|
if (!SetEvent (c->have_space_ev))
|
|
|
|
|
DEBUG1 ("SetEvent failed: ec=%d", (int)GetLastError ());
|
2001-01-30 11:01:41 +00:00
|
|
|
|
UNLOCK (c->mutex);
|
|
|
|
|
|
|
|
|
|
DEBUG2 ("fd %d: got %d bytes\n", fd, nread );
|
2005-08-26 12:38:57 +00:00
|
|
|
|
if (nread > 0)
|
|
|
|
|
_gpgme_debug (2, "fd %d: got `%.*s'\n", fd, nread, buffer);
|
2000-11-22 17:10:48 +00:00
|
|
|
|
|
|
|
|
|
return nread;
|
|
|
|
|
}
|
2001-02-28 10:18:38 +00:00
|
|
|
|
/*
|
|
|
|
|
* The writer does use a simple buffering strategy so that we are
|
|
|
|
|
* informed about write errors as soon as possible (i.e. with the the
|
|
|
|
|
* next call to the write function
|
|
|
|
|
*/
|
|
|
|
|
static DWORD CALLBACK
|
|
|
|
|
writer (void *arg)
|
2000-11-22 17:10:48 +00:00
|
|
|
|
{
|
2001-02-28 10:18:38 +00:00
|
|
|
|
struct writer_context_s *c = arg;
|
2001-01-30 11:01:41 +00:00
|
|
|
|
DWORD nwritten;
|
2000-11-22 17:10:48 +00:00
|
|
|
|
|
2001-02-28 10:18:38 +00:00
|
|
|
|
DEBUG2 ("writer thread %p for file %p started", c->thread_hd, c->file_hd );
|
|
|
|
|
for (;;) {
|
|
|
|
|
LOCK (c->mutex);
|
2006-02-15 13:30:08 +00:00
|
|
|
|
if ( c->stop_me ) {
|
|
|
|
|
UNLOCK (c->mutex);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2001-02-28 10:18:38 +00:00
|
|
|
|
if ( !c->nbytes ) {
|
2006-02-15 13:30:08 +00:00
|
|
|
|
if (!SetEvent (c->is_empty))
|
|
|
|
|
DEBUG1 ("SetEvent failed: ec=%d", (int)GetLastError ());
|
2001-02-28 10:18:38 +00:00
|
|
|
|
if (!ResetEvent (c->have_data) )
|
|
|
|
|
DEBUG1 ("ResetEvent failed: ec=%d", (int)GetLastError ());
|
|
|
|
|
UNLOCK (c->mutex);
|
|
|
|
|
DEBUG1 ("writer thread %p: idle ...", c->thread_hd );
|
|
|
|
|
WaitForSingleObject (c->have_data, INFINITE);
|
|
|
|
|
DEBUG1 ("writer thread %p: got data to send", c->thread_hd );
|
|
|
|
|
LOCK (c->mutex);
|
|
|
|
|
}
|
|
|
|
|
if ( c->stop_me ) {
|
|
|
|
|
UNLOCK (c->mutex);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
UNLOCK (c->mutex);
|
|
|
|
|
|
|
|
|
|
DEBUG2 ("writer thread %p: writing %d bytes",
|
|
|
|
|
c->thread_hd, c->nbytes );
|
|
|
|
|
if ( c->nbytes && !WriteFile ( c->file_hd, c->buffer, c->nbytes,
|
|
|
|
|
&nwritten, NULL)) {
|
|
|
|
|
c->error_code = (int)GetLastError ();
|
|
|
|
|
c->error = 1;
|
|
|
|
|
DEBUG2 ("writer thread %p: write error: ec=%d",
|
|
|
|
|
c->thread_hd, c->error_code );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
DEBUG2 ("writer thread %p: wrote %d bytes",
|
|
|
|
|
c->thread_hd, (int)nwritten );
|
|
|
|
|
|
|
|
|
|
LOCK (c->mutex);
|
|
|
|
|
c->nbytes -= nwritten;
|
|
|
|
|
UNLOCK (c->mutex);
|
|
|
|
|
}
|
|
|
|
|
/* indicate that we have an error */
|
|
|
|
|
if ( !SetEvent (c->is_empty) )
|
|
|
|
|
DEBUG1 ("SetEvent failed: ec=%d", (int)GetLastError ());
|
|
|
|
|
DEBUG1 ("writer thread %p ended", c->thread_hd );
|
|
|
|
|
SetEvent (c->stopped);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static struct writer_context_s *
|
|
|
|
|
create_writer (HANDLE fd)
|
|
|
|
|
{
|
|
|
|
|
struct writer_context_s *c;
|
|
|
|
|
SECURITY_ATTRIBUTES sec_attr;
|
|
|
|
|
DWORD tid;
|
|
|
|
|
|
|
|
|
|
DEBUG1 ("creating new write thread for file handle %p", fd );
|
|
|
|
|
memset (&sec_attr, 0, sizeof sec_attr );
|
|
|
|
|
sec_attr.nLength = sizeof sec_attr;
|
|
|
|
|
sec_attr.bInheritHandle = FALSE;
|
|
|
|
|
|
2002-10-08 Marcus Brinkmann <marcus@g10code.de>
* util.h (_gpgme_malloc, _gpgme_realloc, _gpgme_calloc,
_gpgme_strdup, _gpgme_free): Remove prototypes.
(xtrymalloc, xtrycalloc, xtryrealloc, xtrystrdup, xfree): Remove
macros.
* util.c: File removed.
* Makefile.am (libgpgme_la_SOURCES): Remove util.h.
* conversion.c (_gpgme_decode_c_string): Use malloc instead of
xtrymalloc, realloc instead of xtryrealloc, calloc instead of
xtrycalloc, free instead of xfree.
(_gpgme_data_append_percentstring_for_xml): Likewise.
* data.c (_gpgme_data_new, _gpgme_data_release): Likewise.
* data-compat.c (gpgme_data_new_from_filepart): Likewise.
* data-mem.c (mem_write, mem_release, gpgme_data_new_from_mem,
_gpgme_data_get_as_string): Likewise.
* debug.c (debug_init): Likewise.
* decrypt.c (_gpgme_release_decrypt_result): Likewise.
* delete.c (_gpgme_release_delete_result): Likewise.
* edit.c (_gpgme_release_edit_result, _gpgme_op_edit_start):
Likewise.
* encrypt.c (_gpgme_release_encrypt_result): Likewise.
* engine.c (_gpgme_engine_get_info, _gpgme_engine_new,
_gpgme_engine_release): Likewise.
* engine-gpgsm.c (_gpgme_gpgsm_new, _gpgme_gpgsm_release,
_gpgme_gpgsm_op_decrypt, _gpgme_gpgsm_op_delete,
gpgsm_set_recipients, _gpgme_gpgsm_op_encrypt,
_gpgme_gpgsm_op_export, _gpgme_gpgsm_op_genkey,
_gpgme_gpgsm_op_import, _gpgme_gpgsm_op_keylist,
_gpgme_gpgsm_op_keylist_ext, _gpgme_gpgsm_op_sign,
_gpgme_gpgsm_op_verify, gpgsm_status_handler): Likewise.
* genkey.c (_gpgme_release_genkey_result): Likewise.
* gpgme.c (gpgme_new, gpgme_release): Likewise.
* import.c (_gpgme_release_import_result): Likewise.
* key.c (_gpgme_key_cache_init, _gpgme_key_cache_add, key_new,
add_subkey, gpgme_key_release, _gpgme_key_append_name): Likewise.
* keylist.c (_gpgme_release_keylist_result, keylist_colon_handler,
_gpgme_op_keylist_event_cb, gpgme_op_keylist_next): Likewise.
* ops.h (test_and_allocate_result): Likewise.
* passphrase.c (_gpgme_release_passphrase_result,
_gpgme_passphrase_status_handler,
_gpgme_passphrase_command_handler): Likewise.
* progress.c (_gpgme_progress_status_handler): Likewise.
* recipient.c (gpgme_recipients_new, gpgme_recipients_release,
gpgme_recipients_add_name_with_validity): Likewise.
* rungpg.c (_gpgme_gpg_new, _gpgme_gpg_release,
_gpgme_gpg_add_arg, _gpgme_gpg_add_data,
_gpgme_gpg_set_colon_line_handler, free_argv, free_fd_data_map,
build_argv, _gpgme_gpg_spawn, read_status, read_colon_line):
Likewise.
* sign.c (_gpgme_release_sign_result): Likewise.
* signers.c (_gpgme_signers_add): Likewise.
* trustlist.c (trust_item_new, trustlist_colon_handler,
_gpgme_op_trustlist_event_cb, gpgme_op_trustlist_next,
gpgme_trustitem_release): Likewise.
* verify.c (_gpgme_release_verify_result, finish_sig): Likewise.
* version.c (gpgme_get_engine_info, _gpgme_get_program_version):
Likewise.
* w32-io.c (create_reader, create_writer, destroy_reader,
destroy_writer, build_commandline, _gpgme_io_spawn): Likewise.
* w32-sema.c (critsect_init, _gpgme_sema_cs_destroy): Likewise.
* w32-util.c (read_w32_registry_string): Likewise.
* wait.c (_gpgme_fd_table_deinit, _gpgme_fd_table_put,
_gpgme_wait_event_cb, _gpgme_add_io_cb, _gpgme_remove_io_cb)
* data-compat.c: Include <stdlib.h>.
2002-10-09 01:08:21 +00:00
|
|
|
|
c = calloc (1, sizeof *c );
|
2001-02-28 10:18:38 +00:00
|
|
|
|
if (!c)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
c->file_hd = fd;
|
2006-02-15 13:30:08 +00:00
|
|
|
|
c->have_data = CreateEvent (&sec_attr, TRUE, FALSE, NULL);
|
2001-02-28 10:18:38 +00:00
|
|
|
|
c->is_empty = CreateEvent (&sec_attr, TRUE, TRUE, NULL);
|
|
|
|
|
c->stopped = CreateEvent (&sec_attr, TRUE, FALSE, NULL);
|
|
|
|
|
if (!c->have_data || !c->is_empty || !c->stopped ) {
|
|
|
|
|
DEBUG1 ("** CreateEvent failed: ec=%d\n", (int)GetLastError ());
|
|
|
|
|
if (c->have_data)
|
|
|
|
|
CloseHandle (c->have_data);
|
|
|
|
|
if (c->is_empty)
|
|
|
|
|
CloseHandle (c->is_empty);
|
|
|
|
|
if (c->stopped)
|
|
|
|
|
CloseHandle (c->stopped);
|
2002-10-08 Marcus Brinkmann <marcus@g10code.de>
* util.h (_gpgme_malloc, _gpgme_realloc, _gpgme_calloc,
_gpgme_strdup, _gpgme_free): Remove prototypes.
(xtrymalloc, xtrycalloc, xtryrealloc, xtrystrdup, xfree): Remove
macros.
* util.c: File removed.
* Makefile.am (libgpgme_la_SOURCES): Remove util.h.
* conversion.c (_gpgme_decode_c_string): Use malloc instead of
xtrymalloc, realloc instead of xtryrealloc, calloc instead of
xtrycalloc, free instead of xfree.
(_gpgme_data_append_percentstring_for_xml): Likewise.
* data.c (_gpgme_data_new, _gpgme_data_release): Likewise.
* data-compat.c (gpgme_data_new_from_filepart): Likewise.
* data-mem.c (mem_write, mem_release, gpgme_data_new_from_mem,
_gpgme_data_get_as_string): Likewise.
* debug.c (debug_init): Likewise.
* decrypt.c (_gpgme_release_decrypt_result): Likewise.
* delete.c (_gpgme_release_delete_result): Likewise.
* edit.c (_gpgme_release_edit_result, _gpgme_op_edit_start):
Likewise.
* encrypt.c (_gpgme_release_encrypt_result): Likewise.
* engine.c (_gpgme_engine_get_info, _gpgme_engine_new,
_gpgme_engine_release): Likewise.
* engine-gpgsm.c (_gpgme_gpgsm_new, _gpgme_gpgsm_release,
_gpgme_gpgsm_op_decrypt, _gpgme_gpgsm_op_delete,
gpgsm_set_recipients, _gpgme_gpgsm_op_encrypt,
_gpgme_gpgsm_op_export, _gpgme_gpgsm_op_genkey,
_gpgme_gpgsm_op_import, _gpgme_gpgsm_op_keylist,
_gpgme_gpgsm_op_keylist_ext, _gpgme_gpgsm_op_sign,
_gpgme_gpgsm_op_verify, gpgsm_status_handler): Likewise.
* genkey.c (_gpgme_release_genkey_result): Likewise.
* gpgme.c (gpgme_new, gpgme_release): Likewise.
* import.c (_gpgme_release_import_result): Likewise.
* key.c (_gpgme_key_cache_init, _gpgme_key_cache_add, key_new,
add_subkey, gpgme_key_release, _gpgme_key_append_name): Likewise.
* keylist.c (_gpgme_release_keylist_result, keylist_colon_handler,
_gpgme_op_keylist_event_cb, gpgme_op_keylist_next): Likewise.
* ops.h (test_and_allocate_result): Likewise.
* passphrase.c (_gpgme_release_passphrase_result,
_gpgme_passphrase_status_handler,
_gpgme_passphrase_command_handler): Likewise.
* progress.c (_gpgme_progress_status_handler): Likewise.
* recipient.c (gpgme_recipients_new, gpgme_recipients_release,
gpgme_recipients_add_name_with_validity): Likewise.
* rungpg.c (_gpgme_gpg_new, _gpgme_gpg_release,
_gpgme_gpg_add_arg, _gpgme_gpg_add_data,
_gpgme_gpg_set_colon_line_handler, free_argv, free_fd_data_map,
build_argv, _gpgme_gpg_spawn, read_status, read_colon_line):
Likewise.
* sign.c (_gpgme_release_sign_result): Likewise.
* signers.c (_gpgme_signers_add): Likewise.
* trustlist.c (trust_item_new, trustlist_colon_handler,
_gpgme_op_trustlist_event_cb, gpgme_op_trustlist_next,
gpgme_trustitem_release): Likewise.
* verify.c (_gpgme_release_verify_result, finish_sig): Likewise.
* version.c (gpgme_get_engine_info, _gpgme_get_program_version):
Likewise.
* w32-io.c (create_reader, create_writer, destroy_reader,
destroy_writer, build_commandline, _gpgme_io_spawn): Likewise.
* w32-sema.c (critsect_init, _gpgme_sema_cs_destroy): Likewise.
* w32-util.c (read_w32_registry_string): Likewise.
* wait.c (_gpgme_fd_table_deinit, _gpgme_fd_table_put,
_gpgme_wait_event_cb, _gpgme_add_io_cb, _gpgme_remove_io_cb)
* data-compat.c: Include <stdlib.h>.
2002-10-09 01:08:21 +00:00
|
|
|
|
free (c);
|
2001-02-28 10:18:38 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c->is_empty = set_synchronize (c->is_empty);
|
|
|
|
|
INIT_LOCK (c->mutex);
|
|
|
|
|
|
|
|
|
|
c->thread_hd = CreateThread (&sec_attr, 0, writer, c, 0, &tid );
|
|
|
|
|
if (!c->thread_hd) {
|
|
|
|
|
DEBUG1 ("** failed to create writer thread: ec=%d\n",
|
|
|
|
|
(int)GetLastError ());
|
|
|
|
|
DESTROY_LOCK (c->mutex);
|
|
|
|
|
if (c->have_data)
|
|
|
|
|
CloseHandle (c->have_data);
|
|
|
|
|
if (c->is_empty)
|
|
|
|
|
CloseHandle (c->is_empty);
|
|
|
|
|
if (c->stopped)
|
|
|
|
|
CloseHandle (c->stopped);
|
2002-10-08 Marcus Brinkmann <marcus@g10code.de>
* util.h (_gpgme_malloc, _gpgme_realloc, _gpgme_calloc,
_gpgme_strdup, _gpgme_free): Remove prototypes.
(xtrymalloc, xtrycalloc, xtryrealloc, xtrystrdup, xfree): Remove
macros.
* util.c: File removed.
* Makefile.am (libgpgme_la_SOURCES): Remove util.h.
* conversion.c (_gpgme_decode_c_string): Use malloc instead of
xtrymalloc, realloc instead of xtryrealloc, calloc instead of
xtrycalloc, free instead of xfree.
(_gpgme_data_append_percentstring_for_xml): Likewise.
* data.c (_gpgme_data_new, _gpgme_data_release): Likewise.
* data-compat.c (gpgme_data_new_from_filepart): Likewise.
* data-mem.c (mem_write, mem_release, gpgme_data_new_from_mem,
_gpgme_data_get_as_string): Likewise.
* debug.c (debug_init): Likewise.
* decrypt.c (_gpgme_release_decrypt_result): Likewise.
* delete.c (_gpgme_release_delete_result): Likewise.
* edit.c (_gpgme_release_edit_result, _gpgme_op_edit_start):
Likewise.
* encrypt.c (_gpgme_release_encrypt_result): Likewise.
* engine.c (_gpgme_engine_get_info, _gpgme_engine_new,
_gpgme_engine_release): Likewise.
* engine-gpgsm.c (_gpgme_gpgsm_new, _gpgme_gpgsm_release,
_gpgme_gpgsm_op_decrypt, _gpgme_gpgsm_op_delete,
gpgsm_set_recipients, _gpgme_gpgsm_op_encrypt,
_gpgme_gpgsm_op_export, _gpgme_gpgsm_op_genkey,
_gpgme_gpgsm_op_import, _gpgme_gpgsm_op_keylist,
_gpgme_gpgsm_op_keylist_ext, _gpgme_gpgsm_op_sign,
_gpgme_gpgsm_op_verify, gpgsm_status_handler): Likewise.
* genkey.c (_gpgme_release_genkey_result): Likewise.
* gpgme.c (gpgme_new, gpgme_release): Likewise.
* import.c (_gpgme_release_import_result): Likewise.
* key.c (_gpgme_key_cache_init, _gpgme_key_cache_add, key_new,
add_subkey, gpgme_key_release, _gpgme_key_append_name): Likewise.
* keylist.c (_gpgme_release_keylist_result, keylist_colon_handler,
_gpgme_op_keylist_event_cb, gpgme_op_keylist_next): Likewise.
* ops.h (test_and_allocate_result): Likewise.
* passphrase.c (_gpgme_release_passphrase_result,
_gpgme_passphrase_status_handler,
_gpgme_passphrase_command_handler): Likewise.
* progress.c (_gpgme_progress_status_handler): Likewise.
* recipient.c (gpgme_recipients_new, gpgme_recipients_release,
gpgme_recipients_add_name_with_validity): Likewise.
* rungpg.c (_gpgme_gpg_new, _gpgme_gpg_release,
_gpgme_gpg_add_arg, _gpgme_gpg_add_data,
_gpgme_gpg_set_colon_line_handler, free_argv, free_fd_data_map,
build_argv, _gpgme_gpg_spawn, read_status, read_colon_line):
Likewise.
* sign.c (_gpgme_release_sign_result): Likewise.
* signers.c (_gpgme_signers_add): Likewise.
* trustlist.c (trust_item_new, trustlist_colon_handler,
_gpgme_op_trustlist_event_cb, gpgme_op_trustlist_next,
gpgme_trustitem_release): Likewise.
* verify.c (_gpgme_release_verify_result, finish_sig): Likewise.
* version.c (gpgme_get_engine_info, _gpgme_get_program_version):
Likewise.
* w32-io.c (create_reader, create_writer, destroy_reader,
destroy_writer, build_commandline, _gpgme_io_spawn): Likewise.
* w32-sema.c (critsect_init, _gpgme_sema_cs_destroy): Likewise.
* w32-util.c (read_w32_registry_string): Likewise.
* wait.c (_gpgme_fd_table_deinit, _gpgme_fd_table_put,
_gpgme_wait_event_cb, _gpgme_add_io_cb, _gpgme_remove_io_cb)
* data-compat.c: Include <stdlib.h>.
2002-10-09 01:08:21 +00:00
|
|
|
|
free (c);
|
2001-02-28 10:18:38 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2005-09-23 13:29:04 +00:00
|
|
|
|
else {
|
|
|
|
|
/* We set the priority of the thread higher because we know that
|
|
|
|
|
it only runs for a short time. This greatly helps to increase
|
|
|
|
|
the performance of the I/O. */
|
2006-01-26 10:23:15 +00:00
|
|
|
|
SetThreadPriority (c->thread_hd, get_desired_thread_priority ());
|
2005-09-23 13:29:04 +00:00
|
|
|
|
}
|
2001-02-28 10:18:38 +00:00
|
|
|
|
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
destroy_writer (struct writer_context_s *c)
|
|
|
|
|
{
|
2001-03-14 13:51:30 +00:00
|
|
|
|
LOCK (c->mutex);
|
2001-02-28 10:18:38 +00:00
|
|
|
|
c->stop_me = 1;
|
|
|
|
|
if (c->have_data)
|
|
|
|
|
SetEvent (c->have_data);
|
2001-03-14 13:51:30 +00:00
|
|
|
|
UNLOCK (c->mutex);
|
2001-02-28 10:18:38 +00:00
|
|
|
|
|
|
|
|
|
DEBUG1 ("waiting for thread %p termination ...", c->thread_hd );
|
|
|
|
|
WaitForSingleObject (c->stopped, INFINITE);
|
|
|
|
|
DEBUG1 ("thread %p has terminated", c->thread_hd );
|
|
|
|
|
|
|
|
|
|
if (c->stopped)
|
|
|
|
|
CloseHandle (c->stopped);
|
|
|
|
|
if (c->have_data)
|
|
|
|
|
CloseHandle (c->have_data);
|
|
|
|
|
if (c->is_empty)
|
|
|
|
|
CloseHandle (c->is_empty);
|
|
|
|
|
CloseHandle (c->thread_hd);
|
|
|
|
|
DESTROY_LOCK (c->mutex);
|
2002-10-08 Marcus Brinkmann <marcus@g10code.de>
* util.h (_gpgme_malloc, _gpgme_realloc, _gpgme_calloc,
_gpgme_strdup, _gpgme_free): Remove prototypes.
(xtrymalloc, xtrycalloc, xtryrealloc, xtrystrdup, xfree): Remove
macros.
* util.c: File removed.
* Makefile.am (libgpgme_la_SOURCES): Remove util.h.
* conversion.c (_gpgme_decode_c_string): Use malloc instead of
xtrymalloc, realloc instead of xtryrealloc, calloc instead of
xtrycalloc, free instead of xfree.
(_gpgme_data_append_percentstring_for_xml): Likewise.
* data.c (_gpgme_data_new, _gpgme_data_release): Likewise.
* data-compat.c (gpgme_data_new_from_filepart): Likewise.
* data-mem.c (mem_write, mem_release, gpgme_data_new_from_mem,
_gpgme_data_get_as_string): Likewise.
* debug.c (debug_init): Likewise.
* decrypt.c (_gpgme_release_decrypt_result): Likewise.
* delete.c (_gpgme_release_delete_result): Likewise.
* edit.c (_gpgme_release_edit_result, _gpgme_op_edit_start):
Likewise.
* encrypt.c (_gpgme_release_encrypt_result): Likewise.
* engine.c (_gpgme_engine_get_info, _gpgme_engine_new,
_gpgme_engine_release): Likewise.
* engine-gpgsm.c (_gpgme_gpgsm_new, _gpgme_gpgsm_release,
_gpgme_gpgsm_op_decrypt, _gpgme_gpgsm_op_delete,
gpgsm_set_recipients, _gpgme_gpgsm_op_encrypt,
_gpgme_gpgsm_op_export, _gpgme_gpgsm_op_genkey,
_gpgme_gpgsm_op_import, _gpgme_gpgsm_op_keylist,
_gpgme_gpgsm_op_keylist_ext, _gpgme_gpgsm_op_sign,
_gpgme_gpgsm_op_verify, gpgsm_status_handler): Likewise.
* genkey.c (_gpgme_release_genkey_result): Likewise.
* gpgme.c (gpgme_new, gpgme_release): Likewise.
* import.c (_gpgme_release_import_result): Likewise.
* key.c (_gpgme_key_cache_init, _gpgme_key_cache_add, key_new,
add_subkey, gpgme_key_release, _gpgme_key_append_name): Likewise.
* keylist.c (_gpgme_release_keylist_result, keylist_colon_handler,
_gpgme_op_keylist_event_cb, gpgme_op_keylist_next): Likewise.
* ops.h (test_and_allocate_result): Likewise.
* passphrase.c (_gpgme_release_passphrase_result,
_gpgme_passphrase_status_handler,
_gpgme_passphrase_command_handler): Likewise.
* progress.c (_gpgme_progress_status_handler): Likewise.
* recipient.c (gpgme_recipients_new, gpgme_recipients_release,
gpgme_recipients_add_name_with_validity): Likewise.
* rungpg.c (_gpgme_gpg_new, _gpgme_gpg_release,
_gpgme_gpg_add_arg, _gpgme_gpg_add_data,
_gpgme_gpg_set_colon_line_handler, free_argv, free_fd_data_map,
build_argv, _gpgme_gpg_spawn, read_status, read_colon_line):
Likewise.
* sign.c (_gpgme_release_sign_result): Likewise.
* signers.c (_gpgme_signers_add): Likewise.
* trustlist.c (trust_item_new, trustlist_colon_handler,
_gpgme_op_trustlist_event_cb, gpgme_op_trustlist_next,
gpgme_trustitem_release): Likewise.
* verify.c (_gpgme_release_verify_result, finish_sig): Likewise.
* version.c (gpgme_get_engine_info, _gpgme_get_program_version):
Likewise.
* w32-io.c (create_reader, create_writer, destroy_reader,
destroy_writer, build_commandline, _gpgme_io_spawn): Likewise.
* w32-sema.c (critsect_init, _gpgme_sema_cs_destroy): Likewise.
* w32-util.c (read_w32_registry_string): Likewise.
* wait.c (_gpgme_fd_table_deinit, _gpgme_fd_table_put,
_gpgme_wait_event_cb, _gpgme_add_io_cb, _gpgme_remove_io_cb)
* data-compat.c: Include <stdlib.h>.
2002-10-09 01:08:21 +00:00
|
|
|
|
free (c);
|
2001-02-28 10:18:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Find a writer context or create a new one
|
|
|
|
|
* Note that the writer context will last until a io_close.
|
|
|
|
|
*/
|
|
|
|
|
static struct writer_context_s *
|
|
|
|
|
find_writer (int fd, int start_it)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i=0; i < writer_table_size ; i++ ) {
|
|
|
|
|
if ( writer_table[i].used && writer_table[i].fd == fd )
|
|
|
|
|
return writer_table[i].context;
|
|
|
|
|
}
|
|
|
|
|
if (!start_it)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
LOCK (writer_table_lock);
|
|
|
|
|
for (i=0; i < writer_table_size; i++ ) {
|
|
|
|
|
if (!writer_table[i].used) {
|
|
|
|
|
writer_table[i].fd = fd;
|
|
|
|
|
writer_table[i].context = create_writer (fd_to_handle (fd));
|
|
|
|
|
writer_table[i].used = 1;
|
|
|
|
|
UNLOCK (writer_table_lock);
|
|
|
|
|
return writer_table[i].context;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
UNLOCK (writer_table_lock);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
kill_writer (int fd)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
LOCK (writer_table_lock);
|
|
|
|
|
for (i=0; i < writer_table_size; i++ ) {
|
|
|
|
|
if (writer_table[i].used && writer_table[i].fd == fd ) {
|
|
|
|
|
destroy_writer (writer_table[i].context);
|
|
|
|
|
writer_table[i].context = NULL;
|
|
|
|
|
writer_table[i].used = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
UNLOCK (writer_table_lock);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
_gpgme_io_write ( int fd, const void *buffer, size_t count )
|
|
|
|
|
{
|
|
|
|
|
struct writer_context_s *c = find_writer (fd,1);
|
2001-01-30 12:06:29 +00:00
|
|
|
|
|
2001-01-30 11:01:41 +00:00
|
|
|
|
DEBUG2 ("fd %d: about to write %d bytes\n", fd, (int)count );
|
2005-08-26 12:38:57 +00:00
|
|
|
|
_gpgme_debug (2, "fd %d: write `%.*s'\n", fd, (int) count, buffer);
|
2001-02-28 10:18:38 +00:00
|
|
|
|
if ( !c ) {
|
|
|
|
|
DEBUG0 ( "no writer thread\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOCK (c->mutex);
|
|
|
|
|
if ( c->nbytes ) { /* bytes are pending for send */
|
2006-02-15 13:30:08 +00:00
|
|
|
|
/* Reset the is_empty event. Better safe than sorry. */
|
|
|
|
|
if (!ResetEvent (c->is_empty))
|
|
|
|
|
DEBUG1 ("ResetEvent failed: ec=%d", (int)GetLastError ());
|
2001-02-28 10:18:38 +00:00
|
|
|
|
UNLOCK (c->mutex);
|
|
|
|
|
DEBUG2 ("fd %d: waiting for empty buffer in thread %p",
|
|
|
|
|
fd, c->thread_hd);
|
|
|
|
|
WaitForSingleObject (c->is_empty, INFINITE);
|
|
|
|
|
DEBUG2 ("fd %d: thread %p buffer is empty", fd, c->thread_hd);
|
|
|
|
|
LOCK (c->mutex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( c->error) {
|
|
|
|
|
UNLOCK (c->mutex);
|
|
|
|
|
DEBUG1 ("fd %d: write error", fd );
|
2000-11-22 17:10:48 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
2006-02-15 13:30:08 +00:00
|
|
|
|
|
|
|
|
|
/* If no error occured, the number of bytes in the buffer must be
|
|
|
|
|
zero. */
|
|
|
|
|
assert (!c->nbytes);
|
|
|
|
|
|
2001-02-28 10:18:38 +00:00
|
|
|
|
if (count > WRITEBUF_SIZE)
|
|
|
|
|
count = WRITEBUF_SIZE;
|
|
|
|
|
memcpy (c->buffer, buffer, count);
|
|
|
|
|
c->nbytes = count;
|
2006-02-15 13:30:08 +00:00
|
|
|
|
|
|
|
|
|
/* We have to reset the is_empty event early, because it is also
|
|
|
|
|
used by the select() implementation to probe the channel. */
|
|
|
|
|
if (!ResetEvent (c->is_empty))
|
|
|
|
|
DEBUG1 ("ResetEvent failed: ec=%d", (int)GetLastError ());
|
2001-02-28 10:18:38 +00:00
|
|
|
|
if (!SetEvent (c->have_data))
|
|
|
|
|
DEBUG1 ("SetEvent failed: ec=%d", (int)GetLastError ());
|
|
|
|
|
UNLOCK (c->mutex);
|
2000-11-22 17:10:48 +00:00
|
|
|
|
|
2001-02-28 10:18:38 +00:00
|
|
|
|
DEBUG2 ("fd %d: copied %d bytes\n",
|
|
|
|
|
fd, (int)count );
|
|
|
|
|
return (int)count;
|
2000-11-22 17:10:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-02-28 10:18:38 +00:00
|
|
|
|
|
2000-11-22 17:10:48 +00:00
|
|
|
|
int
|
2000-12-06 12:17:10 +00:00
|
|
|
|
_gpgme_io_pipe ( int filedes[2], int inherit_idx )
|
2000-11-22 17:10:48 +00:00
|
|
|
|
{
|
|
|
|
|
HANDLE r, w;
|
2000-12-06 12:17:10 +00:00
|
|
|
|
SECURITY_ATTRIBUTES sec_attr;
|
|
|
|
|
|
|
|
|
|
memset (&sec_attr, 0, sizeof sec_attr );
|
|
|
|
|
sec_attr.nLength = sizeof sec_attr;
|
|
|
|
|
sec_attr.bInheritHandle = FALSE;
|
2000-11-22 17:10:48 +00:00
|
|
|
|
|
2005-09-23 13:29:04 +00:00
|
|
|
|
if (!CreatePipe ( &r, &w, &sec_attr, PIPEBUF_SIZE))
|
2000-11-22 17:10:48 +00:00
|
|
|
|
return -1;
|
2005-09-23 13:29:04 +00:00
|
|
|
|
/* Make one end inheritable. */
|
2000-12-06 12:17:10 +00:00
|
|
|
|
if ( inherit_idx == 0 ) {
|
|
|
|
|
HANDLE h;
|
|
|
|
|
if (!DuplicateHandle( GetCurrentProcess(), r,
|
|
|
|
|
GetCurrentProcess(), &h, 0,
|
|
|
|
|
TRUE, DUPLICATE_SAME_ACCESS ) ) {
|
2001-01-30 11:01:41 +00:00
|
|
|
|
DEBUG1 ("DuplicateHandle failed: ec=%d\n", (int)GetLastError());
|
2000-12-06 12:17:10 +00:00
|
|
|
|
CloseHandle (r);
|
|
|
|
|
CloseHandle (w);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
CloseHandle (r);
|
|
|
|
|
r = h;
|
|
|
|
|
}
|
|
|
|
|
else if ( inherit_idx == 1 ) {
|
|
|
|
|
HANDLE h;
|
|
|
|
|
if (!DuplicateHandle( GetCurrentProcess(), w,
|
|
|
|
|
GetCurrentProcess(), &h, 0,
|
|
|
|
|
TRUE, DUPLICATE_SAME_ACCESS ) ) {
|
2001-01-30 11:01:41 +00:00
|
|
|
|
DEBUG1 ("DuplicateHandle failed: ec=%d\n", (int)GetLastError());
|
2000-12-06 12:17:10 +00:00
|
|
|
|
CloseHandle (r);
|
|
|
|
|
CloseHandle (w);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
CloseHandle (w);
|
|
|
|
|
w = h;
|
|
|
|
|
}
|
|
|
|
|
|
2000-11-22 17:10:48 +00:00
|
|
|
|
filedes[0] = handle_to_fd (r);
|
|
|
|
|
filedes[1] = handle_to_fd (w);
|
2001-01-30 11:01:41 +00:00
|
|
|
|
DEBUG5 ("CreatePipe %p %p %d %d inherit=%d\n", r, w,
|
|
|
|
|
filedes[0], filedes[1], inherit_idx );
|
2000-11-23 15:28:15 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
_gpgme_io_close ( int fd )
|
|
|
|
|
{
|
2001-02-20 13:31:56 +00:00
|
|
|
|
int i;
|
|
|
|
|
void (*handler)(int, void*) = NULL;
|
|
|
|
|
void *value = NULL;
|
|
|
|
|
|
2000-11-23 15:28:15 +00:00
|
|
|
|
if ( fd == -1 )
|
|
|
|
|
return -1;
|
2000-12-06 12:17:10 +00:00
|
|
|
|
|
2001-01-30 11:01:41 +00:00
|
|
|
|
DEBUG1 ("** closing handle for fd %d\n", fd);
|
2001-02-20 13:31:56 +00:00
|
|
|
|
kill_reader (fd);
|
2001-02-28 10:18:38 +00:00
|
|
|
|
kill_writer (fd);
|
2001-02-20 13:31:56 +00:00
|
|
|
|
LOCK (notify_table_lock);
|
|
|
|
|
for ( i=0; i < DIM (notify_table); i++ ) {
|
|
|
|
|
if (notify_table[i].inuse && notify_table[i].fd == fd) {
|
|
|
|
|
handler = notify_table[i].handler;
|
|
|
|
|
value = notify_table[i].value;
|
|
|
|
|
notify_table[i].handler = NULL;
|
|
|
|
|
notify_table[i].value = NULL;
|
|
|
|
|
notify_table[i].inuse = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
UNLOCK (notify_table_lock);
|
|
|
|
|
if (handler)
|
|
|
|
|
handler (fd, value);
|
2001-01-30 11:01:41 +00:00
|
|
|
|
|
2000-12-06 12:17:10 +00:00
|
|
|
|
if ( !CloseHandle (fd_to_handle (fd)) ) {
|
2001-01-30 11:01:41 +00:00
|
|
|
|
DEBUG2 ("CloseHandle for fd %d failed: ec=%d\n",
|
2000-12-06 12:17:10 +00:00
|
|
|
|
fd, (int)GetLastError ());
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
2000-11-22 17:10:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-02-20 13:31:56 +00:00
|
|
|
|
int
|
|
|
|
|
_gpgme_io_set_close_notify (int fd, void (*handler)(int, void*), void *value)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
assert (fd != -1);
|
|
|
|
|
|
|
|
|
|
LOCK (notify_table_lock);
|
|
|
|
|
for (i=0; i < DIM (notify_table); i++ ) {
|
|
|
|
|
if ( notify_table[i].inuse && notify_table[i].fd == fd )
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if ( i == DIM (notify_table) ) {
|
|
|
|
|
for (i=0; i < DIM (notify_table); i++ ) {
|
|
|
|
|
if ( !notify_table[i].inuse )
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( i == DIM (notify_table) ) {
|
|
|
|
|
UNLOCK (notify_table_lock);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
notify_table[i].fd = fd;
|
|
|
|
|
notify_table[i].handler = handler;
|
|
|
|
|
notify_table[i].value = value;
|
|
|
|
|
notify_table[i].inuse = 1;
|
|
|
|
|
UNLOCK (notify_table_lock);
|
|
|
|
|
DEBUG2 ("set notification for fd %d (idx=%d)", fd, i );
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-11-23 15:28:15 +00:00
|
|
|
|
|
2000-11-22 17:10:48 +00:00
|
|
|
|
int
|
|
|
|
|
_gpgme_io_set_nonblocking ( int fd )
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static char *
|
2007-01-17 19:35:06 +00:00
|
|
|
|
build_commandline (char **argv)
|
2000-11-22 17:10:48 +00:00
|
|
|
|
{
|
2007-01-17 19:35:06 +00:00
|
|
|
|
int i;
|
|
|
|
|
int j;
|
|
|
|
|
int n = 0;
|
|
|
|
|
char *buf;
|
|
|
|
|
char *p;
|
2005-09-13 14:17:04 +00:00
|
|
|
|
|
2007-01-17 19:35:06 +00:00
|
|
|
|
/* We have to quote some things because under Windows the program
|
|
|
|
|
parses the commandline and does some unquoting. We enclose the
|
|
|
|
|
whole argument in double-quotes, and escape literal double-quotes
|
|
|
|
|
as well as backslashes with a backslash. We end up with a
|
|
|
|
|
trailing space at the end of the line, but that is harmless. */
|
|
|
|
|
for (i = 0; argv[i]; i++)
|
|
|
|
|
{
|
|
|
|
|
p = argv[i];
|
|
|
|
|
/* The leading double-quote. */
|
|
|
|
|
n++;
|
|
|
|
|
while (*p)
|
|
|
|
|
{
|
|
|
|
|
/* An extra one for each literal that must be escaped. */
|
|
|
|
|
if (*p == '\\' || *p == '"')
|
|
|
|
|
n++;
|
|
|
|
|
n++;
|
|
|
|
|
p++;
|
|
|
|
|
}
|
|
|
|
|
/* The trailing double-quote and the delimiter. */
|
|
|
|
|
n += 2;
|
|
|
|
|
}
|
|
|
|
|
/* And a trailing zero. */
|
|
|
|
|
n++;
|
|
|
|
|
|
2005-09-13 14:17:04 +00:00
|
|
|
|
buf = p = malloc (n);
|
2007-01-17 19:35:06 +00:00
|
|
|
|
if (!buf)
|
2005-09-13 14:17:04 +00:00
|
|
|
|
return NULL;
|
2007-01-17 19:35:06 +00:00
|
|
|
|
for (i = 0; argv[i]; i++)
|
2005-09-13 14:17:04 +00:00
|
|
|
|
{
|
2007-01-17 19:35:06 +00:00
|
|
|
|
char *argvp = argv[i];
|
|
|
|
|
|
|
|
|
|
*(p++) = '"';
|
|
|
|
|
while (*argvp)
|
|
|
|
|
{
|
|
|
|
|
if (*p == '\\' || *p == '"')
|
|
|
|
|
*(p++) = '\\';
|
|
|
|
|
*(p++) = *(argvp++);
|
|
|
|
|
}
|
|
|
|
|
*(p++) = '"';
|
|
|
|
|
*(p++) = ' ';
|
2001-07-31 15:21:58 +00:00
|
|
|
|
}
|
2007-01-17 19:35:06 +00:00
|
|
|
|
*(p++) = 0;
|
|
|
|
|
|
2005-09-13 14:17:04 +00:00
|
|
|
|
return buf;
|
2000-11-22 17:10:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-11-23 15:28:15 +00:00
|
|
|
|
int
|
2000-11-22 17:10:48 +00:00
|
|
|
|
_gpgme_io_spawn ( const char *path, char **argv,
|
|
|
|
|
struct spawn_fd_item_s *fd_child_list,
|
|
|
|
|
struct spawn_fd_item_s *fd_parent_list )
|
|
|
|
|
{
|
|
|
|
|
SECURITY_ATTRIBUTES sec_attr;
|
|
|
|
|
PROCESS_INFORMATION pi = {
|
|
|
|
|
NULL, /* returns process handle */
|
|
|
|
|
0, /* returns primary thread handle */
|
|
|
|
|
0, /* returns pid */
|
|
|
|
|
0 /* returns tid */
|
|
|
|
|
};
|
2000-12-06 12:17:10 +00:00
|
|
|
|
STARTUPINFO si;
|
2000-11-22 17:10:48 +00:00
|
|
|
|
char *envblock = NULL;
|
|
|
|
|
int cr_flags = CREATE_DEFAULT_ERROR_MODE
|
|
|
|
|
| GetPriorityClass (GetCurrentProcess ());
|
2000-12-06 12:17:10 +00:00
|
|
|
|
int i;
|
2000-11-23 15:28:15 +00:00
|
|
|
|
char *arg_string;
|
2000-12-06 12:17:10 +00:00
|
|
|
|
int duped_stdin = 0;
|
|
|
|
|
int duped_stderr = 0;
|
|
|
|
|
HANDLE hnul = INVALID_HANDLE_VALUE;
|
2003-09-13 17:45:04 +00:00
|
|
|
|
/* FIXME. */
|
|
|
|
|
int debug_me = 0;
|
2000-11-22 17:10:48 +00:00
|
|
|
|
|
2000-12-06 12:17:10 +00:00
|
|
|
|
memset (&sec_attr, 0, sizeof sec_attr );
|
|
|
|
|
sec_attr.nLength = sizeof sec_attr;
|
2000-11-22 17:10:48 +00:00
|
|
|
|
sec_attr.bInheritHandle = FALSE;
|
|
|
|
|
|
|
|
|
|
arg_string = build_commandline ( argv );
|
|
|
|
|
if (!arg_string )
|
|
|
|
|
return -1;
|
|
|
|
|
|
2000-12-06 12:17:10 +00:00
|
|
|
|
memset (&si, 0, sizeof si);
|
2000-11-22 17:10:48 +00:00
|
|
|
|
si.cb = sizeof (si);
|
2000-12-12 13:31:25 +00:00
|
|
|
|
si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
|
2005-10-24 09:53:59 +00:00
|
|
|
|
si.wShowWindow = debug_me? SW_SHOW : SW_HIDE;
|
2000-11-22 17:10:48 +00:00
|
|
|
|
si.hStdInput = GetStdHandle (STD_INPUT_HANDLE);
|
|
|
|
|
si.hStdOutput = GetStdHandle (STD_OUTPUT_HANDLE);
|
|
|
|
|
si.hStdError = GetStdHandle (STD_ERROR_HANDLE);
|
2000-12-06 12:17:10 +00:00
|
|
|
|
|
|
|
|
|
for (i=0; fd_child_list[i].fd != -1; i++ ) {
|
|
|
|
|
if (fd_child_list[i].dup_to == 0 ) {
|
|
|
|
|
si.hStdInput = fd_to_handle (fd_child_list[i].fd);
|
2001-01-30 11:01:41 +00:00
|
|
|
|
DEBUG1 ("using %d for stdin", fd_child_list[i].fd );
|
2000-12-06 12:17:10 +00:00
|
|
|
|
duped_stdin=1;
|
|
|
|
|
}
|
|
|
|
|
else if (fd_child_list[i].dup_to == 1 ) {
|
|
|
|
|
si.hStdOutput = fd_to_handle (fd_child_list[i].fd);
|
2001-01-30 11:01:41 +00:00
|
|
|
|
DEBUG1 ("using %d for stdout", fd_child_list[i].fd );
|
2000-12-06 12:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
else if (fd_child_list[i].dup_to == 2 ) {
|
|
|
|
|
si.hStdError = fd_to_handle (fd_child_list[i].fd);
|
2001-01-30 11:01:41 +00:00
|
|
|
|
DEBUG1 ("using %d for stderr", fd_child_list[i].fd );
|
2000-12-06 12:17:10 +00:00
|
|
|
|
duped_stderr = 1;
|
|
|
|
|
}
|
2000-11-22 17:10:48 +00:00
|
|
|
|
}
|
2000-12-06 12:17:10 +00:00
|
|
|
|
|
|
|
|
|
if( !duped_stdin || !duped_stderr ) {
|
|
|
|
|
SECURITY_ATTRIBUTES sa;
|
|
|
|
|
|
|
|
|
|
memset (&sa, 0, sizeof sa );
|
|
|
|
|
sa.nLength = sizeof sa;
|
|
|
|
|
sa.bInheritHandle = TRUE;
|
2001-01-30 11:01:41 +00:00
|
|
|
|
hnul = CreateFile ( "nul",
|
2000-12-06 12:17:10 +00:00
|
|
|
|
GENERIC_READ|GENERIC_WRITE,
|
|
|
|
|
FILE_SHARE_READ|FILE_SHARE_WRITE,
|
|
|
|
|
&sa,
|
|
|
|
|
OPEN_EXISTING,
|
|
|
|
|
FILE_ATTRIBUTE_NORMAL,
|
|
|
|
|
NULL );
|
|
|
|
|
if ( hnul == INVALID_HANDLE_VALUE ) {
|
2001-01-30 11:01:41 +00:00
|
|
|
|
DEBUG1 ("can't open `nul': ec=%d\n", (int)GetLastError ());
|
2002-10-08 Marcus Brinkmann <marcus@g10code.de>
* util.h (_gpgme_malloc, _gpgme_realloc, _gpgme_calloc,
_gpgme_strdup, _gpgme_free): Remove prototypes.
(xtrymalloc, xtrycalloc, xtryrealloc, xtrystrdup, xfree): Remove
macros.
* util.c: File removed.
* Makefile.am (libgpgme_la_SOURCES): Remove util.h.
* conversion.c (_gpgme_decode_c_string): Use malloc instead of
xtrymalloc, realloc instead of xtryrealloc, calloc instead of
xtrycalloc, free instead of xfree.
(_gpgme_data_append_percentstring_for_xml): Likewise.
* data.c (_gpgme_data_new, _gpgme_data_release): Likewise.
* data-compat.c (gpgme_data_new_from_filepart): Likewise.
* data-mem.c (mem_write, mem_release, gpgme_data_new_from_mem,
_gpgme_data_get_as_string): Likewise.
* debug.c (debug_init): Likewise.
* decrypt.c (_gpgme_release_decrypt_result): Likewise.
* delete.c (_gpgme_release_delete_result): Likewise.
* edit.c (_gpgme_release_edit_result, _gpgme_op_edit_start):
Likewise.
* encrypt.c (_gpgme_release_encrypt_result): Likewise.
* engine.c (_gpgme_engine_get_info, _gpgme_engine_new,
_gpgme_engine_release): Likewise.
* engine-gpgsm.c (_gpgme_gpgsm_new, _gpgme_gpgsm_release,
_gpgme_gpgsm_op_decrypt, _gpgme_gpgsm_op_delete,
gpgsm_set_recipients, _gpgme_gpgsm_op_encrypt,
_gpgme_gpgsm_op_export, _gpgme_gpgsm_op_genkey,
_gpgme_gpgsm_op_import, _gpgme_gpgsm_op_keylist,
_gpgme_gpgsm_op_keylist_ext, _gpgme_gpgsm_op_sign,
_gpgme_gpgsm_op_verify, gpgsm_status_handler): Likewise.
* genkey.c (_gpgme_release_genkey_result): Likewise.
* gpgme.c (gpgme_new, gpgme_release): Likewise.
* import.c (_gpgme_release_import_result): Likewise.
* key.c (_gpgme_key_cache_init, _gpgme_key_cache_add, key_new,
add_subkey, gpgme_key_release, _gpgme_key_append_name): Likewise.
* keylist.c (_gpgme_release_keylist_result, keylist_colon_handler,
_gpgme_op_keylist_event_cb, gpgme_op_keylist_next): Likewise.
* ops.h (test_and_allocate_result): Likewise.
* passphrase.c (_gpgme_release_passphrase_result,
_gpgme_passphrase_status_handler,
_gpgme_passphrase_command_handler): Likewise.
* progress.c (_gpgme_progress_status_handler): Likewise.
* recipient.c (gpgme_recipients_new, gpgme_recipients_release,
gpgme_recipients_add_name_with_validity): Likewise.
* rungpg.c (_gpgme_gpg_new, _gpgme_gpg_release,
_gpgme_gpg_add_arg, _gpgme_gpg_add_data,
_gpgme_gpg_set_colon_line_handler, free_argv, free_fd_data_map,
build_argv, _gpgme_gpg_spawn, read_status, read_colon_line):
Likewise.
* sign.c (_gpgme_release_sign_result): Likewise.
* signers.c (_gpgme_signers_add): Likewise.
* trustlist.c (trust_item_new, trustlist_colon_handler,
_gpgme_op_trustlist_event_cb, gpgme_op_trustlist_next,
gpgme_trustitem_release): Likewise.
* verify.c (_gpgme_release_verify_result, finish_sig): Likewise.
* version.c (gpgme_get_engine_info, _gpgme_get_program_version):
Likewise.
* w32-io.c (create_reader, create_writer, destroy_reader,
destroy_writer, build_commandline, _gpgme_io_spawn): Likewise.
* w32-sema.c (critsect_init, _gpgme_sema_cs_destroy): Likewise.
* w32-util.c (read_w32_registry_string): Likewise.
* wait.c (_gpgme_fd_table_deinit, _gpgme_fd_table_put,
_gpgme_wait_event_cb, _gpgme_add_io_cb, _gpgme_remove_io_cb)
* data-compat.c: Include <stdlib.h>.
2002-10-09 01:08:21 +00:00
|
|
|
|
free (arg_string);
|
2000-12-06 12:17:10 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
/* Make sure that the process has a connected stdin */
|
|
|
|
|
if ( !duped_stdin ) {
|
|
|
|
|
si.hStdInput = hnul;
|
2001-01-30 11:01:41 +00:00
|
|
|
|
DEBUG1 ("using %d for dummy stdin", (int)hnul );
|
2000-12-06 12:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
/* We normally don't want all the normal output */
|
|
|
|
|
if ( !duped_stderr ) {
|
2001-01-30 11:01:41 +00:00
|
|
|
|
si.hStdError = hnul;
|
|
|
|
|
DEBUG1 ("using %d for dummy stderr", (int)hnul );
|
2000-12-06 12:17:10 +00:00
|
|
|
|
}
|
2000-11-22 17:10:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-01-30 17:36:03 +00:00
|
|
|
|
DEBUG2 ("CreateProcess, path=`%s' args=`%s'", path, arg_string);
|
2000-12-06 12:17:10 +00:00
|
|
|
|
cr_flags |= CREATE_SUSPENDED;
|
2001-01-30 17:36:03 +00:00
|
|
|
|
if ( !CreateProcessA (path,
|
2000-11-22 17:10:48 +00:00
|
|
|
|
arg_string,
|
|
|
|
|
&sec_attr, /* process security attributes */
|
|
|
|
|
&sec_attr, /* thread security attributes */
|
|
|
|
|
TRUE, /* inherit handles */
|
|
|
|
|
cr_flags, /* creation flags */
|
|
|
|
|
envblock, /* environment */
|
|
|
|
|
NULL, /* use current drive/directory */
|
|
|
|
|
&si, /* startup information */
|
|
|
|
|
&pi /* returns process information */
|
|
|
|
|
) ) {
|
2001-01-30 11:01:41 +00:00
|
|
|
|
DEBUG1 ("CreateProcess failed: ec=%d\n", (int) GetLastError ());
|
2002-10-08 Marcus Brinkmann <marcus@g10code.de>
* util.h (_gpgme_malloc, _gpgme_realloc, _gpgme_calloc,
_gpgme_strdup, _gpgme_free): Remove prototypes.
(xtrymalloc, xtrycalloc, xtryrealloc, xtrystrdup, xfree): Remove
macros.
* util.c: File removed.
* Makefile.am (libgpgme_la_SOURCES): Remove util.h.
* conversion.c (_gpgme_decode_c_string): Use malloc instead of
xtrymalloc, realloc instead of xtryrealloc, calloc instead of
xtrycalloc, free instead of xfree.
(_gpgme_data_append_percentstring_for_xml): Likewise.
* data.c (_gpgme_data_new, _gpgme_data_release): Likewise.
* data-compat.c (gpgme_data_new_from_filepart): Likewise.
* data-mem.c (mem_write, mem_release, gpgme_data_new_from_mem,
_gpgme_data_get_as_string): Likewise.
* debug.c (debug_init): Likewise.
* decrypt.c (_gpgme_release_decrypt_result): Likewise.
* delete.c (_gpgme_release_delete_result): Likewise.
* edit.c (_gpgme_release_edit_result, _gpgme_op_edit_start):
Likewise.
* encrypt.c (_gpgme_release_encrypt_result): Likewise.
* engine.c (_gpgme_engine_get_info, _gpgme_engine_new,
_gpgme_engine_release): Likewise.
* engine-gpgsm.c (_gpgme_gpgsm_new, _gpgme_gpgsm_release,
_gpgme_gpgsm_op_decrypt, _gpgme_gpgsm_op_delete,
gpgsm_set_recipients, _gpgme_gpgsm_op_encrypt,
_gpgme_gpgsm_op_export, _gpgme_gpgsm_op_genkey,
_gpgme_gpgsm_op_import, _gpgme_gpgsm_op_keylist,
_gpgme_gpgsm_op_keylist_ext, _gpgme_gpgsm_op_sign,
_gpgme_gpgsm_op_verify, gpgsm_status_handler): Likewise.
* genkey.c (_gpgme_release_genkey_result): Likewise.
* gpgme.c (gpgme_new, gpgme_release): Likewise.
* import.c (_gpgme_release_import_result): Likewise.
* key.c (_gpgme_key_cache_init, _gpgme_key_cache_add, key_new,
add_subkey, gpgme_key_release, _gpgme_key_append_name): Likewise.
* keylist.c (_gpgme_release_keylist_result, keylist_colon_handler,
_gpgme_op_keylist_event_cb, gpgme_op_keylist_next): Likewise.
* ops.h (test_and_allocate_result): Likewise.
* passphrase.c (_gpgme_release_passphrase_result,
_gpgme_passphrase_status_handler,
_gpgme_passphrase_command_handler): Likewise.
* progress.c (_gpgme_progress_status_handler): Likewise.
* recipient.c (gpgme_recipients_new, gpgme_recipients_release,
gpgme_recipients_add_name_with_validity): Likewise.
* rungpg.c (_gpgme_gpg_new, _gpgme_gpg_release,
_gpgme_gpg_add_arg, _gpgme_gpg_add_data,
_gpgme_gpg_set_colon_line_handler, free_argv, free_fd_data_map,
build_argv, _gpgme_gpg_spawn, read_status, read_colon_line):
Likewise.
* sign.c (_gpgme_release_sign_result): Likewise.
* signers.c (_gpgme_signers_add): Likewise.
* trustlist.c (trust_item_new, trustlist_colon_handler,
_gpgme_op_trustlist_event_cb, gpgme_op_trustlist_next,
gpgme_trustitem_release): Likewise.
* verify.c (_gpgme_release_verify_result, finish_sig): Likewise.
* version.c (gpgme_get_engine_info, _gpgme_get_program_version):
Likewise.
* w32-io.c (create_reader, create_writer, destroy_reader,
destroy_writer, build_commandline, _gpgme_io_spawn): Likewise.
* w32-sema.c (critsect_init, _gpgme_sema_cs_destroy): Likewise.
* w32-util.c (read_w32_registry_string): Likewise.
* wait.c (_gpgme_fd_table_deinit, _gpgme_fd_table_put,
_gpgme_wait_event_cb, _gpgme_add_io_cb, _gpgme_remove_io_cb)
* data-compat.c: Include <stdlib.h>.
2002-10-09 01:08:21 +00:00
|
|
|
|
free (arg_string);
|
2000-11-22 17:10:48 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2005-09-23 13:29:04 +00:00
|
|
|
|
/* Close the /dev/nul handle if used. */
|
2000-12-06 12:17:10 +00:00
|
|
|
|
if (hnul != INVALID_HANDLE_VALUE ) {
|
|
|
|
|
if ( !CloseHandle ( hnul ) )
|
2001-01-30 11:01:41 +00:00
|
|
|
|
DEBUG1 ("CloseHandle(hnul) failed: ec=%d\n", (int)GetLastError());
|
2000-12-06 12:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-09-23 13:29:04 +00:00
|
|
|
|
/* Close the other ends of the pipes. */
|
2002-11-25 21:12:46 +00:00
|
|
|
|
for (i = 0; fd_parent_list[i].fd != -1; i++)
|
|
|
|
|
_gpgme_io_close (fd_parent_list[i].fd);
|
2000-11-22 17:10:48 +00:00
|
|
|
|
|
2001-01-30 11:01:41 +00:00
|
|
|
|
DEBUG4 ("CreateProcess ready\n"
|
|
|
|
|
"- hProcess=%p hThread=%p\n"
|
|
|
|
|
"- dwProcessID=%d dwThreadId=%d\n",
|
|
|
|
|
pi.hProcess, pi.hThread,
|
|
|
|
|
(int) pi.dwProcessId, (int) pi.dwThreadId);
|
2000-12-06 12:17:10 +00:00
|
|
|
|
|
|
|
|
|
if ( ResumeThread ( pi.hThread ) < 0 ) {
|
2001-01-30 11:01:41 +00:00
|
|
|
|
DEBUG1 ("ResumeThread failed: ec=%d\n", (int)GetLastError ());
|
2000-12-06 12:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !CloseHandle (pi.hThread) ) {
|
2001-01-30 11:01:41 +00:00
|
|
|
|
DEBUG1 ("CloseHandle of thread failed: ec=%d\n",
|
2000-12-06 12:17:10 +00:00
|
|
|
|
(int)GetLastError ());
|
|
|
|
|
}
|
2000-11-22 17:10:48 +00:00
|
|
|
|
|
|
|
|
|
return handle_to_pid (pi.hProcess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Select on the list of fds.
|
|
|
|
|
* Returns: -1 = error
|
|
|
|
|
* 0 = timeout or nothing to select
|
|
|
|
|
* >0 = number of signaled fds
|
|
|
|
|
*/
|
|
|
|
|
int
|
2002-07-28 Marcus Brinkmann <marcus@g10code.de>
* data.c (gpgme_data_read): For GPGME_DATA_TYPE_NONE, return EOF
instead an error.
The following changes make it possible to flush an inbound data
pipe before invoking a command handler:
* posix-io.c (_gpgme_io_select): Accept new argument NONBLOCK to
_gpgme_io_select. Set timeout of 0 if this is set.
* w32-io.c (_gpgme_io_select): Likewise.
* io.h: Add new argument NONBLOCK to _gpgme_io_select prototype.
* wait.c (do_select): Add new argument to _gpgme_io_select
invocation.
* rungpg.h (_gpgme_gpg_set_command_handler): Add new argument
linked_data to prototype.
* engine.h (_gpgme_engine_set_command_handler): Likewise.
* engine.c (_gpgme_engine_set_command_handler): Likewise.
* passphrase.c (_gpgme_passphrase_start): Pass NULL as linked_data
argument to _gpgme_engine_set_command_handler.
* rungpg.c (struct gpg_object_s): New members linked_data and
linked_idx in CMD.
(_gpgme_gpg_new): Initialize those new members.
(_gpgme_gpg_set_command_handler): Accept new argument linked_data.
(build_argv): Handle linked_data in the same hack as cb_data.
(read_status): If linked_data is in use, flush the pipe before
activating the command handler.
* gpgme.h: Add prototypes for gpgme_op_edit_start and
gpgme_op_edit.
The next changes export the status codes to the user:
* decrypt.c (_gpgme_decrypt_status_handler): Likewise, also prefix
all STATUS_ with GPGME_.
* delete.c (delete_status_handler): Likewise.
* decrypt-verify.c (decrypt_verify_status_handler): Likewise.
* encrypt.c (_gpgme_encrypt_status_handler): Likewise.
(_gpgme_encrypt_sym_status_handler): Likewise.
* encrypt-sign.c (encrypt_sign_status_handler): Likewise.
* engine-gpgsm.c (parse_status): Likewise.
(gpgsm_status_handler): Likewise.
(gpgsm_set_recipients): Likewise.
* export.c (export_status_handler): Likewise.
* genkey.c (genkey_status_handler): Likewise.
* import.c (append_xml_impinfo): Likewise.
(import_status_handler): Likewise.
* keylist.c (keylist_status_handler): Likewise.
* passphrase.c (_gpgme_passphrase_status_handler): Likewise.
(command_handler): Likewise.
* progress.c (_gpgme_progress_status_handler): Likewise.
* sign.c (_gpgme_sign_status_handler): Likewise.
* trustlist.c (trustlist_status_handler): Likewise.
* verify.c (_gpgme_verify_status_handler): Likewise.
* gpgme.h (GpgmeEditCb): New type.
* rungpg.h (GpgStatusCode): Rename and move to ...
* gpgme.h (GpgmeStatusCode): ... this and here.
* Makefile.am (status-table.h): Run mkstatus on gpgme.h, not rungpg.h.
* mkstatus: Prefix STATUS with GPGME_.
* rungpg.h (GpgStatusHandler, GpgCommandHandler): Change type
accordingly.
* ops.h (_gpgme_verify_status_handler,
_gpgme_decrypt_status_handler, _gpgme_sign_status_handler,
_gpgme_encrypt_status_handler, _gpgme_passphrase_status_handler,
_gpgme_progress_status_handler): Likewise.
* rungpg.c (struct gpg_object_s): Likewise for CMD.code.
These changes add an edit operation to GPGME:
* context.h (struct gpgme_context_s): New member RESULT.edit. *
ops.h: Add prototype for _gpgme_release_edit_result and
_gpgme_passphrase_command_handler.
* passphrase.c (command_handler): Make non-static and rename to ...
(_gpgme_passphrase_command_handler): ... this.
(_gpgme_passphrase_start): Use new name for command handler.
* types.h: Add EditResult type.
* gpgme.c (_gpgme_release_result): Release EDIT result.
* edit.c: New file.
* Makefile.am (libgpgme_la_SOURCES): Add edit.c.
(libgpgme_la_LDADD): Rename to libgpgme_la_LIBADD, and include
assuan_libobjs.
(assuan_libobjs): New variable, set this instead
libgpgme_la_LIBADD.
* engine.h (_gpgme_engine_op_edit): New prototype.
* engine.c (_gpgme_engine_op_edit): New function.
* rungpg.h (_gpgme_gpg_op_edit): New prototype.
* rungpg.c (_gpgme_gpg_op_edit): New function.
2002-07-28 18:41:02 +00:00
|
|
|
|
_gpgme_io_select ( struct io_select_fd_s *fds, size_t nfds, int nonblock )
|
2000-11-22 17:10:48 +00:00
|
|
|
|
{
|
2000-11-23 15:28:15 +00:00
|
|
|
|
HANDLE waitbuf[MAXIMUM_WAIT_OBJECTS];
|
2001-01-31 12:39:53 +00:00
|
|
|
|
int waitidx[MAXIMUM_WAIT_OBJECTS];
|
2000-11-23 15:28:15 +00:00
|
|
|
|
int code, nwait;
|
2001-02-28 10:18:38 +00:00
|
|
|
|
int i, any;
|
2000-12-06 12:17:10 +00:00
|
|
|
|
int count;
|
2001-01-30 11:01:41 +00:00
|
|
|
|
void *dbg_help;
|
2000-11-23 15:28:15 +00:00
|
|
|
|
|
2000-12-06 12:17:10 +00:00
|
|
|
|
restart:
|
2003-01-19 22:05:40 +00:00
|
|
|
|
DEBUG_BEGIN (dbg_help, 3, "select on [ ");
|
2001-02-28 10:18:38 +00:00
|
|
|
|
any = 0;
|
2000-11-23 15:28:15 +00:00
|
|
|
|
nwait = 0;
|
2001-02-20 13:31:56 +00:00
|
|
|
|
count = 0;
|
2000-11-23 15:28:15 +00:00
|
|
|
|
for ( i=0; i < nfds; i++ ) {
|
|
|
|
|
if ( fds[i].fd == -1 )
|
|
|
|
|
continue;
|
2001-02-20 13:31:56 +00:00
|
|
|
|
fds[i].signaled = 0;
|
2001-01-31 12:39:53 +00:00
|
|
|
|
if ( fds[i].for_read || fds[i].for_write ) {
|
2001-02-20 13:31:56 +00:00
|
|
|
|
if ( fds[i].frozen ) {
|
|
|
|
|
DEBUG_ADD1 (dbg_help, "f%d ", fds[i].fd );
|
|
|
|
|
}
|
|
|
|
|
else if ( fds[i].for_read ) {
|
2001-01-31 12:39:53 +00:00
|
|
|
|
struct reader_context_s *c = find_reader (fds[i].fd,1);
|
|
|
|
|
|
|
|
|
|
if (!c) {
|
|
|
|
|
DEBUG1 ("oops: no reader thread for fd %d", fds[i].fd);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if ( nwait >= DIM (waitbuf) ) {
|
|
|
|
|
DEBUG_END (dbg_help, "oops ]");
|
|
|
|
|
DEBUG0 ("Too many objects for WFMO!" );
|
|
|
|
|
return -1;
|
2001-01-30 11:01:41 +00:00
|
|
|
|
}
|
2001-01-31 12:39:53 +00:00
|
|
|
|
waitidx[nwait] = i;
|
|
|
|
|
waitbuf[nwait++] = c->have_data_ev;
|
2001-01-30 11:01:41 +00:00
|
|
|
|
}
|
2001-02-20 13:31:56 +00:00
|
|
|
|
DEBUG_ADD1 (dbg_help, "r%d ", fds[i].fd );
|
|
|
|
|
any = 1;
|
|
|
|
|
}
|
|
|
|
|
else if ( fds[i].for_write ) {
|
2001-02-28 10:18:38 +00:00
|
|
|
|
struct writer_context_s *c = find_writer (fds[i].fd,1);
|
|
|
|
|
|
|
|
|
|
if (!c) {
|
|
|
|
|
DEBUG1 ("oops: no writer thread for fd %d", fds[i].fd);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if ( nwait >= DIM (waitbuf) ) {
|
|
|
|
|
DEBUG_END (dbg_help, "oops ]");
|
|
|
|
|
DEBUG0 ("Too many objects for WFMO!" );
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2006-02-15 13:30:08 +00:00
|
|
|
|
waitidx[nwait] = i;
|
|
|
|
|
waitbuf[nwait++] = c->is_empty;
|
2001-02-28 10:18:38 +00:00
|
|
|
|
}
|
2006-02-15 13:30:08 +00:00
|
|
|
|
DEBUG_ADD1 (dbg_help, "w%d ", fds[i].fd );
|
|
|
|
|
any = 1;
|
2000-11-23 15:28:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-01-30 11:01:41 +00:00
|
|
|
|
DEBUG_END (dbg_help, "]");
|
2000-12-06 12:17:10 +00:00
|
|
|
|
if (!any)
|
2000-11-23 15:28:15 +00:00
|
|
|
|
return 0;
|
|
|
|
|
|
2002-07-28 Marcus Brinkmann <marcus@g10code.de>
* data.c (gpgme_data_read): For GPGME_DATA_TYPE_NONE, return EOF
instead an error.
The following changes make it possible to flush an inbound data
pipe before invoking a command handler:
* posix-io.c (_gpgme_io_select): Accept new argument NONBLOCK to
_gpgme_io_select. Set timeout of 0 if this is set.
* w32-io.c (_gpgme_io_select): Likewise.
* io.h: Add new argument NONBLOCK to _gpgme_io_select prototype.
* wait.c (do_select): Add new argument to _gpgme_io_select
invocation.
* rungpg.h (_gpgme_gpg_set_command_handler): Add new argument
linked_data to prototype.
* engine.h (_gpgme_engine_set_command_handler): Likewise.
* engine.c (_gpgme_engine_set_command_handler): Likewise.
* passphrase.c (_gpgme_passphrase_start): Pass NULL as linked_data
argument to _gpgme_engine_set_command_handler.
* rungpg.c (struct gpg_object_s): New members linked_data and
linked_idx in CMD.
(_gpgme_gpg_new): Initialize those new members.
(_gpgme_gpg_set_command_handler): Accept new argument linked_data.
(build_argv): Handle linked_data in the same hack as cb_data.
(read_status): If linked_data is in use, flush the pipe before
activating the command handler.
* gpgme.h: Add prototypes for gpgme_op_edit_start and
gpgme_op_edit.
The next changes export the status codes to the user:
* decrypt.c (_gpgme_decrypt_status_handler): Likewise, also prefix
all STATUS_ with GPGME_.
* delete.c (delete_status_handler): Likewise.
* decrypt-verify.c (decrypt_verify_status_handler): Likewise.
* encrypt.c (_gpgme_encrypt_status_handler): Likewise.
(_gpgme_encrypt_sym_status_handler): Likewise.
* encrypt-sign.c (encrypt_sign_status_handler): Likewise.
* engine-gpgsm.c (parse_status): Likewise.
(gpgsm_status_handler): Likewise.
(gpgsm_set_recipients): Likewise.
* export.c (export_status_handler): Likewise.
* genkey.c (genkey_status_handler): Likewise.
* import.c (append_xml_impinfo): Likewise.
(import_status_handler): Likewise.
* keylist.c (keylist_status_handler): Likewise.
* passphrase.c (_gpgme_passphrase_status_handler): Likewise.
(command_handler): Likewise.
* progress.c (_gpgme_progress_status_handler): Likewise.
* sign.c (_gpgme_sign_status_handler): Likewise.
* trustlist.c (trustlist_status_handler): Likewise.
* verify.c (_gpgme_verify_status_handler): Likewise.
* gpgme.h (GpgmeEditCb): New type.
* rungpg.h (GpgStatusCode): Rename and move to ...
* gpgme.h (GpgmeStatusCode): ... this and here.
* Makefile.am (status-table.h): Run mkstatus on gpgme.h, not rungpg.h.
* mkstatus: Prefix STATUS with GPGME_.
* rungpg.h (GpgStatusHandler, GpgCommandHandler): Change type
accordingly.
* ops.h (_gpgme_verify_status_handler,
_gpgme_decrypt_status_handler, _gpgme_sign_status_handler,
_gpgme_encrypt_status_handler, _gpgme_passphrase_status_handler,
_gpgme_progress_status_handler): Likewise.
* rungpg.c (struct gpg_object_s): Likewise for CMD.code.
These changes add an edit operation to GPGME:
* context.h (struct gpgme_context_s): New member RESULT.edit. *
ops.h: Add prototype for _gpgme_release_edit_result and
_gpgme_passphrase_command_handler.
* passphrase.c (command_handler): Make non-static and rename to ...
(_gpgme_passphrase_command_handler): ... this.
(_gpgme_passphrase_start): Use new name for command handler.
* types.h: Add EditResult type.
* gpgme.c (_gpgme_release_result): Release EDIT result.
* edit.c: New file.
* Makefile.am (libgpgme_la_SOURCES): Add edit.c.
(libgpgme_la_LDADD): Rename to libgpgme_la_LIBADD, and include
assuan_libobjs.
(assuan_libobjs): New variable, set this instead
libgpgme_la_LIBADD.
* engine.h (_gpgme_engine_op_edit): New prototype.
* engine.c (_gpgme_engine_op_edit): New function.
* rungpg.h (_gpgme_gpg_op_edit): New prototype.
* rungpg.c (_gpgme_gpg_op_edit): New function.
2002-07-28 18:41:02 +00:00
|
|
|
|
code = WaitForMultipleObjects ( nwait, waitbuf, 0, nonblock ? 0 : 1000);
|
2001-01-30 11:01:41 +00:00
|
|
|
|
if ( code >= WAIT_OBJECT_0 && code < WAIT_OBJECT_0 + nwait ) {
|
2000-11-23 15:28:15 +00:00
|
|
|
|
/* This WFMO is a really silly function: It does return either
|
|
|
|
|
* the index of the signaled object or if 2 objects have been
|
|
|
|
|
* signalled at the same time, the index of the object with the
|
|
|
|
|
* lowest object is returned - so and how do we find out
|
|
|
|
|
* how many objects have been signaled???.
|
|
|
|
|
* The only solution I can imagine is to test each object starting
|
|
|
|
|
* with the returned index individually - how dull.
|
|
|
|
|
*/
|
|
|
|
|
any = 0;
|
|
|
|
|
for (i=code - WAIT_OBJECT_0; i < nwait; i++ ) {
|
2005-03-09 11:47:21 +00:00
|
|
|
|
if (WaitForSingleObject (waitbuf[i], 0) == WAIT_OBJECT_0) {
|
2001-01-31 12:39:53 +00:00
|
|
|
|
assert (waitidx[i] >=0 && waitidx[i] < nfds);
|
|
|
|
|
fds[waitidx[i]].signaled = 1;
|
2000-11-23 15:28:15 +00:00
|
|
|
|
any = 1;
|
2000-12-06 12:17:10 +00:00
|
|
|
|
count++;
|
2000-11-23 15:28:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2000-12-06 12:17:10 +00:00
|
|
|
|
if (!any) {
|
2001-01-30 11:01:41 +00:00
|
|
|
|
DEBUG0 ("Oops: No signaled objects found after WFMO");
|
2000-12-06 12:17:10 +00:00
|
|
|
|
count = -1;
|
2000-11-23 15:28:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-01-30 11:01:41 +00:00
|
|
|
|
else if ( code == WAIT_TIMEOUT ) {
|
|
|
|
|
DEBUG0 ("WFMO timed out\n" );
|
|
|
|
|
}
|
|
|
|
|
else if (code == WAIT_FAILED ) {
|
|
|
|
|
int le = (int)GetLastError ();
|
|
|
|
|
if ( le == ERROR_INVALID_HANDLE ) {
|
|
|
|
|
int k, j = handle_to_fd (waitbuf[i]);
|
|
|
|
|
|
|
|
|
|
DEBUG1 ("WFMO invalid handle %d removed\n", j);
|
2005-05-11 12:48:55 +00:00
|
|
|
|
for (k=0 ; k < nfds; k++ ) {
|
2001-01-30 11:01:41 +00:00
|
|
|
|
if ( fds[k].fd == j ) {
|
|
|
|
|
fds[k].for_read = fds[k].for_write = 0;
|
|
|
|
|
goto restart;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
DEBUG0 (" oops, or not???\n");
|
|
|
|
|
}
|
|
|
|
|
DEBUG1 ("WFMO failed: %d\n", le );
|
|
|
|
|
count = -1;
|
|
|
|
|
}
|
2000-11-23 15:28:15 +00:00
|
|
|
|
else {
|
2001-01-30 11:01:41 +00:00
|
|
|
|
DEBUG1 ("WFMO returned %d\n", code );
|
2000-12-06 12:17:10 +00:00
|
|
|
|
count = -1;
|
2000-11-23 15:28:15 +00:00
|
|
|
|
}
|
2000-11-22 17:10:48 +00:00
|
|
|
|
|
2001-01-31 12:39:53 +00:00
|
|
|
|
if ( count ) {
|
2003-01-19 22:05:40 +00:00
|
|
|
|
DEBUG_BEGIN (dbg_help, 3, " signaled [ ");
|
2001-01-31 12:39:53 +00:00
|
|
|
|
for ( i=0; i < nfds; i++ ) {
|
|
|
|
|
if ( fds[i].fd == -1 )
|
|
|
|
|
continue;
|
|
|
|
|
if ( (fds[i].for_read || fds[i].for_write) && fds[i].signaled ) {
|
|
|
|
|
DEBUG_ADD2 (dbg_help, "%c%d ",
|
|
|
|
|
fds[i].for_read? 'r':'w',fds[i].fd );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
DEBUG_END (dbg_help, "]");
|
|
|
|
|
}
|
|
|
|
|
|
2000-12-06 12:17:10 +00:00
|
|
|
|
return count;
|
2000-11-23 15:28:15 +00:00
|
|
|
|
}
|
2005-03-09 11:47:21 +00:00
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
_gpgme_io_subsystem_init (void)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2005-11-18 14:00:50 +00:00
|
|
|
|
|
|
|
|
|
/* Write the printable version of FD to the buffer BUF of length
|
|
|
|
|
BUFLEN. The printable version is the representation on the command
|
|
|
|
|
line that the child process expects. */
|
|
|
|
|
int
|
|
|
|
|
_gpgme_io_fd2str (char *buf, int buflen, int fd)
|
|
|
|
|
{
|
|
|
|
|
return snprintf (buf, buflen, "%d", fd);
|
|
|
|
|
}
|
|
|
|
|
|
2005-11-17 18:45:14 +00:00
|
|
|
|
|
|
|
|
|
/* The following interface is only useful for GPGME Glib. */
|
|
|
|
|
|
|
|
|
|
/* Look up the giochannel for file descriptor FD. */
|
|
|
|
|
void *
|
|
|
|
|
gpgme_get_giochannel (int fd)
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2005-03-09 11:47:21 +00:00
|
|
|
|
|