* output_image() now reads the entire image from Citadel into a buffer before
authorArt Cancro <ajc@citadel.org>
Sat, 14 Sep 2002 16:26:35 +0000 (16:26 +0000)
committerArt Cancro <ajc@citadel.org>
Sat, 14 Sep 2002 16:26:35 +0000 (16:26 +0000)
  sending it to the browser (for performance reasons, and so it can compress)

webcit/ChangeLog
webcit/webcit.c

index 0daab4976133222b0d7b614eb6d0a1a462107695..a95f0738292acda3b19d787bf72192e1a87e6d70 100644 (file)
@@ -1,4 +1,8 @@
 $Log$
+Revision 400.6  2002/09/14 16:26:35  ajc
+* output_image() now reads the entire image from Citadel into a buffer before
+  sending it to the browser (for performance reasons, and so it can compress)
+
 Revision 400.5  2002/09/14 04:52:59  ajc
 * Look for the "libical" calendaring library and link it in if present...
 
@@ -953,4 +957,3 @@ Sun Dec  6 19:50:55 EST 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
 
 1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
        * webserver.c: warning fix
-
index d4d9cacc41f01bc46355aebc550ebc4298015749..f6e735087e14ac73b657df891db8854819971d74 100644 (file)
@@ -514,7 +514,7 @@ void output_static(char *what)
 void output_image()
 {
        char buf[SIZ];
-       char xferbuf[4096];
+       char *xferbuf = NULL;
        off_t bytes;
        off_t thisblock;
        off_t accomplished = 0L;
@@ -524,11 +524,9 @@ void output_image()
        serv_gets(buf);
        if (buf[0] == '2') {
                bytes = extract_long(&buf[4], 0);
-               output_headers(0);
-               wprintf("Content-type: image/gif\n");
-               wprintf("Content-length: %ld\n", (long) bytes);
-               wprintf("\n");
+               xferbuf = malloc(bytes);
 
+               /* Read it from the server */
                while (bytes > (off_t) 0) {
                        thisblock = (off_t) sizeof(xferbuf);
                        if (thisblock > bytes) {
@@ -538,17 +536,25 @@ void output_image()
                        serv_gets(buf);
                        if (buf[0] == '6') {
                                thisblock = extract_long(&buf[4], 0);
-                               serv_read(xferbuf, (int) thisblock);
+                               serv_read(&xferbuf[accomplished],
+                                       (int) thisblock);
                        }
                        else {
-                               memset(xferbuf, 0, thisblock);
+                               memset(&xferbuf[accomplished], 0, thisblock);
                        }
-                       http_write(WC->http_sock, xferbuf, thisblock);
                        bytes = bytes - thisblock;
-                       accomplished = accomplished + thisblock;
+                       accomplished += thisblock;
                }
                serv_puts("CLOS");
                serv_gets(buf);
+
+               /* Now write it to the browser */
+               output_headers(0);
+               wprintf("Content-type: image/gif\n");
+               wprintf("Content-length: %ld\n", (long) accomplished);
+               wprintf("\n");
+               http_write(WC->http_sock, xferbuf, accomplished);
+
        } else {
                wprintf("HTTP/1.0 404 %s\n", &buf[4]);
                output_headers(0);
@@ -557,6 +563,10 @@ void output_image()
                wprintf("Error retrieving image: %s\n", &buf[4]);
        }
 
+       if (xferbuf) {
+               free(xferbuf);
+       }
+
 }
 
 /*