commit-mailutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU Mailutils branch, stream-cleanup, updated. rel-2_1-96-gb4ed41d


From: Sergey Poznyakoff
Subject: [SCM] GNU Mailutils branch, stream-cleanup, updated. rel-2_1-96-gb4ed41d
Date: Sun, 02 May 2010 19:37:03 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Mailutils".

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=b4ed41dcc3d0617358b9497d93c675e786109c5c

The branch, stream-cleanup has been updated
       via  b4ed41dcc3d0617358b9497d93c675e786109c5c (commit)
       via  9289484606db997acfff0f832049de9bae537a35 (commit)
       via  6f6681b1906430011403bceb36b992c44955ad50 (commit)
       via  b4a02de17f416199ce90f030f8b013f0a8651b90 (commit)
      from  b000617bad12dc7d3b0ea5f4541cc66b64e2fb02 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit b4ed41dcc3d0617358b9497d93c675e786109c5c
Author: Sergey Poznyakoff <address@hidden>
Date:   Sun May 2 22:38:06 2010 +0300

    Various fixes in imap4d.
    
    Imap4d successfully passes all tests.
    
    * imap4d/close.c (imap4d_close0): Fix improper use of MU_STREAM_READ
    (flags changed their semantics since then).
    * imap4d/fetch.c: Send \n terminated lines, rely on filters to recode
    line terminators to \r\n.
    (fetch_io): Rewrite using CRLF encoder and util_copy_out.
    (_frt_header_fields): Rewind memory stream before reading from it.
    
    * imap4d/auth_gsasl.c: Send \n terminated lines, rely on filters
    to recode line terminators to \r\n.
    * imap4d/auth_gss.c: Likewise.
    * imap4d/capability.c: Likewise.
    * imap4d/copy.c: Likewise.
    * imap4d/id.c: Likewise.
    * imap4d/idle.c: Likewise.
    * imap4d/list.c: Likewise.
    * imap4d/namespace.c: Likewise.
    * imap4d/preauth.c: Likewise.
    * imap4d/search.c: Likewise.
    * imap4d/status.c: Likewise.
    * imap4d/store.c: Likewise.
    * imap4d/select.c: Likewise.
    (imap4d_select_status): Fix improper use of MU_STREAM_READ.
    
    * imap4d/util.c: Send \n terminated lines, rely on filters
    to recode line terminators to \r\n.
    (util_setio): Apply CRLF filters to both input and output streams
    (in opposite directions).
    (util_copy_out): New function.
    (remove_cr): Remove.
    * imap4d/imap4d.h (util_copy_out): New prototype.

commit 9289484606db997acfff0f832049de9bae537a35
Author: Sergey Poznyakoff <address@hidden>
Date:   Sun May 2 22:34:54 2010 +0300

    Fix mailbox corruption in imap4d.
    
    Delivery of a signal when a previous signal was being handled caused
    mailbox corruption.
    
    * imap4d/imap4d.c (imap4d_child_signal_setup): New function.
    (imap4d_mainloop): Call imap4d_child_signal_setup.
    * imap4d/signal.c (imap4d_child_signal): Reset all signal handlers
    before doing actual job.
    * lib/signal.c (mu_set_signals): Use sigaction.

commit 6f6681b1906430011403bceb36b992c44955ad50
Author: Sergey Poznyakoff <address@hidden>
Date:   Sun May 2 22:33:08 2010 +0300

    Fix for mbox read/write consistency.
    
    * libproto/mbox/mbox.c (append_message_to_stream): Add \n after each
    message (scanner relies on this to determine message sizes).

commit b4a02de17f416199ce90f030f8b013f0a8651b90
Author: Sergey Poznyakoff <address@hidden>
Date:   Sun May 2 22:32:11 2010 +0300

    Bugfixes in stream-related code.
    
    * mailbox/fltstream.c (filter_read): Do not try to get more input until
    the output buffer is drained.
    * mailbox/mapfile_stream.c (_mapfile_seek): Fix conditional.
    * mailbox/stream.c (_stream_fill_buffer): Fix increment.
    (mu_stream_skip_input_bytes): Bugfixes.

-----------------------------------------------------------------------

Summary of changes:
 imap4d/auth_gsasl.c      |    4 +-
 imap4d/auth_gss.c        |    8 ++--
 imap4d/capability.c      |    2 +-
 imap4d/close.c           |    2 +-
 imap4d/copy.c            |    2 +-
 imap4d/fetch.c           |   36 +++++++--------
 imap4d/id.c              |    2 +-
 imap4d/idle.c            |    2 +-
 imap4d/imap4d.c          |   14 ++++--
 imap4d/imap4d.h          |    4 +-
 imap4d/list.c            |    6 +-
 imap4d/namespace.c       |    2 +-
 imap4d/preauth.c         |    2 +-
 imap4d/search.c          |    2 +-
 imap4d/select.c          |    8 ++--
 imap4d/signal.c          |   18 ++++---
 imap4d/status.c          |    2 +-
 imap4d/store.c           |    2 +-
 imap4d/util.c            |   58 +++++++++--------------
 lib/signal.c             |   11 ++++-
 libproto/mbox/mbox.c     |    2 +
 mailbox/fltstream.c      |  115 ++++++++++++++++++++++++----------------------
 mailbox/mapfile_stream.c |    2 +-
 mailbox/stream.c         |   14 +++--
 24 files changed, 167 insertions(+), 153 deletions(-)

