[svn] assuan - r275 - in trunk: . src
svn author wk
cvs at cvs.gnupg.org
Mon Oct 8 20:03:48 CEST 2007
Author: wk
Date: 2007-10-08 20:03:38 +0200 (Mon, 08 Oct 2007)
New Revision: 275
Modified:
trunk/NEWS
trunk/src/ChangeLog
trunk/src/assuan-defs.h
trunk/src/assuan-io-pth.c
trunk/src/assuan-io.c
trunk/src/assuan-util.c
trunk/src/assuan.h
Log:
Add assuan_set_io_hooks.
Modified: trunk/NEWS
===================================================================
--- trunk/NEWS 2007-10-05 16:55:51 UTC (rev 274)
+++ trunk/NEWS 2007-10-08 18:03:38 UTC (rev 275)
@@ -1,10 +1,12 @@
Noteworthy changes in version 1.0.4
------------------------------------------------
- * New socket wrapper fucntions to support Unix domain sockets under
+ * New socket wrapper functions to support Unix domain sockets under
Windows.
+ * New hook feature to enhance the internal I/O functions.
+
Noteworthy changes in version 1.0.3 (2007-08-24)
------------------------------------------------
Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog 2007-10-05 16:55:51 UTC (rev 274)
+++ trunk/src/ChangeLog 2007-10-08 18:03:38 UTC (rev 275)
@@ -1,3 +1,16 @@
+2007-10-08 Werner Koch <wk at g10code.com>
+
+ * assuan-util.c (assuan_set_io_hooks): New.
+ * assuan.h (struct assuan_io_hooks): New.
+ (assuan_set_io_hooks, _assuan_io_hooks): Add prefix macros.
+ * assuan-defs.h (_assuan_io_hooks): New.
+ * assuan-io.c (do_io_read): Take all code from _assuan_io_read.
+ (_assuan_io_read, _assuan_simple_read): Add hook feature.
+ (do_io_write): Take all code from _assuan_io_write.
+ (_assuan_io_write, _assuan_simple_write): Add hook feature.
+ * assuan-io-pth.c (_assuan_simple_read, _assuan_simple_write)
+ (_assuan_io_read, _assuan_io_write): Add hook feature.
+
2007-10-05 Marcus Brinkmann <marcus at g10code.de>
* assuan.h (_assuan_error_is_eagain): Add prefix macro.
Modified: trunk/src/assuan-defs.h
===================================================================
--- trunk/src/assuan-defs.h 2007-10-05 16:55:51 UTC (rev 274)
+++ trunk/src/assuan-defs.h 2007-10-08 18:03:38 UTC (rev 275)
@@ -75,6 +75,10 @@
};
+/* The global variable with the optional hook fucntions. */
+extern struct assuan_io_hooks _assuan_io_hooks;
+
+
/* The context we use with most functions. */
struct assuan_context_s
{
Modified: trunk/src/assuan-io-pth.c
===================================================================
--- trunk/src/assuan-io-pth.c 2007-10-05 16:55:51 UTC (rev 274)
+++ trunk/src/assuan-io-pth.c 2007-10-08 18:03:38 UTC (rev 275)
@@ -1,5 +1,5 @@
/* assuan-io-pth.c - Pth version of assua-io.c.
- * Copyright (C) 2002, 2004, 2006 Free Software Foundation, Inc.
+ * Copyright (C) 2002, 2004, 2006, 2007 Free Software Foundation, Inc.
*
* This file is part of Assuan.
*
@@ -56,24 +56,47 @@
{
/* Fixme: For W32 we should better not cast the HANDLE type to int.
However, this requires changes in w32pth too. */
+ ssize_t retval;
+
+ if (_assuan_io_hooks.read_hook
+ && _assuan_io_hooks.read_hook (ctx, ctx->inbound.fd,
+ buffer, size, &retval) == 1)
+ return retval;
+
return _assuan_io_read (ctx->inbound.fd, buffer, size);
}
ssize_t
_assuan_simple_write (assuan_context_t ctx, const void *buffer, size_t size)
{
+ ssize_t retval;
+
+ if (_assuan_io_hooks.write_hook
+ && _assuan_io_hooks.write_hook (ctx, ctx->outbound.fd,
+ buffer, size, &retval) == 1)
+ return retval;
return _assuan_io_write (ctx->outbound.fd, buffer, size);
}
ssize_t
_assuan_io_read (assuan_fd_t fd, void *buffer, size_t size)
{
+ ssize_t retval;
+
+ if (_assuan_io_hooks.read_hook
+ && _assuan_io_hooks.read_hook (NULL, fd, buffer, size, &retval) == 1)
+ return retval;
return pth_read ((int)fd, buffer, size);
}
ssize_t
_assuan_io_write (assuan_fd_t fd, const void *buffer, size_t size)
{
+ ssize_t retval;
+
+ if (_assuan_io_hooks.write_hook
+ && _assuan_io_hooks.write_hook (NULL, fd, buffer, size, &retval) == 1)
+ return retval;
return pth_write ((int)fd, buffer, size);
}
Modified: trunk/src/assuan-io.c
===================================================================
--- trunk/src/assuan-io.c 2007-10-05 16:55:51 UTC (rev 274)
+++ trunk/src/assuan-io.c 2007-10-08 18:03:38 UTC (rev 275)
@@ -1,5 +1,5 @@
/* assuan-io.c - Wraps the read and write functions.
- * Copyright (C) 2002, 2004, 2006 Free Software Foundation, Inc.
+ * Copyright (C) 2002, 2004, 2006, 2007 Free Software Foundation, Inc.
*
* This file is part of Assuan.
*
@@ -46,8 +46,8 @@
#endif
-ssize_t
-_assuan_io_read (assuan_fd_t fd, void *buffer, size_t size)
+static ssize_t
+do_io_read (assuan_fd_t fd, void *buffer, size_t size)
{
#ifdef HAVE_W32_SYSTEM
/* Due to the peculiarities of the W32 API we can't use read for a
@@ -92,14 +92,34 @@
ssize_t
+_assuan_io_read (assuan_fd_t fd, void *buffer, size_t size)
+{
+ ssize_t retval;
+
+ if (_assuan_io_hooks.read_hook
+ && _assuan_io_hooks.read_hook (NULL, fd, buffer, size, &retval) == 1)
+ return retval;
+
+ return do_io_read (fd, buffer, size);
+}
+
+ssize_t
_assuan_simple_read (assuan_context_t ctx, void *buffer, size_t size)
{
- return _assuan_io_read (ctx->inbound.fd, buffer, size);
+ ssize_t retval;
+
+ if (_assuan_io_hooks.read_hook
+ && _assuan_io_hooks.read_hook (ctx, ctx->inbound.fd,
+ buffer, size, &retval) == 1)
+ return retval;
+
+ return do_io_read (ctx->inbound.fd, buffer, size);
}
-ssize_t
-_assuan_io_write (assuan_fd_t fd, const void *buffer, size_t size)
+
+static ssize_t
+do_io_write (assuan_fd_t fd, const void *buffer, size_t size)
{
#ifdef HAVE_W32_SYSTEM
/* Due to the peculiarities of the W32 API we can't use write for a
@@ -132,11 +152,28 @@
#endif /*!HAVE_W32_SYSTEM*/
}
+ssize_t
+_assuan_io_write (assuan_fd_t fd, const void *buffer, size_t size)
+{
+ ssize_t retval;
+
+ if (_assuan_io_hooks.write_hook
+ && _assuan_io_hooks.write_hook (NULL, fd, buffer, size, &retval) == 1)
+ return retval;
+ return do_io_write (fd, buffer, size);
+}
ssize_t
_assuan_simple_write (assuan_context_t ctx, const void *buffer, size_t size)
{
- return _assuan_io_write (ctx->outbound.fd, buffer, size);
+ ssize_t retval;
+
+ if (_assuan_io_hooks.write_hook
+ && _assuan_io_hooks.write_hook (ctx, ctx->outbound.fd,
+ buffer, size, &retval) == 1)
+ return retval;
+
+ return do_io_write (ctx->outbound.fd, buffer, size);
}
Modified: trunk/src/assuan-util.c
===================================================================
--- trunk/src/assuan-util.c 2007-10-05 16:55:51 UTC (rev 274)
+++ trunk/src/assuan-util.c 2007-10-08 18:03:38 UTC (rev 275)
@@ -30,6 +30,10 @@
static void *(*realloc_func)(void *p, size_t n) = realloc;
static void (*free_func)(void*) = free;
+struct assuan_io_hooks _assuan_io_hooks;
+
+
+
void
assuan_set_malloc_hooks ( void *(*new_alloc_func)(size_t n),
void *(*new_realloc_func)(void *p, size_t n),
@@ -40,6 +44,20 @@
free_func = new_free_func;
}
+
+void
+assuan_set_io_hooks (assuan_io_hooks_t io_hooks)
+{
+ _assuan_io_hooks.read_hook = NULL;
+ _assuan_io_hooks.write_hook = NULL;
+ if (io_hooks)
+ {
+ _assuan_io_hooks.read_hook = io_hooks->read_hook;
+ _assuan_io_hooks.write_hook = io_hooks->write_hook;
+ }
+}
+
+
void *
_assuan_malloc (size_t n)
{
@@ -168,4 +186,3 @@
return 0;
}
-
Modified: trunk/src/assuan.h
===================================================================
--- trunk/src/assuan.h 2007-10-05 16:55:51 UTC (rev 274)
+++ trunk/src/assuan.h 2007-10-08 18:03:38 UTC (rev 275)
@@ -121,6 +121,7 @@
#define assuan_sendfd _ASSUAN_PREFIX(assuan_sendfd)
#define assuan_receivefd _ASSUAN_PREFIX(assuan_receivefd)
#define assuan_set_malloc_hooks _ASSUAN_PREFIX(assuan_set_malloc_hooks)
+#define assuan_set_io_hooks _ASSUAN_PREFIX(assuan_set_io_hooks)
#define assuan_set_log_stream _ASSUAN_PREFIX(assuan_set_log_stream)
#define assuan_set_error _ASSUAN_PREFIX(assuan_set_error)
#define assuan_set_pointer _ASSUAN_PREFIX(assuan_set_pointer)
@@ -162,6 +163,7 @@
#define _assuan_simple_write _ASSUAN_PREFIX(_assuan_simple_write)
#define _assuan_io_read _ASSUAN_PREFIX(_assuan_io_read)
#define _assuan_io_write _ASSUAN_PREFIX(_assuan_io_write)
+#define _assuan_io_hooks _ASSUAN_PREFIX(_assuan_io_hooks)
#define _assuan_new_context _ASSUAN_PREFIX(_assuan_new_context)
#define _assuan_release_context _ASSUAN_PREFIX(_assuan_release_context)
#define _assuan_malloc _ASSUAN_PREFIX(_assuan_malloc)
@@ -420,6 +422,18 @@
#endif
+/* Definition of hook functions used to conditionally replace the
+ default I/O functions. */
+struct assuan_io_hooks
+{
+ int (*read_hook)(assuan_context_t, assuan_fd_t, void *, size_t, ssize_t *);
+ int (*write_hook)(assuan_context_t, assuan_fd_t fd,
+ const void *, size_t, ssize_t *);
+};
+typedef struct assuan_io_hooks *assuan_io_hooks_t;
+
+
+
/*-- assuan-handler.c --*/
int assuan_register_command (assuan_context_t ctx,
const char *cmd_string,
@@ -560,6 +574,7 @@
void assuan_set_malloc_hooks ( void *(*new_alloc_func)(size_t n),
void *(*new_realloc_func)(void *p, size_t n),
void (*new_free_func)(void*) );
+void assuan_set_io_hooks (assuan_io_hooks_t io_hooks);
void assuan_set_log_stream (assuan_context_t ctx, FILE *fp);
int assuan_set_error (assuan_context_t ctx, int err, const char *text);
void assuan_set_pointer (assuan_context_t ctx, void *pointer);
More information about the Gnupg-commits
mailing list