]> code.citadel.org Git - citadel.git/commitdiff
Fixed a bug which was here even before we started the groupware project: in
authorArt Cancro <ajc@citadel.org>
Sun, 26 Jul 1998 23:48:14 +0000 (23:48 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 26 Jul 1998 23:48:14 +0000 (23:48 +0000)
the inprocess() section of netproc.c, the sizes of incoming messages were
being miscalculated.  This caused significantly inflated (and possibly
corrupted) messages to be transmitted to the local Citadel server.  Symptoms
included lots of "Error trying to read 255 bytes" messages in the netproc log,
and (when using the GDBM-based development code) unacceptably large message
base sizes.  Now the bug is fixed and correct message sizes are being
calculated - using a more efficient algorithm, even.  I can envision one more
optimization, though: buffer the incoming messages in memory instead of
holding them in a temp file.  Perhaps next time...

citadel/netproc.c

index 49b912d7a932155951e81f46529fa671709722e7..974c44d8d7f943813bebaa64164929824e3740ec 100644 (file)
@@ -720,12 +720,14 @@ void inprocess() {
        struct recentmsg recentmsg;
        char tname[128],aaa[1024],iname[256],sfilename[256],pfilename[256];
        int a,b;
+       int FieldID;
        struct syslist *stemp;
        char *ptr = NULL;
        char buf[256];
        long msglen;
        int bloklen;
 
+
        sprintf(tname,"/tmp/net.t%d",getpid()); /* temp file name */
        sprintf(iname,"/tmp/net.i%d",getpid()); /* temp file name */
 
@@ -756,12 +758,12 @@ void inprocess() {
        fprintf(stderr,"netproc: processing <%s>\n", pfilename);
        fflush(stderr);
        
-       fp=fopen(pfilename,"r");
-       if(fp == NULL) {
+       fp = fopen(pfilename, "rb");
+       if (fp == NULL) {
            fprintf(stderr, "netproc: cannot open <%s>: %s\n",
-                       pfilename,strerror(errno));
+                       pfilename, strerror(errno));
            fflush(stderr);
-           fp = fopen("/dev/null","r");
+           fp = fopen("/dev/null" ,"rb");
            }
                
 NXMSG: /* Seek to the beginning of the next message */
@@ -769,21 +771,26 @@ NXMSG:    /* Seek to the beginning of the next message */
                a=getc(fp);
                } while((a!=255)&&(a>=0));
        if (a<0) goto ENDSTR;
-       message=fopen(tname,"wb");
-       putc(255,message);
+
+       message = fopen(tname,"wb");    /* This crates the temporary file. */
+       if (message == NULL) {
+               fprintf(stderr, "Error creating %s: %s\n",
+                       tname, strerror(errno));
+               goto ENDSTR;
+               }
+       putc(255,message);              /* 0xFF (start-of-message) */
+       a = getc(fp); putc(a, message); /* type */
+       a = getc(fp); putc(a, message); /* mode */
        do {
+               FieldID = getc(fp);     /* Header field ID */
+               putc(FieldID, message);
                do {
-                       a=getc(fp);
-                       putc(a,message);
-                       } while(a>0);
-               a=getc(fp);
-               putc(a,message);
-               } while ((a!='M') && (a>0));
-       do {
-               a=getc(fp);
-               putc(a,message);
-               } while(a>0);
-       msglen = ftell(fp);
+                       a = getc(fp);
+                       putc(a, message);
+                       } while (a > 0);
+               } while ((FieldID != 'M') && (a >= 0)); /* M is always last */
+
+       msglen = ftell(message);
        fclose(message);
 
        /* process the individual mesage */
@@ -917,11 +924,6 @@ NXMSG:     /* Seek to the beginning of the next message */
                        goto NXMSG;
                        }
 
-               /* Measure the message */
-               fseek(message, 0L, 2);
-               msglen = ftell(fp);
-               fseek(message, 0L, 0);
-
                /* Transmit the message to the server */
                sprintf(buf, "ENT3 1|%s|%ld", minfo.R, msglen);
                printf("< %s\n", buf);