]> code.citadel.org Git - citadel.git/commitdiff
* All functions which read binary data from the server now make use of the
authorArt Cancro <ajc@citadel.org>
Tue, 28 Jan 2003 15:37:12 +0000 (15:37 +0000)
committerArt Cancro <ajc@citadel.org>
Tue, 28 Jan 2003 15:37:12 +0000 (15:37 +0000)
  read_server_binary() function in tools.c
* Binary reads from server now have safety code to prevent infinite loops
* All output of MIME objects is now done with http_transmit_thing()

webcit/ChangeLog
webcit/tools.c
webcit/webcit.c

index dbfb53b463f65c5949ea78e427590b7e39c33682..778d74b161c3cf2dee2ef0597607eb52b5203c17 100644 (file)
@@ -1,4 +1,10 @@
 $Log$
+Revision 400.87  2003/01/28 15:37:12  ajc
+* All functions which read binary data from the server now make use of the
+  read_server_binary() function in tools.c
+* Binary reads from server now have safety code to prevent infinite loops
+* All output of MIME objects is now done with http_transmit_thing()
+
 Revision 400.86  2003/01/19 06:28:04  ajc
 * Minimum required Citadel version 6.05
 
@@ -1252,4 +1258,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 6912515cae5e1e73393c7ad88cbeb2a8de6d4977..b640141567da488278593e4e14dca50313ab5ccc 100644 (file)
@@ -352,17 +352,20 @@ int is_msg_in_mset(char *mset, long msgnum) {
 
 
 /*
- * Read binary data from server into memory
+ * Read binary data from server into memory using a series of
+ * server READ commands.
  */
 void read_server_binary(char *buffer, size_t total_len) {
        char buf[SIZ];
        size_t bytes = 0;
        size_t thisblock = 0;
 
+       memset(buffer, 0, total_len);
        while (bytes < total_len) {
                thisblock = 4095;
                if ((total_len - bytes) < thisblock) {
                        thisblock = total_len - bytes;
+                       if (thisblock == 0) return;
                }
                serv_printf("READ %d|%d", (int)bytes, (int)thisblock);
                serv_gets(buf);
@@ -372,7 +375,8 @@ void read_server_binary(char *buffer, size_t total_len) {
                        bytes += thisblock;
                }
                else {
-                       wprintf("Error: %s<BR>\n", &buf[4]);
+                       lprintf(3, "Error: %s<BR>\n", &buf[4]);
+                       return;
                }
        }
 }
index 0f971ffef301c01abf76eb35ffb6694605f891a5..1233b04a4ab7530d8f1e0328355398fbe2291fcc 100644 (file)
@@ -414,6 +414,7 @@ void output_static(char *what)
        char *bigbuffer;
        char content_type[SIZ];
 
+       lprintf(9, "output_static(%s)\n", what);
        sprintf(buf, "static/%s", what);
        fp = fopen(buf, "rb");
        if (fp == NULL) {
@@ -472,8 +473,6 @@ void output_image()
        char buf[SIZ];
        char *xferbuf = NULL;
        off_t bytes;
-       off_t thisblock;
-       off_t accomplished = 0L;
 
        serv_printf("OIMG %s|%s", bstr("name"), bstr("parm"));
        serv_gets(buf);
@@ -482,30 +481,13 @@ void output_image()
                xferbuf = malloc(bytes);
 
                /* Read it from the server */
-               while (bytes > (off_t) 0) {
-                       thisblock = 4096;
-                       if (thisblock > bytes) {
-                               thisblock = bytes;
-                       }
-                       serv_printf("READ %ld|%ld", accomplished, thisblock);
-                       serv_gets(buf);
-                       if (buf[0] == '6') {
-                               thisblock = extract_long(&buf[4], 0);
-                               serv_read(&xferbuf[accomplished],
-                                       (int) thisblock);
-                       }
-                       else {
-                               memset(&xferbuf[accomplished], 0, thisblock);
-                       }
-                       bytes = bytes - thisblock;
-                       accomplished += thisblock;
-               }
+               read_server_binary(xferbuf, bytes);
                serv_puts("CLOS");
                serv_gets(buf);
 
                /* Write it to the browser */
-               http_transmit_thing(xferbuf, (size_t)accomplished,
-                                       "image/gif");
+               http_transmit_thing(xferbuf, (size_t)bytes, "image/gif");
+               free(xferbuf);
 
        } else {
                wprintf("HTTP/1.0 404 %s\n", &buf[4]);
@@ -517,9 +499,6 @@ void output_image()
                );
        }
 