diff --git a/imap4d/auth_gsasl.c b/imap4d/auth_gsasl.c
index 8676c4f..15e55ce 100644
--- a/imap4d/auth_gsasl.c
+++ b/imap4d/auth_gsasl.c
@@ -95,7 +95,7 @@ auth_gsasl (struct imap4d_command *command, char *auth_type, 
char **username)
   while ((rc = gsasl_step64 (sess_ctx, input_str, &output))
           == GSASL_NEEDS_MORE)
     {
-      util_send ("+ %s\r\n", output);
+      util_send ("+ %s\n", output);
       imap4d_getline (&input_str, &input_size, &input_len);
     }
   
@@ -112,7 +112,7 @@ auth_gsasl (struct imap4d_command *command, char 
*auth_type, char **username)
      returned, and clients must respond with an empty response. */
   if (output[0])
     {
-      util_send ("+ %s\r\n", output);
+      util_send ("+ %s\n", output);
       imap4d_getline (&input_str, &input_size, &input_len);
       if (input_len != 0)
        {
diff --git a/imap4d/auth_gss.c b/imap4d/auth_gss.c
index e85c258..1a7fd95 100644
--- a/imap4d/auth_gss.c
+++ b/imap4d/auth_gss.c
@@ -163,7 +163,7 @@ auth_gssapi (struct imap4d_command *command,
 
   /* Start the dialogue */
 
-  util_send ("+ \r\n");
+  util_send ("+ \n");
   util_flush_output ();
   
   context = GSS_C_NO_CONTEXT;
@@ -192,7 +192,7 @@ auth_gssapi (struct imap4d_command *command,
          if (outbuf.length)
            {
              mu_base64_encode (outbuf.value, outbuf.length, &tmp, &size);
-             util_send ("+ %s\r\n", tmp);
+             util_send ("+ %s\n", tmp);
              free (tmp);
              gss_release_buffer (&min_stat, &outbuf);
            }
@@ -212,7 +212,7 @@ auth_gssapi (struct imap4d_command *command,
   if (outbuf.length)
     {
       mu_base64_encode (outbuf.value, outbuf.length, &tmp, &size);
-      util_send ("+ %s\r\n", tmp);
+      util_send ("+ %s\n", tmp);
       free (tmp);
       gss_release_buffer (&min_stat, &outbuf);
       imap4d_getline (&token_str, &token_size, &token_len);
@@ -232,7 +232,7 @@ auth_gssapi (struct imap4d_command *command,
     }
   
   mu_base64_encode (outbuf.value, outbuf.length, &tmp, &size);
-  util_send ("+ %s\r\n", tmp);
+  util_send ("+ %s\n", tmp);
   free (tmp);
 
   imap4d_getline (&token_str, &token_size, &token_len);
diff --git a/imap4d/capability.c b/imap4d/capability.c
index c88bc60..b52d926 100644
--- a/imap4d/capability.c
+++ b/imap4d/capability.c
@@ -80,7 +80,7 @@ imap4d_capability (struct imap4d_command *command, 
imap4d_tokbuf_t tok)
   mu_list_do (capa_list, print_capa, NULL);
   
   imap4d_auth_capability ();
-  util_send ("\r\n");
+  util_send ("\n");
 
   return util_finish (command, RESP_OK, "Completed");
 }
diff --git a/imap4d/close.c b/imap4d/close.c
index 732e849..e730268 100644
--- a/imap4d/close.c
+++ b/imap4d/close.c
@@ -30,7 +30,7 @@ imap4d_close0 (struct imap4d_command *command, 
imap4d_tokbuf_t tok,
     return util_finish (command, RESP_BAD, "Invalid arguments");
   
   mu_mailbox_get_flags (mbox, &flags);
-  if ((flags & MU_STREAM_READ) == 0)
+  if (flags & MU_STREAM_WRITE)
     {
       status = mu_mailbox_flush (mbox, expunge);
       if (status)
diff --git a/imap4d/copy.c b/imap4d/copy.c
index b25e1ee..7f9acad 100644
--- a/imap4d/copy.c
+++ b/imap4d/copy.c
@@ -52,7 +52,7 @@ imap4d_copy (struct imap4d_command *command, imap4d_tokbuf_t 
tok)
       int new_state = (rc == RESP_OK) ? command->success : command->failure;
       if (new_state != STATE_NONE)
        state = new_state;
-      return util_send ("%s %s\r\n", command->tag, text);
+      return util_send ("%s %s\n", command->tag, text);
     }
   return util_finish (command, rc, "%s", text);
 }
diff --git a/imap4d/fetch.c b/imap4d/fetch.c
index a36a097..ef8ae9a 100644
--- a/imap4d/fetch.c
+++ b/imap4d/fetch.c
@@ -689,39 +689,36 @@ static int
 fetch_io (mu_stream_t stream, size_t start, size_t size, size_t max)
 {
   mu_stream_t rfc = NULL;
+  
   size_t n = 0;
 
   mu_filter_create (&rfc, stream, "rfc822", MU_FILTER_ENCODE,
-                   MU_STREAM_READ|MU_STREAM_NO_CHECK|MU_STREAM_NO_CLOSE);
-
+                   MU_STREAM_READ|MU_STREAM_SEEK|MU_STREAM_NO_CLOSE);
+  
   if (start == 0 && size == (size_t) -1)
     {
-      char *buffer;
-      size_t bufsize;
       int rc;
       
-      for (bufsize = max; (buffer = malloc (bufsize)) == NULL; bufsize /= 2)
-       if (bufsize < 512)
-         imap4d_bye (ERR_NO_MEM);
-
       rc = mu_stream_seek (rfc, 0, MU_SEEK_SET, NULL);
       if (rc)
        {
-         mu_error ("seek error: %s", mu_stream_strerror (rfc, rc));
+         mu_error ("seek error: %s", mu_stream_strerror (stream, rc));
          return RESP_BAD;
        }
       if (max)
        {
-         util_send (" {%lu}\r\n", (unsigned long) max);
-         while (mu_stream_read (rfc, buffer, bufsize, &n) == 0 && n > 0)
-           util_send_bytes (buffer, n);
-
+         util_send (" {%lu}\n", (unsigned long) max);
+         util_copy_out (rfc, max);
          /* FIXME: Make sure exactly max bytes were sent */
-          free (buffer); 
        }
       else
        util_send (" \"\"");
     }
+  else if (start > max)
+    {
+      util_send ("<%lu>", (unsigned long) start);
+      util_send (" \"\"");
+    }
   else if (size + 2 < size) /* Check for integer overflow */
     {
       mu_stream_destroy (&rfc);
@@ -737,16 +734,17 @@ fetch_io (mu_stream_t stream, size_t start, size_t size, 
size_t max)
       if (!p)
        imap4d_bye (ERR_NO_MEM);
 
-      rc = mu_stream_seek (stream, start, MU_SEEK_SET, NULL);
+      rc = mu_stream_seek (rfc, start, MU_SEEK_SET, NULL);
       if (rc)
        {
          mu_error ("seek error: %s", mu_stream_strerror (rfc, rc));
          free (buffer);
+         mu_stream_destroy (&rfc);
          return RESP_BAD;
        }
 
       while (total < size
-            && mu_stream_read (rfc, p, size - total + 1, &n) == 0
+            && mu_stream_read (rfc, p, size - total, &n) == 0
             && n > 0)
        {
          total += n;
@@ -756,7 +754,7 @@ fetch_io (mu_stream_t stream, size_t start, size_t size, 
size_t max)
       util_send ("<%lu>", (unsigned long) start);
       if (total)
        {
-         util_send (" {%lu}\r\n", (unsigned long) total);
+         util_send (" {%lu}\n", (unsigned long) total);
          util_send_bytes (buffer, total);
        }
       else
@@ -1085,6 +1083,7 @@ _frt_header_fields (struct fetch_function_closure *ffc,
   
   /* Output collected data */
   mu_stream_size (stream, &size);
+  mu_stream_seek (stream, 0, MU_SEEK_SET, NULL);
   status = fetch_io (stream, ffc->start, ffc->size, size + lines);
   mu_stream_destroy (&stream);
   
@@ -1657,7 +1656,7 @@ imap4d_fetch0 (imap4d_tokbuf_t tok, int isuid, char 
**err_text)
              util_send ("* %lu FETCH (", (unsigned long) frc.msgno);
              frc.eltno = 0;
              rc = mu_list_do (pclos.fnlist, _do_fetch, &frc);
-             util_send (")\r\n");
+             util_send (")\n");
            }
        }
       }
@@ -1693,4 +1692,3 @@ imap4d_fetch (struct imap4d_command *command, 
imap4d_tokbuf_t tok)
   rc = imap4d_fetch0 (tok, 0, &err_text);
   return util_finish (command, rc, "%s", err_text);
 }
-
diff --git a/imap4d/id.c b/imap4d/id.c
index f8c261c..353d3fe 100644
--- a/imap4d/id.c
+++ b/imap4d/id.c
@@ -202,7 +202,7 @@ imap4d_id (struct imap4d_command *command, imap4d_tokbuf_t 
tok)
        }
       mu_iterator_destroy (&itr);
       if (outcnt)
-       util_send (")\r\n");
+       util_send (")\n");
     }
   return util_finish (command, RESP_OK, "Completed");
 }
diff --git a/imap4d/idle.c b/imap4d/idle.c
index e3ddd6c..e8e7b8c 100644
--- a/imap4d/idle.c
+++ b/imap4d/idle.c
@@ -32,7 +32,7 @@ imap4d_idle (struct imap4d_command *command, imap4d_tokbuf_t 
tok)
   if (util_wait_input (0) == -1)
     return util_finish (command, RESP_NO, "Cannot idle");
 
-  util_send ("+ idling\r\n");
+  util_send ("+ idling\n");
   util_flush_output ();
 
   start = time (NULL);
diff --git a/imap4d/imap4d.c b/imap4d/imap4d.c
index b180206..ea492a0 100644
--- a/imap4d/imap4d.c
+++ b/imap4d/imap4d.c
@@ -383,18 +383,22 @@ get_client_address (int fd, struct sockaddr_in *pcs)
   return 0;
 }
 
