2 /* ====================================================================
4 * MOD_GZIP.C - Version 1.3.19.1a
6 * This program was developed and is currently maintained by
7 * Remote Communications, Inc.
8 * Home page: http://www.RemoteCommunications.com
10 * Original author: Kevin Kiley, CTO, Remote Communications, Inc.
11 * Email: Kiley@RemoteCommunications.com
13 * As of this writing there is an online support forum which
14 * anyone may join by following the instructions found at...
15 * http://lists.over.net/mailman/listinfo/mod_gzip
17 * ====================================================================
20 /* APACHE LICENSE: START
22 * Portions of this software are covered under the following license
23 * which, as it states, must remain included in this source code
24 * module and may not be altered in any way.
27 /* ====================================================================
28 * The Apache Software License, Version 1.1
30 * Copyright (c) 2000 The Apache Software Foundation. All rights
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in
42 * the documentation and/or other materials provided with the
45 * 3. The end-user documentation included with the redistribution,
46 * if any, must include the following acknowledgment:
47 * "This product includes software developed by the
48 * Apache Software Foundation (http://www.apache.org/)."
49 * Alternately, this acknowledgment may appear in the software itself,
50 * if and wherever such third-party acknowledgments normally appear.
52 * 4. The names "Apache" and "Apache Software Foundation" must
53 * not be used to endorse or promote products derived from this
54 * software without prior written permission. For written
55 * permission, please contact apache@apache.org.
57 * 5. Products derived from this software may not be called "Apache",
58 * nor may "Apache" appear in their name, without prior written
59 * permission of the Apache Software Foundation.
61 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
62 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
63 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
64 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
65 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
66 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
67 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
68 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
69 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
70 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
71 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
73 * ====================================================================
75 * This software consists of voluntary contributions made by many
76 * individuals on behalf of the Apache Software Foundation. For more
77 * information on the Apache Software Foundation, please see
78 * <http://www.apache.org/>.
80 * Portions of this software are based upon public domain software
81 * originally written at the National Center for Supercomputing Applications,
82 * University of Illinois, Urbana-Champaign.
85 /* APACHE LICENSE: END */
90 #include "http_config.h"
91 #include "http_core.h"
93 #include "http_main.h"
94 #include "http_protocol.h"
95 #include "http_request.h"
96 #include "util_script.h"
98 extern API_VAR_EXPORT char ap_server_root[ MAX_STRING_LEN ];
100 char mod_gzip_version[] = "1.3.19.1a";
102 #define MOD_GZIP_VERSION_INFO_STRING "mod_gzip/1.3.19.1a"
105 * Declare the NAME by which this module will be known.
106 * This is the NAME that will be used in LoadModule command(s).
109 extern module MODULE_VAR_EXPORT gzip_module;
112 * Turn MOD_GZIP_USES_APACHE_LOGS switch ON to include the
113 * code that can update Apache logs with compression information.
116 #define MOD_GZIP_USES_APACHE_LOGS
119 * Turn MOD_GZIP_DEBUG1 switch ON to include debug code.
120 * This is normally OFF by default and should only be
121 * used for diagnosing problems. The log output is
122 * VERY detailed and the log files will be HUGE.
126 #define MOD_GZIP_DEBUG1
130 * Turn MOD_GZIP_DEBUG1_VERBOSE1 switch ON to include
131 * some VERY 'verbose' debug code such as request record
132 * dumps during transactions and hex dumps of data.
133 * This is normally OFF by default. MOD_GZIP_DEBUG1
134 * switch must also be 'on' for this to have any effect.
137 #ifdef MOD_GZIP_DEBUG1
138 #define MOD_GZIP_DEBUG1_VERBOSE1
142 * Turn this 'define' on to send all log output to
143 * Apache error_log instead of a flat file. "LogLevel debug"
144 * must be set in httpd.conf for log output to appear in error_log.
148 #define MOD_GZIP_LOG_IS_APACHE_LOG
155 #ifndef MOD_GZIP_MAX_PATH_LEN
156 #define MOD_GZIP_MAX_PATH_LEN 512
160 char mod_gzip_dirsep[]="\\";
162 char mod_gzip_dirsep[]="/";
165 #define MOD_GZIP_IMAP_MAXNAMES 256
166 #define MOD_GZIP_IMAP_MAXNAMELEN 90
168 #define MOD_GZIP_IMAP_ISNONE 0
169 #define MOD_GZIP_IMAP_ISMIME 1
170 #define MOD_GZIP_IMAP_ISHANDLER 2
171 #define MOD_GZIP_IMAP_ISFILE 3
172 #define MOD_GZIP_IMAP_ISURI 4
173 #define MOD_GZIP_IMAP_ISREQHEADER 5
174 #define MOD_GZIP_IMAP_ISRSPHEADER 6
175 #define MOD_GZIP_IMAP_ISPORT 7
176 #define MOD_GZIP_IMAP_ISADDRESS 8
178 #define MOD_GZIP_IMAP_STATIC1 9001
179 #define MOD_GZIP_IMAP_DYNAMIC1 9002
180 #define MOD_GZIP_IMAP_DYNAMIC2 9003
181 #define MOD_GZIP_IMAP_DECLINED1 9004
183 #define MOD_GZIP_REQUEST 9005
184 #define MOD_GZIP_RESPONSE 9006
195 char name[ MOD_GZIP_IMAP_MAXNAMELEN + 2 ];
199 int mod_gzip_imap_size = (int) sizeof( mod_gzip_imap );
201 #define MOD_GZIP_CONFIG_MODE_SERVER 1
202 #define MOD_GZIP_CONFIG_MODE_DIRECTORY 2
203 #define MOD_GZIP_CONFIG_MODE_COMBO 3
215 int keep_workfiles_set;
220 int add_header_count;
221 int add_header_count_set;
226 long minimum_file_size;
227 int minimum_file_size_set;
229 long maximum_file_size;
230 int maximum_file_size_set;
232 long maximum_inmem_size;
233 int maximum_inmem_size_set;
235 char temp_dir[256]; /* Length is safety-checked during startup */
238 int imap_total_entries;
239 int imap_total_ismime;
240 int imap_total_isfile;
241 int imap_total_isuri;
242 int imap_total_ishandler;
243 int imap_total_isreqheader;
244 int imap_total_isrspheader;
246 mod_gzip_imap imap[ MOD_GZIP_IMAP_MAXNAMES + 1 ];
248 #define MOD_GZIP_COMMAND_VERSION_USED
249 #ifdef MOD_GZIP_COMMAND_VERSION_USED
250 #define MOD_GZIP_COMMAND_VERSION 8001
251 #define MOD_GZIP_COMMAND_VERSION_MAXLEN 128
252 char command_version[ MOD_GZIP_COMMAND_VERSION_MAXLEN + 1 ];
253 int command_version_set;
256 #define MOD_GZIP_CAN_NEGOTIATE
257 #ifdef MOD_GZIP_CAN_NEGOTIATE
259 int can_negotiate_set;
264 long mod_gzip_iusn = 0;
266 int mod_gzip_strncmp( char *s1, char *s2, int len1 );
267 int mod_gzip_strnicmp( char *s1, char *s2, int len1 );
268 int mod_gzip_strcpy( char *s1, char *s2 );
269 int mod_gzip_strcat( char *s1, char *s2 );
270 int mod_gzip_strlen( char *s1 );
271 int mod_gzip_stringcontains( char *source, char *substring );
272 int mod_gzip_strendswith( char *s1, char *s2, int ignorcase );
274 #ifdef MOD_GZIP_CAN_NEGOTIATE
275 int mod_gzip_check_for_precompressed_file( request_rec *r );
278 int mod_gzip_create_unique_filename(
284 int mod_gzip_delete_file(
289 int mod_gzip_flush_and_update_counts(
291 mod_gzip_conf *dconf,
292 long total_header_bytes_sent,
293 long total_body_bytes_sent
296 long mod_gzip_sendfile1(
298 char *input_filename,
303 int mod_gzip_sendfile2(
305 mod_gzip_conf *dconf,
309 int mod_gzip_dyn1_getfdo1(
314 int mod_gzip_redir1_handler(
325 int mod_gzip_encode_and_transmit(
327 mod_gzip_conf *dconf,
329 int source_is_a_file,
333 char *result_prefix_string
336 typedef struct _GZP_CONTROL {
341 char *input_ismem_ibuf;
342 long input_ismem_ibuflen;
344 char input_filename[ MOD_GZIP_MAX_PATH_LEN + 2 ];
349 char *output_ismem_obuf;
350 long output_ismem_obuflen;
352 char output_filename[ MOD_GZIP_MAX_PATH_LEN + 2 ];
359 int gzp_main( request_rec *, GZP_CONTROL *gzp );
361 char mod_gzip_check_permissions[] =
362 "Make sure all named directories exist and have the correct permissions.";
364 #ifdef MOD_GZIP_DEBUG1
366 server_rec *mod_gzip_server_now = 0;
368 const char *npp( const char *s )
370 /* NOTE: This 'Null Pointer Protection' call is really only */
371 /* needed for the Solaris Operating System which seems to have */
372 /* some kind of problem handling NULL pointers passed to certain */
373 /* STDLIB calls. Sloaris will GP fault where all other OS's are OK. */
379 #ifdef MOD_GZIP_LOG_IS_APACHE_LOG
381 void mod_gzip_printf( const char *fmt, ... )
391 l = vsprintf( log_line, fmt, ap );
395 ap_log_error( "",0,APLOG_NOERRNO|APLOG_DEBUG, mod_gzip_server_now, log_line);
402 void mod_gzip_printf( const char *fmt, ... )
414 long pid = GetCurrentProcessId();
416 long pid = (long) getpid();
420 sprintf( logname, "c:\\temp\\t%ld.log",(long)pid);
422 sprintf( logname, "/tmp/t%ld.log",(long)pid);
425 log = fopen( logname,"a" );
434 l = vsprintf(log_line, fmt, ap);
437 while((*p1!=0)&&(*p1!=13)&&(*p1!=10)) p1++;
440 fprintf( log, "%s\n", log_line );
451 void mod_gzip_hexdump( char *buffer, int buflen )
477 for ( i=0; i<buflen; i++ )
479 ch1 = (char) *buffer++;
481 #define DUMPIT_ASTERISK 42
482 #define DUMPIT_LAPOSTROPHE 96
483 #define DUMPIT_RAPOSTROPHE 39
484 #define DUMPIT_PERIOD 46
488 #ifdef MASK_ONLY_CERTAIN_CHARS
489 if ( ch1 == 0 ) ch2 = DUMPIT_PERIOD;
490 else if ( ch1 == 13 ) ch2 = DUMPIT_CR;
491 else if ( ch1 == 10 ) ch2 = DUMPIT_LF;
492 else if ( ch1 == 9 ) ch2 = DUMPIT_LAPOSTROPHE;
496 #define MASK_ALL_NON_PRINTABLE_CHARS
497 #ifdef MASK_ALL_NON_PRINTABLE_CHARS
499 if ( ch1 == 13 ) ch2 = DUMPIT_CR;
500 else if ( ch1 == 10 ) ch2 = DUMPIT_LF;
501 else if ( ch1 < 32 ) ch2 = DUMPIT_PERIOD;
502 else if ( ch1 > 126) ch2 = DUMPIT_LAPOSTROPHE;
503 else if ( ch1 == 37 ) ch2 = DUMPIT_ASTERISK;
504 else if ( ch1 == 92 ) ch2 = DUMPIT_ASTERISK;
511 sprintf( s, "%02X", ch1 );
513 if ( mod_gzip_strlen(s) > 2 ) s[2]=0;
515 len1 = mod_gzip_strlen(s);
516 len2 = mod_gzip_strlen(l1);
518 if ( mod_gzip_strlen(l1) < (int)(sizeof(l1) - (len1+1)) )
528 mod_gzip_printf( "%6lu| %-49.49s| %-16.16s |", offset1, l1, l2 );
546 mod_gzip_printf( "%6lu| %-49.49s| %-16.16s |", offset1, l1, l2 );
558 int mod_gzip_log_comerror( request_rec *r, char *p, int error )
567 #if defined(WIN32) || defined(NETWARE)
569 if ( error == WSANOTINITIALISED )
571 sprintf(b[0],"%s * WSANOTINITIALISED",p);
572 sprintf(b[1],"%s * A successful WSAStartup() must occur",p);
573 sprintf(b[2],"%s * before using this WINSOCK API call.",p);
575 else if ( error == WSAENETDOWN )
577 sprintf(b[0],"%s * WSAENETDOWN",p);
578 sprintf(b[1],"%s * The Windows Sockets implementation has detected",p);
579 sprintf(b[2],"%s * that the network subsystem has failed.",p);
581 else if ( error == WSAENOTCONN )
583 sprintf(b[0],"%s * WSAENOTCONN",p);
584 sprintf(b[1],"%s * The socket is not connected.",p);
586 else if ( error == WSAEINTR )
588 sprintf(b[0],"%s * WSAEINTR",p);
589 sprintf(b[1],"%s * The (blocking) call was cancelled",p);
590 sprintf(b[2],"%s * via WSACancelBlockingCall()",p);
592 else if ( error == WSAEINPROGRESS )
594 sprintf(b[0],"%s * WSAEINPROGRESS",p);
595 sprintf(b[1],"%s * A blocking Windows Sockets operation",p);
596 sprintf(b[2],"%s * is in progress.",p);
598 else if ( error == WSAENOTSOCK )
600 sprintf(b[0],"%s * WSAENOTSOCK",p);
601 sprintf(b[1],"%s * The descriptor is not a socket.",p);
603 else if ( error == WSAEOPNOTSUPP )
605 sprintf(b[0],"%s * WSAEOPNOTSUPP",p);
606 sprintf(b[1],"%s * MSG_OOB was specified, but the socket is",p);
607 sprintf(b[2],"%s * not of type SOCK_STREAM.",p);
609 else if ( error == WSAESHUTDOWN )
611 sprintf(b[0],"%s * WSAESHUTDOWN",p);
612 sprintf(b[1],"%s * The socket has been shutdown.",p);
614 else if ( error == WSAEWOULDBLOCK )
616 sprintf(b[0],"%s * WSAEWOULDBLOCK",p);
617 sprintf(b[1],"%s * The socket is marked as non-blocking",p);
618 sprintf(b[2],"%s * and receive operation would block.",p);
620 else if ( error == WSAEMSGSIZE )
622 sprintf(b[0],"%s * WSAEMSGSIZE",p);
623 sprintf(b[1],"%s * The datagram was too large to",p);
624 sprintf(b[2],"%s * fit into the specified buffer.",p);
626 else if ( error == WSAEINVAL )
628 sprintf(b[0],"%s * WSAEINVAL",p);
629 sprintf(b[1],"%s * The socket has not been bound with bind().",p);
631 else if ( error == WSAECONNABORTED )
633 sprintf(b[0],"%s * WSAECONNABORTED",p);
634 sprintf(b[1],"%s * The virtual circuit was aborted",p);
635 sprintf(b[2],"%s * due to timeout or other failure.",p);
637 else if ( error == WSAECONNRESET )
639 sprintf(b[0],"%s * WSAECONNRESET",p);
640 sprintf(b[1],"%s * The virtual circuit was reset by the remote side.",p);
644 sprintf(b[0],"%s * WSA????",p);
645 sprintf(b[1],"%s * Unexpected WINSOCK error code %d",p,error);
650 if ( error == EBADF ) sprintf(b[0],"%s * EBADF", p );
651 else if ( error == EAGAIN ) sprintf(b[0],"%s * EAGAIN",p );
652 else if ( error == EDQUOT ) sprintf(b[0],"%s * EDQUOT",p );
653 else if ( error == EFAULT ) sprintf(b[0],"%s * EFAULT",p );
654 else if ( error == EFBIG ) sprintf(b[0],"%s * EFBIG", p );
655 else if ( error == EINTR ) sprintf(b[0],"%s * EINTR", p );
656 else if ( error == EINVAL ) sprintf(b[0],"%s * EINVAL",p );
657 else if ( error == EIO ) sprintf(b[0],"%s * EIO", p );
658 else if ( error == ENOSPC ) sprintf(b[0],"%s * ENOSPC",p );
659 else if ( error == ENXIO ) sprintf(b[0],"%s * ENXIO", p );
660 else if ( error == EPIPE ) sprintf(b[0],"%s * EPIPE", p );
661 else if ( error == ERANGE ) sprintf(b[0],"%s * ERANGE",p );
662 else if ( error == EINVAL ) sprintf(b[0],"%s * EINVAL",p );
663 else if ( error == EWOULDBLOCK ) sprintf(b[0],"%s * EWOULDBLOCK",p );
667 sprintf(b[0],"%s * E???? Unexpected error code %d",p,error);
672 for ( i=0; i<3; i++ )
676 #ifdef MOD_GZIP_DEBUG1
677 mod_gzip_printf("%s",npp(b[i]));
685 int mod_gzip_translate_comerror( int error, char *buf )
694 #if defined(WIN32) || defined(NETWARE)
696 if ( error == WSANOTINITIALISED ) sprintf(bb,"WSANOTINITIALISED");
697 else if ( error == WSAENETDOWN ) sprintf(bb,"WSAENETDOWN");
698 else if ( error == WSAENOTCONN ) sprintf(bb,"WSAENOTCONN");
699 else if ( error == WSAEINTR ) sprintf(bb,"WSAEINTR");
700 else if ( error == WSAEINPROGRESS ) sprintf(bb,"WSAEINPROGRESS");
701 else if ( error == WSAENOTSOCK ) sprintf(bb,"WSAENOTSOCK");
702 else if ( error == WSAEOPNOTSUPP ) sprintf(bb,"WSAEOPNOTSUPP");
703 else if ( error == WSAESHUTDOWN ) sprintf(bb,"WSAESHUTDOWN");
704 else if ( error == WSAEWOULDBLOCK ) sprintf(bb,"WSAEWOULDBLOCK");
705 else if ( error == WSAEMSGSIZE ) sprintf(bb,"WSAEMSGSIZE");
706 else if ( error == WSAEINVAL ) sprintf(bb,"WSAEINVAL");
707 else if ( error == WSAECONNABORTED ) sprintf(bb,"WSAECONNABORTED");
708 else if ( error == WSAECONNRESET ) sprintf(bb,"WSAECONNRESET");
709 else sprintf(bb,"%d=WSA????",error);
713 if ( error == EBADF ) sprintf(bb,"EBADF" );
714 else if ( error == EAGAIN ) sprintf(bb,"EAGAIN" );
715 else if ( error == EDQUOT ) sprintf(bb,"EDQUOT" );
716 else if ( error == EFAULT ) sprintf(bb,"EFAULT" );
717 else if ( error == EFBIG ) sprintf(bb,"EFBIG" );
718 else if ( error == EINTR ) sprintf(bb,"EINTR" );
719 else if ( error == EINVAL ) sprintf(bb,"EINVAL" );
720 else if ( error == EIO ) sprintf(bb,"EIO" );
721 else if ( error == ENOSPC ) sprintf(bb,"ENOSPC" );
722 else if ( error == ENXIO ) sprintf(bb,"ENXIO" );
723 else if ( error == EPIPE ) sprintf(bb,"EPIPE" );
724 else if ( error == ERANGE ) sprintf(bb,"ERANGE" );
725 else if ( error == EINVAL ) sprintf(bb,"EINVAL" );
726 else if ( error == EWOULDBLOCK ) sprintf(bb,"EWOULDBLOCK" );
727 else sprintf(bb,"%d=E????",error);
731 mod_gzip_strcpy( buf, bb );
738 int mod_gzip_validate1(
743 char *r__content_type,
761 int this_include = 0;
762 char *checktarget = 0;
764 int action_value = 0;
765 int filter_value = 0;
766 int type_to_match = 0;
767 int ok_to_check_it = 0;
768 int http_field_check = 0;
769 int item_is_included = 0;
770 int item_is_excluded = 0;
771 int type_is_included = 0;
773 regex_t *this_pregex = NULL;
776 #ifdef MOD_GZIP_DEBUG1
777 char cn[]="mod_gzip_validate1()";
780 if ( r__filename ) flen = mod_gzip_strlen( (char *) r__filename );
781 if ( r__uri ) ulen = mod_gzip_strlen( (char *) r__uri );
782 if ( r__content_type ) clen = mod_gzip_strlen( (char *) r__content_type );
783 if ( r__handler ) hlen = mod_gzip_strlen( (char *) r__handler );
785 #ifdef MOD_GZIP_DEBUG1
787 mod_gzip_printf( "%s: Entry...",cn);
788 mod_gzip_printf( "%s: r__filename = [%s]",cn,npp(r__filename));
789 mod_gzip_printf( "%s: flen = %d", cn,flen);
790 mod_gzip_printf( "%s: r__uri = [%s]",cn,npp(r__uri));
791 mod_gzip_printf( "%s: ulen = %d", cn,ulen);
792 mod_gzip_printf( "%s: r__content_type = [%s]",cn,npp(r__content_type));
793 mod_gzip_printf( "%s: clen = %d", cn,clen);
794 mod_gzip_printf( "%s: r__handler = [%s]",cn,npp(r__handler));
795 mod_gzip_printf( "%s: hlen = %d", cn,hlen);
796 mod_gzip_printf( "%s: fieldkey = [%s]",cn,npp(fieldkey));
797 mod_gzip_printf( "%s: fieldstring = [%s]",cn,npp(fieldstring));
798 mod_gzip_printf( "%s: direction = %d", cn,direction);
802 if ( ( fieldkey ) && ( fieldstring ) )
804 http_field_check = 1;
808 if ( direction == MOD_GZIP_REQUEST )
810 type_to_match = MOD_GZIP_IMAP_ISREQHEADER;
812 else if ( direction == MOD_GZIP_RESPONSE )
814 type_to_match = MOD_GZIP_IMAP_ISRSPHEADER;
818 #ifdef MOD_GZIP_DEBUG1
819 mod_gzip_printf( "%s: Invalid 'direction' value.",cn);
820 mod_gzip_printf( "%s: Must be MOD_GZIP_REQUEST or MOD_GZIP_RESPONSE",cn);
821 mod_gzip_printf( "%s: Exit > return( MOD_GZIP_IMAP_DECLINED1 ) >",cn);
824 return( MOD_GZIP_IMAP_DECLINED1 );
828 else if ( ( hlen == 0 ) && ( clen == 0 ) && ( flen == 0 ) )
830 #ifdef MOD_GZIP_DEBUG1
831 mod_gzip_printf( "%s: hlen = 0 = No handler name passed...",cn);
832 mod_gzip_printf( "%s: clen = 0 = No valid content-type passed",cn);
833 mod_gzip_printf( "%s: flen = 0 = No valid filename passed",cn);
834 mod_gzip_printf( "%s: There is nothing we can use to search",cn);
835 mod_gzip_printf( "%s: for a match in the inclusion/exclusion list.",cn);
836 mod_gzip_printf( "%s: Exit > return( MOD_GZIP_IMAP_DECLINED1 ) >",cn);
839 return( MOD_GZIP_IMAP_DECLINED1 );
842 #ifdef MOD_GZIP_DEBUG1
843 mod_gzip_printf( "%s: passes = %d", cn,
845 mod_gzip_printf( "%s: http_field_check = %d", cn,
846 (int) http_field_check );
847 mod_gzip_printf( "%s: mgc->imap_total_entries = %d", cn,
848 (int) mgc->imap_total_entries );
851 for ( pass=0; pass<passes; pass++ )
855 #ifdef MOD_GZIP_DEBUG1_VALIDATE1_VERBOSE1
856 #ifdef MOD_GZIP_DEBUG1
857 mod_gzip_printf( "%s: ",cn);
863 #ifdef MOD_GZIP_DEBUG1_VALIDATE1_VERBOSE1
864 #ifdef MOD_GZIP_DEBUG1
865 mod_gzip_printf( "%s: pass = %d", cn, pass );
866 mod_gzip_printf( "%s: filter_value = %d", cn, filter_value );
867 mod_gzip_printf( "%s: mgc->imap_total_entries = %d", cn,
868 (int) mgc->imap_total_entries );
872 for ( x=0; x < mgc->imap_total_entries; x++ )
874 this_include = mgc->imap[x].include;
875 this_type = mgc->imap[x].type;
876 this_action = mgc->imap[x].action;
878 #ifdef MOD_GZIP_DEBUG1_VALIDATE1_VERBOSE1
879 #ifdef MOD_GZIP_DEBUG1
881 mod_gzip_printf( "%s: --------------------------------------------",cn);
882 mod_gzip_printf( "%s: http_field_check = %d", cn,http_field_check );
884 if ( http_field_check )
886 mod_gzip_printf( "%s: fieldkey = [%s]",cn,npp(fieldkey));
887 mod_gzip_printf( "%s: fieldstring = [%s]",cn,npp(fieldstring));
891 mod_gzip_printf( "%s: r__filename = [%s]",cn,npp(r__filename));
892 mod_gzip_printf( "%s: r__uri = [%s]",cn,npp(r__uri));
893 mod_gzip_printf( "%s: r__content_type = [%s]",cn,npp(r__content_type));
894 mod_gzip_printf( "%s: r__handler = [%s]",cn,npp(r__handler));
897 if ( this_include == 0 )
899 mod_gzip_printf( "%s: mgc->imap[%3.3d].include = %d EXCLUDE",cn,x,this_include);
901 else if ( this_include == 1 )
903 mod_gzip_printf( "%s: mgc->imap[%3.3d].include = %d INCLUDE",cn,x,this_include);
907 mod_gzip_printf( "%s: mgc->imap[%3.3d].include = %d ??? UNKNOWN VALUE",cn,x,this_include);
910 if ( mgc->imap[x].type == MOD_GZIP_IMAP_ISMIME )
912 mod_gzip_printf( "%s: mgc->imap[%3.3d].type = %d MOD_GZIP_IMAP_ISMIME",
915 else if ( mgc->imap[x].type == MOD_GZIP_IMAP_ISHANDLER )
917 mod_gzip_printf( "%s: mgc->imap[%3.3d].type = %d MOD_GZIP_IMAP_ISHANDLER",
920 else if ( mgc->imap[x].type == MOD_GZIP_IMAP_ISFILE )
922 mod_gzip_printf( "%s: mgc->imap[%3.3d].type = %d MOD_GZIP_IMAP_ISFILE",
925 else if ( mgc->imap[x].type == MOD_GZIP_IMAP_ISURI )
927 mod_gzip_printf( "%s: mgc->imap[%3.3d].type = %d MOD_GZIP_IMAP_ISURI",
930 else if ( mgc->imap[x].type == MOD_GZIP_IMAP_ISREQHEADER )
932 mod_gzip_printf( "%s: mgc->imap[%3.3d].type = %d MOD_GZIP_IMAP_ISREQHEADER",
935 else if ( mgc->imap[x].type == MOD_GZIP_IMAP_ISRSPHEADER )
937 mod_gzip_printf( "%s: mgc->imap[%3.3d].type = %d MOD_GZIP_IMAP_ISRSPHEADER",
942 mod_gzip_printf( "%s: mgc->imap[%3.3d].type = %d MOD_GZIP_IMAP_IS??? Unknown type",
946 if ( mgc->imap[x].action == MOD_GZIP_IMAP_STATIC1 )
948 mod_gzip_printf( "%s: mgc->imap[%3.3d].action = %d MOD_GZIP_IMAP_STATIC1",
951 else if ( mgc->imap[x].action == MOD_GZIP_IMAP_DYNAMIC1 )
953 mod_gzip_printf( "%s: mgc->imap[%3.3d].action = %d MOD_GZIP_IMAP_DYNAMIC1",
956 else if ( mgc->imap[x].action == MOD_GZIP_IMAP_DYNAMIC2 )
958 mod_gzip_printf( "%s: mgc->imap[%3.3d].action = %d MOD_GZIP_IMAP_DYNAMIC2",
963 mod_gzip_printf( "%s: mgc->imap[%3.3d].action = %d MOD_GZIP_IMAP_??? Unknown action",
967 mod_gzip_printf( "%s: mgc->imap[%3.3d].name = [%s]",cn,x,npp(mgc->imap[x].name));
968 mod_gzip_printf( "%s: mgc->imap[%3.3d].namelen = %d", cn,x,mgc->imap[x].namelen);
973 if ( this_include == filter_value )
975 #ifdef MOD_GZIP_DEBUG1_VALIDATE1_VERBOSE1
976 #ifdef MOD_GZIP_DEBUG1
977 mod_gzip_printf( "%s: This record matches filter_value %d",
979 mod_gzip_printf( "%s: The record will be checked...",cn);
983 type_is_included = 0;
986 if ( http_field_check )
988 if ( this_type == type_to_match )
990 type_is_included = 1;
992 checktarget = (char *) fieldstring;
997 if ( ( this_type == MOD_GZIP_IMAP_ISMIME ) &&
1000 type_is_included = 1;
1002 checktarget = r__content_type;
1004 else if ( ( this_type == MOD_GZIP_IMAP_ISFILE ) &&
1007 type_is_included = 1;
1009 checktarget = r__filename;
1011 else if ( ( this_type == MOD_GZIP_IMAP_ISURI ) &&
1014 type_is_included = 1;
1016 checktarget = r__uri;
1018 else if ( ( this_type == MOD_GZIP_IMAP_ISHANDLER ) &&
1021 type_is_included = 1;
1023 checktarget = r__handler;
1027 if ( type_is_included )
1029 #ifdef MOD_GZIP_DEBUG1_VALIDATE1_VERBOSE1
1030 #ifdef MOD_GZIP_DEBUG1
1031 mod_gzip_printf( "%s: type_is_included = %d = YES",cn,type_is_included);
1035 this_name = mgc->imap[x].name;
1036 this_len1 = mgc->imap[x].len1;
1037 this_pregex = mgc->imap[x].pregex;
1041 if ( http_field_check )
1043 #ifdef MOD_GZIP_DEBUG1_VALIDATE1_VERBOSE1
1044 #ifdef MOD_GZIP_DEBUG1
1045 mod_gzip_printf( "%s: fieldkey = [%s]",cn,npp(fieldkey));
1046 mod_gzip_printf( "%s: this_name = [%s]",cn,npp(this_name));
1047 mod_gzip_printf( "%s: this_len1 = %d", cn,this_len1);
1048 mod_gzip_printf( "%s: Call mod_gzip_strnicmp(fieldkey,this_name,this_len1)...",cn);
1052 if ( mod_gzip_strnicmp( fieldkey, this_name, this_len1 )==0)
1054 #ifdef MOD_GZIP_DEBUG1_VALIDATE1_VERBOSE1
1055 #ifdef MOD_GZIP_DEBUG1
1056 mod_gzip_printf( "%s: .... mod_gzip_strnicmp() = TRUE",cn);
1057 mod_gzip_printf( "%s: .... Field key name MATCHES",cn);
1063 #ifdef MOD_GZIP_DEBUG1_VALIDATE1_VERBOSE1
1064 #ifdef MOD_GZIP_DEBUG1
1065 mod_gzip_printf( "%s: .... mod_gzip_strnicmp() = FALSE",cn);
1066 mod_gzip_printf( "%s: .... Field key name does NOT MATCH",cn);
1074 if ( ok_to_check_it )
1076 #ifdef MOD_GZIP_DEBUG1_VALIDATE1_VERBOSE1
1077 #ifdef MOD_GZIP_DEBUG1
1078 mod_gzip_printf( "%s: ok_to_check_it = %d = YES",cn,ok_to_check_it);
1082 if ( ( this_pregex ) && ( checktarget ) )
1084 #ifdef MOD_GZIP_DEBUG1
1085 mod_gzip_printf( "%s: 'this_pregex' is NON-NULL",cn);
1086 mod_gzip_printf( "%s: Performing regular expression check...",cn);
1087 mod_gzip_printf( "%s: Call ap_regexec( this_name=[%s], checktarget=[%s] )",
1088 cn, npp(this_name), npp(checktarget) );
1093 this_pregex, checktarget, 0, (regmatch_t *) NULL, 0 );
1095 if ( regex_error == 0 )
1097 #ifdef MOD_GZIP_DEBUG1
1098 mod_gzip_printf( "%s: YYYY regex_error = %d = MATCH!",cn,regex_error);
1102 action_value = this_action;
1107 #ifdef MOD_GZIP_DEBUG1
1108 mod_gzip_printf( "%s: NNNN regex_error = %d = NO MATCH!",cn,regex_error);
1114 #ifdef MOD_GZIP_DEBUG1
1118 mod_gzip_printf( "%s: 'this_pregex' is NULL",cn);
1122 mod_gzip_printf( "%s: 'checktarget' is NULL",cn);
1125 mod_gzip_printf( "%s: No regular expression check performed",cn);
1132 #ifdef MOD_GZIP_DEBUG1_VALIDATE1_VERBOSE1
1133 #ifdef MOD_GZIP_DEBUG1
1134 mod_gzip_printf( "%s: ok_to_check_it = %d = NO",cn,ok_to_check_it);
1135 mod_gzip_printf( "%s: The record has been SKIPPED...",cn);
1142 #ifdef MOD_GZIP_DEBUG1_VALIDATE1_VERBOSE1
1143 #ifdef MOD_GZIP_DEBUG1
1144 mod_gzip_printf( "%s: type_is_included = %d = NO",cn,type_is_included);
1145 mod_gzip_printf( "%s: The record has been SKIPPED...",cn);
1152 #ifdef MOD_GZIP_DEBUG1_VALIDATE1_VERBOSE1
1153 #ifdef MOD_GZIP_DEBUG1
1154 mod_gzip_printf( "%s: This record does NOT match filter_value %d",
1156 mod_gzip_printf( "%s: The record has been SKIPPED...",cn);
1162 #ifdef MOD_GZIP_DEBUG1_VALIDATE1_VERBOSE1
1163 #ifdef MOD_GZIP_DEBUG1
1164 mod_gzip_printf( "%s: --------------------------------------------",cn);
1165 mod_gzip_printf( "%s: pass_result = %d",cn,pass_result);
1171 if ( pass == 0 ) item_is_excluded = 1;
1172 else item_is_included = 1;
1177 }/* End 'for ( pass=0; pass<passes; pass++ )' */
1179 #ifdef MOD_GZIP_DEBUG1
1180 mod_gzip_printf( "%s: item_is_excluded = %d",cn,item_is_excluded);
1181 mod_gzip_printf( "%s: item_is_included = %d",cn,item_is_included);
1184 if ( item_is_excluded )
1186 #ifdef MOD_GZIP_DEBUG1
1187 mod_gzip_printf( "%s: The item is EXCLUDED...",cn);
1188 mod_gzip_printf( "%s: Exit > return( MOD_GZIP_IMAP_DECLINED1 ) >",cn);
1191 return( MOD_GZIP_IMAP_DECLINED1 );
1194 else if ( item_is_included )
1196 #ifdef MOD_GZIP_DEBUG1
1197 mod_gzip_printf( "%s: The item is INCLUDED...",cn);
1198 mod_gzip_printf( "%s: Exit > return( 1 ) >",cn);
1201 return action_value;
1204 if ( http_field_check )
1206 #ifdef MOD_GZIP_DEBUG1
1207 mod_gzip_printf( "%s: ?? Status unknown ?? Default is to 'accept'...",cn);
1208 mod_gzip_printf( "%s: Exit > return( MOD_GZIP_IMAP_STATIC1 ) >",cn);
1211 return MOD_GZIP_IMAP_STATIC1;
1214 #ifdef MOD_GZIP_DEBUG1
1215 mod_gzip_printf( "%s: Exit > return( MOD_GZIP_IMAP_DECLINED1 ) >",cn);
1218 return( MOD_GZIP_IMAP_DECLINED1 );
1222 /* NOTE: If API_VAR_EXPORT prefix is not used for 'top_module' */
1223 /* declaration then MSVC 6.0 will give 'incosistent DLL linkage' */
1224 /* warning during WIN32 compile... */
1226 extern API_VAR_EXPORT module *top_module;
1230 #ifdef MAKE_TABLE_PROFILE
1234 typedef struct _table _table;
1236 #ifdef MOD_GZIP_DEBUG1
1238 int mod_gzip_dump_a_table( request_rec *r, _table *t )
1240 table_entry *elts = (table_entry *) t->a.elts;
1243 char cn[]="mod_gzip_dump_a_table()";
1245 for ( i = 0; i < t->a.nelts; i++ )
1247 mod_gzip_printf( "%s: %3.3d key=[%s] val=[%s]",
1248 cn,i,npp(elts[i].key),npp(elts[i].val));
1256 #define MOD_GZIP_RUN_TYPE_CHECKERS 1
1257 #define MOD_GZIP_RUN_TRANSLATE_HANDLERS 2
1259 int mod_gzip_run_handlers( request_rec *r, int flag1 )
1264 int handler_is_present=0;
1268 #ifdef MOD_GZIP_DEBUG1
1269 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
1270 const handler_rec *handp;
1271 char cn[]="mod_gzip_run_handlers()";
1275 #ifdef MOD_GZIP_DEBUG1
1276 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
1277 mod_gzip_server_now = r->server;
1278 mod_gzip_printf( "%s: Entry...",cn);
1279 mod_gzip_printf( "%s: *IN: r->uri =[%s]", cn, npp(r->uri));
1280 mod_gzip_printf( "%s: *IN: r->unparsed_uri =[%s]", cn, npp(r->unparsed_uri));
1281 mod_gzip_printf( "%s: *IN: r->filename =[%s]", cn, npp(r->filename));
1282 mod_gzip_printf( "%s: *IN: r->handler =[%s]", cn, npp(r->handler));
1283 mod_gzip_printf( "%s: *IN: r->content_type =[%s]", cn, npp(r->content_type));
1287 if ( flag1 == MOD_GZIP_RUN_TYPE_CHECKERS )
1289 #ifdef MOD_GZIP_DEBUG1
1290 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
1291 mod_gzip_printf( "%s: flag1 = %d = MOD_GZIP_RUN_TYPE_CHECKERS",cn,flag1);
1295 else if ( flag1 == MOD_GZIP_RUN_TRANSLATE_HANDLERS )
1297 #ifdef MOD_GZIP_DEBUG1
1298 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
1299 mod_gzip_printf( "%s: flag1 = %d = MOD_GZIP_RUN_TRANSLATE_HANDLERS",cn,flag1);
1305 #ifdef MOD_GZIP_DEBUG1
1306 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
1307 mod_gzip_printf( "%s: flag1 = %d = MOD_GZIP_RUN_??? Unknown value",cn,flag1);
1308 mod_gzip_printf( "%s: ERROR: Exit > return( DECLINED ) >",cn);
1315 for ( modp = top_module; modp; modp = modp->next )
1317 #ifdef MOD_GZIP_DEBUG1
1318 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
1319 mod_gzip_printf( "%s: count=%4.4d modp = %10.10ld modp->name=[%s]",
1320 cn,count,(long)modp,npp(modp->name));
1330 if ( modp == &gzip_module )
1336 if ( mod_gzip_strnicmp( (char *) modp->name, "mod_gzip.c",10)==0)
1345 #ifdef MOD_GZIP_DEBUG1
1346 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
1348 mod_gzip_printf( "%s: ++++++++++ MODULE FOUND!...",cn);
1349 mod_gzip_printf( "%s: ++++++++++ modp->module_index = %d",cn,(int)modp->module_index);
1354 const char *content_type;
1355 int (*handler) (request_rec *);
1358 typedef struct module_struct {
1360 const handler_rec *handlers;
1366 mod_gzip_printf( "%s: ++++++++++ METHODS",cn);
1367 mod_gzip_printf( "%s: ++++++++++ modp->translate_handler = %ld",cn,(long)modp->translate_handler);
1368 mod_gzip_printf( "%s: ++++++++++ modp->ap_check_user_id = %ld",cn,(long)modp->ap_check_user_id);
1369 mod_gzip_printf( "%s: ++++++++++ modp->auth_checker = %ld",cn,(long)modp->auth_checker);
1370 mod_gzip_printf( "%s: ++++++++++ modp->access_checker = %ld",cn,(long)modp->access_checker);
1371 mod_gzip_printf( "%s: ++++++++++ modp->type_checker = %ld",cn,(long)modp->type_checker);
1372 mod_gzip_printf( "%s: ++++++++++ modp->fixer_upper = %ld",cn,(long)modp->fixer_upper);
1373 mod_gzip_printf( "%s: ++++++++++ modp->logger = %ld",cn,(long)modp->logger);
1374 mod_gzip_printf( "%s: ++++++++++ modp->header_parser = %ld",cn,(long)modp->header_parser);
1375 mod_gzip_printf( "%s: .......... CONTENT HANDLERS",cn);
1377 if ( !modp->handlers )
1379 mod_gzip_printf( "%s: .......... NO CONTENT HANDLERS!",cn);
1383 for ( handp = modp->handlers; handp->content_type; ++handp )
1385 mod_gzip_printf( "%s: .......... handp->content_type = [%s]",
1386 cn,npp(handp->content_type));
1387 mod_gzip_printf( "%s: .......... handp->handler = %ld",
1388 cn,(long)handp->handler);
1395 handler_is_present = 0;
1397 if ( flag1 == MOD_GZIP_RUN_TYPE_CHECKERS )
1399 if ( modp->type_checker ) handler_is_present = 1;
1401 else if ( flag1 == MOD_GZIP_RUN_TRANSLATE_HANDLERS )
1403 if ( modp->translate_handler ) handler_is_present = 1;
1406 #ifdef MOD_GZIP_DEBUG1
1407 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
1408 mod_gzip_printf( "%s: handler_is_present = %d ",
1409 cn, handler_is_present);
1413 if ( handler_is_present )
1415 #ifdef MOD_GZIP_DEBUG1
1416 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
1418 mod_gzip_printf( "%s: 'handler_is_present' is TRUE...",cn);
1420 mod_gzip_printf( "%s: r->filename = [%s]",cn,npp(r->filename));
1421 mod_gzip_printf( "%s: r->uri = [%s]",cn,npp(r->uri));
1422 mod_gzip_printf( "%s: r->handler = [%s]",cn,npp(r->handler));
1423 mod_gzip_printf( "%s: r->content_type = [%s]",cn,npp(r->content_type));
1425 if ( flag1 == MOD_GZIP_RUN_TYPE_CHECKERS )
1427 mod_gzip_printf( "%s: Call (modp->type_checker)(r)...",cn);
1429 else if ( flag1 == MOD_GZIP_RUN_TRANSLATE_HANDLERS )
1431 mod_gzip_printf( "%s: Call (modp->translate_handler)(r)...",cn);
1437 if ( flag1 == MOD_GZIP_RUN_TYPE_CHECKERS )
1439 rc = (modp->type_checker)( (request_rec *) r );
1441 else if ( flag1 == MOD_GZIP_RUN_TRANSLATE_HANDLERS )
1443 rc = (modp->translate_handler)( (request_rec *) r );
1446 #ifdef MOD_GZIP_DEBUG1
1447 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
1449 if ( flag1 == MOD_GZIP_RUN_TYPE_CHECKERS )
1451 mod_gzip_printf( "%s: Back (modp->type_checker)(r)...",cn);
1453 else if ( flag1 == MOD_GZIP_RUN_TRANSLATE_HANDLERS )
1455 mod_gzip_printf( "%s: Back (modp->translate_handler)(r)...",cn);
1458 mod_gzip_printf( "%s: r->filename = [%s]",cn,npp(r->filename));
1459 mod_gzip_printf( "%s: r->uri = [%s]",cn,npp(r->uri));
1460 mod_gzip_printf( "%s: r->handler = [%s]",cn,npp(r->handler));
1461 mod_gzip_printf( "%s: r->content_type = [%s]",cn,npp(r->content_type));
1465 mod_gzip_printf( "%s: rc = %d = OK",cn, rc );
1467 else if ( rc == DECLINED )
1469 mod_gzip_printf( "%s: rc = %d = DECLINED",cn, rc );
1471 else if ( rc == DONE )
1473 mod_gzip_printf( "%s: rc = %d = DONE",cn, rc );
1477 mod_gzip_printf( "%s: rc = %d = HTTP_ERROR?",cn, rc );
1485 #ifdef MOD_GZIP_DEBUG1
1486 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
1487 mod_gzip_printf( "%s: Call SUCCEEDED",cn );
1488 mod_gzip_printf( "%s: Exit > return( rc=%d ) >",cn,rc);
1496 #ifdef MOD_GZIP_DEBUG1
1497 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
1498 mod_gzip_printf( "%s: Call FAILED",cn );
1502 if ( rc != DECLINED )
1504 #ifdef MOD_GZIP_DEBUG1
1505 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
1506 mod_gzip_printf( "%s: Something other than 'DECLINED' was returned.",cn);
1507 mod_gzip_printf( "%s: Exit > return( rc=%d ) >",cn,rc);
1515 #ifdef MOD_GZIP_DEBUG1
1516 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
1517 mod_gzip_printf( "%s: 'DECLINED' was returned... Continuing chain...",cn);
1525 #ifdef MOD_GZIP_DEBUG1
1526 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
1527 mod_gzip_printf( "%s: 'handler_is_present' is FALSE...",cn);
1534 #ifdef MOD_GZIP_DEBUG1
1535 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
1536 mod_gzip_printf( "%s: 'runit' is FALSE...",cn);
1537 mod_gzip_printf( "%s: SKIPPING THIS MODULE",cn);
1545 #ifdef MOD_GZIP_DEBUG1
1546 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
1547 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
1555 int mod_gzip_delete_file(
1560 #ifdef MOD_GZIP_DEBUG1
1561 char cn[]="mod_gzip_delete_file()";
1572 #ifdef MOD_GZIP_DEBUG1
1573 mod_gzip_printf( "%s: Entry...",cn);
1574 mod_gzip_printf( "%s: filename = [%s]",cn,npp(filename));
1579 #ifdef MOD_GZIP_DEBUG1
1580 mod_gzip_printf( "%s: Call DeleteFile(%s)...",cn,npp(filename));
1583 rc = (BOOL) DeleteFile( filename );
1585 #ifdef MOD_GZIP_DEBUG1
1586 mod_gzip_printf( "%s: Back DeleteFile(%s)...",cn,npp(filename));
1591 #ifdef MOD_GZIP_DEBUG1
1592 mod_gzip_printf( "%s: .... DeleteFile() FAILED",cn);
1597 #ifdef MOD_GZIP_DEBUG1
1598 mod_gzip_printf( "%s: .... DeleteFile() SUCCEEDED",cn);
1606 #ifdef MOD_GZIP_DEBUG1
1607 mod_gzip_printf( "%s: Call unlink(%s)...",cn,npp(filename));
1610 rc = (int) unlink( filename );
1612 #ifdef MOD_GZIP_DEBUG1
1613 mod_gzip_printf( "%s: Back unlink(%s)...",cn,npp(filename));
1618 #ifdef MOD_GZIP_DEBUG1
1619 mod_gzip_printf( "%s: .... unlink() FAILED",cn);
1624 #ifdef MOD_GZIP_DEBUG1
1625 mod_gzip_printf( "%s: .... unlink() SUCCEEDED",cn);
1633 #ifdef MOD_GZIP_DEBUG1
1635 if ( final_rc == 1 )
1637 mod_gzip_printf( "%s: Exit > return( final_rc = %d ) SUCCESS >",cn,final_rc);
1641 mod_gzip_printf( "%s: Exit > return( final_rc = %d ) FAILURE >",cn,final_rc);
1649 static void mod_gzip_init( server_rec *server, pool *p )
1651 int add_version_info=1;
1653 #ifdef MOD_GZIP_DEBUG1
1654 char cn[]="mod_gzip_init()";
1659 #ifdef MOD_GZIP_DEBUG1
1661 mod_gzip_server_now = server;
1663 mod_gzip_printf( " " );
1664 mod_gzip_printf( "%s: Entry...", cn );
1668 mgc = ( mod_gzip_conf * )
1669 ap_get_module_config( server->module_config, &gzip_module );
1671 #ifdef MOD_GZIP_DEBUG1
1672 mod_gzip_printf( "%s: MODULE_MAGIC_NUMBER = %ld", cn, (long) MODULE_MAGIC_NUMBER );
1675 if ( add_version_info )
1677 #ifdef MOD_GZIP_DEBUG1
1678 mod_gzip_printf( "%s: add_version_info = TRUE", cn );
1681 #if MODULE_MAGIC_NUMBER >= 19980507
1683 #ifdef MOD_GZIP_DEBUG1
1684 mod_gzip_printf( "%s: MODULE_MAGIC_NUMBER is >= 19980507",cn);
1685 mod_gzip_printf( "%s: Call ap_add_version_component(%s)...",
1686 cn, npp(MOD_GZIP_VERSION_INFO_STRING));
1689 ap_add_version_component( MOD_GZIP_VERSION_INFO_STRING );
1691 #ifdef MOD_GZIP_DEBUG1
1692 mod_gzip_printf( "%s: Back ap_add_version_component(%s)...",
1693 cn, npp(MOD_GZIP_VERSION_INFO_STRING));
1698 #ifdef MOD_GZIP_DEBUG1
1699 mod_gzip_printf( "%s: MODULE_MAGIC_NUMBER is NOT >= 19980507", cn );
1700 mod_gzip_printf( "%s: ap_add_version_component() NOT called.", cn );
1707 #ifdef MOD_GZIP_DEBUG1
1708 mod_gzip_printf( "%s: add_version_info = FALSE", cn );
1709 mod_gzip_printf( "%s: ap_add_version_component() NOT called.", cn );
1713 #ifdef MOD_GZIP_DEBUG1
1714 mod_gzip_printf( "%s: Initialization completed...", cn );
1715 mod_gzip_printf( "%s: Exit > return( void ) >", cn );
1716 mod_gzip_printf( " " );
1720 int mod_gzip_strncmp( char *s1, char *s2, int len1 )
1726 if ( ( s1 == 0 ) || ( s2 == 0 ) )
1731 for ( i=0; i<len1; i++ )
1733 if ( ( *s1 == 0 ) || ( *s2 == 0 ) ) return( 1 );
1738 if ( ch1 == '/' ) ch1 = '\\';
1739 if ( ch2 == '/' ) ch2 = '\\';
1741 if ( ch1 != ch2 ) return 1;
1750 int mod_gzip_strnicmp( char *s1, char *s2, int len1 )
1756 if ( ( s1 == 0 ) || ( s2 == 0 ) )
1761 for ( i=0; i<len1; i++ )
1763 if ( ( *s1 == 0 ) || ( *s2 == 0 ) ) return( 1 );
1768 if ( ch1 > 96 ) ch1 -= 32;
1769 if ( ch2 > 96 ) ch2 -= 32;
1771 if ( ch1 == '/' ) ch1 = '\\';
1772 if ( ch2 == '/' ) ch2 = '\\';
1774 if ( ch1 != ch2 ) return 1;
1783 int mod_gzip_strendswith( char *s1, char *s2, int ignorcase )
1788 if ( ( s1 == 0 ) || ( s2 == 0 ) )
1793 len1 = mod_gzip_strlen( s1 );
1794 len2 = mod_gzip_strlen( s2 );
1798 /* Source string is shorter than search string */
1799 /* so no match is possible */
1804 s1 += ( len1 - len2 );
1808 if ( mod_gzip_strnicmp( s1, s2, len2 ) == 0 ) return 1; /* TRUE */
1812 if ( mod_gzip_strncmp( s1, s2, len2 ) == 0 ) return 1; /* TRUE */
1815 return 0; /* FALSE */
1818 int mod_gzip_strlen( char *s1 )
1824 while( *s1 != 0 ) { s1++; len++; }
1830 int mod_gzip_strcpy( char *s1, char *s2 )
1834 if ( ( s1 != 0 )&&( s2 != 0 ) )
1836 while( *s2 != 0 ) { *s1++ = *s2++; len++; }
1843 int mod_gzip_strcat( char *s1, char *s2 )
1849 while( *s1 != 0 ) { s1++; len++; }
1852 while( *s2 != 0 ) { *s1++ = *s2++; len++; }
1860 int mod_gzip_stringcontains( char *source, char *substring )
1871 if ( source == NULL )
1876 if ( substring == NULL )
1882 substring1 = substring;
1884 len1 = mod_gzip_strlen( source );
1885 len2 = mod_gzip_strlen( substring );
1894 for ( i=0; i<=len3; i++ )
1896 if ( mod_gzip_strnicmp( source, substring, len2 ) == 0 )
1899 substring = substring1;
1909 substring = substring1;
1914 int mod_gzip_show_request_record(
1919 #ifdef MOD_GZIP_DEBUG1
1921 mod_gzip_printf( "%s: -------------------------------------------------------------",cn);
1922 mod_gzip_printf( "%s: REQUEST RECORD SNAPSHOT",cn);
1923 mod_gzip_printf( "%s: -------------------------------------------------------------",cn);
1924 mod_gzip_printf( "%s: r = %ld", cn, (long) r );
1925 mod_gzip_printf( "%s: r->connection->keepalive=%d", cn, r->connection->keepalive );
1926 mod_gzip_printf( "%s: r->the_request=[%s]", cn, npp(r->the_request) );
1927 mod_gzip_printf( "%s: -------------------------------------------------------------",cn);
1928 mod_gzip_printf( "%s: r->next = %ld",cn,(long)r->next);
1929 mod_gzip_printf( "%s: r->prev = %ld",cn,(long)r->prev);
1930 mod_gzip_printf( "%s: r->main = %ld",cn,(long)r->main);
1931 mod_gzip_printf( "%s: -------------------------------------------------------------",cn);
1932 mod_gzip_printf( "%s: r->sent_bodyct = %ld",cn,(long)r->sent_bodyct);
1933 mod_gzip_printf( "%s: r->bytes_sent = %ld",cn,(long)r->bytes_sent);
1934 mod_gzip_printf( "%s: r->chunked = %ld",cn,(long)r->chunked);
1935 mod_gzip_printf( "%s: r->byterange = %ld",cn,(long)r->byterange);
1936 mod_gzip_printf( "%s: r->clength = %ld (The 'real' content length )",cn,(long)r->clength);
1937 mod_gzip_printf( "%s: r->byterange = %ld",cn,(long)r->remaining);
1938 mod_gzip_printf( "%s: r->read_length = %ld",cn,(long)r->read_length);
1939 mod_gzip_printf( "%s: r->read_body = %ld",cn,(long)r->read_body);
1940 mod_gzip_printf( "%s: r->read_chunked = %ld",cn,(long)r->read_chunked);
1941 mod_gzip_printf( "%s: -------------------------------------------------------------",cn);
1942 mod_gzip_printf( "%s: *IN: r->uri =[%s]", cn, npp(r->uri));
1943 mod_gzip_printf( "%s: *IN: r->unparsed_uri =[%s]", cn, npp(r->unparsed_uri));
1944 mod_gzip_printf( "%s: *IN: r->filename =[%s]", cn, npp(r->filename));
1945 mod_gzip_printf( "%s: *IN: r->path_info =[%s]", cn, npp(r->path_info));
1946 mod_gzip_printf( "%s: *IN: r->args =[%s]", cn, npp(r->args));
1947 mod_gzip_printf( "%s: *IN: r->header_only =%d", cn, r->header_only );
1948 mod_gzip_printf( "%s: *IN: r->protocol =[%s]", cn, npp(r->protocol));
1949 mod_gzip_printf( "%s: *IN: r->proto_num =%d", cn, r->proto_num );
1950 mod_gzip_printf( "%s: *IN: r->hostname =[%s]", cn, npp(r->hostname));
1951 mod_gzip_printf( "%s: *IN: r->the_request =[%s]", cn, npp(r->the_request));
1952 mod_gzip_printf( "%s: *IN: r->assbackwards =%d", cn, r->assbackwards );
1953 mod_gzip_printf( "%s: *IN: r->status_line =[%s]", cn, npp(r->status_line));
1954 mod_gzip_printf( "%s: *IN: r->status =%d", cn, r->status );
1955 mod_gzip_printf( "%s: *IN: r->method =[%s]", cn, npp(r->method));
1956 mod_gzip_printf( "%s: *IN: r->method_number =%d", cn, r->method_number );
1957 mod_gzip_printf( "%s: *IN: r->content_type =[%s]", cn, npp(r->content_type));
1958 mod_gzip_printf( "%s: *IN: r->handler =[%s]", cn, npp(r->handler));
1959 mod_gzip_printf( "%s: *IN: r->content_encoding =[%s]", cn, npp(r->content_encoding));
1960 mod_gzip_printf( "%s: *IN: r->content_language =[%s]", cn, npp(r->content_language));
1961 mod_gzip_printf( "%s: -------------------------------------------------------------",cn);
1962 mod_gzip_printf( "%s: *IN: r->parsed_uri.scheme =[%s]", cn, npp(r->parsed_uri.scheme));
1963 mod_gzip_printf( "%s: *IN: r->parsed_uri.hostinfo =[%s]", cn, npp(r->parsed_uri.hostinfo));
1964 mod_gzip_printf( "%s: *IN: r->parsed_uri.user =[%s]", cn, npp(r->parsed_uri.user));
1965 mod_gzip_printf( "%s: *IN: r->parsed_uri.password =[%s]", cn, npp(r->parsed_uri.password));
1966 mod_gzip_printf( "%s: *IN: r->parsed_uri.hostname =[%s]", cn, npp(r->parsed_uri.hostname));
1967 mod_gzip_printf( "%s: *IN: r->parsed_uri.port_str =[%s]", cn, npp(r->parsed_uri.port_str));
1968 mod_gzip_printf( "%s: *IN: r->parsed_uri.port =%u", cn, r->parsed_uri.port );
1969 mod_gzip_printf( "%s: *IN: r->parsed_uri.path =[%s]", cn, npp(r->parsed_uri.path));
1970 mod_gzip_printf( "%s: *IN: r->parsed_uri.query =[%s]", cn, npp(r->parsed_uri.query));
1971 mod_gzip_printf( "%s: *IN: r->parsed_uri.fragment =[%s]", cn, npp(r->parsed_uri.fragment));
1972 mod_gzip_printf( "%s: -------------------------------------------------------------",cn);
1973 mod_gzip_printf( "%s: 'r->headers_in'...",cn);
1974 mod_gzip_printf( "%s: -------------------------------------------------------------",cn);
1975 mod_gzip_dump_a_table( r, (_table *) r->headers_in );
1976 mod_gzip_printf( "%s: -------------------------------------------------------------",cn);
1977 mod_gzip_printf( "%s: 'r->headers_out'...",cn);
1978 mod_gzip_printf( "%s: -------------------------------------------------------------",cn);
1979 mod_gzip_dump_a_table( r, (_table *) r->headers_out );
1980 mod_gzip_printf( "%s: -------------------------------------------------------------",cn);
1981 mod_gzip_printf( "%s: 'r->err_headers_out'...",cn);
1982 mod_gzip_printf( "%s: -------------------------------------------------------------",cn);
1983 mod_gzip_dump_a_table( r, (_table *) r->err_headers_out );
1984 mod_gzip_printf( "%s: -------------------------------------------------------------",cn);
1985 mod_gzip_printf( "%s: 'r->subprocess_env'...",cn);
1986 mod_gzip_printf( "%s: -------------------------------------------------------------",cn);
1987 mod_gzip_dump_a_table( r, (_table *) r->subprocess_env );
1988 mod_gzip_printf( "%s: -------------------------------------------------------------",cn);
1989 mod_gzip_printf( "%s: 'r->notes'...",cn);
1990 mod_gzip_printf( "%s: -------------------------------------------------------------",cn);
1991 mod_gzip_dump_a_table( r, (_table *) r->notes );
1992 mod_gzip_printf( "%s: -------------------------------------------------------------",cn);
1996 mod_gzip_printf( "%s: r->next is valid... showing 'r->next' record...",cn);
1998 mod_gzip_show_request_record( r->next, cn );
2010 int mod_gzip_create_unique_filename(
2016 long process_id = 0;
2019 #ifdef MOD_GZIP_DEBUG1
2020 char cn[]="mod_gzip_create_unique_filename()";
2027 process_id = (long) GetCurrentProcessId();
2028 thread_id = (long) GetCurrentThreadId();
2031 process_id = (long) getpid();
2032 thread_id = (long) fake_tid;
2034 if ( fake_tid > 9999999 ) fake_tid = 99;
2037 #ifdef MOD_GZIP_DEBUG1
2038 mod_gzip_printf( "%s: Entry...",cn );
2039 mod_gzip_printf( "%s: prefix = [%s]",cn,npp(prefix));
2040 mod_gzip_printf( "%s: target = %ld", cn,(long)target);
2041 mod_gzip_printf( "%s: targetmaxlen = %ld", cn,(long)targetmaxlen);
2042 mod_gzip_printf( "%s: process_id = %ld", cn,(long)process_id );
2043 mod_gzip_printf( "%s: thread_id = %ld", cn,(long)thread_id );
2044 mod_gzip_printf( "%s: mod_gzip_iusn = %ld", cn,(long)mod_gzip_iusn );
2047 if ( ( !target ) || ( targetmaxlen == 0 ) )
2049 #ifdef MOD_GZIP_DEBUG1
2050 mod_gzip_printf( "%s: Invalid target or targetmaxlen value.",cn);
2051 mod_gzip_printf( "%s: Exit > return( 1 ) > ERROR >",cn );
2059 prefixlen = mod_gzip_strlen( prefix );
2062 if ( prefixlen > 0 )
2066 if ( ( *(prefix+(prefixlen-1)) != '\\' ) &&
2067 ( *(prefix+(prefixlen-1)) != '/' ) )
2079 "%s%s_%ld_%ld_%ld.wrk",
2084 (long) mod_gzip_iusn
2094 (long) mod_gzip_iusn
2100 if ( mod_gzip_iusn > 999999999L ) mod_gzip_iusn = 1;
2102 #ifdef MOD_GZIP_DEBUG1
2103 mod_gzip_printf( "%s: target = [%s]",cn,npp(target));
2104 mod_gzip_printf( "%s: Exit > return( 0 ) >",cn );
2110 int mod_gzip_type_checker( request_rec *r )
2115 int action_flag = 0;
2116 const char *tablekey = 0;
2117 const char *tablestring = 0;
2118 int accept_encoding_gzip_seen = 0;
2121 table_entry *elts = 0;
2123 mod_gzip_conf *dconf = 0;
2125 #ifdef MOD_GZIP_DEBUG1
2126 char cn[]="mod_gzip_type_checker()";
2127 mod_gzip_conf *sconf = 0;
2130 #ifdef MOD_GZIP_DEBUG1
2131 mod_gzip_printf( " " );
2132 mod_gzip_printf( "%s: ''''Entry...",cn);
2133 mod_gzip_printf( "%s: r = %ld", cn,(long)r);
2134 mod_gzip_printf( "%s: r->main = %ld", cn,(long)r->main);
2135 mod_gzip_printf( "%s: r->next = %ld", cn,(long)r->next);
2136 mod_gzip_printf( "%s: r->prev = %ld", cn,(long)r->prev);
2137 mod_gzip_printf( "%s: r->header_only = %ld", cn,(long)r->header_only );
2138 mod_gzip_printf( "%s: r->method_number = %ld", cn,(long)r->method_number );
2139 mod_gzip_printf( "%s: r->method = [%s]",cn,npp(r->method));
2140 mod_gzip_printf( "%s: r->unparsed_uri = [%s]",cn,npp(r->unparsed_uri));
2141 mod_gzip_printf( "%s: r->uri = [%s]",cn,npp(r->uri));
2142 mod_gzip_printf( "%s: r->filename = [%s]",cn,npp(r->filename));
2143 mod_gzip_printf( "%s: r->handler = [%s]",cn,npp(r->handler));
2144 mod_gzip_printf( "%s: r->content_type = [%s]",cn,npp(r->content_type));
2147 #ifdef MOD_GZIP_USES_APACHE_LOGS
2151 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:UNHANDLED_SUBREQ"));
2155 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:UNHANDLED_REDIR"));
2159 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:INIT1"));
2162 ap_table_setn( r->notes,"mod_gzip_input_size", ap_pstrdup(r->pool,"0"));
2163 ap_table_setn( r->notes,"mod_gzip_output_size",ap_pstrdup(r->pool,"0"));
2164 ap_table_setn( r->notes,"mod_gzip_compression_ratio",ap_pstrdup(r->pool,"0"));
2170 if ( mod_gzip_strendswith( r->filename, ".gz", 1 ) )
2172 #ifdef MOD_GZIP_USES_APACHE_LOGS
2175 /* This is a mod_gzip negotiated .gz static file transmit... */
2176 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:STATIC_GZ_FOUND"));
2180 /* This is a direct request from client for a .gz file... */
2181 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:FEXT_GZ"));
2185 #ifdef MOD_GZIP_DEBUG1
2186 mod_gzip_printf( "%s: r->filename ends with '.gz'...",cn);
2187 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
2192 #ifdef MOD_GZIP_DEBUG1
2195 #ifdef MOD_GZIP_DEBUG1
2196 mod_gzip_printf( "%s: r->filename does NOT end with '.gz'...",cn);
2197 mod_gzip_printf( "%s: OK to continue...",cn);
2203 dconf = ( mod_gzip_conf * )
2204 ap_get_module_config( r->per_dir_config, &gzip_module );
2206 #ifdef MOD_GZIP_DEBUG1
2208 sconf = ( mod_gzip_conf * )
2209 ap_get_module_config( r->server->module_config, &gzip_module );
2211 mod_gzip_printf( "%s: r->server->server_hostname = [%s]", cn,npp(r->server->server_hostname));
2212 mod_gzip_printf( "%s: sconf = %ld", cn,(long)sconf);
2213 mod_gzip_printf( "%s: sconf->loc = [%s]",cn,npp(sconf->loc));
2214 mod_gzip_printf( "%s: sconf->is_on = %ld", cn,(long)sconf->is_on);
2215 mod_gzip_printf( "%s: dconf = %ld", cn,(long)dconf);
2216 mod_gzip_printf( "%s: dconf->loc = [%s]",cn,npp(dconf->loc));
2217 mod_gzip_printf( "%s: dconf->is_on = %ld", cn,(long)dconf->is_on);
2223 #ifdef MOD_GZIP_USES_APACHE_LOGS
2224 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:NO_DCONF"));
2227 #ifdef MOD_GZIP_DEBUG1
2228 mod_gzip_printf( "%s: 'dconf' is NULL. Unable to continue.",cn);
2229 mod_gzip_printf( "%s: Exit > return( DECLINED ) >", cn);
2235 if ( !dconf->is_on )
2237 #ifdef MOD_GZIP_USES_APACHE_LOGS
2238 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:OFF"));
2241 #ifdef MOD_GZIP_DEBUG1
2242 mod_gzip_printf( "%s: 'dconf->is_on' is FALSE",cn);
2243 mod_gzip_printf( "%s: mod_gzip is not turned ON for this location...",cn);
2244 mod_gzip_printf( "%s: This transaction will be ignored...",cn);
2245 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
2251 if ( ( r->method_number != M_GET ) &&
2252 ( r->method_number != M_POST ) )
2254 #ifdef MOD_GZIP_USES_APACHE_LOGS
2255 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:NOT_GET_OR_POST"));
2258 #ifdef MOD_GZIP_DEBUG1
2259 mod_gzip_printf( "%s: r->method_number is NOT M_GET or M_POST",cn);
2260 mod_gzip_printf( "%s: Ignoring this request...",cn);
2261 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
2267 if ( r->header_only )
2269 #ifdef MOD_GZIP_USES_APACHE_LOGS
2270 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:HEAD_REQUEST"));
2273 #ifdef MOD_GZIP_DEBUG1
2274 mod_gzip_printf( "%s: r->header_only is TRUE...",cn);
2275 mod_gzip_printf( "%s: Ignoring this HEAD request...",cn);
2276 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
2282 if ( r->main ) /* SUBREQUEST */
2284 #ifdef MOD_GZIP_DEBUG1
2285 mod_gzip_printf( "%s: r->main is TRUE - This is a subrequest...",cn);
2286 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
2293 #ifdef MOD_GZIP_DEBUG1
2294 mod_gzip_printf( "%s: r->main is FALSE",cn);
2295 mod_gzip_printf( "%s: This is NOT a subrequest in progress...",cn);
2296 mod_gzip_printf( "%s: OK to continue...",cn);
2300 if ( r->prev ) /* REDIRECT */
2302 #ifdef MOD_GZIP_DEBUG1
2303 mod_gzip_printf( "%s: r->prev is NON-NULL... This is a redirection",cn);
2304 #ifdef MOD_GZIP_DEBUG1_SHOW_REQUEST_RECORD1
2305 mod_gzip_printf( "%s: Showing contents of r->prev now...",cn);
2306 mod_gzip_show_request_record( r->prev, cn );
2310 tablestring = ap_table_get(r->prev->notes, "mod_gzip_running");
2312 #ifdef MOD_GZIP_DEBUG1
2313 mod_gzip_printf( "%s: r->prev->notes->mod_gzip_running = [%s]",
2314 cn,npp(tablestring));
2319 #ifdef MOD_GZIP_DEBUG1
2320 mod_gzip_printf( "%s: 'mod_gzip_running' note FOUND",cn);
2323 if ( *tablestring == '1' )
2325 #ifdef MOD_GZIP_DEBUG1
2326 mod_gzip_printf( "%s: 'mod_gzip_running' note value is '1'...",cn);
2329 #ifdef MOD_GZIP_DEBUG1
2330 mod_gzip_printf( "%s: ************************************************",cn);
2331 mod_gzip_printf( "%s: mod_gzip is currently 'running' so we ",cn);
2332 mod_gzip_printf( "%s: must return DECLINED so that other type_checker",cn);
2333 mod_gzip_printf( "%s: hooks can fire...",cn);
2334 mod_gzip_printf( "%s: ************************************************",cn);
2335 mod_gzip_printf( "%s: IMPORTANT: We must now 'replicate' the note flag",cn);
2336 mod_gzip_printf( "%s: on this record or next time around r->prev",cn);
2337 mod_gzip_printf( "%s: note flag check will be FALSE.",cn);
2338 mod_gzip_printf( "%s: ************************************************",cn);
2341 ap_table_setn(r->notes,"mod_gzip_running",ap_pstrdup(r->pool,"1"));
2343 #ifdef MOD_GZIP_DEBUG1
2344 mod_gzip_printf( "%s: r->notes 'mod_gzip_running' set with value = '1'",cn);
2345 mod_gzip_printf( "%s: ************************************************",cn);
2346 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
2353 #ifdef MOD_GZIP_DEBUG1
2354 mod_gzip_printf( "%s: 'mod_gzip_running' note value is NOT '1'...",cn);
2360 #ifdef MOD_GZIP_DEBUG1
2361 mod_gzip_printf( "%s: 'mod_gzip_running' note NOT FOUND",cn);
2365 #ifdef MOD_GZIP_DEBUG1
2368 mod_gzip_printf( "%s: r->prev is NULL... This is NOT a redirection",cn);
2372 #ifdef MOD_GZIP_DEBUG1
2373 mod_gzip_printf( "%s: dconf->min_http = %ld", cn, (long) dconf->min_http );
2374 mod_gzip_printf( "%s: r->proto_num = %ld", cn, (long) r->proto_num );
2377 if ( ( dconf->min_http > 0 ) && ( r->proto_num > 0 ) )
2379 if ( r->proto_num < dconf->min_http )
2381 #ifdef MOD_GZIP_USES_APACHE_LOGS
2382 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:HTTP_LEVEL_TOO_LOW"));
2385 #ifdef MOD_GZIP_DEBUG1
2386 mod_gzip_printf( "%s: HTTP protocol version level is TOO LOW", cn);
2387 mod_gzip_printf( "%s: Exit > return( DECLINED ) >", cn);
2394 #ifdef MOD_GZIP_DEBUG1
2395 mod_gzip_printf( "%s: HTTP protocol version level is OK", cn);
2400 #ifdef MOD_GZIP_DEBUG1
2401 mod_gzip_printf( "%s: Checking for [Accept-Encoding: gzip]", cn );
2404 tablestring = ap_table_get(r->headers_in, "Accept-Encoding");
2406 #ifdef MOD_GZIP_DEBUG1
2407 mod_gzip_printf( "%s: r->headers_in->Accept-Encoding = [%s]",
2408 cn,npp(tablestring));
2413 #ifdef MOD_GZIP_DEBUG1
2414 mod_gzip_printf( "%s: 'Accept-Encoding' field seen...", cn);
2415 mod_gzip_printf( "%s: Checking for 'gzip' value...", cn);
2418 if ( mod_gzip_stringcontains( (char *)tablestring, "gzip" ) )
2420 #ifdef MOD_GZIP_DEBUG1
2421 mod_gzip_printf( "%s: 'gzip' value seen...", cn);
2424 accept_encoding_gzip_seen = 1;
2428 #ifdef MOD_GZIP_USES_APACHE_LOGS
2429 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:NO_GZIP"));
2432 #ifdef MOD_GZIP_DEBUG1
2433 mod_gzip_printf( "%s: 'gzip' value NOT seen...", cn);
2434 mod_gzip_printf( "%s: Exit > return( DECLINED ) >", cn);
2442 #ifdef MOD_GZIP_USES_APACHE_LOGS
2443 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:NO_ACCEPT_ENCODING"));
2446 #ifdef MOD_GZIP_DEBUG1
2447 mod_gzip_printf( "%s: 'Accept-Encoding' field NOT seen...", cn);
2448 mod_gzip_printf( "%s: Exit > return( DECLINED ) >", cn);
2454 #ifdef MOD_GZIP_DEBUG1
2455 mod_gzip_printf( "%s: accept_encoding_gzip_seen = %ld",
2456 cn, accept_encoding_gzip_seen );
2459 #ifdef MOD_GZIP_DEBUG1
2460 mod_gzip_printf( "%s: dconf->imap_total_entries = %d", cn,
2461 (int) dconf->imap_total_entries );
2464 if ( dconf->imap_total_entries < 1 )
2466 #ifdef MOD_GZIP_USES_APACHE_LOGS
2467 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:NO_ITEMS_DEFINED"));
2470 #ifdef MOD_GZIP_DEBUG1
2471 mod_gzip_printf( "%s: There are no IMAP entries. Unable to include/exclude",cn);
2472 mod_gzip_printf( "%s: Exit > return( DECLINED ) >", cn);
2478 #ifdef MOD_GZIP_DEBUG1
2479 mod_gzip_printf( "%s: dconf->imap_total_isreqheader = %d", cn,
2480 (int) dconf->imap_total_isreqheader );
2483 if ( dconf->imap_total_isreqheader > 0 )
2485 #ifdef MOD_GZIP_DEBUG1
2486 mod_gzip_printf( "%s: Checking inbound REQUEST header fields...", cn );
2489 t = (_table *) r->headers_in;
2490 elts = (table_entry *) t->a.elts;
2492 for ( i = 0; i < t->a.nelts; i++ )
2494 #ifdef MOD_GZIP_DEBUG1
2495 mod_gzip_printf( "%s: %3.3d key=[%s] val=[%s]",
2496 cn,i,npp(elts[i].key),npp(elts[i].val));
2499 tablekey = elts[i].key;
2500 tablestring = elts[i].val;
2502 if (( tablekey && tablestring ))
2504 #ifdef MOD_GZIP_DEBUG1
2505 mod_gzip_printf( "%s: Checking key[%s] string[%s]",
2506 cn,npp(tablekey),npp(tablestring));
2507 mod_gzip_printf( "%s: Call mod_gzip_validate1()...",cn);
2513 (mod_gzip_conf *) dconf,
2514 NULL, /* r->filename (Not used here) */
2515 NULL, /* r->uri (Not used here) */
2516 NULL, /* r->content_type (Not used here) */
2517 NULL, /* r->handler (Not used here) */
2518 (char *) tablekey, /* (Field key ) */
2519 (char *) tablestring, /* (Field string ) */
2520 MOD_GZIP_REQUEST /* (Direction ) */
2523 #ifdef MOD_GZIP_DEBUG1
2524 mod_gzip_printf( "%s: Back mod_gzip_validate1()...",cn);
2525 mod_gzip_printf( "%s: field_ok = %d",cn,field_ok);
2528 if ( field_ok == MOD_GZIP_IMAP_DECLINED1 )
2530 #ifdef MOD_GZIP_USES_APACHE_LOGS
2531 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:REQ_HEADER_FIELD_EXCLUDED"));
2534 #ifdef MOD_GZIP_DEBUG1
2535 mod_gzip_printf( "%s: This request is EXCLUDED...",cn);
2536 mod_gzip_printf( "%s: Exit > return( DECLINED ) >", cn);
2544 #ifdef MOD_GZIP_DEBUG1
2547 #ifdef MOD_GZIP_DEBUG1
2548 mod_gzip_printf( "%s: NO CHECK required on inbound REQUEST header fields...", cn );
2553 #ifdef MOD_GZIP_DEBUG1
2554 mod_gzip_printf( "%s: 1 ***: r->uri =[%s]", cn, npp(r->uri ));
2555 mod_gzip_printf( "%s: 1 ***: r->unparsed_uri=[%s]", cn, npp(r->unparsed_uri ));
2556 mod_gzip_printf( "%s: 1 ***: r->filename =[%s]", cn, npp(r->filename ));
2557 mod_gzip_printf( "%s: 1 ***: r->content_type=[%s]", cn, npp(r->content_type ));
2558 mod_gzip_printf( "%s: 1 ***: r->handler =[%s]", cn, npp(r->handler ));
2561 if ( !r->content_type )
2563 #ifdef MOD_GZIP_DEBUG1
2564 mod_gzip_printf( "%s: 'r->content_type' is NULL...",cn);
2565 mod_gzip_printf( "%s: Performing 'quick lookup'...",cn);
2566 mod_gzip_printf( "%s: Call mod_gzip_run_handlers(r,RUN_TYPE_CHECKERS)...",cn);
2569 rc = mod_gzip_run_handlers( r, MOD_GZIP_RUN_TYPE_CHECKERS );
2571 #ifdef MOD_GZIP_DEBUG1
2573 mod_gzip_printf( "%s: Back mod_gzip_run_handlers(r,RUN_TYPE_CHECKERS)...",cn);
2577 mod_gzip_printf( "%s: rc = %d = OK",cn, rc );
2579 else if ( rc == DECLINED )
2581 mod_gzip_printf( "%s: rc = %d = DECLINED",cn, rc );
2583 else if ( rc == DONE )
2585 mod_gzip_printf( "%s: rc = %d = DONE",cn, rc );
2589 mod_gzip_printf( "%s: rc = %d = HTTP_ERROR?",cn, rc );
2594 #ifdef MOD_GZIP_DEBUG1
2597 mod_gzip_printf( "%s: 'r->content_type' is VALID already...",cn);
2598 mod_gzip_printf( "%s: No 'quick lookup' was performed...",cn);
2602 #ifdef MOD_GZIP_DEBUG1
2603 mod_gzip_printf( "%s: 2 ***: r->uri =[%s]", cn, npp(r->uri ));
2604 mod_gzip_printf( "%s: 2 ***: r->unparsed_uri=[%s]", cn, npp(r->unparsed_uri ));
2605 mod_gzip_printf( "%s: 2 ***: r->filename =[%s]", cn, npp(r->filename ));
2606 mod_gzip_printf( "%s: 2 ***: r->content_type=[%s]", cn, npp(r->content_type ));
2607 mod_gzip_printf( "%s: 2 ***: r->handler =[%s]", cn, npp(r->handler ));
2608 mod_gzip_printf( "%s: Call mod_gzip_validate1()...",cn);
2614 (mod_gzip_conf *) dconf,
2615 (char *) r->filename,
2617 (char *) r->content_type,
2618 (char *) r->handler,
2619 NULL, /* Field key (Not used here) */
2620 NULL, /* Field string (Not used here) */
2621 0 /* Direction (Not used here) */
2624 #ifdef MOD_GZIP_DEBUG1
2626 mod_gzip_printf( "%s: Back mod_gzip_validate1()...",cn);
2627 mod_gzip_printf( "%s: action_flag = %d",cn,action_flag);
2629 if ( action_flag == MOD_GZIP_IMAP_DYNAMIC1 )
2631 mod_gzip_printf( "%s: action_flag = MOD_GZIP_IMAP_DYNAMIC1",cn);
2633 else if ( action_flag == MOD_GZIP_IMAP_DYNAMIC2 )
2635 mod_gzip_printf( "%s: action_flag = MOD_GZIP_IMAP_DYNAMIC2",cn);
2637 else if ( action_flag == MOD_GZIP_IMAP_STATIC1 )
2639 mod_gzip_printf( "%s: action_flag = MOD_GZIP_IMAP_STATIC1",cn);
2641 else if ( action_flag == MOD_GZIP_IMAP_DECLINED1 )
2643 mod_gzip_printf( "%s: action_flag = MOD_GZIP_IMAP_DECLINED1",cn);
2647 mod_gzip_printf( "%s: action_flag = MOD_GZIP_IMAP_??? Unknown action",cn);
2652 if ( action_flag != MOD_GZIP_IMAP_DECLINED1 )
2654 #ifdef MOD_GZIP_DEBUG1
2655 mod_gzip_printf( "%s: This transaction is a valid candidate...",cn);
2656 mod_gzip_printf( "%s: Saving current r->handler value [%s] to mod_gzip_r_handler note...",
2657 cn, npp(r->handler) );
2662 ap_table_setn( r->notes,"mod_gzip_r_handler",ap_pstrdup(r->pool,r->handler));
2666 ap_table_setn( r->notes,"mod_gzip_r_handler",ap_pstrdup(r->pool,"0"));
2669 #ifdef MOD_GZIP_DEBUG1
2670 mod_gzip_printf( "%s: Forcing r->handler to be 'mod_gzip_handler'...", cn );
2673 r->handler = "mod_gzip_handler";
2675 #ifdef MOD_GZIP_DEBUG1
2676 mod_gzip_printf( "%s: r->handler is now = [%s]", cn, npp(r->handler) );
2677 mod_gzip_printf( "%s: Exit > return( OK ) >", cn );
2678 mod_gzip_printf( " " );
2685 #ifdef MOD_GZIP_DEBUG1
2686 mod_gzip_printf( "%s: This transaction is NOT a valid candidate...",cn);
2689 #ifdef MOD_GZIP_USES_APACHE_LOGS
2690 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:EXCLUDED"));
2693 #ifdef MOD_GZIP_DEBUG1
2694 mod_gzip_printf( "%s: Exit > return( DECLINED ) >", cn );
2695 mod_gzip_printf( " " );
2702 #ifdef MOD_GZIP_COMMAND_VERSION_USED
2704 int mod_gzip_do_command(
2705 int this_command, /* MOD_GZIP_COMMAND_XXXX */
2706 request_rec *r, /* Request record */
2707 mod_gzip_conf *dconf /* Directory config pointer */
2710 /* Generic command response transmitter... */
2712 char tmpbuf[2048]; /* Fill/flush as needed. Don't overflow */
2717 #ifdef USE_MOD_GZIP_DEBUG1
2718 char cn[]="mod_gzip.c: mod_gzip_send_html_command_response()";
2723 if ( this_command == MOD_GZIP_COMMAND_VERSION )
2725 mod_gzip_strcpy(s1,"No");
2729 if ( dconf->is_on == 1 ) mod_gzip_strcpy(s1,"Yes");
2734 "mod_gzip is available...<br>\r\n"
2735 "mod_gzip_version = %s<br>\r\n"
2736 "mod_gzip_on = %s<br>\r\n"
2742 #ifdef MOD_GZIP_USES_APACHE_LOGS
2743 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"COMMAND:VERSION"));
2748 #ifdef MOD_GZIP_USES_APACHE_LOGS
2749 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:INVALID_COMMAND"));
2755 /* Add the length of the response to the output header... */
2756 /* The third parameter to ap_table_set() MUST be a string. */
2758 tmplen = strlen( tmp );
2760 sprintf( s1, "%d", tmplen );
2762 ap_table_set( r->headers_out, "Content-Length", s1 );
2764 /* Make sure the content type matches this response... */
2766 r->content_type = "text/html";
2768 /* Start a timer for this return trip... */
2770 ap_soft_timeout( "mod_gzip: mod_gzip_do_command", r );
2772 #ifdef MOD_GZIP_COMMANDS_USE_LAST_MODIFIED
2774 /* Set the 'Last modified' stamp to current time/date... */
2776 ap_set_last_modified(r);
2778 /* TODO? Add 'no-cache' option(s) to mod_gzip command responses */
2779 /* so user doesn't have hit reload to get fresh data? This might */
2780 /* be necessary for static files that are subject to an Apache */
2781 /* lookup but mod_gzip command results as sent 'fresh' each */
2782 /* time no matter what so there doesn't seem to be a need for */
2783 /* any 'Last modified' information. Just pump a 200 + data and */
2784 /* then turn and burn... */
2786 #endif /* MOD_GZIP_COMMANDS_USE_LAST_MODIFIED */
2788 /* Send the HTTP response header... */
2790 ap_send_http_header(r);
2792 /* Send the response BODY... */
2794 ap_send_mmap( tmp, r, 0, tmplen );
2796 /* Clean up and exit... */
2802 }/* End of mod_gzip_send_html_command_response() */
2804 #endif /* MOD_GZIP_COMMAND_VERSION_USED */
2807 static int mod_gzip_handler( request_rec *r )
2809 #ifdef MOD_GZIP_DEBUG1
2810 char cn[]="mod_gzip_handler()";
2814 int action_flag = 0;
2816 request_rec *r__next=0;
2818 mod_gzip_conf *sconf = 0;
2819 mod_gzip_conf *dconf = 0;
2821 const char *tablestring;
2828 #ifdef MOD_GZIP_CAN_NEGOTIATE
2829 struct stat statbuf;
2834 #ifdef MOD_GZIP_DEBUG1
2836 mod_gzip_server_now = r->server;
2838 mod_gzip_printf( " " );
2840 mod_gzip_printf( "%s: ''''Entry...",cn);
2841 mod_gzip_printf( "%s: r = %ld", cn,(long)r);
2842 mod_gzip_printf( "%s: r->main = %ld", cn,(long)r->main);
2843 mod_gzip_printf( "%s: r->next = %ld", cn,(long)r->next);
2844 mod_gzip_printf( "%s: r->prev = %ld", cn,(long)r->prev);
2845 mod_gzip_printf( "%s: r->unparsed_uri = [%s]",cn,npp(r->unparsed_uri));
2846 mod_gzip_printf( "%s: r->uri = [%s]",cn,npp(r->uri));
2847 mod_gzip_printf( "%s: r->filename = [%s]",cn,npp(r->filename));
2848 mod_gzip_printf( "%s: r->handler = [%s]",cn,npp(r->handler));
2852 if ( r->main ) /* SUBREQUEST */
2854 #ifdef MOD_GZIP_DEBUG1
2855 mod_gzip_printf( "%s: r->main is TRUE - This is a subrequest...",cn);
2856 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
2861 #ifdef MOD_GZIP_DEBUG1
2864 mod_gzip_printf( "%s: r->main is FALSE",cn);
2865 mod_gzip_printf( "%s: This is NOT a subrequest in progress...",cn);
2866 mod_gzip_printf( "%s: OK to continue...",cn);
2872 if ( mod_gzip_strendswith( r->filename, ".gz", 1 ) )
2874 #ifdef MOD_GZIP_USES_APACHE_LOGS
2877 /* This is a mod_gzip negotiated .gz static file transmit... */
2878 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:STATIC_GZ_FOUND"));
2882 /* This is a direct request from client for a .gz file... */
2883 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:FEXT_GZ"));
2887 #ifdef MOD_GZIP_DEBUG1
2888 mod_gzip_printf( "%s: r->filename ends with '.gz'...",cn);
2889 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
2894 #ifdef MOD_GZIP_DEBUG1
2897 #ifdef MOD_GZIP_DEBUG1
2898 mod_gzip_printf( "%s: r->filename does NOT end with '.gz'...",cn);
2899 mod_gzip_printf( "%s: OK to continue...",cn);
2905 if ( r->prev ) /* REDIRECT */
2907 #ifdef MOD_GZIP_DEBUG1
2908 mod_gzip_printf( "%s: r->prev is TRUE - This is a redirection...",cn);
2911 /* This might be a 'directory' index lookup... */
2913 tablestring = ap_table_get(r->prev->notes, "mod_gzip_running");
2915 #ifdef MOD_GZIP_DEBUG1
2916 mod_gzip_printf( "%s: r->prev->notes->mod_gzip_running = [%s]",
2917 cn,npp(tablestring));
2922 #ifdef MOD_GZIP_DEBUG1
2923 mod_gzip_printf( "%s: 'mod_gzip_running' note FOUND",cn);
2926 if ( *tablestring == '1' )
2928 #ifdef MOD_GZIP_DEBUG1
2929 mod_gzip_printf( "%s: 'mod_gzip_running' note value is '1'...",cn);
2932 #ifdef MOD_GZIP_DEBUG1
2933 mod_gzip_printf( "%s: ************************************************",cn);
2934 mod_gzip_printf( "%s: mod_gzip is currently 'running' so we ",cn);
2935 mod_gzip_printf( "%s: must return DECLINED.",cn);
2936 mod_gzip_printf( "%s: ************************************************",cn);
2937 mod_gzip_printf( "%s: IMPORTANT: We must now 'replicate' the note flag",cn);
2938 mod_gzip_printf( "%s: on this record or next time around r->prev",cn);
2939 mod_gzip_printf( "%s: note flag check will be FALSE.",cn);
2940 mod_gzip_printf( "%s: ************************************************",cn);
2943 ap_table_setn(r->notes,"mod_gzip_running",ap_pstrdup(r->pool,"1"));
2945 #ifdef MOD_GZIP_DEBUG1
2946 mod_gzip_printf( "%s: r->notes 'mod_gzip_running' set with value = '1'",cn);
2947 mod_gzip_printf( "%s: ************************************************",cn);
2950 #ifdef MOD_GZIP_DEBUG1
2951 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
2956 #ifdef MOD_GZIP_DEBUG1
2959 mod_gzip_printf( "%s: 'mod_gzip_running' note value is NOT '1'...",cn);
2963 #ifdef MOD_GZIP_DEBUG1
2966 mod_gzip_printf( "%s: 'mod_gzip_running' note NOT FOUND",cn);
2970 #ifdef MOD_GZIP_DEBUG1
2973 mod_gzip_printf( "%s: r->prev is FALSE",cn);
2974 mod_gzip_printf( "%s: This is NOT a redirection in progress...",cn);
2975 mod_gzip_printf( "%s: OK to continue...",cn);
2979 sconf = ( mod_gzip_conf * )
2980 ap_get_module_config( r->server->module_config, &gzip_module );
2982 dconf = ( mod_gzip_conf * )
2983 ap_get_module_config( r->per_dir_config, &gzip_module );
2985 #ifdef MOD_GZIP_DEBUG1
2986 mod_gzip_printf( "%s: r->server->server_hostname = [%s]", cn,npp(r->server->server_hostname));
2987 mod_gzip_printf( "%s: sconf = %ld", cn,(long)sconf);
2988 mod_gzip_printf( "%s: sconf->loc = [%s]",cn,npp(sconf->loc));
2989 mod_gzip_printf( "%s: sconf->is_on = %ld", cn,(long)sconf->is_on);
2990 mod_gzip_printf( "%s: dconf = %ld", cn,(long)dconf);
2991 mod_gzip_printf( "%s: dconf->loc = [%s]",cn,npp(dconf->loc));
2992 mod_gzip_printf( "%s: dconf->is_on = %ld", cn,(long)dconf->is_on);
2995 #ifdef MOD_GZIP_COMMAND_VERSION_USED
2997 /* NOTE: Certain mod_gzip 'commands' should return a response */
2998 /* even if mod_gzip is OFF in the current location. Make sure */
2999 /* the checks for these commands take place BEFORE checking */
3000 /* the actual mod_gzip on/off status... */
3002 #ifdef MOD_GZIP_DEBUG1
3003 mod_gzip_printf( "%s: dconf->command_version = [%s]",cn,npp(dconf->command_version));
3006 /* Check for mod_gzip commands in the 'r->unparsed_uri' request */
3007 /* line so the commands can actually be part of query parms that */
3008 /* follow the '?'. 'r->uri' is simply he URI itself with any/all */
3009 /* additional query arguments removed already... */
3011 if ( dconf->command_version[0] != 0 )
3013 if ( mod_gzip_stringcontains(r->unparsed_uri,dconf->command_version))
3015 #ifdef MOD_GZIP_DEBUG1
3016 mod_gzip_printf( "%s: Call mod_gzip_do_command( MOD_GZIP_COMMAND_VERSION, r )...",cn);
3019 /* mod_gzip_do_command() returns the correct command */
3020 /* response page and (normally) just returns 'OK'... */
3023 mod_gzip_do_command(
3024 MOD_GZIP_COMMAND_VERSION,
3031 #endif /* MOD_GZIP_COMMAND_VERSION_USED */
3033 tablestring = ap_table_get(r->notes, "mod_gzip_r_handler");
3037 #ifdef MOD_GZIP_DEBUG1
3038 mod_gzip_printf( "%s: r->notes->mod_gzip_r_handler = NOT FOUND",cn);
3039 mod_gzip_printf( "%s: This transaction will be ignored...",cn);
3040 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
3046 #ifdef MOD_GZIP_DEBUG1
3047 mod_gzip_printf( "%s: r->notes->mod_gzip_r_handler = FOUND",cn);
3048 mod_gzip_printf( "%s: r->notes->mod_gzip_r_handler = [%s]",cn,npp(tablestring));
3051 #ifdef MOD_GZIP_USES_APACHE_LOGS
3052 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"INIT2"));
3055 if ( !dconf->is_on )
3057 #ifdef MOD_GZIP_USES_APACHE_LOGS
3058 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:OFF2"));
3061 #ifdef MOD_GZIP_DEBUG1
3062 mod_gzip_printf( "%s: 'dconf->is_on' is FALSE",cn);
3063 mod_gzip_printf( "%s: mod_gzip is not turned ON for this location...",cn);
3064 mod_gzip_printf( "%s: This transaction will be ignored...",cn);
3065 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
3071 if ( *tablestring == '0' )
3077 r->handler = tablestring;
3080 #ifdef MOD_GZIP_DEBUG1
3081 mod_gzip_printf( "%s: r->handler set back to = [%s]",cn,npp(r->handler));
3084 /* Verify it (again) in case names have changed... */
3086 #ifdef MOD_GZIP_DEBUG1
3087 mod_gzip_printf( "%s: Call mod_gzip_validate1()...",cn);
3093 (mod_gzip_conf *) dconf,
3094 (char *) r->filename,
3096 (char *) r->content_type,
3097 (char *) r->handler,
3098 NULL, /* Field key (Not used here */
3099 NULL, /* Field string (Not used here) */
3100 0 /* Direction (Not used here) */
3103 #ifdef MOD_GZIP_DEBUG1
3105 mod_gzip_printf( "%s: Back mod_gzip_validate1()...",cn);
3106 mod_gzip_printf( "%s: action_flag = %d",cn,action_flag);
3108 if ( action_flag == MOD_GZIP_IMAP_DYNAMIC1 )
3110 mod_gzip_printf( "%s: action_flag = MOD_GZIP_IMAP_DYNAMIC1",cn);
3112 else if ( action_flag == MOD_GZIP_IMAP_DYNAMIC2 )
3114 mod_gzip_printf( "%s: action_flag = MOD_GZIP_IMAP_DYNAMIC2",cn);
3116 else if ( action_flag == MOD_GZIP_IMAP_STATIC1 )
3118 mod_gzip_printf( "%s: action_flag = MOD_GZIP_IMAP_STATIC1",cn);
3120 else if ( action_flag == MOD_GZIP_IMAP_DECLINED1 )
3122 mod_gzip_printf( "%s: action_flag = MOD_GZIP_IMAP_DECLINED1",cn);
3126 mod_gzip_printf( "%s: action_flag = MOD_GZIP_IMAP_??? Unknown action",cn);
3131 if ( action_flag == MOD_GZIP_IMAP_DECLINED1 )
3133 #ifdef MOD_GZIP_DEBUG1
3134 mod_gzip_printf( "%s: This transaction is NOT a valid candidate...",cn);
3135 mod_gzip_printf( "%s: This transaction will be ignored...",cn);
3138 #ifdef MOD_GZIP_USES_APACHE_LOGS
3139 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:EXCLUDED_BY_HANDLER"));
3142 #ifdef MOD_GZIP_DEBUG1
3143 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
3149 #ifdef MOD_GZIP_DEBUG1
3150 mod_gzip_printf( "%s: This transaction is a valid candidate...",cn);
3153 #ifdef MOD_GZIP_CAN_NEGOTIATE
3155 #ifdef MOD_GZIP_DEBUG1
3156 mod_gzip_printf( "%s: dconf->can_negotiate = %d",cn,(int)dconf->can_negotiate);
3159 if ( dconf->can_negotiate == 1 )
3161 #ifdef MOD_GZIP_DEBUG1
3162 mod_gzip_printf( "%s: dconf->can_negotiate is TRUE...",cn);
3165 /* Check for a static compressed version of the file requested... */
3167 new_name = ap_pstrcat(r->pool, r->filename, ".gz", NULL);
3169 #ifdef MOD_GZIP_DEBUG1
3170 mod_gzip_printf( "%s: Call stat(new_name=[%s])...",cn,npp(new_name));
3173 if ( stat( new_name, &statbuf) != 0 )
3175 #ifdef MOD_GZIP_DEBUG1
3176 mod_gzip_printf( "%s: .... stat() call FAILED",cn);
3177 mod_gzip_printf( "%s: OK to continue...",cn);
3182 #ifdef MOD_GZIP_DEBUG1
3183 mod_gzip_printf( "%s: .... stat() call SUCCEEDED",cn);
3184 mod_gzip_printf( "%s: Sending precompressed version of file...",cn);
3185 mod_gzip_printf( "%s: GZ_REDIRECT: START...",cn);
3188 new_name = ap_pstrcat(r->pool, r->uri, ".gz", NULL);
3190 if ( r->args != NULL )
3192 new_uri = ap_pstrcat(r->pool, new_name, "?", r->args, NULL);
3196 new_uri = ap_pstrcat(r->pool, new_name, NULL );
3199 #ifdef MOD_GZIP_DEBUG1
3200 mod_gzip_printf( "%s: Call ap_internal_redirect(new_uri=[%s])...",
3202 mod_gzip_printf( " " );
3205 ap_internal_redirect( new_uri, r );
3207 #ifdef MOD_GZIP_DEBUG1
3208 mod_gzip_printf( " " );
3209 mod_gzip_printf( "%s: Back ap_internal_redirect(new_uri=[%s])...",
3211 mod_gzip_printf( "%s: GZ_REDIRECT: FINISHED...",cn);
3214 #ifdef MOD_GZIP_DEBUG1
3215 mod_gzip_printf( "%s: Exit > return( OK ) >",cn);
3218 /* We are about to return OK to end the transaction but go */
3219 /* ahead and make the mod_gzip final result a DECLINED */
3220 /* condition since that's what actually happened... */
3222 #ifdef MOD_GZIP_USES_APACHE_LOGS
3223 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:STATIC_GZ_FOUND"));
3229 #ifdef MOD_GZIP_DEBUG1
3232 mod_gzip_printf( "%s: dconf->can_negotiate is FALSE",cn);
3236 #endif /* MOD_GZIP_CAN_NEGOTIATE */
3238 #ifdef MOD_GZIP_DEBUG1
3239 mod_gzip_printf( "%s: Call mod_gzip_redir1_handler( r, dconf )...",cn);
3242 rc = (int) mod_gzip_redir1_handler( r, dconf );
3244 #ifdef MOD_GZIP_DEBUG1
3246 mod_gzip_printf( "%s: Back mod_gzip_redir1_handler( r, dconf )...",cn);
3250 mod_gzip_printf( "%s: rc = %d OK", cn, (int) rc);
3252 else if ( rc == DECLINED )
3254 mod_gzip_printf( "%s: rc = %d DECLINED", cn, (int) rc );
3258 mod_gzip_printf( "%s: rc = %d ( HTTP ERROR CODE? )", cn, (int) rc );
3265 #ifdef MOD_GZIP_DEBUG1
3266 mod_gzip_printf( "%s: mod_gzip_redir1_handler() call FAILED...",cn);
3269 #ifdef MOD_GZIP_USES_APACHE_LOGS
3272 r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"RECOVERY"));
3275 ap_log_error( APLOG_MARK,APLOG_NOERRNO|APLOG_WARNING, r->server,
3276 "mod_gzip: RECOVERY [%s]", r->the_request );
3278 #ifdef MOD_GZIP_DEBUG1
3279 mod_gzip_printf( "%s: RECOVERY_REDIRECT: START...",cn);
3280 mod_gzip_printf( "%s: Call ap_internal_redirect(r->unparsed_uri=[%s])...",
3281 cn,npp(r->unparsed_uri));
3282 mod_gzip_printf( " " );
3285 ap_internal_redirect( r->unparsed_uri, r );
3287 #ifdef MOD_GZIP_DEBUG1
3288 mod_gzip_printf( " " );
3289 mod_gzip_printf( "%s: Back ap_internal_redirect(r->unparsed_uri=[%s])...",
3290 cn,npp(r->unparsed_uri));
3291 mod_gzip_printf( "%s: RECOVERY_REDIRECT: FINISHED...",cn);
3297 #ifdef MOD_GZIP_USES_APACHE_LOGS
3303 s1 = ap_table_get( r->notes, "mod_gzip_result" );
3304 s2 = ap_table_get( r->notes, "mod_gzip_input_size" );
3305 s3 = ap_table_get( r->notes, "mod_gzip_output_size" );
3306 s4 = ap_table_get( r->notes, "mod_gzip_compression_ratio" );
3310 if ( s1 ) ap_table_setn( r__next->notes,"mod_gzip_result",ap_pstrdup(r__next->pool,s1));
3311 if ( s2 ) ap_table_setn( r__next->notes,"mod_gzip_input_size",ap_pstrdup(r__next->pool,s2));
3312 if ( s3 ) ap_table_setn( r__next->notes,"mod_gzip_output_size",ap_pstrdup(r__next->pool,s3));
3313 if ( s4 ) ap_table_setn( r__next->notes,"mod_gzip_compression_ratio",ap_pstrdup(r__next->pool,s4));
3315 r__next = r__next->next;
3321 #ifdef MOD_GZIP_DEBUG1
3322 #ifdef MOD_GZIP_DEBUG1_SHOW_REQUEST_RECORD2
3323 mod_gzip_show_request_record( r, cn );
3327 #ifdef MOD_GZIP_DEBUG1
3329 mod_gzip_printf( "%s: 1 r->connection->client->outcnt = %ld",
3330 cn, r->connection->client->outcnt );
3331 mod_gzip_printf( "%s: 1 r->connection->client->bytes_sent = %ld",
3332 cn, r->connection->client->bytes_sent );
3333 mod_gzip_printf( "%s: 1 Sum of the 2......................= %ld",
3334 cn, r->connection->client->outcnt +
3335 r->connection->client->bytes_sent );
3338 mod_gzip_printf( "%s: Exit > return ( rc = %d OK ) >",cn,(int)rc);
3340 else if ( rc == DECLINED )
3342 mod_gzip_printf( "%s: Exit > return ( rc = %d DECLINED ) >",cn,(int)rc);
3346 mod_gzip_printf( "%s: Exit > return ( rc = %d HTTP_ERROR ) >",cn,(int)rc);
3354 int mod_gzip_set_defaults1( mod_gzip_conf *cfg )
3361 cfg->keep_workfiles = 0;
3362 cfg->keep_workfiles_set = 0;
3364 cfg->add_header_count = 0;
3365 cfg->add_header_count_set = 0;
3368 cfg->dechunk_set = 0;
3371 cfg->min_http_set = 0;
3373 cfg->minimum_file_size = 300;
3374 cfg->minimum_file_size_set = 0;
3376 cfg->maximum_file_size = 0;
3377 cfg->maximum_file_size_set = 0;
3379 cfg->maximum_inmem_size = 0;
3380 cfg->maximum_inmem_size_set = 0;
3383 mod_gzip_strcpy( cfg->temp_dir, "c:\\temp\\" );
3385 mod_gzip_strcpy( cfg->temp_dir, "/tmp/" );
3387 cfg->temp_dir_set = 0;
3389 cfg->imap_total_entries = 0;
3390 cfg->imap_total_ismime = 0;
3391 cfg->imap_total_isfile = 0;
3392 cfg->imap_total_isuri = 0;
3393 cfg->imap_total_ishandler = 0;
3394 cfg->imap_total_isreqheader = 0;
3395 cfg->imap_total_isrspheader = 0;
3397 for ( i=0; i<MOD_GZIP_IMAP_MAXNAMES; i++ )
3399 memset( &(cfg->imap[i]), 0, mod_gzip_imap_size );
3402 #ifdef MOD_GZIP_COMMAND_VERSION_USED
3404 cfg->command_version, 0, MOD_GZIP_COMMAND_VERSION_MAXLEN );
3405 cfg->command_version_set = 0;
3408 #ifdef MOD_GZIP_CAN_NEGOTIATE
3409 cfg->can_negotiate = 0;
3410 cfg->can_negotiate_set = 0;
3417 static void *mod_gzip_merge_dconfig(
3423 mod_gzip_conf *merged_config = (mod_gzip_conf *) ap_pcalloc(p, sizeof(mod_gzip_conf));
3424 mod_gzip_conf *pconf = (mod_gzip_conf *) parent_conf;
3425 mod_gzip_conf *nconf = (mod_gzip_conf *) newloc_conf;
3429 ( mod_gzip_conf * ) merged_config,
3430 ( mod_gzip_conf * ) pconf,
3431 ( mod_gzip_conf * ) nconf
3434 return (void *) merged_config;
3438 int mod_gzip_merge1(
3440 mod_gzip_conf *merged_config,
3441 mod_gzip_conf *pconf,
3442 mod_gzip_conf *nconf )
3444 #ifdef MOD_GZIP_DEBUG1
3445 char cn[]="mod_gzip_merge1():::::::";
3458 int total_ismime = 0;
3459 int total_isfile = 0;
3460 int total_isuri = 0;
3461 int total_ishandler = 0;
3462 int total_isreqheader = 0;
3463 int total_isrspheader = 0;
3465 #ifdef MOD_GZIP_DEBUG1
3466 mod_gzip_printf( "%s: ",cn);
3469 #ifdef MOD_GZIP_DEBUG1
3471 if ( nconf->is_on_set )
3473 merged_config->is_on = nconf->is_on;
3479 merged_config->is_on = pconf->is_on;
3484 mod_gzip_printf( "%s: pconf %c= nconf : merged_config->is_on = %ld", cn, ch1, (long) merged_config->is_on );
3488 merged_config->is_on =
3489 ( nconf->is_on_set) ? nconf->is_on : pconf->is_on;
3493 #ifdef MOD_GZIP_DEBUG1
3495 if ( pconf->cmode == nconf->cmode )
3497 merged_config->cmode = pconf->cmode;
3503 merged_config->cmode = MOD_GZIP_CONFIG_MODE_COMBO;
3508 mod_gzip_printf( "%s: pconf %c= nconf : merged_config->cmode = %ld", cn, ch1, (long) merged_config->cmode );
3512 merged_config->cmode =
3513 (pconf->cmode == nconf->cmode) ? pconf->cmode : MOD_GZIP_CONFIG_MODE_COMBO;
3517 merged_config->loc = ap_pstrdup( p, nconf->loc );
3519 #ifdef MOD_GZIP_DEBUG1
3520 mod_gzip_printf( "%s: .............. : merged_config->loc = [%s]", cn, npp(merged_config->loc));
3523 #ifdef MOD_GZIP_DEBUG1
3524 if ( !nconf->add_header_count_set )
3525 { merged_config->add_header_count = pconf->add_header_count; ch1='='; }
3526 else { merged_config->add_header_count = nconf->add_header_count; ch1='!'; }
3527 mod_gzip_printf( "%s: pconf %c= nconf : merged_config->add_header_count = %ld", cn, ch1, (long) merged_config->add_header_count );
3529 merged_config->add_header_count = ( !nconf->add_header_count_set ) ? pconf->add_header_count : nconf->add_header_count;
3532 #ifdef MOD_GZIP_DEBUG1
3533 if ( !nconf->keep_workfiles_set )
3534 { merged_config->keep_workfiles = pconf->keep_workfiles; ch1='='; }
3535 else { merged_config->keep_workfiles = nconf->keep_workfiles; ch1='!'; }
3536 mod_gzip_printf( "%s: pconf %c= nconf : merged_config->keep_workfiles = %ld", cn, ch1, (long) merged_config->keep_workfiles );
3538 merged_config->keep_workfiles = ( !nconf->keep_workfiles_set ) ? pconf->keep_workfiles : nconf->keep_workfiles;
3541 #ifdef MOD_GZIP_CAN_NEGOTIATE
3542 #ifdef MOD_GZIP_DEBUG1
3543 if ( !nconf->can_negotiate_set )
3544 { merged_config->can_negotiate = pconf->can_negotiate; ch1='='; }
3545 else { merged_config->can_negotiate = nconf->can_negotiate; ch1='!'; }
3546 mod_gzip_printf( "%s: pconf %c= nconf : merged_config->can_negotiate = %ld", cn, ch1, (long) merged_config->can_negotiate );
3548 merged_config->can_negotiate = ( !nconf->can_negotiate_set ) ? pconf->can_negotiate : nconf->can_negotiate;
3552 #ifdef MOD_GZIP_DEBUG1
3553 if ( !nconf->dechunk_set )
3554 { merged_config->dechunk = pconf->dechunk; ch1='='; }
3555 else { merged_config->dechunk = nconf->dechunk; ch1='!'; }
3556 mod_gzip_printf( "%s: pconf %c= nconf : merged_config->dechunk = %ld", cn, ch1, (long) merged_config->dechunk );
3558 merged_config->dechunk = ( !nconf->dechunk_set ) ? pconf->dechunk : nconf->dechunk;
3561 #ifdef MOD_GZIP_DEBUG1
3562 if ( !nconf->min_http_set )
3563 { merged_config->min_http = pconf->min_http; ch1='='; }
3564 else { merged_config->min_http = nconf->min_http; ch1='!'; }
3565 mod_gzip_printf( "%s: pconf %c= nconf : merged_config->min_http = %ld", cn, ch1, (long) merged_config->min_http );
3567 merged_config->min_http = ( !nconf->min_http_set ) ? pconf->min_http : nconf->min_http;
3570 #ifdef MOD_GZIP_DEBUG1
3571 if ( !nconf->minimum_file_size_set )
3572 { merged_config->minimum_file_size = pconf->minimum_file_size; ch1='='; }
3573 else { merged_config->minimum_file_size = nconf->minimum_file_size; ch1='!'; }
3574 mod_gzip_printf( "%s: pconf %c= nconf : merged_config->minimum_file_size = %ld", cn, ch1, (long) merged_config->minimum_file_size );
3576 merged_config->minimum_file_size = ( !nconf->minimum_file_size_set ) ? pconf->minimum_file_size : nconf->minimum_file_size;
3579 #ifdef MOD_GZIP_DEBUG1
3580 if ( !nconf->maximum_file_size_set )
3581 { merged_config->maximum_file_size = pconf->maximum_file_size; ch1='='; }
3582 else { merged_config->maximum_file_size = nconf->maximum_file_size; ch1='!'; }
3583 mod_gzip_printf( "%s: pconf %c= nconf : merged_config->maximum_file_size = %ld", cn, ch1, (long) merged_config->maximum_file_size );
3585 merged_config->maximum_file_size = ( !nconf->maximum_file_size_set ) ? pconf->maximum_file_size : nconf->maximum_file_size;
3588 #ifdef MOD_GZIP_DEBUG1
3589 if ( !nconf->maximum_inmem_size_set )
3590 { merged_config->maximum_inmem_size = pconf->maximum_inmem_size; ch1='='; }
3591 else { merged_config->maximum_inmem_size = nconf->maximum_inmem_size; ch1='!'; }
3592 mod_gzip_printf( "%s: pconf %c= nconf : merged_config->maximum_inmem_size = %ld", cn, ch1, (long) merged_config->maximum_inmem_size );
3594 merged_config->maximum_inmem_size = ( !nconf->maximum_inmem_size_set ) ? pconf->maximum_inmem_size : nconf->maximum_inmem_size;
3597 #ifdef MOD_GZIP_DEBUG1
3598 if ( !nconf->temp_dir_set )
3599 { mod_gzip_strcpy(merged_config->temp_dir,pconf->temp_dir); ch1='='; }
3600 else { mod_gzip_strcpy(merged_config->temp_dir,nconf->temp_dir); ch1='!'; }
3601 mod_gzip_printf( "%s: pconf %c= nconf : merged_config->temp_dir = [%s]", cn, ch1,npp(merged_config->temp_dir));
3603 if ( !nconf->temp_dir_set )
3604 { mod_gzip_strcpy(merged_config->temp_dir,pconf->temp_dir); }
3605 else { mod_gzip_strcpy(merged_config->temp_dir,nconf->temp_dir); }
3608 #ifdef MOD_GZIP_COMMAND_VERSION_USED
3609 #ifdef MOD_GZIP_DEBUG1
3610 if ( !nconf->command_version_set )
3611 { mod_gzip_strcpy(merged_config->command_version,pconf->command_version); ch1='='; }
3612 else { mod_gzip_strcpy(merged_config->command_version,nconf->command_version); ch1='!'; }
3613 mod_gzip_printf( "%s: pconf %c= nconf : merged_config->command_version = [%s]", cn, ch1,npp(merged_config->command_version));
3615 if ( !nconf->command_version_set )
3616 { mod_gzip_strcpy(merged_config->command_version,pconf->command_version); }
3617 else { mod_gzip_strcpy(merged_config->command_version,nconf->command_version); }
3623 for ( i=0; i<nconf->imap_total_entries; i++ )
3626 &(merged_config->imap[i]),
3633 if ( nconf->imap[i].type == MOD_GZIP_IMAP_ISMIME )
3637 else if ( nconf->imap[i].type == MOD_GZIP_IMAP_ISFILE )
3641 else if ( nconf->imap[i].type == MOD_GZIP_IMAP_ISURI )
3645 else if ( nconf->imap[i].type == MOD_GZIP_IMAP_ISHANDLER )
3649 else if ( nconf->imap[i].type == MOD_GZIP_IMAP_ISREQHEADER )
3651 total_isreqheader++;
3653 else if ( nconf->imap[i].type == MOD_GZIP_IMAP_ISRSPHEADER )
3655 total_isrspheader++;
3659 for ( i=0; i<pconf->imap_total_entries; i++ )
3661 p1 = pconf->imap[i].name;
3662 l1 = mod_gzip_strlen( p1 );
3666 for ( ii=0; ii<nconf->imap_total_entries; ii++ )
3668 p2 = nconf->imap[ii].name;
3669 l2 = nconf->imap[ii].namelen;
3673 if ( mod_gzip_strncmp( p1, p2, l1 ) == 0 )
3687 if ( total < MOD_GZIP_IMAP_MAXNAMES )
3690 &(merged_config->imap[ total ]),
3697 if ( pconf->imap[i].type == MOD_GZIP_IMAP_ISMIME )
3701 else if ( pconf->imap[i].type == MOD_GZIP_IMAP_ISFILE )
3705 else if ( pconf->imap[i].type == MOD_GZIP_IMAP_ISURI )
3709 else if ( pconf->imap[i].type == MOD_GZIP_IMAP_ISHANDLER )
3713 else if ( pconf->imap[i].type == MOD_GZIP_IMAP_ISREQHEADER )
3715 total_isreqheader++;
3717 else if ( pconf->imap[i].type == MOD_GZIP_IMAP_ISRSPHEADER )
3719 total_isrspheader++;
3725 merged_config->imap_total_entries = total;
3726 merged_config->imap_total_ismime = total_ismime;
3727 merged_config->imap_total_isfile = total_isfile;
3728 merged_config->imap_total_isuri = total_isuri;
3729 merged_config->imap_total_ishandler = total_ishandler;
3730 merged_config->imap_total_isreqheader = total_isreqheader;
3731 merged_config->imap_total_isrspheader = total_isrspheader;
3733 #ifdef MOD_GZIP_DEBUG1
3734 mod_gzip_printf( "%s: pconf += nconf : merged_config->imap_total_entries = %ld", cn, (long) merged_config->imap_total_entries );
3735 mod_gzip_printf( "%s: pconf += nconf : merged_config->imap_total_ismime = %ld", cn, (long) merged_config->imap_total_ismime );
3736 mod_gzip_printf( "%s: pconf += nconf : merged_config->imap_total_isfile = %ld", cn, (long) merged_config->imap_total_isfile );
3737 mod_gzip_printf( "%s: pconf += nconf : merged_config->imap_total_isuri = %ld", cn, (long) merged_config->imap_total_isuri );
3738 mod_gzip_printf( "%s: pconf += nconf : merged_config->imap_total_ishandler = %ld", cn, (long) merged_config->imap_total_ishandler );
3739 mod_gzip_printf( "%s: pconf += nconf : merged_config->imap_total_isreqheader = %ld", cn, (long) merged_config->imap_total_isreqheader );
3740 mod_gzip_printf( "%s: pconf += nconf : merged_config->imap_total_isrspheader = %ld", cn, (long) merged_config->imap_total_isrspheader );
3743 #ifdef MOD_GZIP_DEBUG1
3744 mod_gzip_printf( "%s: ",cn);
3751 mod_gzip_set_is_on( cmd_parms *parms, void *cfg, char *arg )
3755 #ifdef MOD_GZIP_DEBUG1
3756 server_rec *srv = parms->server;
3757 char cn[]="mod_gzip_set_is_on()";
3760 #ifdef MOD_GZIP_DEBUG1
3762 mod_gzip_server_now = srv;
3764 mod_gzip_printf( " ");
3765 mod_gzip_printf( "%s: Entry", cn );
3766 mod_gzip_printf( "%s: arg=[%s]", cn, npp(arg) );
3770 mgc = ( mod_gzip_conf * ) cfg;
3772 #ifdef MOD_GZIP_ALTERNATIVE1
3774 mgc = ( mod_gzip_conf * )
3775 ap_get_module_config(parms->server->module_config, &gzip_module);
3778 if ( ( arg[0] == 'Y' )||( arg[0] == 'y' ) )
3789 #ifdef MOD_GZIP_DEBUG1
3790 mod_gzip_printf( "%s: mgc->loc = [%s]", cn, npp(mgc->loc));
3791 mod_gzip_printf( "%s: srv->is_virtual = %ld", cn, (long)srv->is_virtual );
3792 mod_gzip_printf( "%s: srv->server_hostname = [%s]", cn, npp(srv->server_hostname));
3793 mod_gzip_printf( "%s: mgc->cmode = %ld", cn, (long) mgc->cmode );
3794 mod_gzip_printf( "%s: mgc->is_on = %ld", cn, (long) mgc->is_on );
3795 mod_gzip_printf( "%s: mgc->is_on_set = %ld", cn, (long) mgc->is_on_set );
3802 mod_gzip_set_add_header_count( cmd_parms *parms, void *cfg, char *arg )
3806 #ifdef MOD_GZIP_DEBUG1
3807 server_rec *srv = parms->server;
3808 char cn[]="mod_gzip_set_add_header_count()";
3811 #ifdef MOD_GZIP_DEBUG1
3812 mod_gzip_server_now = srv;
3813 mod_gzip_printf( " ");
3814 mod_gzip_printf( "%s: Entry", cn );
3815 mod_gzip_printf( "%s: arg=[%s]", cn, npp(arg) );
3818 mgc = ( mod_gzip_conf * ) cfg;
3820 if ( ( arg[0] == 'Y' )||( arg[0] == 'y' ) )
3822 mgc->add_header_count = 1;
3826 mgc->add_header_count = 0;
3829 mgc->add_header_count_set = 1;
3831 #ifdef MOD_GZIP_DEBUG1
3832 mod_gzip_printf( "%s: mgc->loc = [%s]",cn, npp(mgc->loc));
3833 mod_gzip_printf( "%s: mgc->cmode = %ld", cn, (long) mgc->cmode );
3834 mod_gzip_printf( "%s: srv->is_virtual = %ld", cn, (long)srv->is_virtual );
3835 mod_gzip_printf( "%s: srv->server_hostname = [%s]",cn, npp(srv->server_hostname));
3836 mod_gzip_printf( "%s: mgc->add_header_count = %ld", cn,
3837 (long) mgc->add_header_count );
3838 mod_gzip_printf( "%s: mgc->add_header_count_set = %ld", cn,
3839 (long) mgc->add_header_count_set );
3846 mod_gzip_set_keep_workfiles( cmd_parms *parms, void *cfg, char *arg )
3850 #ifdef MOD_GZIP_DEBUG1
3851 server_rec *srv = parms->server;
3852 char cn[]="mod_gzip_set_keep_workfiles()";
3855 #ifdef MOD_GZIP_DEBUG1
3856 mod_gzip_server_now = srv;
3857 mod_gzip_printf( " ");
3858 mod_gzip_printf( "%s: Entry", cn );
3859 mod_gzip_printf( "%s: arg=[%s]", cn, npp(arg) );
3862 mgc = ( mod_gzip_conf * ) cfg;
3864 if ( ( arg[0] == 'Y' )||( arg[0] == 'y' ) )
3866 mgc->keep_workfiles = 1;
3870 mgc->keep_workfiles = 0;
3873 mgc->keep_workfiles_set = 1;
3875 #ifdef MOD_GZIP_DEBUG1
3876 mod_gzip_printf( "%s: mgc->loc = [%s]",cn, npp(mgc->loc) );
3877 mod_gzip_printf( "%s: mgc->cmode = %ld", cn, (long) mgc->cmode );
3878 mod_gzip_printf( "%s: srv->is_virtual = %ld", cn, (long)srv->is_virtual );
3879 mod_gzip_printf( "%s: srv->server_hostname = [%s]",cn, npp(srv->server_hostname) );
3880 mod_gzip_printf( "%s: mgc->keep_workfiles = %ld", cn,
3881 (long) mgc->keep_workfiles );
3882 mod_gzip_printf( "%s: mgc->keep_workfiles_set = %ld", cn,
3883 (long) mgc->keep_workfiles_set );
3889 #ifdef MOD_GZIP_CAN_NEGOTIATE
3891 mod_gzip_set_can_negotiate( cmd_parms *parms, void *cfg, char *arg )
3895 #ifdef MOD_GZIP_DEBUG1
3896 server_rec *srv = parms->server;
3897 char cn[]="mod_gzip_set_can_negotiate()";
3900 #ifdef MOD_GZIP_DEBUG1
3901 mod_gzip_server_now = srv;
3902 mod_gzip_printf( " ");
3903 mod_gzip_printf( "%s: Entry", cn );
3904 mod_gzip_printf( "%s: arg=[%s]", cn, npp(arg) );
3907 mgc = ( mod_gzip_conf * ) cfg;
3909 if ( ( arg[0] == 'Y' )||( arg[0] == 'y' ) )
3911 mgc->can_negotiate = 1;
3915 mgc->can_negotiate = 0;
3918 mgc->can_negotiate_set = 1;
3920 #ifdef MOD_GZIP_DEBUG1
3921 mod_gzip_printf( "%s: mgc->loc = [%s]",cn, npp(mgc->loc) );
3922 mod_gzip_printf( "%s: mgc->cmode = %ld", cn, (long) mgc->cmode );
3923 mod_gzip_printf( "%s: srv->is_virtual = %ld", cn, (long)srv->is_virtual );
3924 mod_gzip_printf( "%s: srv->server_hostname = [%s]",cn, npp(srv->server_hostname) );
3925 mod_gzip_printf( "%s: mgc->can_negotiate = %ld", cn,
3926 (long) mgc->can_negotiate );
3927 mod_gzip_printf( "%s: mgc->can_negotiate_set = %ld", cn,
3928 (long) mgc->can_negotiate_set );
3936 mod_gzip_set_dechunk( cmd_parms *parms, void *cfg, char *arg )
3940 #ifdef MOD_GZIP_DEBUG1
3941 server_rec *srv = parms->server;
3942 char cn[]="mod_gzip_set_dechunk()";
3945 #ifdef MOD_GZIP_DEBUG1
3946 mod_gzip_server_now = srv;
3947 mod_gzip_printf( " ");
3948 mod_gzip_printf( "%s: Entry", cn );
3949 mod_gzip_printf( "%s: arg=[%s]", cn, npp(arg) );
3952 mgc = ( mod_gzip_conf * ) cfg;
3954 if ( ( arg[0] == 'Y' )||( arg[0] == 'y' ) )
3963 mgc->dechunk_set = 1;
3965 #ifdef MOD_GZIP_DEBUG1
3966 mod_gzip_printf( "%s: mgc->loc = [%s]",cn, npp(mgc->loc) );
3967 mod_gzip_printf( "%s: mgc->cmode = %ld", cn, (long) mgc->cmode );
3968 mod_gzip_printf( "%s: srv->is_virtual = %ld", cn, (long)srv->is_virtual );
3969 mod_gzip_printf( "%s: srv->server_hostname = [%s]",cn, npp(srv->server_hostname) );
3970 mod_gzip_printf( "%s: mgc->dechunk = %ld", cn,
3971 (long) mgc->dechunk );
3972 mod_gzip_printf( "%s: mgc->dechunk_set = %ld", cn,
3973 (long) mgc->dechunk_set );
3980 mod_gzip_set_min_http( cmd_parms *parms, void *cfg, char *arg )
3984 #ifdef MOD_GZIP_DEBUG1
3985 server_rec *srv = parms->server;
3986 char cn[]="mod_gzip_set_min_http()";
3989 #ifdef MOD_GZIP_DEBUG1
3990 mod_gzip_server_now = srv;
3991 mod_gzip_printf( " ");
3992 mod_gzip_printf( "%s: Entry", cn );
3993 mod_gzip_printf( "%s: arg=[%s]", cn, npp(arg) );
3996 mgc = ( mod_gzip_conf * ) cfg;
3998 mgc->min_http = (int) atoi( arg );
3999 mgc->min_http_set = 1;
4001 #ifdef MOD_GZIP_DEBUG1
4002 mod_gzip_printf( "%s: mgc->loc = [%s]",cn, npp(mgc->loc));
4003 mod_gzip_printf( "%s: mgc->cmode = %ld", cn, (long) mgc->cmode );
4004 mod_gzip_printf( "%s: srv->is_virtual = %ld", cn, (long)srv->is_virtual );
4005 mod_gzip_printf( "%s: srv->server_hostname = [%s]",cn, npp(srv->server_hostname));
4006 mod_gzip_printf( "%s: mgc->min_http = %ld", cn,
4007 (long) mgc->min_http );
4008 mod_gzip_printf( "%s: mgc->min_http = %ld", cn,
4009 (long) mgc->min_http_set );
4016 mod_gzip_set_minimum_file_size( cmd_parms *parms, void *cfg, char *arg )
4020 #ifdef MOD_GZIP_DEBUG1
4021 server_rec *srv = parms->server;
4022 char cn[]="mod_gzip_set_minimum_file_size()";
4025 #ifdef MOD_GZIP_DEBUG1
4026 mod_gzip_server_now = srv;
4027 mod_gzip_printf( " ");
4028 mod_gzip_printf( "%s: Entry", cn );
4029 mod_gzip_printf( "%s: arg=[%s]", cn, npp(arg));
4032 mgc = ( mod_gzip_conf * ) cfg;
4034 mgc->minimum_file_size = (long) atol( arg );
4035 mgc->minimum_file_size_set = 1;
4037 if ( mgc->minimum_file_size < 300 )
4039 mgc->minimum_file_size = 300;
4042 #ifdef MOD_GZIP_DEBUG1
4043 mod_gzip_printf( "%s: mgc->loc = [%s]",cn, npp(mgc->loc));
4044 mod_gzip_printf( "%s: mgc->cmode = %ld", cn, (long) mgc->cmode );
4045 mod_gzip_printf( "%s: srv->is_virtual = %ld", cn, (long)srv->is_virtual );
4046 mod_gzip_printf( "%s: srv->server_hostname = [%s]",cn, npp(srv->server_hostname));
4047 mod_gzip_printf( "%s: mgc->minimum_file_size = %ld", cn,
4048 (long) mgc->minimum_file_size );
4049 mod_gzip_printf( "%s: mgc->minimum_file_size = %ld", cn,
4050 (long) mgc->minimum_file_size_set );
4057 mod_gzip_set_maximum_file_size( cmd_parms *parms, void *cfg, char *arg )
4061 #ifdef MOD_GZIP_DEBUG1
4062 server_rec *srv = parms->server;
4063 char cn[]="mod_gzip_set_maximum_file_size()";
4066 #ifdef MOD_GZIP_DEBUG1
4067 mod_gzip_server_now = srv;
4068 mod_gzip_printf( " ");
4069 mod_gzip_printf( "%s: Entry", cn );
4070 mod_gzip_printf( "%s: arg=[%s]", cn, npp(arg));
4073 mgc = ( mod_gzip_conf * ) cfg;
4075 mgc->maximum_file_size = (long) atol( arg );
4076 mgc->maximum_file_size_set = 1;
4078 #ifdef MOD_GZIP_DEBUG1
4079 mod_gzip_printf( "%s: mgc->loc = [%s]",cn, npp(mgc->loc));
4080 mod_gzip_printf( "%s: mgc->cmode = %ld", cn, (long) mgc->cmode );
4081 mod_gzip_printf( "%s: srv->is_virtual = %ld", cn, (long)srv->is_virtual );
4082 mod_gzip_printf( "%s: srv->server_hostname = [%s]",cn, npp(srv->server_hostname));
4083 mod_gzip_printf( "%s: mgc->maximum_file_size = %ld", cn,
4084 (long) mgc->maximum_file_size );
4085 mod_gzip_printf( "%s: mgc->maximum_file_size = %ld", cn,
4086 (long) mgc->maximum_file_size_set );
4093 mod_gzip_set_maximum_inmem_size( cmd_parms *parms, void *cfg, char *arg )
4097 #ifdef MOD_GZIP_DEBUG1
4098 server_rec *srv = parms->server;
4099 char cn[]="mod_gzip_set_maximum_inmem_size()";
4102 #ifdef MOD_GZIP_DEBUG1
4103 mod_gzip_server_now = srv;
4104 mod_gzip_printf( " ");
4105 mod_gzip_printf( "%s: Entry", cn );
4106 mod_gzip_printf( "%s: arg=[%s]", cn, npp(arg) );
4109 mgc = ( mod_gzip_conf * ) cfg;
4111 mgc->maximum_inmem_size = (long) atol(arg);
4112 mgc->maximum_inmem_size_set = 1;
4114 #ifdef MOD_GZIP_DEBUG1
4115 mod_gzip_printf( "%s: mgc->loc = [%s]",cn, npp(mgc->loc));
4116 mod_gzip_printf( "%s: mgc->cmode = %ld", cn, (long) mgc->cmode );
4117 mod_gzip_printf( "%s: srv->is_virtual = %ld", cn, (long)srv->is_virtual );
4118 mod_gzip_printf( "%s: srv->server_hostname = [%s]",cn, npp(srv->server_hostname));
4119 mod_gzip_printf( "%s: mgc->maximum_inmem_size = %ld", cn,
4120 (long) mgc->maximum_inmem_size );
4121 mod_gzip_printf( "%s: mgc->maximum_inmem_size = %ld", cn,
4122 (long) mgc->maximum_inmem_size_set );
4129 mod_gzip_set_temp_dir( cmd_parms *parms, void *cfg, char *arg )
4133 #ifdef MOD_GZIP_DEBUG1
4134 server_rec *srv = parms->server;
4135 char cn[]="mod_gzip_set_temp_dir()";
4149 #ifdef MOD_GZIP_DEBUG1
4150 mod_gzip_server_now = srv;
4151 mod_gzip_printf( " ");
4152 mod_gzip_printf( "%s: Entry", cn );
4157 #ifdef MOD_GZIP_DEBUG1
4158 mod_gzip_printf( "%s: ERROR: 'arg' is NULL...", cn );
4159 mod_gzip_printf( "%s: ERROR: No valid directory supplied.", cn );
4162 return "mod_gzip_temp_dir: ERROR: No valid directory supplied.";
4165 #ifdef MOD_GZIP_DEBUG1
4166 mod_gzip_printf( "%s: arg=[%s]", cn, npp(arg) );
4169 mgc = ( mod_gzip_conf * ) cfg;
4171 arglen = mod_gzip_strlen( arg );
4175 mod_gzip_strcpy( mgc->temp_dir, arg );
4176 mgc->temp_dir_set = 1;
4180 if (( arglen == 1 ) && ( *arg == 32 ))
4182 #ifdef MOD_GZIP_DEBUG1
4183 mod_gzip_printf( "%s: Special ONE SPACE pickup seen.", cn );
4184 mod_gzip_printf( "%s: temp_dir set to NOTHING.", cn );
4187 mod_gzip_strcpy( mgc->temp_dir, "" );
4191 if ( ( *(mgc->temp_dir+(arglen-1)) != '\\' ) &&
4192 ( *(mgc->temp_dir+(arglen-1)) != '/' ) )
4194 mod_gzip_strcat( mgc->temp_dir, dirsep );
4197 rc = stat( mgc->temp_dir, &sbuf );
4201 #ifdef MOD_GZIP_DEBUG1
4202 mod_gzip_printf( "%s: .... stat() call FAILED",cn);
4203 mod_gzip_printf( "%s: Directory name is not valid.",cn);
4206 return "mod_gzip_temp_dir: ERROR: Directory does not exist.";
4210 #ifdef MOD_GZIP_DEBUG1
4211 mod_gzip_printf( "%s: .... stat() call SUCCEEDED",cn);
4212 mod_gzip_printf( "%s: Directory name appears to be valid.",cn);
4218 #ifdef MOD_GZIP_DEBUG1
4219 mod_gzip_printf( "%s: mgc->loc = [%s]", cn, npp(mgc->loc));
4220 mod_gzip_printf( "%s: srv->is_virtual = %ld", cn, (long)srv->is_virtual );
4221 mod_gzip_printf( "%s: srv->server_hostname = [%s]", cn, npp(srv->server_hostname));
4222 mod_gzip_printf( "%s: mgc->cmode = %ld", cn, (long) mgc->cmode);
4223 mod_gzip_printf( "%s: mgc->temp_dir = [%s]", cn, npp(mgc->temp_dir));
4224 mod_gzip_printf( "%s: mgc->temp_dir_set = %d", cn, mgc->temp_dir_set);
4231 return "mod_gzip_temp_dir pathname must be less than 256 characters.";
4235 #ifdef MOD_GZIP_COMMAND_VERSION_USED
4237 mod_gzip_set_command_version( cmd_parms *parms, void *cfg, char *arg )
4241 #ifdef MOD_GZIP_DEBUG1
4242 server_rec *srv = parms->server;
4243 char cn[]="mod_gzip_set_command_version()";
4248 #ifdef MOD_GZIP_DEBUG1
4249 mod_gzip_server_now = srv;
4250 mod_gzip_printf( " ");
4251 mod_gzip_printf( "%s: Entry", cn );
4256 #ifdef MOD_GZIP_DEBUG1
4257 mod_gzip_printf( "%s: ERROR: 'arg' is NULL...", cn );
4258 mod_gzip_printf( "%s: ERROR: No valid string supplied.", cn );
4261 return "mod_gzip_command_version: ERROR: No valid string supplied.";
4264 #ifdef MOD_GZIP_DEBUG1
4265 mod_gzip_printf( "%s: arg=[%s]", cn, npp(arg) );
4268 mgc = ( mod_gzip_conf * ) cfg;
4270 arglen = mod_gzip_strlen( arg );
4272 if ( arglen < MOD_GZIP_COMMAND_VERSION_MAXLEN )
4274 mod_gzip_strcpy( mgc->command_version, arg );
4275 mgc->command_version_set = 1;
4277 #ifdef MOD_GZIP_DEBUG1
4278 mod_gzip_printf( "%s: mgc->loc = [%s]", cn, npp(mgc->loc));
4279 mod_gzip_printf( "%s: srv->is_virtual = %ld", cn, (long)srv->is_virtual );
4280 mod_gzip_printf( "%s: srv->server_hostname = [%s]", cn, npp(srv->server_hostname));
4281 mod_gzip_printf( "%s: mgc->cmode = %ld", cn, (long) mgc->cmode);
4282 mod_gzip_printf( "%s: mgc->command_version = [%s]", cn, npp(mgc->command_version));
4283 mod_gzip_printf( "%s: mgc->command_version_set = %d", cn, mgc->command_version_set);
4290 return "mod_gzip_command_version string must be less than 128 characters.";
4296 mod_gzip_imap_add_item(
4308 int this_include=flag1;
4311 int this_direction=0;
4312 unsigned this_port=0;
4314 regex_t *this_pregex=NULL;
4319 #define MOD_GZIP_TEST_REGEX1
4321 #ifdef MOD_GZIP_TEST_REGEX1
4326 #ifdef MOD_GZIP_DEBUG1
4327 char cn[]="mod_gzip_imap_add_item()";
4330 #ifdef MOD_GZIP_DEBUG1
4332 mod_gzip_printf( "%s: Entry", cn );
4333 mod_gzip_printf( "%s: 1 a1=[%s]", cn, npp(a1));
4334 mod_gzip_printf( "%s: 1 a2=[%s]", cn, npp(a2));
4336 mod_gzip_printf( "%s: mgc->imap_total_entries = %d",
4337 cn, mgc->imap_total_entries );
4338 mod_gzip_printf( "%s: mgc->imap_total_ismime = %d",
4339 cn, mgc->imap_total_ismime );
4340 mod_gzip_printf( "%s: mgc->imap_total_isfile = %d",
4341 cn, mgc->imap_total_isfile );
4342 mod_gzip_printf( "%s: mgc->imap_total_isuri = %d",
4343 cn, mgc->imap_total_isuri );
4344 mod_gzip_printf( "%s: mgc->imap_total_ishandler = %d",
4345 cn, mgc->imap_total_ishandler );
4346 mod_gzip_printf( "%s: mgc->imap_total_isreqheader = %d",
4347 cn, mgc->imap_total_isreqheader );
4348 mod_gzip_printf( "%s: mgc->imap_total_isrspheader = %d",
4349 cn, mgc->imap_total_isrspheader );
4353 mod_gzip_printf( "%s: flag1 = %d = INCLUDE", cn, flag1 );
4355 else if ( flag1 == 0 )
4357 mod_gzip_printf( "%s: flag1 = %d = EXCLUDE", cn, flag1 );
4361 mod_gzip_printf( "%s: flag1 = %d = ??? Unknown value", cn, flag1 );
4366 this_type = MOD_GZIP_IMAP_ISNONE;
4368 if ( mod_gzip_strnicmp( a1, "mime", 4 ) == 0 )
4370 this_type = MOD_GZIP_IMAP_ISMIME;
4372 #ifdef MOD_GZIP_DEBUG1
4373 mod_gzip_printf( "%s: this_type = MOD_GZIP_IMAP_ISMIME", cn);
4376 else if ( mod_gzip_strnicmp( a1, "file", 4 ) == 0 )
4378 this_type = MOD_GZIP_IMAP_ISFILE;
4380 #ifdef MOD_GZIP_DEBUG1
4381 mod_gzip_printf( "%s: this_type = MOD_GZIP_IMAP_ISFILE",cn);
4384 else if ( mod_gzip_strnicmp( a1, "ur", 2 ) == 0 )
4386 /* Allow user to specify EITHER 'uri' or 'url' for this 'type' */
4388 this_type = MOD_GZIP_IMAP_ISURI;
4390 #ifdef MOD_GZIP_DEBUG1
4391 mod_gzip_printf( "%s: this_type = MOD_GZIP_IMAP_ISURI",cn);
4394 else if ( mod_gzip_strnicmp( a1, "hand", 4 ) == 0 )
4396 this_type = MOD_GZIP_IMAP_ISHANDLER;
4398 #ifdef MOD_GZIP_DEBUG1
4399 mod_gzip_printf( "%s: this_type = MOD_GZIP_IMAP_ISHANDLER",cn);
4402 else if ( mod_gzip_strnicmp( a1, "reqh", 4 ) == 0 )
4404 this_type = MOD_GZIP_IMAP_ISREQHEADER;
4405 this_direction = MOD_GZIP_REQUEST;
4407 #ifdef MOD_GZIP_DEBUG1
4408 mod_gzip_printf( "%s: this_type = MOD_GZIP_IMAP_ISREQHEADER",cn);
4411 else if ( mod_gzip_strnicmp( a1, "rsph", 4 ) == 0 )
4413 this_type = MOD_GZIP_IMAP_ISRSPHEADER;
4414 this_direction = MOD_GZIP_RESPONSE;
4416 #ifdef MOD_GZIP_DEBUG1
4417 mod_gzip_printf( "%s: this_type = MOD_GZIP_IMAP_ISRSPHEADER",cn);
4421 if ( this_type == MOD_GZIP_IMAP_ISNONE )
4423 #ifdef MOD_GZIP_DEBUG1
4424 mod_gzip_printf( "%s: this_type = ?? UNKNOWN ??",cn);
4425 mod_gzip_printf( "%s: Exit > return( ERRORSTRING ) >",cn);
4428 return "mod_gzip: ERROR: Valid item types are mime,file,uri,handler,reqheader or rspheader";
4433 if ( ( this_type == MOD_GZIP_IMAP_ISREQHEADER ) ||
4434 ( this_type == MOD_GZIP_IMAP_ISRSPHEADER ) )
4436 while((*p1!=0)&&(*p1!=':')) { p1++; this_len1++; }
4440 if ( this_len1 < 1 )
4442 return "mod_gzip: ERROR: Missing HTTP field name.";
4449 return "mod_gzip: ERROR: Missing HTTP field name. No colon found.";
4452 while((*p1!=0)&&(*p1<33)) p1++;
4457 #ifdef MOD_GZIP_DEBUG1
4458 mod_gzip_printf( "%s: regex = [%s]", cn, npp(regex) );
4463 return "mod_gzip: ERROR: Missing regular expression string.";
4468 #ifdef MOD_GZIP_DEBUG1
4469 mod_gzip_printf( "%s: ignorecase = %d",cn,ignorecase);
4470 mod_gzip_printf( "%s: Call ap_pregcomp(%s)...",cn,npp(regex));
4474 ap_pregcomp(parms->pool, regex,
4475 (REG_EXTENDED | REG_NOSUB
4476 | (ignorecase ? REG_ICASE : 0)));
4478 if ( this_pregex == NULL )
4480 #ifdef MOD_GZIP_DEBUG1
4481 mod_gzip_printf( "%s: .... ap_pregcomp(%s) FAILED...",cn,npp(regex));
4482 mod_gzip_printf( "%s: regex 'pre-compile' FAILED...", cn );
4483 mod_gzip_printf( "%s: Exit > return( ERRORSTRING ) >",cn);
4486 return "mod_gzip: ERROR: Regular expression compile failed.";
4489 #ifdef MOD_GZIP_DEBUG1
4490 mod_gzip_printf( "%s: .... ap_pregcomp(%s) SUCCEEDED...",cn,npp(regex));
4491 mod_gzip_printf( "%s: regex 'pre-compiled' OK", cn );
4494 #ifdef MOD_GZIP_TEST_REGEX1
4496 if ( ( this_type == MOD_GZIP_IMAP_ISREQHEADER ) ||
4497 ( this_type == MOD_GZIP_IMAP_ISRSPHEADER ) )
4501 "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt; TUCOWS)"
4504 #ifdef MOD_GZIP_DEBUG1
4505 mod_gzip_printf( "%s: Call ap_regexec( regex=[%s], string=[%s] )",
4506 cn, npp(regex), npp(string) );
4509 regex_error = ap_regexec(this_pregex, string, 0, (regmatch_t *)NULL,0);
4511 #ifdef MOD_GZIP_DEBUG1
4512 if ( regex_error != 0 )
4513 mod_gzip_printf( "%s: regex_error = %d = NO MATCH!", cn, regex_error );
4515 mod_gzip_printf( "%s: regex_error = %d = MATCH!", cn, regex_error );
4519 #endif /* MOD_GZIP_TEST_REGEX1 */
4521 this_action = MOD_GZIP_IMAP_STATIC1;
4525 if ( ( this_action != MOD_GZIP_IMAP_DYNAMIC1 ) &&
4526 ( this_action != MOD_GZIP_IMAP_DYNAMIC2 ) &&
4527 ( this_action != MOD_GZIP_IMAP_STATIC1 ) )
4529 #ifdef MOD_GZIP_DEBUG1
4530 mod_gzip_printf( "%s: this_action = %d = MOD_GZIP_IMAP_??? Unknown action",cn,this_action);
4531 mod_gzip_printf( "%s: return( mod_gzip: ERROR: Unrecognized item 'action'",cn);
4534 return( "mod_gzip: ERROR: Unrecognized item 'action'" );
4539 if ( mgc->imap_total_entries < MOD_GZIP_IMAP_MAXNAMES )
4541 if ( mod_gzip_strlen( a2 ) < MOD_GZIP_IMAP_MAXNAMELEN )
4543 x = mgc->imap_total_entries;
4547 mod_gzip_strcpy( mgc->imap[x].name, p1 );
4549 mgc->imap[x].namelen = mod_gzip_strlen( mgc->imap[x].name );
4551 mgc->imap[x].include = this_include;
4552 mgc->imap[x].type = this_type;
4553 mgc->imap[x].action = this_action;
4554 mgc->imap[x].direction = this_direction;
4555 mgc->imap[x].port = this_port;
4556 mgc->imap[x].len1 = this_len1;
4557 mgc->imap[x].pregex = this_pregex;
4559 mgc->imap_total_entries++;
4561 if ( this_type == MOD_GZIP_IMAP_ISMIME )
4563 mgc->imap_total_ismime++;
4565 else if ( this_type == MOD_GZIP_IMAP_ISFILE )
4567 mgc->imap_total_isfile++;
4569 else if ( this_type == MOD_GZIP_IMAP_ISURI )
4571 mgc->imap_total_isuri++;
4573 else if ( this_type == MOD_GZIP_IMAP_ISHANDLER )
4575 mgc->imap_total_ishandler++;
4577 else if ( this_type == MOD_GZIP_IMAP_ISREQHEADER )
4579 mgc->imap_total_isreqheader++;
4581 else if ( this_type == MOD_GZIP_IMAP_ISRSPHEADER )
4583 mgc->imap_total_isrspheader++;
4588 #ifdef MOD_GZIP_DEBUG1
4589 mod_gzip_printf( "%s: return( mod_gzip: ERROR: Item name is too long",cn);
4592 return( "mod_gzip: ERROR: Item name is too long" );
4597 #ifdef MOD_GZIP_DEBUG1
4598 mod_gzip_printf( "%s: return( mod_gzip: ERROR: Item index is full",cn);
4601 return( "mod_gzip: ERROR: Item index is full" );
4604 #ifdef MOD_GZIP_DEBUG1
4606 mod_gzip_printf( "%s: mgc->imap_total_entries = %d",
4607 cn, mgc->imap_total_entries );
4608 mod_gzip_printf( "%s: mgc->imap_total_ismime = %d",
4609 cn, mgc->imap_total_ismime );
4610 mod_gzip_printf( "%s: mgc->imap_total_isfile = %d",
4611 cn, mgc->imap_total_isfile );
4612 mod_gzip_printf( "%s: mgc->imap_total_isuri = %d",
4613 cn, mgc->imap_total_isuri );
4614 mod_gzip_printf( "%s: mgc->imap_total_ishandler = %d",
4615 cn, mgc->imap_total_ishandler );
4616 mod_gzip_printf( "%s: mgc->imap_total_isreqheader = %d",
4617 cn, mgc->imap_total_isreqheader );
4618 mod_gzip_printf( "%s: mgc->imap_total_isrspheader = %d",
4619 cn, mgc->imap_total_isrspheader );
4621 mod_gzip_printf( "%s: Exit > return( NULL ) >",cn);
4629 mod_gzip_set_item_include( cmd_parms *parms, void *cfg, char *a1, char *a2 )
4634 #ifdef MOD_GZIP_DEBUG1
4635 server_rec *srv = parms->server;
4636 char cn[]="mod_gzip_set_item_include()";
4639 #ifdef MOD_GZIP_DEBUG1
4640 mod_gzip_server_now = srv;
4641 mod_gzip_printf( " ");
4642 mod_gzip_printf( "%s: Entry", cn );
4643 mod_gzip_printf( "%s: a1=[%s]", cn, npp(a1) );
4644 mod_gzip_printf( "%s: a2=[%s]", cn, npp(a2) );
4649 mgc = ( mod_gzip_conf * ) cfg;
4651 #ifdef MOD_GZIP_DEBUG1
4652 mod_gzip_printf( "%s: mgc->loc = [%s]", cn, npp(mgc->loc));
4653 mod_gzip_printf( "%s: srv->is_virtual = %ld", cn, (long)srv->is_virtual );
4654 mod_gzip_printf( "%s: srv->server_hostname = [%s]", cn, npp(srv->server_hostname));
4655 mod_gzip_printf( "%s: mgc->cmode = %ld", cn, (long) mgc->cmode );
4658 return( mod_gzip_imap_add_item( parms, mgc, a1, a2, 1 ) );
4662 mod_gzip_set_item_exclude( cmd_parms *parms, void *cfg, char *a1, char *a2 )
4667 #ifdef MOD_GZIP_DEBUG1
4668 server_rec *srv = parms->server;
4669 char cn[]="mod_gzip_set_item_exclude()";
4672 #ifdef MOD_GZIP_DEBUG1
4673 mod_gzip_server_now = srv;
4674 mod_gzip_printf( " ");
4675 mod_gzip_printf( "%s: Entry", cn );
4676 mod_gzip_printf( "%s: a1=[%s]", cn, npp(a1));
4677 mod_gzip_printf( "%s: a2=[%s]", cn, npp(a2));
4682 mgc = ( mod_gzip_conf * ) cfg;
4684 #ifdef MOD_GZIP_DEBUG1
4685 mod_gzip_printf( "%s: mgc->loc = [%s]", cn, npp(mgc->loc));
4686 mod_gzip_printf( "%s: srv->is_virtual = %ld", cn, (long)srv->is_virtual );
4687 mod_gzip_printf( "%s: srv->server_hostname = [%s]", cn, npp(srv->server_hostname));
4688 mod_gzip_printf( "%s: mgc->cmode = %ld", cn, (long) mgc->cmode );
4691 return( mod_gzip_imap_add_item( parms, mgc, a1, a2, 0 ) );
4694 static void *mod_gzip_create_dconfig(
4700 char *dname = dirspec;
4702 cfg = (mod_gzip_conf *) ap_pcalloc(p, sizeof(mod_gzip_conf));
4704 cfg->cmode = MOD_GZIP_CONFIG_MODE_DIRECTORY;
4706 dname = (dname != NULL) ? dname : "";
4708 cfg->loc = ap_pstrcat(p, "DIR(", dname, ")", NULL);
4710 mod_gzip_set_defaults1( (mod_gzip_conf *) cfg );
4712 return (void *) cfg;
4715 static void *mod_gzip_merge_dconfig(
4721 mod_gzip_conf *merged_config = (mod_gzip_conf *) ap_pcalloc(p, sizeof(mod_gzip_conf));
4722 mod_gzip_conf *pconf = (mod_gzip_conf *) parent_conf;
4723 mod_gzip_conf *nconf = (mod_gzip_conf *) newloc_conf;
4727 ( mod_gzip_conf * ) merged_config,
4728 ( mod_gzip_conf * ) pconf,
4729 ( mod_gzip_conf * ) nconf
4732 return (void *) merged_config;
4735 static void *mod_gzip_create_sconfig(
4741 char *sname = s->server_hostname;
4743 #ifdef MOD_GZIP_DEBUG1
4744 mod_gzip_server_now = s;
4747 cfg = (mod_gzip_conf *) ap_pcalloc(p, sizeof(mod_gzip_conf));
4749 cfg->cmode = MOD_GZIP_CONFIG_MODE_SERVER;
4751 sname = (sname != NULL) ? sname : "";
4753 cfg->loc = ap_pstrcat(p, "SVR(", sname, ")", NULL);
4755 mod_gzip_set_defaults1( (mod_gzip_conf *) cfg );
4757 return (void *) cfg;
4760 static void *mod_gzip_merge_sconfig(
4766 mod_gzip_conf *merged_config = (mod_gzip_conf *) ap_pcalloc(p, sizeof(mod_gzip_conf));
4767 mod_gzip_conf *pconf = (mod_gzip_conf *) parent_conf;
4768 mod_gzip_conf *nconf = (mod_gzip_conf *) newloc_conf;
4772 ( mod_gzip_conf * ) merged_config,
4773 ( mod_gzip_conf * ) pconf,
4774 ( mod_gzip_conf * ) nconf
4777 return (void *) merged_config;
4780 char mod_gzip_command_no_longer_supported[] =
4781 "Configuration directive no longer supported.";
4784 mod_gzip_obsolete_command( cmd_parms *parms, void *cfg, char *arg )
4786 return mod_gzip_command_no_longer_supported;
4789 static const command_rec mod_gzip_cmds[] =
4791 {"mod_gzip_on", mod_gzip_set_is_on, NULL, OR_OPTIONS, TAKE1,
4792 "Yes=mod_gzip will handle requests. No=mod_gzip is disabled."},
4793 {"mod_gzip_add_header_count", mod_gzip_set_add_header_count, NULL, OR_OPTIONS, TAKE1,
4794 "Yes=Add header byte counts to Common Log Format output total(s)."},
4795 {"mod_gzip_keep_workfiles", mod_gzip_set_keep_workfiles, NULL, OR_OPTIONS, TAKE1,
4796 "Yes=Keep any work files used. No=Automatically delete any work files used."},
4797 {"mod_gzip_dechunk", mod_gzip_set_dechunk, NULL, OR_OPTIONS, TAKE1,
4798 "Yes=Allow removal of 'Transfer-encoding: chunked' when necessary."},
4799 {"mod_gzip_min_http", mod_gzip_set_min_http, NULL, OR_OPTIONS, TAKE1,
4800 "Minimum HTTP protocol value to support. 1000 = HTTP/1.0 1001 = HTTP/1.1"},
4801 {"mod_gzip_minimum_file_size", mod_gzip_set_minimum_file_size, NULL, OR_OPTIONS, TAKE1,
4802 "Minimum size ( bytes ) of a file eligible for compression"},
4803 {"mod_gzip_maximum_file_size", mod_gzip_set_maximum_file_size, NULL, OR_OPTIONS, TAKE1,
4804 "Maximum size ( bytes ) of a file eligible for compression"},
4805 {"mod_gzip_maximum_inmem_size", mod_gzip_set_maximum_inmem_size, NULL, OR_OPTIONS, TAKE1,
4806 "Maximum size ( bytes ) to use for in-memory compression."},
4807 {"mod_gzip_temp_dir", mod_gzip_set_temp_dir, NULL, OR_OPTIONS, TAKE1,
4808 "The directory to use for work files and compression cache"},
4809 {"mod_gzip_item_include", mod_gzip_set_item_include, NULL, OR_OPTIONS, TAKE2,
4810 "\r\nARG1=[mime,handler,file,uri,reqheader,rspheader] \r\nARG2=[Name of item to INCLUDE in list of things that should be compressed]"},
4811 {"mod_gzip_item_exclude", mod_gzip_set_item_exclude, NULL, OR_OPTIONS, TAKE2,
4812 "\r\nARG1=[mime,handler,file,uri,reqheader,rspheader] \r\nARG2=[Name of item to EXCLUDE from list of things that should be compressed]"},
4813 {"mod_gzip_add_vinfo", mod_gzip_obsolete_command, NULL, OR_OPTIONS, TAKE1,
4814 mod_gzip_command_no_longer_supported },
4815 {"mod_gzip_do_static_files", mod_gzip_obsolete_command, NULL, OR_OPTIONS, TAKE1,
4816 mod_gzip_command_no_longer_supported },
4817 {"mod_gzip_do_cgi", mod_gzip_obsolete_command, NULL, OR_OPTIONS, TAKE1,
4818 mod_gzip_command_no_longer_supported },
4819 {"mod_gzip_verbose_debug", mod_gzip_obsolete_command, NULL, OR_OPTIONS, TAKE1,
4820 mod_gzip_command_no_longer_supported },
4821 {"mod_gzip_post_on", mod_gzip_obsolete_command, NULL, OR_OPTIONS, TAKE1,
4822 mod_gzip_command_no_longer_supported },
4823 #ifdef MOD_GZIP_COMMAND_VERSION_USED
4824 {"mod_gzip_command_version", mod_gzip_set_command_version, NULL, OR_OPTIONS, TAKE1,
4825 "User defined pickup string to use for mod_gzip version command."},
4827 #ifdef MOD_GZIP_CAN_NEGOTIATE
4828 {"mod_gzip_can_negotiate", mod_gzip_set_can_negotiate, NULL, OR_OPTIONS, TAKE1,
4829 "Yes=Negotiate/send static compressed versions of files No=Do not negotiate."},
4834 static const handler_rec mod_gzip_handlers[] =
4836 {"mod_gzip_handler", mod_gzip_handler},
4837 {CGI_MAGIC_TYPE, mod_gzip_handler},
4838 {"cgi-script", mod_gzip_handler},
4839 {"*", mod_gzip_handler},
4843 module MODULE_VAR_EXPORT gzip_module =
4845 STANDARD_MODULE_STUFF,
4847 mod_gzip_create_dconfig,
4848 mod_gzip_merge_dconfig,
4849 mod_gzip_create_sconfig,
4850 mod_gzip_merge_sconfig,
4857 mod_gzip_type_checker,
4867 int main(int argc, char *argv[])
4869 ExitThread(TSR_THREAD, 0);
4879 #ifdef MOD_GZIP_DEBUG1
4880 char cn[]="mod_gzip_send()";
4883 int bytes_to_send = 0;
4885 long bytes_left = buflen;
4886 long total_bytes_sent = 0;
4891 #ifdef MOD_GZIP_DEBUG1
4892 #ifdef MOD_GZIP_DEBUG1_SEND1
4893 mod_gzip_printf("%s: Entry...",cn);
4894 mod_gzip_printf("%s: buf = %ld",cn,(long)buf);
4895 mod_gzip_printf("%s: buflen = %ld",cn,(long)buflen);
4896 mod_gzip_printf("%s: r = %ld",cn,(long)r);
4900 if ( !buf ) return 0;
4901 if ( !buflen ) return 0;
4906 if ( bytes_left <= 0 )
4911 bytes_to_send = p1maxlen;
4913 if ( bytes_to_send > bytes_left )
4915 bytes_to_send = bytes_left;
4918 #ifdef MOD_GZIP_DEBUG1
4919 #ifdef MOD_GZIP_DEBUG1_SEND1
4920 mod_gzip_printf("%s: Call ap_rwrite(bytes_to_send=%d)...",cn,bytes_to_send);
4931 #ifdef MOD_GZIP_DEBUG1
4932 #ifdef MOD_GZIP_DEBUG1_SEND1
4933 mod_gzip_printf("%s: Back ap_rwrite(bytes_to_send=%d)...",cn,bytes_to_send);
4934 mod_gzip_printf("%s: bytes_sent = %d",cn,bytes_sent);
4938 if ( bytes_sent > 0 )
4940 total_bytes_sent += bytes_sent;
4941 bytes_left -= bytes_sent;
4950 #ifdef MOD_GZIP_DEBUG1
4951 mod_gzip_printf("%s: Done > return( total_bytes_sent = %ld ) >",
4952 cn, (long) total_bytes_sent);
4955 return( total_bytes_sent );
4958 int mod_gzip_redir1_handler(
4960 mod_gzip_conf *dconf
4963 #ifdef MOD_GZIP_DEBUG1
4964 char cn[]="mod_gzip_redir1_handler()";
4970 int save_socket = 0;
4972 int dconf__keep_workfiles = 0;
4973 char *dconf__temp_dir = 0;
4975 char tempfile_redir1[ MOD_GZIP_MAX_PATH_LEN + 2 ];
4981 #ifdef MOD_GZIP_DEBUG1
4982 mod_gzip_printf( " " );
4983 mod_gzip_printf( "%s: Entry...",cn);
4986 tempfile_redir1[0] = 0;
4988 dconf__keep_workfiles = dconf->keep_workfiles;
4989 dconf__temp_dir = dconf->temp_dir;
4991 #ifdef MOD_GZIP_DEBUG1
4992 mod_gzip_printf( "%s: r->proxyreq = %d", cn, (int) r->proxyreq );
4993 mod_gzip_printf( "%s: dconf__keep_workfiles = %d", cn, (int) dconf__keep_workfiles );
4994 mod_gzip_printf( "%s: dconf__temp_dir = [%s]", cn, npp(dconf__temp_dir));
4997 ap_table_setn( r->notes,
4998 "mod_gzip_running",ap_pstrdup(r->pool,"1"));
5000 #ifdef MOD_GZIP_DEBUG1
5001 mod_gzip_printf( "%s: r->notes->mod_gzip_running set to '1'",cn);
5006 #ifdef MOD_GZIP_DEBUG1
5007 mod_gzip_printf( "%s: Saving 'r->connection->client->fd' value to 'save_socket' stack variable...",cn);
5010 save_socket = (int) r->connection->client->fd;
5012 #ifdef MOD_GZIP_DEBUG1
5013 mod_gzip_printf( "%s: 'r->connection->client->fd' saved to 'save_socket' stack variable",cn);
5016 #ifdef MOD_GZIP_DEBUG1
5017 mod_gzip_printf( "%s: Creating 'tempfile_redir1' string now...",cn);
5020 mod_gzip_create_unique_filename(
5022 (char *) tempfile_redir1,
5023 MOD_GZIP_MAX_PATH_LEN
5026 #ifdef MOD_GZIP_DEBUG1
5027 mod_gzip_printf( "%s: tempfile_redir1 = [%s]",cn,npp(tempfile_redir1));
5028 mod_gzip_printf( "%s: Call mod_gzip_dyn1_getfdo1(%s)...",cn,npp(tempfile_redir1));
5031 status = mod_gzip_dyn1_getfdo1( r, tempfile_redir1 );
5033 #ifdef MOD_GZIP_DEBUG1
5034 mod_gzip_printf( "%s: Back mod_gzip_dyn1_getfdo1(%s)...",cn,npp(tempfile_redir1));
5039 #ifdef MOD_GZIP_DEBUG1
5040 mod_gzip_printf( "%s: Back mod_gzip_dyn1_getfdo1(%s)...",cn,npp(tempfile_redir1));
5041 mod_gzip_printf( "%s: .... mod_gzip_dyn1_getfdo1() call FAILED",cn);
5042 mod_gzip_printf( "%s: status = %d",cn,status);
5046 ap_log_error( "",0,APLOG_NOERRNO|APLOG_WARNING, r->server,
5047 "mod_gzip: ERROR: CreateFile(%s) in dyn1_getfdo1",tempfile_redir1);
5049 ap_log_error( "",0,APLOG_NOERRNO|APLOG_WARNING, r->server,
5050 "mod_gzip: ERROR: fopen(%s) in dyn1_getfdo1",tempfile_redir1);
5053 ap_log_error( "",0,APLOG_NOERRNO|APLOG_WARNING, r->server,
5054 "mod_gzip: ERROR: %s",mod_gzip_check_permissions);
5056 #ifdef MOD_GZIP_USES_APACHE_LOGS
5057 ap_table_setn( r->notes,
5058 "mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:DYN1_OPENFAIL_BODY"));
5061 #ifdef MOD_GZIP_DEBUG1
5062 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
5069 #ifdef MOD_GZIP_DEBUG1
5070 mod_gzip_printf( "%s: Back mod_gzip_dyn1_getfdo1(%s)...",cn,npp(tempfile_redir1));
5071 mod_gzip_printf( "%s: .... mod_gzip_dyn1_getfdo1() call SUCCEEDED",cn);
5077 #ifdef MOD_GZIP_DEBUG1
5078 mod_gzip_printf( "%s: WIN32: Saves/restores B_SOCKET flag as well...",cn);
5079 mod_gzip_printf( "%s: WIN32: Saving 'r->connection->client->flags' value to 'save_flags' stack variable...",cn);
5082 save_flags = (int) r->connection->client->flags;
5084 #ifdef MOD_GZIP_DEBUG1
5086 mod_gzip_printf( "%s: WIN32: r->connection->client->flags = %ld", cn, (long) r->connection->client->flags );
5088 if ( r->connection->client->flags & B_SOCKET )
5090 mod_gzip_printf( "%s: WIN32: r->connection->client->flags & B_SOCKET is TRUE",cn);
5094 mod_gzip_printf( "%s: WIN32: r->connection->client->flags & B_SOCKET is FALSE",cn);
5099 if ( r->connection->client->flags & B_SOCKET )
5101 #ifdef MOD_GZIP_DEBUG1
5102 mod_gzip_printf( "%s: WIN32: Clearing B_SOCKET flag now....", cn);
5103 mod_gzip_printf( "%s: WIN32: r->connection->client->flags &= ~B_SOCKET", cn);
5106 r->connection->client->flags &= ~B_SOCKET;
5110 #ifdef MOD_GZIP_DEBUG1
5111 mod_gzip_printf( "%s: WIN32: B_SOCKET flag not present...", cn);
5112 mod_gzip_printf( "%s: WIN32: No action was taken...", cn);
5116 #ifdef MOD_GZIP_DEBUG1
5118 mod_gzip_printf( "%s: WIN32: r->connection->client->flags = %ld", cn, (long) r->connection->client->flags );
5120 if ( r->connection->client->flags & B_SOCKET )
5122 mod_gzip_printf( "%s: WIN32: r->connection->client->flags & B_SOCKET is TRUE",cn);
5126 mod_gzip_printf( "%s: WIN32: r->connection->client->flags & B_SOCKET is FALSE",cn);
5133 #ifdef MOD_GZIP_DEBUG1
5134 mod_gzip_printf( "%s: Call ap_internal_redirect(r->unparsed_uri=[%s])...",
5135 cn,npp(r->unparsed_uri));
5136 mod_gzip_printf( " " );
5139 ap_internal_redirect( r->unparsed_uri, r );
5141 #ifdef MOD_GZIP_DEBUG1
5142 mod_gzip_printf( " " );
5143 mod_gzip_printf( "%s: Back ap_internal_redirect(r->unparsed_uri=[%s])...",
5144 cn,npp(r->unparsed_uri));
5147 #ifdef MOD_GZIP_DEBUG1
5148 mod_gzip_printf( "%s: Before... ap_rflush()...",cn);
5149 mod_gzip_printf( "%s: r->connection->client->outcnt = %ld",
5150 cn,(long) r->connection->client->outcnt );
5151 mod_gzip_printf( "%s: r->connection->client->bytes_sent = %ld",
5152 cn,(long) r->connection->client->bytes_sent );
5153 mod_gzip_printf( "%s: Call..... ap_rflush()...",cn);
5158 #ifdef MOD_GZIP_DEBUG1
5159 mod_gzip_printf( "%s: Back..... ap_rflush()...",cn);
5160 mod_gzip_printf( "%s: After.... ap_rflush()...",cn);
5161 mod_gzip_printf( "%s: r->connection->client->outcnt = %ld",
5162 cn,(long) r->connection->client->outcnt );
5163 mod_gzip_printf( "%s: r->connection->client->bytes_sent = %ld",
5164 cn,(long) r->connection->client->bytes_sent );
5169 if ( r->connection->client->hFH )
5171 #ifdef MOD_GZIP_DEBUG1
5172 mod_gzip_printf( "%s: WIN32: Call CloseHandle( r->connection->client->hFH )...",cn);
5175 CloseHandle( r->connection->client->hFH );
5177 #ifdef MOD_GZIP_DEBUG1
5178 mod_gzip_printf( "%s: WIN32: Back CloseHandle( r->connection->client->hFH )...",cn);
5181 r->connection->client->hFH = 0;
5183 #ifdef MOD_GZIP_DEBUG1
5184 mod_gzip_printf( "%s: WIN32: r->connection->client->hFH reset to ZERO",cn);
5189 #ifdef MOD_GZIP_DEBUG1
5190 mod_gzip_printf( "%s: WIN32: r->connection->client->hFH already closed.",cn);
5191 mod_gzip_printf( "%s: WIN32: No CloseFile() call was necessary at this point.",cn);
5197 #ifdef MOD_GZIP_DEBUG1
5198 mod_gzip_printf( "%s: UNIX: Call close( r->connection->client->fd )...",cn);
5201 close( r->connection->client->fd );
5203 #ifdef MOD_GZIP_DEBUG1
5204 mod_gzip_printf( "%s: UNIX: Back close( r->connection->client->fd )...",cn);
5209 r->connection->client->fd = (int) save_socket;
5211 #ifdef MOD_GZIP_DEBUG1
5212 mod_gzip_printf( "%s: 'r->connection->client->fd' RESTORED from 'save_socket' stack variable",cn);
5217 r->connection->client->flags = (int) save_flags;
5219 #ifdef MOD_GZIP_DEBUG1
5220 mod_gzip_printf( "%s: WIN32: r->connection->client->flags RESTORED from 'save_flags' stack variable...",cn);
5223 #ifdef MOD_GZIP_DEBUG1
5225 mod_gzip_printf( "%s: WIN32: r->connection->client->flags = %ld", cn, (long) r->connection->client->flags );
5227 if ( r->connection->client->flags & B_SOCKET )
5229 mod_gzip_printf( "%s: WIN32: r->connection->client->flags & B_SOCKET is TRUE",cn);
5233 mod_gzip_printf( "%s: WIN32: r->connection->client->flags & B_SOCKET is FALSE",cn);
5240 r->connection->client->bytes_sent = 0;
5241 r->connection->client->outcnt = 0;
5243 #ifdef MOD_GZIP_DEBUG1
5244 mod_gzip_printf( "%s: Connection byte counts have been RESET...",cn);
5245 mod_gzip_printf( "%s: r->connection->client->outcnt = %ld",
5246 cn, r->connection->client->outcnt );
5247 mod_gzip_printf( "%s: r->connection->client->bytes_sent = %ld",
5248 cn, r->connection->client->bytes_sent );
5250 mod_gzip_printf( "%s: r->bytes_sent = %ld",cn,(long)r->bytes_sent);
5254 mod_gzip_printf( "%s: r->next->bytes_sent = %ld",cn,(long)r->next->bytes_sent);
5258 mod_gzip_printf( "%s: r->prev->bytes_sent = %ld",cn,(long)r->prev->bytes_sent);
5263 #ifdef MOD_GZIP_DEBUG1
5264 mod_gzip_printf( "%s: Call mod_gzip_sendfile2(tempfile_redir1=[%s])...",
5265 cn, npp(tempfile_redir1));
5275 #ifdef MOD_GZIP_DEBUG1
5277 mod_gzip_printf( "%s: Back mod_gzip_sendfile2(tempfile_redir1=[%s])...",
5278 cn, npp(tempfile_redir1));
5282 mod_gzip_printf( "%s: rc = %d OK", cn, (int) rc);
5284 else if ( rc == DECLINED )
5286 mod_gzip_printf( "%s: rc = %d DECLINED", cn, (int) rc );
5290 mod_gzip_printf( "%s: rc = %d ( HTTP ERROR CODE? )", cn, (int) rc );
5297 #ifdef MOD_GZIP_DEBUG1
5298 mod_gzip_printf( "%s: mod_gzip_sendfile2() call FAILED",cn);
5303 #ifdef MOD_GZIP_DEBUG1
5304 mod_gzip_printf( "%s: mod_gzip_sendfile2() call SUCCEEDED",cn);
5308 #ifdef MOD_GZIP_DEBUG1
5309 mod_gzip_printf( "%s: r->connection->client->outcnt = %ld",
5310 cn, r->connection->client->outcnt );
5311 mod_gzip_printf( "%s: r->connection->client->bytes_sent = %ld",
5312 cn, r->connection->client->bytes_sent );
5313 mod_gzip_printf( "%s: Sum of the 2..................... = %ld",
5314 cn, r->connection->client->outcnt +
5315 r->connection->client->bytes_sent );
5318 #ifdef MOD_GZIP_DEBUG1
5319 mod_gzip_printf( "%s: FINAL CLEANUP...",cn);
5320 mod_gzip_printf( "%s: dconf__keep_workfiles = %d",
5321 cn, dconf__keep_workfiles );
5324 if ( !dconf__keep_workfiles )
5326 #ifdef MOD_GZIP_DEBUG1
5327 mod_gzip_printf( "%s: Call mod_gzip_delete_file(tempfile_redir1=[%s])...",
5328 cn, npp(tempfile_redir1));
5331 mod_gzip_delete_file( r, tempfile_redir1 );
5333 #ifdef MOD_GZIP_DEBUG1
5334 mod_gzip_printf( "%s: Back mod_gzip_delete_file(tempfile_redir1=[%s])...",
5335 cn, npp(tempfile_redir1));
5339 #ifdef MOD_GZIP_DEBUG1
5340 mod_gzip_printf( "%s: Exit > return( OK ) >",cn,(int)rc);
5346 int mod_gzip_dyn1_getfdo1(
5353 int open_failed = 0;
5359 #ifdef MOD_GZIP_DEBUG1
5360 char cn[]="mod_gzip_dyn1_getfdo1()";
5363 #ifdef MOD_GZIP_DEBUG1
5364 mod_gzip_printf( "%s: Entry...",cn);
5365 mod_gzip_printf( "%s: filename=[%s]",cn,npp(filename));
5368 #ifdef MOD_GZIP_DYN1_GETFDO1_ERROR_TEST1
5371 #ifdef MOD_GZIP_DEBUG1
5372 mod_gzip_printf( "%s: ** TEST ** 'status' forced to 'DECLINED'...",cn);
5379 #ifdef MOD_GZIP_DEBUG1
5380 mod_gzip_printf( "%s: WIN32: Call CreateFile(filename=[%s],GENERIC_WRITE, FILE_SHARE_WRITE )...",
5391 FILE_ATTRIBUTE_NORMAL,
5395 if ( temp_fdhan == INVALID_HANDLE_VALUE )
5402 #ifdef MOD_GZIP_DEBUG1
5403 mod_gzip_printf( "%s: UNIX: Call open(filename=[%s],O_RDWR|O_CREAT|O_TRUNC,S_IRWXU)...",
5407 if ((temp_fd = open(filename,O_RDWR|O_CREAT|O_TRUNC,S_IRWXU)) == -1)
5416 #ifdef MOD_GZIP_DEBUG1
5419 mod_gzip_printf( "%s: WIN32: .... CreateFile() call FAILED", cn );
5420 mod_gzip_printf( "%s: WIN32: temp_fd = %d", cn, temp_fd );
5422 mod_gzip_printf( "%s: UNIX: .... open() call FAILED", cn );
5423 mod_gzip_printf( "%s: UNIX: temp_fd = %d", cn, temp_fd );
5428 ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r,
5429 "mod_gzip: ERROR: Couldn't create a file descriptor at HTTP : %s", filename);
5431 #ifdef MOD_GZIP_DEBUG1
5432 mod_gzip_printf( "%s: Exit > return( HTTP_INTERNAL_SERVER_ERROR ) >",cn);
5435 return HTTP_INTERNAL_SERVER_ERROR;
5438 #ifdef MOD_GZIP_DEBUG1
5442 mod_gzip_printf( "%s: WIN32: .... CreateFile() call SUCCEEDED", cn );
5443 mod_gzip_printf( "%s: WIN32: temp_fdhan = (WIN32 HANDLE) %d", cn, (int) temp_fdhan );
5447 mod_gzip_printf( "%s: UNIX: .... open() call SUCCEEDED", cn );
5448 mod_gzip_printf( "%s: UNIX: temp_fd = (UNIX int) %d", cn, temp_fd );
5456 r->connection->client->fd = (int) temp_fdhan;
5457 r->connection->client->hFH = (HANDLE) temp_fdhan;
5459 #ifdef MOD_GZIP_DEBUG1
5461 mod_gzip_printf( "%s: WIN32: r->connection->client->fd = (int ) %d", cn, (int ) r->connection->client->fd );
5462 mod_gzip_printf( "%s: WIN32: r->connection->client->hFH = (HANDLE) %ld", cn, (long) r->connection->client->hFH );
5463 mod_gzip_printf( "%s: WIN32: r->connection->client->flags = %ld", cn, (long) r->connection->client->flags );
5465 if ( r->connection->client->flags & B_SOCKET )
5467 mod_gzip_printf( "%s: WIN32: r->connection->client->flags & B_SOCKET is TRUE",cn);
5471 mod_gzip_printf( "%s: WIN32: r->connection->client->flags & B_SOCKET is FALSE",cn);
5478 r->connection->client->fd = temp_fd;
5480 #ifdef MOD_GZIP_DEBUG1
5481 mod_gzip_printf( "%s: UNIX: r->connection->client->fd = %d", cn, r->connection->client->fd );
5486 #ifdef MOD_GZIP_DEBUG1
5487 mod_gzip_printf( "%s: Exit > return( status=%d ) >", cn, status );
5493 long mod_gzip_sendfile1(
5495 char *input_filename,
5497 long starting_offset
5505 long total_byteswritten=0;
5507 #define MOD_GZIP_SENDFILE1_BUFFER_SIZE 4096
5508 char tmp[ MOD_GZIP_SENDFILE1_BUFFER_SIZE + 16 ];
5510 #ifdef MOD_GZIP_DEBUG1
5511 char cn[]="mod_gzip_sendfile1()";
5514 #ifdef MOD_GZIP_DEBUG1
5515 mod_gzip_printf( "%s: Entry...",cn);
5516 mod_gzip_printf( "%s: r = %ld", cn,(long)r);
5517 mod_gzip_printf( "%s: input_filename = [%s]",cn,npp(input_filename));
5518 mod_gzip_printf( "%s: ifh_passed = %ld", cn,(long) ifh_passed);
5519 mod_gzip_printf( "%s: starting_offset = %ld", cn,(long) starting_offset);
5523 if ( ( !ifh_passed ) && ( !input_filename ) ) return 0;
5527 #ifdef MOD_GZIP_DEBUG1
5528 mod_gzip_printf( "%s: 'ifh_passed' is valid",cn);
5529 mod_gzip_printf( "%s: 'ifh' set to 'ifh_passed'...",cn);
5530 mod_gzip_printf( "%s: fopen() was NOT called...",cn);
5537 #ifdef MOD_GZIP_DEBUG1
5538 mod_gzip_printf( "%s: 'ifh_passed' was NULL...",cn);
5539 mod_gzip_printf( "%s: Call fopen(%s)...",cn,npp(input_filename));
5542 ifh = fopen( input_filename, "rb" );
5546 #ifdef MOD_GZIP_DEBUG1
5547 mod_gzip_printf( "%s: .... fopen() FAILED",cn);
5548 mod_gzip_printf( "%s: Exit > return( 0 ) >",cn);
5554 #ifdef MOD_GZIP_DEBUG1
5555 mod_gzip_printf( "%s: .... fopen() SUCCEEDED",cn);
5559 if ( starting_offset > -1 )
5561 #ifdef MOD_GZIP_DEBUG1
5562 mod_gzip_printf( "%s: Call fseek(ifh,starting_offset=%ld,0)...",
5563 cn, (long) starting_offset );
5566 rc = fseek( ifh, starting_offset, 0 );
5570 #ifdef MOD_GZIP_DEBUG1
5571 mod_gzip_printf( "%s: .... fseek() FAILED",cn);
5572 mod_gzip_printf( "%s: Exit > return( 0 ) >",cn);
5577 #ifdef MOD_GZIP_DEBUG1
5580 mod_gzip_printf( "%s: .... fseek() SUCCEEDED",cn);
5585 #ifdef MOD_GZIP_DEBUG1
5586 mod_gzip_printf( "%s: sizeof( tmp ) = %d",cn,sizeof(tmp));
5587 mod_gzip_printf( "%s: MOD_GZIP_SENDFILE1_BUFFER_SIZE = %d",
5588 cn,(int)MOD_GZIP_SENDFILE1_BUFFER_SIZE);
5589 mod_gzip_printf( "%s: Sending file contents now...",cn);
5594 bytesread = fread( tmp, 1, MOD_GZIP_SENDFILE1_BUFFER_SIZE, ifh );
5596 #ifdef MOD_GZIP_DEBUG1
5597 #ifdef MOD_GZIP_DEBUG1_SENDFILE1
5598 mod_gzip_printf( "%s: Back fread(): bytesread=%d",cn,bytesread);
5602 if ( bytesread < 1 ) break;
5604 byteswritten = (int)
5605 mod_gzip_send( tmp, bytesread, r );
5607 if ( byteswritten > 0 )
5609 total_byteswritten += byteswritten;
5612 #ifdef MOD_GZIP_DEBUG1
5613 #ifdef MOD_GZIP_DEBUG1_SENDFILE1
5614 mod_gzip_printf( "%s: byteswritten = %d",cn,(int)byteswritten);
5618 if ( byteswritten != bytesread )
5623 #if defined(WIN32) || defined(NETWARE)
5624 err = WSAGetLastError();
5630 #ifdef MOD_GZIP_DEBUG1
5631 mod_gzip_printf( "%s: TRANSMIT ERROR: bytesread=%d byteswritten=%d err=%d",
5632 cn,(int)bytesread,(int)byteswritten,(int)err );
5635 #ifdef MOD_GZIP_DEBUG1
5636 mod_gzip_printf( "%s: Breaking out of transmit loop early...",cn);
5643 #ifdef MOD_GZIP_DEBUG1
5644 mod_gzip_printf( "%s: Done sending file contents...",cn);
5645 mod_gzip_printf( "%s: total_byteswritten = %ld",cn,total_byteswritten);
5650 #ifdef MOD_GZIP_DEBUG1
5651 mod_gzip_printf( "%s: 'ifh_passed' was NULL so close the",cn);
5652 mod_gzip_printf( "%s: input file that was opened at the",cn);
5653 mod_gzip_printf( "%s: start of this routine...",cn);
5654 mod_gzip_printf( "%s: Call fclose(%s)...",cn,npp(input_filename));
5659 #ifdef MOD_GZIP_DEBUG1
5660 mod_gzip_printf( "%s: Back fclose(%s)...",cn,npp(input_filename));
5665 #ifdef MOD_GZIP_DEBUG1
5666 mod_gzip_printf( "%s: 'ifh_passed' was VALID on entry.",cn);
5667 mod_gzip_printf( "%s: No call to fclose() was made.",cn);
5671 #ifdef MOD_GZIP_DEBUG1
5672 mod_gzip_printf( "%s: Exit > return( total_byteswritten = %ld ) >",
5673 cn, (long) total_byteswritten );
5676 return total_byteswritten;
5679 int mod_gzip_sendfile2(
5681 mod_gzip_conf *dconf,
5682 char *input_filename
5700 long total_bytes_sent=0;
5701 int valid_char_count=0;
5702 int total_bytes_left_to_copy=0;
5705 * TODO: This is a brain-teaser to solve.
5707 * gcc UNIX compiler will report the following 'ok_to_send'
5708 * flag as no longer being 'used' inside this function but
5709 * if it is removed or even commented out then Apache GP faults
5710 * at runtime when logic enters this function ( but only if
5711 * MOD_GZIP_DEBUG1 flag is OFF at compile time ?? ).
5713 * There is no 'macro' anywhere that bears this name and
5714 * there doesn't seem to be any reason for this GP fault.
5716 * If this 'ok_to_send' variable is removed everything is fine
5717 * for Win32... it is only UNIX gcc compiler that reports no
5718 * warning but will still GP fault at runtime.
5720 * It's a mystery. Can anyone solve it?
5723 int ok_to_send = 1; /* This MUST remain or UNIX 'GP faults' ??? */
5725 #ifdef MOD_GZIP_DEBUG1
5726 int total_bytes_copied=0;
5731 #define MOD_GZIP_SENDFILE2_BUFFER_SIZE 4099
5732 char tmp[ MOD_GZIP_SENDFILE2_BUFFER_SIZE + 16 ];
5734 #define MOD_GZIP_LINE_BUFFER_SIZE 2048
5735 char lbuf[ MOD_GZIP_LINE_BUFFER_SIZE + 16 ];
5737 #define MOD_GZIP_DEBUG1_SENDFILE2
5739 #ifdef MOD_GZIP_DEBUG1
5740 char cn[]="mod_gzip_sendfile2()";
5752 long bbytes_out = 0;
5753 long bbytes_total = 0;
5755 int action_flag = 0;
5756 int header_done = 0;
5764 char ct_value[ 256 ];
5767 int fields_excluded = 0;
5769 char *fieldstring = 0;
5771 char output_filename1[256];
5773 long raw_input_length = 0;
5775 #define CHUNKE_GET_HEXSTRING 1
5776 #define CHUNKE_WAIT_REAL_EOL1 2
5777 #define CHUNKE_GET_FOOTER 3
5778 #define CHUNKE_GET_REAL_DATA 4
5780 #define CHUNKE_HEXSTRING_MAXLEN 10
5782 int chunke_count = 1;
5783 char *chunke_errstr = NULL;
5784 int chunke_state = CHUNKE_GET_HEXSTRING;
5785 int chunke_nextstate = 0;
5786 long chunke_realdata_length = 0;
5787 long chunke_realdata_read = 0;
5788 int chunke_hexstring_oset = 0;
5789 char chunke_hexstring[ CHUNKE_HEXSTRING_MAXLEN + 1 ];
5791 #ifdef CHUNKE_USES_OUTPUT_BUFFER
5792 char *chunke_obufstart = lbuf;
5793 char *chunke_obuf = chunke_obufstart;
5794 int chunke_obuflen = 0;
5795 int chunke_obuflenmax = MOD_GZIP_LINE_BUFFER_SIZE;
5798 int dconf__dechunk = 0;
5799 int dconf__keep_workfiles = 0;
5800 char *dconf__temp_dir = 0;
5802 #ifdef MOD_GZIP_DEBUG1
5803 mod_gzip_printf( "%s: Entry...",cn);
5806 if ( !r ) return DECLINED;
5807 if ( !dconf ) return DECLINED;
5808 if ( !input_filename ) return DECLINED;
5810 #ifdef MOD_GZIP_DEBUG1
5811 mod_gzip_printf( "%s: r = %ld",cn,(long)r);
5812 mod_gzip_printf( "%s: r->proxyreq = %d", cn,(int) r->proxyreq );
5813 mod_gzip_printf( "%s: input_filename = [%s]",cn,npp(input_filename));
5818 dconf__dechunk = dconf->dechunk;
5819 dconf__keep_workfiles = dconf->keep_workfiles;
5820 dconf__temp_dir = dconf->temp_dir;
5822 #ifdef MOD_GZIP_DEBUG1
5823 mod_gzip_printf( "%s: dconf__dechunk = %d", cn, (int) dconf__dechunk );
5824 mod_gzip_printf( "%s: dconf__keep_workfiles = %d", cn, (int) dconf__keep_workfiles );
5825 mod_gzip_printf( "%s: dconf__temp_dir = [%s]", cn, npp(dconf__temp_dir));
5828 #ifdef MOD_GZIP_DEBUG1
5829 mod_gzip_printf( "%s: Call stat(%s)...",cn,npp(input_filename));
5832 rc = stat( input_filename, &sbuf );
5836 #ifdef MOD_GZIP_DEBUG1
5837 mod_gzip_printf( "%s: .... stat() call FAILED",cn);
5840 #ifdef MOD_GZIP_USES_APACHE_LOGS
5841 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"STAT_FAILED"));
5844 ap_log_error( APLOG_MARK,APLOG_NOERRNO|APLOG_ERR, r->server,
5845 "mod_gzip: stat(%s) in sendfile2", input_filename );
5847 ap_log_error( "",0,APLOG_NOERRNO|APLOG_ERR, r->server,
5848 "mod_gzip: %s",mod_gzip_check_permissions);
5850 #ifdef MOD_GZIP_DEBUG1
5851 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
5858 raw_input_length = (long) sbuf.st_size;
5860 #ifdef MOD_GZIP_DEBUG1
5861 mod_gzip_printf( "%s: .... stat() call SUCCEEDED",cn);
5862 mod_gzip_printf( "%s: sbuf.st_size = %ld",cn,(long)sbuf.st_size);
5863 mod_gzip_printf( "%s: raw_input_length = %ld",cn,(long)raw_input_length);
5866 if ( sbuf.st_size < 1 )
5868 #ifdef MOD_GZIP_DEBUG1
5869 mod_gzip_printf( "%s: ERROR: The input file is EMPTY",cn);
5870 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
5873 #ifdef MOD_GZIP_USES_APACHE_LOGS
5874 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"CAP_FILE_EMPTY"));
5877 ap_log_error( APLOG_MARK,APLOG_NOERRNO|APLOG_ERR, r->server,
5878 "mod_gzip: EMPTY FILE [%s] in sendfile2", input_filename );
5880 ap_log_error( "",0,APLOG_NOERRNO|APLOG_ERR, r->server,
5881 "mod_gzip: %s",mod_gzip_check_permissions);
5887 #ifdef MOD_GZIP_DEBUG1
5888 mod_gzip_printf( "%s: Call fopen(%s)...",cn,npp(input_filename));
5891 ifh = fopen( input_filename, "rb" );
5895 #ifdef MOD_GZIP_DEBUG1
5896 mod_gzip_printf( "%s: .... fopen() FAILED",cn);
5899 #ifdef MOD_GZIP_USES_APACHE_LOGS
5900 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"CAP_FOPEN_FAILED"));
5903 ap_log_error( APLOG_MARK,APLOG_NOERRNO|APLOG_ERR, r->server,
5904 "mod_gzip: fopen(%s) in sendfile2", input_filename);
5906 ap_log_error( "",0,APLOG_NOERRNO|APLOG_ERR, r->server,
5907 "mod_gzip: %s",mod_gzip_check_permissions);
5909 #ifdef MOD_GZIP_DEBUG1
5910 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
5916 #ifdef MOD_GZIP_DEBUG1
5917 mod_gzip_printf( "%s: .... fopen() SUCCEEDED",cn);
5918 mod_gzip_printf( "%s: sizeof( tmp ) = %d",cn,sizeof(tmp));
5919 mod_gzip_printf( "%s: MOD_GZIP_SENDFILE2_BUFFER_SIZE = %d",
5920 cn,(int)MOD_GZIP_SENDFILE2_BUFFER_SIZE);
5921 mod_gzip_printf( "%s: Processing header now...",cn);
5926 bytesread = fread( tmp, 1, MOD_GZIP_SENDFILE2_BUFFER_SIZE, ifh );
5928 #ifdef MOD_GZIP_DEBUG1
5929 mod_gzip_printf( "%s: HEADER: %5.5d: Back fread(): bytesread=%d",
5930 cn,linecount,bytesread);
5933 if ( bytesread < 1 ) break;
5938 for ( i=0; i<bytesread; i++ )
5946 if ( valid_char_count < 1 )
5948 #ifdef MOD_GZIP_DEBUG1
5949 mod_gzip_printf( "%s: HEADER: %5.5d: lbuf=[CR/LF]",
5963 #ifdef MOD_GZIP_DEBUG1
5964 mod_gzip_printf( "%s: HEADER: %5.5d: lbuf=[%s]",
5968 if ( linecount == 1 )
5972 while((*p3!=0)&&(*p3<33)) p3++;
5973 while((*p3!=0)&&(*p3>32)) p3++;
5974 while((*p3!=0)&&(*p3<33)) p3++;
5976 #ifdef MOD_GZIP_DEBUG1
5977 mod_gzip_printf( "%s: HEADER: %5.5d: * p3=[%s]",
5978 cn,linecount,npp(p3));
5983 resp_code = (int) atoi( p3 );
5986 #ifdef MOD_GZIP_DEBUG1
5987 mod_gzip_printf( "%s: HEADER: %5.5d: * resp_code = %d",
5988 cn,linecount,resp_code);
5992 else if ( lbuf[0] == 'T' )
5994 if ( mod_gzip_strnicmp(lbuf,"Transfer-Encoding:",18)==0)
5996 #ifdef MOD_GZIP_DEBUG1
5997 mod_gzip_printf( "%s: HEADER: %5.5d: * 'Transfer-Encoding:' seen",
6003 if ( mod_gzip_stringcontains( lbuf, "chunked" ) )
6005 #ifdef MOD_GZIP_DEBUG1
6006 mod_gzip_printf( "%s: HEADER: %5.5d: * 'Transfer-Encoding: chunked' seen",
6015 else if ( lbuf[0] == 'C' )
6017 if ( mod_gzip_strnicmp(lbuf,"Content-Encoding:",17)==0)
6019 #ifdef MOD_GZIP_DEBUG1
6020 mod_gzip_printf( "%s: HEADER: %5.5d: * 'Content-Encoding:' seen",
6027 else if ( mod_gzip_strnicmp(lbuf,"Content-Type:",13)==0)
6029 #ifdef MOD_GZIP_DEBUG1
6030 mod_gzip_printf( "%s: HEADER: %5.5d: * 'Content-Type:' seen",
6038 while((*p3!=0)&&(*p3<33)) p3++;
6039 while((*p3!=0)&&(*p3>32)) p3++;
6040 while((*p3!=0)&&(*p3<33)) p3++;
6044 mod_gzip_strcpy( ct_value, p3 );
6048 sprintf( ct_value, "%-230.230s", p3 );
6051 #ifdef MOD_GZIP_DEBUG1
6052 mod_gzip_printf( "%s: HEADER: %5.5d: * ct_value=[%s]",
6053 cn,linecount,npp(ct_value));
6058 if ( ( fields_excluded < 1 ) &&
6059 ( dconf->imap_total_isrspheader > 0 ) )
6061 #ifdef MOD_GZIP_DEBUG1
6062 mod_gzip_printf( "%s: dconf->imap_total_isrspheader = %d", cn,
6063 (int) dconf->imap_total_isrspheader );
6064 mod_gzip_printf( "%s: Checking RESPONSE header field...", cn );
6069 while((*p3!=0)&&(*p3<33)) p3++;
6070 while((*p3!=0)&&(*p3>32)) p3++;
6071 while((*p3!=0)&&(*p3<33)) p3++;
6076 #ifdef MOD_GZIP_DEBUG1
6077 mod_gzip_printf( "%s: Call mod_gzip_validate1()...",cn);
6083 (mod_gzip_conf *) dconf,
6084 NULL, /* r->filename (Not used here) */
6085 NULL, /* r->uri (Not used here) */
6086 NULL, /* r->content_type (Not used here) */
6087 NULL, /* r->handler (Not used here) */
6088 (char *) fieldkey, /* Field key */
6089 (char *) fieldstring, /* Field string */
6090 MOD_GZIP_RESPONSE /* Direction */
6093 #ifdef MOD_GZIP_DEBUG1
6094 mod_gzip_printf( "%s: Back mod_gzip_validate1()...",cn);
6095 mod_gzip_printf( "%s: field_ok = %d",cn,field_ok);
6098 if ( field_ok == MOD_GZIP_IMAP_DECLINED1 )
6108 valid_char_count = 0;
6112 if ( *p1 > 32 ) valid_char_count++;
6114 if (( p2len < MOD_GZIP_LINE_BUFFER_SIZE )&&( *p1 != 13 ))
6126 if ( header_done ) break;
6129 bbytes_total = raw_input_length - hbytes_in;
6131 #ifdef MOD_GZIP_DEBUG1
6132 mod_gzip_printf( "%s: Done processing header...",cn);
6133 mod_gzip_printf( "%s: header_done = %d",cn,header_done);
6134 mod_gzip_printf( "%s: fields_excluded = %d",cn,fields_excluded);
6135 mod_gzip_printf( "%s: bytesread = %d",cn,bytesread);
6136 mod_gzip_printf( "%s: p1len = %d",cn,p1len);
6137 mod_gzip_printf( "%s: resp_code = %d (HTTP response code)",cn,resp_code);
6138 mod_gzip_printf( "%s: hbytes_in = %ld (Total HEADER bytes read)",cn,(long)hbytes_in);
6139 mod_gzip_printf( "%s: bbytes_total = %ld (Total BODY bytes left)",cn,(long)bbytes_total);
6140 mod_gzip_printf( "%s: te_seen = %d (Transfer-Encoding:)",cn,te_seen);
6141 mod_gzip_printf( "%s: te_chunked = %d (Transfer-Encoding: chunked)",cn,te_chunked);
6142 mod_gzip_printf( "%s: ce_seen = %d (Content-Encoding:)",cn,ce_seen);
6143 mod_gzip_printf( "%s: ct_seen = %d (Content-Type:)",cn,ct_seen);
6144 mod_gzip_printf( "%s: ct_value = [%s]",cn,npp(ct_value));
6145 mod_gzip_printf( "%s: dconf__dechunk = %ld",cn,(long)dconf__dechunk);
6150 #ifdef MOD_GZIP_DEBUG1
6151 mod_gzip_printf( "%s: ERROR: 'header_done' flag is NOT SET",cn);
6152 mod_gzip_printf( "%s: No valid HTTP 'End of header' was found...",cn);
6155 #ifdef MOD_GZIP_USES_APACHE_LOGS
6156 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"NO_HTTP_EOH"));
6159 ap_log_error( APLOG_MARK,APLOG_NOERRNO|APLOG_ERR, r->server,
6160 "mod_gzip: Invalid HTTP response header for r->the_request[%s] in sendfile2", r->the_request);
6161 ap_log_error( APLOG_MARK,APLOG_NOERRNO|APLOG_ERR, r->server,
6162 "mod_gzip: Invalid HTTP response header in FILE [%s] in sendfile2",input_filename);
6164 #ifdef MOD_GZIP_DEBUG1
6165 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
6173 #ifdef MOD_GZIP_DEBUG1
6174 mod_gzip_printf( "%s: ERROR: 'resp_code' value is NOT SET",cn);
6175 mod_gzip_printf( "%s: No valid HTTP response code was found...",cn);
6178 #ifdef MOD_GZIP_USES_APACHE_LOGS
6179 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"NO_HTTP_RESP_CODE"));
6182 ap_log_error( APLOG_MARK,APLOG_NOERRNO|APLOG_ERR, r->server,
6183 "mod_gzip: No valid HTTP response code for r->the_request[%s] in sendfile2", r->the_request);
6184 ap_log_error( APLOG_MARK,APLOG_NOERRNO|APLOG_ERR, r->server,
6185 "mod_gzip: No valid HTTP response code in FILE [%s] in sendfile2",input_filename);
6187 #ifdef MOD_GZIP_DEBUG1
6188 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
6194 #ifdef MOD_GZIP_DEBUG1
6195 mod_gzip_printf( "%s: --------------------------------------------------",cn);
6196 mod_gzip_printf( "%s: Checking for various 'send as is' conditions...",cn);
6197 mod_gzip_printf( "%s: --------------------------------------------------",cn);
6200 #ifdef MOD_GZIP_USES_APACHE_LOGS
6201 mod_gzip_strcpy( lbuf, "SEND_AS_IS");
6204 if ( resp_code != 200 )
6206 #ifdef MOD_GZIP_DEBUG1
6207 mod_gzip_printf( "%s: resp_code is NOT '200'...",cn);
6208 mod_gzip_printf( "%s: Issuing send_as_is++",cn);
6213 #ifdef MOD_GZIP_USES_APACHE_LOGS
6214 mod_gzip_strcat( lbuf, ":NO_200");
6218 if ( ( !send_as_is ) && ( fields_excluded > 0 ) )
6220 #ifdef MOD_GZIP_DEBUG1
6221 mod_gzip_printf( "%s: 'fields_excluded' = %d ( More than ZERO )",
6222 cn, fields_excluded );
6223 mod_gzip_printf( "%s: Issuing send_as_is++",cn);
6228 #ifdef MOD_GZIP_USES_APACHE_LOGS
6229 mod_gzip_strcat( lbuf, ":RESPONSE_FIELD_EXCLUDED");
6233 if ( ( !send_as_is ) && ( bbytes_total < 1 ) )
6235 #ifdef MOD_GZIP_DEBUG1
6236 mod_gzip_printf( "%s: bbytes_total is less than 1",cn);
6237 mod_gzip_printf( "%s: There is no valid BODY data.",cn);
6238 mod_gzip_printf( "%s: Issuing send_as_is++",cn);
6243 #ifdef MOD_GZIP_USES_APACHE_LOGS
6244 mod_gzip_strcat( lbuf, ":NO_BODY");
6248 if ( ( !send_as_is ) && ( ( te_seen == 1 ) && ( te_chunked == 0 ) ) )
6250 #ifdef MOD_GZIP_DEBUG1
6251 mod_gzip_printf( "%s: 'Transfer-Encoding:' is present but 'type' is UNKNOWN",cn);
6252 mod_gzip_printf( "%s: Issuing send_as_is++",cn);
6257 #ifdef MOD_GZIP_USES_APACHE_LOGS
6258 mod_gzip_strcat( lbuf, ":UNKNOWN_TE_VALUE");
6262 if ( ( !send_as_is ) && ( ce_seen == 1 ) )
6264 #ifdef MOD_GZIP_DEBUG1
6265 mod_gzip_printf( "%s: 'Content-Encoding:' is already present...",cn);
6266 mod_gzip_printf( "%s: Issuing send_as_is++",cn);
6271 #ifdef MOD_GZIP_USES_APACHE_LOGS
6272 mod_gzip_strcat( lbuf, ":HAS_CE");
6276 if ( ( !send_as_is ) && ( ct_seen != 1 ) )
6278 #ifdef MOD_GZIP_DEBUG1
6279 mod_gzip_printf( "%s: 'Content-Type:' response field NOT PRESENT...",cn);
6280 mod_gzip_printf( "%s: Issuing send_as_is++",cn);
6285 #ifdef MOD_GZIP_USES_APACHE_LOGS
6286 mod_gzip_strcat( lbuf, ":NO_CONTENT_TYPE_IN_RESPONSE_HEADER");
6289 else if ( !send_as_is )
6291 #ifdef MOD_GZIP_DEBUG1
6292 mod_gzip_printf( "%s: 'Content-Type:' response field is PRESENT",cn);
6295 #ifdef MOD_GZIP_DEBUG1
6296 mod_gzip_printf( "%s: dconf->imap_total_ismime = %d", cn,
6297 (int) dconf->imap_total_ismime );
6300 if ( dconf->imap_total_ismime > 0 )
6302 #ifdef MOD_GZIP_DEBUG1
6303 mod_gzip_printf( "%s: Call mod_gzip_validate1(ct_value=[%s])...",
6310 (mod_gzip_conf *) dconf,
6311 NULL, /* r->filename (Not used here) */
6312 NULL, /* r->uri (Not used here) */
6313 ct_value, /* Content type (Used ) */
6314 NULL, /* r->handler (Not used here) */
6315 NULL, /* Field key (Not used here) */
6316 NULL, /* Field string (Not used here) */
6317 0 /* Direction (Not used here) */
6320 #ifdef MOD_GZIP_DEBUG1
6321 mod_gzip_printf( "%s: Back mod_gzip_validate1(ct_value=[%s])...",
6323 mod_gzip_printf( "%s: action_flag = %d",cn,action_flag);
6326 if ( action_flag != MOD_GZIP_IMAP_DECLINED1 )
6328 #ifdef MOD_GZIP_DEBUG1
6329 mod_gzip_printf( "%s: This 'Content-Type:' is NOT EXCLUDED",cn);
6334 #ifdef MOD_GZIP_DEBUG1
6335 mod_gzip_printf( "%s: This 'Content-Type:' is EXCLUDED",cn);
6336 mod_gzip_printf( "%s: Issuing send_as_is++",cn);
6341 #ifdef MOD_GZIP_USES_APACHE_LOGS
6342 mod_gzip_strcat( lbuf, ":RESPONSE_CONTENT_TYPE_EXCLUDED");
6348 #ifdef MOD_GZIP_DEBUG1
6349 mod_gzip_printf( "%s: --------------------------------------------------",cn);
6350 mod_gzip_printf( "%s: send_as_is = %d",cn,send_as_is);
6351 mod_gzip_printf( "%s: --------------------------------------------------",cn);
6354 if ( send_as_is > 0 )
6356 #ifdef MOD_GZIP_USES_APACHE_LOGS
6357 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,lbuf));
6360 #ifdef MOD_GZIP_DEBUG1
6361 mod_gzip_printf( "%s: Sending response 'as is'...",cn);
6362 mod_gzip_printf( "%s: Issuing 'goto mod_gzip_sendfile2_send_as_is'...",cn);
6365 goto mod_gzip_sendfile2_send_as_is;
6370 #ifdef MOD_GZIP_DEBUG1
6371 mod_gzip_printf( "%s: Call fclose(%s)...",cn, npp(input_filename));
6378 #ifdef MOD_GZIP_DEBUG1
6379 mod_gzip_printf( "%s: Back fclose(%s)...",cn,npp(input_filename));
6380 mod_gzip_printf( "%s: Call mod_gzip_encode_and_transmit()...",cn);
6384 mod_gzip_encode_and_transmit(
6395 #ifdef MOD_GZIP_DEBUG1
6396 mod_gzip_printf( "%s: Back mod_gzip_encode_and_transmit()...",cn);
6397 mod_gzip_printf( "%s: rc = %d",cn,rc);
6400 if ( rc == DECLINED )
6402 #ifdef MOD_GZIP_DEBUG1
6403 mod_gzip_printf( "%s: rc = DECLINED (FAILURE)",cn);
6404 mod_gzip_printf( "%s: Sending response 'as is'...",cn);
6405 mod_gzip_printf( "%s: Issuing 'goto mod_gzip_sendfile2_send_as_is'...",cn);
6408 goto mod_gzip_sendfile2_send_as_is;
6413 #ifdef MOD_GZIP_DEBUG1
6414 mod_gzip_printf( "%s: rc = OK (SUCCESS)",cn);
6415 mod_gzip_printf( "%s: Call goto mod_gzip_sendfile2_cleanup...",cn,rc);
6420 goto mod_gzip_sendfile2_cleanup;
6424 #ifdef MOD_GZIP_DEBUG1
6425 mod_gzip_printf( "%s: * TRANSFER ENCODING DE-CHUNKING OPTION",cn);
6426 mod_gzip_printf( "%s: dconf__dechunk = %ld",cn,(long)dconf__dechunk);
6429 if ( dconf__dechunk )
6431 #ifdef MOD_GZIP_DEBUG1
6432 mod_gzip_printf( "%s: dconf__dechunk = YES",cn);
6433 mod_gzip_printf( "%s: BODY data 'de-chunking' option is ON...",cn);
6438 #ifdef MOD_GZIP_DEBUG1
6439 mod_gzip_printf( "%s: dconf__dechunk = NO",cn);
6440 mod_gzip_printf( "%s: BODY data 'de-chunking' option is OFF...",cn);
6443 #ifdef MOD_GZIP_USES_APACHE_LOGS
6445 ap_table_setn( r->notes,"mod_gzip_result",
6446 ap_pstrdup(r->pool,"SEND_AS_IS:DECHUNK_OPTION_IS_OFF"));
6449 ap_log_error( APLOG_MARK,APLOG_NOERRNO|APLOG_ERR, r->server,
6450 "mod_gzip: DECHUNK option is OFF in sendfile2");
6452 ap_log_error( APLOG_MARK,APLOG_NOERRNO|APLOG_ERR, r->server,
6453 "mod_gzip: Cannot compress chunked response for [%s]",
6456 ap_log_error( APLOG_MARK,APLOG_NOERRNO|APLOG_ERR, r->server,
6457 "mod_gzip: ** Uncompressed responses that use 'Transfer-encoding: chunked'");
6459 ap_log_error( APLOG_MARK,APLOG_NOERRNO|APLOG_ERR, r->server,
6460 "mod_gzip: ** must be 'de-chunked' before they can be compressed." );
6462 ap_log_error( APLOG_MARK,APLOG_NOERRNO|APLOG_ERR, r->server,
6463 "mod_gzip: ** Turn DECHUNK option ON for this response category." );
6465 #ifdef MOD_GZIP_DEBUG1
6466 mod_gzip_printf( "%s: Sending response 'as is'...",cn);
6467 mod_gzip_printf( "%s: Issuing 'goto mod_gzip_sendfile2_send_as_is'...",cn);
6470 goto mod_gzip_sendfile2_send_as_is;
6473 #ifdef MOD_GZIP_DEBUG1
6474 mod_gzip_printf( "%s: De-chunking the body data now...",cn);
6477 #ifdef MOD_GZIP_DEBUG1
6478 mod_gzip_printf( "%s: Creating 'output_filename1' string now...",cn);
6481 mod_gzip_create_unique_filename(
6483 (char *) output_filename1,
6484 MOD_GZIP_MAX_PATH_LEN
6487 #ifdef MOD_GZIP_DEBUG1
6488 mod_gzip_printf( "%s: output_filename1 = [%s]",cn,npp(output_filename1));
6489 mod_gzip_printf( "%s: Call OUTPUT fopen(%s)...",cn,npp(output_filename1));
6492 ofh = fopen( output_filename1, "wb" );
6496 #ifdef MOD_GZIP_DEBUG1
6497 mod_gzip_printf( "%s: .... OUTPUT fopen() FAILED",cn);
6500 #ifdef MOD_GZIP_USES_APACHE_LOGS
6502 ap_table_setn( r->notes,"mod_gzip_result",
6503 ap_pstrdup(r->pool,"SEND_AS_IS:FOPEN_FAILED"));
6506 ap_log_error( APLOG_MARK,APLOG_NOERRNO|APLOG_ERR, r->server,
6507 "mod_gzip: fopen(%s) for OUTPUT in sendfile2", output_filename1 );
6509 ap_log_error( "",0,APLOG_NOERRNO|APLOG_ERR, r->server,
6510 "mod_gzip: %s",mod_gzip_check_permissions);
6512 #ifdef MOD_GZIP_DEBUG1
6513 mod_gzip_printf( "%s: Sending response 'as is'...",cn);
6514 mod_gzip_printf( "%s: Issuing 'goto mod_gzip_sendfile2_send_as_is'...",cn);
6517 goto mod_gzip_sendfile2_send_as_is;
6520 #ifdef MOD_GZIP_DEBUG1
6521 mod_gzip_printf( "%s: .... OUTPUT fopen() SUCCEEDED",cn);
6526 #ifdef MOD_GZIP_DEBUG1
6527 mod_gzip_printf( "%s: Call fseek(ifh,0,0)...",cn );
6530 rc = fseek( ifh, 0, 0 );
6534 #ifdef MOD_GZIP_DEBUG1
6535 mod_gzip_printf( "%s: .... fseek(ifh,0,0) FAILED",cn);
6538 #ifdef MOD_GZIP_USES_APACHE_LOGS
6540 ap_table_setn( r->notes,"mod_gzip_result",
6541 ap_pstrdup(r->pool,"SEND_AS_IS:FSEEK_FAILED"));
6544 ap_log_error( APLOG_MARK,APLOG_NOERRNO|APLOG_ERR, r->server,
6545 "mod_gzip: fseek(ifh,0,0) in sendfile2" );
6547 #ifdef MOD_GZIP_DEBUG1
6548 mod_gzip_printf( "%s: Sending response 'as is'...",cn);
6549 mod_gzip_printf( "%s: Issuing 'goto mod_gzip_sendfile2_send_as_is'...",cn);
6552 goto mod_gzip_sendfile2_send_as_is;
6554 #ifdef MOD_GZIP_DEBUG1
6557 mod_gzip_printf( "%s: .... fseek(ifh,0,0) SUCCEEDED",cn);
6561 total_bytes_left_to_copy = hbytes_in;
6563 #ifdef MOD_GZIP_DEBUG1
6564 total_bytes_copied = 0;
6565 mod_gzip_printf( "%s: Copying %ld header bytes now...",
6566 cn,(long)total_bytes_left_to_copy);
6569 while( total_bytes_left_to_copy > 0 )
6571 if ( total_bytes_left_to_copy < MOD_GZIP_SENDFILE2_BUFFER_SIZE )
6573 bytestoread = total_bytes_left_to_copy;
6577 bytestoread = MOD_GZIP_SENDFILE2_BUFFER_SIZE;
6580 bytesread = fread ( tmp, 1, bytestoread, ifh );
6581 byteswritten = fwrite( tmp, 1, bytesread, ofh );
6583 total_bytes_left_to_copy -= byteswritten;
6585 #ifdef MOD_GZIP_DEBUG1
6586 total_bytes_copied += byteswritten;
6590 #ifdef MOD_GZIP_DEBUG1
6591 mod_gzip_printf( "%s: %ld header bytes have been copied...",
6592 cn,(long)total_bytes_copied);
6599 bytesread = fread( p1, 1, MOD_GZIP_SENDFILE2_BUFFER_SIZE, ifh );
6601 #ifdef MOD_GZIP_DEBUG1
6602 mod_gzip_printf( "%s: Back fread(): bytesread=%d",cn,bytesread);
6605 if ( bytesread < 1 ) break;
6607 bbytes_in += bytesread;
6608 bytesleft = bytesread;
6612 #ifdef MOD_GZIP_DEBUG1
6613 mod_gzip_printf( "%s: 'te_chunked' flag is TRUE...",cn);
6614 mod_gzip_printf( "%s: Filtering chunked data...",cn);
6619 while ( bytesleft > 0 )
6621 switch( chunke_state )
6623 case CHUNKE_GET_HEXSTRING:
6625 if ((*sp==13)||(*sp==10)||(*sp==';'))
6627 chunke_hexstring[chunke_hexstring_oset]=0;
6629 #ifdef MOD_GZIP_CHUNKE_DIAG1
6630 mod_gzip_printf("chunke: %5.5ld chunke_hexstring=[%s]\n",
6631 chunke_count, npp(chunke_hexstring) );
6634 chunke_realdata_length = (long)
6635 strtol(chunke_hexstring,&chunke_errstr,16);
6637 #ifdef MOD_GZIP_CHUNKE_DIAG1
6638 mod_gzip_printf("chunke: %5.5ld realdata_length= 0x%X %ld\n",
6639 chunke_count, chunke_realdata_length,
6640 chunke_realdata_length );
6643 if ( chunke_realdata_length < 1 )
6645 #ifdef MOD_GZIP_CHUNKE_DIAG1
6646 mod_gzip_printf("chunke: %5.5ld END OF CHUNKED DATA\n",
6651 chunke_realdata_read = 0;
6655 if ( chunke_realdata_length == 0 )
6657 chunke_state = CHUNKE_GET_FOOTER;
6661 chunke_state = CHUNKE_GET_REAL_DATA;
6666 chunke_state = CHUNKE_WAIT_REAL_EOL1;
6668 if ( chunke_realdata_length == 0 )
6670 chunke_nextstate = CHUNKE_GET_FOOTER;
6674 chunke_nextstate = CHUNKE_GET_REAL_DATA;
6681 if ( ( chunke_hexstring_oset <
6682 CHUNKE_HEXSTRING_MAXLEN ) &&
6686 chunke_hexstring_oset++] = *sp;
6688 #ifdef MOD_GZIP_CHUNKE_DIAG1
6690 chunke_hexstring_oset ] = 0;
6694 #ifdef MOD_GZIP_CHUNKE_DIAG1
6695 mod_gzip_printf("chunke: %5.5ld chunke_hexstring is now [%s]\n",
6696 chunke_count, npp(chunke_hexstring) );
6702 case CHUNKE_WAIT_REAL_EOL1:
6706 #ifdef MOD_GZIP_CHUNKE_DIAG1
6707 mod_gzip_printf("chunke: %5.5ld Real EOL seen...\n",
6711 chunke_state = chunke_nextstate;
6716 case CHUNKE_GET_FOOTER:
6720 #ifdef MOD_GZIP_CHUNKE_DIAG1
6721 mod_gzip_printf("chunke: %5.5ld FOOTER EOL seen...\n",
6728 case CHUNKE_GET_REAL_DATA:
6730 #ifdef CHUNKE_USES_OUTPUT_BUFFER
6732 *chunke_obuf++ = *sp;
6735 if ( chunke_obuflen >= chunke_obuflenmax )
6745 if ( byteswritten > 0 )
6747 bbytes_out += byteswritten;
6750 chunke_obuf = chunke_obufstart;
6754 chunke_realdata_read++;
6758 bytestowrite = bytesleft;
6760 if ( ( chunke_realdata_read + bytesleft ) >
6761 chunke_realdata_length )
6764 chunke_realdata_length - chunke_realdata_read;
6775 if ( byteswritten > 0 )
6778 bytesleft -= byteswritten;
6779 bbytes_out += byteswritten;
6780 chunke_realdata_read += byteswritten;
6787 if ( chunke_realdata_read >=
6788 chunke_realdata_length )
6790 #ifdef CHUNKE_USES_OUTPUT_BUFFER
6792 if ( chunke_obuflen > 0 )
6802 if ( byteswritten > 0 )
6804 bbytes_out += byteswritten;
6807 chunke_obuf = chunke_obufstart;
6813 #ifdef MOD_GZIP_CHUNKE_DIAG1
6814 mod_gzip_printf("chunke: %5.5ld DONE reading CHUNK data...\n",
6816 mod_gzip_printf("chunke: %5.5ld realdata_length = %ld\n",
6817 chunke_count, chunke_realdata_length );
6818 mod_gzip_printf("chunke: %5.5ld realdata_read = %ld\n",
6819 chunke_count, chunke_realdata_read );
6820 mod_gzip_printf("chunke: %5.5ld Increasing 'chunke_count' to %d\n",
6821 chunke_count, chunke_count + 1 );
6822 mod_gzip_printf("chunke: %5.5ld Advancing to CHUNKE_WAIT_REAL_EOL1...\n",
6828 chunke_hexstring[0] = 0;
6829 chunke_hexstring_oset = 0;
6830 chunke_realdata_length = 0;
6831 chunke_realdata_read = 0;
6833 chunke_state = CHUNKE_WAIT_REAL_EOL1;
6834 chunke_nextstate = CHUNKE_GET_HEXSTRING;
6854 chunke_buffer_scan_done: ;
6857 #ifdef MOD_GZIP_CHUNKE_DIAG1
6858 mod_gzip_printf("chunke: %5.5ld Out of next buffer scan loop\n",
6860 mod_gzip_printf("chunke: %5.5ld realdata_length = %ld\n",
6861 chunke_count, chunke_realdata_length );
6862 mod_gzip_printf("chunke: %5.5ld realdata_read = %ld\n",
6863 chunke_count, chunke_realdata_read );
6864 mod_gzip_printf("chunke: %5.5ld realdata_left = %ld\n",
6865 chunke_count, chunke_realdata_length - chunke_realdata_read);
6866 mod_gzip_printf("chunke: %5.5ld Looping back for more input data...\n",
6881 if ( byteswritten > 0 )
6883 bbytes_out += byteswritten;
6886 #ifdef MOD_GZIP_DEBUG1
6887 mod_gzip_printf( "%s: byteswritten = %d",cn,(int)byteswritten);
6890 if ( byteswritten != bytesread )
6895 #if defined(WIN32) || defined(NETWARE)
6896 err = WSAGetLastError();
6902 #ifdef MOD_GZIP_DEBUG1
6903 mod_gzip_printf( "%s: TRANSMIT ERROR: bytesread=%d byteswritten=%d err=%d",
6904 cn,(int)bytesread,(int)byteswritten,(int)err );
6907 #ifdef MOD_GZIP_DEBUG1
6908 mod_gzip_printf( "%s: Breaking out of transmit loop early...",cn);
6916 if ( body_done ) break;
6919 bbytes_total = bbytes_out;
6921 #ifdef MOD_GZIP_DEBUG1
6922 mod_gzip_printf( "%s: Done processing BODY...",cn);
6923 mod_gzip_printf( "%s: Call fclose(ofh)...",cn);
6926 fclose( ofh ); ofh = 0;
6928 #ifdef MOD_GZIP_DEBUG1
6929 mod_gzip_printf( "%s: Back fclose(ofh)...",cn);
6930 mod_gzip_printf( "%s: bbytes_in = %ld (Total BODY bytes read)",cn,(long)bbytes_in);
6931 mod_gzip_printf( "%s: bbytes_out = %ld (Total BODY bytes written)",cn,(long)bbytes_out);
6932 mod_gzip_printf( "%s: bbytes_total = %ld (Same as bbytes_out)",cn,(long)bbytes_total);
6935 if ( bbytes_total > 0 )
6937 #ifdef MOD_GZIP_DEBUG1
6938 mod_gzip_printf( "%s: Call fclose(%s)...",cn, npp(input_filename));
6941 fclose( ifh ); ifh = 0;
6943 #ifdef MOD_GZIP_DEBUG1
6944 mod_gzip_printf( "%s: Back fclose(%s)...",cn, npp(input_filename));
6947 #ifdef MOD_GZIP_DEBUG1
6948 mod_gzip_printf( "%s: Call mod_gzip_encode_and_transmit()...",cn);
6952 mod_gzip_encode_and_transmit(
6963 #ifdef MOD_GZIP_DEBUG1
6964 mod_gzip_printf( "%s: Back mod_gzip_encode_and_transmit()...",cn);
6965 mod_gzip_printf( "%s: rc = %d",cn,rc);
6968 #ifdef MOD_GZIP_DEBUG1
6969 mod_gzip_printf( "%s: dconf__keep_workfiles = %d",
6970 cn, dconf__keep_workfiles );
6973 if ( !dconf__keep_workfiles )
6975 #ifdef MOD_GZIP_DEBUG1
6976 mod_gzip_printf( "%s: Call mod_gzip_delete_file(output_filename1=[%s])...",
6977 cn, npp(output_filename1));
6980 mod_gzip_delete_file( r, output_filename1 );
6982 #ifdef MOD_GZIP_DEBUG1
6983 mod_gzip_printf( "%s: Back mod_gzip_delete_file(output_filename1=[%s])...",
6984 cn, npp(output_filename1));
6988 if ( rc == DECLINED )
6990 #ifdef MOD_GZIP_DEBUG1
6991 mod_gzip_printf( "%s: rc = DECLINED (FAILURE)",cn);
6992 mod_gzip_printf( "%s: Sending response 'as is'...",cn);
6993 mod_gzip_printf( "%s: Issuing 'goto mod_gzip_sendfile2_send_as_is'...",cn);
6996 goto mod_gzip_sendfile2_send_as_is;
7001 #ifdef MOD_GZIP_DEBUG1
7002 mod_gzip_printf( "%s: rc = OK (SUCCESS)",cn);
7003 mod_gzip_printf( "%s: Call goto mod_gzip_sendfile2_cleanup...",cn,rc);
7008 goto mod_gzip_sendfile2_cleanup;
7014 #ifdef MOD_GZIP_DEBUG1
7015 mod_gzip_printf( "%s: ERROR: bbytes_total is ZERO",cn);
7016 mod_gzip_printf( "%s: ERROR: Original response must be sent 'as is'",cn);
7017 mod_gzip_printf( "%s: Issuing 'goto mod_gzip_sendfile2_send_as_is'...",cn);
7020 #ifdef MOD_GZIP_USES_APACHE_LOGS
7022 ap_table_setn( r->notes,"mod_gzip_result",
7023 ap_pstrdup(r->pool,"SEND_AS_IS:BODY_MISSING"));
7026 goto mod_gzip_sendfile2_send_as_is;
7029 mod_gzip_sendfile2_send_as_is: ;
7031 #ifdef MOD_GZIP_DEBUG1
7032 mod_gzip_printf( "%s: * SEND 'AS IS'...",cn);
7033 mod_gzip_printf( "%s: * label entry point: mod_gzip_sendfile2_send_as_is",cn);
7034 mod_gzip_printf( "%s: Sending response 'as is'...",cn);
7039 #ifdef MOD_GZIP_DEBUG1
7040 mod_gzip_printf( "%s: Input file was closed.",cn);
7041 mod_gzip_printf( "%s: Re-opening input_filename[%s]...",
7042 cn, npp(input_filename));
7045 ifh = fopen( input_filename, "rb" );
7049 #ifdef MOD_GZIP_DEBUG1
7050 mod_gzip_printf( "%s: .... fopen() FAILED",cn);
7053 ap_log_error( APLOG_MARK,APLOG_NOERRNO|APLOG_ERR, r->server,
7054 "mod_gzip: fopen(%s) on REOPEN in sendfile2", input_filename );
7056 final_rc = DECLINED;
7058 goto mod_gzip_sendfile2_cleanup;
7061 #ifdef MOD_GZIP_DEBUG1
7062 mod_gzip_printf( "%s: .... fopen() SUCCEEDED",cn);
7066 #ifdef MOD_GZIP_DEBUG1
7067 mod_gzip_printf( "%s: Call mod_gzip_sendfile1()...",cn);
7070 total_bytes_sent = (long)
7078 #ifdef MOD_GZIP_DEBUG1
7079 mod_gzip_printf( "%s: Back mod_gzip_sendfile1()...",cn);
7080 mod_gzip_printf( "%s: .... total_bytes_sent = %ld",cn,(long)total_bytes_sent);
7083 #ifdef MOD_GZIP_DEBUG1
7084 mod_gzip_printf( "%s: Call mod_gzip_flush_and_update_counts()...",cn);
7087 mod_gzip_flush_and_update_counts(
7091 total_bytes_sent - hbytes_in
7094 #ifdef MOD_GZIP_DEBUG1
7095 mod_gzip_printf( "%s: Back mod_gzip_flush_and_update_counts()...",cn);
7100 mod_gzip_sendfile2_cleanup: ;
7102 #ifdef MOD_GZIP_DEBUG1
7103 mod_gzip_printf( "%s: * FINAL CLEANUP",cn);
7104 mod_gzip_printf( "%s: * label entry point: mod_gzip_sendfile2_cleanup",cn);
7105 mod_gzip_printf( "%s: dconf__keep_workfiles = %ld",cn,(long)dconf__keep_workfiles);
7106 mod_gzip_printf( "%s: ifh = %ld (Input file handle)",cn,(long)ifh);
7111 #ifdef MOD_GZIP_DEBUG1
7112 mod_gzip_printf( "%s: Input file is still OPEN...",cn );
7113 mod_gzip_printf( "%s: Call fclose(%s)...",cn, npp(input_filename));
7116 fclose( ifh ); ifh = 0;
7118 #ifdef MOD_GZIP_DEBUG1
7119 mod_gzip_printf( "%s: Back fclose(%s)...",cn,npp(input_filename));
7122 #ifdef MOD_GZIP_DEBUG1
7125 mod_gzip_printf( "%s: Input file is already CLOSED...",cn );
7126 mod_gzip_printf( "%s: NO CALL MADE TO fclose(%s)",cn,npp(input_filename));
7130 #ifdef MOD_GZIP_DEBUG1
7131 mod_gzip_printf( "%s: Caller must delete input_filename=[%s]",
7132 cn, npp(input_filename));
7135 #ifdef MOD_GZIP_DEBUG1
7136 mod_gzip_printf( "%s: ofh_used = %ld (Output file usage flag)",cn,(long)ofh_used);
7137 mod_gzip_printf( "%s: ofh = %ld (Output file handle)",cn,(long)ofh);
7142 #ifdef MOD_GZIP_DEBUG1
7143 mod_gzip_printf( "%s: 'ofh_used' is TRUE",cn );
7148 #ifdef MOD_GZIP_DEBUG1
7149 mod_gzip_printf( "%s: Output file is still OPEN...",cn );
7150 mod_gzip_printf( "%s: Call fclose(output_filename1=[%s])...",
7151 cn, npp(output_filename1));
7154 fclose( ofh ); ofh = 0;
7156 #ifdef MOD_GZIP_DEBUG1
7157 mod_gzip_printf( "%s: Back fclose(output_filename1=[%s])...",
7158 cn, npp(output_filename1));
7161 #ifdef MOD_GZIP_DEBUG1
7164 mod_gzip_printf( "%s: 'ofh' is NULL. File is already CLOSED.",cn );
7168 if ( !dconf__keep_workfiles )
7170 #ifdef MOD_GZIP_DEBUG1
7171 mod_gzip_printf( "%s: 'dconf__keep_workfiles' is FALSE",cn );
7172 mod_gzip_printf( "%s: Call mod_gzip_delete_file(output_filename1=[%s])...",
7173 cn, npp(output_filename1));
7176 mod_gzip_delete_file( r, output_filename1 );
7178 #ifdef MOD_GZIP_DEBUG1
7179 mod_gzip_printf( "%s: Back mod_gzip_delete_file(output_filename1=[%s])...",
7180 cn, npp(output_filename1));
7184 #ifdef MOD_GZIP_DEBUG1
7187 mod_gzip_printf( "%s: 'dconf__keep_workfiles' is TRUE.",cn );
7188 mod_gzip_printf( "%s: Keeping output_filename1=[%s]",
7189 cn, npp(output_filename1));
7195 #ifdef MOD_GZIP_DEBUG1
7198 mod_gzip_printf( "%s: 'ofh_used' is FALSE",cn );
7199 mod_gzip_printf( "%s: Output file was NOT USED",cn );
7203 #ifdef MOD_GZIP_DEBUG1
7204 mod_gzip_printf( "%s: final_rc was......: %d",cn,final_rc);
7209 #ifdef MOD_GZIP_DEBUG1
7210 mod_gzip_printf( "%s: final_rc is now...: %d",cn,final_rc);
7213 #ifdef MOD_GZIP_DEBUG1
7214 mod_gzip_printf( "%s: Exit > return( final_rc = %d ) >",cn,final_rc);
7220 long mod_gzip_send_header(
7222 char *input_filename,
7226 #ifdef MOD_GZIP_DEBUG1
7227 char cn[]="mod_gzip_send_header()";
7235 int valid_char_count=0;
7237 #define MOD_GZIP_SEND_HEADER_BUFFER_SIZE 4096
7238 char tmp[ MOD_GZIP_SEND_HEADER_BUFFER_SIZE + 16 ];
7240 #define MOD_GZIP_LINE_BUFFER_SIZE 2048
7241 char lbuf[ MOD_GZIP_LINE_BUFFER_SIZE + 16 ];
7249 int send_header = 0;
7250 int header_done = 0;
7256 long hbytes_out = 0;
7258 #ifdef MOD_GZIP_DEBUG1
7259 mod_gzip_printf( "%s: Entry...",cn);
7260 mod_gzip_printf( "%s: input_filename = [%s]",cn,npp(input_filename));
7261 mod_gzip_printf( "%s: content_length = %ld", cn,(long)content_length);
7265 if ( !input_filename ) return 0;
7267 #ifdef MOD_GZIP_DEBUG1
7268 mod_gzip_printf( "%s: Call fopen(%s)...",cn,npp(input_filename));
7271 ifh = fopen( input_filename, "rb" );
7275 #ifdef MOD_GZIP_DEBUG1
7276 mod_gzip_printf( "%s: .... fopen() FAILED",cn);
7277 mod_gzip_printf( "%s: Exit > return( 0 ) >",cn);
7283 #ifdef MOD_GZIP_DEBUG1
7284 mod_gzip_printf( "%s: .... fopen() SUCCEEDED",cn);
7285 mod_gzip_printf( "%s: sizeof( tmp ) = %d",cn,sizeof(tmp));
7286 mod_gzip_printf( "%s: MOD_GZIP_SEND_HEADER_BUFFER_SIZE = %d",
7287 cn,(int)MOD_GZIP_SEND_HEADER_BUFFER_SIZE);
7288 mod_gzip_printf( "%s: Processing header now...",cn);
7295 bytesread = fread( tmp, 1, MOD_GZIP_SEND_HEADER_BUFFER_SIZE, ifh );
7297 #ifdef MOD_GZIP_DEBUG1
7298 mod_gzip_printf( "%s: HEADER: Back fread(): bytesread=%d",cn,bytesread);
7301 if ( bytesread < 1 ) break;
7306 for ( i=0; i<bytesread; i++ )
7312 if ( valid_char_count < 1 )
7318 sprintf( lbuf, "Content-Encoding: gzip" );
7320 #ifdef MOD_GZIP_DEBUG1
7321 mod_gzip_printf( "%s: HEADER: ADDING: lbuf=[%s]",cn,npp(lbuf));
7324 mod_gzip_strcat( lbuf, "\r\n" );
7328 hbytes_out += mod_gzip_send(lbuf,mod_gzip_strlen(lbuf),r);
7331 sprintf( lbuf, "Content-Length: %ld",(long)content_length);
7333 #ifdef MOD_GZIP_DEBUG1
7334 mod_gzip_printf( "%s: HEADER: ADDING: lbuf=[%s]",cn,npp(lbuf));
7337 mod_gzip_strcat( lbuf, "\r\n" );
7341 hbytes_out += mod_gzip_send(lbuf,mod_gzip_strlen(lbuf),r);
7344 #ifdef MOD_GZIP_DEBUG1
7345 mod_gzip_printf( "%s: HEADER: ADDING: lbuf=[CR/LF]",cn);
7350 hbytes_out += mod_gzip_send("\r\n",2,r);
7361 if ( lbuf[0] == 'T' )
7363 if ( mod_gzip_strnicmp(lbuf,"Transfer-Encoding:",18)==0)
7365 #ifdef MOD_GZIP_DEBUG1
7366 mod_gzip_printf( "%s: HEADER: * 'Transfer-Encoding:' seen",cn);
7371 if ( mod_gzip_stringcontains( lbuf, "chunked" ) )
7373 #ifdef MOD_GZIP_DEBUG1
7374 mod_gzip_printf( "%s: HEADER: * 'Transfer-Encoding: chunked' seen",cn);
7384 else if ( lbuf[0] == 'E' )
7386 if ( mod_gzip_strnicmp(lbuf,"ETag:",5)==0)
7393 else if ( lbuf[0] == 'C' )
7395 if ( mod_gzip_strnicmp(lbuf,"Content-Encoding:",17)==0)
7399 else if ( mod_gzip_strnicmp(lbuf,"Content-Length:",15)==0)
7407 #ifdef MOD_GZIP_DEBUG1
7408 mod_gzip_printf( "%s: HEADER: Sending lbuf=[%s]",cn,npp(lbuf));
7411 *p2++ = 13; p2len++;
7412 *p2++ = 10; p2len++;
7417 hbytes_out += mod_gzip_send( lbuf, p2len, r );
7420 #ifdef MOD_GZIP_DEBUG1
7423 #ifdef MOD_GZIP_DEBUG1
7424 mod_gzip_printf( "%s: HEADER: NOSEND: lbuf=[%s]",cn,npp(lbuf));
7433 valid_char_count = 0;
7437 if ( *p1 > 32 ) valid_char_count++;
7439 if (( p2len < MOD_GZIP_LINE_BUFFER_SIZE )&&( *p1 != 13 ))
7451 if ( header_done ) break;
7454 #ifdef MOD_GZIP_DEBUG1
7455 mod_gzip_printf( "%s: Done processing header...",cn);
7458 #ifdef MOD_GZIP_DEBUG1
7459 mod_gzip_printf( "%s: Call fclose(%s)...",cn,npp(input_filename));
7462 fclose( ifh ); ifh = 0;
7464 #ifdef MOD_GZIP_DEBUG1
7465 mod_gzip_printf( "%s: Back fclose(%s)...",cn,npp(input_filename));
7468 #ifdef MOD_GZIP_DEBUG1
7469 mod_gzip_printf( "%s: p1len = %d",cn,p1len);
7470 mod_gzip_printf( "%s: hbytes_in = %ld (Total HEADER bytes read)",cn,(long)hbytes_in);
7471 mod_gzip_printf( "%s: hbytes_out = %ld (Total HEADER bytes sent)",cn,(long)hbytes_out);
7474 #ifdef MOD_GZIP_DEBUG1
7475 mod_gzip_printf( "%s: Exit > return( hbytes_out = %d ) >",cn,hbytes_out);
7478 return (long) hbytes_out;
7481 FILE *mod_gzip_open_output_file(
7483 char *output_filename,
7489 #ifdef MOD_GZIP_DEBUG1
7490 char cn[]="mod_gzip_open_output_file():::";
7493 #ifdef MOD_GZIP_DEBUG1
7494 mod_gzip_printf( "%s: Entry...",cn);
7495 mod_gzip_printf( "%s: output_filename=[%s]",cn,npp(output_filename));
7498 ifh = fopen( output_filename, "rb" );
7502 #ifdef MOD_GZIP_DEBUG1
7503 mod_gzip_printf( "%s: ERROR: Cannot open file [%s]",
7504 cn,npp(output_filename));
7507 ap_log_error( APLOG_MARK,APLOG_NOERRNO|APLOG_ERR, r->server,
7508 "mod_gzip: Cannot re-open output_filename=[%s]",
7511 #ifdef MOD_GZIP_USES_APACHE_LOGS
7514 r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"SEND_AS_IS:WORK_OPENFAIL"));
7518 #ifdef MOD_GZIP_DEBUG1
7519 mod_gzip_printf( "%s: Exit > return( NULL ) >",cn);
7527 #ifdef MOD_GZIP_DEBUG1
7528 mod_gzip_printf( "%s: File is now open...",cn);
7529 mod_gzip_printf( "%s: Exit > return( FILE *ifh ) >",cn);
7537 int mod_gzip_flush_and_update_counts(
7539 mod_gzip_conf *dconf,
7540 long total_header_bytes_sent,
7541 long total_body_bytes_sent
7544 #ifdef MOD_GZIP_DEBUG1
7545 char cn[]="mod_gzip_flush_and_update_counts()";
7548 #ifdef MOD_GZIP_DEBUG1
7549 mod_gzip_printf( "%s: Entry",cn);
7550 mod_gzip_printf( "%s: total_header_bytes_sent = %ld",
7551 cn,(long)total_header_bytes_sent);
7552 mod_gzip_printf( "%s: total_body_bytes_sent = %ld",
7553 cn,(long)total_body_bytes_sent);
7554 mod_gzip_printf( "%s: total_bytes_sent (Sum) = %ld",
7555 cn,(long)total_header_bytes_sent +
7556 total_body_bytes_sent );
7557 mod_gzip_printf( "%s: dconf->add_header_count = %d",
7558 cn,(int )dconf->add_header_count );
7561 #ifdef MOD_GZIP_DEBUG1
7562 mod_gzip_printf( "%s: Before... ap_rflush()...",cn);
7563 mod_gzip_printf( "%s: r->connection->client->outcnt = %ld",
7564 cn,(long) r->connection->client->outcnt );
7565 mod_gzip_printf( "%s: r->connection->client->bytes_sent = %ld",
7566 cn,(long) r->connection->client->bytes_sent );
7567 mod_gzip_printf( "%s: Call..... ap_rflush()...",cn);
7572 #ifdef MOD_GZIP_DEBUG1
7573 mod_gzip_printf( "%s: Back..... ap_rflush()...",cn);
7574 mod_gzip_printf( "%s: After.... ap_rflush()...",cn);
7575 mod_gzip_printf( "%s: r->connection->client->outcnt = %ld",
7576 cn,(long) r->connection->client->outcnt );
7577 mod_gzip_printf( "%s: r->connection->client->bytes_sent = %ld",
7578 cn,(long) r->connection->client->bytes_sent );
7581 #ifdef MOD_GZIP_DEBUG1
7582 mod_gzip_printf( "%s: dconf->add_header_count = %ld",
7583 cn,(long)dconf->add_header_count);
7586 if ( dconf->add_header_count )
7588 r->connection->client->bytes_sent =
7589 total_header_bytes_sent + total_body_bytes_sent;
7593 r->connection->client->bytes_sent = total_body_bytes_sent;
7596 #ifdef MOD_GZIP_DEBUG1
7597 mod_gzip_printf( "%s: After count update...",cn);
7598 mod_gzip_printf( "%s: r->connection->client->outcnt = %ld",
7599 cn,(long) r->connection->client->outcnt );
7600 mod_gzip_printf( "%s: r->connection->client->bytes_sent = %ld",
7601 cn,(long) r->connection->client->bytes_sent );
7602 mod_gzip_printf( "%s: Exit > return( 1 ) >",cn);
7608 int mod_gzip_encode_and_transmit(
7610 mod_gzip_conf *dconf,
7612 int source_is_a_file,
7616 char *result_prefix_string
7619 char *prefix_string = result_prefix_string;
7622 GZP_CONTROL* gzp = &gzc;
7628 long byteswritten = 0;
7629 long output_size = 0;
7630 long compression_ratio = 0;
7631 char *gz1_ismem_obuf = 0;
7632 int finalize_stats = 1;
7633 long output_offset = 0;
7635 long total_bytes_sent = 0;
7636 long total_header_bytes_sent = 0;
7637 long total_compressed_bytes_sent = 0;
7638 int gz1_ismem_obuf_was_allocated = 0;
7640 #define MOD_GZIP_LARGE_BUFFER_SIZE 4000
7642 char tmp[ MOD_GZIP_LARGE_BUFFER_SIZE + 2 ];
7644 char actual_content_encoding_name[] = "gzip";
7646 char dummy_result_prefix_string[] = "";
7648 #ifdef MOD_GZIP_DEBUG1
7652 #ifdef MOD_GZIP_DEBUG1
7653 char cn[]="mod_gzip_encode_and_transmit()";
7656 #ifdef MOD_GZIP_USES_APACHE_LOGS
7660 char *dconf__temp_dir = 0;
7661 int dconf__keep_workfiles = 0;
7662 long dconf__minimum_file_size = 300;
7663 long dconf__maximum_file_size = 0;
7664 long dconf__maximum_inmem_size = 0;
7666 #ifdef MOD_GZIP_DEBUG1
7667 mod_gzip_printf( "%s: Entry...", cn);
7671 * Initialize the GZP control deck on the stack with some
7672 * safe default values. As of this writing the filename and
7673 * scratch buffers do not need to be fully reset on entry
7674 * so there is no need to suffer the overhead of a full
7675 * 'memset( gzp, 0, sizeof( GZP_CONTROL )' call.
7678 gzp->decompress = 0;
7679 gzp->input_ismem = 0;
7680 gzp->input_ismem_ibuf = 0;
7681 gzp->input_ismem_ibuflen = 0;
7682 gzp->input_filename[0] = 0;
7683 gzp->input_offset = header_length;
7684 gzp->output_ismem = 0;
7685 gzp->output_ismem_obuf = 0;
7686 gzp->output_ismem_obuflen = 0;
7687 gzp->output_filename[0] = 0;
7688 gzp->result_code = 0;
7693 dconf__keep_workfiles = dconf->keep_workfiles;
7694 dconf__minimum_file_size = dconf->minimum_file_size;
7695 dconf__maximum_file_size = dconf->maximum_file_size;
7696 dconf__maximum_inmem_size = dconf->maximum_inmem_size;
7697 dconf__temp_dir = dconf->temp_dir;
7700 #ifdef MOD_GZIP_DEBUG1
7702 mod_gzip_printf( "%s: dconf__keep_workfiles = %d", cn, (int) dconf__keep_workfiles );
7703 mod_gzip_printf( "%s: dconf__temp_dir = [%s]",cn, npp(dconf__temp_dir));
7704 mod_gzip_printf( "%s: dconf__minimum_file_size = %ld", cn, (long) dconf__minimum_file_size );
7705 mod_gzip_printf( "%s: dconf__maximum_file_size = %ld", cn, (long) dconf__maximum_file_size );
7706 mod_gzip_printf( "%s: dconf__maximum_inmem_size = %ld", cn, (long) dconf__maximum_inmem_size );
7708 mod_gzip_printf( "%s: source_is_a_file = %d", cn, source_is_a_file );
7709 mod_gzip_printf( "%s: nodecline = %d", cn, nodecline );
7710 mod_gzip_printf( "%s: header_length = %ld", cn, header_length );
7712 if ( source_is_a_file )
7714 mod_gzip_printf( "%s: source = [%s]", cn, npp(source));
7718 mod_gzip_printf( "%s: source = MEMORY BUFFER", cn );
7721 mod_gzip_printf( "%s: input_size = %ld", cn,(long)input_size);
7725 #ifdef MOD_GZIP_USES_APACHE_LOGS
7727 if ( !prefix_string )
7729 prefix_string = dummy_result_prefix_string;
7732 sprintf( log_info,"%sOK", prefix_string );
7735 r->notes,"mod_gzip_result",ap_pstrdup(r->pool,log_info));
7737 sprintf( log_info,"%d", (int) input_size );
7738 ap_table_setn( r->notes,"mod_gzip_input_size",ap_pstrdup(r->pool,log_info));
7742 if ( input_size < 1 )
7744 #ifdef MOD_GZIP_DEBUG1
7745 mod_gzip_printf( "%s: ERROR: Input source has no valid length.",cn);
7746 mod_gzip_printf( "%s: This request will not be processed...",cn);
7749 #ifdef MOD_GZIP_USES_APACHE_LOGS
7751 sprintf( log_info,"%sDECLINED:NO_ILEN", prefix_string );
7754 r->notes,"mod_gzip_result",ap_pstrdup(r->pool,log_info));
7758 #ifdef MOD_GZIP_DEBUG1
7759 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
7765 #ifdef MOD_GZIP_DEBUG1
7766 mod_gzip_printf( "%s: dconf__minimum_file_size = %ld",
7767 cn, (long) dconf__minimum_file_size );
7770 if ( input_size < (long) dconf__minimum_file_size )
7772 #ifdef MOD_GZIP_DEBUG1
7773 mod_gzip_printf( "%s: Source does not meet the minimum size requirement...",cn);
7776 #ifdef MOD_GZIP_USES_APACHE_LOGS
7778 sprintf( log_info,"%sDECLINED:TOO_SMALL", prefix_string );
7781 r->notes,"mod_gzip_result",ap_pstrdup(r->pool,log_info));
7785 #ifdef MOD_GZIP_DEBUG1
7786 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
7793 #ifdef MOD_GZIP_DEBUG1
7794 mod_gzip_printf( "%s: Source meets the minimum size requirement.",cn);
7795 mod_gzip_printf( "%s: Assuming OK to proceed...",cn);
7799 #ifdef MOD_GZIP_DEBUG1
7800 mod_gzip_printf( "%s: dconf__maximum_file_size = %ld",
7801 cn, (long) dconf__maximum_file_size );
7804 if ( ( dconf__maximum_file_size > 0 ) &&
7805 ( input_size > (long) dconf__maximum_file_size ) )
7807 #ifdef MOD_GZIP_DEBUG1
7808 mod_gzip_printf( "%s: Source exceeds the maximum size limit...",cn);
7811 #ifdef MOD_GZIP_USES_APACHE_LOGS
7813 sprintf( log_info,"%sDECLINED:TOO_BIG", prefix_string );
7816 r->notes,"mod_gzip_result",ap_pstrdup(r->pool,log_info));
7820 #ifdef MOD_GZIP_DEBUG1
7821 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
7828 #ifdef MOD_GZIP_DEBUG1
7829 mod_gzip_printf( "%s: Source does not exceed the maximum size limit.",cn);
7830 mod_gzip_printf( "%s: Assuming OK to proceed...",cn);
7834 #ifdef MOD_GZIP_DEBUG1
7835 mod_gzip_printf( "%s: dconf__maximum_inmem_size = %ld",
7836 cn, (long) dconf__maximum_inmem_size );
7839 if ( source_is_a_file )
7841 #ifdef MOD_GZIP_DEBUG1
7842 mod_gzip_printf( "%s: Input source is file[%s]",cn,npp(source));
7845 mod_gzip_strcpy( gzp->input_filename, source );
7847 gzp->input_ismem = 0;
7848 gzp->input_ismem_ibuf = 0;
7849 gzp->input_ismem_ibuflen = 0;
7853 #ifdef MOD_GZIP_DEBUG1
7854 mod_gzip_printf( "%s: Input source is a MEMORY BUFFER",cn);
7857 gzp->input_ismem = 1;
7858 gzp->input_ismem_ibuf = source;
7859 gzp->input_ismem_ibuflen = input_size;
7862 gzp->decompress = 0;
7864 if ( dconf__maximum_inmem_size > (long) 60000L )
7866 /* TODO: Some OS'es will have a 'malloc()' problem if the */
7867 /* in-memory size is greater than 64k so for now just set */
7868 /* 60k as the fixed upper limit. Expand this later. */
7870 /* NOTE: Testing has shown that for responses greater than */
7871 /* 60k or so the 'swap to disk' option SHOULD be used, anyway. */
7872 /* MOST responses will be far less than 60k. */
7874 dconf__maximum_inmem_size = (long) 60000L;
7877 if ( input_size < (long) dconf__maximum_inmem_size )
7879 #ifdef MOD_GZIP_DEBUG1
7880 mod_gzip_printf( "%s: Input source is small enough for in-memory compression.",cn);
7883 *gzp->output_filename = 0;
7884 gzp->output_ismem = 1;
7886 #ifdef MOD_GZIP_DEBUG1
7887 mod_gzip_printf( "%s: Call malloc( input_size + 1000 = %ld )...",
7888 cn,(long)(input_size+1000));
7891 gz1_ismem_obuf = (char *) malloc( input_size + 1000 );
7893 #ifdef MOD_GZIP_DEBUG1
7894 mod_gzip_printf( "%s: Back malloc( input_size + 1000 = %ld )...",
7895 cn,(long)(input_size+1000));
7898 if ( !gz1_ismem_obuf )
7900 #ifdef MOD_GZIP_DEBUG1
7901 mod_gzip_printf( "%s: ERROR: Cannot allocate GZP memory...",cn);
7902 mod_gzip_printf( "%s: Defaulting to output file method... ",cn);
7905 gzp->output_ismem = 0;
7909 #ifdef MOD_GZIP_DEBUG1
7910 mod_gzip_printf( "%s: ( %ld + 1000 ) bytes allocated OK",cn,(long)input_size);
7913 gz1_ismem_obuf_was_allocated = 1;
7915 /* TODO: This probably isn't necessary and just wastes time... */
7916 memset( gz1_ismem_obuf, 0, ( input_size + 1000 ) );
7918 gzp->output_ismem_obuf = gz1_ismem_obuf;
7919 gzp->output_ismem_obuflen = input_size + 1000;
7922 #ifdef MOD_GZIP_DEBUG1
7925 mod_gzip_printf( "%s: Input source is too large for in-memory compression.",cn);
7929 if ( gzp->output_ismem != 1 )
7931 #ifdef MOD_GZIP_DEBUG1
7932 mod_gzip_printf( "%s: Ouput target is a FILE...",cn);
7935 mod_gzip_create_unique_filename(
7937 (char *) gzp->output_filename,
7938 MOD_GZIP_MAX_PATH_LEN
7941 gzp->output_ismem = 0;
7943 gzp->output_ismem_obuf = 0;
7944 gzp->output_ismem_obuflen = 0;
7947 #ifdef MOD_GZIP_DEBUG1
7948 mod_gzip_printf( "%s: gzp->decompress = %d" ,cn,gzp->decompress);
7949 mod_gzip_printf( "%s: gzp->input_ismem = %d", cn,gzp->input_ismem);
7950 mod_gzip_printf( "%s: gzp->output_ismem = %d", cn,gzp->output_ismem);
7951 mod_gzip_printf( "%s: gzp->input_filename = [%s]",cn,npp(gzp->input_filename));
7952 mod_gzip_printf( "%s: gzp->input_offset = %ld", cn,gzp->input_offset);
7953 mod_gzip_printf( "%s: gzp->output_filename = [%s]",cn,npp(gzp->output_filename));
7954 mod_gzip_printf( "%s: Call gzp_main(r,gzp)...",cn);
7957 rc = gzp_main( r, gzp );
7959 output_size = (long) gzp->bytes_out;
7961 #ifdef MOD_GZIP_DEBUG1
7962 mod_gzip_printf( "%s: Back gzp_main(r,gzp)...",cn);
7963 mod_gzip_printf( "%s: input_size = %ld",cn,(long)input_size);
7964 mod_gzip_printf( "%s: output_size = %ld",cn,(long)output_size);
7965 mod_gzip_printf( "%s: gzp->bytes_out = %ld",cn,(long)gzp->bytes_out);
7966 mod_gzip_printf( "%s: Bytes saved = %ld",cn,
7967 (long)input_size-gzp->bytes_out );
7970 compression_ratio = 0;
7972 if ( ( input_size > 0 ) &&
7973 ( output_size > 0 ) )
7975 compression_ratio = 100 - (int)
7976 ( output_size * 100L / input_size );
7979 #ifdef MOD_GZIP_DEBUG1
7980 mod_gzip_printf( "%s: Compression = %ld percent",cn,
7981 (long) compression_ratio );
7984 #ifdef MOD_GZIP_USES_APACHE_LOGS
7986 sprintf( log_info,"%d", (int) output_size );
7987 ap_table_setn( r->notes,"mod_gzip_output_size",ap_pstrdup(r->pool,log_info));
7989 sprintf( log_info,"%d", (int) compression_ratio );
7990 ap_table_setn( r->notes,"mod_gzip_compression_ratio",ap_pstrdup(r->pool,log_info));
7994 if ( output_size < 1 )
7996 #ifdef MOD_GZIP_DEBUG1
7997 mod_gzip_printf( "%s: Compressed version has no length.",cn);
7998 mod_gzip_printf( "%s: Sending the original version uncompressed...",cn);
8003 #ifdef MOD_GZIP_USES_APACHE_LOGS
8005 sprintf( log_info,"%sDECLINED:NO_OLEN", prefix_string );
8008 r->notes,"mod_gzip_result",ap_pstrdup(r->pool,log_info));
8012 if ( gz1_ismem_obuf )
8014 #ifdef MOD_GZIP_DEBUG1
8015 mod_gzip_printf( "%s: gz1_ismem_obuf is still a VALID pointer",cn);
8016 mod_gzip_printf( "%s: gz1_ismem_obuf_was_allocated = %d",
8017 cn,(int) gz1_ismem_obuf_was_allocated );
8020 if ( gz1_ismem_obuf_was_allocated )
8022 #ifdef MOD_GZIP_DEBUG1
8023 mod_gzip_printf( "%s: Call free( gz1_ismem_obuf )...",cn);
8026 free( gz1_ismem_obuf );
8028 #ifdef MOD_GZIP_DEBUG1
8029 mod_gzip_printf( "%s: Back free( gz1_ismem_obuf )...",cn);
8033 gz1_ismem_obuf_was_allocated = 0;
8037 #ifdef MOD_GZIP_DEBUG1
8038 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
8044 if ( output_size > input_size )
8046 #ifdef MOD_GZIP_DEBUG1
8047 mod_gzip_printf( "%s: Compressed version is larger than original.",cn);
8048 mod_gzip_printf( "%s: Sending the original version uncompressed...",cn);
8053 #ifdef MOD_GZIP_USES_APACHE_LOGS
8055 sprintf( log_info,"%sDECLINED:ORIGINAL_SMALLER", prefix_string );
8058 r->notes,"mod_gzip_result",ap_pstrdup(r->pool,log_info));
8062 if ( gz1_ismem_obuf )
8064 #ifdef MOD_GZIP_DEBUG1
8065 mod_gzip_printf( "%s: gz1_ismem_obuf is still a VALID pointer",cn);
8066 mod_gzip_printf( "%s: gz1_ismem_obuf_was_allocated = %d",
8067 cn,(int) gz1_ismem_obuf_was_allocated );
8070 if ( gz1_ismem_obuf_was_allocated )
8072 #ifdef MOD_GZIP_DEBUG1
8073 mod_gzip_printf( "%s: Call free( gz1_ismem_obuf )...",cn);
8076 free( gz1_ismem_obuf );
8078 #ifdef MOD_GZIP_DEBUG1
8079 mod_gzip_printf( "%s: Back free( gz1_ismem_obuf )...",cn);
8083 gz1_ismem_obuf_was_allocated = 0;
8087 #ifdef MOD_GZIP_DEBUG1
8088 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
8093 #ifdef MOD_GZIP_DEBUG1
8096 mod_gzip_printf( "%s: Compressed version is smaller than original.",cn);
8097 mod_gzip_printf( "%s: Sending the compressed version...",cn);
8101 if ( !gzp->output_ismem )
8103 #ifdef MOD_GZIP_DEBUG1
8104 mod_gzip_printf( "%s: Re-opening compressed output file [%s]...",
8105 cn, npp(gzp->output_filename));
8108 ifh = mod_gzip_open_output_file( r, gzp->output_filename, &rc );
8112 #ifdef MOD_GZIP_DEBUG1
8113 mod_gzip_printf( "%s: ERROR: Cannot re-open file [%s]",
8114 cn,npp(gzp->output_filename));
8117 #ifdef MOD_GZIP_USES_APACHE_LOGS
8119 sprintf( log_info,"%sDECLINED:REOPEN_FAILED", prefix_string );
8122 r->notes,"mod_gzip_result",ap_pstrdup(r->pool,log_info));
8126 #ifdef MOD_GZIP_DEBUG1
8127 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
8133 #ifdef MOD_GZIP_DEBUG1
8134 mod_gzip_printf( "%s: Workfile re-opened OK...",cn);
8138 /* TODO: This isn't really necessary? */
8139 r->content_encoding = actual_content_encoding_name;
8141 #ifdef MOD_GZIP_DEBUG1
8142 mod_gzip_printf( "%s: r->content_encoding is now [%s]",
8143 cn, npp(r->content_encoding));
8146 #ifdef MOD_GZIP_DEBUG1
8147 mod_gzip_printf( "%s: Starting transmit phase...",cn);
8148 mod_gzip_printf( "%s: output_offset = %ld",cn, (long) output_offset );
8151 /* Send the response header... */
8153 #ifdef MOD_GZIP_DEBUG1
8154 mod_gzip_printf( "%s: Call mod_gzip_send_header(source=%s)",cn,npp(source));
8157 total_header_bytes_sent = (int)
8158 mod_gzip_send_header(
8164 #ifdef MOD_GZIP_DEBUG1
8165 mod_gzip_printf( "%s: Back mod_gzip_send_header(source=%s)",cn,npp(source));
8166 mod_gzip_printf( "%s: total_header_bytes_sent = %d",cn,rc);
8169 total_compressed_bytes_sent = 0;
8171 /* Send the compressed data.. */
8173 if ( gzp->output_ismem )
8175 #ifdef MOD_GZIP_DEBUG1
8177 mod_gzip_printf( "%s: Sending in-memory output buffer...",cn);
8178 mod_gzip_printf( "%s: output_size = %ld",cn,(long)output_size);
8179 mod_gzip_printf( "%s: output_offset = %ld",cn,(long)output_offset);
8181 #ifdef MOD_GZIP_DUMP_JUST_BEFORE_SENDING
8182 mod_gzip_hexdump( gz1_ismem_obuf, output_size );
8185 mod_gzip_printf( "%s: Call mod_gzip_send( gz1_ismem_obuf+output_offset=%ld, output_size=%ld )...",
8186 cn, (long) output_offset, (long) output_size );
8189 byteswritten = (long)
8190 mod_gzip_send( gz1_ismem_obuf+output_offset, output_size, r );
8192 #ifdef MOD_GZIP_DEBUG1
8193 mod_gzip_printf( "%s: Back mod_gzip_send( gz1_ismem_obuf+output_offset=%ld, output_size=%ld )...",
8194 cn, (long) output_offset, (long) output_size );
8195 mod_gzip_printf( "%s: byteswritten = %ld",cn,(long)byteswritten);
8198 if ( byteswritten > 0 )
8200 total_compressed_bytes_sent = byteswritten;
8203 if ( byteswritten != output_size )
8208 #if defined(WIN32) || defined(NETWARE)
8209 err = WSAGetLastError();
8215 #ifdef MOD_GZIP_DEBUG1
8216 mod_gzip_printf( "%s: TRANSMIT ERROR: output_size=%ld byteswritten=%ld err=%d",
8217 cn,(long)output_size,(long)byteswritten,(int)err );
8220 #ifdef MOG_GZIP_DEBUG1
8222 mod_gzip_log_comerror( r, "mod_gzip: TRANSMIT_ERROR:", err );
8226 ap_log_error( APLOG_MARK,APLOG_NOERRNO|APLOG_ERR, r->server,
8227 "mod_gzip: TRANSMIT_ERROR:ISMEM:%d",(int)err);
8231 #ifdef MOD_GZIP_USES_APACHE_LOGS
8233 #ifdef MOD_GZIP_DEBUG1
8234 mod_gzip_translate_comerror( err, scratch2 );
8235 sprintf( log_info,"%sTRANSMIT_ERROR:ISMEM:%d:%s", prefix_string, (int) err, scratch2 );
8237 sprintf( log_info,"%sTRANSMIT_ERROR:ISMEM:%d", prefix_string, (int) err );
8240 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,log_info));
8247 #ifdef MOD_GZIP_DEBUG1
8248 mod_gzip_printf( "%s: sizeof( tmp ) = %d",cn,sizeof(tmp));
8249 mod_gzip_printf( "%s: MOD_GZIP_LARGE_BUFFER_SIZE = %d",cn,(int)MOD_GZIP_LARGE_BUFFER_SIZE);
8250 mod_gzip_printf( "%s: Transmit buffer size = %d",cn,sizeof(tmp));
8251 mod_gzip_printf( "%s: Sending output file...",cn);
8254 if ( output_offset > 0 )
8256 #ifdef MOD_GZIP_DEBUG1
8257 mod_gzip_printf( "%s: output_offset = %ld",cn,(long)output_offset);
8258 mod_gzip_printf( "%s: Call fseek(ifh,%ld,1)...",cn,(long)output_offset);
8261 fseek( ifh, (long) output_offset, 1 );
8263 #ifdef MOD_GZIP_DEBUG1
8264 mod_gzip_printf( "%s: Back fseek(ifh,%ld,1)...",cn,(long)output_offset);
8269 #ifdef MOD_GZIP_DEBUG1
8270 mod_gzip_printf( "%s: output_offset = %ld = ZERO",cn,(long)output_offset);
8271 mod_gzip_printf( "%s: No fseek() call required before transmit.",cn);
8277 bytesread = fread( tmp, 1, MOD_GZIP_LARGE_BUFFER_SIZE, ifh );
8279 #ifdef MOD_GZIP_DEBUG1
8280 mod_gzip_printf( "%s: Back fread(): bytesread=%d",cn,bytesread);
8283 if ( bytesread < 1 ) break;
8285 byteswritten = (long)
8286 mod_gzip_send( tmp, bytesread, r );
8288 #ifdef MOD_GZIP_DEBUG1
8289 mod_gzip_printf( "%s: byteswritten = %ld",cn,(long)byteswritten);
8292 if ( byteswritten > 0 )
8294 total_compressed_bytes_sent += byteswritten;
8297 if ( byteswritten != bytesread )
8302 #if defined(WIN32) || defined(NETWARE)
8303 err = WSAGetLastError();
8309 #ifdef MOD_GZIP_DEBUG1
8310 mod_gzip_printf( "%s: TRANSMIT ERROR: bytesread=%ld byteswritten=%ld err=%d",
8311 cn,(long)bytesread,(long)byteswritten,(int)err );
8314 #ifdef MOG_GZIP_DEBUG1
8316 mod_gzip_log_comerror( r, "mod_gzip: TRANSMIT_ERROR:", err );
8320 ap_log_error( APLOG_MARK,APLOG_NOERRNO|APLOG_ERR, r->server,
8321 "mod_gzip: TRANSMIT_ERROR:%d",(int)err);
8325 #ifdef MOD_GZIP_USES_APACHE_LOGS
8327 #ifdef MOD_GZIP_DEBUG1
8328 mod_gzip_translate_comerror( err, scratch2 );
8329 sprintf( log_info,"%sTRANSMIT_ERROR:%d:%s", prefix_string, (int) err, scratch2 );
8331 sprintf( log_info,"%sTRANSMIT_ERROR:%d", prefix_string, (int) err );
8334 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,log_info));
8338 #ifdef MOD_GZIP_DEBUG1
8339 mod_gzip_printf( "%s: Breaking out of transmit loop early...",cn);
8345 }/* End for(;;) loop that transmits workfile... */
8349 /* Flush the output and update counts... */
8352 total_header_bytes_sent +
8353 total_compressed_bytes_sent;
8355 #ifdef MOD_GZIP_DEBUG1
8356 mod_gzip_printf( "%s: Done Sending compressed data...",cn);
8357 mod_gzip_printf( "%s: total_header_bytes_sent = %ld",
8358 cn,(long)total_header_bytes_sent);
8359 mod_gzip_printf( "%s: total_compressed_bytes_sent = %ld",
8360 cn,(long)total_compressed_bytes_sent);
8361 mod_gzip_printf( "%s: total_bytes_sent (Sum) = %ld",
8362 cn,(long)total_bytes_sent);
8363 mod_gzip_printf( "%s: Call mod_gzip_flush_and_update_counts()...",cn);
8366 mod_gzip_flush_and_update_counts(
8369 total_header_bytes_sent,
8370 total_compressed_bytes_sent
8373 #ifdef MOD_GZIP_DEBUG1
8374 mod_gzip_printf( "%s: Back mod_gzip_flush_and_update_counts()...",cn);
8379 #ifdef MOD_GZIP_DEBUG1
8380 mod_gzip_printf( "%s: Cleanup phase START...",cn);
8383 if ( gzp->output_ismem )
8385 #ifdef MOD_GZIP_DEBUG1
8386 mod_gzip_printf( "%s: Output source was MEMORY...",cn);
8389 if ( gz1_ismem_obuf )
8391 #ifdef MOD_GZIP_DEBUG1
8392 mod_gzip_printf( "%s: gz1_ismem_obuf is still VALID...",cn);
8395 if ( gz1_ismem_obuf_was_allocated )
8397 #ifdef MOD_GZIP_DEBUG1
8398 mod_gzip_printf( "%s: gz1_ismem_obuf_was_allocated = TRUE",cn);
8399 mod_gzip_printf( "%s: Call free( gz1_ismem_obuf )...",cn);
8402 free( gz1_ismem_obuf );
8404 #ifdef MOD_GZIP_DEBUG1
8405 mod_gzip_printf( "%s: Back free( gz1_ismem_obuf )...",cn);
8409 gz1_ismem_obuf_was_allocated = 0;
8415 #ifdef MOD_GZIP_DEBUG1
8416 mod_gzip_printf( "%s: Output source was a WORKFILE...",cn);
8417 mod_gzip_printf( "%s: Closing workfile [%s]...",cn,npp(gzp->output_filename));
8423 #ifdef MOD_GZIP_DEBUG1
8424 mod_gzip_printf( "%s: dconf__keep_workfiles = %d",
8425 cn, dconf__keep_workfiles );
8428 if ( !dconf__keep_workfiles )
8430 #ifdef MOD_GZIP_DEBUG1
8431 mod_gzip_printf( "%s: Deleting workfile [%s]...",
8432 cn, npp(gzp->output_filename));
8436 DeleteFile( gzp->output_filename );
8438 unlink( gzp->output_filename );
8443 #ifdef MOD_GZIP_DEBUG1
8444 mod_gzip_printf( "%s: Keeping workfile [%s]...",
8445 cn, npp(gzp->output_filename));
8450 #ifdef MOD_GZIP_USES_APACHE_LOGS
8452 if ( finalize_stats )
8454 sprintf( log_info,"%d", (int) output_size );
8455 ap_table_setn( r->notes,"mod_gzip_output_size",ap_pstrdup(r->pool,log_info));
8457 sprintf( log_info,"%d", (int) compression_ratio );
8458 ap_table_setn( r->notes,"mod_gzip_compression_ratio",ap_pstrdup(r->pool,log_info));
8463 if ( r->server->loglevel == APLOG_DEBUG )
8465 ap_log_error( "",0,APLOG_NOERRNO|APLOG_DEBUG, r->server,
8466 "mod_gzip: r->uri=[%s] OK: Bytes In:%ld Out:%ld Compression: %ld pct.",
8470 (long) compression_ratio
8474 #ifdef MOD_GZIP_DEBUG1
8475 mod_gzip_printf( "%s: Exit > return( OK ) >",cn);
8481 /*--------------------------------------------------------------------------*/
8482 /* COMPRESSION_SUPPORT: START */
8483 /*--------------------------------------------------------------------------*/
8487 typedef unsigned uns;
8488 typedef unsigned int uni;
8489 typedef unsigned char uch;
8490 typedef unsigned short ush;
8491 typedef unsigned long ulg;
8492 typedef int gz1_file_t;
8495 typedef void *voidp;
8497 typedef char *voidp;
8500 #if defined(__MSDOS__) && !defined(MSDOS)
8504 #if defined(__OS2__) && !defined(OS2)
8508 #if defined(OS2) && defined(MSDOS)
8519 # ifdef __BORLANDC__
8525 # define HAVE_SYS_UTIME_H
8529 # define PATH_SEP2 '\\'
8530 # define PATH_SEP3 ':'
8531 # define MAX_PATH_LEN 128
8532 # define NO_MULTIPLE_DOTS
8533 # define MAX_EXT_CHARS 3
8534 # define Z_SUFFIX "z"
8537 # define STDC_HEADERS
8538 # define NO_SIZE_CHECK
8539 # define casemap(c) tolow(c)
8542 # define OS_CODE 0x00
8543 # define SET_BINARY_MODE(fd) setmode(fd, O_BINARY)
8544 # if !defined(NO_ASM) && !defined(ASMV)
8552 # define PATH_SEP2 '\\'
8553 # define PATH_SEP3 ':'
8554 # define MAX_PATH_LEN 260
8556 # define NO_MULTIPLE_DOTS
8557 # define MAX_EXT_CHARS 3
8558 # define Z_SUFFIX "z"
8559 # define casemap(c) tolow(c)
8563 # define STDC_HEADERS
8566 # define OS_CODE 0x06
8567 # define SET_BINARY_MODE(fd) setmode(fd, O_BINARY)
8569 # define HAVE_SYS_UTIME_H
8576 # define HAVE_SYS_UTIME_H
8579 # define EXPAND(argc,argv) \
8580 {_response(&argc, &argv); _wildcard(&argc, &argv);}
8582 # ifdef __BORLANDC__
8589 # define EXPAND(argc,argv) \
8590 {response_expand(&argc, &argv);}
8595 # define HAVE_SYS_UTIME_H
8597 # define PATH_SEP2 '\\'
8598 # define PATH_SEP3 ':'
8599 # undef MAX_PATH_LEN
8600 # define MAX_PATH_LEN 260
8603 # define STDC_HEADERS
8604 # define SET_BINARY_MODE(fd) setmode(fd, O_BINARY)
8606 # include <malloc.h>
8608 # define NO_MULTIPLE_DOTS
8609 # define MAX_EXT_CHARS 3
8610 # define Z_SUFFIX "z"
8611 # define casemap(c) tolow(c)
8615 # define OS_CODE 0x00
8623 void * fcalloc (unsigned items, unsigned size);
8624 void fcfree (void *ptr);
8626 # include <malloc.h>
8627 # define fcalloc(nitems,itemsize) halloc((long)(nitems),(itemsize))
8628 # define fcfree(ptr) hfree(ptr)
8632 # define fcalloc(items,size) calloc((items),(size))
8634 # define fcalloc(items,size) malloc((size_t)(items)*(size_t)(size))
8636 # define fcfree(ptr) free(ptr)
8639 #if defined(VAXC) || defined(VMS)
8640 # define PATH_SEP ']'
8641 # define PATH_SEP2 ':'
8642 # define SUFFIX_SEP ';'
8643 # define NO_MULTIPLE_DOTS
8644 # define Z_SUFFIX "-gz"
8645 # define RECORD_IO 1
8646 # define casemap(c) tolow(c)
8648 # define OS_CODE 0x02
8649 # define OPTIONS_VAR "GZIP_OPT"
8650 # define STDC_HEADERS
8652 # define EXPAND(argc,argv) vms_expand_args(&argc,&argv);
8654 # define unlink delete
8657 # include <unixio.h>
8662 # define PATH_SEP2 ':'
8663 # define STDC_HEADERS
8665 # define OS_CODE 0x01
8669 # define HAVE_UNISTD_H
8671 # define NO_STDIN_FSTAT
8677 # define direct dirent
8678 extern void _expand_args(int *argc, char ***argv);
8679 # define EXPAND(argc,argv) _expand_args(&argc,&argv);
8684 #if defined(ATARI) || defined(atarist)
8685 # ifndef STDC_HEADERS
8686 # define STDC_HEADERS
8687 # define HAVE_UNISTD_H
8692 # define OS_CODE 0x05
8694 # define PATH_SEP2 '\\'
8695 # define PATH_SEP3 ':'
8696 # define MAX_PATH_LEN 128
8697 # define NO_MULTIPLE_DOTS
8698 # define MAX_EXT_CHARS 3
8699 # define Z_SUFFIX "z"
8701 # define casemap(c) tolow(c)
8707 # define PATH_SEP ':'
8710 # define NO_STDIN_FSTAT
8713 # define chmod(file, mode) (0)
8714 # define OPEN(name, flags, mode) open(name, flags)
8715 # define SEEKFORWARD(handle, offset) lseek( handle, offset, 1 )
8717 # define OS_CODE 0x07
8719 # define isatty(fd) ((fd) <= 2)
8724 # define PATH_SEP '>'
8725 # define STDC_HEADERS
8726 # define NO_MEMORY_H
8730 # define NO_STDIN_FSTAT
8731 # define NO_SIZE_CHECK
8733 # define RECORD_IO 1
8734 # define casemap(c) tolow(c)
8735 # define put_char(c) put_byte((c) & 0x7F)
8736 # define get_char(c) ascii2pascii(get_byte())
8738 # define OS_CODE 0x0F
8744 #if defined(pyr) && !defined(NOMEMCPY)
8750 # define OS_CODE 0x0a
8759 # define OS_CODE 0x03
8763 # define PATH_SEP '/'
8767 # define casemap(c) (c)
8771 # define OPTIONS_VAR "GZIP"
8775 # define Z_SUFFIX ".gz"
8778 #ifdef MAX_EXT_CHARS
8779 # define MAX_SUFFIX MAX_EXT_CHARS
8781 # define MAX_SUFFIX 30
8789 # define EXPAND(argc,argv)
8793 # define RECORD_IO 0
8796 #ifndef SET_BINARY_MODE
8797 # define SET_BINARY_MODE(fd)
8801 # define OPEN(name, flags, mode) open(name, flags, mode)
8805 # define SEEKFORWARD(handle, offset) lseek( handle, offset, 1 )
8809 # define get_char() get_byte()
8813 # define put_char(c) put_byte(c)
8824 #define COMPRESSED 1
8828 #define MAX_METHODS 9
8831 #include <sys/file.h>
8833 #define O_CREAT FCREAT
8836 #define O_EXCL FEXCL
8841 #define S_IRUSR 0400
8844 #define S_IWUSR 0200
8846 #define RW_USER (S_IRUSR | S_IWUSR)
8848 #ifndef MAX_PATH_LEN
8849 #define MAX_PATH_LEN 256
8856 #define PACK_MAGIC "\037\036"
8857 #define GZIP_MAGIC "\037\213"
8858 #define OLD_GZIP_MAGIC "\037\236"
8859 #define LZH_MAGIC "\037\240"
8860 #define PKZIP_MAGIC "\120\113\003\004"
8861 #define ASCII_FLAG 0x01
8862 #define CONTINUATION 0x02
8863 #define EXTRA_FIELD 0x04
8864 #define ORIG_NAME 0x08
8865 #define COMMENT 0x10
8866 #define ENCRYPTED 0x20
8867 #define RESERVED 0xC0
8868 #define UNKNOWN 0xffff
8873 #define WSIZE 0x8000
8878 #define INBUFSIZ 0x2000
8880 #define INBUFSIZ 0x8000
8883 #define INBUF_EXTRA 64
8887 #define OUTBUFSIZ 8192
8889 #define OUTBUFSIZ 0x4000
8892 #define OUTBUF_EXTRA 2048
8894 #ifndef DIST_BUFSIZE
8896 #define DIST_BUFSIZE 0x2000
8898 #define DIST_BUFSIZE 0x8000
8906 #define LZW_MAGIC "\037\235"
8909 #define MAX_MATCH 258
8911 #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
8912 #define MAX_DIST (WSIZE-MIN_LOOKAHEAD)
8915 #define HASH_BITS 13
8918 #define HASH_BITS 14
8921 #define HASH_BITS 15
8924 #define HASH_SIZE (unsigned)(1<<HASH_BITS)
8925 #define HASH_MASK (HASH_SIZE-1)
8926 #define WMASK (WSIZE-1)
8927 #define H_SHIFT ((HASH_BITS+MIN_MATCH-1)/MIN_MATCH)
8930 #define TOO_FAR 4096
8937 #define REPZ_3_10 17
8938 #define REPZ_11_138 18
8940 #define MAX_BL_BITS 7
8944 #define LENGTH_CODES 29
8945 #define LITERALS 256
8946 #define END_BLOCK 256
8947 #define L_CODES (LITERALS+1+LENGTH_CODES)
8951 #define LIT_BUFSIZE 0x2000
8954 #define LIT_BUFSIZE 0x4000
8956 #define LIT_BUFSIZE 0x8000
8961 #define HEAP_SIZE (2*L_CODES+1)
8962 #define STORED_BLOCK 0
8963 #define STATIC_TREES 1
8965 #define NO_FILE (-1)
8970 #define LOCSIG 0x04034b50L
8983 #define RAND_HEAD_LEN 12
8984 #define BUFSIZE (8 * 2*sizeof(char))
8986 #define translate_eol 0
8988 #define FLUSH_BLOCK(eof) \
8989 flush_block(gz1,gz1->block_start >= 0L ? (char*)&gz1->window[(unsigned)gz1->block_start] : \
8990 (char*)NULL, (long)gz1->strstart - gz1->block_start, (eof))
8993 # define ALLOC(type, array, size) { \
8994 array = (type*)fcalloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \
8995 if (array == NULL) error("insufficient memory"); \
8997 # define FREE(array) {if (array != NULL) fcfree(array), array=NULL;}
8999 # define ALLOC(type, array, size)
9000 # define FREE(array)
9003 #define GZ1_MAX(a,b) (a >= b ? a : b)
9005 #define tolow(c) (isupper(c) ? (c)-'A'+'a' : (c))
9007 #define smaller(tree, n, m) \
9008 (tree[n].fc.freq < tree[m].fc.freq || \
9009 (tree[n].fc.freq == tree[m].fc.freq && gz1->depth[n] <= gz1->depth[m]))
9011 #define send_code(c, tree) send_bits(gz1,tree[c].fc.code, tree[c].dl.len)
9013 #define put_byte(c) {gz1->outbuf[gz1->outcnt++]=(uch)(c); if (gz1->outcnt==OUTBUFSIZ)\
9016 #define put_short(w) \
9017 { if (gz1->outcnt < OUTBUFSIZ-2) { \
9018 gz1->outbuf[gz1->outcnt++] = (uch) ((w) & 0xff); \
9019 gz1->outbuf[gz1->outcnt++] = (uch) ((ush)(w) >> 8); \
9021 put_byte((uch)((w) & 0xff)); \
9022 put_byte((uch)((ush)(w) >> 8)); \
9026 #define put_long(n) { \
9027 put_short((n) & 0xffff); \
9028 put_short(((ulg)(n)) >> 16); \
9033 # define NEXTBYTE() \
9034 (decrypt ? (cc = get_byte(), zdecode(cc), cc) : get_byte())
9036 # define NEXTBYTE() (uch)get_byte()
9039 #define NEEDBITS(n) {while(k<(n)){b|=((ulg)NEXTBYTE())<<k;k+=8;}}
9040 #define DUMPBITS(n) {b>>=(n);k-=(n);}
9042 #define SH(p) ((ush)(uch)((p)[0]) | ((ush)(uch)((p)[1]) << 8))
9043 #define LG(p) ((ulg)(SH(p)) | ((ulg)(SH((p)+2)) << 16))
9045 #define put_ubyte(c) {gz1->window[gz1->outcnt++]=(uch)(c); if (gz1->outcnt==WSIZE)\
9048 #define WARN(msg) { if (gz1->exit_code == OK) gz1->exit_code = WARNING; }
9050 #define get_byte() (gz1->inptr < gz1->insize ? gz1->inbuf[gz1->inptr++] : fill_inbuf(gz1,0))
9051 #define try_byte() (gz1->inptr < gz1->insize ? gz1->inbuf[gz1->inptr++] : fill_inbuf(gz1,1))
9053 #define d_code(dist) \
9054 ((dist) < 256 ? gz1->dist_code[dist] : gz1->dist_code[256+((dist)>>7)])
9056 typedef struct config {
9063 config configuration_table[10] = {
9073 {32, 128, 258, 1024},
9074 {32, 258, 258, 4096}};
9076 typedef struct ct_data {
9089 typedef struct tree_desc {
9091 ct_data *static_tree;
9108 uch bl_order[BL_CODES]
9109 = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
9111 int extra_lbits[LENGTH_CODES]
9112 = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0};
9114 int extra_dbits[D_CODES]
9115 = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13};
9117 int extra_blbits[BL_CODES]
9118 = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
9120 ulg crc_32_tab[] = {
9121 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
9122 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
9123 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
9124 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
9125 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
9126 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
9127 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
9128 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
9129 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
9130 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
9131 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
9132 0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
9133 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
9134 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
9135 0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
9136 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
9137 0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
9138 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
9139 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
9140 0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
9141 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
9142 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
9143 0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
9144 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
9145 0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
9146 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
9147 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
9148 0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
9149 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
9150 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
9151 0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
9152 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
9153 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
9154 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
9155 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
9156 0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
9157 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
9158 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
9159 0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
9160 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
9161 0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
9162 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
9163 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
9164 0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
9165 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
9166 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
9167 0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
9168 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
9169 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
9170 0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
9171 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
9175 typedef struct _GZ1 {
9179 int deflate1_initialized;
9180 unsigned deflate1_hash_head;
9181 unsigned deflate1_prev_match;
9183 int deflate1_match_available;
9184 unsigned deflate1_match_length;
9186 char ifname[MAX_PATH_LEN];
9187 char ofname[MAX_PATH_LEN];
9194 long input_bytesleft;
9219 uns max_chain_length;
9267 uch length_code[MAX_MATCH-MIN_MATCH+1];
9268 int heap[2*L_CODES+1];
9269 uch depth[2*L_CODES+1];
9270 int base_length[LENGTH_CODES];
9271 int base_dist[D_CODES];
9272 ush bl_count[MAX_BITS+1];
9273 uch flag_buf[(LIT_BUFSIZE/8)];
9281 uch inbuf [INBUFSIZ +INBUF_EXTRA];
9282 uch outbuf[OUTBUFSIZ+OUTBUF_EXTRA];
9283 ush d_buf [DIST_BUFSIZE];
9284 uch window[2L*WSIZE];
9288 #define nice_match MAX_MATCH
9297 ct_data static_ltree[L_CODES+2];
9298 ct_data static_dtree[D_CODES];
9299 ct_data dyn_dtree[(2*D_CODES+1)];
9300 ct_data dyn_ltree[HEAP_SIZE];
9301 ct_data bl_tree[2*BL_CODES+1];
9309 ush prev2[1L<<BITS];
9311 #define prev gz1->prev2
9312 #define head (gz1->prev2+WSIZE)
9319 #define prev gz1->prev2
9320 #define head gz1->tab_prefix1
9326 int gz1_size = sizeof( GZ1 );
9328 /* Declare some local function protypes... */
9330 /* Any routine name that can/might conflict with */
9331 /* other modules or object code should simply have */
9332 /* the standard prefix 'gz1_' added to the front. */
9333 /* This will only usually be any kind of problem at all */
9334 /* if the code is being compiled directly into the parent */
9335 /* instead of being built as a standalone DLL or DSO library. */
9337 PGZ1 gz1_init ( void );
9338 int gz1_cleanup ( PGZ1 gz1 );
9339 ulg gz1_deflate ( PGZ1 gz1 );
9340 ulg gz1_deflate_fast( PGZ1 gz1 );
9342 /* The rest of the routines should not need the 'gz1_' prefix. */
9343 /* No conflicts reported at this time. */
9345 int inflate ( PGZ1 gz1 );
9346 int inflate_dynamic( PGZ1 gz1 );
9347 int inflate_stored ( PGZ1 gz1 );
9348 int inflate_fixed ( PGZ1 gz1 );
9349 void fill_window ( PGZ1 gz1 );
9350 void flush_outbuf ( PGZ1 gz1 );
9351 void flush_window ( PGZ1 gz1 );
9352 void bi_windup ( PGZ1 gz1 );
9353 void set_file_type ( PGZ1 gz1 );
9354 void init_block ( PGZ1 gz1 );
9355 int build_bl_tree ( PGZ1 gz1 );
9356 void read_error ( PGZ1 gz1 );
9357 void write_error ( PGZ1 gz1 );
9358 int get_header ( PGZ1 gz1, int in );
9359 int inflate_block ( PGZ1 gz1, int *e );
9360 int fill_inbuf ( PGZ1 gz1, int eof_ok );
9361 char *gz1_basename ( PGZ1 gz1, char *fname );
9362 int longest_match ( PGZ1 gz1, unsigned cur_match );
9363 void bi_init ( PGZ1 gz1, gz1_file_t zipfile );
9364 int file_read ( PGZ1 gz1, char *buf, unsigned size );
9365 void write_buf ( PGZ1 gz1, int fd, voidp buf, unsigned cnt );
9367 void error( char *msg );
9407 void send_all_trees(
9431 void compress_block(
9485 unsigned bi_reverse(
9500 gz1 = (PGZ1) malloc( gz1_size );
9507 memset( gz1, 0, gz1_size );
9509 ALLOC(uch, gz1->inbuf, INBUFSIZ +INBUF_EXTRA);
9517 ALLOC(uch, gz1->outbuf, OUTBUFSIZ+OUTBUF_EXTRA);
9526 ALLOC(ush, gz1->d_buf, DIST_BUFSIZE);
9530 FREE( gz1->outbuf );
9536 ALLOC(uch, gz1->window, 2L*WSIZE);
9541 FREE( gz1->outbuf );
9551 ALLOC(ush, gz1->prev2, 1L<<(BITS-1) );
9555 FREE( gz1->window );
9557 FREE( gz1->outbuf );
9563 ALLOC(ush, gz1->tab_prefix1, 1L<<(BITS-1) );
9565 if ( !gz1->tab_prefix1 )
9568 FREE( gz1->window );
9570 FREE( gz1->outbuf );
9578 gz1->method = DEFLATED;
9582 gz1->exit_code = OK;
9586 gz1->window_size = (ulg)2*WSIZE;
9587 gz1->crc = (ulg)0xffffffffL;
9589 gz1->d_desc.dyn_tree = (ct_data *) gz1->dyn_dtree;
9590 gz1->d_desc.static_tree = (ct_data *) gz1->static_dtree;
9591 gz1->d_desc.extra_bits = (int *) extra_dbits;
9592 gz1->d_desc.extra_base = (int ) 0;
9593 gz1->d_desc.elems = (int ) D_CODES;
9594 gz1->d_desc.max_length = (int ) MAX_BITS;
9595 gz1->d_desc.max_code = (int ) 0;
9597 gz1->l_desc.dyn_tree = (ct_data *) gz1->dyn_ltree;
9598 gz1->l_desc.static_tree = (ct_data *) gz1->static_ltree;
9599 gz1->l_desc.extra_bits = (int *) extra_lbits;
9600 gz1->l_desc.extra_base = (int ) LITERALS+1;
9601 gz1->l_desc.elems = (int ) L_CODES;
9602 gz1->l_desc.max_length = (int ) MAX_BITS;
9603 gz1->l_desc.max_code = (int ) 0;
9605 gz1->bl_desc.dyn_tree = (ct_data *) gz1->bl_tree;
9606 gz1->bl_desc.static_tree = (ct_data *) 0;
9607 gz1->bl_desc.extra_bits = (int *) extra_blbits;
9608 gz1->bl_desc.extra_base = (int ) 0;
9609 gz1->bl_desc.elems = (int ) BL_CODES;
9610 gz1->bl_desc.max_length = (int ) MAX_BL_BITS;
9611 gz1->bl_desc.max_code = (int ) 0;
9617 int gz1_cleanup( PGZ1 gz1 )
9624 FREE( gz1->tab_prefix1 );
9628 FREE( gz1->window );
9630 FREE( gz1->outbuf );
9639 int (*read_buf)(PGZ1 gz1, char *buf, unsigned size);
9641 void error( char *msg )
9646 int (*work)( PGZ1 gz1, int infile, int outfile ) = 0;
9652 int get_header( PGZ1 gz1, int in )
9660 if ( gz1->force && gz1->to_stdout )
9662 magic[0] = (char)try_byte();
9663 magic[1] = (char)try_byte();
9667 magic[0] = (char)get_byte();
9668 magic[1] = (char)get_byte();
9672 gz1->header_bytes = 0;
9673 gz1->last_member = RECORD_IO;
9676 if ( memcmp(magic, GZIP_MAGIC, 2 ) == 0 ||
9677 memcmp(magic, OLD_GZIP_MAGIC, 2 ) == 0 )
9679 gz1->method = (int)get_byte();
9681 if ( gz1->method != DEFLATED )
9683 gz1->exit_code = LZ1_ERROR;
9690 if ((flags & ENCRYPTED) != 0)
9692 gz1->exit_code = LZ1_ERROR;
9696 if ((flags & CONTINUATION) != 0)
9698 gz1->exit_code = LZ1_ERROR;
9699 if ( gz1->force <= 1) return -1;
9702 if ((flags & RESERVED) != 0)
9704 gz1->exit_code = LZ1_ERROR;
9705 if ( gz1->force <= 1)
9709 stamp = (ulg)get_byte();
9710 stamp |= ((ulg)get_byte()) << 8;
9711 stamp |= ((ulg)get_byte()) << 16;
9712 stamp |= ((ulg)get_byte()) << 24;
9714 if ( stamp != 0 && !gz1->no_time )
9716 gz1->time_stamp = stamp;
9722 if ((flags & CONTINUATION) != 0)
9724 part = (unsigned) get_byte();
9725 part |= ((unsigned) get_byte())<<8;
9728 if ((flags & EXTRA_FIELD) != 0)
9730 len = (unsigned) get_byte();
9731 len |= ((unsigned) get_byte())<<8;
9733 while (len--) (void)get_byte();
9736 if ((flags & COMMENT) != 0)
9738 while (get_char() != 0) ;
9741 if ( gz1->part_nb == 1 )
9743 gz1->header_bytes = gz1->inptr + 2*sizeof(long);
9750 int fill_inbuf( PGZ1 gz1, int eof_ok )
9759 if ( gz1->input_ismem )
9761 if ( gz1->input_bytesleft > 0 )
9763 bytes_to_copy = INBUFSIZ - gz1->insize;
9765 if ( bytes_to_copy > gz1->input_bytesleft )
9767 bytes_to_copy = gz1->input_bytesleft;
9771 (char*)gz1->inbuf+gz1->insize,
9776 gz1->input_ptr += bytes_to_copy;
9777 gz1->input_bytesleft -= bytes_to_copy;
9779 len = bytes_to_copy;
9791 (char*)gz1->inbuf+gz1->insize,
9792 INBUFSIZ-gz1->insize
9796 if (len == 0 || len == EOF) break;
9800 } while( gz1->insize < INBUFSIZ );
9802 if ( gz1->insize == 0 )
9804 if( eof_ok ) return EOF;
9808 gz1->bytes_in += (ulg) gz1->insize;
9811 return gz1->inbuf[0];
9833 c = crc_32_tab[((int)c ^ (*s++)) & 0xff] ^ (c >> 8);
9841 return( c ^ 0xffffffffL );
9844 void read_error( PGZ1 gz1 )
9849 void mod_gzip_strlwr( char *s )
9853 if ( s == 0 ) return;
9857 if ( *p1 > 96 ) *p1 = *p1 - 32;
9866 char *gz1_basename( PGZ1 gz1, char *fname )
9869 if ((p = strrchr(fname, PATH_SEP)) != NULL) fname = p+1;
9871 if ((p = strrchr(fname, PATH_SEP2)) != NULL) fname = p+1;
9874 if ((p = strrchr(fname, PATH_SEP3)) != NULL) fname = p+1;
9877 if ((p = strrchr(fname, SUFFIX_SEP)) != NULL) *p = '\0';
9879 if (casemap('A') == 'a') mod_gzip_strlwr(fname);
9883 void write_buf( PGZ1 gz1, int fd, voidp buf, unsigned cnt )
9887 if ( gz1->output_ismem )
9889 if ( ( gz1->bytes_out + cnt ) < gz1->output_maxlen )
9891 memcpy( gz1->output_ptr, buf, cnt );
9892 gz1->output_ptr += cnt;
9901 while ((n = write(fd, buf, cnt)) != cnt)
9903 if (n == (unsigned)(-1))
9908 buf = (voidp)((char*)buf+n);
9913 void write_error( PGZ1 gz1 )
9921 static ush ptr_offset = 0;
9928 void * buf = farmalloc((ulg)items*size + 16L);
9930 if (buf == NULL) return NULL;
9932 if (ptr_offset == 0)
9934 ptr_offset = (ush)((uch*)buf-0);
9936 else if (ptr_offset != (ush)((uch*)buf-0))
9938 error("inconsistent ptr_offset");
9941 *((ush*)&buf+1) += (ptr_offset + 15) >> 4;
9947 void fcfree( void *ptr )
9949 *((ush*)&ptr+1) -= (ptr_offset + 15) >> 4;
9950 *(ush*)&ptr = ptr_offset;
9966 ush deflate_flags = 0;
9972 gz1->method = DEFLATED;
9974 put_byte(GZIP_MAGIC[0]);
9975 put_byte(GZIP_MAGIC[1]);
9978 if ( gz1->save_orig_name )
9984 put_long(gz1->time_stamp);
9988 updcrc( gz1, NULL, 0 );
9990 bi_init( gz1, out );
9991 ct_init( gz1, &attr, &gz1->method );
9992 lm_init( gz1, gz1->level, &deflate_flags );
9994 put_byte((uch)deflate_flags);
9998 if ( gz1->save_orig_name )
10000 char *p = gz1_basename( gz1, gz1->ifname );
10008 gz1->header_bytes = (long)gz1->outcnt;
10010 (void) gz1_deflate( gz1 );
10012 put_long( gz1->crc );
10013 put_long( gz1->bytes_in );
10015 gz1->header_bytes += 2*sizeof(long);
10017 flush_outbuf( gz1 );
10022 ulg gz1_deflate( PGZ1 gz1 )
10024 unsigned hash_head;
10025 unsigned prev_match;
10027 int match_available = 0;
10028 register unsigned match_length = MIN_MATCH-1;
10033 if (gz1->compr_level <= 3)
10035 return gz1_deflate_fast(gz1);
10038 while (gz1->lookahead != 0)
10041 (((gz1->ins_h)<<H_SHIFT) ^ (gz1->window[gz1->strstart+MIN_MATCH-1])) & HASH_MASK;
10043 prev[ gz1->strstart & WMASK ] = hash_head = head[ gz1->ins_h ];
10045 head[ gz1->ins_h ] = gz1->strstart;
10047 gz1->prev_length = match_length, prev_match = gz1->match_start;
10048 match_length = MIN_MATCH-1;
10050 if (hash_head != NIL && gz1->prev_length < gz1->max_lazy_match &&
10051 gz1->strstart - hash_head <= MAX_DIST) {
10053 match_length = longest_match( gz1, hash_head );
10055 if (match_length > gz1->lookahead) match_length = gz1->lookahead;
10057 if (match_length == MIN_MATCH && gz1->strstart-gz1->match_start > TOO_FAR){
10063 if (gz1->prev_length >= MIN_MATCH && match_length <= gz1->prev_length) {
10065 flush = ct_tally(gz1,gz1->strstart-1-prev_match, gz1->prev_length - MIN_MATCH);
10067 gz1->lookahead -= ( gz1->prev_length - 1 );
10068 gz1->prev_length -= 2;
10074 (((gz1->ins_h)<<H_SHIFT) ^ (gz1->window[ gz1->strstart + MIN_MATCH-1])) & HASH_MASK;
10076 prev[ gz1->strstart & WMASK ] = hash_head = head[gz1->ins_h];
10078 head[ gz1->ins_h ] = gz1->strstart;
10080 } while (--gz1->prev_length != 0);
10081 match_available = 0;
10082 match_length = MIN_MATCH-1;
10084 if (flush) FLUSH_BLOCK(0), gz1->block_start = gz1->strstart;
10086 } else if (match_available) {
10088 if (ct_tally( gz1, 0, gz1->window[gz1->strstart-1] )) {
10089 FLUSH_BLOCK(0), gz1->block_start = gz1->strstart;
10095 match_available = 1;
10100 while (gz1->lookahead < MIN_LOOKAHEAD && !gz1->eofile) fill_window(gz1);
10102 if (match_available) ct_tally( gz1, 0, gz1->window[gz1->strstart-1] );
10104 return FLUSH_BLOCK(1);
10109 void flush_outbuf( PGZ1 gz1 )
10111 if ( gz1->outcnt == 0 )
10116 write_buf( gz1, gz1->ofd, (char *)gz1->outbuf, gz1->outcnt );
10118 gz1->bytes_out += (ulg)gz1->outcnt;
10128 register unsigned j;
10130 if ( pack_level < 1 || pack_level > 9 )
10132 error("bad pack level");
10135 gz1->compr_level = pack_level;
10137 #if defined(MAXSEG_64K) && HASH_BITS == 15
10138 for (j = 0; j < HASH_SIZE; j++) head[j] = NIL;
10140 memset( (char*)head, 0, (HASH_SIZE*sizeof(*head)) );
10143 gz1->max_lazy_match = configuration_table[pack_level].max_lazy;
10144 gz1->good_match = configuration_table[pack_level].good_length;
10145 #ifndef FULL_SEARCH
10146 gz1->nice_match = configuration_table[pack_level].nice_length;
10148 gz1->max_chain_length = configuration_table[pack_level].max_chain;
10150 if ( pack_level == 1 )
10154 else if ( pack_level == 9 )
10160 gz1->block_start = 0L;
10165 gz1->lookahead = read_buf(gz1,(char*)gz1->window,
10166 sizeof(int) <= 2 ? (unsigned)WSIZE : 2*WSIZE);
10168 if (gz1->lookahead == 0 || gz1->lookahead == (unsigned)EOF)
10170 gz1->eofile = 1, gz1->lookahead = 0;
10176 while (gz1->lookahead < MIN_LOOKAHEAD && !gz1->eofile)
10183 for ( j=0; j<MIN_MATCH-1; j++ )
10186 (((gz1->ins_h)<<H_SHIFT) ^ (gz1->window[j])) & HASH_MASK;
10190 void fill_window( PGZ1 gz1 )
10192 register unsigned n, m;
10195 (unsigned)( gz1->window_size - (ulg)gz1->lookahead - (ulg)gz1->strstart );
10197 if ( more == (unsigned)EOF)
10201 else if ( gz1->strstart >= WSIZE+MAX_DIST )
10203 memcpy((char*)gz1->window, (char*)gz1->window+WSIZE, (unsigned)WSIZE);
10205 gz1->match_start -= WSIZE;
10206 gz1->strstart -= WSIZE;
10208 gz1->block_start -= (long) WSIZE;
10210 for ( n = 0; n < HASH_SIZE; n++ )
10213 head[n] = (ush)(m >= WSIZE ? m-WSIZE : NIL);
10216 for ( n = 0; n < WSIZE; n++ )
10220 prev[n] = (ush)(m >= WSIZE ? m-WSIZE : NIL);
10226 if ( !gz1->eofile )
10228 n = read_buf(gz1,(char*)gz1->window+gz1->strstart+gz1->lookahead, more);
10230 if ( n == 0 || n == (unsigned)EOF )
10236 gz1->lookahead += n;
10241 ulg gz1_deflate_fast( PGZ1 gz1 )
10243 unsigned hash_head;
10245 unsigned match_length = 0;
10247 gz1->prev_length = MIN_MATCH-1;
10249 while (gz1->lookahead != 0)
10252 (((gz1->ins_h)<<H_SHIFT) ^ (gz1->window[ gz1->strstart + MIN_MATCH-1])) & HASH_MASK;
10254 prev[ gz1->strstart & WMASK ] = hash_head = head[ gz1->ins_h ];
10256 head[ gz1->ins_h ] = gz1->strstart;
10258 if (hash_head != NIL && gz1->strstart - hash_head <= MAX_DIST) {
10260 match_length = longest_match( gz1, hash_head );
10262 if (match_length > gz1->lookahead) match_length = gz1->lookahead;
10264 if (match_length >= MIN_MATCH) {
10266 flush = ct_tally(gz1,gz1->strstart-gz1->match_start, match_length - MIN_MATCH);
10268 gz1->lookahead -= match_length;
10270 if (match_length <= gz1->max_lazy_match )
10278 (((gz1->ins_h)<<H_SHIFT) ^ (gz1->window[ gz1->strstart + MIN_MATCH-1])) & HASH_MASK;
10280 prev[ gz1->strstart & WMASK ] = hash_head = head[ gz1->ins_h ];
10282 head[ gz1->ins_h ] = gz1->strstart;
10284 } while (--match_length != 0);
10287 gz1->strstart += match_length;
10289 gz1->ins_h = gz1->window[gz1->strstart];
10292 (((gz1->ins_h)<<H_SHIFT) ^ (gz1->window[gz1->strstart+1])) & HASH_MASK;
10295 Call UPDATE_HASH() MIN_MATCH-3 more times
10300 flush = ct_tally(gz1, 0, gz1->window[gz1->strstart]);
10304 if (flush) FLUSH_BLOCK(0), gz1->block_start = gz1->strstart;
10306 while (gz1->lookahead < MIN_LOOKAHEAD && !gz1->eofile) fill_window(gz1);
10309 return FLUSH_BLOCK(1);
10328 gz1->file_type = attr;
10329 gz1->file_method = methodp;
10330 gz1->compressed_len = gz1->input_len = 0L;
10332 if ( gz1->static_dtree[0].dl.len != 0 )
10339 for ( code = 0; code < LENGTH_CODES-1; code++ )
10341 gz1->base_length[code] = length;
10343 for ( n = 0; n < (1<<extra_lbits[code]); n++ )
10345 gz1->length_code[length++] = (uch)code;
10349 gz1->length_code[length-1] = (uch)code;
10353 for ( code = 0 ; code < 16; code++ )
10355 gz1->base_dist[code] = dist;
10357 for ( n = 0; n < (1<<extra_dbits[code]); n++ )
10359 gz1->dist_code[dist++] = (uch)code;
10365 for ( ; code < D_CODES; code++ )
10367 gz1->base_dist[code] = dist << 7;
10369 for ( n = 0; n < (1<<(extra_dbits[code]-7)); n++ )
10371 gz1->dist_code[256 + dist++] = (uch)code;
10375 for ( bits = 0; bits <= MAX_BITS; bits++ )
10377 gz1->bl_count[bits] = 0;
10382 while (n <= 143) gz1->static_ltree[n++].dl.len = 8, gz1->bl_count[8]++;
10383 while (n <= 255) gz1->static_ltree[n++].dl.len = 9, gz1->bl_count[9]++;
10384 while (n <= 279) gz1->static_ltree[n++].dl.len = 7, gz1->bl_count[7]++;
10385 while (n <= 287) gz1->static_ltree[n++].dl.len = 8, gz1->bl_count[8]++;
10387 gen_codes(gz1,(ct_data *)gz1->static_ltree, L_CODES+1);
10389 for ( n = 0; n < D_CODES; n++ )
10391 gz1->static_dtree[n].dl.len = 5;
10392 gz1->static_dtree[n].fc.code = bi_reverse( gz1, n, 5 );
10409 gz1->flag_buf[gz1->last_flags] = gz1->flags;
10411 if (*gz1->file_type == (ush)UNKNOWN) set_file_type(gz1);
10413 build_tree( gz1, (tree_desc *)(&gz1->l_desc) );
10414 build_tree( gz1, (tree_desc *)(&gz1->d_desc) );
10416 max_blindex = build_bl_tree( gz1 );
10418 opt_lenb = (gz1->opt_len+3+7)>>3;
10419 static_lenb = (gz1->static_len+3+7)>>3;
10420 gz1->input_len += stored_len;
10422 if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
10424 #ifdef FORCE_METHOD
10426 if ( level == 1 && eof && gz1->compressed_len == 0L )
10428 if (stored_len <= opt_lenb && eof && gz1->compressed_len == 0L && 0 )
10431 if (buf == (char*)0) error ("block vanished");
10433 copy_block( gz1, buf, (unsigned)stored_len, 0 );
10435 gz1->compressed_len = stored_len << 3;
10436 *gz1->file_method = STORED;
10438 #ifdef FORCE_METHOD
10439 } else if (level == 2 && buf != (char*)0) {
10441 } else if (stored_len+4 <= opt_lenb && buf != (char*)0) {
10445 send_bits(gz1,(STORED_BLOCK<<1)+eof, 3);
10446 gz1->compressed_len = (gz1->compressed_len + 3 + 7) & ~7L;
10447 gz1->compressed_len += (stored_len + 4) << 3;
10449 copy_block(gz1, buf, (unsigned)stored_len, 1);
10451 #ifdef FORCE_METHOD
10452 } else if (level == 3) {
10454 } else if (static_lenb == opt_lenb) {
10456 send_bits(gz1,(STATIC_TREES<<1)+eof, 3);
10460 (ct_data *)gz1->static_ltree,
10461 (ct_data *)gz1->static_dtree
10464 gz1->compressed_len += 3 + gz1->static_len;
10468 send_bits(gz1,(DYN_TREES<<1)+eof, 3);
10472 gz1->l_desc.max_code+1,
10473 gz1->d_desc.max_code+1,
10479 (ct_data *)gz1->dyn_ltree,
10480 (ct_data *)gz1->dyn_dtree
10483 gz1->compressed_len += 3 + gz1->opt_len;
10492 gz1->compressed_len += 7;
10495 return gz1->compressed_len >> 3;
10498 #ifdef __BORLANDC__
10502 unsigned bi_reverse(
10508 register unsigned res = 0;
10512 code >>= 1, res <<= 1;
10514 } while (--len > 0);
10519 void set_file_type( PGZ1 gz1 )
10522 unsigned ascii_freq = 0;
10523 unsigned bin_freq = 0;
10525 while (n < 7) bin_freq += gz1->dyn_ltree[n++].fc.freq;
10526 while (n < 128) ascii_freq += gz1->dyn_ltree[n++].fc.freq;
10527 while (n < LITERALS) bin_freq += gz1->dyn_ltree[n++].fc.freq;
10529 *gz1->file_type = bin_freq > (ascii_freq >> 2) ? BINARY : ASCII;
10532 void init_block( PGZ1 gz1 )
10536 for (n = 0; n < L_CODES; n++) gz1->dyn_ltree[n].fc.freq = 0;
10537 for (n = 0; n < D_CODES; n++) gz1->dyn_dtree[n].fc.freq = 0;
10538 for (n = 0; n < BL_CODES; n++) gz1->bl_tree[n].fc.freq = 0;
10540 gz1->dyn_ltree[END_BLOCK].fc.freq = 1;
10543 gz1->static_len = 0L;
10545 gz1->last_dist = 0;
10546 gz1->last_flags = 0;
10551 void bi_init( PGZ1 gz1, gz1_file_t zipfile )
10553 gz1->zfile = zipfile;
10557 if ( gz1->zfile != NO_FILE )
10559 read_buf = file_read;
10571 gz1->inbuf[gz1->last_lit++] = (uch)lc;
10575 gz1->dyn_ltree[lc].fc.freq++;
10581 gz1->dyn_ltree[gz1->length_code[lc]+LITERALS+1].fc.freq++;
10582 gz1->dyn_dtree[d_code(dist)].fc.freq++;
10583 gz1->d_buf[gz1->last_dist++] = (ush)dist;
10584 gz1->flags |= gz1->flag_bit;
10587 gz1->flag_bit <<= 1;
10589 if ( (gz1->last_lit & 7) == 0 )
10591 gz1->flag_buf[gz1->last_flags++] = gz1->flags;
10592 gz1->flags = 0, gz1->flag_bit = 1;
10595 if ( gz1->level > 2 && (gz1->last_lit & 0xfff) == 0)
10597 ulg out_length = (ulg) ( gz1->last_lit * 8L );
10598 ulg in_length = (ulg) ( gz1->strstart - gz1->block_start );
10600 for ( dcode = 0; dcode < D_CODES; dcode++ )
10602 out_length += (ulg) ((gz1->dyn_dtree[dcode].fc.freq)*(5L+extra_dbits[dcode]));
10607 if ( gz1->last_dist < gz1->last_lit/2 && out_length < in_length/2 )
10613 return( gz1->last_lit == LIT_BUFSIZE-1 || gz1->last_dist == DIST_BUFSIZE );
10616 void compress_block(
10631 if (gz1->last_lit != 0) do {
10632 if ((lx & 7) == 0) flag = gz1->flag_buf[fx++];
10633 lc = gz1->inbuf[lx++];
10634 if ((flag & 1) == 0) {
10635 send_code(lc, ltree);
10638 code = gz1->length_code[lc];
10639 send_code(code+LITERALS+1, ltree);
10640 extra = extra_lbits[code];
10642 lc -= gz1->base_length[code];
10643 send_bits(gz1,lc, extra);
10645 dist = gz1->d_buf[dx++];
10647 code = d_code(dist);
10649 send_code(code, dtree);
10650 extra = extra_dbits[code];
10652 dist -= gz1->base_dist[code];
10653 send_bits(gz1,dist, extra);
10657 } while (lx < gz1->last_lit);
10659 send_code(END_BLOCK, ltree);
10664 int longest_match( PGZ1 gz1, unsigned cur_match )
10666 unsigned chain_length = gz1->max_chain_length;
10667 register uch *scan = gz1->window + gz1->strstart;
10668 register uch *match;
10670 int best_len = gz1->prev_length;
10671 unsigned limit = gz1->strstart > (unsigned)MAX_DIST ? gz1->strstart - (unsigned)MAX_DIST : NIL;
10673 #if HASH_BITS < 8 || MAX_MATCH != 258
10674 error: Code too clever
10677 #ifdef UNALIGNED_OK
10679 register uch *strend = gz1->window + gz1->strstart + MAX_MATCH - 1;
10680 register ush scan_start = *(ush*)scan;
10681 register ush scan_end = *(ush*)(scan+best_len-1);
10683 register uch *strend = gz1->window + gz1->strstart + MAX_MATCH;
10684 register uch scan_end1 = scan[best_len-1];
10685 register uch scan_end = scan[best_len];
10688 if (gz1->prev_length >= gz1->good_match) {
10689 chain_length >>= 2;
10693 match = gz1->window + cur_match;
10695 #if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
10697 if (*(ush*)(match+best_len-1) != scan_end ||
10698 *(ush*)match != scan_start) continue;
10702 } while (*(ush*)(scan+=2) == *(ush*)(match+=2) &&
10703 *(ush*)(scan+=2) == *(ush*)(match+=2) &&
10704 *(ush*)(scan+=2) == *(ush*)(match+=2) &&
10705 *(ush*)(scan+=2) == *(ush*)(match+=2) &&
10708 if (*scan == *match) scan++;
10710 len = (MAX_MATCH - 1) - (int)(strend-scan);
10711 scan = strend - (MAX_MATCH-1);
10713 if (match[best_len] != scan_end ||
10714 match[best_len-1] != scan_end1 ||
10716 *++match != scan[1]) continue;
10718 scan += 2, match++;
10721 } while (*++scan == *++match && *++scan == *++match &&
10722 *++scan == *++match && *++scan == *++match &&
10723 *++scan == *++match && *++scan == *++match &&
10724 *++scan == *++match && *++scan == *++match &&
10727 len = MAX_MATCH - (int)(strend - scan);
10728 scan = strend - MAX_MATCH;
10730 if (len > best_len) {
10731 gz1->match_start = cur_match;
10733 if (len >= gz1->nice_match) break;
10734 #ifdef UNALIGNED_OK
10735 scan_end = *(ush*)(scan+best_len-1);
10737 scan_end1 = scan[best_len-1];
10738 scan_end = scan[best_len];
10741 } while ((cur_match = prev[cur_match & WMASK]) > limit
10742 && --chain_length != 0);
10754 if ( gz1->bi_valid > (int) BUFSIZE - length )
10756 gz1->bi_buf |= (value << gz1->bi_valid);
10758 put_short(gz1->bi_buf);
10760 gz1->bi_buf = (ush)value >> (BUFSIZE - gz1->bi_valid);
10761 gz1->bi_valid += length - BUFSIZE;
10765 gz1->bi_buf |= value << gz1->bi_valid;
10766 gz1->bi_valid += length;
10775 int elems = desc->elems;
10776 ct_data *tree = desc->dyn_tree;
10777 ct_data *stree = desc->static_tree;
10785 gz1->heap_len = 0, gz1->heap_max = HEAP_SIZE;
10787 for (n = 0; n < elems; n++) {
10788 if (tree[n].fc.freq != 0) {
10789 gz1->heap[++gz1->heap_len] = max_code = n;
10792 tree[n].dl.len = 0;
10796 while (gz1->heap_len < 2) {
10797 new1 = gz1->heap[++gz1->heap_len] = (max_code < 2 ? ++max_code : 0);
10798 tree[new1].fc.freq = 1;
10799 gz1->depth[new1] = 0;
10800 gz1->opt_len--; if (stree) gz1->static_len -= stree[new1].dl.len;
10802 desc->max_code = max_code;
10804 for (n = gz1->heap_len/2; n >= 1; n--) pqdownheap(gz1, tree, n);
10807 n = gz1->heap[SMALLEST];
10808 gz1->heap[SMALLEST] = gz1->heap[gz1->heap_len--];
10809 pqdownheap(gz1, tree, SMALLEST);
10810 m = gz1->heap[SMALLEST];
10811 gz1->heap[--gz1->heap_max] = n;
10812 gz1->heap[--gz1->heap_max] = m;
10813 tree[node].fc.freq = tree[n].fc.freq + tree[m].fc.freq;
10814 gz1->depth[node] = (uch) (GZ1_MAX(gz1->depth[n], gz1->depth[m]) + 1);
10815 tree[n].dl.dad = tree[m].dl.dad = (ush)node;
10816 gz1->heap[SMALLEST] = node++;
10817 pqdownheap(gz1, tree, SMALLEST);
10819 } while (gz1->heap_len >= 2);
10821 gz1->heap[--gz1->heap_max] = gz1->heap[SMALLEST];
10823 gen_bitlen(gz1,(tree_desc *)desc);
10825 gen_codes(gz1,(ct_data *)tree, max_code);
10828 int build_bl_tree( PGZ1 gz1 )
10832 scan_tree( gz1, (ct_data *)gz1->dyn_ltree, gz1->l_desc.max_code );
10833 scan_tree( gz1, (ct_data *)gz1->dyn_dtree, gz1->d_desc.max_code );
10835 build_tree( gz1, (tree_desc *)(&gz1->bl_desc) );
10837 for ( max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex-- )
10839 if (gz1->bl_tree[bl_order[max_blindex]].dl.len != 0) break;
10842 gz1->opt_len += 3*(max_blindex+1) + 5+5+4;
10844 return max_blindex;
10853 ush next_code[MAX_BITS+1];
10858 for ( bits = 1; bits <= MAX_BITS; bits++ )
10860 next_code[bits] = code = (code + gz1->bl_count[bits-1]) << 1;
10863 for ( n = 0; n <= max_code; n++ )
10865 int len = tree[n].dl.len;
10866 if (len == 0) continue;
10868 tree[n].fc.code = bi_reverse( gz1, next_code[len]++, len );
10879 ct_data *tree = desc->dyn_tree;
10880 int *extra = desc->extra_bits;
10881 int base = desc->extra_base;
10882 int max_code = desc->max_code;
10883 int max_length = desc->max_length;
10884 ct_data *stree = desc->static_tree;
10892 for (bits = 0; bits <= MAX_BITS; bits++) gz1->bl_count[bits] = 0;
10894 tree[gz1->heap[gz1->heap_max]].dl.len = 0;
10896 for (h = gz1->heap_max+1; h < HEAP_SIZE; h++) {
10898 bits = tree[tree[n].dl.dad].dl.len + 1;
10899 if (bits > max_length) bits = max_length, overflow++;
10900 tree[n].dl.len = (ush)bits;
10902 if (n > max_code) continue;
10904 gz1->bl_count[bits]++;
10906 if (n >= base) xbits = extra[n-base];
10907 f = tree[n].fc.freq;
10908 gz1->opt_len += (ulg)f * (bits + xbits);
10909 if (stree) gz1->static_len += (ulg)f * (stree[n].dl.len + xbits);
10911 if (overflow == 0) return;
10914 bits = max_length-1;
10915 while (gz1->bl_count[bits] == 0) bits--;
10916 gz1->bl_count[bits]--;
10917 gz1->bl_count[bits+1] += 2;
10918 gz1->bl_count[max_length]--;
10921 } while (overflow > 0);
10923 for (bits = max_length; bits != 0; bits--) {
10924 n = gz1->bl_count[bits];
10926 m = gz1->heap[--h];
10927 if (m > max_code) continue;
10928 if (tree[m].dl.len != (unsigned) bits) {
10929 gz1->opt_len += ((long)bits-(long)tree[m].dl.len)*(long)tree[m].fc.freq;
10930 tree[m].dl.len = (ush)bits;
10952 put_short((ush)len);
10953 put_short((ush)~len);
10959 if (key) zencode(*buf, t);
10966 int file_read( PGZ1 gz1, char *buf, unsigned size )
10969 unsigned bytes_to_copy = 0;
10971 if ( gz1->input_ismem )
10973 if ( gz1->input_bytesleft > 0 )
10975 bytes_to_copy = size;
10977 if ( bytes_to_copy > (unsigned) gz1->input_bytesleft )
10979 bytes_to_copy = (unsigned) gz1->input_bytesleft;
10982 memcpy( buf, gz1->input_ptr, bytes_to_copy );
10984 gz1->input_ptr += bytes_to_copy;
10985 gz1->input_bytesleft -= bytes_to_copy;
10987 len = bytes_to_copy;
10996 len = read( gz1->ifd, buf, size );
10999 if ( len == (unsigned)(-1) || len == 0 )
11001 gz1->crc = gz1->crc ^ 0xffffffffL;
11005 updcrc( gz1, (uch*)buf, len );
11006 gz1->bytes_in += (ulg)len;
11011 void bi_windup( PGZ1 gz1 )
11013 if ( gz1->bi_valid > 8 )
11015 put_short(gz1->bi_buf);
11017 else if ( gz1->bi_valid > 0 )
11019 put_byte(gz1->bi_buf);
11026 void send_all_trees(
11035 send_bits(gz1,lcodes-257, 5);
11036 send_bits(gz1,dcodes-1, 5);
11037 send_bits(gz1,blcodes-4, 4);
11039 for ( rank = 0; rank < blcodes; rank++ )
11041 send_bits(gz1,gz1->bl_tree[bl_order[rank]].dl.len, 3 );
11044 send_tree(gz1,(ct_data *)gz1->dyn_ltree, lcodes-1);
11045 send_tree(gz1,(ct_data *)gz1->dyn_dtree, dcodes-1);
11057 int nextlen = tree[0].dl.len;
11062 if (nextlen == 0) max_count = 138, min_count = 3;
11064 for ( n = 0; n <= max_code; n++ )
11067 nextlen = tree[n+1].dl.len;
11069 if (++count < max_count && curlen == nextlen)
11073 else if (count < min_count)
11075 do { send_code(curlen, gz1->bl_tree); } while (--count != 0);
11077 else if (curlen != 0)
11079 if ( curlen != prevlen )
11081 send_code(curlen, gz1->bl_tree); count--;
11084 send_code( REP_3_6, gz1->bl_tree ); send_bits(gz1,count-3, 2);
11086 else if (count <= 10)
11088 send_code(REPZ_3_10, gz1->bl_tree); send_bits(gz1,count-3, 3);
11092 send_code(REPZ_11_138, gz1->bl_tree); send_bits(gz1,count-11, 7);
11100 max_count = 138, min_count = 3;
11102 else if (curlen == nextlen)
11104 max_count = 6, min_count = 3;
11108 max_count = 7, min_count = 4;
11122 int nextlen = tree[0].dl.len;
11127 if (nextlen == 0) max_count = 138, min_count = 3;
11129 tree[max_code+1].dl.len = (ush)0xffff;
11131 for ( n = 0; n <= max_code; n++ )
11134 nextlen = tree[n+1].dl.len;
11136 if ( ++count < max_count && curlen == nextlen )
11140 else if ( count < min_count )
11142 gz1->bl_tree[curlen].fc.freq += count;
11144 else if ( curlen != 0 )
11146 if ( curlen != prevlen ) gz1->bl_tree[curlen].fc.freq++;
11147 gz1->bl_tree[REP_3_6].fc.freq++;
11149 else if ( count <= 10 )
11151 gz1->bl_tree[REPZ_3_10].fc.freq++;
11155 gz1->bl_tree[REPZ_11_138].fc.freq++;
11161 if ( nextlen == 0 )
11166 else if (curlen == nextlen)
11185 int v = gz1->heap[k];
11188 while( j <= gz1->heap_len )
11190 if (j < gz1->heap_len && smaller(tree, gz1->heap[j+1], gz1->heap[j])) j++;
11192 if (smaller(tree, v, gz1->heap[j])) break;
11194 gz1->heap[k] = gz1->heap[j]; k = j;
11204 #define GZS_DEFLATE1 3
11205 #define GZS_DEFLATE2 4
11207 int gzs_fsp ( PGZ1 gz1 );
11208 int gzs_zip1 ( PGZ1 gz1 );
11209 int gzs_zip2 ( PGZ1 gz1 );
11210 int gzs_deflate1( PGZ1 gz1 );
11211 int gzs_deflate2( PGZ1 gz1 );
11213 int gzp_main( request_rec *r, GZP_CONTROL *gzp )
11215 char cn[]="gzp_main()";
11219 int final_exit_code = 0;
11220 int ofile_flags = O_RDWR | O_CREAT | O_TRUNC | O_BINARY;
11222 gzp->result_code = 0;
11223 gzp->bytes_out = 0;
11225 gz1 = (PGZ1) gz1_init();
11232 gz1->decompress = gzp->decompress;
11234 mod_gzip_strcpy( gz1->ifname, gzp->input_filename );
11235 mod_gzip_strcpy( gz1->ofname, gzp->output_filename );
11237 gz1->input_ismem = gzp->input_ismem;
11238 gz1->input_ptr = gzp->input_ismem_ibuf + gzp->input_offset;
11239 gz1->input_bytesleft = gzp->input_ismem_ibuflen;
11241 gz1->output_ismem = gzp->output_ismem;
11242 gz1->output_ptr = gzp->output_ismem_obuf;
11243 gz1->output_maxlen = gzp->output_ismem_obuflen;
11245 if ( gz1->no_time < 0 ) gz1->no_time = gz1->decompress;
11246 if ( gz1->no_name < 0 ) gz1->no_name = gz1->decompress;
11250 if ( !gz1->input_ismem )
11254 rc = stat( gz1->ifname, &gz1->istat );
11258 ap_log_error( "",0,APLOG_NOERRNO|APLOG_DEBUG, r->server,
11259 "%s: stat(gz1->ifname=%s) FAILED", cn, gz1->ifname );
11261 gz1_cleanup( gz1 );
11266 gz1->ifile_size = ( gz1->istat.st_size - gzp->input_offset );
11268 if ( gz1->ifile_size < 0 ) gz1->ifile_size = 0;
11273 gz1->ascii && !gz1->decompress ? O_RDONLY : O_RDONLY | O_BINARY,
11277 if ( gz1->ifd == -1 )
11279 ap_log_error( "",0,APLOG_NOERRNO|APLOG_DEBUG, r->server,
11280 "%s: OPEN(gz1->ifname=%s) FAILED", cn, gz1->ifname );
11282 gz1_cleanup( gz1 );
11287 if ( gzp->input_offset > 0 )
11289 SEEKFORWARD( gz1->ifd, gzp->input_offset );
11293 if ( !gz1->output_ismem )
11295 if ( gz1->ascii && gz1->decompress )
11297 ofile_flags &= ~O_BINARY;
11300 gz1->ofd = OPEN( gz1->ofname, ofile_flags, RW_USER );
11302 if ( gz1->ofd == -1 )
11304 ap_log_error( "",0,APLOG_NOERRNO|APLOG_DEBUG, r->server,
11305 "%s: OPEN(gz1->ofname=%s) FAILED", cn, gz1->ofname );
11313 gz1_cleanup( gz1 );
11322 gz1->bytes_in = 0L;
11323 gz1->bytes_out = 0L;
11326 if ( gz1->decompress )
11328 gz1->method = get_header( gz1, gz1->ifd );
11330 if ( gz1->method < 0 )
11348 gz1->save_orig_name = 0;
11350 gz1->state = GZS_ZIP1;
11356 if ( gz1->done == 1 ) break;
11371 gzp->result_code = gz1->exit_code;
11372 gzp->bytes_out = gz1->bytes_out;
11374 final_exit_code = (int) gz1->exit_code;
11376 gz1_cleanup( gz1 );
11378 return final_exit_code;
11381 int gzs_fsp( PGZ1 gz1 )
11385 switch( gz1->state )
11389 rc = gzs_zip1( gz1 );
11395 rc = gzs_zip2( gz1 );
11401 rc = gzs_deflate1( gz1 );
11407 rc = gzs_deflate2( gz1 );
11421 int gzs_zip1( PGZ1 gz1 )
11427 ush deflate_flags = 0;
11432 gz1->method = DEFLATED;
11434 put_byte(GZIP_MAGIC[0]);
11435 put_byte(GZIP_MAGIC[1]);
11436 put_byte(DEFLATED);
11438 if ( gz1->save_orig_name )
11440 flags |= ORIG_NAME;
11444 put_long(gz1->time_stamp);
11448 updcrc( gz1, NULL, 0 );
11450 gz1->state = GZS_ZIP2;
11455 int gzs_zip2( PGZ1 gz1 )
11462 ush deflate_flags = 0;
11464 bi_init( gz1, gz1->ofd );
11465 ct_init( gz1, &attr, &gz1->method );
11466 lm_init( gz1, gz1->level, &deflate_flags );
11467 put_byte((uch)deflate_flags);
11471 if ( gz1->save_orig_name )
11473 char *p = gz1_basename( gz1, gz1->ifname );
11481 gz1->header_bytes = (long)gz1->outcnt;
11483 gz1->state = GZS_DEFLATE1;
11488 int gzs_deflate1( PGZ1 gz1 )
11490 if ( !gz1->deflate1_initialized )
11492 gz1->deflate1_match_available = 0;
11493 gz1->deflate1_match_length = MIN_MATCH-1;
11494 gz1->deflate1_initialized = 1;
11497 if ( gz1->compr_level <= 3 )
11504 if ( gz1->lookahead == 0 )
11506 if ( gz1->deflate1_match_available )
11508 ct_tally( gz1, 0, gz1->window[gz1->strstart-1] );
11511 gz1->state = GZS_DEFLATE2;
11513 return (int) FLUSH_BLOCK(1);
11516 #ifdef STAY_HERE_FOR_A_CERTAIN_AMOUNT_OF_ITERATIONS
11518 while( iterations < max_iterations_per_yield )
11523 (((gz1->ins_h)<<H_SHIFT) ^ (gz1->window[gz1->strstart+MIN_MATCH-1])) & HASH_MASK;
11525 prev[ gz1->strstart & WMASK ] = gz1->deflate1_hash_head = head[ gz1->ins_h ];
11527 head[ gz1->ins_h ] = gz1->strstart;
11529 gz1->prev_length = gz1->deflate1_match_length, gz1->deflate1_prev_match = gz1->match_start;
11530 gz1->deflate1_match_length = MIN_MATCH-1;
11532 if ( gz1->deflate1_hash_head != NIL && gz1->prev_length < gz1->max_lazy_match &&
11533 gz1->strstart - gz1->deflate1_hash_head <= MAX_DIST)
11535 gz1->deflate1_match_length = longest_match( gz1, gz1->deflate1_hash_head );
11537 if ( gz1->deflate1_match_length > gz1->lookahead )
11539 gz1->deflate1_match_length = gz1->lookahead;
11542 if (gz1->deflate1_match_length == MIN_MATCH && gz1->strstart-gz1->match_start > TOO_FAR)
11544 gz1->deflate1_match_length--;
11548 if ( gz1->prev_length >= MIN_MATCH && gz1->deflate1_match_length <= gz1->prev_length )
11550 gz1->deflate1_flush =
11551 ct_tally(gz1,gz1->strstart-1-gz1->deflate1_prev_match, gz1->prev_length - MIN_MATCH);
11553 gz1->lookahead -= ( gz1->prev_length - 1 );
11554 gz1->prev_length -= 2;
11560 (((gz1->ins_h)<<H_SHIFT) ^ (gz1->window[ gz1->strstart + MIN_MATCH-1])) & HASH_MASK;
11562 prev[ gz1->strstart & WMASK ] = gz1->deflate1_hash_head = head[gz1->ins_h];
11564 head[ gz1->ins_h ] = gz1->strstart;
11566 } while (--gz1->prev_length != 0);
11568 gz1->deflate1_match_available = 0;
11569 gz1->deflate1_match_length = MIN_MATCH-1;
11573 if (gz1->deflate1_flush) FLUSH_BLOCK(0), gz1->block_start = gz1->strstart;
11578 if ( gz1->deflate1_match_available )
11580 if ( ct_tally( gz1, 0, gz1->window[gz1->strstart-1] ) )
11582 FLUSH_BLOCK(0), gz1->block_start = gz1->strstart;
11590 gz1->deflate1_match_available = 1;
11595 while (gz1->lookahead < MIN_LOOKAHEAD && !gz1->eofile )
11604 int gzs_deflate2( PGZ1 gz1 )
11606 #if !defined(NO_SIZE_CHECK) && !defined(RECORD_IO)
11607 if (gz1->ifile_size != -1L && gz1->isize != (ulg)gz1->ifile_size)
11612 put_long( gz1->crc );
11613 put_long( gz1->bytes_in );
11615 gz1->header_bytes += 2*sizeof(long);
11617 flush_outbuf( gz1 );
11624 /*--------------------------------------------------------------------------*/
11625 /* COMPRESSION_SUPPORT: END */
11626 /*--------------------------------------------------------------------------*/