📄 mod_gzip.c.orig
字号:
/* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2000 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * Portions of this software are based upon public domain software * originally written at the National Center for Supercomputing Applications, * University of Illinois, Urbana-Champaign. *//* MOD_GZIP 2.0.26a *//* NOTE: This modules is written for the Apache 2.x series only *//* and will not compile correctly against the Apache 1.x series. */#include "httpd.h"#include "http_config.h"#include "http_log.h"#include "apr_strings.h"#include "apr_general.h"#include "util_filter.h"#include "apr_buckets.h"#include "http_request.h"#include "http_protocol.h"/* NOTE: Since Apache 2.0 is using APRLIB then we now have to *//* manually include certain system headers that would have been *//* included automatically at this point in a pre-2.0 compile... */#include <sys/stat.h> /* For stat() call *//* Version information... */char mod_gzip_version[] = "2.0.26.1a";#define MOD_GZIP_VERSION_INFO_STRING "mod_gzip/2.0.26.1a"/* For now just use ZLIB... */#define MOD_GZIP_USES_ZLIB#ifdef MOD_GZIP_USES_ZLIB/* The ZLIB/LIBPNG Public License...ZLIB (C) 1995-1998 Jean-loup Gailly and Mark AdlerThis software is provided 'as-is', without any express or impliedwarranty. In no event will the authors be held liable for any damagesarising from the use of this software.Permission is granted to anyone to use this software for any purpose,including commercial applications, and to alter it and redistribute itfreely, subject to the following restrictions:1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.3. This notice may not be removed or altered from any source distribution.Jean-loup Gailly Mark Adlerjloup@gzip.org madler@alumni.caltech.edu*/#include "zlib.h" /* Standard ZLIB header *//* NOTE: ZUTIL.H is not normally found in binary only distributions *//* of ZLIB. It comes from the ZLIB source directories. *//* The only real dependency on ZUTIL.H is for the OS_CODE define *//* ( which is part of the LZ77 deflate() header ) but the OS_CODE *//* definitions are complex so for now, ZUTIL.H has to be required. */#include "zutil.h" /* Contains OS_CODE definition(s) */#define MOD_GZIP_ZLIB_WINDOWSIZE -15#define MOD_GZIP_ZLIB_CFACTOR 9#define MOD_GZIP_ZLIB_BSIZE 8096/* ZLIB's deflate() compression algorithm uses the same *//* 0-9 based scale that GZIP does where '1' is 'Best speed' *//* and '9' is 'Best compression'. Testing has proved level '6' *//* to be about the best level to use in an HTTP Server. */#define MOD_GZIP_DEFLATE_DEFAULT_COMPRESSION_LEVEL 6static int zlib_gzip_magic[2] = { 0x1f, 0x8b };typedef struct zlib_context{ z_stream strm; char buffer[MOD_GZIP_ZLIB_BSIZE]; unsigned long crc;}zlib_context;#endif /* MOD_GZIP_USES_ZLIB *//* * Declare the internal module 'name'... */module AP_MODULE_DECLARE_DATA gzip_module;/* * Apache 2.x filters need a NAME... */static const char mod_gzip_filter_name[] = "GZIP";/* * Turn MOD_GZIP_USES_APACHE_LOGS switch ON to include the * code that can update Apache logs with compression information. */#define MOD_GZIP_USES_APACHE_LOGS/* * Turn MOD_GZIP_DEBUG1 switch ON to include debug code. * This is normally OFF by default and should only be * used for diagnosing problems. The log output is * VERY detailed and the log files will be HUGE. */ #define MOD_GZIP_DEBUG1/* * Turn this 'define' on to send all DEBUG log output to * Apache error_log instead of a flat file. "LogLevel debug" * must be set in httpd.conf for log output to appear in error_log. *//*#define MOD_GZIP_DEBUG_LOG_IS_APACHE_LOG*//* * Other globals... */#ifndef MOD_GZIP_MAX_PATH_LEN#define MOD_GZIP_MAX_PATH_LEN 512#endif#ifdef WIN32char mod_gzip_dirsep[]="\\"; #else char mod_gzip_dirsep[]="/"; #endif #define MOD_GZIP_IMAP_MAXNAMES 256#define MOD_GZIP_IMAP_MAXNAMELEN 90#define MOD_GZIP_IMAP_ISNONE 0#define MOD_GZIP_IMAP_ISMIME 1#define MOD_GZIP_IMAP_ISHANDLER 2#define MOD_GZIP_IMAP_ISFILE 3#define MOD_GZIP_IMAP_ISURI 4#define MOD_GZIP_IMAP_ISREQHEADER 5#define MOD_GZIP_IMAP_ISRSPHEADER 6#define MOD_GZIP_IMAP_ISPORT 7#define MOD_GZIP_IMAP_ISADDRESS 8#define MOD_GZIP_IMAP_STATIC1 9001#define MOD_GZIP_IMAP_DYNAMIC1 9002#define MOD_GZIP_IMAP_DYNAMIC2 9003#define MOD_GZIP_IMAP_DECLINED1 9004#define MOD_GZIP_REQUEST 9005#define MOD_GZIP_RESPONSE 9006typedef struct { int include; int type; int action; int direction; unsigned port; int len1; regex_t *pregex; char name[ MOD_GZIP_IMAP_MAXNAMELEN + 2 ]; int namelen; } mod_gzip_imap;int mod_gzip_imap_size = (int) sizeof( mod_gzip_imap );#define MOD_GZIP_CONFIG_MODE_SERVER 1#define MOD_GZIP_CONFIG_MODE_DIRECTORY 2#define MOD_GZIP_CONFIG_MODE_COMBO 3typedef struct { int cmode; char *loc; int is_on; int is_on_set; int keep_workfiles; int keep_workfiles_set; int dechunk; int dechunk_set; int add_header_count; int add_header_count_set; int min_http; int min_http_set; long minimum_file_size; int minimum_file_size_set; long maximum_file_size; int maximum_file_size_set; long maximum_inmem_size; int maximum_inmem_size_set; int deflate_compression_level; int deflate_compression_level_set; char temp_dir[256]; /* Length is safety-checked during startup */ int temp_dir_set; int imap_total_entries; int imap_total_ismime; int imap_total_isfile; int imap_total_isuri; int imap_total_ishandler; int imap_total_isreqheader; int imap_total_isrspheader; mod_gzip_imap imap[ MOD_GZIP_IMAP_MAXNAMES + 1 ]; #define MOD_GZIP_COMMAND_VERSION_USED #ifdef MOD_GZIP_COMMAND_VERSION_USED #define MOD_GZIP_COMMAND_VERSION 8001 #define MOD_GZIP_COMMAND_VERSION_MAXLEN 128 char command_version[ MOD_GZIP_COMMAND_VERSION_MAXLEN + 1 ]; int command_version_set; #endif #define MOD_GZIP_CAN_NEGOTIATE #ifdef MOD_GZIP_CAN_NEGOTIATE int can_negotiate; int can_negotiate_set; #endif} mod_gzip_conf;#ifdef MOD_GZIP_DEBUG1server_rec *mod_gzip_server_now = 0;#endif#ifdef MOD_GZIP_DEBUG_LOG_IS_APACHE_LOGvoid mod_gzip_printf( const char *fmt, ... ){ int l; va_list ap; char log_line[2048]; va_start( ap, fmt ); l = vsprintf( log_line, fmt, ap ); va_end(ap); ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_DEBUG, 0, mod_gzip_server_now, log_line ); return;}#else /* !MOD_GZIP_DEBUG_LOG_IS_APACHE_LOG */void mod_gzip_printf( const char *fmt, ... ){ int l; char *p1; FILE *log; va_list ap; char logname[256]; char log_line[4096]; #ifdef WIN32 long pid = GetCurrentProcessId(); #else long pid = (long) getpid(); #endif #ifdef WIN32 sprintf( logname, "c:\\temp\\t%ld.log",(long)pid); #else sprintf( logname, "/tmp/t%ld.log",(long)pid); #endif /* WARNING: Keep in mind that depending on the 'temp' */ /* directory permissions for UNIX the fact that PID is */ /* being used as part of the log filename in order to */ /* separate the request logs means that someone MAY be */ /* able to see the actual PID of the Sever process when */ /* DEBUG is running and (perhaps) do some of the weird */ /* hacks that are always possible under UNIX when you */ /* know a given process ID. Run debug only in a secure */ /* environment if you are prone to worry about such things. */ log = fopen( logname,"a" ); if ( !log ) { return; } va_start( ap, fmt ); l = vsprintf(log_line, fmt, ap); p1=log_line; while((*p1!=0)&&(*p1!=13)&&(*p1!=10)) p1++; *p1=0; fprintf( log, "%s\n", log_line ); fclose( log ); va_end(ap); return; }#endif /* MOD_GZIP_DEBUG_LOG_IS_APACHE_LOG *//* Thread safe FAST string handlers... */int mod_gzip_strncmp( char *s1, char *s2, int len1 );int mod_gzip_strnicmp( char *s1, char *s2, int len1 );int mod_gzip_strcpy( char *s1, char *s2 );int mod_gzip_strcat( char *s1, char *s2 );int mod_gzip_strlen( char *s1 );int mod_gzip_stringcontains( char *source, char *substring );int mod_gzip_strendswith( char *s1, char *s2, int ignorcase );int mod_gzip_strncmp( char *s1, char *s2, int len1 ){ int i; char ch1; char ch2; if ( ( s1 == 0 ) || ( s2 == 0 ) ) { return 1; } for ( i=0; i<len1; i++ ) { if ( ( *s1 == 0 ) || ( *s2 == 0 ) ) return( 1 ); ch1 = *s1; ch2 = *s2; if ( ch1 == '/' ) ch1 = '\\'; if ( ch2 == '/' ) ch2 = '\\'; if ( ch1 != ch2 ) return 1; s1++; s2++; } return 0;}int mod_gzip_strnicmp( char *s1, char *s2, int len1 ){ int i; char ch1; char ch2; if ( ( s1 == 0 ) || ( s2 == 0 ) ) { return 1; } for ( i=0; i<len1; i++ ) { if ( ( *s1 == 0 ) || ( *s2 == 0 ) ) return( 1 ); ch1 = *s1; ch2 = *s2; if ( ch1 > 96 ) ch1 -= 32; if ( ch2 > 96 ) ch2 -= 32; if ( ch1 == '/' ) ch1 = '\\';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -