* dump message headers on artv dump
authorWilfried Göesgens <willi@citadel.org>
Sun, 4 Nov 2007 23:19:17 +0000 (23:19 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sun, 4 Nov 2007 23:19:17 +0000 (23:19 +0000)
* some more tweaking on buffered reading.

citadel/citadel_ipc.c
citadel/debian/rules
citadel/modules/vandelay/serv_vandelay.c
citadel/msgbase.c
citadel/msgbase.h
citadel/sendcommand.c
citadel/sysdep.c

index 6b097551d1d50234c7530f0bae7d08f9eda0097d..891facb3481974727804a24aee5f1941f2f6e95f 100644 (file)
@@ -2640,7 +2640,7 @@ static void serv_read(CtdlIPC *ipc, char *buf, unsigned int bytes)
 /*
  * send binary to server
  */
-static void serv_write(CtdlIPC *ipc, const char *buf, unsigned int nbytes)
+void serv_write(CtdlIPC *ipc, const char *buf, unsigned int nbytes)
 {
        unsigned int bytes_written = 0;
        int retval;
@@ -2858,25 +2858,26 @@ int
 ReadNetworkChunk(CtdlIPC* ipc)
 {
        fd_set read_fd;
+       int tries;
        int ret = 0;
        int err = 0;
        struct timeval tv;
+       size_t n;
 
        tv.tv_sec = 1;
-       tv.tv_usec = 0;
+       tv.tv_usec = 1000;
+       tries = 0;
+       n = 0;
        while (1)
        {
+               errno=0;
                FD_ZERO(&read_fd);
                FD_SET(ipc->sock, &read_fd);
                ret = select(ipc->sock+1, &read_fd, NULL, NULL,  &tv);
-               if (ret == -1) {
-                       if (!(errno == EINTR || errno == EAGAIN))
-                               fprintf(stderr, "\nselect failed: %d %s\n", err, strerror(err));
-                       return -1;
-               }
                
-               if (ret != 0) {
-                       size_t n;
+//             fprintf(stderr, "\nselect failed: %d %d %s\n", ret,  err, strerror(err));
+               
+               if (ret > 0) {
                        
                        *(ipc->BufPtr) = '\0';
                        n = read(ipc->sock, ipc->BufPtr, ipc->BufSize  - (ipc->BufPtr - ipc->Buf) - 1);
@@ -2885,7 +2886,28 @@ ReadNetworkChunk(CtdlIPC* ipc)
                                ipc->BufUsed += n;
                                return n;
                        }
+                       else 
+                               return n;
                }
+               else if (ret < 0) {
+                       if (!(errno == EINTR || errno == EAGAIN))
+                               error_printf( "\nselect failed: %d %s\n", err, strerror(err));
+                       return -1;
+               }/*
+               else {
+                       tries ++;
+                       if (tries >= 10)
+                       n = read(ipc->sock, ipc->BufPtr, ipc->BufSize  - (ipc->BufPtr - ipc->Buf) - 1);
+                       if (n > 0) {
+                               ipc->BufPtr[n]='\0';
+                               ipc->BufUsed += n;
+                               return n;
+                       }
+                       else {
+                               connection_died(ipc, 0);
+                               return -1;
+                       }
+                       }*/
        }
 }
 
@@ -2894,9 +2916,11 @@ ReadNetworkChunk(CtdlIPC* ipc)
  */
 static void CtdlIPC_getline(CtdlIPC* ipc, char *buf)
 {
-       int i;
+       int i, ntries;
        char *aptr, *bptr, *aeptr, *beptr;
 
+//     error_printf("---\n");
+
        beptr = buf + SIZ;
 #if defined(HAVE_OPENSSL)
        if (ipc->ssl) {
@@ -2928,10 +2952,12 @@ static void CtdlIPC_getline(CtdlIPC* ipc, char *buf)
                        ipc->BufPtr = ipc->Buf;
                }
 
+               ntries = 0;
+//             while ((ipc->BufUsed == 0)||(ntries++ > 10))
                if (ipc->BufUsed == 0)
-                       while ( ReadNetworkChunk(ipc) < 0 )
-                               sleep (1);
+                       ReadNetworkChunk(ipc);
 
+////           if (ipc->BufUsed != 0) while (1)
                bptr = buf;
 
                while (1)
@@ -2951,7 +2977,7 @@ static void CtdlIPC_getline(CtdlIPC* ipc, char *buf)
                                while ((aptr < aeptr ) && (*(aptr + 1) == '\0') )
                                        aptr ++;
                                *(bptr++) = '\0';
-//                             fprintf(stderr, "parsing %d %d %d - %d %d %d\n", ipc->BufPtr - ipc->Buf, aptr - ipc->BufPtr, ipc->BufUsed , *aptr, *(aptr-1), *(aptr+1));
+//                             fprintf(stderr, "parsing %d %d %d - %d %d %d %s\n", ipc->BufPtr - ipc->Buf, aptr - ipc->BufPtr, ipc->BufUsed , *aptr, *(aptr-1), *(aptr+1), buf);
                                if ((bptr > buf + 1) && (*(bptr-1) == '\r'))
                                        *(--bptr) = '\0';
                                
@@ -2965,6 +2991,7 @@ static void CtdlIPC_getline(CtdlIPC* ipc, char *buf)
                                        ipc->BufUsed = 0;
                                        ipc->BufPtr = ipc->Buf;
                                }
+//                             error_printf("----bla6\n");
                                return;
                                
                        }/* should we move our read stuf to the bufferstart so we have more space at the end? */
@@ -2984,9 +3011,14 @@ static void CtdlIPC_getline(CtdlIPC* ipc, char *buf)
                                ipc->BufSize = NewBufSize;
                        }
                        if (ReadNetworkChunk(ipc) <0)