+void
+imap4d_child_signal_setup (RETSIGTYPE (*handler) (int signo))
+{
+  static int sigtab[] = { SIGILL, SIGBUS, SIGFPE, SIGSEGV, SIGSTOP, SIGPIPE,
+                         SIGABRT, SIGINT, SIGQUIT, SIGTERM, SIGHUP, SIGALRM };
+  mu_set_signals (handler, sigtab, MU_ARRAY_SIZE (sigtab));
+}
+
 static int
 imap4d_mainloop (int fd, FILE *infile, FILE *outfile)
 {
   imap4d_tokbuf_t tokp;
   char *text;
   int debug_mode = isatty (fd);
-  static int sigtab[] = { SIGILL, SIGBUS, SIGFPE, SIGSEGV, SIGSTOP, SIGPIPE,
-                         SIGABRT, SIGINT, SIGQUIT, SIGTERM, SIGHUP, SIGALRM };
 
-  /* Reset signals */
-  mu_set_signals (imap4d_child_signal, sigtab, MU_ARRAY_SIZE (sigtab));
-  
+  imap4d_child_signal_setup (imap4d_child_signal);
   util_setio (infile, outfile);
 
   if (imap4d_preauth_setup (fd) == 0)
diff --git a/imap4d/imap4d.h b/imap4d/imap4d.h
index 1d9378d..6a01e46 100644
--- a/imap4d/imap4d.h
+++ b/imap4d/imap4d.h
@@ -202,7 +202,7 @@ extern int imap4d_transcript;
 extern mu_list_t imap4d_id_list;
 extern int imap4d_argc;                 
 extern char **imap4d_argv;
-  
+
 #ifndef HAVE_STRTOK_R
 extern char *strtok_r (char *s, const char *delim, char **save_ptr);
 #endif
@@ -334,6 +334,8 @@ extern int  util_send (const char *, ...) 
MU_PRINTFLIKE(1,2);
 extern int  util_send_bytes (const char *buf, size_t size);
 extern int  util_send_qstring (const char *);
 extern int  util_send_literal (const char *);
+extern int  util_copy_out (mu_stream_t str, size_t size);
+
 extern int  util_start (char *);
 extern int  util_finish (struct imap4d_command *, int, const char *, ...) 
                          MU_PRINTFLIKE(3,4);
diff --git a/imap4d/list.c b/imap4d/list.c
index 7ee42be..c7f42e4 100644
--- a/imap4d/list.c
+++ b/imap4d/list.c
@@ -97,11 +97,11 @@ list_fun (mu_folder_t folder, struct mu_list_response 
*resp, void *data)
   name = refinfo->buf;
   
   if (strpbrk (name, "\"{}"))
-    util_send ("{%lu}\r\n%s\r\n", (unsigned long) strlen (name), name);
+    util_send ("{%lu}\n%s\n", (unsigned long) strlen (name), name);
   else if (is_atom (name))
-    util_send ("%s\r\n", name);
+    util_send ("%s\n", name);
   else
-    util_send ("\"%s\"\r\n", name);
+    util_send ("\"%s\"\n", name);
   return 0;
 }
 
