[Pkg-gnupg-commit] [libassuan] 113/437: * assuan-listen.c (assuan_set_hello_line, assuan_accept): Allow for multi line hello strings.

Eric Dorland eric at moszumanska.debian.org
Fri May 22 05:33:31 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 2284687515072f8824dc352e8d90bcdace558fee
Author: Werner Koch <wk at gnupg.org>
Date:   Tue May 11 09:14:56 2004 +0000

    * assuan-listen.c (assuan_set_hello_line, assuan_accept): Allow
    for multi line hello strings.
    
    * assuan-buffer.c (_assuan_write_line): New with parts of ..
    (assuan_write_line): .. factored out.
---
 NEWS                |  4 +++
 src/ChangeLog       |  8 ++++++
 src/assuan-buffer.c | 78 ++++++++++++++++++++++++++++++++++++++---------------
 src/assuan-defs.h   |  2 ++
 src/assuan-listen.c | 35 +++++++++++++++++++-----
 5 files changed, 100 insertions(+), 27 deletions(-)

diff --git a/NEWS b/NEWS
index 2b6dc12..8f915a7 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,10 @@
 Noteworthy changes in version 0.6.6
 ------------------------------------------------
 
+ * assuan_set_hello_line may now take a multi line argument where the
+   first lines are send as comment lines and the last one as a OK
+   line.
+
 
 Noteworthy changes in version 0.6.5 (2004-04-29)
 ------------------------------------------------
diff --git a/src/ChangeLog b/src/ChangeLog
index 0d1aa90..5808f1e 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,11 @@
+2004-05-11  Werner Koch  <wk at gnupg.org>
+
+	* assuan-listen.c (assuan_set_hello_line, assuan_accept): Allow
+	for multi line hello strings.
+
+	* assuan-buffer.c (_assuan_write_line): New with parts of ..
+	(assuan_write_line): .. factored out.
+
 2004-04-29  Werner Koch  <wk at gnupg.org>
 
 	* assuan-socket-connect.c: Include string.h.
diff --git a/src/assuan-buffer.c b/src/assuan-buffer.c
index dbb3604..6d81441 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 Free Software Foundation, Inc.
+ *	Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
  *
  * This file is part of Assuan.
  *
@@ -227,29 +227,33 @@ assuan_pending_line (ASSUAN_CONTEXT ctx)
 }
 
 
-AssuanError 
-assuan_write_line (ASSUAN_CONTEXT ctx, const char *line)
+assuan_error_t 
+_assuan_write_line (assuan_context_t ctx, const char *prefix,
+                    const char *line, size_t len)
 {
-  int rc;
-  size_t len;
-  const char *s;
+  int rc = 0;
+  size_t prefixlen = prefix? strlen (prefix):0;
 
-  if (!ctx)
-    return ASSUAN_Invalid_Value;
-
-  /* Make sure that we never take a LF from the user - this might
-     violate the protocol. */
-  s = strchr (line, '\n');
-  len = s? (s-line) : strlen (line);
+  /* Make sure that the line is short enough. */
+  if (len + prefixlen + 2 > ASSUAN_LINELENGTH)
+    {
+      if (ctx->log_fp)
+        fprintf (ctx->log_fp, "%s[%u.%p] DBG: -> "
+                 "[supplied line too long -truncated]\n",
+                 assuan_get_assuan_log_prefix (),
+                 (unsigned int)getpid (), ctx);
+      if (prefixlen > 5)
+        prefixlen = 5;
+      if (len > ASSUAN_LINELENGTH - prefixlen - 2)
+        len = ASSUAN_LINELENGTH - prefixlen - 2 - 1;
+    }
 
-  /* fixme: we should do some kind of line buffering.  */
+  /* Fixme: we should do some kind of line buffering.  */
   if (ctx->log_fp)
     {
       fprintf (ctx->log_fp, "%s[%u.%p] DBG: -> ",
 	       assuan_get_assuan_log_prefix (),
                (unsigned int)getpid (), ctx);
-      if (s)
-	fputs ("[supplied line contained a LF]", ctx->log_fp);
       if (ctx->confidential)
 	fputs ("[Confidential data not shown]", ctx->log_fp);
       else
@@ -257,20 +261,52 @@ assuan_write_line (ASSUAN_CONTEXT ctx, const char *line)
       putc ('\n', ctx->log_fp);
     }
 
-  rc = writen (ctx, line, len);
-  if (rc)
-    rc = ASSUAN_Write_Error;
+  if (prefixlen)
+    {
+      rc = writen (ctx, prefix, prefixlen);
+      if (rc)
+        rc = ASSUAN_Write_Error;
+    }
   if (!rc)
     {
-      rc = writen (ctx, "\n", 1);
+      rc = writen (ctx, line, len);
       if (rc)
         rc = ASSUAN_Write_Error;
+      if (!rc)
+        {
+          rc = writen (ctx, "\n", 1);
+          if (rc)
+            rc = ASSUAN_Write_Error;
+        }
     }
-
   return rc;
 }
 
 
