httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cody Sherr <csh...@covalent.net>
Subject [PATCH] resubmit new and improved ap_vrprintf fix to handle > 4K
Date Wed, 15 Aug 2001 23:12:57 GMT


Small changes, AP_IOBUFSIZE macro (8K) for the buffer size, seemed
appropriate, and using local buffer.

Thanks for the feedback.

--
Cody Sherr

Engineer
Covalent Technologies

phone: (415)536-5292
email: csherr@covalent.net


Index: protocol.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/server/protocol.c,v
retrieving revision 1.38
diff -u -r1.38 protocol.c
--- protocol.c	2001/08/07 16:40:25	1.38
+++ protocol.c	2001/08/15 23:04:07
@@ -1133,19 +1133,63 @@
     return nbyte;
 }

+struct ap_vrprintf_data {
+    apr_vformatter_buff_t vbuff;
+    request_rec *r;
+    char *buff;
+};
+
+static apr_status_t r_flush(apr_vformatter_buff_t *buff)
+{
+    /* callback function passed to ap_vformatter to be called when
+     * vformatter needs to write into buff and buff.curpos > buff.endpos */
+
+    /* ap_vrprintf_data passed as a apr_vformatter_buff_t, which is then
+     * "downcast" to an ap_vrprintf_data */
+    struct ap_vrprintf_data *vd = (struct ap_vrprintf_data*)buff;
+
+    if (vd->r->connection->aborted)
+        return -1;
+
+    /* r_flush is called when vbuff is completely full */
+    if (buffer_output(vd->r, vd->buff, AP_IOBUFSIZE)) {
+	return -1;
+    }
+
+    /* reset the buffer position */
+    vd->vbuff.curpos = vd->buff;
+    vd->vbuff.endpos = vd->buff + AP_IOBUFSIZE;
+
+    return APR_SUCCESS;
+}
+
 AP_DECLARE(int) ap_vrprintf(request_rec *r, const char *fmt, va_list va)
 {
-    char buf[4096];
     apr_size_t written;
+    struct ap_vrprintf_data vd;
+    static char vrprintf_buf[AP_IOBUFSIZE];
+
+    vd.vbuff.curpos = vrprintf_buf;
+    vd.vbuff.endpos = vrprintf_buf + AP_IOBUFSIZE;
+    vd.r = r;
+    vd.buff = vrprintf_buf;

     if (r->connection->aborted)
         return -1;

-    /* ### fix this mechanism to allow more than 4K of output */
-    written = apr_vsnprintf(buf, sizeof(buf), fmt, va);
+    written = apr_vformatter(r_flush, &vd.vbuff, fmt, va);
+    /* tack on null terminator on remaining string */
+    *(vd.vbuff.curpos) = '\0';

-    if (buffer_output(r, buf, written) != APR_SUCCESS)
-        return -1;
+    if (written != -1) {
+	int n = vd.vbuff.curpos - vrprintf_buf;
+
+	/* last call to buffer_output, to finish clearing the buffer */
+	if (buffer_output(r, vrprintf_buf,n) != APR_SUCCESS)
+	    return -1;
+
+	written += n;
+    }

     return written;
 }


Mime
View raw message