summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Brinkmann <mb@g10code.com>2010-06-10 17:27:24 +0000
committerMarcus Brinkmann <mb@g10code.com>2010-06-10 17:27:24 +0000
commit9ab3e9b9854863b897be3c2eb684f5a73c8a9a1b (patch)
tree97ec36e1b822194fe1d41a962a7dc94acf348e5a
parent64360f7f70d783da90945f68674f23614683d39a (diff)
downloadlibassuan-9ab3e9b9854863b897be3c2eb684f5a73c8a9a1b.tar.gz
2010-06-10 Marcus Brinkmann <marcus@g10code.de>
* w32ce-add.h (ASSUAN_STDIN, ASSUAN_STDOUT): Define magic handle values. * system-w32ce.c (__assuan_read, __assuan_write): Handle magic handle values differently. * system-w32ce.c (_assuan_w32ce_finish_pipe): Return error on RVID 0.
-rw-r--r--src/ChangeLog8
-rw-r--r--src/system-w32ce.c37
-rw-r--r--src/w32ce-add.h5
3 files changed, 50 insertions, 0 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index dc20d24..f78ac81 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,11 @@
+2010-06-10 Marcus Brinkmann <marcus@g10code.de>
+
+ * w32ce-add.h (ASSUAN_STDIN, ASSUAN_STDOUT): Define magic handle values.
+ * system-w32ce.c (__assuan_read, __assuan_write): Handle magic
+ handle values differently.
+
+ * system-w32ce.c (_assuan_w32ce_finish_pipe): Return error on RVID 0.
+
2010-06-09 Marcus Brinkmann <marcus@g10code.de>
* gpgcedev.c (GPGCEDEV_IOCTL_UNBLOCK): New ioctl.
diff --git a/src/system-w32ce.c b/src/system-w32ce.c
index fb098da..a95fbf3 100644
--- a/src/system-w32ce.c
+++ b/src/system-w32ce.c
@@ -158,6 +158,9 @@ _assuan_w32ce_finish_pipe (int rvid, int write_end)
{
HANDLE hd;
+ if (!rvid)
+ return INVALID_HANDLE_VALUE;
+
hd = CreateFile (L"GPG1:", write_end? GENERIC_WRITE : GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL);
@@ -281,6 +284,28 @@ __assuan_read (assuan_context_t ctx, assuan_fd_t fd, void *buffer, size_t size)
TRACE_BEG3 (ctx, ASSUAN_LOG_SYSIO, "__assuan_read", ctx,
"fd=0x%x, buffer=%p, size=%i", fd, buffer, size);
+#ifdef HAVE_W32CE_SYSTEM
+ /* This is a bit of a hack to support stdin over ssh. Note that
+ fread buffers fully while getchar is line buffered. Weird, but
+ that's the way it is. ASSUAN_STDIN and ASSUAN_STDOUT are
+ special handle values that shouldn't occur in the wild. */
+ if (fd == ASSUAN_STDIN)
+ {
+ int i = 0;
+ int chr;
+ while (i < size)
+ {
+ chr = getchar();
+ if (chr == EOF)
+ break;
+ ((char*)buffer)[i++] = (char) chr;
+ if (chr == '\n')
+ break;
+ }
+ return TRACE_SYSRES (i);
+ }
+#endif
+
res = recv (HANDLE2SOCKET (fd), buffer, size, 0);
if (res == -1)
{
@@ -346,6 +371,18 @@ __assuan_write (assuan_context_t ctx, assuan_fd_t fd, const void *buffer,
TRACE_BEG3 (ctx, ASSUAN_LOG_SYSIO, "__assuan_write", ctx,
"fd=0x%x, buffer=%p, size=%i", fd, buffer, size);
+#ifdef HAVE_W32CE_SYSTEM
+ /* This is a bit of a hack to support stdout over ssh. Note that
+ fread buffers fully while getchar is line buffered. Weird, but
+ that's the way it is. ASSUAN_STDIN and ASSUAN_STDOUT are
+ special handle values that shouldn't occur in the wild. */
+ if (fd == ASSUAN_STDOUT)
+ {
+ res = fwrite (buffer, 1, size, stdout);
+ return TRACE_SYSRES (res);
+ }
+#endif
+
res = send ((int)fd, buffer, size, 0);
if (res == -1 && WSAGetLastError () == WSAENOTSOCK)
{
diff --git a/src/w32ce-add.h b/src/w32ce-add.h
index 76ce141..5306f9a 100644
--- a/src/w32ce-add.h
+++ b/src/w32ce-add.h
@@ -26,3 +26,8 @@ DWORD _assuan_w32ce_create_pipe (HANDLE *read_hd, HANDLE *write_hd,
LPSECURITY_ATTRIBUTES sec_attr, DWORD size);
#define CreatePipe(a,b,c,d) _assuan_w32ce_create_pipe ((a),(b),(c),(d))
+/* Magic handle values. Let's hope those never occur legitimately as
+ handles or sockets. (Sockets are numbered sequentially from 0,
+ while handles seem aligned to wordsize. */
+#define ASSUAN_STDIN (void*)0x7ffffffd
+#define ASSUAN_STDOUT (void*)0x7fffffff