-       if (xferbuf) {
-               free(xferbuf);
-       }
 
 
 }
@@ -529,42 +508,22 @@ void output_image()
 void output_mimepart()
 {
        char buf[SIZ];
-       char xferbuf[4096];
        off_t bytes;
-       off_t thisblock;
-       off_t accomplished = 0L;
        char content_type[SIZ];
+       char *content = NULL;
        
        serv_printf("OPNA %s|%s", bstr("msgnum"), bstr("partnum"));
        serv_gets(buf);
        if (buf[0] == '2') {
                bytes = extract_long(&buf[4], 0);
+               content = malloc(bytes);
                extract(content_type, &buf[4], 3);
                output_headers(0);
-               wprintf("Content-type: %s\n", content_type);
-               wprintf("Content-length: %ld\n", (long) bytes);
-               wprintf("\n");
-
-               while (bytes > (off_t) 0) {
-                       thisblock = (off_t) sizeof(xferbuf);
-                       if (thisblock > bytes) {
-                               thisblock = bytes;
-                       }
-                       serv_printf("READ %ld|%ld", accomplished, thisblock);
-                       serv_gets(buf);
-                       if (buf[0] == '6') {
-                               thisblock = extract_long(&buf[4], 0);
-                               serv_read(xferbuf, (int) thisblock);
-                       }
-                       else {
-                               memset(xferbuf, 0, thisblock);
-                       }
-                       write(WC->http_sock, xferbuf, thisblock);
-                       bytes = bytes - thisblock;
-                       accomplished = accomplished + thisblock;
-               }
+               read_server_binary(content, bytes);
                serv_puts("CLOS");
                serv_gets(buf);
+               http_transmit_thing(content, bytes, content_type);
+               free(content);
        } else {
                wprintf("HTTP/1.0 404 %s\n", &buf[4]);
                output_headers(0);
@@ -582,8 +541,6 @@ char *load_mimepart(long msgnum, char *partnum)
 {
        char buf[SIZ];
        off_t bytes;
-       off_t thisblock;
-       off_t accomplished = 0L;
        char content_type[SIZ];
        char *content;
        
@@ -594,30 +551,11 @@ char *load_mimepart(long msgnum, char *partnum)
                extract(content_type, &buf[4], 3);
 
                content = malloc(bytes + 1);
+               read_server_binary(content, bytes);
 
-               while (bytes > (off_t) 0) {
-                       thisblock = bytes;
-                       if (thisblock > 4096L) {
-                               thisblock = 4096L;
-                       }
-                       if (thisblock > bytes) {
-                               thisblock = bytes;
-                       }
-                       serv_printf("READ %ld|%ld", accomplished, thisblock);
-                       serv_gets(buf);
-                       if (buf[0] == '6') {
-                               thisblock = extract_long(&buf[4], 0);
-                               serv_read(&content[accomplished], (int) thisblock);
-                       }
-                       else {
-                               memset(&content[accomplished], 0, thisblock);
-                       }
-                       bytes = bytes - thisblock;
-                       accomplished = accomplished + thisblock;
-               }
                serv_puts("CLOS");
                serv_gets(buf);
-               content[accomplished] = 0;      /* null terminate for good measure */
+               content[bytes] = 0;     /* null terminate for good measure */
                return(content);
        }
        else {