diff --git a/imap4d/namespace.c b/imap4d/namespace.c
index abe21cd..5fd1408 100644
--- a/imap4d/namespace.c
+++ b/imap4d/namespace.c
@@ -126,7 +126,7 @@ imap4d_namespace (struct imap4d_command *command, 
imap4d_tokbuf_t tok)
   print_namespace (NS_OTHER);
   util_send (" ");
   print_namespace (NS_SHARED);
-  util_send ("\r\n");
+  util_send ("\n");
 
   return util_finish (command, RESP_OK, "Completed");
 }
diff --git a/imap4d/preauth.c b/imap4d/preauth.c
index 3168286..d26efc8 100644
--- a/imap4d/preauth.c
+++ b/imap4d/preauth.c
@@ -366,7 +366,7 @@ do_preauth_ident (struct sockaddr *clt_sa, struct sockaddr 
*srv_sa)
       return NULL;
     }
 
-  mu_stream_printf (stream, "%u , %u\r\n",
+  mu_stream_printf (stream, "%u , %u\n",
                    ntohs (clt_addr->sin_port),
                    ntohs (srv_addr->sin_port));
   mu_stream_shutdown (stream, MU_STREAM_WRITE);
diff --git a/imap4d/search.c b/imap4d/search.c
index 33d2aa2..1163ce9 100644
--- a/imap4d/search.c
+++ b/imap4d/search.c
@@ -363,7 +363,7 @@ do_search (struct parsebuf *pb)
            util_send (" %s", mu_umaxtostr (0, pb->msgno));
        }
     }