+                       {
+//                             error_printf("----bla\n");
                                return;
+                       }
                }
+///            error_printf("----bl45761%s\nipc->BufUsed");
        }
+//     error_printf("----bla1\n");
 }
 
 void CtdlIPC_chat_recv(CtdlIPC* ipc, char* buf)
index c0ca8031ced686c11f5ed43d536e1bc607eec81e..4c651a403fc6fe151758504c12f5b23916dd3c56 100755 (executable)
@@ -13,7 +13,7 @@ CFLAGS = -Wall -g
 
 EXTRA_ARGS=
 PROFILE_ARGS=
-#to enable debugging: export DEB_BUILD_OPTIONS="debug profiling"
+#to enable debugging: export DEB_BUILD_OPTIONS="debug profiling threadoff"
 ifneq (,$(findstring profiling,$(DEB_BUILD_OPTIONS)))
        PROFILE_ARGS= --with-gprof
 endif
@@ -24,6 +24,12 @@ else
        CFLAGS += -O2
 endif
 
+ifneq (,$(findstring threadoff,$(DEB_BUILD_OPTIONS)))
+       THREAD_ARGS=--without-threaded-client
+else
+       THREAD_ARGS=
+endif
+
 configure: configure-stamp
 configure-stamp:
        dh_testdir
@@ -44,7 +50,7 @@ configure-stamp:
                --with-ldap \
                --with-libical \
                --with-libsieve \
-               --enable-debug $(EXTRA_ARGS) $(PROFILE_ARGS)
+               --enable-debug $(EXTRA_ARGS) $(PROFILE_ARGS) $(THREAD_ARGS)
 
        touch configure-stamp
 
