]> granicus.if.org Git - apache/blob - support/apxs.in
ab was sending wrong number of requests when keepalive enabled.
[apache] / support / apxs.in
1 #!@perlbin@ -w
2 #
3 # Licensed to the Apache Software Foundation (ASF) under one or more
4 # contributor license agreements.  See the NOTICE file distributed with
5 # this work for additional information regarding copyright ownership.
6 # The ASF licenses this file to You under the Apache License, Version 2.0
7 # (the "License"); you may not use this file except in compliance with
8 # the License.  You may obtain a copy of the License at
9 #
10 #     http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17
18 require 5.004;
19 use strict;
20 package apxs;
21
22 ##
23 ##  Configuration
24 ##
25
26 my %config_vars = ();
27
28 my $installbuilddir = "@exp_installbuilddir@";
29 get_config_vars("$installbuilddir/config_vars.mk",\%config_vars);
30
31 # read the configuration variables once
32
33 my $prefix         = get_vars("prefix");
34 my $CFG_PREFIX     = $prefix;
35 my $exec_prefix    = get_vars("exec_prefix");
36 my $datadir        = get_vars("datadir");
37 my $localstatedir  = get_vars("localstatedir");
38 my $CFG_TARGET     = get_vars("progname");
39 my $CFG_SYSCONFDIR = get_vars("sysconfdir");
40 my $CFG_CFLAGS     = join ' ', map { get_vars($_) }
41   qw(SHLTCFLAGS CFLAGS NOTEST_CPPFLAGS EXTRA_CPPFLAGS EXTRA_CFLAGS);
42 my $includedir     = get_vars("includedir");
43 my $CFG_INCLUDEDIR = eval qq("$includedir");
44 my $CFG_CC         = get_vars("CC");
45 my $libexecdir     = get_vars("libexecdir");
46 my $CFG_LIBEXECDIR = eval qq("$libexecdir");
47 my $sbindir        = get_vars("sbindir");
48 my $CFG_SBINDIR    = eval qq("$sbindir");
49 my $ltflags        = $ENV{'LTFLAGS'};
50 $ltflags or $ltflags = "--silent";
51
52 my %internal_vars = map {$_ => 1}
53     qw(TARGET CC CFLAGS CFLAGS_SHLIB LD_SHLIB LDFLAGS_SHLIB LIBS_SHLIB
54        PREFIX SBINDIR INCLUDEDIR LIBEXECDIR SYSCONFDIR);
55
56 ##
57 ##  parse argument line
58 ##
59
60 #   defaults for parameters
61 my $opt_n = '';
62 my $opt_g = '';
63 my $opt_c = 0;
64 my $opt_o = '';
65 my @opt_D = ();
66 my @opt_I = ();
67 my @opt_L = ();
68 my @opt_l = ();
69 my @opt_W = ();
70 my @opt_S = ();
71 my $opt_e = 0;
72 my $opt_i = 0;
73 my $opt_a = 0;
74 my $opt_A = 0;
75 my $opt_q = 0;
76 my $opt_h = 0;
77 my $opt_p = 0;
78 my $opt_v = 0;
79
80 #   this subroutine is derived from Perl's getopts.pl with the enhancement of
81 #   the "+" metacharacter at the format string to allow a list to be built by
82 #   subsequent occurrences of the same option.
83 sub Getopts {
84     my ($argumentative, @ARGV) = @_;
85     my $errs = 0;
86     local $_;
87
88     my @args = split / */, $argumentative;
89     while (@ARGV && ($_ = $ARGV[0]) =~ /^-(.)(.*)/) {
90         my ($first, $rest) = ($1,$2);
91         if ($_ =~ m|^--$|) {
92             shift @ARGV;
93             last;
94         }
95         my $pos = index($argumentative,$first);
96         if ($pos >= 0) {
97             if ($pos < $#args && $args[$pos+1] eq ':') {
98                 shift @ARGV;
99                 if ($rest eq '') {
100                     unless (@ARGV) {
101                         error("Incomplete option: $first (needs an argument)");
102                         $errs++;
103                     }
104                     $rest = shift(@ARGV);
105                 }
106                 eval "\$opt_$first = \$rest;";
107             }
108             elsif ($pos < $#args && $args[$pos+1] eq '+') {
109                 shift @ARGV;
110                 if ($rest eq '') {
111                     unless (@ARGV) {
112                         error("Incomplete option: $first (needs an argument)");
113                         $errs++;
114                     }
115                     $rest = shift(@ARGV);
116                 }
117                 eval "push(\@opt_$first, \$rest);";
118             }
119             else {
120                 eval "\$opt_$first = 1";
121                 if ($rest eq '') {
122                     shift(@ARGV);
123                 }
124                 else {
125                     $ARGV[0] = "-$rest";
126                 }
127             }
128         }
129         else {
130             error("Unknown option: $first");
131             $errs++;
132             if ($rest ne '') {
133                 $ARGV[0] = "-$rest";
134             }
135             else {
136                 shift(@ARGV);
137             }
138         }
139     }
140     return ($errs == 0, @ARGV);
141 }
142
143 sub usage {
144     print STDERR "Usage: apxs -g [-S <var>=<val>] -n <modname>\n";
145     print STDERR "       apxs -q [-v] [-S <var>=<val>] [<query> ...]\n";
146     print STDERR "       apxs -c [-S <var>=<val>] [-o <dsofile>] [-D <name>[=<value>]]\n";
147     print STDERR "               [-I <incdir>] [-L <libdir>] [-l <libname>] [-Wc,<flags>]\n";
148     print STDERR "               [-Wl,<flags>] [-p] <files> ...\n";
149     print STDERR "       apxs -i [-S <var>=<val>] [-a] [-A] [-n <modname>] <dsofile> ...\n";
150     print STDERR "       apxs -e [-S <var>=<val>] [-a] [-A] [-n <modname>] <dsofile> ...\n";
151     exit(1);
152 }
153
154 #   option handling
155 my $rc;
156 ($rc, @ARGV) = &Getopts("qn:gco:I+D+L+l+W+S+eiaApv", @ARGV);
157 &usage if ($rc == 0);
158 &usage if ($#ARGV == -1 and not $opt_g and not $opt_q);
159 &usage if (not $opt_q and not ($opt_g and $opt_n) and not $opt_i and not $opt_c and not $opt_e);
160
161 #   argument handling
162 my @args = @ARGV;
163 my $name = 'unknown';
164 $name = $opt_n if ($opt_n ne '');
165
166 if (@opt_S) {
167     my ($opt_S);
168     foreach $opt_S (@opt_S) {
169         if ($opt_S =~ m/^([^=]+)=(.*)$/) {
170             my ($var) = $1;
171             my ($val) = $2;
172             my $oldval = eval "\$CFG_$var";
173
174             unless ($var and $oldval) {
175                 print STDERR "apxs:Error: no config variable $var\n";
176                 &usage;
177             }
178
179             eval "\$CFG_${var}=\"${val}\"";
180         } else {
181             print STDERR "apxs:Error: malformatted -S option\n";
182             &usage;
183         }       
184     }
185 }
186
187 ##
188 ##  Initial shared object support check
189 ##
190 unless ("@MOD_SO_ENABLED@" eq "yes") {
191     error("Sorry, no shared object support for Apache");
192     error("available under your platform. Make sure");
193     error("the Apache module mod_so is compiled into");
194     error("the server binary.");
195     exit 1;
196 }
197
198 sub get_config_vars{
199     my ($file, $rh_config) = @_;
200
201     open IN, $file or die "cannot open $file: $!";
202     while (<IN>){
203         if (/^\s*(.*?)\s*=\s*(.*)$/){
204             $rh_config->{$1} = $2;
205         }
206     }
207     close IN;
208 }
209
210 sub get_vars {
211     my $result = '';
212     my $ok = 0;
213     my $arg;
214     foreach $arg (@_) {
215         if (exists $config_vars{$arg} or exists $config_vars{lc $arg}) {
216             my $val = exists $config_vars{$arg}
217                 ? $config_vars{$arg}
218                 : $config_vars{lc $arg};
219             $val =~ s/[()]//g;
220             $result .= eval "qq($val)" if defined $val;
221             $result .= ";;";
222             $ok = 1;
223         }
224         if (not $ok) {
225             if (exists $internal_vars{$arg} or exists $internal_vars{lc $arg}) {
226                 my $val = exists $internal_vars{$arg} ? $arg : lc $arg;
227                 $val = eval "\$CFG_$val";
228                 $result .= eval "qq($val)" if defined $val;
229                 $result .= ";;";
230                 $ok = 1;
231             }
232             if (not $ok) {
233                 error("Invalid query string `$arg'");
234                 exit(1);
235             }
236         }
237     }
238     $result =~ s|;;$||;
239     $result =~ s|:| |;
240     return $result;
241 }
242
243 ##
244 ##  Operation
245 ##
246
247 #   helper function for executing a list of
248 #   system command with return code checks
249 sub execute_cmds {
250     my (@cmds) = @_;
251     my ($cmd, $rc);
252
253     foreach $cmd (@cmds) {
254         notice($cmd);
255         $rc = system $cmd;
256         if ($rc) {
257             error(sprintf "Command failed with rc=%d\n", $rc << 8);
258             exit 1 ;
259         }
260     }
261 }
262
263 if ($opt_g) {
264     ##
265     ##  SAMPLE MODULE SOURCE GENERATION
266     ##
267
268     if (-d $name) {
269         error("Directory `$name' already exists. Remove first");
270         exit(1);
271     }
272
273     my $data = join('', <DATA>);
274     $data =~ s|%NAME%|$name|sg;
275     $data =~ s|%TARGET%|$CFG_TARGET|sg;
276     $data =~ s|%PREFIX%|$prefix|sg;
277     $data =~ s|%INSTALLBUILDDIR%|$installbuilddir|sg;
278
279     my ($mkf, $mods, $src) = ($data =~ m|^(.+)-=#=-\n(.+)-=#=-\n(.+)|s);
280
281     notice("Creating [DIR]  $name");
282     system("mkdir $name");
283     notice("Creating [FILE] $name/Makefile");
284     open(FP, ">${name}/Makefile") || die;
285     print FP $mkf;
286     close(FP);
287     notice("Creating [FILE] $name/modules.mk");
288     open(FP, ">${name}/modules.mk") || die;
289     print FP $mods;
290     close(FP);
291     notice("Creating [FILE] $name/mod_$name.c");
292     open(FP, ">${name}/mod_${name}.c") || die;
293     print FP $src;
294     close(FP);
295     notice("Creating [FILE] $name/.deps");
296     system("touch ${name}/.deps");
297
298     exit(0);
299 }
300
301
302 if ($opt_q) {
303     ##
304     ##  QUERY INFORMATION 
305     ##
306     my $result;
307     if ($#args >= 0) { 
308         $result = get_vars(@args);
309         print "$result\n";
310     } else {
311         # -q without var name prints all variables and their values
312         
313         # Additional -v pretty-prints output
314         if ($opt_v) {
315             # Variable names in alphabetic order
316             my @vars = sort {uc($a) cmp uc($b)} keys %config_vars;
317             
318             # Make the left column as wide as the longest variable name
319             my $width = 0;
320             foreach (@vars) {
321                 my $l = length $_; 
322                 $width = $l unless ($l <= $width);
323             }
324     
325             foreach (@vars) {
326                 printf "%-${width}s = %s\n", $_, $config_vars{$_};
327             }
328         } else {
329             # Unprettified name=value list
330             foreach (keys %config_vars) {
331                 print "$_=$config_vars{$_}\n";
332             }
333         }
334     }
335 }
336
337 my $apr_config = get_vars("APR_CONFIG");
338
339 if (! -x "$apr_config") {
340     error("$apr_config not found!");
341     exit(1);
342 }
343
344 my $apr_major_version = (split /\./, `$apr_config --version`)[0];
345
346 my $apu_config = "";
347 if ($apr_major_version < 2) {
348     $apu_config = get_vars("APU_CONFIG");
349
350     if (! -x "$apu_config") {
351         error("$apu_config not found!");
352         exit(1);
353     }
354 }
355
356 my $libtool = `$apr_config --apr-libtool`;
357 chomp($libtool);
358
359 my $apr_includedir = `$apr_config --includes`;
360 chomp($apr_includedir);
361 my $apu_includedir = "";
362 if ($apr_major_version < 2) {
363     $apu_includedir = `$apu_config --includes`;
364     chomp($apu_includedir);
365 }
366
367 if ($opt_c) {
368     ##
369     ##  SHARED OBJECT COMPILATION
370     ##
371
372     #   split files into sources and objects
373     my @srcs = ();
374     my @objs = ();
375     my $f;
376     foreach $f (@args) {
377         if ($f =~ m|\.c$|) {
378             push(@srcs, $f);
379         }
380         else {
381             push(@objs, $f);
382         }
383     }
384
385     #   determine output file
386     my $dso_file;
387     if ($opt_o eq '') {
388         if ($#srcs > -1) {
389             $dso_file = $srcs[0];
390             $dso_file =~ s|\.[^.]+$|.la|;
391         }
392         elsif ($#objs > -1) {
393             $dso_file = $objs[0];
394             $dso_file =~ s|\.[^.]+$|.la|;
395         }
396         else {
397             $dso_file = "mod_unknown.la";
398         }
399     }
400     else {
401         $dso_file = $opt_o;
402         $dso_file =~ s|\.[^.]+$|.la|;
403     }
404
405     #   create compilation commands
406     my @cmds = ();
407     my $opt = '';
408     my ($opt_Wc, $opt_I, $opt_D);
409     foreach $opt_Wc (@opt_W) {
410         $opt .= "$1 " if ($opt_Wc =~ m|^\s*c,(.*)$|);
411     }
412     foreach $opt_I (@opt_I) {
413         $opt .= "-I$opt_I ";
414     }
415     foreach $opt_D (@opt_D) {
416         $opt .= "-D$opt_D ";
417     }
418     my $cflags = "$CFG_CFLAGS";
419     my $s;
420     my $mod;
421     foreach $s (@srcs) {
422         my $slo = $s;
423         $slo =~ s|\.c$|.slo|;
424         my $lo = $s;
425         $lo =~ s|\.c$|.lo|;
426         my $la = $s;
427         $la =~ s|\.c$|.la|;
428         my $o = $s;
429         $o =~ s|\.c$|.o|;
430         push(@cmds, "$libtool $ltflags --mode=compile $CFG_CC $cflags -I$CFG_INCLUDEDIR $apr_includedir $apu_includedir $opt -c -o $lo $s && touch $slo");
431         unshift(@objs, $lo);
432     }
433
434     #   create link command
435     my $o;
436     my $lo;     
437     foreach $o (@objs) {
438         $lo .= " $o";
439     }
440     my ($opt_Wl, $opt_L, $opt_l);
441     $opt = '';
442     foreach $opt_Wl (@opt_W) {
443         $opt .= "$1 " if ($opt_Wl =~ m|^\s*l,(.*)$|);
444     }
445     foreach $opt_L (@opt_L) {
446         $opt .= " -L$opt_L";
447     }
448     foreach $opt_l (@opt_l) {
449         $opt .= " -l$opt_l";
450     }
451
452     if ($opt_p == 1) {
453         
454         my $apr_libs=`$apr_config --cflags --ldflags --link-libtool --libs`;
455         chomp($apr_libs);
456         my $apu_libs="";
457         if ($apr_major_version < 2) {
458             $apu_libs=`$apu_config --ldflags --link-libtool --libs`;
459             chomp($apu_libs);
460         }
461         
462         $opt .= " ".$apu_libs." ".$apr_libs;
463     }
464     else {
465         my $apr_ldflags=`$apr_config --ldflags`;
466         chomp($apr_ldflags);
467         $opt .= " -rpath $CFG_LIBEXECDIR -module -avoid-version $apr_ldflags";
468     }
469
470     push(@cmds, "$libtool $ltflags --mode=link $CFG_CC -o $dso_file $opt $lo");
471
472     #   execute the commands
473     &execute_cmds(@cmds);
474
475     #   allow one-step compilation and installation
476     if ($opt_i or $opt_e) {
477         @args = ( $dso_file );
478     }
479 }
480
481 if ($opt_i or $opt_e) {
482     ##
483     ##  SHARED OBJECT INSTALLATION
484     ##
485
486     #   determine installation commands
487     #   and corresponding LoadModule directive
488     my @lmd = ();
489     my @cmds = ();
490     my $f;
491     foreach $f (@args) {
492         #  ack all potential gcc, hp/ux, win32+os2+aix and os/x extensions
493         if ($f !~ m#(\.so$|\.la$|\.sl$|\.dll$|\.dylib$|)#) {
494             error("file $f is not a shared object");
495             exit(1);
496         }
497         my $t = $f;
498         $t =~ s|^.+/([^/]+)$|$1|;
499         #  use .so unambigiously for installed shared library modules
500         $t =~ s|\.[^./\\]+$|\.so|;
501         if ($opt_i) {
502             push(@cmds, "$installbuilddir/instdso.sh SH_LIBTOOL='" .
503                  "$libtool' $f $CFG_LIBEXECDIR");
504             push(@cmds, "chmod 755 $CFG_LIBEXECDIR/$t");
505         }
506
507         #   determine module symbolname and filename
508         my $filename = '';
509         if ($name eq 'unknown') {
510             $name = '';
511             my $base = $f;
512             $base =~ s|\.[^.]+$||;
513             if (-f "$base.c") {
514                 open(FP, "<$base.c");
515                 my $content = join('', <FP>);
516                 close(FP);
517                 if ($content =~ m|.*module\s+(?:AP_MODULE_DECLARE_DATA\s+)?([a-zA-Z0-9_]+)_module\s*=\s*.*|s) {
518                     $name = "$1";
519                     $filename = "$base.c";
520                     $filename =~ s|^[^/]+/||;
521                 }
522             }
523             if ($name eq '') {
524                 if ($base =~ m|.*mod_([a-zA-Z0-9_]+)\..+|) {
525                     $name = "$1";
526                     $filename = $base;
527                     $filename =~ s|^[^/]+/||;
528                 }
529             }
530             if ($name eq '') {
531                 error("Sorry, cannot determine bootstrap symbol name");
532                 error("Please specify one with option `-n'");
533                 exit(1);
534             }
535         }
536         if ($filename eq '') {
537             $filename = "mod_${name}.c";
538         }
539         my $dir = $CFG_LIBEXECDIR;
540         $dir =~ s|^$CFG_PREFIX/?||;
541         $dir =~ s|(.)$|$1/|;
542         $t =~ s|\.la$|.so|;
543         push(@lmd, sprintf("LoadModule %-18s %s", "${name}_module", "$dir$t"));
544     }
545
546     #   execute the commands
547     &execute_cmds(@cmds);
548
549     #   activate module via LoadModule/AddModule directive
550     if ($opt_a or $opt_A) {
551         if (not -f "$CFG_SYSCONFDIR/$CFG_TARGET.conf") {
552             error("Config file $CFG_SYSCONFDIR/$CFG_TARGET.conf not found");
553             exit(1);
554         }
555
556         open(FP, "<$CFG_SYSCONFDIR/$CFG_TARGET.conf") || die;
557         my $content = join('', <FP>);
558         close(FP);
559
560         if ($content !~ m|\n#?\s*LoadModule\s+|) {
561             error("Activation failed for custom $CFG_SYSCONFDIR/$CFG_TARGET.conf file.");
562             error("At least one `LoadModule' directive already has to exist.");
563             exit(1);
564         }
565
566         my $lmd;
567         my $c = '';
568         $c = '#' if ($opt_A);
569         foreach $lmd (@lmd) {
570             my $what = $opt_A ? "preparing" : "activating";
571             if ($content !~ m|\n#?\s*$lmd|) {
572                 # check for open <containers>, so that the new LoadModule
573                 # directive always appears *outside* of an <container>.
574
575                 my $before = ($content =~ m|^(.*\n)#?\s*LoadModule\s+[^\n]+\n|s)[0];
576
577                 # the '()=' trick forces list context and the scalar
578                 # assignment counts the number of list members (aka number
579                 # of matches) then
580                 my $cntopen = () = ($before =~ m|^\s*<[^/].*$|mg);
581                 my $cntclose = () = ($before =~ m|^\s*</.*$|mg);
582
583                 if ($cntopen == $cntclose) {
584                     # fine. Last LoadModule is contextless.
585                     $content =~ s|^(.*\n#?\s*LoadModule\s+[^\n]+\n)|$1$c$lmd\n|s;
586                 }
587                 elsif ($cntopen < $cntclose) {
588                     error('Configuration file is not valid. There are sections'
589                           . ' closed before opened.');
590                     exit(1);
591                 }
592                 else {
593                     # put our cmd after the section containing the last
594                     # LoadModule.
595                     my $found =
596                     $content =~ s!\A (               # string and capture start
597                                   (?:(?:
598                                     ^\s*             # start of conf line with a
599                                     (?:[^<]|<[^/])   # directive which does not
600                                                      # start with '</'
601
602                                     .*(?:$)\n        # rest of the line.
603                                                      # the '$' is in parentheses
604                                                      # to avoid misinterpreting
605                                                      # the string "$\" as
606                                                      # perl variable.
607
608                                     )*               # catch as much as possible
609                                                      # of such lines. (including
610                                                      # zero)
611
612                                     ^\s*</.*(?:$)\n? # after the above, we
613                                                      # expect a config line with
614                                                      # a closing container (</)
615
616                                   ) {$cntopen}       # the whole pattern (bunch
617                                                      # of lines that end up with
618                                                      # a closing directive) must
619                                                      # be repeated $cntopen
620                                                      # times. That's it.
621                                                      # Simple, eh? ;-)
622
623                                   )                  # capture end
624                                  !$1$c$lmd\n!mx;
625
626                     unless ($found) {
627                         error('Configuration file is not valid. There are '
628                               . 'sections opened and not closed.');
629                         exit(1);
630                     }
631                 }
632             } else {
633                 # replace already existing LoadModule line
634                 $content =~ s|^(.*\n)#?\s*$lmd[^\n]*\n|$1$c$lmd\n|s;
635             }
636             $lmd =~ m|LoadModule\s+(.+?)_module.*|;
637             notice("[$what module `$1' in $CFG_SYSCONFDIR/$CFG_TARGET.conf]");
638         }
639         if (@lmd) {
640             if (open(FP, ">$CFG_SYSCONFDIR/$CFG_TARGET.conf.new")) {
641                 print FP $content;
642                 close(FP);
643                 system("cp $CFG_SYSCONFDIR/$CFG_TARGET.conf $CFG_SYSCONFDIR/$CFG_TARGET.conf.bak && " .
644                        "cp $CFG_SYSCONFDIR/$CFG_TARGET.conf.new $CFG_SYSCONFDIR/$CFG_TARGET.conf && " .
645                        "rm $CFG_SYSCONFDIR/$CFG_TARGET.conf.new");
646             } else {
647                 notice("unable to open configuration file");
648             }
649         }
650     }
651 }
652
653 sub error{
654     print STDERR "apxs:Error: $_[0].\n";
655 }
656
657 sub notice{
658     print STDERR "$_[0]\n";
659 }
660
661 ##EOF##
662 __DATA__
663 ##
664 ##  Makefile -- Build procedure for sample %NAME% Apache module
665 ##  Autogenerated via ``apxs -n %NAME% -g''.
666 ##
667
668 builddir=.
669 top_srcdir=%PREFIX%
670 top_builddir=%PREFIX%
671 include %INSTALLBUILDDIR%/special.mk
672
673 #   the used tools
674 APXS=apxs
675 APACHECTL=apachectl
676
677 #   additional defines, includes and libraries
678 #DEFS=-Dmy_define=my_value
679 #INCLUDES=-Imy/include/dir
680 #LIBS=-Lmy/lib/dir -lmylib
681
682 #   the default target
683 all: local-shared-build
684
685 #   install the shared object file into Apache 
686 install: install-modules-yes
687
688 #   cleanup
689 clean:
690         -rm -f mod_%NAME%.o mod_%NAME%.lo mod_%NAME%.slo mod_%NAME%.la 
691
692 #   simple test
693 test: reload
694         lynx -mime_header http://localhost/%NAME%
695
696 #   install and activate shared object by reloading Apache to
697 #   force a reload of the shared object file
698 reload: install restart
699
700 #   the general Apache start/restart/stop
701 #   procedures
702 start:
703         $(APACHECTL) start
704 restart:
705         $(APACHECTL) restart
706 stop:
707         $(APACHECTL) stop
708
709 -=#=-
710 mod_%NAME%.la: mod_%NAME%.slo
711         $(SH_LINK) -rpath $(libexecdir) -module -avoid-version  mod_%NAME%.lo
712 DISTCLEAN_TARGETS = modules.mk
713 shared =  mod_%NAME%.la
714 -=#=-
715 /* 
716 **  mod_%NAME%.c -- Apache sample %NAME% module
717 **  [Autogenerated via ``apxs -n %NAME% -g'']
718 **
719 **  To play with this sample module first compile it into a
720 **  DSO file and install it into Apache's modules directory 
721 **  by running:
722 **
723 **    $ apxs -c -i mod_%NAME%.c
724 **
725 **  Then activate it in Apache's %TARGET%.conf file for instance
726 **  for the URL /%NAME% in as follows:
727 **
728 **    #   %TARGET%.conf
729 **    LoadModule %NAME%_module modules/mod_%NAME%.so
730 **    <Location /%NAME%>
731 **    SetHandler %NAME%
732 **    </Location>
733 **
734 **  Then after restarting Apache via
735 **
736 **    $ apachectl restart
737 **
738 **  you immediately can request the URL /%NAME% and watch for the
739 **  output of this module. This can be achieved for instance via:
740 **
741 **    $ lynx -mime_header http://localhost/%NAME% 
742 **
743 **  The output should be similar to the following one:
744 **
745 **    HTTP/1.1 200 OK
746 **    Date: Tue, 31 Mar 1998 14:42:22 GMT
747 **    Server: Apache/1.3.4 (Unix)
748 **    Connection: close
749 **    Content-Type: text/html
750 **  
751 **    The sample page from mod_%NAME%.c
752 */ 
753
754 #include "httpd.h"
755 #include "http_config.h"
756 #include "http_protocol.h"
757 #include "ap_config.h"
758
759 /* The sample content handler */
760 static int %NAME%_handler(request_rec *r)
761 {
762     if (strcmp(r->handler, "%NAME%")) {
763         return DECLINED;
764     }
765     r->content_type = "text/html";      
766
767     if (!r->header_only)
768         ap_rputs("The sample page from mod_%NAME%.c\n", r);
769     return OK;
770 }
771
772 static void %NAME%_register_hooks(apr_pool_t *p)
773 {
774     ap_hook_handler(%NAME%_handler, NULL, NULL, APR_HOOK_MIDDLE);
775 }
776
777 /* Dispatch list for API hooks */
778 module AP_MODULE_DECLARE_DATA %NAME%_module = {
779     STANDARD20_MODULE_STUFF, 
780     NULL,                  /* create per-dir    config structures */
781     NULL,                  /* merge  per-dir    config structures */
782     NULL,                  /* create per-server config structures */
783     NULL,                  /* merge  per-server config structures */
784     NULL,                  /* table of config file commands       */
785     %NAME%_register_hooks  /* register hooks                      */
786 };
787