-  util_send ("\r\n");
+  util_send ("\n");
 }
 
 /* Parse buffer functions */
diff --git a/imap4d/select.c b/imap4d/select.c
index dcf3fe0..2e2142b 100644
--- a/imap4d/select.c
+++ b/imap4d/select.c
@@ -74,9 +74,9 @@ imap4d_select0 (struct imap4d_command *command, const char 
*mboxname,
        {
          free (mailbox_name);
          /* Need to set the state explicitely for select.  */
-         return util_send ("%s OK [%s] %s Completed\r\n", command->tag,
-                           (flags & MU_STREAM_READ)  ?
-                           "READ-ONLY" : "READ-WRITE", command->name);
+         return util_send ("%s OK [%s] %s Completed\n", command->tag,
+                           ((flags & MU_STREAM_RDWR) == MU_STREAM_RDWR) ?
+                           "READ-WRITE" : "READ-ONLY", command->name);
        }
     }
   
@@ -119,7 +119,7 @@ imap4d_select_status ()
   /* FIXME:
      - '\*' can be supported if we use the attribute_set userflag()
      - Answered is still not set in the mailbox code.  */
-  if (select_flags & MU_STREAM_READ)
+  if (!(select_flags & MU_STREAM_WRITE))
     util_out (RESP_OK, "[PERMANENTFLAGS ()] No Permanent flags");
   else
     util_out (RESP_OK, "[PERMANENTFLAGS (%s)] Permanent flags", pflags);
diff --git a/imap4d/signal.c b/imap4d/signal.c
index c9dcfc5..d71138e 100644
--- a/imap4d/signal.c
+++ b/imap4d/signal.c
@@ -49,21 +49,25 @@ imap4d_master_signal (int signo)
 RETSIGTYPE
 imap4d_child_signal (int signo)
 {
+  imap4d_child_signal_setup (SIG_IGN);
   mu_diag_output (MU_DIAG_CRIT, _("got signal `%s'"), strsignal (signo));
-
   switch (signo)
     {
     case SIGTERM:
     case SIGHUP:
-      imap4d_bye (ERR_TERMINATE);
-
+      signo = ERR_TERMINATE;
+      break;
+      
     case SIGALRM:
-      imap4d_bye (ERR_TIMEOUT);
-
+      signo = ERR_TIMEOUT;
+      break;
+      
     case SIGPIPE:
-      imap4d_bye (ERR_NO_OFILE);
+      signo = ERR_NO_OFILE;
+      break;
       
     default:
-      imap4d_bye (ERR_SIGNAL);
+      signo = ERR_SIGNAL;
     }
+  imap4d_bye (signo);
 }
diff --git a/imap4d/status.c b/imap4d/status.c
index 3933a79..3622c47 100644
--- a/imap4d/status.c
+++ b/imap4d/status.c
@@ -136,7 +136,7 @@ imap4d_status (struct imap4d_command *command, 
imap4d_tokbuf_t tok)
 
          
          if (count > 0)
-           util_send (")\r\n");
+           util_send (")\n");
          mu_mailbox_close (smbox);
        }
       mu_mailbox_destroy (&smbox);
diff --git a/imap4d/store.c b/imap4d/store.c
index ac06bdc..c043a3e 100644
--- a/imap4d/store.c
+++ b/imap4d/store.c
@@ -157,7 +157,7 @@ imap4d_store0 (imap4d_tokbuf_t tok, int isuid, char **ptext)
                util_send ("UID %lu ", (unsigned long) msgno);
              util_send ("FLAGS (");
              util_print_flags (attr);
-             util_send ("))\r\n");
+             util_send ("))\n");
            }
          /* Update the flags of uid table.  */
          imap4d_sync_flags (pclos.set[i]);
