"Fossies" - the Fresh Open Source Software Archive 
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1
2 /* ====================================================================
3 *
4 * MOD_GZIP.C - Version 1.3.26.1a
5 *
6 * This program was developed by
7 *
8 * Remote Communications, Inc.
9 * Home page: http://www.RemoteCommunications.com
10 *
11 * and is currently maintained by
12 *
13 * Christian Kruse, <ckruse@wwwtech.de> and Michael Schroepl,
14 * <michael@schroepl.net>
15 * Home page: http://sourceforge.net/projects/mod-gzip/
16 *
17 * Original author: Kevin Kiley, CTO, Remote Communications, Inc.
18 * Email: Kiley@RemoteCommunications.com
19 *
20 * As of this writing there is an online support forum which
21 * anyone may join by following the instructions found at...
22 * http://lists.over.net/mailman/listinfo/mod_gzip
23 *
24 * ====================================================================
25 */
26
27 /* APACHE LICENSE: START
28 *
29 * Portions of this software are covered under the following license
30 * which, as it states, must remain included in this source code
31 * module and may not be altered in any way.
32 */
33
34 /* ====================================================================
35 * The Apache Software License, Version 1.1
36 *
37 * Copyright (c) 2000 The Apache Software Foundation. All rights
38 * reserved.
39 *
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
42 * are met:
43 *
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 *
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in
49 * the documentation and/or other materials provided with the
50 * distribution.
51 *
52 * 3. The end-user documentation included with the redistribution,
53 * if any, must include the following acknowledgment:
54 * "This product includes software developed by the
55 * Apache Software Foundation (http://www.apache.org/)."
56 * Alternately, this acknowledgment may appear in the software itself,
57 * if and wherever such third-party acknowledgments normally appear.
58 *
59 * 4. The names "Apache" and "Apache Software Foundation" must
60 * not be used to endorse or promote products derived from this
61 * software without prior written permission. For written
62 * permission, please contact apache@apache.org.
63 *
64 * 5. Products derived from this software may not be called "Apache",
65 * nor may "Apache" appear in their name, without prior written
66 * permission of the Apache Software Foundation.
67 *
68 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
69 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
70 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
71 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
72 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
73 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
74 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
75 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
76 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
77 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
78 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
79 * SUCH DAMAGE.
80 * ====================================================================
81 *
82 * This software consists of voluntary contributions made by many
83 * individuals on behalf of the Apache Software Foundation. For more
84 * information on the Apache Software Foundation, please see
85 * <http://www.apache.org/>.
86 *
87 * Portions of this software are based upon public domain software
88 * originally written at the National Center for Supercomputing Applications,
89 * University of Illinois, Urbana-Champaign.
90 */
91
92 /* APACHE LICENSE: END */
93
94 #define CORE_PRIVATE
95
96 #include "httpd.h"
97 #include "http_config.h"
98 #include "http_core.h"
99 #include "http_log.h"
100 #include "http_main.h"
101 #include "http_protocol.h"
102 #include "http_request.h"
103 #include "util_script.h"
104
105 #include "mod_gzip.h"
106
107 #ifdef MOD_GZIP_DEBUG1
108 #include "mod_gzip_debug.h"
109 #endif
110
111 extern API_VAR_EXPORT char ap_server_root[ MAX_STRING_LEN ];
112
113 static char mod_gzip_version[] = "1.3.26.1a";
114
115 int mod_gzip_imap_size = (int) sizeof( mod_gzip_imap );
116 long mod_gzip_iusn = 0;
117 static char mod_gzip_check_permissions[] = "Make sure all named directories exist and have the correct permissions.";
118
119
120 int mod_gzip_validate1(
121 request_rec *r,
122 mod_gzip_conf *mgc,
123 char *r__filename,
124 char *r__uri,
125 char *r__content_type,
126 char *r__handler,
127 char *fieldkey,
128 char *fieldstring,
129 int direction
130 )
131 {
132 int x = 0;
133 int clen = 0;
134 int hlen = 0;
135 int flen = 0;
136 int ulen = 0;
137 int pass = 0;
138 int passes = 2;
139 char *this_name = 0;
140 int this_type = 0;
141 int this_len1 = 0;
142 int this_action = 0;
143 int this_include = 0;
144 char *checktarget = 0;
145 int pass_result = 0;
146 int action_value = 0;
147 int filter_value = 0;
148 int type_to_match = 0;
149 int ok_to_check_it = 0;
150 int http_field_check = 0;
151 int item_is_included = 0;
152 int item_is_excluded = 0;
153 int type_is_included = 0;
154 int remove_vary = 0;
155
156 regex_t *this_pregex = NULL;
157 int regex_error = 0;
158
159 #ifdef MOD_GZIP_DEBUG1
160 char cn[]="mod_gzip_validate1()";
161 #endif
162
163 if ( r__filename ) flen = mod_gzip_strlen( (char *) r__filename );
164 if ( r__uri ) ulen = mod_gzip_strlen( (char *) r__uri );
165 if ( r__content_type ) clen = mod_gzip_strlen( (char *) r__content_type );
166 if ( r__handler ) hlen = mod_gzip_strlen( (char *) r__handler );
167
168 #ifdef MOD_GZIP_DEBUG1
169
170 mod_gzip_printf( "%s: Entry...",cn);
171 mod_gzip_printf( "%s: r__filename = [%s]",cn,npp(r__filename));
172 mod_gzip_printf( "%s: flen = %d", cn,flen);
173 mod_gzip_printf( "%s: r__uri = [%s]",cn,npp(r__uri));
174 mod_gzip_printf( "%s: ulen = %d", cn,ulen);
175 mod_gzip_printf( "%s: r__content_type = [%s]",cn,npp(r__content_type));
176 mod_gzip_printf( "%s: clen = %d", cn,clen);
177 mod_gzip_printf( "%s: r__handler = [%s]",cn,npp(r__handler));
178 mod_gzip_printf( "%s: hlen = %d", cn,hlen);
179 mod_gzip_printf( "%s: fieldkey = [%s]",cn,npp(fieldkey));
180 mod_gzip_printf( "%s: fieldstring = [%s]",cn,npp(fieldstring));
181 mod_gzip_printf( "%s: direction = %d", cn,direction);
182
183 #endif
184
185 if ( ( fieldkey ) && ( fieldstring ) )
186 {
187 http_field_check = 1;
188
189 passes = 1;
190
191 if ( direction == MOD_GZIP_REQUEST )
192 {
193 type_to_match = MOD_GZIP_IMAP_ISREQHEADER;
194 }
195 else if ( direction == MOD_GZIP_RESPONSE )
196 {
197 type_to_match = MOD_GZIP_IMAP_ISRSPHEADER;
198 }
199 else
200 {
201 #ifdef MOD_GZIP_DEBUG1
202 mod_gzip_printf( "%s: Invalid 'direction' value.",cn);
203 mod_gzip_printf( "%s: Must be MOD_GZIP_REQUEST or MOD_GZIP_RESPONSE",cn);
204 mod_gzip_printf( "%s: Exit > return( MOD_GZIP_IMAP_DECLINED1 ) >",cn);
205 #endif
206
207 return( MOD_GZIP_IMAP_DECLINED1 );
208 }
209 }
210
211 else if ( ( hlen == 0 ) && ( clen == 0 ) && ( flen == 0 ) )
212 {
213 #ifdef MOD_GZIP_DEBUG1
214 mod_gzip_printf( "%s: hlen = 0 = No handler name passed...",cn);
215 mod_gzip_printf( "%s: clen = 0 = No valid content-type passed",cn);
216 mod_gzip_printf( "%s: flen = 0 = No valid filename passed",cn);
217 mod_gzip_printf( "%s: There is nothing we can use to search",cn);
218 mod_gzip_printf( "%s: for a match in the inclusion/exclusion list.",cn);
219 mod_gzip_printf( "%s: Exit > return( MOD_GZIP_IMAP_DECLINED1 ) >",cn);
220 #endif
221
222 return( MOD_GZIP_IMAP_DECLINED1 );
223 }
224
225 #ifdef MOD_GZIP_DEBUG1
226 mod_gzip_printf( "%s: passes = %d", cn,
227 (int) passes );
228 mod_gzip_printf( "%s: http_field_check = %d", cn,
229 (int) http_field_check );
230 mod_gzip_printf( "%s: mgc->imap_total_entries = %d", cn,
231 (int) mgc->imap_total_entries );
232 #endif
233
234 for ( pass=0; pass<passes; pass++ )
235 {
236 pass_result = 0;
237
238 #ifdef MOD_GZIP_DEBUG1_VALIDATE1_VERBOSE1
239 #ifdef MOD_GZIP_DEBUG1
240 mod_gzip_printf( "%s: ",cn);
241 #endif
242 #endif
243
244 filter_value = pass;
245
246 #ifdef MOD_GZIP_DEBUG1_VALIDATE1_VERBOSE1
247 #ifdef MOD_GZIP_DEBUG1
248 mod_gzip_printf( "%s: pass = %d", cn, pass );
249 mod_gzip_printf( "%s: filter_value = %d", cn, filter_value );
250 mod_gzip_printf( "%s: mgc->imap_total_entries = %d", cn,
251 (int) mgc->imap_total_entries );
252 #endif
253 #endif
254
255 for ( x=0; x < mgc->imap_total_entries; x++ )
256 {
257 this_include = mgc->imap[x].include;
258 this_type = mgc->imap[x].type;
259 this_action = mgc->imap[x].action;
260
261 #ifdef MOD_GZIP_DEBUG1_VALIDATE1_VERBOSE1
262 #ifdef MOD_GZIP_DEBUG1
263
264 mod_gzip_printf( "%s: --------------------------------------------",cn);
265 mod_gzip_printf( "%s: http_field_check = %d", cn,http_field_check );
266
267 if ( http_field_check )
268 {
269 mod_gzip_printf( "%s: fieldkey = [%s]",cn,npp(fieldkey));
270 mod_gzip_printf( "%s: fieldstring = [%s]",cn,npp(fieldstring));
271 }
272 else
273 {
274 mod_gzip_printf( "%s: r__filename = [%s]",cn,npp(r__filename));
275 mod_gzip_printf( "%s: r__uri = [%s]",cn,npp(r__uri));
276 mod_gzip_printf( "%s: r__content_type = [%s]",cn,npp(r__content_type));
277 mod_gzip_printf( "%s: r__handler = [%s]",cn,npp(r__handler));
278 }
279
280 if ( this_include == 0 )
281 {
282 mod_gzip_printf( "%s: mgc->imap[%3.3d].include = %d EXCLUDE",cn,x,this_include);
283 }
284 else if ( this_include == 1 )
285 {
286 mod_gzip_printf( "%s: mgc->imap[%3.3d].include = %d INCLUDE",cn,x,this_include);
287 }
288 else
289 {
290 mod_gzip_printf( "%s: mgc->imap[%3.3d].include = %d ??? UNKNOWN VALUE",cn,x,this_include);
291 }
292
293 if ( mgc->imap[x].type == MOD_GZIP_IMAP_ISMIME )
294 {
295 mod_gzip_printf( "%s: mgc->imap[%3.3d].type = %d MOD_GZIP_IMAP_ISMIME",
296 cn,x,this_type);
297 }
298 else if ( mgc->imap[x].type == MOD_GZIP_IMAP_ISHANDLER )
299 {
300 mod_gzip_printf( "%s: mgc->imap[%3.3d].type = %d MOD_GZIP_IMAP_ISHANDLER",
301 cn,x,this_type);
302 }
303 else if ( mgc->imap[x].type == MOD_GZIP_IMAP_ISFILE )
304 {
305 mod_gzip_printf( "%s: mgc->imap[%3.3d].type = %d MOD_GZIP_IMAP_ISFILE",
306 cn,x,this_type);
307 }
308 else if ( mgc->imap[x].type == MOD_GZIP_IMAP_ISURI )
309 {
310 mod_gzip_printf( "%s: mgc->imap[%3.3d].type = %d MOD_GZIP_IMAP_ISURI",
311 cn,x,this_type);
312 }
313 else if ( mgc->imap[x].type == MOD_GZIP_IMAP_ISREQHEADER )
314 {
315 mod_gzip_printf( "%s: mgc->imap[%3.3d].type = %d MOD_GZIP_IMAP_ISREQHEADER",
316 cn,x,this_type);
317 }
318 else if ( mgc->imap[x].type == MOD_GZIP_IMAP_ISRSPHEADER )
319 {
320 mod_gzip_printf( "%s: mgc->imap[%3.3d].type = %d MOD_GZIP_IMAP_ISRSPHEADER",
321 cn,x,this_type);
322 }
323 else
324 {
325 mod_gzip_printf( "%s: mgc->imap[%3.3d].type = %d MOD_GZIP_IMAP_IS??? Unknown type",
326 cn,x,this_type);
327 }
328
329 if ( mgc->imap[x].action == MOD_GZIP_IMAP_STATIC1 )
330 {
331 mod_gzip_printf( "%s: mgc->imap[%3.3d].action = %d MOD_GZIP_IMAP_STATIC1",
332 cn,x,this_action);
333 }
334 else if ( mgc->imap[x].action == MOD_GZIP_IMAP_DYNAMIC1 )
335 {
336 mod_gzip_printf( "%s: mgc->imap[%3.3d].action = %d MOD_GZIP_IMAP_DYNAMIC1",
337 cn,x,this_action);
338 }
339 else if ( mgc->imap[x].action == MOD_GZIP_IMAP_DYNAMIC2 )
340 {
341 mod_gzip_printf( "%s: mgc->imap[%3.3d].action = %d MOD_GZIP_IMAP_DYNAMIC2",
342 cn,x,this_action);
343 }
344 else
345 {
346 mod_gzip_printf( "%s: mgc->imap[%3.3d].action = %d MOD_GZIP_IMAP_??? Unknown action",
347 cn,x,this_action);
348 }
349
350 mod_gzip_printf( "%s: mgc->imap[%3.3d].name = [%s]",cn,x,npp(mgc->imap[x].name));
351 mod_gzip_printf( "%s: mgc->imap[%3.3d].namelen = %d", cn,x,mgc->imap[x].namelen);
352
353 #endif
354 #endif
355
356 if ( this_include == filter_value )
357 {
358 #ifdef MOD_GZIP_DEBUG1_VALIDATE1_VERBOSE1
359 #ifdef MOD_GZIP_DEBUG1
360 mod_gzip_printf( "%s: This record matches filter_value %d",
361 cn, filter_value );
362 mod_gzip_printf( "%s: The record will be checked...",cn);
363 #endif
364 #endif
365
366 type_is_included = 0;
367 checktarget = 0;
368 remove_vary = 0;
369
370 if ( http_field_check )
371 {
372 if ( this_type == type_to_match )
373 {
374 type_is_included = 1;
375
376 checktarget = (char *) fieldstring;
377 }
378 }
379 else
380 {
381 if ( ( this_type == MOD_GZIP_IMAP_ISMIME ) &&
382 ( clen > 0 ) )
383 {
384 type_is_included = 1;
385
386 checktarget = r__content_type;
387 }
388 else if ( ( this_type == MOD_GZIP_IMAP_ISFILE ) &&
389 ( flen > 0 ) )
390 {
391 type_is_included = 1;
392 remove_vary = 1;
393
394 checktarget = r__filename;
395 }
396 else if ( ( this_type == MOD_GZIP_IMAP_ISURI ) &&
397 ( ulen > 0 ) )
398 {
399 type_is_included = 1;
400 remove_vary = 1;
401
402 checktarget = r__uri;
403 }
404 else if ( ( this_type == MOD_GZIP_IMAP_ISHANDLER ) &&
405 ( hlen > 0 ) )
406 {
407 type_is_included = 1;
408 remove_vary = 1;
409
410 checktarget = r__handler;
411 }
412 }
413
414 if ( type_is_included )
415 {
416 #ifdef MOD_GZIP_DEBUG1_VALIDATE1_VERBOSE1
417 #ifdef MOD_GZIP_DEBUG1
418 mod_gzip_printf( "%s: type_is_included = %d = YES",cn,type_is_included);
419 #endif
420 #endif
421
422 this_name = mgc->imap[x].name;
423 this_len1 = mgc->imap[x].len1;
424 this_pregex = mgc->imap[x].pregex;
425
426 ok_to_check_it = 1;
427
428 if ( http_field_check )
429 {
430 #ifdef MOD_GZIP_DEBUG1_VALIDATE1_VERBOSE1
431 #ifdef MOD_GZIP_DEBUG1
432 mod_gzip_printf( "%s: fieldkey = [%s]",cn,npp(fieldkey));
433 mod_gzip_printf( "%s: this_name = [%s]",cn,npp(this_name));
434 mod_gzip_printf( "%s: this_len1 = %d", cn,this_len1);
435 mod_gzip_printf( "%s: Call mod_gzip_strnicmp(fieldkey,this_name,this_len1)...",cn);
436 #endif
437 #endif
438
439 if ( mod_gzip_strnicmp( fieldkey, this_name, this_len1 )==0)
440 {
441 #ifdef MOD_GZIP_DEBUG1_VALIDATE1_VERBOSE1
442 #ifdef MOD_GZIP_DEBUG1
443 mod_gzip_printf( "%s: .... mod_gzip_strnicmp() = TRUE",cn);
444 mod_gzip_printf( "%s: .... Field key name MATCHES",cn);
445 #endif
446 #endif
447 }
448 else
449 {
450 #ifdef MOD_GZIP_DEBUG1_VALIDATE1_VERBOSE1
451 #ifdef MOD_GZIP_DEBUG1
452 mod_gzip_printf( "%s: .... mod_gzip_strnicmp() = FALSE",cn);
453 mod_gzip_printf( "%s: .... Field key name does NOT MATCH",cn);
454 #endif
455 #endif
456
457 ok_to_check_it = 0;
458 }
459 }
460
461 if ( ok_to_check_it )
462 {
463 #ifdef MOD_GZIP_DEBUG1_VALIDATE1_VERBOSE1
464 #ifdef MOD_GZIP_DEBUG1
465 mod_gzip_printf( "%s: ok_to_check_it = %d = YES",cn,ok_to_check_it);
466 #endif
467 #endif
468
469 if ( ( this_pregex ) && ( checktarget ) )
470 {
471 #ifdef MOD_GZIP_DEBUG1
472 mod_gzip_printf( "%s: 'this_pregex' is NON-NULL",cn);
473 mod_gzip_printf( "%s: Performing regular expression check...",cn);
474 mod_gzip_printf( "%s: Call ap_regexec( this_name=[%s], checktarget=[%s] )",
475 cn, npp(this_name), npp(checktarget) );
476 #endif
477
478 regex_error =
479 ap_regexec(
480 this_pregex, checktarget, 0, (regmatch_t *) NULL, 0 );
481
482 if ( regex_error == 0 )
483 {
484 #ifdef MOD_GZIP_DEBUG1
485 mod_gzip_printf( "%s: YYYY regex_error = %d = MATCH!",cn,regex_error);
486 #endif
487
488 pass_result = 1;
489 action_value = this_action;
490 break;
491 }
492 else
493 {
494 #ifdef MOD_GZIP_DEBUG1
495 mod_gzip_printf( "%s: NNNN regex_error = %d = NO MATCH!",cn,regex_error);
496 #endif
497 }
498 }
499 else
500 {
501 #ifdef MOD_GZIP_DEBUG1
502
503 if ( !this_pregex )
504 {
505 mod_gzip_printf( "%s: 'this_pregex' is NULL",cn);
506 }
507 if ( !checktarget )
508 {
509 mod_gzip_printf( "%s: 'checktarget' is NULL",cn);
510 }
511
512 mod_gzip_printf( "%s: No regular expression check performed",cn);
513
514 #endif
515 }
516 }
517 else
518 {
519 #ifdef MOD_GZIP_DEBUG1_VALIDATE1_VERBOSE1
520 #ifdef MOD_GZIP_DEBUG1
521 mod_gzip_printf( "%s: ok_to_check_it = %d = NO",cn,ok_to_check_it);
522 mod_gzip_printf( "%s: The record has been SKIPPED...",cn);
523 #endif
524 #endif
525 }
526 }
527 else
528 {
529 #ifdef MOD_GZIP_DEBUG1_VALIDATE1_VERBOSE1
530 #ifdef MOD_GZIP_DEBUG1
531 mod_gzip_printf( "%s: type_is_included = %d = NO",cn,type_is_included);
532 mod_gzip_printf( "%s: The record has been SKIPPED...",cn);
533 #endif
534 #endif
535 }
536 }
537 else
538 {
539 #ifdef MOD_GZIP_DEBUG1_VALIDATE1_VERBOSE1
540 #ifdef MOD_GZIP_DEBUG1
541 mod_gzip_printf( "%s: This record does NOT match filter_value %d",
542 cn, filter_value );
543 mod_gzip_printf( "%s: The record has been SKIPPED...",cn);
544 #endif
545 #endif
546 }
547 }
548
549 #ifdef MOD_GZIP_DEBUG1_VALIDATE1_VERBOSE1
550 #ifdef MOD_GZIP_DEBUG1
551 mod_gzip_printf( "%s: --------------------------------------------",cn);
552 mod_gzip_printf( "%s: pass_result = %d",cn,pass_result);
553 #endif
554 #endif
555
556 if ( pass_result )
557 {
558 if ( pass == 0 ) item_is_excluded = 1;
559 else item_is_included = 1;
560
561 break;
562 }
563
564 }/* End 'for ( pass=0; pass<passes; pass++ )' */
565
566 #ifdef MOD_GZIP_DEBUG1
567 mod_gzip_printf( "%s: item_is_excluded = %d",cn,item_is_excluded);
568 mod_gzip_printf( "%s: item_is_included = %d",cn,item_is_included);
569 #endif
570
571 if ( item_is_excluded )
572 {
573 #ifdef MOD_GZIP_DEBUG1
574 mod_gzip_printf( "%s: The item is EXCLUDED...",cn);
575 mod_gzip_printf( "%s: Exit > return( MOD_GZIP_IMAP_DECLINED1 ) >",cn);
576 #endif
577
578 if(remove_vary) {
579 #ifdef MOD_GZIP_DEBUG1
580 mod_gzip_printf("%s: removing vary...",cn);
581 #endif
582
583 ap_table_unset(r->headers_out,"Vary");
584 }
585 #ifdef MOD_GZIP_DEBUG1
586 else {
587 mod_gzip_printf("%s: leaving vary as it is...",cn);
588 }
589 #endif
590
591 return( MOD_GZIP_IMAP_DECLINED1 );
592 }
593
594 else if ( item_is_included )
595 {
596 #ifdef MOD_GZIP_DEBUG1
597 mod_gzip_printf( "%s: The item is INCLUDED, leaving vary as it is...",cn);
598 mod_gzip_printf( "%s: Exit > return( 1 ) >",cn);
599 #endif
600
601 return action_value;
602 }
603
604 if ( http_field_check )
605 {
606 #ifdef MOD_GZIP_DEBUG1
607 mod_gzip_printf( "%s: ?? Status unknown ?? Default is to 'accept'...",cn);
608 mod_gzip_printf( "%s: Exit > return( MOD_GZIP_IMAP_STATIC1 ) >",cn);
609 #endif
610
611 return MOD_GZIP_IMAP_STATIC1;
612 }
613
614 #ifdef MOD_GZIP_DEBUG1
615 mod_gzip_printf( "%s: Exit > return( MOD_GZIP_IMAP_DECLINED1 ) >",cn);
616 #endif
617
618 if(remove_vary) {
619 #ifdef MOD_GZIP_DEBUG1
620 mod_gzip_printf("%s: removing vary...",cn);
621 #endif
622
623 ap_table_unset(r->headers_out,"Vary");
624 }
625 #ifdef MOD_GZIP_DEBUG1
626 else {
627 mod_gzip_printf("%s: leaving vary as it is...",cn);
628 }
629 #endif
630
631 return( MOD_GZIP_IMAP_DECLINED1 );
632 }
633
634
635 /* NOTE: If API_VAR_EXPORT prefix is not used for 'top_module' */
636 /* declaration then MSVC 6.0 will give 'incosistent DLL linkage' */
637 /* warning during WIN32 compile... */
638
639 extern API_VAR_EXPORT module *top_module;
640
641 #define MOD_GZIP_RUN_TYPE_CHECKERS 1
642 #define MOD_GZIP_RUN_TRANSLATE_HANDLERS 2
643
644 int mod_gzip_run_handlers( request_rec *r, int flag1 )
645 {
646 int rc = 0;
647 int count = 0;
648 int runit = 0;
649 int handler_is_present=0;
650
651 module *modp;
652
653 #ifdef MOD_GZIP_DEBUG1
654 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
655 const handler_rec *handp;
656 char cn[]="mod_gzip_run_handlers()";
657 #endif
658 #endif
659
660 #ifdef MOD_GZIP_DEBUG1
661 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
662 mod_gzip_server_now = r->server;
663 mod_gzip_printf( "%s: Entry...",cn);
664 mod_gzip_printf( "%s: *IN: r->uri =[%s]", cn, npp(r->uri));
665 mod_gzip_printf( "%s: *IN: r->unparsed_uri =[%s]", cn, npp(r->unparsed_uri));
666 mod_gzip_printf( "%s: *IN: r->filename =[%s]", cn, npp(r->filename));
667 mod_gzip_printf( "%s: *IN: r->handler =[%s]", cn, npp(r->handler));
668 mod_gzip_printf( "%s: *IN: r->content_type =[%s]", cn, npp(r->content_type));
669 #endif
670 #endif
671
672 if ( flag1 == MOD_GZIP_RUN_TYPE_CHECKERS )
673 {
674 #ifdef MOD_GZIP_DEBUG1
675 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
676 mod_gzip_printf( "%s: flag1 = %d = MOD_GZIP_RUN_TYPE_CHECKERS",cn,flag1);
677 #endif
678 #endif
679 }
680 else if ( flag1 == MOD_GZIP_RUN_TRANSLATE_HANDLERS )
681 {
682 #ifdef MOD_GZIP_DEBUG1
683 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
684 mod_gzip_printf( "%s: flag1 = %d = MOD_GZIP_RUN_TRANSLATE_HANDLERS",cn,flag1);
685 #endif
686 #endif
687 }
688 else
689 {
690 #ifdef MOD_GZIP_DEBUG1
691 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
692 mod_gzip_printf( "%s: flag1 = %d = MOD_GZIP_RUN_??? Unknown value",cn,flag1);
693 mod_gzip_printf( "%s: ERROR: Exit > return( DECLINED ) >",cn);
694 #endif
695 #endif
696
697 return( DECLINED );
698 }
699
700 for ( modp = top_module; modp; modp = modp->next )
701 {
702 #ifdef MOD_GZIP_DEBUG1
703 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
704 mod_gzip_printf( "%s: count=%4.4d modp = %10.10ld modp->name=[%s]",
705 cn,count,(long)modp,npp(modp->name));
706 #endif
707 #endif
708
709 runit = 0;
710
711 if ( modp )
712 {
713 runit = 1;
714
715 if ( modp == &gzip_module )
716 {
717 runit = 0;
718 }
719
720 #ifdef FUTURE_USE
721 if ( mod_gzip_strnicmp( (char *) modp->name, "mod_gzip.c",10)==0)
722 {
723 runit = 0;
724 }
725 #endif
726 }
727
728 if ( runit )
729 {
730 #ifdef MOD_GZIP_DEBUG1
731 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
732
733 mod_gzip_printf( "%s: ++++++++++ MODULE FOUND!...",cn);
734 mod_gzip_printf( "%s: ++++++++++ modp->module_index = %d",cn,(int)modp->module_index);
735
736 #ifdef REFERENCE
737
738 typedef struct {
739 const char *content_type;
740 int (*handler) (request_rec *);
741 } handler_rec;
742
743 typedef struct module_struct {
744 ...
745 const handler_rec *handlers;
746 ...
747 }module;
748
749 #endif
750
751 mod_gzip_printf( "%s: ++++++++++ METHODS",cn);
752 mod_gzip_printf( "%s: ++++++++++ modp->translate_handler = %ld",cn,(long)modp->translate_handler);
753 mod_gzip_printf( "%s: ++++++++++ modp->ap_check_user_id = %ld",cn,(long)modp->ap_check_user_id);
754 mod_gzip_printf( "%s: ++++++++++ modp->auth_checker = %ld",cn,(long)modp->auth_checker);
755 mod_gzip_printf( "%s: ++++++++++ modp->access_checker = %ld",cn,(long)modp->access_checker);
756 mod_gzip_printf( "%s: ++++++++++ modp->type_checker = %ld",cn,(long)modp->type_checker);
757 mod_gzip_printf( "%s: ++++++++++ modp->fixer_upper = %ld",cn,(long)modp->fixer_upper);
758 mod_gzip_printf( "%s: ++++++++++ modp->logger = %ld",cn,(long)modp->logger);
759 mod_gzip_printf( "%s: ++++++++++ modp->header_parser = %ld",cn,(long)modp->header_parser);
760 mod_gzip_printf( "%s: .......... CONTENT HANDLERS",cn);
761
762 if ( !modp->handlers )
763 {
764 mod_gzip_printf( "%s: .......... NO CONTENT HANDLERS!",cn);
765 }
766 else
767 {
768 for ( handp = modp->handlers; handp->content_type; ++handp )
769 {
770 mod_gzip_printf( "%s: .......... handp->content_type = [%s]",
771 cn,npp(handp->content_type));
772 mod_gzip_printf( "%s: .......... handp->handler = %ld",
773 cn,(long)handp->handler);
774 }
775 }
776
777 #endif
778 #endif
779
780 handler_is_present = 0;
781
782 if ( flag1 == MOD_GZIP_RUN_TYPE_CHECKERS )
783 {
784 if ( modp->type_checker ) handler_is_present = 1;
785 }
786 else if ( flag1 == MOD_GZIP_RUN_TRANSLATE_HANDLERS )
787 {
788 if ( modp->translate_handler ) handler_is_present = 1;
789 }
790
791 #ifdef MOD_GZIP_DEBUG1
792 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
793 mod_gzip_printf( "%s: handler_is_present = %d ",
794 cn, handler_is_present);
795 #endif
796 #endif
797
798 if ( handler_is_present )
799 {
800 #ifdef MOD_GZIP_DEBUG1
801 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
802
803 mod_gzip_printf( "%s: 'handler_is_present' is TRUE...",cn);
804
805 mod_gzip_printf( "%s: r->filename = [%s]",cn,npp(r->filename));
806 mod_gzip_printf( "%s: r->uri = [%s]",cn,npp(r->uri));
807 mod_gzip_printf( "%s: r->handler = [%s]",cn,npp(r->handler));
808 mod_gzip_printf( "%s: r->content_type = [%s]",cn,npp(r->content_type));
809
810 if ( flag1 == MOD_GZIP_RUN_TYPE_CHECKERS )
811 {
812 mod_gzip_printf( "%s: Call (modp->type_checker)(r)...",cn);
813 }
814 else if ( flag1 == MOD_GZIP_RUN_TRANSLATE_HANDLERS )
815 {
816 mod_gzip_printf( "%s: Call (modp->translate_handler)(r)...",cn);
817 }
818
819 #endif
820 #endif
821
822 if ( flag1 == MOD_GZIP_RUN_TYPE_CHECKERS )
823 {
824 rc = (modp->type_checker)( (request_rec *) r );
825 }
826 else if ( flag1 == MOD_GZIP_RUN_TRANSLATE_HANDLERS )
827 {
828 rc = (modp->translate_handler)( (request_rec *) r );
829 }
830
831 #ifdef MOD_GZIP_DEBUG1
832 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
833
834 if ( flag1 == MOD_GZIP_RUN_TYPE_CHECKERS )
835 {
836 mod_gzip_printf( "%s: Back (modp->type_checker)(r)...",cn);
837 }
838 else if ( flag1 == MOD_GZIP_RUN_TRANSLATE_HANDLERS )
839 {
840 mod_gzip_printf( "%s: Back (modp->translate_handler)(r)...",cn);
841 }
842
843 mod_gzip_printf( "%s: r->filename = [%s]",cn,npp(r->filename));
844 mod_gzip_printf( "%s: r->uri = [%s]",cn,npp(r->uri));
845 mod_gzip_printf( "%s: r->handler = [%s]",cn,npp(r->handler));
846 mod_gzip_printf( "%s: r->content_type = [%s]",cn,npp(r->content_type));
847
848 if ( rc == OK )
849 {
850 mod_gzip_printf( "%s: rc = %d = OK",cn, rc );
851 }
852 else if ( rc == DECLINED )
853 {
854 mod_gzip_printf( "%s: rc = %d = DECLINED",cn, rc );
855 }
856 else if ( rc == DONE )
857 {
858 mod_gzip_printf( "%s: rc = %d = DONE",cn, rc );
859 }
860 else
861 {
862 mod_gzip_printf( "%s: rc = %d = HTTP_ERROR?",cn, rc );
863 }
864
865 #endif
866 #endif
867
868 if ( rc == OK )
869 {
870 #ifdef MOD_GZIP_DEBUG1
871 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
872 mod_gzip_printf( "%s: Call SUCCEEDED",cn );
873 mod_gzip_printf( "%s: Exit > return( rc=%d ) >",cn,rc);
874 #endif
875 #endif
876
877 return rc;
878 }
879 else
880 {
881 #ifdef MOD_GZIP_DEBUG1
882 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
883 mod_gzip_printf( "%s: Call FAILED",cn );
884 #endif
885 #endif
886
887 if ( rc != DECLINED )
888 {
889 #ifdef MOD_GZIP_DEBUG1
890 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
891 mod_gzip_printf( "%s: Something other than 'DECLINED' was returned.",cn);
892 mod_gzip_printf( "%s: Exit > return( rc=%d ) >",cn,rc);
893 #endif
894 #endif
895
896 return rc;
897 }
898 else
899 {
900 #ifdef MOD_GZIP_DEBUG1
901 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
902 mod_gzip_printf( "%s: 'DECLINED' was returned... Continuing chain...",cn);
903 #endif
904 #endif
905 }
906 }
907 }
908 else
909 {
910 #ifdef MOD_GZIP_DEBUG1
911 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
912 mod_gzip_printf( "%s: 'handler_is_present' is FALSE...",cn);
913 #endif
914 #endif
915 }
916 }
917 else
918 {
919 #ifdef MOD_GZIP_DEBUG1
920 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
921 mod_gzip_printf( "%s: 'runit' is FALSE...",cn);
922 mod_gzip_printf( "%s: SKIPPING THIS MODULE",cn);
923 #endif
924 #endif
925 }
926
927 count++;
928 }
929
930 #ifdef MOD_GZIP_DEBUG1
931 #ifdef MOD_GZIP_DEBUG1_RUN_HANDLERS1
932 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
933 #endif
934 #endif
935
936 return DECLINED;
937 }
938
939
940 int mod_gzip_delete_file(
941 request_rec *r,
942 char *filename
943 )
944 {
945 #ifdef MOD_GZIP_DEBUG1
946 char cn[]="mod_gzip_delete_file()";
947 #endif
948
949 int final_rc = 0;
950
951 #ifdef WIN32
952 BOOL rc;
953 #else
954 int rc;
955 #endif
956
957 #ifdef MOD_GZIP_DEBUG1
958 mod_gzip_printf( "%s: Entry...",cn);
959 mod_gzip_printf( "%s: filename = [%s]",cn,npp(filename));
960 #endif
961
962 #ifdef WIN32
963
964 #ifdef MOD_GZIP_DEBUG1
965 mod_gzip_printf( "%s: Call DeleteFile(%s)...",cn,npp(filename));
966 #endif
967
968 rc = (BOOL) DeleteFile( filename );
969
970 #ifdef MOD_GZIP_DEBUG1
971 mod_gzip_printf( "%s: Back DeleteFile(%s)...",cn,npp(filename));
972 #endif
973
974 if ( rc == FALSE )
975 {
976 #ifdef MOD_GZIP_DEBUG1
977 mod_gzip_printf( "%s: .... DeleteFile() FAILED",cn);
978 #endif
979 }
980 else
981 {
982 #ifdef MOD_GZIP_DEBUG1
983 mod_gzip_printf( "%s: .... DeleteFile() SUCCEEDED",cn);
984 #endif
985
986 final_rc = 1;
987 }
988
989 #else
990
991 #ifdef MOD_GZIP_DEBUG1
992 mod_gzip_printf( "%s: Call unlink(%s)...",cn,npp(filename));
993 #endif
994
995 rc = (int) unlink( filename );
996
997 #ifdef MOD_GZIP_DEBUG1
998 mod_gzip_printf( "%s: Back unlink(%s)...",cn,npp(filename));
999 #endif
1000
1001 if ( rc < 0 )
1002 {
1003 #ifdef MOD_GZIP_DEBUG1
1004 mod_gzip_printf( "%s: .... unlink() FAILED",cn);
1005 #endif
1006 }
1007 else
1008 {
1009 #ifdef MOD_GZIP_DEBUG1
1010 mod_gzip_printf( "%s: .... unlink() SUCCEEDED",cn);
1011 #endif
1012
1013 final_rc = 1;
1014 }
1015
1016 #endif
1017
1018 #ifdef MOD_GZIP_DEBUG1
1019
1020 if ( final_rc == 1 )
1021 {
1022 mod_gzip_printf( "%s: Exit > return( final_rc = %d ) SUCCESS >",cn,final_rc);
1023 }
1024 else
1025 {
1026 mod_gzip_printf( "%s: Exit > return( final_rc = %d ) FAILURE >",cn,final_rc);
1027 }
1028
1029 #endif
1030
1031 return( final_rc );
1032 }
1033
1034 static void mod_gzip_init( server_rec *server, pool *p )
1035 {
1036 int add_version_info=1;
1037
1038 #ifdef MOD_GZIP_DEBUG1
1039 char cn[]="mod_gzip_init()";
1040 #endif
1041
1042 mod_gzip_conf *mgc;
1043
1044 #ifdef MOD_GZIP_DEBUG1
1045
1046 mod_gzip_server_now = server;
1047
1048 mod_gzip_printf( " " );
1049 mod_gzip_printf( "%s: Entry...", cn );
1050
1051 #endif
1052
1053 mgc = ( mod_gzip_conf * )
1054 ap_get_module_config( server->module_config, &gzip_module );
1055
1056 #ifdef MOD_GZIP_DEBUG1
1057 mod_gzip_printf( "%s: MODULE_MAGIC_NUMBER = %ld", cn, (long) MODULE_MAGIC_NUMBER );
1058 #endif
1059
1060 if ( add_version_info )
1061 {
1062 #ifdef MOD_GZIP_DEBUG1
1063 mod_gzip_printf( "%s: add_version_info = TRUE", cn );
1064 #endif
1065
1066 #if MODULE_MAGIC_NUMBER >= 19980507
1067
1068 #ifdef MOD_GZIP_DEBUG1
1069 mod_gzip_printf( "%s: MODULE_MAGIC_NUMBER is >= 19980507",cn);
1070 mod_gzip_printf( "%s: Call ap_add_version_component(%s)...",
1071 cn, npp(MOD_GZIP_VERSION_INFO_STRING));
1072 #endif
1073
1074 ap_add_version_component( MOD_GZIP_VERSION_INFO_STRING );
1075
1076 #ifdef MOD_GZIP_DEBUG1
1077 mod_gzip_printf( "%s: Back ap_add_version_component(%s)...",
1078 cn, npp(MOD_GZIP_VERSION_INFO_STRING));
1079 #endif
1080
1081 #else
1082
1083 #ifdef MOD_GZIP_DEBUG1
1084 mod_gzip_printf( "%s: MODULE_MAGIC_NUMBER is NOT >= 19980507", cn );
1085 mod_gzip_printf( "%s: ap_add_version_component() NOT called.", cn );
1086 #endif
1087
1088 #endif
1089 }
1090 else
1091 {
1092 #ifdef MOD_GZIP_DEBUG1
1093 mod_gzip_printf( "%s: add_version_info = FALSE", cn );
1094 mod_gzip_printf( "%s: ap_add_version_component() NOT called.", cn );
1095 #endif
1096 }
1097
1098 #ifdef MOD_GZIP_DEBUG1
1099 mod_gzip_printf( "%s: Initialization completed...", cn );
1100 mod_gzip_printf( "%s: Exit > return( void ) >", cn );
1101 mod_gzip_printf( " " );
1102 #endif
1103 }
1104
1105 int mod_gzip_strncmp( char *s1, char *s2, int len1 )
1106 {
1107 int i;
1108 char ch1;
1109 char ch2;
1110
1111 if ( ( s1 == 0 ) || ( s2 == 0 ) )
1112 {
1113 return 1;
1114 }
1115
1116 for ( i=0; i<len1; i++ )
1117 {
1118 if ( ( *s1 == 0 ) || ( *s2 == 0 ) ) return( 1 );
1119
1120 ch1 = *s1;
1121 ch2 = *s2;
1122
1123 if ( ch1 == '/' ) ch1 = '\\';
1124 if ( ch2 == '/' ) ch2 = '\\';
1125
1126 if ( ch1 != ch2 ) return 1;
1127
1128 s1++;
1129 s2++;
1130 }
1131
1132 return 0;
1133 }
1134
1135 int mod_gzip_strnicmp( char *s1, char *s2, int len1 )
1136 {
1137 int i;
1138 char ch1;
1139 char ch2;
1140
1141 if ( ( s1 == 0 ) || ( s2 == 0 ) )
1142 {
1143 return 1;
1144 }
1145
1146 for ( i=0; i<len1; i++ )
1147 {
1148 if ( ( *s1 == 0 ) || ( *s2 == 0 ) ) return( 1 );
1149
1150 ch1 = *s1;
1151 ch2 = *s2;
1152
1153 if ( ch1 > 96 ) ch1 -= 32;
1154 if ( ch2 > 96 ) ch2 -= 32;
1155
1156 if ( ch1 == '/' ) ch1 = '\\';
1157 if ( ch2 == '/' ) ch2 = '\\';
1158
1159 if ( ch1 != ch2 ) return 1;
1160
1161 s1++;
1162 s2++;
1163 }
1164
1165 return 0;
1166 }
1167
1168 int mod_gzip_strendswith( char *s1, char *s2, int ignorcase )
1169 {
1170 int len1;
1171 int len2;
1172
1173 if ( ( s1 == 0 ) || ( s2 == 0 ) )
1174 {
1175 return 0;
1176 }
1177
1178 len1 = mod_gzip_strlen( s1 );
1179 len2 = mod_gzip_strlen( s2 );
1180
1181 if ( len1 < len2 )
1182 {
1183 /* Source string is shorter than search string */
1184 /* so no match is possible */
1185
1186 return 0;
1187 }
1188
1189 s1 += ( len1 - len2 );
1190
1191 if ( ignorcase )
1192 {
1193 if ( mod_gzip_strnicmp( s1, s2, len2 ) == 0 ) return 1; /* TRUE */
1194 }
1195 else
1196 {
1197 if ( mod_gzip_strncmp( s1, s2, len2 ) == 0 ) return 1; /* TRUE */
1198 }
1199
1200 return 0; /* FALSE */
1201 }
1202
1203 int mod_gzip_strlen( char *s1 )
1204 {
1205 int len = 0;
1206
1207 if ( s1 != 0 )
1208 {
1209 while( *s1 != 0 ) { s1++; len++; }
1210 }
1211
1212 return len;
1213 }
1214
1215 int mod_gzip_strcpy( char *s1, char *s2 )
1216 {
1217 int len = 0;
1218
1219 if ( ( s1 != 0 )&&( s2 != 0 ) )
1220 {
1221 while( *s2 != 0 ) { *s1++ = *s2++; len++; }
1222 *s1=0;
1223 }
1224
1225 return len;
1226 }
1227
1228 int mod_gzip_strncpy(char *s1,char *s2,int l) {
1229 int len = 0;
1230
1231 if((s1 != 0) && (s2 != 0)) {
1232 while(*s2 != 0 && *s1 != 0 && len <= l) {
1233 *s1++ = *s2++;
1234 len++;
1235 }
1236
1237 *s1 = 0;
1238 }
1239
1240 return len;
1241 }
1242
1243 int mod_gzip_strcat( char *s1, char *s2 )
1244 {
1245 int len = 0;
1246
1247 if ( s1 != 0 )
1248 {
1249 while( *s1 != 0 ) { s1++; len++; }
1250 if ( s2 != 0 )
1251 {
1252 while( *s2 != 0 ) { *s1++ = *s2++; len++; }
1253 *s1 = 0;
1254 }
1255 }
1256
1257 return len;
1258 }
1259
1260 int mod_gzip_stringcontains( char *source, char *substring )
1261 {
1262 int i;
1263 int len1;
1264 int len2;
1265 int len3;
1266 int offset=1;
1267
1268 char *source1;
1269 char *substring1;
1270
1271 if ( source == NULL )
1272 {
1273 return 0;
1274 }
1275
1276 if ( substring == NULL )
1277 {
1278 return 0;
1279 }
1280
1281 source1 = source;
1282 substring1 = substring;
1283
1284 len1 = mod_gzip_strlen( source );
1285 len2 = mod_gzip_strlen( substring );
1286
1287 if ( len1 < len2 )
1288 {
1289 return 0;
1290 }
1291
1292 len3 = len1 - len2;
1293
1294 for ( i=0; i<=len3; i++ )
1295 {
1296 if ( mod_gzip_strnicmp( source, substring, len2 ) == 0 )
1297 {
1298 source = source1;
1299 substring = substring1;
1300
1301 return offset;
1302 }
1303
1304 source++;
1305 offset++;
1306 }
1307
1308 source = source1;
1309 substring = substring1;
1310
1311 return 0;
1312 }
1313
1314 #ifndef WIN32
1315 long fake_tid = 99;
1316 #endif
1317
1318 int mod_gzip_create_unique_filename(
1319 char *prefix,
1320 char *target,
1321 int targetmaxlen
1322 )
1323 {
1324 long process_id = 0;
1325 long thread_id = 0;
1326
1327 #ifdef MOD_GZIP_DEBUG1
1328 char cn[]="mod_gzip_create_unique_filename()";
1329 #endif
1330
1331 int prefixlen = 0;
1332 char slash[4];
1333
1334 #ifdef WIN32
1335 process_id = (long) GetCurrentProcessId();
1336 thread_id = (long) GetCurrentThreadId();
1337 #else
1338
1339 process_id = (long) getpid();
1340 thread_id = (long) fake_tid;
1341 fake_tid++;
1342 if ( fake_tid > 9999999 ) fake_tid = 99;
1343 #endif
1344
1345 #ifdef MOD_GZIP_DEBUG1
1346 mod_gzip_printf( "%s: Entry...",cn );
1347 mod_gzip_printf( "%s: prefix = [%s]",cn,npp(prefix));
1348 mod_gzip_printf( "%s: target = %ld", cn,(long)target);
1349 mod_gzip_printf( "%s: targetmaxlen = %ld", cn,(long)targetmaxlen);
1350 mod_gzip_printf( "%s: process_id = %ld", cn,(long)process_id );
1351 mod_gzip_printf( "%s: thread_id = %ld", cn,(long)thread_id );
1352 mod_gzip_printf( "%s: mod_gzip_iusn = %ld", cn,(long)mod_gzip_iusn );
1353 #endif
1354
1355 if ( ( !target ) || ( targetmaxlen == 0 ) )
1356 {
1357 #ifdef MOD_GZIP_DEBUG1
1358 mod_gzip_printf( "%s: Invalid target or targetmaxlen value.",cn);
1359 mod_gzip_printf( "%s: Exit > return( 1 ) > ERROR >",cn );
1360 #endif
1361
1362 return 1;
1363 }
1364
1365 if ( prefix )
1366 {
1367 prefixlen = mod_gzip_strlen( prefix );
1368 }
1369
1370 if ( prefixlen > 0 )
1371 {
1372 slash[0]=0;
1373
1374 if ( ( *(prefix+(prefixlen-1)) != '\\' ) &&
1375 ( *(prefix+(prefixlen-1)) != '/' ) )
1376 {
1377 #ifdef WIN32
1378 slash[0]='\\';
1379 #else
1380 slash[0]='/';
1381 #endif
1382 slash[1]=0;
1383 }
1384
1385 sprintf(
1386 target,
1387 "%s%s_%ld_%ld_%ld.wrk",
1388 prefix,
1389 slash,
1390 (long) process_id,
1391 (long) thread_id,
1392 (long) mod_gzip_iusn
1393 );
1394 }
1395 else
1396 {
1397 sprintf(
1398 target,
1399 "_%ld_%ld_%ld.wrk",
1400 (long) process_id,
1401 (long) thread_id,
1402 (long) mod_gzip_iusn
1403 );
1404 }
1405
1406 mod_gzip_iusn++;
1407
1408 if ( mod_gzip_iusn > 999999999L ) mod_gzip_iusn = 1;
1409
1410 #ifdef MOD_GZIP_DEBUG1
1411 mod_gzip_printf( "%s: target = [%s]",cn,npp(target));
1412 mod_gzip_printf( "%s: Exit > return( 0 ) >",cn );
1413 #endif
1414
1415 return 0;
1416 }
1417
1418 int mod_gzip_type_checker( request_rec *r )
1419 {
1420 int i = 0;
1421 int rc = 0;
1422 int field_ok = 0;
1423 int action_flag = 0;
1424 const char *tablekey = 0;
1425 const char *tablestring = 0;
1426 int accept_encoding_gzip_seen = 0;
1427
1428 #ifdef WIN32
1429 long content_length;
1430 #endif
1431
1432 _table *t = 0;
1433 table_entry *elts = 0;
1434
1435 mod_gzip_conf *dconf = 0;
1436
1437 #ifdef MOD_GZIP_DEBUG1
1438 char cn[]="mod_gzip_type_checker()";
1439 mod_gzip_conf *sconf = 0;
1440 #endif
1441
1442 #ifdef MOD_GZIP_DEBUG1
1443 mod_gzip_printf( " " );
1444 mod_gzip_printf( "%s: ''''Entry...",cn);
1445 mod_gzip_printf( "%s: r = %ld", cn,(long)r);
1446 mod_gzip_printf( "%s: r->main = %ld", cn,(long)r->main);
1447 mod_gzip_printf( "%s: r->next = %ld", cn,(long)r->next);
1448 mod_gzip_printf( "%s: r->prev = %ld", cn,(long)r->prev);
1449 mod_gzip_printf( "%s: r->header_only = %ld", cn,(long)r->header_only );
1450 mod_gzip_printf( "%s: r->method_number = %ld", cn,(long)r->method_number );
1451 mod_gzip_printf( "%s: r->method = [%s]",cn,npp(r->method));
1452 mod_gzip_printf( "%s: r->unparsed_uri = [%s]",cn,npp(r->unparsed_uri));
1453 mod_gzip_printf( "%s: r->uri = [%s]",cn,npp(r->uri));
1454 mod_gzip_printf( "%s: r->filename = [%s]",cn,npp(r->filename));
1455 mod_gzip_printf( "%s: r->handler = [%s]",cn,npp(r->handler));
1456 mod_gzip_printf( "%s: r->content_type = [%s]",cn,npp(r->content_type));
1457 #endif
1458
1459 #ifdef MOD_GZIP_USES_APACHE_LOGS
1460
1461 if ( r->main )
1462 {
1463 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:UNHANDLED_SUBREQ"));
1464 }
1465 else if ( r->prev )
1466 {
1467 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:UNHANDLED_REDIR"));
1468 }
1469 else
1470 {
1471 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:INIT1"));
1472 }
1473
1474 ap_table_setn( r->notes,"mod_gzip_input_size", ap_pstrdup(r->pool,"0"));
1475 ap_table_setn( r->notes,"mod_gzip_output_size",ap_pstrdup(r->pool,"0"));
1476 ap_table_setn( r->notes,"mod_gzip_compression_ratio",ap_pstrdup(r->pool,"0"));
1477
1478 #endif
1479
1480
1481 dconf = ( mod_gzip_conf * )
1482 ap_get_module_config( r->per_dir_config, &gzip_module );
1483
1484 #ifdef MOD_GZIP_DEBUG1
1485
1486 sconf = ( mod_gzip_conf * )
1487 ap_get_module_config( r->server->module_config, &gzip_module );
1488
1489 mod_gzip_printf( "%s: r->server->server_hostname = [%s]", cn,npp(r->server->server_hostname));
1490 mod_gzip_printf( "%s: sconf = %ld", cn,(long)sconf);
1491 mod_gzip_printf( "%s: sconf->loc = [%s]",cn,npp(sconf->loc));
1492 mod_gzip_printf( "%s: sconf->is_on = %ld", cn,(long)sconf->is_on);
1493 mod_gzip_printf( "%s: dconf = %ld", cn,(long)dconf);
1494 mod_gzip_printf( "%s: dconf->loc = [%s]",cn,npp(dconf->loc));
1495 mod_gzip_printf( "%s: dconf->is_on = %ld", cn,(long)dconf->is_on);
1496
1497 #endif
1498
1499 if(!dconf) {
1500 #ifdef MOD_GZIP_USES_APACHE_LOGS
1501 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:NO_DCONF"));
1502 #endif
1503
1504 #ifdef MOD_GZIP_DEBUG1
1505 mod_gzip_printf( "%s: 'dconf' is NULL. Unable to continue.",cn);
1506 mod_gzip_printf( "%s: Exit > return( DECLINED ) >", cn);
1507 #endif
1508
1509 return DECLINED;
1510 }
1511
1512 if(r->filename) {
1513 #ifdef MOD_GZIP_DEBUG1
1514 mod_gzip_printf("%s: in r->filename, suffix is: %s, filename is: %s",cn,dconf->suffix,r->filename);
1515 #endif
1516
1517 if(mod_gzip_strendswith( r->filename, dconf->suffix, 1)) {
1518 if(r->prev) {
1519 /* This is a mod_gzip negotiated .gz static file transmit... */
1520 #ifdef MOD_GZIP_USES_APACHE_LOGS
1521 const char *t = ap_table_get(r->prev->notes,"mod_gzip_result_n");
1522 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,t ? t : "DECLINED:STATIC_GZ_FOUND"));
1523 #endif
1524
1525 if(dconf->send_vary) {
1526 if(dconf->min_http_set) {
1527 ap_table_setn(r->headers_out,ap_pstrdup(r->pool,"Vary"),ap_pstrdup(r->pool,"*"));
1528 }
1529 else {
1530 ap_table_setn(r->headers_out,ap_pstrdup(r->pool,"Vary"),mod_gzip_generate_vary_header(dconf,r->pool));
1531 }
1532 }
1533 }
1534 #ifdef MOD_GZIP_USES_APACHE_LOGS
1535 else {
1536 /* This is a direct request from client for a .gz file... */
1537 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:FEXT_GZ"));
1538 }
1539 #endif
1540
1541 #ifdef MOD_GZIP_DEBUG1
1542 mod_gzip_printf( "%s: r->filename ends with '%s'...",cn,dconf->suffix);
1543 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
1544 #endif
1545
1546 return DECLINED;
1547 }
1548 #ifdef MOD_GZIP_DEBUG1
1549 else {
1550 mod_gzip_printf( "%s: r->filename does NOT end with '%s'...",cn,dconf->suffix);
1551 mod_gzip_printf( "%s: OK to continue...",cn);
1552 }
1553 #endif
1554 }
1555
1556 if ( !dconf->is_on )
1557 {
1558 #ifdef MOD_GZIP_USES_APACHE_LOGS
1559 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:OFF"));
1560 #endif
1561
1562 #ifdef MOD_GZIP_DEBUG1
1563 mod_gzip_printf( "%s: 'dconf->is_on' is FALSE",cn);
1564 mod_gzip_printf( "%s: mod_gzip is not turned ON for this location...",cn);
1565 mod_gzip_printf( "%s: This transaction will be ignored...",cn);
1566 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
1567 #endif
1568
1569 return DECLINED;
1570 }
1571
1572 if ( ( r->method_number != M_GET ) &&
1573 ( r->method_number != M_POST ) )
1574 {
1575 #ifdef MOD_GZIP_USES_APACHE_LOGS
1576 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:NOT_GET_OR_POST"));
1577 #endif
1578
1579 #ifdef MOD_GZIP_DEBUG1
1580 mod_gzip_printf( "%s: r->method_number is NOT M_GET or M_POST",cn);
1581 mod_gzip_printf( "%s: Ignoring this request...",cn);
1582 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
1583 #endif
1584
1585 return DECLINED;
1586 }
1587 else {
1588 if(dconf->handle_methods != MOD_GZIP_M_BOTH && dconf->handle_methods != MOD_GZIP_M_NOT_SET) {
1589 if(
1590 (r->method_number == M_GET && dconf->handle_methods == M_POST) ||
1591 (r->method_number == M_POST && dconf->handle_methods == M_GET)) {
1592 #ifdef MOD_GZIP_USES_APACHE_LOGS
1593 ap_table_setn(r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:METHOD_EXCLUDED"));
1594 #endif
1595
1596 return DECLINED;
1597 }
1598 }
1599 }
1600
1601 /*
1602 * Bugfix for POST bug on win32
1603 */
1604 #ifdef WIN32
1605 if(r->method_number == M_POST) {
1606 content_length = strtol(ap_table_get(r->headers_in,"Content-Length"),NULL,10);
1607
1608 if(r->connection->client->incnt < content_length) {
1609 #ifdef MOD_GZIP_USES_APACHE_LOGS
1610 ap_table_setn(r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:POST_TOO_BIG"));
1611 #endif
1612 return DECLINED;
1613 }
1614 }
1615 #endif
1616
1617 if ( r->header_only )
1618 {
1619 #ifdef MOD_GZIP_USES_APACHE_LOGS
1620 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:HEAD_REQUEST"));
1621 #endif
1622
1623 #ifdef MOD_GZIP_DEBUG1
1624 mod_gzip_printf( "%s: r->header_only is TRUE...",cn);
1625 mod_gzip_printf( "%s: Ignoring this HEAD request...",cn);
1626 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
1627 #endif
1628
1629 return DECLINED;
1630 }
1631
1632
1633 /*
1634 * set the vary header
1635 */
1636 if(dconf->send_vary) {
1637 if(dconf->min_http_set) {
1638 ap_table_setn(r->headers_out,ap_pstrdup(r->pool,"Vary"),ap_pstrdup(r->pool,"*"));
1639 }
1640 else {
1641 ap_table_setn(r->headers_out,ap_pstrdup(r->pool,"Vary"),mod_gzip_generate_vary_header(dconf,r->pool));
1642 }
1643 }
1644
1645 if ( r->main ) /* SUBREQUEST */
1646 {
1647 #ifdef MOD_GZIP_DEBUG1
1648 mod_gzip_printf( "%s: r->main is TRUE - This is a subrequest...",cn);
1649 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
1650 #endif
1651
1652 return DECLINED;
1653 }
1654 else
1655 {
1656 #ifdef MOD_GZIP_DEBUG1
1657 mod_gzip_printf( "%s: r->main is FALSE",cn);
1658 mod_gzip_printf( "%s: This is NOT a subrequest in progress...",cn);
1659 mod_gzip_printf( "%s: OK to continue...",cn);
1660 #endif
1661 }
1662
1663 if ( r->prev ) /* REDIRECT */
1664 {
1665 #ifdef MOD_GZIP_DEBUG1
1666 mod_gzip_printf( "%s: r->prev is NON-NULL... This is a redirection",cn);
1667 #ifdef MOD_GZIP_DEBUG1_SHOW_REQUEST_RECORD1
1668 mod_gzip_printf( "%s: Showing contents of r->prev now...",cn);
1669 mod_gzip_show_request_record( r->prev, cn );
1670 #endif
1671 #endif
1672
1673 tablestring = ap_table_get(r->prev->notes, "mod_gzip_running");
1674
1675 #ifdef MOD_GZIP_DEBUG1
1676 mod_gzip_printf( "%s: r->prev->notes->mod_gzip_running = [%s]",
1677 cn,npp(tablestring));
1678 #endif
1679
1680 if ( tablestring )
1681 {
1682 #ifdef MOD_GZIP_DEBUG1
1683 mod_gzip_printf( "%s: 'mod_gzip_running' note FOUND",cn);
1684 #endif
1685
1686 if ( *tablestring == '1' )
1687 {
1688 #ifdef MOD_GZIP_DEBUG1
1689 mod_gzip_printf( "%s: 'mod_gzip_running' note value is '1'...",cn);
1690 #endif
1691
1692 #ifdef MOD_GZIP_DEBUG1
1693 mod_gzip_printf( "%s: ************************************************",cn);
1694 mod_gzip_printf( "%s: mod_gzip is currently 'running' so we ",cn);
1695 mod_gzip_printf( "%s: must return DECLINED so that other type_checker",cn);
1696 mod_gzip_printf( "%s: hooks can fire...",cn);
1697 mod_gzip_printf( "%s: ************************************************",cn);
1698 mod_gzip_printf( "%s: IMPORTANT: We must now 'replicate' the note flag",cn);
1699 mod_gzip_printf( "%s: on this record or next time around r->prev",cn);
1700 mod_gzip_printf( "%s: note flag check will be FALSE.",cn);
1701 mod_gzip_printf( "%s: ************************************************",cn);
1702 #endif
1703
1704 ap_table_setn(r->notes,"mod_gzip_running",ap_pstrdup(r->pool,"1"));
1705
1706 #ifdef MOD_GZIP_DEBUG1
1707 mod_gzip_printf( "%s: r->notes 'mod_gzip_running' set with value = '1'",cn);
1708 mod_gzip_printf( "%s: ************************************************",cn);
1709 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
1710 #endif
1711
1712 return DECLINED;
1713 }
1714 else
1715 {
1716 #ifdef MOD_GZIP_DEBUG1
1717 mod_gzip_printf( "%s: 'mod_gzip_running' note value is NOT '1'...",cn);
1718 #endif
1719 }
1720 }
1721 else
1722 {
1723 #ifdef MOD_GZIP_DEBUG1
1724 mod_gzip_printf( "%s: 'mod_gzip_running' note NOT FOUND",cn);
1725 #endif
1726 }
1727 }
1728 #ifdef MOD_GZIP_DEBUG1
1729 else
1730 {
1731 mod_gzip_printf( "%s: r->prev is NULL... This is NOT a redirection",cn);
1732 }
1733 #endif
1734
1735 #ifdef MOD_GZIP_DEBUG1
1736 mod_gzip_printf( "%s: dconf->min_http = %ld", cn, (long) dconf->min_http );
1737 mod_gzip_printf( "%s: r->proto_num = %ld", cn, (long) r->proto_num );
1738 #endif
1739
1740 if ( ( dconf->min_http > 0 ) && ( r->proto_num > 0 ) )
1741 {
1742 if ( r->proto_num < dconf->min_http )
1743 {
1744 #ifdef MOD_GZIP_USES_APACHE_LOGS
1745 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:HTTP_LEVEL_TOO_LOW"));
1746 #endif
1747
1748 #ifdef MOD_GZIP_DEBUG1
1749 mod_gzip_printf( "%s: HTTP protocol version level is TOO LOW", cn);
1750 mod_gzip_printf( "%s: Exit > return( DECLINED ) >", cn);
1751 #endif
1752
1753 return DECLINED;
1754 }
1755 else
1756 {
1757 #ifdef MOD_GZIP_DEBUG1
1758 mod_gzip_printf( "%s: HTTP protocol version level is OK", cn);
1759 #endif
1760 }
1761 }
1762
1763 #ifdef MOD_GZIP_DEBUG1
1764 mod_gzip_printf( "%s: Checking for [Accept-Encoding: gzip]", cn );
1765 #endif
1766
1767 tablestring = ap_table_get(r->headers_in, "Accept-Encoding");
1768
1769 #ifdef MOD_GZIP_DEBUG1
1770 mod_gzip_printf( "%s: r->headers_in->Accept-Encoding = [%s]",
1771 cn,npp(tablestring));
1772 #endif
1773
1774 if ( tablestring )
1775 {
1776 #ifdef MOD_GZIP_DEBUG1
1777 mod_gzip_printf( "%s: 'Accept-Encoding' field seen...", cn);
1778 mod_gzip_printf( "%s: Checking for 'gzip' value...", cn);
1779 #endif
1780
1781 if ( mod_gzip_stringcontains( (char *)tablestring, "gzip" ) )
1782 {
1783 #ifdef MOD_GZIP_DEBUG1
1784 mod_gzip_printf( "%s: 'gzip' value seen...", cn);
1785 #endif
1786
1787 accept_encoding_gzip_seen = 1;
1788 }
1789 else
1790 {
1791 #ifdef MOD_GZIP_USES_APACHE_LOGS
1792 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:NO_GZIP"));
1793 #endif
1794
1795 #ifdef MOD_GZIP_DEBUG1
1796 mod_gzip_printf( "%s: 'gzip' value NOT seen...", cn);
1797 mod_gzip_printf( "%s: Exit > return( DECLINED ) >", cn);
1798 #endif
1799
1800 return DECLINED;
1801 }
1802 }
1803 else
1804 {
1805 #ifdef MOD_GZIP_USES_APACHE_LOGS
1806 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:NO_ACCEPT_ENCODING"));
1807 #endif
1808
1809 #ifdef MOD_GZIP_DEBUG1
1810 mod_gzip_printf( "%s: 'Accept-Encoding' field NOT seen...", cn);
1811 mod_gzip_printf( "%s: Exit > return( DECLINED ) >", cn);
1812 #endif
1813
1814 return DECLINED;
1815 }
1816
1817 #ifdef MOD_GZIP_DEBUG1
1818 mod_gzip_printf( "%s: accept_encoding_gzip_seen = %ld",
1819 cn, accept_encoding_gzip_seen );
1820 #endif
1821
1822 #ifdef MOD_GZIP_DEBUG1
1823 mod_gzip_printf( "%s: dconf->imap_total_entries = %d", cn,
1824 (int) dconf->imap_total_entries );
1825 #endif
1826
1827 if ( dconf->imap_total_entries < 1 )
1828 {
1829 #ifdef MOD_GZIP_USES_APACHE_LOGS
1830 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:NO_ITEMS_DEFINED"));
1831 #endif
1832
1833 #ifdef MOD_GZIP_DEBUG1
1834 mod_gzip_printf( "%s: There are no IMAP entries. Unable to include/exclude",cn);
1835 mod_gzip_printf( "%s: Exit > return( DECLINED ) >", cn);
1836 #endif
1837
1838 return DECLINED;
1839 }
1840
1841 #ifdef MOD_GZIP_DEBUG1
1842 mod_gzip_printf( "%s: dconf->imap_total_isreqheader = %d", cn,
1843 (int) dconf->imap_total_isreqheader );
1844 #endif
1845
1846 if ( dconf->imap_total_isreqheader > 0 )
1847 {
1848 #ifdef MOD_GZIP_DEBUG1
1849 mod_gzip_printf( "%s: Checking inbound REQUEST header fields...", cn );
1850 #endif
1851
1852 t = (_table *) r->headers_in;
1853 elts = (table_entry *) t->a.elts;
1854
1855 for ( i = 0; i < t->a.nelts; i++ )
1856 {
1857 #ifdef MOD_GZIP_DEBUG1
1858 mod_gzip_printf( "%s: %3.3d key=[%s] val=[%s]",
1859 cn,i,npp(elts[i].key),npp(elts[i].val));
1860 #endif
1861
1862 tablekey = elts[i].key;
1863 tablestring = elts[i].val;
1864
1865 if (( tablekey && tablestring ))
1866 {
1867 #ifdef MOD_GZIP_DEBUG1
1868 mod_gzip_printf( "%s: Checking key[%s] string[%s]",
1869 cn,npp(tablekey),npp(tablestring));
1870 mod_gzip_printf( "%s: Call mod_gzip_validate1()...",cn);
1871 #endif
1872
1873 field_ok =
1874 mod_gzip_validate1(
1875 (request_rec *) r,
1876 (mod_gzip_conf *) dconf,
1877 NULL, /* r->filename (Not used here) */
1878 NULL, /* r->uri (Not used here) */
1879 NULL, /* r->content_type (Not used here) */
1880 NULL, /* r->handler (Not used here) */
1881 (char *) tablekey, /* (Field key ) */
1882 (char *) tablestring, /* (Field string ) */
1883 MOD_GZIP_REQUEST /* (Direction ) */
1884 );
1885
1886 #ifdef MOD_GZIP_DEBUG1
1887 mod_gzip_printf( "%s: Back mod_gzip_validate1()...",cn);
1888 mod_gzip_printf( "%s: field_ok = %d",cn,field_ok);
1889 #endif
1890
1891 if ( field_ok == MOD_GZIP_IMAP_DECLINED1 )
1892 {
1893 #ifdef MOD_GZIP_USES_APACHE_LOGS
1894 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:REQ_HEADER_FIELD_EXCLUDED"));
1895 #endif
1896
1897 #ifdef MOD_GZIP_DEBUG1
1898 mod_gzip_printf( "%s: This request is EXCLUDED...",cn);
1899 mod_gzip_printf( "%s: Exit > return( DECLINED ) >", cn);
1900 #endif
1901
1902 return DECLINED;
1903 }
1904 }
1905 }
1906 }
1907 #ifdef MOD_GZIP_DEBUG1
1908 else
1909 {
1910 #ifdef MOD_GZIP_DEBUG1
1911 mod_gzip_printf( "%s: NO CHECK required on inbound REQUEST header fields...", cn );
1912 #endif
1913 }
1914 #endif
1915
1916 #ifdef MOD_GZIP_DEBUG1
1917 mod_gzip_printf( "%s: 1 ***: r->uri =[%s]", cn, npp(r->uri ));
1918 mod_gzip_printf( "%s: 1 ***: r->unparsed_uri=[%s]", cn, npp(r->unparsed_uri ));
1919 mod_gzip_printf( "%s: 1 ***: r->filename =[%s]", cn, npp(r->filename ));
1920 mod_gzip_printf( "%s: 1 ***: r->content_type=[%s]", cn, npp(r->content_type ));
1921 mod_gzip_printf( "%s: 1 ***: r->handler =[%s]", cn, npp(r->handler ));
1922 #endif
1923
1924 if ( !r->content_type )
1925 {
1926 #ifdef MOD_GZIP_DEBUG1
1927 mod_gzip_printf( "%s: 'r->content_type' is NULL...",cn);
1928 mod_gzip_printf( "%s: Performing 'quick lookup'...",cn);
1929 mod_gzip_printf( "%s: Call mod_gzip_run_handlers(r,RUN_TYPE_CHECKERS)...",cn);
1930 #endif
1931
1932 rc = mod_gzip_run_handlers( r, MOD_GZIP_RUN_TYPE_CHECKERS );
1933
1934 #ifdef MOD_GZIP_DEBUG1
1935
1936 mod_gzip_printf( "%s: Back mod_gzip_run_handlers(r,RUN_TYPE_CHECKERS)...",cn);
1937
1938 if ( rc == OK )
1939 {
1940 mod_gzip_printf( "%s: rc = %d = OK",cn, rc );
1941 }
1942 else if ( rc == DECLINED )
1943 {
1944 mod_gzip_printf( "%s: rc = %d = DECLINED",cn, rc );
1945 }
1946 else if ( rc == DONE )
1947 {
1948 mod_gzip_printf( "%s: rc = %d = DONE",cn, rc );
1949 }
1950 else
1951 {
1952 mod_gzip_printf( "%s: rc = %d = HTTP_ERROR?",cn, rc );
1953 }
1954
1955 #endif
1956 }
1957 #ifdef MOD_GZIP_DEBUG1
1958 else
1959 {
1960 mod_gzip_printf( "%s: 'r->content_type' is VALID already...",cn);
1961 mod_gzip_printf( "%s: No 'quick lookup' was performed...",cn);
1962 }
1963 #endif
1964
1965 #ifdef MOD_GZIP_DEBUG1
1966 mod_gzip_printf( "%s: 2 ***: r->uri =[%s]", cn, npp(r->uri ));
1967 mod_gzip_printf( "%s: 2 ***: r->unparsed_uri=[%s]", cn, npp(r->unparsed_uri ));
1968 mod_gzip_printf( "%s: 2 ***: r->filename =[%s]", cn, npp(r->filename ));
1969 mod_gzip_printf( "%s: 2 ***: r->content_type=[%s]", cn, npp(r->content_type ));
1970 mod_gzip_printf( "%s: 2 ***: r->handler =[%s]", cn, npp(r->handler ));
1971 mod_gzip_printf( "%s: Call mod_gzip_validate1()...",cn);
1972 #endif
1973
1974 action_flag =
1975 mod_gzip_validate1(
1976 (request_rec *) r,
1977 (mod_gzip_conf *) dconf,
1978 (char *) r->filename,
1979 (char *) r->uri,
1980 (char *) r->content_type,
1981 (char *) r->handler,
1982 NULL, /* Field key (Not used here) */
1983 NULL, /* Field string (Not used here) */
1984 0 /* Direction (Not used here) */
1985 );
1986
1987 #ifdef MOD_GZIP_DEBUG1
1988
1989 mod_gzip_printf( "%s: Back mod_gzip_validate1()...",cn);
1990 mod_gzip_printf( "%s: action_flag = %d",cn,action_flag);
1991
1992 if ( action_flag == MOD_GZIP_IMAP_DYNAMIC1 )
1993 {
1994 mod_gzip_printf( "%s: action_flag = MOD_GZIP_IMAP_DYNAMIC1",cn);
1995 }
1996 else if ( action_flag == MOD_GZIP_IMAP_DYNAMIC2 )
1997 {
1998 mod_gzip_printf( "%s: action_flag = MOD_GZIP_IMAP_DYNAMIC2",cn);
1999 }
2000 else if ( action_flag == MOD_GZIP_IMAP_STATIC1 )
2001 {
2002 mod_gzip_printf( "%s: action_flag = MOD_GZIP_IMAP_STATIC1",cn);
2003 }
2004 else if ( action_flag == MOD_GZIP_IMAP_DECLINED1 )
2005 {
2006 mod_gzip_printf( "%s: action_flag = MOD_GZIP_IMAP_DECLINED1",cn);
2007 }
2008 else
2009 {
2010 mod_gzip_printf( "%s: action_flag = MOD_GZIP_IMAP_??? Unknown action",cn);
2011 }
2012
2013 #endif
2014
2015 if ( action_flag != MOD_GZIP_IMAP_DECLINED1 )
2016 {
2017 #ifdef MOD_GZIP_DEBUG1
2018 mod_gzip_printf( "%s: This transaction is a valid candidate...",cn);
2019 mod_gzip_printf( "%s: Saving current r->handler value [%s] to mod_gzip_r_handler note...",
2020 cn, npp(r->handler) );
2021 #endif
2022
2023 if ( r->handler )
2024 {
2025 ap_table_setn( r->notes,"mod_gzip_r_handler",ap_pstrdup(r->pool,r->handler));
2026 }
2027 else
2028 {
2029 ap_table_setn( r->notes,"mod_gzip_r_handler",ap_pstrdup(r->pool,"0"));
2030 }
2031
2032 #ifdef MOD_GZIP_DEBUG1
2033 mod_gzip_printf( "%s: Forcing r->handler to be 'mod_gzip_handler'...", cn );
2034 #endif
2035
2036 r->handler = "mod_gzip_handler";
2037
2038 #ifdef MOD_GZIP_DEBUG1
2039 mod_gzip_printf( "%s: r->handler is now = [%s]", cn, npp(r->handler) );
2040 mod_gzip_printf( "%s: Exit > return( OK ) >", cn );
2041 mod_gzip_printf( " " );
2042 #endif
2043
2044 return OK;
2045 }
2046 else
2047 {
2048 #ifdef MOD_GZIP_DEBUG1
2049 mod_gzip_printf( "%s: This transaction is NOT a valid candidate...",cn);
2050 #endif
2051
2052 #ifdef MOD_GZIP_USES_APACHE_LOGS
2053 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:EXCLUDED"));
2054 #endif
2055
2056 #ifdef MOD_GZIP_DEBUG1
2057 mod_gzip_printf( "%s: Exit > return( DECLINED ) >", cn );
2058 mod_gzip_printf( " " );
2059 #endif
2060
2061 return DECLINED;
2062 }
2063 }
2064
2065 #ifdef MOD_GZIP_COMMAND_VERSION_USED
2066
2067 int mod_gzip_do_command(
2068 int this_command, /* MOD_GZIP_COMMAND_XXXX */
2069 request_rec *r, /* Request record */
2070 mod_gzip_conf *dconf /* Directory config pointer */
2071 )
2072 {
2073 /* Generic command response transmitter... */
2074
2075 char tmpbuf[2048]; /* Fill/flush as needed. Don't overflow */
2076 char *tmp=tmpbuf;
2077 int tmplen=0;
2078 char s1[90];
2079
2080 #ifdef USE_MOD_GZIP_DEBUG1
2081 char cn[]="mod_gzip.c: mod_gzip_send_html_command_response()";
2082 #endif
2083
2084 /* Start... */
2085
2086 if ( this_command == MOD_GZIP_COMMAND_VERSION )
2087 {
2088 mod_gzip_strcpy(s1,"No");
2089
2090 if ( dconf )
2091 {
2092 if ( dconf->is_on == 1 ) mod_gzip_strcpy(s1,"Yes");
2093 }
2094
2095 sprintf( tmp,
2096 "<html><head><title>mod_gzip status</title></head><body>"
2097 "mod_gzip is available...<br>\r\n"
2098 "mod_gzip_version = %s<br>\r\n"
2099 "mod_gzip_on = %s<br>\r\n"
2100 "</body></html>",
2101 mod_gzip_version,
2102 s1
2103 );
2104
2105 #ifdef MOD_GZIP_USES_APACHE_LOGS
2106 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"COMMAND:VERSION"));
2107 #endif
2108 }
2109 else
2110 {
2111 #ifdef MOD_GZIP_USES_APACHE_LOGS
2112 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:INVALID_COMMAND"));
2113 #endif
2114
2115 return( DECLINED );
2116 }
2117
2118 /* Add the length of the response to the output header... */
2119 /* The third parameter to ap_table_set() MUST be a string. */
2120
2121 tmplen = strlen( tmp );
2122
2123 sprintf( s1, "%d", tmplen );
2124
2125 ap_table_set( r->headers_out, "Content-Length", s1 );
2126
2127 /* Make sure the content type matches this response... */
2128
2129 r->content_type = "text/html";
2130
2131 /* Start a timer for this return trip... */
2132
2133 ap_soft_timeout( "mod_gzip: mod_gzip_do_command", r );
2134
2135 #ifdef MOD_GZIP_COMMANDS_USE_LAST_MODIFIED
2136
2137 /* Set the 'Last modified' stamp to current time/date... */
2138
2139 ap_set_last_modified(r);
2140
2141 /* TODO? Add 'no-cache' option(s) to mod_gzip command responses */
2142 /* so user doesn't have hit reload to get fresh data? This might */
2143 /* be necessary for static files that are subject to an Apache */
2144 /* lookup but mod_gzip command results as sent 'fresh' each */
2145 /* time no matter what so there doesn't seem to be a need for */
2146 /* any 'Last modified' information. Just pump a 200 + data and */
2147 /* then turn and burn... */
2148
2149 #endif /* MOD_GZIP_COMMANDS_USE_LAST_MODIFIED */
2150
2151 /* Send the HTTP response header... */
2152
2153 ap_send_http_header(r);
2154
2155 /* Send the response BODY... */
2156
2157 ap_send_mmap( tmp, r, 0, tmplen );
2158
2159 /* Clean up and exit... */
2160
2161 ap_kill_timeout(r);
2162
2163 return OK;
2164
2165 }/* End of mod_gzip_send_html_command_response() */
2166
2167 #endif /* MOD_GZIP_COMMAND_VERSION_USED */
2168
2169
2170 static int mod_gzip_handler( request_rec *r )
2171 {
2172 #ifdef MOD_GZIP_DEBUG1
2173 char cn[]="mod_gzip_handler()";
2174 #endif
2175
2176 int rc = DECLINED;
2177 int action_flag = 0;
2178
2179 request_rec *r__next=0;
2180
2181 mod_gzip_conf *sconf = 0;
2182 mod_gzip_conf *dconf = 0;
2183
2184 const char *tablestring;
2185
2186 const char *s1;
2187 const char *s2;
2188 const char *s3;
2189 const char *s4;
2190
2191 #ifdef MOD_GZIP_CAN_NEGOTIATE
2192 struct stat statbuf;
2193 struct stat statbuf1;
2194 char *new_uri;
2195 char *new_name;
2196 int precompressed_send_ok = 1;
2197 #endif
2198
2199 #ifdef MOD_GZIP_DEBUG1
2200
2201 mod_gzip_server_now = r->server;
2202
2203 mod_gzip_printf( " " );
2204
2205 mod_gzip_printf( "%s: ''''Entry...",cn);
2206 mod_gzip_printf( "%s: r = %ld", cn,(long)r);
2207 mod_gzip_printf( "%s: r->main = %ld", cn,(long)r->main);
2208 mod_gzip_printf( "%s: r->next = %ld", cn,(long)r->next);
2209 mod_gzip_printf( "%s: r->prev = %ld", cn,(long)r->prev);
2210 mod_gzip_printf( "%s: r->unparsed_uri = [%s]",cn,npp(r->unparsed_uri));
2211 mod_gzip_printf( "%s: r->uri = [%s]",cn,npp(r->uri));
2212 mod_gzip_printf( "%s: r->filename = [%s]",cn,npp(r->filename));
2213 mod_gzip_printf( "%s: r->handler = [%s]",cn,npp(r->handler));
2214
2215 #endif
2216
2217 if ( r->main ) /* SUBREQUEST */
2218 {
2219 #ifdef MOD_GZIP_DEBUG1
2220 mod_gzip_printf( "%s: r->main is TRUE - This is a subrequest...",cn);
2221 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
2222 #endif
2223
2224 return DECLINED;
2225 }
2226 #ifdef MOD_GZIP_DEBUG1
2227 else
2228 {
2229 mod_gzip_printf( "%s: r->main is FALSE",cn);
2230 mod_gzip_printf( "%s: This is NOT a subrequest in progress...",cn);
2231 mod_gzip_printf( "%s: OK to continue...",cn);
2232 }
2233 #endif
2234
2235 if ( r->prev ) /* REDIRECT */
2236 {
2237 #ifdef MOD_GZIP_DEBUG1
2238 mod_gzip_printf( "%s: r->prev is TRUE - This is a redirection...",cn);
2239 #endif
2240
2241 /* This might be a 'directory' index lookup... */
2242
2243 tablestring = ap_table_get(r->prev->notes, "mod_gzip_running");
2244
2245 #ifdef MOD_GZIP_DEBUG1
2246 mod_gzip_printf( "%s: r->prev->notes->mod_gzip_running = [%s]",
2247 cn,npp(tablestring));
2248 #endif
2249
2250 if ( tablestring )
2251 {
2252 #ifdef MOD_GZIP_DEBUG1
2253 mod_gzip_printf( "%s: 'mod_gzip_running' note FOUND",cn);
2254 #endif
2255
2256 if ( *tablestring == '1' )
2257 {
2258 #ifdef MOD_GZIP_DEBUG1
2259 mod_gzip_printf( "%s: 'mod_gzip_running' note value is '1'...",cn);
2260 #endif
2261
2262 #ifdef MOD_GZIP_DEBUG1
2263 mod_gzip_printf( "%s: ************************************************",cn);
2264 mod_gzip_printf( "%s: mod_gzip is currently 'running' so we ",cn);
2265 mod_gzip_printf( "%s: must return DECLINED.",cn);
2266 mod_gzip_printf( "%s: ************************************************",cn);
2267 mod_gzip_printf( "%s: IMPORTANT: We must now 'replicate' the note flag",cn);
2268 mod_gzip_printf( "%s: on this record or next time around r->prev",cn);
2269 mod_gzip_printf( "%s: note flag check will be FALSE.",cn);
2270 mod_gzip_printf( "%s: ************************************************",cn);
2271 #endif
2272
2273 ap_table_setn(r->notes,"mod_gzip_running",ap_pstrdup(r->pool,"1"));
2274
2275 #ifdef MOD_GZIP_DEBUG1
2276 mod_gzip_printf( "%s: r->notes 'mod_gzip_running' set with value = '1'",cn);
2277 mod_gzip_printf( "%s: ************************************************",cn);
2278 #endif
2279
2280 #ifdef MOD_GZIP_DEBUG1
2281 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
2282 #endif
2283
2284 return DECLINED;
2285 }
2286 #ifdef MOD_GZIP_DEBUG1
2287 else
2288 {
2289 mod_gzip_printf( "%s: 'mod_gzip_running' note value is NOT '1'...",cn);
2290 }
2291 #endif
2292 }
2293 #ifdef MOD_GZIP_DEBUG1
2294 else
2295 {
2296 mod_gzip_printf( "%s: 'mod_gzip_running' note NOT FOUND",cn);
2297 }
2298 #endif
2299 }
2300 #ifdef MOD_GZIP_DEBUG1
2301 else
2302 {
2303 mod_gzip_printf( "%s: r->prev is FALSE",cn);
2304 mod_gzip_printf( "%s: This is NOT a redirection in progress...",cn);
2305 mod_gzip_printf( "%s: OK to continue...",cn);
2306 }
2307 #endif
2308
2309 sconf = ( mod_gzip_conf * )
2310 ap_get_module_config( r->server->module_config, &gzip_module );
2311
2312 dconf = ( mod_gzip_conf * )
2313 ap_get_module_config( r->per_dir_config, &gzip_module );
2314
2315
2316 #ifdef MOD_GZIP_DEBUG1
2317 mod_gzip_printf("%s: i'm going to check r->filename",cn);
2318 #endif
2319
2320 if(r->filename) {
2321 #ifdef MOD_GZIP_DEBUG1
2322 mod_gzip_printf("%s: suffix is %s, filename is %s",cn,dconf->suffix,r->filename);
2323 #endif
2324
2325 if(mod_gzip_strendswith(r->filename, dconf->suffix, 1)) {
2326 #ifdef MOD_GZIP_USES_APACHE_LOGS
2327 if(r->prev) {
2328 /* This is a mod_gzip negotiated .gz static file transmit... */
2329 const char *t = ap_table_get(r->prev->notes,"mod_gzip_result_n");
2330 ap_table_setn(r->notes,"mod_gzip_result",ap_pstrdup(r->pool,t ? t : "DECLINED:STATIC_GZ_FOUND"));
2331 }
2332 else {
2333 /* This is a direct request from client for a .gz file... */
2334 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:FEXT_GZ"));
2335 }
2336 #endif
2337
2338 #ifdef MOD_GZIP_DEBUG1
2339 mod_gzip_printf( "%s: r->filename ends with '%s'...",dconf->suffix);
2340 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
2341 #endif
2342
2343 return DECLINED;
2344 }
2345 #ifdef MOD_GZIP_DEBUG1
2346 else {
2347 mod_gzip_printf( "%s: r->filename does NOT end with '%s'...",cn,dconf->suffix);
2348 mod_gzip_printf( "%s: OK to continue...",cn);
2349 }
2350 #endif
2351 }
2352
2353 #ifdef MOD_GZIP_DEBUG1
2354 mod_gzip_printf( "%s: r->server->server_hostname = [%s]", cn,npp(r->server->server_hostname));
2355 mod_gzip_printf( "%s: sconf = %ld", cn,(long)sconf);
2356 mod_gzip_printf( "%s: sconf->loc = [%s]",cn,npp(sconf->loc));
2357 mod_gzip_printf( "%s: sconf->is_on = %ld", cn,(long)sconf->is_on);
2358 mod_gzip_printf( "%s: dconf = %ld", cn,(long)dconf);
2359 mod_gzip_printf( "%s: dconf->loc = [%s]",cn,npp(dconf->loc));
2360 mod_gzip_printf( "%s: dconf->is_on = %ld", cn,(long)dconf->is_on);
2361 #endif
2362
2363 #ifdef MOD_GZIP_COMMAND_VERSION_USED
2364
2365 /* NOTE: Certain mod_gzip 'commands' should return a response */
2366 /* even if mod_gzip is OFF in the current location. Make sure */
2367 /* the checks for these commands take place BEFORE checking */
2368 /* the actual mod_gzip on/off status... */
2369
2370 #ifdef MOD_GZIP_DEBUG1
2371 mod_gzip_printf( "%s: dconf->command_version = [%s]",cn,npp(dconf->command_version));
2372 #endif
2373
2374 /* Check for mod_gzip commands in the 'r->unparsed_uri' request */
2375 /* line so the commands can actually be part of query parms that */
2376 /* follow the '?'. 'r->uri' is simply he URI itself with any/all */
2377 /* additional query arguments removed already... */
2378
2379 if ( dconf->command_version[0] != 0 )
2380 {
2381 if ( mod_gzip_stringcontains(r->unparsed_uri,dconf->command_version))
2382 {
2383 #ifdef MOD_GZIP_DEBUG1
2384 mod_gzip_printf( "%s: Call mod_gzip_do_command( MOD_GZIP_COMMAND_VERSION, r )...",cn);
2385 #endif
2386
2387 /* mod_gzip_do_command() returns the correct command */
2388 /* response page and (normally) just returns 'OK'... */
2389
2390 return(
2391 mod_gzip_do_command(
2392 MOD_GZIP_COMMAND_VERSION,
2393 r,
2394 dconf
2395 ));
2396 }
2397 }
2398
2399 #endif /* MOD_GZIP_COMMAND_VERSION_USED */
2400
2401 tablestring = ap_table_get(r->notes, "mod_gzip_r_handler");
2402
2403 if ( !tablestring )
2404 {
2405 #ifdef MOD_GZIP_DEBUG1
2406 mod_gzip_printf( "%s: r->notes->mod_gzip_r_handler = NOT FOUND",cn);
2407 mod_gzip_printf( "%s: This transaction will be ignored...",cn);
2408 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
2409 #endif
2410
2411 return DECLINED;
2412 }
2413
2414 #ifdef MOD_GZIP_DEBUG1
2415 mod_gzip_printf( "%s: r->notes->mod_gzip_r_handler = FOUND",cn);
2416 mod_gzip_printf( "%s: r->notes->mod_gzip_r_handler = [%s]",cn,npp(tablestring));
2417 #endif
2418
2419 #ifdef MOD_GZIP_USES_APACHE_LOGS
2420 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"INIT2"));
2421 #endif
2422
2423 if ( !dconf->is_on )
2424 {
2425 #ifdef MOD_GZIP_USES_APACHE_LOGS
2426 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:OFF2"));
2427 #endif
2428
2429 #ifdef MOD_GZIP_DEBUG1
2430 mod_gzip_printf( "%s: 'dconf->is_on' is FALSE",cn);
2431 mod_gzip_printf( "%s: mod_gzip is not turned ON for this location...",cn);
2432 mod_gzip_printf( "%s: This transaction will be ignored...",cn);
2433 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
2434 #endif
2435
2436 return DECLINED;
2437 }
2438
2439 if ( *tablestring == '0' )
2440 {
2441 r->handler = 0;
2442 }
2443 else
2444 {
2445 r->handler = tablestring;
2446 }
2447
2448 #ifdef MOD_GZIP_DEBUG1
2449 mod_gzip_printf( "%s: r->handler set back to = [%s]",cn,npp(r->handler));
2450 #endif
2451
2452 /* Verify it (again) in case names have changed... */
2453
2454 #ifdef MOD_GZIP_DEBUG1
2455 mod_gzip_printf( "%s: Call mod_gzip_validate1()...",cn);
2456 #endif
2457
2458 action_flag =
2459 mod_gzip_validate1(
2460 (request_rec *) r,
2461 (mod_gzip_conf *) dconf,
2462 (char *) r->filename,
2463 (char *) r->uri,
2464 (char *) r->content_type,
2465 (char *) r->handler,
2466 NULL, /* Field key (Not used here */
2467 NULL, /* Field string (Not used here) */
2468 0 /* Direction (Not used here) */
2469 );
2470
2471 #ifdef MOD_GZIP_DEBUG1
2472
2473 mod_gzip_printf( "%s: Back mod_gzip_validate1()...",cn);
2474 mod_gzip_printf( "%s: action_flag = %d",cn,action_flag);
2475
2476 if ( action_flag == MOD_GZIP_IMAP_DYNAMIC1 )
2477 {
2478 mod_gzip_printf( "%s: action_flag = MOD_GZIP_IMAP_DYNAMIC1",cn);
2479 }
2480 else if ( action_flag == MOD_GZIP_IMAP_DYNAMIC2 )
2481 {
2482 mod_gzip_printf( "%s: action_flag = MOD_GZIP_IMAP_DYNAMIC2",cn);
2483 }
2484 else if ( action_flag == MOD_GZIP_IMAP_STATIC1 )
2485 {
2486 mod_gzip_printf( "%s: action_flag = MOD_GZIP_IMAP_STATIC1",cn);
2487 }
2488 else if ( action_flag == MOD_GZIP_IMAP_DECLINED1 )
2489 {
2490 mod_gzip_printf( "%s: action_flag = MOD_GZIP_IMAP_DECLINED1",cn);
2491 }
2492 else
2493 {
2494 mod_gzip_printf( "%s: action_flag = MOD_GZIP_IMAP_??? Unknown action",cn);
2495 }
2496
2497 #endif
2498
2499 if ( action_flag == MOD_GZIP_IMAP_DECLINED1 )
2500 {
2501 #ifdef MOD_GZIP_DEBUG1
2502 mod_gzip_printf( "%s: This transaction is NOT a valid candidate...",cn);
2503 mod_gzip_printf( "%s: This transaction will be ignored...",cn);
2504 #endif
2505
2506 #ifdef MOD_GZIP_USES_APACHE_LOGS
2507 ap_table_setn( r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:EXCLUDED_BY_HANDLER"));
2508 #endif
2509
2510 #ifdef MOD_GZIP_DEBUG1
2511 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
2512 #endif
2513
2514 return DECLINED;
2515 }
2516
2517 #ifdef MOD_GZIP_DEBUG1
2518 mod_gzip_printf( "%s: This transaction is a valid candidate...",cn);
2519 #endif
2520
2521 #ifdef MOD_GZIP_CAN_NEGOTIATE
2522
2523 #ifdef MOD_GZIP_DEBUG1
2524 mod_gzip_printf( "%s: dconf->can_negotiate = %d",cn,(int)dconf->can_negotiate);
2525 #endif
2526
2527 if ( dconf->can_negotiate == 1 )
2528 {
2529 #ifdef MOD_GZIP_DEBUG1
2530 mod_gzip_printf( "%s: dconf->can_negotiate is TRUE...",cn);
2531 #endif
2532
2533 /* Check for a static compressed version of the file requested... */
2534
2535 new_name = ap_pstrcat(r->pool, r->filename, dconf->suffix, NULL);
2536
2537 #ifdef MOD_GZIP_DEBUG1
2538 mod_gzip_printf( "%s: Call stat(new_name=[%s])...",cn,npp(new_name));
2539 #endif
2540
2541 if ( stat( new_name, &statbuf) != 0 )
2542 {
2543 #ifdef MOD_GZIP_DEBUG1
2544 mod_gzip_printf( "%s: .... stat() call FAILED",cn);
2545 mod_gzip_printf( "%s: OK to continue...",cn);
2546 #endif
2547 }
2548 else
2549 {
2550 #ifdef MOD_GZIP_DEBUG1
2551 mod_gzip_printf( "%s: .... stat() call SUCCEEDED",cn);
2552 #endif
2553 if(stat(r->filename,&statbuf1) == 0) {
2554 /*
2555 * create a new precompressed version
2556 */
2557 if(!(statbuf1.st_atime <= statbuf.st_atime || statbuf1.st_mtime <= statbuf.st_mtime)) {
2558 if(dconf->refresh_files) {
2559 precompressed_send_ok = mod_gzip_compress_file(r,new_name);
2560 }
2561 else {
2562 #ifdef MOD_GZIP_USES_APACHE_LOGS
2563 ap_table_setn(r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"SEND_AS_IS:FOPEN_FAILED"));
2564 #endif
2565
2566 return DECLINED;
2567 }
2568 }
2569
2570 if(precompressed_send_ok) {
2571 #ifdef MOD_GZIP_DEBUG
2572 mod_gzip_printf( "%s: Sending precompressed version of file...",cn);
2573 mod_gzip_printf( "%s: GZ_REDIRECT: START...",cn);
2574 #endif
2575
2576 new_name = ap_pstrcat(r->pool, r->uri, dconf->suffix, NULL);
2577
2578 if( r->args != NULL ) {
2579 new_uri = ap_pstrcat(r->pool, new_name, "?", r->args, NULL);
2580 }
2581 else {
2582 new_uri = ap_pstrdup(r->pool, new_name);
2583 }
2584
2585 #ifdef MOD_GZIP_DEBUG1
2586 mod_gzip_printf( "%s: Call ap_internal_redirect(new_uri=[%s])...",
2587 cn,npp(new_uri));
2588 mod_gzip_printf( " " );
2589 #endif
2590
2591 ap_internal_redirect(new_uri, r);
2592
2593 #ifdef MOD_GZIP_DEBUG1
2594 mod_gzip_printf( " " );
2595 mod_gzip_printf( "%s: Back ap_internal_redirect(new_uri=[%s])...",
2596 cn,npp(new_uri));
2597 mod_gzip_printf( "%s: GZ_REDIRECT: FINISHED...",cn);
2598 #endif
2599
2600 #ifdef MOD_GZIP_DEBUG1
2601 mod_gzip_printf( "%s: Exit > return( OK ) >",cn);
2602 #endif
2603
2604 /* We are about to return OK to end the transaction but go */
2605 /* ahead and make the mod_gzip final result a DECLINED */
2606 /* condition since that's what actually happened... */
2607
2608 #ifdef MOD_GZIP_USES_APACHE_LOGS
2609 ap_table_setn(r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:STATIC_GZ_FOUND"));
2610 #endif
2611
2612 return OK;
2613 }
2614 else {
2615 #ifdef MOD_GZIP_USES_APACHE_LOGS
2616 ap_table_setn(r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"SEND_AS_IS:PRECOMPRESSED_VARIANT_OUTDATED"));
2617 #endif
2618
2619 return DECLINED;
2620 }
2621 }
2622 }
2623 }
2624 #ifdef MOD_GZIP_DEBUG1
2625 else
2626 {
2627 mod_gzip_printf( "%s: dconf->can_negotiate is FALSE",cn);
2628 }
2629 #endif
2630
2631 #endif /* MOD_GZIP_CAN_NEGOTIATE */
2632
2633 #ifdef MOD_GZIP_DEBUG1
2634 mod_gzip_printf( "%s: Call mod_gzip_redir1_handler( r, dconf )...",cn);
2635 #endif
2636
2637 rc = (int) mod_gzip_redir1_handler( r, dconf );
2638
2639 #ifdef MOD_GZIP_DEBUG1
2640
2641 mod_gzip_printf( "%s: Back mod_gzip_redir1_handler( r, dconf )...",cn);
2642
2643 if ( rc == OK )
2644 {
2645 mod_gzip_printf( "%s: rc = %d OK", cn, (int) rc);
2646 }
2647 else if ( rc == DECLINED )
2648 {
2649 mod_gzip_printf( "%s: rc = %d DECLINED", cn, (int) rc );
2650 }
2651 else
2652 {
2653 mod_gzip_printf( "%s: rc = %d ( HTTP ERROR CODE? )", cn, (int) rc );
2654 }
2655
2656 #endif
2657
2658 if ( rc != OK )
2659 {
2660 #ifdef MOD_GZIP_DEBUG1
2661 mod_gzip_printf( "%s: mod_gzip_redir1_handler() call FAILED...",cn);
2662 #endif
2663
2664 #ifdef MOD_GZIP_USES_APACHE_LOGS
2665
2666 ap_table_setn(
2667 r->notes,"mod_gzip_result",ap_pstrdup(r->pool,"RECOVERY"));
2668 #endif
2669
2670 ap_log_error( APLOG_MARK,APLOG_NOERRNO|APLOG_WARNING, r->server,
2671 "mod_gzip: RECOVERY [%s]", r->the_request );
2672
2673 #ifdef MOD_GZIP_DEBUG1
2674 mod_gzip_printf( "%s: RECOVERY_REDIRECT: START...",cn);
2675 mod_gzip_printf( "%s: Call ap_internal_redirect(r->unparsed_uri=[%s])...",
2676 cn,npp(r->unparsed_uri));
2677 mod_gzip_printf( " " );
2678 #endif
2679
2680 ap_internal_redirect( r->unparsed_uri, r );
2681
2682 #ifdef MOD_GZIP_DEBUG1
2683 mod_gzip_printf( " " );
2684 mod_gzip_printf( "%s: Back ap_internal_redirect(r->unparsed_uri=[%s])...",
2685 cn,npp(r->unparsed_uri));
2686 mod_gzip_printf( "%s: RECOVERY_REDIRECT: FINISHED...",cn);
2687 #endif
2688
2689 rc = OK;
2690 }
2691
2692 #ifdef MOD_GZIP_USES_APACHE_LOGS
2693
2694 if ( r->next )
2695 {
2696 r__next = r->next;
2697
2698 s1 = ap_table_get( r->notes, "mod_gzip_result" );
2699 s2 = ap_table_get( r->notes, "mod_gzip_input_size" );
2700 s3 = ap_table_get( r->notes, "mod_gzip_output_size" );
2701 s4 = ap_table_get( r->notes, "mod_gzip_compression_ratio" );
2702
2703 while( r__next )
2704 {
2705 if ( s1 ) ap_table_setn( r__next->notes,"mod_gzip_result",ap_pstrdup(r__next->pool,s1));
2706 if ( s2 ) ap_table_setn( r__next->notes,"mod_gzip_input_size",ap_pstrdup(r__next->pool,s2));
2707 if ( s3 ) ap_table_setn( r__next->notes,"mod_gzip_output_size",ap_pstrdup(r__next->pool,s3));
2708 if ( s4 ) ap_table_setn( r__next->notes,"mod_gzip_compression_ratio",ap_pstrdup(r__next->pool,s4));
2709
2710 r__next = r__next->next;
2711 }
2712 }
2713
2714 #endif
2715
2716 #ifdef MOD_GZIP_DEBUG1
2717 #ifdef MOD_GZIP_DEBUG1_SHOW_REQUEST_RECORD2
2718 mod_gzip_show_request_record( r, cn );
2719 #endif
2720 #endif
2721
2722 #ifdef MOD_GZIP_DEBUG1
2723
2724 mod_gzip_printf( "%s: 1 r->connection->client->outcnt = %ld",
2725 cn, r->connection->client->outcnt );
2726 mod_gzip_printf( "%s: 1 r->connection->client->bytes_sent = %ld",
2727 cn, r->connection->client->bytes_sent );
2728 mod_gzip_printf( "%s: 1 Sum of the 2......................= %ld",
2729 cn, r->connection->client->outcnt +
2730 r->connection->client->bytes_sent );
2731 if ( rc == OK )
2732 {
2733 mod_gzip_printf( "%s: Exit > return ( rc = %d OK ) >",cn,(int)rc);
2734 }
2735 else if ( rc == DECLINED )
2736 {
2737 mod_gzip_printf( "%s: Exit > return ( rc = %d DECLINED ) >",cn,(int)rc);
2738 }
2739 else
2740 {
2741 mod_gzip_printf( "%s: Exit > return ( rc = %d HTTP_ERROR ) >",cn,(int)rc);
2742 }
2743
2744 #endif
2745
2746 return rc;
2747 }
2748
2749 int mod_gzip_set_defaults1( mod_gzip_conf *cfg )
2750 {
2751 int i;
2752
2753 cfg->is_on = 0;
2754 cfg->is_on_set = 0;
2755
2756 cfg->keep_workfiles = 0;
2757 cfg->keep_workfiles_set = 0;
2758
2759 cfg->add_header_count = 0;
2760 cfg->add_header_count_set = 0;
2761
2762 cfg->dechunk = 0;
2763 cfg->dechunk_set = 0;
2764
2765 cfg->min_http = 0;
2766 cfg->min_http_set = 0;
2767
2768 cfg->minimum_file_size = 300;
2769 cfg->minimum_file_size_set = 0;
2770
2771 cfg->maximum_file_size = 0;
2772 cfg->maximum_file_size_set = 0;
2773
2774 cfg->maximum_inmem_size = 0;
2775 cfg->maximum_inmem_size_set = 0;
2776
2777 #ifdef WIN32
2778 mod_gzip_strcpy( cfg->temp_dir, "c:\\temp\\" );
2779 #else
2780 mod_gzip_strcpy( cfg->temp_dir, "/tmp/" );
2781 #endif
2782 cfg->temp_dir_set = 0;
2783
2784 cfg->imap_total_entries = 0;
2785 cfg->imap_total_ismime = 0;
2786 cfg->imap_total_isfile = 0;
2787 cfg->imap_total_isuri = 0;
2788 cfg->imap_total_ishandler = 0;
2789 cfg->imap_total_isreqheader = 0;
2790 cfg->imap_total_isrspheader = 0;
2791
2792 for ( i=0; i<MOD_GZIP_IMAP_MAXNAMES; i++ )
2793 {
2794 memset( &(cfg->imap[i]), 0, mod_gzip_imap_size );
2795 }
2796
2797 #ifdef MOD_GZIP_COMMAND_VERSION_USED
2798 memset(
2799 cfg->command_version, 0, MOD_GZIP_COMMAND_VERSION_MAXLEN );
2800 cfg->command_version_set = 0;
2801 #endif
2802
2803 #ifdef MOD_GZIP_CAN_NEGOTIATE
2804 cfg->can_negotiate = 0;
2805 cfg->can_negotiate_set = 0;
2806 #endif
2807
2808 cfg->handle_methods = MOD_GZIP_M_NOT_SET;
2809
2810 strcpy(cfg->suffix,".gz");
2811 cfg->suffix_set = 0;
2812
2813 cfg->send_vary = 1;
2814 cfg->send_vary_set = 0;
2815
2816 cfg->refresh_files = 0;
2817 cfg->refresh_files_set = 0;
2818
2819 return 0;
2820 }
2821
2822 #ifdef REFERENCE
2823 static void *mod_gzip_merge_dconfig(
2824 pool *p,
2825 void *parent_conf,
2826 void *newloc_conf
2827 )
2828 {
2829 mod_gzip_conf *merged_config = (mod_gzip_conf *) ap_pcalloc(p, sizeof(mod_gzip_conf));
2830 mod_gzip_conf *pconf = (mod_gzip_conf *) parent_conf;
2831 mod_gzip_conf *nconf = (mod_gzip_conf *) newloc_conf;
2832
2833 mod_gzip_merge1(
2834 ( pool * ) p,
2835 ( mod_gzip_conf * ) merged_config,
2836 ( mod_gzip_conf * ) pconf,
2837 ( mod_gzip_conf * ) nconf
2838 );
2839
2840 return (void *) merged_config;
2841 }
2842 #endif
2843
2844 int mod_gzip_merge1(
2845 pool *p,
2846 mod_gzip_conf *merged_config,
2847 mod_gzip_conf *pconf,
2848 mod_gzip_conf *nconf )
2849 {
2850 #ifdef MOD_GZIP_DEBUG1
2851 char cn[]="mod_gzip_merge1():::::::";
2852 char ch1 = 0;
2853 #endif
2854
2855 char *p1 = 0;
2856 char *p2 = 0;
2857 int i = 0;
2858 int ii = 0;
2859 int l1 = 0;
2860 int l2 = 0;
2861 int match = 0;
2862
2863 int total = 0;
2864 int total_ismime = 0;
2865 int total_isfile = 0;
2866 int total_isuri = 0;
2867 int total_ishandler = 0;
2868 int total_isreqheader = 0;
2869 int total_isrspheader = 0;
2870
2871 #ifdef MOD_GZIP_DEBUG1
2872 mod_gzip_printf( "%s: ",cn);
2873 #endif
2874
2875 #ifdef MOD_GZIP_DEBUG1
2876
2877 if ( nconf->is_on_set )
2878 {
2879 merged_config->is_on = nconf->is_on;
2880
2881 ch1='!';
2882 }
2883 else
2884 {
2885 merged_config->is_on = pconf->is_on;
2886
2887 ch1='=';
2888 }
2889
2890 mod_gzip_printf( "%s: pconf %c= nconf : merged_config->is_on = %ld", cn, ch1, (long) merged_config->is_on );
2891
2892 #else
2893
2894 merged_config->is_on =
2895 ( nconf->is_on_set) ? nconf->is_on : pconf->is_on;
2896
2897 #endif
2898
2899 #ifdef MOD_GZIP_DEBUG1
2900
2901 if ( pconf->cmode == nconf->cmode )
2902 {
2903 merged_config->cmode = pconf->cmode;
2904
2905 ch1='=';
2906 }
2907 else
2908 {
2909 merged_config->cmode = MOD_GZIP_CONFIG_MODE_COMBO;
2910
2911 ch1='!';
2912 }
2913
2914 mod_gzip_printf( "%s: pconf %c= nconf : merged_config->cmode = %ld", cn, ch1, (long) merged_config->cmode );
2915
2916 #else
2917
2918 merged_config->cmode =
2919 (pconf->cmode == nconf->cmode) ? pconf->cmode : MOD_GZIP_CONFIG_MODE_COMBO;
2920
2921 #endif
2922
2923 merged_config->loc = ap_pstrdup( p, nconf->loc );
2924
2925 #ifdef MOD_GZIP_DEBUG1
2926 mod_gzip_printf( "%s: .............. : merged_config->loc = [%s]", cn, npp(merged_config->loc));
2927 #endif
2928
2929 #ifdef MOD_GZIP_DEBUG1
2930 if ( !nconf->add_header_count_set )
2931 { merged_config->add_header_count = pconf->add_header_count; ch1='='; }
2932 else { merged_config->add_header_count = nconf->add_header_count; ch1='!'; }
2933 mod_gzip_printf( "%s: pconf %c= nconf : merged_config->add_header_count = %ld", cn, ch1, (long) merged_config->add_header_count );
2934 #else
2935 merged_config->add_header_count = ( !nconf->add_header_count_set ) ? pconf->add_header_count : nconf->add_header_count;
2936 #endif
2937
2938 #ifdef MOD_GZIP_DEBUG1
2939 if ( !nconf->keep_workfiles_set )
2940 { merged_config->keep_workfiles = pconf->keep_workfiles; ch1='='; }
2941 else { merged_config->keep_workfiles = nconf->keep_workfiles; ch1='!'; }
2942 mod_gzip_printf( "%s: pconf %c= nconf : merged_config->keep_workfiles = %ld", cn, ch1, (long) merged_config->keep_workfiles );
2943 #else
2944 merged_config->keep_workfiles = ( !nconf->keep_workfiles_set ) ? pconf->keep_workfiles : nconf->keep_workfiles;
2945 #endif
2946
2947 #ifdef MOD_GZIP_CAN_NEGOTIATE
2948 #ifdef MOD_GZIP_DEBUG1
2949 if ( !nconf->can_negotiate_set )
2950 { merged_config->can_negotiate = pconf->can_negotiate; ch1='='; }
2951 else { merged_config->can_negotiate = nconf->can_negotiate; ch1='!'; }
2952 mod_gzip_printf( "%s: pconf %c= nconf : merged_config->can_negotiate = %ld", cn, ch1, (long) merged_config->can_negotiate );
2953 #else
2954 merged_config->can_negotiate = ( !nconf->can_negotiate_set ) ? pconf->can_negotiate : nconf->can_negotiate;
2955 #endif
2956 #endif
2957
2958 #ifdef MOD_GZIP_DEBUG1
2959 if ( !nconf->dechunk_set )
2960 { merged_config->dechunk = pconf->dechunk; ch1='='; }
2961 else { merged_config->dechunk = nconf->dechunk; ch1='!'; }
2962 mod_gzip_printf( "%s: pconf %c= nconf : merged_config->dechunk = %ld", cn, ch1, (long) merged_config->dechunk );
2963 #else
2964 merged_config->dechunk = ( !nconf->dechunk_set ) ? pconf->dechunk : nconf->dechunk;
2965 #endif
2966
2967 #ifdef MOD_GZIP_DEBUG1
2968 if ( !nconf->min_http_set )
2969 { merged_config->min_http = pconf->min_http; ch1='='; }
2970 else { merged_config->min_http = nconf->min_http; ch1='!'; }
2971 mod_gzip_printf( "%s: pconf %c= nconf : merged_config->min_http = %ld", cn, ch1, (long) merged_config->min_http );
2972 #else
2973 merged_config->min_http = ( !nconf->min_http_set ) ? pconf->min_http : nconf->min_http;
2974 #endif
2975
2976 #ifdef MOD_GZIP_DEBUG1
2977 if ( !nconf->minimum_file_size_set )
2978 { merged_config->minimum_file_size = pconf->minimum_file_size; ch1='='; }
2979 else { merged_config->minimum_file_size = nconf->minimum_file_size; ch1='!'; }
2980 mod_gzip_printf( "%s: pconf %c= nconf : merged_config->minimum_file_size = %ld", cn, ch1, (long) merged_config->minimum_file_size );
2981 #else
2982 merged_config->minimum_file_size = ( !nconf->minimum_file_size_set ) ? pconf->minimum_file_size : nconf->minimum_file_size;
2983 #endif
2984
2985 #ifdef MOD_GZIP_DEBUG1
2986 if ( !nconf->maximum_file_size_set )
2987 { merged_config->maximum_file_size = pconf->maximum_file_size; ch1='='; }
2988 else { merged_config->maximum_file_size = nconf->maximum_file_size; ch1='!'; }
2989 mod_gzip_printf( "%s: pconf %c= nconf : merged_config->maximum_file_size = %ld", cn, ch1, (long) merged_config->maximum_file_size );
2990 #else
2991 merged_config->maximum_file_size = ( !nconf->maximum_file_size_set ) ? pconf->maximum_file_size : nconf->maximum_file_size;
2992 #endif
2993
2994 #ifdef MOD_GZIP_DEBUG1
2995 if ( !nconf->maximum_inmem_size_set )
2996 { merged_config->maximum_inmem_size = pconf->maximum_inmem_size; ch1='='; }
2997 else { merged_config->maximum_inmem_size = nconf->maximum_inmem_size; ch1='!'; }
2998 mod_gzip_printf( "%s: pconf %c= nconf : merged_config->maximum_inmem_size = %ld", cn, ch1, (long) merged_config->maximum_inmem_size );
2999 #else
3000 merged_config->maximum_inmem_size = ( !nconf->maximum_inmem_size_set ) ? pconf->maximum_inmem_size : nconf->maximum_inmem_size;
3001 #endif
3002
3003 #ifdef MOD_GZIP_DEBUG1
3004 if ( !nconf->temp_dir_set )
3005 { mod_gzip_strcpy(merged_config->temp_dir,pconf->temp_dir); ch1='='; }
3006 else { mod_gzip_strcpy(merged_config->temp_dir,nconf->temp_dir); ch1='!'; }
3007 mod_gzip_printf( "%s: pconf %c= nconf : merged_config->temp_dir = [%s]", cn, ch1,npp(merged_config->temp_dir));
3008 #else
3009 if ( !nconf->temp_dir_set )
3010 { mod_gzip_strcpy(merged_config->temp_dir,pconf->temp_dir); }
3011 else { mod_gzip_strcpy(merged_config->temp_dir,nconf->temp_dir); }
3012 #endif
3013
3014 #ifdef MOD_GZIP_COMMAND_VERSION_USED
3015 #ifdef MOD_GZIP_DEBUG1
3016 if ( !nconf->command_version_set )
3017 { mod_gzip_strcpy(merged_config->command_version,pconf->command_version); ch1='='; }
3018 else { mod_gzip_strcpy(merged_config->command_version,nconf->command_version); ch1='!'; }
3019 mod_gzip_printf( "%s: pconf %c= nconf : merged_config->command_version = [%s]", cn, ch1,npp(merged_config->command_version));
3020 #else
3021 if ( !nconf->command_version_set )
3022 { mod_gzip_strcpy(merged_config->command_version,pconf->command_version); }
3023 else { mod_gzip_strcpy(merged_config->command_version,nconf->command_version); }
3024 #endif
3025 #endif
3026
3027 total = 0;
3028
3029 /*
3030 * new config overrides old config
3031 */
3032 if(nconf->handle_methods == MOD_GZIP_M_NOT_SET) {
3033 merged_config->handle_methods = pconf->handle_methods;
3034 }
3035 else {
3036 merged_config->handle_methods = nconf->handle_methods;
3037 }
3038
3039 if(!nconf->suffix_set) {
3040 mod_gzip_strcpy(merged_config->suffix,pconf->suffix);
3041 }
3042 else {
3043 mod_gzip_strcpy(merged_config->suffix,nconf->suffix);
3044 merged_config->suffix_set = 1;
3045 }
3046
3047 if(!nconf->send_vary_set) {
3048 merged_config->send_vary = pconf->send_vary;
3049 }
3050 else {
3051 merged_config->send_vary = nconf->send_vary;
3052 merged_config->send_vary_set = 1;
3053 }
3054
3055 if(!nconf->refresh_files_set) {
3056 merged_config->refresh_files = pconf->refresh_files;
3057 }
3058 else {
3059 merged_config->refresh_files = nconf->refresh_files;
3060 merged_config->refresh_files_set = 1;
3061 }
3062
3063 for ( i=0; i<nconf->imap_total_entries; i++ )
3064 {
3065 memcpy(
3066 &(merged_config->imap[i]),
3067 &(nconf->imap[i]),
3068 mod_gzip_imap_size
3069 );
3070
3071 total++;
3072
3073 if ( nconf->imap[i].type == MOD_GZIP_IMAP_ISMIME )
3074 {
3075 total_ismime++;
3076 }
3077 else if ( nconf->imap[i].type == MOD_GZIP_IMAP_ISFILE )
3078 {
3079 total_isfile++;
3080 }
3081 else if ( nconf->imap[i].type == MOD_GZIP_IMAP_ISURI )
3082 {
3083 total_isuri++;
3084 }
3085 else if ( nconf->imap[i].type == MOD_GZIP_IMAP_ISHANDLER )
3086 {
3087 total_ishandler++;
3088 }
3089 else if ( nconf->imap[i].type == MOD_GZIP_IMAP_ISREQHEADER )
3090 {
3091 total_isreqheader++;
3092 }
3093 else if ( nconf->imap[i].type == MOD_GZIP_IMAP_ISRSPHEADER )
3094 {
3095 total_isrspheader++;
3096 }
3097 }
3098
3099 for ( i=0; i<pconf->imap_total_entries; i++ )
3100 {
3101 p1 = pconf->imap[i].name;
3102 l1 = mod_gzip_strlen( p1 );
3103
3104 match = -1;
3105
3106 for ( ii=0; ii<nconf->imap_total_entries; ii++ )
3107 {
3108 p2 = nconf->imap[ii].name;
3109 l2 = nconf->imap[ii].namelen;
3110
3111 if ( l1 == l2 )
3112 {
3113 if ( mod_gzip_strncmp( p1, p2, l1 ) == 0 )
3114 {
3115 match = ii;
3116
3117 break;
3118 }
3119 }
3120 }
3121
3122 if ( match != -1 )
3123 {
3124 }
3125 else
3126 {
3127 if ( total < MOD_GZIP_IMAP_MAXNAMES )
3128 {
3129 memcpy(
3130 &(merged_config->imap[ total ]),
3131 &(pconf->imap[i]),
3132 mod_gzip_imap_size
3133 );
3134
3135 total++;
3136
3137 if ( pconf->imap[i].type == MOD_GZIP_IMAP_ISMIME )
3138 {
3139 total_ismime++;
3140 }
3141 else if ( pconf->imap[i].type == MOD_GZIP_IMAP_ISFILE )
3142 {
3143 total_isfile++;
3144 }
3145 else if ( pconf->imap[i].type == MOD_GZIP_IMAP_ISURI )
3146 {
3147 total_isuri++;
3148 }
3149 else if ( pconf->imap[i].type == MOD_GZIP_IMAP_ISHANDLER )
3150 {
3151 total_ishandler++;
3152 }
3153 else if ( pconf->imap[i].type == MOD_GZIP_IMAP_ISREQHEADER )
3154 {
3155 total_isreqheader++;
3156 }
3157 else if ( pconf->imap[i].type == MOD_GZIP_IMAP_ISRSPHEADER )
3158 {
3159 total_isrspheader++;
3160 }
3161 }
3162 }
3163 }
3164
3165 merged_config->imap_total_entries = total;
3166 merged_config->imap_total_ismime = total_ismime;
3167 merged_config->imap_total_isfile = total_isfile;
3168 merged_config->imap_total_isuri = total_isuri;
3169 merged_config->imap_total_ishandler = total_ishandler;
3170 merged_config->imap_total_isreqheader = total_isreqheader;
3171 merged_config->imap_total_isrspheader = total_isrspheader;
3172
3173 #ifdef MOD_GZIP_DEBUG1
3174 mod_gzip_printf( "%s: pconf += nconf : merged_config->imap_total_entries = %ld", cn, (long) merged_config->imap_total_entries );
3175 mod_gzip_printf( "%s: pconf += nconf : merged_config->imap_total_ismime = %ld", cn, (long) merged_config->imap_total_ismime );
3176 mod_gzip_printf( "%s: pconf += nconf : merged_config->imap_total_isfile = %ld", cn, (long) merged_config->imap_total_isfile );
3177 mod_gzip_printf( "%s: pconf += nconf : merged_config->imap_total_isuri = %ld", cn, (long) merged_config->imap_total_isuri );
3178 mod_gzip_printf( "%s: pconf += nconf : merged_config->imap_total_ishandler = %ld", cn, (long) merged_config->imap_total_ishandler );
3179 mod_gzip_printf( "%s: pconf += nconf : merged_config->imap_total_isreqheader = %ld", cn, (long) merged_config->imap_total_isreqheader );
3180 mod_gzip_printf( "%s: pconf += nconf : merged_config->imap_total_isrspheader = %ld", cn, (long) merged_config->imap_total_isrspheader );
3181 #endif
3182
3183 #ifdef MOD_GZIP_DEBUG1
3184 mod_gzip_printf( "%s: ",cn);
3185 #endif
3186
3187 return 0;
3188 }
3189
3190 static const char *
3191 mod_gzip_set_is_on( cmd_parms *parms, void *cfg, char *arg )
3192 {
3193 mod_gzip_conf *mgc;
3194
3195 #ifdef MOD_GZIP_DEBUG1
3196 server_rec *srv = parms->server;
3197 char cn[]="mod_gzip_set_is_on()";
3198 #endif
3199
3200 #ifdef MOD_GZIP_DEBUG1
3201
3202 mod_gzip_server_now = srv;
3203
3204 mod_gzip_printf( " ");
3205 mod_gzip_printf( "%s: Entry", cn );
3206 mod_gzip_printf( "%s: arg=[%s]", cn, npp(arg) );
3207
3208 #endif
3209
3210 mgc = ( mod_gzip_conf * ) cfg;
3211
3212 #ifdef MOD_GZIP_ALTERNATIVE1
3213
3214 mgc = ( mod_gzip_conf * )
3215 ap_get_module_config(parms->server->module_config, &gzip_module);
3216 #endif
3217
3218 if ( ( arg[0] == 'Y' )||( arg[0] == 'y' ) )
3219 {
3220 mgc->is_on = 1;
3221 }
3222 else
3223 {
3224 mgc->is_on = 0;
3225 }
3226
3227 mgc->is_on_set = 1;
3228
3229 #ifdef MOD_GZIP_DEBUG1
3230 mod_gzip_printf( "%s: mgc->loc = [%s]", cn, npp(mgc->loc));
3231 mod_gzip_printf( "%s: srv->is_virtual = %ld", cn, (long)srv->is_virtual );
3232 mod_gzip_printf( "%s: srv->server_hostname = [%s]", cn, npp(srv->server_hostname));
3233 mod_gzip_printf( "%s: mgc->cmode = %ld", cn, (long) mgc->cmode );
3234 mod_gzip_printf( "%s: mgc->is_on = %ld", cn, (long) mgc->is_on );
3235 mod_gzip_printf( "%s: mgc->is_on_set = %ld", cn, (long) mgc->is_on_set );
3236 #endif
3237
3238 return NULL;
3239 }
3240
3241 static const char *
3242 mod_gzip_set_add_header_count( cmd_parms *parms, void *cfg, char *arg )
3243 {
3244 mod_gzip_conf *mgc;
3245
3246 #ifdef MOD_GZIP_DEBUG1
3247 server_rec *srv = parms->server;
3248 char cn[]="mod_gzip_set_add_header_count()";
3249 #endif
3250
3251 #ifdef MOD_GZIP_DEBUG1
3252 mod_gzip_server_now = srv;
3253 mod_gzip_printf( " ");
3254 mod_gzip_printf( "%s: Entry", cn );
3255 mod_gzip_printf( "%s: arg=[%s]", cn, npp(arg) );
3256 #endif
3257
3258 mgc = ( mod_gzip_conf * ) cfg;
3259
3260 if ( ( arg[0] == 'Y' )||( arg[0] == 'y' ) )
3261 {
3262 mgc->add_header_count = 1;
3263 }
3264 else
3265 {
3266 mgc->add_header_count = 0;
3267 }
3268
3269 mgc->add_header_count_set = 1;
3270
3271 #ifdef MOD_GZIP_DEBUG1
3272 mod_gzip_printf( "%s: mgc->loc = [%s]",cn, npp(mgc->loc));
3273 mod_gzip_printf( "%s: mgc->cmode = %ld", cn, (long) mgc->cmode );
3274 mod_gzip_printf( "%s: srv->is_virtual = %ld", cn, (long)srv->is_virtual );
3275 mod_gzip_printf( "%s: srv->server_hostname = [%s]",cn, npp(srv->server_hostname));
3276 mod_gzip_printf( "%s: mgc->add_header_count = %ld", cn,
3277 (long) mgc->add_header_count );
3278 mod_gzip_printf( "%s: mgc->add_header_count_set = %ld", cn,
3279 (long) mgc->add_header_count_set );
3280 #endif
3281
3282 return NULL;
3283 }
3284
3285 static const char *
3286 mod_gzip_set_keep_workfiles( cmd_parms *parms, void *cfg, char *arg )
3287 {
3288 mod_gzip_conf *mgc;
3289
3290 #ifdef MOD_GZIP_DEBUG1
3291 server_rec *srv = parms->server;
3292 char cn[]="mod_gzip_set_keep_workfiles()";
3293 #endif
3294
3295 #ifdef MOD_GZIP_DEBUG1
3296 mod_gzip_server_now = srv;
3297 mod_gzip_printf( " ");
3298 mod_gzip_printf( "%s: Entry", cn );
3299 mod_gzip_printf( "%s: arg=[%s]", cn, npp(arg) );
3300 #endif
3301
3302 mgc = ( mod_gzip_conf * ) cfg;
3303
3304 if ( ( arg[0] == 'Y' )||( arg[0] == 'y' ) )
3305 {
3306 mgc->keep_workfiles = 1;
3307 }
3308 else
3309 {
3310 mgc->keep_workfiles = 0;
3311 }
3312
3313 mgc->keep_workfiles_set = 1;
3314
3315 #ifdef MOD_GZIP_DEBUG1
3316 mod_gzip_printf( "%s: mgc->loc = [%s]",cn, npp(mgc->loc) );
3317 mod_gzip_printf( "%s: mgc->cmode = %ld", cn, (long) mgc->cmode );
3318 mod_gzip_printf( "%s: srv->is_virtual = %ld", cn, (long)srv->is_virtual );
3319 mod_gzip_printf( "%s: srv->server_hostname = [%s]",cn, npp(srv->server_hostname) );
3320 mod_gzip_printf( "%s: mgc->keep_workfiles = %ld", cn,
3321 (long) mgc->keep_workfiles );
3322 mod_gzip_printf( "%s: mgc->keep_workfiles_set = %ld", cn,
3323 (long) mgc->keep_workfiles_set );
3324 #endif
3325
3326 return NULL;
3327 }
3328
3329 #ifdef MOD_GZIP_CAN_NEGOTIATE
3330 static const char *
3331 mod_gzip_set_can_negotiate( cmd_parms *parms, void *cfg, char *arg )
3332 {
3333 mod_gzip_conf *mgc;
3334
3335 #ifdef MOD_GZIP_DEBUG1
3336 server_rec *srv = parms->server;
3337 char cn[]="mod_gzip_set_can_negotiate()";
3338 #endif
3339
3340 #ifdef MOD_GZIP_DEBUG1
3341 mod_gzip_server_now = srv;
3342 mod_gzip_printf( " ");
3343 mod_gzip_printf( "%s: Entry", cn );
3344 mod_gzip_printf( "%s: arg=[%s]", cn, npp(arg) );
3345 #endif
3346
3347 mgc = ( mod_gzip_conf * ) cfg;
3348
3349 if ( ( arg[0] == 'Y' )||( arg[0] == 'y' ) )
3350 {
3351 mgc->can_negotiate = 1;
3352 }
3353 else
3354 {
3355 mgc->can_negotiate = 0;
3356 }
3357
3358 mgc->can_negotiate_set = 1;
3359
3360 #ifdef MOD_GZIP_DEBUG1
3361 mod_gzip_printf( "%s: mgc->loc = [%s]",cn, npp(mgc->loc) );
3362 mod_gzip_printf( "%s: mgc->cmode = %ld", cn, (long) mgc->cmode );
3363 mod_gzip_printf( "%s: srv->is_virtual = %ld", cn, (long)srv->is_virtual );
3364 mod_gzip_printf( "%s: srv->server_hostname = [%s]",cn, npp(srv->server_hostname) );
3365 mod_gzip_printf( "%s: mgc->can_negotiate = %ld", cn,
3366 (long) mgc->can_negotiate );
3367 mod_gzip_printf( "%s: mgc->can_negotiate_set = %ld", cn,
3368 (long) mgc->can_negotiate_set );
3369 #endif
3370
3371 return NULL;
3372 }
3373 #endif
3374
3375 static const char *
3376 mod_gzip_set_dechunk( cmd_parms *parms, void *cfg, char *arg )
3377 {
3378 mod_gzip_conf *mgc;
3379
3380 #ifdef MOD_GZIP_DEBUG1
3381 server_rec *srv = parms->server;
3382 char cn[]="mod_gzip_set_dechunk()";
3383 #endif
3384
3385 #ifdef MOD_GZIP_DEBUG1
3386 mod_gzip_server_now = srv;
3387 mod_gzip_printf( " ");
3388 mod_gzip_printf( "%s: Entry", cn );
3389 mod_gzip_printf( "%s: arg=[%s]", cn, npp(arg) );
3390 #endif
3391
3392 mgc = ( mod_gzip_conf * ) cfg;
3393
3394 if ( ( arg[0] == 'Y' )||( arg[0] == 'y' ) )
3395 {
3396 mgc->dechunk = 1;
3397 }
3398 else
3399 {
3400 mgc->dechunk = 0;
3401 }
3402
3403 mgc->dechunk_set = 1;
3404
3405 #ifdef MOD_GZIP_DEBUG1
3406 mod_gzip_printf( "%s: mgc->loc = [%s]",cn, npp(mgc->loc) );
3407 mod_gzip_printf( "%s: mgc->cmode = %ld", cn, (long) mgc->cmode );
3408 mod_gzip_printf( "%s: srv->is_virtual = %ld", cn, (long)srv->is_virtual );
3409 mod_gzip_printf( "%s: srv->server_hostname = [%s]",cn, npp(srv->server_hostname) );
3410 mod_gzip_printf( "%s: mgc->dechunk = %ld", cn,
3411 (long) mgc->dechunk );
3412 mod_gzip_printf( "%s: mgc->dechunk_set = %ld", cn,
3413 (long) mgc->dechunk_set );
3414 #endif
3415
3416 return NULL;
3417 }
3418
3419 static const char *
3420 mod_gzip_set_min_http( cmd_parms *parms, void *cfg, char *arg )
3421 {
3422 mod_gzip_conf *mgc;
3423
3424 #ifdef MOD_GZIP_DEBUG1
3425 server_rec *srv = parms->server;
3426 char cn[]="mod_gzip_set_min_http()";
3427 #endif
3428
3429 #ifdef MOD_GZIP_DEBUG1
3430 mod_gzip_server_now = srv;
3431 mod_gzip_printf( " ");
3432 mod_gzip_printf( "%s: Entry", cn );
3433 mod_gzip_printf( "%s: arg=[%s]", cn, npp(arg) );
3434 #endif
3435
3436 mgc = ( mod_gzip_conf * ) cfg;
3437
3438 mgc->min_http = (int) atoi( arg );
3439 mgc->min_http_set = 1;
3440
3441 #ifdef MOD_GZIP_DEBUG1
3442 mod_gzip_printf( "%s: mgc->loc = [%s]",cn, npp(mgc->loc));
3443 mod_gzip_printf( "%s: mgc->cmode = %ld", cn, (long) mgc->cmode );
3444 mod_gzip_printf( "%s: srv->is_virtual = %ld", cn, (long)srv->is_virtual );
3445 mod_gzip_printf( "%s: srv->server_hostname = [%s]",cn, npp(srv->server_hostname));
3446 mod_gzip_printf( "%s: mgc->min_http = %ld", cn,
3447 (long) mgc->min_http );
3448 mod_gzip_printf( "%s: mgc->min_http = %ld", cn,
3449 (long) mgc->min_http_set );
3450 #endif
3451
3452 return NULL;
3453 }
3454
3455 static const char *
3456 mod_gzip_set_minimum_file_size( cmd_parms *parms, void *cfg, char *arg )
3457 {
3458 mod_gzip_conf *mgc;
3459
3460 #ifdef MOD_GZIP_DEBUG1
3461 server_rec *srv = parms->server;
3462 char cn[]="mod_gzip_set_minimum_file_size()";
3463 #endif
3464
3465 #ifdef MOD_GZIP_DEBUG1
3466 mod_gzip_server_now = srv;
3467 mod_gzip_printf( " ");
3468 mod_gzip_printf( "%s: Entry", cn );
3469 mod_gzip_printf( "%s: arg=[%s]", cn, npp(arg));
3470 #endif
3471
3472 mgc = ( mod_gzip_conf * ) cfg;
3473
3474 mgc->minimum_file_size = (long) atol( arg );
3475 mgc->minimum_file_size_set = 1;
3476
3477 if ( mgc->minimum_file_size < 300 )
3478 {
3479 mgc->minimum_file_size = 300;
3480 }
3481
3482 #ifdef MOD_GZIP_DEBUG1
3483 mod_gzip_printf( "%s: mgc->loc = [%s]",cn, npp(mgc->loc));
3484 mod_gzip_printf( "%s: mgc->cmode = %ld", cn, (long) mgc->cmode );
3485 mod_gzip_printf( "%s: srv->is_virtual = %ld", cn, (long)srv->is_virtual );
3486 mod_gzip_printf( "%s: srv->server_hostname = [%s]",cn, npp(srv->server_hostname));
3487 mod_gzip_printf( "%s: mgc->minimum_file_size = %ld", cn,
3488 (long) mgc->minimum_file_size );
3489 mod_gzip_printf( "%s: mgc->minimum_file_size = %ld", cn,
3490 (long) mgc->minimum_file_size_set );
3491 #endif
3492
3493 return NULL;
3494 }
3495
3496 static const char *
3497 mod_gzip_set_maximum_file_size( cmd_parms *parms, void *cfg, char *arg )
3498 {
3499 mod_gzip_conf *mgc;
3500
3501 #ifdef MOD_GZIP_DEBUG1
3502 server_rec *srv = parms->server;
3503 char cn[]="mod_gzip_set_maximum_file_size()";
3504 #endif
3505
3506 #ifdef MOD_GZIP_DEBUG1
3507 mod_gzip_server_now = srv;
3508 mod_gzip_printf( " ");
3509 mod_gzip_printf( "%s: Entry", cn );
3510 mod_gzip_printf( "%s: arg=[%s]", cn, npp(arg));
3511 #endif
3512
3513 mgc = ( mod_gzip_conf * ) cfg;
3514
3515 mgc->maximum_file_size = (long) atol( arg );
3516 mgc->maximum_file_size_set = 1;
3517
3518 #ifdef MOD_GZIP_DEBUG1
3519 mod_gzip_printf( "%s: mgc->loc = [%s]",cn, npp(mgc->loc));
3520 mod_gzip_printf( "%s: mgc->cmode = %ld", cn, (long) mgc->cmode );
3521 mod_gzip_printf( "%s: srv->is_virtual = %ld", cn, (long)srv->is_virtual );
3522 mod_gzip_printf( "%s: srv->server_hostname = [%s]",cn, npp(srv->server_hostname));
3523 mod_gzip_printf( "%s: mgc->maximum_file_size = %ld", cn,
3524 (long) mgc->maximum_file_size );
3525 mod_gzip_printf( "%s: mgc->maximum_file_size = %ld", cn,
3526 (long) mgc->maximum_file_size_set );
3527 #endif
3528
3529 return NULL;
3530 }
3531
3532 static const char *
3533 mod_gzip_set_maximum_inmem_size( cmd_parms *parms, void *cfg, char *arg )
3534 {
3535 mod_gzip_conf *mgc;
3536
3537 #ifdef MOD_GZIP_DEBUG1
3538 server_rec *srv = parms->server;
3539 char cn[]="mod_gzip_set_maximum_inmem_size()";
3540 #endif
3541
3542 #ifdef MOD_GZIP_DEBUG1
3543 mod_gzip_server_now = srv;
3544 mod_gzip_printf( " ");
3545 mod_gzip_printf( "%s: Entry", cn );
3546 mod_gzip_printf( "%s: arg=[%s]", cn, npp(arg) );
3547 #endif
3548
3549 mgc = ( mod_gzip_conf * ) cfg;
3550
3551 mgc->maximum_inmem_size = (long) atol(arg);
3552 mgc->maximum_inmem_size_set = 1;
3553
3554 #ifdef MOD_GZIP_DEBUG1
3555 mod_gzip_printf( "%s: mgc->loc = [%s]",cn, npp(mgc->loc));
3556 mod_gzip_printf( "%s: mgc->cmode = %ld", cn, (long) mgc->cmode );
3557 mod_gzip_printf( "%s: srv->is_virtual = %ld", cn, (long)srv->is_virtual );
3558 mod_gzip_printf( "%s: srv->server_hostname = [%s]",cn, npp(srv->server_hostname));
3559 mod_gzip_printf( "%s: mgc->maximum_inmem_size = %ld", cn,
3560 (long) mgc->maximum_inmem_size );
3561 mod_gzip_printf( "%s: mgc->maximum_inmem_size = %ld", cn,
3562 (long) mgc->maximum_inmem_size_set );
3563 #endif
3564
3565 return NULL;
3566 }
3567
3568 static const char *
3569 mod_gzip_set_temp_dir( cmd_parms *parms, void *cfg, char *arg )
3570 {
3571 mod_gzip_conf *mgc;
3572
3573 #ifdef MOD_GZIP_DEBUG1
3574 server_rec *srv = parms->server;
3575 char cn[]="mod_gzip_set_temp_dir()";
3576 #endif
3577
3578 int arglen = 0;
3579 int rc = 0;
3580
3581 struct stat sbuf;
3582
3583 #ifdef WIN32
3584 char dirsep[]="\\";
3585 #else
3586 char dirsep[]="/";
3587 #endif
3588
3589 #ifdef MOD_GZIP_DEBUG1
3590 mod_gzip_server_now = srv;
3591 mod_gzip_printf( " ");
3592 mod_gzip_printf( "%s: Entry", cn );
3593 #endif
3594
3595 if ( !arg )
3596 {
3597 #ifdef MOD_GZIP_DEBUG1
3598 mod_gzip_printf( "%s: ERROR: 'arg' is NULL...", cn );
3599 mod_gzip_printf( "%s: ERROR: No valid directory supplied.", cn );
3600 #endif
3601
3602 return "mod_gzip_temp_dir: ERROR: No valid directory supplied.";
3603 }
3604
3605 #ifdef MOD_GZIP_DEBUG1
3606 mod_gzip_printf( "%s: arg=[%s]", cn, npp(arg) );
3607 #endif
3608
3609 mgc = ( mod_gzip_conf * ) cfg;
3610
3611 arglen = mod_gzip_strlen( arg );
3612
3613 if ( arglen < 256 )
3614 {
3615 mod_gzip_strcpy( mgc->temp_dir, arg );
3616 mgc->temp_dir_set = 1;
3617
3618 if ( arglen > 0 )
3619 {
3620 if (( arglen == 1 ) && ( *arg == 32 ))
3621 {
3622 #ifdef MOD_GZIP_DEBUG1
3623 mod_gzip_printf( "%s: Special ONE SPACE pickup seen.", cn );
3624 mod_gzip_printf( "%s: temp_dir set to NOTHING.", cn );
3625 #endif
3626
3627 mod_gzip_strcpy( mgc->temp_dir, "" );
3628 }
3629 else
3630 {
3631 if ( ( *(mgc->temp_dir+(arglen-1)) != '\\' ) &&
3632 ( *(mgc->temp_dir+(arglen-1)) != '/' ) )
3633 {
3634 mod_gzip_strcat( mgc->temp_dir, dirsep );
3635 }
3636
3637 rc = stat( mgc->temp_dir, &sbuf );
3638
3639 if ( rc )
3640 {
3641 #ifdef MOD_GZIP_DEBUG1
3642 mod_gzip_printf( "%s: .... stat() call FAILED",cn);
3643 mod_gzip_printf( "%s: Directory name is not valid.",cn);
3644 #endif
3645
3646 return "mod_gzip_temp_dir: ERROR: Directory does not exist.";
3647 }
3648 else
3649 {
3650 #ifdef MOD_GZIP_DEBUG1
3651 mod_gzip_printf( "%s: .... stat() call SUCCEEDED",cn);
3652 mod_gzip_printf( "%s: Directory name appears to be valid.",cn);
3653 #endif
3654 }
3655 }
3656 }
3657
3658 #ifdef MOD_GZIP_DEBUG1
3659 mod_gzip_printf( "%s: mgc->loc = [%s]", cn, npp(mgc->loc));
3660 mod_gzip_printf( "%s: srv->is_virtual = %ld", cn, (long)srv->is_virtual );
3661 mod_gzip_printf( "%s: srv->server_hostname = [%s]", cn, npp(srv->server_hostname));
3662 mod_gzip_printf( "%s: mgc->cmode = %ld", cn, (long) mgc->cmode);
3663 mod_gzip_printf( "%s: mgc->temp_dir = [%s]", cn, npp(mgc->temp_dir));
3664 mod_gzip_printf( "%s: mgc->temp_dir_set = %d", cn, mgc->temp_dir_set);
3665 #endif
3666
3667 return NULL;
3668 }
3669 else
3670 {
3671 return "mod_gzip_temp_dir pathname must be less than 256 characters.";
3672 }
3673 }
3674
3675 static const char *mod_gzip_handle_methods(cmd_parms *parms,void *cfg,char *arg1,char *arg2) {
3676 mod_gzip_conf *mgc = (mod_gzip_conf *)cfg;
3677 int set[2] = { 0, 0 };
3678
3679 if(arg1 && arg2) {
3680 if(strcasecmp(arg1,"GET") == 0) {
3681 set[0] = 1;
3682 }
3683 else if(strcasecmp(arg1,"POST") == 0) {
3684 set[1] = 1;
3685 }
3686
3687 if(strcasecmp(arg2,"GET") == 0) {
3688 if(set[0]) {
3689 return "mod_gzip_handle_methods: duplicate method name!";
3690 }
3691
3692 set[0] = 1;
3693 }
3694 else if(strcasecmp(arg2,"POST") == 0) {
3695 if(set[1]) {
3696 return "mod_gzip_handle_methods: duplicate method name!";
3697 }
3698
3699 set[1] = 1;
3700 }
3701
3702 if(set[0] && set[1]) {
3703 mgc->handle_methods = MOD_GZIP_M_BOTH;
3704 return NULL;
3705 }
3706 else {
3707 return "mod_gzip_handle_methods: can only handle GET or POST!";
3708 }
3709 }
3710 else if(arg1) {
3711 if(strcasecmp(arg1,"GET") == 0) {
3712 mgc->handle_methods = M_GET;
3713 }
3714 else if(strcmp(arg1,"POST") == 0) {
3715 mgc->handle_methods = M_POST;
3716 }
3717 else {
3718 return "mod_gzip_handle_methods: can only handle GET or POST!";
3719 }
3720
3721 return NULL;
3722 }
3723
3724 return "mod_gzip_handle_methods: Argument needed!";
3725 }
3726
3727 static const char *mod_gzip_static_suffix(cmd_parms *parms,void *cfg,char *arg1) {
3728 mod_gzip_conf *mgc = (mod_gzip_conf *)cfg;
3729 size_t len;
3730
3731 if(arg1) {
3732 len = strlen(arg1);
3733 if(len > MOD_GZIP_MAX_SUFFIX_LEN) {
3734 return "mod_gzip_static_suffix: suffix to long!";
3735 }
3736
3737 mod_gzip_strcpy(mgc->suffix,arg1);
3738 mgc->suffix_set = 1;
3739 return NULL;
3740 }
3741
3742 return "mod_gzip_static_suffix: Argument needed!";
3743 }
3744
3745 static const char *mod_gzip_send_vary(cmd_parms *parms,void *cfg,char *arg1) {
3746 mod_gzip_conf *mgc = (mod_gzip_conf *)cfg;
3747
3748 if(arg1) {
3749 mgc->send_vary_set = 1;
3750
3751 if(strcasecmp(arg1,"on") == 0) {
3752 mgc->send_vary = 1;
3753 }
3754 else {
3755 mgc->send_vary = 0;
3756 }
3757
3758 return NULL;
3759 }
3760
3761 return "mod_gzip_send_vary: Argument needed!";
3762 }
3763
3764 static const char *mod_gzip_update_static(cmd_parms *parms,void *cfg,char *arg) {
3765 mod_gzip_conf *mgc = (mod_gzip_conf *)cfg;
3766
3767 if(arg) {
3768 if(strcasecmp(arg,"yes") == 0) {
3769 mgc->refresh_files = 1;
3770 mgc->refresh_files_set = 1;
3771
3772 return NULL;
3773 }
3774 else if(strcasecmp(arg,"no") == 0) {
3775 mgc->refresh_files = 0;
3776 mgc->refresh_files_set = 1;
3777
3778 return NULL;
3779 }
3780 }
3781
3782 return "mod_gzip_update_static: usage: mod_gzip_update_static yes|no";
3783 }
3784
3785 #ifdef MOD_GZIP_COMMAND_VERSION_USED
3786 static const char *
3787 mod_gzip_set_command_version( cmd_parms *parms, void *cfg, char *arg )
3788 {
3789 mod_gzip_conf *mgc;
3790
3791 #ifdef MOD_GZIP_DEBUG1
3792 server_rec *srv = parms->server;
3793 char cn[]="mod_gzip_set_command_version()";
3794 #endif
3795
3796 int arglen = 0;
3797
3798 #ifdef MOD_GZIP_DEBUG1
3799 mod_gzip_server_now = srv;
3800 mod_gzip_printf( " ");
3801 mod_gzip_printf( "%s: Entry", cn );
3802 #endif
3803
3804 if ( !arg )
3805 {
3806 #ifdef MOD_GZIP_DEBUG1
3807 mod_gzip_printf( "%s: ERROR: 'arg' is NULL...", cn );
3808 mod_gzip_printf( "%s: ERROR: No valid string supplied.", cn );
3809 #endif
3810
3811 return "mod_gzip_command_version: ERROR: No valid string supplied.";
3812 }
3813
3814 #ifdef MOD_GZIP_DEBUG1
3815 mod_gzip_printf( "%s: arg=[%s]", cn, npp(arg) );
3816 #endif
3817
3818 mgc = ( mod_gzip_conf * ) cfg;
3819
3820 arglen = mod_gzip_strlen( arg );
3821
3822 if ( arglen < MOD_GZIP_COMMAND_VERSION_MAXLEN )
3823 {
3824 mod_gzip_strcpy( mgc->command_version, arg );
3825 mgc->command_version_set = 1;
3826
3827 #ifdef MOD_GZIP_DEBUG1
3828 mod_gzip_printf( "%s: mgc->loc = [%s]", cn, npp(mgc->loc));
3829 mod_gzip_printf( "%s: srv->is_virtual = %ld", cn, (long)srv->is_virtual );
3830 mod_gzip_printf( "%s: srv->server_hostname = [%s]", cn, npp(srv->server_hostname));
3831 mod_gzip_printf( "%s: mgc->cmode = %ld", cn, (long) mgc->cmode);
3832 mod_gzip_printf( "%s: mgc->command_version = [%s]", cn, npp(mgc->command_version));
3833 mod_gzip_printf( "%s: mgc->command_version_set = %d", cn, mgc->command_version_set);
3834 #endif
3835
3836 return NULL;
3837 }
3838 else
3839 {
3840 return "mod_gzip_command_version string must be less than 128 characters.";
3841 }
3842 }
3843 #endif
3844
3845 static const char *
3846 mod_gzip_imap_add_item(
3847 cmd_parms *parms,
3848 mod_gzip_conf *mgc,
3849 char *a1,
3850 char *a2,
3851 int flag1
3852 )
3853 {
3854 int x;
3855 char *p1;
3856 int ignorecase=0;
3857
3858 int this_include=flag1;
3859 int this_type=0;
3860 int this_action=0;
3861 int this_direction=0;
3862 unsigned this_port=0;
3863 int this_len1=0;
3864 regex_t *this_pregex=NULL;
3865
3866 char *regex;
3867
3868 /* Diagnostic only
3869 #define MOD_GZIP_TEST_REGEX1
3870 */
3871 #ifdef MOD_GZIP_TEST_REGEX1
3872 char string[129];
3873 int regex_error;
3874 #endif
3875
3876 #ifdef MOD_GZIP_DEBUG1
3877 char cn[]="mod_gzip_imap_add_item()";
3878 #endif
3879
3880 #ifdef MOD_GZIP_DEBUG1
3881
3882 mod_gzip_printf( "%s: Entry", cn );
3883 mod_gzip_printf( "%s: 1 a1=[%s]", cn, npp(a1));
3884 mod_gzip_printf( "%s: 1 a2=[%s]", cn, npp(a2));
3885
3886 mod_gzip_printf( "%s: mgc->imap_total_entries = %d",
3887 cn, mgc->imap_total_entries );
3888 mod_gzip_printf( "%s: mgc->imap_total_ismime = %d",
3889 cn, mgc->imap_total_ismime );
3890 mod_gzip_printf( "%s: mgc->imap_total_isfile = %d",
3891 cn, mgc->imap_total_isfile );
3892 mod_gzip_printf( "%s: mgc->imap_total_isuri = %d",
3893 cn, mgc->imap_total_isuri );
3894 mod_gzip_printf( "%s: mgc->imap_total_ishandler = %d",
3895 cn, mgc->imap_total_ishandler );
3896 mod_gzip_printf( "%s: mgc->imap_total_isreqheader = %d",
3897 cn, mgc->imap_total_isreqheader );
3898 mod_gzip_printf( "%s: mgc->imap_total_isrspheader = %d",
3899 cn, mgc->imap_total_isrspheader );
3900
3901 if ( flag1 == 1 )
3902 {
3903 mod_gzip_printf( "%s: flag1 = %d = INCLUDE", cn, flag1 );
3904 }
3905 else if ( flag1 == 0 )
3906 {
3907 mod_gzip_printf( "%s: flag1 = %d = EXCLUDE", cn, flag1 );
3908 }
3909 else
3910 {
3911 mod_gzip_printf( "%s: flag1 = %d = ??? Unknown value", cn, flag1 );
3912 }
3913
3914 #endif
3915
3916 this_type = MOD_GZIP_IMAP_ISNONE;
3917
3918 if ( mod_gzip_strnicmp( a1, "mime", 4 ) == 0 )
3919 {
3920 this_type = MOD_GZIP_IMAP_ISMIME;
3921
3922 #ifdef MOD_GZIP_DEBUG1
3923 mod_gzip_printf( "%s: this_type = MOD_GZIP_IMAP_ISMIME", cn);
3924 #endif
3925 }
3926 else if ( mod_gzip_strnicmp( a1, "file", 4 ) == 0 )
3927 {
3928 this_type = MOD_GZIP_IMAP_ISFILE;
3929
3930 #ifdef MOD_GZIP_DEBUG1
3931 mod_gzip_printf( "%s: this_type = MOD_GZIP_IMAP_ISFILE",cn);
3932 #endif
3933 }
3934 else if ( mod_gzip_strnicmp( a1, "ur", 2 ) == 0 )
3935 {
3936 /* Allow user to specify EITHER 'uri' or 'url' for this 'type' */
3937
3938 this_type = MOD_GZIP_IMAP_ISURI;
3939
3940 #ifdef MOD_GZIP_DEBUG1
3941 mod_gzip_printf( "%s: this_type = MOD_GZIP_IMAP_ISURI",cn);
3942 #endif
3943 }
3944 else if ( mod_gzip_strnicmp( a1, "hand", 4 ) == 0 )
3945 {
3946 this_type = MOD_GZIP_IMAP_ISHANDLER;
3947
3948 #ifdef MOD_GZIP_DEBUG1
3949 mod_gzip_printf( "%s: this_type = MOD_GZIP_IMAP_ISHANDLER",cn);
3950 #endif
3951 }
3952 else if ( mod_gzip_strnicmp( a1, "reqh", 4 ) == 0 )
3953 {
3954 this_type = MOD_GZIP_IMAP_ISREQHEADER;
3955 this_direction = MOD_GZIP_REQUEST;
3956
3957 #ifdef MOD_GZIP_DEBUG1
3958 mod_gzip_printf( "%s: this_type = MOD_GZIP_IMAP_ISREQHEADER",cn);
3959 #endif
3960 }
3961 else if ( mod_gzip_strnicmp( a1, "rsph", 4 ) == 0 )
3962 {
3963 this_type = MOD_GZIP_IMAP_ISRSPHEADER;
3964 this_direction = MOD_GZIP_RESPONSE;
3965
3966 #ifdef MOD_GZIP_DEBUG1
3967 mod_gzip_printf( "%s: this_type = MOD_GZIP_IMAP_ISRSPHEADER",cn);
3968 #endif
3969 }
3970
3971 if ( this_type == MOD_GZIP_IMAP_ISNONE )
3972 {
3973 #ifdef MOD_GZIP_DEBUG1
3974 mod_gzip_printf( "%s: this_type = ?? UNKNOWN ??",cn);
3975 mod_gzip_printf( "%s: Exit > return( ERRORSTRING ) >",cn);
3976 #endif
3977
3978 return "mod_gzip: ERROR: Valid item types are mime,file,uri,handler,reqheader or rspheader";
3979 }
3980
3981 p1 = a2;
3982
3983 if ( ( this_type == MOD_GZIP_IMAP_ISREQHEADER ) ||
3984 ( this_type == MOD_GZIP_IMAP_ISRSPHEADER ) )
3985 {
3986 while((*p1!=0)&&(*p1!=':')) { p1++; this_len1++; }
3987
3988 if (*p1==':')
3989 {
3990 if ( this_len1 < 1 )
3991 {
3992 return "mod_gzip: ERROR: Missing HTTP field name.";
3993 }
3994
3995 p1++;
3996 }
3997 else
3998 {
3999 return "mod_gzip: ERROR: Missing HTTP field name. No colon found.";
4000 }
4001
4002 while((*p1!=0)&&(*p1<33)) p1++;
4003 }
4004
4005 regex = p1;
4006
4007 #ifdef MOD_GZIP_DEBUG1
4008 mod_gzip_printf( "%s: regex = [%s]", cn, npp(regex) );
4009 #endif
4010
4011 if ( !*regex )
4012 {
4013 return "mod_gzip: ERROR: Missing regular expression string.";
4014 }
4015
4016 ignorecase = 1;
4017
4018 #ifdef MOD_GZIP_DEBUG1
4019 mod_gzip_printf( "%s: ignorecase = %d",cn,ignorecase);
4020 mod_gzip_printf( "%s: Call ap_pregcomp(%s)...",cn,npp(regex));
4021 #endif
4022
4023 this_pregex =
4024 ap_pregcomp(parms->pool, regex,
4025 (REG_EXTENDED | REG_NOSUB
4026 | (ignorecase ? REG_ICASE : 0)));
4027
4028 if ( this_pregex == NULL )
4029 {
4030 #ifdef MOD_GZIP_DEBUG1
4031 mod_gzip_printf( "%s: .... ap_pregcomp(%s) FAILED...",cn,npp(regex));
4032 mod_gzip_printf( "%s: regex 'pre-compile' FAILED...", cn );
4033 mod_gzip_printf( "%s: Exit > return( ERRORSTRING ) >",cn);
4034 #endif
4035
4036 return "mod_gzip: ERROR: Regular expression compile failed.";
4037 }
4038
4039 #ifdef MOD_GZIP_DEBUG1
4040 mod_gzip_printf( "%s: .... ap_pregcomp(%s) SUCCEEDED...",cn,npp(regex));
4041 mod_gzip_printf( "%s: regex 'pre-compiled' OK", cn );
4042 #endif
4043
4044 #ifdef MOD_GZIP_TEST_REGEX1
4045
4046 if ( ( this_type == MOD_GZIP_IMAP_ISREQHEADER ) ||
4047 ( this_type == MOD_GZIP_IMAP_ISRSPHEADER ) )
4048 {
4049 mod_gzip_strcpy(
4050 string,
4051 "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt; TUCOWS)"
4052 );
4053
4054 #ifdef MOD_GZIP_DEBUG1
4055 mod_gzip_printf( "%s: Call ap_regexec( regex=[%s], string=[%s] )",
4056 cn, npp(regex), npp(string) );
4057 #endif
4058
4059 regex_error = ap_regexec(this_pregex, string, 0, (regmatch_t *)NULL,0);
4060
4061 #ifdef MOD_GZIP_DEBUG1
4062 if ( regex_error != 0 )
4063 mod_gzip_printf( "%s: regex_error = %d = NO MATCH!", cn, regex_error );
4064 else
4065 mod_gzip_printf( "%s: regex_error = %d = MATCH!", cn, regex_error );
4066 #endif
4067 }
4068
4069 #endif /* MOD_GZIP_TEST_REGEX1 */
4070
4071 this_action = MOD_GZIP_IMAP_STATIC1;
4072
4073 #ifdef FUTURE_USE
4074
4075 if ( ( this_action != MOD_GZIP_IMAP_DYNAMIC1 ) &&
4076 ( this_action != MOD_GZIP_IMAP_DYNAMIC2 ) &&
4077 ( this_action != MOD_GZIP_IMAP_STATIC1 ) )
4078 {
4079 #ifdef MOD_GZIP_DEBUG1
4080 mod_gzip_printf( "%s: this_action = %d = MOD_GZIP_IMAP_??? Unknown action",cn,this_action);
4081 mod_gzip_printf( "%s: return( mod_gzip: ERROR: Unrecognized item 'action'",cn);
4082 #endif
4083
4084 return( "mod_gzip: ERROR: Unrecognized item 'action'" );
4085 }
4086
4087 #endif
4088
4089 if ( mgc->imap_total_entries < MOD_GZIP_IMAP_MAXNAMES )
4090 {
4091 if ( mod_gzip_strlen( a2 ) < MOD_GZIP_IMAP_MAXNAMELEN )
4092 {
4093 x = mgc->imap_total_entries;
4094
4095 p1 = a2;
4096
4097 mod_gzip_strcpy( mgc->imap[x].name, p1 );
4098
4099 mgc->imap[x].namelen = mod_gzip_strlen( mgc->imap[x].name );
4100
4101 mgc->imap[x].include = this_include;
4102 mgc->imap[x].type = this_type;
4103 mgc->imap[x].action = this_action;
4104 mgc->imap[x].direction = this_direction;
4105 mgc->imap[x].port = this_port;
4106 mgc->imap[x].len1 = this_len1;
4107 mgc->imap[x].pregex = this_pregex;
4108
4109 mgc->imap_total_entries++;
4110
4111 if ( this_type == MOD_GZIP_IMAP_ISMIME )
4112 {
4113 mgc->imap_total_ismime++;
4114 }
4115 else if ( this_type == MOD_GZIP_IMAP_ISFILE )
4116 {
4117 mgc->imap_total_isfile++;
4118 }
4119 else if ( this_type == MOD_GZIP_IMAP_ISURI )
4120 {
4121 mgc->imap_total_isuri++;
4122 }
4123 else if ( this_type == MOD_GZIP_IMAP_ISHANDLER )
4124 {
4125 mgc->imap_total_ishandler++;
4126 }
4127 else if ( this_type == MOD_GZIP_IMAP_ISREQHEADER )
4128 {
4129 mgc->imap_total_isreqheader++;
4130 }
4131 else if ( this_type == MOD_GZIP_IMAP_ISRSPHEADER )
4132 {
4133 mgc->imap_total_isrspheader++;
4134 }
4135 }
4136 else
4137 {
4138 #ifdef MOD_GZIP_DEBUG1
4139 mod_gzip_printf( "%s: return( mod_gzip: ERROR: Item name is too long",cn);
4140 #endif
4141
4142 return( "mod_gzip: ERROR: Item name is too long" );
4143 }
4144 }
4145 else
4146 {
4147 #ifdef MOD_GZIP_DEBUG1
4148 mod_gzip_printf( "%s: return( mod_gzip: ERROR: Item index is full",cn);
4149 #endif
4150
4151 return( "mod_gzip: ERROR: Item index is full" );
4152 }
4153
4154 #ifdef MOD_GZIP_DEBUG1
4155
4156 mod_gzip_printf( "%s: mgc->imap_total_entries = %d",
4157 cn, mgc->imap_total_entries );
4158 mod_gzip_printf( "%s: mgc->imap_total_ismime = %d",
4159 cn, mgc->imap_total_ismime );
4160 mod_gzip_printf( "%s: mgc->imap_total_isfile = %d",
4161 cn, mgc->imap_total_isfile );
4162 mod_gzip_printf( "%s: mgc->imap_total_isuri = %d",
4163 cn, mgc->imap_total_isuri );
4164 mod_gzip_printf( "%s: mgc->imap_total_ishandler = %d",
4165 cn, mgc->imap_total_ishandler );
4166 mod_gzip_printf( "%s: mgc->imap_total_isreqheader = %d",
4167 cn, mgc->imap_total_isreqheader );
4168 mod_gzip_printf( "%s: mgc->imap_total_isrspheader = %d",
4169 cn, mgc->imap_total_isrspheader );
4170
4171 mod_gzip_printf( "%s: Exit > return( NULL ) >",cn);
4172
4173 #endif
4174
4175 return NULL;
4176 }
4177
4178 static const char *
4179 mod_gzip_set_item_include( cmd_parms *parms, void *cfg, char *a1, char *a2 )
4180 {
4181 mod_gzip_conf *mgc;
4182 char *arg;
4183
4184 #ifdef MOD_GZIP_DEBUG1
4185 server_rec *srv = parms->server;
4186 char cn[]="mod_gzip_set_item_include()";
4187 #endif
4188
4189 #ifdef MOD_GZIP_DEBUG1
4190 mod_gzip_server_now = srv;
4191 mod_gzip_printf( " ");
4192 mod_gzip_printf( "%s: Entry", cn );
4193 mod_gzip_printf( "%s: a1=[%s]", cn, npp(a1) );
4194 mod_gzip_printf( "%s: a2=[%s]", cn, npp(a2) );
4195 #endif
4196
4197 arg = a1;
4198
4199 mgc = ( mod_gzip_conf * ) cfg;
4200
4201 #ifdef MOD_GZIP_DEBUG1
4202 mod_gzip_printf( "%s: mgc->loc = [%s]", cn, npp(mgc->loc));
4203 mod_gzip_printf( "%s: srv->is_virtual = %ld", cn, (long)srv->is_virtual );
4204 mod_gzip_printf( "%s: srv->server_hostname = [%s]", cn, npp(srv->server_hostname));
4205 mod_gzip_printf( "%s: mgc->cmode = %ld", cn, (long) mgc->cmode );
4206 #endif
4207
4208 return( mod_gzip_imap_add_item( parms, mgc, a1, a2, 1 ) );
4209 }
4210
4211 static const char *
4212 mod_gzip_set_item_exclude( cmd_parms *parms, void *cfg, char *a1, char *a2 )
4213 {
4214 mod_gzip_conf *mgc;
4215 char *arg;
4216
4217 #ifdef MOD_GZIP_DEBUG1
4218 server_rec *srv = parms->server;
4219 char cn[]="mod_gzip_set_item_exclude()";
4220 #endif
4221
4222 #ifdef MOD_GZIP_DEBUG1
4223 mod_gzip_server_now = srv;
4224 mod_gzip_printf( " ");
4225 mod_gzip_printf( "%s: Entry", cn );
4226 mod_gzip_printf( "%s: a1=[%s]", cn, npp(a1));
4227 mod_gzip_printf( "%s: a2=[%s]", cn, npp(a2));
4228 #endif
4229
4230 arg = a1;
4231
4232 mgc = ( mod_gzip_conf * ) cfg;
4233
4234 #ifdef MOD_GZIP_DEBUG1
4235 mod_gzip_printf( "%s: mgc->loc = [%s]", cn, npp(mgc->loc));
4236 mod_gzip_printf( "%s: srv->is_virtual = %ld", cn, (long)srv->is_virtual );
4237 mod_gzip_printf( "%s: srv->server_hostname = [%s]", cn, npp(srv->server_hostname));
4238 mod_gzip_printf( "%s: mgc->cmode = %ld", cn, (long) mgc->cmode );
4239 #endif
4240
4241 return( mod_gzip_imap_add_item( parms, mgc, a1, a2, 0 ) );
4242 }
4243
4244 static void *mod_gzip_create_dconfig(
4245 pool *p,
4246 char *dirspec
4247 )
4248 {
4249 mod_gzip_conf *cfg;
4250 char *dname = dirspec;
4251
4252 cfg = (mod_gzip_conf *) ap_pcalloc(p, sizeof(mod_gzip_conf));
4253
4254 cfg->cmode = MOD_GZIP_CONFIG_MODE_DIRECTORY;
4255
4256 dname = (dname != NULL) ? dname : "";
4257
4258 cfg->loc = ap_pstrcat(p, "DIR(", dname, ")", NULL);
4259
4260 mod_gzip_set_defaults1( (mod_gzip_conf *) cfg );
4261
4262 return (void *) cfg;
4263 }
4264
4265 static void *mod_gzip_merge_dconfig(
4266 pool *p,
4267 void *parent_conf,
4268 void *newloc_conf
4269 )
4270 {
4271 mod_gzip_conf *merged_config = (mod_gzip_conf *) ap_pcalloc(p, sizeof(mod_gzip_conf));
4272 mod_gzip_conf *pconf = (mod_gzip_conf *) parent_conf;
4273 mod_gzip_conf *nconf = (mod_gzip_conf *) newloc_conf;
4274
4275 mod_gzip_merge1(
4276 ( pool * ) p,
4277 ( mod_gzip_conf * ) merged_config,
4278 ( mod_gzip_conf * ) pconf,
4279 ( mod_gzip_conf * ) nconf
4280 );
4281
4282 return (void *) merged_config;
4283 }
4284
4285 static void *mod_gzip_create_sconfig(
4286 pool *p,
4287 server_rec *s
4288 )
4289 {
4290 mod_gzip_conf *cfg;
4291 char *sname = s->server_hostname;
4292
4293 #ifdef MOD_GZIP_DEBUG1
4294 mod_gzip_server_now = s;
4295 #endif
4296
4297 cfg = (mod_gzip_conf *) ap_pcalloc(p, sizeof(mod_gzip_conf));
4298
4299 cfg->cmode = MOD_GZIP_CONFIG_MODE_SERVER;
4300
4301 sname = (sname != NULL) ? sname : "";
4302
4303 cfg->loc = ap_pstrcat(p, "SVR(", sname, ")", NULL);
4304
4305 mod_gzip_set_defaults1( (mod_gzip_conf *) cfg );
4306
4307 return (void *) cfg;
4308 }
4309
4310 static void *mod_gzip_merge_sconfig(
4311 pool *p,
4312 void *parent_conf,
4313 void *newloc_conf
4314 )
4315 {
4316 mod_gzip_conf *merged_config = (mod_gzip_conf *) ap_pcalloc(p, sizeof(mod_gzip_conf));
4317 mod_gzip_conf *pconf = (mod_gzip_conf *) parent_conf;
4318 mod_gzip_conf *nconf = (mod_gzip_conf *) newloc_conf;
4319
4320 mod_gzip_merge1(
4321 ( pool * ) p,
4322 ( mod_gzip_conf * ) merged_config,
4323 ( mod_gzip_conf * ) pconf,
4324 ( mod_gzip_conf * ) nconf
4325 );
4326
4327 return (void *) merged_config;
4328 }
4329
4330 static const command_rec mod_gzip_cmds[] =
4331 {
4332 {"mod_gzip_on", mod_gzip_set_is_on, NULL, OR_OPTIONS, TAKE1,
4333 "Yes=mod_gzip will handle requests. No=mod_gzip is disabled."},
4334 {"mod_gzip_add_header_count", mod_gzip_set_add_header_count, NULL, OR_OPTIONS, TAKE1,
4335 "Yes=Add header byte counts to Common Log Format output total(s)."},
4336 {"mod_gzip_keep_workfiles", mod_gzip_set_keep_workfiles, NULL, OR_OPTIONS, TAKE1,
4337 "Yes=Keep any work files used. No=Automatically delete any work files used."},
4338 {"mod_gzip_dechunk", mod_gzip_set_dechunk, NULL, OR_OPTIONS, TAKE1,
4339 "Yes=Allow removal of 'Transfer-encoding: chunked' when necessary."},
4340 {"mod_gzip_min_http", mod_gzip_set_min_http, NULL, OR_OPTIONS, TAKE1,
4341 "Minimum HTTP protocol value to support. 1000 = HTTP/1.0 1001 = HTTP/1.1"},
4342 {"mod_gzip_minimum_file_size", mod_gzip_set_minimum_file_size, NULL, OR_OPTIONS, TAKE1,
4343 "Minimum size ( bytes ) of a file eligible for compression"},
4344 {"mod_gzip_maximum_file_size", mod_gzip_set_maximum_file_size, NULL, OR_OPTIONS, TAKE1,
4345 "Maximum size ( bytes ) of a file eligible for compression"},
4346 {"mod_gzip_maximum_inmem_size", mod_gzip_set_maximum_inmem_size, NULL, OR_OPTIONS, TAKE1,
4347 "Maximum size ( bytes ) to use for in-memory compression."},
4348 {"mod_gzip_temp_dir", mod_gzip_set_temp_dir, NULL, OR_OPTIONS, TAKE1,
4349 "The directory to use for work files and compression cache"},
4350 {"mod_gzip_item_include", mod_gzip_set_item_include, NULL, OR_OPTIONS, TAKE2,
4351 "\r\nARG1=[mime,handler,file,uri,reqheader,rspheader] \r\nARG2=[Name of item to INCLUDE in list of things that should be compressed]"},
4352 {"mod_gzip_item_exclude", mod_gzip_set_item_exclude, NULL, OR_OPTIONS, TAKE2,
4353 "\r\nARG1=[mime,handler,file,uri,reqheader,rspheader] \r\nARG2=[Name of item to EXCLUDE from list of things that should be compressed]"},
4354 #ifdef MOD_GZIP_COMMAND_VERSION_USED
4355 {"mod_gzip_command_version", mod_gzip_set_command_version, NULL, OR_OPTIONS, TAKE1,
4356 "User defined pickup string to use for mod_gzip version command."},
4357 #endif
4358 #ifdef MOD_GZIP_CAN_NEGOTIATE
4359 {"mod_gzip_can_negotiate", mod_gzip_set_can_negotiate, NULL, OR_OPTIONS, TAKE1,
4360 "Yes=Negotiate/send static compressed versions of files No=Do not negotiate."},
4361 #endif
4362 { "mod_gzip_handle_methods", mod_gzip_handle_methods, NULL, OR_OPTIONS, TAKE12,
4363 "mod_gzip_handle_methods GET|POST [GET|POST]\n" },
4364 { "mod_gzip_static_suffix", mod_gzip_static_suffix, NULL, OR_OPTIONS, TAKE1,
4365 "mod_gzip_static_suffix suffix" },
4366 { "mod_gzip_send_vary", mod_gzip_send_vary, NULL, OR_OPTIONS, TAKE1,
4367 "mod_gzip_send_vary on|off" },
4368 { "mod_gzip_update_static", mod_gzip_update_static, NULL, OR_OPTIONS, TAKE1,
4369 "mod_gzip_update_static yes|no" },
4370 {NULL}
4371 };
4372
4373 static const handler_rec mod_gzip_handlers[] =
4374 {
4375 {"mod_gzip_handler", mod_gzip_handler},
4376 {CGI_MAGIC_TYPE, mod_gzip_handler},
4377 {"cgi-script", mod_gzip_handler},
4378 {"*", mod_gzip_handler},
4379 {NULL}
4380 };
4381
4382 module MODULE_VAR_EXPORT gzip_module =
4383 {
4384 STANDARD_MODULE_STUFF,
4385 mod_gzip_init,
4386 mod_gzip_create_dconfig,
4387 mod_gzip_merge_dconfig,
4388 mod_gzip_create_sconfig,
4389 mod_gzip_merge_sconfig,
4390 mod_gzip_cmds,
4391 mod_gzip_handlers,
4392 NULL,
4393 NULL,
4394 NULL,
4395 NULL,
4396 mod_gzip_type_checker,
4397 NULL,
4398 NULL,
4399 NULL,
4400 NULL,
4401 NULL,
4402 NULL
4403 };
4404
4405 #ifdef NETWARE
4406 int main(int argc, char *argv[])
4407 {
4408 ExitThread(TSR_THREAD, 0);
4409 }
4410 #endif
4411
4412 long mod_gzip_send(
4413 char *buf,
4414 long buflen,
4415 request_rec *r
4416 )
4417 {
4418 #ifdef MOD_GZIP_DEBUG1
4419 char cn[]="mod_gzip_send()";
4420 #endif
4421
4422 int bytes_to_send = 0;
4423 int bytes_sent = 0;
4424 long bytes_left = buflen;
4425 long total_bytes_sent = 0;
4426
4427 char *p1=buf;
4428 int p1maxlen=4096;
4429
4430 #ifdef MOD_GZIP_DEBUG1
4431 #ifdef MOD_GZIP_DEBUG1_SEND1
4432 mod_gzip_printf("%s: Entry...",cn);
4433 mod_gzip_printf("%s: buf = %ld",cn,(long)buf);
4434 mod_gzip_printf("%s: buflen = %ld",cn,(long)buflen);
4435 mod_gzip_printf("%s: r = %ld",cn,(long)r);
4436 #endif
4437 #endif
4438
4439 if ( !buf ) return 0;
4440 if ( !buflen ) return 0;
4441 if ( !r ) return 0;
4442
4443 for (;;)
4444 {
4445 if ( bytes_left <= 0 )
4446 {
4447 break;
4448 }
4449
4450 bytes_to_send = p1maxlen;
4451
4452 if ( bytes_to_send > bytes_left )
4453 {
4454 bytes_to_send = bytes_left;
4455 }
4456
4457 #ifdef MOD_GZIP_DEBUG1
4458 #ifdef MOD_GZIP_DEBUG1_SEND1
4459 mod_gzip_printf("%s: Call ap_rwrite(bytes_to_send=%d)...",cn,bytes_to_send);
4460 #endif
4461 #endif
4462
4463 bytes_sent =
4464 ap_rwrite(
4465 p1,
4466 bytes_to_send,
4467 (request_rec *) r
4468 );
4469
4470 #ifdef MOD_GZIP_DEBUG1
4471 #ifdef MOD_GZIP_DEBUG1_SEND1
4472 mod_gzip_printf("%s: Back ap_rwrite(bytes_to_send=%d)...",cn,bytes_to_send);
4473 mod_gzip_printf("%s: bytes_sent = %d",cn,bytes_sent);
4474 #endif
4475 #endif
4476
4477 if ( bytes_sent > 0 )
4478 {
4479 total_bytes_sent += bytes_sent;
4480 bytes_left -= bytes_sent;
4481 p1 += bytes_sent;
4482 }
4483 else
4484 {
4485 break;
4486 }
4487 }
4488
4489 #ifdef MOD_GZIP_DEBUG1
4490 mod_gzip_printf("%s: Done > return( total_bytes_sent = %ld ) >",
4491 cn, (long) total_bytes_sent);
4492 #endif
4493
4494 return( total_bytes_sent );
4495 }
4496
4497 int mod_gzip_redir1_handler(
4498 request_rec *r,
4499 mod_gzip_conf *dconf
4500 )
4501 {
4502 #ifdef MOD_GZIP_DEBUG1
4503 char cn[]="mod_gzip_redir1_handler()";
4504 #endif
4505
4506 int rc = 0;
4507 int status = 0;
4508 int pid = 0;
4509 int save_socket = 0;
4510
4511 int dconf__keep_workfiles = 0;
4512 char *dconf__temp_dir = 0;
4513
4514 char tempfile_redir1[ MOD_GZIP_MAX_PATH_LEN + 2 ];
4515
4516 #if defined(WIN32) || defined(NETWARE)
4517 int save_flags = 0;
4518 #endif
4519
4520 #ifdef MOD_GZIP_DEBUG1
4521 mod_gzip_printf( " " );
4522 mod_gzip_printf( "%s: Entry...",cn);
4523 #endif
4524
4525 tempfile_redir1[0] = 0;
4526
4527 dconf__keep_workfiles = dconf->keep_workfiles;
4528 dconf__temp_dir = dconf->temp_dir;
4529
4530 #ifdef MOD_GZIP_DEBUG1
4531 mod_gzip_printf( "%s: r->proxyreq = %d", cn, (int) r->proxyreq );
4532 mod_gzip_printf( "%s: dconf__keep_workfiles = %d", cn, (int) dconf__keep_workfiles );
4533 mod_gzip_printf( "%s: dconf__temp_dir = [%s]", cn, npp(dconf__temp_dir));
4534 #endif
4535
4536 ap_table_setn( r->notes,
4537 "mod_gzip_running",ap_pstrdup(r->pool,"1"));
4538
4539 #ifdef MOD_GZIP_DEBUG1
4540 mod_gzip_printf( "%s: r->notes->mod_gzip_running set to '1'",cn);
4541 #endif
4542
4543 pid = getpid();
4544
4545 #ifdef MOD_GZIP_DEBUG1
4546 mod_gzip_printf( "%s: Saving 'r->connection->client->fd' value to 'save_socket' stack variable...",cn);
4547 #endif
4548
4549 save_socket = (int) r->connection->client->fd;
4550
4551 #ifdef MOD_GZIP_DEBUG1
4552 mod_gzip_printf( "%s: 'r->connection->client->fd' saved to 'save_socket' stack variable",cn);
4553 #endif
4554
4555 #ifdef MOD_GZIP_DEBUG1
4556 mod_gzip_printf( "%s: Creating 'tempfile_redir1' string now...",cn);
4557 #endif
4558
4559 mod_gzip_create_unique_filename(
4560 dconf__temp_dir,
4561 (char *) tempfile_redir1,
4562 MOD_GZIP_MAX_PATH_LEN
4563 );
4564
4565 #ifdef MOD_GZIP_DEBUG1
4566 mod_gzip_printf( "%s: tempfile_redir1 = [%s]",cn,npp(tempfile_redir1));
4567 mod_gzip_printf( "%s: Call mod_gzip_dyn1_getfdo1(%s)...",cn,npp(tempfile_redir1));
4568 #endif
4569
4570 status = mod_gzip_dyn1_getfdo1( r, tempfile_redir1 );
4571
4572 #ifdef MOD_GZIP_DEBUG1
4573 mod_gzip_printf( "%s: Back mod_gzip_dyn1_getfdo1(%s)...",cn,npp(tempfile_redir1));
4574 #endif
4575
4576 if ( status != OK )
4577 {
4578 #ifdef MOD_GZIP_DEBUG1
4579 mod_gzip_printf( "%s: Back mod_gzip_dyn1_getfdo1(%s)...",cn,npp(tempfile_redir1));
4580 mod_gzip_printf( "%s: .... mod_gzip_dyn1_getfdo1() call FAILED",cn);
4581 mod_gzip_printf( "%s: status = %d",cn,status);
4582 #endif
4583
4584 #ifdef WIN32
4585 ap_log_error( "",0,APLOG_NOERRNO|APLOG_WARNING, r->server,
4586 "mod_gzip: ERROR: CreateFile(%s) in dyn1_getfdo1",tempfile_redir1);
4587 #else
4588 ap_log_error( "",0,APLOG_NOERRNO|APLOG_WARNING, r->server,
4589 "mod_gzip: ERROR: fopen(%s) in dyn1_getfdo1",tempfile_redir1);
4590 #endif
4591
4592 ap_log_error( "",0,APLOG_NOERRNO|APLOG_WARNING, r->server,
4593 "mod_gzip: ERROR: %s",mod_gzip_check_permissions);
4594
4595 #ifdef MOD_GZIP_USES_APACHE_LOGS
4596 ap_table_setn( r->notes,
4597 "mod_gzip_result",ap_pstrdup(r->pool,"DECLINED:DYN1_OPENFAIL_BODY"));
4598 #endif
4599
4600 #ifdef MOD_GZIP_DEBUG1
4601 mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn);
4602 #endif
4603
4604 return DECLINED;
4605 }
4606 else
4607 {
4608 #ifdef MOD_GZIP_DEBUG1
4609 mod_gzip_printf( "%s: Back mod_gzip_dyn1_getfdo1(%s)...",cn,npp(tempfile_redir1));
4610 mod_gzip_printf( "%s: .... mod_gzip_dyn1_getfdo1() call SUCCEEDED",cn);
4611 #endif
4612 }
4613
4614 #if defined(WIN32) || defined(NETWARE)
4615
4616 #ifdef MOD_GZIP_DEBUG1
4617 mod_gzip_printf( "%s: WINSOCK: Saves/restores B_SOCKET flag as well...",cn);
4618 mod_gzip_printf( "%s: WINSOCK: Saving 'r->connection->client->flags' value to 'save_flags' stack variable...",cn);
4619 #endif
4620
4621 save_flags = (int) r->connection->client->flags;
4622
4623 #ifdef MOD_GZIP_DEBUG1
4624
4625 mod_gzip_printf( "%s: WINSOCK: r->connection->client->flags = %ld", cn, (long) r->connection->client->flags );
4626
4627 if ( r->connection->client->flags & B_SOCKET )
4628 {
4629 mod_gzip_printf( "%s: WINSOCK: r->connection->client->flags & B_SOCKET is TRUE",cn);
4630 }
4631 else
4632 {
4633 mod_gzip_printf( "%s: WINSOCK: r->connection->client->flags & B_SOCKET is FALSE",cn);
4634 }
4635
4636 #endif
4637
4638 if ( r->connection->client->flags & B_SOCKET )
4639 {
4640 #ifdef MOD_GZIP_DEBUG1
4641 mod_gzip_printf( "%s: WINSOCK: Clearing B_SOCKET flag now....", cn);
4642 mod_gzip_printf( "%s: WINSOCK: r->connection->client->flags &= ~B_SOCKET", cn);
4643 #endif
4644
4645 r->connection->client->flags &= ~B_SOCKET;
4646 }
4647 else
4648 {
4649 #ifdef MOD_GZIP_DEBUG1
4650 mod_gzip_printf( "%s: WINSOCK: B_SOCKET flag not present...", cn);
4651 mod_gzip_printf( "%s: WINSOCK: No action was taken...", cn);
4652 #endif
4653 }
4654
4655 #ifdef MOD_GZIP_DEBUG1
4656
4657 mod_gzip_printf( "%s: WINSOCK: r->connection->client->flags = %ld", cn, (long) r->connection->client->flags );
4658
4659 if ( r->connection->client->flags & B_SOCKET )
4660 {
4661 mod_gzip_printf( "%s: WINSOCK: r->connection->client->flags & B_SOCKET is TRUE",cn);
4662 }
4663 else
4664 {
4665 mod_gzip_printf( "%s: WINSOCK: r->connection->client->flags & B_SOCKET is FALSE",cn);
4666 }
4667
4668 #endif
4669
4670 #endif
4671
4672 #ifdef MOD_GZIP_DEBUG1
4673 mod_gzip_printf( "%s: Call ap_internal_redirect(r->unparsed_uri=[%s])...",
4674 cn,npp(r->unparsed_uri));
4675 mod_gzip_printf( " " );
4676 #endif
4677
4678 ap_internal_redirect( r->unparsed_uri, r );
4679
4680 #ifdef MOD_GZIP_DEBUG1
4681 mod_gzip_printf( " " );
4682 mod_gzip_printf( "%s: Back ap_internal_redirect(r->unparsed_uri=[%s])...",
4683 cn,npp(r->unparsed_uri));
4684 #endif
4685
4686 #ifdef MOD_GZIP_DEBUG1
4687 mod_gzip_printf( "%s: Before... ap_rflush()...",cn);
4688 mod_gzip_printf( "%s: r->connection->client->outcnt = %ld",
4689 cn,(long) r->connection->client->outcnt );
4690 mod_gzip_printf( "%s: r->connection->client->bytes_sent = %ld",
4691 cn,(long) r->connection->client->bytes_sent );
4692 mod_gzip_printf( "%s: Call..... ap_rflush()...",cn);
4693 #endif
4694
4695 ap_rflush(r);
4696
4697 #ifdef MOD_GZIP_DEBUG1
4698 mod_gzip_printf( "%s: Back..... ap_rflush()...",cn);
4699 mod_gzip_printf( "%s: After.... ap_rflush()...",cn);
4700 mod_gzip_printf( "%s: r->connection->client->outcnt = %ld",
4701 cn,(long) r->connection->client->outcnt );
4702 mod_gzip_printf( "%s: r->connection->client->bytes_sent = %ld",
4703 cn,(long) r->connection->client->bytes_sent );
4704 #endif
4705
4706 #ifdef WIN32
4707
4708 if ( r->connection->client->hFH )
4709 {
4710 #ifdef MOD_GZIP_DEBUG1
4711 mod_gzip_printf( "%s: WIN32: Call CloseHandle( r->connection->client->hFH )...",cn);
4712 #endif
4713
4714 CloseHandle( r->connection->client->hFH );
4715
4716 #ifdef MOD_GZIP_DEBUG1
4717 mod_gzip_printf( "%s: WIN32: Back CloseHandle( r->connection->client->hFH )...",cn);
4718 #endif
4719
4720 r->connection->client->hFH = 0;
4721
4722 #ifdef MOD_GZIP_DEBUG1
4723 mod_gzip_printf( "%s: WIN32: r->connection->client->hFH reset to ZERO",cn);
4724 #endif
4725 }
4726 else
4727 {
4728 #ifdef MOD_GZIP_DEBUG1
4729 mod_gzip_printf( "%s: WIN32: r->connection->client->hFH already closed.",cn);
4730 mod_gzip_printf( "%s: WIN32: No CloseFile() call was necessary at this point.",cn);
4731 #endif
4732 }
4733
4734 #else
4735
4736 #ifdef MOD_GZIP_DEBUG1
4737 mod_gzip_printf( "%s: UNIX: Call close( r->connection->client->fd )...",cn);
4738 #endif
4739
4740 close( r->connection->client->fd );
4741
4742 #ifdef MOD_GZIP_DEBUG1
4743 mod_gzip_printf( "%s: UNIX: Back close( r->connection->client->fd )...",cn);
4744 #endif
4745
4746 #endif
4747
4748 r->connection->client->fd = (int) save_socket;
4749
4750 #ifdef MOD_GZIP_DEBUG1
4751 mod_gzip_printf( "%s: 'r->connection->client->fd' RESTORED from 'save_socket' stack variable",cn);
4752 #endif
4753
4754 #if defined(WIN32) || defined(NETWARE)
4755
4756 r->connection->client->flags = (int) save_flags;
4757
4758 #ifdef MOD_GZIP_DEBUG1
4759 mod_gzip_printf( "%s: WINSOCK: r->connection->client->flags RESTORED from 'save_flags' stack variable...",cn);
4760 #endif
4761
4762 #ifdef MOD_GZIP_DEBUG1
4763
4764 mod_gzip_printf( "%s: WINSOCK: r->connection->client->flags = %ld", cn, (long) r->connection->client->flags );
4765
4766 if ( r->connection->client->flags & B_SOCKET )
4767 {
4768 mod_gzip_printf( "%s: WINSOCK: r->connection->client->flags & B_SOCKET is TRUE",cn);
4769 }
4770 else
4771 {
4772 mod_gzip_printf( "%s: WINSOCK: r->connection->client->flags & B_SOCKET is FALSE",cn);
4773 }
4774
4775 #endif
4776
4777 #endif
4778
4779 r->connection->client->bytes_sent = 0;
4780 r->connection->client->outcnt = 0;
4781
4782 #ifdef MOD_GZIP_DEBUG1
4783 mod_gzip_printf( "%s: Connection byte counts have been RESET...",cn);
4784 mod_gzip_printf( "%s: r->connection->client->outcnt = %ld",
4785 cn, r->connection->client->outcnt );
4786 mod_gzip_printf( "%s: r->connection->client->bytes_sent = %ld",
4787 cn, r->connection->client->bytes_sent );
4788
4789 mod_gzip_printf( "%s: r->bytes_sent = %ld",cn,(long)r->bytes_sent);
4790
4791 if ( r->next )
4792 {
4793 mod_gzip_printf( "%s: r->next->bytes_sent = %ld",cn,(long)r->next->bytes_sent);
4794 }
4795 if ( r->prev )
4796 {
4797 mod_gzip_printf( "%s: r->prev->bytes_sent = %ld",cn,(long)r->prev->bytes_sent);
4798 }
4799
4800 #endif
4801
4802 #ifdef MOD_GZIP_DEBUG1
4803 mod_gzip_printf( "%s: Call mod_gzip_sendfile2(tempfile_redir1=[%s])...",
4804 cn, npp(tempfile_redir1));
4805 #endif
4806
4807 rc = (int)
4808 mod_gzip_sendfile2(
4809 r,
4810 dconf,
4811 tempfile_redir1
4812 );
4813
4814 #ifdef MOD_GZIP_DEBUG1
4815
4816 mod_gzip_printf( "%s: Back mod_gzip_sendfile2(tempfile_redir1=[%s])...",
4817 cn, npp(tempfile_redir1));
4818
4819 if ( rc == OK )
4820 {
4821 mod_gzip_printf( "%s: rc = %d OK", cn, (int) rc);
4822 }
4823 else if ( rc == DECLINED )
4824 {
4825 mod_gzip_printf( "%s: rc = %d DECLINED", cn, (int) rc );
4826 }
4827 else
4828 {
4829 mod_gzip_printf( "%s: rc = %d ( HTTP ERROR CODE? )", cn, (int) rc );
4830 }
4831
4832 #endif
4833
4834 if ( rc != OK )
4835 {
4836 #ifdef MOD_GZIP_DEBUG1
4837 mod_gzip_printf( "%s: mod_gzip_sendfile2() call FAILED",cn);
4838 #endif
4839 }
4840 else
4841 {
4842 #ifdef MOD_GZIP_DEBUG1
4843 mod_gzip_printf( "%s: mod_gzip_sendfile2() call SUCCEEDED",cn);
4844 #endif
4845 }
4846
4847 #ifdef MOD_GZIP_DEBUG1
4848 mod_gzip_printf( "%s: r->connection->client->outcnt = %ld",
4849 cn, r->connection->client->outcnt );
4850 mod_gzip_printf( "%s: r->connection->client->bytes_sent = %ld",
4851 cn, r->connection->client->bytes_sent );
4852 mod_gzip_printf( "%s: Sum of the 2..................... = %ld",
4853 cn, r->connection->client->outcnt +
4854 r->connection->client->bytes_sent );
4855 #endif
4856
4857 #ifdef MOD_GZIP_DEBUG1
4858 mod_gzip_printf( "%s: FINAL CLEANUP...",cn);
4859 mod_gzip_printf( "%s: dconf__keep_workfiles = %d",
4860 cn, dconf__keep_workfiles );
4861 #endif
4862
4863 if ( !dconf__keep_workfiles )
4864 {
4865 #ifdef MOD_GZIP_DEBUG1
4866 mod_gzip_printf( "%s: Call mod_gzip_delete_file(tempfile_redir1=[%s])...",
4867 cn, npp(tempfile_redir1));
4868 #endif
4869
4870 mod_gzip_delete_file( r, tempfile_redir1 );
4871
4872 #ifdef MOD_GZIP_DEBUG1
4873 mod_gzip_printf( "%s: Back mod_gzip_delete_file(tempfile_redir1=[%s])...",
4874 cn, npp(tempfile_redir1));
4875 #endif
4876 }
4877
4878 #ifdef MOD_GZIP_DEBUG1
4879 mod_gzip_printf( "%s: Exit > return( OK ) >",cn,(int)rc);
4880 #endif
4881
4882 return OK;
4883 }
4884
4885 int mod_gzip_dyn1_getfdo1(
4886 request_rec *r,
4887 char *filename
4888 )
4889 {
4890 int status = OK;
4891 int temp_fd = 0;
4892 int open_failed = 0;
4893
4894 #ifdef WIN32
4895 HANDLE temp_fdhan;
4896 #endif
4897
4898 #ifdef MOD_GZIP_DEBUG1
4899 char cn[]="mod_gzip_dyn1_getfdo1()";
4900 #endif
4901
4902 #ifdef MOD_GZIP_DEBUG1
4903 mod_gzip_printf( "%s: Entry...",cn);
4904 mod_gzip_printf( "%s: filename=[%s]",cn,npp(filename));
4905 #endif
4906
4907 #ifdef MOD_GZIP_DYN1_GETFDO1_ERROR_TEST1
4908
4909 status = DECLINED;
4910 #ifdef MOD_GZIP_DEBUG1
4911 mod_gzip_printf( "%s: ** TEST ** 'status' forced to 'DECLINED'...",cn);
4912 #endif
4913 return DECLINED;
4914 #endif
4915
4916 #ifdef WIN32
4917
4918 #ifdef MOD_GZIP_DEBUG1
4919 mod_gzip_printf( "%s: WIN32: Call CreateFile(filename=[%s],GENERIC_WRITE, FILE_SHARE_WRITE )...",
4920 cn, npp(filename));
4921 #endif
4922
4923 temp_fdhan =
4924 CreateFile(
4925 filename,
4926 GENERIC_WRITE,
4927 FILE_SHARE_WRITE,
4928 NULL,
4929 CREATE_ALWAYS,
4930 FILE_ATTRIBUTE_NORMAL,
4931 NULL
4932 );
4933
4934 if ( temp_fdhan == INVALID_HANDLE_VALUE )
4935 {
4936 open_failed = 1;
4937 }
4938
4939 #else
4940
4941 #ifdef MOD_GZIP_DEBUG1
4942 mod_gzip_printf( "%s: UNIX: Call open(filename=[%s],O_RDWR|O_CREAT|O_TRUNC,S_IRWXU)...",
4943 cn, npp(filename));
4944 #endif
4945
4946 if ((temp_fd = open(filename,O_RDWR|O_CREAT|O_TRUNC,S_IRWXU)) == -1)
4947 {
4948 open_failed = 1;
4949 }
4950
4951 #endif
4952
4953 if ( open_failed )
4954 {
4955 #ifdef MOD_GZIP_DEBUG1
4956
4957 #ifdef WIN32
4958 mod_gzip_printf( "%s: WIN32: .... CreateFile() call FAILED", cn );
4959 mod_gzip_printf( "%s: WIN32: temp_fd = %d", cn, temp_fd );
4960 #else
4961 mod_gzip_printf( "%s: UNIX: .... open() call FAILED", cn );
4962 mod_gzip_printf( "%s: UNIX: temp_fd = %d", cn, temp_fd );
4963 #endif
4964
4965 #endif
4966
4967 ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r,
4968 "mod_gzip: ERROR: Couldn't create a file descriptor at HTTP : %s", filename);
4969
4970 #ifdef MOD_GZIP_DEBUG1
4971 mod_gzip_printf( "%s: Exit > return( HTTP_INTERNAL_SERVER_ERROR ) >",cn);
4972 #endif
4973
4974 return HTTP_INTERNAL_SERVER_ERROR;
4975 }
4976
4977 #ifdef MOD_GZIP_DEBUG1
4978
4979 #ifdef WIN32
4980
4981 mod_gzip_printf( "%s: WIN32: .... CreateFile() call SUCCEEDED", cn );
4982 mod_gzip_printf( "%s: WIN32: temp_fdhan = (WIN32 HANDLE) %d", cn, (int) temp_fdhan );
4983
4984 #else
4985
4986 mod_gzip_printf( "%s: UNIX: .... open() call SUCCEEDED", cn );
4987 mod_gzip_printf( "%s: UNIX: temp_fd = (UNIX int) %d", cn, temp_fd );
4988
4989 #endif
4990
4991 #endif
4992
4993 #ifdef WIN32
4994
4995 r->connection->client->fd = (int) temp_fdhan;
4996 r->connection->client->hFH = (HANDLE) temp_fdhan;
4997
4998 #ifdef MOD_GZIP_DEBUG1
4999
5000 mod_gzip_printf( "%s: WIN32: r->connection->client->fd = (int ) %d", cn, (int ) r->connection->client->fd );
5001 mod_gzip_printf( "%s: WIN32: r->connection->client->hFH = (HANDLE) %ld", cn, (long) r->connection->client->hFH );
5002 mod_gzip_printf( "%s: WIN32: r->connection->client->flags = %ld", cn, (long) r->connection->client->flags );
5003
5004 if ( r->connection->client->flags & B_SOCKET )
5005 {
5006 mod_gzip_printf( "%s: WIN32: r->connection->client->flags & B_SOCKET is TRUE",cn);
5007 }
5008 else
5009 {
5010 mod_gzip_printf( "%s: WIN32: r->connection->client->flags & B_SOCKET is FALSE",cn);
5011 }
5012
5013 #endif
5014
5015 #else
5016
5017 r->connection->client->fd = temp_fd;
5018
5019 #ifdef MOD_GZIP_DEBUG1
5020 mod_gzip_printf( "%s: UNIX: r->connection->client->fd = %d", cn, r->connection->client->fd );
5021 #endif
5022
5023 #endif
5024
5025 #ifdef MOD_GZIP_DEBUG1
5026 mod_gzip_printf( "%s: Exit > return( status=%d ) >", cn, status );
5027 #endif
5028
5029 return status;
5030 }
5031
5032 long mod_gzip_sendfile1(
5033 request_rec *r,
5034 char *input_filename,
5035 FILE *ifh_passed,
5036 long starting_offset
5037 )
5038 {
5039 FILE *ifh;
5040 int rc;
5041 int err;
5042 int bytesread;
5043 int byteswritten;
5044 long total_byteswritten=0;
5045
5046 #define MOD_GZIP_SENDFILE1_BUFFER_SIZE 4096
5047 char tmp[ MOD_GZIP_SENDFILE1_BUFFER_SIZE + 16 ];
5048
5049 #ifdef MOD_GZIP_DEBUG1
5050 char cn[]="mod_gzip_sendfile1()";
5051 #endif
5052
5053 #ifdef MOD_GZIP_DEBUG1
5054 mod_gzip_printf( "%s: Entry...",cn);
5055 mod_gzip_printf( "%s: r = %ld", cn,(long)r);
5056 mod_gzip_printf( "%s: input_filename = [%s]",cn,npp(input_filename));
5057 mod_gzip_printf( "%s: ifh_passed = %ld", cn,(long) ifh_passed);
5058 mod_gzip_printf( "%s: starting_offset = %ld", cn,(long) starting_offset);
5059 #endif
5060
5061 if ( !r ) return 0;
5062 if ( ( !ifh_passed ) && ( !input_filename ) ) return 0;
5063
5064 if ( ifh_passed )
5065 {
5066 #ifdef MOD_GZIP_DEBUG1
5067 mod_gzip_printf( "%s: 'ifh_passed' is valid",cn);
5068 mod_gzip_printf( "%s: 'ifh' set to 'ifh_passed'...",cn);
5069 mod_gzip_printf( "%s: fopen() was NOT called...",cn);
5070 #endif
5071
5072 ifh = ifh_passed;
5073 }
5074 else
5075 {
5076 #ifdef MOD_GZIP_DEBUG1
5077 mod_gzip_printf( "%s: 'ifh_passed' was NULL...",cn);
5078 mod_gzip_printf( "%s: Call fopen(%s)...",cn,npp(input_filename));
5079 #endif
5080
5081 ifh = fopen( input_filename, "rb" );
5082
5083 if ( !ifh )
5084 {
5085 #ifdef MOD_GZIP_DEBUG1
5086 mod_gzip_printf( "%s: .... fopen() FAILED",cn);
5087 mod_gzip_printf( "%s: Exit > return( 0 ) >",cn);
5088 #endif
5089
5090 return 0;
5091 }
5092
5093 #ifdef MOD_GZIP_DEBUG1
5094 mod_gzip_printf( "%s: .... fopen() SUCCEEDED",cn);
5095 #endif
5096 }
5097
5098 if ( starting_offset > -1 )
5099 {
5100 #ifdef MOD_GZIP_DEBUG1
5101 mod_gzip_printf( "%s: Call fseek(ifh,starting_offset=%ld,0)...",
5102 cn, (long) starting_offset );
5103 #endif
5104
5105 rc = fseek( ifh, starting_offset, 0 );
5106
5107 if ( rc != 0 )
5108 {
5109 #ifdef MOD_GZIP_DEBUG1
5110 mod_gzip_printf( "%s: .... fseek() FAILED",cn);
5111 mod_gzip_printf( "%s: Exit > return( 0 ) >",cn);
5112 #endif
5113
5114 return 0;
5115 }
5116 #ifdef MOD_GZIP_DEBUG1
5117 else
5118 {
5119 mod_gzip_printf( "%s: .... fseek() SUCCEEDED",cn);
5120 }
5121 #endif
5122 }
5123
5124 #ifdef MOD_GZIP_DEBUG1
5125 mod_gzip_printf( "%s: sizeof( tmp ) = %d",cn,sizeof(tmp));
5126 mod_gzip_printf( "%s: MOD_GZIP_SENDFILE1_BUFFER_SIZE = %d",
5127 cn,(int)MOD_GZIP_SENDFILE1_BUFFER_SIZE);
5128 mod_gzip_printf( "%s: Sending file contents now...",cn);
5129 #endif
5130
5131 for (;;)
5132 {
5133 bytesread = fread( tmp, 1, MOD_GZIP_SENDFILE1_BUFFER_SIZE, ifh );
5134
5135 #ifdef MOD_GZIP_DEBUG1
5136 #ifdef MOD_GZIP_DEBUG1_SENDFILE1
5137 mod_gzip_printf( "%s: Back fread(): bytesread=%d",cn,bytesread);
5138 #endif
5139 #endif
5140
5141 if ( bytesread < 1 ) break;
5142
5143 byteswritten = (int)
5144 mod_gzip_send( tmp, bytesread, r );
5145
5146 if ( byteswritten > 0 )
5147 {
5148 total_byteswritten += byteswritten;
5149 }
5150
5151 #ifdef MOD_GZIP_DEBUG1
5152 #ifdef MOD_GZIP_DEBUG1_SENDFILE1
5153 mod_gzip_printf( "%s: byteswritten = %d",cn,(int)byteswritten);
5154 #endif
5155 #endif
5156
5157 if ( byteswritten != bytesread )
5158 {
5159 err = errno;
5160
5161 #ifdef FUTURE_USE
5162 #if defined(WIN32) || defined(NETWARE)
5163 err = WSAGetLastError();
5164 #else
5165 err = errno;
5166 #endif
5167 #endif
5168
5169 #ifdef MOD_GZIP_DEBUG1
5170 mod_gzip_printf( "%s: TRANSMIT ERROR: bytesread=%d byteswritten=%d err=%d",
5171 cn,(int)bytesread,(int)byteswritten,(int)err );
5172 #endif
5173
5174 #ifdef MOD_GZIP_DEBUG1
5175 mod_gzip_printf( "%s: Breaking out of transmit loop early...",cn);
5176 #endif
5177
5178 break;
5179 }
5180 }
5181
5182 #ifdef MOD_GZIP_DEBUG1
5183 mod_gzip_printf( "%s: Done sending file contents...",cn);
5184 mod_gzip_printf( "%s: total_byteswritten = %ld",cn,total_byteswritten);
5185 #endif
5186
5187 if ( !ifh_passed )
5188 {
5189 #ifdef MOD_GZIP_DEBUG1
5190 mod_gzip_printf( "%s: 'ifh_passed' was NULL so close the",cn);
5191 mod_gzip_printf( "%s: input file that was opened at the",cn);
5192 mod_gzip_printf( "%s: start of this routine...",cn);
5193 mod_gzip_printf( "%s: Call fclose(%s)...",cn,npp(input_filename));
5194 #endif
5195
5196 fclose( ifh );
5197
5198 #ifdef MOD_GZIP_DEBUG1
5199 mod_gzip_printf( "%s: Back fclose(%s)...",cn,npp(input_filename));
5200 #endif
5201 }
5202 else
5203 {
5204 #ifdef MOD_GZIP_DEBUG1
5205 mod_gzip_printf( "%s: 'ifh_passed' was VALID on entry.",cn);
5206 mod_gzip_printf( "%s: No call to fclose() was made.",cn);
5207 #endif
5208 }
5209
5210 #ifdef MOD_GZIP_DEBUG1
5211 mod_gzip_printf( "%s: Exit > return( total_byteswritten = %ld ) >",
5212 cn, (long) total_byteswritten );
5213 #endif
5214
5215 return total_byteswritten;
5216 }
5217
5218 int mod_gzip_sendfile2(
5219 request_rec *r,
5220 mod_gzip_conf *dconf,
5221 char *input_filename
5222 )
5223 {
5224 FILE *ifh=0;
5225 FILE *ofh=0;
5226 int ofh_used=0;
5227
5228 int i=0;
5229 int rc=1;
5230 int err=0;
5231 int final_rc=1;
5232 int linecount=0;
5233 int bytesleft=0;
5234 int bytesread=0;
5235 int bytestoread=0;
5236 int skip_advance=0;
5237 int byteswritten=0;
5238 int bytestowrite=0;
5239 long total_bytes_sent=0;
5240 int valid_char_count=0;
5241 int total_bytes_left_to_copy=0;
5242
5243 /*
5244 * TODO: This is a brain-teaser to solve.
5245 *
5246 * gcc UNIX compiler will report the following 'ok_to_send'
5247 * flag as no longer being 'used' inside this function but
5248 * if it is removed or even commented out then Apache GP faults
5249 * at runtime when logic enters this function ( but only if
5250 * MOD_GZIP_DEBUG1 flag is OFF at compile time ?? ).
5251 *
5252 * There is no 'macro' anywhere that bears this name and
5253 * there doesn't seem to be any reason for this GP fault.
5254 *
5255 * If this 'ok_to_send' variable is removed everything is fine
5256 * for Win32... it is only UNIX gcc compiler that reports no
5257 * warning but will still GP fault at runtime.
5258 *
5259 * It's a mystery. Can anyone solve it?
5260 */
5261
5262 int ok_to_send = 1; /* This MUST remain or UNIX 'GP faults' ??? */
5263
5264 #ifdef MOD_GZIP_DEBUG1
5265 int total_bytes_copied=0;
5266 #endif
5267
5268 struct stat sbuf;
5269
5270 #define MOD_GZIP_SENDFILE2_BUFFER_SIZE 4099
5271 char tmp[ MOD_GZIP_SENDFILE2_BUFFER_SIZE + 16 ];
5272
5273 #define MOD_GZIP_LINE_BUFFER_SIZE 2048
5274 /*char lbuf[ MOD_GZIP_LINE_BUFFER_SIZE + 16 ];*/
5275 char *lbuf = malloc(MOD_GZIP_LINE_BUFFER_SIZE + 16);
5276 int lbuf_reser = 1;
5277
5278 #define MOD_GZIP_DEBUG1_SENDFILE2
5279
5280 #ifdef MOD_GZIP_DEBUG1
5281 char cn[]="mod_gzip_sendfile2()";
5282 #endif
5283
5284 char *sp = 0;
5285 char *p1 = 0;
5286 int p1len = 0;
5287 char *p2 = lbuf;
5288 int p2len = 0;
5289 char *p3 = 0;
5290
5291 long hbytes_in = 0;
5292 long bbytes_in = 0;
5293 long bbytes_out = 0;
5294 long bbytes_total = 0;
5295
5296 int action_flag = 0;
5297 int header_done = 0;
5298 int body_done = 0;
5299 int te_seen = 0;
5300 int te_chunked = 0;
5301 int send_as_is = 0;
5302 int resp_code = 0;
5303 int ce_seen = 0;
5304 int ct_seen = 0;
5305 char ct_value[ 256 ];
5306
5307 int field_ok = 0;
5308 int fields_excluded = 0;
5309 char *fieldkey = 0;
5310 char *fieldstring = 0;
5311
5312 char output_filename1[256];
5313
5314 long raw_input_length = 0;
5315
5316 #define CHUNKE_GET_HEXSTRING 1
5317 #define CHUNKE_WAIT_REAL_EOL1 2
5318 #define CHUNKE_GET_FOOTER 3
5319 #define CHUNKE_GET_REAL_DATA 4
5320
5321 #define CHUNKE_HEXSTRING_MAXLEN 10
5322
5323 int chunke_count = 1;
5324 char *chunke_errstr = NULL;
5325 int chunke_state = CHUNKE_GET_HEXSTRING;
5326 int chunke_nextstate = 0;
5327 long chunke_realdata_length = 0;
5328 long chunke_realdata_read = 0;
5329 int chunke_hexstring_oset = 0;
5330 char chunke_hexstring[ CHUNKE_HEXSTRING_MAXLEN + 1 ];
5331
5332 #ifdef CHUNKE_USES_OUTPUT_BUFFER
5333 char *chunke_obufstart = lbuf;
5334 char *chunke_obuf = chunke_obufstart;
5335 int chunke_obuflen = 0;
5336 int chunke_obuflenmax = MOD_GZIP_LINE_BUFFER_SIZE;
5337 #endif
5338
5339 int dconf__dechunk = 0;
5340 int dconf__keep_workfiles = 0;
5341 char *dconf__temp_dir = 0;
5342
5343 #ifdef MOD_GZIP_DEBUG1