index c50f4dc2a069845b7db2c8dabf3162ffd02c39ea..c79e1eeee6b2c5ed1a468fb2adf85e3fc5215995 100644 (file)
@@ -366,10 +366,6 @@ void artv_export_message(long msgnum) {
 void artv_dump_message(long msgnum) {
        struct MetaData smi;
        struct CtdlMessage *msg;
-       struct ser_ret smr;
-       FILE *fp;
-       char buf[SIZ];
-       char tempfile[PATH_MAX];
 
        msg = CtdlFetchMessage(msgnum, 1);
        if (msg == NULL) return;        /* fail silently */
@@ -380,27 +376,9 @@ void artv_dump_message(long msgnum) {
        cprintf(" MetaRefcount: %d\n", smi.meta_refcount);
        cprintf(" MetaContentType: %s\n", smi.meta_content_type);
 
-       serialize_message(&smr, msg);
+       dump_message(msg, 80);
        CtdlFreeMessage(msg);
 
-       /* write it in base64 * /
-       CtdlMakeTempFileName(tempfile, sizeof tempfile);
-       snprintf(buf, sizeof buf, "%s -e >%s", file_base64, tempfile);
-       fp = popen(buf, "w");
-       fwrite(smr.ser, smr.len, 1, fp);
-       pclose(fp);
-
-       free(smr.ser);
-
-       fp = fopen(tempfile, "r");
-       unlink(tempfile);
-       if (fp != NULL) {
-               while (fgets(buf, sizeof(buf), fp) != NULL) {
-                       buf[strlen(buf)-1] = 0;
-                       cprintf("%s\n", buf);
-               }
-               fclose(fp);
-               }*/
        cprintf("%s\n", END_OF_MESSAGE);
 }
 
@@ -513,7 +491,7 @@ void artv_do_dump(void) {
        /* export the config file (this is done using x-macros) */
        cprintf("config\n");
 
-#include "artv_serialize.h"
+#include "artv_dump.h"
 #include "dtds/config-defs.h"
 #include "undef_data.h"
 
index f914c85269f9c7496433a7721401fe1ffeeab4a7..733e34ad688baa1e3033e742a0c2d47079d02404 100644 (file)
@@ -1811,21 +1811,26 @@ START_TEXT:
         * what message transfer format is in use.
         */
        if (TheMessage->cm_format_type == FMT_FIXED) {
+               int buflen;
                if (mode == MT_MIME) {
                        cprintf("Content-type: text/plain\n\n");
                }
-               strcpy(buf, "");
+               *buf = '\0';
+               buflen = 0;
                while (ch = *mptr++, ch > 0) {
                        if (ch == 13)
                                ch = 10;
-                       if ((ch == 10) || (strlen(buf) > 250)) {
+                       if ((ch == 10) || (buflen > 250)) {
+                               buf[buflen] = '\0';
                                cprintf("%s%s", buf, nl);
-                               strcpy(buf, "");
+                               *buf = '\0';
+                               buflen = 0;
                        } else {
-                               buf[strlen(buf) + 1] = 0;
-                               buf[strlen(buf)] = ch;
+                               buf[buflen] = ch;
+                               buflen++;
                        }
                }
+               buf[buflen] = '\0';
                if (!IsEmptyStr(buf))
                        cprintf("%s%s", buf, nl);
        }
@@ -2315,6 +2320,43 @@ void serialize_message(struct ser_ret *ret,              /* return values */
 }
 
 
+/*
+ * Serialize a struct CtdlMessage into the format used on disk and network.
+ * 
+ * This function loads up a "struct ser_ret" (defined in server.h) which
+ * contains the length of the serialized message and a pointer to the
+ * serialized message in memory.  THE LATTER MUST BE FREED BY THE CALLER.
+ */
+void dump_message(struct CtdlMessage *msg,     /* unserialized msg */
+                 long Siz)                     /* how many chars ? */
+{
+       size_t wlen;
+       int i;
+       static char *forder = FORDER;
+       char *buf;
+
+       /*
+        * Check for valid message format
+        */
+       if (is_valid_message(msg) == 0) {
+               lprintf(CTDL_ERR, "dump_message() aborting due to invalid message\n");
+               return;
+       }
+
+       buf = (char*) malloc (Siz + 1);
+
+       wlen = 3;
+       
+       for (i=0; i<26; ++i) if (msg->cm_fields[(int)forder[i]] != NULL) {
+                       snprintf (buf, Siz, " msg[%c] = %s ...\n", (char) forder[i], 
+                                  msg->cm_fields[(int)forder[i]]);
+                       client_write (buf, strlen(buf));
+               }
+
+       return;
+}
+
+
 
 /*
  * Check to see if any messages already exist in the current room which
index fa5d06f647634b342122c257afb9e16d42647cfb..ca0e6f0ac83129d4024955fb3a456a94ed0f4dd6 100644 (file)
@@ -124,6 +124,7 @@ void CtdlWriteObject(char *, char *, char *, struct ctdluser *,
 struct CtdlMessage *CtdlFetchMessage(long msgnum, int with_body);
 void CtdlFreeMessage(struct CtdlMessage *msg);
 void serialize_message(struct ser_ret *, struct CtdlMessage *);
+void dump_message(struct CtdlMessage *msg, long Siz);
 int is_valid_message(struct CtdlMessage *);
 void ReplicationChecks(struct CtdlMessage *);
 int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newmsgs,
index c7439dc0dbca681423020307810a64c8ff905f56..9b331cc2456d44df78ab9ad3932d367a80608c19 100644 (file)
@@ -77,12 +77,40 @@ void nq_cleanup(int e)
        exit(e);
 }
 
+/*
+ * send binary to server
+ */
+void serv_write(CtdlIPC *ipc, const char *buf, unsigned int nbytes)
+{
+       unsigned int bytes_written = 0;
+       int retval;
+/*
+#if defined(HAVE_OPENSSL)
+       if (ipc->ssl) {
+               serv_write_ssl(ipc, buf, nbytes);
+               return;
+       }
+#endif
+*/
+       while (bytes_written < nbytes) {
+               retval = write(ipc->sock, &buf[bytes_written],
+                              nbytes - bytes_written);
+               if (retval < 1) {
+                       connection_died(ipc, 0);
+                       return;
+               }
+               bytes_written += retval;
+       }
+}
+
+
 void cleanup(int e)
 {
        static int nested = 0;
 
        alarm(30);
        signal(SIGALRM, nq_cleanup);
+       serv_write(ipc, "\n", 1);
        if (nested++ < 1)
                CtdlIPCQuit(ipc);
        nq_cleanup(e);
index f7cfe8e2e693137382245371dee570639b1fe306..182c0df7d1b0795b098eb566d092025ca9d95f53 100644 (file)
@@ -632,7 +632,7 @@ void client_write(char *buf, int nbytes)
                                "client_write(%d bytes) failed: %s (%d)\n",
                                nbytes - bytes_written,
                                strerror(errno), errno);
-                       // cit_backtrace();
+                       cit_backtrace();
                        // lprintf(CTDL_DEBUG, "Tried to send: %s",  &buf[bytes_written]);
                        Ctx->kill_me = 1;
                        return;