[Pkg-gnupg-commit] [libassuan] 365/437: Add new flag ASSUAN_FORCE_CLOSE.

Eric Dorland eric at moszumanska.debian.org
Fri May 22 05:34:04 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 02c13554c5a5c44556acb9ff4e4b380f92a98b7d
Author: Werner Koch <wk at gnupg.org>
Date:   Wed Aug 10 13:04:04 2011 +0200

    Add new flag ASSUAN_FORCE_CLOSE.
---
 NEWS                 |  7 +++++--
 doc/assuan.texi      | 43 ++++++++++++++++++++++++-------------------
 src/ChangeLog        |  8 ++++++++
 src/assuan-defs.h    |  5 +++--
 src/assuan-handler.c | 15 ++++++++++++---
 src/assuan.h.in      | 10 ++++++----
 src/context.c        | 12 ++++++++++--
 7 files changed, 68 insertions(+), 32 deletions(-)

diff --git a/NEWS b/NEWS
index c76501d..6514943 100644
--- a/NEWS
+++ b/NEWS
@@ -1,10 +1,13 @@
 Noteworthy changes in version 2.0.3 (unreleased)
 ------------------------------------------------
 
- * ...
+ * Interface changes relative to the 2.0.2 release:
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ASSUAN_FORCE_CLOSE       NEW.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 
-Noteworthy changes in version 2.0.2 (2010-06-16)
+Noteworthy changes in version 2.0.2 (2011-06-16)
 ------------------------------------------------
 
  * A new flag may now be used to convey comments via assuan_transact.
diff --git a/doc/assuan.texi b/doc/assuan.texi
index 1121935..9907803 100644
--- a/doc/assuan.texi
+++ b/doc/assuan.texi
@@ -378,7 +378,7 @@ to set the error source to a different value than the default
 assuan_set_gpg_err_source} early.
 
 
- at c 
+ at c
 @c           P R E P A R A T I O N
 @c
 @node Preparation
@@ -386,7 +386,7 @@ assuan_set_gpg_err_source} early.
 
 To use @sc{Assuan}, you have to perform some changes to your
 sources and the build system.  The necessary changes are small and
-explained in the following sections. 
+explained in the following sections.
 
 
 @menu
@@ -411,7 +411,7 @@ file, like this:
 The name space of @code{libassuan} is @code{assuan_*} for function
 and type names and @code{ASSUAN*} for other symbols.  In addition the
 same name prefixes with one prepended underscore are reserved for
-internal use and should never be used by an application. 
+internal use and should never be used by an application.
 
 Because @code{libassuan} makes use of the GPG Error library, using
 @code{libassuan} will also use the @code{GPG_ERR_*} name space
@@ -519,7 +519,7 @@ across contexts.
 @end itemize
 
 
- at c 
+ at c
 @c     G E N E R A L I T I E S
 @c
 @node Generalities
@@ -694,7 +694,7 @@ The default log handler can be configured by the following functions:
 
 @deftypefun void assuan_set_assuan_log_prefix (@w{const char *@var{text}})
 Set the prefix to be used at the start of a line emitted by assuan
-on the log stream to @var{text}.  The default is the empty string. 
+on the log stream to @var{text}.  The default is the empty string.
 @end deftypefun
 
 
@@ -816,7 +816,7 @@ The flags are all named and collected in an @code{enum} for better readability.
 Currently only one flag is defined:
 
 @table @code
- at item ASSUAN_NO_WAITPID 
+ at item ASSUAN_NO_WAITPID
 When using a pipe server, by default Libassuan will wait for the forked
 process to die in @code{assuan_release}.  In certain cases this is
 not desirable.  By setting this flag, a call to @code{waitpid} will be
@@ -828,13 +828,18 @@ Do not modify signal handler for @code{SIGPIPE}.
 @item ASSUAN_CONVEY_COMMENTS
 If enabled comment lines are passed to the status callback of the
 @code{assuan_transact}.
+ at item ASSUAN_FORCE_CLOSE
+Setting this flag forces the next command to assume that the
+connection has been closed.  This breaks the command processing loop
+and may be used as an implicit BYE command.  @var{value} is ignored
+and thus it is not possible to clear this flag.
 @end table
 @end deftp
 @end deftypefun
 
 @deftypefun int assuan_get_flag (@w{assuan_context_t @var{ctx}}, @w{assuan_flag_t @var{flag}})
-Return the value of @var{flag} in context @var{ctx}. 
- at end deftypefun 
+Return the value of @var{flag} in context @var{ctx}.
+ at end deftypefun
 
 
 @deftypefun void assuan_begin_confidential (@w{assuan_context_t @var{ctx}})
@@ -999,7 +1004,7 @@ function shall not be used for sending data (@code{D}) lines.  This
 function returns @code{0} on success or an error value.
 @end deftypefun
 
