[svn] assuan - r225 - in trunk: . doc src
svn author wk
cvs at cvs.gnupg.org
Tue Nov 14 17:56:09 CET 2006
Author: wk
Date: 2006-11-14 17:56:07 +0100 (Tue, 14 Nov 2006)
New Revision: 225
Modified:
trunk/NEWS
trunk/doc/assuan.texi
trunk/src/ChangeLog
trunk/src/assuan-buffer.c
trunk/src/assuan-defs.h
trunk/src/assuan-handler.c
trunk/src/assuan-util.c
trunk/src/assuan.h
trunk/src/libassuan.m4
Log:
New functions assuan_set_io_monitor and assuan_register_post_cmd_notify
Modified: trunk/NEWS
===================================================================
--- trunk/NEWS 2006-10-31 20:10:36 UTC (rev 224)
+++ trunk/NEWS 2006-11-14 16:56:07 UTC (rev 225)
@@ -1,7 +1,11 @@
Noteworthy changes in version 1.0.1
------------------------------------------------
+ * New function: assuan_set_io_monitor.
+ * New function: assuan_register_post_cmd_notify.
+
+
Noteworthy changes in version 1.0.0 (2006-10-31)
------------------------------------------------
Modified: trunk/doc/assuan.texi
===================================================================
--- trunk/doc/assuan.texi 2006-10-31 20:10:36 UTC (rev 224)
+++ trunk/doc/assuan.texi 2006-11-14 16:56:07 UTC (rev 225)
@@ -943,6 +943,14 @@
these commands.
@end deftypefun
+ at deftypefun assuan_error_t assuan_register_post_cmd_notify (@w{assuan_context_t @var{ctx}}, @w{void (*@var{fnc})(assuan_context_t)}, @w{int @var{err}})
+
+Register a function to be called right after a command has been
+processed. @var{err} is the result code from the last internal assuan
+operation and not the one returned by the handler. It may be used to
+command related cleanup.
+ at end deftypefun
+
@deftypefun assuan_error_t assuan_register_bye_notify (@w{assuan_context_t @var{ctx}}, @w{void (*@var{fnc})(assuan_context_t)})
Register function @var{fnc} with context @var{ctx} to be called right
@@ -1320,7 +1328,17 @@
I/O.
@end deftypefun
+ at deftypefun void assuan_set_io_monitor (@w{assuan_context_t @var{ctx}}, @w{unsigned int} (*@var{monitor})(@w{assuan_context_t @var{ctx}}, @w{int @var{direction}}, @w{const char *@var{line}}, @w{size_t @var{linelen}}))
+This function registers an I/O monitor for the context @var{ctx}. Such
+a monitor function is called right after a line has been received or
+just before it is send. With @var{direction} set to 1 the monitor has
+been called for an output operation; 0 obviosuly means it has been
+called for an input operation. If the monitor sets bit 0 in the return
+value, any active logging of the line will be suppressed. With bit 1
+set, the entire line will be ignored.
+ at end deftypefun
+
@deftypefun void assuan_begin_confidential (@w{assuan_context_t @var{ctx}})
Put the logging feature into confidential mode. This is to avoid
Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog 2006-10-31 20:10:36 UTC (rev 224)
+++ trunk/src/ChangeLog 2006-11-14 16:56:07 UTC (rev 225)
@@ -1,3 +1,15 @@
+2006-11-14 Werner Koch <wk at g10code.com>
+
+ * libassuan.m4 (AM_CHECK_LIBASSUAN): New.
+
+ * assuan-handler.c (assuan_register_post_cmd_notify)
+ (assuan_register_post_cmd_notify): New.
+ * assuan-util.c (assuan_set_io_monitor): New.
+ * assuan-buffer.c (_assuan_read_line): Use it.
+ (_assuan_write_line): Ditto.
+ (_assuan_cookie_write_data): Ditto.
+ (_assuan_cookie_write_flush): Ditto.
+
2006-10-18 Werner Koch <wk at g10code.com>
* libassuan.m4: Pass "pthread" to the common macro. Reported by
Modified: trunk/src/assuan-buffer.c
===================================================================
--- trunk/src/assuan-buffer.c 2006-10-31 20:10:36 UTC (rev 224)
+++ trunk/src/assuan-buffer.c 2006-11-14 16:56:07 UTC (rev 225)
@@ -1,5 +1,5 @@
/* assuan-buffer.c - read and send data
- * Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+ * Copyright (C) 2001, 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
*
* This file is part of Assuan.
*
@@ -159,7 +159,9 @@
if (endp)
{
+ unsigned monitor_result;
int n = endp - line + 1;
+
if (n < nread)
/* LINE contains more than one line. We copy it to the attic
now as handlers are allowed to modify the passed
@@ -176,7 +178,16 @@
*endp = 0;
ctx->inbound.linelen = endp - line;
- if (ctx->log_fp)
+
+ monitor_result = (ctx->io_monitor
+ ? ctx->io_monitor (ctx, 0,
+ ctx->inbound.line,
+ ctx->inbound.linelen)
+ : 0);
+ if ( (monitor_result & 2) )
+ ctx->inbound.linelen = 0;
+
+ if (ctx->log_fp && !(monitor_result & 1))
{
fprintf (ctx->log_fp, "%s[%u.%d] DBG: <- ",
assuan_get_assuan_log_prefix (),
@@ -245,6 +256,7 @@
{
assuan_error_t rc = 0;
size_t prefixlen = prefix? strlen (prefix):0;
+ unsigned int monitor_result;
/* Make sure that the line is short enough. */
if (len + prefixlen + 2 > ASSUAN_LINELENGTH)
@@ -260,8 +272,12 @@
len = ASSUAN_LINELENGTH - prefixlen - 2 - 1;
}
+ monitor_result = (ctx->io_monitor
+ ? ctx->io_monitor (ctx, 1, line, len)
+ : 0);
+
/* Fixme: we should do some kind of line buffering. */
- if (ctx->log_fp)
+ if (ctx->log_fp && !(monitor_result & 1))
{
fprintf (ctx->log_fp, "%s[%u.%d] DBG: -> ",
assuan_get_assuan_log_prefix (),
@@ -277,13 +293,13 @@
putc ('\n', ctx->log_fp);
}
- if (prefixlen)
+ if (prefixlen && !(monitor_result & 2))
{
rc = writen (ctx, prefix, prefixlen);
if (rc)
rc = _assuan_error (ASSUAN_Write_Error);
}
- if (!rc)
+ if (!rc && !(monitor_result & 2))
{
rc = writen (ctx, line, len);
if (rc)
@@ -325,7 +341,7 @@
/* Write out the data in buffer as datalines with line wrapping and
- percent escaping. This function is used for GNU's custom streams */
+ percent escaping. This function is used for GNU's custom streams. */
int
_assuan_cookie_write_data (void *cookie, const char *buffer, size_t orig_size)
{
@@ -342,7 +358,9 @@
line += linelen;
while (size)
{
- /* insert data line header */
+ unsigned int monitor_result;
+
+ /* Insert data line header. */
if (!linelen)
{
*line++ = 'D';
@@ -350,7 +368,7 @@
linelen += 2;
}
- /* copy data, keep some space for the CRLF and to escape one character */
+ /* Copy data, keep space for the CRLF and to escape one character. */
while (size && linelen < LINELENGTH-2-2)
{
if (*buffer == '%' || *buffer == '\r' || *buffer == '\n')
@@ -368,9 +386,15 @@
size--;
}
+
+ monitor_result = (ctx->io_monitor
+ ? ctx->io_monitor (ctx, 1,
+ ctx->outbound.data.line, linelen)
+ : 0);
+
if (linelen >= LINELENGTH-2-2)
{
- if (ctx->log_fp)
+ if (ctx->log_fp && !(monitor_result & 1))
{
fprintf (ctx->log_fp, "%s[%u.%d] DBG: -> ",
assuan_get_assuan_log_prefix (),
@@ -386,7 +410,8 @@
}
*line++ = '\n';
linelen++;
- if (writen (ctx, ctx->outbound.data.line, linelen))
+ if ( !(monitor_result & 2)
+ && writen (ctx, ctx->outbound.data.line, linelen))
{
ctx->outbound.data.error = _assuan_error (ASSUAN_Write_Error);
return 0;
@@ -409,6 +434,7 @@
assuan_context_t ctx = cookie;
char *line;
size_t linelen;
+ unsigned int monitor_result;
if (ctx->outbound.data.error)
return 0;
@@ -416,9 +442,15 @@
line = ctx->outbound.data.line;
linelen = ctx->outbound.data.linelen;
line += linelen;
+
+ monitor_result = (ctx->io_monitor
+ ? ctx->io_monitor (ctx, 1,
+ ctx->outbound.data.line, linelen)
+ : 0);
+
if (linelen)
{
- if (ctx->log_fp)
+ if (ctx->log_fp && !(monitor_result & 1))
{
fprintf (ctx->log_fp, "%s[%u.%d] DBG: -> ",
assuan_get_assuan_log_prefix (),
@@ -432,7 +464,8 @@
}
*line++ = '\n';
linelen++;
- if (writen (ctx, ctx->outbound.data.line, linelen))
+ if ( !(monitor_result & 2)
+ && writen (ctx, ctx->outbound.data.line, linelen))
{
ctx->outbound.data.error = _assuan_error (ASSUAN_Write_Error);
return 0;
Modified: trunk/src/assuan-defs.h
===================================================================
--- trunk/src/assuan-defs.h 2006-10-31 20:10:36 UTC (rev 224)
+++ trunk/src/assuan-defs.h 2006-11-14 16:56:07 UTC (rev 225)
@@ -179,6 +179,20 @@
void (*input_notify_fnc)(assuan_context_t, const char *);
void (*output_notify_fnc)(assuan_context_t, const char *);
+ /* This function is called right after a command has been processed.
+ It may be used to command related cleanup. */
+ void (*post_cmd_notify_fnc)(assuan_context_t, int);
+
+ /* If set, this is called right before logging an I/O line. With
+ DIRECTION set to 1 it is called for an output oeration; 0 means
+ an input operation. If bit 0 is set in the return value, the
+ logging of the will be suppressed. With bit 1 set, the entire
+ line will be ignored. */
+ unsigned int (*io_monitor)(assuan_context_t ctx,
+ int direction,
+ const char *line,
+ size_t linelen);
+
int input_fd; /* set by INPUT command */
int output_fd; /* set by OUTPUT command */
Modified: trunk/src/assuan-handler.c
===================================================================
--- trunk/src/assuan-handler.c 2006-10-31 20:10:36 UTC (rev 224)
+++ trunk/src/assuan-handler.c 2006-11-14 16:56:07 UTC (rev 225)
@@ -292,6 +292,16 @@
}
int
+assuan_register_post_cmd_notify (assuan_context_t ctx,
+ void (*fnc)(assuan_context_t, int))
+{
+ if (!ctx)
+ return _assuan_error (ASSUAN_Invalid_Value);
+ ctx->post_cmd_notify_fnc = fnc;
+ return 0;
+}
+
+int
assuan_register_bye_notify (assuan_context_t ctx,
void (*fnc)(assuan_context_t))
{
@@ -543,6 +553,9 @@
rc = assuan_write_line (ctx, errline);
}
+ if (ctx->post_cmd_notify_fnc)
+ ctx->post_cmd_notify_fnc (ctx, rc);
+
ctx->confidential = 0;
if (ctx->okay_line)
{
Modified: trunk/src/assuan-util.c
===================================================================
--- trunk/src/assuan-util.c 2006-10-31 20:10:36 UTC (rev 224)
+++ trunk/src/assuan-util.c 2006-11-14 16:56:07 UTC (rev 225)
@@ -125,7 +125,22 @@
}
+void
+assuan_set_io_monitor (assuan_context_t ctx,
+ unsigned int (*monitor)(assuan_context_t ctx,
+ int direction,
+ const char *line,
+ size_t linelen))
+{
+ if (ctx)
+ {
+ ctx->io_monitor = monitor;
+ }
+}
+
+
+
/* For context CTX, set the flag FLAG to VALUE. Values for flags
are usually 1 or 0 but certain flags might allow for other values;
see the description of the type assuan_flag_t for details. */
Modified: trunk/src/assuan.h
===================================================================
--- trunk/src/assuan.h 2006-10-31 20:10:36 UTC (rev 224)
+++ trunk/src/assuan.h 2006-11-14 16:56:07 UTC (rev 225)
@@ -62,6 +62,8 @@
#define _ASSUAN_PREFIX(x) _ASSUAN_PREFIX2(_ASSUAN_EXT_SYM_PREFIX,x)
#define assuan_ _ASSUAN_PREFIX(assuan_)
#define assuan_register_command _ASSUAN_PREFIX(assuan_register_command)
+#define assuan_register_post_cmd_notify \
+ _ASSUAN_PREFIX(assuan_register_post_cmd_notify)
#define assuan_register_bye_notify _ASSUAN_PREFIX(assuan_register_bye_notify)
#define assuan_register_reset_notify \
_ASSUAN_PREFIX(assuan_register_reset_notify)
@@ -113,6 +115,7 @@
#define assuan_set_error _ASSUAN_PREFIX(assuan_set_error)
#define assuan_set_pointer _ASSUAN_PREFIX(assuan_set_pointer)
#define assuan_get_pointer _ASSUAN_PREFIX(assuan_get_pointer)
+#define assuan_set_io_monitor _ASSUAN_PREFIX(assuan_set_io_monitor)
#define assuan_begin_confidential _ASSUAN_PREFIX(assuan_begin_confidential)
#define assuan_end_confidential _ASSUAN_PREFIX(assuan_end_confidential)
#define assuan_strerror _ASSUAN_PREFIX(assuan_strerror)
@@ -336,6 +339,8 @@
int assuan_register_command (assuan_context_t ctx,
const char *cmd_string,
int (*handler)(assuan_context_t, char *));
+int assuan_register_post_cmd_notify (assuan_context_t ctx,
+ void (*fnc)(assuan_context_t, int));
int assuan_register_bye_notify (assuan_context_t ctx,
void (*fnc)(assuan_context_t));
int assuan_register_reset_notify (assuan_context_t ctx,
@@ -466,6 +471,12 @@
void assuan_begin_confidential (assuan_context_t ctx);
void assuan_end_confidential (assuan_context_t ctx);
+void assuan_set_io_monitor (assuan_context_t ctx,
+ unsigned int (*monitor)(assuan_context_t ctx,
+ int direction,
+ const char *line,
+ size_t linelen));
+
/* For context CTX, set the flag FLAG to VALUE. Values for flags
are usually 1 or 0 but certain flags might allow for other values;
see the description of the type assuan_flag_t for details. */
Modified: trunk/src/libassuan.m4
===================================================================
--- trunk/src/libassuan.m4 2006-10-31 20:10:36 UTC (rev 224)
+++ trunk/src/libassuan.m4 2006-11-14 16:56:07 UTC (rev 225)
@@ -96,8 +96,23 @@
])
+dnl AM_CHECK_LIBASSUAN([MINIMUM-VERSION,
+dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
+dnl Test whether libassuan has at least MINIMUM-VERSION. This is
+dnl used to test for features only available in newer versions.
+dnl
+AC_DEFUN([AM_CHECK_LIBASSUAN],
+[ _AM_PATH_LIBASSUAN_COMMON($1)
+ if test $ok = yes; then
+ ifelse([$2], , :, [$2])
+ else
+ ifelse([$3], , :, [$3])
+ fi
+])
+
+
dnl AM_PATH_LIBASSUAN([MINIMUM-VERSION,
dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
dnl Test for libassuan and define LIBASSUAN_CFLAGS and LIBASSUAN_LIBS
More information about the Gnupg-commits
mailing list