[Pkg-gnupg-commit] [libassuan] 175/437: New functions assuan_set_io_monitor and assuan_register_post_cmd_notify

Eric Dorland eric at moszumanska.debian.org
Fri May 22 05:33:39 UTC 2015


This is an automated email from the git hooks/post-receive script.

eric pushed a commit to branch master
in repository libassuan.

commit 2cf3dcd3dcfe00321e8ca65ac2ffb4ebb8e7bb29
Author: Werner Koch <wk at gnupg.org>
Date:   Tue Nov 14 16:56:07 2006 +0000

    New functions assuan_set_io_monitor and assuan_register_post_cmd_notify
---
 NEWS                 |  4 ++++
 doc/assuan.texi      | 18 +++++++++++++++++
 src/ChangeLog        | 12 +++++++++++
 src/assuan-buffer.c  | 57 +++++++++++++++++++++++++++++++++++++++++-----------
 src/assuan-defs.h    | 14 +++++++++++++
 src/assuan-handler.c | 13 ++++++++++++
 src/assuan-util.c    | 15 ++++++++++++++
 src/assuan.h         | 11 ++++++++++
 src/libassuan.m4     | 15 ++++++++++++++
 9 files changed, 147 insertions(+), 12 deletions(-)

diff --git a/NEWS b/NEWS
index db8434d..014b18a 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,10 @@
 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)
 ------------------------------------------------
diff --git a/doc/assuan.texi b/doc/assuan.texi
index cdd5b1c..434386d 100644
--- a/doc/assuan.texi
+++ b/doc/assuan.texi
@@ -943,6 +943,14 @@ application.  Instead special functions should be used to get hold of
 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,6 +1328,16 @@ thus an entire assuan line may be read without triggering any actual
 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}})
 
diff --git a/src/ChangeLog b/src/ChangeLog
index b5bef81..e651060 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -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
diff --git a/src/assuan-buffer.c b/src/assuan-buffer.c
index 228aa7c..b06025b 100644
--- a/src/assuan-buffer.c
+++ b/src/assuan-buffer.c
@@ -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 @@ _assuan_read_line (assuan_context_t ctx)
 
   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 @@ _assuan_read_line (assuan_context_t ctx)
       *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_write_line (assuan_context_t ctx, const char *prefix,
 {
   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 @@ _assuan_write_line (assuan_context_t ctx, const char *prefix,
         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 @@ _assuan_write_line (assuan_context_t ctx, const char *prefix,
       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 @@ assuan_write_line (assuan_context_t ctx, const char *line)
 
 

 /* 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 @@ _assuan_cookie_write_data (void *cookie, const char *buffer, size_t orig_size)
   line += linelen;
   while (size)
     {
-      /* insert data line header */
+      unsigned int monitor_result;
+
+      /* Insert data line header. */
       if (!linelen)
         {
           *line++ = 'D';
@@ -350,7 +368,7 @@ _assuan_cookie_write_data (void *cookie, const char *buffer, size_t orig_size)
           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 @@ _assuan_cookie_write_data (void *cookie, const char *buffer, size_t orig_size)
           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 @@ _assuan_cookie_write_data (void *cookie, const char *buffer, size_t orig_size)
             }
           *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_cookie_write_flush (void *cookie)
   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 @@ _assuan_cookie_write_flush (void *cookie)
   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 @@ _assuan_cookie_write_flush (void *cookie)
 	}
       *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;
diff --git a/src/assuan-defs.h b/src/assuan-defs.h
index 5bf1b9e..fa04f0b 100644
--- a/src/assuan-defs.h
+++ b/src/assuan-defs.h
@@ -179,6 +179,20 @@ struct assuan_context_s
   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 */
 
diff --git a/src/assuan-handler.c b/src/assuan-handler.c
index 19dab71..fd3a52b 100644
--- a/src/assuan-handler.c
+++ b/src/assuan-handler.c
@@ -292,6 +292,16 @@ assuan_register_command (assuan_context_t ctx,
 }
 
 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 @@ process_request (assuan_context_t ctx)
       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)
     {
diff --git a/src/assuan-util.c b/src/assuan-util.c
index 3e627fc..d12277f 100644
--- a/src/assuan-util.c
+++ b/src/assuan-util.c
@@ -125,6 +125,21 @@ 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))
+{
+  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;
diff --git a/src/assuan.h b/src/assuan.h
index cbc386b..9080fd3 100644
--- a/src/assuan.h
+++ b/src/assuan.h
@@ -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 @@ typedef struct assuan_context_s *ASSUAN_CONTEXT _ASSUAN_DEPRECATED;
 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_get_pointer (assuan_context_t ctx);
 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. */
diff --git a/src/libassuan.m4 b/src/libassuan.m4
index 95b6190..e099b66 100644
--- a/src/libassuan.m4
+++ b/src/libassuan.m4
@@ -96,6 +96,21 @@ AC_DEFUN([_AM_PATH_LIBASSUAN_COMMON],
 
 ])
 
+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,

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/libassuan.git



More information about the Pkg-gnupg-commit mailing list