]> code.citadel.org Git - citadel.git/commitdiff
* Began implementation of a third RedirectOutput mode -- one which writes
authorArt Cancro <ajc@citadel.org>
Tue, 1 Mar 2005 22:03:35 +0000 (22:03 +0000)
committerArt Cancro <ajc@citadel.org>
Tue, 1 Mar 2005 22:03:35 +0000 (22:03 +0000)
  to a memory buffer.  This will replace the other two.
* serv_pop3.c: began migration to the new redirect mode.

citadel/ChangeLog
citadel/serv_pop3.c
citadel/server.h
citadel/sysdep.c

index d83d1df64e5b77c8a85f7454f2c6efcd1d135bba..83c9d6cceb592a9784f23c2e5ac25b943f587627 100644 (file)
@@ -1,4 +1,9 @@
  $Log$
+ Revision 641.10  2005/03/01 22:03:35  ajc
+ * Began implementation of a third RedirectOutput mode -- one which writes
+   to a memory buffer.  This will replace the other two.
+ * serv_pop3.c: began migration to the new redirect mode.
+
  Revision 641.9  2005/03/01 04:24:52  ajc
  * When saving an RFC822 message, use a less expensive algorithm to
    search for the Content Type
@@ -6462,3 +6467,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import
+
index 668711f6967fd8afcb293a558e83aa4f545546c5..f1d4d32e86099419f8e6e555f03cb8b4e267d43e 100644 (file)
@@ -136,7 +136,6 @@ void pop3_user(char *argbuf) {
  * Back end for pop3_grab_mailbox()
  */
 void pop3_add_message(long msgnum, void *userdata) {
-       FILE *fp;
        struct MetaData smi;
 
        ++POP3->num_msgs;
@@ -153,12 +152,15 @@ void pop3_add_message(long msgnum, void *userdata) {
         */
        GetMetaData(&smi, POP3->num_msgs-1);
        if (smi.meta_rfc822_length <= 0L) {
-               fp = tmpfile();
-               CtdlRedirectOutput(fp, -1);
+               CC->redirect_buffer = malloc(SIZ);
+               CC->redirect_len = 0;
+               CC->redirect_alloc = SIZ;
                CtdlOutputMsg(msgnum, MT_RFC822, HEADERS_ALL, 0, 1);
-               CtdlRedirectOutput(NULL, -1);
-               smi.meta_rfc822_length = ftell(fp);
-               fclose(fp);
+               smi.meta_rfc822_length = CC->redirect_len;
+               free(CC->redirect_buffer);
+               CC->redirect_buffer = NULL;
+               CC->redirect_len = 0;
+               CC->redirect_alloc = 0;
                PutMetaData(&smi);
        }
        POP3->msgs[POP3->num_msgs-1].rfc822_length = smi.meta_rfc822_length;
index 99b8dccb6e03f08264af22dc4738ac19085e7d67..6de5716d740ed14ea3209b3b46be3e85803d5854 100644 (file)
@@ -124,6 +124,9 @@ struct CitContext {
        /* Redirect this session's output to somewhere else? */
        FILE *redirect_fp;
        int redirect_sock;
+       char *redirect_buffer;          /* the buffer */
+       size_t redirect_len;            /* length of data in buffer */
+       size_t redirect_alloc;          /* length of allocated buffer */
 #ifdef HAVE_OPENSSL
        SSL *ssl;
        int redirect_ssl;
index db6405a1fce4335361359b8737d29d8cfafc64a3..c8137cda397a0349b38dc7049179dc42e9cef02d 100644 (file)
@@ -547,6 +547,17 @@ void client_write(char *buf, int nbytes)
        int old_buffer_len = 0;
 #endif
 
+       if (CC->redirect_buffer != NULL) {
+               if (CC->redirect_len + nbytes >= CC->redirect_alloc) {
+                       CC->redirect_alloc = CC->redirect_alloc * 2;
+                       CC->redirect_buffer = realloc(CC->redirect_buffer,
+                                               CC->redirect_alloc);
+               }
+               memcpy(&CC->redirect_buffer[CC->redirect_len], buf, nbytes);
+               CC->redirect_len += nbytes;
+               return;
+       }
+
        if (CC->redirect_fp != NULL) {
                fwrite(buf, (size_t)nbytes, (size_t)1, CC->redirect_fp);
                return;