diff --git a/imap4d/util.c b/imap4d/util.c
index 8487161..26a1a8d 100644
--- a/imap4d/util.c
+++ b/imap4d/util.c
@@ -270,6 +270,12 @@ util_msgset (char *s, size_t ** set, int *n, int isuid)
 }
 
 int
+util_copy_out (mu_stream_t str, size_t size)
+{
+  return mu_stream_copy (ostream, str, size);
+}
+
+int
 util_send_bytes (const char *buf, size_t size)
 {
   return mu_stream_write (ostream, buf, size, NULL);
@@ -325,7 +331,7 @@ util_send_qstring (const char *buffer)
 int
 util_send_literal (const char *buffer)
 {
-  return util_send ("{%lu}\r\n%s", (unsigned long) strlen (buffer), buffer);
+  return util_send ("{%lu}\n%s", (unsigned long) strlen (buffer), buffer);
 }
 
 /* Send an unsolicited response.  */
@@ -337,7 +343,7 @@ util_out (int rc, const char *format, ...)
   int status = 0;
   va_list ap;
 
-  asprintf (&tempbuf, "* %s%s\r\n", sc2string (rc), format);
+  asprintf (&tempbuf, "* %s%s\n", sc2string (rc), format);
   va_start (ap, format);
   vasprintf (&buf, tempbuf, ap);
   va_end (ap);
@@ -346,7 +352,7 @@ util_out (int rc, const char *format, ...)
 
   if (imap4d_transcript)
     {
-      int len = strcspn (buf, "\r\n");
+      int len = strcspn (buf, "\n");
       mu_diag_output (MU_DIAG_DEBUG, "sent: %*.*s", len, len, buf);
     }
 
@@ -393,7 +399,7 @@ util_finish (struct imap4d_command *command, int rc, const 
char *format, ...)
 
   mu_stream_write (ostream, buf, strlen (buf), NULL);
   free (buf);
-  mu_stream_write (ostream, "\r\n", 2, NULL);
+  mu_stream_write (ostream, "\n", 2, NULL);
 
   /* Reset the state.  */
   if (rc == RESP_OK)
@@ -800,16 +806,24 @@ util_uidvalidity (mu_mailbox_t smbox, unsigned long 
*uidvp)
 void
 util_setio (FILE *in, FILE *out)
 {
+  mu_stream_t tmp;
+  
   if (!in)
     imap4d_bye (ERR_NO_IFILE);
   if (!out)
     imap4d_bye (ERR_NO_OFILE);
 
-  if (mu_stdio_stream_create (&istream, fileno (in), MU_STREAM_NO_CLOSE))
+  if (mu_stdio_stream_create (&tmp, fileno (in), MU_STREAM_NO_CLOSE))
     imap4d_bye (ERR_NO_IFILE);
-  if (mu_stdio_stream_create (&ostream, fileno (out), MU_STREAM_NO_CLOSE))
-    imap4d_bye (ERR_NO_OFILE);
+  mu_stream_set_buffer (tmp, mu_buffer_line, 1024);
+  mu_filter_create (&istream, tmp, "rfc822", MU_FILTER_DECODE, MU_STREAM_READ);
   mu_stream_set_buffer (istream, mu_buffer_line, 1024);
+  
+  if (mu_stdio_stream_create (&tmp, fileno (out), MU_STREAM_NO_CLOSE))
+    imap4d_bye (ERR_NO_OFILE);
+  mu_stream_set_buffer (tmp, mu_buffer_line, 1024);
+  mu_filter_create (&ostream, tmp, "rfc822", MU_FILTER_ENCODE,
+                   MU_STREAM_WRITE);
   mu_stream_set_buffer (ostream, mu_buffer_line, 1024);
 }
 
@@ -917,7 +931,7 @@ void
 util_bye ()
 {
   int rc = istream != ostream;
-  
+
   mu_stream_close (istream);
   mu_stream_destroy (&istream);
 
@@ -926,7 +940,6 @@ util_bye ()
       mu_stream_close (ostream);
       mu_stream_destroy (&ostream);
     }
-      
   mu_list_do (atexit_list, atexit_run, 0);
 }
 
@@ -1021,30 +1034,6 @@ is_atom (const char *s)
      
 
 static size_t
-remove_cr (char *line, size_t len)
-{
-  char *prev = NULL;
-  size_t rlen = len;
-  char *p;
-  while ((p = memchr (line, '\r', len)))
-    {
-      if (prev)
-       {
-         memmove (prev, line, p - line);
-         prev += p - line;
-       }
-      else
-       prev = p;
-      rlen--;
-      len -= p - line + 1;
-      line = p + 1;
-    }
-  if (prev)
-    memmove (prev, line, len);
-  return rlen;
-}
-
-static size_t
 unquote (char *line, size_t len)
 {
   char *prev = NULL;
@@ -1318,7 +1307,7 @@ imap4d_readline (struct imap4d_tokbuf *tok)
          /* Client can ask for non-synchronised literal,
             if a '+' is appended to the octet count. */
          if (*sp == '}')
-           util_send ("+ GO AHEAD\r\n");
+           util_send ("+ GO AHEAD\n");
          else if (*sp != '+')
            break;
          imap4d_tokbuf_expand (tok, number + 1);
@@ -1334,7 +1323,6 @@ imap4d_readline (struct imap4d_tokbuf *tok)
                len += sz;
             }
          check_input_err (rc, len);
