You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by rp...@apache.org on 2006/07/29 14:49:52 UTC

svn commit: r426790 - /httpd/httpd/trunk/modules/filters/mod_deflate.c

Author: rpluem
Date: Sat Jul 29 05:49:51 2006
New Revision: 426790

URL: http://svn.apache.org/viewvc?rev=426790&view=rev
Log:
* Add parameter crc to flush_libz_buffer in order to call the libz's crc32
  function on the output buffer if needed. This is actually needed by the
  later rework of the inflate out filter.

Modified:
    httpd/httpd/trunk/modules/filters/mod_deflate.c

Modified: httpd/httpd/trunk/modules/filters/mod_deflate.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/filters/mod_deflate.c?rev=426790&r1=426789&r2=426790&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/filters/mod_deflate.c (original)
+++ httpd/httpd/trunk/modules/filters/mod_deflate.c Sat Jul 29 05:49:51 2006
@@ -215,9 +215,15 @@
     int (*libz_end_func)(z_streamp);
 } deflate_ctx;
 
+/* Do not update ctx->crc, see comment in flush_libz_buffer */
+#define NO_UPDATE_CRC 0
+/* Do update ctx->crc, see comment in flush_libz_buffer */
+#define UPDATE_CRC 1
+
 static int flush_libz_buffer(deflate_ctx *ctx, deflate_filter_config *c,
                              struct apr_bucket_alloc_t *bucket_alloc,
-                             int (*libz_func)(z_streamp, int), int flush)
+                             int (*libz_func)(z_streamp, int), int flush,
+                             int crc)
 {
     int zRC = Z_OK;
     int done = 0;
@@ -228,6 +234,15 @@
          deflate_len = c->bufferSize - ctx->stream.avail_out;
 
          if (deflate_len != 0) {
+             /*
+              * Do we need to update ctx->crc? Usually this is the case for
+              * inflate action where we need to do a crc on the output, whereas
+              * in the deflate case we need to do a crc on the input
+              */
+             if (crc) {
+                 ctx->crc = crc32(ctx->crc, (const Bytef *)ctx->buffer,
+                                  deflate_len);
+             }
              b = apr_bucket_heap_create((char *)ctx->buffer,
                                         deflate_len, NULL,
                                         bucket_alloc);
@@ -467,7 +482,8 @@
 
             ctx->stream.avail_in = 0; /* should be zero already anyway */
             /* flush the remaining data from the zlib buffers */
-            flush_libz_buffer(ctx, c, f->c->bucket_alloc, deflate, Z_FINISH);
+            flush_libz_buffer(ctx, c, f->c->bucket_alloc, deflate, Z_FINISH,
+                              NO_UPDATE_CRC);
 
             buf = apr_palloc(r->pool, 8);
             putLong((unsigned char *)&buf[0], ctx->crc);
@@ -525,7 +541,7 @@
 
             /* flush the remaining data from the zlib buffers */
             zRC = flush_libz_buffer(ctx, c, f->c->bucket_alloc, deflate,
-                                    Z_SYNC_FLUSH);
+                                    Z_SYNC_FLUSH, NO_UPDATE_CRC);
             if (zRC != Z_OK) {
                 return APR_EGENERAL;
             }