+AssuanError 
+assuan_write_line (ASSUAN_CONTEXT ctx, const char *line)
+{
+  size_t len;
+  const char *s;
+
+  if (!ctx)
+    return ASSUAN_Invalid_Value;
+
+  /* Make sure that we never take a LF from the user - this might
+     violate the protocol. */
+  s = strchr (line, '\n');
+  len = s? (s-line) : strlen (line);
+
+  if (ctx->log_fp && s)
+    fprintf (ctx->log_fp, "%s[%u.%p] DBG: -> "
+             "[supplied line contained a LF -truncated]\n",
+             assuan_get_assuan_log_prefix (),
+             (unsigned int)getpid (), ctx);
+
+  return _assuan_write_line (ctx, NULL, line, len);
+}
+
+
 

 /* Write out the data in buffer as datalines with line wrapping and
    percent escaping.  This function is used for GNU's custom streams */
diff --git a/src/assuan-defs.h b/src/assuan-defs.h
index 608c05a..7038b16 100644
--- a/src/assuan-defs.h
+++ b/src/assuan-defs.h
@@ -152,6 +152,8 @@ int _assuan_register_std_commands (ASSUAN_CONTEXT ctx);
 int _assuan_read_line (ASSUAN_CONTEXT ctx);
 int _assuan_cookie_write_data (void *cookie, const char *buffer, size_t size);
 int _assuan_cookie_write_flush (void *cookie);
+assuan_error_t _assuan_write_line (assuan_context_t ctx, const char *prefix,
+                                   const char *line, size_t len);
 
 /*-- assuan-client.c --*/
 AssuanError _assuan_read_from_server (ASSUAN_CONTEXT ctx, int *okay, int *off);
diff --git a/src/assuan-listen.c b/src/assuan-listen.c
index aae3f7b..eb292c5 100644
--- a/src/assuan-listen.c
+++ b/src/assuan-listen.c
@@ -1,5 +1,5 @@
 /* assuan-listen.c - Wait for a connection (server) 
- *	Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+ *	Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc.
  *
  * This file is part of Assuan.
  *
@@ -41,8 +41,13 @@ assuan_set_hello_line (ASSUAN_CONTEXT ctx, const char *line)
       char *buf = xtrymalloc (3+strlen(line)+1);
       if (!buf)
         return ASSUAN_Out_Of_Core;
-      strcpy (buf, "OK ");
-      strcpy (buf+3, line);
+      if (strchr (line, '\n'))
+        strcpy (buf, line);
+      else
+        {
+          strcpy (buf, "OK ");
+          strcpy (buf+3, line);
+        }
       xfree (ctx->hello_line);
       ctx->hello_line = buf;
     }
@@ -65,6 +70,7 @@ AssuanError
 assuan_accept (ASSUAN_CONTEXT ctx)
 {
   int rc;
+  const char *p, *pend;
 
   if (!ctx)
     return ASSUAN_Invalid_Value;
@@ -77,9 +83,26 @@ assuan_accept (ASSUAN_CONTEXT ctx)
   if (rc)
     return rc;
 
-  /* send the hello */
-  rc = assuan_write_line (ctx, ctx->hello_line? ctx->hello_line
-                                              : "OK Your orders please");
+  /* Send the hello. */
+  p = ctx->hello_line;
+  if (p && (pend = strchr (p, '\n')))
+    { /* This is a multi line hello.  Send all but the last line as
+         comments. */
+      do
+        {
+          rc = _assuan_write_line (ctx, "# ", p, pend - p);
+          if (rc)
+            return rc;
+          p = pend + 1;
+          pend = strchr (p, '\n');
+        }
+      while (pend);
+      rc = _assuan_write_line (ctx, "OK ", p, strlen (p));
+    }
+  else if (p)
+    rc = assuan_write_line (ctx, p);
+  else
+    rc = assuan_write_line (ctx, "OK Pleased to meet you");
   if (rc)
     return rc;
   

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