- at noindent 
+ at noindent
 To actually send bulk data lines a specialized function is available:
 
 @deftypefun gpg_error_t assuan_send_data (@w{assuan_context_t @var{ctx}}, @w{const void *@var{buffer}}, @w{size_t @var{length}})
@@ -1047,7 +1052,7 @@ context @var{ctx} with the hook value @var{hook_data}.
 @end deftypefun
 
 
- at c 
+ at c
 @c     C L I E N T   C O D E
 @c
 @node Client code
@@ -1173,7 +1178,7 @@ trigger is sent (e.g. using @code{assuan_write_line ("INPUT FD")}.
 @end deftypefun
 
 
- at c 
+ at c
 @c     S E R V E R   C O D E
 @c
 @node Server code
@@ -1187,14 +1192,14 @@ commented example.
 The list of the implemented server commands is defined by a table like:
 
 @smallexample
-  static struct @{ 
+  static struct @{
     const char *name;
     int (*handler) (assuan_context_t, char *line);
   @} command_table[] = @{
     @{ "FOO", cmd_foo @},
     @{ "BAR", cmd_bar @},
-    @{ "INPUT", NULL @}, 
-    @{ "OUTPUT", NULL @}, 
+    @{ "INPUT", NULL @},
+    @{ "OUTPUT", NULL @},
     @{ NULL @}@};
 @end smallexample
 
@@ -1301,7 +1306,7 @@ Windows but it does not harm to use it on other systems as well.
 
 @noindent
 After error checking, the implemented assuan commands are registered with
-the server.  
+the server.
 
 @example
   for (i = 0; command_table[i].name; i++)
@@ -1315,7 +1320,7 @@ the server.
           assuan_release (ctx);
           return;
         @}
-    @} 
+    @}
 @end example
 
 @deftp {Data type} {gpg_error_t (*assuan_handler_t) (@w{assuan_context_t @var{ctx}}, @w{char *@var{line}})}
@@ -1429,7 +1434,7 @@ clients requests.
           fprintf (stderr, "accept problem: %s\n", gpg_strerror (rc));
           break;
         @}
-      
+
       rc = assuan_process (ctx);
       if (rc)
         @{
@@ -1559,7 +1564,7 @@ event loop.
 When bulk data FDs become ready, you can simply perform the
 corresponding read or write operations.  When the inbound status FD
 becomes ready, you can receive the next server line with
-assuan_read_line().  
+assuan_read_line().
 
 @item
 You should close and unregister the bulk data FDs when you wrote all
@@ -1936,7 +1941,7 @@ port number and a random nonce to this file.
         @w{assuan_sock_nonce_t *@var{nonce}})
 
 This is used by the server after a bind to return the random nonce.  To
-keep the code readable this may also be used on POSIX system. 
+keep the code readable this may also be used on POSIX system.
 @end deftypefun
 
 @deftypefun int assuan_sock_check_nonce ( @
diff --git a/src/ChangeLog b/src/ChangeLog
index 261c605..ddbad5e 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,11 @@
+2011-08-10  Werner Koch  <wk at g10code.com>
+
+	* assuan.h.in (ASSUAN_FORCE_CLOSE): New.
+	* assuan-defs.h (assuan_context_s): Add flags.FORCE_CLOSE.
+	* context.c (assuan_set_flag, assuan_get_flag): Set/get the flag.
+	* assuan-handler.c (assuan_process_done): Close connection if
+	requested.
+
 2011-04-06  Werner Koch  <wk at g10code.com>
 
 	* libassuan-config.in: Add option --host.
diff --git a/src/assuan-defs.h b/src/assuan-defs.h
index 8a3fcc2..f6cb9b4 100644
--- a/src/assuan-defs.h
+++ b/src/assuan-defs.h
@@ -40,7 +40,7 @@
 
 #include "assuan.h"
 
-#if __GNUC__ > 2 
+#if __GNUC__ > 2
 # define ASSUAN_GCC_A_PURE  __attribute__ ((__pure__))
 #else
 # define ASSUAN_GCC_A_PURE
@@ -97,6 +97,7 @@ struct assuan_context_s
     unsigned int no_fixsignals : 1;
     unsigned int convey_comments : 1;
     unsigned int no_logging : 1;
+    unsigned int force_close : 1;
   } flags;
 
   /* If set, this is called right before logging an I/O line.  */
@@ -199,7 +200,7 @@ struct assuan_context_s
   struct cmdtbl_s *cmdtbl;
   size_t cmdtbl_used; /* used entries */
   size_t cmdtbl_size; /* allocated size of table */
-  
+
   /* The name of the command currently processed by a command handler.
      This is a pointer into CMDTBL.  NULL if not in a command
      handler.  */
