]> granicus.if.org Git - apache/commitdiff
* Add parameter crc to flush_libz_buffer in order to call the libz's crc32
authorRuediger Pluem <rpluem@apache.org>
Sat, 29 Jul 2006 12:49:51 +0000 (12:49 +0000)
committerRuediger Pluem <rpluem@apache.org>
Sat, 29 Jul 2006 12:49:51 +0000 (12:49 +0000)
  function on the output buffer if needed. This is actually needed by the
  later rework of the inflate out filter.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@426790 13f79535-47bb-0310-9956-ffa450edef68

modules/filters/mod_deflate.c

index a1b456bb81c60c0af0a51ccf852a3c369a3f19b0..2cecccff8506f446f008acf6fdb5fbaa142045a9 100644 (file)
@@ -215,9 +215,15 @@ typedef struct deflate_ctx_t
     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 @@ static int flush_libz_buffer(deflate_ctx *ctx, deflate_filter_config *c,
          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 @@ static apr_status_t deflate_out_filter(ap_filter_t *f,
 
             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 @@ static apr_status_t deflate_out_filter(ap_filter_t *f,
 
             /* 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;
             }