-         len = remove_cr (buf, len);
          imap4d_tokbuf_unquote (tok, &off, &len);
          tok->level += len;
          tok->buffer[tok->level++] = 0;
diff --git a/lib/signal.c b/lib/signal.c
index 8f5b615..8ce2108 100644
--- a/lib/signal.c
+++ b/lib/signal.c
@@ -26,7 +26,16 @@ void
 mu_set_signals (RETSIGTYPE (*handler) (int signo), int *sigv, int sigc)
 {
   int i;
+  struct sigaction act;
 
+  act.sa_flags = 0;
+  sigemptyset (&act.sa_mask);
   for (i = 0; i < sigc; i++)
-    signal (sigv[i], handler);
+    sigaddset (&act.sa_mask, i);
+      
+  for (i = 0; i < sigc; i++)
+    {
+      act.sa_handler = handler;
+      sigaction (sigv[i], &act, NULL);
+    }
 }
diff --git a/libproto/mbox/mbox.c b/libproto/mbox/mbox.c
index 5bb043c..98d288d 100644
--- a/libproto/mbox/mbox.c
+++ b/libproto/mbox/mbox.c
@@ -1087,6 +1087,8 @@ append_message_to_stream (mu_stream_t ostr, mu_message_t 
msg,
     }
   status = mu_stream_copy (ostr, istr, 0);
   mu_stream_destroy (&istr);
+  if (status == 0)
+    status = mu_stream_write (ostr, "\n", 1, NULL);
   return status;
 }
 