diff --git a/src/assuan-handler.c b/src/assuan-handler.c
index bd57ca0..28fcdfd 100644
--- a/src/assuan-handler.c
+++ b/src/assuan-handler.c
@@ -635,6 +635,9 @@ assuan_process_done (assuan_context_t ctx, gpg_error_t rc)
   if (!ctx->in_command)
     return _assuan_error (ctx, GPG_ERR_ASS_GENERAL);
 
+  if (ctx->flags.force_close)
+    ctx->process_complete = 1;
+
   ctx->in_command = 0;
 
   /* Check for data write errors.  */
@@ -673,12 +676,18 @@ assuan_process_done (assuan_context_t ctx, gpg_error_t rc)
       const char *text = ctx->err_no == rc ? ctx->err_str : NULL;
       char ebuf[50];
 
+      if (ctx->flags.force_close)
+        text = "[closing connection]";
+
       gpg_strerror_r (rc, ebuf, sizeof (ebuf));
-      sprintf (errline, "ERR %d %.50s <%.30s>%s%.100s",
-	       rc, ebuf, gpg_strsource (rc),
-	       text? " - ":"", text?text:"");
+      snprintf (errline, sizeof errline, "ERR %d %.50s <%.30s>%s%.100s",
+                rc, ebuf, gpg_strsource (rc),
+                text? " - ":"", text?text:"");
 
       rc = assuan_write_line (ctx, errline);
+
+      if (ctx->flags.force_close)
+        ctx->finish_handler (ctx);
     }
 
   if (ctx->post_cmd_notify_fnc)
diff --git a/src/assuan.h.in b/src/assuan.h.in
index 9ff263f..7aae362 100644
--- a/src/assuan.h.in
+++ b/src/assuan.h.in
@@ -164,8 +164,10 @@ typedef unsigned int assuan_flag_t;
 /* This flag changes assuan_transact to return comment lines via the
    status callback.  The default is to skip comment lines.  */
 #define ASSUAN_CONVEY_COMMENTS 4
-/* This flags disables logging for one context.  */
+/* This flag disables logging for one context.  */
 #define ASSUAN_NO_LOGGING 5
+/* This flag forces a connection close.  */
+#define ASSUAN_FORCE_CLOSE 6
 
 /* 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;
@@ -402,7 +404,7 @@ gpg_error_t assuan_client_parse_response (assuan_context_t ctx,
 					  int *off);
 
 /*-- assuan-client.c --*/
-gpg_error_t 
+gpg_error_t
 assuan_transact (assuan_context_t ctx,
                  const char *command,
                  gpg_error_t (*data_cb)(void *, const void *, size_t),
@@ -453,10 +455,10 @@ gpg_error_t assuan_sock_init (void);
 void assuan_sock_deinit (void);
 int assuan_sock_close (assuan_fd_t fd);
 assuan_fd_t assuan_sock_new (int domain, int type, int proto);
-int assuan_sock_connect (assuan_fd_t sockfd, 
+int assuan_sock_connect (assuan_fd_t sockfd,
                          struct sockaddr *addr, int addrlen);
 int assuan_sock_bind (assuan_fd_t sockfd, struct sockaddr *addr, int addrlen);
-int assuan_sock_get_nonce (struct sockaddr *addr, int addrlen, 
+int assuan_sock_get_nonce (struct sockaddr *addr, int addrlen,
                            assuan_sock_nonce_t *nonce);
 int assuan_sock_check_nonce (assuan_fd_t fd, assuan_sock_nonce_t *nonce);
 
diff --git a/src/context.c b/src/context.c
index a56a4d2..b4d4d49 100644
--- a/src/context.c
+++ b/src/context.c
@@ -88,6 +88,10 @@ assuan_set_flag (assuan_context_t ctx, assuan_flag_t flag, int value)
     case ASSUAN_NO_LOGGING:
       ctx->flags.no_logging = value;
       break;
+
+    case ASSUAN_FORCE_CLOSE:
+      ctx->flags.force_close = 1;
+      break;
     }
 }
 
@@ -120,10 +124,14 @@ assuan_get_flag (assuan_context_t ctx, assuan_flag_t flag)
     case ASSUAN_CONVEY_COMMENTS:
       res = ctx->flags.convey_comments;
       break;
-      
+
     case ASSUAN_NO_LOGGING:
       res = ctx->flags.no_logging;
       break;
+
+    case ASSUAN_FORCE_CLOSE:
+      res = ctx->flags.force_close;
+      break;
     }
 
   return TRACE_SUC1 ("flag_value=%i", res);
@@ -183,7 +191,7 @@ assuan_set_error (assuan_context_t ctx, gpg_error_t err, const char *text)
   TRACE4 (ctx, ASSUAN_LOG_CTX, "assuan_set_error", ctx,
 	  "err=%i (%s,%s),text=%s", err, gpg_strsource (err),
 	  gpg_strerror (err), text);
-  
+
   ctx->err_no = err;
   ctx->err_str = text;
   return err;

-- 
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