httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerenkra...@apache.org
Subject cvs commit: httpd-2.0/modules/filters NWGNUdeflate mod_deflate.c mod_deflate.dsp mod_deflate.exp config.m4
Date Mon, 06 May 2002 22:23:53 GMT
jerenkrantz    02/05/06 15:23:52

  Modified:    .        CHANGES STATUS
               modules/experimental config.m4
               modules/filters config.m4
  Added:       modules/filters NWGNUdeflate mod_deflate.c mod_deflate.dsp
                        mod_deflate.exp
  Removed:     modules/experimental NWGNUdeflate mod_deflate.c
                        mod_deflate.dsp mod_deflate.exp
  Log:
  Move mod_deflate from experimental to filters to represent our belief
  in its stability.
  
  Revision  Changes    Path
  1.763     +3 -0      httpd-2.0/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/CHANGES,v
  retrieving revision 1.762
  retrieving revision 1.763
  diff -u -r1.762 -r1.763
  --- CHANGES	6 May 2002 18:47:22 -0000	1.762
  +++ CHANGES	6 May 2002 22:23:51 -0000	1.763
  @@ -1,5 +1,8 @@
   Changes with Apache 2.0.37
   
  +  *) Move mod_deflate out of experimental and into filters.
  +     [Justin Erenkrantz]
  +
     *) Get proxy CONNECT basically working.  [Jeff Trawick]
   
     *) Fix mod_rewrite hang when APR uses SysV Semaphores and
  
  
  
  1.616     +1 -3      httpd-2.0/STATUS
  
  Index: STATUS
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/STATUS,v
  retrieving revision 1.615
  retrieving revision 1.616
  diff -u -r1.615 -r1.616
  --- STATUS	6 May 2002 22:14:09 -0000	1.615
  +++ STATUS	6 May 2002 22:23:51 -0000	1.616
  @@ -1,5 +1,5 @@
   APACHE 2.0 STATUS:                                              -*-text-*-
  -Last modified at [$Date: 2002/05/06 22:14:09 $]
  +Last modified at [$Date: 2002/05/06 22:23:51 $]
   
   Release:
   
  @@ -53,8 +53,6 @@
   RELEASE SHOWSTOPPERS:
   
       * for 2.0.37: decide if the MMN bump was warranted
  -
  -    * Move mod_deflate out of experimental
   
   CURRENT VOTES:
   
  
  
  
  1.21      +0 -53     httpd-2.0/modules/experimental/config.m4
  
  Index: config.m4
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/experimental/config.m4,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- config.m4	6 May 2002 00:58:16 -0000	1.20
  +++ config.m4	6 May 2002 22:23:52 -0000	1.21
  @@ -28,57 +28,4 @@
   APACHE_MODULE(case_filter, example uppercase conversion filter, , , no)
   APACHE_MODULE(case_filter_in, example uppercase conversion input filter, , , no)
   
  -APACHE_MODULE(deflate, Deflate transfer encoding support, , , no, [
  -  AC_ARG_WITH(z, APACHE_HELP_STRING(--with-z=DIR,use a specific zlib library),
  -  [
  -    if test "x$withval" != "xyes" && test "x$withval" != "x"; then
  -      ap_zlib_base="$withval"
  -    fi
  -  ])
  -  if test "x$ap_zlib_base" = "x"; then
  -    AC_MSG_CHECKING([for zlib location])
  -    AC_CACHE_VAL(ap_cv_zlib,[
  -      for dir in /usr/local /usr ; do
  -        if test -d $dir && test -f $dir/include/zlib.h; then
  -          ap_cv_zlib=$dir
  -          break
  -        fi
  -      done
  -    ])
  -    ap_zlib_base=$ap_cv_zlib
  -    if test "x$ap_zlib_base" = "x"; then
  -      enable_deflate=no
  -      AC_MSG_RESULT([not found])
  -    else
  -      AC_MSG_RESULT([$ap_zlib_base])
  -    fi
  -  fi
  -  if test "$enable_deflate" != "no"; then
  -    ap_save_includes=$INCLUDE
  -    ap_save_ldflags=$LDFLAGS
  -    ap_save_libs=$LIBS
  -    ap_save_cppflags=$CPPFLAGS
  -    if test "$ap_zlib_base" != "/usr"; then
  -      APR_ADDTO(INCLUDES, [-I${ap_zlib_base}/include])
  -      dnl put in CPPFLAGS temporarily so that AC_TRY_LINK below will work
  -      CPPFLAGS="$CPPFLAGS -I${ap_zlib_base}/include"
  -      APR_ADDTO(LDFLAGS, [-L${ap_zlib_base}/lib])
  -      if test "x$ap_platform_runtime_link_flag" != "x"; then
  -         APR_ADDTO(LDFLAGS, [$ap_platform_runtime_link_flag${ap_zlib_base}/lib])
  -      fi
  -    fi
  -    APR_ADDTO(LIBS, [-lz])
  -    AC_MSG_CHECKING([for zlib library])
  -    AC_TRY_LINK([#include <zlib.h>], [return Z_OK;], 
  -    [AC_MSG_RESULT(found) 
  -     AC_CHECK_HEADERS(zutil.h)],
  -    [AC_MSG_RESULT(not found)
  -     enable_deflate=no
  -     INCLUDES=$ap_save_includes
  -     LDFLAGS=$ap_save_ldflags
  -     LIBS=$ap_save_libs])
  -    CPPFLAGS=$ap_save_cppflags
  -  fi
  -])
  -
   APACHE_MODPATH_FINISH
  
  
  
  1.7       +53 -0     httpd-2.0/modules/filters/config.m4
  
  Index: config.m4
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/filters/config.m4,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- config.m4	12 May 2001 03:48:31 -0000	1.6
  +++ config.m4	6 May 2002 22:23:52 -0000	1.7
  @@ -8,4 +8,57 @@
   
   APR_ADDTO(LT_LDFLAGS,-export-dynamic)
   
  +APACHE_MODULE(deflate, Deflate transfer encoding support, , , no, [
  +  AC_ARG_WITH(z, APACHE_HELP_STRING(--with-z=DIR,use a specific zlib library),
  +  [
  +    if test "x$withval" != "xyes" && test "x$withval" != "x"; then
  +      ap_zlib_base="$withval"
  +    fi
  +  ])
  +  if test "x$ap_zlib_base" = "x"; then
  +    AC_MSG_CHECKING([for zlib location])
  +    AC_CACHE_VAL(ap_cv_zlib,[
  +      for dir in /usr/local /usr ; do
  +        if test -d $dir && test -f $dir/include/zlib.h; then
  +          ap_cv_zlib=$dir
  +          break
  +        fi
  +      done
  +    ])
  +    ap_zlib_base=$ap_cv_zlib
  +    if test "x$ap_zlib_base" = "x"; then
  +      enable_deflate=no
  +      AC_MSG_RESULT([not found])
  +    else
  +      AC_MSG_RESULT([$ap_zlib_base])
  +    fi
  +  fi
  +  if test "$enable_deflate" != "no"; then
  +    ap_save_includes=$INCLUDE
  +    ap_save_ldflags=$LDFLAGS
  +    ap_save_libs=$LIBS
  +    ap_save_cppflags=$CPPFLAGS
  +    if test "$ap_zlib_base" != "/usr"; then
  +      APR_ADDTO(INCLUDES, [-I${ap_zlib_base}/include])
  +      dnl put in CPPFLAGS temporarily so that AC_TRY_LINK below will work
  +      CPPFLAGS="$CPPFLAGS -I${ap_zlib_base}/include"
  +      APR_ADDTO(LDFLAGS, [-L${ap_zlib_base}/lib])
  +      if test "x$ap_platform_runtime_link_flag" != "x"; then
  +         APR_ADDTO(LDFLAGS, [$ap_platform_runtime_link_flag${ap_zlib_base}/lib])
  +      fi
  +    fi
  +    APR_ADDTO(LIBS, [-lz])
  +    AC_MSG_CHECKING([for zlib library])
  +    AC_TRY_LINK([#include <zlib.h>], [return Z_OK;], 
  +    [AC_MSG_RESULT(found) 
  +     AC_CHECK_HEADERS(zutil.h)],
  +    [AC_MSG_RESULT(not found)
  +     enable_deflate=no
  +     INCLUDES=$ap_save_includes
  +     LDFLAGS=$ap_save_ldflags
  +     LIBS=$ap_save_libs])
  +    CPPFLAGS=$ap_save_cppflags
  +  fi
  +])
  +
   APACHE_MODPATH_FINISH
  
  
  
  1.1                  httpd-2.0/modules/filters/NWGNUdeflate
  
  Index: NWGNUdeflate
  ===================================================================
  #
  # The MOD_DEFLATE module requires the ZLib source which
  # can be downloaded from http://www.gzip.org/zlib/
  #
  # Declare the sub-directories to be built here
  #
  
  SUBDIRS = \
  	$(EOLIST)
  
  #
  # Get the 'head' of the build environment.  This includes default targets and
  # paths to tools
  #
  
  include $(AP_WORK)\build\NWGNUhead.inc
  
  #
  # build this level's files
  
  #
  # Make sure all needed macro's are defined
  #
  
  #
  # These directories will be at the beginning of the include list, followed by
  # INCDIRS
  #
  XINCDIRS	+= \
  			$(AP_WORK)/include \
  			$(NWOS) \
  			$(AP_WORK)/modules/arch/netware \
  			$(AP_WORK)/srclib/apr/include \
  			$(AP_WORK)/srclib/apr-util/include \
  			$(AP_WORK)/srclib/apr \
  			$(AP_WORK)/srclib/zlib \
  			$(EOLIST)
  
  #
  # These flags will come after CFLAGS
  #
  XCFLAGS		+= \
  			-prefix pre_nw.h \
  			$(EOLIST)
  
  #
  # These defines will come after DEFINES
  #
  XDEFINES	+= \
  			$(EOLIST)
  
  #
  # These flags will be added to the link.opt file
  #
  XLFLAGS		+= \
  			$(EOLIST)
  
  #
  # These values will be appended to the correct variables based on the value of
  # RELEASE
  #
  ifeq "$(RELEASE)" "debug"
  XINCDIRS	+= \
  			$(EOLIST)
  
  XCFLAGS		+= \
  			$(EOLIST)
  
  XDEFINES	+= \
  			$(EOLIST)
  
  XLFLAGS		+= \
  		   	$(EOLIST)
  endif
  
  ifeq "$(RELEASE)" "noopt"
  XINCDIRS	+= \
  			$(EOLIST)
  
  XCFLAGS		+= \
  			$(EOLIST)
  
  XDEFINES	+= \
  			$(EOLIST)
  
  XLFLAGS		+= \
  		   	$(EOLIST)
  endif
  
  ifeq "$(RELEASE)" "release"
  XINCDIRS	+= \
  			$(EOLIST)
  
  XCFLAGS		+= \
  			$(EOLIST)
  
  XDEFINES	+= \
  			$(EOLIST)
  
  XLFLAGS		+= \
  			$(EOLIST)
  endif
  
  #
  # These are used by the link target if an NLM is being generated
  # This is used by the link 'name' directive to name the nlm.  If left blank
  # TARGET_nlm (see below) will be used.
  #
  NLM_NAME		= deflate
  
  #
  # This is used by the link '-desc ' directive.
  # If left blank, NLM_NAME will be used.
  #
  NLM_DESCRIPTION	= Deflate Module
  
  #
  # This is used by the '-threadname' directive.  If left blank,
  # NLM_NAME Thread will be used.
  #
  NLM_THREAD_NAME	= Deflate Module
  
  #
  # If this is specified, it will override VERSION value in
  # $(AP_WORK)\build\NWGNUenvironment.inc
  #
  NLM_VERSION		=
  
  #
  # If this is specified, it will override the default of 64K
  #
  NLM_STACK_SIZE	= 8192
  
  
  #
  # If this is specified it will be used by the link '-entry' directive
  #
  NLM_ENTRY_SYM	= _LibCPrelude
  
  #
  # If this is specified it will be used by the link '-exit' directive
  #
  NLM_EXIT_SYM	= _LibCPostlude
  
  #
  # If this is specified it will be used by the link '-check' directive
  #
  NLM_CHECK_SYM	=
  
  #
  # If these are specified it will be used by the link '-flags' directive
  #
  NLM_FLAGS		=  AUTOUNLOAD, PSEUDOPREEMPTION
  
  #
  # If this is specified it will be linked in with the XDCData option in the def
  # file instead of the default of $(NWOS)/apache.xdc.  XDCData can be disabled
  # by setting APACHE_UNIPROC in the environment
  #
  XDCDATA         =
  
  #
  # If there is an NLM target, put it here
  #
  TARGET_nlm = \
  	$(OBJDIR)/deflate.nlm \
  	$(EOLIST)
  
  #
  # If there is an LIB target, put it here
  #
  TARGET_lib = \
  	$(EOLIST)
  
  #
  # These are the OBJ files needed to create the NLM target above.
  # Paths must all use the '/' character
  #
  FILES_nlm_objs = \
  	$(OBJDIR)/mod_deflate.o \
  	$(OBJDIR)/adler32.o \
  	$(OBJDIR)/crc32.o \
  	$(OBJDIR)/deflate.o \
  	$(OBJDIR)/trees.o \
  	$(OBJDIR)/zutil.o \
  	$(EOLIST)
  
  #
  # These are the LIB files needed to create the NLM target above.
  # These will be added as a library command in the link.opt file.
  #
  FILES_nlm_libs = \
     	libcpre.o \
  	$(EOLIST)
  
  #
  # These are the modules that the above NLM target depends on to load.
  # These will be added as a module command in the link.opt file.
  #
  FILES_nlm_modules = \
  	aprlib \
  	libc \
  	$(EOLIST)
  
  #
  # If the nlm has a msg file, put it's path here
  #
  FILE_nlm_msg =
  
  #
  # If the nlm has a hlp file put it's path here
  #
  FILE_nlm_hlp =
  
  #
  # If this is specified, it will override $(NWOS)\copyright.txt.
  #
  FILE_nlm_copyright =
  
  #
  # Any additional imports go here
  #
  FILES_nlm_Ximports = \
  	@$(APR)/aprlib.imp \
  	@$(NWOS)/httpd.imp \
  	@libc.imp \
  	$(EOLIST)
  
  #
  # Any symbols exported to here
  #
  FILES_nlm_exports = \
  	deflate_module \
  	$(EOLIST)
  
  #
  # These are the OBJ files needed to create the LIB target above.
  # Paths must all use the '/' character
  #
  FILES_lib_objs = \
  		$(EOLIST)
  
  #
  # implement targets and dependancies (leave this section alone)
  #
  
  libs :: $(OBJDIR) $(TARGET_lib)
  
  nlms :: libs $(TARGET_nlm)
  
  #
  # Updated this target to create necessary directories and copy files to the
  # correct place.  (See $(AP_WORK)\build\NWGNUhead.inc for examples)
  #
  install :: nlms FORCE
  
  #
  # Any specialized rules here
  #
  
  $(OBJDIR)/%.o: ../../srclib/zlib/%.c $(OBJDIR)\cc.opt
  	@echo Compiling $<
  	$(CC) ..\..\srclib\zlib\$(<F) -o=$(OBJDIR)\$(@F) @$(OBJDIR)\cc.opt
  
  
  #
  # Include the 'tail' makefile that has targets that depend on variables defined
  # in this makefile
  #
  
  include $(AP_WORK)\build\NWGNUtail.inc
  
  
  
  
  
  
  1.1                  httpd-2.0/modules/filters/mod_deflate.c
  
  Index: mod_deflate.c
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * (zlib functions gz_open and gzwrite)
   */
  
  /*
   * mod_deflate.c: Perform deflate transfer-encoding on the fly
   *
   * Written by Ian Holsman (IanH@apache.org)
   *
   */
  
  #include "httpd.h"
  #include "http_config.h"
  #include "http_log.h"
  #include "apr_strings.h"
  #include "apr_general.h"
  #include "util_filter.h"
  #include "apr_buckets.h"
  #include "http_request.h"
  
  #include "zlib.h"
  
  #ifdef HAVE_ZUTIL_H
  #include "zutil.h"
  #else
  /* As part of the encoding process, we must send what our OS_CODE is
   * (or so it seems based on what I can tell of how gzip encoding works).
   *
   * zutil.h is not always included with zlib distributions (it is a private
   * header), so this is straight from zlib 1.1.3's zutil.h.
   */
  #ifdef OS2
  #define OS_CODE  0x06
  #endif
  
  #ifdef WIN32 /* Window 95 & Windows NT */
  #define OS_CODE  0x0b
  #endif
  
  #if defined(VAXC) || defined(VMS)
  #define OS_CODE  0x02
  #endif
  
  #ifdef AMIGA
  #define OS_CODE  0x01
  #endif
  
  #if defined(ATARI) || defined(atarist)
  #define OS_CODE  0x05
  #endif
  
  #if defined(MACOS) || defined(TARGET_OS_MAC)
  #define OS_CODE  0x07
  #endif
  
  #ifdef __50SERIES /* Prime/PRIMOS */
  #define OS_CODE  0x0F
  #endif
  
  #ifdef TOPS20
  #define OS_CODE  0x0a
  #endif
  
  #ifndef OS_CODE
  #define OS_CODE  0x03  /* assume Unix */
  #endif
  #endif
  
  static const char deflateFilterName[] = "DEFLATE";
  module AP_MODULE_DECLARE_DATA deflate_module;
  
  typedef struct deflate_filter_config_t
  {
      int windowSize;
      int memlevel;
      char *noteName;
  } deflate_filter_config;
  
  /* windowsize is negative to suppress Zlib header */
  #define DEFAULT_WINDOWSIZE -15
  #define DEFAULT_MEMLEVEL 9
  #define FILTER_BUFSIZE 8096
  
  /* Outputs a long in LSB order to the given file
   * only the bottom 4 bits are required for the deflate file format.
   */
  static void putLong(char *string, unsigned long x)
  {
      int n;
      for (n = 0; n < 4; n++) {
          string[n] = (int) (x & 0xff);
          x >>= 8;
      }
  }
  
  static void *create_deflate_server_config(apr_pool_t *p, server_rec *s)
  {
      deflate_filter_config *c = apr_pcalloc(p, sizeof *c);
  
      c->memlevel   = DEFAULT_MEMLEVEL;
      c->windowSize = DEFAULT_WINDOWSIZE;
  
      return c;
  }
  
  static const char *deflate_set_window_size(cmd_parms *cmd, void *dummy,
                                             const char *arg)
  {
      deflate_filter_config *c = ap_get_module_config(cmd->server->module_config,
                                                      &deflate_module);
      int i;
  
      i = atoi(arg);
  
      if (i < 1 || i > 15)
          return "DeflateWindowSize must be between 1 and 15";
  
      c->windowSize = i * -1;
  
      return NULL;
  }
  
  static const char *deflate_set_note(cmd_parms *cmd, void *dummy,
                                      const char *arg)
  {
      deflate_filter_config *c = ap_get_module_config(cmd->server->module_config,
                                                      &deflate_module);
      c->noteName = apr_pstrdup(cmd->pool, arg);
  
      return NULL;
  }
  
  static const char *deflate_set_memlevel(cmd_parms *cmd, void *dummy,
                                          const char *arg)
  {
      deflate_filter_config *c = ap_get_module_config(cmd->server->module_config,
                                                      &deflate_module);
      int i;
  
      i = atoi(arg);
  
      if (i < 1 || i > 9)
          return "DeflateMemLevel must be between 1 and 9";
  
      c->memlevel = i;
  
      return NULL;
  }
  
  /* magic header */
  static int deflate_magic[2] = { 0x1f, 0x8b };
  
  typedef struct deflate_ctx_t
  {
      z_stream stream;
      unsigned char buffer[FILTER_BUFSIZE];
      unsigned long crc;
      apr_bucket_brigade *bb;
  } deflate_ctx;
  
  static apr_status_t deflate_out_filter(ap_filter_t *f,
                                         apr_bucket_brigade *bb)
  {
      apr_bucket *e;
      const char *accepts;
      request_rec *r = f->r;
      deflate_ctx *ctx = f->ctx;
      char *token = NULL;
      int zRC;
      deflate_filter_config *c = ap_get_module_config(r->server->module_config,
                                                      &deflate_module);
  
      /* If we don't have a context, we need to ensure that it is okay to send
       * the deflated content.  If we have a context, that means we've done
       * this before and we liked it.
       * This could be not so nice if we always fail.  But, if we succeed,
       * we're in better shape.
       */
      if (!ctx) {
          char *buf;
  
          /* only work on main request/no subrequests */
          if (r->main) {
              return ap_pass_brigade(f->next, bb);
          }
  
          /* some browsers might have problems, so set no-gzip
           * (with browsermatch) for them
           */
          if (apr_table_get(r->subprocess_env, "no-gzip")) {
              return ap_pass_brigade(f->next, bb);
          }
  
          /* Some browsers might have problems with content types
           * other than text/html, so set gzip-only-text/html
           * (with browsermatch) for them
           */
          if ((r->content_type == NULL
               || strncmp(r->content_type, "text/html", 9))
              && apr_table_get(r->subprocess_env, "gzip-only-text/html")) {
              return ap_pass_brigade(f->next, bb);
          }
  
          /* if they don't have the line, then they can't play */
          accepts = apr_table_get(r->headers_in, "Accept-Encoding");
          if (accepts == NULL) {
              return ap_pass_brigade(f->next, bb);
          }
  
          token = ap_get_token(r->pool, &accepts, 0);
          while (token && token[0] && strcmp(token, "gzip")) {
              /* skip token */
              accepts++;
              token = ap_get_token(r->pool, &accepts, 0);
          }
  
          /* No acceptable token found. */
          if (token == NULL || token[0] == '\0') {
              return ap_pass_brigade(f->next, bb);
          }
  
          /* We're cool with filtering this. */
          ctx = f->ctx = apr_pcalloc(r->pool, sizeof(*ctx));
          ctx->bb = apr_brigade_create(r->pool, f->c->bucket_alloc);
  /*
          ctx->stream.zalloc = (alloc_func) 0;
          ctx->stream.zfree = (free_func) 0;
          ctx->stream.opaque = (voidpf) 0;
          ctx->crc = 0L;
  */
          zRC = deflateInit2(&ctx->stream, Z_BEST_SPEED, Z_DEFLATED,
                             c->windowSize, c->memlevel,
                             Z_DEFAULT_STRATEGY);
  
          if (zRC != Z_OK) {
              f->ctx = NULL;
              ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
                            "unable to init Zlib: "
                            "deflateInit2 returned %d: URL %s",
                            zRC, r->uri);
              return ap_pass_brigade(f->next, bb);
          }
  
          buf = apr_psprintf(r->pool, "%c%c%c%c%c%c%c%c%c%c", deflate_magic[0],
                             deflate_magic[1], Z_DEFLATED, 0 /* flags */ , 0, 0,
                             0, 0 /* time */ , 0 /* xflags */ , OS_CODE);
          e = apr_bucket_pool_create(buf, 10, r->pool, f->c->bucket_alloc);
          APR_BRIGADE_INSERT_TAIL(ctx->bb, e);
  
          apr_table_setn(r->headers_out, "Content-Encoding", "gzip");
          apr_table_setn(r->headers_out, "Vary", "Accept-Encoding");
          apr_table_unset(r->headers_out, "Content-Length");
      }
  
      APR_BRIGADE_FOREACH(e, bb) {
          const char *data;
          apr_bucket *b;
          apr_size_t len;
  
          int done = 0;
  
          if (APR_BUCKET_IS_EOS(e)) {
              char *buf, *p;
              char crc_array[4], len_array[4];
              unsigned int deflate_len;
  
              ctx->stream.avail_in = 0; /* should be zero already anyway */
              for (;;) {
                  deflate_len = FILTER_BUFSIZE - ctx->stream.avail_out;
  
                  if (deflate_len != 0) {
                      b = apr_bucket_heap_create((char *)ctx->buffer,
                                                 deflate_len, NULL,
                                                 f->c->bucket_alloc);
                      APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
                      ctx->stream.next_out = ctx->buffer;
                      ctx->stream.avail_out = FILTER_BUFSIZE;
                  }
  
                  if (done) {
                      break;
                  }
  
                  zRC = deflate(&ctx->stream, Z_FINISH);
  
                  if (deflate_len == 0 && zRC == Z_BUF_ERROR) {
                      zRC = Z_OK;
                  }
  
                  done = (ctx->stream.avail_out != 0 || zRC == Z_STREAM_END);
  
                  if (zRC != Z_OK && zRC != Z_STREAM_END) {
                      break;
                  }
              }
  
              putLong(crc_array, ctx->crc);
              putLong(len_array, ctx->stream.total_in);
  
              p = buf = apr_palloc(r->pool, 8);
              *p++ = crc_array[0];
              *p++ = crc_array[1];
              *p++ = crc_array[2];
              *p++ = crc_array[3];
              *p++ = len_array[0];
              *p++ = len_array[1];
              *p++ = len_array[2];
              *p++ = len_array[3];
  
              b = apr_bucket_pool_create(buf, 8, r->pool, f->c->bucket_alloc);
              APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
              ap_log_rerror(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, 0, r,
                            "Zlib: Compressed %ld to %ld : URL %s",
                            ctx->stream.total_in, ctx->stream.total_out, r->uri);
  
              if (c->noteName) {
                  if (ctx->stream.total_in > 0) {
                      int total;
  
                      total = ctx->stream.total_out * 100 / ctx->stream.total_in;
  
                      apr_table_setn(r->notes, c->noteName,
                                     apr_itoa(r->pool, total));
                  }
                  else {
                      apr_table_setn(r->notes, c->noteName, "-");
                  }
              }
  
              deflateEnd(&ctx->stream);
  
              /* Remove EOS from the old list, and insert into the new. */
              APR_BUCKET_REMOVE(e);
              APR_BRIGADE_INSERT_TAIL(ctx->bb, e);
  
              /* Okay, we've seen the EOS.
               * Time to pass it along down the chain.
               */
              return ap_pass_brigade(f->next, ctx->bb);
          }
  
          if (APR_BUCKET_IS_FLUSH(e)) {
              /* XXX FIX: do we need the Content-Size set, or can we stream?
               * we should be able to stream
               */
  
              /* Ignore flush buckets for the moment.. we can't stream as we
               * need the size ;(
               */
              continue;
          }
  
          /* read */
          apr_bucket_read(e, &data, &len, APR_BLOCK_READ);
  
          /* This crc32 function is from zlib. */
          ctx->crc = crc32(ctx->crc, (const Bytef *)data, len);
  
          /* write */
          ctx->stream.next_in = (unsigned char *)data; /* We just lost const-ness,
                                                        * but we'll just have to
                                                        * trust zlib */
          ctx->stream.avail_in = len;
          ctx->stream.next_out = ctx->buffer;
          ctx->stream.avail_out = FILTER_BUFSIZE;
  
          while (ctx->stream.avail_in != 0) {
              if (ctx->stream.avail_out == 0) {
                  ctx->stream.next_out = ctx->buffer;
                  len = FILTER_BUFSIZE - ctx->stream.avail_out;
  
                  b = apr_bucket_heap_create((char *)ctx->buffer, len,
                                             NULL, f->c->bucket_alloc);
                  APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
                  ctx->stream.avail_out = FILTER_BUFSIZE;
              }
  
              zRC = deflate(&(ctx->stream), Z_NO_FLUSH);
  
              if (zRC != Z_OK)
                  return APR_EGENERAL;
          }
      }
  
      apr_brigade_destroy(bb);
      return APR_SUCCESS;
  }
  
  static void register_hooks(apr_pool_t *p)
  {
      ap_register_output_filter(deflateFilterName, deflate_out_filter,
                                AP_FTYPE_CONTENT_SET);
  }
  
  static const command_rec deflate_filter_cmds[] = {
      AP_INIT_TAKE1("DeflateFilterNote", deflate_set_note, NULL, RSRC_CONF,
                    "Set a note to report on compression ratio"),
      AP_INIT_TAKE1("DeflateWindowSize", deflate_set_window_size, NULL,
                    RSRC_CONF, "Set the Deflate window size (1-15)"),
      AP_INIT_TAKE1("DeflateMemLevel", deflate_set_memlevel, NULL, RSRC_CONF,
                    "Set the Deflate Memory Level (1-9)"),
      {NULL}
  };
  
  module AP_MODULE_DECLARE_DATA deflate_module = {
      STANDARD20_MODULE_STUFF,
      NULL,                         /* dir config creater */
      NULL,                         /* dir merger --- default is to override */
      create_deflate_server_config, /* server config */
      NULL,                         /* merge server config */
      deflate_filter_cmds,          /* command table */
      register_hooks                /* register hooks */
  };
  
  
  
  1.1                  httpd-2.0/modules/filters/mod_deflate.dsp
  
  Index: mod_deflate.dsp
  ===================================================================
  # Microsoft Developer Studio Project File - Name="mod_deflate" - Package Owner=<4>
  # Microsoft Developer Studio Generated Build File, Format Version 6.00
  # ** DO NOT EDIT **
  
  # TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
  
  CFG=mod_deflate - Win32 Release
  !MESSAGE This is not a valid makefile. To build this project using NMAKE,
  !MESSAGE use the Export Makefile command and run
  !MESSAGE 
  !MESSAGE NMAKE /f "mod_deflate.mak".
  !MESSAGE 
  !MESSAGE You can specify a configuration when running NMAKE
  !MESSAGE by defining the macro CFG on the command line. For deflate:
  !MESSAGE 
  !MESSAGE NMAKE /f "mod_deflate.mak" CFG="mod_deflate - Win32 Release"
  !MESSAGE 
  !MESSAGE Possible choices for configuration are:
  !MESSAGE 
  !MESSAGE "mod_deflate - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
  !MESSAGE "mod_deflate - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
  !MESSAGE 
  
  # Begin Project
  # PROP AllowPerConfigDependencies 0
  # PROP Scc_ProjName ""
  # PROP Scc_LocalPath ""
  CPP=cl.exe
  MTL=midl.exe
  RSC=rc.exe
  
  !IF  "$(CFG)" == "mod_deflate - Win32 Release"
  
  # PROP BASE Use_MFC 0
  # PROP BASE Use_Debug_Libraries 0
  # PROP BASE Output_Dir "Release"
  # PROP BASE Intermediate_Dir "Release"
  # PROP BASE Target_Dir ""
  # PROP Use_MFC 0
  # PROP Use_Debug_Libraries 0
  # PROP Output_Dir "Release"
  # PROP Intermediate_Dir "Release"
  # PROP Ignore_Export_Lib 0
  # PROP Target_Dir ""
  # ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "HAVE_ZUTIL_H"
/FD /c
  # ADD CPP /nologo /MD /W3 /O2 /I "../../include" /I "../../srclib/apr/include" /I "../../srclib/apr-util/include"
/I "../../srclib/zlib" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /Fd"Release\mod_deflate" /FD /c
  # ADD BASE MTL /nologo /D "NDEBUG" /win32
  # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
  # ADD BASE RSC /l 0x409 /d "NDEBUG"
  # ADD RSC /l 0x409 /d "NDEBUG"
  BSC32=bscmake.exe
  # ADD BASE BSC32 /nologo
  # ADD BSC32 /nologo
  LINK32=link.exe
  # ADD BASE LINK32 kernel32.lib /nologo /subsystem:windows /dll /map /machine:I386 /out:"Release/mod_deflate.so"
/base:@..\..\os\win32\BaseAddr.ref,mod_deflate
  # ADD LINK32 kernel32.lib /nologo /subsystem:windows /dll /map /machine:I386 /out:"Release/mod_deflate.so"
/base:@..\..\os\win32\BaseAddr.ref,mod_deflate
  
  !ELSEIF  "$(CFG)" == "mod_deflate - Win32 Debug"
  
  # PROP BASE Use_MFC 0
  # PROP BASE Use_Debug_Libraries 1
  # PROP BASE Output_Dir "Debug"
  # PROP BASE Intermediate_Dir "Debug"
  # PROP BASE Target_Dir ""
  # PROP Use_MFC 0
  # PROP Use_Debug_Libraries 1
  # PROP Output_Dir "Debug"
  # PROP Intermediate_Dir "Debug"
  # PROP Ignore_Export_Lib 0
  # PROP Target_Dir ""
  # ADD BASE CPP /nologo /MDd /W3 /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FD /c
  # ADD CPP /nologo /MDd /W3 /GX /Zi /Od /I "../../include" /I "../../srclib/apr/include"
/I "../../srclib/apr-util/include" /I "../../srclib/zlib" /D "_DEBUG" /D "WIN32" /D "_WINDOWS"
/D "HAVE_ZUTIL_H" /Fd"Debug\mod_deflate" /FD /c
  # ADD BASE MTL /nologo /D "_DEBUG" /win32
  # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
  # ADD BASE RSC /l 0x409 /d "_DEBUG"
  # ADD RSC /l 0x409 /d "_DEBUG"
  BSC32=bscmake.exe
  # ADD BASE BSC32 /nologo
  # ADD BSC32 /nologo
  LINK32=link.exe
  # ADD BASE LINK32 kernel32.lib /nologo /subsystem:windows /dll /incremental:no /map /debug
/machine:I386 /out:"Debug/mod_deflate.so" /base:@..\..\os\win32\BaseAddr.ref,mod_deflate
  # ADD LINK32 kernel32.lib /nologo /subsystem:windows /dll /incremental:no /map /debug /machine:I386
/out:"Debug/mod_deflate.so" /base:@..\..\os\win32\BaseAddr.ref,mod_deflate
  
  !ENDIF 
  
  # Begin Target
  
  # Name "mod_deflate - Win32 Release"
  # Name "mod_deflate - Win32 Debug"
  # Begin Source File
  
  SOURCE=.\mod_deflate.c
  # End Source File
  # Begin Source File
  
  SOURCE=.\mod_deflate.rc
  # End Source File
  # Begin Source File
  
  SOURCE=..\..\build\win32\win32ver.awk
  
  !IF  "$(CFG)" == "mod_deflate - Win32 Release"
  
  # PROP Ignore_Default_Tool 1
  # Begin Custom Build - Creating Version Resource
  InputPath=..\..\build\win32\win32ver.awk
  
  ".\mod_deflate.rc" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
  	awk -f ../../build/win32/win32ver.awk mod_deflate  "deflate_module for Apache" ../../include/ap_release.h
> .\mod_deflate.rc
  
  # End Custom Build
  
  !ELSEIF  "$(CFG)" == "mod_deflate - Win32 Debug"
  
  # PROP Ignore_Default_Tool 1
  # Begin Custom Build - Creating Version Resource
  InputPath=..\..\build\win32\win32ver.awk
  
  ".\mod_deflate.rc" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
  	awk -f ../../build/win32/win32ver.awk mod_deflate  "deflate_module for Apache" ../../include/ap_release.h
> .\mod_deflate.rc
  
  # End Custom Build
  
  !ENDIF 
  
  # End Source File
  # Begin Group "zlib"
  
  # PROP Default_Filter ""
  # Begin Source File
  
  SOURCE=..\..\srclib\zlib\adler32.c
  # End Source File
  # Begin Source File
  
  SOURCE=..\..\srclib\zlib\crc32.c
  # End Source File
  # Begin Source File
  
  SOURCE=..\..\srclib\zlib\deflate.c
  # End Source File
  # Begin Source File
  
  SOURCE=..\..\srclib\zlib\trees.c
  # End Source File
  # Begin Source File
  
  SOURCE=..\..\srclib\zlib\zutil.c
  # End Source File
  # End Group
  # End Target
  # End Project
  
  
  
  1.1                  httpd-2.0/modules/filters/mod_deflate.exp
  
  Index: mod_deflate.exp
  ===================================================================
  deflate_module
  
  
  

Mime
View raw message