diff --git a/mailbox/fltstream.c b/mailbox/fltstream.c
index 99b5a47..90575a4 100644
--- a/mailbox/fltstream.c
+++ b/mailbox/fltstream.c
@@ -117,73 +117,78 @@ filter_read (mu_stream_t stream, char *buf, size_t size, 
size_t *pret)
   
   while (total < size && cmd != mu_filter_lastbuf)
     {
-      enum mu_filter_result res;
-      int rc;
       size_t rdsize;
 
-      if (MFB_RDBYTES (fs->inbuf) < min_input_level)
+      if (MFB_RDBYTES (fs->outbuf) == 0)
        {
-         rc = MFB_require (&fs->inbuf, min_input_level);
-         if (rc)
-           return rc;
-         rc = mu_stream_read (fs->transport,
-                              MFB_ENDPTR (fs->inbuf),
-                              MFB_FREESIZE (fs->inbuf),
-                              &rdsize);
+         enum mu_filter_result res;
+         int rc;
+         
+         if (MFB_RDBYTES (fs->inbuf) < min_input_level)
+           {
+             rc = MFB_require (&fs->inbuf, min_input_level);
+             if (rc)
+               return rc;
+             rc = mu_stream_read (fs->transport,
+                                  MFB_ENDPTR (fs->inbuf),
+                                  MFB_FREESIZE (fs->inbuf),
+                                  &rdsize);
+             if (rc)
+               return rc;
+             if (rdsize == 0 &&
+                 MFB_RDBYTES (fs->outbuf) == 0
+                 && MFB_RDBYTES (fs->inbuf) == 0)
+               break;
+             MFB_advance_level (&fs->inbuf, rdsize);
+           }
+
+         if (min_output_size < MFB_RDBYTES (fs->inbuf))
+           min_output_size = MFB_RDBYTES (fs->inbuf);
+         rc = MFB_require (&fs->outbuf, min_output_size);
          if (rc)
            return rc;
-         if (rdsize == 0 &&
-             MFB_RDBYTES (fs->outbuf) == 0 && MFB_RDBYTES (fs->inbuf) == 0)
-           break;
-         MFB_advance_level (&fs->inbuf, rdsize);
-       }
-
-      if (min_output_size < MFB_RDBYTES (fs->inbuf))
-       min_output_size = MFB_RDBYTES (fs->inbuf);
-      rc = MFB_require (&fs->outbuf, min_output_size);
-      if (rc)
-       return rc;
       
-      init_iobuf (&iobuf, fs);
+         init_iobuf (&iobuf, fs);
 
-      cmd = mu_stream_eof (fs->transport) ?
-              mu_filter_lastbuf : mu_filter_xcode;
-      res = fs->xcode (fs->xdata, cmd, &iobuf);
-      switch (res)
-       {
-       case mu_filter_ok:
-         if (iobuf.isize == 0 || iobuf.osize == 0)
+         cmd = mu_stream_eof (fs->transport) ?
+           mu_filter_lastbuf : mu_filter_xcode;
+         res = fs->xcode (fs->xdata, cmd, &iobuf);
+         switch (res)
            {
-             /* FIXME: Hack to handle eventual buggy filters */
-             if (iobuf.isize == 0)
-               min_input_level++;
-             if (iobuf.osize == 0)
-               min_output_size++;
+           case mu_filter_ok:
+             if (iobuf.isize == 0 || iobuf.osize == 0)
+               {
+                 /* FIXME: Hack to handle eventual buggy filters */
+                 if (iobuf.isize == 0)
+                   min_input_level++;
+                 if (iobuf.osize == 0)
+                   min_output_size++;
+                 continue;
+               }
+             if (iobuf.isize > MFB_RDBYTES (fs->inbuf)
+                 || iobuf.osize > MFB_FREESIZE (fs->outbuf))
+               return MU_ERR_FAILURE; /* FIXME: special error code? */
+             break;
+         
+           case mu_filter_falure:
+             return iobuf.errcode;
+             
+           case mu_filter_moreinput:
+             min_input_level = iobuf.isize;
+             continue;
+             
+           case mu_filter_moreoutput:
+             min_output_size = iobuf.osize;
              continue;
            }
-         if (iobuf.isize > MFB_RDBYTES (fs->inbuf)
-             || iobuf.osize > MFB_FREESIZE (fs->outbuf))
-           return MU_ERR_FAILURE; /* FIXME: special error code? */
-         break;
-         
-       case mu_filter_falure:
-         return iobuf.errcode;
-         
-       case mu_filter_moreinput:
-         min_input_level = iobuf.isize;
-         continue;
+      
+         /* iobuf.osize contains number of bytes written to output */
+         MFB_advance_level (&fs->outbuf, iobuf.osize);
          
-       case mu_filter_moreoutput:
-         min_output_size = iobuf.osize;
-         continue;
+         /* iobuf.isize contains number of bytes read from input */
+         MFB_advance_pos (&fs->inbuf, iobuf.isize);
        }
-      
-      /* iobuf.osize contains number of bytes written to output */
-      MFB_advance_level (&fs->outbuf, iobuf.osize);
-      
-      /* iobuf.isize contains number of bytes read from input */
-      MFB_advance_pos (&fs->inbuf, iobuf.isize);
-      
+
       rdsize = size - total;
       if (rdsize > MFB_RDBYTES (fs->outbuf))
        rdsize = MFB_RDBYTES (fs->outbuf);
diff --git a/mailbox/mapfile_stream.c b/mailbox/mapfile_stream.c
index 94d3f52..0b60147 100644
--- a/mailbox/mapfile_stream.c
+++ b/mailbox/mapfile_stream.c
@@ -316,7 +316,7 @@ _mapfile_seek (struct _mu_stream *str, mu_off_t off, 
mu_off_t *presult)
 { 
   struct _mu_mapfile_stream *mfs = (struct _mu_mapfile_stream *) str;
   
-  if (off < 0 || off >= mfs->size)
+  if (off < 0 || off > mfs->size)
     return ESPIPE;
   mfs->offset = off;
   *presult = off;
diff --git a/mailbox/stream.c b/mailbox/stream.c
index 2bc2117..b064421 100644
--- a/mailbox/stream.c
+++ b/mailbox/stream.c
@@ -80,9 +80,9 @@ _stream_fill_buffer (struct _mu_stream *stream)
           n < stream->bufsize
             && (rc = mu_stream_read_unbuffered (stream,
                                                 &c, 1, 0, &rdn)) == 0
-            && rdn; n++)
+            && rdn; )
        {
-         stream->buffer[n] = c;
+         stream->buffer[n++] = c;
          if (c == '\n')
            break;
        }
@@ -368,10 +368,10 @@ mu_stream_skip_input_bytes (mu_stream_t stream, mu_off_t 
count, mu_off_t *pres)
     }
   else
     {
-      if ((rc = _stream_flush_buffer (stream, 1)))
-       return rc;
       for (pos = 0;;)
        {
+         if ((rc = _stream_flush_buffer (stream, 1)))
+           return rc;
          if (stream->level == 0)
            {
              rc = _stream_fill_buffer (stream);
@@ -385,11 +385,13 @@ mu_stream_skip_input_bytes (mu_stream_t stream, mu_off_t 
count, mu_off_t *pres)
            }
          if (pos <= count && count < pos + stream->level)
            {
-             rc = 0;
-             stream->cur = stream->buffer + count - pos;
+             size_t delta = count - pos;
+             _stream_advance_buffer (stream, delta);
              pos = count;
+             rc = 0;
              break;
            }
+         pos += stream->level;
        }
     }
   


hooks/post-receive
-- 
GNU Mailutils




reply via email to

[Prev in Thread] Current Thread [Next in Thread]